@theokit/sdk-tools 0.1.0 → 0.3.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/CHANGELOG.md +85 -0
- package/README.md +2 -0
- package/dist/index.cjs +634 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +362 -4
- package/dist/index.d.ts +362 -4
- package/dist/index.js +617 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomTool } from '@theokit/sdk';
|
|
1
|
+
import { CustomTool, ConfigurationError } from '@theokit/sdk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* `apply_patch` — built-in tool for coding agents.
|
|
@@ -18,6 +18,60 @@ interface CreateApplyPatchToolOptions {
|
|
|
18
18
|
}
|
|
19
19
|
declare function createApplyPatchTool(opts: CreateApplyPatchToolOptions): CustomTool;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link createSessionArtifactStore}.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
interface SessionArtifactStoreOptions {
|
|
27
|
+
/** Directory holding one file per artifact (`<dir>/<idStrategy(id)><extension>`). */
|
|
28
|
+
dir: string;
|
|
29
|
+
/**
|
|
30
|
+
* Map an opaque artifact id to a filesystem-safe filename stem.
|
|
31
|
+
* Default: `safeFilenameForId` (accepts ANY id; deterministically hashes
|
|
32
|
+
* non-conforming input). The result is additionally passed through
|
|
33
|
+
* `safePathJoin`, so a traversal id can never escape `dir`.
|
|
34
|
+
*
|
|
35
|
+
* NOTE — the default `safeFilenameForId` is CASE-FOLDING: ids differing only
|
|
36
|
+
* in case (`"Run-1"` vs `"run-1"`) map to the SAME file. If your ids are
|
|
37
|
+
* case-sensitive (e.g. base64), supply a case-preserving `idStrategy`.
|
|
38
|
+
*/
|
|
39
|
+
idStrategy?: (id: string) => string;
|
|
40
|
+
/** File extension (with leading dot). Default `".md"`. */
|
|
41
|
+
extension?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A generic, id-keyed, atomic artifact store. Generalizes the per-run
|
|
45
|
+
* session-summary writer pattern: persist an opaque text artifact under a
|
|
46
|
+
* stable id, read it back, and enumerate what's stored.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
interface SessionArtifactStore {
|
|
51
|
+
/**
|
|
52
|
+
* Write (overwrite) the artifact atomically; returns the resolved path.
|
|
53
|
+
* Content is persisted byte-for-byte. The id is mapped via `idStrategy`
|
|
54
|
+
* (default case-folding — see {@link SessionArtifactStoreOptions.idStrategy}).
|
|
55
|
+
*/
|
|
56
|
+
write(id: string, content: string): Promise<string>;
|
|
57
|
+
/** Read the artifact, or `undefined` if absent/unreadable (never throws). */
|
|
58
|
+
read(id: string): Promise<string | undefined>;
|
|
59
|
+
/** Whether an artifact exists for `id` (never throws). */
|
|
60
|
+
has(id: string): Promise<boolean>;
|
|
61
|
+
/** The filename stems of all stored artifacts (never throws; `[]` if dir absent). */
|
|
62
|
+
list(): Promise<string[]>;
|
|
63
|
+
/** The resolved, traversal-safe path for `id`. */
|
|
64
|
+
path(id: string): string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a generic artifact store rooted at `dir`. Composes the shipped
|
|
68
|
+
* `safeFilenameForId`/`safePathJoin` path guard + the atomic `replaceFileAtomic`
|
|
69
|
+
* writer — zero new dependencies. Reads never throw; writes fail loud.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
declare function createSessionArtifactStore(options: SessionArtifactStoreOptions): SessionArtifactStore;
|
|
74
|
+
|
|
21
75
|
/**
|
|
22
76
|
* `edit_file` — built-in tool for coding agents.
|
|
23
77
|
*
|
|
@@ -88,8 +142,8 @@ declare function createGitDiffTool(opts: CreateGitDiffToolOptions): CustomTool;
|
|
|
88
142
|
* .git, and dist by default. Returns relative paths.
|
|
89
143
|
*
|
|
90
144
|
* Return shape (always a JSON string):
|
|
91
|
-
* - `{ ok: true, files: string[] }`
|
|
92
|
-
* - `{ ok: false, error: 'path_traversal'
|
|
145
|
+
* - `{ ok: true, files: string[], count }` (an empty match is `ok: true` with `files: []`)
|
|
146
|
+
* - `{ ok: false, error: 'path_traversal' }`
|
|
93
147
|
*/
|
|
94
148
|
|
|
95
149
|
interface CreateGlobToolOptions {
|
|
@@ -98,6 +152,216 @@ interface CreateGlobToolOptions {
|
|
|
98
152
|
}
|
|
99
153
|
declare function createGlobTool(opts: CreateGlobToolOptions): CustomTool;
|
|
100
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Composable command-permission policy layer (M3-6).
|
|
157
|
+
*
|
|
158
|
+
* A `CommandPolicy` is a pure predicate returning a deny REASON (or `null` to
|
|
159
|
+
* allow). `denyCatastrophicCommands()` COMPOSES the M3-2 `catastrophicShellReason`
|
|
160
|
+
* guardrail (it does not duplicate the deny-list). `commandDenialReason` combines
|
|
161
|
+
* a policy array with deny-wins semantics (the first policy returning a reason
|
|
162
|
+
* denies); an empty array denies nothing. `isCommandAllowed` is the boolean view.
|
|
163
|
+
*
|
|
164
|
+
* Framework-agnostic: a consumer wires it at their permission layer — e.g. inside
|
|
165
|
+
* an ACP `pre_tool_call` hook — `@theokit/agents` is not required. Inherits the
|
|
166
|
+
* M3-2 honesty: a heuristic gate, not a sandbox. Design: blueprint m3-command-policy.
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* A pure command-permission predicate: returns a non-empty deny reason, or `null`
|
|
170
|
+
* to allow. NOTE: return `null` to allow — NOT `""`. An empty string is treated
|
|
171
|
+
* as a deny with a blank reason (`"" !== null`), which is almost never intended.
|
|
172
|
+
*/
|
|
173
|
+
type CommandPolicy = (command: string) => string | null;
|
|
174
|
+
/** A policy that denies catastrophic commands by composing the M3-2 guardrail. */
|
|
175
|
+
declare function denyCatastrophicCommands(): CommandPolicy;
|
|
176
|
+
/**
|
|
177
|
+
* The first deny reason across `policies` (deny-wins), or `null` if every policy
|
|
178
|
+
* allows. An empty `policies` array denies nothing (returns `null`).
|
|
179
|
+
*/
|
|
180
|
+
declare function commandDenialReason(command: string, policies: CommandPolicy[]): string | null;
|
|
181
|
+
/** `true` when no policy denies `command` (an empty policy array allows everything). */
|
|
182
|
+
declare function isCommandAllowed(command: string, policies: CommandPolicy[]): boolean;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* SSRF guard for network tools (M3-1).
|
|
186
|
+
*
|
|
187
|
+
* `isBlockedIp` is a pure block-list of the canonical private/loopback/link-local/
|
|
188
|
+
* CGNAT/metadata/reserved ranges (IPv4 + IPv6, with IPv4-mapped unwrap).
|
|
189
|
+
* `resolveAndScreen` resolves ALL of a host's addresses and rejects if any is
|
|
190
|
+
* blocked. `screenedFetch` fetches with `redirect:"manual"` and re-screens every
|
|
191
|
+
* hop. `lookup`/`fetchImpl` are injectable so the DNS + redirect paths are
|
|
192
|
+
* deterministically testable without real network access.
|
|
193
|
+
*
|
|
194
|
+
* Design: blueprint m3-ssrf-guard ADRs D1-D6. Node builtins only (zero new deps).
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/** Thrown when a host/redirect resolves to a blocked (private/reserved) address. */
|
|
198
|
+
declare class SsrfBlockedError extends ConfigurationError {
|
|
199
|
+
readonly name = "SsrfBlockedError";
|
|
200
|
+
constructor(host: string, detail?: string);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* True if `ip` is a blocked address (private/loopback/link-local/CGNAT/metadata/
|
|
204
|
+
* reserved). A non-IP literal returns `true` (fail closed — callers resolve names
|
|
205
|
+
* to IPs first via {@link resolveAndScreen}).
|
|
206
|
+
*/
|
|
207
|
+
declare function isBlockedIp(ip: string): boolean;
|
|
208
|
+
type LookupFn = (host: string, opts: {
|
|
209
|
+
all: true;
|
|
210
|
+
}) => Promise<Array<{
|
|
211
|
+
address: string;
|
|
212
|
+
}>>;
|
|
213
|
+
/** Options for {@link resolveAndScreen}. */
|
|
214
|
+
interface ResolveAndScreenOptions {
|
|
215
|
+
/** DNS resolver (injectable for tests); defaults to `node:dns/promises` lookup. */
|
|
216
|
+
lookup?: LookupFn;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Resolve `host` to ALL its addresses and screen each. Throws {@link SsrfBlockedError}
|
|
220
|
+
* if any resolved address is blocked (or if `host` is a blocked IP literal, or if
|
|
221
|
+
* resolution yields no address). Returns the resolved IPs otherwise.
|
|
222
|
+
*/
|
|
223
|
+
declare function resolveAndScreen(rawHost: string, options?: ResolveAndScreenOptions): Promise<string[]>;
|
|
224
|
+
type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
|
|
225
|
+
/** Options for {@link screenedFetch}. */
|
|
226
|
+
interface ScreenedFetchOptions {
|
|
227
|
+
/** Fetch implementation (injectable for tests); defaults to global `fetch`. */
|
|
228
|
+
fetchImpl?: FetchFn;
|
|
229
|
+
/** DNS resolver (injectable for tests). */
|
|
230
|
+
lookup?: LookupFn;
|
|
231
|
+
/** Max redirect hops to follow (default 5). */
|
|
232
|
+
maxRedirects?: number;
|
|
233
|
+
/** Skip SSRF screening entirely (opt-out for local-dev tools). Default false. */
|
|
234
|
+
allowPrivateHosts?: boolean;
|
|
235
|
+
/** Abort signal forwarded to fetch. */
|
|
236
|
+
signal?: AbortSignal;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Fetch `url` with SSRF screening: screens the host (unless `allowPrivateHosts`),
|
|
240
|
+
* sets `redirect:"manual"`, and re-screens every redirect hop (rejecting a hop to a
|
|
241
|
+
* blocked host or a non-http(s) target). Throws {@link SsrfBlockedError} on a block
|
|
242
|
+
* or on exceeding `maxRedirects`.
|
|
243
|
+
*/
|
|
244
|
+
declare function screenedFetch(url: string, options?: ScreenedFetchOptions): Promise<Response>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Repo-map / env-context builders for orienting an LLM coding agent (M3-3).
|
|
248
|
+
*
|
|
249
|
+
* `buildEnvContext(cwd)` renders a short `<env>` block (cwd, platform, node,
|
|
250
|
+
* is-git, date, project docs, manifests). `buildRepoMap(cwd, opts)` renders a
|
|
251
|
+
* char-bounded, depth-limited directory tree. Both are node:fs-only and NEVER
|
|
252
|
+
* throw — a missing/unreadable path yields a best-effort partial string or an
|
|
253
|
+
* `(unavailable)` marker (distinct from the M3-1/M3-2 guards, which throw).
|
|
254
|
+
*
|
|
255
|
+
* Design: blueprint m3-repo-map. Zero new dependencies. A best-effort
|
|
256
|
+
* orientation aid, not a complete or secure listing (bounded + skips on error).
|
|
257
|
+
*/
|
|
258
|
+
interface RepoMapOptions {
|
|
259
|
+
/** Max characters of tree output before truncation. Default 8000. */
|
|
260
|
+
budget?: number;
|
|
261
|
+
/** Directory/file names to skip (merged with the built-in ignore set). */
|
|
262
|
+
ignore?: string[];
|
|
263
|
+
/** Max directory depth to descend. Default 4. */
|
|
264
|
+
maxDepth?: number;
|
|
265
|
+
}
|
|
266
|
+
/** Render a portable `<env>` orientation block. Never throws. */
|
|
267
|
+
declare function buildEnvContext(cwd: string): string;
|
|
268
|
+
/** Render a char-bounded, depth-limited directory tree. Never throws. */
|
|
269
|
+
declare function buildRepoMap(cwd: string, opts?: RepoMapOptions): string;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Catastrophic-command guardrail for `shell_exec` (M3-2; hardened V3-1).
|
|
273
|
+
*
|
|
274
|
+
* `catastrophicShellReason` is a pure, segment-aware deny-list ported from
|
|
275
|
+
* theocode's security-reviewed `shell-guard.ts` (the proven spec: 42-blocked +
|
|
276
|
+
* 24-allowed corpus, 0 misses / 0 false-positives). It splits a command on shell
|
|
277
|
+
* separators (`;`, `&&`, `||`, `|`, `&`, newline), inspects EVERY segment (so a
|
|
278
|
+
* chained `rm -rf <safe>; rm -rf /` cannot hide), and matches at COMMAND POSITION
|
|
279
|
+
* (the executable, not an arbitrary substring) so a mention like `echo "rm -rf /"`
|
|
280
|
+
* is not over-blocked. Returns a human reason for the first catastrophic segment,
|
|
281
|
+
* else `null`.
|
|
282
|
+
*
|
|
283
|
+
* Categories: recursive-force `rm` of an absolute/home/parent path; destructive git
|
|
284
|
+
* (force-push, `reset --hard`, `clean -fd`); remote-code-execution (curl/wget piped
|
|
285
|
+
* OR command-substitution `$( )` / `<( )` / eval / source); disk/raw-device wipe
|
|
286
|
+
* (mkfs, `dd of=/dev/`, `truncate /dev/`, `> /dev/<blockdev>`); recursive chmod/chown
|
|
287
|
+
* of a root path (SDK extra); fork bomb; `find -delete` / `-exec rm`; secret-file
|
|
288
|
+
* exfiltration over the network.
|
|
289
|
+
*
|
|
290
|
+
* This is a heuristic GUARDRAIL, NOT a sandbox: it is bypassable by deep obfuscation
|
|
291
|
+
* (base64/env-indirection) and is best-effort. POSIX `/bin/sh` only; Windows
|
|
292
|
+
* PowerShell is out of scope. True isolation needs a container.
|
|
293
|
+
* referencia: .claude/knowledge-base/references/theocode-shell-guard/server-lib/shell-guard.ts
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
/** Thrown / reported when a command matches the catastrophic deny-list. */
|
|
297
|
+
declare class CatastrophicCommandError extends ConfigurationError {
|
|
298
|
+
readonly name = "CatastrophicCommandError";
|
|
299
|
+
constructor(reason: string);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Return a human-readable reason when `command` is catastrophic/irreversible, or `null`.
|
|
303
|
+
* The message is surfaced to the model so it self-corrects.
|
|
304
|
+
*/
|
|
305
|
+
declare function catastrophicShellReason(command: string): string | null;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* ACI (Agent-Computer Interface) helpers for tools (M3-5).
|
|
309
|
+
*
|
|
310
|
+
* `withDescription(tool, description)` immutably overrides a tool's LLM-facing
|
|
311
|
+
* description (the wording that drives tool-selection accuracy) — returning a
|
|
312
|
+
* NEW `CustomTool` and leaving the original untouched. `renderToolList(tools)`
|
|
313
|
+
* renders a `<tools>` block FROM THE SAME `CustomTool[]` the agent runs, so the
|
|
314
|
+
* rendered list cannot drift from the real tools (single source of truth).
|
|
315
|
+
*
|
|
316
|
+
* Both are pure, zero-dependency, and never throw. The `<tools>` block is a
|
|
317
|
+
* system-prompt orientation aid — NOT the provider tool-call schema (that stays
|
|
318
|
+
* each tool's `inputSchema`). Design: blueprint m3-aci-tools.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Return a new `CustomTool` with `description` replaced. Preserves
|
|
323
|
+
* name/inputSchema/handler; does NOT mutate the original tool.
|
|
324
|
+
*/
|
|
325
|
+
declare function withDescription(tool: CustomTool, description: string): CustomTool;
|
|
326
|
+
/**
|
|
327
|
+
* Render a `<tools>` block (name + description per tool) from the agent's actual
|
|
328
|
+
* `CustomTool[]` — single source of truth, so an overridden/added/removed tool
|
|
329
|
+
* is reflected automatically. An empty array yields `<tools></tools>`. Never throws.
|
|
330
|
+
*/
|
|
331
|
+
declare function renderToolList(tools: CustomTool[]): string;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Rich-error guidance for tool failures (M3-4).
|
|
335
|
+
*
|
|
336
|
+
* `withToolResultGuidance(tool, guidance)` wraps a `CustomTool` so a failing
|
|
337
|
+
* `{ ok: false, error }` JSON result gains an LLM-actionable `guidance` string
|
|
338
|
+
* telling the model how to self-correct. The injection is ADDITIVE (only on
|
|
339
|
+
* `ok:false`), IDEMPOTENT (never overwrites an existing `guidance`), and
|
|
340
|
+
* NEVER-THROW (a non-JSON / non-object / `ok:true` / unknown-code result is
|
|
341
|
+
* returned unchanged). Composes over the existing built-in tools (and custom
|
|
342
|
+
* tools) — no factory edits required.
|
|
343
|
+
*
|
|
344
|
+
* Design: blueprint m3-rich-errors. Zero new dependencies (JSON transform).
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
/** Maps a tool error code to a short, LLM-actionable self-correction hint. */
|
|
348
|
+
type ToolGuidanceMap = Record<string, string>;
|
|
349
|
+
/** Curated hints for the common cross-tool error codes. Consumers may extend. */
|
|
350
|
+
declare const DEFAULT_TOOL_GUIDANCE: ToolGuidanceMap;
|
|
351
|
+
/**
|
|
352
|
+
* Pure: parse a tool handler's JSON output and ADD a `guidance` hint when the
|
|
353
|
+
* result is an `{ ok: false, error }` object whose code has a hint and that does
|
|
354
|
+
* not already carry guidance. Any other input is returned UNCHANGED (never throws).
|
|
355
|
+
*/
|
|
356
|
+
declare function injectGuidance(handlerOutput: string, guidance: ToolGuidanceMap): string;
|
|
357
|
+
/**
|
|
358
|
+
* Wrap a `CustomTool` so its failed results gain a `guidance` hint from `guidance`.
|
|
359
|
+
* Preserves name/description/inputSchema; only the handler output is augmented.
|
|
360
|
+
*/
|
|
361
|
+
declare function withToolResultGuidance(tool: CustomTool, guidance: ToolGuidanceMap): CustomTool;
|
|
362
|
+
/** `withToolResultGuidance` pre-bound to {@link DEFAULT_TOOL_GUIDANCE}. */
|
|
363
|
+
declare function withDefaultGuidance(tool: CustomTool): CustomTool;
|
|
364
|
+
|
|
101
365
|
/**
|
|
102
366
|
* `list_dir` — built-in tool for coding agents.
|
|
103
367
|
*
|
|
@@ -133,7 +397,11 @@ declare function createListDirTool(opts: CreateListDirToolOptions): CustomTool;
|
|
|
133
397
|
* Return shape (always a JSON string):
|
|
134
398
|
* - `{ ok: true, mode: string, message: string }`
|
|
135
399
|
* - `{ ok: false, error: "invalid_action" }`
|
|
400
|
+
*
|
|
401
|
+
* Opt-in persistence (M4-4): `createPlanModeTool({ artifactStore })` returns a
|
|
402
|
+
* variant whose async handler persists the submitted `plan` on `exit`.
|
|
136
403
|
*/
|
|
404
|
+
|
|
137
405
|
type Mode = "normal" | "plan";
|
|
138
406
|
interface PlanModeTool {
|
|
139
407
|
name: string;
|
|
@@ -145,7 +413,36 @@ interface PlanModeTool {
|
|
|
145
413
|
/** Expose current mode for testing. */
|
|
146
414
|
currentMode: () => Mode;
|
|
147
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Plan-mode tool with opt-in artifact persistence (M4-4). Same surface as
|
|
418
|
+
* {@link PlanModeTool} but the handler is ASYNC (it may write to the store) and
|
|
419
|
+
* accepts an optional `plan` to persist on `exit`.
|
|
420
|
+
*
|
|
421
|
+
* @public
|
|
422
|
+
*/
|
|
423
|
+
interface PlanModeToolWithStore {
|
|
424
|
+
name: string;
|
|
425
|
+
description: string;
|
|
426
|
+
inputSchema: unknown;
|
|
427
|
+
handler: (input: {
|
|
428
|
+
action: string;
|
|
429
|
+
plan?: string;
|
|
430
|
+
}) => Promise<string>;
|
|
431
|
+
currentMode: () => Mode;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Options for the persistence-enabled {@link createPlanModeTool} overload.
|
|
435
|
+
*
|
|
436
|
+
* @public
|
|
437
|
+
*/
|
|
438
|
+
interface PlanModeToolOptions {
|
|
439
|
+
/** Store the submitted `plan` is persisted to on `exit`. */
|
|
440
|
+
artifactStore: SessionArtifactStore;
|
|
441
|
+
/** Artifact id under which the plan is stored. Default `"plan"`. */
|
|
442
|
+
artifactId?: string;
|
|
443
|
+
}
|
|
148
444
|
declare function createPlanModeTool(): PlanModeTool;
|
|
445
|
+
declare function createPlanModeTool(options: PlanModeToolOptions): PlanModeToolWithStore;
|
|
149
446
|
|
|
150
447
|
/**
|
|
151
448
|
* `question` — interactive tool that asks the user a question and waits for a response.
|
|
@@ -289,6 +586,13 @@ interface CreateShellToolOptions {
|
|
|
289
586
|
projectRoot: string;
|
|
290
587
|
/** Default timeout in ms. Capped at 300s. */
|
|
291
588
|
defaultTimeoutMs?: number;
|
|
589
|
+
/**
|
|
590
|
+
* Opt out of the catastrophic-command guardrail. Default `false` (the
|
|
591
|
+
* guardrail screens every command before spawn). Set `true` only when the
|
|
592
|
+
* agent legitimately needs destructive power flows — it is a heuristic
|
|
593
|
+
* guardrail, not a sandbox.
|
|
594
|
+
*/
|
|
595
|
+
allowCatastrophic?: boolean;
|
|
292
596
|
}
|
|
293
597
|
declare function createShellTool(opts: CreateShellToolOptions): CustomTool;
|
|
294
598
|
|
|
@@ -339,6 +643,27 @@ type TodoInput = {
|
|
|
339
643
|
};
|
|
340
644
|
declare function createTodolistTool(): TodolistTool;
|
|
341
645
|
|
|
646
|
+
/**
|
|
647
|
+
* A flat plan-render node — the stable shape a UI/plan layer consumes. Mirrors
|
|
648
|
+
* the `TodoItem` status union; `label` is the item title.
|
|
649
|
+
*
|
|
650
|
+
* @public
|
|
651
|
+
*/
|
|
652
|
+
interface PlanNode {
|
|
653
|
+
id: string;
|
|
654
|
+
label: string;
|
|
655
|
+
status: "pending" | "in_progress" | "done";
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Convert structured todo items (from a `todolist` tool result's `items`, M4-5)
|
|
659
|
+
* into versioned `PlanNode`s for rendering. Pure: projects EXACTLY
|
|
660
|
+
* `{ id, label, status }` (timestamps are intentionally dropped), preserving
|
|
661
|
+
* input order. Replaces consumer-side hand-rolled mappers.
|
|
662
|
+
*
|
|
663
|
+
* @public
|
|
664
|
+
*/
|
|
665
|
+
declare function todoItemsToPlanNodes(items: readonly TodoItem[]): PlanNode[];
|
|
666
|
+
|
|
342
667
|
/**
|
|
343
668
|
* `truncateOutput` — utility for truncating large tool output.
|
|
344
669
|
*
|
|
@@ -380,6 +705,12 @@ declare function truncateOutput(output: string, opts?: TruncationOptions): Trunc
|
|
|
380
705
|
interface CreateWebFetchToolOptions {
|
|
381
706
|
/** Default timeout in ms. */
|
|
382
707
|
defaultTimeoutMs?: number;
|
|
708
|
+
/**
|
|
709
|
+
* Opt out of the SSRF guard (default `false`). When `true`, requests to
|
|
710
|
+
* private/loopback/link-local/metadata addresses are NOT blocked — use only for
|
|
711
|
+
* trusted local-dev tooling.
|
|
712
|
+
*/
|
|
713
|
+
allowPrivateHosts?: boolean;
|
|
383
714
|
}
|
|
384
715
|
declare function createWebFetchTool(opts?: CreateWebFetchToolOptions): CustomTool;
|
|
385
716
|
|
|
@@ -408,6 +739,33 @@ interface CreateWebSearchToolOptions {
|
|
|
408
739
|
}
|
|
409
740
|
declare function createWebSearchTool(opts: CreateWebSearchToolOptions): CustomTool;
|
|
410
741
|
|
|
742
|
+
/**
|
|
743
|
+
* Brave Search adapter for `createWebSearchTool` (M3-7).
|
|
744
|
+
*
|
|
745
|
+
* `createBraveWebSearchAdapter()` returns a `WebSearchCallback` that queries the
|
|
746
|
+
* Brave Search API using an env-driven key (`BRAVE_API_KEY`). It plugs into the
|
|
747
|
+
* provider-agnostic `createWebSearchTool` via its callback seam — the tool is NOT
|
|
748
|
+
* modified. The `fetch` impl is injectable (default `globalThis.fetch`) so the
|
|
749
|
+
* adapter is offline-testable; a plain fetch (not `screenedFetch`) is used because
|
|
750
|
+
* the endpoint host is fixed (no SSRF surface) and `screenedFetch` cannot carry
|
|
751
|
+
* the required auth header. Zero new dependencies. Design: blueprint m3-websearch-adapter.
|
|
752
|
+
*/
|
|
753
|
+
|
|
754
|
+
type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
|
|
755
|
+
interface CreateBraveWebSearchAdapterOptions {
|
|
756
|
+
/** Brave API key. Defaults to `process.env.BRAVE_API_KEY`. */
|
|
757
|
+
apiKey?: string;
|
|
758
|
+
/** Injectable fetch (default `globalThis.fetch`) — set in tests for offline runs. */
|
|
759
|
+
fetchImpl?: FetchLike;
|
|
760
|
+
/** Override the Brave endpoint (self-host / test). */
|
|
761
|
+
endpoint?: string;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Build a `WebSearchCallback` backed by the Brave Search API. Throws a typed
|
|
765
|
+
* `ConfigurationError` ("no_api_key") at creation when no key is available.
|
|
766
|
+
*/
|
|
767
|
+
declare function createBraveWebSearchAdapter(opts?: CreateBraveWebSearchAdapterOptions): WebSearchCallback;
|
|
768
|
+
|
|
411
769
|
/**
|
|
412
770
|
* `write_file` — built-in tool for coding agents.
|
|
413
771
|
*
|
|
@@ -427,4 +785,4 @@ interface CreateWriteFileToolOptions {
|
|
|
427
785
|
}
|
|
428
786
|
declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
|
|
429
787
|
|
|
430
|
-
export { type CreateApplyPatchToolOptions, type CreateEditFileToolOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, type PlanModeTool, type QuestionTool, type QuestionToolOptions, type TodoItem, type TodolistTool, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, createApplyPatchTool, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, formatCode, formatDiff, formatError, formatFileList, truncateOutput };
|
|
788
|
+
export { CatastrophicCommandError, type CommandPolicy, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGitDiffTool, createGlobTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withToolResultGuidance };
|