@theokit/agents 0.30.2 → 0.32.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/{bridge-entry-DzSZRp22.d.ts → bridge-entry-1r1DL-mS.d.ts} +578 -7
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +22 -2
- package/dist/{chunk-FI6ZG2YP.js → chunk-3AX6M5TF.js} +1 -1
- package/dist/chunk-3AX6M5TF.js.map +1 -0
- package/dist/{chunk-QJKU2YMC.js → chunk-5VIRIPVV.js} +656 -65
- package/dist/chunk-5VIRIPVV.js.map +1 -0
- package/dist/{chunk-K4MCMREI.js → chunk-AAG26UJ7.js} +2 -2
- package/dist/decorators.d.ts +2 -2
- package/dist/decorators.js +2 -2
- package/dist/index.d.ts +272 -33
- package/dist/index.js +329 -5
- package/dist/index.js.map +1 -1
- package/dist/{skills-Dx_KJ6Eg.d.ts → skills-DvI_LYWZ.d.ts} +6 -0
- package/package.json +11 -11
- package/LICENSE +0 -201
- package/dist/chunk-FI6ZG2YP.js.map +0 -1
- package/dist/chunk-QJKU2YMC.js.map +0 -1
- /package/dist/{chunk-K4MCMREI.js.map → chunk-AAG26UJ7.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExecutionContext } from '@theokit/http';
|
|
2
|
-
import { A as AgentOptions, D as ToolOptions, m as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, l as HumanInTheLoopOptions, k as GatewayOptions, r as MemoryOptions, z as SkillsOptions, j as ContextWindowOptions, w as ProjectContextOptions, p as McpServersMap, g as CompactionDecoratorConfig, b as CheckpointOptions, R as ReasoningEffort } from './skills-
|
|
2
|
+
import { A as AgentOptions, D as ToolOptions, m as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, l as HumanInTheLoopOptions, k as GatewayOptions, r as MemoryOptions, z as SkillsOptions, j as ContextWindowOptions, w as ProjectContextOptions, p as McpServersMap, g as CompactionDecoratorConfig, b as CheckpointOptions, R as ReasoningEffort } from './skills-DvI_LYWZ.js';
|
|
3
3
|
import { SystemPromptResolver, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition as AgentDefinition$1, BudgetTracker, ConversationStorageAdapter, CustomTool, ModelSelection } from '@theokit/sdk';
|
|
4
4
|
import { UIMessageChunk } from 'ai';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -102,6 +102,75 @@ declare function walkAgentMetadata(AgentClass: Function, toolboxClasses?: Functi
|
|
|
102
102
|
*/
|
|
103
103
|
declare function validateUniqueRoutes(results: AgentWalkResult[]): void;
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* M9 (theokit-ai-first) — guardrail contract + typed errors.
|
|
107
|
+
*
|
|
108
|
+
* ADR-0040 § D2: guardrails are a HOME/BOUNDARY concern (filter user input before the SDK,
|
|
109
|
+
* filter model output before the client). They REUSE the SDK runtime — this module makes zero
|
|
110
|
+
* LLM calls. A guard reports one of three actions; the pipeline (`pipeline.ts`) enforces them.
|
|
111
|
+
*/
|
|
112
|
+
/** What a guard decided for a piece of text. */
|
|
113
|
+
type GuardrailAction = 'allow' | 'block' | 'redact';
|
|
114
|
+
/**
|
|
115
|
+
* The result of a single guard check.
|
|
116
|
+
* - `allow` — text passes untouched.
|
|
117
|
+
* - `block` — the pipeline throws {@link GuardrailViolationError}; the run stops fail-fast.
|
|
118
|
+
* - `redact` — the pipeline replaces the text with {@link GuardrailResult.text} and continues.
|
|
119
|
+
*/
|
|
120
|
+
interface GuardrailResult {
|
|
121
|
+
action: GuardrailAction;
|
|
122
|
+
/** Human-readable reason — required in spirit for `block`, surfaced in the thrown error. */
|
|
123
|
+
reason?: string;
|
|
124
|
+
/** The transformed text — present (and used) only when `action === 'redact'`. */
|
|
125
|
+
text?: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A guardrail. A guard MAY inspect input (before the model), output (after the model), or both.
|
|
129
|
+
* A guard that omits a phase hook is skipped for that phase.
|
|
130
|
+
*/
|
|
131
|
+
interface Guardrail {
|
|
132
|
+
readonly name: string;
|
|
133
|
+
checkInput?(text: string): GuardrailResult | Promise<GuardrailResult>;
|
|
134
|
+
checkOutput?(text: string): GuardrailResult | Promise<GuardrailResult>;
|
|
135
|
+
}
|
|
136
|
+
/** Which boundary phase a violation happened in. */
|
|
137
|
+
type GuardrailPhase = 'input' | 'output';
|
|
138
|
+
/** Thrown (fail-fast) when a guard returns `action: 'block'`. Typed per error-handling.md. */
|
|
139
|
+
declare class GuardrailViolationError extends Error {
|
|
140
|
+
readonly guardName: string;
|
|
141
|
+
readonly phase: GuardrailPhase;
|
|
142
|
+
readonly reason: string;
|
|
143
|
+
constructor(guardName: string, phase: GuardrailPhase, reason: string);
|
|
144
|
+
}
|
|
145
|
+
/** Thrown when {@link costGuard}'s cumulative token budget is exceeded. */
|
|
146
|
+
declare class CostBudgetExceededError extends Error {
|
|
147
|
+
readonly usedTokens: number;
|
|
148
|
+
readonly maxTokens: number;
|
|
149
|
+
constructor(usedTokens: number, maxTokens: number);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* M13 (theokit-ai-first) — per-request skills resolution (ADR-0040 § D2, home/boundary concern).
|
|
154
|
+
*
|
|
155
|
+
* The static `skills.enabled` filter already works (`compile-skills` maps `include` → the SDK's
|
|
156
|
+
* `enabled`). This adds a PER-REQUEST resolver so multi-tenant apps expose different skill sets to
|
|
157
|
+
* different users. A selection is either a static list or a function of the request context (the M7
|
|
158
|
+
* run-context). Discovery + injection stay in the SDK; this only CHOOSES the enabled set per call.
|
|
159
|
+
*/
|
|
160
|
+
/** The request context handed to a skills resolver (the M7 run-context — opaque per-request data). */
|
|
161
|
+
type SkillsRequestContext = Record<string, unknown>;
|
|
162
|
+
/**
|
|
163
|
+
* How the enabled skill set is chosen:
|
|
164
|
+
* - `string[]` — a static list (same shape `skills.enabled` accepts today).
|
|
165
|
+
* - a function — resolved per request from the {@link SkillsRequestContext} (sync or async).
|
|
166
|
+
*/
|
|
167
|
+
type SkillsSelection = readonly string[] | ((ctx: SkillsRequestContext) => readonly string[] | Promise<readonly string[]>);
|
|
168
|
+
/**
|
|
169
|
+
* Resolve the enabled skill names for a request. Returns `undefined` when no selection is given (the
|
|
170
|
+
* SDK then enables every discovered skill). Fails fast if a resolver returns a non-array.
|
|
171
|
+
*/
|
|
172
|
+
declare function resolveEnabledSkills(selection: SkillsSelection | undefined, ctx: SkillsRequestContext): Promise<string[] | undefined>;
|
|
173
|
+
|
|
105
174
|
/**
|
|
106
175
|
* Agent compiler — transforms decorator metadata into SDK calls.
|
|
107
176
|
*
|
|
@@ -116,7 +185,17 @@ interface CompiledTool {
|
|
|
116
185
|
name: string;
|
|
117
186
|
description: string;
|
|
118
187
|
inputSchema: unknown;
|
|
119
|
-
|
|
188
|
+
/**
|
|
189
|
+
* M7 — the optional 2nd `ctx` arg carries the SDK run context: `ctx.context` is the
|
|
190
|
+
* `defineAgent({ context })` / per-run value, `ctx.signal` the abort signal. Optional so the
|
|
191
|
+
* decorator `@Tool` handlers (which ignore it) stay assignable. The SDK calls the tool with
|
|
192
|
+
* both args; a handler that needs run-context (e.g. a filesystem tool reading `projectRoot`)
|
|
193
|
+
* reads `ctx?.context`.
|
|
194
|
+
*/
|
|
195
|
+
handler: (input: unknown, ctx?: {
|
|
196
|
+
signal?: AbortSignal;
|
|
197
|
+
context?: unknown;
|
|
198
|
+
}) => string | Promise<string>;
|
|
120
199
|
}
|
|
121
200
|
/**
|
|
122
201
|
* Compile @Tool metadata into tool definitions.
|
|
@@ -155,6 +234,13 @@ interface CompiledAgentOptions {
|
|
|
155
234
|
memory?: MemoryOptions;
|
|
156
235
|
skills?: SkillsSettings;
|
|
157
236
|
context?: ContextSettings;
|
|
237
|
+
/**
|
|
238
|
+
* M7 — run-context injected into every tool handler's `ctx.context` by the theokit adapter
|
|
239
|
+
* (`buildSdkTools` wrapper). Populated by `defineAgent({ context })` (functional surface).
|
|
240
|
+
* NAME NOTE: distinct from the context-window `context` (`ContextSettings`) above — this is
|
|
241
|
+
* per-run user data for tools, not token-budget config.
|
|
242
|
+
*/
|
|
243
|
+
runContext?: Record<string, unknown>;
|
|
158
244
|
/** Raw @ProjectContext config; the adapter builds the (async) systemPrompt resolver from it. */
|
|
159
245
|
projectContext?: ProjectContextOptions;
|
|
160
246
|
mcpServers?: McpServersMap;
|
|
@@ -171,6 +257,18 @@ interface CompiledAgentOptions {
|
|
|
171
257
|
* durable SDK conversation storage (`storage: 'filesystem'`) so a same-`sessionId` request resumes.
|
|
172
258
|
*/
|
|
173
259
|
checkpoint?: CheckpointOptions;
|
|
260
|
+
/**
|
|
261
|
+
* M9 — guardrails: input/output guards applied at the framework boundary (ADR-0040 § D2).
|
|
262
|
+
* Input guards run on the user message BEFORE the SDK runtime sees it (fail-fast on `block`).
|
|
263
|
+
* They REUSE the runtime; they never reimplement it. Absent/empty ⇒ no guards.
|
|
264
|
+
*/
|
|
265
|
+
guardrails?: readonly Guardrail[];
|
|
266
|
+
/**
|
|
267
|
+
* M13 — per-request skills resolver (from `defineAgent({ skills: (ctx) => [...] })`). The request
|
|
268
|
+
* path resolves it against the run-context (`resolveEnabledSkills`) and sets `skills.enabled`
|
|
269
|
+
* before the SDK runs. Not consumed by the SDK directly (it reads `skills`). Absent ⇒ no resolver.
|
|
270
|
+
*/
|
|
271
|
+
skillsResolver?: SkillsSelection;
|
|
174
272
|
}
|
|
175
273
|
/**
|
|
176
274
|
* Compile @Agent metadata into SDK-compatible options.
|
|
@@ -322,6 +420,8 @@ interface ApprovalRequiredEvent {
|
|
|
322
420
|
input?: unknown;
|
|
323
421
|
callbackUrl: string;
|
|
324
422
|
timeoutMs: number;
|
|
423
|
+
/** M20 — JSON-schema descriptor of the custom payload the approver may attach (optional). */
|
|
424
|
+
payloadSchema?: Record<string, unknown>;
|
|
325
425
|
}
|
|
326
426
|
/** Agent encountered an error. */
|
|
327
427
|
interface ErrorEvent {
|
|
@@ -474,6 +574,12 @@ interface RuntimeOverrides {
|
|
|
474
574
|
recoverLeakedToolCalls?: boolean;
|
|
475
575
|
/** Per-run cwd → `Agent.create({ local: { cwd } })` → `SystemPromptContext.cwd`. */
|
|
476
576
|
cwd?: string;
|
|
577
|
+
/**
|
|
578
|
+
* M7 — per-run run-context override (`?? compiled.runContext`). Injected into every tool
|
|
579
|
+
* handler's `ctx.context` by `buildSdkTools`. Lets a single request override the agent-level
|
|
580
|
+
* `defineAgent({ context })` (mirrors `model`/`cwd`).
|
|
581
|
+
*/
|
|
582
|
+
runContext?: Record<string, unknown>;
|
|
477
583
|
/**
|
|
478
584
|
* Per-run plugins (e.g. permission gate selected by request mode). Accepts EITHER
|
|
479
585
|
* named-plugin discovery settings (`{ enabled: [...] }`) OR an array of code `Plugin`
|
|
@@ -632,13 +738,56 @@ interface DefineAgentConfig<TInput extends z.ZodType = z.ZodType> {
|
|
|
632
738
|
* normalized to the internal {@link CompiledTool} shape at compile time.
|
|
633
739
|
*/
|
|
634
740
|
tools?: readonly CustomTool[];
|
|
741
|
+
/**
|
|
742
|
+
* M7 — run-context: an opaque, per-agent object forwarded to every tool handler's
|
|
743
|
+
* `ctx.context` at run time (injected by the theokit adapter's tool wrapper). Set shared config
|
|
744
|
+
* (e.g. `{ projectRoot }`) ONCE at the agent level instead of baking it into each tool
|
|
745
|
+
* factory. Mirrors ai-sdk `experimental_context`, mastra `RuntimeContext`, and
|
|
746
|
+
* openai-agents-js `RunContext`. Distinct from `@Agent`'s context-window `context`.
|
|
747
|
+
*/
|
|
748
|
+
context?: Record<string, unknown>;
|
|
749
|
+
/**
|
|
750
|
+
* M9 — guardrails: input/output guards applied at the framework boundary (ADR-0040 § D2).
|
|
751
|
+
* Input guards run on the user message before the SDK runtime; a `block` fails the run fast.
|
|
752
|
+
* Built-ins live in `@theokit/agents` (`promptInjectionDetector`, `piiDetector`, `costGuard`,
|
|
753
|
+
* `unicodeNormalizer`, `outputModeration`).
|
|
754
|
+
*/
|
|
755
|
+
guardrails?: readonly Guardrail[];
|
|
756
|
+
/**
|
|
757
|
+
* M14 — HITL approvals keyed by tool name. Each gated tool pauses the run and emits an
|
|
758
|
+
* `approval_required` event until approved (reuses the same `compiled.hitl` wiring the `@Agent`
|
|
759
|
+
* + `@HumanInTheLoop` path produces). A key that does not match a declared tool fails fast at
|
|
760
|
+
* compile time.
|
|
761
|
+
*/
|
|
762
|
+
approvals?: Record<string, HumanInTheLoopOptions>;
|
|
763
|
+
/**
|
|
764
|
+
* M13 — skills selection: a static list (compiled straight to the SDK `skills.enabled`) OR a
|
|
765
|
+
* per-request resolver `(ctx) => string[]` (carried on `compiled.skillsResolver`, resolved by the
|
|
766
|
+
* request path against the run-context). Absent ⇒ the SDK enables every discovered skill.
|
|
767
|
+
*/
|
|
768
|
+
skills?: SkillsSelection;
|
|
635
769
|
}
|
|
636
|
-
/**
|
|
637
|
-
|
|
770
|
+
/**
|
|
771
|
+
* A branded agent definition — the value {@link defineAgent} returns.
|
|
772
|
+
*
|
|
773
|
+
* `TTools` (M8) is a phantom type parameter carrying the tool-name union: the `agent()` builder
|
|
774
|
+
* threads its accumulated literal tool names here (`.build()` returns `AgentDefinition<TInput,
|
|
775
|
+
* 'a' | 'b'>`), so the generated client (`.theokit/agents.d.ts`) can expose them via
|
|
776
|
+
* {@link InferAgentToolNames}. `defineAgent` leaves it `string` (its tools array carries no literal
|
|
777
|
+
* names). Never present at runtime.
|
|
778
|
+
*/
|
|
779
|
+
type AgentDefinition<TInput extends z.ZodType = z.ZodType, TTools extends string = string> = DefineAgentConfig<TInput> & {
|
|
638
780
|
readonly [AGENT_BRAND]: true;
|
|
781
|
+
readonly __toolNames?: TTools;
|
|
639
782
|
};
|
|
640
783
|
/** Infer the request type of an agent definition from its `input` Zod schema. */
|
|
641
784
|
type InferAgentInput<T> = T extends AgentDefinition<infer S> ? (S extends z.ZodType ? z.infer<S> : never) : never;
|
|
785
|
+
/**
|
|
786
|
+
* Infer the tool-name union of an agent definition (M8). Yields the literal union for agents built
|
|
787
|
+
* with the `agent()` builder (`'read_file' | 'count_lines'`), or `string` for `defineAgent` agents
|
|
788
|
+
* whose tools array carries no literal names.
|
|
789
|
+
*/
|
|
790
|
+
type InferAgentToolNames<T> = T extends AgentDefinition<z.ZodType, infer N> ? N : never;
|
|
642
791
|
/**
|
|
643
792
|
* Define a zero-config agent. Identity/normalizer (like `defineRoute`) — returns the config
|
|
644
793
|
* branded so the scanner recognizes it. Compilation is deferred to {@link compileAgentDefinition}.
|
|
@@ -652,6 +801,106 @@ declare function isAgentDefinition(value: unknown): value is AgentDefinition;
|
|
|
652
801
|
*/
|
|
653
802
|
declare function compileAgentDefinition(def: AgentDefinition): CompiledAgentOptions;
|
|
654
803
|
|
|
804
|
+
/**
|
|
805
|
+
* M8 — `agent()`, the fluent agent builder with accumulative **type-state**.
|
|
806
|
+
*
|
|
807
|
+
* `agent().context<C>().tool(t).model(id).system(s).build()` accumulates type parameters the way
|
|
808
|
+
* the most-loved TS DX does (tRPC `t.procedure.input().query()`, Zod, Hono) and resolves to the
|
|
809
|
+
* **SAME branded `AgentDefinition`** that {@link defineAgent} produces — one runtime, N syntaxes
|
|
810
|
+
* (ADR-B1). The value is entirely at the type level; `.build()` delegates to `defineAgent`, so
|
|
811
|
+
* convergence with the `defineAgent` / `@Agent` surfaces is by construction.
|
|
812
|
+
*
|
|
813
|
+
* Compile-time guarantees (proven by `tests/type/agent-builder.test-d.ts`):
|
|
814
|
+
* - `.build()` is a compile error when `.model()` was never called (UnsetMarker technique — tRPC
|
|
815
|
+
* `utils.ts:2-4` / `procedureBuilder.ts:362-379`).
|
|
816
|
+
* - `.tool(t)` is a compile error when the tool declares a required run-context ⊄ the agent's `C`.
|
|
817
|
+
* - tool names accumulate into a union type parameter (`TTools`).
|
|
818
|
+
*
|
|
819
|
+
* PURE metadata (sdk-runtime.md / G2): the builder describes an agent, it NEVER calls an LLM.
|
|
820
|
+
*/
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* A required-but-unset builder field. Branded (a literal intersected with a unique brand) so no
|
|
824
|
+
* ordinary value can satisfy it — the terminal-method guards below key off it. tRPC's UnsetMarker.
|
|
825
|
+
*/
|
|
826
|
+
type UnsetMarker = 'theokit.unset' & {
|
|
827
|
+
readonly __brand: 'theokit.unset';
|
|
828
|
+
};
|
|
829
|
+
/**
|
|
830
|
+
* Compile-error carriers. When a guarded method's precondition fails, its signature demands an
|
|
831
|
+
* argument of one of these types, which the caller cannot supply — the labeled tuple element
|
|
832
|
+
* surfaces the reason in the error. (Idiomatic gate for zero-arg terminal methods.)
|
|
833
|
+
*/
|
|
834
|
+
interface MissingModelError {
|
|
835
|
+
readonly __theokitError: 'call .model(id) before .build()';
|
|
836
|
+
}
|
|
837
|
+
interface ToolContextError<TRequired> {
|
|
838
|
+
readonly __theokitError: 'this tool requires a run-context not provided via .context()';
|
|
839
|
+
readonly required: TRequired;
|
|
840
|
+
}
|
|
841
|
+
/** The agent context before `.context()` is called — satisfies only tools with no requirement. */
|
|
842
|
+
type EmptyContext = Record<never, never>;
|
|
843
|
+
/**
|
|
844
|
+
* A tool that MAY declare, at the type level, the run-context shape it needs. A plain
|
|
845
|
+
* {@link CustomTool} (`TRequired = unknown`) is satisfied by any agent context. Build one that
|
|
846
|
+
* carries a literal name + optional required-context via {@link contextualTool}.
|
|
847
|
+
*/
|
|
848
|
+
interface ContextualTool<TName extends string = string, TRequired = unknown> extends CustomTool {
|
|
849
|
+
readonly name: TName;
|
|
850
|
+
/** Phantom — never present at runtime; carries the required run-context type for `.tool()`. */
|
|
851
|
+
readonly __requiredContext?: TRequired;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Tag a {@link CustomTool} with a literal name (so `.tool()` can accumulate the tool-name union)
|
|
855
|
+
* and, optionally, a required run-context type. The `requiredContext` argument is a type-only
|
|
856
|
+
* witness — pass `undefined as C` or a sample value; it is never read at runtime.
|
|
857
|
+
*/
|
|
858
|
+
declare function contextualTool<TName extends string, TRequired = unknown>(tool: CustomTool & {
|
|
859
|
+
name: TName;
|
|
860
|
+
}, _requiredContext?: TRequired): ContextualTool<TName, TRequired>;
|
|
861
|
+
/**
|
|
862
|
+
* The fluent builder. Each method returns a NEW builder type with the relevant type parameter
|
|
863
|
+
* advanced (immutable chaining). Runtime state is a plain {@link DefineAgentConfig} accumulator.
|
|
864
|
+
*/
|
|
865
|
+
interface AgentBuilder<TInput extends z.ZodType | UnsetMarker = UnsetMarker, TModel extends string | UnsetMarker = UnsetMarker, TContext = EmptyContext, TTools extends string = never> {
|
|
866
|
+
/** Set the request schema (lifted into the typed client via {@link AgentDefinition}). */
|
|
867
|
+
input<S extends z.ZodType>(schema: S): AgentBuilder<S, TModel, TContext, TTools>;
|
|
868
|
+
/**
|
|
869
|
+
* Set the model id. Required before `.build()`. COMPILE ERROR when called twice — the argument
|
|
870
|
+
* type collapses to `never` once the model is set (tRPC's set-once technique).
|
|
871
|
+
*/
|
|
872
|
+
model(id: TModel extends UnsetMarker ? string : never): AgentBuilder<TInput, string, TContext, TTools>;
|
|
873
|
+
/** Set the static system prompt. */
|
|
874
|
+
system(prompt: string): AgentBuilder<TInput, TModel, TContext, TTools>;
|
|
875
|
+
/** Set the extended-thinking effort. */
|
|
876
|
+
reasoningEffort(effort: ReasoningEffort): AgentBuilder<TInput, TModel, TContext, TTools>;
|
|
877
|
+
/** Set the run-context (M7) — the object every tool handler receives as `ctx.context`. */
|
|
878
|
+
context<C extends Record<string, unknown>>(value: C): AgentBuilder<TInput, TModel, C, TTools>;
|
|
879
|
+
/**
|
|
880
|
+
* Add a tool. Accumulates its name into `TTools`. COMPILE ERROR when the tool declares a
|
|
881
|
+
* required run-context (`ContextualTool<_, TRequired>`) that the agent's `TContext` does not
|
|
882
|
+
* satisfy — set it first with `.context()`.
|
|
883
|
+
*/
|
|
884
|
+
tool<TName extends string, TRequired>(tool: ContextualTool<TName, TRequired>, ...guard: TContext extends TRequired ? [] : [error: ToolContextError<TRequired>]): AgentBuilder<TInput, TModel, TContext, TTools | TName>;
|
|
885
|
+
/**
|
|
886
|
+
* Apply a reusable partial chain (Spring-Boot-style composition). `preset` receives the current
|
|
887
|
+
* builder and returns an advanced one; its accumulated type-state flows through.
|
|
888
|
+
*/
|
|
889
|
+
use<TResult>(preset: (builder: AgentBuilder<TInput, TModel, TContext, TTools>) => TResult): TResult;
|
|
890
|
+
/**
|
|
891
|
+
* Resolve to the branded {@link AgentDefinition} — the SAME value `defineAgent` returns.
|
|
892
|
+
* COMPILE ERROR when `.model()` was never called.
|
|
893
|
+
*/
|
|
894
|
+
build(...guard: TModel extends UnsetMarker ? [error: MissingModelError] : []): AgentDefinition<TInput extends z.ZodType ? TInput : z.ZodType, TTools>;
|
|
895
|
+
/** Phantom — lets type tests read the accumulated tool-name union. Never present at runtime. */
|
|
896
|
+
readonly __toolNames?: TTools;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Start a fluent agent definition. Chain `.model()` (required) + `.context()` / `.system()` /
|
|
900
|
+
* `.input()` / `.tool()` / `.use()`, then `.build()` to get the branded {@link AgentDefinition}.
|
|
901
|
+
*/
|
|
902
|
+
declare function agent(): AgentBuilder;
|
|
903
|
+
|
|
655
904
|
/**
|
|
656
905
|
* M4 (theokit-ai-first) — the HITL producer: a `pre_tool_call` plugin that pauses the SDK run
|
|
657
906
|
* for a human-in-the-loop tool approval.
|
|
@@ -667,14 +916,27 @@ declare function compileAgentDefinition(def: AgentDefinition): CompiledAgentOpti
|
|
|
667
916
|
* surfaces as a tool result the model self-corrects on).
|
|
668
917
|
*/
|
|
669
918
|
|
|
919
|
+
/**
|
|
920
|
+
* M20 — a settled HITL decision. Structural mirror of the harness's `ApprovalDecision` (the agents
|
|
921
|
+
* package must not import from `theokit` — dependency direction). `awaitApproval` may resolve a bare
|
|
922
|
+
* boolean (legacy) OR this object; the plugin normalizes both.
|
|
923
|
+
*/
|
|
924
|
+
interface HitlDecision {
|
|
925
|
+
approved: boolean;
|
|
926
|
+
reason?: string;
|
|
927
|
+
payload?: unknown;
|
|
928
|
+
}
|
|
670
929
|
/** Injected wiring — the harness (mount-agent) supplies these; the plugin stays pure. */
|
|
671
930
|
interface HitlWiring {
|
|
672
931
|
/** Tool name → its `@HumanInTheLoop` config. A tool absent here is NOT gated. */
|
|
673
932
|
gated: Map<string, HumanInTheLoopOptions>;
|
|
674
933
|
/** Push the approval-required event into the agent stream (the translator emits the chunk). */
|
|
675
934
|
emit: (event: ApprovalRequiredEvent) => void;
|
|
676
|
-
/**
|
|
677
|
-
|
|
935
|
+
/**
|
|
936
|
+
* Await the human decision for `approvalId`; resolves approve/deny (or timeout). M20 — may resolve
|
|
937
|
+
* a bare boolean (legacy) OR a {@link HitlDecision} carrying an approver `reason` + `payload`.
|
|
938
|
+
*/
|
|
939
|
+
awaitApproval: (approvalId: string, opts: HumanInTheLoopOptions, toolName: string) => Promise<boolean | HitlDecision>;
|
|
678
940
|
}
|
|
679
941
|
|
|
680
942
|
/**
|
|
@@ -921,6 +1183,34 @@ declare const ladderReflectionStrategy: ReflectionStrategy;
|
|
|
921
1183
|
*/
|
|
922
1184
|
declare const noopReflectionStrategy: ReflectionStrategy;
|
|
923
1185
|
|
|
1186
|
+
/**
|
|
1187
|
+
* runReflectiveLoop — the multi-round reflective driver that gives `@MainLoop`
|
|
1188
|
+
* its runtime (closes the metadata-only gap, V4-A / plan ADR D2).
|
|
1189
|
+
*
|
|
1190
|
+
* Per round it consumes ONE SDK stream turn (the model call stays in the SDK —
|
|
1191
|
+
* the factory is `createSdkAgentStream(...)`, injected for testability), derives
|
|
1192
|
+
* a {@link LoopOutcome}, asks the {@link ReflectionStrategy} for feedback, then
|
|
1193
|
+
* the {@link LoopStrategy} whether to continue. Bounded by `maxIterations`
|
|
1194
|
+
* (forced terminal at the ceiling — never an infinite loop). The bridge owns the
|
|
1195
|
+
* loop; the SDK owns the model call (sdk-runtime.md / ADR 0031 — no second runtime).
|
|
1196
|
+
*
|
|
1197
|
+
* `runReflectiveLoop` is INTERNAL (not re-exported from the package barrel,
|
|
1198
|
+
* Drawback #4) — consumed by `delegate()` (T2.2) and `AgentRunner` (T3.1).
|
|
1199
|
+
*
|
|
1200
|
+
* referencia: knowledge-base/references/mastra agent.ts (re-enter the loop with feedback).
|
|
1201
|
+
*/
|
|
1202
|
+
|
|
1203
|
+
/** One SDK stream turn: `createSdkAgentStream(...)` returns this shape. */
|
|
1204
|
+
/**
|
|
1205
|
+
* Opens one round's SDK stream. `opts.disableTools` (step-cap force-close) asks the factory to
|
|
1206
|
+
* gate tools OFF for THIS round (the SDK adapter maps it to `tool_choice:"none"` at send-time, so a
|
|
1207
|
+
* cached agent — whose tools can't be un-registered — is still forced to a text summary). Optional +
|
|
1208
|
+
* ignored by injected test factories ⇒ backward-compatible.
|
|
1209
|
+
*/
|
|
1210
|
+
type RoundStreamFactory = (message: string, sessionId: string, opts?: {
|
|
1211
|
+
disableTools?: boolean;
|
|
1212
|
+
}) => AsyncIterable<StreamEvent>;
|
|
1213
|
+
|
|
924
1214
|
/**
|
|
925
1215
|
* Multi-agent orchestration runtime.
|
|
926
1216
|
*
|
|
@@ -967,6 +1257,27 @@ interface DelegateOptions {
|
|
|
967
1257
|
reflection?: ReflectionStrategy;
|
|
968
1258
|
/** Per-run loop-ceiling override (`?? SubAgent @MainLoop maxIterations`). */
|
|
969
1259
|
maxIterations?: number;
|
|
1260
|
+
/**
|
|
1261
|
+
* Called BEFORE the sub-agent runs. Returns the input the sub-agent will receive — return
|
|
1262
|
+
* `ctx.input` unchanged, or a rewritten string (e.g. inject a persona). A transform, not a veto.
|
|
1263
|
+
*/
|
|
1264
|
+
onDelegationStart?: (ctx: {
|
|
1265
|
+
subAgent: string;
|
|
1266
|
+
input: string;
|
|
1267
|
+
}) => string | Promise<string>;
|
|
1268
|
+
/**
|
|
1269
|
+
* Called AFTER the sub-agent completes. Returns the result the supervisor sees — return
|
|
1270
|
+
* `ctx.result` unchanged, or a transformed one (e.g. redact, score, re-wrap).
|
|
1271
|
+
*/
|
|
1272
|
+
onDelegationComplete?: (ctx: {
|
|
1273
|
+
subAgent: string;
|
|
1274
|
+
result: DelegationResult;
|
|
1275
|
+
}) => DelegationResult | Promise<DelegationResult>;
|
|
1276
|
+
/**
|
|
1277
|
+
* Injected stream factory (parity with `AgentRunnerRunOptions.streamFactory`) — drives the loop
|
|
1278
|
+
* directly instead of the SDK adapter (tests / custom transport). Absent ⇒ `createSdkAgentStream`.
|
|
1279
|
+
*/
|
|
1280
|
+
streamFactory?: RoundStreamFactory;
|
|
970
1281
|
}
|
|
971
1282
|
/**
|
|
972
1283
|
* Delegate a task to a sub-agent and collect its result.
|
|
@@ -982,6 +1293,266 @@ interface DelegateOptions {
|
|
|
982
1293
|
*/
|
|
983
1294
|
declare function delegate(SubAgentClass: Function, message: string, opts?: DelegateOptions): Promise<DelegationResult>;
|
|
984
1295
|
|
|
1296
|
+
/**
|
|
1297
|
+
* M10 (theokit-ai-first) — createToolHooksPlugin: `beforeToolCall` / `afterToolCall` observability.
|
|
1298
|
+
*
|
|
1299
|
+
* ADR-0040 § D2: a HOME/BOUNDARY plugin over the SDK's OWN `pre_tool_call` / `post_tool_call` /
|
|
1300
|
+
* `pre_llm_call` / `post_llm_call` / `pre_user_send` hooks (mirrors {@link createHitlPlugin}). It
|
|
1301
|
+
* calls no LLM, dispatches no tool, runs no second loop — the SDK owns the run. `beforeToolCall`
|
|
1302
|
+
* may VETO a call; `afterToolCall` observes the result.
|
|
1303
|
+
*
|
|
1304
|
+
* M19 — `processInput` completes the input side of the processor pipeline, wired to the SDK
|
|
1305
|
+
* `pre_user_send` hook. NOTE (honest ceiling): the SDK does NOT let a plugin mutate the raw
|
|
1306
|
+
* prompt/stream; `pre_user_send` lets a handler INJECT derived context (`recalledContext`) BEFORE
|
|
1307
|
+
* the model. So `processInput` receives the prompt and returns an optional string, which the SDK
|
|
1308
|
+
* injects as a `<memory-context>` block ahead of the prompt. The api-error side of M19 lives in
|
|
1309
|
+
* `./api-error-handler` (a sibling factory — the SDK owns retry and exposes no error hook).
|
|
1310
|
+
*/
|
|
1311
|
+
/** A tool call about to run (mirrored from the SDK `pre_tool_call` context — type-only). */
|
|
1312
|
+
interface BeforeToolCallContext {
|
|
1313
|
+
name: string;
|
|
1314
|
+
args: Record<string, unknown>;
|
|
1315
|
+
}
|
|
1316
|
+
/** A veto returned from `beforeToolCall` — blocks the tool; the SDK surfaces `message` to the model. */
|
|
1317
|
+
interface ToolCallVeto {
|
|
1318
|
+
block: true;
|
|
1319
|
+
message: string;
|
|
1320
|
+
}
|
|
1321
|
+
/** A completed tool call (mirrored from the SDK `post_tool_call` context — type-only). */
|
|
1322
|
+
interface AfterToolCallContext {
|
|
1323
|
+
name: string;
|
|
1324
|
+
result: unknown;
|
|
1325
|
+
}
|
|
1326
|
+
interface ToolHooks {
|
|
1327
|
+
/** Observe (and optionally VETO) every tool call before it runs. Return a veto or nothing. */
|
|
1328
|
+
beforeToolCall?: (ctx: BeforeToolCallContext) => ToolCallVeto | undefined | Promise<ToolCallVeto | undefined>;
|
|
1329
|
+
/** Observe every tool call's result after it runs. */
|
|
1330
|
+
afterToolCall?: (ctx: AfterToolCallContext) => void | Promise<void>;
|
|
1331
|
+
/**
|
|
1332
|
+
* M10 — observe every LLM turn BEFORE it runs (SDK `pre_llm_call`). Observability only — the
|
|
1333
|
+
* SDK's LLM-call context carries `{ agentId, runId, iteration }`, not the mutable request body.
|
|
1334
|
+
*/
|
|
1335
|
+
beforeLLMCall?: (ctx: LLMCallContext) => void | Promise<void>;
|
|
1336
|
+
/** M10 — observe every LLM turn AFTER it completes (SDK `post_llm_call`). Observability only. */
|
|
1337
|
+
afterLLMCall?: (ctx: LLMCallContext) => void | Promise<void>;
|
|
1338
|
+
/**
|
|
1339
|
+
* M19 — pre-process the user input BEFORE the model runs (SDK `pre_user_send`). Receives the
|
|
1340
|
+
* prompt; return a string to INJECT as derived context ahead of it (the SDK wraps it in a
|
|
1341
|
+
* `<memory-context>` block), or `undefined` to inject nothing. The SDK does not expose raw-prompt
|
|
1342
|
+
* mutation to plugins, so this is additive, not a rewrite of the caller's stream.
|
|
1343
|
+
*/
|
|
1344
|
+
processInput?: (ctx: ProcessInputContext) => string | undefined | Promise<string | undefined>;
|
|
1345
|
+
}
|
|
1346
|
+
/** Context of the input seam (mirrors the SDK `PreUserSendContext`). */
|
|
1347
|
+
interface ProcessInputContext {
|
|
1348
|
+
prompt: string;
|
|
1349
|
+
agentId: string;
|
|
1350
|
+
runId: string;
|
|
1351
|
+
}
|
|
1352
|
+
/** Context of an LLM turn (mirrors the SDK `LlmCallContext` for `pre_llm_call`/`post_llm_call`). */
|
|
1353
|
+
interface LLMCallContext {
|
|
1354
|
+
agentId: string;
|
|
1355
|
+
runId: string;
|
|
1356
|
+
/** 0-based iteration index of the current turn, when available. */
|
|
1357
|
+
iteration?: number;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Minimal SDK hook context (type-only — no runtime import, keeps the SDK peer optional). Tool hooks
|
|
1361
|
+
* carry `name`/`args`/`result`; LLM hooks carry `iteration`. All optional so one shape covers both.
|
|
1362
|
+
*/
|
|
1363
|
+
interface ToolHookRawContext {
|
|
1364
|
+
agentId: string;
|
|
1365
|
+
runId: string;
|
|
1366
|
+
name?: string;
|
|
1367
|
+
args?: Record<string, unknown>;
|
|
1368
|
+
result?: unknown;
|
|
1369
|
+
iteration?: number;
|
|
1370
|
+
/** M19 — the user prompt, present on the `pre_user_send` seam. */
|
|
1371
|
+
prompt?: string;
|
|
1372
|
+
}
|
|
1373
|
+
interface ToolHooksPluginContext {
|
|
1374
|
+
on(hook: string, handler: (ctx: ToolHookRawContext) => unknown): void;
|
|
1375
|
+
}
|
|
1376
|
+
interface ToolHooksPlugin {
|
|
1377
|
+
name: string;
|
|
1378
|
+
/** SDK `BasePlugin.version` — required by the `@theokit/sdk` Plugin contract. */
|
|
1379
|
+
version: string;
|
|
1380
|
+
/**
|
|
1381
|
+
* SDK Plugin discriminator. MUST be `'general'` — the SDK's `isCodePlugin()` gate filters out any
|
|
1382
|
+
* plugin object lacking `kind: 'general'` (a `register()`-only object is silently dropped and its
|
|
1383
|
+
* hooks NEVER fire). Regression guard for the M10/M19 latent E2E bug.
|
|
1384
|
+
*/
|
|
1385
|
+
kind: 'general';
|
|
1386
|
+
register(ctx: ToolHooksPluginContext): void;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Build the tool-hooks plugin. Registers ONLY the hooks provided (inert when none) so it adds no
|
|
1390
|
+
* overhead unless used. The returned object is a structural `@theokit/sdk` `Plugin`.
|
|
1391
|
+
*/
|
|
1392
|
+
declare function createToolHooksPlugin(hooks: ToolHooks): ToolHooksPlugin;
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* M19 (theokit-ai-first) — `processApiError`: app-level fallback around an agent run.
|
|
1396
|
+
*
|
|
1397
|
+
* ADR-0040 § D2 + sdk-runtime.md: the `@theokit/sdk` runtime OWNS the LLM call AND its own
|
|
1398
|
+
* retry/backoff, and exposes NO api-error hook to plugins. This module is therefore NOT a plugin —
|
|
1399
|
+
* it is a thin app-boundary wrapper (the M19 DoD explicitly allows "a sibling factory"). It
|
|
1400
|
+
* RE-INVOKES the caller's run thunk on error; it never calls an LLM, never dispatches a tool, never
|
|
1401
|
+
* reimplements retry inside the loop (G2). The SDK's internal retry runs first; this handles what
|
|
1402
|
+
* survives it — a second, app-owned fallback layer (the M19 top-risk note: "app-level fallback, not
|
|
1403
|
+
* a second retry loop" inside the SDK).
|
|
1404
|
+
*/
|
|
1405
|
+
/** What the app decides after seeing an API error. */
|
|
1406
|
+
interface ApiErrorDecision<R = unknown> {
|
|
1407
|
+
/** Re-invoke the run thunk once more. Ignored past `maxAttempts`. */
|
|
1408
|
+
retry?: boolean;
|
|
1409
|
+
/**
|
|
1410
|
+
* A value to return INSTEAD of rethrowing, when `retry` is false/absent. Lets the app degrade
|
|
1411
|
+
* gracefully (e.g. a canned response) rather than surface the raw provider error.
|
|
1412
|
+
*/
|
|
1413
|
+
fallback?: R;
|
|
1414
|
+
}
|
|
1415
|
+
/** Context handed to the app's error handler for each failed attempt (1-based). */
|
|
1416
|
+
interface ApiErrorContext {
|
|
1417
|
+
error: unknown;
|
|
1418
|
+
/** 1-based attempt number that just failed. */
|
|
1419
|
+
attempt: number;
|
|
1420
|
+
}
|
|
1421
|
+
interface ApiErrorPolicy<R = unknown> {
|
|
1422
|
+
/** Called once per failed attempt. Return `{ retry: true }` to try again, or a `{ fallback }`. */
|
|
1423
|
+
processApiError: (ctx: ApiErrorContext) => ApiErrorDecision<R> | Promise<ApiErrorDecision<R>>;
|
|
1424
|
+
/**
|
|
1425
|
+
* Hard cap on total attempts (defaults to 3). A backstop so a handler that always returns
|
|
1426
|
+
* `{ retry: true }` cannot loop forever (mirrors the SDK's own bounded retry philosophy).
|
|
1427
|
+
*/
|
|
1428
|
+
maxAttempts?: number;
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Run `thunk`, applying the app's `processApiError` policy on failure. Returns the run's value on
|
|
1432
|
+
* success, the policy's `fallback` when it declines to retry with one, or rethrows the last error.
|
|
1433
|
+
*
|
|
1434
|
+
* `thunk` is typically `() => agent.send(msg).then((r) => r.wait())` — a whole SDK run. On retry the
|
|
1435
|
+
* thunk is re-invoked from scratch (a fresh run), never resumed mid-loop.
|
|
1436
|
+
*/
|
|
1437
|
+
declare function runWithApiErrorHandling<R>(thunk: () => Promise<R>, policy: ApiErrorPolicy<R>): Promise<R>;
|
|
1438
|
+
/**
|
|
1439
|
+
* Build a reusable guard bound to one policy. `const guard = createApiErrorHandler({ ... })` then
|
|
1440
|
+
* `guard(() => agent.send(m).then((r) => r.wait()))` — the same policy applied to many runs.
|
|
1441
|
+
*/
|
|
1442
|
+
declare function createApiErrorHandler<R = unknown>(policy: ApiErrorPolicy<R>): (thunk: () => Promise<R>) => Promise<R>;
|
|
1443
|
+
|
|
1444
|
+
/**
|
|
1445
|
+
* M25 (theokit-ai-first) — background delegation + task-completion scoring.
|
|
1446
|
+
*
|
|
1447
|
+
* Two THIN wrappers over the M12 `delegate` (ADR 0038/0040): no new orchestration engine, no second
|
|
1448
|
+
* loop, no new store. `delegateBackground` kicks off a sub-agent without blocking the supervisor and
|
|
1449
|
+
* hands back a handle to await later. `delegateWithScoring` runs `delegate`, scores the result with
|
|
1450
|
+
* an injected scorer, and re-delegates with the scorer's feedback until it passes or `maxRounds` is
|
|
1451
|
+
* hit. The `delegate` implementation is injectable (`delegateFn`) so this is testable without a
|
|
1452
|
+
* SubAgent class or an LLM — and so it NEVER re-implements the delegation runtime.
|
|
1453
|
+
*/
|
|
1454
|
+
|
|
1455
|
+
/** The delegation primitive both wrappers drive. Defaults to the M12 {@link delegate}. */
|
|
1456
|
+
type DelegateFn = (subAgent: Function, message: string, opts?: DelegateOptions) => Promise<DelegationResult>;
|
|
1457
|
+
/** A running background delegation the supervisor can await/poll later. */
|
|
1458
|
+
interface BackgroundDelegation {
|
|
1459
|
+
/** Await the sub-agent's result (or rejection). Idempotent — returns the same settled promise. */
|
|
1460
|
+
wait(): Promise<DelegationResult>;
|
|
1461
|
+
/** Whether the underlying delegation has resolved or rejected. */
|
|
1462
|
+
settled(): boolean;
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Start a sub-agent WITHOUT blocking the supervisor. Returns immediately with a handle; the
|
|
1466
|
+
* supervisor keeps working and calls `wait()` when it needs the result. A thin async wrapper over
|
|
1467
|
+
* `delegate` — not a scheduler (Top-risk 1). Rejections are still observable via `wait()`.
|
|
1468
|
+
*/
|
|
1469
|
+
declare function delegateBackground(subAgent: Function, message: string, opts?: DelegateOptions & {
|
|
1470
|
+
delegateFn?: DelegateFn;
|
|
1471
|
+
}): BackgroundDelegation;
|
|
1472
|
+
/** A scorer's verdict on a sub-agent result. `feedback` is fed back into the next round on failure. */
|
|
1473
|
+
interface ScoreVerdict {
|
|
1474
|
+
pass: boolean;
|
|
1475
|
+
/** Optional numeric score (0..1) for logging/telemetry. */
|
|
1476
|
+
score?: number;
|
|
1477
|
+
/** Guidance appended to the next delegation when `pass` is false. */
|
|
1478
|
+
feedback?: string;
|
|
1479
|
+
}
|
|
1480
|
+
/** Scores a sub-agent result. Opt-in (Top-risk 2) — the caller supplies it, and pays its cost. */
|
|
1481
|
+
type Scorer = (result: DelegationResult) => ScoreVerdict | Promise<ScoreVerdict>;
|
|
1482
|
+
/** The outcome of a scored delegation: the final result plus the per-round verdict trail. */
|
|
1483
|
+
interface ScoredDelegation {
|
|
1484
|
+
result: DelegationResult;
|
|
1485
|
+
/** Rounds actually run (1..maxRounds). */
|
|
1486
|
+
rounds: number;
|
|
1487
|
+
/** Whether the final round passed the scorer. */
|
|
1488
|
+
passed: boolean;
|
|
1489
|
+
/** The verdict from each round, in order. */
|
|
1490
|
+
verdicts: ScoreVerdict[];
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Run `delegate`, score the result, and re-delegate with the scorer's feedback until it passes or
|
|
1494
|
+
* `maxRounds` is reached. Each round is ONE `delegate` call — no second loop, no new store. Returns
|
|
1495
|
+
* the final result (passing, or the last attempt) with the per-round verdict trail.
|
|
1496
|
+
*/
|
|
1497
|
+
declare function delegateWithScoring(subAgent: Function, message: string, opts: DelegateOptions & {
|
|
1498
|
+
scorer: Scorer;
|
|
1499
|
+
maxRounds?: number;
|
|
1500
|
+
delegateFn?: DelegateFn;
|
|
1501
|
+
feedbackTemplate?: (message: string, feedback: string) => string;
|
|
1502
|
+
}): Promise<ScoredDelegation>;
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* M24 (ADR-0041) — MCP follow-ups, framework-side layer over the `@MCP` config (ADR-0040 § D2).
|
|
1506
|
+
*
|
|
1507
|
+
* Three home/boundary helpers that compose with the existing `@MCP` / `defineAgent` surfaces — the
|
|
1508
|
+
* SDK still owns MCP server EXECUTION (`Agent.create({ mcpServers })`); these only shape the config:
|
|
1509
|
+
* - `resolveMcpServers` — per-request resolver so multi-tenant apps hand different MCP creds to
|
|
1510
|
+
* different callers (mirrors the M13 skills resolver);
|
|
1511
|
+
* - `mcpRegistry` — build a server config for a known MCP registry (Composio / mcp.run);
|
|
1512
|
+
* - `mcpToolApprovals` — mark MCP tools for approval, producing the M14 `approvals` entries so a
|
|
1513
|
+
* gated MCP tool routes through the (E2E-proven) HITL flow.
|
|
1514
|
+
*/
|
|
1515
|
+
|
|
1516
|
+
/** The request context handed to an MCP resolver (the M7 run-context — opaque per-request data). */
|
|
1517
|
+
type McpRequestContext = Record<string, unknown>;
|
|
1518
|
+
/**
|
|
1519
|
+
* How the MCP server set is chosen:
|
|
1520
|
+
* - a map — static `@MCP`-style config.
|
|
1521
|
+
* - a function — resolved per request from the {@link McpRequestContext} (sync or async).
|
|
1522
|
+
*/
|
|
1523
|
+
type McpSelection = McpServersMap | ((ctx: McpRequestContext) => McpServersMap | Promise<McpServersMap>);
|
|
1524
|
+
/**
|
|
1525
|
+
* Resolve the MCP servers for a request. Returns `undefined` when no selection is given. Fails fast
|
|
1526
|
+
* if a resolver returns a non-object (error-handling.md). Multi-tenant apps pass a function that
|
|
1527
|
+
* reads per-user credentials from `ctx`.
|
|
1528
|
+
*/
|
|
1529
|
+
declare function resolveMcpServers(selection: McpSelection | undefined, ctx: McpRequestContext): Promise<McpServersMap | undefined>;
|
|
1530
|
+
/** Config for {@link mcpRegistry}. `registry` selects a known provider. */
|
|
1531
|
+
interface McpRegistryConfig {
|
|
1532
|
+
registry: 'composio' | 'mcp.run';
|
|
1533
|
+
/** The registry API key (kept in the server's env, never logged). */
|
|
1534
|
+
apiKey: string;
|
|
1535
|
+
/** Composio: the app toolkits to expose (e.g. `['github', 'slack']`). */
|
|
1536
|
+
apps?: string[];
|
|
1537
|
+
/** mcp.run: the profile to connect. */
|
|
1538
|
+
profile?: string;
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Build an {@link McpServersMap} for a known MCP registry. Emits an `npx`-launched server config with
|
|
1542
|
+
* the API key in `env`. Documented registries: **Composio** (`@composio/mcp`) and **mcp.run**
|
|
1543
|
+
* (`@mcp.run/cli`). Other registries are wired manually via a raw `@MCP` entry.
|
|
1544
|
+
*/
|
|
1545
|
+
declare function mcpRegistry(config: McpRegistryConfig): McpServersMap;
|
|
1546
|
+
/** An MCP tool's approval spec: full {@link HumanInTheLoopOptions} or a bare question string. */
|
|
1547
|
+
type McpApprovalSpec = HumanInTheLoopOptions | string;
|
|
1548
|
+
/**
|
|
1549
|
+
* Mark MCP tools for human approval (`requireToolApproval`). Returns the `Record<toolName,
|
|
1550
|
+
* HumanInTheLoopOptions>` shape the M14 `defineAgent({ approvals })` map consumes — so a gated MCP
|
|
1551
|
+
* tool routes through the same (E2E-proven) HITL flow as a native gated tool. A bare string is
|
|
1552
|
+
* shorthand for `{ question }`.
|
|
1553
|
+
*/
|
|
1554
|
+
declare function mcpToolApprovals(specs: Record<string, McpApprovalSpec>): Record<string, HumanInTheLoopOptions>;
|
|
1555
|
+
|
|
985
1556
|
/**
|
|
986
1557
|
* Agent manifest generator — build-time JSON describing all agents, tools, guards, policies.
|
|
987
1558
|
*
|
|
@@ -1065,4 +1636,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
1065
1636
|
register(app: PluginApp): void;
|
|
1066
1637
|
};
|
|
1067
1638
|
|
|
1068
|
-
export {
|
|
1639
|
+
export { type LoopFinishReason as $, type AgentManifestEntry as A, type BackgroundDelegation as B, type CompiledAgentOptions as C, type DelegationResult as D, type CompiledContextWindow as E, type ContextualTool as F, type Guardrail as G, CostBudgetExceededError as H, DEFAULT_MAX_ITERATIONS as I, type DefineAgentConfig as J, type DelegateFn as K, type LoopStrategy as L, type DelegateOptions as M, DelegationError as N, type DoneEvent as O, type ErrorEvent as P, type FileEditEvent as Q, type ReflectionStrategy as R, type StreamEvent as S, type GuardrailAction as T, type GuardrailPhase as U, type GuardrailResult as V, GuardrailViolationError as W, type InferAgentInput as X, type InferAgentToolNames as Y, type IterationEvent as Z, type LLMCallContext as _, type CompiledTool as a, mcpRegistry as a$, type LoopOutcome as a0, type LoopStrategyConfig as a1, type McpApprovalSpec as a2, type McpRegistryConfig as a3, type McpRequestContext as a4, type McpSelection as a5, type PartialToolCallEvent as a6, type ProcessInputContext as a7, type ReflectionContext as a8, type ReflectionResult as a9, compileProjectContext as aA, compileSkills as aB, compileTools as aC, contextualTool as aD, createAgentExecutionContext as aE, createApiErrorHandler as aF, createSdkAgentStream as aG, createThinkTagExtractor as aH, createToolHooksPlugin as aI, defineAgent as aJ, delegate as aK, delegateBackground as aL, delegateWithScoring as aM, extractThinkTagStream as aN, generateAgentManifest as aO, generateAgentRoutes as aP, isAgentContext as aQ, isAgentDefinition as aR, isApprovalRequired as aS, isDone as aT, isError as aU, isPartialToolCall as aV, isTextDelta as aW, isToolCall as aX, isToolResult as aY, ladderReflectionStrategy as aZ, loopStrategyConfigSchema as a_, type ReflectionStrategyConfig as aa, type RunStartedEvent as ab, type ScoreVerdict as ac, type ScoredDelegation as ad, type Scorer as ae, type SdkMessage as af, type Segment as ag, type SkillsRequestContext as ah, type SkillsSelection as ai, type StateUpdateEvent as aj, type TextDeltaEvent as ak, type ThinkingEvent as al, type ToolCallEvent as am, type ToolCallVeto as an, type ToolHooks as ao, type ToolHooksPlugin as ap, type ToolResultEvent as aq, type ToolWalkResult as ar, type ToolboxWalkResult as as, agent as at, agentsPlugin as au, buildModelSelection as av, compileAgent as aw, compileAgentDefinition as ax, compileAgentModule as ay, compileContextWindow as az, type RoundStreamFactory as b, mcpToolApprovals as b0, noopReflectionStrategy as b1, projectContextMetadataOnlyKnobs as b2, reflectionStrategyConfigSchema as b3, resolveEnabledSkills as b4, resolveLoopStrategy as b5, resolveMcpServers as b6, runWithApiErrorHandling as b7, streamAgentResponse as b8, streamAgentUIMessages as b9, translateSdkEvent as ba, translateToUIMessageStream as bb, validateUniqueRoutes as bc, walkAgentMetadata as bd, AGENT_BRAND as c, type AfterToolCallContext as d, type AgentBuilder as e, type AgentDefinition as f, AgentDefinitionError as g, type AgentExecutionContext as h, type AgentManifest as i, type AgentManifestTool as j, type AgentRoute as k, type AgentRouteContext as l, type AgentRunInfo as m, type AgentStreamEvent as n, type AgentWalkResult as o, AgentWarningCode as p, type AgentsPluginOptions as q, type ApiErrorContext as r, type ApiErrorDecision as s, type ApiErrorPolicy as t, type ApprovalRequiredEvent as u, type ArtifactChunkEvent as v, type ArtifactStartEvent as w, type BeforeToolCallContext as x, BudgetExceededError as y, type CheckpointSavedEvent as z };
|