@standardagents/spec 0.11.0-next.5d2e71b → 0.11.0-next.7005954
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 +1194 -248
- package/dist/index.js +67 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,159 +1,83 @@
|
|
|
1
|
-
import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion } from 'zod';
|
|
1
|
+
import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion, ZodTypeAny } from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
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.
|
|
4
|
+
* Global namespace for Standard Agent Specification types.
|
|
121
5
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* for reliability and include pricing for cost tracking.
|
|
6
|
+
* This namespace provides extensible registries that consumers can augment
|
|
7
|
+
* via TypeScript's declaration merging to enable type-safe references.
|
|
125
8
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @returns The model definition for registration
|
|
9
|
+
* When registries are empty, all types fall back to `string` for flexibility.
|
|
10
|
+
* When augmented with registry entries, types narrow to the specific values.
|
|
129
11
|
*
|
|
130
|
-
* @example
|
|
12
|
+
* @example Augmenting the namespace (typically in generated types)
|
|
131
13
|
* ```typescript
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* inputPrice: 2.5,
|
|
141
|
-
* outputPrice: 10,
|
|
142
|
-
* });
|
|
14
|
+
* declare global {
|
|
15
|
+
* namespace StandardAgentSpec {
|
|
16
|
+
* interface ModelRegistry {
|
|
17
|
+
* 'gpt-4o': true;
|
|
18
|
+
* 'claude-3': true;
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
143
22
|
* ```
|
|
144
23
|
*
|
|
145
|
-
* @
|
|
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
|
-
* ```
|
|
24
|
+
* @module
|
|
155
25
|
*/
|
|
156
|
-
declare
|
|
26
|
+
declare global {
|
|
27
|
+
namespace StandardAgentSpec {
|
|
28
|
+
/**
|
|
29
|
+
* Registry of model names. Augment to add model names.
|
|
30
|
+
* Generated types add properties: interface ModelRegistry { 'gpt-4o': true; }
|
|
31
|
+
* This gives us: type Models = keyof ModelRegistry = 'gpt-4o'
|
|
32
|
+
*/
|
|
33
|
+
interface ModelRegistry {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Registry of prompt names. Augment to add prompt names.
|
|
37
|
+
*/
|
|
38
|
+
interface PromptRegistry {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Registry of agent names. Augment to add agent names.
|
|
42
|
+
*/
|
|
43
|
+
interface AgentRegistry {
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Registry of tool names. Augment to add tool names.
|
|
47
|
+
*/
|
|
48
|
+
interface ToolRegistry {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Registry of all callable items (prompts, agents, tools).
|
|
52
|
+
* Used for tool references in prompts and agents.
|
|
53
|
+
*/
|
|
54
|
+
interface CallableRegistry {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Union of all model names, or string when registry is empty.
|
|
58
|
+
* When ModelRegistry is empty, this defaults to string for flexibility.
|
|
59
|
+
* When populated, it narrows to the specific model names.
|
|
60
|
+
*/
|
|
61
|
+
type Models = keyof ModelRegistry extends never ? string : keyof ModelRegistry;
|
|
62
|
+
/**
|
|
63
|
+
* Union of all prompt names, or string when registry is empty.
|
|
64
|
+
*/
|
|
65
|
+
type Prompts = keyof PromptRegistry extends never ? string : keyof PromptRegistry;
|
|
66
|
+
/**
|
|
67
|
+
* Union of all agent names, or string when registry is empty.
|
|
68
|
+
*/
|
|
69
|
+
type Agents = keyof AgentRegistry extends never ? string : keyof AgentRegistry;
|
|
70
|
+
/**
|
|
71
|
+
* Union of all tool names, or string when registry is empty.
|
|
72
|
+
*/
|
|
73
|
+
type Tools = keyof ToolRegistry extends never ? string : keyof ToolRegistry;
|
|
74
|
+
/**
|
|
75
|
+
* Union of all callable names, or string when registry is empty.
|
|
76
|
+
* Callables include prompts, agents, and tools that can be used as tools.
|
|
77
|
+
*/
|
|
78
|
+
type Callables = keyof CallableRegistry extends never ? string : keyof CallableRegistry;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
157
81
|
|
|
158
82
|
/**
|
|
159
83
|
* Effect definition types for Standard Agents.
|
|
@@ -304,6 +228,10 @@ interface Message {
|
|
|
304
228
|
silent?: boolean;
|
|
305
229
|
/** Custom metadata */
|
|
306
230
|
metadata?: Record<string, unknown>;
|
|
231
|
+
/** Message processing status */
|
|
232
|
+
status?: 'pending' | 'completed' | 'failed' | null;
|
|
233
|
+
/** Tool execution status (for tool result messages) */
|
|
234
|
+
tool_status?: 'success' | 'error' | null;
|
|
307
235
|
}
|
|
308
236
|
/**
|
|
309
237
|
* Input for injecting a new message.
|
|
@@ -977,6 +905,30 @@ type ToolArgsRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
|
|
|
977
905
|
* @template D - Maximum nesting depth (default: 7)
|
|
978
906
|
*/
|
|
979
907
|
type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
|
|
908
|
+
/**
|
|
909
|
+
* Raw shape for tenv schema - uses same pattern as ToolArgsRawShape.
|
|
910
|
+
* Each key is a tenv name, value is a Zod schema for validation.
|
|
911
|
+
*
|
|
912
|
+
* @template D - Maximum nesting depth (default: 7)
|
|
913
|
+
*/
|
|
914
|
+
type TenvRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
|
|
915
|
+
/**
|
|
916
|
+
* Top-level thread environment variable schema.
|
|
917
|
+
*
|
|
918
|
+
* Defines which thread environment variables a tool requires.
|
|
919
|
+
* Required tenvs are non-optional fields, optional tenvs use .optional().
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```typescript
|
|
923
|
+
* z.object({
|
|
924
|
+
* vectorStoreId: z.string().describe('OpenAI Vector Store ID'), // Required
|
|
925
|
+
* userLocation: z.string().optional().describe('User location'), // Optional
|
|
926
|
+
* })
|
|
927
|
+
* ```
|
|
928
|
+
*
|
|
929
|
+
* @template D - Maximum nesting depth (default: 7)
|
|
930
|
+
*/
|
|
931
|
+
type ToolTenvs<D extends number = 7> = z.ZodObject<TenvRawShape<D>>;
|
|
980
932
|
/**
|
|
981
933
|
* Tool function signature.
|
|
982
934
|
*
|
|
@@ -988,127 +940,998 @@ type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
|
|
|
988
940
|
*/
|
|
989
941
|
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
942
|
/**
|
|
991
|
-
*
|
|
943
|
+
* Options for defining a tool.
|
|
992
944
|
*
|
|
993
|
-
*
|
|
994
|
-
* -
|
|
995
|
-
* -
|
|
996
|
-
* - Tool implementation function
|
|
945
|
+
* @template State - The state type (defaults to ThreadState)
|
|
946
|
+
* @template Args - The Zod schema for tool arguments, or null for no args
|
|
947
|
+
* @template Tenvs - The Zod schema for thread environment variables, or null
|
|
997
948
|
*/
|
|
998
|
-
|
|
949
|
+
interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
|
|
950
|
+
/** Description of what the tool does (shown to the LLM). */
|
|
951
|
+
description: string;
|
|
952
|
+
/** Zod schema for validating tool arguments. Omit for tools with no args. */
|
|
953
|
+
args?: Args;
|
|
954
|
+
/** The tool implementation function. */
|
|
955
|
+
execute: Tool<State, Args>;
|
|
956
|
+
/** Zod schema for thread environment variables the tool requires. */
|
|
957
|
+
tenvs?: Tenvs;
|
|
958
|
+
/**
|
|
959
|
+
* Where this tool is executed:
|
|
960
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
961
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
962
|
+
*/
|
|
963
|
+
executionMode?: 'local' | 'provider';
|
|
964
|
+
/**
|
|
965
|
+
* Which provider executes this tool (when executionMode='provider').
|
|
966
|
+
* e.g., 'openai', 'anthropic'
|
|
967
|
+
*/
|
|
968
|
+
executionProvider?: string;
|
|
969
|
+
}
|
|
999
970
|
/**
|
|
1000
|
-
*
|
|
971
|
+
* Tool definition object returned by defineTool().
|
|
972
|
+
*
|
|
973
|
+
* Contains all the metadata and implementation needed to register
|
|
974
|
+
* and execute a tool.
|
|
1001
975
|
*
|
|
1002
|
-
* @
|
|
1003
|
-
* @
|
|
1004
|
-
* @
|
|
1005
|
-
* @returns A tuple containing the tool definition
|
|
976
|
+
* @template State - The state type (defaults to ThreadState)
|
|
977
|
+
* @template Args - The Zod schema for tool arguments, or null for no args
|
|
978
|
+
* @template Tenvs - The Zod schema for thread environment variables, or null
|
|
1006
979
|
*/
|
|
1007
|
-
|
|
980
|
+
interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
|
|
981
|
+
/** Description of what the tool does (shown to the LLM). */
|
|
982
|
+
description: string;
|
|
983
|
+
/** Zod schema for validating tool arguments, or null for no args. */
|
|
984
|
+
args: Args;
|
|
985
|
+
/** The tool implementation function. */
|
|
986
|
+
execute: Tool<State, Args>;
|
|
987
|
+
/** Zod schema for thread environment variables, or null if none. */
|
|
988
|
+
tenvs: Tenvs;
|
|
989
|
+
/**
|
|
990
|
+
* Where this tool is executed:
|
|
991
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
992
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
993
|
+
*/
|
|
994
|
+
executionMode?: 'local' | 'provider';
|
|
995
|
+
/**
|
|
996
|
+
* Which provider executes this tool (when executionMode='provider').
|
|
997
|
+
*/
|
|
998
|
+
executionProvider?: string;
|
|
999
|
+
}
|
|
1008
1000
|
/**
|
|
1009
|
-
*
|
|
1001
|
+
* Defines a tool that agents can call during execution.
|
|
1002
|
+
*
|
|
1003
|
+
* Tools are the primary way agents interact with external systems.
|
|
1004
|
+
* Each tool has a description (shown to the LLM), optional argument
|
|
1005
|
+
* schema (validated at runtime), an implementation function, and
|
|
1006
|
+
* optional thread environment variable (tenv) requirements.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* import { defineTool } from '@standardagents/spec';
|
|
1011
|
+
* import { z } from 'zod';
|
|
1012
|
+
*
|
|
1013
|
+
* // Tool with arguments
|
|
1014
|
+
* export default defineTool({
|
|
1015
|
+
* description: 'Search the knowledge base for relevant information',
|
|
1016
|
+
* args: z.object({
|
|
1017
|
+
* query: z.string().describe('Search query'),
|
|
1018
|
+
* limit: z.number().optional().describe('Max results'),
|
|
1019
|
+
* }),
|
|
1020
|
+
* execute: async (state, args) => {
|
|
1021
|
+
* const results = await search(args.query, args.limit);
|
|
1022
|
+
* return { status: 'success', result: JSON.stringify(results) };
|
|
1023
|
+
* },
|
|
1024
|
+
* });
|
|
1025
|
+
*
|
|
1026
|
+
* // Tool without arguments
|
|
1027
|
+
* export default defineTool({
|
|
1028
|
+
* description: 'Get the current server time',
|
|
1029
|
+
* execute: async (state) => {
|
|
1030
|
+
* return { status: 'success', result: new Date().toISOString() };
|
|
1031
|
+
* },
|
|
1032
|
+
* });
|
|
1033
|
+
*
|
|
1034
|
+
* // Tool with tenvs (thread environment variables)
|
|
1035
|
+
* export default defineTool({
|
|
1036
|
+
* description: 'Search through uploaded files',
|
|
1037
|
+
* args: z.object({ query: z.string() }),
|
|
1038
|
+
* execute: async (state, args) => ({ status: 'success', result: 'done' }),
|
|
1039
|
+
* tenvs: z.object({
|
|
1040
|
+
* vectorStoreId: z.string().describe('OpenAI Vector Store ID'),
|
|
1041
|
+
* }),
|
|
1042
|
+
* });
|
|
1010
1043
|
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1044
|
+
* // Provider-executed tool (e.g., OpenAI built-in tools)
|
|
1045
|
+
* export default defineTool({
|
|
1046
|
+
* description: 'Generate images using DALL-E',
|
|
1047
|
+
* args: z.object({ prompt: z.string() }),
|
|
1048
|
+
* execute: async () => ({ status: 'success', result: 'Handled by provider' }),
|
|
1049
|
+
* executionMode: 'provider',
|
|
1050
|
+
* executionProvider: 'openai',
|
|
1051
|
+
* });
|
|
1052
|
+
* ```
|
|
1053
|
+
*
|
|
1054
|
+
* @param options - Tool definition options
|
|
1055
|
+
* @returns A tool definition object
|
|
1014
1056
|
*/
|
|
1015
|
-
declare function defineTool<State = ThreadState
|
|
1057
|
+
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
1058
|
|
|
1017
1059
|
/**
|
|
1018
|
-
*
|
|
1060
|
+
* Provider types for Standard Agents.
|
|
1019
1061
|
*
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1062
|
+
* These types define the interface between Standard Agents and LLM providers.
|
|
1063
|
+
* Provider packages implement these types to integrate with different LLM APIs.
|
|
1022
1064
|
*
|
|
1023
1065
|
* @module
|
|
1024
1066
|
*/
|
|
1025
1067
|
|
|
1026
1068
|
/**
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1029
|
-
* @example
|
|
1030
|
-
* ```typescript
|
|
1031
|
-
* { type: 'text', content: 'You are a helpful assistant.\n\n' }
|
|
1032
|
-
* ```
|
|
1069
|
+
* Stripped-down response summary for async metadata fetching.
|
|
1070
|
+
* Intentionally excludes content/attachments to avoid passing large data.
|
|
1033
1071
|
*/
|
|
1034
|
-
interface
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1072
|
+
interface ResponseSummary {
|
|
1073
|
+
/** Provider-specific response/generation ID */
|
|
1074
|
+
responseId?: string;
|
|
1075
|
+
/** Model that handled the request */
|
|
1076
|
+
model: string;
|
|
1077
|
+
/** How the response ended */
|
|
1078
|
+
finishReason: ProviderFinishReason;
|
|
1079
|
+
/** Token usage (without detailed breakdowns) */
|
|
1080
|
+
usage: {
|
|
1081
|
+
promptTokens: number;
|
|
1082
|
+
completionTokens: number;
|
|
1083
|
+
totalTokens: number;
|
|
1084
|
+
};
|
|
1038
1085
|
}
|
|
1039
1086
|
/**
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
* @example
|
|
1043
|
-
* ```typescript
|
|
1044
|
-
* { type: 'include', prompt: 'responder_rules' }
|
|
1045
|
-
* ```
|
|
1087
|
+
* Model information returned by provider's getModels method.
|
|
1046
1088
|
*/
|
|
1047
|
-
interface
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1089
|
+
interface ProviderModelInfo {
|
|
1090
|
+
/** The model identifier used in API calls (e.g., 'gpt-4o', 'anthropic/claude-3-opus') */
|
|
1091
|
+
id: string;
|
|
1092
|
+
/** Human-readable display name */
|
|
1093
|
+
name: string;
|
|
1094
|
+
/** Optional description of the model */
|
|
1095
|
+
description?: string;
|
|
1096
|
+
/** Optional context window size in tokens */
|
|
1097
|
+
contextLength?: number;
|
|
1098
|
+
/** Optional icon identifier for UI display */
|
|
1099
|
+
iconId?: string;
|
|
1100
|
+
/** Optional slug for additional lookups (e.g., OpenRouter endpoint queries) */
|
|
1101
|
+
slug?: string;
|
|
1051
1102
|
}
|
|
1052
1103
|
/**
|
|
1053
|
-
*
|
|
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)
|
|
1104
|
+
* Provider interface - thin translation layer between Standard Agents and LLM APIs
|
|
1092
1105
|
*/
|
|
1093
|
-
interface
|
|
1106
|
+
interface LLMProviderInterface {
|
|
1107
|
+
readonly name: string;
|
|
1108
|
+
readonly specificationVersion: '1';
|
|
1094
1109
|
/**
|
|
1095
|
-
*
|
|
1096
|
-
* Must be a prompt defined in agents/prompts/.
|
|
1110
|
+
* Non-streaming generation
|
|
1097
1111
|
*/
|
|
1098
|
-
|
|
1112
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
1099
1113
|
/**
|
|
1100
|
-
*
|
|
1101
|
-
* @default true
|
|
1114
|
+
* Streaming generation
|
|
1102
1115
|
*/
|
|
1103
|
-
|
|
1116
|
+
stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
|
|
1104
1117
|
/**
|
|
1105
|
-
*
|
|
1106
|
-
* @default true
|
|
1118
|
+
* Check if this provider supports a model
|
|
1107
1119
|
*/
|
|
1108
|
-
|
|
1120
|
+
supportsModel?(modelId: string): boolean;
|
|
1109
1121
|
/**
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1122
|
+
* List available models from this provider.
|
|
1123
|
+
* Optional for backwards compatibility - providers may implement this
|
|
1124
|
+
* to enable model selection in the UI.
|
|
1125
|
+
*
|
|
1126
|
+
* @param filter - Optional search string to filter models by name/id
|
|
1127
|
+
* @returns Array of available models
|
|
1128
|
+
*/
|
|
1129
|
+
getModels?(filter?: string): Promise<ProviderModelInfo[]>;
|
|
1130
|
+
/**
|
|
1131
|
+
* Fetch capabilities for a specific model.
|
|
1132
|
+
* Optional for backwards compatibility - providers may implement this
|
|
1133
|
+
* to enable auto-detection of model features in the UI.
|
|
1134
|
+
*
|
|
1135
|
+
* @param modelId - The model identifier (e.g., 'gpt-4o', 'anthropic/claude-3-opus')
|
|
1136
|
+
* @returns The model capabilities, or null if not available
|
|
1137
|
+
*/
|
|
1138
|
+
getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Get tools embedded in this provider.
|
|
1141
|
+
* Optional - providers may implement this to expose built-in tools
|
|
1142
|
+
* (e.g., OpenAI's web_search, file_search, code_interpreter).
|
|
1143
|
+
*
|
|
1144
|
+
* These tools are defined using defineTool() with optional tenv requirements.
|
|
1145
|
+
* Tools returned here can be referenced by name in model/prompt definitions.
|
|
1146
|
+
*
|
|
1147
|
+
* @param modelId - Optional filter to get tools available for a specific model
|
|
1148
|
+
* @returns Record of tool name to tool definition (sync or async)
|
|
1149
|
+
*/
|
|
1150
|
+
getTools?(modelId?: string): Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>>>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Get an icon for this provider or a specific model.
|
|
1153
|
+
* Optional - providers may implement this to provide UI icons.
|
|
1154
|
+
*
|
|
1155
|
+
* **Preferred return format: SVG data URI** (e.g., 'data:image/svg+xml,...')
|
|
1156
|
+
*
|
|
1157
|
+
* The data URI format allows icons to be embedded directly in the UI without
|
|
1158
|
+
* additional network requests. Use the `svgToDataUri()` helper from provider
|
|
1159
|
+
* packages to convert SVG strings.
|
|
1160
|
+
*
|
|
1161
|
+
* Return value can be:
|
|
1162
|
+
* - A data URI (e.g., 'data:image/svg+xml,...') - **PREFERRED**
|
|
1163
|
+
* - A full URL (e.g., 'https://example.com/icon.svg')
|
|
1164
|
+
* - An icon identifier that the UI resolves (legacy)
|
|
1165
|
+
*
|
|
1166
|
+
* For providers like OpenRouter that host many models, the modelId parameter
|
|
1167
|
+
* allows returning different icons based on the model's origin lab
|
|
1168
|
+
* (e.g., 'anthropic/claude-3-opus' -> anthropic icon).
|
|
1169
|
+
*
|
|
1170
|
+
* @param modelId - Optional model ID to get a model-specific icon
|
|
1171
|
+
* @returns SVG data URI (preferred), URL, icon identifier, or undefined
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* // Provider returning its own icon
|
|
1176
|
+
* getIcon() {
|
|
1177
|
+
* return svgToDataUri(OPENAI_ICON);
|
|
1178
|
+
* }
|
|
1179
|
+
*
|
|
1180
|
+
* // Provider returning model-specific icon (e.g., OpenRouter)
|
|
1181
|
+
* getIcon(modelId?: string) {
|
|
1182
|
+
* if (modelId) {
|
|
1183
|
+
* const lab = modelId.split('/')[0]; // 'anthropic' from 'anthropic/claude-3'
|
|
1184
|
+
* return getLabIconDataUri(lab);
|
|
1185
|
+
* }
|
|
1186
|
+
* return svgToDataUri(OPENROUTER_ICON);
|
|
1187
|
+
* }
|
|
1188
|
+
* ```
|
|
1189
|
+
*/
|
|
1190
|
+
getIcon?(modelId?: string): string | undefined;
|
|
1191
|
+
/**
|
|
1192
|
+
* Transform a ProviderRequest to the provider's native format for inspection/debugging.
|
|
1193
|
+
* Returns the transformed request as it would be sent to the provider's API.
|
|
1194
|
+
*
|
|
1195
|
+
* This is used by the admin UI to view logged requests in provider-specific format,
|
|
1196
|
+
* helping debug issues like message transformation or tool handling.
|
|
1197
|
+
*
|
|
1198
|
+
* Implementations should truncate base64 data to ~50 chars for readability.
|
|
1199
|
+
*
|
|
1200
|
+
* @param request - The Standard Agents format request to transform
|
|
1201
|
+
* @returns The transformed request in the provider's native format
|
|
1202
|
+
*/
|
|
1203
|
+
inspectRequest?(request: ProviderRequest): Promise<InspectedRequest>;
|
|
1204
|
+
/**
|
|
1205
|
+
* Fetch additional metadata about a completed response.
|
|
1206
|
+
* Called asynchronously after the response is received - does not block the main execution flow.
|
|
1207
|
+
*
|
|
1208
|
+
* This is useful for providers (like aggregators) where complete metadata isn't available
|
|
1209
|
+
* immediately. The execution engine calls this in the background and uses the returned
|
|
1210
|
+
* data to update log records.
|
|
1211
|
+
*
|
|
1212
|
+
* @param summary - Stripped-down response info (no content/attachments)
|
|
1213
|
+
* @param signal - Optional abort signal for cancellation
|
|
1214
|
+
* @returns Additional metadata or null if unavailable
|
|
1215
|
+
*/
|
|
1216
|
+
getResponseMetadata?(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Result from inspectRequest() - the transformed request in provider's native format
|
|
1220
|
+
*/
|
|
1221
|
+
interface InspectedRequest {
|
|
1222
|
+
/** The transformed request body as it would be sent to the API */
|
|
1223
|
+
body: Record<string, unknown>;
|
|
1224
|
+
/** Path to the messages array within body (e.g., "input" for OpenAI, "messages" for others) */
|
|
1225
|
+
messagesPath: string;
|
|
1226
|
+
/** Optional: Additional metadata about the transformation */
|
|
1227
|
+
metadata?: {
|
|
1228
|
+
/** The API endpoint that would be called */
|
|
1229
|
+
endpoint?: string;
|
|
1230
|
+
/** Headers that would be sent (excluding auth) */
|
|
1231
|
+
headers?: Record<string, string>;
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Standard Agent request format - providers translate to their native format
|
|
1236
|
+
*/
|
|
1237
|
+
interface ProviderRequest {
|
|
1238
|
+
model: string;
|
|
1239
|
+
messages: ProviderMessage[];
|
|
1240
|
+
tools?: ProviderTool[];
|
|
1241
|
+
toolChoice?: 'auto' | 'none' | 'required' | {
|
|
1242
|
+
name: string;
|
|
1243
|
+
};
|
|
1244
|
+
parallelToolCalls?: boolean;
|
|
1245
|
+
maxOutputTokens?: number;
|
|
1246
|
+
temperature?: number;
|
|
1247
|
+
topP?: number;
|
|
1248
|
+
topK?: number;
|
|
1249
|
+
stopSequences?: string[];
|
|
1250
|
+
reasoning?: {
|
|
1251
|
+
level?: number;
|
|
1252
|
+
maxTokens?: number;
|
|
1253
|
+
exclude?: boolean;
|
|
1254
|
+
};
|
|
1255
|
+
responseFormat?: {
|
|
1256
|
+
type: 'text';
|
|
1257
|
+
} | {
|
|
1258
|
+
type: 'json';
|
|
1259
|
+
schema?: Record<string, unknown>;
|
|
1260
|
+
};
|
|
1261
|
+
signal?: AbortSignal;
|
|
1262
|
+
providerOptions?: Record<string, unknown>;
|
|
1263
|
+
}
|
|
1264
|
+
type ProviderMessage = ProviderSystemMessage | ProviderUserMessage | ProviderAssistantMessage | ProviderToolMessage;
|
|
1265
|
+
interface ProviderSystemMessage {
|
|
1266
|
+
role: 'system';
|
|
1267
|
+
content: string;
|
|
1268
|
+
}
|
|
1269
|
+
interface ProviderUserMessage {
|
|
1270
|
+
role: 'user';
|
|
1271
|
+
content: ProviderMessageContent;
|
|
1272
|
+
}
|
|
1273
|
+
interface ProviderAssistantMessage {
|
|
1274
|
+
role: 'assistant';
|
|
1275
|
+
content?: string | null;
|
|
1276
|
+
reasoning?: string | null;
|
|
1277
|
+
reasoningDetails?: ProviderReasoningDetail[];
|
|
1278
|
+
toolCalls?: ProviderToolCallPart[];
|
|
1279
|
+
}
|
|
1280
|
+
interface ProviderToolMessage {
|
|
1281
|
+
role: 'tool';
|
|
1282
|
+
toolCallId: string;
|
|
1283
|
+
toolName: string;
|
|
1284
|
+
content: ProviderToolResultContent;
|
|
1285
|
+
attachments?: ProviderAttachment[];
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Attachment on a provider message (loaded from storage, ready for provider-specific transformation)
|
|
1289
|
+
*/
|
|
1290
|
+
interface ProviderAttachment {
|
|
1291
|
+
type: 'image' | 'file';
|
|
1292
|
+
data: string;
|
|
1293
|
+
mediaType: string;
|
|
1294
|
+
name?: string;
|
|
1295
|
+
path?: string;
|
|
1296
|
+
}
|
|
1297
|
+
type ProviderMessageContent = string | ContentPart[];
|
|
1298
|
+
type ContentPart = TextPart | ImagePart | ImageUrlPart | FilePart;
|
|
1299
|
+
interface TextPart {
|
|
1300
|
+
type: 'text';
|
|
1301
|
+
text: string;
|
|
1302
|
+
}
|
|
1303
|
+
interface ImagePart {
|
|
1304
|
+
type: 'image';
|
|
1305
|
+
data: string;
|
|
1306
|
+
mediaType: string;
|
|
1307
|
+
detail?: 'auto' | 'low' | 'high';
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Image URL content part (OpenAI/OpenRouter format).
|
|
1311
|
+
* Used for passing image URLs directly to providers.
|
|
1312
|
+
*/
|
|
1313
|
+
interface ImageUrlPart {
|
|
1314
|
+
type: 'image_url';
|
|
1315
|
+
image_url: {
|
|
1316
|
+
url: string;
|
|
1317
|
+
detail?: 'auto' | 'low' | 'high';
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
interface FilePart {
|
|
1321
|
+
type: 'file';
|
|
1322
|
+
data: string;
|
|
1323
|
+
mediaType: string;
|
|
1324
|
+
filename?: string;
|
|
1325
|
+
}
|
|
1326
|
+
interface ProviderTool {
|
|
1327
|
+
type: 'function';
|
|
1328
|
+
function: {
|
|
1329
|
+
name: string;
|
|
1330
|
+
description: string;
|
|
1331
|
+
parameters?: Record<string, unknown>;
|
|
1332
|
+
};
|
|
1333
|
+
/**
|
|
1334
|
+
* Where this tool is executed:
|
|
1335
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
1336
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
1337
|
+
*/
|
|
1338
|
+
executionMode?: 'local' | 'provider';
|
|
1339
|
+
/**
|
|
1340
|
+
* Which provider executes this tool (when executionMode='provider')
|
|
1341
|
+
* e.g., 'openai', 'anthropic'
|
|
1342
|
+
*/
|
|
1343
|
+
executionProvider?: string;
|
|
1344
|
+
}
|
|
1345
|
+
interface ProviderToolCallPart {
|
|
1346
|
+
id: string;
|
|
1347
|
+
name: string;
|
|
1348
|
+
arguments: Record<string, unknown>;
|
|
1349
|
+
}
|
|
1350
|
+
type ProviderToolResultContent = string | {
|
|
1351
|
+
type: 'text';
|
|
1352
|
+
text: string;
|
|
1353
|
+
} | {
|
|
1354
|
+
type: 'error';
|
|
1355
|
+
error: string;
|
|
1356
|
+
} | ContentPart[];
|
|
1357
|
+
interface ProviderResponse {
|
|
1358
|
+
content: string | null;
|
|
1359
|
+
reasoning?: string | null;
|
|
1360
|
+
reasoningDetails?: ProviderReasoningDetail[];
|
|
1361
|
+
toolCalls?: ProviderToolCallPart[];
|
|
1362
|
+
images?: ProviderGeneratedImage[];
|
|
1363
|
+
finishReason: ProviderFinishReason;
|
|
1364
|
+
usage: ProviderUsage;
|
|
1365
|
+
metadata?: Record<string, unknown>;
|
|
1366
|
+
}
|
|
1367
|
+
type ProviderFinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error';
|
|
1368
|
+
interface ProviderUsage {
|
|
1369
|
+
promptTokens: number;
|
|
1370
|
+
completionTokens: number;
|
|
1371
|
+
totalTokens: number;
|
|
1372
|
+
reasoningTokens?: number;
|
|
1373
|
+
cachedTokens?: number;
|
|
1374
|
+
cost?: number;
|
|
1375
|
+
/** The actual provider that fulfilled the request (e.g., 'google', 'anthropic') */
|
|
1376
|
+
provider?: string;
|
|
1377
|
+
}
|
|
1378
|
+
interface ProviderGeneratedImage {
|
|
1379
|
+
/** Unique ID for this generated image (used to link to tool call) */
|
|
1380
|
+
id?: string;
|
|
1381
|
+
/** Name of the tool that generated this image (e.g., 'image_generation') */
|
|
1382
|
+
toolName?: string;
|
|
1383
|
+
data: string;
|
|
1384
|
+
mediaType: string;
|
|
1385
|
+
revisedPrompt?: string;
|
|
1386
|
+
}
|
|
1387
|
+
interface ProviderReasoningDetail {
|
|
1388
|
+
type: 'summary' | 'encrypted' | 'text';
|
|
1389
|
+
/** Original reasoning ID from provider (e.g., rs_xxx for OpenAI) */
|
|
1390
|
+
id?: string;
|
|
1391
|
+
text?: string;
|
|
1392
|
+
data?: string;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Web search result from provider
|
|
1396
|
+
*/
|
|
1397
|
+
interface ProviderWebSearchResult {
|
|
1398
|
+
/** Unique ID of the web search call */
|
|
1399
|
+
id: string;
|
|
1400
|
+
/** Status of the search */
|
|
1401
|
+
status: 'in_progress' | 'searching' | 'completed' | 'failed';
|
|
1402
|
+
/** Search actions performed */
|
|
1403
|
+
actions?: Array<{
|
|
1404
|
+
type: 'search' | 'open_page' | 'find';
|
|
1405
|
+
query?: string;
|
|
1406
|
+
url?: string;
|
|
1407
|
+
pattern?: string;
|
|
1408
|
+
sources?: Array<{
|
|
1409
|
+
type: 'url';
|
|
1410
|
+
url: string;
|
|
1411
|
+
title?: string;
|
|
1412
|
+
}>;
|
|
1413
|
+
}>;
|
|
1414
|
+
}
|
|
1415
|
+
type ProviderStreamChunk = {
|
|
1416
|
+
type: 'content-delta';
|
|
1417
|
+
delta: string;
|
|
1418
|
+
} | {
|
|
1419
|
+
type: 'content-done';
|
|
1420
|
+
} | {
|
|
1421
|
+
type: 'reasoning-delta';
|
|
1422
|
+
delta: string;
|
|
1423
|
+
} | {
|
|
1424
|
+
type: 'reasoning-done';
|
|
1425
|
+
} | {
|
|
1426
|
+
type: 'tool-call-start';
|
|
1427
|
+
id: string;
|
|
1428
|
+
name: string;
|
|
1429
|
+
} | {
|
|
1430
|
+
type: 'tool-call-delta';
|
|
1431
|
+
id: string;
|
|
1432
|
+
argumentsDelta: string;
|
|
1433
|
+
} | {
|
|
1434
|
+
type: 'tool-call-done';
|
|
1435
|
+
id: string;
|
|
1436
|
+
arguments: Record<string, unknown>;
|
|
1437
|
+
} | {
|
|
1438
|
+
type: 'image-delta';
|
|
1439
|
+
index: number;
|
|
1440
|
+
data: string;
|
|
1441
|
+
} | {
|
|
1442
|
+
type: 'image-done';
|
|
1443
|
+
index: number;
|
|
1444
|
+
image: ProviderGeneratedImage;
|
|
1445
|
+
} | {
|
|
1446
|
+
type: 'web-search-done';
|
|
1447
|
+
result: ProviderWebSearchResult;
|
|
1448
|
+
} | {
|
|
1449
|
+
type: 'finish';
|
|
1450
|
+
finishReason: ProviderFinishReason;
|
|
1451
|
+
usage: ProviderUsage;
|
|
1452
|
+
reasoningDetails?: ProviderReasoningDetail[];
|
|
1453
|
+
} | {
|
|
1454
|
+
type: 'error';
|
|
1455
|
+
error: string;
|
|
1456
|
+
code?: string;
|
|
1457
|
+
};
|
|
1458
|
+
type ProviderErrorCode = 'rate_limit' | 'invalid_request' | 'auth_error' | 'server_error' | 'timeout' | 'unknown';
|
|
1459
|
+
declare class ProviderError extends Error {
|
|
1460
|
+
code: ProviderErrorCode;
|
|
1461
|
+
statusCode?: number | undefined;
|
|
1462
|
+
retryAfter?: number | undefined;
|
|
1463
|
+
constructor(message: string, code: ProviderErrorCode, statusCode?: number | undefined, retryAfter?: number | undefined);
|
|
1464
|
+
/**
|
|
1465
|
+
* Whether this error is retryable
|
|
1466
|
+
*/
|
|
1467
|
+
get isRetryable(): boolean;
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Maps a 0-100 reasoning level to the model's nearest supported level
|
|
1471
|
+
*/
|
|
1472
|
+
declare function mapReasoningLevel(level: number, reasoningLevels: Record<number, string | null> | undefined): string | null;
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* Model definition types for Standard Agents.
|
|
1476
|
+
*
|
|
1477
|
+
* Models define LLM configurations including provider, model ID, pricing,
|
|
1478
|
+
* and fallback chains. Models are referenced by name from prompts.
|
|
1479
|
+
*
|
|
1480
|
+
* @module
|
|
1481
|
+
*/
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* Legacy provider identifiers - kept for reference only.
|
|
1485
|
+
* New code should use ProviderFactory imports from provider packages.
|
|
1486
|
+
*
|
|
1487
|
+
* @deprecated Use ProviderFactory from provider packages instead
|
|
1488
|
+
* @internal
|
|
1489
|
+
*/
|
|
1490
|
+
type ModelProvider = 'openai' | 'openrouter' | 'anthropic' | 'google' | 'test';
|
|
1491
|
+
/**
|
|
1492
|
+
* Provider interface for LLM providers.
|
|
1493
|
+
*
|
|
1494
|
+
* Provider packages export a factory function that creates instances
|
|
1495
|
+
* implementing this interface. This is structurally compatible with
|
|
1496
|
+
* LLMProviderInterface from providers.ts.
|
|
1497
|
+
*/
|
|
1498
|
+
interface ProviderInstance {
|
|
1499
|
+
readonly name: string;
|
|
1500
|
+
readonly specificationVersion: '1';
|
|
1501
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
1502
|
+
stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
|
|
1503
|
+
supportsModel?(modelId: string): boolean;
|
|
1504
|
+
/** List available models from this provider */
|
|
1505
|
+
getModels?(filter?: string): Promise<ProviderModelInfo[]>;
|
|
1506
|
+
/** Fetch capabilities for a specific model */
|
|
1507
|
+
getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
|
|
1508
|
+
/** Get provider-specific tools available for a model */
|
|
1509
|
+
getTools?(modelId?: string): Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>>>;
|
|
1510
|
+
/** Get the icon URL for this provider or a specific model */
|
|
1511
|
+
getIcon?(modelId?: string): string | undefined;
|
|
1512
|
+
/** Inspect a raw request for debugging purposes */
|
|
1513
|
+
inspectRequest?(request: ProviderRequest): Promise<InspectedRequest>;
|
|
1514
|
+
/** Fetch additional metadata about a completed response */
|
|
1515
|
+
getResponseMetadata?(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Configuration passed to provider factory functions.
|
|
1519
|
+
*/
|
|
1520
|
+
interface ProviderFactoryConfig {
|
|
1521
|
+
apiKey: string;
|
|
1522
|
+
baseUrl?: string;
|
|
1523
|
+
timeout?: number;
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Provider factory with optional typed providerOptions schema.
|
|
1527
|
+
*
|
|
1528
|
+
* The schema property allows type inference and runtime validation of
|
|
1529
|
+
* provider-specific options in model definitions.
|
|
1530
|
+
*
|
|
1531
|
+
* @template TOptions - Zod schema type for providerOptions (defaults to ZodTypeAny)
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* ```typescript
|
|
1535
|
+
* import { openai } from '@standardagents/openai';
|
|
1536
|
+
*
|
|
1537
|
+
* // openai is a ProviderFactoryWithOptions with typed schema
|
|
1538
|
+
* const provider = openai({ apiKey: 'sk-...' });
|
|
1539
|
+
*
|
|
1540
|
+
* // Access the schema for validation
|
|
1541
|
+
* openai.providerOptions?.parse({ service_tier: 'default' });
|
|
1542
|
+
* ```
|
|
1543
|
+
*/
|
|
1544
|
+
interface ProviderFactoryWithOptions<TOptions extends ZodTypeAny = ZodTypeAny> {
|
|
1545
|
+
(config: ProviderFactoryConfig): ProviderInstance;
|
|
1546
|
+
/** Zod schema for provider-specific options */
|
|
1547
|
+
providerOptions?: TOptions;
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Factory function that creates provider instances.
|
|
1551
|
+
*
|
|
1552
|
+
* Provider packages (like @standardagents/openai) export this type.
|
|
1553
|
+
* This is an alias for ProviderFactoryWithOptions for backward compatibility.
|
|
1554
|
+
*
|
|
1555
|
+
* @example
|
|
1556
|
+
* ```typescript
|
|
1557
|
+
* import { openai } from '@standardagents/openai';
|
|
1558
|
+
*
|
|
1559
|
+
* // openai is a ProviderFactory
|
|
1560
|
+
* const provider = openai({ apiKey: 'sk-...' });
|
|
1561
|
+
* ```
|
|
1562
|
+
*/
|
|
1563
|
+
type ProviderFactory = ProviderFactoryWithOptions<ZodTypeAny>;
|
|
1564
|
+
/**
|
|
1565
|
+
* Extract providerOptions type from a provider factory.
|
|
1566
|
+
*
|
|
1567
|
+
* Returns the inferred input type from the provider's Zod schema,
|
|
1568
|
+
* or Record<string, unknown> if no schema is defined.
|
|
1569
|
+
*
|
|
1570
|
+
* @template P - Provider factory type
|
|
1571
|
+
*/
|
|
1572
|
+
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>;
|
|
1573
|
+
/**
|
|
1574
|
+
* Model capability flags indicating supported features.
|
|
1575
|
+
*
|
|
1576
|
+
* These capabilities are used by the FlowEngine to determine how to
|
|
1577
|
+
* interact with the model and what features are available.
|
|
1578
|
+
*/
|
|
1579
|
+
interface ModelCapabilities {
|
|
1580
|
+
/**
|
|
1581
|
+
* Reasoning level mapping (0-100 scale → model-specific values).
|
|
1582
|
+
* Keys are breakpoints, values are model's native reasoning strings.
|
|
1583
|
+
*
|
|
1584
|
+
* @example
|
|
1585
|
+
* // OpenAI o-series
|
|
1586
|
+
* reasoningLevels: { 0: null, 33: 'low', 66: 'medium', 100: 'high' }
|
|
1587
|
+
*
|
|
1588
|
+
* @example
|
|
1589
|
+
* // Binary reasoning (Claude extended thinking)
|
|
1590
|
+
* reasoningLevels: { 0: null, 100: 'enabled' }
|
|
1591
|
+
*
|
|
1592
|
+
* @example
|
|
1593
|
+
* // No reasoning support
|
|
1594
|
+
* reasoningLevels: { 0: null }
|
|
1595
|
+
*/
|
|
1596
|
+
reasoningLevels?: Record<number, string | null>;
|
|
1597
|
+
/**
|
|
1598
|
+
* Whether the model supports vision (image understanding).
|
|
1599
|
+
* When true, image attachments will be sent to the model as part of the request.
|
|
1600
|
+
* Models like GPT-4o, Claude 3, and Gemini support vision.
|
|
1601
|
+
*/
|
|
1602
|
+
supportsImages?: boolean;
|
|
1603
|
+
/**
|
|
1604
|
+
* @deprecated Use supportsImages instead
|
|
1605
|
+
*/
|
|
1606
|
+
vision?: boolean;
|
|
1607
|
+
/**
|
|
1608
|
+
* Whether the model supports function calling (tool use).
|
|
1609
|
+
* Most modern models support this, defaults to true if not specified.
|
|
1610
|
+
*/
|
|
1611
|
+
supportsToolCalls?: boolean;
|
|
1612
|
+
/**
|
|
1613
|
+
* @deprecated Use supportsToolCalls instead
|
|
1614
|
+
*/
|
|
1615
|
+
functionCalling?: boolean;
|
|
1616
|
+
/**
|
|
1617
|
+
* Whether the model supports streaming responses.
|
|
1618
|
+
* @default true
|
|
1619
|
+
*/
|
|
1620
|
+
supportsStreaming?: boolean;
|
|
1621
|
+
/**
|
|
1622
|
+
* Whether the model supports structured outputs (JSON mode).
|
|
1623
|
+
*/
|
|
1624
|
+
supportsJsonMode?: boolean;
|
|
1625
|
+
/**
|
|
1626
|
+
* @deprecated Use supportsJsonMode instead
|
|
1627
|
+
*/
|
|
1628
|
+
structuredOutputs?: boolean;
|
|
1629
|
+
/**
|
|
1630
|
+
* Maximum context window size in tokens.
|
|
1631
|
+
*/
|
|
1632
|
+
maxContextTokens?: number;
|
|
1633
|
+
/**
|
|
1634
|
+
* Maximum output tokens the model can generate.
|
|
1635
|
+
*/
|
|
1636
|
+
maxOutputTokens?: number;
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Model definition configuration.
|
|
1640
|
+
*
|
|
1641
|
+
* Defines an LLM model with its provider, pricing, capabilities, and fallback chain.
|
|
1642
|
+
*
|
|
1643
|
+
* @template N - The model name as a string literal type for type inference
|
|
1644
|
+
*
|
|
1645
|
+
* @example Basic usage
|
|
1646
|
+
* ```typescript
|
|
1647
|
+
* import { defineModel } from '@standardagents/spec';
|
|
1648
|
+
* import { openai } from '@standardagents/openai';
|
|
1649
|
+
*
|
|
1650
|
+
* export default defineModel({
|
|
1651
|
+
* name: 'gpt-4o',
|
|
1652
|
+
* provider: openai,
|
|
1653
|
+
* model: 'gpt-4o',
|
|
1654
|
+
* inputPrice: 2.5,
|
|
1655
|
+
* outputPrice: 10,
|
|
1656
|
+
* });
|
|
1657
|
+
* ```
|
|
1658
|
+
*
|
|
1659
|
+
* @example With capabilities and typed provider options
|
|
1660
|
+
* ```typescript
|
|
1661
|
+
* import { defineModel } from '@standardagents/spec';
|
|
1662
|
+
* import { openai } from '@standardagents/openai';
|
|
1663
|
+
*
|
|
1664
|
+
* export default defineModel({
|
|
1665
|
+
* name: 'gpt-4o',
|
|
1666
|
+
* provider: openai,
|
|
1667
|
+
* model: 'gpt-4o',
|
|
1668
|
+
* inputPrice: 2.5,
|
|
1669
|
+
* outputPrice: 10,
|
|
1670
|
+
* capabilities: {
|
|
1671
|
+
* supportsImages: true,
|
|
1672
|
+
* supportsToolCalls: true,
|
|
1673
|
+
* supportsJsonMode: true,
|
|
1674
|
+
* maxContextTokens: 128000,
|
|
1675
|
+
* },
|
|
1676
|
+
* providerOptions: {
|
|
1677
|
+
* service_tier: 'default', // TypeScript knows this is valid
|
|
1678
|
+
* },
|
|
1679
|
+
* });
|
|
1680
|
+
* ```
|
|
1681
|
+
*/
|
|
1682
|
+
interface ModelDefinition<N extends string = string, P extends ProviderFactoryWithOptions<ZodTypeAny> = ProviderFactoryWithOptions<ZodTypeAny>> {
|
|
1683
|
+
/**
|
|
1684
|
+
* Unique name for this model definition.
|
|
1685
|
+
* Used as the identifier when referencing from prompts.
|
|
1686
|
+
* Should be descriptive and consistent (e.g., 'gpt-4o', 'claude-3-opus').
|
|
1687
|
+
*/
|
|
1688
|
+
name: N;
|
|
1689
|
+
/**
|
|
1690
|
+
* The LLM provider factory function to use for API calls.
|
|
1691
|
+
*
|
|
1692
|
+
* Import from a provider package like @standardagents/openai or @standardagents/openrouter.
|
|
1693
|
+
* The provider's type determines what providerOptions are available.
|
|
1694
|
+
*
|
|
1695
|
+
* @example
|
|
1696
|
+
* ```typescript
|
|
1697
|
+
* import { openai } from '@standardagents/openai';
|
|
1698
|
+
* provider: openai
|
|
1699
|
+
* ```
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```typescript
|
|
1703
|
+
* import { openrouter } from '@standardagents/openrouter';
|
|
1704
|
+
* provider: openrouter
|
|
1705
|
+
* ```
|
|
1706
|
+
*/
|
|
1707
|
+
provider: P;
|
|
1708
|
+
/**
|
|
1709
|
+
* The actual model identifier sent to the provider API.
|
|
1710
|
+
*
|
|
1711
|
+
* For OpenAI: 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', etc.
|
|
1712
|
+
* For OpenRouter: 'openai/gpt-4o', 'anthropic/claude-3-opus', etc.
|
|
1713
|
+
* For Anthropic: 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', etc.
|
|
1714
|
+
* For Google: 'gemini-1.5-pro', 'gemini-1.5-flash', etc.
|
|
1715
|
+
*/
|
|
1716
|
+
model: string;
|
|
1717
|
+
/**
|
|
1718
|
+
* Optional list of additional provider prefixes for OpenRouter.
|
|
1719
|
+
* Allows routing through specific providers when using OpenRouter.
|
|
1720
|
+
*
|
|
1721
|
+
* @example ['anthropic', 'google'] - prefer Anthropic, fallback to Google
|
|
1722
|
+
*/
|
|
1723
|
+
includedProviders?: string[];
|
|
1724
|
+
/**
|
|
1725
|
+
* Fallback model names to try if this model fails.
|
|
1726
|
+
* Referenced by model name (must be defined in agents/models/).
|
|
1727
|
+
* Tried in order after primary model exhausts retries.
|
|
1728
|
+
*
|
|
1729
|
+
* @example ['gpt-4', 'gpt-3.5-turbo']
|
|
1730
|
+
*/
|
|
1731
|
+
fallbacks?: StandardAgentSpec.Models[];
|
|
1732
|
+
/**
|
|
1733
|
+
* Cost per 1 million input tokens in USD.
|
|
1734
|
+
* Used for cost tracking and reporting in logs.
|
|
1735
|
+
*/
|
|
1736
|
+
inputPrice?: number;
|
|
1737
|
+
/**
|
|
1738
|
+
* Cost per 1 million output tokens in USD.
|
|
1739
|
+
* Used for cost tracking and reporting in logs.
|
|
1740
|
+
*/
|
|
1741
|
+
outputPrice?: number;
|
|
1742
|
+
/**
|
|
1743
|
+
* Cost per 1 million cached input tokens in USD.
|
|
1744
|
+
* Some providers offer reduced pricing for cached/repeated prompts.
|
|
1745
|
+
*/
|
|
1746
|
+
cachedPrice?: number;
|
|
1747
|
+
/**
|
|
1748
|
+
* Model capabilities - features this model supports.
|
|
1749
|
+
*/
|
|
1750
|
+
capabilities?: ModelCapabilities;
|
|
1751
|
+
/**
|
|
1752
|
+
* Provider-specific options passed through to the provider.
|
|
1753
|
+
* These are merged with prompt-level providerOptions (model options are defaults).
|
|
1754
|
+
*
|
|
1755
|
+
* The type is automatically inferred from the provider's schema when available,
|
|
1756
|
+
* providing TypeScript autocompletion and runtime validation.
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1759
|
+
* ```typescript
|
|
1760
|
+
* // With OpenAI provider
|
|
1761
|
+
* providerOptions: {
|
|
1762
|
+
* service_tier: 'default',
|
|
1763
|
+
* }
|
|
1764
|
+
* ```
|
|
1765
|
+
*
|
|
1766
|
+
* @example
|
|
1767
|
+
* ```typescript
|
|
1768
|
+
* // With OpenRouter provider
|
|
1769
|
+
* providerOptions: {
|
|
1770
|
+
* provider: {
|
|
1771
|
+
* zdr: true,
|
|
1772
|
+
* max_price: { prompt: 1 },
|
|
1773
|
+
* },
|
|
1774
|
+
* }
|
|
1775
|
+
* ```
|
|
1776
|
+
*/
|
|
1777
|
+
providerOptions?: InferProviderOptions<P>;
|
|
1778
|
+
/**
|
|
1779
|
+
* Provider tools available for this model.
|
|
1780
|
+
* References tool names from provider.getTools().
|
|
1781
|
+
*
|
|
1782
|
+
* Provider tools are built-in tools offered by the provider (e.g., OpenAI's
|
|
1783
|
+
* web_search, file_search, code_interpreter, image_generation). These tools
|
|
1784
|
+
* can be used in prompts alongside custom tools.
|
|
1785
|
+
*
|
|
1786
|
+
* @example
|
|
1787
|
+
* ```typescript
|
|
1788
|
+
* providerTools: ['web_search', 'code_interpreter'],
|
|
1789
|
+
* ```
|
|
1790
|
+
*/
|
|
1791
|
+
providerTools?: string[];
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Defines an LLM model configuration.
|
|
1795
|
+
*
|
|
1796
|
+
* Models are the foundation of the agent system - they specify which
|
|
1797
|
+
* AI model to use and how to connect to it. Models can have fallbacks
|
|
1798
|
+
* for reliability and include pricing for cost tracking.
|
|
1799
|
+
*
|
|
1800
|
+
* @template N - The model name as a string literal type
|
|
1801
|
+
* @param options - Model configuration options
|
|
1802
|
+
* @returns The model definition for registration
|
|
1803
|
+
*
|
|
1804
|
+
* @example
|
|
1805
|
+
* ```typescript
|
|
1806
|
+
* // agents/models/gpt_4o.ts
|
|
1807
|
+
* import { defineModel } from '@standardagents/spec';
|
|
1808
|
+
* import { openai } from '@standardagents/openai';
|
|
1809
|
+
*
|
|
1810
|
+
* export default defineModel({
|
|
1811
|
+
* name: 'gpt-4o',
|
|
1812
|
+
* provider: openai,
|
|
1813
|
+
* model: 'gpt-4o',
|
|
1814
|
+
* fallbacks: ['gpt-4-turbo'],
|
|
1815
|
+
* inputPrice: 2.5,
|
|
1816
|
+
* outputPrice: 10,
|
|
1817
|
+
* });
|
|
1818
|
+
* ```
|
|
1819
|
+
*
|
|
1820
|
+
* @example
|
|
1821
|
+
* ```typescript
|
|
1822
|
+
* // Using OpenRouter with typed provider options
|
|
1823
|
+
* import { openrouter } from '@standardagents/openrouter';
|
|
1824
|
+
*
|
|
1825
|
+
* export default defineModel({
|
|
1826
|
+
* name: 'claude-3-opus',
|
|
1827
|
+
* provider: openrouter,
|
|
1828
|
+
* model: 'anthropic/claude-3-opus',
|
|
1829
|
+
* providerOptions: {
|
|
1830
|
+
* provider: {
|
|
1831
|
+
* zdr: true,
|
|
1832
|
+
* only: ['anthropic'],
|
|
1833
|
+
* },
|
|
1834
|
+
* },
|
|
1835
|
+
* });
|
|
1836
|
+
* ```
|
|
1837
|
+
*/
|
|
1838
|
+
declare function defineModel<N extends string, P extends ProviderFactoryWithOptions<ZodTypeAny>>(options: ModelDefinition<N, P>): ModelDefinition<N, P>;
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* Prompt definition types for Standard Agents.
|
|
1842
|
+
*
|
|
1843
|
+
* Prompts define LLM interaction configurations including the system prompt,
|
|
1844
|
+
* model selection, available tools, and various behavioral options.
|
|
1845
|
+
*
|
|
1846
|
+
* @module
|
|
1847
|
+
*/
|
|
1848
|
+
|
|
1849
|
+
/**
|
|
1850
|
+
* A text part of a prompt - static text content.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```typescript
|
|
1854
|
+
* { type: 'text', content: 'You are a helpful assistant.\n\n' }
|
|
1855
|
+
* ```
|
|
1856
|
+
*/
|
|
1857
|
+
interface PromptTextPart {
|
|
1858
|
+
type: 'text';
|
|
1859
|
+
/** The text content */
|
|
1860
|
+
content: string;
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* A prompt inclusion part - includes another prompt's content.
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```typescript
|
|
1867
|
+
* { type: 'include', prompt: 'responder_rules' }
|
|
1868
|
+
* ```
|
|
1869
|
+
*/
|
|
1870
|
+
interface PromptIncludePart {
|
|
1871
|
+
type: 'include';
|
|
1872
|
+
/** The name of the prompt to include */
|
|
1873
|
+
prompt: StandardAgentSpec.Prompts;
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* A single part of a structured prompt.
|
|
1877
|
+
* Discriminated union on `type` field for TypeScript narrowing.
|
|
1878
|
+
*/
|
|
1879
|
+
type PromptPart = PromptTextPart | PromptIncludePart;
|
|
1880
|
+
/**
|
|
1881
|
+
* A structured prompt is an array of prompt parts.
|
|
1882
|
+
* Provides composition with other prompts via includes.
|
|
1883
|
+
*
|
|
1884
|
+
* @example
|
|
1885
|
+
* ```typescript
|
|
1886
|
+
* prompt: [
|
|
1887
|
+
* { type: 'text', content: 'You are a helpful assistant.\n\n' },
|
|
1888
|
+
* { type: 'include', prompt: 'common_rules' },
|
|
1889
|
+
* { type: 'text', content: '\n\nBe concise.' },
|
|
1890
|
+
* ]
|
|
1891
|
+
* ```
|
|
1892
|
+
*/
|
|
1893
|
+
type StructuredPrompt = PromptPart[];
|
|
1894
|
+
/**
|
|
1895
|
+
* The prompt content can be either a plain string or a structured array.
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* ```typescript
|
|
1899
|
+
* // Simple string prompt:
|
|
1900
|
+
* prompt: 'You are a helpful assistant.'
|
|
1901
|
+
*
|
|
1902
|
+
* // Structured prompt with includes:
|
|
1903
|
+
* prompt: [
|
|
1904
|
+
* { type: 'text', content: 'You are a helpful assistant.\n\n' },
|
|
1905
|
+
* { type: 'include', prompt: 'common_rules' },
|
|
1906
|
+
* ]
|
|
1907
|
+
* ```
|
|
1908
|
+
*/
|
|
1909
|
+
type PromptContent = string | StructuredPrompt;
|
|
1910
|
+
/**
|
|
1911
|
+
* Configuration for sub-prompts used as tools.
|
|
1912
|
+
* These options control how results from sub-prompts are returned to the caller.
|
|
1913
|
+
*
|
|
1914
|
+
* @template T - The sub-prompt name type (for type-safe references)
|
|
1915
|
+
*/
|
|
1916
|
+
interface SubpromptConfig<T extends string = StandardAgentSpec.Callables> {
|
|
1917
|
+
/**
|
|
1918
|
+
* Name of the sub-prompt to call.
|
|
1919
|
+
* Must be a prompt defined in agents/prompts/.
|
|
1920
|
+
*/
|
|
1921
|
+
name: T;
|
|
1922
|
+
/**
|
|
1923
|
+
* Include text response content from sub-prompt execution in the result string.
|
|
1924
|
+
* @default true
|
|
1925
|
+
*/
|
|
1926
|
+
includeTextResponse?: boolean;
|
|
1927
|
+
/**
|
|
1928
|
+
* Serialize tool calls made by the sub-prompt (and their results) into the result string.
|
|
1929
|
+
* @default true
|
|
1930
|
+
*/
|
|
1931
|
+
includeToolCalls?: boolean;
|
|
1932
|
+
/**
|
|
1933
|
+
* Serialize any errors from the sub-prompt into the result string.
|
|
1934
|
+
* @default true
|
|
1112
1935
|
*/
|
|
1113
1936
|
includeErrors?: boolean;
|
|
1114
1937
|
/**
|
|
@@ -1121,24 +1944,86 @@ interface SubpromptConfig<T extends string = string> {
|
|
|
1121
1944
|
* "search term" as the initial user message.
|
|
1122
1945
|
*/
|
|
1123
1946
|
initUserMessageProperty?: string;
|
|
1947
|
+
/**
|
|
1948
|
+
* Property containing attachment path(s) to include as multimodal content
|
|
1949
|
+
* when invoking the sub-prompt.
|
|
1950
|
+
*
|
|
1951
|
+
* Supports both a single path string or an array of paths.
|
|
1952
|
+
*
|
|
1953
|
+
* @example
|
|
1954
|
+
* If the tool is called with `{ image: "/attachments/123.jpg" }` and
|
|
1955
|
+
* `initAttachmentsProperty: 'image'`, the sub-prompt will receive
|
|
1956
|
+
* the image as an attachment in the user message.
|
|
1957
|
+
*
|
|
1958
|
+
* @example
|
|
1959
|
+
* If the tool is called with `{ images: ["/attachments/a.jpg", "/attachments/b.jpg"] }` and
|
|
1960
|
+
* `initAttachmentsProperty: 'images'`, the sub-prompt will receive
|
|
1961
|
+
* both images as attachments.
|
|
1962
|
+
*/
|
|
1963
|
+
initAttachmentsProperty?: string;
|
|
1124
1964
|
}
|
|
1125
1965
|
/**
|
|
1126
1966
|
* @deprecated Use SubpromptConfig instead
|
|
1127
1967
|
*/
|
|
1128
1968
|
type ToolConfig<T extends string = string> = SubpromptConfig<T>;
|
|
1969
|
+
/**
|
|
1970
|
+
* Configuration for a tool used in a prompt.
|
|
1971
|
+
* Allows specifying tenv values and static options for the tool.
|
|
1972
|
+
*
|
|
1973
|
+
* @example
|
|
1974
|
+
* ```typescript
|
|
1975
|
+
* // Tool with tenv values
|
|
1976
|
+
* { name: 'file_search', tenvs: { vectorStoreId: 'vs_abc123' } }
|
|
1977
|
+
*
|
|
1978
|
+
* // Tool with options
|
|
1979
|
+
* { name: 'web_search', options: { searchContextSize: 'high' } }
|
|
1980
|
+
* ```
|
|
1981
|
+
*/
|
|
1982
|
+
interface PromptToolConfig {
|
|
1983
|
+
/**
|
|
1984
|
+
* Name of the tool (custom tool or provider tool).
|
|
1985
|
+
*/
|
|
1986
|
+
name: StandardAgentSpec.Callables;
|
|
1987
|
+
/**
|
|
1988
|
+
* Thread environment variable values for this tool.
|
|
1989
|
+
* These values are merged with agent and thread tenvs (prompt tenvs are lowest priority).
|
|
1990
|
+
*/
|
|
1991
|
+
tenvs?: Record<string, unknown>;
|
|
1992
|
+
/**
|
|
1993
|
+
* Static options for this tool.
|
|
1994
|
+
* Passed to the tool handler at execution time.
|
|
1995
|
+
*/
|
|
1996
|
+
options?: Record<string, unknown>;
|
|
1997
|
+
}
|
|
1129
1998
|
/**
|
|
1130
1999
|
* Reasoning configuration for models that support extended thinking.
|
|
1131
|
-
* Applies to models like OpenAI o1, Anthropic Claude with extended thinking,
|
|
2000
|
+
* Applies to models like OpenAI o1/o3, Anthropic Claude with extended thinking,
|
|
1132
2001
|
* Google Gemini with thinking, and Qwen with reasoning.
|
|
1133
2002
|
*/
|
|
1134
2003
|
interface ReasoningConfig {
|
|
1135
2004
|
/**
|
|
2005
|
+
* Numeric reasoning level on a 0-100 scale.
|
|
2006
|
+
* The FlowEngine maps this to the model's nearest supported reasoning option.
|
|
2007
|
+
*
|
|
2008
|
+
* @example
|
|
2009
|
+
* // Typical breakpoints:
|
|
2010
|
+
* // 0 = No reasoning
|
|
2011
|
+
* // 33 = Low effort
|
|
2012
|
+
* // 66 = Medium effort
|
|
2013
|
+
* // 100 = Maximum effort
|
|
2014
|
+
*
|
|
2015
|
+
* reasoning: { level: 75 } // Maps to 'high' on most models
|
|
2016
|
+
*/
|
|
2017
|
+
level?: number;
|
|
2018
|
+
/**
|
|
2019
|
+
* @deprecated Use `level` instead. Will be removed in future versions.
|
|
2020
|
+
*
|
|
1136
2021
|
* Effort level for reasoning models.
|
|
1137
2022
|
* Higher effort = more thinking tokens = potentially better results.
|
|
1138
2023
|
*
|
|
1139
|
-
* - `low`: Minimal reasoning, faster responses
|
|
1140
|
-
* - `medium`: Balanced reasoning and speed
|
|
1141
|
-
* - `high`: Maximum reasoning, slower but more thorough
|
|
2024
|
+
* - `low`: Minimal reasoning, faster responses (equivalent to level ~33)
|
|
2025
|
+
* - `medium`: Balanced reasoning and speed (equivalent to level ~66)
|
|
2026
|
+
* - `high`: Maximum reasoning, slower but more thorough (equivalent to level ~100)
|
|
1142
2027
|
*
|
|
1143
2028
|
* @default undefined (use model defaults)
|
|
1144
2029
|
*/
|
|
@@ -1205,7 +2090,7 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
|
|
|
1205
2090
|
* Model to use for this prompt.
|
|
1206
2091
|
* Must reference a model defined in agents/models/.
|
|
1207
2092
|
*/
|
|
1208
|
-
model:
|
|
2093
|
+
model: StandardAgentSpec.Models;
|
|
1209
2094
|
/**
|
|
1210
2095
|
* Include full chat history in the LLM context.
|
|
1211
2096
|
* @default false
|
|
@@ -1237,10 +2122,37 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
|
|
|
1237
2122
|
requiredSchema?: S;
|
|
1238
2123
|
/**
|
|
1239
2124
|
* Tools available to this prompt.
|
|
1240
|
-
* Can be
|
|
2125
|
+
* Can be:
|
|
2126
|
+
* - string: Simple tool name (custom or provider tool)
|
|
2127
|
+
* - SubpromptConfig: Sub-prompt used as a tool
|
|
2128
|
+
* - PromptToolConfig: Tool with tenv values and/or options
|
|
2129
|
+
*
|
|
1241
2130
|
* To enable handoffs, include ai_human agent names in this array.
|
|
2131
|
+
*
|
|
2132
|
+
* @example
|
|
2133
|
+
* ```typescript
|
|
2134
|
+
* tools: [
|
|
2135
|
+
* 'custom_tool', // Simple tool name
|
|
2136
|
+
* { name: 'other_prompt' }, // Sub-prompt as tool
|
|
2137
|
+
* { name: 'file_search', tenvs: { vectorStoreId: 'vs_123' } }, // Tool with tenvs
|
|
2138
|
+
* ]
|
|
2139
|
+
* ```
|
|
1242
2140
|
*/
|
|
1243
|
-
tools?: (
|
|
2141
|
+
tools?: (StandardAgentSpec.Callables | SubpromptConfig | PromptToolConfig)[];
|
|
2142
|
+
/**
|
|
2143
|
+
* Thread environment variables for this prompt.
|
|
2144
|
+
* These values are merged with agent and thread tenvs when creating a thread.
|
|
2145
|
+
* Prompt tenvs have lowest priority (overridden by agent and thread tenvs).
|
|
2146
|
+
*
|
|
2147
|
+
* @example
|
|
2148
|
+
* ```typescript
|
|
2149
|
+
* tenvs: {
|
|
2150
|
+
* vectorStoreId: 'vs_default_123',
|
|
2151
|
+
* apiEndpoint: 'https://api.example.com',
|
|
2152
|
+
* }
|
|
2153
|
+
* ```
|
|
2154
|
+
*/
|
|
2155
|
+
tenvs?: Record<string, unknown>;
|
|
1244
2156
|
/**
|
|
1245
2157
|
* Reasoning configuration for models that support extended thinking.
|
|
1246
2158
|
*/
|
|
@@ -1250,6 +2162,22 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
|
|
|
1250
2162
|
* @default 10
|
|
1251
2163
|
*/
|
|
1252
2164
|
recentImageThreshold?: number;
|
|
2165
|
+
/**
|
|
2166
|
+
* Provider-specific options passed through to the provider.
|
|
2167
|
+
* These override model-level providerOptions for this prompt.
|
|
2168
|
+
*
|
|
2169
|
+
* Options are merged in order (later wins):
|
|
2170
|
+
* 1. model.providerOptions (defaults)
|
|
2171
|
+
* 2. prompt.providerOptions (this field - overrides)
|
|
2172
|
+
*
|
|
2173
|
+
* @example
|
|
2174
|
+
* ```typescript
|
|
2175
|
+
* providerOptions: {
|
|
2176
|
+
* response_format: { type: 'json_object' },
|
|
2177
|
+
* }
|
|
2178
|
+
* ```
|
|
2179
|
+
*/
|
|
2180
|
+
providerOptions?: Record<string, unknown>;
|
|
1253
2181
|
}
|
|
1254
2182
|
/**
|
|
1255
2183
|
* Helper type to extract the inferred input type from a prompt's Zod schema.
|
|
@@ -1655,7 +2583,7 @@ type AgentType = 'ai_human' | 'dual_ai';
|
|
|
1655
2583
|
* };
|
|
1656
2584
|
* ```
|
|
1657
2585
|
*/
|
|
1658
|
-
interface SideConfig<Prompt extends string =
|
|
2586
|
+
interface SideConfig<Prompt extends string = StandardAgentSpec.Prompts, Callable extends string = StandardAgentSpec.Callables> {
|
|
1659
2587
|
/**
|
|
1660
2588
|
* Custom label for this side of the conversation.
|
|
1661
2589
|
* Used in UI and logs for clarity.
|
|
@@ -1722,7 +2650,7 @@ interface SideConfig<Prompt extends string = string, Callable extends string = s
|
|
|
1722
2650
|
* });
|
|
1723
2651
|
* ```
|
|
1724
2652
|
*/
|
|
1725
|
-
interface AgentDefinition<N extends string = string, Prompt extends string =
|
|
2653
|
+
interface AgentDefinition<N extends string = string, Prompt extends string = StandardAgentSpec.Prompts, Callable extends string = StandardAgentSpec.Callables> {
|
|
1726
2654
|
/**
|
|
1727
2655
|
* Unique name for this agent.
|
|
1728
2656
|
* Used as the identifier for thread creation and handoffs.
|
|
@@ -1789,6 +2717,24 @@ interface AgentDefinition<N extends string = string, Prompt extends string = str
|
|
|
1789
2717
|
* @example 'https://example.com/icon.svg' or '/icons/support.svg'
|
|
1790
2718
|
*/
|
|
1791
2719
|
icon?: string;
|
|
2720
|
+
/**
|
|
2721
|
+
* Thread environment variables for this agent.
|
|
2722
|
+
* These values are merged with prompt and thread tenvs when creating a thread.
|
|
2723
|
+
*
|
|
2724
|
+
* Merge priority (later wins):
|
|
2725
|
+
* 1. Prompt tenvs (lowest)
|
|
2726
|
+
* 2. Agent tenvs (this field)
|
|
2727
|
+
* 3. Thread tenvs (highest)
|
|
2728
|
+
*
|
|
2729
|
+
* @example
|
|
2730
|
+
* ```typescript
|
|
2731
|
+
* tenvs: {
|
|
2732
|
+
* vectorStoreId: 'vs_agent_default',
|
|
2733
|
+
* apiEndpoint: 'https://api.example.com',
|
|
2734
|
+
* }
|
|
2735
|
+
* ```
|
|
2736
|
+
*/
|
|
2737
|
+
tenvs?: Record<string, unknown>;
|
|
1792
2738
|
}
|
|
1793
2739
|
/**
|
|
1794
2740
|
* Defines an agent configuration.
|
|
@@ -2030,4 +2976,4 @@ declare function defineController(controller: Controller): Controller;
|
|
|
2030
2976
|
*/
|
|
2031
2977
|
declare function defineThreadEndpoint(handler: ThreadEndpointHandler): Controller;
|
|
2032
2978
|
|
|
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 };
|
|
2979
|
+
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 };
|