@assistant-ui/react 0.11.45 → 0.11.46

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.
Files changed (26) hide show
  1. package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
  2. package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.js +2 -1
  3. package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.js.map +1 -1
  4. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  5. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +2 -1
  6. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  7. package/dist/legacy-runtime/runtime-cores/local/index.d.ts +1 -1
  8. package/dist/legacy-runtime/runtime-cores/local/index.d.ts.map +1 -1
  9. package/dist/legacy-runtime/runtime-cores/local/index.js +2 -3
  10. package/dist/legacy-runtime/runtime-cores/local/index.js.map +1 -1
  11. package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts +0 -2
  12. package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts.map +1 -1
  13. package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js +3 -3
  14. package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js.map +1 -1
  15. package/dist/legacy-runtime/runtime-cores/remote-thread-list/types.d.ts +6 -0
  16. package/dist/legacy-runtime/runtime-cores/remote-thread-list/types.d.ts.map +1 -1
  17. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
  18. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js +15 -1
  19. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/legacy-runtime/cloud/useCloudThreadListRuntime.tsx +1 -0
  22. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +1 -0
  23. package/src/legacy-runtime/runtime-cores/local/index.ts +1 -1
  24. package/src/legacy-runtime/runtime-cores/local/useLocalRuntime.tsx +2 -1
  25. package/src/legacy-runtime/runtime-cores/remote-thread-list/types.tsx +7 -0
  26. package/src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx +25 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useCloudThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/cloud/useCloudThreadListRuntime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9C,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IAEtB,WAAW,EAAE,MAAM,gBAAgB,CAAC;IAEpC,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,oCAGvC,sBAAsB,qBAQxB,CAAC"}
1
+ {"version":3,"file":"useCloudThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/cloud/useCloudThreadListRuntime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9C,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IAEtB,WAAW,EAAE,MAAM,gBAAgB,CAAC;IAEpC,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,oCAGvC,sBAAsB,qBASxB,CAAC"}
@@ -10,7 +10,8 @@ var useCloudThreadListRuntime = ({
10
10
  const adapter = useCloudThreadListAdapter(adapterOptions);
11
11
  const runtime = useRemoteThreadListRuntime({
12
12
  runtimeHook,
13
- adapter
13
+ adapter,
14
+ allowNesting: true
14
15
  });
15
16
  return runtime;
16
17
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/legacy-runtime/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { AssistantRuntime } from \"../runtime\";\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 const useCloudThreadListRuntime = ({\n runtimeHook,\n ...adapterOptions\n}: CloudThreadListAdapter) => {\n const adapter = useCloudThreadListAdapter(adapterOptions);\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: runtimeHook,\n adapter,\n });\n\n return runtime;\n};\n"],"mappings":";;;AAIA,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAenC,IAAM,4BAA4B,CAAC;AAAA,EACxC;AAAA,EACA,GAAG;AACL,MAA8B;AAC5B,QAAM,UAAU,0BAA0B,cAAc;AACxD,QAAM,UAAU,2BAA2B;AAAA,IACzC;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/legacy-runtime/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { AssistantRuntime } from \"../runtime\";\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 const useCloudThreadListRuntime = ({\n runtimeHook,\n ...adapterOptions\n}: CloudThreadListAdapter) => {\n const adapter = useCloudThreadListAdapter(adapterOptions);\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: runtimeHook,\n adapter,\n allowNesting: true,\n });\n\n return runtime;\n};\n"],"mappings":";;;AAIA,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAenC,IAAM,4BAA4B,CAAC;AAAA,EACxC;AAAA,EACA,GAAG;AACL,MAA8B;AAC5B,QAAM,UAAU,0BAA0B,cAAc;AACxD,QAAM,UAAU,2BAA2B;AAAA,IACzC;AAAA,IACA;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AAED,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useAssistantTransportRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AASlE,OAAO,EACL,yBAAyB,EAKzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AASjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D,eAAO,MAAM,gCAAgC,SAGnC,SAAS,yBAAyB,SAK3C,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,iBAAiB,CAAC;AAChE,wBAAgB,0BAA0B,CAAC,CAAC,EAC1C,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,CAAC,GACxC,CAAC,CAAC;AAqPL;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,EAC5C,SAAS,yBAAyB,CAAC,CAAC,CAAC,KACpC,gBAQF,CAAC"}
1
+ {"version":3,"file":"useAssistantTransportRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AASlE,OAAO,EACL,yBAAyB,EAKzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AASjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D,eAAO,MAAM,gCAAgC,SAGnC,SAAS,yBAAyB,SAK3C,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,iBAAiB,CAAC;AAChE,wBAAgB,0BAA0B,CAAC,CAAC,EAC1C,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,CAAC,GACxC,CAAC,CAAC;AAqPL;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,EAC5C,SAAS,yBAAyB,CAAC,CAAC,CAAC,KACpC,gBASF,CAAC"}
@@ -236,7 +236,8 @@ var useAssistantTransportRuntime = (options) => {
236
236
  runtimeHook: function RuntimeHook() {
237
237
  return useAssistantTransportThreadRuntime(options);
238
238
  },
239
- adapter: new InMemoryThreadListAdapter()
239
+ adapter: new InMemoryThreadListAdapter(),
240
+ allowNesting: true
240
241
  });
