@theokit/sdk-tools 0.5.0 → 0.6.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 +12 -0
- package/dist/index.cjs +21 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -707,7 +716,7 @@ declare function truncateOutput(output: string, opts?: TruncationOptions): Trunc
|
|
|
707
716
|
* Return shape (always a JSON string):
|
|
708
717
|
* - `{ ok: true, content, status_code, content_type }`
|
|
709
718
|
* - `{ ok: false, error: 'invalid_url' | 'fetch_failed' |
|
|
710
|
-
* 'timeout' | 'too_large' }`
|
|
719
|
+
* 'timeout' | 'too_large' | 'ssrf_blocked' | 'redirect_blocked' }`
|
|
711
720
|
*/
|
|
712
721
|
|
|
713
722
|
interface CreateWebFetchToolOptions {
|
|
@@ -719,6 +728,16 @@ interface CreateWebFetchToolOptions {
|
|
|
719
728
|
* trusted local-dev tooling.
|
|
720
729
|
*/
|
|
721
730
|
allowPrivateHosts?: boolean;
|
|
731
|
+
/**
|
|
732
|
+
* Max redirect hops to follow (each SSRF-screened). Default 5. Set `0` to BLOCK ALL
|
|
733
|
+
* redirects — a 3xx then returns `{ ok: false, error: "redirect_blocked" }` (a strict
|
|
734
|
+
* no-redirect policy for untrusted, model-chosen URLs).
|
|
735
|
+
*/
|
|
736
|
+
maxRedirects?: number;
|
|
737
|
+
/** Fetch implementation (injectable for tests — drive paths with no real network). */
|
|
738
|
+
fetchImpl?: ScreenedFetchOptions["fetchImpl"];
|
|
739
|
+
/** DNS resolver (injectable for tests — drive the SSRF path with no real DNS). */
|
|
740
|
+
lookup?: ScreenedFetchOptions["lookup"];
|
|
722
741
|
}
|
|
723
742
|
declare function createWebFetchTool(opts?: CreateWebFetchToolOptions): CustomTool;
|
|
724
743
|
|
|
@@ -793,4 +812,4 @@ interface CreateWriteFileToolOptions {
|
|
|
793
812
|
}
|
|
794
813
|
declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
|
|
795
814
|
|
|
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 };
|
|
815
|
+
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
|
|
@@ -707,7 +716,7 @@ declare function truncateOutput(output: string, opts?: TruncationOptions): Trunc
|
|
|
707
716
|
* Return shape (always a JSON string):
|
|
708
717
|
* - `{ ok: true, content, status_code, content_type }`
|
|
709
718
|
* - `{ ok: false, error: 'invalid_url' | 'fetch_failed' |
|
|
710
|
-
* 'timeout' | 'too_large' }`
|
|
719
|
+
* 'timeout' | 'too_large' | 'ssrf_blocked' | 'redirect_blocked' }`
|
|
711
720
|
*/
|
|
712
721
|
|
|
713
722
|
interface CreateWebFetchToolOptions {
|
|
@@ -719,6 +728,16 @@ interface CreateWebFetchToolOptions {
|
|
|
719
728
|
* trusted local-dev tooling.
|
|
720
729
|
*/
|
|
721
730
|
allowPrivateHosts?: boolean;
|
|
731
|
+
/**
|
|
732
|
+
* Max redirect hops to follow (each SSRF-screened). Default 5. Set `0` to BLOCK ALL
|
|
733
|
+
* redirects — a 3xx then returns `{ ok: false, error: "redirect_blocked" }` (a strict
|
|
734
|
+
* no-redirect policy for untrusted, model-chosen URLs).
|
|
735
|
+
*/
|
|
736
|
+
maxRedirects?: number;
|
|
737
|
+
/** Fetch implementation (injectable for tests — drive paths with no real network). */
|
|
738
|
+
fetchImpl?: ScreenedFetchOptions["fetchImpl"];
|
|
739
|
+
/** DNS resolver (injectable for tests — drive the SSRF path with no real DNS). */
|
|
740
|
+
lookup?: ScreenedFetchOptions["lookup"];
|
|
722
741
|
}
|
|
723
742
|
declare function createWebFetchTool(opts?: CreateWebFetchToolOptions): CustomTool;
|
|
724
743
|
|
|
@@ -793,4 +812,4 @@ interface CreateWriteFileToolOptions {
|
|
|
793
812
|
}
|
|
794
813
|
declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
|
|
795
814
|
|
|
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 };
|
|
815
|
+
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
|
|
854
|
+
throw new RedirectBlockedError(url, "too many redirects");
|
|
846
855
|
}
|
|
847
856
|
var DEFAULT_BUDGET = 8e3;
|
|
848
857
|
var DEFAULT_MAX_DEPTH = 4;
|
|
@@ -1767,6 +1776,9 @@ var MAX_BODY_BYTES = 1 * 1024 * 1024;
|
|
|
1767
1776
|
function createWebFetchTool(opts) {
|
|
1768
1777
|
const defaultTimeoutMs = opts?.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS4;
|
|
1769
1778
|
const allowPrivateHosts = opts?.allowPrivateHosts ?? false;
|
|
1779
|
+
const maxRedirects = opts?.maxRedirects;
|
|
1780
|
+
const fetchImpl = opts?.fetchImpl;
|
|
1781
|
+
const lookup = opts?.lookup;
|
|
1770
1782
|
return defineTool({
|
|
1771
1783
|
name: "web_fetch",
|
|
1772
1784
|
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 +1808,10 @@ function createWebFetchTool(opts) {
|
|
|
1796
1808
|
try {
|
|
1797
1809
|
const response = await screenedFetch(url, {
|
|
1798
1810
|
signal: controller.signal,
|
|
1799
|
-
allowPrivateHosts
|
|
1811
|
+
allowPrivateHosts,
|
|
1812
|
+
...maxRedirects !== void 0 ? { maxRedirects } : {},
|
|
1813
|
+
...fetchImpl ? { fetchImpl } : {},
|
|
1814
|
+
...lookup ? { lookup } : {}
|
|
1800
1815
|
});
|
|
1801
1816
|
clearTimeout(timer);
|
|
1802
1817
|
const contentLength = response.headers.get("content-length");
|
|
@@ -1829,6 +1844,9 @@ function createWebFetchTool(opts) {
|
|
|
1829
1844
|
});
|
|
1830
1845
|
} catch (err) {
|
|
1831
1846
|
clearTimeout(timer);
|
|
1847
|
+
if (err instanceof RedirectBlockedError) {
|
|
1848
|
+
return JSON.stringify({ ok: false, error: "redirect_blocked", url, reason: err.message });
|
|
1849
|
+
}
|
|
1832
1850
|
if (err instanceof SsrfBlockedError) {
|
|
1833
1851
|
return JSON.stringify({ ok: false, error: "ssrf_blocked", url, reason: err.message });
|
|
1834
1852
|
}
|
|
@@ -1959,6 +1977,6 @@ async function isBinaryFile(absolutePath) {
|
|
|
1959
1977
|
}
|
|
1960
1978
|
}
|
|
1961
1979
|
|
|
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 };
|
|
1980
|
+
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
1981
|
//# sourceMappingURL=index.js.map
|
|
1964
1982
|
//# sourceMappingURL=index.js.map
|