@theokit/sdk 2.19.0 → 2.21.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 (89) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/dist/a2a/index.cjs +611 -274
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +612 -275
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/a2a/types.d.cts +7 -0
  7. package/dist/a2a/types.d.ts +7 -0
  8. package/dist/agent-builder.d.ts +2 -1
  9. package/dist/agent-generate.d.ts +12 -0
  10. package/dist/client/index.cjs.map +1 -1
  11. package/dist/client/index.d.cts +5 -0
  12. package/dist/client/index.d.ts +5 -0
  13. package/dist/client/index.js.map +1 -1
  14. package/dist/client/theokit-client.d.cts +6 -0
  15. package/dist/client/theokit-client.d.ts +6 -0
  16. package/dist/client/types.d.cts +2 -0
  17. package/dist/client/types.d.ts +2 -0
  18. package/dist/create-skill.d.ts +29 -0
  19. package/dist/{cron-D_wK1S-0.d.cts → cron-YrmsszEN.d.cts} +110 -3
  20. package/dist/{cron-Cep07kTz.d.ts → cron-dpvtRoro.d.ts} +110 -3
  21. package/dist/cron.cjs +660 -370
  22. package/dist/cron.cjs.map +1 -1
  23. package/dist/cron.d.cts +3 -2
  24. package/dist/cron.d.ts +3 -2
  25. package/dist/cron.js +661 -371
  26. package/dist/cron.js.map +1 -1
  27. package/dist/{errors-5lj1EWgs.d.ts → errors-C4vZPqXf.d.ts} +2 -2
  28. package/dist/{errors-CE-lMBi2.d.cts → errors-DrcpYVfZ.d.cts} +2 -2
  29. package/dist/errors.d.cts +3 -2
  30. package/dist/eval.cjs +660 -370
  31. package/dist/eval.cjs.map +1 -1
  32. package/dist/eval.js +660 -370
  33. package/dist/eval.js.map +1 -1
  34. package/dist/generate-object.d.ts +19 -4
  35. package/dist/index.cjs +867 -371
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +274 -16
  38. package/dist/index.d.ts +274 -16
  39. package/dist/index.js +863 -373
  40. package/dist/index.js.map +1 -1
  41. package/dist/internal/agent-loop/loop-types.d.ts +2 -0
  42. package/dist/internal/agent-loop/tool-result-guard.d.ts +1 -0
  43. package/dist/internal/llm/tool-result-content.d.ts +40 -0
  44. package/dist/internal/llm/types.d.ts +6 -1
  45. package/dist/internal/persistence/conversation-storage-fs.d.cts +3 -1
  46. package/dist/internal/persistence/conversation-storage-fs.d.ts +3 -1
  47. package/dist/internal/persistence/conversation-storage-memory.d.cts +3 -1
  48. package/dist/internal/persistence/conversation-storage-memory.d.ts +3 -1
  49. package/dist/internal/persistence/session-meta.d.cts +13 -0
  50. package/dist/internal/persistence/session-meta.d.ts +13 -0
  51. package/dist/internal/runtime/model-selection.d.ts +14 -0
  52. package/dist/internal/structured-output-helpers.d.ts +1 -1
  53. package/dist/permission-engine.d.ts +32 -1
  54. package/dist/{run-BgfBWX-z.d.cts → run-BMo8yRwK.d.cts} +262 -19
  55. package/dist/{run-BgfBWX-z.d.ts → run-BMo8yRwK.d.ts} +262 -19
  56. package/dist/stream-object.d.ts +2 -1
  57. package/dist/tool-error.d.ts +30 -0
  58. package/dist/types/agent-prims.d.ts +10 -8
  59. package/dist/types/agent.d.ts +22 -1
  60. package/dist/types/content-blocks.d.ts +47 -0
  61. package/dist/types/conversation-storage.d.ts +38 -0
  62. package/dist/types/index.d.ts +1 -0
  63. package/dist/types/messages.d.ts +2 -9
  64. package/dist/types/run-events.d.ts +84 -0
  65. package/dist/types/run.d.ts +115 -1
  66. package/dist/types/session.d.ts +99 -0
  67. package/dist/types/workflow.d.ts +7 -0
  68. package/dist/workflow.cjs +7 -2
  69. package/dist/workflow.cjs.map +1 -1
  70. package/dist/workflow.d.cts +2 -0
  71. package/dist/workflow.d.ts +2 -0
  72. package/dist/workflow.js +7 -2
  73. package/dist/workflow.js.map +1 -1
  74. package/package.json +3 -23
  75. package/dist/internal/observability/context.d.cts +0 -23
  76. package/dist/internal/observability/context.d.ts +0 -23
  77. package/dist/internal/observability/index.cjs +0 -38
  78. package/dist/internal/observability/index.cjs.map +0 -1
  79. package/dist/internal/observability/index.d.cts +0 -8
  80. package/dist/internal/observability/index.d.ts +0 -8
  81. package/dist/internal/observability/index.js +0 -33
  82. package/dist/internal/observability/index.js.map +0 -1
  83. package/dist/internal/plugins/index.cjs +0 -363
  84. package/dist/internal/plugins/index.cjs.map +0 -1
  85. package/dist/internal/plugins/index.js +0 -357
  86. package/dist/internal/plugins/index.js.map +0 -1
  87. package/dist/internal/workflow/index.d.ts +0 -12
  88. package/dist/server/adapter/index.d.cts +0 -8
  89. package/dist/server/adapter/index.d.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,128 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 707d1e3: **SE1 — Permission model: `PermissionMode` + an enriched `canUseTool` gate.**