241
242
  return runtime;
242
243
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReadonlyJSONObject,\n type ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { AppendMessage } from \"../../../types\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport { AddToolResultOptions } from \"../core\";\nimport { useState, useRef, useMemo } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n AssistantTransportDecoder,\n unstable_createInitialMessage as createInitialMessage,\n} from \"assistant-stream\";\nimport {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n AssistantTransportCommand,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport { ToolExecutionStatus, useToolInvocations } from \"./useToolInvocations\";\nimport { toAISDKTools, getEnabledTools, createRequestHeaders } from \"./utils\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"../remote-thread-list/adapter/in-memory\";\nimport { useAssistantApi, useAssistantState } from \"../../../context/react\";\nimport { UserExternalState } from \"../../../augmentations\";\n\nconst symbolAssistantTransportExtras = Symbol(\"assistant-transport-extras\");\ntype AssistantTransportExtras = {\n [symbolAssistantTransportExtras]: true;\n sendCommand: (command: AssistantTransportCommand) => void;\n state: UserExternalState;\n};\n\nconst asAssistantTransportExtras = (\n extras: unknown,\n): AssistantTransportExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolAssistantTransportExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useAssistantTransportRuntime\",\n );\n\n return extras as AssistantTransportExtras;\n};\n\nexport const useAssistantTransportSendCommand = () => {\n const api = useAssistantApi();\n\n return (command: AssistantTransportCommand) => {\n const extras = api.thread().getState().extras;\n const transportExtras = asAssistantTransportExtras(extras);\n transportExtras.sendCommand(command);\n };\n};\n\nexport function useAssistantTransportState(): UserExternalState;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T,\n): T;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T = (t) => t as T,\n): T | UserExternalState {\n return useAssistantState(({ thread }) =>\n selector(asAssistantTransportExtras(thread.extras).state),\n );\n}\n\nconst useAssistantTransportThreadRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume)\n throw new Error(\"No commands to send\");\n\n const headers = await createRequestHeaders(options.headers);\n const context = runtime.thread.getModelContext();\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n commands,\n state: agentStateRef.current,\n system: context.system,\n tools: context.tools\n ? toAISDKTools(getEnabledTools(context.tools))\n : undefined,\n ...context.callSettings,\n ...context.config,\n ...options.body,\n }),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Select decoder based on protocol option\n const protocol = options.protocol ?? \"data-stream\";\n const decoder =\n protocol === \"assistant-transport\"\n ? new AssistantTransportDecoder()\n : new DataStreamDecoder();\n\n let err: string | undefined;\n const stream = response.body.pipeThrough(decoder).pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n throttle: isResume,\n onError: (error) => {\n err = error;\n },\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n\n if (err) {\n throw new Error(err);\n }\n },\n onFinish: options.onFinish,\n onCancel: () => {\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n\n commandQueue.reset();\n\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n },\n onError: async (error) => {\n const inTransitCmds = [...commandQueue.state.inTransit];\n const queuedCmds = [...commandQueue.state.queued];\n\n commandQueue.reset();\n\n try {\n await options.onError?.(error as Error, {\n commands: inTransitCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n } finally {\n options.onCancel?.({\n commands: queuedCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n error: error as Error,\n });\n }\n },\n });\n\n // Tool execution status state\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n toolStatuses,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n messages: converted.messages,\n state: converted.state,\n isRunning: converted.isRunning,\n adapters: options.adapters,\n extras: {\n [symbolAssistantTransportExtras]: true,\n sendCommand: (command: AssistantTransportCommand) => {\n commandQueue.enqueue(command);\n },\n state: agentStateRef.current as UserExternalState,\n } satisfies AssistantTransportExtras,\n onNew: async (message: AppendMessage): Promise<void> => {\n if (message.role !== \"user\")\n throw new Error(\"Only user messages are supported\");\n\n // Convert AppendMessage to AddMessageCommand\n const parts: UserMessagePart[] = [];\n\n const content = [\n ...message.content,\n ...(message.attachments?.flatMap((a) => a.content) ?? []),\n ];\n for (const contentPart of content) {\n if (contentPart.type === \"text\") {\n parts.push({ type: \"text\", text: contentPart.text });\n } else if (contentPart.type === \"image\") {\n parts.push({ type: \"image\", image: contentPart.image });\n }\n }\n\n const command: AddMessageCommand = {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n };\n\n commandQueue.enqueue(command);\n },\n onCancel: async () => {\n runManager.cancel();\n toolInvocations.abort();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n toolInvocations.reset();\n rerender((prev) => prev + 1);\n },\n });\n\n const toolInvocations = useToolInvocations({\n state: converted,\n getTools: () => runtime.thread.getModelContext().tools,\n onResult: commandQueue.enqueue,\n setToolStatuses,\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n });\n return runtime;\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,+BAA+B;AAGxC,SAAS,UAAU,QAAQ,e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A+C;AAEjE,oBAAc,UAAU;AACxB,iBAAW,SAAS;AAAA,IACtB;AAAA,IACA,iBAAiB,OACf,gBACkB;AAClB,YAAM,UAAgC;AAAA,QACpC,MAAM;AAAA,QACN,YAAY,YAAY;AAAA,QACxB,QAAQ,YAAY;AAAA,QACpB,UAAU,YAAY;AAAA,QACtB,SAAS,YAAY;AAAA,QACrB,GAAI,YAAY,YAAY,EAAE,UAAU,YAAY,SAAS;AAAA,MAC/D;AAEA,mBAAa,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,qBAAqB,OAAO,UAAU;AACpC,oBAAc,UAAU;AACxB,sBAAgB,MAAM;AACtB,eAAS,CAAC,SAAS,OAAO,CAAC;AAAA,IAC7B;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB;AAAA,IACzC,OAAO;AAAA,IACP,UAAU,MAAM,QAAQ,OAAO,gBAAgB,EAAE;AAAA,IACjD,UAAU,aAAa;AAAA,IACvB;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAKO,IAAM,+BAA+B,CAC1C,YACqB;AACrB,QAAM,UAAU,2BAA2B;AAAA,IACzC,aAAa,SAAS,cAAc;AAClC,aAAO,mCAAmC,OAAO;AAAA,IACnD;AAAA,IACA,SAAS,IAAI,0BAA0B;AAAA,EACzC,CAAC;AACD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReadonlyJSONObject,\n type ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { AppendMessage } from \"../../../types\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport { AddToolResultOptions } from \"../core\";\nimport { useState, useRef, useMemo } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n AssistantTransportDecoder,\n unstable_createInitialMessage as createInitialMessage,\n} from \"assistant-stream\";\nimport {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n AssistantTransportCommand,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport { ToolExecutionStatus, useToolInvocations } from \"./useToolInvocations\";\nimport { toAISDKTools, getEnabledTools, createRequestHeaders } from \"./utils\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"../remote-thread-list/adapter/in-memory\";\nimport { useAssistantApi, useAssistantState } from \"../../../context/react\";\nimport { UserExternalState } from \"../../../augmentations\";\n\nconst symbolAssistantTransportExtras = Symbol(\"assistant-transport-extras\");\ntype AssistantTransportExtras = {\n [symbolAssistantTransportExtras]: true;\n sendCommand: (command: AssistantTransportCommand) => void;\n state: UserExternalState;\n};\n\nconst asAssistantTransportExtras = (\n extras: unknown,\n): AssistantTransportExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolAssistantTransportExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useAssistantTransportRuntime\",\n );\n\n return extras as AssistantTransportExtras;\n};\n\nexport const useAssistantTransportSendCommand = () => {\n const api = useAssistantApi();\n\n return (command: AssistantTransportCommand) => {\n const extras = api.thread().getState().extras;\n const transportExtras = asAssistantTransportExtras(extras);\n transportExtras.sendCommand(command);\n };\n};\n\nexport function useAssistantTransportState(): UserExternalState;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T,\n): T;\nexport function useAssistantTransportState<T>(\n selector: (state: UserExternalState) => T = (t) => t as T,\n): T | UserExternalState {\n return useAssistantState(({ thread }) =>\n selector(asAssistantTransportExtras(thread.extras).state),\n );\n}\n\nconst useAssistantTransportThreadRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume)\n throw new Error(\"No commands to send\");\n\n const headers = await createRequestHeaders(options.headers);\n const context = runtime.thread.getModelContext();\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n commands,\n state: agentStateRef.current,\n system: context.system,\n tools: context.tools\n ? toAISDKTools(getEnabledTools(context.tools))\n : undefined,\n ...context.callSettings,\n ...context.config,\n ...options.body,\n }),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Select decoder based on protocol option\n const protocol = options.protocol ?? \"data-stream\";\n const decoder =\n protocol === \"assistant-transport\"\n ? new AssistantTransportDecoder()\n : new DataStreamDecoder();\n\n let err: string | undefined;\n const stream = response.body.pipeThrough(decoder).pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n throttle: isResume,\n onError: (error) => {\n err = error;\n },\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n\n if (err) {\n throw new Error(err);\n }\n },\n onFinish: options.onFinish,\n onCancel: () => {\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n\n commandQueue.reset();\n\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n },\n onError: async (error) => {\n const inTransitCmds = [...commandQueue.state.inTransit];\n const queuedCmds = [...commandQueue.state.queued];\n\n commandQueue.reset();\n\n try {\n await options.onError?.(error as Error, {\n commands: inTransitCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n } finally {\n options.onCancel?.({\n commands: queuedCmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n error: error as Error,\n });\n }\n },\n });\n\n // Tool execution status state\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n toolStatuses,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n messages: converted.messages,\n state: converted.state,\n isRunning: converted.isRunning,\n adapters: options.adapters,\n extras: {\n [symbolAssistantTransportExtras]: true,\n sendCommand: (command: AssistantTransportCommand) => {\n commandQueue.enqueue(command);\n },\n state: agentStateRef.current as UserExternalState,\n } satisfies AssistantTransportExtras,\n onNew: async (message: AppendMessage): Promise<void> => {\n if (message.role !== \"user\")\n throw new Error(\"Only user messages are supported\");\n\n // Convert AppendMessage to AddMessageCommand\n const parts: UserMessagePart[] = [];\n\n const content = [\n ...message.content,\n ...(message.attachments?.flatMap((a) => a.content) ?? []),\n ];\n for (const contentPart of content) {\n if (contentPart.type === \"text\") {\n parts.push({ type: \"text\", text: contentPart.text });\n } else if (contentPart.type === \"image\") {\n parts.push({ type: \"image\", image: contentPart.image });\n }\n }\n\n const command: AddMessageCommand = {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n };\n\n commandQueue.enqueue(command);\n },\n onCancel: async () => {\n runManager.cancel();\n toolInvocations.abort();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n toolInvocations.reset();\n rerender((prev) => prev + 1);\n },\n });\n\n const toolInvocations = useToolInvocations({\n state: converted,\n getTools: () => runtime.thread.getModelContext().tools,\n onResult: commandQueue.enqueue,\n setToolStatuses,\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n allowNesting: true,\n });\n return runtime;\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,+BAA+B;AAGxC,SAAS,UAAU,QAAQ,eAAe;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,iCAAiC;AAAA,OAC5B;AASP,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAA8B,0BAA0B;AACxD,SAAS,cAAc,iBAAiB,4BAA4B;AACpE,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAG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AAS;AAAA,MAC/D;AAEA,mBAAa,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,qBAAqB,OAAO,UAAU;AACpC,oBAAc,UAAU;AACxB,sBAAgB,MAAM;AACtB,eAAS,CAAC,SAAS,OAAO,CAAC;AAAA,IAC7B;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB;AAAA,IACzC,OAAO;AAAA,IACP,UAAU,MAAM,QAAQ,OAAO,gBAAgB,EAAE;AAAA,IACjD,UAAU,aAAa;AAAA,IACvB;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAKO,IAAM,+BAA+B,CAC1C,YACqB;AACrB,QAAM,UAAU,2BAA2B;AAAA,IACzC,aAAa,SAAS,cAAc;AAClC,aAAO,mCAAmC,OAAO;AAAA,IACnD;AAAA,IACA,SAAS,IAAI,0BAA0B;AAAA,IACvC,cAAc;AAAA,EAChB,CAAC;AACD,SAAO;AACT;","names":[]}
@@ -1,4 +1,4 @@
1
- export { useLocalRuntime, useLocalThreadRuntime } from "./useLocalRuntime";
1
+ export { useLocalRuntime } from "./useLocalRuntime";
2
2
  export type { LocalRuntimeOptions } from "./LocalRuntimeOptions";
