From 708507cbc7ce30661799a3338a81a5197fa2a14d Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Tue, 20 Aug 2024 13:49:07 -0400 Subject: [PATCH] feat: handle OAuth authentication flow Signed-off-by: Donnie Adams --- components/script/messages/promptForm.tsx | 20 +++++++++++++++++++- components/script/useChatSocket.tsx | 13 +++++++++++-- package-lock.json | 8 ++++---- package.json | 2 +- server/app.mjs | 4 +++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/components/script/messages/promptForm.tsx b/components/script/messages/promptForm.tsx index c208a457..b57fbf61 100644 --- a/components/script/messages/promptForm.tsx +++ b/components/script/messages/promptForm.tsx @@ -23,8 +23,18 @@ const PromptForm = ({ const onSubmitForm = () => { setSubmitted(true); onSubmit({ id: frame.id, responses: getValues() }); + if (frame.metadata && frame.metadata.authURL) { + open(frame.metadata.authURL); + } }; + let buttonText = noFields ? 'OK' : 'Submit'; + let includeHiddenInput = false; + if (noFields && frame.metadata && frame.metadata.authURL) { + buttonText = 'Click here to sign in'; + includeHiddenInput = true; + } + return (
{frame.fields.map( @@ -40,6 +50,14 @@ const PromptForm = ({ /> ) )} + {includeHiddenInput && ( + + )}
); diff --git a/components/script/useChatSocket.tsx b/components/script/useChatSocket.tsx index 37b6f5f8..daffe467 100644 --- a/components/script/useChatSocket.tsx +++ b/components/script/useChatSocket.tsx @@ -153,14 +153,23 @@ const useChatSocket = (isEmpty?: boolean) => { if (latestAgentMessageIndex.current !== -1) { // Update the message content updatedMessages[latestAgentMessageIndex.current].message = - frame.message; + frame.metadata && + frame.metadata.authURL && + frame.metadata.toolDisplayName + ? `${frame.metadata.toolDisplayName} requires authentication` + : frame.message; updatedMessages[latestAgentMessageIndex.current].component = form; updatedMessages[latestAgentMessageIndex.current].calls = state; } else { // If there are no previous messages, create a new message updatedMessages.push({ type: MessageType.Agent, - message: frame.message, + message: + frame.metadata && + frame.metadata.authURL && + frame.metadata.toolDisplayName + ? `${frame.metadata.toolDisplayName} requires authentication` + : frame.message, component: form, calls: state, }); diff --git a/package-lock.json b/package-lock.json index 0162e3bf..ad686295 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "acorn", "version": "v0.10.0-rc3", "dependencies": { - "@gptscript-ai/gptscript": "^0.9.5-rc3", + "@gptscript-ai/gptscript": "github:gptscript-ai/node-gptscript#de914911013bf9da02046906b88a5613dce508e1", "@monaco-editor/react": "^4.6.0", "@nextui-org/button": "2.0.32", "@nextui-org/code": "2.0.28", @@ -512,9 +512,9 @@ } }, "node_modules/@gptscript-ai/gptscript": { - "version": "0.9.5-rc3", - "resolved": "https://registry.npmjs.org/@gptscript-ai/gptscript/-/gptscript-0.9.5-rc3.tgz", - "integrity": "sha512-ZAaVFtN6Ni6Dok22SF5qjRcbxfHfUksZi0xCWpGIhboa3G7takJenzBLnIg1bpeweGK+NAvE3eP8iAg0aT27Jw==", + "version": "v0.9.5-rc3", + "resolved": "git+ssh://git@github.com/gptscript-ai/node-gptscript.git#de914911013bf9da02046906b88a5613dce508e1", + "integrity": "sha512-XeinsuZgXIdHj1LAc0NuS65CgSt+qmvFGHmO9RhmuZyLJU4KocVRw647mB6FYFi5y1CSb2zenGt/L/k8+c8Hqw==", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index ea404bac..1cd08079 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "main": "electron/main.mjs", "dependencies": { - "@gptscript-ai/gptscript": "^0.9.5-rc3", + "@gptscript-ai/gptscript": "github:gptscript-ai/node-gptscript#de914911013bf9da02046906b88a5613dce508e1", "@monaco-editor/react": "^4.6.0", "@nextui-org/button": "2.0.32", "@nextui-org/code": "2.0.28", diff --git a/server/app.mjs b/server/app.mjs index 1e164a07..aa8f7b3d 100644 --- a/server/app.mjs +++ b/server/app.mjs @@ -166,7 +166,9 @@ const mount = async ( tools: state.tools || [], }); } - } catch (e) {} + } catch (e) { + console.error('Error loading state:', e); + } // Start the script let runningScript = null;