@assistant-ui/react 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +92 -6
- 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-XVZ2GVQM.mjs → chunk-RITM2IUH.mjs} +1 -1
- package/dist/{chunk-XVZ2GVQM.mjs.map → chunk-RITM2IUH.mjs.map} +1 -1
- package/dist/experimental.d.mts +13 -13
- package/dist/experimental.d.ts +13 -13
- package/dist/experimental.js +26 -26
- 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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -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";
|
@@ -841,10 +841,8 @@ var defaultComponents = {
|
|
841
841
|
UI: () => /* @__PURE__ */ jsx15(ContentPartDisplay, {}),
|
842
842
|
tools: {
|
843
843
|
Fallback: (props) => {
|
844
|
-
const {
|
845
|
-
const Render =
|
846
|
-
(s) => s.getToolRenderer(props.part.toolName)
|
847
|
-
);
|
844
|
+
const { useToolUIs } = useAssistantContext();
|
845
|
+
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
|
848
846
|
if (!Render) return null;
|
849
847
|
return /* @__PURE__ */ jsx15(Render, { ...props });
|
850
848
|
}
|
@@ -858,6 +856,8 @@ var MessageContentPartComponent = ({
|
|
858
856
|
tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {}
|
859
857
|
} = {}
|
860
858
|
}) => {
|
859
|
+
const { useThread } = useThreadContext();
|
860
|
+
const addToolResult = useThread((t) => t.addToolResult);
|
861
861
|
const { useContentPart } = useContentPartContext();
|
862
862
|
const { part, status } = useContentPart();
|
863
863
|
const type = part.type;
|
@@ -870,7 +870,8 @@ var MessageContentPartComponent = ({
|
|
870
870
|
return /* @__PURE__ */ jsx15(UI, { part, status });
|
871
871
|
case "tool-call": {
|
872
872
|
const Tool = by_name[part.toolName] || Fallback;
|
873
|
-
|
873
|
+
const addResult = (result) => addToolResult(part.toolCallId, result);
|
874
|
+
return /* @__PURE__ */ jsx15(Tool, { part, status, addResult });
|
874
875
|
}
|
875
876
|
default:
|
876
877
|
throw new Error(`Unknown content part type: ${type}`);
|
@@ -1337,6 +1338,9 @@ var LocalRuntime = class {
|
|
1337
1338
|
this._configProviders.add(provider);
|
1338
1339
|
return () => this._configProviders.delete(provider);
|
1339
1340
|
}
|
1341
|
+
addToolResult() {
|
1342
|
+
throw new Error("LocalRuntime does not yet support tool results");
|
1343
|
+
}
|
1340
1344
|
};
|
1341
1345
|
|
1342
1346
|
// src/runtime/local/useLocalRuntime.tsx
|
@@ -1384,18 +1388,18 @@ var makeAssistantModelConfigStore = () => create4(() => {
|
|
1384
1388
|
};
|
1385
1389
|
});
|
1386
1390
|
|
1387
|
-
// src/context/stores/
|
1391
|
+
// src/context/stores/AssistantToolUIs.ts
|
1388
1392
|
import { create as create5 } from "zustand";
|
1389
|
-
var
|
1393
|
+
var makeAssistantToolUIsStore = () => create5((set) => {
|
1390
1394
|
const renderers = /* @__PURE__ */ new Map();
|
1391
1395
|
return {
|
1392
|
-
|
1396
|
+
getToolUI: (name) => {
|
1393
1397
|
const arr = renderers.get(name);
|
1394
1398
|
const last = arr?.at(-1);
|
1395
1399
|
if (last) return last;
|
1396
1400
|
return null;
|
1397
1401
|
},
|
1398
|
-
|
1402
|
+
setToolUI: (name, render) => {
|
1399
1403
|
let arr = renderers.get(name);
|
1400
1404
|
if (!arr) {
|
1401
1405
|
arr = [];
|
@@ -1450,7 +1454,8 @@ var makeThreadStore = (runtimeRef) => {
|
|
1450
1454
|
switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),
|
1451
1455
|
startRun: (parentId) => runtimeRef.current.startRun(parentId),
|
1452
1456
|
append: (message) => runtimeRef.current.append(message),
|
1453
|
-
cancelRun: () => runtimeRef.current.cancelRun()
|
1457
|
+
cancelRun: () => runtimeRef.current.cancelRun(),
|
1458
|
+
addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
|
1454
1459
|
}));
|
1455
1460
|
const onRuntimeUpdate = () => {
|
1456
1461
|
useThread.setState({
|
@@ -1527,8 +1532,8 @@ var AssistantProvider = ({ children, runtime }) => {
|
|
1527
1532
|
});
|
1528
1533
|
const [context] = useState5(() => {
|
1529
1534
|
const useModelConfig = makeAssistantModelConfigStore();
|
1530
|
-
const
|
1531
|
-
return { useModelConfig,
|
1535
|
+
const useToolUIs = makeAssistantToolUIsStore();
|
1536
|
+
return { useModelConfig, useToolUIs };
|
1532
1537
|
});
|
1533
1538
|
const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
|
1534
1539
|
useEffect7(() => {
|