@dxos/plugin-automation 0.7.4 → 0.7.5-labs.401163d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/AutomationPanel-VW2XIUPU.mjs +8 -0
- package/dist/lib/browser/ChatContainer-OLRZNGWK.mjs +12 -0
- package/dist/lib/browser/ai-client-5CNY6JBF.mjs +22 -0
- package/dist/lib/browser/ai-client-5CNY6JBF.mjs.map +7 -0
- package/dist/lib/browser/app-graph-builder-6H7MDCXE.mjs +197 -0
- package/dist/lib/browser/app-graph-builder-6H7MDCXE.mjs.map +7 -0
- package/dist/lib/browser/chunk-2H2EUYXL.mjs +15 -0
- package/dist/lib/browser/chunk-2H2EUYXL.mjs.map +7 -0
- package/dist/lib/browser/chunk-ITG6CBKL.mjs +1602 -0
- package/dist/lib/browser/chunk-ITG6CBKL.mjs.map +7 -0
- package/dist/lib/browser/chunk-MRBC5J4T.mjs +518 -0
- package/dist/lib/browser/chunk-MRBC5J4T.mjs.map +7 -0
- package/dist/lib/browser/chunk-NQFZ6XRX.mjs +243 -0
- package/dist/lib/browser/chunk-NQFZ6XRX.mjs.map +7 -0
- package/dist/lib/browser/chunk-Q4IMHYGH.mjs +150 -0
- package/dist/lib/browser/chunk-Q4IMHYGH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-X5KMOH3I.mjs → chunk-R4JH4TLE.mjs} +6 -4
- package/dist/lib/browser/chunk-R4JH4TLE.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +157 -252
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-BWAXKT27.mjs +29 -0
- package/dist/lib/browser/intent-resolver-BWAXKT27.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-O6SHIBCA.mjs +58 -0
- package/dist/lib/browser/react-surface-O6SHIBCA.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +12 -3
- package/dist/lib/node/{meta.cjs → AutomationPanel-G6EDDYWW.cjs} +7 -11
- package/dist/lib/node/AutomationPanel-G6EDDYWW.cjs.map +7 -0
- package/dist/lib/node/ChatContainer-GRZDJIG5.cjs +33 -0
- package/dist/lib/node/ChatContainer-GRZDJIG5.cjs.map +7 -0
- package/dist/lib/node/ai-client-FKLPDELV.cjs +38 -0
- package/dist/lib/node/ai-client-FKLPDELV.cjs.map +7 -0
- package/dist/lib/node/app-graph-builder-7JMJLZIE.cjs +212 -0
- package/dist/lib/node/app-graph-builder-7JMJLZIE.cjs.map +7 -0
- package/dist/lib/node/chunk-CFBERLTN.cjs +1586 -0
- package/dist/lib/node/chunk-CFBERLTN.cjs.map +7 -0
- package/dist/lib/node/{chunk-DTJ7XVO2.cjs → chunk-EQYHOTGG.cjs} +11 -8
- package/dist/lib/node/chunk-EQYHOTGG.cjs.map +7 -0
- package/dist/lib/node/chunk-FQUY77HT.cjs +527 -0
- package/dist/lib/node/chunk-FQUY77HT.cjs.map +7 -0
- package/dist/lib/node/chunk-GB7245FH.cjs +173 -0
- package/dist/lib/node/chunk-GB7245FH.cjs.map +7 -0
- package/dist/lib/node/chunk-QXIHYOMF.cjs +267 -0
- package/dist/lib/node/chunk-QXIHYOMF.cjs.map +7 -0
- package/dist/lib/node/chunk-U5Z7LFWB.cjs +34 -0
- package/dist/lib/node/chunk-U5Z7LFWB.cjs.map +7 -0
- package/dist/lib/node/index.cjs +174 -282
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-C6OKFVEW.cjs +44 -0
- package/dist/lib/node/intent-resolver-C6OKFVEW.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-JT6SVCPK.cjs +76 -0
- package/dist/lib/node/react-surface-JT6SVCPK.cjs.map +7 -0
- package/dist/lib/node/types/index.cjs +16 -7
- package/dist/lib/node/types/index.cjs.map +2 -2
- package/dist/lib/node-esm/AutomationPanel-V3IWQAMO.mjs +9 -0
- package/dist/lib/node-esm/AutomationPanel-V3IWQAMO.mjs.map +7 -0
- package/dist/lib/node-esm/ChatContainer-ORVWQPJO.mjs +13 -0
- package/dist/lib/node-esm/ChatContainer-ORVWQPJO.mjs.map +7 -0
- package/dist/lib/node-esm/ai-client-XGNA6SJ5.mjs +23 -0
- package/dist/lib/node-esm/ai-client-XGNA6SJ5.mjs.map +7 -0
- package/dist/lib/node-esm/app-graph-builder-C6NUQGCU.mjs +198 -0
- package/dist/lib/node-esm/app-graph-builder-C6NUQGCU.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2OKJZ4ZW.mjs +519 -0
- package/dist/lib/node-esm/chunk-2OKJZ4ZW.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6HLBYDUI.mjs +244 -0
- package/dist/lib/node-esm/chunk-6HLBYDUI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-7VPT3OO3.mjs +1603 -0
- package/dist/lib/node-esm/chunk-7VPT3OO3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DNCXRGAF.mjs +151 -0
- package/dist/lib/node-esm/chunk-DNCXRGAF.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-HNOBZHWK.mjs → chunk-EMVA6QUT.mjs} +6 -4
- package/dist/lib/node-esm/chunk-EMVA6QUT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-IJRTDSKN.mjs +16 -0
- package/dist/lib/node-esm/chunk-IJRTDSKN.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +157 -252
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-DCP4ZDBA.mjs +30 -0
- package/dist/lib/node-esm/intent-resolver-DCP4ZDBA.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-DSVM33SA.mjs +59 -0
- package/dist/lib/node-esm/react-surface-DSVM33SA.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +12 -3
- package/dist/types/src/AutomationPlugin.d.ts +1 -3
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/artifacts.stories.d.ts +16 -0
- package/dist/types/src/artifacts.stories.d.ts.map +1 -0
- package/dist/types/src/capabilities/ai-client.d.ts +5 -0
- package/dist/types/src/capabilities/ai-client.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +5 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +182 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/AmbientChatDialog/AmbientChatDialog.d.ts +3 -0
- package/dist/types/src/components/AmbientChatDialog/AmbientChatDialog.d.ts.map +1 -0
- package/dist/types/src/components/AmbientChatDialog/AmbientChatDialog.stories.d.ts +8 -0
- package/dist/types/src/components/AmbientChatDialog/AmbientChatDialog.stories.d.ts.map +1 -0
- package/dist/types/src/components/AmbientChatDialog/index.d.ts +2 -0
- package/dist/types/src/components/AmbientChatDialog/index.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -1
- package/dist/types/src/components/Box/StatusLine.d.ts +11 -0
- package/dist/types/src/components/Box/StatusLine.d.ts.map +1 -0
- package/dist/types/src/components/Box/StatusLine.stories.d.ts +9 -0
- package/dist/types/src/components/Box/StatusLine.stories.d.ts.map +1 -0
- package/dist/types/src/components/Box/Tabbed.d.ts +15 -0
- package/dist/types/src/components/Box/Tabbed.d.ts.map +1 -0
- package/dist/types/src/components/Box/Tabbed.stories.d.ts +8 -0
- package/dist/types/src/components/Box/Tabbed.stories.d.ts.map +1 -0
- package/dist/types/src/components/Box/ToggleContainer.d.ts +13 -0
- package/dist/types/src/components/Box/ToggleContainer.d.ts.map +1 -0
- package/dist/types/src/components/Box/ToggleContainer.stories.d.ts +9 -0
- package/dist/types/src/components/Box/ToggleContainer.stories.d.ts.map +1 -0
- package/dist/types/src/components/Box/index.d.ts +4 -0
- package/dist/types/src/components/Box/index.d.ts.map +1 -0
- package/dist/types/src/components/ChatContainer/ChatContainer.d.ts +7 -0
- package/dist/types/src/components/ChatContainer/ChatContainer.d.ts.map +1 -0
- package/dist/types/src/components/ChatContainer/index.d.ts +4 -0
- package/dist/types/src/components/ChatContainer/index.d.ts.map +1 -0
- package/dist/types/src/components/MarkdownViewer/MarkdownViewer.d.ts +14 -0
- package/dist/types/src/components/MarkdownViewer/MarkdownViewer.d.ts.map +1 -0
- package/dist/types/src/components/MarkdownViewer/MarkdownViewer.stories.d.ts +8 -0
- package/dist/types/src/components/MarkdownViewer/MarkdownViewer.stories.d.ts.map +1 -0
- package/dist/types/src/components/MarkdownViewer/index.d.ts +2 -0
- package/dist/types/src/components/MarkdownViewer/index.d.ts.map +1 -0
- package/dist/types/src/components/Prompt/Prompt.d.ts +7 -0
- package/dist/types/src/components/Prompt/Prompt.d.ts.map +1 -0
- package/dist/types/src/components/Prompt/Prompt.stories.d.ts +8 -0
- package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +1 -0
- package/dist/types/src/components/Prompt/index.d.ts +2 -0
- package/dist/types/src/components/Prompt/index.d.ts.map +1 -0
- package/dist/types/src/components/Prompt/prompt-autocomplete.d.ts +20 -0
- package/dist/types/src/components/Prompt/prompt-autocomplete.d.ts.map +1 -0
- package/dist/types/src/components/ServiceRegistry/ServiceRegistry.d.ts +6 -0
- package/dist/types/src/components/ServiceRegistry/ServiceRegistry.d.ts.map +1 -0
- package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts +8 -0
- package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts.map +1 -0
- package/dist/types/src/components/ServiceRegistry/index.d.ts +2 -0
- package/dist/types/src/components/ServiceRegistry/index.d.ts.map +1 -0
- package/dist/types/src/components/Thread/Thread.d.ts +11 -0
- package/dist/types/src/components/Thread/Thread.d.ts.map +1 -0
- package/dist/types/src/components/Thread/Thread.stories.d.ts +11 -0
- package/dist/types/src/components/Thread/Thread.stories.d.ts.map +1 -0
- package/dist/types/src/components/Thread/ThreadMessage.d.ts +12 -0
- package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +1 -0
- package/dist/types/src/components/Thread/index.d.ts +2 -0
- package/dist/types/src/components/Thread/index.d.ts.map +1 -0
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +1 -2
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +13 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/email.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +4 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/invocation-handler.d.ts.map +1 -1
- package/dist/types/src/hooks/processor.d.ts +70 -0
- package/dist/types/src/hooks/processor.d.ts.map +1 -0
- package/dist/types/src/hooks/processor.test.d.ts +2 -0
- package/dist/types/src/hooks/processor.test.d.ts.map +1 -0
- package/dist/types/src/hooks/useChatProcessor.d.ts +7 -0
- package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -0
- package/dist/types/src/hooks/useMessageQueue.d.ts +41 -0
- package/dist/types/src/hooks/useMessageQueue.d.ts.map +1 -0
- package/dist/types/src/hooks/useServices.d.ts +7 -0
- package/dist/types/src/hooks/useServices.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/{testing.d.ts → test-functions.d.ts} +3 -1
- package/dist/types/src/testing/test-functions.d.ts.map +1 -0
- package/dist/types/src/testing/test-services.d.ts +5 -0
- package/dist/types/src/testing/test-services.d.ts.map +1 -0
- package/dist/types/src/tools/function.d.ts +5 -0
- package/dist/types/src/tools/function.d.ts.map +1 -0
- package/dist/types/src/tools/index.d.ts +3 -0
- package/dist/types/src/tools/index.d.ts.map +1 -0
- package/dist/types/src/tools/openapi.d.ts +10 -0
- package/dist/types/src/tools/openapi.d.ts.map +1 -0
- package/dist/types/src/tools/openapi.test.d.ts +2 -0
- package/dist/types/src/tools/openapi.test.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +84 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/registry.d.ts +10 -0
- package/dist/types/src/types/registry.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +189 -39
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +16 -5
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +57 -48
- package/src/AutomationPlugin.tsx +77 -194
- package/src/artifacts.stories.tsx +241 -0
- package/src/capabilities/ai-client.ts +19 -0
- package/src/capabilities/app-graph-builder.ts +187 -0
- package/src/capabilities/capabilities.ts +12 -0
- package/src/capabilities/index.ts +12 -0
- package/src/capabilities/intent-resolver.ts +27 -0
- package/src/capabilities/react-surface.tsx +42 -0
- package/src/components/AmbientChatDialog/AmbientChatDialog.stories.tsx +44 -0
- package/src/components/AmbientChatDialog/AmbientChatDialog.tsx +63 -0
- package/src/components/AmbientChatDialog/index.ts +5 -0
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +1 -2
- package/src/components/AutomationPanel/AutomationPanel.tsx +61 -39
- package/src/components/Box/StatusLine.stories.tsx +52 -0
- package/src/components/Box/StatusLine.tsx +76 -0
- package/src/components/Box/Tabbed.stories.tsx +51 -0
- package/src/components/Box/Tabbed.tsx +89 -0
- package/src/components/Box/ToggleContainer.stories.tsx +110 -0
- package/src/components/Box/ToggleContainer.tsx +108 -0
- package/src/components/Box/index.ts +7 -0
- package/src/components/ChatContainer/ChatContainer.tsx +52 -0
- package/src/components/ChatContainer/index.ts +8 -0
- package/src/components/MarkdownViewer/MarkdownViewer.stories.tsx +56 -0
- package/src/components/MarkdownViewer/MarkdownViewer.tsx +79 -0
- package/src/components/MarkdownViewer/index.ts +5 -0
- package/src/components/Prompt/Prompt.stories.tsx +50 -0
- package/src/components/Prompt/Prompt.tsx +39 -0
- package/src/components/Prompt/index.ts +5 -0
- package/src/components/Prompt/prompt-autocomplete.ts +200 -0
- package/src/components/PromptEditor/PromptEditor.stories.tsx +6 -6
- package/src/components/PromptEditor/PromptEditor.tsx +3 -3
- package/src/components/ServiceRegistry/ServiceRegistry.stories.tsx +49 -0
- package/src/components/ServiceRegistry/ServiceRegistry.tsx +76 -0
- package/src/components/ServiceRegistry/index.ts +5 -0
- package/src/components/Thread/Thread.stories.tsx +197 -0
- package/src/components/Thread/Thread.tsx +156 -0
- package/src/components/Thread/ThreadMessage.tsx +225 -0
- package/src/components/Thread/index.ts +5 -0
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +1 -2
- package/src/components/TriggerEditor/TriggerEditor.tsx +86 -16
- package/src/components/index.ts +10 -1
- package/src/hooks/email.ts +2 -2
- package/src/hooks/index.ts +5 -0
- package/src/hooks/invocation-handler.ts +2 -2
- package/src/hooks/processor.test.ts +15 -0
- package/src/hooks/processor.ts +210 -0
- package/src/hooks/useChatProcessor.tsx +86 -0
- package/src/hooks/useMessageQueue.ts +23 -0
- package/src/hooks/useServices.ts +28 -0
- package/src/index.ts +1 -4
- package/src/meta.ts +5 -2
- package/src/testing/index.ts +2 -1
- package/src/testing/{testing.ts → test-functions.ts} +9 -2
- package/src/testing/test-services.ts +131 -0
- package/src/tools/function.ts +47 -0
- package/src/tools/index.ts +6 -0
- package/src/tools/openapi.test.ts +224 -0
- package/src/tools/openapi.ts +331 -0
- package/src/translations.ts +18 -2
- package/src/types/index.ts +1 -0
- package/src/types/registry.ts +26 -0
- package/src/types/schema.ts +96 -2
- package/src/types/types.ts +15 -21
- package/dist/lib/browser/AssistantPanel-N3QSALKY.mjs +0 -341
- package/dist/lib/browser/AssistantPanel-N3QSALKY.mjs.map +0 -7
- package/dist/lib/browser/AutomationPanel-AQMN2CQR.mjs +0 -153
- package/dist/lib/browser/AutomationPanel-AQMN2CQR.mjs.map +0 -7
- package/dist/lib/browser/chunk-7KB4UMXO.mjs +0 -49
- package/dist/lib/browser/chunk-7KB4UMXO.mjs.map +0 -7
- package/dist/lib/browser/chunk-X5KMOH3I.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/node/AssistantPanel-RIA4TI3B.cjs +0 -361
- package/dist/lib/node/AssistantPanel-RIA4TI3B.cjs.map +0 -7
- package/dist/lib/node/AutomationPanel-HZS5WKI5.cjs +0 -173
- package/dist/lib/node/AutomationPanel-HZS5WKI5.cjs.map +0 -7
- package/dist/lib/node/chunk-CUCUWUAF.cjs +0 -73
- package/dist/lib/node/chunk-CUCUWUAF.cjs.map +0 -7
- package/dist/lib/node/chunk-DTJ7XVO2.cjs.map +0 -7
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node-esm/AssistantPanel-72YH43CH.mjs +0 -342
- package/dist/lib/node-esm/AssistantPanel-72YH43CH.mjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-JUHOWQWW.mjs +0 -154
- package/dist/lib/node-esm/AutomationPanel-JUHOWQWW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-23LY7DYS.mjs +0 -51
- package/dist/lib/node-esm/chunk-23LY7DYS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNOBZHWK.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts +0 -8
- package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts.map +0 -1
- package/dist/types/src/components/AssistantPanel/index.d.ts +0 -3
- package/dist/types/src/components/AssistantPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/AssistantPanel/system-instructions.d.ts +0 -6
- package/dist/types/src/components/AssistantPanel/system-instructions.d.ts.map +0 -1
- package/dist/types/src/testing/testing.d.ts.map +0 -1
- package/src/components/AssistantPanel/AssistantPanel.tsx +0 -230
- package/src/components/AssistantPanel/index.ts +0 -7
- package/src/components/AssistantPanel/system-instructions.ts +0 -166
- /package/dist/lib/browser/{meta.mjs.map → AutomationPanel-VW2XIUPU.mjs.map} +0 -0
- /package/dist/lib/{node-esm/meta.mjs.map → browser/ChatContainer-OLRZNGWK.mjs.map} +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Signal, batch, computed, signal } from '@preact/signals-core';
|
|
6
|
+
|
|
7
|
+
import { type PromiseIntentDispatcher } from '@dxos/app-framework';
|
|
8
|
+
import { type Tool, Message, type MessageContentBlock } from '@dxos/artifact';
|
|
9
|
+
import {
|
|
10
|
+
isToolUse,
|
|
11
|
+
runTools,
|
|
12
|
+
type AIServiceClientImpl,
|
|
13
|
+
type GenerateRequest,
|
|
14
|
+
type GenerationStream,
|
|
15
|
+
MixedStreamParser,
|
|
16
|
+
} from '@dxos/assistant';
|
|
17
|
+
import { createStatic } from '@dxos/echo-schema';
|
|
18
|
+
import { invariant } from '@dxos/invariant';
|
|
19
|
+
import { log } from '@dxos/log';
|
|
20
|
+
import { type Space } from '@dxos/react-client/echo';
|
|
21
|
+
|
|
22
|
+
// TODO(burdon): Factor out.
|
|
23
|
+
declare global {
|
|
24
|
+
interface ToolContextExtensions {
|
|
25
|
+
space?: Space;
|
|
26
|
+
dispatch?: PromiseIntentDispatcher;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type RequestOptions = {
|
|
31
|
+
history?: Message[];
|
|
32
|
+
onComplete?: (messages: Message[]) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type ChatProcessorOptions = Pick<GenerateRequest, 'model' | 'systemPrompt'>;
|
|
36
|
+
|
|
37
|
+
const defaultOptions: ChatProcessorOptions = {
|
|
38
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
39
|
+
systemPrompt: 'you are a helpful assistant',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Handles interactions with the AI service.
|
|
44
|
+
* Maintains a queue of messages and handles streaming responses from the AI service.
|
|
45
|
+
* Executes tools based on AI responses.
|
|
46
|
+
* Supports cancellation of in-progress requests.
|
|
47
|
+
*/
|
|
48
|
+
export class ChatProcessor {
|
|
49
|
+
/** SSE stream parser. */
|
|
50
|
+
private readonly _parser = new MixedStreamParser();
|
|
51
|
+
|
|
52
|
+
/** Current streaming response (iterator). */
|
|
53
|
+
private _stream: GenerationStream | undefined;
|
|
54
|
+
|
|
55
|
+
/** Pending messages (incl. the user request). */
|
|
56
|
+
private readonly _pending: Signal<Message[]> = signal([]);
|
|
57
|
+
|
|
58
|
+
/** Current streaming block (from the AI service). */
|
|
59
|
+
private readonly _block: Signal<MessageContentBlock | undefined> = signal(undefined);
|
|
60
|
+
|
|
61
|
+
/** Prior history from queue. */
|
|
62
|
+
private _history: Message[] = [];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Streaming state.
|
|
66
|
+
* @reactive
|
|
67
|
+
*/
|
|
68
|
+
public readonly streaming: Signal<boolean> = computed(() => this._block.value !== undefined);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Array of Messages (incl. the current message being streamed).
|
|
72
|
+
* @reactive
|
|
73
|
+
*/
|
|
74
|
+
public readonly messages: Signal<Message[]> = computed(() => {
|
|
75
|
+
const messages = [...this._pending.value];
|
|
76
|
+
if (this._block.value) {
|
|
77
|
+
const current = messages.pop();
|
|
78
|
+
invariant(current);
|
|
79
|
+
const { content, ...rest } = current;
|
|
80
|
+
const message = { ...rest, content: [...content, this._block.value] };
|
|
81
|
+
messages.push(message);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return messages;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
constructor(
|
|
88
|
+
private readonly _client: AIServiceClientImpl,
|
|
89
|
+
private _tools?: Tool[],
|
|
90
|
+
private readonly _extensions?: ToolContextExtensions,
|
|
91
|
+
private readonly _options: ChatProcessorOptions = defaultOptions,
|
|
92
|
+
) {
|
|
93
|
+
// Message complete.
|
|
94
|
+
this._parser.message.on((message) => {
|
|
95
|
+
batch(() => {
|
|
96
|
+
this._pending.value = [...this._pending.value, message];
|
|
97
|
+
this._block.value = undefined;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Streaming update (happens before message complete).
|
|
102
|
+
this._parser.update.on((block) => {
|
|
103
|
+
batch(() => {
|
|
104
|
+
this._block.value = block;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Update tools.
|
|
111
|
+
*/
|
|
112
|
+
setTools(tools: Tool[]) {
|
|
113
|
+
this._tools = tools;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Make GPT request.
|
|
118
|
+
*/
|
|
119
|
+
async request(message: string, options: RequestOptions = {}): Promise<Message[]> {
|
|
120
|
+
batch(() => {
|
|
121
|
+
this._history = options.history ?? [];
|
|
122
|
+
this._pending.value = [
|
|
123
|
+
createStatic(Message, {
|
|
124
|
+
role: 'user',
|
|
125
|
+
content: [{ type: 'text', text: message }],
|
|
126
|
+
}),
|
|
127
|
+
];
|
|
128
|
+
this._block.value = undefined;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
await this._generate();
|
|
132
|
+
options.onComplete?.(this._pending.value);
|
|
133
|
+
return this._reset();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Cancel pending requests.
|
|
138
|
+
* @returns Pending requests (incl. the request message).
|
|
139
|
+
*/
|
|
140
|
+
async cancel(): Promise<Message[]> {
|
|
141
|
+
log.info('cancelling...');
|
|
142
|
+
this._stream?.abort();
|
|
143
|
+
return this._reset();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private async _reset(): Promise<Message[]> {
|
|
147
|
+
const messages = this._pending.value;
|
|
148
|
+
batch(() => {
|
|
149
|
+
this._history = [];
|
|
150
|
+
this._pending.value = [];
|
|
151
|
+
this._block.value = undefined;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return messages;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Generate a response from the AI service.
|
|
159
|
+
* Iterates over tool requests.
|
|
160
|
+
*/
|
|
161
|
+
private async _generate() {
|
|
162
|
+
try {
|
|
163
|
+
let more = false;
|
|
164
|
+
do {
|
|
165
|
+
log.info('requesting...', { history: this._history.length, messages: this._pending.value.length });
|
|
166
|
+
this._stream = await this._client.generate({
|
|
167
|
+
...this._options,
|
|
168
|
+
// TODO(burdon): Rename messages or separate history/message.
|
|
169
|
+
history: [...this._history, ...this._pending.value],
|
|
170
|
+
tools: this._tools,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Wait until complete.
|
|
174
|
+
await this._parser.parse(this._stream);
|
|
175
|
+
await this._stream.complete();
|
|
176
|
+
|
|
177
|
+
// Add messages.
|
|
178
|
+
log.info('response', { messages: this._pending.value });
|
|
179
|
+
|
|
180
|
+
// Resolve tool use locally.
|
|
181
|
+
more = false;
|
|
182
|
+
const message = this._pending.value.at(-1);
|
|
183
|
+
invariant(message);
|
|
184
|
+
if (isToolUse(message)) {
|
|
185
|
+
log.info('tool request...');
|
|
186
|
+
const response = await runTools({
|
|
187
|
+
message: this._pending.value.at(-1)!,
|
|
188
|
+
tools: this._tools ?? [],
|
|
189
|
+
extensions: this._extensions,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
log.info('tool response', { response });
|
|
193
|
+
switch (response.type) {
|
|
194
|
+
case 'continue': {
|
|
195
|
+
this._pending.value = [...this._pending.value, response.message];
|
|
196
|
+
more = true;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} while (more);
|
|
202
|
+
} catch (err) {
|
|
203
|
+
// TODO(burdon): Handle error.
|
|
204
|
+
log.catch('request failed', { err });
|
|
205
|
+
} finally {
|
|
206
|
+
log.info('done');
|
|
207
|
+
this._stream = undefined;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Capabilities, useCapabilities, useCapability, useIntentDispatcher } from '@dxos/app-framework';
|
|
8
|
+
import { createSystemPrompt, type Tool } from '@dxos/artifact';
|
|
9
|
+
import { FunctionType } from '@dxos/functions';
|
|
10
|
+
import { useConfig } from '@dxos/react-client';
|
|
11
|
+
import { Filter, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
12
|
+
import { isNonNullable } from '@dxos/util';
|
|
13
|
+
|
|
14
|
+
import { AutomationCapabilities } from '../capabilities';
|
|
15
|
+
import { ChatProcessor } from '../hooks';
|
|
16
|
+
import { covertFunctionToTool, createToolsFromService } from '../tools';
|
|
17
|
+
import { ServiceType, type AIChatType } from '../types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a processor for the chat.
|
|
21
|
+
*/
|
|
22
|
+
export const useChatProcessor = (chat: AIChatType) => {
|
|
23
|
+
const aiClient = useCapability(AutomationCapabilities.AiClient);
|
|
24
|
+
const globalTools = useCapabilities(Capabilities.Tools);
|
|
25
|
+
const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
|
|
26
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
27
|
+
const space = getSpace(chat);
|
|
28
|
+
|
|
29
|
+
// Services.
|
|
30
|
+
const services = useQuery(space, Filter.schema(ServiceType));
|
|
31
|
+
const [serviceTools, setServiceTools] = useState<Tool[]>([]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
queueMicrotask(async () => {
|
|
34
|
+
const tools = await Promise.all(services.map((service) => createToolsFromService(service)));
|
|
35
|
+
setServiceTools(tools.flat());
|
|
36
|
+
});
|
|
37
|
+
}, [services]);
|
|
38
|
+
|
|
39
|
+
// Tools.
|
|
40
|
+
const config = useConfig();
|
|
41
|
+
const functions = useQuery(space, Filter.schema(FunctionType));
|
|
42
|
+
const tools = useMemo(
|
|
43
|
+
() => [
|
|
44
|
+
...globalTools.flat(),
|
|
45
|
+
...artifactDefinitions.flatMap((definition) => definition.tools),
|
|
46
|
+
...serviceTools,
|
|
47
|
+
...functions
|
|
48
|
+
.map((fn) => covertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? '', space?.id))
|
|
49
|
+
.filter(isNonNullable),
|
|
50
|
+
],
|
|
51
|
+
[globalTools, artifactDefinitions, serviceTools, functions, space?.id],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Prompt.
|
|
55
|
+
const systemPrompt = useMemo(
|
|
56
|
+
() => createSystemPrompt({ artifacts: artifactDefinitions.map((definition) => definition.instructions) }),
|
|
57
|
+
[artifactDefinitions],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Create processor.
|
|
61
|
+
const processor = useMemo(
|
|
62
|
+
() =>
|
|
63
|
+
new ChatProcessor(
|
|
64
|
+
aiClient,
|
|
65
|
+
tools,
|
|
66
|
+
{
|
|
67
|
+
space,
|
|
68
|
+
dispatch,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
72
|
+
systemPrompt,
|
|
73
|
+
},
|
|
74
|
+
),
|
|
75
|
+
[aiClient, tools, space, dispatch, systemPrompt],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Update processor.
|
|
79
|
+
// useEffect(() => {
|
|
80
|
+
// if (processor) {
|
|
81
|
+
// processor.setTools(tools.flat());
|
|
82
|
+
// }
|
|
83
|
+
// }, [processor, tools]);
|
|
84
|
+
|
|
85
|
+
return processor;
|
|
86
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Message } from '@dxos/artifact';
|
|
8
|
+
import { DXN, QueueSubspaceTags } from '@dxos/keys';
|
|
9
|
+
import { getSpace } from '@dxos/react-client/echo';
|
|
10
|
+
import { useEdgeClient, useQueue } from '@dxos/react-edge-client';
|
|
11
|
+
|
|
12
|
+
import { type AIChatType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const useMessageQueue = (chat: AIChatType) => {
|
|
15
|
+
const edgeClient = useEdgeClient();
|
|
16
|
+
const space = getSpace(chat);
|
|
17
|
+
const queueDxn = useMemo(
|
|
18
|
+
() => new DXN(DXN.kind.QUEUE, [QueueSubspaceTags.DATA, space!.id, chat.queue.dxn.parts.at(-1)!]),
|
|
19
|
+
[chat.queue.dxn],
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return useQueue<Message>(edgeClient, queueDxn);
|
|
23
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Space } from '@dxos/client/echo';
|
|
8
|
+
|
|
9
|
+
import { MockServiceRegistry } from '../testing';
|
|
10
|
+
import { type ServiceType, type ServiceQuery } from '../types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves matching services from the registry.
|
|
14
|
+
*/
|
|
15
|
+
export const useServices = (space: Space, query?: ServiceQuery): ServiceType[] => {
|
|
16
|
+
const registry = useMemo(() => new MockServiceRegistry(), []);
|
|
17
|
+
const [services, setServices] = useState<ServiceType[]>([]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const t = setTimeout(async () => {
|
|
20
|
+
const services = await registry.queryServices(query);
|
|
21
|
+
setServices(services);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return () => clearTimeout(t);
|
|
25
|
+
}, [query, registry]);
|
|
26
|
+
|
|
27
|
+
return services;
|
|
28
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { AutomationPlugin } from './AutomationPlugin';
|
|
6
|
-
|
|
7
|
-
export default AutomationPlugin;
|
|
8
|
-
|
|
9
5
|
export * from './AutomationPlugin';
|
|
10
6
|
export * from './components';
|
|
7
|
+
export * from './meta';
|
|
11
8
|
export * from './presets';
|
|
12
9
|
export * from './types';
|
package/src/meta.ts
CHANGED
|
@@ -6,10 +6,13 @@ import { type PluginMeta } from '@dxos/app-framework';
|
|
|
6
6
|
|
|
7
7
|
export const AUTOMATION_PLUGIN = 'dxos.org/plugin/automation';
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export const AMBIENT_CHAT_DIALOG = `${AUTOMATION_PLUGIN}/ambient-chat/dialog`;
|
|
10
|
+
|
|
11
|
+
export const meta = {
|
|
10
12
|
id: AUTOMATION_PLUGIN,
|
|
11
13
|
name: 'Automation',
|
|
12
|
-
description:
|
|
14
|
+
description:
|
|
15
|
+
'The Automation tab allows you to trigger pre-defined workflows related to the element you are interacting with inside of Composer.',
|
|
13
16
|
icon: 'ph--magic-wand--regular',
|
|
14
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-automation',
|
|
15
18
|
tags: ['experimental'],
|
package/src/testing/index.ts
CHANGED
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { createSystemPrompt } from '@dxos/artifact';
|
|
6
|
+
import { type GenerateRequest } from '@dxos/assistant';
|
|
5
7
|
import { AST, S, toJsonSchema } from '@dxos/echo-schema';
|
|
6
8
|
|
|
9
|
+
export const createProcessorOptions = (artifacts: string[]): Pick<GenerateRequest, 'model' | 'systemPrompt'> => ({
|
|
10
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
11
|
+
systemPrompt: createSystemPrompt({ artifacts }),
|
|
12
|
+
});
|
|
13
|
+
|
|
7
14
|
export const functions = [
|
|
8
15
|
{
|
|
9
16
|
name: 'example.com/function/chess',
|
|
10
|
-
version: '0.0
|
|
17
|
+
version: '0.1.0',
|
|
11
18
|
inputSchema: toJsonSchema(
|
|
12
19
|
S.Struct({
|
|
13
20
|
level: S.Number.annotations({
|
|
@@ -18,7 +25,7 @@ export const functions = [
|
|
|
18
25
|
},
|
|
19
26
|
{
|
|
20
27
|
name: 'example.com/function/forex',
|
|
21
|
-
version: '0.0
|
|
28
|
+
version: '0.1.0',
|
|
22
29
|
binding: 'FOREX',
|
|
23
30
|
inputSchema: toJsonSchema(
|
|
24
31
|
S.Struct({
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createStatic } from '@dxos/echo-schema';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type ApiAuthorization,
|
|
9
|
+
type BaseServiceRegistry,
|
|
10
|
+
type ServiceQuery,
|
|
11
|
+
ServiceType,
|
|
12
|
+
categoryIcons,
|
|
13
|
+
} from '../types';
|
|
14
|
+
|
|
15
|
+
export class MockServiceRegistry implements BaseServiceRegistry {
|
|
16
|
+
async queryServices(query?: ServiceQuery): Promise<ServiceType[]> {
|
|
17
|
+
return TEST_SERVICES;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// TODO(burdon): Can we generalize credentials?
|
|
22
|
+
|
|
23
|
+
const AMADEUS_AUTH: ApiAuthorization = {
|
|
24
|
+
type: 'oauth',
|
|
25
|
+
clientId: 'BOEnpLd1sMyKjAPGKYeAPFFy60u53QEG',
|
|
26
|
+
clientSecret: 'n4qldSN7usvD57gm',
|
|
27
|
+
tokenUrl: 'https://test.api.amadeus.com/v1/security/oauth2/token',
|
|
28
|
+
grantType: 'client_credentials',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const VISUAL_CROSSING_CREDENTIALS: ApiAuthorization = {
|
|
32
|
+
type: 'api-key',
|
|
33
|
+
key: 'FDPRVS953KB4GQQLD25GRT975',
|
|
34
|
+
placement: {
|
|
35
|
+
type: 'query',
|
|
36
|
+
name: 'key',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Registries:
|
|
41
|
+
// - https://apis.guru
|
|
42
|
+
// - https://rapidapi.com
|
|
43
|
+
// - https://github.com/konfig-sdks/openapi-examples
|
|
44
|
+
// - https://publicapis.io/?utm_source=chatgpt.com
|
|
45
|
+
|
|
46
|
+
// Examples:
|
|
47
|
+
// - https://petstore.swagger.io/v2/swagger.json (testing)
|
|
48
|
+
// - https://lichess.org/api
|
|
49
|
+
// - https://github.com/konfig-sdks/openapi-examples/tree/main/xkcd
|
|
50
|
+
// - https://api.coindesk.com/v1/bpi/currentprice.json
|
|
51
|
+
// - https://www.coingecko.com/en/api/documentation
|
|
52
|
+
|
|
53
|
+
// TODO(burdon): Support yaml endpoints.
|
|
54
|
+
// - e.g., https://github.com/konfig-sdks/openapi-examples/blob/main/xkcd/openapi.yaml
|
|
55
|
+
|
|
56
|
+
const TEST_SERVICES: ServiceType[] = [
|
|
57
|
+
createStatic(ServiceType, {
|
|
58
|
+
serviceId: 'amadeus.com/service/FlightSearch',
|
|
59
|
+
name: 'Amadeus Flight Search',
|
|
60
|
+
description: 'Search for local and international flights.',
|
|
61
|
+
category: 'travel',
|
|
62
|
+
interfaces: [
|
|
63
|
+
{
|
|
64
|
+
kind: 'api',
|
|
65
|
+
schemaUrl: 'https://api.apis.guru/v2/specs/amadeus.com/amadeus-flight-availabilities-search/1.0.2/swagger.json',
|
|
66
|
+
authorization: AMADEUS_AUTH,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
}),
|
|
70
|
+
|
|
71
|
+
createStatic(ServiceType, {
|
|
72
|
+
serviceId: 'amadeus.com/service/HotelSearch',
|
|
73
|
+
name: 'Amadeus Hotel Search',
|
|
74
|
+
description: 'Search for local and international hotels.',
|
|
75
|
+
category: 'travel',
|
|
76
|
+
interfaces: [
|
|
77
|
+
{
|
|
78
|
+
kind: 'api',
|
|
79
|
+
schemaUrl: 'https://api.apis.guru/v2/specs/amadeus.com/amadeus-hotel-search/3.0.8/swagger.json',
|
|
80
|
+
authorization: AMADEUS_AUTH,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
|
+
createStatic(ServiceType, {
|
|
86
|
+
serviceId: 'visualcrossing.com/service/Weather',
|
|
87
|
+
name: 'Visual Crossing Weather',
|
|
88
|
+
description: 'Search for global weather forecasts.',
|
|
89
|
+
category: 'weather',
|
|
90
|
+
interfaces: [
|
|
91
|
+
{
|
|
92
|
+
kind: 'api',
|
|
93
|
+
schemaUrl: 'https://api.apis.guru/v2/specs/visualcrossing.com/weather/4.6/openapi.json',
|
|
94
|
+
authorization: VISUAL_CROSSING_CREDENTIALS,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
98
|
+
|
|
99
|
+
// TODO(burdon): Needs auth.
|
|
100
|
+
createStatic(ServiceType, {
|
|
101
|
+
serviceId: 'abstractapi.com/service/GeoLocation',
|
|
102
|
+
name: 'Abstract GeoLocation',
|
|
103
|
+
description: 'Get the location of any IP address.',
|
|
104
|
+
category: 'geolocation',
|
|
105
|
+
interfaces: [
|
|
106
|
+
{
|
|
107
|
+
kind: 'api',
|
|
108
|
+
schemaUrl: 'https://api.apis.guru/v2/specs/abstractapi.com/geolocation/1.0.0/openapi.json',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
}),
|
|
112
|
+
|
|
113
|
+
//
|
|
114
|
+
// Testing
|
|
115
|
+
//
|
|
116
|
+
|
|
117
|
+
...Array.from({ length: 20 }, (_, i) =>
|
|
118
|
+
createStatic(ServiceType, {
|
|
119
|
+
serviceId: `example.com/service/test-${i}`,
|
|
120
|
+
name: `Test ${i}`,
|
|
121
|
+
description: `Test ${i}`,
|
|
122
|
+
category: Object.keys(categoryIcons)[Math.floor(Math.random() * Object.keys(categoryIcons).length)],
|
|
123
|
+
interfaces: [
|
|
124
|
+
{
|
|
125
|
+
kind: 'api',
|
|
126
|
+
schemaUrl: 'https://petstore.swagger.io/v2/swagger.json',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
}),
|
|
130
|
+
),
|
|
131
|
+
] as const;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { defineTool, ToolResult } from '@dxos/artifact';
|
|
6
|
+
import type { Tool } from '@dxos/artifact';
|
|
7
|
+
import { toEffectSchema } from '@dxos/echo-schema';
|
|
8
|
+
import { getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
9
|
+
import type { FunctionType } from '@dxos/functions';
|
|
10
|
+
import { log } from '@dxos/log';
|
|
11
|
+
import type { SpaceId } from '@dxos/react-client/echo';
|
|
12
|
+
import { getMeta } from '@dxos/react-client/echo';
|
|
13
|
+
|
|
14
|
+
export const covertFunctionToTool = (
|
|
15
|
+
fn: FunctionType,
|
|
16
|
+
edgeUrl: string,
|
|
17
|
+
spaceId?: SpaceId | undefined,
|
|
18
|
+
): Tool | undefined => {
|
|
19
|
+
if (!fn.description || !fn.inputSchema) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
24
|
+
if (!existingFunctionUrl) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
|
|
28
|
+
spaceId,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return defineTool({
|
|
32
|
+
name: fn.name,
|
|
33
|
+
description: fn.description,
|
|
34
|
+
schema: toEffectSchema(fn.inputSchema),
|
|
35
|
+
execute: async (input) => {
|
|
36
|
+
log.info('execute function tool', { name: fn.name, url, input });
|
|
37
|
+
const response = await fetch(url, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify(input),
|
|
43
|
+
});
|
|
44
|
+
return ToolResult.Success(await response.text());
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|