@assistant-ui/core 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/react/RuntimeAdapter.js +1 -1
- package/dist/react/RuntimeAdapter.js.map +1 -1
- package/dist/react/client/Interactables.js +1 -1
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts +1 -1
- package/dist/react/client/Tools.js +1 -1
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +9 -9
- package/dist/react/index.js +4 -4
- package/dist/react/model-context/interactableTool.d.ts +1 -1
- package/dist/react/model-context/useAssistantTool.d.ts +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +1 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +2 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts +1 -1
- package/dist/react/runtimes/createRuntimeExtras.d.ts +4 -1
- package/dist/react/runtimes/createRuntimeExtras.d.ts.map +1 -1
- package/dist/react/runtimes/createRuntimeExtras.js +6 -17
- package/dist/react/runtimes/createRuntimeExtras.js.map +1 -1
- package/dist/react/types/scopes/dataRenderers.d.ts +1 -1
- package/dist/react/types/scopes/interactables.d.ts +1 -1
- package/dist/react/types/scopes/tools.d.ts +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +0 -2
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +18 -25
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/utils/runtime-extras-brand.d.ts +21 -0
- package/dist/runtime/utils/runtime-extras-brand.d.ts.map +1 -0
- package/dist/runtime/utils/runtime-extras-brand.js +37 -0
- package/dist/runtime/utils/runtime-extras-brand.js.map +1 -0
- package/dist/runtime/utils/thread-message-like.js +3 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.js +1 -1
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/dist/store/clients/suggestions.js +1 -1
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/index.d.ts +10 -1
- package/dist/store/index.js +7 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/types/message.d.ts +1 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/package.json +3 -3
- package/src/react/RuntimeAdapter.test.ts +85 -0
- package/src/react/RuntimeAdapter.ts +1 -1
- package/src/react/client/Interactables.test.ts +3 -2
- package/src/react/client/Interactables.ts +4 -4
- package/src/react/client/Tools.ts +4 -4
- package/src/react/index.ts +1 -0
- package/src/react/runtimes/cloud/auiV0.ts +8 -1
- package/src/react/runtimes/createRuntimeExtras.test.ts +14 -1
- package/src/react/runtimes/createRuntimeExtras.ts +15 -26
- package/src/runtime/base/default-edit-composer-runtime-core.ts +32 -50
- package/src/runtime/utils/runtime-extras-brand.ts +47 -0
- package/src/runtime/utils/thread-message-like.ts +5 -1
- package/src/store/clients/runtime-adapter.ts +2 -5
- package/src/store/clients/suggestions.ts +1 -1
- package/src/store/clients/thread-message-client.ts +1 -1
- package/src/store/index.ts +31 -0
- package/src/store/runtime-clients/composer-runtime-client.ts +2 -5
- package/src/store/runtime-clients/lookup-domains.test.ts +109 -0
- package/src/store/runtime-clients/message-runtime-client.ts +2 -5
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +2 -1
- package/src/store/runtime-clients/thread-list-runtime-client.ts +2 -5
- package/src/store/runtime-clients/thread-runtime-client.ts +2 -2
- package/src/tests/auiV0Encode.test.ts +97 -0
- package/src/tests/default-edit-composer-runtime-core.test.ts +6 -2
- package/src/tests/framework-neutral-boundary.test.ts +60 -24
- package/src/tests/thread-message-like.test.ts +43 -0
- package/src/types/message.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -43,10 +43,10 @@ import { ThreadListRuntime, ThreadListState } from "./runtime/api/thread-list-ru
|
|
|
43
43
|
import { bindExternalStoreMessage, getExternalStoreMessages } from "./runtime/utils/external-store-message.js";
|
|
44
44
|
import { LocalRuntimeOptionsBase } from "./runtimes/local/local-runtime-options.js";
|
|
45
45
|
import { ExternalStoreAdapter, ExternalStoreBranchChange, ExternalStoreMessageConverter, ExternalStoreThreadData, ExternalStoreThreadListAdapter } from "./runtimes/external-store/external-store-adapter.js";
|
|
46
|
+
import { StreamingTimingAccessors, StreamingTimingOptions, StreamingTimingState, stepStreamingTiming } from "./runtime/utils/streaming-timing.js";
|
|
46
47
|
import { RemoteThreadInitializeResponse, RemoteThreadListAdapter, RemoteThreadListOptions, RemoteThreadListPageOptions, RemoteThreadListProviderComponent, RemoteThreadListResponse, RemoteThreadMetadata } from "./runtimes/remote-thread-list/types.js";
|
|
47
48
|
import { CreateAppendMessage, CreateResumeRunConfig, CreateStartRunConfig, ThreadRuntime, ThreadState } from "./runtime/api/thread-runtime.js";
|
|
48
49
|
import { AssistantRuntime } from "./runtime/api/assistant-runtime.js";
|
|
49
|
-
import { StreamingTimingAccessors, StreamingTimingOptions, StreamingTimingState, stepStreamingTiming } from "./runtime/utils/streaming-timing.js";
|
|
50
50
|
import { ExternalStoreSharedOptions, pickExternalStoreSharedOptions } from "./runtimes/external-store/external-store-shared-options.js";
|
|
51
51
|
import { ExternalThreadBranchAdapter } from "./runtime/branch/external-thread-branch-adapter.js";
|
|
52
52
|
import { MessageQueueController, MessageQueueDriver, createMessageQueue } from "./runtime/queue/message-queue.js";
|
|
@@ -4,8 +4,8 @@ import { DataRenderers } from "./client/DataRenderers.js";
|
|
|
4
4
|
import { Tools } from "./client/Tools.js";
|
|
5
5
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
6
6
|
import { useEffect } from "@assistant-ui/tap/react-shim";
|
|
7
|
-
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
8
7
|
import { resource, useResource } from "@assistant-ui/tap";
|
|
8
|
+
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store/client";
|
|
9
9
|
//#region src/react/RuntimeAdapter.ts
|
|
10
10
|
const useRuntimeAdapter = (runtime) => {
|
|
11
11
|
const $ = c(6);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeAdapter.js","names":["useEffect","useResource","resource","AssistantRuntime","baseRuntimeAdapterTransformScopes","ThreadListClient","attachTransformScopes","useAssistantClientRef","DataRenderers","Tools","useRuntimeAdapter","runtime","$","_c","clientRef","t0","t1","registerModelContextProvider","current","modelContext","t2","threads","__internal_assistantRuntime","RuntimeAdapter","scopes","parent","tools","source","dataRenderers"],"sources":["../../src/react/RuntimeAdapter.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useResource, resource } from \"@assistant-ui/tap\";\nimport type { AssistantRuntime } from \"..\";\nimport {\n baseRuntimeAdapterTransformScopes,\n ThreadListClient,\n} from \"../store/internal\";\nimport {\n attachTransformScopes,\n useAssistantClientRef,\n} from \"@assistant-ui/store\";\nimport { DataRenderers } from \"./client/DataRenderers\";\nimport { Tools } from \"./client/Tools\";\n\nconst useRuntimeAdapter = (runtime: AssistantRuntime) => {\n const clientRef = useAssistantClientRef();\n\n useEffect(() => {\n return runtime.registerModelContextProvider(\n clientRef.current!.modelContext(),\n );\n }, [runtime, clientRef]);\n\n return useResource(\n ThreadListClient({\n runtime: runtime.threads,\n __internal_assistantRuntime: runtime,\n }),\n );\n};\n\nexport const RuntimeAdapter = resource(useRuntimeAdapter);\n\nattachTransformScopes(useRuntimeAdapter, (scopes, parent) => {\n baseRuntimeAdapterTransformScopes(scopes, parent);\n\n if (!scopes.tools && parent.tools.source === null) {\n scopes.tools = Tools({});\n }\n\n if (!scopes.dataRenderers && parent.dataRenderers.source === null) {\n scopes.dataRenderers = DataRenderers();\n }\n});\n"],"mappings":";;;;;;;;;AAcA,MAAMU,qBAAoBC,YAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACxB,MAAAC,YAAkBP,sBAAsB;CAAE,IAAAQ;CAAA,IAAAC;CAAA,IAAAJ,EAAA,OAAAE,aAAAF,EAAA,OAAAD,SAAA;EAEhCI,WACDJ,QAAOM,6BACZH,UAASI,QAAQC,aAAe,CAClC;EACCH,KAAA,CAACL,SAASG,SAAS;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAD;EAAAC,EAAA,KAAAG;EAAAH,EAAA,KAAAI;CAAA,OAAA;EAAAD,KAAAH,EAAA;EAAAI,KAAAJ,EAAA;CAAA;CAJvBZ,UAAUe,IAIPC,EAAoB;CAAC,IAAAI;CAAA,IAAAR,EAAA,OAAAD,SAAA;EAGtBS,KAAAf,iBAAiB;GAAAM,SACNA,QAAOU;GAAQC,6BACKX;EAC/B,CAAC;EAACC,EAAA,KAAAD;EAAAC,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,OAJGX,YACLmB,EAIF;AAAC;AAGH,MAAaG,iBAAiBrB,SAASQ,iBAAiB;AAExDJ,sBAAsBI,oBAAoBc,QAAQC,WAAW;CAC3DrB,kCAAkCoB,QAAQC,MAAM;CAEhD,IAAI,CAACD,OAAOE,SAASD,OAAOC,MAAMC,WAAW,MAC3CH,OAAOE,QAAQjB,MAAM,CAAC,CAAC;CAGzB,IAAI,CAACe,OAAOI,iBAAiBH,OAAOG,cAAcD,WAAW,MAC3DH,OAAOI,gBAAgBpB,cAAc;AAEzC,CAAC"}
|
|
1
|
+
{"version":3,"file":"RuntimeAdapter.js","names":["useEffect","useResource","resource","AssistantRuntime","baseRuntimeAdapterTransformScopes","ThreadListClient","attachTransformScopes","useAssistantClientRef","DataRenderers","Tools","useRuntimeAdapter","runtime","$","_c","clientRef","t0","t1","registerModelContextProvider","current","modelContext","t2","threads","__internal_assistantRuntime","RuntimeAdapter","scopes","parent","tools","source","dataRenderers"],"sources":["../../src/react/RuntimeAdapter.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useResource, resource } from \"@assistant-ui/tap\";\nimport type { AssistantRuntime } from \"..\";\nimport {\n baseRuntimeAdapterTransformScopes,\n ThreadListClient,\n} from \"../store/internal\";\nimport {\n attachTransformScopes,\n useAssistantClientRef,\n} from \"@assistant-ui/store/client\";\nimport { DataRenderers } from \"./client/DataRenderers\";\nimport { Tools } from \"./client/Tools\";\n\nconst useRuntimeAdapter = (runtime: AssistantRuntime) => {\n const clientRef = useAssistantClientRef();\n\n useEffect(() => {\n return runtime.registerModelContextProvider(\n clientRef.current!.modelContext(),\n );\n }, [runtime, clientRef]);\n\n return useResource(\n ThreadListClient({\n runtime: runtime.threads,\n __internal_assistantRuntime: runtime,\n }),\n );\n};\n\nexport const RuntimeAdapter = resource(useRuntimeAdapter);\n\nattachTransformScopes(useRuntimeAdapter, (scopes, parent) => {\n baseRuntimeAdapterTransformScopes(scopes, parent);\n\n if (!scopes.tools && parent.tools.source === null) {\n scopes.tools = Tools({});\n }\n\n if (!scopes.dataRenderers && parent.dataRenderers.source === null) {\n scopes.dataRenderers = DataRenderers();\n }\n});\n"],"mappings":";;;;;;;;;AAcA,MAAMU,qBAAoBC,YAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACxB,MAAAC,YAAkBP,sBAAsB;CAAE,IAAAQ;CAAA,IAAAC;CAAA,IAAAJ,EAAA,OAAAE,aAAAF,EAAA,OAAAD,SAAA;EAEhCI,WACDJ,QAAOM,6BACZH,UAASI,QAAQC,aAAe,CAClC;EACCH,KAAA,CAACL,SAASG,SAAS;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAD;EAAAC,EAAA,KAAAG;EAAAH,EAAA,KAAAI;CAAA,OAAA;EAAAD,KAAAH,EAAA;EAAAI,KAAAJ,EAAA;CAAA;CAJvBZ,UAAUe,IAIPC,EAAoB;CAAC,IAAAI;CAAA,IAAAR,EAAA,OAAAD,SAAA;EAGtBS,KAAAf,iBAAiB;GAAAM,SACNA,QAAOU;GAAQC,6BACKX;EAC/B,CAAC;EAACC,EAAA,KAAAD;EAAAC,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,OAJGX,YACLmB,EAIF;AAAC;AAGH,MAAaG,iBAAiBrB,SAASQ,iBAAiB;AAExDJ,sBAAsBI,oBAAoBc,QAAQC,WAAW;CAC3DrB,kCAAkCoB,QAAQC,MAAM;CAEhD,IAAI,CAACD,OAAOE,SAASD,OAAOC,MAAMC,WAAW,MAC3CH,OAAOE,QAAQjB,MAAM,CAAC,CAAC;CAGzB,IAAI,CAACe,OAAOI,iBAAiBH,OAAOG,cAAcD,WAAW,MAC3DH,OAAOI,gBAAgBpB,cAAc;AAEzC,CAAC"}
|
|
@@ -3,8 +3,8 @@ import { ModelContext } from "../../store/clients/model-context-client.js";
|
|
|
3
3
|
import { buildInteractableModelContext } from "./interactable-model-context.js";
|
|
4
4
|
import { toJSONSchema, toPartialJSONSchema } from "assistant-stream";
|
|
5
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
6
|
-
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
7
6
|
import { resource } from "@assistant-ui/tap";
|
|
7
|
+
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store/client";
|
|
8
8
|
//#region src/react/client/Interactables.ts
|
|
9
9
|
const PERSISTENCE_DEBOUNCE_MS = 500;
|
|
10
10
|
const hasInteractableCreateCall = (messages, id, name) => messages.some((message) => message.role === "assistant" && message.content?.some((part) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interactables.js","names":["useState","useEffect","useCallback","useRef","useMemo","resource","useAssistantClientRef","ClientOutput","attachTransformScopes","Unstable_InteractablesState","Unstable_InteractableRegistration","Unstable_InteractablePersistedState","Unstable_InteractablePersistenceAdapter","Unstable_InteractablesConfig","toJSONSchema","toPartialJSONSchema","ModelContext","buildInteractableModelContext","PartialJSONSchema","findModelKnownState","interactableToolName","PERSISTENCE_DEBOUNCE_MS","RestorePersistedStateOptions","stash","Map","shouldStash","id","shouldApply","def","ToolCallLikePart","type","toolCallId","toolName","MessageLike","role","content","InternalInteractableRegistration","scope","hasInteractableCreateCall","messages","name","some","message","part","p","useInteractablesResource","persistence","state","setState","definitions","clientRef","stateRef","subscribersRef","Set","partialSchemaCacheRef","streamBaselinesRef","targetId","detachedAppStateRef","detachedThreadStateRef","registrationCountsRef","updateToolUIsRef","count","unsubscribe","loadedStateRef","touchedIdsRef","adapterRef","undefined","debounceTimerRef","ReturnType","setTimeout","syncSeqRef","hasPendingLocalChangeRef","flushResolversRef","Array","dirtyIdsRef","setStateAndRef","updater","prev","next","current","exportState","result","Object","entries","runPersistence","adapter","resolve","seq","dirtyIds","clear","payload","fromEntries","map","isPending","error","save","e","size","schedulePersistence","add","clearTimeout","restorePersistedState","saved","options","entry","set","changed","importState","applyLoadedState","has","loadFromAdapter","load","console","warn","setPersistenceAdapter","getCurrentThreadId","client","threadListItem","source","getState","threads","mainThreadId","flush","Promise","push","flushIfPending","setDefState","existing","provider","getModelContext","defs","subscribe","callback","delete","cb","modelContext","register","threadAccessor","thread","threadMessages","process","env","NODE_ENV","get","releaseUpdateToolUI","updateRender","toolsAccessor","tools","setToolUI","standalone","jsonSchema","stateSchema","threadId","detached","loaded","known","description","initialState","remaining","stateById","_","rest","__","restPersistence","unstable_Interactables","scopes","parent"],"sources":["../../../src/react/client/Interactables.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport {\n useAssistantClientRef,\n type ClientOutput,\n attachTransformScopes,\n} from \"@assistant-ui/store\";\nimport type {\n Unstable_InteractablesState,\n Unstable_InteractableRegistration,\n Unstable_InteractablePersistedState,\n Unstable_InteractablePersistenceAdapter,\n Unstable_InteractablesConfig,\n} from \"../types/scopes/interactables\";\nimport { toJSONSchema, toPartialJSONSchema } from \"assistant-stream\";\nimport { ModelContext } from \"../../store\";\nimport {\n buildInteractableModelContext,\n type PartialJSONSchema,\n} from \"./interactable-model-context\";\nimport {\n findModelKnownState,\n interactableToolName,\n} from \"../../model-context/interactable-composer-metadata\";\n\nconst PERSISTENCE_DEBOUNCE_MS = 500;\n\ntype RestorePersistedStateOptions = {\n stash: Map<string, unknown>;\n shouldStash?: (id: string) => boolean;\n shouldApply?: (\n id: string,\n def: Unstable_InteractablesState[\"definitions\"][string],\n ) => boolean;\n};\n\ntype ToolCallLikePart = {\n type?: string;\n toolCallId?: string;\n toolName?: string;\n};\n\ntype MessageLike = {\n role?: string;\n content?: readonly unknown[] | undefined;\n};\n\ntype InternalInteractableRegistration = Unstable_InteractableRegistration & {\n scope?: \"thread\" | undefined;\n};\n\nconst hasInteractableCreateCall = (\n messages: readonly MessageLike[],\n id: string,\n name: string,\n) =>\n messages.some(\n (message) =>\n message.role === \"assistant\" &&\n message.content?.some((part) => {\n if (!part || typeof part !== \"object\") return false;\n const p = part as ToolCallLikePart;\n return (\n p.type === \"tool-call\" && p.toolCallId === id && p.toolName === name\n );\n }),\n );\n\nconst useInteractablesResource = ({\n persistence,\n}: Unstable_InteractablesConfig = {}): ClientOutput<\"unstable_interactables\"> => {\n const [state, setState] = useState<Unstable_InteractablesState>(() => ({\n definitions: {},\n persistence: {},\n }));\n\n const clientRef = useAssistantClientRef();\n\n const stateRef = useRef(state);\n\n const subscribersRef = useRef(new Set<() => void>());\n const partialSchemaCacheRef = useRef(new Map<string, PartialJSONSchema>());\n const streamBaselinesRef = useRef(\n new Map<string, { targetId: string; state: unknown }>(),\n );\n const detachedAppStateRef = useRef(new Map<string, unknown>());\n const detachedThreadStateRef = useRef(\n new Map<string, Map<string, unknown>>(),\n );\n // An instance may be registered from several anchors (its creating tool\n // call plus update_* calls); the definition lives until the last one leaves.\n const registrationCountsRef = useRef(new Map<string, number>());\n // One update-tool UI per interactable name, alive while any registrant\n // that supplied an updateRender is mounted.\n const updateToolUIsRef = useRef(\n new Map<string, { count: number; unsubscribe: () => void }>(),\n );\n // App-scoped state restored via adapter.load(), consumed as components register.\n const loadedStateRef = useRef(new Map<string, unknown>());\n // Ids edited locally this session — a local edit always wins over a slow load.\n const touchedIdsRef = useRef(new Set<string>());\n\n const adapterRef = useRef<\n Unstable_InteractablePersistenceAdapter | undefined\n >(undefined);\n const debounceTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n const syncSeqRef = useRef(0);\n const hasPendingLocalChangeRef = useRef(false);\n const flushResolversRef = useRef<Array<() => void>>([]);\n const dirtyIdsRef = useRef(new Set<string>());\n\n const setStateAndRef = useCallback(\n (\n updater: (\n prev: Unstable_InteractablesState,\n ) => Unstable_InteractablesState,\n ) => {\n const next = updater(stateRef.current);\n stateRef.current = next;\n setState(next);\n },\n [],\n );\n\n const exportState = useCallback((): Unstable_InteractablePersistedState => {\n const result: Unstable_InteractablePersistedState = {};\n for (const [id, def] of Object.entries(stateRef.current.definitions)) {\n if (def.scope === \"thread\") continue; // thread items persist via snapshot, not the adapter\n result[id] = { name: def.name, state: def.state };\n }\n return result;\n }, []);\n\n const runPersistence = useCallback(async () => {\n const adapter = adapterRef.current;\n if (!adapter) {\n for (const resolve of flushResolversRef.current) resolve();\n flushResolversRef.current = [];\n return;\n }\n\n const seq = ++syncSeqRef.current;\n const dirtyIds = new Set(dirtyIdsRef.current);\n dirtyIdsRef.current.clear();\n hasPendingLocalChangeRef.current = true;\n\n // Snapshot before any await so unregistered definitions are still included.\n const payload = exportState();\n\n setStateAndRef((prev) => ({\n ...prev,\n persistence: {\n ...prev.persistence,\n ...Object.fromEntries(\n [...dirtyIds].map((id) => [\n id,\n { isPending: true, error: undefined },\n ]),\n ),\n },\n }));\n\n try {\n await adapter.save(payload);\n if (syncSeqRef.current === seq) {\n hasPendingLocalChangeRef.current = false;\n setStateAndRef((prev) => {\n const persistence = { ...prev.persistence };\n for (const id of dirtyIds) delete persistence[id];\n return { ...prev, persistence };\n });\n }\n } catch (e) {\n if (syncSeqRef.current === seq) {\n hasPendingLocalChangeRef.current = false;\n setStateAndRef((prev) => ({\n ...prev,\n persistence: {\n ...prev.persistence,\n ...Object.fromEntries(\n [...dirtyIds].map((id) => [id, { isPending: false, error: e }]),\n ),\n },\n }));\n }\n } finally {\n if (dirtyIdsRef.current.size > 0 && adapterRef.current) {\n runPersistence();\n } else {\n for (const resolve of flushResolversRef.current) resolve();\n flushResolversRef.current = [];\n }\n }\n }, [exportState, setStateAndRef]);\n\n const schedulePersistence = useCallback(\n (id: string) => {\n if (!adapterRef.current) return;\n dirtyIdsRef.current.add(id);\n if (debounceTimerRef.current !== undefined) {\n clearTimeout(debounceTimerRef.current);\n }\n debounceTimerRef.current = setTimeout(() => {\n debounceTimerRef.current = undefined;\n if (!hasPendingLocalChangeRef.current) {\n runPersistence();\n } else {\n debounceTimerRef.current = setTimeout(() => {\n debounceTimerRef.current = undefined;\n runPersistence();\n }, PERSISTENCE_DEBOUNCE_MS);\n }\n }, PERSISTENCE_DEBOUNCE_MS);\n },\n [runPersistence],\n );\n\n const restorePersistedState = useCallback(\n (\n saved: Unstable_InteractablePersistedState,\n options: RestorePersistedStateOptions,\n ) => {\n const shouldStash = options.shouldStash ?? (() => true);\n const shouldApply = options.shouldApply ?? (() => true);\n\n for (const [id, entry] of Object.entries(saved)) {\n if (shouldStash(id)) options.stash.set(id, entry.state);\n }\n setStateAndRef((prev) => {\n let changed = false;\n const definitions = { ...prev.definitions };\n for (const [id, entry] of Object.entries(saved)) {\n const def = definitions[id];\n if (!def || !shouldApply(id, def)) continue;\n definitions[id] = { ...def, state: entry.state };\n changed = true;\n }\n if (!changed) return prev;\n return { ...prev, definitions };\n });\n },\n [setStateAndRef],\n );\n\n const importState = useCallback(\n (saved: Unstable_InteractablePersistedState) => {\n restorePersistedState(saved, { stash: detachedAppStateRef.current });\n },\n [restorePersistedState],\n );\n\n // Applies adapter.load() output: a local edit made while the load was in\n // flight wins, and thread-scoped items never restore from the adapter.\n const applyLoadedState = useCallback(\n (saved: Unstable_InteractablePersistedState) => {\n restorePersistedState(saved, {\n stash: loadedStateRef.current,\n shouldStash: (id) => !touchedIdsRef.current.has(id),\n shouldApply: (id, def) =>\n !touchedIdsRef.current.has(id) && def.scope !== \"thread\",\n });\n },\n [restorePersistedState],\n );\n\n const loadFromAdapter = useCallback(\n async (adapter: Unstable_InteractablePersistenceAdapter) => {\n if (!adapter.load) return;\n try {\n const saved = await adapter.load();\n if (!saved || adapterRef.current !== adapter) return;\n applyLoadedState(saved);\n } catch (e) {\n console.warn(\"[Interactables] Persistence load failed.\", e);\n }\n },\n [applyLoadedState],\n );\n\n const setPersistenceAdapter = useCallback(\n (adapter: Unstable_InteractablePersistenceAdapter | undefined) => {\n adapterRef.current = adapter;\n if (adapter) void loadFromAdapter(adapter);\n },\n [loadFromAdapter],\n );\n\n const getCurrentThreadId = useCallback((): string | undefined => {\n const client = clientRef.current;\n if (!client) return undefined;\n\n const threadListItem = client.threadListItem;\n if (threadListItem.source != null) {\n return threadListItem().getState().id;\n }\n\n const threads = client.threads;\n if (threads.source != null) {\n return threads().getState().mainThreadId;\n }\n\n return undefined;\n }, [clientRef]);\n\n useEffect(() => {\n if (!persistence) return;\n setPersistenceAdapter(persistence);\n return () => {\n if (adapterRef.current === persistence) {\n adapterRef.current = undefined;\n }\n };\n }, [persistence, setPersistenceAdapter]);\n\n const flush = useCallback(async () => {\n if (debounceTimerRef.current !== undefined) {\n clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n }\n if (!adapterRef.current) return;\n if (!hasPendingLocalChangeRef.current && dirtyIdsRef.current.size === 0)\n return;\n const p = new Promise<void>((resolve) => {\n flushResolversRef.current.push(resolve);\n });\n if (!hasPendingLocalChangeRef.current) {\n runPersistence();\n }\n return p;\n }, [runPersistence]);\n\n const flushIfPending = useCallback(() => {\n if (adapterRef.current && debounceTimerRef.current !== undefined) {\n clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n runPersistence();\n }\n }, [runPersistence]);\n\n const setDefState = useCallback(\n (id: string, updater: (prev: unknown) => unknown) => {\n touchedIdsRef.current.add(id);\n setStateAndRef((prev) => {\n const existing = prev.definitions[id];\n if (!existing) return prev;\n return {\n ...prev,\n definitions: {\n ...prev.definitions,\n [id]: { ...existing, state: updater(existing.state) },\n },\n };\n });\n if (stateRef.current.definitions[id]?.scope !== \"thread\") {\n schedulePersistence(id);\n }\n },\n [schedulePersistence, setStateAndRef],\n );\n\n const provider = useMemo(\n () => ({\n getModelContext: () => {\n const defs = stateRef.current.definitions;\n return (\n buildInteractableModelContext(\n defs,\n partialSchemaCacheRef.current,\n setDefState,\n streamBaselinesRef.current,\n ) ?? {}\n );\n },\n subscribe: (callback: () => void) => {\n subscribersRef.current.add(callback);\n return () => {\n subscribersRef.current.delete(callback);\n };\n },\n }),\n [setDefState],\n );\n\n useEffect(() => {\n for (const cb of subscribersRef.current) cb();\n }, [state]);\n\n useEffect(() => {\n return clientRef.current!.modelContext().register(provider);\n }, [clientRef, provider]);\n\n const register = useCallback(\n (def: InternalInteractableRegistration) => {\n const threadAccessor = clientRef.current?.thread;\n const threadMessages =\n threadAccessor && threadAccessor.source != null\n ? (threadAccessor().getState().messages ?? [])\n : [];\n const scope =\n def.scope ??\n (hasInteractableCreateCall(threadMessages, def.id, def.name)\n ? \"thread\"\n : \"app\");\n\n if (\n process.env.NODE_ENV !== \"production\" &&\n stateRef.current.definitions[def.id] &&\n scope !== \"thread\"\n ) {\n console.warn(\n `[Interactables] \"${def.name}\" (${def.id}) is already registered. ` +\n `Register an app-scoped interactable once (unstable_useInteractable) and ` +\n `read it from other components with unstable_useInteractableState.`,\n );\n }\n\n registrationCountsRef.current.set(\n def.id,\n (registrationCountsRef.current.get(def.id) ?? 0) + 1,\n );\n\n let releaseUpdateToolUI: (() => void) | undefined;\n if (def.updateRender) {\n const toolsAccessor = clientRef.current?.tools;\n if (toolsAccessor && toolsAccessor.source != null) {\n const toolName = interactableToolName(def.name);\n const existing = updateToolUIsRef.current.get(def.name);\n if (existing) {\n existing.count++;\n } else {\n updateToolUIsRef.current.set(def.name, {\n count: 1,\n unsubscribe: toolsAccessor().setToolUI(\n toolName,\n def.updateRender,\n { standalone: true },\n ),\n });\n }\n releaseUpdateToolUI = () => {\n const entry = updateToolUIsRef.current.get(def.name);\n if (!entry) return;\n if (--entry.count === 0) {\n updateToolUIsRef.current.delete(def.name);\n entry.unsubscribe();\n }\n };\n } else if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n `[Interactables] \"${def.name}\" supplied an updateRender, but no ` +\n `tools scope is available to install it into.`,\n );\n }\n }\n\n // The same id re-registers once per anchor (its create call + each update_*).\n if (!partialSchemaCacheRef.current.has(def.id)) {\n try {\n const jsonSchema = toJSONSchema(def.stateSchema);\n partialSchemaCacheRef.current.set(\n def.id,\n toPartialJSONSchema(jsonSchema),\n );\n } catch (e) {\n console.warn(\n `[Interactables] Failed to create partial schema for \"${def.name}\". The update tool will accept arbitrary fields without validation.`,\n e,\n );\n }\n }\n\n const threadId = scope === \"thread\" ? getCurrentThreadId() : undefined;\n const detached =\n scope === \"thread\"\n ? threadId\n ? detachedThreadStateRef.current.get(threadId)?.get(def.id)\n : undefined\n : detachedAppStateRef.current.get(def.id);\n if (scope === \"thread\") {\n if (threadId)\n detachedThreadStateRef.current.get(threadId)?.delete(def.id);\n } else {\n detachedAppStateRef.current.delete(def.id);\n }\n const loaded =\n scope === \"thread\" ? undefined : loadedStateRef.current.get(def.id);\n\n // Tool-created items restore from what the model already knows in this\n // thread (the creating call's args, sent snapshots, and the model's own\n // update_* calls) on a fresh reload; detached (in-session remount) still\n // wins so an unsent edit survives a scroll/virtualization cycle.\n const known =\n scope === \"thread\"\n ? findModelKnownState(threadMessages, def.id, def.name)\n : undefined;\n\n setStateAndRef((prev) => ({\n ...prev,\n definitions: {\n ...prev.definitions,\n [def.id]: {\n id: def.id,\n name: def.name,\n description: def.description,\n stateSchema: def.stateSchema,\n initialState: def.initialState,\n scope,\n state:\n prev.definitions[def.id]?.state ??\n detached ??\n known?.state ??\n loaded ??\n def.initialState,\n },\n },\n }));\n\n return () => {\n releaseUpdateToolUI?.();\n\n const remaining = (registrationCountsRef.current.get(def.id) ?? 1) - 1;\n if (remaining > 0) {\n registrationCountsRef.current.set(def.id, remaining);\n return;\n }\n registrationCountsRef.current.delete(def.id);\n\n flushIfPending();\n setStateAndRef((prev) => {\n const existing = prev.definitions[def.id];\n if (existing) {\n if (existing.scope === \"thread\") {\n const threadId = getCurrentThreadId();\n if (threadId) {\n let stateById = detachedThreadStateRef.current.get(threadId);\n if (!stateById) {\n stateById = new Map();\n detachedThreadStateRef.current.set(threadId, stateById);\n }\n stateById.set(def.id, existing.state);\n }\n } else {\n detachedAppStateRef.current.set(def.id, existing.state);\n }\n }\n partialSchemaCacheRef.current.delete(def.id);\n const { [def.id]: _, ...rest } = prev.definitions;\n const { [def.id]: __, ...restPersistence } = prev.persistence;\n return { ...prev, definitions: rest, persistence: restPersistence };\n });\n };\n },\n [flushIfPending, clientRef, getCurrentThreadId, setStateAndRef],\n );\n\n return {\n getState: () => stateRef.current,\n register,\n setState: setDefState,\n exportState,\n importState,\n setPersistenceAdapter,\n flush,\n };\n};\n\n/**\n * Registers the unstable interactables store scope.\n *\n * @deprecated Unstable / Experimental (not actually removed).\n */\nexport const unstable_Interactables = resource(useInteractablesResource);\n\nattachTransformScopes(useInteractablesResource, (scopes, parent) => {\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n});\n"],"mappings":";;;;;;;;AAyBA,MAAMqB,0BAA0B;AA0BhC,MAAMiB,6BACJC,UACAb,IACAc,SAEAD,SAASE,MACNC,YACCA,QAAQR,SAAS,eACjBQ,QAAQP,SAASM,MAAME,SAAS;CAC9B,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU,OAAO;CAC9C,MAAMC,IAAID;CACV,OACEC,EAAEd,SAAS,eAAec,EAAEb,eAAeL,MAAMkB,EAAEZ,aAAaQ;AAEpE,CAAC,CACL;AAEF,MAAMK,4BAA4B,EAChCC,gBACgC,CAAC,MAA8C;CAC/E,MAAM,CAACC,OAAOC,YAAYhD,gBAA6C;EACrEiD,aAAa,CAAC;EACdH,aAAa,CAAC;CAChB,EAAE;CAEF,MAAMI,YAAY5C,sBAAsB;CAExC,MAAM6C,WAAWhD,OAAO4C,KAAK;CAE7B,MAAMK,iBAAiBjD,uBAAO,IAAIkD,IAAgB,CAAC;CACnD,MAAMC,wBAAwBnD,uBAAO,IAAIqB,IAA+B,CAAC;CACzE,MAAM+B,qBAAqBpD,uBACzB,IAAIqB,IAAkD,CACxD;CACA,MAAMiC,sBAAsBtD,uBAAO,IAAIqB,IAAqB,CAAC;CAC7D,MAAMkC,yBAAyBvD,uBAC7B,IAAIqB,IAAkC,CACxC;CAGA,MAAMmC,wBAAwBxD,uBAAO,IAAIqB,IAAoB,CAAC;CAG9D,MAA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AAKwI,IAAI,GAAGC,oBAAoBtF,OAAK/B;KAClD,OAAO;MAAE,GAAG+B;MAAM5B,aAAagH;MAAMnH,aAAaqH;KAAgB;IACpE,CAAC;GACH;EACF,GACA;GAACtC;GAAgB3E;GAAWiE;GAAoBxC;EAAc,CAK9D6D;EACAxF,UAAU8E;EACV9C;EACA2B;EACAO;EACAQ;CACF;AACF;;;;;;AAOA,MAAa0C,yBAAyB/J,SAASwC,wBAAwB;AAEvErC,sBAAsBqC,2BAA2BwH,QAAQC,WAAW;CAClE,IAAI,CAACD,OAAO9B,gBAAgB+B,OAAO/B,aAAajB,WAAW,MACzD+C,OAAO9B,eAAevH,aAAa;AAEvC,CAAC"}
|
|
1
|
+
{"version":3,"file":"Interactables.js","names":["useState","useEffect","useCallback","useRef","useMemo","resource","ClientOutput","attachTransformScopes","useAssistantClientRef","Unstable_InteractablesState","Unstable_InteractableRegistration","Unstable_InteractablePersistedState","Unstable_InteractablePersistenceAdapter","Unstable_InteractablesConfig","toJSONSchema","toPartialJSONSchema","ModelContext","buildInteractableModelContext","PartialJSONSchema","findModelKnownState","interactableToolName","PERSISTENCE_DEBOUNCE_MS","RestorePersistedStateOptions","stash","Map","shouldStash","id","shouldApply","def","ToolCallLikePart","type","toolCallId","toolName","MessageLike","role","content","InternalInteractableRegistration","scope","hasInteractableCreateCall","messages","name","some","message","part","p","useInteractablesResource","persistence","state","setState","definitions","clientRef","stateRef","subscribersRef","Set","partialSchemaCacheRef","streamBaselinesRef","targetId","detachedAppStateRef","detachedThreadStateRef","registrationCountsRef","updateToolUIsRef","count","unsubscribe","loadedStateRef","touchedIdsRef","adapterRef","undefined","debounceTimerRef","ReturnType","setTimeout","syncSeqRef","hasPendingLocalChangeRef","flushResolversRef","Array","dirtyIdsRef","setStateAndRef","updater","prev","next","current","exportState","result","Object","entries","runPersistence","adapter","resolve","seq","dirtyIds","clear","payload","fromEntries","map","isPending","error","save","e","size","schedulePersistence","add","clearTimeout","restorePersistedState","saved","options","entry","set","changed","importState","applyLoadedState","has","loadFromAdapter","load","console","warn","setPersistenceAdapter","getCurrentThreadId","client","threadListItem","source","getState","threads","mainThreadId","flush","Promise","push","flushIfPending","setDefState","existing","provider","getModelContext","defs","subscribe","callback","delete","cb","modelContext","register","threadAccessor","thread","threadMessages","process","env","NODE_ENV","get","releaseUpdateToolUI","updateRender","toolsAccessor","tools","setToolUI","standalone","jsonSchema","stateSchema","threadId","detached","loaded","known","description","initialState","remaining","stateById","_","rest","__","restPersistence","unstable_Interactables","scopes","parent"],"sources":["../../../src/react/client/Interactables.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport {\n attachTransformScopes,\n useAssistantClientRef,\n} from \"@assistant-ui/store/client\";\nimport type {\n Unstable_InteractablesState,\n Unstable_InteractableRegistration,\n Unstable_InteractablePersistedState,\n Unstable_InteractablePersistenceAdapter,\n Unstable_InteractablesConfig,\n} from \"../types/scopes/interactables\";\nimport { toJSONSchema, toPartialJSONSchema } from \"assistant-stream\";\nimport { ModelContext } from \"../../store/clients/model-context-client\";\nimport {\n buildInteractableModelContext,\n type PartialJSONSchema,\n} from \"./interactable-model-context\";\nimport {\n findModelKnownState,\n interactableToolName,\n} from \"../../model-context/interactable-composer-metadata\";\n\nconst PERSISTENCE_DEBOUNCE_MS = 500;\n\ntype RestorePersistedStateOptions = {\n stash: Map<string, unknown>;\n shouldStash?: (id: string) => boolean;\n shouldApply?: (\n id: string,\n def: Unstable_InteractablesState[\"definitions\"][string],\n ) => boolean;\n};\n\ntype ToolCallLikePart = {\n type?: string;\n toolCallId?: string;\n toolName?: string;\n};\n\ntype MessageLike = {\n role?: string;\n content?: readonly unknown[] | undefined;\n};\n\ntype InternalInteractableRegistration = Unstable_InteractableRegistration & {\n scope?: \"thread\" | undefined;\n};\n\nconst hasInteractableCreateCall = (\n messages: readonly MessageLike[],\n id: string,\n name: string,\n) =>\n messages.some(\n (message) =>\n message.role === \"assistant\" &&\n message.content?.some((part) => {\n if (!part || typeof part !== \"object\") return false;\n const p = part as ToolCallLikePart;\n return (\n p.type === \"tool-call\" && p.toolCallId === id && p.toolName === name\n );\n }),\n );\n\nconst useInteractablesResource = ({\n persistence,\n}: Unstable_InteractablesConfig = {}): ClientOutput<\"unstable_interactables\"> => {\n const [state, setState] = useState<Unstable_InteractablesState>(() => ({\n definitions: {},\n persistence: {},\n }));\n\n const clientRef = useAssistantClientRef();\n\n const stateRef = useRef(state);\n\n const subscribersRef = useRef(new Set<() => void>());\n const partialSchemaCacheRef = useRef(new Map<string, PartialJSONSchema>());\n const streamBaselinesRef = useRef(\n new Map<string, { targetId: string; state: unknown }>(),\n );\n const detachedAppStateRef = useRef(new Map<string, unknown>());\n const detachedThreadStateRef = useRef(\n new Map<string, Map<string, unknown>>(),\n );\n // An instance may be registered from several anchors (its creating tool\n // call plus update_* calls); the definition lives until the last one leaves.\n const registrationCountsRef = useRef(new Map<string, number>());\n // One update-tool UI per interactable name, alive while any registrant\n // that supplied an updateRender is mounted.\n const updateToolUIsRef = useRef(\n new Map<string, { count: number; unsubscribe: () => void }>(),\n );\n // App-scoped state restored via adapter.load(), consumed as components register.\n const loadedStateRef = useRef(new Map<string, unknown>());\n // Ids edited locally this session — a local edit always wins over a slow load.\n const touchedIdsRef = useRef(new Set<string>());\n\n const adapterRef = useRef<\n Unstable_InteractablePersistenceAdapter | undefined\n >(undefined);\n const debounceTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n const syncSeqRef = useRef(0);\n const hasPendingLocalChangeRef = useRef(false);\n const flushResolversRef = useRef<Array<() => void>>([]);\n const dirtyIdsRef = useRef(new Set<string>());\n\n const setStateAndRef = useCallback(\n (\n updater: (\n prev: Unstable_InteractablesState,\n ) => Unstable_InteractablesState,\n ) => {\n const next = updater(stateRef.current);\n stateRef.current = next;\n setState(next);\n },\n [],\n );\n\n const exportState = useCallback((): Unstable_InteractablePersistedState => {\n const result: Unstable_InteractablePersistedState = {};\n for (const [id, def] of Object.entries(stateRef.current.definitions)) {\n if (def.scope === \"thread\") continue; // thread items persist via snapshot, not the adapter\n result[id] = { name: def.name, state: def.state };\n }\n return result;\n }, []);\n\n const runPersistence = useCallback(async () => {\n const adapter = adapterRef.current;\n if (!adapter) {\n for (const resolve of flushResolversRef.current) resolve();\n flushResolversRef.current = [];\n return;\n }\n\n const seq = ++syncSeqRef.current;\n const dirtyIds = new Set(dirtyIdsRef.current);\n dirtyIdsRef.current.clear();\n hasPendingLocalChangeRef.current = true;\n\n // Snapshot before any await so unregistered definitions are still included.\n const payload = exportState();\n\n setStateAndRef((prev) => ({\n ...prev,\n persistence: {\n ...prev.persistence,\n ...Object.fromEntries(\n [...dirtyIds].map((id) => [\n id,\n { isPending: true, error: undefined },\n ]),\n ),\n },\n }));\n\n try {\n await adapter.save(payload);\n if (syncSeqRef.current === seq) {\n hasPendingLocalChangeRef.current = false;\n setStateAndRef((prev) => {\n const persistence = { ...prev.persistence };\n for (const id of dirtyIds) delete persistence[id];\n return { ...prev, persistence };\n });\n }\n } catch (e) {\n if (syncSeqRef.current === seq) {\n hasPendingLocalChangeRef.current = false;\n setStateAndRef((prev) => ({\n ...prev,\n persistence: {\n ...prev.persistence,\n ...Object.fromEntries(\n [...dirtyIds].map((id) => [id, { isPending: false, error: e }]),\n ),\n },\n }));\n }\n } finally {\n if (dirtyIdsRef.current.size > 0 && adapterRef.current) {\n runPersistence();\n } else {\n for (const resolve of flushResolversRef.current) resolve();\n flushResolversRef.current = [];\n }\n }\n }, [exportState, setStateAndRef]);\n\n const schedulePersistence = useCallback(\n (id: string) => {\n if (!adapterRef.current) return;\n dirtyIdsRef.current.add(id);\n if (debounceTimerRef.current !== undefined) {\n clearTimeout(debounceTimerRef.current);\n }\n debounceTimerRef.current = setTimeout(() => {\n debounceTimerRef.current = undefined;\n if (!hasPendingLocalChangeRef.current) {\n runPersistence();\n } else {\n debounceTimerRef.current = setTimeout(() => {\n debounceTimerRef.current = undefined;\n runPersistence();\n }, PERSISTENCE_DEBOUNCE_MS);\n }\n }, PERSISTENCE_DEBOUNCE_MS);\n },\n [runPersistence],\n );\n\n const restorePersistedState = useCallback(\n (\n saved: Unstable_InteractablePersistedState,\n options: RestorePersistedStateOptions,\n ) => {\n const shouldStash = options.shouldStash ?? (() => true);\n const shouldApply = options.shouldApply ?? (() => true);\n\n for (const [id, entry] of Object.entries(saved)) {\n if (shouldStash(id)) options.stash.set(id, entry.state);\n }\n setStateAndRef((prev) => {\n let changed = false;\n const definitions = { ...prev.definitions };\n for (const [id, entry] of Object.entries(saved)) {\n const def = definitions[id];\n if (!def || !shouldApply(id, def)) continue;\n definitions[id] = { ...def, state: entry.state };\n changed = true;\n }\n if (!changed) return prev;\n return { ...prev, definitions };\n });\n },\n [setStateAndRef],\n );\n\n const importState = useCallback(\n (saved: Unstable_InteractablePersistedState) => {\n restorePersistedState(saved, { stash: detachedAppStateRef.current });\n },\n [restorePersistedState],\n );\n\n // Applies adapter.load() output: a local edit made while the load was in\n // flight wins, and thread-scoped items never restore from the adapter.\n const applyLoadedState = useCallback(\n (saved: Unstable_InteractablePersistedState) => {\n restorePersistedState(saved, {\n stash: loadedStateRef.current,\n shouldStash: (id) => !touchedIdsRef.current.has(id),\n shouldApply: (id, def) =>\n !touchedIdsRef.current.has(id) && def.scope !== \"thread\",\n });\n },\n [restorePersistedState],\n );\n\n const loadFromAdapter = useCallback(\n async (adapter: Unstable_InteractablePersistenceAdapter) => {\n if (!adapter.load) return;\n try {\n const saved = await adapter.load();\n if (!saved || adapterRef.current !== adapter) return;\n applyLoadedState(saved);\n } catch (e) {\n console.warn(\"[Interactables] Persistence load failed.\", e);\n }\n },\n [applyLoadedState],\n );\n\n const setPersistenceAdapter = useCallback(\n (adapter: Unstable_InteractablePersistenceAdapter | undefined) => {\n adapterRef.current = adapter;\n if (adapter) void loadFromAdapter(adapter);\n },\n [loadFromAdapter],\n );\n\n const getCurrentThreadId = useCallback((): string | undefined => {\n const client = clientRef.current;\n if (!client) return undefined;\n\n const threadListItem = client.threadListItem;\n if (threadListItem.source != null) {\n return threadListItem().getState().id;\n }\n\n const threads = client.threads;\n if (threads.source != null) {\n return threads().getState().mainThreadId;\n }\n\n return undefined;\n }, [clientRef]);\n\n useEffect(() => {\n if (!persistence) return;\n setPersistenceAdapter(persistence);\n return () => {\n if (adapterRef.current === persistence) {\n adapterRef.current = undefined;\n }\n };\n }, [persistence, setPersistenceAdapter]);\n\n const flush = useCallback(async () => {\n if (debounceTimerRef.current !== undefined) {\n clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n }\n if (!adapterRef.current) return;\n if (!hasPendingLocalChangeRef.current && dirtyIdsRef.current.size === 0)\n return;\n const p = new Promise<void>((resolve) => {\n flushResolversRef.current.push(resolve);\n });\n if (!hasPendingLocalChangeRef.current) {\n runPersistence();\n }\n return p;\n }, [runPersistence]);\n\n const flushIfPending = useCallback(() => {\n if (adapterRef.current && debounceTimerRef.current !== undefined) {\n clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n runPersistence();\n }\n }, [runPersistence]);\n\n const setDefState = useCallback(\n (id: string, updater: (prev: unknown) => unknown) => {\n touchedIdsRef.current.add(id);\n setStateAndRef((prev) => {\n const existing = prev.definitions[id];\n if (!existing) return prev;\n return {\n ...prev,\n definitions: {\n ...prev.definitions,\n [id]: { ...existing, state: updater(existing.state) },\n },\n };\n });\n if (stateRef.current.definitions[id]?.scope !== \"thread\") {\n schedulePersistence(id);\n }\n },\n [schedulePersistence, setStateAndRef],\n );\n\n const provider = useMemo(\n () => ({\n getModelContext: () => {\n const defs = stateRef.current.definitions;\n return (\n buildInteractableModelContext(\n defs,\n partialSchemaCacheRef.current,\n setDefState,\n streamBaselinesRef.current,\n ) ?? {}\n );\n },\n subscribe: (callback: () => void) => {\n subscribersRef.current.add(callback);\n return () => {\n subscribersRef.current.delete(callback);\n };\n },\n }),\n [setDefState],\n );\n\n useEffect(() => {\n for (const cb of subscribersRef.current) cb();\n }, [state]);\n\n useEffect(() => {\n return clientRef.current!.modelContext().register(provider);\n }, [clientRef, provider]);\n\n const register = useCallback(\n (def: InternalInteractableRegistration) => {\n const threadAccessor = clientRef.current?.thread;\n const threadMessages =\n threadAccessor && threadAccessor.source != null\n ? (threadAccessor().getState().messages ?? [])\n : [];\n const scope =\n def.scope ??\n (hasInteractableCreateCall(threadMessages, def.id, def.name)\n ? \"thread\"\n : \"app\");\n\n if (\n process.env.NODE_ENV !== \"production\" &&\n stateRef.current.definitions[def.id] &&\n scope !== \"thread\"\n ) {\n console.warn(\n `[Interactables] \"${def.name}\" (${def.id}) is already registered. ` +\n `Register an app-scoped interactable once (unstable_useInteractable) and ` +\n `read it from other components with unstable_useInteractableState.`,\n );\n }\n\n registrationCountsRef.current.set(\n def.id,\n (registrationCountsRef.current.get(def.id) ?? 0) + 1,\n );\n\n let releaseUpdateToolUI: (() => void) | undefined;\n if (def.updateRender) {\n const toolsAccessor = clientRef.current?.tools;\n if (toolsAccessor && toolsAccessor.source != null) {\n const toolName = interactableToolName(def.name);\n const existing = updateToolUIsRef.current.get(def.name);\n if (existing) {\n existing.count++;\n } else {\n updateToolUIsRef.current.set(def.name, {\n count: 1,\n unsubscribe: toolsAccessor().setToolUI(\n toolName,\n def.updateRender,\n { standalone: true },\n ),\n });\n }\n releaseUpdateToolUI = () => {\n const entry = updateToolUIsRef.current.get(def.name);\n if (!entry) return;\n if (--entry.count === 0) {\n updateToolUIsRef.current.delete(def.name);\n entry.unsubscribe();\n }\n };\n } else if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n `[Interactables] \"${def.name}\" supplied an updateRender, but no ` +\n `tools scope is available to install it into.`,\n );\n }\n }\n\n // The same id re-registers once per anchor (its create call + each update_*).\n if (!partialSchemaCacheRef.current.has(def.id)) {\n try {\n const jsonSchema = toJSONSchema(def.stateSchema);\n partialSchemaCacheRef.current.set(\n def.id,\n toPartialJSONSchema(jsonSchema),\n );\n } catch (e) {\n console.warn(\n `[Interactables] Failed to create partial schema for \"${def.name}\". The update tool will accept arbitrary fields without validation.`,\n e,\n );\n }\n }\n\n const threadId = scope === \"thread\" ? getCurrentThreadId() : undefined;\n const detached =\n scope === \"thread\"\n ? threadId\n ? detachedThreadStateRef.current.get(threadId)?.get(def.id)\n : undefined\n : detachedAppStateRef.current.get(def.id);\n if (scope === \"thread\") {\n if (threadId)\n detachedThreadStateRef.current.get(threadId)?.delete(def.id);\n } else {\n detachedAppStateRef.current.delete(def.id);\n }\n const loaded =\n scope === \"thread\" ? undefined : loadedStateRef.current.get(def.id);\n\n // Tool-created items restore from what the model already knows in this\n // thread (the creating call's args, sent snapshots, and the model's own\n // update_* calls) on a fresh reload; detached (in-session remount) still\n // wins so an unsent edit survives a scroll/virtualization cycle.\n const known =\n scope === \"thread\"\n ? findModelKnownState(threadMessages, def.id, def.name)\n : undefined;\n\n setStateAndRef((prev) => ({\n ...prev,\n definitions: {\n ...prev.definitions,\n [def.id]: {\n id: def.id,\n name: def.name,\n description: def.description,\n stateSchema: def.stateSchema,\n initialState: def.initialState,\n scope,\n state:\n prev.definitions[def.id]?.state ??\n detached ??\n known?.state ??\n loaded ??\n def.initialState,\n },\n },\n }));\n\n return () => {\n releaseUpdateToolUI?.();\n\n const remaining = (registrationCountsRef.current.get(def.id) ?? 1) - 1;\n if (remaining > 0) {\n registrationCountsRef.current.set(def.id, remaining);\n return;\n }\n registrationCountsRef.current.delete(def.id);\n\n flushIfPending();\n setStateAndRef((prev) => {\n const existing = prev.definitions[def.id];\n if (existing) {\n if (existing.scope === \"thread\") {\n const threadId = getCurrentThreadId();\n if (threadId) {\n let stateById = detachedThreadStateRef.current.get(threadId);\n if (!stateById) {\n stateById = new Map();\n detachedThreadStateRef.current.set(threadId, stateById);\n }\n stateById.set(def.id, existing.state);\n }\n } else {\n detachedAppStateRef.current.set(def.id, existing.state);\n }\n }\n partialSchemaCacheRef.current.delete(def.id);\n const { [def.id]: _, ...rest } = prev.definitions;\n const { [def.id]: __, ...restPersistence } = prev.persistence;\n return { ...prev, definitions: rest, persistence: restPersistence };\n });\n };\n },\n [flushIfPending, clientRef, getCurrentThreadId, setStateAndRef],\n );\n\n return {\n getState: () => stateRef.current,\n register,\n setState: setDefState,\n exportState,\n importState,\n setPersistenceAdapter,\n flush,\n };\n};\n\n/**\n * Registers the unstable interactables store scope.\n *\n * @deprecated Unstable / Experimental (not actually removed).\n */\nexport const unstable_Interactables = resource(useInteractablesResource);\n\nattachTransformScopes(useInteractablesResource, (scopes, parent) => {\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n});\n"],"mappings":";;;;;;;;AAyBA,MAAMqB,0BAA0B;AA0BhC,MAAMiB,6BACJC,UACAb,IACAc,SAEAD,SAASE,MACNC,YACCA,QAAQR,SAAS,eACjBQ,QAAQP,SAASM,MAAME,SAAS;CAC9B,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU,OAAO;CAC9C,MAAMC,IAAID;CACV,OACEC,EAAEd,SAAS,eAAec,EAAEb,eAAeL,MAAMkB,EAAEZ,aAAaQ;AAEpE,CAAC,CACL;AAEF,MAAMK,4BAA4B,EAChCC,gBACgC,CAAC,MAA8C;CAC/E,MAAM,CAACC,OAAOC,YAAYhD,gBAA6C;EACrEiD,aAAa,CAAC;EACdH,aAAa,CAAC;CAChB,EAAE;CAEF,MAAMI,YAAY1C,sBAAsB;CAExC,MAAM2C,WAAWhD,OAAO4C,KAAK;CAE7B,MAAMK,iBAAiBjD,uBAAO,IAAIkD,IAAgB,CAAC;CACnD,MAAMC,wBAAwBnD,uBAAO,IAAIqB,IAA+B,CAAC;CACzE,MAAM+B,qBAAqBpD,uBACzB,IAAIqB,IAAkD,CACxD;CACA,MAAMiC,sBAAsBtD,uBAAO,IAAIqB,IAAqB,CAAC;CAC7D,MAAMkC,yBAAyBvD,uBAC7B,IAAIqB,IAAkC,CACxC;CAGA,MAAMmC,wBAAwBxD,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F,OAAK5B;KACtC,MAAM,GAAGrB,MAAIF,KAAKwI,IAAI,GAAGC,oBAAoBtF,OAAK/B;KAClD,OAAO;MAAE,GAAG+B;MAAM5B,aAAagH;MAAMnH,aAAaqH;KAAgB;IACpE,CAAC;GACH;EACF,GACA;GAACtC;GAAgB3E;GAAWiE;GAAoBxC;EAAc,CAK9D6D;EACAxF,UAAU8E;EACV9C;EACA2B;EACAO;EACAQ;CACF;AACF;;;;;;AAOA,MAAa0C,yBAAyB/J,SAASwC,wBAAwB;AAEvEtC,sBAAsBsC,2BAA2BwH,QAAQC,WAAW;CAClE,IAAI,CAACD,OAAO9B,gBAAgB+B,OAAO/B,aAAajB,WAAW,MACzD+C,OAAO9B,eAAevH,aAAa;AAEvC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { McpAppResourceOutput } from "../types/scopes/tools.js";
|
|
2
1
|
import { Toolkit } from "../model-context/toolbox.js";
|
|
2
|
+
import { McpAppResourceOutput } from "../types/scopes/tools.js";
|
|
3
3
|
import { ClientOutput } from "@assistant-ui/store";
|
|
4
4
|
import { ResourceElement } from "@assistant-ui/tap";
|
|
5
5
|
//#region src/react/client/Tools.d.ts
|
|
@@ -2,8 +2,8 @@ import { ModelContext } from "../../store/clients/model-context-client.js";
|
|
|
2
2
|
import { isStandaloneToolDisplay, makeToolCallTextComponent } from "../model-context/toolbox.js";
|
|
3
3
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
4
|
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
5
|
-
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
6
5
|
import { resource, useResources, withKey } from "@assistant-ui/tap";
|
|
6
|
+
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store/client";
|
|
7
7
|
//#region src/react/client/Tools.ts
|
|
8
8
|
/**
|
|
9
9
|
* Registers tools with model context and installs tool-call renderers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tools.js","names":["useState","useEffect","useCallback","useMemo","useResources","resource","withKey","ResourceElement","
|
|
1
|
+
{"version":3,"file":"Tools.js","names":["useState","useEffect","useCallback","useMemo","useResources","resource","withKey","ResourceElement","ClientOutput","attachTransformScopes","useAssistantClientRef","McpAppResourceOutput","ToolsState","Tool","isStandaloneToolDisplay","makeToolCallTextComponent","Toolkit","ToolCallMessagePartComponent","ModelContext","useTools","t0","$","_c","toolkit","mcpApp","t1","mcpAppOutputs","mcpAppOutput","toolUIs","setToolUIs","_temp","t2","state","clientRef","t3","Symbol","for","toolName","render","options","registration","standalone","prev","prev_0","next","filter","r","length","rest","setToolUI","t4","t5","unsubscribes","toolName_0","tool","Object","entries","toolRender","undefined","toolRenderText","renderText","render_0","push","toolsWithoutRender","reduce","_temp2","Record","modelContextProvider","getModelContext","tools","current","modelContext","register","forEach","_temp3","t6","getState","Tools","scopes","parent","source","acc","name","tool_0","type","display","_display","_render","_renderText","rest_0","fn"],"sources":["../../../src/react/client/Tools.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useMemo } from \"react\";\nimport {\n useResources,\n resource,\n withKey,\n type ResourceElement,\n} from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport {\n attachTransformScopes,\n useAssistantClientRef,\n} from \"@assistant-ui/store/client\";\nimport type { McpAppResourceOutput, ToolsState } from \"../types/scopes/tools\";\nimport type { Tool } from \"assistant-stream\";\nimport {\n isStandaloneToolDisplay,\n makeToolCallTextComponent,\n type Toolkit,\n} from \"../model-context/toolbox\";\nimport type { ToolCallMessagePartComponent } from \"../types/MessagePartComponentTypes\";\nimport { ModelContext } from \"../../store/clients/model-context-client\";\n\nexport type { McpAppResourceOutput };\n\n/**\n * Registers tools with model context and installs tool-call renderers.\n *\n * Mount this resource near an assistant subtree when you want to expose a\n * group of tools declaratively. Tool definitions are registered with model\n * context, while each tool renderer is registered with the tools scope for\n * message rendering.\n */\nconst useTools = ({\n toolkit,\n mcpApp,\n}: {\n /** Tools to expose to the model and optional renderers to install. */\n toolkit?: Toolkit;\n /** Optional MCP app resource whose tools should be merged into context. */\n mcpApp?: ResourceElement<McpAppResourceOutput> | undefined;\n}): ClientOutput<\"tools\"> => {\n const mcpAppOutputs = useResources(mcpApp ? [withKey(\"mcpApp\", mcpApp)] : []);\n const mcpAppOutput = mcpAppOutputs[0];\n\n const [toolUIs, setToolUIs] = useState<ToolsState[\"toolUIs\"]>(() => ({}));\n\n const state = useMemo(\n (): ToolsState => ({\n toolUIs,\n mcpApp: mcpAppOutput,\n }),\n [toolUIs, mcpAppOutput],\n );\n\n const clientRef = useAssistantClientRef();\n\n const setToolUI = useCallback(\n (\n toolName: string,\n render: ToolCallMessagePartComponent,\n options?: { standalone?: boolean },\n ) => {\n // One registration object per call; identity is the removal key, so\n // the per-name list stays correctly ref-counted across re-registers.\n const registration = {\n render,\n standalone: options?.standalone ?? false,\n };\n\n setToolUIs((prev) => ({\n ...prev,\n [toolName]: [...(prev[toolName] ?? []), registration],\n }));\n\n return () => {\n setToolUIs((prev) => {\n const next = prev[toolName]?.filter((r) => r !== registration) ?? [];\n if (next.length > 0) return { ...prev, [toolName]: next };\n // Drop the key entirely so repeatedly mounted/unmounted tools\n // don't leave empty arrays accumulating across a long session.\n const rest = { ...prev };\n delete rest[toolName];\n return rest;\n });\n };\n },\n [],\n );\n\n useEffect(() => {\n if (!toolkit) return;\n const unsubscribes: (() => void)[] = [];\n\n // Register tool UIs (exclude symbols)\n for (const [toolName, tool] of Object.entries(toolkit)) {\n const toolRender = \"render\" in tool ? tool.render : undefined;\n const toolRenderText = \"renderText\" in tool ? tool.renderText : undefined;\n const render =\n toolRender ??\n (toolRenderText\n ? makeToolCallTextComponent(toolRenderText)\n : undefined);\n if (render) {\n unsubscribes.push(\n setToolUI(toolName, render, {\n standalone: isStandaloneToolDisplay(tool),\n }),\n );\n }\n }\n\n // Register tools with model context (exclude symbols). `render`,\n // `renderText`, and `display` are client-only presentation concerns and\n // never reach the model.\n const toolsWithoutRender = Object.entries(toolkit).reduce(\n (acc, [name, tool]) => {\n if (tool.type === \"mcp\") return acc;\n const {\n display: _display,\n render: _render,\n renderText: _renderText,\n ...rest\n } = tool as typeof tool & { renderText?: unknown };\n acc[name] = rest as Tool<any, any>;\n return acc;\n },\n {} as Record<string, Tool<any, any>>,\n );\n\n const modelContextProvider = {\n getModelContext: () => ({\n tools: toolsWithoutRender,\n }),\n };\n\n unsubscribes.push(\n clientRef.current!.modelContext().register(modelContextProvider),\n );\n\n return () => {\n unsubscribes.forEach((fn) => fn());\n };\n }, [toolkit, setToolUI, clientRef]);\n\n return {\n getState: () => state,\n setToolUI,\n };\n};\n\nexport const Tools = resource(useTools);\n\nattachTransformScopes(useTools, (scopes, parent) => {\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,MAAMmB,YAAWC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,SAAAC,WAAAJ;CAQjB,IAAAK;CAAA,IAAAJ,EAAA,OAAAG,QAAA;EACoCC,KAAAD,SAAA,CAAUlB,QAAQ,UAAUkB,MAAM,CAAC,IAAnC,CAAA;EAAyCH,EAAA,KAAAG;EAAAH,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAC5E,MAAAM,eADsBvB,aAAaqB,EACdC,CAAa,CAAA;CAElC,MAAA,CAAAE,SAAAC,cAA8B7B,SAAgC8B,KAAU;CAAE,IAAAC;CAAA,IAAAV,EAAA,OAAAM,gBAAAN,EAAA,OAAAO,SAAA;EAGrDG,KAAA;GAAAH;GAAAJ,QAETG;EACV;EAACN,EAAA,KAAAM;EAAAN,EAAA,KAAAO;EAAAP,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAJH,MAAAW,QACqBD;CAOrB,MAAAE,YAAkBvB,sBAAsB;CAAE,IAAAwB;CAAA,IAAAb,EAAA,OAAAc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CAAAC,SAAUL,EAPhBC,wBACH,EAAAC,OACfN,mBACT,GAI2CI,CAAoB,CACjE;GAAC,aAEM;IACLf,aAAYqB,QAASC,MAAY;GAAC;EACnC;EACAvB,KAAA;GAAC5B;GAAS0B;GAAWhB;EAAS;EAACZ,EAAA,KAAAY;EAAAZ,EAAA,KAAAE;EAAAF,EAAA,KAAA6B;EAAA7B,EAAA,KAAA8B;CAAA,OAAA;EAAAD,KAAA7B,EAAA;EAAA8B,KAAA9B,EAAA;CAAA;CArDlCpB,UAAUiD,IAqDPC,EAA+B;CAAC,IAAAwB;CAAA,IAAAtD,EAAA,QAAAW,OAAA;EAE5B2C,KAAA;GAAAC,gBACW5C;GAAKiB;EAEvB;EAAC5B,EAAA,MAAAW;EAAAX,EAAA,MAAAsD;CAAA,OAAAA,KAAAtD,EAAA;CAAA,OAHMsD;AAGN;AAGH,MAAaE,QAAQxE,SAASc,QAAQ;AAEtCV,sBAAsBU,WAAW2D,QAAQC,WAAW;CAClD,IAAI,CAACD,OAAOP,gBAAgBQ,OAAOR,aAAaS,WAAW,MACzDF,OAAOP,eAAerD,aAAa;AAEvC,CAAC;AA5HgB,SAAAY,QAAA;CAAA,OAYsD,CAAC;AAAC;AAZxD,SAAAmC,OAAAgB,KAAA7D,IAAA;CAmFL,MAAA,CAAA8D,MAAAC,UAAA/D;CACJ,IAAIkC,OAAI8B,SAAU,OAAK,OAASH;CAChC,MAAA,EAAAI,SAAAC,UAAAhD,QAAAiD,SAAA3B,YAAA4B,aAAA,GAAAC,WAKInC;CACJ2B,IAAIC,QAAQlC;CAAH,OACFiC;AAAG;AA5FD,SAAAP,OAAAgB,IAAA;CAAA,OA4GkBA,GAAG;AAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
/// <reference path="./types/store-augmentation.d.ts" />
|
|
3
3
|
import { AssistantContextConfig } from "../model-context/types.js";
|
|
4
4
|
import { PartState } from "../store/scopes/part.js";
|
|
5
|
+
import { RuntimeAdapter } from "./RuntimeAdapter.js";
|
|
6
|
+
import { JoinStrategy, convertExternalMessages, useExternalMessageConverter } from "./runtimes/external-message-converter.js";
|
|
5
7
|
import { StreamingTimingAccessors, StreamingTimingOptions, StreamingTimingState } from "../runtime/utils/streaming-timing.js";
|
|
8
|
+
import { useStreamingTiming } from "./runtimes/useStreamingTiming.js";
|
|
9
|
+
import { DataMessagePartComponent, DataMessagePartProps, EmptyMessagePartComponent, EmptyMessagePartProps, FileMessagePartComponent, FileMessagePartProps, GenerativeUIComponentRegistry, GenerativeUIMessagePartComponent, GenerativeUIMessagePartProps, GenerativeUIRenderProps, ImageMessagePartComponent, ImageMessagePartProps, QuoteMessagePartComponent, QuoteMessagePartProps, ReasoningGroupComponent, ReasoningGroupProps, ReasoningMessagePartComponent, ReasoningMessagePartProps, SourceMessagePartComponent, SourceMessagePartProps, TextMessagePartComponent, TextMessagePartProps, ToolCallMessagePartComponent, ToolCallMessagePartProps, Unstable_AudioMessagePartComponent, Unstable_AudioMessagePartProps } from "./types/MessagePartComponentTypes.js";
|
|
10
|
+
import { ToolCallText, ToolDefinition, Toolkit, ToolkitDefinition, ToolkitDefinitionEntry } from "./model-context/toolbox.js";
|
|
11
|
+
import { defineToolkit } from "./model-context/define-toolkit.js";
|
|
12
|
+
import { McpToolkitDefinition, McpToolkitEntry, McpToolkitToolConfig, defineMcpToolkit } from "./model-context/define-mcp-toolkit.js";
|
|
6
13
|
import { AssistantProviderBase, AssistantProviderBaseProps, getRenderComponent } from "./AssistantProvider.js";
|
|
7
14
|
import { AssistantRuntimeProvider } from "./AssistantRuntimeProvider.js";
|
|
8
|
-
import { RuntimeAdapter } from "./RuntimeAdapter.js";
|
|
9
15
|
import { TitleGenerationAdapter, createSimpleTitleAdapter } from "./adapters/TitleGenerationAdapter.js";
|
|
10
16
|
import { AsyncStorageLike, createLocalStorageAdapter } from "./adapters/LocalStorageThreadListAdapter.js";
|
|
11
17
|
import { DataRenderers } from "./client/DataRenderers.js";
|
|
12
|
-
import { DataMessagePartComponent, DataMessagePartProps, EmptyMessagePartComponent, EmptyMessagePartProps, FileMessagePartComponent, FileMessagePartProps, GenerativeUIComponentRegistry, GenerativeUIMessagePartComponent, GenerativeUIMessagePartProps, GenerativeUIRenderProps, ImageMessagePartComponent, ImageMessagePartProps, QuoteMessagePartComponent, QuoteMessagePartProps, ReasoningGroupComponent, ReasoningGroupProps, ReasoningMessagePartComponent, ReasoningMessagePartProps, SourceMessagePartComponent, SourceMessagePartProps, TextMessagePartComponent, TextMessagePartProps, ToolCallMessagePartComponent, ToolCallMessagePartProps, Unstable_AudioMessagePartComponent, Unstable_AudioMessagePartProps } from "./types/MessagePartComponentTypes.js";
|
|
13
18
|
import { Unstable_InteractableDefinition, Unstable_InteractablePersistedState, Unstable_InteractablePersistenceAdapter, Unstable_InteractablePersistenceStatus, Unstable_InteractableRegistration, Unstable_InteractableStateSchema, Unstable_InteractablesClientSchema, Unstable_InteractablesConfig, Unstable_InteractablesMethods, Unstable_InteractablesState } from "./types/scopes/interactables.js";
|
|
14
19
|
import { unstable_Interactables } from "./client/Interactables.js";
|
|
15
20
|
import { McpAppResourceOutput, ToolsClientSchema, ToolsMethods, ToolsState } from "./types/scopes/tools.js";
|
|
16
|
-
import { ToolCallText, ToolDefinition, Toolkit, ToolkitDefinition, ToolkitDefinitionEntry } from "./model-context/toolbox.js";
|
|
17
21
|
import { Tools } from "./client/Tools.js";
|
|
18
22
|
import { AssistantToolProps, useAssistantTool } from "./model-context/useAssistantTool.js";
|
|
19
23
|
import { AssistantTool, makeAssistantTool } from "./model-context/makeAssistantTool.js";
|
|
@@ -24,13 +28,11 @@ import { AssistantDataUI, makeAssistantDataUI } from "./model-context/makeAssist
|
|
|
24
28
|
import { useAssistantInstructions } from "./model-context/useAssistantInstructions.js";
|
|
25
29
|
import { useAssistantContext } from "./model-context/useAssistantContext.js";
|
|
26
30
|
import { useInlineRender } from "./model-context/useInlineRender.js";
|
|
27
|
-
import { defineToolkit } from "./model-context/define-toolkit.js";
|
|
28
31
|
import { stubTool } from "./model-context/stub-tool.js";
|
|
29
32
|
import { externalTool } from "./model-context/external-tool.js";
|
|
30
33
|
import { useAuiToolOverrides } from "./model-context/useAuiToolOverrides.js";
|
|
31
34
|
import { hitl, hitlTool, humanTool } from "./model-context/human-tool.js";
|
|
32
35
|
import { ProviderToolConfig, providerTool } from "./model-context/provider-tool.js";
|
|
33
|
-
import { McpToolkitDefinition, McpToolkitEntry, McpToolkitToolConfig, defineMcpToolkit } from "./model-context/define-mcp-toolkit.js";
|
|
34
36
|
import { InteractableDefinition, InteractablePersistedState, InteractablePersistenceAdapter, InteractablePersistenceStatus, InteractableRegistration, InteractableStateSchema, InteractablesClientSchema, InteractablesMethods, InteractablesState } from "./interactables-legacy/scopes.js";
|
|
35
37
|
import { AssistantInteractableProps, useAssistantInteractable } from "./interactables-legacy/useAssistantInteractable.js";
|
|
36
38
|
import { useInteractableState } from "./interactables-legacy/useInteractableState.js";
|
|
@@ -55,10 +57,8 @@ import { ReadonlyThreadProvider } from "./providers/ReadonlyThreadProvider.js";
|
|
|
55
57
|
import { RuntimeAdapterProvider, RuntimeAdapters, useRuntimeAdapters } from "./runtimes/RuntimeAdapterProvider.js";
|
|
56
58
|
import { useExternalStoreRuntime } from "./runtimes/useExternalStoreRuntime.js";
|
|
57
59
|
import { useExternalStoreSharedOptions } from "./runtimes/useExternalStoreSharedOptions.js";
|
|
58
|
-
import { JoinStrategy, convertExternalMessages, useExternalMessageConverter } from "./runtimes/external-message-converter.js";
|
|
59
60
|
import { createMessageConverter } from "./runtimes/createMessageConverter.js";
|
|
60
|
-
import {
|
|
61
|
-
import { RuntimeExtras, createRuntimeExtras } from "./runtimes/createRuntimeExtras.js";
|
|
61
|
+
import { RuntimeExtras, createRuntimeExtras, unstable_createRuntimeExtrasFromBrand } from "./runtimes/createRuntimeExtras.js";
|
|
62
62
|
import { RemoteThreadListHookInstanceManager } from "./runtimes/RemoteThreadListHookInstanceManager.js";
|
|
63
63
|
import { RemoteThreadListThreadListRuntimeCore } from "./runtimes/RemoteThreadListThreadListRuntimeCore.js";
|
|
64
64
|
import { useRemoteThreadListRuntime } from "./runtimes/useRemoteThreadListRuntime.js";
|
|
@@ -112,4 +112,4 @@ import { useEditComposerCancel } from "./primitive-hooks/useEditComposerCancel.j
|
|
|
112
112
|
import { useEditComposerSend } from "./primitive-hooks/useEditComposerSend.js";
|
|
113
113
|
import { useMessageError } from "./primitive-hooks/useMessageError.js";
|
|
114
114
|
import { LocalRuntimeOptions, splitLocalRuntimeOptions, useLocalRuntime } from "./runtimes/useLocalRuntime.js";
|
|
115
|
-
export { type AssistantContextConfig, type AssistantDataUI, type AssistantDataUIProps, type AssistantInteractableProps, AssistantProviderBase, type AssistantProviderBaseProps, AssistantRuntimeProvider, type AssistantTool, type AssistantToolProps, type AssistantToolUI, type AssistantToolUIProps, type AsyncStorageLike, ChainOfThoughtByIndicesProvider, ChainOfThoughtPartByIndexProvider, ChainOfThoughtPrimitiveParts, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, ComposerPrimitiveAttachmentByIndex, ComposerPrimitiveAttachments, ComposerPrimitiveIf, ComposerPrimitiveQueue, type DataMessagePartComponent, type DataMessagePartProps, DataRenderers, type DataRenderersClientSchema, type DataRenderersMethods, type DataRenderersState, type EmptyMessagePartComponent, type EmptyMessagePartProps, type EnrichedPartState, type FileMessagePartComponent, type FileMessagePartProps, type GenerativeUIComponentRegistry, type GenerativeUIMessagePartComponent, type GenerativeUIMessagePartProps, GenerativeUIRender, GenerativeUIRenderError, type GenerativeUIRenderProps, type GroupByContext, type ImageMessagePartComponent, type ImageMessagePartProps, type InteractableDefinition, type InteractablePersistedState, type InteractablePersistenceAdapter, type InteractablePersistenceStatus, type InteractableRegistration, type InteractableStateSchema, Interactables, type InteractablesClientSchema, type InteractablesMethods, type InteractablesState, type JoinStrategy, type LocalRuntimeOptions, type McpAppResourceOutput, type McpToolkitDefinition, type McpToolkitEntry, type McpToolkitToolConfig, MessageAttachmentByIndexProvider, MessageByIndexProvider, MessagePartComponent, MessagePartPrimitiveInProgress, MessagePrimitiveAttachmentByIndex, MessagePrimitiveAttachments, MessagePrimitiveGenerativeUI, MessagePrimitiveGroupedParts, MessagePrimitivePartByIndex, MessagePrimitiveParts, MessagePrimitiveQuote, PartByIndexProvider, PartPrimitiveMessages, PartPrimitiveMessagesImpl, type PartState, type ProviderToolConfig, QueueItemByIndexProvider, type QueueItemByIndexProviderProps, type QuoteMessagePartComponent, type QuoteMessagePartProps, ReadonlyThreadProvider, type ReasoningGroupComponent, type ReasoningGroupProps, type ReasoningMessagePartComponent, type ReasoningMessagePartProps, RemoteThreadListHookInstanceManager, RemoteThreadListThreadListRuntimeCore, RuntimeAdapter, RuntimeAdapterProvider, type RuntimeAdapters, type RuntimeExtras, type SourceMessagePartComponent, type SourceMessagePartProps, type StreamingTimingAccessors, type StreamingTimingOptions, type StreamingTimingState, SuggestionByIndexProvider, type SuggestionByIndexProviderProps, type TextMessagePartComponent, type TextMessagePartProps, TextMessagePartProvider, ThreadListItemByIndexProvider, ThreadListItemPrimitiveTitle, ThreadListItemRuntimeProvider, ThreadListPrimitiveItemByIndex, ThreadListPrimitiveItems, ThreadPrimitiveMessageByIndex, ThreadPrimitiveMessages, ThreadPrimitiveMessagesImpl, ThreadPrimitiveSuggestionByIndex, ThreadPrimitiveSuggestions, ThreadPrimitiveSuggestionsImpl, ThreadPrimitiveUnstable_MessageById, type TitleGenerationAdapter, type ToolArgsStatus, type ToolCallMessagePartComponent, type ToolCallMessagePartProps, type ToolCallText, type ToolDefinition, type Toolkit, type ToolkitDefinition, type ToolkitDefinitionEntry, Tools, type ToolsClientSchema, type ToolsMethods, type ToolsState, type Unstable_AudioMessagePartComponent, type Unstable_AudioMessagePartProps, type Unstable_InferInteractableState, type Unstable_InteractableConfig, type Unstable_InteractableDefinition, type Unstable_InteractablePersistedState, type Unstable_InteractablePersistenceAdapter, type Unstable_InteractablePersistenceStatus, type Unstable_InteractableRegistration, type Unstable_InteractableStateSchema, type Unstable_InteractableToolConfig, type Unstable_InteractableToolRenderProps, type Unstable_InteractableVersionInfo, type Unstable_InteractablesClientSchema, type Unstable_InteractablesConfig, type Unstable_InteractablesMethods, type Unstable_InteractablesState, type UseActionBarCopyOptions, type UseComposerIfProps, type UseSuggestionTriggerOptions, convertExternalMessages, createLocalStorageAdapter, createMessageConverter, createRuntimeExtras, createSimpleTitleAdapter, defineMcpToolkit, defineToolkit, externalTool, getMessageQuote, getRenderComponent, groupPartByType, hitl, hitlTool, humanTool, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, defaultComponents as messagePartsDefaultComponents, providerTool, splitLocalRuntimeOptions, stubTool, unstable_Interactables, unstable_interactableTool, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useThreadMessageIds, useActionBarCopy, useActionBarEdit, useActionBarFeedbackNegative, useActionBarFeedbackPositive, useActionBarReload, useActionBarSpeak, useActionBarStopSpeaking, useAssistantCloudThreadHistoryAdapter, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAuiToolOverrides, useBranchPickerNext, useBranchPickerPrevious, useCloudThreadListAdapter, useComposerAddAttachment, useComposerCancel, useComposerDictate, useComposerSend, useEditComposerCancel, useEditComposerSend, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessageBranching, useMessageError, useMessageReload, useRemoteThreadListRuntime, useRuntimeAdapters, useStreamingTiming, useSuggestionTrigger, useThreadIsEmpty, useThreadIsRunning, useThreadListItemArchive, useThreadListItemDelete, useThreadListItemTrigger, useThreadListItemUnarchive, useThreadListLoadMore, useThreadListNew, useThreadMessages, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
115
|
+
export { type AssistantContextConfig, type AssistantDataUI, type AssistantDataUIProps, type AssistantInteractableProps, AssistantProviderBase, type AssistantProviderBaseProps, AssistantRuntimeProvider, type AssistantTool, type AssistantToolProps, type AssistantToolUI, type AssistantToolUIProps, type AsyncStorageLike, ChainOfThoughtByIndicesProvider, ChainOfThoughtPartByIndexProvider, ChainOfThoughtPrimitiveParts, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, ComposerPrimitiveAttachmentByIndex, ComposerPrimitiveAttachments, ComposerPrimitiveIf, ComposerPrimitiveQueue, type DataMessagePartComponent, type DataMessagePartProps, DataRenderers, type DataRenderersClientSchema, type DataRenderersMethods, type DataRenderersState, type EmptyMessagePartComponent, type EmptyMessagePartProps, type EnrichedPartState, type FileMessagePartComponent, type FileMessagePartProps, type GenerativeUIComponentRegistry, type GenerativeUIMessagePartComponent, type GenerativeUIMessagePartProps, GenerativeUIRender, GenerativeUIRenderError, type GenerativeUIRenderProps, type GroupByContext, type ImageMessagePartComponent, type ImageMessagePartProps, type InteractableDefinition, type InteractablePersistedState, type InteractablePersistenceAdapter, type InteractablePersistenceStatus, type InteractableRegistration, type InteractableStateSchema, Interactables, type InteractablesClientSchema, type InteractablesMethods, type InteractablesState, type JoinStrategy, type LocalRuntimeOptions, type McpAppResourceOutput, type McpToolkitDefinition, type McpToolkitEntry, type McpToolkitToolConfig, MessageAttachmentByIndexProvider, MessageByIndexProvider, MessagePartComponent, MessagePartPrimitiveInProgress, MessagePrimitiveAttachmentByIndex, MessagePrimitiveAttachments, MessagePrimitiveGenerativeUI, MessagePrimitiveGroupedParts, MessagePrimitivePartByIndex, MessagePrimitiveParts, MessagePrimitiveQuote, PartByIndexProvider, PartPrimitiveMessages, PartPrimitiveMessagesImpl, type PartState, type ProviderToolConfig, QueueItemByIndexProvider, type QueueItemByIndexProviderProps, type QuoteMessagePartComponent, type QuoteMessagePartProps, ReadonlyThreadProvider, type ReasoningGroupComponent, type ReasoningGroupProps, type ReasoningMessagePartComponent, type ReasoningMessagePartProps, RemoteThreadListHookInstanceManager, RemoteThreadListThreadListRuntimeCore, RuntimeAdapter, RuntimeAdapterProvider, type RuntimeAdapters, type RuntimeExtras, type SourceMessagePartComponent, type SourceMessagePartProps, type StreamingTimingAccessors, type StreamingTimingOptions, type StreamingTimingState, SuggestionByIndexProvider, type SuggestionByIndexProviderProps, type TextMessagePartComponent, type TextMessagePartProps, TextMessagePartProvider, ThreadListItemByIndexProvider, ThreadListItemPrimitiveTitle, ThreadListItemRuntimeProvider, ThreadListPrimitiveItemByIndex, ThreadListPrimitiveItems, ThreadPrimitiveMessageByIndex, ThreadPrimitiveMessages, ThreadPrimitiveMessagesImpl, ThreadPrimitiveSuggestionByIndex, ThreadPrimitiveSuggestions, ThreadPrimitiveSuggestionsImpl, ThreadPrimitiveUnstable_MessageById, type TitleGenerationAdapter, type ToolArgsStatus, type ToolCallMessagePartComponent, type ToolCallMessagePartProps, type ToolCallText, type ToolDefinition, type Toolkit, type ToolkitDefinition, type ToolkitDefinitionEntry, Tools, type ToolsClientSchema, type ToolsMethods, type ToolsState, type Unstable_AudioMessagePartComponent, type Unstable_AudioMessagePartProps, type Unstable_InferInteractableState, type Unstable_InteractableConfig, type Unstable_InteractableDefinition, type Unstable_InteractablePersistedState, type Unstable_InteractablePersistenceAdapter, type Unstable_InteractablePersistenceStatus, type Unstable_InteractableRegistration, type Unstable_InteractableStateSchema, type Unstable_InteractableToolConfig, type Unstable_InteractableToolRenderProps, type Unstable_InteractableVersionInfo, type Unstable_InteractablesClientSchema, type Unstable_InteractablesConfig, type Unstable_InteractablesMethods, type Unstable_InteractablesState, type UseActionBarCopyOptions, type UseComposerIfProps, type UseSuggestionTriggerOptions, convertExternalMessages, createLocalStorageAdapter, createMessageConverter, createRuntimeExtras, createSimpleTitleAdapter, defineMcpToolkit, defineToolkit, externalTool, getMessageQuote, getRenderComponent, groupPartByType, hitl, hitlTool, humanTool, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, defaultComponents as messagePartsDefaultComponents, providerTool, splitLocalRuntimeOptions, stubTool, unstable_Interactables, unstable_createRuntimeExtrasFromBrand, unstable_interactableTool, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useThreadMessageIds, useActionBarCopy, useActionBarEdit, useActionBarFeedbackNegative, useActionBarFeedbackPositive, useActionBarReload, useActionBarSpeak, useActionBarStopSpeaking, useAssistantCloudThreadHistoryAdapter, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAuiToolOverrides, useBranchPickerNext, useBranchPickerPrevious, useCloudThreadListAdapter, useComposerAddAttachment, useComposerCancel, useComposerDictate, useComposerSend, useEditComposerCancel, useEditComposerSend, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessageBranching, useMessageError, useMessageReload, useRemoteThreadListRuntime, useRuntimeAdapters, useStreamingTiming, useSuggestionTrigger, useThreadIsEmpty, useThreadIsRunning, useThreadListItemArchive, useThreadListItemDelete, useThreadListItemTrigger, useThreadListItemUnarchive, useThreadListLoadMore, useThreadListNew, useThreadMessages, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
package/dist/react/index.js
CHANGED
|
@@ -26,6 +26,8 @@ import { unstable_useInteractable } from "./model-context/useInteractable.js";
|
|
|
26
26
|
import { unstable_useInteractableVersions } from "./model-context/useInteractableVersions.js";
|
|
27
27
|
import { unstable_interactableTool } from "./model-context/interactableTool.js";
|
|
28
28
|
import { useToolArgsStatus } from "./model-context/useToolArgsStatus.js";
|
|
29
|
+
import { convertExternalMessages, useExternalMessageConverter } from "./runtimes/external-message-converter.js";
|
|
30
|
+
import { useStreamingTiming } from "./runtimes/useStreamingTiming.js";
|
|
29
31
|
import { Interactables } from "./interactables-legacy/Interactables.js";
|
|
30
32
|
import { unstable_Interactables } from "./client/Interactables.js";
|
|
31
33
|
import { ComposerAttachmentByIndexProvider, MessageAttachmentByIndexProvider } from "./providers/AttachmentByIndexProvider.js";
|
|
@@ -42,10 +44,8 @@ import { ReadonlyThreadProvider } from "./providers/ReadonlyThreadProvider.js";
|
|
|
42
44
|
import { RuntimeAdapterProvider, useRuntimeAdapters } from "./runtimes/RuntimeAdapterProvider.js";
|
|
43
45
|
import { useExternalStoreRuntime } from "./runtimes/useExternalStoreRuntime.js";
|
|
44
46
|
import { useExternalStoreSharedOptions } from "./runtimes/useExternalStoreSharedOptions.js";
|
|
45
|
-
import { convertExternalMessages, useExternalMessageConverter } from "./runtimes/external-message-converter.js";
|
|
46
47
|
import { createMessageConverter } from "./runtimes/createMessageConverter.js";
|
|
47
|
-
import {
|
|
48
|
-
import { createRuntimeExtras } from "./runtimes/createRuntimeExtras.js";
|
|
48
|
+
import { createRuntimeExtras, unstable_createRuntimeExtrasFromBrand } from "./runtimes/createRuntimeExtras.js";
|
|
49
49
|
import { RemoteThreadListHookInstanceManager } from "./runtimes/RemoteThreadListHookInstanceManager.js";
|
|
50
50
|
import { RemoteThreadListThreadListRuntimeCore } from "./runtimes/RemoteThreadListThreadListRuntimeCore.js";
|
|
51
51
|
import { useRemoteThreadListRuntime } from "./runtimes/useRemoteThreadListRuntime.js";
|
|
@@ -101,4 +101,4 @@ import { useEditComposerCancel } from "./primitive-hooks/useEditComposerCancel.j
|
|
|
101
101
|
import { useEditComposerSend } from "./primitive-hooks/useEditComposerSend.js";
|
|
102
102
|
import { useMessageError } from "./primitive-hooks/useMessageError.js";
|
|
103
103
|
import { splitLocalRuntimeOptions, useLocalRuntime } from "./runtimes/useLocalRuntime.js";
|
|
104
|
-
export { AssistantProviderBase, AssistantRuntimeProvider, ChainOfThoughtByIndicesProvider, ChainOfThoughtPartByIndexProvider, ChainOfThoughtPrimitiveParts, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, ComposerPrimitiveAttachmentByIndex, ComposerPrimitiveAttachments, ComposerPrimitiveIf, ComposerPrimitiveQueue, DataRenderers, GenerativeUIRender, GenerativeUIRenderError, Interactables, MessageAttachmentByIndexProvider, MessageByIndexProvider, MessagePartComponent, MessagePartPrimitiveInProgress, MessagePrimitiveAttachmentByIndex, MessagePrimitiveAttachments, MessagePrimitiveGenerativeUI, MessagePrimitiveGroupedParts, MessagePrimitivePartByIndex, MessagePrimitiveParts, MessagePrimitiveQuote, PartByIndexProvider, PartPrimitiveMessages, PartPrimitiveMessagesImpl, QueueItemByIndexProvider, ReadonlyThreadProvider, RemoteThreadListHookInstanceManager, RemoteThreadListThreadListRuntimeCore, RuntimeAdapter, RuntimeAdapterProvider, SuggestionByIndexProvider, TextMessagePartProvider, ThreadListItemByIndexProvider, ThreadListItemPrimitiveTitle, ThreadListItemRuntimeProvider, ThreadListPrimitiveItemByIndex, ThreadListPrimitiveItems, ThreadPrimitiveMessageByIndex, ThreadPrimitiveMessages, ThreadPrimitiveMessagesImpl, ThreadPrimitiveSuggestionByIndex, ThreadPrimitiveSuggestions, ThreadPrimitiveSuggestionsImpl, ThreadPrimitiveUnstable_MessageById, Tools, convertExternalMessages, createLocalStorageAdapter, createMessageConverter, createRuntimeExtras, createSimpleTitleAdapter, defineMcpToolkit, defineToolkit, externalTool, getMessageQuote, getRenderComponent, groupPartByType, hitl, hitlTool, humanTool, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, defaultComponents as messagePartsDefaultComponents, providerTool, splitLocalRuntimeOptions, stubTool, unstable_Interactables, unstable_interactableTool, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useThreadMessageIds, useActionBarCopy, useActionBarEdit, useActionBarFeedbackNegative, useActionBarFeedbackPositive, useActionBarReload, useActionBarSpeak, useActionBarStopSpeaking, useAssistantCloudThreadHistoryAdapter, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAuiToolOverrides, useBranchPickerNext, useBranchPickerPrevious, useCloudThreadListAdapter, useComposerAddAttachment, useComposerCancel, useComposerDictate, useComposerSend, useEditComposerCancel, useEditComposerSend, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessageBranching, useMessageError, useMessageReload, useRemoteThreadListRuntime, useRuntimeAdapters, useStreamingTiming, useSuggestionTrigger, useThreadIsEmpty, useThreadIsRunning, useThreadListItemArchive, useThreadListItemDelete, useThreadListItemTrigger, useThreadListItemUnarchive, useThreadListLoadMore, useThreadListNew, useThreadMessages, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
104
|
+
export { AssistantProviderBase, AssistantRuntimeProvider, ChainOfThoughtByIndicesProvider, ChainOfThoughtPartByIndexProvider, ChainOfThoughtPrimitiveParts, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, ComposerPrimitiveAttachmentByIndex, ComposerPrimitiveAttachments, ComposerPrimitiveIf, ComposerPrimitiveQueue, DataRenderers, GenerativeUIRender, GenerativeUIRenderError, Interactables, MessageAttachmentByIndexProvider, MessageByIndexProvider, MessagePartComponent, MessagePartPrimitiveInProgress, MessagePrimitiveAttachmentByIndex, MessagePrimitiveAttachments, MessagePrimitiveGenerativeUI, MessagePrimitiveGroupedParts, MessagePrimitivePartByIndex, MessagePrimitiveParts, MessagePrimitiveQuote, PartByIndexProvider, PartPrimitiveMessages, PartPrimitiveMessagesImpl, QueueItemByIndexProvider, ReadonlyThreadProvider, RemoteThreadListHookInstanceManager, RemoteThreadListThreadListRuntimeCore, RuntimeAdapter, RuntimeAdapterProvider, SuggestionByIndexProvider, TextMessagePartProvider, ThreadListItemByIndexProvider, ThreadListItemPrimitiveTitle, ThreadListItemRuntimeProvider, ThreadListPrimitiveItemByIndex, ThreadListPrimitiveItems, ThreadPrimitiveMessageByIndex, ThreadPrimitiveMessages, ThreadPrimitiveMessagesImpl, ThreadPrimitiveSuggestionByIndex, ThreadPrimitiveSuggestions, ThreadPrimitiveSuggestionsImpl, ThreadPrimitiveUnstable_MessageById, Tools, convertExternalMessages, createLocalStorageAdapter, createMessageConverter, createRuntimeExtras, createSimpleTitleAdapter, defineMcpToolkit, defineToolkit, externalTool, getMessageQuote, getRenderComponent, groupPartByType, hitl, hitlTool, humanTool, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, defaultComponents as messagePartsDefaultComponents, providerTool, splitLocalRuntimeOptions, stubTool, unstable_Interactables, unstable_createRuntimeExtrasFromBrand, unstable_interactableTool, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useThreadMessageIds, useActionBarCopy, useActionBarEdit, useActionBarFeedbackNegative, useActionBarFeedbackPositive, useActionBarReload, useActionBarSpeak, useActionBarStopSpeaking, useAssistantCloudThreadHistoryAdapter, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAuiToolOverrides, useBranchPickerNext, useBranchPickerPrevious, useCloudThreadListAdapter, useComposerAddAttachment, useComposerCancel, useComposerDictate, useComposerSend, useEditComposerCancel, useEditComposerSend, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessageBranching, useMessageError, useMessageReload, useRemoteThreadListRuntime, useRuntimeAdapters, useStreamingTiming, useSuggestionTrigger, useThreadIsEmpty, useThreadIsRunning, useThreadListItemArchive, useThreadListItemDelete, useThreadListItemTrigger, useThreadListItemUnarchive, useThreadListLoadMore, useThreadListNew, useThreadMessages, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Unstable_InteractableStateSchema } from "../types/scopes/interactables.js";
|
|
2
1
|
import { ToolDefinition } from "./toolbox.js";
|
|
2
|
+
import { Unstable_InteractableStateSchema } from "../types/scopes/interactables.js";
|
|
3
3
|
import { Unstable_InferInteractableState, Unstable_InteractableVersionInfo } from "./useInteractable.js";
|
|
4
4
|
import { ReactNode } from "react";
|
|
5
5
|
//#region src/react/model-context/interactableTool.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AssistantToolProps as AssistantToolProps$1 } from "../../model-context/types.js";
|
|
2
|
-
import "../../index.js";
|
|
3
2
|
import { ToolCallMessagePartComponent } from "../types/MessagePartComponentTypes.js";
|
|
4
3
|
import { ToolCallText } from "./toolbox.js";
|
|
4
|
+
import "../../index.js";
|
|
5
5
|
//#region src/react/model-context/useAssistantTool.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Props used to register a tool from React.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auiV0.d.ts","names":[],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"mappings":";;;;;;KAgBK;WACM;WACA;WACA;WACA;WACA,mBAAmB;WACnB;WACA;;KAGN;WAEU;WACA;;WAGA;WACA;;WAGA;WACA;WACA;WACA;WACA;WACA,mBAAmB;;WAGnB;WACA;WACA;WACA;WACA;WACA;WACA,mBAAmB;;WAGnB;WACA;WACA;WACA,MAAM;WACN,SAAS;WACT;WACA,WAAW;;WAGX;WACA;WACA;WACA;WACA,SAAS;WACT;WACA,WAAW;;WAGX;WACA;;WAGA;WACA;WACA;WACA;WACA;;KAGV;WAEU;WACA;;WAGA;WACA;WACA;;WAGA;WACA;WACA;WACA;WACA;;WAGA;WACA;aACE;aACA;;;WAIF;WACA;WACA,MAAM;;KAGhB;WACM;WACA,MAAM;WACN;WACA;WACA,QAAQ;WACR,kBAAkB;;KAGxB;WACM;WACA,SAAS;WACT,kBAAkB;WAClB,uBAAuB;WACvB;aACE,iBAAiB;aACjB,+BAA+B;aAC/B,wBAAwB;aACxB;eACE;iBACE;iBACA;;;aAGJ,QAAQ;;;iBA2EL,YAAY,SAAS,gBAAgB;
|
|
1
|
+
{"version":3,"file":"auiV0.d.ts","names":[],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"mappings":";;;;;;KAgBK;WACM;WACA;WACA;WACA;WACA,mBAAmB;WACnB;WACA;;KAGN;WAEU;WACA;;WAGA;WACA;WACA;;WAGA;WACA;WACA;WACA;WACA;WACA,mBAAmB;;WAGnB;WACA;WACA;WACA;WACA;WACA;WACA,mBAAmB;;WAGnB;WACA;WACA;WACA,MAAM;WACN,SAAS;WACT;WACA,WAAW;;WAGX;WACA;WACA;WACA;WACA,SAAS;WACT;WACA,WAAW;;WAGX;WACA;;WAGA;WACA;WACA;WACA;WACA;;KAGV;WAEU;WACA;;WAGA;WACA;WACA;;WAGA;WACA;WACA;WACA;WACA;;WAGA;WACA;aACE;aACA;;;WAIF;WACA;WACA,MAAM;;KAGhB;WACM;WACA,MAAM;WACN;WACA;WACA,QAAQ;WACR,kBAAkB;;KAGxB;WACM;WACA,SAAS;WACT,kBAAkB;WAClB,uBAAuB;WACvB;aACE,iBAAiB;aACjB,+BAA+B;aAC/B,wBAAwB;aACxB;eACE;iBACE;iBACA;;;aAGJ,QAAQ;;;iBA2EL,YAAY,SAAS,gBAAgB;iBAoGrC,YACd,cAAc;EAAiB;IAC9B"}
|
|
@@ -65,7 +65,8 @@ function auiV0Encode(message) {
|
|
|
65
65
|
};
|
|
66
66
|
case "reasoning": return {
|
|
67
67
|
type: "reasoning",
|
|
68
|
-
text: part.text
|
|
68
|
+
text: part.text,
|
|
69
|
+
...part.unstable_summary !== void 0 ? { unstable_summary: part.unstable_summary } : void 0
|
|
69
70
|
};
|
|
70
71
|
case "source":
|
|
71
72
|
if (part.sourceType === "url") return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auiV0.js","names":["MessageStatus","SourceProviderMetadata","ThreadMessage","ToolApprovalOption","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","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/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n ToolApprovalOption,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\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 }\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 { type: \"reasoning\", text: part.text };\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":";;;AA4IA,MAAM0D,wBACJC,SACwB;CACxB,MAAMvC,OAAOuC,KAAKvC;CAClB,QAAQA,MAAR;EACE,KAAK,QACH,OAAO;GAAEA,MAAM;GAAQC,MAAMsC,KAAKtC;EAAK;EAEzC,KAAK,SACH,OAAO;GACLD,MAAM;GACNe,OAAOwB,KAAKxB;GACZ,GAAIwB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;EAC5D;EAEF,KAAK,QACH,OAAO;GACLxC,MAAM;GACNgB,MAAMuB,KAAKvB;GACXC,UAAUsB,KAAKtB;GACf,GAAIsB,KAAKhC,YAAY,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AAKxB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLf,MAAM;KACNgB,MAAMuB,KAAKvB;KACXC,UAAUsB,KAAKtB;KACf,GAAIsB,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,UAAU/D,sBACd;EACEO,IAAI6D,aAAa7D;EACjB+D,WAAWF,aAAaG;EACxB,GAAGF;CACL,GACAD,aAAa7D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACL+D,UAAUJ,aAAaK;EACvBV;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"auiV0.js","names":["MessageStatus","SourceProviderMetadata","ThreadMessage","ToolApprovalOption","CompleteAttachment","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/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n ToolApprovalOption,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\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,GA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1B,WAAW,EAAEA,UAAU0B,KAAK1B,SAAS,IAAI2B,KAAAA;KACpD;IAGF,KAAK,SACH,OAAO;KAAEzC,MAAM;KAASgB,OAAOwB,KAAKxB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLhB,MAAM;KACNiB,MAAMuB,KAAKvB;KACXC,UAAUsB,KAAKtB;KACf,GAAIsB,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,6 +1,6 @@
|
|
|
1
1
|
import { ThreadMessage } from "../../types/message.js";
|
|
2
|
-
import { ThreadState } from "../../runtime/api/thread-runtime.js";
|
|
3
2
|
import { JoinStrategy, useExternalMessageConverter } from "./external-message-converter.js";
|
|
3
|
+
import { ThreadState } from "../../runtime/api/thread-runtime.js";
|
|
4
4
|
//#region src/react/runtimes/createMessageConverter.d.ts
|
|
5
5
|
declare const createMessageConverter: <T extends object>(callback: useExternalMessageConverter.Callback<T>) => {
|
|
6
6
|
useThreadMessages: ({ messages, isRunning, joinStrategy, metadata }: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RuntimeExtrasBrand } from "../../runtime/utils/runtime-extras-brand.js";
|
|
1
2
|
import { AssistantClient } from "@assistant-ui/store";
|
|
2
3
|
//#region src/react/runtimes/createRuntimeExtras.d.ts
|
|
3
4
|
/** @deprecated Internal API for external-store adapter authors. Not part of the public API; may change or be removed without notice. */
|
|
@@ -13,7 +14,9 @@ type RuntimeExtras<T extends object> = {
|
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
/** @deprecated Internal API for external-store adapter authors. Not part of the public API; may change or be removed without notice. */
|
|
17
|
+
declare const unstable_createRuntimeExtrasFromBrand: <T extends object>(brand: RuntimeExtrasBrand<T>) => RuntimeExtras<T>;
|
|
18
|
+
/** @deprecated Internal API for external-store adapter authors. Not part of the public API; may change or be removed without notice. */
|
|
16
19
|
declare const createRuntimeExtras: <T extends object>(runtimeName: string) => RuntimeExtras<T>;
|
|
17
20
|
//#endregion
|
|
18
|
-
export { RuntimeExtras, createRuntimeExtras };
|
|
21
|
+
export { RuntimeExtras, createRuntimeExtras, unstable_createRuntimeExtrasFromBrand };
|
|
19
22
|
//# sourceMappingURL=createRuntimeExtras.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRuntimeExtras.d.ts","names":[],"sources":["../../../src/react/runtimes/createRuntimeExtras.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRuntimeExtras.d.ts","names":[],"sources":["../../../src/react/runtimes/createRuntimeExtras.ts"],"mappings":";;;;KAUY,cAAc;EACxB,UAAU,OAAO,MAAM;EACvB,KAAK,oBAAoB,UAAU;EACnC,SAAS,oBAAoB;EAC7B,MAAM,QAAQ,oBAAoB;EAClC;QACM;KACH,GAAG,SAAS,QAAQ,MAAM,IAAI;KAC9B,GAAG,SAAS,QAAQ,MAAM,GAAG,UAAU,IAAI;;;;cAKnC,wCAAyC,kBACpD,OAAO,mBAAmB,OACzB,cAAc;;cA0BJ,sBAAuB,kBAClC,wBACC,cAAc"}
|