3
3
  export type { ChatModelAdapter, ChatModelRunOptions, ChatModelRunResult, ChatModelRunUpdate, } from "./ChatModelAdapter";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  // src/legacy-runtime/runtime-cores/local/index.ts
2
- import { useLocalRuntime, useLocalThreadRuntime } from "./useLocalRuntime.js";
2
+ import { useLocalRuntime } from "./useLocalRuntime.js";
3
3
  export {
4
- useLocalRuntime,
5
- useLocalThreadRuntime
4
+ useLocalRuntime
6
5
  };
7
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/local/index.ts"],"sourcesContent":["export { useLocalRuntime, useLocalThreadRuntime } from \"./useLocalRuntime\";\nexport type { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nexport type {\n ChatModelAdapter,\n ChatModelRunOptions,\n ChatModelRunResult,\n ChatModelRunUpdate,\n} from \"./ChatModelAdapter\";\n"],"mappings":";AAAA,SAAS,iBAAiB,6BAA6B;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/local/index.ts"],"sourcesContent":["export { useLocalRuntime } from \"./useLocalRuntime\";\nexport type { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nexport type {\n ChatModelAdapter,\n ChatModelRunOptions,\n ChatModelRunResult,\n ChatModelRunUpdate,\n} from \"./ChatModelAdapter\";\n"],"mappings":";AAAA,SAAS,uBAAuB;","names":[]}
@@ -1,6 +1,4 @@
1
1
  import type { ChatModelAdapter } from "./ChatModelAdapter";
