@assistant-ui/react 0.5.56 → 0.5.58
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +17 -8
- package/dist/index.d.ts +17 -8
- package/dist/index.js +32 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -1839,8 +1839,8 @@ var ExternalStoreRuntime = class extends BaseAssistantRuntime {
|
|
1839
1839
|
if (!this.store.onSwitchToNewThread)
|
1840
1840
|
throw new Error("Runtime does not support switching to new threads.");
|
1841
1841
|
this.thread = new ExternalStoreThreadRuntime({
|
1842
|
-
|
1843
|
-
|
1842
|
+
...this.store,
|
1843
|
+
messages: []
|
1844
1844
|
});
|
1845
1845
|
await this.store.onSwitchToNewThread();
|
1846
1846
|
}
|
@@ -1849,8 +1849,9 @@ var ExternalStoreRuntime = class extends BaseAssistantRuntime {
|
|
1849
1849
|
if (!this.store.onSwitchToThread)
|
1850
1850
|
throw new Error("Runtime does not support switching threads.");
|
1851
1851
|
this.thread = new ExternalStoreThreadRuntime({
|
1852
|
-
|
1853
|
-
|
1852
|
+
...this.store,
|
1853
|
+
messages: []
|
1854
|
+
// ignore messages until rerender
|
1854
1855
|
});
|
1855
1856
|
this.store.onSwitchToThread(threadId);
|
1856
1857
|
} else {
|
@@ -2344,19 +2345,40 @@ var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
|
2344
2345
|
var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
2345
2346
|
|
2346
2347
|
// src/context/providers/TextContentPartProvider.tsx
|
2347
|
-
import { useState as useState9 } from "react";
|
2348
|
+
import { useEffect as useEffect5, useState as useState9 } from "react";
|
2348
2349
|
import { create as create11 } from "zustand";
|
2349
2350
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
2350
|
-
var
|
2351
|
+
var COMPLETE_STATUS = {
|
2352
|
+
type: "complete"
|
2353
|
+
};
|
2354
|
+
var RUNNING_STATUS = {
|
2355
|
+
type: "running"
|
2356
|
+
};
|
2357
|
+
var TextContentPartProvider = ({ children, text, isRunning }) => {
|
2351
2358
|
const [context] = useState9(() => {
|
2352
2359
|
const useContentPart2 = create11(() => ({
|
2353
|
-
status:
|
2360
|
+
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
2354
2361
|
part: { type: "text", text }
|
2355
2362
|
}));
|
2356
2363
|
return {
|
2357
2364
|
useContentPart: useContentPart2
|
2358
2365
|
};
|
2359
2366
|
});
|
2367
|
+
useEffect5(() => {
|
2368
|
+
const state = context.useContentPart.getState();
|
2369
|
+
const textUpdated = state.part.text !== text;
|
2370
|
+
const targetTextPart = textUpdated ? { type: "text", text } : state.part;
|
2371
|
+
const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;
|
2372
|
+
const statusUpdated = state.status !== targetStatus;
|
2373
|
+
if (!textUpdated && !statusUpdated) return;
|
2374
|
+
writableStore(context.useContentPart).setState(
|
2375
|
+
{
|
2376
|
+
part: targetTextPart,
|
2377
|
+
status: targetStatus
|
2378
|
+
},
|
2379
|
+
true
|
2380
|
+
);
|
2381
|
+
}, [context, isRunning, text]);
|
2360
2382
|
return /* @__PURE__ */ jsx9(ContentPartContext.Provider, { value: context, children });
|
2361
2383
|
};
|
2362
2384
|
|
@@ -2451,11 +2473,11 @@ var useSwitchToNewThread = () => {
|
|
2451
2473
|
};
|
2452
2474
|
|
2453
2475
|
// src/model-config/useAssistantTool.tsx
|
2454
|
-
import { useEffect as
|
2476
|
+
import { useEffect as useEffect6 } from "react";
|
2455
2477
|
var useAssistantTool = (tool) => {
|
2456
2478
|
const assistantActionsStore = useAssistantActionsStore();
|
2457
2479
|
const toolUIsStore = useToolUIsStore();
|
2458
|
-
|
2480
|
+
useEffect6(() => {
|
2459
2481
|
const { toolName, render, ...rest } = tool;
|
2460
2482
|
const config = {
|
2461
2483
|
tools: {
|
@@ -2484,10 +2506,10 @@ var makeAssistantTool = (tool) => {
|
|
2484
2506
|
};
|
2485
2507
|
|
2486
2508
|
// src/model-config/useAssistantToolUI.tsx
|
2487
|
-
import { useEffect as
|
2509
|
+
import { useEffect as useEffect7 } from "react";
|
2488
2510
|
var useAssistantToolUI = (tool) => {
|
2489
2511
|
const toolUIsStore = useToolUIsStore();
|
2490
|
-
|
2512
|
+
useEffect7(() => {
|
2491
2513
|
if (!tool) return;
|
2492
2514
|
const { toolName, render } = tool;
|
2493
2515
|
return toolUIsStore.getState().setToolUI(toolName, render);
|
@@ -2505,10 +2527,10 @@ var makeAssistantToolUI = (tool) => {
|
|
2505
2527
|
};
|
2506
2528
|
|
2507
2529
|
// src/model-config/useAssistantInstructions.tsx
|
2508
|
-
import { useEffect as
|
2530
|
+
import { useEffect as useEffect8 } from "react";
|
2509
2531
|
var useAssistantInstructions = (instruction) => {
|
2510
2532
|
const actionsStore = useAssistantActionsStore();
|
2511
|
-
|
2533
|
+
useEffect8(() => {
|
2512
2534
|
const config = {
|
2513
2535
|
system: instruction
|
2514
2536
|
};
|
@@ -3047,11 +3069,11 @@ import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primiti
|
|
3047
3069
|
|
3048
3070
|
// src/utils/hooks/useOnComposerFocus.tsx
|
3049
3071
|
import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
|
3050
|
-
import { useEffect as
|
3072
|
+
import { useEffect as useEffect9 } from "react";
|
3051
3073
|
var useOnComposerFocus = (callback) => {
|
3052
3074
|
const callbackRef = useCallbackRef2(callback);
|
3053
3075
|
const threadComposerStore = useThreadComposerStore();
|
3054
|
-
|
3076
|
+
useEffect9(() => {
|
3055
3077
|
return threadComposerStore.getState().onFocus(() => {
|
3056
3078
|
callbackRef();
|
3057
3079
|
});
|
@@ -3280,24 +3302,24 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
|
3280
3302
|
import { memo as memo2 } from "react";
|
3281
3303
|
|
3282
3304
|
// src/context/providers/ContentPartProvider.tsx
|
3283
|
-
import { useEffect as
|
3305
|
+
import { useEffect as useEffect10, useState as useState11 } from "react";
|
3284
3306
|
import { create as create12 } from "zustand";
|
3285
3307
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
3286
|
-
var
|
3308
|
+
var COMPLETE_STATUS2 = {
|
3287
3309
|
type: "complete"
|
3288
3310
|
};
|
3289
3311
|
var toContentPartStatus = (message, partIndex, part) => {
|
3290
|
-
if (message.role !== "assistant") return
|
3312
|
+
if (message.role !== "assistant") return COMPLETE_STATUS2;
|
3291
3313
|
const isLastPart = partIndex === Math.max(0, message.content.length - 1);
|
3292
3314
|
if (part.type !== "tool-call") {
|
3293
3315
|
if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
|
3294
3316
|
throw new Error(
|
3295
3317
|
"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
|
3296
3318
|
);
|
3297
|
-
return isLastPart ? message.status :
|
3319
|
+
return isLastPart ? message.status : COMPLETE_STATUS2;
|
3298
3320
|
}
|
3299
3321
|
if (!!part.result) {
|
3300
|
-
return
|
3322
|
+
return COMPLETE_STATUS2;
|
3301
3323
|
}
|
3302
3324
|
return message.status;
|
3303
3325
|
};
|
@@ -3327,7 +3349,7 @@ var useContentPartContext2 = (partIndex) => {
|
|
3327
3349
|
);
|
3328
3350
|
return { useContentPart: useContentPart2 };
|
3329
3351
|
});
|
3330
|
-
|
3352
|
+
useEffect10(() => {
|
3331
3353
|
const syncContentPart = (message) => {
|
3332
3354
|
const newState = getContentPartState(
|
3333
3355
|
message,
|
@@ -3534,7 +3556,7 @@ var {
|
|
3534
3556
|
} = createContextStoreHook(useMessageAttachmentContext, "useAttachment");
|
3535
3557
|
|
3536
3558
|
// src/context/providers/MessageAttachmentProvider.tsx
|
3537
|
-
import { useEffect as
|
3559
|
+
import { useEffect as useEffect11, useState as useState12 } from "react";
|
3538
3560
|
import { create as create13 } from "zustand";
|
3539
3561
|
import { jsx as jsx24 } from "react/jsx-runtime";
|
3540
3562
|
var getAttachment = ({ message }, useAttachment2, partIndex) => {
|
@@ -3556,7 +3578,7 @@ var useMessageAttachmentContext2 = (partIndex) => {
|
|
3556
3578
|
return { type: "message", useAttachment: useAttachment2 };
|
3557
3579
|
}
|
3558
3580
|
);
|
3559
|
-
|
3581
|
+
useEffect11(() => {
|
3560
3582
|
const syncAttachment = (messageState) => {
|
3561
3583
|
const newState = getAttachment(
|
3562
3584
|
messageState,
|
@@ -3676,7 +3698,7 @@ import { Slot } from "@radix-ui/react-slot";
|
|
3676
3698
|
import {
|
3677
3699
|
forwardRef as forwardRef16,
|
3678
3700
|
useCallback as useCallback17,
|
3679
|
-
useEffect as
|
3701
|
+
useEffect as useEffect12,
|
3680
3702
|
useRef as useRef4
|
3681
3703
|
} from "react";
|
3682
3704
|
import TextareaAutosize from "react-textarea-autosize";
|
@@ -3729,7 +3751,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
3729
3751
|
textareaRef.current.value.length
|
3730
3752
|
);
|
3731
3753
|
}, [autoFocusEnabled]);
|
3732
|
-
|
3754
|
+
useEffect12(() => focus(), [focus]);
|
3733
3755
|
useOnComposerFocus(() => {
|
3734
3756
|
if (composerStore.getState().type === "thread") {
|
3735
3757
|
focus();
|
@@ -3777,7 +3799,7 @@ var ComposerPrimitiveAddAttachment = createActionButton(
|
|
3777
3799
|
import { memo as memo4 } from "react";
|
3778
3800
|
|
3779
3801
|
// src/context/providers/ComposerAttachmentProvider.tsx
|
3780
|
-
import { useEffect as
|
3802
|
+
import { useEffect as useEffect13, useState as useState13 } from "react";
|
3781
3803
|
import { create as create14 } from "zustand";
|
3782
3804
|
import { jsx as jsx29 } from "react/jsx-runtime";
|
3783
3805
|
var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
|
@@ -3797,7 +3819,7 @@ var useComposerAttachmentContext2 = (partIndex) => {
|
|
3797
3819
|
return { type: "composer", useAttachment: useAttachment2 };
|
3798
3820
|
}
|
3799
3821
|
);
|
3800
|
-
|
3822
|
+
useEffect13(() => {
|
3801
3823
|
const syncAttachment = (composer) => {
|
3802
3824
|
const newState = getAttachment2(
|
3803
3825
|
composer,
|
@@ -3970,11 +3992,11 @@ var useOnResizeContent = (callback) => {
|
|
3970
3992
|
|
3971
3993
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
3972
3994
|
import { useCallbackRef as useCallbackRef4 } from "@radix-ui/react-use-callback-ref";
|
3973
|
-
import { useEffect as
|
3995
|
+
import { useEffect as useEffect14 } from "react";
|
3974
3996
|
var useOnScrollToBottom = (callback) => {
|
3975
3997
|
const callbackRef = useCallbackRef4(callback);
|
3976
3998
|
const threadViewportStore = useThreadViewportStore();
|
3977
|
-
|
3999
|
+
useEffect14(() => {
|
3978
4000
|
return threadViewportStore.getState().onScrollToBottom(() => {
|
3979
4001
|
callbackRef();
|
3980
4002
|
});
|
@@ -4047,7 +4069,7 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
|
4047
4069
|
import { memo as memo5 } from "react";
|
4048
4070
|
|
4049
4071
|
// src/context/providers/MessageProvider.tsx
|
4050
|
-
import { useEffect as
|
4072
|
+
import { useEffect as useEffect15, useState as useState14 } from "react";
|
4051
4073
|
import { create as create17 } from "zustand";
|
4052
4074
|
|
4053
4075
|
// src/context/stores/EditComposer.ts
|
@@ -4173,7 +4195,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
4173
4195
|
});
|
4174
4196
|
return { useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
|
4175
4197
|
});
|
4176
|
-
|
4198
|
+
useEffect15(() => {
|
4177
4199
|
const syncMessage = (thread) => {
|
4178
4200
|
const newState = getMessageState(
|
4179
4201
|
thread,
|