@assistant-ui/react 0.7.25 → 0.7.27
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/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.js +1 -2
- package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs +2 -3
- package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
- package/dist/model-config/useAssistantInstructions.d.ts +6 -1
- package/dist/model-config/useAssistantInstructions.d.ts.map +1 -1
- package/dist/model-config/useAssistantInstructions.js +9 -3
- package/dist/model-config/useAssistantInstructions.js.map +1 -1
- package/dist/model-config/useAssistantInstructions.mjs +9 -3
- package/dist/model-config/useAssistantInstructions.mjs.map +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.d.ts +9 -2
- package/dist/runtimes/core/AssistantRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.d.ts +2 -0
- package/dist/runtimes/core/BaseAssistantRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseAssistantRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +4 -0
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +6 -0
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts +5 -2
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js +21 -6
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs +21 -6
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.js +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.js.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.mjs +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts +1 -0
- package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.js +1 -0
- package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.mjs +1 -0
- package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js +3 -3
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs +3 -3
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +3 -6
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +4 -7
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js +1 -2
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs +1 -2
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +2 -2
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/types.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +2 -2
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +2 -2
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -1
- package/dist/styles/index.css +8 -7
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/tailwindcss/thread.css +7 -7
- package/dist/styles/tailwindcss/thread.css.json +7 -7
- package/dist/styles/themes/default.css +3 -0
- package/dist/styles/themes/default.css.json +2 -1
- package/dist/styles/themes/shadcn-extras.css +4 -0
- package/dist/styles/themes/shadcn-extras.css.json +5 -0
- package/dist/tailwindcss/index.d.ts.map +1 -1
- package/dist/tailwindcss/index.js +7 -0
- package/dist/tailwindcss/index.js.map +1 -1
- package/dist/tailwindcss/index.mjs +7 -0
- package/dist/tailwindcss/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/context/providers/AssistantRuntimeProvider.tsx +2 -6
- package/src/model-config/useAssistantInstructions.tsx +19 -1
- package/src/runtimes/core/AssistantRuntimeCore.tsx +9 -2
- package/src/runtimes/core/BaseAssistantRuntimeCore.tsx +4 -0
- package/src/runtimes/core/ThreadRuntimeCore.tsx +5 -0
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +8 -0
- package/src/runtimes/external-store/ExternalStoreRuntimeCore.tsx +26 -6
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +2 -2
- package/src/runtimes/external-store/useExternalStoreRuntime.tsx +1 -1
- package/src/runtimes/local/LocalRuntimeCore.tsx +1 -0
- package/src/runtimes/remote-thread-list/EMPTY_THREAD_CORE.tsx +7 -3
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +4 -10
- package/src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx +1 -2
- package/src/runtimes/remote-thread-list/types.tsx +2 -2
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +2 -2
- package/src/styles/tailwindcss/thread.css +7 -7
- package/src/styles/themes/default.css +3 -0
- package/src/styles/themes/shadcn-extras.css +4 -0
- package/src/tailwindcss/index.ts +7 -0
- package/dist/primitive-hooks/thread/useThread.d.ts +0 -1
- package/dist/primitive-hooks/thread/useThread.d.ts.map +0 -1
- package/dist/primitive-hooks/thread/useThread.js +0 -2
- package/dist/primitive-hooks/thread/useThread.js.map +0 -1
- package/dist/primitive-hooks/thread/useThread.mjs +0 -1
- package/dist/primitive-hooks/thread/useThread.mjs.map +0 -1
- package/src/primitive-hooks/thread/useThread.tsx +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["import { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../internal\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { RemoteThreadListHookInstanceManager } from \"./RemoteThreadListHookInstanceManager\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { EMPTY_THREAD_CORE } from \"./EMPTY_THREAD_CORE\";\nimport { OptimisticState } from \"./OptimisticState\";\nimport { FC, PropsWithChildren, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { CloudInitializeResponse } from \"./cloud/CloudContext\";\n\ntype RemoteThreadData =\n | {\n readonly threadId: string;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly threadId: string;\n readonly remoteId: string;\n readonly externalId: string | undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n };\n\nconst DEFAULT_RENDER_COMPONENT: FC<PropsWithChildren> = ({ children }) => {\n return children;\n};\n\ntype THREAD_MAPPING_ID = string & { __brand: \"THREAD_MAPPING_ID\" };\nfunction createThreadMappingId(id: string): THREAD_MAPPING_ID {\n return id as THREAD_MAPPING_ID;\n}\n\ntype RemoteThreadState = {\n readonly isLoading: boolean;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly threadIdMap: Readonly<Record<string, THREAD_MAPPING_ID>>;\n readonly threadData: Readonly<Record<THREAD_MAPPING_ID, RemoteThreadData>>;\n};\n\nconst getThreadData = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n) => {\n const idx = state.threadIdMap[threadIdOrRemoteId];\n if (idx === undefined) return undefined;\n return state.threadData[idx];\n};\n\nconst updateStatusReducer = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n newStatus: \"regular\" | \"archived\" | \"deleted\",\n) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n const { threadId, remoteId, status: lastStatus } = data;\n if (lastStatus === newStatus) return state;\n\n const newState = { ...state };\n\n // lastStatus\n switch (lastStatus) {\n case \"new\":\n newState.newThreadId = undefined;\n break;\n case \"regular\":\n newState.threadIds = newState.threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newStatus\n switch (newStatus) {\n case \"regular\":\n newState.threadIds = [...newState.threadIds, threadId];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [...newState.archivedThreadIds, threadId];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== threadId),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== threadId && key !== remoteId,\n ),\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = newStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newStatus !== \"deleted\") {\n newState.threadData = {\n ...newState.threadData,\n [threadId]: {\n ...data,\n status: newStatus,\n },\n };\n }\n\n return newState;\n};\n\nexport class RemoteThreadListThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _adapter!: RemoteThreadListAdapter;\n private _disposeOldAdapter?: () => void;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private readonly _loadThreadsPromise: Promise<void>;\n\n private _mainThreadId!: string;\n private readonly _state = new OptimisticState<RemoteThreadState>({\n isLoading: false,\n newThreadId: undefined,\n threadIds: [],\n archivedThreadIds: [],\n threadIdMap: {},\n threadData: {},\n });\n\n public getLoadThreadsPromise() {\n return this._loadThreadsPromise;\n }\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n adapter.runtimeHook,\n );\n this.useRenderComponent = create(() => ({\n RenderComponent:\n adapter.__internal_RenderComponent ?? DEFAULT_RENDER_COMPONENT,\n }));\n this.__internal_setAdapter(adapter);\n\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => adapter.list(),\n loading: (state) => {\n return {\n ...state,\n isLoading: true,\n };\n },\n then: (state, l) => {\n const newThreadIds = [];\n const newArchivedThreadIds = [];\n const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;\n const newThreadData = {} as Record<\n THREAD_MAPPING_ID,\n RemoteThreadData\n >;\n\n for (const thread of l.threads) {\n switch (thread.status) {\n case \"regular\":\n newThreadIds.push(thread.remoteId);\n break;\n case \"archived\":\n newArchivedThreadIds.push(thread.remoteId);\n break;\n default: {\n const _exhaustiveCheck: never = thread.status;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n const mappingId = createThreadMappingId(thread.remoteId);\n newThreadIdMap[thread.remoteId] = mappingId;\n newThreadData[mappingId] = {\n threadId: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n };\n }\n\n return {\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: {\n ...state.threadIdMap,\n ...newThreadIdMap,\n },\n threadData: {\n ...state.threadData,\n ...newThreadData,\n },\n };\n },\n })\n .then(() => {});\n\n this.switchToNewThread();\n }\n\n private useRenderComponent;\n\n public __internal_setAdapter(adapter: RemoteThreadListAdapter) {\n if (this._adapter === adapter) return;\n\n this._adapter = adapter;\n this._disposeOldAdapter?.();\n this._disposeOldAdapter = this._adapter.onInitialize(this._onInitialize);\n\n const RenderComponent =\n adapter.__internal_RenderComponent ?? DEFAULT_RENDER_COMPONENT;\n if (\n RenderComponent !== this.useRenderComponent.getState().RenderComponent\n ) {\n this.useRenderComponent.setState({ RenderComponent }, true);\n }\n\n this._hookManager.setRuntimeHook(adapter.runtimeHook);\n }\n\n public get threadIds() {\n return this._state.value.threadIds;\n }\n\n public get archivedThreadIds() {\n return this._state.value.archivedThreadIds;\n }\n\n public get newThreadId() {\n return this._state.value.newThreadId;\n }\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);\n if (!result) return EMPTY_THREAD_CORE;\n return result;\n }\n\n public getItemById(threadIdOrRemoteId: string) {\n return getThreadData(this._state.value, threadIdOrRemoteId);\n }\n\n public async switchToThread(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (this._mainThreadId === data.threadId) return;\n\n const task = this._hookManager.startThreadRuntime(data.threadId);\n if (this.mainThreadId !== undefined) {\n await task;\n } else {\n task.then(() => this._notifySubscribers());\n }\n\n if (data.status === \"archived\") await this.unarchive(data.threadId);\n this._mainThreadId = data.threadId;\n\n this._notifySubscribers();\n }\n\n public async switchToNewThread(): Promise<void> {\n // an initialization transaction is in progress, wait for it to settle\n while (\n this._state.baseValue.newThreadId !== undefined &&\n this._state.value.newThreadId === undefined\n ) {\n await this._state.waitForUpdate();\n }\n\n const state = this._state.value;\n let threadId: string | undefined = this._state.value.newThreadId;\n if (threadId === undefined) {\n do {\n threadId = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[threadId]);\n\n const mappingId = createThreadMappingId(threadId);\n this._state.update({\n ...state,\n newThreadId: threadId,\n threadIdMap: {\n ...state.threadIdMap,\n [threadId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n status: \"new\",\n threadId,\n },\n },\n });\n }\n\n return this.switchToThread(threadId);\n }\n\n private _onInitialize = async (task: Promise<CloudInitializeResponse>) => {\n const threadId = this._state.value.newThreadId;\n if (!threadId)\n throw new Error(\n \"ThreadListAdapter called onInitialize before switching to new thread\",\n );\n\n await this._state.optimisticUpdate({\n execute: () => {\n return task;\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(remoteId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n ...data,\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._adapter.rename(data.remoteId, newTitle);\n },\n optimistic: (state) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n // if thread is main thread, switch to another thread\n if (threadId === this._mainThreadId) {\n const lastThreadId = this._state.value.threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n }\n }\n\n public async archive(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n return this._adapter.archive(data.remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"archived\");\n },\n });\n }\n\n public unarchive(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n try {\n return await this._adapter.unarchive(data.remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.threadId);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"regular\");\n },\n });\n }\n\n public async delete(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n return await this._adapter.delete(data.remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"deleted\");\n },\n });\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC<PropsWithChildren> = ({ children }) => {\n const id = useId();\n useEffect(() => {\n this.useBoundIds.setState((s) => [...s, id], true);\n return () => {\n this.useBoundIds.setState((s) => s.filter((i) => i !== id), true);\n };\n }, []);\n\n const boundIds = this.useBoundIds();\n const { RenderComponent } = this.useRenderComponent();\n\n return (\n <RenderComponent>\n {(boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <this._hookManager.__internal_RenderThreadRuntimes />\n )}\n\n {children}\n </RenderComponent>\n );\n };\n}\n"],"mappings":";AACA,SAAS,kBAAkB;AAE3B,SAAS,2CAA2C;AACpD,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAgC,WAAW,aAAa;AACxD,SAAS,cAAc;AAmdjB,SAGI,KAHJ;AAhcN,IAAM,2BAAkD,CAAC,EAAE,SAAS,MAAM;AACxE,SAAO;AACT;AAGA,SAAS,sBAAsB,IAA+B;AAC5D,SAAO;AACT;AAWA,IAAM,gBAAgB,CACpB,OACA,uBACG;AACH,QAAM,MAAM,MAAM,YAAY,kBAAkB;AAChD,MAAI,QAAQ,OAAW,QAAO;AAC9B,SAAO,MAAM,WAAW,GAAG;AAC7B;AAEA,IAAM,sBAAsB,CAC1B,OACA,oBACA,cACG;AACH,QAAM,OAAO,cAAc,OAAO,kBAAkB;AACpD,MAAI,CAAC,KAAM,QAAO;AAElB,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,UAAU,SAAS;AAAA,MAC5D;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAa,OAAO,oBAA4B;AAC9C,UAAM,OAAO,KAAK,YAAY,kBAAkB;AAChD,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,aAAa,KAAK,WAAW;AAC/C,YAAM,IAAI,MAAM,+BAA+B;AAEjD,WAAO,KAAK,OAAO,iBAAiB;AAAA,MAClC,SAAS,YAAY;AACnB,cAAM,KAAK,uBAAuB,KAAK,QAAQ;AAC/C,eAAO,MAAM,KAAK,SAAS,OAAO,KAAK,QAAQ;AAAA,MACjD;AAAA,MACA,YAAY,CAAC,UAAU;AACrB,eAAO,oBAAoB,OAAO,KAAK,UAAU,SAAS;AAAA,MAC5D;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,OAAiB,MAAM,CAAC,CAAC;AAAA,EAExC,6BAAoD,CAAC,EAAE,SAAS,MAAM;AAC3E,UAAM,KAAK,MAAM;AACjB,cAAU,MAAM;AACd,WAAK,YAAY,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,IAAI;AACjD,aAAO,MAAM;AACX,aAAK,YAAY,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,GAAG,IAAI;AAAA,MAClE;AAAA,IACF,GAAG,CAAC,CAAC;AAEL,UAAM,WAAW,KAAK,YAAY;AAClC,UAAM,EAAE,gBAAgB,IAAI,KAAK,mBAAmB;AAEpD,WACE,qBAAC,mBACG;AAAA,gBAAS,WAAW,KAAK,SAAS,CAAC,MAAM;AAAA,MAEzC,oBAAC,KAAK,aAAa,iCAAlB,EAAkD;AAAA,MAGpD;AAAA,OACH;AAAA,EAEJ;AACF;","names":["data"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["import { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../internal\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { RemoteThreadListHookInstanceManager } from \"./RemoteThreadListHookInstanceManager\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { EMPTY_THREAD_CORE } from \"./EMPTY_THREAD_CORE\";\nimport { OptimisticState } from \"./OptimisticState\";\nimport { FC, Fragment, PropsWithChildren, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { CloudInitializeResponse } from \"./cloud/CloudContext\";\n\ntype RemoteThreadData =\n | {\n readonly threadId: string;\n readonly remoteId?: undefined;\n readonly externalId?: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly threadId: string;\n readonly remoteId: string;\n readonly externalId: string | undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n };\n\ntype THREAD_MAPPING_ID = string & { __brand: \"THREAD_MAPPING_ID\" };\nfunction createThreadMappingId(id: string): THREAD_MAPPING_ID {\n return id as THREAD_MAPPING_ID;\n}\n\ntype RemoteThreadState = {\n readonly isLoading: boolean;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly threadIdMap: Readonly<Record<string, THREAD_MAPPING_ID>>;\n readonly threadData: Readonly<Record<THREAD_MAPPING_ID, RemoteThreadData>>;\n};\n\nconst getThreadData = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n) => {\n const idx = state.threadIdMap[threadIdOrRemoteId];\n if (idx === undefined) return undefined;\n return state.threadData[idx];\n};\n\nconst updateStatusReducer = (\n state: RemoteThreadState,\n threadIdOrRemoteId: string,\n newStatus: \"regular\" | \"archived\" | \"deleted\",\n) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n const { threadId, remoteId, status: lastStatus } = data;\n if (lastStatus === newStatus) return state;\n\n const newState = { ...state };\n\n // lastStatus\n switch (lastStatus) {\n case \"new\":\n newState.newThreadId = undefined;\n break;\n case \"regular\":\n newState.threadIds = newState.threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newStatus\n switch (newStatus) {\n case \"regular\":\n newState.threadIds = [...newState.threadIds, threadId];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [...newState.archivedThreadIds, threadId];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== threadId),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== threadId && key !== remoteId,\n ),\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = newStatus;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newStatus !== \"deleted\") {\n newState.threadData = {\n ...newState.threadData,\n [threadId]: {\n ...data,\n status: newStatus,\n },\n };\n }\n\n return newState;\n};\n\nexport class RemoteThreadListThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _adapter!: RemoteThreadListAdapter;\n private _disposeOldAdapter?: () => void;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private readonly _loadThreadsPromise: Promise<void>;\n\n private _mainThreadId!: string;\n private readonly _state = new OptimisticState<RemoteThreadState>({\n isLoading: false,\n newThreadId: undefined,\n threadIds: [],\n archivedThreadIds: [],\n threadIdMap: {},\n threadData: {},\n });\n\n public getLoadThreadsPromise() {\n return this._loadThreadsPromise;\n }\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n adapter.runtimeHook,\n );\n this.useRenderComponent = create(() => ({\n RenderComponent: adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setAdapter(adapter);\n\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => adapter.list(),\n loading: (state) => {\n return {\n ...state,\n isLoading: true,\n };\n },\n then: (state, l) => {\n const newThreadIds = [];\n const newArchivedThreadIds = [];\n const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;\n const newThreadData = {} as Record<\n THREAD_MAPPING_ID,\n RemoteThreadData\n >;\n\n for (const thread of l.threads) {\n switch (thread.status) {\n case \"regular\":\n newThreadIds.push(thread.remoteId);\n break;\n case \"archived\":\n newArchivedThreadIds.push(thread.remoteId);\n break;\n default: {\n const _exhaustiveCheck: never = thread.status;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n const mappingId = createThreadMappingId(thread.remoteId);\n newThreadIdMap[thread.remoteId] = mappingId;\n newThreadData[mappingId] = {\n threadId: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n };\n }\n\n return {\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: {\n ...state.threadIdMap,\n ...newThreadIdMap,\n },\n threadData: {\n ...state.threadData,\n ...newThreadData,\n },\n };\n },\n })\n .then(() => {});\n\n this.switchToNewThread();\n }\n\n private useRenderComponent;\n\n public __internal_setAdapter(adapter: RemoteThreadListAdapter) {\n if (this._adapter === adapter) return;\n\n this._adapter = adapter;\n this._disposeOldAdapter?.();\n this._disposeOldAdapter = this._adapter.onInitialize(this._onInitialize);\n\n const RenderComponent = adapter.unstable_Provider ?? Fragment;\n if (\n RenderComponent !== this.useRenderComponent.getState().RenderComponent\n ) {\n this.useRenderComponent.setState({ RenderComponent }, true);\n }\n\n this._hookManager.setRuntimeHook(adapter.runtimeHook);\n }\n\n public get threadIds() {\n return this._state.value.threadIds;\n }\n\n public get archivedThreadIds() {\n return this._state.value.archivedThreadIds;\n }\n\n public get newThreadId() {\n return this._state.value.newThreadId;\n }\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);\n if (!result) return EMPTY_THREAD_CORE;\n return result;\n }\n\n public getItemById(threadIdOrRemoteId: string) {\n return getThreadData(this._state.value, threadIdOrRemoteId);\n }\n\n public async switchToThread(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (this._mainThreadId === data.threadId) return;\n\n const task = this._hookManager.startThreadRuntime(data.threadId);\n if (this.mainThreadId !== undefined) {\n await task;\n } else {\n task.then(() => this._notifySubscribers());\n }\n\n if (data.status === \"archived\") await this.unarchive(data.threadId);\n this._mainThreadId = data.threadId;\n\n this._notifySubscribers();\n }\n\n public async switchToNewThread(): Promise<void> {\n // an initialization transaction is in progress, wait for it to settle\n while (\n this._state.baseValue.newThreadId !== undefined &&\n this._state.value.newThreadId === undefined\n ) {\n await this._state.waitForUpdate();\n }\n\n const state = this._state.value;\n let threadId: string | undefined = this._state.value.newThreadId;\n if (threadId === undefined) {\n do {\n threadId = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[threadId]);\n\n const mappingId = createThreadMappingId(threadId);\n this._state.update({\n ...state,\n newThreadId: threadId,\n threadIdMap: {\n ...state.threadIdMap,\n [threadId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n status: \"new\",\n threadId,\n },\n },\n });\n }\n\n return this.switchToThread(threadId);\n }\n\n private _onInitialize = async (task: Promise<CloudInitializeResponse>) => {\n const threadId = this._state.value.newThreadId;\n if (!threadId)\n throw new Error(\n \"ThreadListAdapter called onInitialize before switching to new thread\",\n );\n\n await this._state.optimisticUpdate({\n execute: () => {\n return task;\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(remoteId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [threadId]: {\n ...data,\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._adapter.rename(data.remoteId, newTitle);\n },\n optimistic: (state) => {\n const data = getThreadData(state, threadIdOrRemoteId);\n if (!data) return state;\n\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [data.threadId]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n // if thread is main thread, switch to another thread\n if (threadId === this._mainThreadId) {\n const lastThreadId = this._state.value.threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n }\n }\n\n public async archive(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n return this._adapter.archive(data.remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"archived\");\n },\n });\n }\n\n public unarchive(threadIdOrRemoteId: string): Promise<void> {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"archived\") throw new Error(\"Thread is not archived\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n try {\n return await this._adapter.unarchive(data.remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.threadId);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"regular\");\n },\n });\n }\n\n public async delete(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n return this._state.optimisticUpdate({\n execute: async () => {\n await this._ensureThreadIsNotMain(data.threadId);\n return await this._adapter.delete(data.remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.threadId, \"deleted\");\n },\n });\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_Provider: FC<PropsWithChildren> = ({ children }) => {\n const id = useId();\n useEffect(() => {\n this.useBoundIds.setState((s) => [...s, id], true);\n return () => {\n this.useBoundIds.setState((s) => s.filter((i) => i !== id), true);\n };\n }, []);\n\n const boundIds = this.useBoundIds();\n const { RenderComponent } = this.useRenderComponent();\n\n return (\n <RenderComponent>\n {(boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <this._hookManager.__internal_RenderThreadRuntimes />\n )}\n\n {children}\n </RenderComponent>\n );\n };\n}\n"],"mappings":";AACA,SAAS,kBAAkB;AAE3B,SAAS,2CAA2C;AACpD,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAa,UAA6B,WAAW,aAAa;AAClE,SAAS,cAAc;AA6cjB,SAGI,KAHJ;AAzbN,SAAS,sBAAsB,IAA+B;AAC5D,SAAO;AACT;AAWA,IAAM,gBAAgB,CACpB,OACA,uBACG;AACH,QAAM,MAAM,MAAM,YAAY,kBAAkB;AAChD,MAAI,QAAQ,OAAW,QAAO;AAC9B,SAAO,MAAM,WAAW,GAAG;AAC7B;AAEA,IAAM,sBAAsB,CAC1B,OACA,oBACA,cACG;AACH,QAAM,OAAO,cAAc,OAAO,kBAAkB;AACpD,MAAI,CAAC,KAAM,QAAO;AAElB,QAAM,EAAE,UAAU,UAAU,QAAQ,WAAW,IAAI;AACnD,MAAI,eAAe,UAAW,QAAO;AAErC,QAAM,WAAW,EAAE,GAAG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OAAO,KAAK,YAAY,kBAAkB;AAChD,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,aAAa,KAAK,WAAW;AAC/C,YAAM,IAAI,MAAM,+BAA+B;AAEjD,WAAO,KAAK,OAAO,iBAAiB;AAAA,MAClC,SAAS,YAAY;AACnB,cAAM,KAAK,uBAAuB,KAAK,QAAQ;AAC/C,eAAO,MAAM,KAAK,SAAS,OAAO,KAAK,QAAQ;AAAA,MACjD;AAAA,MACA,YAAY,CAAC,UAAU;AACrB,eAAO,oBAAoB,OAAO,KAAK,UAAU,SAAS;AAAA,MAC5D;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,OAAiB,MAAM,CAAC,CAAC;AAAA,EAExC,sBAA6C,CAAC,EAAE,SAAS,MAAM;AACpE,UAAM,KAAK,MAAM;AACjB,cAAU,MAAM;AACd,WAAK,YAAY,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,IAAI;AACjD,aAAO,MAAM;AACX,aAAK,YAAY,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,GAAG,IAAI;AAAA,MAClE;AAAA,IACF,GAAG,CAAC,CAAC;AAEL,UAAM,WAAW,KAAK,YAAY;AAClC,UAAM,EAAE,gBAAgB,IAAI,KAAK,mBAAmB;AAEpD,WACE,qBAAC,mBACG;AAAA,gBAAS,WAAW,KAAK,SAAS,CAAC,MAAM;AAAA,MAEzC,oBAAC,KAAK,aAAa,iCAAlB,EAAkD;AAAA,MAGpD;AAAA,OACH;AAAA,EAEJ;AACF;","names":["data"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IAEtB,WAAW,EAAE,MAAM,gBAAgB,CAAC;IAEpC,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,yBAAyB,YAAa,sBAAsB,
|
|
1
|
+
{"version":3,"file":"useCloudThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IAEtB,WAAW,EAAE,MAAM,gBAAgB,CAAC;IAEpC,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,yBAAyB,YAAa,sBAAsB,wCA6ExE,CAAC"}
|
|
@@ -89,8 +89,7 @@ var useCloudThreadListRuntime = (adapter) => {
|
|
|
89
89
|
onInitialize: (callback) => {
|
|
90
90
|
return cloudContextValue.subscribe(callback);
|
|
91
91
|
},
|
|
92
|
-
|
|
93
|
-
console.log("RENDER COMPONENT");
|
|
92
|
+
unstable_Provider: ({ children }) => {
|
|
94
93
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CloudContext.CloudContext.Provider, { value: cloudContextValue, children });
|
|
95
94
|
}
|
|
96
95
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantRuntime } from \"@assistant-ui/react\";\nimport { PropsWithChildren, useEffect, useMemo, useRef } from \"react\";\nimport { useRemoteThreadListRuntime } from \"../useRemoteThreadListRuntime\";\nimport { AssistantCloud } from \"./AssistantCloud\";\nimport { CloudContext, CloudInitializeResponse } from \"./CloudContext\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapter = {\n cloud: AssistantCloud;\n\n runtimeHook: () => AssistantRuntime;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nexport const useCloudThreadListRuntime = (adapter: CloudThreadListAdapter) => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const cloudContextValue = useMemo(() => {\n const subscribers = new Set<\n (result: Promise<CloudInitializeResponse>) => void\n >();\n return {\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const task = createTask.then(async (t) => {\n const external_id = t ? t.externalId : undefined;\n const { thread_id } = await adapterRef.current.cloud.threads.create({\n title: \"New Thread\",\n last_message_at: new Date(),\n external_id,\n });\n return { externalId: external_id, remoteId: thread_id };\n });\n for (const subscriber of subscribers) {\n subscriber(task);\n }\n return task;\n },\n subscribe: (\n callback: (result: Promise<CloudInitializeResponse>) => void,\n ) => {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n }, []);\n\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: adapter.runtimeHook,\n list: async () => {\n const { threads } = await adapter.cloud.threads.list();\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n externalId: t.external_id ?? undefined,\n })),\n };\n },\n rename: async (threadId, newTitle) => {\n return adapter.cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return adapter.cloud.threads.delete(threadId);\n },\n onInitialize: (callback) => {\n return cloudContextValue.subscribe(callback);\n },\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantRuntime } from \"@assistant-ui/react\";\nimport { PropsWithChildren, useEffect, useMemo, useRef } from \"react\";\nimport { useRemoteThreadListRuntime } from \"../useRemoteThreadListRuntime\";\nimport { AssistantCloud } from \"./AssistantCloud\";\nimport { CloudContext, CloudInitializeResponse } from \"./CloudContext\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapter = {\n cloud: AssistantCloud;\n\n runtimeHook: () => AssistantRuntime;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nexport const useCloudThreadListRuntime = (adapter: CloudThreadListAdapter) => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const cloudContextValue = useMemo(() => {\n const subscribers = new Set<\n (result: Promise<CloudInitializeResponse>) => void\n >();\n return {\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const task = createTask.then(async (t) => {\n const external_id = t ? t.externalId : undefined;\n const { thread_id } = await adapterRef.current.cloud.threads.create({\n title: \"New Thread\",\n last_message_at: new Date(),\n external_id,\n });\n return { externalId: external_id, remoteId: thread_id };\n });\n for (const subscriber of subscribers) {\n subscriber(task);\n }\n return task;\n },\n subscribe: (\n callback: (result: Promise<CloudInitializeResponse>) => void,\n ) => {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n }, []);\n\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: adapter.runtimeHook,\n list: async () => {\n const { threads } = await adapter.cloud.threads.list();\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n externalId: t.external_id ?? undefined,\n })),\n };\n },\n rename: async (threadId, newTitle) => {\n return adapter.cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return adapter.cloud.threads.delete(threadId);\n },\n onInitialize: (callback) => {\n return cloudContextValue.subscribe(callback);\n },\n unstable_Provider: ({ children }: PropsWithChildren) => {\n return (\n <CloudContext.Provider value={cloudContextValue}>\n {children}\n </CloudContext.Provider>\n );\n },\n });\n\n return runtime;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA8D;AAC9D,wCAA2C;AAE3C,0BAAsD;AAoF9C;AArED,IAAM,4BAA4B,CAAC,YAAoC;AAC5E,QAAM,iBAAa,qBAAO,OAAO;AACjC,8BAAU,MAAM;AACd,eAAW,UAAU;AAAA,EACvB,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,wBAAoB,sBAAQ,MAAM;AACtC,UAAM,cAAc,oBAAI,IAEtB;AACF,WAAO;AAAA,MACL,YAAY,YAAY;AACtB,cAAM,aAAa,WAAW,QAAQ,SAAS,KAAK,QAAQ,QAAQ;AACpE,cAAM,OAAO,WAAW,KAAK,OAAO,MAAM;AACxC,gBAAM,cAAc,IAAI,EAAE,aAAa;AACvC,gBAAM,EAAE,UAAU,IAAI,MAAM,WAAW,QAAQ,MAAM,QAAQ,OAAO;AAAA,YAClE,OAAO;AAAA,YACP,iBAAiB,oBAA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ACA,mBAAmB,CAAC,EAAE,SAAS,MAAyB;AACtD,aACE,4CAAC,iCAAa,UAAb,EAAsB,OAAO,mBAC3B,UACH;AAAA,IAEJ;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -66,8 +66,7 @@ var useCloudThreadListRuntime = (adapter) => {
|
|
|
66
66
|
onInitialize: (callback) => {
|
|
67
67
|
return cloudContextValue.subscribe(callback);
|
|
68
68
|
},
|
|
69
|
-
|
|
70
|
-
console.log("RENDER COMPONENT");
|
|
69
|
+
unstable_Provider: ({ children }) => {
|
|
71
70
|
return /* @__PURE__ */ jsx(CloudContext.Provider, { value: cloudContextValue, children });
|
|
72
71
|
}
|
|
73
72
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantRuntime } from \"@assistant-ui/react\";\nimport { PropsWithChildren, useEffect, useMemo, useRef } from \"react\";\nimport { useRemoteThreadListRuntime } from \"../useRemoteThreadListRuntime\";\nimport { AssistantCloud } from \"./AssistantCloud\";\nimport { CloudContext, CloudInitializeResponse } from \"./CloudContext\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapter = {\n cloud: AssistantCloud;\n\n runtimeHook: () => AssistantRuntime;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nexport const useCloudThreadListRuntime = (adapter: CloudThreadListAdapter) => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const cloudContextValue = useMemo(() => {\n const subscribers = new Set<\n (result: Promise<CloudInitializeResponse>) => void\n >();\n return {\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const task = createTask.then(async (t) => {\n const external_id = t ? t.externalId : undefined;\n const { thread_id } = await adapterRef.current.cloud.threads.create({\n title: \"New Thread\",\n last_message_at: new Date(),\n external_id,\n });\n return { externalId: external_id, remoteId: thread_id };\n });\n for (const subscriber of subscribers) {\n subscriber(task);\n }\n return task;\n },\n subscribe: (\n callback: (result: Promise<CloudInitializeResponse>) => void,\n ) => {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n }, []);\n\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: adapter.runtimeHook,\n list: async () => {\n const { threads } = await adapter.cloud.threads.list();\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n externalId: t.external_id ?? undefined,\n })),\n };\n },\n rename: async (threadId, newTitle) => {\n return adapter.cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return adapter.cloud.threads.delete(threadId);\n },\n onInitialize: (callback) => {\n return cloudContextValue.subscribe(callback);\n },\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantRuntime } from \"@assistant-ui/react\";\nimport { PropsWithChildren, useEffect, useMemo, useRef } from \"react\";\nimport { useRemoteThreadListRuntime } from \"../useRemoteThreadListRuntime\";\nimport { AssistantCloud } from \"./AssistantCloud\";\nimport { CloudContext, CloudInitializeResponse } from \"./CloudContext\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapter = {\n cloud: AssistantCloud;\n\n runtimeHook: () => AssistantRuntime;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nexport const useCloudThreadListRuntime = (adapter: CloudThreadListAdapter) => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const cloudContextValue = useMemo(() => {\n const subscribers = new Set<\n (result: Promise<CloudInitializeResponse>) => void\n >();\n return {\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const task = createTask.then(async (t) => {\n const external_id = t ? t.externalId : undefined;\n const { thread_id } = await adapterRef.current.cloud.threads.create({\n title: \"New Thread\",\n last_message_at: new Date(),\n external_id,\n });\n return { externalId: external_id, remoteId: thread_id };\n });\n for (const subscriber of subscribers) {\n subscriber(task);\n }\n return task;\n },\n subscribe: (\n callback: (result: Promise<CloudInitializeResponse>) => void,\n ) => {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n }, []);\n\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: adapter.runtimeHook,\n list: async () => {\n const { threads } = await adapter.cloud.threads.list();\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n externalId: t.external_id ?? undefined,\n })),\n };\n },\n rename: async (threadId, newTitle) => {\n return adapter.cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return adapter.cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return adapter.cloud.threads.delete(threadId);\n },\n onInitialize: (callback) => {\n return cloudContextValue.subscribe(callback);\n },\n unstable_Provider: ({ children }: PropsWithChildren) => {\n return (\n <CloudContext.Provider value={cloudContextValue}>\n {children}\n </CloudContext.Provider>\n );\n },\n });\n\n return runtime;\n};\n"],"mappings":";;;AAGA,SAA4B,WAAW,SAAS,cAAc;AAC9D,SAAS,kCAAkC;AAE3C,SAAS,oBAA6C;AAoF9C;AArED,IAAM,4BAA4B,CAAC,YAAoC;AAC5E,QAAM,aAAa,OAAO,OAAO;AACjC,YAAU,MAAM;AACd,eAAW,UAAU;AAAA,EACvB,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,oBAA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;AAAA,IACrE;AAAA,IACA,WAAW,OAAO,aAAa;AAC7B,aAAO,QAAQ,MAAM,QAAQ,OAAO,UAAU,EAAE,aAAa,MAAM,CAAC;AAAA,IACtE;AAAA,IACA,QAAQ,OAAO,aAAa;AAC1B,YAAM,QAAQ,SAAS,QAAQ;AAC/B,aAAO,QAAQ,MAAM,QAAQ,OAAO,QAAQ;AAAA,IAC9C;AAAA,IACA,cAAc,CAAC,aAAa;AAC1B,aAAO,kBAAkB,UAAU,QAAQ;AAAA,IAC7C;AAAA,IACA,mBAAmB,CAAC,EAAE,SAAS,MAAyB;AACtD,aACE,oBAAC,aAAa,UAAb,EAAsB,OAAO,mBAC3B,UACH;AAAA,IAEJ;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentType, PropsWithChildren } from "react";
|
|
2
2
|
import { AssistantRuntime } from "../../api";
|
|
3
3
|
import { Unsubscribe } from "../../types";
|
|
4
4
|
import { CloudInitializeResponse } from "./cloud/CloudContext";
|
|
@@ -20,6 +20,6 @@ export type RemoteThreadListAdapter = {
|
|
|
20
20
|
unarchive(remoteId: string): Promise<void>;
|
|
21
21
|
delete(remoteId: string): Promise<void>;
|
|
22
22
|
onInitialize(callback: (task: Promise<CloudInitializeResponse>) => Promise<void>): Unsubscribe;
|
|
23
|
-
|
|
23
|
+
unstable_Provider?: ComponentType<PropsWithChildren>;
|
|
24
24
|
};
|
|
25
25
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/types.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/types.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAA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
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/types.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/types.tsx"],"sourcesContent":["import { ComponentType, PropsWithChildren } from \"react\";\nimport { AssistantRuntime } from \"../../api\";\nimport { Unsubscribe } from \"../../types\";\nimport { CloudInitializeResponse } from \"./cloud/CloudContext\";\n\nexport type RemoteThreadMetadata = {\n readonly status: \"regular\" | \"archived\";\n readonly remoteId: string;\n readonly externalId?: string | undefined;\n readonly title?: string | undefined;\n};\n\nexport type RemoteThreadListResponse = {\n threads: RemoteThreadMetadata[];\n};\n\nexport type RemoteThreadListHook = () => AssistantRuntime;\n\nexport type RemoteThreadListAdapter = {\n runtimeHook: RemoteThreadListHook;\n\n list(): Promise<RemoteThreadListResponse>;\n\n rename(remoteId: string, newTitle: string): Promise<void>;\n archive(remoteId: string): Promise<void>;\n unarchive(remoteId: string): Promise<void>;\n delete(remoteId: string): Promise<void>;\n\n onInitialize(\n callback: (task: Promise<CloudInitializeResponse>) => Promise<void>,\n ): Unsubscribe;\n\n unstable_Provider?: ComponentType<PropsWithChildren>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -33,8 +33,8 @@ var RemoteThreadListRuntimeCore = class extends import_BaseAssistantRuntimeCore.
|
|
|
33
33
|
super();
|
|
34
34
|
this.threadList = new import_RemoteThreadListThreadListRuntimeCore.RemoteThreadListThreadListRuntimeCore(adapter);
|
|
35
35
|
}
|
|
36
|
-
get
|
|
37
|
-
return this.threadList.
|
|
36
|
+
get Provider() {
|
|
37
|
+
return this.threadList.__internal_Provider;
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
var useRemoteThreadListRuntime = (adapter) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["import { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\n\nclass RemoteThreadListRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threadList;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threadList = new RemoteThreadListThreadListRuntimeCore(adapter);\n }\n\n public get
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["import { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\n\nclass RemoteThreadListRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threadList;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threadList = new RemoteThreadListThreadListRuntimeCore(adapter);\n }\n\n public get Provider() {\n return this.threadList.__internal_Provider;\n }\n}\n\nexport const useRemoteThreadListRuntime = (\n adapter: RemoteThreadListAdapter,\n) => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(adapter));\n useEffect(() => {\n runtime.threadList.__internal_setAdapter(adapter);\n }, [runtime, adapter]);\n return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAC7C,sCAAyC;AACzC,mDAAsD;AAEtD,sBAAqC;AAErC,IAAM,8BAAN,cAA0C,yDAAyB;AAAA,EACjD;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,aAAa,IAAI,mFAAsC,OAAO;AAAA,EACrE;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,6BAA6B,CACxC,YACG;AACH,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM,IAAI,4BAA4B,OAAO,CAAC;AACzE,8BAAU,MAAM;AACd,YAAQ,WAAW,sBAAsB,OAAO;AAAA,EAClD,GAAG,CAAC,SAAS,OAAO,CAAC;AACrB,aAAO,sBAAQ,MAAM,qCAAqB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AACtE;","names":[]}
|
|
@@ -9,8 +9,8 @@ var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
|
|
|
9
9
|
super();
|
|
10
10
|
this.threadList = new RemoteThreadListThreadListRuntimeCore(adapter);
|
|
11
11
|
}
|
|
12
|
-
get
|
|
13
|
-
return this.threadList.
|
|
12
|
+
get Provider() {
|
|
13
|
+
return this.threadList.__internal_Provider;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
var useRemoteThreadListRuntime = (adapter) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["import { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\n\nclass RemoteThreadListRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threadList;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threadList = new RemoteThreadListThreadListRuntimeCore(adapter);\n }\n\n public get
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx"],"sourcesContent":["import { useState, useEffect, useMemo } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { RemoteThreadListAdapter } from \"./types\";\nimport { AssistantRuntimeImpl } from \"../../internal\";\n\nclass RemoteThreadListRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threadList;\n\n constructor(adapter: RemoteThreadListAdapter) {\n super();\n this.threadList = new RemoteThreadListThreadListRuntimeCore(adapter);\n }\n\n public get Provider() {\n return this.threadList.__internal_Provider;\n }\n}\n\nexport const useRemoteThreadListRuntime = (\n adapter: RemoteThreadListAdapter,\n) => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(adapter));\n useEffect(() => {\n runtime.threadList.__internal_setAdapter(adapter);\n }, [runtime, adapter]);\n return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);\n};\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,eAAe;AAC7C,SAAS,gCAAgC;AACzC,SAAS,6CAA6C;AAEtD,SAAS,4BAA4B;AAErC,IAAM,8BAAN,cAA0C,yBAAyB;AAAA,EACjD;AAAA,EAEhB,YAAY,SAAkC;AAC5C,UAAM;AACN,SAAK,aAAa,IAAI,sCAAsC,OAAO;AAAA,EACrE;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,6BAA6B,CACxC,YACG;AACH,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM,IAAI,4BAA4B,OAAO,CAAC;AACzE,YAAU,MAAM;AACd,YAAQ,WAAW,sBAAsB,OAAO;AAAA,EAClD,GAAG,CAAC,SAAS,OAAO,CAAC;AACrB,SAAO,QAAQ,MAAM,qBAAqB,OAAO,OAAO,GAAG,CAAC,OAAO,CAAC;AACtE;","names":[]}
|
package/dist/styles/index.css
CHANGED
|
@@ -606,7 +606,7 @@
|
|
|
606
606
|
margin-top: 0.75rem;
|
|
607
607
|
display: flex;
|
|
608
608
|
width: 100%;
|
|
609
|
-
max-width:
|
|
609
|
+
max-width: var(--aui-thread-max-width);
|
|
610
610
|
flex-direction: column;
|
|
611
611
|
align-items: center;
|
|
612
612
|
justify-content: flex-end;
|
|
@@ -658,7 +658,7 @@
|
|
|
658
658
|
.aui-thread-welcome-root {
|
|
659
659
|
display: flex;
|
|
660
660
|
width: 100%;
|
|
661
|
-
max-width:
|
|
661
|
+
max-width: var(--aui-thread-max-width);
|
|
662
662
|
flex-grow: 1;
|
|
663
663
|
flex-direction: column;
|
|
664
664
|
}
|
|
@@ -890,7 +890,7 @@
|
|
|
890
890
|
}
|
|
891
891
|
.aui-user-message-root {
|
|
892
892
|
width: 100%;
|
|
893
|
-
max-width:
|
|
893
|
+
max-width: var(--aui-thread-max-width);
|
|
894
894
|
padding-top: 1rem;
|
|
895
895
|
padding-bottom: 1rem;
|
|
896
896
|
}
|
|
@@ -918,7 +918,7 @@
|
|
|
918
918
|
justify-content: flex-end;
|
|
919
919
|
}
|
|
920
920
|
.aui-user-message-content {
|
|
921
|
-
max-width:
|
|
921
|
+
max-width: calc(var(--aui-thread-max-width) * 0.8);
|
|
922
922
|
overflow-wrap: break-word;
|
|
923
923
|
border-radius: 1.5rem;
|
|
924
924
|
background-color: hsl(var(--aui-muted));
|
|
@@ -944,7 +944,7 @@
|
|
|
944
944
|
margin-bottom: 1rem;
|
|
945
945
|
display: flex;
|
|
946
946
|
width: 100%;
|
|
947
|
-
max-width:
|
|
947
|
+
max-width: var(--aui-thread-max-width);
|
|
948
948
|
flex-direction: column;
|
|
949
949
|
gap: 0.5rem;
|
|
950
950
|
border-radius: 0.75rem;
|
|
@@ -978,7 +978,7 @@
|
|
|
978
978
|
grid-template-rows: auto 1fr;
|
|
979
979
|
position: relative;
|
|
980
980
|
width: 100%;
|
|
981
|
-
max-width:
|
|
981
|
+
max-width: var(--aui-thread-max-width);
|
|
982
982
|
padding-top: 1rem;
|
|
983
983
|
padding-bottom: 1rem;
|
|
984
984
|
}
|
|
@@ -1007,7 +1007,7 @@
|
|
|
1007
1007
|
margin-bottom: 0.375rem;
|
|
1008
1008
|
}
|
|
1009
1009
|
.aui-assistant-message-content {
|
|
1010
|
-
max-width:
|
|
1010
|
+
max-width: calc(var(--aui-thread-max-width) * 0.8);
|
|
1011
1011
|
overflow-wrap: break-word;
|
|
1012
1012
|
line-height: 1.75rem;
|
|
1013
1013
|
color: hsl(var(--aui-foreground));
|
|
@@ -1204,6 +1204,7 @@
|
|
|
1204
1204
|
--aui-input: 240 5.9% 90%;
|
|
1205
1205
|
--aui-ring: 240 10% 3.9%;
|
|
1206
1206
|
--aui-radius: 0.5rem;
|
|
1207
|
+
--aui-thread-max-width: 42rem;
|
|
1207
1208
|
}
|
|
1208
1209
|
.dark {
|
|
1209
1210
|
--aui-background: 0 0% 7%;
|