UNPKG

agentswarm

Version:

LLM-agnostic typescript framework for creating OpenAI-style Swarm agents with the Vercel AI SDK

71 lines (70 loc) 2.74 kB
import z from 'zod'; import { type CoreTool, type JSONValue, type TextStreamPart } from 'ai'; /** * Deep-copy an object using JSON.parse and JSON.stringify. This will not work for complex objects, and may be slow * as your object size increases * @param object */ export declare function deepCopy<T>(object: any): T; export declare const jsonValueSchema: z.ZodType<JSONValue>; export type JSONSerializableObject = { [key: string]: JSONValue; }; export type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>; export declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>; /** * Creates a stitchable stream that can pipe one stream at a time. * * @template T - The type of values emitted by the streams. * @returns {Object} An object containing the stitchable stream and control methods. */ export declare function createStitchableStream<T>(): { stream: ReadableStream<T>; addStream: (innerStream: ReadableStream<T>) => void; enqueue: (c: T) => void; close: () => void; }; /** * Creates a Promise with externally accessible resolve and reject functions. * * @template T - The type of the value that the Promise will resolve to. * @returns An object containing: * - promise: A Promise that can be resolved or rejected externally. * - resolve: A function to resolve the Promise with a value of type T. * - reject: A function to reject the Promise with an error. */ export declare function createResolvablePromise<T = any>(): { promise: Promise<T>; resolve: (value: T) => void; reject: (error: unknown) => void; }; /** * Types copied/pasted from AI SDK so that I can add the 'handover' property */ export type EnrichedStreamPart<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPUT> = { part: TextStreamPart<TOOLS>; partialOutput: PARTIAL_OUTPUT | undefined; }; type TextStreamPartWithoutToolResult<TOOLS extends Record<string, CoreTool>> = Exclude<TextStreamPart<TOOLS>, { type: 'tool-result'; }>; type TextStreamPartToolResult<TOOLS extends Record<string, CoreTool>> = Extract<TextStreamPart<TOOLS>, { type: 'tool-result'; }>; type NewToolResultPart<TOOLS extends Record<string, CoreTool>> = TextStreamPartToolResult<TOOLS> & { handedOverTo?: { name: string; id: string; }; }; export type ExtendedTextStreamPart<TOOLS extends Record<string, CoreTool>> = (TextStreamPartWithoutToolResult<TOOLS> | NewToolResultPart<TOOLS>) & { agent: { id: string; name: string; }; }; export type ExtendedEnrichedStreamPart<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPUT> = { part: ExtendedTextStreamPart<TOOLS>; partialOutput: PARTIAL_OUTPUT | undefined; }; export {};