@standardagents/spec 0.11.12 → 0.12.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/index.d.ts +496 -48
- package/dist/index.js +64 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,13 @@ declare global {
|
|
|
53
53
|
*/
|
|
54
54
|
interface CallableRegistry {
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Registry of hook IDs from agents/hooks/.
|
|
58
|
+
* Generated types add properties: interface HookIdRegistry { 'limit_messages': true; }
|
|
59
|
+
* This gives us: type HookIds = keyof HookIdRegistry = 'limit_messages'
|
|
60
|
+
*/
|
|
61
|
+
interface HookIdRegistry {
|
|
62
|
+
}
|
|
56
63
|
/**
|
|
57
64
|
* Registry mapping prompt/agent names to their requiredSchema field names.
|
|
58
65
|
* For agents, this maps to the side_a prompt's requiredSchema fields.
|
|
@@ -95,6 +102,11 @@ declare global {
|
|
|
95
102
|
* Callables include prompts, agents, and tools that can be used as tools.
|
|
96
103
|
*/
|
|
97
104
|
type Callables = keyof CallableRegistry extends never ? string : keyof CallableRegistry;
|
|
105
|
+
/**
|
|
106
|
+
* Union of all hook IDs, or string when registry is empty.
|
|
107
|
+
* Hook IDs are the unique identifiers defined in agents/hooks/ files.
|
|
108
|
+
*/
|
|
109
|
+
type HookIds = keyof HookIdRegistry extends never ? string : keyof HookIdRegistry;
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
|
|
@@ -969,20 +981,83 @@ type ToolTenvs<D extends number = 7> = z.ZodObject<TenvRawShape<D>>;
|
|
|
969
981
|
* @template Args - The Zod schema for tool arguments, or null for no args
|
|
970
982
|
*/
|
|
971
983
|
type Tool<State = ThreadState, Args extends ToolArgs | null = null> = Args extends ToolArgs ? (state: State, args: z.infer<Args>) => Promise<ToolResult> : (state: State) => Promise<ToolResult>;
|
|
984
|
+
/**
|
|
985
|
+
* Helper type to check if Uses is a non-empty const array.
|
|
986
|
+
* Returns true only if Uses has literal string elements (from `as const`).
|
|
987
|
+
*/
|
|
988
|
+
type IsConstArray<Uses extends readonly string[]> = string extends Uses[number] ? false : true;
|
|
989
|
+
/**
|
|
990
|
+
* Helper type to check if Uses array is empty.
|
|
991
|
+
*/
|
|
992
|
+
type IsEmptyArray<Uses extends readonly string[]> = Uses extends readonly [] ? true : false;
|
|
993
|
+
/**
|
|
994
|
+
* A ThreadState with queueTool and invokeTool constrained to specific tool names.
|
|
995
|
+
*
|
|
996
|
+
* When a tool declares `uses: ['a', 'b'] as const`, the state passed to execute
|
|
997
|
+
* will only allow calling those specific tools.
|
|
998
|
+
*
|
|
999
|
+
* @template Uses - Readonly array of allowed tool names
|
|
1000
|
+
*/
|
|
1001
|
+
type UsesConstrainedState<Uses extends readonly string[]> = Omit<ThreadState, 'queueTool' | 'invokeTool'> & {
|
|
1002
|
+
/**
|
|
1003
|
+
* Queue a tool for execution.
|
|
1004
|
+
*
|
|
1005
|
+
* Constrained to only tools declared in `uses` array.
|
|
1006
|
+
*
|
|
1007
|
+
* @param toolName - Name of the tool to invoke (must be in uses array)
|
|
1008
|
+
* @param args - Arguments to pass to the tool
|
|
1009
|
+
*/
|
|
1010
|
+
queueTool(toolName: Uses[number], args?: Record<string, unknown>): void;
|
|
1011
|
+
/**
|
|
1012
|
+
* Invoke a tool directly and wait for the result.
|
|
1013
|
+
*
|
|
1014
|
+
* Constrained to only tools declared in `uses` array.
|
|
1015
|
+
*
|
|
1016
|
+
* @param toolName - Name of the tool to invoke (must be in uses array)
|
|
1017
|
+
* @param args - Arguments to pass to the tool
|
|
1018
|
+
* @returns The tool result
|
|
1019
|
+
*/
|
|
1020
|
+
invokeTool(toolName: Uses[number], args?: Record<string, unknown>): Promise<ToolResult>;
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* A ThreadState where queueTool and invokeTool cannot be called (empty uses).
|
|
1024
|
+
*/
|
|
1025
|
+
type EmptyUsesState = Omit<ThreadState, 'queueTool' | 'invokeTool'>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Determines the correct state type based on the Uses array.
|
|
1028
|
+
*
|
|
1029
|
+
* - Empty `uses: [] as const` → EmptyUsesState (no queueTool/invokeTool)
|
|
1030
|
+
* - Const `uses: ['a', 'b'] as const` → UsesConstrainedState (constrained methods)
|
|
1031
|
+
* - Non-const `uses: ['a']` or no uses → ThreadState (unconstrained, backward compatible)
|
|
1032
|
+
*/
|
|
1033
|
+
type ResolveUsesState<Uses extends readonly string[]> = IsEmptyArray<Uses> extends true ? EmptyUsesState : IsConstArray<Uses> extends true ? UsesConstrainedState<Uses> : ThreadState;
|
|
1034
|
+
/**
|
|
1035
|
+
* Tool execute function with uses-aware state.
|
|
1036
|
+
*
|
|
1037
|
+
* When `uses` is declared with `as const`, the state's queueTool and invokeTool
|
|
1038
|
+
* are constrained to only the declared tools. When `uses` is not declared or
|
|
1039
|
+
* is a regular string[], any tool name is allowed (backward compatible).
|
|
1040
|
+
*
|
|
1041
|
+
* @template State - Base state type
|
|
1042
|
+
* @template Args - Tool arguments schema
|
|
1043
|
+
* @template Uses - Readonly array of allowed tool names
|
|
1044
|
+
*/
|
|
1045
|
+
type UsesAwareExecute<State, Args extends ToolArgs | null, Uses extends readonly string[]> = Args extends ToolArgs ? (state: ResolveUsesState<Uses>, args: z.infer<Args>) => Promise<ToolResult> : (state: ResolveUsesState<Uses>) => Promise<ToolResult>;
|
|
972
1046
|
/**
|
|
973
1047
|
* Options for defining a tool.
|
|
974
1048
|
*
|
|
975
1049
|
* @template State - The state type (defaults to ThreadState)
|
|
976
1050
|
* @template Args - The Zod schema for tool arguments, or null for no args
|
|
977
1051
|
* @template Tenvs - The Zod schema for thread environment variables, or null
|
|
1052
|
+
* @template Uses - Readonly array of tool names this tool can invoke
|
|
978
1053
|
*/
|
|
979
|
-
interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
|
|
1054
|
+
interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null, Uses extends readonly string[] = readonly string[]> {
|
|
980
1055
|
/** Description of what the tool does (shown to the LLM). */
|
|
981
1056
|
description: string;
|
|
982
1057
|
/** Zod schema for validating tool arguments. Omit for tools with no args. */
|
|
983
1058
|
args?: Args;
|
|
984
1059
|
/** The tool implementation function. */
|
|
985
|
-
execute:
|
|
1060
|
+
execute: UsesAwareExecute<State, Args, Uses>;
|
|
986
1061
|
/** Zod schema for thread environment variables the tool requires. */
|
|
987
1062
|
tenvs?: Tenvs;
|
|
988
1063
|
/**
|
|
@@ -996,6 +1071,42 @@ interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null =
|
|
|
996
1071
|
* e.g., 'openai', 'anthropic'
|
|
997
1072
|
*/
|
|
998
1073
|
executionProvider?: string;
|
|
1074
|
+
/**
|
|
1075
|
+
* Explicit list of tools, prompts, or agents this tool can call.
|
|
1076
|
+
*
|
|
1077
|
+
* When specified with `as const`, the tool's execute function's state
|
|
1078
|
+
* will have queueTool() and invokeTool() constrained to only the
|
|
1079
|
+
* declared tools (compile-time type safety).
|
|
1080
|
+
*
|
|
1081
|
+
* At runtime, attempts to call unlisted items will throw an error.
|
|
1082
|
+
*
|
|
1083
|
+
* This is required for packed tools to ensure namespace isolation.
|
|
1084
|
+
* For unpacked tools, it's optional but recommended for clarity.
|
|
1085
|
+
*
|
|
1086
|
+
* @example
|
|
1087
|
+
* ```typescript
|
|
1088
|
+
* // Type-safe: only 'validate_input' and 'format_output' allowed
|
|
1089
|
+
* defineTool({
|
|
1090
|
+
* description: 'Process data using helper tools',
|
|
1091
|
+
* uses: ['validate_input', 'format_output'] as const,
|
|
1092
|
+
* execute: async (state) => {
|
|
1093
|
+
* state.queueTool('validate_input', { data: '...' }); // ✓ OK
|
|
1094
|
+
* state.queueTool('unknown_tool', {}); // ✗ TypeScript error
|
|
1095
|
+
* // ...
|
|
1096
|
+
* },
|
|
1097
|
+
* });
|
|
1098
|
+
*
|
|
1099
|
+
* // Without `as const`, any tool name is allowed (backward compatible)
|
|
1100
|
+
* defineTool({
|
|
1101
|
+
* description: 'Flexible tool',
|
|
1102
|
+
* uses: ['some_tool'],
|
|
1103
|
+
* execute: async (state) => {
|
|
1104
|
+
* state.queueTool('any_tool', {}); // ✓ OK (no type constraint)
|
|
1105
|
+
* },
|
|
1106
|
+
* });
|
|
1107
|
+
* ```
|
|
1108
|
+
*/
|
|
1109
|
+
uses?: Uses;
|
|
999
1110
|
}
|
|
1000
1111
|
/**
|
|
1001
1112
|
* Tool definition object returned by defineTool().
|
|
@@ -1006,14 +1117,15 @@ interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null =
|
|
|
1006
1117
|
* @template State - The state type (defaults to ThreadState)
|
|
1007
1118
|
* @template Args - The Zod schema for tool arguments, or null for no args
|
|
1008
1119
|
* @template Tenvs - The Zod schema for thread environment variables, or null
|
|
1120
|
+
* @template Uses - Readonly array of tool names this tool can invoke
|
|
1009
1121
|
*/
|
|
1010
|
-
interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
|
|
1122
|
+
interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null, Uses extends readonly string[] = readonly string[]> {
|
|
1011
1123
|
/** Description of what the tool does (shown to the LLM). */
|
|
1012
1124
|
description: string;
|
|
1013
1125
|
/** Zod schema for validating tool arguments, or null for no args. */
|
|
1014
1126
|
args: Args;
|
|
1015
1127
|
/** The tool implementation function. */
|
|
1016
|
-
execute:
|
|
1128
|
+
execute: UsesAwareExecute<State, Args, Uses>;
|
|
1017
1129
|
/** Zod schema for thread environment variables, or null if none. */
|
|
1018
1130
|
tenvs: Tenvs;
|
|
1019
1131
|
/**
|
|
@@ -1026,6 +1138,21 @@ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = nul
|
|
|
1026
1138
|
* Which provider executes this tool (when executionMode='provider').
|
|
1027
1139
|
*/
|
|
1028
1140
|
executionProvider?: string;
|
|
1141
|
+
/**
|
|
1142
|
+
* Explicit list of tools, prompts, or agents this tool can call.
|
|
1143
|
+
*
|
|
1144
|
+
* When specified with `as const`, TypeScript constrains queueTool()
|
|
1145
|
+
* and invokeTool() at compile time. At runtime, attempts to call
|
|
1146
|
+
* unlisted items throw an error.
|
|
1147
|
+
*
|
|
1148
|
+
* This is required for packed tools to ensure namespace isolation.
|
|
1149
|
+
* For unpacked tools, it's optional but recommended for clarity.
|
|
1150
|
+
*
|
|
1151
|
+
* Items can be:
|
|
1152
|
+
* - Simple names: Resolve within current namespace
|
|
1153
|
+
* - Qualified names (e.g., 'other_pkg:agent'): Cross-package entry point
|
|
1154
|
+
*/
|
|
1155
|
+
uses?: Uses;
|
|
1029
1156
|
}
|
|
1030
1157
|
/**
|
|
1031
1158
|
* Defines a tool that agents can call during execution.
|
|
@@ -1084,7 +1211,13 @@ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = nul
|
|
|
1084
1211
|
* @param options - Tool definition options
|
|
1085
1212
|
* @returns A tool definition object
|
|
1086
1213
|
*/
|
|
1087
|
-
|
|
1214
|
+
/**
|
|
1215
|
+
* Validate a tool name does not contain reserved characters.
|
|
1216
|
+
* Tools are typically defined without a name field (they get the filename),
|
|
1217
|
+
* but this can be called by build tools that assign names.
|
|
1218
|
+
*/
|
|
1219
|
+
declare function validateToolName(name: string): void;
|
|
1220
|
+
declare function defineTool<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null, Uses extends readonly string[] = readonly string[]>(options: DefineToolOptions<State, Args, Tenvs, Uses>): ToolDefinition<State, Args, Tenvs, Uses>;
|
|
1088
1221
|
|
|
1089
1222
|
/**
|
|
1090
1223
|
* Provider types for Standard Agents.
|
|
@@ -2211,6 +2344,17 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
|
|
|
2211
2344
|
* ```
|
|
2212
2345
|
*/
|
|
2213
2346
|
providerOptions?: Record<string, unknown>;
|
|
2347
|
+
/**
|
|
2348
|
+
* Hook IDs to run when this prompt is active.
|
|
2349
|
+
* References hooks by their unique `id` property from defineHook().
|
|
2350
|
+
* If not specified, falls back to agent-level hooks.
|
|
2351
|
+
*
|
|
2352
|
+
* @example
|
|
2353
|
+
* ```typescript
|
|
2354
|
+
* hooks: ['limit_to_20_messages', 'log_tool_calls']
|
|
2355
|
+
* ```
|
|
2356
|
+
*/
|
|
2357
|
+
hooks?: StandardAgentSpec.HookIds[];
|
|
2214
2358
|
}
|
|
2215
2359
|
/**
|
|
2216
2360
|
* Helper type to extract the inferred input type from a prompt's Zod schema.
|
|
@@ -2316,21 +2460,37 @@ interface HookToolResult {
|
|
|
2316
2460
|
error?: string;
|
|
2317
2461
|
/** Stack trace (for debugging) */
|
|
2318
2462
|
stack?: string;
|
|
2463
|
+
/**
|
|
2464
|
+
* File attachments returned by the tool.
|
|
2465
|
+
*
|
|
2466
|
+
* Can contain either:
|
|
2467
|
+
* - ToolAttachment: New files with base64 data to be stored
|
|
2468
|
+
* - AttachmentRef: References to existing files in the thread filesystem
|
|
2469
|
+
*/
|
|
2470
|
+
attachments?: Array<ToolAttachment | AttachmentRef>;
|
|
2319
2471
|
}
|
|
2320
2472
|
/**
|
|
2321
2473
|
* LLM message format for prefilter hook.
|
|
2474
|
+
*
|
|
2475
|
+
* Messages passed to the prefilter_llm_history hook are in chat completion
|
|
2476
|
+
* format. Content can be a plain string or a multimodal array (for messages
|
|
2477
|
+
* with images). Additional provider-specific fields may also be present.
|
|
2322
2478
|
*/
|
|
2323
2479
|
interface LLMMessage {
|
|
2324
2480
|
/** Message role */
|
|
2325
2481
|
role: string;
|
|
2326
|
-
/** Message content */
|
|
2327
|
-
content
|
|
2482
|
+
/** Message content (string for text-only, array for multimodal) */
|
|
2483
|
+
content?: string | null | unknown[];
|
|
2328
2484
|
/** Tool calls (parsed) */
|
|
2329
2485
|
tool_calls?: unknown;
|
|
2330
2486
|
/** Tool call ID */
|
|
2331
2487
|
tool_call_id?: string;
|
|
2332
2488
|
/** Tool name */
|
|
2333
2489
|
name?: string;
|
|
2490
|
+
/** Reasoning content (for models like o1) */
|
|
2491
|
+
reasoning_content?: string;
|
|
2492
|
+
/** Allow additional provider-specific fields */
|
|
2493
|
+
[key: string]: unknown;
|
|
2334
2494
|
}
|
|
2335
2495
|
/**
|
|
2336
2496
|
* Hook signatures for all available hooks.
|
|
@@ -2388,22 +2548,29 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
2388
2548
|
/**
|
|
2389
2549
|
* Called before a message is created in the database.
|
|
2390
2550
|
*
|
|
2391
|
-
* Receives the message
|
|
2392
|
-
* to transform
|
|
2551
|
+
* Receives the full message object before insertion. Return modified
|
|
2552
|
+
* message to transform before storage.
|
|
2393
2553
|
*
|
|
2394
2554
|
* @param state - Thread state
|
|
2395
|
-
* @param message - Message
|
|
2396
|
-
* @returns Modified message
|
|
2555
|
+
* @param message - Message to be created
|
|
2556
|
+
* @returns Modified message
|
|
2397
2557
|
*
|
|
2398
2558
|
* @example
|
|
2399
2559
|
* ```typescript
|
|
2400
|
-
* defineHook(
|
|
2401
|
-
*
|
|
2402
|
-
*
|
|
2560
|
+
* defineHook({
|
|
2561
|
+
* hook: 'before_create_message',
|
|
2562
|
+
* id: 'prefix_content',
|
|
2563
|
+
* execute: async (state, message) => {
|
|
2564
|
+
* // message has full type: id, role, content, created_at, etc.
|
|
2565
|
+
* if (message.role === 'user' && message.content) {
|
|
2566
|
+
* return { ...message, content: `[user] ${message.content}` };
|
|
2567
|
+
* }
|
|
2568
|
+
* return message;
|
|
2569
|
+
* }
|
|
2403
2570
|
* });
|
|
2404
2571
|
* ```
|
|
2405
2572
|
*/
|
|
2406
|
-
before_create_message: (state: State, message:
|
|
2573
|
+
before_create_message: (state: State, message: Msg) => Promise<Msg>;
|
|
2407
2574
|
/**
|
|
2408
2575
|
* Called after a message is created in the database.
|
|
2409
2576
|
*
|
|
@@ -2411,16 +2578,20 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
2411
2578
|
* message creation. Cannot modify the message.
|
|
2412
2579
|
*
|
|
2413
2580
|
* @param state - Thread state
|
|
2414
|
-
* @param message - The created message
|
|
2581
|
+
* @param message - The created message
|
|
2415
2582
|
*
|
|
2416
2583
|
* @example
|
|
2417
2584
|
* ```typescript
|
|
2418
|
-
* defineHook(
|
|
2419
|
-
*
|
|
2585
|
+
* defineHook({
|
|
2586
|
+
* hook: 'after_create_message',
|
|
2587
|
+
* id: 'log_creation',
|
|
2588
|
+
* execute: async (state, message) => {
|
|
2589
|
+
* console.log(`Created ${message.role} message: ${message.id}`);
|
|
2590
|
+
* }
|
|
2420
2591
|
* });
|
|
2421
2592
|
* ```
|
|
2422
2593
|
*/
|
|
2423
|
-
after_create_message: (state: State, message:
|
|
2594
|
+
after_create_message: (state: State, message: Msg) => Promise<void>;
|
|
2424
2595
|
/**
|
|
2425
2596
|
* Called before a message is updated in the database.
|
|
2426
2597
|
*
|
|
@@ -2466,17 +2637,25 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
2466
2637
|
* @param state - Thread state
|
|
2467
2638
|
* @param toolCall - The tool call that was executed
|
|
2468
2639
|
* @param toolResult - The result from tool execution
|
|
2469
|
-
* @returns Modified tool result
|
|
2640
|
+
* @returns Modified tool result
|
|
2470
2641
|
*
|
|
2471
2642
|
* @example
|
|
2472
2643
|
* ```typescript
|
|
2473
|
-
* defineHook(
|
|
2474
|
-
*
|
|
2475
|
-
*
|
|
2644
|
+
* defineHook({
|
|
2645
|
+
* hook: 'before_store_tool_result',
|
|
2646
|
+
* id: 'sanitize_results',
|
|
2647
|
+
* execute: async (state, toolCall, toolResult) => {
|
|
2648
|
+
* // toolCall has: id, type, function.name, function.arguments
|
|
2649
|
+
* // toolResult has: status, result?, error?, stack?, attachments?
|
|
2650
|
+
* if (toolResult.result) {
|
|
2651
|
+
* return { ...toolResult, result: sanitize(toolResult.result) };
|
|
2652
|
+
* }
|
|
2653
|
+
* return toolResult;
|
|
2654
|
+
* }
|
|
2476
2655
|
* });
|
|
2477
2656
|
* ```
|
|
2478
2657
|
*/
|
|
2479
|
-
before_store_tool_result: (state: State, toolCall:
|
|
2658
|
+
before_store_tool_result: (state: State, toolCall: ToolCall, toolResult: ToolResult) => Promise<ToolResult>;
|
|
2480
2659
|
/**
|
|
2481
2660
|
* Called after a successful tool call.
|
|
2482
2661
|
*
|
|
@@ -2534,51 +2713,90 @@ type HookName = keyof HookSignatures;
|
|
|
2534
2713
|
* @template Msg - The message type
|
|
2535
2714
|
* @template ToolCall - The tool call type
|
|
2536
2715
|
* @template ToolResult - The tool result type
|
|
2716
|
+
* @deprecated Use the object-based defineHook signature instead
|
|
2537
2717
|
*/
|
|
2538
2718
|
type HookDefinition<K extends HookName = HookName, State = ThreadState, Msg = HookMessage, ToolCall = HookToolCall, ToolResult = HookToolResult> = [K, HookSignatures<State, Msg, ToolCall, ToolResult>[K]];
|
|
2539
2719
|
/**
|
|
2540
|
-
*
|
|
2720
|
+
* Options for defining a hook with explicit ID.
|
|
2721
|
+
* The generic K ensures `execute` is properly typed for the specific hook type.
|
|
2541
2722
|
*
|
|
2542
|
-
*
|
|
2543
|
-
|
|
2544
|
-
|
|
2723
|
+
* @template K - Hook type from HookSignatures (e.g., 'filter_messages')
|
|
2724
|
+
*/
|
|
2725
|
+
interface HookDefinitionOptions<K extends HookName> {
|
|
2726
|
+
/** The hook type (e.g., 'filter_messages', 'before_create_message') */
|
|
2727
|
+
hook: K;
|
|
2728
|
+
/** Unique identifier for this hook implementation (snake_case) */
|
|
2729
|
+
id: string;
|
|
2730
|
+
/**
|
|
2731
|
+
* The hook implementation function.
|
|
2732
|
+
* Type is automatically inferred from the hook type.
|
|
2733
|
+
*/
|
|
2734
|
+
execute: HookSignatures<ThreadState, HookMessage, HookToolCall, HookToolResult>[K];
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Return type from defineHook - preserves the hook type for type-safe usage.
|
|
2738
|
+
*
|
|
2739
|
+
* @template K - Hook type from HookSignatures
|
|
2740
|
+
*/
|
|
2741
|
+
interface HookDefinitionResult<K extends HookName> {
|
|
2742
|
+
/** The hook type name */
|
|
2743
|
+
hook: K;
|
|
2744
|
+
/** The unique hook ID */
|
|
2745
|
+
id: string;
|
|
2746
|
+
/** The typed execute function */
|
|
2747
|
+
execute: HookSignatures<ThreadState, HookMessage, HookToolCall, HookToolResult>[K];
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* Define a hook with a unique identifier and strict typing.
|
|
2545
2751
|
*
|
|
2546
|
-
*
|
|
2547
|
-
*
|
|
2548
|
-
*
|
|
2549
|
-
* @
|
|
2752
|
+
* The hook type determines the execute function signature.
|
|
2753
|
+
* TypeScript will enforce correct parameter and return types.
|
|
2754
|
+
*
|
|
2755
|
+
* @template K - The hook type (inferred from options.hook)
|
|
2756
|
+
* @param options - Hook definition with hook type, ID, and execute function
|
|
2757
|
+
* @returns Typed hook definition for registration
|
|
2550
2758
|
*
|
|
2551
2759
|
* @example
|
|
2552
2760
|
* ```typescript
|
|
2553
|
-
* // Filter messages
|
|
2554
|
-
* export default defineHook(
|
|
2555
|
-
*
|
|
2761
|
+
* // Filter messages - execute receives (state: ThreadState, messages: HookMessage[])
|
|
2762
|
+
* export default defineHook({
|
|
2763
|
+
* hook: 'filter_messages',
|
|
2764
|
+
* id: 'limit_to_20_messages',
|
|
2765
|
+
* execute: async (state, messages) => {
|
|
2766
|
+
* return messages.slice(-20);
|
|
2767
|
+
* }
|
|
2556
2768
|
* });
|
|
2557
2769
|
* ```
|
|
2558
2770
|
*
|
|
2559
2771
|
* @example
|
|
2560
2772
|
* ```typescript
|
|
2561
|
-
* //
|
|
2562
|
-
* export default defineHook(
|
|
2563
|
-
*
|
|
2564
|
-
*
|
|
2773
|
+
* // Before create message - execute receives (state: ThreadState, message: Message)
|
|
2774
|
+
* export default defineHook({
|
|
2775
|
+
* hook: 'before_create_message',
|
|
2776
|
+
* id: 'prefix_content',
|
|
2777
|
+
* execute: async (state, message) => {
|
|
2778
|
+
* if (message.role === 'user' && message.content) {
|
|
2779
|
+
* return { ...message, content: `[user] ${message.content}` };
|
|
2780
|
+
* }
|
|
2781
|
+
* return message;
|
|
2782
|
+
* }
|
|
2565
2783
|
* });
|
|
2566
2784
|
* ```
|
|
2567
2785
|
*
|
|
2568
2786
|
* @example
|
|
2569
2787
|
* ```typescript
|
|
2570
|
-
* //
|
|
2571
|
-
* export default defineHook(
|
|
2572
|
-
*
|
|
2573
|
-
*
|
|
2574
|
-
*
|
|
2575
|
-
*
|
|
2788
|
+
* // After tool call success - execute receives (state, toolCall, toolResult)
|
|
2789
|
+
* export default defineHook({
|
|
2790
|
+
* hook: 'after_tool_call_success',
|
|
2791
|
+
* id: 'log_tool_usage',
|
|
2792
|
+
* execute: async (state, toolCall, toolResult) => {
|
|
2793
|
+
* console.log(`Tool ${toolCall.function.name} returned: ${toolResult.result}`);
|
|
2794
|
+
* return null; // Use original result
|
|
2576
2795
|
* }
|
|
2577
|
-
* return messages;
|
|
2578
2796
|
* });
|
|
2579
2797
|
* ```
|
|
2580
2798
|
*/
|
|
2581
|
-
declare function defineHook<K extends
|
|
2799
|
+
declare function defineHook<K extends HookName>(options: HookDefinitionOptions<K>): HookDefinitionResult<K>;
|
|
2582
2800
|
|
|
2583
2801
|
/**
|
|
2584
2802
|
* Agent definition types for Standard Agents.
|
|
@@ -2768,6 +2986,47 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
|
|
|
2768
2986
|
* ```
|
|
2769
2987
|
*/
|
|
2770
2988
|
tenvs?: Record<string, unknown>;
|
|
2989
|
+
/**
|
|
2990
|
+
* npm package name for this agent when packed.
|
|
2991
|
+
* Used by the packing system to maintain consistent package identity
|
|
2992
|
+
* across pack/unpack cycles.
|
|
2993
|
+
*
|
|
2994
|
+
* @example 'standardagent-support-agent', '@myorg/support-agent'
|
|
2995
|
+
*/
|
|
2996
|
+
packageName?: string;
|
|
2997
|
+
/**
|
|
2998
|
+
* Package version (semver format).
|
|
2999
|
+
* Used by the packing system to track versions across pack/unpack cycles.
|
|
3000
|
+
* When re-packing, this version is auto-incremented by the pack modal.
|
|
3001
|
+
*
|
|
3002
|
+
* @example '1.0.0', '2.3.1-beta.1'
|
|
3003
|
+
*/
|
|
3004
|
+
version?: string;
|
|
3005
|
+
/**
|
|
3006
|
+
* Package author/copyright holder.
|
|
3007
|
+
* Used by the packing system for the LICENSE file and package.json author field.
|
|
3008
|
+
*
|
|
3009
|
+
* @example 'John Doe', 'Acme Corp'
|
|
3010
|
+
*/
|
|
3011
|
+
author?: string;
|
|
3012
|
+
/**
|
|
3013
|
+
* License identifier (SPDX format).
|
|
3014
|
+
* Used by the packing system for LICENSE file generation.
|
|
3015
|
+
*
|
|
3016
|
+
* @example 'MIT', 'Apache-2.0', 'ISC'
|
|
3017
|
+
*/
|
|
3018
|
+
license?: string;
|
|
3019
|
+
/**
|
|
3020
|
+
* Hook IDs to run for this agent.
|
|
3021
|
+
* References hooks by their unique `id` property from defineHook().
|
|
3022
|
+
* These run when prompts don't specify their own hooks.
|
|
3023
|
+
*
|
|
3024
|
+
* @example
|
|
3025
|
+
* ```typescript
|
|
3026
|
+
* hooks: ['log_messages', 'track_tool_usage']
|
|
3027
|
+
* ```
|
|
3028
|
+
*/
|
|
3029
|
+
hooks?: StandardAgentSpec.HookIds[];
|
|
2771
3030
|
}
|
|
2772
3031
|
/**
|
|
2773
3032
|
* Defines an agent configuration.
|
|
@@ -3033,4 +3292,193 @@ declare function defineController(controller: Controller): Controller;
|
|
|
3033
3292
|
*/
|
|
3034
3293
|
declare function defineThreadEndpoint(handler: ThreadEndpointHandler): MarkedThreadEndpoint;
|
|
3035
3294
|
|
|
3036
|
-
|
|
3295
|
+
/**
|
|
3296
|
+
* Packing types for Standard Agents.
|
|
3297
|
+
*
|
|
3298
|
+
* Defines types for packaging agents with their dependencies into
|
|
3299
|
+
* reusable, encapsulated packages that can be published to npm
|
|
3300
|
+
* or stored locally.
|
|
3301
|
+
*
|
|
3302
|
+
* @module
|
|
3303
|
+
*/
|
|
3304
|
+
/**
|
|
3305
|
+
* Package signature applied to packed definitions.
|
|
3306
|
+
*
|
|
3307
|
+
* When an agent and its dependencies are packed, each definition
|
|
3308
|
+
* receives this signature marking it as belonging to a specific package.
|
|
3309
|
+
* This enables namespace isolation during execution.
|
|
3310
|
+
*
|
|
3311
|
+
* @example
|
|
3312
|
+
* ```typescript
|
|
3313
|
+
* const signature: PackageSignature = {
|
|
3314
|
+
* packageId: 'standardagent-my-workflow',
|
|
3315
|
+
* version: '1.0.0',
|
|
3316
|
+
* source: 'npm',
|
|
3317
|
+
* packedAt: Date.now(),
|
|
3318
|
+
* };
|
|
3319
|
+
* ```
|
|
3320
|
+
*/
|
|
3321
|
+
interface PackageSignature {
|
|
3322
|
+
/** Unique package identifier (npm name or local identifier) */
|
|
3323
|
+
packageId: string;
|
|
3324
|
+
/** Package version */
|
|
3325
|
+
version: string;
|
|
3326
|
+
/** Source type */
|
|
3327
|
+
source: 'npm' | 'local';
|
|
3328
|
+
/** When packed (timestamp in milliseconds) */
|
|
3329
|
+
packedAt: number;
|
|
3330
|
+
}
|
|
3331
|
+
/**
|
|
3332
|
+
* Global namespace context - for unpacked code.
|
|
3333
|
+
*
|
|
3334
|
+
* Unpacked code sees:
|
|
3335
|
+
* - All unpacked tools, prompts, models, hooks
|
|
3336
|
+
* - Packed agent entry points (agents with exposeAsTool: true)
|
|
3337
|
+
* - NOT internal packed tools/prompts (those are hidden)
|
|
3338
|
+
*/
|
|
3339
|
+
interface GlobalNamespaceContext {
|
|
3340
|
+
type: 'global';
|
|
3341
|
+
}
|
|
3342
|
+
/**
|
|
3343
|
+
* Packed namespace context - for code inside a packed agent.
|
|
3344
|
+
*
|
|
3345
|
+
* Packed code sees:
|
|
3346
|
+
* - Only items within its own package (by packageId)
|
|
3347
|
+
* - Other packed agent entry points (for handoffs)
|
|
3348
|
+
* - NOT unpacked global code
|
|
3349
|
+
*/
|
|
3350
|
+
interface PackedNamespaceContext {
|
|
3351
|
+
type: 'packed';
|
|
3352
|
+
/** Package ID this code belongs to */
|
|
3353
|
+
packageId: string;
|
|
3354
|
+
}
|
|
3355
|
+
/**
|
|
3356
|
+
* Namespace context for execution.
|
|
3357
|
+
* Determines what items are visible during execution.
|
|
3358
|
+
*
|
|
3359
|
+
* @example
|
|
3360
|
+
* ```typescript
|
|
3361
|
+
* // Global namespace (unpacked code)
|
|
3362
|
+
* const globalNs: NamespaceContext = { type: 'global' };
|
|
3363
|
+
*
|
|
3364
|
+
* // Packed namespace (inside a packed agent)
|
|
3365
|
+
* const packedNs: NamespaceContext = {
|
|
3366
|
+
* type: 'packed',
|
|
3367
|
+
* packageId: 'standardagent-my-workflow',
|
|
3368
|
+
* };
|
|
3369
|
+
* ```
|
|
3370
|
+
*/
|
|
3371
|
+
type NamespaceContext = GlobalNamespaceContext | PackedNamespaceContext;
|
|
3372
|
+
/**
|
|
3373
|
+
* Extended metadata for packed definitions.
|
|
3374
|
+
*
|
|
3375
|
+
* This interface is added to agent, prompt, tool, model, and hook
|
|
3376
|
+
* definitions when they are packed. It marks them as belonging
|
|
3377
|
+
* to a specific package and optionally as readonly.
|
|
3378
|
+
*/
|
|
3379
|
+
interface PackedMetadata {
|
|
3380
|
+
/**
|
|
3381
|
+
* Package signature if this definition is part of a packed agent.
|
|
3382
|
+
* Undefined for unpacked (global) definitions.
|
|
3383
|
+
*/
|
|
3384
|
+
__package?: PackageSignature;
|
|
3385
|
+
/**
|
|
3386
|
+
* Whether this definition is readonly (cannot be edited in UI).
|
|
3387
|
+
* Packed definitions are typically readonly.
|
|
3388
|
+
*/
|
|
3389
|
+
__readonly?: boolean;
|
|
3390
|
+
}
|
|
3391
|
+
/**
|
|
3392
|
+
* Helper type to check if a definition is packed.
|
|
3393
|
+
*/
|
|
3394
|
+
declare function isPacked(metadata: PackedMetadata | undefined): metadata is PackedMetadata & {
|
|
3395
|
+
__package: PackageSignature;
|
|
3396
|
+
};
|
|
3397
|
+
/**
|
|
3398
|
+
* Helper to check if a definition belongs to a specific package.
|
|
3399
|
+
*/
|
|
3400
|
+
declare function belongsToPackage(metadata: PackedMetadata | undefined, packageId: string): boolean;
|
|
3401
|
+
/**
|
|
3402
|
+
* Helper to check if a definition is visible in a given namespace.
|
|
3403
|
+
*
|
|
3404
|
+
* @param metadata - The definition's packed metadata
|
|
3405
|
+
* @param namespace - The current namespace context
|
|
3406
|
+
* @param isEntryPoint - Whether this is an agent with exposeAsTool: true
|
|
3407
|
+
*/
|
|
3408
|
+
declare function isVisibleInNamespace(metadata: PackedMetadata | undefined, namespace: NamespaceContext, isEntryPoint?: boolean): boolean;
|
|
3409
|
+
/**
|
|
3410
|
+
* Metadata export for packed packages.
|
|
3411
|
+
*
|
|
3412
|
+
* This is exported as `__meta` from the packed package's index.ts,
|
|
3413
|
+
* replacing the manifest.json file from the old format.
|
|
3414
|
+
*
|
|
3415
|
+
* @example
|
|
3416
|
+
* ```typescript
|
|
3417
|
+
* export const __meta: PackedMeta = {
|
|
3418
|
+
* packageId: 'standardagent-my-workflow',
|
|
3419
|
+
* version: '1.0.0',
|
|
3420
|
+
* entryAgents: ['my_agent'],
|
|
3421
|
+
* packedAt: 1705012800000,
|
|
3422
|
+
* };
|
|
3423
|
+
* ```
|
|
3424
|
+
*/
|
|
3425
|
+
interface PackedMeta {
|
|
3426
|
+
/** Unique package identifier (npm name or local identifier) */
|
|
3427
|
+
packageId: string;
|
|
3428
|
+
/** Package version (semver) */
|
|
3429
|
+
version: string;
|
|
3430
|
+
/** Entry agents exposed as tools (visible from outside the package) */
|
|
3431
|
+
entryAgents: string[];
|
|
3432
|
+
/** When the package was packed (timestamp in milliseconds) */
|
|
3433
|
+
packedAt: number;
|
|
3434
|
+
/** Optional description from the entry agent */
|
|
3435
|
+
description?: string;
|
|
3436
|
+
}
|
|
3437
|
+
/**
|
|
3438
|
+
* Lazy loader type for packed definitions.
|
|
3439
|
+
*
|
|
3440
|
+
* Each definition in a packed package is wrapped in a function
|
|
3441
|
+
* that returns a Promise, enabling lazy loading.
|
|
3442
|
+
*
|
|
3443
|
+
* @example
|
|
3444
|
+
* ```typescript
|
|
3445
|
+
* export const tools = {
|
|
3446
|
+
* search: async (): Promise<ToolDefinition> => ({
|
|
3447
|
+
* description: 'Search for information',
|
|
3448
|
+
* execute: async (state, args) => { ... },
|
|
3449
|
+
* }),
|
|
3450
|
+
* } as const;
|
|
3451
|
+
* ```
|
|
3452
|
+
*/
|
|
3453
|
+
type DefinitionLoader<T> = () => Promise<T>;
|
|
3454
|
+
|
|
3455
|
+
/**
|
|
3456
|
+
* Standard shape for packed package exports.
|
|
3457
|
+
*
|
|
3458
|
+
* Every packed package exports this structure, enabling
|
|
3459
|
+
* consistent discovery and loading.
|
|
3460
|
+
*
|
|
3461
|
+
* @example
|
|
3462
|
+
* ```typescript
|
|
3463
|
+
* import type { PackedExports } from '@standardagents/spec';
|
|
3464
|
+
*
|
|
3465
|
+
* const pkg: PackedExports = await import('standardagent-my-workflow');
|
|
3466
|
+
* const tool = await pkg.tools.search();
|
|
3467
|
+
* ```
|
|
3468
|
+
*/
|
|
3469
|
+
interface PackedExports {
|
|
3470
|
+
/** Agent definitions, keyed by name */
|
|
3471
|
+
agents: Record<string, DefinitionLoader<AgentDefinition>>;
|
|
3472
|
+
/** Prompt definitions, keyed by name */
|
|
3473
|
+
prompts: Record<string, DefinitionLoader<PromptDefinition>>;
|
|
3474
|
+
/** Tool definitions, keyed by name */
|
|
3475
|
+
tools: Record<string, DefinitionLoader<ToolDefinition<unknown, any, any>>>;
|
|
3476
|
+
/** Model definitions, keyed by name */
|
|
3477
|
+
models: Record<string, DefinitionLoader<ModelDefinition>>;
|
|
3478
|
+
/** Hook definitions, keyed by name */
|
|
3479
|
+
hooks: Record<string, DefinitionLoader<HookSignatures[keyof HookSignatures]>>;
|
|
3480
|
+
/** Package metadata */
|
|
3481
|
+
__meta: PackedMeta;
|
|
3482
|
+
}
|
|
3483
|
+
|
|
3484
|
+
export { type AgentDefinition, type AgentType, type AttachmentRef, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type DefineToolOptions, type DefinitionLoader, type Effect, type EffectDefinition, type EmptyUsesState, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type MarkedThreadEndpoint, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type NamespaceContext, type PackageSignature, type PackedExports, type PackedMeta, type PackedMetadata, type PackedNamespaceContext, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, ProviderError, type ProviderErrorCode, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderModelInfo, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUserMessage, type ProviderWebSearchResult, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type ScheduledEffect, type SideConfig, type StructuredPrompt, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type UsesAwareExecute, type UsesConstrainedState, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, isPacked, isThreadEndpoint, isVisibleInNamespace, mapReasoningLevel, validateToolName };
|