@assistant-ui/core 0.2.18 → 0.2.19
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/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +2 -1
- package/dist/model-context/interactable-composer-metadata.d.ts +105 -0
- package/dist/model-context/interactable-composer-metadata.d.ts.map +1 -0
- package/dist/model-context/interactable-composer-metadata.js +259 -0
- package/dist/model-context/interactable-composer-metadata.js.map +1 -0
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +1 -0
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/types.d.ts +6 -0
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js +4 -0
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/AssistantProvider.d.ts +1 -1
- package/dist/react/AssistantProvider.js +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +1 -1
- package/dist/react/RuntimeAdapter.js +1 -1
- package/dist/react/client/Interactables.d.ts +8 -2
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +190 -94
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.js +1 -1
- package/dist/react/client/interactable-model-context.d.ts +9 -6
- package/dist/react/client/interactable-model-context.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.js +154 -32
- package/dist/react/client/interactable-model-context.js.map +1 -1
- package/dist/react/index.d.ts +15 -6
- package/dist/react/index.js +12 -5
- package/dist/react/interactables-legacy/Interactables.d.ts +12 -0
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -0
- package/dist/react/interactables-legacy/Interactables.js +264 -0
- package/dist/react/interactables-legacy/Interactables.js.map +1 -0
- package/dist/react/interactables-legacy/interactable-model-context.d.ts +12 -0
- package/dist/react/interactables-legacy/interactable-model-context.d.ts.map +1 -0
- package/dist/react/interactables-legacy/interactable-model-context.js +54 -0
- package/dist/react/interactables-legacy/interactable-model-context.js.map +1 -0
- package/dist/react/interactables-legacy/scopes.d.ts +58 -0
- package/dist/react/interactables-legacy/scopes.d.ts.map +1 -0
- package/dist/react/interactables-legacy/scopes.js +0 -0
- package/dist/react/interactables-legacy/useAssistantInteractable.d.ts +31 -0
- package/dist/react/interactables-legacy/useAssistantInteractable.d.ts.map +1 -0
- package/dist/react/{model-context → interactables-legacy}/useAssistantInteractable.js +6 -2
- package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -0
- package/dist/react/interactables-legacy/useInteractableState.d.ts +21 -0
- package/dist/react/interactables-legacy/useInteractableState.d.ts.map +1 -0
- package/dist/react/interactables-legacy/useInteractableState.js +84 -0
- package/dist/react/interactables-legacy/useInteractableState.js.map +1 -0
- package/dist/react/model-context/interactableTool.d.ts +53 -0
- package/dist/react/model-context/interactableTool.d.ts.map +1 -0
- package/dist/react/model-context/interactableTool.js +188 -0
- package/dist/react/model-context/interactableTool.js.map +1 -0
- package/dist/react/model-context/useAssistantContext.js +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +1 -1
- package/dist/react/model-context/useAssistantInstructions.js +1 -1
- package/dist/react/model-context/useAssistantTool.js +1 -1
- package/dist/react/model-context/useAssistantToolUI.js +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +1 -1
- package/dist/react/model-context/useInteractable.d.ts +73 -0
- package/dist/react/model-context/useInteractable.d.ts.map +1 -0
- package/dist/react/model-context/useInteractable.js +100 -0
- package/dist/react/model-context/useInteractable.js.map +1 -0
- package/dist/react/model-context/useInteractableState.d.ts +8 -5
- package/dist/react/model-context/useInteractableState.d.ts.map +1 -1
- package/dist/react/model-context/useInteractableState.js +48 -48
- package/dist/react/model-context/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useInteractableVersions.d.ts +19 -0
- package/dist/react/model-context/useInteractableVersions.d.ts.map +1 -0
- package/dist/react/model-context/useInteractableVersions.js +51 -0
- package/dist/react/model-context/useInteractableVersions.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadMessageIds.d.ts +15 -0
- package/dist/react/primitive-hooks/useThreadMessageIds.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadMessageIds.js +26 -0
- package/dist/react/primitive-hooks/useThreadMessageIds.js.map +1 -0
- package/dist/react/primitive-hooks/useVoice.js +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +1 -1
- package/dist/react/primitives/message/MessageParts.js +1 -1
- package/dist/react/primitives/message/MessageQuote.js +1 -1
- package/dist/react/primitives/part/PartMessages.d.ts +5 -2
- package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
- package/dist/react/primitives/part/PartMessages.js +8 -8
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.d.ts +31 -1
- package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +64 -2
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +1 -1
- package/dist/react/providers/MessageByIdProvider.d.ts +9 -0
- package/dist/react/providers/MessageByIdProvider.d.ts.map +1 -0
- package/dist/react/providers/MessageByIdProvider.js +57 -0
- package/dist/react/providers/MessageByIdProvider.js.map +1 -0
- package/dist/react/providers/ReadonlyThreadProvider.js +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +3 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +16 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +1 -1
- package/dist/react/runtimes/createRuntimeExtras.d.ts +20 -0
- package/dist/react/runtimes/createRuntimeExtras.d.ts.map +1 -0
- package/dist/react/runtimes/createRuntimeExtras.js +43 -0
- package/dist/react/runtimes/createRuntimeExtras.js.map +1 -0
- package/dist/react/runtimes/useLocalRuntime.js +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +6 -2
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/runtimes/useStreamingTiming.d.ts +26 -0
- package/dist/react/runtimes/useStreamingTiming.d.ts.map +1 -0
- package/dist/react/runtimes/useStreamingTiming.js +43 -0
- package/dist/react/runtimes/useStreamingTiming.js.map +1 -0
- package/dist/react/types/scopes/interactables.d.ts +40 -24
- package/dist/react/types/scopes/interactables.d.ts.map +1 -1
- package/dist/react/types/store-augmentation.d.ts +3 -1
- package/dist/react/types/store-augmentation.d.ts.map +1 -1
- package/dist/react/utils/useJSONEqual.d.ts +11 -0
- package/dist/react/utils/useJSONEqual.d.ts.map +1 -0
- package/dist/react/utils/useJSONEqual.js +30 -0
- package/dist/react/utils/useJSONEqual.js.map +1 -0
- package/dist/runtime/base/base-composer-runtime-core.d.ts +5 -0
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +13 -0
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +6 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +4 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts +1 -0
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +6 -3
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/streaming-timing.d.ts +59 -0
- package/dist/runtime/utils/streaming-timing.d.ts.map +1 -0
- package/dist/runtime/utils/streaming-timing.js +76 -0
- package/dist/runtime/utils/streaming-timing.js.map +1 -0
- package/dist/runtime/utils/thread-message-like.js +2 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +26 -1
- 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 +9 -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 +19 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +12 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts +1 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.js +3 -2
- package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +17 -0
- package/src/internal.ts +7 -0
- package/src/model-context/interactable-composer-metadata.test.ts +550 -0
- package/src/model-context/interactable-composer-metadata.ts +395 -0
- package/src/model-context/registry.ts +5 -0
- package/src/model-context/types.ts +12 -0
- package/src/react/client/Interactables.test.ts +358 -0
- package/src/react/client/Interactables.ts +339 -86
- package/src/react/client/interactable-model-context.test.ts +418 -0
- package/src/react/client/interactable-model-context.ts +252 -58
- package/src/react/index.ts +72 -3
- package/src/react/interactables-legacy/Interactables.ts +332 -0
- package/src/react/interactables-legacy/interactable-model-context.test.ts +54 -0
- package/src/react/interactables-legacy/interactable-model-context.ts +80 -0
- package/src/react/interactables-legacy/scopes.ts +66 -0
- package/src/react/{model-context → interactables-legacy}/useAssistantInteractable.ts +10 -1
- package/src/react/interactables-legacy/useInteractableState.ts +67 -0
- package/src/react/model-context/interactableTool.tsx +175 -0
- package/src/react/model-context/useInteractable.ts +233 -0
- package/src/react/model-context/useInteractableState.ts +31 -23
- package/src/react/model-context/useInteractableVersions.ts +48 -0
- package/src/react/primitive-hooks/useThreadMessageIds.ts +27 -0
- package/src/react/primitives/part/PartMessages.test.tsx +17 -0
- package/src/react/primitives/part/PartMessages.tsx +13 -8
- package/src/react/primitives/thread/ThreadMessages.tsx +67 -0
- package/src/react/providers/MessageByIdProvider.tsx +23 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +21 -1
- package/src/react/runtimes/createRuntimeExtras.test.ts +58 -0
- package/src/react/runtimes/createRuntimeExtras.ts +68 -0
- package/src/react/runtimes/createRuntimeExtras.use.test.ts +50 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +13 -1
- package/src/react/runtimes/useStreamingTiming.ts +68 -0
- package/src/react/types/scopes/interactables.ts +45 -23
- package/src/react/types/store-augmentation.ts +4 -2
- package/src/react/utils/useJSONEqual.ts +20 -0
- package/src/runtime/base/base-composer-runtime-core.ts +13 -0
- package/src/runtime/base/default-edit-composer-runtime-core.ts +18 -1
- package/src/runtime/base/default-thread-composer-runtime-core.ts +11 -1
- package/src/runtime/utils/message-repository.ts +11 -7
- package/src/runtime/utils/streaming-timing.test.ts +301 -0
- package/src/runtime/utils/streaming-timing.ts +161 -0
- package/src/runtime/utils/thread-message-like.ts +2 -1
- package/src/runtimes/external-store/external-store-adapter.ts +28 -0
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +33 -1
- package/src/runtimes/local/local-thread-runtime-core.ts +4 -1
- package/src/runtimes/remote-thread-list/types.ts +13 -0
- package/src/tests/MessageRepository.test.ts +2 -0
- package/src/tests/composer-can-send.test.ts +1 -0
- package/src/tests/default-edit-composer-runtime-core.test.ts +78 -1
- package/src/tests/default-thread-composer-runtime-core.test.ts +82 -0
- package/src/tests/external-store-thread-runtime-core.test.ts +337 -0
- package/src/tests/groupParts.test.ts +32 -0
- package/src/tests/remote-thread-list-reactive-threadId.test.ts +90 -0
- package/src/tests/remote-thread-list-test-helpers.ts +2 -1
- package/src/tests/thread-message-like.test.ts +50 -0
- package/dist/react/model-context/useAssistantInteractable.d.ts +0 -22
- package/dist/react/model-context/useAssistantInteractable.d.ts.map +0 -1
- package/dist/react/model-context/useAssistantInteractable.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookRef","runtimeHook","current","startThreadIdRef","threadId","initialThreadId","stableRuntimeHook","stableOptions","adapter","allowNesting","aui","isNested","threadListItem","source","Error","prevThreadIdRef","switchToThread","catch","switchToNewThread"],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookRef","runtimeHook","current","startThreadIdRef","threadId","initialThreadId","stableRuntimeHook","onThreadIdChange","stableOptions","adapter","allowNesting","aui","isNested","threadListItem","source","Error","prevThreadIdRef","switchToThread","catch","switchToNewThread"],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import {\n useState,\n useEffect,\n useMemo,\n useRef,\n useCallback,\n useEffectEvent,\n} from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { AssistantRuntimeImpl } from \"../../runtime/api/assistant-runtime\";\nimport type { RemoteThreadListOptions } from \"../../runtimes/remote-thread-list/types\";\nimport type { AssistantRuntimeCore } from \"../../runtime/interfaces/assistant-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { useAui } from \"@assistant-ui/store\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(options: RemoteThreadListOptions) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n options,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nconst useRemoteThreadListRuntimeImpl = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));\n useEffect(() => {\n runtime.threads.__internal_setOptions(options);\n runtime.threads.__internal_load();\n }, [runtime, options]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const runtimeHookRef = useRef(options.runtimeHook);\n runtimeHookRef.current = options.runtimeHook;\n\n // threadId/initialThreadId only affect the constructor; capture once via ref\n const startThreadIdRef = useRef(options.threadId ?? options.initialThreadId);\n\n const stableRuntimeHook = useCallback(() => {\n return runtimeHookRef.current();\n }, []);\n\n const onThreadIdChange = useEffectEvent((threadId: string | undefined) => {\n options.onThreadIdChange?.(threadId);\n });\n\n const stableOptions = useMemo<RemoteThreadListOptions>(\n () => ({\n adapter: options.adapter,\n allowNesting: options.allowNesting,\n initialThreadId: startThreadIdRef.current,\n runtimeHook: stableRuntimeHook,\n onThreadIdChange,\n }),\n [options.adapter, options.allowNesting, stableRuntimeHook],\n );\n\n const aui = useAui();\n const isNested = aui.threadListItem.source !== null;\n\n if (isNested) {\n if (!stableOptions.allowNesting) {\n throw new Error(\n \"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. \" +\n \"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).\",\n );\n }\n\n // If allowNesting is true and already inside a thread list context,\n // just call the runtimeHook directly (no-op behavior)\n return stableRuntimeHook();\n }\n\n const runtime = useRemoteThreadListRuntimeImpl(stableOptions);\n\n const prevThreadIdRef = useRef(options.threadId);\n useEffect(() => {\n if (options.threadId === prevThreadIdRef.current) return;\n prevThreadIdRef.current = options.threadId;\n if (options.threadId) {\n runtime.threads.switchToThread(options.threadId).catch(() => {});\n } else {\n runtime.threads.switchToNewThread().cat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W;CACjDD,eAAeE,UAAUjB,QAAQgB;CAGjC,MAAME,mBAAmB/B,OAAOa,QAAQmB,YAAYnB,QAAQoB,eAAe;CAE3E,MAAMC,oBAAoBjC,kBAAkB;EAC1C,OAAO2B,eAAeE,QAAQ;CAChC,GAAG,CAAA,CAAE;CAEL,MAAMK,mBAAmBjC,gBAAgB8B,aAAiC;EACxEnB,QAAQsB,mBAAmBH,QAAQ;CACrC,CAAC;CAED,MAAMI,gBAAgBrC,eACb;EACLsC,SAASxB,QAAQwB;EACjBC,cAAczB,QAAQyB;EACtBL,iBAAiBF,iBAAiBD;EAClCD,aAAaK;EACbC;CACF,IACA;EAACtB,QAAQwB;EAASxB,QAAQyB;EAAcJ;CAAiB,CAC3D;CAKA,IAHYzB,OACK8B,CAAG,CAACE,eAAeC,WAAW,MAEjC;EACZ,IAAI,CAACN,cAAcE,cACjB,MAAM,IAAIK,MACR,sKAEF;EAKF,OAAOT,kBAAkB;CAC3B;CAEA,MAAMb,UAAUJ,+BAA+BmB,aAAa;CAE5D,MAAMQ,kBAAkB5C,OAAOa,QAAQmB,QAAQ;CAC/ClC,gBAAgB;EACd,IAAIe,QAAQmB,aAAaY,gBAAgBd,SAAS;EAClDc,gBAAgBd,UAAUjB,QAAQmB;EAClC,IAAInB,QAAQmB,UACVX,QAAQV,QAAQkC,eAAehC,QAAQmB,QAAQ,CAAC,CAACc,YAAY,CAAC,CAAC;OAE/DzB,QAAQV,QAAQoC,kBAAkB,CAAC,CAACD,YAAY,CAAC,CAAC;CAEtD,GAAG,CAACzB,SAASR,QAAQmB,QAAQ,CAAC;CAE9B,OAAOX;AACT"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MessageTiming } from "../../types/message.js";
|
|
2
|
+
import { StreamingTimingAccessors, StreamingTimingOptions, StreamingTimingState } from "../../runtime/utils/streaming-timing.js";
|
|
3
|
+
|
|
4
|
+
//#region src/react/runtimes/useStreamingTiming.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Tracks per-message streaming timing client-side and returns finalized
|
|
7
|
+
* `MessageTiming` keyed by message id.
|
|
8
|
+
*
|
|
9
|
+
* Observes `isRunning` transitions and content growth through the provided
|
|
10
|
+
* `accessors`, which adapt the hook to a runtime's message shape. Timing is
|
|
11
|
+
* finalized when streaming ends; adapters thread the result into
|
|
12
|
+
* `useExternalMessageConverter` metadata as `messageTiming`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const messageTiming = useStreamingTiming(messages, isRunning, {
|
|
17
|
+
* getAssistantMessageId: (msgs) => msgs.findLast((m) => m.role === "assistant")?.id,
|
|
18
|
+
* getTextLength: (msgs, id) => msgs.find((m) => m.id === id)?.content?.length ?? 0,
|
|
19
|
+
* getToolCallCount: (msgs, id) => msgs.find((m) => m.id === id)?.tool_calls?.length ?? 0,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare const useStreamingTiming: <TMessage>(messages: readonly TMessage[], isRunning: boolean, accessors: StreamingTimingAccessors<TMessage>, options?: StreamingTimingOptions) => Record<string, MessageTiming>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { type StreamingTimingAccessors, type StreamingTimingOptions, type StreamingTimingState, useStreamingTiming };
|
|
26
|
+
//# sourceMappingURL=useStreamingTiming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStreamingTiming.d.ts","names":[],"sources":["../../../src/react/runtimes/useStreamingTiming.ts"],"mappings":";;;;;AAmCA;;;;;;;;;;;;;;;;;cAAa,kBAAA,aACX,QAAA,WAAmB,QAAA,IACnB,SAAA,WACA,SAAA,EAAW,wBAAA,CAAyB,QAAA,GACpC,OAAA,GAAU,sBAAA,KACT,MAAA,SAAe,aAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { stepStreamingTiming } from "../../runtime/utils/streaming-timing.js";
|
|
3
|
+
import { useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
//#region src/react/runtimes/useStreamingTiming.ts
|
|
5
|
+
/**
|
|
6
|
+
* Tracks per-message streaming timing client-side and returns finalized
|
|
7
|
+
* `MessageTiming` keyed by message id.
|
|
8
|
+
*
|
|
9
|
+
* Observes `isRunning` transitions and content growth through the provided
|
|
10
|
+
* `accessors`, which adapt the hook to a runtime's message shape. Timing is
|
|
11
|
+
* finalized when streaming ends; adapters thread the result into
|
|
12
|
+
* `useExternalMessageConverter` metadata as `messageTiming`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const messageTiming = useStreamingTiming(messages, isRunning, {
|
|
17
|
+
* getAssistantMessageId: (msgs) => msgs.findLast((m) => m.role === "assistant")?.id,
|
|
18
|
+
* getTextLength: (msgs, id) => msgs.find((m) => m.id === id)?.content?.length ?? 0,
|
|
19
|
+
* getToolCallCount: (msgs, id) => msgs.find((m) => m.id === id)?.tool_calls?.length ?? 0,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const useStreamingTiming = (messages, isRunning, accessors, options) => {
|
|
24
|
+
const [timings, setTimings] = useState({});
|
|
25
|
+
const stateRef = useRef(null);
|
|
26
|
+
const accessorsRef = useRef(accessors);
|
|
27
|
+
accessorsRef.current = accessors;
|
|
28
|
+
const optionsRef = useRef(options);
|
|
29
|
+
optionsRef.current = options;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const result = stepStreamingTiming(stateRef.current, messages, isRunning, accessorsRef.current, optionsRef.current);
|
|
32
|
+
stateRef.current = result.state;
|
|
33
|
+
if (Object.keys(result.timings).length > 0) setTimings((prev) => ({
|
|
34
|
+
...prev,
|
|
35
|
+
...result.timings
|
|
36
|
+
}));
|
|
37
|
+
}, [messages, isRunning]);
|
|
38
|
+
return timings;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useStreamingTiming };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=useStreamingTiming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStreamingTiming.js","names":["useEffect","useRef","useState","MessageTiming","stepStreamingTiming","StreamingTimingAccessors","StreamingTimingOptions","StreamingTimingState","useStreamingTiming","messages","TMessage","isRunning","accessors","options","Record","timings","setTimings","stateRef","accessorsRef","current","optionsRef","result","state","Object","keys","length","prev"],"sources":["../../../src/react/runtimes/useStreamingTiming.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport type { MessageTiming } from \"../../types/message\";\nimport {\n stepStreamingTiming,\n type StreamingTimingAccessors,\n type StreamingTimingOptions,\n type StreamingTimingState,\n} from \"../../runtime/utils/streaming-timing\";\n\nexport type {\n StreamingTimingAccessors,\n StreamingTimingOptions,\n StreamingTimingState,\n};\n\n/**\n * Tracks per-message streaming timing client-side and returns finalized\n * `MessageTiming` keyed by message id.\n *\n * Observes `isRunning` transitions and content growth through the provided\n * `accessors`, which adapt the hook to a runtime's message shape. Timing is\n * finalized when streaming ends; adapters thread the result into\n * `useExternalMessageConverter` metadata as `messageTiming`.\n *\n * @example\n * ```ts\n * const messageTiming = useStreamingTiming(messages, isRunning, {\n * getAssistantMessageId: (msgs) => msgs.findLast((m) => m.role === \"assistant\")?.id,\n * getTextLength: (msgs, id) => msgs.find((m) => m.id === id)?.content?.length ?? 0,\n * getToolCallCount: (msgs, id) => msgs.find((m) => m.id === id)?.tool_calls?.length ?? 0,\n * });\n * ```\n */\nexport const useStreamingTiming = <TMessage>(\n messages: readonly TMessage[],\n isRunning: boolean,\n accessors: StreamingTimingAccessors<TMessage>,\n options?: StreamingTimingOptions,\n): Record<string, MessageTiming> => {\n const [timings, setTimings] = useState<Record<string, MessageTiming>>({});\n const stateRef = useRef<StreamingTimingState | null>(null);\n // Read the latest accessors/options from refs so the effect keeps the\n // original `[messages, isRunning]` reactivity of the adapter hooks this\n // replaces (a stable timings object while streaming, a single new reference\n // at finalize).\n const accessorsRef = useRef(accessors);\n accessorsRef.current = accessors;\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n const result = stepStreamingTiming(\n stateRef.current,\n messages,\n isRunning,\n accessorsRef.current,\n optionsRef.current,\n );\n stateRef.current = result.state;\n if (Object.keys(result.timings).length > 0) {\n setTimings((prev) => ({ ...prev, ...result.timings }));\n }\n }, [messages, isRunning]);\n\n return timings;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAaQ,sBACXC,UACAE,WACAC,WACAC,YACkC;CAClC,MAAM,CAACE,SAASC,cAAcd,SAAwC,CAAC,CAAC;CACxE,MAAMe,WAAWhB,OAAoC,IAAI;CAKzD,MAAMiB,eAAejB,OAAOW,SAAS;CACrCM,aAAaC,UAAUP;CACvB,MAAMQ,aAAanB,OAAOY,OAAO;CACjCO,WAAWD,UAAUN;CAErBb,gBAAgB;EACd,MAAMqB,SAASjB,oBACba,SAASE,SACTV,UACAE,WACAO,aAAaC,SACbC,WAAWD,OACb;EACAF,SAASE,UAAUE,OAAOC;EAC1B,IAAIC,OAAOC,KAAKH,OAAON,OAAO,CAAC,CAACU,SAAS,GACvCT,YAAYU,UAAU;GAAE,GAAGA;GAAM,GAAGL,OAAON;EAAQ,EAAE;CAEzD,GAAG,CAACN,UAAUE,SAAS,CAAC;CAExB,OAAOI;AACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Unsubscribe } from "../../../types/unsubscribe.js";
|
|
2
|
+
import { ToolCallMessagePartComponent } from "../MessagePartComponentTypes.js";
|
|
2
3
|
import { Tool } from "assistant-stream";
|
|
3
4
|
|
|
4
5
|
//#region src/react/types/scopes/interactables.d.ts
|
|
@@ -6,53 +7,68 @@ import { Tool } from "assistant-stream";
|
|
|
6
7
|
* Schema type matching Tool["parameters"] from assistant-stream.
|
|
7
8
|
* Accepts both StandardSchemaV1 and JSONSchema7.
|
|
8
9
|
*/
|
|
9
|
-
type
|
|
10
|
+
type Unstable_InteractableStateSchema = NonNullable<Extract<Tool, {
|
|
10
11
|
parameters: unknown;
|
|
11
12
|
}>["parameters"]>;
|
|
12
|
-
type
|
|
13
|
+
type InteractableScope = "app" | "thread";
|
|
14
|
+
type Unstable_InteractableDefinition = {
|
|
13
15
|
id: string;
|
|
14
16
|
name: string;
|
|
15
17
|
description: string;
|
|
16
|
-
stateSchema:
|
|
18
|
+
stateSchema: Unstable_InteractableStateSchema;
|
|
17
19
|
state: unknown;
|
|
18
|
-
|
|
20
|
+
initialState: unknown;
|
|
21
|
+
scope?: InteractableScope | undefined;
|
|
19
22
|
};
|
|
20
|
-
type
|
|
23
|
+
type Unstable_InteractableRegistration = {
|
|
21
24
|
id: string;
|
|
22
25
|
name: string;
|
|
23
26
|
description: string;
|
|
24
|
-
stateSchema:
|
|
27
|
+
stateSchema: Unstable_InteractableStateSchema;
|
|
25
28
|
initialState: unknown;
|
|
26
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Component installed as the tool UI for this interactable's `update_{name}`
|
|
31
|
+
* tool calls, so a model edit re-renders the interactable at the message
|
|
32
|
+
* that made it. Registered once per name; requires the `tools` scope.
|
|
33
|
+
*/
|
|
34
|
+
updateRender?: ToolCallMessagePartComponent | undefined;
|
|
27
35
|
};
|
|
28
|
-
type
|
|
36
|
+
type Unstable_InteractablePersistenceStatus = {
|
|
29
37
|
isPending: boolean;
|
|
30
38
|
error: unknown;
|
|
31
39
|
};
|
|
32
|
-
type
|
|
33
|
-
/** Keyed by instance id */definitions: Record<string,
|
|
34
|
-
persistence: Record<string,
|
|
40
|
+
type Unstable_InteractablesState = {
|
|
41
|
+
/** Keyed by instance id */definitions: Record<string, Unstable_InteractableDefinition>; /** Per-id persistence sync status */
|
|
42
|
+
persistence: Record<string, Unstable_InteractablePersistenceStatus>;
|
|
35
43
|
};
|
|
36
|
-
type
|
|
44
|
+
type Unstable_InteractablePersistedState = Record<string, {
|
|
37
45
|
name: string;
|
|
38
46
|
state: unknown;
|
|
39
47
|
}>;
|
|
40
|
-
type
|
|
41
|
-
save(state:
|
|
48
|
+
type Unstable_InteractablePersistenceAdapter = {
|
|
49
|
+
save(state: Unstable_InteractablePersistedState): void | Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Restores previously saved state. Called when the adapter is attached;
|
|
52
|
+
* loaded state seeds app-scoped interactables that have not been locally
|
|
53
|
+
* edited yet (a local edit always wins over a slow load).
|
|
54
|
+
*/
|
|
55
|
+
load?(): Unstable_InteractablePersistedState | null | undefined | Promise<Unstable_InteractablePersistedState | null | undefined>;
|
|
56
|
+
};
|
|
57
|
+
type Unstable_InteractablesConfig = {
|
|
58
|
+
persistence?: Unstable_InteractablePersistenceAdapter | undefined;
|
|
42
59
|
};
|
|
43
|
-
type
|
|
44
|
-
getState():
|
|
45
|
-
register(def:
|
|
60
|
+
type Unstable_InteractablesMethods = {
|
|
61
|
+
getState(): Unstable_InteractablesState;
|
|
62
|
+
register(def: Unstable_InteractableRegistration): Unsubscribe;
|
|
46
63
|
setState(id: string, updater: (prev: unknown) => unknown): void;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setPersistenceAdapter(adapter: InteractablePersistenceAdapter | undefined): void;
|
|
64
|
+
exportState(): Unstable_InteractablePersistedState;
|
|
65
|
+
importState(saved: Unstable_InteractablePersistedState): void;
|
|
66
|
+
setPersistenceAdapter(adapter: Unstable_InteractablePersistenceAdapter | undefined): void;
|
|
51
67
|
flush(): Promise<void>;
|
|
52
68
|
};
|
|
53
|
-
type
|
|
54
|
-
methods:
|
|
69
|
+
type Unstable_InteractablesClientSchema = {
|
|
70
|
+
methods: Unstable_InteractablesMethods;
|
|
55
71
|
};
|
|
56
72
|
//#endregion
|
|
57
|
-
export {
|
|
73
|
+
export { Unstable_InteractableDefinition, Unstable_InteractablePersistedState, Unstable_InteractablePersistenceAdapter, Unstable_InteractablePersistenceStatus, Unstable_InteractableRegistration, Unstable_InteractableStateSchema, Unstable_InteractablesClientSchema, Unstable_InteractablesConfig, Unstable_InteractablesMethods, Unstable_InteractablesState };
|
|
58
74
|
//# sourceMappingURL=interactables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactables.d.ts","names":[],"sources":["../../../../src/react/types/scopes/interactables.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"interactables.d.ts","names":[],"sources":["../../../../src/react/types/scopes/interactables.ts"],"mappings":";;;;;;;;AAQA;KAAY,gCAAA,GAAmC,WAAA,CAC7C,OAAA,CAAQ,IAAA;EAAQ,UAAA;AAAA;AAAA,KAGb,iBAAA;AAAA,KAEO,+BAAA;EACV,EAAA;EACA,IAAA;EACA,WAAA;EACA,WAAA,EAAa,gCAAA;EACb,KAAA;EACA,YAAA;EACA,KAAA,GAAQ,iBAAiB;AAAA;AAAA,KAGf,iCAAA;EACV,EAAA;EACA,IAAA;EACA,WAAA;EACA,WAAA,EAAa,gCAAA;EACb,YAAA;EAfyC;;;;;EAqBzC,YAAA,GAAe,4BAA4B;AAAA;AAAA,KAGjC,sCAAA;EACV,SAAA;EACA,KAAK;AAAA;AAAA,KAGK,2BAAA;EAtBe,2BAwBzB,WAAA,EAAa,MAAA,SAAe,+BAAA,GArBlB;EAuBV,WAAA,EAAa,MAAA,SAAe,sCAAA;AAAA;AAAA,KAGlB,mCAAA,GAAsC,MAAM;EAEpD,IAAA;EAAc,KAAA;AAAA;AAAA,KAGN,uCAAA;EACV,IAAA,CAAK,KAAA,EAAO,mCAAA,UAA6C,OAAA;EA3BzD;;;;AAM2C;EA2B3C,IAAA,KACI,mCAAA,sBAGA,OAAA,CAAQ,mCAAA;AAAA;AAAA,KAGF,4BAAA;EACV,WAAA,GAAc,uCAAuC;AAAA;AAAA,KAG3C,6BAAA;EACV,QAAA,IAAY,2BAAA;EACZ,QAAA,CAAS,GAAA,EAAK,iCAAA,GAAoC,WAAA;EAClD,QAAA,CAAS,EAAA,UAAY,OAAA,GAAU,IAAA;EAC/B,WAAA,IAAe,mCAAA;EACf,WAAA,CAAY,KAAA,EAAO,mCAAA;EACnB,qBAAA,CACE,OAAA,EAAS,uCAAA;EAEX,KAAA,IAAS,OAAA;AAAA;AAAA,KAGC,kCAAA;EACV,OAAA,EAAS,6BAA6B;AAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Unstable_InteractablesClientSchema } from "./scopes/interactables.js";
|
|
1
2
|
import { ToolsClientSchema } from "./scopes/tools.js";
|
|
2
|
-
import { InteractablesClientSchema } from "
|
|
3
|
+
import { InteractablesClientSchema } from "../interactables-legacy/scopes.js";
|
|
3
4
|
import { DataRenderersClientSchema } from "./scopes/dataRenderers.js";
|
|
4
5
|
|
|
5
6
|
//#region src/react/types/store-augmentation.d.ts
|
|
@@ -8,6 +9,7 @@ declare module "@assistant-ui/store" {
|
|
|
8
9
|
tools: ToolsClientSchema;
|
|
9
10
|
dataRenderers: DataRenderersClientSchema;
|
|
10
11
|
interactables: InteractablesClientSchema;
|
|
12
|
+
unstable_interactables: Unstable_InteractablesClientSchema;
|
|
11
13
|
}
|
|
12
14
|
} //# sourceMappingURL=store-augmentation.d.ts.map
|
|
13
15
|
//# sourceMappingURL=store-augmentation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-augmentation.d.ts","names":[],"sources":["../../../src/react/types/store-augmentation.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"store-augmentation.d.ts","names":[],"sources":["../../../src/react/types/store-augmentation.ts"],"mappings":";;;;;;;YAMY,aAAA;IACR,KAAA,EAAO,iBAAA;IACP,aAAA,EAAe,yBAAA;IACf,aAAA,EAAe,yBAAA;IACf,sBAAA,EAAwB,kCAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/react/utils/useJSONEqual.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Like `useShallow`, but with JSON deep-equality. Use when a selector derives an
|
|
4
|
+
* equal-but-fresh value on every store update — e.g. folding over
|
|
5
|
+
* `thread.messages`, whose identity changes on every streaming token — where a
|
|
6
|
+
* shallow compare would re-render regardless.
|
|
7
|
+
*/
|
|
8
|
+
declare function useJSONEqual<S, U>(selector: (state: S) => U): (state: S) => U;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useJSONEqual };
|
|
11
|
+
//# sourceMappingURL=useJSONEqual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useJSONEqual.d.ts","names":[],"sources":["../../../src/react/utils/useJSONEqual.ts"],"mappings":";;AASA;;;;;iBAAgB,YAAA,OAAmB,QAAA,GAAW,KAAA,EAAO,CAAA,KAAM,CAAA,IAAK,KAAA,EAAO,CAAA,KAAM,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isJSONValueEqual } from "../../utils/json/is-json-equal.js";
|
|
2
|
+
import { useRef } from "@assistant-ui/tap/react-shim";
|
|
3
|
+
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
|
+
//#region src/react/utils/useJSONEqual.ts
|
|
5
|
+
/**
|
|
6
|
+
* Like `useShallow`, but with JSON deep-equality. Use when a selector derives an
|
|
7
|
+
* equal-but-fresh value on every store update — e.g. folding over
|
|
8
|
+
* `thread.messages`, whose identity changes on every streaming token — where a
|
|
9
|
+
* shallow compare would re-render regardless.
|
|
10
|
+
*/
|
|
11
|
+
function useJSONEqual(selector) {
|
|
12
|
+
const $ = c(2);
|
|
13
|
+
const prev = useRef(void 0);
|
|
14
|
+
let t0;
|
|
15
|
+
if ($[0] !== selector) {
|
|
16
|
+
t0 = (state) => {
|
|
17
|
+
const next = selector(state);
|
|
18
|
+
if (prev.current !== void 0 && isJSONValueEqual(prev.current, next)) return prev.current;
|
|
19
|
+
prev.current = next;
|
|
20
|
+
return next;
|
|
21
|
+
};
|
|
22
|
+
$[0] = selector;
|
|
23
|
+
$[1] = t0;
|
|
24
|
+
} else t0 = $[1];
|
|
25
|
+
return t0;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { useJSONEqual };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=useJSONEqual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useJSONEqual.js","names":["useRef","isJSONValueEqual","useJSONEqual","selector","$","_c","prev","undefined","t0","state","next","current"],"sources":["../../../src/react/utils/useJSONEqual.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { isJSONValueEqual } from \"../../utils/json/is-json-equal\";\n\n/**\n * Like `useShallow`, but with JSON deep-equality. Use when a selector derives an\n * equal-but-fresh value on every store update — e.g. folding over\n * `thread.messages`, whose identity changes on every streaming token — where a\n * shallow compare would re-render regardless.\n */\nexport function useJSONEqual<S, U>(selector: (state: S) => U): (state: S) => U {\n const prev = useRef<U | undefined>(undefined);\n return (state) => {\n const next = selector(state);\n if (prev.current !== undefined && isJSONValueEqual(prev.current, next)) {\n return prev.current;\n }\n prev.current = next;\n return next;\n };\n}\n"],"mappings":";;;;;;;;;;AASA,SAAOE,aAAAC,UAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACL,MAAAC,OAAaN,OAAsBO,KAAAA,CAAS;CAAE,IAAAC;CAAA,IAAAJ,EAAA,OAAAD,UAAA;EACvCK,MAAAC,UAAA;GACL,MAAAC,OAAaP,SAASM,KAAK;GAC3B,IAAIH,KAAIK,YAAaJ,KAAAA,KAAaN,iBAAiBK,KAAIK,SAAUD,IAAI,GAAC,OAC7DJ,KAAIK;GAEbL,KAAIK,UAAWD;GAAH,OACLA;EAAI;EACZN,EAAA,KAAAD;EAAAC,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,OAPMI;AAON"}
|
|
@@ -12,6 +12,11 @@ declare abstract class BaseComposerRuntimeCore extends BaseSubscribable implemen
|
|
|
12
12
|
readonly isEditing = true;
|
|
13
13
|
protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;
|
|
14
14
|
protected abstract getDictationAdapter(): DictationAdapter | undefined;
|
|
15
|
+
protected enrichWithComposerMetadata<T extends {
|
|
16
|
+
metadata?: {
|
|
17
|
+
custom?: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
}>(message: T, composerMetadata: Record<string, unknown> | undefined): T;
|
|
15
20
|
get attachmentAccept(): string;
|
|
16
21
|
private _attachments;
|
|
17
22
|
get attachments(): readonly Attachment[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"mappings":";;;;;;;;;;uBAkCsB,uBAAA,SACZ,gBAAA,YACG,mBAAA;EAAA,SAEK,SAAA;EAAA,mBAEG,oBAAA,IAAwB,iBAAA;EAAA,mBACxB,mBAAA,IAAuB,gBAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"base-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"mappings":";;;;;;;;;;uBAkCsB,uBAAA,SACZ,gBAAA,YACG,mBAAA;EAAA,SAEK,SAAA;EAAA,mBAEG,oBAAA,IAAwB,iBAAA;EAAA,mBACxB,mBAAA,IAAuB,gBAAA;EAAA,UAEhC,0BAAA;IACI,QAAA;MAAa,MAAA,GAAS,MAAA;IAAA;EAAA,GAClC,OAAA,EAAS,CAAA,EAAG,gBAAA,EAAkB,MAAA,gCAAsC,CAAA;EAAA,IAW3D,gBAAA;EAAA,QAIH,YAAA;EAAA,IACG,WAAA,aAAW,UAAA;EAAA,UAIZ,cAAA,CAAe,KAAA,WAAgB,UAAA;EAAA,aAKrB,SAAA;EAAA,aACA,OAAA;EAAA,IAET,OAAA;EAAA,QAIH,KAAA;EAAA,IAEJ,IAAA;EAAA,QAII,KAAA;EAAA,IAEJ,IAAA;EAAA,QAII,UAAA;EAAA,IAEJ,SAAA,IAAS,SAAA;EAAA,QAIL,MAAA;EAAA,IAEJ,KAAA,IAAK,SAAA;EAIF,QAAA,CAAS,KAAA,EAAO,SAAA;EAOhB,OAAA,CAAQ,KAAA;EAaR,OAAA,CAAQ,IAAA,EAAM,WAAA;EAOd,YAAA,CAAa,SAAA,EAAW,SAAA;EAAA,QAOvB,wBAAA;EAAA,QAMM,mBAAA;EAQD,KAAA,IAAK,OAAA;EAoBL,gBAAA,IAAgB,OAAA;EAOhB,IAAA,CAAK,OAAA,GAAU,WAAA,GAAW,OAAA;EAuChC,MAAA;EAAA,IAII,KAAA,aAAkB,cAAA;EAItB,cAAA,CAAe,YAAA;EACf,eAAA,CAAgB,YAAA;EAAA,mBAEJ,UAAA,CACjB,OAAA,EAAS,IAAA,CAAK,aAAA,4BACd,OAAA,GAAU,WAAA;EAAA,mBAEO,YAAA;EAEb,aAAA,CAAc,gBAAA,EAAkB,IAAA,GAAO,gBAAA,GAAgB,OAAA;EAAA,QAqHrD,2BAAA;EAqBF,gBAAA,CAAiB,YAAA,WAAoB,OAAA;EAAA,QAenC,UAAA;EAAA,QACA,iBAAA;EAAA,QACA,sBAAA;EAAA,QACA,kBAAA;EAAA,QACA,mBAAA;EAAA,QACA,0BAAA;EAAA,QACA,yBAAA;EAAA,QACA,oBAAA;EAAA,IAEG,SAAA,IAAa,cAAA;EAAA,QAIhB,gBAAA;EAUD,cAAA;EA6FA,aAAA;EAAA,QAUC,iBAAA;EAAA,QAuBA,iBAAA;EAAA,UAKE,uBAAA,WAAkC,wBAAA,EAC1C,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,2BAAA,CAA4B,CAAA;EAQhC,WAAA,WAAsB,wBAAA,EAC3B,KAAA,EAAO,CAAA,EACP,QAAA,EAAU,4BAAA,CAA6B,CAAA;AAAA"}
|
|
@@ -6,6 +6,19 @@ import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
|
6
6
|
const isAttachmentComplete = (a) => a.status.type === "complete";
|
|
7
7
|
var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
8
8
|
isEditing = true;
|
|
9
|
+
enrichWithComposerMetadata(message, composerMetadata) {
|
|
10
|
+
if (!composerMetadata) return message;
|
|
11
|
+
return {
|
|
12
|
+
...message,
|
|
13
|
+
metadata: {
|
|
14
|
+
...message.metadata,
|
|
15
|
+
custom: {
|
|
16
|
+
...message.metadata?.custom,
|
|
17
|
+
...composerMetadata
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
9
22
|
get attachmentAccept() {
|
|
10
23
|
return this.getAttachmentAdapter()?.accept ?? "*";
|
|
11
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-composer-runtime-core.js","names":["Attachment","CompleteAttachment","CreateAttachment","PendingAttachment","MessageRole","AppendMessage","QuoteInfo","Unsubscribe","RunConfig","BaseSubscribable","AttachmentAdapter","fileMatchesAccept","AttachmentAddErrorReason","ComposerRuntimeCore","ComposerRuntimeEventCallback","ComposerRuntimeEventPayload","ComposerRuntimeEventType","DictationState","SendOptions","DictationAdapter","EMPTY_QUEUE_ITEMS","QueueItemState","generateId","isAttachmentComplete","a","status","type","BaseComposerRuntimeCore","isEditing","getAttachmentAdapter","getDictationAdapter","attachmentAccept","accept","_attachments","attachments","setAttachments","value","_notifySubscribers","canCancel","canSend","isEmpty","text","trim","length","_text","_role","role","_runConfig","runConfig","_quote","undefined","quote","setQuote","setText","_dictation","_dictationBaseText","_currentInterimText","inputDisabled","setRole","setRunConfig","_emptyTextAndAttachments","_onClearAttachments","adapter","pending","filter","Promise","all","map","remove","reset","Object","keys","task","clearAttachments","send","options","_dictationSession","cancel","_cleanupDictation","Error","result","message","Omit","createdAt","Date","content","metadata","custom","handleSend","_notifyEventSubscribers","handleCancel","queue","steerQueueItem","_queueItemId","removeQueueItem","addAttachment","fileOrAttachment","File","name","contentType","err","_safeEmitAttachmentAddError","id","upsertAttachment","idx","findIndex","attachment","slice","lastAttachment","promiseOrGenerator","add","file","Symbol","asyncIterator","r","e","reason","String","hasError","attachmentId","error","subscriberError","console","removeAttachment","index","Session","_dictationUnsubscribes","_dictationSessionIdCounter","_activeDictationSessionId","_isCleaningDictation","dictation","_isActiveSession","sessionId","session","startDictation","unsub","oldSession","stop","catch","disableInputDuringDictation","listen","unsubSpeech","onSpeech","isFinal","needsSeparator","endsWith","transcript","separator","_","rest","push","unsubStart","onSpeechStart","unsubEnd","onSpeechEnd","statusInterval","setInterval","clearInterval","stopDictation","finally","isStaleSession","_eventSubscribers","Map","Set","payload","event","E","subscribers","get","callback","unstable_on","wrapped","set","delete"],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"sourcesContent":["import type {\n Attachment,\n CompleteAttachment,\n CreateAttachment,\n PendingAttachment,\n} from \"../../types/attachment\";\nimport type { MessageRole, AppendMessage } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport {\n type AttachmentAdapter,\n fileMatchesAccept,\n} from \"../../adapters/attachment\";\nimport type {\n AttachmentAddErrorReason,\n ComposerRuntimeCore,\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventPayload,\n ComposerRuntimeEventType,\n DictationState,\n SendOptions,\n} from \"../interfaces/composer-runtime-core\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\nimport { generateId } from \"../../utils/id\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n protected abstract getDictationAdapter(): DictationAdapter | undefined;\n\n public get attachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n public abstract get canSend(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n private _quote: QuoteInfo | undefined = undefined;\n\n get quote() {\n return this._quote;\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n if (this._quote === quote) return;\n\n this._quote = quote;\n this._notifySubscribers();\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n if (this._dictation) {\n this._dictationBaseText = value;\n this._currentInterimText = \"\";\n const { status, inputDisabled } = this._dictation;\n this._dictation = inputDisabled ? { status, inputDisabled } : { status };\n }\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n const pending = this._attachments.filter((a) => !isAttachmentComplete(a));\n await Promise.all(pending.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0 &&\n this._quote === undefined\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n this._quote = undefined;\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send(options?: SendOptions) {\n if (!this.canSend) return;\n\n if (this._dictationSession) {\n this._dictationSession.cancel();\n this._cleanupDictation();\n }\n\n const adapter = this.getAttachmentAdapter();\n const attachments =\n this.attachments.length > 0\n ? Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n if (!adapter) throw new Error(\"Attachments are not supported\");\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const text = this.text;\n const quote = this._quote;\n this._quote = undefined;\n this._emptyTextAndAttachments();\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n createdAt: new Date(),\n role: this.role,\n content: text ? [{ type: \"text\", text }] : [],\n attachments: await attachments,\n runConfig: this.runConfig,\n metadata: { custom: { ...(quote ? { quote } : {}) } },\n };\n\n this.handleSend(message, options);\n this._notifyEventSubscribers(\"send\", {});\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n public get queue(): readonly QueueItemState[] {\n return EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(_queueItemId: string): void {}\n public removeQueueItem(_queueItemId: string): void {}\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(fileOrAttachment: File | CreateAttachment) {\n if (!(fileOrAttachment instanceof File)) {\n const adapter = this.getAttachmentAdapter();\n if (\n adapter &&\n !fileMatchesAccept(\n {\n name: fileOrAttachment.name,\n type: fileOrAttachment.contentType ?? \"\",\n },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.contentType || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\n \"not-accepted\",\n message,\n undefined,\n err,\n );\n throw err;\n }\n\n const a: CompleteAttachment = {\n id: fileOrAttachment.id ?? generateId(),\n type: fileOrAttachment.type ?? \"document\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.contentType,\n content: fileOrAttachment.content,\n status: { type: \"complete\" },\n };\n this._attachments = [...this._attachments, a];\n this._notifySubscribers();\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n return;\n }\n\n const upsertAttachment = (a: PendingAttachment) => {\n const idx = this._attachments.findIndex(\n (attachment) => attachment.id === a.id,\n );\n if (idx !== -1)\n this._attachments = [\n ...this._attachments.slice(0, idx),\n a,\n ...this._attachments.slice(idx + 1),\n ];\n else {\n this._attachments = [...this._attachments, a];\n }\n\n this._notifySubscribers();\n };\n\n const adapter = this.getAttachmentAdapter();\n if (!adapter) {\n const message = \"Attachments are not supported\";\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"no-adapter\", message, undefined, err);\n throw err;\n }\n\n if (\n !fileMatchesAccept(\n { name: fileOrAttachment.name, type: fileOrAttachment.type },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.type || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"not-accepted\", message, undefined, err);\n throw err;\n }\n\n let lastAttachment: PendingAttachment | undefined;\n try {\n const promiseOrGenerator = adapter.add({ file: fileOrAttachment });\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n lastAttachment = r;\n upsertAttachment(r);\n }\n } else {\n lastAttachment = await promiseOrGenerator;\n upsertAttachment(lastAttachment);\n }\n } catch (e) {\n if (lastAttachment) {\n upsertAttachment({\n ...lastAttachment,\n status: { type: \"incomplete\", reason: \"error\" },\n });\n }\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n e instanceof Error ? e.message : String(e),\n lastAttachment?.id,\n e instanceof Error ? e : undefined,\n );\n throw e;\n }\n\n const hasError =\n lastAttachment?.status.type === \"incomplete\" &&\n lastAttachment.status.reason === \"error\";\n if (hasError) {\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n \"Attachment upload did not complete successfully.\",\n lastAttachment?.id,\n );\n } else {\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n }\n }\n\n private _safeEmitAttachmentAddError(\n reason: AttachmentAddErrorReason,\n message: string,\n attachmentId?: string,\n error?: Error,\n ) {\n try {\n this._notifyEventSubscribers(\"attachmentAddError\", {\n reason,\n message,\n ...(attachmentId !== undefined && { attachmentId }),\n ...(error !== undefined && { error }),\n });\n } catch (subscriberError) {\n console.error(\n \"[assistant-ui] attachmentAddError subscriber threw:\",\n subscriberError,\n );\n }\n }\n\n async removeAttachment(attachmentId: string) {\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n if (!isAttachmentComplete(attachment)) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n await adapter.remove(attachment);\n }\n\n this._attachments = this._attachments.filter((a) => a.id !== attachmentId);\n this._notifySubscribers();\n }\n\n private _dictation: DictationState | undefined;\n private _dictationSession: DictationAdapter.Session | undefined;\n private _dictationUnsubscribes: Unsubscribe[] = [];\n private _dictationBaseText = \"\";\n private _currentInterimText = \"\";\n private _dictationSessionIdCounter = 0;\n private _activeDictationSessionId: number | undefined;\n private _isCleaningDictation = false;\n\n public get dictation(): DictationState | undefined {\n return this._dictation;\n }\n\n private _isActiveSession(\n sessionId: number,\n session: DictationAdapter.Session,\n ): boolean {\n return (\n this._activeDictationSessionId === sessionId &&\n this._dictationSession === session\n );\n }\n\n public startDictation(): void {\n const adapter = this.getDictationAdapter();\n if (!adapter) {\n throw new Error(\"Dictation adapter not configured\");\n }\n\n if (this._dictationSession) {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n const oldSession = this._dictationSession;\n oldSession.stop().catch(() => {});\n this._dictationSession = undefined;\n }\n\n const inputDisabled = adapter.disableInputDuringDictation ?? false;\n\n this._dictationBaseText = this._text;\n this._currentInterimText = \"\";\n\n const session = adapter.listen();\n this._dictationSession = session;\n const sessionId = ++this._dictationSessionIdCounter;\n this._activeDictationSessionId = sessionId;\n this._dictation = { status: session.status, inputDisabled };\n this._notifySubscribers();\n\n const unsubSpeech = session.onSpeech((result) => {\n if (!this._isActiveSession(sessionId, session)) return;\n const isFinal = result.isFinal !== false;\n\n const needsSeparator =\n this._dictationBaseText &&\n !this._dictationBaseText.endsWith(\" \") &&\n result.transcript;\n const separator = needsSeparator ? \" \" : \"\";\n\n if (isFinal) {\n this._dictationBaseText =\n this._dictationBaseText + separator + result.transcript;\n this._currentInterimText = \"\";\n this._text = this._dictationBaseText;\n\n if (this._dictation) {\n const { transcript: _, ...rest } = this._dictation;\n this._dictation = rest;\n }\n this._notifySubscribers();\n } else {\n this._currentInterimText = separator + result.transcript;\n this._text = this._dictationBaseText + this._currentInterimText;\n\n if (this._dictation) {\n this._dictation = {\n ...this._dictation,\n transcript: result.transcript,\n };\n }\n this._notifySubscribers();\n }\n });\n this._dictationUnsubscribes.push(unsubSpeech);\n\n const unsubStart = session.onSpeechStart(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n this._dictation = {\n status: { type: \"running\" },\n inputDisabled,\n ...(this._dictation?.transcript && {\n transcript: this._dictation.transcript,\n }),\n };\n this._notifySubscribers();\n });\n this._dictationUnsubscribes.push(unsubStart);\n\n const unsubEnd = session.onSpeechEnd(() => {\n this._cleanupDictation({ sessionId });\n });\n this._dictationUnsubscribes.push(unsubEnd);\n\n const statusInterval = setInterval(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n if (session.status.type === \"ended\") {\n this._cleanupDictation({ sessionId });\n }\n }, 100);\n this._dictationUnsubscribes.push(() => clearInterval(statusInterval));\n }\n\n public stopDictation(): void {\n if (!this._dictationSession) return;\n\n const session = this._dictationSession;\n const sessionId = this._activeDictationSessionId;\n session.stop().finally(() => {\n this._cleanupDictation({ sessionId });\n });\n }\n\n private _cleanupDictation(options?: { sessionId: number | undefined }): void {\n const isStaleSession =\n options?.sessionId !== undefined &&\n options.sessionId !== this._activeDictationSessionId;\n if (isStaleSession || this._isCleaningDictation) return;\n\n this._isCleaningDictation = true;\n try {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n this._dictationSession = undefined;\n this._activeDictationSessionId = undefined;\n this._dictation = undefined;\n this._dictationBaseText = \"\";\n this._currentInterimText = \"\";\n this._notifySubscribers();\n } finally {\n this._isCleaningDictation = false;\n }\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<(payload?: unknown) => void>\n >();\n\n protected _notifyEventSubscribers<E extends ComposerRuntimeEventType>(\n event: E,\n payload: ComposerRuntimeEventPayload[E],\n ) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback(payload);\n }\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ) {\n const wrapped = callback as (payload?: unknown) => void;\n let subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n subscribers = new Set();\n this._eventSubscribers.set(event, subscribers);\n }\n subscribers.add(wrapped);\n\n return () => {\n this._eventSubscribers.get(event)?.delete(wrapped);\n };\n }\n}\n"],"mappings":";;;;;AA+BA,MAAMuB,wBAAwBC,MAC5BA,EAAEC,OAAOC,SAAS;AAEpB,IAAsBC,0BAAtB,cACUlB,iBAEV;CACE,YAA4B;CAK5B,IAAWsB,mBAA2B;EACpC,OAAO,KAAKF,qBAAqB,CAAC,EAAEG,UAAU;CAChD;CAEA,eAA8C,CAAA;CAC9C,IAAWE,cAAc;EACvB,OAAO,KAAKD;CACd;CAEA,eAAyBG,OAA8B;EACrD,KAAKH,eAAeG;EACpB,KAAKC,mBAAmB;CAC1B;CAKA,IAAWG,UAAU;EACnB,OAAO,CAAC,KAAKC,KAAKC,KAAK,KAAK,CAAC,KAAKR,YAAYS;CAChD;CAEA,QAAgB;CAEhB,IAAIF,OAAO;EACT,OAAO,KAAKG;CACd;CAEA,QAA6B;CAE7B,IAAIE,OAAO;EACT,OAAO,KAAK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,cAAc,KAAKN,kBAAkBO,IAAIH,KAAK;EACpD,IAAI,CAACE,aAAa;EAElB,KAAK,MAAME,YAAYF,aAAaE,SAASL,OAAO;CACtD;CAEA,YACEC,OACAI,UACA;EACA,MAAME,UAAUF;EAChB,IAAIF,cAAc,KAAKN,kBAAkBO,IAAIH,KAAK;EAClD,IAAI,CAACE,aAAa;GAChBA,8BAAc,IAAIJ,IAAI;GACtB,KAAKF,kBAAkBW,IAAIP,OAAOE,WAAW;EAC/C;EACAA,YAAYzD,IAAI6D,OAAO;EAEvB,aAAa;GACX,KAAKV,kBAAkBO,IAAIH,KAAK,CAAC,EAAEQ,OAAOF,OAAO;EACnD;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"base-composer-runtime-core.js","names":["Attachment","CompleteAttachment","CreateAttachment","PendingAttachment","MessageRole","AppendMessage","QuoteInfo","Unsubscribe","RunConfig","BaseSubscribable","AttachmentAdapter","fileMatchesAccept","AttachmentAddErrorReason","ComposerRuntimeCore","ComposerRuntimeEventCallback","ComposerRuntimeEventPayload","ComposerRuntimeEventType","DictationState","SendOptions","DictationAdapter","EMPTY_QUEUE_ITEMS","QueueItemState","generateId","isAttachmentComplete","a","status","type","BaseComposerRuntimeCore","isEditing","getAttachmentAdapter","getDictationAdapter","enrichWithComposerMetadata","metadata","custom","Record","message","T","composerMetadata","attachmentAccept","accept","_attachments","attachments","setAttachments","value","_notifySubscribers","canCancel","canSend","isEmpty","text","trim","length","_text","_role","role","_runConfig","runConfig","_quote","undefined","quote","setQuote","setText","_dictation","_dictationBaseText","_currentInterimText","inputDisabled","setRole","setRunConfig","_emptyTextAndAttachments","_onClearAttachments","adapter","pending","filter","Promise","all","map","remove","reset","Object","keys","task","clearAttachments","send","options","_dictationSession","cancel","_cleanupDictation","Error","result","Omit","createdAt","Date","content","handleSend","_notifyEventSubscribers","handleCancel","queue","steerQueueItem","_queueItemId","removeQueueItem","addAttachment","fileOrAttachment","File","name","contentType","err","_safeEmitAttachmentAddError","id","upsertAttachment","idx","findIndex","attachment","slice","lastAttachment","promiseOrGenerator","add","file","Symbol","asyncIterator","r","e","reason","String","hasError","attachmentId","error","subscriberError","console","removeAttachment","index","Session","_dictationUnsubscribes","_dictationSessionIdCounter","_activeDictationSessionId","_isCleaningDictation","dictation","_isActiveSession","sessionId","session","startDictation","unsub","oldSession","stop","catch","disableInputDuringDictation","listen","unsubSpeech","onSpeech","isFinal","needsSeparator","endsWith","transcript","separator","_","rest","push","unsubStart","onSpeechStart","unsubEnd","onSpeechEnd","statusInterval","setInterval","clearInterval","stopDictation","finally","isStaleSession","_eventSubscribers","Map","Set","payload","event","E","subscribers","get","callback","unstable_on","wrapped","set","delete"],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"sourcesContent":["import type {\n Attachment,\n CompleteAttachment,\n CreateAttachment,\n PendingAttachment,\n} from \"../../types/attachment\";\nimport type { MessageRole, AppendMessage } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport {\n type AttachmentAdapter,\n fileMatchesAccept,\n} from \"../../adapters/attachment\";\nimport type {\n AttachmentAddErrorReason,\n ComposerRuntimeCore,\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventPayload,\n ComposerRuntimeEventType,\n DictationState,\n SendOptions,\n} from \"../interfaces/composer-runtime-core\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\nimport { generateId } from \"../../utils/id\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n protected abstract getDictationAdapter(): DictationAdapter | undefined;\n\n protected enrichWithComposerMetadata<\n T extends { metadata?: { custom?: Record<string, unknown> } },\n >(message: T, composerMetadata: Record<string, unknown> | undefined): T {\n if (!composerMetadata) return message;\n return {\n ...message,\n metadata: {\n ...message.metadata,\n custom: { ...message.metadata?.custom, ...composerMetadata },\n },\n } as T;\n }\n\n public get attachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n public abstract get canSend(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n private _quote: QuoteInfo | undefined = undefined;\n\n get quote() {\n return this._quote;\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n if (this._quote === quote) return;\n\n this._quote = quote;\n this._notifySubscribers();\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n if (this._dictation) {\n this._dictationBaseText = value;\n this._currentInterimText = \"\";\n const { status, inputDisabled } = this._dictation;\n this._dictation = inputDisabled ? { status, inputDisabled } : { status };\n }\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n const pending = this._attachments.filter((a) => !isAttachmentComplete(a));\n await Promise.all(pending.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0 &&\n this._quote === undefined\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n this._quote = undefined;\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send(options?: SendOptions) {\n if (!this.canSend) return;\n\n if (this._dictationSession) {\n this._dictationSession.cancel();\n this._cleanupDictation();\n }\n\n const adapter = this.getAttachmentAdapter();\n const attachments =\n this.attachments.length > 0\n ? Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n if (!adapter) throw new Error(\"Attachments are not supported\");\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const text = this.text;\n const quote = this._quote;\n this._quote = undefined;\n this._emptyTextAndAttachments();\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n createdAt: new Date(),\n role: this.role,\n content: text ? [{ type: \"text\", text }] : [],\n attachments: await attachments,\n runConfig: this.runConfig,\n metadata: { custom: { ...(quote ? { quote } : {}) } },\n };\n\n this.handleSend(message, options);\n this._notifyEventSubscribers(\"send\", {});\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n public get queue(): readonly QueueItemState[] {\n return EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(_queueItemId: string): void {}\n public removeQueueItem(_queueItemId: string): void {}\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(fileOrAttachment: File | CreateAttachment) {\n if (!(fileOrAttachment instanceof File)) {\n const adapter = this.getAttachmentAdapter();\n if (\n adapter &&\n !fileMatchesAccept(\n {\n name: fileOrAttachment.name,\n type: fileOrAttachment.contentType ?? \"\",\n },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.contentType || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\n \"not-accepted\",\n message,\n undefined,\n err,\n );\n throw err;\n }\n\n const a: CompleteAttachment = {\n id: fileOrAttachment.id ?? generateId(),\n type: fileOrAttachment.type ?? \"document\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.contentType,\n content: fileOrAttachment.content,\n status: { type: \"complete\" },\n };\n this._attachments = [...this._attachments, a];\n this._notifySubscribers();\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n return;\n }\n\n const upsertAttachment = (a: PendingAttachment) => {\n const idx = this._attachments.findIndex(\n (attachment) => attachment.id === a.id,\n );\n if (idx !== -1)\n this._attachments = [\n ...this._attachments.slice(0, idx),\n a,\n ...this._attachments.slice(idx + 1),\n ];\n else {\n this._attachments = [...this._attachments, a];\n }\n\n this._notifySubscribers();\n };\n\n const adapter = this.getAttachmentAdapter();\n if (!adapter) {\n const message = \"Attachments are not supported\";\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"no-adapter\", message, undefined, err);\n throw err;\n }\n\n if (\n !fileMatchesAccept(\n { name: fileOrAttachment.name, type: fileOrAttachment.type },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.type || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"not-accepted\", message, undefined, err);\n throw err;\n }\n\n let lastAttachment: PendingAttachment | undefined;\n try {\n const promiseOrGenerator = adapter.add({ file: fileOrAttachment });\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n lastAttachment = r;\n upsertAttachment(r);\n }\n } else {\n lastAttachment = await promiseOrGenerator;\n upsertAttachment(lastAttachment);\n }\n } catch (e) {\n if (lastAttachment) {\n upsertAttachment({\n ...lastAttachment,\n status: { type: \"incomplete\", reason: \"error\" },\n });\n }\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n e instanceof Error ? e.message : String(e),\n lastAttachment?.id,\n e instanceof Error ? e : undefined,\n );\n throw e;\n }\n\n const hasError =\n lastAttachment?.status.type === \"incomplete\" &&\n lastAttachment.status.reason === \"error\";\n if (hasError) {\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n \"Attachment upload did not complete successfully.\",\n lastAttachment?.id,\n );\n } else {\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n }\n }\n\n private _safeEmitAttachmentAddError(\n reason: AttachmentAddErrorReason,\n message: string,\n attachmentId?: string,\n error?: Error,\n ) {\n try {\n this._notifyEventSubscribers(\"attachmentAddError\", {\n reason,\n message,\n ...(attachmentId !== undefined && { attachmentId }),\n ...(error !== undefined && { error }),\n });\n } catch (subscriberError) {\n console.error(\n \"[assistant-ui] attachmentAddError subscriber threw:\",\n subscriberError,\n );\n }\n }\n\n async removeAttachment(attachmentId: string) {\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n if (!isAttachmentComplete(attachment)) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n await adapter.remove(attachment);\n }\n\n this._attachments = this._attachments.filter((a) => a.id !== attachmentId);\n this._notifySubscribers();\n }\n\n private _dictation: DictationState | undefined;\n private _dictationSession: DictationAdapter.Session | undefined;\n private _dictationUnsubscribes: Unsubscribe[] = [];\n private _dictationBaseText = \"\";\n private _currentInterimText = \"\";\n private _dictationSessionIdCounter = 0;\n private _activeDictationSessionId: number | undefined;\n private _isCleaningDictation = false;\n\n public get dictation(): DictationState | undefined {\n return this._dictation;\n }\n\n private _isActiveSession(\n sessionId: number,\n session: DictationAdapter.Session,\n ): boolean {\n return (\n this._activeDictationSessionId === sessionId &&\n this._dictationSession === session\n );\n }\n\n public startDictation(): void {\n const adapter = this.getDictationAdapter();\n if (!adapter) {\n throw new Error(\"Dictation adapter not configured\");\n }\n\n if (this._dictationSession) {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n const oldSession = this._dictationSession;\n oldSession.stop().catch(() => {});\n this._dictationSession = undefined;\n }\n\n const inputDisabled = adapter.disableInputDuringDictation ?? false;\n\n this._dictationBaseText = this._text;\n this._currentInterimText = \"\";\n\n const session = adapter.listen();\n this._dictationSession = session;\n const sessionId = ++this._dictationSessionIdCounter;\n this._activeDictationSessionId = sessionId;\n this._dictation = { status: session.status, inputDisabled };\n this._notifySubscribers();\n\n const unsubSpeech = session.onSpeech((result) => {\n if (!this._isActiveSession(sessionId, session)) return;\n const isFinal = result.isFinal !== false;\n\n const needsSeparator =\n this._dictationBaseText &&\n !this._dictationBaseText.endsWith(\" \") &&\n result.transcript;\n const separator = needsSeparator ? \" \" : \"\";\n\n if (isFinal) {\n this._dictationBaseText =\n this._dictationBaseText + separator + result.transcript;\n this._currentInterimText = \"\";\n this._text = this._dictationBaseText;\n\n if (this._dictation) {\n const { transcript: _, ...rest } = this._dictation;\n this._dictation = rest;\n }\n this._notifySubscribers();\n } else {\n this._currentInterimText = separator + result.transcript;\n this._text = this._dictationBaseText + this._currentInterimText;\n\n if (this._dictation) {\n this._dictation = {\n ...this._dictation,\n transcript: result.transcript,\n };\n }\n this._notifySubscribers();\n }\n });\n this._dictationUnsubscribes.push(unsubSpeech);\n\n const unsubStart = session.onSpeechStart(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n this._dictation = {\n status: { type: \"running\" },\n inputDisabled,\n ...(this._dictation?.transcript && {\n transcript: this._dictation.transcript,\n }),\n };\n this._notifySubscribers();\n });\n this._dictationUnsubscribes.push(unsubStart);\n\n const unsubEnd = session.onSpeechEnd(() => {\n this._cleanupDictation({ sessionId });\n });\n this._dictationUnsubscribes.push(unsubEnd);\n\n const statusInterval = setInterval(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n if (session.status.type === \"ended\") {\n this._cleanupDictation({ sessionId });\n }\n }, 100);\n this._dictationUnsubscribes.push(() => clearInterval(statusInterval));\n }\n\n public stopDictation(): void {\n if (!this._dictationSession) return;\n\n const session = this._dictationSession;\n const sessionId = this._activeDictationSessionId;\n session.stop().finally(() => {\n this._cleanupDictation({ sessionId });\n });\n }\n\n private _cleanupDictation(options?: { sessionId: number | undefined }): void {\n const isStaleSession =\n options?.sessionId !== undefined &&\n options.sessionId !== this._activeDictationSessionId;\n if (isStaleSession || this._isCleaningDictation) return;\n\n this._isCleaningDictation = true;\n try {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n this._dictationSession = undefined;\n this._activeDictationSessionId = undefined;\n this._dictation = undefined;\n this._dictationBaseText = \"\";\n this._currentInterimText = \"\";\n this._notifySubscribers();\n } finally {\n this._isCleaningDictation = false;\n }\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<(payload?: unknown) => void>\n >();\n\n protected _notifyEventSubscribers<E extends ComposerRuntimeEventType>(\n event: E,\n payload: ComposerRuntimeEventPayload[E],\n ) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback(payload);\n }\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ) {\n const wrapped = callback as (payload?: unknown) => void;\n let subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n subscribers = new Set();\n this._eventSubscribers.set(event, subscribers);\n }\n subscribers.add(wrapped);\n\n return () => {\n this._eventSubscribers.get(event)?.delete(wrapped);\n };\n }\n}\n"],"mappings":";;;;;AA+BA,MAAMuB,wBAAwBC,MAC5BA,EAAEC,OAAOC,SAAS;AAEpB,IAAsBC,0BAAtB,cACUlB,iBAEV;CACE,YAA4B;CAK5B,2BAEE0B,SAAYE,kBAA0D;EACtE,IAAI,CAACA,kBAAkB,OAAOF;EAC9B,OAAO;GACL,GAAGA;GACHH,UAAU;IACR,G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AAU,CAAC;EACtC,CAAC;CACH;CAEA,kBAA0BtD,SAAmD;EAI3E,IAFEA,SAASsD,cAAc/E,KAAAA,KACvByB,QAAQsD,cAAc,KAAKJ,6BACP,KAAKC,sBAAsB;EAEjD,KAAKA,uBAAuB;EAC5B,IAAI;GACF,KAAK,MAAMM,SAAS,KAAKT,wBACvBS,MAAM;GAER,KAAKT,yBAAyB,CAAA;GAC9B,KAAK/C,oBAAoB1B,KAAAA;GACzB,KAAK2E,4BAA4B3E,KAAAA;GACjC,KAAKI,aAAaJ,KAAAA;GAClB,KAAKK,qBAAqB;GAC1B,KAAKC,sBAAsB;GAC3B,KAAKnB,mBAAmB;EAC1B,UAAU;GACR,KAAKyF,uBAAuB;EAC9B;CACF;CAEA,oCAA4B,IAAIiC,IAG9B;CAEF,wBACEG,OACAD,SACA;EACA,MAAMG,cAAc,KAAKN,kBAAkBO,IAAIH,KAAK;EACpD,IAAI,CAACE,aAAa;EAElB,KAAK,MAAME,YAAYF,aAAaE,SAASL,OAAO;CACtD;CAEA,YACEC,OACAI,UACA;EACA,MAAME,UAAUF;EAChB,IAAIF,cAAc,KAAKN,kBAAkBO,IAAIH,KAAK;EAClD,IAAI,CAACE,aAAa;GAChBA,8BAAc,IAAIJ,IAAI;GACtB,KAAKF,kBAAkBW,IAAIP,OAAOE,WAAW;EAC/C;EACAA,YAAYzD,IAAI6D,OAAO;EAEvB,aAAa;GACX,KAAKV,kBAAkBO,IAAIH,KAAK,CAAC,EAAEQ,OAAOF,OAAO;EACnD;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-edit-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/default-edit-composer-runtime-core.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"default-edit-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/default-edit-composer-runtime-core.ts"],"mappings":";;;;;;;;cAWa,8BAAA,SAAuC,uBAAA;EAAA,QAuBxC,OAAA;EAAA,QAQA,eAAA;EAAA,IA9BC,SAAA;EAAA,IAIA,OAAA;EAAA,UAID,oBAAA,IAAoB,iBAAA;EAAA,UAIpB,mBAAA,IAAmB,gBAAA;EAAA,QAIrB,aAAA;EAAA,QACA,oBAAA;EAAA,QACA,mBAAA;EAAA,QACA,SAAA;EAAA,QACA,SAAA;cAEE,OAAA,EAAS,iBAAA;IACf,QAAA;MAEM,WAAA,GAAc,iBAAA;MACd,SAAA,GAAY,gBAAA;IAAA;EAAA,GAIZ,eAAA;IACN,QAAA;IAAU;EAAA;IAAa,QAAA;IAAyB,OAAA,EAAS,aAAA;EAAA;EAAA,IA2BlD,QAAA;EAAA,IAIA,QAAA;EAIE,UAAA,CACX,OAAA,EAAS,IAAA,CAAK,aAAA,4BACd,OAAA,GAAU,WAAA,GAAW,OAAA;EAgDhB,YAAA;AAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gateInteractableComposerMetadata } from "../../model-context/interactable-composer-metadata.js";
|
|
1
2
|
import { attachmentsEqual, liftNonTextParts } from "../../adapters/attachment.js";
|
|
2
3
|
import { getThreadMessageText } from "../../utils/text.js";
|
|
3
4
|
import { BaseComposerRuntimeCore } from "./base-composer-runtime-core.js";
|
|
@@ -52,8 +53,12 @@ var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
52
53
|
const attachmentsChanged = !attachmentsEqual(message.attachments ?? [], this._previousAttachments);
|
|
53
54
|
if (text !== this._previousText || attachmentsChanged || options?.startRun) {
|
|
54
55
|
const content = this._nonTextPassthrough.length > 0 ? [...message.content, ...this._nonTextPassthrough] : message.content;
|
|
56
|
+
const messages = this.runtime.messages;
|
|
57
|
+
const parentIndex = this._parentId === null ? -1 : messages.findIndex((m) => m.id === this._parentId);
|
|
58
|
+
const composerMetadata = gateInteractableComposerMetadata(this.runtime.getModelContext().unstable_composerMetadata, messages.slice(0, parentIndex + 1));
|
|
59
|
+
const enriched = this.enrichWithComposerMetadata(message, composerMetadata);
|
|
55
60
|
this.runtime.append({
|
|
56
|
-
...
|
|
61
|
+
...enriched,
|
|
57
62
|
content,
|
|
58
63
|
parentId: this._parentId,
|
|
59
64
|
sourceId: this._sourceId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-edit-composer-runtime-core.js","names":["AppendMessage","ThreadMessage","CompleteAttachment","getThreadMessageText","attachmentsEqual","liftNonTextParts","AttachmentAdapter","DictationAdapter","SendOptions","ThreadRuntimeCore","BaseComposerRuntimeCore","DefaultEditComposerRuntimeCore","canCancel","canSend","isEmpty","getAttachmentAdapter","runtime","adapters","attachments","getDictationAdapter","dictation","_previousText","_previousAttachments","_nonTextPassthrough","_parentId","_sourceId","constructor","endEditCallback","parentId","message","id","setText","setRole","role","content","filter","p","type","setAttachments","setRunConfig","composer","runConfig","sourceId","handleSend","Omit","options","text","attachmentsChanged","startRun","length","append","handleCancel","_notifySubscribers"],"sources":["../../../src/runtime/base/default-edit-composer-runtime-core.ts"],"sourcesContent":["import type { AppendMessage, ThreadMessage } from \"../../types/message\";\nimport type { CompleteAttachment } from \"../../types/attachment\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { attachmentsEqual, liftNonTextParts } from \"../../adapters/attachment\";\nimport type { AttachmentAdapter } from \"../../adapters/attachment\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport type { SendOptions } from \"../interfaces/composer-runtime-core\";\nimport type { ThreadRuntimeCore } from \"../interfaces/thread-runtime-core\";\nimport { BaseComposerRuntimeCore } from \"./base-composer-runtime-core\";\n\nexport class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {\n public get canCancel() {\n return true;\n }\n\n public get canSend() {\n return !this.isEmpty;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n protected getDictationAdapter() {\n return this.runtime.adapters?.dictation;\n }\n\n private _previousText;\n private _previousAttachments: readonly CompleteAttachment[];\n private _nonTextPassthrough: readonly ThreadMessage[\"content\"][number][];\n private _parentId: string | null;\n private _sourceId: string | null;\n constructor(\n private runtime: ThreadRuntimeCore & {\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n dictation?: DictationAdapter | undefined;\n }\n | undefined;\n },\n private endEditCallback: () => void,\n { parentId, message }: { parentId: string | null; message: ThreadMessage },\n ) {\n super();\n this._parentId = parentId;\n this._sourceId = message.id;\n this._previousText = getThreadMessageText(message);\n this.setText(this._previousText);\n\n this.setRole(message.role);\n\n if (message.role === \"user\") {\n this._previousAttachments = [\n ...(message.attachments ?? []),\n ...liftNonTextParts(message.content),\n ];\n this._nonTextPassthrough = [];\n } else {\n this._previousAttachments = message.attachments ?? [];\n this._nonTextPassthrough = message.content.filter(\n (p) => p.type !== \"text\",\n );\n }\n this.setAttachments(this._previousAttachments);\n\n this.setRunConfig({ ...runtime.composer.runConfig });\n }\n\n public get parentId() {\n return this._parentId;\n }\n\n public get sourceId() {\n return this._sourceId;\n }\n\n public async handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ) {\n const text = getThreadMessageText(message as AppendMessage);\n const attachmentsChanged = !attachmentsEqual(\n message.attachments ?? [],\n this._previousAttachments,\n );\n\n if (\n text !== this._previousText ||\n attachmentsChanged ||\n options?.startRun\n ) {\n const content =\n this._nonTextPassthrough.length > 0\n ? ([\n ...message.content,\n ...this._nonTextPassthrough,\n ] as AppendMessage[\"content\"])\n : message.content;\n this.runtime.append({\n ...
|
|
1
|
+
{"version":3,"file":"default-edit-composer-runtime-core.js","names":["AppendMessage","ThreadMessage","CompleteAttachment","getThreadMessageText","attachmentsEqual","liftNonTextParts","AttachmentAdapter","DictationAdapter","SendOptions","ThreadRuntimeCore","BaseComposerRuntimeCore","gateInteractableComposerMetadata","DefaultEditComposerRuntimeCore","canCancel","canSend","isEmpty","getAttachmentAdapter","runtime","adapters","attachments","getDictationAdapter","dictation","_previousText","_previousAttachments","_nonTextPassthrough","_parentId","_sourceId","constructor","endEditCallback","parentId","message","id","setText","setRole","role","content","filter","p","type","setAttachments","setRunConfig","composer","runConfig","sourceId","handleSend","Omit","options","text","attachmentsChanged","startRun","length","messages","parentIndex","findIndex","m","composerMetadata","getModelContext","unstable_composerMetadata","slice","enriched","enrichWithComposerMetadata","append","handleCancel","_notifySubscribers"],"sources":["../../../src/runtime/base/default-edit-composer-runtime-core.ts"],"sourcesContent":["import type { AppendMessage, ThreadMessage } from \"../../types/message\";\nimport type { CompleteAttachment } from \"../../types/attachment\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { attachmentsEqual, liftNonTextParts } from \"../../adapters/attachment\";\nimport type { AttachmentAdapter } from \"../../adapters/attachment\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport type { SendOptions } from \"../interfaces/composer-runtime-core\";\nimport type { ThreadRuntimeCore } from \"../interfaces/thread-runtime-core\";\nimport { BaseComposerRuntimeCore } from \"./base-composer-runtime-core\";\nimport { gateInteractableComposerMetadata } from \"../../model-context/interactable-composer-metadata\";\n\nexport class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {\n public get canCancel() {\n return true;\n }\n\n public get canSend() {\n return !this.isEmpty;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n protected getDictationAdapter() {\n return this.runtime.adapters?.dictation;\n }\n\n private _previousText;\n private _previousAttachments: readonly CompleteAttachment[];\n private _nonTextPassthrough: readonly ThreadMessage[\"content\"][number][];\n private _parentId: string | null;\n private _sourceId: string | null;\n constructor(\n private runtime: ThreadRuntimeCore & {\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n dictation?: DictationAdapter | undefined;\n }\n | undefined;\n },\n private endEditCallback: () => void,\n { parentId, message }: { parentId: string | null; message: ThreadMessage },\n ) {\n super();\n this._parentId = parentId;\n this._sourceId = message.id;\n this._previousText = getThreadMessageText(message);\n this.setText(this._previousText);\n\n this.setRole(message.role);\n\n if (message.role === \"user\") {\n this._previousAttachments = [\n ...(message.attachments ?? []),\n ...liftNonTextParts(message.content),\n ];\n this._nonTextPassthrough = [];\n } else {\n this._previousAttachments = message.attachments ?? [];\n this._nonTextPassthrough = message.content.filter(\n (p) => p.type !== \"text\",\n );\n }\n this.setAttachments(this._previousAttachments);\n\n this.setRunConfig({ ...runtime.composer.runConfig });\n }\n\n public get parentId() {\n return this._parentId;\n }\n\n public get sourceId() {\n return this._sourceId;\n }\n\n public async handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ) {\n const text = getThreadMessageText(message as AppendMessage);\n const attachmentsChanged = !attachmentsEqual(\n message.attachments ?? [],\n this._previousAttachments,\n );\n\n if (\n text !== this._previousText ||\n attachmentsChanged ||\n options?.startRun\n ) {\n const content =\n this._nonTextPassthrough.length > 0\n ? ([\n ...message.content,\n ...this._nonTextPassthrough,\n ] as AppendMessage[\"content\"])\n : message.content;\n // Gate live state against the new branch's prefix (messages up to the\n // parent): an unchanged interactable re-stamps the prior baseline, an\n // interactable edited since the original message stamps its newest state.\n const messages = this.runtime.messages;\n const parentIndex =\n this._parentId === null\n ? -1\n : messages.findIndex((m) => m.id === this._parentId);\n const composerMetadata = gateInteractableComposerMetadata(\n this.runtime.getModelContext().unstable_composerMetadata,\n messages.slice(0, parentIndex + 1),\n );\n const enriched = this.enrichWithComposerMetadata(\n message,\n composerMetadata,\n );\n this.runtime.append({\n ...enriched,\n content,\n parentId: this._parentId,\n sourceId: this._sourceId,\n startRun: options?.startRun,\n });\n }\n\n this.handleCancel();\n }\n\n public handleCancel() {\n this.endEditCallback();\n this._notifySubscribers();\n }\n}\n"],"mappings":";;;;;AAWA,IAAaY,iCAAb,cAAoDF,wBAAwB;CAuBhEO;CAQAW;CA9BV,IAAWf,YAAY;EACrB,OAAO;CACT;CAEA,IAAWC,UAAU;EACnB,OAAO,CAAC,KAAKC;CACf;CAEA,uBAAiC;EAC/B,OAAO,KAAKE,QAAQC,UAAUC;CAChC;CAEA,sBAAgC;EAC9B,OAAO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O,KAAKN,SAAS;GACvD,MAAM8B,mBAAmB5C,iCACvB,KAAKM,QAAQuC,gBAAgB,CAAC,CAACC,2BAC/BN,SAASO,MAAM,GAAGN,cAAc,CAAC,CACnC;GACA,MAAMO,WAAW,KAAKC,2BACpB9B,SACAyB,gBACF;GACA,KAAKtC,QAAQ4C,OAAO;IAClB,GAAGF;IACHxB;IACAN,UAAU,KAAKJ;IACfkB,UAAU,KAAKjB;IACfuB,UAAUH,SAASG;GACrB,CAAC;EACH;EAEA,KAAKa,aAAa;CACpB;CAEA,eAAsB;EACpB,KAAKlC,gBAAgB;EACrB,KAAKmC,mBAAmB;CAC1B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-thread-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/default-thread-composer-runtime-core.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"default-thread-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/default-thread-composer-runtime-core.ts"],"mappings":";;;;;;;;;cAea,gCAAA,SACH,uBAAA,YACG,yBAAA;EAAA,QAgCD,OAAA;EAAA,QA9BF,UAAA;EAAA,IACG,SAAA;EAAA,IAIA,OAAA;EAAA,IAIS,KAAA,aAAkB,cAAA;EAItB,cAAA,CAAe,WAAA;EAIf,eAAA,CAAgB,WAAA;EAAA,UAItB,oBAAA,IAAoB,iBAAA;EAAA,UAIpB,mBAAA,IAAmB,gBAAA;cAKnB,OAAA,EAAS,IAAA,CAAK,iBAAA;IACpB,QAAA;MAEM,WAAA,GAAc,iBAAA;MACd,SAAA,GAAY,gBAAA;IAAA;EAAA;EASf,OAAA,IAT+B,WAAA;EA8BzB,UAAA,CACX,OAAA,EAAS,IAAA,CAAK,aAAA,4BACd,OAAA,GAAU,WAAA,GAAW,OAAA;EAoBV,YAAA,IAAY,OAAA;AAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gateInteractableComposerMetadata } from "../../model-context/interactable-composer-metadata.js";
|
|
1
2
|
import { EMPTY_QUEUE_ITEMS } from "../../store/scopes/queue-item.js";
|
|
2
3
|
import { BaseComposerRuntimeCore } from "./base-composer-runtime-core.js";
|
|
3
4
|
//#region src/runtime/base/default-thread-composer-runtime-core.ts
|
|
@@ -51,8 +52,10 @@ var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
async handleSend(message, options) {
|
|
55
|
+
const composerMetadata = gateInteractableComposerMetadata(this.runtime.getModelContext().unstable_composerMetadata, this.runtime.messages);
|
|
56
|
+
const enriched = this.enrichWithComposerMetadata(message, composerMetadata);
|
|
54
57
|
this.runtime.append({
|
|
55
|
-
...
|
|
58
|
+
...enriched,
|
|
56
59
|
parentId: this.runtime.messages.at(-1)?.id ?? null,
|
|
57
60
|
sourceId: null,
|
|
58
61
|
startRun: options?.startRun,
|