@standardagents/spec 0.14.1 → 0.15.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 +584 -55
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion, ZodTypeAny } from 'zod';
|
|
1
|
+
import { z, ZodString, ZodNumber, ZodBoolean, ZodNull, ZodLiteral, ZodUnknown, ZodEnum, ZodOptional, ZodNullable, ZodDefault, ZodArray, ZodObject, ZodRecord, ZodUnion, ZodTypeAny } from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Global namespace for Standard Agent Specification types.
|
|
@@ -97,11 +97,21 @@ declare global {
|
|
|
97
97
|
* Union of all tool names, or string when registry is empty.
|
|
98
98
|
*/
|
|
99
99
|
type Tools = keyof ToolRegistry extends never ? string : keyof ToolRegistry;
|
|
100
|
+
/**
|
|
101
|
+
* Provider-executed tool reference stored by AgentBuilder prompts.
|
|
102
|
+
*/
|
|
103
|
+
type ProviderCallable = `provider:${string}`;
|
|
104
|
+
/**
|
|
105
|
+
* MCP tool reference stored by AgentBuilder prompts.
|
|
106
|
+
*/
|
|
107
|
+
type McpCallable = `mcp:${string}`;
|
|
100
108
|
/**
|
|
101
109
|
* Union of all callable names, or string when registry is empty.
|
|
102
110
|
* Callables include prompts, agents, and tools that can be used as tools.
|
|
111
|
+
* Provider and MCP tool references use reserved prefixes and remain valid
|
|
112
|
+
* even when generated project registries are populated.
|
|
103
113
|
*/
|
|
104
|
-
type Callables = keyof CallableRegistry extends never ? string : keyof CallableRegistry;
|
|
114
|
+
type Callables = keyof CallableRegistry extends never ? string : keyof CallableRegistry | ProviderCallable | McpCallable;
|
|
105
115
|
/**
|
|
106
116
|
* Union of all hook IDs, or string when registry is empty.
|
|
107
117
|
* Hook IDs are the unique identifiers defined in agents/hooks/ files.
|
|
@@ -115,7 +125,7 @@ declare global {
|
|
|
115
125
|
*
|
|
116
126
|
* Effects are scheduled operations that run outside the tool execution context.
|
|
117
127
|
* They enable implementation-specific side effects with optional delay support,
|
|
118
|
-
* leveraging
|
|
128
|
+
* leveraging whichever scheduling mechanism the runtime provides.
|
|
119
129
|
*
|
|
120
130
|
* Unlike tools, effects:
|
|
121
131
|
* - Do not return results to the LLM
|
|
@@ -462,6 +472,221 @@ interface FileChunk {
|
|
|
462
472
|
/** Whether this is the final chunk */
|
|
463
473
|
isLast: boolean;
|
|
464
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Options passed to {@link ThreadState.runCode}.
|
|
477
|
+
*
|
|
478
|
+
* Code execution is strictly capability-based: the sandbox starts with no
|
|
479
|
+
* ambient capabilities (no `fs`, no `fetch`, no `console`, no host globals).
|
|
480
|
+
* Every capability the sandbox needs must be bridged in explicitly through
|
|
481
|
+
* `imports` or `globals`.
|
|
482
|
+
*
|
|
483
|
+
* Deadlines are **not** an option. Callers impose their own by calling
|
|
484
|
+
* `handle.terminate()` on the returned {@link CodeExecution}.
|
|
485
|
+
*
|
|
486
|
+
* See the [Code Execution specification](https://standardagentspec.com/0.1.0/specification/threads/code-execution)
|
|
487
|
+
* for the full contract.
|
|
488
|
+
*/
|
|
489
|
+
interface CodeExecutionOptions {
|
|
490
|
+
/**
|
|
491
|
+
* Export to execute from the evaluated module and arguments to pass.
|
|
492
|
+
*
|
|
493
|
+
* By default, runtimes execute the module's `default` export with no
|
|
494
|
+
* arguments. If the selected export is a function, it is called with
|
|
495
|
+
* `args` and the returned value or promise is used as the run result. If the
|
|
496
|
+
* selected export is not a function, `args` MUST be omitted or empty and the
|
|
497
|
+
* export value itself becomes the result.
|
|
498
|
+
*
|
|
499
|
+
* @default { fn: 'default', args: [] }
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```ts
|
|
503
|
+
* execute: { fn: 'increment', args: [100] }
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
execute?: {
|
|
507
|
+
/** Export name to execute. Use `'default'` for the default export. */
|
|
508
|
+
fn?: string;
|
|
509
|
+
/** Arguments passed to the selected export when it is a function. */
|
|
510
|
+
args?: unknown[];
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Map of bare module specifier → named exports exposed to the sandbox.
|
|
514
|
+
*
|
|
515
|
+
* Only bare specifiers resolve from `imports` (e.g., `'fs'`,
|
|
516
|
+
* `'@scope/pkg'`). Relative specifiers resolve only from `modules`; URL
|
|
517
|
+
* (`'https://…'`) imports MUST fail at link time.
|
|
518
|
+
*
|
|
519
|
+
* The key `default` within a namespace becomes that module's default export.
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* imports: {
|
|
524
|
+
* fs: { readFile: (path) => state.readFile(path) },
|
|
525
|
+
* supervisor: { report: (payload) => telemetry.push(payload) },
|
|
526
|
+
* }
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
imports?: Record<string, Record<string, unknown>>;
|
|
530
|
+
/**
|
|
531
|
+
* Additional relative ES modules available to the sandbox.
|
|
532
|
+
*
|
|
533
|
+
* Keys are relative module specifiers from the module graph root, such as
|
|
534
|
+
* `'./helpers.js'` or `'./lib/math.js'`. Entry source imports resolve from
|
|
535
|
+
* `filename` when one is supplied. Entry and module source may import sibling
|
|
536
|
+
* or parent modules with `./` and `../` specifiers when those imports resolve
|
|
537
|
+
* within the supplied module graph. Values are JavaScript or TypeScript module
|
|
538
|
+
* source. Use this when a caller wants the entry source to import local files
|
|
539
|
+
* while still keeping all modules inside the sandbox.
|
|
540
|
+
*/
|
|
541
|
+
modules?: Record<string, string>;
|
|
542
|
+
/**
|
|
543
|
+
* Map of identifier → value installed on the sandbox's module scope.
|
|
544
|
+
*
|
|
545
|
+
* These identifiers are resolvable as free variables inside the sandbox
|
|
546
|
+
* but MUST NOT appear on `globalThis`.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* globals: {
|
|
551
|
+
* console: { log: (...args) => logger.info(...args) },
|
|
552
|
+
* getMessage: async () => '...',
|
|
553
|
+
* }
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
globals?: Record<string, unknown>;
|
|
557
|
+
/**
|
|
558
|
+
* Source language. TypeScript source has its types erased before evaluation;
|
|
559
|
+
* no type checking is performed.
|
|
560
|
+
*
|
|
561
|
+
* @default 'typescript'
|
|
562
|
+
*/
|
|
563
|
+
language?: 'javascript' | 'typescript';
|
|
564
|
+
/**
|
|
565
|
+
* Maximum sandbox heap in bytes. Exceeding this settles the handle with
|
|
566
|
+
* `status: 'memory'`. Runtime default is implementation-defined and
|
|
567
|
+
* documented per runtime.
|
|
568
|
+
*/
|
|
569
|
+
memoryLimitBytes?: number;
|
|
570
|
+
/**
|
|
571
|
+
* Label used in stack traces and error `specifier` fields.
|
|
572
|
+
*
|
|
573
|
+
* @default '<runCode>'
|
|
574
|
+
*/
|
|
575
|
+
filename?: string;
|
|
576
|
+
/**
|
|
577
|
+
* Optional host-side sink for the built-in `report` bridge.
|
|
578
|
+
*
|
|
579
|
+
* When provided, the runtime installs a `report` global that forwards values
|
|
580
|
+
* to this callback. Reported values are also appended to the live
|
|
581
|
+
* {@link CodeExecution.reports} view and to the final
|
|
582
|
+
* {@link CodeExecutionResult.reports}.
|
|
583
|
+
*/
|
|
584
|
+
report?: (value: unknown) => void;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Handle returned by {@link ThreadState.runCode}.
|
|
588
|
+
*
|
|
589
|
+
* `CodeExecution` is a `PromiseLike<CodeExecutionResult>` — `await` the handle
|
|
590
|
+
* to get the final result. The handle also exposes controls that only make
|
|
591
|
+
* sense while the run is in flight: caller-initiated termination and a live
|
|
592
|
+
* view of values emitted via the `report` bridge.
|
|
593
|
+
*/
|
|
594
|
+
interface CodeExecution extends PromiseLike<CodeExecutionResult> {
|
|
595
|
+
/**
|
|
596
|
+
* Stop the run. Idempotent: subsequent calls are no-ops.
|
|
597
|
+
*
|
|
598
|
+
* Settles the handle with `status: 'terminated'` at the next ECMAScript
|
|
599
|
+
* yield point (microtask boundary, async operation, or runtime interrupt).
|
|
600
|
+
* Typically a few milliseconds and SHOULD be ≤ 50 ms under normal host load;
|
|
601
|
+
* a pure-synchronous tight loop may run until the runtime's own safety cap
|
|
602
|
+
* fires. When `reason` is provided, it surfaces in `error.message`.
|
|
603
|
+
*/
|
|
604
|
+
terminate(reason?: string): void;
|
|
605
|
+
/** `true` until the handle settles. */
|
|
606
|
+
readonly running: boolean;
|
|
607
|
+
/**
|
|
608
|
+
* Snapshot of values emitted via the `report` bridge so far, in call order.
|
|
609
|
+
* The same values appear in {@link CodeExecutionResult.reports} once the
|
|
610
|
+
* run ends.
|
|
611
|
+
*/
|
|
612
|
+
readonly reports: readonly unknown[];
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Outcome classification for {@link CodeExecutionResult.status}.
|
|
616
|
+
*
|
|
617
|
+
* - `success` — Module evaluated and the configured export resolved.
|
|
618
|
+
* - `error` — Uncaught runtime error inside the sandbox.
|
|
619
|
+
* - `memory` — `memoryLimitBytes` exceeded.
|
|
620
|
+
* - `terminated` — Caller called `handle.terminate()`, or the runtime's own
|
|
621
|
+
* safety cap fired. `error.message` distinguishes the two (including any
|
|
622
|
+
* `reason` the caller passed).
|
|
623
|
+
* - `link_error` — Module graph failed to link (unknown specifier, missing
|
|
624
|
+
* named export, parse error).
|
|
625
|
+
*/
|
|
626
|
+
type CodeExecutionStatus = 'success' | 'error' | 'memory' | 'terminated' | 'link_error';
|
|
627
|
+
/**
|
|
628
|
+
* A single captured `console.*` call from inside the sandbox.
|
|
629
|
+
*
|
|
630
|
+
* Only populated when the runtime installs a capturing `console` (typically
|
|
631
|
+
* when the caller does not provide one via `options.globals`).
|
|
632
|
+
*/
|
|
633
|
+
interface CodeExecutionLog {
|
|
634
|
+
level: 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
635
|
+
/** Marshaled argument values, deep-cloned from the sandbox. */
|
|
636
|
+
args: unknown[];
|
|
637
|
+
/** Millisecond timestamp when the call occurred. */
|
|
638
|
+
timestamp: number;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Error surfaced when a {@link CodeExecutionResult} does not have
|
|
642
|
+
* `status: 'success'`.
|
|
643
|
+
*
|
|
644
|
+
* Host-side stack frames MUST NOT leak into this object — only sandbox
|
|
645
|
+
* frames are included.
|
|
646
|
+
*/
|
|
647
|
+
interface CodeExecutionError {
|
|
648
|
+
name: string;
|
|
649
|
+
message: string;
|
|
650
|
+
stack?: string;
|
|
651
|
+
/** Module specifier that failed to link (for `link_error`). */
|
|
652
|
+
specifier?: string;
|
|
653
|
+
/** Source filename associated with `line` and `column`, when available. */
|
|
654
|
+
filename?: string;
|
|
655
|
+
/** 1-based line number in source, when available. */
|
|
656
|
+
line?: number;
|
|
657
|
+
/** 1-based column number in source, when available. */
|
|
658
|
+
column?: number;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Result of a {@link ThreadState.runCode} call.
|
|
662
|
+
*
|
|
663
|
+
* The sandbox has two result channels and both may be used in the same run:
|
|
664
|
+
* - **Configured export** → marshaled into `result` on success.
|
|
665
|
+
* - **Bridge reports** → appended to `reports` in call order as they are emitted.
|
|
666
|
+
*/
|
|
667
|
+
interface CodeExecutionResult {
|
|
668
|
+
/** Outcome classification — see {@link CodeExecutionStatus}. */
|
|
669
|
+
status: CodeExecutionStatus;
|
|
670
|
+
/**
|
|
671
|
+
* Resolved configured export (after awaiting top-level promises).
|
|
672
|
+
* Omitted when `status !== 'success'`. `undefined` is a valid success result
|
|
673
|
+
* when the configured export resolves to `undefined`.
|
|
674
|
+
*/
|
|
675
|
+
result?: unknown;
|
|
676
|
+
/**
|
|
677
|
+
* Values emitted through the built-in `report` bridge when
|
|
678
|
+
* `options.report` is supplied, in call order. Empty when unused.
|
|
679
|
+
*/
|
|
680
|
+
reports: unknown[];
|
|
681
|
+
/** Captured `console.*` calls (see {@link CodeExecutionLog}). Empty when the caller supplies its own `console`. */
|
|
682
|
+
logs: CodeExecutionLog[];
|
|
683
|
+
/** Error detail. Present iff `status` is not `'success'`. */
|
|
684
|
+
error?: CodeExecutionError;
|
|
685
|
+
/** Wall-clock execution time in milliseconds. */
|
|
686
|
+
durationMs: number;
|
|
687
|
+
/** Peak sandbox heap in bytes, when the engine can measure it. */
|
|
688
|
+
memoryUsedBytes?: number;
|
|
689
|
+
}
|
|
465
690
|
/**
|
|
466
691
|
* Execution-specific state available during agent execution.
|
|
467
692
|
*
|
|
@@ -520,6 +745,24 @@ interface ExecutionState {
|
|
|
520
745
|
*/
|
|
521
746
|
readonly promptPath: string[];
|
|
522
747
|
}
|
|
748
|
+
/**
|
|
749
|
+
* Display/redaction classification for thread-scoped environment values.
|
|
750
|
+
*
|
|
751
|
+
* `secret` values should be redacted from tool output and logs. `text` values
|
|
752
|
+
* may be displayed.
|
|
753
|
+
*/
|
|
754
|
+
type EnvValueType = 'text' | 'secret';
|
|
755
|
+
/**
|
|
756
|
+
* Options for {@link ThreadState.setEnv}.
|
|
757
|
+
*/
|
|
758
|
+
interface SetEnvOptions {
|
|
759
|
+
/**
|
|
760
|
+
* Display/redaction classification for this value.
|
|
761
|
+
*
|
|
762
|
+
* Defaults to the existing type for that key, or `secret` for new keys.
|
|
763
|
+
*/
|
|
764
|
+
type?: EnvValueType;
|
|
765
|
+
}
|
|
523
766
|
/**
|
|
524
767
|
* The unified interface for all thread operations.
|
|
525
768
|
*
|
|
@@ -554,10 +797,10 @@ interface ExecutionState {
|
|
|
554
797
|
* @example
|
|
555
798
|
* ```typescript
|
|
556
799
|
* // In an endpoint
|
|
557
|
-
* export default defineThreadEndpoint(async (req, state) => {
|
|
800
|
+
* export default defineThreadEndpoint(async (req, state, params) => {
|
|
558
801
|
* // state.execution is null (not executing)
|
|
559
802
|
* const { messages } = await state.getMessages({ limit: 50 });
|
|
560
|
-
* return Response.json({ messages });
|
|
803
|
+
* return Response.json({ messages, params });
|
|
561
804
|
* });
|
|
562
805
|
* ```
|
|
563
806
|
*/
|
|
@@ -698,6 +941,13 @@ interface ThreadState {
|
|
|
698
941
|
* @throws If the variable is not defined in any source
|
|
699
942
|
*/
|
|
700
943
|
env(propertyName: string): Promise<string>;
|
|
944
|
+
/**
|
|
945
|
+
* Resolve the display/redaction type for an environment value.
|
|
946
|
+
*
|
|
947
|
+
* Values marked `secret` should be redacted from tool output and logs.
|
|
948
|
+
* Values marked `text` may be shown. Unknown values default to `secret`.
|
|
949
|
+
*/
|
|
950
|
+
envType(propertyName: string): Promise<EnvValueType>;
|
|
701
951
|
/**
|
|
702
952
|
* Set a thread-scoped environment variable.
|
|
703
953
|
*
|
|
@@ -707,8 +957,9 @@ interface ThreadState {
|
|
|
707
957
|
*
|
|
708
958
|
* @param propertyName - Environment variable name
|
|
709
959
|
* @param value - Environment variable value
|
|
960
|
+
* @param options - Optional display/redaction classification for this value
|
|
710
961
|
*/
|
|
711
|
-
setEnv(propertyName: string, value: string): Promise<void>;
|
|
962
|
+
setEnv(propertyName: string, value: string, options?: SetEnvOptions): Promise<void>;
|
|
712
963
|
/**
|
|
713
964
|
* Queue a silent message to this thread's parent, if one exists.
|
|
714
965
|
*
|
|
@@ -787,13 +1038,14 @@ interface ThreadState {
|
|
|
787
1038
|
*/
|
|
788
1039
|
getScheduledEffects(name?: string): Promise<ScheduledEffect[]>;
|
|
789
1040
|
/**
|
|
790
|
-
*
|
|
1041
|
+
* Cancel a scheduled effect.
|
|
791
1042
|
*
|
|
792
|
-
* Cancels a pending effect before it executes. Has no effect if the
|
|
793
|
-
*
|
|
1043
|
+
* Cancels a pending effect before it executes. Has no effect if the effect
|
|
1044
|
+
* has already executed, was already canceled, or doesn't exist. Runtimes may
|
|
1045
|
+
* retain canceled effects in inspection history.
|
|
794
1046
|
*
|
|
795
1047
|
* @param id - The effect ID returned by scheduleEffect
|
|
796
|
-
* @returns true if the effect was found and
|
|
1048
|
+
* @returns true if the effect was found and canceled, false otherwise
|
|
797
1049
|
*/
|
|
798
1050
|
removeScheduledEffect(id: string): Promise<boolean>;
|
|
799
1051
|
/**
|
|
@@ -837,10 +1089,47 @@ interface ThreadState {
|
|
|
837
1089
|
* Key-value storage for custom data scoped to this thread.
|
|
838
1090
|
*
|
|
839
1091
|
* Context data persists across tool calls within a single execution.
|
|
840
|
-
* For persistent storage across executions, use
|
|
841
|
-
* storage.
|
|
1092
|
+
* For persistent storage across executions, use {@link ThreadState.getValue}
|
|
1093
|
+
* and {@link ThreadState.setValue}, the file system, or external storage.
|
|
842
1094
|
*/
|
|
843
1095
|
context: Record<string, unknown>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Read a value from the thread's durable key-value store.
|
|
1098
|
+
*
|
|
1099
|
+
* Values written with {@link ThreadState.setValue} persist across executions,
|
|
1100
|
+
* tool calls, hook invocations, and endpoint requests for the lifetime of
|
|
1101
|
+
* the thread. The key-value store is one of two ways to store persistent
|
|
1102
|
+
* data on a thread, alongside the file system.
|
|
1103
|
+
*
|
|
1104
|
+
* Returns `null` when no value has been set for the given key. Values are
|
|
1105
|
+
* returned exactly as they were stored; runtimes MUST preserve JSON-equivalent
|
|
1106
|
+
* structure (objects, arrays, strings, numbers, booleans, `null`).
|
|
1107
|
+
*
|
|
1108
|
+
* @param key - The key to read
|
|
1109
|
+
* @returns The stored value, or `null` if the key has no value
|
|
1110
|
+
*
|
|
1111
|
+
* @example
|
|
1112
|
+
* ```typescript
|
|
1113
|
+
* const count = (await state.getValue<number>('invocation_count')) ?? 0;
|
|
1114
|
+
* await state.setValue('invocation_count', count + 1);
|
|
1115
|
+
* ```
|
|
1116
|
+
*/
|
|
1117
|
+
getValue<T = unknown>(key: string): Promise<T | null>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Write a value to the thread's durable key-value store.
|
|
1120
|
+
*
|
|
1121
|
+
* The value persists across executions for the lifetime of the thread.
|
|
1122
|
+
* Passing `null` or `undefined` deletes the key. Values MUST be
|
|
1123
|
+
* JSON-serializable; implementations MAY reject non-serializable values.
|
|
1124
|
+
*
|
|
1125
|
+
* Durable values are **not** automatically copied between threads when
|
|
1126
|
+
* subagents are spawned — each thread maintains its own key-value store.
|
|
1127
|
+
*
|
|
1128
|
+
* @param key - The key to write
|
|
1129
|
+
* @param value - The value to store (JSON-serializable), or `null`/`undefined`
|
|
1130
|
+
* to delete the key
|
|
1131
|
+
*/
|
|
1132
|
+
setValue(key: string, value: unknown): Promise<void>;
|
|
844
1133
|
/**
|
|
845
1134
|
* Write a file to the thread's file system.
|
|
846
1135
|
*
|
|
@@ -954,11 +1243,79 @@ interface ThreadState {
|
|
|
954
1243
|
* Use this to access step counts, force turns, or stop execution.
|
|
955
1244
|
*/
|
|
956
1245
|
execution: ExecutionState | null;
|
|
1246
|
+
/**
|
|
1247
|
+
* Execute JavaScript or TypeScript source in an isolated sandbox.
|
|
1248
|
+
*
|
|
1249
|
+
* The sandbox has **no ambient capabilities**: no filesystem, no network,
|
|
1250
|
+
* no timers, no host globals, no access to `state` itself. Every capability
|
|
1251
|
+
* the sandbox needs must be bridged in explicitly via `options.imports`,
|
|
1252
|
+
* `options.modules`, or `options.globals`.
|
|
1253
|
+
*
|
|
1254
|
+
* Returns a {@link CodeExecution} handle that is a
|
|
1255
|
+
* `PromiseLike<CodeExecutionResult>` — `await` it for the final result — and
|
|
1256
|
+
* also exposes `terminate()` for caller-initiated cancellation. The spec
|
|
1257
|
+
* does not impose a wall-clock timeout; callers layer their own deadline
|
|
1258
|
+
* using a timer plus `handle.terminate()`.
|
|
1259
|
+
*
|
|
1260
|
+
* Results flow back through either:
|
|
1261
|
+
* - the module export selected by `options.execute` (marshaled into
|
|
1262
|
+
* `result.result`; defaults to the `default` export with no arguments; if
|
|
1263
|
+
* the selected export is a function, it is called with `execute.args` and
|
|
1264
|
+
* any returned promise is awaited before marshaling), or
|
|
1265
|
+
* - the built-in `report` bridge (accumulated into `result.reports` and
|
|
1266
|
+
* visible live on `handle.reports`), or
|
|
1267
|
+
* - caller-installed bridge callbacks that the caller owns.
|
|
1268
|
+
*
|
|
1269
|
+
* See the [Code Execution specification](https://standardagentspec.com/0.1.0/specification/threads/code-execution)
|
|
1270
|
+
* for isolation guarantees, module resolution rules, value marshaling, and
|
|
1271
|
+
* conformance requirements.
|
|
1272
|
+
*
|
|
1273
|
+
* @param source - JavaScript or TypeScript source, evaluated as an ES module.
|
|
1274
|
+
* @param options - Export selection, imports, globals, memory cap, and language hints.
|
|
1275
|
+
* @returns A handle that settles with the execution result and can be
|
|
1276
|
+
* terminated at any time before settlement.
|
|
1277
|
+
*
|
|
1278
|
+
* @example
|
|
1279
|
+
* ```typescript
|
|
1280
|
+
* const run = state.runCode(
|
|
1281
|
+
* `
|
|
1282
|
+
* import { readFile } from 'fs';
|
|
1283
|
+
* import { report } from 'supervisor';
|
|
1284
|
+
*
|
|
1285
|
+
* const message = await getMessage();
|
|
1286
|
+
* if (/username/.test(message)) {
|
|
1287
|
+
* report({ topic: 'username', message });
|
|
1288
|
+
* }
|
|
1289
|
+
* export default async () => ({ scanned: true });
|
|
1290
|
+
* `,
|
|
1291
|
+
* {
|
|
1292
|
+
* imports: {
|
|
1293
|
+
* fs: { readFile: (p) => state.readFile(p) },
|
|
1294
|
+
* supervisor: { report: (payload) => flagged.push(payload) },
|
|
1295
|
+
* },
|
|
1296
|
+
* globals: {
|
|
1297
|
+
* console: { log: (...a) => {} },
|
|
1298
|
+
* getMessage: async () => 'latest user message',
|
|
1299
|
+
* },
|
|
1300
|
+
* },
|
|
1301
|
+
* );
|
|
1302
|
+
*
|
|
1303
|
+
* const deadline = setTimeout(() => run.terminate('5s budget'), 5_000);
|
|
1304
|
+
* const result = await run;
|
|
1305
|
+
* clearTimeout(deadline);
|
|
1306
|
+
*
|
|
1307
|
+
* if (result.status === 'success') {
|
|
1308
|
+
* // result.result === { scanned: true }
|
|
1309
|
+
* }
|
|
1310
|
+
* ```
|
|
1311
|
+
*/
|
|
1312
|
+
runCode(source: string, options?: CodeExecutionOptions): CodeExecution;
|
|
957
1313
|
/**
|
|
958
1314
|
* Runtime-specific context that cannot be packed or shared.
|
|
959
1315
|
*
|
|
960
|
-
* This property
|
|
961
|
-
*
|
|
1316
|
+
* This property lets runtime implementations inject non-portable context —
|
|
1317
|
+
* typically host bindings, database connections, or other
|
|
1318
|
+
* platform-specific handles the runtime chooses to expose.
|
|
962
1319
|
*
|
|
963
1320
|
* WARNING: Tools using this property cannot be packed, shared, or
|
|
964
1321
|
* published as they depend on runtime-specific context.
|
|
@@ -1089,10 +1446,12 @@ type Dec<N extends number> = N extends 10 ? 9 : N extends 9 ? 8 : N extends 8 ?
|
|
|
1089
1446
|
* This is the single source of truth for which Zod types can be used
|
|
1090
1447
|
* in tool argument schemas. The depth parameter limits recursion to
|
|
1091
1448
|
* prevent infinite type expansion.
|
|
1449
|
+
* Use ZodUnknown for arbitrary JSON slots, such as array items that can
|
|
1450
|
+
* be strings, numbers, booleans, null, arrays, or objects.
|
|
1092
1451
|
*
|
|
1093
1452
|
* @template D - Maximum nesting depth (default: 7)
|
|
1094
1453
|
*/
|
|
1095
|
-
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<[
|
|
1454
|
+
type ToolArgsNode<D extends number = 7> = ZodString | ZodNumber | ZodBoolean | ZodNull | ZodLiteral<string | number | boolean | null> | ZodUnknown | 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<readonly [
|
|
1096
1455
|
ToolArgsNode<Dec<D>>,
|
|
1097
1456
|
ToolArgsNode<Dec<D>>,
|
|
1098
1457
|
...ToolArgsNode<Dec<D>>[]
|
|
@@ -1477,6 +1836,16 @@ interface ProviderModelInfo {
|
|
|
1477
1836
|
iconId?: string;
|
|
1478
1837
|
/** Optional slug for additional lookups (e.g., OpenRouter endpoint queries) */
|
|
1479
1838
|
slug?: string;
|
|
1839
|
+
/**
|
|
1840
|
+
* Optional capability hints surfaced from the provider's listing
|
|
1841
|
+
* payload. Populated when the provider can derive support flags
|
|
1842
|
+
* (vision / tool calls / streaming / JSON mode) without an
|
|
1843
|
+
* additional per-model probe — lets UIs render the capability
|
|
1844
|
+
* matrix on every row in the picker. Omit when the provider
|
|
1845
|
+
* doesn't expose enough metadata; consumers must tolerate
|
|
1846
|
+
* undefined.
|
|
1847
|
+
*/
|
|
1848
|
+
capabilities?: ModelCapabilities;
|
|
1480
1849
|
}
|
|
1481
1850
|
/**
|
|
1482
1851
|
* Query params for provider-backed model discovery.
|
|
@@ -1546,7 +1915,11 @@ interface LLMProviderInterface {
|
|
|
1546
1915
|
/**
|
|
1547
1916
|
* Get tools embedded in this provider.
|
|
1548
1917
|
* Optional - providers may implement this to expose built-in tools
|
|
1549
|
-
* (e.g., OpenAI's web_search
|
|
1918
|
+
* (e.g., OpenAI's web_search or xAI's x_search).
|
|
1919
|
+
*
|
|
1920
|
+
* Tool names are provider-defined capability names. Standard Agents defines
|
|
1921
|
+
* discovery, selection, execution ownership, and result reporting; providers
|
|
1922
|
+
* define their own native request mapping.
|
|
1550
1923
|
*
|
|
1551
1924
|
* These tools are defined using defineTool() with optional variable requirements.
|
|
1552
1925
|
* Tools returned here can be referenced by name in model/prompt definitions.
|
|
@@ -1753,6 +2126,12 @@ interface ProviderToolCallPart {
|
|
|
1753
2126
|
id: string;
|
|
1754
2127
|
name: string;
|
|
1755
2128
|
arguments: Record<string, unknown>;
|
|
2129
|
+
/**
|
|
2130
|
+
* Provider-specific metadata that must round-trip with the tool call.
|
|
2131
|
+
* For example, Gemini tool calls can include a thought signature that must
|
|
2132
|
+
* be echoed back on the next turn for tool calling to continue working.
|
|
2133
|
+
*/
|
|
2134
|
+
extraContent?: Record<string, unknown>;
|
|
1756
2135
|
}
|
|
1757
2136
|
type ProviderToolResultContent = string | {
|
|
1758
2137
|
type: 'text';
|
|
@@ -1767,6 +2146,14 @@ interface ProviderResponse {
|
|
|
1767
2146
|
reasoningDetails?: ProviderReasoningDetail[];
|
|
1768
2147
|
toolCalls?: ProviderToolCallPart[];
|
|
1769
2148
|
images?: ProviderGeneratedImage[];
|
|
2149
|
+
/**
|
|
2150
|
+
* Provider-executed tool calls surfaced for logging and inspection.
|
|
2151
|
+
*
|
|
2152
|
+
* Providers should populate this when the upstream provider executed a
|
|
2153
|
+
* built-in/native tool server-side. These entries are informational for
|
|
2154
|
+
* Standard Agents and must not be re-executed locally.
|
|
2155
|
+
*/
|
|
2156
|
+
providerTools?: ProviderExecutedToolResult[];
|
|
1770
2157
|
finishReason: ProviderFinishReason;
|
|
1771
2158
|
usage: ProviderUsage;
|
|
1772
2159
|
metadata?: Record<string, unknown>;
|
|
@@ -1821,6 +2208,57 @@ interface ProviderWebSearchResult {
|
|
|
1821
2208
|
}>;
|
|
1822
2209
|
}>;
|
|
1823
2210
|
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Provider-executed tool call surfaced for logging.
|
|
2213
|
+
*
|
|
2214
|
+
* Providers use this when the upstream model provider executes a native tool
|
|
2215
|
+
* server-side and Standard Agents should record the call without attempting to
|
|
2216
|
+
* execute it locally.
|
|
2217
|
+
*/
|
|
2218
|
+
interface ProviderExecutedToolResult {
|
|
2219
|
+
/** Provider-facing tool name, such as "web_search" or "x_search" */
|
|
2220
|
+
name: string;
|
|
2221
|
+
/**
|
|
2222
|
+
* Legacy alias for `name`, retained for persisted log compatibility.
|
|
2223
|
+
* New provider implementations should set `name`; runtimes may mirror it
|
|
2224
|
+
* into `type` when serializing logs for older UIs.
|
|
2225
|
+
*/
|
|
2226
|
+
type?: string;
|
|
2227
|
+
/** Provider that executed the tool, such as "openai" or "xai" */
|
|
2228
|
+
provider?: string;
|
|
2229
|
+
/** Unique ID of the provider tool call */
|
|
2230
|
+
id: string;
|
|
2231
|
+
/** Execution status */
|
|
2232
|
+
status: 'completed' | 'failed' | 'in_progress';
|
|
2233
|
+
/** Optional provider-specific result or argument summary */
|
|
2234
|
+
result?: {
|
|
2235
|
+
actions?: Array<{
|
|
2236
|
+
type: string;
|
|
2237
|
+
query?: string;
|
|
2238
|
+
url?: string;
|
|
2239
|
+
pattern?: string;
|
|
2240
|
+
sources?: Array<{
|
|
2241
|
+
type?: string;
|
|
2242
|
+
url: string;
|
|
2243
|
+
title?: string;
|
|
2244
|
+
}>;
|
|
2245
|
+
}>;
|
|
2246
|
+
input?: Record<string, unknown>;
|
|
2247
|
+
output?: string;
|
|
2248
|
+
results?: unknown[];
|
|
2249
|
+
artifacts?: Array<{
|
|
2250
|
+
type: string;
|
|
2251
|
+
id?: string;
|
|
2252
|
+
mediaType?: string;
|
|
2253
|
+
url?: string;
|
|
2254
|
+
path?: string;
|
|
2255
|
+
title?: string;
|
|
2256
|
+
metadata?: Record<string, unknown>;
|
|
2257
|
+
}>;
|
|
2258
|
+
};
|
|
2259
|
+
/** Provider-specific structured details that should stay JSON-serializable */
|
|
2260
|
+
metadata?: Record<string, unknown>;
|
|
2261
|
+
}
|
|
1824
2262
|
type ProviderStreamChunk = {
|
|
1825
2263
|
type: 'content-delta';
|
|
1826
2264
|
delta: string;
|
|
@@ -1835,6 +2273,7 @@ type ProviderStreamChunk = {
|
|
|
1835
2273
|
type: 'tool-call-start';
|
|
1836
2274
|
id: string;
|
|
1837
2275
|
name: string;
|
|
2276
|
+
extraContent?: Record<string, unknown>;
|
|
1838
2277
|
} | {
|
|
1839
2278
|
type: 'tool-call-delta';
|
|
1840
2279
|
id: string;
|
|
@@ -1843,6 +2282,7 @@ type ProviderStreamChunk = {
|
|
|
1843
2282
|
type: 'tool-call-done';
|
|
1844
2283
|
id: string;
|
|
1845
2284
|
arguments: Record<string, unknown>;
|
|
2285
|
+
extraContent?: Record<string, unknown>;
|
|
1846
2286
|
} | {
|
|
1847
2287
|
type: 'image-delta';
|
|
1848
2288
|
index: number;
|
|
@@ -1854,6 +2294,9 @@ type ProviderStreamChunk = {
|
|
|
1854
2294
|
} | {
|
|
1855
2295
|
type: 'web-search-done';
|
|
1856
2296
|
result: ProviderWebSearchResult;
|
|
2297
|
+
} | {
|
|
2298
|
+
type: 'provider-tool-done';
|
|
2299
|
+
tool: ProviderExecutedToolResult;
|
|
1857
2300
|
} | {
|
|
1858
2301
|
type: 'finish';
|
|
1859
2302
|
finishReason: ProviderFinishReason;
|
|
@@ -1916,7 +2359,7 @@ interface ProviderInstance {
|
|
|
1916
2359
|
getModelsPage?(query?: ProviderModelsQuery): Promise<ProviderModelsPage>;
|
|
1917
2360
|
/** Fetch capabilities for a specific model */
|
|
1918
2361
|
getModelCapabilities?(modelId: string): Promise<ModelCapabilities | null>;
|
|
1919
|
-
/** Get provider-
|
|
2362
|
+
/** Get provider-defined built-in tools available for a model */
|
|
1920
2363
|
getTools?(modelId?: string): Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>> | Promise<Record<string, ToolDefinition<unknown, ToolArgs | null, ToolTenvs | null>>>;
|
|
1921
2364
|
/** Get the icon URL for this provider or a specific model */
|
|
1922
2365
|
getIcon?(modelId?: string): string | undefined;
|
|
@@ -2190,9 +2633,10 @@ interface ModelDefinition<N extends string = string, P extends ProviderFactoryWi
|
|
|
2190
2633
|
* Provider tools available for this model.
|
|
2191
2634
|
* References tool names from provider.getTools().
|
|
2192
2635
|
*
|
|
2193
|
-
* Provider tools are built-in tools offered by the provider
|
|
2194
|
-
*
|
|
2195
|
-
* can be used in prompts alongside custom tools
|
|
2636
|
+
* Provider tools are built-in tools offered by the provider. Tool names are
|
|
2637
|
+
* provider-defined capability names, not Standard Agents global names. These
|
|
2638
|
+
* tools can be used in prompts alongside custom tools and are executed by
|
|
2639
|
+
* the upstream provider.
|
|
2196
2640
|
*
|
|
2197
2641
|
* @example
|
|
2198
2642
|
* ```typescript
|
|
@@ -2432,7 +2876,9 @@ interface PromptToolConfig {
|
|
|
2432
2876
|
* Non-resumable subagents behave like normal tool calls.
|
|
2433
2877
|
* Resumable subagents are created/messaged through runtime-injected lifecycle
|
|
2434
2878
|
* tools (for example `subagent_create` and `subagent_message`) and tracked in
|
|
2435
|
-
* the parent thread registry.
|
|
2879
|
+
* the parent thread registry. The injected `subagent_create` tool MUST require
|
|
2880
|
+
* a non-empty human-readable `name` argument and runtimes SHOULD persist it as
|
|
2881
|
+
* a child thread display name.
|
|
2436
2882
|
*
|
|
2437
2883
|
* @example
|
|
2438
2884
|
* ```typescript
|
|
@@ -2816,12 +3262,16 @@ declare function definePrompt<N extends string, S extends ToolArgs = never>(opti
|
|
|
2816
3262
|
*
|
|
2817
3263
|
* @example
|
|
2818
3264
|
* ```typescript
|
|
2819
|
-
* const hook = defineHook(
|
|
2820
|
-
*
|
|
2821
|
-
*
|
|
2822
|
-
*
|
|
2823
|
-
*
|
|
2824
|
-
*
|
|
3265
|
+
* const hook = defineHook({
|
|
3266
|
+
* hook: 'filter_messages',
|
|
3267
|
+
* id: 'keep_recent',
|
|
3268
|
+
* execute: async (state, messages) => {
|
|
3269
|
+
* console.log(`Thread: ${state.threadId}`);
|
|
3270
|
+
* if (state.execution) {
|
|
3271
|
+
* console.log(`Step: ${state.execution.stepCount}`);
|
|
3272
|
+
* }
|
|
3273
|
+
* return messages.slice(-10);
|
|
3274
|
+
* },
|
|
2825
3275
|
* });
|
|
2826
3276
|
* ```
|
|
2827
3277
|
*/
|
|
@@ -2908,6 +3358,38 @@ interface LLMMessage {
|
|
|
2908
3358
|
* @template ToolResult - The tool result type (defaults to HookToolResult)
|
|
2909
3359
|
*/
|
|
2910
3360
|
interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = HookToolCall, ToolResult = HookToolResult> {
|
|
3361
|
+
/**
|
|
3362
|
+
* Called after a thread is created, before initial message processing or LLM
|
|
3363
|
+
* requests for that thread.
|
|
3364
|
+
*
|
|
3365
|
+
* Only ThreadState is passed. Use for initializing durable thread values,
|
|
3366
|
+
* env placeholders, files, or side-effect instrumentation.
|
|
3367
|
+
*
|
|
3368
|
+
* @param state - Created thread state
|
|
3369
|
+
*/
|
|
3370
|
+
after_thread_created: (state: State) => Promise<void>;
|
|
3371
|
+
/**
|
|
3372
|
+
* Called on the parent thread immediately after a subagent child thread is
|
|
3373
|
+
* created.
|
|
3374
|
+
*
|
|
3375
|
+
* Receives parent ThreadState and child ThreadState. Use for copying or
|
|
3376
|
+
* linking metadata, bookkeeping, or side-effect instrumentation.
|
|
3377
|
+
*
|
|
3378
|
+
* @param state - Parent thread state
|
|
3379
|
+
* @param childState - Created child thread state
|
|
3380
|
+
*/
|
|
3381
|
+
after_subagent_created: (state: State, childState: State) => Promise<void>;
|
|
3382
|
+
/**
|
|
3383
|
+
* Called after the prompt system message is rendered for a model request.
|
|
3384
|
+
*
|
|
3385
|
+
* Return a string to replace the rendered system message. Return null or
|
|
3386
|
+
* undefined to keep the original message.
|
|
3387
|
+
*
|
|
3388
|
+
* @param state - Thread state
|
|
3389
|
+
* @param systemMessage - Rendered system message for this request
|
|
3390
|
+
* @returns Replacement system message, or null/undefined for no change
|
|
3391
|
+
*/
|
|
3392
|
+
after_system_message: (state: State, systemMessage: string) => string | Promise<string | null | undefined> | null | undefined;
|
|
2911
3393
|
/**
|
|
2912
3394
|
* Called before messages are filtered and sent to the LLM.
|
|
2913
3395
|
*
|
|
@@ -2920,9 +3402,10 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
2920
3402
|
*
|
|
2921
3403
|
* @example
|
|
2922
3404
|
* ```typescript
|
|
2923
|
-
* defineHook(
|
|
2924
|
-
*
|
|
2925
|
-
*
|
|
3405
|
+
* defineHook({
|
|
3406
|
+
* hook: 'filter_messages',
|
|
3407
|
+
* id: 'limit_to_10',
|
|
3408
|
+
* execute: async (state, messages) => messages.slice(-10),
|
|
2926
3409
|
* });
|
|
2927
3410
|
* ```
|
|
2928
3411
|
*/
|
|
@@ -2939,9 +3422,10 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
2939
3422
|
*
|
|
2940
3423
|
* @example
|
|
2941
3424
|
* ```typescript
|
|
2942
|
-
* defineHook(
|
|
2943
|
-
*
|
|
2944
|
-
*
|
|
3425
|
+
* defineHook({
|
|
3426
|
+
* hook: 'prefilter_llm_history',
|
|
3427
|
+
* id: 'add_reminder',
|
|
3428
|
+
* execute: async (state, messages) => messages,
|
|
2945
3429
|
* });
|
|
2946
3430
|
* ```
|
|
2947
3431
|
*/
|
|
@@ -3006,8 +3490,13 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
3006
3490
|
*
|
|
3007
3491
|
* @example
|
|
3008
3492
|
* ```typescript
|
|
3009
|
-
* defineHook(
|
|
3010
|
-
*
|
|
3493
|
+
* defineHook({
|
|
3494
|
+
* hook: 'before_update_message',
|
|
3495
|
+
* id: 'stamp_updated_at',
|
|
3496
|
+
* execute: async (state, messageId, updates) => ({
|
|
3497
|
+
* ...updates,
|
|
3498
|
+
* updated_at: Date.now(),
|
|
3499
|
+
* }),
|
|
3011
3500
|
* });
|
|
3012
3501
|
* ```
|
|
3013
3502
|
*/
|
|
@@ -3023,8 +3512,12 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
3023
3512
|
*
|
|
3024
3513
|
* @example
|
|
3025
3514
|
* ```typescript
|
|
3026
|
-
* defineHook(
|
|
3027
|
-
*
|
|
3515
|
+
* defineHook({
|
|
3516
|
+
* hook: 'after_update_message',
|
|
3517
|
+
* id: 'log_update',
|
|
3518
|
+
* execute: async (state, message) => {
|
|
3519
|
+
* console.log(`Message updated: ${message.id}`);
|
|
3520
|
+
* },
|
|
3028
3521
|
* });
|
|
3029
3522
|
* ```
|
|
3030
3523
|
*/
|
|
@@ -3071,9 +3564,13 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
3071
3564
|
*
|
|
3072
3565
|
* @example
|
|
3073
3566
|
* ```typescript
|
|
3074
|
-
* defineHook(
|
|
3075
|
-
*
|
|
3076
|
-
*
|
|
3567
|
+
* defineHook({
|
|
3568
|
+
* hook: 'after_tool_call_success',
|
|
3569
|
+
* id: 'log_success',
|
|
3570
|
+
* execute: async (state, toolCall, toolResult) => {
|
|
3571
|
+
* console.log(`Tool ${toolCall.function.name} succeeded`);
|
|
3572
|
+
* return null; // use original result
|
|
3573
|
+
* },
|
|
3077
3574
|
* });
|
|
3078
3575
|
* ```
|
|
3079
3576
|
*/
|
|
@@ -3092,9 +3589,13 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
|
|
|
3092
3589
|
*
|
|
3093
3590
|
* @example
|
|
3094
3591
|
* ```typescript
|
|
3095
|
-
* defineHook(
|
|
3096
|
-
*
|
|
3097
|
-
*
|
|
3592
|
+
* defineHook({
|
|
3593
|
+
* hook: 'after_tool_call_failure',
|
|
3594
|
+
* id: 'log_failure',
|
|
3595
|
+
* execute: async (state, toolCall, toolResult) => {
|
|
3596
|
+
* console.error(`Tool ${toolCall.function.name} failed: ${toolResult.error}`);
|
|
3597
|
+
* return null; // use original error
|
|
3598
|
+
* },
|
|
3098
3599
|
* });
|
|
3099
3600
|
* ```
|
|
3100
3601
|
*/
|
|
@@ -3602,8 +4103,9 @@ type VirtualModuleRegistry<T> = Record<string, VirtualModuleLoader<T>>;
|
|
|
3602
4103
|
* and optionally the virtual module registries injected at runtime.
|
|
3603
4104
|
*
|
|
3604
4105
|
* Note: The `env` property contains implementation-specific bindings.
|
|
3605
|
-
*
|
|
3606
|
-
*
|
|
4106
|
+
* Its shape is defined by the runtime — typical surfaces include handles
|
|
4107
|
+
* to storage, queues, key-value stores, or other platform resources the
|
|
4108
|
+
* runtime chooses to expose.
|
|
3607
4109
|
*/
|
|
3608
4110
|
interface ControllerContext {
|
|
3609
4111
|
/** The incoming HTTP request */
|
|
@@ -3615,7 +4117,8 @@ interface ControllerContext {
|
|
|
3615
4117
|
/**
|
|
3616
4118
|
* Environment bindings (implementation-specific).
|
|
3617
4119
|
*
|
|
3618
|
-
* Contains platform-specific bindings
|
|
4120
|
+
* Contains platform-specific bindings — handles to storage,
|
|
4121
|
+
* queues, key-value stores, or other resources the runtime exposes.
|
|
3619
4122
|
* The exact contents depend on the runtime implementation.
|
|
3620
4123
|
*/
|
|
3621
4124
|
env: Record<string, unknown>;
|
|
@@ -3663,9 +4166,19 @@ type Controller = (context: ControllerContext) => ControllerReturn;
|
|
|
3663
4166
|
* Thread endpoint handler function.
|
|
3664
4167
|
*
|
|
3665
4168
|
* Receives the HTTP request and the ThreadState for the requested thread.
|
|
3666
|
-
* The
|
|
4169
|
+
* The supplied ThreadState includes the standard thread surface, including
|
|
4170
|
+
* `runCode`. The thread is automatically looked up by ID from URL parameters. Route
|
|
4171
|
+
* parameters are derived from the endpoint file path. For a dynamic segment
|
|
4172
|
+
* such as `[id].ts`, `params.id` contains the matched segment. For a catch-all
|
|
4173
|
+
* segment `[*].ts`, `params['*']` contains the unmatched path suffix,
|
|
4174
|
+
* including `/` separators when the match spans multiple segments.
|
|
4175
|
+
*
|
|
4176
|
+
* Thread endpoint routes are scoped beneath the runtime's thread ID prefix.
|
|
4177
|
+
* A request under that prefix that does not match any local or packed thread
|
|
4178
|
+
* endpoint route MUST return HTTP 404.
|
|
3667
4179
|
*/
|
|
3668
|
-
type
|
|
4180
|
+
type ThreadEndpointRouteParams = Record<string, string>;
|
|
4181
|
+
type ThreadEndpointHandler = (req: Request, state: ThreadState, params: ThreadEndpointRouteParams) => Response | Promise<Response>;
|
|
3669
4182
|
/**
|
|
3670
4183
|
* Define a standard HTTP controller.
|
|
3671
4184
|
*
|
|
@@ -3704,12 +4217,15 @@ declare function defineController(controller: Controller): Controller;
|
|
|
3704
4217
|
* ThreadState with messages, logs, resource loading, event emission,
|
|
3705
4218
|
* and (when executing) execution state.
|
|
3706
4219
|
*
|
|
3707
|
-
*
|
|
4220
|
+
* Runtimes MUST return HTTP 404 for requests beneath the thread endpoint
|
|
4221
|
+
* prefix that do not match any local or packed thread endpoint route.
|
|
4222
|
+
*
|
|
4223
|
+
* @param handler - The handler function receiving request, ThreadState, and route params
|
|
3708
4224
|
* @returns A Controller that can be used with the router
|
|
3709
4225
|
*
|
|
3710
4226
|
* @example
|
|
3711
4227
|
* ```typescript
|
|
3712
|
-
* // agents/api/
|
|
4228
|
+
* // agents/api/status.ts
|
|
3713
4229
|
* import { defineThreadEndpoint } from '@standardagents/spec';
|
|
3714
4230
|
*
|
|
3715
4231
|
* export default defineThreadEndpoint(async (req, state) => {
|
|
@@ -3724,7 +4240,7 @@ declare function defineController(controller: Controller): Controller;
|
|
|
3724
4240
|
*
|
|
3725
4241
|
* @example
|
|
3726
4242
|
* ```typescript
|
|
3727
|
-
* // agents/api/
|
|
4243
|
+
* // agents/api/export.ts
|
|
3728
4244
|
* import { defineThreadEndpoint } from '@standardagents/spec';
|
|
3729
4245
|
*
|
|
3730
4246
|
* export default defineThreadEndpoint(async (req, state) => {
|
|
@@ -3743,7 +4259,7 @@ declare function defineController(controller: Controller): Controller;
|
|
|
3743
4259
|
*
|
|
3744
4260
|
* @example
|
|
3745
4261
|
* ```typescript
|
|
3746
|
-
* // agents/api/
|
|
4262
|
+
* // agents/api/invoke.post.ts
|
|
3747
4263
|
* import { defineThreadEndpoint } from '@standardagents/spec';
|
|
3748
4264
|
*
|
|
3749
4265
|
* export default defineThreadEndpoint(async (req, state) => {
|
|
@@ -3755,6 +4271,17 @@ declare function defineController(controller: Controller): Controller;
|
|
|
3755
4271
|
* return Response.json({ queued: true });
|
|
3756
4272
|
* });
|
|
3757
4273
|
* ```
|
|
4274
|
+
*
|
|
4275
|
+
* @example
|
|
4276
|
+
* ```typescript
|
|
4277
|
+
* // agents/api/files/[id].ts
|
|
4278
|
+
* import { defineThreadEndpoint } from '@standardagents/spec';
|
|
4279
|
+
*
|
|
4280
|
+
* export default defineThreadEndpoint(async (req, state, params) => {
|
|
4281
|
+
* const file = await state.readFile(`/files/${params.id}.json`);
|
|
4282
|
+
* return Response.json({ exists: !!file });
|
|
4283
|
+
* });
|
|
4284
|
+
* ```
|
|
3758
4285
|
*/
|
|
3759
4286
|
declare function defineThreadEndpoint(handler: ThreadEndpointHandler): MarkedThreadEndpoint;
|
|
3760
4287
|
|
|
@@ -3952,8 +4479,10 @@ interface PackedExports {
|
|
|
3952
4479
|
/**
|
|
3953
4480
|
* Thread endpoint handlers, keyed by packed route key (for example, `status.get`).
|
|
3954
4481
|
*
|
|
3955
|
-
* Runtimes
|
|
3956
|
-
*
|
|
4482
|
+
* Runtimes mount these beneath the same thread ID prefix as local thread
|
|
4483
|
+
* endpoints, using the packed route key to derive the endpoint path.
|
|
4484
|
+
* Requests beneath that prefix that do not match any local or packed thread
|
|
4485
|
+
* endpoint route MUST return HTTP 404.
|
|
3957
4486
|
*
|
|
3958
4487
|
* Optional for backward compatibility with previously packed packages.
|
|
3959
4488
|
*/
|
|
@@ -3962,4 +4491,4 @@ interface PackedExports {
|
|
|
3962
4491
|
__meta: PackedMeta;
|
|
3963
4492
|
}
|
|
3964
4493
|
|
|
3965
|
-
export { type AgentDefinition, type AgentType, type AttachmentRef, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type DefineToolOptions, type DefinitionLoader, type Effect, type EffectDefinition, type EmptyUsesState, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type MarkedThreadEndpoint, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type NamespaceContext, type PackageSignature, type PackedExports, type PackedMeta, type PackedMetadata, type PackedNamespaceContext, type PromptContent, type PromptDefinition, type PromptEnvPart, 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 ProviderModelsPage, type ProviderModelsQuery, 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 QueueMessageInput, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SideConfig, type StructuredPrompt, type SubagentRegistryEntry, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type ToolVariables, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, isPacked, isThreadEndpoint, isVisibleInNamespace, mapReasoningLevel, validateToolName };
|
|
4494
|
+
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 DefineToolOptions, type DefinitionLoader, type Effect, type EffectDefinition, type EmptyUsesState, type EnvValueType, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type MarkedThreadEndpoint, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type NamespaceContext, type PackageSignature, type PackedExports, type PackedMeta, type PackedMetadata, type PackedNamespaceContext, type PromptContent, type PromptDefinition, type PromptEnvPart, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, ProviderError, type ProviderErrorCode, type ProviderExecutedToolResult, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderModelInfo, type ProviderModelsPage, type ProviderModelsQuery, 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 QueueMessageInput, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SetEnvOptions, type SideConfig, type StructuredPrompt, type SubagentRegistryEntry, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadEndpointRouteParams, 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 ToolVariables, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, isPacked, isThreadEndpoint, isVisibleInNamespace, mapReasoningLevel, validateToolName };
|