@theokit/agents 0.30.1 → 0.31.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-DVhOQc_f.d.ts → bridge-entry-DtDotZGW.d.ts} +376 -7
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +7 -1
- package/dist/{chunk-XCQNYAVU.js → chunk-BWYBOMKR.js} +477 -61
- package/dist/chunk-BWYBOMKR.js.map +1 -0
- package/dist/index.d.ts +270 -31
- package/dist/index.js +313 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XCQNYAVU.js.map +0 -1
|
@@ -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.
|
|
@@ -474,6 +572,12 @@ interface RuntimeOverrides {
|
|
|
474
572
|
recoverLeakedToolCalls?: boolean;
|
|
475
573
|
/** Per-run cwd → `Agent.create({ local: { cwd } })` → `SystemPromptContext.cwd`. */
|
|
476
574
|
cwd?: string;
|
|
575
|
+
/**
|
|
576
|
+
* M7 — per-run run-context override (`?? compiled.runContext`). Injected into every tool
|
|
577
|
+
* handler's `ctx.context` by `buildSdkTools`. Lets a single request override the agent-level
|
|
578
|
+
* `defineAgent({ context })` (mirrors `model`/`cwd`).
|
|
579
|
+
*/
|
|
580
|
+
runContext?: Record<string, unknown>;
|
|
477
581
|
/**
|
|
478
582
|
* Per-run plugins (e.g. permission gate selected by request mode). Accepts EITHER
|
|
479
583
|
* named-plugin discovery settings (`{ enabled: [...] }`) OR an array of code `Plugin`
|
|
@@ -626,15 +730,62 @@ interface DefineAgentConfig<TInput extends z.ZodType = z.ZodType> {
|
|
|
626
730
|
system?: string;
|
|
627
731
|
/** Extended-thinking effort (mirrors `@Agent({ reasoningEffort })`). */
|
|
628
732
|
reasoningEffort?: ReasoningEffort;
|
|
629
|
-
/**
|
|
630
|
-
|
|
733
|
+
/**
|
|
734
|
+
* Pre-built tools. Accepts the `@theokit/sdk` `CustomTool` that `defineAgentTool`
|
|
735
|
+
* (theokit/server) and every `@theokit/sdk-tools` factory return (issue #81) — they are
|
|
736
|
+
* normalized to the internal {@link CompiledTool} shape at compile time.
|
|
737
|
+
*/
|
|
738
|
+
tools?: readonly CustomTool[];
|
|
739
|
+
/**
|
|
740
|
+
* M7 — run-context: an opaque, per-agent object forwarded to every tool handler's
|
|
741
|
+
* `ctx.context` at run time (injected by the theokit adapter's tool wrapper). Set shared config
|
|
742
|
+
* (e.g. `{ projectRoot }`) ONCE at the agent level instead of baking it into each tool
|
|
743
|
+
* factory. Mirrors ai-sdk `experimental_context`, mastra `RuntimeContext`, and
|
|
744
|
+
* openai-agents-js `RunContext`. Distinct from `@Agent`'s context-window `context`.
|
|
745
|
+
*/
|
|
746
|
+
context?: Record<string, unknown>;
|
|
747
|
+
/**
|
|
748
|
+
* M9 — guardrails: input/output guards applied at the framework boundary (ADR-0040 § D2).
|
|
749
|
+
* Input guards run on the user message before the SDK runtime; a `block` fails the run fast.
|
|
750
|
+
* Built-ins live in `@theokit/agents` (`promptInjectionDetector`, `piiDetector`, `costGuard`,
|
|
751
|
+
* `unicodeNormalizer`, `outputModeration`).
|
|
752
|
+
*/
|
|
753
|
+
guardrails?: readonly Guardrail[];
|
|
754
|
+
/**
|
|
755
|
+
* M14 — HITL approvals keyed by tool name. Each gated tool pauses the run and emits an
|
|
756
|
+
* `approval_required` event until approved (reuses the same `compiled.hitl` wiring the `@Agent`
|
|
757
|
+
* + `@HumanInTheLoop` path produces). A key that does not match a declared tool fails fast at
|
|
758
|
+
* compile time.
|
|
759
|
+
*/
|
|
760
|
+
approvals?: Record<string, HumanInTheLoopOptions>;
|
|
761
|
+
/**
|
|
762
|
+
* M13 — skills selection: a static list (compiled straight to the SDK `skills.enabled`) OR a
|
|
763
|
+
* per-request resolver `(ctx) => string[]` (carried on `compiled.skillsResolver`, resolved by the
|
|
764
|
+
* request path against the run-context). Absent ⇒ the SDK enables every discovered skill.
|
|
765
|
+
*/
|
|
766
|
+
skills?: SkillsSelection;
|
|
631
767
|
}
|
|
632
|
-
/**
|
|
633
|
-
|
|
768
|
+
/**
|
|
769
|
+
* A branded agent definition — the value {@link defineAgent} returns.
|
|
770
|
+
*
|
|
771
|
+
* `TTools` (M8) is a phantom type parameter carrying the tool-name union: the `agent()` builder
|
|
772
|
+
* threads its accumulated literal tool names here (`.build()` returns `AgentDefinition<TInput,
|
|
773
|
+
* 'a' | 'b'>`), so the generated client (`.theokit/agents.d.ts`) can expose them via
|
|
774
|
+
* {@link InferAgentToolNames}. `defineAgent` leaves it `string` (its tools array carries no literal
|
|
775
|
+
* names). Never present at runtime.
|
|
776
|
+
*/
|
|
777
|
+
type AgentDefinition<TInput extends z.ZodType = z.ZodType, TTools extends string = string> = DefineAgentConfig<TInput> & {
|
|
634
778
|
readonly [AGENT_BRAND]: true;
|
|
779
|
+
readonly __toolNames?: TTools;
|
|
635
780
|
};
|
|
636
781
|
/** Infer the request type of an agent definition from its `input` Zod schema. */
|
|
637
782
|
type InferAgentInput<T> = T extends AgentDefinition<infer S> ? (S extends z.ZodType ? z.infer<S> : never) : never;
|
|
783
|
+
/**
|
|
784
|
+
* Infer the tool-name union of an agent definition (M8). Yields the literal union for agents built
|
|
785
|
+
* with the `agent()` builder (`'read_file' | 'count_lines'`), or `string` for `defineAgent` agents
|
|
786
|
+
* whose tools array carries no literal names.
|
|
787
|
+
*/
|
|
788
|
+
type InferAgentToolNames<T> = T extends AgentDefinition<z.ZodType, infer N> ? N : never;
|
|
638
789
|
/**
|
|
639
790
|
* Define a zero-config agent. Identity/normalizer (like `defineRoute`) — returns the config
|
|
640
791
|
* branded so the scanner recognizes it. Compilation is deferred to {@link compileAgentDefinition}.
|
|
@@ -648,6 +799,106 @@ declare function isAgentDefinition(value: unknown): value is AgentDefinition;
|
|
|
648
799
|
*/
|
|
649
800
|
declare function compileAgentDefinition(def: AgentDefinition): CompiledAgentOptions;
|
|
650
801
|
|
|
802
|
+
/**
|
|
803
|
+
* M8 — `agent()`, the fluent agent builder with accumulative **type-state**.
|
|
804
|
+
*
|
|
805
|
+
* `agent().context<C>().tool(t).model(id).system(s).build()` accumulates type parameters the way
|
|
806
|
+
* the most-loved TS DX does (tRPC `t.procedure.input().query()`, Zod, Hono) and resolves to the
|
|
807
|
+
* **SAME branded `AgentDefinition`** that {@link defineAgent} produces — one runtime, N syntaxes
|
|
808
|
+
* (ADR-B1). The value is entirely at the type level; `.build()` delegates to `defineAgent`, so
|
|
809
|
+
* convergence with the `defineAgent` / `@Agent` surfaces is by construction.
|
|
810
|
+
*
|
|
811
|
+
* Compile-time guarantees (proven by `tests/type/agent-builder.test-d.ts`):
|
|
812
|
+
* - `.build()` is a compile error when `.model()` was never called (UnsetMarker technique — tRPC
|
|
813
|
+
* `utils.ts:2-4` / `procedureBuilder.ts:362-379`).
|
|
814
|
+
* - `.tool(t)` is a compile error when the tool declares a required run-context ⊄ the agent's `C`.
|
|
815
|
+
* - tool names accumulate into a union type parameter (`TTools`).
|
|
816
|
+
*
|
|
817
|
+
* PURE metadata (sdk-runtime.md / G2): the builder describes an agent, it NEVER calls an LLM.
|
|
818
|
+
*/
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* A required-but-unset builder field. Branded (a literal intersected with a unique brand) so no
|
|
822
|
+
* ordinary value can satisfy it — the terminal-method guards below key off it. tRPC's UnsetMarker.
|
|
823
|
+
*/
|
|
824
|
+
type UnsetMarker = 'theokit.unset' & {
|
|
825
|
+
readonly __brand: 'theokit.unset';
|
|
826
|
+
};
|
|
827
|
+
/**
|
|
828
|
+
* Compile-error carriers. When a guarded method's precondition fails, its signature demands an
|
|
829
|
+
* argument of one of these types, which the caller cannot supply — the labeled tuple element
|
|
830
|
+
* surfaces the reason in the error. (Idiomatic gate for zero-arg terminal methods.)
|
|
831
|
+
*/
|
|
832
|
+
interface MissingModelError {
|
|
833
|
+
readonly __theokitError: 'call .model(id) before .build()';
|
|
834
|
+
}
|
|
835
|
+
interface ToolContextError<TRequired> {
|
|
836
|
+
readonly __theokitError: 'this tool requires a run-context not provided via .context()';
|
|
837
|
+
readonly required: TRequired;
|
|
838
|
+
}
|
|
839
|
+
/** The agent context before `.context()` is called — satisfies only tools with no requirement. */
|
|
840
|
+
type EmptyContext = Record<never, never>;
|
|
841
|
+
/**
|
|
842
|
+
* A tool that MAY declare, at the type level, the run-context shape it needs. A plain
|
|
843
|
+
* {@link CustomTool} (`TRequired = unknown`) is satisfied by any agent context. Build one that
|
|
844
|
+
* carries a literal name + optional required-context via {@link contextualTool}.
|
|
845
|
+
*/
|
|
846
|
+
interface ContextualTool<TName extends string = string, TRequired = unknown> extends CustomTool {
|
|
847
|
+
readonly name: TName;
|
|
848
|
+
/** Phantom — never present at runtime; carries the required run-context type for `.tool()`. */
|
|
849
|
+
readonly __requiredContext?: TRequired;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Tag a {@link CustomTool} with a literal name (so `.tool()` can accumulate the tool-name union)
|
|
853
|
+
* and, optionally, a required run-context type. The `requiredContext` argument is a type-only
|
|
854
|
+
* witness — pass `undefined as C` or a sample value; it is never read at runtime.
|
|
855
|
+
*/
|
|
856
|
+
declare function contextualTool<TName extends string, TRequired = unknown>(tool: CustomTool & {
|
|
857
|
+
name: TName;
|
|
858
|
+
}, _requiredContext?: TRequired): ContextualTool<TName, TRequired>;
|
|
859
|
+
/**
|
|
860
|
+
* The fluent builder. Each method returns a NEW builder type with the relevant type parameter
|
|
861
|
+
* advanced (immutable chaining). Runtime state is a plain {@link DefineAgentConfig} accumulator.
|
|
862
|
+
*/
|
|
863
|
+
interface AgentBuilder<TInput extends z.ZodType | UnsetMarker = UnsetMarker, TModel extends string | UnsetMarker = UnsetMarker, TContext = EmptyContext, TTools extends string = never> {
|
|
864
|
+
/** Set the request schema (lifted into the typed client via {@link AgentDefinition}). */
|
|
865
|
+
input<S extends z.ZodType>(schema: S): AgentBuilder<S, TModel, TContext, TTools>;
|
|
866
|
+
/**
|
|
867
|
+
* Set the model id. Required before `.build()`. COMPILE ERROR when called twice — the argument
|
|
868
|
+
* type collapses to `never` once the model is set (tRPC's set-once technique).
|
|
869
|
+
*/
|
|
870
|
+
model(id: TModel extends UnsetMarker ? string : never): AgentBuilder<TInput, string, TContext, TTools>;
|
|
871
|
+
/** Set the static system prompt. */
|
|
872
|
+
system(prompt: string): AgentBuilder<TInput, TModel, TContext, TTools>;
|
|
873
|
+
/** Set the extended-thinking effort. */
|
|
874
|
+
reasoningEffort(effort: ReasoningEffort): AgentBuilder<TInput, TModel, TContext, TTools>;
|
|
875
|
+
/** Set the run-context (M7) — the object every tool handler receives as `ctx.context`. */
|
|
876
|
+
context<C extends Record<string, unknown>>(value: C): AgentBuilder<TInput, TModel, C, TTools>;
|
|
877
|
+
/**
|
|
878
|
+
* Add a tool. Accumulates its name into `TTools`. COMPILE ERROR when the tool declares a
|
|
879
|
+
* required run-context (`ContextualTool<_, TRequired>`) that the agent's `TContext` does not
|
|
880
|
+
* satisfy — set it first with `.context()`.
|
|
881
|
+
*/
|
|
882
|
+
tool<TName extends string, TRequired>(tool: ContextualTool<TName, TRequired>, ...guard: TContext extends TRequired ? [] : [error: ToolContextError<TRequired>]): AgentBuilder<TInput, TModel, TContext, TTools | TName>;
|
|
883
|
+
/**
|
|
884
|
+
* Apply a reusable partial chain (Spring-Boot-style composition). `preset` receives the current
|
|
885
|
+
* builder and returns an advanced one; its accumulated type-state flows through.
|
|
886
|
+
*/
|
|
887
|
+
use<TResult>(preset: (builder: AgentBuilder<TInput, TModel, TContext, TTools>) => TResult): TResult;
|
|
888
|
+
/**
|
|
889
|
+
* Resolve to the branded {@link AgentDefinition} — the SAME value `defineAgent` returns.
|
|
890
|
+
* COMPILE ERROR when `.model()` was never called.
|
|
891
|
+
*/
|
|
892
|
+
build(...guard: TModel extends UnsetMarker ? [error: MissingModelError] : []): AgentDefinition<TInput extends z.ZodType ? TInput : z.ZodType, TTools>;
|
|
893
|
+
/** Phantom — lets type tests read the accumulated tool-name union. Never present at runtime. */
|
|
894
|
+
readonly __toolNames?: TTools;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Start a fluent agent definition. Chain `.model()` (required) + `.context()` / `.system()` /
|
|
898
|
+
* `.input()` / `.tool()` / `.use()`, then `.build()` to get the branded {@link AgentDefinition}.
|
|
899
|
+
*/
|
|
900
|
+
declare function agent(): AgentBuilder;
|
|
901
|
+
|
|
651
902
|
/**
|
|
652
903
|
* M4 (theokit-ai-first) — the HITL producer: a `pre_tool_call` plugin that pauses the SDK run
|
|
653
904
|
* for a human-in-the-loop tool approval.
|
|
@@ -670,7 +921,7 @@ interface HitlWiring {
|
|
|
670
921
|
/** Push the approval-required event into the agent stream (the translator emits the chunk). */
|
|
671
922
|
emit: (event: ApprovalRequiredEvent) => void;
|
|
672
923
|
/** Await the human decision for `approvalId`; resolves true=approve, false=deny (or timeout). */
|
|
673
|
-
awaitApproval: (approvalId: string, opts: HumanInTheLoopOptions) => Promise<boolean>;
|
|
924
|
+
awaitApproval: (approvalId: string, opts: HumanInTheLoopOptions, toolName: string) => Promise<boolean>;
|
|
674
925
|
}
|
|
675
926
|
|
|
676
927
|
/**
|
|
@@ -917,6 +1168,34 @@ declare const ladderReflectionStrategy: ReflectionStrategy;
|
|
|
917
1168
|
*/
|
|
918
1169
|
declare const noopReflectionStrategy: ReflectionStrategy;
|
|
919
1170
|
|
|
1171
|
+
/**
|
|
1172
|
+
* runReflectiveLoop — the multi-round reflective driver that gives `@MainLoop`
|
|
1173
|
+
* its runtime (closes the metadata-only gap, V4-A / plan ADR D2).
|
|
1174
|
+
*
|
|
1175
|
+
* Per round it consumes ONE SDK stream turn (the model call stays in the SDK —
|
|
1176
|
+
* the factory is `createSdkAgentStream(...)`, injected for testability), derives
|
|
1177
|
+
* a {@link LoopOutcome}, asks the {@link ReflectionStrategy} for feedback, then
|
|
1178
|
+
* the {@link LoopStrategy} whether to continue. Bounded by `maxIterations`
|
|
1179
|
+
* (forced terminal at the ceiling — never an infinite loop). The bridge owns the
|
|
1180
|
+
* loop; the SDK owns the model call (sdk-runtime.md / ADR 0031 — no second runtime).
|
|
1181
|
+
*
|
|
1182
|
+
* `runReflectiveLoop` is INTERNAL (not re-exported from the package barrel,
|
|
1183
|
+
* Drawback #4) — consumed by `delegate()` (T2.2) and `AgentRunner` (T3.1).
|
|
1184
|
+
*
|
|
1185
|
+
* referencia: knowledge-base/references/mastra agent.ts (re-enter the loop with feedback).
|
|
1186
|
+
*/
|
|
1187
|
+
|
|
1188
|
+
/** One SDK stream turn: `createSdkAgentStream(...)` returns this shape. */
|
|
1189
|
+
/**
|
|
1190
|
+
* Opens one round's SDK stream. `opts.disableTools` (step-cap force-close) asks the factory to
|
|
1191
|
+
* gate tools OFF for THIS round (the SDK adapter maps it to `tool_choice:"none"` at send-time, so a
|
|
1192
|
+
* cached agent — whose tools can't be un-registered — is still forced to a text summary). Optional +
|
|
1193
|
+
* ignored by injected test factories ⇒ backward-compatible.
|
|
1194
|
+
*/
|
|
1195
|
+
type RoundStreamFactory = (message: string, sessionId: string, opts?: {
|
|
1196
|
+
disableTools?: boolean;
|
|
1197
|
+
}) => AsyncIterable<StreamEvent>;
|
|
1198
|
+
|
|
920
1199
|
/**
|
|
921
1200
|
* Multi-agent orchestration runtime.
|
|
922
1201
|
*
|
|
@@ -963,6 +1242,27 @@ interface DelegateOptions {
|
|
|
963
1242
|
reflection?: ReflectionStrategy;
|
|
964
1243
|
/** Per-run loop-ceiling override (`?? SubAgent @MainLoop maxIterations`). */
|
|
965
1244
|
maxIterations?: number;
|
|
1245
|
+
/**
|
|
1246
|
+
* Called BEFORE the sub-agent runs. Returns the input the sub-agent will receive — return
|
|
1247
|
+
* `ctx.input` unchanged, or a rewritten string (e.g. inject a persona). A transform, not a veto.
|
|
1248
|
+
*/
|
|
1249
|
+
onDelegationStart?: (ctx: {
|
|
1250
|
+
subAgent: string;
|
|
1251
|
+
input: string;
|
|
1252
|
+
}) => string | Promise<string>;
|
|
1253
|
+
/**
|
|
1254
|
+
* Called AFTER the sub-agent completes. Returns the result the supervisor sees — return
|
|
1255
|
+
* `ctx.result` unchanged, or a transformed one (e.g. redact, score, re-wrap).
|
|
1256
|
+
*/
|
|
1257
|
+
onDelegationComplete?: (ctx: {
|
|
1258
|
+
subAgent: string;
|
|
1259
|
+
result: DelegationResult;
|
|
1260
|
+
}) => DelegationResult | Promise<DelegationResult>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Injected stream factory (parity with `AgentRunnerRunOptions.streamFactory`) — drives the loop
|
|
1263
|
+
* directly instead of the SDK adapter (tests / custom transport). Absent ⇒ `createSdkAgentStream`.
|
|
1264
|
+
*/
|
|
1265
|
+
streamFactory?: RoundStreamFactory;
|
|
966
1266
|
}
|
|
967
1267
|
/**
|
|
968
1268
|
* Delegate a task to a sub-agent and collect its result.
|
|
@@ -978,6 +1278,75 @@ interface DelegateOptions {
|
|
|
978
1278
|
*/
|
|
979
1279
|
declare function delegate(SubAgentClass: Function, message: string, opts?: DelegateOptions): Promise<DelegationResult>;
|
|
980
1280
|
|
|
1281
|
+
/**
|
|
1282
|
+
* M10 (theokit-ai-first) — createToolHooksPlugin: `beforeToolCall` / `afterToolCall` observability.
|
|
1283
|
+
*
|
|
1284
|
+
* ADR-0040 § D2: a HOME/BOUNDARY plugin over the SDK's OWN `pre_tool_call` / `post_tool_call`
|
|
1285
|
+
* hooks (mirrors {@link createHitlPlugin}). It calls no LLM, dispatches no tool, runs no second
|
|
1286
|
+
* loop — the SDK owns the run. `beforeToolCall` may VETO a call; `afterToolCall` observes the
|
|
1287
|
+
* result. The processor pipeline's remaining lifecycle hooks (LLM request/response) live in the
|
|
1288
|
+
* SDK; this ships the two tool-boundary hooks the framework can wire today.
|
|
1289
|
+
*/
|
|
1290
|
+
/** A tool call about to run (mirrored from the SDK `pre_tool_call` context — type-only). */
|
|
1291
|
+
interface BeforeToolCallContext {
|
|
1292
|
+
name: string;
|
|
1293
|
+
args: Record<string, unknown>;
|
|
1294
|
+
}
|
|
1295
|
+
/** A veto returned from `beforeToolCall` — blocks the tool; the SDK surfaces `message` to the model. */
|
|
1296
|
+
interface ToolCallVeto {
|
|
1297
|
+
block: true;
|
|
1298
|
+
message: string;
|
|
1299
|
+
}
|
|
1300
|
+
/** A completed tool call (mirrored from the SDK `post_tool_call` context — type-only). */
|
|
1301
|
+
interface AfterToolCallContext {
|
|
1302
|
+
name: string;
|
|
1303
|
+
result: unknown;
|
|
1304
|
+
}
|
|
1305
|
+
interface ToolHooks {
|
|
1306
|
+
/** Observe (and optionally VETO) every tool call before it runs. Return a veto or nothing. */
|
|
1307
|
+
beforeToolCall?: (ctx: BeforeToolCallContext) => ToolCallVeto | undefined | Promise<ToolCallVeto | undefined>;
|
|
1308
|
+
/** Observe every tool call's result after it runs. */
|
|
1309
|
+
afterToolCall?: (ctx: AfterToolCallContext) => void | Promise<void>;
|
|
1310
|
+
/**
|
|
1311
|
+
* M10 — observe every LLM turn BEFORE it runs (SDK `pre_llm_call`). Observability only — the
|
|
1312
|
+
* SDK's LLM-call context carries `{ agentId, runId, iteration }`, not the mutable request body.
|
|
1313
|
+
*/
|
|
1314
|
+
beforeLLMCall?: (ctx: LLMCallContext) => void | Promise<void>;
|
|
1315
|
+
/** M10 — observe every LLM turn AFTER it completes (SDK `post_llm_call`). Observability only. */
|
|
1316
|
+
afterLLMCall?: (ctx: LLMCallContext) => void | Promise<void>;
|
|
1317
|
+
}
|
|
1318
|
+
/** Context of an LLM turn (mirrors the SDK `LlmCallContext` for `pre_llm_call`/`post_llm_call`). */
|
|
1319
|
+
interface LLMCallContext {
|
|
1320
|
+
agentId: string;
|
|
1321
|
+
runId: string;
|
|
1322
|
+
/** 0-based iteration index of the current turn, when available. */
|
|
1323
|
+
iteration?: number;
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Minimal SDK hook context (type-only — no runtime import, keeps the SDK peer optional). Tool hooks
|
|
1327
|
+
* carry `name`/`args`/`result`; LLM hooks carry `iteration`. All optional so one shape covers both.
|
|
1328
|
+
*/
|
|
1329
|
+
interface ToolHookRawContext {
|
|
1330
|
+
agentId: string;
|
|
1331
|
+
runId: string;
|
|
1332
|
+
name?: string;
|
|
1333
|
+
args?: Record<string, unknown>;
|
|
1334
|
+
result?: unknown;
|
|
1335
|
+
iteration?: number;
|
|
1336
|
+
}
|
|
1337
|
+
interface ToolHooksPluginContext {
|
|
1338
|
+
on(hook: string, handler: (ctx: ToolHookRawContext) => unknown): void;
|
|
1339
|
+
}
|
|
1340
|
+
interface ToolHooksPlugin {
|
|
1341
|
+
name: string;
|
|
1342
|
+
register(ctx: ToolHooksPluginContext): void;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Build the tool-hooks plugin. Registers ONLY the hooks provided (inert when none) so it adds no
|
|
1346
|
+
* overhead unless used. The returned object is a structural `@theokit/sdk` `Plugin`.
|
|
1347
|
+
*/
|
|
1348
|
+
declare function createToolHooksPlugin(hooks: ToolHooks): ToolHooksPlugin;
|
|
1349
|
+
|
|
981
1350
|
/**
|
|
982
1351
|
* Agent manifest generator — build-time JSON describing all agents, tools, guards, policies.
|
|
983
1352
|
*
|
|
@@ -1061,4 +1430,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
1061
1430
|
register(app: PluginApp): void;
|
|
1062
1431
|
};
|
|
1063
1432
|
|
|
1064
|
-
export {
|
|
1433
|
+
export { type ReflectionResult as $, type AgentManifestEntry as A, type BeforeToolCallContext as B, type CompiledAgentOptions as C, type DelegationResult as D, type DefineAgentConfig as E, type DelegateOptions as F, type Guardrail as G, DelegationError as H, type DoneEvent as I, type ErrorEvent as J, type FileEditEvent as K, type LoopStrategy as L, type GuardrailAction as M, type GuardrailPhase as N, type GuardrailResult as O, GuardrailViolationError as P, type InferAgentInput as Q, type ReflectionStrategy as R, type StreamEvent as S, type InferAgentToolNames as T, type IterationEvent as U, type LLMCallContext as V, type LoopFinishReason as W, type LoopOutcome as X, type LoopStrategyConfig as Y, type PartialToolCallEvent as Z, type ReflectionContext as _, type CompiledTool as a, type ReflectionStrategyConfig as a0, type RunStartedEvent as a1, type SdkMessage as a2, type Segment as a3, type SkillsRequestContext as a4, type SkillsSelection as a5, type StateUpdateEvent as a6, type TextDeltaEvent as a7, type ThinkingEvent as a8, type ToolCallEvent as a9, isAgentContext as aA, isAgentDefinition as aB, isApprovalRequired as aC, isDone as aD, isError as aE, isPartialToolCall as aF, isTextDelta as aG, isToolCall as aH, isToolResult as aI, ladderReflectionStrategy as aJ, loopStrategyConfigSchema as aK, noopReflectionStrategy as aL, projectContextMetadataOnlyKnobs as aM, reflectionStrategyConfigSchema as aN, resolveEnabledSkills as aO, resolveLoopStrategy as aP, streamAgentResponse as aQ, streamAgentUIMessages as aR, translateSdkEvent as aS, translateToUIMessageStream as aT, validateUniqueRoutes as aU, walkAgentMetadata as aV, type ToolCallVeto as aa, type ToolHooks as ab, type ToolHooksPlugin as ac, type ToolResultEvent as ad, type ToolWalkResult as ae, type ToolboxWalkResult as af, agent as ag, agentsPlugin as ah, buildModelSelection as ai, compileAgent as aj, compileAgentDefinition as ak, compileAgentModule as al, compileContextWindow as am, compileProjectContext as an, compileSkills as ao, compileTools as ap, contextualTool as aq, createAgentExecutionContext as ar, createSdkAgentStream as as, createThinkTagExtractor as at, createToolHooksPlugin as au, defineAgent as av, delegate as aw, extractThinkTagStream as ax, generateAgentManifest as ay, generateAgentRoutes as az, type RoundStreamFactory as b, 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 ApprovalRequiredEvent as r, type ArtifactChunkEvent as s, type ArtifactStartEvent as t, BudgetExceededError as u, type CheckpointSavedEvent as v, type CompiledContextWindow as w, type ContextualTool as x, CostBudgetExceededError as y, DEFAULT_MAX_ITERATIONS as z };
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { c as AGENT_BRAND, d as AfterToolCallContext, e as AgentBuilder, f as AgentDefinition, g as AgentDefinitionError, h as AgentExecutionContext, i as AgentManifest, A as AgentManifestEntry, j as AgentManifestTool, k as AgentRoute, l as AgentRouteContext, m as AgentRunInfo, n as AgentStreamEvent, o as AgentWalkResult, p as AgentWarningCode, q as AgentsPluginOptions, r as ApprovalRequiredEvent, s as ArtifactChunkEvent, t as ArtifactStartEvent, B as BeforeToolCallContext, u as BudgetExceededError, v as CheckpointSavedEvent, C as CompiledAgentOptions, w as CompiledContextWindow, a as CompiledTool, x as ContextualTool, E as DefineAgentConfig, F as DelegateOptions, H as DelegationError, D as DelegationResult, I as DoneEvent, J as ErrorEvent, K as FileEditEvent, Q as InferAgentInput, T as InferAgentToolNames, U as IterationEvent, V as LLMCallContext, Z as PartialToolCallEvent, a1 as RunStartedEvent, a2 as SdkMessage, a3 as Segment, a6 as StateUpdateEvent, S as StreamEvent, a7 as TextDeltaEvent, a8 as ThinkingEvent, a9 as ToolCallEvent, aa as ToolCallVeto, ab as ToolHooks, ac as ToolHooksPlugin, ad as ToolResultEvent, ae as ToolWalkResult, af as ToolboxWalkResult, ag as agent, ah as agentsPlugin, ai as buildModelSelection, aj as compileAgent, ak as compileAgentDefinition, al as compileAgentModule, am as compileContextWindow, an as compileProjectContext, ao as compileSkills, ap as compileTools, aq as contextualTool, ar as createAgentExecutionContext, as as createSdkAgentStream, at as createThinkTagExtractor, au as createToolHooksPlugin, av as defineAgent, aw as delegate, ax as extractThinkTagStream, ay as generateAgentManifest, az as generateAgentRoutes, aA as isAgentContext, aB as isAgentDefinition, aC as isApprovalRequired, aD as isDone, aE as isError, aF as isPartialToolCall, aG as isTextDelta, aH as isToolCall, aI as isToolResult, aM as projectContextMetadataOnlyKnobs, aQ as streamAgentResponse, aR as streamAgentUIMessages, aS as translateSdkEvent, aT as translateToUIMessageStream, aU as validateUniqueRoutes, aV as walkAgentMetadata } from './bridge-entry-DtDotZGW.js';
|
|
2
2
|
import '@theokit/http';
|
|
3
3
|
import './skills-Dx_KJ6Eg.js';
|
|
4
4
|
import '@theokit/sdk';
|
package/dist/bridge.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
AgentWarningCode,
|
|
5
5
|
BudgetExceededError,
|
|
6
6
|
DelegationError,
|
|
7
|
+
agent,
|
|
7
8
|
agentsPlugin,
|
|
8
9
|
buildModelSelection,
|
|
9
10
|
compileAgent,
|
|
@@ -13,9 +14,11 @@ import {
|
|
|
13
14
|
compileProjectContext,
|
|
14
15
|
compileSkills,
|
|
15
16
|
compileTools,
|
|
17
|
+
contextualTool,
|
|
16
18
|
createAgentExecutionContext,
|
|
17
19
|
createSdkAgentStream,
|
|
18
20
|
createThinkTagExtractor,
|
|
21
|
+
createToolHooksPlugin,
|
|
19
22
|
defineAgent,
|
|
20
23
|
delegate,
|
|
21
24
|
extractThinkTagStream,
|
|
@@ -37,7 +40,7 @@ import {
|
|
|
37
40
|
translateToUIMessageStream,
|
|
38
41
|
validateUniqueRoutes,
|
|
39
42
|
walkAgentMetadata
|
|
40
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-BWYBOMKR.js";
|
|
41
44
|
import "./chunk-FI6ZG2YP.js";
|
|
42
45
|
import "./chunk-7QVYU63E.js";
|
|
43
46
|
export {
|
|
@@ -46,6 +49,7 @@ export {
|
|
|
46
49
|
AgentWarningCode,
|
|
47
50
|
BudgetExceededError,
|
|
48
51
|
DelegationError,
|
|
52
|
+
agent,
|
|
49
53
|
agentsPlugin,
|
|
50
54
|
buildModelSelection,
|
|
51
55
|
compileAgent,
|
|
@@ -55,9 +59,11 @@ export {
|
|
|
55
59
|
compileProjectContext,
|
|
56
60
|
compileSkills,
|
|
57
61
|
compileTools,
|
|
62
|
+
contextualTool,
|
|
58
63
|
createAgentExecutionContext,
|
|
59
64
|
createSdkAgentStream,
|
|
60
65
|
createThinkTagExtractor,
|
|
66
|
+
createToolHooksPlugin,
|
|
61
67
|
defineAgent,
|
|
62
68
|
delegate,
|
|
63
69
|
extractThinkTagStream,
|