@theokit/sdk-tools 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -199,6 +199,15 @@ declare class SsrfBlockedError extends ConfigurationError {
199
199
  readonly name = "SsrfBlockedError";
200
200
  constructor(host: string, detail?: string);
201
201
  }
202
+ /**
203
+ * Thrown when a request is refused by the REDIRECT policy (the `maxRedirects` hop limit was
204
+ * exceeded) — a distinct event from {@link SsrfBlockedError} (a blocked host). With `maxRedirects: 0`
205
+ * this fires on the first 3xx (block-all-redirects). Carries `code: "redirect_blocked"`.
206
+ */
207
+ declare class RedirectBlockedError extends ConfigurationError {
208
+ readonly name = "RedirectBlockedError";
209
+ constructor(url: string, detail?: string);
210
+ }
202
211
  /**
203
212
  * True if `ip` is a blocked address (private/loopback/link-local/CGNAT/metadata/
204
213
  * reserved). A non-IP literal returns `true` (fail closed — callers resolve names
@@ -323,12 +332,26 @@ declare function catastrophicShellReason(command: string): string | null;
323
332
  * name/inputSchema/handler; does NOT mutate the original tool.
324
333
  */
325
334
  declare function withDescription(tool: CustomTool, description: string): CustomTool;
335
+ /** Render mode for {@link renderToolList}. Local — the published `renderToolList`
336
+ * signature inlines this union into its `.d.ts`, so consumers pass the literal
337
+ * ("summary" | "names" | "full") without needing the named type exported. */
338
+ type ToolListMode = "full" | "summary" | "names";
326
339
  /**
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.
340
+ * Render the agent's actual `CustomTool[]` single source of truth, so an
341
+ * overridden/added/removed tool is reflected automatically. Never throws.
342
+ *
343
+ * Modes (`options.mode`, default `"full"`):
344
+ * - `"full"`: a `<tools>` XML block (name + description per tool, XML-escaped).
345
+ * An empty array yields `<tools></tools>`.
346
+ * - `"summary"`: markdown `- name: <first sentence>` per tool (NOT XML-escaped).
347
+ * - `"names"`: markdown `- name` per tool (NOT XML-escaped).
348
+ *
349
+ * Markdown modes on an empty array yield `""`. A non-object `options` arg (e.g. a
350
+ * map index from `tools.map(renderToolList)`) has no `.mode` → falls back to `"full"`.
330
351
  */
331
- declare function renderToolList(tools: CustomTool[]): string;
352
+ declare function renderToolList(tools: CustomTool[], options?: {
353
+ mode?: ToolListMode;
354
+ }): string;
332
355
 
333
356
  /**
334
357
  * Rich-error guidance for tool failures (M3-4).
@@ -707,7 +730,7 @@ declare function truncateOutput(output: string, opts?: TruncationOptions): Trunc
707
730
  * Return shape (always a JSON string):
708
731
  * - `{ ok: true, content, status_code, content_type }`
709
732
  * - `{ ok: false, error: 'invalid_url' | 'fetch_failed' |
710
- * 'timeout' | 'too_large' }`
733
+ * 'timeout' | 'too_large' | 'ssrf_blocked' | 'redirect_blocked' }`
711
734
  */
712
735
 
713
736
  interface CreateWebFetchToolOptions {
@@ -719,6 +742,16 @@ interface CreateWebFetchToolOptions {
719
742
  * trusted local-dev tooling.
720
743
  */
721
744
  allowPrivateHosts?: boolean;
745
+ /**
746
+ * Max redirect hops to follow (each SSRF-screened). Default 5. Set `0` to BLOCK ALL
747
+ * redirects — a 3xx then returns `{ ok: false, error: "redirect_blocked" }` (a strict
748
+ * no-redirect policy for untrusted, model-chosen URLs).
749
+ */
750
+ maxRedirects?: number;
751
+ /** Fetch implementation (injectable for tests — drive paths with no real network). */
752
+ fetchImpl?: ScreenedFetchOptions["fetchImpl"];
753
+ /** DNS resolver (injectable for tests — drive the SSRF path with no real DNS). */
754
+ lookup?: ScreenedFetchOptions["lookup"];
722
755
  }
723
756
  declare function createWebFetchTool(opts?: CreateWebFetchToolOptions): CustomTool;
724
757
 
@@ -793,4 +826,4 @@ interface CreateWriteFileToolOptions {
793
826
  }
794
827
  declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
795
828
 
796
- 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, withShellExitGuidance, withToolResultGuidance };
829
+ 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, RedirectBlockedError, 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, withShellExitGuidance, withToolResultGuidance };
package/dist/index.d.ts CHANGED
@@ -199,6 +199,15 @@ declare class SsrfBlockedError extends ConfigurationError {
199
199
  readonly name = "SsrfBlockedError";
200
200
  constructor(host: string, detail?: string);
201
201
  }