2
2
  import type { LocalRuntimeOptions } from "./LocalRuntimeOptions";
3
- import { AssistantRuntimeImpl } from "../../../internal";
4
- export declare const useLocalThreadRuntime: (adapter: ChatModelAdapter, { initialMessages, ...options }: LocalRuntimeOptions) => AssistantRuntimeImpl;
5
3
  export declare const useLocalRuntime: (adapter: ChatModelAdapter, { cloud, ...options }?: LocalRuntimeOptions) => import("../../runtime").AssistantRuntime;
6
4
  //# sourceMappingURL=useLocalRuntime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,eAAO,MAAM,qBAAqB,GAChC,SAAS,gBAAgB,EACzB,iCAAiC,mBAAmB,yBAkCrD,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,SAAS,gBAAgB,EACzB,wBAAuB,mBAAwB,6CAShD,CAAC"}
1
+ {"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AA4CjE,eAAO,MAAM,eAAe,GAC1B,SAAS,gBAAgB,EACzB,wBAAuB,mBAAwB,6CAUhD,CAAC"}
@@ -42,11 +42,11 @@ var useLocalRuntime = (adapter, { cloud, ...options } = {}) => {
42
42
  runtimeHook: function RuntimeHook() {
43
43
  return useLocalThreadRuntime(adapter, options);
44
44
  },
45
- adapter: cloudAdapter
45
+ adapter: cloudAdapter,
46
+ allowNesting: true
46
47
  });
