@assistant-ui/react-native 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/context/AssistantContext.d.ts +3 -1
  2. package/dist/context/AssistantContext.d.ts.map +1 -1
  3. package/dist/context/AssistantContext.js +2 -2
  4. package/dist/context/AssistantContext.js.map +1 -1
  5. package/dist/context/index.d.ts +1 -1
  6. package/dist/context/index.d.ts.map +1 -1
  7. package/dist/context/index.js +1 -1
  8. package/dist/context/index.js.map +1 -1
  9. package/dist/context/providers/RuntimeAdapterProvider.d.ts +1 -15
  10. package/dist/context/providers/RuntimeAdapterProvider.d.ts.map +1 -1
  11. package/dist/context/providers/RuntimeAdapterProvider.js +1 -13
  12. package/dist/context/providers/RuntimeAdapterProvider.js.map +1 -1
  13. package/dist/index.d.ts +12 -13
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +12 -14
  16. package/dist/index.js.map +1 -1
  17. package/dist/primitive-hooks/index.d.ts +0 -2
  18. package/dist/primitive-hooks/index.d.ts.map +1 -1
  19. package/dist/primitive-hooks/index.js +0 -2
  20. package/dist/primitive-hooks/index.js.map +1 -1
  21. package/dist/primitive-hooks/useComposerCancel.js +1 -1
  22. package/dist/primitive-hooks/useComposerCancel.js.map +1 -1
  23. package/dist/primitive-hooks/useComposerSend.d.ts.map +1 -1
  24. package/dist/primitive-hooks/useComposerSend.js +1 -1
  25. package/dist/primitive-hooks/useComposerSend.js.map +1 -1
  26. package/dist/primitives/actionBar/index.d.ts +5 -5
  27. package/dist/primitives/actionBar/index.d.ts.map +1 -1
  28. package/dist/primitives/actionBar/index.js +5 -5
  29. package/dist/primitives/actionBar/index.js.map +1 -1
  30. package/dist/primitives/attachment/index.d.ts +4 -4
  31. package/dist/primitives/attachment/index.d.ts.map +1 -1
  32. package/dist/primitives/attachment/index.js +4 -4
  33. package/dist/primitives/attachment/index.js.map +1 -1
  34. package/dist/primitives/branchPicker/index.d.ts +4 -4
  35. package/dist/primitives/branchPicker/index.d.ts.map +1 -1
  36. package/dist/primitives/branchPicker/index.js +4 -4
  37. package/dist/primitives/branchPicker/index.js.map +1 -1
  38. package/dist/primitives/chainOfThought/index.d.ts +3 -3
  39. package/dist/primitives/chainOfThought/index.d.ts.map +1 -1
  40. package/dist/primitives/chainOfThought/index.js +3 -3
  41. package/dist/primitives/chainOfThought/index.js.map +1 -1
  42. package/dist/primitives/composer/ComposerInput.d.ts +10 -2
  43. package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
  44. package/dist/primitives/composer/ComposerInput.js +36 -4
  45. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  46. package/dist/primitives/composer/index.d.ts +7 -10
  47. package/dist/primitives/composer/index.d.ts.map +1 -1
  48. package/dist/primitives/composer/index.js +7 -10
  49. package/dist/primitives/composer/index.js.map +1 -1
  50. package/dist/primitives/message/index.d.ts +5 -5
  51. package/dist/primitives/message/index.d.ts.map +1 -1
  52. package/dist/primitives/message/index.js +5 -5
  53. package/dist/primitives/message/index.js.map +1 -1
  54. package/dist/primitives/suggestion/index.d.ts +3 -3
  55. package/dist/primitives/suggestion/index.d.ts.map +1 -1
  56. package/dist/primitives/suggestion/index.js +3 -3
  57. package/dist/primitives/suggestion/index.js.map +1 -1
  58. package/dist/primitives/thread/ThreadMessages.d.ts +23 -6
  59. package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
  60. package/dist/primitives/thread/ThreadMessages.js +56 -15
  61. package/dist/primitives/thread/ThreadMessages.js.map +1 -1
  62. package/dist/primitives/thread/index.d.ts +7 -7
  63. package/dist/primitives/thread/index.d.ts.map +1 -1
  64. package/dist/primitives/thread/index.js +7 -7
  65. package/dist/primitives/thread/index.js.map +1 -1
  66. package/dist/primitives/threadList/index.d.ts +3 -3
  67. package/dist/primitives/threadList/index.d.ts.map +1 -1
  68. package/dist/primitives/threadList/index.js +3 -3
  69. package/dist/primitives/threadList/index.js.map +1 -1
  70. package/dist/primitives/threadListItem/index.d.ts +6 -6
  71. package/dist/primitives/threadListItem/index.d.ts.map +1 -1
  72. package/dist/primitives/threadListItem/index.js +6 -6
  73. package/dist/primitives/threadListItem/index.js.map +1 -1
  74. package/dist/runtimes/RemoteThreadListHookInstanceManager.d.ts +1 -95
  75. package/dist/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  76. package/dist/runtimes/RemoteThreadListHookInstanceManager.js +1 -109
  77. package/dist/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  78. package/dist/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +1 -112
  79. package/dist/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  80. package/dist/runtimes/RemoteThreadListThreadListRuntimeCore.js +1 -439
  81. package/dist/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  82. package/dist/runtimes/useRemoteThreadListRuntime.d.ts +1 -3
  83. package/dist/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
  84. package/dist/runtimes/useRemoteThreadListRuntime.js +1 -46
  85. package/dist/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  86. package/package.json +6 -6
  87. package/src/context/AssistantContext.tsx +5 -3
  88. package/src/context/index.ts +4 -1
  89. package/src/context/providers/RuntimeAdapterProvider.tsx +5 -42
  90. package/src/index.ts +11 -20
  91. package/src/primitive-hooks/index.ts +0 -2
  92. package/src/primitive-hooks/useComposerCancel.ts +1 -1
  93. package/src/primitive-hooks/useComposerSend.ts +3 -1
  94. package/src/primitives/actionBar/index.ts +16 -7
  95. package/src/primitives/attachment/index.ts +14 -5
  96. package/src/primitives/branchPicker/index.ts +8 -8
  97. package/src/primitives/chainOfThought/index.ts +5 -5
  98. package/src/primitives/composer/ComposerInput.tsx +75 -5
  99. package/src/primitives/composer/index.ts +19 -19
  100. package/src/primitives/message/index.ts +13 -7
  101. package/src/primitives/suggestion/index.ts +6 -6
  102. package/src/primitives/thread/ThreadMessages.tsx +103 -29
  103. package/src/primitives/thread/index.ts +17 -11
  104. package/src/primitives/threadList/index.ts +12 -3
  105. package/src/primitives/threadListItem/index.ts +11 -11
  106. package/src/runtimes/RemoteThreadListHookInstanceManager.tsx +1 -180
  107. package/src/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +1 -538
  108. package/src/runtimes/useRemoteThreadListRuntime.ts +1 -80
