bs-agent 0.0.29 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,9 +29,11 @@ type MessagePart = {
29
29
  inputs: any;
30
30
  sequence: number;
31
31
  paused?: boolean;
32
- status?: "pending" | "submitted";
32
+ status?: "pending" | "submitted" | "error";
33
33
  /** Persisted result from a tool submission (handler or widget submit). */
34
34
  result?: any;
35
+ /** Error message if the handler failed. */
36
+ error?: string;
35
37
  } | {
36
38
  type: "tool_call";
37
39
  toolName: string;
@@ -128,9 +130,11 @@ interface ClientToolRenderProps<T = any> {
128
130
  /** Submit a result back to the agent (only available when `await: true`). */
129
131
  submit: (result: any) => void;
130
132
  /** Current status of this widget instance. */
131
- status: "pending" | "submitted";
133
+ status: "pending" | "submitted" | "error";
132
134
  /** The persisted result from a previous submission (available after submit or on reload). */
133
135
  result?: any;
136
+ /** Error message if the handler failed (only present when status is "error"). */
137
+ error?: string;
134
138
  }
135
139
  interface ClientToolConfig<TParams = any> {
136
140
  /** Tool name — must match the name the agent knows. */
@@ -205,8 +209,9 @@ interface ToolRendererProps {
205
209
  callId: string;
206
210
  inputs: any;
207
211
  paused?: boolean;
208
- status?: "pending" | "submitted";
212
+ status?: "pending" | "submitted" | "error";
209
213
  result?: any;
214
+ error?: string;
210
215
  };
211
216
  }
212
217
  /**
@@ -446,6 +446,18 @@ function handleToolCallEnd(event, setMessages, syncSessionRef) {
446
446
  break;
447
447
  }
448
448
  }
449
+ for (let i = updatedParts.length - 1; i >= 0; i--) {
450
+ const part = updatedParts[i];
451
+ if (part.type === "widget" && part.callId === callId) {
452
+ updatedParts[i] = {
453
+ ...part,
454
+ status: error ? "error" : "submitted",
455
+ ...result !== void 0 ? { result } : {},
456
+ ...error ? { error } : {}
457
+ };
458
+ break;
459
+ }
460
+ }
449
461
  const updated = { ...last, parts: updatedParts };
450
462
  const updatedMessages = replaceLastAgent(prev, updated);
451
463
  if (syncSessionRef.current) syncSessionRef.current(updatedMessages);
@@ -1020,7 +1032,17 @@ function handleEvent(event, _fullText, callbacks, clientTools, onPaused, onAutoR
1020
1032
  meta: event.meta
1021
1033
  });
1022
1034
  return { callId, result };
1023
- } catch (error) {
1035
+ } catch (handlerError) {
1036
+ callbacks.onEvent?.({
1037
+ type: "tool_call_end",
1038
+ data: {
1039
+ callId,
1040
+ toolName,
1041
+ toolType: "client",
1042
+ error: handlerError instanceof Error ? handlerError.message : String(handlerError)
1043
+ },
1044
+ meta: event.meta
1045
+ });
1024
1046
  callbacks.onPaused?.(toolName, inputs);
1025
1047
  onPaused?.({ callId, toolName, args: inputs });
1026
1048
  return null;
@@ -1635,7 +1657,8 @@ function ToolRenderer({ agentId, part }) {
1635
1657
  submit: part.paused ? handleSubmit : () => {
1636
1658
  },
1637
1659
  status: localStatus,
1638
- result: part.result
1660
+ result: part.result,
1661
+ error: part.error
1639
1662
  });
1640
1663
  }
1641
1664
  export {