@standardagents/spec 0.11.0-next.af971ae → 0.11.0-next.c3b4490

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
@@ -1,159 +1,75 @@
1
- import { ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion, z } from 'zod';
1
+ import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion, ZodTypeAny } from 'zod';
2
2
 
3
3
  /**
4
- * Model definition types for Standard Agents.
4
+ * Effect definition types for Standard Agents.
5
5
  *
6
- * Models define LLM configurations including provider, model ID, pricing,
7
- * and fallback chains. Models are referenced by name from prompts.
6
+ * Effects are scheduled operations that run outside the tool execution context.
7
+ * They enable implementation-specific side effects with optional delay support,
8
+ * leveraging the runtime's scheduling mechanism (e.g., Cloudflare Durable Object alarms).
9
+ *
10
+ * Unlike tools, effects:
11
+ * - Do not return results to the LLM
12
+ * - Can be delayed for future execution
13
+ * - Run independently of the conversation flow
14
+ * - Are ideal for notifications, cleanup, and async operations
8
15
  *
9
16
  * @module
10
17
  */
18
+
11
19
  /**
12
- * Supported LLM provider identifiers.
20
+ * Effect function signature.
21
+ *
22
+ * Effects are async functions that receive a ThreadState and
23
+ * optionally validated arguments. Unlike tools, they return void
24
+ * since results are not included in the conversation.
13
25
  *
14
- * Each provider requires a corresponding API key environment variable:
15
- * - `openai` `OPENAI_API_KEY`
16
- * - `openrouter` → `OPENROUTER_API_KEY`
17
- * - `anthropic` → `ANTHROPIC_API_KEY`
18
- * - `google` → `GOOGLE_API_KEY`
19
- * - `test` → No API key required (for testing with scripted responses)
26
+ * @template State - The state type (defaults to ThreadState)
27
+ * @template Args - The Zod schema for effect arguments, or null for no args
20
28
  */
21
- type ModelProvider = 'openai' | 'openrouter' | 'anthropic' | 'google' | 'test';
29
+ type Effect<State = ThreadState, Args extends ToolArgs | null = null> = Args extends ToolArgs ? (state: State, args: z.infer<Args>) => Promise<void> | void : (state: State) => Promise<void> | void;
22
30
  /**
23
- * Model capability flags indicating supported features.
31
+ * Return type of defineEffect function.
32
+ *
33
+ * A tuple containing:
34
+ * - Effect description string
35
+ * - Argument schema (or null)
36
+ * - Effect implementation function
24
37
  */
25
- interface ModelCapabilities {
26
- /**
27
- * Whether the model supports vision (image understanding).
28
- * When true, image attachments will be sent to the model as part of the request.
29
- * Models like GPT-4o, Claude 3, and Gemini support vision.
30
- */
31
- vision?: boolean;
32
- /**
33
- * Whether the model supports function calling (tool use).
34
- * Most modern models support this, defaults to true if not specified.
35
- */
36
- functionCalling?: boolean;
37
- /**
38
- * Whether the model supports structured outputs (JSON mode).
39
- */
40
- structuredOutputs?: boolean;
41
- }
38
+ type EffectDefinition<State = ThreadState, Args extends ToolArgs | null = null> = [string, Args, Effect<State, Args>];
42
39
  /**
43
- * Model definition configuration.
44
- *
45
- * Defines an LLM model with its provider, pricing, capabilities, and fallback chain.
40
+ * Record of a scheduled effect.
46
41
  *
47
- * @template N - The model name as a string literal type for type inference
48
- *
49
- * @example
50
- * ```typescript
51
- * import { defineModel } from '@standardagents/spec';
52
- *
53
- * export default defineModel({
54
- * name: 'gpt-4o',
55
- * provider: 'openai',
56
- * model: 'gpt-4o',
57
- * fallbacks: ['gpt-4-turbo', 'gpt-3.5-turbo'],
58
- * inputPrice: 2.5,
59
- * outputPrice: 10,
60
- * });
61
- * ```
42
+ * Returned by getScheduledEffects() to inspect pending effects.
62
43
  */
63
- interface ModelDefinition<N extends string = string> {
64
- /**
65
- * Unique name for this model definition.
66
- * Used as the identifier when referencing from prompts.
67
- * Should be descriptive and consistent (e.g., 'gpt-4o', 'claude-3-opus').
68
- */
69
- name: N;
70
- /**
71
- * The LLM provider to use for API calls.
72
- * The corresponding API key environment variable must be set.
73
- */
74
- provider: ModelProvider;
75
- /**
76
- * The actual model identifier sent to the provider API.
77
- *
78
- * For OpenAI: 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', etc.
79
- * For OpenRouter: 'openai/gpt-4o', 'anthropic/claude-3-opus', etc.
80
- * For Anthropic: 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', etc.
81
- * For Google: 'gemini-1.5-pro', 'gemini-1.5-flash', etc.
82
- */
83
- model: string;
84
- /**
85
- * Optional list of additional provider prefixes for OpenRouter.
86
- * Allows routing through specific providers when using OpenRouter.
87
- *
88
- * @example ['anthropic', 'google'] - prefer Anthropic, fallback to Google
89
- */
90
- includedProviders?: string[];
91
- /**
92
- * Fallback model names to try if this model fails.
93
- * Referenced by model name (must be defined in agents/models/).
94
- * Tried in order after primary model exhausts retries.
95
- *
96
- * @example ['gpt-4', 'gpt-3.5-turbo']
97
- */
98
- fallbacks?: string[];
99
- /**
100
- * Cost per 1 million input tokens in USD.
101
- * Used for cost tracking and reporting in logs.
102
- */
103
- inputPrice?: number;
104
- /**
105
- * Cost per 1 million output tokens in USD.
106
- * Used for cost tracking and reporting in logs.
107
- */
108
- outputPrice?: number;
109
- /**
110
- * Cost per 1 million cached input tokens in USD.
111
- * Some providers offer reduced pricing for cached/repeated prompts.
112
- */
113
- cachedPrice?: number;
114
- /**
115
- * Model capabilities - features this model supports.
116
- */
117
- capabilities?: ModelCapabilities;
44
+ interface ScheduledEffect {
45
+ /** Unique identifier for this scheduled effect. */
46
+ id: string;
47
+ /** Name of the effect to execute. */
48
+ name: string;
49
+ /** Arguments to pass to the effect handler. */
50
+ args: Record<string, unknown>;
51
+ /** When the effect is scheduled to run (microseconds since epoch). */
52
+ scheduledAt: number;
53
+ /** When the effect was created (microseconds since epoch). */
54
+ createdAt: number;
118
55
  }
119
56
  /**
120
- * Defines an LLM model configuration.
121
- *
122
- * Models are the foundation of the agent system - they specify which
123
- * AI model to use and how to connect to it. Models can have fallbacks
124
- * for reliability and include pricing for cost tracking.
125
- *
126
- * @template N - The model name as a string literal type
127
- * @param options - Model configuration options
128
- * @returns The model definition for registration
129
- *
130
- * @example
131
- * ```typescript
132
- * // agents/models/gpt_4o.ts
133
- * import { defineModel } from '@standardagents/spec';
57
+ * Define an effect with arguments.
134
58
  *
135
- * export default defineModel({
136
- * name: 'gpt-4o',
137
- * provider: 'openai',
138
- * model: 'gpt-4o',
139
- * fallbacks: ['gpt-4-turbo'],
140
- * inputPrice: 2.5,
141
- * outputPrice: 10,
142
- * });
143
- * ```
59
+ * @param description - Description of what the effect does
60
+ * @param args - Zod schema for validating effect arguments
61
+ * @param handler - The effect implementation function
62
+ * @returns A tuple containing the effect definition
63
+ */
64
+ declare function defineEffect<State = ThreadState, Args extends ToolArgs = ToolArgs>(description: string, args: Args, handler: Effect<State, Args>): EffectDefinition<State, Args>;
65
+ /**
66
+ * Define an effect without arguments.
144
67
  *
145
- * @example
146
- * ```typescript
147
- * // Using OpenRouter with provider preferences
148
- * export default defineModel({
149
- * name: 'claude-3-opus',
150
- * provider: 'openrouter',
151
- * model: 'anthropic/claude-3-opus',
152
- * includedProviders: ['anthropic'],
153
- * });
154
- * ```
68
+ * @param description - Description of what the effect does
69
+ * @param handler - The effect implementation function
70
+ * @returns A tuple containing the effect definition
155
71
  */
156
- declare function defineModel<N extends string>(options: ModelDefinition<N>): ModelDefinition<N>;
72
+ declare function defineEffect<State = ThreadState>(description: string, handler: Effect<State, null>): EffectDefinition<State, null>;
157
73
 
158
74
  /**
159
75
  * Thread state types for Standard Agents.
@@ -233,6 +149,10 @@ interface Message {
233
149
  silent?: boolean;
234
150
  /** Custom metadata */
235
151
  metadata?: Record<string, unknown>;
152
+ /** Message processing status */
153
+ status?: 'pending' | 'completed' | 'failed' | null;
154
+ /** Tool execution status (for tool result messages) */
155
+ tool_status?: 'success' | 'error' | null;
236
156
  }
237
157
  /**
238
158
  * Input for injecting a new message.
@@ -256,32 +176,6 @@ interface MessageUpdates {
256
176
  /** Updated metadata (merged with existing) */
257
177
  metadata?: Record<string, unknown>;
