@assistant-ui/react 0.15.13 → 0.15.15
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/assistant-transport.d.ts +32 -0
- package/dist/assistant-transport.d.ts.map +1 -0
- package/dist/assistant-transport.js +27 -0
- package/dist/assistant-transport.js.map +1 -0
- package/dist/context/providers/MessageProvider.js +1 -1
- package/dist/hooks/useMessageQuote.js +1 -1
- package/dist/hooks/useToolCallElapsed.js +1 -1
- package/dist/index.d.ts +5 -8
- package/dist/index.js +7 -9
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +1 -1
- package/dist/mcp-apps/McpAppsRemoteHost.d.ts.map +1 -1
- package/dist/mcp-apps/McpAppsRemoteHost.js +18 -2
- package/dist/mcp-apps/McpAppsRemoteHost.js.map +1 -1
- package/dist/mcp-apps/bridge.js +39 -24
- package/dist/mcp-apps/bridge.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js +24 -37
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.js +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js +1 -1
- package/dist/primitives/attachment/AttachmentName.js +1 -1
- package/dist/primitives/attachment/AttachmentRemove.js +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.js +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.js +1 -1
- package/dist/primitives/composer/ComposerInput.js +2 -2
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.js +1 -1
- package/dist/primitives/composer/ComposerRoot.js +1 -1
- package/dist/primitives/composer/ComposerStopDictation.js +1 -1
- package/dist/primitives/composer/trigger/TriggerPopover.js +1 -1
- package/dist/primitives/composer/useComposerInputState.js +1 -1
- package/dist/primitives/message/MessageIf.js +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +1 -1
- package/dist/primitives/message/MessageRoot.js +1 -1
- package/dist/primitives/queueItem/QueueItemRemove.js +1 -1
- package/dist/primitives/queueItem/QueueItemSteer.js +1 -1
- package/dist/primitives/queueItem/QueueItemText.js +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.js +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.js +1 -1
- package/dist/primitives/thread/ThreadIf.js +1 -1
- package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadRoot.js +41 -9
- package/dist/primitives/thread/ThreadRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +2 -13
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +23 -8
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.js +1 -1
- package/dist/sandbox-host/SandboxHost.js +2 -0
- package/dist/sandbox-host/SandboxHost.js.map +1 -1
- package/dist/unstable/useComposerInput.d.ts +2 -2
- package/dist/unstable/useComposerInput.js +1 -1
- package/dist/unstable/useComposerInput.js.map +1 -1
- package/dist/unstable/useComposerInputHistory.js +1 -1
- package/dist/unstable/useComposerInputHistory.js.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.d.ts +5 -0
- package/dist/unstable/useLiveCompletionAdapter.d.ts.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.js +16 -3
- package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
- package/dist/unstable/useMentionAdapter.d.ts +1 -1
- package/dist/utils/smooth/SmoothContext.js +1 -1
- package/dist/utils/useToolArgsFieldStatus.js +1 -1
- package/package.json +9 -9
- package/src/assistant-transport.ts +94 -0
- package/src/index.ts +9 -4
- package/src/mcp-apps/McpAppsRemoteHost.test.ts +29 -3
- package/src/mcp-apps/McpAppsRemoteHost.ts +42 -7
- package/src/mcp-apps/bridge.test.ts +132 -0
- package/src/mcp-apps/bridge.ts +54 -30
- package/src/primitives/actionBar/ActionBarStopSpeaking.tsx +0 -9
- package/src/primitives/composer/ComposerInput.tsx +1 -1
- package/src/primitives/thread/ThreadRoot.test.tsx +251 -0
- package/src/primitives/thread/ThreadRoot.tsx +30 -0
- package/src/primitives/thread/ThreadViewport.tsx +1 -8
- package/src/primitives/thread/useThreadViewportAutoScroll.test.tsx +152 -0
- package/src/primitives/thread/useThreadViewportAutoScroll.ts +26 -19
- package/src/sandbox-host/SandboxHost.test.tsx +29 -0
- package/src/sandbox-host/SandboxHost.tsx +2 -0
- package/src/tests/RemoteThreadListRuntime.adapterProvider.test.tsx +24 -3
- package/src/tests/RemoteThreadListRuntime.reloadMainThread.test.tsx +1 -2
- package/src/tests/augmentations.test.ts +49 -0
- package/src/tests/in-memory-thread-list.test.tsx +87 -3
- package/src/tests/threadMessageById.test.tsx +61 -1
- package/src/unstable/useComposerInput.ts +2 -2
- package/src/unstable/useComposerInputHistory.test.tsx +4 -4
- package/src/unstable/useComposerInputHistory.ts +1 -1
- package/src/unstable/useLiveCompletionAdapter.test.tsx +100 -0
- package/src/unstable/useLiveCompletionAdapter.ts +41 -17
- package/dist/client/InMemoryThreadList.d.ts +0 -12
- package/dist/client/InMemoryThreadList.d.ts.map +0 -1
- package/dist/client/InMemoryThreadList.js +0 -365
- package/dist/client/InMemoryThreadList.js.map +0 -1
- package/dist/legacy-runtime/cloud/auiV0.d.ts +0 -119
- package/dist/legacy-runtime/cloud/auiV0.d.ts.map +0 -1
- package/dist/legacy-runtime/cloud/auiV0.js +0 -137
- package/dist/legacy-runtime/cloud/auiV0.js.map +0 -1
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts +0 -16
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts.map +0 -1
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.js +0 -36
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts +0 -17
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js +0 -55
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.d.ts +0 -11
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.js +0 -141
- package/dist/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts +0 -15
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +0 -81
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +0 -126
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js +0 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts +0 -14
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +0 -290
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts +0 -7
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js +0 -25
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.d.ts +0 -7
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.d.ts.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.js +0 -27
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.js.map +0 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts +0 -2
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js +0 -2
- package/src/client/InMemoryThreadList.ts +0 -241
- package/src/legacy-runtime/cloud/auiV0.ts +0 -331
- package/src/legacy-runtime/cloud/useCloudThreadListRuntime.ts +0 -31
- package/src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts +0 -68
- package/src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.test.ts +0 -430
- package/src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.ts +0 -146
- package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +0 -113
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-delivery.test.tsx +0 -79
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-parentid.test.tsx +0 -97
- package/src/legacy-runtime/runtime-cores/assistant-transport/transport-scheduling.test.ts +0 -307
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +0 -170
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +0 -141
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +0 -585
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +0 -476
- package/src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts +0 -20
- package/src/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.ts +0 -9
- package/src/legacy-runtime/runtime-cores/assistant-transport/utils.ts +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auiV0.js","names":["CompleteAttachment","MessageStatus","SourceProviderMetadata","ThreadMessage","ToolApprovalOption","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","unstable_summary","sourceType","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","approval","argsText","image","data","mimeType","AuiV0AttachmentPart","audio","format","name","AuiV0Attachment","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","undefined","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","map","auiV0Encode","auiV0Decode","cloudMessage","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../src/legacy-runtime/cloud/auiV0.ts"],"sourcesContent":["import type {\n CompleteAttachment,\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n ToolApprovalOption,\n} from \"@assistant-ui/core\";\nimport { fromThreadMessageLike } from \"../runtime-cores/external-store/ThreadMessageLike\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"@assistant-ui/core/internal\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../runtime-cores/utils/MessageRepository\";\n\ntype AuiV0ToolApproval = {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n};\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly unstable_summary?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n readonly sourceType?: \"url\" | \"id\";\n };\n\ntype AuiV0AttachmentPart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n readonly sourceType?: \"url\" | \"id\";\n }\n | {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n }\n | {\n readonly type: \"data\";\n readonly name: string;\n readonly data: ReadonlyJSONValue;\n };\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"image\":\n return {\n type: \"image\",\n image: part.image,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n ...(part.sourceType != null\n ? { sourceType: part.sourceType }\n : undefined),\n };\n\n case \"audio\":\n return {\n type: \"audio\",\n audio: { data: part.audio.data, format: part.audio.format },\n };\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return {\n type: \"data\",\n name: part.name,\n data: part.data as ReadonlyJSONValue,\n };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return {\n type: \"reasoning\",\n text: part.text,\n ...(part.unstable_summary !== undefined\n ? { unstable_summary: part.unstable_summary }\n : undefined),\n };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (part.result !== undefined && !isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result !== undefined\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n ...(part.approval ? { approval: part.approval } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n ...(part.sourceType ? { sourceType: part.sourceType } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n}\n"],"mappings":";;;AA6IA,MAAM2D,wBACJC,SACwB;CACxB,MAAMxC,OAAOwC,KAAKxC;CAClB,QAAQA,MAAR;EACE,KAAK,QACH,OAAO;GAAEA,MAAM;GAAQC,MAAMuC,KAAKvC;EAAK;EAEzC,KAAK,SACH,OAAO;GACLD,MAAM;GACNgB,OAAOwB,KAAKxB;GACZ,GAAIwB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;EAC5D;EAEF,KAAK,QACH,OAAO;GACLzC,MAAM;GACNiB,MAAMuB,KAAKvB;GACXC,UAAUsB,KAAKtB;GACf,GAAIsB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;GAC1D,GAAID,KAAKrC,cAAc,OACnB,EAAEA,YAAYqC,KAAKrC,WAAW,IAC9BsC,KAAAA;EACN;EAEF,KAAK,SACH,OAAO;GACLzC,MAAM;GACNoB,OAAO;IAAEH,MAAMuB,KAA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KAAKhC,WAAW,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;KAClD,GAAID,KAAKrC,aAAa,EAAEA,YAAYqC,KAAKrC,WAAW,IAAIsC,KAAAA;IAC1D;IAEF,SAEE,MAAM,IAAIM,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDhB,UAAUmB,QAAQnB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIgB,KAAAA;EAC1B,GAAIZ,cAAc,EAAEA,YAAY,IAAIY,KAAAA;CACtC;AACF;AAEA,SAAgBY,YACdC,cAC+B;CAC/B,MAAMC,UAAUD,aAAa5B;CAC7B,MAAMuB,UAAUhE,sBACd;EACEO,IAAI8D,aAAa9D;EACjBgE,WAAWF,aAAaG;EACxB,GAAGF;CACL,GACAD,aAAa9D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACLgE,UAAUJ,aAAaK;EACvBV;CACF;AACF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AssistantCloud } from "assistant-cloud";
|
|
2
|
-
import { AssistantRuntime } from "@assistant-ui/core";
|
|
3
|
-
//#region src/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts
|
|
4
|
-
type ThreadData = {
|
|
5
|
-
externalId: string;
|
|
6
|
-
};
|
|
7
|
-
type CloudThreadListAdapter = {
|
|
8
|
-
cloud: AssistantCloud;
|
|
9
|
-
runtimeHook: () => AssistantRuntime;
|
|
10
|
-
create?(): Promise<ThreadData>;
|
|
11
|
-
delete?(threadId: string): Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
declare function useCloudThreadListRuntime({ runtimeHook, ...adapterOptions }: CloudThreadListAdapter): AssistantRuntime;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { useCloudThreadListRuntime };
|
|
16
|
-
//# sourceMappingURL=useCloudThreadListRuntime.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListRuntime.d.ts","names":[],"sources":["../../../src/legacy-runtime/cloud/useCloudThreadListRuntime.ts"],"mappings":";;;KAOK;EACH;;KAGG;EACH,OAAO;EAEP,mBAAmB;EAEnB,WAAW,QAAQ;EACnB,QAAQ,mBAAmB;;iBAGb,4BACd,gBACG,kBACF,yBAAsB"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useRemoteThreadListRuntime } from "../runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js";
|
|
3
|
-
import { useCloudThreadListAdapter } from "../runtime-cores/remote-thread-list/adapter/cloud.js";
|
|
4
|
-
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
|
-
//#region src/legacy-runtime/cloud/useCloudThreadListRuntime.ts
|
|
6
|
-
function useCloudThreadListRuntime(t0) {
|
|
7
|
-
const $ = c(6);
|
|
8
|
-
let adapterOptions;
|
|
9
|
-
let runtimeHook;
|
|
10
|
-
if ($[0] !== t0) {
|
|
11
|
-
({runtimeHook, ...adapterOptions} = t0);
|
|
12
|
-
$[0] = t0;
|
|
13
|
-
$[1] = adapterOptions;
|
|
14
|
-
$[2] = runtimeHook;
|
|
15
|
-
} else {
|
|
16
|
-
adapterOptions = $[1];
|
|
17
|
-
runtimeHook = $[2];
|
|
18
|
-
}
|
|
19
|
-
const adapter = useCloudThreadListAdapter(adapterOptions);
|
|
20
|
-
let t1;
|
|
21
|
-
if ($[3] !== adapter || $[4] !== runtimeHook) {
|
|
22
|
-
t1 = {
|
|
23
|
-
runtimeHook,
|
|
24
|
-
adapter,
|
|
25
|
-
allowNesting: true
|
|
26
|
-
};
|
|
27
|
-
$[3] = adapter;
|
|
28
|
-
$[4] = runtimeHook;
|
|
29
|
-
$[5] = t1;
|
|
30
|
-
} else t1 = $[5];
|
|
31
|
-
return useRemoteThreadListRuntime(t1);
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
export { useCloudThreadListRuntime };
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=useCloudThreadListRuntime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListRuntime.js","names":["c","_c","AssistantCloud","AssistantRuntime","useRemoteThreadListRuntime","useCloudThreadListAdapter","ThreadData","externalId","CloudThreadListAdapter","cloud","runtimeHook","create","Promise","delete","threadId","useCloudThreadListRuntime","t0","$","adapterOptions","adapter","t1","allowNesting"],"sources":["../../../src/legacy-runtime/cloud/useCloudThreadListRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport type { AssistantCloud } from \"assistant-cloud\";\nimport type { AssistantRuntime } from \"@assistant-ui/core\";\nimport { useRemoteThreadListRuntime } from \"../runtime-cores/remote-thread-list/useRemoteThreadListRuntime\";\nimport { useCloudThreadListAdapter } from \"../runtime-cores/remote-thread-list/adapter/cloud\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapter = {\n cloud: AssistantCloud;\n\n runtimeHook: () => AssistantRuntime;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nexport function useCloudThreadListRuntime({\n runtimeHook,\n ...adapterOptions\n}: CloudThreadListAdapter) {\n const adapter = useCloudThreadListAdapter(adapterOptions);\n return useRemoteThreadListRuntime({\n runtimeHook,\n adapter,\n allowNesting: true,\n });\n}\n"],"mappings":";;;;;AAoBA,SAAOe,0BAAAC,IAAA;CAAA,MAAAC,IAAAhB,EAAA,CAAA;CAAA,IAAAiB;CAAA,IAAAR;CAAA,IAAAO,EAAA,OAAAD,IAAA;EAAmC,CAAA,CAAAN,gBAAAQ,kBAAAF;EAGjBC,EAAA,KAAAD;EAAAC,EAAA,KAAAC;EAAAD,EAAA,KAAAP;CAAA,OAAA;EAAAQ,iBAAAD,EAAA;EAAAP,cAAAO,EAAA;CAAA;CACvB,MAAAE,UAAgBd,0BAA0Ba,cAAc;CAAE,IAAAE;CAAA,IAAAH,EAAA,OAAAE,WAAAF,EAAA,OAAAP,aAAA;EACxBU,KAAA;GAAAV;GAAAS;GAAAE,cAGlB;EAChB;EAACJ,EAAA,KAAAE;EAAAF,EAAA,KAAAP;EAAAO,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,OAJMb,2BAA2BgB,EAIjC;AAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AssistantTransportCommand, CommandQueueState, QueuedCommand } from "./types.js";
|
|
2
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts
|
|
3
|
-
declare const createInitialQueueState: () => CommandQueueState;
|
|
4
|
-
declare const useCommandQueue: (opts: {
|
|
5
|
-
onQueue: () => void;
|
|
6
|
-
}) => {
|
|
7
|
-
readonly state: CommandQueueState;
|
|
8
|
-
enqueue: (command: AssistantTransportCommand, options?: {
|
|
9
|
-
schedule?: boolean;
|
|
10
|
-
}) => void;
|
|
11
|
-
flush: () => QueuedCommand[];
|
|
12
|
-
markDelivered: () => void;
|
|
13
|
-
reset: () => void;
|
|
14
|
-
};
|
|
15
|
-
//#endregion
|
|
16
|
-
export { createInitialQueueState, useCommandQueue };
|
|
17
|
-
//# sourceMappingURL=commandQueue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commandQueue.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts"],"mappings":";;cAOa,+BAA8B;cAK9B,kBAAmB;EAAQ;;;EAU3B,UAAA,SAAA,2BAAyB;IACtB;;EAWI,aAAA"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
2
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts
|
|
3
|
-
const createInitialQueueState = () => ({
|
|
4
|
-
queued: [],
|
|
5
|
-
inTransit: []
|
|
6
|
-
});
|
|
7
|
-
const useCommandQueue = (opts) => {
|
|
8
|
-
const onQueueRef = useRef(opts.onQueue);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
onQueueRef.current = opts.onQueue;
|
|
11
|
-
});
|
|
12
|
-
const [, rerender] = useState(0);
|
|
13
|
-
const queueStateRef = useRef(createInitialQueueState());
|
|
14
|
-
const enqueue = (command, options) => {
|
|
15
|
-
queueStateRef.current = {
|
|
16
|
-
queued: [...queueStateRef.current.queued, command],
|
|
17
|
-
inTransit: queueStateRef.current.inTransit
|
|
18
|
-
};
|
|
19
|
-
rerender((prev) => prev + 1);
|
|
20
|
-
if (options?.schedule !== false) onQueueRef.current();
|
|
21
|
-
};
|
|
22
|
-
const flush = () => {
|
|
23
|
-
if (queueStateRef.current.queued.length === 0) return [];
|
|
24
|
-
const queued = queueStateRef.current.queued;
|
|
25
|
-
queueStateRef.current = {
|
|
26
|
-
queued: [],
|
|
27
|
-
inTransit: [...queueStateRef.current.inTransit, ...queued]
|
|
28
|
-
};
|
|
29
|
-
rerender((prev_0) => prev_0 + 1);
|
|
30
|
-
return queued;
|
|
31
|
-
};
|
|
32
|
-
const markDelivered = () => {
|
|
33
|
-
queueStateRef.current = {
|
|
34
|
-
...queueStateRef.current,
|
|
35
|
-
inTransit: []
|
|
36
|
-
};
|
|
37
|
-
rerender((prev_1) => prev_1 + 1);
|
|
38
|
-
};
|
|
39
|
-
return {
|
|
40
|
-
get state() {
|
|
41
|
-
return queueStateRef.current;
|
|
42
|
-
},
|
|
43
|
-
enqueue,
|
|
44
|
-
flush,
|
|
45
|
-
markDelivered,
|
|
46
|
-
reset: useCallback(() => {
|
|
47
|
-
queueStateRef.current = createInitialQueueState();
|
|
48
|
-
rerender((prev_2) => prev_2 + 1);
|
|
49
|
-
}, [])
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
//#endregion
|
|
53
|
-
export { createInitialQueueState, useCommandQueue };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=commandQueue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commandQueue.js","names":["useState","useCallback","useRef","useEffect","AssistantTransportCommand","CommandQueueState","QueuedCommand","createInitialQueueState","queued","inTransit","useCommandQueue","opts","onQueue","onQueueRef","current","rerender","queueStateRef","enqueue","command","options","schedule","prev","flush","length","markDelivered","reset","state"],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts"],"sourcesContent":["import { useState, useCallback, useRef, useEffect } from \"react\";\nimport type {\n AssistantTransportCommand,\n CommandQueueState,\n QueuedCommand,\n} from \"./types\";\n\nexport const createInitialQueueState = (): CommandQueueState => ({\n queued: [],\n inTransit: [],\n});\n\nexport const useCommandQueue = (opts: { onQueue: () => void }) => {\n const onQueueRef = useRef(opts.onQueue);\n useEffect(() => {\n onQueueRef.current = opts.onQueue;\n });\n\n const [, rerender] = useState(0);\n const queueStateRef = useRef<CommandQueueState>(createInitialQueueState());\n\n const enqueue = (\n command: AssistantTransportCommand,\n options?: { schedule?: boolean },\n ) => {\n queueStateRef.current = {\n queued: [...queueStateRef.current.queued, command],\n inTransit: queueStateRef.current.inTransit,\n };\n rerender((prev) => prev + 1);\n\n if (options?.schedule !== false) onQueueRef.current();\n };\n\n const flush = (): QueuedCommand[] => {\n if (queueStateRef.current.queued.length === 0) return [];\n\n const queued = queueStateRef.current.queued;\n queueStateRef.current = {\n queued: [],\n inTransit: [...queueStateRef.current.inTransit, ...queued],\n };\n rerender((prev) => prev + 1);\n\n return queued;\n };\n\n const markDelivered = () => {\n queueStateRef.current = { ...queueStateRef.current, inTransit: [] };\n rerender((prev) => prev + 1);\n };\n\n const reset = useCallback(() => {\n queueStateRef.current = createInitialQueueState();\n rerender((prev) => prev + 1);\n }, []);\n\n return {\n // live getter — callbacks firing between renders must not see a stale snapshot\n get state() {\n return queueStateRef.current;\n },\n enqueue,\n flush,\n markDelivered,\n reset,\n };\n};\n"],"mappings":";;AAOA,MAAaO,iCAAoD;CAC/DC,QAAQ,CAAA;CACRC,WAAW,CAAA;AACb;AAEA,MAAaC,mBAAmBC,SAAkC;CAChE,MAAME,aAAaX,OAAOS,KAAKC,OAAO;CACtCT,gBAAgB;EACdU,WAAWC,UAAUH,KAAKC;CAC5B,CAAC;CAED,MAAM,GAAGG,YAAYf,SAAS,CAAC;CAC/B,MAAMgB,gBAAgBd,OAA0BK,wBAAwB,CAAC;CAEzE,MAAMU,WACJC,SACAC,YACG;EACHH,cAAcF,UAAU;GACtBN,QAAQ,CAAC,GAAGQ,cAAcF,QAAQN,QAAQU,OAAO;GACjDT,WAAWO,cAAcF,QAAQL;EACnC;EACAM,UAAUM,SAASA,OAAO,CAAC;EAE3B,IAAIF,SAASC,aAAa,OAAOP,WAAWC,QAAQ;CACtD;CAEA,MAAMQ,cAA+B;EACnC,IAAIN,cAAcF,QAAQN,OAAOe,WAAW,GAAG,OAAO,CAAA;EAEtD,MAAMf,SAASQ,cAAcF,QAAQN;EACrCQ,cAAcF,UAAU;GACtBN,QAAQ,CAAA;GACRC,WAAW,CAAC,GAAGO,cAAcF,QAAQL,WAAW,GAAGD,MAAM;EAC3D;EACAO,UAAUM,WAASA,SAAO,CAAC;EAE3B,OAAOb;CACT;CAEA,MAAMgB,sBAAsB;EAC1BR,cAAcF,UAAU;GAAE,GAAGE,cAAcF;GAASL,WAAW,CAAA;EAAG;EAClEM,UAAUM,WAASA,SAAO,CAAC;CAC7B;CAOA,OAAO;EAEL,IAAIK,QAAQ;GACV,OAAOV,cAAcF;EACvB;EACAG;EACAK;EACAE;EACAC,OAbYxB,kBAAkB;GAC9Be,cAAcF,UAAUP,wBAAwB;GAChDQ,UAAUM,WAASA,SAAO,CAAC;EAC7B,GAAG,CAAA,CAUDI;CACF;AACF"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.d.ts
|
|
2
|
-
declare const REPLAY_CONTENT_LENGTH_HEADER = "Aui-Replay-Content-Length";
|
|
3
|
-
type ReplayBoundaryStreamOptions = {
|
|
4
|
-
setReplaying: (value: boolean) => void;
|
|
5
|
-
waitForRender: () => Promise<void>;
|
|
6
|
-
};
|
|
7
|
-
declare const useReplayRenderWait: () => () => Promise<void>;
|
|
8
|
-
declare const createReplayBoundaryStream: (response: Response, { setReplaying, waitForRender: waitForReplayRender }: ReplayBoundaryStreamOptions) => Promise<ReadableStream<Uint8Array>>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { REPLAY_CONTENT_LENGTH_HEADER, createReplayBoundaryStream, useReplayRenderWait };
|
|
11
|
-
//# sourceMappingURL=replayBoundaryStream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replayBoundaryStream.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.ts"],"mappings":";cAIa;KAER;EACH,eAAe;EACf,qBAAqB;;cAGV,iCAAmB;cA6DnB,6BACX,UAAU,YACV,cAAA,eAAA,uBAGG,gCACF,QAAQ,eAAe"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
4
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.ts
|
|
5
|
-
const REPLAY_CONTENT_LENGTH_HEADER = "Aui-Replay-Content-Length";
|
|
6
|
-
const useReplayRenderWait = () => {
|
|
7
|
-
const $ = c(8);
|
|
8
|
-
const [renderTicket, setRenderTicket] = useState(0);
|
|
9
|
-
const mountedRef = useRef(true);
|
|
10
|
-
const nextTicketRef = useRef(0);
|
|
11
|
-
let t0;
|
|
12
|
-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
13
|
-
t0 = [];
|
|
14
|
-
$[0] = t0;
|
|
15
|
-
} else t0 = $[0];
|
|
16
|
-
const waitersRef = useRef(t0);
|
|
17
|
-
let t1;
|
|
18
|
-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
19
|
-
t1 = (committedTicket) => {
|
|
20
|
-
const pendingWaiters = [];
|
|
21
|
-
for (const waiter of waitersRef.current) if (committedTicket === void 0 || waiter.ticket <= committedTicket) waiter.resolve();
|
|
22
|
-
else pendingWaiters.push(waiter);
|
|
23
|
-
waitersRef.current = pendingWaiters;
|
|
24
|
-
};
|
|
25
|
-
$[1] = t1;
|
|
26
|
-
} else t1 = $[1];
|
|
27
|
-
const resolveWaiters = t1;
|
|
28
|
-
let t2;
|
|
29
|
-
let t3;
|
|
30
|
-
if ($[2] !== renderTicket) {
|
|
31
|
-
t2 = () => {
|
|
32
|
-
mountedRef.current = true;
|
|
33
|
-
resolveWaiters(renderTicket);
|
|
34
|
-
};
|
|
35
|
-
t3 = [renderTicket, resolveWaiters];
|
|
36
|
-
$[2] = renderTicket;
|
|
37
|
-
$[3] = t2;
|
|
38
|
-
$[4] = t3;
|
|
39
|
-
} else {
|
|
40
|
-
t2 = $[3];
|
|
41
|
-
t3 = $[4];
|
|
42
|
-
}
|
|
43
|
-
useEffect(t2, t3);
|
|
44
|
-
let t4;
|
|
45
|
-
let t5;
|
|
46
|
-
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
47
|
-
t4 = () => () => {
|
|
48
|
-
mountedRef.current = false;
|
|
49
|
-
resolveWaiters();
|
|
50
|
-
};
|
|
51
|
-
t5 = [resolveWaiters];
|
|
52
|
-
$[5] = t4;
|
|
53
|
-
$[6] = t5;
|
|
54
|
-
} else {
|
|
55
|
-
t4 = $[5];
|
|
56
|
-
t5 = $[6];
|
|
57
|
-
}
|
|
58
|
-
useEffect(t4, t5);
|
|
59
|
-
let t6;
|
|
60
|
-
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
61
|
-
t6 = () => new Promise((resolve) => {
|
|
62
|
-
setTimeout(() => {
|
|
63
|
-
if (!mountedRef.current) {
|
|
64
|
-
resolve();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const ticket = nextTicketRef.current + 1;
|
|
68
|
-
nextTicketRef.current = ticket;
|
|
69
|
-
waitersRef.current.push({
|
|
70
|
-
ticket,
|
|
71
|
-
resolve
|
|
72
|
-
});
|
|
73
|
-
setRenderTicket(ticket);
|
|
74
|
-
}, 0);
|
|
75
|
-
});
|
|
76
|
-
$[7] = t6;
|
|
77
|
-
} else t6 = $[7];
|
|
78
|
-
return t6;
|
|
79
|
-
};
|
|
80
|
-
const parseReplayContentLength = (headers) => {
|
|
81
|
-
const raw = headers.get(REPLAY_CONTENT_LENGTH_HEADER);
|
|
82
|
-
if (raw == null) return 0;
|
|
83
|
-
const boundary = Number(raw);
|
|
84
|
-
return Number.isSafeInteger(boundary) && boundary > 0 ? boundary : 0;
|
|
85
|
-
};
|
|
86
|
-
const createReplayBoundaryStream = async (response, { setReplaying, waitForRender: waitForReplayRender }) => {
|
|
87
|
-
const body = response.body;
|
|
88
|
-
const replayContentLength = parseReplayContentLength(response.headers);
|
|
89
|
-
if (replayContentLength <= 0) return body;
|
|
90
|
-
setReplaying(true);
|
|
91
|
-
await waitForReplayRender();
|
|
92
|
-
const reader = body.getReader();
|
|
93
|
-
let bytesForwarded = 0;
|
|
94
|
-
let replayFinished = false;
|
|
95
|
-
const finishReplay = async () => {
|
|
96
|
-
if (replayFinished) return;
|
|
97
|
-
replayFinished = true;
|
|
98
|
-
await waitForReplayRender();
|
|
99
|
-
setReplaying(false);
|
|
100
|
-
await waitForReplayRender();
|
|
101
|
-
};
|
|
102
|
-
return new ReadableStream({
|
|
103
|
-
async pull(controller) {
|
|
104
|
-
const { done, value } = await reader.read();
|
|
105
|
-
if (done) {
|
|
106
|
-
await finishReplay();
|
|
107
|
-
controller.close();
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (replayFinished) {
|
|
111
|
-
controller.enqueue(value);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const nextBytesForwarded = bytesForwarded + value.byteLength;
|
|
115
|
-
if (nextBytesForwarded < replayContentLength) {
|
|
116
|
-
bytesForwarded = nextBytesForwarded;
|
|
117
|
-
controller.enqueue(value);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (nextBytesForwarded === replayContentLength) {
|
|
121
|
-
controller.enqueue(value);
|
|
122
|
-
await finishReplay();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const replayBytesInChunk = replayContentLength - bytesForwarded;
|
|
126
|
-
controller.enqueue(value.subarray(0, replayBytesInChunk));
|
|
127
|
-
await finishReplay();
|
|
128
|
-
controller.enqueue(value.subarray(replayBytesInChunk));
|
|
129
|
-
},
|
|
130
|
-
async cancel(reason) {
|
|
131
|
-
const wasFinished = replayFinished;
|
|
132
|
-
replayFinished = true;
|
|
133
|
-
if (!wasFinished) setReplaying(false);
|
|
134
|
-
await reader.cancel(reason);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
//#endregion
|
|
139
|
-
export { REPLAY_CONTENT_LENGTH_HEADER, createReplayBoundaryStream, useReplayRenderWait };
|
|
140
|
-
|
|
141
|
-
//# sourceMappingURL=replayBoundaryStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replayBoundaryStream.js","names":["c","_c","useCallback","useEffect","useRef","useState","REPLAY_CONTENT_LENGTH_HEADER","ReplayBoundaryStreamOptions","setReplaying","value","waitForRender","Promise","useReplayRenderWait","$","renderTicket","setRenderTicket","mountedRef","nextTicketRef","t0","Symbol","for","waitersRef","t1","committedTicket","pendingWaiters","waiter","current","undefined","ticket","resolve","push","resolveWaiters","t2","t3","t4","t5","t6","setTimeout","parseReplayContentLength","headers","Headers","raw","get","boundary","Number","isSafeInteger","createReplayBoundaryStream","response","Response","waitForReplayRender","ReadableStream","Uint8Array","body","replayContentLength","reader","getReader","bytesForwarded","replayFinished","finishReplay","pull","controller","done","read","close","enqueue","nextBytesForwarded","byteLength","replayBytesInChunk","subarray","cancel","reason","wasFinished"],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/replayBoundaryStream.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport const REPLAY_CONTENT_LENGTH_HEADER = \"Aui-Replay-Content-Length\";\n\ntype ReplayBoundaryStreamOptions = {\n setReplaying: (value: boolean) => void;\n waitForRender: () => Promise<void>;\n};\n\nexport const useReplayRenderWait = () => {\n const [renderTicket, setRenderTicket] = useState(0);\n const mountedRef = useRef(true);\n const nextTicketRef = useRef(0);\n const waitersRef = useRef<Array<{ ticket: number; resolve: () => void }>>([]);\n\n const resolveWaiters = useCallback((committedTicket?: number) => {\n const pendingWaiters = [];\n\n for (const waiter of waitersRef.current) {\n if (committedTicket === undefined || waiter.ticket <= committedTicket) {\n waiter.resolve();\n } else {\n pendingWaiters.push(waiter);\n }\n }\n\n waitersRef.current = pendingWaiters;\n }, []);\n\n useEffect(() => {\n mountedRef.current = true;\n resolveWaiters(renderTicket);\n }, [renderTicket, resolveWaiters]);\n\n useEffect(\n () => () => {\n mountedRef.current = false;\n resolveWaiters();\n },\n [resolveWaiters],\n );\n\n return useCallback(\n () =>\n new Promise<void>((resolve) => {\n setTimeout(() => {\n if (!mountedRef.current) {\n resolve();\n return;\n }\n\n const ticket = nextTicketRef.current + 1;\n nextTicketRef.current = ticket;\n waitersRef.current.push({ ticket, resolve });\n setRenderTicket(ticket);\n }, 0);\n }),\n [],\n );\n};\n\nconst parseReplayContentLength = (headers: Headers): number => {\n const raw = headers.get(REPLAY_CONTENT_LENGTH_HEADER);\n if (raw == null) return 0;\n\n const boundary = Number(raw);\n return Number.isSafeInteger(boundary) && boundary > 0 ? boundary : 0;\n};\n\n// Gates replay bytes until isReplaying:true renders, then releases live bytes after isReplaying:false renders.\nexport const createReplayBoundaryStream = async (\n response: Response,\n {\n setReplaying,\n waitForRender: waitForReplayRender,\n }: ReplayBoundaryStreamOptions,\n): Promise<ReadableStream<Uint8Array>> => {\n const body = response.body as ReadableStream<Uint8Array>;\n const replayContentLength = parseReplayContentLength(response.headers);\n\n if (replayContentLength <= 0) {\n return body;\n }\n\n setReplaying(true);\n await waitForReplayRender();\n\n const reader = body.getReader();\n let bytesForwarded = 0;\n let replayFinished = false;\n\n const finishReplay = async () => {\n if (replayFinished) return;\n replayFinished = true;\n\n // Let replay bytes drain before rendering live mode, then render live mode before releasing live bytes.\n await waitForReplayRender();\n setReplaying(false);\n await waitForReplayRender();\n };\n\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n const { done, value } = await reader.read();\n\n if (done) {\n await finishReplay();\n controller.close();\n return;\n }\n\n if (replayFinished) {\n controller.enqueue(value);\n return;\n }\n\n const nextBytesForwarded = bytesForwarded + value.byteLength;\n\n if (nextBytesForwarded < replayContentLength) {\n bytesForwarded = nextBytesForwarded;\n controller.enqueue(value);\n return;\n }\n\n if (nextBytesForwarded === replayContentLength) {\n controller.enqueue(value);\n await finishReplay();\n return;\n }\n\n const replayBytesInChunk = replayContentLength - bytesForwarded;\n\n controller.enqueue(value.subarray(0, replayBytesInChunk));\n await finishReplay();\n controller.enqueue(value.subarray(replayBytesInChunk));\n },\n async cancel(reason) {\n const wasFinished = replayFinished;\n replayFinished = true;\n if (!wasFinished) setReplaying(false);\n await reader.cancel(reason);\n },\n });\n};\n"],"mappings":";;;;AAIA,MAAaM,+BAA+B;AAO5C,MAAaM,4BAAsB;CAAA,MAAAC,IAAAZ,EAAA,CAAA;CACjC,MAAA,CAAAa,cAAAC,mBAAwCV,SAAS,CAAC;CAClD,MAAAW,aAAmBZ,OAAO,IAAI;CAC9B,MAAAa,gBAAsBb,OAAO,CAAC;CAAE,IAAAc;CAAA,IAAAL,EAAA,OAAAM,OAAAC,IAAA,2BAAA,GAAA;EAC0CF,KAAA,CAAA;EAAEL,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAA5E,MAAAQ,aAAmBjB,OAAuDc,EAAE;CAAE,IAAAI;CAAA,IAAAT,EAAA,OAAAM,OAAAC,IAAA,2BAAA,G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QAAQvD,MAAM2D,SAAS,GAAGD,kBAAkB,CAAC;GACxD,MAAMT,aAAa;GACnBE,WAAWI,QAAQvD,MAAM2D,SAASD,kBAAkB,CAAC;EACvD;EACA,MAAME,OAAOC,QAAQ;GACnB,MAAMC,cAAcd;GACpBA,iBAAiB;GACjB,IAAI,CAACc,aAAa/D,aAAa,KAAK;GACpC,MAAM8C,OAAOe,OAAOC,MAAM;EAC5B;CACF,CAAC;AACH"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts
|
|
2
|
-
type RunManager = Readonly<{
|
|
3
|
-
isRunning: boolean;
|
|
4
|
-
schedule: () => void;
|
|
5
|
-
cancel: () => void;
|
|
6
|
-
}>;
|
|
7
|
-
declare function useRunManager(config: {
|
|
8
|
-
onRun: (signal: AbortSignal) => Promise<void>;
|
|
9
|
-
onFinish?: (() => void) | undefined;
|
|
10
|
-
onCancel?: (() => void) | undefined;
|
|
11
|
-
onError?: ((error: Error) => void | Promise<void>) | undefined;
|
|
12
|
-
}): RunManager;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { RunManager, useRunManager };
|
|
15
|
-
//# sourceMappingURL=runManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runManager.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts"],"mappings":";KAGY,aAAa;EACvB;EACA;EACA;;iBAYc,cAAc;EAC5B,QAAQ,QAAQ,gBAAgB;EAChC;EACA;EACA,YAAY,OAAO,iBAAiB;IAClC"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { useLatestRef } from "./useLatestRef.js";
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
3
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts
|
|
4
|
-
const disposeReason = Symbol("assistant-transport-dispose");
|
|
5
|
-
const reportFinishError = (error) => {
|
|
6
|
-
console.error("[assistant-ui] Assistant transport onFinish callback threw an error", error);
|
|
7
|
-
};
|
|
8
|
-
function useRunManager(config) {
|
|
9
|
-
const [isRunning, setIsRunning] = useState(false);
|
|
10
|
-
const stateRef = useRef({
|
|
11
|
-
pending: false,
|
|
12
|
-
disposed: false,
|
|
13
|
-
abortController: null
|
|
14
|
-
});
|
|
15
|
-
const onRunRef = useLatestRef(config.onRun);
|
|
16
|
-
const onFinishRef = useLatestRef(config.onFinish);
|
|
17
|
-
const onCancelRef = useLatestRef(config.onCancel);
|
|
18
|
-
const onErrorRef = useLatestRef(config.onError);
|
|
19
|
-
const startRun = useCallback(() => {
|
|
20
|
-
setIsRunning(true);
|
|
21
|
-
stateRef.current.pending = false;
|
|
22
|
-
const ac = new AbortController();
|
|
23
|
-
stateRef.current.abortController = ac;
|
|
24
|
-
const disposeAborted = () => ac.signal.reason === disposeReason;
|
|
25
|
-
queueMicrotask(async () => {
|
|
26
|
-
try {
|
|
27
|
-
if (!disposeAborted()) await onRunRef.current(ac.signal);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (!disposeAborted() && !stateRef.current.disposed) {
|
|
30
|
-
stateRef.current.pending = false;
|
|
31
|
-
if (ac.signal.aborted) onCancelRef.current?.();
|
|
32
|
-
else await onErrorRef.current?.(error);
|
|
33
|
-
}
|
|
34
|
-
} finally {
|
|
35
|
-
if (!disposeAborted() && !stateRef.current.disposed) try {
|
|
36
|
-
Promise.resolve(onFinishRef.current?.()).catch(reportFinishError);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
reportFinishError(error);
|
|
39
|
-
}
|
|
40
|
-
if (!stateRef.current.disposed && stateRef.current.pending) startRun();
|
|
41
|
-
else {
|
|
42
|
-
setIsRunning(false);
|
|
43
|
-
if (stateRef.current.abortController === ac) stateRef.current.abortController = null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}, [
|
|
48
|
-
onRunRef,
|
|
49
|
-
onFinishRef,
|
|
50
|
-
onErrorRef,
|
|
51
|
-
onCancelRef
|
|
52
|
-
]);
|
|
53
|
-
const schedule = useCallback(() => {
|
|
54
|
-
if (stateRef.current.disposed) return;
|
|
55
|
-
if (stateRef.current.abortController) {
|
|
56
|
-
stateRef.current.pending = true;
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
startRun();
|
|
60
|
-
}, [startRun]);
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
stateRef.current.disposed = false;
|
|
63
|
-
return () => {
|
|
64
|
-
stateRef.current.disposed = true;
|
|
65
|
-
stateRef.current.pending = false;
|
|
66
|
-
stateRef.current.abortController?.abort(disposeReason);
|
|
67
|
-
};
|
|
68
|
-
}, []);
|
|
69
|
-
return {
|
|
70
|
-
isRunning,
|
|
71
|
-
schedule,
|
|
72
|
-
cancel: useCallback(() => {
|
|
73
|
-
stateRef.current.pending = false;
|
|
74
|
-
stateRef.current.abortController?.abort();
|
|
75
|
-
}, [])
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
export { useRunManager };
|
|
80
|
-
|
|
81
|
-
//# sourceMappingURL=runManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runManager.js","names":["useCallback","useEffect","useRef","useState","useLatestRef","RunManager","Readonly","isRunning","schedule","cancel","disposeReason","Symbol","reportFinishError","error","console","useRunManager","config","onRun","signal","AbortSignal","Promise","onFinish","onCancel","onError","Error","setIsRunning","stateRef","pending","disposed","abortController","AbortController","onRunRef","onFinishRef","onCancelRef","onErrorRef","startRun","current","ac","disposeAborted","reason","queueMicrotask","aborted","resolve","catch","abort"],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useLatestRef } from \"./useLatestRef\";\n\nexport type RunManager = Readonly<{\n isRunning: boolean;\n schedule: () => void;\n cancel: () => void;\n}>;\n\nconst disposeReason = Symbol(\"assistant-transport-dispose\");\n\nconst reportFinishError = (error: unknown) => {\n console.error(\n \"[assistant-ui] Assistant transport onFinish callback threw an error\",\n error,\n );\n};\n\nexport function useRunManager(config: {\n onRun: (signal: AbortSignal) => Promise<void>;\n onFinish?: (() => void) | undefined;\n onCancel?: (() => void) | undefined;\n onError?: ((error: Error) => void | Promise<void>) | undefined;\n}): RunManager {\n const [isRunning, setIsRunning] = useState(false);\n const stateRef = useRef({\n pending: false,\n disposed: false,\n abortController: null as AbortController | null,\n });\n const onRunRef = useLatestRef(config.onRun);\n const onFinishRef = useLatestRef(config.onFinish);\n const onCancelRef = useLatestRef(config.onCancel);\n const onErrorRef = useLatestRef(config.onError);\n\n const startRun = useCallback(() => {\n setIsRunning(true);\n stateRef.current.pending = false;\n const ac = new AbortController();\n stateRef.current.abortController = ac;\n\n // The dispose marker rides on the abort reason so a settling run detects\n // its own disposal even after an effect cycle re-arms the manager.\n const disposeAborted = () => ac.signal.reason === disposeReason;\n\n queueMicrotask(async () => {\n try {\n if (!disposeAborted()) {\n await onRunRef.current(ac.signal);\n }\n } catch (error) {\n if (!disposeAborted() && !stateRef.current.disposed) {\n stateRef.current.pending = false;\n if (ac.signal.aborted) {\n onCancelRef.current?.();\n } else {\n await onErrorRef.current?.(error as Error);\n }\n }\n } finally {\n if (!disposeAborted() && !stateRef.current.disposed) {\n try {\n void Promise.resolve(onFinishRef.current?.()).catch(\n reportFinishError,\n );\n } catch (error) {\n reportFinishError(error);\n }\n }\n if (!stateRef.current.disposed && stateRef.current.pending) {\n startRun();\n } else {\n setIsRunning(false);\n if (stateRef.current.abortController === ac) {\n stateRef.current.abortController = null;\n }\n }\n }\n });\n }, [onRunRef, onFinishRef, onErrorRef, onCancelRef]);\n\n const schedule = useCallback(() => {\n if (stateRef.current.disposed) return;\n if (stateRef.current.abortController) {\n // Coalesce multiple schedules while running into a single follow-up run.\n stateRef.current.pending = true;\n return;\n }\n startRun();\n }, [startRun]);\n\n // Strict-mode effects run setup / cleanup / setup on the same instance;\n // arming on setup undoes the cleanup's dispose.\n useEffect(() => {\n stateRef.current.disposed = false;\n return () => {\n stateRef.current.disposed = true;\n stateRef.current.pending = false;\n stateRef.current.abortController?.abort(disposeReason);\n };\n }, []);\n\n const cancel = useCallback(() => {\n stateRef.current.pending = false;\n stateRef.current.abortController?.abort();\n }, []);\n\n return {\n isRunning,\n schedule,\n cancel,\n };\n}\n"],"mappings":";;;AASA,MAAMU,gBAAgBC,OAAO,6BAA6B;AAE1D,MAAMC,qBAAqBC,UAAmB;CAC5CC,QAAQD,MACN,uEACAA,KACF;AACF;AAEA,SAAgBE,cAAcC,QAKf;CACb,MAAM,CAACT,WAAWkB,gBAAgBtB,SAAS,KAAK;CAChD,MAAMuB,WAAWxB,OAAO;EACtByB,SAAS;EACTC,UAAU;EACVC,iBAAiB;CACnB,CAAC;CACD,MAAME,WAAW3B,aAAaY,OAAOC,KAAK;CAC1C,MAAMe,cAAc5B,aAAaY,OAAOK,QAAQ;CAChD,MAAMY,cAAc7B,aAAaY,OAAOM,QAAQ;CAChD,MAAMY,aAAa9B,aAAaY,OAAOO,OAAO;CAE9C,MAAMY,WAAWnC,kBAAkB;EACjCyB,aAAa,IAAI;EACjBC,SAASU,QAAQT,UAAU;EAC3B,MAAMU,KAAK,IAAIP,gBAAgB;EAC/BJ,SAASU,QAAQP,kBAAkBQ;EAInC,MAAMC,uBAAuBD,GAAGnB,OAAOqB,WAAW7B;EAElD8B,eAAe,YAAY;GACzB,IAAI;IACF,IAAI,CAACF,eAAe,GAClB,MAAMP,SAASK,QAAQC,GAAGnB,MAAM;GAEpC,SAASL,OAAO;IACd,IAAI,CAACyB,eAAe,KAAK,CAACZ,SAASU,QAAQR,UAAU;KACnDF,SAASU,QAAQT,UAAU;KAC3B,IAAIU,GAAGnB,OAAOuB,SACZR,YAAYG,UAAU;UAEtB,MAAMF,WAAWE,UAAUvB,KAAc;IAE7C;GACF,UAAU;IACR,IAAI,CAACyB,eAAe,KAAK,CAACZ,SAASU,QAAQR,UACzC,IAAI;KACF,QAAac,QAAQV,YAAYI,UAAU,CAAC,CAAC,CAACO,MAC5C/B,iBACF;IACF,SAASC,OAAO;KACdD,kBAAkBC,KAAK;IACzB;IAEF,IAAI,CAACa,SAASU,QAAQR,YAAYF,SAASU,QAAQT,SACjDQ,SAAS;SACJ;KACLV,aAAa,KAAK;KAClB,IAAIC,SAASU,QAAQP,oBAAoBQ,IACvCX,SAASU,QAAQP,kBAAkB;IAEvC;GACF;EACF,CAAC;CACH,GAAG;EAACE;EAAUC;EAAaE;EAAYD;CAAW,CAAC;CAEnD,MAAMzB,WAAWR,kBAAkB;EACjC,IAAI0B,SAASU,QAAQR,UAAU;EAC/B,IAAIF,SAASU,QAAQP,iBAAiB;GAEpCH,SAASU,QAAQT,UAAU;GAC3B;EACF;EACAQ,SAAS;CACX,GAAG,CAACA,QAAQ,CAAC;CAIblC,gBAAgB;EACdyB,SAASU,QAAQR,WAAW;EAC5B,aAAa;GACXF,SAASU,QAAQR,WAAW;GAC5BF,SAASU,QAAQT,UAAU;GAC3BD,SAASU,QAAQP,iBAAiBe,MAAMlC,aAAa;EACvD;CACF,GAAG,CAAA,CAAE;CAOL,OAAO;EACLH;EACAC;EACAC,QARaT,kBAAkB;GAC/B0B,SAASU,QAAQT,UAAU;GAC3BD,SAASU,QAAQP,iBAAiBe,MAAM;EAC1C,GAAG,CAAA,CAKDnC;CACF;AACF"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { UserCommands } from "../../../augmentations.js";
|
|
2
|
-
import { AttachmentAdapter, LanguageModelConfig, LanguageModelV1CallSettings, ThreadHistoryAdapter, ThreadMessage, ToolExecutionStatus } from "@assistant-ui/core";
|
|
3
|
-
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
4
|
-
import { ToolModelContentPart } from "assistant-stream";
|
|
5
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/types.d.ts
|
|
6
|
-
type TextPart = {
|
|
7
|
-
readonly type: "text";
|
|
8
|
-
readonly text: string;
|
|
9
|
-
};
|
|
10
|
-
type ImagePart = {
|
|
11
|
-
readonly type: "image";
|
|
12
|
-
readonly image: string;
|
|
13
|
-
};
|
|
14
|
-
type UserMessagePart = TextPart | ImagePart;
|
|
15
|
-
type UserMessage = {
|
|
16
|
-
readonly role: "user";
|
|
17
|
-
readonly parts: readonly UserMessagePart[];
|
|
18
|
-
};
|
|
19
|
-
type AssistantMessage = {
|
|
20
|
-
readonly role: "assistant";
|
|
21
|
-
readonly parts: readonly TextPart[];
|
|
22
|
-
};
|
|
23
|
-
type AddMessageCommand = {
|
|
24
|
-
readonly type: "add-message";
|
|
25
|
-
readonly message: UserMessage | AssistantMessage;
|
|
26
|
-
readonly parentId: string | null;
|
|
27
|
-
readonly sourceId: string | null;
|
|
28
|
-
};
|
|
29
|
-
type AddToolResultCommand = {
|
|
30
|
-
readonly type: "add-tool-result";
|
|
31
|
-
readonly toolCallId: string;
|
|
32
|
-
readonly toolName: string;
|
|
33
|
-
readonly result: ReadonlyJSONValue;
|
|
34
|
-
readonly isError: boolean;
|
|
35
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
36
|
-
readonly modelContent?: readonly ToolModelContentPart[];
|
|
37
|
-
};
|
|
38
|
-
type AssistantTransportCommand = AddMessageCommand | AddToolResultCommand | UserCommands;
|
|
39
|
-
type AssistantTransportState = {
|
|
40
|
-
readonly messages: readonly ThreadMessage[];
|
|
41
|
-
readonly state?: ReadonlyJSONValue;
|
|
42
|
-
readonly isRunning: boolean;
|
|
43
|
-
};
|
|
44
|
-
type AssistantTransportConnectionMetadata = {
|
|
45
|
-
pendingCommands: AssistantTransportCommand[];
|
|
46
|
-
isSending: boolean;
|
|
47
|
-
toolStatuses: Record<string, ToolExecutionStatus>;
|
|
48
|
-
};
|
|
49
|
-
type AssistantTransportStateConverter<T> = (state: T, connectionMetadata: AssistantTransportConnectionMetadata) => AssistantTransportState;
|
|
50
|
-
type CommandQueueState = {
|
|
51
|
-
queued: AssistantTransportCommand[];
|
|
52
|
-
inTransit: AssistantTransportCommand[];
|
|
53
|
-
};
|
|
54
|
-
type QueuedCommand = AssistantTransportCommand;
|
|
55
|
-
type HeadersValue = Record<string, string> | Headers;
|
|
56
|
-
type AssistantTransportProtocol = "data-stream" | "assistant-transport";
|
|
57
|
-
type SendCommandsRequestBody = {
|
|
58
|
-
commands: QueuedCommand[];
|
|
59
|
-
/** Absent on a resume with `resumeStateApi`; the server replays from its retained snapshot. */
|
|
60
|
-
state?: unknown;
|
|
61
|
-
runId?: string;
|
|
62
|
-
system: string | undefined;
|
|
63
|
-
tools: Record<string, unknown> | undefined;
|
|
64
|
-
callSettings: LanguageModelV1CallSettings | undefined;
|
|
65
|
-
config: LanguageModelConfig | undefined;
|
|
66
|
-
threadId: string | null;
|
|
67
|
-
parentId?: string | null;
|
|
68
|
-
[key: string]: unknown;
|
|
69
|
-
};
|
|
70
|
-
type AssistantTransportOptions<T> = {
|
|
71
|
-
initialState: T;
|
|
72
|
-
api: string;
|
|
73
|
-
resumeApi?: string;
|
|
74
|
-
/** Endpoint that returns the retained initial state and run ID for a resume stream. A 204 response means no run is active and the resume is skipped. */
|
|
75
|
-
resumeStateApi?: string;
|
|
76
|
-
protocol?: AssistantTransportProtocol;
|
|
77
|
-
/**
|
|
78
|
-
* When `false`, stream decoding and state reconciliation tolerate malformed
|
|
79
|
-
* input (invalid chunks are dropped with a console log) instead of throwing.
|
|
80
|
-
* Resume runs always decode leniently. Defaults to `true`.
|
|
81
|
-
*/
|
|
82
|
-
strict?: boolean;
|
|
83
|
-
converter: AssistantTransportStateConverter<T>;
|
|
84
|
-
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
85
|
-
body?: object | (() => Promise<object | undefined>);
|
|
86
|
-
/**
|
|
87
|
-
* Transform the request body before it is sent to the API.
|
|
88
|
-
* Receives the fully assembled body and returns the (potentially transformed) body.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* prepareSendCommandsRequest: (body) => ({
|
|
93
|
-
* ...body,
|
|
94
|
-
* trackingId: crypto.randomUUID(),
|
|
95
|
-
* })
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
prepareSendCommandsRequest?: (body: SendCommandsRequestBody) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
99
|
-
onResponse?: (response: Response) => void;
|
|
100
|
-
onFinish?: () => void;
|
|
101
|
-
onError?: (error: Error, params: {
|
|
102
|
-
commands: AssistantTransportCommand[];
|
|
103
|
-
updateState: (updater: (state: T) => T) => void;
|
|
104
|
-
}) => void | Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Called when commands are cancelled.
|
|
107
|
-
*
|
|
108
|
-
* When an error occurs, queued commands are automatically cancelled after `onError` settles.
|
|
109
|
-
* In this case, the `error` parameter contains the error that caused the cancellation.
|
|
110
|
-
*/
|
|
111
|
-
onCancel?: (params: {
|
|
112
|
-
commands: AssistantTransportCommand[];
|
|
113
|
-
updateState: (updater: (state: T) => T) => void;
|
|
114
|
-
error?: Error;
|
|
115
|
-
}) => void;
|
|
116
|
-
capabilities?: {
|
|
117
|
-
edit?: boolean;
|
|
118
|
-
};
|
|
119
|
-
adapters?: {
|
|
120
|
-
attachments?: AttachmentAdapter | undefined;
|
|
121
|
-
history?: ThreadHistoryAdapter | undefined;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
//#endregion
|
|
125
|
-
export { AddMessageCommand, AddToolResultCommand, AssistantMessage, AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, CommandQueueState, HeadersValue, ImagePart, QueuedCommand, SendCommandsRequestBody, TextPart, UserMessage, UserMessagePart };
|
|
126
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/types.ts"],"mappings":";;;;;KAaY;WACD;WACA;;KAGC;WACD;WACA;;KAGC,kBAAkB,WAAW;KAE7B;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,gBAAgB;;KAIf;WACD;WACA,SAAS,cAAc;WACvB;WACA;;KAGC;WACD;WACA;WACA;WACA,QAAQ;WACR;WACA,WAAW;WACX,wBAAwB;;KAGvB,4BACR,oBACA,uBACA;KAGQ;WACD,mBAAmB;WACnB,QAAQ;WACR;;KAGC;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAGO;EACV,QAAQ;EACR,WAAW;;KAID,gBAAgB;KAKhB,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;;EAEV;EACA;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GAIC;;KAGS,0BAA0B;EACpC,cAAc;EACd;EACA;;EAEA;EACA,WAAW;;;;;;EAMX;EACA,WAAW,iCAAiC;EAC5C,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;;;;;;;;;;;;EAavB,8BACE,MAAM,4BACH,0BAA0B,QAAQ;EACvC,cAAc,UAAU;EACxB;EACA,WACE,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;;;EAOZ,YAAY;IACV,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAEV;IACE;;EAEF;IACE,cAAc;IACd,UAAU"}
|
|
File without changes
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { UserExternalState } from "../../../augmentations.js";
|
|
2
|
-
import { AssistantRuntime } from "../../runtime/AssistantRuntime.js";
|
|
3
|
-
import { AssistantTransportCommand, AssistantTransportOptions } from "./types.js";
|
|
4
|
-
//#region src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts
|
|
5
|
-
declare const useAssistantTransportSendCommand: () => (command: AssistantTransportCommand) => void;
|
|
6
|
-
declare function useAssistantTransportState(): UserExternalState;
|
|
7
|
-
declare function useAssistantTransportState<T>(selector: (state: UserExternalState) => T): T;
|
|
8
|
-
/**
|
|
9
|
-
* @alpha This is an experimental API that is subject to change.
|
|
10
|
-
*/
|
|
11
|
-
declare const useAssistantTransportRuntime: <T>(options: AssistantTransportOptions<T>) => AssistantRuntime;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState };
|
|
14
|
-
//# sourceMappingURL=useAssistantTransportRuntime.d.ts.map
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantTransportRuntime.d.ts","names":[],"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts"],"mappings":";;;;cA8Ha,yCAGH,SAAS;iBAOH,8BAA8B;iBAC9B,2BAA2B,GACzC,WAAW,OAAO,sBAAsB,IACvC;;;;cAqUU,+BAAgC,GAC3C,SAAS,0BAA0B,OAClC"}
|