202
+ /**
203
+ * Thrown when a request is refused by the REDIRECT policy (the `maxRedirects` hop limit was
204
+ * exceeded) — a distinct event from {@link SsrfBlockedError} (a blocked host). With `maxRedirects: 0`
205
+ * this fires on the first 3xx (block-all-redirects). Carries `code: "redirect_blocked"`.
206
+ */
207
+ declare class RedirectBlockedError extends ConfigurationError {
208
+ readonly name = "RedirectBlockedError";
209
+ constructor(url: string, detail?: string);
210
+ }
202
211
  /**
203
212
  * True if `ip` is a blocked address (private/loopback/link-local/CGNAT/metadata/
204
213
  * reserved). A non-IP literal returns `true` (fail closed — callers resolve names
@@ -323,12 +332,26 @@ declare function catastrophicShellReason(command: string): string | null;
323
332
  * name/inputSchema/handler; does NOT mutate the original tool.
324
333
  */
325
334
  declare function withDescription(tool: CustomTool, description: string): CustomTool;
335
+ /** Render mode for {@link renderToolList}. Local — the published `renderToolList`
336
+ * signature inlines this union into its `.d.ts`, so consumers pass the literal
337
+ * ("summary" | "names" | "full") without needing the named type exported. */
338
+ type ToolListMode = "full" | "summary" | "names";
326
339
  /**
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.
340
+ * Render the agent's actual `CustomTool[]` single source of truth, so an
341
+ * overridden/added/removed tool is reflected automatically. Never throws.
342
+ *
343
+ * Modes (`options.mode`, default `"full"`):
344
+ * - `"full"`: a `<tools>` XML block (name + description per tool, XML-escaped).
345
+ * An empty array yields `<tools></tools>`.
346
+ * - `"summary"`: markdown `- name: <first sentence>` per tool (NOT XML-escaped).
347
+ * - `"names"`: markdown `- name` per tool (NOT XML-escaped).
348
+ *
349
+ * Markdown modes on an empty array yield `""`. A non-object `options` arg (e.g. a
350
+ * map index from `tools.map(renderToolList)`) has no `.mode` → falls back to `"full"`.
330
351
  */
331
- declare function renderToolList(tools: CustomTool[]): string;
352
+ declare function renderToolList(tools: CustomTool[], options?: {
353
+ mode?: ToolListMode;
354
+ }): string;
332
355
 
333
356
  /**
334
357
  * Rich-error guidance for tool failures (M3-4).
@@ -707,7 +730,7 @@ declare function truncateOutput(output: string, opts?: TruncationOptions): Trunc
707
730
  * Return shape (always a JSON string):
708
731
  * - `{ ok: true, content, status_code, content_type }`
709
732
  * - `{ ok: false, error: 'invalid_url' | 'fetch_failed' |
710
- * 'timeout' | 'too_large' }`
733
+ * 'timeout' | 'too_large' | 'ssrf_blocked' | 'redirect_blocked' }`
711
734
  */
712
735
 
713
736
  interface CreateWebFetchToolOptions {
@@ -719,6 +742,16 @@ interface CreateWebFetchToolOptions {
719
742
  * trusted local-dev tooling.
720
743
  */
721
744
  allowPrivateHosts?: boolean;
745
+ /**
746
+ * Max redirect hops to follow (each SSRF-screened). Default 5. Set `0` to BLOCK ALL
747
+ * redirects — a 3xx then returns `{ ok: false, error: "redirect_blocked" }` (a strict
748
+ * no-redirect policy for untrusted, model-chosen URLs).
749
+ */
750
+ maxRedirects?: number;
751
+ /** Fetch implementation (injectable for tests — drive paths with no real network). */
752
+ fetchImpl?: ScreenedFetchOptions["fetchImpl"];
753
+ /** DNS resolver (injectable for tests — drive the SSRF path with no real DNS). */
754
+ lookup?: ScreenedFetchOptions["lookup"];
722
755
  }
723
756
  declare function createWebFetchTool(opts?: CreateWebFetchToolOptions): CustomTool;
724
757
 
@@ -793,4 +826,4 @@ interface CreateWriteFileToolOptions {
793
826
  }
794
827
  declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
795
828
 
796
- 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, withShellExitGuidance, withToolResultGuidance };
829
+ 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, RedirectBlockedError, 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, withShellExitGuidance, withToolResultGuidance };
package/dist/index.js CHANGED
@@ -719,6 +719,15 @@ var SsrfBlockedError = class extends ConfigurationError {
719
719
  );
720
720
  }
721
721
  };