258
178
  }
259
- /**
260
- * Options for retrieving logs.
261
- */
262
- interface GetLogsOptions {
263
- /** Maximum number of logs to return */
264
- limit?: number;
265
- /** Number of logs to skip */
266
- offset?: number;
267
- /** Sort order */
268
- order?: 'asc' | 'desc';
269
- }
270
- /**
271
- * An execution log entry.
272
- */
273
- interface Log {
274
- /** Unique log identifier */
275
- id: string;
276
- /** Log type (e.g., 'tool_call', 'llm_request', 'error') */
277
- type: string;
278
- /** Log data (structure varies by type) */
279
- data: Record<string, unknown>;
280
- /** Creation timestamp (microseconds since epoch) */
281
- created_at: number;
282
- /** Parent log ID (for nested operations) */
283
- parent_id?: string | null;
284
- }
285
179
  /**
286
180
  * Storage location identifier.
287
181
  *
@@ -519,12 +413,15 @@ interface ThreadState {
519
413
  */
520
414
  updateMessage(messageId: string, updates: MessageUpdates): Promise<Message>;
521
415
  /**
522
- * Get execution logs.
416
+ * Delete a message from the thread.
523
417
  *
524
- * @param options - Query options
525
- * @returns Array of log entries
418
+ * Removes the message and any associated attachments from storage.
419
+ * Tool call results are cascade-deleted when their parent message is removed.
420
+ *
421
+ * @param messageId - The message ID to delete
422
+ * @returns true if the message was found and deleted, false if not found
526
423
  */
527
- getLogs(options?: GetLogsOptions): Promise<Log[]>;
424
+ deleteMessage(messageId: string): Promise<boolean>;
528
425
  /**
529
426
  * Load a model definition by name.
530
427
  *
@@ -590,6 +487,69 @@ interface ThreadState {
590
487
  * @returns The tool result
591
488
  */
592
489
  invokeTool(toolName: string, args: Record<string, unknown>): Promise<ToolResult>;
490
+ /**
491
+ * Schedule an effect for future execution.
492
+ *
493
+ * Effects are executed outside the current conversation flow, making them
494
+ * ideal for delayed operations like sending notifications, triggering
495
+ * webhooks, or running cleanup tasks.
496
+ *
497
+ * @param name - Name of the effect to schedule (must exist in agents/effects/)
498
+ * @param args - Arguments to pass to the effect handler
499
+ * @param delay - Delay in milliseconds before execution (default: 0 for immediate)
500
+ * @returns Unique ID of the scheduled effect (UUID)
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * // Schedule a reminder email in 30 minutes
505
+ * const effectId = await state.scheduleEffect(
506
+ * 'send_reminder_email',
507
+ * { to: 'user@example.com', subject: 'Reminder' },
508
+ * 30 * 60 * 1000
509
+ * );
510
+ * ```
511
+ */
512
+ scheduleEffect(name: string, args: Record<string, unknown>, delay?: number): Promise<string>;
513
+ /**
514
+ * Get scheduled effects for this thread.
515
+ *
516
+ * Returns effects that are pending execution. Can optionally filter
517
+ * by effect name.
518
+ *
519
+ * @param name - Optional effect name to filter by
520
+ * @returns Array of scheduled effect records
521
+ */
522
+ getScheduledEffects(name?: string): Promise<ScheduledEffect[]>;
523
+ /**
524
+ * Remove a scheduled effect.
525
+ *
526
+ * Cancels a pending effect before it executes. Has no effect if the
527
+ * effect has already executed or doesn't exist.
528
+ *
529
+ * @param id - The effect ID returned by scheduleEffect
530
+ * @returns true if the effect was found and removed, false otherwise
531
+ */
532
+ removeScheduledEffect(id: string): Promise<boolean>;
533
+ /**
534
+ * Trigger an agent to run on this thread.
535
+ *
536
+ * Starts a new agent execution asynchronously. This is useful for effects
537
+ * that need to trigger background agent work (e.g., running a finalizer
538
+ * agent after a delay).
539
+ *
540
+ * The agent runs in the background - this method returns immediately
541
+ * after queuing the execution.
542
+ *
543
+ * @param agentName - Name of the agent to run (must exist in agents/agents/)
544
+ * @returns Promise that resolves when the execution is queued
545
+ *
546
+ * @example
547
+ * ```typescript
548
+ * // In an effect handler, trigger a finalizer agent
549
+ * await state.runAgent('booking_finalizer');
550
+ * ```
551
+ */
552
+ runAgent(agentName: string): Promise<void>;
593
553
  /**
594
554
  * Emit a custom event to connected clients.
595
555
  *
@@ -711,197 +671,1092 @@ interface ThreadState {
711
671
  * @param path - Path to the image file
712
672
  * @returns Thumbnail data as ArrayBuffer, or null if not available
713
673
  */
