@anvia/extensions 0.0.0-stage → 0.2.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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/dist/guardrails/index.d.ts +2 -0
  4. package/dist/guardrails/index.js +4 -0
  5. package/dist/guardrails/length.js +53 -0
  6. package/dist/guardrails/length.js.map +1 -0
  7. package/dist/guardrails/llm-judge.js +91 -0
  8. package/dist/guardrails/llm-judge.js.map +1 -0
  9. package/dist/guardrails/redaction-guardrails.js +92 -0
  10. package/dist/guardrails/redaction-guardrails.js.map +1 -0
  11. package/dist/hooks/audit.js +77 -0
  12. package/dist/hooks/audit.js.map +1 -0
  13. package/dist/hooks/console.js +45 -0
  14. package/dist/hooks/console.js.map +1 -0
  15. package/dist/hooks/index.d.ts +2 -0
  16. package/dist/hooks/index.js +4 -0
  17. package/dist/hooks/usage.js +88 -0
  18. package/dist/hooks/usage.js.map +1 -0
  19. package/dist/index-Bd0LrPbr.d.ts +86 -0
  20. package/dist/index-Bd0LrPbr.d.ts.map +1 -0
  21. package/dist/index-Bov_OeIz.d.ts +20 -0
  22. package/dist/index-Bov_OeIz.d.ts.map +1 -0
  23. package/dist/index-CzQBvrEU.d.ts +29 -0
  24. package/dist/index-CzQBvrEU.d.ts.map +1 -0
  25. package/dist/index-D4FdbT72.d.ts +23 -0
  26. package/dist/index-D4FdbT72.d.ts.map +1 -0
  27. package/dist/index-DC6th6Lq.d.ts +23 -0
  28. package/dist/index-DC6th6Lq.d.ts.map +1 -0
  29. package/dist/index-NVtYgz_h.d.ts +72 -0
  30. package/dist/index-NVtYgz_h.d.ts.map +1 -0
  31. package/dist/index-_OYHBsgm.d.ts +64 -0
  32. package/dist/index-_OYHBsgm.d.ts.map +1 -0
  33. package/dist/index-tDVrZS31.d.ts +26 -0
  34. package/dist/index-tDVrZS31.d.ts.map +1 -0
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.js +16 -0
  37. package/dist/internal/pattern-redaction.js +46 -0
  38. package/dist/internal/pattern-redaction.js.map +1 -0
  39. package/dist/internal/truncate.js +23 -0
  40. package/dist/internal/truncate.js.map +1 -0
  41. package/dist/internal/url-safety.js +383 -0
  42. package/dist/internal/url-safety.js.map +1 -0
  43. package/dist/middlewares/index.d.ts +2 -0
  44. package/dist/middlewares/index.js +3 -0
  45. package/dist/middlewares/output-limit.js +91 -0
  46. package/dist/middlewares/output-limit.js.map +1 -0
  47. package/dist/middlewares/redaction.js +208 -0
  48. package/dist/middlewares/redaction.js.map +1 -0
  49. package/dist/tools/cache.js +98 -0
  50. package/dist/tools/cache.js.map +1 -0
  51. package/dist/tools/fs/index.d.ts +2 -0
  52. package/dist/tools/fs/index.js +299 -0
  53. package/dist/tools/fs/index.js.map +1 -0
  54. package/dist/tools/fs/path-safety.js +75 -0
  55. package/dist/tools/fs/path-safety.js.map +1 -0
  56. package/dist/tools/http/index.d.ts +2 -0
  57. package/dist/tools/http/index.js +111 -0
  58. package/dist/tools/http/index.js.map +1 -0
  59. package/dist/tools/index.d.ts +19 -0
  60. package/dist/tools/index.d.ts.map +1 -0
  61. package/dist/tools/index.js +8 -0
  62. package/dist/tools/todo/index.d.ts +2 -0
  63. package/dist/tools/todo/index.js +68 -0
  64. package/dist/tools/todo/index.js.map +1 -0
  65. package/dist/tools/web-fetch/html-to-text.js +67 -0
  66. package/dist/tools/web-fetch/html-to-text.js.map +1 -0
  67. package/dist/tools/web-fetch/index.d.ts +2 -0
  68. package/dist/tools/web-fetch/index.js +74 -0
  69. package/dist/tools/web-fetch/index.js.map +1 -0
  70. package/dist/tools/web-search/index.d.ts +2 -0
  71. package/dist/tools/web-search/index.js +52 -0
  72. package/dist/tools/web-search/index.js.map +1 -0
  73. package/dist/tools/web-search/providers.js +234 -0
  74. package/dist/tools/web-search/providers.js.map +1 -0
  75. package/dist/tools/web-search/types.js +1 -0
  76. package/dist/url-safety-tHZmtyx2.d.ts +11 -0
  77. package/dist/url-safety-tHZmtyx2.d.ts.map +1 -0
  78. package/package.json +81 -3