8
+
9
+ The existing `PermissionEngine` (rules + arg-matching + fail-closed `ask` default, #55) gains a per-run **`PermissionMode`** (`"default" | "plan" | "acceptEdits" | "bypass"`) — a pure post-processor of the rule verdict (no tool metadata needed, fits bring-your-own-tools):
10
+
11
+ - `default` — rules decide; unmatched ⇒ `ask` (fail-closed).
12
+ - `plan` — read-only: `allow` rules pass, everything else ⇒ `deny`.
13
+ - `acceptEdits` — auto-approve the UNMATCHED verdict but still honor an explicit `ask` rule (Codex `UnlessTrusted`).
14
+ - `bypass` — everything ⇒ `allow` EXCEPT an explicit `deny` rule (OpenCode `dangerously-skip-permissions` / Codex `Never`).
15
+
16
+ **Invariant (both OpenCode + Codex):** an explicit `deny` is immune to every auto-approve mode. `bypass`/`acceptEdits` never un-deny.
17
+
18
+ `createPermissionPlugin` gains `mode` + an enriched async **`canUseTool(toolName, input, ctx)`** gate (the Anthropic-parity shape) that resolves the `ask` verdict to allow/deny — fail-closed on absent/throwing gate. The old `onAsk(toolName)` is kept as a `@deprecated` back-compat fallback.
19
+
20
+ New exports: `PermissionMode`, `applyMode`, `PermissionGate`, `PermissionGateContext`, `PermissionGateDecision`. Additive + backward-compatible (`evaluate` mode defaults to `default`; `onAsk` still works). `updatedInput` (arg rewrite) is intentionally deferred — the `pre_tool_call` seam is veto-only today.
21
+
22
+ Grounded in a deep OpenCode + Codex permission-model comparison (SDK Evolution roadmap SE1).
23
+
24
+ - f9001bb: **SE2 — typed runtime event stream (opt-in `SendOptions.onRunEvent`).**
25
+
26
+ New public `RunEvent` discriminated union + an opt-in `onRunEvent` sink, ADDITIVE to the `SDKMessage` content stream (non-breaking). Runtime-observability signals are delivered out-of-band — the model's content is unaffected. Mirrors the Anthropic `SDKMessage`-union approach.
27
+
28
+ - `RunEvent` union (the forward-compatible contract): `tool_progress`, `permission_denied`, `rate_limit`, `task_started`, `task_updated`, `task_completed`, `compact_boundary`. Discriminate on `type`.
29
+ - `SendOptions.onRunEvent?: (e: RunEvent) => void` — best-effort, fail-safe: a throwing sink never breaks the run (`emitRunEvent` swallows it).
30
+ - **Emitted end-to-end as of SE2:** `tool_progress` (a tool dispatches) and `permission_denied` (a plugin gate blocks a tool) — both proven via an integration test driving a real run against a stub provider. The remaining variants (`rate_limit`, `task_*`, `compact_boundary`) are part of the contract; their emission is wired incrementally as the sink is threaded into the LLM-client retry / task / session-compaction subsystems (they live below the agent loop). A consumer switching exhaustively on `type` is future-proof.
31
+
32
+ New exports: `RunEvent` (+ the 7 member types), `RunEventSink`, `emitRunEvent`. Additive + backward-compatible.
33
+
34
+ Grounded in the SDK Evolution roadmap SE2 (Anthropic Agent SDK comparison).
35
+
36
+ - eec7d55: **SE3 — multi-agent provenance (`origin`).**
37
+
38
+ New public `MessageOrigin` discriminated union that stamps WHO triggered a turn in the multi-agent path (Squad / a2a / handoff / background-delegation) and is **forwarded onto the run result** — so consumers can attribute or route turns by their trigger. Metadata-only: zero change to routing or dispatch. Mirrors the Anthropic Agent SDK's `origin` shape.
39
+
40
+ - `MessageOrigin` union: `{ kind: "human" }` | `{ kind: "peer"; from }` | `{ kind: "task-notification" }` | `{ kind: "coordinator"; from? }` | `{ kind: "auto-continuation" }`. Absence = a direct human turn.
41
+ - `SendOptions.origin?: MessageOrigin` — the caller stamps the provenance; `RunResult.origin?: MessageOrigin` — forwarded onto the result (both fixture and real runtimes).
42
+ - **Squad** stamps `{ kind: "peer", from: "agent-<i-1>" }` on every step after the first (the first receives the human input). `agentStep(id, agent, prompt, { origin })` carries it; `AgentStep.origin` is the plumbing.
43
+ - **a2a** projects `{ kind: "peer", from }` onto every `A2AMessage.origin` — a thin view over the existing sender address (`from`), not a parallel system.
44
+ - **background-delegation / handoff** are host-driven (no in-repo re-send seam): the `SendOptions.origin → RunResult.origin` plumbing IS the integration point — a background follow-up carries `{ kind: "task-notification" }`, a coordinator carries `{ kind: "coordinator" }`.
45
+
46
+ New exports: `MessageOrigin`, plus `origin` fields on `SendOptions` / `RunResult` / `A2AMessage` / `AgentStep` and the `agentStep(..., { origin })` option. Additive + backward-compatible.
47
+
48
+ Grounded in the SDK Evolution roadmap SE3 (Anthropic Agent SDK comparison).
49
+
50
+ - 8606f5b: **SE4 — session-management surface (`createSessionManager`).**
51
+
52
+ A session-management API over the `ConversationStorageAdapter` interface, so hosts (TheoKit) can build session UIs without reaching into storage internals. Light metadata is derived from the transcript; title/tag are persisted; adapters that can't list or write metadata degrade with a typed `{ supported: false }` result instead of throwing on every call.
53
+
54
+ - `createSessionManager(storage)` → `{ listSessions, getSessionMessages, renameSession, tagSession }`, bound to the same adapter a host passed to `Agent.create({ conversationStorage })` (composition-LEGO precedent of `createSquad`).
55
+ - `listSessions(opts?)` returns `SessionSummary`s with LIGHT metadata derived from the transcript — `firstPrompt` (first user message), `lastModified` (max `StoredMessage.at`), `messageCount`, plus a `summary` preview (title when set, else the truncated first prompt). `{ offset, limit }` windows the result.
56
+ - `renameSession(id, title)` / `tagSession(id, tag | null)` persist session metadata (`tag: null` clears). `getSessionMessages(id, opts?)` passes through to the adapter's mandatory `getMessages`.
57
+ - **Typed graceful degradation:** `listSessions` is unsupported when the adapter lacks `listConversationIds` (or it returns `undefined`); `renameSession` / `tagSession` are unsupported when the adapter lacks `setSessionMeta`. `SessionCapabilityResult<T> = { supported: true; value } | { supported: false; reason }`.
58
+ - **Storage:** two new OPTIONAL adapter methods `getSessionMeta?` / `setSessionMeta?` (`SessionMeta { title?, tag? }`, `SessionMetaPatch { title?, tag?: string | null }`). `FileSystemConversationStorage` persists them in a per-conversation sidecar `.theokit/agents/<id>/session.json` (same sanitized path perimeter as the transcript); `InMemoryConversationStorage` in a `Map`.
59
+
60
+ New exports: `createSessionManager`, `SessionManager`, `SessionSummary`, `SessionListOptions`, `SessionCapabilityResult`, `SessionMeta`, `SessionMetaPatch`. Additive + backward-compatible.
61
+
62
+ Grounded in the SDK Evolution roadmap SE4 (Anthropic Agent SDK comparison).
63
+
64
+ - ce9b375: **SE7 — structured/multimodal tool results + `ToolError`.**
65
+
66
+ A tool can now hand the model structured content (text + image) as its result OR its error, not just a string — symmetrically. A `handler` may RETURN content blocks on success, and may THROW a `ToolError` carrying content blocks on failure (e.g. a screenshot, a rendered chart). Additive + backward-compatible: returning/throwing a string is unchanged.
67
+
68
+ - New types `ImageBlock` + `ToolResultContentBlock = TextBlock | ImageBlock`; new `ToolError` class carrying `string | ToolResultContentBlock[]` (throw it from a handler for a clean message or multimodal error content).
69
+ - `CustomTool.handler` return widened to `string | ToolResultContentBlock[]`.
70
+ - **Provider-agnostic, capability-based:** block-capable provider wires forward the blocks natively; string-only provider wires flatten text-only blocks to a string and **fail fast** with a typed `ConfigurationError` on an image block (no silent drop — a dropped image would be a lie to the model, per the error-handling policy).
71
+ - Persistence/replay (event-based) is untouched; the tool-result guard still redacts/delimits the text of a structured result (image blocks pass through).
72
+
73
+ New exports: `ToolError`, `ImageBlock`, `ToolResultContentBlock`. Proven end-to-end by an integration test (a handler-returned image, and a `ToolError`'s image, both carried onto the outbound `tool_result`).
74
+
75
+ Grounded in the SDK Evolution roadmap SE7.
76
+
77
+ - 3722208: **SE8 — model bare-string shorthand.**
78
+
79
+ Every public model-accepting surface — `AgentOptions.model`, `SendOptions.model`, `AgentBuilder.model()`, and `GenerateObjectOptions.model` / `structuringModel` / `StreamObjectOptions.model` — now accepts a bare-string model id (`model: "openai/gpt-4o-mini"`) in addition to the `{ id }` object, matching every peer SDK's `"provider/model"` shorthand. Additive + fully backward-compatible: the object form (and `{ id, params }` for tuning) is unchanged.
80
+
81
+ - A bare string is normalized to `{ id }` at ONE boundary seam (`normalizeModel`), so all downstream code keeps seeing a `ModelSelection`. The id still parses a `provider/` prefix for routing.
82
+ - Use the object form when you need `params` (reasoning/temperature tuning): `model: { id: "...", params: [...] }`.
83
+ - An empty / whitespace-only string throws a typed `ConfigurationError` (`code: "invalid_model_selection"`).
84
+
85
+ From the DX comparison against OpenAI Agents / LangChain `create_agent` / Vercel AI SDK `ToolLoopAgent` / Mastra (all take a bare string). Grounded in ROADMAP SE8.
86
+
87
+ - d039cd6: **SE9 — integrated structured output on `agent.generate()`.**
88
+
89
+ New typed `agent.generate(input, { output: schema, ...sendOptions })` method: runs the agent's NORMAL tool loop (the user's tools run first) and then coerces the final answer into a Zod schema, returning a validated, **inferred-typed** object — in one call, instead of a separate `generateObject`. This closes the biggest DX-capability gap vs LangChain `response_format` / Vercel AI SDK `Output.object`.
90
+
91
+ - `agent.generate<T>(input, { output: T, ...SendOptions }): Promise<GenerateRunResult<z.infer<T>>>` — `{ object, result, raw, usage }`. `object` carries the inferred type; `result` is the underlying tool-loop `RunResult` (status/usage/model).
92
+ - **Sugar over `Agent.generateObject` (ADR D33), not a fork:** phase 1 is the user's own `agent.send()` run; phase 2 reuses `generateObjectImpl` (the synthetic forced-`output`-tool + Zod validation + retries) over the run's final answer.
93
+ - **Precedence:** `SendOptions` (tools, `toolChoice`, `maxIterations`, …) drive phase 1; the structuring phase forces its own `output` tool. `maxRetries` / `errorStrategy` (`"throw"` | `"return-partial"` | `"return-raw"`) tune phase 2.
94
+ - **Typed failure:** a run that errors before an answer surfaces a typed `GenerateObjectError` (no structuring over a failed run); a persistent parse-failure is governed by `errorStrategy`.
95
+ - Available on both local and cloud agents.
96
+
97
+ New exports: `GenerateOptions`, `GenerateRunResult` (+ the `SDKAgent.generate` method). Additive + backward-compatible. From the DX comparison vs OpenAI Agents / LangChain / AI SDK / Mastra. Grounded in ROADMAP SE9.
98
+
99
+ ### Patch Changes
100
+
101
+ - d07ae2e: Dead-code cleanup (evidence-based review, 2026-07-09).
102
+
103
+ - Removed 8 dead files: 6 unused barrels (`internal/{error-mappers,tool-dispatch,tool-registry,workflow}/index.ts`, `server/adapter/index.ts`, `internal/observability/index.ts`) whose members are reached via direct imports, plus `internal/runtime/hooks/hooks-loader.ts` (`loadProjectHooks` had zero callers) and `internal/observability/context.ts` (only reachable via the now-removed barrel). The live `internal/observability/tracer-loader.ts` is untouched (3 direct importers).
104
+ - Removed two dead public sub-path exports: `@theokit/sdk/internal/plugins` and `@theokit/sdk/internal/observability` (both `@internal`, semver-exempt, zero consumers across the monorepo). The plugin contract (`definePlugin`/`Plugin`) remains exported from the main entry — the sub-path was superseded (see `src/index.ts`); `internal/plugins/index.ts` stays as an internal relative import.
105
+
106
+ No behavior change — typecheck + build green; full test suite delta neutral (pre-existing flaky init-claude/oauth failures unchanged). See `DEAD-CODE-REVIEW-2026-07-09.md` for the full 3-layer review and the remaining phased plan.
107
+
108
+ - e462318: Deprecate the `@theokit/sdk/client` sub-path (`TheoKitClient`).
109
+
110
+ `TheoKitClient` consumes a legacy server-adapter HTTP contract (`POST /agent/send`, `GET /agent/stream`) that the ecosystem no longer produces — the framework (`theokit`) exposes agents at `POST /api/agents/<name>` over a `UIMessageStream` with its own typed client, and the SDK's own in-process path is the `Agent` façade. The sub-path has zero consumers across the monorepo (evidence-based dead-code review, 2026-07-09).
111
+
112
+ Marked `@deprecated` (class + barrel + types). No behavior change — the sub-path still works this major. It will be **removed in the next major**. Migrate to `Agent` (`@theokit/sdk`) for in-process runs, or the framework's `/api/agents/<name>` typed client for HTTP.
113
+
114
+ - b4f165c: Remove 3 orphaned internal helpers (dead code, 0 references monorepo-wide): `buildRequestId` (a wrapper around `generateRequestId`, no callers), `isCloudAgentId` (`internal/ids.ts`, no callers), and `deleteTokens` (`internal/mcp/token-storage.ts`, no callers). All `@internal`, not part of the public API. Verified: typecheck + build green, full test suite unchanged (181 pre-existing flaky failures, 3042 pass — identical to baseline).
115
+
116
+ The remaining knip-flagged "unused exports" were audited and deliberately NOT deleted: they are mostly redundant `export` modifiers on symbols still used same-file (cosmetic), future-reserved stubs (`serializeHookRules` — "reserved for future"), or intentional test/reset seams (`__*ForTests`, `createTestCtx`, `clearRunRegistry`, `memoryFilePath` — "kept for tests"). Those are maintainer judgment calls, not mechanical dead code. See `DEAD-CODE-REVIEW-2026-07-09.md`.
117
+
118
+ ## 2.20.0
119
+
120
+ ### Minor Changes
121
+
122
+ - **M21 — `GenerateObjectOptions.structuringModel`.** An optional separate model for the structured-extraction step: when set, `model` first produces a free-text reasoned answer (phase 1), then `structuringModel` extracts the schema-matched object by calling the synthetic `output` tool over that answer (phase 2). Lets a large model reason while a cheap fast model structures. Absent ⇒ today's single-model flow (backward-compatible). Proven by a golden test asserting two distinct model ids in the run.
123
+ - **M22 — `createSkill()` + `SkillsSettings.skillsDir` / `.inline`.** `createSkill({ name, description, instructions })` defines a skill in TypeScript without a `SKILL.md` file; pass code-defined skills via `skills.inline` (they surface in `list()` + the `<skills>` block alongside filesystem skills, overriding a file skill of the same name). `skills.skillsDir` discovers skills from a custom directory instead of `<cwd>/.theokit/skills`. Both compose with the per-request enabled-name resolver.
124
+ - **M23 — `normalizeSchema()`.** Converts a schema from Zod (default), JSON Schema (passthrough), ArkType (`.toJsonSchema()`), or Valibot (via the optional `@valibot/to-json-schema` peer) to the internal JSON Schema the synthetic `output` tool uses. Zod stays the default and the documented recommendation; thin adapter, uniform parse-failure handling. A golden test per provider.
125
+
3
126
  ## 2.19.0
4
127
 
5
128
  ### Minor Changes