@theokit/agents 14.5.0 → 15.0.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/README.md +44 -15
  3. package/dist/{agent-compiler-D7-Xd6Zh.d.ts → agent-compiler-DEMJlZNS.d.ts} +225 -6
  4. package/dist/auth.js +1 -1
  5. package/dist/{bridge-entry-kh9JllQT.d.ts → bridge-entry-qz6EGrLd.d.ts} +87 -6
  6. package/dist/bridge.d.ts +4 -5
  7. package/dist/bridge.js +5 -3
  8. package/dist/{chunk-5WS66AW7.js → chunk-3DAWVAHP.js} +7 -1
  9. package/dist/chunk-3DAWVAHP.js.map +1 -0
  10. package/dist/{chunk-D2EFYZBV.js → chunk-4ULFP7GK.js} +2 -3
  11. package/dist/chunk-4ULFP7GK.js.map +1 -0
  12. package/dist/{chunk-DLBGAMHP.js → chunk-A2FQ2C35.js} +33 -6
  13. package/dist/chunk-A2FQ2C35.js.map +1 -0
  14. package/dist/{chunk-44IHBFL6.js → chunk-FLTPPA4Y.js} +98 -33
  15. package/dist/chunk-FLTPPA4Y.js.map +1 -0
  16. package/dist/config.d.ts +57 -7
  17. package/dist/config.js +53 -7
  18. package/dist/config.js.map +1 -1
  19. package/dist/{delegation-scoring-CH9Mr9NF.d.ts → delegation-scoring-Bbr4zCpR.d.ts} +2 -2
  20. package/dist/hooks.js +1 -1
  21. package/dist/index.d.ts +21 -10
  22. package/dist/index.js +13 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/mcp-health.d.ts +1 -1
  25. package/dist/session.js +1 -1
  26. package/dist/testing.d.ts +3 -4
  27. package/dist/testing.js +1 -1
  28. package/dist/tools.d.ts +13 -7
  29. package/dist/tools.js +2 -2
  30. package/dist/tools.js.map +1 -1
  31. package/dist/{types-C16Wuh9E.d.ts → types-CxI2x6mU.d.ts} +38 -10
  32. package/package.json +2 -2
  33. package/dist/chunk-44IHBFL6.js.map +0 -1
  34. package/dist/chunk-5WS66AW7.js.map +0 -1
  35. package/dist/chunk-D2EFYZBV.js.map +0 -1
  36. package/dist/chunk-DLBGAMHP.js.map +0 -1
  37. package/dist/define-agent-y3fsG91f.d.ts +0 -188
