@langchain/langgraph-sdk
Version:
Client library for interacting with the LangGraph API
73 lines (72 loc) • 3.14 kB
text/typescript
import { ToolsEvent } from "@langchain/protocol";
//#region src/client/stream/handles/tools.d.ts
/**
* High-level outcome of a single tool call.
*/
type ToolCallStatus = "running" | "finished" | "error";
/** Shared metadata for assembled tool-call handles. */
interface ToolCallBase<TName extends string = string, TInput = unknown> {
readonly name: TName;
readonly callId: string;
/**
* Pre-v1 alias for {@link callId}. Matches `ToolCallWithResult.id` and
* `ToolCall.id` on message-level tool calls.
*/
readonly id: string;
readonly namespace: string[];
readonly input: TInput;
/**
* Pre-v1 alias for {@link input}. Matches `ToolCallFromTool` `args`.
*/
readonly args: TInput;
}
/**
* Script-oriented tool handle from the client SDK (`ThreadStream.toolCalls`,
* subagent/subgraph projections). Completion and errors are surfaced only
* through {@link output}.
*/
interface ClientAssembledToolCall<TName extends string = string, TInput = unknown, TOutput = unknown> extends ToolCallBase<TName, TInput> {
readonly output: Promise<TOutput>;
}
/**
* Reactive tool handle for framework bindings (`stream.toolCalls`,
* `useToolCalls`, `injectToolCalls`).
*
* {@link status}, {@link error}, and {@link output} are plain values that
* the assembler updates in place as tool events arrive. That lets React,
* Vue, Svelte, and Angular re-render from a snapshot on each store tick
* without `await`, effects, or Suspense boundaries around a promise.
* {@link ClientAssembledToolCall} keeps a promise-based {@link output}
* instead for script consumers that read tool results sequentially.
*
* {@link output} is `null` while the call is running or after it fails;
* successful completion sets it to the parsed tool return value (objects
* and strings are unwrapped from ToolMessage wire envelopes when needed).
*/
interface AssembledToolCall<TName extends string = string, TInput = unknown, TOutput = unknown> extends ToolCallBase<TName, TInput> {
readonly output: TOutput | null;
readonly status: ToolCallStatus;
readonly error: string | undefined;
}
/**
* Parse wire-format tool payloads into structured values.
*
* Tool events may carry JSON-encoded object strings on the wire; this
* helper normalises them to plain objects for consumers. Non-JSON strings
* are returned unchanged.
*/
declare function parseToolPayload(value: unknown): unknown;
/**
* Parse a `tool-finished` output payload into the tool's return value.
*
* Wire events often wrap structured tool results in a ToolMessage-shaped
* object (`{ type: "tool", content: "..." }`) or a LangGraph
* {@link Command} whose `update.messages` carries the ToolMessage.
* This unwraps those envelopes, JSON-decodes string content when possible,
* and leaves plain strings as-is. Returns `null` when a ToolMessage envelope
* is present but its content cannot be normalised.
*/
declare function parseToolOutput(value: unknown, toolCallId?: string): unknown | null;
//#endregion
export { AssembledToolCall, ClientAssembledToolCall, ToolCallStatus, parseToolOutput, parseToolPayload };
//# sourceMappingURL=tools.d.cts.map