@standardagents/builder 0.11.12 → 0.12.1
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/built-in-routes.js +3498 -498
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +56 -25
- package/dist/client/vendor.js +78 -5
- package/dist/client/vue.js +1 -1
- package/dist/discovery-CpMs68Yx.d.ts +97 -0
- package/dist/index-DkbUJ4MM.d.ts +1043 -0
- package/dist/index.d.ts +205 -999
- package/dist/index.js +4563 -956
- package/dist/index.js.map +1 -1
- package/dist/packing.d.ts +266 -0
- package/dist/packing.js +2202 -0
- package/dist/packing.js.map +1 -0
- package/dist/plugin.js +3477 -608
- package/dist/plugin.js.map +1 -1
- package/dist/test.d.ts +256 -0
- package/dist/test.js +391 -0
- package/dist/test.js.map +1 -0
- package/dist/types-pLkJx8vg.d.ts +306 -0
- package/package.json +25 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
export { AgentPluginOptions, agentbuilder } from './plugin.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
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';
|
|
2
|
+
import { T as ThreadEnv, a as ThreadMetadata, F as FileRecord, b as FlowState, M as Message, c as FileStats, G as GrepResult, A as AttachmentRef, d as MessageContent } from './index-DkbUJ4MM.js';
|
|
3
|
+
export { j as Agent, i as BuilderThreadEndpointHandler, B as Controller, g as ControllerContext, E as Env, n as FlowResult, q as ImageContentPart, I as ImageMetadata, L as LLMResponse, r as MultimodalContent, R as RequestContext, S as StorageBackend, o as TelemetryEvent, p as TextContentPart, h as ThreadEndpointContext, k as ThreadInstance, l as ToolCall, m as ToolResult, f as createThreadEndpointHandler, e as defineController } from './index-DkbUJ4MM.js';
|
|
4
|
+
import { ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$1, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
|
|
5
|
+
export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, 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, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
|
|
6
6
|
import { DurableObject } from 'cloudflare:workers';
|
|
7
|
+
import { N as NamespacedRegistry } from './types-pLkJx8vg.js';
|
|
8
|
+
export { C as ConstituentItem, D as DiscoveredPackage, P as PackingAnalysis, a as PackingOptions, b as PackingResult, U as UnpackOptions, c as UnpackResult } from './types-pLkJx8vg.js';
|
|
9
|
+
export { D as DiscoveryConfig, P as PackageDiscoveryService, d as discoverPackages } from './discovery-CpMs68Yx.js';
|
|
7
10
|
import 'vite';
|
|
11
|
+
import '@cloudflare/workers-types';
|
|
12
|
+
import 'zod';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Global namespace for AgentBuilder types.
|
|
@@ -81,999 +86,6 @@ declare global {
|
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
/**
|
|
85
|
-
* Callback function to execute before stream closes
|
|
86
|
-
*/
|
|
87
|
-
type BeforeClose = () => Promise<void> | void;
|
|
88
|
-
/**
|
|
89
|
-
* Manages HTTP streaming of content chunks.
|
|
90
|
-
* WebSocket telemetry is handled separately by DurableThread.
|
|
91
|
-
* Inspired by bod.coach MultiplexedStream pattern.
|
|
92
|
-
*/
|
|
93
|
-
declare class StreamManager {
|
|
94
|
-
/**
|
|
95
|
-
* HTTP ReadableStream controller for content
|
|
96
|
-
*/
|
|
97
|
-
private httpController?;
|
|
98
|
-
/**
|
|
99
|
-
* HTTP ReadableStream for content chunks
|
|
100
|
-
*/
|
|
101
|
-
httpStream: ReadableStream<Uint8Array>;
|
|
102
|
-
/**
|
|
103
|
-
* Active channels
|
|
104
|
-
*/
|
|
105
|
-
activeChannels: number;
|
|
106
|
-
/**
|
|
107
|
-
* Before close hooks
|
|
108
|
-
*/
|
|
109
|
-
private beforeCloseHooks;
|
|
110
|
-
/**
|
|
111
|
-
* Prevent automatic close
|
|
112
|
-
*/
|
|
113
|
-
preventClose: boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Text encoder for streams
|
|
116
|
-
*/
|
|
117
|
-
private encoder;
|
|
118
|
-
/**
|
|
119
|
-
* Promise that resolves when stream is completely finished
|
|
120
|
-
*/
|
|
121
|
-
then: Promise<void>;
|
|
122
|
-
/**
|
|
123
|
-
* Resolver for the then promise
|
|
124
|
-
*/
|
|
125
|
-
private resolver;
|
|
126
|
-
/**
|
|
127
|
-
* Whether the stream has been closed
|
|
128
|
-
*/
|
|
129
|
-
private closed;
|
|
130
|
-
constructor(beforeClose?: BeforeClose | BeforeClose[]);
|
|
131
|
-
/**
|
|
132
|
-
* Send content chunk to HTTP stream
|
|
133
|
-
*/
|
|
134
|
-
sendContent(chunk: string): void;
|
|
135
|
-
/**
|
|
136
|
-
* Add a before close hook
|
|
137
|
-
*/
|
|
138
|
-
addBeforeClose(hook: BeforeClose | BeforeClose[]): void;
|
|
139
|
-
/**
|
|
140
|
-
* Wait for a callback to complete before allowing stream to close
|
|
141
|
-
*/
|
|
142
|
-
waitFor(callback: () => Promise<void> | void): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* Close a channel (decrement active channel count)
|
|
145
|
-
*/
|
|
146
|
-
closeChannel(): void;
|
|
147
|
-
/**
|
|
148
|
-
* Close all streams and connections
|
|
149
|
-
*/
|
|
150
|
-
close(): Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
* Force close the stream immediately
|
|
153
|
-
*/
|
|
154
|
-
forceClose(): void;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Agent configuration from D1 agents table
|
|
159
|
-
*/
|
|
160
|
-
interface Agent {
|
|
161
|
-
id: string;
|
|
162
|
-
title: string;
|
|
163
|
-
type: "dual_ai" | "ai_human";
|
|
164
|
-
created_at: number;
|
|
165
|
-
max_session_turns: number | null;
|
|
166
|
-
side_a_label: string | null;
|
|
167
|
-
side_a_agent_prompt: string | null;
|
|
168
|
-
side_a_stop_on_response: boolean;
|
|
169
|
-
side_a_stop_tool: string | null;
|
|
170
|
-
side_a_stop_tool_response_property: string | null;
|
|
171
|
-
side_a_max_steps: number | null;
|
|
172
|
-
side_a_end_session_tool: string | null;
|
|
173
|
-
side_b_label: string | null;
|
|
174
|
-
side_b_agent_prompt: string | null;
|
|
175
|
-
side_b_stop_on_response: boolean;
|
|
176
|
-
side_b_stop_tool: string | null;
|
|
177
|
-
side_b_stop_tool_response_property: string | null;
|
|
178
|
-
side_b_max_steps: number | null;
|
|
179
|
-
side_b_end_session_tool: string | null;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Message in OpenAI chat completion format
|
|
183
|
-
*/
|
|
184
|
-
interface Message {
|
|
185
|
-
id: string;
|
|
186
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
187
|
-
content: string | null;
|
|
188
|
-
name?: string | null;
|
|
189
|
-
tool_calls?: string | null;
|
|
190
|
-
tool_call_id?: string | null;
|
|
191
|
-
log_id?: string | null;
|
|
192
|
-
created_at: number;
|
|
193
|
-
request_sent_at?: number | null;
|
|
194
|
-
response_completed_at?: number | null;
|
|
195
|
-
status?: "pending" | "completed" | "failed";
|
|
196
|
-
silent?: boolean;
|
|
197
|
-
tool_status?: "success" | "error" | null;
|
|
198
|
-
reasoning_content?: string | null;
|
|
199
|
-
reasoning_details?: string | null;
|
|
200
|
-
parent_id?: string | null;
|
|
201
|
-
depth?: number;
|
|
202
|
-
attachments?: string | null;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Tool call from OpenAI format
|
|
206
|
-
*/
|
|
207
|
-
interface ToolCall {
|
|
208
|
-
id: string;
|
|
209
|
-
type: "function";
|
|
210
|
-
function: {
|
|
211
|
-
name: string;
|
|
212
|
-
arguments: string;
|
|
213
|
-
};
|
|
214
|
-
forceAllow?: boolean;
|
|
215
|
-
queued_at?: number;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Thread metadata from DurableAgentBuilder
|
|
219
|
-
* Note: agent_id is now the agent name (not UUID) since agents are in TypeScript
|
|
220
|
-
*/
|
|
221
|
-
interface ThreadMetadata {
|
|
222
|
-
id: string;
|
|
223
|
-
agent_id: string;
|
|
224
|
-
user_id: string | null;
|
|
225
|
-
tenvs: Record<string, unknown> | null;
|
|
226
|
-
properties: Record<string, unknown> | null;
|
|
227
|
-
created_at: number;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Hook registry type - transforms HookSignatures into lazy-loaded optional hooks
|
|
231
|
-
*/
|
|
232
|
-
type HookRegistry = {
|
|
233
|
-
[K in keyof HookSignatures]?: () => Promise<HookSignatures[K]>;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* Native tool module type - represents a loaded tool definition.
|
|
237
|
-
* Tools can have args (with validation schema) or no args.
|
|
238
|
-
* Uses local Zod types for compatibility with z.toJSONSchema().
|
|
239
|
-
*/
|
|
240
|
-
interface NativeToolModule {
|
|
241
|
-
/** Description of what the tool does (shown to the LLM). */
|
|
242
|
-
description: string;
|
|
243
|
-
/** Zod schema for validating tool arguments, or null for no args. */
|
|
244
|
-
args: ZodObject<ZodRawShape> | null;
|
|
245
|
-
/** The tool implementation function. */
|
|
246
|
-
execute: ((state: any, args: Record<string, unknown>) => Promise<ToolResult$1>) | ((state: any) => Promise<ToolResult$1>);
|
|
247
|
-
/** Zod schema for thread environment variables, or null if none. */
|
|
248
|
-
tenvs?: ZodObject<ZodRawShape> | null;
|
|
249
|
-
/**
|
|
250
|
-
* Where this tool is executed:
|
|
251
|
-
* - 'local': Execute locally by the execution engine (default)
|
|
252
|
-
* - 'provider': Executed by the LLM provider, results come in response
|
|
253
|
-
*/
|
|
254
|
-
executionMode?: 'local' | 'provider';
|
|
255
|
-
/**
|
|
256
|
-
* Which provider executes this tool (when executionMode='provider').
|
|
257
|
-
*/
|
|
258
|
-
executionProvider?: string;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Thread instance (forward reference to avoid circular dependency)
|
|
262
|
-
*/
|
|
263
|
-
interface ThreadInstance {
|
|
264
|
-
ctx: DurableObjectState;
|
|
265
|
-
env: ThreadEnv;
|
|
266
|
-
getMessages(limit?: number, offset?: number, order?: "asc" | "desc", includeSilent?: boolean, maxDepth?: number): Promise<{
|
|
267
|
-
messages: Message[];
|
|
268
|
-
total: number;
|
|
269
|
-
hasMore: boolean;
|
|
270
|
-
}>;
|
|
271
|
-
getLogs(limit?: number, offset?: number, order?: "asc" | "desc"): Promise<LogData[]>;
|
|
272
|
-
getThreadMeta(threadId: string): Promise<ThreadMetadata | null>;
|
|
273
|
-
deleteMessage(messageId: string): Promise<{
|
|
274
|
-
success: boolean;
|
|
275
|
-
error?: string;
|
|
276
|
-
}>;
|
|
277
|
-
shouldStop(): Promise<boolean>;
|
|
278
|
-
tools(): Record<string, () => Promise<NativeToolModule>>;
|
|
279
|
-
hooks(): HookRegistry;
|
|
280
|
-
loadModel(name: string): Promise<any>;
|
|
281
|
-
loadPrompt(name: string): Promise<any>;
|
|
282
|
-
loadAgent(name: string): Promise<any>;
|
|
283
|
-
getPromptNames(): string[];
|
|
284
|
-
getAgentNames(): string[];
|
|
285
|
-
writeFile(path: string, data: string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
|
|
286
|
-
writeTextFile(path: string, content: string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
|
|
287
|
-
readFile(path: string): Promise<{
|
|
288
|
-
success: boolean;
|
|
289
|
-
data?: string;
|
|
290
|
-
error?: string;
|
|
291
|
-
}>;
|
|
292
|
-
statFile(path: string): Promise<any>;
|
|
293
|
-
readdirFile(path: string): Promise<any[]>;
|
|
294
|
-
unlinkFile(path: string): Promise<void>;
|
|
295
|
-
mkdirFile(path: string): Promise<any>;
|
|
296
|
-
rmdirFile(path: string): Promise<void>;
|
|
297
|
-
getFileStats(): Promise<any>;
|
|
298
|
-
grepFiles(pattern: string): Promise<any[]>;
|
|
299
|
-
findFiles(pattern: string): Promise<any>;
|
|
300
|
-
getFileThumbnail(path: string): Promise<ArrayBuffer | null>;
|
|
301
|
-
readFileChunk(path: string, chunkIndex: number): Promise<{
|
|
302
|
-
success: boolean;
|
|
303
|
-
data?: string;
|
|
304
|
-
error?: string;
|
|
305
|
-
}>;
|
|
306
|
-
runAgent(threadId: string, agentName: string): Promise<void>;
|
|
307
|
-
scheduleEffect(threadId: string, effectName: string, effectArgs: Record<string, unknown>, delayMs?: number): Promise<string>;
|
|
308
|
-
getScheduledEffects(name?: string): Promise<Array<{
|
|
309
|
-
id: string;
|
|
310
|
-
name: string;
|
|
311
|
-
args: Record<string, unknown>;
|
|
312
|
-
scheduledAt: number;
|
|
313
|
-
createdAt: number;
|
|
314
|
-
}>>;
|
|
315
|
-
removeScheduledEffect(id: string): Promise<boolean>;
|
|
316
|
-
insertOrphanedToolCall(params: {
|
|
317
|
-
content?: string;
|
|
318
|
-
toolCallId: string;
|
|
319
|
-
toolName: string;
|
|
320
|
-
toolArgs: string;
|
|
321
|
-
}): Promise<Response>;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Tool call for internal flow management
|
|
325
|
-
*/
|
|
326
|
-
type FlowToolCall = {
|
|
327
|
-
tool: string;
|
|
328
|
-
args: Record<string, unknown>;
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* Prompt call for internal flow management
|
|
332
|
-
*/
|
|
333
|
-
type FlowPromptCall = {
|
|
334
|
-
prompt: string;
|
|
335
|
-
args: Record<string, unknown>;
|
|
336
|
-
};
|
|
337
|
-
/**
|
|
338
|
-
* Flow call (tool or prompt)
|
|
339
|
-
*/
|
|
340
|
-
type FlowCall = FlowToolCall | FlowPromptCall;
|
|
341
|
-
/**
|
|
342
|
-
* Flow call with retry tracking
|
|
343
|
-
*/
|
|
344
|
-
type FlowCallWithRetries = FlowCall & {
|
|
345
|
-
retries: number;
|
|
346
|
-
reasons: string[];
|
|
347
|
-
};
|
|
348
|
-
/**
|
|
349
|
-
* Sub-prompt configuration - defines options for when a sub-prompt is called as a tool
|
|
350
|
-
*/
|
|
351
|
-
interface SubpromptConfig$1 {
|
|
352
|
-
name: string;
|
|
353
|
-
initUserMessageProperty?: string;
|
|
354
|
-
initAttachmentsProperty?: string;
|
|
355
|
-
includeTextResponse?: boolean;
|
|
356
|
-
includeToolCalls?: boolean;
|
|
357
|
-
includeErrors?: boolean;
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Prompt configuration - now loaded from TypeScript virtual modules
|
|
361
|
-
*/
|
|
362
|
-
interface PromptData {
|
|
363
|
-
id: string;
|
|
364
|
-
name: string;
|
|
365
|
-
prompt: string | any[];
|
|
366
|
-
system_prompt?: string;
|
|
367
|
-
model: string;
|
|
368
|
-
model_id?: string;
|
|
369
|
-
tool_description: string;
|
|
370
|
-
required_schema: string;
|
|
371
|
-
include_chat: boolean;
|
|
372
|
-
include_past_tools: boolean;
|
|
373
|
-
prompts: string;
|
|
374
|
-
created_at: number;
|
|
375
|
-
/** @deprecated All prompts are now automatically exposed as tools */
|
|
376
|
-
expose_as_tool?: boolean;
|
|
377
|
-
parallel_tool_calls: boolean;
|
|
378
|
-
tool_choice: "auto" | "none" | "required" | "function";
|
|
379
|
-
reasoning_effort: "low" | "medium" | "high" | null;
|
|
380
|
-
reasoning_max_tokens: number | null;
|
|
381
|
-
reasoning_exclude: boolean;
|
|
382
|
-
include_reasoning: boolean;
|
|
383
|
-
recentImageThreshold: number | null;
|
|
384
|
-
_tools?: (string | SubpromptConfig$1)[];
|
|
385
|
-
_requiredSchema?: any;
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Central state object that flows through execution
|
|
389
|
-
*/
|
|
390
|
-
interface FlowState {
|
|
391
|
-
threadId: string;
|
|
392
|
-
flowId: string;
|
|
393
|
-
thread: {
|
|
394
|
-
instance: ThreadInstance;
|
|
395
|
-
metadata: ThreadMetadata;
|
|
396
|
-
};
|
|
397
|
-
agentConfig: Agent;
|
|
398
|
-
currentSide: "a" | "b";
|
|
399
|
-
prompts: {
|
|
400
|
-
sideA: PromptData;
|
|
401
|
-
sideB: PromptData | null;
|
|
402
|
-
};
|
|
403
|
-
prompt: PromptData;
|
|
404
|
-
stepCount: number;
|
|
405
|
-
sideAStepCount: number;
|
|
406
|
-
sideBStepCount: number;
|
|
407
|
-
stopped: boolean;
|
|
408
|
-
stoppedBy?: "a" | "b";
|
|
409
|
-
forcedNextSide?: "side_a" | "side_b";
|
|
410
|
-
pendingForceTurn?: "side_a" | "side_b";
|
|
411
|
-
abortController?: AbortController;
|
|
412
|
-
messageHistory: Message[];
|
|
413
|
-
/**
|
|
414
|
-
* Appends these messages
|
|
415
|
-
*/
|
|
416
|
-
extraMessages: Message[];
|
|
417
|
-
sequence: {
|
|
418
|
-
queue: ToolCall[];
|
|
419
|
-
queuedTools: ToolCall[];
|
|
420
|
-
isHandling: boolean;
|
|
421
|
-
};
|
|
422
|
-
active: FlowCallWithRetries;
|
|
423
|
-
queue: FlowCall[];
|
|
424
|
-
pendingHandoff?: {
|
|
425
|
-
agentId: string;
|
|
426
|
-
args?: Record<string, unknown>;
|
|
427
|
-
toolConfig?: {
|
|
428
|
-
initUserMessageProperty?: string;
|
|
429
|
-
initAttachmentsProperty?: string;
|
|
430
|
-
};
|
|
431
|
-
};
|
|
432
|
-
stream: StreamManager;
|
|
433
|
-
context: Record<string, unknown>;
|
|
434
|
-
retryCount: number;
|
|
435
|
-
retryReason?: string;
|
|
436
|
-
storage: DurableObjectStorage;
|
|
437
|
-
env: ThreadEnv;
|
|
438
|
-
emitLog?: (log: unknown) => void;
|
|
439
|
-
emitMessage?: (message: unknown) => void;
|
|
440
|
-
emitMessageChunk?: (messageId: string, chunk: string, depth?: number) => void;
|
|
441
|
-
emitTelemetry?: (event: TelemetryEvent) => void;
|
|
442
|
-
emitEvent?: (type: string, data: unknown) => void;
|
|
443
|
-
rootState: FlowState;
|
|
444
|
-
rootMessageId?: string | null;
|
|
445
|
-
parentLogId?: string | null;
|
|
446
|
-
currentLogId?: string | null;
|
|
447
|
-
parentMessageId?: string;
|
|
448
|
-
depth: number;
|
|
449
|
-
/** Path from root prompt to current prompt (e.g., ['basic_prompt', 'generate_image']) */
|
|
450
|
-
promptPath: string[];
|
|
451
|
-
pendingMessageId?: string;
|
|
452
|
-
allowedTools?: ToolDefinition[];
|
|
453
|
-
pendingMetadataPromises?: Promise<void>[];
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Text content part for multimodal messages
|
|
457
|
-
*/
|
|
458
|
-
interface TextContentPart {
|
|
459
|
-
type: "text";
|
|
460
|
-
text: string;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Image URL content part for multimodal messages (OpenAI/OpenRouter format)
|
|
464
|
-
*/
|
|
465
|
-
interface ImageContentPart {
|
|
466
|
-
type: "image_url";
|
|
467
|
-
image_url: {
|
|
468
|
-
url: string;
|
|
469
|
-
detail?: "auto" | "low" | "high";
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Multimodal content - array of text and image parts
|
|
474
|
-
*/
|
|
475
|
-
type MultimodalContent = Array<TextContentPart | ImageContentPart>;
|
|
476
|
-
/**
|
|
477
|
-
* Message content - can be string (text only) or array (multimodal)
|
|
478
|
-
*/
|
|
479
|
-
type MessageContent = string | MultimodalContent;
|
|
480
|
-
/**
|
|
481
|
-
* Request context for LLM calls
|
|
482
|
-
*/
|
|
483
|
-
interface RequestContext {
|
|
484
|
-
messages: Array<{
|
|
485
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
486
|
-
content?: MessageContent;
|
|
487
|
-
tool_calls?: ToolCall[];
|
|
488
|
-
tool_call_id?: string;
|
|
489
|
-
name?: string;
|
|
490
|
-
reasoning_content?: string;
|
|
491
|
-
reasoning_details?: any[];
|
|
492
|
-
attachments?: any[];
|
|
493
|
-
toolName?: string;
|
|
494
|
-
}>;
|
|
495
|
-
model: string;
|
|
496
|
-
tools?: ToolDefinition[];
|
|
497
|
-
stream?: boolean;
|
|
498
|
-
promptName?: string;
|
|
499
|
-
systemPrompt?: string;
|
|
500
|
-
parentLogId?: string | null;
|
|
501
|
-
parallel_tool_calls?: boolean;
|
|
502
|
-
tool_choice?: "auto" | "none" | "required" | {
|
|
503
|
-
type: "function";
|
|
504
|
-
function: {
|
|
505
|
-
name: string;
|
|
506
|
-
};
|
|
507
|
-
};
|
|
508
|
-
reasoning?: {
|
|
509
|
-
effort?: "low" | "medium" | "high";
|
|
510
|
-
max_tokens?: number;
|
|
511
|
-
exclude?: boolean;
|
|
512
|
-
};
|
|
513
|
-
imagePathMap?: Map<string, string>;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Tool definition for LLM requests
|
|
517
|
-
*/
|
|
518
|
-
interface ToolDefinition {
|
|
519
|
-
type: "function";
|
|
520
|
-
function: {
|
|
521
|
-
name: string;
|
|
522
|
-
description: string;
|
|
523
|
-
parameters?: Record<string, any>;
|
|
524
|
-
};
|
|
525
|
-
/**
|
|
526
|
-
* Where this tool is executed:
|
|
527
|
-
* - 'local': Execute locally by the execution engine (default)
|
|
528
|
-
* - 'provider': Executed by the LLM provider, results come in response
|
|
529
|
-
*/
|
|
530
|
-
executionMode?: 'local' | 'provider';
|
|
531
|
-
/**
|
|
532
|
-
* Which provider executes this tool (when executionMode='provider')
|
|
533
|
-
* e.g., 'openai', 'anthropic'
|
|
534
|
-
*/
|
|
535
|
-
executionProvider?: string;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Image returned by an LLM response (e.g., from image generation models)
|
|
539
|
-
* Format follows OpenAI/OpenRouter chat completions API
|
|
540
|
-
*/
|
|
541
|
-
interface LLMResponseImage {
|
|
542
|
-
type: "image_url";
|
|
543
|
-
/** Unique ID for this generated image (used to link to tool call) */
|
|
544
|
-
id?: string;
|
|
545
|
-
/** Name of the tool that generated this image (e.g., 'image_generation') */
|
|
546
|
-
toolName?: string;
|
|
547
|
-
/** The revised/actual prompt used to generate the image (from OpenAI's image_generation) */
|
|
548
|
-
revisedPrompt?: string;
|
|
549
|
-
image_url: {
|
|
550
|
-
url: string;
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* LLM response
|
|
555
|
-
*/
|
|
556
|
-
interface LLMResponse {
|
|
557
|
-
id: string;
|
|
558
|
-
model: string;
|
|
559
|
-
content: string | null;
|
|
560
|
-
reasoning_content?: string | null;
|
|
561
|
-
reasoning_details?: any[];
|
|
562
|
-
tool_calls?: ToolCall[];
|
|
563
|
-
images?: LLMResponseImage[];
|
|
564
|
-
finish_reason: string;
|
|
565
|
-
usage: {
|
|
566
|
-
prompt_tokens: number;
|
|
567
|
-
completion_tokens: number;
|
|
568
|
-
total_tokens: number;
|
|
569
|
-
prompt_tokens_details?: {
|
|
570
|
-
cached_tokens?: number;
|
|
571
|
-
};
|
|
572
|
-
completion_tokens_details?: {
|
|
573
|
-
reasoning_tokens?: number;
|
|
574
|
-
};
|
|
575
|
-
cost?: number;
|
|
576
|
-
provider?: string;
|
|
577
|
-
};
|
|
578
|
-
/** @internal Provider instance reference for async metadata fetching */
|
|
579
|
-
_provider?: unknown;
|
|
580
|
-
/** @internal Provider response ID for async metadata fetching */
|
|
581
|
-
_providerResponseId?: string;
|
|
582
|
-
/** @internal Aggregate response for logging */
|
|
583
|
-
_aggregate_response?: unknown;
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* Attachment returned by a tool (e.g., generated images)
|
|
587
|
-
* Stored in thread filesystem and linked to the tool message
|
|
588
|
-
*/
|
|
589
|
-
interface ToolAttachment {
|
|
590
|
-
name: string;
|
|
591
|
-
mimeType: string;
|
|
592
|
-
data: string;
|
|
593
|
-
width?: number;
|
|
594
|
-
height?: number;
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Tool result
|
|
598
|
-
*/
|
|
599
|
-
interface ToolResult {
|
|
600
|
-
status: "success" | "error";
|
|
601
|
-
/**
|
|
602
|
-
* Flattened text representation of the tool output.
|
|
603
|
-
*
|
|
604
|
-
* For tools that return structured MCP-style content (an array of
|
|
605
|
-
* content parts), this will be derived by concatenating all text
|
|
606
|
-
* parts. For legacy tools that returned a plain string `result`,
|
|
607
|
-
* that value is used directly.
|
|
608
|
-
*/
|
|
609
|
-
result?: string;
|
|
610
|
-
error?: string;
|
|
611
|
-
stack?: string;
|
|
612
|
-
/**
|
|
613
|
-
* File attachments returned by the tool.
|
|
614
|
-
*
|
|
615
|
-
* Can contain either:
|
|
616
|
-
* - ToolAttachment: New files with base64 data to be stored
|
|
617
|
-
* - AttachmentRef: References to existing files in the thread filesystem
|
|
618
|
-
*
|
|
619
|
-
* New attachments are stored under /attachments/ directory.
|
|
620
|
-
*/
|
|
621
|
-
attachments?: Array<ToolAttachment | AttachmentRef>;
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* Flow execution result
|
|
625
|
-
*/
|
|
626
|
-
interface FlowResult {
|
|
627
|
-
messages: Message[];
|
|
628
|
-
stopped: boolean;
|
|
629
|
-
stoppedBy?: "a" | "b";
|
|
630
|
-
stepCount: number;
|
|
631
|
-
stream: ReadableStream<Uint8Array>;
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Telemetry event types
|
|
635
|
-
*/
|
|
636
|
-
type TelemetryEvent = {
|
|
637
|
-
type: "step_started";
|
|
638
|
-
step: number;
|
|
639
|
-
side: "a" | "b";
|
|
640
|
-
timestamp: number;
|
|
641
|
-
} | {
|
|
642
|
-
type: "step_completed";
|
|
643
|
-
step: number;
|
|
644
|
-
stopped: boolean;
|
|
645
|
-
timestamp: number;
|
|
646
|
-
} | {
|
|
647
|
-
type: "llm_request";
|
|
648
|
-
model: string;
|
|
649
|
-
attempt: number;
|
|
650
|
-
timestamp: number;
|
|
651
|
-
} | {
|
|
652
|
-
type: "llm_response";
|
|
653
|
-
tokens: number;
|
|
654
|
-
latency: number;
|
|
655
|
-
timestamp: number;
|
|
656
|
-
} | {
|
|
657
|
-
type: "validation_failed";
|
|
658
|
-
error: string;
|
|
659
|
-
timestamp: number;
|
|
660
|
-
} | {
|
|
661
|
-
type: "fallback_triggered";
|
|
662
|
-
from: string;
|
|
663
|
-
to: string;
|
|
664
|
-
timestamp: number;
|
|
665
|
-
} | {
|
|
666
|
-
type: "tool_started";
|
|
667
|
-
tool: string;
|
|
668
|
-
timestamp: number;
|
|
669
|
-
} | {
|
|
670
|
-
type: "tool_completed";
|
|
671
|
-
tool: string;
|
|
672
|
-
status: string;
|
|
673
|
-
timestamp: number;
|
|
674
|
-
} | {
|
|
675
|
-
type: "stopped";
|
|
676
|
-
reason: string;
|
|
677
|
-
side: "a" | "b";
|
|
678
|
-
timestamp: number;
|
|
679
|
-
} | {
|
|
680
|
-
type: "stopped_by_user";
|
|
681
|
-
timestamp: number;
|
|
682
|
-
};
|
|
683
|
-
/**
|
|
684
|
-
* Log data for telemetry table
|
|
685
|
-
*/
|
|
686
|
-
interface LogData {
|
|
687
|
-
id: string;
|
|
688
|
-
message_id: string;
|
|
689
|
-
provider: string;
|
|
690
|
-
model: string;
|
|
691
|
-
model_name?: string;
|
|
692
|
-
endpoint?: string;
|
|
693
|
-
request_body?: string;
|
|
694
|
-
request_headers?: string;
|
|
695
|
-
response_body?: string;
|
|
696
|
-
response_headers?: string;
|
|
697
|
-
status_code?: number;
|
|
698
|
-
reasoning_content?: string | null;
|
|
699
|
-
input_tokens?: number;
|
|
700
|
-
cached_tokens?: number;
|
|
701
|
-
output_tokens?: number;
|
|
702
|
-
reasoning_tokens?: number;
|
|
703
|
-
total_tokens?: number;
|
|
704
|
-
latency_ms?: number;
|
|
705
|
-
time_to_first_token_ms?: number;
|
|
706
|
-
finish_reason?: string;
|
|
707
|
-
error?: string;
|
|
708
|
-
error_type?: string;
|
|
709
|
-
cost_input?: number;
|
|
710
|
-
cost_output?: number;
|
|
711
|
-
cost_total?: number;
|
|
712
|
-
message_history_length?: number;
|
|
713
|
-
tools_available?: number;
|
|
714
|
-
prompt_name?: string;
|
|
715
|
-
tools_called?: string;
|
|
716
|
-
queued_tools?: string;
|
|
717
|
-
actual_provider?: string | null;
|
|
718
|
-
parent_log_id?: string | null;
|
|
719
|
-
tools_schema?: string | null;
|
|
720
|
-
message_history?: string | null;
|
|
721
|
-
system_prompt?: string | null;
|
|
722
|
-
is_complete?: boolean;
|
|
723
|
-
errors?: string | null;
|
|
724
|
-
retry_of_log_id?: string | null;
|
|
725
|
-
created_at: number;
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Base environment interface for StandardAgents.
|
|
729
|
-
* Extends ThreadEnv with optional provider API keys.
|
|
730
|
-
*
|
|
731
|
-
* User's Env interface should extend this or include these bindings.
|
|
732
|
-
*/
|
|
733
|
-
interface Env extends ThreadEnv {
|
|
734
|
-
OPENAI_API_KEY?: string;
|
|
735
|
-
ANTHROPIC_API_KEY?: string;
|
|
736
|
-
OPENROUTER_API_KEY?: string;
|
|
737
|
-
GOOGLE_API_KEY?: string;
|
|
738
|
-
UI_DEV_SERVER?: string;
|
|
739
|
-
ASSETS?: {
|
|
740
|
-
fetch(request: Request | string): Promise<Response>;
|
|
741
|
-
};
|
|
742
|
-
GITHUB_TOKEN?: string;
|
|
743
|
-
GITHUB_REPO?: string;
|
|
744
|
-
GITHUB_BRANCH?: string;
|
|
745
|
-
SUPER_ADMIN_PASSWORD?: string;
|
|
746
|
-
ENCRYPTION_KEY?: string;
|
|
747
|
-
[key: string]: unknown;
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Storage backend types for files
|
|
751
|
-
*/
|
|
752
|
-
type StorageBackend = "local" | "url" | "s3" | "r2";
|
|
753
|
-
/**
|
|
754
|
-
* File record stored in the files table
|
|
755
|
-
*/
|
|
756
|
-
interface FileRecord {
|
|
757
|
-
path: string;
|
|
758
|
-
name: string;
|
|
759
|
-
mimeType: string;
|
|
760
|
-
storage: StorageBackend;
|
|
761
|
-
location?: string | null;
|
|
762
|
-
size: number;
|
|
763
|
-
metadata?: Record<string, unknown> | null;
|
|
764
|
-
isDirectory: boolean;
|
|
765
|
-
createdAt: number;
|
|
766
|
-
width?: number | null;
|
|
767
|
-
height?: number | null;
|
|
768
|
-
isChunked?: boolean;
|
|
769
|
-
chunkCount?: number;
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Image-specific metadata stored in FileRecord.metadata
|
|
773
|
-
*/
|
|
774
|
-
interface ImageMetadata {
|
|
775
|
-
width: number;
|
|
776
|
-
height: number;
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Attachment reference stored in messages.attachments (JSON array)
|
|
780
|
-
*/
|
|
781
|
-
interface AttachmentRef {
|
|
782
|
-
id: string;
|
|
783
|
-
type: "file";
|
|
784
|
-
path: string;
|
|
785
|
-
name: string;
|
|
786
|
-
mimeType: string;
|
|
787
|
-
width?: number;
|
|
788
|
-
height?: number;
|
|
789
|
-
description?: string;
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Grep search result
|
|
793
|
-
*/
|
|
794
|
-
interface GrepResult {
|
|
795
|
-
path: string;
|
|
796
|
-
name: string;
|
|
797
|
-
matches: string[];
|
|
798
|
-
lineNumbers?: number[];
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* File stats for storage tracking
|
|
802
|
-
*/
|
|
803
|
-
interface FileStats {
|
|
804
|
-
totalSize: number;
|
|
805
|
-
fileCount: number;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Router and endpoint definition module for AgentBuilder.
|
|
810
|
-
*
|
|
811
|
-
* This module re-exports endpoint types from @standardagents/spec and provides
|
|
812
|
-
* the runtime router implementation for handling HTTP requests.
|
|
813
|
-
*
|
|
814
|
-
* @module
|
|
815
|
-
*/
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* Durable Object namespace interface.
|
|
819
|
-
* This is Cloudflare-specific and used by the builder runtime.
|
|
820
|
-
*/
|
|
821
|
-
interface DurableObjectNamespace$1<T = unknown> {
|
|
822
|
-
idFromName(name: string): DurableObjectId;
|
|
823
|
-
idFromString(id: string): DurableObjectId;
|
|
824
|
-
newUniqueId(): DurableObjectId;
|
|
825
|
-
get(id: DurableObjectId): DurableObjectStub$1<T>;
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* Durable Object ID interface.
|
|
829
|
-
*/
|
|
830
|
-
interface DurableObjectId {
|
|
831
|
-
toString(): string;
|
|
832
|
-
equals(other: DurableObjectId): boolean;
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Durable Object stub interface.
|
|
836
|
-
* The generic type T represents the RPC methods available on the stub.
|
|
837
|
-
*/
|
|
838
|
-
type DurableObjectStub$1<T = unknown> = {
|
|
839
|
-
id: DurableObjectId;
|
|
840
|
-
name?: string;
|
|
841
|
-
fetch(request: Request | string, requestInitr?: RequestInit): Promise<Response>;
|
|
842
|
-
} & T;
|
|
843
|
-
/**
|
|
844
|
-
* Log entry from DurableThread.getLogs()
|
|
845
|
-
*/
|
|
846
|
-
interface LogEntry {
|
|
847
|
-
id: string;
|
|
848
|
-
message_id: string;
|
|
849
|
-
provider: string;
|
|
850
|
-
model: string;
|
|
851
|
-
model_name: string | null;
|
|
852
|
-
prompt_name: string | null;
|
|
853
|
-
tools_called: string | null;
|
|
854
|
-
parent_log_id: string | null;
|
|
855
|
-
retry_of_log_id: string | null;
|
|
856
|
-
error: string | null;
|
|
857
|
-
cost_total: number | null;
|
|
858
|
-
is_complete: number;
|
|
859
|
-
created_at: number;
|
|
860
|
-
request_body: string | null;
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* Response from getThreadMeta()
|
|
864
|
-
*/
|
|
865
|
-
interface ThreadMetaResponse {
|
|
866
|
-
thread: ThreadRegistryEntry$1;
|
|
867
|
-
agent: AgentDefinition$1 | null;
|
|
868
|
-
stats: {
|
|
869
|
-
messageCount: number;
|
|
870
|
-
logCount: number;
|
|
871
|
-
lastActivity: number | null;
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Log details returned by getLogDetails
|
|
876
|
-
*/
|
|
877
|
-
interface LogDetails {
|
|
878
|
-
id: string;
|
|
879
|
-
message_id: string;
|
|
880
|
-
provider: string;
|
|
881
|
-
actual_provider: string | null;
|
|
882
|
-
model: string;
|
|
883
|
-
model_name: string | null;
|
|
884
|
-
endpoint: string | null;
|
|
885
|
-
request_body: string | null;
|
|
886
|
-
request_headers: string | null;
|
|
887
|
-
response_body: string | null;
|
|
888
|
-
response_headers: string | null;
|
|
889
|
-
status_code: number | null;
|
|
890
|
-
reasoning_content: string | null;
|
|
891
|
-
input_tokens: number | null;
|
|
892
|
-
cached_tokens: number | null;
|
|
893
|
-
output_tokens: number | null;
|
|
894
|
-
reasoning_tokens: number | null;
|
|
895
|
-
total_tokens: number | null;
|
|
896
|
-
latency_ms: number | null;
|
|
897
|
-
time_to_first_token_ms: number | null;
|
|
898
|
-
finish_reason: string | null;
|
|
899
|
-
error: string | null;
|
|
900
|
-
error_type: string | null;
|
|
901
|
-
cost_input: number | null;
|
|
902
|
-
cost_output: number | null;
|
|
903
|
-
cost_total: number | null;
|
|
904
|
-
message_history_length: number | null;
|
|
905
|
-
tools_available: number | null;
|
|
906
|
-
prompt_name: string | null;
|
|
907
|
-
tools_called: string | null;
|
|
908
|
-
provider_tools: string | null;
|
|
909
|
-
parent_log_id: string | null;
|
|
910
|
-
tools_schema: string | null;
|
|
911
|
-
system_prompt: string | null;
|
|
912
|
-
errors: string | null;
|
|
913
|
-
retry_of_log_id: string | null;
|
|
914
|
-
tool_results: string | null;
|
|
915
|
-
is_complete: number;
|
|
916
|
-
created_at: number;
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* RPC methods exposed by DurableThread for external callers.
|
|
920
|
-
*/
|
|
921
|
-
interface DurableThreadRpc {
|
|
922
|
-
stop(): Promise<Response>;
|
|
923
|
-
getMessages(limit?: number, offset?: number, order?: "ASC" | "DESC", includeSilent?: boolean, maxDepth?: number): Promise<{
|
|
924
|
-
messages: unknown[];
|
|
925
|
-
total: number;
|
|
926
|
-
hasMore: boolean;
|
|
927
|
-
}>;
|
|
928
|
-
deleteMessage(messageId: string): Promise<{
|
|
929
|
-
success: boolean;
|
|
930
|
-
error?: string;
|
|
931
|
-
}>;
|
|
932
|
-
updateMessageContent(messageId: string, content: string): Promise<{
|
|
933
|
-
success: boolean;
|
|
934
|
-
error?: string;
|
|
935
|
-
}>;
|
|
936
|
-
getLogs(limit?: number, offset?: number, order?: "ASC" | "DESC"): Promise<{
|
|
937
|
-
logs: LogEntry[];
|
|
938
|
-
total: number;
|
|
939
|
-
hasMore: boolean;
|
|
940
|
-
}>;
|
|
941
|
-
getLogDetails(logId: string): Promise<LogDetails | null>;
|
|
942
|
-
getThreadMeta(threadId: string): Promise<ThreadMetaResponse | null>;
|
|
943
|
-
deleteThread(): Promise<void>;
|
|
944
|
-
readFile(path: string): Promise<{
|
|
945
|
-
success: boolean;
|
|
946
|
-
data?: string;
|
|
947
|
-
error?: string;
|
|
948
|
-
}>;
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Thread registry entry from DurableAgentBuilder.
|
|
952
|
-
*/
|
|
953
|
-
interface ThreadRegistryEntry$1 {
|
|
954
|
-
id: string;
|
|
955
|
-
agent_name: string;
|
|
956
|
-
user_id: string | null;
|
|
957
|
-
tags: string[] | null;
|
|
958
|
-
created_at: number;
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* RPC methods exposed by DurableAgentBuilder for external callers.
|
|
962
|
-
*/
|
|
963
|
-
interface DurableAgentBuilderRpc {
|
|
964
|
-
createThread(params: {
|
|
965
|
-
agent_name: string;
|
|
966
|
-
user_id?: string;
|
|
967
|
-
tags?: string[];
|
|
968
|
-
tenvs?: Record<string, unknown>;
|
|
969
|
-
properties?: Record<string, unknown>;
|
|
970
|
-
}): Promise<ThreadRegistryEntry$1>;
|
|
971
|
-
getThread(threadId: string): Promise<ThreadRegistryEntry$1 | null>;
|
|
972
|
-
listThreads(params?: {
|
|
973
|
-
agent_name?: string;
|
|
974
|
-
user_id?: string;
|
|
975
|
-
search?: string;
|
|
976
|
-
startDate?: number;
|
|
977
|
-
endDate?: number;
|
|
978
|
-
limit?: number;
|
|
979
|
-
offset?: number;
|
|
980
|
-
}): Promise<{
|
|
981
|
-
threads: ThreadRegistryEntry$1[];
|
|
982
|
-
total: number;
|
|
983
|
-
}>;
|
|
984
|
-
deleteThread(threadId: string): Promise<void>;
|
|
985
|
-
getUserByUsername(username: string): Promise<unknown>;
|
|
986
|
-
createSession(session: {
|
|
987
|
-
user_id: string;
|
|
988
|
-
token_hash: string;
|
|
989
|
-
expires_at: number;
|
|
990
|
-
}): Promise<void>;
|
|
991
|
-
loadAgent(name: string): Promise<AgentDefinition$1>;
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* Minimum required environment bindings for thread endpoints.
|
|
995
|
-
* User's Env interface should extend this.
|
|
996
|
-
*
|
|
997
|
-
* This is Cloudflare-specific and used by the builder runtime.
|
|
998
|
-
*/
|
|
999
|
-
interface ThreadEnv {
|
|
1000
|
-
AGENT_BUILDER_THREAD: DurableObjectNamespace$1<DurableThreadRpc>;
|
|
1001
|
-
AGENT_BUILDER: DurableObjectNamespace$1<DurableAgentBuilderRpc>;
|
|
1002
|
-
[key: string]: unknown;
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Builder-specific controller context with typed env.
|
|
1006
|
-
*
|
|
1007
|
-
* This extends the spec's ControllerContext with proper typing for
|
|
1008
|
-
* Cloudflare environment bindings.
|
|
1009
|
-
*/
|
|
1010
|
-
interface BuilderControllerContext<Env extends ThreadEnv = ThreadEnv> extends Omit<ControllerContext, 'env'> {
|
|
1011
|
-
env: Env;
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* Builder-specific controller type with typed env.
|
|
1015
|
-
*/
|
|
1016
|
-
type BuilderController<Env extends ThreadEnv = ThreadEnv> = (context: BuilderControllerContext<Env>) => ReturnType<Controller>;
|
|
1017
|
-
/**
|
|
1018
|
-
* Thread endpoint context with access to thread instance and metadata.
|
|
1019
|
-
* @deprecated Use ThreadState instead
|
|
1020
|
-
*/
|
|
1021
|
-
interface ThreadEndpointContext {
|
|
1022
|
-
req: Request;
|
|
1023
|
-
thread: {
|
|
1024
|
-
instance: ThreadInstance;
|
|
1025
|
-
metadata: ThreadMetadata;
|
|
1026
|
-
};
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Handler function for builder thread endpoints.
|
|
1030
|
-
*
|
|
1031
|
-
* Receives the request and a ThreadState object per the Standard Agents spec.
|
|
1032
|
-
* The ThreadState provides access to thread identity, messages, logs,
|
|
1033
|
-
* resource loading, tool invocation, and more.
|
|
1034
|
-
*
|
|
1035
|
-
* Note: `state.execution` is always null in endpoints since the thread
|
|
1036
|
-
* is not actively executing.
|
|
1037
|
-
*/
|
|
1038
|
-
type BuilderThreadEndpointHandler = ThreadEndpointHandler;
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* Define a controller with typed Cloudflare environment bindings.
|
|
1042
|
-
*
|
|
1043
|
-
* This is the builder's version of defineController that provides
|
|
1044
|
-
* proper typing for AGENT_BUILDER_THREAD and other CF bindings.
|
|
1045
|
-
*
|
|
1046
|
-
* @example
|
|
1047
|
-
* ```typescript
|
|
1048
|
-
* import { defineController } from '../router/index.js';
|
|
1049
|
-
*
|
|
1050
|
-
* export default defineController(async ({ req, env }) => {
|
|
1051
|
-
* const stub = env.AGENT_BUILDER.get(env.AGENT_BUILDER.idFromName('singleton'));
|
|
1052
|
-
* // ...
|
|
1053
|
-
* });
|
|
1054
|
-
* ```
|
|
1055
|
-
*/
|
|
1056
|
-
declare function defineController<Env extends ThreadEnv = ThreadEnv>(controller: BuilderController<Env>): BuilderController<Env>;
|
|
1057
|
-
/**
|
|
1058
|
-
* Runtime implementation for defineThreadEndpoint.
|
|
1059
|
-
*
|
|
1060
|
-
* This wraps the spec's defineThreadEndpoint to provide the actual
|
|
1061
|
-
* thread lookup and ThreadState creation at runtime.
|
|
1062
|
-
*
|
|
1063
|
-
* @param handler - Function that receives the request and ThreadState
|
|
1064
|
-
* @returns A Controller that can be used with the router
|
|
1065
|
-
*
|
|
1066
|
-
* @example
|
|
1067
|
-
* // agentbuilder/api/threads/[id]/status.get.ts
|
|
1068
|
-
* import { defineThreadEndpoint } from '@standardagents/spec';
|
|
1069
|
-
*
|
|
1070
|
-
* export default defineThreadEndpoint(async (req, state) => {
|
|
1071
|
-
* const { messages } = await state.getMessages({ limit: 1 });
|
|
1072
|
-
* return Response.json({ status: "ok", messageCount: messages.length });
|
|
1073
|
-
* });
|
|
1074
|
-
*/
|
|
1075
|
-
declare function createThreadEndpointHandler<Env extends ThreadEnv = ThreadEnv>(handler: ThreadEndpointHandler): BuilderController<Env>;
|
|
1076
|
-
|
|
1077
89
|
/**
|
|
1078
90
|
* Authentication middleware for protecting API routes
|
|
1079
91
|
*
|
|
@@ -1179,8 +191,19 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1179
191
|
* @returns Record of effect name to effect loader function
|
|
1180
192
|
*/
|
|
1181
193
|
effects(): Record<string, () => Promise<any>>;
|
|
194
|
+
/**
|
|
195
|
+
* Returns the namespaced registry for packed agent support.
|
|
196
|
+
* This method is implemented when you import DurableThread from 'virtual:@standardagents/builder'.
|
|
197
|
+
*
|
|
198
|
+
* @throws Error if not implemented in a subclass
|
|
199
|
+
* @returns The namespaced registry with global and packages namespaces
|
|
200
|
+
*/
|
|
201
|
+
registry(): any;
|
|
1182
202
|
/**
|
|
1183
203
|
* Load a model definition by name.
|
|
204
|
+
* Supports both global models and packed models (e.g., "packageId/modelName").
|
|
205
|
+
* For scoped packages, use "@scope/pkg/modelName".
|
|
206
|
+
* For packed context, tries package first then falls back to global.
|
|
1184
207
|
*/
|
|
1185
208
|
loadModel(name: string): Promise<any>;
|
|
1186
209
|
/**
|
|
@@ -1189,6 +212,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1189
212
|
getModelNames(): string[];
|
|
1190
213
|
/**
|
|
1191
214
|
* Load a prompt definition by name.
|
|
215
|
+
* Supports both global prompts (e.g., "my-prompt") and packed prompts (e.g., "packageId/promptName").
|
|
1192
216
|
*/
|
|
1193
217
|
loadPrompt(name: string): Promise<any>;
|
|
1194
218
|
/**
|
|
@@ -1197,6 +221,8 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1197
221
|
getPromptNames(): string[];
|
|
1198
222
|
/**
|
|
1199
223
|
* Load an agent definition by name.
|
|
224
|
+
* Supports both global agents (e.g., "my-agent") and packed agents (e.g., "packageId/agentName").
|
|
225
|
+
* For scoped packages, use "@scope/pkg/agentName".
|
|
1200
226
|
*/
|
|
1201
227
|
loadAgent(name: string): Promise<any>;
|
|
1202
228
|
/**
|
|
@@ -1211,6 +237,11 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1211
237
|
* List available effect names.
|
|
1212
238
|
*/
|
|
1213
239
|
getEffectNames(): string[];
|
|
240
|
+
/**
|
|
241
|
+
* Load a tool definition by name.
|
|
242
|
+
* Supports both global tools (e.g., "my_tool") and packed tools (e.g., "packageId/toolName").
|
|
243
|
+
*/
|
|
244
|
+
loadTool(name: string): Promise<any>;
|
|
1214
245
|
/**
|
|
1215
246
|
* Get thread metadata from DurableAgentBuilder.
|
|
1216
247
|
* Used for creating ThreadState outside of flow execution.
|
|
@@ -2002,6 +1033,11 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
2002
1033
|
* Must be overridden in a subclass.
|
|
2003
1034
|
*/
|
|
2004
1035
|
agents(): Record<string, () => Promise<any>>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Returns the namespaced registry for packed agent support.
|
|
1038
|
+
* Must be overridden in a subclass.
|
|
1039
|
+
*/
|
|
1040
|
+
registry(): any;
|
|
2005
1041
|
private ensureMigrated;
|
|
2006
1042
|
private getCurrentVersion;
|
|
2007
1043
|
private runMigrations;
|
|
@@ -2066,6 +1102,8 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
2066
1102
|
getPromptNames(): string[];
|
|
2067
1103
|
/**
|
|
2068
1104
|
* Load an agent definition by name.
|
|
1105
|
+
* Supports both global agents (e.g., "my-agent") and packed agents (e.g., "packageId/agentName").
|
|
1106
|
+
* For scoped packages, use "@scope/pkg/agentName".
|
|
2069
1107
|
*/
|
|
2070
1108
|
loadAgent(name: string): Promise<any>;
|
|
2071
1109
|
/**
|
|
@@ -2315,7 +1353,7 @@ type PromptContent = string | PromptPart[];
|
|
|
2315
1353
|
/**
|
|
2316
1354
|
* Sub-prompt configuration with type-safe name references.
|
|
2317
1355
|
*/
|
|
2318
|
-
interface SubpromptConfig<T extends string = AgentBuilder.Callables> extends Omit<SubpromptConfig$
|
|
1356
|
+
interface SubpromptConfig<T extends string = AgentBuilder.Callables> extends Omit<SubpromptConfig$1<T>, 'name'> {
|
|
2319
1357
|
/** Name of the sub-prompt (type-safe with autocomplete) */
|
|
2320
1358
|
name: T;
|
|
2321
1359
|
}
|
|
@@ -2467,6 +1505,26 @@ interface AgentDefinition<N extends string = string> {
|
|
|
2467
1505
|
description?: string;
|
|
2468
1506
|
/** Icon URL or absolute path for the agent. */
|
|
2469
1507
|
icon?: string;
|
|
1508
|
+
/**
|
|
1509
|
+
* npm package name for this agent when packed.
|
|
1510
|
+
* Preserved through unpack → edit → pack cycles.
|
|
1511
|
+
*/
|
|
1512
|
+
packageName?: string;
|
|
1513
|
+
/**
|
|
1514
|
+
* Package version (semver format).
|
|
1515
|
+
* Preserved through unpack → edit → pack cycles.
|
|
1516
|
+
*/
|
|
1517
|
+
version?: string;
|
|
1518
|
+
/**
|
|
1519
|
+
* Package author/copyright holder.
|
|
1520
|
+
* Preserved through unpack → edit → pack cycles.
|
|
1521
|
+
*/
|
|
1522
|
+
author?: string;
|
|
1523
|
+
/**
|
|
1524
|
+
* License identifier (SPDX format).
|
|
1525
|
+
* Preserved through unpack → edit → pack cycles.
|
|
1526
|
+
*/
|
|
1527
|
+
license?: string;
|
|
2470
1528
|
}
|
|
2471
1529
|
|
|
2472
1530
|
/**
|
|
@@ -2613,9 +1671,13 @@ interface InjectMessageOptions$1 {
|
|
|
2613
1671
|
* This adds a tool call to the execution queue without immediately executing it.
|
|
2614
1672
|
* The tool will be executed as part of the normal flow processing.
|
|
2615
1673
|
*
|
|
1674
|
+
* If the current tool has a `uses` list defined, the toolName must be in that list.
|
|
1675
|
+
* This enforces namespace isolation for packed agents.
|
|
1676
|
+
*
|
|
2616
1677
|
* @param flow - The current FlowState
|
|
2617
1678
|
* @param toolName - The name of the tool to call
|
|
2618
1679
|
* @param args - The arguments to pass to the tool
|
|
1680
|
+
* @throws Error if toolName is not in the current tool's uses list (when defined)
|
|
2619
1681
|
*
|
|
2620
1682
|
* @example
|
|
2621
1683
|
* ```typescript
|
|
@@ -3654,4 +2716,148 @@ type ProviderImagePart = ImagePart;
|
|
|
3654
2716
|
/** @public Alias for FilePart */
|
|
3655
2717
|
type ProviderFilePart = FilePart;
|
|
3656
2718
|
|
|
3657
|
-
|
|
2719
|
+
/**
|
|
2720
|
+
* Namespace-scoped resolution for the packing system.
|
|
2721
|
+
*
|
|
2722
|
+
* This module provides functions to resolve items (tools, prompts, models, agents)
|
|
2723
|
+
* within the correct namespace context, enforcing isolation between packed and
|
|
2724
|
+
* unpacked code.
|
|
2725
|
+
*
|
|
2726
|
+
* @module
|
|
2727
|
+
*/
|
|
2728
|
+
|
|
2729
|
+
/**
|
|
2730
|
+
* Error thrown when an item cannot be resolved in the current namespace.
|
|
2731
|
+
*/
|
|
2732
|
+
declare class NamespaceResolutionError extends Error {
|
|
2733
|
+
readonly itemType: 'tool' | 'prompt' | 'model' | 'agent' | 'hook';
|
|
2734
|
+
readonly itemName: string;
|
|
2735
|
+
readonly namespace: NamespaceContext;
|
|
2736
|
+
constructor(itemType: 'tool' | 'prompt' | 'model' | 'agent' | 'hook', itemName: string, namespace: NamespaceContext, message: string);
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Parse a potentially qualified name into package ID and short name.
|
|
2740
|
+
*
|
|
2741
|
+
* For scoped npm packages (starting with @), the format is @scope/pkg-name/item-name
|
|
2742
|
+
* where @scope/pkg-name is the package and item-name is the short name.
|
|
2743
|
+
*
|
|
2744
|
+
* For non-scoped packages, the format is pkg-name/item-name.
|
|
2745
|
+
*
|
|
2746
|
+
* @param name - The name to parse (e.g., 'tool', 'pkg/tool', or '@scope/pkg/tool')
|
|
2747
|
+
* @returns Tuple of [packageId, shortName] where packageId is null for unqualified names
|
|
2748
|
+
*/
|
|
2749
|
+
declare function parseQualifiedName(name: string): [string | null, string];
|
|
2750
|
+
/**
|
|
2751
|
+
* Create a qualified name from package ID and short name.
|
|
2752
|
+
*/
|
|
2753
|
+
declare function qualifyName(packageId: string, shortName: string): string;
|
|
2754
|
+
/**
|
|
2755
|
+
* Get the short name (strip any package qualification).
|
|
2756
|
+
*/
|
|
2757
|
+
declare function getShortName(name: string): string;
|
|
2758
|
+
/**
|
|
2759
|
+
* Resolve a tool by name within a namespace context.
|
|
2760
|
+
*
|
|
2761
|
+
* Resolution rules:
|
|
2762
|
+
* - Qualified names (pkg:tool) → resolve cross-package entry point
|
|
2763
|
+
* - Unqualified names in packed context → resolve from own package
|
|
2764
|
+
* - Unqualified names in global context → resolve from global namespace
|
|
2765
|
+
*
|
|
2766
|
+
* @param registry - The namespaced registry
|
|
2767
|
+
* @param name - Tool name (can be qualified with packageId:toolName)
|
|
2768
|
+
* @param namespace - Current namespace context
|
|
2769
|
+
* @returns Loader function for the tool definition
|
|
2770
|
+
* @throws NamespaceResolutionError if tool cannot be found or accessed
|
|
2771
|
+
*/
|
|
2772
|
+
declare function resolveTool(registry: NamespacedRegistry, name: string, namespace: NamespaceContext): DefinitionLoader<unknown>;
|
|
2773
|
+
/**
|
|
2774
|
+
* Resolve a prompt by name within a namespace context.
|
|
2775
|
+
*
|
|
2776
|
+
* @param registry - The namespaced registry
|
|
2777
|
+
* @param name - Prompt name (can be qualified)
|
|
2778
|
+
* @param namespace - Current namespace context
|
|
2779
|
+
* @returns Loader function for the prompt definition
|
|
2780
|
+
*/
|
|
2781
|
+
declare function resolvePrompt(registry: NamespacedRegistry, name: string, namespace: NamespaceContext): DefinitionLoader<unknown>;
|
|
2782
|
+
/**
|
|
2783
|
+
* Resolve a model by name within a namespace context.
|
|
2784
|
+
*
|
|
2785
|
+
* Models are special: packed agents include their model definitions,
|
|
2786
|
+
* but the host must provide API keys.
|
|
2787
|
+
*
|
|
2788
|
+
* @param registry - The namespaced registry
|
|
2789
|
+
* @param name - Model name
|
|
2790
|
+
* @param namespace - Current namespace context
|
|
2791
|
+
* @returns Loader function for the model definition
|
|
2792
|
+
*/
|
|
2793
|
+
declare function resolveModel(registry: NamespacedRegistry, name: string, namespace: NamespaceContext): DefinitionLoader<unknown>;
|
|
2794
|
+
/**
|
|
2795
|
+
* Resolve an agent by name within a namespace context.
|
|
2796
|
+
*
|
|
2797
|
+
* Resolution rules:
|
|
2798
|
+
* - Qualified names (pkg:agent) → resolve cross-package entry point
|
|
2799
|
+
* - Unqualified in packed → resolve from own package
|
|
2800
|
+
* - Unqualified in global → resolve from global + entry points
|
|
2801
|
+
*
|
|
2802
|
+
* @param registry - The namespaced registry
|
|
2803
|
+
* @param name - Agent name (can be qualified)
|
|
2804
|
+
* @param namespace - Current namespace context
|
|
2805
|
+
* @returns Loader function for the agent definition
|
|
2806
|
+
*/
|
|
2807
|
+
declare function resolveAgent(registry: NamespacedRegistry, name: string, namespace: NamespaceContext): DefinitionLoader<unknown>;
|
|
2808
|
+
/**
|
|
2809
|
+
* Resolve a hook by name within a namespace context.
|
|
2810
|
+
*
|
|
2811
|
+
* Hooks follow similar rules to tools but are keyed by hook type.
|
|
2812
|
+
*
|
|
2813
|
+
* @param registry - The namespaced registry
|
|
2814
|
+
* @param name - Hook name (file name, e.g., 'filter_messages')
|
|
2815
|
+
* @param namespace - Current namespace context
|
|
2816
|
+
* @returns Loader function for the hook implementation
|
|
2817
|
+
*/
|
|
2818
|
+
declare function resolveHook(registry: NamespacedRegistry, name: string, namespace: NamespaceContext): DefinitionLoader<unknown> | null;
|
|
2819
|
+
/**
|
|
2820
|
+
* Get all tool names visible in a namespace context.
|
|
2821
|
+
*
|
|
2822
|
+
* @param registry - The namespaced registry
|
|
2823
|
+
* @param namespace - Current namespace context
|
|
2824
|
+
* @returns Array of visible tool names (short names)
|
|
2825
|
+
*/
|
|
2826
|
+
declare function getVisibleToolNames(registry: NamespacedRegistry, namespace: NamespaceContext): string[];
|
|
2827
|
+
/**
|
|
2828
|
+
* Get all agent names visible in a namespace context.
|
|
2829
|
+
*
|
|
2830
|
+
* @param registry - The namespaced registry
|
|
2831
|
+
* @param namespace - Current namespace context
|
|
2832
|
+
* @returns Array of visible agent names (may include qualified names for cross-package)
|
|
2833
|
+
*/
|
|
2834
|
+
declare function getVisibleAgentNames(registry: NamespacedRegistry, namespace: NamespaceContext): string[];
|
|
2835
|
+
/**
|
|
2836
|
+
* Get all prompt names visible in a namespace context.
|
|
2837
|
+
*/
|
|
2838
|
+
declare function getVisiblePromptNames(registry: NamespacedRegistry, namespace: NamespaceContext): string[];
|
|
2839
|
+
/**
|
|
2840
|
+
* Get all model names visible in a namespace context.
|
|
2841
|
+
*/
|
|
2842
|
+
declare function getVisibleModelNames(registry: NamespacedRegistry, namespace: NamespaceContext): string[];
|
|
2843
|
+
/**
|
|
2844
|
+
* Create a namespace context for an agent definition.
|
|
2845
|
+
*
|
|
2846
|
+
* @param agentDef - Agent definition (may have __package field)
|
|
2847
|
+
* @returns Appropriate namespace context
|
|
2848
|
+
*/
|
|
2849
|
+
declare function createNamespaceContext(agentDef: {
|
|
2850
|
+
__package?: {
|
|
2851
|
+
packageId: string;
|
|
2852
|
+
};
|
|
2853
|
+
} | undefined): NamespaceContext;
|
|
2854
|
+
/**
|
|
2855
|
+
* Check if a name is qualified (contains package prefix).
|
|
2856
|
+
*
|
|
2857
|
+
* For scoped packages (@scope/name), there must be at least two slashes
|
|
2858
|
+
* to be considered qualified (e.g., @scope/pkg/item).
|
|
2859
|
+
* For non-scoped packages, a single slash qualifies it (e.g., pkg/item).
|
|
2860
|
+
*/
|
|
2861
|
+
declare function isQualifiedName(name: string): boolean;
|
|
2862
|
+
|
|
2863
|
+
export { type AgentBuilderEnv, type AgentDefinition, AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, DurableAgentBuilder, DurableThread, FileRecord, FileStats, FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, GrepResult, type ImageContextConfig, type InjectMessageOptions$1 as InjectMessageOptions, type Provider as LLMProviderInterface, Message, MessageContent, type ModelDefinition, NamespaceResolutionError, NamespacedRegistry, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptPart, type Provider$1 as Provider, type ProviderContentPart, type ProviderFilePart, type ProviderImagePart, type ProviderTextPart, type SideConfig, type SubpromptConfig, ThreadEnv, ThreadMetadata, type ThreadRegistryEntry, type ToolConfig, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, createNamespaceContext, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isQualifiedName, linkFile, mkdir, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
|