@standardagents/builder 0.11.0-next.af971ae → 0.11.0
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 +21823 -317
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +26 -23
- package/dist/client/vendor.js +1 -1
- package/dist/client/vue.js +1 -1
- package/dist/index.d.ts +333 -44
- package/dist/index.js +3347 -1112
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +375 -67
- package/dist/plugin.js.map +1 -1
- package/dist/sip.wasm +0 -0
- package/package.json +8 -6
- 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,8 +1,8 @@
|
|
|
1
1
|
export { AgentPluginOptions, agentbuilder } from './plugin.js';
|
|
2
2
|
import { DurableObjectStorage } from '@cloudflare/workers-types';
|
|
3
3
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
4
|
-
import { ToolResult as ToolResult$1, HookSignatures, ControllerContext, Controller, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, SubpromptConfig as SubpromptConfig$2, ReasoningConfig, SideConfig as SideConfig$1 } from '@standardagents/spec';
|
|
5
|
-
export { AgentType, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, PromptInput, PromptTextPart, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, defineAgent, defineHook, defineModel, definePrompt,
|
|
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';
|
|
6
6
|
import { DurableObject } from 'cloudflare:workers';
|
|
7
7
|
import 'vite';
|
|
8
8
|
|
|
@@ -13,63 +13,71 @@ import 'vite';
|
|
|
13
13
|
* Types are automatically populated when you run `pnpm dev` or `pnpm build`,
|
|
14
14
|
* which scans your `agentbuilder/` directories and generates types.
|
|
15
15
|
*
|
|
16
|
-
* The generated types are placed in `.
|
|
16
|
+
* The generated types are placed in `.agents/types.d.ts` and augment the
|
|
17
|
+
* StandardAgentSpec namespace from @standardagents/spec.
|
|
17
18
|
*
|
|
18
|
-
* Note:
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* Note: This namespace is provided for backward compatibility. New code should
|
|
20
|
+
* use StandardAgentSpec types directly, which are defined in @standardagents/spec.
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use StandardAgentSpec namespace from @standardagents/spec instead
|
|
21
23
|
*/
|
|
22
24
|
declare global {
|
|
23
25
|
namespace AgentBuilder {
|
|
24
26
|
/**
|
|
25
27
|
* Interface for model type registration.
|
|
26
|
-
*
|
|
27
|
-
* This gives us: type Models = keyof ModelRegistry = 'gpt-4o' | 'claude-3'
|
|
28
|
+
* @deprecated Use StandardAgentSpec.ModelRegistry instead
|
|
28
29
|
*/
|
|
29
|
-
interface ModelRegistry {
|
|
30
|
+
interface ModelRegistry extends StandardAgentSpec.ModelRegistry {
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Interface for prompt type registration.
|
|
34
|
+
* @deprecated Use StandardAgentSpec.PromptRegistry instead
|
|
33
35
|
*/
|
|
34
|
-
interface PromptRegistry {
|
|
36
|
+
interface PromptRegistry extends StandardAgentSpec.PromptRegistry {
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Interface for agent type registration.
|
|
40
|
+
* @deprecated Use StandardAgentSpec.AgentRegistry instead
|
|
38
41
|
*/
|
|
39
|
-
interface AgentRegistry {
|
|
42
|
+
interface AgentRegistry extends StandardAgentSpec.AgentRegistry {
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* Interface for tool type registration.
|
|
46
|
+
* @deprecated Use StandardAgentSpec.ToolRegistry instead
|
|
43
47
|
*/
|
|
44
|
-
interface ToolRegistry {
|
|
48
|
+
interface ToolRegistry extends StandardAgentSpec.ToolRegistry {
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Interface for callable type registration (prompts, agents, tools).
|
|
52
|
+
* @deprecated Use StandardAgentSpec.CallableRegistry instead
|
|
48
53
|
*/
|
|
49
|
-
interface CallableRegistry {
|
|
54
|
+
interface CallableRegistry extends StandardAgentSpec.CallableRegistry {
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Union type of all model names defined in agentbuilder/models/.
|
|
53
|
-
*
|
|
54
|
-
* When populated, it narrows to the specific model names.
|
|
58
|
+
* @deprecated Use StandardAgentSpec.Models instead
|
|
55
59
|
*/
|
|
56
|
-
type Models =
|
|
60
|
+
type Models = StandardAgentSpec.Models;
|
|
57
61
|
/**
|
|
58
62
|
* Union type of all prompt names defined in agentbuilder/prompts/.
|
|
63
|
+
* @deprecated Use StandardAgentSpec.Prompts instead
|
|
59
64
|
*/
|
|
60
|
-
type Prompts =
|
|
65
|
+
type Prompts = StandardAgentSpec.Prompts;
|
|
61
66
|
/**
|
|
62
67
|
* Union type of all agent names defined in agentbuilder/agents/.
|
|
68
|
+
* @deprecated Use StandardAgentSpec.Agents instead
|
|
63
69
|
*/
|
|
64
|
-
type Agents =
|
|
70
|
+
type Agents = StandardAgentSpec.Agents;
|
|
65
71
|
/**
|
|
66
72
|
* Union type of all tool names defined in agentbuilder/tools/.
|
|
73
|
+
* @deprecated Use StandardAgentSpec.Tools instead
|
|
67
74
|
*/
|
|
68
|
-
type Tools =
|
|
75
|
+
type Tools = StandardAgentSpec.Tools;
|
|
69
76
|
/**
|
|
70
77
|
* Union type of all callable items (prompts, agents, tools) that can be used as tools.
|
|
78
|
+
* @deprecated Use StandardAgentSpec.Callables instead
|
|
71
79
|
*/
|
|
72
|
-
type Callables =
|
|
80
|
+
type Callables = StandardAgentSpec.Callables;
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
|
|
@@ -213,6 +221,8 @@ interface ThreadMetadata {
|
|
|
213
221
|
id: string;
|
|
214
222
|
agent_id: string;
|
|
215
223
|
user_id: string | null;
|
|
224
|
+
tenvs: Record<string, unknown> | null;
|
|
225
|
+
properties: Record<string, unknown> | null;
|
|
216
226
|
created_at: number;
|
|
217
227
|
}
|
|
218
228
|
/**
|
|
@@ -226,7 +236,26 @@ type HookRegistry = {
|
|
|
226
236
|
* Tools can have args (with validation schema) or no args.
|
|
227
237
|
* Uses local Zod types for compatibility with z.toJSONSchema().
|
|
228
238
|
*/
|
|
229
|
-
|
|
239
|
+
interface NativeToolModule {
|
|
240
|
+
/** Description of what the tool does (shown to the LLM). */
|
|
241
|
+
description: string;
|
|
242
|
+
/** Zod schema for validating tool arguments, or null for no args. */
|
|
243
|
+
args: ZodObject<ZodRawShape> | null;
|
|
244
|
+
/** The tool implementation function. */
|
|
245
|
+
execute: ((state: any, args: Record<string, unknown>) => Promise<ToolResult$1>) | ((state: any) => Promise<ToolResult$1>);
|
|
246
|
+
/** Zod schema for thread environment variables, or null if none. */
|
|
247
|
+
tenvs?: ZodObject<ZodRawShape> | null;
|
|
248
|
+
/**
|
|
249
|
+
* Where this tool is executed:
|
|
250
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
251
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
252
|
+
*/
|
|
253
|
+
executionMode?: 'local' | 'provider';
|
|
254
|
+
/**
|
|
255
|
+
* Which provider executes this tool (when executionMode='provider').
|
|
256
|
+
*/
|
|
257
|
+
executionProvider?: string;
|
|
258
|
+
}
|
|
230
259
|
/**
|
|
231
260
|
* Thread instance (forward reference to avoid circular dependency)
|
|
232
261
|
*/
|
|
@@ -240,6 +269,10 @@ interface ThreadInstance {
|
|
|
240
269
|
}>;
|
|
241
270
|
getLogs(limit?: number, offset?: number, order?: "asc" | "desc"): Promise<LogData[]>;
|
|
242
271
|
getThreadMeta(threadId: string): Promise<ThreadMetadata | null>;
|
|
272
|
+
deleteMessage(messageId: string): Promise<{
|
|
273
|
+
success: boolean;
|
|
274
|
+
error?: string;
|
|
275
|
+
}>;
|
|
243
276
|
shouldStop(): Promise<boolean>;
|
|
244
277
|
tools(): Record<string, () => Promise<NativeToolModule>>;
|
|
245
278
|
hooks(): HookRegistry;
|
|
@@ -249,7 +282,11 @@ interface ThreadInstance {
|
|
|
249
282
|
getPromptNames(): string[];
|
|
250
283
|
getAgentNames(): string[];
|
|
251
284
|
writeFile(path: string, data: ArrayBuffer | string, mimeType: string, options?: Record<string, unknown>): Promise<any>;
|
|
252
|
-
readFile(path: string): Promise<
|
|
285
|
+
readFile(path: string): Promise<{
|
|
286
|
+
success: boolean;
|
|
287
|
+
data?: string;
|
|
288
|
+
error?: string;
|
|
289
|
+
}>;
|
|
253
290
|
statFile(path: string): Promise<any>;
|
|
254
291
|
readdirFile(path: string): Promise<any[]>;
|
|
255
292
|
unlinkFile(path: string): Promise<void>;
|
|
@@ -264,6 +301,16 @@ interface ThreadInstance {
|
|
|
264
301
|
data?: string;
|
|
265
302
|
error?: string;
|
|
266
303
|
}>;
|
|
304
|
+
runAgent(threadId: string, agentName: string): Promise<void>;
|
|
305
|
+
scheduleEffect(threadId: string, effectName: string, effectArgs: Record<string, unknown>, delayMs?: number): Promise<string>;
|
|
306
|
+
getScheduledEffects(name?: string): Promise<Array<{
|
|
307
|
+
id: string;
|
|
308
|
+
name: string;
|
|
309
|
+
args: Record<string, unknown>;
|
|
310
|
+
scheduledAt: number;
|
|
311
|
+
createdAt: number;
|
|
312
|
+
}>>;
|
|
313
|
+
removeScheduledEffect(id: string): Promise<boolean>;
|
|
267
314
|
insertOrphanedToolCall(params: {
|
|
268
315
|
content?: string;
|
|
269
316
|
toolCallId: string;
|
|
@@ -302,6 +349,7 @@ type FlowCallWithRetries = FlowCall & {
|
|
|
302
349
|
interface SubpromptConfig$1 {
|
|
303
350
|
name: string;
|
|
304
351
|
initUserMessageProperty?: string;
|
|
352
|
+
initAttachmentsProperty?: string;
|
|
305
353
|
includeTextResponse?: boolean;
|
|
306
354
|
includeToolCalls?: boolean;
|
|
307
355
|
includeErrors?: boolean;
|
|
@@ -392,6 +440,7 @@ interface FlowState {
|
|
|
392
440
|
depth: number;
|
|
393
441
|
pendingMessageId?: string;
|
|
394
442
|
allowedTools?: ToolDefinition[];
|
|
443
|
+
pendingMetadataPromises?: Promise<void>[];
|
|
395
444
|
}
|
|
396
445
|
/**
|
|
397
446
|
* Text content part for multimodal messages
|
|
@@ -428,6 +477,10 @@ interface RequestContext {
|
|
|
428
477
|
tool_calls?: ToolCall[];
|
|
429
478
|
tool_call_id?: string;
|
|
430
479
|
name?: string;
|
|
480
|
+
reasoning_content?: string;
|
|
481
|
+
reasoning_details?: any[];
|
|
482
|
+
attachments?: any[];
|
|
483
|
+
toolName?: string;
|
|
431
484
|
}>;
|
|
432
485
|
model: string;
|
|
433
486
|
tools?: ToolDefinition[];
|
|
@@ -459,6 +512,17 @@ interface ToolDefinition {
|
|
|
459
512
|
description: string;
|
|
460
513
|
parameters?: Record<string, any>;
|
|
461
514
|
};
|
|
515
|
+
/**
|
|
516
|
+
* Where this tool is executed:
|
|
517
|
+
* - 'local': Execute locally by the execution engine (default)
|
|
518
|
+
* - 'provider': Executed by the LLM provider, results come in response
|
|
519
|
+
*/
|
|
520
|
+
executionMode?: 'local' | 'provider';
|
|
521
|
+
/**
|
|
522
|
+
* Which provider executes this tool (when executionMode='provider')
|
|
523
|
+
* e.g., 'openai', 'anthropic'
|
|
524
|
+
*/
|
|
525
|
+
executionProvider?: string;
|
|
462
526
|
}
|
|
463
527
|
/**
|
|
464
528
|
* Image returned by an LLM response (e.g., from image generation models)
|
|
@@ -466,6 +530,12 @@ interface ToolDefinition {
|
|
|
466
530
|
*/
|
|
467
531
|
interface LLMResponseImage {
|
|
468
532
|
type: "image_url";
|
|
533
|
+
/** Unique ID for this generated image (used to link to tool call) */
|
|
534
|
+
id?: string;
|
|
535
|
+
/** Name of the tool that generated this image (e.g., 'image_generation') */
|
|
536
|
+
toolName?: string;
|
|
537
|
+
/** The revised/actual prompt used to generate the image (from OpenAI's image_generation) */
|
|
538
|
+
revisedPrompt?: string;
|
|
469
539
|
image_url: {
|
|
470
540
|
url: string;
|
|
471
541
|
};
|
|
@@ -495,6 +565,12 @@ interface LLMResponse {
|
|
|
495
565
|
cost?: number;
|
|
496
566
|
provider?: string;
|
|
497
567
|
};
|
|
568
|
+
/** @internal Provider instance reference for async metadata fetching */
|
|
569
|
+
_provider?: unknown;
|
|
570
|
+
/** @internal Provider response ID for async metadata fetching */
|
|
571
|
+
_providerResponseId?: string;
|
|
572
|
+
/** @internal Aggregate response for logging */
|
|
573
|
+
_aggregate_response?: unknown;
|
|
498
574
|
}
|
|
499
575
|
/**
|
|
500
576
|
* Attachment returned by a tool (e.g., generated images)
|
|
@@ -627,6 +703,7 @@ interface LogData {
|
|
|
627
703
|
tools_available?: number;
|
|
628
704
|
prompt_name?: string;
|
|
629
705
|
tools_called?: string;
|
|
706
|
+
actual_provider?: string | null;
|
|
630
707
|
parent_log_id?: string | null;
|
|
631
708
|
tools_schema?: string | null;
|
|
632
709
|
message_history?: string | null;
|
|
@@ -771,20 +848,6 @@ interface LogEntry {
|
|
|
771
848
|
created_at: number;
|
|
772
849
|
request_body: string | null;
|
|
773
850
|
}
|
|
774
|
-
/**
|
|
775
|
-
* Agent definition returned from loadAgent()
|
|
776
|
-
*/
|
|
777
|
-
interface AgentDefinition$1 {
|
|
778
|
-
name: string;
|
|
779
|
-
title?: string;
|
|
780
|
-
type?: string;
|
|
781
|
-
description?: string;
|
|
782
|
-
icon?: string;
|
|
783
|
-
defaultPrompt?: string;
|
|
784
|
-
defaultModel?: string;
|
|
785
|
-
tools?: string[];
|
|
786
|
-
[key: string]: unknown;
|
|
787
|
-
}
|
|
788
851
|
/**
|
|
789
852
|
* Response from getThreadMeta()
|
|
790
853
|
*/
|
|
@@ -797,6 +860,50 @@ interface ThreadMetaResponse {
|
|
|
797
860
|
lastActivity: number | null;
|
|
798
861
|
};
|
|
799
862
|
}
|
|
863
|
+
/**
|
|
864
|
+
* Log details returned by getLogDetails
|
|
865
|
+
*/
|
|
866
|
+
interface LogDetails {
|
|
867
|
+
id: string;
|
|
868
|
+
message_id: string;
|
|
869
|
+
provider: string;
|
|
870
|
+
actual_provider: string | null;
|
|
871
|
+
model: string;
|
|
872
|
+
model_name: string | null;
|
|
873
|
+
endpoint: string | null;
|
|
874
|
+
request_body: string | null;
|
|
875
|
+
request_headers: string | null;
|
|
876
|
+
response_body: string | null;
|
|
877
|
+
response_headers: string | null;
|
|
878
|
+
status_code: number | null;
|
|
879
|
+
reasoning_content: string | null;
|
|
880
|
+
input_tokens: number | null;
|
|
881
|
+
cached_tokens: number | null;
|
|
882
|
+
output_tokens: number | null;
|
|
883
|
+
reasoning_tokens: number | null;
|
|
884
|
+
total_tokens: number | null;
|
|
885
|
+
latency_ms: number | null;
|
|
886
|
+
time_to_first_token_ms: number | null;
|
|
887
|
+
finish_reason: string | null;
|
|
888
|
+
error: string | null;
|
|
889
|
+
error_type: string | null;
|
|
890
|
+
cost_input: number | null;
|
|
891
|
+
cost_output: number | null;
|
|
892
|
+
cost_total: number | null;
|
|
893
|
+
message_history_length: number | null;
|
|
894
|
+
tools_available: number | null;
|
|
895
|
+
prompt_name: string | null;
|
|
896
|
+
tools_called: string | null;
|
|
897
|
+
provider_tools: string | null;
|
|
898
|
+
parent_log_id: string | null;
|
|
899
|
+
tools_schema: string | null;
|
|
900
|
+
system_prompt: string | null;
|
|
901
|
+
errors: string | null;
|
|
902
|
+
retry_of_log_id: string | null;
|
|
903
|
+
tool_results: string | null;
|
|
904
|
+
is_complete: number;
|
|
905
|
+
created_at: number;
|
|
906
|
+
}
|
|
800
907
|
/**
|
|
801
908
|
* RPC methods exposed by DurableThread for external callers.
|
|
802
909
|
*/
|
|
@@ -820,9 +927,14 @@ interface DurableThreadRpc {
|
|
|
820
927
|
total: number;
|
|
821
928
|
hasMore: boolean;
|
|
822
929
|
}>;
|
|
823
|
-
getLogDetails(logId: string): Promise<
|
|
930
|
+
getLogDetails(logId: string): Promise<LogDetails | null>;
|
|
824
931
|
getThreadMeta(threadId: string): Promise<ThreadMetaResponse | null>;
|
|
825
932
|
deleteThread(): Promise<void>;
|
|
933
|
+
readFile(path: string): Promise<{
|
|
934
|
+
success: boolean;
|
|
935
|
+
data?: string;
|
|
936
|
+
error?: string;
|
|
937
|
+
}>;
|
|
826
938
|
}
|
|
827
939
|
/**
|
|
828
940
|
* Thread registry entry from DurableAgentBuilder.
|
|
@@ -842,11 +954,16 @@ interface DurableAgentBuilderRpc {
|
|
|
842
954
|
agent_name: string;
|
|
843
955
|
user_id?: string;
|
|
844
956
|
tags?: string[];
|
|
957
|
+
tenvs?: Record<string, unknown>;
|
|
958
|
+
properties?: Record<string, unknown>;
|
|
845
959
|
}): Promise<ThreadRegistryEntry$1>;
|
|
846
960
|
getThread(threadId: string): Promise<ThreadRegistryEntry$1 | null>;
|
|
847
961
|
listThreads(params?: {
|
|
848
962
|
agent_name?: string;
|
|
849
963
|
user_id?: string;
|
|
964
|
+
search?: string;
|
|
965
|
+
startDate?: number;
|
|
966
|
+
endDate?: number;
|
|
850
967
|
limit?: number;
|
|
851
968
|
offset?: number;
|
|
852
969
|
}): Promise<{
|
|
@@ -896,6 +1013,49 @@ interface ThreadEndpointContext {
|
|
|
896
1013
|
metadata: ThreadMetadata;
|
|
897
1014
|
};
|
|
898
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Handler function for builder thread endpoints.
|
|
1018
|
+
*
|
|
1019
|
+
* Unlike the spec's ThreadEndpointHandler which receives ThreadState,
|
|
1020
|
+
* the builder's handler receives direct access to the Durable Object
|
|
1021
|
+
* instance and thread metadata. This allows for lower-level operations
|
|
1022
|
+
* like calling RPC methods directly on the instance.
|
|
1023
|
+
*/
|
|
1024
|
+
type BuilderThreadEndpointHandler = (req: Request, context: {
|
|
1025
|
+
instance: ThreadInstance;
|
|
1026
|
+
metadata: ThreadMetadata;
|
|
1027
|
+
}) => Response | Promise<Response>;
|
|
1028
|
+
/**
|
|
1029
|
+
* Define a thread-specific endpoint with access to the Durable Object instance.
|
|
1030
|
+
*
|
|
1031
|
+
* This is the builder's version of defineThreadEndpoint. It provides direct
|
|
1032
|
+
* access to the thread's Durable Object instance and metadata, allowing
|
|
1033
|
+
* for lower-level operations like calling RPC methods directly.
|
|
1034
|
+
*
|
|
1035
|
+
* @param handler - Function that receives the request and thread context
|
|
1036
|
+
* @returns A Controller that can be used with the router
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```typescript
|
|
1040
|
+
* import { defineThreadEndpoint } from '@standardagents/builder';
|
|
1041
|
+
*
|
|
1042
|
+
* export default defineThreadEndpoint(async (req, { instance, metadata }) => {
|
|
1043
|
+
* // Access thread metadata
|
|
1044
|
+
* console.log('Thread ID:', metadata.id);
|
|
1045
|
+
* console.log('Agent ID:', metadata.agent_id);
|
|
1046
|
+
*
|
|
1047
|
+
* // Call RPC methods on the Durable Object instance
|
|
1048
|
+
* const messagesResult = await instance.getMessages();
|
|
1049
|
+
* const logs = await instance.getLogs();
|
|
1050
|
+
*
|
|
1051
|
+
* return Response.json({
|
|
1052
|
+
* messageCount: messagesResult.messages.length,
|
|
1053
|
+
* logCount: logs.length,
|
|
1054
|
+
* });
|
|
1055
|
+
* });
|
|
1056
|
+
* ```
|
|
1057
|
+
*/
|
|
1058
|
+
declare function defineThreadEndpoint(handler: BuilderThreadEndpointHandler): BuilderController;
|
|
899
1059
|
|
|
900
1060
|
/**
|
|
901
1061
|
* Define a controller with typed Cloudflare environment bindings.
|
|
@@ -1009,6 +1169,17 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1009
1169
|
* @returns Record of agent name to agent loader function
|
|
1010
1170
|
*/
|
|
1011
1171
|
agents(): Record<string, () => Promise<any>>;
|
|
1172
|
+
/**
|
|
1173
|
+
* Returns the effects registry for lazy-loading effect definitions.
|
|
1174
|
+
* This method is implemented when you import DurableThread from 'virtual:@standardagents/builder'.
|
|
1175
|
+
*
|
|
1176
|
+
* Effects are scheduled operations that run outside the tool execution context,
|
|
1177
|
+
* ideal for delayed notifications, webhooks, and cleanup tasks.
|
|
1178
|
+
*
|
|
1179
|
+
* @throws Error if not implemented in a subclass
|
|
1180
|
+
* @returns Record of effect name to effect loader function
|
|
1181
|
+
*/
|
|
1182
|
+
effects(): Record<string, () => Promise<any>>;
|
|
1012
1183
|
/**
|
|
1013
1184
|
* Load a model definition by name.
|
|
1014
1185
|
*/
|
|
@@ -1033,6 +1204,59 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1033
1204
|
* List available agent names.
|
|
1034
1205
|
*/
|
|
1035
1206
|
getAgentNames(): string[];
|
|
1207
|
+
/**
|
|
1208
|
+
* Load an effect definition by name.
|
|
1209
|
+
*/
|
|
1210
|
+
loadEffect(name: string): Promise<any>;
|
|
1211
|
+
/**
|
|
1212
|
+
* List available effect names.
|
|
1213
|
+
*/
|
|
1214
|
+
getEffectNames(): string[];
|
|
1215
|
+
/**
|
|
1216
|
+
* Get thread metadata from DurableAgentBuilder.
|
|
1217
|
+
* Used for creating ThreadState outside of flow execution.
|
|
1218
|
+
*/
|
|
1219
|
+
getThreadMetadata(threadId: string): Promise<ThreadMetadata>;
|
|
1220
|
+
/**
|
|
1221
|
+
* Trigger an agent to run on this thread.
|
|
1222
|
+
*
|
|
1223
|
+
* Queues an agent execution via the alarm queue. The execution
|
|
1224
|
+
* runs asynchronously in the background.
|
|
1225
|
+
*
|
|
1226
|
+
* @param threadId - Thread ID for the execution
|
|
1227
|
+
* @param agentName - Name of the agent to run
|
|
1228
|
+
*/
|
|
1229
|
+
runAgent(threadId: string, agentName: string): Promise<void>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Schedule an effect for future execution.
|
|
1232
|
+
*
|
|
1233
|
+
* @param threadId - Thread ID for the effect execution context
|
|
1234
|
+
* @param effectName - Name of the effect to schedule
|
|
1235
|
+
* @param effectArgs - Arguments to pass to the effect handler
|
|
1236
|
+
* @param delayMs - Delay in milliseconds before execution (default: 0)
|
|
1237
|
+
* @returns UUID of the scheduled effect
|
|
1238
|
+
*/
|
|
1239
|
+
scheduleEffect(threadId: string, effectName: string, effectArgs: Record<string, unknown>, delayMs?: number): Promise<string>;
|
|
1240
|
+
/**
|
|
1241
|
+
* Get scheduled effects for this thread.
|
|
1242
|
+
*
|
|
1243
|
+
* @param name - Optional effect name to filter by
|
|
1244
|
+
* @returns Array of scheduled effect records
|
|
1245
|
+
*/
|
|
1246
|
+
getScheduledEffects(name?: string): Promise<Array<{
|
|
1247
|
+
id: string;
|
|
1248
|
+
name: string;
|
|
1249
|
+
args: Record<string, unknown>;
|
|
1250
|
+
scheduledAt: number;
|
|
1251
|
+
createdAt: number;
|
|
1252
|
+
}>>;
|
|
1253
|
+
/**
|
|
1254
|
+
* Remove a scheduled effect.
|
|
1255
|
+
*
|
|
1256
|
+
* @param id - The effect ID returned by scheduleEffect
|
|
1257
|
+
* @returns true if the effect was found and removed, false otherwise
|
|
1258
|
+
*/
|
|
1259
|
+
removeScheduledEffect(id: string): Promise<boolean>;
|
|
1036
1260
|
/**
|
|
1037
1261
|
* Ensures the database schema is up to date.
|
|
1038
1262
|
* This method is called on the first request to the Durable Object.
|
|
@@ -1078,6 +1302,15 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1078
1302
|
* Simple "off" switch - stops turns, only cleared by user messages
|
|
1079
1303
|
*/
|
|
1080
1304
|
stop(): Promise<Response>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Continue execution from where it stopped (RPC method)
|
|
1307
|
+
* Useful for debugging - continues the FlowEngine with additional steps
|
|
1308
|
+
* without adding a new message.
|
|
1309
|
+
*
|
|
1310
|
+
* @param threadId The thread ID
|
|
1311
|
+
* @param side Which side to start from ('a' or 'b'), defaults to 'a'
|
|
1312
|
+
*/
|
|
1313
|
+
continueExecution(threadId: string, side?: 'a' | 'b'): Promise<Response>;
|
|
1081
1314
|
/**
|
|
1082
1315
|
* Get message history (RPC method)
|
|
1083
1316
|
*
|
|
@@ -1190,10 +1423,12 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1190
1423
|
id: string;
|
|
1191
1424
|
message_id: string;
|
|
1192
1425
|
provider: string;
|
|
1426
|
+
actual_provider: string | null;
|
|
1193
1427
|
model: string;
|
|
1194
1428
|
model_name: string | null;
|
|
1195
1429
|
prompt_name: string | null;
|
|
1196
1430
|
tools_called: string | null;
|
|
1431
|
+
provider_tools: string | null;
|
|
1197
1432
|
parent_log_id: string | null;
|
|
1198
1433
|
retry_of_log_id: string | null;
|
|
1199
1434
|
error: string | null;
|
|
@@ -1213,6 +1448,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1213
1448
|
id: string;
|
|
1214
1449
|
message_id: string;
|
|
1215
1450
|
provider: string;
|
|
1451
|
+
actual_provider: string | null;
|
|
1216
1452
|
model: string;
|
|
1217
1453
|
model_name: string | null;
|
|
1218
1454
|
endpoint: string | null;
|
|
@@ -1239,6 +1475,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1239
1475
|
tools_available: number | null;
|
|
1240
1476
|
prompt_name: string | null;
|
|
1241
1477
|
tools_called: string | null;
|
|
1478
|
+
provider_tools: string | null;
|
|
1242
1479
|
parent_log_id: string | null;
|
|
1243
1480
|
tools_schema: string | null;
|
|
1244
1481
|
message_history: string | null;
|
|
@@ -1347,8 +1584,9 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1347
1584
|
/**
|
|
1348
1585
|
* WebSocket Hibernation API handler for connection close
|
|
1349
1586
|
* Called when a WebSocket connection is closed
|
|
1587
|
+
* Note: Do NOT call ws.close() here - the connection is already closed
|
|
1350
1588
|
*/
|
|
1351
|
-
webSocketClose(ws: WebSocket,
|
|
1589
|
+
webSocketClose(ws: WebSocket, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
|
|
1352
1590
|
/**
|
|
1353
1591
|
* WebSocket Hibernation API handler for errors
|
|
1354
1592
|
* Called when a WebSocket encounters an error
|
|
@@ -1367,11 +1605,21 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1367
1605
|
* This is the actual execution logic, separate from the public execute() RPC method
|
|
1368
1606
|
*/
|
|
1369
1607
|
private executeFlow;
|
|
1608
|
+
/**
|
|
1609
|
+
* Internal method: Execute an effect (called by alarm queue)
|
|
1610
|
+
* Effects run outside the tool execution context.
|
|
1611
|
+
*/
|
|
1612
|
+
private executeEffect;
|
|
1370
1613
|
/**
|
|
1371
1614
|
* Internal method: Process a message (called by alarm queue)
|
|
1372
1615
|
* This is the actual message processing logic, separate from the public sendMessage() RPC method
|
|
1373
1616
|
*/
|
|
1374
1617
|
private processMessage;
|
|
1618
|
+
/**
|
|
1619
|
+
* Internal method: Continue execution without adding a message (called by alarm queue)
|
|
1620
|
+
* This allows resuming FlowEngine execution from where it stopped.
|
|
1621
|
+
*/
|
|
1622
|
+
private doContinueExecution;
|
|
1375
1623
|
/**
|
|
1376
1624
|
* TEST METHOD: Queue a test operation
|
|
1377
1625
|
* Used for testing alarm queue ordering and timing
|
|
@@ -1683,6 +1931,7 @@ interface AgentBuilderEnv {
|
|
|
1683
1931
|
GITHUB_TOKEN?: string;
|
|
1684
1932
|
GITHUB_REPO?: string;
|
|
1685
1933
|
GITHUB_BRANCH?: string;
|
|
1934
|
+
ENCRYPTION_KEY?: string;
|
|
1686
1935
|
}
|
|
1687
1936
|
/**
|
|
1688
1937
|
* Thread metadata stored in the registry.
|
|
@@ -1692,6 +1941,8 @@ interface ThreadRegistryEntry {
|
|
|
1692
1941
|
agent_name: string;
|
|
1693
1942
|
user_id: string | null;
|
|
1694
1943
|
tags: string[] | null;
|
|
1944
|
+
tenvs: Record<string, unknown> | null;
|
|
1945
|
+
properties: Record<string, unknown> | null;
|
|
1695
1946
|
created_at: number;
|
|
1696
1947
|
}
|
|
1697
1948
|
/**
|
|
@@ -1716,7 +1967,7 @@ interface User {
|
|
|
1716
1967
|
/**
|
|
1717
1968
|
* Provider credentials.
|
|
1718
1969
|
*/
|
|
1719
|
-
interface Provider {
|
|
1970
|
+
interface Provider$1 {
|
|
1720
1971
|
name: string;
|
|
1721
1972
|
sdk: string;
|
|
1722
1973
|
api_key: string;
|
|
@@ -1760,6 +2011,8 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1760
2011
|
agent_name: string;
|
|
1761
2012
|
user_id?: string;
|
|
1762
2013
|
tags?: string[];
|
|
2014
|
+
tenvs?: Record<string, unknown>;
|
|
2015
|
+
properties?: Record<string, unknown>;
|
|
1763
2016
|
}): Promise<ThreadRegistryEntry>;
|
|
1764
2017
|
/**
|
|
1765
2018
|
* Get a thread by ID.
|
|
@@ -1767,10 +2020,15 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1767
2020
|
getThread(id: string): Promise<ThreadRegistryEntry | null>;
|
|
1768
2021
|
/**
|
|
1769
2022
|
* List threads with optional filtering.
|
|
2023
|
+
* Note: tenvs are not decrypted in list operations for performance.
|
|
2024
|
+
* Use getThread() to retrieve a thread with decrypted tenvs.
|
|
1770
2025
|
*/
|
|
1771
2026
|
listThreads(params?: {
|
|
1772
2027
|
agent_name?: string;
|
|
1773
2028
|
user_id?: string;
|
|
2029
|
+
search?: string;
|
|
2030
|
+
startDate?: number;
|
|
2031
|
+
endDate?: number;
|
|
1774
2032
|
limit?: number;
|
|
1775
2033
|
offset?: number;
|
|
1776
2034
|
}): Promise<{
|
|
@@ -1816,15 +2074,15 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
|
|
|
1816
2074
|
/**
|
|
1817
2075
|
* Get a provider's credentials.
|
|
1818
2076
|
*/
|
|
1819
|
-
getProvider(name: string): Promise<Provider | null>;
|
|
2077
|
+
getProvider(name: string): Promise<Provider$1 | null>;
|
|
1820
2078
|
/**
|
|
1821
2079
|
* Set a provider's credentials.
|
|
1822
2080
|
*/
|
|
1823
|
-
setProvider(provider: Provider): Promise<void>;
|
|
2081
|
+
setProvider(provider: Provider$1): Promise<void>;
|
|
1824
2082
|
/**
|
|
1825
2083
|
* List all providers.
|
|
1826
2084
|
*/
|
|
1827
|
-
listProviders(): Promise<Provider[]>;
|
|
2085
|
+
listProviders(): Promise<Provider$1[]>;
|
|
1828
2086
|
/**
|
|
1829
2087
|
* Delete a provider.
|
|
1830
2088
|
*/
|
|
@@ -2198,16 +2456,34 @@ interface AgentDefinition<N extends string = string> {
|
|
|
2198
2456
|
exposeAsTool?: boolean;
|
|
2199
2457
|
/** Description shown when agent is used as a tool. */
|
|
2200
2458
|
toolDescription?: string;
|
|
2459
|
+
/**
|
|
2460
|
+
* Thread environment variables for this agent.
|
|
2461
|
+
* Merged into thread tenvs at creation time.
|
|
2462
|
+
* Later values (thread) override earlier ones (prompt -> agent).
|
|
2463
|
+
*/
|
|
2464
|
+
tenvs?: Record<string, unknown>;
|
|
2201
2465
|
/** Brief description of what this agent does. */
|
|
2202
2466
|
description?: string;
|
|
2203
2467
|
/** Icon URL or absolute path for the agent. */
|
|
2204
2468
|
icon?: string;
|
|
2205
2469
|
}
|
|
2206
2470
|
|
|
2471
|
+
/**
|
|
2472
|
+
* Options for generating a model file.
|
|
2473
|
+
*/
|
|
2474
|
+
interface GenerateModelFileOptions {
|
|
2475
|
+
/** The provider export name (e.g., 'openai', 'openrouter') */
|
|
2476
|
+
providerName: string;
|
|
2477
|
+
/** The provider package (e.g., '@standardagents/openai') */
|
|
2478
|
+
providerPackage: string;
|
|
2479
|
+
}
|
|
2207
2480
|
/**
|
|
2208
2481
|
* Generate a TypeScript file for a model definition.
|
|
2482
|
+
*
|
|
2483
|
+
* @param data - The model definition data
|
|
2484
|
+
* @param options - Provider import options (required since providers are functions)
|
|
2209
2485
|
*/
|
|
2210
|
-
declare function generateModelFile(data: ModelDefinition): string;
|
|
2486
|
+
declare function generateModelFile(data: ModelDefinition, options: GenerateModelFileOptions): string;
|
|
2211
2487
|
|
|
2212
2488
|
/**
|
|
2213
2489
|
* Converts JSON Schema to Zod code string.
|
|
@@ -2246,6 +2522,8 @@ interface ToolConfigInput {
|
|
|
2246
2522
|
include_tool_calls?: boolean;
|
|
2247
2523
|
include_errors?: boolean;
|
|
2248
2524
|
init_user_message_property?: string | null;
|
|
2525
|
+
init_attachments_property?: string | null;
|
|
2526
|
+
tenvs?: Record<string, unknown>;
|
|
2249
2527
|
}
|
|
2250
2528
|
/**
|
|
2251
2529
|
* Prompt part as it comes from the UI/API.
|
|
@@ -3364,4 +3642,15 @@ declare class GitHubApiError extends Error {
|
|
|
3364
3642
|
constructor(message: string, status: number, details?: unknown);
|
|
3365
3643
|
}
|
|
3366
3644
|
|
|
3367
|
-
|
|
3645
|
+
/** @public Alias for LLMProviderInterface */
|
|
3646
|
+
type Provider = LLMProviderInterface;
|
|
3647
|
+
/** @public Alias for ContentPart */
|
|
3648
|
+
type ProviderContentPart = ContentPart;
|
|
3649
|
+
/** @public Alias for TextPart */
|
|
3650
|
+
type ProviderTextPart = TextPart;
|
|
3651
|
+
/** @public Alias for ImagePart */
|
|
3652
|
+
type ProviderImagePart = ImagePart;
|
|
3653
|
+
/** @public Alias for FilePart */
|
|
3654
|
+
type ProviderFilePart = FilePart;
|
|
3655
|
+
|
|
3656
|
+
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 };
|