Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/script/chatBar/commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default function Commands({
...prev,
{
type: MessageType.Alert,
name: prev ? prev[prev.length - 1].name : undefined,
icon: <GoPaperclip className="mt-1" />,
message: `Uploading knowledge ${file.name}`,
},
Expand All @@ -149,6 +150,7 @@ export default function Commands({
{
type: MessageType.Alert,
icon: <GoCheckCircleFill className="mt-1" />,
name: prev ? prev[prev.length - 1].name : undefined,
message: `Successfully uploaded knowledge ${plainFiles.map((f) => f.name).join(', ')}`,
},
]);
Expand All @@ -163,6 +165,7 @@ export default function Commands({
...prev,
{
type: MessageType.Alert,
name: prev ? prev[prev.length - 1].name : undefined,
icon: <GoAlert className="mt-1" />,
message: `Error uploading knowledge ${filesContent.map((f) => f.name).join(', ')}: ${e}`,
},
Expand Down Expand Up @@ -204,6 +207,7 @@ export default function Commands({
{
type: MessageType.Alert,
icon: <GoTools className="mt-1" />,
name: prev ? prev[prev.length - 1].name : undefined,
message: `Added ${tool
.split('/')
.pop()
Expand All @@ -219,6 +223,7 @@ export default function Commands({
{
type: MessageType.Alert,
icon: <GoTools className="mt-1" />,
name: prev ? prev[prev.length - 1].name : undefined,
message: `Removed ${tool
.split('/')
.pop()
Expand Down
33 changes: 24 additions & 9 deletions components/script/useChatSocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const useChatSocket = (isEmpty?: boolean) => {
// If there are no previous messages, create a new error message
updatedMessages.push({
type: MessageType.Agent,
name: '',
message:
'The script encountered an error. You can either restart the script or try to continue chatting.',
error,
Expand All @@ -66,14 +67,16 @@ const useChatSocket = (isEmpty?: boolean) => {
});
}, []);

// handles progress being recieved from the server (callProgress style frames).
// handles progress being received from the server (callProgress style frames).
const handleProgress = useCallback(
({
frame,
state,
name,
}: {
frame: CallFrame;
state: Record<string, CallFrame>;
name?: string;
}) => {
if (!frame.error && frame.toolCategory === 'provider') {
return;
Expand Down Expand Up @@ -106,7 +109,7 @@ const useChatSocket = (isEmpty?: boolean) => {
type: MessageType.Agent,
message: content,
calls: state,
name: frame.tool?.name,
name: name,
};
if (latestAgentMessageIndex.current === -1) {
latestAgentMessageIndex.current = messagesRef.current.length;
Expand Down Expand Up @@ -139,9 +142,11 @@ const useChatSocket = (isEmpty?: boolean) => {
({
frame,
state,
name,
}: {
frame: PromptFrame;
state: Record<string, CallFrame>;
name?: string;
}) => {
setMessages((prevMessages) => {
const updatedMessages = [...prevMessages];
Expand All @@ -164,6 +169,7 @@ const useChatSocket = (isEmpty?: boolean) => {
: frame.message;
updatedMessages[latestAgentMessageIndex.current].component = form;
updatedMessages[latestAgentMessageIndex.current].calls = state;
updatedMessages[latestAgentMessageIndex.current].name = name;
} else {
// If there are no previous messages, create a new message
updatedMessages.push({
Expand All @@ -176,6 +182,7 @@ const useChatSocket = (isEmpty?: boolean) => {
: frame.message,
component: form,
calls: state,
name: name,
});
}
return updatedMessages;
Expand All @@ -188,9 +195,11 @@ const useChatSocket = (isEmpty?: boolean) => {
({
frame,
state,
name,
}: {
frame: CallFrame;
state: Record<string, CallFrame>;
name?: string;
}) => {
if (!frame.tool) return;

Expand Down Expand Up @@ -227,7 +236,7 @@ const useChatSocket = (isEmpty?: boolean) => {

const message: Message = {
type: MessageType.Agent,
name: frame.tool?.name,
name: name,
component: form,
calls: state,
};
Expand Down Expand Up @@ -379,15 +388,21 @@ const useChatSocket = (isEmpty?: boolean) => {
setForceRun(true);
});
socket.on('running', () => setRunning(true));
socket.on('progress', (data: { frame: CallFrame; state: any }) =>
handleProgress(data)
socket.on(
'progress',
(data: { frame: CallFrame; state: any; name?: string }) =>
handleProgress(data)
);
socket.on('error', (data: string) => handleError(data));
socket.on('promptRequest', (data: { frame: PromptFrame; state: any }) =>
handlePromptRequest(data)
socket.on(
'promptRequest',
(data: { frame: PromptFrame; state: any; name?: string }) =>
handlePromptRequest(data)
);
socket.on('confirmRequest', (data: { frame: CallFrame; state: any }) =>
handleConfirmRequest(data)
socket.on(
'confirmRequest',
(data: { frame: CallFrame; state: any; name?: string }) =>
handleConfirmRequest(data)
);
socket.on('toolAdded', handleToolAdded);
socket.on('addingTool', handleAddingTool);
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"main": "electron/main.mjs",
"dependencies": {
"@gptscript-ai/gptscript": "^0.9.5-rc4",
"@gptscript-ai/gptscript": "github:gptscript-ai/node-gptscript#0ec49d9df04627afe4518f4689dc212c0d03cdd6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to fix an issue in node-gptscript to get the respondingTool stuff to work correctly.

"@monaco-editor/react": "^4.6.0",
"@nextui-org/button": "2.0.32",
"@nextui-org/code": "2.0.28",
Expand Down
20 changes: 18 additions & 2 deletions server/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,21 @@ const mount = async (
socket.emit('progress', {
frame: data,
state: runningScript.calls,
name: script[0]?.name || data.tool?.name || '',
})
);
runningScript.on(RunEventType.Prompt, async (data) =>
socket.emit('promptRequest', {
frame: data,
state: runningScript.calls,
name: script[0]?.name || data.tool?.name || '',
})
);
runningScript.on(RunEventType.CallConfirm, (data) =>
socket.emit('confirmRequest', {
frame: data,
state: runningScript.calls,
name: script[0]?.name || data.tool?.name || '',
})
);
socket.on(
Expand All @@ -222,7 +225,11 @@ const mount = async (
if (!runningScript) return;

if (!state.messages) state.messages = [];
state.messages.push({ type: AGENT, message: output });
state.messages.push({
type: AGENT,
message: output,
name: (runningScript.respondingTool() || {}).name || '',
});
state.chatState = runningScript.currentChatState();

if (threadID) {
Expand Down Expand Up @@ -357,29 +364,34 @@ const mount = async (

// If there is not a running script, that means we're loading a thread and have been waiting
// for the user to send a message.
let name = script[0].name || '';
if (!runningScript) {
opts.input = message;
runningScript = await gptscript.evaluate(script, opts);
} else {
name = runningScript.respondingTool().name || '';
runningScript = runningScript.nextChat(message);
}

runningScript.on(RunEventType.Event, (data) =>
socket.emit('progress', {
frame: data,
state: runningScript.calls,
name: name || data.tool?.name || '',
})
);
runningScript.on(RunEventType.Prompt, async (data) =>
socket.emit('promptRequest', {
frame: data,
state: runningScript.calls,
name: name || data.tool?.name || '',
})
);
runningScript.on(RunEventType.CallConfirm, (data) =>
socket.emit('confirmRequest', {
frame: data,
state: runningScript.calls,
name: name || data.tool?.name || '',
})
);
socket.on(
Expand All @@ -396,7 +408,11 @@ const mount = async (
if (!state.messages) state.messages = [];
state.messages.push(
{ type: USER, message: message },
{ type: AGENT, message: output }
{
type: AGENT,
message: output,
name: (runningScript.respondingTool() || {}).name || '',
}
);

state.chatState = runningScript.currentChatState();
Expand Down