@assistant-ui/react 0.7.21 → 0.7.23

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 (82) hide show
  1. package/dist/api/ComposerRuntime.d.ts +9 -7
  2. package/dist/api/ComposerRuntime.d.ts.map +1 -1
  3. package/dist/api/ComposerRuntime.js +9 -4
  4. package/dist/api/ComposerRuntime.js.map +1 -1
  5. package/dist/api/ComposerRuntime.mjs +9 -4
  6. package/dist/api/ComposerRuntime.mjs.map +1 -1
  7. package/dist/api/MessageRuntime.d.ts +7 -3
  8. package/dist/api/MessageRuntime.d.ts.map +1 -1
  9. package/dist/api/MessageRuntime.js +5 -2
  10. package/dist/api/MessageRuntime.js.map +1 -1
  11. package/dist/api/MessageRuntime.mjs +5 -2
  12. package/dist/api/MessageRuntime.mjs.map +1 -1
  13. package/dist/api/ThreadRuntime.d.ts +5 -5
  14. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  15. package/dist/api/ThreadRuntime.js +3 -2
  16. package/dist/api/ThreadRuntime.js.map +1 -1
  17. package/dist/api/ThreadRuntime.mjs +3 -2
  18. package/dist/api/ThreadRuntime.mjs.map +1 -1
  19. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +6 -3
  20. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
  21. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +19 -6
  22. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  23. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +19 -6
  24. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
  25. package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +2 -2
  26. package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
  27. package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
  28. package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
  29. package/dist/runtimes/core/ComposerRuntimeCore.d.ts +6 -4
  30. package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
  31. package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
  32. package/dist/runtimes/core/ThreadRuntimeCore.d.ts +6 -1
  33. package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
  34. package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
  35. package/dist/runtimes/edge/EdgeChatAdapter.d.ts +1 -1
  36. package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +1 -1
  37. package/dist/runtimes/edge/EdgeChatAdapter.js +2 -0
  38. package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
  39. package/dist/runtimes/edge/EdgeChatAdapter.mjs +2 -0
  40. package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
  41. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts +13 -0
  42. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts.map +1 -1
  43. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js +3 -0
  44. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js.map +1 -1
  45. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs +3 -0
  46. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs.map +1 -1
  47. package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +2 -2
  48. package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
  49. package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
  50. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -2
  51. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  52. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +2 -2
  53. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  54. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +2 -2
  55. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
  56. package/dist/runtimes/local/ChatModelAdapter.d.ts +2 -1
  57. package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
  58. package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
  59. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +3 -2
  60. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  61. package/dist/runtimes/local/LocalThreadRuntimeCore.js +14 -5
  62. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  63. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +14 -5
  64. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
  65. package/dist/types/AssistantTypes.d.ts +5 -0
  66. package/dist/types/AssistantTypes.d.ts.map +1 -1
  67. package/dist/types/AssistantTypes.js.map +1 -1
  68. package/package.json +1 -1
  69. package/src/api/ComposerRuntime.ts +21 -12
  70. package/src/api/MessageRuntime.ts +11 -3
  71. package/src/api/ThreadRuntime.ts +9 -4
  72. package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +26 -6
  73. package/src/runtimes/core/BaseThreadRuntimeCore.tsx +2 -1
  74. package/src/runtimes/core/ComposerRuntimeCore.tsx +9 -6
  75. package/src/runtimes/core/ThreadRuntimeCore.tsx +7 -1
  76. package/src/runtimes/edge/EdgeChatAdapter.ts +2 -0
  77. package/src/runtimes/edge/EdgeRuntimeRequestOptions.ts +5 -0
  78. package/src/runtimes/external-store/ExternalStoreAdapter.tsx +4 -1
  79. package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +3 -2
  80. package/src/runtimes/local/ChatModelAdapter.tsx +2 -0
  81. package/src/runtimes/local/LocalThreadRuntimeCore.tsx +17 -4
  82. package/src/types/AssistantTypes.ts +7 -0