714
- getFileThumbnail(path: string): Promise<ArrayBuffer | null>;
674
+ getFileThumbnail(path: string): Promise<ArrayBuffer | null>;
675
+ /**
676
+ * Execution-specific state.
677
+ *
678
+ * This is present when the thread is actively executing (tools, hooks)
679
+ * and null when accessing a thread at rest (endpoints, external code).
680
+ *
681
+ * Use this to access step counts, force turns, or stop execution.
682
+ */
683
+ execution: ExecutionState | null;
684
+ /**
685
+ * Runtime-specific context that cannot be packed or shared.
686
+ *
687
+ * This property allows runtime implementations to inject non-portable
688
+ * context (e.g., Cloudflare env bindings, database connections).
689
+ *
690
+ * WARNING: Tools using this property cannot be packed, shared, or
691
+ * published as they depend on runtime-specific context.
692
+ */
693
+ readonly _notPackableRuntimeContext?: Record<string, unknown>;
694
+ }
695
+
696
+ /**
697
+ * Tool definition types for Standard Agents.
698
+ *
699
+ * Tools are callable functions that agents can invoke during execution.
700
+ * They receive the current ThreadState and validated arguments,
701
+ * and return results that are included in the conversation.
702
+ *
703
+ * @module
704
+ */
705
+
706
+ /**
707
+ * Text content item returned by tools.
708
+ */
709
+ interface TextContent {
710
+ type: 'text';
711
+ text: string;
712
+ }
713
+ /**
714
+ * Image content item returned by tools.
715
+ */
716
+ interface ImageContent {
717
+ type: 'image';
718
+ /** Base64-encoded image data. */
719
+ data: string;
720
+ /** MIME type of the image (e.g., 'image/png', 'image/jpeg'). */
721
+ mimeType: string;
722
+ }
723
+ /**
724
+ * Content types that can be returned by tools.
725
+ */
726
+ type ToolContent = TextContent | ImageContent;
727
+ /**
728
+ * File attachment generated by a tool.
729
+ *
730
+ * Attachments are stored in the thread's file system and linked to
731
+ * the tool result message. Unlike user uploads, tool attachments are
732
+ * not subject to image downsampling.
733
+ */
734
+ interface ToolAttachment {
735
+ /** File name for the attachment. */
736
+ name: string;
737
+ /** MIME type of the attachment. */
738
+ mimeType: string;
739
+ /** Base64-encoded file data. */
740
+ data: string;
741
+ /** Width in pixels (for images). */
742
+ width?: number;
743
+ /** Height in pixels (for images). */
744
+ height?: number;
745
+ }
746
+ /**
747
+ * Reference to a pre-existing attachment in the thread file system.
748
+ */
749
+ interface AttachmentRef {
750
+ /** Unique identifier for the attachment. */
751
+ id: string;
752
+ /** Attachment type. */
753
+ type: 'file';
754
+ /** Path in the thread file system. */
755
+ path: string;
756
+ /** File name. */
757
+ name: string;
758
+ /** MIME type. */
759
+ mimeType: string;
760
+ /** File size in bytes. */
761
+ size: number;
762
+ /** Width in pixels (for images). */
763
+ width?: number;
764
+ /** Height in pixels (for images). */
765
+ height?: number;
766
+ /** AI-generated description. */
767
+ description?: string;
768
+ }
769
+ /**
770
+ * Result returned by a tool execution.
771
+ */
772
+ interface ToolResult {
773
+ /** Status of the tool execution. */
774
+ status: 'success' | 'error';
775
+ /**
776
+ * Text representation of the tool output.
777
+ *
778
+ * For tools that return structured content, this is derived by
779
+ * concatenating all text parts. For simple tools, this is the
780
+ * direct result string.
781
+ */
782
+ result?: string;
783
+ /** Error message if status is 'error'. */
784
+ error?: string;
785
+ /** Stack trace for error debugging. */
786
+ stack?: string;
787
+ /**
788
+ * File attachments returned by the tool.
789
+ *
790
+ * Can contain either:
791
+ * - ToolAttachment: New files with base64 data to be stored
792
+ * - AttachmentRef: References to existing files in the thread filesystem
793
+ *
794
+ * Implementations MUST store new attachments under /attachments/ directory.
795
+ */
796
+ attachments?: Array<ToolAttachment | AttachmentRef>;
797
+ }
798
+ /** Decrement helper to limit recursion depth. */
799
+ type Dec<N extends number> = N extends 10 ? 9 : N extends 9 ? 8 : N extends 8 ? 7 : N extends 7 ? 6 : N extends 6 ? 5 : N extends 5 ? 4 : N extends 4 ? 3 : N extends 3 ? 2 : N extends 2 ? 1 : N extends 1 ? 0 : 0;
800
+ /**
801
+ * Allowed Zod types for tool argument nodes.
802
+ *
803
+ * This is the single source of truth for which Zod types can be used
804
+ * in tool argument schemas. The depth parameter limits recursion to
805
+ * prevent infinite type expansion.
806
+ *
807
+ * @template D - Maximum nesting depth (default: 7)
808
+ */
809
+ type ToolArgsNode<D extends number = 7> = ZodString | ZodNumber | ZodBoolean | ZodNull | ZodLiteral<string | number | boolean | null> | ZodEnum<Readonly<Record<string, string>>> | (D extends 0 ? never : ZodOptional<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodNullable<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodDefault<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodArray<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodObject<Record<string, ToolArgsNode<Dec<D>>>>) | (D extends 0 ? never : ZodRecord<ZodString, ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodUnion<[
810
+ ToolArgsNode<Dec<D>>,
811
+ ToolArgsNode<Dec<D>>,
812
+ ...ToolArgsNode<Dec<D>>[]
813
+ ]>);
814
+ /**
815
+ * Raw shape for a Zod object schema containing tool argument nodes.
816
+ *
817
+ * @template D - Maximum nesting depth (default: 7)
818
+ */
819
+ type ToolArgsRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
820
+ /**
821
+ * Top-level tool argument schema.
822
+ *
823
+ * Tool arguments MUST be defined as a Zod object schema.
824
+ * This is required for compatibility with OpenAI's function calling API.
825
+ *
826
+ * @template D - Maximum nesting depth (default: 7)
827
+ */
828
+ type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
829
+ /**
830
+ * Raw shape for tenv schema - uses same pattern as ToolArgsRawShape.
831
+ * Each key is a tenv name, value is a Zod schema for validation.
832
+ *
833
+ * @template D - Maximum nesting depth (default: 7)
834
+ */
835
+ type TenvRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
836
+ /**
837
+ * Top-level thread environment variable schema.
838
+ *
839
+ * Defines which thread environment variables a tool requires.
840
+ * Required tenvs are non-optional fields, optional tenvs use .optional().
841
+ *
842
+ * @example
843
+ * ```typescript
844
+ * z.object({
845
+ * vectorStoreId: z.string().describe('OpenAI Vector Store ID'), // Required
846
+ * userLocation: z.string().optional().describe('User location'), // Optional
847
+ * })
848
+ * ```
849
+ *
850
+ * @template D - Maximum nesting depth (default: 7)
851
+ */
852
+ type ToolTenvs<D extends number = 7> = z.ZodObject<TenvRawShape<D>>;
853
+ /**
854
+ * Tool function signature.
855
+ *
856
+ * Tools are async functions that receive a ThreadState and
857
+ * optionally validated arguments, returning a ToolResult.
858
+ *
859
+ * @template State - The state type (defaults to ThreadState)
860
+ * @template Args - The Zod schema for tool arguments, or null for no args
861
+ */
862
+ type Tool<State = ThreadState, Args extends ToolArgs | null = null> = Args extends ToolArgs ? (state: State, args: z.infer<Args>) => Promise<ToolResult> : (state: State) => Promise<ToolResult>;
863
+ /**
864
+ * Options for defining a tool.
865
+ *
866
+ * @template State - The state type (defaults to ThreadState)
867
+ * @template Args - The Zod schema for tool arguments, or null for no args
868
+ * @template Tenvs - The Zod schema for thread environment variables, or null
869
+ */
870
+ interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
871
+ /** Description of what the tool does (shown to the LLM). */
872
+ description: string;
873
+ /** Zod schema for validating tool arguments. Omit for tools with no args. */
874
+ args?: Args;
875
+ /** The tool implementation function. */
876
+ execute: Tool<State, Args>;
877
+ /** Zod schema for thread environment variables the tool requires. */
878
+ tenvs?: Tenvs;
879
+ /**
880
+ * Where this tool is executed:
881
+ * - 'local': Execute locally by the execution engine (default)
882
+ * - 'provider': Executed by the LLM provider, results come in response
883
+ */
884
+ executionMode?: 'local' | 'provider';
885
+ /**
886
+ * Which provider executes this tool (when executionMode='provider').
887
+ * e.g., 'openai', 'anthropic'
888
+ */
889
+ executionProvider?: string;
890
+ }
891
+ /**
892
+ * Tool definition object returned by defineTool().
893
+ *
894
+ * Contains all the metadata and implementation needed to register
895
+ * and execute a tool.
896
+ *
897
+ * @template State - The state type (defaults to ThreadState)
898
+ * @template Args - The Zod schema for tool arguments, or null for no args
899
+ * @template Tenvs - The Zod schema for thread environment variables, or null
900
+ */
901
+ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null> {
902
+ /** Description of what the tool does (shown to the LLM). */
903
+ description: string;
904
+ /** Zod schema for validating tool arguments, or null for no args. */
905
+ args: Args;
906
+ /** The tool implementation function. */
907
+ execute: Tool<State, Args>;
908
+ /** Zod schema for thread environment variables, or null if none. */
909
+ tenvs: Tenvs;
910
+ /**
911
+ * Where this tool is executed:
912
+ * - 'local': Execute locally by the execution engine (default)
913
+ * - 'provider': Executed by the LLM provider, results come in response
914
+ */
915
+ executionMode?: 'local' | 'provider';
916
+ /**
917
+ * Which provider executes this tool (when executionMode='provider').
918
+ */
919
+ executionProvider?: string;
920
+ }
921
+ /**
922
+ * Defines a tool that agents can call during execution.
923
+ *
924
+ * Tools are the primary way agents interact with external systems.
925
+ * Each tool has a description (shown to the LLM), optional argument
926
+ * schema (validated at runtime), an implementation function, and
927
+ * optional thread environment variable (tenv) requirements.
928
+ *
929
+ * @example
930
+ * ```typescript
931
+ * import { defineTool } from '@standardagents/spec';
932
+ * import { z } from 'zod';
933
+ *
934
+ * // Tool with arguments
935
+ * export default defineTool({
936
+ * description: 'Search the knowledge base for relevant information',
937
+ * args: z.object({
938
+ * query: z.string().describe('Search query'),
939
+ * limit: z.number().optional().describe('Max results'),
940
+ * }),
941
+ * execute: async (state, args) => {
942
+ * const results = await search(args.query, args.limit);
943
+ * return { status: 'success', result: JSON.stringify(results) };
944
+ * },
945
+ * });
946
+ *
947
+ * // Tool without arguments
948
+ * export default defineTool({
949
+ * description: 'Get the current server time',
950
+ * execute: async (state) => {
951
+ * return { status: 'success', result: new Date().toISOString() };
952
+ * },
953
+ * });
954
+ *
955
+ * // Tool with tenvs (thread environment variables)
956
+ * export default defineTool({
957
+ * description: 'Search through uploaded files',
958
+ * args: z.object({ query: z.string() }),
959
+ * execute: async (state, args) => ({ status: 'success', result: 'done' }),
960
+ * tenvs: z.object({
961
+ * vectorStoreId: z.string().describe('OpenAI Vector Store ID'),
962
+ * }),
963
+ * });
964
+ *
965
+ * // Provider-executed tool (e.g., OpenAI built-in tools)
966
+ * export default defineTool({
967
+ * description: 'Generate images using DALL-E',
968
+ * args: z.object({ prompt: z.string() }),
969
+ * execute: async () => ({ status: 'success', result: 'Handled by provider' }),
970
+ * executionMode: 'provider',
971
+ * executionProvider: 'openai',
972
+ * });
973
+ * ```
974
+ *
975
+ * @param options - Tool definition options
976
+ * @returns A tool definition object
977
+ */
978
+ declare function defineTool<State = ThreadState, Args extends ToolArgs | null = null, Tenvs extends ToolTenvs | null = null>(options: DefineToolOptions<State, Args, Tenvs>): ToolDefinition<State, Args, Tenvs>;
979
+
980
+ /**
981
+ * Provider types for Standard Agents.
982
+ *
983
+ * These types define the interface between Standard Agents and LLM providers.
984
+ * Provider packages implement these types to integrate with different LLM APIs.
985
+ *
986
+ * @module
987
+ */
988
+
989
+ /**
990
+ * Stripped-down response summary for async metadata fetching.
991
+ * Intentionally excludes content/attachments to avoid passing large data.
992
+ */
993
+ interface ResponseSummary {
994
+ /** Provider-specific response/generation ID */
995
+ responseId?: string;
996
+ /** Model that handled the request */
997
+ model: string;
998
+ /** How the response ended */
999
+ finishReason: ProviderFinishReason;
1000
+ /** Token usage (without detailed breakdowns) */
1001
+ usage: {
1002
+ promptTokens: number;
1003
+ completionTokens: number;
1004
+ totalTokens: number;
1005
+ };
1006
+ }
1007
+ /**
1008
+ * Model information returned by provider's getModels method.
1009
+ */
1010
+ interface ProviderModelInfo {
1011
+ /** The model identifier used in API calls (e.g., 'gpt-4o', 'anthropic/claude-3-opus') */
1012
+ id: string;
1013
+ /** Human-readable display name */
1014
+ name: string;
1015
+ /** Optional description of the model */
1016
+ description?: string;
1017
+ /** Optional context window size in tokens */
1018
+ contextLength?: number;
1019
+ /** Optional icon identifier for UI display */
1020
+ iconId?: string;
1021
+ /** Optional slug for additional lookups (e.g., OpenRouter endpoint queries) */
1022
+ slug?: string;
1023
+ }
1024
+ /**
1025
+ * Provider interface - thin translation layer between Standard Agents and LLM APIs
1026
+ */
1027
+ interface LLMProviderInterface {
1028
+ readonly name: string;
1029
+ readonly specificationVersion: '1';
1030
+ /**
1031
+ * Non-streaming generation
1032
+ */
1033
+ generate(request: ProviderRequest): Promise<ProviderResponse>;
1034
+ /**
1035
+ * Streaming generation
1036
+ */
1037
+ stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
1038
+ /**
1039
+ * Check if this provider supports a model
1040
+ */
1041
+ supportsModel?(modelId: string): boolean;
1042
+ /**
1043
+ * List available models from this provider.
1044
+ * Optional for backwards compatibility - providers may implement this
1045
+ * to enable model selection in the UI.
1046
+ *
1047
+ * @param filter - Optional search string to filter models by name/id
1048
+ * @returns Array of available models
1049
+ */
1050
+ getModels?(filter?: string): Promise<ProviderModelInfo[]>;
1051
+ /**
1052
+ * Fetch capabilities for a specific model.
1053
+ * Optional for backwards compatibility - providers may implement this
1054
+ * to enable auto-detection of model features in the UI.
1055
+ *
1056
+ * @param modelId - The model identifier (e.g., 'gpt-4o', 'anthropic/claude-3-opus')
1057
+ * @returns The model capabilities, or null if not available
1058
+ */
1059
+ getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
1060
+ /**
1061
+ * Get tools embedded in this provider.
1062
+ * Optional - providers may implement this to expose built-in tools
1063
+ * (e.g., OpenAI's web_search, file_search, code_interpreter).
1064
+ *
1065
+ * These tools are defined using defineTool() with optional tenv requirements.
1066
+ * Tools returned here can be referenced by name in model/prompt definitions.
1067
+ *
1068
+ * @param modelId - Optional filter to get tools available for a specific model
1069
+ * @returns Record of tool name to tool definition (sync or async)
1070
+ */
1071
+ getTools?(modelId?: string): Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<any, ToolArgs | null, ToolTenvs | null>>>;
1072
+ /**
1073
+ * Get an icon for this provider or a specific model.
1074
+ * Optional - providers may implement this to provide UI icons.
1075
+ *
1076
+ * **Preferred return format: SVG data URI** (e.g., 'data:image/svg+xml,...')
1077
+ *
1078
+ * The data URI format allows icons to be embedded directly in the UI without
1079
+ * additional network requests. Use the `svgToDataUri()` helper from provider
1080
+ * packages to convert SVG strings.
1081
+ *
1082
+ * Return value can be:
1083
+ * - A data URI (e.g., 'data:image/svg+xml,...') - **PREFERRED**
1084
+ * - A full URL (e.g., 'https://example.com/icon.svg')
1085
+ * - An icon identifier that the UI resolves (legacy)
1086
+ *
1087
+ * For providers like OpenRouter that host many models, the modelId parameter
1088
+ * allows returning different icons based on the model's origin lab
1089
+ * (e.g., 'anthropic/claude-3-opus' -> anthropic icon).
1090
+ *
1091
+ * @param modelId - Optional model ID to get a model-specific icon
1092
+ * @returns SVG data URI (preferred), URL, icon identifier, or undefined
1093
+ *
1094
+ * @example
1095
+ * ```typescript
1096
+ * // Provider returning its own icon
1097
+ * getIcon() {
1098
+ * return svgToDataUri(OPENAI_ICON);
1099
+ * }
1100
+ *
1101
+ * // Provider returning model-specific icon (e.g., OpenRouter)
1102
+ * getIcon(modelId?: string) {
1103
+ * if (modelId) {
1104
+ * const lab = modelId.split('/')[0]; // 'anthropic' from 'anthropic/claude-3'
1105
+ * return getLabIconDataUri(lab);
1106
+ * }
1107
+ * return svgToDataUri(OPENROUTER_ICON);
1108
+ * }
1109
+ * ```
1110
+ */
1111
+ getIcon?(modelId?: string): string | undefined;
1112
+ /**
1113
+ * Transform a ProviderRequest to the provider's native format for inspection/debugging.
1114
+ * Returns the transformed request as it would be sent to the provider's API.
1115
+ *
1116
+ * This is used by the admin UI to view logged requests in provider-specific format,
1117
+ * helping debug issues like message transformation or tool handling.
1118
+ *
1119
+ * Implementations should truncate base64 data to ~50 chars for readability.
1120
+ *
1121
+ * @param request - The Standard Agents format request to transform
1122
+ * @returns The transformed request in the provider's native format
1123
+ */
1124
+ inspectRequest?(request: ProviderRequest): Promise<InspectedRequest>;
1125
+ /**
1126
+ * Fetch additional metadata about a completed response.
1127
+ * Called asynchronously after the response is received - does not block the main execution flow.
1128
+ *
1129
+ * This is useful for providers (like aggregators) where complete metadata isn't available
1130
+ * immediately. The execution engine calls this in the background and uses the returned
1131
+ * data to update log records.
1132
+ *
1133
+ * @param summary - Stripped-down response info (no content/attachments)
1134
+ * @param signal - Optional abort signal for cancellation
1135
+ * @returns Additional metadata or null if unavailable
1136
+ */
1137
+ getResponseMetadata?(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
1138
+ }
1139
+ /**
1140
+ * Result from inspectRequest() - the transformed request in provider's native format
1141
+ */
1142
+ interface InspectedRequest {
1143
+ /** The transformed request body as it would be sent to the API */
1144
+ body: Record<string, unknown>;
1145
+ /** Path to the messages array within body (e.g., "input" for OpenAI, "messages" for others) */
1146
+ messagesPath: string;
1147
+ /** Optional: Additional metadata about the transformation */
1148
+ metadata?: {
1149
+ /** The API endpoint that would be called */
1150
+ endpoint?: string;
1151
+ /** Headers that would be sent (excluding auth) */
1152
+ headers?: Record<string, string>;
1153
+ };
1154
+ }
1155
+ /**
1156
+ * Standard Agent request format - providers translate to their native format
1157
+ */
1158
+ interface ProviderRequest {
1159
+ model: string;
1160
+ messages: ProviderMessage[];
1161
+ tools?: ProviderTool[];
1162
+ toolChoice?: 'auto' | 'none' | 'required' | {
1163
+ name: string;
1164
+ };
1165
+ parallelToolCalls?: boolean;
1166
+ maxOutputTokens?: number;
1167
+ temperature?: number;
1168
+ topP?: number;
1169
+ topK?: number;
1170
+ stopSequences?: string[];
1171
+ reasoning?: {
1172
+ level?: number;
1173
+ maxTokens?: number;
1174
+ exclude?: boolean;
1175
+ };
1176
+ responseFormat?: {
1177
+ type: 'text';
1178
+ } | {
1179
+ type: 'json';
1180
+ schema?: Record<string, unknown>;
1181
+ };
1182
+ signal?: AbortSignal;
1183
+ providerOptions?: Record<string, unknown>;
1184
+ }
1185
+ type ProviderMessage = ProviderSystemMessage | ProviderUserMessage | ProviderAssistantMessage | ProviderToolMessage;
1186
+ interface ProviderSystemMessage {
1187
+ role: 'system';
1188
+ content: string;
1189
+ }
1190
+ interface ProviderUserMessage {
1191
+ role: 'user';
1192
+ content: ProviderMessageContent;
1193
+ }
1194
+ interface ProviderAssistantMessage {
1195
+ role: 'assistant';
1196
+ content?: string | null;
1197
+ reasoning?: string | null;
1198
+ reasoningDetails?: ProviderReasoningDetail[];
1199
+ toolCalls?: ProviderToolCallPart[];
1200
+ }
1201
+ interface ProviderToolMessage {
1202
+ role: 'tool';
1203
+ toolCallId: string;
1204
+ toolName: string;
1205
+ content: ProviderToolResultContent;
1206
+ attachments?: ProviderAttachment[];
1207
+ }
1208
+ /**
1209
+ * Attachment on a provider message (loaded from storage, ready for provider-specific transformation)
1210
+ */
1211
+ interface ProviderAttachment {
1212
+ type: 'image' | 'file';
1213
+ data: string;
1214
+ mediaType: string;
1215
+ name?: string;
1216
+ path?: string;
1217
+ }
1218
+ type ProviderMessageContent = string | ContentPart[];
1219
+ type ContentPart = TextPart | ImagePart | ImageUrlPart | FilePart;
1220
+ interface TextPart {
1221
+ type: 'text';
1222
+ text: string;
1223
+ }
1224
+ interface ImagePart {
1225
+ type: 'image';
1226
+ data: string;
1227
+ mediaType: string;
1228
+ detail?: 'auto' | 'low' | 'high';
1229
+ }
1230
+ /**
1231
+ * Image URL content part (OpenAI/OpenRouter format).
1232
+ * Used for passing image URLs directly to providers.
1233
+ */
1234
+ interface ImageUrlPart {
1235
+ type: 'image_url';
1236
+ image_url: {
1237
+ url: string;
1238
+ detail?: 'auto' | 'low' | 'high';
1239
+ };
1240
+ }
1241
+ interface FilePart {
1242
+ type: 'file';
1243
+ data: string;
1244
+ mediaType: string;
1245
+ filename?: string;
1246
+ }
1247
+ interface ProviderTool {
1248
+ type: 'function';
1249
+ function: {
1250
+ name: string;
1251
+ description: string;
1252
+ parameters?: Record<string, unknown>;
1253
+ };
1254
+ /**
1255
+ * Where this tool is executed:
1256
+ * - 'local': Execute locally by the execution engine (default)
1257
+ * - 'provider': Executed by the LLM provider, results come in response
1258
+ */
1259
+ executionMode?: 'local' | 'provider';
1260
+ /**
1261
+ * Which provider executes this tool (when executionMode='provider')
1262
+ * e.g., 'openai', 'anthropic'
1263
+ */
1264
+ executionProvider?: string;
1265
+ }
1266
+ interface ProviderToolCallPart {
1267
+ id: string;
1268
+ name: string;
1269
+ arguments: Record<string, unknown>;
1270
+ }
1271
+ type ProviderToolResultContent = string | {
1272
+ type: 'text';
1273
+ text: string;
1274
+ } | {
1275
+ type: 'error';
1276
+ error: string;
1277
+ } | ContentPart[];
1278
+ interface ProviderResponse {
1279
+ content: string | null;
1280
+ reasoning?: string | null;
1281
+ reasoningDetails?: ProviderReasoningDetail[];
1282
+ toolCalls?: ProviderToolCallPart[];
1283
+ images?: ProviderGeneratedImage[];
1284
+ finishReason: ProviderFinishReason;
1285
+ usage: ProviderUsage;
1286
+ metadata?: Record<string, unknown>;
1287
+ }
1288
+ type ProviderFinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error';
1289
+ interface ProviderUsage {
1290
+ promptTokens: number;
1291
+ completionTokens: number;
1292
+ totalTokens: number;
1293
+ reasoningTokens?: number;
1294
+ cachedTokens?: number;
1295
+ cost?: number;
1296
+ /** The actual provider that fulfilled the request (e.g., 'google', 'anthropic') */
1297
+ provider?: string;
1298
+ }
1299
+ interface ProviderGeneratedImage {
1300
+ /** Unique ID for this generated image (used to link to tool call) */
1301
+ id?: string;
1302
+ /** Name of the tool that generated this image (e.g., 'image_generation') */
1303
+ toolName?: string;
1304
+ data: string;
1305
+ mediaType: string;
1306
+ revisedPrompt?: string;
1307
+ }
1308
+ interface ProviderReasoningDetail {
1309
+ type: 'summary' | 'encrypted' | 'text';
1310
+ /** Original reasoning ID from provider (e.g., rs_xxx for OpenAI) */
1311
+ id?: string;
1312
+ text?: string;
1313
+ data?: string;
1314
+ }
1315
+ /**
1316
+ * Web search result from provider
1317
+ */
1318
+ interface ProviderWebSearchResult {
1319
+ /** Unique ID of the web search call */
1320
+ id: string;
1321
+ /** Status of the search */
1322
+ status: 'in_progress' | 'searching' | 'completed' | 'failed';
1323
+ /** Search actions performed */
1324
+ actions?: Array<{
1325
+ type: 'search' | 'open_page' | 'find';
1326
+ query?: string;
1327
+ url?: string;
1328
+ pattern?: string;
1329
+ sources?: Array<{
1330
+ type: 'url';
1331
+ url: string;
1332
+ title?: string;
1333
+ }>;
1334
+ }>;
1335
+ }
1336
+ type ProviderStreamChunk = {
1337
+ type: 'content-delta';
1338
+ delta: string;
1339
+ } | {
1340
+ type: 'content-done';
1341
+ } | {
1342
+ type: 'reasoning-delta';
1343
+ delta: string;
1344
+ } | {
1345
+ type: 'reasoning-done';
1346
+ } | {
1347
+ type: 'tool-call-start';
1348
+ id: string;
1349
+ name: string;
1350
+ } | {
1351
+ type: 'tool-call-delta';
1352
+ id: string;
1353
+ argumentsDelta: string;
1354
+ } | {
1355
+ type: 'tool-call-done';
1356
+ id: string;
1357
+ arguments: Record<string, unknown>;
1358
+ } | {
1359
+ type: 'image-delta';
1360
+ index: number;
1361
+ data: string;
1362
+ } | {
1363
+ type: 'image-done';
1364
+ index: number;
1365
+ image: ProviderGeneratedImage;
1366
+ } | {
1367
+ type: 'web-search-done';
1368
+ result: ProviderWebSearchResult;
1369
+ } | {
1370
+ type: 'finish';
1371
+ finishReason: ProviderFinishReason;
1372
+ usage: ProviderUsage;
1373
+ reasoningDetails?: ProviderReasoningDetail[];
1374
+ } | {
1375
+ type: 'error';
1376
+ error: string;
1377
+ code?: string;
1378
+ };
1379
+ type ProviderErrorCode = 'rate_limit' | 'invalid_request' | 'auth_error' | 'server_error' | 'timeout' | 'unknown';
1380
+ declare class ProviderError extends Error {
1381
+ code: ProviderErrorCode;
1382
+ statusCode?: number | undefined;
1383
+ retryAfter?: number | undefined;
1384
+ constructor(message: string, code: ProviderErrorCode, statusCode?: number | undefined, retryAfter?: number | undefined);
1385
+ /**
1386
+ * Whether this error is retryable
1387
+ */
1388
+ get isRetryable(): boolean;
1389
+ }
1390
+ /**
1391
+ * Maps a 0-100 reasoning level to the model's nearest supported level
1392
+ */
1393
+ declare function mapReasoningLevel(level: number, reasoningLevels: Record<number, string | null> | undefined): string | null;
1394
+
1395
+ /**
1396
+ * Model definition types for Standard Agents.
1397
+ *
1398
+ * Models define LLM configurations including provider, model ID, pricing,
1399
+ * and fallback chains. Models are referenced by name from prompts.
1400
+ *
1401
+ * @module
1402
+ */
1403
+
1404
+ /**
1405
+ * Legacy provider identifiers - kept for reference only.
1406
+ * New code should use ProviderFactory imports from provider packages.
1407
+ *
1408
+ * @deprecated Use ProviderFactory from provider packages instead
1409
+ * @internal
1410
+ */
1411
+ type ModelProvider = 'openai' | 'openrouter' | 'anthropic' | 'google' | 'test';
1412
+ /**
1413
+ * Provider interface for LLM providers.
1414
+ *
1415
+ * Provider packages export a factory function that creates instances
1416
+ * implementing this interface. This is structurally compatible with
1417
+ * LLMProviderInterface from providers.ts.
1418
+ */
1419
+ interface ProviderInstance {
1420
+ readonly name: string;
1421
+ readonly specificationVersion: '1';
1422
+ generate(request: ProviderRequest): Promise<ProviderResponse>;
1423
+ stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
1424
+ supportsModel?(modelId: string): boolean;
1425
+ /** List available models from this provider */
1426
+ getModels?(filter?: string): Promise<ProviderModelInfo[]>;
1427
+ /** Fetch capabilities for a specific model */
1428
+ getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
1429
+ /** Get provider-specific tools available for a model */
1430
+ getTools?(modelId?: string): Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>>>;
1431
+ /** Get the icon URL for this provider or a specific model */
1432
+ getIcon?(modelId?: string): string | undefined;
1433
+ /** Inspect a raw request for debugging purposes */
1434
+ inspectRequest?(request: ProviderRequest): Promise<InspectedRequest>;
1435
+ /** Fetch additional metadata about a completed response */
1436
+ getResponseMetadata?(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
1437
+ }
1438
+ /**
1439
+ * Configuration passed to provider factory functions.
1440
+ */
1441
+ interface ProviderFactoryConfig {
1442
+ apiKey: string;
1443
+ baseUrl?: string;
1444
+ timeout?: number;
1445
+ }
1446
+ /**
1447
+ * Provider factory with optional typed providerOptions schema.
1448
+ *
1449
+ * The schema property allows type inference and runtime validation of
1450
+ * provider-specific options in model definitions.
1451
+ *
1452
+ * @template TOptions - Zod schema type for providerOptions (defaults to ZodTypeAny)
1453
+ *
1454
+ * @example
1455
+ * ```typescript
1456
+ * import { openai } from '@standardagents/openai';
1457
+ *
1458
+ * // openai is a ProviderFactoryWithOptions with typed schema
1459
+ * const provider = openai({ apiKey: 'sk-...' });
1460
+ *
1461
+ * // Access the schema for validation
1462
+ * openai.providerOptions?.parse({ service_tier: 'default' });
1463
+ * ```
1464
+ */
1465
+ interface ProviderFactoryWithOptions<TOptions extends ZodTypeAny = ZodTypeAny> {
1466
+ (config: ProviderFactoryConfig): ProviderInstance;
1467
+ /** Zod schema for provider-specific options */
1468
+ providerOptions?: TOptions;
1469
+ }
1470
+ /**
1471
+ * Factory function that creates provider instances.
1472
+ *
1473
+ * Provider packages (like @standardagents/openai) export this type.
1474
+ * This is an alias for ProviderFactoryWithOptions for backward compatibility.
1475
+ *
1476
+ * @example
1477
+ * ```typescript
1478
+ * import { openai } from '@standardagents/openai';
1479
+ *
1480
+ * // openai is a ProviderFactory
1481
+ * const provider = openai({ apiKey: 'sk-...' });
1482
+ * ```
1483
+ */
1484
+ type ProviderFactory = ProviderFactoryWithOptions<ZodTypeAny>;
1485
+ /**
1486
+ * Extract providerOptions type from a provider factory.
1487
+ *
1488
+ * Returns the inferred input type from the provider's Zod schema,
1489
+ * or Record<string, unknown> if no schema is defined.
1490
+ *
1491
+ * @template P - Provider factory type
1492
+ */
1493
+ type InferProviderOptions<P> = P extends ProviderFactoryWithOptions<infer S> ? S extends ZodTypeAny ? z.input<S> extends Record<string, unknown> ? z.input<S> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown>;
1494
+ /**
1495
+ * Model capability flags indicating supported features.
1496
+ *
1497
+ * These capabilities are used by the FlowEngine to determine how to
1498
+ * interact with the model and what features are available.
1499
+ */
1500
+ interface ModelCapabilities {
1501
+ /**
1502
+ * Reasoning level mapping (0-100 scale → model-specific values).
1503
+ * Keys are breakpoints, values are model's native reasoning strings.
1504
+ *
1505
+ * @example
1506
+ * // OpenAI o-series
1507
+ * reasoningLevels: { 0: null, 33: 'low', 66: 'medium', 100: 'high' }
1508
+ *
1509
+ * @example
1510
+ * // Binary reasoning (Claude extended thinking)
1511
+ * reasoningLevels: { 0: null, 100: 'enabled' }
1512
+ *
1513
+ * @example
1514
+ * // No reasoning support
1515
+ * reasoningLevels: { 0: null }
1516
+ */
1517
+ reasoningLevels?: Record<number, string | null>;
1518
+ /**
1519
+ * Whether the model supports vision (image understanding).
1520
+ * When true, image attachments will be sent to the model as part of the request.
1521
+ * Models like GPT-4o, Claude 3, and Gemini support vision.
1522
+ */
1523
+ supportsImages?: boolean;
1524
+ /**
1525
+ * @deprecated Use supportsImages instead
1526
+ */
1527
+ vision?: boolean;
1528
+ /**
1529
+ * Whether the model supports function calling (tool use).
1530
+ * Most modern models support this, defaults to true if not specified.
1531
+ */
1532
+ supportsToolCalls?: boolean;
1533
+ /**
1534
+ * @deprecated Use supportsToolCalls instead
1535
+ */
1536
+ functionCalling?: boolean;
1537
+ /**
1538
+ * Whether the model supports streaming responses.
1539
+ * @default true
1540
+ */
1541
+ supportsStreaming?: boolean;
1542
+ /**
1543
+ * Whether the model supports structured outputs (JSON mode).
1544
+ */
1545
+ supportsJsonMode?: boolean;
1546
+ /**
1547
+ * @deprecated Use supportsJsonMode instead
1548
+ */
1549
+ structuredOutputs?: boolean;
1550
+ /**
1551
+ * Maximum context window size in tokens.
1552
+ */
1553
+ maxContextTokens?: number;
1554
+ /**
1555
+ * Maximum output tokens the model can generate.
1556
+ */
1557
+ maxOutputTokens?: number;
1558
+ }
1559
+ /**
1560
+ * Model definition configuration.
1561
+ *
1562
+ * Defines an LLM model with its provider, pricing, capabilities, and fallback chain.
1563
+ *
1564
+ * @template N - The model name as a string literal type for type inference
1565
+ *
1566
+ * @example Basic usage
1567
+ * ```typescript
1568
+ * import { defineModel } from '@standardagents/spec';
1569
+ * import { openai } from '@standardagents/openai';
1570
+ *
1571
+ * export default defineModel({
1572
+ * name: 'gpt-4o',
1573
+ * provider: openai,
1574
+ * model: 'gpt-4o',
1575
+ * inputPrice: 2.5,
1576
+ * outputPrice: 10,
1577
+ * });
1578
+ * ```
1579
+ *
1580
+ * @example With capabilities and typed provider options
1581
+ * ```typescript
1582
+ * import { defineModel } from '@standardagents/spec';
1583
+ * import { openai } from '@standardagents/openai';
1584
+ *
1585
+ * export default defineModel({
1586
+ * name: 'gpt-4o',
1587
+ * provider: openai,
1588
+ * model: 'gpt-4o',
1589
+ * inputPrice: 2.5,
1590
+ * outputPrice: 10,
1591
+ * capabilities: {
1592
+ * supportsImages: true,
1593
+ * supportsToolCalls: true,
1594
+ * supportsJsonMode: true,
1595
+ * maxContextTokens: 128000,
1596
+ * },
1597
+ * providerOptions: {
1598
+ * service_tier: 'default', // TypeScript knows this is valid
1599
+ * },
1600
+ * });
1601
+ * ```
1602
+ */
1603
+ interface ModelDefinition<N extends string = string, P extends ProviderFactoryWithOptions<ZodTypeAny> = ProviderFactoryWithOptions<ZodTypeAny>> {
1604
+ /**
1605
+ * Unique name for this model definition.
1606
+ * Used as the identifier when referencing from prompts.
1607
+ * Should be descriptive and consistent (e.g., 'gpt-4o', 'claude-3-opus').
1608
+ */
1609
+ name: N;
1610
+ /**
1611
+ * The LLM provider factory function to use for API calls.
1612
+ *
1613
+ * Import from a provider package like @standardagents/openai or @standardagents/openrouter.
1614
+ * The provider's type determines what providerOptions are available.
1615
+ *
1616
+ * @example
1617
+ * ```typescript
1618
+ * import { openai } from '@standardagents/openai';
1619
+ * provider: openai
1620
+ * ```
1621
+ *
1622
+ * @example
1623
+ * ```typescript
1624
+ * import { openrouter } from '@standardagents/openrouter';
1625
+ * provider: openrouter
1626
+ * ```
1627
+ */
1628
+ provider: P;
1629
+ /**
1630
+ * The actual model identifier sent to the provider API.
1631
+ *
1632
+ * For OpenAI: 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', etc.
1633
+ * For OpenRouter: 'openai/gpt-4o', 'anthropic/claude-3-opus', etc.
1634
+ * For Anthropic: 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', etc.
1635
+ * For Google: 'gemini-1.5-pro', 'gemini-1.5-flash', etc.
1636
+ */
1637
+ model: string;
1638
+ /**
1639
+ * Optional list of additional provider prefixes for OpenRouter.
1640
+ * Allows routing through specific providers when using OpenRouter.
1641
+ *
1642
+ * @example ['anthropic', 'google'] - prefer Anthropic, fallback to Google
1643
+ */
1644
+ includedProviders?: string[];
1645
+ /**
1646
+ * Fallback model names to try if this model fails.
1647
+ * Referenced by model name (must be defined in agents/models/).
1648
+ * Tried in order after primary model exhausts retries.
1649
+ *
1650
+ * @example ['gpt-4', 'gpt-3.5-turbo']
1651
+ */
1652
+ fallbacks?: string[];
1653
+ /**
1654
+ * Cost per 1 million input tokens in USD.
1655
+ * Used for cost tracking and reporting in logs.
1656
+ */
1657
+ inputPrice?: number;
1658
+ /**
1659
+ * Cost per 1 million output tokens in USD.
1660
+ * Used for cost tracking and reporting in logs.
1661
+ */
1662
+ outputPrice?: number;
1663
+ /**
1664
+ * Cost per 1 million cached input tokens in USD.
1665
+ * Some providers offer reduced pricing for cached/repeated prompts.
1666
+ */
1667
+ cachedPrice?: number;
715
1668
  /**
716
- * Execution-specific state.
717
- *
718
- * This is present when the thread is actively executing (tools, hooks)
719
- * and null when accessing a thread at rest (endpoints, external code).
720
- *
721
- * Use this to access step counts, force turns, or stop execution.
1669
+ * Model capabilities - features this model supports.
722
1670
  */
723
- execution: ExecutionState | null;
1671
+ capabilities?: ModelCapabilities;
724
1672
  /**
725
- * Runtime-specific context that cannot be packed or shared.
1673
+ * Provider-specific options passed through to the provider.
1674
+ * These are merged with prompt-level providerOptions (model options are defaults).
726
1675
  *
727
- * This property allows runtime implementations to inject non-portable
728
- * context (e.g., Cloudflare env bindings, database connections).
1676
+ * The type is automatically inferred from the provider's schema when available,
1677
+ * providing TypeScript autocompletion and runtime validation.
729
1678
  *
730
- * WARNING: Tools using this property cannot be packed, shared, or
731
- * published as they depend on runtime-specific context.
732
- */
733
- readonly _notPackableRuntimeContext?: Record<string, unknown>;
734
- }
735
-
736
- /**
737
- * Tool definition types for Standard Agents.
738
- *
739
- * Tools are callable functions that agents can invoke during execution.
740
- * They receive the current ThreadState and validated arguments,
741
- * and return results that are included in the conversation.
742
- *
743
- * @module
744
- */
745
-
746
- /**
747
- * Text content item returned by tools.
748
- */
749
- interface TextContent {
750
- type: 'text';
751
- text: string;
752
- }
753
- /**
754
- * Image content item returned by tools.
755
- */
756
- interface ImageContent {
757
- type: 'image';
758
- /** Base64-encoded image data. */
759
- data: string;
760
- /** MIME type of the image (e.g., 'image/png', 'image/jpeg'). */
761
- mimeType: string;
762
- }
763
- /**
764
- * Content types that can be returned by tools.
765
- */
766
- type ToolContent = TextContent | ImageContent;
767
- /**
768
- * File attachment generated by a tool.
769
- *
770
- * Attachments are stored in the thread's file system and linked to
771
- * the tool result message. Unlike user uploads, tool attachments are
772
- * not subject to image downsampling.
773
- */
774
- interface ToolAttachment {
775
- /** File name for the attachment. */
776
- name: string;
777
- /** MIME type of the attachment. */
778
- mimeType: string;
779
- /** Base64-encoded file data. */
780
- data: string;
781
- /** Width in pixels (for images). */
782
- width?: number;
783
- /** Height in pixels (for images). */
784
- height?: number;
785
- }
786
- /**
787
- * Reference to a pre-existing attachment in the thread file system.
788
- */
789
- interface AttachmentRef {
790
- /** Unique identifier for the attachment. */
791
- id: string;
792
- /** Attachment type. */
793
- type: 'file';
794
- /** Path in the thread file system. */
795
- path: string;
796
- /** File name. */
797
- name: string;
798
- /** MIME type. */
799
- mimeType: string;
800
- /** File size in bytes. */
801
- size: number;
802
- /** Width in pixels (for images). */
803
- width?: number;
804
- /** Height in pixels (for images). */
805
- height?: number;
806
- /** AI-generated description. */
807
- description?: string;
808
- }
809
- /**
810
- * Result returned by a tool execution.
811
- */
812
- interface ToolResult {
813
- /** Status of the tool execution. */
814
- status: 'success' | 'error';
815
- /**
816
- * Text representation of the tool output.
1679
+ * @example
1680
+ * ```typescript
1681
+ * // With OpenAI provider
1682
+ * providerOptions: {
1683
+ * service_tier: 'default',
1684
+ * }
1685
+ * ```
817
1686
  *
818
- * For tools that return structured content, this is derived by
819
- * concatenating all text parts. For simple tools, this is the
820
- * direct result string.
1687
+ * @example
1688
+ * ```typescript
1689
+ * // With OpenRouter provider
1690
+ * providerOptions: {
1691
+ * provider: {
1692
+ * zdr: true,
1693
+ * max_price: { prompt: 1 },
1694
+ * },
1695
+ * }
1696
+ * ```
821
1697
  */
822
- result?: string;
823
- /** Error message if status is 'error'. */
824
- error?: string;
825
- /** Stack trace for error debugging. */
826
- stack?: string;
1698
+ providerOptions?: InferProviderOptions<P>;
827
1699
  /**
828
- * File attachments returned by the tool.
1700
+ * Provider tools available for this model.
1701
+ * References tool names from provider.getTools().
829
1702
  *
830
- * Can contain either:
831
- * - ToolAttachment: New files with base64 data to be stored
832
- * - AttachmentRef: References to existing files in the thread filesystem
1703
+ * Provider tools are built-in tools offered by the provider (e.g., OpenAI's
1704
+ * web_search, file_search, code_interpreter, image_generation). These tools
1705
+ * can be used in prompts alongside custom tools.
833
1706
  *
834
- * Implementations MUST store new attachments under /attachments/ directory.
1707
+ * @example
1708
+ * ```typescript
1709
+ * providerTools: ['web_search', 'code_interpreter'],
1710
+ * ```
835
1711
  */
836
- attachments?: Array<ToolAttachment | AttachmentRef>;
1712
+ providerTools?: string[];
837
1713
  }
838
- /** Decrement helper to limit recursion depth. */
839
- type Dec<N extends number> = N extends 10 ? 9 : N extends 9 ? 8 : N extends 8 ? 7 : N extends 7 ? 6 : N extends 6 ? 5 : N extends 5 ? 4 : N extends 4 ? 3 : N extends 3 ? 2 : N extends 2 ? 1 : N extends 1 ? 0 : 0;
840
- /**
841
- * Allowed Zod types for tool argument nodes.
842
- *
843
- * This is the single source of truth for which Zod types can be used
844
- * in tool argument schemas. The depth parameter limits recursion to
845
- * prevent infinite type expansion.
846
- *
847
- * @template D - Maximum nesting depth (default: 7)
848
- */
849
- type ToolArgsNode<D extends number = 7> = ZodString | ZodNumber | ZodBoolean | ZodNull | ZodLiteral<string | number | boolean | null> | ZodEnum<Readonly<Record<string, string>>> | (D extends 0 ? never : ZodOptional<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodNullable<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodDefault<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodArray<ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodObject<Record<string, ToolArgsNode<Dec<D>>>>) | (D extends 0 ? never : ZodRecord<ZodString, ToolArgsNode<Dec<D>>>) | (D extends 0 ? never : ZodUnion<[
850
- ToolArgsNode<Dec<D>>,
851
- ToolArgsNode<Dec<D>>,
852
- ...ToolArgsNode<Dec<D>>[]
853
- ]>);
854
- /**
855
- * Raw shape for a Zod object schema containing tool argument nodes.
856
- *
857
- * @template D - Maximum nesting depth (default: 7)
858
- */
859
- type ToolArgsRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
860
1714
  /**
861
- * Top-level tool argument schema.
862
- *
863
- * Tool arguments MUST be defined as a Zod object schema.
864
- * This is required for compatibility with OpenAI's function calling API.
1715
+ * Defines an LLM model configuration.
865
1716
  *
866
- * @template D - Maximum nesting depth (default: 7)
867
- */
868
- type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
869
- /**
870
- * Tool function signature.
1717
+ * Models are the foundation of the agent system - they specify which
1718
+ * AI model to use and how to connect to it. Models can have fallbacks
1719
+ * for reliability and include pricing for cost tracking.
871
1720
  *
872
- * Tools are async functions that receive a ThreadState and
873
- * optionally validated arguments, returning a ToolResult.
1721
+ * @template N - The model name as a string literal type
1722
+ * @param options - Model configuration options
1723
+ * @returns The model definition for registration
874
1724
  *
875
- * @template State - The state type (defaults to ThreadState)
876
- * @template Args - The Zod schema for tool arguments, or null for no args
877
- */
878
- type Tool<State = ThreadState, Args extends ToolArgs | null = null> = Args extends ToolArgs ? (state: State, args: z.infer<Args>) => Promise<ToolResult> : (state: State) => Promise<ToolResult>;
879
- /**
880
- * Return type of defineTool function.
1725
+ * @example
1726
+ * ```typescript
1727
+ * // agents/models/gpt_4o.ts
1728
+ * import { defineModel } from '@standardagents/spec';
1729
+ * import { openai } from '@standardagents/openai';
881
1730
  *
882
- * A tuple containing:
883
- * - Tool description string
884
- * - Argument schema (or null)
885
- * - Tool implementation function
886
- */
887
- type ToolDefinition<State = ThreadState, Args extends ToolArgs | null = null> = [string, Args, Tool<State, Args>];
888
- /**
889
- * Define a tool with arguments.
1731
+ * export default defineModel({
1732
+ * name: 'gpt-4o',
1733
+ * provider: openai,
1734
+ * model: 'gpt-4o',
1735
+ * fallbacks: ['gpt-4-turbo'],
1736
+ * inputPrice: 2.5,
1737
+ * outputPrice: 10,
1738
+ * });
1739
+ * ```
890
1740
  *
891
- * @param toolDescription - Description of what the tool does (shown to the LLM)
892
- * @param args - Zod schema for validating tool arguments
893
- * @param tool - The tool implementation function
894
- * @returns A tuple containing the tool definition
895
- */
896
- declare function defineTool<State = ThreadState, Args extends ToolArgs = ToolArgs>(toolDescription: string, args: Args, tool: Tool<State, Args>): ToolDefinition<State, Args>;
897
- /**
898
- * Define a tool without arguments.
1741
+ * @example
1742
+ * ```typescript
1743
+ * // Using OpenRouter with typed provider options
1744
+ * import { openrouter } from '@standardagents/openrouter';
899
1745
  *
900
- * @param toolDescription - Description of what the tool does (shown to the LLM)
901
- * @param tool - The tool implementation function
902
- * @returns A tuple containing the tool definition
1746
+ * export default defineModel({
1747
+ * name: 'claude-3-opus',
1748
+ * provider: openrouter,
1749
+ * model: 'anthropic/claude-3-opus',
1750
+ * providerOptions: {
1751
+ * provider: {
1752
+ * zdr: true,
1753
+ * only: ['anthropic'],
1754
+ * },
1755
+ * },
1756
+ * });
1757
+ * ```
903
1758
  */
904
- declare function defineTool<State = ThreadState>(toolDescription: string, tool: Tool<State, null>): ToolDefinition<State, null>;
1759
+ declare function defineModel<N extends string, P extends ProviderFactoryWithOptions<ZodTypeAny>>(options: ModelDefinition<N, P>): ModelDefinition<N, P>;
905
1760
 
906
1761
  /**
907
1762
  * Prompt definition types for Standard Agents.
@@ -1010,24 +1865,86 @@ interface SubpromptConfig<T extends string = string> {
1010
1865
  * "search term" as the initial user message.
1011
1866
  */
1012
1867
  initUserMessageProperty?: string;
1868
+ /**
1869
+ * Property containing attachment path(s) to include as multimodal content
1870
+ * when invoking the sub-prompt.
1871
+ *
1872
+ * Supports both a single path string or an array of paths.
1873
+ *
1874
+ * @example
1875
+ * If the tool is called with `{ image: "/attachments/123.jpg" }` and
1876
+ * `initAttachmentsProperty: 'image'`, the sub-prompt will receive
1877
+ * the image as an attachment in the user message.
1878
+ *
1879
+ * @example
1880
+ * If the tool is called with `{ images: ["/attachments/a.jpg", "/attachments/b.jpg"] }` and
1881
+ * `initAttachmentsProperty: 'images'`, the sub-prompt will receive
1882
+ * both images as attachments.
1883
+ */
1884
+ initAttachmentsProperty?: string;
1013
1885
  }
1014
1886
  /**
1015
1887
  * @deprecated Use SubpromptConfig instead
1016
1888
  */
1017
1889
  type ToolConfig<T extends string = string> = SubpromptConfig<T>;
1890
+ /**
1891
+ * Configuration for a tool used in a prompt.
1892
+ * Allows specifying tenv values and static options for the tool.
1893
+ *
1894
+ * @example
1895
+ * ```typescript
1896
+ * // Tool with tenv values
1897
+ * { name: 'file_search', tenvs: { vectorStoreId: 'vs_abc123' } }
1898
+ *
1899
+ * // Tool with options
1900
+ * { name: 'web_search', options: { searchContextSize: 'high' } }
1901
+ * ```
1902
+ */
1903
+ interface PromptToolConfig {
1904
+ /**
1905
+ * Name of the tool (custom tool or provider tool).
1906
+ */
1907
+ name: string;
1908
+ /**
1909
+ * Thread environment variable values for this tool.
1910
+ * These values are merged with agent and thread tenvs (prompt tenvs are lowest priority).
1911
+ */
1912
+ tenvs?: Record<string, unknown>;
1913
+ /**
1914
+ * Static options for this tool.
1915
+ * Passed to the tool handler at execution time.
1916
+ */
1917
+ options?: Record<string, unknown>;
1918
+ }
1018
1919
  /**
1019
1920
  * Reasoning configuration for models that support extended thinking.
1020
- * Applies to models like OpenAI o1, Anthropic Claude with extended thinking,
1921
+ * Applies to models like OpenAI o1/o3, Anthropic Claude with extended thinking,
1021
1922
  * Google Gemini with thinking, and Qwen with reasoning.
1022
1923
  */
1023
1924
  interface ReasoningConfig {
1024
1925
  /**
1926
+ * Numeric reasoning level on a 0-100 scale.
1927
+ * The FlowEngine maps this to the model's nearest supported reasoning option.
1928
+ *
1929
+ * @example
1930
+ * // Typical breakpoints:
1931
+ * // 0 = No reasoning
1932
+ * // 33 = Low effort
1933
+ * // 66 = Medium effort
1934
+ * // 100 = Maximum effort
1935
+ *
1936
+ * reasoning: { level: 75 } // Maps to 'high' on most models
1937
+ */
1938
+ level?: number;
1939
+ /**
1940
+ * @deprecated Use `level` instead. Will be removed in future versions.
1941
+ *
1025
1942
  * Effort level for reasoning models.
1026
1943
  * Higher effort = more thinking tokens = potentially better results.
1027
1944
  *
1028
- * - `low`: Minimal reasoning, faster responses
1029
- * - `medium`: Balanced reasoning and speed
1030
- * - `high`: Maximum reasoning, slower but more thorough
1945
+ * - `low`: Minimal reasoning, faster responses (equivalent to level ~33)
1946
+ * - `medium`: Balanced reasoning and speed (equivalent to level ~66)
1947
+ * - `high`: Maximum reasoning, slower but more thorough (equivalent to level ~100)
1031
1948
  *
1032
1949
  * @default undefined (use model defaults)
1033
1950
  */
@@ -1126,10 +2043,37 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
1126
2043
  requiredSchema?: S;
1127
2044
  /**
1128
2045
  * Tools available to this prompt.
1129
- * Can be simple tool names or sub-prompt configurations.
2046
+ * Can be:
2047
+ * - string: Simple tool name (custom or provider tool)
2048
+ * - SubpromptConfig: Sub-prompt used as a tool
2049
+ * - PromptToolConfig: Tool with tenv values and/or options
2050
+ *
1130
2051
  * To enable handoffs, include ai_human agent names in this array.
2052
+ *
2053
+ * @example
2054
+ * ```typescript
2055
+ * tools: [
2056
+ * 'custom_tool', // Simple tool name
2057
+ * { name: 'other_prompt' }, // Sub-prompt as tool
2058
+ * { name: 'file_search', tenvs: { vectorStoreId: 'vs_123' } }, // Tool with tenvs
2059
+ * ]
2060
+ * ```
2061
+ */
2062
+ tools?: (string | SubpromptConfig | PromptToolConfig)[];
2063
+ /**
2064
+ * Thread environment variables for this prompt.
2065
+ * These values are merged with agent and thread tenvs when creating a thread.
2066
+ * Prompt tenvs have lowest priority (overridden by agent and thread tenvs).
2067
+ *
2068
+ * @example
2069
+ * ```typescript
2070
+ * tenvs: {
2071
+ * vectorStoreId: 'vs_default_123',
2072
+ * apiEndpoint: 'https://api.example.com',
2073
+ * }
2074
+ * ```
1131
2075
  */
1132
- tools?: (string | SubpromptConfig)[];
2076
+ tenvs?: Record<string, unknown>;
1133
2077
  /**
1134
2078
  * Reasoning configuration for models that support extended thinking.
1135
2079
  */
@@ -1139,6 +2083,22 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
1139
2083
  * @default 10
1140
2084
  */
1141
2085
  recentImageThreshold?: number;
2086
+ /**
2087
+ * Provider-specific options passed through to the provider.
2088
+ * These override model-level providerOptions for this prompt.
2089
+ *
2090
+ * Options are merged in order (later wins):
2091
+ * 1. model.providerOptions (defaults)
2092
+ * 2. prompt.providerOptions (this field - overrides)
2093
+ *
2094
+ * @example
2095
+ * ```typescript
2096
+ * providerOptions: {
2097
+ * response_format: { type: 'json_object' },
2098
+ * }
2099
+ * ```
2100
+ */
2101
+ providerOptions?: Record<string, unknown>;
1142
2102
  }
1143
2103
  /**
1144
2104
  * Helper type to extract the inferred input type from a prompt's Zod schema.
@@ -1678,6 +2638,24 @@ interface AgentDefinition<N extends string = string, Prompt extends string = str
1678
2638
  * @example 'https://example.com/icon.svg' or '/icons/support.svg'
1679
2639
  */
1680
2640
  icon?: string;
2641
+ /**
2642
+ * Thread environment variables for this agent.
2643
+ * These values are merged with prompt and thread tenvs when creating a thread.
2644
+ *
2645
+ * Merge priority (later wins):
2646
+ * 1. Prompt tenvs (lowest)
2647
+ * 2. Agent tenvs (this field)
2648
+ * 3. Thread tenvs (highest)
2649
+ *
2650
+ * @example
2651
+ * ```typescript
2652
+ * tenvs: {
2653
+ * vectorStoreId: 'vs_agent_default',
2654
+ * apiEndpoint: 'https://api.example.com',
2655
+ * }
2656
+ * ```
2657
+ */
2658
+ tenvs?: Record<string, unknown>;
1681
2659
  }
