import type { TypeToken } from "../di"; import type { CredentialRequirement } from "../contracts/credentialTypes"; import type { Expr } from "../contracts/params"; import type { Item, Items, JsonValue, NodeExecutionContext, NodeOutputs, RunnableNodeConfig, RunnableNodeInputJson, } from "../types"; import type { input as ZodInput, output as ZodOutput, ZodType } from "zod"; export interface AgentCanvasPresentation { readonly label?: string; readonly icon?: TIcon; } export type ZodSchemaAny = ZodType; export interface ToolConfig { readonly type: TypeToken; readonly name: string; readonly description?: string; readonly presentation?: AgentCanvasPresentation; getCredentialRequirements?(): ReadonlyArray; } export type ToolExecuteArgs = Readonly<{ config: TConfig; input: TInput; ctx: NodeExecutionContext; item: Item; itemIndex: number; items: Items; hooks?: Readonly<{ parentSpan?: import("../contracts/telemetryTypes").TelemetrySpanScope; parentInvocationId?: import("../contracts/runTypes").ConnectionInvocationId; }>; }>; export interface Tool< TConfig extends ToolConfig = ToolConfig, TInputSchema extends ZodSchemaAny = ZodSchemaAny, TOutputSchema extends ZodSchemaAny = ZodSchemaAny, > { readonly defaultDescription: string; readonly inputSchema: TInputSchema; readonly outputSchema: TOutputSchema; execute( args: ToolExecuteArgs>, ): Promise> | ZodOutput; } export type AgentTool< TInputSchema extends ZodSchemaAny = ZodSchemaAny, TOutputSchema extends ZodSchemaAny = ZodSchemaAny, > = Tool; export type AgentToolExecuteArgs = ToolExecuteArgs; export type AgentToolToken = TypeToken>; export type AgentMessageRole = "system" | "user" | "assistant"; export type AgentMessageBuildArgs = Readonly<{ item: Item; itemIndex: number; items: Items; ctx: NodeExecutionContext; }>; export interface AgentMessageDto { readonly role: AgentMessageRole; readonly content: string; } export type AgentMessageTemplateContent = | string | ((args: AgentMessageBuildArgs) => string); export interface AgentMessageTemplate { readonly role: AgentMessageRole; readonly content: AgentMessageTemplateContent; } export type AgentMessageLine = AgentMessageDto | AgentMessageTemplate; export type AgentMessageConfig = | Expr>, TInputJson> | ReadonlyArray> | { readonly prompt?: ReadonlyArray>; readonly buildMessages?: (args: AgentMessageBuildArgs) => ReadonlyArray; }; export type AgentTurnLimitBehavior = "error" | "respondWithLastMessage"; export interface AgentModelInvocationOptions { readonly maxTokens?: number; readonly providerOptions?: Readonly>; } export interface AgentGuardrailConfig { readonly maxTurns?: number; readonly onTurnLimitReached?: AgentTurnLimitBehavior; readonly modelInvocationOptions?: AgentModelInvocationOptions; } export const AgentGuardrailDefaults = { maxTurns: 10, onTurnLimitReached: "error" as AgentTurnLimitBehavior, } as const; export interface AgentToolDefinition { readonly name: string; readonly description: string; readonly inputSchema: ZodSchemaAny; } export type AgentToolCall = Readonly<{ id?: string; name: string; input: unknown }>; export type AgentToolCallPlanner<_TNodeConfig = unknown> = ( item: Item, index: number, items: Items, ctx: NodeExecutionContext, ) => ReadonlyArray; export interface ChatModelConfig { readonly type: TypeToken>; readonly name: string; readonly provider?: string; readonly modelName?: string; readonly presentation?: AgentCanvasPresentation; getCredentialRequirements?(): ReadonlyArray; } export interface ChatLanguageModel { readonly languageModel: unknown; readonly modelName: string; readonly provider?: string; readonly defaultCallOptions?: ChatLanguageModelCallOptions; } export interface ChatLanguageModelCallOptions { readonly maxOutputTokens?: number; readonly temperature?: number; readonly providerOptions?: Readonly>>>; } export interface StructuredOutputOptions { readonly schemaName?: string; readonly strict?: boolean; } export interface ChatModelFactory { create( args: Readonly<{ config: TConfig; ctx: NodeExecutionContext }>, ): Promise | ChatLanguageModel; } export type NodeBackedToolInputMapperArgs< TNodeConfig extends RunnableNodeConfig, TToolInput = unknown, > = Readonly<{ input: TToolInput; item: Item; itemIndex: number; items: Items; ctx: NodeExecutionContext; node: TNodeConfig; }>; export type NodeBackedToolOutputMapperArgs< TNodeConfig extends RunnableNodeConfig, TToolInput = unknown, > = Readonly<{ input: TToolInput; item: Item; itemIndex: number; items: Items; ctx: NodeExecutionContext; node: TNodeConfig; outputs: NodeOutputs; }>; export type NodeBackedToolInputMapper, TToolInput = unknown> = ( args: NodeBackedToolInputMapperArgs, ) => Item> | RunnableNodeInputJson; export type NodeBackedToolOutputMapper< TNodeConfig extends RunnableNodeConfig, TToolInput = unknown, TToolOutput = unknown, > = (args: NodeBackedToolOutputMapperArgs) => TToolOutput; export type NodeBackedToolConfigOptions< TNodeConfig extends RunnableNodeConfig, TInputSchema extends ZodSchemaAny, TOutputSchema extends ZodSchemaAny, > = Readonly<{ description?: string; presentation?: AgentCanvasPresentation; inputSchema: TInputSchema; outputSchema: TOutputSchema; mapInput?: NodeBackedToolInputMapper>; mapOutput?: NodeBackedToolOutputMapper, ZodOutput>; onRejected?: "halt" | "return"; }>; export interface AgentNodeConfig extends RunnableNodeConfig< TInputJson, TOutputJson > { readonly messages: AgentMessageConfig; readonly chatModel: ChatModelConfig; readonly tools?: ReadonlyArray; readonly guardrails?: AgentGuardrailConfig; readonly outputSchema?: ZodType; } export type AgentAttachmentRole = "languageModel" | "tool" | "nestedAgent"; export { NodeBackedToolConfig } from "./NodeBackedToolConfig"; export { CallableToolConfig } from "./CallableToolConfig"; export type { CallableToolConfigOptions, CallableToolExecuteHandler } from "./CallableToolConfig"; export { CallableToolFactory } from "./CallableToolFactory"; export { CallableToolKindToken } from "./CallableToolKindToken"; export { AgentToolFactory } from "./AgentToolFactory"; export { AgentMessageConfigNormalizer } from "./AgentMessageConfigNormalizerFactory"; export { AgentConfigInspector } from "./AgentConfigInspectorFactory";