@assistant-ui/react 0.5.65 → 0.5.67
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{edge-D7ch2oPK.d.mts → edge-BDAlTCC1.d.mts} +2 -2
- package/dist/{edge-D7ch2oPK.d.ts → edge-BDAlTCC1.d.ts} +2 -2
- package/dist/index.d.mts +637 -846
- package/dist/index.d.ts +637 -846
- package/dist/index.js +1720 -1719
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1170 -1169
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -16,10 +16,7 @@ import {
|
|
16
16
|
} from "./chunk-BJPOCE4O.mjs";
|
17
17
|
|
18
18
|
// src/context/providers/AssistantRuntimeProvider.tsx
|
19
|
-
import { memo } from "react";
|
20
|
-
|
21
|
-
// src/context/providers/AssistantProvider.tsx
|
22
|
-
import { useEffect as useEffect2, useInsertionEffect, useRef, useState as useState2 } from "react";
|
19
|
+
import { memo, useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
23
20
|
|
24
21
|
// src/context/react/AssistantContext.ts
|
25
22
|
import { createContext } from "react";
|
@@ -122,8 +119,8 @@ var makeAssistantToolUIsStore = () => create((set) => {
|
|
122
119
|
});
|
123
120
|
});
|
124
121
|
|
125
|
-
// src/context/providers/
|
126
|
-
import { useEffect, useState } from "react";
|
122
|
+
// src/context/providers/ThreadRuntimeProvider.tsx
|
123
|
+
import { useEffect, useMemo, useState } from "react";
|
127
124
|
|
128
125
|
// src/context/react/ThreadContext.ts
|
129
126
|
import { createContext as createContext2 } from "react";
|
@@ -148,7 +145,9 @@ var { useThread, useThreadStore } = createContextStoreHook(
|
|
148
145
|
useThreadContext,
|
149
146
|
"useThread"
|
150
147
|
);
|
151
|
-
var
|
148
|
+
var messages = createContextStoreHook(useThreadContext, "useThreadMessages");
|
149
|
+
var useThreadMessages = messages.useThreadMessages;
|
150
|
+
var useThreadMessagesStore = messages.useThreadMessagesStore;
|
152
151
|
var {
|
153
152
|
useComposer: useThreadComposer,
|
154
153
|
useComposerStore: useThreadComposerStore
|
@@ -158,81 +157,11 @@ var {
|
|
158
157
|
useViewportStore: useThreadViewportStore
|
159
158
|
} = createContextStoreHook(useThreadContext, "useViewport");
|
160
159
|
|
161
|
-
// src/context/stores/ThreadComposer.ts
|
162
|
-
import { create as create2 } from "zustand";
|
163
|
-
var makeThreadComposerStore = (useThreadRuntime2) => {
|
164
|
-
const focusListeners = /* @__PURE__ */ new Set();
|
165
|
-
return create2()((_, get) => {
|
166
|
-
const runtime = useThreadRuntime2.getState();
|
167
|
-
return {
|
168
|
-
type: "thread",
|
169
|
-
get value() {
|
170
|
-
return get().text;
|
171
|
-
},
|
172
|
-
setValue(value) {
|
173
|
-
get().setText(value);
|
174
|
-
},
|
175
|
-
attachmentAccept: runtime.composer.attachmentAccept,
|
176
|
-
attachments: runtime.composer.attachments,
|
177
|
-
addAttachment: (file) => {
|
178
|
-
useThreadRuntime2.getState().composer.addAttachment(file);
|
179
|
-
},
|
180
|
-
removeAttachment: (attachmentId) => {
|
181
|
-
useThreadRuntime2.getState().composer.removeAttachment(attachmentId);
|
182
|
-
},
|
183
|
-
reset: () => {
|
184
|
-
useThreadRuntime2.getState().composer.reset();
|
185
|
-
},
|
186
|
-
text: runtime.composer.text,
|
187
|
-
setText: (text) => {
|
188
|
-
useThreadRuntime2.getState().composer.setText(text);
|
189
|
-
},
|
190
|
-
canCancel: runtime.capabilities.cancel,
|
191
|
-
isEditing: true,
|
192
|
-
isEmpty: runtime.composer.isEmpty,
|
193
|
-
send: () => {
|
194
|
-
const runtime2 = useThreadRuntime2.getState();
|
195
|
-
runtime2.composer.send();
|
196
|
-
},
|
197
|
-
cancel: () => {
|
198
|
-
useThreadRuntime2.getState().cancelRun();
|
199
|
-
},
|
200
|
-
focus: () => {
|
201
|
-
for (const listener of focusListeners) {
|
202
|
-
listener();
|
203
|
-
}
|
204
|
-
},
|
205
|
-
onFocus: (listener) => {
|
206
|
-
focusListeners.add(listener);
|
207
|
-
return () => {
|
208
|
-
focusListeners.delete(listener);
|
209
|
-
};
|
210
|
-
}
|
211
|
-
};
|
212
|
-
});
|
213
|
-
};
|
214
|
-
|
215
|
-
// src/context/stores/Thread.ts
|
216
|
-
import { create as create3 } from "zustand";
|
217
|
-
var getThreadStateFromRuntime = (runtime) => {
|
218
|
-
const lastMessage = runtime.messages.at(-1);
|
219
|
-
return Object.freeze({
|
220
|
-
threadId: runtime.threadId,
|
221
|
-
capabilities: runtime.capabilities,
|
222
|
-
isDisabled: runtime.isDisabled,
|
223
|
-
isRunning: lastMessage?.role !== "assistant" ? false : lastMessage.status.type === "running"
|
224
|
-
});
|
225
|
-
};
|
226
|
-
var makeThreadStore = (runtimeRef) => {
|
227
|
-
const runtime = runtimeRef.getState();
|
228
|
-
return create3(() => getThreadStateFromRuntime(runtime));
|
229
|
-
};
|
230
|
-
|
231
160
|
// src/context/stores/ThreadViewport.tsx
|
232
|
-
import { create as
|
161
|
+
import { create as create2 } from "zustand";
|
233
162
|
var makeThreadViewportStore = () => {
|
234
163
|
const scrollToBottomListeners = /* @__PURE__ */ new Set();
|
235
|
-
return
|
164
|
+
return create2(() => ({
|
236
165
|
isAtBottom: true,
|
237
166
|
scrollToBottom: () => {
|
238
167
|
for (const listener of scrollToBottomListeners) {
|
@@ -248,85 +177,65 @@ var makeThreadViewportStore = () => {
|
|
248
177
|
}));
|
249
178
|
};
|
250
179
|
|
251
|
-
// src/context/stores/ThreadMessages.ts
|
252
|
-
import { create as create5 } from "zustand";
|
253
|
-
var makeThreadMessagesStore = (runtimeRef) => {
|
254
|
-
return create5(() => runtimeRef.getState().messages);
|
255
|
-
};
|
256
|
-
|
257
180
|
// src/context/ReadonlyStore.ts
|
258
181
|
var writableStore = (store) => {
|
259
182
|
return store;
|
260
183
|
};
|
261
184
|
|
262
|
-
// src/context/providers/
|
263
|
-
import { create as
|
185
|
+
// src/context/providers/ThreadRuntimeProvider.tsx
|
186
|
+
import { create as create3 } from "zustand";
|
264
187
|
import { jsx, jsxs } from "react/jsx-runtime";
|
265
|
-
var
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
188
|
+
var useThreadRuntimeStore2 = (runtime) => {
|
189
|
+
const [store] = useState(() => create3(() => runtime));
|
190
|
+
useEffect(() => {
|
191
|
+
writableStore(store).setState(runtime, true);
|
192
|
+
}, [runtime, store]);
|
193
|
+
return store;
|
194
|
+
};
|
195
|
+
var useThreadStore2 = (runtime) => {
|
196
|
+
const [store] = useState(() => create3(() => runtime.getState()));
|
197
|
+
useEffect(() => {
|
198
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
199
|
+
updateState();
|
200
|
+
return runtime.subscribe(updateState);
|
201
|
+
}, [runtime, store]);
|
202
|
+
return store;
|
203
|
+
};
|
204
|
+
var useThreadMessagesStore2 = (runtime) => {
|
205
|
+
const [store] = useState(() => create3(() => runtime.messages));
|
206
|
+
useEffect(() => {
|
207
|
+
const updateState = () => writableStore(store).setState(runtime.messages, true);
|
208
|
+
updateState();
|
209
|
+
return runtime.subscribe(updateState);
|
210
|
+
}, [runtime, store]);
|
211
|
+
return store;
|
212
|
+
};
|
213
|
+
var useThreadComposerStore2 = (runtime) => {
|
214
|
+
const [store] = useState(() => create3(() => runtime.getState()));
|
215
|
+
useEffect(() => {
|
216
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
217
|
+
updateState();
|
218
|
+
return runtime.subscribe(updateState);
|
219
|
+
}, [runtime, store]);
|
220
|
+
return store;
|
221
|
+
};
|
222
|
+
var ThreadRuntimeProvider = ({ children, runtime }) => {
|
223
|
+
const useThreadRuntime2 = useThreadRuntimeStore2(runtime);
|
224
|
+
const useThread2 = useThreadStore2(runtime);
|
225
|
+
const useThreadMessages2 = useThreadMessagesStore2(runtime);
|
226
|
+
const useThreadComposer2 = useThreadComposerStore2(runtime.composer);
|
227
|
+
const context = useMemo(() => {
|
273
228
|
const useViewport = makeThreadViewportStore();
|
274
|
-
const useComposer2 = makeThreadComposerStore(useThreadRuntime2);
|
275
229
|
return {
|
276
230
|
useThread: useThread2,
|
277
231
|
useThreadRuntime: useThreadRuntime2,
|
278
232
|
useThreadMessages: useThreadMessages2,
|
279
233
|
useThreadActions: useThreadRuntime2,
|
280
|
-
useComposer:
|
234
|
+
useComposer: useThreadComposer2,
|
281
235
|
useViewport
|
282
236
|
};
|
283
|
-
});
|
284
|
-
|
285
|
-
const onThreadUpdate = () => {
|
286
|
-
const oldState = context.useThread.getState();
|
287
|
-
const state = getThreadStateFromRuntime(thread);
|
288
|
-
if (oldState.threadId !== state.threadId || oldState.isDisabled !== state.isDisabled || oldState.isRunning !== state.isRunning || oldState.capabilities !== state.capabilities) {
|
289
|
-
writableStore(context.useThread).setState(state, true);
|
290
|
-
}
|
291
|
-
if (thread.messages !== context.useThreadMessages.getState()) {
|
292
|
-
writableStore(context.useThreadMessages).setState(
|
293
|
-
thread.messages,
|
294
|
-
true
|
295
|
-
);
|
296
|
-
}
|
297
|
-
const composerState = context.useComposer.getState();
|
298
|
-
if (state.capabilities.cancel !== composerState.canCancel) {
|
299
|
-
writableStore(context.useComposer).setState({
|
300
|
-
canCancel: state.capabilities.cancel
|
301
|
-
});
|
302
|
-
}
|
303
|
-
};
|
304
|
-
onThreadUpdate();
|
305
|
-
return thread.subscribe(onThreadUpdate);
|
306
|
-
}, [thread, context]);
|
307
|
-
useEffect(() => {
|
308
|
-
const onComposerUpdate = () => {
|
309
|
-
const composer = thread.composer;
|
310
|
-
const composerState = context.useComposer.getState();
|
311
|
-
if (composer.isEmpty !== composerState.isEmpty || composer.text !== composerState.text || composer.attachmentAccept !== composerState.attachmentAccept || composer.attachments !== composerState.attachments) {
|
312
|
-
writableStore(context.useComposer).setState({
|
313
|
-
isEmpty: composer.isEmpty,
|
314
|
-
text: composer.text,
|
315
|
-
attachmentAccept: composer.attachmentAccept,
|
316
|
-
attachments: composer.attachments
|
317
|
-
});
|
318
|
-
}
|
319
|
-
};
|
320
|
-
onComposerUpdate();
|
321
|
-
return thread.composer.subscribe(onComposerUpdate);
|
322
|
-
}, [thread, context]);
|
323
|
-
useEffect(
|
324
|
-
() => thread.subscribe(() => {
|
325
|
-
writableStore(context.useThreadRuntime).setState(thread, true);
|
326
|
-
}),
|
327
|
-
[thread, context]
|
328
|
-
);
|
329
|
-
const Synchronizer = context.useThreadRuntime(
|
237
|
+
}, [useThread2, useThreadRuntime2, useThreadMessages2, useThreadComposer2]);
|
238
|
+
const Synchronizer = context.useThread(
|
330
239
|
(t) => t.unstable_synchronizer
|
331
240
|
);
|
332
241
|
return /* @__PURE__ */ jsxs(ThreadContext.Provider, { value: context, children: [
|
@@ -335,40 +244,36 @@ var ThreadProvider = ({
|
|
335
244
|
] });
|
336
245
|
};
|
337
246
|
|
338
|
-
// src/context/providers/
|
339
|
-
import { create as
|
247
|
+
// src/context/providers/AssistantRuntimeProvider.tsx
|
248
|
+
import { create as create4 } from "zustand";
|
340
249
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
341
|
-
var
|
342
|
-
const
|
343
|
-
|
344
|
-
|
345
|
-
});
|
346
|
-
|
347
|
-
|
348
|
-
|
250
|
+
var useAssistantRuntimeStore2 = (runtime) => {
|
251
|
+
const [store] = useState2(() => create4(() => runtime));
|
252
|
+
useEffect2(() => {
|
253
|
+
writableStore(store).setState(runtime, true);
|
254
|
+
}, [runtime, store]);
|
255
|
+
return store;
|
256
|
+
};
|
257
|
+
var useAssistantToolUIsStore = () => {
|
258
|
+
return useMemo2(() => makeAssistantToolUIsStore(), []);
|
259
|
+
};
|
260
|
+
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
261
|
+
const useAssistantRuntime2 = useAssistantRuntimeStore2(runtime);
|
262
|
+
const useToolUIs2 = useAssistantToolUIsStore();
|
263
|
+
const context = useMemo2(() => {
|
349
264
|
return {
|
350
265
|
useToolUIs: useToolUIs2,
|
351
266
|
useAssistantRuntime: useAssistantRuntime2,
|
352
267
|
useAssistantActions: useAssistantRuntime2
|
353
268
|
};
|
354
|
-
});
|
355
|
-
|
356
|
-
() => writableStore(context.useAssistantRuntime).setState(runtime, true),
|
357
|
-
[runtime, context]
|
358
|
-
);
|
359
|
-
return /* @__PURE__ */ jsx2(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx2(ThreadProvider, { provider: runtime.thread, children }) });
|
360
|
-
};
|
361
|
-
|
362
|
-
// src/context/providers/AssistantRuntimeProvider.tsx
|
363
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
364
|
-
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
365
|
-
return /* @__PURE__ */ jsx3(AssistantProvider, { runtime, children });
|
269
|
+
}, [useAssistantRuntime2, useToolUIs2]);
|
270
|
+
return /* @__PURE__ */ jsx2(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx2(ThreadRuntimeProvider, { runtime: runtime.thread, children }) });
|
366
271
|
};
|
367
272
|
var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
368
273
|
|
369
274
|
// src/context/providers/TextContentPartProvider.tsx
|
370
275
|
import { useEffect as useEffect3, useState as useState3 } from "react";
|
371
|
-
import { create as
|
276
|
+
import { create as create5 } from "zustand";
|
372
277
|
|
373
278
|
// src/context/react/ContentPartContext.ts
|
374
279
|
import { createContext as createContext3 } from "react";
|
@@ -379,13 +284,49 @@ var useContentPartContext = createContextHook(
|
|
379
284
|
ContentPartContext,
|
380
285
|
"a component passed to <MessagePrimitive.Content components={...}>"
|
381
286
|
);
|
287
|
+
function useContentPartRuntime(options) {
|
288
|
+
const context = useContentPartContext(options);
|
289
|
+
if (!context) return null;
|
290
|
+
return context.useContentPartRuntime();
|
291
|
+
}
|
382
292
|
var { useContentPart, useContentPartStore } = createContextStoreHook(
|
383
293
|
useContentPartContext,
|
384
294
|
"useContentPart"
|
385
295
|
);
|
386
296
|
|
297
|
+
// src/api/ContentPartRuntime.ts
|
298
|
+
var ContentPartRuntime = class {
|
299
|
+
constructor(contentBinding, messageApi, threadApi) {
|
300
|
+
this.contentBinding = contentBinding;
|
301
|
+
this.messageApi = messageApi;
|
302
|
+
this.threadApi = threadApi;
|
303
|
+
}
|
304
|
+
getState() {
|
305
|
+
return this.contentBinding.getState();
|
306
|
+
}
|
307
|
+
addToolResult(result) {
|
308
|
+
const message = this.messageApi.getState();
|
309
|
+
if (!message) throw new Error("Message is not available");
|
310
|
+
const state = this.contentBinding.getState();
|
311
|
+
if (!state) throw new Error("Content part is not available");
|
312
|
+
if (state.type !== "tool-call")
|
313
|
+
throw new Error("Tried to add tool result to non-tool content part");
|
314
|
+
const toolName = state.toolName;
|
315
|
+
const toolCallId = state.toolCallId;
|
316
|
+
this.threadApi.getState().addToolResult({
|
317
|
+
messageId: message.id,
|
318
|
+
toolName,
|
319
|
+
toolCallId,
|
320
|
+
result
|
321
|
+
});
|
322
|
+
}
|
323
|
+
subscribe(callback) {
|
324
|
+
return this.contentBinding.subscribe(callback);
|
325
|
+
}
|
326
|
+
};
|
327
|
+
|
387
328
|
// src/context/providers/TextContentPartProvider.tsx
|
388
|
-
import { jsx as
|
329
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
389
330
|
var COMPLETE_STATUS = {
|
390
331
|
type: "complete"
|
391
332
|
};
|
@@ -394,18 +335,22 @@ var RUNNING_STATUS = {
|
|
394
335
|
};
|
395
336
|
var TextContentPartProvider = ({ children, text, isRunning }) => {
|
396
337
|
const [context] = useState3(() => {
|
397
|
-
const
|
338
|
+
const useContentPartRuntime2 = create5(
|
339
|
+
// TODO
|
340
|
+
() => new ContentPartRuntime(null, null, null)
|
341
|
+
);
|
342
|
+
const useContentPart2 = create5(() => ({
|
398
343
|
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
399
|
-
part: { type: "text", text }
|
344
|
+
part: { type: "text", text },
|
345
|
+
type: "text",
|
346
|
+
text
|
400
347
|
}));
|
401
|
-
return {
|
402
|
-
useContentPart: useContentPart2
|
403
|
-
};
|
348
|
+
return { useContentPartRuntime: useContentPartRuntime2, useContentPart: useContentPart2 };
|
404
349
|
});
|
405
350
|
useEffect3(() => {
|
406
351
|
const state = context.useContentPart.getState();
|
407
|
-
const textUpdated = state.
|
408
|
-
const targetTextPart = textUpdated ? { type: "text", text } : state
|
352
|
+
const textUpdated = state.text !== text;
|
353
|
+
const targetTextPart = textUpdated ? { type: "text", text } : state;
|
409
354
|
const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;
|
410
355
|
const statusUpdated = state.status !== targetStatus;
|
411
356
|
if (!textUpdated && !statusUpdated) return;
|
@@ -417,7 +362,7 @@ var TextContentPartProvider = ({ children, text, isRunning }) => {
|
|
417
362
|
true
|
418
363
|
);
|
419
364
|
}, [context, isRunning, text]);
|
420
|
-
return /* @__PURE__ */
|
365
|
+
return /* @__PURE__ */ jsx3(ContentPartContext.Provider, { value: context, children });
|
421
366
|
};
|
422
367
|
|
423
368
|
// src/context/react/MessageContext.ts
|
@@ -427,6 +372,11 @@ var useMessageContext = createContextHook(
|
|
427
372
|
MessageContext,
|
428
373
|
"a component passed to <ThreadPrimitive.Messages components={...} />"
|
429
374
|
);
|
375
|
+
function useMessageRuntime(options) {
|
376
|
+
const context = useMessageContext(options);
|
377
|
+
if (!context) return null;
|
378
|
+
return context.useMessageRuntime();
|
379
|
+
}
|
430
380
|
var { useMessage, useMessageStore } = createContextStoreHook(
|
431
381
|
useMessageContext,
|
432
382
|
"useMessage"
|
@@ -441,59 +391,41 @@ var { useEditComposer, useEditComposerStore } = createContextStoreHook(
|
|
441
391
|
);
|
442
392
|
|
443
393
|
// src/context/react/ComposerContext.ts
|
444
|
-
import { useMemo } from "react";
|
394
|
+
import { useMemo as useMemo3 } from "react";
|
445
395
|
var useComposerContext = () => {
|
446
|
-
const { useComposer:
|
396
|
+
const { useComposer: useThreadComposer2 } = useThreadContext();
|
447
397
|
const { useEditComposer: useEditComposer2 } = useMessageContext({ optional: true }) ?? {};
|
448
|
-
return
|
398
|
+
return useMemo3(
|
449
399
|
() => ({
|
450
|
-
useComposer: useEditComposer2 ??
|
400
|
+
useComposer: useEditComposer2 ?? useThreadComposer2,
|
451
401
|
type: useEditComposer2 ? "edit" : "new"
|
452
402
|
}),
|
453
|
-
[useEditComposer2,
|
403
|
+
[useEditComposer2, useThreadComposer2]
|
454
404
|
);
|
455
405
|
};
|
456
406
|
var { useComposer, useComposerStore } = createContextStoreHook(
|
457
407
|
useComposerContext,
|
458
408
|
"useComposer"
|
459
409
|
);
|
410
|
+
function useComposerRuntime(options) {
|
411
|
+
const messageRuntime = useMessageRuntime({ optional: true });
|
412
|
+
const threadRuntime = useThreadRuntime(options);
|
413
|
+
return messageRuntime ? messageRuntime.composer : threadRuntime?.composer ?? null;
|
414
|
+
}
|
460
415
|
|
461
416
|
// src/hooks/useAppendMessage.tsx
|
462
417
|
import { useCallback } from "react";
|
463
|
-
var toAppendMessage = (useThreadMessages2, message) => {
|
464
|
-
if (typeof message === "string") {
|
465
|
-
return {
|
466
|
-
parentId: useThreadMessages2.getState().at(-1)?.id ?? null,
|
467
|
-
role: "user",
|
468
|
-
content: [{ type: "text", text: message }],
|
469
|
-
attachments: []
|
470
|
-
};
|
471
|
-
}
|
472
|
-
return {
|
473
|
-
parentId: message.parentId ?? useThreadMessages2.getState().at(-1)?.id ?? null,
|
474
|
-
role: message.role ?? "user",
|
475
|
-
content: message.content,
|
476
|
-
attachments: message.attachments ?? []
|
477
|
-
};
|
478
|
-
};
|
479
418
|
var useAppendMessage = () => {
|
480
|
-
const threadMessagesStore = useThreadMessagesStore();
|
481
419
|
const threadRuntime = useThreadRuntime();
|
482
420
|
const threadViewportStore = useThreadViewportStore();
|
483
421
|
const threadComposerStore = useThreadComposerStore();
|
484
422
|
const append = useCallback(
|
485
423
|
(message) => {
|
486
|
-
|
487
|
-
threadRuntime.append(appendMessage);
|
424
|
+
threadRuntime.append(message);
|
488
425
|
threadViewportStore.getState().scrollToBottom();
|
489
426
|
threadComposerStore.getState().focus();
|
490
427
|
},
|
491
|
-
[
|
492
|
-
threadMessagesStore,
|
493
|
-
threadRuntime,
|
494
|
-
threadViewportStore,
|
495
|
-
threadComposerStore
|
496
|
-
]
|
428
|
+
[threadRuntime, threadViewportStore, threadComposerStore]
|
497
429
|
);
|
498
430
|
return append;
|
499
431
|
};
|
@@ -582,7 +514,7 @@ var useAssistantInstructions = (instruction) => {
|
|
582
514
|
import { useCallback as useCallback3 } from "react";
|
583
515
|
|
584
516
|
// src/utils/combined/useCombinedStore.ts
|
585
|
-
import { useMemo as
|
517
|
+
import { useMemo as useMemo4 } from "react";
|
586
518
|
|
587
519
|
// src/utils/combined/createCombinedStore.ts
|
588
520
|
import { useSyncExternalStore } from "react";
|
@@ -603,7 +535,7 @@ var createCombinedStore = (stores) => {
|
|
603
535
|
|
604
536
|
// src/utils/combined/useCombinedStore.ts
|
605
537
|
var useCombinedStore = (stores, selector) => {
|
606
|
-
const useCombined =
|
538
|
+
const useCombined = useMemo4(() => createCombinedStore(stores), stores);
|
607
539
|
return useCombined(selector);
|
608
540
|
};
|
609
541
|
|
@@ -624,12 +556,12 @@ var useActionBarCopy = ({
|
|
624
556
|
const editComposerStore = useEditComposerStore();
|
625
557
|
const hasCopyableContent = useCombinedStore(
|
626
558
|
[messageStore, editComposerStore],
|
627
|
-
(
|
559
|
+
(message, c) => {
|
628
560
|
return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
629
561
|
}
|
630
562
|
);
|
631
563
|
const callback = useCallback3(() => {
|
632
|
-
const
|
564
|
+
const message = messageStore.getState();
|
633
565
|
const { setIsCopied } = messageUtilsStore.getState();
|
634
566
|
const { isEditing, text: composerValue } = editComposerStore.getState();
|
635
567
|
const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
|
@@ -645,12 +577,11 @@ var useActionBarCopy = ({
|
|
645
577
|
// src/primitive-hooks/actionBar/useActionBarEdit.tsx
|
646
578
|
import { useCallback as useCallback4 } from "react";
|
647
579
|
var useActionBarEdit = () => {
|
648
|
-
const
|
649
|
-
const disabled =
|
580
|
+
const composerRuntime = useComposerRuntime();
|
581
|
+
const disabled = useComposer((c) => c.isEditing);
|
650
582
|
const callback = useCallback4(() => {
|
651
|
-
|
652
|
-
|
653
|
-
}, [editComposerStore]);
|
583
|
+
composerRuntime.beginEdit();
|
584
|
+
}, [composerRuntime]);
|
654
585
|
if (disabled) return null;
|
655
586
|
return callback;
|
656
587
|
};
|
@@ -660,19 +591,18 @@ import { useCallback as useCallback5 } from "react";
|
|
660
591
|
var useActionBarReload = () => {
|
661
592
|
const messageStore = useMessageStore();
|
662
593
|
const threadStore = useThreadStore();
|
663
|
-
const
|
594
|
+
const messageRuntime = useMessageRuntime();
|
664
595
|
const threadComposerStore = useThreadComposerStore();
|
665
596
|
const threadViewportStore = useThreadViewportStore();
|
666
597
|
const disabled = useCombinedStore(
|
667
598
|
[threadStore, messageStore],
|
668
|
-
(t, m) => t.isRunning || t.isDisabled || m.
|
599
|
+
(t, m) => t.isRunning || t.isDisabled || m.role !== "assistant"
|
669
600
|
);
|
670
601
|
const callback = useCallback5(() => {
|
671
|
-
|
672
|
-
threadRuntime.startRun(parentId);
|
602
|
+
messageRuntime.reload();
|
673
603
|
threadViewportStore.getState().scrollToBottom();
|
674
604
|
threadComposerStore.getState().focus();
|
675
|
-
}, [
|
605
|
+
}, [messageRuntime, threadComposerStore, threadViewportStore]);
|
676
606
|
if (disabled) return null;
|
677
607
|
return callback;
|
678
608
|
};
|
@@ -682,19 +612,18 @@ import { useCallback as useCallback6 } from "react";
|
|
682
612
|
var useActionBarSpeak = () => {
|
683
613
|
const messageStore = useMessageStore();
|
684
614
|
const editComposerStore = useEditComposerStore();
|
685
|
-
const
|
615
|
+
const messageRunime = useMessageRuntime();
|
686
616
|
const messageUtilsStore = useMessageUtilsStore();
|
687
617
|
const hasSpeakableContent = useCombinedStore(
|
688
618
|
[messageStore, editComposerStore],
|
689
|
-
(
|
619
|
+
(message, c) => {
|
690
620
|
return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
691
621
|
}
|
692
622
|
);
|
693
623
|
const callback = useCallback6(async () => {
|
694
|
-
const
|
695
|
-
const utt = threadRuntime.speak(message.id);
|
624
|
+
const utt = messageRunime.speak();
|
696
625
|
messageUtilsStore.getState().addUtterance(utt);
|
697
|
-
}, [
|
626
|
+
}, [messageRunime, messageUtilsStore]);
|
698
627
|
if (!hasSpeakableContent) return null;
|
699
628
|
return callback;
|
700
629
|
};
|
@@ -714,79 +643,73 @@ var useActionBarStopSpeaking = () => {
|
|
714
643
|
// src/primitive-hooks/actionBar/useActionBarFeedbackPositive.tsx
|
715
644
|
import { useCallback as useCallback8 } from "react";
|
716
645
|
var useActionBarFeedbackPositive = () => {
|
717
|
-
const
|
718
|
-
const messageStore = useMessageStore();
|
646
|
+
const messageRuntime = useMessageRuntime();
|
719
647
|
const messageUtilsStore = useMessageUtilsStore();
|
720
648
|
const callback = useCallback8(() => {
|
721
|
-
|
722
|
-
messageId: messageStore.getState().message.id,
|
649
|
+
messageRuntime.submitFeedback({
|
723
650
|
type: "positive"
|
724
651
|
});
|
725
652
|
messageUtilsStore.getState().setSubmittedFeedback("positive");
|
726
|
-
}, [
|
653
|
+
}, [messageUtilsStore, messageRuntime]);
|
727
654
|
return callback;
|
728
655
|
};
|
729
656
|
|
730
657
|
// src/primitive-hooks/actionBar/useActionBarFeedbackNegative.tsx
|
731
658
|
import { useCallback as useCallback9 } from "react";
|
732
659
|
var useActionBarFeedbackNegative = () => {
|
733
|
-
const
|
734
|
-
const messageStore = useMessageStore();
|
660
|
+
const messageRuntime = useMessageRuntime();
|
735
661
|
const messageUtilsStore = useMessageUtilsStore();
|
736
662
|
const callback = useCallback9(() => {
|
737
|
-
|
738
|
-
messageId: messageStore.getState().message.id,
|
663
|
+
messageRuntime.submitFeedback({
|
739
664
|
type: "negative"
|
740
665
|
});
|
741
666
|
messageUtilsStore.getState().setSubmittedFeedback("negative");
|
742
|
-
}, [
|
667
|
+
}, [messageUtilsStore, messageRuntime]);
|
743
668
|
return callback;
|
744
669
|
};
|
745
670
|
|
746
671
|
// src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
|
747
672
|
var useBranchPickerCount = () => {
|
748
|
-
const branchCount = useMessage((s) => s.
|
673
|
+
const branchCount = useMessage((s) => s.branchCount);
|
749
674
|
return branchCount;
|
750
675
|
};
|
751
676
|
|
752
677
|
// src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
|
753
678
|
import { useCallback as useCallback10 } from "react";
|
754
679
|
var useBranchPickerNext = () => {
|
680
|
+
const messageRuntime = useMessageRuntime();
|
755
681
|
const messageStore = useMessageStore();
|
756
682
|
const editComposerStore = useEditComposerStore();
|
757
|
-
const threadRuntime = useThreadRuntime();
|
758
683
|
const disabled = useCombinedStore(
|
759
684
|
[messageStore, editComposerStore],
|
760
|
-
(m, c) => c.isEditing || m.
|
685
|
+
(m, c) => c.isEditing || m.branchNumber >= m.branchCount
|
761
686
|
);
|
762
687
|
const callback = useCallback10(() => {
|
763
|
-
|
764
|
-
|
765
|
-
}, [threadRuntime, messageStore]);
|
688
|
+
messageRuntime.switchToBranch({ position: "next" });
|
689
|
+
}, [messageRuntime]);
|
766
690
|
if (disabled) return null;
|
767
691
|
return callback;
|
768
692
|
};
|
769
693
|
|
770
694
|
// src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
|
771
695
|
var useBranchPickerNumber = () => {
|
772
|
-
const
|
773
|
-
return
|
696
|
+
const branchNumber = useMessage((s) => s.branchNumber);
|
697
|
+
return branchNumber;
|
774
698
|
};
|
775
699
|
|
776
700
|
// src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
|
777
701
|
import { useCallback as useCallback11 } from "react";
|
778
702
|
var useBranchPickerPrevious = () => {
|
703
|
+
const messageRuntime = useMessageRuntime();
|
779
704
|
const messageStore = useMessageStore();
|
780
705
|
const editComposerStore = useEditComposerStore();
|
781
|
-
const threadRuntime = useThreadRuntime();
|
782
706
|
const disabled = useCombinedStore(
|
783
707
|
[messageStore, editComposerStore],
|
784
|
-
(m, c) => c.isEditing || m.
|
708
|
+
(m, c) => c.isEditing || m.branchNumber <= 1
|
785
709
|
);
|
786
710
|
const callback = useCallback11(() => {
|
787
|
-
|
788
|
-
|
789
|
-
}, [threadRuntime, messageStore]);
|
711
|
+
messageRuntime.switchToBranch({ position: "previous" });
|
712
|
+
}, [messageRuntime]);
|
790
713
|
if (disabled) return null;
|
791
714
|
return callback;
|
792
715
|
};
|
@@ -863,7 +786,7 @@ var useComposerAddAttachment = () => {
|
|
863
786
|
// src/primitive-hooks/contentPart/useContentPartDisplay.tsx
|
864
787
|
var useContentPartDisplay = () => {
|
865
788
|
const display = useContentPart((c) => {
|
866
|
-
if (c.
|
789
|
+
if (c.type !== "ui")
|
867
790
|
throw new Error(
|
868
791
|
"This component can only be used inside ui content parts."
|
869
792
|
);
|
@@ -875,7 +798,7 @@ var useContentPartDisplay = () => {
|
|
875
798
|
// src/primitive-hooks/contentPart/useContentPartImage.tsx
|
876
799
|
var useContentPartImage = () => {
|
877
800
|
const image = useContentPart((c) => {
|
878
|
-
if (c.
|
801
|
+
if (c.type !== "image")
|
879
802
|
throw new Error(
|
880
803
|
"ContentPartImage can only be used inside image content parts."
|
881
804
|
);
|
@@ -887,7 +810,7 @@ var useContentPartImage = () => {
|
|
887
810
|
// src/primitive-hooks/contentPart/useContentPartText.tsx
|
888
811
|
var useContentPartText = () => {
|
889
812
|
const text = useContentPart((c) => {
|
890
|
-
if (c.
|
813
|
+
if (c.type !== "text")
|
891
814
|
throw new Error(
|
892
815
|
"ContentPartText can only be used inside text content parts."
|
893
816
|
);
|
@@ -902,19 +825,19 @@ var useMessageIf = (props) => {
|
|
902
825
|
const messageUtilsStore = useMessageUtilsStore();
|
903
826
|
return useCombinedStore(
|
904
827
|
[messageStore, messageUtilsStore],
|
905
|
-
({
|
906
|
-
if (props.hasBranches === true &&
|
907
|
-
if (props.user &&
|
908
|
-
if (props.assistant &&
|
909
|
-
if (props.system &&
|
828
|
+
({ role, attachments, branchCount, isLast }, { isCopied, isHovering, isSpeaking, submittedFeedback }) => {
|
829
|
+
if (props.hasBranches === true && branchCount < 2) return false;
|
830
|
+
if (props.user && role !== "user") return false;
|
831
|
+
if (props.assistant && role !== "assistant") return false;
|
832
|
+
if (props.system && role !== "system") return false;
|
910
833
|
if (props.lastOrHover === true && !isHovering && !isLast) return false;
|
911
834
|
if (props.copied === true && !isCopied) return false;
|
912
835
|
if (props.copied === false && isCopied) return false;
|
913
836
|
if (props.speaking === true && !isSpeaking) return false;
|
914
837
|
if (props.speaking === false && isSpeaking) return false;
|
915
|
-
if (props.hasAttachments === true && (
|
838
|
+
if (props.hasAttachments === true && (role !== "user" || !attachments.length))
|
916
839
|
return false;
|
917
|
-
if (props.hasAttachments === false &&
|
840
|
+
if (props.hasAttachments === false && role === "user" && !!attachments.length)
|
918
841
|
return false;
|
919
842
|
if (props.submittedFeedback !== void 0 && submittedFeedback !== props.submittedFeedback)
|
920
843
|
return false;
|
@@ -925,20 +848,15 @@ var useMessageIf = (props) => {
|
|
925
848
|
|
926
849
|
// src/primitive-hooks/thread/useThreadIf.tsx
|
927
850
|
var useThreadIf = (props) => {
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
(thread
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
if (props.disabled === true && thread.isDisabled) return false;
|
938
|
-
if (props.disabled === false && thread.isDisabled) return false;
|
939
|
-
return true;
|
940
|
-
}
|
941
|
-
);
|
851
|
+
return useThread((thread) => {
|
852
|
+
if (props.empty === true && thread.messages.length !== 0) return false;
|
853
|
+
if (props.empty === false && thread.messages.length === 0) return false;
|
854
|
+
if (props.running === true && !thread.isRunning) return false;
|
855
|
+
if (props.running === false && thread.isRunning) return false;
|
856
|
+
if (props.disabled === true && thread.isDisabled) return false;
|
857
|
+
if (props.disabled === false && thread.isDisabled) return false;
|
858
|
+
return true;
|
859
|
+
});
|
942
860
|
};
|
943
861
|
|
944
862
|
// src/primitive-hooks/thread/useThreadEmpty.tsx
|
@@ -1025,7 +943,7 @@ var useActionBarFloatStatus = ({
|
|
1025
943
|
};
|
1026
944
|
|
1027
945
|
// src/primitives/actionBar/ActionBarRoot.tsx
|
1028
|
-
import { jsx as
|
946
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
1029
947
|
var ActionBarPrimitiveRoot = forwardRef(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
|
1030
948
|
const hideAndfloatStatus = useActionBarFloatStatus({
|
1031
949
|
hideWhenRunning,
|
@@ -1033,7 +951,7 @@ var ActionBarPrimitiveRoot = forwardRef(({ hideWhenRunning, autohide, autohideFl
|
|
1033
951
|
autohideFloat
|
1034
952
|
});
|
1035
953
|
if (hideAndfloatStatus === "hidden" /* Hidden */) return null;
|
1036
|
-
return /* @__PURE__ */
|
954
|
+
return /* @__PURE__ */ jsx4(
|
1037
955
|
Primitive.div,
|
1038
956
|
{
|
1039
957
|
...hideAndfloatStatus === "floating" /* Floating */ ? { "data-floating": "true" } : null,
|
@@ -1048,11 +966,11 @@ ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
|
|
1048
966
|
import { forwardRef as forwardRef2 } from "react";
|
1049
967
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
1050
968
|
import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
|
1051
|
-
import { jsx as
|
969
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
1052
970
|
var ActionBarPrimitiveCopy = forwardRef2(({ copiedDuration, onClick, disabled, ...props }, forwardedRef) => {
|
1053
971
|
const isCopied = useMessageUtils((u) => u.isCopied);
|
1054
972
|
const callback = useActionBarCopy({ copiedDuration });
|
1055
|
-
return /* @__PURE__ */
|
973
|
+
return /* @__PURE__ */ jsx5(
|
1056
974
|
Primitive2.button,
|
1057
975
|
{
|
1058
976
|
type: "button",
|
@@ -1072,7 +990,7 @@ ActionBarPrimitiveCopy.displayName = "ActionBarPrimitive.Copy";
|
|
1072
990
|
import { forwardRef as forwardRef3 } from "react";
|
1073
991
|
import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
|
1074
992
|
import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
|
1075
|
-
import { jsx as
|
993
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
1076
994
|
var createActionButton = (displayName, useActionButton, forwardProps = []) => {
|
1077
995
|
const ActionButton = forwardRef3((props, forwardedRef) => {
|
1078
996
|
const forwardedProps = {};
|
@@ -1085,7 +1003,7 @@ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
|
|
1085
1003
|
}
|
1086
1004
|
});
|
1087
1005
|
const callback = useActionButton(forwardedProps);
|
1088
|
-
return /* @__PURE__ */
|
1006
|
+
return /* @__PURE__ */ jsx6(
|
1089
1007
|
Primitive3.button,
|
1090
1008
|
{
|
1091
1009
|
type: "button",
|
@@ -1125,7 +1043,7 @@ import { forwardRef as forwardRef4 } from "react";
|
|
1125
1043
|
import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
|
1126
1044
|
import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
|
1127
1045
|
import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primitive";
|
1128
|
-
import { jsx as
|
1046
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
1129
1047
|
var ActionBarPrimitiveStopSpeaking = forwardRef4((props, ref) => {
|
1130
1048
|
const callback = useActionBarStopSpeaking();
|
1131
1049
|
useEscapeKeydown((e) => {
|
@@ -1134,7 +1052,7 @@ var ActionBarPrimitiveStopSpeaking = forwardRef4((props, ref) => {
|
|
1134
1052
|
callback();
|
1135
1053
|
}
|
1136
1054
|
});
|
1137
|
-
return /* @__PURE__ */
|
1055
|
+
return /* @__PURE__ */ jsx7(
|
1138
1056
|
Primitive4.button,
|
1139
1057
|
{
|
1140
1058
|
type: "button",
|
@@ -1153,13 +1071,13 @@ ActionBarPrimitiveStopSpeaking.displayName = "ActionBarPrimitive.StopSpeaking";
|
|
1153
1071
|
import { forwardRef as forwardRef5 } from "react";
|
1154
1072
|
import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
|
1155
1073
|
import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
|
1156
|
-
import { jsx as
|
1074
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
1157
1075
|
var ActionBarPrimitiveFeedbackPositive = forwardRef5(({ onClick, disabled, ...props }, forwardedRef) => {
|
1158
1076
|
const isSubmitted = useMessageUtils(
|
1159
1077
|
(u) => u.submittedFeedback === "positive"
|
1160
1078
|
);
|
1161
1079
|
const callback = useActionBarFeedbackPositive();
|
1162
|
-
return /* @__PURE__ */
|
1080
|
+
return /* @__PURE__ */ jsx8(
|
1163
1081
|
Primitive5.button,
|
1164
1082
|
{
|
1165
1083
|
type: "button",
|
@@ -1179,13 +1097,13 @@ ActionBarPrimitiveFeedbackPositive.displayName = "ActionBarPrimitive.FeedbackPos
|
|
1179
1097
|
import { forwardRef as forwardRef6 } from "react";
|
1180
1098
|
import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
|
1181
1099
|
import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
|
1182
|
-
import { jsx as
|
1100
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
1183
1101
|
var ActionBarPrimitiveFeedbackNegative = forwardRef6(({ onClick, disabled, ...props }, forwardedRef) => {
|
1184
1102
|
const isSubmitted = useMessageUtils(
|
1185
1103
|
(u) => u.submittedFeedback === "negative"
|
1186
1104
|
);
|
1187
1105
|
const callback = useActionBarFeedbackNegative();
|
1188
|
-
return /* @__PURE__ */
|
1106
|
+
return /* @__PURE__ */ jsx9(
|
1189
1107
|
Primitive6.button,
|
1190
1108
|
{
|
1191
1109
|
type: "button",
|
@@ -1233,7 +1151,7 @@ import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
1233
1151
|
var usePopoverScope = PopoverPrimitive.createPopoverScope();
|
1234
1152
|
|
1235
1153
|
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
1236
|
-
import { jsx as
|
1154
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
1237
1155
|
var useAssistantModalOpenState = (defaultOpen = false) => {
|
1238
1156
|
const state = useState4(defaultOpen);
|
1239
1157
|
const [, setOpen] = state;
|
@@ -1251,7 +1169,7 @@ var AssistantModalPrimitiveRoot = ({
|
|
1251
1169
|
}) => {
|
1252
1170
|
const scope = usePopoverScope(__scopeAssistantModal);
|
1253
1171
|
const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);
|
1254
|
-
return /* @__PURE__ */
|
1172
|
+
return /* @__PURE__ */ jsx10(
|
1255
1173
|
PopoverPrimitive2.Root,
|
1256
1174
|
{
|
1257
1175
|
...scope,
|
@@ -1266,14 +1184,14 @@ AssistantModalPrimitiveRoot.displayName = "AssistantModalPrimitive.Root";
|
|
1266
1184
|
// src/primitives/assistantModal/AssistantModalTrigger.tsx
|
1267
1185
|
import { forwardRef as forwardRef7 } from "react";
|
1268
1186
|
import * as PopoverPrimitive3 from "@radix-ui/react-popover";
|
1269
|
-
import { jsx as
|
1187
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
1270
1188
|
var AssistantModalPrimitiveTrigger = forwardRef7(
|
1271
1189
|
({
|
1272
1190
|
__scopeAssistantModal,
|
1273
1191
|
...rest
|
1274
1192
|
}, ref) => {
|
1275
1193
|
const scope = usePopoverScope(__scopeAssistantModal);
|
1276
|
-
return /* @__PURE__ */
|
1194
|
+
return /* @__PURE__ */ jsx11(PopoverPrimitive3.Trigger, { ...scope, ...rest, ref });
|
1277
1195
|
}
|
1278
1196
|
);
|
1279
1197
|
AssistantModalPrimitiveTrigger.displayName = "AssistantModalPrimitive.Trigger";
|
@@ -1282,7 +1200,7 @@ AssistantModalPrimitiveTrigger.displayName = "AssistantModalPrimitive.Trigger";
|
|
1282
1200
|
import { forwardRef as forwardRef8 } from "react";
|
1283
1201
|
import * as PopoverPrimitive4 from "@radix-ui/react-popover";
|
1284
1202
|
import { composeEventHandlers as composeEventHandlers7 } from "@radix-ui/primitive";
|
1285
|
-
import { jsx as
|
1203
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
1286
1204
|
var AssistantModalPrimitiveContent = forwardRef8(
|
1287
1205
|
({
|
1288
1206
|
__scopeAssistantModal,
|
@@ -1293,7 +1211,7 @@ var AssistantModalPrimitiveContent = forwardRef8(
|
|
1293
1211
|
...props
|
1294
1212
|
}, forwardedRef) => {
|
1295
1213
|
const scope = usePopoverScope(__scopeAssistantModal);
|
1296
|
-
return /* @__PURE__ */
|
1214
|
+
return /* @__PURE__ */ jsx12(PopoverPrimitive4.Portal, { ...scope, children: /* @__PURE__ */ jsx12(
|
1297
1215
|
PopoverPrimitive4.Content,
|
1298
1216
|
{
|
1299
1217
|
...scope,
|
@@ -1314,14 +1232,14 @@ AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
|
|
1314
1232
|
// src/primitives/assistantModal/AssistantModalAnchor.tsx
|
1315
1233
|
import { forwardRef as forwardRef9 } from "react";
|
1316
1234
|
import * as PopoverPrimitive5 from "@radix-ui/react-popover";
|
1317
|
-
import { jsx as
|
1235
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
1318
1236
|
var AssistantModalPrimitiveAnchor = forwardRef9(
|
1319
1237
|
({
|
1320
1238
|
__scopeAssistantModal,
|
1321
1239
|
...rest
|
1322
1240
|
}, ref) => {
|
1323
1241
|
const scope = usePopoverScope(__scopeAssistantModal);
|
1324
|
-
return /* @__PURE__ */
|
1242
|
+
return /* @__PURE__ */ jsx13(PopoverPrimitive5.Anchor, { ...scope, ...rest, ref });
|
1325
1243
|
}
|
1326
1244
|
);
|
1327
1245
|
AssistantModalPrimitiveAnchor.displayName = "AssistantModalPrimitive.Anchor";
|
@@ -1349,18 +1267,18 @@ var BranchPickerPrevious = createActionButton(
|
|
1349
1267
|
);
|
1350
1268
|
|
1351
1269
|
// src/primitives/branchPicker/BranchPickerCount.tsx
|
1352
|
-
import { Fragment, jsx as
|
1270
|
+
import { Fragment, jsx as jsx14 } from "react/jsx-runtime";
|
1353
1271
|
var BranchPickerPrimitiveCount = () => {
|
1354
1272
|
const branchCount = useBranchPickerCount();
|
1355
|
-
return /* @__PURE__ */
|
1273
|
+
return /* @__PURE__ */ jsx14(Fragment, { children: branchCount });
|
1356
1274
|
};
|
1357
1275
|
BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
|
1358
1276
|
|
1359
1277
|
// src/primitives/branchPicker/BranchPickerNumber.tsx
|
1360
|
-
import { Fragment as Fragment2, jsx as
|
1278
|
+
import { Fragment as Fragment2, jsx as jsx15 } from "react/jsx-runtime";
|
1361
1279
|
var BranchPickerPrimitiveNumber = () => {
|
1362
1280
|
const branchNumber = useBranchPickerNumber();
|
1363
|
-
return /* @__PURE__ */
|
1281
|
+
return /* @__PURE__ */ jsx15(Fragment2, { children: branchNumber });
|
1364
1282
|
};
|
1365
1283
|
BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
|
1366
1284
|
|
@@ -1386,9 +1304,9 @@ import {
|
|
1386
1304
|
} from "react";
|
1387
1305
|
|
1388
1306
|
// src/utils/hooks/useManagedRef.ts
|
1389
|
-
import { useCallback as useCallback17, useRef
|
1307
|
+
import { useCallback as useCallback17, useRef } from "react";
|
1390
1308
|
var useManagedRef = (callback) => {
|
1391
|
-
const cleanupRef =
|
1309
|
+
const cleanupRef = useRef();
|
1392
1310
|
const ref = useCallback17(
|
1393
1311
|
(el) => {
|
1394
1312
|
if (cleanupRef.current) {
|
@@ -1405,7 +1323,7 @@ var useManagedRef = (callback) => {
|
|
1405
1323
|
|
1406
1324
|
// src/primitives/message/MessageRoot.tsx
|
1407
1325
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
1408
|
-
import { jsx as
|
1326
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
1409
1327
|
var useIsHoveringRef = () => {
|
1410
1328
|
const messageUtilsStore = useMessageUtilsStore();
|
1411
1329
|
const callbackRef = useCallback18(
|
@@ -1432,7 +1350,7 @@ var useIsHoveringRef = () => {
|
|
1432
1350
|
var MessagePrimitiveRoot = forwardRef10((props, forwardRef33) => {
|
1433
1351
|
const isHoveringRef = useIsHoveringRef();
|
1434
1352
|
const ref = useComposedRefs(forwardRef33, isHoveringRef);
|
1435
|
-
return /* @__PURE__ */
|
1353
|
+
return /* @__PURE__ */ jsx16(Primitive7.div, { ...props, ref });
|
1436
1354
|
});
|
1437
1355
|
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
1438
1356
|
|
@@ -1447,77 +1365,38 @@ var MessagePrimitiveIf = ({
|
|
1447
1365
|
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
1448
1366
|
|
1449
1367
|
// src/primitives/message/MessageContent.tsx
|
1450
|
-
import { memo as memo2 } from "react";
|
1368
|
+
import { memo as memo2, useMemo as useMemo6 } from "react";
|
1451
1369
|
|
1452
|
-
// src/context/providers/
|
1370
|
+
// src/context/providers/ContentPartRuntimeProvider.tsx
|
1453
1371
|
import { useEffect as useEffect8, useState as useState5 } from "react";
|
1454
|
-
import { create as
|
1455
|
-
import { jsx as
|
1456
|
-
var
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
if (part.type !== "tool-call") {
|
1463
|
-
if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
|
1464
|
-
throw new Error(
|
1465
|
-
"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
|
1466
|
-
);
|
1467
|
-
return isLastPart ? message.status : COMPLETE_STATUS2;
|
1468
|
-
}
|
1469
|
-
if (!!part.result) {
|
1470
|
-
return COMPLETE_STATUS2;
|
1471
|
-
}
|
1472
|
-
return message.status;
|
1473
|
-
};
|
1474
|
-
var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
|
1475
|
-
var getContentPartState = ({ message }, useContentPart2, partIndex) => {
|
1476
|
-
let part = message.content[partIndex];
|
1477
|
-
if (!part) {
|
1478
|
-
if (message.content.length === 0 && partIndex === 0) {
|
1479
|
-
part = EMPTY_CONTENT;
|
1480
|
-
} else {
|
1481
|
-
return null;
|
1482
|
-
}
|
1483
|
-
} else if (message.content.length === 1 && part.type === "text" && part.text.length === 0) {
|
1484
|
-
part = EMPTY_CONTENT;
|
1485
|
-
}
|
1486
|
-
const status = toContentPartStatus(message, partIndex, part);
|
1487
|
-
const currentState = useContentPart2?.getState();
|
1488
|
-
if (currentState && currentState.part === part && currentState.status === status)
|
1489
|
-
return null;
|
1490
|
-
return Object.freeze({ part, status });
|
1372
|
+
import { create as create6 } from "zustand";
|
1373
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
1374
|
+
var useContentPartRuntimeStore = (runtime) => {
|
1375
|
+
const [store] = useState5(() => create6(() => runtime));
|
1376
|
+
useEffect8(() => {
|
1377
|
+
writableStore(store).setState(runtime, true);
|
1378
|
+
}, [runtime, store]);
|
1379
|
+
return store;
|
1491
1380
|
};
|
1492
|
-
var
|
1493
|
-
const
|
1494
|
-
const [context] = useState5(() => {
|
1495
|
-
const useContentPart2 = create9(
|
1496
|
-
() => getContentPartState(messageStore.getState(), void 0, partIndex)
|
1497
|
-
);
|
1498
|
-
return { useContentPart: useContentPart2 };
|
1499
|
-
});
|
1381
|
+
var useContentPartStore2 = (runtime) => {
|
1382
|
+
const [store] = useState5(() => create6(() => runtime.getState()));
|
1500
1383
|
useEffect8(() => {
|
1501
|
-
const
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
);
|
1507
|
-
if (!newState) return;
|
1508
|
-
writableStore(context.useContentPart).setState(newState, true);
|
1509
|
-
};
|
1510
|
-
syncContentPart(messageStore.getState());
|
1511
|
-
return messageStore.subscribe(syncContentPart);
|
1512
|
-
}, [context, messageStore, partIndex]);
|
1513
|
-
return context;
|
1384
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
1385
|
+
updateState();
|
1386
|
+
return runtime.subscribe(updateState);
|
1387
|
+
}, [runtime, store]);
|
1388
|
+
return store;
|
1514
1389
|
};
|
1515
|
-
var
|
1516
|
-
|
1390
|
+
var ContentPartRuntimeProvider = ({
|
1391
|
+
runtime,
|
1517
1392
|
children
|
1518
1393
|
}) => {
|
1519
|
-
const
|
1520
|
-
|
1394
|
+
const useContentPartRuntime2 = useContentPartRuntimeStore(runtime);
|
1395
|
+
const useContentPart2 = useContentPartStore2(runtime);
|
1396
|
+
const [context] = useState5(() => {
|
1397
|
+
return { useContentPartRuntime: useContentPartRuntime2, useContentPart: useContentPart2 };
|
1398
|
+
});
|
1399
|
+
return /* @__PURE__ */ jsx17(ContentPartContext.Provider, { value: context, children });
|
1521
1400
|
};
|
1522
1401
|
|
1523
1402
|
// src/primitives/contentPart/ContentPartText.tsx
|
@@ -1526,7 +1405,7 @@ import {
|
|
1526
1405
|
} from "react";
|
1527
1406
|
|
1528
1407
|
// src/utils/smooth/useSmooth.tsx
|
1529
|
-
import { useEffect as useEffect9, useMemo as
|
1408
|
+
import { useEffect as useEffect9, useMemo as useMemo5, useRef as useRef2, useState as useState7 } from "react";
|
1530
1409
|
import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
|
1531
1410
|
|
1532
1411
|
// src/utils/smooth/SmoothContext.tsx
|
@@ -1536,11 +1415,11 @@ import {
|
|
1536
1415
|
useContext as useContext2,
|
1537
1416
|
useState as useState6
|
1538
1417
|
} from "react";
|
1539
|
-
import { create as
|
1540
|
-
import { jsx as
|
1418
|
+
import { create as create7 } from "zustand";
|
1419
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
1541
1420
|
var SmoothContext = createContext5(null);
|
1542
1421
|
var makeSmoothContext = (initialState) => {
|
1543
|
-
const useSmoothStatus2 =
|
1422
|
+
const useSmoothStatus2 = create7(() => initialState);
|
1544
1423
|
return { useSmoothStatus: useSmoothStatus2 };
|
1545
1424
|
};
|
1546
1425
|
var SmoothContextProvider = ({ children }) => {
|
@@ -1550,11 +1429,11 @@ var SmoothContextProvider = ({ children }) => {
|
|
1550
1429
|
() => makeSmoothContext(contentPartStore.getState().status)
|
1551
1430
|
);
|
1552
1431
|
if (outer) return children;
|
1553
|
-
return /* @__PURE__ */
|
1432
|
+
return /* @__PURE__ */ jsx18(SmoothContext.Provider, { value: context, children });
|
1554
1433
|
};
|
1555
1434
|
var withSmoothContextProvider = (Component) => {
|
1556
1435
|
const Wrapped = forwardRef11((props, ref) => {
|
1557
|
-
return /* @__PURE__ */
|
1436
|
+
return /* @__PURE__ */ jsx18(SmoothContextProvider, { children: /* @__PURE__ */ jsx18(Component, { ...props, ref }) });
|
1558
1437
|
});
|
1559
1438
|
Wrapped.displayName = Component.displayName;
|
1560
1439
|
return Wrapped;
|
@@ -1621,31 +1500,29 @@ var SMOOTH_STATUS = Object.freeze({
|
|
1621
1500
|
type: "running"
|
1622
1501
|
});
|
1623
1502
|
var useSmooth = (state, smooth = false) => {
|
1624
|
-
const {
|
1625
|
-
part: { text }
|
1626
|
-
} = state;
|
1503
|
+
const { text } = state;
|
1627
1504
|
const id = useMessage({
|
1628
1505
|
optional: true,
|
1629
|
-
selector: (m) => m.
|
1506
|
+
selector: (m) => m.id
|
1630
1507
|
});
|
1631
|
-
const idRef =
|
1508
|
+
const idRef = useRef2(id);
|
1632
1509
|
const [displayedText, setDisplayedText] = useState7(text);
|
1633
1510
|
const smoothStatusStore = useSmoothStatusStore({ optional: true });
|
1634
1511
|
const setText = useCallbackRef2((text2) => {
|
1635
1512
|
setDisplayedText(text2);
|
1636
1513
|
if (smoothStatusStore) {
|
1637
1514
|
writableStore(smoothStatusStore).setState(
|
1638
|
-
text2 !== state.
|
1515
|
+
text2 !== state.text ? SMOOTH_STATUS : state.status
|
1639
1516
|
);
|
1640
1517
|
}
|
1641
1518
|
});
|
1642
1519
|
useEffect9(() => {
|
1643
1520
|
if (smoothStatusStore) {
|
1644
1521
|
writableStore(smoothStatusStore).setState(
|
1645
|
-
text !== state.
|
1522
|
+
text !== state.text ? SMOOTH_STATUS : state.status
|
1646
1523
|
);
|
1647
1524
|
}
|
1648
|
-
}, [smoothStatusStore, text, displayedText, state.status, state.
|
1525
|
+
}, [smoothStatusStore, text, displayedText, state.status, state.text]);
|
1649
1526
|
const [animatorRef] = useState7(
|
1650
1527
|
new TextStreamAnimator(text, setText)
|
1651
1528
|
);
|
@@ -1670,8 +1547,10 @@ var useSmooth = (state, smooth = false) => {
|
|
1670
1547
|
animatorRef.stop();
|
1671
1548
|
};
|
1672
1549
|
}, [animatorRef]);
|
1673
|
-
return
|
1550
|
+
return useMemo5(
|
1674
1551
|
() => smooth ? {
|
1552
|
+
type: "text",
|
1553
|
+
text: displayedText,
|
1675
1554
|
part: { type: "text", text: displayedText },
|
1676
1555
|
status: text === displayedText ? state.status : SMOOTH_STATUS
|
1677
1556
|
} : state,
|
@@ -1680,33 +1559,26 @@ var useSmooth = (state, smooth = false) => {
|
|
1680
1559
|
};
|
1681
1560
|
|
1682
1561
|
// src/primitives/contentPart/ContentPartText.tsx
|
1683
|
-
import { jsx as
|
1562
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
1684
1563
|
var ContentPartPrimitiveText = forwardRef12(({ smooth = true, component: Component = "span", ...rest }, forwardedRef) => {
|
1685
|
-
const {
|
1686
|
-
|
1687
|
-
status
|
1688
|
-
} = useSmooth(useContentPartText(), smooth);
|
1689
|
-
return /* @__PURE__ */ jsx20(Component, { "data-status": status.type, ...rest, ref: forwardedRef, children: text });
|
1564
|
+
const { text, status } = useSmooth(useContentPartText(), smooth);
|
1565
|
+
return /* @__PURE__ */ jsx19(Component, { "data-status": status.type, ...rest, ref: forwardedRef, children: text });
|
1690
1566
|
});
|
1691
1567
|
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1692
1568
|
|
1693
1569
|
// src/primitives/contentPart/ContentPartImage.tsx
|
1694
1570
|
import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
|
1695
1571
|
import { forwardRef as forwardRef13 } from "react";
|
1696
|
-
import { jsx as
|
1572
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
1697
1573
|
var ContentPartPrimitiveImage = forwardRef13((props, forwardedRef) => {
|
1698
|
-
const {
|
1699
|
-
|
1700
|
-
} = useContentPartImage();
|
1701
|
-
return /* @__PURE__ */ jsx21(Primitive8.img, { src: image, ...props, ref: forwardedRef });
|
1574
|
+
const { image } = useContentPartImage();
|
1575
|
+
return /* @__PURE__ */ jsx20(Primitive8.img, { src: image, ...props, ref: forwardedRef });
|
1702
1576
|
});
|
1703
1577
|
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1704
1578
|
|
1705
1579
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
1706
1580
|
var ContentPartPrimitiveDisplay = () => {
|
1707
|
-
const {
|
1708
|
-
part: { display }
|
1709
|
-
} = useContentPartDisplay();
|
1581
|
+
const { display } = useContentPartDisplay();
|
1710
1582
|
return display ?? null;
|
1711
1583
|
};
|
1712
1584
|
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
@@ -1718,28 +1590,399 @@ var ContentPartPrimitiveInProgress = ({ children }) => {
|
|
1718
1590
|
};
|
1719
1591
|
ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
|
1720
1592
|
|
1721
|
-
// src/
|
1722
|
-
|
1723
|
-
|
1724
|
-
UI,
|
1725
|
-
...props
|
1726
|
-
}) => {
|
1727
|
-
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName)) ?? UI;
|
1728
|
-
if (!Render) return null;
|
1729
|
-
return /* @__PURE__ */ jsx22(Render, { ...props });
|
1593
|
+
// src/api/ComposerRuntime.ts
|
1594
|
+
var METHOD_NOT_SUPPORTED = () => {
|
1595
|
+
throw new Error("Composer is not available");
|
1730
1596
|
};
|
1731
|
-
var
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1597
|
+
var EMPTY_ARRAY = Object.freeze([]);
|
1598
|
+
var getThreadComposerState = (type, runtime, beginEdit, focus, onFocus) => {
|
1599
|
+
return Object.freeze({
|
1600
|
+
type,
|
1601
|
+
isEditing: runtime?.isEditing ?? false,
|
1602
|
+
canCancel: runtime?.canCancel ?? false,
|
1603
|
+
isEmpty: runtime?.isEmpty ?? true,
|
1604
|
+
text: runtime?.text ?? "",
|
1605
|
+
attachments: runtime?.attachments ?? EMPTY_ARRAY,
|
1606
|
+
attachmentAccept: runtime?.attachmentAccept ?? "*",
|
1607
|
+
value: runtime?.text ?? "",
|
1608
|
+
setValue: runtime?.setText.bind(runtime) ?? METHOD_NOT_SUPPORTED,
|
1609
|
+
setText: runtime?.setText.bind(runtime) ?? METHOD_NOT_SUPPORTED,
|
1610
|
+
edit: beginEdit,
|
1611
|
+
send: runtime?.send.bind(runtime) ?? METHOD_NOT_SUPPORTED,
|
1612
|
+
cancel: runtime?.cancel.bind(runtime) ?? METHOD_NOT_SUPPORTED,
|
1613
|
+
focus: focus ?? METHOD_NOT_SUPPORTED,
|
1614
|
+
onFocus: onFocus ?? METHOD_NOT_SUPPORTED,
|
1615
|
+
reset: runtime?.reset.bind(runtime) ?? METHOD_NOT_SUPPORTED,
|
1616
|
+
addAttachment: runtime?.addAttachment.bind(runtime) ?? METHOD_NOT_SUPPORTED,
|
1617
|
+
removeAttachment: runtime?.removeAttachment.bind(runtime) ?? METHOD_NOT_SUPPORTED
|
1618
|
+
});
|
1738
1619
|
};
|
1739
|
-
var
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1620
|
+
var ComposerRuntime = class {
|
1621
|
+
constructor(_core, _beginEdit) {
|
1622
|
+
this._core = _core;
|
1623
|
+
this._beginEdit = _beginEdit;
|
1624
|
+
}
|
1625
|
+
get type() {
|
1626
|
+
return this._beginEdit ? "edit" : "thread";
|
1627
|
+
}
|
1628
|
+
/**
|
1629
|
+
* @deprecated Use `getState().isEditing` instead. This will be removed in 0.6.0.
|
1630
|
+
*/
|
1631
|
+
get isEditing() {
|
1632
|
+
return this.getState().isEditing;
|
1633
|
+
}
|
1634
|
+
/**
|
1635
|
+
* @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
|
1636
|
+
*/
|
1637
|
+
get isEmpty() {
|
1638
|
+
return this.getState().isEmpty;
|
1639
|
+
}
|
1640
|
+
/**
|
1641
|
+
* @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0.
|
1642
|
+
*/
|
1643
|
+
get canCancel() {
|
1644
|
+
return this.getState().canCancel;
|
1645
|
+
}
|
1646
|
+
/**
|
1647
|
+
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
1648
|
+
*/
|
1649
|
+
get text() {
|
1650
|
+
return this.getState().text;
|
1651
|
+
}
|
1652
|
+
/**
|
1653
|
+
* @deprecated Use `getState().attachmentAccept` instead. This will be removed in 0.6.0.
|
1654
|
+
*/
|
1655
|
+
get attachmentAccept() {
|
1656
|
+
return this.getState().attachmentAccept;
|
1657
|
+
}
|
1658
|
+
// TODO should this instead return getAttachmentByIndex([idx]) instead?
|
1659
|
+
/**
|
1660
|
+
* @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
|
1661
|
+
*/
|
1662
|
+
get attachments() {
|
1663
|
+
return this.getState().attachments;
|
1664
|
+
}
|
1665
|
+
/**
|
1666
|
+
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
1667
|
+
*/
|
1668
|
+
get value() {
|
1669
|
+
return this.text;
|
1670
|
+
}
|
1671
|
+
getState() {
|
1672
|
+
return getThreadComposerState(
|
1673
|
+
this.type,
|
1674
|
+
this._core.getState(),
|
1675
|
+
this._beginEdit?.bind(this) ?? METHOD_NOT_SUPPORTED,
|
1676
|
+
this.focus.bind(this),
|
1677
|
+
this.onFocus.bind(this)
|
1678
|
+
);
|
1679
|
+
}
|
1680
|
+
setText(text) {
|
1681
|
+
const core = this._core.getState();
|
1682
|
+
if (!core) throw new Error("Composer is not available");
|
1683
|
+
core.setText(text);
|
1684
|
+
}
|
1685
|
+
setValue(text) {
|
1686
|
+
this.setText(text);
|
1687
|
+
}
|
1688
|
+
addAttachment(file) {
|
1689
|
+
const core = this._core.getState();
|
1690
|
+
if (!core) throw new Error("Composer is not available");
|
1691
|
+
return core.addAttachment(file);
|
1692
|
+
}
|
1693
|
+
// /**
|
1694
|
+
// * @deprecated Use `getAttachmentById(id).removeAttachment` instead. This will be removed in 0.6.0.
|
1695
|
+
// */
|
1696
|
+
removeAttachment(attachmentId) {
|
1697
|
+
const core = this._core.getState();
|
1698
|
+
if (!core) throw new Error("Composer is not available");
|
1699
|
+
return core.removeAttachment(attachmentId);
|
1700
|
+
}
|
1701
|
+
/**
|
1702
|
+
* @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
|
1703
|
+
*/
|
1704
|
+
reset() {
|
1705
|
+
const core = this._core.getState();
|
1706
|
+
if (!core) throw new Error("Composer is not available");
|
1707
|
+
core.reset();
|
1708
|
+
}
|
1709
|
+
send() {
|
1710
|
+
const core = this._core.getState();
|
1711
|
+
if (!core) throw new Error("Composer is not available");
|
1712
|
+
core.send();
|
1713
|
+
}
|
1714
|
+
cancel() {
|
1715
|
+
const core = this._core.getState();
|
1716
|
+
if (!core) throw new Error("Composer is not available");
|
1717
|
+
core.cancel();
|
1718
|
+
}
|
1719
|
+
beginEdit() {
|
1720
|
+
this._beginEdit?.();
|
1721
|
+
}
|
1722
|
+
/**
|
1723
|
+
* @deprecated Use `beginEdit()` instead. This will be removed in 0.6.0.
|
1724
|
+
*/
|
1725
|
+
edit() {
|
1726
|
+
this.beginEdit();
|
1727
|
+
}
|
1728
|
+
subscribe(callback) {
|
1729
|
+
return this._core.subscribe(callback);
|
1730
|
+
}
|
1731
|
+
_focusListeners = /* @__PURE__ */ new Set();
|
1732
|
+
focus() {
|
1733
|
+
this._focusListeners.forEach((callback) => callback());
|
1734
|
+
}
|
1735
|
+
onFocus(callback) {
|
1736
|
+
this._focusListeners.add(callback);
|
1737
|
+
return () => this._focusListeners.delete(callback);
|
1738
|
+
}
|
1739
|
+
};
|
1740
|
+
|
1741
|
+
// src/api/subscribable/BaseSubject.ts
|
1742
|
+
var BaseSubject = class {
|
1743
|
+
_subscriptions = /* @__PURE__ */ new Set();
|
1744
|
+
_connection;
|
1745
|
+
get isConnected() {
|
1746
|
+
return !!this._connection;
|
1747
|
+
}
|
1748
|
+
notifySubscribers() {
|
1749
|
+
for (const callback of this._subscriptions) callback();
|
1750
|
+
}
|
1751
|
+
_updateConnection() {
|
1752
|
+
if (this._subscriptions.size > 0) {
|
1753
|
+
if (this._connection) return;
|
1754
|
+
this._connection = this._connect();
|
1755
|
+
} else {
|
1756
|
+
this._connection?.();
|
1757
|
+
this._connection = void 0;
|
1758
|
+
}
|
1759
|
+
}
|
1760
|
+
subscribe(callback) {
|
1761
|
+
this._subscriptions.add(callback);
|
1762
|
+
this._updateConnection();
|
1763
|
+
return () => {
|
1764
|
+
this._subscriptions.delete(callback);
|
1765
|
+
this._updateConnection();
|
1766
|
+
};
|
1767
|
+
}
|
1768
|
+
};
|
1769
|
+
|
1770
|
+
// src/api/subscribable/NestedSubscriptionSubject.ts
|
1771
|
+
var NestedSubscriptionSubject = class extends BaseSubject {
|
1772
|
+
constructor(binding) {
|
1773
|
+
super();
|
1774
|
+
this.binding = binding;
|
1775
|
+
}
|
1776
|
+
getState() {
|
1777
|
+
return this.binding.getState();
|
1778
|
+
}
|
1779
|
+
_connect() {
|
1780
|
+
const callback = () => {
|
1781
|
+
this.notifySubscribers();
|
1782
|
+
};
|
1783
|
+
let lastState = this.binding.getState();
|
1784
|
+
let innerUnsubscribe = lastState?.subscribe(callback);
|
1785
|
+
const onRuntimeUpdate = () => {
|
1786
|
+
const newState = this.binding.getState();
|
1787
|
+
if (newState === lastState) return;
|
1788
|
+
lastState = newState;
|
1789
|
+
innerUnsubscribe?.();
|
1790
|
+
innerUnsubscribe = this.binding.getState()?.subscribe(callback);
|
1791
|
+
callback();
|
1792
|
+
};
|
1793
|
+
const outerUnsubscribe = this.binding.subscribe(onRuntimeUpdate);
|
1794
|
+
return () => {
|
1795
|
+
outerUnsubscribe?.();
|
1796
|
+
innerUnsubscribe?.();
|
1797
|
+
};
|
1798
|
+
}
|
1799
|
+
};
|
1800
|
+
|
1801
|
+
// src/api/subscribable/shallowEqual.ts
|
1802
|
+
function shallowEqual(objA, objB) {
|
1803
|
+
if (objA === void 0 && objB === void 0) return true;
|
1804
|
+
if (objA === void 0) return false;
|
1805
|
+
if (objB === void 0) return false;
|
1806
|
+
for (const key of Object.keys(objA)) {
|
1807
|
+
const valueA = objA[key];
|
1808
|
+
const valueB = objB[key];
|
1809
|
+
if (!Object.is(valueA, valueB)) return false;
|
1810
|
+
}
|
1811
|
+
return true;
|
1812
|
+
}
|
1813
|
+
|
1814
|
+
// src/api/subscribable/ShallowMemoizeSubject.ts
|
1815
|
+
var ShallowMemoizeSubject = class extends BaseSubject {
|
1816
|
+
constructor(binding) {
|
1817
|
+
super();
|
1818
|
+
this.binding = binding;
|
1819
|
+
const state = binding.getState();
|
1820
|
+
if (state === void 0)
|
1821
|
+
throw new Error("Entry not available in the store");
|
1822
|
+
this._previousState = state;
|
1823
|
+
}
|
1824
|
+
_previousState;
|
1825
|
+
getState = () => {
|
1826
|
+
if (!this.isConnected) this._syncState();
|
1827
|
+
return this._previousState;
|
1828
|
+
};
|
1829
|
+
_syncState() {
|
1830
|
+
const state = this.binding.getState();
|
1831
|
+
if (state === void 0) return false;
|
1832
|
+
if (shallowEqual(state, this._previousState)) return false;
|
1833
|
+
this._previousState = state;
|
1834
|
+
return true;
|
1835
|
+
}
|
1836
|
+
_connect() {
|
1837
|
+
const callback = () => {
|
1838
|
+
if (this._syncState()) {
|
1839
|
+
this.notifySubscribers();
|
1840
|
+
}
|
1841
|
+
};
|
1842
|
+
return this.binding.subscribe(callback);
|
1843
|
+
}
|
1844
|
+
};
|
1845
|
+
|
1846
|
+
// src/api/MessageRuntime.ts
|
1847
|
+
var COMPLETE_STATUS2 = {
|
1848
|
+
type: "complete"
|
1849
|
+
};
|
1850
|
+
var toContentPartStatus = (message, partIndex, part) => {
|
1851
|
+
if (message.role !== "assistant") return COMPLETE_STATUS2;
|
1852
|
+
const isLastPart = partIndex === Math.max(0, message.content.length - 1);
|
1853
|
+
if (part.type !== "tool-call") {
|
1854
|
+
if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
|
1855
|
+
throw new Error(
|
1856
|
+
"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
|
1857
|
+
);
|
1858
|
+
return isLastPart ? message.status : COMPLETE_STATUS2;
|
1859
|
+
}
|
1860
|
+
if (!!part.result) {
|
1861
|
+
return COMPLETE_STATUS2;
|
1862
|
+
}
|
1863
|
+
return message.status;
|
1864
|
+
};
|
1865
|
+
var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
|
1866
|
+
var getContentPartState = (message, partIndex) => {
|
1867
|
+
let part = message.content[partIndex];
|
1868
|
+
if (!part) {
|
1869
|
+
if (message.content.length === 0 && partIndex === 0) {
|
1870
|
+
part = EMPTY_CONTENT;
|
1871
|
+
} else {
|
1872
|
+
return void 0;
|
1873
|
+
}
|
1874
|
+
} else if (message.content.length === 1 && part.type === "text" && part.text.length === 0) {
|
1875
|
+
part = EMPTY_CONTENT;
|
1876
|
+
}
|
1877
|
+
const status = toContentPartStatus(message, partIndex, part);
|
1878
|
+
return Object.freeze({ ...part, part, status });
|
1879
|
+
};
|
1880
|
+
var MessageRuntime = class {
|
1881
|
+
constructor(_core, _threadBinding) {
|
1882
|
+
this._core = _core;
|
1883
|
+
this._threadBinding = _threadBinding;
|
1884
|
+
}
|
1885
|
+
composer = new ComposerRuntime(
|
1886
|
+
new NestedSubscriptionSubject({
|
1887
|
+
getState: () => this._threadBinding.getState().getEditComposer(this._core.getState().id),
|
1888
|
+
subscribe: (callback) => this._threadBinding.subscribe(callback)
|
1889
|
+
}),
|
1890
|
+
() => this._threadBinding.getState().beginEdit(this._core.getState().id)
|
1891
|
+
);
|
1892
|
+
getState() {
|
1893
|
+
return this._core.getState();
|
1894
|
+
}
|
1895
|
+
// TODO improve type
|
1896
|
+
unstable_edit(message) {
|
1897
|
+
const state = this._core.getState();
|
1898
|
+
if (!state) throw new Error("Message is not available");
|
1899
|
+
this._threadBinding.getState().append({
|
1900
|
+
...message,
|
1901
|
+
parentId: state.parentId
|
1902
|
+
});
|
1903
|
+
}
|
1904
|
+
reload() {
|
1905
|
+
const state = this._core.getState();
|
1906
|
+
if (!state) throw new Error("Message is not available");
|
1907
|
+
if (state.role !== "assistant")
|
1908
|
+
throw new Error("Can only reload assistant messages");
|
1909
|
+
this._threadBinding.getState().startRun(state.parentId);
|
1910
|
+
}
|
1911
|
+
speak() {
|
1912
|
+
const state = this._core.getState();
|
1913
|
+
if (!state) throw new Error("Message is not available");
|
1914
|
+
return this._threadBinding.getState().speak(state.id);
|
1915
|
+
}
|
1916
|
+
submitFeedback({ type }) {
|
1917
|
+
const state = this._core.getState();
|
1918
|
+
if (!state) throw new Error("Message is not available");
|
1919
|
+
this._threadBinding.getState().submitFeedback({
|
1920
|
+
messageId: state.id,
|
1921
|
+
type
|
1922
|
+
});
|
1923
|
+
}
|
1924
|
+
switchToBranch({
|
1925
|
+
position,
|
1926
|
+
branchId
|
1927
|
+
}) {
|
1928
|
+
const state = this._core.getState();
|
1929
|
+
if (!state) throw new Error("Message is not available");
|
1930
|
+
if (branchId && position) {
|
1931
|
+
throw new Error("May not specify both branchId and position");
|
1932
|
+
} else if (!branchId && !position) {
|
1933
|
+
throw new Error("Must specify either branchId or position");
|
1934
|
+
}
|
1935
|
+
const thread = this._threadBinding.getState();
|
1936
|
+
const branches = thread.getBranches(state.id);
|
1937
|
+
let targetBranch = branchId;
|
1938
|
+
if (position === "previous") {
|
1939
|
+
targetBranch = branches[state.branchNumber - 2];
|
1940
|
+
} else if (position === "next") {
|
1941
|
+
targetBranch = branches[state.branchNumber];
|
1942
|
+
}
|
1943
|
+
if (!targetBranch) throw new Error("Branch not found");
|
1944
|
+
this._threadBinding.getState().switchToBranch(targetBranch);
|
1945
|
+
}
|
1946
|
+
subscribe(callback) {
|
1947
|
+
return this._core.subscribe(callback);
|
1948
|
+
}
|
1949
|
+
unstable_getContentPartByIndex(idx) {
|
1950
|
+
if (idx < 0) throw new Error("Message index must be >= 0");
|
1951
|
+
return new ContentPartRuntime(
|
1952
|
+
new ShallowMemoizeSubject({
|
1953
|
+
getState: () => {
|
1954
|
+
return getContentPartState(this.getState(), idx);
|
1955
|
+
},
|
1956
|
+
subscribe: (callback) => this._core.subscribe(callback)
|
1957
|
+
}),
|
1958
|
+
this._core,
|
1959
|
+
this._threadBinding
|
1960
|
+
);
|
1961
|
+
}
|
1962
|
+
};
|
1963
|
+
|
1964
|
+
// src/primitives/message/MessageContent.tsx
|
1965
|
+
import { jsx as jsx21, jsxs as jsxs2 } from "react/jsx-runtime";
|
1966
|
+
var ToolUIDisplay = ({
|
1967
|
+
UI,
|
1968
|
+
...props
|
1969
|
+
}) => {
|
1970
|
+
const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? UI;
|
1971
|
+
if (!Render) return null;
|
1972
|
+
return /* @__PURE__ */ jsx21(Render, { ...props });
|
1973
|
+
};
|
1974
|
+
var defaultComponents = {
|
1975
|
+
Text: () => /* @__PURE__ */ jsxs2("p", { style: { whiteSpace: "pre-line" }, children: [
|
1976
|
+
/* @__PURE__ */ jsx21(ContentPartPrimitiveText, {}),
|
1977
|
+
/* @__PURE__ */ jsx21(ContentPartPrimitiveInProgress, { children: /* @__PURE__ */ jsx21("span", { style: { fontFamily: "revert" }, children: " \u25CF" }) })
|
1978
|
+
] }),
|
1979
|
+
Image: () => /* @__PURE__ */ jsx21(ContentPartPrimitiveImage, {}),
|
1980
|
+
UI: () => /* @__PURE__ */ jsx21(ContentPartPrimitiveDisplay, {})
|
1981
|
+
};
|
1982
|
+
var MessageContentPartComponent = ({
|
1983
|
+
components: {
|
1984
|
+
Text: Text2 = defaultComponents.Text,
|
1985
|
+
Empty,
|
1743
1986
|
Image: Image2 = defaultComponents.Image,
|
1744
1987
|
UI = defaultComponents.UI,
|
1745
1988
|
tools: { by_name = {}, Fallback: Fallback2 = void 0 } = {}
|
@@ -1747,41 +1990,33 @@ var MessageContentPartComponent = ({
|
|
1747
1990
|
}) => {
|
1748
1991
|
const messageStore = useMessageStore();
|
1749
1992
|
const threadRuntime = useThreadRuntime();
|
1750
|
-
const
|
1993
|
+
const part = useContentPart();
|
1751
1994
|
const type = part.type;
|
1752
1995
|
switch (type) {
|
1753
1996
|
case "text":
|
1754
|
-
if (status.type === "requires-action")
|
1997
|
+
if (part.status.type === "requires-action")
|
1755
1998
|
throw new Error("Encountered unexpected requires-action status");
|
1756
|
-
if (part === EMPTY_CONTENT && !!Empty) {
|
1757
|
-
return /* @__PURE__ */
|
1999
|
+
if (part.part === EMPTY_CONTENT && !!Empty) {
|
2000
|
+
return /* @__PURE__ */ jsx21(Empty, { status: part.status });
|
1758
2001
|
}
|
1759
|
-
return /* @__PURE__ */
|
2002
|
+
return /* @__PURE__ */ jsx21(Text2, { ...part, part });
|
1760
2003
|
case "image":
|
1761
|
-
if (status.type === "requires-action")
|
2004
|
+
if (part.status.type === "requires-action")
|
1762
2005
|
throw new Error("Encountered unexpected requires-action status");
|
1763
|
-
return /* @__PURE__ */
|
2006
|
+
return /* @__PURE__ */ jsx21(Image2, { ...part, part });
|
1764
2007
|
case "ui":
|
1765
|
-
if (status.type === "requires-action")
|
2008
|
+
if (part.status.type === "requires-action")
|
1766
2009
|
throw new Error("Encountered unexpected requires-action status");
|
1767
|
-
return /* @__PURE__ */
|
2010
|
+
return /* @__PURE__ */ jsx21(UI, { ...part, part });
|
1768
2011
|
case "tool-call": {
|
1769
2012
|
const Tool = by_name[part.toolName] || Fallback2;
|
1770
2013
|
const addResult = (result) => threadRuntime.addToolResult({
|
1771
|
-
messageId: messageStore.getState().
|
2014
|
+
messageId: messageStore.getState().id,
|
1772
2015
|
toolName: part.toolName,
|
1773
2016
|
toolCallId: part.toolCallId,
|
1774
2017
|
result
|
1775
2018
|
});
|
1776
|
-
return /* @__PURE__ */
|
1777
|
-
ToolUIDisplay,
|
1778
|
-
{
|
1779
|
-
UI: Tool,
|
1780
|
-
part,
|
1781
|
-
status,
|
1782
|
-
addResult
|
1783
|
-
}
|
1784
|
-
);
|
2019
|
+
return /* @__PURE__ */ jsx21(ToolUIDisplay, { ...part, part, UI: Tool, addResult });
|
1785
2020
|
}
|
1786
2021
|
default:
|
1787
2022
|
const unhandledType = type;
|
@@ -1792,7 +2027,12 @@ var MessageContentPartImpl = ({
|
|
1792
2027
|
partIndex,
|
1793
2028
|
components
|
1794
2029
|
}) => {
|
1795
|
-
|
2030
|
+
const messageRuntime = useMessageRuntime();
|
2031
|
+
const runtime = useMemo6(
|
2032
|
+
() => messageRuntime.unstable_getContentPartByIndex(partIndex),
|
2033
|
+
[messageRuntime, partIndex]
|
2034
|
+
);
|
2035
|
+
return /* @__PURE__ */ jsx21(ContentPartRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx21(MessageContentPartComponent, { components }) });
|
1796
2036
|
};
|
1797
2037
|
var MessageContentPart = memo2(
|
1798
2038
|
MessageContentPartImpl,
|
@@ -1801,8 +2041,8 @@ var MessageContentPart = memo2(
|
|
1801
2041
|
var MessagePrimitiveContent = ({
|
1802
2042
|
components
|
1803
2043
|
}) => {
|
1804
|
-
const contentLength = useMessage((s) => s.
|
1805
|
-
return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */
|
2044
|
+
const contentLength = useMessage((s) => s.content.length) || 1;
|
2045
|
+
return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ jsx21(MessageContentPart, { partIndex: index, components }, index));
|
1806
2046
|
};
|
1807
2047
|
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
1808
2048
|
|
@@ -1861,9 +2101,9 @@ var {
|
|
1861
2101
|
|
1862
2102
|
// src/context/providers/MessageAttachmentProvider.tsx
|
1863
2103
|
import { useEffect as useEffect10, useState as useState8 } from "react";
|
1864
|
-
import { create as
|
1865
|
-
import { jsx as
|
1866
|
-
var getAttachment = (
|
2104
|
+
import { create as create8 } from "zustand";
|
2105
|
+
import { jsx as jsx22 } from "react/jsx-runtime";
|
2106
|
+
var getAttachment = (message, useAttachment2, partIndex) => {
|
1867
2107
|
if (message.role !== "user") return null;
|
1868
2108
|
const attachments = message.attachments;
|
1869
2109
|
const attachment = attachments[partIndex];
|
@@ -1876,7 +2116,7 @@ var useMessageAttachmentContext2 = (partIndex) => {
|
|
1876
2116
|
const messageStore = useMessageStore();
|
1877
2117
|
const [context] = useState8(
|
1878
2118
|
() => {
|
1879
|
-
const useAttachment2 =
|
2119
|
+
const useAttachment2 = create8(
|
1880
2120
|
() => getAttachment(messageStore.getState(), void 0, partIndex)
|
1881
2121
|
);
|
1882
2122
|
return { type: "message", useAttachment: useAttachment2 };
|
@@ -1902,11 +2142,11 @@ var MessageAttachmentProvider = ({
|
|
1902
2142
|
children
|
1903
2143
|
}) => {
|
1904
2144
|
const context = useMessageAttachmentContext2(partIndex);
|
1905
|
-
return /* @__PURE__ */
|
2145
|
+
return /* @__PURE__ */ jsx22(AttachmentContext.Provider, { value: context, children });
|
1906
2146
|
};
|
1907
2147
|
|
1908
2148
|
// src/primitives/message/MessageAttachments.tsx
|
1909
|
-
import { jsx as
|
2149
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
1910
2150
|
var getComponent = (components, attachment) => {
|
1911
2151
|
const type = attachment.type;
|
1912
2152
|
switch (type) {
|
@@ -1926,10 +2166,10 @@ var AttachmentComponent = ({ components }) => {
|
|
1926
2166
|
(a) => getComponent(components, a.attachment)
|
1927
2167
|
);
|
1928
2168
|
if (!Component) return null;
|
1929
|
-
return /* @__PURE__ */
|
2169
|
+
return /* @__PURE__ */ jsx23(Component, {});
|
1930
2170
|
};
|
1931
2171
|
var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
|
1932
|
-
return /* @__PURE__ */
|
2172
|
+
return /* @__PURE__ */ jsx23(MessageAttachmentProvider, { attachmentIndex, children: /* @__PURE__ */ jsx23(AttachmentComponent, { components }) });
|
1933
2173
|
};
|
1934
2174
|
var MessageAttachment = memo3(
|
1935
2175
|
MessageAttachmentImpl,
|
@@ -1940,7 +2180,7 @@ var MessagePrimitiveAttachments = ({ components }) => {
|
|
1940
2180
|
if (message.role !== "user") return 0;
|
1941
2181
|
return message.attachments.length;
|
1942
2182
|
});
|
1943
|
-
return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */
|
2183
|
+
return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx23(
|
1944
2184
|
MessageAttachment,
|
1945
2185
|
{
|
1946
2186
|
attachmentIndex: index,
|
@@ -1952,9 +2192,9 @@ var MessagePrimitiveAttachments = ({ components }) => {
|
|
1952
2192
|
MessagePrimitiveAttachments.displayName = "MessagePrimitive.Attachments";
|
1953
2193
|
|
1954
2194
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1955
|
-
import { jsx as
|
2195
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
1956
2196
|
var BranchPickerPrimitiveRoot = forwardRef14(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1957
|
-
return /* @__PURE__ */
|
2197
|
+
return /* @__PURE__ */ jsx24(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx24(Primitive9.div, { ...rest, ref }) });
|
1958
2198
|
});
|
1959
2199
|
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
1960
2200
|
|
@@ -1976,7 +2216,7 @@ import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
|
|
1976
2216
|
import {
|
1977
2217
|
forwardRef as forwardRef15
|
1978
2218
|
} from "react";
|
1979
|
-
import { jsx as
|
2219
|
+
import { jsx as jsx25 } from "react/jsx-runtime";
|
1980
2220
|
var ComposerPrimitiveRoot = forwardRef15(({ onSubmit, ...rest }, forwardedRef) => {
|
1981
2221
|
const send = useComposerSend();
|
1982
2222
|
const handleSubmit = (e) => {
|
@@ -1984,7 +2224,7 @@ var ComposerPrimitiveRoot = forwardRef15(({ onSubmit, ...rest }, forwardedRef) =
|
|
1984
2224
|
if (!send) return;
|
1985
2225
|
send();
|
1986
2226
|
};
|
1987
|
-
return /* @__PURE__ */
|
2227
|
+
return /* @__PURE__ */ jsx25(
|
1988
2228
|
Primitive10.form,
|
1989
2229
|
{
|
1990
2230
|
...rest,
|
@@ -2003,11 +2243,11 @@ import {
|
|
2003
2243
|
forwardRef as forwardRef16,
|
2004
2244
|
useCallback as useCallback19,
|
2005
2245
|
useEffect as useEffect11,
|
2006
|
-
useRef as
|
2246
|
+
useRef as useRef3
|
2007
2247
|
} from "react";
|
2008
2248
|
import TextareaAutosize from "react-textarea-autosize";
|
2009
2249
|
import { useEscapeKeydown as useEscapeKeydown2 } from "@radix-ui/react-use-escape-keydown";
|
2010
|
-
import { jsx as
|
2250
|
+
import { jsx as jsx26 } from "react/jsx-runtime";
|
2011
2251
|
var ComposerPrimitiveInput = forwardRef16(
|
2012
2252
|
({
|
2013
2253
|
autoFocus = false,
|
@@ -2027,7 +2267,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
2027
2267
|
});
|
2028
2268
|
const Component = asChild ? Slot : TextareaAutosize;
|
2029
2269
|
const isDisabled = useThread((t) => t.isDisabled) ?? disabledProp ?? false;
|
2030
|
-
const textareaRef =
|
2270
|
+
const textareaRef = useRef3(null);
|
2031
2271
|
const ref = useComposedRefs2(forwardedRef, textareaRef);
|
2032
2272
|
useEscapeKeydown2((e) => {
|
2033
2273
|
if (!cancelOnEscape) return;
|
@@ -2064,7 +2304,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
2064
2304
|
focus();
|
2065
2305
|
}
|
2066
2306
|
});
|
2067
|
-
return /* @__PURE__ */
|
2307
|
+
return /* @__PURE__ */ jsx26(
|
2068
2308
|
Component,
|
2069
2309
|
{
|
2070
2310
|
name: "input",
|
@@ -2107,8 +2347,8 @@ import { memo as memo4 } from "react";
|
|
2107
2347
|
|
2108
2348
|
// src/context/providers/ComposerAttachmentProvider.tsx
|
2109
2349
|
import { useEffect as useEffect12, useState as useState9 } from "react";
|
2110
|
-
import { create as
|
2111
|
-
import { jsx as
|
2350
|
+
import { create as create9 } from "zustand";
|
2351
|
+
import { jsx as jsx27 } from "react/jsx-runtime";
|
2112
2352
|
var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
|
2113
2353
|
const attachment = attachments[partIndex];
|
2114
2354
|
if (!attachment) return null;
|
@@ -2120,7 +2360,7 @@ var useComposerAttachmentContext2 = (partIndex) => {
|
|
2120
2360
|
const threadComposerStore = useThreadComposerStore();
|
2121
2361
|
const [context] = useState9(
|
2122
2362
|
() => {
|
2123
|
-
const useAttachment2 =
|
2363
|
+
const useAttachment2 = create9(
|
2124
2364
|
() => getAttachment2(threadComposerStore.getState(), void 0, partIndex)
|
2125
2365
|
);
|
2126
2366
|
return { type: "composer", useAttachment: useAttachment2 };
|
@@ -2143,11 +2383,11 @@ var useComposerAttachmentContext2 = (partIndex) => {
|
|
2143
2383
|
};
|
2144
2384
|
var ComposerAttachmentProvider = ({ attachmentIndex: partIndex, children }) => {
|
2145
2385
|
const context = useComposerAttachmentContext2(partIndex);
|
2146
|
-
return /* @__PURE__ */
|
2386
|
+
return /* @__PURE__ */ jsx27(AttachmentContext.Provider, { value: context, children });
|
2147
2387
|
};
|
2148
2388
|
|
2149
2389
|
// src/primitives/composer/ComposerAttachments.tsx
|
2150
|
-
import { jsx as
|
2390
|
+
import { jsx as jsx28 } from "react/jsx-runtime";
|
2151
2391
|
var getComponent2 = (components, attachment) => {
|
2152
2392
|
const type = attachment.type;
|
2153
2393
|
switch (type) {
|
@@ -2167,10 +2407,10 @@ var AttachmentComponent2 = ({ components }) => {
|
|
2167
2407
|
(a) => getComponent2(components, a.attachment)
|
2168
2408
|
);
|
2169
2409
|
if (!Component) return null;
|
2170
|
-
return /* @__PURE__ */
|
2410
|
+
return /* @__PURE__ */ jsx28(Component, {});
|
2171
2411
|
};
|
2172
2412
|
var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
|
2173
|
-
return /* @__PURE__ */
|
2413
|
+
return /* @__PURE__ */ jsx28(ComposerAttachmentProvider, { attachmentIndex, children: /* @__PURE__ */ jsx28(AttachmentComponent2, { components }) });
|
2174
2414
|
};
|
2175
2415
|
var ComposerAttachment = memo4(
|
2176
2416
|
ComposerAttachmentImpl,
|
@@ -2178,7 +2418,7 @@ var ComposerAttachment = memo4(
|
|
2178
2418
|
);
|
2179
2419
|
var ComposerPrimitiveAttachments = ({ components }) => {
|
2180
2420
|
const attachmentsCount = useThreadComposer((s) => s.attachments.length);
|
2181
|
-
return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */
|
2421
|
+
return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx28(
|
2182
2422
|
ComposerAttachment,
|
2183
2423
|
{
|
2184
2424
|
attachmentIndex: index,
|
@@ -2223,9 +2463,9 @@ __export(thread_exports, {
|
|
2223
2463
|
// src/primitives/thread/ThreadRoot.tsx
|
2224
2464
|
import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
|
2225
2465
|
import { forwardRef as forwardRef17 } from "react";
|
2226
|
-
import { jsx as
|
2466
|
+
import { jsx as jsx29 } from "react/jsx-runtime";
|
2227
2467
|
var ThreadPrimitiveRoot = forwardRef17((props, ref) => {
|
2228
|
-
return /* @__PURE__ */
|
2468
|
+
return /* @__PURE__ */ jsx29(Primitive11.div, { ...props, ref });
|
2229
2469
|
});
|
2230
2470
|
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
2231
2471
|
|
@@ -2255,7 +2495,7 @@ import { forwardRef as forwardRef18 } from "react";
|
|
2255
2495
|
|
2256
2496
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
2257
2497
|
import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
|
2258
|
-
import { useRef as
|
2498
|
+
import { useRef as useRef4 } from "react";
|
2259
2499
|
|
2260
2500
|
// src/utils/hooks/useOnResizeContent.tsx
|
2261
2501
|
import { useCallbackRef as useCallbackRef3 } from "@radix-ui/react-use-callback-ref";
|
@@ -2314,10 +2554,10 @@ var useOnScrollToBottom = (callback) => {
|
|
2314
2554
|
var useThreadViewportAutoScroll = ({
|
2315
2555
|
autoScroll = true
|
2316
2556
|
}) => {
|
2317
|
-
const divRef =
|
2557
|
+
const divRef = useRef4(null);
|
2318
2558
|
const threadViewportStore = useThreadViewportStore();
|
2319
|
-
const lastScrollTop =
|
2320
|
-
const isScrollingToBottomRef =
|
2559
|
+
const lastScrollTop = useRef4(0);
|
2560
|
+
const isScrollingToBottomRef = useRef4(false);
|
2321
2561
|
const scrollToBottom = (behavior) => {
|
2322
2562
|
const div = divRef.current;
|
2323
2563
|
if (!div || !autoScroll) return;
|
@@ -2362,65 +2602,26 @@ var useThreadViewportAutoScroll = ({
|
|
2362
2602
|
};
|
2363
2603
|
|
2364
2604
|
// src/primitives/thread/ThreadViewport.tsx
|
2365
|
-
import { jsx as
|
2605
|
+
import { jsx as jsx30 } from "react/jsx-runtime";
|
2366
2606
|
var ThreadPrimitiveViewport = forwardRef18(({ autoScroll, children, ...rest }, forwardedRef) => {
|
2367
2607
|
const autoScrollRef = useThreadViewportAutoScroll({
|
2368
2608
|
autoScroll
|
2369
2609
|
});
|
2370
2610
|
const ref = useComposedRefs4(forwardedRef, autoScrollRef);
|
2371
|
-
return /* @__PURE__ */
|
2611
|
+
return /* @__PURE__ */ jsx30(Primitive12.div, { ...rest, ref, children });
|
2372
2612
|
});
|
2373
2613
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
2374
2614
|
|
2375
2615
|
// src/primitives/thread/ThreadMessages.tsx
|
2376
|
-
import { memo as memo5 } from "react";
|
2616
|
+
import { memo as memo5, useMemo as useMemo7 } from "react";
|
2377
2617
|
|
2378
|
-
// src/context/providers/
|
2618
|
+
// src/context/providers/MessageRuntimeProvider.tsx
|
2379
2619
|
import { useEffect as useEffect14, useState as useState10 } from "react";
|
2380
|
-
import { create as
|
2381
|
-
|
2382
|
-
// src/context/stores/EditComposer.ts
|
2383
|
-
import { create as create13 } from "zustand";
|
2384
|
-
var makeEditComposerStore = ({
|
2385
|
-
onEdit,
|
2386
|
-
onSend
|
2387
|
-
}) => create13()((set, get) => ({
|
2388
|
-
type: "edit",
|
2389
|
-
get value() {
|
2390
|
-
return get().text;
|
2391
|
-
},
|
2392
|
-
setValue(value) {
|
2393
|
-
get().setText(value);
|
2394
|
-
},
|
2395
|
-
text: "",
|
2396
|
-
setText: (text) => {
|
2397
|
-
set({ text, isEmpty: text.trim().length === 0 });
|
2398
|
-
},
|
2399
|
-
canCancel: false,
|
2400
|
-
isEditing: false,
|
2401
|
-
isEmpty: true,
|
2402
|
-
edit: () => {
|
2403
|
-
const text = onEdit();
|
2404
|
-
set({
|
2405
|
-
isEditing: true,
|
2406
|
-
canCancel: true,
|
2407
|
-
isEmpty: text.trim().length === 0,
|
2408
|
-
text
|
2409
|
-
});
|
2410
|
-
},
|
2411
|
-
send: () => {
|
2412
|
-
const text = get().text;
|
2413
|
-
set({ isEditing: false, canCancel: false });
|
2414
|
-
onSend(text);
|
2415
|
-
},
|
2416
|
-
cancel: () => {
|
2417
|
-
set({ isEditing: false, canCancel: false });
|
2418
|
-
}
|
2419
|
-
}));
|
2620
|
+
import { create as create11 } from "zustand";
|
2420
2621
|
|
2421
2622
|
// src/context/stores/MessageUtils.ts
|
2422
|
-
import { create as
|
2423
|
-
var makeMessageUtilsStore = () =>
|
2623
|
+
import { create as create10 } from "zustand";
|
2624
|
+
var makeMessageUtilsStore = () => create10((set) => {
|
2424
2625
|
let utterance = null;
|
2425
2626
|
return {
|
2426
2627
|
isCopied: false,
|
@@ -2449,89 +2650,54 @@ var makeMessageUtilsStore = () => create14((set) => {
|
|
2449
2650
|
};
|
2450
2651
|
});
|
2451
2652
|
|
2452
|
-
// src/context/providers/
|
2453
|
-
import { jsx as
|
2454
|
-
var
|
2455
|
-
|
2456
|
-
|
2457
|
-
|
2458
|
-
|
2459
|
-
|
2460
|
-
if (!message) return null;
|
2461
|
-
const isLast = getIsLast(messages, message);
|
2462
|
-
const branches = getBranches(message.id);
|
2463
|
-
const currentState = useMessage2?.getState();
|
2464
|
-
if (currentState && currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
|
2465
|
-
return null;
|
2466
|
-
return Object.freeze({
|
2467
|
-
message,
|
2468
|
-
parentId,
|
2469
|
-
branches,
|
2470
|
-
isLast
|
2471
|
-
});
|
2653
|
+
// src/context/providers/MessageRuntimeProvider.tsx
|
2654
|
+
import { jsx as jsx31 } from "react/jsx-runtime";
|
2655
|
+
var useMessageRuntimeStore = (runtime) => {
|
2656
|
+
const [store] = useState10(() => create11(() => runtime));
|
2657
|
+
useEffect14(() => {
|
2658
|
+
writableStore(store).setState(runtime, true);
|
2659
|
+
}, [runtime, store]);
|
2660
|
+
return store;
|
2472
2661
|
};
|
2473
|
-
var
|
2474
|
-
const
|
2475
|
-
const threadRuntime = useThreadRuntime();
|
2476
|
-
const [context] = useState10(() => {
|
2477
|
-
const useMessage2 = create15(
|
2478
|
-
() => getMessageState(
|
2479
|
-
threadMessagesStore.getState(),
|
2480
|
-
threadRuntime.getBranches.bind(threadRuntime),
|
2481
|
-
void 0,
|
2482
|
-
messageIndex
|
2483
|
-
)
|
2484
|
-
);
|
2485
|
-
const useMessageUtils2 = makeMessageUtilsStore();
|
2486
|
-
const useEditComposer2 = makeEditComposerStore({
|
2487
|
-
onEdit: () => {
|
2488
|
-
const message = useMessage2.getState().message;
|
2489
|
-
const text = getThreadMessageText(message);
|
2490
|
-
return text;
|
2491
|
-
},
|
2492
|
-
onSend: (text) => {
|
2493
|
-
const { message, parentId } = useMessage2.getState();
|
2494
|
-
const previousText = getThreadMessageText(message);
|
2495
|
-
if (previousText === text) return;
|
2496
|
-
const nonTextParts = message.content.filter(
|
2497
|
-
(part) => part.type !== "text" && part.type !== "ui"
|
2498
|
-
);
|
2499
|
-
threadRuntime.append({
|
2500
|
-
parentId,
|
2501
|
-
role: message.role,
|
2502
|
-
content: [{ type: "text", text }, ...nonTextParts],
|
2503
|
-
attachments: message.attachments
|
2504
|
-
});
|
2505
|
-
}
|
2506
|
-
});
|
2507
|
-
return { useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
|
2508
|
-
});
|
2662
|
+
var useMessageStore2 = (runtime) => {
|
2663
|
+
const [store] = useState10(() => create11(() => runtime.getState()));
|
2509
2664
|
useEffect14(() => {
|
2510
|
-
const
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
messageIndex
|
2516
|
-
);
|
2517
|
-
if (!newState) return;
|
2518
|
-
writableStore(context.useMessage).setState(newState, true);
|
2519
|
-
};
|
2520
|
-
syncMessage(threadMessagesStore.getState());
|
2521
|
-
return threadMessagesStore.subscribe(syncMessage);
|
2522
|
-
}, [threadMessagesStore, threadRuntime, context, messageIndex]);
|
2523
|
-
return context;
|
2665
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
2666
|
+
updateState();
|
2667
|
+
return runtime.subscribe(updateState);
|
2668
|
+
}, [runtime, store]);
|
2669
|
+
return store;
|
2524
2670
|
};
|
2525
|
-
var
|
2526
|
-
|
2671
|
+
var useMessageUtilsStore2 = () => {
|
2672
|
+
const [store] = useState10(() => makeMessageUtilsStore());
|
2673
|
+
return store;
|
2674
|
+
};
|
2675
|
+
var useEditComposerStore2 = (useMessageRuntime2) => {
|
2676
|
+
const runtime = useMessageRuntime2.getState().composer;
|
2677
|
+
const [store] = useState10(() => create11(() => runtime.getState()));
|
2678
|
+
useEffect14(() => {
|
2679
|
+
const updateState = () => writableStore(store).setState(runtime.getState());
|
2680
|
+
updateState();
|
2681
|
+
return runtime.subscribe(updateState);
|
2682
|
+
}, [runtime, store]);
|
2683
|
+
return store;
|
2684
|
+
};
|
2685
|
+
var MessageRuntimeProvider = ({
|
2686
|
+
runtime,
|
2527
2687
|
children
|
2528
2688
|
}) => {
|
2529
|
-
const
|
2530
|
-
|
2689
|
+
const useMessageRuntime2 = useMessageRuntimeStore(runtime);
|
2690
|
+
const useMessage2 = useMessageStore2(runtime);
|
2691
|
+
const useMessageUtils2 = useMessageUtilsStore2();
|
2692
|
+
const useEditComposer2 = useEditComposerStore2(useMessageRuntime2);
|
2693
|
+
const [context] = useState10(() => {
|
2694
|
+
return { useMessageRuntime: useMessageRuntime2, useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
|
2695
|
+
});
|
2696
|
+
return /* @__PURE__ */ jsx31(MessageContext.Provider, { value: context, children });
|
2531
2697
|
};
|
2532
2698
|
|
2533
2699
|
// src/primitives/thread/ThreadMessages.tsx
|
2534
|
-
import { jsx as
|
2700
|
+
import { jsx as jsx32 } from "react/jsx-runtime";
|
2535
2701
|
var isComponentsSame = (prev, next) => {
|
2536
2702
|
return prev.Message === next.Message && prev.EditComposer === next.EditComposer && prev.UserEditComposer === next.UserEditComposer && prev.AssistantEditComposer === next.AssistantEditComposer && prev.SystemEditComposer === next.SystemEditComposer && prev.UserMessage === next.UserMessage && prev.AssistantMessage === next.AssistantMessage && prev.SystemMessage === next.SystemMessage;
|
2537
2703
|
};
|
@@ -2564,16 +2730,21 @@ var getComponent3 = (components, role, isEditing) => {
|
|
2564
2730
|
var ThreadMessageComponent = ({
|
2565
2731
|
components
|
2566
2732
|
}) => {
|
2567
|
-
const role = useMessage((m) => m.
|
2733
|
+
const role = useMessage((m) => m.role);
|
2568
2734
|
const isEditing = useEditComposer((c) => c.isEditing);
|
2569
2735
|
const Component = getComponent3(components, role, isEditing);
|
2570
|
-
return /* @__PURE__ */
|
2736
|
+
return /* @__PURE__ */ jsx32(Component, {});
|
2571
2737
|
};
|
2572
2738
|
var ThreadMessageImpl = ({
|
2573
2739
|
messageIndex,
|
2574
2740
|
components
|
2575
2741
|
}) => {
|
2576
|
-
|
2742
|
+
const threadRuntime = useThreadRuntime();
|
2743
|
+
const runtime = useMemo7(
|
2744
|
+
() => threadRuntime.unstable_getMesssageByIndex(messageIndex),
|
2745
|
+
[threadRuntime, messageIndex]
|
2746
|
+
);
|
2747
|
+
return /* @__PURE__ */ jsx32(MessageRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx32(ThreadMessageComponent, { components }) });
|
2577
2748
|
};
|
2578
2749
|
var ThreadMessage = memo5(
|
2579
2750
|
ThreadMessageImpl,
|
@@ -2582,9 +2753,9 @@ var ThreadMessage = memo5(
|
|
2582
2753
|
var ThreadPrimitiveMessagesImpl = ({
|
2583
2754
|
components
|
2584
2755
|
}) => {
|
2585
|
-
const messagesLength =
|
2756
|
+
const messagesLength = useThread((t) => t.messages.length);
|
2586
2757
|
if (messagesLength === 0) return null;
|
2587
|
-
return Array.from({ length: messagesLength }, (_, index) => /* @__PURE__ */
|
2758
|
+
return Array.from({ length: messagesLength }, (_, index) => /* @__PURE__ */ jsx32(ThreadMessage, { messageIndex: index, components }, index));
|
2588
2759
|
};
|
2589
2760
|
ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
|
2590
2761
|
var ThreadPrimitiveMessages = memo5(
|
@@ -2626,7 +2797,7 @@ var subscribeToMainThread = (runtime, callback) => {
|
|
2626
2797
|
};
|
2627
2798
|
|
2628
2799
|
// src/runtimes/local/useLocalRuntime.tsx
|
2629
|
-
import { useInsertionEffect
|
2800
|
+
import { useInsertionEffect, useMemo as useMemo8, useState as useState12 } from "react";
|
2630
2801
|
|
2631
2802
|
// src/runtimes/core/BaseAssistantRuntimeCore.tsx
|
2632
2803
|
var BaseAssistantRuntimeCore = class {
|
@@ -2656,7 +2827,7 @@ var internal_exports = {};
|
|
2656
2827
|
__export(internal_exports, {
|
2657
2828
|
AssistantRuntime: () => AssistantRuntime,
|
2658
2829
|
BaseAssistantRuntimeCore: () => BaseAssistantRuntimeCore,
|
2659
|
-
|
2830
|
+
DefaultThreadComposerRuntimeCore: () => DefaultThreadComposerRuntimeCore,
|
2660
2831
|
MessageRepository: () => MessageRepository,
|
2661
2832
|
ProxyConfigProvider: () => ProxyConfigProvider,
|
2662
2833
|
ThreadRuntime: () => ThreadRuntime,
|
@@ -2667,45 +2838,20 @@ __export(internal_exports, {
|
|
2667
2838
|
withSmoothContextProvider: () => withSmoothContextProvider
|
2668
2839
|
});
|
2669
2840
|
|
2670
|
-
// src/runtimes/
|
2671
|
-
var
|
2672
|
-
|
2673
|
-
this.runtime = runtime;
|
2674
|
-
}
|
2675
|
-
_attachmentAdapter;
|
2841
|
+
// src/runtimes/composer/BaseComposerRuntimeCore.tsx
|
2842
|
+
var BaseComposerRuntimeCore = class {
|
2843
|
+
isEditing = true;
|
2676
2844
|
attachmentAccept = "*";
|
2677
|
-
get isEmpty() {
|
2678
|
-
return !this.text.trim() && !this.attachments.length;
|
2679
|
-
}
|
2680
|
-
setAttachmentAdapter(adapter) {
|
2681
|
-
this._attachmentAdapter = adapter;
|
2682
|
-
const accept = adapter?.accept ?? "*";
|
2683
|
-
if (this.attachmentAccept !== accept) {
|
2684
|
-
this.attachmentAccept = accept;
|
2685
|
-
return true;
|
2686
|
-
}
|
2687
|
-
return false;
|
2688
|
-
}
|
2689
2845
|
_attachments = [];
|
2846
|
+
set attachments(value) {
|
2847
|
+
this._attachments = value;
|
2848
|
+
this.notifySubscribers();
|
2849
|
+
}
|
2690
2850
|
get attachments() {
|
2691
2851
|
return this._attachments;
|
2692
2852
|
}
|
2693
|
-
|
2694
|
-
|
2695
|
-
throw new Error("Attachments are not supported");
|
2696
|
-
const attachment = await this._attachmentAdapter.add({ file });
|
2697
|
-
this._attachments = [...this._attachments, attachment];
|
2698
|
-
this.notifySubscribers();
|
2699
|
-
}
|
2700
|
-
async removeAttachment(attachmentId) {
|
2701
|
-
if (!this._attachmentAdapter)
|
2702
|
-
throw new Error("Attachments are not supported");
|
2703
|
-
const index = this._attachments.findIndex((a) => a.id === attachmentId);
|
2704
|
-
if (index === -1) throw new Error("Attachment not found");
|
2705
|
-
const attachment = this._attachments[index];
|
2706
|
-
await this._attachmentAdapter.remove(attachment);
|
2707
|
-
this._attachments = this._attachments.toSpliced(index, 1);
|
2708
|
-
this.notifySubscribers();
|
2853
|
+
get isEmpty() {
|
2854
|
+
return !this.text.trim() && !this.attachments.length;
|
2709
2855
|
}
|
2710
2856
|
_text = "";
|
2711
2857
|
get text() {
|
@@ -2726,13 +2872,39 @@ var BaseThreadComposerRuntimeCore = class {
|
|
2726
2872
|
async (a) => await this._attachmentAdapter.send(a)
|
2727
2873
|
)
|
2728
2874
|
) : [];
|
2729
|
-
|
2730
|
-
parentId: this.runtime.messages.at(-1)?.id ?? null,
|
2875
|
+
const message = {
|
2731
2876
|
role: "user",
|
2732
2877
|
content: this.text ? [{ type: "text", text: this.text }] : [],
|
2733
2878
|
attachments
|
2734
|
-
}
|
2879
|
+
};
|
2735
2880
|
this.reset();
|
2881
|
+
this.handleSend(message);
|
2882
|
+
}
|
2883
|
+
_attachmentAdapter;
|
2884
|
+
setAttachmentAdapter(adapter) {
|
2885
|
+
this._attachmentAdapter = adapter;
|
2886
|
+
const accept = adapter?.accept ?? "*";
|
2887
|
+
if (this.attachmentAccept !== accept) {
|
2888
|
+
this.attachmentAccept = accept;
|
2889
|
+
this.notifySubscribers();
|
2890
|
+
}
|
2891
|
+
}
|
2892
|
+
async addAttachment(file) {
|
2893
|
+
if (!this._attachmentAdapter)
|
2894
|
+
throw new Error("Attachments are not supported");
|
2895
|
+
const attachment = await this._attachmentAdapter.add({ file });
|
2896
|
+
this._attachments = [...this._attachments, attachment];
|
2897
|
+
this.notifySubscribers();
|
2898
|
+
}
|
2899
|
+
async removeAttachment(attachmentId) {
|
2900
|
+
if (!this._attachmentAdapter)
|
2901
|
+
throw new Error("Attachments are not supported");
|
2902
|
+
const index = this._attachments.findIndex((a) => a.id === attachmentId);
|
2903
|
+
if (index === -1) throw new Error("Attachment not found");
|
2904
|
+
const attachment = this._attachments[index];
|
2905
|
+
await this._attachmentAdapter.remove(attachment);
|
2906
|
+
this._attachments = this._attachments.toSpliced(index, 1);
|
2907
|
+
this.notifySubscribers();
|
2736
2908
|
}
|
2737
2909
|
_subscriptions = /* @__PURE__ */ new Set();
|
2738
2910
|
notifySubscribers() {
|
@@ -2744,6 +2916,36 @@ var BaseThreadComposerRuntimeCore = class {
|
|
2744
2916
|
}
|
2745
2917
|
};
|
2746
2918
|
|
2919
|
+
// src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx
|
2920
|
+
var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
2921
|
+
constructor(runtime) {
|
2922
|
+
super();
|
2923
|
+
this.runtime = runtime;
|
2924
|
+
this.connect();
|
2925
|
+
}
|
2926
|
+
_canCancel = false;
|
2927
|
+
get canCancel() {
|
2928
|
+
return this._canCancel;
|
2929
|
+
}
|
2930
|
+
connect() {
|
2931
|
+
return this.runtime.subscribe(() => {
|
2932
|
+
if (this.canCancel !== this.runtime.capabilities.cancel) {
|
2933
|
+
this._canCancel = this.runtime.capabilities.cancel;
|
2934
|
+
this.notifySubscribers();
|
2935
|
+
}
|
2936
|
+
});
|
2937
|
+
}
|
2938
|
+
async handleSend(message) {
|
2939
|
+
this.runtime.append({
|
2940
|
+
...message,
|
2941
|
+
parentId: this.runtime.messages.at(-1)?.id ?? null
|
2942
|
+
});
|
2943
|
+
}
|
2944
|
+
async cancel() {
|
2945
|
+
this.runtime.cancelRun();
|
2946
|
+
}
|
2947
|
+
};
|
2948
|
+
|
2747
2949
|
// src/utils/ProxyConfigProvider.ts
|
2748
2950
|
var ProxyConfigProvider = class {
|
2749
2951
|
_providers = /* @__PURE__ */ new Set();
|
@@ -2869,11 +3071,11 @@ var MessageRepository = class {
|
|
2869
3071
|
}
|
2870
3072
|
}
|
2871
3073
|
getMessages() {
|
2872
|
-
const
|
3074
|
+
const messages2 = new Array(this.head?.level ?? 0);
|
2873
3075
|
for (let current = this.head; current; current = current.prev) {
|
2874
|
-
|
3076
|
+
messages2[current.level] = current.current;
|
2875
3077
|
}
|
2876
|
-
return
|
3078
|
+
return messages2;
|
2877
3079
|
}
|
2878
3080
|
addOrUpdateMessage(parentId, message) {
|
2879
3081
|
const existingItem = this.messages.get(message.id);
|
@@ -2999,11 +3201,11 @@ var MessageRepository = class {
|
|
2999
3201
|
messages: exportItems
|
3000
3202
|
};
|
3001
3203
|
}
|
3002
|
-
import({ headId, messages }) {
|
3003
|
-
for (const { message, parentId } of
|
3204
|
+
import({ headId, messages: messages2 }) {
|
3205
|
+
for (const { message, parentId } of messages2) {
|
3004
3206
|
this.addOrUpdateMessage(parentId, message);
|
3005
3207
|
}
|
3006
|
-
this.resetHead(headId ??
|
3208
|
+
this.resetHead(headId ?? messages2.at(-1)?.message.id ?? null);
|
3007
3209
|
}
|
3008
3210
|
};
|
3009
3211
|
|
@@ -3018,7 +3220,7 @@ import {
|
|
3018
3220
|
forwardRef as forwardRef19
|
3019
3221
|
} from "react";
|
3020
3222
|
import classNames from "classnames";
|
3021
|
-
import { jsx as
|
3223
|
+
import { jsx as jsx33 } from "react/jsx-runtime";
|
3022
3224
|
var withDefaultProps = ({
|
3023
3225
|
className,
|
3024
3226
|
...defaultProps
|
@@ -3034,7 +3236,7 @@ var withDefaults = (Component, defaultProps) => {
|
|
3034
3236
|
const WithDefaults = forwardRef19(
|
3035
3237
|
(props, ref) => {
|
3036
3238
|
const ComponentAsAny = Component;
|
3037
|
-
return /* @__PURE__ */
|
3239
|
+
return /* @__PURE__ */ jsx33(ComponentAsAny, { ...getProps(props), ref });
|
3038
3240
|
}
|
3039
3241
|
);
|
3040
3242
|
WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
|
@@ -3042,9 +3244,9 @@ var withDefaults = (Component, defaultProps) => {
|
|
3042
3244
|
};
|
3043
3245
|
|
3044
3246
|
// src/ui/base/tooltip.tsx
|
3045
|
-
import { jsx as
|
3247
|
+
import { jsx as jsx34 } from "react/jsx-runtime";
|
3046
3248
|
var Tooltip = (props) => {
|
3047
|
-
return /* @__PURE__ */
|
3249
|
+
return /* @__PURE__ */ jsx34(TooltipPrimitive.Provider, { children: /* @__PURE__ */ jsx34(TooltipPrimitive.Root, { ...props }) });
|
3048
3250
|
};
|
3049
3251
|
Tooltip.displayName = "Tooltip";
|
3050
3252
|
var TooltipTrigger = TooltipPrimitive.Trigger;
|
@@ -3058,7 +3260,7 @@ TooltipContent.displayName = "TooltipContent";
|
|
3058
3260
|
import { cva } from "class-variance-authority";
|
3059
3261
|
import { Primitive as Primitive13 } from "@radix-ui/react-primitive";
|
3060
3262
|
import { forwardRef as forwardRef20 } from "react";
|
3061
|
-
import { jsx as
|
3263
|
+
import { jsx as jsx35 } from "react/jsx-runtime";
|
3062
3264
|
var buttonVariants = cva("aui-button", {
|
3063
3265
|
variants: {
|
3064
3266
|
variant: {
|
@@ -3078,7 +3280,7 @@ var buttonVariants = cva("aui-button", {
|
|
3078
3280
|
});
|
3079
3281
|
var Button = forwardRef20(
|
3080
3282
|
({ className, variant, size, ...props }, ref) => {
|
3081
|
-
return /* @__PURE__ */
|
3283
|
+
return /* @__PURE__ */ jsx35(
|
3082
3284
|
Primitive13.button,
|
3083
3285
|
{
|
3084
3286
|
className: buttonVariants({ variant, size, className }),
|
@@ -3091,78 +3293,18 @@ var Button = forwardRef20(
|
|
3091
3293
|
Button.displayName = "Button";
|
3092
3294
|
|
3093
3295
|
// src/ui/base/tooltip-icon-button.tsx
|
3094
|
-
import { jsx as
|
3296
|
+
import { jsx as jsx36, jsxs as jsxs3 } from "react/jsx-runtime";
|
3095
3297
|
var TooltipIconButton = forwardRef21(({ children, tooltip, side = "bottom", ...rest }, ref) => {
|
3096
3298
|
return /* @__PURE__ */ jsxs3(Tooltip, { children: [
|
3097
|
-
/* @__PURE__ */
|
3299
|
+
/* @__PURE__ */ jsx36(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs3(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
|
3098
3300
|
children,
|
3099
|
-
/* @__PURE__ */
|
3301
|
+
/* @__PURE__ */ jsx36("span", { className: "aui-sr-only", children: tooltip })
|
3100
3302
|
] }) }),
|
3101
|
-
/* @__PURE__ */
|
3303
|
+
/* @__PURE__ */ jsx36(TooltipContent, { side, children: tooltip })
|
3102
3304
|
] });
|
3103
3305
|
});
|
3104
3306
|
TooltipIconButton.displayName = "TooltipIconButton";
|
3105
3307
|
|
3106
|
-
// src/api/subscribable/BaseSubject.ts
|
3107
|
-
var BaseSubject = class {
|
3108
|
-
_subscriptions = /* @__PURE__ */ new Set();
|
3109
|
-
_connection;
|
3110
|
-
get isConnected() {
|
3111
|
-
return !!this._connection;
|
3112
|
-
}
|
3113
|
-
notifySubscribers() {
|
3114
|
-
for (const callback of this._subscriptions) callback();
|
3115
|
-
}
|
3116
|
-
_updateConnection() {
|
3117
|
-
if (this._subscriptions.size > 0) {
|
3118
|
-
if (this._connection) return;
|
3119
|
-
this._connection = this._connect();
|
3120
|
-
} else {
|
3121
|
-
this._connection?.();
|
3122
|
-
this._connection = void 0;
|
3123
|
-
}
|
3124
|
-
}
|
3125
|
-
subscribe(callback) {
|
3126
|
-
this._subscriptions.add(callback);
|
3127
|
-
this._updateConnection();
|
3128
|
-
return () => {
|
3129
|
-
this._subscriptions.delete(callback);
|
3130
|
-
this._updateConnection();
|
3131
|
-
};
|
3132
|
-
}
|
3133
|
-
};
|
3134
|
-
|
3135
|
-
// src/api/subscribable/NestedSubscriptionSubject.ts
|
3136
|
-
var NestedSubscriptionSubject = class extends BaseSubject {
|
3137
|
-
constructor(binding) {
|
3138
|
-
super();
|
3139
|
-
this.binding = binding;
|
3140
|
-
}
|
3141
|
-
getState() {
|
3142
|
-
return this.binding.getState();
|
3143
|
-
}
|
3144
|
-
_connect() {
|
3145
|
-
const callback = () => {
|
3146
|
-
this.notifySubscribers();
|
3147
|
-
};
|
3148
|
-
let lastState = this.binding.getState();
|
3149
|
-
let innerUnsubscribe = lastState.subscribe(callback);
|
3150
|
-
const onRuntimeUpdate = () => {
|
3151
|
-
const newState = this.binding.getState();
|
3152
|
-
if (newState === lastState) return;
|
3153
|
-
lastState = newState;
|
3154
|
-
innerUnsubscribe?.();
|
3155
|
-
innerUnsubscribe = this.binding.getState().subscribe(callback);
|
3156
|
-
callback();
|
3157
|
-
};
|
3158
|
-
const outerUnsubscribe = this.binding.subscribe(onRuntimeUpdate);
|
3159
|
-
return () => {
|
3160
|
-
outerUnsubscribe?.();
|
3161
|
-
innerUnsubscribe();
|
3162
|
-
};
|
3163
|
-
}
|
3164
|
-
};
|
3165
|
-
|
3166
3308
|
// src/api/AssistantRuntime.ts
|
3167
3309
|
var AssistantRuntime = class {
|
3168
3310
|
constructor(_core, CustomThreadRuntime) {
|
@@ -3179,63 +3321,22 @@ var AssistantRuntime = class {
|
|
3179
3321
|
return this._core.switchToNewThread();
|
3180
3322
|
}
|
3181
3323
|
switchToThread(threadId) {
|
3182
|
-
return this._core.switchToThread(threadId);
|
3183
|
-
}
|
3184
|
-
registerModelConfigProvider(provider) {
|
3185
|
-
return this._core.registerModelConfigProvider(provider);
|
3186
|
-
}
|
3187
|
-
// TODO events for thread switching
|
3188
|
-
/**
|
3189
|
-
* @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.
|
3190
|
-
*/
|
3191
|
-
subscribe(callback) {
|
3192
|
-
return this._core.subscribe(callback);
|
3193
|
-
}
|
3194
|
-
};
|
3195
|
-
|
3196
|
-
// src/api/ContentPartRuntime.ts
|
3197
|
-
var ContentPartRuntime = class {
|
3198
|
-
constructor(contentBinding, messageApi, threadApi) {
|
3199
|
-
this.contentBinding = contentBinding;
|
3200
|
-
this.messageApi = messageApi;
|
3201
|
-
this.threadApi = threadApi;
|
3202
|
-
}
|
3203
|
-
getState() {
|
3204
|
-
return this.contentBinding.getState();
|
3205
|
-
}
|
3206
|
-
addToolResult(result) {
|
3207
|
-
const message = this.messageApi.getState();
|
3208
|
-
if (!message) throw new Error("Message is not available");
|
3209
|
-
const state = this.contentBinding.getState();
|
3210
|
-
if (!state) throw new Error("Content part is not available");
|
3211
|
-
if (state.part.type !== "tool-call")
|
3212
|
-
throw new Error("Tried to add tool result to non-tool content part");
|
3213
|
-
const toolName = state.part.toolName;
|
3214
|
-
const toolCallId = state.part.toolCallId;
|
3215
|
-
this.threadApi.getState().addToolResult({
|
3216
|
-
messageId: message.message.id,
|
3217
|
-
toolName,
|
3218
|
-
toolCallId,
|
3219
|
-
result
|
3220
|
-
});
|
3324
|
+
return this._core.switchToThread(threadId);
|
3221
3325
|
}
|
3222
|
-
|
3223
|
-
|
3224
|
-
// src/api/subscribable/shallowEqual.ts
|
3225
|
-
function shallowEqual(objA, objB) {
|
3226
|
-
if (objA === void 0 && objB === void 0) return true;
|
3227
|
-
if (objA === void 0) return false;
|
3228
|
-
if (objB === void 0) return false;
|
3229
|
-
for (const key of Object.keys(objA)) {
|
3230
|
-
const valueA = objA[key];
|
3231
|
-
const valueB = objB[key];
|
3232
|
-
if (!Object.is(valueA, valueB)) return false;
|
3326
|
+
registerModelConfigProvider(provider) {
|
3327
|
+
return this._core.registerModelConfigProvider(provider);
|
3233
3328
|
}
|
3234
|
-
|
3235
|
-
|
3329
|
+
// TODO events for thread switching
|
3330
|
+
/**
|
3331
|
+
* @deprecated Thread is now static and never gets updated. This will be removed in 0.6.0.
|
3332
|
+
*/
|
3333
|
+
subscribe(callback) {
|
3334
|
+
return this._core.subscribe(callback);
|
3335
|
+
}
|
3336
|
+
};
|
3236
3337
|
|
3237
|
-
// src/api/subscribable/
|
3238
|
-
var
|
3338
|
+
// src/api/subscribable/LazyMemoizeSubject.ts
|
3339
|
+
var LazyMemoizeSubject = class extends BaseSubject {
|
3239
3340
|
constructor(binding) {
|
3240
3341
|
super();
|
3241
3342
|
this.binding = binding;
|
@@ -3244,261 +3345,59 @@ var ShallowMemoizeSubject = class extends BaseSubject {
|
|
3244
3345
|
throw new Error("Entry not available in the store");
|
3245
3346
|
this._previousState = state;
|
3246
3347
|
}
|
3348
|
+
_previousStateDirty = true;
|
3247
3349
|
_previousState;
|
3248
3350
|
getState = () => {
|
3249
|
-
if (!this.isConnected
|
3351
|
+
if (!this.isConnected || this._previousStateDirty) {
|
3352
|
+
const newState = this.binding.getState();
|
3353
|
+
if (newState !== void 0) {
|
3354
|
+
this._previousState = newState;
|
3355
|
+
}
|
3356
|
+
this._previousStateDirty = false;
|
3357
|
+
}
|
3250
3358
|
return this._previousState;
|
3251
3359
|
};
|
3252
|
-
_syncState() {
|
3253
|
-
const state = this.binding.getState();
|
3254
|
-
if (state === void 0) return false;
|
3255
|
-
if (shallowEqual(state, this._previousState)) return false;
|
3256
|
-
this._previousState = state;
|
3257
|
-
return true;
|
3258
|
-
}
|
3259
3360
|
_connect() {
|
3260
3361
|
const callback = () => {
|
3261
|
-
|
3262
|
-
|
3263
|
-
}
|
3362
|
+
this._previousStateDirty = true;
|
3363
|
+
this.notifySubscribers();
|
3264
3364
|
};
|
3265
3365
|
return this.binding.subscribe(callback);
|
3266
3366
|
}
|
3267
3367
|
};
|
3268
3368
|
|
3269
|
-
// src/api/MessageRuntime.ts
|
3270
|
-
var MessageState = class {
|
3271
|
-
constructor(snapshot) {
|
3272
|
-
this.snapshot = snapshot;
|
3273
|
-
}
|
3274
|
-
/**
|
3275
|
-
* @deprecated Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.
|
3276
|
-
*/
|
3277
|
-
get message() {
|
3278
|
-
return this.snapshot.message;
|
3279
|
-
}
|
3280
|
-
get id() {
|
3281
|
-
return this.snapshot.message.id;
|
3282
|
-
}
|
3283
|
-
get createdAt() {
|
3284
|
-
return this.snapshot.message.createdAt;
|
3285
|
-
}
|
3286
|
-
get role() {
|
3287
|
-
return this.snapshot.message.role;
|
3288
|
-
}
|
3289
|
-
get content() {
|
3290
|
-
return this.snapshot.message.content;
|
3291
|
-
}
|
3292
|
-
get attachments() {
|
3293
|
-
return this.snapshot.message.attachments;
|
3294
|
-
}
|
3295
|
-
get metadata() {
|
3296
|
-
return this.snapshot.message.metadata;
|
3297
|
-
}
|
3298
|
-
get status() {
|
3299
|
-
return this.snapshot.message.status;
|
3300
|
-
}
|
3301
|
-
get parentId() {
|
3302
|
-
return this.snapshot.parentId;
|
3303
|
-
}
|
3304
|
-
get isLast() {
|
3305
|
-
return this.snapshot.isLast;
|
3306
|
-
}
|
3307
|
-
get branches() {
|
3308
|
-
return this.snapshot.branches;
|
3309
|
-
}
|
3310
|
-
get branchNumber() {
|
3311
|
-
return this.snapshot.branchNumber;
|
3312
|
-
}
|
3313
|
-
get branchCount() {
|
3314
|
-
return this.snapshot.branchCount;
|
3315
|
-
}
|
3316
|
-
};
|
3317
|
-
var MessageRuntime = class {
|
3318
|
-
constructor(_core, _threadBinding) {
|
3319
|
-
this._core = _core;
|
3320
|
-
this._threadBinding = _threadBinding;
|
3321
|
-
}
|
3322
|
-
getState() {
|
3323
|
-
return new MessageState(this._core.getState());
|
3324
|
-
}
|
3325
|
-
// TODO improve type
|
3326
|
-
edit(message) {
|
3327
|
-
const state = this._core.getState();
|
3328
|
-
if (!state) throw new Error("Message is not available");
|
3329
|
-
this._threadBinding.getState().append({
|
3330
|
-
...message,
|
3331
|
-
parentId: state.parentId
|
3332
|
-
});
|
3333
|
-
}
|
3334
|
-
reload() {
|
3335
|
-
const state = this._core.getState();
|
3336
|
-
if (!state) throw new Error("Message is not available");
|
3337
|
-
this._threadBinding.getState().startRun(state.parentId);
|
3338
|
-
}
|
3339
|
-
speak() {
|
3340
|
-
const state = this._core.getState();
|
3341
|
-
if (!state) throw new Error("Message is not available");
|
3342
|
-
this._threadBinding.getState().speak(state.message.id);
|
3343
|
-
}
|
3344
|
-
submitFeedback({ type }) {
|
3345
|
-
const state = this._core.getState();
|
3346
|
-
if (!state) throw new Error("Message is not available");
|
3347
|
-
this._threadBinding.getState().submitFeedback({
|
3348
|
-
messageId: state.message.id,
|
3349
|
-
type
|
3350
|
-
});
|
3351
|
-
}
|
3352
|
-
switchToBranch({
|
3353
|
-
position,
|
3354
|
-
branchId
|
3355
|
-
}) {
|
3356
|
-
const state = this._core.getState();
|
3357
|
-
if (!state) throw new Error("Message is not available");
|
3358
|
-
if (branchId && position) {
|
3359
|
-
throw new Error("May not specify both branchId and position");
|
3360
|
-
} else if (!branchId && !position) {
|
3361
|
-
throw new Error("Must specify either branchId or position");
|
3362
|
-
}
|
3363
|
-
const thread = this._threadBinding.getState();
|
3364
|
-
const branches = thread.getBranches(state.message.id);
|
3365
|
-
let targetBranch = branchId;
|
3366
|
-
if (position === "previous") {
|
3367
|
-
targetBranch = branches[state.branchNumber - 2];
|
3368
|
-
} else if (position === "next") {
|
3369
|
-
targetBranch = branches[state.branchNumber];
|
3370
|
-
}
|
3371
|
-
if (!targetBranch) throw new Error("Branch not found");
|
3372
|
-
this._threadBinding.getState().switchToBranch(targetBranch);
|
3373
|
-
}
|
3374
|
-
subscribe(callback) {
|
3375
|
-
return this._core.subscribe(callback);
|
3376
|
-
}
|
3377
|
-
getContentPartByIdx(idx) {
|
3378
|
-
if (idx < 0) throw new Error("Message index must be >= 0");
|
3379
|
-
return new ContentPartRuntime(
|
3380
|
-
new ShallowMemoizeSubject({
|
3381
|
-
getState: () => {
|
3382
|
-
const state = this.getState();
|
3383
|
-
if (!state) return void 0;
|
3384
|
-
const message = state.message;
|
3385
|
-
const part = message.content[idx];
|
3386
|
-
if (!part) return void 0;
|
3387
|
-
return {
|
3388
|
-
part,
|
3389
|
-
status: toContentPartStatus(message, idx, part)
|
3390
|
-
};
|
3391
|
-
},
|
3392
|
-
subscribe: (callback) => this._core.subscribe(callback)
|
3393
|
-
}),
|
3394
|
-
this._core,
|
3395
|
-
this._threadBinding
|
3396
|
-
);
|
3397
|
-
}
|
3398
|
-
};
|
3399
|
-
|
3400
|
-
// src/api/ThreadComposerRuntime.ts
|
3401
|
-
var ComposerState = class {
|
3402
|
-
constructor(_composerBinding) {
|
3403
|
-
this._composerBinding = _composerBinding;
|
3404
|
-
}
|
3405
|
-
get isEmpty() {
|
3406
|
-
return this._composerBinding.getState().isEmpty;
|
3407
|
-
}
|
3408
|
-
get text() {
|
3409
|
-
return this._composerBinding.getState().text;
|
3410
|
-
}
|
3411
|
-
get attachmentAccept() {
|
3412
|
-
return this._composerBinding.getState().attachmentAccept;
|
3413
|
-
}
|
3414
|
-
get attachments() {
|
3415
|
-
return this._composerBinding.getState().attachments;
|
3416
|
-
}
|
3417
|
-
};
|
3418
|
-
var ThreadComposerRuntime = class {
|
3419
|
-
constructor(_core) {
|
3420
|
-
this._core = _core;
|
3421
|
-
this._state = new ComposerState(_core);
|
3422
|
-
}
|
3423
|
-
/**
|
3424
|
-
* @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
|
3425
|
-
*/
|
3426
|
-
get isEmpty() {
|
3427
|
-
return this._core.getState().isEmpty;
|
3428
|
-
}
|
3429
|
-
/**
|
3430
|
-
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
3431
|
-
*/
|
3432
|
-
get text() {
|
3433
|
-
return this._core.getState().text;
|
3434
|
-
}
|
3435
|
-
/**
|
3436
|
-
* @deprecated Use `getState().attachmentAccept` instead. This will be removed in 0.6.0.
|
3437
|
-
*/
|
3438
|
-
get attachmentAccept() {
|
3439
|
-
return this._core.getState().attachmentAccept;
|
3440
|
-
}
|
3441
|
-
// TODO should this instead return getAttachmentByIndex([idx]) instead?
|
3442
|
-
/**
|
3443
|
-
* @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
|
3444
|
-
*/
|
3445
|
-
get attachments() {
|
3446
|
-
return this._core.getState().attachments;
|
3447
|
-
}
|
3448
|
-
_state;
|
3449
|
-
getState() {
|
3450
|
-
return this._state;
|
3451
|
-
}
|
3452
|
-
setText(text) {
|
3453
|
-
this._core.getState().setText(text);
|
3454
|
-
}
|
3455
|
-
addAttachment(file) {
|
3456
|
-
return this._core.getState().addAttachment(file);
|
3457
|
-
}
|
3458
|
-
// /**
|
3459
|
-
// * @deprecated Use `getAttachmentById(id).removeAttachment` instead. This will be removed in 0.6.0.
|
3460
|
-
// */
|
3461
|
-
removeAttachment(attachmentId) {
|
3462
|
-
return this._core.getState().removeAttachment(attachmentId);
|
3463
|
-
}
|
3464
|
-
/**
|
3465
|
-
* @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
|
3466
|
-
*/
|
3467
|
-
reset() {
|
3468
|
-
this._core.getState().reset();
|
3469
|
-
}
|
3470
|
-
send() {
|
3471
|
-
this._core.getState().send();
|
3472
|
-
}
|
3473
|
-
subscribe(callback) {
|
3474
|
-
return this._core.subscribe(callback);
|
3475
|
-
}
|
3476
|
-
};
|
3477
|
-
|
3478
3369
|
// src/api/ThreadRuntime.ts
|
3479
|
-
var
|
3480
|
-
|
3481
|
-
|
3482
|
-
|
3483
|
-
|
3484
|
-
|
3485
|
-
|
3486
|
-
|
3487
|
-
return this._core.isDisabled;
|
3488
|
-
}
|
3489
|
-
get isRunning() {
|
3490
|
-
const messages = this._core.messages;
|
3491
|
-
const lastMessage = messages[messages.length - 1];
|
3492
|
-
return lastMessage?.role !== "assistant" ? false : lastMessage.status.type === "running";
|
3370
|
+
var toAppendMessage = (messages2, message) => {
|
3371
|
+
if (typeof message === "string") {
|
3372
|
+
return {
|
3373
|
+
parentId: messages2.at(-1)?.id ?? null,
|
3374
|
+
role: "user",
|
3375
|
+
content: [{ type: "text", text: message }],
|
3376
|
+
attachments: []
|
3377
|
+
};
|
3493
3378
|
}
|
3494
|
-
|
3495
|
-
return
|
3379
|
+
if (message.role && message.parentId && message.attachments) {
|
3380
|
+
return message;
|
3496
3381
|
}
|
3382
|
+
return {
|
3383
|
+
parentId: message.parentId ?? messages2.at(-1)?.id ?? null,
|
3384
|
+
role: message.role ?? "user",
|
3385
|
+
content: message.content,
|
3386
|
+
attachments: message.attachments ?? []
|
3387
|
+
};
|
3388
|
+
};
|
3389
|
+
var getThreadState = (runtime) => {
|
3390
|
+
const lastMessage = runtime.messages.at(-1);
|
3391
|
+
return Object.freeze({
|
3392
|
+
threadId: runtime.threadId,
|
3393
|
+
capabilities: runtime.capabilities,
|
3394
|
+
isDisabled: runtime.isDisabled,
|
3395
|
+
isRunning: lastMessage?.role !== "assistant" ? false : lastMessage.status.type === "running",
|
3396
|
+
messages: runtime.messages,
|
3397
|
+
unstable_synchronizer: runtime.unstable_synchronizer
|
3398
|
+
});
|
3497
3399
|
};
|
3498
3400
|
var ThreadRuntime = class {
|
3499
|
-
constructor(_threadBinding) {
|
3500
|
-
this._threadBinding = _threadBinding;
|
3501
|
-
}
|
3502
3401
|
// public path = "assistant.threads[main]"; // TODO
|
3503
3402
|
/**
|
3504
3403
|
* @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.
|
@@ -3524,24 +3423,40 @@ var ThreadRuntime = class {
|
|
3524
3423
|
get capabilities() {
|
3525
3424
|
return this.getState().capabilities;
|
3526
3425
|
}
|
3527
|
-
|
3426
|
+
/**
|
3427
|
+
* @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.
|
3428
|
+
*/
|
3528
3429
|
get messages() {
|
3529
3430
|
return this._threadBinding.getState().messages;
|
3530
3431
|
}
|
3531
3432
|
unstable_getCore() {
|
3532
3433
|
return this._threadBinding.getState();
|
3533
3434
|
}
|
3534
|
-
|
3435
|
+
_threadBinding;
|
3436
|
+
constructor(threadBinding) {
|
3437
|
+
const stateBinding = new LazyMemoizeSubject({
|
3438
|
+
getState: () => getThreadState(threadBinding.getState()),
|
3439
|
+
subscribe: (callback) => threadBinding.subscribe(callback)
|
3440
|
+
});
|
3441
|
+
this._threadBinding = {
|
3442
|
+
getState: () => threadBinding.getState(),
|
3443
|
+
getStateState: () => stateBinding.getState(),
|
3444
|
+
subscribe: (callback) => threadBinding.subscribe(callback)
|
3445
|
+
};
|
3446
|
+
}
|
3447
|
+
composer = new ComposerRuntime(
|
3535
3448
|
new NestedSubscriptionSubject({
|
3536
3449
|
getState: () => this._threadBinding.getState().composer,
|
3537
3450
|
subscribe: (callback) => this._threadBinding.subscribe(callback)
|
3538
3451
|
})
|
3539
3452
|
);
|
3540
3453
|
getState() {
|
3541
|
-
return
|
3454
|
+
return this._threadBinding.getStateState();
|
3542
3455
|
}
|
3543
3456
|
append(message) {
|
3544
|
-
this._threadBinding.getState().append(
|
3457
|
+
this._threadBinding.getState().append(
|
3458
|
+
toAppendMessage(this._threadBinding.getState().messages, message)
|
3459
|
+
);
|
3545
3460
|
}
|
3546
3461
|
subscribe(callback) {
|
3547
3462
|
return this._threadBinding.subscribe(callback);
|
@@ -3585,6 +3500,18 @@ var ThreadRuntime = class {
|
|
3585
3500
|
submitFeedback(options) {
|
3586
3501
|
return this._threadBinding.getState().submitFeedback(options);
|
3587
3502
|
}
|
3503
|
+
/**
|
3504
|
+
* @deprecated This is a temporary API. This will be removed in 0.6.0.
|
3505
|
+
*/
|
3506
|
+
getEditComposer(messageId) {
|
3507
|
+
return this._threadBinding.getState().getEditComposer(messageId);
|
3508
|
+
}
|
3509
|
+
/**
|
3510
|
+
* @deprecated This is a temporary API. This will be removed in 0.6.0.
|
3511
|
+
*/
|
3512
|
+
beginEdit(messageId) {
|
3513
|
+
return this._threadBinding.getState().beginEdit(messageId);
|
3514
|
+
}
|
3588
3515
|
export() {
|
3589
3516
|
return this._threadBinding.getState().export();
|
3590
3517
|
}
|
@@ -3596,14 +3523,15 @@ var ThreadRuntime = class {
|
|
3596
3523
|
return new MessageRuntime(
|
3597
3524
|
new ShallowMemoizeSubject({
|
3598
3525
|
getState: () => {
|
3599
|
-
const
|
3600
|
-
const message =
|
3526
|
+
const messages2 = this.messages;
|
3527
|
+
const message = messages2[idx];
|
3601
3528
|
if (!message) return void 0;
|
3602
3529
|
const branches = this._threadBinding.getState().getBranches(message.id);
|
3603
3530
|
return {
|
3531
|
+
...message,
|
3604
3532
|
message,
|
3605
|
-
isLast: idx ===
|
3606
|
-
parentId:
|
3533
|
+
isLast: idx === messages2.length - 1,
|
3534
|
+
parentId: messages2[idx - 1]?.id ?? null,
|
3607
3535
|
branches,
|
3608
3536
|
branchNumber: branches.indexOf(message.id) + 1,
|
3609
3537
|
branchCount: branches.length
|
@@ -3618,12 +3546,12 @@ var ThreadRuntime = class {
|
|
3618
3546
|
|
3619
3547
|
// src/runtimes/edge/converters/fromLanguageModelMessages.ts
|
3620
3548
|
var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
3621
|
-
const
|
3549
|
+
const messages2 = [];
|
3622
3550
|
for (const lmMessage of lm) {
|
3623
3551
|
const role = lmMessage.role;
|
3624
3552
|
switch (role) {
|
3625
3553
|
case "system": {
|
3626
|
-
|
3554
|
+
messages2.push({
|
3627
3555
|
role: "system",
|
3628
3556
|
content: [
|
3629
3557
|
{
|
@@ -3635,7 +3563,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3635
3563
|
break;
|
3636
3564
|
}
|
3637
3565
|
case "user": {
|
3638
|
-
|
3566
|
+
messages2.push({
|
3639
3567
|
role: "user",
|
3640
3568
|
content: lmMessage.content.map((part) => {
|
3641
3569
|
const type = part.type;
|
@@ -3678,20 +3606,20 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3678
3606
|
return part;
|
3679
3607
|
});
|
3680
3608
|
if (mergeRoundtrips) {
|
3681
|
-
const previousMessage =
|
3609
|
+
const previousMessage = messages2[messages2.length - 1];
|
3682
3610
|
if (previousMessage?.role === "assistant") {
|
3683
3611
|
previousMessage.content.push(...newContent);
|
3684
3612
|
break;
|
3685
3613
|
}
|
3686
3614
|
}
|
3687
|
-
|
3615
|
+
messages2.push({
|
3688
3616
|
role: "assistant",
|
3689
3617
|
content: newContent
|
3690
3618
|
});
|
3691
3619
|
break;
|
3692
3620
|
}
|
3693
3621
|
case "tool": {
|
3694
|
-
const previousMessage =
|
3622
|
+
const previousMessage = messages2[messages2.length - 1];
|
3695
3623
|
if (previousMessage?.role !== "assistant")
|
3696
3624
|
throw new Error(
|
3697
3625
|
"A tool message must be preceded by an assistant message."
|
@@ -3717,7 +3645,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3717
3645
|
}
|
3718
3646
|
}
|
3719
3647
|
}
|
3720
|
-
return
|
3648
|
+
return messages2;
|
3721
3649
|
};
|
3722
3650
|
|
3723
3651
|
// src/runtimes/edge/converters/fromLanguageModelTools.ts
|
@@ -3875,7 +3803,7 @@ var EdgeChatAdapter = class {
|
|
3875
3803
|
constructor(options) {
|
3876
3804
|
this.options = options;
|
3877
3805
|
}
|
3878
|
-
async *run({ messages, abortSignal, config }) {
|
3806
|
+
async *run({ messages: messages2, abortSignal, config }) {
|
3879
3807
|
const headers = new Headers(this.options.headers);
|
3880
3808
|
headers.set("Content-Type", "application/json");
|
3881
3809
|
const result = await fetch(this.options.api, {
|
@@ -3884,7 +3812,7 @@ var EdgeChatAdapter = class {
|
|
3884
3812
|
credentials: this.options.credentials ?? "same-origin",
|
3885
3813
|
body: JSON.stringify({
|
3886
3814
|
system: config.system,
|
3887
|
-
messages: toCoreMessages(
|
3815
|
+
messages: toCoreMessages(messages2),
|
3888
3816
|
tools: config.tools ? toLanguageModelTools(config.tools) : [],
|
3889
3817
|
...config.callSettings,
|
3890
3818
|
...config.config,
|
@@ -3923,6 +3851,43 @@ var useEdgeRuntime = ({
|
|
3923
3851
|
// src/runtimes/local/shouldContinue.tsx
|
3924
3852
|
var shouldContinue = (result) => result.status?.type === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
|
3925
3853
|
|
3854
|
+
// src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx
|
3855
|
+
var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
3856
|
+
constructor(runtime, endEditCallback, { parentId, message }) {
|
3857
|
+
super();
|
3858
|
+
this.runtime = runtime;
|
3859
|
+
this.endEditCallback = endEditCallback;
|
3860
|
+
this._parentId = parentId;
|
3861
|
+
this._previousText = getThreadMessageText(message);
|
3862
|
+
this.setText(this._previousText);
|
3863
|
+
this._nonTextParts = message.content.filter(
|
3864
|
+
(part) => part.type !== "text" && part.type !== "ui"
|
3865
|
+
);
|
3866
|
+
}
|
3867
|
+
get canCancel() {
|
3868
|
+
return true;
|
3869
|
+
}
|
3870
|
+
_nonTextParts;
|
3871
|
+
_previousText;
|
3872
|
+
_parentId;
|
3873
|
+
async handleSend(message) {
|
3874
|
+
const text = getThreadMessageText(message);
|
3875
|
+
if (text !== this._previousText) {
|
3876
|
+
this.runtime.append({
|
3877
|
+
...message,
|
3878
|
+
content: [...message.content, ...this._nonTextParts],
|
3879
|
+
parentId: this._parentId
|
3880
|
+
});
|
3881
|
+
}
|
3882
|
+
this.endEditCallback();
|
3883
|
+
this.notifySubscribers();
|
3884
|
+
}
|
3885
|
+
async cancel() {
|
3886
|
+
this.endEditCallback();
|
3887
|
+
this.notifySubscribers();
|
3888
|
+
}
|
3889
|
+
};
|
3890
|
+
|
3926
3891
|
// src/runtimes/local/LocalThreadRuntimeCore.tsx
|
3927
3892
|
var LocalThreadRuntimeCore = class {
|
3928
3893
|
constructor(configProvider, adapter, { initialMessages, ...options }) {
|
@@ -3932,8 +3897,8 @@ var LocalThreadRuntimeCore = class {
|
|
3932
3897
|
this.options = options;
|
3933
3898
|
if (initialMessages) {
|
3934
3899
|
let parentId = null;
|
3935
|
-
const
|
3936
|
-
for (const message of
|
3900
|
+
const messages2 = fromCoreMessages(initialMessages);
|
3901
|
+
for (const message of messages2) {
|
3937
3902
|
this.repository.addOrUpdateMessage(parentId, message);
|
3938
3903
|
parentId = message.id;
|
3939
3904
|
}
|
@@ -3957,7 +3922,7 @@ var LocalThreadRuntimeCore = class {
|
|
3957
3922
|
get messages() {
|
3958
3923
|
return this.repository.getMessages();
|
3959
3924
|
}
|
3960
|
-
composer = new
|
3925
|
+
composer = new DefaultThreadComposerRuntimeCore(this);
|
3961
3926
|
getModelConfig() {
|
3962
3927
|
return this.configProvider.getModelConfig();
|
3963
3928
|
}
|
@@ -3986,6 +3951,23 @@ var LocalThreadRuntimeCore = class {
|
|
3986
3951
|
}
|
3987
3952
|
if (hasUpdates) this.notifySubscribers();
|
3988
3953
|
}
|
3954
|
+
_editComposers = /* @__PURE__ */ new Map();
|
3955
|
+
getEditComposer(messageId) {
|
3956
|
+
return this._editComposers.get(messageId);
|
3957
|
+
}
|
3958
|
+
beginEdit(messageId) {
|
3959
|
+
if (this._editComposers.has(messageId))
|
3960
|
+
throw new Error("Edit already in progress");
|
3961
|
+
this._editComposers.set(
|
3962
|
+
messageId,
|
3963
|
+
new DefaultEditComposerRuntimeCore(
|
3964
|
+
this,
|
3965
|
+
() => this._editComposers.delete(messageId),
|
3966
|
+
this.repository.getMessage(messageId)
|
3967
|
+
)
|
3968
|
+
);
|
3969
|
+
this.notifySubscribers();
|
3970
|
+
}
|
3989
3971
|
getBranches(messageId) {
|
3990
3972
|
return this.repository.getBranches(messageId);
|
3991
3973
|
}
|
@@ -4020,7 +4002,7 @@ var LocalThreadRuntimeCore = class {
|
|
4020
4002
|
} while (shouldContinue(message));
|
4021
4003
|
}
|
4022
4004
|
async performRoundtrip(parentId, message) {
|
4023
|
-
const
|
4005
|
+
const messages2 = this.repository.getMessages();
|
4024
4006
|
this.abortController?.abort();
|
4025
4007
|
this.abortController = new AbortController();
|
4026
4008
|
const initialContent = message.content;
|
@@ -4075,7 +4057,7 @@ var LocalThreadRuntimeCore = class {
|
|
4075
4057
|
}
|
4076
4058
|
try {
|
4077
4059
|
const promiseOrGenerator = this.adapter.run({
|
4078
|
-
messages,
|
4060
|
+
messages: messages2,
|
4079
4061
|
abortSignal: this.abortController.signal,
|
4080
4062
|
config: this.configProvider.getModelConfig(),
|
4081
4063
|
onUpdate: updateMessage
|
@@ -4217,10 +4199,10 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
|
|
4217
4199
|
} = {}) {
|
4218
4200
|
this.switchToThread(null);
|
4219
4201
|
if (!initialMessages) return;
|
4220
|
-
const
|
4202
|
+
const messages2 = fromCoreMessages(initialMessages);
|
4221
4203
|
this.thread.import({
|
4222
|
-
messages:
|
4223
|
-
parentId:
|
4204
|
+
messages: messages2.map((m, idx) => ({
|
4205
|
+
parentId: messages2[idx - 1]?.id ?? null,
|
4224
4206
|
message: m
|
4225
4207
|
}))
|
4226
4208
|
});
|
@@ -4239,15 +4221,15 @@ var LocalRuntime = class extends AssistantRuntime {
|
|
4239
4221
|
};
|
4240
4222
|
var useLocalRuntime = (adapter, options = {}) => {
|
4241
4223
|
const [runtime] = useState12(() => new LocalRuntimeCore(adapter, options));
|
4242
|
-
|
4224
|
+
useInsertionEffect(() => {
|
4243
4225
|
runtime.thread.adapter = adapter;
|
4244
4226
|
runtime.thread.options = options;
|
4245
4227
|
});
|
4246
|
-
return
|
4228
|
+
return useMemo8(() => new LocalRuntime(runtime), [runtime]);
|
4247
4229
|
};
|
4248
4230
|
|
4249
4231
|
// src/runtimes/external-store/useExternalStoreRuntime.tsx
|
4250
|
-
import { useEffect as useEffect15, useMemo as
|
4232
|
+
import { useEffect as useEffect15, useMemo as useMemo9, useState as useState13 } from "react";
|
4251
4233
|
|
4252
4234
|
// src/runtimes/external-store/getExternalStoreMessage.tsx
|
4253
4235
|
var symbolInnerMessage = Symbol("innerMessage");
|
@@ -4258,8 +4240,8 @@ var getExternalStoreMessage = (message) => {
|
|
4258
4240
|
// src/runtimes/external-store/ThreadMessageConverter.ts
|
4259
4241
|
var ThreadMessageConverter = class {
|
4260
4242
|
cache = /* @__PURE__ */ new WeakMap();
|
4261
|
-
convertMessages(
|
4262
|
-
return
|
4243
|
+
convertMessages(messages2, converter) {
|
4244
|
+
return messages2.map((m, idx) => {
|
4263
4245
|
const cached = this.cache.get(m);
|
4264
4246
|
const newMessage = converter(cached, m, idx);
|
4265
4247
|
this.cache.set(m, newMessage);
|
@@ -4352,8 +4334,8 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
|
|
4352
4334
|
};
|
4353
4335
|
|
4354
4336
|
// src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx
|
4355
|
-
var hasUpcomingMessage = (isRunning,
|
4356
|
-
return isRunning &&
|
4337
|
+
var hasUpcomingMessage = (isRunning, messages2) => {
|
4338
|
+
return isRunning && messages2[messages2.length - 1]?.role !== "assistant";
|
4357
4339
|
};
|
4358
4340
|
var ExternalStoreThreadRuntimeCore = class {
|
4359
4341
|
constructor(configProvider, store) {
|
@@ -4381,7 +4363,24 @@ var ExternalStoreThreadRuntimeCore = class {
|
|
4381
4363
|
isDisabled;
|
4382
4364
|
converter = new ThreadMessageConverter();
|
4383
4365
|
_store;
|
4384
|
-
composer = new
|
4366
|
+
composer = new DefaultThreadComposerRuntimeCore(this);
|
4367
|
+
_editComposers = /* @__PURE__ */ new Map();
|
4368
|
+
getEditComposer(messageId) {
|
4369
|
+
return this._editComposers.get(messageId);
|
4370
|
+
}
|
4371
|
+
beginEdit(messageId) {
|
4372
|
+
if (this._editComposers.has(messageId))
|
4373
|
+
throw new Error("Edit already in progress");
|
4374
|
+
this._editComposers.set(
|
4375
|
+
messageId,
|
4376
|
+
new DefaultEditComposerRuntimeCore(
|
4377
|
+
this,
|
4378
|
+
() => this._editComposers.delete(messageId),
|
4379
|
+
this.repository.getMessage(messageId)
|
4380
|
+
)
|
4381
|
+
);
|
4382
|
+
this.notifySubscribers();
|
4383
|
+
}
|
4385
4384
|
get store() {
|
4386
4385
|
return this._store;
|
4387
4386
|
}
|
@@ -4412,7 +4411,7 @@ var ExternalStoreThreadRuntimeCore = class {
|
|
4412
4411
|
return;
|
4413
4412
|
}
|
4414
4413
|
}
|
4415
|
-
const
|
4414
|
+
const messages2 = !store.convertMessage ? store.messages : this.converter.convertMessages(store.messages, (cache, m, idx) => {
|
4416
4415
|
if (!store.convertMessage) return m;
|
4417
4416
|
const isLast = idx === store.messages.length - 1;
|
4418
4417
|
const autoStatus = getAutoStatus(isLast, isRunning);
|
@@ -4426,18 +4425,18 @@ var ExternalStoreThreadRuntimeCore = class {
|
|
4426
4425
|
newMessage[symbolInnerMessage] = m;
|
4427
4426
|
return newMessage;
|
4428
4427
|
});
|
4429
|
-
for (let i = 0; i <
|
4430
|
-
const message =
|
4431
|
-
const parent =
|
4428
|
+
for (let i = 0; i < messages2.length; i++) {
|
4429
|
+
const message = messages2[i];
|
4430
|
+
const parent = messages2[i - 1];
|
4432
4431
|
this.repository.addOrUpdateMessage(parent?.id ?? null, message);
|
4433
4432
|
}
|
4434
4433
|
if (this.assistantOptimisticId) {
|
4435
4434
|
this.repository.deleteMessage(this.assistantOptimisticId);
|
4436
4435
|
this.assistantOptimisticId = null;
|
4437
4436
|
}
|
4438
|
-
if (hasUpcomingMessage(isRunning,
|
4437
|
+
if (hasUpcomingMessage(isRunning, messages2)) {
|
4439
4438
|
this.assistantOptimisticId = this.repository.appendOptimisticMessage(
|
4440
|
-
|
4439
|
+
messages2.at(-1)?.id ?? null,
|
4441
4440
|
{
|
4442
4441
|
role: "assistant",
|
4443
4442
|
content: []
|
@@ -4445,7 +4444,7 @@ var ExternalStoreThreadRuntimeCore = class {
|
|
4445
4444
|
);
|
4446
4445
|
}
|
4447
4446
|
this.repository.resetHead(
|
4448
|
-
this.assistantOptimisticId ??
|
4447
|
+
this.assistantOptimisticId ?? messages2.at(-1)?.id ?? null
|
4449
4448
|
);
|
4450
4449
|
this.messages = this.repository.getMessages();
|
4451
4450
|
this.notifySubscribers();
|
@@ -4487,19 +4486,19 @@ var ExternalStoreThreadRuntimeCore = class {
|
|
4487
4486
|
this.repository.deleteMessage(this.assistantOptimisticId);
|
4488
4487
|
this.assistantOptimisticId = null;
|
4489
4488
|
}
|
4490
|
-
let
|
4491
|
-
const previousMessage =
|
4492
|
-
if (previousMessage?.role === "user" && previousMessage.id ===
|
4489
|
+
let messages2 = this.repository.getMessages();
|
4490
|
+
const previousMessage = messages2[messages2.length - 1];
|
4491
|
+
if (previousMessage?.role === "user" && previousMessage.id === messages2.at(-1)?.id) {
|
4493
4492
|
this.repository.deleteMessage(previousMessage.id);
|
4494
4493
|
if (!this.composer.text.trim()) {
|
4495
4494
|
this.composer.setText(getThreadMessageText(previousMessage));
|
4496
4495
|
}
|
4497
|
-
|
4496
|
+
messages2 = this.repository.getMessages();
|
4498
4497
|
} else {
|
4499
4498
|
this.notifySubscribers();
|
4500
4499
|
}
|
4501
4500
|
setTimeout(() => {
|
4502
|
-
this.updateMessages(
|
4501
|
+
this.updateMessages(messages2);
|
4503
4502
|
}, 0);
|
4504
4503
|
}
|
4505
4504
|
addToolResult(options) {
|
@@ -4523,9 +4522,9 @@ var ExternalStoreThreadRuntimeCore = class {
|
|
4523
4522
|
this._subscriptions.add(callback);
|
4524
4523
|
return () => this._subscriptions.delete(callback);
|
4525
4524
|
}
|
4526
|
-
updateMessages = (
|
4525
|
+
updateMessages = (messages2) => {
|
4527
4526
|
this._store.setMessages?.(
|
4528
|
-
|
4527
|
+
messages2.flatMap(getExternalStoreMessage).filter((m) => m != null)
|
4529
4528
|
);
|
4530
4529
|
};
|
4531
4530
|
import(repository) {
|
@@ -4587,17 +4586,17 @@ var useExternalStoreRuntime = (store) => {
|
|
4587
4586
|
useEffect15(() => {
|
4588
4587
|
runtime.thread.store = store;
|
4589
4588
|
});
|
4590
|
-
return
|
4589
|
+
return useMemo9(() => new AssistantRuntime(runtime, ThreadRuntime), [runtime]);
|
4591
4590
|
};
|
4592
4591
|
|
4593
4592
|
// src/runtimes/external-store/external-message-converter.tsx
|
4594
|
-
import { useMemo as
|
4595
|
-
var joinExternalMessages = (
|
4593
|
+
import { useMemo as useMemo10 } from "react";
|
4594
|
+
var joinExternalMessages = (messages2) => {
|
4596
4595
|
const assistantMessage = {
|
4597
4596
|
role: "assistant",
|
4598
4597
|
content: []
|
4599
4598
|
};
|
4600
|
-
for (const output of
|
4599
|
+
for (const output of messages2) {
|
4601
4600
|
if (output.role === "tool") {
|
4602
4601
|
const toolCallIdx = assistantMessage.content.findIndex(
|
4603
4602
|
(c) => c.type === "tool-call" && c.toolCallId === output.toolCallId
|
@@ -4620,19 +4619,18 @@ var joinExternalMessages = (messages) => {
|
|
4620
4619
|
);
|
4621
4620
|
}
|
4622
4621
|
} else {
|
4623
|
-
const content = output.content;
|
4624
4622
|
const role = output.role;
|
4625
4623
|
switch (role) {
|
4626
4624
|
case "system":
|
4627
4625
|
case "user":
|
4628
|
-
return
|
4626
|
+
return output;
|
4629
4627
|
case "assistant":
|
4630
4628
|
if (assistantMessage.content.length === 0) {
|
4631
4629
|
assistantMessage.id = output.id;
|
4632
4630
|
assistantMessage.createdAt ??= output.createdAt;
|
4633
4631
|
assistantMessage.status ??= output.status;
|
4634
4632
|
}
|
4635
|
-
assistantMessage.content.push(...content);
|
4633
|
+
assistantMessage.content.push(...output.content);
|
4636
4634
|
break;
|
4637
4635
|
default: {
|
4638
4636
|
const unsupportedRole = role;
|
@@ -4675,10 +4673,10 @@ var chunkExternalMessages = (callbackResults) => {
|
|
4675
4673
|
};
|
4676
4674
|
var useExternalMessageConverter = ({
|
4677
4675
|
callback,
|
4678
|
-
messages,
|
4676
|
+
messages: messages2,
|
4679
4677
|
isRunning
|
4680
4678
|
}) => {
|
4681
|
-
const state =
|
4679
|
+
const state = useMemo10(
|
4682
4680
|
() => ({
|
4683
4681
|
callback,
|
4684
4682
|
callbackCache: /* @__PURE__ */ new WeakMap(),
|
@@ -4687,9 +4685,9 @@ var useExternalMessageConverter = ({
|
|
4687
4685
|
}),
|
4688
4686
|
[callback]
|
4689
4687
|
);
|
4690
|
-
return
|
4688
|
+
return useMemo10(() => {
|
4691
4689
|
const callbackResults = [];
|
4692
|
-
for (const message of
|
4690
|
+
for (const message of messages2) {
|
4693
4691
|
let result = state.callbackCache.get(message);
|
4694
4692
|
if (!result) {
|
4695
4693
|
const output = state.callback(message);
|
@@ -4727,7 +4725,7 @@ var useExternalMessageConverter = ({
|
|
4727
4725
|
return newMessage;
|
4728
4726
|
}
|
4729
4727
|
);
|
4730
|
-
}, [state,
|
4728
|
+
}, [state, messages2, isRunning]);
|
4731
4729
|
};
|
4732
4730
|
var shallowArrayEqual = (a, b) => {
|
4733
4731
|
if (a.length !== b.length) return false;
|
@@ -4745,13 +4743,13 @@ var DangerousInBrowserAdapter = class {
|
|
4745
4743
|
constructor(options) {
|
4746
4744
|
this.options = options;
|
4747
4745
|
}
|
4748
|
-
async *run({ messages, abortSignal, config }) {
|
4746
|
+
async *run({ messages: messages2, abortSignal, config }) {
|
4749
4747
|
const res = await getEdgeRuntimeStream({
|
4750
4748
|
options: this.options,
|
4751
4749
|
abortSignal,
|
4752
4750
|
requestData: {
|
4753
4751
|
system: config.system,
|
4754
|
-
messages: toCoreMessages(
|
4752
|
+
messages: toCoreMessages(messages2),
|
4755
4753
|
tools: config.tools ? toLanguageModelTools(config.tools) : [],
|
4756
4754
|
...config.callSettings,
|
4757
4755
|
...config.config
|
@@ -4955,7 +4953,7 @@ import {
|
|
4955
4953
|
createContext as createContext7,
|
4956
4954
|
useContext as useContext4
|
4957
4955
|
} from "react";
|
4958
|
-
import { Fragment as Fragment3, jsx as
|
4956
|
+
import { Fragment as Fragment3, jsx as jsx37 } from "react/jsx-runtime";
|
4959
4957
|
var ThreadConfigContext = createContext7({});
|
4960
4958
|
var useThreadConfig = () => {
|
4961
4959
|
return useContext4(ThreadConfigContext);
|
@@ -4965,14 +4963,14 @@ var ThreadConfigProvider = ({
|
|
4965
4963
|
config
|
4966
4964
|
}) => {
|
4967
4965
|
const hasAssistant = !!useAssistantRuntime({ optional: true });
|
4968
|
-
const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */
|
4966
|
+
const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ jsx37(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx37(Fragment3, { children });
|
4969
4967
|
if (!config?.runtime) return configProvider;
|
4970
4968
|
if (hasAssistant) {
|
4971
4969
|
throw new Error(
|
4972
4970
|
"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
|
4973
4971
|
);
|
4974
4972
|
}
|
4975
|
-
return /* @__PURE__ */
|
4973
|
+
return /* @__PURE__ */ jsx37(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
|
4976
4974
|
};
|
4977
4975
|
ThreadConfigProvider.displayName = "ThreadConfigProvider";
|
4978
4976
|
|
@@ -4987,7 +4985,7 @@ import {
|
|
4987
4985
|
ThumbsDownIcon,
|
4988
4986
|
ThumbsUpIcon
|
4989
4987
|
} from "lucide-react";
|
4990
|
-
import { Fragment as Fragment4, jsx as
|
4988
|
+
import { Fragment as Fragment4, jsx as jsx38, jsxs as jsxs4 } from "react/jsx-runtime";
|
4991
4989
|
var useAllowCopy = (ensureCapability = false) => {
|
4992
4990
|
const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
|
4993
4991
|
const copySupported = useThread((t) => t.capabilities.unstable_copy);
|
@@ -5028,11 +5026,11 @@ var AssistantActionBar = () => {
|
|
5028
5026
|
autohide: "not-last",
|
5029
5027
|
autohideFloat: "single-branch",
|
5030
5028
|
children: [
|
5031
|
-
allowSpeak && /* @__PURE__ */
|
5032
|
-
allowCopy && /* @__PURE__ */
|
5033
|
-
allowReload && /* @__PURE__ */
|
5034
|
-
allowFeedbackPositive && /* @__PURE__ */
|
5035
|
-
allowFeedbackNegative && /* @__PURE__ */
|
5029
|
+
allowSpeak && /* @__PURE__ */ jsx38(AssistantActionBarSpeechControl, {}),
|
5030
|
+
allowCopy && /* @__PURE__ */ jsx38(AssistantActionBarCopy, {}),
|
5031
|
+
allowReload && /* @__PURE__ */ jsx38(AssistantActionBarReload, {}),
|
5032
|
+
allowFeedbackPositive && /* @__PURE__ */ jsx38(AssistantActionBarFeedbackPositive, {}),
|
5033
|
+
allowFeedbackNegative && /* @__PURE__ */ jsx38(AssistantActionBarFeedbackNegative, {})
|
5036
5034
|
]
|
5037
5035
|
}
|
5038
5036
|
);
|
@@ -5048,16 +5046,16 @@ var AssistantActionBarCopy = forwardRef22((props, ref) => {
|
|
5048
5046
|
assistantMessage: { copy: { tooltip = "Copy" } = {} } = {}
|
5049
5047
|
} = {}
|
5050
5048
|
} = useThreadConfig();
|
5051
|
-
return /* @__PURE__ */
|
5052
|
-
/* @__PURE__ */
|
5053
|
-
/* @__PURE__ */
|
5049
|
+
return /* @__PURE__ */ jsx38(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
5050
|
+
/* @__PURE__ */ jsx38(message_exports.If, { copied: true, children: /* @__PURE__ */ jsx38(CheckIcon, {}) }),
|
5051
|
+
/* @__PURE__ */ jsx38(message_exports.If, { copied: false, children: /* @__PURE__ */ jsx38(CopyIcon, {}) })
|
5054
5052
|
] }) }) });
|
5055
5053
|
});
|
5056
5054
|
AssistantActionBarCopy.displayName = "AssistantActionBarCopy";
|
5057
5055
|
var AssistantActionBarSpeechControl = () => {
|
5058
5056
|
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
5059
|
-
/* @__PURE__ */
|
5060
|
-
/* @__PURE__ */
|
5057
|
+
/* @__PURE__ */ jsx38(message_exports.If, { speaking: false, children: /* @__PURE__ */ jsx38(AssistantActionBarSpeak, {}) }),
|
5058
|
+
/* @__PURE__ */ jsx38(message_exports.If, { speaking: true, children: /* @__PURE__ */ jsx38(AssistantActionBarStopSpeaking, {}) })
|
5061
5059
|
] });
|
5062
5060
|
};
|
5063
5061
|
var AssistantActionBarSpeak = forwardRef22((props, ref) => {
|
@@ -5067,7 +5065,7 @@ var AssistantActionBarSpeak = forwardRef22((props, ref) => {
|
|
5067
5065
|
} = {}
|
5068
5066
|
} = useThreadConfig();
|
5069
5067
|
const allowSpeak = useAllowSpeak();
|
5070
|
-
return /* @__PURE__ */
|
5068
|
+
return /* @__PURE__ */ jsx38(actionBar_exports.Speak, { disabled: !allowSpeak, asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(AudioLinesIcon, {}) }) });
|
5071
5069
|
});
|
5072
5070
|
AssistantActionBarSpeak.displayName = "AssistantActionBarSpeak";
|
5073
5071
|
var AssistantActionBarStopSpeaking = forwardRef22((props, ref) => {
|
@@ -5079,7 +5077,7 @@ var AssistantActionBarStopSpeaking = forwardRef22((props, ref) => {
|
|
5079
5077
|
} = {}
|
5080
5078
|
} = useThreadConfig();
|
5081
5079
|
const allowSpeak = useAllowSpeak();
|
5082
|
-
return /* @__PURE__ */
|
5080
|
+
return /* @__PURE__ */ jsx38(actionBar_exports.StopSpeaking, { disabled: !allowSpeak, asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip: stopTooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(StopCircleIcon, {}) }) });
|
5083
5081
|
});
|
5084
5082
|
AssistantActionBarStopSpeaking.displayName = "AssistantActionBarStopSpeaking";
|
5085
5083
|
var AssistantActionBarReload = forwardRef22((props, ref) => {
|
@@ -5089,7 +5087,7 @@ var AssistantActionBarReload = forwardRef22((props, ref) => {
|
|
5089
5087
|
} = {}
|
5090
5088
|
} = useThreadConfig();
|
5091
5089
|
const allowReload = useAllowReload();
|
5092
|
-
return /* @__PURE__ */
|
5090
|
+
return /* @__PURE__ */ jsx38(actionBar_exports.Reload, { disabled: !allowReload, asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(RefreshCwIcon, {}) }) });
|
5093
5091
|
});
|
5094
5092
|
AssistantActionBarReload.displayName = "AssistantActionBarReload";
|
5095
5093
|
var AssistantActionBarFeedbackPositive = forwardRef22((props, ref) => {
|
@@ -5101,13 +5099,13 @@ var AssistantActionBarFeedbackPositive = forwardRef22((props, ref) => {
|
|
5101
5099
|
} = {}
|
5102
5100
|
} = useThreadConfig();
|
5103
5101
|
const allowFeedbackPositive = useAllowFeedbackPositive();
|
5104
|
-
return /* @__PURE__ */
|
5102
|
+
return /* @__PURE__ */ jsx38(
|
5105
5103
|
actionBar_exports.FeedbackPositive,
|
5106
5104
|
{
|
5107
5105
|
disabled: !allowFeedbackPositive,
|
5108
5106
|
className: "aui-assistant-action-bar-feedback-positive",
|
5109
5107
|
asChild: true,
|
5110
|
-
children: /* @__PURE__ */
|
5108
|
+
children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(ThumbsUpIcon, {}) })
|
5111
5109
|
}
|
5112
5110
|
);
|
5113
5111
|
});
|
@@ -5121,13 +5119,13 @@ var AssistantActionBarFeedbackNegative = forwardRef22((props, ref) => {
|
|
5121
5119
|
} = {}
|
5122
5120
|
} = useThreadConfig();
|
5123
5121
|
const allowFeedbackNegative = useAllowFeedbackNegative();
|
5124
|
-
return /* @__PURE__ */
|
5122
|
+
return /* @__PURE__ */ jsx38(
|
5125
5123
|
actionBar_exports.FeedbackNegative,
|
5126
5124
|
{
|
5127
5125
|
disabled: !allowFeedbackNegative,
|
5128
5126
|
className: "aui-assistant-action-bar-feedback-negative",
|
5129
5127
|
asChild: true,
|
5130
|
-
children: /* @__PURE__ */
|
5128
|
+
children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(ThumbsDownIcon, {}) })
|
5131
5129
|
}
|
5132
5130
|
);
|
5133
5131
|
});
|
@@ -5148,12 +5146,12 @@ var assistant_action_bar_default = Object.assign(
|
|
5148
5146
|
);
|
5149
5147
|
|
5150
5148
|
// src/ui/assistant-message.tsx
|
5151
|
-
import { forwardRef as forwardRef24, useMemo as
|
5149
|
+
import { forwardRef as forwardRef24, useMemo as useMemo11 } from "react";
|
5152
5150
|
|
5153
5151
|
// src/ui/branch-picker.tsx
|
5154
5152
|
import { forwardRef as forwardRef23 } from "react";
|
5155
5153
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
5156
|
-
import { jsx as
|
5154
|
+
import { jsx as jsx39, jsxs as jsxs5 } from "react/jsx-runtime";
|
5157
5155
|
var useAllowBranchPicker = (ensureCapability = false) => {
|
5158
5156
|
const { branchPicker: { allowBranchPicker = true } = {} } = useThreadConfig();
|
5159
5157
|
const branchPickerSupported = useThread((t) => t.capabilities.edit);
|
@@ -5163,9 +5161,9 @@ var BranchPicker = () => {
|
|
5163
5161
|
const allowBranchPicker = useAllowBranchPicker();
|
5164
5162
|
if (!allowBranchPicker) return null;
|
5165
5163
|
return /* @__PURE__ */ jsxs5(BranchPickerRoot, { hideWhenSingleBranch: true, children: [
|
5166
|
-
/* @__PURE__ */
|
5167
|
-
/* @__PURE__ */
|
5168
|
-
/* @__PURE__ */
|
5164
|
+
/* @__PURE__ */ jsx39(BranchPickerPrevious2, {}),
|
5165
|
+
/* @__PURE__ */ jsx39(BranchPickerState, {}),
|
5166
|
+
/* @__PURE__ */ jsx39(BranchPickerNext, {})
|
5169
5167
|
] });
|
5170
5168
|
};
|
5171
5169
|
BranchPicker.displayName = "BranchPicker";
|
@@ -5180,7 +5178,7 @@ var BranchPickerPrevious2 = forwardRef23((props, ref) => {
|
|
5180
5178
|
} = {}
|
5181
5179
|
} = useThreadConfig();
|
5182
5180
|
const allowBranchPicker = useAllowBranchPicker();
|
5183
|
-
return /* @__PURE__ */
|
5181
|
+
return /* @__PURE__ */ jsx39(branchPicker_exports.Previous, { disabled: !allowBranchPicker, asChild: true, children: /* @__PURE__ */ jsx39(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx39(ChevronLeftIcon, {}) }) });
|
5184
5182
|
});
|
5185
5183
|
BranchPickerPrevious2.displayName = "BranchPickerPrevious";
|
5186
5184
|
var BranchPickerStateWrapper = withDefaults("span", {
|
@@ -5188,9 +5186,9 @@ var BranchPickerStateWrapper = withDefaults("span", {
|
|
5188
5186
|
});
|
5189
5187
|
var BranchPickerState = forwardRef23((props, ref) => {
|
5190
5188
|
return /* @__PURE__ */ jsxs5(BranchPickerStateWrapper, { ...props, ref, children: [
|
5191
|
-
/* @__PURE__ */
|
5189
|
+
/* @__PURE__ */ jsx39(branchPicker_exports.Number, {}),
|
5192
5190
|
" / ",
|
5193
|
-
/* @__PURE__ */
|
5191
|
+
/* @__PURE__ */ jsx39(branchPicker_exports.Count, {})
|
5194
5192
|
] });
|
5195
5193
|
});
|
5196
5194
|
BranchPickerState.displayName = "BranchPickerState";
|
@@ -5199,7 +5197,7 @@ var BranchPickerNext = forwardRef23((props, ref) => {
|
|
5199
5197
|
strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
|
5200
5198
|
} = useThreadConfig();
|
5201
5199
|
const allowBranchPicker = useAllowBranchPicker();
|
5202
|
-
return /* @__PURE__ */
|
5200
|
+
return /* @__PURE__ */ jsx39(branchPicker_exports.Next, { disabled: !allowBranchPicker, asChild: true, children: /* @__PURE__ */ jsx39(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx39(ChevronRightIcon, {}) }) });
|
5203
5201
|
});
|
5204
5202
|
BranchPickerNext.displayName = "BranchPickerNext";
|
5205
5203
|
var exports2 = {
|
@@ -5211,12 +5209,12 @@ var branch_picker_default = Object.assign(BranchPicker, exports2);
|
|
5211
5209
|
|
5212
5210
|
// src/ui/base/avatar.tsx
|
5213
5211
|
import * as AvatarPrimitive from "@radix-ui/react-avatar";
|
5214
|
-
import { jsx as
|
5212
|
+
import { jsx as jsx40, jsxs as jsxs6 } from "react/jsx-runtime";
|
5215
5213
|
var Avatar = ({ src, alt, fallback }) => {
|
5216
5214
|
if (src == null && fallback == null) return null;
|
5217
5215
|
return /* @__PURE__ */ jsxs6(AvatarRoot, { children: [
|
5218
|
-
src != null && /* @__PURE__ */
|
5219
|
-
fallback != null && /* @__PURE__ */
|
5216
|
+
src != null && /* @__PURE__ */ jsx40(AvatarImage, { src, alt }),
|
5217
|
+
fallback != null && /* @__PURE__ */ jsx40(AvatarFallback, { children: fallback })
|
5220
5218
|
] });
|
5221
5219
|
};
|
5222
5220
|
Avatar.displayName = "Avatar";
|
@@ -5235,10 +5233,10 @@ AvatarFallback.displayName = "AvatarFallback";
|
|
5235
5233
|
|
5236
5234
|
// src/ui/content-part.tsx
|
5237
5235
|
import classNames2 from "classnames";
|
5238
|
-
import { jsx as
|
5236
|
+
import { jsx as jsx41 } from "react/jsx-runtime";
|
5239
5237
|
var Text = () => {
|
5240
5238
|
const status = useSmoothStatus();
|
5241
|
-
return /* @__PURE__ */
|
5239
|
+
return /* @__PURE__ */ jsx41(
|
5242
5240
|
contentPart_exports.Text,
|
5243
5241
|
{
|
5244
5242
|
className: classNames2(
|
@@ -5253,19 +5251,19 @@ var exports3 = { Text: withSmoothContextProvider(Text) };
|
|
5253
5251
|
var content_part_default = exports3;
|
5254
5252
|
|
5255
5253
|
// src/ui/assistant-message.tsx
|
5256
|
-
import { jsx as
|
5254
|
+
import { jsx as jsx42, jsxs as jsxs7 } from "react/jsx-runtime";
|
5257
5255
|
var AssistantMessage = () => {
|
5258
5256
|
return /* @__PURE__ */ jsxs7(AssistantMessageRoot, { children: [
|
5259
|
-
/* @__PURE__ */
|
5260
|
-
/* @__PURE__ */
|
5261
|
-
/* @__PURE__ */
|
5262
|
-
/* @__PURE__ */
|
5257
|
+
/* @__PURE__ */ jsx42(AssistantMessageAvatar, {}),
|
5258
|
+
/* @__PURE__ */ jsx42(AssistantMessageContent, {}),
|
5259
|
+
/* @__PURE__ */ jsx42(branch_picker_default, {}),
|
5260
|
+
/* @__PURE__ */ jsx42(assistant_action_bar_default, {})
|
5263
5261
|
] });
|
5264
5262
|
};
|
5265
5263
|
AssistantMessage.displayName = "AssistantMessage";
|
5266
5264
|
var AssistantMessageAvatar = () => {
|
5267
5265
|
const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
|
5268
|
-
return /* @__PURE__ */
|
5266
|
+
return /* @__PURE__ */ jsx42(Avatar, { ...avatar });
|
5269
5267
|
};
|
5270
5268
|
var AssistantMessageRoot = withDefaults(message_exports.Root, {
|
5271
5269
|
className: "aui-assistant-message-root"
|
@@ -5276,7 +5274,7 @@ var AssistantMessageContentWrapper = withDefaults("div", {
|
|
5276
5274
|
});
|
5277
5275
|
var AssistantMessageContent = forwardRef24(({ components: componentsProp, ...rest }, ref) => {
|
5278
5276
|
const { tools, assistantMessage: { components = {} } = {} } = useThreadConfig();
|
5279
|
-
const toolsComponents =
|
5277
|
+
const toolsComponents = useMemo11(
|
5280
5278
|
() => ({
|
5281
5279
|
by_name: !tools ? void 0 : Object.fromEntries(
|
5282
5280
|
tools.map((t) => [
|
@@ -5289,7 +5287,7 @@ var AssistantMessageContent = forwardRef24(({ components: componentsProp, ...res
|
|
5289
5287
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
5290
5288
|
[...tools ?? [], components.ToolFallback]
|
5291
5289
|
);
|
5292
|
-
return /* @__PURE__ */
|
5290
|
+
return /* @__PURE__ */ jsx42(AssistantMessageContentWrapper, { ...rest, ref, children: /* @__PURE__ */ jsx42(
|
5293
5291
|
message_exports.Content,
|
5294
5292
|
{
|
5295
5293
|
components: {
|
@@ -5324,9 +5322,9 @@ import { forwardRef as forwardRef26 } from "react";
|
|
5324
5322
|
import { PaperclipIcon, SendHorizontalIcon } from "lucide-react";
|
5325
5323
|
|
5326
5324
|
// src/ui/base/CircleStopIcon.tsx
|
5327
|
-
import { jsx as
|
5325
|
+
import { jsx as jsx43 } from "react/jsx-runtime";
|
5328
5326
|
var CircleStopIcon = () => {
|
5329
|
-
return /* @__PURE__ */
|
5327
|
+
return /* @__PURE__ */ jsx43(
|
5330
5328
|
"svg",
|
5331
5329
|
{
|
5332
5330
|
xmlns: "http://www.w3.org/2000/svg",
|
@@ -5334,7 +5332,7 @@ var CircleStopIcon = () => {
|
|
5334
5332
|
fill: "currentColor",
|
5335
5333
|
width: "16",
|
5336
5334
|
height: "16",
|
5337
|
-
children: /* @__PURE__ */
|
5335
|
+
children: /* @__PURE__ */ jsx43("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" })
|
5338
5336
|
}
|
5339
5337
|
);
|
5340
5338
|
};
|
@@ -5343,7 +5341,7 @@ CircleStopIcon.displayName = "CircleStopIcon";
|
|
5343
5341
|
// src/ui/composer-attachment.tsx
|
5344
5342
|
import { forwardRef as forwardRef25 } from "react";
|
5345
5343
|
import { CircleXIcon } from "lucide-react";
|
5346
|
-
import { jsx as
|
5344
|
+
import { jsx as jsx44, jsxs as jsxs8 } from "react/jsx-runtime";
|
5347
5345
|
var ComposerAttachmentRoot = withDefaults("div", {
|
5348
5346
|
className: "aui-composer-attachment-root"
|
5349
5347
|
});
|
@@ -5353,7 +5351,7 @@ var ComposerAttachment2 = () => {
|
|
5353
5351
|
return /* @__PURE__ */ jsxs8(ComposerAttachmentRoot, { children: [
|
5354
5352
|
".",
|
5355
5353
|
attachment.name.split(".").pop(),
|
5356
|
-
/* @__PURE__ */
|
5354
|
+
/* @__PURE__ */ jsx44(ComposerAttachmentRemove, {})
|
5357
5355
|
] });
|
5358
5356
|
};
|
5359
5357
|
ComposerAttachment2.displayName = "ComposerAttachment";
|
@@ -5368,7 +5366,7 @@ var ComposerAttachmentRemove = forwardRef25((props, ref) => {
|
|
5368
5366
|
const handleRemoveAttachment = () => {
|
5369
5367
|
composerStore.getState().removeAttachment(attachmentStore.getState().attachment.id);
|
5370
5368
|
};
|
5371
|
-
return /* @__PURE__ */
|
5369
|
+
return /* @__PURE__ */ jsx44(
|
5372
5370
|
TooltipIconButton,
|
5373
5371
|
{
|
5374
5372
|
tooltip,
|
@@ -5377,7 +5375,7 @@ var ComposerAttachmentRemove = forwardRef25((props, ref) => {
|
|
5377
5375
|
...props,
|
5378
5376
|
onClick: handleRemoveAttachment,
|
5379
5377
|
ref,
|
5380
|
-
children: props.children ?? /* @__PURE__ */
|
5378
|
+
children: props.children ?? /* @__PURE__ */ jsx44(CircleXIcon, {})
|
5381
5379
|
}
|
5382
5380
|
);
|
5383
5381
|
});
|
@@ -5392,7 +5390,7 @@ var composer_attachment_default = Object.assign(
|
|
5392
5390
|
);
|
5393
5391
|
|
5394
5392
|
// src/ui/composer.tsx
|
5395
|
-
import { Fragment as Fragment5, jsx as
|
5393
|
+
import { Fragment as Fragment5, jsx as jsx45, jsxs as jsxs9 } from "react/jsx-runtime";
|
5396
5394
|
var useAllowAttachments = (ensureCapability = false) => {
|
5397
5395
|
const { composer: { allowAttachments = true } = {} } = useThreadConfig();
|
5398
5396
|
const attachmentsSupported = useThread((t) => t.capabilities.attachments);
|
@@ -5401,10 +5399,10 @@ var useAllowAttachments = (ensureCapability = false) => {
|
|
5401
5399
|
var Composer = () => {
|
5402
5400
|
const allowAttachments = useAllowAttachments(true);
|
5403
5401
|
return /* @__PURE__ */ jsxs9(ComposerRoot, { children: [
|
5404
|
-
allowAttachments && /* @__PURE__ */
|
5405
|
-
allowAttachments && /* @__PURE__ */
|
5406
|
-
/* @__PURE__ */
|
5407
|
-
/* @__PURE__ */
|
5402
|
+
allowAttachments && /* @__PURE__ */ jsx45(ComposerAttachments, {}),
|
5403
|
+
allowAttachments && /* @__PURE__ */ jsx45(ComposerAddAttachment, {}),
|
5404
|
+
/* @__PURE__ */ jsx45(ComposerInput, { autoFocus: true }),
|
5405
|
+
/* @__PURE__ */ jsx45(ComposerAction, {})
|
5408
5406
|
] });
|
5409
5407
|
};
|
5410
5408
|
Composer.displayName = "Composer";
|
@@ -5424,7 +5422,7 @@ var ComposerInput = forwardRef26(
|
|
5424
5422
|
composer: { input: { placeholder = "Write a message..." } = {} } = {}
|
5425
5423
|
} = {}
|
5426
5424
|
} = useThreadConfig();
|
5427
|
-
return /* @__PURE__ */
|
5425
|
+
return /* @__PURE__ */ jsx45(ComposerInputStyled, { placeholder, ...props, ref });
|
5428
5426
|
}
|
5429
5427
|
);
|
5430
5428
|
ComposerInput.displayName = "ComposerInput";
|
@@ -5432,7 +5430,7 @@ var ComposerAttachmentsContainer = withDefaults("div", {
|
|
5432
5430
|
className: "aui-composer-attachments"
|
5433
5431
|
});
|
5434
5432
|
var ComposerAttachments = ({ components }) => {
|
5435
|
-
return /* @__PURE__ */
|
5433
|
+
return /* @__PURE__ */ jsx45(ComposerAttachmentsContainer, { children: /* @__PURE__ */ jsx45(
|
5436
5434
|
composer_exports.Attachments,
|
5437
5435
|
{
|
5438
5436
|
components: {
|
@@ -5453,14 +5451,14 @@ var ComposerAddAttachment = forwardRef26((props, ref) => {
|
|
5453
5451
|
} = {}
|
5454
5452
|
} = useThreadConfig();
|
5455
5453
|
const allowAttachments = useAllowAttachments();
|
5456
|
-
return /* @__PURE__ */
|
5454
|
+
return /* @__PURE__ */ jsx45(composer_exports.AddAttachment, { disabled: !allowAttachments, asChild: true, children: /* @__PURE__ */ jsx45(
|
5457
5455
|
ComposerAttachButton,
|
5458
5456
|
{
|
5459
5457
|
tooltip,
|
5460
5458
|
variant: "ghost",
|
5461
5459
|
...props,
|
5462
5460
|
ref,
|
5463
|
-
children: props.children ?? /* @__PURE__ */
|
5461
|
+
children: props.children ?? /* @__PURE__ */ jsx45(PaperclipIcon, {})
|
5464
5462
|
}
|
5465
5463
|
) });
|
5466
5464
|
});
|
@@ -5471,10 +5469,10 @@ var useAllowCancel = () => {
|
|
5471
5469
|
};
|
5472
5470
|
var ComposerAction = () => {
|
5473
5471
|
const allowCancel = useAllowCancel();
|
5474
|
-
if (!allowCancel) return /* @__PURE__ */
|
5472
|
+
if (!allowCancel) return /* @__PURE__ */ jsx45(ComposerSend, {});
|
5475
5473
|
return /* @__PURE__ */ jsxs9(Fragment5, { children: [
|
5476
|
-
/* @__PURE__ */
|
5477
|
-
/* @__PURE__ */
|
5474
|
+
/* @__PURE__ */ jsx45(thread_exports.If, { running: false, children: /* @__PURE__ */ jsx45(ComposerSend, {}) }),
|
5475
|
+
/* @__PURE__ */ jsx45(thread_exports.If, { running: true, children: /* @__PURE__ */ jsx45(ComposerCancel, {}) })
|
5478
5476
|
] });
|
5479
5477
|
};
|
5480
5478
|
ComposerAction.displayName = "ComposerAction";
|
@@ -5486,7 +5484,7 @@ var ComposerSend = forwardRef26((props, ref) => {
|
|
5486
5484
|
const {
|
5487
5485
|
strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
|
5488
5486
|
} = useThreadConfig();
|
5489
|
-
return /* @__PURE__ */
|
5487
|
+
return /* @__PURE__ */ jsx45(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx45(ComposerSendButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx45(SendHorizontalIcon, {}) }) });
|
5490
5488
|
});
|
5491
5489
|
ComposerSend.displayName = "ComposerSend";
|
5492
5490
|
var ComposerCancelButton = withDefaults(TooltipIconButton, {
|
@@ -5497,7 +5495,7 @@ var ComposerCancel = forwardRef26((props, ref) => {
|
|
5497
5495
|
const {
|
5498
5496
|
strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
|
5499
5497
|
} = useThreadConfig();
|
5500
|
-
return /* @__PURE__ */
|
5498
|
+
return /* @__PURE__ */ jsx45(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx45(ComposerCancelButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx45(CircleStopIcon, {}) }) });
|
5501
5499
|
});
|
5502
5500
|
ComposerCancel.displayName = "ComposerCancel";
|
5503
5501
|
var exports6 = {
|
@@ -5513,14 +5511,14 @@ var composer_default = Object.assign(Composer, exports6);
|
|
5513
5511
|
|
5514
5512
|
// src/ui/thread-welcome.tsx
|
5515
5513
|
import { forwardRef as forwardRef27 } from "react";
|
5516
|
-
import { jsx as
|
5514
|
+
import { jsx as jsx46, jsxs as jsxs10 } from "react/jsx-runtime";
|
5517
5515
|
var ThreadWelcome = () => {
|
5518
5516
|
return /* @__PURE__ */ jsxs10(ThreadWelcomeRoot, { children: [
|
5519
5517
|
/* @__PURE__ */ jsxs10(ThreadWelcomeCenter, { children: [
|
5520
|
-
/* @__PURE__ */
|
5521
|
-
/* @__PURE__ */
|
5518
|
+
/* @__PURE__ */ jsx46(ThreadWelcomeAvatar, {}),
|
5519
|
+
/* @__PURE__ */ jsx46(ThreadWelcomeMessage, {})
|
5522
5520
|
] }),
|
5523
|
-
/* @__PURE__ */
|
5521
|
+
/* @__PURE__ */ jsx46(ThreadWelcomeSuggestions, {})
|
5524
5522
|
] });
|
5525
5523
|
};
|
5526
5524
|
ThreadWelcome.displayName = "ThreadWelcome";
|
@@ -5532,20 +5530,20 @@ var ThreadWelcomeCenter = withDefaults("div", {
|
|
5532
5530
|
});
|
5533
5531
|
var ThreadWelcomeRoot = forwardRef27(
|
5534
5532
|
(props, ref) => {
|
5535
|
-
return /* @__PURE__ */
|
5533
|
+
return /* @__PURE__ */ jsx46(thread_exports.Empty, { children: /* @__PURE__ */ jsx46(ThreadWelcomeRootStyled, { ...props, ref }) });
|
5536
5534
|
}
|
5537
5535
|
);
|
5538
5536
|
ThreadWelcomeRoot.displayName = "ThreadWelcomeRoot";
|
5539
5537
|
var ThreadWelcomeAvatar = () => {
|
5540
5538
|
const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
|
5541
|
-
return /* @__PURE__ */
|
5539
|
+
return /* @__PURE__ */ jsx46(Avatar, { ...avatar });
|
5542
5540
|
};
|
5543
5541
|
var ThreadWelcomeMessageStyled = withDefaults("p", {
|
5544
5542
|
className: "aui-thread-welcome-message"
|
5545
5543
|
});
|
5546
5544
|
var ThreadWelcomeMessage = forwardRef27(({ message: messageProp, ...rest }, ref) => {
|
5547
5545
|
const { welcome: { message = "How can I help you today?" } = {} } = useThreadConfig();
|
5548
|
-
return /* @__PURE__ */
|
5546
|
+
return /* @__PURE__ */ jsx46(ThreadWelcomeMessageStyled, { ...rest, ref, children: messageProp ?? message });
|
5549
5547
|
});
|
5550
5548
|
ThreadWelcomeMessage.displayName = "ThreadWelcomeMessage";
|
5551
5549
|
var ThreadWelcomeSuggestionContainer = withDefaults("div", {
|
@@ -5557,21 +5555,21 @@ var ThreadWelcomeSuggestionStyled = withDefaults(thread_exports.Suggestion, {
|
|
5557
5555
|
var ThreadWelcomeSuggestion = ({
|
5558
5556
|
suggestion: { text, prompt }
|
5559
5557
|
}) => {
|
5560
|
-
return /* @__PURE__ */
|
5558
|
+
return /* @__PURE__ */ jsx46(
|
5561
5559
|
ThreadWelcomeSuggestionStyled,
|
5562
5560
|
{
|
5563
5561
|
prompt,
|
5564
5562
|
method: "replace",
|
5565
5563
|
autoSend: true,
|
5566
|
-
children: /* @__PURE__ */
|
5564
|
+
children: /* @__PURE__ */ jsx46("span", { className: "aui-thread-welcome-suggestion-text", children: text ?? prompt })
|
5567
5565
|
}
|
5568
5566
|
);
|
5569
5567
|
};
|
5570
5568
|
var ThreadWelcomeSuggestions = () => {
|
5571
5569
|
const { welcome: { suggestions } = {} } = useThreadConfig();
|
5572
|
-
return /* @__PURE__ */
|
5570
|
+
return /* @__PURE__ */ jsx46(ThreadWelcomeSuggestionContainer, { children: suggestions?.map((suggestion, idx) => {
|
5573
5571
|
const key = `${suggestion.prompt}-${idx}`;
|
5574
|
-
return /* @__PURE__ */
|
5572
|
+
return /* @__PURE__ */ jsx46(ThreadWelcomeSuggestion, { suggestion }, key);
|
5575
5573
|
}) });
|
5576
5574
|
};
|
5577
5575
|
ThreadWelcomeSuggestions.displayName = "ThreadWelcomeSuggestions";
|
@@ -5591,7 +5589,7 @@ import { forwardRef as forwardRef29 } from "react";
|
|
5591
5589
|
// src/ui/user-action-bar.tsx
|
5592
5590
|
import { forwardRef as forwardRef28 } from "react";
|
5593
5591
|
import { PencilIcon } from "lucide-react";
|
5594
|
-
import { jsx as
|
5592
|
+
import { jsx as jsx47 } from "react/jsx-runtime";
|
5595
5593
|
var useAllowEdit = (ensureCapability = false) => {
|
5596
5594
|
const { userMessage: { allowEdit = true } = {} } = useThreadConfig();
|
5597
5595
|
const editSupported = useThread((t) => t.capabilities.edit);
|
@@ -5600,7 +5598,7 @@ var useAllowEdit = (ensureCapability = false) => {
|
|
5600
5598
|
var UserActionBar = () => {
|
5601
5599
|
const allowEdit = useAllowEdit(true);
|
5602
5600
|
if (!allowEdit) return null;
|
5603
|
-
return /* @__PURE__ */
|
5601
|
+
return /* @__PURE__ */ jsx47(UserActionBarRoot, { hideWhenRunning: true, autohide: "not-last", children: /* @__PURE__ */ jsx47(UserActionBarEdit, {}) });
|
5604
5602
|
};
|
5605
5603
|
UserActionBar.displayName = "UserActionBar";
|
5606
5604
|
var UserActionBarRoot = withDefaults(actionBar_exports.Root, {
|
@@ -5612,7 +5610,7 @@ var UserActionBarEdit = forwardRef28((props, ref) => {
|
|
5612
5610
|
strings: { userMessage: { edit: { tooltip = "Edit" } = {} } = {} } = {}
|
5613
5611
|
} = useThreadConfig();
|
5614
5612
|
const allowEdit = useAllowEdit();
|
5615
|
-
return /* @__PURE__ */
|
5613
|
+
return /* @__PURE__ */ jsx47(actionBar_exports.Edit, { disabled: !allowEdit, asChild: true, children: /* @__PURE__ */ jsx47(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx47(PencilIcon, {}) }) });
|
5616
5614
|
});
|
5617
5615
|
UserActionBarEdit.displayName = "UserActionBarEdit";
|
5618
5616
|
var exports8 = {
|
@@ -5644,13 +5642,13 @@ var user_message_attachment_default = Object.assign(
|
|
5644
5642
|
);
|
5645
5643
|
|
5646
5644
|
// src/ui/user-message.tsx
|
5647
|
-
import { jsx as
|
5645
|
+
import { jsx as jsx48, jsxs as jsxs12 } from "react/jsx-runtime";
|
5648
5646
|
var UserMessage = () => {
|
5649
5647
|
return /* @__PURE__ */ jsxs12(UserMessageRoot, { children: [
|
5650
|
-
/* @__PURE__ */
|
5651
|
-
/* @__PURE__ */
|
5652
|
-
/* @__PURE__ */
|
5653
|
-
/* @__PURE__ */
|
5648
|
+
/* @__PURE__ */ jsx48(UserMessageAttachments, {}),
|
5649
|
+
/* @__PURE__ */ jsx48(user_action_bar_default, {}),
|
5650
|
+
/* @__PURE__ */ jsx48(UserMessageContent, {}),
|
5651
|
+
/* @__PURE__ */ jsx48(branch_picker_default, {})
|
5654
5652
|
] });
|
5655
5653
|
};
|
5656
5654
|
UserMessage.displayName = "UserMessage";
|
@@ -5663,7 +5661,7 @@ var UserMessageContentWrapper = withDefaults("div", {
|
|
5663
5661
|
});
|
5664
5662
|
var UserMessageContent = forwardRef29(
|
5665
5663
|
({ components, ...props }, ref) => {
|
5666
|
-
return /* @__PURE__ */
|
5664
|
+
return /* @__PURE__ */ jsx48(UserMessageContentWrapper, { ...props, ref, children: /* @__PURE__ */ jsx48(
|
5667
5665
|
message_exports.Content,
|
5668
5666
|
{
|
5669
5667
|
components: {
|
@@ -5681,7 +5679,7 @@ var UserMessageAttachmentsContainer = withDefaults("div", {
|
|
5681
5679
|
var UserMessageAttachments = ({
|
5682
5680
|
components
|
5683
5681
|
}) => {
|
5684
|
-
return /* @__PURE__ */
|
5682
|
+
return /* @__PURE__ */ jsx48(message_exports.If, { hasAttachments: true, children: /* @__PURE__ */ jsx48(UserMessageAttachmentsContainer, { children: /* @__PURE__ */ jsx48(
|
5685
5683
|
message_exports.Attachments,
|
5686
5684
|
{
|
5687
5685
|
components: {
|
@@ -5700,13 +5698,13 @@ var user_message_default = Object.assign(UserMessage, exports10);
|
|
5700
5698
|
|
5701
5699
|
// src/ui/edit-composer.tsx
|
5702
5700
|
import { forwardRef as forwardRef30 } from "react";
|
5703
|
-
import { jsx as
|
5701
|
+
import { jsx as jsx49, jsxs as jsxs13 } from "react/jsx-runtime";
|
5704
5702
|
var EditComposer = () => {
|
5705
5703
|
return /* @__PURE__ */ jsxs13(EditComposerRoot, { children: [
|
5706
|
-
/* @__PURE__ */
|
5704
|
+
/* @__PURE__ */ jsx49(EditComposerInput, {}),
|
5707
5705
|
/* @__PURE__ */ jsxs13(EditComposerFooter, { children: [
|
5708
|
-
/* @__PURE__ */
|
5709
|
-
/* @__PURE__ */
|
5706
|
+
/* @__PURE__ */ jsx49(EditComposerCancel, {}),
|
5707
|
+
/* @__PURE__ */ jsx49(EditComposerSend, {})
|
5710
5708
|
] })
|
5711
5709
|
] });
|
5712
5710
|
};
|
@@ -5730,7 +5728,7 @@ var EditComposerCancel = forwardRef30(
|
|
5730
5728
|
editComposer: { cancel: { label = "Cancel" } = {} } = {}
|
5731
5729
|
} = {}
|
5732
5730
|
} = useThreadConfig();
|
5733
|
-
return /* @__PURE__ */
|
5731
|
+
return /* @__PURE__ */ jsx49(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx49(Button, { variant: "ghost", ...props, ref, children: props.children ?? label }) });
|
5734
5732
|
}
|
5735
5733
|
);
|
5736
5734
|
EditComposerCancel.displayName = "EditComposerCancel";
|
@@ -5739,7 +5737,7 @@ var EditComposerSend = forwardRef30(
|
|
5739
5737
|
const {
|
5740
5738
|
strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
|
5741
5739
|
} = useThreadConfig();
|
5742
|
-
return /* @__PURE__ */
|
5740
|
+
return /* @__PURE__ */ jsx49(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx49(Button, { ...props, ref, children: props.children ?? label }) });
|
5743
5741
|
}
|
5744
5742
|
);
|
5745
5743
|
EditComposerSend.displayName = "EditComposerSend";
|
@@ -5753,14 +5751,14 @@ var exports11 = {
|
|
5753
5751
|
var edit_composer_default = Object.assign(EditComposer, exports11);
|
5754
5752
|
|
5755
5753
|
// src/ui/thread.tsx
|
5756
|
-
import { jsx as
|
5754
|
+
import { jsx as jsx50, jsxs as jsxs14 } from "react/jsx-runtime";
|
5757
5755
|
var Thread = (config) => {
|
5758
|
-
return /* @__PURE__ */
|
5759
|
-
/* @__PURE__ */
|
5760
|
-
/* @__PURE__ */
|
5756
|
+
return /* @__PURE__ */ jsx50(ThreadRoot, { config, children: /* @__PURE__ */ jsxs14(ThreadViewport, { children: [
|
5757
|
+
/* @__PURE__ */ jsx50(thread_welcome_default, {}),
|
5758
|
+
/* @__PURE__ */ jsx50(ThreadMessages, {}),
|
5761
5759
|
/* @__PURE__ */ jsxs14(ThreadViewportFooter, { children: [
|
5762
|
-
/* @__PURE__ */
|
5763
|
-
/* @__PURE__ */
|
5760
|
+
/* @__PURE__ */ jsx50(ThreadScrollToBottom, {}),
|
5761
|
+
/* @__PURE__ */ jsx50(composer_default, {})
|
5764
5762
|
] })
|
5765
5763
|
] }) });
|
5766
5764
|
};
|
@@ -5769,7 +5767,7 @@ var ThreadRootStyled = withDefaults(thread_exports.Root, {
|
|
5769
5767
|
});
|
5770
5768
|
var ThreadRoot = forwardRef31(
|
5771
5769
|
({ config, ...props }, ref) => {
|
5772
|
-
return /* @__PURE__ */
|
5770
|
+
return /* @__PURE__ */ jsx50(ThreadConfigProvider, { config, children: /* @__PURE__ */ jsx50(ThreadRootStyled, { ...props, ref }) });
|
5773
5771
|
}
|
5774
5772
|
);
|
5775
5773
|
ThreadRoot.displayName = "ThreadRoot";
|
@@ -5783,7 +5781,7 @@ var ThreadViewportFooter = withDefaults("div", {
|
|
5783
5781
|
ThreadViewportFooter.displayName = "ThreadViewportFooter";
|
5784
5782
|
var SystemMessage = () => null;
|
5785
5783
|
var ThreadMessages = ({ components, ...rest }) => {
|
5786
|
-
return /* @__PURE__ */
|
5784
|
+
return /* @__PURE__ */ jsx50(
|
5787
5785
|
thread_exports.Messages,
|
5788
5786
|
{
|
5789
5787
|
components: {
|
@@ -5807,7 +5805,7 @@ var ThreadScrollToBottom = forwardRef31((props, ref) => {
|
|
5807
5805
|
thread: { scrollToBottom: { tooltip = "Scroll to bottom" } = {} } = {}
|
5808
5806
|
} = {}
|
5809
5807
|
} = useThreadConfig();
|
5810
|
-
return /* @__PURE__ */
|
5808
|
+
return /* @__PURE__ */ jsx50(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx50(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx50(ArrowDownIcon, {}) }) });
|
5811
5809
|
});
|
5812
5810
|
ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
|
5813
5811
|
var exports12 = {
|
@@ -5820,20 +5818,20 @@ var exports12 = {
|
|
5820
5818
|
var thread_default = Object.assign(Thread, exports12);
|
5821
5819
|
|
5822
5820
|
// src/ui/assistant-modal.tsx
|
5823
|
-
import { Fragment as Fragment6, jsx as
|
5821
|
+
import { Fragment as Fragment6, jsx as jsx51, jsxs as jsxs15 } from "react/jsx-runtime";
|
5824
5822
|
var AssistantModal = (config) => {
|
5825
5823
|
return /* @__PURE__ */ jsxs15(AssistantModalRoot, { config, children: [
|
5826
|
-
/* @__PURE__ */
|
5827
|
-
/* @__PURE__ */
|
5824
|
+
/* @__PURE__ */ jsx51(AssistantModalTrigger, {}),
|
5825
|
+
/* @__PURE__ */ jsx51(AssistantModalContent, { children: /* @__PURE__ */ jsx51(thread_default, {}) })
|
5828
5826
|
] });
|
5829
5827
|
};
|
5830
5828
|
AssistantModal.displayName = "AssistantModal";
|
5831
5829
|
var AssistantModalRoot = ({ config, ...props }) => {
|
5832
|
-
return /* @__PURE__ */
|
5830
|
+
return /* @__PURE__ */ jsx51(ThreadConfigProvider, { config, children: /* @__PURE__ */ jsx51(assistantModal_exports.Root, { ...props }) });
|
5833
5831
|
};
|
5834
5832
|
AssistantModalRoot.displayName = "AssistantModalRoot";
|
5835
5833
|
var AssistantModalTrigger = forwardRef32((props, ref) => {
|
5836
|
-
return /* @__PURE__ */
|
5834
|
+
return /* @__PURE__ */ jsx51(AssistantModalAnchor, { children: /* @__PURE__ */ jsx51(assistantModal_exports.Trigger, { asChild: true, children: /* @__PURE__ */ jsx51(AssistantModalButton, { ...props, ref }) }) });
|
5837
5835
|
});
|
5838
5836
|
AssistantModalTrigger.displayName = "AssistantModalTrigger";
|
5839
5837
|
var AssistantModalAnchor = withDefaults(assistantModal_exports.Anchor, {
|
@@ -5858,7 +5856,7 @@ var AssistantModalButton = forwardRef32(({ "data-state": state, ...rest }, ref)
|
|
5858
5856
|
} = {}
|
5859
5857
|
} = useThreadConfig();
|
5860
5858
|
const tooltip = state === "open" ? openTooltip : closedTooltip;
|
5861
|
-
return /* @__PURE__ */
|
5859
|
+
return /* @__PURE__ */ jsx51(
|
5862
5860
|
ModalButtonStyled,
|
5863
5861
|
{
|
5864
5862
|
side: "left",
|
@@ -5867,14 +5865,14 @@ var AssistantModalButton = forwardRef32(({ "data-state": state, ...rest }, ref)
|
|
5867
5865
|
...rest,
|
5868
5866
|
ref,
|
5869
5867
|
children: rest.children ?? /* @__PURE__ */ jsxs15(Fragment6, { children: [
|
5870
|
-
/* @__PURE__ */
|
5868
|
+
/* @__PURE__ */ jsx51(
|
5871
5869
|
BotIcon,
|
5872
5870
|
{
|
5873
5871
|
"data-state": state,
|
5874
5872
|
className: "aui-modal-button-closed-icon"
|
5875
5873
|
}
|
5876
5874
|
),
|
5877
|
-
/* @__PURE__ */
|
5875
|
+
/* @__PURE__ */ jsx51(
|
5878
5876
|
ChevronDownIcon,
|
5879
5877
|
{
|
5880
5878
|
"data-state": state,
|
@@ -5967,12 +5965,14 @@ export {
|
|
5967
5965
|
useComposerCancel,
|
5968
5966
|
useComposerContext,
|
5969
5967
|
useComposerIf,
|
5968
|
+
useComposerRuntime,
|
5970
5969
|
useComposerSend,
|
5971
5970
|
useComposerStore,
|
5972
5971
|
useContentPart,
|
5973
5972
|
useContentPartContext,
|
5974
5973
|
useContentPartDisplay,
|
5975
5974
|
useContentPartImage,
|
5975
|
+
useContentPartRuntime,
|
5976
5976
|
useContentPartStore,
|
5977
5977
|
useContentPartText,
|
5978
5978
|
useDangerousInBrowserRuntime,
|
@@ -5985,6 +5985,7 @@ export {
|
|
5985
5985
|
useMessage,
|
5986
5986
|
useMessageContext,
|
5987
5987
|
useMessageIf,
|
5988
|
+
useMessageRuntime,
|
5988
5989
|
useMessageStore,
|
5989
5990
|
useMessageUtils,
|
5990
5991
|
useMessageUtilsStore,
|