@@ -1,538 +1 @@
1
- import type { ThreadListRuntimeCore } from "@assistant-ui/core";
2
- import {
3
- generateId,
4
- BaseSubscribable,
5
- OptimisticState,
6
- EMPTY_THREAD_CORE,
7
- type RemoteThreadData,
8
- type THREAD_MAPPING_ID,
9
- type RemoteThreadState,
10
- createThreadMappingId,
11
- getThreadData,
12
- updateStatusReducer,
13
- type RemoteThreadListOptions,
14
- } from "@assistant-ui/core/internal";
15
- import { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager";
16
- import {
17
- ComponentType,
18
- FC,
19
- Fragment,
20
- PropsWithChildren,
21
- useEffect,
22
- useId,
23
- } from "react";
24
- import { create } from "zustand";
25
- import { AssistantMessageStream } from "assistant-stream";
26
- import type { ModelContextProvider } from "@assistant-ui/core";
27
- import { RuntimeAdapterProvider } from "../context/providers/RuntimeAdapterProvider";
28
-
29
- export class RemoteThreadListThreadListRuntimeCore
30
- extends BaseSubscribable
31
- implements ThreadListRuntimeCore
32
- {
33
- private _options!: RemoteThreadListOptions;
34
- private readonly _hookManager: RemoteThreadListHookInstanceManager;
35
-
36
- private _loadThreadsPromise: Promise<void> | undefined;
37
-
38
- private _mainThreadId!: string;
39
- private readonly _state = new OptimisticState<RemoteThreadState>({
40
- isLoading: false,
41
- newThreadId: undefined,
42
- threadIds: [],
43
- archivedThreadIds: [],
44
- threadIdMap: {},
45
- threadData: {},
46
- });
47
-
48
- public get threadItems() {
49
- return this._state.value.threadData;
50
- }
51
-
52
- public getLoadThreadsPromise() {
53
- if (!this._loadThreadsPromise) {
54
- this._loadThreadsPromise = this._state
55
- .optimisticUpdate({
56
- execute: () => this._options.adapter.list(),
57
- loading: (state) => {
58
- return {
59
- ...state,
60
- isLoading: true,
61
- };
62
- },
63
- then: (state, l) => {
64
- const newThreadIds = [];
65
- const newArchivedThreadIds = [];
66
- const newThreadIdMap = {} as Record<string, THREAD_MAPPING_ID>;
67
- const newThreadData = {} as Record<
68
- THREAD_MAPPING_ID,
69
- RemoteThreadData
70
- >;
71
-
72
- for (const thread of l.threads) {
73
- switch (thread.status) {
74
- case "regular":
75
- newThreadIds.push(thread.remoteId);
76
- break;
77
- case "archived":
78
- newArchivedThreadIds.push(thread.remoteId);
79
- break;
80
- default: {
81
- const _exhaustiveCheck: never = thread.status;
82
- throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
83
- }
84
- }
85
-
86
- const mappingId = createThreadMappingId(thread.remoteId);
87
- newThreadIdMap[thread.remoteId] = mappingId;
88
- newThreadData[mappingId] = {
89
- id: thread.remoteId,
90
- remoteId: thread.remoteId,
91
- externalId: thread.externalId,
92
- status: thread.status,
93
- title: thread.title,
94
- initializeTask: Promise.resolve({
95
- remoteId: thread.remoteId,
96
- externalId: thread.externalId,
97
- }),
98
- };
99
- }
100
-
101
- return {
102
- ...state,
103
- threadIds: newThreadIds,
104
- archivedThreadIds: newArchivedThreadIds,
105
- threadIdMap: {
106
- ...state.threadIdMap,
107
- ...newThreadIdMap,
108
- },
109
- threadData: {
110
- ...state.threadData,
111
- ...newThreadData,
112
- },
113
- };
114
- },
115
- })
116
- .then(() => {});
117
- }
118
-
119
- return this._loadThreadsPromise;
120
- }
121
-
122
- private readonly contextProvider: ModelContextProvider;
123
-
124
- constructor(
125
- options: RemoteThreadListOptions,
126
- contextProvider: ModelContextProvider,
127
- ) {
128
- super();
129
- this.contextProvider = contextProvider;
130
-
131
- this._state.subscribe(() => this._notifySubscribers());
132
- this._hookManager = new RemoteThreadListHookInstanceManager(
133
- options.runtimeHook,
134
- this,
135
- );
136
- this.useProvider = create(() => ({
137
- Provider: (options.adapter.unstable_Provider ??
138
- Fragment) as ComponentType<PropsWithChildren>,
139
- }));
140
- this.__internal_setOptions(options);
141
- this.switchToNewThread();
142
- }
143
-
144
- private useProvider;
145
-
146
- public __internal_setOptions(options: RemoteThreadListOptions) {
147
- if (this._options === options) return;
148
-
149
- this._options = options;
150
-
151
- const Provider = (options.adapter.unstable_Provider ??
152
- Fragment) as ComponentType<PropsWithChildren>;
153
- if (Provider !== this.useProvider.getState().Provider) {
154
- this.useProvider.setState({ Provider }, true);
155
- }
156
-
157
- this._hookManager.setRuntimeHook(options.runtimeHook);
158
- }
159
-
160
- public __internal_load() {
161
- this.getLoadThreadsPromise(); // begin loading on initial bind
162
- }
163
-
164
- public get isLoading() {
165
- return this._state.value.isLoading;
166
- }
167
-
168
- public get threadIds() {
169
- return this._state.value.threadIds;
170
- }
171
-
172
- public get archivedThreadIds() {
173
- return this._state.value.archivedThreadIds;
174
- }
175
-
176
- public get newThreadId() {
177
- return this._state.value.newThreadId;
178
- }
179
-
180
- public get mainThreadId(): string {
181
- return this._mainThreadId;
182
- }
183
-
184
- public getMainThreadRuntimeCore() {
185
- const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);
186
- if (!result) return EMPTY_THREAD_CORE;
187
- return result;
188
- }
189
-
190
- public getThreadRuntimeCore(threadIdOrRemoteId: string) {
191
- const data = this.getItemById(threadIdOrRemoteId);
192
- if (!data) throw new Error("Thread not found");
193
-
194
- const result = this._hookManager.getThreadRuntimeCore(data.id);
195
- if (!result) throw new Error("Thread not found");
196
- return result;
197
- }
198
-
199
- public getItemById(threadIdOrRemoteId: string) {
200
- return getThreadData(this._state.value, threadIdOrRemoteId);
201
- }
202
-
203
- public async switchToThread(threadIdOrRemoteId: string): Promise<void> {
204
- let data = this.getItemById(threadIdOrRemoteId);
205
-
206
- if (!data) {
207
- const remoteMetadata =
208
- await this._options.adapter.fetch(threadIdOrRemoteId);
209
- const state = this._state.value;
210
- const mappingId = createThreadMappingId(remoteMetadata.remoteId);
211
-
212
- const newThreadData = {
213
- ...state.threadData,
214
- [mappingId]: {
215
- id: mappingId,
216
- initializeTask: Promise.resolve({
217
- remoteId: remoteMetadata.remoteId,
218
- externalId: remoteMetadata.externalId,
219
- }),
220
- remoteId: remoteMetadata.remoteId,
221
- externalId: remoteMetadata.externalId,
222
- status: remoteMetadata.status,
223
- title: remoteMetadata.title,
224
- } as RemoteThreadData,
225
- };
226
-
227
- const newThreadIdMap = {
228
- ...state.threadIdMap,
229
- [remoteMetadata.remoteId]: mappingId,
230
- };
231
-
232
- const newThreadIds =
233
- remoteMetadata.status === "regular"
234
- ? [...state.threadIds, remoteMetadata.remoteId]
235
- : state.threadIds;
236
-
237
- const newArchivedThreadIds =
238
- remoteMetadata.status === "archived"
239
- ? [...state.archivedThreadIds, remoteMetadata.remoteId]
240
- : state.archivedThreadIds;
241
-
242
- this._state.update({
243
- ...state,
244
- threadIds: newThreadIds,
245
- archivedThreadIds: newArchivedThreadIds,
246
- threadIdMap: newThreadIdMap,
247
- threadData: newThreadData,
248
- });
249
-
250
- data = this.getItemById(threadIdOrRemoteId);
251
- }
252
-
253
- if (!data) throw new Error("Thread not found");
254
- if (this._mainThreadId === data.id) return;
255
-
256
- const task = this._hookManager.startThreadRuntime(data.id);
257
- if (this.mainThreadId !== undefined) {
258
- await task;
259
- } else {
260
- task.then(() => this._notifySubscribers());
261
- }
262
-
263
- if (data.status === "archived") await this.unarchive(data.id);
264
- this._mainThreadId = data.id;
265
-
266
- this._notifySubscribers();
267
- }
268
-
269
- public async switchToNewThread(): Promise<void> {
270
- // an initialization transaction is in progress, wait for it to settle
271
- while (
272
- this._state.baseValue.newThreadId !== undefined &&
273
- this._state.value.newThreadId === undefined
274
- ) {
275
- await this._state.waitForUpdate();
276
- }
277
-
278
- const state = this._state.value;
279
- let id: string | undefined = this._state.value.newThreadId;
280
- if (id === undefined) {
281
- do {
282
- id = `__LOCALID_${generateId()}`;
283
- } while (state.threadIdMap[id]);
284
-
285
- const mappingId = createThreadMappingId(id);
286
- this._state.update({
287
- ...state,
288
- newThreadId: id,
289
- threadIdMap: {
290
- ...state.threadIdMap,
291
- [id]: mappingId,
292
- },
293
- threadData: {
294
- ...state.threadData,
295
- [mappingId]: {
296
- status: "new",
297
- id,
298
- remoteId: undefined,
299
- externalId: undefined,
300
- title: undefined,
301
- } satisfies RemoteThreadData,
302
- },
303
- });
304
- }
305
-
306
- return this.switchToThread(id);
307
- }
308
-
309
- public initialize = async (threadId: string) => {
310
- if (this._state.value.newThreadId !== threadId) {
311
- const data = this.getItemById(threadId);
312
- if (!data) throw new Error("Thread not found");
313
- if (data.status === "new") throw new Error("Unexpected new state");
314
- return data.initializeTask;
315
- }
316
-
317
- return this._state.optimisticUpdate({
318
- execute: () => {
319
- return this._options.adapter.initialize(threadId);
320
- },
321
- optimistic: (state) => {
322
- return updateStatusReducer(state, threadId, "regular");
323
- },
324
- loading: (state, task) => {
325
- const mappingId = createThreadMappingId(threadId);
326
- return {
327
- ...state,
328
- threadData: {
329
- ...state.threadData,
330
- [mappingId]: {
331
- ...state.threadData[mappingId],
332
- initializeTask: task,
333
- },
334
- },
335
- };
336
- },
337
- then: (state, { remoteId, externalId }) => {
338
- const data = getThreadData(state, threadId);
339
- if (!data) return state;
340
-
341
- const mappingId = createThreadMappingId(threadId);
342
- return {
343
- ...state,
344
- threadIdMap: {
345
- ...state.threadIdMap,
346
- [remoteId]: mappingId,
347
- },
348
- threadData: {
349
- ...state.threadData,
350
- [mappingId]: {
351
- ...data,
352
- initializeTask: Promise.resolve({ remoteId, externalId }),
353
- remoteId,
354
- externalId,
355
- },
356
- },
357
- };
358
- },
359
- });
360
- };
361
-
362
- public generateTitle = async (threadId: string) => {
363
- const data = this.getItemById(threadId);
364
- if (!data) throw new Error("Thread not found");
365
- if (data.status === "new") throw new Error("Thread is not yet initialized");
366
-
367
- const { remoteId } = await data.initializeTask;
368
-
369
- const runtimeCore = this._hookManager.getThreadRuntimeCore(data.id);
370
- if (!runtimeCore) return; // thread is no longer running
371
-
372
- const messages = runtimeCore.messages;
373
- const stream = await this._options.adapter.generateTitle(
374
- remoteId,
375
- messages,
376
- );
377
- const messageStream = AssistantMessageStream.fromAssistantStream(stream);
378
- for await (const result of messageStream) {
379
- const textPart = result.parts.find(
380
- (c: { type: string }) => c.type === "text",
381
- );
382
- const newTitle =
383
- textPart && "text" in textPart ? (textPart.text as string) : undefined;
384
- const state = this._state.baseValue;
385
- const currentData = getThreadData(state, data.id);
386
- if (!currentData) continue;
387
- this._state.update({
388
- ...state,
389
- threadData: {
390
- ...state.threadData,
391
- [data.id]: {
392
- ...currentData,
393
- title: newTitle,
394
- },
395
- },
396
- });
397
- }
398
- };
399
-
400
- public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {
401
- const data = this.getItemById(threadIdOrRemoteId);
402
- if (!data) throw new Error("Thread not found");
403
- if (data.status === "new") throw new Error("Thread is not yet initialized");
404
-
405
- return this._state.optimisticUpdate({
406
- execute: async () => {
407
- const { remoteId } = await data.initializeTask;
408
- return this._options.adapter.rename(remoteId, newTitle);
409
- },
410
- optimistic: (state) => {
411
- const data = getThreadData(state, threadIdOrRemoteId);
412
- if (!data) return state;
413
-
414
- return {
415
- ...state,
416
- threadData: {
417
- ...state.threadData,
418
- [data.id]: {
419
- ...data,
420
- title: newTitle,
421
- },
422
- },
423
- };
424
- },
425
- });
426
- }
427
-
428
- private async _ensureThreadIsNotMain(threadId: string) {
429
- if (threadId === this.newThreadId)
430
- throw new Error("Cannot ensure new thread is not main");
431
-
432
- if (threadId === this._mainThreadId) {
433
- await this.switchToNewThread();
434
- }
435
- }
436
-
437
- public async archive(threadIdOrRemoteId: string) {
438
- const data = this.getItemById(threadIdOrRemoteId);
439
- if (!data) throw new Error("Thread not found");
440
- if (data.status !== "regular")
441
- throw new Error("Thread is not yet initialized or already archived");
442
-
443
- await this._ensureThreadIsNotMain(data.id);
444
-
445
- return this._state.optimisticUpdate({
446
- execute: async () => {
447
- const { remoteId } = await data.initializeTask;
448
- return this._options.adapter.archive(remoteId);
449
- },
450
- optimistic: (state) => {
451
- return updateStatusReducer(state, data.id, "archived");
452
- },
453
- });
454
- }
455
-
456
- public unarchive(threadIdOrRemoteId: string): Promise<void> {
457
- const data = this.getItemById(threadIdOrRemoteId);
458
- if (!data) throw new Error("Thread not found");
459
- if (data.status !== "archived") throw new Error("Thread is not archived");
460
-
461
- return this._state.optimisticUpdate({
462
- execute: async () => {
463
- try {
464
- const { remoteId } = await data.initializeTask;
465
- return await this._options.adapter.unarchive(remoteId);
466
- } catch (error) {
467
- await this._ensureThreadIsNotMain(data.id);
468
- throw error;
469
- }
470
- },
471
- optimistic: (state) => {
472
- return updateStatusReducer(state, data.id, "regular");
473
- },
474
- });
475
- }
476
-
477
- public async delete(threadIdOrRemoteId: string) {
478
- const data = this.getItemById(threadIdOrRemoteId);
479
- if (!data) throw new Error("Thread not found");
480
- if (data.status !== "regular" && data.status !== "archived")
481
- throw new Error("Thread is not yet initialized");
482
-
483
- await this._ensureThreadIsNotMain(data.id);
484
-
485
- return this._state.optimisticUpdate({
486
- execute: async () => {
487
- const { remoteId } = await data.initializeTask;
488
- return await this._options.adapter.delete(remoteId);
489
- },
490
- optimistic: (state) => {
491
- return updateStatusReducer(state, data.id, "deleted");
492
- },
493
- });
494
- }
495
-
496
- public async detach(threadIdOrRemoteId: string): Promise<void> {
497
- const data = this.getItemById(threadIdOrRemoteId);
498
- if (!data) throw new Error("Thread not found");
499
- if (data.status !== "regular" && data.status !== "archived")
500
- throw new Error("Thread is not yet initialized");
501
-
502
- await this._ensureThreadIsNotMain(data.id);
503
- this._hookManager.stopThreadRuntime(data.id);
504
- }
505
-
506
- private useBoundIds = create<string[]>(() => []);
507
-
508
- public __internal_RenderComponent: FC = () => {
509
- const id = useId();
510
- useEffect(() => {
511
- this.useBoundIds.setState((s: string[]) => [...s, id], true);
512
- return () => {
513
- this.useBoundIds.setState(
514
- (s: string[]) => s.filter((i: string) => i !== id),
515
- true,
516
- );
517
- };
518
- }, [id]);
519
-
520
- const boundIds = this.useBoundIds();
521
- const { Provider } = this.useProvider();
522
-
523
- const adapters = {
524
- modelContext: this.contextProvider,
525
- };
526
-
527
- return (
528
- (boundIds.length === 0 || boundIds[0] === id) && (
529
- // only render if the component is the first one mounted
530
- <RuntimeAdapterProvider adapters={adapters}>
531
- <this._hookManager.__internal_RenderThreadRuntimes
532
- provider={Provider}
533
- />
534
- </RuntimeAdapterProvider>
535
- )
536
- );
537
- };
538
- }
1
+ export { RemoteThreadListThreadListRuntimeCore } from "@assistant-ui/core/react";
@@ -1,80 +1 @@
1
- import { useState, useEffect, useMemo, useRef, useCallback } from "react";
2
- import {
3
- BaseAssistantRuntimeCore,
4
- AssistantRuntimeImpl,
5
- type RemoteThreadListOptions,
6
- } from "@assistant-ui/core/internal";
7
- import type {
8
- AssistantRuntimeCore,
9
- AssistantRuntime,
10
- } from "@assistant-ui/core";
11
- import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore";
12
- import { useAui } from "@assistant-ui/store";
13
-
14
- class RemoteThreadListRuntimeCore
15
- extends BaseAssistantRuntimeCore
16
- implements AssistantRuntimeCore
17
- {
18
- public readonly threads;
19
-
20
- constructor(options: RemoteThreadListOptions) {
21
- super();
22
- this.threads = new RemoteThreadListThreadListRuntimeCore(
23
- options,
24
- this._contextProvider,
25
- );
26
- }
27
-
28
- public get RenderComponent() {
29
- return this.threads.__internal_RenderComponent;
30
- }
31
- }
32
-
33
- const useRemoteThreadListRuntimeImpl = (
34
- options: RemoteThreadListOptions,
35
- ): AssistantRuntime => {
36
- const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
37
- useEffect(() => {
38
- runtime.threads.__internal_setOptions(options);
39
- runtime.threads.__internal_load();
40
- }, [runtime, options]);
41
- return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
42
- };
43
-
44
- export const useRemoteThreadListRuntime = (
45
- options: RemoteThreadListOptions,
46
- ): AssistantRuntime => {
47
- const runtimeHookRef = useRef(options.runtimeHook);
48
- runtimeHookRef.current = options.runtimeHook;
49
-
50
- const stableRuntimeHook = useCallback(() => {
51
- return runtimeHookRef.current();
52
- }, []);
53
-
54
- const stableOptions = useMemo<RemoteThreadListOptions>(
55
- () => ({
56
- adapter: options.adapter,
57
- allowNesting: options.allowNesting,
58
- runtimeHook: stableRuntimeHook,
59
- }),
60
- [options.adapter, options.allowNesting, stableRuntimeHook],
61
- );
62
-
63
- const aui = useAui();
64
- const isNested = aui.threadListItem.source !== null;
65
-
66
- if (isNested) {
67
- if (!stableOptions.allowNesting) {
68
- throw new Error(
69
- "useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. " +
70
- "Set allowNesting: true to allow nesting (the inner runtime will become a no-op).",
71
- );
72
- }
73
-
74
- // If allowNesting is true and already inside a thread list context,
75
- // just call the runtimeHook directly (no-op behavior)
76
- return stableRuntimeHook();
77
- }
78
-
79
- return useRemoteThreadListRuntimeImpl(stableOptions);
80
- };
1
+ export { useRemoteThreadListRuntime } from "@assistant-ui/core/react";