@standardagents/spec 0.11.0-next.174a940 → 0.11.0-next.24f9ff1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,159 +1,4 @@
1
- import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion } from 'zod';
2
-
3
- /**
4
- * Model definition types for Standard Agents.
5
- *
6
- * Models define LLM configurations including provider, model ID, pricing,
7
- * and fallback chains. Models are referenced by name from prompts.
8
- *
9
- * @module
10
- */
11
- /**
12
- * Supported LLM provider identifiers.
13
- *
14
- * Each provider requires a corresponding API key environment variable:
15
- * - `openai` → `OPENAI_API_KEY`
16
- * - `openrouter` → `OPENROUTER_API_KEY`
17
- * - `anthropic` → `ANTHROPIC_API_KEY`
18
- * - `google` → `GOOGLE_API_KEY`
19
- * - `test` → No API key required (for testing with scripted responses)
20
- */
21
- type ModelProvider = 'openai' | 'openrouter' | 'anthropic' | 'google' | 'test';
22
- /**
23
- * Model capability flags indicating supported features.
24
- */
25
- interface ModelCapabilities {
26
- /**
27
- * Whether the model supports vision (image understanding).
28
- * When true, image attachments will be sent to the model as part of the request.
29
- * Models like GPT-4o, Claude 3, and Gemini support vision.
30
- */
31
- vision?: boolean;
32
- /**
33
- * Whether the model supports function calling (tool use).
34
- * Most modern models support this, defaults to true if not specified.
35
- */
36
- functionCalling?: boolean;
37
- /**
38
- * Whether the model supports structured outputs (JSON mode).
39
- */
40
- structuredOutputs?: boolean;
41
- }
42
- /**
43
- * Model definition configuration.
44
- *
45
- * Defines an LLM model with its provider, pricing, capabilities, and fallback chain.
46
- *
47
- * @template N - The model name as a string literal type for type inference
48
- *
49
- * @example
50
- * ```typescript
51
- * import { defineModel } from '@standardagents/spec';
52
- *
53
- * export default defineModel({
54
- * name: 'gpt-4o',
55
- * provider: 'openai',
56
- * model: 'gpt-4o',
57
- * fallbacks: ['gpt-4-turbo', 'gpt-3.5-turbo'],
58
- * inputPrice: 2.5,
59
- * outputPrice: 10,
60
- * });
61
- * ```
62
- */
63
- interface ModelDefinition<N extends string = string> {
64
- /**
65
- * Unique name for this model definition.
66
- * Used as the identifier when referencing from prompts.
67
- * Should be descriptive and consistent (e.g., 'gpt-4o', 'claude-3-opus').
68
- */
69
- name: N;
70
- /**
71
- * The LLM provider to use for API calls.
72
- * The corresponding API key environment variable must be set.
73
- */
74
- provider: ModelProvider;
75
- /**
76
- * The actual model identifier sent to the provider API.
77
- *
78
- * For OpenAI: 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', etc.
79
- * For OpenRouter: 'openai/gpt-4o', 'anthropic/claude-3-opus', etc.
80
- * For Anthropic: 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', etc.
81
- * For Google: 'gemini-1.5-pro', 'gemini-1.5-flash', etc.
82
- */
83
- model: string;
84
- /**
85
- * Optional list of additional provider prefixes for OpenRouter.
86
- * Allows routing through specific providers when using OpenRouter.
87
- *
88
- * @example ['anthropic', 'google'] - prefer Anthropic, fallback to Google
89
- */
90
- includedProviders?: string[];
91
- /**
92
- * Fallback model names to try if this model fails.
93
- * Referenced by model name (must be defined in agents/models/).
94
- * Tried in order after primary model exhausts retries.
95
- *
96
- * @example ['gpt-4', 'gpt-3.5-turbo']
97
- */
98
- fallbacks?: string[];
99
- /**
100
- * Cost per 1 million input tokens in USD.
101
- * Used for cost tracking and reporting in logs.
102
- */
103
- inputPrice?: number;
104
- /**
105
- * Cost per 1 million output tokens in USD.
106
- * Used for cost tracking and reporting in logs.
107
- */
108
- outputPrice?: number;
109
- /**
110
- * Cost per 1 million cached input tokens in USD.
111
- * Some providers offer reduced pricing for cached/repeated prompts.
112
- */
113
- cachedPrice?: number;
114
- /**
115
- * Model capabilities - features this model supports.
116
- */
117
- capabilities?: ModelCapabilities;
118
- }
119
- /**
120
- * Defines an LLM model configuration.
121
- *
122
- * Models are the foundation of the agent system - they specify which
123
- * AI model to use and how to connect to it. Models can have fallbacks
124
- * for reliability and include pricing for cost tracking.
125
- *
126
- * @template N - The model name as a string literal type
127
- * @param options - Model configuration options
128
- * @returns The model definition for registration
129
- *
130
- * @example
131
- * ```typescript
132
- * // agents/models/gpt_4o.ts
133
- * import { defineModel } from '@standardagents/spec';
134
- *
135
- * export default defineModel({
136
- * name: 'gpt-4o',
137
- * provider: 'openai',
138
- * model: 'gpt-4o',
139
- * fallbacks: ['gpt-4-turbo'],
140
- * inputPrice: 2.5,
141
- * outputPrice: 10,
142
- * });
143
- * ```
144
- *
145
- * @example
146
- * ```typescript
147
- * // Using OpenRouter with provider preferences
148
- * export default defineModel({
149
- * name: 'claude-3-opus',
150
- * provider: 'openrouter',
151
- * model: 'anthropic/claude-3-opus',
152
- * includedProviders: ['anthropic'],
153
- * });
154
- * ```
155
- */
156
- declare function defineModel<N extends string>(options: ModelDefinition<N>): ModelDefinition<N>;
1
+ import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion, ZodTypeAny } from 'zod';
157
2
 
158
3
  /**
159
4
  * Effect definition types for Standard Agents.
@@ -304,6 +149,10 @@ interface Message {
304
149
  silent?: boolean;
305
150
  /** Custom metadata */
306
151
  metadata?: Record<string, unknown>;
152
+ /** Message processing status */
153
+ status?: 'pending' | 'completed' | 'failed' | null;
154
+ /** Tool execution status (for tool result messages) */
155
+ tool_status?: 'success' | 'error' | null;
307
156
  }
308
157
  /**
309
158
  * Input for injecting a new message.
@@ -977,6 +826,30 @@ type ToolArgsRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
977
826
  * @template D - Maximum nesting depth (default: 7)
978
827
  */
979
828
  type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
829
+ /**
830
+ * Raw shape for tenv schema - uses same pattern as ToolArgsRawShape.
831
+ * Each key is a tenv name, value is a Zod schema for validation.
832
+ *
833
+ * @template D - Maximum nesting depth (default: 7)
834
+ */
835
+ type TenvRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
836
+ /**
837
+ * Top-level thread environment variable schema.
838
+ *
839
+ * Defines which thread environment variables a tool requires.
840
+ * Required tenvs are non-optional fields, optional tenvs use .optional().
841
+ *
842
+ * @example
843
+ * ```typescript
844
+ * z.object({
845
+ * vectorStoreId: z.string().describe('OpenAI Vector Store ID'), // Required
846
+ * userLocation: z.string().optional().describe('User location'), // Optional
847
+ * })
848
+ * ```
849
+ *
850
+ * @template D - Maximum nesting depth (default: 7)
851
+ */
852
+ type ToolTenvs<D extends number = 7> = z.ZodObject<TenvRawShape<D>>;
980
853
  /**
981
854
  * Tool function signature.
982
855
  *
@@ -988,114 +861,985 @@ type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
988
861
  */