@@ -53,6 +53,7 @@ export class EdgeChatAdapter implements ChatModelAdapter {
53
53
 
54
54
  async *run({
55
55
  messages,
56
+ runConfig,
56
57
  abortSignal,
57
58
  config,
58
59
  unstable_assistantMessageId,
@@ -75,6 +76,7 @@ export class EdgeChatAdapter implements ChatModelAdapter {
75
76
  }),
76
77
  tools: config.tools ? toLanguageModelTools(config.tools) : [],
77
78
  unstable_assistantMessageId,
79
+ runConfig,
78
80
  ...config.callSettings,
79
81
  ...config.config,
80
82
 
@@ -82,6 +82,11 @@ export const EdgeRuntimeRequestOptionsSchema = z
82
82
  .object({
83
83
  system: z.string().optional(),
84
84
  messages: z.array(CoreMessageSchema).min(1),
85
+ runConfig: z
86
+ .object({
87
+ custom: z.record(z.unknown()).optional(),
88
+ })
89
+ .optional(),
85
90
  tools: z.array(LanguageModelV1FunctionToolSchema).optional(),
86
91
  unstable_assistantMessageId: z.string().optional(),
87
92
  })
@@ -2,6 +2,7 @@ import { AppendMessage, ThreadMessage } from "../../types";
2
2
  import { AttachmentAdapter } from "../attachment";
3
3
  import {
4
4
  AddToolResultOptions,
5
+ StartRunConfig,
5
6
  ThreadSuggestion,
6
7
  } from "../core/ThreadRuntimeCore";
7
8
  import { FeedbackAdapter } from "../feedback/FeedbackAdapter";
@@ -57,7 +58,9 @@ type ExternalStoreAdapterBase<T> = {
57
58
  setMessages?: ((messages: T[]) => void) | undefined;
58
59
  onNew: (message: AppendMessage) => Promise<void>;
59
60
  onEdit?: ((message: AppendMessage) => Promise<void>) | undefined;
60
- onReload?: ((parentId: string | null) => Promise<void>) | undefined;
61
+ onReload?: // TODO: remove parentId in 0.8.0
62
+ | ((parentId: string | null, config: StartRunConfig) => Promise<void>)
63
+ | undefined;
61
64
  onCancel?: (() => Promise<void>) | undefined;
62
65
  onAddToolResult?:
63
66
  | ((options: AddToolResultOptions) => Promise<void> | void)
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  AddToolResultOptions,
3
+ StartRunConfig,
3
4
  ThreadSuggestion,
4
5
  } from "../core/ThreadRuntimeCore";
5
6
 
@@ -192,11 +193,11 @@ export class ExternalStoreThreadRuntimeCore
192
193
  }
193
194
  }
194
195
 
