UNPKG

jorel

Version:

A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.

235 lines (234 loc) 9.57 kB
import { LlmMessageBase, LlmToolCall, ToolCallClassification, WithToolCalls } from "../providers"; /** * Generic type for messages that contain tool calls * This allows consumers to add additional fields while still using the toolkit */ interface WithToolCallsMessage extends LlmMessageBase, WithToolCalls { role: "assistant_with_tools"; } /** * Options for tool call operations */ interface ToolCallOperationOptions { /** Specific tool call IDs to target. If not provided, applies to all applicable calls */ toolCallIds?: string | string[]; } /** * Static utilities for working with individual tool calls */ declare class LlmToolCallUtilities { /** * Extract tool calls that require approval * @param toolCalls - Array of tool calls * @returns Array of tool calls that require approval */ extractRequiringApproval(toolCalls: LlmToolCall[]): LlmToolCall[]; /** * Extract tool calls that are pending execution * @param toolCalls - Array of tool calls * @returns Array of tool calls that are pending execution */ extractPending(toolCalls: LlmToolCall[]): LlmToolCall[]; /** * Extract tool calls that are completed * @param toolCalls - Array of tool calls * @returns Array of tool calls that are completed */ extractCompleted(toolCalls: LlmToolCall[]): LlmToolCall[]; /** * Extract tool calls that have errors * @param toolCalls - Array of tool calls * @returns Array of tool calls that have errors */ extractErrored(toolCalls: LlmToolCall[]): LlmToolCall[]; /** * Classify tool calls * @param toolCalls - Array of tool calls * @returns Classification of the tool calls */ classify(toolCalls: LlmToolCall[]): ToolCallClassification; /** * Check if any tool calls require approval * @param toolCalls - Array of tool calls * @returns True if any tool calls require approval */ hasRequiringApproval(toolCalls: LlmToolCall[]): boolean; /** * Check if any tool calls are pending * @param toolCalls - Array of tool calls * @returns True if any tool calls are pending execution */ hasPending(toolCalls: LlmToolCall[]): boolean; /** * Approve tool calls * @param toolCalls - Array of tool calls * @param options - Options for the operation * @returns New array with approved tool calls */ approve(toolCalls: LlmToolCall[], options?: ToolCallOperationOptions): LlmToolCall[]; /** * Reject tool calls * @param toolCalls - Array of tool calls * @param options - Options for the operation * @returns New array with rejected tool calls */ reject(toolCalls: LlmToolCall[], options?: ToolCallOperationOptions): LlmToolCall[]; /** * Cancel tool calls * @param toolCalls - Array of tool calls * @param options - Options for the operation * @returns New array with cancelled tool calls */ cancel(toolCalls: LlmToolCall[], options?: ToolCallOperationOptions): LlmToolCall[]; } /** * Utilities for working with messages containing tool calls */ declare class LlmMessageUtilities { /** * Extract tool calls that require approval from an object with tool calls * @param input - The object with tool calls * @returns Array of tool calls that require approval */ extractToolCallsRequiringApproval<T extends WithToolCalls>(input: T): LlmToolCall[]; /** * Extract tool calls that are pending execution from an object with tool calls * @param input - The object with tool calls * @returns Array of tool calls that are pending execution */ extractPendingToolCalls<T extends WithToolCalls>(input: T): LlmToolCall[]; /** * Extract tool calls that are completed from an object with tool calls * @param input - The object with tool calls * @returns Array of tool calls that are completed */ extractCompletedToolCalls<T extends WithToolCalls>(input: T): LlmToolCall[]; /** * Extract tool calls that have errors from an object with tool calls * @param input - The object with tool calls * @returns Array of tool calls that have errors */ extractErroredToolCalls<T extends WithToolCalls>(input: T): LlmToolCall[]; /** * Classify the tool calls in an object with tool calls * @param input - The object with tool calls * @returns Classification of the tool calls */ classifyToolCalls<T extends WithToolCalls>(input: T): ToolCallClassification; /** * Check if an object has any tool calls requiring approval * @param input - The object with tool calls * @returns True if any tool calls require approval */ hasToolCallsRequiringApproval<T extends WithToolCalls>(input: T): boolean; /** * Check if an object has any pending tool calls * @param input - The object with tool calls * @returns True if any tool calls are pending execution */ hasPendingToolCalls<T extends WithToolCalls>(input: T): boolean; /** * Approve tool calls in an object with tool calls * @param input - The object with tool calls * @param options - Options for the operation * @returns New object with approved tool calls */ approveToolCalls<T extends WithToolCalls>(input: T, options?: ToolCallOperationOptions): T; /** * Reject tool calls in an object with tool calls * @param input - The object with tool calls * @param options - Options for the operation * @returns New object with rejected tool calls */ rejectToolCalls<T extends WithToolCalls>(input: T, options?: ToolCallOperationOptions): T; /** * Cancel tool calls in an object with tool calls * @param input - The object with tool calls * @param options - Options for the operation * @returns New object with cancelled tool calls */ cancelToolCalls<T extends WithToolCalls>(input: T, options?: ToolCallOperationOptions): T; } /** * Utilities for working with arrays of messages */ declare class LlmMessagesUtilities { /** * Find messages with tool calls requiring approval in a message list * @param messages - Array of mixed messages * @returns Array of messages that have tool calls requiring approval */ extractMessagesWithApprovalRequired<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[]): Extract<T, WithToolCallsMessage>[]; /** * Find messages with pending tool calls in a message list * @param messages - Array of mixed messages * @returns Array of messages that have pending tool calls */ extractMessagesWithPendingToolCalls<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[]): Extract<T, WithToolCallsMessage>[]; /** * Find the latest message with tool calls requiring approval * @param messages - Array of mixed messages * @returns The latest message with tool calls requiring approval, or null if none found */ getLatestMessageWithApprovalRequired<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[]): Extract<T, WithToolCallsMessage> | null; /** * Approve tool calls in messages * @param messages - Array of mixed messages * @param options - Options for the operation * @returns New array of messages with approved tool calls */ approveToolCalls<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[], options?: ToolCallOperationOptions): T[]; /** * Reject tool calls in messages * @param messages - Array of mixed messages * @param options - Options for the operation * @returns New array of messages with rejected tool calls */ rejectToolCalls<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[], options?: ToolCallOperationOptions): T[]; /** * Cancel tool calls in messages * @param messages - Array of mixed messages * @param options - Options for the operation * @returns New array of messages with cancelled tool calls */ cancelToolCalls<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[], options?: ToolCallOperationOptions): T[]; /** * Check if an object has any pending tool calls * @param input - The object with tool calls * @returns True if any tool calls are pending execution */ extractPendingToolCalls<T extends WithToolCallsMessage | LlmMessageBase>(input: T[]): (LlmToolCall & { messageId: string; })[]; /** * Get the number of pending tool calls in a message list * @param messages - Array of mixed messages * @returns Number of pending tool calls */ getNumberOfPendingToolCalls<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[]): number; /** * Get a summary of tool call states across all messages * @param messages - Array of mixed messages * @returns Summary of tool call states */ getToolCallSummary<T extends WithToolCallsMessage | LlmMessageBase>(messages: T[]): { totalToolCalls: number; requiresApproval: number; approved: number; rejected: number; pending: number; inProgress: number; completed: number; cancelled: number; errored: number; }; } /** * Utilities for working with tool calls and messages */ export declare class LlmToolKitUtilities { readonly calls: LlmToolCallUtilities; readonly message: LlmMessageUtilities; readonly messages: LlmMessagesUtilities; } export {};