@standardagents/spec 0.37.7 → 0.38.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
@@ -1159,6 +1159,13 @@ interface Message {
1159
1159
  status?: 'pending' | 'completed' | 'failed' | null;
1160
1160
  /** Tool execution status (for tool result messages) */
1161
1161
  tool_status?: 'success' | 'error' | null;
1162
+ /**
1163
+ * Stored-file attachments on this message: refs into the thread filesystem
1164
+ * (generated assets, uploads). Runtimes expose these so clients can render
1165
+ * a message's files — a generated image is part of the conversation, not a
1166
+ * hidden side effect.
1167
+ */
1168
+ attachments?: AttachmentRef[] | null;
1162
1169
  /**
1163
1170
  * Stored model reasoning/thinking text for assistant messages (when the
1164
1171
  * model produced any). Runtimes that persist reasoning expose it here so
@@ -5101,6 +5108,68 @@ declare function defineAgent<N extends string>(options: AgentDefinition<N>): Age
5101
5108
  * @module
5102
5109
  */
5103
5110
 
5111
+ /**
5112
+ * The access level of an endpoint.
5113
+ *
5114
+ * - `authenticated` — the runtime MUST authenticate the request before
5115
+ * invoking the handler, and for thread endpoints MUST additionally enforce
5116
+ * its thread access policy. Requests that fail authentication or
5117
+ * authorization MUST be rejected without invoking the handler.
5118
+ * - `public` — the runtime MUST invoke the handler regardless of the
5119
+ * request's authentication state. The runtime MUST still attempt caller
5120
+ * resolution: a request presenting credentials the runtime can verify is
5121
+ * attributed to that caller, and any other request is treated as anonymous
5122
+ * rather than rejected.
5123
+ *
5124
+ * When no access level is declared, the access level is `authenticated`.
5125
+ */
5126
+ type EndpointAccess = 'authenticated' | 'public';
5127
+ /**
5128
+ * Symbol used to carry an endpoint's declared access level.
5129
+ *
5130
+ * The declaration is attached to the handler at definition time so that
5131
+ * runtimes can read it before routing the request through their
5132
+ * authentication layer.
5133
+ */
5134
+ declare const ENDPOINT_ACCESS_SYMBOL: unique symbol;
5135
+ /**
5136
+ * Options accepted when defining an endpoint.
5137
+ */
5138
+ interface EndpointOptions {
5139
+ /**
5140
+ * The endpoint's access level. Defaults to `authenticated`.
5141
+ */
5142
+ access?: EndpointAccess;
5143
+ }
5144
+ /**
5145
+ * Resolve the declared access level of an endpoint handler.
5146
+ *
5147
+ * Returns `authenticated` when the value carries no declaration.
5148
+ */
5149
+ declare function getEndpointAccess(value: unknown): EndpointAccess;
5150
+ /**
5151
+ * The authentication context supplied to a thread endpoint handler.
5152
+ *
5153
+ * The runtime constructs this context for every invocation:
5154
+ *
5155
+ * - `caller` MUST be the authenticated identity when the request presented
5156
+ * credentials the runtime verified, and `null` otherwise. For an endpoint
5157
+ * whose access level is `authenticated`, `caller` is always non-null.
5158
+ * - `threadAccess` MUST be `true` if and only if the runtime's thread access
5159
+ * policy grants the resolved caller access to the requested thread. It
5160
+ * MUST be `false` when `caller` is `null`. For an endpoint whose access
5161
+ * level is `authenticated`, `threadAccess` is always `true`.
5162
+ *
5163
+ * The mechanism by which a runtime authenticates requests is
5164
+ * implementation-defined; this interface defines only the identity contract
5165
+ * observable by endpoint code.
5166
+ */
5167
+ interface ThreadEndpointAuth {
5168
+ /** The authenticated caller, or `null` for an anonymous request. */
5169
+ caller: ThreadUser | null;
5170
+ /** Whether the caller satisfies the runtime's access policy for the requested thread. */
5171
+ threadAccess: boolean;
5172
+ }
5104
5173
  /**
5105
5174
  * Symbol used to identify thread endpoint handlers.
5106
5175
  *
@@ -5151,6 +5220,15 @@ type VirtualModuleRegistry<T> = Record<string, VirtualModuleLoader<T>>;
5151
5220
  interface ControllerContext {
5152
5221
  /** The incoming HTTP request */
5153
5222
  req: Request;
5223
+ /**
5224
+ * The authenticated caller, or `null` for an anonymous request.
5225
+ *
5226
+ * Populated under the same contract as {@link ThreadEndpointAuth.caller}:
5227
+ * non-null whenever the request presented credentials the runtime
5228
+ * verified, and always non-null for a controller whose access level is
5229
+ * `authenticated`.
5230
+ */
5231
+ caller?: ThreadUser | null;
5154
5232
  /** URL path parameters extracted by the router */
5155
5233
  params: Record<string, string>;
5156
5234
  /** Parsed URL object */
@@ -5217,16 +5295,25 @@ type Controller = (context: ControllerContext) => ControllerReturn;
5217
5295
  * Thread endpoint routes are scoped beneath the runtime's thread ID prefix.
5218
5296
  * A request under that prefix that does not match any local or packed thread
5219
5297
  * endpoint route MUST return HTTP 404.
5298
+ *
5299
+ * The fourth argument carries the request's authentication context under the
5300
+ * contract defined by {@link ThreadEndpointAuth}. Handlers that do not
5301
+ * consume it may omit the parameter.
5220
5302
  */
5221
5303
  type ThreadEndpointRouteParams = Record<string, string>;
5222
- type ThreadEndpointHandler = (req: Request, state: ThreadState, params: ThreadEndpointRouteParams) => Response | Promise<Response>;
5304
+ type ThreadEndpointHandler = (req: Request, state: ThreadState, params: ThreadEndpointRouteParams, auth: ThreadEndpointAuth) => Response | Promise<Response>;
5223
5305
  /**
5224
5306
  * Define a standard HTTP controller.
5225
5307
  *
5226
5308
  * Controllers handle HTTP requests and return responses. They have
5227
5309
  * access to the controller context including virtual module registries.
5228
5310
  *
5311
+ * A controller's access level is declared through `options.access` and
5312
+ * defaults to `authenticated`; see {@link EndpointAccess} for the
5313
+ * requirements each level places on the runtime.
5314
+ *
5229
5315
  * @param controller - The controller function
5316
+ * @param options - Endpoint options, including the access level
5230
5317
  * @returns The controller for registration
5231
5318
  *
5232
5319
  * @example
@@ -5249,7 +5336,7 @@ type ThreadEndpointHandler = (req: Request, state: ThreadState, params: ThreadEn
5249
5336
  * });
5250
5337
  * ```
5251
5338
  */
5252
- declare function defineController(controller: Controller): Controller;
5339
+ declare function defineController(controller: Controller, options?: EndpointOptions): Controller;
5253
5340
  /**
5254
5341
  * Define a thread-specific endpoint.
5255
5342
  *
@@ -5261,7 +5348,14 @@ declare function defineController(controller: Controller): Controller;
5261
5348
  * Runtimes MUST return HTTP 404 for requests beneath the thread endpoint
5262
5349
  * prefix that do not match any local or packed thread endpoint route.
5263
5350
  *
5264
- * @param handler - The handler function receiving request, ThreadState, and route params
5351
+ * A thread endpoint's access level is declared through `options.access` and
5352
+ * defaults to `authenticated`; see {@link EndpointAccess} for the
5353
+ * requirements each level places on the runtime. Handlers receive the
5354
+ * request's authentication context as their fourth argument under the
5355
+ * contract defined by {@link ThreadEndpointAuth}.
5356
+ *
5357
+ * @param handler - The handler function receiving request, ThreadState, route params, and authentication context
5358
+ * @param options - Endpoint options, including the access level
5265
5359
  * @returns A Controller that can be used with the router
5266
5360
  *
5267
5361
  * @example
@@ -5323,8 +5417,24 @@ declare function defineController(controller: Controller): Controller;
5323
5417
  * return Response.json({ exists: !!file });
5324
5418
  * });
5325
5419
  * ```
5420
+ *
5421
+ * @example
5422
+ * ```typescript
5423
+ * // agents/api/status.ts
5424
+ * import { defineThreadEndpoint } from '@standardagents/spec';
5425
+ *
5426
+ * export default defineThreadEndpoint(
5427
+ * async (req, state, params, auth) => {
5428
+ * return Response.json({
5429
+ * threadId: state.threadId,
5430
+ * authorized: auth.threadAccess,
5431
+ * });
5432
+ * },
5433
+ * { access: 'public' }
5434
+ * );
5435
+ * ```
5326
5436
  */
5327
- declare function defineThreadEndpoint(handler: ThreadEndpointHandler): MarkedThreadEndpoint;
5437
+ declare function defineThreadEndpoint(handler: ThreadEndpointHandler, options?: EndpointOptions): MarkedThreadEndpoint;
5328
5438
 
5329
5439
  /**
5330
5440
  * Packing types for Standard Agents.
@@ -5537,4 +5647,4 @@ interface PackedExports {
5537
5647
  __meta: PackedMeta;
5538
5648
  }
5539
5649
 
5540
- 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, type DefineToolOptions, type DefinitionLoader, type Effect, type EffectDefinition, type EmptyUsesState, type EnvValueType, type ExecutionState, type FetchLike, 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 ListUserThreadsOptions, type ListUserValuesOptions, type MarkedThreadEndpoint, type MarkedUserEndpoint, 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 PromptEnvPart, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, type ProviderConfigSlot, type ProviderConfigSlots, type ProviderConfigValueSource, type ProviderDefinition, ProviderError, type ProviderErrorCode, 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, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type RuntimeByteStream, type RuntimeStreamErrorCode, type RuntimeStreamRequest, type RuntimeStreamResult, type RuntimeStreams, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SetEnvOptions, type SideConfig, type SkillFileInput, type SkillMetadata, type SkillsNamespace, type StopSessionOptions, type StructuredPrompt, type SubagentRegistryEntry, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, THREAD_STREAM_REASONING_PARAM, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadEndpointRouteParams, type ThreadMessageChunkEvent, type ThreadMetadata, type ThreadReasoningChunkEvent, type ThreadState, 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, type UserClientInfo, type UserEndpointHandler, type UserEndpointRouteParams, type UserHandle, type UserIdentity, type UserState, type UserThreadSummary, type UserValueEntry, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineProvider, defineThreadEndpoint, defineTool, defineUserEndpoint, isPacked, isThreadEndpoint, isUserEndpoint, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue, validateToolName };
5650
+ 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, type DefineToolOptions, type DefinitionLoader, ENDPOINT_ACCESS_SYMBOL, type Effect, type EffectDefinition, type EmptyUsesState, type EndpointAccess, type EndpointOptions, type EnvValueType, type ExecutionState, type FetchLike, 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 ListUserThreadsOptions, type ListUserValuesOptions, type MarkedThreadEndpoint, type MarkedUserEndpoint, 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 PromptEnvPart, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, type ProviderConfigSlot, type ProviderConfigSlots, type ProviderConfigValueSource, type ProviderDefinition, ProviderError, type ProviderErrorCode, 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, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type RuntimeByteStream, type RuntimeStreamErrorCode, type RuntimeStreamRequest, type RuntimeStreamResult, type RuntimeStreams, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SetEnvOptions, type SideConfig, type SkillFileInput, type SkillMetadata, type SkillsNamespace, type StopSessionOptions, type StructuredPrompt, type SubagentRegistryEntry, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, THREAD_STREAM_REASONING_PARAM, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointAuth, type ThreadEndpointHandler, type ThreadEndpointRouteParams, type ThreadMessageChunkEvent, type ThreadMetadata, type ThreadReasoningChunkEvent, type ThreadState, 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, type UserClientInfo, type UserEndpointHandler, type UserEndpointRouteParams, type UserHandle, type UserIdentity, type UserState, type UserThreadSummary, type UserValueEntry, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineProvider, defineThreadEndpoint, defineTool, defineUserEndpoint, getEndpointAccess, isPacked, isThreadEndpoint, isUserEndpoint, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue, validateToolName };
package/dist/index.js CHANGED
@@ -355,17 +355,30 @@ function defineAgent(options) {
355
355
  var THREAD_STREAM_REASONING_PARAM = "reasoning";
356
356
 
357
357
  // src/endpoints.ts
358
+ var ENDPOINT_ACCESS_SYMBOL = Symbol.for("standardagents.endpointAccess");
359
+ function getEndpointAccess(value) {
360
+ if ((typeof value === "function" || typeof value === "object" && value !== null) && value[ENDPOINT_ACCESS_SYMBOL] === "public") {
361
+ return "public";
362
+ }
363
+ return "authenticated";
364
+ }
358
365
  var THREAD_ENDPOINT_SYMBOL = Symbol.for("standardagents.threadEndpoint");
359
366
  function isThreadEndpoint(controller) {
360
367
  return THREAD_ENDPOINT_SYMBOL in controller && controller[THREAD_ENDPOINT_SYMBOL] === true;
361
368
  }
362
- function defineController(controller) {
369
+ function defineController(controller, options) {
370
+ if (options?.access) {
371
+ controller[ENDPOINT_ACCESS_SYMBOL] = options.access;
372
+ }
363
373
  return controller;
364
374
  }
365
- function defineThreadEndpoint(handler) {
375
+ function defineThreadEndpoint(handler, options) {
366
376
  const markedHandler = handler;
367
377
  markedHandler[THREAD_ENDPOINT_SYMBOL] = true;
368
378
  markedHandler.__handler = handler;
379
+ if (options?.access) {
380
+ markedHandler[ENDPOINT_ACCESS_SYMBOL] = options.access;
381
+ }
369
382
  return markedHandler;
370
383
  }
371
384
 
@@ -432,6 +445,7 @@ function isVisibleInNamespace(metadata, namespace, isEntryPoint = false) {
432
445
  return isOwnPackage || hasPkg && isEntryPoint;
433
446
  }
434
447
  export {
448
+ ENDPOINT_ACCESS_SYMBOL,
435
449
  ProviderError,
436
450
  THREAD_ENDPOINT_SYMBOL,
437
451
  THREAD_STREAM_REASONING_PARAM,
@@ -447,6 +461,7 @@ export {
447
461
  defineThreadEndpoint,
448
462
  defineTool,
449
463
  defineUserEndpoint,
464
+ getEndpointAccess,
450
465
  isPacked,
451
466
  isThreadEndpoint,
452
467
  isUserEndpoint,