theokit 0.30.0 → 0.30.2
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/LICENSE +201 -0
- package/dist/{actions-virtual-module-PBLLMJY4.js → actions-virtual-module-XHVLBFNN.js} +7 -7
- package/dist/actions-virtual-module-Z2IXNF72.js +0 -0
- package/dist/add-W6FNTAFS.js +0 -0
- package/dist/agent-I5QEOMCN.js +0 -0
- package/dist/agents-typed-client-5DCGDWFZ.js +0 -0
- package/dist/{app-typed-client-EXHUWPOI.js → app-typed-client-4PAUHTO6.js} +7 -7
- package/dist/app-typed-client-YCQC3MZ7.js +0 -0
- package/dist/aws-lambda-7GSCNLPY.js +0 -0
- package/dist/body-parser-web-FV5HWCY3.js +0 -0
- package/dist/boot/index.js +3 -3
- package/dist/broadcast-LUMOJIJT.js +0 -0
- package/dist/build-V2QEBE7I.js +0 -0
- package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
- package/dist/bun-KP2KES6S.js +0 -0
- package/dist/check-PD2FTKMM.js +0 -0
- package/dist/chunk-2CVV6CNN.js +0 -0
- package/dist/chunk-45C3WUQ7.js +0 -0
- package/dist/{chunk-UYFZ6DDW.js → chunk-4MTCKE5I.js} +1 -189
- package/dist/chunk-4MTCKE5I.js.map +1 -0
- package/dist/chunk-5ODOE6EF.js +0 -0
- package/dist/chunk-63BUBV5L.js +64 -0
- package/dist/chunk-63BUBV5L.js.map +1 -0
- package/dist/chunk-AFVTEAES.js +0 -0
- package/dist/chunk-FOZIR3TG.js +0 -0
- package/dist/chunk-FRUEDJFX.js +0 -0
- package/dist/chunk-GDN3PXFH.js +0 -0
- package/dist/chunk-GEQJAFSV.js +0 -0
- package/dist/chunk-GSO77FSM.js +0 -0
- package/dist/{chunk-EHUT4FMG.js → chunk-HAOPVC47.js} +29 -27
- package/dist/{chunk-EHUT4FMG.js.map → chunk-HAOPVC47.js.map} +1 -1
- package/dist/chunk-HGZL5EOI.js +0 -0
- package/dist/chunk-HNBWZKIQ.js +0 -0
- package/dist/chunk-HZ6USUHC.js +191 -0
- package/dist/chunk-HZ6USUHC.js.map +1 -0
- package/dist/chunk-IEES3CHD.js +0 -0
- package/dist/chunk-JAIKGP3Q.js +0 -0
- package/dist/chunk-KXA37ONC.js +0 -0
- package/dist/chunk-M6NMS5LR.js +0 -0
- package/dist/chunk-P37RZRFV.js +0 -0
- package/dist/chunk-S7L6H3KP.js +0 -0
- package/dist/chunk-SPFMJAFW.js +326 -0
- package/dist/chunk-SPFMJAFW.js.map +1 -0
- package/dist/chunk-TERFLG67.js +0 -0
- package/dist/{chunk-DMGVH3VG.js → chunk-V3X5FWJA.js} +5 -62
- package/dist/chunk-V3X5FWJA.js.map +1 -0
- package/dist/chunk-VRVNM3QL.js +0 -0
- package/dist/chunk-WR4F4EEZ.js +0 -0
- package/dist/chunk-Y4TOVMNC.js +0 -0
- package/dist/chunk-YJWEADAW.js +0 -0
- package/dist/cloudflare-C6E5SPAE.js +0 -0
- package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
- package/dist/db-3UNAMSFK.js +0 -0
- package/dist/define-agent-tool-ChaGymol.d.ts +88 -0
- package/dist/deno-deploy-RFZN56X4.js +0 -0
- package/dist/dev-5ZQMWVFC.js +0 -0
- package/dist/dev-emit-EFQRBVYS.js +0 -0
- package/dist/dispatcher-EJHL6JMJ.js +0 -0
- package/dist/docker-LZZB4D5E.js +0 -0
- package/dist/generate-373DALPY.js +0 -0
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/info-2OOXFTJX.js +0 -0
- package/dist/{internal-api-JIR3HRKF.js → internal-api-QSP2HCUU.js} +20 -20
- package/dist/internal-api-Y5REPVUS.js +0 -0
- package/dist/load-config-3EAQTXPH.js +0 -0
- package/dist/mcp-VMKWB2BY.js +0 -0
- package/dist/netlify-PMLHVPN4.js +0 -0
- package/dist/node-BPJ3Z4DT.js +0 -0
- package/dist/openapi-ERYWAT3A.js +0 -0
- package/dist/registry-3NB7KOUI.js +0 -0
- package/dist/router-TLEAOFID.js +0 -0
- package/dist/routes-XNS3UM3B.js +0 -0
- package/dist/scan-7MJC6PYU.js +0 -0
- package/dist/schema-LYOLNHZ7.js +0 -0
- package/dist/server/agent/index.d.ts +387 -0
- package/dist/server/agent/index.js +43 -0
- package/dist/server/agent/index.js.map +1 -0
- package/dist/server/auth/index.js +1 -1
- package/dist/server/define/index.d.ts +3 -86
- package/dist/server/define/index.js +4 -2
- package/dist/server/index.d.ts +10 -387
- package/dist/server/index.js +112 -398
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.js +4 -4
- package/dist/server/scan/index.js +1 -1
- package/dist/server/webhook/index.d.ts +4 -45
- package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
- package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
- package/dist/services-json-Y3XODNB5.js +0 -0
- package/dist/services-typed-client-32KMTTXR.js +0 -0
- package/dist/start-IFTLTEPZ.js +0 -0
- package/dist/static-MB2CD5Y3.js +0 -0
- package/dist/storage-manager-ZSQFLEYT.js +0 -0
- package/dist/theo-cloud-DQRP6S6M.js +0 -0
- package/dist/upgrade-readiness-ACGW44JC.js +0 -0
- package/dist/vercel-J6G7ZHYQ.js +0 -0
- package/dist/vite-plugin/index.js +11 -10
- package/dist/vite-plugin-BNI7YLCD.js +0 -0
- package/dist/webhook-types-CNUZY7o1.d.ts +45 -0
- package/package.json +14 -10
- package/dist/chunk-DMGVH3VG.js.map +0 -1
- package/dist/chunk-UYFZ6DDW.js.map +0 -1
- /package/dist/{actions-virtual-module-PBLLMJY4.js.map → actions-virtual-module-XHVLBFNN.js.map} +0 -0
- /package/dist/{app-typed-client-EXHUWPOI.js.map → app-typed-client-4PAUHTO6.js.map} +0 -0
- /package/dist/{internal-api-JIR3HRKF.js.map → internal-api-QSP2HCUU.js.map} +0 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { C as CustomTool } from '../../define-agent-tool-ChaGymol.js';
|
|
3
|
+
import { AcpTransport, HumanInTheLoopOptions, HitlDecision, streamAgentUIMessages } from '@theokit/agents';
|
|
4
|
+
import { CustomTool as CustomTool$1 } from '@theokit/sdk';
|
|
5
|
+
import { V as VerifyFn } from '../../webhook-types-CNUZY7o1.js';
|
|
6
|
+
import { UIMessageChunk } from 'ai';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* M26 (ADR-0041) — `createWorkflowTool`: wrap an SDK `Workflow` as a `CustomTool`.
|
|
10
|
+
*
|
|
11
|
+
* THIN adapter. `packages/workflows/` stays G13-forbidden — the workflow ENGINE is the SDK's
|
|
12
|
+
* (`Workflow.create(...).run(input)`). This exposes an already-built `Workflow` to an agent as one
|
|
13
|
+
* callable tool: it validates the tool input, delegates to `workflow.run(input)`, and shapes the
|
|
14
|
+
* result for the model. It calls no LLM, dispatches no tool, and runs no orchestration of its own —
|
|
15
|
+
* the SDK owns all of that (sdk-runtime.md / G2).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Structural stand-in for the SDK `Workflow` (the adapter never imports the SDK type — keeps the
|
|
20
|
+
* SDK an optional peer). Any object with a `run(input)` resolving to `{ status, output }` matches.
|
|
21
|
+
*/
|
|
22
|
+
interface WorkflowLike {
|
|
23
|
+
run(input: unknown): Promise<{
|
|
24
|
+
status: string;
|
|
25
|
+
output: unknown;
|
|
26
|
+
runId?: string;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/** Config for {@link createWorkflowTool}. `inputSchema` defaults to an open object. */
|
|
30
|
+
interface WorkflowToolConfig {
|
|
31
|
+
/** Tool name surfaced to the LLM. */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Tool description surfaced to the LLM. */
|
|
34
|
+
description: string;
|
|
35
|
+
/** Zod schema for the workflow input (defaults to `z.object({}).passthrough()`). */
|
|
36
|
+
inputSchema?: z.ZodType;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Wrap an SDK `Workflow` as a {@link CustomTool}. Fails fast if `workflow` does not expose a
|
|
40
|
+
* `run()` method (the SDK Workflow contract), so a mis-wired call is caught at definition time, not
|
|
41
|
+
* at the first invocation (error-handling.md).
|
|
42
|
+
*/
|
|
43
|
+
declare function createWorkflowTool(workflow: WorkflowLike, config: WorkflowToolConfig): CustomTool;
|
|
44
|
+
|
|
45
|
+
/** Stdio transport backed by a spawned subprocess (the default for {@link createACPTool}). */
|
|
46
|
+
declare class NodeAcpTransport implements AcpTransport {
|
|
47
|
+
private readonly proc;
|
|
48
|
+
constructor(command: string, args?: string[], cwd?: string);
|
|
49
|
+
send(line: string): void;
|
|
50
|
+
subscribe(onData: (chunk: string) => void): void;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
53
|
+
interface AcpToolConfig {
|
|
54
|
+
/** Executable for the coding agent (e.g. `claude`, `amp`, `codex`). */
|
|
55
|
+
command: string;
|
|
56
|
+
/** Command-line arguments. */
|
|
57
|
+
args?: string[];
|
|
58
|
+
/** Working directory for the spawned agent. */
|
|
59
|
+
cwd?: string;
|
|
60
|
+
/** Tool name the model calls. */
|
|
61
|
+
name: string;
|
|
62
|
+
/** Tool description surfaced to the model. */
|
|
63
|
+
description: string;
|
|
64
|
+
/**
|
|
65
|
+
* REQUIRED — decide file/shell permission requests from the coding agent. Security by default:
|
|
66
|
+
* there is NO default-allow. Return `{ granted: boolean }` (may be async).
|
|
67
|
+
*/
|
|
68
|
+
onPermissionRequest: (params: unknown) => {
|
|
69
|
+
granted: boolean;
|
|
70
|
+
} | Promise<{
|
|
71
|
+
granted: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
/** Injected transport factory (defaults to spawning via {@link NodeAcpTransport}) — for tests. */
|
|
74
|
+
transportFactory?: (config: AcpToolConfig) => AcpTransport;
|
|
75
|
+
}
|
|
76
|
+
/** Wrap a coding agent as a `CustomTool`. Fails fast if `onPermissionRequest` is missing. */
|
|
77
|
+
declare function createACPTool(config: AcpToolConfig): CustomTool$1;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* M28 (ADR-0041) — `createVendorAgentTool`: expose a third-party agent SDK (Claude Agent SDK,
|
|
81
|
+
* OpenAI, Cursor) behind a uniform `CustomTool`, mirroring the M17 ACP pattern.
|
|
82
|
+
*
|
|
83
|
+
* The vendor RUNTIME stays theirs — TheoKit only wires. The vendor client is INJECTED (the real
|
|
84
|
+
* vendor SDK client in prod, a fake in tests), so no vendor dependency enters core; vendor-specific
|
|
85
|
+
* client packages belong under `@theokit/agent-*`, never here. This calls no LLM of its own and runs
|
|
86
|
+
* no loop — it delegates each prompt to `client.query(...)` (sdk-runtime.md / G2). Resume is threaded
|
|
87
|
+
* via the vendor's own session id.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Structural contract a vendor agent client must satisfy (the adapter never imports a vendor type).
|
|
92
|
+
* `query` runs one turn; `resumeSessionId` continues a prior vendor session; the returned
|
|
93
|
+
* `sessionId` identifies the session to resume next.
|
|
94
|
+
*/
|
|
95
|
+
interface VendorAgentClient {
|
|
96
|
+
query(prompt: string, opts?: {
|
|
97
|
+
resumeSessionId?: string;
|
|
98
|
+
}): Promise<{
|
|
99
|
+
text: string;
|
|
100
|
+
sessionId?: string;
|
|
101
|
+
}>;
|
|
102
|
+
}
|
|
103
|
+
/** Config for {@link createVendorAgentTool}. */
|
|
104
|
+
interface VendorAgentToolConfig {
|
|
105
|
+
/** Vendor label (e.g. `claude`, `openai`, `cursor`). Drives the default tool name. */
|
|
106
|
+
vendor: string;
|
|
107
|
+
/** The injected vendor client (real SDK client in prod, a fake in tests). */
|
|
108
|
+
client: VendorAgentClient;
|
|
109
|
+
/** Tool name the model calls (defaults to `<vendor>_agent`). */
|
|
110
|
+
name?: string;
|
|
111
|
+
/** Tool description surfaced to the model (defaults to a one-line delegate hint). */
|
|
112
|
+
description?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Side-channel callback invoked with the vendor session id after each turn — lets the app capture
|
|
115
|
+
* it for a later resume WITHOUT leaking session bookkeeping into the model's view of the result.
|
|
116
|
+
*/
|
|
117
|
+
onSession?: (sessionId: string) => void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Wrap a vendor agent SDK as a {@link CustomTool}. Fails fast if `vendor` is empty or the client
|
|
121
|
+
* does not expose `query()` (error-handling.md) — a mis-wired call is caught at definition time.
|
|
122
|
+
*/
|
|
123
|
+
declare function createVendorAgentTool(config: VendorAgentToolConfig): CustomTool;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* M29 (ADR-0041) — `createCodeMode`: expose a set of tools to agent-authored code run inside an
|
|
127
|
+
* ISOLATION boundary, so the agent composes tools programmatically instead of one call at a time.
|
|
128
|
+
*
|
|
129
|
+
* Security posture (the whole point of this feature):
|
|
130
|
+
* - The isolation boundary (`sandbox`) is **injected**, never hand-rolled here (Top-risk 1). The app
|
|
131
|
+
* supplies a vetted sandbox — isolated-vm, QuickJS-WASM, or a locked-down worker. TheoKit core
|
|
132
|
+
* ships no VM and adds no sandbox dependency (same posture as the injected deploy adapter / the
|
|
133
|
+
* M17 transport). `node:vm` is NOT a security boundary and MUST NOT be used as the sandbox.
|
|
134
|
+
* - TheoKit owns the **restricted API** (only the declared tools are reachable from the code — no
|
|
135
|
+
* `fs`, `process`, `require`, or network unless a declared, permission-gated tool provides it) and
|
|
136
|
+
* the **mandatory permission gate**: every tool call from the code passes `onPermissionRequest`
|
|
137
|
+
* first, and there is NO default-allow (mirrors M17 `onPermissionRequest`).
|
|
138
|
+
*
|
|
139
|
+
* Threat model (summary): a malicious model could author code that (a) calls a dangerous tool, or
|
|
140
|
+
* (b) tries to reach a host capability. (a) is stopped by the permission gate (deny → the API call
|
|
141
|
+
* throws). (b) is stopped by the injected sandbox (the restricted API is the ONLY surface the code
|
|
142
|
+
* sees). If the app injects a weak sandbox, (b) is on the app — hence the vetted-sandbox requirement.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
/** The restricted API handed to sandboxed code: declared tool names → permission-gated callables. */
|
|
146
|
+
type CodeModeApi = Record<string, (args: unknown) => Promise<unknown>>;
|
|
147
|
+
/** The injected isolation boundary. The app supplies a vetted implementation. */
|
|
148
|
+
interface Sandbox {
|
|
149
|
+
/** Run `code` with access to ONLY `api` (the restricted tool surface). Resolve the code's result. */
|
|
150
|
+
run(code: string, api: CodeModeApi): Promise<unknown>;
|
|
151
|
+
}
|
|
152
|
+
/** A permission decision for one tool call from sandboxed code. */
|
|
153
|
+
interface CodeModePermission {
|
|
154
|
+
granted: boolean;
|
|
155
|
+
/** Optional reason surfaced to the model on denial. */
|
|
156
|
+
reason?: string;
|
|
157
|
+
}
|
|
158
|
+
interface CodeModeConfig {
|
|
159
|
+
/** The tools reachable from the code (the restricted API). */
|
|
160
|
+
tools: CustomTool[];
|
|
161
|
+
/** The injected isolation boundary (vetted sandbox — NEVER node:vm). */
|
|
162
|
+
sandbox: Sandbox;
|
|
163
|
+
/**
|
|
164
|
+
* REQUIRED — decide each tool call the code attempts. Security by default: NO default-allow.
|
|
165
|
+
* Return `{ granted }` (may be async). Mirrors M17 `onPermissionRequest`.
|
|
166
|
+
*/
|
|
167
|
+
onPermissionRequest: (req: {
|
|
168
|
+
tool: string;
|
|
169
|
+
args: unknown;
|
|
170
|
+
}) => CodeModePermission | Promise<CodeModePermission>;
|
|
171
|
+
/** Tool name the model calls (default `run_code`). */
|
|
172
|
+
name?: string;
|
|
173
|
+
/** Tool description surfaced to the model. */
|
|
174
|
+
description?: string;
|
|
175
|
+
}
|
|
176
|
+
/** Thrown when the permission gate denies a tool call from sandboxed code. */
|
|
177
|
+
declare class CodeModePermissionDeniedError extends Error {
|
|
178
|
+
constructor(tool: string, reason?: string);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Build a code-mode tool + its generated model instructions (M40 / ADR-0049). Fails fast if
|
|
182
|
+
* `onPermissionRequest` or `sandbox` is missing (security by default). `tool` takes `{ code }`,
|
|
183
|
+
* assembles the permission-gated restricted API from `tools`, runs the code in the injected sandbox,
|
|
184
|
+
* and returns the code's result. `instructions` (add it to the agent's system prompt) teaches the
|
|
185
|
+
* model the sandboxed-code contract + the available `api.<name>(input)` calls.
|
|
186
|
+
*/
|
|
187
|
+
declare function createCodeMode(config: CodeModeConfig): {
|
|
188
|
+
tool: CustomTool;
|
|
189
|
+
instructions: string;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* M27 (ADR-0041) — channel webhook routes: `POST /api/agents/<name>/channels/<platform>/webhook`.
|
|
194
|
+
*
|
|
195
|
+
* Auto-generates a per-platform inbound webhook endpoint that VALIDATES the platform signature
|
|
196
|
+
* (reusing the existing webhook `VerifyFn` providers — Slack/Telegram/Discord — never a hand-rolled
|
|
197
|
+
* scheme) and hands the parsed payload to an injected `onMessage` seam. The seam is where an app
|
|
198
|
+
* wires the SDK gateway package (`@theokit/gateway-*`) that translates the payload into an agent
|
|
199
|
+
* turn — TheoKit provides the route + signature gate, NOT the gateway's parsing (G2 / it does not
|
|
200
|
+
* reimplement the gateway).
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
/** Parsed `{ agent, platform }` from a channel webhook path, or `null` when it doesn't match. */
|
|
204
|
+
declare function parseChannelPath(urlPath: string): {
|
|
205
|
+
agent: string;
|
|
206
|
+
platform: string;
|
|
207
|
+
} | null;
|
|
208
|
+
/** True when `urlPath` targets a channel webhook (dev/prod routing branches on this). */
|
|
209
|
+
declare function isChannelPath(urlPath: string): boolean;
|
|
210
|
+
/** The inbound message handed to the app after signature validation passes. */
|
|
211
|
+
interface ChannelMessage {
|
|
212
|
+
agent: string;
|
|
213
|
+
platform: string;
|
|
214
|
+
/** The parsed JSON payload from the platform (the gateway translates this to an agent turn). */
|
|
215
|
+
payload: unknown;
|
|
216
|
+
}
|
|
217
|
+
interface ChannelWebhookConfig {
|
|
218
|
+
/** Per-platform signature validators (e.g. `{ slack: slack({...}), telegram: telegram({...}) }`). */
|
|
219
|
+
validators: Record<string, VerifyFn>;
|
|
220
|
+
/** Handoff seam — wire the SDK gateway / agent here. Invoked only after signature validation. */
|
|
221
|
+
onMessage: (message: ChannelMessage) => void | Promise<void>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Handle one channel webhook request. Returns:
|
|
225
|
+
* 404 UNKNOWN_PLATFORM — no validator configured for `<platform>`
|
|
226
|
+
* 400 BAD_REQUEST — path is not a channel webhook, or the body is not JSON
|
|
227
|
+
* 401 INVALID_SIGNATURE — the platform signature check failed (negative case)
|
|
228
|
+
* 200 { ok: true } — validated + handed to `onMessage`
|
|
229
|
+
*/
|
|
230
|
+
declare function handleChannelWebhook(request: Request, urlPath: string, config: ChannelWebhookConfig): Promise<Response>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* M35 (multi-surface) — the in-process agent-turn seam (Model A).
|
|
234
|
+
*
|
|
235
|
+
* The FRAMEWORK-owned sibling of the HTTP `mountAgent` and the stdout `runAgentInTerminal`: it runs a
|
|
236
|
+
* compiled agent with the SAME `compileAgentModule` + SAME `streamAgentUIMessages` (G2 — reuses the
|
|
237
|
+
* SDK runtime, reimplements nothing), but returns the raw `UIMessageChunk` generator so ANY consumer
|
|
238
|
+
* drives it directly — the Ink TUI (M35), a Tauri window (M36), or a test — in a SINGLE process with
|
|
239
|
+
* NO HTTP loopback, NO port, and NO CSRF (there is no network boundary to defend).
|
|
240
|
+
*
|
|
241
|
+
* The ONLY difference from the HTTP mount is HITL resolution: the mount pauses the run and resolves
|
|
242
|
+
* the approval via a SECOND HTTP request to `/approve/:id` (the approval registry). In-process there
|
|
243
|
+
* is no second request — the caller resolves the approval INLINE via `awaitApproval` (e.g. the Ink
|
|
244
|
+
* TUI's y/n prompt). The gated-tool map is `compiled.hitl` verbatim, so the pause semantics are
|
|
245
|
+
* byte-identical to the HTTP path; only the resolver differs. Parity with the mount is by
|
|
246
|
+
* construction: both compile the module, resolve function-form skills, and call `streamAgentUIMessages`
|
|
247
|
+
* with the same `{ message, sessionId, hitl }`.
|
|
248
|
+
*
|
|
249
|
+
* Consumers WILL still receive `tool-approval-request` chunks from the returned generator — they are
|
|
250
|
+
* INFORMATIONAL (render them or ignore them). The authoritative human gate is `awaitApproval`, which
|
|
251
|
+
* the SDK awaits BEFORE the gated tool runs; the chunk is not the gate.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/** An inline approval request handed to the caller's `awaitApproval` (the Ink/Tauri prompt). */
|
|
255
|
+
interface InProcessApprovalRequest {
|
|
256
|
+
approvalId: string;
|
|
257
|
+
toolName: string;
|
|
258
|
+
opts: HumanInTheLoopOptions;
|
|
259
|
+
}
|
|
260
|
+
/** Resolve one gated-tool approval inline (approve/deny, or a structured {@link HitlDecision}). */
|
|
261
|
+
type InProcessAwaitApproval = (req: InProcessApprovalRequest) => Promise<boolean | HitlDecision>;
|
|
262
|
+
interface StreamAgentTurnInProcessInput {
|
|
263
|
+
message: string;
|
|
264
|
+
/** Resume key; a fresh id per run when omitted. */
|
|
265
|
+
sessionId?: string;
|
|
266
|
+
/**
|
|
267
|
+
* Inline HITL resolver — required IFF the agent has `@HumanInTheLoop`-gated tools. Omitting it for a
|
|
268
|
+
* gated agent is a fail-fast error, never a silent bypass (Rule 8, the #99 lesson).
|
|
269
|
+
*/
|
|
270
|
+
awaitApproval?: InProcessAwaitApproval;
|
|
271
|
+
/** Labels a fail-fast `AgentDefinitionError` (the file path). */
|
|
272
|
+
source?: string;
|
|
273
|
+
/** Abort signal forwarded to the SDK stream (client disconnect / window close). */
|
|
274
|
+
signal?: AbortSignal;
|
|
275
|
+
}
|
|
276
|
+
/** Injectable stream fn (defaults to the real SDK bridge) — lets tests drive a deterministic stream. */
|
|
277
|
+
interface StreamAgentTurnDeps {
|
|
278
|
+
stream: typeof streamAgentUIMessages;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Thrown when a gated agent is run in-process without an `awaitApproval` resolver. Refusing loudly is
|
|
282
|
+
* the correct posture: silently running a `@HumanInTheLoop`-gated tool with no human gate is exactly
|
|
283
|
+
* the #99 class of bug. Typed so callers can catch it distinctly.
|
|
284
|
+
*/
|
|
285
|
+
declare class InProcessApprovalRequiredError extends Error {
|
|
286
|
+
constructor(toolNames: readonly string[]);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Run a compiled agent in-process and return its `UIMessageChunk` stream. `apiKey` is resolved by the
|
|
290
|
+
* caller (same contract as the HTTP mount). Validation + compile happen SYNCHRONOUSLY (so a gated
|
|
291
|
+
* agent without a resolver throws at call time, not lazily on first iteration); the returned value is
|
|
292
|
+
* the SDK's `streamAgentUIMessages` generator.
|
|
293
|
+
*/
|
|
294
|
+
declare function streamAgentTurnInProcess(mod: unknown, apiKey: string, input: StreamAgentTurnInProcessInput, deps?: StreamAgentTurnDeps): AsyncGenerator<UIMessageChunk>;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* M30 (ADR-0041) — MCP Apps: `ui://` HTML resources for the MCP server (M16).
|
|
298
|
+
*
|
|
299
|
+
* A tool can declare a `ui://` HTML resource; the MCP server advertises it via `resources/list` and
|
|
300
|
+
* serves the HTML via `resources/read`. The client renders it in a SANDBOXED iframe (see
|
|
301
|
+
* `mcp-app-host.ts`). Pure data transforms here — no LLM, no runtime (ADR-0040 § D2 home concern).
|
|
302
|
+
*
|
|
303
|
+
* Security: only the `ui://` scheme is accepted (an app UI resource), never `http(s)://` — the HTML
|
|
304
|
+
* is rendered sandboxed on the client, and the scheme gate keeps a tool from smuggling a remote URL
|
|
305
|
+
* into the app surface.
|
|
306
|
+
*/
|
|
307
|
+
/** A declared `ui://` app resource. */
|
|
308
|
+
interface AppResource {
|
|
309
|
+
uri: string;
|
|
310
|
+
name: string;
|
|
311
|
+
mimeType: 'text/html';
|
|
312
|
+
html: string;
|
|
313
|
+
description?: string;
|
|
314
|
+
}
|
|
315
|
+
/** Input to {@link defineAppResource}. */
|
|
316
|
+
interface AppResourceInput {
|
|
317
|
+
/** MUST start with `ui://`. */
|
|
318
|
+
uri: string;
|
|
319
|
+
name: string;
|
|
320
|
+
html: string;
|
|
321
|
+
description?: string;
|
|
322
|
+
}
|
|
323
|
+
/** An MCP `resources/list` descriptor (no HTML body — that comes from `resources/read`). */
|
|
324
|
+
interface McpResourceDescriptor {
|
|
325
|
+
uri: string;
|
|
326
|
+
name: string;
|
|
327
|
+
mimeType: 'text/html';
|
|
328
|
+
description?: string;
|
|
329
|
+
}
|
|
330
|
+
/** An MCP `resources/read` result. */
|
|
331
|
+
interface McpResourceContents {
|
|
332
|
+
contents: {
|
|
333
|
+
uri: string;
|
|
334
|
+
mimeType: 'text/html';
|
|
335
|
+
text: string;
|
|
336
|
+
}[];
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Declare a `ui://` HTML app resource. Fails fast if the uri is not a `ui://` scheme or the HTML is
|
|
340
|
+
* empty (error-handling.md) — a misconfigured resource is caught at definition time.
|
|
341
|
+
*/
|
|
342
|
+
declare function defineAppResource(input: AppResourceInput): AppResource;
|
|
343
|
+
/** Map app resources to MCP `resources/list` descriptors (the HTML body is omitted from the list). */
|
|
344
|
+
declare function buildResourceDescriptors(resources: readonly AppResource[]): McpResourceDescriptor[];
|
|
345
|
+
/** Serve the HTML for `uri` as an MCP `resources/read` result, or `null` when unknown. */
|
|
346
|
+
declare function readAppResource(resources: readonly AppResource[], uri: string): McpResourceContents | null;
|
|
347
|
+
/**
|
|
348
|
+
* M30 wiring — extract the App resources an agent module declares via a named `appResources` export
|
|
349
|
+
* (`export const appResources = [defineAppResource(...)]`). Returns only the well-formed entries; a
|
|
350
|
+
* module without the export (or with a malformed one) yields `[]`. This is how per-agent `ui://`
|
|
351
|
+
* resources reach the MCP server's `resources/list` + `resources/read` without a runtime dependency
|
|
352
|
+
* from `@theokit/agents` on this theo-side type (the module exports them; the serving path reads them).
|
|
353
|
+
*/
|
|
354
|
+
declare function extractAppResources(mod: unknown): AppResource[];
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* MCP stdio transport (M16 follow-up) — expose a TheoKit agent as an MCP server over stdin/stdout,
|
|
358
|
+
* the sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`). A desktop MCP client (e.g.
|
|
359
|
+
* Claude Desktop) spawns `theokit mcp <agent>` and speaks newline-delimited JSON-RPC over the pipe.
|
|
360
|
+
*
|
|
361
|
+
* This is a TRANSPORT over the framework's OWN {@link handleMcpJsonRpc} — it reuses the exact handler
|
|
362
|
+
* the HTTP route uses; it calls no LLM, spawns no MCP client, and reimplements no runtime (G2 /
|
|
363
|
+
* sdk-runtime.md). Distinct from the SDK's MCP CLIENT stdio (which spawns external MCP servers via
|
|
364
|
+
* `mcpServers` command/args) — that stays SDK-side. Here TheoKit is the SERVER. The framework-side
|
|
365
|
+
* placement of this server-exposure transport is recorded in ADR-0042 (refining ADR-0040's M16 note).
|
|
366
|
+
*/
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Handle one newline-delimited JSON-RPC line. Returns the response line to write to stdout, or
|
|
370
|
+
* `null` for a blank line (nothing to emit). A malformed JSON line yields a `-32700` (Parse error)
|
|
371
|
+
* envelope — never throws, so the stdio loop never dies on bad input.
|
|
372
|
+
*/
|
|
373
|
+
declare function handleMcpStdioLine(line: string, mod: unknown, name: string, appResources?: readonly AppResource[]): Promise<string | null>;
|
|
374
|
+
/** A minimal readable line source (an async iterable of lines) + a writable sink. */
|
|
375
|
+
interface StdioStreams {
|
|
376
|
+
/** Async iterable of newline-delimited input lines (e.g. `readline.createInterface({ input })`). */
|
|
377
|
+
lines: AsyncIterable<string>;
|
|
378
|
+
/** Write a response line (the caller appends no newline). */
|
|
379
|
+
write: (line: string) => void;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Drive the MCP stdio server loop: for each input line, dispatch via {@link handleMcpStdioLine} and
|
|
383
|
+
* write the response line (with a trailing `\n`). Returns when the input stream ends (EOF).
|
|
384
|
+
*/
|
|
385
|
+
declare function serveMcpStdio(mod: unknown, name: string, appResources: readonly AppResource[], streams: StdioStreams): Promise<void>;
|
|
386
|
+
|
|
387
|
+
export { type AcpToolConfig, type AppResource, type AppResourceInput, type ChannelMessage, type ChannelWebhookConfig, type CodeModeApi, type CodeModeConfig, type CodeModePermission, CodeModePermissionDeniedError, type InProcessApprovalRequest, InProcessApprovalRequiredError, type InProcessAwaitApproval, type McpResourceContents, type McpResourceDescriptor, NodeAcpTransport, type Sandbox, type StdioStreams, type StreamAgentTurnDeps, type StreamAgentTurnInProcessInput, type VendorAgentClient, type VendorAgentToolConfig, type WorkflowLike, type WorkflowToolConfig, buildResourceDescriptors, createACPTool, createCodeMode, createVendorAgentTool, createWorkflowTool, defineAppResource, extractAppResources, handleChannelWebhook, handleMcpStdioLine, isChannelPath, parseChannelPath, readAppResource, serveMcpStdio, streamAgentTurnInProcess };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CodeModePermissionDeniedError,
|
|
3
|
+
InProcessApprovalRequiredError,
|
|
4
|
+
NodeAcpTransport,
|
|
5
|
+
createACPTool,
|
|
6
|
+
createCodeMode,
|
|
7
|
+
createVendorAgentTool,
|
|
8
|
+
createWorkflowTool,
|
|
9
|
+
handleChannelWebhook,
|
|
10
|
+
handleMcpStdioLine,
|
|
11
|
+
isChannelPath,
|
|
12
|
+
parseChannelPath,
|
|
13
|
+
serveMcpStdio,
|
|
14
|
+
streamAgentTurnInProcess
|
|
15
|
+
} from "../../chunk-SPFMJAFW.js";
|
|
16
|
+
import {
|
|
17
|
+
buildResourceDescriptors,
|
|
18
|
+
defineAppResource,
|
|
19
|
+
extractAppResources,
|
|
20
|
+
readAppResource
|
|
21
|
+
} from "../../chunk-HZ6USUHC.js";
|
|
22
|
+
import "../../chunk-63BUBV5L.js";
|
|
23
|
+
import "../../chunk-DGUM43GV.js";
|
|
24
|
+
export {
|
|
25
|
+
CodeModePermissionDeniedError,
|
|
26
|
+
InProcessApprovalRequiredError,
|
|
27
|
+
NodeAcpTransport,
|
|
28
|
+
buildResourceDescriptors,
|
|
29
|
+
createACPTool,
|
|
30
|
+
createCodeMode,
|
|
31
|
+
createVendorAgentTool,
|
|
32
|
+
createWorkflowTool,
|
|
33
|
+
defineAppResource,
|
|
34
|
+
extractAppResources,
|
|
35
|
+
handleChannelWebhook,
|
|
36
|
+
handleMcpStdioLine,
|
|
37
|
+
isChannelPath,
|
|
38
|
+
parseChannelPath,
|
|
39
|
+
readAppResource,
|
|
40
|
+
serveMcpStdio,
|
|
41
|
+
streamAgentTurnInProcess
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -24,10 +24,10 @@ import {
|
|
|
24
24
|
verifyOAuthState,
|
|
25
25
|
verifyTotp
|
|
26
26
|
} from "../../chunk-SJIRP73B.js";
|
|
27
|
+
import "../../chunk-ZJQ4O76G.js";
|
|
27
28
|
import {
|
|
28
29
|
generateNonce
|
|
29
30
|
} from "../../chunk-C3ZZ56YZ.js";
|
|
30
|
-
import "../../chunk-ZJQ4O76G.js";
|
|
31
31
|
import "../../chunk-DGUM43GV.js";
|
|
32
32
|
export {
|
|
33
33
|
AuthRequiredError,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { W as WebSocketHandler, b as WebSocketLike } from '../../define-websocket-CPQcQK9h.js';
|
|
3
3
|
export { a as WebSocketHandlerWeb } from '../../define-websocket-CPQcQK9h.js';
|
|
4
|
+
import { T as ToolTransform, C as CustomTool } from '../../define-agent-tool-ChaGymol.js';
|
|
5
|
+
export { D as DefineAgentToolSpec, a as applyTransform } from '../../define-agent-tool-ChaGymol.js';
|
|
4
6
|
import { f as OnRequestHook, i as PreHandlerHook, g as OnResponseHook, O as OnErrorHook, T as TheoPlugin } from '../../plugin-types-L49QYMb5.js';
|
|
5
7
|
import { UIMessageChunk } from 'ai';
|
|
6
8
|
import { IncomingMessage } from 'node:http';
|
|
@@ -95,91 +97,6 @@ interface ActionConfig<TInput extends z.ZodType, TCtx = unknown> {
|
|
|
95
97
|
|
|
96
98
|
type MiddlewareHandler = (request: Request, next: (request: Request) => Promise<Response>) => Response | Promise<Response>;
|
|
97
99
|
|
|
98
|
-
/**
|
|
99
|
-
* Item #4 — `defineAgentTool`
|
|
100
|
-
*
|
|
101
|
-
* Sugar over the `@theokit/sdk` `CustomTool` contract. Takes a Zod schema +
|
|
102
|
-
* handler and produces a structurally-compatible `CustomTool` that
|
|
103
|
-
* `Agent.create({ tools: [...] })` accepts.
|
|
104
|
-
*
|
|
105
|
-
* Uses Zod v4's native `z.toJSONSchema()` to convert the input schema to
|
|
106
|
-
* JSON Schema for LLM providers.
|
|
107
|
-
*
|
|
108
|
-
* Handler error propagation:
|
|
109
|
-
* `defineAgentTool` parses the input via the Zod schema BEFORE calling the
|
|
110
|
-
* user handler. Invalid input throws a `ZodError`, which the SDK's tool-
|
|
111
|
-
* dispatcher treats as a tool failure and surfaces to the model as a tool
|
|
112
|
-
* error (the SDK owns the wire; ADR D3).
|
|
113
|
-
*/
|
|
114
|
-
/**
|
|
115
|
-
* Local mirror of the SDK's `CustomTool` interface. We don't `import type`
|
|
116
|
-
* from `@theokit/sdk` because the SDK is an optional peer (consumers who
|
|
117
|
-
* never call `defineAgentTool` shouldn't need it installed). The shape is
|
|
118
|
-
* the wire contract; any structurally-matching object is accepted by
|
|
119
|
-
* `Agent.create({ tools })`.
|
|
120
|
-
*
|
|
121
|
-
* @public
|
|
122
|
-
*/
|
|
123
|
-
interface CustomTool {
|
|
124
|
-
name: string;
|
|
125
|
-
description: string;
|
|
126
|
-
inputSchema: Record<string, unknown>;
|
|
127
|
-
handler: (input: Record<string, unknown>, ctx?: {
|
|
128
|
-
signal?: AbortSignal;
|
|
129
|
-
context?: unknown;
|
|
130
|
-
}) => string | Promise<string>;
|
|
131
|
-
/** M18 — optional per-target formatters for the app's UI/transcript (ignored by the SDK wire). */
|
|
132
|
-
transform?: ToolTransform;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* M18 — per-target formatters. `display` shapes the rich handler result for the UI; `transcript`
|
|
136
|
-
* shapes it for a saved transcript. Applied by {@link applyTransform}, never by the model wire.
|
|
137
|
-
*/
|
|
138
|
-
interface ToolTransform<R = unknown> {
|
|
139
|
-
display?: (result: R) => unknown;
|
|
140
|
-
transcript?: (result: R) => unknown;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Spec accepted by {@link defineAgentTool}. `inputSchema` is a Zod 3 schema
|
|
144
|
-
* rooted in `z.object(...)`. The `handler` argument type is inferred via
|
|
145
|
-
* `z.infer<T>`.
|
|
146
|
-
*
|
|
147
|
-
* @public
|
|
148
|
-
*/
|
|
149
|
-
interface DefineAgentToolSpec<T extends z.ZodType, R = string> {
|
|
150
|
-
/** Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`. */
|
|
151
|
-
name: string;
|
|
152
|
-
/** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
|
|
153
|
-
description: string;
|
|
154
|
-
/** Zod schema describing the input. Must be `z.object(...)` at the root. */
|
|
155
|
-
inputSchema: T;
|
|
156
|
-
/**
|
|
157
|
-
* Handler invoked with the parsed input and, optionally, the run `ctx` (M7). `ctx.context`
|
|
158
|
-
* is the object supplied once at the agent level (`defineAgent({ context })`) or per-run —
|
|
159
|
-
* read it for shared config like `projectRoot` instead of baking it into the factory.
|
|
160
|
-
* `ctx.signal` is the abort signal. Optional so existing one-arg handlers keep working.
|
|
161
|
-
*
|
|
162
|
-
* M18 — the handler may return RICH data `R` (not just a string) when `toModelOutput` is
|
|
163
|
-
* provided to map it to the model-visible string.
|
|
164
|
-
*/
|
|
165
|
-
handler: (input: z.infer<T>, ctx?: {
|
|
166
|
-
signal?: AbortSignal;
|
|
167
|
-
context?: unknown;
|
|
168
|
-
}) => R | Promise<R>;
|
|
169
|
-
/**
|
|
170
|
-
* M18 — map the rich handler result `R` to the string the model sees. Required (in practice)
|
|
171
|
-
* when `handler` returns a non-string; absent ⇒ the handler must return a string.
|
|
172
|
-
*/
|
|
173
|
-
toModelOutput?: (result: R) => string;
|
|
174
|
-
/** M18 — per-target formatters (`display` / `transcript`) for the app, applied by {@link applyTransform}. */
|
|
175
|
-
transform?: ToolTransform<R>;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* M18 — apply a tool's `transform` for a target (`display` / `transcript`). Returns the formatted
|
|
179
|
-
* value, or the raw `result` when the tool declares no transform for that target.
|
|
180
|
-
*/
|
|
181
|
-
declare function applyTransform(tool: CustomTool, result: unknown, target: 'display' | 'transcript'): unknown;
|
|
182
|
-
|
|
183
100
|
/**
|
|
184
101
|
* M31 Phase 3 — `route()`, the fluent builder that replaces `defineRoute({...})`.
|
|
185
102
|
*
|
|
@@ -492,4 +409,4 @@ interface WebChannelHandler<TMessage = unknown> {
|
|
|
492
409
|
*/
|
|
493
410
|
declare function defineWebChannel<TMessage = unknown>(handler: WebChannelHandler<TMessage>): WebChannelHandler<TMessage>;
|
|
494
411
|
|
|
495
|
-
export { type ActionAccept, type ActionBuilder, type ActionConfig, type ChannelHandler,
|
|
412
|
+
export { type ActionAccept, type ActionBuilder, type ActionConfig, type ChannelHandler, CustomTool, type MiddlewareBuilder, type MiddlewareHandler, type PluginBuilder, type RouteBuilder, type RouteConfig, type ToolBuilder, ToolTransform, type WebChannelHandler, type WebSocketBuilder, WebSocketHandler, WebSocketLike, action, defineChannel, defineWebChannel, middleware, plugin, route, tool, uiMessageStreamResponse, websocket };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
action,
|
|
3
|
-
applyTransform,
|
|
4
3
|
defineChannel,
|
|
5
4
|
defineWebChannel,
|
|
6
5
|
middleware,
|
|
@@ -9,7 +8,7 @@ import {
|
|
|
9
8
|
tool,
|
|
10
9
|
uiMessageStreamResponse,
|
|
11
10
|
websocket
|
|
12
|
-
} from "../../chunk-
|
|
11
|
+
} from "../../chunk-V3X5FWJA.js";
|
|
13
12
|
import {
|
|
14
13
|
HEALTH_PATH,
|
|
15
14
|
READY_PATH,
|
|
@@ -17,6 +16,9 @@ import {
|
|
|
17
16
|
defineReadyRoute,
|
|
18
17
|
serveReservedRoute
|
|
19
18
|
} from "../../chunk-V3LJN2GS.js";
|
|
19
|
+
import {
|
|
20
|
+
applyTransform
|
|
21
|
+
} from "../../chunk-63BUBV5L.js";
|
|
20
22
|
import "../../chunk-DGUM43GV.js";
|
|
21
23
|
export {
|
|
22
24
|
HEALTH_PATH,
|