@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/dist/index.js CHANGED
@@ -934,10 +934,8 @@ var defaultComponents = {
934
934
  UI: () => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ContentPartDisplay, {}),
935
935
  tools: {
936
936
  Fallback: (props) => {
937
- const { useToolRenderers } = useAssistantContext();
938
- const Render = useToolRenderers(
939
- (s) => s.getToolRenderer(props.part.toolName)
940
- );
937
+ const { useToolUIs } = useAssistantContext();
938
+ const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
941
939
  if (!Render) return null;
942
940
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Render, { ...props });
943
941
  }
@@ -951,6 +949,8 @@ var MessageContentPartComponent = ({
951
949
  tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {}
952
950
  } = {}
953
951
  }) => {
952
+ const { useThread } = useThreadContext();
953
+ const addToolResult = useThread((t) => t.addToolResult);
954
954
  const { useContentPart } = useContentPartContext();
955
955
  const { part, status } = useContentPart();
956
956
  const type = part.type;
@@ -963,7 +963,8 @@ var MessageContentPartComponent = ({
963
963
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(UI, { part, status });
964
964
  case "tool-call": {
965
965
  const Tool = by_name[part.toolName] || Fallback;
966
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Tool, { part, status });
966
+ const addResult = (result) => addToolResult(part.toolCallId, result);
967
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Tool, { part, status, addResult });
967
968
  }
968
969
  default:
969
970
  throw new Error(`Unknown content part type: ${type}`);
@@ -1427,6 +1428,9 @@ var LocalRuntime = class {
1427
1428
  this._configProviders.add(provider);
1428
1429
  return () => this._configProviders.delete(provider);
1429
1430
  }
1431
+ addToolResult() {
1432
+ throw new Error("LocalRuntime does not yet support tool results");
1433
+ }
1430
1434
  };
1431
1435
 
1432
1436
  // src/runtime/local/useLocalRuntime.tsx
@@ -1474,18 +1478,18 @@ var makeAssistantModelConfigStore = () => (0, import_zustand4.create)(() => {
1474
1478
  };
1475
1479
  });
1476
1480
 
1477
- // src/context/stores/AssistantToolRenderers.ts
1481
+ // src/context/stores/AssistantToolUIs.ts
1478
1482
  var import_zustand5 = require("zustand");
1479
- var makeAssistantToolRenderersStore = () => (0, import_zustand5.create)((set) => {
1483
+ var makeAssistantToolUIsStore = () => (0, import_zustand5.create)((set) => {
1480
1484
  const renderers = /* @__PURE__ */ new Map();
1481
1485
  return {
1482
- getToolRenderer: (name) => {
1486
+ getToolUI: (name) => {
1483
1487
  const arr = renderers.get(name);
1484
1488
  const last = arr?.at(-1);
1485
1489
  if (last) return last;
1486
1490
  return null;
1487
1491
  },
1488
- setToolRenderer: (name, render) => {
1492
+ setToolUI: (name, render) => {
1489
1493
  let arr = renderers.get(name);
1490
1494
  if (!arr) {
1491
1495
  arr = [];
@@ -1540,7 +1544,8 @@ var makeThreadStore = (runtimeRef) => {
1540
1544
  switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),
1541
1545
  startRun: (parentId) => runtimeRef.current.startRun(parentId),
1542
1546
  append: (message) => runtimeRef.current.append(message),
1543
- cancelRun: () => runtimeRef.current.cancelRun()
1547
+ cancelRun: () => runtimeRef.current.cancelRun(),
1548
+ addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
1544
1549
  }));
1545
1550
  const onRuntimeUpdate = () => {
1546
1551
  useThread.setState({
@@ -1617,8 +1622,8 @@ var AssistantProvider = ({ children, runtime }) => {
1617
1622
  });
1618
1623
  const [context] = (0, import_react36.useState)(() => {
1619
1624
  const useModelConfig = makeAssistantModelConfigStore();
1620
- const useToolRenderers = makeAssistantToolRenderersStore();
1621
- return { useModelConfig, useToolRenderers };
1625
+ const useToolUIs = makeAssistantToolUIsStore();
1626
+ return { useModelConfig, useToolUIs };
1622
1627
  });
1623
1628
  const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
1624
1629
  (0, import_react36.useEffect)(() => {