722
+ var RedirectBlockedError = class extends ConfigurationError {
723
+ name = "RedirectBlockedError";
724
+ constructor(url, detail) {
725
+ super(
726
+ `Blocked redirect for "${url}"${detail ? ` (${detail})` : ""}: redirect-hop limit exceeded (redirect policy).`,
727
+ { code: "redirect_blocked" }
728
+ );
729
+ }
730
+ };
722
731
  function v4ToInt(ip) {
723
732
  const parts = ip.split(".");
724
733
  return (Number(parts[0]) << 24 | Number(parts[1]) << 16 | Number(parts[2]) << 8 | Number(parts[3])) >>> 0;
@@ -842,7 +851,7 @@ async function screenedFetch(url, options = {}) {
842
851
  if (next === void 0) return res;
843
852
  current = next;
844
853
  }
845
- throw new SsrfBlockedError(url, "too many redirects");
854
+ throw new RedirectBlockedError(url, "too many redirects");
846
855
  }
847
856
  var DEFAULT_BUDGET = 8e3;
848
857
  var DEFAULT_MAX_DEPTH = 4;
@@ -970,7 +979,18 @@ function withDescription(tool, description) {
970
979
  function esc(s) {
971
980
  return String(s).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
972
981
  }
973
- function renderToolList(tools) {
982
+ function firstSentence(d) {
983
+ const m = d.trim().match(/\.\s+(?=[A-Z(]|$)/);
984
+ return m?.index == null ? d.trim() : d.trim().slice(0, m.index + 1);
985
+ }
986
+ function renderToolList(tools, options) {
987
+ const mode = options?.mode ?? "full";
988
+ if (mode === "summary") {
989
+ return tools.map((t) => `- ${t.name}: ${firstSentence(t.description)}`).join("\n");
990
+ }
991
+ if (mode === "names") {
992
+ return tools.map((t) => `- ${t.name}`).join("\n");
993
+ }
974
994
  if (tools.length === 0) return "<tools></tools>";
975
995
  const lines = ["<tools>"];
976
996
  for (const t of tools) {
@@ -1767,6 +1787,9 @@ var MAX_BODY_BYTES = 1 * 1024 * 1024;
1767
1787
  function createWebFetchTool(opts) {
1768
1788
  const defaultTimeoutMs = opts?.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS4;
1769
1789
  const allowPrivateHosts = opts?.allowPrivateHosts ?? false;
1790
+ const maxRedirects = opts?.maxRedirects;
1791
+ const fetchImpl = opts?.fetchImpl;
1792
+ const lookup = opts?.lookup;
1770
1793
  return defineTool({
1771
1794
  name: "web_fetch",
1772
1795
  description: "Fetch the contents of a URL via HTTP/HTTPS. Use only for URLs the user provided or that you are confident help with the task; never invent or guess URLs. Rejects non-http(s) URLs and is SSRF-guarded by default (private/loopback/link-local/cloud-metadata hosts are refused with an ssrf_blocked error). The response body is capped at 1 MB. Returns { ok, content, status_code, content_type } or { ok: false, error }.",
@@ -1796,7 +1819,10 @@ function createWebFetchTool(opts) {
1796
1819
  try {
1797
1820
  const response = await screenedFetch(url, {
1798
1821
  signal: controller.signal,
1799
- allowPrivateHosts
1822
+ allowPrivateHosts,
1823
+ ...maxRedirects !== void 0 ? { maxRedirects } : {},
1824
+ ...fetchImpl ? { fetchImpl } : {},
1825
+ ...lookup ? { lookup } : {}
1800
1826
  });
1801
1827
  clearTimeout(timer);
1802
1828
  const contentLength = response.headers.get("content-length");
@@ -1829,6 +1855,9 @@ function createWebFetchTool(opts) {
1829
1855
  });
1830
1856
  } catch (err) {
1831
1857
  clearTimeout(timer);
1858
+ if (err instanceof RedirectBlockedError) {
1859
+ return JSON.stringify({ ok: false, error: "redirect_blocked", url, reason: err.message });
1860
+ }
1832
1861
  if (err instanceof SsrfBlockedError) {
1833
1862
  return JSON.stringify({ ok: false, error: "ssrf_blocked", url, reason: err.message });
1834
1863
  }
@@ -1959,6 +1988,6 @@ async function isBinaryFile(absolutePath) {
1959
1988
  }
1960
1989
  }
1961
1990
 
1962
- export { CatastrophicCommandError, DEFAULT_TOOL_GUIDANCE, SsrfBlockedError, 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, withShellExitGuidance, withToolResultGuidance };
1991
+ export { CatastrophicCommandError, DEFAULT_TOOL_GUIDANCE, RedirectBlockedError, SsrfBlockedError, 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, withShellExitGuidance, withToolResultGuidance };
1963
1992
  //# sourceMappingURL=index.js.map
1964
1993
  //# sourceMappingURL=index.js.map