47
48
  };
48
49
  export {
49
- useLocalRuntime,
50
- useLocalThreadRuntime
50
+ useLocalRuntime
51
51
  };
52
52
  //# sourceMappingURL=useLocalRuntime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport type { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { useCloudThreadListAdapter } from \"../remote-thread-list/adapter/cloud\";\nimport { AssistantRuntimeImpl } from \"../../../internal\";\n\nexport const useLocalThreadRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions,\n) => {\n const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};\n const opt = useMemo(\n () => ({\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel: adapter,\n },\n }),\n [adapter, options, threadListAdapters],\n );\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n return () => {\n runtime.threads.getMainThreadRuntimeCore().detach();\n };\n }, [runtime]);\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n }, [runtime, opt]);\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { cloud, ...options }: LocalRuntimeOptions = {},\n) => {\n const cloudAdapter = useCloudThreadListAdapter({ cloud });\n return useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useLocalThreadRuntime(adapter, options);\n },\n adapter: cloudAdapter,\n });\n};\n"],"mappings":";;;AAEA,SAAS,WAAW,SAAS,gBAAgB;AA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,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntimeCore } from \"./LocalRuntimeCore\";\nimport type { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nimport { useRuntimeAdapters } from \"../adapters/RuntimeAdapterProvider\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { useCloudThreadListAdapter } from \"../remote-thread-list/adapter/cloud\";\nimport { AssistantRuntimeImpl } from \"../../../internal\";\n\nconst useLocalThreadRuntime = (\n adapter: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions,\n) => {\n const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};\n const opt = useMemo(\n () => ({\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel: adapter,\n },\n }),\n [adapter, options, threadListAdapters],\n );\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n useEffect(() => {\n return () => {\n runtime.threads.getMainThreadRuntimeCore().detach();\n };\n }, [runtime]);\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n }, [runtime, opt]);\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useLocalRuntime = (\n adapter: ChatModelAdapter,\n { cloud, ...options }: LocalRuntimeOptions = {},\n) => {\n const cloudAdapter = useCloudThreadListAdapter({ cloud });\n return useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useLocalThreadRuntime(adapter, options);\n },\n adapter: cloudAdapter,\n allowNesting: true,\n });\n};\n"],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AAO;AAAA,IAC/C;AAAA,IACA,SAAS;AAAA,IACT,cAAc;AAAA,EAChB,CAAC;AACH;","names":[]}