195
- public async startRun(parentId: string | null): Promise<void> {
196
+ public async startRun(config: StartRunConfig): Promise<void> {
196
197
  if (!this._store.onReload)
197
198
  throw new Error("Runtime does not support reloading messages.");
198
199
 
199
- await this._store.onReload(parentId);
200
+ await this._store.onReload(config.parentId, config);
200
201
  }
201
202
 
202
203
  public cancelRun(): void {
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type {
4
4
  MessageStatus,
5
+ RunConfig,
5
6
  ThreadAssistantContentPart,
6
7
  ThreadMessage,
7
8
  ThreadStep,
@@ -24,6 +25,7 @@ export type ChatModelRunResult = {
24
25
 
25
26
  export type ChatModelRunOptions = {
26
27
  messages: ThreadMessage[];
28
+ runConfig: RunConfig;
27
29
  abortSignal: AbortSignal;
28
30
  config: ModelConfig;
29
31
 
@@ -12,8 +12,10 @@ import {
12
12
  AddToolResultOptions,
13
13
  ThreadSuggestion,
14
14
  ThreadRuntimeCore,
15
+ StartRunConfig,
15
16
  } from "../core/ThreadRuntimeCore";
16
17
  import { BaseThreadRuntimeCore } from "../core/BaseThreadRuntimeCore";
18
+ import { RunConfig } from "../../types/AssistantTypes";
17
19
 
18
20
  export class LocalThreadRuntimeCore
19
21
  extends BaseThreadRuntimeCore
@@ -49,6 +51,8 @@ export class LocalThreadRuntimeCore
49
51
 
50
52
  private _options!: LocalRuntimeOptionsBase;
51
53
 
54
+ private _lastRunConfig: RunConfig = {};
55
+
52
56
  public get extras() {
53
57
  return undefined;
54
58
  }
@@ -91,14 +95,20 @@ export class LocalThreadRuntimeCore
91
95
 
92
96
  const startRun = message.startRun ?? message.role === "user";
93
97
  if (startRun) {
94
- await this.startRun(newMessage.id);
98
+ await this.startRun({
99
+ parentId: newMessage.id,
100
+ runConfig: message.runConfig ?? {},
101
+ });
95
102
  } else {
96
103
  this.repository.resetHead(newMessage.id);
97
104
  this._notifySubscribers();
98
105
  }
99
106
  }
100
107
 
101
- public async startRun(parentId: string | null): Promise<void> {
108
+ public async startRun({
109
+ parentId,
110
+ runConfig,
111
+ }: StartRunConfig): Promise<void> {
102
112
  this.ensureInitialized();
103
113
 
104
114
  this.repository.resetHead(parentId);
@@ -117,13 +127,14 @@ export class LocalThreadRuntimeCore
117
127
  this._notifyEventSubscribers("run-start");
118
128
 
119
129
  do {
120
- message = await this.performRoundtrip(parentId, message);
130
+ message = await this.performRoundtrip(parentId, message, runConfig);
121
131
  } while (shouldContinue(message));
122
132
  }
123
133
 
124
134
  private async performRoundtrip(
125
135
  parentId: string | null,
126
136
  message: ThreadAssistantMessage,
137
+ runConfig: RunConfig | undefined,
127
138
  ) {
128
139
  const messages = this.repository.getMessages();
129
140
 
@@ -185,8 +196,10 @@ export class LocalThreadRuntimeCore
185
196
  }
186
197
 
187
198
  try {
199
+ this._lastRunConfig = runConfig ?? {};
188
200
  const promiseOrGenerator = this.adapters.chatModel.run({
189
201
  messages,
202
+ runConfig: this._lastRunConfig,
190
203
  abortSignal: this.abortController.signal,
191
204
  config: this.getModelConfig(),
192
205
  unstable_assistantMessageId: message.id,
@@ -267,7 +280,7 @@ export class LocalThreadRuntimeCore
267
280
  this.repository.addOrUpdateMessage(parentId, message);
268
281
 
269
282
  if (added && shouldContinue(message)) {
270
- this.performRoundtrip(parentId, message);
283
+ this.performRoundtrip(parentId, message, this._lastRunConfig);
271
284
  }
272
285
  }
273
286
  }
@@ -146,10 +146,17 @@ export type ThreadAssistantMessage = MessageCommonProps & {
146
146
  };
147
147
  };
148
148
 
149
+ export type RunConfig = {
150
+ // TODO allow user customization via global type overrides
151
+ readonly custom?: Record<string, unknown>;
152
+ };
153
+
149
154
  export type AppendMessage = CoreMessage & {
150
155
  parentId: string | null;
151
156
  attachments: readonly CompleteAttachment[];
152
157
  startRun?: boolean | undefined;
158
+ /** TODO: make required in 0.8.0 */
159
+ runConfig?: RunConfig | undefined;
153
160
  };
154
161
 
155
162
  type BaseThreadMessage = {