@assistant-ui/react 0.7.43 → 0.7.44
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/api/AssistantRuntime.d.ts +11 -3
- package/dist/api/AssistantRuntime.d.ts.map +1 -1
- package/dist/api/AssistantRuntime.js +8 -17
- package/dist/api/AssistantRuntime.js.map +1 -1
- package/dist/api/AssistantRuntime.mjs +8 -17
- package/dist/api/AssistantRuntime.mjs.map +1 -1
- package/dist/api/RuntimePathTypes.d.ts +4 -1
- package/dist/api/RuntimePathTypes.d.ts.map +1 -1
- package/dist/api/RuntimePathTypes.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.d.ts +8 -0
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js +4 -0
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs +4 -0
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/api/ThreadListRuntime.d.ts +11 -1
- package/dist/api/ThreadListRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListRuntime.js +37 -1
- package/dist/api/ThreadListRuntime.js.map +1 -1
- package/dist/api/ThreadListRuntime.mjs +39 -1
- package/dist/api/ThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.d.ts +15 -0
- package/dist/runtimes/adapters/RuntimeAdapterProvider.d.ts.map +1 -0
- package/dist/runtimes/adapters/RuntimeAdapterProvider.js +45 -0
- package/dist/runtimes/adapters/RuntimeAdapterProvider.js.map +1 -0
- package/dist/runtimes/adapters/RuntimeAdapterProvider.mjs +19 -0
- package/dist/runtimes/adapters/RuntimeAdapterProvider.mjs.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/AttachmentAdapter.d.ts +1 -1
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/AttachmentAdapter.js +1 -1
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.js.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/CompositeAttachmentAdapter.d.ts +2 -2
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/CompositeAttachmentAdapter.js +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/CompositeAttachmentAdapter.mjs +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/SimpleImageAttachmentAdapter.d.ts +1 -1
- package/dist/runtimes/adapters/attachment/SimpleImageAttachmentAdapter.d.ts.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/SimpleImageAttachmentAdapter.js +1 -1
- package/dist/runtimes/adapters/attachment/SimpleImageAttachmentAdapter.js.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/SimpleImageAttachmentAdapter.mjs +1 -1
- package/dist/runtimes/adapters/attachment/SimpleImageAttachmentAdapter.mjs.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/SimpleTextAttachmentAdapter.d.ts +1 -1
- package/dist/runtimes/adapters/attachment/SimpleTextAttachmentAdapter.d.ts.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/SimpleTextAttachmentAdapter.js +1 -1
- package/dist/runtimes/adapters/attachment/SimpleTextAttachmentAdapter.js.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/SimpleTextAttachmentAdapter.mjs +1 -1
- package/dist/runtimes/adapters/attachment/SimpleTextAttachmentAdapter.mjs.map +1 -0
- package/dist/runtimes/adapters/attachment/index.d.ts.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/index.js +1 -1
- package/dist/runtimes/adapters/attachment/index.js.map +1 -0
- package/dist/runtimes/{attachment → adapters/attachment}/index.mjs +1 -1
- package/dist/runtimes/adapters/attachment/index.mjs.map +1 -0
- package/dist/runtimes/{feedback → adapters/feedback}/FeedbackAdapter.d.ts +1 -1
- package/dist/runtimes/adapters/feedback/FeedbackAdapter.d.ts.map +1 -0
- package/dist/runtimes/{feedback → adapters/feedback}/FeedbackAdapter.js +1 -1
- package/dist/runtimes/adapters/feedback/FeedbackAdapter.js.map +1 -0
- package/dist/runtimes/adapters/feedback/index.d.ts.map +1 -0
- package/dist/runtimes/{feedback → adapters/feedback}/index.js +1 -1
- package/dist/runtimes/adapters/feedback/index.js.map +1 -0
- package/dist/runtimes/adapters/index.d.ts +4 -0
- package/dist/runtimes/adapters/index.d.ts.map +1 -0
- package/dist/runtimes/adapters/index.js +29 -0
- package/dist/runtimes/adapters/index.js.map +1 -0
- package/dist/runtimes/adapters/index.mjs +5 -0
- package/dist/runtimes/adapters/index.mjs.map +1 -0
- package/dist/runtimes/{speech → adapters/speech}/SpeechAdapterTypes.d.ts +1 -1
- package/dist/runtimes/adapters/speech/SpeechAdapterTypes.d.ts.map +1 -0
- package/dist/runtimes/{speech → adapters/speech}/SpeechAdapterTypes.js +1 -1
- package/dist/runtimes/adapters/speech/SpeechAdapterTypes.js.map +1 -0
- package/dist/runtimes/adapters/speech/WebSpeechSynthesisAdapter.d.ts.map +1 -0
- package/dist/runtimes/{speech → adapters/speech}/WebSpeechSynthesisAdapter.js +1 -1
- package/dist/runtimes/adapters/speech/WebSpeechSynthesisAdapter.js.map +1 -0
- package/dist/runtimes/{speech → adapters/speech}/WebSpeechSynthesisAdapter.mjs +1 -1
- package/dist/runtimes/adapters/speech/WebSpeechSynthesisAdapter.mjs.map +1 -0
- package/dist/runtimes/adapters/speech/index.d.ts.map +1 -0
- package/dist/runtimes/{speech → adapters/speech}/index.js +1 -1
- package/dist/runtimes/adapters/speech/index.js.map +1 -0
- package/dist/runtimes/{speech → adapters/speech}/index.mjs +1 -1
- package/dist/runtimes/adapters/speech/index.mjs.map +1 -0
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.d.ts +6 -0
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.d.ts.map +1 -0
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.js +19 -0
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.js.map +1 -0
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.mjs +1 -0
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.mjs.map +1 -0
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.d.ts +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.d.ts +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.d.ts +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +3 -3
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +5 -0
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +3 -3
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js +4 -4
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs +4 -4
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +2 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +6 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +6 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +7 -0
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +7 -0
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/index.d.ts +1 -3
- package/dist/runtimes/index.d.ts.map +1 -1
- package/dist/runtimes/index.js +3 -7
- package/dist/runtimes/index.js.map +1 -1
- package/dist/runtimes/index.mjs +1 -3
- package/dist/runtimes/index.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.js +5 -5
- package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.mjs +5 -5
- package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts +6 -3
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +2 -0
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +8 -0
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +8 -0
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +7 -3
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +7 -3
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +1 -1
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +32 -2
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +11 -5
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +11 -5
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.d.ts +3 -2
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.js +9 -4
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.js.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.mjs +9 -4
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.d.ts +6 -3
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.js +13 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.js.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.mjs +13 -1
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/index.d.ts +0 -1
- package/dist/runtimes/remote-thread-list/cloud/index.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/index.js +0 -3
- package/dist/runtimes/remote-thread-list/cloud/index.js.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/index.mjs +0 -2
- package/dist/runtimes/remote-thread-list/cloud/index.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js +26 -49
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs +27 -56
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +2 -2
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/types.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +5 -5
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +5 -5
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/utils/MessageRepository.d.ts +4 -0
- package/dist/runtimes/utils/MessageRepository.d.ts.map +1 -1
- package/dist/runtimes/utils/MessageRepository.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/AssistantRuntime.ts +19 -18
- package/src/api/RuntimePathTypes.ts +6 -1
- package/src/api/ThreadListItemRuntime.ts +9 -0
- package/src/api/ThreadListRuntime.ts +56 -1
- package/src/runtimes/adapters/RuntimeAdapterProvider.tsx +31 -0
- package/src/runtimes/{attachment → adapters/attachment}/AttachmentAdapter.ts +1 -1
- package/src/runtimes/{attachment → adapters/attachment}/CompositeAttachmentAdapter.ts +1 -1
- package/src/runtimes/{attachment → adapters/attachment}/SimpleImageAttachmentAdapter.ts +1 -1
- package/src/runtimes/{attachment → adapters/attachment}/SimpleTextAttachmentAdapter.ts +1 -1
- package/src/runtimes/{feedback → adapters/feedback}/FeedbackAdapter.ts +1 -1
- package/src/runtimes/adapters/index.ts +3 -0
- package/src/runtimes/{speech → adapters/speech}/SpeechAdapterTypes.ts +1 -1
- package/src/runtimes/adapters/thread-history/ThreadHistoryAdapter.ts +9 -0
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +1 -1
- package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +1 -1
- package/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx +1 -1
- package/src/runtimes/core/AssistantRuntimeCore.tsx +1 -1
- package/src/runtimes/core/BaseAssistantRuntimeCore.tsx +1 -1
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +3 -3
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +6 -0
- package/src/runtimes/core/ThreadRuntimeCore.tsx +2 -1
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +3 -3
- package/src/runtimes/external-store/ExternalStoreRuntimeCore.tsx +4 -4
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +8 -0
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +8 -0
- package/src/runtimes/index.ts +1 -3
- package/src/runtimes/local/LocalRuntimeCore.tsx +5 -5
- package/src/runtimes/local/LocalRuntimeOptions.tsx +5 -3
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +10 -0
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +7 -3
- package/src/runtimes/local/useLocalRuntime.tsx +1 -1
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +14 -12
- package/src/runtimes/remote-thread-list/cloud/AssistantCloudAPI.tsx +13 -5
- package/src/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.tsx +24 -4
- package/src/runtimes/remote-thread-list/cloud/index.ts +0 -1
- package/src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx +36 -60
- package/src/runtimes/remote-thread-list/types.tsx +2 -5
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +5 -5
- package/src/runtimes/utils/MessageRepository.tsx +5 -0
- package/dist/runtimes/attachment/AttachmentAdapter.d.ts.map +0 -1
- package/dist/runtimes/attachment/AttachmentAdapter.js.map +0 -1
- package/dist/runtimes/attachment/CompositeAttachmentAdapter.d.ts.map +0 -1
- package/dist/runtimes/attachment/CompositeAttachmentAdapter.js.map +0 -1
- package/dist/runtimes/attachment/CompositeAttachmentAdapter.mjs.map +0 -1
- package/dist/runtimes/attachment/SimpleImageAttachmentAdapter.d.ts.map +0 -1
- package/dist/runtimes/attachment/SimpleImageAttachmentAdapter.js.map +0 -1
- package/dist/runtimes/attachment/SimpleImageAttachmentAdapter.mjs.map +0 -1
- package/dist/runtimes/attachment/SimpleTextAttachmentAdapter.d.ts.map +0 -1
- package/dist/runtimes/attachment/SimpleTextAttachmentAdapter.js.map +0 -1
- package/dist/runtimes/attachment/SimpleTextAttachmentAdapter.mjs.map +0 -1
- package/dist/runtimes/attachment/index.d.ts.map +0 -1
- package/dist/runtimes/attachment/index.js.map +0 -1
- package/dist/runtimes/attachment/index.mjs.map +0 -1
- package/dist/runtimes/feedback/FeedbackAdapter.d.ts.map +0 -1
- package/dist/runtimes/feedback/FeedbackAdapter.js.map +0 -1
- package/dist/runtimes/feedback/index.d.ts.map +0 -1
- package/dist/runtimes/feedback/index.js.map +0 -1
- package/dist/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.d.ts +0 -22
- package/dist/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.d.ts.map +0 -1
- package/dist/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.js +0 -85
- package/dist/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.js.map +0 -1
- package/dist/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.mjs +0 -60
- package/dist/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.mjs.map +0 -1
- package/dist/runtimes/speech/SpeechAdapterTypes.d.ts.map +0 -1
- package/dist/runtimes/speech/SpeechAdapterTypes.js.map +0 -1
- package/dist/runtimes/speech/WebSpeechSynthesisAdapter.d.ts.map +0 -1
- package/dist/runtimes/speech/WebSpeechSynthesisAdapter.js.map +0 -1
- package/dist/runtimes/speech/WebSpeechSynthesisAdapter.mjs.map +0 -1
- package/dist/runtimes/speech/index.d.ts.map +0 -1
- package/dist/runtimes/speech/index.js.map +0 -1
- package/dist/runtimes/speech/index.mjs.map +0 -1
- package/src/runtimes/remote-thread-list/cloud/CloudThreadListItemRuntime.tsx +0 -89
- /package/dist/runtimes/{attachment → adapters/attachment}/AttachmentAdapter.mjs +0 -0
- /package/dist/runtimes/{attachment → adapters/attachment}/AttachmentAdapter.mjs.map +0 -0
- /package/dist/runtimes/{attachment → adapters/attachment}/index.d.ts +0 -0
- /package/dist/runtimes/{feedback → adapters/feedback}/FeedbackAdapter.mjs +0 -0
- /package/dist/runtimes/{feedback → adapters/feedback}/FeedbackAdapter.mjs.map +0 -0
- /package/dist/runtimes/{feedback → adapters/feedback}/index.d.ts +0 -0
- /package/dist/runtimes/{feedback → adapters/feedback}/index.mjs +0 -0
- /package/dist/runtimes/{feedback → adapters/feedback}/index.mjs.map +0 -0
- /package/dist/runtimes/{speech → adapters/speech}/SpeechAdapterTypes.mjs +0 -0
- /package/dist/runtimes/{speech → adapters/speech}/SpeechAdapterTypes.mjs.map +0 -0
- /package/dist/runtimes/{speech → adapters/speech}/WebSpeechSynthesisAdapter.d.ts +0 -0
- /package/dist/runtimes/{speech → adapters/speech}/index.d.ts +0 -0
- /package/src/runtimes/{attachment → adapters/attachment}/index.ts +0 -0
- /package/src/runtimes/{feedback → adapters/feedback}/index.ts +0 -0
- /package/src/runtimes/{speech → adapters/speech}/WebSpeechSynthesisAdapter.ts +0 -0
- /package/src/runtimes/{speech → adapters/speech}/index.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalRuntimeOptions.tsx"],"sourcesContent":["import { AttachmentAdapter } from \"../attachment/AttachmentAdapter\";\nimport { ThreadMessageLike } from \"../external-store\";\nimport { FeedbackAdapter } from \"../feedback/FeedbackAdapter\";\nimport { SpeechSynthesisAdapter } from \"../speech/SpeechAdapterTypes\";\nimport { ChatModelAdapter } from \"./ChatModelAdapter\";\n\nexport type LocalRuntimeOptionsBase = {\n maxSteps?: number | undefined;\n adapters: {\n chatModel: ChatModelAdapter;\n attachments?: AttachmentAdapter | undefined;\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n };\n};\n\n// TODO align LocalRuntimeOptions with LocalRuntimeOptionsBase\nexport type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, \"adapters\"> & {\n initialMessages?: readonly ThreadMessageLike[] | undefined;\n adapters?: Omit<LocalRuntimeOptionsBase[\"adapters\"], \"chatModel\"> | undefined;\n};\n\nexport const splitLocalRuntimeOptions = <T extends LocalRuntimeOptions>(\n options: T,\n) => {\n const { initialMessages, maxSteps, adapters, ...rest } = options;\n\n return {\n localRuntimeOptions: {\n initialMessages,\n maxSteps,\n adapters,\n },\n otherOptions: rest,\n };\n};\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalRuntimeOptions.tsx"],"sourcesContent":["import { ThreadHistoryAdapter } from \"../adapters/thread-history/ThreadHistoryAdapter\";\nimport { AttachmentAdapter } from \"../adapters/attachment/AttachmentAdapter\";\nimport { ThreadMessageLike } from \"../external-store\";\nimport { FeedbackAdapter } from \"../adapters/feedback/FeedbackAdapter\";\nimport { SpeechSynthesisAdapter } from \"../adapters/speech/SpeechAdapterTypes\";\nimport { ChatModelAdapter } from \"./ChatModelAdapter\";\n\nexport type LocalRuntimeOptionsBase = {\n maxSteps?: number | undefined;\n adapters: {\n chatModel: ChatModelAdapter;\n history?: ThreadHistoryAdapter | undefined;\n attachments?: AttachmentAdapter | undefined;\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n };\n};\n\n// TODO align LocalRuntimeOptions with LocalRuntimeOptionsBase\nexport type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, \"adapters\"> & {\n initialMessages?: readonly ThreadMessageLike[] | undefined;\n adapters?: Omit<LocalRuntimeOptionsBase[\"adapters\"], \"chatModel\"> | undefined;\n};\n\nexport const splitLocalRuntimeOptions = <T extends LocalRuntimeOptions>(\n options: T,\n) => {\n const { initialMessages, maxSteps, adapters, ...rest } = options;\n\n return {\n localRuntimeOptions: {\n initialMessages,\n maxSteps,\n adapters,\n },\n otherOptions: rest,\n };\n};\n"],"mappings":";AAwBO,IAAM,2BAA2B,CACtC,YACG;AACH,QAAM,EAAE,iBAAiB,UAAU,UAAU,GAAG,KAAK,IAAI;AAEzD,SAAO;AAAA,IACL,qBAAqB;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,cAAc;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -24,6 +24,7 @@ export declare class LocalThreadListRuntimeCore implements ThreadListRuntimeCore
|
|
|
24
24
|
get mainThreadId(): string;
|
|
25
25
|
constructor(_threadFactory: LocalThreadFactory);
|
|
26
26
|
getMainThreadRuntimeCore(): LocalThreadRuntimeCore;
|
|
27
|
+
getThreadRuntimeCore(threadId: string): LocalThreadRuntimeCore;
|
|
27
28
|
getLoadThreadsPromise(): Promise<void>;
|
|
28
29
|
getItemById(threadId: string): LocalThreadData | undefined;
|
|
29
30
|
switchToThread(threadId: string): Promise<void>;
|
|
@@ -33,6 +34,7 @@ export declare class LocalThreadListRuntimeCore implements ThreadListRuntimeCore
|
|
|
33
34
|
archive(threadId: string): Promise<void>;
|
|
34
35
|
unarchive(threadId: string): Promise<void>;
|
|
35
36
|
delete(threadId: string): Promise<void>;
|
|
37
|
+
initialize(): never;
|
|
36
38
|
private _subscriptions;
|
|
37
39
|
subscribe(callback: () => void): Unsubscribe;
|
|
38
40
|
private _notifySubscribers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,GAAG,UAAU,CAAC;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,sBAAsB,CAAC;AAG9D,qBAAa,0BAA2B,YAAW,qBAAqB;IAwB1D,OAAO,CAAC,cAAc;IAvBlC,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,YAAY,CAAqB;IAEzC,IAAW,WAAW,uBAErB;IAED,IAAW,SAAS,sBAEnB;IAED,IAAW,iBAAiB,sBAE3B;IAED,OAAO,CAAC,aAAa,CAAU;IAE/B,IAAW,YAAY,IAAI,MAAM,CAEhC;gBAEmB,cAAc,EAAE,kBAAkB;IAI/C,wBAAwB;IAOxB,qBA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,qBAAqB;IAwB1D,OAAO,CAAC,cAAc;IAvBlC,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,YAAY,CAAqB;IAEzC,IAAW,WAAW,uBAErB;IAED,IAAW,SAAS,sBAEnB;IAED,IAAW,iBAAiB,sBAE3B;IAED,OAAO,CAAC,aAAa,CAAU;IAE/B,IAAW,YAAY,IAAI,MAAM,CAEhC;gBAEmB,cAAc,EAAE,kBAAkB;IAI/C,wBAAwB;IAOxB,oBAAoB,CAAC,QAAQ,EAAE,MAAM;IAMrC,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC,WAAW,CAAC,QAAQ,EAAE,MAAM;IAItB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;YA2B3B,QAAQ;IAwEf,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYzD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1C,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvC,UAAU,IAAI,KAAK;IAI1B,OAAO,CAAC,cAAc,CAAyB;IAExC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW;IAKnD,OAAO,CAAC,kBAAkB;CAG3B"}
|
|
@@ -53,6 +53,11 @@ var LocalThreadListRuntimeCore = class {
|
|
|
53
53
|
throw new Error("Main thread not found. This is a bug in assistant-ui.");
|
|
54
54
|
return result;
|
|
55
55
|
}
|
|
56
|
+
getThreadRuntimeCore(threadId) {
|
|
57
|
+
const result = this._threadData.get(threadId)?.runtime;
|
|
58
|
+
if (!result) throw new Error("Thread not found.");
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
56
61
|
getLoadThreadsPromise() {
|
|
57
62
|
return RESOLVED_PROMISE;
|
|
58
63
|
}
|
|
@@ -177,6 +182,9 @@ var LocalThreadListRuntimeCore = class {
|
|
|
177
182
|
this._stateOp(threadId, "deleted");
|
|
178
183
|
return Promise.resolve();
|
|
179
184
|
}
|
|
185
|
+
initialize() {
|
|
186
|
+
throw new Error("Method not implemented.");
|
|
187
|
+
}
|
|
180
188
|
_subscriptions = /* @__PURE__ */ new Set();
|
|
181
189
|
subscribe(callback) {
|
|
182
190
|
this._subscriptions.add(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../utils/idUtils\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type ThreadListAdapter = {\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport type LocalThreadData = {\n readonly runtime: LocalThreadRuntimeCore;\n readonly status: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n};\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst RESOLVED_PROMISE = Promise.resolve();\nexport class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _threadData = new Map<string, LocalThreadData>();\n private _threadIds: readonly string[] = [];\n private _archivedThreadIds: readonly string[] = [];\n private _newThreadId: string | undefined;\n\n public get newThreadId() {\n return this._newThreadId;\n }\n\n public get threadIds() {\n return this._threadIds;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreadIds;\n }\n\n private _mainThreadId!: string;\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n constructor(private _threadFactory: LocalThreadFactory) {\n this.switchToNewThread();\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._threadData.get(this._mainThreadId)?.runtime;\n if (!result)\n throw new Error(\"Main thread not found. This is a bug in assistant-ui.\");\n return result;\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return RESOLVED_PROMISE;\n }\n\n public getItemById(threadId: string) {\n return this._threadData.get(threadId);\n }\n\n public async switchToThread(threadId: string): Promise<void> {\n if (this._mainThreadId === threadId) return;\n\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (data.status === \"archived\") await this.unarchive(threadId);\n\n this._mainThreadId = data.threadId;\n this._notifySubscribers();\n }\n\n public switchToNewThread(): Promise<void> {\n if (this._newThreadId === undefined) {\n let threadId: string;\n do {\n threadId = generateId();\n } while (this._threadData.has(threadId));\n\n const runtime = this._threadFactory();\n const dispose = runtime.unstable_on(\"initialize\", () => {\n dispose();\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._stateOp(threadId, \"regular\");\n });\n this._threadData.set(threadId, {\n runtime,\n status: \"new\",\n threadId,\n });\n this._newThreadId = threadId;\n }\n\n this.switchToThread(this._newThreadId);\n return Promise.resolve();\n }\n\n private async _stateOp(\n threadId: string,\n newState: \"regular\" | \"archived\" | \"deleted\",\n ) {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n const { status: lastState } = data;\n if (lastState === newState) return;\n\n // lastState\n switch (lastState) {\n case \"new\":\n this._newThreadId = undefined;\n break;\n case \"regular\":\n this._threadIds = this._threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n this._archivedThreadIds = this._archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newState\n switch (newState) {\n case \"regular\":\n this._threadIds = [data.threadId, ...this._threadIds];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\n break;\n\n default: {\n const _exhaustiveCheck: never = newState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newState !== \"deleted\") {\n this._threadData.set(threadId, {\n ...data,\n status: newState,\n });\n }\n\n if (\n threadId === this._mainThreadId &&\n (newState === \"archived\" || newState === \"deleted\")\n ) {\n const lastThreadId = this._threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n } else {\n this._notifySubscribers();\n }\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._threadData.set(threadId, {\n ...data,\n title: newTitle,\n });\n this._notifySubscribers();\n return Promise.resolve();\n }\n\n public archive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n this._stateOp(threadId, \"archived\");\n return Promise.resolve();\n }\n\n public unarchive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n this._stateOp(threadId, \"regular\");\n return Promise.resolve();\n }\n\n public delete(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;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AC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,aAAa,KAAK,WAAW;AAC/C,YAAM,IAAI,MAAM,+BAA+B;AAEjD,SAAK,SAAS,UAAU,SAAS;AACjC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEQ,iBAAiB,oBAAI,IAAgB;AAAA,EAEtC,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../utils/idUtils\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type ThreadListAdapter = {\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport type LocalThreadData = {\n readonly runtime: LocalThreadRuntimeCore;\n readonly status: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n};\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst RESOLVED_PROMISE = Promise.resolve();\nexport class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _threadData = new Map<string, LocalThreadData>();\n private _threadIds: readonly string[] = [];\n private _archivedThreadIds: readonly string[] = [];\n private _newThreadId: string | undefined;\n\n public get newThreadId() {\n return this._newThreadId;\n }\n\n public get threadIds() {\n return this._threadIds;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreadIds;\n }\n\n private _mainThreadId!: string;\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n constructor(private _threadFactory: LocalThreadFactory) {\n this.switchToNewThread();\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._threadData.get(this._mainThreadId)?.runtime;\n if (!result)\n throw new Error(\"Main thread not found. This is a bug in assistant-ui.\");\n return result;\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const result = this._threadData.get(threadId)?.runtime;\n if (!result) throw new Error(\"Thread not found.\");\n return result;\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return RESOLVED_PROMISE;\n }\n\n public getItemById(threadId: string) {\n return this._threadData.get(threadId);\n }\n\n public async switchToThread(threadId: string): Promise<void> {\n if (this._mainThreadId === threadId) return;\n\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (data.status === \"archived\") await this.unarchive(threadId);\n\n this._mainThreadId = data.threadId;\n this._notifySubscribers();\n }\n\n public switchToNewThread(): Promise<void> {\n if (this._newThreadId === undefined) {\n let threadId: string;\n do {\n threadId = generateId();\n } while (this._threadData.has(threadId));\n\n const runtime = this._threadFactory();\n const dispose = runtime.unstable_on(\"initialize\", () => {\n dispose();\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._stateOp(threadId, \"regular\");\n });\n this._threadData.set(threadId, {\n runtime,\n status: \"new\",\n threadId,\n });\n this._newThreadId = threadId;\n }\n\n this.switchToThread(this._newThreadId);\n return Promise.resolve();\n }\n\n private async _stateOp(\n threadId: string,\n newState: \"regular\" | \"archived\" | \"deleted\",\n ) {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n const { status: lastState } = data;\n if (lastState === newState) return;\n\n // lastState\n switch (lastState) {\n case \"new\":\n this._newThreadId = undefined;\n break;\n case \"regular\":\n this._threadIds = this._threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n this._archivedThreadIds = this._archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newState\n switch (newState) {\n case \"regular\":\n this._threadIds = [data.threadId, ...this._threadIds];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\n break;\n\n default: {\n const _exhaustiveCheck: never = newState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newState !== \"deleted\") {\n this._threadData.set(threadId, {\n ...data,\n status: newState,\n });\n }\n\n if (\n threadId === this._mainThreadId &&\n (newState === \"archived\" || newState === \"deleted\")\n ) {\n const lastThreadId = this._threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n } else {\n this._notifySubscribers();\n }\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._threadData.set(threadId, {\n ...data,\n title: newTitle,\n });\n this._notifySubscribers();\n return Promise.resolve();\n }\n\n public archive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n this._stateOp(threadId, \"archived\");\n return Promise.resolve();\n }\n\n public unarchive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n this._stateOp(threadId, \"regular\");\n return Promise.resolve();\n }\n\n public delete(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n public initialize(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscrib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M,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,WAAY,OAAM,IAAI,MAAM,wBAAwB;AAExE,SAAK,SAAS,UAAU,SAAS;AACjC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,OAAO,UAAiC;AAC7C,UAAM,OAAO,KAAK,YAAY,IAAI,QAAQ;AAC1C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,aAAa,KAAK,WAAW;AAC/C,YAAM,IAAI,MAAM,+BAA+B;AAEjD,SAAK,SAAS,UAAU,SAAS;AACjC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,aAAoB;AACzB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEQ,iBAAiB,oBAAI,IAAgB;AAAA,EAEtC,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -29,6 +29,11 @@ var LocalThreadListRuntimeCore = class {
|
|
|
29
29
|
throw new Error("Main thread not found. This is a bug in assistant-ui.");
|
|
30
30
|
return result;
|
|
31
31
|
}
|
|
32
|
+
getThreadRuntimeCore(threadId) {
|
|
33
|
+
const result = this._threadData.get(threadId)?.runtime;
|
|
34
|
+
if (!result) throw new Error("Thread not found.");
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
32
37
|
getLoadThreadsPromise() {
|
|
33
38
|
return RESOLVED_PROMISE;
|
|
34
39
|
}
|
|
@@ -153,6 +158,9 @@ var LocalThreadListRuntimeCore = class {
|
|
|
153
158
|
this._stateOp(threadId, "deleted");
|
|
154
159
|
return Promise.resolve();
|
|
155
160
|
}
|
|
161
|
+
initialize() {
|
|
162
|
+
throw new Error("Method not implemented.");
|
|
163
|
+
}
|
|
156
164
|
_subscriptions = /* @__PURE__ */ new Set();
|
|
157
165
|
subscribe(callback) {
|
|
158
166
|
this._subscriptions.add(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../utils/idUtils\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type ThreadListAdapter = {\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport type LocalThreadData = {\n readonly runtime: LocalThreadRuntimeCore;\n readonly status: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n};\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst RESOLVED_PROMISE = Promise.resolve();\nexport class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _threadData = new Map<string, LocalThreadData>();\n private _threadIds: readonly string[] = [];\n private _archivedThreadIds: readonly string[] = [];\n private _newThreadId: string | undefined;\n\n public get newThreadId() {\n return this._newThreadId;\n }\n\n public get threadIds() {\n return this._threadIds;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreadIds;\n }\n\n private _mainThreadId!: string;\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n constructor(private _threadFactory: LocalThreadFactory) {\n this.switchToNewThread();\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._threadData.get(this._mainThreadId)?.runtime;\n if (!result)\n throw new Error(\"Main thread not found. This is a bug in assistant-ui.\");\n return result;\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return RESOLVED_PROMISE;\n }\n\n public getItemById(threadId: string) {\n return this._threadData.get(threadId);\n }\n\n public async switchToThread(threadId: string): Promise<void> {\n if (this._mainThreadId === threadId) return;\n\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (data.status === \"archived\") await this.unarchive(threadId);\n\n this._mainThreadId = data.threadId;\n this._notifySubscribers();\n }\n\n public switchToNewThread(): Promise<void> {\n if (this._newThreadId === undefined) {\n let threadId: string;\n do {\n threadId = generateId();\n } while (this._threadData.has(threadId));\n\n const runtime = this._threadFactory();\n const dispose = runtime.unstable_on(\"initialize\", () => {\n dispose();\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._stateOp(threadId, \"regular\");\n });\n this._threadData.set(threadId, {\n runtime,\n status: \"new\",\n threadId,\n });\n this._newThreadId = threadId;\n }\n\n this.switchToThread(this._newThreadId);\n return Promise.resolve();\n }\n\n private async _stateOp(\n threadId: string,\n newState: \"regular\" | \"archived\" | \"deleted\",\n ) {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n const { status: lastState } = data;\n if (lastState === newState) return;\n\n // lastState\n switch (lastState) {\n case \"new\":\n this._newThreadId = undefined;\n break;\n case \"regular\":\n this._threadIds = this._threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n this._archivedThreadIds = this._archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newState\n switch (newState) {\n case \"regular\":\n this._threadIds = [data.threadId, ...this._threadIds];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\n break;\n\n default: {\n const _exhaustiveCheck: never = newState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newState !== \"deleted\") {\n this._threadData.set(threadId, {\n ...data,\n status: newState,\n });\n }\n\n if (\n threadId === this._mainThreadId &&\n (newState === \"archived\" || newState === \"deleted\")\n ) {\n const lastThreadId = this._threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n } else {\n this._notifySubscribers();\n }\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._threadData.set(threadId, {\n ...data,\n title: newTitle,\n });\n this._notifySubscribers();\n return Promise.resolve();\n }\n\n public archive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n this._stateOp(threadId, \"archived\");\n return Promise.resolve();\n }\n\n public unarchive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n this._stateOp(threadId, \"regular\");\n return Promise.resolve();\n }\n\n public delete(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";AAEA,SAAS,kBAAkB;AAgB3B,IAAM,mBAAmB,QAAQ,QAAQ;AAClC,IAAM,6BAAN,MAAkE;AAAA,EAwBvE,YAAoB,gBAAoC;AAApC;AAClB,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAzBQ,cAAc,oBAAI,IAA6B;AAAA,EAC/C,aAAgC,CAAC;AAAA,EACjC,qBAAwC,CAAC;AAAA,EACzC;AAAA,EAER,IAAW,cAAc;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,YAAY;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,oBA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UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../utils/idUtils\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type ThreadListAdapter = {\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport type LocalThreadData = {\n readonly runtime: LocalThreadRuntimeCore;\n readonly status: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n};\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst RESOLVED_PROMISE = Promise.resolve();\nexport class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _threadData = new Map<string, LocalThreadData>();\n private _threadIds: readonly string[] = [];\n private _archivedThreadIds: readonly string[] = [];\n private _newThreadId: string | undefined;\n\n public get newThreadId() {\n return this._newThreadId;\n }\n\n public get threadIds() {\n return this._threadIds;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreadIds;\n }\n\n private _mainThreadId!: string;\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n constructor(private _threadFactory: LocalThreadFactory) {\n this.switchToNewThread();\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._threadData.get(this._mainThreadId)?.runtime;\n if (!result)\n throw new Error(\"Main thread not found. This is a bug in assistant-ui.\");\n return result;\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const result = this._threadData.get(threadId)?.runtime;\n if (!result) throw new Error(\"Thread not found.\");\n return result;\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return RESOLVED_PROMISE;\n }\n\n public getItemById(threadId: string) {\n return this._threadData.get(threadId);\n }\n\n public async switchToThread(threadId: string): Promise<void> {\n if (this._mainThreadId === threadId) return;\n\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (data.status === \"archived\") await this.unarchive(threadId);\n\n this._mainThreadId = data.threadId;\n this._notifySubscribers();\n }\n\n public switchToNewThread(): Promise<void> {\n if (this._newThreadId === undefined) {\n let threadId: string;\n do {\n threadId = generateId();\n } while (this._threadData.has(threadId));\n\n const runtime = this._threadFactory();\n const dispose = runtime.unstable_on(\"initialize\", () => {\n dispose();\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._stateOp(threadId, \"regular\");\n });\n this._threadData.set(threadId, {\n runtime,\n status: \"new\",\n threadId,\n });\n this._newThreadId = threadId;\n }\n\n this.switchToThread(this._newThreadId);\n return Promise.resolve();\n }\n\n private async _stateOp(\n threadId: string,\n newState: \"regular\" | \"archived\" | \"deleted\",\n ) {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n const { status: lastState } = data;\n if (lastState === newState) return;\n\n // lastState\n switch (lastState) {\n case \"new\":\n this._newThreadId = undefined;\n break;\n case \"regular\":\n this._threadIds = this._threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n this._archivedThreadIds = this._archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newState\n switch (newState) {\n case \"regular\":\n this._threadIds = [data.threadId, ...this._threadIds];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\n break;\n\n default: {\n const _exhaustiveCheck: never = newState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newState !== \"deleted\") {\n this._threadData.set(threadId, {\n ...data,\n status: newState,\n });\n }\n\n if (\n threadId === this._mainThreadId &&\n (newState === \"archived\" || newState === \"deleted\")\n ) {\n const lastThreadId = this._threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n } else {\n this._notifySubscribers();\n }\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._threadData.set(threadId, {\n ...data,\n title: newTitle,\n });\n this._notifySubscribers();\n return Promise.resolve();\n }\n\n public archive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n this._stateOp(threadId, \"archived\");\n return Promise.resolve();\n }\n\n public unarchive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n this._stateOp(threadId, \"regular\");\n return Promise.resolve();\n }\n\n public delete(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n public initialize(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";AAEA,SAAS,kBAAkB;AAgB3B,IAAM,mBAAmB,QAAQ,QAAQ;AAClC,IAAM,6BAAN,MAAkE;AAAA,EAwBvE,YAAoB,gBAAoC;AAApC;AAClB,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAzBQ,cAAc,oBAAI,IAA6B;AAAA,EAC/C,aAAgC,CAAC;AAAA,EACjC,qBAAwC,CAAC;AAAA,EACzC;AAAA,EAER,IAAW,cAAc;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,YAAY;AACrB,WAAO,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,aAAoB;AACzB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEQ,iBAAiB,oBAAI,IAAgB;AAAA,EAEtC,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -18,6 +18,7 @@ export declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implem
|
|
|
18
18
|
readonly suggestions: readonly ThreadSuggestion[];
|
|
19
19
|
get adapters(): {
|
|
20
20
|
chatModel: import("./ChatModelAdapter").ChatModelAdapter;
|
|
21
|
+
history?: import("../adapters/thread-history/ThreadHistoryAdapter").ThreadHistoryAdapter | undefined;
|
|
21
22
|
attachments?: import("..").AttachmentAdapter | undefined;
|
|
22
23
|
speech?: import("..").SpeechSynthesisAdapter | undefined;
|
|
23
24
|
feedback?: import("..").FeedbackAdapter | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalThreadRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EAEd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,qBAAa,sBACX,SAAQ,qBACR,YAAW,iBAAiB;IAE5B,SAAgB,YAAY;;;;;;;;;MAS1B;IAEF,OAAO,CAAC,eAAe,CAAgC;IAEvD,SAAgB,UAAU,SAAS;IACnC,SAAgB,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAM;IAE9D,IAAW,QAAQ
|
|
1
|
+
{"version":3,"file":"LocalThreadRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EAEd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,qBAAa,sBACX,SAAQ,qBACR,YAAW,iBAAiB;IAE5B,SAAgB,YAAY;;;;;;;;;MAS1B;IAEF,OAAO,CAAC,eAAe,CAAgC;IAEvD,SAAgB,UAAU,SAAS;IACnC,SAAgB,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAM;IAE9D,IAAW,QAAQ;;;;;;MAElB;gBAGC,cAAc,EAAE,mBAAmB,EACnC,OAAO,EAAE,uBAAuB;IAMlC,OAAO,CAAC,QAAQ,CAA2B;IAE3C,OAAO,CAAC,cAAc,CAAiB;IAEvC,IAAW,MAAM,cAEhB;IAEM,qBAAqB,CAAC,OAAO,EAAE,uBAAuB;IA4BhD,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB7C,QAAQ,CAAC,EACpB,QAAQ,EACR,SAAS,GACV,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;YA2BnB,gBAAgB;IAkHvB,SAAS;IAKT,aAAa,CAAC,EACnB,SAAS,EACT,UAAU,EACV,MAAM,GACP,EAAE,oBAAoB;CAkCxB"}
|
|
@@ -108,9 +108,13 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
|
108
108
|
createdAt: /* @__PURE__ */ new Date()
|
|
109
109
|
};
|
|
110
110
|
this._notifyEventSubscribers("run-start");
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
try {
|
|
112
|
+
do {
|
|
113
|
+
message = await this.performRoundtrip(parentId, message, runConfig);
|
|
114
|
+
} while ((0, import_shouldContinue.shouldContinue)(message));
|
|
115
|
+
} finally {
|
|
116
|
+
this._notifyEventSubscribers("run-end");
|
|
117
|
+
}
|
|
114
118
|
}
|
|
115
119
|
async performRoundtrip(parentId, message, runConfig) {
|
|
116
120
|
const messages = this.repository.getMessages();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { unstable_data: [], steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newData = m.metadata?.unstable_data;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAM3B,kBAAgC;AAEhC,4BAA+B;AAQ/B,mCAAsC;AAG/B,IAAM,yBAAN,cACG,mDAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,SACA;AACA,UAAM,cAAc;AACpB,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA,EAEQ;AAAA,EAEA,iBAA4B,CAAC;AAAA,EAErC,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,sBAAsB,SAAkC;AAC7D,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,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,EAEO,YAAY;AACjB,SAAK,iBAAiB,MAAM;AAC5B,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAEO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAyB;AACvB,UAAM,cAAc,KAAK,WAAW,WAAW,SAAS;AACxD,UAAM,EAAE,SAAS,IAAI;AACrB,QAAI,EAAE,QAAQ,IAAI;AAElB,QAAI,QAAQ,SAAS;AACnB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,QAAQ;AACZ,QAAI,QAAQ;AACZ,UAAM,aAAa,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,aAAS,sCAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { unstable_data: [], steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n try {\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (shouldContinue(message));\n } finally {\n this._notifyEventSubscribers(\"run-end\");\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newData = m.metadata?.unstable_data;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAM3B,kBAAgC;AAEhC,4BAA+B;AAQ/B,mCAAsC;AAG/B,IAAM,yBAAN,cACG,mDAEV;AAAA,EAC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AEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,aAAS,sCAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
|
@@ -84,9 +84,13 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
84
84
|
createdAt: /* @__PURE__ */ new Date()
|
|
85
85
|
};
|
|
86
86
|
this._notifyEventSubscribers("run-start");
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
try {
|
|
88
|
+
do {
|
|
89
|
+
message = await this.performRoundtrip(parentId, message, runConfig);
|
|
90
|
+
} while (shouldContinue(message));
|
|
91
|
+
} finally {
|
|
92
|
+
this._notifyEventSubscribers("run-end");
|
|
93
|
+
}
|
|
90
94
|
}
|
|
91
95
|
async performRoundtrip(parentId, message, runConfig) {
|
|
92
96
|
const messages = this.repository.getMessages();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { unstable_data: [], steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (shouldContinue(message));\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newData = m.metadata?.unstable_data;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAM3B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAQ/B,SAAS,6BAA6B;AAG/B,IAAM,yBAAN,cACG,sBAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IA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I,aAAa,SAAS,EAAE,SAAS,cAAc;AACjD,sBAAc;AAAA,UACZ,QAAQ,EAAE,MAAM,cAAc,QAAQ,YAAY;AAAA,QACpD,CAAC;AAAA,MACH,OAAO;AACL,sBAAc;AAAA,UACZ,QAAQ,EAAE,MAAM,cAAc,QAAQ,SAAS,OAAO,EAAE;AAAA,QAC1D,CAAC;AAED,cAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEO,YAAY;AACjB,SAAK,iBAAiB,MAAM;AAC5B,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAEO,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAyB;AACvB,UAAM,cAAc,KAAK,WAAW,WAAW,SAAS;AACxD,UAAM,EAAE,SAAS,IAAI;AACrB,QAAI,EAAE,QAAQ,IAAI;AAElB,QAAI,QAAQ,SAAS;AACnB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,QAAQ;AACZ,QAAI,QAAQ;AACZ,UAAM,aAAa,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,SAAS,eAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type {\n ModelConfigProvider,\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(configProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: { unstable_data: [], steps: [], custom: {} },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n try {\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (shouldContinue(message));\n } finally {\n this._notifyEventSubscribers(\"run-end\");\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newData = m.metadata?.unstable_data;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n config: this.getModelConfig(),\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: { type: \"incomplete\", reason: \"error\", error: e },\n });\n\n throw e;\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (added && shouldContinue(message)) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAM3B,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAQ/B,SAAS,6BAA6B;AAG/B,IAAM,yBAAN,cACG,sBAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,gBACA,SACA;AACA,UAAM,cAAc;AACpB,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA,EAEQ;AAAA,EAEA,iBAA4B,CAAC;AAAA,EAErC,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,sBAAsB,SAAkC;AAC7D,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,WAAW;AAEhB,QAAI,aAAa;AAEjB,UAAM,WAAW,QAAQ,UAAU,WAAW;AAC9C,QAAI,KAAK,aAAa,WAAW,UAAU;AACzC,WAAK,aAAa,SAAS;AAC3B,mBAAa;AAAA,IACf;AAEA,UAAM,YAAY,QAAQ,UAAU,gBAAgB;AACpD,QAAI,KAAK,aAAa,gBAAgB,WAAW;AAC/C,WAAK,aAAa,cAAc;AAChC,mBAAa;AAAA,IACf;AAEA,UAAM,cAAc,QAAQ,UAAU,aAAa;AACnD,QAAI,KAAK,aAAa,aAAa,aAAa;AAC9C,WAAK,aAAa,WAAW;AAC7B,mBAAa;AAAA,IACf;AAEA,QAAI,WAAY,MAAK,mBAAmB;AAAA,EAC1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AC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QAAI,SAAS,eAAe,OAAO,GAAG;AACpC,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
|
@@ -50,7 +50,7 @@ var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
|
|
|
50
50
|
};
|
|
51
51
|
const [runtime] = (0, import_react.useState)(() => new import_LocalRuntimeCore.LocalRuntimeCore(opt, initialMessages));
|
|
52
52
|
(0, import_react.useEffect)(() => {
|
|
53
|
-
runtime.
|
|
53
|
+
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
|
54
54
|
}, [runtime, opt]);
|
|
55
55
|
return (0, import_react.useMemo)(() => LocalRuntimeImpl.create(runtime), [runtime]);
|
|
56
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6C;AAE7C,8BAAiC;AAEjC,8BAGO;AACP,sBAAkC;AAMlC,IAAM,mBAAN,MAAM,0BAAyB,6CAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iCAAiB;AADH;AAAA,EAE5B;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,yCAAiB,KAAK,eAAe,CAAC;AAE3E,8BAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AAAA,EACtE,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,aAAO,sBAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
|
|
@@ -29,7 +29,7 @@ var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
|
|
|
29
29
|
};
|
|
30
30
|
const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));
|
|
31
31
|
useEffect(() => {
|
|
32
|
-
runtime.
|
|
32
|
+
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
|
33
33
|
}, [runtime, opt]);
|
|
34
34
|
return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);
|
|
35
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport {\n AssistantRuntime,\n AssistantRuntimeImpl,\n} from \"../../api/AssistantRuntime\";\nimport { ThreadRuntimeImpl } from \"../../internal\";\n\nexport type LocalRuntime = AssistantRuntime & {\n reset: (options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) => void;\n};\n\nclass LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {\n private constructor(private core: LocalRuntimeCore) {\n super(core, ThreadRuntimeImpl);\n }\n\n public reset(options?: Parameters<LocalRuntimeCore[\"reset\"]>[0]) {\n this.core.reset(options);\n }\n\n public static override create(_core: LocalRuntimeCore): LocalRuntime {\n return new LocalRuntimeImpl(_core);\n }\n}\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions = {},\n) => {\n const opt = {\n ...options,\n adapters: {\n ...options.adapters,\n chatModel: adapter,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n }, [runtime, opt]);\n\n return useMemo(() => LocalRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AAE7C,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAMlC,IAAM,mBAAN,MAAM,0BAAyB,qBAA6C;AAAA,EAClE,YAAoB,MAAwB;AAClD,UAAM,MAAM,iBAAiB;AADH;AAAA,EAE5B;AAAA,EAEO,MAAM,SAAoD;AAC/D,SAAK,KAAK,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,OAAuB,OAAO,OAAuC;AACnE,WAAO,IAAI,kBAAiB,KAAK;AAAA,EACnC;AACF;AAEO,IAAM,kBAAkB,CAC7B,SACA,EAAE,iBAAiB,GAAG,QAAQ,IAAyB,CAAC,MACrD;AACH,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAU;AAAA,MACR,GAAG,QAAQ;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,iBAAiB,KAAK,eAAe,CAAC;AAE3E,YAAU,MAAM;AACd,YAAQ,QAAQ,yBAAyB,EAAE,sBAAsB,GAAG;AAAA,EACtE,GAAG,CAAC,SAAS,GAAG,CAAC;AAEjB,SAAO,QAAQ,MAAM,iBAAiB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AAClE;","names":[]}
|
|
@@ -25,7 +25,7 @@ export declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscriba
|
|
|
25
25
|
constructor(adapter: RemoteThreadListAdapter);
|
|
26
26
|
private useProvider;
|
|
27
27
|
__internal_setAdapter(adapter: RemoteThreadListAdapter): void;
|
|
28
|
-
__internal_bindAdapter(): import("../..").Unsubscribe;
|
|
28
|
+
__internal_bindAdapter(): import("../..").Unsubscribe | undefined;
|
|
29
29
|
get threadIds(): readonly string[];
|
|
30
30
|
get archivedThreadIds(): readonly string[];
|
|
31
31
|
get newThreadId(): string | undefined;
|
|
@@ -60,10 +60,40 @@ export declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscriba
|
|
|
60
60
|
export(): import("../utils/MessageRepository").ExportedMessageRepository;
|
|
61
61
|
unstable_on(event: import("../core/ThreadRuntimeCore").ThreadRuntimeEventType, callback: () => void): import("../..").Unsubscribe;
|
|
62
62
|
}>;
|
|
63
|
+
getThreadRuntimeCore(threadIdOrRemoteId: string): Readonly<{
|
|
64
|
+
getMessageById: (messageId: string) => {
|
|
65
|
+
parentId: string | null;
|
|
66
|
+
message: import("../..").ThreadMessage;
|
|
67
|
+
} | undefined;
|
|
68
|
+
getBranches: (messageId: string) => readonly string[];
|
|
69
|
+
switchToBranch: (branchId: string) => void;
|
|
70
|
+
append: (message: import("../..").AppendMessage) => void;
|
|
71
|
+
startRun: (config: import("../core/ThreadRuntimeCore").StartRunConfig) => void;
|
|
72
|
+
cancelRun: () => void;
|
|
73
|
+
addToolResult: (options: import("..").AddToolResultOptions) => void;
|
|
74
|
+
speak: (messageId: string) => void;
|
|
75
|
+
stopSpeaking: () => void;
|
|
76
|
+
getSubmittedFeedback: (messageId: string) => import("../core/ThreadRuntimeCore").SubmittedFeedback | undefined;
|
|
77
|
+
submitFeedback: (feedback: import("..").SubmitFeedbackOptions) => void;
|
|
78
|
+
getModelConfig: () => import("../..").ModelConfig;
|
|
79
|
+
composer: import("../core/ComposerRuntimeCore").ThreadComposerRuntimeCore;
|
|
80
|
+
getEditComposer: (messageId: string) => import("../core/ComposerRuntimeCore").ComposerRuntimeCore | undefined;
|
|
81
|
+
beginEdit: (messageId: string) => void;
|
|
82
|
+
speech: import("../core/ThreadRuntimeCore").SpeechState | undefined;
|
|
83
|
+
capabilities: Readonly<import("../core/ThreadRuntimeCore").RuntimeCapabilities>;
|
|
84
|
+
isDisabled: boolean;
|
|
85
|
+
messages: readonly import("../..").ThreadMessage[];
|
|
86
|
+
suggestions: readonly import("..").ThreadSuggestion[];
|
|
87
|
+
extras: unknown;
|
|
88
|
+
subscribe: (callback: () => void) => import("../..").Unsubscribe;
|
|
89
|
+
import(repository: import("../utils/MessageRepository").ExportedMessageRepository): void;
|
|
90
|
+
export(): import("../utils/MessageRepository").ExportedMessageRepository;
|
|
91
|
+
unstable_on(event: import("../core/ThreadRuntimeCore").ThreadRuntimeEventType, callback: () => void): import("../..").Unsubscribe;
|
|
92
|
+
}>;
|
|
63
93
|
getItemById(threadIdOrRemoteId: string): RemoteThreadData | undefined;
|
|
64
94
|
switchToThread(threadIdOrRemoteId: string): Promise<void>;
|
|
65
95
|
switchToNewThread(): Promise<void>;
|
|
66
|
-
|
|
96
|
+
initialize: (threadId: string) => Promise<import("./types").RemoteThreadInitializeResponse>;
|
|
67
97
|
private _onGenerateTitle;
|
|
68
98
|
rename(threadIdOrRemoteId: string, newTitle: string): Promise<void>;
|
|
69
99
|
private _ensureThreadIsNotMain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,
|
|
1
|
+
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;AAIvD,KAAK,gBAAgB,GACjB;IACE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC3B,GACD;IACE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AAkGN,qBAAa,qCACX,SAAQ,gBACR,YAAW,qBAAqB;IAEhC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IAEnE,OAAO,CAAC,mBAAmB,CAA4B;IAEvD,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOpB;IAEI,qBAAqB;gBAmEhB,OAAO,EAAE,uBAAuB;IAe5C,OAAO,CAAC,WAAW,CAAC;IAEb,qBAAqB,CAAC,OAAO,EAAE,uBAAuB;IAatD,sBAAsB;IAO7B,IAAW,SAAS,sBAEnB;IAED,IAAW,iBAAiB,sBAE3B;IAED,IAAW,WAAW,uBAErB;IAED,IAAW,YAAY,IAAI,MAAM,CAEhC;IAEM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMxB,oBAAoB,CAAC,kBAAkB,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAS/C,WAAW,CAAC,kBAAkB,EAAE,MAAM;IAIhC,cAAc,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBzD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAqCxC,UAAU,aAAoB,MAAM,+DAiCzC;IAEF,OAAO,CAAC,gBAAgB,CA0BtB;IAEK,MAAM,CAAC,kBAAkB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YA2B5D,sBAAsB;IAYvB,OAAO,CAAC,kBAAkB,EAAE,MAAM;IAiBxC,SAAS,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB9C,MAAM,CAAC,kBAAkB,EAAE,MAAM;IAiB9C,OAAO,CAAC,WAAW,CAA8B;IAE1C,0BAA0B,EAAE,EAAE,CAoBnC;CACH"}
|
|
@@ -194,8 +194,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends import_BaseSubscribabl
|
|
|
194
194
|
}
|
|
195
195
|
__internal_bindAdapter() {
|
|
196
196
|
this.getLoadThreadsPromise();
|
|
197
|
-
return this._adapter.subscribe({
|
|
198
|
-
onInitialize: this._onInitialize,
|
|
197
|
+
return this._adapter.subscribe?.({
|
|
199
198
|
onGenerateTitle: this._onGenerateTitle
|
|
200
199
|
});
|
|
201
200
|
}
|
|
@@ -216,6 +215,13 @@ var RemoteThreadListThreadListRuntimeCore = class extends import_BaseSubscribabl
|
|
|
216
215
|
if (!result) return import_EMPTY_THREAD_CORE.EMPTY_THREAD_CORE;
|
|
217
216
|
return result;
|
|
218
217
|
}
|
|
218
|
+
getThreadRuntimeCore(threadIdOrRemoteId) {
|
|
219
|
+
const data = this.getItemById(threadIdOrRemoteId);
|
|
220
|
+
if (!data) throw new Error("Thread not found");
|
|
221
|
+
const result = this._hookManager.getThreadRuntimeCore(data.threadId);
|
|
222
|
+
if (!result) throw new Error("Thread not found");
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
219
225
|
getItemById(threadIdOrRemoteId) {
|
|
220
226
|
return getThreadData(this._state.value, threadIdOrRemoteId);
|
|
221
227
|
}
|
|
@@ -262,12 +268,12 @@ var RemoteThreadListThreadListRuntimeCore = class extends import_BaseSubscribabl
|
|
|
262
268
|
}
|
|
263
269
|
return this.switchToThread(threadId);
|
|
264
270
|
}
|
|
265
|
-
|
|
271
|
+
initialize = async (threadId) => {
|
|
266
272
|
if (this._state.value.newThreadId !== threadId)
|
|
267
273
|
throw new Error("The provided thread is already initialized");
|
|
268
|
-
|
|
274
|
+
return this._state.optimisticUpdate({
|
|
269
275
|
execute: () => {
|
|
270
|
-
return
|
|
276
|
+
return this._adapter.initialize(threadId);
|
|
271
277
|
},
|
|
272
278
|
optimistic: (state) => {
|
|
273
279
|
return updateStatusReducer(state, threadId, "regular");
|