989
862
  type Tool<State = ThreadState, Args extends ToolArgs | null = null> = Args extends ToolArgs ? (state: State, args: z.infer<Args>) => Promise<ToolResult> : (state: State) => Promise<ToolResult>;
990
863
  /**
991
- * Return type of defineTool function.
864
+ * Options for defining a tool.
992
865
  *
993
- * A tuple containing:
994
- * - Tool description string
995
- * - Argument schema (or null)
996
- * - Tool implementation function
866
+ * @template State - The state type (defaults to ThreadState)
867
+ * @template Args - The Zod schema for tool arguments, or null for no args
868
+ * @template Tenvs - The Zod schema for thread environment variables, or null
997
869
  */
998
- type ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null> = [string, Args, Tool<State, Args>];
870
+ interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
871
+ /** Description of what the tool does (shown to the LLM). */
872
+ description: string;
873
+ /** Zod schema for validating tool arguments. Omit for tools with no args. */
874
+ args?: Args;
875
+ /** The tool implementation function. */
876
+ execute: Tool<State, Args>;
877
+ /** Zod schema for thread environment variables the tool requires. */
878
+ tenvs?: Tenvs;
879
+ /**
880
+ * Where this tool is executed:
881
+ * - 'local': Execute locally by the execution engine (default)
882
+ * - 'provider': Executed by the LLM provider, results come in response
883
+ */
884
+ executionMode?: 'local' | 'provider';
885
+ /**
886
+ * Which provider executes this tool (when executionMode='provider').
887
+ * e.g., 'openai', 'anthropic'
888
+ */
889
+ executionProvider?: string;
890
+ }
999
891
  /**
1000
- * Define a tool with arguments.
892
+ * Tool definition object returned by defineTool().
893
+ *
894
+ * Contains all the metadata and implementation needed to register
895
+ * and execute a tool.
1001
896
  *
1002
- * @param toolDescription - Description of what the tool does (shown to the LLM)
1003
- * @param args - Zod schema for validating tool arguments
1004
- * @param tool - The tool implementation function
1005
- * @returns A tuple containing the tool definition
897
+ * @template State - The state type (defaults to ThreadState)
898
+ * @template Args - The Zod schema for tool arguments, or null for no args
899
+ * @template Tenvs - The Zod schema for thread environment variables, or null
1006
900
  */
1007
- declare function defineTool<State = ThreadState, Args extends ToolArgs = ToolArgs>(toolDescription: string, args: Args, tool: Tool<State, Args>): ToolDefinition<State, Args>;
901
+ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
902
+ /** Description of what the tool does (shown to the LLM). */
903
+ description: string;
904
+ /** Zod schema for validating tool arguments, or null for no args. */
905
+ args: Args;
906
+ /** The tool implementation function. */
907
+ execute: Tool<State, Args>;
908
+ /** Zod schema for thread environment variables, or null if none. */
909
+ tenvs: Tenvs;
910
+ /**
911
+ * Where this tool is executed:
912
+ * - 'local': Execute locally by the execution engine (default)
913
+ * - 'provider': Executed by the LLM provider, results come in response
914
+ */
915
+ executionMode?: 'local' | 'provider';
916
+ /**
917
+ * Which provider executes this tool (when executionMode='provider').
918
+ */
919
+ executionProvider?: string;
920
+ }
1008
921
  /**
1009
- * Define a tool without arguments.
922
+ * Defines a tool that agents can call during execution.
923
+ *
924
+ * Tools are the primary way agents interact with external systems.
925
+ * Each tool has a description (shown to the LLM), optional argument
926
+ * schema (validated at runtime), an implementation function, and
927
+ * optional thread environment variable (tenv) requirements.
928
+ *
929
+ * @example
930
+ * ```typescript
931
+ * import { defineTool } from '@standardagents/spec';
932
+ * import { z } from 'zod';
933
+ *
934
+ * // Tool with arguments
935
+ * export default defineTool({
936
+ * description: 'Search the knowledge base for relevant information',
937
+ * args: z.object({
938
+ * query: z.string().describe('Search query'),
939
+ * limit: z.number().optional().describe('Max results'),
940
+ * }),
941
+ * execute: async (state, args) => {
942
+ * const results = await search(args.query, args.limit);
943
+ * return { status: 'success', result: JSON.stringify(results) };
944
+ * },
945
+ * });
1010
946
  *
1011
- * @param toolDescription - Description of what the tool does (shown to the LLM)
1012
- * @param tool - The tool implementation function
1013
- * @returns A tuple containing the tool definition
947
+ * // Tool without arguments
948
+ * export default defineTool({
949
+ * description: 'Get the current server time',
950
+ * execute: async (state) => {
951
+ * return { status: 'success', result: new Date().toISOString() };
952
+ * },
953
+ * });
954
+ *
955
+ * // Tool with tenvs (thread environment variables)
956
+ * export default defineTool({
957
+ * description: 'Search through uploaded files',
958
+ * args: z.object({ query: z.string() }),
959
+ * execute: async (state, args) => ({ status: 'success', result: 'done' }),
960
+ * tenvs: z.object({
961
+ * vectorStoreId: z.string().describe('OpenAI Vector Store ID'),
962
+ * }),
963
+ * });
964
+ *
965
+ * // Provider-executed tool (e.g., OpenAI built-in tools)
966
+ * export default defineTool({
967
+ * description: 'Generate images using DALL-E',
968
+ * args: z.object({ prompt: z.string() }),
969
+ * execute: async () => ({ status: 'success', result: 'Handled by provider' }),
970
+ * executionMode: 'provider',
971
+ * executionProvider: 'openai',
972
+ * });
973
+ * ```
974
+ *
975
+ * @param options - Tool definition options
976
+ * @returns A tool definition object
1014
977
  */
1015
- declare function defineTool<State = ThreadState>(toolDescription: string, tool: Tool<State, null>): ToolDefinition<State, null>;
978
+ declare function defineTool<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null>(options: DefineToolOptions<State, Args, Tenvs>): ToolDefinition<State, Args, Tenvs>;
1016
979
 
1017
980
  /**
1018
- * Prompt definition types for Standard Agents.
981
+ * Provider types for Standard Agents.
1019
982
  *
1020
- * Prompts define LLM interaction configurations including the system prompt,
1021
- * model selection, available tools, and various behavioral options.
983
+ * These types define the interface between Standard Agents and LLM providers.
984
+ * Provider packages implement these types to integrate with different LLM APIs.
1022
985
  *
1023
986
  * @module
1024
987
  */
1025
988
 
1026
989
  /**
1027
- * A text part of a prompt - static text content.
1028
- *
1029
- * @example
1030
- * ```typescript
1031
- * { type: 'text', content: 'You are a helpful assistant.\n\n' }
1032
- * ```
990
+ * Stripped-down response summary for async metadata fetching.
991
+ * Intentionally excludes content/attachments to avoid passing large data.
1033
992
  */
