@assistant-ui/react 0.11.36 → 0.11.38
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/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +34 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js +9 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.d.ts +2 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.js +3 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/types.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/types.d.ts.map +1 -1
- package/dist/primitives/assistantModal/scope.d.ts +2 -3
- package/dist/primitives/assistantModal/scope.d.ts.map +1 -1
- package/dist/primitives/assistantModal/scope.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/message/MessageParts.d.ts +31 -1
- package/dist/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/primitives/message/MessageParts.js +66 -23
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/reasoning/index.d.ts +2 -0
- package/dist/primitives/reasoning/index.d.ts.map +1 -0
- package/dist/primitives/reasoning/index.js +6 -0
- package/dist/primitives/reasoning/index.js.map +1 -0
- package/dist/primitives/reasoning/useScrollLock.d.ts +29 -0
- package/dist/primitives/reasoning/useScrollLock.d.ts.map +1 -0
- package/dist/primitives/reasoning/useScrollLock.js +50 -0
- package/dist/primitives/reasoning/useScrollLock.js.map +1 -0
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +11 -12
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/tests/setup.js +287 -125
- package/dist/tests/setup.js.map +1 -1
- package/dist/types/MessagePartComponentTypes.d.ts +6 -1
- package/dist/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +49 -2
- package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx +10 -0
- package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.tsx +5 -0
- package/src/legacy-runtime/runtime-cores/remote-thread-list/types.tsx +1 -0
- package/src/primitives/assistantModal/scope.tsx +3 -1
- package/src/primitives/index.ts +1 -0
- package/src/primitives/message/MessageParts.tsx +111 -30
- package/src/primitives/reasoning/index.ts +1 -0
- package/src/primitives/reasoning/useScrollLock.tsx +86 -0
- package/src/primitives/thread/useThreadViewportAutoScroll.tsx +14 -13
- package/src/types/MessagePartComponentTypes.tsx +7 -1
- package/src/types/index.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO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ACX,SAAQ,gBACR,YAAW,qBAAqB;IA8F9B,OAAO,CAAC,QAAQ,CAAC,eAAe;IA5FlC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IAEnE,OAAO,CAAC,mBAAmB,CAA4B;IAEvD,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOpB;IAEH,IAAW,UAAU,0DAEpB;IAEM,qBAAqB;gBAwE1B,OAAO,EAAE,uBAAuB,EACf,eAAe,EAAE,oBAAoB;IAgBxD,OAAO,CAAC,WAAW,CAAC;IAEb,qBAAqB,CAAC,OAAO,EAAE,uBAAuB;IAatD,eAAe;IAItB,IAAW,SAAS,YAEnB;IAED,IAAW,SAAS,sBAEnB;IAED,IAAW,iBAAiB,sBAE3B;IAED,IAAW,WAAW,uBAErB;IAED,IAAW,YAAY,IAAI,MAAM,CAEhC;IAEM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMxB,oBAAoB,CAAC,kBAAkB,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAS/C,WAAW,CAAC,kBAAkB,EAAE,MAAM;IAIhC,cAAc,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EACL,8BAA8B,EAC9B,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;AAGvD,OAAO,EAAE,oBAAoB,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extends BaseSubscribable {
|
|
|
209
209
|
return getThreadData(this._state.value, threadIdOrRemoteId);
|
|
210
210
|
}
|
|
211
211
|
async switchToThread(threadIdOrRemoteId) {
|
|
212
|
-
|
|
212
|
+
let data = this.getItemById(threadIdOrRemoteId);
|
|
213
|
+
if (!data) {
|
|
214
|
+
const remoteMetadata = await this._options.adapter.fetch(threadIdOrRemoteId);
|
|
215
|
+
const state = this._state.value;
|
|
216
|
+
const mappingId = createThreadMappingId(remoteMetadata.remoteId);
|
|
217
|
+
const newThreadData = {
|
|
218
|
+
...state.threadData,
|
|
219
|
+
[mappingId]: {
|
|
220
|
+
id: mappingId,
|
|
221
|
+
initializeTask: Promise.resolve({
|
|
222
|
+
remoteId: remoteMetadata.remoteId,
|
|
223
|
+
externalId: remoteMetadata.externalId
|
|
224
|
+
}),
|
|
225
|
+
remoteId: remoteMetadata.remoteId,
|
|
226
|
+
externalId: remoteMetadata.externalId,
|
|
227
|
+
status: remoteMetadata.status,
|
|
228
|
+
title: remoteMetadata.title
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const newThreadIdMap = {
|
|
232
|
+
...state.threadIdMap,
|
|
233
|
+
[remoteMetadata.remoteId]: mappingId
|
|
234
|
+
};
|
|
235
|
+
const newThreadIds = remoteMetadata.status === "regular" ? [...state.threadIds, remoteMetadata.remoteId] : state.threadIds;
|
|
236
|
+
const newArchivedThreadIds = remoteMetadata.status === "archived" ? [...state.archivedThreadIds, remoteMetadata.remoteId] : state.archivedThreadIds;
|
|
237
|
+
this._state.update({
|
|
238
|
+
...state,
|
|
239
|
+
threadIds: newThreadIds,
|
|
240
|
+
archivedThreadIds: newArchivedThreadIds,
|
|
241
|
+
threadIdMap: newThreadIdMap,
|
|
242
|
+
threadData: newThreadData
|
|
243
|
+
});
|
|
244
|
+
data = this.getItemById(threadIdOrRemoteId);
|
|
245
|
+
}
|
|
213
246
|
if (!data) throw new Error("Thread not found");
|
|
214
247
|
if (this._mainThreadId === data.id) return;
|
|
215
248
|
const task = this._hookManager.startThreadRuntime(data.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["\"use client\";\n\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../../internal\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListOptions,\n} 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, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { AssistantMessageStream } from \"assistant-stream\";\nimport { ModelContextProvider } from \"../../../model-context\";\nimport { RuntimeAdapterProvider } from \"../adapters/RuntimeAdapterProvider\";\n\ntype RemoteThreadData =\n | {\n readonly id: string;\n readonly remoteId: undefined;\n readonly externalId: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly id: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId: undefined;\n readonly externalId: undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n }\n | {\n readonly id: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\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 { id, 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 !== id);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== id,\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 = [id, ...newState.threadIds];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [id, ...newState.archivedThreadIds];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== id),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== id && 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 [id]: {\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 _options!: RemoteThreadListOptions;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private _loadThreadsPromise: Promise<void> | undefined;\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 get threadData() {\n return this._state.value.threadData;\n }\n\n public getLoadThreadsPromise() {\n // TODO this needs to be cached in case this promise is loaded during suspense\n if (!this._loadThreadsPromise) {\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => this._options.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 id: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n initializeTask: Promise.resolve({\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n }),\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\n return this._loadThreadsPromise;\n }\n\n constructor(\n options: RemoteThreadListOptions,\n private readonly contextProvider: ModelContextProvider,\n ) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n options.runtimeHook,\n );\n this.useProvider = create(() => ({\n Provider: options.adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setOptions(options);\n\n this.switchToNewThread();\n }\n\n private useProvider;\n\n public __internal_setOptions(options: RemoteThreadListOptions) {\n if (this._options === options) return;\n\n this._options = options;\n\n const Provider = options.adapter.unstable_Provider ?? Fragment;\n if (Provider !== this.useProvider.getState().Provider) {\n this.useProvider.setState({ Provider }, true);\n }\n\n this._hookManager.setRuntimeHook(options.runtimeHook);\n }\n\n public __internal_load() {\n this.getLoadThreadsPromise(); // begin loading on initial bind\n }\n\n public get isLoading() {\n return this._state.value.isLoading;\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 getThreadRuntimeCore(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n const result = this._hookManager.getThreadRuntimeCore(data.id);\n if (!result) throw new Error(\"Thread not found\");\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.id) return;\n\n const task = this._hookManager.startThreadRuntime(data.id);\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.id);\n this._mainThreadId = data.id;\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 id: string | undefined = this._state.value.newThreadId;\n if (id === undefined) {\n do {\n id = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[id]);\n\n const mappingId = createThreadMappingId(id);\n this._state.update({\n ...state,\n newThreadId: id,\n threadIdMap: {\n ...state.threadIdMap,\n [id]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n status: \"new\",\n id,\n remoteId: undefined,\n externalId: undefined,\n title: undefined,\n } satisfies RemoteThreadData,\n },\n });\n }\n\n return this.switchToThread(id);\n }\n\n public initialize = async (threadId: string) => {\n if (this._state.value.newThreadId !== threadId) {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Unexpected new state\");\n return data.initializeTask;\n }\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._options.adapter.initialize(threadId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n loading: (state, task) => {\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...state.threadData[mappingId],\n initializeTask: task,\n },\n },\n };\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...data,\n initializeTask: Promise.resolve({ remoteId, externalId }),\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n public generateTitle = async (threadId: string) => {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n const { remoteId } = await data.initializeTask;\n\n const runtimeCore = this._hookManager.getThreadRuntimeCore(data.id);\n if (!runtimeCore) return; // thread is no longer running\n\n const messages = runtimeCore.messages;\n const stream = await this._options.adapter.generateTitle(\n remoteId,\n messages,\n );\n const messageStream = AssistantMessageStream.fromAssistantStream(stream);\n for await (const result of messageStream) {\n const newTitle = result.parts.filter((c) => c.type === \"text\")[0]?.text;\n const state = this._state.baseValue;\n this._state.update({\n ...state,\n threadData: {\n ...state.threadData,\n [data.id]: {\n ...data,\n title: newTitle,\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: async () => {\n const { remoteId } = await data.initializeTask;\n return this._options.adapter.rename(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.id]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n if (threadId === this.newThreadId)\n throw new Error(\"Cannot ensure new thread is not main\");\n\n if (threadId === this._mainThreadId) {\n await this.switchToNewThread();\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.id);\n const { remoteId } = await data.initializeTask;\n return this._options.adapter.archive(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.id, \"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 const { remoteId } = await data.initializeTask;\n return await this._options.adapter.unarchive(remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.id);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.id, \"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.id);\n const { remoteId } = await data.initializeTask;\n return await this._options.adapter.delete(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.id, \"deleted\");\n },\n });\n }\n\n public async detach(threadIdOrRemoteId: string): Promise<void> {\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 await this._ensureThreadIsNotMain(data.id);\n this._hookManager.stopThreadRuntime(data.id);\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC = () => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const id = useId();\n // eslint-disable-next-line react-hooks/rules-of-hooks\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 }, [id]);\n\n const boundIds = this.useBoundIds();\n const { Provider } = this.useProvider();\n\n const adapters = {\n modelContext: this.contextProvider,\n };\n\n return (\n (boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <RuntimeAdapterProvider adapters={adapters}>\n <this._hookManager.__internal_RenderThreadRuntimes\n provider={Provider}\n />\n </RuntimeAdapterProvider>\n )\n );\n };\n}\n"],"mappings":";;;AAGA,SAAS,kBAAkB;AAK3B,SAAS,2CAA2C;AACpD,SAAS,wBA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,YACG,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM;AAAA,IAExC,oBAAC,0BAAuB,UACtB;AAAA,MAAC,KAAK,aAAa;AAAA,MAAlB;AAAA,QACC,UAAU;AAAA;AAAA,IACZ,GACF;AAAA,EAGN;AACF;","names":["data"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx"],"sourcesContent":["\"use client\";\n\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { generateId } from \"../../../internal\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListOptions,\n} 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, useEffect, useId } from \"react\";\nimport { create } from \"zustand\";\nimport { AssistantMessageStream } from \"assistant-stream\";\nimport { ModelContextProvider } from \"../../../model-context\";\nimport { RuntimeAdapterProvider } from \"../adapters/RuntimeAdapterProvider\";\n\ntype RemoteThreadData =\n | {\n readonly id: string;\n readonly remoteId: undefined;\n readonly externalId: undefined;\n readonly status: \"new\";\n readonly title: undefined;\n }\n | {\n readonly id: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\n readonly remoteId: undefined;\n readonly externalId: undefined;\n readonly status: \"regular\" | \"archived\";\n readonly title?: string | undefined;\n }\n | {\n readonly id: string;\n readonly initializeTask: Promise<RemoteThreadInitializeResponse>;\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 { id, 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 !== id);\n break;\n case \"archived\":\n newState.archivedThreadIds = newState.archivedThreadIds.filter(\n (t) => t !== id,\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 = [id, ...newState.threadIds];\n break;\n\n case \"archived\":\n newState.archivedThreadIds = [id, ...newState.archivedThreadIds];\n break;\n\n case \"deleted\":\n newState.threadData = Object.fromEntries(\n Object.entries(newState.threadData).filter(([key]) => key !== id),\n );\n newState.threadIdMap = Object.fromEntries(\n Object.entries(newState.threadIdMap).filter(\n ([key]) => key !== id && 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 [id]: {\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 _options!: RemoteThreadListOptions;\n private readonly _hookManager: RemoteThreadListHookInstanceManager;\n\n private _loadThreadsPromise: Promise<void> | undefined;\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 get threadData() {\n return this._state.value.threadData;\n }\n\n public getLoadThreadsPromise() {\n // TODO this needs to be cached in case this promise is loaded during suspense\n if (!this._loadThreadsPromise) {\n this._loadThreadsPromise = this._state\n .optimisticUpdate({\n execute: () => this._options.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 id: thread.remoteId,\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n initializeTask: Promise.resolve({\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n }),\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\n return this._loadThreadsPromise;\n }\n\n constructor(\n options: RemoteThreadListOptions,\n private readonly contextProvider: ModelContextProvider,\n ) {\n super();\n\n this._state.subscribe(() => this._notifySubscribers());\n this._hookManager = new RemoteThreadListHookInstanceManager(\n options.runtimeHook,\n );\n this.useProvider = create(() => ({\n Provider: options.adapter.unstable_Provider ?? Fragment,\n }));\n this.__internal_setOptions(options);\n\n this.switchToNewThread();\n }\n\n private useProvider;\n\n public __internal_setOptions(options: RemoteThreadListOptions) {\n if (this._options === options) return;\n\n this._options = options;\n\n const Provider = options.adapter.unstable_Provider ?? Fragment;\n if (Provider !== this.useProvider.getState().Provider) {\n this.useProvider.setState({ Provider }, true);\n }\n\n this._hookManager.setRuntimeHook(options.runtimeHook);\n }\n\n public __internal_load() {\n this.getLoadThreadsPromise(); // begin loading on initial bind\n }\n\n public get isLoading() {\n return this._state.value.isLoading;\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 getThreadRuntimeCore(threadIdOrRemoteId: string) {\n const data = this.getItemById(threadIdOrRemoteId);\n if (!data) throw new Error(\"Thread not found\");\n\n const result = this._hookManager.getThreadRuntimeCore(data.id);\n if (!result) throw new Error(\"Thread not found\");\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 let data = this.getItemById(threadIdOrRemoteId);\n\n if (!data) {\n const remoteMetadata =\n await this._options.adapter.fetch(threadIdOrRemoteId);\n const state = this._state.value;\n const mappingId = createThreadMappingId(remoteMetadata.remoteId);\n\n const newThreadData = {\n ...state.threadData,\n [mappingId]: {\n id: mappingId,\n initializeTask: Promise.resolve({\n remoteId: remoteMetadata.remoteId,\n externalId: remoteMetadata.externalId,\n }),\n remoteId: remoteMetadata.remoteId,\n externalId: remoteMetadata.externalId,\n status: remoteMetadata.status,\n title: remoteMetadata.title,\n } as RemoteThreadData,\n };\n\n const newThreadIdMap = {\n ...state.threadIdMap,\n [remoteMetadata.remoteId]: mappingId,\n };\n\n const newThreadIds =\n remoteMetadata.status === \"regular\"\n ? [...state.threadIds, remoteMetadata.remoteId]\n : state.threadIds;\n\n const newArchivedThreadIds =\n remoteMetadata.status === \"archived\"\n ? [...state.archivedThreadIds, remoteMetadata.remoteId]\n : state.archivedThreadIds;\n\n this._state.update({\n ...state,\n threadIds: newThreadIds,\n archivedThreadIds: newArchivedThreadIds,\n threadIdMap: newThreadIdMap,\n threadData: newThreadData,\n });\n\n data = this.getItemById(threadIdOrRemoteId);\n }\n\n if (!data) throw new Error(\"Thread not found\");\n if (this._mainThreadId === data.id) return;\n\n const task = this._hookManager.startThreadRuntime(data.id);\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.id);\n this._mainThreadId = data.id;\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 id: string | undefined = this._state.value.newThreadId;\n if (id === undefined) {\n do {\n id = `__LOCALID_${generateId()}`;\n } while (state.threadIdMap[id]);\n\n const mappingId = createThreadMappingId(id);\n this._state.update({\n ...state,\n newThreadId: id,\n threadIdMap: {\n ...state.threadIdMap,\n [id]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n status: \"new\",\n id,\n remoteId: undefined,\n externalId: undefined,\n title: undefined,\n } satisfies RemoteThreadData,\n },\n });\n }\n\n return this.switchToThread(id);\n }\n\n public initialize = async (threadId: string) => {\n if (this._state.value.newThreadId !== threadId) {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Unexpected new state\");\n return data.initializeTask;\n }\n\n return this._state.optimisticUpdate({\n execute: () => {\n return this._options.adapter.initialize(threadId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, threadId, \"regular\");\n },\n loading: (state, task) => {\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...state.threadData[mappingId],\n initializeTask: task,\n },\n },\n };\n },\n then: (state, { remoteId, externalId }) => {\n const data = getThreadData(state, threadId);\n if (!data) return state;\n\n const mappingId = createThreadMappingId(threadId);\n return {\n ...state,\n threadIdMap: {\n ...state.threadIdMap,\n [remoteId]: mappingId,\n },\n threadData: {\n ...state.threadData,\n [mappingId]: {\n ...data,\n initializeTask: Promise.resolve({ remoteId, externalId }),\n remoteId,\n externalId,\n },\n },\n };\n },\n });\n };\n\n public generateTitle = async (threadId: string) => {\n const data = this.getItemById(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.status === \"new\") throw new Error(\"Thread is not yet initialized\");\n\n const { remoteId } = await data.initializeTask;\n\n const runtimeCore = this._hookManager.getThreadRuntimeCore(data.id);\n if (!runtimeCore) return; // thread is no longer running\n\n const messages = runtimeCore.messages;\n const stream = await this._options.adapter.generateTitle(\n remoteId,\n messages,\n );\n const messageStream = AssistantMessageStream.fromAssistantStream(stream);\n for await (const result of messageStream) {\n const newTitle = result.parts.filter((c) => c.type === \"text\")[0]?.text;\n const state = this._state.baseValue;\n this._state.update({\n ...state,\n threadData: {\n ...state.threadData,\n [data.id]: {\n ...data,\n title: newTitle,\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: async () => {\n const { remoteId } = await data.initializeTask;\n return this._options.adapter.rename(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.id]: {\n ...data,\n title: newTitle,\n },\n },\n };\n },\n });\n }\n\n private async _ensureThreadIsNotMain(threadId: string) {\n if (threadId === this.newThreadId)\n throw new Error(\"Cannot ensure new thread is not main\");\n\n if (threadId === this._mainThreadId) {\n await this.switchToNewThread();\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.id);\n const { remoteId } = await data.initializeTask;\n return this._options.adapter.archive(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.id, \"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 const { remoteId } = await data.initializeTask;\n return await this._options.adapter.unarchive(remoteId);\n } catch (error) {\n await this._ensureThreadIsNotMain(data.id);\n throw error;\n }\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.id, \"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.id);\n const { remoteId } = await data.initializeTask;\n return await this._options.adapter.delete(remoteId);\n },\n optimistic: (state) => {\n return updateStatusReducer(state, data.id, \"deleted\");\n },\n });\n }\n\n public async detach(threadIdOrRemoteId: string): Promise<void> {\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 await this._ensureThreadIsNotMain(data.id);\n this._hookManager.stopThreadRuntime(data.id);\n }\n\n private useBoundIds = create<string[]>(() => []);\n\n public __internal_RenderComponent: FC = () => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const id = useId();\n // eslint-disable-next-line react-hooks/rules-of-hooks\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 }, [id]);\n\n const boundIds = this.useBoundIds();\n const { Provider } = this.useProvider();\n\n const adapters = {\n modelContext: this.contextProvider,\n };\n\n return (\n (boundIds.length === 0 || boundIds[0] === id) && (\n // only render if the component is the first one mounted\n <RuntimeAdapterProvider adapters={adapters}>\n <this._hookManager.__internal_RenderThreadRuntimes\n provider={Provider}\n />\n </RuntimeAdapterProvider>\n )\n );\n };\n}\n"],"mappings":";;;AAGA,SAAS,kBAAkB;AAK3B,SAAS,2CAA2C;AACpD,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAa,UAAU,WAAW,aAAa;AAC/C,SAAS,cAAc;AACvB,SAAS,8BAA8B;AAEvC,SAAS,8BAA8B;AAomB7B;AAxkBV,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,k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AAa,kBAAkB,KAAK,EAAE;AAAA,EAC7C;AAAA,EAEQ,cAAc,OAAiB,MAAM,CAAC,CAAC;AAAA,EAExC,6BAAiC,MAAM;AAE5C,UAAM,KAAK,MAAM;AAEjB,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,EAAE,CAAC;AAEP,UAAM,WAAW,KAAK,YAAY;AAClC,UAAM,EAAE,SAAS,IAAI,KAAK,YAAY;AAEtC,UAAM,WAAW;AAAA,MACf,cAAc,KAAK;AAAA,IACrB;AAEA,YACG,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM;AAAA,IAExC,oBAAC,0BAAuB,UACtB;AAAA,MAAC,KAAK,aAAa;AAAA,MAAlB;AAAA,QACC,UAAU;AAAA;AAAA,IACZ,GACF;AAAA,EAGN;AACF;","names":["data"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAMnD,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAEnC,MAAM,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC;IACjD,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CAC5D,CAAC;AASF,eAAO,MAAM,yBAAyB,GACpC,SAAS,6BAA6B,KACrC,
|
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAMnD,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAEnC,MAAM,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC;IACjD,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CAC5D,CAAC;AASF,eAAO,MAAM,yBAAyB,GACpC,SAAS,6BAA6B,KACrC,uBAkGF,CAAC"}
|
|
@@ -88,6 +88,15 @@ var useCloudThreadListAdapter = (adapter) => {
|
|
|
88
88
|
// TODO serialize these to a more efficient format
|
|
89
89
|
});
|
|
90
90
|
},
|
|
91
|
+
fetch: async (threadId) => {
|
|
92
|
+
const thread = await cloud.threads.get(threadId);
|
|
93
|
+
return {
|
|
94
|
+
status: thread.is_archived ? "archived" : "regular",
|
|
95
|
+
remoteId: thread.id,
|
|
96
|
+
title: thread.title,
|
|
97
|
+
externalId: thread.external_id ?? void 0
|
|
98
|
+
};
|
|
99
|
+
},
|
|
91
100
|
unstable_Provider
|
|
92
101
|
};
|
|
93
102
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { RemoteThreadListAdapter } from \"../types\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"../../../cloud/AssistantCloudThreadHistoryAdapter\";\nimport { RuntimeAdapterProvider } from \"../../adapters/RuntimeAdapterProvider\";\nimport { InMemoryThreadListAdapter } from \"./in-memory\";\nimport { CloudFileAttachmentAdapter } from \"../../adapters\";\n\ntype ThreadData = {\n externalId: string | undefined;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?: (() => Promise<ThreadData>) | undefined;\n delete?: ((threadId: string) => Promise<void>) | undefined;\n};\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.[\"NEXT_PUBLIC_ASSISTANT_BASE_URL\"];\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const cloudInstance = adapterRef.current.cloud ?? autoCloud!;\n const attachments = useMemo(\n () => new CloudFileAttachmentAdapter(cloudInstance),\n [cloudInstance],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n if (!cloud) return new InMemoryThreadListAdapter();\n\n return {\n list: async () => {\n const { threads } = await 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\n initialize: async () => {\n const createTask = adapter.create?.() ?? Promise.resolve();\n const t = await createTask;\n const external_id = t ? t.externalId : undefined;\n const { thread_id: remoteId } = await cloud.threads.create({\n last_message_at: new Date(),\n external_id,\n });\n\n return { externalId: external_id, remoteId: remoteId };\n },\n\n rename: async (threadId, newTitle) => {\n return cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return cloud.threads.delete(threadId);\n },\n\n generateTitle: async (threadId, messages) => {\n return cloud.runs.stream({\n thread_id: threadId,\n assistant_id: \"system/thread_title\",\n messages: messages, // TODO serialize these to a more efficient format\n });\n },\n\n unstable_Provider,\n };\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,SAAS,6CAA6C;AACtD,SAAS,8BAA8B;AACvC,SAAS,iCAAiC;AAC1C,SAAS,kCAAkC;AAkDnC;AArCR,IAAM,UACJ,OAAO,YAAY,eACnB,SAAS,MAAM,gCAAgC;AACjD,IAAM,YAAY,UACd,IAAI,eAAe,EAAE,SAAS,WAAW,KAAK,CAAC,IAC/C;AAEG,IAAM,4BAA4B,CACvC,YAC4B;AAC5B,QAAM,aAAa,OAAO,OAAO;AACjC,YAAU,MAAM;AACd,eAAW,UAAU;AAAA,EACvB,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,oBAAoB;AAAA,IACxB,SAAS,SAAS,EAAE,SAAS,GAAG;AAC9B,YAAM,UAAU,sCAAsC;AAAA,QACpD,IAAI,UAAU;AACZ,iBAAO,WAAW,QAAQ,SAAS;AAAA,QACrC;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AAA,IAC7D;AAAA,IACA,WAAW,OAAO,aAAa;AAC7B,aAAO,MAAM,QAAQ,OAAO,UAAU,EAAE,aAAa,MAAM,CAAC;AAAA,IAC9D;AAAA,IACA,QAAQ,OAAO,aAAa;AAC1B,YAAM,QAAQ,SAAS,QAAQ;AAC/B,aAAO,MAAM,QAAQ,OAAO,QAAQ;AAAA,IACtC;AAAA,IAEA,eAAe,OAAO,UAAU,aAAa;AAC3C,aAAO,MAAM,KAAK,OAAO;AAAA,QACvB,WAAW;AAAA,QACX,cAAc;AAAA,QACd;AAAA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { RemoteThreadListAdapter } from \"../types\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"../../../cloud/AssistantCloudThreadHistoryAdapter\";\nimport { RuntimeAdapterProvider } from \"../../adapters/RuntimeAdapterProvider\";\nimport { InMemoryThreadListAdapter } from \"./in-memory\";\nimport { CloudFileAttachmentAdapter } from \"../../adapters\";\n\ntype ThreadData = {\n externalId: string | undefined;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?: (() => Promise<ThreadData>) | undefined;\n delete?: ((threadId: string) => Promise<void>) | undefined;\n};\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.[\"NEXT_PUBLIC_ASSISTANT_BASE_URL\"];\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const cloudInstance = adapterRef.current.cloud ?? autoCloud!;\n const attachments = useMemo(\n () => new CloudFileAttachmentAdapter(cloudInstance),\n [cloudInstance],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n if (!cloud) return new InMemoryThreadListAdapter();\n\n return {\n list: async () => {\n const { threads } = await 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\n initialize: async () => {\n const createTask = adapter.create?.() ?? Promise.resolve();\n const t = await createTask;\n const external_id = t ? t.externalId : undefined;\n const { thread_id: remoteId } = await cloud.threads.create({\n last_message_at: new Date(),\n external_id,\n });\n\n return { externalId: external_id, remoteId: remoteId };\n },\n\n rename: async (threadId, newTitle) => {\n return cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return cloud.threads.delete(threadId);\n },\n\n generateTitle: async (threadId, messages) => {\n return cloud.runs.stream({\n thread_id: threadId,\n assistant_id: \"system/thread_title\",\n messages: messages, // TODO serialize these to a more efficient format\n });\n },\n\n fetch: async (threadId: string) => {\n const thread = await cloud.threads.get(threadId);\n return {\n status: thread.is_archived ? \"archived\" : \"regular\",\n remoteId: thread.id,\n title: thread.title,\n externalId: thread.external_id ?? undefined,\n };\n },\n\n unstable_Prov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;AAAA,IAEA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssistantStream } from "assistant-stream";
|
|
2
|
-
import { RemoteThreadInitializeResponse, RemoteThreadListAdapter, RemoteThreadListResponse } from "../types";
|
|
2
|
+
import { RemoteThreadInitializeResponse, RemoteThreadListAdapter, RemoteThreadListResponse, RemoteThreadMetadata } from "../types";
|
|
3
3
|
export declare class InMemoryThreadListAdapter implements RemoteThreadListAdapter {
|
|
4
4
|
list(): Promise<RemoteThreadListResponse>;
|
|
5
5
|
rename(): Promise<void>;
|
|
@@ -8,5 +8,6 @@ export declare class InMemoryThreadListAdapter implements RemoteThreadListAdapte
|
|
|
8
8
|
delete(): Promise<void>;
|
|
9
9
|
initialize(threadId: string): Promise<RemoteThreadInitializeResponse>;
|
|
10
10
|
generateTitle(): Promise<AssistantStream>;
|
|
11
|
+
fetch(_threadId: string): Promise<RemoteThreadMetadata>;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=in-memory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwB,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,8BAA8B,EAC9B,uBAAuB,EACvB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwB,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,8BAA8B,EAC9B,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB,qBAAa,yBAA0B,YAAW,uBAAuB;IACvE,IAAI,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAMzC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAIrE,aAAa,IAAI,OAAO,CAAC,eAAe,CAAC;IAIzC,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAGxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.tsx"],"sourcesContent":["import { AssistantStream, AssistantStreamChunk } from \"assistant-stream\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n RemoteThreadListResponse,\n} from \"../types\";\n\nexport class InMemoryThreadListAdapter implements RemoteThreadListAdapter {\n list(): Promise<RemoteThreadListResponse> {\n return Promise.resolve({\n threads: [],\n });\n }\n\n rename(): Promise<void> {\n return Promise.resolve();\n }\n\n archive(): Promise<void> {\n return Promise.resolve();\n }\n\n unarchive(): Promise<void> {\n return Promise.resolve();\n }\n\n delete(): Promise<void> {\n return Promise.resolve();\n }\n\n initialize(threadId: string): Promise<RemoteThreadInitializeResponse> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n generateTitle(): Promise<AssistantStream> {\n return Promise.resolve(new ReadableStream<AssistantStreamChunk>());\n }\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../../../src/legacy-runtime/runtime-cores/remote-thread-list/adapter/in-memory.tsx"],"sourcesContent":["import { AssistantStream, AssistantStreamChunk } from \"assistant-stream\";\nimport {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n RemoteThreadListResponse,\n RemoteThreadMetadata,\n} from \"../types\";\n\nexport class InMemoryThreadListAdapter implements RemoteThreadListAdapter {\n list(): Promise<RemoteThreadListResponse> {\n return Promise.resolve({\n threads: [],\n });\n }\n\n rename(): Promise<void> {\n return Promise.resolve();\n }\n\n archive(): Promise<void> {\n return Promise.resolve();\n }\n\n unarchive(): Promise<void> {\n return Promise.resolve();\n }\n\n delete(): Promise<void> {\n return Promise.resolve();\n }\n\n initialize(threadId: string): Promise<RemoteThreadInitializeResponse> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n generateTitle(): Promise<AssistantStream> {\n return Promise.resolve(new ReadableStream<AssistantStreamChunk>());\n }\n\n fetch(_threadId: string): Promise<RemoteThreadMetadata> {\n return Promise.reject(new Error(\"Thread not found\"));\n }\n}\n"],"mappings":";AAQO,IAAM,4BAAN,MAAmE;AAAA,EACxE,OAA0C;AACxC,WAAO,QAAQ,QAAQ;AAAA,MACrB,SAAS,CAAC;AAAA,IACZ,CAAC;AAAA,EACH;AAAA,EAEA,SAAwB;AACtB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,UAAyB;AACvB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,YAA2B;AACzB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,SAAwB;AACtB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,WAAW,UAA2D;AACpE,WAAO,QAAQ,QAAQ,EAAE,UAAU,UAAU,YAAY,OAAU,CAAC;AAAA,EACtE;AAAA,EAEA,gBAA0C;AACxC,WAAO,QAAQ,QAAQ,IAAI,eAAqC,CAAC;AAAA,EACnE;AAAA,EAEA,MAAM,WAAkD;AACtD,WAAO,QAAQ,OAAO,IAAI,MAAM,kBAAkB,CAAC;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -23,6 +23,7 @@ export type RemoteThreadListAdapter = {
|
|
|
23
23
|
delete(remoteId: string): Promise<void>;
|
|
24
24
|
initialize(threadId: string): Promise<RemoteThreadInitializeResponse>;
|
|
25
25
|
generateTitle(remoteId: string, unstable_messages: readonly ThreadMessage[]): Promise<AssistantStream>;
|
|
26
|
+
fetch(threadId: string): Promise<RemoteThreadMetadata>;
|
|
26
27
|
unstable_Provider?: ComponentType<PropsWithChildren>;
|
|
27
28
|
};
|
|
28
29
|
export type RemoteThreadListOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/remote-thread-list/types.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,8BAA8B,GAAG;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,oBAAoB,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAE1C,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG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AC,CAAC;IAE1C,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;IACtE,aAAa,CACX,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,SAAS,aAAa,EAAE,GAC1C,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5B,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEvD,iBAAiB,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,gBAAgB,CAAC;IACpC,OAAO,EAAE,uBAAuB,CAAC;CAClC,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
1
2
|
import type { Scope } from "@radix-ui/react-context";
|
|
2
|
-
export declare const usePopoverScope:
|
|
3
|
-
[__scopeProp: string]: Scope;
|
|
4
|
-
};
|
|
3
|
+
export declare const usePopoverScope: ReturnType<typeof PopoverPrimitive.createPopoverScope>;
|
|
5
4
|
export type ScopedProps<P> = P & {
|
|
6
5
|
__scopeAssistantModal?: Scope;
|
|
7
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/primitives/assistantModal/scope.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/primitives/assistantModal/scope.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAErD,eAAO,MAAM,eAAe,EAAE,UAAU,CACtC,OAAO,gBAAgB,CAAC,kBAAkB,CACH,CAAC;AAC1C,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,qBAAqB,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/assistantModal/scope.tsx"],"sourcesContent":["import * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport type { Scope } from \"@radix-ui/react-context\";\n\nexport const usePopoverScope = PopoverPrimitive.createPopoverScope();\nexport type ScopedProps<P> = P & { __scopeAssistantModal?: Scope };\n"],"mappings":";AAAA,YAAY,sBAAsB;AAG3B,IAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/assistantModal/scope.tsx"],"sourcesContent":["import * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport type { Scope } from \"@radix-ui/react-context\";\n\nexport const usePopoverScope: ReturnType<\n typeof PopoverPrimitive.createPopoverScope\n> = PopoverPrimitive.createPopoverScope();\nexport type ScopedProps<P> = P & { __scopeAssistantModal?: Scope };\n"],"mappings":";AAAA,YAAY,sBAAsB;AAG3B,IAAM,kBAEQ,oCAAmB;","names":[]}
|
|
@@ -15,4 +15,5 @@ export { useMessagePartSource } from "./messagePart/useMessagePartSource";
|
|
|
15
15
|
export { useMessagePartFile } from "./messagePart/useMessagePartFile";
|
|
16
16
|
export { useMessagePartImage } from "./messagePart/useMessagePartImage";
|
|
17
17
|
export { useThreadViewportAutoScroll } from "./thread/useThreadViewportAutoScroll";
|
|
18
|
+
export { useScrollLock } from "./reasoning";
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,iBAAiB,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,oBAAoB,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,cAAc,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,gBAAgB,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,eAAe,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,iBAAiB,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,oBAAoB,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,cAAc,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,gBAAgB,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,eAAe,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/primitives/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { useMessagePartSource } from "./messagePart/useMessagePartSource.js";
|
|
|
16
16
|
import { useMessagePartFile } from "./messagePart/useMessagePartFile.js";
|
|
17
17
|
import { useMessagePartImage } from "./messagePart/useMessagePartImage.js";
|
|
18
18
|
import { useThreadViewportAutoScroll } from "./thread/useThreadViewportAutoScroll.js";
|
|
19
|
+
import { useScrollLock } from "./reasoning/index.js";
|
|
19
20
|
export {
|
|
20
21
|
ActionBarPrimitive,
|
|
21
22
|
AssistantModalPrimitive,
|
|
@@ -33,6 +34,7 @@ export {
|
|
|
33
34
|
useMessagePartReasoning,
|
|
34
35
|
useMessagePartSource,
|
|
35
36
|
useMessagePartText,
|
|
37
|
+
useScrollLock,
|
|
36
38
|
useThreadViewportAutoScroll
|
|
37
39
|
};
|
|
38
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/primitives/index.ts"],"sourcesContent":["export * as ActionBarPrimitive from \"./actionBar\";\nexport * as AssistantModalPrimitive from \"./assistantModal\";\nexport * as AttachmentPrimitive from \"./attachment\";\nexport * as BranchPickerPrimitive from \"./branchPicker\";\nexport * as ComposerPrimitive from \"./composer\";\nexport * as MessagePartPrimitive from \"./messagePart\";\nexport * as ErrorPrimitive from \"./error\";\nexport * as MessagePrimitive from \"./message\";\nexport * as ThreadPrimitive from \"./thread\";\nexport * as ThreadListPrimitive from \"./threadList\";\nexport * as ThreadListItemPrimitive from \"./threadListItem\";\n\nexport { useMessagePartText } from \"./messagePart/useMessagePartText\";\nexport { useMessagePartReasoning } from \"./messagePart/useMessagePartReasoning\";\nexport { useMessagePartSource } from \"./messagePart/useMessagePartSource\";\nexport { useMessagePartFile } from \"./messagePart/useMessagePartFile\";\nexport { useMessagePartImage } from \"./messagePart/useMessagePartImage\";\nexport { useThreadViewportAutoScroll } from \"./thread/useThreadViewportAutoScroll\";\n"],"mappings":";AAAA,YAAY,wBAAwB;AACpC,YAAY,6BAA6B;AACzC,YAAY,yBAAyB;AACrC,YAAY,2BAA2B;AACvC,YAAY,uBAAuB;AACnC,YAAY,0BAA0B;AACtC,YAAY,oBAAoB;AAChC,YAAY,sBAAsB;AAClC,YAAY,qBAAqB;AACjC,YAAY,yBAAyB;AACrC,YAAY,6BAA6B;AAEzC,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,mCAAmC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/primitives/index.ts"],"sourcesContent":["export * as ActionBarPrimitive from \"./actionBar\";\nexport * as AssistantModalPrimitive from \"./assistantModal\";\nexport * as AttachmentPrimitive from \"./attachment\";\nexport * as BranchPickerPrimitive from \"./branchPicker\";\nexport * as ComposerPrimitive from \"./composer\";\nexport * as MessagePartPrimitive from \"./messagePart\";\nexport * as ErrorPrimitive from \"./error\";\nexport * as MessagePrimitive from \"./message\";\nexport * as ThreadPrimitive from \"./thread\";\nexport * as ThreadListPrimitive from \"./threadList\";\nexport * as ThreadListItemPrimitive from \"./threadListItem\";\n\nexport { useMessagePartText } from \"./messagePart/useMessagePartText\";\nexport { useMessagePartReasoning } from \"./messagePart/useMessagePartReasoning\";\nexport { useMessagePartSource } from \"./messagePart/useMessagePartSource\";\nexport { useMessagePartFile } from \"./messagePart/useMessagePartFile\";\nexport { useMessagePartImage } from \"./messagePart/useMessagePartImage\";\nexport { useThreadViewportAutoScroll } from \"./thread/useThreadViewportAutoScroll\";\nexport { useScrollLock } from \"./reasoning\";\n"],"mappings":";AAAA,YAAY,wBAAwB;AACpC,YAAY,6BAA6B;AACzC,YAAY,yBAAyB;AACrC,YAAY,2BAA2B;AACvC,YAAY,uBAAuB;AACnC,YAAY,0BAA0B;AACtC,YAAY,oBAAoB;AAChC,YAAY,sBAAsB;AAClC,YAAY,qBAAqB;AACjC,YAAY,yBAAyB;AACrC,YAAY,6BAA6B;AAEzC,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,mCAAmC;AAC5C,SAAS,qBAAqB;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type FC, PropsWithChildren } from "react";
|
|
2
|
-
import type { Unstable_AudioMessagePartComponent, EmptyMessagePartComponent, TextMessagePartComponent, ImageMessagePartComponent, SourceMessagePartComponent, ToolCallMessagePartComponent, ToolCallMessagePartProps, FileMessagePartComponent, ReasoningMessagePartComponent } from "../../types/MessagePartComponentTypes";
|
|
2
|
+
import type { Unstable_AudioMessagePartComponent, EmptyMessagePartComponent, TextMessagePartComponent, ImageMessagePartComponent, SourceMessagePartComponent, ToolCallMessagePartComponent, ToolCallMessagePartProps, FileMessagePartComponent, ReasoningMessagePartComponent, ReasoningGroupComponent } from "../../types/MessagePartComponentTypes";
|
|
3
3
|
export declare namespace MessagePrimitiveParts {
|
|
4
4
|
type Props = {
|
|
5
5
|
/**
|
|
@@ -85,6 +85,36 @@ export declare namespace MessagePrimitiveParts {
|
|
|
85
85
|
startIndex: number;
|
|
86
86
|
endIndex: number;
|
|
87
87
|
}>>;
|
|
88
|
+
/**
|
|
89
|
+
* Component for rendering grouped reasoning parts.
|
|
90
|
+
*
|
|
91
|
+
* When provided, this component will automatically wrap reasoning message parts
|
|
92
|
+
* (one or more consecutive) in a group container. Each reasoning part inside
|
|
93
|
+
* renders its own text independently - no text merging occurs.
|
|
94
|
+
*
|
|
95
|
+
* The component receives:
|
|
96
|
+
* - `startIndex`: The index of the first reasoning part in the group
|
|
97
|
+
* - `endIndex`: The index of the last reasoning part in the group
|
|
98
|
+
* - `children`: The rendered Reasoning components (one per part)
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* // Collapsible reasoning group
|
|
103
|
+
* ReasoningGroup: ({ children }) => (
|
|
104
|
+
* <details className="reasoning-group">
|
|
105
|
+
* <summary>Reasoning</summary>
|
|
106
|
+
* <div className="reasoning-content">
|
|
107
|
+
* {children}
|
|
108
|
+
* </div>
|
|
109
|
+
* </details>
|
|
110
|
+
* )
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param startIndex - Index of the first reasoning part in the group
|
|
114
|
+
* @param endIndex - Index of the last reasoning part in the group
|
|
115
|
+
* @param children - Rendered reasoning part components
|
|
116
|
+
*/
|
|
117
|
+
ReasoningGroup?: ReasoningGroupComponent;
|
|
88
118
|
} | undefined;
|
|
89
119
|
};
|
|
90
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageParts.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageParts.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EAEP,iBAAiB,EAElB,MAAM,OAAO,CAAC;AASf,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,
|
|
1
|
+
{"version":3,"file":"MessageParts.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageParts.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EAEP,iBAAiB,EAElB,MAAM,OAAO,CAAC;AASf,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,uCAAuC,CAAC;AA6F/C,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,KAAK,GAAG;QAClB;;;;;WAKG;QACH,UAAU,CAAC,EACP;YACE,6CAA6C;YAC7C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,mEAAmE;YACnE,SAAS,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;YACtD,6CAA6C;YAC7C,MAAM,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;YAChD,4CAA4C;YAC5C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,2DAA2D;YAC3D,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,4CAA4C;YAC5C,KAAK,CAAC,EACF;gBACE,qDAAqD;gBACrD,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,gDAAgD;gBAChD,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,qDAAqD;gBACrD,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;YAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+CG;YACH,SAAS,CAAC,EAAE,aAAa,CACvB,iBAAiB,CAAC;gBAAE,UAAU,EAAE,MAAM,CAAC;gBAAC,QAAQ,EAAE,MAAM,CAAA;aAAE,CAAC,CAC5D,CAAC;YAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA4BG;YACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;SAC1C,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAoGD,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,qBAAqB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;KACvD,CAAC;CACH;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAAC,2BAA2B,CAAC,KAAK,CAoB3E,CAAC;AAyCJ;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,CAsEjE,CAAC"}
|
|
@@ -16,34 +16,55 @@ import { MessagePartPrimitiveImage } from "../messagePart/MessagePartImage.js";
|
|
|
16
16
|
import { MessagePartPrimitiveInProgress } from "../messagePart/MessagePartInProgress.js";
|
|
17
17
|
import { useShallow } from "zustand/shallow";
|
|
18
18
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
var createGroupState = (groupType) => {
|
|
20
|
+
let start = -1;
|
|
21
|
+
return {
|
|
22
|
+
startGroup: (index) => {
|
|
23
|
+
if (start === -1) {
|
|
24
|
+
start = index;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
endGroup: (endIndex, ranges) => {
|
|
28
|
+
if (start !== -1) {
|
|
29
|
+
ranges.push({
|
|
30
|
+
type: groupType,
|
|
31
|
+
startIndex: start,
|
|
32
|
+
endIndex
|
|
33
|
+
});
|
|
34
|
+
start = -1;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
finalize: (endIndex, ranges) => {
|
|
38
|
+
if (start !== -1) {
|
|
39
|
+
ranges.push({
|
|
40
|
+
type: groupType,
|
|
41
|
+
startIndex: start,
|
|
42
|
+
endIndex
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
19
48
|
var groupMessageParts = (messageTypes) => {
|
|
20
49
|
const ranges = [];
|
|
21
|
-
|
|
50
|
+
const toolGroup = createGroupState("toolGroup");
|
|
51
|
+
const reasoningGroup = createGroupState("reasoningGroup");
|
|
22
52
|
for (let i = 0; i < messageTypes.length; i++) {
|
|
23
53
|
const type = messageTypes[i];
|
|
24
54
|
if (type === "tool-call") {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
55
|
+
reasoningGroup.endGroup(i - 1, ranges);
|
|
56
|
+
toolGroup.startGroup(i);
|
|
57
|
+
} else if (type === "reasoning") {
|
|
58
|
+
toolGroup.endGroup(i - 1, ranges);
|
|
59
|
+
reasoningGroup.startGroup(i);
|
|
28
60
|
} else {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type: "toolGroup",
|
|
32
|
-
startIndex: currentToolGroupStart,
|
|
33
|
-
endIndex: i - 1
|
|
34
|
-
});
|
|
35
|
-
currentToolGroupStart = -1;
|
|
36
|
-
}
|
|
61
|
+
toolGroup.endGroup(i - 1, ranges);
|
|
62
|
+
reasoningGroup.endGroup(i - 1, ranges);
|
|
37
63
|
ranges.push({ type: "single", index: i });
|
|
38
64
|
}
|
|
39
65
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
type: "toolGroup",
|
|
43
|
-
startIndex: currentToolGroupStart,
|
|
44
|
-
endIndex: messageTypes.length - 1
|
|
45
|
-
});
|
|
46
|
-
}
|
|
66
|
+
toolGroup.finalize(messageTypes.length - 1, ranges);
|
|
67
|
+
reasoningGroup.finalize(messageTypes.length - 1, ranges);
|
|
47
68
|
return ranges;
|
|
48
69
|
};
|
|
49
70
|
var useMessagePartsGroups = () => {
|
|
@@ -79,7 +100,8 @@ var defaultComponents = {
|
|
|
79
100
|
Image: () => /* @__PURE__ */ jsx(MessagePartPrimitiveImage, {}),
|
|
80
101
|
File: () => null,
|
|
81
102
|
Unstable_Audio: () => null,
|
|
82
|
-
ToolGroup: ({ children }) => children
|
|
103
|
+
ToolGroup: ({ children }) => children,
|
|
104
|
+
ReasoningGroup: ({ children }) => children
|
|
83
105
|
};
|
|
84
106
|
var MessagePartComponent = ({
|
|
85
107
|
components: {
|
|
@@ -135,7 +157,7 @@ var MessagePrimitivePartByIndex = memo(
|
|
|
135
157
|
({ index, components }) => {
|
|
136
158
|
return /* @__PURE__ */ jsx(PartByIndexProvider, { index, children: /* @__PURE__ */ jsx(MessagePartComponent, { components }) });
|
|
137
159
|
},
|
|
138
|
-
(prev, next) => prev.index === next.index && prev.components?.Text === next.components?.Text && prev.components?.Reasoning === next.components?.Reasoning && prev.components?.Source === next.components?.Source && prev.components?.Image === next.components?.Image && prev.components?.File === next.components?.File && prev.components?.Unstable_Audio === next.components?.Unstable_Audio && prev.components?.tools === next.components?.tools && prev.components?.ToolGroup === next.components?.ToolGroup
|
|
160
|
+
(prev, next) => prev.index === next.index && prev.components?.Text === next.components?.Text && prev.components?.Reasoning === next.components?.Reasoning && prev.components?.Source === next.components?.Source && prev.components?.Image === next.components?.Image && prev.components?.File === next.components?.File && prev.components?.Unstable_Audio === next.components?.Unstable_Audio && prev.components?.tools === next.components?.tools && prev.components?.ToolGroup === next.components?.ToolGroup && prev.components?.ReasoningGroup === next.components?.ReasoningGroup
|
|
139
161
|
);
|
|
140
162
|
MessagePrimitivePartByIndex.displayName = "MessagePrimitive.PartByIndex";
|
|
141
163
|
var EmptyPartFallback = ({ status, component: Component }) => {
|
|
@@ -182,7 +204,7 @@ var MessagePrimitiveParts = ({
|
|
|
182
204
|
},
|
|
183
205
|
range.index
|
|
184
206
|
);
|
|
185
|
-
} else {
|
|
207
|
+
} else if (range.type === "toolGroup") {
|
|
186
208
|
const ToolGroupComponent = components.ToolGroup ?? defaultComponents.ToolGroup;
|
|
187
209
|
return /* @__PURE__ */ jsx(
|
|
188
210
|
ToolGroupComponent,
|
|
@@ -201,7 +223,28 @@ var MessagePrimitiveParts = ({
|
|
|
201
223
|
)
|
|
202
224
|
)
|
|
203
225
|
},
|
|
204
|
-
range.startIndex
|
|
226
|
+
`tool-${range.startIndex}`
|
|
227
|
+
);
|
|
228
|
+
} else {
|
|
229
|
+
const ReasoningGroupComponent = components.ReasoningGroup ?? defaultComponents.ReasoningGroup;
|
|
230
|
+
return /* @__PURE__ */ jsx(
|
|
231
|
+
ReasoningGroupComponent,
|
|
232
|
+
{
|
|
233
|
+
startIndex: range.startIndex,
|
|
234
|
+
endIndex: range.endIndex,
|
|
235
|
+
children: Array.from(
|
|
236
|
+
{ length: range.endIndex - range.startIndex + 1 },
|
|
237
|
+
(_, i) => /* @__PURE__ */ jsx(
|
|
238
|
+
MessagePrimitivePartByIndex,
|
|
239
|
+
{
|
|
240
|
+
index: range.startIndex + i,
|
|
241
|
+
components
|
|
242
|
+
},
|
|
243
|
+
i
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
},
|
|
247
|
+
`reasoning-${range.startIndex}`
|
|
205
248
|
);
|
|
206
249
|
}
|
|
207
250
|
});
|