@dxos/plugin-assistant 0.8.3 → 0.8.4-main.f9ba587
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/ChatContainer-6XNB5NEI.mjs +57 -0
- package/dist/lib/browser/ChatContainer-6XNB5NEI.mjs.map +7 -0
- package/dist/lib/browser/ChatDialog-IMWPRXTO.mjs +74 -0
- package/dist/lib/browser/ChatDialog-IMWPRXTO.mjs.map +7 -0
- package/dist/lib/browser/{BlueprintContainer-AT5Y7EXG.mjs → SequenceContainer-6XOYB2RN.mjs} +38 -37
- package/dist/lib/browser/SequenceContainer-6XOYB2RN.mjs.map +7 -0
- package/dist/lib/browser/{TemplateContainer-QQHVOTSI.mjs → TemplateContainer-6ZGGH5T4.mjs} +4 -4
- package/dist/lib/browser/TemplateContainer-6ZGGH5T4.mjs.map +7 -0
- package/dist/lib/browser/{ai-client-MK2ZZII2.mjs → ai-client-ML7OQWAO.mjs} +6 -6
- package/dist/lib/browser/ai-client-ML7OQWAO.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-E4H5DCOJ.mjs → app-graph-builder-UJ5NHRGK.mjs} +31 -33
- package/dist/lib/browser/app-graph-builder-UJ5NHRGK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JQFUME3B.mjs → chunk-44HZKIAW.mjs} +5 -5
- package/dist/lib/browser/chunk-44HZKIAW.mjs.map +7 -0
- package/dist/lib/browser/{chunk-XOZ7YMO3.mjs → chunk-LKP65RPA.mjs} +2 -2
- package/dist/lib/browser/chunk-NTBGTFTV.mjs +15 -0
- package/dist/lib/browser/chunk-NTBGTFTV.mjs.map +7 -0
- package/dist/lib/browser/{chunk-BI6AHRNJ.mjs → chunk-OZL4OHTU.mjs} +15 -15
- package/dist/lib/browser/chunk-OZL4OHTU.mjs.map +7 -0
- package/dist/lib/browser/chunk-TQ3QW3HJ.mjs +2072 -0
- package/dist/lib/browser/chunk-TQ3QW3HJ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-AAOKC2JN.mjs → chunk-TU7UUGWQ.mjs} +68 -73
- package/dist/lib/browser/chunk-TU7UUGWQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-WPZ4UANI.mjs +16 -0
- package/dist/lib/browser/index.mjs +53 -68
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-3UICTGPM.mjs → intent-resolver-LEAPB55Q.mjs} +10 -11
- package/dist/lib/browser/intent-resolver-LEAPB55Q.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-LXCNUSZN.mjs → react-surface-TMF7JJA4.mjs} +34 -37
- package/dist/lib/browser/react-surface-TMF7JJA4.mjs.map +7 -0
- package/dist/lib/browser/{settings-XRHXVWGB.mjs → settings-N4HEXADL.mjs} +6 -6
- package/dist/lib/browser/settings-N4HEXADL.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -10
- package/dist/lib/node-esm/ChatContainer-VOLG7J6N.mjs +58 -0
- package/dist/lib/node-esm/ChatContainer-VOLG7J6N.mjs.map +7 -0
- package/dist/lib/node-esm/ChatDialog-B2XNUNRM.mjs +75 -0
- package/dist/lib/node-esm/ChatDialog-B2XNUNRM.mjs.map +7 -0
- package/dist/lib/node-esm/{BlueprintContainer-STOJAVML.mjs → SequenceContainer-WWG6IMN3.mjs} +38 -37
- package/dist/lib/node-esm/SequenceContainer-WWG6IMN3.mjs.map +7 -0
- package/dist/lib/node-esm/{TemplateContainer-SOEWY2ZN.mjs → TemplateContainer-6KRNEMVE.mjs} +4 -4
- package/dist/lib/node-esm/TemplateContainer-6KRNEMVE.mjs.map +7 -0
- package/dist/lib/node-esm/{ai-client-XGZBJ6BE.mjs → ai-client-2FQ434CT.mjs} +6 -6
- package/dist/lib/node-esm/ai-client-2FQ434CT.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-3SY5MBIK.mjs → app-graph-builder-MEQ5CYNI.mjs} +31 -33
- package/dist/lib/node-esm/app-graph-builder-MEQ5CYNI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-D3HTVK5D.mjs +2073 -0
- package/dist/lib/node-esm/chunk-D3HTVK5D.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-3UEZLJ2V.mjs → chunk-E6V2RUQ2.mjs} +5 -5
- package/dist/lib/node-esm/chunk-E6V2RUQ2.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-UCOFKNKN.mjs → chunk-HVMVHP4R.mjs} +15 -15
- package/dist/lib/node-esm/chunk-HVMVHP4R.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HXKRKIN2.mjs +18 -0
- package/dist/lib/node-esm/{chunk-BB2TAT4P.mjs → chunk-KOC6ESG7.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-OYN6HLXZ.mjs → chunk-VESVUAOS.mjs} +5 -5
- package/dist/lib/node-esm/chunk-VESVUAOS.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-J6UXXZGJ.mjs → chunk-YYUVTTVK.mjs} +68 -73
- package/dist/lib/node-esm/chunk-YYUVTTVK.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +53 -68
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-E6MXTYAU.mjs → intent-resolver-4ULF3F7U.mjs} +10 -11
- package/dist/lib/node-esm/intent-resolver-4ULF3F7U.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-7HA5EDWY.mjs → react-surface-6XL6SWL2.mjs} +34 -37
- package/dist/lib/node-esm/react-surface-6XL6SWL2.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-5IAY6BT4.mjs → settings-WQ76EG6O.mjs} +6 -6
- package/dist/lib/node-esm/settings-WQ76EG6O.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +4 -10
- package/dist/types/src/capabilities/ai-client.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts +2 -2
- package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts.map +1 -1
- package/dist/types/src/components/Chat/Chat.d.ts +42 -0
- package/dist/types/src/components/Chat/Chat.d.ts.map +1 -0
- package/dist/types/src/components/Chat/index.d.ts +2 -0
- package/dist/types/src/components/Chat/index.d.ts.map +1 -0
- package/dist/types/src/components/ChatContainer.d.ts +5 -5
- package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
- package/dist/types/src/components/ChatDialog.d.ts +8 -0
- package/dist/types/src/components/ChatDialog.d.ts.map +1 -0
- package/dist/types/src/components/ChatPrompt/ChatActions.d.ts +10 -0
- package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -0
- package/dist/types/src/components/ChatPrompt/ChatOptionsMenu.d.ts +9 -0
- package/dist/types/src/components/ChatPrompt/ChatOptionsMenu.d.ts.map +1 -0
- package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts +11 -0
- package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts.map +1 -0
- package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts +7 -0
- package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts.map +1 -0
- package/dist/types/src/components/ChatPrompt/events.d.ts +17 -0
- package/dist/types/src/components/ChatPrompt/events.d.ts.map +1 -0
- package/dist/types/src/components/ChatPrompt/index.d.ts +6 -0
- package/dist/types/src/components/ChatPrompt/index.d.ts.map +1 -0
- package/dist/types/src/components/{Thread/ThreadMessage.d.ts → ChatThread/ChatMessage.d.ts} +6 -4
- package/dist/types/src/components/ChatThread/ChatMessage.d.ts.map +1 -0
- package/dist/types/src/components/ChatThread/ChatThread.d.ts +25 -0
- package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -0
- package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +232 -0
- package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -0
- package/dist/types/src/components/ChatThread/ToolBlock.d.ts +18 -0
- package/dist/types/src/components/ChatThread/ToolBlock.d.ts.map +1 -0
- package/dist/types/src/components/ChatThread/index.d.ts +2 -0
- package/dist/types/src/components/ChatThread/index.d.ts.map +1 -0
- package/dist/types/src/components/ChatThread/reducer.d.ts.map +1 -0
- package/dist/types/src/components/SequenceContainer.d.ts +9 -0
- package/dist/types/src/components/SequenceContainer.d.ts.map +1 -0
- package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts +13 -0
- package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts.map +1 -0
- package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts +8 -0
- package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/SequenceEditor/index.d.ts +2 -0
- package/dist/types/src/components/SequenceEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/TemplateContainer.d.ts +4 -3
- package/dist/types/src/components/TemplateContainer.d.ts.map +1 -1
- package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
- package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +1 -1
- package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbox/Toolbox.d.ts +10 -3
- package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
- package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +1 -1
- package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +6 -12
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts.map +1 -1
- package/dist/types/src/hooks/{processor.d.ts → chat-processor.d.ts} +27 -17
- package/dist/types/src/hooks/chat-processor.d.ts.map +1 -0
- package/dist/types/src/hooks/chat-processor.test.d.ts +2 -0
- package/dist/types/src/hooks/chat-processor.test.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +4 -4
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useBlueprints.d.ts +4 -0
- package/dist/types/src/hooks/useBlueprints.d.ts.map +1 -0
- package/dist/types/src/hooks/useChatProcessor.d.ts +20 -6
- package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
- package/dist/types/src/hooks/useContextProvider.d.ts +6 -0
- package/dist/types/src/hooks/useContextProvider.d.ts.map +1 -1
- package/dist/types/src/hooks/useServiceContainer.d.ts +8 -0
- package/dist/types/src/hooks/useServiceContainer.d.ts.map +1 -0
- package/dist/types/src/queue-logger.d.ts +5 -5
- package/dist/types/src/queue-logger.d.ts.map +1 -1
- package/dist/types/src/stories/Chat.stories.d.ts +199 -0
- package/dist/types/src/stories/Chat.stories.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-sequence.d.ts +8 -0
- package/dist/types/src/testing/test-sequence.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +61 -113
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +71 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/types/service.d.ts +6 -6
- package/dist/types/src/types/service.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +76 -74
- package/src/AssistantPlugin.tsx +13 -13
- package/src/capabilities/ai-client.ts +3 -6
- package/src/capabilities/app-graph-builder.ts +30 -26
- package/src/capabilities/capabilities.ts +2 -3
- package/src/capabilities/intent-resolver.ts +6 -6
- package/src/capabilities/react-surface.tsx +29 -29
- package/src/capabilities/settings.ts +3 -3
- package/src/components/AssistantSettings/AssistantSettings.tsx +4 -4
- package/src/components/Chat/Chat.tsx +348 -0
- package/src/{experimental/transcription → components/Chat}/index.ts +2 -0
- package/src/components/ChatContainer.tsx +24 -18
- package/src/components/ChatDialog.tsx +65 -0
- package/src/components/ChatPrompt/ChatActions.tsx +76 -0
- package/src/components/ChatPrompt/ChatOptionsMenu.tsx +52 -0
- package/src/components/ChatPrompt/ChatReferences.tsx +52 -0
- package/src/components/ChatPrompt/ChatStatusIndicator.tsx +26 -0
- package/src/components/ChatPrompt/events.ts +12 -0
- package/src/components/ChatPrompt/index.ts +10 -0
- package/src/components/{Thread/ThreadMessage.tsx → ChatThread/ChatMessage.tsx} +35 -31
- package/src/components/ChatThread/ChatThread.stories.tsx +148 -0
- package/src/components/ChatThread/ChatThread.tsx +68 -0
- package/src/components/{Thread/ToolInvocations.tsx → ChatThread/ToolBlock.tsx} +13 -8
- package/src/components/{AmbientDialog → ChatThread}/index.ts +1 -1
- package/src/components/PromptSettings.tsx +2 -2
- package/src/components/{BlueprintContainer.tsx → SequenceContainer.tsx} +23 -32
- package/src/components/SequenceEditor/SequenceEditor.stories.tsx +32 -0
- package/src/components/{BlueprintEditor/BlueprintEditor.tsx → SequenceEditor/SequenceEditor.tsx} +7 -7
- package/src/components/SequenceEditor/index.ts +5 -0
- package/src/components/TemplateContainer.tsx +7 -5
- package/src/components/TemplateEditor/TemplateEditor.stories.tsx +2 -2
- package/src/components/TemplateEditor/TemplateEditor.tsx +2 -2
- package/src/components/TemplateEditor/TemplateForm.stories.tsx +2 -2
- package/src/components/TemplateEditor/TemplateForm.tsx +2 -3
- package/src/components/Toolbox/Toolbox.stories.tsx +4 -5
- package/src/components/Toolbox/Toolbox.tsx +56 -3
- package/src/components/index.ts +4 -5
- package/src/events.ts +2 -2
- package/src/hooks/{processor.test.ts → chat-processor.test.ts} +1 -1
- package/src/hooks/{processor.ts → chat-processor.ts} +115 -72
- package/src/hooks/index.ts +4 -4
- package/src/hooks/useBlueprints.ts +31 -0
- package/src/hooks/useChatProcessor.tsx +69 -24
- package/src/hooks/useContextProvider.ts +8 -2
- package/src/hooks/useServiceContainer.ts +42 -0
- package/src/queue-logger.ts +6 -6
- package/src/stories/Chat.stories.tsx +269 -0
- package/src/testing/index.ts +1 -1
- package/src/testing/{test-blueprint.ts → test-sequence.ts} +4 -9
- package/src/tools/openapi.test.ts +11 -11
- package/src/translations.ts +24 -22
- package/src/types/index.ts +1 -2
- package/src/types/schema.ts +86 -0
- package/dist/lib/browser/AssistantDialog-MQOOR364.mjs +0 -47
- package/dist/lib/browser/AssistantDialog-MQOOR364.mjs.map +0 -7
- package/dist/lib/browser/BlueprintContainer-AT5Y7EXG.mjs.map +0 -7
- package/dist/lib/browser/ChatContainer-C2NEAS3A.mjs +0 -40
- package/dist/lib/browser/ChatContainer-C2NEAS3A.mjs.map +0 -7
- package/dist/lib/browser/TemplateContainer-QQHVOTSI.mjs.map +0 -7
- package/dist/lib/browser/ai-client-MK2ZZII2.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-E4H5DCOJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-AAOKC2JN.mjs.map +0 -7
- package/dist/lib/browser/chunk-BI6AHRNJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-JO4W3MF7.mjs +0 -2101
- package/dist/lib/browser/chunk-JO4W3MF7.mjs.map +0 -7
- package/dist/lib/browser/chunk-JQFUME3B.mjs.map +0 -7
- package/dist/lib/browser/chunk-MEGMOFJB.mjs +0 -16
- package/dist/lib/browser/chunk-Q6UZ4F3H.mjs +0 -96
- package/dist/lib/browser/chunk-Q6UZ4F3H.mjs.map +0 -7
- package/dist/lib/browser/chunk-UE3IZ4PN.mjs +0 -15
- package/dist/lib/browser/chunk-UE3IZ4PN.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-3UICTGPM.mjs.map +0 -7
- package/dist/lib/browser/react-surface-LXCNUSZN.mjs.map +0 -7
- package/dist/lib/browser/settings-XRHXVWGB.mjs.map +0 -7
- package/dist/lib/node/AssistantDialog-AN4Z6YUV.cjs +0 -73
- package/dist/lib/node/AssistantDialog-AN4Z6YUV.cjs.map +0 -7
- package/dist/lib/node/BlueprintContainer-NOWLDYCZ.cjs +0 -344
- package/dist/lib/node/BlueprintContainer-NOWLDYCZ.cjs.map +0 -7
- package/dist/lib/node/ChatContainer-VKYBQHUB.cjs +0 -68
- package/dist/lib/node/ChatContainer-VKYBQHUB.cjs.map +0 -7
- package/dist/lib/node/TemplateContainer-JZF2DCCG.cjs +0 -58
- package/dist/lib/node/TemplateContainer-JZF2DCCG.cjs.map +0 -7
- package/dist/lib/node/ai-client-7HNSMUMT.cjs +0 -53
- package/dist/lib/node/ai-client-7HNSMUMT.cjs.map +0 -7
- package/dist/lib/node/app-graph-builder-PPR5B5KU.cjs +0 -235
- package/dist/lib/node/app-graph-builder-PPR5B5KU.cjs.map +0 -7
- package/dist/lib/node/chunk-4EEWTDQK.cjs +0 -117
- package/dist/lib/node/chunk-4EEWTDQK.cjs.map +0 -7
- package/dist/lib/node/chunk-FUAGEO7Q.cjs +0 -52
- package/dist/lib/node/chunk-FUAGEO7Q.cjs.map +0 -7
- package/dist/lib/node/chunk-HRNIUYVQ.cjs +0 -128
- package/dist/lib/node/chunk-HRNIUYVQ.cjs.map +0 -7
- package/dist/lib/node/chunk-IKZBMHSW.cjs +0 -184
- package/dist/lib/node/chunk-IKZBMHSW.cjs.map +0 -7
- package/dist/lib/node/chunk-LMDJEGZ2.cjs +0 -233
- package/dist/lib/node/chunk-LMDJEGZ2.cjs.map +0 -7
- package/dist/lib/node/chunk-NIDICM57.cjs +0 -2080
- package/dist/lib/node/chunk-NIDICM57.cjs.map +0 -7
- package/dist/lib/node/chunk-P74TWGMG.cjs +0 -44
- package/dist/lib/node/chunk-P74TWGMG.cjs.map +0 -7
- package/dist/lib/node/chunk-QGPWY6GW.cjs +0 -34
- package/dist/lib/node/chunk-QGPWY6GW.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -289
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-QSWGTKON.cjs +0 -58
- package/dist/lib/node/intent-resolver-QSWGTKON.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/react-surface-D3NBYRZ6.cjs +0 -172
- package/dist/lib/node/react-surface-D3NBYRZ6.cjs.map +0 -7
- package/dist/lib/node/settings-2JXLKYGE.cjs +0 -36
- package/dist/lib/node/settings-2JXLKYGE.cjs.map +0 -7
- package/dist/lib/node/types/index.cjs +0 -54
- package/dist/lib/node/types/index.cjs.map +0 -7
- package/dist/lib/node-esm/AssistantDialog-6WEMLUPU.mjs +0 -48
- package/dist/lib/node-esm/AssistantDialog-6WEMLUPU.mjs.map +0 -7
- package/dist/lib/node-esm/BlueprintContainer-STOJAVML.mjs.map +0 -7
- package/dist/lib/node-esm/ChatContainer-3MVBTUJN.mjs +0 -41
- package/dist/lib/node-esm/ChatContainer-3MVBTUJN.mjs.map +0 -7
- package/dist/lib/node-esm/TemplateContainer-SOEWY2ZN.mjs.map +0 -7
- package/dist/lib/node-esm/ai-client-XGZBJ6BE.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-3SY5MBIK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-34EX6E5Q.mjs +0 -18
- package/dist/lib/node-esm/chunk-3UEZLJ2V.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CDAILLCU.mjs +0 -98
- package/dist/lib/node-esm/chunk-CDAILLCU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-J6UXXZGJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OD574YIU.mjs +0 -2102
- package/dist/lib/node-esm/chunk-OD574YIU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OYN6HLXZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UCOFKNKN.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-E6MXTYAU.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-7HA5EDWY.mjs.map +0 -7
- package/dist/lib/node-esm/settings-5IAY6BT4.mjs.map +0 -7
- package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts +0 -10
- package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts.map +0 -1
- package/dist/types/src/components/AmbientDialog/AmbientDialog.stories.d.ts +0 -8
- package/dist/types/src/components/AmbientDialog/AmbientDialog.stories.d.ts.map +0 -1
- package/dist/types/src/components/AmbientDialog/index.d.ts +0 -2
- package/dist/types/src/components/AmbientDialog/index.d.ts.map +0 -1
- package/dist/types/src/components/AssistantDialog.d.ts +0 -7
- package/dist/types/src/components/AssistantDialog.d.ts.map +0 -1
- package/dist/types/src/components/BlueprintContainer.d.ts +0 -9
- package/dist/types/src/components/BlueprintContainer.d.ts.map +0 -1
- package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts +0 -13
- package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts.map +0 -1
- package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts +0 -8
- package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/BlueprintEditor/index.d.ts +0 -2
- package/dist/types/src/components/BlueprintEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/Prompt.d.ts +0 -23
- package/dist/types/src/components/Prompt/Prompt.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/Prompt.stories.d.ts +0 -13
- package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/PromptBar.d.ts +0 -16
- package/dist/types/src/components/Prompt/PromptBar.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/PromptBar.stories.d.ts +0 -9
- package/dist/types/src/components/Prompt/PromptBar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/autocomplete.d.ts +0 -25
- package/dist/types/src/components/Prompt/autocomplete.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/index.d.ts +0 -3
- package/dist/types/src/components/Prompt/index.d.ts.map +0 -1
- package/dist/types/src/components/Prompt/references.d.ts +0 -30
- package/dist/types/src/components/Prompt/references.d.ts.map +0 -1
- package/dist/types/src/components/Thread/Thread.d.ts +0 -28
- package/dist/types/src/components/Thread/Thread.d.ts.map +0 -1
- package/dist/types/src/components/Thread/Thread.stories.d.ts +0 -11
- package/dist/types/src/components/Thread/Thread.stories.d.ts.map +0 -1
- package/dist/types/src/components/Thread/ThreadContainer.d.ts +0 -13
- package/dist/types/src/components/Thread/ThreadContainer.d.ts.map +0 -1
- package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts +0 -16
- package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts.map +0 -1
- package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +0 -1
- package/dist/types/src/components/Thread/ToolInvocations.d.ts +0 -13
- package/dist/types/src/components/Thread/ToolInvocations.d.ts.map +0 -1
- package/dist/types/src/components/Thread/index.d.ts +0 -3
- package/dist/types/src/components/Thread/index.d.ts.map +0 -1
- package/dist/types/src/components/Thread/reducer.d.ts.map +0 -1
- package/dist/types/src/experimental/transcription/index.d.ts +0 -1
- package/dist/types/src/experimental/transcription/index.d.ts.map +0 -1
- package/dist/types/src/hooks/processor.d.ts.map +0 -1
- package/dist/types/src/hooks/processor.test.d.ts +0 -2
- package/dist/types/src/hooks/processor.test.d.ts.map +0 -1
- package/dist/types/src/hooks/useMessageQueue.d.ts +0 -42
- package/dist/types/src/hooks/useMessageQueue.d.ts.map +0 -1
- package/dist/types/src/hooks/useServices.d.ts +0 -7
- package/dist/types/src/hooks/useServices.d.ts.map +0 -1
- package/dist/types/src/stories/Prompt.stories.d.ts +0 -8
- package/dist/types/src/stories/Prompt.stories.d.ts.map +0 -1
- package/dist/types/src/stories/Query.stories.d.ts +0 -19
- package/dist/types/src/stories/Query.stories.d.ts.map +0 -1
- package/dist/types/src/stories/Research.stories.d.ts +0 -15
- package/dist/types/src/stories/Research.stories.d.ts.map +0 -1
- package/dist/types/src/stories/test-data.d.ts +0 -3
- package/dist/types/src/stories/test-data.d.ts.map +0 -1
- package/dist/types/src/stories/testing.d.ts +0 -12
- package/dist/types/src/stories/testing.d.ts.map +0 -1
- package/dist/types/src/testing/test-blueprint.d.ts +0 -8
- package/dist/types/src/testing/test-blueprint.d.ts.map +0 -1
- package/dist/types/src/types/chat.d.ts +0 -23
- package/dist/types/src/types/chat.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -50
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/components/AmbientDialog/AmbientDialog.stories.tsx +0 -84
- package/src/components/AmbientDialog/AmbientDialog.tsx +0 -117
- package/src/components/AssistantDialog.tsx +0 -37
- package/src/components/BlueprintEditor/BlueprintEditor.stories.tsx +0 -32
- package/src/components/BlueprintEditor/index.ts +0 -5
- package/src/components/Prompt/Prompt.stories.tsx +0 -121
- package/src/components/Prompt/Prompt.tsx +0 -124
- package/src/components/Prompt/PromptBar.stories.tsx +0 -69
- package/src/components/Prompt/PromptBar.tsx +0 -105
- package/src/components/Prompt/autocomplete.ts +0 -218
- package/src/components/Prompt/index.ts +0 -6
- package/src/components/Prompt/references.ts +0 -180
- package/src/components/Thread/Thread.stories.tsx +0 -201
- package/src/components/Thread/Thread.tsx +0 -118
- package/src/components/Thread/ThreadContainer.stories.tsx +0 -283
- package/src/components/Thread/ThreadContainer.tsx +0 -105
- package/src/components/Thread/index.ts +0 -6
- package/src/hooks/useMessageQueue.ts +0 -22
- package/src/hooks/useServices.ts +0 -28
- package/src/stories/Prompt.stories.tsx +0 -60
- package/src/stories/Query.stories.tsx +0 -514
- package/src/stories/Research.stories.tsx +0 -482
- package/src/stories/test-data.ts +0 -128
- package/src/stories/testing.ts +0 -60
- package/src/types/chat.ts +0 -32
- package/src/types/types.ts +0 -48
- /package/dist/lib/browser/{chunk-XOZ7YMO3.mjs.map → chunk-LKP65RPA.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-MEGMOFJB.mjs.map → chunk-WPZ4UANI.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-34EX6E5Q.mjs.map → chunk-HXKRKIN2.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-BB2TAT4P.mjs.map → chunk-KOC6ESG7.mjs.map} +0 -0
- /package/dist/types/src/components/{Thread → ChatThread}/reducer.d.ts +0 -0
- /package/src/components/{Thread → ChatThread}/reducer.ts +0 -0
|
@@ -0,0 +1,2072 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ServiceType
|
|
3
|
+
} from "./chunk-TU7UUGWQ.mjs";
|
|
4
|
+
import {
|
|
5
|
+
AssistantCapabilities
|
|
6
|
+
} from "./chunk-NTBGTFTV.mjs";
|
|
7
|
+
import {
|
|
8
|
+
meta
|
|
9
|
+
} from "./chunk-LKP65RPA.mjs";
|
|
10
|
+
|
|
11
|
+
// src/hooks/useChatProcessor.tsx
|
|
12
|
+
import { useEffect as useEffect2, useMemo as useMemo3, useState as useState4 } from "react";
|
|
13
|
+
import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL2, DEFAULT_OLLAMA_MODEL } from "@dxos/ai";
|
|
14
|
+
import { Capabilities as Capabilities3, useCapabilities as useCapabilities3, useIntentDispatcher } from "@dxos/app-framework";
|
|
15
|
+
import { createSystemPrompt } from "@dxos/artifact";
|
|
16
|
+
import { Conversation } from "@dxos/assistant";
|
|
17
|
+
import { FunctionType } from "@dxos/functions";
|
|
18
|
+
import { log as log5 } from "@dxos/log";
|
|
19
|
+
import { useConfig } from "@dxos/react-client";
|
|
20
|
+
import { Filter as Filter3, fullyQualifiedId, useQuery } from "@dxos/react-client/echo";
|
|
21
|
+
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
22
|
+
|
|
23
|
+
// src/hooks/chat-processor.ts
|
|
24
|
+
import { batch, computed, signal } from "@preact/signals-core";
|
|
25
|
+
import { DEFAULT_EDGE_MODEL } from "@dxos/ai";
|
|
26
|
+
import { Context } from "@dxos/context";
|
|
27
|
+
import { log } from "@dxos/log";
|
|
28
|
+
import { Filter, getVersion } from "@dxos/react-client/echo";
|
|
29
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
30
|
+
if (value !== null && value !== void 0) {
|
|
31
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
32
|
+
var dispose, inner;
|
|
33
|
+
if (async) {
|
|
34
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
35
|
+
dispose = value[Symbol.asyncDispose];
|
|
36
|
+
}
|
|
37
|
+
if (dispose === void 0) {
|
|
38
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
39
|
+
dispose = value[Symbol.dispose];
|
|
40
|
+
if (async) inner = dispose;
|
|
41
|
+
}
|
|
42
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
43
|
+
if (inner) dispose = function() {
|
|
44
|
+
try {
|
|
45
|
+
inner.call(this);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return Promise.reject(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
env.stack.push({
|
|
51
|
+
value,
|
|
52
|
+
dispose,
|
|
53
|
+
async
|
|
54
|
+
});
|
|
55
|
+
} else if (async) {
|
|
56
|
+
env.stack.push({
|
|
57
|
+
async: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function _ts_dispose_resources(env) {
|
|
63
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
64
|
+
var e = new Error(message);
|
|
65
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
66
|
+
};
|
|
67
|
+
return (_ts_dispose_resources = function _ts_dispose_resources2(env2) {
|
|
68
|
+
function fail(e) {
|
|
69
|
+
env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
|
|
70
|
+
env2.hasError = true;
|
|
71
|
+
}
|
|
72
|
+
var r, s = 0;
|
|
73
|
+
function next() {
|
|
74
|
+
while (r = env2.stack.pop()) {
|
|
75
|
+
try {
|
|
76
|
+
if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
|
|
77
|
+
if (r.dispose) {
|
|
78
|
+
var result = r.dispose.call(r.value);
|
|
79
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
80
|
+
fail(e);
|
|
81
|
+
return next();
|
|
82
|
+
});
|
|
83
|
+
} else s |= 1;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
fail(e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
|
|
89
|
+
if (env2.hasError) throw env2.error;
|
|
90
|
+
}
|
|
91
|
+
return next();
|
|
92
|
+
})(env);
|
|
93
|
+
}
|
|
94
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/chat-processor.ts";
|
|
95
|
+
var defaultOptions = {
|
|
96
|
+
model: DEFAULT_EDGE_MODEL,
|
|
97
|
+
systemPrompt: "you are a helpful assistant"
|
|
98
|
+
};
|
|
99
|
+
var ChatProcessor = class {
|
|
100
|
+
constructor(_conversation, _options = defaultOptions) {
|
|
101
|
+
this._conversation = _conversation;
|
|
102
|
+
this._options = _options;
|
|
103
|
+
this._pending = signal([]);
|
|
104
|
+
this._block = signal(void 0);
|
|
105
|
+
this.streaming = computed(() => this._block.value !== void 0);
|
|
106
|
+
this.error = signal(void 0);
|
|
107
|
+
this.messages = computed(() => {
|
|
108
|
+
const messages = [
|
|
109
|
+
...this._pending.value
|
|
110
|
+
];
|
|
111
|
+
if (this._block.value && messages.length) {
|
|
112
|
+
const { content, ...rest } = messages.pop();
|
|
113
|
+
const message = {
|
|
114
|
+
...rest,
|
|
115
|
+
content: [
|
|
116
|
+
...content,
|
|
117
|
+
this._block.value
|
|
118
|
+
]
|
|
119
|
+
};
|
|
120
|
+
messages.push(message);
|
|
121
|
+
}
|
|
122
|
+
return messages;
|
|
123
|
+
});
|
|
124
|
+
this._session = void 0;
|
|
125
|
+
this._artifactDiffResolver = async (artifacts) => {
|
|
126
|
+
const space = this._options.extensions?.space;
|
|
127
|
+
if (!space) {
|
|
128
|
+
return /* @__PURE__ */ new Map();
|
|
129
|
+
}
|
|
130
|
+
const versions = /* @__PURE__ */ new Map();
|
|
131
|
+
await Promise.all(artifacts.map(async (artifact) => {
|
|
132
|
+
const { objects: [object] } = await space.db.query(Filter.ids(artifact.id)).run();
|
|
133
|
+
if (!object) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
versions.set(artifact.id, {
|
|
137
|
+
version: getVersion(object),
|
|
138
|
+
diff: `Current state: ${JSON.stringify(object)}`
|
|
139
|
+
});
|
|
140
|
+
}));
|
|
141
|
+
return versions;
|
|
142
|
+
};
|
|
143
|
+
this._tools = [
|
|
144
|
+
..._options.tools ?? []
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
get conversation() {
|
|
148
|
+
return this._conversation;
|
|
149
|
+
}
|
|
150
|
+
get context() {
|
|
151
|
+
return this._conversation.context;
|
|
152
|
+
}
|
|
153
|
+
get blueprintRegistry() {
|
|
154
|
+
return this._options.blueprintRegistry;
|
|
155
|
+
}
|
|
156
|
+
get tools() {
|
|
157
|
+
return this._tools;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated Replace with blueprints
|
|
161
|
+
*/
|
|
162
|
+
setTools(tools) {
|
|
163
|
+
this._tools = tools;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Make GPT request.
|
|
167
|
+
*/
|
|
168
|
+
async request(message, options = {}) {
|
|
169
|
+
const env = {
|
|
170
|
+
stack: [],
|
|
171
|
+
error: void 0,
|
|
172
|
+
hasError: false
|
|
173
|
+
};
|
|
174
|
+
try {
|
|
175
|
+
const ctx = _ts_add_disposable_resource(env, Context.default(void 0, {
|
|
176
|
+
F: __dxlog_file,
|
|
177
|
+
L: 140
|
|
178
|
+
}), true);
|
|
179
|
+
this._conversation.onBegin.on(ctx, (session) => {
|
|
180
|
+
log.info("onBegin", {
|
|
181
|
+
session,
|
|
182
|
+
isDisposed: ctx.disposed
|
|
183
|
+
}, {
|
|
184
|
+
F: __dxlog_file,
|
|
185
|
+
L: 143,
|
|
186
|
+
S: this,
|
|
187
|
+
C: (f, a) => f(...a)
|
|
188
|
+
});
|
|
189
|
+
this._session = session;
|
|
190
|
+
ctx.onDispose(() => {
|
|
191
|
+
log.info("onDispose", {
|
|
192
|
+
session,
|
|
193
|
+
isDisposed: ctx.disposed
|
|
194
|
+
}, {
|
|
195
|
+
F: __dxlog_file,
|
|
196
|
+
L: 147,
|
|
197
|
+
S: this,
|
|
198
|
+
C: (f, a) => f(...a)
|
|
199
|
+
});
|
|
200
|
+
if (this._session === session) {
|
|
201
|
+
this._session = void 0;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
session.message.on((message2) => {
|
|
205
|
+
batch(() => {
|
|
206
|
+
this._pending.value = [
|
|
207
|
+
...this._pending.value,
|
|
208
|
+
message2
|
|
209
|
+
];
|
|
210
|
+
this._block.value = void 0;
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
session.update.on((block) => {
|
|
214
|
+
batch(() => {
|
|
215
|
+
this._block.value = block;
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
session.userMessage.on((message2) => {
|
|
219
|
+
log.info("userMessage", {
|
|
220
|
+
message: message2
|
|
221
|
+
}, {
|
|
222
|
+
F: __dxlog_file,
|
|
223
|
+
L: 169,
|
|
224
|
+
S: this,
|
|
225
|
+
C: (f, a) => f(...a)
|
|
226
|
+
});
|
|
227
|
+
this._pending.value = [
|
|
228
|
+
...this._pending.value,
|
|
229
|
+
message2
|
|
230
|
+
];
|
|
231
|
+
});
|
|
232
|
+
session.toolStatusReport.on(({ message: message2, status }) => {
|
|
233
|
+
const msg = this._pending.peek().find((m) => m.id === message2.id);
|
|
234
|
+
const toolUse = msg?.content.find((block2) => block2.type === "tool_use");
|
|
235
|
+
if (!toolUse) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const block = msg?.content.find((block2) => block2.type === "tool_use" && block2.id === toolUse.id);
|
|
239
|
+
if (block) {
|
|
240
|
+
this._pending.value = this._pending.value.map((m) => {
|
|
241
|
+
if (m.id === message2.id) {
|
|
242
|
+
return {
|
|
243
|
+
...m,
|
|
244
|
+
content: m.content.map((block2) => block2.type === "tool_use" && block2.id === toolUse.id ? {
|
|
245
|
+
...block2,
|
|
246
|
+
currentStatus: status
|
|
247
|
+
} : block2)
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return m;
|
|
251
|
+
});
|
|
252
|
+
} else {
|
|
253
|
+
log.warn("no block for status report", void 0, {
|
|
254
|
+
F: __dxlog_file,
|
|
255
|
+
L: 197,
|
|
256
|
+
S: this,
|
|
257
|
+
C: (f, a) => f(...a)
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
try {
|
|
263
|
+
const messages = await this._conversation.run({
|
|
264
|
+
artifacts: [
|
|
265
|
+
...this._options.artifacts ?? []
|
|
266
|
+
],
|
|
267
|
+
requiredArtifactIds: this._options.artifacts?.map((artifact) => artifact.id) ?? [],
|
|
268
|
+
// TODO(dmaretskyi): Migrate to Effect's AiToolkit.
|
|
269
|
+
tools: this._tools ?? [],
|
|
270
|
+
systemPrompt: this._options.systemPrompt,
|
|
271
|
+
prompt: message,
|
|
272
|
+
extensions: this._options.extensions,
|
|
273
|
+
artifactDiffResolver: this._artifactDiffResolver,
|
|
274
|
+
generationOptions: {
|
|
275
|
+
model: this._options.model
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
log("completed", {
|
|
279
|
+
messages
|
|
280
|
+
}, {
|
|
281
|
+
F: __dxlog_file,
|
|
282
|
+
L: 218,
|
|
283
|
+
S: this,
|
|
284
|
+
C: (f, a) => f(...a)
|
|
285
|
+
});
|
|
286
|
+
} catch (err) {
|
|
287
|
+
log.catch(err, void 0, {
|
|
288
|
+
F: __dxlog_file,
|
|
289
|
+
L: 220,
|
|
290
|
+
S: this,
|
|
291
|
+
C: (f, a) => f(...a)
|
|
292
|
+
});
|
|
293
|
+
if (err instanceof Error && err.message.includes("Overloaded")) {
|
|
294
|
+
this.error.value = new AiServiceOverloadedError("AI service overloaded", {
|
|
295
|
+
cause: err
|
|
296
|
+
});
|
|
297
|
+
} else {
|
|
298
|
+
this.error.value = new Error("AI service error", {
|
|
299
|
+
cause: err
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return this._reset();
|
|
304
|
+
} catch (e) {
|
|
305
|
+
env.error = e;
|
|
306
|
+
env.hasError = true;
|
|
307
|
+
} finally {
|
|
308
|
+
const result = _ts_dispose_resources(env);
|
|
309
|
+
if (result) await result;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Cancel pending requests.
|
|
314
|
+
* @returns Pending requests (incl. the request message).
|
|
315
|
+
*/
|
|
316
|
+
async cancel() {
|
|
317
|
+
log.info("cancelling...", void 0, {
|
|
318
|
+
F: __dxlog_file,
|
|
319
|
+
L: 236,
|
|
320
|
+
S: this,
|
|
321
|
+
C: (f, a) => f(...a)
|
|
322
|
+
});
|
|
323
|
+
this._session?.abort();
|
|
324
|
+
return this._reset();
|
|
325
|
+
}
|
|
326
|
+
async _reset() {
|
|
327
|
+
const messages = this._pending.value;
|
|
328
|
+
batch(() => {
|
|
329
|
+
this._pending.value = [];
|
|
330
|
+
this._block.value = void 0;
|
|
331
|
+
});
|
|
332
|
+
return messages;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var AiServiceOverloadedError = class extends Error {
|
|
336
|
+
constructor() {
|
|
337
|
+
super(...arguments);
|
|
338
|
+
this.code = "AI_SERVICE_OVERLOADED";
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// src/hooks/useBlueprints.ts
|
|
343
|
+
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
344
|
+
import { useCallback, useState } from "react";
|
|
345
|
+
import { Ref } from "@dxos/echo";
|
|
346
|
+
import { log as log2 } from "@dxos/log";
|
|
347
|
+
import { useTimeout } from "@dxos/react-ui";
|
|
348
|
+
import { isNonNullable } from "@dxos/util";
|
|
349
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useBlueprints.ts";
|
|
350
|
+
var useBlueprints = (context) => {
|
|
351
|
+
var _effect = _useSignals();
|
|
352
|
+
try {
|
|
353
|
+
const [blueprints, setBlueprints] = useState([]);
|
|
354
|
+
useTimeout(async () => {
|
|
355
|
+
const blueprints2 = (await Ref.Array.loadAll(context.blueprints.value ?? [])).filter(isNonNullable);
|
|
356
|
+
setBlueprints(blueprints2);
|
|
357
|
+
}, 0, [
|
|
358
|
+
context
|
|
359
|
+
]);
|
|
360
|
+
const handleUpdate = useCallback((key, active) => {
|
|
361
|
+
log2.info("update", {
|
|
362
|
+
key,
|
|
363
|
+
active
|
|
364
|
+
}, {
|
|
365
|
+
F: __dxlog_file2,
|
|
366
|
+
L: 27,
|
|
367
|
+
S: void 0,
|
|
368
|
+
C: (f, a) => f(...a)
|
|
369
|
+
});
|
|
370
|
+
}, []);
|
|
371
|
+
return [
|
|
372
|
+
blueprints,
|
|
373
|
+
handleUpdate
|
|
374
|
+
];
|
|
375
|
+
} finally {
|
|
376
|
+
_effect.f();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// src/hooks/useContextProvider.ts
|
|
381
|
+
import { useMemo } from "react";
|
|
382
|
+
import { Capabilities, useCapabilities } from "@dxos/app-framework";
|
|
383
|
+
import { Filter as Filter2, Obj } from "@dxos/echo";
|
|
384
|
+
var useContextProvider = (space) => {
|
|
385
|
+
const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
|
|
386
|
+
return useMemo(() => {
|
|
387
|
+
if (!space) {
|
|
388
|
+
return void 0;
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
query: async ({ query }) => {
|
|
392
|
+
const artifactSchemas = artifactDefinitions.map((artifact) => artifact.schema);
|
|
393
|
+
const { objects } = await space.db.query(Filter2.or(...artifactSchemas.map((schema) => Filter2.type(schema)))).run();
|
|
394
|
+
return objects.filter((object) => stringMatch(query, Obj.getLabel(object) ?? "")).filter((object) => !!Obj.getDXN(object)).map((object) => ({
|
|
395
|
+
uri: Obj.getDXN(object).toString(),
|
|
396
|
+
label: Obj.getLabel(object) ?? ""
|
|
397
|
+
}));
|
|
398
|
+
},
|
|
399
|
+
resolveMetadata: async ({ uri }) => {
|
|
400
|
+
const object = await space.db.query(Filter2.ids(uri)).first();
|
|
401
|
+
return {
|
|
402
|
+
uri,
|
|
403
|
+
label: Obj.getLabel(object) ?? ""
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}, [
|
|
408
|
+
space,
|
|
409
|
+
artifactDefinitions
|
|
410
|
+
]);
|
|
411
|
+
};
|
|
412
|
+
var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
|
|
413
|
+
|
|
414
|
+
// src/hooks/useServiceContainer.ts
|
|
415
|
+
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
416
|
+
import { useEffect, useMemo as useMemo2, useState as useState2 } from "react";
|
|
417
|
+
import { ToolRegistry } from "@dxos/ai";
|
|
418
|
+
import { Capabilities as Capabilities2, useCapabilities as useCapabilities2, useCapability } from "@dxos/app-framework";
|
|
419
|
+
import { AiService, DatabaseService, QueueService, ServiceContainer, ToolResolverService } from "@dxos/functions";
|
|
420
|
+
var useServiceContainer = ({ space }) => {
|
|
421
|
+
var _effect = _useSignals2();
|
|
422
|
+
try {
|
|
423
|
+
const aiClient = useCapability(AssistantCapabilities.AiClient);
|
|
424
|
+
const tools = useCapabilities2(Capabilities2.Tools).flat();
|
|
425
|
+
const [toolRegistry] = useState2(() => new ToolRegistry([]));
|
|
426
|
+
useEffect(() => {
|
|
427
|
+
for (const tool of tools) {
|
|
428
|
+
if (!toolRegistry.has(tool)) {
|
|
429
|
+
toolRegistry.register(tool);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}, [
|
|
433
|
+
toolRegistry,
|
|
434
|
+
JSON.stringify(tools.map((tool) => tool.id))
|
|
435
|
+
]);
|
|
436
|
+
return useMemo2(() => new ServiceContainer().setServices({
|
|
437
|
+
ai: AiService.make(aiClient.value),
|
|
438
|
+
database: space ? DatabaseService.make(space.db) : void 0,
|
|
439
|
+
queues: space ? QueueService.make(space.queues, void 0) : void 0,
|
|
440
|
+
// eventLogger: consoleLogger,
|
|
441
|
+
toolResolver: ToolResolverService.make(toolRegistry)
|
|
442
|
+
}), [
|
|
443
|
+
space,
|
|
444
|
+
aiClient
|
|
445
|
+
]);
|
|
446
|
+
} finally {
|
|
447
|
+
_effect.f();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/hooks/useTextInputEvents.ts
|
|
452
|
+
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
453
|
+
import { useState as useState3, useCallback as useCallback2 } from "react";
|
|
454
|
+
|
|
455
|
+
// src/tools/function.ts
|
|
456
|
+
import { createTool, ToolResult } from "@dxos/ai";
|
|
457
|
+
import { Type } from "@dxos/echo";
|
|
458
|
+
import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
|
|
459
|
+
import { log as log3 } from "@dxos/log";
|
|
460
|
+
import { getMeta } from "@dxos/react-client/echo";
|
|
461
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/tools/function.ts";
|
|
462
|
+
var convertFunctionToTool = (fn, edgeUrl, spaceId) => {
|
|
463
|
+
if (!fn.description || !fn.inputSchema) {
|
|
464
|
+
return void 0;
|
|
465
|
+
}
|
|
466
|
+
const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
467
|
+
if (!existingFunctionUrl) {
|
|
468
|
+
return void 0;
|
|
469
|
+
}
|
|
470
|
+
const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
|
|
471
|
+
spaceId
|
|
472
|
+
});
|
|
473
|
+
return createTool("user-function", {
|
|
474
|
+
name: fn.name,
|
|
475
|
+
description: fn.description,
|
|
476
|
+
schema: Type.toEffectSchema(fn.inputSchema),
|
|
477
|
+
execute: async (input) => {
|
|
478
|
+
log3.info("execute function tool", {
|
|
479
|
+
name: fn.name,
|
|
480
|
+
url,
|
|
481
|
+
input
|
|
482
|
+
}, {
|
|
483
|
+
F: __dxlog_file3,
|
|
484
|
+
L: 34,
|
|
485
|
+
S: void 0,
|
|
486
|
+
C: (f, a) => f(...a)
|
|
487
|
+
});
|
|
488
|
+
const response = await fetch(url, {
|
|
489
|
+
method: "POST",
|
|
490
|
+
headers: {
|
|
491
|
+
"Content-Type": "application/json"
|
|
492
|
+
},
|
|
493
|
+
body: JSON.stringify(input)
|
|
494
|
+
});
|
|
495
|
+
return ToolResult.Success(await response.text());
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// src/tools/openapi.ts
|
|
501
|
+
import { Schema } from "effect";
|
|
502
|
+
import jsonpointer from "jsonpointer";
|
|
503
|
+
import { ToolResult as ToolResult2, createRawTool } from "@dxos/ai";
|
|
504
|
+
import { Type as Type2 } from "@dxos/echo";
|
|
505
|
+
import { normalizeSchema } from "@dxos/echo-schema";
|
|
506
|
+
import { invariant } from "@dxos/invariant";
|
|
507
|
+
import { log as log4 } from "@dxos/log";
|
|
508
|
+
import { deepMapValues } from "@dxos/util";
|
|
509
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/tools/openapi.ts";
|
|
510
|
+
var createToolsFromService = async (service) => {
|
|
511
|
+
invariant(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
|
|
512
|
+
F: __dxlog_file4,
|
|
513
|
+
L: 24,
|
|
514
|
+
S: void 0,
|
|
515
|
+
A: [
|
|
516
|
+
"service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
|
|
517
|
+
""
|
|
518
|
+
]
|
|
519
|
+
});
|
|
520
|
+
const iface = service.interfaces[0];
|
|
521
|
+
invariant(iface.schemaUrl, void 0, {
|
|
522
|
+
F: __dxlog_file4,
|
|
523
|
+
L: 26,
|
|
524
|
+
S: void 0,
|
|
525
|
+
A: [
|
|
526
|
+
"iface.schemaUrl",
|
|
527
|
+
""
|
|
528
|
+
]
|
|
529
|
+
});
|
|
530
|
+
invariant(iface.schemaUrl, void 0, {
|
|
531
|
+
F: __dxlog_file4,
|
|
532
|
+
L: 27,
|
|
533
|
+
S: void 0,
|
|
534
|
+
A: [
|
|
535
|
+
"iface.schemaUrl",
|
|
536
|
+
""
|
|
537
|
+
]
|
|
538
|
+
});
|
|
539
|
+
return createToolsFromApi(iface.schemaUrl, {
|
|
540
|
+
authorization: iface.authorization
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
var createToolsFromApi = async (url, options) => {
|
|
544
|
+
const res = await fetch(url);
|
|
545
|
+
const spec = await res.json();
|
|
546
|
+
log4("spec", {
|
|
547
|
+
spec
|
|
548
|
+
}, {
|
|
549
|
+
F: __dxlog_file4,
|
|
550
|
+
L: 37,
|
|
551
|
+
S: void 0,
|
|
552
|
+
C: (f, a) => f(...a)
|
|
553
|
+
});
|
|
554
|
+
const tools = [];
|
|
555
|
+
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
556
|
+
if (typeof pathItem !== "object") {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
const { ...methods } = pathItem;
|
|
560
|
+
for (const [method, m] of Object.entries(methods)) {
|
|
561
|
+
const methodItem = m;
|
|
562
|
+
log4("methodItem", {
|
|
563
|
+
path,
|
|
564
|
+
method,
|
|
565
|
+
methodItem
|
|
566
|
+
}, {
|
|
567
|
+
F: __dxlog_file4,
|
|
568
|
+
L: 48,
|
|
569
|
+
S: void 0,
|
|
570
|
+
C: (f, a) => f(...a)
|
|
571
|
+
});
|
|
572
|
+
const parametersResolved = methodItem.parameters?.map((parameter) => {
|
|
573
|
+
const resolved = resolveJsonSchema(parameter, spec);
|
|
574
|
+
return resolved;
|
|
575
|
+
}) ?? [];
|
|
576
|
+
const inputSchema = {
|
|
577
|
+
type: "object",
|
|
578
|
+
properties: {}
|
|
579
|
+
};
|
|
580
|
+
const endpointParameters = [];
|
|
581
|
+
for (const parameter of parametersResolved) {
|
|
582
|
+
log4("parameter", {
|
|
583
|
+
parameter
|
|
584
|
+
}, {
|
|
585
|
+
F: __dxlog_file4,
|
|
586
|
+
L: 63,
|
|
587
|
+
S: void 0,
|
|
588
|
+
C: (f, a) => f(...a)
|
|
589
|
+
});
|
|
590
|
+
if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
endpointParameters.push(parameter);
|
|
594
|
+
if (parameter.schema) {
|
|
595
|
+
inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
|
|
596
|
+
} else if (typeof parameter.type === "string") {
|
|
597
|
+
const { name, in: _in, required, ...schema } = parameter;
|
|
598
|
+
inputSchema.properties[name] = normalizeSchema(schema);
|
|
599
|
+
if (required) {
|
|
600
|
+
inputSchema.required ??= [];
|
|
601
|
+
inputSchema.required.push(name);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
log4("inputSchema", {
|
|
606
|
+
inputSchema
|
|
607
|
+
}, {
|
|
608
|
+
F: __dxlog_file4,
|
|
609
|
+
L: 88,
|
|
610
|
+
S: void 0,
|
|
611
|
+
C: (f, a) => f(...a)
|
|
612
|
+
});
|
|
613
|
+
Schema.validateSync(Type2.JsonSchema)(inputSchema);
|
|
614
|
+
const description = methodItem.description ?? methodItem.summary;
|
|
615
|
+
if (!description) {
|
|
616
|
+
log4.warn("no description", {
|
|
617
|
+
path,
|
|
618
|
+
method
|
|
619
|
+
}, {
|
|
620
|
+
F: __dxlog_file4,
|
|
621
|
+
L: 93,
|
|
622
|
+
S: void 0,
|
|
623
|
+
C: (f, a) => f(...a)
|
|
624
|
+
});
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
const endpoint = {
|
|
628
|
+
document: spec,
|
|
629
|
+
path,
|
|
630
|
+
method,
|
|
631
|
+
parameters: endpointParameters,
|
|
632
|
+
authorization: options?.authorization
|
|
633
|
+
};
|
|
634
|
+
tools.push(
|
|
635
|
+
// TODO(burdon): Namespace?
|
|
636
|
+
createRawTool("openapi", {
|
|
637
|
+
name: getToolName(path, method, methodItem),
|
|
638
|
+
description: options?.instructions ? `${options.instructions}
|
|
639
|
+
|
|
640
|
+
${description}` : description,
|
|
641
|
+
parameters: inputSchema,
|
|
642
|
+
execute: async (input) => {
|
|
643
|
+
const response = await callApiEndpoint(endpoint, input);
|
|
644
|
+
return ToolResult2.Success(response);
|
|
645
|
+
}
|
|
646
|
+
})
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return tools;
|
|
651
|
+
};
|
|
652
|
+
var getToolName = (path, method, methodItem) => {
|
|
653
|
+
if (methodItem.operationId) {
|
|
654
|
+
return methodItem.operationId;
|
|
655
|
+
}
|
|
656
|
+
let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
|
|
657
|
+
while (name.length > MAX_TOOL_NAME_LENGTH) {
|
|
658
|
+
const lengthBefore = name.length;
|
|
659
|
+
for (const word of GENERIC_WORDS) {
|
|
660
|
+
if (name.includes(word)) {
|
|
661
|
+
name = name.replace(word, "");
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
name = name.replaceAll("__", "_").replace(/_$/, "");
|
|
666
|
+
const lengthAfter = name.length;
|
|
667
|
+
if (lengthBefore === lengthAfter) {
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
|
|
672
|
+
return name.slice(0, MAX_TOOL_NAME_LENGTH);
|
|
673
|
+
};
|
|
674
|
+
var MAX_TOOL_NAME_LENGTH = 64;
|
|
675
|
+
var GENERIC_WORDS = [
|
|
676
|
+
"services",
|
|
677
|
+
"service",
|
|
678
|
+
"api",
|
|
679
|
+
"rest",
|
|
680
|
+
"endpoint",
|
|
681
|
+
"get",
|
|
682
|
+
"post",
|
|
683
|
+
"put",
|
|
684
|
+
"delete",
|
|
685
|
+
"patch",
|
|
686
|
+
"head",
|
|
687
|
+
"options",
|
|
688
|
+
"trace",
|
|
689
|
+
"service",
|
|
690
|
+
"api",
|
|
691
|
+
"endpoint"
|
|
692
|
+
];
|
|
693
|
+
var callApiEndpoint = async (endpoint, input) => {
|
|
694
|
+
log4.info("endpoint", {
|
|
695
|
+
method: endpoint.method,
|
|
696
|
+
name: endpoint.path,
|
|
697
|
+
input
|
|
698
|
+
}, {
|
|
699
|
+
F: __dxlog_file4,
|
|
700
|
+
L: 180,
|
|
701
|
+
S: void 0,
|
|
702
|
+
C: (f, a) => f(...a)
|
|
703
|
+
});
|
|
704
|
+
let url = getEndpointUrl(endpoint);
|
|
705
|
+
const request = {
|
|
706
|
+
method: endpoint.method,
|
|
707
|
+
headers: {}
|
|
708
|
+
};
|
|
709
|
+
const query = new URLSearchParams();
|
|
710
|
+
let body;
|
|
711
|
+
for (const parameter of endpoint.parameters) {
|
|
712
|
+
if (input[parameter.name] === void 0) {
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
switch (parameter.in) {
|
|
716
|
+
case "header": {
|
|
717
|
+
if (parameter.example) {
|
|
718
|
+
request.headers[parameter.name] = parameter.default;
|
|
719
|
+
}
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
case "path": {
|
|
723
|
+
url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
case "body": {
|
|
727
|
+
const value = input[parameter.name];
|
|
728
|
+
const effectSchema = Type2.toEffectSchema(parameter.schema);
|
|
729
|
+
Schema.validateSync(effectSchema)(value);
|
|
730
|
+
if (body) {
|
|
731
|
+
throw new Error(`Duplicate body parameter: ${parameter.name}`);
|
|
732
|
+
}
|
|
733
|
+
body = value;
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
case "query": {
|
|
737
|
+
query.set(parameter.name, input[parameter.name]);
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
|
|
743
|
+
request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
|
|
744
|
+
} else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
|
|
745
|
+
query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
|
|
746
|
+
}
|
|
747
|
+
if (query.size > 0) {
|
|
748
|
+
url += `?${query.toString()}`;
|
|
749
|
+
}
|
|
750
|
+
if (body) {
|
|
751
|
+
request.body = JSON.stringify(body);
|
|
752
|
+
request.headers["Content-Type"] = "application/json";
|
|
753
|
+
}
|
|
754
|
+
log4.info("request", {
|
|
755
|
+
url,
|
|
756
|
+
request
|
|
757
|
+
}, {
|
|
758
|
+
F: __dxlog_file4,
|
|
759
|
+
L: 243,
|
|
760
|
+
S: void 0,
|
|
761
|
+
C: (f, a) => f(...a)
|
|
762
|
+
});
|
|
763
|
+
const response = await fetch(url, request);
|
|
764
|
+
log4.info("response", {
|
|
765
|
+
ok: response.ok,
|
|
766
|
+
status: response.status,
|
|
767
|
+
statusText: response.statusText
|
|
768
|
+
}, {
|
|
769
|
+
F: __dxlog_file4,
|
|
770
|
+
L: 246,
|
|
771
|
+
S: void 0,
|
|
772
|
+
C: (f, a) => f(...a)
|
|
773
|
+
});
|
|
774
|
+
if (response.ok) {
|
|
775
|
+
const contentType = response.headers.get("Content-Type");
|
|
776
|
+
if (contentType?.includes("application/json")) {
|
|
777
|
+
return await response.json();
|
|
778
|
+
} else {
|
|
779
|
+
return await response.text();
|
|
780
|
+
}
|
|
781
|
+
} else {
|
|
782
|
+
if (response.headers.get("Content-Type")?.includes("application/json")) {
|
|
783
|
+
const responseBody = await response.text();
|
|
784
|
+
let error;
|
|
785
|
+
try {
|
|
786
|
+
error = JSON.parse(responseBody);
|
|
787
|
+
} catch {
|
|
788
|
+
error = responseBody;
|
|
789
|
+
}
|
|
790
|
+
log4.error("error", {
|
|
791
|
+
error
|
|
792
|
+
}, {
|
|
793
|
+
F: __dxlog_file4,
|
|
794
|
+
L: 264,
|
|
795
|
+
S: void 0,
|
|
796
|
+
C: (f, a) => f(...a)
|
|
797
|
+
});
|
|
798
|
+
throw new Error(error.message);
|
|
799
|
+
} else {
|
|
800
|
+
const error = await response.text();
|
|
801
|
+
log4.error("error", {
|
|
802
|
+
error
|
|
803
|
+
}, {
|
|
804
|
+
F: __dxlog_file4,
|
|
805
|
+
L: 268,
|
|
806
|
+
S: void 0,
|
|
807
|
+
C: (f, a) => f(...a)
|
|
808
|
+
});
|
|
809
|
+
throw new Error(error);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
var getEndpointUrl = (endpoint) => {
|
|
814
|
+
let url = "";
|
|
815
|
+
if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
|
|
816
|
+
url = endpoint.document.servers[0].url;
|
|
817
|
+
} else {
|
|
818
|
+
invariant(!isV3_1(endpoint.document), void 0, {
|
|
819
|
+
F: __dxlog_file4,
|
|
820
|
+
L: 279,
|
|
821
|
+
S: void 0,
|
|
822
|
+
A: [
|
|
823
|
+
"!isV3_1(endpoint.document)",
|
|
824
|
+
""
|
|
825
|
+
]
|
|
826
|
+
});
|
|
827
|
+
url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
|
|
828
|
+
}
|
|
829
|
+
if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
|
|
830
|
+
url += endpoint.document.basePath;
|
|
831
|
+
}
|
|
832
|
+
url += endpoint.path;
|
|
833
|
+
return url;
|
|
834
|
+
};
|
|
835
|
+
var resolveAuthorization = async (authorization) => {
|
|
836
|
+
switch (authorization.type) {
|
|
837
|
+
case "api-key": {
|
|
838
|
+
invariant(authorization.placement.type === "authorization-header", void 0, {
|
|
839
|
+
F: __dxlog_file4,
|
|
840
|
+
L: 295,
|
|
841
|
+
S: void 0,
|
|
842
|
+
A: [
|
|
843
|
+
"authorization.placement.type === 'authorization-header'",
|
|
844
|
+
""
|
|
845
|
+
]
|
|
846
|
+
});
|
|
847
|
+
return `Bearer ${authorization.key}`;
|
|
848
|
+
}
|
|
849
|
+
case "oauth": {
|
|
850
|
+
const response = await fetch(authorization.tokenUrl, {
|
|
851
|
+
method: "POST",
|
|
852
|
+
headers: {
|
|
853
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
854
|
+
},
|
|
855
|
+
body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
|
|
856
|
+
});
|
|
857
|
+
const data = await response.json();
|
|
858
|
+
return `Bearer ${data.access_token}`;
|
|
859
|
+
}
|
|
860
|
+
default: {
|
|
861
|
+
throw new Error(`Unknown authorization type: ${authorization.type}`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
var resolveJsonSchema = (schema, base) => {
|
|
866
|
+
return deepMapValues(schema, (value, recurse) => {
|
|
867
|
+
if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
|
|
868
|
+
if (value.$ref.startsWith("#")) {
|
|
869
|
+
const resolved = jsonpointer.get(base, value.$ref.slice(1));
|
|
870
|
+
if (resolved) {
|
|
871
|
+
return recurse(resolved);
|
|
872
|
+
} else {
|
|
873
|
+
log4.warn("unresolved", {
|
|
874
|
+
ref: value.$ref,
|
|
875
|
+
base
|
|
876
|
+
}, {
|
|
877
|
+
F: __dxlog_file4,
|
|
878
|
+
L: 328,
|
|
879
|
+
S: void 0,
|
|
880
|
+
C: (f, a) => f(...a)
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return recurse(value);
|
|
886
|
+
});
|
|
887
|
+
};
|
|
888
|
+
var isV3_1 = (document) => {
|
|
889
|
+
return document.openapi === "3.0.1";
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
// src/hooks/useChatProcessor.tsx
|
|
893
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.tsx";
|
|
894
|
+
var useChatProcessor = ({ part = "deck", space, chat, serviceContainer, blueprintRegistry, settings, instructions, artifact, noPluginArtifacts }) => {
|
|
895
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
896
|
+
const globalTools = useCapabilities3(Capabilities3.Tools);
|
|
897
|
+
let artifacts = useCapabilities3(Capabilities3.ArtifactDefinition);
|
|
898
|
+
if (noPluginArtifacts) {
|
|
899
|
+
artifacts = Stable.array;
|
|
900
|
+
}
|
|
901
|
+
const services = useQuery(space, Filter3.type(ServiceType));
|
|
902
|
+
const [serviceTools, setServiceTools] = useState4([]);
|
|
903
|
+
useEffect2(() => {
|
|
904
|
+
log5("creating service tools...", void 0, {
|
|
905
|
+
F: __dxlog_file5,
|
|
906
|
+
L: 65,
|
|
907
|
+
S: void 0,
|
|
908
|
+
C: (f, a) => f(...a)
|
|
909
|
+
});
|
|
910
|
+
queueMicrotask(async () => {
|
|
911
|
+
const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
|
|
912
|
+
setServiceTools(tools2.flat());
|
|
913
|
+
});
|
|
914
|
+
}, [
|
|
915
|
+
services
|
|
916
|
+
]);
|
|
917
|
+
const config = useConfig();
|
|
918
|
+
const functions = useQuery(space, Filter3.type(FunctionType));
|
|
919
|
+
const chatId = useMemo3(() => chat ? fullyQualifiedId(chat) : void 0, [
|
|
920
|
+
chat
|
|
921
|
+
]);
|
|
922
|
+
const [tools, extensions] = useMemo3(() => {
|
|
923
|
+
log5("creating tools...", void 0, {
|
|
924
|
+
F: __dxlog_file5,
|
|
925
|
+
L: 77,
|
|
926
|
+
S: void 0,
|
|
927
|
+
C: (f, a) => f(...a)
|
|
928
|
+
});
|
|
929
|
+
const tools2 = [
|
|
930
|
+
...globalTools.flat(),
|
|
931
|
+
...serviceTools,
|
|
932
|
+
...functions.map((fn) => convertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNonNullable2)
|
|
933
|
+
];
|
|
934
|
+
const extensions2 = {
|
|
935
|
+
part,
|
|
936
|
+
space,
|
|
937
|
+
dispatch,
|
|
938
|
+
pivotId: chatId
|
|
939
|
+
};
|
|
940
|
+
return [
|
|
941
|
+
tools2,
|
|
942
|
+
extensions2
|
|
943
|
+
];
|
|
944
|
+
}, [
|
|
945
|
+
dispatch,
|
|
946
|
+
globalTools,
|
|
947
|
+
space,
|
|
948
|
+
chatId,
|
|
949
|
+
serviceTools,
|
|
950
|
+
functions
|
|
951
|
+
]);
|
|
952
|
+
const systemPrompt = useMemo3(() => createSystemPrompt({
|
|
953
|
+
artifacts: artifacts.map((definition) => `${definition.name}
|
|
954
|
+
${definition.instructions}`),
|
|
955
|
+
artifact,
|
|
956
|
+
instructions
|
|
957
|
+
}), [
|
|
958
|
+
artifacts,
|
|
959
|
+
artifact,
|
|
960
|
+
instructions
|
|
961
|
+
]);
|
|
962
|
+
const model = settings?.llmProvider === "ollama" ? settings?.ollamaModel ?? DEFAULT_OLLAMA_MODEL : settings?.edgeModel ?? DEFAULT_EDGE_MODEL2;
|
|
963
|
+
const conversation = useMemo3(() => {
|
|
964
|
+
if (!chat?.queue.target) {
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
return new Conversation({
|
|
968
|
+
serviceContainer,
|
|
969
|
+
queue: chat.queue.target
|
|
970
|
+
});
|
|
971
|
+
}, [
|
|
972
|
+
chat?.queue.target,
|
|
973
|
+
serviceContainer
|
|
974
|
+
]);
|
|
975
|
+
const processor = useMemo3(() => {
|
|
976
|
+
if (!conversation) {
|
|
977
|
+
return void 0;
|
|
978
|
+
}
|
|
979
|
+
log5("creating processor...", {
|
|
980
|
+
settings
|
|
981
|
+
}, {
|
|
982
|
+
F: __dxlog_file5,
|
|
983
|
+
L: 124,
|
|
984
|
+
S: void 0,
|
|
985
|
+
C: (f, a) => f(...a)
|
|
986
|
+
});
|
|
987
|
+
return new ChatProcessor(conversation, {
|
|
988
|
+
tools,
|
|
989
|
+
extensions,
|
|
990
|
+
blueprintRegistry,
|
|
991
|
+
artifacts,
|
|
992
|
+
systemPrompt,
|
|
993
|
+
model
|
|
994
|
+
});
|
|
995
|
+
}, [
|
|
996
|
+
conversation,
|
|
997
|
+
tools,
|
|
998
|
+
blueprintRegistry,
|
|
999
|
+
artifacts,
|
|
1000
|
+
extensions,
|
|
1001
|
+
systemPrompt,
|
|
1002
|
+
model
|
|
1003
|
+
]);
|
|
1004
|
+
return processor;
|
|
1005
|
+
};
|
|
1006
|
+
var Stable = Object.freeze({
|
|
1007
|
+
array: [],
|
|
1008
|
+
object: {}
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
// src/components/Toolbox/Toolbox.tsx
|
|
1012
|
+
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
|
1013
|
+
import React, { useState as useState5, useEffect as useEffect3, Fragment } from "react";
|
|
1014
|
+
import { parseToolName } from "@dxos/ai";
|
|
1015
|
+
import { Capabilities as Capabilities4, useCapabilities as useCapabilities4 } from "@dxos/app-framework";
|
|
1016
|
+
import { FunctionType as FunctionType2 } from "@dxos/functions";
|
|
1017
|
+
import { log as log6 } from "@dxos/log";
|
|
1018
|
+
import { Filter as Filter4, useQuery as useQuery2 } from "@dxos/react-client/echo";
|
|
1019
|
+
import { useTranslation } from "@dxos/react-ui";
|
|
1020
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
1021
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
|
|
1022
|
+
var Toolbox = ({ classNames, artifacts, functions, services, blueprints, activeBlueprints, striped }) => {
|
|
1023
|
+
var _effect = _useSignals4();
|
|
1024
|
+
try {
|
|
1025
|
+
const { t } = useTranslation(meta.id);
|
|
1026
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1027
|
+
className: mx("flex flex-col overflow-y-auto box-content", classNames)
|
|
1028
|
+
}, blueprints && blueprints.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
1029
|
+
title: "Blueprints",
|
|
1030
|
+
items: blueprints.map(({ target }) => ({
|
|
1031
|
+
name: target?.name ?? "",
|
|
1032
|
+
description: target?.description ?? "",
|
|
1033
|
+
subitems: target?.tools.map((toolId) => ({
|
|
1034
|
+
name: `\u2219 ${parseToolName(toolId)}`
|
|
1035
|
+
}))
|
|
1036
|
+
}))
|
|
1037
|
+
}), activeBlueprints && activeBlueprints.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
1038
|
+
title: "Blueprints",
|
|
1039
|
+
items: activeBlueprints.map(({ target }) => ({
|
|
1040
|
+
name: target?.name ?? "",
|
|
1041
|
+
description: target?.description ?? "",
|
|
1042
|
+
subitems: target?.tools.map((toolId) => ({
|
|
1043
|
+
name: `\u2219 ${parseToolName(toolId)}`
|
|
1044
|
+
}))
|
|
1045
|
+
}))
|
|
1046
|
+
}), artifacts && artifacts.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
1047
|
+
title: "Artifacts",
|
|
1048
|
+
items: artifacts.map(({ name, description, tools }) => ({
|
|
1049
|
+
name,
|
|
1050
|
+
description,
|
|
1051
|
+
subitems: tools.map(({ name: name2, description: description2 }) => ({
|
|
1052
|
+
name: `\u2219 ${parseToolName(name2)}`,
|
|
1053
|
+
description: description2
|
|
1054
|
+
}))
|
|
1055
|
+
}))
|
|
1056
|
+
}), services && services.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
1057
|
+
title: "Services",
|
|
1058
|
+
items: services.map(({ service: { serviceId, name, description }, tools }) => ({
|
|
1059
|
+
name: name ?? serviceId,
|
|
1060
|
+
description,
|
|
1061
|
+
subitems: tools.map(({ name: name2, description: description2 }) => ({
|
|
1062
|
+
name: `\u2219 ${name2}`,
|
|
1063
|
+
description: description2
|
|
1064
|
+
}))
|
|
1065
|
+
}))
|
|
1066
|
+
}), functions && functions.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
1067
|
+
title: "Functions",
|
|
1068
|
+
items: functions.map(({ name, description }) => ({
|
|
1069
|
+
name,
|
|
1070
|
+
description
|
|
1071
|
+
}))
|
|
1072
|
+
}), !blueprints?.length && !activeBlueprints?.length && !artifacts?.length && !services?.length && !functions?.length && /* @__PURE__ */ React.createElement("div", null, t("no tools")));
|
|
1073
|
+
} finally {
|
|
1074
|
+
_effect.f();
|
|
1075
|
+
}
|
|
1076
|
+
};
|
|
1077
|
+
var Section = ({ title, items, striped }) => {
|
|
1078
|
+
var _effect = _useSignals4();
|
|
1079
|
+
try {
|
|
1080
|
+
const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
|
|
1081
|
+
const gridClassNames = "grid grid-cols-[8rem_1fr]";
|
|
1082
|
+
const subGridClassNames = mx("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
|
|
1083
|
+
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
|
|
1084
|
+
className: "px-2 text-sm"
|
|
1085
|
+
}, title), /* @__PURE__ */ React.createElement("div", {
|
|
1086
|
+
className: gridClassNames
|
|
1087
|
+
}, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React.createElement(Fragment, {
|
|
1088
|
+
key: i
|
|
1089
|
+
}, name && /* @__PURE__ */ React.createElement("div", {
|
|
1090
|
+
className: subGridClassNames
|
|
1091
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1092
|
+
className: "truncate text-primary-500"
|
|
1093
|
+
}, name), /* @__PURE__ */ React.createElement("div", {
|
|
1094
|
+
className: "line-clamp-2"
|
|
1095
|
+
}, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React.createElement("div", {
|
|
1096
|
+
key: i2,
|
|
1097
|
+
className: mx(subGridClassNames, striped && stripeClassNames)
|
|
1098
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1099
|
+
className: "truncate"
|
|
1100
|
+
}, name2), /* @__PURE__ */ React.createElement("div", {
|
|
1101
|
+
className: "line-clamp-3 text-subdued"
|
|
1102
|
+
}, description2)))))));
|
|
1103
|
+
} finally {
|
|
1104
|
+
_effect.f();
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
var ToolboxContainer = ({ classNames, space, processor }) => {
|
|
1108
|
+
var _effect = _useSignals4();
|
|
1109
|
+
try {
|
|
1110
|
+
const artifactDefinitions = useCapabilities4(Capabilities4.ArtifactDefinition);
|
|
1111
|
+
const services = useQuery2(space, Filter4.type(ServiceType));
|
|
1112
|
+
const [serviceTools, setServiceTools] = useState5([]);
|
|
1113
|
+
useEffect3(() => {
|
|
1114
|
+
log6("creating service tools...", {
|
|
1115
|
+
services: services.length
|
|
1116
|
+
}, {
|
|
1117
|
+
F: __dxlog_file6,
|
|
1118
|
+
L: 147,
|
|
1119
|
+
S: void 0,
|
|
1120
|
+
C: (f, a) => f(...a)
|
|
1121
|
+
});
|
|
1122
|
+
queueMicrotask(async () => {
|
|
1123
|
+
const tools = await Promise.all(services.map(async (service) => ({
|
|
1124
|
+
service,
|
|
1125
|
+
tools: await createToolsFromService(service)
|
|
1126
|
+
})));
|
|
1127
|
+
setServiceTools(tools);
|
|
1128
|
+
});
|
|
1129
|
+
}, [
|
|
1130
|
+
services
|
|
1131
|
+
]);
|
|
1132
|
+
const functions = useQuery2(space, Filter4.type(FunctionType2));
|
|
1133
|
+
return /* @__PURE__ */ React.createElement(Toolbox, {
|
|
1134
|
+
classNames,
|
|
1135
|
+
blueprints: processor?.context.blueprints.value,
|
|
1136
|
+
artifacts: artifactDefinitions,
|
|
1137
|
+
services: serviceTools,
|
|
1138
|
+
functions
|
|
1139
|
+
});
|
|
1140
|
+
} finally {
|
|
1141
|
+
_effect.f();
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
// src/components/Chat/Chat.tsx
|
|
1146
|
+
import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
|
|
1147
|
+
import { Prec } from "@codemirror/state";
|
|
1148
|
+
import { keymap } from "@codemirror/view";
|
|
1149
|
+
import { createContext } from "@radix-ui/react-context";
|
|
1150
|
+
import { dedupeWith } from "effect/Array";
|
|
1151
|
+
import React9, { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo7, useRef as useRef2, useState as useState7 } from "react";
|
|
1152
|
+
import { Message } from "@dxos/ai";
|
|
1153
|
+
import { CollaborationActions, createIntent, useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
|
|
1154
|
+
import { Event } from "@dxos/async";
|
|
1155
|
+
import { DXN, Obj as Obj3, Ref as Ref3 } from "@dxos/echo";
|
|
1156
|
+
import { log as log8 } from "@dxos/log";
|
|
1157
|
+
import { useVoiceInput } from "@dxos/plugin-transcription";
|
|
1158
|
+
import { getSpace, useQueue } from "@dxos/react-client/echo";
|
|
1159
|
+
import { useIdentity } from "@dxos/react-client/halo";
|
|
1160
|
+
import { useTranslation as useTranslation5 } from "@dxos/react-ui";
|
|
1161
|
+
import { ChatEditor, references } from "@dxos/react-ui-chat";
|
|
1162
|
+
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
1163
|
+
import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
|
1164
|
+
|
|
1165
|
+
// src/components/ChatPrompt/ChatActions.tsx
|
|
1166
|
+
import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
|
|
1167
|
+
import React2 from "react";
|
|
1168
|
+
import { IconButton, Select, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
1169
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1170
|
+
var ChatActions = ({ microphone, recording, processing, onEvent }) => {
|
|
1171
|
+
var _effect = _useSignals5();
|
|
1172
|
+
try {
|
|
1173
|
+
const { t } = useTranslation2(meta.id);
|
|
1174
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
1175
|
+
className: "flex items-center mie-1"
|
|
1176
|
+
}, /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
1177
|
+
value: "ollama",
|
|
1178
|
+
disabled: true
|
|
1179
|
+
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
1180
|
+
classNames: "mie-2 text-sm"
|
|
1181
|
+
}), /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
1182
|
+
value: "ollama",
|
|
1183
|
+
classNames: "text-sm"
|
|
1184
|
+
}, "Ollama"))), processing && /* @__PURE__ */ React2.createElement(IconButton, {
|
|
1185
|
+
disabled: !processing,
|
|
1186
|
+
classNames: "px-1.5",
|
|
1187
|
+
variant: "ghost",
|
|
1188
|
+
size: 5,
|
|
1189
|
+
icon: "ph--x--regular",
|
|
1190
|
+
iconOnly: true,
|
|
1191
|
+
label: t("button cancel processing"),
|
|
1192
|
+
onClick: () => onEvent?.({
|
|
1193
|
+
type: "cancel"
|
|
1194
|
+
})
|
|
1195
|
+
}) || /* @__PURE__ */ React2.createElement(IconButton, {
|
|
1196
|
+
classNames: "px-1.5",
|
|
1197
|
+
variant: "ghost",
|
|
1198
|
+
size: 5,
|
|
1199
|
+
icon: "ph--arrow-down--regular",
|
|
1200
|
+
iconOnly: true,
|
|
1201
|
+
label: t("button scroll down"),
|
|
1202
|
+
onClick: () => onEvent?.({
|
|
1203
|
+
type: "scroll-to-bottom"
|
|
1204
|
+
})
|
|
1205
|
+
}), microphone && /* @__PURE__ */ React2.createElement(IconButton, {
|
|
1206
|
+
disabled: !processing,
|
|
1207
|
+
classNames: mx2("px-1.5", recording && "bg-primary-500"),
|
|
1208
|
+
variant: "ghost",
|
|
1209
|
+
size: 5,
|
|
1210
|
+
icon: "ph--microphone--regular",
|
|
1211
|
+
iconOnly: true,
|
|
1212
|
+
noTooltip: true,
|
|
1213
|
+
label: t("button microphone"),
|
|
1214
|
+
onMouseDown: () => onEvent?.({
|
|
1215
|
+
type: "record-start"
|
|
1216
|
+
}),
|
|
1217
|
+
onMouseUp: () => onEvent?.({
|
|
1218
|
+
type: "record-stop"
|
|
1219
|
+
}),
|
|
1220
|
+
onTouchStart: () => onEvent?.({
|
|
1221
|
+
type: "record-start"
|
|
1222
|
+
}),
|
|
1223
|
+
onTouchEnd: () => onEvent?.({
|
|
1224
|
+
type: "record-stop"
|
|
1225
|
+
})
|
|
1226
|
+
}));
|
|
1227
|
+
} finally {
|
|
1228
|
+
_effect.f();
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
// src/components/ChatPrompt/ChatOptionsMenu.tsx
|
|
1233
|
+
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
1234
|
+
import React3, { useMemo as useMemo4 } from "react";
|
|
1235
|
+
import { DropdownMenu, IconButton as IconButton2, Input, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
1236
|
+
var ChatOptionsMenu = ({ blueprintRegistry, blueprints, onChange }) => {
|
|
1237
|
+
var _effect = _useSignals6();
|
|
1238
|
+
try {
|
|
1239
|
+
const { t } = useTranslation3(meta.id);
|
|
1240
|
+
const blueprintOptions = useMemo4(() => blueprintRegistry?.query().map((blueprint) => ({
|
|
1241
|
+
key: blueprint.key,
|
|
1242
|
+
label: blueprint.name
|
|
1243
|
+
})), [
|
|
1244
|
+
blueprintRegistry
|
|
1245
|
+
]);
|
|
1246
|
+
return /* @__PURE__ */ React3.createElement(DropdownMenu.Root, null, /* @__PURE__ */ React3.createElement(DropdownMenu.Trigger, {
|
|
1247
|
+
asChild: true,
|
|
1248
|
+
disabled: !blueprintOptions?.length
|
|
1249
|
+
}, /* @__PURE__ */ React3.createElement(IconButton2, {
|
|
1250
|
+
icon: "ph--plus--regular",
|
|
1251
|
+
variant: "ghost",
|
|
1252
|
+
size: 5,
|
|
1253
|
+
iconOnly: true,
|
|
1254
|
+
label: t("button add blueprint")
|
|
1255
|
+
})), /* @__PURE__ */ React3.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React3.createElement(DropdownMenu.Content, {
|
|
1256
|
+
side: "left"
|
|
1257
|
+
}, /* @__PURE__ */ React3.createElement(DropdownMenu.Viewport, null, blueprintOptions?.map((option) => /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
1258
|
+
key: option.key
|
|
1259
|
+
}, /* @__PURE__ */ React3.createElement(Input.Root, null, /* @__PURE__ */ React3.createElement(Input.Checkbox, {
|
|
1260
|
+
checked: !!blueprints?.find((blueprint) => blueprint.key === option.key),
|
|
1261
|
+
onCheckedChange: (checked) => onChange?.(option.key, !!checked)
|
|
1262
|
+
}), /* @__PURE__ */ React3.createElement(Input.Label, {
|
|
1263
|
+
classNames: "m-0"
|
|
1264
|
+
}, option.label))))), /* @__PURE__ */ React3.createElement(DropdownMenu.Arrow, null))));
|
|
1265
|
+
} finally {
|
|
1266
|
+
_effect.f();
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
// src/components/ChatPrompt/ChatReferences.tsx
|
|
1271
|
+
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
1272
|
+
import React4, { useCallback as useCallback3 } from "react";
|
|
1273
|
+
import { Filter as Filter5, Obj as Obj2, Ref as Ref2 } from "@dxos/echo";
|
|
1274
|
+
import { useAsyncState, useTranslation as useTranslation4 } from "@dxos/react-ui";
|
|
1275
|
+
import { TagPicker } from "@dxos/react-ui-tag-picker";
|
|
1276
|
+
import { isNonNullable as isNonNullable3 } from "@dxos/util";
|
|
1277
|
+
var ChatReferences = ({ classNames, space, context, onUpdate }) => {
|
|
1278
|
+
var _effect = _useSignals7();
|
|
1279
|
+
try {
|
|
1280
|
+
const { t } = useTranslation4(meta.id);
|
|
1281
|
+
const [items] = useAsyncState(async () => {
|
|
1282
|
+
const objects = await Ref2.Array.loadAll(context.objects.value ?? []);
|
|
1283
|
+
return objects.filter(isNonNullable3).map((obj) => ({
|
|
1284
|
+
id: obj.id,
|
|
1285
|
+
label: Obj2.getLabel(obj) ?? obj.id
|
|
1286
|
+
}));
|
|
1287
|
+
}, [
|
|
1288
|
+
context
|
|
1289
|
+
]);
|
|
1290
|
+
const handleSearch = useCallback3((text, ids) => {
|
|
1291
|
+
const objects = space.db.query(Filter5.everything()).runSync();
|
|
1292
|
+
return objects.map(({ object }) => ({
|
|
1293
|
+
id: object.id,
|
|
1294
|
+
label: Obj2.getLabel(object) ?? ""
|
|
1295
|
+
})).filter(({ id, label }) => !ids.includes(id) && label.toLocaleLowerCase().includes(text.toLocaleLowerCase()));
|
|
1296
|
+
}, [
|
|
1297
|
+
space
|
|
1298
|
+
]);
|
|
1299
|
+
return /* @__PURE__ */ React4.createElement(TagPicker, {
|
|
1300
|
+
classNames,
|
|
1301
|
+
mode: "multi-select",
|
|
1302
|
+
placeholder: t("context objects placeholder"),
|
|
1303
|
+
items,
|
|
1304
|
+
onSearch: handleSearch,
|
|
1305
|
+
onUpdate
|
|
1306
|
+
});
|
|
1307
|
+
} finally {
|
|
1308
|
+
_effect.f();
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
// src/components/ChatPrompt/ChatStatusIndicator.tsx
|
|
1313
|
+
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
1314
|
+
import React5 from "react";
|
|
1315
|
+
import { Icon, Tooltip } from "@dxos/react-ui";
|
|
1316
|
+
import { Spinner } from "@dxos/react-ui-sfx";
|
|
1317
|
+
import { errorText } from "@dxos/react-ui-theme";
|
|
1318
|
+
var ChatStatusIndicator = ({ error, processing }) => {
|
|
1319
|
+
var _effect = _useSignals8();
|
|
1320
|
+
try {
|
|
1321
|
+
if (error) {
|
|
1322
|
+
return /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
|
|
1323
|
+
content: error.message,
|
|
1324
|
+
delayDuration: 0
|
|
1325
|
+
}, /* @__PURE__ */ React5.createElement(Icon, {
|
|
1326
|
+
icon: "ph--warning-circle--regular",
|
|
1327
|
+
classNames: errorText,
|
|
1328
|
+
size: 5
|
|
1329
|
+
}));
|
|
1330
|
+
}
|
|
1331
|
+
return /* @__PURE__ */ React5.createElement(Spinner, {
|
|
1332
|
+
active: processing
|
|
1333
|
+
});
|
|
1334
|
+
} finally {
|
|
1335
|
+
_effect.f();
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
// src/components/ChatThread/ChatThread.tsx
|
|
1340
|
+
import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
|
|
1341
|
+
import React8, { forwardRef, useMemo as useMemo6 } from "react";
|
|
1342
|
+
import { PublicKey } from "@dxos/keys";
|
|
1343
|
+
import { ScrollContainer } from "@dxos/react-ui-components";
|
|
1344
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
1345
|
+
import { keyToFallback } from "@dxos/util";
|
|
1346
|
+
|
|
1347
|
+
// src/components/ChatThread/ChatMessage.tsx
|
|
1348
|
+
import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
|
|
1349
|
+
import React7 from "react";
|
|
1350
|
+
import { Surface } from "@dxos/app-framework";
|
|
1351
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1352
|
+
import { Button, Icon as Icon2, IconButton as IconButton3 } from "@dxos/react-ui";
|
|
1353
|
+
import { MarkdownViewer, ToggleContainer as NativeToggleContainer } from "@dxos/react-ui-components";
|
|
1354
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
1355
|
+
import { safeParseJson } from "@dxos/util";
|
|
1356
|
+
|
|
1357
|
+
// src/components/ChatThread/ToolBlock.tsx
|
|
1358
|
+
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
1359
|
+
import React6, { useEffect as useEffect4, useMemo as useMemo5, useRef, useState as useState6 } from "react";
|
|
1360
|
+
import { log as log7 } from "@dxos/log";
|
|
1361
|
+
import { NumericTabs, StatusRoll, ToggleContainer } from "@dxos/react-ui-components";
|
|
1362
|
+
import { Json as NativeJson } from "@dxos/react-ui-syntax-highlighter";
|
|
1363
|
+
import { isNonNullable as isNonNullable4, isNotFalsy } from "@dxos/util";
|
|
1364
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/ToolBlock.tsx";
|
|
1365
|
+
var isToolMessage = (message) => {
|
|
1366
|
+
return message.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
|
|
1367
|
+
};
|
|
1368
|
+
var getToolName2 = (tool) => {
|
|
1369
|
+
return tool.namespace && tool.function ? `${tool.namespace}:${tool.function}` : tool.name.split("_").pop();
|
|
1370
|
+
};
|
|
1371
|
+
var getToolCaption = (tool, status) => {
|
|
1372
|
+
if (!tool) {
|
|
1373
|
+
return "Calling tool...";
|
|
1374
|
+
}
|
|
1375
|
+
return status?.message ?? tool.caption ?? `Calling ${getToolName2(tool)}...`;
|
|
1376
|
+
};
|
|
1377
|
+
var ToolBlock = ({ classNames, message, tools }) => {
|
|
1378
|
+
var _effect = _useSignals9();
|
|
1379
|
+
try {
|
|
1380
|
+
const { content = [] } = message;
|
|
1381
|
+
let request;
|
|
1382
|
+
const blocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
|
|
1383
|
+
const items = blocks.map((block) => {
|
|
1384
|
+
switch (block.type) {
|
|
1385
|
+
case "tool_use": {
|
|
1386
|
+
if (block.pending && request?.block.id === block.id) {
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
request = {
|
|
1390
|
+
tool: tools?.find((tool) => tool.name === block.name),
|
|
1391
|
+
block
|
|
1392
|
+
};
|
|
1393
|
+
return {
|
|
1394
|
+
title: getToolCaption(request.tool, block.currentStatus),
|
|
1395
|
+
block
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
case "tool_result": {
|
|
1399
|
+
if (!request) {
|
|
1400
|
+
log7.warn("unexpected message", {
|
|
1401
|
+
block
|
|
1402
|
+
}, {
|
|
1403
|
+
F: __dxlog_file7,
|
|
1404
|
+
L: 55,
|
|
1405
|
+
S: void 0,
|
|
1406
|
+
C: (f, a) => f(...a)
|
|
1407
|
+
});
|
|
1408
|
+
return {
|
|
1409
|
+
title: "Error",
|
|
1410
|
+
block
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
return {
|
|
1414
|
+
title: `${getToolCaption(request.tool, void 0)} (Success)`,
|
|
1415
|
+
block
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
default: {
|
|
1419
|
+
request = void 0;
|
|
1420
|
+
return {
|
|
1421
|
+
title: "Error",
|
|
1422
|
+
block
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}).filter(isNonNullable4);
|
|
1427
|
+
return /* @__PURE__ */ React6.createElement(ToolContainer, {
|
|
1428
|
+
classNames,
|
|
1429
|
+
items
|
|
1430
|
+
});
|
|
1431
|
+
} finally {
|
|
1432
|
+
_effect.f();
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
var ToolContainer = ({ classNames, items }) => {
|
|
1436
|
+
var _effect = _useSignals9();
|
|
1437
|
+
try {
|
|
1438
|
+
const tabsRef = useRef(null);
|
|
1439
|
+
const [selected, setSelected] = useState6(0);
|
|
1440
|
+
const [open, setOpen] = useState6(false);
|
|
1441
|
+
useEffect4(() => {
|
|
1442
|
+
if (open) {
|
|
1443
|
+
tabsRef.current?.focus();
|
|
1444
|
+
}
|
|
1445
|
+
}, [
|
|
1446
|
+
open
|
|
1447
|
+
]);
|
|
1448
|
+
const handleSelect = (index) => {
|
|
1449
|
+
if (index === selected) {
|
|
1450
|
+
setOpen(false);
|
|
1451
|
+
} else {
|
|
1452
|
+
setSelected(index);
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
const title = useMemo5(() => {
|
|
1456
|
+
const lines = items.map((item) => item.title).filter(isNotFalsy);
|
|
1457
|
+
return /* @__PURE__ */ React6.createElement(StatusRoll, {
|
|
1458
|
+
key: "status-roll",
|
|
1459
|
+
lines,
|
|
1460
|
+
duration: 1e3,
|
|
1461
|
+
autoAdvance: true
|
|
1462
|
+
});
|
|
1463
|
+
}, [
|
|
1464
|
+
items
|
|
1465
|
+
]);
|
|
1466
|
+
return /* @__PURE__ */ React6.createElement(ToggleContainer, {
|
|
1467
|
+
classNames: [
|
|
1468
|
+
"flex flex-col",
|
|
1469
|
+
classNames
|
|
1470
|
+
],
|
|
1471
|
+
title,
|
|
1472
|
+
open,
|
|
1473
|
+
onChangeOpen: setOpen
|
|
1474
|
+
}, /* @__PURE__ */ React6.createElement("div", {
|
|
1475
|
+
className: "w-full grid grid-cols-[32px_1fr]"
|
|
1476
|
+
}, /* @__PURE__ */ React6.createElement(NumericTabs, {
|
|
1477
|
+
ref: tabsRef,
|
|
1478
|
+
length: items.length,
|
|
1479
|
+
selected,
|
|
1480
|
+
onSelect: handleSelect
|
|
1481
|
+
}), /* @__PURE__ */ React6.createElement(Json, {
|
|
1482
|
+
data: items[selected].block
|
|
1483
|
+
})));
|
|
1484
|
+
} finally {
|
|
1485
|
+
_effect.f();
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
var Json = ({ data }) => {
|
|
1489
|
+
var _effect = _useSignals9();
|
|
1490
|
+
try {
|
|
1491
|
+
return /* @__PURE__ */ React6.createElement(NativeJson, {
|
|
1492
|
+
data,
|
|
1493
|
+
classNames: "!p-1 text-xs bg-transparent"
|
|
1494
|
+
});
|
|
1495
|
+
} finally {
|
|
1496
|
+
_effect.f();
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
|
|
1500
|
+
// src/components/ChatThread/ChatMessage.tsx
|
|
1501
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/ChatMessage.tsx";
|
|
1502
|
+
var ChatMessage = ({ classNames, space, processor, message, tools, onPrompt, onAddToGraph }) => {
|
|
1503
|
+
var _effect = _useSignals10();
|
|
1504
|
+
try {
|
|
1505
|
+
const { role, content = [] } = message;
|
|
1506
|
+
if (isToolMessage(message)) {
|
|
1507
|
+
return /* @__PURE__ */ React7.createElement(MessageContainer, {
|
|
1508
|
+
classNames: mx3(classNames, "animate-[fadeIn_0.5s]")
|
|
1509
|
+
}, /* @__PURE__ */ React7.createElement(ToolBlock, {
|
|
1510
|
+
classNames: panelClassNames,
|
|
1511
|
+
message,
|
|
1512
|
+
tools
|
|
1513
|
+
}));
|
|
1514
|
+
}
|
|
1515
|
+
return content.map((block, idx) => {
|
|
1516
|
+
if (block.type === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
|
|
1517
|
+
return null;
|
|
1518
|
+
}
|
|
1519
|
+
const Component = components[block.type] ?? components.default;
|
|
1520
|
+
return /* @__PURE__ */ React7.createElement(MessageContainer, {
|
|
1521
|
+
key: idx,
|
|
1522
|
+
classNames: mx3(classNames, "animate-[fadeIn_0.5s]"),
|
|
1523
|
+
user: block.type === "text" && role === "user"
|
|
1524
|
+
}, /* @__PURE__ */ React7.createElement(Component, {
|
|
1525
|
+
space,
|
|
1526
|
+
processor,
|
|
1527
|
+
block,
|
|
1528
|
+
onPrompt,
|
|
1529
|
+
onAddToGraph
|
|
1530
|
+
}));
|
|
1531
|
+
});
|
|
1532
|
+
} finally {
|
|
1533
|
+
_effect.f();
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
var components = {
|
|
1537
|
+
//
|
|
1538
|
+
// Text
|
|
1539
|
+
//
|
|
1540
|
+
["text"]: ({ block }) => {
|
|
1541
|
+
invariant2(block.type === "text", void 0, {
|
|
1542
|
+
F: __dxlog_file8,
|
|
1543
|
+
L: 90,
|
|
1544
|
+
S: void 0,
|
|
1545
|
+
A: [
|
|
1546
|
+
"block.type === 'text'",
|
|
1547
|
+
""
|
|
1548
|
+
]
|
|
1549
|
+
});
|
|
1550
|
+
const title = block.disposition ? titles[block.disposition] : void 0;
|
|
1551
|
+
if (!title) {
|
|
1552
|
+
return /* @__PURE__ */ React7.createElement(MarkdownViewer, {
|
|
1553
|
+
classNames: "[&>p]:animate-[fadeIn_0.5s]",
|
|
1554
|
+
content: block.text
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
return /* @__PURE__ */ React7.createElement(ToggleContainer2, {
|
|
1558
|
+
// open={open}
|
|
1559
|
+
defaultOpen: systemDispositions.includes(block.disposition ?? "") && block.pending,
|
|
1560
|
+
title,
|
|
1561
|
+
icon: block.pending ? /* @__PURE__ */ React7.createElement(Icon2, {
|
|
1562
|
+
icon: "ph--circle-notch--regular",
|
|
1563
|
+
classNames: "text-subdued ml-2 animate-spin",
|
|
1564
|
+
size: 4
|
|
1565
|
+
}) : void 0
|
|
1566
|
+
}, /* @__PURE__ */ React7.createElement(MarkdownViewer, {
|
|
1567
|
+
content: block.text,
|
|
1568
|
+
classNames: [
|
|
1569
|
+
"pbe-2",
|
|
1570
|
+
systemDispositions.includes(block.disposition ?? "") && "text-sm text-subdued"
|
|
1571
|
+
]
|
|
1572
|
+
}));
|
|
1573
|
+
},
|
|
1574
|
+
//
|
|
1575
|
+
// JSON
|
|
1576
|
+
//
|
|
1577
|
+
["json"]: ({ space, processor, block, onPrompt, onAddToGraph }) => {
|
|
1578
|
+
invariant2(block.type === "json", void 0, {
|
|
1579
|
+
F: __dxlog_file8,
|
|
1580
|
+
L: 128,
|
|
1581
|
+
S: void 0,
|
|
1582
|
+
A: [
|
|
1583
|
+
"block.type === 'json'",
|
|
1584
|
+
""
|
|
1585
|
+
]
|
|
1586
|
+
});
|
|
1587
|
+
switch (block.disposition) {
|
|
1588
|
+
case "tool_list": {
|
|
1589
|
+
return /* @__PURE__ */ React7.createElement(ToggleContainer2, {
|
|
1590
|
+
title: titles[block.disposition],
|
|
1591
|
+
defaultOpen: true
|
|
1592
|
+
}, /* @__PURE__ */ React7.createElement(ToolboxContainer, {
|
|
1593
|
+
space,
|
|
1594
|
+
processor,
|
|
1595
|
+
classNames: "pbe-2"
|
|
1596
|
+
}));
|
|
1597
|
+
}
|
|
1598
|
+
case "suggest": {
|
|
1599
|
+
const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
|
|
1600
|
+
return /* @__PURE__ */ React7.createElement(IconButton3, {
|
|
1601
|
+
icon: "ph--lightning--regular",
|
|
1602
|
+
label: text,
|
|
1603
|
+
onClick: () => onPrompt?.(text)
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
case "select": {
|
|
1607
|
+
const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
|
|
1608
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
1609
|
+
className: "flex flex-wrap gap-1"
|
|
1610
|
+
}, options.map((option, idx) => /* @__PURE__ */ React7.createElement(Button, {
|
|
1611
|
+
classNames: "animate-[fadeIn_0.5s] rounded-sm text-sm",
|
|
1612
|
+
key: option,
|
|
1613
|
+
onClick: () => onPrompt?.(option)
|
|
1614
|
+
}, option)));
|
|
1615
|
+
}
|
|
1616
|
+
case "graph": {
|
|
1617
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
1618
|
+
className: "flex flex-wrap gap-1"
|
|
1619
|
+
}, /* @__PURE__ */ React7.createElement(Surface, {
|
|
1620
|
+
role: "card",
|
|
1621
|
+
data: {
|
|
1622
|
+
subject: JSON.parse(block.json ?? "{}")
|
|
1623
|
+
},
|
|
1624
|
+
limit: 1,
|
|
1625
|
+
fallback: /* @__PURE__ */ React7.createElement("div", {
|
|
1626
|
+
className: "font-mono text-xs text-pre"
|
|
1627
|
+
}, block.json)
|
|
1628
|
+
}), onAddToGraph && /* @__PURE__ */ React7.createElement(IconButton3, {
|
|
1629
|
+
icon: "ph--plus--regular",
|
|
1630
|
+
label: "Add to graph",
|
|
1631
|
+
onClick: () => onAddToGraph?.(JSON.parse(block.json ?? "{}"))
|
|
1632
|
+
}));
|
|
1633
|
+
}
|
|
1634
|
+
default: {
|
|
1635
|
+
const title = block.disposition ? titles[block.disposition] : void 0;
|
|
1636
|
+
return /* @__PURE__ */ React7.createElement(ToggleContainer2, {
|
|
1637
|
+
title: title ?? "JSON"
|
|
1638
|
+
}, /* @__PURE__ */ React7.createElement(Json, {
|
|
1639
|
+
data: safeParseJson(block.json ?? block)
|
|
1640
|
+
}));
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
},
|
|
1644
|
+
//
|
|
1645
|
+
// Default
|
|
1646
|
+
//
|
|
1647
|
+
default: ({ block }) => {
|
|
1648
|
+
let title = titles[block.type];
|
|
1649
|
+
if (block.type === "tool_use") {
|
|
1650
|
+
title = `Tool [${block.name}]`;
|
|
1651
|
+
}
|
|
1652
|
+
return /* @__PURE__ */ React7.createElement(ToggleContainer2, {
|
|
1653
|
+
title: title ?? "JSON"
|
|
1654
|
+
}, /* @__PURE__ */ React7.createElement(Json, {
|
|
1655
|
+
data: block
|
|
1656
|
+
}));
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
var titles = {
|
|
1660
|
+
["cot"]: "Chain of thought",
|
|
1661
|
+
["artifact"]: "Artifact",
|
|
1662
|
+
["tool_use"]: "Tool request",
|
|
1663
|
+
["tool_result"]: "Tool result",
|
|
1664
|
+
["tool_list"]: "Tools",
|
|
1665
|
+
["artifact-update"]: "Artifact(s) changed"
|
|
1666
|
+
};
|
|
1667
|
+
var systemDispositions = [
|
|
1668
|
+
"cot",
|
|
1669
|
+
"artifact-update"
|
|
1670
|
+
];
|
|
1671
|
+
var panelClassNames = "flex flex-col w-full px-2 bg-activeSurface rounded-sm";
|
|
1672
|
+
var userClassNames = "bg-[--user-fill] text-accentSurfaceText";
|
|
1673
|
+
var ToggleContainer2 = (props) => {
|
|
1674
|
+
var _effect = _useSignals10();
|
|
1675
|
+
try {
|
|
1676
|
+
return /* @__PURE__ */ React7.createElement(NativeToggleContainer, {
|
|
1677
|
+
...props,
|
|
1678
|
+
classNames: mx3(panelClassNames, props.classNames)
|
|
1679
|
+
});
|
|
1680
|
+
} finally {
|
|
1681
|
+
_effect.f();
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
var MessageContainer = ({ children, classNames, user }) => {
|
|
1685
|
+
var _effect = _useSignals10();
|
|
1686
|
+
try {
|
|
1687
|
+
if (!children) {
|
|
1688
|
+
return null;
|
|
1689
|
+
}
|
|
1690
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
1691
|
+
role: "list-item",
|
|
1692
|
+
className: mx3("flex w-full", user && "justify-end", classNames)
|
|
1693
|
+
}, /* @__PURE__ */ React7.createElement("div", {
|
|
1694
|
+
className: mx3(user ? [
|
|
1695
|
+
"px-2 py-1 rounded-sm",
|
|
1696
|
+
userClassNames
|
|
1697
|
+
] : "w-full")
|
|
1698
|
+
}, children));
|
|
1699
|
+
} finally {
|
|
1700
|
+
_effect.f();
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1704
|
+
// src/components/ChatThread/reducer.ts
|
|
1705
|
+
var messageReducer = ({ current, messages }, message) => {
|
|
1706
|
+
let i = 0;
|
|
1707
|
+
for (const block of message.content) {
|
|
1708
|
+
switch (block.type) {
|
|
1709
|
+
case "tool_use":
|
|
1710
|
+
case "tool_result": {
|
|
1711
|
+
if (current) {
|
|
1712
|
+
current.content.push(block);
|
|
1713
|
+
} else {
|
|
1714
|
+
current = {
|
|
1715
|
+
id: [
|
|
1716
|
+
message.id,
|
|
1717
|
+
i
|
|
1718
|
+
].join("_"),
|
|
1719
|
+
role: message.role,
|
|
1720
|
+
content: [
|
|
1721
|
+
block
|
|
1722
|
+
]
|
|
1723
|
+
};
|
|
1724
|
+
messages.push(current);
|
|
1725
|
+
}
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
case "text":
|
|
1729
|
+
default: {
|
|
1730
|
+
current = void 0;
|
|
1731
|
+
messages.push({
|
|
1732
|
+
id: [
|
|
1733
|
+
message.id,
|
|
1734
|
+
i
|
|
1735
|
+
].join("_"),
|
|
1736
|
+
role: message.role,
|
|
1737
|
+
content: [
|
|
1738
|
+
block
|
|
1739
|
+
]
|
|
1740
|
+
});
|
|
1741
|
+
break;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
i++;
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
current,
|
|
1748
|
+
messages
|
|
1749
|
+
};
|
|
1750
|
+
};
|
|
1751
|
+
|
|
1752
|
+
// src/components/ChatThread/ChatThread.tsx
|
|
1753
|
+
var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, space, processor, messages, collapse = true, ...props }, forwardedRef) => {
|
|
1754
|
+
var _effect = _useSignals11();
|
|
1755
|
+
try {
|
|
1756
|
+
const userHue = useMemo6(() => {
|
|
1757
|
+
return identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue;
|
|
1758
|
+
}, [
|
|
1759
|
+
identity
|
|
1760
|
+
]);
|
|
1761
|
+
const { messages: filteredMessages = [] } = useMemo6(() => {
|
|
1762
|
+
if (collapse) {
|
|
1763
|
+
return (messages ?? []).reduce(messageReducer, {
|
|
1764
|
+
messages: []
|
|
1765
|
+
});
|
|
1766
|
+
} else {
|
|
1767
|
+
return {
|
|
1768
|
+
messages: messages ?? []
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
}, [
|
|
1772
|
+
messages,
|
|
1773
|
+
collapse
|
|
1774
|
+
]);
|
|
1775
|
+
return /* @__PURE__ */ React8.createElement(ScrollContainer, {
|
|
1776
|
+
ref: forwardedRef,
|
|
1777
|
+
classNames,
|
|
1778
|
+
fade: true
|
|
1779
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
1780
|
+
role: "none",
|
|
1781
|
+
className: mx4(filteredMessages.length > 0 && "pbs-6 pbe-6"),
|
|
1782
|
+
style: {
|
|
1783
|
+
"--user-fill": `var(--dx-${userHue}Fill)`
|
|
1784
|
+
}
|
|
1785
|
+
}, filteredMessages.map((message) => /* @__PURE__ */ React8.createElement(ChatMessage, {
|
|
1786
|
+
key: message.id,
|
|
1787
|
+
classNames: "px-4 pbe-4",
|
|
1788
|
+
space,
|
|
1789
|
+
processor,
|
|
1790
|
+
message,
|
|
1791
|
+
...props
|
|
1792
|
+
}))));
|
|
1793
|
+
} finally {
|
|
1794
|
+
_effect.f();
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
|
|
1798
|
+
// src/components/Chat/Chat.tsx
|
|
1799
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Chat/Chat.tsx";
|
|
1800
|
+
var Endcap = ({ children }) => {
|
|
1801
|
+
var _effect = _useSignals12();
|
|
1802
|
+
try {
|
|
1803
|
+
return /* @__PURE__ */ React9.createElement("div", {
|
|
1804
|
+
className: "grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center"
|
|
1805
|
+
}, children);
|
|
1806
|
+
} finally {
|
|
1807
|
+
_effect.f();
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
var [ChatContextProvider, useChatContext] = createContext("Chat");
|
|
1811
|
+
var ChatRoot = ({ classNames, children, chat, processor, artifact, onEvent, ...props }) => {
|
|
1812
|
+
var _effect = _useSignals12();
|
|
1813
|
+
try {
|
|
1814
|
+
const space = getSpace(chat);
|
|
1815
|
+
const queue = useQueue(chat?.queue.dxn);
|
|
1816
|
+
const messages = useMemo7(() => dedupeWith([
|
|
1817
|
+
...queue?.objects?.filter(Obj3.instanceOf(Message)) ?? [],
|
|
1818
|
+
...processor?.messages.value ?? []
|
|
1819
|
+
], (a, b) => a.id === b.id), [
|
|
1820
|
+
queue?.objects,
|
|
1821
|
+
processor?.messages.value
|
|
1822
|
+
]);
|
|
1823
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher2();
|
|
1824
|
+
useEffect5(() => {
|
|
1825
|
+
if (!processor?.streaming.value && queue?.objects && artifact) {
|
|
1826
|
+
const message = queue.objects[queue.objects.length - 1];
|
|
1827
|
+
if (dispatch && space && chat && message) {
|
|
1828
|
+
void dispatch(createIntent(CollaborationActions.InsertContent, {
|
|
1829
|
+
target: artifact,
|
|
1830
|
+
object: Ref3.fromDXN(new DXN(DXN.kind.QUEUE, [
|
|
1831
|
+
...chat.queue.dxn.parts,
|
|
1832
|
+
message.id
|
|
1833
|
+
])),
|
|
1834
|
+
label: "View proposal"
|
|
1835
|
+
}));
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
}, [
|
|
1839
|
+
queue,
|
|
1840
|
+
processor?.streaming.value
|
|
1841
|
+
]);
|
|
1842
|
+
const event = useMemo7(() => new Event(), []);
|
|
1843
|
+
useEffect5(() => {
|
|
1844
|
+
return event.on((event2) => {
|
|
1845
|
+
switch (event2.type) {
|
|
1846
|
+
case "submit": {
|
|
1847
|
+
if (!processor.streaming.value) {
|
|
1848
|
+
void processor.request(event2.text);
|
|
1849
|
+
}
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
case "cancel": {
|
|
1853
|
+
void processor.cancel();
|
|
1854
|
+
break;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
onEvent?.(event2);
|
|
1858
|
+
});
|
|
1859
|
+
}, [
|
|
1860
|
+
event,
|
|
1861
|
+
onEvent
|
|
1862
|
+
]);
|
|
1863
|
+
if (!space) {
|
|
1864
|
+
return null;
|
|
1865
|
+
}
|
|
1866
|
+
return /* @__PURE__ */ React9.createElement(ChatContextProvider, {
|
|
1867
|
+
event,
|
|
1868
|
+
chat,
|
|
1869
|
+
space,
|
|
1870
|
+
processor,
|
|
1871
|
+
messages,
|
|
1872
|
+
...props
|
|
1873
|
+
}, /* @__PURE__ */ React9.createElement("div", {
|
|
1874
|
+
role: "none",
|
|
1875
|
+
className: mx5("flex flex-col grow", classNames)
|
|
1876
|
+
}, children));
|
|
1877
|
+
} finally {
|
|
1878
|
+
_effect.f();
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
ChatRoot.displayName = "Chat.Root";
|
|
1882
|
+
var ChatThread2 = (props) => {
|
|
1883
|
+
var _effect = _useSignals12();
|
|
1884
|
+
try {
|
|
1885
|
+
const { event, space, processor, messages } = useChatContext(ChatThread2.displayName);
|
|
1886
|
+
const identity = useIdentity();
|
|
1887
|
+
const scrollerRef = useRef2(null);
|
|
1888
|
+
useEffect5(() => {
|
|
1889
|
+
return event.on((event2) => {
|
|
1890
|
+
switch (event2.type) {
|
|
1891
|
+
case "submit":
|
|
1892
|
+
case "scroll-to-bottom":
|
|
1893
|
+
scrollerRef.current?.scrollToBottom("smooth");
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
});
|
|
1897
|
+
}, [
|
|
1898
|
+
event
|
|
1899
|
+
]);
|
|
1900
|
+
const handlePrompt = useCallback4((text) => {
|
|
1901
|
+
if (!processor.streaming.value) {
|
|
1902
|
+
event.emit({
|
|
1903
|
+
type: "submit",
|
|
1904
|
+
text
|
|
1905
|
+
});
|
|
1906
|
+
return true;
|
|
1907
|
+
}
|
|
1908
|
+
}, [
|
|
1909
|
+
processor,
|
|
1910
|
+
event
|
|
1911
|
+
]);
|
|
1912
|
+
if (!identity) {
|
|
1913
|
+
return null;
|
|
1914
|
+
}
|
|
1915
|
+
return /* @__PURE__ */ React9.createElement(ChatThread, {
|
|
1916
|
+
...props,
|
|
1917
|
+
ref: scrollerRef,
|
|
1918
|
+
identity,
|
|
1919
|
+
space,
|
|
1920
|
+
messages,
|
|
1921
|
+
tools: processor?.tools,
|
|
1922
|
+
onPrompt: handlePrompt
|
|
1923
|
+
});
|
|
1924
|
+
} finally {
|
|
1925
|
+
_effect.f();
|
|
1926
|
+
}
|
|
1927
|
+
};
|
|
1928
|
+
ChatThread2.displayName = "Chat.Thread";
|
|
1929
|
+
var ChatPrompt = ({ classNames, placeholder, expandable }) => {
|
|
1930
|
+
var _effect = _useSignals12();
|
|
1931
|
+
try {
|
|
1932
|
+
const { t } = useTranslation5(meta.id);
|
|
1933
|
+
const { space, event, processor } = useChatContext(ChatPrompt.displayName);
|
|
1934
|
+
const [active, setActive] = useState7(false);
|
|
1935
|
+
useEffect5(() => {
|
|
1936
|
+
return event.on((event2) => {
|
|
1937
|
+
switch (event2.type) {
|
|
1938
|
+
case "record-start":
|
|
1939
|
+
setActive(true);
|
|
1940
|
+
break;
|
|
1941
|
+
case "record-stop":
|
|
1942
|
+
setActive(false);
|
|
1943
|
+
break;
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
}, [
|
|
1947
|
+
event
|
|
1948
|
+
]);
|
|
1949
|
+
const editorRef = useRef2(null);
|
|
1950
|
+
const { recording } = useVoiceInput({
|
|
1951
|
+
active,
|
|
1952
|
+
onUpdate: (text) => {
|
|
1953
|
+
editorRef.current?.setText(text);
|
|
1954
|
+
editorRef.current?.focus();
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1957
|
+
const [blueprints, handleUpdateBlueprints] = useBlueprints(processor.context);
|
|
1958
|
+
const contextProvider = useContextProvider(space);
|
|
1959
|
+
const extensions = useMemo7(() => {
|
|
1960
|
+
return [
|
|
1961
|
+
contextProvider && references({
|
|
1962
|
+
provider: {
|
|
1963
|
+
getReferences: async ({ query }) => contextProvider.query({
|
|
1964
|
+
query
|
|
1965
|
+
}),
|
|
1966
|
+
resolveReference: async ({ uri }) => contextProvider.resolveMetadata({
|
|
1967
|
+
uri
|
|
1968
|
+
})
|
|
1969
|
+
}
|
|
1970
|
+
}),
|
|
1971
|
+
expandable && Prec.highest(keymap.of([
|
|
1972
|
+
{
|
|
1973
|
+
key: "cmd-ArrowUp",
|
|
1974
|
+
preventDefault: true,
|
|
1975
|
+
run: () => {
|
|
1976
|
+
event.emit({
|
|
1977
|
+
type: "thread-open"
|
|
1978
|
+
});
|
|
1979
|
+
return true;
|
|
1980
|
+
}
|
|
1981
|
+
},
|
|
1982
|
+
{
|
|
1983
|
+
key: "cmd-ArrowDown",
|
|
1984
|
+
preventDefault: true,
|
|
1985
|
+
run: () => {
|
|
1986
|
+
event.emit({
|
|
1987
|
+
type: "thread-close"
|
|
1988
|
+
});
|
|
1989
|
+
return true;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
]))
|
|
1993
|
+
].filter(isNotFalsy2);
|
|
1994
|
+
}, [
|
|
1995
|
+
event,
|
|
1996
|
+
expandable,
|
|
1997
|
+
contextProvider
|
|
1998
|
+
]);
|
|
1999
|
+
const handleSubmit = useCallback4((text) => {
|
|
2000
|
+
if (!processor.streaming.value) {
|
|
2001
|
+
event.emit({
|
|
2002
|
+
type: "submit",
|
|
2003
|
+
text
|
|
2004
|
+
});
|
|
2005
|
+
return true;
|
|
2006
|
+
}
|
|
2007
|
+
}, [
|
|
2008
|
+
processor,
|
|
2009
|
+
event
|
|
2010
|
+
]);
|
|
2011
|
+
const handleEvent = useCallback4((ev) => {
|
|
2012
|
+
event.emit(ev);
|
|
2013
|
+
}, [
|
|
2014
|
+
event
|
|
2015
|
+
]);
|
|
2016
|
+
const handleUpdateReferences = useCallback4((ids) => {
|
|
2017
|
+
log8.info("update", {
|
|
2018
|
+
ids
|
|
2019
|
+
}, {
|
|
2020
|
+
F: __dxlog_file9,
|
|
2021
|
+
L: 289,
|
|
2022
|
+
S: void 0,
|
|
2023
|
+
C: (f, a) => f(...a)
|
|
2024
|
+
});
|
|
2025
|
+
}, []);
|
|
2026
|
+
return /* @__PURE__ */ React9.createElement("div", {
|
|
2027
|
+
className: mx5("is-full grid grid-cols-[var(--rail-action)_1fr_min-content] grid-rows-[min-content_var(--rail-action)]", classNames)
|
|
2028
|
+
}, /* @__PURE__ */ React9.createElement(Endcap, null, /* @__PURE__ */ React9.createElement(ChatStatusIndicator, {
|
|
2029
|
+
error: processor.error.value,
|
|
2030
|
+
processing: processor.streaming.value
|
|
2031
|
+
})), /* @__PURE__ */ React9.createElement(ChatEditor, {
|
|
2032
|
+
ref: editorRef,
|
|
2033
|
+
autoFocus: true,
|
|
2034
|
+
lineWrapping: true,
|
|
2035
|
+
classNames: "col-span-2 pis-1 pbs-2",
|
|
2036
|
+
placeholder: placeholder ?? t("prompt placeholder"),
|
|
2037
|
+
extensions,
|
|
2038
|
+
onSubmit: handleSubmit
|
|
2039
|
+
}), /* @__PURE__ */ React9.createElement(ChatOptionsMenu, {
|
|
2040
|
+
blueprintRegistry: processor.blueprintRegistry,
|
|
2041
|
+
blueprints,
|
|
2042
|
+
onChange: handleUpdateBlueprints
|
|
2043
|
+
}), /* @__PURE__ */ React9.createElement(ChatReferences, {
|
|
2044
|
+
classNames: "flex pis-1 items-center",
|
|
2045
|
+
space,
|
|
2046
|
+
context: processor.context,
|
|
2047
|
+
onUpdate: handleUpdateReferences
|
|
2048
|
+
}), /* @__PURE__ */ React9.createElement(ChatActions, {
|
|
2049
|
+
microphone: true,
|
|
2050
|
+
recording,
|
|
2051
|
+
processing: processor.streaming.value,
|
|
2052
|
+
onEvent: handleEvent
|
|
2053
|
+
}));
|
|
2054
|
+
} finally {
|
|
2055
|
+
_effect.f();
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
ChatPrompt.displayName = "Chat.Prompt";
|
|
2059
|
+
var Chat = {
|
|
2060
|
+
Root: ChatRoot,
|
|
2061
|
+
Thread: ChatThread2,
|
|
2062
|
+
Prompt: ChatPrompt
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
export {
|
|
2066
|
+
useChatProcessor,
|
|
2067
|
+
useServiceContainer,
|
|
2068
|
+
Toolbox,
|
|
2069
|
+
ToolboxContainer,
|
|
2070
|
+
Chat
|
|
2071
|
+
};
|
|
2072
|
+
//# sourceMappingURL=chunk-TQ3QW3HJ.mjs.map
|