import { type B4ContentPart } from "@b4run/sdk"; /** * Result of unwrapping a tool's return value. * * - `content` is what becomes the ToolMessage content the agent sees: a string, * or the ordered content parts the tool returned. * Built rules: * • A branded denial (`toolDenial(reason)` from a permission or constraint * wrapper) is the reason string verbatim; the brand is for the converter * (`isToolDenial`), never for the model. * • A non-empty content-part array (returned plainly, or as a wrapped * `result`) is kept as parts. An empty array is JSON `[]`, as before. * • If the tool returned a wrapped `{result}` shape and `result` is a string, * `content` is that string verbatim (no JSON quoting). * • If `result` is any other value, `content` is `JSON.stringify(result)`. * • If the tool returned a plain value (no wrapper), `content` is * `JSON.stringify(value)`. * * - `stateUpdates` is the partial state-channel update object to apply, or * undefined if the tool didn't request any state mutation. */ export interface UnwrappedToolResult { readonly content: string | readonly B4ContentPart[]; readonly stateUpdates: Record | undefined; } /** * Detect whether a tool's return value uses the B4.run wrapper shape * `{result, state?}` and split it into the agent-facing `content` and the * optional `stateUpdates` for the route's state channels. * * The wrapper shape is recognized strictly: the value must be a non-null * plain object whose own enumerable keys are exactly `result`, or exactly * `result` and `state`. Any other shape (including objects with extra keys, * missing `result`, or arrays) falls through to plain-return handling. * * Edge case: if a tool returns `{result: undefined}`, the wrapper IS detected * structurally but the resulting `content` would be the string "undefined" * (JSON.stringify(undefined) === undefined). We treat this as plain — capability * authors should never return undefined as the agent-facing result. */ export declare function unwrapToolResult(value: unknown): UnwrappedToolResult; //# sourceMappingURL=unwrap-tool-result.d.ts.map