@assistant-ui/core 0.2.12 → 0.2.14
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/adapters/thread-history.d.ts +3 -1
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js.map +1 -1
- package/dist/react/AssistantProvider.js +6 -1
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/RuntimeAdapter.d.ts +1 -1
- package/dist/react/RuntimeAdapter.d.ts.map +1 -1
- package/dist/react/RuntimeAdapter.js +16 -6
- package/dist/react/RuntimeAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.d.ts +1 -8
- package/dist/react/client/DataRenderers.d.ts.map +1 -1
- package/dist/react/client/DataRenderers.js +3 -2
- package/dist/react/client/DataRenderers.js.map +1 -1
- package/dist/react/client/Interactables.d.ts +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +4 -3
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts +2 -13
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +4 -3
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +3 -2
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +4 -4
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +28 -1
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +43 -9
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +3 -2
- package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +2 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +6 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +2 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/utils/groupParts.d.ts +13 -1
- package/dist/react/utils/groupParts.d.ts.map +1 -1
- package/dist/react/utils/groupParts.js +17 -5
- package/dist/react/utils/groupParts.js.map +1 -1
- package/dist/runtime/api/bindings.d.ts +1 -0
- package/dist/runtime/api/bindings.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +2 -0
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -0
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +1 -0
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +3 -0
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +4 -0
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/branch/external-thread-branch-adapter.d.ts +30 -0
- package/dist/runtime/branch/external-thread-branch-adapter.d.ts.map +1 -0
- package/dist/runtime/branch/external-thread-branch-adapter.js +0 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +1 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +2 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +13 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-runtime-options.d.ts +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +8 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +63 -5
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/should-continue.js +4 -2
- package/dist/runtimes/local/should-continue.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +2 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +4 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +4 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js +1 -0
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts +2 -7
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +3 -2
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/model-context-client.d.ts +1 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.js +3 -2
- package/dist/store/clients/model-context-client.js.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts +2 -4
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.js +3 -2
- package/dist/store/clients/no-op-composer-client.js.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts +1 -3
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.js +2 -15
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts +1 -4
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +6 -4
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.d.ts +1 -1
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +14 -10
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/internal.d.ts +2 -2
- package/dist/store/internal.js +2 -2
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.js +3 -2
- package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts +2 -10
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +9 -6
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.js +3 -2
- package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +2 -7
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +10 -6
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +3 -2
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +2 -5
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +6 -4
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +7 -4
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scopes/message.d.ts +1 -0
- package/dist/store/scopes/message.d.ts.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +1 -0
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +1 -0
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/adapters/thread-history.ts +2 -0
- package/src/index.ts +1 -0
- package/src/react/AssistantProvider.tsx +3 -1
- package/src/react/RuntimeAdapter.ts +25 -8
- package/src/react/client/DataRenderers.ts +42 -45
- package/src/react/client/Interactables.ts +261 -261
- package/src/react/client/Tools.ts +6 -4
- package/src/react/primitives/message/MessageGroupedParts.tsx +19 -7
- package/src/react/primitives/message/MessageParts.tsx +64 -13
- package/src/react/providers/TextMessagePartProvider.tsx +5 -3
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +1 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +11 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +6 -0
- package/src/react/utils/groupParts.ts +27 -0
- package/src/runtime/api/bindings.ts +1 -0
- package/src/runtime/api/message-runtime.ts +7 -0
- package/src/runtime/api/thread-list-runtime.ts +1 -0
- package/src/runtime/api/thread-runtime.ts +7 -0
- package/src/runtime/base/base-thread-runtime-core.ts +1 -0
- package/src/runtime/branch/external-thread-branch-adapter.ts +26 -0
- package/src/runtime/interfaces/thread-list-runtime-core.ts +1 -0
- package/src/runtime/interfaces/thread-runtime-core.ts +2 -0
- package/src/runtimes/external-store/external-store-adapter.ts +1 -0
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +24 -0
- package/src/runtimes/local/local-runtime-options.ts +1 -1
- package/src/runtimes/local/local-thread-runtime-core.test.ts +311 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +104 -7
- package/src/runtimes/local/should-continue.ts +23 -13
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +5 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +5 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +2 -0
- package/src/runtimes/remote-thread-list/types.ts +1 -0
- package/src/store/clients/chain-of-thought-client.ts +5 -3
- package/src/store/clients/model-context-client.test.ts +5 -4
- package/src/store/clients/model-context-client.ts +21 -21
- package/src/store/clients/no-op-composer-client.ts +5 -3
- package/src/store/clients/runtime-adapter.ts +0 -24
- package/src/store/clients/suggestions.ts +9 -18
- package/src/store/clients/thread-message-client.ts +29 -26
- package/src/store/internal.ts +1 -4
- package/src/store/runtime-clients/attachment-runtime-client.ts +14 -14
- package/src/store/runtime-clients/composer-runtime-client.ts +30 -24
- package/src/store/runtime-clients/message-part-runtime-client.ts +5 -3
- package/src/store/runtime-clients/message-runtime-client.ts +26 -19
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +5 -3
- package/src/store/runtime-clients/thread-list-runtime-client.ts +10 -6
- package/src/store/runtime-clients/thread-runtime-client.ts +11 -6
- package/src/store/scopes/message.ts +1 -0
- package/src/store/scopes/thread-list-item.ts +1 -0
- package/src/store/scopes/thread.ts +1 -0
- package/src/tests/external-store-thread-runtime-core.test.ts +57 -0
- package/src/tests/groupMessageParts.test.ts +84 -0
- package/src/tests/groupParts.test.ts +55 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-store-thread-runtime-core.js","names":[],"sources":["../../../src/runtimes/external-store/external-store-thread-runtime-core.ts"],"sourcesContent":["import type { AppendMessage, ThreadMessage } from \"../../types/message\";\nimport type {\n AddToolResultOptions,\n ResumeRunConfig,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n StartRunConfig,\n ThreadSuggestion,\n} from \"../../runtime/interfaces/thread-runtime-core\";\n\nimport type { ExternalStoreAdapter } from \"./external-store-adapter\";\nimport {\n getExternalStoreMessages,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport { ThreadMessageConverter } from \"./thread-message-converter\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport type {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseThreadRuntimeCore } from \"../../runtime/base/base-thread-runtime-core\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport {\n ExportedMessageRepository,\n MessageRepository,\n} from \"../../runtime/utils/message-repository\";\nimport { generateId } from \"../../utils/id\";\nimport { ToolInvocationTracker } from \"../tool-invocations/ToolInvocationTracker\";\nimport { EMPTY_QUEUE_ITEMS } from \"../../store/scopes/queue-item\";\n\nconst EMPTY_ARRAY: readonly ThreadSuggestion[] = Object.freeze([]);\n\nconst shallowEqual = (a: object, b: object): boolean => {\n const aKeys = Object.keys(a);\n if (aKeys.length !== Object.keys(b).length) return false;\n for (const key of aKeys) {\n if ((a as any)[key] !== (b as any)[key]) return false;\n }\n return true;\n};\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: readonly ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n private _messages!: readonly ThreadMessage[];\n public isDisabled!: boolean;\n public isSendDisabled!: boolean;\n public get isLoading() {\n return this._store.isLoading ?? false;\n }\n // Unlike `isLoading`: pass `undefined` through to preserve the `getThreadState` fallback.\n public get isRunning(): boolean | undefined {\n return this._store.isRunning;\n }\n\n protected override _getBaseMessages(): readonly ThreadMessage[] {\n return this._messages;\n }\n\n public override get state() {\n return this._store.state ?? super.state;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n /**\n * Client-side tool-invocations pipeline. Constructed lazily on first\n * snapshot — only when `adapter.unstable_enableToolInvocations === true`.\n */\n private _toolInvocations: ToolInvocationTracker | null = null;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n store: ExternalStoreAdapter<any>,\n ) {\n super(contextProvider);\n this.__internal_setAdapter(store);\n }\n\n public __internal_setAdapter(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n this.isSendDisabled = store.isSendDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n if (this.extras !== store.extras) {\n this.extras = store.extras;\n }\n\n const newSuggestions = store.suggestions ?? EMPTY_ARRAY;\n if (!shallowEqual(this.suggestions, newSuggestions)) {\n this.suggestions = newSuggestions;\n }\n\n const newCapabilities: RuntimeCapabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n switchBranchDuringRun: false,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n dictation: this._store.adapters?.dictation !== undefined,\n voice: this._store.adapters?.voice !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false,\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n queue: this._store.queue !== undefined,\n };\n if (!shallowEqual(this._capabilities, newCapabilities)) {\n this._capabilities = newCapabilities;\n }\n\n let messages: readonly ThreadMessage[];\n\n if (store.messageRepository) {\n // Handle messageRepository\n if (\n oldStore &&\n oldStore.isRunning === store.isRunning &&\n oldStore.messageRepository === store.messageRepository\n ) {\n this._notifySubscribers();\n return;\n }\n\n this.repository.clear();\n this.repository.import(store.messageRepository);\n\n messages = this.repository.getMessages();\n } else if (store.messages) {\n // Handle messages array\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === (store.messages?.length ?? 0) - 1;\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n false,\n false,\n undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const messageLike = store.convertMessage(m, idx);\n const newMessage = fromThreadMessageLike(\n messageLike,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, m);\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n } else {\n throw new Error(\n \"ExternalStoreAdapter must provide either 'messages' or 'messageRepository'\",\n );\n }\n\n // Common logic for both paths\n if (messages.length > 0) this.ensureInitialized();\n\n if ((oldStore?.isRunning ?? false) !== (store.isRunning ?? false)) {\n if (store.isRunning) {\n this._notifyEventSubscribers(\"runStart\", {});\n } else {\n this._notifyEventSubscribers(\"runEnd\", {});\n }\n }\n\n // Append an optimistic placeholder while running but before a trailing\n // assistant message exists. resetHead evicts off-branch optimistic messages\n // (prior placeholders, mid-run id-swap siblings); export() never persists them.\n let optimisticId: string | null = null;\n if (hasUpcomingMessage(isRunning, messages)) {\n optimisticId = generateId();\n this.repository.addOrUpdateMessage(\n messages.at(-1)?.id ?? null,\n fromThreadMessageLike(\n { role: \"assistant\", content: [], metadata: { isOptimistic: true } },\n optimisticId,\n { type: \"running\" },\n ),\n );\n }\n\n this.repository.resetHead(optimisticId ?? messages.at(-1)?.id ?? null);\n\n this._messages = this.repository.getMessages();\n\n this._driveToolInvocations();\n\n this._notifySubscribers();\n }\n\n /**\n * Feed the current message snapshot into the tool-invocations tracker.\n * Opt-in via `adapter.unstable_enableToolInvocations: true`. The tracker\n * itself is fail-silent — see ToolInvocationTracker for the\n * state-transition contract.\n */\n private _driveToolInvocations(): void {\n if (!this._store.unstable_enableToolInvocations) {\n // Adapter did not opt in (default). If a tracker was previously\n // constructed (e.g. the adapter just toggled the flag off via a\n // dynamic swap), drop it so subsequent snapshots are no-ops.\n if (this._toolInvocations) {\n this._toolInvocations.reset();\n this._toolInvocations = null;\n this._store.setToolStatuses?.({});\n }\n return;\n }\n\n if (!this._toolInvocations) {\n this._toolInvocations = new ToolInvocationTracker(\n () => this.getModelContext().tools,\n {\n onResult: (command) => {\n try {\n const messageId = this._findMessageIdForToolCall(\n command.toolCallId,\n );\n if (messageId === undefined) {\n // The tool call no longer exists in the snapshot (e.g.\n // rolled back). Drop the result.\n return;\n }\n this._store.onAddToolResult?.({\n messageId,\n toolCallId: command.toolCallId,\n toolName: command.toolName,\n result: command.result,\n isError: command.isError,\n ...(command.artifact !== undefined && {\n artifact: command.artifact,\n }),\n ...(command.modelContent !== undefined && {\n modelContent: command.modelContent,\n }),\n });\n } catch (err) {\n console.error(\n \"[ExternalStoreThreadRuntimeCore] onAddToolResult dispatch failed\",\n err,\n );\n }\n },\n onStatusesChange: (statuses) => {\n this._store.setToolStatuses?.(Object.fromEntries(statuses));\n },\n },\n );\n }\n\n this._toolInvocations.setState({\n messages: this._messages,\n isRunning: this._store.isRunning ?? false,\n ...(this._store.isLoading !== undefined && {\n isLoading: this._store.isLoading,\n }),\n });\n }\n\n /**\n * Lookup table from `toolCallId` to the owning assistant message's `id`,\n * rebuilt lazily when `_messages` changes (see `_messagesForToolCallIndex`).\n */\n private _toolCallToMessageId = new Map<string, string>();\n private _messagesForToolCallIndex: readonly ThreadMessage[] | null = null;\n\n /**\n * Look up the assistant message that owns a tool-call part. Lazily builds\n * (and caches) a `toolCallId → messageId` map keyed off the current\n * `_messages` reference, so onResult dispatches stay O(1) instead of\n * walking the full thread on every result.\n */\n private _findMessageIdForToolCall(toolCallId: string): string | undefined {\n if (this._messagesForToolCallIndex !== this._messages) {\n this._toolCallToMessageId.clear();\n const visit = (messages: readonly ThreadMessage[]): void => {\n for (const message of messages) {\n if (!Array.isArray(message.content)) continue;\n for (const part of message.content) {\n if (!part || part.type !== \"tool-call\") continue;\n this._toolCallToMessageId.set(part.toolCallId, message.id);\n if (part.messages) visit(part.messages);\n }\n }\n };\n visit(this._messages);\n this._messagesForToolCallIndex = this._messages;\n }\n return this._toolCallToMessageId.get(toolCallId);\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n // Silently ignore branch switches while running\n if (this._store.isRunning) {\n return;\n }\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n const isEdit = message.parentId !== (this.messages.at(-1)?.id ?? null);\n\n // Buffering does not start a run, so the tool-abort below must wait until\n // the queue flushes. By then the prior run (and its tools) has settled.\n if (!isEdit && this._store.queue) {\n this._store.queue.enqueue(message, { steer: message.steer ?? false });\n return;\n }\n\n // Auto-abort in-flight client-side tool executions when a new run is\n // about to start. Without this, a tool that finishes after the new turn\n // begins would feed a stale result into `onAddToolResult`, racing with\n // the new turn the user just initiated. `startRun` defaults to true for\n // user messages — matches the satellites' historical opt-in cancel\n // behavior, which is now built in.\n if (message.startRun ?? message.role === \"user\") {\n await this._toolInvocations?.abort();\n }\n\n if (isEdit) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n this._store.queue?.clear(\"edit\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public getQueueItems() {\n // The composer reads this during base-thread construction, before the\n // constructor assigns `_store`, so guard against the unset field.\n return this._store?.queue?.items ?? EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(queueItemId: string) {\n this._store?.queue?.steer(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string) {\n this._store?.queue?.remove(queueItemId);\n }\n\n public async startRun(config: StartRunConfig): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n this._store.queue?.clear(\"reload\");\n\n // Auto-abort in-flight client-side tool executions when a run reloads;\n // any results that land afterward would target a turn that no longer\n // exists. See `append` above for full rationale.\n await this._toolInvocations?.abort();\n\n await this._store.onReload(config.parentId, config);\n }\n\n public async resumeRun(config: ResumeRunConfig): Promise<void> {\n if (!this._store.onResume)\n throw new Error(\"Runtime does not support resuming runs.\");\n\n await this._store.onResume(config);\n }\n\n public exportExternalState(): any {\n if (!this._store.onExportExternalState)\n throw new Error(\"Runtime does not support exporting external states.\");\n\n return this._store.onExportExternalState();\n }\n\n public importExternalState(state: any): void {\n if (!this._store.onLoadExternalState)\n throw new Error(\"Runtime does not support importing external states.\");\n\n // Re-arm the tracker so the next adapter snapshot (containing the\n // imported state) is treated as historical — no streamCall/execute\n // fires for the loaded tool calls. The adapter is expected to update\n // its messages in response to onLoadExternalState; that update flows\n // back here via __internal_setAdapter. We only clear adapter-side\n // tool statuses when the tracker is the source of truth — otherwise\n // we'd wipe statuses the adapter is managing on its own.\n if (this._toolInvocations) {\n this._toolInvocations.reset();\n this._store.setToolStatuses?.({});\n }\n\n this._store.onLoadExternalState(state);\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.queue?.clear(\"cancel-run\");\n\n // Abort any in-flight client-side tool executions. Fire-and-forget —\n // the abort resolves once executions settle, but we don't gate the\n // cancel on it.\n void this._toolInvocations?.abort();\n\n this._store.onCancel();\n\n // Drop an empty optimistic head (placeholder or pre-stream message); a\n // partially-streamed one is kept and re-supplied by the store on resync.\n const head = this.repository.getMessages().at(-1);\n if (head && head.metadata.isOptimistic && head.content.length === 0) {\n this.repository.deleteMessage(head.id);\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult?.(options);\n }\n\n public resumeToolCall(options: ResumeToolCallOptions) {\n // Tracker owns its own human-input handlers — let it resume in-process\n // tool calls without round-tripping through the adapter. Falls back to\n // the adapter's onResumeToolCall (if any) for tool calls the tracker\n // doesn't know about.\n const handled =\n this._toolInvocations?.resume(options.toolCallId, options.payload) ??\n false;\n if (handled) return;\n\n if (this._store.onResumeToolCall) {\n this._store.onResumeToolCall(options);\n return;\n }\n\n throw new Error(\n `Tool call ${options.toolCallId} is not waiting for resume.`,\n );\n }\n\n public respondToToolApproval(options: RespondToToolApprovalOptions) {\n if (!this._store.onRespondToToolApproval)\n throw new Error(\"Runtime does not support tool approvals.\");\n this._store.onRespondToToolApproval(options);\n }\n\n public override reset(initialMessages?: readonly ThreadMessageLike[]) {\n const repo = new MessageRepository();\n repo.import(ExportedMessageRepository.fromArray(initialMessages ?? []));\n this.updateMessages(repo.getMessages());\n }\n\n public override import(data: ExportedMessageRepository) {\n super.import(data);\n\n if (this._store.onImport) {\n this._store.onImport(this.repository.getMessages());\n }\n }\n\n private updateMessages = (messages: readonly ThreadMessage[]) => {\n const hasConverter = this._store.convertMessage !== undefined;\n if (hasConverter) {\n this._store.setMessages?.(messages.flatMap(getExternalStoreMessages));\n } else {\n // TODO mark this as readonly in v0.12.0\n this._store.setMessages?.(messages as ThreadMessage[]);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;AAoCA,MAAM,cAA2C,OAAO,OAAO,CAA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f,KAAK,eAAe,QAAQ;EAC9B,GAAG,CAAC;CACN;CAEA,cAAqB,SAA+B;EAClD,IAAI,CAAC,KAAK,OAAO,iBACf,MAAM,IAAI,MAAM,wCAAwC;EAC1D,KAAK,OAAO,kBAAkB,OAAO;CACvC;CAEA,eAAsB,SAAgC;EAQpD,IAFE,KAAK,kBAAkB,OAAO,QAAQ,YAAY,QAAQ,OAAO,KACjE,OACW;EAEb,IAAI,KAAK,OAAO,kBAAkB;GAChC,KAAK,OAAO,iBAAiB,OAAO;GACpC;EACF;EAEA,MAAM,IAAI,MACR,aAAa,QAAQ,WAAW,4BAClC;CACF;CAEA,sBAA6B,SAAuC;EAClE,IAAI,CAAC,KAAK,OAAO,yBACf,MAAM,IAAI,MAAM,0CAA0C;EAC5D,KAAK,OAAO,wBAAwB,OAAO;CAC7C;CAEA,MAAsB,iBAAgD;EACpE,MAAM,OAAO,IAAI,kBAAkB;EACnC,KAAK,OAAO,0BAA0B,UAAU,mBAAmB,CAAC,CAAC,CAAC;EACtE,KAAK,eAAe,KAAK,YAAY,CAAC;CACxC;CAEA,OAAuB,MAAiC;EACtD,MAAM,OAAO,IAAI;EAEjB,IAAI,KAAK,OAAO,UACd,KAAK,OAAO,SAAS,KAAK,WAAW,YAAY,CAAC;CAEtD;CAEA,kBAA0B,aAAuC;EAE/D,IADqB,KAAK,OAAO,mBAAmB,KAAA,GAElD,KAAK,OAAO,cAAc,SAAS,QAAQ,wBAAwB,CAAC;OAGpE,KAAK,OAAO,cAAc,QAA2B;CAEzD;AACF"}
|
|
1
|
+
{"version":3,"file":"external-store-thread-runtime-core.js","names":[],"sources":["../../../src/runtimes/external-store/external-store-thread-runtime-core.ts"],"sourcesContent":["import type { AppendMessage, ThreadMessage } from \"../../types/message\";\nimport type {\n AddToolResultOptions,\n ResumeRunConfig,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n StartRunConfig,\n ThreadSuggestion,\n} from \"../../runtime/interfaces/thread-runtime-core\";\n\nimport type { ExternalStoreAdapter } from \"./external-store-adapter\";\nimport {\n getExternalStoreMessages,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport { ThreadMessageConverter } from \"./thread-message-converter\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport type {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseThreadRuntimeCore } from \"../../runtime/base/base-thread-runtime-core\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport {\n ExportedMessageRepository,\n MessageRepository,\n} from \"../../runtime/utils/message-repository\";\nimport { generateId } from \"../../utils/id\";\nimport { ToolInvocationTracker } from \"../tool-invocations/ToolInvocationTracker\";\nimport { EMPTY_QUEUE_ITEMS } from \"../../store/scopes/queue-item\";\n\nconst EMPTY_ARRAY: readonly ThreadSuggestion[] = Object.freeze([]);\n\nconst shallowEqual = (a: object, b: object): boolean => {\n const aKeys = Object.keys(a);\n if (aKeys.length !== Object.keys(b).length) return false;\n for (const key of aKeys) {\n if ((a as any)[key] !== (b as any)[key]) return false;\n }\n return true;\n};\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: readonly ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n delete: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n private _messages!: readonly ThreadMessage[];\n public isDisabled!: boolean;\n public isSendDisabled!: boolean;\n public get isLoading() {\n return this._store.isLoading ?? false;\n }\n // Unlike `isLoading`: pass `undefined` through to preserve the `getThreadState` fallback.\n public get isRunning(): boolean | undefined {\n return this._store.isRunning;\n }\n\n protected override _getBaseMessages(): readonly ThreadMessage[] {\n return this._messages;\n }\n\n public override get state() {\n return this._store.state ?? super.state;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n /**\n * Client-side tool-invocations pipeline. Constructed lazily on first\n * snapshot — only when `adapter.unstable_enableToolInvocations === true`.\n */\n private _toolInvocations: ToolInvocationTracker | null = null;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n store: ExternalStoreAdapter<any>,\n ) {\n super(contextProvider);\n this.__internal_setAdapter(store);\n }\n\n public __internal_setAdapter(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n this.isSendDisabled = store.isSendDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n if (this.extras !== store.extras) {\n this.extras = store.extras;\n }\n\n const newSuggestions = store.suggestions ?? EMPTY_ARRAY;\n if (!shallowEqual(this.suggestions, newSuggestions)) {\n this.suggestions = newSuggestions;\n }\n\n const newCapabilities: RuntimeCapabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n switchBranchDuringRun: false,\n edit: this._store.onEdit !== undefined,\n delete:\n this._store.onDelete !== undefined ||\n this._store.setMessages !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n dictation: this._store.adapters?.dictation !== undefined,\n voice: this._store.adapters?.voice !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false,\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n queue: this._store.queue !== undefined,\n };\n if (!shallowEqual(this._capabilities, newCapabilities)) {\n this._capabilities = newCapabilities;\n }\n\n let messages: readonly ThreadMessage[];\n\n if (store.messageRepository) {\n // Handle messageRepository\n if (\n oldStore &&\n oldStore.isRunning === store.isRunning &&\n oldStore.messageRepository === store.messageRepository\n ) {\n this._notifySubscribers();\n return;\n }\n\n this.repository.clear();\n this.repository.import(store.messageRepository);\n\n messages = this.repository.getMessages();\n } else if (store.messages) {\n // Handle messages array\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === (store.messages?.length ?? 0) - 1;\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n false,\n false,\n undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const messageLike = store.convertMessage(m, idx);\n const newMessage = fromThreadMessageLike(\n messageLike,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, m);\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n } else {\n throw new Error(\n \"ExternalStoreAdapter must provide either 'messages' or 'messageRepository'\",\n );\n }\n\n // Common logic for both paths\n if (messages.length > 0) this.ensureInitialized();\n\n if ((oldStore?.isRunning ?? false) !== (store.isRunning ?? false)) {\n if (store.isRunning) {\n this._notifyEventSubscribers(\"runStart\", {});\n } else {\n this._notifyEventSubscribers(\"runEnd\", {});\n }\n }\n\n // Append an optimistic placeholder while running but before a trailing\n // assistant message exists. resetHead evicts off-branch optimistic messages\n // (prior placeholders, mid-run id-swap siblings); export() never persists them.\n let optimisticId: string | null = null;\n if (hasUpcomingMessage(isRunning, messages)) {\n optimisticId = generateId();\n this.repository.addOrUpdateMessage(\n messages.at(-1)?.id ?? null,\n fromThreadMessageLike(\n { role: \"assistant\", content: [], metadata: { isOptimistic: true } },\n optimisticId,\n { type: \"running\" },\n ),\n );\n }\n\n this.repository.resetHead(optimisticId ?? messages.at(-1)?.id ?? null);\n\n this._messages = this.repository.getMessages();\n\n this._driveToolInvocations();\n\n this._notifySubscribers();\n }\n\n /**\n * Feed the current message snapshot into the tool-invocations tracker.\n * Opt-in via `adapter.unstable_enableToolInvocations: true`. The tracker\n * itself is fail-silent — see ToolInvocationTracker for the\n * state-transition contract.\n */\n private _driveToolInvocations(): void {\n if (!this._store.unstable_enableToolInvocations) {\n // Adapter did not opt in (default). If a tracker was previously\n // constructed (e.g. the adapter just toggled the flag off via a\n // dynamic swap), drop it so subsequent snapshots are no-ops.\n if (this._toolInvocations) {\n this._toolInvocations.reset();\n this._toolInvocations = null;\n this._store.setToolStatuses?.({});\n }\n return;\n }\n\n if (!this._toolInvocations) {\n this._toolInvocations = new ToolInvocationTracker(\n () => this.getModelContext().tools,\n {\n onResult: (command) => {\n try {\n const messageId = this._findMessageIdForToolCall(\n command.toolCallId,\n );\n if (messageId === undefined) {\n // The tool call no longer exists in the snapshot (e.g.\n // rolled back). Drop the result.\n return;\n }\n this._store.onAddToolResult?.({\n messageId,\n toolCallId: command.toolCallId,\n toolName: command.toolName,\n result: command.result,\n isError: command.isError,\n ...(command.artifact !== undefined && {\n artifact: command.artifact,\n }),\n ...(command.modelContent !== undefined && {\n modelContent: command.modelContent,\n }),\n });\n } catch (err) {\n console.error(\n \"[ExternalStoreThreadRuntimeCore] onAddToolResult dispatch failed\",\n err,\n );\n }\n },\n onStatusesChange: (statuses) => {\n this._store.setToolStatuses?.(Object.fromEntries(statuses));\n },\n },\n );\n }\n\n this._toolInvocations.setState({\n messages: this._messages,\n isRunning: this._store.isRunning ?? false,\n ...(this._store.isLoading !== undefined && {\n isLoading: this._store.isLoading,\n }),\n });\n }\n\n /**\n * Lookup table from `toolCallId` to the owning assistant message's `id`,\n * rebuilt lazily when `_messages` changes (see `_messagesForToolCallIndex`).\n */\n private _toolCallToMessageId = new Map<string, string>();\n private _messagesForToolCallIndex: readonly ThreadMessage[] | null = null;\n\n /**\n * Look up the assistant message that owns a tool-call part. Lazily builds\n * (and caches) a `toolCallId → messageId` map keyed off the current\n * `_messages` reference, so onResult dispatches stay O(1) instead of\n * walking the full thread on every result.\n */\n private _findMessageIdForToolCall(toolCallId: string): string | undefined {\n if (this._messagesForToolCallIndex !== this._messages) {\n this._toolCallToMessageId.clear();\n const visit = (messages: readonly ThreadMessage[]): void => {\n for (const message of messages) {\n if (!Array.isArray(message.content)) continue;\n for (const part of message.content) {\n if (!part || part.type !== \"tool-call\") continue;\n this._toolCallToMessageId.set(part.toolCallId, message.id);\n if (part.messages) visit(part.messages);\n }\n }\n };\n visit(this._messages);\n this._messagesForToolCallIndex = this._messages;\n }\n return this._toolCallToMessageId.get(toolCallId);\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n // Silently ignore branch switches while running\n if (this._store.isRunning) {\n return;\n }\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n const isEdit = message.parentId !== (this.messages.at(-1)?.id ?? null);\n\n // Buffering does not start a run, so the tool-abort below must wait until\n // the queue flushes. By then the prior run (and its tools) has settled.\n if (!isEdit && this._store.queue) {\n this._store.queue.enqueue(message, { steer: message.steer ?? false });\n return;\n }\n\n // Auto-abort in-flight client-side tool executions when a new run is\n // about to start. Without this, a tool that finishes after the new turn\n // begins would feed a stale result into `onAddToolResult`, racing with\n // the new turn the user just initiated. `startRun` defaults to true for\n // user messages — matches the satellites' historical opt-in cancel\n // behavior, which is now built in.\n if (message.startRun ?? message.role === \"user\") {\n await this._toolInvocations?.abort();\n }\n\n if (isEdit) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n this._store.queue?.clear(\"edit\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async deleteMessage(messageId: string): Promise<void> {\n if (this._store.onDelete) {\n await this._store.onDelete(messageId);\n return;\n }\n\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support deleting messages.\");\n\n if (this._store.isRunning) {\n await this._toolInvocations?.abort();\n }\n\n const messages = this.repository.getMessages();\n const messageIndex = messages.findIndex((m) => m.id === messageId);\n if (messageIndex === -1) throw new Error(\"Message not found.\");\n\n this.updateMessages(messages.filter((message) => message.id !== messageId));\n }\n\n public getQueueItems() {\n // The composer reads this during base-thread construction, before the\n // constructor assigns `_store`, so guard against the unset field.\n return this._store?.queue?.items ?? EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(queueItemId: string) {\n this._store?.queue?.steer(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string) {\n this._store?.queue?.remove(queueItemId);\n }\n\n public async startRun(config: StartRunConfig): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n this._store.queue?.clear(\"reload\");\n\n // Auto-abort in-flight client-side tool executions when a run reloads;\n // any results that land afterward would target a turn that no longer\n // exists. See `append` above for full rationale.\n await this._toolInvocations?.abort();\n\n await this._store.onReload(config.parentId, config);\n }\n\n public async resumeRun(config: ResumeRunConfig): Promise<void> {\n if (!this._store.onResume)\n throw new Error(\"Runtime does not support resuming runs.\");\n\n await this._store.onResume(config);\n }\n\n public exportExternalState(): any {\n if (!this._store.onExportExternalState)\n throw new Error(\"Runtime does not support exporting external states.\");\n\n return this._store.onExportExternalState();\n }\n\n public importExternalState(state: any): void {\n if (!this._store.onLoadExternalState)\n throw new Error(\"Runtime does not support importing external states.\");\n\n // Re-arm the tracker so the next adapter snapshot (containing the\n // imported state) is treated as historical — no streamCall/execute\n // fires for the loaded tool calls. The adapter is expected to update\n // its messages in response to onLoadExternalState; that update flows\n // back here via __internal_setAdapter. We only clear adapter-side\n // tool statuses when the tracker is the source of truth — otherwise\n // we'd wipe statuses the adapter is managing on its own.\n if (this._toolInvocations) {\n this._toolInvocations.reset();\n this._store.setToolStatuses?.({});\n }\n\n this._store.onLoadExternalState(state);\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.queue?.clear(\"cancel-run\");\n\n // Abort any in-flight client-side tool executions. Fire-and-forget —\n // the abort resolves once executions settle, but we don't gate the\n // cancel on it.\n void this._toolInvocations?.abort();\n\n this._store.onCancel();\n\n // Drop an empty optimistic head (placeholder or pre-stream message); a\n // partially-streamed one is kept and re-supplied by the store on resync.\n const head = this.repository.getMessages().at(-1);\n if (head && head.metadata.isOptimistic && head.content.length === 0) {\n this.repository.deleteMessage(head.id);\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult?.(options);\n }\n\n public resumeToolCall(options: ResumeToolCallOptions) {\n // Tracker owns its own human-input handlers — let it resume in-process\n // tool calls without round-tripping through the adapter. Falls back to\n // the adapter's onResumeToolCall (if any) for tool calls the tracker\n // doesn't know about.\n const handled =\n this._toolInvocations?.resume(options.toolCallId, options.payload) ??\n false;\n if (handled) return;\n\n if (this._store.onResumeToolCall) {\n this._store.onResumeToolCall(options);\n return;\n }\n\n throw new Error(\n `Tool call ${options.toolCallId} is not waiting for resume.`,\n );\n }\n\n public respondToToolApproval(options: RespondToToolApprovalOptions) {\n if (!this._store.onRespondToToolApproval)\n throw new Error(\"Runtime does not support tool approvals.\");\n this._store.onRespondToToolApproval(options);\n }\n\n public override reset(initialMessages?: readonly ThreadMessageLike[]) {\n const repo = new MessageRepository();\n repo.import(ExportedMessageRepository.fromArray(initialMessages ?? []));\n this.updateMessages(repo.getMessages());\n }\n\n public override import(data: ExportedMessageRepository) {\n super.import(data);\n\n if (this._store.onImport) {\n this._store.onImport(this.repository.getMessages());\n }\n }\n\n private updateMessages = (messages: readonly ThreadMessage[]) => {\n const hasConverter = this._store.convertMessage !== undefined;\n if (hasConverter) {\n this._store.setMessages?.(messages.flatMap(getExternalStoreMessages));\n } else {\n // TODO mark this as readonly in v0.12.0\n this._store.setMessages?.(messages as ThreadMessage[]);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;AAoCA,MAAM,cAA2C,OAAO,OAAO,CAAC,CAAC;AAEjE,MAAM,gBAAgB,GAAW,MAAuB;CACtD,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,IAAI,MAAM,WAAW,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,OAAO;CACnD,KAAK,MAAM,OAAO,OAChB,IAAK,EAAU,SAAU,EAAU,MAAM,OAAO;CAElD,OAAO;AACT;AAEA,MAAa,sBACX,WACA,aACG;CACH,OAAO,aAAa,SAAS,SAAS,SAAS,EAAE,EAAE,SAAS;AAC9D;AAEA,IAAa,iCAAb,cACU,sBAEV;CACE,gBAA6C;EAC3C,gBAAgB;EAChB,uBAAuB;EACvB,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,eAAe;EACf,QAAQ;EACR,WA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BAAmB;EAI1B,iBAAiB;GACf,KAAK,eAAe,QAAQ;EAC9B,GAAG,CAAC;CACN;CAEA,cAAqB,SAA+B;EAClD,IAAI,CAAC,KAAK,OAAO,iBACf,MAAM,IAAI,MAAM,wCAAwC;EAC1D,KAAK,OAAO,kBAAkB,OAAO;CACvC;CAEA,eAAsB,SAAgC;EAQpD,IAFE,KAAK,kBAAkB,OAAO,QAAQ,YAAY,QAAQ,OAAO,KACjE,OACW;EAEb,IAAI,KAAK,OAAO,kBAAkB;GAChC,KAAK,OAAO,iBAAiB,OAAO;GACpC;EACF;EAEA,MAAM,IAAI,MACR,aAAa,QAAQ,WAAW,4BAClC;CACF;CAEA,sBAA6B,SAAuC;EAClE,IAAI,CAAC,KAAK,OAAO,yBACf,MAAM,IAAI,MAAM,0CAA0C;EAC5D,KAAK,OAAO,wBAAwB,OAAO;CAC7C;CAEA,MAAsB,iBAAgD;EACpE,MAAM,OAAO,IAAI,kBAAkB;EACnC,KAAK,OAAO,0BAA0B,UAAU,mBAAmB,CAAC,CAAC,CAAC;EACtE,KAAK,eAAe,KAAK,YAAY,CAAC;CACxC;CAEA,OAAuB,MAAiC;EACtD,MAAM,OAAO,IAAI;EAEjB,IAAI,KAAK,OAAO,UACd,KAAK,OAAO,SAAS,KAAK,WAAW,YAAY,CAAC;CAEtD;CAEA,kBAA0B,aAAuC;EAE/D,IADqB,KAAK,OAAO,mBAAmB,KAAA,GAElD,KAAK,OAAO,cAAc,SAAS,QAAQ,wBAAwB,CAAC;OAGpE,KAAK,OAAO,cAAc,QAA2B;CAEzD;AACF"}
|
|
@@ -20,7 +20,7 @@ type LocalRuntimeOptionsBase = {
|
|
|
20
20
|
suggestion?: SuggestionAdapter | undefined;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* Names of tools that
|
|
23
|
+
* Names of tools that pause the run until a result is supplied via `addToolResult`.
|
|
24
24
|
*/
|
|
25
25
|
unstable_humanToolNames?: string[] | undefined;
|
|
26
26
|
/**
|
|
@@ -17,6 +17,7 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
|
|
|
17
17
|
switchToBranch: boolean;
|
|
18
18
|
switchBranchDuringRun: boolean;
|
|
19
19
|
edit: boolean;
|
|
20
|
+
delete: boolean;
|
|
20
21
|
reload: boolean;
|
|
21
22
|
cancel: boolean;
|
|
22
23
|
unstable_copy: boolean;
|
|
@@ -63,6 +64,7 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
|
|
|
63
64
|
steerQueueItem(queueItemId: string): void;
|
|
64
65
|
removeQueueItem(queueItemId: string): void;
|
|
65
66
|
private _runAppend;
|
|
67
|
+
deleteMessage(messageId: string): Promise<void>;
|
|
66
68
|
resumeRun({
|
|
67
69
|
stream,
|
|
68
70
|
...startConfig
|
|
@@ -73,6 +75,7 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
|
|
|
73
75
|
parentId,
|
|
74
76
|
runConfig
|
|
75
77
|
}: StartRunConfig, runCallback?: ChatModelAdapter["run"]): Promise<void>;
|
|
78
|
+
private _runLoop;
|
|
76
79
|
private performRoundtrip;
|
|
77
80
|
detach(): void;
|
|
78
81
|
cancelRun(): void;
|
|
@@ -84,7 +87,11 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
|
|
|
84
87
|
artifact
|
|
85
88
|
}: AddToolResultOptions): void;
|
|
86
89
|
resumeToolCall(_options: ResumeToolCallOptions): void;
|
|
87
|
-
respondToToolApproval(
|
|
90
|
+
respondToToolApproval({
|
|
91
|
+
approvalId,
|
|
92
|
+
approved,
|
|
93
|
+
reason
|
|
94
|
+
}: RespondToToolApprovalOptions): void;
|
|
88
95
|
}
|
|
89
96
|
//#endregion
|
|
90
97
|
export { LocalThreadRuntimeCore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtimes/local/local-thread-runtime-core.ts"],"mappings":";;;;;;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IACA,OAAA;IACA;EAAA,GACC,oBAAA;EA2CI,cAAA,CAAe,QAAA,EAAU,qBAAA;EAMzB,qBAAA;IACL,UAAA;IACA,QAAA;IACA;EAAA,GACC,4BAAA;AAAA"}
|
|
@@ -18,6 +18,7 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
18
18
|
switchToBranch: true,
|
|
19
19
|
switchBranchDuringRun: true,
|
|
20
20
|
edit: true,
|
|
21
|
+
delete: false,
|
|
21
22
|
reload: true,
|
|
22
23
|
cancel: true,
|
|
23
24
|
unstable_copy: true,
|
|
@@ -89,6 +90,11 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
89
90
|
this.capabilities.feedback = canFeedback;
|
|
90
91
|
hasUpdates = true;
|
|
91
92
|
}
|
|
93
|
+
const canDelete = options.adapters?.history?.delete !== void 0;
|
|
94
|
+
if (this.capabilities.delete !== canDelete) {
|
|
95
|
+
this.capabilities.delete = canDelete;
|
|
96
|
+
hasUpdates = true;
|
|
97
|
+
}
|
|
92
98
|
const canQueue = options.unstable_enableMessageQueue === true;
|
|
93
99
|
if (canQueue && !this._queue) {
|
|
94
100
|
this._queue = createMessageQueue({ run: (message) => {
|
|
@@ -175,6 +181,21 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
175
181
|
this._notifySubscribers();
|
|
176
182
|
}
|
|
177
183
|
}
|
|
184
|
+
async deleteMessage(messageId) {
|
|
185
|
+
const adapter = this._options.adapters.history;
|
|
186
|
+
if (!adapter?.delete) throw new Error("Runtime does not support deleting messages.");
|
|
187
|
+
const messages = this.repository.getMessages();
|
|
188
|
+
const messageIndex = messages.findIndex((m) => m.id === messageId);
|
|
189
|
+
if (messageIndex === -1) throw new Error("Message not found.");
|
|
190
|
+
const message = messages[messageIndex];
|
|
191
|
+
const items = [{
|
|
192
|
+
parentId: messages[messageIndex - 1]?.id ?? null,
|
|
193
|
+
message
|
|
194
|
+
}];
|
|
195
|
+
await adapter.delete(items);
|
|
196
|
+
this.repository.deleteMessage(messageId);
|
|
197
|
+
this._notifySubscribers();
|
|
198
|
+
}
|
|
178
199
|
resumeRun({ stream, ...startConfig }) {
|
|
179
200
|
if (!stream) throw new Error("You must pass a stream parameter to resume runs.");
|
|
180
201
|
return this.startRun(startConfig, stream);
|
|
@@ -187,7 +208,7 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
187
208
|
}
|
|
188
209
|
async startRun({ parentId, runConfig }, runCallback) {
|
|
189
210
|
this.ensureInitialized();
|
|
190
|
-
|
|
211
|
+
const message = {
|
|
191
212
|
id: generateId(),
|
|
192
213
|
role: "assistant",
|
|
193
214
|
status: { type: "running" },
|
|
@@ -201,6 +222,9 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
201
222
|
},
|
|
202
223
|
createdAt: /* @__PURE__ */ new Date()
|
|
203
224
|
};
|
|
225
|
+
return this._runLoop(parentId, message, runConfig, runCallback);
|
|
226
|
+
}
|
|
227
|
+
async _runLoop(parentId, message, runConfig, runCallback) {
|
|
204
228
|
this._notifyEventSubscribers("runStart", {});
|
|
205
229
|
try {
|
|
206
230
|
this._queue?.notifyBusy();
|
|
@@ -378,13 +402,47 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
378
402
|
content: newContent
|
|
379
403
|
};
|
|
380
404
|
this.repository.addOrUpdateMessage(parentId, message);
|
|
381
|
-
|
|
405
|
+
this._notifySubscribers();
|
|
406
|
+
if (added && shouldContinue(message, this._options.unstable_humanToolNames)) this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});
|
|
382
407
|
}
|
|
383
408
|
resumeToolCall(_options) {
|
|
384
|
-
throw new Error("Local runtime does not support resuming tool calls.");
|
|
409
|
+
throw new Error("Local runtime does not support resuming tool calls. For human-in-the-loop tools, list the tool in unstable_humanToolNames and complete the call with addToolResult.");
|
|
385
410
|
}
|
|
386
|
-
respondToToolApproval(
|
|
387
|
-
|
|
411
|
+
respondToToolApproval({ approvalId, approved, reason }) {
|
|
412
|
+
let message = this.repository.getMessages().findLast((m) => m.role === "assistant" && m.content.some((c) => c.type === "tool-call" && c.approval?.id === approvalId));
|
|
413
|
+
if (!message) throw new Error("Tried to respond to a non-existing tool approval");
|
|
414
|
+
if (this.abortController !== null) throw new Error("Tried to respond to a tool approval while a run is in progress");
|
|
415
|
+
if (message.status?.type !== "requires-action") throw new Error("Tried to respond to a tool approval on a message whose status is not requires-action");
|
|
416
|
+
let recorded = false;
|
|
417
|
+
const newContent = message.content.map((c) => {
|
|
418
|
+
if (c.type !== "tool-call" || c.approval?.id !== approvalId) return c;
|
|
419
|
+
if (c.approval.approved !== void 0) return c;
|
|
420
|
+
recorded = true;
|
|
421
|
+
const approval = {
|
|
422
|
+
...c.approval,
|
|
423
|
+
approved,
|
|
424
|
+
...reason != null && { reason }
|
|
425
|
+
};
|
|
426
|
+
if (approved) return {
|
|
427
|
+
...c,
|
|
428
|
+
approval
|
|
429
|
+
};
|
|
430
|
+
return {
|
|
431
|
+
...c,
|
|
432
|
+
approval,
|
|
433
|
+
result: { error: reason || "Tool approval denied" },
|
|
434
|
+
isError: true
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
if (!recorded) throw new Error("Tried to respond to an already decided tool approval");
|
|
438
|
+
message = {
|
|
439
|
+
...message,
|
|
440
|
+
content: newContent
|
|
441
|
+
};
|
|
442
|
+
const { parentId } = this.repository.getMessage(message.id);
|
|
443
|
+
this.repository.addOrUpdateMessage(parentId, message);
|
|
444
|
+
this._notifySubscribers();
|
|
445
|
+
if (this.repository.headId === message.id && shouldContinue(message, this._options.unstable_humanToolNames)) this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});
|
|
388
446
|
}
|
|
389
447
|
};
|
|
390
448
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-thread-runtime-core.js","names":[],"sources":["../../../src/runtimes/local/local-thread-runtime-core.ts"],"sourcesContent":["import { fromThreadMessageLike } from \"../../runtime/utils/thread-message-like\";\nimport { generateId } from \"../../utils/id\";\nimport type {\n ChatModelAdapter,\n ChatModelRunResult,\n} from \"../../runtime/utils/chat-model-adapter\";\nimport { shouldContinue } from \"./should-continue\";\nimport type { LocalRuntimeOptionsBase } from \"./local-runtime-options\";\nimport type {\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseThreadRuntimeCore } from \"../../runtime/base/base-thread-runtime-core\";\nimport type {\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types/message\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport {\n createMessageQueue,\n type MessageQueueController,\n} from \"../../runtime/queue/message-queue\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\n\nclass AbortError extends Error {\n override name = \"AbortError\";\n detach: boolean;\n\n constructor(detach: boolean, message?: string) {\n super(message);\n this.detach = detach;\n }\n}\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n switchBranchDuringRun: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n };\n\n private abortController: AbortController | null = null;\n\n private _queue: MessageQueueController | null = null;\n private _queueRunInFlight = false;\n\n public readonly isDisabled = false;\n public readonly isSendDisabled = false;\n\n private _isLoading = false;\n public get isLoading() {\n return this._isLoading;\n }\n\n private _suggestions: readonly ThreadSuggestion[] = [];\n private _suggestionsController: AbortController | null = null;\n public get suggestions(): readonly ThreadSuggestion[] {\n return this._suggestions;\n }\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(contextProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n private _getThreadId?: () => string | undefined;\n\n public __internal_setGetThreadId(getThreadId: () => string | undefined) {\n this._getThreadId = getThreadId;\n }\n\n private _getInitializePromise?: () => Promise<unknown> | undefined;\n\n public __internal_setGetInitializePromise(\n getPromise: () => Promise<unknown> | undefined,\n ) {\n this._getInitializePromise = getPromise;\n }\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 canDictate = options.adapters?.dictation !== undefined;\n if (this.capabilities.dictation !== canDictate) {\n this.capabilities.dictation = canDictate;\n hasUpdates = true;\n }\n\n const canVoice = options.adapters?.voice !== undefined;\n if (this.capabilities.voice !== canVoice) {\n this.capabilities.voice = canVoice;\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 const canQueue = options.unstable_enableMessageQueue === true;\n if (canQueue && !this._queue) {\n this._queue = createMessageQueue({\n run: (message) => {\n // release the queue when the dispatch settles, even if it rejects\n // before reaching startRun's finally, so a failure can't deadlock it\n this._queueRunInFlight = true;\n void this._runAppend(message)\n .finally(() => {\n this._queueRunInFlight = false;\n this._queue?.notifyIdle();\n })\n .catch(() => {});\n },\n });\n this._queue.subscribe(() => this._notifySubscribers());\n } else if (!canQueue && this._queue) {\n this._queue.adapter.clear(\"cancel-run\");\n this._queue = null;\n }\n if (this.capabilities.queue !== canQueue) {\n this.capabilities.queue = canQueue;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _loadPromise: Promise<void> | undefined;\n public __internal_load() {\n if (this._loadPromise) return this._loadPromise;\n\n const promise = this.adapters.history?.load() ?? Promise.resolve(null);\n\n this._isLoading = true;\n this._notifySubscribers();\n\n this._loadPromise = promise\n .then((repo) => {\n if (!repo) return;\n this.repository.import(repo);\n if (repo.messages.length > 0) {\n this.ensureInitialized();\n }\n this._notifySubscribers();\n\n const resume = this.adapters.history?.resume?.bind(\n this.adapters.history,\n );\n if (repo.unstable_resume && resume) {\n this.startRun(\n {\n parentId: this.repository.headId,\n sourceId: this.repository.headId,\n runConfig: this._lastRunConfig,\n },\n resume,\n ).catch(() => {});\n }\n })\n .finally(() => {\n this._isLoading = false;\n this._notifySubscribers();\n });\n\n return this._loadPromise;\n }\n\n public async append(message: AppendMessage): Promise<void> {\n const isTail = message.parentId === (this.messages.at(-1)?.id ?? null);\n const willRun = message.startRun ?? message.role === \"user\";\n if (this._queue && willRun && isTail) {\n this._queue.adapter.enqueue(message, { steer: message.steer ?? false });\n return;\n }\n if (this._queue && !isTail) this._queue.adapter.clear(\"edit\");\n return this._runAppend(message);\n }\n\n public getQueueItems(): readonly QueueItemState[] {\n // Reads can arrive during base-thread construction, before the queue field\n // is assigned, so guard against the unset field.\n return this._queue?.adapter.items ?? EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(queueItemId: string): void {\n this._queue?.adapter.steer(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string): void {\n this._queue?.adapter.remove(queueItemId);\n }\n\n private async _runAppend(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const initPromise = this._getInitializePromise?.();\n if (initPromise) {\n await initPromise;\n }\n\n const newMessage = fromThreadMessageLike(message, generateId(), {\n type: \"complete\",\n reason: \"unknown\",\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n this._options.adapters.history?.append({\n parentId: message.parentId,\n message: newMessage,\n ...(message.runConfig !== undefined && { runConfig: message.runConfig }),\n });\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 resumeRun({ stream, ...startConfig }: ResumeRunConfig): Promise<void> {\n if (!stream)\n throw new Error(\"You must pass a stream parameter to resume runs.\");\n return this.startRun(startConfig, stream);\n }\n\n public exportExternalState(): any {\n throw new Error(\"Runtime does not support exporting external states.\");\n }\n\n public importExternalState(): void {\n throw new Error(\"Runtime does not support importing external states.\");\n }\n\n public async startRun(\n { parentId, runConfig }: StartRunConfig,\n runCallback?: ChatModelAdapter[\"run\"],\n ): Promise<void> {\n this.ensureInitialized();\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: {\n unstable_state: this.state,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"runStart\", {});\n\n try {\n // mark busy for runs not started through the queue (regenerate, resume)\n this._queue?.notifyBusy();\n this._suggestions = [];\n this._suggestionsController?.abort();\n this._suggestionsController = null;\n this._notifySubscribers();\n\n do {\n message = await this.performRoundtrip(\n parentId,\n message,\n runConfig,\n runCallback,\n );\n runCallback = undefined;\n } while (shouldContinue(message, this._options.unstable_humanToolNames));\n } finally {\n this._notifyEventSubscribers(\"runEnd\", {});\n // queue-driven runs release from the driver settle handler; a direct\n // run (regenerate, resume) releases here\n if (!this._queueRunInFlight) {\n queueMicrotask(() => this._queue?.notifyIdle());\n }\n }\n\n this._suggestionsController = new AbortController();\n const signal = this._suggestionsController.signal;\n if (\n this.adapters.suggestion &&\n message.status?.type !== \"requires-action\"\n ) {\n const promiseOrGenerator = this.adapters.suggestion?.generate({\n messages: this.messages,\n });\n\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (signal.aborted) break;\n this._suggestions = r;\n this._notifySubscribers();\n }\n } else {\n const result = await promiseOrGenerator;\n if (signal.aborted) return;\n this._suggestions = result;\n this._notifySubscribers();\n }\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n runCallback?: ChatModelAdapter[\"run\"],\n ) {\n const messages = parentId ? this.repository.getMessages(parentId) : [];\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialAnnotations = message.metadata?.unstable_annotations;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initialCustom = 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 newAnnotations = m.metadata?.unstable_annotations;\n const newData = m.metadata?.unstable_data;\n const annotations = newAnnotations\n ? [...(initialAnnotations ?? []), ...newAnnotations]\n : undefined;\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 ...(m.metadata.unstable_state\n ? { unstable_state: m.metadata.unstable_state }\n : undefined),\n ...(annotations\n ? { unstable_annotations: annotations }\n : undefined),\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.timing\n ? { timing: m.metadata.timing }\n : undefined),\n ...(m.metadata?.custom\n ? {\n custom: {\n ...(initialCustom ?? {}),\n ...m.metadata.custom,\n },\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 // Switch to the new message branch right after adding it for the first time\n this.repository.resetHead(message.id);\n this._notifySubscribers();\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const context = this.getModelContext();\n\n runCallback =\n runCallback ??\n this.adapters.chatModel.run.bind(this.adapters.chatModel);\n\n const abortSignal = this.abortController.signal;\n const threadId = this._getThreadId?.();\n const promiseOrGenerator = runCallback({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal,\n context,\n unstable_assistantMessageId: message.id,\n unstable_threadId: threadId,\n unstable_parentId: parentId,\n unstable_getMessage() {\n return message;\n },\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (abortSignal.aborted) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n break;\n }\n\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n // TODO this should be handled by the run result stream\n if (e instanceof AbortError) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"error\",\n error:\n e instanceof Error\n ? e.message\n : `[${typeof e}] ${new String(e).toString()}`,\n },\n });\n\n throw e;\n }\n } finally {\n this.abortController = null;\n\n if (\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\"\n ) {\n await this._options.adapters.history?.append({\n parentId,\n message: message,\n runConfig: this._lastRunConfig,\n });\n }\n }\n return message;\n }\n\n public detach() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(true);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public cancelRun() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(false);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n isError,\n artifact,\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 artifact,\n isError,\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 (\n added &&\n shouldContinue(message, this._options.unstable_humanToolNames)\n ) {\n this.performRoundtrip(parentId, message, this._lastRunConfig).catch(\n () => {},\n );\n }\n }\n\n public resumeToolCall(_options: ResumeToolCallOptions) {\n throw new Error(\"Local runtime does not support resuming tool calls.\");\n }\n\n public respondToToolApproval(_options: RespondToToolApprovalOptions) {\n throw new Error(\"Local runtime does not support tool approvals.\");\n }\n}\n"],"mappings":";;;;;;;AAiCA,IAAM,aAAN,cAAyB,MAAM;CAC7B,OAAgB;CAChB;CAEA,YAAY,QAAiB,SAAkB;EAC7C,MAAM,OAAO;EACb,KAAK,SAAS;CAChB;AACF;AAEA,IAAa,yBAAb,cACU,sBAEV;CACE,eAA+B;EAC7B,gBAAgB;EAChB,uBAAuB;EACvB,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,eAAe;EACf,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;EACb,UAAU;EACV,OA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AAC,OACH,MAAM,IAAI,MAAM,oDAAoD;EAEtE,UAAU;GACR,GAAG;GACH,SAAS;EACX;EACA,KAAK,WAAW,mBAAmB,UAAU,OAAO;EAEpD,IACE,SACA,eAAe,SAAS,KAAK,SAAS,uBAAuB,GAE7D,KAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc,CAAC,CAAC,YACtD,CAAC,CACT;CAEJ;CAEA,eAAsB,UAAiC;EACrD,MAAM,IAAI,MAAM,qDAAqD;CACvE;CAEA,sBAA6B,UAAwC;EACnE,MAAM,IAAI,MAAM,gDAAgD;CAClE;AACF"}
|
|
1
|
+
{"version":3,"file":"local-thread-runtime-core.js","names":[],"sources":["../../../src/runtimes/local/local-thread-runtime-core.ts"],"sourcesContent":["import { fromThreadMessageLike } from \"../../runtime/utils/thread-message-like\";\nimport { generateId } from \"../../utils/id\";\nimport type {\n ChatModelAdapter,\n ChatModelRunResult,\n} from \"../../runtime/utils/chat-model-adapter\";\nimport { shouldContinue } from \"./should-continue\";\nimport type { LocalRuntimeOptionsBase } from \"./local-runtime-options\";\nimport type {\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseThreadRuntimeCore } from \"../../runtime/base/base-thread-runtime-core\";\nimport type {\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types/message\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport {\n createMessageQueue,\n type MessageQueueController,\n} from \"../../runtime/queue/message-queue\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\n\nclass AbortError extends Error {\n override name = \"AbortError\";\n detach: boolean;\n\n constructor(detach: boolean, message?: string) {\n super(message);\n this.detach = detach;\n }\n}\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n switchBranchDuringRun: true,\n edit: true,\n delete: false,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n };\n\n private abortController: AbortController | null = null;\n\n private _queue: MessageQueueController | null = null;\n private _queueRunInFlight = false;\n\n public readonly isDisabled = false;\n public readonly isSendDisabled = false;\n\n private _isLoading = false;\n public get isLoading() {\n return this._isLoading;\n }\n\n private _suggestions: readonly ThreadSuggestion[] = [];\n private _suggestionsController: AbortController | null = null;\n public get suggestions(): readonly ThreadSuggestion[] {\n return this._suggestions;\n }\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(contextProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n private _getThreadId?: () => string | undefined;\n\n public __internal_setGetThreadId(getThreadId: () => string | undefined) {\n this._getThreadId = getThreadId;\n }\n\n private _getInitializePromise?: () => Promise<unknown> | undefined;\n\n public __internal_setGetInitializePromise(\n getPromise: () => Promise<unknown> | undefined,\n ) {\n this._getInitializePromise = getPromise;\n }\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 canDictate = options.adapters?.dictation !== undefined;\n if (this.capabilities.dictation !== canDictate) {\n this.capabilities.dictation = canDictate;\n hasUpdates = true;\n }\n\n const canVoice = options.adapters?.voice !== undefined;\n if (this.capabilities.voice !== canVoice) {\n this.capabilities.voice = canVoice;\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 const canDelete = options.adapters?.history?.delete !== undefined;\n if (this.capabilities.delete !== canDelete) {\n this.capabilities.delete = canDelete;\n hasUpdates = true;\n }\n\n const canQueue = options.unstable_enableMessageQueue === true;\n if (canQueue && !this._queue) {\n this._queue = createMessageQueue({\n run: (message) => {\n // release the queue when the dispatch settles, even if it rejects\n // before reaching startRun's finally, so a failure can't deadlock it\n this._queueRunInFlight = true;\n void this._runAppend(message)\n .finally(() => {\n this._queueRunInFlight = false;\n this._queue?.notifyIdle();\n })\n .catch(() => {});\n },\n });\n this._queue.subscribe(() => this._notifySubscribers());\n } else if (!canQueue && this._queue) {\n this._queue.adapter.clear(\"cancel-run\");\n this._queue = null;\n }\n if (this.capabilities.queue !== canQueue) {\n this.capabilities.queue = canQueue;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _loadPromise: Promise<void> | undefined;\n public __internal_load() {\n if (this._loadPromise) return this._loadPromise;\n\n const promise = this.adapters.history?.load() ?? Promise.resolve(null);\n\n this._isLoading = true;\n this._notifySubscribers();\n\n this._loadPromise = promise\n .then((repo) => {\n if (!repo) return;\n this.repository.import(repo);\n if (repo.messages.length > 0) {\n this.ensureInitialized();\n }\n this._notifySubscribers();\n\n const resume = this.adapters.history?.resume?.bind(\n this.adapters.history,\n );\n if (repo.unstable_resume && resume) {\n this.startRun(\n {\n parentId: this.repository.headId,\n sourceId: this.repository.headId,\n runConfig: this._lastRunConfig,\n },\n resume,\n ).catch(() => {});\n }\n })\n .finally(() => {\n this._isLoading = false;\n this._notifySubscribers();\n });\n\n return this._loadPromise;\n }\n\n public async append(message: AppendMessage): Promise<void> {\n const isTail = message.parentId === (this.messages.at(-1)?.id ?? null);\n const willRun = message.startRun ?? message.role === \"user\";\n if (this._queue && willRun && isTail) {\n this._queue.adapter.enqueue(message, { steer: message.steer ?? false });\n return;\n }\n if (this._queue && !isTail) this._queue.adapter.clear(\"edit\");\n return this._runAppend(message);\n }\n\n public getQueueItems(): readonly QueueItemState[] {\n // Reads can arrive during base-thread construction, before the queue field\n // is assigned, so guard against the unset field.\n return this._queue?.adapter.items ?? EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(queueItemId: string): void {\n this._queue?.adapter.steer(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string): void {\n this._queue?.adapter.remove(queueItemId);\n }\n\n private async _runAppend(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const initPromise = this._getInitializePromise?.();\n if (initPromise) {\n await initPromise;\n }\n\n const newMessage = fromThreadMessageLike(message, generateId(), {\n type: \"complete\",\n reason: \"unknown\",\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n this._options.adapters.history?.append({\n parentId: message.parentId,\n message: newMessage,\n ...(message.runConfig !== undefined && { runConfig: message.runConfig }),\n });\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 deleteMessage(messageId: string): Promise<void> {\n const adapter = this._options.adapters.history;\n if (!adapter?.delete)\n throw new Error(\"Runtime does not support deleting messages.\");\n\n const messages = this.repository.getMessages();\n const messageIndex = messages.findIndex((m) => m.id === messageId);\n if (messageIndex === -1) throw new Error(\"Message not found.\");\n\n const message = messages[messageIndex]!;\n const parentId = messages[messageIndex - 1]?.id ?? null;\n const items = [{ parentId, message }];\n\n await adapter.delete(items);\n\n this.repository.deleteMessage(messageId);\n this._notifySubscribers();\n }\n\n public resumeRun({ stream, ...startConfig }: ResumeRunConfig): Promise<void> {\n if (!stream)\n throw new Error(\"You must pass a stream parameter to resume runs.\");\n return this.startRun(startConfig, stream);\n }\n\n public exportExternalState(): any {\n throw new Error(\"Runtime does not support exporting external states.\");\n }\n\n public importExternalState(): void {\n throw new Error(\"Runtime does not support importing external states.\");\n }\n\n public async startRun(\n { parentId, runConfig }: StartRunConfig,\n runCallback?: ChatModelAdapter[\"run\"],\n ): Promise<void> {\n this.ensureInitialized();\n\n // add assistant message\n const id = generateId();\n const message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: {\n unstable_state: this.state,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n createdAt: new Date(),\n };\n\n return this._runLoop(parentId, message, runConfig, runCallback);\n }\n\n private async _runLoop(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n runCallback?: ChatModelAdapter[\"run\"],\n ): Promise<void> {\n this._notifyEventSubscribers(\"runStart\", {});\n\n try {\n // mark busy for runs not started through the queue (regenerate, resume)\n this._queue?.notifyBusy();\n this._suggestions = [];\n this._suggestionsController?.abort();\n this._suggestionsController = null;\n this._notifySubscribers();\n\n do {\n message = await this.performRoundtrip(\n parentId,\n message,\n runConfig,\n runCallback,\n );\n runCallback = undefined;\n } while (shouldContinue(message, this._options.unstable_humanToolNames));\n } finally {\n this._notifyEventSubscribers(\"runEnd\", {});\n // queue-driven runs release from the driver settle handler; a direct\n // run (regenerate, resume) releases here\n if (!this._queueRunInFlight) {\n queueMicrotask(() => this._queue?.notifyIdle());\n }\n }\n\n this._suggestionsController = new AbortController();\n const signal = this._suggestionsController.signal;\n if (\n this.adapters.suggestion &&\n message.status?.type !== \"requires-action\"\n ) {\n const promiseOrGenerator = this.adapters.suggestion?.generate({\n messages: this.messages,\n });\n\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (signal.aborted) break;\n this._suggestions = r;\n this._notifySubscribers();\n }\n } else {\n const result = await promiseOrGenerator;\n if (signal.aborted) return;\n this._suggestions = result;\n this._notifySubscribers();\n }\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n runCallback?: ChatModelAdapter[\"run\"],\n ) {\n const messages = parentId ? this.repository.getMessages(parentId) : [];\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialAnnotations = message.metadata?.unstable_annotations;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initialCustom = 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 newAnnotations = m.metadata?.unstable_annotations;\n const newData = m.metadata?.unstable_data;\n const annotations = newAnnotations\n ? [...(initialAnnotations ?? []), ...newAnnotations]\n : undefined;\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 ...(m.metadata.unstable_state\n ? { unstable_state: m.metadata.unstable_state }\n : undefined),\n ...(annotations\n ? { unstable_annotations: annotations }\n : undefined),\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.timing\n ? { timing: m.metadata.timing }\n : undefined),\n ...(m.metadata?.custom\n ? {\n custom: {\n ...(initialCustom ?? {}),\n ...m.metadata.custom,\n },\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 // Switch to the new message branch right after adding it for the first time\n this.repository.resetHead(message.id);\n this._notifySubscribers();\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const context = this.getModelContext();\n\n runCallback =\n runCallback ??\n this.adapters.chatModel.run.bind(this.adapters.chatModel);\n\n const abortSignal = this.abortController.signal;\n const threadId = this._getThreadId?.();\n const promiseOrGenerator = runCallback({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal,\n context,\n unstable_assistantMessageId: message.id,\n unstable_threadId: threadId,\n unstable_parentId: parentId,\n unstable_getMessage() {\n return message;\n },\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (abortSignal.aborted) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n break;\n }\n\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n // TODO this should be handled by the run result stream\n if (e instanceof AbortError) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"error\",\n error:\n e instanceof Error\n ? e.message\n : `[${typeof e}] ${new String(e).toString()}`,\n },\n });\n\n throw e;\n }\n } finally {\n this.abortController = null;\n\n if (\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\"\n ) {\n await this._options.adapters.history?.append({\n parentId,\n message: message,\n runConfig: this._lastRunConfig,\n });\n }\n }\n return message;\n }\n\n public detach() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(true);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public cancelRun() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(false);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n isError,\n artifact,\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 artifact,\n isError,\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 this._notifySubscribers();\n\n // a result may arrive mid-run or on a non-head message; the resume\n // intentionally aborts any in-flight run, unlike respondToToolApproval\n if (\n added &&\n shouldContinue(message, this._options.unstable_humanToolNames)\n ) {\n this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});\n }\n }\n\n public resumeToolCall(_options: ResumeToolCallOptions) {\n throw new Error(\n \"Local runtime does not support resuming tool calls. For human-in-the-loop tools, list the tool in unstable_humanToolNames and complete the call with addToolResult.\",\n );\n }\n\n public respondToToolApproval({\n approvalId,\n approved,\n reason,\n }: RespondToToolApprovalOptions) {\n let message = this.repository\n .getMessages()\n .findLast(\n (m): m is ThreadAssistantMessage =>\n m.role === \"assistant\" &&\n m.content.some(\n (c) => c.type === \"tool-call\" && c.approval?.id === approvalId,\n ),\n );\n\n if (!message)\n throw new Error(\"Tried to respond to a non-existing tool approval\");\n\n if (this.abortController !== null)\n throw new Error(\n \"Tried to respond to a tool approval while a run is in progress\",\n );\n\n if (message.status?.type !== \"requires-action\")\n throw new Error(\n \"Tried to respond to a tool approval on a message whose status is not requires-action\",\n );\n\n let recorded = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\" || c.approval?.id !== approvalId) return c;\n if (c.approval.approved !== undefined) return c;\n recorded = true;\n const approval = {\n ...c.approval,\n approved,\n ...(reason != null && { reason }),\n };\n if (approved) return { ...c, approval };\n return {\n ...c,\n approval,\n result: { error: reason || \"Tool approval denied\" },\n isError: true,\n };\n });\n\n if (!recorded)\n throw new Error(\"Tried to respond to an already decided tool approval\");\n\n message = { ...message, content: newContent };\n const { parentId } = this.repository.getMessage(message.id);\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n\n if (\n this.repository.headId === message.id &&\n shouldContinue(message, this._options.unstable_humanToolNames)\n ) {\n this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});\n }\n }\n}\n"],"mappings":";;;;;;;AAiCA,IAAM,aAAN,cAAyB,MAAM;CAC7B,OAAgB;CAChB;CAEA,YAAY,QAAiB,SAAkB;EAC7C,MAAM,OAAO;EACb,KAAK,SAAS;CAChB;AACF;AAEA,IAAa,yBAAb,cACU,sBAEV;CACE,eAA+B;EAC7B,gBAAgB;EAChB,uBAAuB;EACvB,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,eAAe;EACf,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;EACb,UAAU;EACV,OAAO;CACT;CAEA,kBAAkD;CAElD,SAAgD;CAChD,oBAA4B;CAE5B,aAA6B;CAC7B,iBAAiC;CAEjC,aAAqB;CACrB,IAAW,YAAY;EACrB,OAAO,KAAK;CACd;CAEA,eAAoD,CAAC;CACrD,yBAAyD;CACzD,IAAW,cAA2C;EACpD,OAAO,KAAK;CACd;CAEA,IAAW,WAAW;EACpB,OAAO,KAAK,SAAS;CACvB;CAEA,YACE,iBACA,SACA;EACA,MAAM,eAAe;EACrB,KAAK,sBAAsB,OAAO;CACpC;CAEA;CAEA,iBAAoC,CAAC;CAErC;CAEA,0BAAiC,aAAuC;EACtE,KAAK,eAAe;CACtB;CAEA;CAEA,mCACE,YACA;EACA,KAAK,wBAAwB;CAC/B;CAEA,IAAW,SAAS,CAEpB;CAEA,sBAA6B,SAAkC;EAC7D,IAAI,KAAK,aAAa,SAAS;EA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AAI,CAAC,UACH,MAAM,IAAI,MAAM,sDAAsD;EAExE,UAAU;GAAE,GAAG;GAAS,SAAS;EAAW;EAC5C,MAAM,EAAE,aAAa,KAAK,WAAW,WAAW,QAAQ,EAAE;EAC1D,KAAK,WAAW,mBAAmB,UAAU,OAAO;EACpD,KAAK,mBAAmB;EAExB,IACE,KAAK,WAAW,WAAW,QAAQ,MACnC,eAAe,SAAS,KAAK,SAAS,uBAAuB,GAE7D,KAAK,SAAS,UAAU,SAAS,KAAK,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;CAExE;AACF"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
//#region src/runtimes/local/should-continue.ts
|
|
2
2
|
const shouldContinue = (result, humanToolNames) => {
|
|
3
|
-
if (
|
|
4
|
-
|
|
3
|
+
if (result.status?.type !== "requires-action" || result.status.reason !== "tool-calls") return false;
|
|
4
|
+
if (result.content.some((c) => c.type === "tool-call" && c.result === void 0 && c.approval !== void 0 && c.approval.approved === void 0)) return false;
|
|
5
|
+
if (humanToolNames === void 0) return result.content.every((c) => c.type !== "tool-call" || !!c.result || c.approval !== void 0);
|
|
6
|
+
return result.content.every((c) => c.type !== "tool-call" || !!c.result || c.approval !== void 0 || !humanToolNames.includes(c.toolName));
|
|
5
7
|
};
|
|
6
8
|
//#endregion
|
|
7
9
|
export { shouldContinue };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"should-continue.js","names":[],"sources":["../../../src/runtimes/local/should-continue.ts"],"sourcesContent":["import type { ThreadAssistantMessage } from \"../../types/message\";\n\nexport const shouldContinue = (\n result: ThreadAssistantMessage,\n humanToolNames: string[] | undefined,\n) => {\n
|
|
1
|
+
{"version":3,"file":"should-continue.js","names":[],"sources":["../../../src/runtimes/local/should-continue.ts"],"sourcesContent":["import type { ThreadAssistantMessage } from \"../../types/message\";\n\nexport const shouldContinue = (\n result: ThreadAssistantMessage,\n humanToolNames: string[] | undefined,\n) => {\n if (\n result.status?.type !== \"requires-action\" ||\n result.status.reason !== \"tool-calls\"\n )\n return false;\n\n const hasPendingApproval = result.content.some(\n (c) =>\n c.type === \"tool-call\" &&\n c.result === undefined &&\n c.approval !== undefined &&\n c.approval.approved === undefined,\n );\n if (hasPendingApproval) return false;\n\n // TODO legacy behavior -- make specifying human tool names required\n if (humanToolNames === undefined) {\n return result.content.every(\n (c) => c.type !== \"tool-call\" || !!c.result || c.approval !== undefined,\n );\n }\n\n return result.content.every(\n (c) =>\n c.type !== \"tool-call\" ||\n !!c.result ||\n c.approval !== undefined ||\n !humanToolNames.includes(c.toolName),\n );\n};\n"],"mappings":";AAEA,MAAa,kBACX,QACA,mBACG;CACH,IACE,OAAO,QAAQ,SAAS,qBACxB,OAAO,OAAO,WAAW,cAEzB,OAAO;CAST,IAP2B,OAAO,QAAQ,MACvC,MACC,EAAE,SAAS,eACX,EAAE,WAAW,KAAA,KACb,EAAE,aAAa,KAAA,KACf,EAAE,SAAS,aAAa,KAAA,CAEP,GAAG,OAAO;CAG/B,IAAI,mBAAmB,KAAA,GACrB,OAAO,OAAO,QAAQ,OACnB,MAAM,EAAE,SAAS,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,KAAA,CAChE;CAGF,OAAO,OAAO,QAAQ,OACnB,MACC,EAAE,SAAS,eACX,CAAC,CAAC,EAAE,UACJ,EAAE,aAAa,KAAA,KACf,CAAC,eAAe,SAAS,EAAE,QAAQ,CACvC;AACF"}
|
|
@@ -16,6 +16,7 @@ declare class ReadonlyThreadRuntimeCore extends BaseSubscribable implements Thre
|
|
|
16
16
|
getBranches(messageId: string): string[];
|
|
17
17
|
switchToBranch(): void;
|
|
18
18
|
append(): void;
|
|
19
|
+
deleteMessage(): void;
|
|
19
20
|
startRun(): void;
|
|
20
21
|
resumeRun(): void;
|
|
21
22
|
cancelRun(): void;
|
|
@@ -72,6 +73,7 @@ declare class ReadonlyThreadRuntimeCore extends BaseSubscribable implements Thre
|
|
|
72
73
|
readonly switchToBranch: false;
|
|
73
74
|
readonly switchBranchDuringRun: false;
|
|
74
75
|
readonly edit: false;
|
|
76
|
+
readonly delete: false;
|
|
75
77
|
readonly reload: false;
|
|
76
78
|
readonly cancel: false;
|
|
77
79
|
readonly unstable_copy: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadonlyThreadRuntimeCore.d.ts","names":[],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"mappings":";;;;;;cASa,yBAAA,SACH,gBAAA,YACG,iBAAA;EAAA,QAEH,SAAA;EAAA,IAEJ,QAAA,aAAQ,aAAA;EAIZ,WAAA,CAAY,QAAA,WAAmB,aAAA;EAM/B,cAAA,CAAe,SAAA;;;;;EAUf,WAAA,CAAY,SAAA;EAMZ,cAAA;EAIA,MAAA;EAIA,QAAA;EAIA,SAAA;EAIA,SAAA;EAEA,aAAA;EAIA,cAAA;EAIA,qBAAA;EAIA,KAAA;EAIA,YAAA;EAEA,YAAA;EAIA,eAAA;EAEA,cAAA;EACA,oBAAA,QAA2B,WAAA;EAE3B,SAAA;EAIA,WAAA;EAIA,cAAA;EAIA,eAAA;EAIA,mBAAA;EAIA,mBAAA;EAIA,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+EA,eAAA;EAIA,SAAA;EAIA,MAAA;EACA,KAAA;EAEA,YAAA;IAAA
|
|
1
|
+
{"version":3,"file":"ReadonlyThreadRuntimeCore.d.ts","names":[],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"mappings":";;;;;;cASa,yBAAA,SACH,gBAAA,YACG,iBAAA;EAAA,QAEH,SAAA;EAAA,IAEJ,QAAA,aAAQ,aAAA;EAIZ,WAAA,CAAY,QAAA,WAAmB,aAAA;EAM/B,cAAA,CAAe,SAAA;;;;;EAUf,WAAA,CAAY,SAAA;EAMZ,cAAA;EAIA,MAAA;EAIA,aAAA;EAIA,QAAA;EAIA,SAAA;EAIA,SAAA;EAEA,aAAA;EAIA,cAAA;EAIA,qBAAA;EAIA,KAAA;EAIA,YAAA;EAEA,YAAA;EAIA,eAAA;EAEA,cAAA;EACA,oBAAA,QAA2B,WAAA;EAE3B,SAAA;EAIA,WAAA;EAIA,cAAA;EAIA,eAAA;EAIA,mBAAA;EAIA,mBAAA;EAIA,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+EA,eAAA;EAIA,SAAA;EAIA,MAAA;EACA,KAAA;EAEA,YAAA;IAAA;;;;;;;;;;;;;;EAgBA,UAAA;EACA,cAAA;EACA,SAAA;EAEA,KAAA;EACA,WAAA;EACA,MAAA;EAEA,MAAA;EAIA,MAAA;;;;;;EASA,KAAA;EAIA,WAAA,IAAe,WAAA;AAAA"}
|
|
@@ -30,6 +30,9 @@ var ReadonlyThreadRuntimeCore = class extends BaseSubscribable {
|
|
|
30
30
|
append() {
|
|
31
31
|
throw READONLY_THREAD_ERROR;
|
|
32
32
|
}
|
|
33
|
+
deleteMessage() {
|
|
34
|
+
throw READONLY_THREAD_ERROR;
|
|
35
|
+
}
|
|
33
36
|
startRun() {
|
|
34
37
|
throw READONLY_THREAD_ERROR;
|
|
35
38
|
}
|
|
@@ -134,6 +137,7 @@ var ReadonlyThreadRuntimeCore = class extends BaseSubscribable {
|
|
|
134
137
|
switchToBranch: false,
|
|
135
138
|
switchBranchDuringRun: false,
|
|
136
139
|
edit: false,
|
|
140
|
+
delete: false,
|
|
137
141
|
reload: false,
|
|
138
142
|
cancel: false,
|
|
139
143
|
unstable_copy: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadonlyThreadRuntimeCore.js","names":[],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ThreadMessage } from \"../../types/message\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\n\nconst READONLY_THREAD_ERROR = new Error(\n \"This is a readonly thread. You cannot perform mutations on readonly threads.\",\n);\n\nexport class ReadonlyThreadRuntimeCore\n extends BaseSubscribable\n implements ThreadRuntimeCore\n{\n private _messages: readonly ThreadMessage[] = [];\n\n get messages() {\n return this._messages;\n }\n\n setMessages(messages: readonly ThreadMessage[]) {\n if (this._messages === messages) return;\n this._messages = messages;\n this._notifySubscribers();\n }\n\n getMessageById(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return undefined;\n return {\n parentId: this._messages[idx - 1]?.id ?? null,\n message: this._messages[idx]!,\n index: idx,\n };\n }\n\n getBranches(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return [];\n return [messageId];\n }\n\n switchToBranch(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n append(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n startRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n cancelRun(): void {}\n\n addToolResult(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeToolCall(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n respondToToolApproval(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speak(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n stopSpeaking(): void {}\n\n connectVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n disconnectVoice(): void {}\n\n getVoiceVolume = () => 0;\n subscribeVoiceVolume = (): Unsubscribe => () => {};\n\n muteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unmuteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n submitFeedback(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n getModelContext() {\n return {};\n }\n\n exportExternalState() {\n throw READONLY_THREAD_ERROR;\n }\n\n importExternalState(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n composer = {\n attachments: [] as never[],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n isEditing: false as const,\n canCancel: false,\n canSend: false,\n isEmpty: true,\n text: \"\",\n\n setText() {\n throw READONLY_THREAD_ERROR;\n },\n\n role: \"user\" as const,\n\n setRole() {\n throw READONLY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw READONLY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw READONLY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw READONLY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw READONLY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n };\n\n getEditComposer() {\n return undefined;\n }\n\n beginEdit(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speech = undefined;\n voice = undefined;\n\n capabilities = {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n } as const;\n\n isDisabled = false;\n isSendDisabled = false;\n isLoading = false;\n\n state = null;\n suggestions = [] as never[];\n extras = undefined;\n\n import(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n export() {\n return {\n messages: this._messages.map((message, idx) => ({\n message,\n parentId: this._messages[idx - 1]?.id ?? null,\n })),\n };\n }\n\n reset(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unstable_on(): Unsubscribe {\n return () => {};\n }\n}\n"],"mappings":";;AAKA,MAAM,wCAAwB,IAAI,MAChC,8EACF;AAEA,IAAa,4BAAb,cACU,iBAEV;CACE,YAA8C,CAAC;CAE/C,IAAI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M;EACR;EAEA,MAAM;EAEN,UAAU;GACR,MAAM;EACR;EAEA,WAAW,CAAC;EAEZ,eAAe;GACb,MAAM;EACR;EAEA,MAAM,QAAQ,CAEd;EAEA,MAAM,mBAAmB,CAEzB;EAEA,OAAO;GACL,MAAM;EACR;EAEA,SAAS,CAET;EAEA,OAAO,CAAC;EACR,iBAAiB,CAAC;EAClB,kBAAkB,CAAC;EAEnB,WAAW,KAAA;EAEX,iBAAiB;GACf,MAAM;EACR;EAEA,gBAAgB,CAEhB;EAEA,OAAO,KAAA;EAEP,WAAW;GACT,MAAM;EACR;EAEA,YAAY;GACV,aAAa,CAAC;EAChB;EAEA,cAAc;GACZ,aAAa,CAAC;EAChB;CACF;CAEA,kBAAkB,CAElB;CAEA,YAAkB;EAChB,MAAM;CACR;CAEA,SAAS,KAAA;CACT,QAAQ,KAAA;CAER,eAAe;EACb,gBAAgB;EAChB,uBAAuB;EACvB,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,eAAe;EACf,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;EACb,UAAU;EACV,OAAO;CACT;CAEA,aAAa;CACb,iBAAiB;CACjB,YAAY;CAEZ,QAAQ;CACR,cAAc,CAAC;CACf,SAAS,KAAA;CAET,SAAe;EACb,MAAM;CACR;CAEA,SAAS;EACP,OAAO,EACL,UAAU,KAAK,UAAU,KAAK,SAAS,SAAS;GAC9C;GACA,UAAU,KAAK,UAAU,MAAM,EAAE,EAAE,MAAM;EAC3C,EAAE,EACJ;CACF;CAEA,QAAc;EACZ,MAAM;CACR;CAEA,cAA2B;EACzB,aAAa,CAAC;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"ReadonlyThreadRuntimeCore.js","names":[],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ThreadMessage } from \"../../types/message\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\n\nconst READONLY_THREAD_ERROR = new Error(\n \"This is a readonly thread. You cannot perform mutations on readonly threads.\",\n);\n\nexport class ReadonlyThreadRuntimeCore\n extends BaseSubscribable\n implements ThreadRuntimeCore\n{\n private _messages: readonly ThreadMessage[] = [];\n\n get messages() {\n return this._messages;\n }\n\n setMessages(messages: readonly ThreadMessage[]) {\n if (this._messages === messages) return;\n this._messages = messages;\n this._notifySubscribers();\n }\n\n getMessageById(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return undefined;\n return {\n parentId: this._messages[idx - 1]?.id ?? null,\n message: this._messages[idx]!,\n index: idx,\n };\n }\n\n getBranches(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return [];\n return [messageId];\n }\n\n switchToBranch(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n append(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n deleteMessage(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n startRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n cancelRun(): void {}\n\n addToolResult(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeToolCall(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n respondToToolApproval(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speak(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n stopSpeaking(): void {}\n\n connectVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n disconnectVoice(): void {}\n\n getVoiceVolume = () => 0;\n subscribeVoiceVolume = (): Unsubscribe => () => {};\n\n muteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unmuteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n submitFeedback(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n getModelContext() {\n return {};\n }\n\n exportExternalState() {\n throw READONLY_THREAD_ERROR;\n }\n\n importExternalState(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n composer = {\n attachments: [] as never[],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n isEditing: false as const,\n canCancel: false,\n canSend: false,\n isEmpty: true,\n text: \"\",\n\n setText() {\n throw READONLY_THREAD_ERROR;\n },\n\n role: \"user\" as const,\n\n setRole() {\n throw READONLY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw READONLY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw READONLY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw READONLY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw READONLY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n };\n\n getEditComposer() {\n return undefined;\n }\n\n beginEdit(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speech = undefined;\n voice = undefined;\n\n capabilities = {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n delete: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n } as const;\n\n isDisabled = false;\n isSendDisabled = false;\n isLoading = false;\n\n state = null;\n suggestions = [] as never[];\n extras = undefined;\n\n import(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n export() {\n return {\n messages: this._messages.map((message, idx) => ({\n message,\n parentId: this._messages[idx - 1]?.id ?? null,\n })),\n };\n }\n\n reset(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unstable_on(): Unsubscribe {\n return () => {};\n }\n}\n"],"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":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"mappings":";;;cAKa,iBAAA,EAAmB,
|
|
1
|
+
{"version":3,"file":"empty-thread-core.d.ts","names":[],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"mappings":";;;cAKa,iBAAA,EAAmB,iBAmO/B"}
|
|
@@ -11,6 +11,9 @@ const EMPTY_THREAD_CORE = {
|
|
|
11
11
|
append() {
|
|
12
12
|
throw EMPTY_THREAD_ERROR;
|
|
13
13
|
},
|
|
14
|
+
deleteMessage() {
|
|
15
|
+
throw EMPTY_THREAD_ERROR;
|
|
16
|
+
},
|
|
14
17
|
startRun() {
|
|
15
18
|
throw EMPTY_THREAD_ERROR;
|
|
16
19
|
},
|
|
@@ -121,6 +124,7 @@ const EMPTY_THREAD_CORE = {
|
|
|
121
124
|
switchToBranch: false,
|
|
122
125
|
switchBranchDuringRun: false,
|
|
123
126
|
edit: false,
|
|
127
|
+
delete: false,
|
|
124
128
|
reload: false,
|
|
125
129
|
cancel: false,
|
|
126
130
|
unstable_copy: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty-thread-core.js","names":[],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"sourcesContent":["import type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\n\nconst EMPTY_THREAD_ERROR = new Error(\n \"This is the empty thread, a placeholder for the main thread. You cannot perform any actions on this thread instance. This error is probably because you tried to call a thread method in your render function. Call the method inside a `useEffect` hook instead.\",\n);\nexport const EMPTY_THREAD_CORE: ThreadRuntimeCore = {\n getMessageById() {\n return undefined;\n },\n\n getBranches() {\n return [];\n },\n\n switchToBranch() {\n throw EMPTY_THREAD_ERROR;\n },\n\n append() {\n throw EMPTY_THREAD_ERROR;\n },\n\n startRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancelRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n addToolResult() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeToolCall() {\n throw EMPTY_THREAD_ERROR;\n },\n\n respondToToolApproval() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speak() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopSpeaking() {\n throw EMPTY_THREAD_ERROR;\n },\n\n connectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n disconnectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getVoiceVolume: () => 0,\n subscribeVoiceVolume: () => () => {},\n\n muteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unmuteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n submitFeedback() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getModelContext() {\n return {};\n },\n\n exportExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n importExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n composer: {\n attachments: [],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n isEditing: true,\n\n canCancel: false,\n canSend: false,\n isEmpty: true,\n\n text: \"\",\n\n setText() {\n throw EMPTY_THREAD_ERROR;\n },\n\n role: \"user\",\n\n setRole() {\n throw EMPTY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw EMPTY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n },\n\n getEditComposer() {\n return undefined;\n },\n\n beginEdit() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speech: undefined,\n voice: undefined,\n\n capabilities: {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n },\n\n isDisabled: false,\n isSendDisabled: false,\n isLoading: true,\n\n messages: [],\n\n state: null,\n\n suggestions: [],\n\n extras: undefined,\n\n subscribe() {\n return () => {};\n },\n\n import() {\n throw EMPTY_THREAD_ERROR;\n },\n\n export() {\n return { messages: [] };\n },\n\n reset() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unstable_on() {\n return () => {};\n },\n};\n"],"mappings":";AAEA,MAAM,qCAAqB,IAAI,MAC7B,mQACF;AACA,MAAa,oBAAuC;CAClD,iBAAiB,CAEjB;CAEA,cAAc;EACZ,OAAO,CAAC;CACV;CAEA,iBAAiB;EACf,MAAM;CACR;CAEA,SAAS;EACP,MAAM;CACR;CAEA,WAAW;EACT,MAAM;CACR;CAEA,YAAY;EACV,MAAM;CACR;CAEA,YAAY;EACV,MAAM;CACR;CAEA,gBAAgB;EACd,MAAM;CACR;CAEA,iBAAiB;EACf,MAAM;CACR;CAEA,wBAAwB;EACtB,MAAM;CACR;CAEA,QAAQ;EACN,MAAM;CACR;CAEA,eAAe;EACb,MAAM;CACR;CAEA,eAAe;EACb,MAAM;CACR;CAEA,kBAAkB;EAChB,MAAM;CACR;CAEA,sBAAsB;CACtB,kCAAkC,CAAC;CAEnC,YAAY;EACV,MAAM;CACR;CAEA,cAAc;EACZ,MAAM;CACR;CAEA,iBAAiB;EACf,MAAM;CACR;CAEA,kBAAkB;EAChB,OAAO,CAAC;CACV;CAEA,sBAAsB;EACpB,MAAM;CACR;CAEA,sBAAsB;EACpB,MAAM;CACR;CAEA,UAAU;EACR,aAAa,CAAC;EACd,kBAAkB;EAElB,MAAM,gBAAgB;GACpB,MAAM;EACR;EAEA,MAAM,mBAAmB;GACvB,MAAM;EACR;EAEA,WAAW;EAEX,WAAW;EACX,SAAS;EACT,SAAS;EAET,MAAM;EAEN,UAAU;GACR,MAAM;EACR;EAEA,MAAM;EAEN,UAAU;GACR,MAAM;EACR;EAEA,WAAW,CAAC;EAEZ,eAAe;GACb,MAAM;EACR;EAEA,MAAM,QAAQ,CAEd;EAEA,MAAM,mBAAmB,CAEzB;EAEA,OAAO;GACL,MAAM;EACR;EAEA,SAAS,CAET;EAEA,OAAO,CAAC;EACR,iBAAiB,CAAC;EAClB,kBAAkB,CAAC;EAEnB,WAAW,KAAA;EAEX,iBAAiB;GACf,MAAM;EACR;EAEA,gBAAgB,CAEhB;EAEA,OAAO,KAAA;EAEP,WAAW;GACT,MAAM;EACR;EAEA,YAAY;GACV,aAAa,CAAC;EAChB;EAEA,cAAc;GACZ,aAAa,CAAC;EAChB;CACF;CAEA,kBAAkB,CAElB;CAEA,YAAY;EACV,MAAM;CACR;CAEA,QAAQ,KAAA;CACR,OAAO,KAAA;CAEP,cAAc;EACZ,gBAAgB;EAChB,uBAAuB;EACvB,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,eAAe;EACf,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;EACb,UAAU;EACV,OAAO;CACT;CAEA,YAAY;CACZ,gBAAgB;CAChB,WAAW;CAEX,UAAU,CAAC;CAEX,OAAO;CAEP,aAAa,CAAC;CAEd,QAAQ,KAAA;CAER,YAAY;EACV,aAAa,CAAC;CAChB;CAEA,SAAS;EACP,MAAM;CACR;CAEA,SAAS;EACP,OAAO,EAAE,UAAU,CAAC,EAAE;CACxB;CAEA,QAAQ;EACN,MAAM;CACR;CAEA,cAAc;EACZ,aAAa,CAAC;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"empty-thread-core.js","names":[],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"sourcesContent":["import type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\n\nconst EMPTY_THREAD_ERROR = new Error(\n \"This is the empty thread, a placeholder for the main thread. You cannot perform any actions on this thread instance. This error is probably because you tried to call a thread method in your render function. Call the method inside a `useEffect` hook instead.\",\n);\nexport const EMPTY_THREAD_CORE: ThreadRuntimeCore = {\n getMessageById() {\n return undefined;\n },\n\n getBranches() {\n return [];\n },\n\n switchToBranch() {\n throw EMPTY_THREAD_ERROR;\n },\n\n append() {\n throw EMPTY_THREAD_ERROR;\n },\n\n deleteMessage() {\n throw EMPTY_THREAD_ERROR;\n },\n\n startRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancelRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n addToolResult() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeToolCall() {\n throw EMPTY_THREAD_ERROR;\n },\n\n respondToToolApproval() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speak() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopSpeaking() {\n throw EMPTY_THREAD_ERROR;\n },\n\n connectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n disconnectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getVoiceVolume: () => 0,\n subscribeVoiceVolume: () => () => {},\n\n muteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unmuteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n submitFeedback() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getModelContext() {\n return {};\n },\n\n exportExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n importExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n composer: {\n attachments: [],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n isEditing: true,\n\n canCancel: false,\n canSend: false,\n isEmpty: true,\n\n text: \"\",\n\n setText() {\n throw EMPTY_THREAD_ERROR;\n },\n\n role: \"user\",\n\n setRole() {\n throw EMPTY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw EMPTY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n },\n\n getEditComposer() {\n return undefined;\n },\n\n beginEdit() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speech: undefined,\n voice: undefined,\n\n capabilities: {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n delete: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n },\n\n isDisabled: false,\n isSendDisabled: false,\n isLoading: true,\n\n messages: [],\n\n state: null,\n\n suggestions: [],\n\n extras: undefined,\n\n subscribe() {\n return () => {};\n },\n\n import() {\n throw EMPTY_THREAD_ERROR;\n },\n\n export() {\n return { messages: [] };\n },\n\n reset() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unstable_on() {\n return () => {};\n },\n};\n"],"mappings":";AAEA,MAAM,qCAAqB,IAAI,MAC7B,mQACF;AACA,MAAa,oBAAuC;CAClD,iBAAiB,CAEjB;CAEA,cAAc;EACZ,OAAO,CAAC;CACV;CAEA,iBAAiB;EACf,MAAM;CACR;CAEA,SAAS;EACP,MAAM;CACR;CAEA,gBAAgB;EACd,MAAM;CACR;CAEA,WAAW;EACT,MAAM;CACR;CAEA,YAAY;EACV,MAAM;CACR;CAEA,YAAY;EACV,MAAM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