@@ -29,5 +29,11 @@ export type RemoteThreadListAdapter = {
29
29
  export type RemoteThreadListOptions = {
30
30
  runtimeHook: () => AssistantRuntime;
31
31
  adapter: RemoteThreadListAdapter;
32
+ /**
33
+ * When true, if this runtime is used inside another RemoteThreadListRuntime,
34
+ * it becomes a no-op and simply calls the runtimeHook directly.
35
+ * This allows wrapping runtimes that internally use RemoteThreadListRuntime.
36
+ */
37
+ allowNesting?: boolean | undefined;
32
38
  };
33
39
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/types.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,8BAA8B,GAAG;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,oBAAoB,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,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IG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRemoteThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAqBlE,eAAO,MAAM,0BAA0B,GACrC,SAAS,uBAAuB,KAC/B,gBAOF,CAAC"}
1
+ {"version":3,"file":"useRemoteThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAiClE,eAAO,MAAM,0BAA0B,GACrC,SAAS,uBAAuB,KAC/B,gBAmBF,CAAC"}
@@ -5,6 +5,7 @@ import { useState, useEffect, useMemo } from "react";
5
5
  import { BaseAssistantRuntimeCore } from "../core/BaseAssistantRuntimeCore.js";
6
6
  import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
7
7
  import { AssistantRuntimeImpl } from "../../../internal.js";
8
+ import { useAssistantApiImpl } from "../../../context/react/AssistantApiContext.js";
8
9
  var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
9
10
  threads;
10
11
  constructor(options) {
@@ -18,7 +19,7 @@ var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
18
19
  return this.threads.__internal_RenderComponent;
19
20
  }
20
21
  };
