@standardagents/builder 0.10.1-next.bbd142a → 0.11.0-next.14455ae
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/LICENSE.txt +48 -0
- package/dist/built-in-routes.js +22190 -407
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +28 -19
- package/dist/client/vendor.js +1 -1
- package/dist/client/vue.js +1 -1
- package/dist/image-processing.d.ts +10 -6
- package/dist/image-processing.js +11 -138
- package/dist/image-processing.js.map +1 -1
- package/dist/index.d.ts +684 -832
- package/dist/index.js +7491 -4615
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +394 -131
- package/dist/plugin.js.map +1 -1
- package/dist/sip.wasm +0 -0
- package/package.json +24 -23
- package/dist/client/assets/img/meta.svg +0 -19
- package/dist/client/assets/img/moonshotai.svg +0 -4
- package/dist/client/assets/img/zai.svg +0 -219
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { AgentPluginOptions, agentbuilder } from './plugin.js';
|
|
2
2
|
import { DurableObjectStorage } from '@cloudflare/workers-types';
|
|
3
|
-
import {
|
|
3
|
+
import { ZodObject, ZodRawShape } from 'zod';
|
|
4
|
+
import { ToolResult as ToolResult$1, HookSignatures, AgentDefinition as AgentDefinition$1, ControllerContext, Controller, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$2, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart } from '@standardagents/spec';
|
|
5
|
+
export { AgentType, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ModelCapabilities as ProviderModelCapabilities, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, defineAgent, defineHook, defineModel, definePrompt, defineTool, mapReasoningLevel } from '@standardagents/spec';
|
|
4
6
|
import { DurableObject } from 'cloudflare:workers';
|
|
5
7
|
import 'vite';
|
|
6
8
|
|
|
@@ -144,122 +146,6 @@ declare class StreamManager {
|
|
|
144
146
|
forceClose(): void;
|
|
145
147
|
}
|
|
146
148
|
|
|
147
|
-
/**
|
|
148
|
-
* Content item types that can be returned by tools
|
|
149
|
-
*/
|
|
150
|
-
interface TextContent {
|
|
151
|
-
type: "text";
|
|
152
|
-
text: string;
|
|
153
|
-
}
|
|
154
|
-
interface ImageContent {
|
|
155
|
-
type: "image";
|
|
156
|
-
data: string;
|
|
157
|
-
mimeType: string;
|
|
158
|
-
}
|
|
159
|
-
type ToolContent = TextContent | ImageContent;
|
|
160
|
-
/** Decrement helper to stop recursion at depth 0 */
|
|
161
|
-
type Dec<N extends number> = N extends 10 ? 9 : N extends 9 ? 8 : N extends 8 ? 7 : N extends 7 ? 6 : N extends 6 ? 5 : N extends 5 ? 4 : N extends 4 ? 3 : N extends 3 ? 2 : N extends 2 ? 1 : N extends 1 ? 0 : 0;
|
|
162
|
-
/**
|
|
163
|
-
* Allowed Zod node for tool arguments.
|
|
164
|
-
* Tweak this union as your single source of truth for what’s allowed.
|
|
165
|
-
* Increase the default depth if you need crazier nesting.
|
|
166
|
-
*/
|
|
167
|
-
type ToolArgsNode<D extends number = 7> = ZodString | ZodNumber | ZodBoolean | ZodNull | ZodLiteral<string | number | boolean | null> | ZodEnum<Record<string, string>> | (D extends 0 ? never : ZodOptional<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodNullable<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodDefault<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodArray<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodObject<Record<string, ToolArgsNode<Dec<D>>>>) | (D extends 0 ? never : ZodRecord<ZodString, ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodUnion<[
|
|
168
|
-
ToolArgsNode<Dec<D>>,
|
|
169
|
-
ToolArgsNode<Dec<D>>,
|
|
170
|
-
...ToolArgsNode<Dec<D>>[]
|
|
171
|
-
]>);
|
|
172
|
-
/**
|
|
173
|
-
* Raw shape for an object whose values are ToolArgsNode.
|
|
174
|
-
* This is what users write inside z.object({ ... }).
|
|
175
|
-
*/
|
|
176
|
-
type ToolArgsRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
|
|
177
|
-
/** The top-level schema must be an object for OpenAI tools. */
|
|
178
|
-
type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
|
|
179
|
-
type StructuredToolReturn = ToolArgs;
|
|
180
|
-
/**
|
|
181
|
-
* Defines a tool function. Tools accept the current flow state as well as the arguments being passed to them.
|
|
182
|
-
*/
|
|
183
|
-
type Tool<Args extends ToolArgs | null = null> = Args extends ToolArgs ? (flow: FlowState, args: z.infer<Args>) => Promise<ToolResult> : (flow: FlowState) => Promise<ToolResult>;
|
|
184
|
-
/**
|
|
185
|
-
* @param toolDescription - Description of what the tool does.
|
|
186
|
-
* @param args - The arguments for the tool.
|
|
187
|
-
* @param tool - The tool function.
|
|
188
|
-
* @returns A tuple containing the description, arguments and the tool function.
|
|
189
|
-
*/
|
|
190
|
-
declare function defineTool<Args extends ToolArgs>(toolDescription: string, args: Args, tool: Tool<Args>): [string, Args, Tool<Args>, null];
|
|
191
|
-
declare function defineTool(toolDescription: string, tool: Tool<null>): [string, null, Tool<null>, null];
|
|
192
|
-
declare function defineTool<Args extends ToolArgs, RetValue extends StructuredToolReturn>(toolDescription: string, args: Args, tool: Tool<Args>, returnSchema: RetValue): [string, Args, Tool<Args>, RetValue];
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Hook signatures for all available hooks
|
|
196
|
-
*/
|
|
197
|
-
interface HookSignatures {
|
|
198
|
-
/**
|
|
199
|
-
* Called before messages are filtered and sent to the LLM
|
|
200
|
-
* Receives SQL row data with all columns before transformation
|
|
201
|
-
* Return value is transformed into chat completion format
|
|
202
|
-
*/
|
|
203
|
-
filter_messages: (state: FlowState, rows: Message[]) => Promise<Message[]>;
|
|
204
|
-
/**
|
|
205
|
-
* Called after message history is loaded and before sending to LLM
|
|
206
|
-
* Receives messages in chat completion format (already transformed)
|
|
207
|
-
*/
|
|
208
|
-
prefilter_llm_history: (state: FlowState, messages: Array<{
|
|
209
|
-
role: string;
|
|
210
|
-
content: string | null;
|
|
211
|
-
tool_calls?: any;
|
|
212
|
-
tool_call_id?: string;
|
|
213
|
-
name?: string;
|
|
214
|
-
}>) => Promise<Array<{
|
|
215
|
-
role: string;
|
|
216
|
-
content: string | null;
|
|
217
|
-
tool_calls?: any;
|
|
218
|
-
tool_call_id?: string;
|
|
219
|
-
name?: string;
|
|
220
|
-
}>>;
|
|
221
|
-
/**
|
|
222
|
-
* Called before a message is created in the database
|
|
223
|
-
*/
|
|
224
|
-
before_create_message: (state: FlowState, message: Record<string, any>) => Promise<Record<string, any>>;
|
|
225
|
-
/**
|
|
226
|
-
* Called after a message is created in the database
|
|
227
|
-
*/
|
|
228
|
-
after_create_message: (state: FlowState, message: Record<string, any>) => Promise<void>;
|
|
229
|
-
/**
|
|
230
|
-
* Called before a message is updated in the database
|
|
231
|
-
*/
|
|
232
|
-
before_update_message: (state: FlowState, messageId: string, updates: Record<string, any>) => Promise<Record<string, any>>;
|
|
233
|
-
/**
|
|
234
|
-
* Called after a message is updated in the database
|
|
235
|
-
*/
|
|
236
|
-
after_update_message: (state: FlowState, message: Message) => Promise<void>;
|
|
237
|
-
/**
|
|
238
|
-
* Called before a tool result is stored in the database
|
|
239
|
-
*/
|
|
240
|
-
before_store_tool_result: (state: FlowState, toolCall: Record<string, any>, toolResult: Record<string, any>) => Promise<Record<string, any>>;
|
|
241
|
-
/**
|
|
242
|
-
* Called after a successful tool call
|
|
243
|
-
*/
|
|
244
|
-
after_tool_call_success: (state: FlowState, toolCall: ToolCall, toolResult: ToolResult) => Promise<ToolResult | null>;
|
|
245
|
-
/**
|
|
246
|
-
* Called after a failed tool call
|
|
247
|
-
*/
|
|
248
|
-
after_tool_call_failure: (state: FlowState, toolCall: ToolCall, toolResult: ToolResult) => Promise<ToolResult | null>;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Define a hook with strict typing based on hook name
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```typescript
|
|
255
|
-
* export default defineHook('filter_messages', async (state, rows) => {
|
|
256
|
-
* // Only include messages from last 10 turns
|
|
257
|
-
* return rows.slice(-10);
|
|
258
|
-
* });
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
declare function defineHook<K extends keyof HookSignatures>(hookName: K, implementation: HookSignatures[K]): HookSignatures[K];
|
|
262
|
-
|
|
263
149
|
/**
|
|
264
150
|
* Agent configuration from D1 agents table
|
|
265
151
|
*/
|
|
@@ -274,15 +160,15 @@ interface Agent {
|
|
|
274
160
|
side_a_stop_on_response: boolean;
|
|
275
161
|
side_a_stop_tool: string | null;
|
|
276
162
|
side_a_stop_tool_response_property: string | null;
|
|
277
|
-
|
|
278
|
-
|
|
163
|
+
side_a_max_steps: number | null;
|
|
164
|
+
side_a_end_session_tool: string | null;
|
|
279
165
|
side_b_label: string | null;
|
|
280
166
|
side_b_agent_prompt: string | null;
|
|
281
167
|
side_b_stop_on_response: boolean;
|
|
282
168
|
side_b_stop_tool: string | null;
|
|
283
169
|
side_b_stop_tool_response_property: string | null;
|
|
284
|
-
|
|
285
|
-
|
|
170
|
+
side_b_max_steps: number | null;
|
|
171
|
+
side_b_end_session_tool: string | null;
|
|
286
172
|
}
|
|
287
173
|
/**
|
|
288
174
|
* Message in OpenAI chat completion format
|
|
@@ -327,6 +213,8 @@ interface ThreadMetadata {
|
|
|
327
213
|
id: string;
|
|
328
214
|
agent_id: string;
|
|
329
215
|
user_id: string | null;
|
|
216
|
+
tenvs: Record<string, unknown> | null;
|
|
217
|
+
properties: Record<string, unknown> | null;
|
|
330
218
|
created_at: number;
|
|
331
219
|
}
|
|
332
220
|
/**
|
|
@@ -335,6 +223,31 @@ interface ThreadMetadata {
|
|
|
335
223
|
type HookRegistry = {
|
|
336
224
|
[K in keyof HookSignatures]?: () => Promise<HookSignatures[K]>;
|
|
337
225
|
};
|
|
226
|
+
/**
|
|
227
|
+
* Native tool module type - represents a loaded tool definition.
|
|
228
|
+
* Tools can have args (with validation schema) or no args.
|
|
229
|
+
* Uses local Zod types for compatibility with z.toJSONSchema().
|
|
230
|
+
*/
|
|
231
|
+
interface NativeToolModule {
|
|
232
|
+
/** Description of what the tool does (shown to the LLM). */
|
|
233
|
+
description: string;
|
|
234
|
+
/** Zod schema for validating tool arguments, or null for no args. */
|
|
235
|
+
args: ZodObject<ZodRawShape> | null;
|
|
236
|
+
/** The tool implementation function. */
|
|
237
|
+
execute: ((state: any, args: Record<string, unknown>) => Promise<ToolResult$1>) | ((state: any) => Promise<ToolResult$1>);
|
|
238
|
+
/** Zod schema for thread environment variables, or null if none. */
|
|
239
|
+
tenvs?: ZodObject<ZodRawShape> | null;
|
|
240
|
+
/**
|
|
241
|
+
* Where this tool is executed:
|
|
242
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
243
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
244
|
+
*/
|
|
245
|
+
executionMode?: 'local' | 'provider';
|
|
246
|
+
/**
|
|
247
|
+
* Which provider executes this tool (when executionMode='provider').
|
|
248
|
+
*/
|
|
249
|
+
executionProvider?: string;
|
|
250
|
+
}
|
|
338
251
|
/**
|
|
339
252
|
* Thread instance (forward reference to avoid circular dependency)
|
|
340
253
|
*/
|
|
@@ -348,14 +261,48 @@ interface ThreadInstance {
|
|
|
348
261
|
}>;
|
|
349
262
|
getLogs(limit?: number, offset?: number, order?: "asc" | "desc"): Promise<LogData[]>;
|
|
350
263
|
getThreadMeta(threadId: string): Promise<ThreadMetadata | null>;
|
|
264
|
+
deleteMessage(messageId: string): Promise<{
|
|
265
|
+
success: boolean;
|
|
266
|
+
error?: string;
|
|
267
|
+
}>;
|
|
351
268
|
shouldStop(): Promise<boolean>;
|
|
352
|
-
tools(): Record<string, () => Promise<
|
|
269
|
+
tools(): Record<string, () => Promise<NativeToolModule>>;
|
|
353
270
|
hooks(): HookRegistry;
|
|
354
271
|
loadModel(name: string): Promise<any>;
|
|
355
272
|
loadPrompt(name: string): Promise<any>;
|
|
356
273
|
loadAgent(name: string): Promise<any>;
|
|
357
274
|
getPromptNames(): string[];
|
|
358
275
|
getAgentNames(): string[];
|
|
276
|
+
writeFile(path: string, data: ArrayBuffer | string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
|
|
277
|
+
readFile(path: string): Promise<{
|
|
278
|
+
success: boolean;
|
|
279
|
+
data?: string;
|
|
280
|
+
error?: string;
|
|
281
|
+
}>;
|
|
282
|
+
statFile(path: string): Promise<any>;
|
|
283
|
+
readdirFile(path: string): Promise<any[]>;
|
|
284
|
+
unlinkFile(path: string): Promise<void>;
|
|
285
|
+
mkdirFile(path: string): Promise<any>;
|
|
286
|
+
rmdirFile(path: string): Promise<void>;
|
|
287
|
+
getFileStats(): Promise<any>;
|
|
288
|
+
grepFiles(pattern: string): Promise<any[]>;
|
|
289
|
+
findFiles(pattern: string): Promise<any>;
|
|
290
|
+
getFileThumbnail(path: string): Promise<ArrayBuffer | null>;
|
|
291
|
+
readFileChunk(path: string, chunkIndex: number): Promise<{
|
|
292
|
+
success: boolean;
|
|
293
|
+
data?: string;
|
|
294
|
+
error?: string;
|
|
295
|
+
}>;
|
|
296
|
+
runAgent(threadId: string, agentName: string): Promise<void>;
|
|
297
|
+
scheduleEffect(threadId: string, effectName: string, effectArgs: Record<string, unknown>, delayMs?: number): Promise<string>;
|
|
298
|
+
getScheduledEffects(name?: string): Promise<Array<{
|
|
299
|
+
id: string;
|
|
300
|
+
name: string;
|
|
301
|
+
args: Record<string, unknown>;
|
|
302
|
+
scheduledAt: number;
|
|
303
|
+
createdAt: number;
|
|
304
|
+
}>>;
|
|
305
|
+
removeScheduledEffect(id: string): Promise<boolean>;
|
|
359
306
|
insertOrphanedToolCall(params: {
|
|
360
307
|
content?: string;
|
|
361
308
|
toolCallId: string;
|
|
@@ -389,11 +336,12 @@ type FlowCallWithRetries = FlowCall & {
|
|
|
389
336
|
reasons: string[];
|
|
390
337
|
};
|
|
391
338
|
/**
|
|
392
|
-
*
|
|
339
|
+
* Sub-prompt configuration - defines options for when a sub-prompt is called as a tool
|
|
393
340
|
*/
|
|
394
|
-
interface
|
|
341
|
+
interface SubpromptConfig$1 {
|
|
395
342
|
name: string;
|
|
396
343
|
initUserMessageProperty?: string;
|
|
344
|
+
initAttachmentsProperty?: string;
|
|
397
345
|
includeTextResponse?: boolean;
|
|
398
346
|
includeToolCalls?: boolean;
|
|
399
347
|
includeErrors?: boolean;
|
|
@@ -412,8 +360,6 @@ interface PromptData {
|
|
|
412
360
|
required_schema: string;
|
|
413
361
|
include_chat: boolean;
|
|
414
362
|
include_past_tools: boolean;
|
|
415
|
-
before_tool: string | null;
|
|
416
|
-
after_tool: string | null;
|
|
417
363
|
prompts: string;
|
|
418
364
|
created_at: number;
|
|
419
365
|
/** @deprecated All prompts are now automatically exposed as tools */
|
|
@@ -424,10 +370,8 @@ interface PromptData {
|
|
|
424
370
|
reasoning_max_tokens: number | null;
|
|
425
371
|
reasoning_exclude: boolean;
|
|
426
372
|
include_reasoning: boolean;
|
|
427
|
-
maxImagePixels: number | null;
|
|
428
373
|
recentImageThreshold: number | null;
|
|
429
|
-
_tools?: (string |
|
|
430
|
-
_handoffAgents?: string[];
|
|
374
|
+
_tools?: (string | SubpromptConfig$1)[];
|
|
431
375
|
_requiredSchema?: any;
|
|
432
376
|
}
|
|
433
377
|
/**
|
|
@@ -447,9 +391,9 @@ interface FlowState {
|
|
|
447
391
|
sideB: PromptData | null;
|
|
448
392
|
};
|
|
449
393
|
prompt: PromptData;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
394
|
+
stepCount: number;
|
|
395
|
+
sideAStepCount: number;
|
|
396
|
+
sideBStepCount: number;
|
|
453
397
|
stopped: boolean;
|
|
454
398
|
stoppedBy?: "a" | "b";
|
|
455
399
|
forcedNextSide?: "side_a" | "side_b";
|
|
@@ -488,6 +432,7 @@ interface FlowState {
|
|
|
488
432
|
depth: number;
|
|
489
433
|
pendingMessageId?: string;
|
|
490
434
|
allowedTools?: ToolDefinition[];
|
|
435
|
+
pendingMetadataPromises?: Promise<void>[];
|
|
491
436
|
}
|
|
492
437
|
/**
|
|
493
438
|
* Text content part for multimodal messages
|
|
@@ -524,6 +469,10 @@ interface RequestContext {
|
|
|
524
469
|
tool_calls?: ToolCall[];
|
|
525
470
|
tool_call_id?: string;
|
|
526
471
|
name?: string;
|
|
472
|
+
reasoning_content?: string;
|
|
473
|
+
reasoning_details?: any[];
|
|
474
|
+
attachments?: any[];
|
|
475
|
+
toolName?: string;
|
|
527
476
|
}>;
|
|
528
477
|
model: string;
|
|
529
478
|
tools?: ToolDefinition[];
|
|
@@ -555,6 +504,33 @@ interface ToolDefinition {
|
|
|
555
504
|
description: string;
|
|
556
505
|
parameters?: Record<string, any>;
|
|
557
506
|
};
|
|
507
|
+
/**
|
|
508
|
+
* Where this tool is executed:
|
|
509
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
510
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
511
|
+
*/
|
|
512
|
+
executionMode?: 'local' | 'provider';
|
|
513
|
+
/**
|
|
514
|
+
* Which provider executes this tool (when executionMode='provider')
|
|
515
|
+
* e.g., 'openai', 'anthropic'
|
|
516
|
+
*/
|
|
517
|
+
executionProvider?: string;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Image returned by an LLM response (e.g., from image generation models)
|
|
521
|
+
* Format follows OpenAI/OpenRouter chat completions API
|
|
522
|
+
*/
|
|
523
|
+
interface LLMResponseImage {
|
|
524
|
+
type: "image_url";
|
|
525
|
+
/** Unique ID for this generated image (used to link to tool call) */
|
|
526
|
+
id?: string;
|
|
527
|
+
/** Name of the tool that generated this image (e.g., 'image_generation') */
|
|
528
|
+
toolName?: string;
|
|
529
|
+
/** The revised/actual prompt used to generate the image (from OpenAI's image_generation) */
|
|
530
|
+
revisedPrompt?: string;
|
|
531
|
+
image_url: {
|
|
532
|
+
url: string;
|
|
533
|
+
};
|
|
558
534
|
}
|
|
559
535
|
/**
|
|
560
536
|
* LLM response
|
|
@@ -566,6 +542,7 @@ interface LLMResponse {
|
|
|
566
542
|
reasoning_content?: string | null;
|
|
567
543
|
reasoning_details?: any[];
|
|
568
544
|
tool_calls?: ToolCall[];
|
|
545
|
+
images?: LLMResponseImage[];
|
|
569
546
|
finish_reason: string;
|
|
570
547
|
usage: {
|
|
571
548
|
prompt_tokens: number;
|
|
@@ -580,6 +557,23 @@ interface LLMResponse {
|
|
|
580
557
|
cost?: number;
|
|
581
558
|
provider?: string;
|
|
582
559
|
};
|
|
560
|
+
/** @internal Provider instance reference for async metadata fetching */
|
|
561
|
+
_provider?: unknown;
|
|
562
|
+
/** @internal Provider response ID for async metadata fetching */
|
|
563
|
+
_providerResponseId?: string;
|
|
564
|
+
/** @internal Aggregate response for logging */
|
|
565
|
+
_aggregate_response?: unknown;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Attachment returned by a tool (e.g., generated images)
|
|
569
|
+
* Stored in thread filesystem and linked to the tool message
|
|
570
|
+
*/
|
|
571
|
+
interface ToolAttachment {
|
|
572
|
+
name: string;
|
|
573
|
+
mimeType: string;
|
|
574
|
+
data: string;
|
|
575
|
+
width?: number;
|
|
576
|
+
height?: number;
|
|
583
577
|
}
|
|
584
578
|
/**
|
|
585
579
|
* Tool result
|
|
@@ -597,6 +591,16 @@ interface ToolResult {
|
|
|
597
591
|
result?: string;
|
|
598
592
|
error?: string;
|
|
599
593
|
stack?: string;
|
|
594
|
+
/**
|
|
595
|
+
* File attachments returned by the tool.
|
|
596
|
+
*
|
|
597
|
+
* Can contain either:
|
|
598
|
+
* - ToolAttachment: New files with base64 data to be stored
|
|
599
|
+
* - AttachmentRef: References to existing files in the thread filesystem
|
|
600
|
+
*
|
|
601
|
+
* New attachments are stored under /attachments/ directory.
|
|
602
|
+
*/
|
|
603
|
+
attachments?: Array<ToolAttachment | AttachmentRef>;
|
|
600
604
|
}
|
|
601
605
|
/**
|
|
602
606
|
* Flow execution result
|
|
@@ -605,20 +609,20 @@ interface FlowResult {
|
|
|
605
609
|
messages: Message[];
|
|
606
610
|
stopped: boolean;
|
|
607
611
|
stoppedBy?: "a" | "b";
|
|
608
|
-
|
|
612
|
+
stepCount: number;
|
|
609
613
|
stream: ReadableStream<Uint8Array>;
|
|
610
614
|
}
|
|
611
615
|
/**
|
|
612
616
|
* Telemetry event types
|
|
613
617
|
*/
|
|
614
618
|
type TelemetryEvent = {
|
|
615
|
-
type: "
|
|
616
|
-
|
|
619
|
+
type: "step_started";
|
|
620
|
+
step: number;
|
|
617
621
|
side: "a" | "b";
|
|
618
622
|
timestamp: number;
|
|
619
623
|
} | {
|
|
620
|
-
type: "
|
|
621
|
-
|
|
624
|
+
type: "step_completed";
|
|
625
|
+
step: number;
|
|
622
626
|
stopped: boolean;
|
|
623
627
|
timestamp: number;
|
|
624
628
|
} | {
|
|
@@ -691,6 +695,7 @@ interface LogData {
|
|
|
691
695
|
tools_available?: number;
|
|
692
696
|
prompt_name?: string;
|
|
693
697
|
tools_called?: string;
|
|
698
|
+
actual_provider?: string | null;
|
|
694
699
|
parent_log_id?: string | null;
|
|
695
700
|
tools_schema?: string | null;
|
|
696
701
|
message_history?: string | null;
|
|
@@ -739,6 +744,10 @@ interface FileRecord {
|
|
|
739
744
|
metadata?: Record<string, unknown> | null;
|
|
740
745
|
isDirectory: boolean;
|
|
741
746
|
createdAt: number;
|
|
747
|
+
width?: number | null;
|
|
748
|
+
height?: number | null;
|
|
749
|
+
isChunked?: boolean;
|
|
750
|
+
chunkCount?: number;
|
|
742
751
|
}
|
|
743
752
|
/**
|
|
744
753
|
* Image-specific metadata stored in FileRecord.metadata
|
|
@@ -777,43 +786,218 @@ interface FileStats {
|
|
|
777
786
|
fileCount: number;
|
|
778
787
|
}
|
|
779
788
|
|
|
789
|
+
/**
|
|
790
|
+
* Router and endpoint definition module for AgentBuilder.
|
|
791
|
+
*
|
|
792
|
+
* This module re-exports endpoint types from @standardagents/spec and provides
|
|
793
|
+
* the runtime router implementation for handling HTTP requests.
|
|
794
|
+
*
|
|
795
|
+
* @module
|
|
796
|
+
*/
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Durable Object namespace interface.
|
|
800
|
+
* This is Cloudflare-specific and used by the builder runtime.
|
|
801
|
+
*/
|
|
802
|
+
interface DurableObjectNamespace$1<T = unknown> {
|
|
803
|
+
idFromName(name: string): DurableObjectId;
|
|
804
|
+
idFromString(id: string): DurableObjectId;
|
|
805
|
+
newUniqueId(): DurableObjectId;
|
|
806
|
+
get(id: DurableObjectId): DurableObjectStub$1<T>;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Durable Object ID interface.
|
|
810
|
+
*/
|
|
811
|
+
interface DurableObjectId {
|
|
812
|
+
toString(): string;
|
|
813
|
+
equals(other: DurableObjectId): boolean;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Durable Object stub interface.
|
|
817
|
+
* The generic type T represents the RPC methods available on the stub.
|
|
818
|
+
*/
|
|
819
|
+
type DurableObjectStub$1<T = unknown> = {
|
|
820
|
+
id: DurableObjectId;
|
|
821
|
+
name?: string;
|
|
822
|
+
fetch(request: Request | string, requestInitr?: RequestInit): Promise<Response>;
|
|
823
|
+
} & T;
|
|
824
|
+
/**
|
|
825
|
+
* Log entry from DurableThread.getLogs()
|
|
826
|
+
*/
|
|
827
|
+
interface LogEntry {
|
|
828
|
+
id: string;
|
|
829
|
+
message_id: string;
|
|
830
|
+
provider: string;
|
|
831
|
+
model: string;
|
|
832
|
+
model_name: string | null;
|
|
833
|
+
prompt_name: string | null;
|
|
834
|
+
tools_called: string | null;
|
|
835
|
+
parent_log_id: string | null;
|
|
836
|
+
retry_of_log_id: string | null;
|
|
837
|
+
error: string | null;
|
|
838
|
+
cost_total: number | null;
|
|
839
|
+
is_complete: number;
|
|
840
|
+
created_at: number;
|
|
841
|
+
request_body: string | null;
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Response from getThreadMeta()
|
|
845
|
+
*/
|
|
846
|
+
interface ThreadMetaResponse {
|
|
847
|
+
thread: ThreadRegistryEntry$1;
|
|
848
|
+
agent: AgentDefinition$1 | null;
|
|
849
|
+
stats: {
|
|
850
|
+
messageCount: number;
|
|
851
|
+
logCount: number;
|
|
852
|
+
lastActivity: number | null;
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Log details returned by getLogDetails
|
|
857
|
+
*/
|
|
858
|
+
interface LogDetails {
|
|
859
|
+
id: string;
|
|
860
|
+
message_id: string;
|
|
861
|
+
provider: string;
|
|
862
|
+
actual_provider: string | null;
|
|
863
|
+
model: string;
|
|
864
|
+
model_name: string | null;
|
|
865
|
+
endpoint: string | null;
|
|
866
|
+
request_body: string | null;
|
|
867
|
+
request_headers: string | null;
|
|
868
|
+
response_body: string | null;
|
|
869
|
+
response_headers: string | null;
|
|
870
|
+
status_code: number | null;
|
|
871
|
+
reasoning_content: string | null;
|
|
872
|
+
input_tokens: number | null;
|
|
873
|
+
cached_tokens: number | null;
|
|
874
|
+
output_tokens: number | null;
|
|
875
|
+
reasoning_tokens: number | null;
|
|
876
|
+
total_tokens: number | null;
|
|
877
|
+
latency_ms: number | null;
|
|
878
|
+
time_to_first_token_ms: number | null;
|
|
879
|
+
finish_reason: string | null;
|
|
880
|
+
error: string | null;
|
|
881
|
+
error_type: string | null;
|
|
882
|
+
cost_input: number | null;
|
|
883
|
+
cost_output: number | null;
|
|
884
|
+
cost_total: number | null;
|
|
885
|
+
message_history_length: number | null;
|
|
886
|
+
tools_available: number | null;
|
|
887
|
+
prompt_name: string | null;
|
|
888
|
+
tools_called: string | null;
|
|
889
|
+
provider_tools: string | null;
|
|
890
|
+
parent_log_id: string | null;
|
|
891
|
+
tools_schema: string | null;
|
|
892
|
+
system_prompt: string | null;
|
|
893
|
+
errors: string | null;
|
|
894
|
+
retry_of_log_id: string | null;
|
|
895
|
+
tool_results: string | null;
|
|
896
|
+
is_complete: number;
|
|
897
|
+
created_at: number;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* RPC methods exposed by DurableThread for external callers.
|
|
901
|
+
*/
|
|
902
|
+
interface DurableThreadRpc {
|
|
903
|
+
stop(): Promise<Response>;
|
|
904
|
+
getMessages(limit?: number, offset?: number, order?: "ASC" | "DESC", includeSilent?: boolean, maxDepth?: number): Promise<{
|
|
905
|
+
messages: unknown[];
|
|
906
|
+
total: number;
|
|
907
|
+
hasMore: boolean;
|
|
908
|
+
}>;
|
|
909
|
+
deleteMessage(messageId: string): Promise<{
|
|
910
|
+
success: boolean;
|
|
911
|
+
error?: string;
|
|
912
|
+
}>;
|
|
913
|
+
updateMessageContent(messageId: string, content: string): Promise<{
|
|
914
|
+
success: boolean;
|
|
915
|
+
error?: string;
|
|
916
|
+
}>;
|
|
917
|
+
getLogs(limit?: number, offset?: number, order?: "ASC" | "DESC"): Promise<{
|
|
918
|
+
logs: LogEntry[];
|
|
919
|
+
total: number;
|
|
920
|
+
hasMore: boolean;
|
|
921
|
+
}>;
|
|
922
|
+
getLogDetails(logId: string): Promise<LogDetails | null>;
|
|
923
|
+
getThreadMeta(threadId: string): Promise<ThreadMetaResponse | null>;
|
|
924
|
+
deleteThread(): Promise<void>;
|
|
925
|
+
readFile(path: string): Promise<{
|
|
926
|
+
success: boolean;
|
|
927
|
+
data?: string;
|
|
928
|
+
error?: string;
|
|
929
|
+
}>;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Thread registry entry from DurableAgentBuilder.
|
|
933
|
+
*/
|
|
934
|
+
interface ThreadRegistryEntry$1 {
|
|
935
|
+
id: string;
|
|
936
|
+
agent_name: string;
|
|
937
|
+
user_id: string | null;
|
|
938
|
+
tags: string[] | null;
|
|
939
|
+
created_at: number;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* RPC methods exposed by DurableAgentBuilder for external callers.
|
|
943
|
+
*/
|
|
944
|
+
interface DurableAgentBuilderRpc {
|
|
945
|
+
createThread(params: {
|
|
946
|
+
agent_name: string;
|
|
947
|
+
user_id?: string;
|
|
948
|
+
tags?: string[];
|
|
949
|
+
tenvs?: Record<string, unknown>;
|
|
950
|
+
properties?: Record<string, unknown>;
|
|
951
|
+
}): Promise<ThreadRegistryEntry$1>;
|
|
952
|
+
getThread(threadId: string): Promise<ThreadRegistryEntry$1 | null>;
|
|
953
|
+
listThreads(params?: {
|
|
954
|
+
agent_name?: string;
|
|
955
|
+
user_id?: string;
|
|
956
|
+
search?: string;
|
|
957
|
+
startDate?: number;
|
|
958
|
+
endDate?: number;
|
|
959
|
+
limit?: number;
|
|
960
|
+
offset?: number;
|
|
961
|
+
}): Promise<{
|
|
962
|
+
threads: ThreadRegistryEntry$1[];
|
|
963
|
+
total: number;
|
|
964
|
+
}>;
|
|
965
|
+
deleteThread(threadId: string): Promise<void>;
|
|
966
|
+
getUserByUsername(username: string): Promise<unknown>;
|
|
967
|
+
createSession(session: {
|
|
968
|
+
user_id: string;
|
|
969
|
+
token_hash: string;
|
|
970
|
+
expires_at: number;
|
|
971
|
+
}): Promise<void>;
|
|
972
|
+
loadAgent(name: string): Promise<AgentDefinition$1>;
|
|
973
|
+
}
|
|
780
974
|
/**
|
|
781
975
|
* Minimum required environment bindings for thread endpoints.
|
|
782
976
|
* User's Env interface should extend this.
|
|
783
977
|
*
|
|
784
|
-
*
|
|
785
|
-
* Durable Object types that extend DurableThread/DurableAgentBuilder.
|
|
978
|
+
* This is Cloudflare-specific and used by the builder runtime.
|
|
786
979
|
*/
|
|
787
980
|
interface ThreadEnv {
|
|
788
|
-
AGENT_BUILDER_THREAD: DurableObjectNamespace<
|
|
789
|
-
AGENT_BUILDER: DurableObjectNamespace<
|
|
981
|
+
AGENT_BUILDER_THREAD: DurableObjectNamespace$1<DurableThreadRpc>;
|
|
982
|
+
AGENT_BUILDER: DurableObjectNamespace$1<DurableAgentBuilderRpc>;
|
|
790
983
|
[key: string]: unknown;
|
|
791
984
|
}
|
|
792
985
|
/**
|
|
793
|
-
*
|
|
986
|
+
* Builder-specific controller context with typed env.
|
|
987
|
+
*
|
|
988
|
+
* This extends the spec's ControllerContext with proper typing for
|
|
989
|
+
* Cloudflare environment bindings.
|
|
794
990
|
*/
|
|
795
|
-
|
|
796
|
-
|
|
991
|
+
interface BuilderControllerContext<Env extends ThreadEnv = ThreadEnv> extends Omit<ControllerContext, 'env'> {
|
|
992
|
+
env: Env;
|
|
993
|
+
}
|
|
797
994
|
/**
|
|
798
|
-
*
|
|
799
|
-
|
|
995
|
+
* Builder-specific controller type with typed env.
|
|
996
|
+
*/
|
|
997
|
+
type BuilderController<Env extends ThreadEnv = ThreadEnv> = (context: BuilderControllerContext<Env>) => ReturnType<Controller>;
|
|
998
|
+
/**
|
|
999
|
+
* Thread endpoint context with access to thread instance and metadata.
|
|
800
1000
|
*/
|
|
801
|
-
interface ControllerContext<Env = any> {
|
|
802
|
-
req: Request;
|
|
803
|
-
params: Record<string, string>;
|
|
804
|
-
env: Env;
|
|
805
|
-
url: URL;
|
|
806
|
-
agents?: VirtualModuleRegistry<unknown>;
|
|
807
|
-
agentNames?: string[];
|
|
808
|
-
prompts?: VirtualModuleRegistry<unknown>;
|
|
809
|
-
promptNames?: string[];
|
|
810
|
-
models?: VirtualModuleRegistry<unknown>;
|
|
811
|
-
modelNames?: string[];
|
|
812
|
-
tools?: VirtualModuleRegistry<unknown>;
|
|
813
|
-
hooks?: VirtualModuleRegistry<unknown>;
|
|
814
|
-
config?: Record<string, unknown>;
|
|
815
|
-
}
|
|
816
|
-
type Controller<Env = any> = (context: ControllerContext<Env>) => string | Promise<string> | Response | Promise<Response> | ReadableStream | Promise<ReadableStream> | null | Promise<null> | void | Promise<void> | Promise<object> | object;
|
|
817
1001
|
interface ThreadEndpointContext {
|
|
818
1002
|
req: Request;
|
|
819
1003
|
thread: {
|
|
@@ -821,22 +1005,67 @@ interface ThreadEndpointContext {
|
|
|
821
1005
|
metadata: ThreadMetadata;
|
|
822
1006
|
};
|
|
823
1007
|
}
|
|
824
|
-
declare function defineController<Env = any>(controller: Controller<Env>): Controller<Env>;
|
|
825
1008
|
/**
|
|
826
|
-
*
|
|
827
|
-
*
|
|
1009
|
+
* Handler function for builder thread endpoints.
|
|
1010
|
+
*
|
|
1011
|
+
* Unlike the spec's ThreadEndpointHandler which receives ThreadState,
|
|
1012
|
+
* the builder's handler receives direct access to the Durable Object
|
|
1013
|
+
* instance and thread metadata. This allows for lower-level operations
|
|
1014
|
+
* like calling RPC methods directly on the instance.
|
|
1015
|
+
*/
|
|
1016
|
+
type BuilderThreadEndpointHandler = (req: Request, context: {
|
|
1017
|
+
instance: ThreadInstance;
|
|
1018
|
+
metadata: ThreadMetadata;
|
|
1019
|
+
}) => Response | Promise<Response>;
|
|
1020
|
+
/**
|
|
1021
|
+
* Define a thread-specific endpoint with access to the Durable Object instance.
|
|
1022
|
+
*
|
|
1023
|
+
* This is the builder's version of defineThreadEndpoint. It provides direct
|
|
1024
|
+
* access to the thread's Durable Object instance and metadata, allowing
|
|
1025
|
+
* for lower-level operations like calling RPC methods directly.
|
|
828
1026
|
*
|
|
829
1027
|
* @param handler - Function that receives the request and thread context
|
|
830
1028
|
* @returns A Controller that can be used with the router
|
|
831
1029
|
*
|
|
832
1030
|
* @example
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
1031
|
+
* ```typescript
|
|
1032
|
+
* import { defineThreadEndpoint } from '@standardagents/builder';
|
|
1033
|
+
*
|
|
1034
|
+
* export default defineThreadEndpoint(async (req, { instance, metadata }) => {
|
|
1035
|
+
* // Access thread metadata
|
|
1036
|
+
* console.log('Thread ID:', metadata.id);
|
|
1037
|
+
* console.log('Agent ID:', metadata.agent_id);
|
|
1038
|
+
*
|
|
1039
|
+
* // Call RPC methods on the Durable Object instance
|
|
1040
|
+
* const messagesResult = await instance.getMessages();
|
|
1041
|
+
* const logs = await instance.getLogs();
|
|
1042
|
+
*
|
|
1043
|
+
* return Response.json({
|
|
1044
|
+
* messageCount: messagesResult.messages.length,
|
|
1045
|
+
* logCount: logs.length,
|
|
1046
|
+
* });
|
|
837
1047
|
* });
|
|
1048
|
+
* ```
|
|
838
1049
|
*/
|
|
839
|
-
declare function defineThreadEndpoint
|
|
1050
|
+
declare function defineThreadEndpoint(handler: BuilderThreadEndpointHandler): BuilderController;
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Define a controller with typed Cloudflare environment bindings.
|
|
1054
|
+
*
|
|
1055
|
+
* This is the builder's version of defineController that provides
|
|
1056
|
+
* proper typing for AGENT_BUILDER_THREAD and other CF bindings.
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```typescript
|
|
1060
|
+
* import { defineController } from '../router/index.js';
|
|
1061
|
+
*
|
|
1062
|
+
* export default defineController(async ({ req, env }) => {
|
|
1063
|
+
* const stub = env.AGENT_BUILDER.get(env.AGENT_BUILDER.idFromName('singleton'));
|
|
1064
|
+
* // ...
|
|
1065
|
+
* });
|
|
1066
|
+
* ```
|
|
1067
|
+
*/
|
|
1068
|
+
declare function defineController<Env extends ThreadEnv = ThreadEnv>(controller: BuilderController<Env>): BuilderController<Env>;
|
|
840
1069
|
|
|
841
1070
|
/**
|
|
842
1071
|
* Authentication middleware for protecting API routes
|
|
@@ -932,6 +1161,17 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
932
1161
|
* @returns Record of agent name to agent loader function
|
|
933
1162
|
*/
|
|
934
1163
|
agents(): Record<string, () => Promise<any>>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Returns the effects registry for lazy-loading effect definitions.
|
|
1166
|
+
* This method is implemented when you import DurableThread from 'virtual:@standardagents/builder'.
|
|
1167
|
+
*
|
|
1168
|
+
* Effects are scheduled operations that run outside the tool execution context,
|
|
1169
|
+
* ideal for delayed notifications, webhooks, and cleanup tasks.
|
|
1170
|
+
*
|
|
1171
|
+
* @throws Error if not implemented in a subclass
|
|
1172
|
+
* @returns Record of effect name to effect loader function
|
|
1173
|
+
*/
|
|
1174
|
+
effects(): Record<string, () => Promise<any>>;
|
|
935
1175
|
/**
|
|
936
1176
|
* Load a model definition by name.
|
|
937
1177
|
*/
|
|
@@ -956,6 +1196,59 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
956
1196
|
* List available agent names.
|
|
957
1197
|
*/
|
|
958
1198
|
getAgentNames(): string[];
|
|
1199
|
+
/**
|
|
1200
|
+
* Load an effect definition by name.
|
|
1201
|
+
*/
|
|
1202
|
+
loadEffect(name: string): Promise<any>;
|
|
1203
|
+
/**
|
|
1204
|
+
* List available effect names.
|
|
1205
|
+
*/
|
|
1206
|
+
getEffectNames(): string[];
|
|
1207
|
+
/**
|
|
1208
|
+
* Get thread metadata from DurableAgentBuilder.
|
|
1209
|
+
* Used for creating ThreadState outside of flow execution.
|
|
1210
|
+
*/
|
|
1211
|
+
getThreadMetadata(threadId: string): Promise<ThreadMetadata>;
|
|
1212
|
+
/**
|
|
1213
|
+
* Trigger an agent to run on this thread.
|
|
1214
|
+
*
|
|
1215
|
+
* Queues an agent execution via the alarm queue. The execution
|
|
1216
|
+
* runs asynchronously in the background.
|
|
1217
|
+
*
|
|
1218
|
+
* @param threadId - Thread ID for the execution
|
|
1219
|
+
* @param agentName - Name of the agent to run
|
|
1220
|
+
*/
|
|
1221
|
+
runAgent(threadId: string, agentName: string): Promise<void>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Schedule an effect for future execution.
|
|
1224
|
+
*
|
|
1225
|
+
* @param threadId - Thread ID for the effect execution context
|
|
1226
|
+
* @param effectName - Name of the effect to schedule
|
|
1227
|
+
* @param effectArgs - Arguments to pass to the effect handler
|
|
1228
|
+
* @param delayMs - Delay in milliseconds before execution (default: 0)
|
|
1229
|
+
* @returns UUID of the scheduled effect
|
|
1230
|
+
*/
|
|
1231
|
+
scheduleEffect(threadId: string, effectName: string, effectArgs: Record<string, unknown>, delayMs?: number): Promise<string>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Get scheduled effects for this thread.
|
|
1234
|
+
*
|
|
1235
|
+
* @param name - Optional effect name to filter by
|
|
1236
|
+
* @returns Array of scheduled effect records
|
|
1237
|
+
*/
|
|
1238
|
+
getScheduledEffects(name?: string): Promise<Array<{
|
|
1239
|
+
id: string;
|
|
1240
|
+
name: string;
|
|
1241
|
+
args: Record<string, unknown>;
|
|
1242
|
+
scheduledAt: number;
|
|
1243
|
+
createdAt: number;
|
|
1244
|
+
}>>;
|
|
1245
|
+
/**
|
|
1246
|
+
* Remove a scheduled effect.
|
|
1247
|
+
*
|
|
1248
|
+
* @param id - The effect ID returned by scheduleEffect
|
|
1249
|
+
* @returns true if the effect was found and removed, false otherwise
|
|
1250
|
+
*/
|
|
1251
|
+
removeScheduledEffect(id: string): Promise<boolean>;
|
|
959
1252
|
/**
|
|
960
1253
|
* Ensures the database schema is up to date.
|
|
961
1254
|
* This method is called on the first request to the Durable Object.
|
|
@@ -1001,6 +1294,15 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1001
1294
|
* Simple "off" switch - stops turns, only cleared by user messages
|
|
1002
1295
|
*/
|
|
1003
1296
|
stop(): Promise<Response>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Continue execution from where it stopped (RPC method)
|
|
1299
|
+
* Useful for debugging - continues the FlowEngine with additional steps
|
|
1300
|
+
* without adding a new message.
|
|
1301
|
+
*
|
|
1302
|
+
* @param threadId The thread ID
|
|
1303
|
+
* @param side Which side to start from ('a' or 'b'), defaults to 'a'
|
|
1304
|
+
*/
|
|
1305
|
+
continueExecution(threadId: string, side?: 'a' | 'b'): Promise<Response>;
|
|
1004
1306
|
/**
|
|
1005
1307
|
* Get message history (RPC method)
|
|
1006
1308
|
*
|
|
@@ -1044,6 +1346,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1044
1346
|
}>;
|
|
1045
1347
|
/**
|
|
1046
1348
|
* Delete a message (RPC method)
|
|
1349
|
+
* Also cleans up any attachment files stored on the thread filesystem
|
|
1047
1350
|
*/
|
|
1048
1351
|
deleteMessage(messageId: string): Promise<{
|
|
1049
1352
|
success: boolean;
|
|
@@ -1112,10 +1415,12 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1112
1415
|
id: string;
|
|
1113
1416
|
message_id: string;
|
|
1114
1417
|
provider: string;
|
|
1418
|
+
actual_provider: string | null;
|
|
1115
1419
|
model: string;
|
|
1116
1420
|
model_name: string | null;
|
|
1117
1421
|
prompt_name: string | null;
|
|
1118
1422
|
tools_called: string | null;
|
|
1423
|
+
provider_tools: string | null;
|
|
1119
1424
|
parent_log_id: string | null;
|
|
1120
1425
|
retry_of_log_id: string | null;
|
|
1121
1426
|
error: string | null;
|
|
@@ -1135,6 +1440,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1135
1440
|
id: string;
|
|
1136
1441
|
message_id: string;
|
|
1137
1442
|
provider: string;
|
|
1443
|
+
actual_provider: string | null;
|
|
1138
1444
|
model: string;
|
|
1139
1445
|
model_name: string | null;
|
|
1140
1446
|
endpoint: string | null;
|
|
@@ -1161,6 +1467,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1161
1467
|
tools_available: number | null;
|
|
1162
1468
|
prompt_name: string | null;
|
|
1163
1469
|
tools_called: string | null;
|
|
1470
|
+
provider_tools: string | null;
|
|
1164
1471
|
parent_log_id: string | null;
|
|
1165
1472
|
tools_schema: string | null;
|
|
1166
1473
|
message_history: string | null;
|
|
@@ -1186,6 +1493,8 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1186
1493
|
id: any;
|
|
1187
1494
|
title: any;
|
|
1188
1495
|
type: any;
|
|
1496
|
+
description: any;
|
|
1497
|
+
icon: any;
|
|
1189
1498
|
side_a_label: any;
|
|
1190
1499
|
side_b_label: any;
|
|
1191
1500
|
} | null;
|
|
@@ -1251,7 +1560,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1251
1560
|
private broadcastMessageChunk;
|
|
1252
1561
|
/**
|
|
1253
1562
|
* Broadcast a telemetry event to all connected message WebSocket clients
|
|
1254
|
-
* Used for execution status updates (
|
|
1563
|
+
* Used for execution status updates (step_started, tool_started, etc.)
|
|
1255
1564
|
*/
|
|
1256
1565
|
private broadcastTelemetry;
|
|
1257
1566
|
/**
|
|
@@ -1267,8 +1576,9 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1267
1576
|
/**
|
|
1268
1577
|
* WebSocket Hibernation API handler for connection close
|
|
1269
1578
|
* Called when a WebSocket connection is closed
|
|
1579
|
+
* Note: Do NOT call ws.close() here - the connection is already closed
|
|
1270
1580
|
*/
|
|
1271
|
-
webSocketClose(ws: WebSocket,
|
|
1581
|
+
webSocketClose(ws: WebSocket, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
|
|
1272
1582
|
/**
|
|
1273
1583
|
* WebSocket Hibernation API handler for errors
|
|
1274
1584
|
* Called when a WebSocket encounters an error
|
|
@@ -1287,11 +1597,21 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1287
1597
|
* This is the actual execution logic, separate from the public execute() RPC method
|
|
1288
1598
|
*/
|
|
1289
1599
|
private executeFlow;
|
|
1600
|
+
/**
|
|
1601
|
+
* Internal method: Execute an effect (called by alarm queue)
|
|
1602
|
+
* Effects run outside the tool execution context.
|
|
1603
|
+
*/
|
|
1604
|
+
private executeEffect;
|
|
1290
1605
|
/**
|
|
1291
1606
|
* Internal method: Process a message (called by alarm queue)
|
|
1292
1607
|
* This is the actual message processing logic, separate from the public sendMessage() RPC method
|
|
1293
1608
|
*/
|
|
1294
1609
|
private processMessage;
|
|
1610
|
+
/**
|
|
1611
|
+
* Internal method: Continue execution without adding a message (called by alarm queue)
|
|
1612
|
+
* This allows resuming FlowEngine execution from where it stopped.
|
|
1613
|
+
*/
|
|
1614
|
+
private doContinueExecution;
|
|
1295
1615
|
/**
|
|
1296
1616
|
* TEST METHOD: Queue a test operation
|
|
1297
1617
|
* Used for testing alarm queue ordering and timing
|
|
@@ -1538,6 +1858,59 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1538
1858
|
error: any;
|
|
1539
1859
|
files?: undefined;
|
|
1540
1860
|
}>;
|
|
1861
|
+
/**
|
|
1862
|
+
* Start a chunked file upload.
|
|
1863
|
+
* Creates file record with is_chunked=1 and chunk_count=null.
|
|
1864
|
+
* Caller should then use writeFileChunk() to write chunks.
|
|
1865
|
+
*/
|
|
1866
|
+
startChunkedUpload(path: string, totalSize: number, mimeType: string, options?: {
|
|
1867
|
+
metadata?: Record<string, unknown>;
|
|
1868
|
+
width?: number;
|
|
1869
|
+
height?: number;
|
|
1870
|
+
}): Promise<{
|
|
1871
|
+
success: boolean;
|
|
1872
|
+
chunkSize?: number;
|
|
1873
|
+
expectedChunks?: number;
|
|
1874
|
+
error?: string;
|
|
1875
|
+
}>;
|
|
1876
|
+
/**
|
|
1877
|
+
* Write a single chunk of a chunked file upload.
|
|
1878
|
+
* @param path - File path
|
|
1879
|
+
* @param chunkIndex - 0-based chunk index
|
|
1880
|
+
* @param data - Base64 encoded chunk data
|
|
1881
|
+
*/
|
|
1882
|
+
writeFileChunk(path: string, chunkIndex: number, data: string): Promise<{
|
|
1883
|
+
success: boolean;
|
|
1884
|
+
error?: string;
|
|
1885
|
+
}>;
|
|
1886
|
+
/**
|
|
1887
|
+
* Complete a chunked file upload.
|
|
1888
|
+
* Validates all chunks are present and sets chunk_count.
|
|
1889
|
+
*/
|
|
1890
|
+
completeChunkedUpload(path: string, expectedChunks: number, options?: {
|
|
1891
|
+
thumbnail?: string;
|
|
1892
|
+
}): Promise<{
|
|
1893
|
+
success: boolean;
|
|
1894
|
+
file?: FileRecord;
|
|
1895
|
+
error?: string;
|
|
1896
|
+
}>;
|
|
1897
|
+
/**
|
|
1898
|
+
* Read a single chunk of a file.
|
|
1899
|
+
* Use for streaming large files to client.
|
|
1900
|
+
*/
|
|
1901
|
+
readFileChunk(path: string, chunkIndex: number): Promise<{
|
|
1902
|
+
success: boolean;
|
|
1903
|
+
data?: string;
|
|
1904
|
+
error?: string;
|
|
1905
|
+
}>;
|
|
1906
|
+
/**
|
|
1907
|
+
* Get file info including chunking metadata.
|
|
1908
|
+
*/
|
|
1909
|
+
getFileInfo(path: string): Promise<{
|
|
1910
|
+
success: boolean;
|
|
1911
|
+
file?: FileRecord;
|
|
1912
|
+
error?: string;
|
|
1913
|
+
}>;
|
|
1541
1914
|
}
|
|
1542
1915
|
|
|
1543
1916
|
/**
|
|
@@ -1550,6 +1923,7 @@ interface AgentBuilderEnv {
|
|
|
1550
1923
|
GITHUB_TOKEN?: string;
|
|
1551
1924
|
GITHUB_REPO?: string;
|
|
1552
1925
|
GITHUB_BRANCH?: string;
|
|
1926
|
+
ENCRYPTION_KEY?: string;
|
|
1553
1927
|
}
|
|
1554
1928
|
/**
|
|
1555
1929
|
* Thread metadata stored in the registry.
|
|
@@ -1559,6 +1933,8 @@ interface ThreadRegistryEntry {
|
|
|
1559
1933
|
agent_name: string;
|
|
1560
1934
|
user_id: string | null;
|
|
1561
1935
|
tags: string[] | null;
|
|
1936
|
+
tenvs: Record<string, unknown> | null;
|
|
1937
|
+
properties: Record<string, unknown> | null;
|
|
1562
1938
|
created_at: number;
|
|
1563
1939
|
}
|
|
1564
1940
|
/**
|
|
@@ -1583,7 +1959,7 @@ interface User {
|
|
|
1583
1959
|
/**
|
|
1584
1960
|
* Provider credentials.
|
|
1585
1961
|
*/
|
|
1586
|
-
interface Provider {
|
|
1962
|
+
interface Provider$1 {
|
|
1587
1963
|
name: string;
|
|
1588
1964
|
sdk: string;
|
|
1589
1965
|
api_key: string;
|
|
@@ -1627,6 +2003,8 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1627
2003
|
agent_name: string;
|
|
1628
2004
|
user_id?: string;
|
|
1629
2005
|
tags?: string[];
|
|
2006
|
+
tenvs?: Record<string, unknown>;
|
|
2007
|
+
properties?: Record<string, unknown>;
|
|
1630
2008
|
}): Promise<ThreadRegistryEntry>;
|
|
1631
2009
|
/**
|
|
1632
2010
|
* Get a thread by ID.
|
|
@@ -1634,10 +2012,15 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1634
2012
|
getThread(id: string): Promise<ThreadRegistryEntry | null>;
|
|
1635
2013
|
/**
|
|
1636
2014
|
* List threads with optional filtering.
|
|
2015
|
+
* Note: tenvs are not decrypted in list operations for performance.
|
|
2016
|
+
* Use getThread() to retrieve a thread with decrypted tenvs.
|
|
1637
2017
|
*/
|
|
1638
2018
|
listThreads(params?: {
|
|
1639
2019
|
agent_name?: string;
|
|
1640
2020
|
user_id?: string;
|
|
2021
|
+
search?: string;
|
|
2022
|
+
startDate?: number;
|
|
2023
|
+
endDate?: number;
|
|
1641
2024
|
limit?: number;
|
|
1642
2025
|
offset?: number;
|
|
1643
2026
|
}): Promise<{
|
|
@@ -1683,15 +2066,15 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1683
2066
|
/**
|
|
1684
2067
|
* Get a provider's credentials.
|
|
1685
2068
|
*/
|
|
1686
|
-
getProvider(name: string): Promise<Provider | null>;
|
|
2069
|
+
getProvider(name: string): Promise<Provider$1 | null>;
|
|
1687
2070
|
/**
|
|
1688
2071
|
* Set a provider's credentials.
|
|
1689
2072
|
*/
|
|
1690
|
-
setProvider(provider: Provider): Promise<void>;
|
|
2073
|
+
setProvider(provider: Provider$1): Promise<void>;
|
|
1691
2074
|
/**
|
|
1692
2075
|
* List all providers.
|
|
1693
2076
|
*/
|
|
1694
|
-
listProviders(): Promise<Provider[]>;
|
|
2077
|
+
listProviders(): Promise<Provider$1[]>;
|
|
1695
2078
|
/**
|
|
1696
2079
|
* Delete a provider.
|
|
1697
2080
|
*/
|
|
@@ -1838,211 +2221,74 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1838
2221
|
/**
|
|
1839
2222
|
* Handle fetch requests - used for WebSocket upgrades
|
|
1840
2223
|
*/
|
|
1841
|
-
fetch(request: Request): Promise<Response>;
|
|
1842
|
-
/**
|
|
1843
|
-
* Handle WebSocket upgrade for events channel
|
|
1844
|
-
* Uses Hibernation API to reduce costs during inactivity
|
|
1845
|
-
*/
|
|
1846
|
-
private handleEventsWebSocketUpgrade;
|
|
1847
|
-
/**
|
|
1848
|
-
* Broadcast an event to all connected WebSocket clients
|
|
1849
|
-
*/
|
|
1850
|
-
private broadcastEvent;
|
|
1851
|
-
/**
|
|
1852
|
-
* WebSocket Hibernation API handler for incoming messages
|
|
1853
|
-
* Called when a message is received on a hibernated WebSocket
|
|
1854
|
-
*/
|
|
1855
|
-
webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void>;
|
|
1856
|
-
/**
|
|
1857
|
-
* WebSocket Hibernation API handler for connection close
|
|
1858
|
-
* Called when a WebSocket connection is closed
|
|
1859
|
-
*/
|
|
1860
|
-
webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
|
|
1861
|
-
/**
|
|
1862
|
-
* WebSocket Hibernation API handler for errors
|
|
1863
|
-
* Called when a WebSocket encounters an error
|
|
1864
|
-
*/
|
|
1865
|
-
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
/**
|
|
1869
|
-
* Model definition module for AgentBuilder.
|
|
1870
|
-
*
|
|
1871
|
-
* Models define LLM configurations including provider, model ID, pricing,
|
|
1872
|
-
* and fallback chains. Models are referenced by name from prompts.
|
|
1873
|
-
*
|
|
1874
|
-
* @module
|
|
1875
|
-
*/
|
|
1876
|
-
/**
|
|
1877
|
-
* Supported LLM provider types.
|
|
1878
|
-
* Each provider requires a corresponding API key environment variable:
|
|
1879
|
-
* - `openai` → `OPENAI_API_KEY`
|
|
1880
|
-
* - `openrouter` → `OPENROUTER_API_KEY`
|
|
1881
|
-
* - `anthropic` → `ANTHROPIC_API_KEY`
|
|
1882
|
-
* - `google` → `GOOGLE_API_KEY`
|
|
1883
|
-
* - `test` → No API key required (for testing with scripted responses)
|
|
1884
|
-
*/
|
|
1885
|
-
type ModelProvider = 'openai' | 'openrouter' | 'anthropic' | 'google' | 'test';
|
|
1886
|
-
/**
|
|
1887
|
-
* Model definition configuration.
|
|
1888
|
-
*
|
|
1889
|
-
* @template N - The model name as a string literal type for type inference
|
|
1890
|
-
*
|
|
1891
|
-
* @example
|
|
1892
|
-
* ```typescript
|
|
1893
|
-
* import { defineModel } from '@standardagents/builder';
|
|
1894
|
-
*
|
|
1895
|
-
* export default defineModel({
|
|
1896
|
-
* name: 'gpt-4o',
|
|
1897
|
-
* provider: 'openai',
|
|
1898
|
-
* model: 'gpt-4o',
|
|
1899
|
-
* fallbacks: ['gpt-4-turbo', 'gpt-3.5-turbo'],
|
|
1900
|
-
* inputPrice: 2.5,
|
|
1901
|
-
* outputPrice: 10,
|
|
1902
|
-
* });
|
|
1903
|
-
* ```
|
|
1904
|
-
*/
|
|
1905
|
-
interface ModelDefinition<N extends string = string> {
|
|
1906
|
-
/**
|
|
1907
|
-
* Unique name for this model definition.
|
|
1908
|
-
* Used as the identifier when referencing from prompts.
|
|
1909
|
-
* Should be descriptive and consistent (e.g., 'gpt-4o', 'claude-3-opus').
|
|
1910
|
-
*/
|
|
1911
|
-
name: N;
|
|
1912
|
-
/**
|
|
1913
|
-
* The LLM provider to use for API calls.
|
|
1914
|
-
* The corresponding API key environment variable must be set.
|
|
1915
|
-
*/
|
|
1916
|
-
provider: ModelProvider;
|
|
1917
|
-
/**
|
|
1918
|
-
* The actual model identifier sent to the provider API.
|
|
1919
|
-
*
|
|
1920
|
-
* For OpenAI: 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', etc.
|
|
1921
|
-
* For OpenRouter: 'openai/gpt-4o', 'anthropic/claude-3-opus', etc.
|
|
1922
|
-
* For Anthropic: 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', etc.
|
|
1923
|
-
* For Google: 'gemini-1.5-pro', 'gemini-1.5-flash', etc.
|
|
1924
|
-
*/
|
|
1925
|
-
model: string;
|
|
1926
|
-
/**
|
|
1927
|
-
* Optional list of additional provider prefixes for OpenRouter.
|
|
1928
|
-
* Allows routing through specific providers when using OpenRouter.
|
|
1929
|
-
*
|
|
1930
|
-
* @example ['anthropic', 'google'] - prefer Anthropic, fallback to Google
|
|
1931
|
-
*/
|
|
1932
|
-
includedProviders?: string[];
|
|
1933
|
-
/**
|
|
1934
|
-
* Fallback models to try if this model fails.
|
|
1935
|
-
* Referenced by model name (must be defined in agentbuilder/models/).
|
|
1936
|
-
* Tried in order after primary model exhausts retries.
|
|
1937
|
-
*
|
|
1938
|
-
* @example ['gpt-4', 'gpt-3.5-turbo']
|
|
2224
|
+
fetch(request: Request): Promise<Response>;
|
|
2225
|
+
/**
|
|
2226
|
+
* Handle WebSocket upgrade for events channel
|
|
2227
|
+
* Uses Hibernation API to reduce costs during inactivity
|
|
1939
2228
|
*/
|
|
1940
|
-
|
|
2229
|
+
private handleEventsWebSocketUpgrade;
|
|
1941
2230
|
/**
|
|
1942
|
-
*
|
|
1943
|
-
* Used for cost tracking and reporting in logs.
|
|
2231
|
+
* Broadcast an event to all connected WebSocket clients
|
|
1944
2232
|
*/
|
|
1945
|
-
|
|
2233
|
+
private broadcastEvent;
|
|
1946
2234
|
/**
|
|
1947
|
-
*
|
|
1948
|
-
*
|
|
2235
|
+
* WebSocket Hibernation API handler for incoming messages
|
|
2236
|
+
* Called when a message is received on a hibernated WebSocket
|
|
1949
2237
|
*/
|
|
1950
|
-
|
|
2238
|
+
webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void>;
|
|
1951
2239
|
/**
|
|
1952
|
-
*
|
|
1953
|
-
*
|
|
2240
|
+
* WebSocket Hibernation API handler for connection close
|
|
2241
|
+
* Called when a WebSocket connection is closed
|
|
1954
2242
|
*/
|
|
1955
|
-
|
|
2243
|
+
webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
|
|
1956
2244
|
/**
|
|
1957
|
-
*
|
|
2245
|
+
* WebSocket Hibernation API handler for errors
|
|
2246
|
+
* Called when a WebSocket encounters an error
|
|
1958
2247
|
*/
|
|
1959
|
-
|
|
1960
|
-
/**
|
|
1961
|
-
* Whether the model supports vision (image understanding).
|
|
1962
|
-
* When true, image attachments will be sent to the model as part of the request.
|
|
1963
|
-
* Models like GPT-4o, Claude 3, and Gemini support vision.
|
|
1964
|
-
*/
|
|
1965
|
-
vision?: boolean;
|
|
1966
|
-
/**
|
|
1967
|
-
* Whether the model supports function calling (tool use).
|
|
1968
|
-
* Most modern models support this, defaults to true if not specified.
|
|
1969
|
-
*/
|
|
1970
|
-
functionCalling?: boolean;
|
|
1971
|
-
/**
|
|
1972
|
-
* Whether the model supports structured outputs (JSON mode).
|
|
1973
|
-
*/
|
|
1974
|
-
structuredOutputs?: boolean;
|
|
1975
|
-
};
|
|
2248
|
+
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
1976
2249
|
}
|
|
2250
|
+
|
|
1977
2251
|
/**
|
|
1978
|
-
*
|
|
2252
|
+
* Model definition module for AgentBuilder.
|
|
1979
2253
|
*
|
|
1980
|
-
*
|
|
1981
|
-
*
|
|
1982
|
-
*
|
|
2254
|
+
* This module re-exports model types from @standardagents/spec and provides
|
|
2255
|
+
* a builder-specific version of ModelDefinition that supports the generated
|
|
2256
|
+
* AgentBuilder.Models type for fallback references.
|
|
1983
2257
|
*
|
|
1984
|
-
* @
|
|
1985
|
-
|
|
1986
|
-
|
|
2258
|
+
* @module
|
|
2259
|
+
*/
|
|
2260
|
+
|
|
2261
|
+
/**
|
|
2262
|
+
* Model definition configuration with AgentBuilder-specific fallback typing.
|
|
1987
2263
|
*
|
|
1988
|
-
* @
|
|
1989
|
-
*
|
|
1990
|
-
* // agentbuilder/models/gpt_4o.ts
|
|
1991
|
-
* import { defineModel } from '@standardagents/builder';
|
|
1992
|
-
*
|
|
1993
|
-
* export default defineModel({
|
|
1994
|
-
* name: 'gpt-4o',
|
|
1995
|
-
* provider: 'openai',
|
|
1996
|
-
* model: 'gpt-4o',
|
|
1997
|
-
* fallbacks: ['gpt-4-turbo'],
|
|
1998
|
-
* inputPrice: 2.5,
|
|
1999
|
-
* outputPrice: 10,
|
|
2000
|
-
* });
|
|
2001
|
-
* ```
|
|
2264
|
+
* Extends the base ModelDefinition from @standardagents/spec to support
|
|
2265
|
+
* the generated AgentBuilder.Models type for type-safe fallback references.
|
|
2002
2266
|
*
|
|
2003
|
-
* @
|
|
2004
|
-
* ```typescript
|
|
2005
|
-
* // Using OpenRouter with provider preferences
|
|
2006
|
-
* export default defineModel({
|
|
2007
|
-
* name: 'claude-3-opus',
|
|
2008
|
-
* provider: 'openrouter',
|
|
2009
|
-
* model: 'anthropic/claude-3-opus',
|
|
2010
|
-
* includedProviders: ['anthropic'],
|
|
2011
|
-
* });
|
|
2012
|
-
* ```
|
|
2267
|
+
* @template N - The model name as a string literal type for type inference
|
|
2013
2268
|
*/
|
|
2014
|
-
|
|
2269
|
+
interface ModelDefinition<N extends string = string> extends Omit<ModelDefinition$1<N>, 'fallbacks'> {
|
|
2270
|
+
/**
|
|
2271
|
+
* Fallback models to try if this model fails.
|
|
2272
|
+
* Referenced by model name (must be defined in agents/models/).
|
|
2273
|
+
* Tried in order after primary model exhausts retries.
|
|
2274
|
+
*
|
|
2275
|
+
* @example ['gpt-4', 'gpt-3.5-turbo']
|
|
2276
|
+
*/
|
|
2277
|
+
fallbacks?: AgentBuilder.Models[];
|
|
2278
|
+
}
|
|
2015
2279
|
|
|
2016
2280
|
/**
|
|
2017
2281
|
* Prompt definition module for AgentBuilder.
|
|
2018
2282
|
*
|
|
2019
|
-
*
|
|
2020
|
-
*
|
|
2283
|
+
* This module re-exports prompt types from @standardagents/spec and provides
|
|
2284
|
+
* builder-specific versions that use the generated AgentBuilder namespace types.
|
|
2021
2285
|
*
|
|
2022
2286
|
* @module
|
|
2023
2287
|
*/
|
|
2024
2288
|
|
|
2025
2289
|
/**
|
|
2026
|
-
* A
|
|
2027
|
-
*
|
|
2028
|
-
* @example
|
|
2029
|
-
* ```typescript
|
|
2030
|
-
* { type: 'text', content: 'You are a helpful assistant.\n\n' }
|
|
2031
|
-
* ```
|
|
2032
|
-
*/
|
|
2033
|
-
interface PromptTextPart {
|
|
2034
|
-
type: 'text';
|
|
2035
|
-
/** The text content */
|
|
2036
|
-
content: string;
|
|
2037
|
-
}
|
|
2038
|
-
/**
|
|
2039
|
-
* A prompt inclusion part - includes another prompt's content.
|
|
2040
|
-
* Uses AgentBuilder.Prompts for type-safe autocomplete of prompt names.
|
|
2041
|
-
*
|
|
2042
|
-
* @example
|
|
2043
|
-
* ```typescript
|
|
2044
|
-
* { type: 'include', prompt: 'responder_rules' }
|
|
2045
|
-
* ```
|
|
2290
|
+
* A prompt inclusion part with type-safe autocomplete.
|
|
2291
|
+
* Uses AgentBuilder.Prompts for type-safe prompt name references.
|
|
2046
2292
|
*/
|
|
2047
2293
|
interface PromptIncludePart {
|
|
2048
2294
|
type: 'include';
|
|
@@ -2051,448 +2297,107 @@ interface PromptIncludePart {
|
|
|
2051
2297
|
}
|
|
2052
2298
|
/**
|
|
2053
2299
|
* A single part of a structured prompt.
|
|
2054
|
-
* Discriminated union on `type` field for TypeScript narrowing.
|
|
2055
2300
|
*/
|
|
2056
2301
|
type PromptPart = PromptTextPart | PromptIncludePart;
|
|
2057
2302
|
/**
|
|
2058
|
-
*
|
|
2059
|
-
* Provides type-safe composition with other prompts via autocomplete.
|
|
2060
|
-
*
|
|
2061
|
-
* @example
|
|
2062
|
-
* ```typescript
|
|
2063
|
-
* prompt: [
|
|
2064
|
-
* { type: 'text', content: 'You are a helpful assistant.\n\n' },
|
|
2065
|
-
* { type: 'include', prompt: 'common_rules' },
|
|
2066
|
-
* { type: 'text', content: '\n\nBe concise.' },
|
|
2067
|
-
* ]
|
|
2068
|
-
* ```
|
|
2069
|
-
*/
|
|
2070
|
-
type StructuredPrompt = PromptPart[];
|
|
2071
|
-
/**
|
|
2072
|
-
* The prompt content can be either a plain string or a structured array.
|
|
2073
|
-
*
|
|
2074
|
-
* @example
|
|
2075
|
-
* ```typescript
|
|
2076
|
-
* // Simple string prompt:
|
|
2077
|
-
* prompt: 'You are a helpful assistant.'
|
|
2078
|
-
*
|
|
2079
|
-
* // Structured prompt with includes:
|
|
2080
|
-
* prompt: [
|
|
2081
|
-
* { type: 'text', content: 'You are a helpful assistant.\n\n' },
|
|
2082
|
-
* { type: 'include', prompt: 'common_rules' },
|
|
2083
|
-
* ]
|
|
2084
|
-
* ```
|
|
2303
|
+
* Prompt content can be a string or structured array with type-safe includes.
|
|
2085
2304
|
*/
|
|
2086
|
-
type PromptContent = string |
|
|
2305
|
+
type PromptContent = string | PromptPart[];
|
|
2087
2306
|
/**
|
|
2088
|
-
*
|
|
2089
|
-
*
|
|
2090
|
-
* @template T - The tool name type (for type-safe tool references)
|
|
2307
|
+
* Sub-prompt configuration with type-safe name references.
|
|
2091
2308
|
*/
|
|
2092
|
-
interface
|
|
2093
|
-
/**
|
|
2094
|
-
* Name of the tool to include.
|
|
2095
|
-
* Must be a tool, prompt, or agent defined in agentbuilder/.
|
|
2096
|
-
*/
|
|
2309
|
+
interface SubpromptConfig<T extends string = AgentBuilder.Callables> extends Omit<SubpromptConfig$2<T>, 'name'> {
|
|
2310
|
+
/** Name of the sub-prompt (type-safe with autocomplete) */
|
|
2097
2311
|
name: T;
|
|
2098
|
-
/**
|
|
2099
|
-
* Include text response content from sub-prompt execution in the tool result.
|
|
2100
|
-
* @default true
|
|
2101
|
-
*/
|
|
2102
|
-
includeTextResponse?: boolean;
|
|
2103
|
-
/**
|
|
2104
|
-
* Include tool call details from sub-prompt execution in the tool result.
|
|
2105
|
-
* @default true
|
|
2106
|
-
*/
|
|
2107
|
-
includeToolCalls?: boolean;
|
|
2108
|
-
/**
|
|
2109
|
-
* Include error details from sub-prompt execution in the tool result.
|
|
2110
|
-
* @default true
|
|
2111
|
-
*/
|
|
2112
|
-
includeErrors?: boolean;
|
|
2113
|
-
/**
|
|
2114
|
-
* Property from the tool call arguments to use as the initial user message
|
|
2115
|
-
* when this tool triggers a sub-prompt execution.
|
|
2116
|
-
*
|
|
2117
|
-
* @example
|
|
2118
|
-
* If the tool is called with `{ query: "search term", limit: 10 }` and
|
|
2119
|
-
* `initUserMessageProperty: 'query'`, the sub-prompt will receive
|
|
2120
|
-
* "search term" as the initial user message.
|
|
2121
|
-
*/
|
|
2122
|
-
initUserMessageProperty?: string;
|
|
2123
2312
|
}
|
|
2124
2313
|
/**
|
|
2125
|
-
*
|
|
2126
|
-
* Applies to models like OpenAI o1, Anthropic Claude with extended thinking,
|
|
2127
|
-
* Google Gemini with thinking, and Qwen with reasoning.
|
|
2314
|
+
* @deprecated Use SubpromptConfig instead
|
|
2128
2315
|
*/
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
* Effort level for reasoning models.
|
|
2132
|
-
* Higher effort = more thinking tokens = potentially better results.
|
|
2133
|
-
*
|
|
2134
|
-
* - `low`: Minimal reasoning, faster responses
|
|
2135
|
-
* - `medium`: Balanced reasoning and speed
|
|
2136
|
-
* - `high`: Maximum reasoning, slower but more thorough
|
|
2137
|
-
*
|
|
2138
|
-
* @default undefined (use model defaults)
|
|
2139
|
-
*/
|
|
2140
|
-
effort?: 'low' | 'medium' | 'high';
|
|
2141
|
-
/**
|
|
2142
|
-
* Maximum tokens to allocate for reasoning.
|
|
2143
|
-
* Applies to models that support token limits on reasoning
|
|
2144
|
-
* (Anthropic, Gemini, Qwen).
|
|
2145
|
-
*/
|
|
2146
|
-
maxTokens?: number;
|
|
2147
|
-
/**
|
|
2148
|
-
* Use reasoning internally but exclude from the response.
|
|
2149
|
-
* Model thinks through the problem but only returns the final answer.
|
|
2150
|
-
* Useful for cleaner outputs while maintaining reasoning quality.
|
|
2151
|
-
*/
|
|
2152
|
-
exclude?: boolean;
|
|
2153
|
-
/**
|
|
2154
|
-
* Include reasoning content in the message history for multi-turn context.
|
|
2155
|
-
* When true, reasoning is preserved and visible to subsequent turns.
|
|
2156
|
-
* @default false
|
|
2157
|
-
*/
|
|
2158
|
-
include?: boolean;
|
|
2159
|
-
}
|
|
2316
|
+
type ToolConfig<T extends string = AgentBuilder.Callables> = SubpromptConfig<T>;
|
|
2317
|
+
|
|
2160
2318
|
/**
|
|
2161
|
-
* Prompt definition configuration.
|
|
2319
|
+
* Prompt definition configuration with AgentBuilder-specific typing.
|
|
2320
|
+
*
|
|
2321
|
+
* Provides type-safe references to models, tools, and agents via the
|
|
2322
|
+
* generated AgentBuilder namespace.
|
|
2162
2323
|
*
|
|
2163
2324
|
* @template N - The prompt name as a string literal type
|
|
2164
2325
|
* @template S - The Zod schema type for requiredSchema (inferred automatically)
|
|
2165
|
-
*
|
|
2166
|
-
* @example
|
|
2167
|
-
* ```typescript
|
|
2168
|
-
* import { definePrompt } from '@standardagents/builder';
|
|
2169
|
-
* import { z } from 'zod';
|
|
2170
|
-
*
|
|
2171
|
-
* export default definePrompt({
|
|
2172
|
-
* name: 'customer_support',
|
|
2173
|
-
* toolDescription: 'Handle customer support inquiries',
|
|
2174
|
-
* model: 'gpt-4o',
|
|
2175
|
-
* // Simple string prompt:
|
|
2176
|
-
* prompt: `You are a helpful customer support agent.
|
|
2177
|
-
* Always be polite and try to resolve issues quickly.`,
|
|
2178
|
-
* // Or structured prompt with type-safe includes:
|
|
2179
|
-
* // prompt: [
|
|
2180
|
-
* // { type: 'text', content: 'You are a helpful customer support agent.\n\n' },
|
|
2181
|
-
* // { type: 'include', prompt: 'common_rules' },
|
|
2182
|
-
* // ],
|
|
2183
|
-
* tools: ['search_knowledge_base', 'create_ticket'],
|
|
2184
|
-
* requiredSchema: z.object({
|
|
2185
|
-
* query: z.string().describe('The customer inquiry'),
|
|
2186
|
-
* }),
|
|
2187
|
-
* });
|
|
2188
|
-
* ```
|
|
2189
2326
|
*/
|
|
2190
|
-
interface PromptDefinition<N extends string = string, S extends
|
|
2191
|
-
/**
|
|
2192
|
-
* Unique name for this prompt.
|
|
2193
|
-
* Used as the identifier when referencing from agents or as a tool.
|
|
2194
|
-
* Should be snake_case (e.g., 'customer_support', 'data_analyst').
|
|
2195
|
-
*/
|
|
2327
|
+
interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolArgs> {
|
|
2328
|
+
/** Unique name for this prompt. */
|
|
2196
2329
|
name: N;
|
|
2197
|
-
/**
|
|
2198
|
-
* Description shown when this prompt is exposed as a tool.
|
|
2199
|
-
* Should clearly describe what this prompt does for LLM tool selection.
|
|
2200
|
-
*/
|
|
2330
|
+
/** Description shown when this prompt is exposed as a tool. */
|
|
2201
2331
|
toolDescription: string;
|
|
2202
|
-
/**
|
|
2203
|
-
* The system prompt content sent to the LLM.
|
|
2204
|
-
*
|
|
2205
|
-
* Can be either:
|
|
2206
|
-
* 1. A plain string - simple prompt text
|
|
2207
|
-
* 2. A structured array - for composing prompts with type-safe includes
|
|
2208
|
-
*
|
|
2209
|
-
* @example
|
|
2210
|
-
* ```typescript
|
|
2211
|
-
* // Simple string prompt:
|
|
2212
|
-
* prompt: 'You are a helpful assistant.'
|
|
2213
|
-
*
|
|
2214
|
-
* // Structured prompt with type-safe includes:
|
|
2215
|
-
* prompt: [
|
|
2216
|
-
* { type: 'text', content: 'You are a helpful assistant.\n\n' },
|
|
2217
|
-
* { type: 'include', prompt: 'common_rules' }, // autocomplete for prompt names!
|
|
2218
|
-
* { type: 'text', content: '\n\nBe concise.' },
|
|
2219
|
-
* ]
|
|
2220
|
-
* ```
|
|
2221
|
-
*/
|
|
2332
|
+
/** The system prompt content with type-safe includes. */
|
|
2222
2333
|
prompt: PromptContent;
|
|
2223
|
-
/**
|
|
2224
|
-
* Model to use for this prompt.
|
|
2225
|
-
* Must reference a model defined in agentbuilder/models/.
|
|
2226
|
-
* Provides autocomplete when types are generated.
|
|
2227
|
-
*/
|
|
2334
|
+
/** Model to use (type-safe with autocomplete). */
|
|
2228
2335
|
model: AgentBuilder.Models;
|
|
2229
2336
|
/**
|
|
2230
2337
|
* @deprecated All prompts are now automatically exposed as tools.
|
|
2231
|
-
* This property is ignored and will be removed in a future version.
|
|
2232
2338
|
*/
|
|
2233
2339
|
exposeAsTool?: boolean;
|
|
2234
|
-
/**
|
|
2235
|
-
* Include full chat history in the LLM context.
|
|
2236
|
-
* When true, all previous messages in the conversation are included.
|
|
2237
|
-
* @default false
|
|
2238
|
-
*/
|
|
2340
|
+
/** Include full chat history in the LLM context. @default false */
|
|
2239
2341
|
includeChat?: boolean;
|
|
2240
|
-
/**
|
|
2241
|
-
* Include results from past tool calls in the LLM context.
|
|
2242
|
-
* When true, previous tool call results are visible to the LLM.
|
|
2243
|
-
* @default false
|
|
2244
|
-
*/
|
|
2342
|
+
/** Include results from past tool calls. @default false */
|
|
2245
2343
|
includePastTools?: boolean;
|
|
2246
|
-
/**
|
|
2247
|
-
* Allow parallel execution of multiple tool calls.
|
|
2248
|
-
* When true, if the LLM requests multiple tools, they execute concurrently.
|
|
2249
|
-
* @default false
|
|
2250
|
-
*/
|
|
2344
|
+
/** Allow parallel execution of multiple tool calls. @default false */
|
|
2251
2345
|
parallelToolCalls?: boolean;
|
|
2252
|
-
/**
|
|
2253
|
-
* Tool calling strategy for the LLM.
|
|
2254
|
-
*
|
|
2255
|
-
* - `auto`: Model decides when to call tools (default)
|
|
2256
|
-
* - `none`: Disable tool calling entirely
|
|
2257
|
-
* - `required`: Force the model to call at least one tool
|
|
2258
|
-
*
|
|
2259
|
-
* @default 'auto'
|
|
2260
|
-
*/
|
|
2346
|
+
/** Tool calling strategy. @default 'auto' */
|
|
2261
2347
|
toolChoice?: 'auto' | 'none' | 'required';
|
|
2262
|
-
/**
|
|
2263
|
-
* Zod schema for validating inputs when this prompt is called as a tool.
|
|
2264
|
-
*
|
|
2265
|
-
* The schema provides:
|
|
2266
|
-
* - Runtime validation of tool call arguments
|
|
2267
|
-
* - Type inference for the prompt's input type
|
|
2268
|
-
* - Auto-generated JSON Schema for LLM tool definitions
|
|
2269
|
-
*
|
|
2270
|
-
* Use `.describe()` on schema fields to provide descriptions for the LLM.
|
|
2271
|
-
*
|
|
2272
|
-
* @example
|
|
2273
|
-
* ```typescript
|
|
2274
|
-
* requiredSchema: z.object({
|
|
2275
|
-
* query: z.string().describe('The search query'),
|
|
2276
|
-
* limit: z.number().optional().default(10).describe('Max results'),
|
|
2277
|
-
* })
|
|
2278
|
-
* ```
|
|
2279
|
-
*/
|
|
2348
|
+
/** Zod schema for validating inputs when called as a tool. */
|
|
2280
2349
|
requiredSchema?: S;
|
|
2281
|
-
/**
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
*
|
|
2285
|
-
* Tools can be:
|
|
2286
|
-
* - Custom tools defined in agentbuilder/tools/
|
|
2287
|
-
* - Other prompts with exposeAsTool: true
|
|
2288
|
-
* - Agents with exposeAsTool: true
|
|
2289
|
-
*
|
|
2290
|
-
* @example
|
|
2291
|
-
* ```typescript
|
|
2292
|
-
* tools: [
|
|
2293
|
-
* 'search_docs', // Simple reference
|
|
2294
|
-
* { name: 'create_ticket', includeErrors: false }, // With config
|
|
2295
|
-
* ]
|
|
2296
|
-
* ```
|
|
2297
|
-
*/
|
|
2298
|
-
tools?: (AgentBuilder.Callables | ToolConfig)[];
|
|
2299
|
-
/**
|
|
2300
|
-
* Agents that can receive handoffs from this prompt.
|
|
2301
|
-
* Enables multi-agent workflows where this prompt can transfer
|
|
2302
|
-
* the conversation to a specialized agent.
|
|
2303
|
-
*/
|
|
2304
|
-
handoffAgents?: AgentBuilder.Agents[];
|
|
2305
|
-
/**
|
|
2306
|
-
* Tool to execute before the LLM request.
|
|
2307
|
-
* Useful for data fetching, context preparation, or preprocessing.
|
|
2308
|
-
* The tool result is available in the prompt context.
|
|
2309
|
-
*/
|
|
2310
|
-
beforeTool?: AgentBuilder.Callables;
|
|
2311
|
-
/**
|
|
2312
|
-
* Tool to execute after the LLM response.
|
|
2313
|
-
* Useful for post-processing, logging, or side effects.
|
|
2314
|
-
*/
|
|
2315
|
-
afterTool?: AgentBuilder.Callables;
|
|
2316
|
-
/**
|
|
2317
|
-
* Reasoning configuration for models that support extended thinking.
|
|
2318
|
-
* Configure effort level, token limits, and visibility of reasoning.
|
|
2319
|
-
*/
|
|
2350
|
+
/** Tools available to this prompt (type-safe with autocomplete). To enable handoffs, include ai_human agent names. */
|
|
2351
|
+
tools?: (AgentBuilder.Callables | SubpromptConfig)[];
|
|
2352
|
+
/** Reasoning configuration for extended thinking models. */
|
|
2320
2353
|
reasoning?: ReasoningConfig;
|
|
2321
|
-
/**
|
|
2322
|
-
* Maximum pixels for image attachments before client-side resize.
|
|
2323
|
-
* Images exceeding this limit are scaled down while preserving aspect ratio.
|
|
2324
|
-
* Images smaller than this limit are not resized up.
|
|
2325
|
-
*
|
|
2326
|
-
* Common values:
|
|
2327
|
-
* - 262144 (256K): 512x512 equivalent - thumbnails, low cost
|
|
2328
|
-
* - 1048576 (1M): 1024x1024 equivalent - good quality (default)
|
|
2329
|
-
* - 2073600 (2M): 1440x1440 equivalent - high quality
|
|
2330
|
-
* - 4194304 (4M): 2048x2048 equivalent - maximum detail
|
|
2331
|
-
*
|
|
2332
|
-
* @default 1048576 (1M pixels, ~1024x1024)
|
|
2333
|
-
*
|
|
2334
|
-
* @example
|
|
2335
|
-
* ```typescript
|
|
2336
|
-
* // High quality images for detailed analysis
|
|
2337
|
-
* maxImagePixels: 2073600
|
|
2338
|
-
*
|
|
2339
|
-
* // Lower quality for cost-sensitive applications
|
|
2340
|
-
* maxImagePixels: 262144
|
|
2341
|
-
* ```
|
|
2342
|
-
*/
|
|
2343
|
-
maxImagePixels?: number;
|
|
2344
|
-
/**
|
|
2345
|
-
* Number of recent messages to keep actual images for in context.
|
|
2346
|
-
* Messages older than this threshold will have their images replaced
|
|
2347
|
-
* with text descriptions to save context window space.
|
|
2348
|
-
*
|
|
2349
|
-
* This helps manage context window usage in long conversations with
|
|
2350
|
-
* many image attachments by summarizing older images.
|
|
2351
|
-
*
|
|
2352
|
-
* @default 10
|
|
2353
|
-
*
|
|
2354
|
-
* @example
|
|
2355
|
-
* ```typescript
|
|
2356
|
-
* // Keep more images in context for image-heavy workflows
|
|
2357
|
-
* recentImageThreshold: 20
|
|
2358
|
-
*
|
|
2359
|
-
* // Aggressively summarize to save context
|
|
2360
|
-
* recentImageThreshold: 5
|
|
2361
|
-
* ```
|
|
2362
|
-
*/
|
|
2354
|
+
/** Number of recent messages to keep actual images for. @default 10 */
|
|
2363
2355
|
recentImageThreshold?: number;
|
|
2364
2356
|
}
|
|
2365
|
-
/**
|
|
2366
|
-
* Helper type to extract the inferred input type from a prompt's Zod schema.
|
|
2367
|
-
*
|
|
2368
|
-
* @template T - The prompt definition type
|
|
2369
|
-
*
|
|
2370
|
-
* @example
|
|
2371
|
-
* ```typescript
|
|
2372
|
-
* const searchPrompt = definePrompt({
|
|
2373
|
-
* name: 'search',
|
|
2374
|
-
* requiredSchema: z.object({ query: z.string(), limit: z.number() }),
|
|
2375
|
-
* // ...
|
|
2376
|
-
* });
|
|
2377
|
-
*
|
|
2378
|
-
* type SearchInput = PromptInput<typeof searchPrompt>;
|
|
2379
|
-
* // { query: string; limit: number }
|
|
2380
|
-
* ```
|
|
2381
|
-
*/
|
|
2382
|
-
type PromptInput<T extends PromptDefinition<any, any>> = T['requiredSchema'] extends z.ZodTypeAny ? z.infer<T['requiredSchema']> : never;
|
|
2383
|
-
/**
|
|
2384
|
-
* Defines a prompt configuration for LLM interactions.
|
|
2385
|
-
*
|
|
2386
|
-
* Prompts are the primary way to configure how agents interact with LLMs.
|
|
2387
|
-
* They specify the system prompt, available tools, input validation,
|
|
2388
|
-
* and various behavioral options.
|
|
2389
|
-
*
|
|
2390
|
-
* @template N - The prompt name as a string literal type
|
|
2391
|
-
* @template S - The Zod schema type for requiredSchema
|
|
2392
|
-
* @param options - Prompt configuration options
|
|
2393
|
-
* @returns The prompt definition for registration
|
|
2394
|
-
*
|
|
2395
|
-
* @example
|
|
2396
|
-
* ```typescript
|
|
2397
|
-
* // agentbuilder/prompts/customer_support.ts
|
|
2398
|
-
* import { definePrompt } from '@standardagents/builder';
|
|
2399
|
-
* import { z } from 'zod';
|
|
2400
|
-
*
|
|
2401
|
-
* export default definePrompt({
|
|
2402
|
-
* name: 'customer_support',
|
|
2403
|
-
* toolDescription: 'Handle customer support inquiries',
|
|
2404
|
-
* model: 'gpt-4o',
|
|
2405
|
-
* prompt: `You are a helpful customer support agent.
|
|
2406
|
-
* Always be polite and try to resolve issues quickly.
|
|
2407
|
-
* If you cannot help, offer to escalate to a human.`,
|
|
2408
|
-
* tools: ['search_knowledge_base', 'create_ticket'],
|
|
2409
|
-
* handoffAgents: ['escalation_agent'],
|
|
2410
|
-
* includeChat: true,
|
|
2411
|
-
* exposeAsTool: true,
|
|
2412
|
-
* requiredSchema: z.object({
|
|
2413
|
-
* query: z.string().describe('The customer inquiry'),
|
|
2414
|
-
* }),
|
|
2415
|
-
* });
|
|
2416
|
-
* ```
|
|
2417
|
-
*/
|
|
2418
|
-
declare function definePrompt<N extends string, S extends z.ZodTypeAny = never>(options: PromptDefinition<N, S>): PromptDefinition<N, S>;
|
|
2419
2357
|
|
|
2420
2358
|
/**
|
|
2421
2359
|
* Agent definition module for AgentBuilder.
|
|
2422
2360
|
*
|
|
2423
|
-
*
|
|
2424
|
-
*
|
|
2425
|
-
* and behavioral rules for each side of the conversation.
|
|
2361
|
+
* This module re-exports agent types from @standardagents/spec and provides
|
|
2362
|
+
* builder-specific versions that use the generated AgentBuilder namespace types.
|
|
2426
2363
|
*
|
|
2427
2364
|
* @module
|
|
2428
2365
|
*/
|
|
2366
|
+
|
|
2429
2367
|
/**
|
|
2430
|
-
*
|
|
2431
|
-
*
|
|
2432
|
-
* - `ai_human`: AI conversing with a human user (most common)
|
|
2433
|
-
* - `dual_ai`: Two AI participants conversing with each other
|
|
2434
|
-
*/
|
|
2435
|
-
type AgentType = 'ai_human' | 'dual_ai';
|
|
2436
|
-
/**
|
|
2437
|
-
* Configuration for one side of an agent conversation.
|
|
2438
|
-
*
|
|
2439
|
-
* Each side has a prompt, stop conditions, and turn limits.
|
|
2440
|
-
* For `ai_human` agents, only sideA (the AI) needs configuration.
|
|
2441
|
-
* For `dual_ai` agents, both sides need configuration.
|
|
2368
|
+
* Side configuration with type-safe autocomplete.
|
|
2369
|
+
* Uses AgentBuilder.Prompts and AgentBuilder.Callables for type-safe references.
|
|
2442
2370
|
*/
|
|
2443
|
-
interface SideConfig {
|
|
2444
|
-
/**
|
|
2445
|
-
* Custom label for this side of the conversation.
|
|
2446
|
-
* Used in UI and logs for clarity.
|
|
2447
|
-
*
|
|
2448
|
-
* @example 'Support Agent', 'Customer', 'ATC', 'Pilot'
|
|
2449
|
-
*/
|
|
2450
|
-
label?: string;
|
|
2371
|
+
interface SideConfig extends Omit<SideConfig$1, 'prompt' | 'stopTool' | 'endSessionTool'> {
|
|
2451
2372
|
/**
|
|
2452
|
-
* The prompt to use for this side.
|
|
2453
|
-
* Must reference a prompt defined in
|
|
2373
|
+
* The prompt to use for this side (type-safe with autocomplete).
|
|
2374
|
+
* Must reference a prompt defined in agents/prompts/.
|
|
2454
2375
|
*/
|
|
2455
2376
|
prompt: AgentBuilder.Prompts;
|
|
2456
2377
|
/**
|
|
2457
|
-
* Stop this side's turn when
|
|
2458
|
-
* When true, the side's turn ends after producing a message without tools.
|
|
2459
|
-
* @default true
|
|
2460
|
-
*/
|
|
2461
|
-
stopOnResponse?: boolean;
|
|
2462
|
-
/**
|
|
2463
|
-
* Stop this side's turn when a specific tool is called.
|
|
2378
|
+
* Stop this side's turn when a specific tool is called (type-safe with autocomplete).
|
|
2464
2379
|
* Overrides stopOnResponse when the named tool is invoked.
|
|
2465
2380
|
* Requires stopToolResponseProperty to extract the result.
|
|
2466
2381
|
*/
|
|
2467
2382
|
stopTool?: AgentBuilder.Callables;
|
|
2468
2383
|
/**
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2471
|
-
* The extracted value is used to determine the conversation outcome.
|
|
2472
|
-
*/
|
|
2473
|
-
stopToolResponseProperty?: string;
|
|
2474
|
-
/**
|
|
2475
|
-
* Maximum turns for this side before forcing a stop.
|
|
2476
|
-
* Safety limit to prevent runaway conversations.
|
|
2477
|
-
* A turn is one complete request/response cycle.
|
|
2478
|
-
*/
|
|
2479
|
-
maxTurns?: number;
|
|
2480
|
-
/**
|
|
2481
|
-
* Tool that ends the entire conversation when called.
|
|
2482
|
-
* Different from stopTool - this ends the conversation for both sides,
|
|
2384
|
+
* Tool that ends the entire session when called (type-safe with autocomplete).
|
|
2385
|
+
* Different from stopTool - this ends the session for both sides,
|
|
2483
2386
|
* not just this side's turn.
|
|
2484
2387
|
*/
|
|
2485
|
-
|
|
2388
|
+
endSessionTool?: AgentBuilder.Callables;
|
|
2486
2389
|
/**
|
|
2487
2390
|
* Enable manual stop condition handling via hooks.
|
|
2488
|
-
*
|
|
2489
|
-
* instead of the built-in rules.
|
|
2391
|
+
* Builder-specific feature for custom stop logic.
|
|
2490
2392
|
* @default false
|
|
2491
2393
|
*/
|
|
2492
2394
|
manualStopCondition?: boolean;
|
|
2493
2395
|
}
|
|
2494
2396
|
/**
|
|
2495
|
-
* Agent definition configuration.
|
|
2397
|
+
* Agent definition configuration with AgentBuilder-specific typing.
|
|
2398
|
+
*
|
|
2399
|
+
* Provides type-safe references to prompts and tools via the
|
|
2400
|
+
* generated AgentBuilder namespace.
|
|
2496
2401
|
*
|
|
2497
2402
|
* @template N - The agent name as a string literal type
|
|
2498
2403
|
*
|
|
@@ -2509,131 +2414,68 @@ interface SideConfig {
|
|
|
2509
2414
|
* prompt: 'customer_support',
|
|
2510
2415
|
* stopOnResponse: true,
|
|
2511
2416
|
* },
|
|
2512
|
-
* tags: ['support', 'tier-1'],
|
|
2513
2417
|
* });
|
|
2514
2418
|
* ```
|
|
2515
2419
|
*/
|
|
2516
2420
|
interface AgentDefinition<N extends string = string> {
|
|
2517
|
-
/**
|
|
2518
|
-
* Unique name for this agent.
|
|
2519
|
-
* Used as the identifier for thread creation and handoffs.
|
|
2520
|
-
* Should be snake_case (e.g., 'support_agent', 'research_flow').
|
|
2521
|
-
*/
|
|
2421
|
+
/** Unique name for this agent. */
|
|
2522
2422
|
name: N;
|
|
2523
2423
|
/**
|
|
2524
2424
|
* Human-readable title for the agent.
|
|
2525
|
-
* Optional - if not provided, the name will be used.
|
|
2526
2425
|
* @deprecated Use name instead. Title will be removed in a future version.
|
|
2527
2426
|
*/
|
|
2528
2427
|
title?: string;
|
|
2529
2428
|
/**
|
|
2530
2429
|
* Agent conversation type.
|
|
2531
|
-
*
|
|
2532
2430
|
* - `ai_human`: AI conversing with a human user (default)
|
|
2533
2431
|
* - `dual_ai`: Two AI participants conversing
|
|
2534
|
-
*
|
|
2535
2432
|
* @default 'ai_human'
|
|
2536
2433
|
*/
|
|
2537
|
-
type?:
|
|
2434
|
+
type?: 'ai_human' | 'dual_ai';
|
|
2538
2435
|
/**
|
|
2539
2436
|
* Maximum total turns across both sides.
|
|
2540
2437
|
* Only applies to `dual_ai` agents.
|
|
2541
|
-
* Prevents infinite loops in AI-to-AI conversations.
|
|
2542
2438
|
*/
|
|
2543
2439
|
maxSessionTurns?: number;
|
|
2544
|
-
/**
|
|
2545
|
-
* Configuration for Side A.
|
|
2546
|
-
* For `ai_human`: This is the AI side.
|
|
2547
|
-
* For `dual_ai`: This is the first AI participant.
|
|
2548
|
-
*/
|
|
2440
|
+
/** Configuration for Side A (type-safe with autocomplete). */
|
|
2549
2441
|
sideA: SideConfig;
|
|
2550
|
-
/**
|
|
2551
|
-
* Configuration for Side B.
|
|
2552
|
-
* For `ai_human`: Optional, the human side doesn't need config.
|
|
2553
|
-
* For `dual_ai`: Required, the second AI participant.
|
|
2554
|
-
*/
|
|
2442
|
+
/** Configuration for Side B (type-safe with autocomplete). */
|
|
2555
2443
|
sideB?: SideConfig;
|
|
2556
2444
|
/**
|
|
2557
2445
|
* Expose this agent as a tool for other prompts.
|
|
2558
|
-
* Enables agent composition and handoffs.
|
|
2559
|
-
* When true, other prompts can invoke this agent as a tool.
|
|
2560
2446
|
* @default false
|
|
2561
2447
|
*/
|
|
2562
2448
|
exposeAsTool?: boolean;
|
|
2563
|
-
/**
|
|
2564
|
-
* Description shown when agent is used as a tool.
|
|
2565
|
-
* Required if exposeAsTool is true.
|
|
2566
|
-
* Should clearly describe what this agent does.
|
|
2567
|
-
*/
|
|
2449
|
+
/** Description shown when agent is used as a tool. */
|
|
2568
2450
|
toolDescription?: string;
|
|
2569
2451
|
/**
|
|
2570
|
-
*
|
|
2571
|
-
*
|
|
2572
|
-
*
|
|
2573
|
-
* @example ['customer-service', 'tier-1', 'english']
|
|
2452
|
+
* Thread environment variables for this agent.
|
|
2453
|
+
* Merged into thread tenvs at creation time.
|
|
2454
|
+
* Later values (thread) override earlier ones (prompt -> agent).
|
|
2574
2455
|
*/
|
|
2575
|
-
|
|
2456
|
+
tenvs?: Record<string, unknown>;
|
|
2457
|
+
/** Brief description of what this agent does. */
|
|
2458
|
+
description?: string;
|
|
2459
|
+
/** Icon URL or absolute path for the agent. */
|
|
2460
|
+
icon?: string;
|
|
2576
2461
|
}
|
|
2462
|
+
|
|
2577
2463
|
/**
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
* Agents orchestrate conversations between AI models, or between AI and
|
|
2581
|
-
* human users. They use prompts to configure each side of the conversation
|
|
2582
|
-
* and define stop conditions to control conversation flow.
|
|
2583
|
-
*
|
|
2584
|
-
* @template N - The agent name as a string literal type
|
|
2585
|
-
* @param options - Agent configuration options
|
|
2586
|
-
* @returns The agent definition for registration
|
|
2587
|
-
*
|
|
2588
|
-
* @example
|
|
2589
|
-
* ```typescript
|
|
2590
|
-
* // agentbuilder/agents/support_agent.ts
|
|
2591
|
-
* import { defineAgent } from '@standardagents/builder';
|
|
2592
|
-
*
|
|
2593
|
-
* export default defineAgent({
|
|
2594
|
-
* name: 'support_agent',
|
|
2595
|
-
* title: 'Customer Support Agent',
|
|
2596
|
-
* type: 'ai_human',
|
|
2597
|
-
* sideA: {
|
|
2598
|
-
* label: 'Support',
|
|
2599
|
-
* prompt: 'customer_support',
|
|
2600
|
-
* stopOnResponse: true,
|
|
2601
|
-
* endConversationTool: 'close_ticket',
|
|
2602
|
-
* },
|
|
2603
|
-
* exposeAsTool: true,
|
|
2604
|
-
* toolDescription: 'Hand off to customer support',
|
|
2605
|
-
* tags: ['support', 'tier-1'],
|
|
2606
|
-
* });
|
|
2607
|
-
* ```
|
|
2608
|
-
*
|
|
2609
|
-
* @example
|
|
2610
|
-
* ```typescript
|
|
2611
|
-
* // Dual AI agent (two AIs conversing)
|
|
2612
|
-
* export default defineAgent({
|
|
2613
|
-
* name: 'debate_agent',
|
|
2614
|
-
* title: 'AI Debate',
|
|
2615
|
-
* type: 'dual_ai',
|
|
2616
|
-
* maxSessionTurns: 10,
|
|
2617
|
-
* sideA: {
|
|
2618
|
-
* label: 'Pro',
|
|
2619
|
-
* prompt: 'debate_pro',
|
|
2620
|
-
* stopOnResponse: true,
|
|
2621
|
-
* },
|
|
2622
|
-
* sideB: {
|
|
2623
|
-
* label: 'Con',
|
|
2624
|
-
* prompt: 'debate_con',
|
|
2625
|
-
* stopOnResponse: true,
|
|
2626
|
-
* endConversationTool: 'conclude_debate',
|
|
2627
|
-
* },
|
|
2628
|
-
* });
|
|
2629
|
-
* ```
|
|
2464
|
+
* Options for generating a model file.
|
|
2630
2465
|
*/
|
|
2631
|
-
|
|
2632
|
-
|
|
2466
|
+
interface GenerateModelFileOptions {
|
|
2467
|
+
/** The provider export name (e.g., 'openai', 'openrouter') */
|
|
2468
|
+
providerName: string;
|
|
2469
|
+
/** The provider package (e.g., '@standardagents/openai') */
|
|
2470
|
+
providerPackage: string;
|
|
2471
|
+
}
|
|
2633
2472
|
/**
|
|
2634
2473
|
* Generate a TypeScript file for a model definition.
|
|
2474
|
+
*
|
|
2475
|
+
* @param data - The model definition data
|
|
2476
|
+
* @param options - Provider import options (required since providers are functions)
|
|
2635
2477
|
*/
|
|
2636
|
-
declare function generateModelFile(data: ModelDefinition): string;
|
|
2478
|
+
declare function generateModelFile(data: ModelDefinition, options: GenerateModelFileOptions): string;
|
|
2637
2479
|
|
|
2638
2480
|
/**
|
|
2639
2481
|
* Converts JSON Schema to Zod code string.
|
|
@@ -2672,6 +2514,8 @@ interface ToolConfigInput {
|
|
|
2672
2514
|
include_tool_calls?: boolean;
|
|
2673
2515
|
include_errors?: boolean;
|
|
2674
2516
|
init_user_message_property?: string | null;
|
|
2517
|
+
init_attachments_property?: string | null;
|
|
2518
|
+
tenvs?: Record<string, unknown>;
|
|
2675
2519
|
}
|
|
2676
2520
|
/**
|
|
2677
2521
|
* Prompt part as it comes from the UI/API.
|
|
@@ -2706,9 +2550,6 @@ interface PromptFileData {
|
|
|
2706
2550
|
parallelToolCalls?: boolean;
|
|
2707
2551
|
toolChoice?: 'auto' | 'none' | 'required';
|
|
2708
2552
|
tools?: (string | ToolConfigInput)[];
|
|
2709
|
-
handoffAgents?: string[];
|
|
2710
|
-
beforeTool?: string;
|
|
2711
|
-
afterTool?: string;
|
|
2712
2553
|
reasoning?: {
|
|
2713
2554
|
effort?: 'low' | 'medium' | 'high';
|
|
2714
2555
|
maxTokens?: number;
|
|
@@ -3793,4 +3634,15 @@ declare class GitHubApiError extends Error {
|
|
|
3793
3634
|
constructor(message: string, status: number, details?: unknown);
|
|
3794
3635
|
}
|
|
3795
3636
|
|
|
3796
|
-
|
|
3637
|
+
/** @public Alias for LLMProviderInterface */
|
|
3638
|
+
type Provider = LLMProviderInterface;
|
|
3639
|
+
/** @public Alias for ContentPart */
|
|
3640
|
+
type ProviderContentPart = ContentPart;
|
|
3641
|
+
/** @public Alias for TextPart */
|
|
3642
|
+
type ProviderTextPart = TextPart;
|
|
3643
|
+
/** @public Alias for ImagePart */
|
|
3644
|
+
type ProviderImagePart = ImagePart;
|
|
3645
|
+
/** @public Alias for FilePart */
|
|
3646
|
+
type ProviderFilePart = FilePart;
|
|
3647
|
+
|
|
3648
|
+
export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, type BuilderThreadEndpointHandler, type BuilderController as Controller, type BuilderControllerContext as ControllerContext, DurableAgentBuilder, DurableThread, type Env, type FileRecord, type FileStats, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type GrepResult, type ImageContentPart, type ImageContextConfig, type ImageMetadata, type InjectMessageOptions$1 as InjectMessageOptions, type Provider as LLMProviderInterface, type LLMResponse, type Message, type MessageContent, type ModelDefinition, type MultimodalContent, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptPart, type Provider$1 as Provider, type ProviderContentPart, type ProviderFilePart, type ProviderImagePart, type ProviderTextPart, type RequestContext, type SideConfig, type StorageBackend, type SubpromptConfig, type TelemetryEvent, type TextContentPart, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type ToolCall, type ToolConfig, type ToolResult, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, defineController, defineThreadEndpoint, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
|