@standardagents/spec 0.43.1 → 0.44.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 +179 -152
- package/dist/index.js +77 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -409,6 +409,7 @@ type ResolveUsesState<Uses extends readonly string[]> = IsEmptyArray<Uses> exten
|
|
|
409
409
|
* @template Uses - Readonly array of allowed tool names
|
|
410
410
|
*/
|
|
411
411
|
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>;
|
|
412
|
+
type ToolAnnotations = Record<string, unknown>;
|
|
412
413
|
/**
|
|
413
414
|
* Options for defining a tool.
|
|
414
415
|
*
|
|
@@ -420,6 +421,7 @@ type UsesAwareExecute<State, Args extends ToolArgs | null, Uses extends readonly
|
|
|
420
421
|
interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null, Uses extends readonly string[] = readonly string[]> {
|
|
421
422
|
/** Description of what the tool does (shown to the LLM). */
|
|
422
423
|
description: string;
|
|
424
|
+
annotations?: ToolAnnotations;
|
|
423
425
|
/** Zod schema for validating tool arguments. Omit for tools with no args. */
|
|
424
426
|
args?: Args;
|
|
425
427
|
/** The tool implementation function. */
|
|
@@ -527,6 +529,7 @@ interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null =
|
|
|
527
529
|
interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null, Uses extends readonly string[] = readonly string[]> {
|
|
528
530
|
/** Description of what the tool does (shown to the LLM). */
|
|
529
531
|
description: string;
|
|
532
|
+
annotations?: ToolAnnotations;
|
|
530
533
|
/** Zod schema for validating tool arguments, or null for no args. */
|
|
531
534
|
args: Args;
|
|
532
535
|
/** The tool implementation function. */
|
|
@@ -882,6 +885,8 @@ interface ProviderRequest {
|
|
|
882
885
|
stopSequences?: string[];
|
|
883
886
|
reasoning?: {
|
|
884
887
|
level?: number;
|
|
888
|
+
/** The model definition map takes precedence over the provider catalog. */
|
|
889
|
+
levels?: Record<number, string | null>;
|
|
885
890
|
maxTokens?: number;
|
|
886
891
|
exclude?: boolean;
|
|
887
892
|
};
|
|
@@ -923,7 +928,6 @@ interface ProviderToolMessage {
|
|
|
923
928
|
toolCallId: string;
|
|
924
929
|
toolName: string;
|
|
925
930
|
content: ProviderToolResultContent;
|
|
926
|
-
attachments?: ProviderAttachment[];
|
|
927
931
|
}
|
|
928
932
|
/**
|
|
929
933
|
* Attachment on a provider message (loaded from storage, ready for provider-specific transformation)
|
|
@@ -1215,6 +1219,13 @@ declare class ProviderError extends Error {
|
|
|
1215
1219
|
*/
|
|
1216
1220
|
get isRetryable(): boolean;
|
|
1217
1221
|
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Optional provider helper for reasoning discovery before dispatch.
|
|
1224
|
+
* A catalog lookup may delay a request by at most 250 ms.
|
|
1225
|
+
* Request aborts reject the wait; failures and timeouts omit discovered levels.
|
|
1226
|
+
* Declared levels bypass discovery. The catalog may continue filling its cache.
|
|
1227
|
+
*/
|
|
1228
|
+
declare function resolveRequestReasoningLevels(request: ProviderRequest, lookup: (model: string) => Promise<ModelCapabilities | null>): Promise<ModelCapabilities['reasoningLevels']>;
|
|
1218
1229
|
/**
|
|
1219
1230
|
* Maps a 0-100 reasoning level to the model's nearest supported level
|
|
1220
1231
|
*/
|
|
@@ -1404,7 +1415,10 @@ declare function defineEffect<State = ThreadState>(description: string, handler:
|
|
|
1404
1415
|
* id; a runtime with exactly one principal resolves all requests to a single
|
|
1405
1416
|
* constant user id.
|
|
1406
1417
|
*/
|
|
1407
|
-
type UserIdentity = ThreadUser
|
|
1418
|
+
type UserIdentity = Omit<ThreadUser, 'username' | 'role'> & {
|
|
1419
|
+
username?: string | null;
|
|
1420
|
+
role?: string | null;
|
|
1421
|
+
};
|
|
1408
1422
|
/**
|
|
1409
1423
|
* A client attached to the user event stream, as reported to user lifecycle
|
|
1410
1424
|
* hooks. `kind` is a client-declared label (for example `"cli"`, `"web"`).
|
|
@@ -1913,7 +1927,7 @@ interface SubagentRegistryEntry {
|
|
|
1913
1927
|
reference: string;
|
|
1914
1928
|
/**
|
|
1915
1929
|
* The relationship name this instance was spawned under — the `as` name
|
|
1916
|
-
* (defaulting to the agent
|
|
1930
|
+
* (defaulting to the unqualified part of `agent`) of the owning side's declaration. This is
|
|
1917
1931
|
* the name lifecycle tools address; `name` is the implementing agent
|
|
1918
1932
|
* definition.
|
|
1919
1933
|
*/
|
|
@@ -3712,7 +3726,7 @@ interface ProviderDefinition<N extends string = string, Base extends ProviderFac
|
|
|
3712
3726
|
* ```
|
|
3713
3727
|
*/
|
|
3714
3728
|
interface ProviderFactoryWithOptions<TOptions extends ZodTypeAny = ZodTypeAny> {
|
|
3715
|
-
(config: ProviderFactoryConfig): ProviderInstance;
|
|
3729
|
+
(config: ProviderFactoryConfig, context?: Pick<ProviderOverrideContext, 'state'>): ProviderInstance;
|
|
3716
3730
|
/** Zod schema for provider-specific options */
|
|
3717
3731
|
providerOptions?: TOptions;
|
|
3718
3732
|
/** Connection-level config slots accepted by this provider factory */
|
|
@@ -3762,7 +3776,7 @@ interface ModelCapabilities {
|
|
|
3762
3776
|
*
|
|
3763
3777
|
* @example
|
|
3764
3778
|
* // OpenAI o-series
|
|
3765
|
-
* reasoningLevels: { 0:
|
|
3779
|
+
* reasoningLevels: { 0: 'low', 33: 'low', 66: 'medium', 100: 'high' }
|
|
3766
3780
|
*
|
|
3767
3781
|
* @example
|
|
3768
3782
|
* // Binary reasoning (Claude extended thinking)
|
|
@@ -4212,31 +4226,26 @@ type SubagentToolConfig<T extends string = string> = never;
|
|
|
4212
4226
|
interface ReasoningConfig {
|
|
4213
4227
|
/**
|
|
4214
4228
|
* Numeric reasoning level on a 0-100 scale.
|
|
4215
|
-
*
|
|
4229
|
+
* An unset level uses the model's default. Level 0 requests the least reasoning.
|
|
4230
|
+
* Providers disable reasoning when supported or select the lowest native setting.
|
|
4231
|
+
* Each provider maps this to the model's nearest declared reasoning option.
|
|
4232
|
+
* A level replaces native effort in providerOptions and preserves other keys.
|
|
4233
|
+
* Without a level, providerOptions apply as provided.
|
|
4234
|
+
* Native effort in model providerOptions remains valid.
|
|
4235
|
+
* Saved input with reasoning.effort fails validation.
|
|
4236
|
+
* A published package prompt with reasoning.effort loads with a warning.
|
|
4237
|
+
* The runtime ignores that field.
|
|
4216
4238
|
*
|
|
4217
4239
|
* @example
|
|
4218
4240
|
* // Typical breakpoints:
|
|
4219
|
-
* // 0 =
|
|
4241
|
+
* // 0 = Least reasoning
|
|
4220
4242
|
* // 33 = Low effort
|
|
4221
4243
|
* // 66 = Medium effort
|
|
4222
4244
|
* // 100 = Maximum effort
|
|
4223
4245
|
*
|
|
4224
|
-
* reasoning: { level:
|
|
4246
|
+
* reasoning: { level: 90 } // Maps to 'high' on most models
|
|
4225
4247
|
*/
|
|
4226
4248
|
level?: number;
|
|
4227
|
-
/**
|
|
4228
|
-
* @deprecated Use `level` instead. Will be removed in future versions.
|
|
4229
|
-
*
|
|
4230
|
-
* Effort level for reasoning models.
|
|
4231
|
-
* Higher effort = more thinking tokens = potentially better results.
|
|
4232
|
-
*
|
|
4233
|
-
* - `low`: Minimal reasoning, faster responses (equivalent to level ~33)
|
|
4234
|
-
* - `medium`: Balanced reasoning and speed (equivalent to level ~66)
|
|
4235
|
-
* - `high`: Maximum reasoning, slower but more thorough (equivalent to level ~100)
|
|
4236
|
-
*
|
|
4237
|
-
* @default undefined (use model defaults)
|
|
4238
|
-
*/
|
|
4239
|
-
effort?: 'low' | 'medium' | 'high';
|
|
4240
4249
|
/**
|
|
4241
4250
|
* Maximum tokens to allocate for reasoning.
|
|
4242
4251
|
* Applies to models that support token limits on reasoning.
|
|
@@ -4521,7 +4530,11 @@ interface SubagentRelationship<Agent extends string = StandardAgentSpec.Agents>
|
|
|
4521
4530
|
*/
|
|
4522
4531
|
readonly agent: Agent;
|
|
4523
4532
|
/**
|
|
4524
|
-
* Relationship name; defaults to `agent`.
|
|
4533
|
+
* Relationship name; defaults to the unqualified part of `agent`.
|
|
4534
|
+
* A packed definition uses `{packageId}/{name}`.
|
|
4535
|
+
* For `@scope/pkg/agent`, the package is `@scope/pkg` and the name is `agent`.
|
|
4536
|
+
* `@scope/name` is unqualified.
|
|
4537
|
+
* Type registries include qualified packed entry agents and exclude package internals.
|
|
4525
4538
|
*
|
|
4526
4539
|
* This is the tool-surface name, the registry identity, and the name the
|
|
4527
4540
|
* lifecycle tools' `agent` argument enumerates. Aliasing lets the same
|
|
@@ -4792,12 +4805,12 @@ interface PromptSide<Prompt extends string = StandardAgentSpec.Prompts, Callable
|
|
|
4792
4805
|
/**
|
|
4793
4806
|
* Stop this side's turn when a specific tool is called.
|
|
4794
4807
|
* Overrides stopOnResponse when the named tool is invoked.
|
|
4795
|
-
*
|
|
4808
|
+
* Set stopToolResponseProperty to extract the result from the tool call.
|
|
4796
4809
|
*/
|
|
4797
4810
|
readonly stopTool?: Callable;
|
|
4798
4811
|
/**
|
|
4799
4812
|
* Property to extract from the stop tool's result.
|
|
4800
|
-
*
|
|
4813
|
+
* Valid only when stopTool is set.
|
|
4801
4814
|
* The extracted value is used to determine the conversation outcome.
|
|
4802
4815
|
*/
|
|
4803
4816
|
readonly stopToolResponseProperty?: string;
|
|
@@ -5006,7 +5019,7 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
|
|
|
5006
5019
|
readonly icon?: string;
|
|
5007
5020
|
/**
|
|
5008
5021
|
* Environment values provided by this agent.
|
|
5009
|
-
*
|
|
5022
|
+
* Resolution precedence is thread, agent, prompt, user, then instance.
|
|
5010
5023
|
*/
|
|
5011
5024
|
readonly env?: Readonly<Record<string, string>>;
|
|
5012
5025
|
/**
|
|
@@ -5135,6 +5148,131 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
|
|
|
5135
5148
|
*/
|
|
5136
5149
|
declare function defineAgent<N extends string>(options: AgentDefinition<N>): AgentDefinition<N>;
|
|
5137
5150
|
|
|
5151
|
+
/**
|
|
5152
|
+
* Handler definition types for Standard Agents.
|
|
5153
|
+
*
|
|
5154
|
+
* A handler is a function that takes one side's turns in a conversation.
|
|
5155
|
+
* When a side of an agent is backed by a handler, the runtime does not call
|
|
5156
|
+
* a model to answer an inbound message — it calls the handler function once,
|
|
5157
|
+
* with the thread state and the message, and whatever that function does is
|
|
5158
|
+
* the side's turn.
|
|
5159
|
+
*
|
|
5160
|
+
* A handler is NOT a hook (hooks decorate turns owned by something else, and
|
|
5161
|
+
* their failures are non-fatal), NOT a tool (tools are capabilities a
|
|
5162
|
+
* turn-owner chooses to invoke), and NOT an effect (effects run outside the
|
|
5163
|
+
* conversation flow). Its only seat is backing a side of an agent: handlers
|
|
5164
|
+
* MUST NOT be referenced by prompt `tools` arrays, hook lists, or effect
|
|
5165
|
+
* schedules, and implementations MUST reject such references at definition
|
|
5166
|
+
* time.
|
|
5167
|
+
*
|
|
5168
|
+
* https://standardagentspec.com/0.2.0/specification/handlers
|
|
5169
|
+
*
|
|
5170
|
+
* @module
|
|
5171
|
+
*/
|
|
5172
|
+
|
|
5173
|
+
/**
|
|
5174
|
+
* Brand marking a value as a handler definition.
|
|
5175
|
+
*
|
|
5176
|
+
* The brand makes `HandlerDefinition` structurally unassignable to tool,
|
|
5177
|
+
* hook, and effect positions, so a handler referenced where those are
|
|
5178
|
+
* expected fails to compile wherever TypeScript can see the reference.
|
|
5179
|
+
* Implementations additionally reject by-name references that types cannot
|
|
5180
|
+
* catch during their definition-registry pass.
|
|
5181
|
+
*/
|
|
5182
|
+
declare const HANDLER_SYMBOL: unique symbol;
|
|
5183
|
+
/**
|
|
5184
|
+
* A handler definition — deterministic code that owns one side's turns.
|
|
5185
|
+
*
|
|
5186
|
+
* Execution model (one turn):
|
|
5187
|
+
* 1. An inbound message arrives on the side's perspective.
|
|
5188
|
+
* 2. The runtime invokes `execute` once with the thread's `ThreadState` and
|
|
5189
|
+
* that message.
|
|
5190
|
+
* 3. The invocation returns (or throws). The turn is complete.
|
|
5191
|
+
*
|
|
5192
|
+
* There are no steps, no tool-choice loop, and no model requests for a
|
|
5193
|
+
* handler-backed side. When the agent sets `maxSessionTurns`, a handler turn
|
|
5194
|
+
* counts toward the exchange cap exactly like a prompt turn.
|
|
5195
|
+
*
|
|
5196
|
+
* Delivery is exactly-once per message, in message persistence order, one
|
|
5197
|
+
* invocation at a time per thread; messages that arrive while a turn is in
|
|
5198
|
+
* flight wait in the queue. A failed invocation is never automatically
|
|
5199
|
+
* redelivered — retry is a userland decision.
|
|
5200
|
+
*
|
|
5201
|
+
* Errors are fatal to the turn, and only the turn: the turn is marked failed
|
|
5202
|
+
* as a runtime-origin failure, the inbound message stays persisted, and the
|
|
5203
|
+
* session continues. A handler ends sessions explicitly via
|
|
5204
|
+
* `state.stopSession()`.
|
|
5205
|
+
*
|
|
5206
|
+
* @template State - The thread state type (defaults to {@link ThreadState})
|
|
5207
|
+
*/
|
|
5208
|
+
interface HandlerDefinition<State = ThreadState> {
|
|
5209
|
+
/** Optional human-facing summary of what this handler does. */
|
|
5210
|
+
readonly description?: string;
|
|
5211
|
+
/**
|
|
5212
|
+
* The turn implementation.
|
|
5213
|
+
*
|
|
5214
|
+
* Receives the full `ThreadState` — it may forward (`queueMessage` toward a
|
|
5215
|
+
* child), respond (`injectMessage` as its own side's role), spawn children,
|
|
5216
|
+
* stop the session, and read/write thread values: anything tools can do.
|
|
5217
|
+
*
|
|
5218
|
+
* The `message` parameter is the full persisted {@link Message} — id, role,
|
|
5219
|
+
* content, silent flag, metadata, timestamps — not a narrowed view:
|
|
5220
|
+
* handlers are trusted definition code, like tools.
|
|
5221
|
+
*
|
|
5222
|
+
* There is no auto-reply channel: the runtime routes inbound; userland
|
|
5223
|
+
* decides outbound. If the handler wants to speak outward, that is code in
|
|
5224
|
+
* this function.
|
|
5225
|
+
*/
|
|
5226
|
+
readonly execute: (state: State, message: Message) => Promise<void>;
|
|
5227
|
+
readonly [HANDLER_SYMBOL]: true;
|
|
5228
|
+
}
|
|
5229
|
+
/**
|
|
5230
|
+
* Options accepted by {@link defineHandler}.
|
|
5231
|
+
*
|
|
5232
|
+
* @template State - The thread state type (defaults to {@link ThreadState})
|
|
5233
|
+
*/
|
|
5234
|
+
interface DefineHandlerOptions<State = ThreadState> {
|
|
5235
|
+
/** Optional human-facing summary of what this handler does. */
|
|
5236
|
+
readonly description?: string;
|
|
5237
|
+
/** The turn implementation. See {@link HandlerDefinition.execute}. */
|
|
5238
|
+
readonly execute: (state: State, message: Message) => Promise<void>;
|
|
5239
|
+
}
|
|
5240
|
+
/**
|
|
5241
|
+
* Defines a handler — deterministic code that backs one side of an agent and
|
|
5242
|
+
* takes that side's turns in place of a model.
|
|
5243
|
+
*
|
|
5244
|
+
* Handlers live in their own definition directory (`agents/handlers/` in the
|
|
5245
|
+
* conventional layout). The handler's name is derived from its file name and
|
|
5246
|
+
* referenced from exactly one place: the `handler` property of a side
|
|
5247
|
+
* configuration.
|
|
5248
|
+
*
|
|
5249
|
+
* @template State - The thread state type (defaults to {@link ThreadState})
|
|
5250
|
+
* @param options - Handler configuration options
|
|
5251
|
+
* @returns The branded handler definition for registration
|
|
5252
|
+
*
|
|
5253
|
+
* @example
|
|
5254
|
+
* ```typescript
|
|
5255
|
+
* // agents/handlers/relay_pipe.ts
|
|
5256
|
+
* import { defineHandler } from '@standardagents/spec';
|
|
5257
|
+
*
|
|
5258
|
+
* export default defineHandler({
|
|
5259
|
+
* description: 'Forwards inbound user traffic to the assistant child and relays answers back.',
|
|
5260
|
+
* execute: async (state, message) => {
|
|
5261
|
+
* const assistant = state.children.find(c => c.relationship === 'assistant_agent');
|
|
5262
|
+
* if (!assistant) return;
|
|
5263
|
+
* const child = await state.getChildThread(assistant.reference);
|
|
5264
|
+
* await child?.queueMessage({ role: 'user', content: message.content ?? '' });
|
|
5265
|
+
* },
|
|
5266
|
+
* });
|
|
5267
|
+
* ```
|
|
5268
|
+
*/
|
|
5269
|
+
declare function defineHandler<State = ThreadState>(options: DefineHandlerOptions<State>): HandlerDefinition<State>;
|
|
5270
|
+
/**
|
|
5271
|
+
* Type guard: is this value a handler definition created by
|
|
5272
|
+
* {@link defineHandler}?
|
|
5273
|
+
*/
|
|
5274
|
+
declare function isHandler(value: unknown): value is HandlerDefinition;
|
|
5275
|
+
|
|
5138
5276
|
/**
|
|
5139
5277
|
* Endpoint definition types for Standard Agents.
|
|
5140
5278
|
*
|
|
@@ -5663,6 +5801,8 @@ type DefinitionLoader<T> = () => Promise<T>;
|
|
|
5663
5801
|
* ```
|
|
5664
5802
|
*/
|
|
5665
5803
|
interface PackedExports {
|
|
5804
|
+
/** Handler definitions, keyed by name */
|
|
5805
|
+
handlers: Record<string, DefinitionLoader<HandlerDefinition>>;
|
|
5666
5806
|
/** Agent definitions, keyed by name */
|
|
5667
5807
|
agents: Record<string, DefinitionLoader<AgentDefinition>>;
|
|
5668
5808
|
/** Prompt definitions, keyed by name */
|
|
@@ -5693,6 +5833,18 @@ interface PackedExports {
|
|
|
5693
5833
|
/** Package metadata */
|
|
5694
5834
|
__meta: PackedMeta;
|
|
5695
5835
|
}
|
|
5836
|
+
/**
|
|
5837
|
+
* Parse a potentially qualified name into package ID and short name.
|
|
5838
|
+
*
|
|
5839
|
+
* For scoped npm packages (starting with @), the format is @scope/pkg-name/item-name
|
|
5840
|
+
* where @scope/pkg-name is the package and item-name is the short name.
|
|
5841
|
+
*
|
|
5842
|
+
* For non-scoped packages, the format is pkg-name/item-name.
|
|
5843
|
+
*
|
|
5844
|
+
* @param name - The name to parse (e.g., 'tool', 'pkg/tool', or '@scope/pkg/tool')
|
|
5845
|
+
* @returns Tuple of [packageId, shortName] where packageId is null for unqualified names
|
|
5846
|
+
*/
|
|
5847
|
+
declare function parseQualifiedName(name: string): [string | null, string];
|
|
5696
5848
|
|
|
5697
5849
|
/**
|
|
5698
5850
|
* Hook definition types for Standard Agents.
|
|
@@ -6271,131 +6423,6 @@ interface HookDefinitionResult<K extends HookName> {
|
|
|
6271
6423
|
*/
|
|
6272
6424
|
declare function defineHook<K extends HookName>(options: HookDefinitionOptions<K>): HookDefinitionResult<K>;
|
|
6273
6425
|
|
|
6274
|
-
/**
|
|
6275
|
-
* Handler definition types for Standard Agents.
|
|
6276
|
-
*
|
|
6277
|
-
* A handler is a function that takes one side's turns in a conversation.
|
|
6278
|
-
* When a side of an agent is backed by a handler, the runtime does not call
|
|
6279
|
-
* a model to answer an inbound message — it calls the handler function once,
|
|
6280
|
-
* with the thread state and the message, and whatever that function does is
|
|
6281
|
-
* the side's turn.
|
|
6282
|
-
*
|
|
6283
|
-
* A handler is NOT a hook (hooks decorate turns owned by something else, and
|
|
6284
|
-
* their failures are non-fatal), NOT a tool (tools are capabilities a
|
|
6285
|
-
* turn-owner chooses to invoke), and NOT an effect (effects run outside the
|
|
6286
|
-
* conversation flow). Its only seat is backing a side of an agent: handlers
|
|
6287
|
-
* MUST NOT be referenced by prompt `tools` arrays, hook lists, or effect
|
|
6288
|
-
* schedules, and implementations MUST reject such references at definition
|
|
6289
|
-
* time.
|
|
6290
|
-
*
|
|
6291
|
-
* https://standardagentspec.com/0.2.0/specification/handlers
|
|
6292
|
-
*
|
|
6293
|
-
* @module
|
|
6294
|
-
*/
|
|
6295
|
-
|
|
6296
|
-
/**
|
|
6297
|
-
* Brand marking a value as a handler definition.
|
|
6298
|
-
*
|
|
6299
|
-
* The brand makes `HandlerDefinition` structurally unassignable to tool,
|
|
6300
|
-
* hook, and effect positions, so a handler referenced where those are
|
|
6301
|
-
* expected fails to compile wherever TypeScript can see the reference.
|
|
6302
|
-
* Implementations additionally reject by-name references that types cannot
|
|
6303
|
-
* catch during their definition-registry pass.
|
|
6304
|
-
*/
|
|
6305
|
-
declare const HANDLER_SYMBOL: unique symbol;
|
|
6306
|
-
/**
|
|
6307
|
-
* A handler definition — deterministic code that owns one side's turns.
|
|
6308
|
-
*
|
|
6309
|
-
* Execution model (one turn):
|
|
6310
|
-
* 1. An inbound message arrives on the side's perspective.
|
|
6311
|
-
* 2. The runtime invokes `execute` once with the thread's `ThreadState` and
|
|
6312
|
-
* that message.
|
|
6313
|
-
* 3. The invocation returns (or throws). The turn is complete.
|
|
6314
|
-
*
|
|
6315
|
-
* There are no steps, no tool-choice loop, and no model requests for a
|
|
6316
|
-
* handler-backed side. When the agent sets `maxSessionTurns`, a handler turn
|
|
6317
|
-
* counts toward the exchange cap exactly like a prompt turn.
|
|
6318
|
-
*
|
|
6319
|
-
* Delivery is exactly-once per message, in message persistence order, one
|
|
6320
|
-
* invocation at a time per thread; messages that arrive while a turn is in
|
|
6321
|
-
* flight wait in the queue. A failed invocation is never automatically
|
|
6322
|
-
* redelivered — retry is a userland decision.
|
|
6323
|
-
*
|
|
6324
|
-
* Errors are fatal to the turn, and only the turn: the turn is marked failed
|
|
6325
|
-
* as a runtime-origin failure, the inbound message stays persisted, and the
|
|
6326
|
-
* session continues. A handler ends sessions explicitly via
|
|
6327
|
-
* `state.stopSession()`.
|
|
6328
|
-
*
|
|
6329
|
-
* @template State - The thread state type (defaults to {@link ThreadState})
|
|
6330
|
-
*/
|
|
6331
|
-
interface HandlerDefinition<State = ThreadState> {
|
|
6332
|
-
/** Optional human-facing summary of what this handler does. */
|
|
6333
|
-
readonly description?: string;
|
|
6334
|
-
/**
|
|
6335
|
-
* The turn implementation.
|
|
6336
|
-
*
|
|
6337
|
-
* Receives the full `ThreadState` — it may forward (`queueMessage` toward a
|
|
6338
|
-
* child), respond (`injectMessage` as its own side's role), spawn children,
|
|
6339
|
-
* stop the session, and read/write thread values: anything tools can do.
|
|
6340
|
-
*
|
|
6341
|
-
* The `message` parameter is the full persisted {@link Message} — id, role,
|
|
6342
|
-
* content, silent flag, metadata, timestamps — not a narrowed view:
|
|
6343
|
-
* handlers are trusted definition code, like tools.
|
|
6344
|
-
*
|
|
6345
|
-
* There is no auto-reply channel: the runtime routes inbound; userland
|
|
6346
|
-
* decides outbound. If the handler wants to speak outward, that is code in
|
|
6347
|
-
* this function.
|
|
6348
|
-
*/
|
|
6349
|
-
readonly execute: (state: State, message: Message) => Promise<void>;
|
|
6350
|
-
readonly [HANDLER_SYMBOL]: true;
|
|
6351
|
-
}
|
|
6352
|
-
/**
|
|
6353
|
-
* Options accepted by {@link defineHandler}.
|
|
6354
|
-
*
|
|
6355
|
-
* @template State - The thread state type (defaults to {@link ThreadState})
|
|
6356
|
-
*/
|
|
6357
|
-
interface DefineHandlerOptions<State = ThreadState> {
|
|
6358
|
-
/** Optional human-facing summary of what this handler does. */
|
|
6359
|
-
readonly description?: string;
|
|
6360
|
-
/** The turn implementation. See {@link HandlerDefinition.execute}. */
|
|
6361
|
-
readonly execute: (state: State, message: Message) => Promise<void>;
|
|
6362
|
-
}
|
|
6363
|
-
/**
|
|
6364
|
-
* Defines a handler — deterministic code that backs one side of an agent and
|
|
6365
|
-
* takes that side's turns in place of a model.
|
|
6366
|
-
*
|
|
6367
|
-
* Handlers live in their own definition directory (`agents/handlers/` in the
|
|
6368
|
-
* conventional layout). The handler's name is derived from its file name and
|
|
6369
|
-
* referenced from exactly one place: the `handler` property of a side
|
|
6370
|
-
* configuration.
|
|
6371
|
-
*
|
|
6372
|
-
* @template State - The thread state type (defaults to {@link ThreadState})
|
|
6373
|
-
* @param options - Handler configuration options
|
|
6374
|
-
* @returns The branded handler definition for registration
|
|
6375
|
-
*
|
|
6376
|
-
* @example
|
|
6377
|
-
* ```typescript
|
|
6378
|
-
* // agents/handlers/relay_pipe.ts
|
|
6379
|
-
* import { defineHandler } from '@standardagents/spec';
|
|
6380
|
-
*
|
|
6381
|
-
* export default defineHandler({
|
|
6382
|
-
* description: 'Forwards inbound user traffic to the assistant child and relays answers back.',
|
|
6383
|
-
* execute: async (state, message) => {
|
|
6384
|
-
* const assistant = state.children.find(c => c.relationship === 'assistant_agent');
|
|
6385
|
-
* if (!assistant) return;
|
|
6386
|
-
* const child = await state.getChildThread(assistant.reference);
|
|
6387
|
-
* await child?.queueMessage({ role: 'user', content: message.content ?? '' });
|
|
6388
|
-
* },
|
|
6389
|
-
* });
|
|
6390
|
-
* ```
|
|
6391
|
-
*/
|
|
6392
|
-
declare function defineHandler<State = ThreadState>(options: DefineHandlerOptions<State>): HandlerDefinition<State>;
|
|
6393
|
-
/**
|
|
6394
|
-
* Type guard: is this value a handler definition created by
|
|
6395
|
-
* {@link defineHandler}?
|
|
6396
|
-
*/
|
|
6397
|
-
declare function isHandler(value: unknown): value is HandlerDefinition;
|
|
6398
|
-
|
|
6399
6426
|
/**
|
|
6400
6427
|
* Pure definition-time validation for Standard Agents.
|
|
6401
6428
|
*
|
|
@@ -6416,7 +6443,7 @@ declare function isHandler(value: unknown): value is HandlerDefinition;
|
|
|
6416
6443
|
/**
|
|
6417
6444
|
* Every issue code `validateAgentDefinition` can emit.
|
|
6418
6445
|
*/
|
|
6419
|
-
declare const DEFINITION_ISSUE_CODES: readonly ["agent_name_missing", "agent_name_invalid", "agent_side_missing", "agent_side_invalid", "agent_side_backing_missing", "agent_side_backing_conflict", "agent_side_option_invalid_for_backing", "agent_subagents_on_human_side", "agent_both_sides_human", "agent_legacy_type", "agent_session_binding_legacy_string", "agent_session_binding_invalid", "
|
|
6446
|
+
declare const DEFINITION_ISSUE_CODES: readonly ["agent_name_missing", "agent_name_invalid", "agent_side_missing", "agent_side_invalid", "agent_side_backing_missing", "agent_side_backing_conflict", "agent_side_option_invalid_for_backing", "agent_subagents_on_human_side", "agent_both_sides_human", "agent_legacy_type", "agent_session_binding_legacy_string", "agent_session_binding_invalid", "agent_max_steps_invalid", "agent_stop_tool_missing", "agent_max_session_turns_invalid", "agent_tool_description_missing", "agent_parent_hooks_invalid", "agent_tenvs_deprecated", "subagent_agent_missing", "subagent_relationship_invalid", "subagent_relationship_duplicate", "subagent_relationship_reserved_name", "subagent_max_instances_invalid", "subagent_legacy_name", "subagent_legacy_resumable", "subagent_legacy_receives_messages"];
|
|
6420
6447
|
/**
|
|
6421
6448
|
* Union of all definition issue codes.
|
|
6422
6449
|
*/
|
|
@@ -6469,4 +6496,4 @@ declare function validateAgentDefinition(def: unknown): DefinitionIssue[];
|
|
|
6469
6496
|
*/
|
|
6470
6497
|
declare const SPEC_VERSION = "0.2.0";
|
|
6471
6498
|
|
|
6472
|
-
export { type AgentDefinition, type AgentType, type AttachmentRef, type CodeExecution, type CodeExecutionError, type CodeExecutionLog, type CodeExecutionOptions, type CodeExecutionResult, type CodeExecutionStatus, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type CreateFetch, type CredentialGrant, DEFINITION_ISSUE_CODES, type DecideOptions, type DecisionAnswer, type DecisionAnswers, type DecisionBooleanAnswer, type DecisionChoiceAnswer, type DecisionContext, type DecisionJson, type DecisionProviderFactory, type DecisionProviderInterface, type DecisionQuestion, type DecisionQuestions, type DecisionRequest, type DecisionResult, type DecisionScoreAnswer, type DefineHandlerOptions, type DefineToolOptions, type DefinitionIssue, type DefinitionIssueCode, type DefinitionLoader, ENDPOINT_ACCESS_SYMBOL, type Effect, type EffectDefinition, type EmptyUsesState, type EndpointAccess, type EndpointOptions, type EnvValueType, type ErrorOrigin, type ExecutionState, type FetchLike, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, HANDLER_SYMBOL, type HandlerDefinition, type HandlerSide, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookExecutionContext, type HookExecutionSource, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type HumanSide, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type ListUserThreadsOptions, type ListUserValuesOptions, type MarkedThreadEndpoint, type MarkedUserEndpoint, type MarkedUserRoom, 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 ParentHookRequirement, type ParentHookStage, type PromptContent, type PromptDefinition, type PromptEnvPart, type PromptIncludePart, type PromptInput, type PromptPart, type PromptSide, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, type ProviderConfigSlot, type ProviderConfigSlots, type ProviderConfigValueSource, type ProviderDefinition, ProviderError, type ProviderErrorCode, type ProviderErrorOptions, type ProviderExecutedToolResult, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderMethodOverrides, type ProviderModelInfo, type ProviderModelsPage, type ProviderModelsQuery, type ProviderOverride, type ProviderOverrideContext, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSyncOverride, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUsagePricing, type ProviderUserMessage, type ProviderWebSearchResult, type QueueMessageInput, RESERVED_RELATIONSHIP_NAMES, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type RuntimeByteStream, type RuntimeStreamErrorCode, type RuntimeStreamRequest, type RuntimeStreamResult, type RuntimeStreams, SPEC_VERSION, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SetEnvOptions, type SideConfig, type SkillFileInput, type SkillMetadata, type SkillsNamespace, type StopSessionOptions, type StructuredPrompt, type SubagentRegistryEntry, type SubagentRelationship, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, THREAD_STREAM_REASONING_PARAM, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointAuth, type ThreadEndpointHandler, type ThreadEndpointRouteParams, type ThreadHookName, type ThreadMessageChunkEvent, type ThreadMetadata, type ThreadReasoningChunkEvent, type ThreadRunState, type ThreadState, type ThreadStatus, type ThreadStatusEvent, type ThreadUser, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type ToolVariables, USER_ENDPOINT_SYMBOL, USER_ROOM_SYMBOL, type UserClientInfo, type UserEndpointHandler, type UserEndpointRouteParams, type UserHandle, type UserIdentity, type UserRoomAttachments, type UserRoomConnection, type UserRoomDefinition, type UserRoomFrame, type UserRoomPresenceEvent, type UserState, type UserThreadSummary, type UserValueEntry, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, decide, defineAgent, defineController, defineEffect, defineHandler, defineHook, defineModel, definePrompt, defineProvider, defineThreadEndpoint, defineTool, defineUserEndpoint, defineUserRoom, getEndpointAccess, isHandler, isPacked, isThreadEndpoint, isUserEndpoint, isUserRoom, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue, validateAgentDefinition, validateToolName };
|
|
6499
|
+
export { type AgentDefinition, type AgentType, type AttachmentRef, type CodeExecution, type CodeExecutionError, type CodeExecutionLog, type CodeExecutionOptions, type CodeExecutionResult, type CodeExecutionStatus, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type CreateFetch, type CredentialGrant, DEFINITION_ISSUE_CODES, type DecideOptions, type DecisionAnswer, type DecisionAnswers, type DecisionBooleanAnswer, type DecisionChoiceAnswer, type DecisionContext, type DecisionJson, type DecisionProviderFactory, type DecisionProviderInterface, type DecisionQuestion, type DecisionQuestions, type DecisionRequest, type DecisionResult, type DecisionScoreAnswer, type DefineHandlerOptions, type DefineToolOptions, type DefinitionIssue, type DefinitionIssueCode, type DefinitionLoader, ENDPOINT_ACCESS_SYMBOL, type Effect, type EffectDefinition, type EmptyUsesState, type EndpointAccess, type EndpointOptions, type EnvValueType, type ErrorOrigin, type ExecutionState, type FetchLike, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, HANDLER_SYMBOL, type HandlerDefinition, type HandlerSide, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookExecutionContext, type HookExecutionSource, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type HumanSide, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type ListUserThreadsOptions, type ListUserValuesOptions, type MarkedThreadEndpoint, type MarkedUserEndpoint, type MarkedUserRoom, 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 ParentHookRequirement, type ParentHookStage, type PromptContent, type PromptDefinition, type PromptEnvPart, type PromptIncludePart, type PromptInput, type PromptPart, type PromptSide, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, type ProviderConfigSlot, type ProviderConfigSlots, type ProviderConfigValueSource, type ProviderDefinition, ProviderError, type ProviderErrorCode, type ProviderErrorOptions, type ProviderExecutedToolResult, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderMethodOverrides, type ProviderModelInfo, type ProviderModelsPage, type ProviderModelsQuery, type ProviderOverride, type ProviderOverrideContext, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSyncOverride, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUsagePricing, type ProviderUserMessage, type ProviderWebSearchResult, type QueueMessageInput, RESERVED_RELATIONSHIP_NAMES, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type RuntimeByteStream, type RuntimeStreamErrorCode, type RuntimeStreamRequest, type RuntimeStreamResult, type RuntimeStreams, SPEC_VERSION, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SetEnvOptions, type SideConfig, type SkillFileInput, type SkillMetadata, type SkillsNamespace, type StopSessionOptions, type StructuredPrompt, type SubagentRegistryEntry, type SubagentRelationship, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, THREAD_STREAM_REASONING_PARAM, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointAuth, type ThreadEndpointHandler, type ThreadEndpointRouteParams, type ThreadHookName, type ThreadMessageChunkEvent, type ThreadMetadata, type ThreadReasoningChunkEvent, type ThreadRunState, type ThreadState, type ThreadStatus, type ThreadStatusEvent, type ThreadUser, type Tool, type ToolAnnotations, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type ToolVariables, USER_ENDPOINT_SYMBOL, USER_ROOM_SYMBOL, type UserClientInfo, type UserEndpointHandler, type UserEndpointRouteParams, type UserHandle, type UserIdentity, type UserRoomAttachments, type UserRoomConnection, type UserRoomDefinition, type UserRoomFrame, type UserRoomPresenceEvent, type UserState, type UserThreadSummary, type UserValueEntry, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, decide, defineAgent, defineController, defineEffect, defineHandler, defineHook, defineModel, definePrompt, defineProvider, defineThreadEndpoint, defineTool, defineUserEndpoint, defineUserRoom, getEndpointAccess, isHandler, isPacked, isThreadEndpoint, isUserEndpoint, isUserRoom, isVisibleInNamespace, mapReasoningLevel, parseQualifiedName, providerConst, providerEnv, providerValue, resolveRequestReasoningLevels, validateAgentDefinition, validateToolName };
|