/** * Top level types to avoid circular dependencies */ import { type JSONSchemaType } from "ajv"; import type { EngineResponse } from "./EngineResponse.js"; /** * Parameters for sending a query. */ export interface QueryEngineParamsBase { query: string; } export interface QueryEngineParamsStreaming extends QueryEngineParamsBase { stream: true; } export interface QueryEngineParamsNonStreaming extends QueryEngineParamsBase { stream?: false | null; } /** * A query engine is a question answerer that can use one or more steps. */ export interface QueryEngine { /** * Query the query engine and get a response. * @param params */ query(params: QueryEngineParamsStreaming): Promise>; query(params: QueryEngineParamsNonStreaming): Promise; } type Known = { [key: string]: Known; } | [Known, ...Known[]] | Known[] | number | string | boolean | null; export type ToolMetadata = Record> = { description: string; name: string; /** * OpenAI uses JSON Schema to describe the parameters that a tool can take. * @link https://json-schema.org/understanding-json-schema */ parameters?: Parameters; }; /** * Simple Tool interface. Likely to change. */ export interface BaseTool { /** * This could be undefined if the implementation is not provided, * which might be the case when communicating with a llm. * * @return {JSONValue | Promise} The output of the tool. */ call?: (input: Input) => JSONValue | Promise; metadata: Input extends Known ? ToolMetadata> : ToolMetadata; } export type BaseToolWithCall = Omit, "call"> & { call: NonNullable, "call">["call"]>; }; /** * An OutputParser is used to extract structured data from the raw output of the LLM. */ export interface BaseOutputParser { parse(output: string): T; format(output: string): string; } /** * StructuredOutput is just a combo of the raw output and the parsed output. */ export interface StructuredOutput { rawOutput: string; parsedOutput: T; } export type ToolMetadataOnlyDescription = Pick; export declare class QueryBundle { queryStr: string; constructor(queryStr: string); toString(): string; } export type UUID = `${string}-${string}-${string}-${string}-${string}`; export type JSONValue = string | number | boolean | JSONObject | JSONArray; export type JSONObject = { [key: string]: JSONValue; }; type JSONArray = Array; export type ToolOutput = { tool: BaseTool | undefined; input: JSONObject; output: JSONValue; isError: boolean; }; export {};