@standardagents/spec 0.43.0 → 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 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 name) of the owning side's declaration. This is
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
  */
@@ -2562,7 +2576,11 @@ interface ExecutionState {
2562
2576
  readonly stopped: boolean;
2563
2577
  /** Which side initiated the stop (if stopped) */
2564
2578
  readonly stoppedBy?: 'a' | 'b';
2565
- /** Live chronological persisted history for the current execution */
2579
+ /**
2580
+ * Live chronological persisted history for the current execution. With
2581
+ * the active prompt's `historyLimit`, only its newest window of
2582
+ * top-level messages (see `PromptDefinition.historyLimit`).
2583
+ */
2566
2584
  readonly messageHistory: Message[];
2567
2585
  /**
2568
2586
  * Force a specific side to play the next turn.
@@ -3708,7 +3726,7 @@ interface ProviderDefinition<N extends string = string, Base extends ProviderFac
3708
3726
  * ```
3709
3727
  */
3710
3728
  interface ProviderFactoryWithOptions<TOptions extends ZodTypeAny = ZodTypeAny> {
3711
- (config: ProviderFactoryConfig): ProviderInstance;
3729
+ (config: ProviderFactoryConfig, context?: Pick<ProviderOverrideContext, 'state'>): ProviderInstance;
3712
3730
  /** Zod schema for provider-specific options */
3713
3731
  providerOptions?: TOptions;
3714
3732
  /** Connection-level config slots accepted by this provider factory */
@@ -3758,7 +3776,7 @@ interface ModelCapabilities {
3758
3776
  *
3759
3777
  * @example
3760
3778
  * // OpenAI o-series
3761
- * reasoningLevels: { 0: null, 33: 'low', 66: 'medium', 100: 'high' }
3779
+ * reasoningLevels: { 0: 'low', 33: 'low', 66: 'medium', 100: 'high' }
3762
3780
  *
3763
3781
  * @example
3764
3782
  * // Binary reasoning (Claude extended thinking)
@@ -4208,31 +4226,26 @@ type SubagentToolConfig<T extends string = string> = never;
4208
4226
  interface ReasoningConfig {
4209
4227
  /**
4210
4228
  * Numeric reasoning level on a 0-100 scale.
4211
- * The FlowEngine maps this to the model's nearest supported reasoning option.
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.
4212
4238
  *
4213
4239
  * @example
4214
4240
  * // Typical breakpoints:
4215
- * // 0 = No reasoning
4241
+ * // 0 = Least reasoning
4216
4242
  * // 33 = Low effort
4217
4243
  * // 66 = Medium effort
4218
4244
  * // 100 = Maximum effort
4219
4245
  *
4220
- * reasoning: { level: 75 } // Maps to 'high' on most models
4246
+ * reasoning: { level: 90 } // Maps to 'high' on most models
4221
4247
  */
4222
4248
  level?: number;
4223
- /**
4224
- * @deprecated Use `level` instead. Will be removed in future versions.
4225
- *
4226
- * Effort level for reasoning models.
4227
- * Higher effort = more thinking tokens = potentially better results.
4228
- *
4229
- * - `low`: Minimal reasoning, faster responses (equivalent to level ~33)
4230
- * - `medium`: Balanced reasoning and speed (equivalent to level ~66)
4231
- * - `high`: Maximum reasoning, slower but more thorough (equivalent to level ~100)
4232
- *
4233
- * @default undefined (use model defaults)
4234
- */
4235
- effort?: 'low' | 'medium' | 'high';
4236
4249
  /**
4237
4250
  * Maximum tokens to allocate for reasoning.
4238
4251
  * Applies to models that support token limits on reasoning.
@@ -4380,6 +4393,19 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
4380
4393
  * @default 10
4381
4394
  */
4382
4395
  recentImageThreshold?: number;
4396
+ /**
4397
+ * Bound the stored chat history a request loads (with `includeChat`):
4398
+ * only the newest top-level messages, at least `historyLimit` and fewer
4399
+ * than twice it. The cut moves `historyLimit` messages at a time, never
4400
+ * per message, so the loaded rows stay the same between steps and a
4401
+ * provider's prompt cache stays warm; a `filter_messages` window that
4402
+ * moves in steps dividing `historyLimit` keeps the same messages it
4403
+ * would keep over the whole history. The window is the execution's
4404
+ * history itself, not only the request: `execution.messageHistory`, tools,
4405
+ * hooks and `filter_messages` all see just these rows. Stored history is
4406
+ * untouched. Unset loads the whole history.
4407
+ */
4408
+ historyLimit?: number;
4383
4409
  /**
4384
4410
  * Provider-specific options passed through to the provider.
4385
4411
  * These override model-level providerOptions for this prompt.
@@ -4504,7 +4530,11 @@ interface SubagentRelationship<Agent extends string = StandardAgentSpec.Agents>
4504
4530
  */
4505
4531
  readonly agent: Agent;
4506
4532
  /**
4507
- * 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.
4508
4538
  *
4509
4539
  * This is the tool-surface name, the registry identity, and the name the
4510
4540
  * lifecycle tools' `agent` argument enumerates. Aliasing lets the same
@@ -4775,12 +4805,12 @@ interface PromptSide<Prompt extends string = StandardAgentSpec.Prompts, Callable
4775
4805
  /**
4776
4806
  * Stop this side's turn when a specific tool is called.
4777
4807
  * Overrides stopOnResponse when the named tool is invoked.
4778
- * Requires stopToolResponseProperty to extract the result.
4808
+ * Set stopToolResponseProperty to extract the result from the tool call.
4779
4809
  */
4780
4810
  readonly stopTool?: Callable;
4781
4811
  /**
4782
4812
  * Property to extract from the stop tool's result.
4783
- * Required when stopTool is set.
4813
+ * Valid only when stopTool is set.
4784
4814
  * The extracted value is used to determine the conversation outcome.
4785
4815
  */
4786
4816
  readonly stopToolResponseProperty?: string;
@@ -4989,7 +5019,7 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
4989
5019
  readonly icon?: string;
4990
5020
  /**
4991
5021
  * Environment values provided by this agent.
4992
- * Agent values are lower priority than thread/account/instance values.
5022
+ * Resolution precedence is thread, agent, prompt, user, then instance.
4993
5023
  */
4994
5024
  readonly env?: Readonly<Record<string, string>>;
4995
5025
  /**
@@ -5118,6 +5148,131 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
5118
5148
  */
5119
5149
  declare function defineAgent<N extends string>(options: AgentDefinition<N>): AgentDefinition<N>;
5120
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
+
5121
5276
  /**
5122
5277
  * Endpoint definition types for Standard Agents.
5123
5278
  *
@@ -5646,6 +5801,8 @@ type DefinitionLoader<T> = () => Promise<T>;
5646
5801
  * ```
5647
5802
  */
5648
5803
  interface PackedExports {
5804
+ /** Handler definitions, keyed by name */
5805
+ handlers: Record<string, DefinitionLoader<HandlerDefinition>>;
5649
5806
  /** Agent definitions, keyed by name */
5650
5807
  agents: Record<string, DefinitionLoader<AgentDefinition>>;
5651
5808
  /** Prompt definitions, keyed by name */
@@ -5676,6 +5833,18 @@ interface PackedExports {
5676
5833
  /** Package metadata */
5677
5834
  __meta: PackedMeta;
5678
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];
5679
5848
 
5680
5849
  /**
5681
5850
  * Hook definition types for Standard Agents.
@@ -5863,7 +6032,8 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
5863
6032
  * Called exactly once per model-context assembly on a stable snapshot of
5864
6033
  * eligible persisted history.
5865
6034
  *
5866
- * Receives raw message rows from storage before any transformation.
6035
+ * Receives raw message rows from storage before any transformation:
6036
+ * with the prompt's `historyLimit`, only its newest window of them.
5867
6037
  * Use for filtering, sorting, or augmenting message history.
5868
6038
  * The result is the request context and does not replace
5869
6039
  * `state.execution.messageHistory`. Messages injected while this hook runs
@@ -6253,131 +6423,6 @@ interface HookDefinitionResult<K extends HookName> {
6253
6423
  */
6254
6424
  declare function defineHook<K extends HookName>(options: HookDefinitionOptions<K>): HookDefinitionResult<K>;
6255
6425
 
6256
- /**
6257
- * Handler definition types for Standard Agents.
6258
- *
6259
- * A handler is a function that takes one side's turns in a conversation.
6260
- * When a side of an agent is backed by a handler, the runtime does not call
6261
- * a model to answer an inbound message — it calls the handler function once,
6262
- * with the thread state and the message, and whatever that function does is
6263
- * the side's turn.
6264
- *
6265
- * A handler is NOT a hook (hooks decorate turns owned by something else, and
6266
- * their failures are non-fatal), NOT a tool (tools are capabilities a
6267
- * turn-owner chooses to invoke), and NOT an effect (effects run outside the
6268
- * conversation flow). Its only seat is backing a side of an agent: handlers
6269
- * MUST NOT be referenced by prompt `tools` arrays, hook lists, or effect
6270
- * schedules, and implementations MUST reject such references at definition
6271
- * time.
6272
- *
6273
- * https://standardagentspec.com/0.2.0/specification/handlers
6274
- *
6275
- * @module
6276
- */
6277
-
6278
- /**
6279
- * Brand marking a value as a handler definition.
6280
- *
6281
- * The brand makes `HandlerDefinition` structurally unassignable to tool,
6282
- * hook, and effect positions, so a handler referenced where those are
6283
- * expected fails to compile wherever TypeScript can see the reference.
6284
- * Implementations additionally reject by-name references that types cannot
6285
- * catch during their definition-registry pass.
6286
- */
6287
- declare const HANDLER_SYMBOL: unique symbol;
6288
- /**
6289
- * A handler definition — deterministic code that owns one side's turns.
6290
- *
6291
- * Execution model (one turn):
6292
- * 1. An inbound message arrives on the side's perspective.
6293
- * 2. The runtime invokes `execute` once with the thread's `ThreadState` and
6294
- * that message.
6295
- * 3. The invocation returns (or throws). The turn is complete.
6296
- *
6297
- * There are no steps, no tool-choice loop, and no model requests for a
6298
- * handler-backed side. When the agent sets `maxSessionTurns`, a handler turn
6299
- * counts toward the exchange cap exactly like a prompt turn.
6300
- *
6301
- * Delivery is exactly-once per message, in message persistence order, one
6302
- * invocation at a time per thread; messages that arrive while a turn is in
6303
- * flight wait in the queue. A failed invocation is never automatically
6304
- * redelivered — retry is a userland decision.
6305
- *
6306
- * Errors are fatal to the turn, and only the turn: the turn is marked failed
6307
- * as a runtime-origin failure, the inbound message stays persisted, and the
6308
- * session continues. A handler ends sessions explicitly via
6309
- * `state.stopSession()`.
6310
- *
6311
- * @template State - The thread state type (defaults to {@link ThreadState})
6312
- */
6313
- interface HandlerDefinition<State = ThreadState> {
6314
- /** Optional human-facing summary of what this handler does. */
6315
- readonly description?: string;
6316
- /**
6317
- * The turn implementation.
6318
- *
6319
- * Receives the full `ThreadState` — it may forward (`queueMessage` toward a
6320
- * child), respond (`injectMessage` as its own side's role), spawn children,
6321
- * stop the session, and read/write thread values: anything tools can do.
6322
- *
6323
- * The `message` parameter is the full persisted {@link Message} — id, role,
6324
- * content, silent flag, metadata, timestamps — not a narrowed view:
6325
- * handlers are trusted definition code, like tools.
6326
- *
6327
- * There is no auto-reply channel: the runtime routes inbound; userland
6328
- * decides outbound. If the handler wants to speak outward, that is code in
6329
- * this function.
6330
- */
6331
- readonly execute: (state: State, message: Message) => Promise<void>;
6332
- readonly [HANDLER_SYMBOL]: true;
6333
- }
6334
- /**
6335
- * Options accepted by {@link defineHandler}.
6336
- *
6337
- * @template State - The thread state type (defaults to {@link ThreadState})
6338
- */
6339
- interface DefineHandlerOptions<State = ThreadState> {
6340
- /** Optional human-facing summary of what this handler does. */
6341
- readonly description?: string;
6342
- /** The turn implementation. See {@link HandlerDefinition.execute}. */
6343
- readonly execute: (state: State, message: Message) => Promise<void>;
6344
- }
6345
- /**
6346
- * Defines a handler — deterministic code that backs one side of an agent and
6347
- * takes that side's turns in place of a model.
6348
- *
6349
- * Handlers live in their own definition directory (`agents/handlers/` in the
6350
- * conventional layout). The handler's name is derived from its file name and
6351
- * referenced from exactly one place: the `handler` property of a side
6352
- * configuration.
6353
- *
6354
- * @template State - The thread state type (defaults to {@link ThreadState})
6355
- * @param options - Handler configuration options
6356
- * @returns The branded handler definition for registration
6357
- *
6358
- * @example
6359
- * ```typescript
6360
- * // agents/handlers/relay_pipe.ts
6361
- * import { defineHandler } from '@standardagents/spec';
6362
- *
6363
- * export default defineHandler({
6364
- * description: 'Forwards inbound user traffic to the assistant child and relays answers back.',
6365
- * execute: async (state, message) => {
6366
- * const assistant = state.children.find(c => c.relationship === 'assistant_agent');
6367
- * if (!assistant) return;
6368
- * const child = await state.getChildThread(assistant.reference);
6369
- * await child?.queueMessage({ role: 'user', content: message.content ?? '' });
6370
- * },
6371
- * });
6372
- * ```
6373
- */
6374
- declare function defineHandler<State = ThreadState>(options: DefineHandlerOptions<State>): HandlerDefinition<State>;
6375
- /**
6376
- * Type guard: is this value a handler definition created by
6377
- * {@link defineHandler}?
6378
- */
6379
- declare function isHandler(value: unknown): value is HandlerDefinition;
6380
-
6381
6426
  /**
6382
6427
  * Pure definition-time validation for Standard Agents.
6383
6428
  *
@@ -6398,7 +6443,7 @@ declare function isHandler(value: unknown): value is HandlerDefinition;
6398
6443
  /**
6399
6444
  * Every issue code `validateAgentDefinition` can emit.
6400
6445
  */
6401
- 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_stop_tool_response_property_missing", "agent_max_steps_invalid", "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"];
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"];
6402
6447
  /**
6403
6448
  * Union of all definition issue codes.
6404
6449
  */
@@ -6451,4 +6496,4 @@ declare function validateAgentDefinition(def: unknown): DefinitionIssue[];
6451
6496
  */
6452
6497
  declare const SPEC_VERSION = "0.2.0";
6453
6498
 
6454
- 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 };