1682
2660
  /**
1683
2661
  * Defines an agent configuration.
@@ -1890,7 +2868,6 @@ declare function defineController(controller: Controller): Controller;
1890
2868
  *
1891
2869
  * export default defineThreadEndpoint(async (req, state) => {
1892
2870
  * const { messages } = await state.getMessages();
1893
- * const logs = await state.getLogs();
1894
2871
  * return Response.json({
1895
2872
  * thread: {
1896
2873
  * id: state.threadId,
@@ -1899,7 +2876,6 @@ declare function defineController(controller: Controller): Controller;
1899
2876
  * createdAt: state.createdAt,
1900
2877
  * },
1901
2878
  * messages,
1902
- * logs,
1903
2879
  * });
1904
2880
  * });
1905
2881
  * ```
@@ -1921,4 +2897,4 @@ declare function defineController(controller: Controller): Controller;
1921
2897
  */
1922
2898
  declare function defineThreadEndpoint(handler: ThreadEndpointHandler): Controller;
1923
2899
 
1924
- export { type AgentDefinition, type AgentType, type AttachmentRef, type Controller, type ControllerContext, type ControllerReturn, type ExecutionState, type FileChunk, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetLogsOptions, type GetMessagesOptions, type GrepResult, type HookContext, type HookDefinition, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type InjectMessageInput, type LLMMessage, type Log, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type SideConfig, type StructuredPrompt, type SubpromptConfig, type TextContent, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, defineAgent, defineController, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool };
2900
+ export { type AgentDefinition, type AgentType, type AttachmentRef, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type DefineToolOptions, type Effect, type EffectDefinition, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GrepResult, type HookContext, type HookDefinition, 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 Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, ProviderError, type ProviderErrorCode, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderModelInfo, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUserMessage, type ProviderWebSearchResult, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResponseSummary, type ScheduledEffect, type SideConfig, type StructuredPrompt, type SubpromptConfig, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, mapReasoningLevel };