-
Notifications
You must be signed in to change notification settings - Fork 7
CLOUD-4325 work-on-box-issue-122 #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@upstash/box": minor | ||
| --- | ||
|
|
||
| Add `toolCallId` to `tool-call` chunks and add a new `tool-result` chunk variant to the streaming `Chunk` union. This lets consumers reliably match results back to their originating call when an agent runs multiple tools in parallel, and removes the need to intercept `tool_result` from the `unknown` event variant. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -826,7 +826,11 @@ export class Box<TProvider = unknown> { | |||||||||
| break; | ||||||||||
| } | ||||||||||
| case "tool": { | ||||||||||
| options.onToolUse?.({ name: parsed.name, input: parsed.input }); | ||||||||||
| options.onToolUse?.({ | ||||||||||
| name: parsed.name, | ||||||||||
| input: parsed.input, | ||||||||||
|
Comment on lines
+830
to
+831
|
||||||||||
| name: parsed.name, | |
| input: parsed.input, | |
| name: parsed.name ?? "", | |
| input: parsed.input ?? {}, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -385,7 +385,35 @@ export type Chunk = | |
| | { type: "start"; runId: string } | ||
| | { type: "text-delta"; text: string } | ||
| | { type: "reasoning"; text: string } | ||
| | { type: "tool-call"; toolName: string; input: Record<string, unknown> } | ||
| | { | ||
| type: "tool-call"; | ||
| /** | ||
| * Stable identifier for this tool invocation. Use this to match a | ||
| * `tool-result` chunk back to its originating call when multiple tool | ||
| * calls are in flight in the same turn. | ||
| * | ||
| * May be an empty string for older agents that don't surface an ID. | ||
| */ | ||
| toolCallId: string; | ||
| toolName: string; | ||
| input: Record<string, unknown>; | ||
| } | ||
| | { | ||
| type: "tool-result"; | ||
| /** | ||
| * Identifier of the `tool-call` chunk this result corresponds to. | ||
| * | ||
| * May be an empty string when the backend does not provide an ID | ||
| * (e.g. older agents or the OpenCode provider). | ||
| */ | ||
| toolCallId: string; | ||
| /** Name of the tool that produced this result, when known. */ | ||
| toolName?: string; | ||
| /** Tool output payload. Shape is tool-specific. */ | ||
| output: unknown; | ||
| /** True when the tool reported an error. */ | ||
| isError?: boolean; | ||
| } | ||
|
Comment on lines
+401
to
+416
|
||
| | { | ||
| type: "finish"; | ||
| output: string; | ||
|
|
@@ -431,7 +459,7 @@ export interface StreamOptions<TProvider = unknown> { | |
| /** Timeout in milliseconds — aborts if exceeded */ | ||
| timeout?: number; | ||
| /** Tool use callback — called when the agent invokes a tool (Read, Write, Bash, etc.) */ | ||
| onToolUse?: (tool: { name: string; input: Record<string, unknown> }) => void; | ||
| onToolUse?: (tool: { name: string; input: Record<string, unknown>; toolCallId?: string }) => void; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -451,7 +479,7 @@ export interface RunOptions<T = undefined, TProvider = unknown> { | |
| /** Retries with exponential backoff on transient failures */ | ||
| maxRetries?: number; | ||
| /** Tool use callback — called when the agent invokes a tool (Read, Write, Bash, etc.) */ | ||
| onToolUse?: (tool: { name: string; input: Record<string, unknown> }) => void; | ||
| onToolUse?: (tool: { name: string; input: Record<string, unknown>; toolCallId?: string }) => void; | ||
| /** Webhook — fire-and-forget, POST to URL on completion */ | ||
| webhook?: WebhookConfig; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
tool_resultparsing has multiple fallback branches (tool_use_idvsid, andoutputvscontent), but the added test only covers thetool_use_id+outputpath. Adding a couple assertions/events to exercise the other branches would help prevent regressions if the backend payload shape varies.