1034
- interface PromptTextPart {
1035
- type: 'text';
1036
- /** The text content */
1037
- content: string;
993
+ interface ResponseSummary {
994
+ /** Provider-specific response/generation ID */
995
+ responseId?: string;
996
+ /** Model that handled the request */
997
+ model: string;
998
+ /** How the response ended */
999
+ finishReason: ProviderFinishReason;
1000
+ /** Token usage (without detailed breakdowns) */
1001
+ usage: {
1002
+ promptTokens: number;
1003
+ completionTokens: number;
1004
+ totalTokens: number;
1005
+ };
1038
1006
  }
1039
1007
  /**
1040
- * A prompt inclusion part - includes another prompt's content.
1041
- *
1042
- * @example
1043
- * ```typescript
1044
- * { type: 'include', prompt: 'responder_rules' }
1045
- * ```
1008
+ * Model information returned by provider's getModels method.
1046
1009
  */
1047
- interface PromptIncludePart {
1048
- type: 'include';
1049
- /** The name of the prompt to include */
1050
- prompt: string;
1010
+ interface ProviderModelInfo {
1011
+ /** The model identifier used in API calls (e.g., 'gpt-4o', 'anthropic/claude-3-opus') */
1012
+ id: string;
1013
+ /** Human-readable display name */
1014
+ name: string;
1015
+ /** Optional description of the model */
1016
+ description?: string;
1017
+ /** Optional context window size in tokens */
1018
+ contextLength?: number;
1019
+ /** Optional icon identifier for UI display */
1020
+ iconId?: string;
1021
+ /** Optional slug for additional lookups (e.g., OpenRouter endpoint queries) */
1022
+ slug?: string;
1051
1023
  }
1052
1024
  /**
1053
- * A single part of a structured prompt.
1054
- * Discriminated union on `type` field for TypeScript narrowing.
1055
- */
1056
- type PromptPart = PromptTextPart | PromptIncludePart;
1057
- /**
1058
- * A structured prompt is an array of prompt parts.
1059
- * Provides composition with other prompts via includes.
1060
- *
1061
- * @example
1062
- * ```typescript
1063
- * prompt: [
1064
- * { type: 'text', content: 'You are a helpful assistant.\n\n' },
1065
- * { type: 'include', prompt: 'common_rules' },
1066
- * { type: 'text', content: '\n\nBe concise.' },
1067
- * ]
1068
- * ```
1069
- */
1070
- type StructuredPrompt = PromptPart[];
1071
- /**
1072
- * The prompt content can be either a plain string or a structured array.
1073
- *
1074
- * @example
1075
- * ```typescript
1076
- * // Simple string prompt:
1077
- * prompt: 'You are a helpful assistant.'
1078
- *
1079
- * // Structured prompt with includes:
1080
- * prompt: [
1081
- * { type: 'text', content: 'You are a helpful assistant.\n\n' },
1082
- * { type: 'include', prompt: 'common_rules' },
1083
- * ]
1084
- * ```
1085
- */
1086
- type PromptContent = string | StructuredPrompt;
1087
- /**
1088
- * Configuration for sub-prompts used as tools.
1089
- * These options control how results from sub-prompts are returned to the caller.
1090
- *
1091
- * @template T - The sub-prompt name type (for type-safe references)
1025
+ * Provider interface - thin translation layer between Standard Agents and LLM APIs
1092
1026
  */
1093
- interface SubpromptConfig<T extends string = string> {
1027
+ interface LLMProviderInterface {
1028
+ readonly name: string;
1029
+ readonly specificationVersion: '1';
1094
1030
  /**
1095
- * Name of the sub-prompt to call.
1096
- * Must be a prompt defined in agents/prompts/.
1031
+ * Non-streaming generation
1097
1032
  */
1098
- name: T;
1033
+ generate(request: ProviderRequest): Promise<ProviderResponse>;
1034
+ /**
1035
+ * Streaming generation
1036
+ */
1037
+ stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
1038
+ /**
1039
+ * Check if this provider supports a model
1040
+ */
1041
+ supportsModel?(modelId: string): boolean;
1042
+ /**
1043
+ * List available models from this provider.
1044
+ * Optional for backwards compatibility - providers may implement this
1045
+ * to enable model selection in the UI.
1046
+ *
1047
+ * @param filter - Optional search string to filter models by name/id
1048
+ * @returns Array of available models
1049
+ */
1050
+ getModels?(filter?: string): Promise<ProviderModelInfo[]>;
1051
+ /**
1052
+ * Fetch capabilities for a specific model.
1053
+ * Optional for backwards compatibility - providers may implement this
1054
+ * to enable auto-detection of model features in the UI.
1055
+ *
1056
+ * @param modelId - The model identifier (e.g., 'gpt-4o', 'anthropic/claude-3-opus')
1057
+ * @returns The model capabilities, or null if not available
1058
+ */
1059
+ getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
1060
+ /**
1061
+ * Get tools embedded in this provider.
1062
+ * Optional - providers may implement this to expose built-in tools
1063
+ * (e.g., OpenAI's web_search, file_search, code_interpreter).
1064
+ *
1065
+ * These tools are defined using defineTool() with optional tenv requirements.
1066
+ * Tools returned here can be referenced by name in model/prompt definitions.
1067
+ *
1068
+ * @param modelId - Optional filter to get tools available for a specific model
1069
+ * @returns Record of tool name to tool definition (sync or async)
1070
+ */
1071
+ getTools?(modelId?: string): Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>>>;
1072
+ /**
1073
+ * Get an icon for this provider or a specific model.
1074
+ * Optional - providers may implement this to provide UI icons.
1075
+ *
1076
+ * **Preferred return format: SVG data URI** (e.g., 'data:image/svg+xml,...')
1077
+ *
1078
+ * The data URI format allows icons to be embedded directly in the UI without
1079
+ * additional network requests. Use the `svgToDataUri()` helper from provider
1080
+ * packages to convert SVG strings.
1081
+ *
1082
+ * Return value can be:
1083
+ * - A data URI (e.g., 'data:image/svg+xml,...') - **PREFERRED**
1084
+ * - A full URL (e.g., 'https://example.com/icon.svg')
1085
+ * - An icon identifier that the UI resolves (legacy)
1086
+ *
1087
+ * For providers like OpenRouter that host many models, the modelId parameter
1088
+ * allows returning different icons based on the model's origin lab
1089
+ * (e.g., 'anthropic/claude-3-opus' -> anthropic icon).
1090
+ *
1091
+ * @param modelId - Optional model ID to get a model-specific icon
1092
+ * @returns SVG data URI (preferred), URL, icon identifier, or undefined
1093
+ *
1094
+ * @example
1095
+ * ```typescript
1096
+ * // Provider returning its own icon
1097
+ * getIcon() {
1098
+ * return svgToDataUri(OPENAI_ICON);
1099
+ * }
1100
+ *
1101
+ * // Provider returning model-specific icon (e.g., OpenRouter)
1102
+ * getIcon(modelId?: string) {
1103
+ * if (modelId) {
1104
+ * const lab = modelId.split('/')[0]; // 'anthropic' from 'anthropic/claude-3'
1105
+ * return getLabIconDataUri(lab);
1106
+ * }
1107
+ * return svgToDataUri(OPENROUTER_ICON);
1108
+ * }
1109
+ * ```
1110
+ */
1111
+ getIcon?(modelId?: string): string | undefined;
1112
+ /**
1113
+ * Transform a ProviderRequest to the provider's native format for inspection/debugging.
1114
+ * Returns the transformed request as it would be sent to the provider's API.
1115
+ *
1116
+ * This is used by the admin UI to view logged requests in provider-specific format,
1117
+ * helping debug issues like message transformation or tool handling.
1118
+ *
1119
+ * Implementations should truncate base64 data to ~50 chars for readability.
1120
+ *
1121
+ * @param request - The Standard Agents format request to transform
1122
+ * @returns The transformed request in the provider's native format
1123
+ */
1124
+ inspectRequest?(request: ProviderRequest): Promise<InspectedRequest>;
1125
+ /**
1126
+ * Fetch additional metadata about a completed response.
1127
+ * Called asynchronously after the response is received - does not block the main execution flow.
1128
+ *
1129
+ * This is useful for providers (like aggregators) where complete metadata isn't available
1130
+ * immediately. The execution engine calls this in the background and uses the returned
1131
+ * data to update log records.
1132
+ *
1133
+ * @param summary - Stripped-down response info (no content/attachments)
1134
+ * @param signal - Optional abort signal for cancellation
1135
+ * @returns Additional metadata or null if unavailable
1136
+ */
1137
+ getResponseMetadata?(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
1138
+ }
1139
+ /**
1140
+ * Result from inspectRequest() - the transformed request in provider's native format
1141
+ */
1142
+ interface InspectedRequest {
1143
+ /** The transformed request body as it would be sent to the API */
1144
+ body: Record<string, unknown>;
1145
+ /** Path to the messages array within body (e.g., "input" for OpenAI, "messages" for others) */
1146
+ messagesPath: string;
1147
+ /** Optional: Additional metadata about the transformation */
1148
+ metadata?: {
1149
+ /** The API endpoint that would be called */
1150
+ endpoint?: string;
1151
+ /** Headers that would be sent (excluding auth) */
1152
+ headers?: Record<string, string>;
1153
+ };
1154
+ }
1155
+ /**
1156
+ * Standard Agent request format - providers translate to their native format
1157
+ */
1158
+ interface ProviderRequest {
1159
+ model: string;
1160
+ messages: ProviderMessage[];
1161
+ tools?: ProviderTool[];
1162
+ toolChoice?: 'auto' | 'none' | 'required' | {
1163
+ name: string;
1164
+ };
1165
+ parallelToolCalls?: boolean;
1166
+ maxOutputTokens?: number;
1167
+ temperature?: number;
1168
+ topP?: number;
1169
+ topK?: number;
1170
+ stopSequences?: string[];
1171
+ reasoning?: {
1172
+ level?: number;
1173
+ maxTokens?: number;
1174
+ exclude?: boolean;
1175
+ };
1176
+ responseFormat?: {
1177
+ type: 'text';
1178
+ } | {
1179
+ type: 'json';
1180
+ schema?: Record<string, unknown>;
1181
+ };
1182
+ signal?: AbortSignal;
1183
+ providerOptions?: Record<string, unknown>;
1184
+ }
1185
+ type ProviderMessage = ProviderSystemMessage | ProviderUserMessage | ProviderAssistantMessage | ProviderToolMessage;
1186
+ interface ProviderSystemMessage {
1187
+ role: 'system';
1188
+ content: string;
1189
+ }
1190
+ interface ProviderUserMessage {
1191
+ role: 'user';
1192
+ content: ProviderMessageContent;
1193
+ }
1194
+ interface ProviderAssistantMessage {
1195
+ role: 'assistant';
1196
+ content?: string | null;
1197
+ reasoning?: string | null;
1198
+ reasoningDetails?: ProviderReasoningDetail[];
1199
+ toolCalls?: ProviderToolCallPart[];
1200
+ }
1201
+ interface ProviderToolMessage {
1202
+ role: 'tool';
1203
+ toolCallId: string;
1204
+ toolName: string;
1205
+ content: ProviderToolResultContent;
1206
+ attachments?: ProviderAttachment[];
1207
+ }
1208
+ /**
1209
+ * Attachment on a provider message (loaded from storage, ready for provider-specific transformation)
1210
+ */
1211
+ interface ProviderAttachment {
1212
+ type: 'image' | 'file';
1213
+ data: string;
1214
+ mediaType: string;
1215
+ name?: string;
1216
+ path?: string;
1217
+ }
1218
+ type ProviderMessageContent = string | ContentPart[];
1219
+ type ContentPart = TextPart | ImagePart | ImageUrlPart | FilePart;
1220
+ interface TextPart {
1221
+ type: 'text';
1222
+ text: string;
1223
+ }
1224
+ interface ImagePart {
1225
+ type: 'image';
1226
+ data: string;
1227
+ mediaType: string;
1228
+ detail?: 'auto' | 'low' | 'high';
1229
+ }
1230
+ /**
1231
+ * Image URL content part (OpenAI/OpenRouter format).
1232
+ * Used for passing image URLs directly to providers.
1233
+ */
1234
+ interface ImageUrlPart {
1235
+ type: 'image_url';
1236
+ image_url: {
1237
+ url: string;
1238
+ detail?: 'auto' | 'low' | 'high';
1239
+ };
1240
+ }
1241
+ interface FilePart {
1242
+ type: 'file';
1243
+ data: string;
1244
+ mediaType: string;
1245
+ filename?: string;
1246
+ }
1247
+ interface ProviderTool {
1248
+ type: 'function';
1249
+ function: {
1250
+ name: string;
1251
+ description: string;
1252
+ parameters?: Record<string, unknown>;
1253
+ };
1254
+ /**
1255
+ * Where this tool is executed:
1256
+ * - 'local': Execute locally by the execution engine (default)
1257
+ * - 'provider': Executed by the LLM provider, results come in response
1258
+ */
1259
+ executionMode?: 'local' | 'provider';
1260
+ /**
1261
+ * Which provider executes this tool (when executionMode='provider')
1262
+ * e.g., 'openai', 'anthropic'
1263
+ */
1264
+ executionProvider?: string;
1265
+ }
1266
+ interface ProviderToolCallPart {
1267
+ id: string;
1268
+ name: string;
1269
+ arguments: Record<string, unknown>;
1270
+ }
1271
+ type ProviderToolResultContent = string | {
1272
+ type: 'text';
1273
+ text: string;
1274
+ } | {
1275
+ type: 'error';
1276
+ error: string;
1277
+ } | ContentPart[];
1278
+ interface ProviderResponse {
1279
+ content: string | null;
1280
+ reasoning?: string | null;
1281
+ reasoningDetails?: ProviderReasoningDetail[];
1282
+ toolCalls?: ProviderToolCallPart[];
1283
+ images?: ProviderGeneratedImage[];
1284
+ finishReason: ProviderFinishReason;
1285
+ usage: ProviderUsage;
1286
+ metadata?: Record<string, unknown>;
1287
+ }
1288
+ type ProviderFinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error';
1289
+ interface ProviderUsage {
1290
+ promptTokens: number;
1291
+ completionTokens: number;
1292
+ totalTokens: number;
1293
+ reasoningTokens?: number;
1294
+ cachedTokens?: number;
1295
+ cost?: number;
1296
+ /** The actual provider that fulfilled the request (e.g., 'google', 'anthropic') */
1297
+ provider?: string;
1298
+ }
1299
+ interface ProviderGeneratedImage {
1300
+ /** Unique ID for this generated image (used to link to tool call) */
1301
+ id?: string;
1302
+ /** Name of the tool that generated this image (e.g., 'image_generation') */
1303
+ toolName?: string;
1304
+ data: string;
1305
+ mediaType: string;
1306
+ revisedPrompt?: string;
1307
+ }
1308
+ interface ProviderReasoningDetail {
1309
+ type: 'summary' | 'encrypted' | 'text';
1310
+ /** Original reasoning ID from provider (e.g., rs_xxx for OpenAI) */
1311
+ id?: string;
1312
+ text?: string;
1313
+ data?: string;
1314
+ }
1315
+ /**
1316
+ * Web search result from provider
1317
+ */
1318
+ interface ProviderWebSearchResult {
1319
+ /** Unique ID of the web search call */
1320
+ id: string;
1321
+ /** Status of the search */
1322
+ status: 'in_progress' | 'searching' | 'completed' | 'failed';
1323
+ /** Search actions performed */
1324
+ actions?: Array<{
1325
+ type: 'search' | 'open_page' | 'find';
1326
+ query?: string;
1327
+ url?: string;
1328
+ pattern?: string;
1329
+ sources?: Array<{
1330
+ type: 'url';
1331
+ url: string;
1332
+ title?: string;
1333
+ }>;
1334
+ }>;
1335
+ }
1336
+ type ProviderStreamChunk = {
1337
+ type: 'content-delta';
1338
+ delta: string;
1339
+ } | {
1340
+ type: 'content-done';
1341
+ } | {
1342
+ type: 'reasoning-delta';
1343
+ delta: string;
1344
+ } | {
1345
+ type: 'reasoning-done';
1346
+ } | {
1347
+ type: 'tool-call-start';
1348
+ id: string;
1349
+ name: string;
1350
+ } | {
1351
+ type: 'tool-call-delta';
1352
+ id: string;
1353
+ argumentsDelta: string;
1354
+ } | {
1355
+ type: 'tool-call-done';
1356
+ id: string;
1357
+ arguments: Record<string, unknown>;
1358
+ } | {
1359
+ type: 'image-delta';
1360
+ index: number;
1361
+ data: string;
1362
+ } | {
1363
+ type: 'image-done';
1364
+ index: number;
1365
+ image: ProviderGeneratedImage;
1366
+ } | {
1367
+ type: 'web-search-done';
1368
+ result: ProviderWebSearchResult;
1369
+ } | {
1370
+ type: 'finish';
1371
+ finishReason: ProviderFinishReason;
1372
+ usage: ProviderUsage;
1373
+ reasoningDetails?: ProviderReasoningDetail[];
1374
+ } | {
1375
+ type: 'error';
1376
+ error: string;
1377
+ code?: string;
1378
+ };
1379
+ type ProviderErrorCode = 'rate_limit' | 'invalid_request' | 'auth_error' | 'server_error' | 'timeout' | 'unknown';
1380
+ declare class ProviderError extends Error {
1381
+ code: ProviderErrorCode;
1382
+ statusCode?: number | undefined;
1383
+ retryAfter?: number | undefined;
1384
+ constructor(message: string, code: ProviderErrorCode, statusCode?: number | undefined, retryAfter?: number | undefined);
1385
+ /**
1386
+ * Whether this error is retryable
1387
+ */
1388
+ get isRetryable(): boolean;
1389
+ }
1390
+ /**
1391
+ * Maps a 0-100 reasoning level to the model's nearest supported level
1392
+ */
1393
+ declare function mapReasoningLevel(level: number, reasoningLevels: Record<number, string | null> | undefined): string | null;
1394
+
1395
+ /**
1396
+ * Model definition types for Standard Agents.
1397
+ *
1398
+ * Models define LLM configurations including provider, model ID, pricing,
1399
+ * and fallback chains. Models are referenced by name from prompts.
1400
+ *
1401
+ * @module
1402
+ */
1403
+
1404
+ /**
1405
+ * Legacy provider identifiers - kept for reference only.
1406
+ * New code should use ProviderFactory imports from provider packages.
1407
+ *
1408
+ * @deprecated Use ProviderFactory from provider packages instead
1409
+ * @internal
1410
+ */
1411
+ type ModelProvider = 'openai' | 'openrouter' | 'anthropic' | 'google' | 'test';
1412
+ /**
1413
+ * Provider interface for LLM providers.
1414
+ *
1415
+ * Provider packages export a factory function that creates instances
1416
+ * implementing this interface. This is structurally compatible with
1417
+ * LLMProviderInterface from providers.ts.
1418
+ */
1419
+ interface ProviderInstance {
1420
+ readonly name: string;
1421
+ readonly specificationVersion: '1';
1422
+ generate(request: ProviderRequest): Promise<ProviderResponse>;
1423
+ stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
1424
+ supportsModel?(modelId: string): boolean;
1425
+ /** List available models from this provider */
1426
+ getModels?(filter?: string): Promise<ProviderModelInfo[]>;
1427
+ /** Fetch capabilities for a specific model */
1428
+ getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
1429
+ /** Get provider-specific tools available for a model */
1430
+ getTools?(modelId?: string): Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>>>;
1431
+ /** Get the icon URL for this provider or a specific model */
1432
+ getIcon?(modelId?: string): string | undefined;
1433
+ /** Inspect a raw request for debugging purposes */
1434
+ inspectRequest?(request: ProviderRequest): Promise<InspectedRequest>;
1435
+ /** Fetch additional metadata about a completed response */
1436
+ getResponseMetadata?(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
1437
+ }
1438
+ /**
1439
+ * Configuration passed to provider factory functions.
1440
+ */
1441
+ interface ProviderFactoryConfig {
1442
+ apiKey: string;
1443
+ baseUrl?: string;
1444
+ timeout?: number;
1445
+ }
1446
+ /**
1447
+ * Provider factory with optional typed providerOptions schema.
1448
+ *
1449
+ * The schema property allows type inference and runtime validation of
1450
+ * provider-specific options in model definitions.
1451
+ *
1452
+ * @template TOptions - Zod schema type for providerOptions (defaults to ZodTypeAny)
1453
+ *
1454
+ * @example
1455
+ * ```typescript
1456
+ * import { openai } from '@standardagents/openai';
1457
+ *
1458
+ * // openai is a ProviderFactoryWithOptions with typed schema
1459
+ * const provider = openai({ apiKey: 'sk-...' });
1460
+ *
1461
+ * // Access the schema for validation
1462
+ * openai.providerOptions?.parse({ service_tier: 'default' });
1463
+ * ```
1464
+ */
1465
+ interface ProviderFactoryWithOptions<TOptions extends ZodTypeAny = ZodTypeAny> {
1466
+ (config: ProviderFactoryConfig): ProviderInstance;
1467
+ /** Zod schema for provider-specific options */
1468
+ providerOptions?: TOptions;
1469
+ }
1470
+ /**
1471
+ * Factory function that creates provider instances.
1472
+ *
1473
+ * Provider packages (like @standardagents/openai) export this type.
1474
+ * This is an alias for ProviderFactoryWithOptions for backward compatibility.
1475
+ *
1476
+ * @example
1477
+ * ```typescript
1478
+ * import { openai } from '@standardagents/openai';
1479
+ *
1480
+ * // openai is a ProviderFactory
1481
+ * const provider = openai({ apiKey: 'sk-...' });
1482
+ * ```
1483
+ */
1484
+ type ProviderFactory = ProviderFactoryWithOptions<ZodTypeAny>;
1485
+ /**
1486
+ * Extract providerOptions type from a provider factory.
1487
+ *
1488
+ * Returns the inferred input type from the provider's Zod schema,
1489
+ * or Record<string, unknown> if no schema is defined.
1490
+ *
1491
+ * @template P - Provider factory type
1492
+ */
1493
+ type InferProviderOptions<P> = P extends ProviderFactoryWithOptions<infer S> ? S extends ZodTypeAny ? z.input<S> extends Record<string, unknown> ? z.input<S> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown>;
1494
+ /**
1495
+ * Model capability flags indicating supported features.
1496
+ *
1497
+ * These capabilities are used by the FlowEngine to determine how to
1498
+ * interact with the model and what features are available.
1499
+ */
1500
+ interface ModelCapabilities {
1501
+ /**
1502
+ * Reasoning level mapping (0-100 scale → model-specific values).
1503
+ * Keys are breakpoints, values are model's native reasoning strings.
1504
+ *
1505
+ * @example
1506
+ * // OpenAI o-series
1507
+ * reasoningLevels: { 0: null, 33: 'low', 66: 'medium', 100: 'high' }
1508
+ *
1509
+ * @example
1510
+ * // Binary reasoning (Claude extended thinking)
1511
+ * reasoningLevels: { 0: null, 100: 'enabled' }
1512
+ *
1513
+ * @example
1514
+ * // No reasoning support
1515
+ * reasoningLevels: { 0: null }
1516
+ */
1517
+ reasoningLevels?: Record<number, string | null>;
1518
+ /**
1519
+ * Whether the model supports vision (image understanding).
1520
+ * When true, image attachments will be sent to the model as part of the request.
1521
+ * Models like GPT-4o, Claude 3, and Gemini support vision.
1522
+ */
1523
+ supportsImages?: boolean;
1524
+ /**
1525
+ * @deprecated Use supportsImages instead
1526
+ */
1527
+ vision?: boolean;
1528
+ /**
1529
+ * Whether the model supports function calling (tool use).
1530
+ * Most modern models support this, defaults to true if not specified.
1531
+ */
1532
+ supportsToolCalls?: boolean;
1533
+ /**
1534
+ * @deprecated Use supportsToolCalls instead
1535
+ */
1536
+ functionCalling?: boolean;
1537
+ /**
1538
+ * Whether the model supports streaming responses.
1539
+ * @default true
1540
+ */
1541
+ supportsStreaming?: boolean;
1542
+ /**
1543
+ * Whether the model supports structured outputs (JSON mode).
1544
+ */
1545
+ supportsJsonMode?: boolean;
1546
+ /**
1547
+ * @deprecated Use supportsJsonMode instead
1548
+ */
1549
+ structuredOutputs?: boolean;
1550
+ /**
1551
+ * Maximum context window size in tokens.
1552
+ */
1553
+ maxContextTokens?: number;
1554
+ /**
1555
+ * Maximum output tokens the model can generate.
1556
+ */
1557
+ maxOutputTokens?: number;
1558
+ }
1559
+ /**
1560
+ * Model definition configuration.
1561
+ *
1562
+ * Defines an LLM model with its provider, pricing, capabilities, and fallback chain.
1563
+ *
1564
+ * @template N - The model name as a string literal type for type inference
1565
+ *
1566
+ * @example Basic usage
1567
+ * ```typescript
1568
+ * import { defineModel } from '@standardagents/spec';
1569
+ * import { openai } from '@standardagents/openai';
1570
+ *
1571
+ * export default defineModel({
1572
+ * name: 'gpt-4o',
1573
+ * provider: openai,
1574
+ * model: 'gpt-4o',
1575
+ * inputPrice: 2.5,
1576
+ * outputPrice: 10,
1577
+ * });
1578
+ * ```
1579
+ *
1580
+ * @example With capabilities and typed provider options
1581
+ * ```typescript
1582
+ * import { defineModel } from '@standardagents/spec';
1583
+ * import { openai } from '@standardagents/openai';
1584
+ *
1585
+ * export default defineModel({
1586
+ * name: 'gpt-4o',
1587
+ * provider: openai,
1588
+ * model: 'gpt-4o',
1589
+ * inputPrice: 2.5,
1590
+ * outputPrice: 10,
1591
+ * capabilities: {
1592
+ * supportsImages: true,
1593
+ * supportsToolCalls: true,
1594
+ * supportsJsonMode: true,
1595
+ * maxContextTokens: 128000,
1596
+ * },
1597
+ * providerOptions: {
1598
+ * service_tier: 'default', // TypeScript knows this is valid
1599
+ * },
1600
+ * });
1601
+ * ```
1602
+ */
1603
+ interface ModelDefinition<N extends string = string, P extends ProviderFactoryWithOptions<ZodTypeAny> = ProviderFactoryWithOptions<ZodTypeAny>> {
1604
+ /**
1605
+ * Unique name for this model definition.
1606
+ * Used as the identifier when referencing from prompts.
1607
+ * Should be descriptive and consistent (e.g., 'gpt-4o', 'claude-3-opus').
1608
+ */
1609
+ name: N;
1610
+ /**
1611
+ * The LLM provider factory function to use for API calls.
1612
+ *
1613
+ * Import from a provider package like @standardagents/openai or @standardagents/openrouter.
1614
+ * The provider's type determines what providerOptions are available.
1615
+ *
1616
+ * @example
1617
+ * ```typescript
1618
+ * import { openai } from '@standardagents/openai';
1619
+ * provider: openai
1620
+ * ```
1621
+ *
1622
+ * @example
1623
+ * ```typescript
1624
+ * import { openrouter } from '@standardagents/openrouter';
1625
+ * provider: openrouter
1626
+ * ```
1627
+ */
1628
+ provider: P;
1629
+ /**
1630
+ * The actual model identifier sent to the provider API.
1631
+ *
1632
+ * For OpenAI: 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', etc.
1633
+ * For OpenRouter: 'openai/gpt-4o', 'anthropic/claude-3-opus', etc.
1634
+ * For Anthropic: 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', etc.
1635
+ * For Google: 'gemini-1.5-pro', 'gemini-1.5-flash', etc.
1636
+ */
1637
+ model: string;
1638
+ /**
1639
+ * Optional list of additional provider prefixes for OpenRouter.
1640
+ * Allows routing through specific providers when using OpenRouter.
1641
+ *
1642
+ * @example ['anthropic', 'google'] - prefer Anthropic, fallback to Google
1643
+ */
1644
+ includedProviders?: string[];
1645
+ /**
1646
+ * Fallback model names to try if this model fails.
1647
+ * Referenced by model name (must be defined in agents/models/).
1648
+ * Tried in order after primary model exhausts retries.
1649
+ *
1650
+ * @example ['gpt-4', 'gpt-3.5-turbo']
1651
+ */
1652
+ fallbacks?: string[];
1653
+ /**
1654
+ * Cost per 1 million input tokens in USD.
1655
+ * Used for cost tracking and reporting in logs.
1656
+ */
1657
+ inputPrice?: number;
1658
+ /**
1659
+ * Cost per 1 million output tokens in USD.
1660
+ * Used for cost tracking and reporting in logs.
1661
+ */
1662
+ outputPrice?: number;
1663
+ /**
1664
+ * Cost per 1 million cached input tokens in USD.
1665
+ * Some providers offer reduced pricing for cached/repeated prompts.
1666
+ */
1667
+ cachedPrice?: number;
1668
+ /**
1669
+ * Model capabilities - features this model supports.
1670
+ */
1671
+ capabilities?: ModelCapabilities;
1672
+ /**
1673
+ * Provider-specific options passed through to the provider.
1674
+ * These are merged with prompt-level providerOptions (model options are defaults).
1675
+ *
1676
+ * The type is automatically inferred from the provider's schema when available,
1677
+ * providing TypeScript autocompletion and runtime validation.
1678
+ *
1679
+ * @example
1680
+ * ```typescript
1681
+ * // With OpenAI provider
1682
+ * providerOptions: {
1683
+ * service_tier: 'default',
1684
+ * }
1685
+ * ```
1686
+ *
1687
+ * @example
1688
+ * ```typescript
1689
+ * // With OpenRouter provider
1690
+ * providerOptions: {
1691
+ * provider: {
1692
+ * zdr: true,
1693
+ * max_price: { prompt: 1 },
1694
+ * },
1695
+ * }
1696
+ * ```
1697
+ */
1698
+ providerOptions?: InferProviderOptions<P>;
1699
+ /**
1700
+ * Provider tools available for this model.
1701
+ * References tool names from provider.getTools().
1702
+ *
1703
+ * Provider tools are built-in tools offered by the provider (e.g., OpenAI's
1704
+ * web_search, file_search, code_interpreter, image_generation). These tools
1705
+ * can be used in prompts alongside custom tools.
1706
+ *
1707
+ * @example
1708
+ * ```typescript
1709
+ * providerTools: ['web_search', 'code_interpreter'],
1710
+ * ```
1711
+ */
1712
+ providerTools?: string[];
1713
+ }
1714
+ /**
1715
+ * Defines an LLM model configuration.
1716
+ *
1717
+ * Models are the foundation of the agent system - they specify which
1718
+ * AI model to use and how to connect to it. Models can have fallbacks
1719
+ * for reliability and include pricing for cost tracking.
1720
+ *
1721
+ * @template N - The model name as a string literal type
1722
+ * @param options - Model configuration options
1723
+ * @returns The model definition for registration
1724
+ *
1725
+ * @example
1726
+ * ```typescript
1727
+ * // agents/models/gpt_4o.ts
1728
+ * import { defineModel } from '@standardagents/spec';
1729
+ * import { openai } from '@standardagents/openai';
1730
+ *
1731
+ * export default defineModel({
1732
+ * name: 'gpt-4o',
1733
+ * provider: openai,
1734
+ * model: 'gpt-4o',
1735
+ * fallbacks: ['gpt-4-turbo'],
1736
+ * inputPrice: 2.5,
1737
+ * outputPrice: 10,
1738
+ * });
1739
+ * ```
1740
+ *
1741
+ * @example
1742
+ * ```typescript
1743
+ * // Using OpenRouter with typed provider options
1744
+ * import { openrouter } from '@standardagents/openrouter';
1745
+ *
1746
+ * export default defineModel({
1747
+ * name: 'claude-3-opus',
1748
+ * provider: openrouter,
1749
+ * model: 'anthropic/claude-3-opus',
1750
+ * providerOptions: {
1751
+ * provider: {
1752
+ * zdr: true,
1753
+ * only: ['anthropic'],
1754
+ * },
1755
+ * },
1756
+ * });
1757
+ * ```
1758
+ */
1759
+ declare function defineModel<N extends string, P extends ProviderFactoryWithOptions<ZodTypeAny>>(options: ModelDefinition<N, P>): ModelDefinition<N, P>;
1760
+
1761
+ /**
1762
+ * Prompt definition types for Standard Agents.
1763
+ *
1764
+ * Prompts define LLM interaction configurations including the system prompt,
1765
+ * model selection, available tools, and various behavioral options.
1766
+ *
1767
+ * @module
1768
+ */
1769
+
1770
+ /**
1771
+ * A text part of a prompt - static text content.
1772
+ *
1773
+ * @example
1774
+ * ```typescript
1775
+ * { type: 'text', content: 'You are a helpful assistant.\n\n' }
1776
+ * ```
1777
+ */
1778
+ interface PromptTextPart {
1779
+ type: 'text';
1780
+ /** The text content */
1781
+ content: string;
1782
+ }
1783
+ /**
1784
+ * A prompt inclusion part - includes another prompt's content.
1785
+ *
1786
+ * @example
1787
+ * ```typescript
1788
+ * { type: 'include', prompt: 'responder_rules' }
1789
+ * ```
1790
+ */
1791
+ interface PromptIncludePart {
1792
+ type: 'include';
1793
+ /** The name of the prompt to include */
1794
+ prompt: string;
1795
+ }
1796
+ /**
1797
+ * A single part of a structured prompt.
1798
+ * Discriminated union on `type` field for TypeScript narrowing.
1799
+ */
1800
+ type PromptPart = PromptTextPart | PromptIncludePart;
1801
+ /**
1802
+ * A structured prompt is an array of prompt parts.
1803
+ * Provides composition with other prompts via includes.
1804
+ *
1805
+ * @example
1806
+ * ```typescript
1807
+ * prompt: [
1808
+ * { type: 'text', content: 'You are a helpful assistant.\n\n' },
1809
+ * { type: 'include', prompt: 'common_rules' },
1810
+ * { type: 'text', content: '\n\nBe concise.' },
1811
+ * ]
1812
+ * ```
1813
+ */
1814
+ type StructuredPrompt = PromptPart[];
1815
+ /**
1816
+ * The prompt content can be either a plain string or a structured array.
1817
+ *
1818
+ * @example
1819
+ * ```typescript
1820
+ * // Simple string prompt:
1821
+ * prompt: 'You are a helpful assistant.'
1822
+ *
1823
+ * // Structured prompt with includes:
1824
+ * prompt: [
1825
+ * { type: 'text', content: 'You are a helpful assistant.\n\n' },
1826
+ * { type: 'include', prompt: 'common_rules' },
1827
+ * ]
1828
+ * ```
1829
+ */
1830
+ type PromptContent = string | StructuredPrompt;
1831
+ /**
1832
+ * Configuration for sub-prompts used as tools.
1833
+ * These options control how results from sub-prompts are returned to the caller.
1834
+ *
1835
+ * @template T - The sub-prompt name type (for type-safe references)
1836
+ */
1837
+ interface SubpromptConfig<T extends string = string> {
1838
+ /**
1839
+ * Name of the sub-prompt to call.
1840
+ * Must be a prompt defined in agents/prompts/.
1841
+ */
1842
+ name: T;
1099
1843
  /**
1100
1844
  * Include text response content from sub-prompt execution in the result string.
1101
1845
  * @default true
@@ -1121,24 +1865,86 @@ interface SubpromptConfig<T extends string = string> {
1121
1865
  * "search term" as the initial user message.
1122
1866
  */
1123
1867
  initUserMessageProperty?: string;
1868
+ /**
1869
+ * Property containing attachment path(s) to include as multimodal content
1870
+ * when invoking the sub-prompt.
1871
+ *
1872
+ * Supports both a single path string or an array of paths.
1873
+ *
1874
+ * @example
1875
+ * If the tool is called with `{ image: "/attachments/123.jpg" }` and
1876
+ * `initAttachmentsProperty: 'image'`, the sub-prompt will receive
1877
+ * the image as an attachment in the user message.
1878
+ *
1879
+ * @example
1880
+ * If the tool is called with `{ images: ["/attachments/a.jpg", "/attachments/b.jpg"] }` and
1881
+ * `initAttachmentsProperty: 'images'`, the sub-prompt will receive
1882
+ * both images as attachments.
1883
+ */
1884
+ initAttachmentsProperty?: string;
1124
1885
  }
1125
1886
  /**
1126
1887
  * @deprecated Use SubpromptConfig instead
1127
1888
  */
1128
1889
  type ToolConfig<T extends string = string> = SubpromptConfig<T>;
1890
+ /**
1891
+ * Configuration for a tool used in a prompt.
1892
+ * Allows specifying tenv values and static options for the tool.
1893
+ *
1894
+ * @example
1895
+ * ```typescript
1896
+ * // Tool with tenv values
1897
+ * { name: 'file_search', tenvs: { vectorStoreId: 'vs_abc123' } }
1898
+ *
1899
+ * // Tool with options
1900
+ * { name: 'web_search', options: { searchContextSize: 'high' } }
1901
+ * ```
1902
+ */
1903
+ interface PromptToolConfig {
1904
+ /**
1905
+ * Name of the tool (custom tool or provider tool).
1906
+ */
1907
+ name: string;
1908
+ /**
1909
+ * Thread environment variable values for this tool.
1910
+ * These values are merged with agent and thread tenvs (prompt tenvs are lowest priority).
1911
+ */
1912
+ tenvs?: Record<string, unknown>;
1913
+ /**
1914
+ * Static options for this tool.
1915
+ * Passed to the tool handler at execution time.
1916
+ */
1917
+ options?: Record<string, unknown>;
1918
+ }
1129
1919
  /**
1130
1920
  * Reasoning configuration for models that support extended thinking.
1131
- * Applies to models like OpenAI o1, Anthropic Claude with extended thinking,
1921
+ * Applies to models like OpenAI o1/o3, Anthropic Claude with extended thinking,
1132
1922
  * Google Gemini with thinking, and Qwen with reasoning.
1133
1923
  */
1134
1924
  interface ReasoningConfig {
1135
1925
  /**
1926
+ * Numeric reasoning level on a 0-100 scale.
1927
+ * The FlowEngine maps this to the model's nearest supported reasoning option.
1928
+ *
1929
+ * @example
1930
+ * // Typical breakpoints:
1931
+ * // 0 = No reasoning
1932
+ * // 33 = Low effort
1933
+ * // 66 = Medium effort
1934
+ * // 100 = Maximum effort
1935
+ *
1936
+ * reasoning: { level: 75 } // Maps to 'high' on most models
1937
+ */
1938
+ level?: number;
1939
+ /**
1940
+ * @deprecated Use `level` instead. Will be removed in future versions.
1941
+ *
1136
1942
  * Effort level for reasoning models.
1137
1943
  * Higher effort = more thinking tokens = potentially better results.
1138
1944
  *
1139
- * - `low`: Minimal reasoning, faster responses
1140
- * - `medium`: Balanced reasoning and speed
1141
- * - `high`: Maximum reasoning, slower but more thorough
1945
+ * - `low`: Minimal reasoning, faster responses (equivalent to level ~33)
1946
+ * - `medium`: Balanced reasoning and speed (equivalent to level ~66)
1947
+ * - `high`: Maximum reasoning, slower but more thorough (equivalent to level ~100)
1142
1948
  *
1143
1949
  * @default undefined (use model defaults)
1144
1950
  */
@@ -1237,10 +2043,37 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
1237
2043
  requiredSchema?: S;
1238
2044
  /**
1239
2045
  * Tools available to this prompt.
1240
- * Can be simple tool names or sub-prompt configurations.
2046
+ * Can be:
2047
+ * - string: Simple tool name (custom or provider tool)
2048
+ * - SubpromptConfig: Sub-prompt used as a tool
2049
+ * - PromptToolConfig: Tool with tenv values and/or options
2050
+ *
1241
2051
  * To enable handoffs, include ai_human agent names in this array.
2052
+ *
2053
+ * @example
2054
+ * ```typescript
2055
+ * tools: [
2056
+ * 'custom_tool', // Simple tool name
2057
+ * { name: 'other_prompt' }, // Sub-prompt as tool
2058
+ * { name: 'file_search', tenvs: { vectorStoreId: 'vs_123' } }, // Tool with tenvs
2059
+ * ]
2060
+ * ```
1242
2061
  */
1243
- tools?: (string | SubpromptConfig)[];
2062
+ tools?: (string | SubpromptConfig | PromptToolConfig)[];
2063
+ /**
2064
+ * Thread environment variables for this prompt.
2065
+ * These values are merged with agent and thread tenvs when creating a thread.
2066
+ * Prompt tenvs have lowest priority (overridden by agent and thread tenvs).
2067
+ *
2068
+ * @example
2069
+ * ```typescript
2070
+ * tenvs: {
2071
+ * vectorStoreId: 'vs_default_123',
2072
+ * apiEndpoint: 'https://api.example.com',
2073
+ * }
2074
+ * ```
2075
+ */
2076
+ tenvs?: Record<string, unknown>;
1244
2077
  /**
1245
2078
  * Reasoning configuration for models that support extended thinking.
1246
2079
  */
@@ -1250,6 +2083,22 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
1250
2083
  * @default 10
1251
2084
  */
1252
2085
  recentImageThreshold?: number;
2086
+ /**
2087
+ * Provider-specific options passed through to the provider.
2088
+ * These override model-level providerOptions for this prompt.
2089
+ *
2090
+ * Options are merged in order (later wins):
2091
+ * 1. model.providerOptions (defaults)
2092
+ * 2. prompt.providerOptions (this field - overrides)
2093
+ *
2094
+ * @example
2095
+ * ```typescript
2096
+ * providerOptions: {
2097
+ * response_format: { type: 'json_object' },
2098
+ * }
2099
+ * ```
2100
+ */
2101
+ providerOptions?: Record<string, unknown>;
1253
2102
  }
1254
2103
  /**
1255
2104
  * Helper type to extract the inferred input type from a prompt's Zod schema.
@@ -1789,6 +2638,24 @@ interface AgentDefinition<N extends string = string, Prompt extends string = str
1789
2638
  * @example 'https://example.com/icon.svg' or '/icons/support.svg'
1790
2639
  */
1791
2640
  icon?: string;
2641
+ /**
2642
+ * Thread environment variables for this agent.
2643
+ * These values are merged with prompt and thread tenvs when creating a thread.
2644
+ *
2645
+ * Merge priority (later wins):
2646
+ * 1. Prompt tenvs (lowest)
2647
+ * 2. Agent tenvs (this field)
2648
+ * 3. Thread tenvs (highest)
2649
+ *
2650
+ * @example
2651
+ * ```typescript
2652
+ * tenvs: {
2653
+ * vectorStoreId: 'vs_agent_default',
2654
+ * apiEndpoint: 'https://api.example.com',
2655
+ * }
2656
+ * ```
2657
+ */
2658
+ tenvs?: Record<string, unknown>;
1792
2659
  }
1793
2660
  /**
1794
2661
  * Defines an agent configuration.
@@ -2030,4 +2897,4 @@ declare function defineController(controller: Controller): Controller;
2030
2897
  */
2031
2898
  declare function defineThreadEndpoint(handler: ThreadEndpointHandler): Controller;
2032
2899
 
2033
- export { type AgentDefinition, type AgentType, type AttachmentRef, type Controller, type ControllerContext, type ControllerReturn, type Effect, type EffectDefinition, type ExecutionState, type FileChunk, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GrepResult, type HookContext, type HookDefinition, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type InjectMessageInput, type LLMMessage, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ScheduledEffect, type SideConfig, type StructuredPrompt, type SubpromptConfig, type TextContent, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool };
2900
+ export { type AgentDefinition, type AgentType, type AttachmentRef, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type DefineToolOptions, type Effect, type EffectDefinition, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GrepResult, type HookContext, type HookDefinition, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, ProviderError, type ProviderErrorCode, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderModelInfo, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUserMessage, type ProviderWebSearchResult, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResponseSummary, type ScheduledEffect, type SideConfig, type StructuredPrompt, type SubpromptConfig, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, mapReasoningLevel };