21
- var useRemoteThreadListRuntime = (options) => {
22
+ var useRemoteThreadListRuntimeImpl = (options) => {
22
23
  const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
23
24
  useEffect(() => {
24
25
  runtime.threads.__internal_setOptions(options);
@@ -26,6 +27,19 @@ var useRemoteThreadListRuntime = (options) => {
26
27
  }, [runtime, options]);
27
28
  return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
28
29
  };
30
+ var useRemoteThreadListRuntime = (options) => {
31
+ const api = useAssistantApiImpl();
32
+ const isNested = api.threadListItem.source !== null;
33
+ if (isNested) {
34
+ if (!options.allowNesting) {
35
+ throw new Error(
36
+ "useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. Set allowNesting: true to allow nesting (the inner runtime will become a no-op)."
37
+ );
38
+ }
39
+ return options.runtimeHook();
40
+ }
41
+ return useRemoteThreadListRuntimeImpl(options);
42
+ };
29
43
  export {
30
44
  useRemoteThreadListRuntime
31
45
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListOptions } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../../internal\";\nimport { AssistantRuntimeCore } from \"../core/AssistantRuntimeCore\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\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\nexport const useRemoteThreadListRuntime = (\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 return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n"],"mappings":";;;AAEA,SAAS,UAAU,WAAW,eAAe;AAC7C,SAAS,gCAAgC;AACzC,SAAS,6CAA6C;AAEtD,SAAS,4BAA4B;AAIrC,IAAM,8BAAN,cACU,yBAEV;AAAA,EACkB;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;AAEO,IAAM,6BAA6B,CACxC,YACqB;AACrB,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,4BAA4B,OAAO,CAAC;AACzE,YAAU,MAAM;AACd,YAAQ,QAAQ,sBAAsB,OAAO;AAC7C,YAAQ,QAAQ,gBAAgB;AAAA,EAClC,GAAG,CAAC,SAAS,OAAO,CAAC;AACrB,SAAO,QAAQ,MAAM,IAAI,qBAAqB,OAAO,GAAG,CAAC,OAAO,CAAC;AACnE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListOptions } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../../internal\";\nimport { AssistantRuntimeCore } from \"../core/AssistantRuntimeCore\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport { useAssistantApiImpl } from \"../../../context/react/AssistantApiContext\";\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 return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const api = useAssistantApiImpl();\n const isNested = api.threadListItem.source !== null;\n\n if (isNested) {\n if (!options.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 options.runtimeHook();\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useRemoteThreadListRuntimeImpl(options);\n};\n"],"mappings":";;;AAEA,SAAS,UAAU,WAAW,eAAe;AAC7C,SAAS,gCAAgC;AACzC,SAAS,6CAA6C;AAEtD,SAAS,4BAA4B;AAGrC,SAAS,2BAA2B;AAEpC,IAAM,8BAAN,cACU,yBAEV;AAAA,EACkB;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;AAEA,IAAM,iCAAiC,CACrC,YACqB;AACrB,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,4BAA4B,OAAO,CAAC;AACzE,YAAU,MAAM;AACd,YAAQ,QAAQ,sBAAsB,OAAO;AAC7C,YAAQ,QAAQ,gBAAgB;AAAA,EAClC,GAAG,CAAC,SAAS,OAAO,CAAC;AACrB,SAAO,QAAQ,MAAM,IAAI,qBAAqB,OAAO,GAAG,CAAC,OAAO,CAAC;AACnE;AAEO,IAAM,6BAA6B,CACxC,YACqB;AACrB,QAAM,MAAM,oBAAoB;AAChC,QAAM,WAAW,IAAI,eAAe,WAAW;AAE/C,MAAI,UAAU;AACZ,QAAI,CAAC,QAAQ,cAAc;AACzB,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AAIA,WAAO,QAAQ,YAAY;AAAA,EAC7B;AAGA,SAAO,+BAA+B,OAAO;AAC/C;","names":[]}
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.11.45",
31
+ "version": "0.11.46",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -26,6 +26,7 @@ export const useCloudThreadListRuntime = ({
26
26
  const runtime = useRemoteThreadListRuntime({
27
27
  runtimeHook: runtimeHook,
28
28
  adapter,
29
+ allowNesting: true,
29
30
  });
30
31
 
31
32
  return runtime;
@@ -325,6 +325,7 @@ export const useAssistantTransportRuntime = <T,>(
325
325
  return useAssistantTransportThreadRuntime(options);
326
326
  },
327
327
  adapter: new InMemoryThreadListAdapter(),
328
+ allowNesting: true,
328
329
  });
