import type { z } from 'zod'; import type { CompiledTool, ExecutionGuard, ToolDefinition } from './capabilities.js'; import type { AgentEvaluation, CompiledEvaluation, DeepReadonly, EvaluatorInput, WeightedPass } from './evaluation.js'; import type { PortableResource, ResourceDeclaration, ResourceDefinition, Skill } from './resources.js'; /** Raw JSON Schema preserves complete contracts and platform-specific annotations. */ export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; }; export type JsonSchema = { [key: string]: JsonValue; }; export type DefinitionSchema = z.ZodType | JsonSchema; export type InferSchema = [S] extends [never] ? unknown : S extends z.ZodType ? z.output : unknown; /** Shared envelope; future worker definitions can use this without changing agents. */ export interface AutomationDefinition { readonly kind: K; readonly inputSchema?: I; readonly outputSchema?: O; } export interface AgentEmailAlias { address: string; /** Omitted leaves platform ownership unchanged; [] explicitly denies all senders. */ allowlist?: string[]; replyConfig?: { [key: string]: JsonValue; }; requireSenderAuth?: boolean; enabled?: boolean; } /** Additive sandbox capability. Paths are relative; package versions must be exact. */ export interface FilesystemOptions { /** Omit for the agent folder; use a repo-relative path to override, or null for no checkout. Paths use ASCII letters, digits, _, ., - and / only; no traversal. */ cwd?: string | null; /** Directory skills require the filesystem capability. */ skills?: Record; /** UTF-8 seed files relative to cwd. Existing differing files are never overwritten. */ files?: Record; /** Extra sandbox dependencies, combined with repository package manifests. */ packages?: { python?: Record; npm?: Record; }; } export interface AgentConfig { name: string; description?: string; model?: string; instructions?: string; filesystem?: boolean; /** Normalized sandbox capability; author with .withFilesystem(). */ workspace?: FilesystemOptions; guards?: ExecutionGuard[]; triggers?: { api?: boolean; email?: { enabled?: boolean; aliases?: (string | AgentEmailAlias)[]; }; }; } export interface AgentOptions extends Omit { /** Zod 4 or raw JSON object schema for run input. Zod infers types; raw schemas infer unknown. No transforms or defaults. */ inputSchema?: I; /** Zod 4 or raw JSON object schema for the final answer. Zod infers evaluator/selector arguments; raw schemas infer unknown. */ outputSchema?: O; /** Import default-exported resource.ts declarations. Keys are local aliases in resource tools and sandbox paths. Files are captured at release, not read by this factory. */ resources?: Record; /** Model-facing names mapped to createTool definitions. Up to 16; built-in names such as read, bash and resource_read are reserved. */ tools?: Record>; } export interface AgentCore extends AutomationDefinition<'agent', I, O> { /** Opt into a sandbox without changing schemas, tools, evaluators or the pass rule. Returns a new definition at the same authoring stage; replaces previous filesystem settings. */ withFilesystem(options?: FilesystemOptions): this; readonly config: DeepReadonly; readonly resources?: Readonly>; readonly tools?: Readonly>>; readonly evaluation?: AgentEvaluation, never>; } type IsUnion = T extends Whole ? ([Whole] extends [T] ? false : true) : never; type EvaluatorName = string extends N ? never : true extends IsUnion ? never : N; export interface AgentDefinition extends AgentCore { /** Register a named score from 0 to 1. Output types flow into the callback/selector; filesystem capability remains composable. */ defineEvaluator(name: N & EvaluatorName, evaluate: EvaluatorInput>): AgentEvaluators>; } /** Evaluation registration preserves filesystem composition; pass closes evaluation registration. */ export interface AgentEvaluators> extends AgentCore { /** Register a named score from 0 to 1. Output types flow into the callback/selector; filesystem capability remains composable. */ defineEvaluator(name: N & EvaluatorName & (N extends keyof S ? never : N), evaluate: EvaluatorInput>): AgentEvaluators>; /** Finish evaluation registration with one typed predicate or weightedScore decision. Filesystem capability can still be extended. */ defineEvalPass>(pass: ((scores: Readonly) => boolean) | (WeightedPass & { readonly weights: Partial & Record, never>; })): AgentCore; } export type InferInput> = InferSchema>; export type InferOutput> = InferSchema>; /** Versioned data, separate from source syntax and from any execution engine. */ export interface CompiledDefinition { schemaVersion: 1; kind: K; inputSchema?: JsonSchema; outputSchema?: JsonSchema; } export interface CompiledAgent extends CompiledDefinition<'agent'> { manifest: AgentConfig & { schemaVersion: 1; filesystem: boolean; }; resources?: Record; tools?: Record; evaluation?: CompiledEvaluation; } export {};