@warlock.js/ai-tools 4.5.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 +22 -0
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/cjs/index.cjs +2519 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/contracts/http.type.d.mts +96 -0
- package/esm/contracts/http.type.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +4 -0
- package/esm/contracts/mcp.type.d.mts +216 -0
- package/esm/contracts/mcp.type.d.mts.map +1 -0
- package/esm/contracts/utility.type.d.mts +96 -0
- package/esm/contracts/utility.type.d.mts.map +1 -0
- package/esm/contracts/web.type.d.mts +136 -0
- package/esm/contracts/web.type.d.mts.map +1 -0
- package/esm/errors.d.mts +225 -0
- package/esm/errors.d.mts.map +1 -0
- package/esm/errors.mjs +136 -0
- package/esm/errors.mjs.map +1 -0
- package/esm/http/http-request.d.mts +57 -0
- package/esm/http/http-request.d.mts.map +1 -0
- package/esm/http/http-request.mjs +221 -0
- package/esm/http/http-request.mjs.map +1 -0
- package/esm/index.d.mts +19 -0
- package/esm/index.mjs +15 -0
- package/esm/mcp/client.mjs +199 -0
- package/esm/mcp/client.mjs.map +1 -0
- package/esm/mcp/index.d.mts +43 -0
- package/esm/mcp/index.d.mts.map +1 -0
- package/esm/mcp/index.mjs +19 -0
- package/esm/mcp/index.mjs.map +1 -0
- package/esm/mcp/json-schema-to-standard.d.mts +34 -0
- package/esm/mcp/json-schema-to-standard.d.mts.map +1 -0
- package/esm/mcp/json-schema-to-standard.mjs +147 -0
- package/esm/mcp/json-schema-to-standard.mjs.map +1 -0
- package/esm/mcp/serve.d.mts +46 -0
- package/esm/mcp/serve.d.mts.map +1 -0
- package/esm/mcp/serve.mjs +264 -0
- package/esm/mcp/serve.mjs.map +1 -0
- package/esm/mcp/transport.d.mts +48 -0
- package/esm/mcp/transport.d.mts.map +1 -0
- package/esm/mcp/transport.mjs +381 -0
- package/esm/mcp/transport.mjs.map +1 -0
- package/esm/mcp/transport.type.d.mts +51 -0
- package/esm/mcp/transport.type.d.mts.map +1 -0
- package/esm/node_modules/@standard-schema/spec/dist/index.d.mts +80 -0
- package/esm/node_modules/@standard-schema/spec/dist/index.d.mts.map +1 -0
- package/esm/register.d.mts +55 -0
- package/esm/register.d.mts.map +1 -0
- package/esm/register.mjs +21 -0
- package/esm/register.mjs.map +1 -0
- package/esm/schema.mjs +127 -0
- package/esm/schema.mjs.map +1 -0
- package/esm/utility/calculator.d.mts +35 -0
- package/esm/utility/calculator.d.mts.map +1 -0
- package/esm/utility/calculator.mjs +272 -0
- package/esm/utility/calculator.mjs.map +1 -0
- package/esm/utility/date-time.d.mts +57 -0
- package/esm/utility/date-time.d.mts.map +1 -0
- package/esm/utility/date-time.mjs +193 -0
- package/esm/utility/date-time.mjs.map +1 -0
- package/esm/utility/index.d.mts +2 -0
- package/esm/utility/index.mjs +4 -0
- package/esm/utility/schema.mjs +114 -0
- package/esm/utility/schema.mjs.map +1 -0
- package/esm/web/fetch-url.d.mts +39 -0
- package/esm/web/fetch-url.d.mts.map +1 -0
- package/esm/web/fetch-url.mjs +228 -0
- package/esm/web/fetch-url.mjs.map +1 -0
- package/esm/web/index.d.mts +2 -0
- package/esm/web/index.mjs +4 -0
- package/esm/web/schema.mjs +86 -0
- package/esm/web/schema.mjs.map +1 -0
- package/esm/web/web-search.d.mts +38 -0
- package/esm/web/web-search.d.mts.map +1 -0
- package/esm/web/web-search.mjs +167 -0
- package/esm/web/web-search.mjs.map +1 -0
- package/llms-full.txt +326 -0
- package/llms.txt +11 -0
- package/package.json +45 -0
- package/skills/README.md +17 -0
- package/skills/connect-mcp-server/SKILL.md +98 -0
- package/skills/expose-as-mcp-server/SKILL.md +85 -0
- package/skills/use-web-and-http-tools/SKILL.md +125 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { JsonSchemaTarget, ToolContract } from "@warlock.js/ai";
|
|
2
|
+
|
|
3
|
+
//#region ../@warlock.js/ai-tools/src/contracts/mcp.type.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Type contracts for the Model Context Protocol surface — the
|
|
6
|
+
* `ai.mcp(server)` client and `ai.mcp.serve(source)` server. Pure
|
|
7
|
+
* declarations only; the factories live outside `contracts/`.
|
|
8
|
+
*
|
|
9
|
+
* **`type`, never `kind`.** MCP's own wire vocabulary uses `kind` in
|
|
10
|
+
* some content / capability descriptors. This package translates any
|
|
11
|
+
* inbound `kind` to `type` at the transport boundary and never emits
|
|
12
|
+
* `kind` from the types it owns — every discriminator below is `type`.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* How the MCP client reaches a server. Discriminated by `type`.
|
|
16
|
+
*
|
|
17
|
+
* - `"stdio"` — spawn `command` (+ `args`) as a child process and speak
|
|
18
|
+
* JSON-RPC over its stdin/stdout (uses `node:child_process` +
|
|
19
|
+
* `node:readline`; no dependency).
|
|
20
|
+
* - `"http"` — Streamable HTTP transport against `url`.
|
|
21
|
+
*/
|
|
22
|
+
type McpTransport = {
|
|
23
|
+
/** stdio transport — a spawned child process. */type: "stdio"; /** Executable to spawn (e.g. `"npx"`). */
|
|
24
|
+
command: string; /** Arguments passed to `command`. */
|
|
25
|
+
args?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Environment for the child. When omitted the process environment
|
|
28
|
+
* is NOT inherited — pass what the server needs explicitly.
|
|
29
|
+
*/
|
|
30
|
+
env?: Record<string, string>;
|
|
31
|
+
} | {
|
|
32
|
+
/** Streamable HTTP transport. */type: "http"; /** The server endpoint URL. */
|
|
33
|
+
url: string; /** Static headers sent with every request (e.g. auth). */
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Options for the `ai.mcp(server, options)` client (Direction A:
|
|
38
|
+
* external server → local agent tools).
|
|
39
|
+
*/
|
|
40
|
+
interface McpClientOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Prefix prepended to each remote tool name to avoid colliding with
|
|
43
|
+
* local tools, e.g. `"github."`. The author owns uniqueness — there
|
|
44
|
+
* is no runtime collision guard.
|
|
45
|
+
*/
|
|
46
|
+
namePrefix?: string;
|
|
47
|
+
/** Only adapt tools whose (unprefixed) name passes this filter. */
|
|
48
|
+
filter?: (toolName: string) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Per-call timeout for `tools/call`, in milliseconds.
|
|
51
|
+
*
|
|
52
|
+
* @default 30_000
|
|
53
|
+
*/
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The client handle returned by `ai.mcp(server, options)`.
|
|
58
|
+
*/
|
|
59
|
+
interface McpClient {
|
|
60
|
+
/**
|
|
61
|
+
* Lazily run the `initialize` handshake + `tools/list`, mapping each
|
|
62
|
+
* remote tool to a {@link ToolContract}. Cached after the first call.
|
|
63
|
+
*/
|
|
64
|
+
tools(): Promise<ToolContract[]>;
|
|
65
|
+
/** Close the underlying transport (kills the child / ends the HTTP session). */
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A source of tools to expose via `ai.mcp.serve` — either an object that
|
|
70
|
+
* can enumerate its `ToolContract`s (a built agent / supervisor /
|
|
71
|
+
* orchestrator), or a literal array of contracts.
|
|
72
|
+
*/
|
|
73
|
+
type McpServeSource = {
|
|
74
|
+
tools(): ToolContract[];
|
|
75
|
+
} | ToolContract[];
|
|
76
|
+
/**
|
|
77
|
+
* Where an `ai.mcp.serve` server listens. Discriminated by `type`.
|
|
78
|
+
*
|
|
79
|
+
* - `"stdio"` — serve JSON-RPC over this process's stdin/stdout.
|
|
80
|
+
* - `"http"` — serve Streamable HTTP on `port`.
|
|
81
|
+
*/
|
|
82
|
+
type McpServeTransport = {
|
|
83
|
+
type: "stdio";
|
|
84
|
+
} | {
|
|
85
|
+
type: "http";
|
|
86
|
+
port: number;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Options for `ai.mcp.serve(source, options)` (Direction B: local
|
|
90
|
+
* primitive → MCP server other clients can consume).
|
|
91
|
+
*/
|
|
92
|
+
interface McpServeOptions {
|
|
93
|
+
/** Server name advertised in the `initialize` response. */
|
|
94
|
+
name: string;
|
|
95
|
+
/**
|
|
96
|
+
* Server version advertised in `initialize`.
|
|
97
|
+
*
|
|
98
|
+
* @default the package version
|
|
99
|
+
*/
|
|
100
|
+
version?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Where to listen.
|
|
103
|
+
*
|
|
104
|
+
* @default { type: "stdio" }
|
|
105
|
+
*/
|
|
106
|
+
transport?: McpServeTransport;
|
|
107
|
+
/**
|
|
108
|
+
* JSON-Schema dialect emitted for each tool's `inputSchema`. Defaults
|
|
109
|
+
* to a neutral MCP draft rather than `extractJsonSchema`'s own
|
|
110
|
+
* `"openai-strict"` default.
|
|
111
|
+
*
|
|
112
|
+
* @default "draft-2020-12"
|
|
113
|
+
*/
|
|
114
|
+
schemaTarget?: JsonSchemaTarget;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A running `ai.mcp.serve` server.
|
|
118
|
+
*/
|
|
119
|
+
interface McpServer {
|
|
120
|
+
/** Begin accepting connections / reading the transport. */
|
|
121
|
+
start(): Promise<void>;
|
|
122
|
+
/** Stop serving and release the transport. */
|
|
123
|
+
stop(): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
/** The JSON-RPC version literal every message carries. */
|
|
126
|
+
type JsonRpcVersion = "2.0";
|
|
127
|
+
/** A JSON-RPC id — a string or number (we never send notifications with `null`). */
|
|
128
|
+
type JsonRpcId = string | number;
|
|
129
|
+
/**
|
|
130
|
+
* A JSON-RPC request: a method invocation that expects a response.
|
|
131
|
+
*/
|
|
132
|
+
interface JsonRpcRequest<TParams = unknown> {
|
|
133
|
+
jsonrpc: JsonRpcVersion;
|
|
134
|
+
id: JsonRpcId;
|
|
135
|
+
/** The RPC method name, e.g. `"tools/list"`. */
|
|
136
|
+
method: string;
|
|
137
|
+
/** Method parameters; shape is method-specific. */
|
|
138
|
+
params?: TParams;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A JSON-RPC notification: a method invocation with no response.
|
|
142
|
+
*/
|
|
143
|
+
interface JsonRpcNotification<TParams = unknown> {
|
|
144
|
+
jsonrpc: JsonRpcVersion;
|
|
145
|
+
/** The RPC method name. */
|
|
146
|
+
method: string;
|
|
147
|
+
/** Method parameters; shape is method-specific. */
|
|
148
|
+
params?: TParams;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A JSON-RPC error object, carried in an error response.
|
|
152
|
+
*/
|
|
153
|
+
interface JsonRpcError {
|
|
154
|
+
/** Numeric error code per the JSON-RPC spec. */
|
|
155
|
+
code: number;
|
|
156
|
+
/** Human-readable error message. */
|
|
157
|
+
message: string;
|
|
158
|
+
/** Optional structured error data. */
|
|
159
|
+
data?: unknown;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A JSON-RPC response — exactly one of `result` / `error` is present.
|
|
163
|
+
*/
|
|
164
|
+
interface JsonRpcResponse<TResult = unknown> {
|
|
165
|
+
jsonrpc: JsonRpcVersion;
|
|
166
|
+
id: JsonRpcId;
|
|
167
|
+
/** Present on success. */
|
|
168
|
+
result?: TResult;
|
|
169
|
+
/** Present on failure. */
|
|
170
|
+
error?: JsonRpcError;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Any inbound JSON-RPC message the transport may surface.
|
|
174
|
+
*/
|
|
175
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
176
|
+
/**
|
|
177
|
+
* One tool descriptor as returned by an MCP server's `tools/list`. Its
|
|
178
|
+
* `inputSchema` is a JSON Schema object the client converts into a
|
|
179
|
+
* Standard Schema for the adapted {@link ToolContract}.
|
|
180
|
+
*/
|
|
181
|
+
interface McpToolDescriptor {
|
|
182
|
+
/** The remote tool's name (before any `namePrefix`). */
|
|
183
|
+
name: string;
|
|
184
|
+
/** Human-readable description forwarded to the LLM. */
|
|
185
|
+
description?: string;
|
|
186
|
+
/** JSON Schema for the tool's arguments. */
|
|
187
|
+
inputSchema?: Record<string, unknown>;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* One content block in an MCP `tools/call` result. MCP's wire field is
|
|
191
|
+
* `type` here already (`"text"`, `"image"`, …); where a server uses
|
|
192
|
+
* `kind` for a content variant, the client maps it onto `type` so our
|
|
193
|
+
* shapes only ever expose `type`.
|
|
194
|
+
*/
|
|
195
|
+
interface McpContentBlock {
|
|
196
|
+
/** The content variant (`"text"`, `"image"`, `"resource"`, …). */
|
|
197
|
+
type: string;
|
|
198
|
+
/** Text payload, present for `type: "text"`. */
|
|
199
|
+
text?: string;
|
|
200
|
+
/** Any further variant-specific fields, left opaque. */
|
|
201
|
+
[extra: string]: unknown;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The `result` payload of an MCP `tools/call`. `isError: true` signals a
|
|
205
|
+
* tool-level failure the client rethrows so `tool()` wraps it as a
|
|
206
|
+
* {@link import("@warlock.js/ai").ToolExecutionError}.
|
|
207
|
+
*/
|
|
208
|
+
interface McpToolCallResult {
|
|
209
|
+
/** Ordered content blocks produced by the tool. */
|
|
210
|
+
content: McpContentBlock[];
|
|
211
|
+
/** True when the call represents a tool-level error. */
|
|
212
|
+
isError?: boolean;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { JsonRpcError, JsonRpcId, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcVersion, McpClient, McpClientOptions, McpContentBlock, McpServeOptions, McpServeSource, McpServeTransport, McpServer, McpToolCallResult, McpToolDescriptor, McpTransport };
|
|
216
|
+
//# sourceMappingURL=mcp.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai-tools/src/contracts/mcp.type.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;;;;;AAoBsB;AAOtB;KA3BY,YAAA;mDAGN,IAAA,WA8BJ;EA5BI,OAAA,UA8BM;EA5BN,IAAA;EAkCK;AAAA;AAMX;;EAnCM,GAAA,GAAM,MAAA;AAAA;EAwCD,iCApCL,IAAA,UAsCY;EApCZ,GAAA,UAkCJ;EAhCI,OAAA,GAAU,MAAM;AAAA;;;;AAkCJ;UA3BD,gBAAA;EAmCS;;;;;EA7BxB,UAAA;EA+Bc;EA7Bd,MAAA,IAAU,QAAA;EAqCA;;;;;EA/BV,SAAA;AAAA;;AAiCsB;AAMxB;UAjCiB,SAAA;;;;;EAKf,KAAA,IAAS,OAAA,CAAQ,YAAA;EA0CL;EAxCZ,KAAA,IAAS,OAAA;AAAA;;AAgDsB;AAMjC;;;KA9CY,cAAA;EACN,KAAA,IAAS,YAAA;AAAA,IACX,YAAY;;;;AAgDC;AAYjB;;KApDY,iBAAA;EACN,IAAA;AAAA;EACA,IAAA;EAAc,IAAA;AAAA;;AAqDC;AAKrB;;UApDiB,eAAA;EAqDN;EAnDT,IAAA;EAwDS;;;;;EAlDT,OAAA;EA8CA;;;;;EAxCA,SAAA,GAAY,iBAAA;EA4CI;AAMlB;;;;;;EA1CE,YAAA,GAAe,gBAAgB;AAAA;;;;UAMhB,SAAA;EA+CA;EA7Cf,KAAA,IAAS,OAAA;;EAET,IAAA,IAAQ,OAAO;AAAA;;KAYL,cAAA;;KAGA,SAAA;AAwCZ;;;AAAA,UAnCiB,cAAA;EACf,OAAA,EAAS,cAAA;EACT,EAAA,EAAI,SAAA;EAuCI;EArCR,MAAA;EAqCoB;EAnCpB,MAAA,GAAS,OAAA;AAAA;;;;UAMM,mBAAA;EACf,OAAA,EAAS,cAAA;EA4BT;EA1BA,MAAA;EA0BoB;EAxBpB,MAAA,GAAS,OAAO;AAAA;;;;UAMD,YAAA;EA2Bb;EAzBF,IAAA;EAyBiB;EAvBjB,OAAA;EAsBE;EApBF,IAAA;AAAA;AAqBiB;AAOnB;;AAPmB,UAfF,eAAA;EACf,OAAA,EAAS,cAAA;EACT,EAAA,EAAI,SAAA;EAwBJ;EAtBA,MAAA,GAAS,OAAA;EAwBK;EAtBd,KAAA,GAAQ,YAAA;AAAA;AA+BV;;;AAAA,KAzBY,cAAA,GACR,cAAA,GACA,mBAAA,GACA,eAAA;;;;;AA4BY;UArBC,iBAAA;EA6BiB;EA3BhC,IAAA;EA6BwB;EA3BxB,WAAA;EA2BS;EAzBT,WAAA,GAAc,MAAM;AAAA;AA2Bb;;;;;;AAAA,UAlBQ,eAAA;;EAEf,IAAA;;EAEA,IAAA;;GAEC,KAAA;AAAA;;;;;;UAQc,iBAAA;;EAEf,OAAA,EAAS,eAAe;;EAExB,OAAA;AAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai-tools/src/contracts/utility.type.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type contracts for the utility tools — `ai.tools.calculator` and
|
|
4
|
+
* `ai.tools.dateTime`. Pure declarations only; the factories live
|
|
5
|
+
* outside `contracts/`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Construction options for `ai.tools.calculator`.
|
|
9
|
+
*/
|
|
10
|
+
interface CalculatorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Override the tool name exposed to the LLM.
|
|
13
|
+
*
|
|
14
|
+
* @default "calculator"
|
|
15
|
+
*/
|
|
16
|
+
name?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The validated input shape the model passes to `calculator`.
|
|
20
|
+
*/
|
|
21
|
+
interface CalculatorInput {
|
|
22
|
+
/** An arithmetic expression to evaluate, e.g. `"(3 + 4) * 2"`. */
|
|
23
|
+
expression: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `calculator` tool's output.
|
|
27
|
+
*/
|
|
28
|
+
interface CalculatorResult {
|
|
29
|
+
/** The numeric result of evaluating the expression. */
|
|
30
|
+
result: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The operations `ai.tools.dateTime` can perform.
|
|
34
|
+
*
|
|
35
|
+
* - `"now"` — current date-time, optionally in a given time zone.
|
|
36
|
+
* - `"add"` — add `amount` of `unit` to `iso`.
|
|
37
|
+
* - `"diff"` — difference between two instants, in `unit`.
|
|
38
|
+
* - `"format"` — render `iso` per `format`.
|
|
39
|
+
*/
|
|
40
|
+
type DateTimeOp = "now" | "add" | "diff" | "format";
|
|
41
|
+
/**
|
|
42
|
+
* Construction options for `ai.tools.dateTime`.
|
|
43
|
+
*/
|
|
44
|
+
interface DateTimeOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Override the tool name exposed to the LLM.
|
|
47
|
+
*
|
|
48
|
+
* @default "date_time"
|
|
49
|
+
*/
|
|
50
|
+
name?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Default IANA time zone applied when a call omits `timeZone`
|
|
53
|
+
* (e.g. `"UTC"`, `"Africa/Cairo"`). When unset, the host time zone
|
|
54
|
+
* is used.
|
|
55
|
+
*/
|
|
56
|
+
defaultTimeZone?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The validated input shape the model passes to `date_time`. Which
|
|
60
|
+
* fields are required depends on `op` (validated at the seal layer).
|
|
61
|
+
*/
|
|
62
|
+
interface DateTimeInput {
|
|
63
|
+
/** Which date-time operation to perform. */
|
|
64
|
+
op: DateTimeOp;
|
|
65
|
+
/** ISO-8601 instant the operation acts on (`add` / `diff` / `format`). */
|
|
66
|
+
iso?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Start instant for `diff`, accepted as an alias for `iso` — models
|
|
69
|
+
* naturally pass `from` / `to` for a difference. When both are set, `iso`
|
|
70
|
+
* wins.
|
|
71
|
+
*/
|
|
72
|
+
from?: string;
|
|
73
|
+
/** Second ISO-8601 instant for `diff`. */
|
|
74
|
+
to?: string;
|
|
75
|
+
/** Signed magnitude for `add`. */
|
|
76
|
+
amount?: number;
|
|
77
|
+
/** Unit for `add` / `diff`, e.g. `"days"`, `"hours"`, `"minutes"`. */
|
|
78
|
+
unit?: string;
|
|
79
|
+
/** IANA time zone override for this call. */
|
|
80
|
+
timeZone?: string;
|
|
81
|
+
/** Output format string for `format` (and the rendered `now`). */
|
|
82
|
+
format?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The `date_time` tool's output.
|
|
86
|
+
*/
|
|
87
|
+
interface DateTimeResult {
|
|
88
|
+
/**
|
|
89
|
+
* The result, rendered as a string — an ISO instant, a formatted
|
|
90
|
+
* date, or a stringified numeric difference depending on `op`.
|
|
91
|
+
*/
|
|
92
|
+
value: string;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { CalculatorInput, CalculatorOptions, CalculatorResult, DateTimeInput, DateTimeOp, DateTimeOptions, DateTimeResult };
|
|
96
|
+
//# sourceMappingURL=utility.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai-tools/src/contracts/utility.type.ts"],"mappings":";;AASA;;;;AAMM;AAMN;;AANM,UANW,iBAAA;EAcL;AAAA;AAMZ;;;EAdE,IAAI;AAAA;AA2BN;;;AAAA,UArBiB,eAAA;EAqBK;EAnBpB,UAAU;AAAA;;;AAoCK;UA9BA,gBAAA;EAqCa;EAnC5B,MAAM;AAAA;;;;;;;;;KAWI,UAAA;;AA4CJ;AAMR;UA7CiB,eAAA;;;AAkDV;;;EA5CL,IAAA;;;;;;EAMA,eAAe;AAAA;;;;;UAOA,aAAA;;EAEf,EAAA,EAAI,UAAU;;EAEd,GAAA;;;;;;EAMA,IAAA;;EAEA,EAAA;;EAEA,MAAA;;EAEA,IAAA;;EAEA,QAAA;;EAEA,MAAA;AAAA;;;;UAMe,cAAA;;;;;EAKf,KAAK;AAAA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai-tools/src/contracts/web.type.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type contracts for the web tools — `ai.tools.webSearch` and
|
|
4
|
+
* `ai.tools.fetchUrl`. Pure declarations only; the factories live
|
|
5
|
+
* outside `contracts/`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Which optional search backend `ai.tools.webSearch` drives. The chosen
|
|
9
|
+
* provider's SDK / HTTP key is a lazily-imported optional peer, so an
|
|
10
|
+
* agent that never searches the web pulls in none of them.
|
|
11
|
+
*
|
|
12
|
+
* Uses `type` as the discriminator everywhere downstream — never `kind`.
|
|
13
|
+
*/
|
|
14
|
+
type SearchProvider = "tavily" | "brave" | "serpapi";
|
|
15
|
+
/**
|
|
16
|
+
* Construction options for {@link SearchProvider}-backed web search.
|
|
17
|
+
*/
|
|
18
|
+
interface WebSearchOptions {
|
|
19
|
+
/** Which optional search backend to use. Its SDK/HTTP key is a lazy peer. */
|
|
20
|
+
provider: SearchProvider;
|
|
21
|
+
/**
|
|
22
|
+
* API key for the provider. Falls back to a provider-specific
|
|
23
|
+
* environment variable (e.g. `TAVILY_API_KEY`) when omitted.
|
|
24
|
+
*/
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Default maximum results per call. The model may request fewer (or
|
|
28
|
+
* more, clamped into `[1, maxResults]`) via the tool input.
|
|
29
|
+
*
|
|
30
|
+
* @default 5
|
|
31
|
+
*/
|
|
32
|
+
maxResults?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Override the tool name exposed to the LLM.
|
|
35
|
+
*
|
|
36
|
+
* @default "web_search"
|
|
37
|
+
*/
|
|
38
|
+
name?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The validated input shape the model passes to the web-search tool.
|
|
42
|
+
*/
|
|
43
|
+
interface WebSearchInput {
|
|
44
|
+
/** The search query. */
|
|
45
|
+
query: string;
|
|
46
|
+
/** Per-call cap on results, clamped into `[1, options.maxResults]`. */
|
|
47
|
+
maxResults?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A single web-search hit. `score` is provider-supplied relevance when
|
|
51
|
+
* the backend returns one (Tavily does; some others do not).
|
|
52
|
+
*/
|
|
53
|
+
interface WebSearchResultItem {
|
|
54
|
+
/** Page / document title. */
|
|
55
|
+
title: string;
|
|
56
|
+
/** Canonical URL of the result. */
|
|
57
|
+
url: string;
|
|
58
|
+
/** Short LLM-ready extract / snippet. */
|
|
59
|
+
snippet: string;
|
|
60
|
+
/** Provider relevance score, when available. */
|
|
61
|
+
score?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The web-search tool's output — the ranked list of hits.
|
|
65
|
+
*/
|
|
66
|
+
interface WebSearchResult {
|
|
67
|
+
/** Ranked results, best-first. */
|
|
68
|
+
results: WebSearchResultItem[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* How `fetch_url` should render the fetched document into the `content`
|
|
72
|
+
* string handed back to the model.
|
|
73
|
+
*
|
|
74
|
+
* - `"text"` — readability-extracted main text (the default; needs the
|
|
75
|
+
* `@mozilla/readability` + `jsdom` optional peers).
|
|
76
|
+
* - `"html"` — the raw response body, untouched.
|
|
77
|
+
* - `"markdown"` — readability extraction converted to Markdown.
|
|
78
|
+
*/
|
|
79
|
+
type FetchUrlExtract = "text" | "html" | "markdown";
|
|
80
|
+
/**
|
|
81
|
+
* Construction options for `ai.tools.fetchUrl`.
|
|
82
|
+
*/
|
|
83
|
+
interface FetchUrlOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Override the tool name exposed to the LLM.
|
|
86
|
+
*
|
|
87
|
+
* @default "fetch_url"
|
|
88
|
+
*/
|
|
89
|
+
name?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Hard cap on the number of response bytes read before truncation.
|
|
92
|
+
*
|
|
93
|
+
* @default 1_000_000
|
|
94
|
+
*/
|
|
95
|
+
maxBytes?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Per-request timeout in milliseconds.
|
|
98
|
+
*
|
|
99
|
+
* @default 15_000
|
|
100
|
+
*/
|
|
101
|
+
timeoutMs?: number;
|
|
102
|
+
/**
|
|
103
|
+
* How to render the fetched document.
|
|
104
|
+
*
|
|
105
|
+
* @default "text"
|
|
106
|
+
*/
|
|
107
|
+
extract?: FetchUrlExtract;
|
|
108
|
+
/**
|
|
109
|
+
* Host allowlist. When set, any request to a host not in this list is
|
|
110
|
+
* rejected before the network call (an SSRF guardrail).
|
|
111
|
+
*/
|
|
112
|
+
allowHosts?: string[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The validated input shape the model passes to `fetch_url`.
|
|
116
|
+
*/
|
|
117
|
+
interface FetchUrlInput {
|
|
118
|
+
/** The absolute URL to fetch. */
|
|
119
|
+
url: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The `fetch_url` tool's output.
|
|
123
|
+
*/
|
|
124
|
+
interface FetchUrlResult {
|
|
125
|
+
/** The URL that was fetched (after any redirects the platform followed). */
|
|
126
|
+
url: string;
|
|
127
|
+
/** HTTP status code of the final response. */
|
|
128
|
+
status: number;
|
|
129
|
+
/** The rendered content per the configured `extract` mode. */
|
|
130
|
+
content: string;
|
|
131
|
+
/** True when `content` was cut off at `maxBytes`. */
|
|
132
|
+
truncated: boolean;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
export { FetchUrlExtract, FetchUrlInput, FetchUrlOptions, FetchUrlResult, SearchProvider, WebSearchInput, WebSearchOptions, WebSearchResult, WebSearchResultItem };
|
|
136
|
+
//# sourceMappingURL=web.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai-tools/src/contracts/web.type.ts"],"mappings":";;AAaA;;;;AAA0B;AAK1B;;;;;;AAL0B,KAAd,cAAA;;;;UAKK,gBAAA;EA0BA;EAxBf,QAAA,EAAU,cAAc;;;AA4Bd;AAOZ;EA9BE,MAAA;;;;;;;EAOA,UAAA;EA+BK;AAMP;;;;EA/BE,IAAA;AAAA;;;;UAMe,cAAA;EA4CA;EA1Cf,KAAA;;EAEA,UAAU;AAAA;;;;;UAOK,mBAAA;EA8DL;EA5DV,KAAA;EAkEe;EAhEf,GAAA;;EAEA,OAAA;EAgEG;EA9DH,KAAA;AAAA;;;;UAMe,eAAA;EAoEf;EAlEA,OAAA,EAAS,mBAAmB;AAAA;AAoEnB;;;;;;;;;AAAA,KAxDC,eAAA;;;;UAKK,eAAA;;;;;;EAMf,IAAA;;;;;;EAMA,QAAA;;;;;;EAMA,SAAA;;;;;;EAMA,OAAA,GAAU,eAAe;;;;;EAKzB,UAAA;AAAA;;;;UAMe,aAAA;;EAEf,GAAG;AAAA;;;;UAMY,cAAA;;EAEf,GAAA;;EAEA,MAAA;;EAEA,OAAA;;EAEA,SAAA;AAAA"}
|
package/esm/errors.d.mts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { AIError, AIErrorOptions } from "@warlock.js/ai";
|
|
2
|
+
|
|
3
|
+
//#region ../@warlock.js/ai-tools/src/errors.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Why the calculator rejected an expression.
|
|
6
|
+
*
|
|
7
|
+
* - `"syntax"` — the expression could not be tokenized or parsed
|
|
8
|
+
* (an unknown character, a misplaced operator, unbalanced parens).
|
|
9
|
+
* - `"divide-by-zero"` — evaluation divided (or took a modulo) by zero.
|
|
10
|
+
* - `"overflow"` — the computed result was not a finite number.
|
|
11
|
+
*/
|
|
12
|
+
type CalculatorFailure = "syntax" | "divide-by-zero" | "overflow";
|
|
13
|
+
/**
|
|
14
|
+
* Options for {@link CalculatorError} — the structured `type`
|
|
15
|
+
* discriminator so a caller can branch without parsing the message.
|
|
16
|
+
*/
|
|
17
|
+
type CalculatorErrorOptions = AIErrorOptions & {
|
|
18
|
+
/** Which class of calculator failure occurred. */type: CalculatorFailure;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The `calculator` tool could not evaluate an expression — it was not
|
|
22
|
+
* valid arithmetic, divided by zero, or overflowed to a non-finite
|
|
23
|
+
* value.
|
|
24
|
+
*
|
|
25
|
+
* **Surface.** Thrown inside the tool handler, where `tool()` wraps it
|
|
26
|
+
* into a `ToolExecutionError` whose message is preserved verbatim and
|
|
27
|
+
* reaches the model as `{ error }` data, so the agent self-corrects
|
|
28
|
+
* rather than crashing. Extends the framework {@link AIError} (category
|
|
29
|
+
* `"tool"` via code `TOOL_EXEC_FAILED`) so it flows through the same
|
|
30
|
+
* typed error contract as every other AI error; branch on `error.type`
|
|
31
|
+
* for the specific failure.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* if (error instanceof CalculatorError && error.type === "divide-by-zero") {
|
|
35
|
+
* // the expression divided by zero — ask the model to revise it
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
declare class CalculatorError extends AIError {
|
|
39
|
+
/** Which class of calculator failure occurred. */
|
|
40
|
+
readonly type: CalculatorFailure;
|
|
41
|
+
constructor(message: string, options: CalculatorErrorOptions);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Why the date-time tool rejected a call.
|
|
45
|
+
*
|
|
46
|
+
* - `"invalid-input"` — a required field for the chosen `op` was
|
|
47
|
+
* missing or malformed (an unparsable ISO instant, a bad `amount`).
|
|
48
|
+
* - `"invalid-unit"` — `unit` was not one of the supported units.
|
|
49
|
+
* - `"invalid-time-zone"` — the IANA time zone was not recognized.
|
|
50
|
+
* - `"unsupported-op"` — the `op` was not one this tool implements.
|
|
51
|
+
*/
|
|
52
|
+
type DateTimeFailure = "invalid-input" | "invalid-unit" | "invalid-time-zone" | "unsupported-op";
|
|
53
|
+
/**
|
|
54
|
+
* Options for {@link DateTimeError} — the structured `type`
|
|
55
|
+
* discriminator so a caller can branch without parsing the message.
|
|
56
|
+
*/
|
|
57
|
+
type DateTimeErrorOptions = AIErrorOptions & {
|
|
58
|
+
/** Which class of date-time failure occurred. */type: DateTimeFailure;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The `date_time` tool could not complete a call — a required field was
|
|
62
|
+
* missing or malformed, the unit/time zone was unrecognized, or the
|
|
63
|
+
* operation is unsupported.
|
|
64
|
+
*
|
|
65
|
+
* **Surface.** Thrown inside the tool handler, where `tool()` wraps it
|
|
66
|
+
* into a `ToolExecutionError` whose message reaches the model as
|
|
67
|
+
* `{ error }` data so the agent self-corrects. Extends the framework
|
|
68
|
+
* {@link AIError} (category `"tool"` via code `TOOL_EXEC_FAILED`); branch
|
|
69
|
+
* on `error.type` for the specific failure.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* if (error instanceof DateTimeError && error.type === "invalid-unit") {
|
|
73
|
+
* // the model passed an unknown unit — re-prompt with the allowed set
|
|
74
|
+
* }
|
|
75
|
+
*/
|
|
76
|
+
declare class DateTimeError extends AIError {
|
|
77
|
+
/** Which class of date-time failure occurred. */
|
|
78
|
+
readonly type: DateTimeFailure;
|
|
79
|
+
constructor(message: string, options: DateTimeErrorOptions);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Why an MCP transport operation failed.
|
|
83
|
+
*
|
|
84
|
+
* - `"connect"` — the transport could not be opened (child process
|
|
85
|
+
* failed to spawn, HTTP endpoint unreachable) or the `initialize`
|
|
86
|
+
* handshake failed.
|
|
87
|
+
* - `"protocol"` — a malformed / unexpected JSON-RPC message, a
|
|
88
|
+
* response that matched no in-flight request, or a missing field.
|
|
89
|
+
* - `"timeout"` — a request exceeded its per-call deadline.
|
|
90
|
+
* - `"closed"` — the transport was used after it was closed, or the
|
|
91
|
+
* peer closed it mid-call.
|
|
92
|
+
*/
|
|
93
|
+
type McpTransportFailure = "connect" | "protocol" | "timeout" | "closed";
|
|
94
|
+
/**
|
|
95
|
+
* Options for {@link McpTransportError} — the structured `type`
|
|
96
|
+
* discriminator plus an optional JSON-RPC method name for branchable
|
|
97
|
+
* diagnostics without parsing the message.
|
|
98
|
+
*/
|
|
99
|
+
type McpTransportErrorOptions = AIErrorOptions & {
|
|
100
|
+
/** Which class of transport failure occurred. */type: McpTransportFailure; /** The JSON-RPC method in flight when the failure occurred, if any. */
|
|
101
|
+
method?: string;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The MCP client's transport layer failed — it could not connect, the
|
|
105
|
+
* peer spoke malformed JSON-RPC, a call timed out, or the transport was
|
|
106
|
+
* already closed.
|
|
107
|
+
*
|
|
108
|
+
* **Surface.** Connection / handshake failures surface at
|
|
109
|
+
* agent-construction time (the caller `await`s `client.tools()`). A
|
|
110
|
+
* `tools/call` failure raised mid-run is wrapped by `tool()` into a
|
|
111
|
+
* `ToolExecutionError` and reaches the model as `{ error }` data, so the
|
|
112
|
+
* agent self-corrects rather than crashing. Extends the framework
|
|
113
|
+
* {@link AIError} (category `"tool"`, code `TOOL_EXEC_FAILED`) so it
|
|
114
|
+
* flows through the same typed error contract as every other AI error;
|
|
115
|
+
* branch on `error.type` for the specific failure.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* if (error instanceof McpTransportError && error.type === "timeout") {
|
|
119
|
+
* // the remote call exceeded its deadline — retry or escalate
|
|
120
|
+
* }
|
|
121
|
+
*/
|
|
122
|
+
declare class McpTransportError extends AIError {
|
|
123
|
+
/** Which class of transport failure occurred. */
|
|
124
|
+
readonly type: McpTransportFailure;
|
|
125
|
+
/** The JSON-RPC method in flight when the failure occurred, if any. */
|
|
126
|
+
readonly method?: string;
|
|
127
|
+
constructor(message: string, options: McpTransportErrorOptions);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Why a web tool (`ai.tools.webSearch` / `ai.tools.fetchUrl`) failed
|
|
131
|
+
* before or during a network call.
|
|
132
|
+
*
|
|
133
|
+
* - `"missing-peer"` — an optional peer dependency the chosen mode needs
|
|
134
|
+
* (`@mozilla/readability` + `jsdom` for text/markdown extraction, a
|
|
135
|
+
* search provider SDK) is not installed. The message carries a curated
|
|
136
|
+
* `npm install` string for the developer.
|
|
137
|
+
* - `"missing-key"` — no API key was supplied via options or the
|
|
138
|
+
* provider's environment variable.
|
|
139
|
+
* - `"denied-host"` — the requested URL's host is not in the configured
|
|
140
|
+
* `allowHosts` allowlist (an SSRF guardrail), rejected before any fetch.
|
|
141
|
+
* - `"invalid-url"` — the supplied URL could not be parsed, or used a
|
|
142
|
+
* non-`http(s)` scheme.
|
|
143
|
+
* - `"request-failed"` — the network call itself failed (DNS, connection
|
|
144
|
+
* reset, timeout) or the provider returned a non-OK status.
|
|
145
|
+
*/
|
|
146
|
+
type WebToolFailure = "missing-peer" | "missing-key" | "denied-host" | "invalid-url" | "request-failed";
|
|
147
|
+
/**
|
|
148
|
+
* Options for {@link WebToolError} — the structured `type` discriminator
|
|
149
|
+
* so a caller can branch without parsing the message.
|
|
150
|
+
*/
|
|
151
|
+
type WebToolErrorOptions = AIErrorOptions & {
|
|
152
|
+
/** Which class of web-tool failure occurred. */type: WebToolFailure;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* A web tool failed — a missing optional peer, an absent API key, a host
|
|
156
|
+
* rejected by the `allowHosts` guardrail, an unparseable URL, or a failed
|
|
157
|
+
* network call.
|
|
158
|
+
*
|
|
159
|
+
* **Surface.** Thrown from inside a tool's `execute`, so the framework's
|
|
160
|
+
* `tool()` wrapper catches it and surfaces it in the returned `{ error }`
|
|
161
|
+
* field (`invoke()` never throws) — the agent reads the failure as data
|
|
162
|
+
* and self-corrects rather than crashing. Extends the framework
|
|
163
|
+
* {@link AIError} (category `"tool"` via code `TOOL_EXEC_FAILED`) so it
|
|
164
|
+
* flows through the same typed error contract as every other AI error;
|
|
165
|
+
* branch on `error.type` for the specific failure.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* const { error } = await fetchTool.invoke({ url: "http://evil.test" });
|
|
169
|
+
* if (error instanceof WebToolError && error.type === "denied-host") {
|
|
170
|
+
* // the host was not in allowHosts — surfaced before any network call
|
|
171
|
+
* }
|
|
172
|
+
*/
|
|
173
|
+
declare class WebToolError extends AIError {
|
|
174
|
+
/** Which class of web-tool failure occurred. */
|
|
175
|
+
readonly type: WebToolFailure;
|
|
176
|
+
constructor(message: string, options: WebToolErrorOptions);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Why an `http_request` call was rejected by its own guardrails, before
|
|
180
|
+
* the network request was ever issued.
|
|
181
|
+
*
|
|
182
|
+
* - `"method-not-allowed"` — the model requested an HTTP method that is
|
|
183
|
+
* not on the tool's `allowMethods` allowlist (defaults to `["GET"]`).
|
|
184
|
+
* - `"host-not-allowed"` — the resolved request host is not on the
|
|
185
|
+
* tool's `allowHosts` allowlist (an SSRF guardrail).
|
|
186
|
+
* - `"invalid-url"` — the supplied URL (or its join with `baseUrl`)
|
|
187
|
+
* could not be parsed into an absolute `http(s)` URL.
|
|
188
|
+
*/
|
|
189
|
+
type HttpPolicyFailure = "method-not-allowed" | "host-not-allowed" | "invalid-url";
|
|
190
|
+
/**
|
|
191
|
+
* Options for {@link HttpPolicyError} — the structured `type`
|
|
192
|
+
* discriminator so a caller can branch without parsing the message.
|
|
193
|
+
*/
|
|
194
|
+
type HttpPolicyErrorOptions = AIErrorOptions & {
|
|
195
|
+
/** Which class of policy rejection occurred. */type: HttpPolicyFailure;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* The `http_request` tool refused a call its construction-time policy
|
|
199
|
+
* does not permit — a disallowed method, a host outside the allowlist,
|
|
200
|
+
* or an unparseable URL. The rejection happens *before* any network
|
|
201
|
+
* request, so a guarded tool can never be coaxed into reaching an
|
|
202
|
+
* off-allowlist host (an SSRF guardrail).
|
|
203
|
+
*
|
|
204
|
+
* **Surface.** Thrown from inside the tool's `execute`, so the framework's
|
|
205
|
+
* `tool()` wrapper catches it and surfaces it in the returned `{ error }`
|
|
206
|
+
* field (`invoke()` never throws) — the agent reads the typed failure as
|
|
207
|
+
* data and self-corrects rather than crashing. Extends the framework
|
|
208
|
+
* {@link AIError} (category `"tool"` via code `TOOL_EXEC_FAILED`) so it
|
|
209
|
+
* flows through the same typed error contract as every other AI error;
|
|
210
|
+
* branch on `error.type` for the specific failure.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* const { error } = await httpTool.invoke({ url: "https://evil.test" });
|
|
214
|
+
* if (error instanceof HttpPolicyError && error.type === "host-not-allowed") {
|
|
215
|
+
* // the model tried to reach a host outside the configured allowlist
|
|
216
|
+
* }
|
|
217
|
+
*/
|
|
218
|
+
declare class HttpPolicyError extends AIError {
|
|
219
|
+
/** Which class of policy rejection occurred. */
|
|
220
|
+
readonly type: HttpPolicyFailure;
|
|
221
|
+
constructor(message: string, options: HttpPolicyErrorOptions);
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
export { CalculatorError, CalculatorErrorOptions, CalculatorFailure, DateTimeError, DateTimeErrorOptions, DateTimeFailure, HttpPolicyError, HttpPolicyErrorOptions, HttpPolicyFailure, McpTransportError, McpTransportErrorOptions, McpTransportFailure, WebToolError, WebToolErrorOptions, WebToolFailure };
|
|
225
|
+
//# sourceMappingURL=errors.d.mts.map
|