Types
The shapes the methods take and return.
1 min read
Types
Tool
interface Tool {
name: string; // e.g., "codespar_pay"
description: string; // Human-readable, shown to LLMs
input_schema: Record<string, unknown>; // JSON Schema
server: string; // Server that provides this tool
}ToolResult
interface ToolResult {
success: boolean;
data: unknown; // Tool output (varies by tool)
error: string | null; // Error message if failed
duration: number; // Execution time in ms
server: string; // Server that executed the tool
tool: string; // Tool name
tool_call_id?: string; // Unique ID for audit
called_at?: string; // ISO 8601 timestamp
}LoopConfig
interface LoopConfig {
steps: LoopStep[];
onStepComplete?: (step: LoopStep, result: ToolResult, index: number) => void;
onStepError?: (step: LoopStep, error: Error, index: number) => void;
retryPolicy?: {
maxRetries?: number;
backoff?: "linear" | "exponential";
baseDelay?: number;
};
abortOnError?: boolean; // default: true
}
interface LoopStep {
tool: string;
params: Record<string, unknown> | ((prevResults: ToolResult[]) => Record<string, unknown>);
when?: (prevResults: ToolResult[]) => boolean;
}LoopResult
interface LoopResult {
success: boolean;
results: ToolResult[];
duration: number; // Total execution time in ms
completedSteps: number;
totalSteps: number;
}SendResult
interface SendResult {
message: string; // Final agent response text
tool_calls: ToolCallRecord[]; // Tools called during execution
iterations: number; // Model iterations
}StreamEvent
type StreamEvent =
| { type: "user_message"; content: string }
| { type: "assistant_text"; content: string; iteration: number }
| { type: "tool_use"; id: string; name: string; input: Record<string, unknown> }
| { type: "tool_result"; toolCall: ToolCallRecord }
| { type: "done"; result: SendResult }
| { type: "error"; error: string; message?: string };ToolCallRecord
interface ToolCallRecord {
id: string;
tool_name: string;
server_id: string;
status: "success" | "error";
duration_ms: number;
input: unknown;
output: unknown;
error_code: string | null;
}ServerConnection
interface ServerConnection {
id: string;
name: string;
category: string;
country: string;
auth_type: "api_key" | "path_secret" | "oauth" | "cert" | "hmac_signed" | "none";
connected: boolean;
}AuthResult
interface AuthResult {
connected: boolean;
redirectUrl?: string; // OAuth redirect URL
error?: string;
}