@@ -0,0 +1,383 @@
1
+ import { lookup } from "node:dns/promises";
2
+ import http from "node:http";
3
+ import https from "node:https";
4
+ import { BlockList, isIP } from "node:net";
5
+ // src/internal/url-safety.ts
6
+ const SENSITIVE_HEADERS = /* @__PURE__ */ new Set([
7
+ "authorization",
8
+ "proxy-authorization",
9
+ "cookie"
10
+ ]);
11
+ const BODY_HEADERS = /* @__PURE__ */ new Set([
12
+ "content-type",
13
+ "content-length",
14
+ "transfer-encoding"
15
+ ]);
16
+ const blockedIpv4 = new BlockList();
17
+ const blockedIpv6 = new BlockList();
18
+ for (const [network, prefix] of [
19
+ ["0.0.0.0", 8],
20
+ ["10.0.0.0", 8],
21
+ ["100.64.0.0", 10],
22
+ ["127.0.0.0", 8],
23
+ ["169.254.0.0", 16],
24
+ ["172.16.0.0", 12],
25
+ ["192.0.0.0", 24],
26
+ ["192.0.2.0", 24],
27
+ ["192.88.99.0", 24],
28
+ ["192.168.0.0", 16],
29
+ ["198.18.0.0", 15],
30
+ ["198.51.100.0", 24],
31
+ ["203.0.113.0", 24],
32
+ ["224.0.0.0", 4],
33
+ ["240.0.0.0", 4]
34
+ ]) blockedIpv4.addSubnet(network, prefix, "ipv4");
35
+ for (const [network, prefix] of [
36
+ ["::", 96],
37
+ ["::ffff:0:0", 96],
38
+ ["64:ff9b::", 96],
39
+ ["64:ff9b:1::", 48],
40
+ ["100::", 64],
41
+ ["2001::", 32],
42
+ ["2001:2::", 48],
43
+ ["2001:10::", 28],
44
+ ["2001:20::", 28],
45
+ ["2001:db8::", 32],
46
+ ["2002::", 16],
47
+ ["fc00::", 7],
48
+ ["fe80::", 10],
49
+ ["fec0::", 10],
50
+ ["ff00::", 8]
51
+ ]) blockedIpv6.addSubnet(network, prefix, "ipv6");
52
+ const defaultAddressResolver = (hostname) => lookup(hostname, {
53
+ all: true,
54
+ verbatim: true
55
+ });
56
+ function parseHttpUrl(rawUrl) {
57
+ let parsed;
58
+ try {
59
+ parsed = new URL(rawUrl);
60
+ } catch {
61
+ throw new Error(`Invalid URL: "${rawUrl}".`);
62
+ }
63
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error(`Blocked URL protocol "${parsed.protocol}": only http: and https: are allowed.`);
64
+ return parsed;
65
+ }
66
+ function isPrivateIpAddress(address) {
67
+ const normalized = normalizeHost(address);
68
+ const family = isIP(normalized);
69
+ if (family === 4) return blockedIpv4.check(normalized, "ipv4");
70
+ if (family === 6) {
71
+ if (normalized === "::1" || normalized === "::") return true;
72
+ return blockedIpv6.check(normalized, "ipv6");
73
+ }
74
+ return false;
75
+ }
76
+ async function assertSafeUrl(rawUrl, options = {}) {
77
+ const parsed = parseHttpUrl(rawUrl);
78
+ const hostname = normalizeHost(parsed.hostname);
79
+ if (hostname.length === 0) throw new Error("URL hostname must not be empty.");
80
+ if (options.allowedOrigins !== void 0) {
81
+ if (!new Set(options.allowedOrigins.map((origin) => origin.toLowerCase())).has(parsed.origin.toLowerCase())) throw new Error(`Origin "${parsed.origin}" is not in the allowedOrigins policy.`);
82
+ }
83
+ if (options.blockedHosts !== void 0 && matchesHostPatternList(hostname, options.blockedHosts)) throw new Error(`Host "${hostname}" is blocked by policy.`);
84
+ if (options.allowedHosts !== void 0) {
85
+ if (!matchesHostPatternList(hostname, options.allowedHosts)) throw new Error(`Host "${hostname}" is not in the allowedHosts policy.`);
86
+ }
87
+ if (!options.allowPrivateAddresses) {
88
+ if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname.endsWith(".local") || hostname.endsWith(".internal")) throw new Error(`Host "${hostname}" is blocked because private addresses are disallowed.`);
89
+ const literalFamily = isIP(hostname);
90
+ if (literalFamily !== 0) {
91
+ if (isPrivateIpAddress(hostname)) throw new Error(`IP address "${hostname}" is blocked because private addresses are disallowed.`);
92
+ return {
93
+ url: parsed,
94
+ addresses: [{
95
+ address: hostname,
96
+ family: literalFamily
97
+ }]
98
+ };
99
+ }
100
+ const addresses = await (options.resolveAddress ?? defaultAddressResolver)(hostname);
101
+ if (addresses.length === 0) throw new Error(`Could not resolve hostname "${hostname}".`);
102
+ for (const entry of addresses) if (isPrivateIpAddress(entry.address)) throw new Error(`Host "${hostname}" resolved to blocked private address "${entry.address}".`);
103
+ return {
104
+ url: parsed,
105
+ addresses
106
+ };
107
+ }
108
+ return {
109
+ url: parsed,
110
+ addresses: []
111
+ };
112
+ }
113
+ async function safeFetch(rawUrl, options = {}) {
114
+ const maxRedirects = options.maxRedirects ?? 5;
115
+ const maxBytes = options.maxBytes ?? 1e6;
116
+ const timeoutMs = options.timeoutMs ?? 15e3;
117
+ if (!Number.isSafeInteger(maxRedirects) || maxRedirects < 0) throw new RangeError("maxRedirects must be a non-negative safe integer.");
118
+ if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new RangeError("maxBytes must be a positive safe integer.");
119
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new RangeError("timeoutMs must be a positive finite number.");
120
+ const protectedHeaders = new Set(SENSITIVE_HEADERS);
121
+ for (const name of options.protectedHeaderNames ?? []) protectedHeaders.add(name.toLowerCase());
122
+ const allowedMethodSet = options.allowedMethods === void 0 ? void 0 : new Set(options.allowedMethods.map((m) => m.toUpperCase()));
123
+ const controller = new AbortController();
124
+ const timer = setTimeout(() => controller.abort(/* @__PURE__ */ new Error(`Request timed out after ${timeoutMs}ms.`)), timeoutMs);
125
+ const signal = options.abortSignal === void 0 ? controller.signal : AbortSignal.any([options.abortSignal, controller.signal]);
126
+ try {
127
+ let currentUrl = rawUrl;
128
+ let method = (options.method ?? "GET").toUpperCase();
129
+ let body = options.body;
130
+ let currentHeaders = normalizeHeaderMap(options.headers);
131
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
132
+ if (allowedMethodSet !== void 0 && !allowedMethodSet.has(method)) throw new Error(`HTTP method "${method}" is not allowed.`);
133
+ const validated = await assertSafeUrl(currentUrl, options);
134
+ const response = options.fetch !== void 0 ? await executeWithCustomFetch(options.fetch, validated.url, {
135
+ method,
136
+ headers: currentHeaders,
137
+ body,
138
+ maxBytes,
139
+ signal
140
+ }) : await executeWithPinnedNodeRequest(validated.url, validated.addresses, {
141
+ method,
142
+ headers: currentHeaders,
143
+ body,
144
+ maxBytes,
145
+ signal
146
+ });
147
+ if (isRedirectStatus(response.status)) {
148
+ const location = response.headers.location;
149
+ if (location === void 0) throw new Error(`Redirect response (${response.status}) missing Location header.`);
150
+ if (redirectCount === maxRedirects) throw new Error(`Exceeded maximum redirect limit (${maxRedirects}).`);
151
+ const nextUrl = new URL(location, validated.url);
152
+ const crossOrigin = nextUrl.origin.toLowerCase() !== validated.url.origin.toLowerCase();
153
+ if (validated.url.protocol === "https:" && nextUrl.protocol === "http:" && hasAnyHeader(currentHeaders, protectedHeaders)) throw new Error("Blocked redirect that downgrades from https: to http: while sensitive headers are present.");
154
+ if (crossOrigin) currentHeaders = omitHeaders(currentHeaders, protectedHeaders);
155
+ currentUrl = nextUrl.toString();
156
+ if (response.status === 303 && method !== "GET" && method !== "HEAD" || (response.status === 301 || response.status === 302) && method === "POST") {
157
+ method = "GET";
158
+ body = void 0;
159
+ currentHeaders = omitHeaders(currentHeaders, BODY_HEADERS);
160
+ }
161
+ continue;
162
+ }
163
+ return response;
164
+ }
165
+ throw new Error(`Exceeded maximum redirect limit (${maxRedirects}).`);
166
+ } finally {
167
+ clearTimeout(timer);
168
+ }
169
+ }
170
+ async function executeWithCustomFetch(fetchImpl, url, params) {
171
+ const requestInit = {
172
+ method: params.method,
173
+ redirect: "manual",
174
+ signal: params.signal
175
+ };
176
+ if (Object.keys(params.headers).length > 0) requestInit.headers = params.headers;
177
+ if (params.body !== void 0 && params.method !== "GET" && params.method !== "HEAD") requestInit.body = params.body;
178
+ const response = await fetchImpl(url.toString(), requestInit);
179
+ const headers = {};
180
+ response.headers.forEach((value, key) => {
181
+ headers[key.toLowerCase()] = value;
182
+ });
183
+ if (isRedirectStatus(response.status)) {
184
+ await response.body?.cancel().catch(() => {});
185
+ return {
186
+ url: url.toString(),
187
+ status: response.status,
188
+ statusText: response.statusText,
189
+ headers,
190
+ bodyText: "",
191
+ bodyTruncated: false,
192
+ byteLength: 0
193
+ };
194
+ }
195
+ const { text, truncated, byteLength } = await readResponseTextWithLimit(response, params.maxBytes);
196
+ return {
197
+ url: url.toString(),
198
+ status: response.status,
199
+ statusText: response.statusText,
200
+ headers,
201
+ bodyText: text,
202
+ bodyTruncated: truncated,
203
+ byteLength
204
+ };
205
+ }
206
+ function executeWithPinnedNodeRequest(url, pinnedAddresses, params) {
207
+ return new Promise((resolve, reject) => {
208
+ const transport = url.protocol === "https:" ? https : http;
209
+ const pinnedLookup = pinnedAddresses.length > 0 ? (_hostname, lookupOptions, callback) => {
210
+ if (typeof lookupOptions === "object" && lookupOptions !== null && lookupOptions.all) {
211
+ callback(null, pinnedAddresses.map((entry) => ({
212
+ address: entry.address,
213
+ family: entry.family
214
+ })));
215
+ return;
216
+ }
217
+ const first = pinnedAddresses[0];
218
+ callback(null, first.address, first.family);
219
+ } : void 0;
220
+ const reqOptions = {
221
+ protocol: url.protocol,
222
+ hostname: normalizeHost(url.hostname),
223
+ port: url.port === "" ? void 0 : Number(url.port),
224
+ path: `${url.pathname}${url.search}`,
225
+ method: params.method,
226
+ headers: {
227
+ host: url.host,
228
+ ...params.headers
229
+ },
230
+ signal: params.signal
231
+ };
232
+ if (pinnedLookup !== void 0) reqOptions.lookup = pinnedLookup;
233
+ if (url.protocol === "https:" && isIP(normalizeHost(url.hostname)) === 0) reqOptions.servername = normalizeHost(url.hostname);
234
+ const req = transport.request(reqOptions, (res) => {
235
+ const headers = {};
236
+ for (const [key, value] of Object.entries(res.headers)) {
237
+ if (value === void 0) continue;
238
+ headers[key.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
239
+ }
240
+ const status = res.statusCode ?? 0;
241
+ const statusText = res.statusMessage ?? "";
242
+ if (isRedirectStatus(status)) {
243
+ res.resume();
244
+ resolve({
245
+ url: url.toString(),
246
+ status,
247
+ statusText,
248
+ headers,
249
+ bodyText: "",
250
+ bodyTruncated: false,
251
+ byteLength: 0
252
+ });
253
+ return;
254
+ }
255
+ const chunks = [];
256
+ let totalBytes = 0;
257
+ let truncated = false;
258
+ let settled = false;
259
+ const finish = () => {
260
+ if (settled) return;
261
+ settled = true;
262
+ const combined = Buffer.concat(chunks, totalBytes);
263
+ const decoder = new TextDecoder("utf-8", { fatal: false });
264
+ resolve({
265
+ url: url.toString(),
266
+ status,
267
+ statusText,
268
+ headers,
269
+ bodyText: decoder.decode(combined),
270
+ bodyTruncated: truncated,
271
+ byteLength: totalBytes
272
+ });
273
+ };
274
+ res.on("data", (chunk) => {
275
+ if (settled) return;
276
+ const buf = typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk;
277
+ if (totalBytes + buf.byteLength > params.maxBytes) {
278
+ const remaining = params.maxBytes - totalBytes;
279
+ if (remaining > 0) {
280
+ chunks.push(buf.subarray(0, remaining));
281
+ totalBytes += remaining;
282
+ }
283
+ truncated = true;
284
+ res.destroy();
285
+ finish();
286
+ return;
287
+ }
288
+ chunks.push(buf);
289
+ totalBytes += buf.byteLength;
290
+ });
291
+ res.on("end", finish);
292
+ res.on("close", finish);
293
+ res.on("error", (error) => {
294
+ if (!settled) {
295
+ settled = true;
296
+ reject(error);
297
+ }
298
+ });
299
+ });
300
+ req.on("error", reject);
301
+ if (params.body !== void 0 && params.method !== "GET" && params.method !== "HEAD") req.write(params.body);
302
+ req.end();
303
+ });
304
+ }
305
+ async function readResponseTextWithLimit(response, maxBytes) {
306
+ if (response.body === null) return {
307
+ text: "",
308
+ truncated: false,
309
+ byteLength: 0
310
+ };
311
+ const reader = response.body.getReader();
312
+ const chunks = [];
313
+ let totalBytes = 0;
314
+ let truncated = false;
315
+ try {
316
+ while (true) {
317
+ const { done, value } = await reader.read();
318
+ if (done) break;
319
+ if (value === void 0) continue;
320
+ if (totalBytes + value.byteLength > maxBytes) {
321
+ const remaining = maxBytes - totalBytes;
322
+ if (remaining > 0) {
323
+ chunks.push(value.subarray(0, remaining));
324
+ totalBytes += remaining;
325
+ }
326
+ truncated = true;
327
+ await reader.cancel();
328
+ break;
329
+ }
330
+ chunks.push(value);
331
+ totalBytes += value.byteLength;
332
+ }
333
+ } finally {
334
+ reader.releaseLock();
335
+ }
336
+ const combined = new Uint8Array(totalBytes);
337
+ let offset = 0;
338
+ for (const chunk of chunks) {
339
+ combined.set(chunk, offset);
340
+ offset += chunk.byteLength;
341
+ }
342
+ return {
343
+ text: new TextDecoder("utf-8", { fatal: false }).decode(combined),
344
+ truncated,
345
+ byteLength: totalBytes
346
+ };
347
+ }
348
+ function isRedirectStatus(status) {
349
+ return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
350
+ }
351
+ function normalizeHost(hostname) {
352
+ return (hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname).trim().toLowerCase().replace(/\.+$/, "");
353
+ }
354
+ function matchesHostPatternList(hostname, patterns) {
355
+ for (const rawPattern of patterns) {
356
+ const pattern = normalizeHost(rawPattern);
357
+ if (pattern.length === 0) continue;
358
+ if (pattern === hostname) return true;
359
+ if (pattern.startsWith("*.")) {
360
+ const suffix = pattern.slice(1);
361
+ if (suffix.length > 1 && hostname.endsWith(suffix) && hostname.length > suffix.length) return true;
362
+ }
363
+ }
364
+ return false;
365
+ }
366
+ function normalizeHeaderMap(headers) {
367
+ if (headers === void 0) return {};
368
+ const out = {};
369
+ for (const [key, value] of Object.entries(headers)) out[key.toLowerCase()] = value;
370
+ return out;
371
+ }
372
+ function omitHeaders(headers, namesToOmit) {
373
+ const out = {};
374
+ for (const [key, value] of Object.entries(headers)) if (!namesToOmit.has(key.toLowerCase())) out[key] = value;
375
+ return out;
376
+ }
377
+ function hasAnyHeader(headers, names) {
378
+ for (const key of Object.keys(headers)) if (names.has(key.toLowerCase())) return true;
379
+ return false;
380
+ }
381
+ export { assertSafeUrl, isPrivateIpAddress, parseHttpUrl, safeFetch };
382
+
383
+ //# sourceMappingURL=url-safety.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-safety.js","names":[],"sources":["../../src/internal/url-safety.ts"],"sourcesContent":["import type { LookupAddress } from \"node:dns\";\nimport { lookup } from \"node:dns/promises\";\nimport http from \"node:http\";\nimport https from \"node:https\";\nimport type { LookupFunction } from \"node:net\";\nimport { BlockList, isIP } from \"node:net\";\n\nexport type AddressResolver = (hostname: string) => Promise<readonly LookupAddress[]>;\n\nexport type UrlSafetyOptions = {\n allowedHosts?: readonly string[] | undefined;\n blockedHosts?: readonly string[] | undefined;\n allowedOrigins?: readonly string[] | undefined;\n allowPrivateAddresses?: boolean | undefined;\n resolveAddress?: AddressResolver | undefined;\n};\n\nexport type SafeFetchOptions = UrlSafetyOptions & {\n method?: string | undefined;\n headers?: Record<string, string> | undefined;\n protectedHeaderNames?: readonly string[] | undefined;\n allowedMethods?: readonly string[] | undefined;\n body?: string | undefined;\n maxRedirects?: number | undefined;\n maxBytes?: number | undefined;\n timeoutMs?: number | undefined;\n abortSignal?: AbortSignal | undefined;\n fetch?: typeof globalThis.fetch | undefined;\n};\n\nexport type SafeFetchResponse = {\n url: string;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n bodyText: string;\n bodyTruncated: boolean;\n byteLength: number;\n};\n\nexport type ValidatedUrlResult = {\n url: URL;\n addresses: readonly LookupAddress[];\n};\n\nconst SENSITIVE_HEADERS = new Set([\"authorization\", \"proxy-authorization\", \"cookie\"]);\nconst BODY_HEADERS = new Set([\"content-type\", \"content-length\", \"transfer-encoding\"]);\n\nconst blockedIpv4 = new BlockList();\nconst blockedIpv6 = new BlockList();\n\nfor (const [network, prefix] of [\n [\"0.0.0.0\", 8],\n [\"10.0.0.0\", 8],\n [\"100.64.0.0\", 10],\n [\"127.0.0.0\", 8],\n [\"169.254.0.0\", 16],\n [\"172.16.0.0\", 12],\n [\"192.0.0.0\", 24],\n [\"192.0.2.0\", 24],\n [\"192.88.99.0\", 24],\n [\"192.168.0.0\", 16],\n [\"198.18.0.0\", 15],\n [\"198.51.100.0\", 24],\n [\"203.0.113.0\", 24],\n [\"224.0.0.0\", 4],\n [\"240.0.0.0\", 4],\n] as const) {\n blockedIpv4.addSubnet(network, prefix, \"ipv4\");\n}\n\nfor (const [network, prefix] of [\n [\"::\", 96],\n [\"::ffff:0:0\", 96],\n [\"64:ff9b::\", 96],\n [\"64:ff9b:1::\", 48],\n [\"100::\", 64],\n [\"2001::\", 32],\n [\"2001:2::\", 48],\n [\"2001:10::\", 28],\n [\"2001:20::\", 28],\n [\"2001:db8::\", 32],\n [\"2002::\", 16],\n [\"fc00::\", 7],\n [\"fe80::\", 10],\n [\"fec0::\", 10],\n [\"ff00::\", 8],\n] as const) {\n blockedIpv6.addSubnet(network, prefix, \"ipv6\");\n}\n\nconst defaultAddressResolver: AddressResolver = (hostname) =>\n lookup(hostname, { all: true, verbatim: true });\n\nexport function parseHttpUrl(rawUrl: string): URL {\n let parsed: URL;\n try {\n parsed = new URL(rawUrl);\n } catch {\n throw new Error(`Invalid URL: \"${rawUrl}\".`);\n }\n\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n throw new Error(\n `Blocked URL protocol \"${parsed.protocol}\": only http: and https: are allowed.`,\n );\n }\n\n return parsed;\n}\n\nexport function isPrivateIpAddress(address: string): boolean {\n const normalized = normalizeHost(address);\n const family = isIP(normalized);\n\n if (family === 4) {\n return blockedIpv4.check(normalized, \"ipv4\");\n }\n\n if (family === 6) {\n if (normalized === \"::1\" || normalized === \"::\") return true;\n\n return blockedIpv6.check(normalized, \"ipv6\");\n }\n\n return false;\n}\n\nexport async function assertSafeUrl(\n rawUrl: string,\n options: UrlSafetyOptions = {},\n): Promise<ValidatedUrlResult> {\n const parsed = parseHttpUrl(rawUrl);\n const hostname = normalizeHost(parsed.hostname);\n\n if (hostname.length === 0) {\n throw new Error(\"URL hostname must not be empty.\");\n }\n\n if (options.allowedOrigins !== undefined) {\n const allowedOriginSet = new Set(options.allowedOrigins.map((origin) => origin.toLowerCase()));\n\n if (!allowedOriginSet.has(parsed.origin.toLowerCase())) {\n throw new Error(`Origin \"${parsed.origin}\" is not in the allowedOrigins policy.`);\n }\n }\n\n if (\n options.blockedHosts !== undefined &&\n matchesHostPatternList(hostname, options.blockedHosts)\n ) {\n throw new Error(`Host \"${hostname}\" is blocked by policy.`);\n }\n\n if (options.allowedHosts !== undefined) {\n if (!matchesHostPatternList(hostname, options.allowedHosts)) {\n throw new Error(`Host \"${hostname}\" is not in the allowedHosts policy.`);\n }\n }\n\n if (!options.allowPrivateAddresses) {\n if (\n hostname === \"localhost\" ||\n hostname.endsWith(\".localhost\") ||\n hostname.endsWith(\".local\") ||\n hostname.endsWith(\".internal\")\n ) {\n throw new Error(`Host \"${hostname}\" is blocked because private addresses are disallowed.`);\n }\n\n const literalFamily = isIP(hostname);\n\n if (literalFamily !== 0) {\n if (isPrivateIpAddress(hostname)) {\n throw new Error(\n `IP address \"${hostname}\" is blocked because private addresses are disallowed.`,\n );\n }\n\n return { url: parsed, addresses: [{ address: hostname, family: literalFamily }] };\n }\n\n const resolve = options.resolveAddress ?? defaultAddressResolver;\n const addresses = await resolve(hostname);\n\n if (addresses.length === 0) {\n throw new Error(`Could not resolve hostname \"${hostname}\".`);\n }\n\n for (const entry of addresses) {\n if (isPrivateIpAddress(entry.address)) {\n throw new Error(\n `Host \"${hostname}\" resolved to blocked private address \"${entry.address}\".`,\n );\n }\n }\n\n return { url: parsed, addresses };\n }\n\n return { url: parsed, addresses: [] };\n}\n\nexport async function safeFetch(\n rawUrl: string,\n options: SafeFetchOptions = {},\n): Promise<SafeFetchResponse> {\n const maxRedirects = options.maxRedirects ?? 5;\n const maxBytes = options.maxBytes ?? 1_000_000;\n const timeoutMs = options.timeoutMs ?? 15_000;\n\n if (!Number.isSafeInteger(maxRedirects) || maxRedirects < 0) {\n throw new RangeError(\"maxRedirects must be a non-negative safe integer.\");\n }\n\n if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {\n throw new RangeError(\"maxBytes must be a positive safe integer.\");\n }\n\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n throw new RangeError(\"timeoutMs must be a positive finite number.\");\n }\n\n const protectedHeaders = new Set<string>(SENSITIVE_HEADERS);\n for (const name of options.protectedHeaderNames ?? []) {\n protectedHeaders.add(name.toLowerCase());\n }\n\n const allowedMethodSet =\n options.allowedMethods === undefined\n ? undefined\n : new Set(options.allowedMethods.map((m) => m.toUpperCase()));\n\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(new Error(`Request timed out after ${timeoutMs}ms.`)),\n timeoutMs,\n );\n const signal =\n options.abortSignal === undefined\n ? controller.signal\n : AbortSignal.any([options.abortSignal, controller.signal]);\n\n try {\n let currentUrl = rawUrl;\n let method = (options.method ?? \"GET\").toUpperCase();\n let body = options.body;\n let currentHeaders = normalizeHeaderMap(options.headers);\n\n for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {\n if (allowedMethodSet !== undefined && !allowedMethodSet.has(method)) {\n throw new Error(`HTTP method \"${method}\" is not allowed.`);\n }\n\n const validated = await assertSafeUrl(currentUrl, options);\n const response =\n options.fetch !== undefined\n ? await executeWithCustomFetch(options.fetch, validated.url, {\n method,\n headers: currentHeaders,\n body,\n maxBytes,\n signal,\n })\n : await executeWithPinnedNodeRequest(validated.url, validated.addresses, {\n method,\n headers: currentHeaders,\n body,\n maxBytes,\n signal,\n });\n\n if (isRedirectStatus(response.status)) {\n const location = response.headers.location;\n\n if (location === undefined) {\n throw new Error(`Redirect response (${response.status}) missing Location header.`);\n }\n\n if (redirectCount === maxRedirects) {\n throw new Error(`Exceeded maximum redirect limit (${maxRedirects}).`);\n }\n\n const nextUrl = new URL(location, validated.url);\n const crossOrigin = nextUrl.origin.toLowerCase() !== validated.url.origin.toLowerCase();\n const protocolDowngrade =\n validated.url.protocol === \"https:\" && nextUrl.protocol === \"http:\";\n\n if (protocolDowngrade && hasAnyHeader(currentHeaders, protectedHeaders)) {\n throw new Error(\n \"Blocked redirect that downgrades from https: to http: while sensitive headers are present.\",\n );\n }\n\n if (crossOrigin) {\n currentHeaders = omitHeaders(currentHeaders, protectedHeaders);\n }\n\n currentUrl = nextUrl.toString();\n\n if (\n (response.status === 303 && method !== \"GET\" && method !== \"HEAD\") ||\n ((response.status === 301 || response.status === 302) && method === \"POST\")\n ) {\n method = \"GET\";\n body = undefined;\n currentHeaders = omitHeaders(currentHeaders, BODY_HEADERS);\n }\n\n continue;\n }\n\n return response;\n }\n\n throw new Error(`Exceeded maximum redirect limit (${maxRedirects}).`);\n } finally {\n clearTimeout(timer);\n }\n}\n\nasync function executeWithCustomFetch(\n fetchImpl: typeof globalThis.fetch,\n url: URL,\n params: {\n method: string;\n headers: Record<string, string>;\n body: string | undefined;\n maxBytes: number;\n signal: AbortSignal;\n },\n): Promise<SafeFetchResponse> {\n const requestInit: RequestInit = {\n method: params.method,\n redirect: \"manual\",\n signal: params.signal,\n };\n\n if (Object.keys(params.headers).length > 0) {\n requestInit.headers = params.headers;\n }\n\n if (params.body !== undefined && params.method !== \"GET\" && params.method !== \"HEAD\") {\n requestInit.body = params.body;\n }\n\n const response = await fetchImpl(url.toString(), requestInit);\n const headers: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headers[key.toLowerCase()] = value;\n });\n\n if (isRedirectStatus(response.status)) {\n await response.body?.cancel().catch(() => {});\n return {\n url: url.toString(),\n status: response.status,\n statusText: response.statusText,\n headers,\n bodyText: \"\",\n bodyTruncated: false,\n byteLength: 0,\n };\n }\n\n const { text, truncated, byteLength } = await readResponseTextWithLimit(\n response,\n params.maxBytes,\n );\n return {\n url: url.toString(),\n status: response.status,\n statusText: response.statusText,\n headers,\n bodyText: text,\n bodyTruncated: truncated,\n byteLength,\n };\n}\n\nfunction executeWithPinnedNodeRequest(\n url: URL,\n pinnedAddresses: readonly LookupAddress[],\n params: {\n method: string;\n headers: Record<string, string>;\n body: string | undefined;\n maxBytes: number;\n signal: AbortSignal;\n },\n): Promise<SafeFetchResponse> {\n return new Promise<SafeFetchResponse>((resolve, reject) => {\n const transport = url.protocol === \"https:\" ? https : http;\n const pinnedLookup: LookupFunction | undefined =\n pinnedAddresses.length > 0\n ? (_hostname, lookupOptions, callback) => {\n if (typeof lookupOptions === \"object\" && lookupOptions !== null && lookupOptions.all) {\n callback(\n null,\n pinnedAddresses.map((entry) => ({\n address: entry.address,\n family: entry.family,\n })),\n );\n return;\n }\n\n const first = pinnedAddresses[0]!;\n callback(null, first.address, first.family);\n }\n : undefined;\n\n const reqOptions: https.RequestOptions = {\n protocol: url.protocol,\n hostname: normalizeHost(url.hostname),\n port: url.port === \"\" ? undefined : Number(url.port),\n path: `${url.pathname}${url.search}`,\n method: params.method,\n headers: {\n host: url.host,\n ...params.headers,\n },\n signal: params.signal,\n };\n\n if (pinnedLookup !== undefined) {\n reqOptions.lookup = pinnedLookup;\n }\n\n if (url.protocol === \"https:\" && isIP(normalizeHost(url.hostname)) === 0) {\n reqOptions.servername = normalizeHost(url.hostname);\n }\n\n const req = transport.request(reqOptions, (res) => {\n const headers: Record<string, string> = {};\n for (const [key, value] of Object.entries(res.headers)) {\n if (value === undefined) continue;\n\n headers[key.toLowerCase()] = Array.isArray(value) ? value.join(\", \") : value;\n }\n\n const status = res.statusCode ?? 0;\n const statusText = res.statusMessage ?? \"\";\n\n if (isRedirectStatus(status)) {\n res.resume();\n resolve({\n url: url.toString(),\n status,\n statusText,\n headers,\n bodyText: \"\",\n bodyTruncated: false,\n byteLength: 0,\n });\n return;\n }\n\n const chunks: Buffer[] = [];\n let totalBytes = 0;\n let truncated = false;\n let settled = false;\n\n const finish = () => {\n if (settled) return;\n\n settled = true;\n const combined = Buffer.concat(chunks, totalBytes);\n const decoder = new TextDecoder(\"utf-8\", { fatal: false });\n resolve({\n url: url.toString(),\n status,\n statusText,\n headers,\n bodyText: decoder.decode(combined),\n bodyTruncated: truncated,\n byteLength: totalBytes,\n });\n };\n\n res.on(\"data\", (chunk: Buffer | string) => {\n if (settled) return;\n\n const buf = typeof chunk === \"string\" ? Buffer.from(chunk, \"utf8\") : chunk;\n\n if (totalBytes + buf.byteLength > params.maxBytes) {\n const remaining = params.maxBytes - totalBytes;\n\n if (remaining > 0) {\n chunks.push(buf.subarray(0, remaining));\n totalBytes += remaining;\n }\n\n truncated = true;\n res.destroy();\n finish();\n return;\n }\n\n chunks.push(buf);\n totalBytes += buf.byteLength;\n });\n\n res.on(\"end\", finish);\n res.on(\"close\", finish);\n res.on(\"error\", (error) => {\n if (!settled) {\n settled = true;\n reject(error);\n }\n });\n });\n\n req.on(\"error\", reject);\n\n if (params.body !== undefined && params.method !== \"GET\" && params.method !== \"HEAD\") {\n req.write(params.body);\n }\n\n req.end();\n });\n}\n\nasync function readResponseTextWithLimit(\n response: Response,\n maxBytes: number,\n): Promise<{ text: string; truncated: boolean; byteLength: number }> {\n if (response.body === null) {\n return { text: \"\", truncated: false, byteLength: 0 };\n }\n\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let totalBytes = 0;\n let truncated = false;\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n if (value === undefined) continue;\n\n if (totalBytes + value.byteLength > maxBytes) {\n const remaining = maxBytes - totalBytes;\n\n if (remaining > 0) {\n chunks.push(value.subarray(0, remaining));\n totalBytes += remaining;\n }\n\n truncated = true;\n await reader.cancel();\n break;\n }\n\n chunks.push(value);\n totalBytes += value.byteLength;\n }\n } finally {\n reader.releaseLock();\n }\n\n const combined = new Uint8Array(totalBytes);\n let offset = 0;\n for (const chunk of chunks) {\n combined.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n const decoder = new TextDecoder(\"utf-8\", { fatal: false });\n return {\n text: decoder.decode(combined),\n truncated,\n byteLength: totalBytes,\n };\n}\n\nfunction isRedirectStatus(status: number): boolean {\n return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;\n}\n\nfunction normalizeHost(hostname: string): string {\n const unbracketed =\n hostname.startsWith(\"[\") && hostname.endsWith(\"]\") ? hostname.slice(1, -1) : hostname;\n return unbracketed.trim().toLowerCase().replace(/\\.+$/, \"\");\n}\n\nfunction matchesHostPatternList(hostname: string, patterns: readonly string[]): boolean {\n for (const rawPattern of patterns) {\n const pattern = normalizeHost(rawPattern);\n\n if (pattern.length === 0) continue;\n\n if (pattern === hostname) return true;\n\n if (pattern.startsWith(\"*.\")) {\n const suffix = pattern.slice(1);\n\n if (suffix.length > 1 && hostname.endsWith(suffix) && hostname.length > suffix.length) {\n return true;\n }\n }\n }\n return false;\n}\n\nfunction normalizeHeaderMap(headers: Record<string, string> | undefined): Record<string, string> {\n if (headers === undefined) return {};\n\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n out[key.toLowerCase()] = value;\n }\n return out;\n}\n\nfunction omitHeaders(\n headers: Record<string, string>,\n namesToOmit: ReadonlySet<string>,\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n if (!namesToOmit.has(key.toLowerCase())) {\n out[key] = value;\n }\n }\n return out;\n}\n\nfunction hasAnyHeader(headers: Record<string, string>, names: ReadonlySet<string>): boolean {\n for (const key of Object.keys(headers)) {\n if (names.has(key.toLowerCase())) return true;\n }\n return false;\n}\n"],"mappings":";;;;;AA6CA,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAiB;CAAuB;AAAQ,CAAC;AACpF,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAgB;CAAkB;AAAmB,CAAC;AAEpF,MAAM,cAAc,IAAI,UAAU;AAClC,MAAM,cAAc,IAAI,UAAU;AAElC,KAAK,MAAM,CAAC,SAAS,WAAW;CAC9B,CAAC,WAAW,CAAC;CACb,CAAC,YAAY,CAAC;CACd,CAAC,cAAc,EAAE;CACjB,CAAC,aAAa,CAAC;CACf,CAAC,eAAe,EAAE;CAClB,CAAC,cAAc,EAAE;CACjB,CAAC,aAAa,EAAE;CAChB,CAAC,aAAa,EAA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AAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAC/C,IAAI,CAAC,YAAY,IAAI,IAAI,YAAY,CAAC,GACpC,IAAI,OAAO;CAGf,OAAO;AACT;AAEA,SAAS,aAAa,SAAiC,OAAqC;CAC1F,KAAK,MAAM,OAAO,OAAO,KAAK,OAAO,GACnC,IAAI,MAAM,IAAI,IAAI,YAAY,CAAC,GAAG,OAAO;CAE3C,OAAO;AACT"}
@@ -0,0 +1,2 @@
1
+ import { a as ToolOutputLimitOptions, i as redactToolOutput, n as RedactToolOutputOptions, o as toolOutputLimit, r as redactCompletionRequest, t as RedactCompletionRequestOptions } from "../index-CzQBvrEU.js";
2
+ export { type RedactCompletionRequestOptions, type RedactToolOutputOptions, type ToolOutputLimitOptions, redactCompletionRequest, redactToolOutput, toolOutputLimit };
@@ -0,0 +1,3 @@
1
+ import { toolOutputLimit } from "./output-limit.js";
2
+ import { redactCompletionRequest, redactToolOutput } from "./redaction.js";
3
+ export { redactCompletionRequest, redactToolOutput, toolOutputLimit };
@@ -0,0 +1,91 @@
1
+ import { truncateText } from "../internal/truncate.js";
2
+ import { createMiddleware } from "@anvia/core/tool";
3
+ // src/middlewares/output-limit.ts
4
+ function toolOutputLimit(options) {
5
+ if (!Number.isSafeInteger(options.maxChars) || options.maxChars <= 0) throw new RangeError("toolOutputLimit maxChars must be a positive safe integer.");
6
+ const toolSet = options.tools === void 0 ? void 0 : new Set(options.tools);
7
+ const suffix = options.suffix ?? "\n...[truncated]";
8
+ return createMiddleware({ onToolOutput(args) {
9
+ if (toolSet !== void 0 && !toolSet.has(args.toolName)) return;
10
+ if (args.structuredResult !== void 0) return truncateStructuredResult(args.structuredResult, options.maxChars, suffix);
11
+ if (args.result.length <= options.maxChars) return;
12
+ const { text } = truncateText(args.result, options.maxChars, suffix);
13
+ return { result: text };
14
+ } });
15
+ }
16
+ function truncateStructuredResult(parts, maxChars, suffix) {
17
+ let totalChars = 0;
18
+ for (const part of parts) totalChars += textLengthOfPart(part);
19
+ if (totalChars <= maxChars) return;
20
+ const effectiveSuffix = maxChars > suffix.length ? suffix : "";
21
+ let remaining = maxChars - effectiveSuffix.length;
22
+ let suffixEmitted = effectiveSuffix.length === 0;
23
+ const nextParts = [];
24
+ for (const part of parts) {
25
+ if (part.type === "text") {
26
+ if (remaining <= 0) {
27
+ if (!suffixEmitted) {
28
+ nextParts.push({
29
+ type: "text",
30
+ text: effectiveSuffix
31
+ });
32
+ suffixEmitted = true;
33
+ }
34
+ continue;
35
+ }
36
+ if (part.text.length <= remaining) {
37
+ remaining -= part.text.length;
38
+ nextParts.push(part);
39
+ } else {
40
+ nextParts.push({
41
+ ...part,
42
+ text: `${part.text.slice(0, remaining)}${effectiveSuffix}`
43
+ });
44
+ remaining = 0;
45
+ suffixEmitted = true;
46
+ }
47
+ continue;
48
+ }
49
+ if (part.type === "file" && part.data.type === "text") {
50
+ if (remaining <= 0) {
51
+ if (!suffixEmitted) {
52
+ nextParts.push({
53
+ type: "text",
54
+ text: effectiveSuffix
55
+ });
56
+ suffixEmitted = true;
57
+ }
58
+ continue;
59
+ }
60
+ if (part.data.text.length <= remaining) {
61
+ remaining -= part.data.text.length;
62
+ nextParts.push(part);
63
+ } else {
64
+ nextParts.push({
65
+ ...part,
66
+ data: {
67
+ type: "text",
68
+ text: `${part.data.text.slice(0, remaining)}${effectiveSuffix}`
69
+ }
70
+ });
71
+ remaining = 0;
72
+ suffixEmitted = true;
73
+ }
74
+ continue;
75
+ }
76
+ nextParts.push(part);
77
+ }
78
+ if (!suffixEmitted) nextParts.push({
79
+ type: "text",
80
+ text: effectiveSuffix
81
+ });
82
+ return { structuredResult: nextParts };
83
+ }
84
+ function textLengthOfPart(part) {
85
+ if (part.type === "text") return part.text.length;
86
+ if (part.type === "file" && part.data.type === "text") return part.data.text.length;
87
+ return 0;
88
+ }
89
+ export { toolOutputLimit };
90
+
91
+ //# sourceMappingURL=output-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-limit.js","names":[],"sources":["../../src/middlewares/output-limit.ts"],"sourcesContent":["import type { ToolResultContentPart } from \"@anvia/core/completion\";\nimport { type AgentMiddleware, createMiddleware } from \"@anvia/core/tool\";\nimport { truncateText } from \"../internal/truncate\";\n\nexport type ToolOutputLimitOptions = {\n /** Maximum characters allowed per tool output before truncating. */\n maxChars: number;\n /** Optional allowlist of tool names to limit. Applies to all tools when omitted. */\n tools?: readonly string[] | undefined;\n /** Suffix appended when truncated. Default `\"\\n...[truncated]\"`. */\n suffix?: string | undefined;\n};\n\nexport function toolOutputLimit(options: ToolOutputLimitOptions): AgentMiddleware {\n if (!Number.isSafeInteger(options.maxChars) || options.maxChars <= 0) {\n throw new RangeError(\"toolOutputLimit maxChars must be a positive safe integer.\");\n }\n\n const toolSet = options.tools === undefined ? undefined : new Set(options.tools);\n const suffix = options.suffix ?? \"\\n...[truncated]\";\n\n return createMiddleware({\n onToolOutput(args) {\n if (toolSet !== undefined && !toolSet.has(args.toolName)) {\n return undefined;\n }\n\n if (args.structuredResult !== undefined) {\n return truncateStructuredResult(args.structuredResult, options.maxChars, suffix);\n }\n\n if (args.result.length <= options.maxChars) {\n return undefined;\n }\n\n const { text } = truncateText(args.result, options.maxChars, suffix);\n return { result: text };\n },\n });\n}\n\nfunction truncateStructuredResult(\n parts: readonly ToolResultContentPart[],\n maxChars: number,\n suffix: string,\n): { structuredResult: ToolResultContentPart[] } | undefined {\n let totalChars = 0;\n for (const part of parts) {\n totalChars += textLengthOfPart(part);\n }\n\n if (totalChars <= maxChars) {\n return undefined;\n }\n\n const effectiveSuffix = maxChars > suffix.length ? suffix : \"\";\n let remaining = maxChars - effectiveSuffix.length;\n let suffixEmitted = effectiveSuffix.length === 0;\n const nextParts: ToolResultContentPart[] = [];\n\n for (const part of parts) {\n if (part.type === \"text\") {\n if (remaining <= 0) {\n if (!suffixEmitted) {\n nextParts.push({ type: \"text\", text: effectiveSuffix });\n suffixEmitted = true;\n }\n\n continue;\n }\n\n if (part.text.length <= remaining) {\n remaining -= part.text.length;\n nextParts.push(part);\n } else {\n nextParts.push({\n ...part,\n text: `${part.text.slice(0, remaining)}${effectiveSuffix}`,\n });\n remaining = 0;\n suffixEmitted = true;\n }\n\n continue;\n }\n\n if (part.type === \"file\" && part.data.type === \"text\") {\n if (remaining <= 0) {\n if (!suffixEmitted) {\n nextParts.push({ type: \"text\", text: effectiveSuffix });\n suffixEmitted = true;\n }\n\n continue;\n }\n\n if (part.data.text.length <= remaining) {\n remaining -= part.data.text.length;\n nextParts.push(part);\n } else {\n nextParts.push({\n ...part,\n data: { type: \"text\", text: `${part.data.text.slice(0, remaining)}${effectiveSuffix}` },\n });\n remaining = 0;\n suffixEmitted = true;\n }\n\n continue;\n }\n\n nextParts.push(part);\n }\n\n if (!suffixEmitted) {\n nextParts.push({ type: \"text\", text: effectiveSuffix });\n }\n\n return { structuredResult: nextParts };\n}\n\nfunction textLengthOfPart(part: ToolResultContentPart): number {\n if (part.type === \"text\") return part.text.length;\n\n if (part.type === \"file\" && part.data.type === \"text\") return part.data.text.length;\n\n return 0;\n}\n"],"mappings":";;;AAaA,SAAgB,gBAAgB,SAAkD;CAChF,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,KAAK,QAAQ,YAAY,GACjE,MAAM,IAAI,WAAW,2DAA2D;CAGlF,MAAM,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,IAAI,IAAI,QAAQ,KAAK;CAC/E,MAAM,SAAS,QAAQ,UAAU;CAEjC,OAAO,iBAAiB,EACtB,aAAa,MAAM;EACjB,IAAI,YAAY,KAAA,KAAa,CAAC,QAAQ,IAAI,KAAK,QAAQ,GACrD;EAGF,IAAI,KAAK,qBAAqB,KAAA,GAC5B,OAAO,yBAAyB,KAAK,kBAAkB,QAAQ,UAAU,MAAM;EAGjF,IAAI,KAAK,OAAO,UAAU,QAAQ,UAChC;EAGF,MAAM,EAAE,SAAS,aAAa,KAAK,QAAQ,QAAQ,UAAU,MAAM;EACnE,OAAO,EA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