@assistant-ui/react 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +79 -4
- package/dist/{Thread-ZUDFhMtm.d.mts → Thread-CoxBELWy.d.mts} +2 -0
- package/dist/{Thread-ZUDFhMtm.d.ts → Thread-CoxBELWy.d.ts} +2 -0
- package/dist/{chunk-KIP3YFVM.mjs → chunk-RITM2IUH.mjs} +4 -2
- package/dist/chunk-RITM2IUH.mjs.map +1 -0
- package/dist/experimental.d.mts +13 -13
- package/dist/experimental.d.ts +13 -13
- package/dist/experimental.js +29 -27
- package/dist/experimental.js.map +1 -1
- package/dist/experimental.mjs +24 -24
- package/dist/experimental.mjs.map +1 -1
- package/dist/index.d.mts +56 -55
- package/dist/index.d.ts +56 -55
- package/dist/index.js +51 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/dist/chunk-KIP3YFVM.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
useContentPartContext,
|
10
10
|
useMessageContext,
|
11
11
|
useThreadContext
|
12
|
-
} from "./chunk-
|
12
|
+
} from "./chunk-RITM2IUH.mjs";
|
13
13
|
|
14
14
|
// src/actions/useCopyMessage.tsx
|
15
15
|
import { useCallback } from "react";
|
@@ -150,9 +150,7 @@ __export(thread_exports, {
|
|
150
150
|
});
|
151
151
|
|
152
152
|
// src/primitives/thread/ThreadRoot.tsx
|
153
|
-
import {
|
154
|
-
Primitive
|
155
|
-
} from "@radix-ui/react-primitive";
|
153
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
156
154
|
import { forwardRef } from "react";
|
157
155
|
import { jsx } from "react/jsx-runtime";
|
158
156
|
var ThreadRoot = forwardRef(
|
@@ -160,6 +158,7 @@ var ThreadRoot = forwardRef(
|
|
160
158
|
return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref });
|
161
159
|
}
|
162
160
|
);
|
161
|
+
ThreadRoot.displayName = "ThreadRoot";
|
163
162
|
|
164
163
|
// src/primitives/thread/ThreadIf.tsx
|
165
164
|
var useThreadIf = (props) => {
|
@@ -186,18 +185,19 @@ var ThreadEmpty = ({ children }) => {
|
|
186
185
|
// src/primitives/thread/ThreadViewport.tsx
|
187
186
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
188
187
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
188
|
+
import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
|
189
189
|
import {
|
190
|
-
|
191
|
-
|
192
|
-
|
190
|
+
forwardRef as forwardRef2,
|
191
|
+
useRef
|
192
|
+
} from "react";
|
193
193
|
|
194
194
|
// src/utils/hooks/useOnResizeContent.tsx
|
195
195
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
196
196
|
import { useEffect } from "react";
|
197
197
|
var useOnResizeContent = (ref, callback) => {
|
198
198
|
const callbackRef = useCallbackRef(callback);
|
199
|
+
const el = ref.current;
|
199
200
|
useEffect(() => {
|
200
|
-
const el = ref.current;
|
201
201
|
if (!el) return;
|
202
202
|
const resizeObserver = new ResizeObserver(() => {
|
203
203
|
callbackRef();
|
@@ -226,7 +226,7 @@ var useOnResizeContent = (ref, callback) => {
|
|
226
226
|
resizeObserver.disconnect();
|
227
227
|
mutationObserver.disconnect();
|
228
228
|
};
|
229
|
-
}, [
|
229
|
+
}, [el, callbackRef]);
|
230
230
|
};
|
231
231
|
|
232
232
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
@@ -295,6 +295,7 @@ var ThreadViewport = forwardRef2(({ autoScroll = true, onScroll, children, ...re
|
|
295
295
|
}
|
296
296
|
);
|
297
297
|
});
|
298
|
+
ThreadViewport.displayName = "ThreadViewport";
|
298
299
|
|
299
300
|
// src/primitives/thread/ThreadMessages.tsx
|
300
301
|
import { memo } from "react";
|
@@ -499,9 +500,7 @@ var ThreadMessages = ({ components }) => {
|
|
499
500
|
|
500
501
|
// src/primitives/thread/ThreadScrollToBottom.tsx
|
501
502
|
import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
|
502
|
-
import {
|
503
|
-
Primitive as Primitive3
|
504
|
-
} from "@radix-ui/react-primitive";
|
503
|
+
import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
|
505
504
|
import { forwardRef as forwardRef3 } from "react";
|
506
505
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
507
506
|
var ThreadScrollToBottom = forwardRef3(({ onClick, ...rest }, ref) => {
|
@@ -520,12 +519,11 @@ var ThreadScrollToBottom = forwardRef3(({ onClick, ...rest }, ref) => {
|
|
520
519
|
}
|
521
520
|
);
|
522
521
|
});
|
522
|
+
ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
|
523
523
|
|
524
524
|
// src/primitives/thread/ThreadSuggestion.tsx
|
525
525
|
import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primitive";
|
526
|
-
import {
|
527
|
-
Primitive as Primitive4
|
528
|
-
} from "@radix-ui/react-primitive";
|
526
|
+
import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
|
529
527
|
import { forwardRef as forwardRef4 } from "react";
|
530
528
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
531
529
|
var ThreadSuggestion = forwardRef4(({ onClick, prompt, method, autoSend: send, ...rest }, ref) => {
|
@@ -549,6 +547,7 @@ var ThreadSuggestion = forwardRef4(({ onClick, prompt, method, autoSend: send, .
|
|
549
547
|
}
|
550
548
|
);
|
551
549
|
});
|
550
|
+
ThreadSuggestion.displayName = "ThreadSuggestion";
|
552
551
|
|
553
552
|
// src/primitives/composer/index.ts
|
554
553
|
var composer_exports = {};
|
@@ -563,10 +562,11 @@ __export(composer_exports, {
|
|
563
562
|
// src/primitives/composer/ComposerRoot.tsx
|
564
563
|
import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
|
565
564
|
import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
|
565
|
+
import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
|
566
566
|
import {
|
567
|
-
|
568
|
-
|
569
|
-
|
567
|
+
forwardRef as forwardRef5,
|
568
|
+
useRef as useRef2
|
569
|
+
} from "react";
|
570
570
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
571
571
|
var ComposerRoot = forwardRef5(
|
572
572
|
({ onSubmit, ...rest }, forwardedRef) => {
|
@@ -591,6 +591,7 @@ var ComposerRoot = forwardRef5(
|
|
591
591
|
);
|
592
592
|
}
|
593
593
|
);
|
594
|
+
ComposerRoot.displayName = "ComposerRoot";
|
594
595
|
|
595
596
|
// src/primitives/composer/ComposerInput.tsx
|
596
597
|
import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
|
@@ -665,11 +666,10 @@ var ComposerInput = forwardRef6(
|
|
665
666
|
);
|
666
667
|
}
|
667
668
|
);
|
669
|
+
ComposerInput.displayName = "ComposerInput";
|
668
670
|
|
669
671
|
// src/primitives/composer/ComposerSend.tsx
|
670
|
-
import {
|
671
|
-
Primitive as Primitive6
|
672
|
-
} from "@radix-ui/react-primitive";
|
672
|
+
import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
|
673
673
|
import { forwardRef as forwardRef7 } from "react";
|
674
674
|
import { jsx as jsx10 } from "react/jsx-runtime";
|
675
675
|
var ComposerSend = forwardRef7(
|
@@ -687,12 +687,11 @@ var ComposerSend = forwardRef7(
|
|
687
687
|
);
|
688
688
|
}
|
689
689
|
);
|
690
|
+
ComposerSend.displayName = "ComposerSend";
|
690
691
|
|
691
692
|
// src/primitives/composer/ComposerCancel.tsx
|
692
693
|
import { composeEventHandlers as composeEventHandlers6 } from "@radix-ui/primitive";
|
693
|
-
import {
|
694
|
-
Primitive as Primitive7
|
695
|
-
} from "@radix-ui/react-primitive";
|
694
|
+
import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
|
696
695
|
import { forwardRef as forwardRef8 } from "react";
|
697
696
|
import { jsx as jsx11 } from "react/jsx-runtime";
|
698
697
|
var ComposerCancel = forwardRef8(({ onClick, ...rest }, ref) => {
|
@@ -710,6 +709,7 @@ var ComposerCancel = forwardRef8(({ onClick, ...rest }, ref) => {
|
|
710
709
|
}
|
711
710
|
);
|
712
711
|
});
|
712
|
+
ComposerCancel.displayName = "ComposerCancel";
|
713
713
|
|
714
714
|
// src/primitives/message/index.ts
|
715
715
|
var message_exports = {};
|
@@ -722,9 +722,7 @@ __export(message_exports, {
|
|
722
722
|
|
723
723
|
// src/primitives/message/MessageRoot.tsx
|
724
724
|
import { composeEventHandlers as composeEventHandlers7 } from "@radix-ui/primitive";
|
725
|
-
import {
|
726
|
-
Primitive as Primitive8
|
727
|
-
} from "@radix-ui/react-primitive";
|
725
|
+
import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
|
728
726
|
import { forwardRef as forwardRef9 } from "react";
|
729
727
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
730
728
|
var MessageRoot = forwardRef9(
|
@@ -748,6 +746,7 @@ var MessageRoot = forwardRef9(
|
|
748
746
|
);
|
749
747
|
}
|
750
748
|
);
|
749
|
+
MessageRoot.displayName = "MessageRoot";
|
751
750
|
|
752
751
|
// src/primitives/message/MessageContent.tsx
|
753
752
|
import { memo as memo2 } from "react";
|
@@ -815,9 +814,7 @@ var ContentPartInProgressIndicator = () => {
|
|
815
814
|
};
|
816
815
|
|
817
816
|
// src/primitives/contentPart/ContentPartText.tsx
|
818
|
-
import {
|
819
|
-
Primitive as Primitive9
|
820
|
-
} from "@radix-ui/react-primitive";
|
817
|
+
import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
|
821
818
|
import { forwardRef as forwardRef10 } from "react";
|
822
819
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
823
820
|
var ContentPartText = forwardRef10((props, forwardedRef) => {
|
@@ -831,6 +828,7 @@ var ContentPartText = forwardRef10((props, forwardedRef) => {
|
|
831
828
|
});
|
832
829
|
return /* @__PURE__ */ jsx14(Primitive9.span, { ...props, ref: forwardedRef, children: text });
|
833
830
|
});
|
831
|
+
ContentPartText.displayName = "ContentPartText";
|
834
832
|
|
835
833
|
// src/primitives/message/MessageContent.tsx
|
836
834
|
import { Fragment, jsx as jsx15, jsxs as jsxs3 } from "react/jsx-runtime";
|
@@ -843,10 +841,8 @@ var defaultComponents = {
|
|
843
841
|
UI: () => /* @__PURE__ */ jsx15(ContentPartDisplay, {}),
|
844
842
|
tools: {
|
845
843
|
Fallback: (props) => {
|
846
|
-
const {
|
847
|
-
const Render =
|
848
|
-
(s) => s.getToolRenderer(props.part.toolName)
|
849
|
-
);
|
844
|
+
const { useToolUIs } = useAssistantContext();
|
845
|
+
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
|
850
846
|
if (!Render) return null;
|
851
847
|
return /* @__PURE__ */ jsx15(Render, { ...props });
|
852
848
|
}
|
@@ -860,6 +856,8 @@ var MessageContentPartComponent = ({
|
|
860
856
|
tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {}
|
861
857
|
} = {}
|
862
858
|
}) => {
|
859
|
+
const { useThread } = useThreadContext();
|
860
|
+
const addToolResult = useThread((t) => t.addToolResult);
|
863
861
|
const { useContentPart } = useContentPartContext();
|
864
862
|
const { part, status } = useContentPart();
|
865
863
|
const type = part.type;
|
@@ -872,7 +870,8 @@ var MessageContentPartComponent = ({
|
|
872
870
|
return /* @__PURE__ */ jsx15(UI, { part, status });
|
873
871
|
case "tool-call": {
|
874
872
|
const Tool = by_name[part.toolName] || Fallback;
|
875
|
-
|
873
|
+
const addResult = (result) => addToolResult(part.toolCallId, result);
|
874
|
+
return /* @__PURE__ */ jsx15(Tool, { part, status, addResult });
|
876
875
|
}
|
877
876
|
default:
|
878
877
|
throw new Error(`Unknown content part type: ${type}`);
|
@@ -905,10 +904,11 @@ var MessageContent = ({ components }) => {
|
|
905
904
|
};
|
906
905
|
|
907
906
|
// src/primitives/message/MessageInProgress.tsx
|
907
|
+
import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
|
908
908
|
import {
|
909
|
-
|
910
|
-
|
911
|
-
|
909
|
+
forwardRef as forwardRef11,
|
910
|
+
useMemo as useMemo2
|
911
|
+
} from "react";
|
912
912
|
import { jsx as jsx16 } from "react/jsx-runtime";
|
913
913
|
var MessageInProgress = forwardRef11((props, ref) => {
|
914
914
|
const { useMessage } = useMessageContext();
|
@@ -917,6 +917,7 @@ var MessageInProgress = forwardRef11((props, ref) => {
|
|
917
917
|
}, [useMessage, props, ref]);
|
918
918
|
return null;
|
919
919
|
});
|
920
|
+
MessageInProgress.displayName = "MessageInProgress";
|
920
921
|
|
921
922
|
// src/primitives/branchPicker/index.ts
|
922
923
|
var branchPicker_exports = {};
|
@@ -930,27 +931,25 @@ __export(branchPicker_exports, {
|
|
930
931
|
|
931
932
|
// src/utils/createActionButton.tsx
|
932
933
|
import { composeEventHandlers as composeEventHandlers8 } from "@radix-ui/primitive";
|
933
|
-
import {
|
934
|
-
Primitive as Primitive11
|
935
|
-
} from "@radix-ui/react-primitive";
|
934
|
+
import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
|
936
935
|
import { forwardRef as forwardRef12 } from "react";
|
937
936
|
import { jsx as jsx17 } from "react/jsx-runtime";
|
938
937
|
var createActionButton = (useActionButton) => {
|
939
|
-
|
940
|
-
(props
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
938
|
+
const ActionButton = forwardRef12((props, forwardedRef) => {
|
939
|
+
const onClick = useActionButton(props);
|
940
|
+
return /* @__PURE__ */ jsx17(
|
941
|
+
Primitive11.button,
|
942
|
+
{
|
943
|
+
type: "button",
|
944
|
+
disabled: !onClick,
|
945
|
+
...props,
|
946
|
+
ref: forwardedRef,
|
947
|
+
onClick: composeEventHandlers8(props.onClick, onClick ?? void 0)
|
948
|
+
}
|
949
|
+
);
|
950
|
+
});
|
951
|
+
ActionButton.displayName = "ActionButton";
|
952
|
+
return ActionButton;
|
954
953
|
};
|
955
954
|
|
956
955
|
// src/primitives/branchPicker/BranchPickerNext.tsx
|
@@ -976,14 +975,13 @@ var BranchPickerNumber = () => {
|
|
976
975
|
};
|
977
976
|
|
978
977
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
979
|
-
import {
|
980
|
-
Primitive as Primitive12
|
981
|
-
} from "@radix-ui/react-primitive";
|
978
|
+
import { Primitive as Primitive12 } from "@radix-ui/react-primitive";
|
982
979
|
import { forwardRef as forwardRef13 } from "react";
|
983
980
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
984
981
|
var BranchPickerRoot = forwardRef13(({ hideWhenSingleBranch, ...rest }, ref) => {
|
985
982
|
return /* @__PURE__ */ jsx20(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx20(Primitive12.div, { ...rest, ref }) });
|
986
983
|
});
|
984
|
+
BranchPickerRoot.displayName = "BranchPickerRoot";
|
987
985
|
|
988
986
|
// src/primitives/actionBar/index.ts
|
989
987
|
var actionBar_exports = {};
|
@@ -995,9 +993,7 @@ __export(actionBar_exports, {
|
|
995
993
|
});
|
996
994
|
|
997
995
|
// src/primitives/actionBar/ActionBarRoot.tsx
|
998
|
-
import {
|
999
|
-
Primitive as Primitive13
|
1000
|
-
} from "@radix-ui/react-primitive";
|
996
|
+
import { Primitive as Primitive13 } from "@radix-ui/react-primitive";
|
1001
997
|
import { forwardRef as forwardRef14 } from "react";
|
1002
998
|
import { jsx as jsx21 } from "react/jsx-runtime";
|
1003
999
|
var ActionBarRoot = forwardRef14(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
|
@@ -1025,6 +1021,7 @@ var ActionBarRoot = forwardRef14(({ hideWhenRunning, autohide, autohideFloat, ..
|
|
1025
1021
|
}
|
1026
1022
|
);
|
1027
1023
|
});
|
1024
|
+
ActionBarRoot.displayName = "ActionBarRoot";
|
1028
1025
|
|
1029
1026
|
// src/primitives/actionBar/ActionBarCopy.tsx
|
1030
1027
|
var ActionBarCopy = createActionButton(useCopyMessage);
|
@@ -1045,9 +1042,7 @@ __export(contentPart_exports, {
|
|
1045
1042
|
});
|
1046
1043
|
|
1047
1044
|
// src/primitives/contentPart/ContentPartImage.tsx
|
1048
|
-
import {
|
1049
|
-
Primitive as Primitive14
|
1050
|
-
} from "@radix-ui/react-primitive";
|
1045
|
+
import { Primitive as Primitive14 } from "@radix-ui/react-primitive";
|
1051
1046
|
import { forwardRef as forwardRef15 } from "react";
|
1052
1047
|
import { jsx as jsx22 } from "react/jsx-runtime";
|
1053
1048
|
var ContentPartImage = forwardRef15((props, forwardedRef) => {
|
@@ -1061,6 +1056,7 @@ var ContentPartImage = forwardRef15((props, forwardedRef) => {
|
|
1061
1056
|
});
|
1062
1057
|
return /* @__PURE__ */ jsx22(Primitive14.img, { src: image, ...props, ref: forwardedRef });
|
1063
1058
|
});
|
1059
|
+
ContentPartImage.displayName = "ContentPartImage";
|
1064
1060
|
|
1065
1061
|
// src/runtime/local/useLocalRuntime.tsx
|
1066
1062
|
import { useInsertionEffect, useState as useState3 } from "react";
|
@@ -1342,6 +1338,9 @@ var LocalRuntime = class {
|
|
1342
1338
|
this._configProviders.add(provider);
|
1343
1339
|
return () => this._configProviders.delete(provider);
|
1344
1340
|
}
|
1341
|
+
addToolResult() {
|
1342
|
+
throw new Error("LocalRuntime does not yet support tool results");
|
1343
|
+
}
|
1345
1344
|
};
|
1346
1345
|
|
1347
1346
|
// src/runtime/local/useLocalRuntime.tsx
|
@@ -1389,18 +1388,18 @@ var makeAssistantModelConfigStore = () => create4(() => {
|
|
1389
1388
|
};
|
1390
1389
|
});
|
1391
1390
|
|
1392
|
-
// src/context/stores/
|
1391
|
+
// src/context/stores/AssistantToolUIs.ts
|
1393
1392
|
import { create as create5 } from "zustand";
|
1394
|
-
var
|
1393
|
+
var makeAssistantToolUIsStore = () => create5((set) => {
|
1395
1394
|
const renderers = /* @__PURE__ */ new Map();
|
1396
1395
|
return {
|
1397
|
-
|
1396
|
+
getToolUI: (name) => {
|
1398
1397
|
const arr = renderers.get(name);
|
1399
1398
|
const last = arr?.at(-1);
|
1400
1399
|
if (last) return last;
|
1401
1400
|
return null;
|
1402
1401
|
},
|
1403
|
-
|
1402
|
+
setToolUI: (name, render) => {
|
1404
1403
|
let arr = renderers.get(name);
|
1405
1404
|
if (!arr) {
|
1406
1405
|
arr = [];
|
@@ -1455,7 +1454,8 @@ var makeThreadStore = (runtimeRef) => {
|
|
1455
1454
|
switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),
|
1456
1455
|
startRun: (parentId) => runtimeRef.current.startRun(parentId),
|
1457
1456
|
append: (message) => runtimeRef.current.append(message),
|
1458
|
-
cancelRun: () => runtimeRef.current.cancelRun()
|
1457
|
+
cancelRun: () => runtimeRef.current.cancelRun(),
|
1458
|
+
addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
|
1459
1459
|
}));
|
1460
1460
|
const onRuntimeUpdate = () => {
|
1461
1461
|
useThread.setState({
|
@@ -1532,8 +1532,8 @@ var AssistantProvider = ({ children, runtime }) => {
|
|
1532
1532
|
});
|
1533
1533
|
const [context] = useState5(() => {
|
1534
1534
|
const useModelConfig = makeAssistantModelConfigStore();
|
1535
|
-
const
|
1536
|
-
return { useModelConfig,
|
1535
|
+
const useToolUIs = makeAssistantToolUIsStore();
|
1536
|
+
return { useModelConfig, useToolUIs };
|
1537
1537
|
});
|
1538
1538
|
const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
|
1539
1539
|
useEffect7(() => {
|