@@ -1,188 +0,0 @@
1
- import { CustomTool, MemorySettings, TelemetrySettings } from '@theokit/sdk';
2
- import { z } from 'zod';
3
- import { G as Guardrail, S as SkillsSelection, H as HookApprovalGate, C as CodePlugin, a as CompiledAgentOptions } from './agent-compiler-D7-Xd6Zh.js';
4
- import { R as ReasoningEffort, H as HumanInTheLoopOptions, M as McpServersMap } from './types-C16Wuh9E.js';
5
- import { H as HookHandlers } from './hook-handlers-Cw2FsnE5.js';
6
- import { S as SettingSourcesSelection } from './setting-sources-gate-BJJiKq33.js';
7
-
8
- /**
9
- * M2 (theokit-ai-first) — `defineAgent`, the zero-config imperative agent surface.
10
- *
11
- * ADR-B1: `defineAgent({...})` (default-exported from a top-level `agents/<name>.ts`) is
12
- * the canonical zero-config surface; the `@Agent` class decorator stays the advanced/DI
13
- * surface. Both compile to {@link CompiledAgentOptions} and run through the same SDK
14
- * runtime (`createSdkAgentStream`) — one runtime, two syntaxes.
15
- *
16
- * This module is PURE metadata (sdk-runtime.md / G2): `defineAgent` describes an agent, it
17
- * NEVER calls an LLM. It imports only `zod` (types) + the compiler shape — no `theokit`
18
- * core, preserving the agents → (nothing) dependency direction (G1).
19
- */
20
-
21
- /**
22
- * Brand tag for a `defineAgent` value. `Symbol.for` (global registry, not `Symbol()`) so
23
- * the brand survives duplicate module instances (dual-package / bundling) — the scanner's
24
- * brand-check then works regardless of which copy created the definition.
25
- */
26
- declare const AGENT_BRAND: unique symbol;
27
- /** Config accepted by {@link defineAgent}. */
28
- interface DefineAgentConfig<TInput extends z.ZodType = z.ZodType> {
29
- /** Zod schema for the request body — lifted into the typed client (M2, {@link InferAgentInput}). */
30
- input?: TInput;
31
- /** Model id (e.g. `claude-sonnet-4-6`). Falls back to the SDK default when omitted. */
32
- model?: string;
33
- /** Static system prompt. */
34
- system?: string;
35
- /** Extended-thinking effort. */
36
- reasoningEffort?: ReasoningEffort;
37
- /**
38
- * theokit#363 — hard ceiling on the agent's tool-calling turns within ONE run. Reaching it ends
39
- * the turn instead of letting the model keep calling tools; absent ⇒ the SDK's own ceiling (8).
40
- *
41
- * Named `maxIterations`, not `maxSteps`, because the concept already has exactly one name here —
42
- * `@Agent({ maxIterations })`, `@MainLoop({ maxIterations })`, `AgentRunner.stream({ maxIterations })`,
43
- * `delegate({ maxIterations })` — and one name in the SDK it lowers to (`SendOptions.maxIterations`).
44
- * A second name would be the only place needing translation, and the translation is invisible where
45
- * it costs most: the SDK rejects an invalid value with a message naming `SendOptions.maxIterations`,
46
- * which an author who typed `.maxSteps()` has no way to connect to what they wrote. Familiarity
47
- * argues for the ai-sdk spelling, but ai-sdk's own name is `stopWhen: stepCountIs(n)` — borrowing
48
- * "steps" would buy recognition of a word, not of an API.
49
- */
50
- maxIterations?: number;
51
- /**
52
- * Pre-built tools. Accepts the `@theokit/sdk` `CustomTool` that `defineAgentTool`
53
- * (theokit/server) and every `@theokit/sdk-tools` factory return (issue #81) — they are
54
- * normalized to the internal {@link CompiledTool} shape at compile time.
55
- */
56
- tools?: readonly CustomTool[];
57
- /**
58
- * M7 — run-context: an opaque, per-agent object forwarded to every tool handler's
59
- * `ctx.context` at run time (injected by the theokit adapter's tool wrapper). Set shared config
60
- * (e.g. `{ projectRoot }`) ONCE at the agent level instead of baking it into each tool
61
- * factory. Mirrors ai-sdk `experimental_context`, mastra `RuntimeContext`, and
62
- * openai-agents-js `RunContext`. Distinct from `@Agent`'s context-window `context`.
63
- */
64
- context?: Record<string, unknown>;
65
- /**
66
- * M9 — guardrails: input/output guards applied at the framework boundary (ADR-0040 § D2).
67
- * Input guards run on the user message before the SDK runtime; a `block` fails the run fast.
68
- * Built-ins live in `@theokit/agents` (`promptInjectionDetector`, `piiDetector`, `costGuard`,
69
- * `unicodeNormalizer`, `outputModeration`).
70
- */
71
- guardrails?: readonly Guardrail[];
72
- /**
73
- * M14 — HITL approvals keyed by tool name. Each gated tool pauses the run and emits an
74
- * `approval_required` event until approved (reuses the same `compiled.hitl` wiring the `@Agent`
75
- * + `@HumanInTheLoop` path produces). A key that does not match a declared tool fails fast at
76
- * compile time.
77
- */
78
- approvals?: Record<string, HumanInTheLoopOptions>;
79
- /**
80
- * M13 — skills selection: a static list (compiled straight to the SDK `skills.enabled`) OR a
81
- * per-request resolver `(ctx) => string[]` (carried on `compiled.skillsResolver`, resolved by the
82
- * request path against the run-context). Absent ⇒ the SDK enables every discovered skill.
83
- */
84
- skills?: SkillsSelection;
85
- /**
86
- * theokit-file-based-config — opt into `.theokit/` file-based config (skills, subagents, hooks,
87
- * MCP, context, cron). The SDK discovers config from these roots under the app's `cwd`:
88
- * `project` = `<cwd>/.theokit/`, `user` = `~/.theokit/`. Absent ⇒ inline (code) config only.
89
- *
90
- * SECURITY (M68): `project` reads `.theokit/hooks.json`, which **executes shell**, so it requires
91
- * a `TrustPosture` rather than a string. This field used to take `readonly SettingSource[]`, and
92
- * its own JSDoc justified the risk as *"opt-in because `.theokit/` is the app's own repo (informed
93
- * consent)"*. That premise holds for a web app whose `cwd` is its own deploy; it does not hold for
94
- * an agent whose `cwd` is a repository the user just cloned, where `.theokit/` is
95
- * attacker-controlled content.
96
- *
97
- * `user` stays a plain boolean — `~/.theokit/` is the operator's own machine. Omitting a root is
98
- * not enabling it. The SDK owns discovery + execution (G2 / ADR-0040); theokit resolves the
99
- * selection through `resolveSettingSources` and wires the result into
100
- * `Agent.create({ local.settingSources })`.
101
- */
102
- settingSources?: SettingSourcesSelection;
103
- /**
104
- * #686 — decide whether a hook declared in a config root is spawned at all, BEFORE it runs.
105
- *
106
- * Covers any root, including a foreign dialect imported through `settingSources.claudeCode`.
107
- * Requires `@theokit/sdk >= 5.4.0`: declaring it against an older SDK is REFUSED at assembly
108
- * rather than forwarded, because a gate that silently does not gate is worse than none.
109
- */
110
- hookApproval?: HookApprovalGate;
111
- /**
112
- * B-054 — `MEMORY.md` here is NOT the Claude Code CLI's auto-memory file. This is the durable
113
- * subsystem below: a SQLite+FTS5 store under `.theokit/memory/`, with `memory_search`/`memory_get`
114
- * tools and no index cap. The CLI's lives under its own home (`CLAUDE_CONFIG_DIR` or `~/.claude`),
115
- * is capped at 200 lines / 25 KB on read, and is swept on `cleanupPeriodDays` — none of which is
116
- * implemented here. The SDK READS that directory for interop and does not write to it.
117
- *
118
- * Same filename, different directory, different semantics. Stated at both ends because a checklist
119
- * that greps for `MEMORY.md` finds one and concludes the other exists.
120
- *
121
- * M49 — durable memory (the SDK's `.theokit/memory/` subsystem: `Remember:` capture, MEMORY.md
122
- * store, auto-injected `<memory>` block, `memory_search`/`memory_get` tools). The shape is the
123
- * SDK's own `MemorySettings` — the canonical runtime contract. Projected into
124
- * `Agent.create({ memory })` by `assembleM8CreateOptions`.
125
- */
126
- memory?: MemorySettings;
127
- /**
128
- * B-072 — OpenTelemetry for this agent. Forwarded verbatim to `Agent.create({ telemetry })`,
129
- * where the SDK emits spans for `agent.send`, `llm.call`, `tool.call` and `memory.search`.
130
- *
131
- * `{ enabled: true }` is the minimal opt-in. `@opentelemetry/api` is an OPTIONAL peer of the SDK:
132
- * without it the whole thing is a silent no-op, which is the usual reason a run reports no spans.
133
- */
134
- telemetry?: TelemetrySettings;
135
- /**
136
- * Code `Plugin` objects forwarded to `Agent.create({ plugins })` — EXTENSION units (tools,
137
- * commands, model providers, memory adapters). For lifecycle interception use {@link hooks}.
138
- */
139
- /**
140
- * Code plugins — `{ name, register }`. NOT the Claude Code filesystem-bundle form, which is
141
- * declared by living in a `plugins/` directory rather than by being passed here (B-055).
142
- *
143
- * `readonly unknown[]` is what let the wrong shape through silently.
144
- */
145
- plugins?: readonly CodePlugin[];
146
- /**
147
- * Lifecycle hooks keyed by `HookName` (`pre_tool_call` may veto via `{ block, message }`). Set by
148
- * the builder's `hooks()`; converted into a code plugin at `build()` and never reaching the SDK
149
- * under this name — the plugin is the TRANSPORT, this is the contract callers write against.
150
- */
151
- hooks?: HookHandlers | Readonly<Record<string, unknown>>;
152
- /**
153
- * MCP servers available to the agent — the builder-chain equivalent of the `@MCP` class
154
- * decorator. Each key is a server name; the value is the server configuration. Forwarded
155
- * unchanged to `Agent.create({ mcpServers })` (the SDK owns MCP execution). Absent ⇒ no MCP.
156
- */
157
- mcpServers?: McpServersMap;
158
- }
159
- /**
160
- * A branded agent definition — the value {@link defineAgent} returns.
161
- *
162
- * `TTools` (M8) is a phantom type parameter carrying the tool-name union: the `AgentBuilder.create()` builder
163
- * threads its accumulated literal tool names here (`.build()` returns `AgentDefinition<TInput,
164
- * 'a' | 'b'>`), so the generated client (`.theokit/agents.d.ts`) can expose them via
165
- * {@link InferAgentToolNames}. `defineAgent` leaves it `string` (its tools array carries no literal
166
- * names). Never present at runtime.
167
- */
168
- type AgentDefinition<TInput extends z.ZodType = z.ZodType, TTools extends string = string> = DefineAgentConfig<TInput> & {
169
- readonly [AGENT_BRAND]: true;
170
- readonly __toolNames?: TTools;
171
- };
172
- /** Infer the request type of an agent definition from its `input` Zod schema. */
173
- type InferAgentInput<T> = T extends AgentDefinition<infer S> ? (S extends z.ZodType ? z.infer<S> : never) : never;
174
- /**
175
- * Infer the tool-name union of an agent definition (M8). Yields the literal union for agents built
176
- * with the `AgentBuilder.create()` builder (`'read_file' | 'count_lines'`), or `string` for `defineAgent` agents
177
- * whose tools array carries no literal names.
178
- */
179
- type InferAgentToolNames<T> = T extends AgentDefinition<z.ZodType, infer N> ? N : never;
180
- /** Brand-check: is `value` a {@link defineAgent} result? */
181
- declare function isAgentDefinition(value: unknown): value is AgentDefinition;
182
- /**
183
- * Lower a definition to the SDK-ready {@link CompiledAgentOptions} — the same shape
184
- * `compileAgent` (decorator path) produces, so both surfaces converge on one runtime.
185
- */
186
- declare function compileAgentDefinition(def: AgentDefinition): CompiledAgentOptions;
187
-
188
- export { type AgentDefinition as A, type DefineAgentConfig as D, type InferAgentInput as I, AGENT_BRAND as a, type InferAgentToolNames as b, compileAgentDefinition as c, isAgentDefinition as i };