329
330
  return runtime;
330
331
  };
@@ -1,4 +1,4 @@
1
- export { useLocalRuntime, useLocalThreadRuntime } from "./useLocalRuntime";
1
+ export { useLocalRuntime } from "./useLocalRuntime";
2
2
  export type { LocalRuntimeOptions } from "./LocalRuntimeOptions";
3
3
  export type {
4
4
  ChatModelAdapter,
@@ -9,7 +9,7 @@ import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThrea
9
9
  import { useCloudThreadListAdapter } from "../remote-thread-list/adapter/cloud";
10
10
  import { AssistantRuntimeImpl } from "../../../internal";
11
11
 
12
- export const useLocalThreadRuntime = (
12
+ const useLocalThreadRuntime = (
13
13
  adapter: ChatModelAdapter,
14
14
  { initialMessages, ...options }: LocalRuntimeOptions,
15
15
  ) => {
@@ -57,5 +57,6 @@ export const useLocalRuntime = (
57
57
  return useLocalThreadRuntime(adapter, options);
58
58
  },
59
59
  adapter: cloudAdapter,
60
+ allowNesting: true,
60
61
  });
61
62
  };
@@ -39,4 +39,11 @@ export type RemoteThreadListAdapter = {
39
39
  export type RemoteThreadListOptions = {
40
40
  runtimeHook: () => AssistantRuntime;
41
41
  adapter: RemoteThreadListAdapter;
42
+
43
+ /**
44
+ * When true, if this runtime is used inside another RemoteThreadListRuntime,
45
+ * it becomes a no-op and simply calls the runtimeHook directly.
46
+ * This allows wrapping runtimes that internally use RemoteThreadListRuntime.
47
+ */
48
+ allowNesting?: boolean | undefined;
42
49
  };
@@ -7,6 +7,7 @@ import { RemoteThreadListOptions } from "./types";
7
7
  import { AssistantRuntimeImpl } from "../../../internal";
8
8
  import { AssistantRuntimeCore } from "../core/AssistantRuntimeCore";
9
9
  import { AssistantRuntime } from "../../runtime/AssistantRuntime";
10
+ import { useAssistantApiImpl } from "../../../context/react/AssistantApiContext";
10
11
 
11
12
  class RemoteThreadListRuntimeCore
12
13
  extends BaseAssistantRuntimeCore
@@ -27,7 +28,7 @@ class RemoteThreadListRuntimeCore
27
28
  }
28
29
  }
29
30
 
30
- export const useRemoteThreadListRuntime = (
31
+ const useRemoteThreadListRuntimeImpl = (
31
32
  options: RemoteThreadListOptions,
32
33
  ): AssistantRuntime => {
33
34
  const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
@@ -37,3 +38,26 @@ export const useRemoteThreadListRuntime = (
37
38
  }, [runtime, options]);
38
39
  return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
39
40
  };
41
+
42
+ export const useRemoteThreadListRuntime = (
43
+ options: RemoteThreadListOptions,
44
+ ): AssistantRuntime => {
45
+ const api = useAssistantApiImpl();
46
+ const isNested = api.threadListItem.source !== null;
47
+
48
+ if (isNested) {
49
+ if (!options.allowNesting) {
50
+ throw new Error(
51
+ "useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. " +
52
+ "Set allowNesting: true to allow nesting (the inner runtime will become a no-op).",
53
+ );
54
+ }
55
+
56
+ // If allowNesting is true and already inside a thread list context,
57
+ // just call the runtimeHook directly (no-op behavior)
58
+ return options.runtimeHook();
59
+ }
60
+
61
+ // eslint-disable-next-line react-hooks/rules-of-hooks
62
+ return useRemoteThreadListRuntimeImpl(options);
63
+ };