@junando/worker 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{checksum-B7SAT8oI.cjs → checksum-AM2soALR.cjs} +276 -241
- package/dist/{checksum-BKPTTLSe.cjs → checksum-DYd9h1Z6.cjs} +242 -232
- package/dist/{event-streams-B7_gEE-_.cjs → event-streams-cGG6y4x_.cjs} +37 -37
- package/dist/{event-streams-DNZOvjgj.cjs → event-streams-x0B21mfk.cjs} +37 -37
- package/dist/handler.cjs +10440 -9351
- package/dist/{node-BzYEGMG1.cjs → node-BYAxz9X-.cjs} +33 -24
- package/dist/{sdk-BD78kZ4E.cjs → sdk-a89HQ1X4.cjs} +2037 -452
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./rolldown-runtime-CfAboj1T.cjs');
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
3
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/tslib.mjs
|
|
4
4
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
5
5
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
6
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -14,7 +14,7 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
//#endregion
|
|
17
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
17
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/uuid.mjs
|
|
18
18
|
/**
|
|
19
19
|
* https://stackoverflow.com/a/2117523
|
|
20
20
|
*/
|
|
@@ -30,7 +30,7 @@ let uuid4 = function() {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
//#endregion
|
|
33
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
33
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/errors.mjs
|
|
34
34
|
function isAbortError(err) {
|
|
35
35
|
return typeof err === "object" && err !== null && ("name" in err && err.name === "AbortError" || "message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
36
36
|
}
|
|
@@ -54,7 +54,7 @@ const castToError = (err) => {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
//#endregion
|
|
57
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
57
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/error.mjs
|
|
58
58
|
var AnthropicError = class extends Error {};
|
|
59
59
|
var APIError = class APIError extends AnthropicError {
|
|
60
60
|
constructor(status, error, message, headers, type) {
|
|
@@ -152,7 +152,7 @@ var RateLimitError = class extends APIError {};
|
|
|
152
152
|
var InternalServerError = class extends APIError {};
|
|
153
153
|
|
|
154
154
|
//#endregion
|
|
155
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
155
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/values.mjs
|
|
156
156
|
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
157
157
|
const isAbsoluteURL = (url) => {
|
|
158
158
|
return startsWithSchemeRegexp.test(url);
|
|
@@ -239,7 +239,7 @@ const pop = (obj, key) => {
|
|
|
239
239
|
};
|
|
240
240
|
|
|
241
241
|
//#endregion
|
|
242
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
242
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs
|
|
243
243
|
/**
|
|
244
244
|
* Resolve after `ms`, or immediately when `signal` aborts.
|
|
245
245
|
*
|
|
@@ -262,11 +262,11 @@ const sleep = (ms, signal) => new Promise((resolve) => {
|
|
|
262
262
|
});
|
|
263
263
|
|
|
264
264
|
//#endregion
|
|
265
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
266
|
-
const VERSION = "0.
|
|
265
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/version.mjs
|
|
266
|
+
const VERSION = "0.112.3";
|
|
267
267
|
|
|
268
268
|
//#endregion
|
|
269
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
269
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/detect-platform.mjs
|
|
270
270
|
const isRunningInBrowser = () => {
|
|
271
271
|
return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof navigator !== "undefined";
|
|
272
272
|
};
|
|
@@ -407,7 +407,7 @@ const getPlatformHeaders = () => {
|
|
|
407
407
|
};
|
|
408
408
|
|
|
409
409
|
//#endregion
|
|
410
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
410
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/shims.mjs
|
|
411
411
|
function getDefaultFetch() {
|
|
412
412
|
if (typeof fetch !== "undefined") {
|
|
413
413
|
return fetch;
|
|
@@ -489,7 +489,16 @@ async function CancelReadableStream(stream) {
|
|
|
489
489
|
}
|
|
490
490
|
|
|
491
491
|
//#endregion
|
|
492
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
492
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/request-options.mjs
|
|
493
|
+
/**
|
|
494
|
+
* Tracks which fallback a sequence of requests is pinned to.
|
|
495
|
+
*
|
|
496
|
+
* Create one (`new BetaFallbackState()`) and pass it via the `fallbackState`
|
|
497
|
+
* request option on every request that should share the pin — the turns of one
|
|
498
|
+
* conversation, or any wider scope the stickiness should apply to;
|
|
499
|
+
* `betaRefusalFallbackMiddleware` mutates it in place when a model refuses.
|
|
500
|
+
*/
|
|
501
|
+
var BetaFallbackState = class {};
|
|
493
502
|
const FallbackEncoder = ({ headers, body }) => {
|
|
494
503
|
return {
|
|
495
504
|
bodyHeaders: { "content-type": "application/json" },
|
|
@@ -498,7 +507,7 @@ const FallbackEncoder = ({ headers, body }) => {
|
|
|
498
507
|
};
|
|
499
508
|
|
|
500
509
|
//#endregion
|
|
501
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
510
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/qs/formats.mjs
|
|
502
511
|
const default_format = "RFC3986";
|
|
503
512
|
const default_formatter = (v) => String(v);
|
|
504
513
|
const formatters = {
|
|
@@ -509,7 +518,7 @@ const RFC1738 = "RFC1738";
|
|
|
509
518
|
const RFC3986 = "RFC3986";
|
|
510
519
|
|
|
511
520
|
//#endregion
|
|
512
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
521
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/qs/utils.mjs
|
|
513
522
|
let has = (obj, key) => (has = Object.hasOwn ?? Function.prototype.call.bind(Object.prototype.hasOwnProperty), has(obj, key));
|
|
514
523
|
const hex_table = /* @__PURE__ */ (() => {
|
|
515
524
|
const array = [];
|
|
@@ -703,7 +712,7 @@ function maybe_map(val, fn) {
|
|
|
703
712
|
}
|
|
704
713
|
|
|
705
714
|
//#endregion
|
|
706
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
715
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/qs/stringify.mjs
|
|
707
716
|
const array_prefix_generators = {
|
|
708
717
|
brackets(prefix) {
|
|
709
718
|
return String(prefix) + "[]";
|
|
@@ -931,13 +940,13 @@ function stringify(object, opts = {}) {
|
|
|
931
940
|
}
|
|
932
941
|
|
|
933
942
|
//#endregion
|
|
934
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
943
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/query.mjs
|
|
935
944
|
function stringifyQuery(query) {
|
|
936
945
|
return stringify(query, { arrayFormat: "brackets" });
|
|
937
946
|
}
|
|
938
947
|
|
|
939
948
|
//#endregion
|
|
940
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
949
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/credentials/types.mjs
|
|
941
950
|
const GRANT_TYPE_JWT_BEARER = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
942
951
|
const GRANT_TYPE_REFRESH_TOKEN = "refresh_token";
|
|
943
952
|
const TOKEN_ENDPOINT = "/v1/oauth/token";
|
|
@@ -1138,14 +1147,14 @@ var WorkloadIdentityError = class extends AnthropicError {
|
|
|
1138
1147
|
};
|
|
1139
1148
|
|
|
1140
1149
|
//#endregion
|
|
1141
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1150
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/time.mjs
|
|
1142
1151
|
/** Current time as unix epoch seconds. */
|
|
1143
1152
|
function nowAsSeconds() {
|
|
1144
1153
|
return Math.floor(Date.now() / 1e3);
|
|
1145
1154
|
}
|
|
1146
1155
|
|
|
1147
1156
|
//#endregion
|
|
1148
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1157
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/credentials/token-cache.mjs
|
|
1149
1158
|
/**
|
|
1150
1159
|
* Wraps an {@link AccessTokenProvider} with two-tier proactive refresh
|
|
1151
1160
|
* and concurrent deduplication.
|
|
@@ -1251,7 +1260,7 @@ var TokenCache = class {
|
|
|
1251
1260
|
};
|
|
1252
1261
|
|
|
1253
1262
|
//#endregion
|
|
1254
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1263
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/env.mjs
|
|
1255
1264
|
/**
|
|
1256
1265
|
* Read an environment variable.
|
|
1257
1266
|
*
|
|
@@ -1270,7 +1279,7 @@ const readEnv = (env) => {
|
|
|
1270
1279
|
};
|
|
1271
1280
|
|
|
1272
1281
|
//#endregion
|
|
1273
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1282
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/bytes.mjs
|
|
1274
1283
|
function concatBytes(buffers) {
|
|
1275
1284
|
let length = 0;
|
|
1276
1285
|
for (const buffer of buffers) {
|
|
@@ -1296,7 +1305,7 @@ function decodeUTF8(bytes) {
|
|
|
1296
1305
|
}
|
|
1297
1306
|
|
|
1298
1307
|
//#endregion
|
|
1299
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1308
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/base64.mjs
|
|
1300
1309
|
const toBase64 = (data) => {
|
|
1301
1310
|
if (!data) return "";
|
|
1302
1311
|
if (typeof globalThis.Buffer !== "undefined") {
|
|
@@ -1327,7 +1336,8 @@ const fromBase64 = (str) => {
|
|
|
1327
1336
|
};
|
|
1328
1337
|
|
|
1329
1338
|
//#endregion
|
|
1330
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1339
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/log.mjs
|
|
1340
|
+
const defaultLogLevel = "warn";
|
|
1331
1341
|
const levelNumbers = {
|
|
1332
1342
|
off: 0,
|
|
1333
1343
|
error: 200,
|
|
@@ -1335,14 +1345,14 @@ const levelNumbers = {
|
|
|
1335
1345
|
info: 400,
|
|
1336
1346
|
debug: 500
|
|
1337
1347
|
};
|
|
1338
|
-
const parseLogLevel = (maybeLevel, sourceName,
|
|
1348
|
+
const parseLogLevel = (maybeLevel, sourceName, logger) => {
|
|
1339
1349
|
if (!maybeLevel) {
|
|
1340
1350
|
return undefined;
|
|
1341
1351
|
}
|
|
1342
1352
|
if (hasOwn(levelNumbers, maybeLevel)) {
|
|
1343
1353
|
return maybeLevel;
|
|
1344
1354
|
}
|
|
1345
|
-
|
|
1355
|
+
logger.warn(`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(Object.keys(levelNumbers))}`);
|
|
1346
1356
|
return undefined;
|
|
1347
1357
|
};
|
|
1348
1358
|
function noop() {}
|
|
@@ -1360,12 +1370,7 @@ const noopLogger = {
|
|
|
1360
1370
|
debug: noop
|
|
1361
1371
|
};
|
|
1362
1372
|
let cachedLoggers = /* @__PURE__ */ new WeakMap();
|
|
1363
|
-
function
|
|
1364
|
-
const logger = client.logger;
|
|
1365
|
-
const logLevel = client.logLevel ?? "off";
|
|
1366
|
-
if (!logger) {
|
|
1367
|
-
return noopLogger;
|
|
1368
|
-
}
|
|
1373
|
+
function filterLogger(logger, logLevel) {
|
|
1369
1374
|
const cachedLogger = cachedLoggers.get(logger);
|
|
1370
1375
|
if (cachedLogger && cachedLogger[0] === logLevel) {
|
|
1371
1376
|
return cachedLogger[1];
|
|
@@ -1379,6 +1384,32 @@ function loggerFor(client) {
|
|
|
1379
1384
|
cachedLoggers.set(logger, [logLevel, levelLogger]);
|
|
1380
1385
|
return levelLogger;
|
|
1381
1386
|
}
|
|
1387
|
+
function loggerFor(client) {
|
|
1388
|
+
const logger = client.logger;
|
|
1389
|
+
const logLevel = client.logLevel ?? "off";
|
|
1390
|
+
if (!logger) {
|
|
1391
|
+
return noopLogger;
|
|
1392
|
+
}
|
|
1393
|
+
return filterLogger(logger, logLevel);
|
|
1394
|
+
}
|
|
1395
|
+
let lastEnvLevel;
|
|
1396
|
+
let cachedDefaultLogger;
|
|
1397
|
+
/**
|
|
1398
|
+
* A logger matching the client defaults — `console`, filtered to
|
|
1399
|
+
* `ANTHROPIC_LOG` or {@link defaultLogLevel} — for contexts with no client to
|
|
1400
|
+
* read the configured `logger`/`logLevel` from.
|
|
1401
|
+
*
|
|
1402
|
+
* Cached per `ANTHROPIC_LOG` value so an invalid value warns once, like a
|
|
1403
|
+
* client construction does, rather than on every request.
|
|
1404
|
+
*/
|
|
1405
|
+
function defaultLogger() {
|
|
1406
|
+
const envLevel = readEnv("ANTHROPIC_LOG");
|
|
1407
|
+
if (!cachedDefaultLogger || envLevel !== lastEnvLevel) {
|
|
1408
|
+
lastEnvLevel = envLevel;
|
|
1409
|
+
cachedDefaultLogger = filterLogger(console, parseLogLevel(envLevel, "process.env['ANTHROPIC_LOG']", filterLogger(console, "warn")) ?? "warn");
|
|
1410
|
+
}
|
|
1411
|
+
return cachedDefaultLogger;
|
|
1412
|
+
}
|
|
1382
1413
|
const formatRequestDetails = (details) => {
|
|
1383
1414
|
if (details.options) {
|
|
1384
1415
|
details.options = { ...details.options };
|
|
@@ -1397,7 +1428,7 @@ const formatRequestDetails = (details) => {
|
|
|
1397
1428
|
};
|
|
1398
1429
|
|
|
1399
1430
|
//#endregion
|
|
1400
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1431
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/credentials.mjs
|
|
1401
1432
|
/** Current schema version written to `configs/<profile>.json`. Absent on read ⇒ "1.0". */
|
|
1402
1433
|
const CONFIG_FILE_VERSION = "1.0";
|
|
1403
1434
|
/** Current schema version written to `credentials/<profile>.json`. Absent on read ⇒ "1.0". */
|
|
@@ -1662,7 +1693,7 @@ const getActiveProfileName = async () => {
|
|
|
1662
1693
|
};
|
|
1663
1694
|
|
|
1664
1695
|
//#endregion
|
|
1665
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1696
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/credentials/identity-token.mjs
|
|
1666
1697
|
/**
|
|
1667
1698
|
* Reads a JWT from a file on every call. Supports automatic rotation
|
|
1668
1699
|
* (e.g. Kubernetes projected service-account tokens).
|
|
@@ -1697,7 +1728,7 @@ function identityTokenFromValue(token) {
|
|
|
1697
1728
|
}
|
|
1698
1729
|
|
|
1699
1730
|
//#endregion
|
|
1700
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1731
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/credentials/oidc-federation.mjs
|
|
1701
1732
|
/**
|
|
1702
1733
|
* Exchanges an external OIDC JWT for an Anthropic access token via the
|
|
1703
1734
|
* RFC 7523 jwt-bearer grant.
|
|
@@ -1735,7 +1766,7 @@ function oidcFederationProvider(config) {
|
|
|
1735
1766
|
headers: {
|
|
1736
1767
|
"Content-Type": "application/json",
|
|
1737
1768
|
"anthropic-beta": `${OAUTH_API_BETA_HEADER},${FEDERATION_BETA_HEADER}`,
|
|
1738
|
-
"User-Agent": config.userAgent || `anthropic-sdk-typescript/${"0.
|
|
1769
|
+
"User-Agent": config.userAgent || `anthropic-sdk-typescript/${"0.112.3"} oidcFederationProvider`
|
|
1739
1770
|
},
|
|
1740
1771
|
body: JSON.stringify(body)
|
|
1741
1772
|
});
|
|
@@ -1766,7 +1797,7 @@ function oidcFederationProvider(config) {
|
|
|
1766
1797
|
}
|
|
1767
1798
|
|
|
1768
1799
|
//#endregion
|
|
1769
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1800
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/credentials/user-oauth.mjs
|
|
1770
1801
|
/**
|
|
1771
1802
|
* Reads a user-oauth credential file. Returns the cached access token while
|
|
1772
1803
|
* fresh; on expiry performs a `refresh_token` grant and writes the new
|
|
@@ -1821,7 +1852,7 @@ function userOAuthProvider(config) {
|
|
|
1821
1852
|
headers: {
|
|
1822
1853
|
"Content-Type": "application/json",
|
|
1823
1854
|
"anthropic-beta": OAUTH_API_BETA_HEADER,
|
|
1824
|
-
"User-Agent": config.userAgent || `anthropic-sdk-typescript/${"0.
|
|
1855
|
+
"User-Agent": config.userAgent || `anthropic-sdk-typescript/${"0.112.3"} userOAuthProvider`
|
|
1825
1856
|
},
|
|
1826
1857
|
body: JSON.stringify(body)
|
|
1827
1858
|
});
|
|
@@ -1856,7 +1887,7 @@ function userOAuthProvider(config) {
|
|
|
1856
1887
|
}
|
|
1857
1888
|
|
|
1858
1889
|
//#endregion
|
|
1859
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
1890
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/credentials/credential-chain.mjs
|
|
1860
1891
|
function resolveCredentialsFromConfig(config, options) {
|
|
1861
1892
|
const credentialsPath = config.authentication.credentials_path ?? null;
|
|
1862
1893
|
const effectiveBaseURL = (config.base_url || options.baseURL).replace(/\/+$/, "");
|
|
@@ -2029,7 +2060,7 @@ function cachedExchangeProvider(exchange, credentialsPath, onCacheWriteError, on
|
|
|
2029
2060
|
}
|
|
2030
2061
|
|
|
2031
2062
|
//#endregion
|
|
2032
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2063
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/decoders/line.mjs
|
|
2033
2064
|
var _LineDecoder_buffer;
|
|
2034
2065
|
var _LineDecoder_carriageReturnIndex;
|
|
2035
2066
|
/**
|
|
@@ -2130,7 +2161,7 @@ function findDoubleNewlineIndex(buffer) {
|
|
|
2130
2161
|
}
|
|
2131
2162
|
|
|
2132
2163
|
//#endregion
|
|
2133
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2164
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/streaming.mjs
|
|
2134
2165
|
var _Stream_client;
|
|
2135
2166
|
var Stream = class Stream {
|
|
2136
2167
|
constructor(iterator, controller, client) {
|
|
@@ -2139,6 +2170,17 @@ var Stream = class Stream {
|
|
|
2139
2170
|
this.controller = controller;
|
|
2140
2171
|
__classPrivateFieldSet(this, _Stream_client, client, "f");
|
|
2141
2172
|
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Iterate the raw Server-Sent Events from `response` — `{event, data, raw}`
|
|
2175
|
+
* objects, before any JSON parsing or event-name filtering.
|
|
2176
|
+
*
|
|
2177
|
+
* This reads `response.body` directly (not a clone), so the response is
|
|
2178
|
+
* consumed. Use this in middleware that fully replaces the stream body; for
|
|
2179
|
+
* read-only observation of parsed events, use `ctx.parse()` instead.
|
|
2180
|
+
*/
|
|
2181
|
+
static rawEvents(response, controller = new AbortController()) {
|
|
2182
|
+
return _iterSSEMessages(response, controller);
|
|
2183
|
+
}
|
|
2142
2184
|
static fromSSEResponse(response, controller, client) {
|
|
2143
2185
|
let consumed = false;
|
|
2144
2186
|
const logger = client ? loggerFor(client) : console;
|
|
@@ -2159,7 +2201,7 @@ var Stream = class Stream {
|
|
|
2159
2201
|
throw e;
|
|
2160
2202
|
}
|
|
2161
2203
|
}
|
|
2162
|
-
if (sse.event === "message_start" || sse.event === "message_delta" || sse.event === "message_stop" || sse.event === "content_block_start" || sse.event === "content_block_delta" || sse.event === "content_block_stop" || sse.event === "message" || sse.event === "user.message" || sse.event === "user.interrupt" || sse.event === "user.tool_confirmation" || sse.event === "user.custom_tool_result" || sse.event === "user.tool_result" || sse.event === "agent.message" || sse.event === "agent.thinking" || sse.event === "agent.tool_use" || sse.event === "agent.tool_result" || sse.event === "agent.mcp_tool_use" || sse.event === "agent.mcp_tool_result" || sse.event === "agent.custom_tool_use" || sse.event === "agent.thread_context_compacted" || sse.event === "session.status_running" || sse.event === "session.status_idle" || sse.event === "session.status_rescheduled" || sse.event === "session.status_terminated" || sse.event === "session.error" || sse.event === "session.deleted" || sse.event === "session.updated" || sse.event === "span.model_request_start" || sse.event === "span.model_request_end" || sse.event === "span.outcome_evaluation_start" || sse.event === "span.outcome_evaluation_ongoing" || sse.event === "span.outcome_evaluation_end" || sse.event === "user.define_outcome" || sse.event === "agent.thread_message_received" || sse.event === "agent.thread_message_sent" || sse.event === "agent.session_thread_message_received" || sse.event === "agent.session_thread_message_sent" || sse.event === "session.thread_created" || sse.event === "session.thread_status_created" || sse.event === "session.thread_status_running" || sse.event === "session.thread_status_idle" || sse.event === "session.thread_status_rescheduled" || sse.event === "session.thread_status_terminated") {
|
|
2204
|
+
if (sse.event === "message_start" || sse.event === "message_delta" || sse.event === "message_stop" || sse.event === "content_block_start" || sse.event === "content_block_delta" || sse.event === "content_block_stop" || sse.event === "message" || sse.event === "user.message" || sse.event === "user.interrupt" || sse.event === "user.tool_confirmation" || sse.event === "user.custom_tool_result" || sse.event === "user.tool_result" || sse.event === "agent.message" || sse.event === "agent.thinking" || sse.event === "agent.tool_use" || sse.event === "agent.tool_result" || sse.event === "agent.mcp_tool_use" || sse.event === "agent.mcp_tool_result" || sse.event === "agent.custom_tool_use" || sse.event === "agent.thread_context_compacted" || sse.event === "session.status_running" || sse.event === "session.status_idle" || sse.event === "session.status_rescheduled" || sse.event === "session.status_terminated" || sse.event === "session.error" || sse.event === "session.deleted" || sse.event === "session.updated" || sse.event === "span.model_request_start" || sse.event === "span.model_request_end" || sse.event === "span.outcome_evaluation_start" || sse.event === "span.outcome_evaluation_ongoing" || sse.event === "span.outcome_evaluation_end" || sse.event === "user.define_outcome" || sse.event === "agent.thread_message_received" || sse.event === "agent.thread_message_sent" || sse.event === "agent.session_thread_message_received" || sse.event === "agent.session_thread_message_sent" || sse.event === "session.thread_created" || sse.event === "session.thread_status_created" || sse.event === "session.thread_status_running" || sse.event === "session.thread_status_idle" || sse.event === "session.thread_status_rescheduled" || sse.event === "session.thread_status_terminated" || sse.event === "event_start" || sse.event === "event_delta" || sse.event === "system.message") {
|
|
2163
2205
|
try {
|
|
2164
2206
|
yield JSON.parse(sse.data);
|
|
2165
2207
|
} catch (e) {
|
|
@@ -2379,15 +2421,12 @@ function partition(str, delimiter) {
|
|
|
2379
2421
|
}
|
|
2380
2422
|
|
|
2381
2423
|
//#endregion
|
|
2382
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2424
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/parse.mjs
|
|
2383
2425
|
async function defaultParseResponse(client, props) {
|
|
2384
2426
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
2385
2427
|
const body = await (async () => {
|
|
2386
2428
|
if (props.options.stream) {
|
|
2387
2429
|
loggerFor(client).debug("response", response.status, response.url, response.headers, response.body);
|
|
2388
|
-
if (props.options.__streamClass) {
|
|
2389
|
-
return props.options.__streamClass.fromSSEResponse(response, props.controller);
|
|
2390
|
-
}
|
|
2391
2430
|
return Stream.fromSSEResponse(response, props.controller);
|
|
2392
2431
|
}
|
|
2393
2432
|
if (response.status === 204) {
|
|
@@ -2430,7 +2469,7 @@ function addRequestID(value, response) {
|
|
|
2430
2469
|
}
|
|
2431
2470
|
|
|
2432
2471
|
//#endregion
|
|
2433
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2472
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/middleware.mjs
|
|
2434
2473
|
/**
|
|
2435
2474
|
* Errors thrown by the underlying `fetch`, as opposed to by a middleware.
|
|
2436
2475
|
*
|
|
@@ -2471,14 +2510,18 @@ function isRetryableError(err) {
|
|
|
2471
2510
|
*
|
|
2472
2511
|
* `options` — the SDK request options behind this call, when there are any —
|
|
2473
2512
|
* is surfaced to middleware as `ctx.options` and drives `ctx.parse`.
|
|
2513
|
+
*
|
|
2514
|
+
* `client` supplies `ctx.logger` (the client's level-filtered logger);
|
|
2515
|
+
* without it, `ctx.logger` falls back to the client defaults: `console`,
|
|
2516
|
+
* filtered to `ANTHROPIC_LOG` or `'warn'`.
|
|
2474
2517
|
*/
|
|
2475
|
-
function wrapFetchWithMiddleware(fetchFn, middleware, options) {
|
|
2518
|
+
function wrapFetchWithMiddleware(fetchFn, middleware, options, client) {
|
|
2476
2519
|
return async (url, init = {}) => {
|
|
2477
2520
|
if (middleware.length === 0) {
|
|
2478
2521
|
return fetchFn.call(undefined, url, init);
|
|
2479
2522
|
}
|
|
2480
2523
|
const headers = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
|
|
2481
|
-
const response = await applyMiddleware(fetchFn, middleware, options)({
|
|
2524
|
+
const response = await applyMiddleware(fetchFn, middleware, options, client)({
|
|
2482
2525
|
...init,
|
|
2483
2526
|
headers,
|
|
2484
2527
|
url: typeof url === "string" ? url : url instanceof URL ? url.href : url.url
|
|
@@ -2492,10 +2535,11 @@ function wrapFetchWithMiddleware(fetchFn, middleware, options) {
|
|
|
2492
2535
|
/**
|
|
2493
2536
|
* Creates the {@link MiddlewareContext} shared by every middleware in one chain.
|
|
2494
2537
|
*/
|
|
2495
|
-
function createMiddlewareContext(options) {
|
|
2538
|
+
function createMiddlewareContext(options, client) {
|
|
2496
2539
|
const cache = new WeakMap();
|
|
2497
2540
|
return {
|
|
2498
2541
|
options,
|
|
2542
|
+
logger: client ? loggerFor(client) : defaultLogger(),
|
|
2499
2543
|
parse(response) {
|
|
2500
2544
|
if (options?.stream && response.ok) {
|
|
2501
2545
|
return parseMiddlewareResponse(response, options);
|
|
@@ -2519,8 +2563,7 @@ async function parseMiddlewareResponse(response, options) {
|
|
|
2519
2563
|
throw new AnthropicError("cannot ctx.parse() a response whose body was already consumed; " + "call ctx.parse() instead of reading the body, or read via response.clone()");
|
|
2520
2564
|
}
|
|
2521
2565
|
if (options?.stream && response.ok) {
|
|
2522
|
-
|
|
2523
|
-
return streamClass.fromSSEResponse(response.clone(), new AbortController());
|
|
2566
|
+
return Stream.fromSSEResponse(response.clone(), new AbortController());
|
|
2524
2567
|
}
|
|
2525
2568
|
if (response.status === 204) {
|
|
2526
2569
|
return null;
|
|
@@ -2542,7 +2585,7 @@ async function parseMiddlewareResponse(response, options) {
|
|
|
2542
2585
|
/**
|
|
2543
2586
|
* Composes `middleware` around `fetchFn` and returns the entry point of the chain.
|
|
2544
2587
|
*/
|
|
2545
|
-
function applyMiddleware(fetchFn, middleware, options) {
|
|
2588
|
+
function applyMiddleware(fetchFn, middleware, options, client) {
|
|
2546
2589
|
let next = async ({ url, ...init }) => {
|
|
2547
2590
|
try {
|
|
2548
2591
|
return await fetchFn.call(undefined, url, init);
|
|
@@ -2552,7 +2595,7 @@ function applyMiddleware(fetchFn, middleware, options) {
|
|
|
2552
2595
|
throw error;
|
|
2553
2596
|
}
|
|
2554
2597
|
};
|
|
2555
|
-
const ctx = createMiddlewareContext(options);
|
|
2598
|
+
const ctx = createMiddlewareContext(options, client);
|
|
2556
2599
|
for (let i = middleware.length - 1; i >= 0; i--) {
|
|
2557
2600
|
const mw = middleware[i];
|
|
2558
2601
|
const nextInner = next;
|
|
@@ -2562,7 +2605,7 @@ function applyMiddleware(fetchFn, middleware, options) {
|
|
|
2562
2605
|
}
|
|
2563
2606
|
|
|
2564
2607
|
//#endregion
|
|
2565
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2608
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/api-promise.mjs
|
|
2566
2609
|
var _APIPromise_client;
|
|
2567
2610
|
/**
|
|
2568
2611
|
* A subclass of `Promise` providing additional helper methods
|
|
@@ -2634,7 +2677,7 @@ var APIPromise = class APIPromise extends Promise {
|
|
|
2634
2677
|
_APIPromise_client = new WeakMap();
|
|
2635
2678
|
|
|
2636
2679
|
//#endregion
|
|
2637
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2680
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/pagination.mjs
|
|
2638
2681
|
var _AbstractPage_client;
|
|
2639
2682
|
var AbstractPage = class {
|
|
2640
2683
|
constructor(client, response, body, options) {
|
|
@@ -2796,9 +2839,33 @@ var PageCursor = class extends AbstractPage {
|
|
|
2796
2839
|
};
|
|
2797
2840
|
}
|
|
2798
2841
|
};
|
|
2842
|
+
var BidirectionalPageCursor = class extends AbstractPage {
|
|
2843
|
+
constructor(client, response, body, options) {
|
|
2844
|
+
super(client, response, body, options);
|
|
2845
|
+
this.data = body.data || [];
|
|
2846
|
+
this.next_page = body.next_page || null;
|
|
2847
|
+
this.prev_page = body.prev_page || null;
|
|
2848
|
+
}
|
|
2849
|
+
getPaginatedItems() {
|
|
2850
|
+
return this.data ?? [];
|
|
2851
|
+
}
|
|
2852
|
+
nextPageRequestOptions() {
|
|
2853
|
+
const cursor = this.next_page;
|
|
2854
|
+
if (!cursor) {
|
|
2855
|
+
return null;
|
|
2856
|
+
}
|
|
2857
|
+
return {
|
|
2858
|
+
...this.options,
|
|
2859
|
+
query: {
|
|
2860
|
+
...maybeObj(this.options.query),
|
|
2861
|
+
page: cursor
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
};
|
|
2799
2866
|
|
|
2800
2867
|
//#endregion
|
|
2801
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2868
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/uploads.mjs
|
|
2802
2869
|
const checkFileSupport = () => {
|
|
2803
2870
|
if (typeof File === "undefined") {
|
|
2804
2871
|
const { process } = globalThis;
|
|
@@ -2910,7 +2977,7 @@ const addFormValue = async (form, key, value, stripFilenames) => {
|
|
|
2910
2977
|
};
|
|
2911
2978
|
|
|
2912
2979
|
//#endregion
|
|
2913
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
2980
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/to-file.mjs
|
|
2914
2981
|
/**
|
|
2915
2982
|
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
|
2916
2983
|
*/
|
|
@@ -2983,7 +3050,7 @@ function propsForError(value) {
|
|
|
2983
3050
|
}
|
|
2984
3051
|
|
|
2985
3052
|
//#endregion
|
|
2986
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
3053
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/core/resource.mjs
|
|
2987
3054
|
var APIResource = class {
|
|
2988
3055
|
constructor(client) {
|
|
2989
3056
|
this._client = client;
|
|
@@ -2991,7 +3058,7 @@ var APIResource = class {
|
|
|
2991
3058
|
};
|
|
2992
3059
|
|
|
2993
3060
|
//#endregion
|
|
2994
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
3061
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/headers.mjs
|
|
2995
3062
|
const brand_privateNullableHeaders = Symbol.for("brand.privateNullableHeaders");
|
|
2996
3063
|
function* iterateHeaders(headers) {
|
|
2997
3064
|
if (!headers) return;
|
|
@@ -3022,12 +3089,27 @@ function* iterateHeaders(headers) {
|
|
|
3022
3089
|
if (value === undefined) continue;
|
|
3023
3090
|
if (shouldClear && !didClear) {
|
|
3024
3091
|
didClear = true;
|
|
3025
|
-
yield [name,
|
|
3092
|
+
yield [name, clearSentinel];
|
|
3026
3093
|
}
|
|
3027
3094
|
yield [name, value];
|
|
3028
3095
|
}
|
|
3029
3096
|
}
|
|
3030
3097
|
}
|
|
3098
|
+
/** Distinguishes iterateHeaders' synthetic clear-before-set from a user `null`. */
|
|
3099
|
+
const clearSentinel = Symbol("clear");
|
|
3100
|
+
/**
|
|
3101
|
+
* Headers whose values accumulate across {@link buildHeaders} sources instead
|
|
3102
|
+
* of the later source's value replacing the earlier one. Values are
|
|
3103
|
+
* comma-appended (deduplicated, order-preserving) into a single header line.
|
|
3104
|
+
*/
|
|
3105
|
+
const APPEND_HEADERS = new Set(["x-stainless-helper"]);
|
|
3106
|
+
const appendHeaderValue = (existing, addition) => {
|
|
3107
|
+
const tokens = existing ? existing.split(",").map((t) => t.trim()).filter(Boolean) : [];
|
|
3108
|
+
for (const tok of addition.split(",").map((t) => t.trim())) {
|
|
3109
|
+
if (tok && !tokens.includes(tok)) tokens.push(tok);
|
|
3110
|
+
}
|
|
3111
|
+
return tokens.join(", ");
|
|
3112
|
+
};
|
|
3031
3113
|
const buildHeaders = (newHeaders) => {
|
|
3032
3114
|
const targetHeaders = new Headers();
|
|
3033
3115
|
const nullHeaders = new Set();
|
|
@@ -3035,9 +3117,21 @@ const buildHeaders = (newHeaders) => {
|
|
|
3035
3117
|
const seenHeaders = new Set();
|
|
3036
3118
|
for (const [name, value] of iterateHeaders(headers)) {
|
|
3037
3119
|
const lowerName = name.toLowerCase();
|
|
3038
|
-
if (
|
|
3120
|
+
if (APPEND_HEADERS.has(lowerName)) {
|
|
3121
|
+
if (value === clearSentinel) continue;
|
|
3122
|
+
if (value === null) {
|
|
3123
|
+
targetHeaders.delete(name);
|
|
3124
|
+
nullHeaders.add(lowerName);
|
|
3125
|
+
} else {
|
|
3126
|
+
targetHeaders.set(name, appendHeaderValue(targetHeaders.get(name), value));
|
|
3127
|
+
nullHeaders.delete(lowerName);
|
|
3128
|
+
}
|
|
3129
|
+
continue;
|
|
3130
|
+
}
|
|
3131
|
+
if (value === clearSentinel || !seenHeaders.has(lowerName)) {
|
|
3039
3132
|
targetHeaders.delete(name);
|
|
3040
3133
|
seenHeaders.add(lowerName);
|
|
3134
|
+
if (value === clearSentinel) continue;
|
|
3041
3135
|
}
|
|
3042
3136
|
if (value === null) {
|
|
3043
3137
|
targetHeaders.delete(name);
|
|
@@ -3060,69 +3154,7 @@ const isEmptyHeaders = (headers) => {
|
|
|
3060
3154
|
};
|
|
3061
3155
|
|
|
3062
3156
|
//#endregion
|
|
3063
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
3064
|
-
/**
|
|
3065
|
-
* Shared utilities for tracking SDK helper usage.
|
|
3066
|
-
*/
|
|
3067
|
-
/**
|
|
3068
|
-
* Symbol used to mark objects created by SDK helpers for tracking.
|
|
3069
|
-
* The value is the helper name (e.g., 'mcpTool', 'betaZodTool').
|
|
3070
|
-
*/
|
|
3071
|
-
const SDK_HELPER_SYMBOL = Symbol("anthropic.sdk.stainlessHelper");
|
|
3072
|
-
function wasCreatedByStainlessHelper(value) {
|
|
3073
|
-
return typeof value === "object" && value !== null && SDK_HELPER_SYMBOL in value;
|
|
3074
|
-
}
|
|
3075
|
-
/**
|
|
3076
|
-
* Collects helper names from tools and messages arrays.
|
|
3077
|
-
* Returns a deduplicated array of helper names found.
|
|
3078
|
-
*/
|
|
3079
|
-
function collectStainlessHelpers(tools, messages) {
|
|
3080
|
-
const helpers = new Set();
|
|
3081
|
-
if (tools) {
|
|
3082
|
-
for (const tool of tools) {
|
|
3083
|
-
if (wasCreatedByStainlessHelper(tool)) {
|
|
3084
|
-
helpers.add(tool[SDK_HELPER_SYMBOL]);
|
|
3085
|
-
}
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
if (messages) {
|
|
3089
|
-
for (const message of messages) {
|
|
3090
|
-
if (wasCreatedByStainlessHelper(message)) {
|
|
3091
|
-
helpers.add(message[SDK_HELPER_SYMBOL]);
|
|
3092
|
-
}
|
|
3093
|
-
if (Array.isArray(message.content)) {
|
|
3094
|
-
for (const block of message.content) {
|
|
3095
|
-
if (wasCreatedByStainlessHelper(block)) {
|
|
3096
|
-
helpers.add(block[SDK_HELPER_SYMBOL]);
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
}
|
|
3100
|
-
}
|
|
3101
|
-
}
|
|
3102
|
-
return Array.from(helpers);
|
|
3103
|
-
}
|
|
3104
|
-
/**
|
|
3105
|
-
* Builds x-stainless-helper header value from tools and messages.
|
|
3106
|
-
* Returns an empty object if no helpers are found.
|
|
3107
|
-
*/
|
|
3108
|
-
function stainlessHelperHeader(tools, messages) {
|
|
3109
|
-
const helpers = collectStainlessHelpers(tools, messages);
|
|
3110
|
-
if (helpers.length === 0) return {};
|
|
3111
|
-
return { "x-stainless-helper": helpers.join(", ") };
|
|
3112
|
-
}
|
|
3113
|
-
/**
|
|
3114
|
-
* Builds x-stainless-helper header value from a file object.
|
|
3115
|
-
* Returns an empty object if the file is not marked with a helper.
|
|
3116
|
-
*/
|
|
3117
|
-
function stainlessHelperHeaderFromFile(file) {
|
|
3118
|
-
if (wasCreatedByStainlessHelper(file)) {
|
|
3119
|
-
return { "x-stainless-helper": file[SDK_HELPER_SYMBOL] };
|
|
3120
|
-
}
|
|
3121
|
-
return {};
|
|
3122
|
-
}
|
|
3123
|
-
|
|
3124
|
-
//#endregion
|
|
3125
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.102.0_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/path.mjs
|
|
3157
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/path.mjs
|
|
3126
3158
|
/**
|
|
3127
3159
|
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
3128
3160
|
*
|
|
@@ -3184,210 +3216,593 @@ const createPathTagFunction = (pathEncoder = encodeURIPath) => function path(sta
|
|
|
3184
3216
|
const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
3185
3217
|
|
|
3186
3218
|
//#endregion
|
|
3187
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
3188
|
-
var
|
|
3219
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/deployment-runs.mjs
|
|
3220
|
+
var DeploymentRuns = class extends APIResource {
|
|
3189
3221
|
/**
|
|
3190
|
-
*
|
|
3222
|
+
* Get Deployment Run
|
|
3191
3223
|
*
|
|
3192
3224
|
* @example
|
|
3193
3225
|
* ```ts
|
|
3194
|
-
*
|
|
3195
|
-
*
|
|
3196
|
-
*
|
|
3197
|
-
*
|
|
3226
|
+
* const betaManagedAgentsDeploymentRun =
|
|
3227
|
+
* await client.beta.deploymentRuns.retrieve(
|
|
3228
|
+
* 'deployment_run_id',
|
|
3229
|
+
* );
|
|
3198
3230
|
* ```
|
|
3199
3231
|
*/
|
|
3200
|
-
|
|
3201
|
-
const { betas
|
|
3202
|
-
return this._client.
|
|
3203
|
-
query,
|
|
3232
|
+
retrieve(deploymentRunID, params = {}, options) {
|
|
3233
|
+
const { betas } = params ?? {};
|
|
3234
|
+
return this._client.get(path`/v1/deployment_runs/${deploymentRunID}?beta=true`, {
|
|
3204
3235
|
...options,
|
|
3205
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
3236
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3206
3237
|
});
|
|
3207
3238
|
}
|
|
3208
3239
|
/**
|
|
3209
|
-
*
|
|
3240
|
+
* List Deployment Runs
|
|
3210
3241
|
*
|
|
3211
3242
|
* @example
|
|
3212
3243
|
* ```ts
|
|
3213
|
-
*
|
|
3214
|
-
*
|
|
3215
|
-
*
|
|
3244
|
+
* // Automatically fetches more pages as needed.
|
|
3245
|
+
* for await (const betaManagedAgentsDeploymentRun of client.beta.deploymentRuns.list()) {
|
|
3246
|
+
* // ...
|
|
3247
|
+
* }
|
|
3216
3248
|
* ```
|
|
3217
3249
|
*/
|
|
3218
|
-
|
|
3219
|
-
const { betas } = params ?? {};
|
|
3220
|
-
return this._client.
|
|
3250
|
+
list(params = {}, options) {
|
|
3251
|
+
const { betas, ...query } = params ?? {};
|
|
3252
|
+
return this._client.getAPIList("/v1/deployment_runs?beta=true", PageCursor, {
|
|
3253
|
+
query,
|
|
3221
3254
|
...options,
|
|
3222
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
3255
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3223
3256
|
});
|
|
3224
3257
|
}
|
|
3258
|
+
};
|
|
3259
|
+
|
|
3260
|
+
//#endregion
|
|
3261
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/deployments.mjs
|
|
3262
|
+
var Deployments = class extends APIResource {
|
|
3225
3263
|
/**
|
|
3226
|
-
*
|
|
3264
|
+
* Create Deployment
|
|
3227
3265
|
*
|
|
3228
3266
|
* @example
|
|
3229
3267
|
* ```ts
|
|
3230
|
-
* const
|
|
3231
|
-
*
|
|
3232
|
-
*
|
|
3233
|
-
*
|
|
3234
|
-
*
|
|
3235
|
-
*
|
|
3268
|
+
* const betaManagedAgentsDeployment =
|
|
3269
|
+
* await client.beta.deployments.create({
|
|
3270
|
+
* agent: 'string',
|
|
3271
|
+
* environment_id: 'x',
|
|
3272
|
+
* initial_events: [
|
|
3273
|
+
* {
|
|
3274
|
+
* content: [
|
|
3275
|
+
* {
|
|
3276
|
+
* text: 'Where is my order #1234?',
|
|
3277
|
+
* type: 'text',
|
|
3278
|
+
* },
|
|
3279
|
+
* ],
|
|
3280
|
+
* type: 'user.message',
|
|
3281
|
+
* },
|
|
3282
|
+
* ],
|
|
3283
|
+
* name: 'x',
|
|
3284
|
+
* });
|
|
3236
3285
|
* ```
|
|
3237
3286
|
*/
|
|
3238
|
-
|
|
3239
|
-
const { betas } = params
|
|
3240
|
-
return this._client.
|
|
3287
|
+
create(params, options) {
|
|
3288
|
+
const { betas, ...body } = params;
|
|
3289
|
+
return this._client.post("/v1/deployments?beta=true", {
|
|
3290
|
+
body,
|
|
3241
3291
|
...options,
|
|
3242
|
-
headers: buildHeaders([{
|
|
3243
|
-
"anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString(),
|
|
3244
|
-
Accept: "application/binary"
|
|
3245
|
-
}, options?.headers]),
|
|
3246
|
-
__binaryResponse: true
|
|
3292
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3247
3293
|
});
|
|
3248
3294
|
}
|
|
3249
3295
|
/**
|
|
3250
|
-
* Get
|
|
3296
|
+
* Get Deployment
|
|
3251
3297
|
*
|
|
3252
3298
|
* @example
|
|
3253
3299
|
* ```ts
|
|
3254
|
-
* const
|
|
3255
|
-
* await client.beta.
|
|
3300
|
+
* const betaManagedAgentsDeployment =
|
|
3301
|
+
* await client.beta.deployments.retrieve(
|
|
3302
|
+
* 'depl_011CZkZcDH3vPqd7xnEfwTai',
|
|
3303
|
+
* );
|
|
3256
3304
|
* ```
|
|
3257
3305
|
*/
|
|
3258
|
-
|
|
3306
|
+
retrieve(deploymentID, params = {}, options) {
|
|
3259
3307
|
const { betas } = params ?? {};
|
|
3260
|
-
return this._client.get(path`/v1/
|
|
3308
|
+
return this._client.get(path`/v1/deployments/${deploymentID}?beta=true`, {
|
|
3261
3309
|
...options,
|
|
3262
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
3310
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3263
3311
|
});
|
|
3264
3312
|
}
|
|
3265
3313
|
/**
|
|
3266
|
-
*
|
|
3314
|
+
* Update Deployment
|
|
3267
3315
|
*
|
|
3268
3316
|
* @example
|
|
3269
3317
|
* ```ts
|
|
3270
|
-
* const
|
|
3271
|
-
*
|
|
3272
|
-
*
|
|
3318
|
+
* const betaManagedAgentsDeployment =
|
|
3319
|
+
* await client.beta.deployments.update(
|
|
3320
|
+
* 'depl_011CZkZcDH3vPqd7xnEfwTai',
|
|
3321
|
+
* );
|
|
3273
3322
|
* ```
|
|
3274
3323
|
*/
|
|
3275
|
-
|
|
3324
|
+
update(deploymentID, params, options) {
|
|
3276
3325
|
const { betas, ...body } = params;
|
|
3277
|
-
return this._client.post(
|
|
3326
|
+
return this._client.post(path`/v1/deployments/${deploymentID}?beta=true`, {
|
|
3278
3327
|
body,
|
|
3279
3328
|
...options,
|
|
3280
|
-
headers: buildHeaders([
|
|
3281
|
-
{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() },
|
|
3282
|
-
stainlessHelperHeaderFromFile(body.file),
|
|
3283
|
-
options?.headers
|
|
3284
|
-
])
|
|
3285
|
-
}, this._client));
|
|
3286
|
-
}
|
|
3287
|
-
};
|
|
3288
|
-
|
|
3289
|
-
//#endregion
|
|
3290
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.102.0_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/models.mjs
|
|
3291
|
-
var Models$1 = class extends APIResource {
|
|
3292
|
-
/**
|
|
3293
|
-
* Get a specific model.
|
|
3294
|
-
*
|
|
3295
|
-
* The Models API response can be used to determine information about a specific
|
|
3296
|
-
* model or resolve a model alias to a model ID.
|
|
3297
|
-
*
|
|
3298
|
-
* @example
|
|
3299
|
-
* ```ts
|
|
3300
|
-
* const betaModelInfo = await client.beta.models.retrieve(
|
|
3301
|
-
* 'model_id',
|
|
3302
|
-
* );
|
|
3303
|
-
* ```
|
|
3304
|
-
*/
|
|
3305
|
-
retrieve(modelID, params = {}, options) {
|
|
3306
|
-
const { betas } = params ?? {};
|
|
3307
|
-
return this._client.get(path`/v1/models/${modelID}?beta=true`, {
|
|
3308
|
-
...options,
|
|
3309
|
-
headers: buildHeaders([{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined }, options?.headers])
|
|
3329
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3310
3330
|
});
|
|
3311
3331
|
}
|
|
3312
3332
|
/**
|
|
3313
|
-
* List
|
|
3314
|
-
*
|
|
3315
|
-
* The Models API response can be used to determine which models are available for
|
|
3316
|
-
* use in the API. More recently released models are listed first.
|
|
3333
|
+
* List Deployments
|
|
3317
3334
|
*
|
|
3318
3335
|
* @example
|
|
3319
3336
|
* ```ts
|
|
3320
3337
|
* // Automatically fetches more pages as needed.
|
|
3321
|
-
* for await (const
|
|
3338
|
+
* for await (const betaManagedAgentsDeployment of client.beta.deployments.list()) {
|
|
3322
3339
|
* // ...
|
|
3323
3340
|
* }
|
|
3324
3341
|
* ```
|
|
3325
3342
|
*/
|
|
3326
3343
|
list(params = {}, options) {
|
|
3327
3344
|
const { betas, ...query } = params ?? {};
|
|
3328
|
-
return this._client.getAPIList("/v1/
|
|
3345
|
+
return this._client.getAPIList("/v1/deployments?beta=true", PageCursor, {
|
|
3329
3346
|
query,
|
|
3330
3347
|
...options,
|
|
3331
|
-
headers: buildHeaders([{ ...betas
|
|
3348
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3332
3349
|
});
|
|
3333
3350
|
}
|
|
3334
|
-
};
|
|
3335
|
-
|
|
3336
|
-
//#endregion
|
|
3337
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.102.0_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/user-profiles.mjs
|
|
3338
|
-
var UserProfiles = class extends APIResource {
|
|
3339
3351
|
/**
|
|
3340
|
-
*
|
|
3352
|
+
* Archive Deployment
|
|
3341
3353
|
*
|
|
3342
3354
|
* @example
|
|
3343
3355
|
* ```ts
|
|
3344
|
-
* const
|
|
3345
|
-
* await client.beta.
|
|
3356
|
+
* const betaManagedAgentsDeployment =
|
|
3357
|
+
* await client.beta.deployments.archive(
|
|
3358
|
+
* 'depl_011CZkZcDH3vPqd7xnEfwTai',
|
|
3359
|
+
* );
|
|
3346
3360
|
* ```
|
|
3347
3361
|
*/
|
|
3348
|
-
|
|
3349
|
-
const { betas
|
|
3350
|
-
return this._client.post(
|
|
3351
|
-
body,
|
|
3362
|
+
archive(deploymentID, params = {}, options) {
|
|
3363
|
+
const { betas } = params ?? {};
|
|
3364
|
+
return this._client.post(path`/v1/deployments/${deploymentID}/archive?beta=true`, {
|
|
3352
3365
|
...options,
|
|
3353
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
3366
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3354
3367
|
});
|
|
3355
3368
|
}
|
|
3356
3369
|
/**
|
|
3357
|
-
*
|
|
3370
|
+
* Pause Deployment
|
|
3358
3371
|
*
|
|
3359
3372
|
* @example
|
|
3360
3373
|
* ```ts
|
|
3361
|
-
* const
|
|
3362
|
-
* await client.beta.
|
|
3363
|
-
* '
|
|
3374
|
+
* const betaManagedAgentsDeployment =
|
|
3375
|
+
* await client.beta.deployments.pause(
|
|
3376
|
+
* 'depl_011CZkZcDH3vPqd7xnEfwTai',
|
|
3364
3377
|
* );
|
|
3365
3378
|
* ```
|
|
3366
3379
|
*/
|
|
3367
|
-
|
|
3380
|
+
pause(deploymentID, params = {}, options) {
|
|
3368
3381
|
const { betas } = params ?? {};
|
|
3369
|
-
return this._client.
|
|
3382
|
+
return this._client.post(path`/v1/deployments/${deploymentID}/pause?beta=true`, {
|
|
3370
3383
|
...options,
|
|
3371
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
3384
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3372
3385
|
});
|
|
3373
3386
|
}
|
|
3374
3387
|
/**
|
|
3375
|
-
*
|
|
3388
|
+
* Run Deployment Now
|
|
3376
3389
|
*
|
|
3377
3390
|
* @example
|
|
3378
3391
|
* ```ts
|
|
3379
|
-
* const
|
|
3380
|
-
* await client.beta.
|
|
3381
|
-
* '
|
|
3392
|
+
* const betaManagedAgentsDeploymentRun =
|
|
3393
|
+
* await client.beta.deployments.run(
|
|
3394
|
+
* 'depl_011CZkZcDH3vPqd7xnEfwTai',
|
|
3382
3395
|
* );
|
|
3383
3396
|
* ```
|
|
3384
3397
|
*/
|
|
3385
|
-
|
|
3386
|
-
const { betas
|
|
3387
|
-
return this._client.post(path`/v1/
|
|
3388
|
-
body,
|
|
3398
|
+
run(deploymentID, params = {}, options) {
|
|
3399
|
+
const { betas } = params ?? {};
|
|
3400
|
+
return this._client.post(path`/v1/deployments/${deploymentID}/run?beta=true`, {
|
|
3389
3401
|
...options,
|
|
3390
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
3402
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
/**
|
|
3406
|
+
* Unpause Deployment
|
|
3407
|
+
*
|
|
3408
|
+
* @example
|
|
3409
|
+
* ```ts
|
|
3410
|
+
* const betaManagedAgentsDeployment =
|
|
3411
|
+
* await client.beta.deployments.unpause(
|
|
3412
|
+
* 'depl_011CZkZcDH3vPqd7xnEfwTai',
|
|
3413
|
+
* );
|
|
3414
|
+
* ```
|
|
3415
|
+
*/
|
|
3416
|
+
unpause(deploymentID, params = {}, options) {
|
|
3417
|
+
const { betas } = params ?? {};
|
|
3418
|
+
return this._client.post(path`/v1/deployments/${deploymentID}/unpause?beta=true`, {
|
|
3419
|
+
...options,
|
|
3420
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
};
|
|
3424
|
+
|
|
3425
|
+
//#endregion
|
|
3426
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/dreams.mjs
|
|
3427
|
+
var Dreams = class extends APIResource {
|
|
3428
|
+
/**
|
|
3429
|
+
* Create a Dream
|
|
3430
|
+
*
|
|
3431
|
+
* @example
|
|
3432
|
+
* ```ts
|
|
3433
|
+
* const betaDream = await client.beta.dreams.create({
|
|
3434
|
+
* inputs: [{ memory_store_id: 'x', type: 'memory_store' }],
|
|
3435
|
+
* model: 'string',
|
|
3436
|
+
* });
|
|
3437
|
+
* ```
|
|
3438
|
+
*/
|
|
3439
|
+
create(params, options) {
|
|
3440
|
+
const { betas, ...body } = params;
|
|
3441
|
+
return this._client.post("/v1/dreams?beta=true", {
|
|
3442
|
+
body,
|
|
3443
|
+
...options,
|
|
3444
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "dreaming-2026-04-21"].toString() }, options?.headers])
|
|
3445
|
+
});
|
|
3446
|
+
}
|
|
3447
|
+
/**
|
|
3448
|
+
* Get a Dream
|
|
3449
|
+
*
|
|
3450
|
+
* @example
|
|
3451
|
+
* ```ts
|
|
3452
|
+
* const betaDream = await client.beta.dreams.retrieve(
|
|
3453
|
+
* 'dream_id',
|
|
3454
|
+
* );
|
|
3455
|
+
* ```
|
|
3456
|
+
*/
|
|
3457
|
+
retrieve(dreamID, params = {}, options) {
|
|
3458
|
+
const { betas } = params ?? {};
|
|
3459
|
+
return this._client.get(path`/v1/dreams/${dreamID}?beta=true`, {
|
|
3460
|
+
...options,
|
|
3461
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "dreaming-2026-04-21"].toString() }, options?.headers])
|
|
3462
|
+
});
|
|
3463
|
+
}
|
|
3464
|
+
/**
|
|
3465
|
+
* List Dreams
|
|
3466
|
+
*
|
|
3467
|
+
* @example
|
|
3468
|
+
* ```ts
|
|
3469
|
+
* // Automatically fetches more pages as needed.
|
|
3470
|
+
* for await (const betaDream of client.beta.dreams.list()) {
|
|
3471
|
+
* // ...
|
|
3472
|
+
* }
|
|
3473
|
+
* ```
|
|
3474
|
+
*/
|
|
3475
|
+
list(params = {}, options) {
|
|
3476
|
+
const { betas, ...query } = params ?? {};
|
|
3477
|
+
return this._client.getAPIList("/v1/dreams?beta=true", PageCursor, {
|
|
3478
|
+
query,
|
|
3479
|
+
...options,
|
|
3480
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "dreaming-2026-04-21"].toString() }, options?.headers])
|
|
3481
|
+
});
|
|
3482
|
+
}
|
|
3483
|
+
/**
|
|
3484
|
+
* Archive a Dream
|
|
3485
|
+
*
|
|
3486
|
+
* @example
|
|
3487
|
+
* ```ts
|
|
3488
|
+
* const betaDream = await client.beta.dreams.archive(
|
|
3489
|
+
* 'dream_id',
|
|
3490
|
+
* );
|
|
3491
|
+
* ```
|
|
3492
|
+
*/
|
|
3493
|
+
archive(dreamID, params = {}, options) {
|
|
3494
|
+
const { betas } = params ?? {};
|
|
3495
|
+
return this._client.post(path`/v1/dreams/${dreamID}/archive?beta=true`, {
|
|
3496
|
+
...options,
|
|
3497
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "dreaming-2026-04-21"].toString() }, options?.headers])
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
/**
|
|
3501
|
+
* Cancel a Dream
|
|
3502
|
+
*
|
|
3503
|
+
* @example
|
|
3504
|
+
* ```ts
|
|
3505
|
+
* const betaDream = await client.beta.dreams.cancel(
|
|
3506
|
+
* 'dream_id',
|
|
3507
|
+
* );
|
|
3508
|
+
* ```
|
|
3509
|
+
*/
|
|
3510
|
+
cancel(dreamID, params = {}, options) {
|
|
3511
|
+
const { betas } = params ?? {};
|
|
3512
|
+
return this._client.post(path`/v1/dreams/${dreamID}/cancel?beta=true`, {
|
|
3513
|
+
...options,
|
|
3514
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "dreaming-2026-04-21"].toString() }, options?.headers])
|
|
3515
|
+
});
|
|
3516
|
+
}
|
|
3517
|
+
};
|
|
3518
|
+
|
|
3519
|
+
//#endregion
|
|
3520
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/stainless-helper-header.mjs
|
|
3521
|
+
/**
|
|
3522
|
+
* Single source of truth for the `x-stainless-helper` telemetry header — the
|
|
3523
|
+
* key, the closed value vocabulary, and per-object helper tagging. The
|
|
3524
|
+
* append-don't-clobber merge for the header itself lives in
|
|
3525
|
+
* {@link import('../internal/headers').buildHeaders} via `APPEND_HEADERS`.
|
|
3526
|
+
*/
|
|
3527
|
+
/**
|
|
3528
|
+
* Telemetry header naming the SDK helper(s) a request came from. Always this
|
|
3529
|
+
* lowercase form; `buildHeaders` matches it case-insensitively for its append
|
|
3530
|
+
* semantics, but a single canonical casing keeps every call site greppable.
|
|
3531
|
+
*/
|
|
3532
|
+
const STAINLESS_HELPER_HEADER = "x-stainless-helper";
|
|
3533
|
+
/** Telemetry header naming the SDK method (e.g. `stream`) in use. */
|
|
3534
|
+
const STAINLESS_HELPER_METHOD_HEADER = "x-stainless-helper-method";
|
|
3535
|
+
/**
|
|
3536
|
+
* The `{ 'x-stainless-helper': value }` header dict, for passing into
|
|
3537
|
+
* `buildHeaders` (which comma-appends `x-stainless-helper` across sources)
|
|
3538
|
+
* or as `defaultHeaders`/per-request `headers`.
|
|
3539
|
+
*/
|
|
3540
|
+
function helperHeader(value) {
|
|
3541
|
+
return { [STAINLESS_HELPER_HEADER]: value };
|
|
3542
|
+
}
|
|
3543
|
+
/**
|
|
3544
|
+
* Symbol used to mark objects created by SDK helpers for tracking.
|
|
3545
|
+
* The value is the helper name (e.g., 'mcpTool', 'betaZodTool').
|
|
3546
|
+
*/
|
|
3547
|
+
const SDK_HELPER_SYMBOL = Symbol("anthropic.sdk.stainlessHelper");
|
|
3548
|
+
function wasCreatedByStainlessHelper(value) {
|
|
3549
|
+
return typeof value === "object" && value !== null && SDK_HELPER_SYMBOL in value;
|
|
3550
|
+
}
|
|
3551
|
+
/**
|
|
3552
|
+
* Collects helper names from tools and messages arrays.
|
|
3553
|
+
* Returns a deduplicated array of helper names found.
|
|
3554
|
+
*/
|
|
3555
|
+
function collectStainlessHelpers(tools, messages) {
|
|
3556
|
+
const helpers = new Set();
|
|
3557
|
+
if (tools) {
|
|
3558
|
+
for (const tool of tools) {
|
|
3559
|
+
if (wasCreatedByStainlessHelper(tool)) {
|
|
3560
|
+
helpers.add(tool[SDK_HELPER_SYMBOL]);
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
if (messages) {
|
|
3565
|
+
for (const message of messages) {
|
|
3566
|
+
if (wasCreatedByStainlessHelper(message)) {
|
|
3567
|
+
helpers.add(message[SDK_HELPER_SYMBOL]);
|
|
3568
|
+
}
|
|
3569
|
+
const content = message.content;
|
|
3570
|
+
if (Array.isArray(content)) {
|
|
3571
|
+
for (const block of content) {
|
|
3572
|
+
if (wasCreatedByStainlessHelper(block)) {
|
|
3573
|
+
helpers.add(block[SDK_HELPER_SYMBOL]);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
return Array.from(helpers);
|
|
3580
|
+
}
|
|
3581
|
+
/**
|
|
3582
|
+
* Builds x-stainless-helper header value from tools and messages.
|
|
3583
|
+
* Returns an empty object if no helpers are found.
|
|
3584
|
+
*/
|
|
3585
|
+
function stainlessHelperHeader(tools, messages) {
|
|
3586
|
+
const helpers = collectStainlessHelpers(tools, messages);
|
|
3587
|
+
if (helpers.length === 0) return {};
|
|
3588
|
+
return { [STAINLESS_HELPER_HEADER]: helpers.join(", ") };
|
|
3589
|
+
}
|
|
3590
|
+
/**
|
|
3591
|
+
* Builds x-stainless-helper header value from a file object.
|
|
3592
|
+
* Returns an empty object if the file is not marked with a helper.
|
|
3593
|
+
*/
|
|
3594
|
+
function stainlessHelperHeaderFromFile(file) {
|
|
3595
|
+
if (wasCreatedByStainlessHelper(file)) {
|
|
3596
|
+
return { [STAINLESS_HELPER_HEADER]: file[SDK_HELPER_SYMBOL] };
|
|
3597
|
+
}
|
|
3598
|
+
return {};
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
//#endregion
|
|
3602
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/files.mjs
|
|
3603
|
+
var Files = class extends APIResource {
|
|
3604
|
+
/**
|
|
3605
|
+
* List Files
|
|
3606
|
+
*
|
|
3607
|
+
* @example
|
|
3608
|
+
* ```ts
|
|
3609
|
+
* // Automatically fetches more pages as needed.
|
|
3610
|
+
* for await (const fileMetadata of client.beta.files.list()) {
|
|
3611
|
+
* // ...
|
|
3612
|
+
* }
|
|
3613
|
+
* ```
|
|
3614
|
+
*/
|
|
3615
|
+
list(params = {}, options) {
|
|
3616
|
+
const { betas, ...query } = params ?? {};
|
|
3617
|
+
return this._client.getAPIList("/v1/files?beta=true", Page, {
|
|
3618
|
+
query,
|
|
3619
|
+
...options,
|
|
3620
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() }, options?.headers])
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3623
|
+
/**
|
|
3624
|
+
* Delete File
|
|
3625
|
+
*
|
|
3626
|
+
* @example
|
|
3627
|
+
* ```ts
|
|
3628
|
+
* const deletedFile = await client.beta.files.delete(
|
|
3629
|
+
* 'file_id',
|
|
3630
|
+
* );
|
|
3631
|
+
* ```
|
|
3632
|
+
*/
|
|
3633
|
+
delete(fileID, params = {}, options) {
|
|
3634
|
+
const { betas } = params ?? {};
|
|
3635
|
+
return this._client.delete(path`/v1/files/${fileID}?beta=true`, {
|
|
3636
|
+
...options,
|
|
3637
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() }, options?.headers])
|
|
3638
|
+
});
|
|
3639
|
+
}
|
|
3640
|
+
/**
|
|
3641
|
+
* Download File
|
|
3642
|
+
*
|
|
3643
|
+
* @example
|
|
3644
|
+
* ```ts
|
|
3645
|
+
* const response = await client.beta.files.download(
|
|
3646
|
+
* 'file_id',
|
|
3647
|
+
* );
|
|
3648
|
+
*
|
|
3649
|
+
* const content = await response.blob();
|
|
3650
|
+
* console.log(content);
|
|
3651
|
+
* ```
|
|
3652
|
+
*/
|
|
3653
|
+
download(fileID, params = {}, options) {
|
|
3654
|
+
const { betas } = params ?? {};
|
|
3655
|
+
return this._client.get(path`/v1/files/${fileID}/content?beta=true`, {
|
|
3656
|
+
...options,
|
|
3657
|
+
headers: buildHeaders([{
|
|
3658
|
+
"anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString(),
|
|
3659
|
+
Accept: "application/binary"
|
|
3660
|
+
}, options?.headers]),
|
|
3661
|
+
__binaryResponse: true
|
|
3662
|
+
});
|
|
3663
|
+
}
|
|
3664
|
+
/**
|
|
3665
|
+
* Get File Metadata
|
|
3666
|
+
*
|
|
3667
|
+
* @example
|
|
3668
|
+
* ```ts
|
|
3669
|
+
* const fileMetadata =
|
|
3670
|
+
* await client.beta.files.retrieveMetadata('file_id');
|
|
3671
|
+
* ```
|
|
3672
|
+
*/
|
|
3673
|
+
retrieveMetadata(fileID, params = {}, options) {
|
|
3674
|
+
const { betas } = params ?? {};
|
|
3675
|
+
return this._client.get(path`/v1/files/${fileID}?beta=true`, {
|
|
3676
|
+
...options,
|
|
3677
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() }, options?.headers])
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
/**
|
|
3681
|
+
* Upload File
|
|
3682
|
+
*
|
|
3683
|
+
* @example
|
|
3684
|
+
* ```ts
|
|
3685
|
+
* const fileMetadata = await client.beta.files.upload({
|
|
3686
|
+
* file: fs.createReadStream('path/to/file'),
|
|
3687
|
+
* });
|
|
3688
|
+
* ```
|
|
3689
|
+
*/
|
|
3690
|
+
upload(params, options) {
|
|
3691
|
+
const { betas, ...body } = params;
|
|
3692
|
+
return this._client.post("/v1/files?beta=true", multipartFormRequestOptions({
|
|
3693
|
+
body,
|
|
3694
|
+
...options,
|
|
3695
|
+
headers: buildHeaders([
|
|
3696
|
+
{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() },
|
|
3697
|
+
stainlessHelperHeaderFromFile(body.file),
|
|
3698
|
+
options?.headers
|
|
3699
|
+
])
|
|
3700
|
+
}, this._client));
|
|
3701
|
+
}
|
|
3702
|
+
};
|
|
3703
|
+
|
|
3704
|
+
//#endregion
|
|
3705
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/models.mjs
|
|
3706
|
+
var Models$1 = class extends APIResource {
|
|
3707
|
+
/**
|
|
3708
|
+
* Get a specific model.
|
|
3709
|
+
*
|
|
3710
|
+
* The Models API response can be used to determine information about a specific
|
|
3711
|
+
* model or resolve a model alias to a model ID.
|
|
3712
|
+
*
|
|
3713
|
+
* @example
|
|
3714
|
+
* ```ts
|
|
3715
|
+
* const betaModelInfo = await client.beta.models.retrieve(
|
|
3716
|
+
* 'model_id',
|
|
3717
|
+
* );
|
|
3718
|
+
* ```
|
|
3719
|
+
*/
|
|
3720
|
+
retrieve(modelID, params = {}, options) {
|
|
3721
|
+
const { betas } = params ?? {};
|
|
3722
|
+
return this._client.get(path`/v1/models/${modelID}?beta=true`, {
|
|
3723
|
+
...options,
|
|
3724
|
+
headers: buildHeaders([{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined }, options?.headers])
|
|
3725
|
+
});
|
|
3726
|
+
}
|
|
3727
|
+
/**
|
|
3728
|
+
* List available models.
|
|
3729
|
+
*
|
|
3730
|
+
* The Models API response can be used to determine which models are available for
|
|
3731
|
+
* use in the API. More recently released models are listed first.
|
|
3732
|
+
*
|
|
3733
|
+
* @example
|
|
3734
|
+
* ```ts
|
|
3735
|
+
* // Automatically fetches more pages as needed.
|
|
3736
|
+
* for await (const betaModelInfo of client.beta.models.list()) {
|
|
3737
|
+
* // ...
|
|
3738
|
+
* }
|
|
3739
|
+
* ```
|
|
3740
|
+
*/
|
|
3741
|
+
list(params = {}, options) {
|
|
3742
|
+
const { betas, ...query } = params ?? {};
|
|
3743
|
+
return this._client.getAPIList("/v1/models?beta=true", Page, {
|
|
3744
|
+
query,
|
|
3745
|
+
...options,
|
|
3746
|
+
headers: buildHeaders([{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined }, options?.headers])
|
|
3747
|
+
});
|
|
3748
|
+
}
|
|
3749
|
+
};
|
|
3750
|
+
|
|
3751
|
+
//#endregion
|
|
3752
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/user-profiles.mjs
|
|
3753
|
+
var UserProfiles = class extends APIResource {
|
|
3754
|
+
/**
|
|
3755
|
+
* Create User Profile
|
|
3756
|
+
*
|
|
3757
|
+
* @example
|
|
3758
|
+
* ```ts
|
|
3759
|
+
* const betaUserProfile =
|
|
3760
|
+
* await client.beta.userProfiles.create();
|
|
3761
|
+
* ```
|
|
3762
|
+
*/
|
|
3763
|
+
create(params, options) {
|
|
3764
|
+
const { betas, ...body } = params;
|
|
3765
|
+
return this._client.post("/v1/user_profiles?beta=true", {
|
|
3766
|
+
body,
|
|
3767
|
+
...options,
|
|
3768
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "user-profiles-2026-03-24"].toString() }, options?.headers])
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3771
|
+
/**
|
|
3772
|
+
* Get User Profile
|
|
3773
|
+
*
|
|
3774
|
+
* @example
|
|
3775
|
+
* ```ts
|
|
3776
|
+
* const betaUserProfile =
|
|
3777
|
+
* await client.beta.userProfiles.retrieve(
|
|
3778
|
+
* 'uprof_011CZkZCu8hGbp5mYRQgUmz9',
|
|
3779
|
+
* );
|
|
3780
|
+
* ```
|
|
3781
|
+
*/
|
|
3782
|
+
retrieve(userProfileID, params = {}, options) {
|
|
3783
|
+
const { betas } = params ?? {};
|
|
3784
|
+
return this._client.get(path`/v1/user_profiles/${userProfileID}?beta=true`, {
|
|
3785
|
+
...options,
|
|
3786
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "user-profiles-2026-03-24"].toString() }, options?.headers])
|
|
3787
|
+
});
|
|
3788
|
+
}
|
|
3789
|
+
/**
|
|
3790
|
+
* Update User Profile
|
|
3791
|
+
*
|
|
3792
|
+
* @example
|
|
3793
|
+
* ```ts
|
|
3794
|
+
* const betaUserProfile =
|
|
3795
|
+
* await client.beta.userProfiles.update(
|
|
3796
|
+
* 'uprof_011CZkZCu8hGbp5mYRQgUmz9',
|
|
3797
|
+
* );
|
|
3798
|
+
* ```
|
|
3799
|
+
*/
|
|
3800
|
+
update(userProfileID, params, options) {
|
|
3801
|
+
const { betas, ...body } = params;
|
|
3802
|
+
return this._client.post(path`/v1/user_profiles/${userProfileID}?beta=true`, {
|
|
3803
|
+
body,
|
|
3804
|
+
...options,
|
|
3805
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "user-profiles-2026-03-24"].toString() }, options?.headers])
|
|
3391
3806
|
});
|
|
3392
3807
|
}
|
|
3393
3808
|
/**
|
|
@@ -4203,7 +4618,7 @@ var require_dist = /* @__PURE__ */ require_rolldown_runtime.__commonJSMin(((expo
|
|
|
4203
4618
|
}));
|
|
4204
4619
|
|
|
4205
4620
|
//#endregion
|
|
4206
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4621
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/webhooks.mjs
|
|
4207
4622
|
var import_dist = require_dist();
|
|
4208
4623
|
var Webhooks = class extends APIResource {
|
|
4209
4624
|
unwrap(body, { headers, key }) {
|
|
@@ -4218,7 +4633,7 @@ var Webhooks = class extends APIResource {
|
|
|
4218
4633
|
};
|
|
4219
4634
|
|
|
4220
4635
|
//#endregion
|
|
4221
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4636
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/agents/versions.mjs
|
|
4222
4637
|
var Versions$1 = class extends APIResource {
|
|
4223
4638
|
/**
|
|
4224
4639
|
* List Agent Versions
|
|
@@ -4244,7 +4659,7 @@ var Versions$1 = class extends APIResource {
|
|
|
4244
4659
|
};
|
|
4245
4660
|
|
|
4246
4661
|
//#endregion
|
|
4247
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4662
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/agents/agents.mjs
|
|
4248
4663
|
var Agents = class extends APIResource {
|
|
4249
4664
|
constructor() {
|
|
4250
4665
|
super(...arguments);
|
|
@@ -4350,7 +4765,7 @@ var Agents = class extends APIResource {
|
|
|
4350
4765
|
Agents.Versions = Versions$1;
|
|
4351
4766
|
|
|
4352
4767
|
//#endregion
|
|
4353
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4768
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/abort.mjs
|
|
4354
4769
|
/**
|
|
4355
4770
|
* Chain an external {@link AbortSignal} into a local {@link AbortController}:
|
|
4356
4771
|
* the controller aborts whenever `external` aborts (synchronously if it is
|
|
@@ -4374,7 +4789,7 @@ function linkAbort(external, controller) {
|
|
|
4374
4789
|
}
|
|
4375
4790
|
|
|
4376
4791
|
//#endregion
|
|
4377
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4792
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/backoff.mjs
|
|
4378
4793
|
/** True when `e` is an {@link APIError} whose HTTP status equals `code`. */
|
|
4379
4794
|
function isStatus(e, code) {
|
|
4380
4795
|
return e instanceof APIError && e.status === code;
|
|
@@ -4411,7 +4826,7 @@ function applyJitter(ms) {
|
|
|
4411
4826
|
}
|
|
4412
4827
|
|
|
4413
4828
|
//#endregion
|
|
4414
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4829
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/helper-client.mjs
|
|
4415
4830
|
/**
|
|
4416
4831
|
* Return a `withOptions()` clone of `client` set up for use *by* one of the
|
|
4417
4832
|
* runner helpers: authenticated with `authToken` as Bearer credentials, with
|
|
@@ -4450,7 +4865,7 @@ function copyClientForHelper(client, { authToken, helper }) {
|
|
|
4450
4865
|
const defaultHeaders = buildHeaders([
|
|
4451
4866
|
inheritedAuthExtraHeaders,
|
|
4452
4867
|
parentDefaults,
|
|
4453
|
-
{
|
|
4868
|
+
{ [STAINLESS_HELPER_HEADER]: helper }
|
|
4454
4869
|
]);
|
|
4455
4870
|
return client.withOptions({
|
|
4456
4871
|
apiKey: null,
|
|
@@ -4462,7 +4877,7 @@ function copyClientForHelper(client, { authToken, helper }) {
|
|
|
4462
4877
|
}
|
|
4463
4878
|
|
|
4464
4879
|
//#endregion
|
|
4465
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
4880
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/environments/poller.mjs
|
|
4466
4881
|
var _WorkPoller_runnerClient;
|
|
4467
4882
|
var _WorkPoller_consumed;
|
|
4468
4883
|
var _WorkPoller_controller;
|
|
@@ -4618,7 +5033,7 @@ function defaultWorkerId() {
|
|
|
4618
5033
|
}
|
|
4619
5034
|
|
|
4620
5035
|
//#endregion
|
|
4621
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
5036
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/async-queue.mjs
|
|
4622
5037
|
var _AsyncQueue_items;
|
|
4623
5038
|
var _AsyncQueue_waiters;
|
|
4624
5039
|
var _AsyncQueue_closed;
|
|
@@ -4702,7 +5117,7 @@ var AsyncQueue = class {
|
|
|
4702
5117
|
_AsyncQueue_items = new WeakMap(), _AsyncQueue_waiters = new WeakMap(), _AsyncQueue_closed = new WeakMap();
|
|
4703
5118
|
|
|
4704
5119
|
//#endregion
|
|
4705
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
5120
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/tools/ToolError.mjs
|
|
4706
5121
|
/**
|
|
4707
5122
|
* An error that can be thrown from a tool's `run` method to return structured
|
|
4708
5123
|
* content blocks as the error result, rather than just a string message.
|
|
@@ -4739,7 +5154,7 @@ var ToolError = class extends Error {
|
|
|
4739
5154
|
};
|
|
4740
5155
|
|
|
4741
5156
|
//#endregion
|
|
4742
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
5157
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/tools/BetaRunnableTool.mjs
|
|
4743
5158
|
/**
|
|
4744
5159
|
* Resolve the registry key for a tool — the name the model addresses it by.
|
|
4745
5160
|
* MCP toolsets are keyed on `mcp_server_name`; every other tool on `name`.
|
|
@@ -4780,7 +5195,12 @@ async function runRunnableTool(tool, rawInput, context) {
|
|
|
4780
5195
|
}
|
|
4781
5196
|
|
|
4782
5197
|
//#endregion
|
|
4783
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
5198
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/tools/SessionToolRunner.mjs
|
|
5199
|
+
var _IdleClock_maxIdleMs;
|
|
5200
|
+
var _IdleClock_onExpire;
|
|
5201
|
+
var _IdleClock_blockers;
|
|
5202
|
+
var _IdleClock_armPending;
|
|
5203
|
+
var _IdleClock_timer;
|
|
4784
5204
|
var _SessionToolRunner_instances;
|
|
4785
5205
|
var _SessionToolRunner_consumed;
|
|
4786
5206
|
var _SessionToolRunner_controller;
|
|
@@ -4790,24 +5210,26 @@ var _SessionToolRunner_toolByName;
|
|
|
4790
5210
|
var _SessionToolRunner_logger;
|
|
4791
5211
|
var _SessionToolRunner_seen;
|
|
4792
5212
|
var _SessionToolRunner_answered;
|
|
5213
|
+
var _SessionToolRunner_confirmationVerdicts;
|
|
5214
|
+
var _SessionToolRunner_awaitingConfirmation;
|
|
4793
5215
|
var _SessionToolRunner_results;
|
|
4794
5216
|
var _SessionToolRunner_inFlightCount;
|
|
4795
5217
|
var _SessionToolRunner_onIdle;
|
|
4796
|
-
var
|
|
5218
|
+
var _SessionToolRunner_idleClock;
|
|
4797
5219
|
var _SessionToolRunner_requestOptions;
|
|
4798
5220
|
var _SessionToolRunner_streamLoop;
|
|
4799
5221
|
var _SessionToolRunner_reconcile;
|
|
4800
5222
|
var _SessionToolRunner_ingestHistory;
|
|
4801
5223
|
var _SessionToolRunner_handleStreamEvent;
|
|
4802
|
-
var
|
|
4803
|
-
var
|
|
5224
|
+
var _SessionToolRunner_routeToolEvent;
|
|
5225
|
+
var _SessionToolRunner_noteConfirmation;
|
|
5226
|
+
var _SessionToolRunner_applyVerdict;
|
|
5227
|
+
var _SessionToolRunner_surfaceCall;
|
|
4804
5228
|
var _SessionToolRunner_execute;
|
|
4805
5229
|
var _SessionToolRunner_sendResult;
|
|
4806
5230
|
var _SessionToolRunner_drain;
|
|
4807
5231
|
/** Beta header for the managed-agents API. */
|
|
4808
5232
|
const MANAGED_AGENTS_BETA = "managed-agents-2026-04-01";
|
|
4809
|
-
/** `x-stainless-helper` value identifying this helper in SDK telemetry. */
|
|
4810
|
-
const HELPER_NAME = "SessionToolRunner";
|
|
4811
5233
|
const STREAM_BACKOFF_START_MS = 500;
|
|
4812
5234
|
const STREAM_BACKOFF_CAP_MS = 1e4;
|
|
4813
5235
|
const TOOL_TIMEOUT_MS = 12e4;
|
|
@@ -4820,6 +5242,82 @@ function isEndTurnIdle(ev) {
|
|
|
4820
5242
|
return ev.type === "session.status_idle" && ev.stop_reason?.type === "end_turn";
|
|
4821
5243
|
}
|
|
4822
5244
|
/**
|
|
5245
|
+
* The `maxIdleMs` stop-countdown, including its deferral. {@link noteEvent}
|
|
5246
|
+
* arms on `session.status_idle` with `stop_reason: end_turn` and disarms on
|
|
5247
|
+
* anything else. Gated tool work registered via {@link block} — a call held for
|
|
5248
|
+
* user confirmation, or a user-approved call still dispatching — keeps
|
|
5249
|
+
* {@link arm} pending until {@link unblock} retires the last blocker, at which
|
|
5250
|
+
* point the countdown starts. Event-driven — there is no polling watchdog.
|
|
5251
|
+
*/
|
|
5252
|
+
var IdleClock = class {
|
|
5253
|
+
constructor(maxIdleMs, onExpire) {
|
|
5254
|
+
_IdleClock_maxIdleMs.set(this, void 0);
|
|
5255
|
+
_IdleClock_onExpire.set(this, void 0);
|
|
5256
|
+
_IdleClock_blockers.set(this, new Set());
|
|
5257
|
+
_IdleClock_armPending.set(this, false);
|
|
5258
|
+
_IdleClock_timer.set(this, void 0);
|
|
5259
|
+
__classPrivateFieldSet(this, _IdleClock_maxIdleMs, maxIdleMs, "f");
|
|
5260
|
+
__classPrivateFieldSet(this, _IdleClock_onExpire, onExpire, "f");
|
|
5261
|
+
}
|
|
5262
|
+
/**
|
|
5263
|
+
* Arm on `status_idle{end_turn}`; disarm otherwise. `user.tool_confirmation`
|
|
5264
|
+
* is neutral: it signals neither agent activity nor an idle, and its effect
|
|
5265
|
+
* on the clock flows through {@link block} / {@link unblock} instead —
|
|
5266
|
+
* disarming here would discard the pending arm the verdict is about to
|
|
5267
|
+
* settle.
|
|
5268
|
+
*/
|
|
5269
|
+
noteEvent(ev) {
|
|
5270
|
+
if (ev.type === "user.tool_confirmation") return;
|
|
5271
|
+
if (isEndTurnIdle(ev)) this.arm();
|
|
5272
|
+
else this.disarm();
|
|
5273
|
+
}
|
|
5274
|
+
/** Register gated work that must resolve before an idle countdown starts. */
|
|
5275
|
+
block(toolUseId) {
|
|
5276
|
+
__classPrivateFieldGet(this, _IdleClock_blockers, "f").add(toolUseId);
|
|
5277
|
+
if (__classPrivateFieldGet(this, _IdleClock_timer, "f") !== undefined) {
|
|
5278
|
+
__classPrivateFieldSet(this, _IdleClock_armPending, true, "f");
|
|
5279
|
+
clearTimeout(__classPrivateFieldGet(this, _IdleClock_timer, "f"));
|
|
5280
|
+
__classPrivateFieldSet(this, _IdleClock_timer, undefined, "f");
|
|
5281
|
+
}
|
|
5282
|
+
}
|
|
5283
|
+
/**
|
|
5284
|
+
* Retire gated work (a no-op for ids never blocked); applies a pending arm —
|
|
5285
|
+
* with a fresh full `maxIdleMs` window — once the last blocker retires.
|
|
5286
|
+
*/
|
|
5287
|
+
unblock(toolUseId) {
|
|
5288
|
+
__classPrivateFieldGet(this, _IdleClock_blockers, "f").delete(toolUseId);
|
|
5289
|
+
if (__classPrivateFieldGet(this, _IdleClock_blockers, "f").size === 0 && __classPrivateFieldGet(this, _IdleClock_armPending, "f")) this.arm();
|
|
5290
|
+
}
|
|
5291
|
+
/**
|
|
5292
|
+
* (Re)start the idle countdown — or, while blockers are outstanding, hold
|
|
5293
|
+
* the arm pending instead. Stopping then would drop a held call when its
|
|
5294
|
+
* verdict later arrives, or cut the runner off before a released call's
|
|
5295
|
+
* result can drive the next turn.
|
|
5296
|
+
*/
|
|
5297
|
+
arm() {
|
|
5298
|
+
if (__classPrivateFieldGet(this, _IdleClock_maxIdleMs, "f") <= 0) return;
|
|
5299
|
+
if (__classPrivateFieldGet(this, _IdleClock_blockers, "f").size > 0) {
|
|
5300
|
+
__classPrivateFieldSet(this, _IdleClock_armPending, true, "f");
|
|
5301
|
+
return;
|
|
5302
|
+
}
|
|
5303
|
+
__classPrivateFieldSet(this, _IdleClock_armPending, false, "f");
|
|
5304
|
+
if (__classPrivateFieldGet(this, _IdleClock_timer, "f") !== undefined) clearTimeout(__classPrivateFieldGet(this, _IdleClock_timer, "f"));
|
|
5305
|
+
__classPrivateFieldSet(this, _IdleClock_timer, setTimeout(__classPrivateFieldGet(this, _IdleClock_onExpire, "f"), __classPrivateFieldGet(this, _IdleClock_maxIdleMs, "f")), "f");
|
|
5306
|
+
}
|
|
5307
|
+
/**
|
|
5308
|
+
* Cancel the idle countdown and any pending arm. Blockers persist — they
|
|
5309
|
+
* track real outstanding work, retired only by {@link unblock}.
|
|
5310
|
+
*/
|
|
5311
|
+
disarm() {
|
|
5312
|
+
__classPrivateFieldSet(this, _IdleClock_armPending, false, "f");
|
|
5313
|
+
if (__classPrivateFieldGet(this, _IdleClock_timer, "f") !== undefined) {
|
|
5314
|
+
clearTimeout(__classPrivateFieldGet(this, _IdleClock_timer, "f"));
|
|
5315
|
+
__classPrivateFieldSet(this, _IdleClock_timer, undefined, "f");
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
};
|
|
5319
|
+
_IdleClock_maxIdleMs = new WeakMap(), _IdleClock_onExpire = new WeakMap(), _IdleClock_blockers = new WeakMap(), _IdleClock_armPending = new WeakMap(), _IdleClock_timer = new WeakMap();
|
|
5320
|
+
/**
|
|
4823
5321
|
* The sessions-side counterpart to `client.beta.messages.toolRunner`: an
|
|
4824
5322
|
* async-iterable that attaches to a managed-agents session, executes every
|
|
4825
5323
|
* incoming `agent.tool_use` and `agent.custom_tool_use` event against a local
|
|
@@ -4829,6 +5327,18 @@ function isEndTurnIdle(ev) {
|
|
|
4829
5327
|
* calls are not dispatched. Internally drives event-stream reconnect and result
|
|
4830
5328
|
* posting.
|
|
4831
5329
|
*
|
|
5330
|
+
* A call the server gated with `evaluated_permission: "ask"` (the `always_ask`
|
|
5331
|
+
* policy — or any value this SDK doesn't recognize, which fails closed) is held
|
|
5332
|
+
* until its `user.tool_confirmation` arrives: only an explicit `allow` runs it;
|
|
5333
|
+
* `deny` — or any verdict this SDK doesn't recognize, failing closed — is never
|
|
5334
|
+
* executed and posts nothing (the denial resolves the call server-side), but is
|
|
5335
|
+
* still yielded (`confirmation="deny"`, `posted=false`, `result=undefined`) so
|
|
5336
|
+
* the consumer can observe it. A held call — and a user-approved one still
|
|
5337
|
+
* dispatching — defers the `maxIdleMs` countdown, so an `end_turn` idle
|
|
5338
|
+
* observed in the meantime cannot stop the runner: it waits until the verdict
|
|
5339
|
+
* arrives, the session terminates, or the abort signal fires — pass
|
|
5340
|
+
* `AbortSignal.timeout(...)` for a wall-clock bound.
|
|
5341
|
+
*
|
|
4832
5342
|
* Iteration ends when the session terminates (`session.status_terminated` /
|
|
4833
5343
|
* `session.deleted`), when the consumer `break`s out of the loop or aborts the
|
|
4834
5344
|
* supplied signal, or — once the session has gone idle with
|
|
@@ -4861,10 +5371,12 @@ var SessionToolRunner = class {
|
|
|
4861
5371
|
_SessionToolRunner_logger.set(this, void 0);
|
|
4862
5372
|
_SessionToolRunner_seen.set(this, new Set());
|
|
4863
5373
|
_SessionToolRunner_answered.set(this, new Set());
|
|
5374
|
+
_SessionToolRunner_confirmationVerdicts.set(this, new Map());
|
|
5375
|
+
_SessionToolRunner_awaitingConfirmation.set(this, new Map());
|
|
4864
5376
|
_SessionToolRunner_results.set(this, new AsyncQueue());
|
|
4865
5377
|
_SessionToolRunner_inFlightCount.set(this, 0);
|
|
4866
5378
|
_SessionToolRunner_onIdle.set(this, null);
|
|
4867
|
-
|
|
5379
|
+
_SessionToolRunner_idleClock.set(this, void 0);
|
|
4868
5380
|
this.client = opts.client;
|
|
4869
5381
|
this.sessionId = sessionId;
|
|
4870
5382
|
this.tools = opts.tools;
|
|
@@ -4874,6 +5386,14 @@ var SessionToolRunner = class {
|
|
|
4874
5386
|
__classPrivateFieldSet(this, _SessionToolRunner_controller, new AbortController(), "f");
|
|
4875
5387
|
__classPrivateFieldSet(this, _SessionToolRunner_detachExternal, linkAbort(opts.signal, __classPrivateFieldGet(this, _SessionToolRunner_controller, "f")), "f");
|
|
4876
5388
|
__classPrivateFieldSet(this, _SessionToolRunner_requestOpts, opts.requestOptions, "f");
|
|
5389
|
+
__classPrivateFieldSet(this, _SessionToolRunner_idleClock, new IdleClock(this.maxIdleMs, () => {
|
|
5390
|
+
__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info("session idle after end_turn; stopping", {
|
|
5391
|
+
component: "session-tool-runner",
|
|
5392
|
+
session_id: this.sessionId,
|
|
5393
|
+
max_idle_ms: this.maxIdleMs
|
|
5394
|
+
});
|
|
5395
|
+
__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
|
|
5396
|
+
}), "f");
|
|
4877
5397
|
}
|
|
4878
5398
|
/** Read-only view of this runner's abort signal. */
|
|
4879
5399
|
get signal() {
|
|
@@ -4883,7 +5403,7 @@ var SessionToolRunner = class {
|
|
|
4883
5403
|
abort() {
|
|
4884
5404
|
__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
|
|
4885
5405
|
}
|
|
4886
|
-
async *[(_SessionToolRunner_consumed = new WeakMap(), _SessionToolRunner_controller = new WeakMap(), _SessionToolRunner_detachExternal = new WeakMap(), _SessionToolRunner_requestOpts = new WeakMap(), _SessionToolRunner_toolByName = new WeakMap(), _SessionToolRunner_logger = new WeakMap(), _SessionToolRunner_seen = new WeakMap(), _SessionToolRunner_answered = new WeakMap(), _SessionToolRunner_results = new WeakMap(), _SessionToolRunner_inFlightCount = new WeakMap(), _SessionToolRunner_onIdle = new WeakMap(),
|
|
5406
|
+
async *[(_SessionToolRunner_consumed = new WeakMap(), _SessionToolRunner_controller = new WeakMap(), _SessionToolRunner_detachExternal = new WeakMap(), _SessionToolRunner_requestOpts = new WeakMap(), _SessionToolRunner_toolByName = new WeakMap(), _SessionToolRunner_logger = new WeakMap(), _SessionToolRunner_seen = new WeakMap(), _SessionToolRunner_answered = new WeakMap(), _SessionToolRunner_confirmationVerdicts = new WeakMap(), _SessionToolRunner_awaitingConfirmation = new WeakMap(), _SessionToolRunner_results = new WeakMap(), _SessionToolRunner_inFlightCount = new WeakMap(), _SessionToolRunner_onIdle = new WeakMap(), _SessionToolRunner_idleClock = new WeakMap(), _SessionToolRunner_instances = new WeakSet(), Symbol.asyncIterator)]() {
|
|
4887
5407
|
if (__classPrivateFieldGet(this, _SessionToolRunner_consumed, "f")) {
|
|
4888
5408
|
throw new AnthropicError("Cannot iterate over a consumed SessionToolRunner");
|
|
4889
5409
|
}
|
|
@@ -4911,7 +5431,7 @@ var SessionToolRunner = class {
|
|
|
4911
5431
|
}
|
|
4912
5432
|
} finally {
|
|
4913
5433
|
__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
|
|
4914
|
-
__classPrivateFieldGet(this,
|
|
5434
|
+
__classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").disarm();
|
|
4915
5435
|
await streamPromise;
|
|
4916
5436
|
try {
|
|
4917
5437
|
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_drain).call(this);
|
|
@@ -4936,7 +5456,7 @@ var SessionToolRunner = class {
|
|
|
4936
5456
|
_SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions() {
|
|
4937
5457
|
return {
|
|
4938
5458
|
...__classPrivateFieldGet(this, _SessionToolRunner_requestOpts, "f"),
|
|
4939
|
-
headers: buildHeaders([
|
|
5459
|
+
headers: buildHeaders([helperHeader("session-tool-runner"), __classPrivateFieldGet(this, _SessionToolRunner_requestOpts, "f")?.headers]),
|
|
4940
5460
|
signal: __classPrivateFieldGet(this, _SessionToolRunner_controller, "f").signal
|
|
4941
5461
|
};
|
|
4942
5462
|
}, _SessionToolRunner_streamLoop = async function _SessionToolRunner_streamLoop() {
|
|
@@ -4982,9 +5502,15 @@ _SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions()
|
|
|
4982
5502
|
return;
|
|
4983
5503
|
}
|
|
4984
5504
|
const unanswered = pending.filter((ev) => !__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.id));
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
for (const
|
|
5505
|
+
__classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").disarm();
|
|
5506
|
+
for (const ev of unanswered) await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_routeToolEvent).call(this, ev);
|
|
5507
|
+
for (const held of [...__classPrivateFieldGet(this, _SessionToolRunner_awaitingConfirmation, "f").values()]) {
|
|
5508
|
+
const verdict = __classPrivateFieldGet(this, _SessionToolRunner_confirmationVerdicts, "f").get(held.id);
|
|
5509
|
+
if (verdict !== undefined) await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_applyVerdict).call(this, held, verdict);
|
|
5510
|
+
}
|
|
5511
|
+
const outstanding = unanswered.filter((ev) => !__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.id) && !__classPrivateFieldGet(this, _SessionToolRunner_awaitingConfirmation, "f").has(ev.id));
|
|
5512
|
+
if (lastWasEndTurn && outstanding.length === 0) __classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").arm();
|
|
5513
|
+
else __classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").disarm();
|
|
4988
5514
|
}, _SessionToolRunner_ingestHistory = function _SessionToolRunner_ingestHistory(ev, pending) {
|
|
4989
5515
|
if (ev.type === "agent.tool_use" || ev.type === "agent.custom_tool_use") {
|
|
4990
5516
|
__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").add(ev.id);
|
|
@@ -4993,18 +5519,22 @@ _SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions()
|
|
|
4993
5519
|
__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.tool_use_id);
|
|
4994
5520
|
} else if (ev.type === "user.custom_tool_result") {
|
|
4995
5521
|
__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.custom_tool_use_id);
|
|
5522
|
+
} else if (ev.type === "user.tool_confirmation") {
|
|
5523
|
+
if (!__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.tool_use_id)) __classPrivateFieldGet(this, _SessionToolRunner_confirmationVerdicts, "f").set(ev.tool_use_id, ev.result);
|
|
4996
5524
|
}
|
|
4997
5525
|
}, _SessionToolRunner_handleStreamEvent = async function _SessionToolRunner_handleStreamEvent(ev) {
|
|
4998
|
-
|
|
4999
|
-
else __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_disarmIdleTimer).call(this);
|
|
5526
|
+
__classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").noteEvent(ev);
|
|
5000
5527
|
switch (ev.type) {
|
|
5001
5528
|
case "agent.tool_use":
|
|
5002
5529
|
case "agent.custom_tool_use":
|
|
5003
5530
|
if (!__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").has(ev.id)) {
|
|
5004
5531
|
__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").add(ev.id);
|
|
5005
|
-
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m",
|
|
5532
|
+
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_routeToolEvent).call(this, ev);
|
|
5006
5533
|
}
|
|
5007
5534
|
return false;
|
|
5535
|
+
case "user.tool_confirmation":
|
|
5536
|
+
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_noteConfirmation).call(this, ev);
|
|
5537
|
+
return false;
|
|
5008
5538
|
case "user.tool_result":
|
|
5009
5539
|
__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.tool_use_id);
|
|
5010
5540
|
return false;
|
|
@@ -5021,23 +5551,66 @@ _SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions()
|
|
|
5021
5551
|
return true;
|
|
5022
5552
|
default: return false;
|
|
5023
5553
|
}
|
|
5024
|
-
},
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5554
|
+
}, _SessionToolRunner_routeToolEvent = async function _SessionToolRunner_routeToolEvent(ev) {
|
|
5555
|
+
const permission = ev.evaluated_permission;
|
|
5556
|
+
const verdict = permission === "deny" ? "deny" : __classPrivateFieldGet(this, _SessionToolRunner_confirmationVerdicts, "f").get(ev.id);
|
|
5557
|
+
if (verdict === undefined) {
|
|
5558
|
+
if (permission === undefined || permission === "allow") {
|
|
5559
|
+
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_execute).call(this, ev, undefined);
|
|
5560
|
+
} else if (!__classPrivateFieldGet(this, _SessionToolRunner_awaitingConfirmation, "f").has(ev.id)) {
|
|
5561
|
+
__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info("tool call awaiting confirmation; holding", {
|
|
5562
|
+
component: "session-tool-runner",
|
|
5563
|
+
session_id: this.sessionId,
|
|
5564
|
+
tool: ev.name,
|
|
5565
|
+
tool_use_id: ev.id
|
|
5566
|
+
});
|
|
5567
|
+
__classPrivateFieldGet(this, _SessionToolRunner_awaitingConfirmation, "f").set(ev.id, ev);
|
|
5568
|
+
__classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").block(ev.id);
|
|
5569
|
+
}
|
|
5570
|
+
return;
|
|
5571
|
+
}
|
|
5572
|
+
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_applyVerdict).call(this, ev, verdict);
|
|
5573
|
+
}, _SessionToolRunner_noteConfirmation = async function _SessionToolRunner_noteConfirmation(ev) {
|
|
5574
|
+
__classPrivateFieldGet(this, _SessionToolRunner_confirmationVerdicts, "f").set(ev.tool_use_id, ev.result);
|
|
5575
|
+
const held = __classPrivateFieldGet(this, _SessionToolRunner_awaitingConfirmation, "f").get(ev.tool_use_id);
|
|
5576
|
+
if (held === undefined) return;
|
|
5577
|
+
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_applyVerdict).call(this, held, ev.result);
|
|
5578
|
+
}, _SessionToolRunner_applyVerdict = async function _SessionToolRunner_applyVerdict(ev, verdict) {
|
|
5579
|
+
const wasHeld = __classPrivateFieldGet(this, _SessionToolRunner_awaitingConfirmation, "f").delete(ev.id);
|
|
5580
|
+
if (verdict === "allow") {
|
|
5581
|
+
__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info("tool call confirmed", {
|
|
5029
5582
|
component: "session-tool-runner",
|
|
5030
5583
|
session_id: this.sessionId,
|
|
5031
|
-
|
|
5584
|
+
tool: ev.name,
|
|
5585
|
+
tool_use_id: ev.id
|
|
5032
5586
|
});
|
|
5033
|
-
__classPrivateFieldGet(this,
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5587
|
+
if (!wasHeld) __classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").block(ev.id);
|
|
5588
|
+
try {
|
|
5589
|
+
await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_execute).call(this, ev, "allow");
|
|
5590
|
+
} finally {
|
|
5591
|
+
__classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").unblock(ev.id);
|
|
5592
|
+
}
|
|
5593
|
+
return;
|
|
5039
5594
|
}
|
|
5040
|
-
|
|
5595
|
+
if (wasHeld) __classPrivateFieldGet(this, _SessionToolRunner_idleClock, "f").unblock(ev.id);
|
|
5596
|
+
__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.id);
|
|
5597
|
+
__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info("tool call denied; not executing", {
|
|
5598
|
+
component: "session-tool-runner",
|
|
5599
|
+
session_id: this.sessionId,
|
|
5600
|
+
tool: ev.name,
|
|
5601
|
+
tool_use_id: ev.id
|
|
5602
|
+
});
|
|
5603
|
+
__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_surfaceCall).call(this, {
|
|
5604
|
+
event: ev,
|
|
5605
|
+
toolUseId: ev.id,
|
|
5606
|
+
name: ev.name,
|
|
5607
|
+
isError: false,
|
|
5608
|
+
posted: false,
|
|
5609
|
+
confirmation: "deny"
|
|
5610
|
+
});
|
|
5611
|
+
}, _SessionToolRunner_surfaceCall = function _SessionToolRunner_surfaceCall(call) {
|
|
5612
|
+
__classPrivateFieldGet(this, _SessionToolRunner_results, "f").push(call);
|
|
5613
|
+
}, _SessionToolRunner_execute = async function _SessionToolRunner_execute(ev, confirmation) {
|
|
5041
5614
|
var _a, _b;
|
|
5042
5615
|
if (__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.id)) return;
|
|
5043
5616
|
__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info("executing tool", {
|
|
@@ -5056,12 +5629,13 @@ _SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions()
|
|
|
5056
5629
|
tool: ev.name,
|
|
5057
5630
|
tool_use_id: ev.id
|
|
5058
5631
|
});
|
|
5059
|
-
__classPrivateFieldGet(this,
|
|
5632
|
+
__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_surfaceCall).call(this, {
|
|
5060
5633
|
event: ev,
|
|
5061
5634
|
toolUseId: ev.id,
|
|
5062
5635
|
name: ev.name,
|
|
5063
5636
|
isError: false,
|
|
5064
|
-
posted: false
|
|
5637
|
+
posted: false,
|
|
5638
|
+
confirmation
|
|
5065
5639
|
});
|
|
5066
5640
|
return;
|
|
5067
5641
|
}
|
|
@@ -5084,13 +5658,14 @@ _SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions()
|
|
|
5084
5658
|
}
|
|
5085
5659
|
const result = buildResultEvent(ev, isError, toSessionContent(content));
|
|
5086
5660
|
const posted = await __classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_sendResult).call(this, result, ev.id);
|
|
5087
|
-
__classPrivateFieldGet(this,
|
|
5661
|
+
__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_surfaceCall).call(this, {
|
|
5088
5662
|
event: ev,
|
|
5089
5663
|
result,
|
|
5090
5664
|
toolUseId: ev.id,
|
|
5091
5665
|
name: ev.name,
|
|
5092
5666
|
isError,
|
|
5093
|
-
posted
|
|
5667
|
+
posted,
|
|
5668
|
+
confirmation
|
|
5094
5669
|
});
|
|
5095
5670
|
} finally {
|
|
5096
5671
|
__classPrivateFieldSet(this, _SessionToolRunner_inFlightCount, (_b = __classPrivateFieldGet(this, _SessionToolRunner_inFlightCount, "f"), _b--, _b), "f");
|
|
@@ -5182,7 +5757,7 @@ function toSessionContent(content) {
|
|
|
5182
5757
|
}
|
|
5183
5758
|
|
|
5184
5759
|
//#endregion
|
|
5185
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
5760
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/environments/worker.mjs
|
|
5186
5761
|
var _EnvironmentWorker_instances;
|
|
5187
5762
|
var _EnvironmentWorker_signal;
|
|
5188
5763
|
var _EnvironmentWorker_handleItem;
|
|
@@ -5319,7 +5894,7 @@ _EnvironmentWorker_signal = new WeakMap(), _EnvironmentWorker_instances = new We
|
|
|
5319
5894
|
...this.unrestrictedPaths !== undefined ? { unrestrictedPaths: this.unrestrictedPaths } : {},
|
|
5320
5895
|
...this.maxFileBytes !== undefined ? { maxFileBytes: this.maxFileBytes } : {}
|
|
5321
5896
|
};
|
|
5322
|
-
const agentToolset = await Promise.resolve().then(() => require("./node-
|
|
5897
|
+
const agentToolset = await Promise.resolve().then(() => require("./node-BYAxz9X-.cjs"));
|
|
5323
5898
|
let cleanupSkills = async () => {};
|
|
5324
5899
|
try {
|
|
5325
5900
|
cleanupSkills = await agentToolset.setupSkills(ctx);
|
|
@@ -5440,7 +6015,7 @@ async function heartbeatLoop(client, work, ctrl, logger, requestOptions) {
|
|
|
5440
6015
|
}
|
|
5441
6016
|
|
|
5442
6017
|
//#endregion
|
|
5443
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6018
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/environments/work.mjs
|
|
5444
6019
|
var Work = class extends APIResource {
|
|
5445
6020
|
/**
|
|
5446
6021
|
* Note: these endpoints are called automatically by the pre-built environment
|
|
@@ -5686,7 +6261,7 @@ Work.WorkPoller = WorkPoller;
|
|
|
5686
6261
|
Work.EnvironmentWorker = EnvironmentWorker;
|
|
5687
6262
|
|
|
5688
6263
|
//#endregion
|
|
5689
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6264
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/environments/environments.mjs
|
|
5690
6265
|
var Environments = class extends APIResource {
|
|
5691
6266
|
constructor() {
|
|
5692
6267
|
super(...arguments);
|
|
@@ -5808,7 +6383,7 @@ var Environments = class extends APIResource {
|
|
|
5808
6383
|
Environments.Work = Work;
|
|
5809
6384
|
|
|
5810
6385
|
//#endregion
|
|
5811
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6386
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memories.mjs
|
|
5812
6387
|
var Memories = class extends APIResource {
|
|
5813
6388
|
/**
|
|
5814
6389
|
* Create a memory
|
|
@@ -5828,7 +6403,7 @@ var Memories = class extends APIResource {
|
|
|
5828
6403
|
query: { view },
|
|
5829
6404
|
body,
|
|
5830
6405
|
...options,
|
|
5831
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6406
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5832
6407
|
});
|
|
5833
6408
|
}
|
|
5834
6409
|
/**
|
|
@@ -5848,7 +6423,7 @@ var Memories = class extends APIResource {
|
|
|
5848
6423
|
return this._client.get(path`/v1/memory_stores/${memory_store_id}/memories/${memoryID}?beta=true`, {
|
|
5849
6424
|
query,
|
|
5850
6425
|
...options,
|
|
5851
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6426
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5852
6427
|
});
|
|
5853
6428
|
}
|
|
5854
6429
|
/**
|
|
@@ -5869,7 +6444,7 @@ var Memories = class extends APIResource {
|
|
|
5869
6444
|
query: { view },
|
|
5870
6445
|
body,
|
|
5871
6446
|
...options,
|
|
5872
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6447
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5873
6448
|
});
|
|
5874
6449
|
}
|
|
5875
6450
|
/**
|
|
@@ -5890,7 +6465,7 @@ var Memories = class extends APIResource {
|
|
|
5890
6465
|
return this._client.getAPIList(path`/v1/memory_stores/${memoryStoreID}/memories?beta=true`, PageCursor, {
|
|
5891
6466
|
query,
|
|
5892
6467
|
...options,
|
|
5893
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6468
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5894
6469
|
});
|
|
5895
6470
|
}
|
|
5896
6471
|
/**
|
|
@@ -5910,13 +6485,13 @@ var Memories = class extends APIResource {
|
|
|
5910
6485
|
return this._client.delete(path`/v1/memory_stores/${memory_store_id}/memories/${memoryID}?beta=true`, {
|
|
5911
6486
|
query: { expected_content_sha256 },
|
|
5912
6487
|
...options,
|
|
5913
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6488
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5914
6489
|
});
|
|
5915
6490
|
}
|
|
5916
6491
|
};
|
|
5917
6492
|
|
|
5918
6493
|
//#endregion
|
|
5919
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6494
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memory-versions.mjs
|
|
5920
6495
|
var MemoryVersions = class extends APIResource {
|
|
5921
6496
|
/**
|
|
5922
6497
|
* Retrieve a memory version
|
|
@@ -5935,7 +6510,7 @@ var MemoryVersions = class extends APIResource {
|
|
|
5935
6510
|
return this._client.get(path`/v1/memory_stores/${memory_store_id}/memory_versions/${memoryVersionID}?beta=true`, {
|
|
5936
6511
|
query,
|
|
5937
6512
|
...options,
|
|
5938
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6513
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5939
6514
|
});
|
|
5940
6515
|
}
|
|
5941
6516
|
/**
|
|
@@ -5956,7 +6531,7 @@ var MemoryVersions = class extends APIResource {
|
|
|
5956
6531
|
return this._client.getAPIList(path`/v1/memory_stores/${memoryStoreID}/memory_versions?beta=true`, PageCursor, {
|
|
5957
6532
|
query,
|
|
5958
6533
|
...options,
|
|
5959
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6534
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5960
6535
|
});
|
|
5961
6536
|
}
|
|
5962
6537
|
/**
|
|
@@ -5975,13 +6550,13 @@ var MemoryVersions = class extends APIResource {
|
|
|
5975
6550
|
const { memory_store_id, betas } = params;
|
|
5976
6551
|
return this._client.post(path`/v1/memory_stores/${memory_store_id}/memory_versions/${memoryVersionID}/redact?beta=true`, {
|
|
5977
6552
|
...options,
|
|
5978
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6553
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
5979
6554
|
});
|
|
5980
6555
|
}
|
|
5981
6556
|
};
|
|
5982
6557
|
|
|
5983
6558
|
//#endregion
|
|
5984
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6559
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memory-stores.mjs
|
|
5985
6560
|
var MemoryStores = class extends APIResource {
|
|
5986
6561
|
constructor() {
|
|
5987
6562
|
super(...arguments);
|
|
@@ -6002,7 +6577,7 @@ var MemoryStores = class extends APIResource {
|
|
|
6002
6577
|
return this._client.post("/v1/memory_stores?beta=true", {
|
|
6003
6578
|
body,
|
|
6004
6579
|
...options,
|
|
6005
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6580
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
6006
6581
|
});
|
|
6007
6582
|
}
|
|
6008
6583
|
/**
|
|
@@ -6020,7 +6595,7 @@ var MemoryStores = class extends APIResource {
|
|
|
6020
6595
|
const { betas } = params ?? {};
|
|
6021
6596
|
return this._client.get(path`/v1/memory_stores/${memoryStoreID}?beta=true`, {
|
|
6022
6597
|
...options,
|
|
6023
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6598
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
6024
6599
|
});
|
|
6025
6600
|
}
|
|
6026
6601
|
/**
|
|
@@ -6037,7 +6612,7 @@ var MemoryStores = class extends APIResource {
|
|
|
6037
6612
|
return this._client.post(path`/v1/memory_stores/${memoryStoreID}?beta=true`, {
|
|
6038
6613
|
body,
|
|
6039
6614
|
...options,
|
|
6040
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6615
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
6041
6616
|
});
|
|
6042
6617
|
}
|
|
6043
6618
|
/**
|
|
@@ -6056,7 +6631,7 @@ var MemoryStores = class extends APIResource {
|
|
|
6056
6631
|
return this._client.getAPIList("/v1/memory_stores?beta=true", PageCursor, {
|
|
6057
6632
|
query,
|
|
6058
6633
|
...options,
|
|
6059
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6634
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
6060
6635
|
});
|
|
6061
6636
|
}
|
|
6062
6637
|
/**
|
|
@@ -6072,7 +6647,7 @@ var MemoryStores = class extends APIResource {
|
|
|
6072
6647
|
const { betas } = params ?? {};
|
|
6073
6648
|
return this._client.delete(path`/v1/memory_stores/${memoryStoreID}?beta=true`, {
|
|
6074
6649
|
...options,
|
|
6075
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6650
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
6076
6651
|
});
|
|
6077
6652
|
}
|
|
6078
6653
|
/**
|
|
@@ -6088,7 +6663,7 @@ var MemoryStores = class extends APIResource {
|
|
|
6088
6663
|
const { betas } = params ?? {};
|
|
6089
6664
|
return this._client.post(path`/v1/memory_stores/${memoryStoreID}/archive?beta=true`, {
|
|
6090
6665
|
...options,
|
|
6091
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
6666
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "agent-memory-2026-07-22"].toString() }, options?.headers])
|
|
6092
6667
|
});
|
|
6093
6668
|
}
|
|
6094
6669
|
};
|
|
@@ -6096,7 +6671,7 @@ MemoryStores.Memories = Memories;
|
|
|
6096
6671
|
MemoryStores.MemoryVersions = MemoryVersions;
|
|
6097
6672
|
|
|
6098
6673
|
//#endregion
|
|
6099
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6674
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.mjs
|
|
6100
6675
|
var JSONLDecoder = class JSONLDecoder {
|
|
6101
6676
|
constructor(iterator, controller) {
|
|
6102
6677
|
this.iterator = iterator;
|
|
@@ -6129,7 +6704,7 @@ var JSONLDecoder = class JSONLDecoder {
|
|
|
6129
6704
|
};
|
|
6130
6705
|
|
|
6131
6706
|
//#endregion
|
|
6132
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6707
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.mjs
|
|
6133
6708
|
var Batches$1 = class extends APIResource {
|
|
6134
6709
|
/**
|
|
6135
6710
|
* Send a batch of Message creation requests.
|
|
@@ -6139,7 +6714,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6139
6714
|
* can take up to 24 hours to complete.
|
|
6140
6715
|
*
|
|
6141
6716
|
* Learn more about the Message Batches API in our
|
|
6142
|
-
* [user guide](https://
|
|
6717
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
6143
6718
|
*
|
|
6144
6719
|
* @example
|
|
6145
6720
|
* ```ts
|
|
@@ -6161,11 +6736,14 @@ var Batches$1 = class extends APIResource {
|
|
|
6161
6736
|
* ```
|
|
6162
6737
|
*/
|
|
6163
6738
|
create(params, options) {
|
|
6164
|
-
const { betas, ...body } = params;
|
|
6739
|
+
const { betas, user_profile_id, ...body } = params;
|
|
6165
6740
|
return this._client.post("/v1/messages/batches?beta=true", {
|
|
6166
6741
|
body,
|
|
6167
6742
|
...options,
|
|
6168
|
-
headers: buildHeaders([{
|
|
6743
|
+
headers: buildHeaders([{
|
|
6744
|
+
"anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString(),
|
|
6745
|
+
...user_profile_id != null ? { "anthropic-user-profile-id": user_profile_id } : undefined
|
|
6746
|
+
}, options?.headers])
|
|
6169
6747
|
});
|
|
6170
6748
|
}
|
|
6171
6749
|
/**
|
|
@@ -6174,7 +6752,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6174
6752
|
* `results_url` field in the response.
|
|
6175
6753
|
*
|
|
6176
6754
|
* Learn more about the Message Batches API in our
|
|
6177
|
-
* [user guide](https://
|
|
6755
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
6178
6756
|
*
|
|
6179
6757
|
* @example
|
|
6180
6758
|
* ```ts
|
|
@@ -6196,7 +6774,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6196
6774
|
* returned first.
|
|
6197
6775
|
*
|
|
6198
6776
|
* Learn more about the Message Batches API in our
|
|
6199
|
-
* [user guide](https://
|
|
6777
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
6200
6778
|
*
|
|
6201
6779
|
* @example
|
|
6202
6780
|
* ```ts
|
|
@@ -6221,7 +6799,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6221
6799
|
* like to delete an in-progress batch, you must first cancel it.
|
|
6222
6800
|
*
|
|
6223
6801
|
* Learn more about the Message Batches API in our
|
|
6224
|
-
* [user guide](https://
|
|
6802
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
6225
6803
|
*
|
|
6226
6804
|
* @example
|
|
6227
6805
|
* ```ts
|
|
@@ -6250,7 +6828,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6250
6828
|
* non-interruptible.
|
|
6251
6829
|
*
|
|
6252
6830
|
* Learn more about the Message Batches API in our
|
|
6253
|
-
* [user guide](https://
|
|
6831
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
6254
6832
|
*
|
|
6255
6833
|
* @example
|
|
6256
6834
|
* ```ts
|
|
@@ -6275,7 +6853,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6275
6853
|
* requests. Use the `custom_id` field to match results to requests.
|
|
6276
6854
|
*
|
|
6277
6855
|
* Learn more about the Message Batches API in our
|
|
6278
|
-
* [user guide](https://
|
|
6856
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
6279
6857
|
*
|
|
6280
6858
|
* @example
|
|
6281
6859
|
* ```ts
|
|
@@ -6304,7 +6882,7 @@ var Batches$1 = class extends APIResource {
|
|
|
6304
6882
|
};
|
|
6305
6883
|
|
|
6306
6884
|
//#endregion
|
|
6307
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6885
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/constants.mjs
|
|
6308
6886
|
/**
|
|
6309
6887
|
* Model-specific timeout constraints for non-streaming requests
|
|
6310
6888
|
*/
|
|
@@ -6320,7 +6898,7 @@ const MODEL_NONSTREAMING_TOKENS = {
|
|
|
6320
6898
|
};
|
|
6321
6899
|
|
|
6322
6900
|
//#endregion
|
|
6323
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6901
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/beta-parser.mjs
|
|
6324
6902
|
function getOutputFormat$1(params) {
|
|
6325
6903
|
return params?.output_format ?? params?.output_config?.format;
|
|
6326
6904
|
}
|
|
@@ -6394,7 +6972,7 @@ function parseBetaOutputFormat(params, content) {
|
|
|
6394
6972
|
}
|
|
6395
6973
|
|
|
6396
6974
|
//#endregion
|
|
6397
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
6975
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.mjs
|
|
6398
6976
|
const tokenize = (input) => {
|
|
6399
6977
|
let current = 0;
|
|
6400
6978
|
let tokens = [];
|
|
@@ -6615,7 +7193,41 @@ const generate = (tokens) => {
|
|
|
6615
7193
|
const partialParse = (input) => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
|
6616
7194
|
|
|
6617
7195
|
//#endregion
|
|
6618
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
7196
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/message-stream-utils.mjs
|
|
7197
|
+
const JSON_BUF_PROPERTY = "__json_buf";
|
|
7198
|
+
/**
|
|
7199
|
+
* Copies a tool-use block with an updated `__json_buf`, installing `.input` as
|
|
7200
|
+
* a memoized getter so the partial-JSON parse happens on first read instead of
|
|
7201
|
+
* on every delta.
|
|
7202
|
+
*/
|
|
7203
|
+
function withLazyInput(prev, jsonBuf) {
|
|
7204
|
+
const next = {};
|
|
7205
|
+
for (const key of Object.keys(prev)) {
|
|
7206
|
+
if (key !== "input") next[key] = prev[key];
|
|
7207
|
+
}
|
|
7208
|
+
Object.defineProperty(next, JSON_BUF_PROPERTY, {
|
|
7209
|
+
value: jsonBuf,
|
|
7210
|
+
enumerable: false,
|
|
7211
|
+
writable: true
|
|
7212
|
+
});
|
|
7213
|
+
let input;
|
|
7214
|
+
let parsed = false;
|
|
7215
|
+
Object.defineProperty(next, "input", {
|
|
7216
|
+
enumerable: true,
|
|
7217
|
+
configurable: true,
|
|
7218
|
+
get() {
|
|
7219
|
+
if (!parsed) {
|
|
7220
|
+
input = jsonBuf ? partialParse(jsonBuf) : {};
|
|
7221
|
+
parsed = true;
|
|
7222
|
+
}
|
|
7223
|
+
return input;
|
|
7224
|
+
}
|
|
7225
|
+
});
|
|
7226
|
+
return next;
|
|
7227
|
+
}
|
|
7228
|
+
|
|
7229
|
+
//#endregion
|
|
7230
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.mjs
|
|
6619
7231
|
var _BetaMessageStream_instances;
|
|
6620
7232
|
var _BetaMessageStream_currentMessageSnapshot;
|
|
6621
7233
|
var _BetaMessageStream_params;
|
|
@@ -6640,7 +7252,7 @@ var _BetaMessageStream_beginRequest;
|
|
|
6640
7252
|
var _BetaMessageStream_addStreamEvent;
|
|
6641
7253
|
var _BetaMessageStream_endRequest;
|
|
6642
7254
|
var _BetaMessageStream_accumulateMessage;
|
|
6643
|
-
|
|
7255
|
+
var _BetaMessageStream_toolInputParseError;
|
|
6644
7256
|
function tracksToolInput$1(content) {
|
|
6645
7257
|
return content.type === "tool_use" || content.type === "server_tool_use" || content.type === "mcp_tool_use";
|
|
6646
7258
|
}
|
|
@@ -6754,7 +7366,7 @@ var BetaMessageStream = class BetaMessageStream {
|
|
|
6754
7366
|
...options,
|
|
6755
7367
|
headers: {
|
|
6756
7368
|
...options?.headers,
|
|
6757
|
-
|
|
7369
|
+
[STAINLESS_HELPER_METHOD_HEADER]: "stream"
|
|
6758
7370
|
}
|
|
6759
7371
|
}));
|
|
6760
7372
|
return runner;
|
|
@@ -7006,8 +7618,15 @@ var BetaMessageStream = class BetaMessageStream {
|
|
|
7006
7618
|
break;
|
|
7007
7619
|
}
|
|
7008
7620
|
case "input_json_delta": {
|
|
7009
|
-
if (tracksToolInput$1(content) &&
|
|
7010
|
-
|
|
7621
|
+
if (tracksToolInput$1(content) && __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f").inputJson?.length) {
|
|
7622
|
+
let jsonSnapshot;
|
|
7623
|
+
try {
|
|
7624
|
+
jsonSnapshot = content.input;
|
|
7625
|
+
} catch (err) {
|
|
7626
|
+
__classPrivateFieldGet(this, _BetaMessageStream_handleError, "f").call(this, __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_toolInputParseError).call(this, content, err));
|
|
7627
|
+
break;
|
|
7628
|
+
}
|
|
7629
|
+
this._emit("inputJson", event.delta.partial_json, jsonSnapshot);
|
|
7011
7630
|
}
|
|
7012
7631
|
break;
|
|
7013
7632
|
}
|
|
@@ -7099,6 +7718,9 @@ var BetaMessageStream = class BetaMessageStream {
|
|
|
7099
7718
|
return snapshot;
|
|
7100
7719
|
case "content_block_start":
|
|
7101
7720
|
snapshot.content.push(event.content_block);
|
|
7721
|
+
if (event.content_block.type === "fallback") {
|
|
7722
|
+
snapshot.model = event.content_block.to.model;
|
|
7723
|
+
}
|
|
7102
7724
|
return snapshot;
|
|
7103
7725
|
case "content_block_delta": {
|
|
7104
7726
|
const snapshotContent = snapshot.content.at(event.index);
|
|
@@ -7123,23 +7745,8 @@ var BetaMessageStream = class BetaMessageStream {
|
|
|
7123
7745
|
}
|
|
7124
7746
|
case "input_json_delta": {
|
|
7125
7747
|
if (snapshotContent && tracksToolInput$1(snapshotContent)) {
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
const newContent = { ...snapshotContent };
|
|
7129
|
-
Object.defineProperty(newContent, JSON_BUF_PROPERTY$1, {
|
|
7130
|
-
value: jsonBuf,
|
|
7131
|
-
enumerable: false,
|
|
7132
|
-
writable: true
|
|
7133
|
-
});
|
|
7134
|
-
if (jsonBuf) {
|
|
7135
|
-
try {
|
|
7136
|
-
newContent.input = partialParse(jsonBuf);
|
|
7137
|
-
} catch (err) {
|
|
7138
|
-
const error = new AnthropicError(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${err}. JSON: ${jsonBuf}`);
|
|
7139
|
-
__classPrivateFieldGet(this, _BetaMessageStream_handleError, "f").call(this, error);
|
|
7140
|
-
}
|
|
7141
|
-
}
|
|
7142
|
-
snapshot.content[event.index] = newContent;
|
|
7748
|
+
const jsonBuf = (snapshotContent["__json_buf"] || "") + event.delta.partial_json;
|
|
7749
|
+
snapshot.content[event.index] = withLazyInput(snapshotContent, jsonBuf);
|
|
7143
7750
|
}
|
|
7144
7751
|
break;
|
|
7145
7752
|
}
|
|
@@ -7175,8 +7782,29 @@ var BetaMessageStream = class BetaMessageStream {
|
|
|
7175
7782
|
}
|
|
7176
7783
|
return snapshot;
|
|
7177
7784
|
}
|
|
7178
|
-
case "content_block_stop":
|
|
7785
|
+
case "content_block_stop": {
|
|
7786
|
+
const snapshotContent = snapshot.content.at(event.index);
|
|
7787
|
+
if (snapshotContent && tracksToolInput$1(snapshotContent) && "__json_buf" in snapshotContent) {
|
|
7788
|
+
let input;
|
|
7789
|
+
try {
|
|
7790
|
+
input = snapshotContent.input;
|
|
7791
|
+
} catch (err) {
|
|
7792
|
+
input = {};
|
|
7793
|
+
__classPrivateFieldGet(this, _BetaMessageStream_handleError, "f").call(this, __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_toolInputParseError).call(this, snapshotContent, err));
|
|
7794
|
+
}
|
|
7795
|
+
Object.defineProperty(snapshotContent, "input", {
|
|
7796
|
+
value: input,
|
|
7797
|
+
enumerable: true,
|
|
7798
|
+
configurable: true,
|
|
7799
|
+
writable: true
|
|
7800
|
+
});
|
|
7801
|
+
}
|
|
7802
|
+
return snapshot;
|
|
7803
|
+
}
|
|
7179
7804
|
}
|
|
7805
|
+
}, _BetaMessageStream_toolInputParseError = function _BetaMessageStream_toolInputParseError(block, err) {
|
|
7806
|
+
const jsonBuf = block[JSON_BUF_PROPERTY];
|
|
7807
|
+
return new AnthropicError(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${err}. JSON: ${jsonBuf}`);
|
|
7180
7808
|
}, Symbol.asyncIterator)]() {
|
|
7181
7809
|
const pushQueue = [];
|
|
7182
7810
|
const readQueue = [];
|
|
@@ -7253,7 +7881,7 @@ var BetaMessageStream = class BetaMessageStream {
|
|
|
7253
7881
|
function checkNever$1(x) {}
|
|
7254
7882
|
|
|
7255
7883
|
//#endregion
|
|
7256
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
7884
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/internal/utils/promise.mjs
|
|
7257
7885
|
/**
|
|
7258
7886
|
* A deferred: a `Promise` together with its `resolve` / `reject` functions.
|
|
7259
7887
|
* This is `Promise.withResolvers()`, which is not available in all supported
|
|
@@ -7274,7 +7902,7 @@ function promiseWithResolvers() {
|
|
|
7274
7902
|
}
|
|
7275
7903
|
|
|
7276
7904
|
//#endregion
|
|
7277
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
7905
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/tools/CompactionControl.mjs
|
|
7278
7906
|
const DEFAULT_TOKEN_THRESHOLD = 1e5;
|
|
7279
7907
|
const DEFAULT_SUMMARY_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
7280
7908
|
1. Task Overview
|
|
@@ -7301,7 +7929,7 @@ Be concise but complete—err on the side of including information that would pr
|
|
|
7301
7929
|
Wrap your summary in <summary></summary> tags.`;
|
|
7302
7930
|
|
|
7303
7931
|
//#endregion
|
|
7304
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
7932
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
|
|
7305
7933
|
var _BetaToolRunner_instances;
|
|
7306
7934
|
var _BetaToolRunner_consumed;
|
|
7307
7935
|
var _BetaToolRunner_mutated;
|
|
@@ -7342,11 +7970,14 @@ var BetaToolRunner = class {
|
|
|
7342
7970
|
...params,
|
|
7343
7971
|
messages: structuredClone(params.messages)
|
|
7344
7972
|
} }, "f");
|
|
7345
|
-
const
|
|
7346
|
-
const helperValue = ["BetaToolRunner", ...helpers].join(", ");
|
|
7973
|
+
const collected = collectStainlessHelpers(params.tools, params.messages);
|
|
7347
7974
|
__classPrivateFieldSet(this, _BetaToolRunner_options, {
|
|
7348
7975
|
...options,
|
|
7349
|
-
headers: buildHeaders([
|
|
7976
|
+
headers: buildHeaders([
|
|
7977
|
+
helperHeader("BetaToolRunner"),
|
|
7978
|
+
collected.length ? { [STAINLESS_HELPER_HEADER]: collected.join(", ") } : undefined,
|
|
7979
|
+
options?.headers
|
|
7980
|
+
])
|
|
7350
7981
|
}, "f");
|
|
7351
7982
|
__classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
|
|
7352
7983
|
if (params.compactionControl?.enabled) {
|
|
@@ -7398,7 +8029,7 @@ var BetaToolRunner = class {
|
|
|
7398
8029
|
max_tokens: __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_tokens
|
|
7399
8030
|
}, {
|
|
7400
8031
|
signal: __classPrivateFieldGet(this, _BetaToolRunner_options, "f").signal,
|
|
7401
|
-
headers: buildHeaders([__classPrivateFieldGet(this, _BetaToolRunner_options, "f").headers,
|
|
8032
|
+
headers: buildHeaders([__classPrivateFieldGet(this, _BetaToolRunner_options, "f").headers, helperHeader("compaction")])
|
|
7402
8033
|
});
|
|
7403
8034
|
if (response.content[0]?.type !== "text") {
|
|
7404
8035
|
throw new AnthropicError("Expected text response for compaction");
|
|
@@ -7443,11 +8074,14 @@ var BetaToolRunner = class {
|
|
|
7443
8074
|
const isCompacted = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_checkAndCompact).call(this);
|
|
7444
8075
|
if (!isCompacted) {
|
|
7445
8076
|
if (!__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
|
7446
|
-
const
|
|
8077
|
+
const message = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
7447
8078
|
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push({
|
|
7448
|
-
role,
|
|
7449
|
-
content
|
|
8079
|
+
role: message.role,
|
|
8080
|
+
content: message.content
|
|
7450
8081
|
});
|
|
8082
|
+
if (message.stop_reason === "refusal") {
|
|
8083
|
+
break;
|
|
8084
|
+
}
|
|
7451
8085
|
}
|
|
7452
8086
|
const toolMessage = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1));
|
|
7453
8087
|
if (toolMessage) {
|
|
@@ -7653,7 +8287,7 @@ async function generateToolResponse(params, lastMessage = params.messages.at(-1)
|
|
|
7653
8287
|
}
|
|
7654
8288
|
|
|
7655
8289
|
//#endregion
|
|
7656
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8290
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
|
|
7657
8291
|
const DEPRECATED_MODELS$1 = {
|
|
7658
8292
|
"claude-1.3": "November 6th, 2024",
|
|
7659
8293
|
"claude-1.3-100k": "November 6th, 2024",
|
|
@@ -7666,8 +8300,15 @@ const DEPRECATED_MODELS$1 = {
|
|
|
7666
8300
|
"claude-2.0": "July 21st, 2025",
|
|
7667
8301
|
"claude-3-7-sonnet-latest": "February 19th, 2026",
|
|
7668
8302
|
"claude-3-7-sonnet-20250219": "February 19th, 2026",
|
|
8303
|
+
"claude-3-5-haiku-latest": "February 19th, 2026",
|
|
8304
|
+
"claude-3-5-haiku-20241022": "February 19th, 2026",
|
|
8305
|
+
"claude-opus-4-0": "June 15th, 2026",
|
|
8306
|
+
"claude-opus-4-20250514": "June 15th, 2026",
|
|
8307
|
+
"claude-sonnet-4-0": "June 15th, 2026",
|
|
8308
|
+
"claude-sonnet-4-20250514": "June 15th, 2026",
|
|
7669
8309
|
"claude-opus-4-1": "August 5th, 2026",
|
|
7670
|
-
"claude-opus-4-1-20250805": "August 5th, 2026"
|
|
8310
|
+
"claude-opus-4-1-20250805": "August 5th, 2026",
|
|
8311
|
+
"claude-mythos-preview": "June 30th, 2026"
|
|
7671
8312
|
};
|
|
7672
8313
|
const MODELS_TO_WARN_WITH_THINKING_ENABLED$1 = ["claude-mythos-preview", "claude-opus-4-6"];
|
|
7673
8314
|
var Messages$1 = class extends APIResource {
|
|
@@ -7677,7 +8318,7 @@ var Messages$1 = class extends APIResource {
|
|
|
7677
8318
|
}
|
|
7678
8319
|
create(params, options) {
|
|
7679
8320
|
const modifiedParams = transformOutputFormat(params);
|
|
7680
|
-
const { betas, ...body } = modifiedParams;
|
|
8321
|
+
const { betas, user_profile_id, ...body } = modifiedParams;
|
|
7681
8322
|
if (body.model in DEPRECATED_MODELS$1) {
|
|
7682
8323
|
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS$1[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
7683
8324
|
}
|
|
@@ -7695,7 +8336,10 @@ var Messages$1 = class extends APIResource {
|
|
|
7695
8336
|
timeout: timeout ?? 6e5,
|
|
7696
8337
|
...options,
|
|
7697
8338
|
headers: buildHeaders([
|
|
7698
|
-
{
|
|
8339
|
+
{
|
|
8340
|
+
...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined,
|
|
8341
|
+
...user_profile_id != null ? { "anthropic-user-profile-id": user_profile_id } : undefined
|
|
8342
|
+
},
|
|
7699
8343
|
helperHeader,
|
|
7700
8344
|
options?.headers
|
|
7701
8345
|
]),
|
|
@@ -7738,7 +8382,7 @@ var Messages$1 = class extends APIResource {
|
|
|
7738
8382
|
* including tools, images, and documents, without creating it.
|
|
7739
8383
|
*
|
|
7740
8384
|
* Learn more about token counting in our
|
|
7741
|
-
* [user guide](https://
|
|
8385
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
|
|
7742
8386
|
*
|
|
7743
8387
|
* @example
|
|
7744
8388
|
* ```ts
|
|
@@ -7751,11 +8395,14 @@ var Messages$1 = class extends APIResource {
|
|
|
7751
8395
|
*/
|
|
7752
8396
|
countTokens(params, options) {
|
|
7753
8397
|
const modifiedParams = transformOutputFormat(params);
|
|
7754
|
-
const { betas, ...body } = modifiedParams;
|
|
8398
|
+
const { betas, user_profile_id, ...body } = modifiedParams;
|
|
7755
8399
|
return this._client.post("/v1/messages/count_tokens?beta=true", {
|
|
7756
8400
|
body,
|
|
7757
8401
|
...options,
|
|
7758
|
-
headers: buildHeaders([{
|
|
8402
|
+
headers: buildHeaders([{
|
|
8403
|
+
"anthropic-beta": [...betas ?? [], "token-counting-2024-11-01"].toString(),
|
|
8404
|
+
...user_profile_id != null ? { "anthropic-user-profile-id": user_profile_id } : undefined
|
|
8405
|
+
}, options?.headers])
|
|
7759
8406
|
});
|
|
7760
8407
|
}
|
|
7761
8408
|
toolRunner(body, options) {
|
|
@@ -7787,7 +8434,7 @@ Messages$1.BetaToolRunner = BetaToolRunner;
|
|
|
7787
8434
|
Messages$1.ToolError = ToolError;
|
|
7788
8435
|
|
|
7789
8436
|
//#endregion
|
|
7790
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8437
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/sessions/events.mjs
|
|
7791
8438
|
var Events$1 = class extends APIResource {
|
|
7792
8439
|
/**
|
|
7793
8440
|
* List Events
|
|
@@ -7854,8 +8501,9 @@ var Events$1 = class extends APIResource {
|
|
|
7854
8501
|
* ```
|
|
7855
8502
|
*/
|
|
7856
8503
|
stream(sessionID, params = {}, options) {
|
|
7857
|
-
const { betas } = params ?? {};
|
|
8504
|
+
const { betas, ...query } = params ?? {};
|
|
7858
8505
|
return this._client.get(path`/v1/sessions/${sessionID}/events/stream?beta=true`, {
|
|
8506
|
+
query,
|
|
7859
8507
|
...options,
|
|
7860
8508
|
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers]),
|
|
7861
8509
|
stream: true
|
|
@@ -7890,7 +8538,7 @@ var Events$1 = class extends APIResource {
|
|
|
7890
8538
|
Events$1.SessionToolRunner = SessionToolRunner;
|
|
7891
8539
|
|
|
7892
8540
|
//#endregion
|
|
7893
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8541
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/sessions/resources.mjs
|
|
7894
8542
|
var Resources = class extends APIResource {
|
|
7895
8543
|
/**
|
|
7896
8544
|
* Get Session Resource
|
|
@@ -8000,7 +8648,7 @@ var Resources = class extends APIResource {
|
|
|
8000
8648
|
};
|
|
8001
8649
|
|
|
8002
8650
|
//#endregion
|
|
8003
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8651
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/sessions/threads/events.mjs
|
|
8004
8652
|
var Events = class extends APIResource {
|
|
8005
8653
|
/**
|
|
8006
8654
|
* List Session Thread Events
|
|
@@ -8047,7 +8695,7 @@ var Events = class extends APIResource {
|
|
|
8047
8695
|
};
|
|
8048
8696
|
|
|
8049
8697
|
//#endregion
|
|
8050
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8698
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/sessions/threads/threads.mjs
|
|
8051
8699
|
var Threads = class extends APIResource {
|
|
8052
8700
|
constructor() {
|
|
8053
8701
|
super(...arguments);
|
|
@@ -8116,7 +8764,7 @@ var Threads = class extends APIResource {
|
|
|
8116
8764
|
Threads.Events = Events;
|
|
8117
8765
|
|
|
8118
8766
|
//#endregion
|
|
8119
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8767
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/sessions/sessions.mjs
|
|
8120
8768
|
var Sessions = class extends APIResource {
|
|
8121
8769
|
constructor() {
|
|
8122
8770
|
super(...arguments);
|
|
@@ -8194,7 +8842,7 @@ var Sessions = class extends APIResource {
|
|
|
8194
8842
|
*/
|
|
8195
8843
|
list(params = {}, options) {
|
|
8196
8844
|
const { betas, ...query } = params ?? {};
|
|
8197
|
-
return this._client.getAPIList("/v1/sessions?beta=true",
|
|
8845
|
+
return this._client.getAPIList("/v1/sessions?beta=true", BidirectionalPageCursor, {
|
|
8198
8846
|
query,
|
|
8199
8847
|
...options,
|
|
8200
8848
|
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "managed-agents-2026-04-01"].toString() }, options?.headers])
|
|
@@ -8242,7 +8890,7 @@ Sessions.Resources = Resources;
|
|
|
8242
8890
|
Sessions.Threads = Threads;
|
|
8243
8891
|
|
|
8244
8892
|
//#endregion
|
|
8245
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8893
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/skills/versions.mjs
|
|
8246
8894
|
var Versions = class extends APIResource {
|
|
8247
8895
|
/**
|
|
8248
8896
|
* Create Skill Version
|
|
@@ -8251,11 +8899,12 @@ var Versions = class extends APIResource {
|
|
|
8251
8899
|
* ```ts
|
|
8252
8900
|
* const version = await client.beta.skills.versions.create(
|
|
8253
8901
|
* 'skill_id',
|
|
8902
|
+
* { files: [fs.createReadStream('path/to/file')] },
|
|
8254
8903
|
* );
|
|
8255
8904
|
* ```
|
|
8256
8905
|
*/
|
|
8257
|
-
create(skillID, params
|
|
8258
|
-
const { betas, ...body } = params
|
|
8906
|
+
create(skillID, params, options) {
|
|
8907
|
+
const { betas, ...body } = params;
|
|
8259
8908
|
return this._client.post(path`/v1/skills/${skillID}/versions?beta=true`, multipartFormRequestOptions({
|
|
8260
8909
|
body,
|
|
8261
8910
|
...options,
|
|
@@ -8333,96 +8982,361 @@ var Versions = class extends APIResource {
|
|
|
8333
8982
|
* console.log(content);
|
|
8334
8983
|
* ```
|
|
8335
8984
|
*/
|
|
8336
|
-
download(version, params, options) {
|
|
8337
|
-
const { skill_id, betas } = params;
|
|
8338
|
-
return this._client.get(path`/v1/skills/${skill_id}/versions/${version}/content?beta=true`, {
|
|
8985
|
+
download(version, params, options) {
|
|
8986
|
+
const { skill_id, betas } = params;
|
|
8987
|
+
return this._client.get(path`/v1/skills/${skill_id}/versions/${version}/content?beta=true`, {
|
|
8988
|
+
...options,
|
|
8989
|
+
headers: buildHeaders([{
|
|
8990
|
+
"anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString(),
|
|
8991
|
+
Accept: "application/binary"
|
|
8992
|
+
}, options?.headers]),
|
|
8993
|
+
__binaryResponse: true
|
|
8994
|
+
});
|
|
8995
|
+
}
|
|
8996
|
+
};
|
|
8997
|
+
|
|
8998
|
+
//#endregion
|
|
8999
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/skills/skills.mjs
|
|
9000
|
+
var Skills = class extends APIResource {
|
|
9001
|
+
constructor() {
|
|
9002
|
+
super(...arguments);
|
|
9003
|
+
this.versions = new Versions(this._client);
|
|
9004
|
+
}
|
|
9005
|
+
/**
|
|
9006
|
+
* Create Skill
|
|
9007
|
+
*
|
|
9008
|
+
* @example
|
|
9009
|
+
* ```ts
|
|
9010
|
+
* const skill = await client.beta.skills.create({
|
|
9011
|
+
* files: [fs.createReadStream('path/to/file')],
|
|
9012
|
+
* });
|
|
9013
|
+
* ```
|
|
9014
|
+
*/
|
|
9015
|
+
create(params, options) {
|
|
9016
|
+
const { betas, ...body } = params;
|
|
9017
|
+
return this._client.post("/v1/skills?beta=true", multipartFormRequestOptions({
|
|
9018
|
+
body,
|
|
9019
|
+
...options,
|
|
9020
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() }, options?.headers])
|
|
9021
|
+
}, this._client, false));
|
|
9022
|
+
}
|
|
9023
|
+
/**
|
|
9024
|
+
* Get Skill
|
|
9025
|
+
*
|
|
9026
|
+
* @example
|
|
9027
|
+
* ```ts
|
|
9028
|
+
* const skill = await client.beta.skills.retrieve('skill_id');
|
|
9029
|
+
* ```
|
|
9030
|
+
*/
|
|
9031
|
+
retrieve(skillID, params = {}, options) {
|
|
9032
|
+
const { betas } = params ?? {};
|
|
9033
|
+
return this._client.get(path`/v1/skills/${skillID}?beta=true`, {
|
|
9034
|
+
...options,
|
|
9035
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() }, options?.headers])
|
|
9036
|
+
});
|
|
9037
|
+
}
|
|
9038
|
+
/**
|
|
9039
|
+
* List Skills
|
|
9040
|
+
*
|
|
9041
|
+
* @example
|
|
9042
|
+
* ```ts
|
|
9043
|
+
* // Automatically fetches more pages as needed.
|
|
9044
|
+
* for await (const skillListResponse of client.beta.skills.list()) {
|
|
9045
|
+
* // ...
|
|
9046
|
+
* }
|
|
9047
|
+
* ```
|
|
9048
|
+
*/
|
|
9049
|
+
list(params = {}, options) {
|
|
9050
|
+
const { betas, ...query } = params ?? {};
|
|
9051
|
+
return this._client.getAPIList("/v1/skills?beta=true", PageCursor, {
|
|
9052
|
+
query,
|
|
9053
|
+
...options,
|
|
9054
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() }, options?.headers])
|
|
9055
|
+
});
|
|
9056
|
+
}
|
|
9057
|
+
/**
|
|
9058
|
+
* Delete Skill
|
|
9059
|
+
*
|
|
9060
|
+
* @example
|
|
9061
|
+
* ```ts
|
|
9062
|
+
* const skill = await client.beta.skills.delete('skill_id');
|
|
9063
|
+
* ```
|
|
9064
|
+
*/
|
|
9065
|
+
delete(skillID, params = {}, options) {
|
|
9066
|
+
const { betas } = params ?? {};
|
|
9067
|
+
return this._client.delete(path`/v1/skills/${skillID}?beta=true`, {
|
|
9068
|
+
...options,
|
|
9069
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() }, options?.headers])
|
|
9070
|
+
});
|
|
9071
|
+
}
|
|
9072
|
+
};
|
|
9073
|
+
Skills.Versions = Versions;
|
|
9074
|
+
|
|
9075
|
+
//#endregion
|
|
9076
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/tunnels/certificates.mjs
|
|
9077
|
+
var Certificates = class extends APIResource {
|
|
9078
|
+
/**
|
|
9079
|
+
* The Tunnels API is in research preview. It requires the
|
|
9080
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9081
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9082
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9083
|
+
*
|
|
9084
|
+
* Registers a public CA certificate on a tunnel. Anthropic verifies the gateway's
|
|
9085
|
+
* server certificate against this CA when it terminates the inner TLS session. A
|
|
9086
|
+
* tunnel holds at most two non-archived certificates.
|
|
9087
|
+
*
|
|
9088
|
+
* @example
|
|
9089
|
+
* ```ts
|
|
9090
|
+
* const betaTunnelCertificate =
|
|
9091
|
+
* await client.beta.tunnels.certificates.create(
|
|
9092
|
+
* 'tunnel_id',
|
|
9093
|
+
* { ca_certificate_pem: 'ca_certificate_pem' },
|
|
9094
|
+
* );
|
|
9095
|
+
* ```
|
|
9096
|
+
*/
|
|
9097
|
+
create(tunnelID, params, options) {
|
|
9098
|
+
const { betas, ...body } = params;
|
|
9099
|
+
return this._client.post(path`/v1/tunnels/${tunnelID}/certificates?beta=true`, {
|
|
9100
|
+
body,
|
|
9101
|
+
...options,
|
|
9102
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
9103
|
+
});
|
|
9104
|
+
}
|
|
9105
|
+
/**
|
|
9106
|
+
* The Tunnels API is in research preview. It requires the
|
|
9107
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9108
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9109
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9110
|
+
*
|
|
9111
|
+
* Fetches a tunnel certificate by ID.
|
|
9112
|
+
*
|
|
9113
|
+
* @example
|
|
9114
|
+
* ```ts
|
|
9115
|
+
* const betaTunnelCertificate =
|
|
9116
|
+
* await client.beta.tunnels.certificates.retrieve(
|
|
9117
|
+
* 'certificate_id',
|
|
9118
|
+
* { tunnel_id: 'tunnel_id' },
|
|
9119
|
+
* );
|
|
9120
|
+
* ```
|
|
9121
|
+
*/
|
|
9122
|
+
retrieve(certificateID, params, options) {
|
|
9123
|
+
const { tunnel_id, betas } = params;
|
|
9124
|
+
return this._client.get(path`/v1/tunnels/${tunnel_id}/certificates/${certificateID}?beta=true`, {
|
|
9125
|
+
...options,
|
|
9126
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
9127
|
+
});
|
|
9128
|
+
}
|
|
9129
|
+
/**
|
|
9130
|
+
* The Tunnels API is in research preview. It requires the
|
|
9131
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9132
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9133
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9134
|
+
*
|
|
9135
|
+
* Lists the certificates registered on a tunnel. Archived certificates are
|
|
9136
|
+
* excluded unless include_archived is set.
|
|
9137
|
+
*
|
|
9138
|
+
* @example
|
|
9139
|
+
* ```ts
|
|
9140
|
+
* // Automatically fetches more pages as needed.
|
|
9141
|
+
* for await (const betaTunnelCertificate of client.beta.tunnels.certificates.list(
|
|
9142
|
+
* 'tunnel_id',
|
|
9143
|
+
* )) {
|
|
9144
|
+
* // ...
|
|
9145
|
+
* }
|
|
9146
|
+
* ```
|
|
9147
|
+
*/
|
|
9148
|
+
list(tunnelID, params = {}, options) {
|
|
9149
|
+
const { betas, ...query } = params ?? {};
|
|
9150
|
+
return this._client.getAPIList(path`/v1/tunnels/${tunnelID}/certificates?beta=true`, PageCursor, {
|
|
9151
|
+
query,
|
|
9152
|
+
...options,
|
|
9153
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
9154
|
+
});
|
|
9155
|
+
}
|
|
9156
|
+
/**
|
|
9157
|
+
* The Tunnels API is in research preview. It requires the
|
|
9158
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9159
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9160
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9161
|
+
*
|
|
9162
|
+
* Archives a tunnel certificate, removing it from the set Anthropic trusts for the
|
|
9163
|
+
* tunnel. The certificate record is retained. Archiving the last non-archived
|
|
9164
|
+
* certificate is permitted; the tunnel rejects MCP traffic until a new certificate
|
|
9165
|
+
* is added.
|
|
9166
|
+
*
|
|
9167
|
+
* @example
|
|
9168
|
+
* ```ts
|
|
9169
|
+
* const betaTunnelCertificate =
|
|
9170
|
+
* await client.beta.tunnels.certificates.archive(
|
|
9171
|
+
* 'certificate_id',
|
|
9172
|
+
* { tunnel_id: 'tunnel_id' },
|
|
9173
|
+
* );
|
|
9174
|
+
* ```
|
|
9175
|
+
*/
|
|
9176
|
+
archive(certificateID, params, options) {
|
|
9177
|
+
const { tunnel_id, betas } = params;
|
|
9178
|
+
return this._client.post(path`/v1/tunnels/${tunnel_id}/certificates/${certificateID}/archive?beta=true`, {
|
|
8339
9179
|
...options,
|
|
8340
|
-
headers: buildHeaders([{
|
|
8341
|
-
"anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString(),
|
|
8342
|
-
Accept: "application/binary"
|
|
8343
|
-
}, options?.headers]),
|
|
8344
|
-
__binaryResponse: true
|
|
9180
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
8345
9181
|
});
|
|
8346
9182
|
}
|
|
8347
9183
|
};
|
|
8348
9184
|
|
|
8349
9185
|
//#endregion
|
|
8350
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
8351
|
-
var
|
|
9186
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/tunnels/tunnels.mjs
|
|
9187
|
+
var Tunnels = class extends APIResource {
|
|
8352
9188
|
constructor() {
|
|
8353
9189
|
super(...arguments);
|
|
8354
|
-
this.
|
|
9190
|
+
this.certificates = new Certificates(this._client);
|
|
8355
9191
|
}
|
|
8356
9192
|
/**
|
|
8357
|
-
*
|
|
9193
|
+
* The Tunnels API is in research preview. It requires the
|
|
9194
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9195
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9196
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9197
|
+
*
|
|
9198
|
+
* Creates a tunnel. Creation allocates a fresh hostname and provisions the tunnel;
|
|
9199
|
+
* it is not idempotent. The new tunnel rejects MCP traffic until at least one CA
|
|
9200
|
+
* certificate is added.
|
|
8358
9201
|
*
|
|
8359
9202
|
* @example
|
|
8360
9203
|
* ```ts
|
|
8361
|
-
* const
|
|
9204
|
+
* const betaTunnel = await client.beta.tunnels.create();
|
|
8362
9205
|
* ```
|
|
8363
9206
|
*/
|
|
8364
|
-
create(params
|
|
8365
|
-
const { betas, ...body } = params
|
|
8366
|
-
return this._client.post("/v1/
|
|
9207
|
+
create(params, options) {
|
|
9208
|
+
const { betas, ...body } = params;
|
|
9209
|
+
return this._client.post("/v1/tunnels?beta=true", {
|
|
8367
9210
|
body,
|
|
8368
9211
|
...options,
|
|
8369
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
8370
|
-
}
|
|
9212
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
9213
|
+
});
|
|
8371
9214
|
}
|
|
8372
9215
|
/**
|
|
8373
|
-
*
|
|
9216
|
+
* The Tunnels API is in research preview. It requires the
|
|
9217
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9218
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9219
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9220
|
+
*
|
|
9221
|
+
* Fetches a tunnel by ID.
|
|
8374
9222
|
*
|
|
8375
9223
|
* @example
|
|
8376
9224
|
* ```ts
|
|
8377
|
-
* const
|
|
9225
|
+
* const betaTunnel = await client.beta.tunnels.retrieve(
|
|
9226
|
+
* 'tunnel_id',
|
|
9227
|
+
* );
|
|
8378
9228
|
* ```
|
|
8379
9229
|
*/
|
|
8380
|
-
retrieve(
|
|
9230
|
+
retrieve(tunnelID, params = {}, options) {
|
|
8381
9231
|
const { betas } = params ?? {};
|
|
8382
|
-
return this._client.get(path`/v1/
|
|
9232
|
+
return this._client.get(path`/v1/tunnels/${tunnelID}?beta=true`, {
|
|
8383
9233
|
...options,
|
|
8384
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
9234
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
8385
9235
|
});
|
|
8386
9236
|
}
|
|
8387
9237
|
/**
|
|
8388
|
-
*
|
|
9238
|
+
* The Tunnels API is in research preview. It requires the
|
|
9239
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9240
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9241
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9242
|
+
*
|
|
9243
|
+
* Lists tunnels. Results are ordered by creation time, newest first; archived
|
|
9244
|
+
* tunnels are excluded unless include_archived is set.
|
|
8389
9245
|
*
|
|
8390
9246
|
* @example
|
|
8391
9247
|
* ```ts
|
|
8392
9248
|
* // Automatically fetches more pages as needed.
|
|
8393
|
-
* for await (const
|
|
9249
|
+
* for await (const betaTunnel of client.beta.tunnels.list()) {
|
|
8394
9250
|
* // ...
|
|
8395
9251
|
* }
|
|
8396
9252
|
* ```
|
|
8397
9253
|
*/
|
|
8398
9254
|
list(params = {}, options) {
|
|
8399
9255
|
const { betas, ...query } = params ?? {};
|
|
8400
|
-
return this._client.getAPIList("/v1/
|
|
9256
|
+
return this._client.getAPIList("/v1/tunnels?beta=true", PageCursor, {
|
|
8401
9257
|
query,
|
|
8402
9258
|
...options,
|
|
8403
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
9259
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
8404
9260
|
});
|
|
8405
9261
|
}
|
|
8406
9262
|
/**
|
|
8407
|
-
*
|
|
9263
|
+
* The Tunnels API is in research preview. It requires the
|
|
9264
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9265
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9266
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9267
|
+
*
|
|
9268
|
+
* Archives a tunnel. Archival is irreversible: every non-archived certificate on
|
|
9269
|
+
* the tunnel is archived in the same operation, the hostname is retired and never
|
|
9270
|
+
* re-allocated, and the tunnel token is invalidated. Retrying against an
|
|
9271
|
+
* already-archived tunnel returns the existing record unchanged.
|
|
8408
9272
|
*
|
|
8409
9273
|
* @example
|
|
8410
9274
|
* ```ts
|
|
8411
|
-
* const
|
|
9275
|
+
* const betaTunnel = await client.beta.tunnels.archive(
|
|
9276
|
+
* 'tunnel_id',
|
|
9277
|
+
* );
|
|
8412
9278
|
* ```
|
|
8413
9279
|
*/
|
|
8414
|
-
|
|
9280
|
+
archive(tunnelID, params = {}, options) {
|
|
8415
9281
|
const { betas } = params ?? {};
|
|
8416
|
-
return this._client.
|
|
9282
|
+
return this._client.post(path`/v1/tunnels/${tunnelID}/archive?beta=true`, {
|
|
8417
9283
|
...options,
|
|
8418
|
-
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "
|
|
9284
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
9285
|
+
});
|
|
9286
|
+
}
|
|
9287
|
+
/**
|
|
9288
|
+
* The Tunnels API is in research preview. It requires the
|
|
9289
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9290
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9291
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9292
|
+
*
|
|
9293
|
+
* Reveals a tunnel's connector token. The value is fetched live on each call;
|
|
9294
|
+
* Anthropic does not store it. Repeated calls return the same value until the
|
|
9295
|
+
* token is rotated. Exposed as POST so the token does not appear in intermediary
|
|
9296
|
+
* access logs.
|
|
9297
|
+
*
|
|
9298
|
+
* @example
|
|
9299
|
+
* ```ts
|
|
9300
|
+
* const betaTunnelToken =
|
|
9301
|
+
* await client.beta.tunnels.revealToken('tunnel_id');
|
|
9302
|
+
* ```
|
|
9303
|
+
*/
|
|
9304
|
+
revealToken(tunnelID, params = {}, options) {
|
|
9305
|
+
const { betas } = params ?? {};
|
|
9306
|
+
return this._client.post(path`/v1/tunnels/${tunnelID}/reveal_token?beta=true`, {
|
|
9307
|
+
...options,
|
|
9308
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
9309
|
+
});
|
|
9310
|
+
}
|
|
9311
|
+
/**
|
|
9312
|
+
* The Tunnels API is in research preview. It requires the
|
|
9313
|
+
* `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a
|
|
9314
|
+
* deprecation period. It supersedes the Admin API endpoints at
|
|
9315
|
+
* `/v1/organizations/tunnels`, which remain available during a migration window.
|
|
9316
|
+
*
|
|
9317
|
+
* Rotates a tunnel's connector token. Rotation invalidates the current token for
|
|
9318
|
+
* new connections and returns a fresh value; established connections are not
|
|
9319
|
+
* severed. A connector restarted after rotation must use the new value.
|
|
9320
|
+
*
|
|
9321
|
+
* @example
|
|
9322
|
+
* ```ts
|
|
9323
|
+
* const betaTunnelToken =
|
|
9324
|
+
* await client.beta.tunnels.rotateToken('tunnel_id');
|
|
9325
|
+
* ```
|
|
9326
|
+
*/
|
|
9327
|
+
rotateToken(tunnelID, params, options) {
|
|
9328
|
+
const { betas, ...body } = params;
|
|
9329
|
+
return this._client.post(path`/v1/tunnels/${tunnelID}/rotate_token?beta=true`, {
|
|
9330
|
+
body,
|
|
9331
|
+
...options,
|
|
9332
|
+
headers: buildHeaders([{ "anthropic-beta": [...betas ?? [], "mcp-tunnels-2026-06-22"].toString() }, options?.headers])
|
|
8419
9333
|
});
|
|
8420
9334
|
}
|
|
8421
9335
|
};
|
|
8422
|
-
|
|
9336
|
+
Tunnels.Certificates = Certificates;
|
|
8423
9337
|
|
|
8424
9338
|
//#endregion
|
|
8425
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
9339
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/vaults/credentials.mjs
|
|
8426
9340
|
var Credentials = class extends APIResource {
|
|
8427
9341
|
/**
|
|
8428
9342
|
* Create Credential
|
|
@@ -8571,7 +9485,7 @@ var Credentials = class extends APIResource {
|
|
|
8571
9485
|
};
|
|
8572
9486
|
|
|
8573
9487
|
//#endregion
|
|
8574
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
9488
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/vaults/vaults.mjs
|
|
8575
9489
|
var Vaults = class extends APIResource {
|
|
8576
9490
|
constructor() {
|
|
8577
9491
|
super(...arguments);
|
|
@@ -8692,7 +9606,7 @@ var Vaults = class extends APIResource {
|
|
|
8692
9606
|
Vaults.Credentials = Credentials;
|
|
8693
9607
|
|
|
8694
9608
|
//#endregion
|
|
8695
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
9609
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
|
|
8696
9610
|
var Beta = class extends APIResource {
|
|
8697
9611
|
constructor() {
|
|
8698
9612
|
super(...arguments);
|
|
@@ -8701,12 +9615,16 @@ var Beta = class extends APIResource {
|
|
|
8701
9615
|
this.agents = new Agents(this._client);
|
|
8702
9616
|
this.environments = new Environments(this._client);
|
|
8703
9617
|
this.sessions = new Sessions(this._client);
|
|
9618
|
+
this.deployments = new Deployments(this._client);
|
|
9619
|
+
this.deploymentRuns = new DeploymentRuns(this._client);
|
|
8704
9620
|
this.vaults = new Vaults(this._client);
|
|
8705
9621
|
this.memoryStores = new MemoryStores(this._client);
|
|
8706
9622
|
this.files = new Files(this._client);
|
|
8707
9623
|
this.skills = new Skills(this._client);
|
|
8708
9624
|
this.webhooks = new Webhooks(this._client);
|
|
8709
9625
|
this.userProfiles = new UserProfiles(this._client);
|
|
9626
|
+
this.dreams = new Dreams(this._client);
|
|
9627
|
+
this.tunnels = new Tunnels(this._client);
|
|
8710
9628
|
}
|
|
8711
9629
|
};
|
|
8712
9630
|
Beta.Models = Models$1;
|
|
@@ -8714,15 +9632,19 @@ Beta.Messages = Messages$1;
|
|
|
8714
9632
|
Beta.Agents = Agents;
|
|
8715
9633
|
Beta.Environments = Environments;
|
|
8716
9634
|
Beta.Sessions = Sessions;
|
|
9635
|
+
Beta.Deployments = Deployments;
|
|
9636
|
+
Beta.DeploymentRuns = DeploymentRuns;
|
|
8717
9637
|
Beta.Vaults = Vaults;
|
|
8718
9638
|
Beta.MemoryStores = MemoryStores;
|
|
8719
9639
|
Beta.Files = Files;
|
|
8720
9640
|
Beta.Skills = Skills;
|
|
8721
9641
|
Beta.Webhooks = Webhooks;
|
|
8722
9642
|
Beta.UserProfiles = UserProfiles;
|
|
9643
|
+
Beta.Dreams = Dreams;
|
|
9644
|
+
Beta.Tunnels = Tunnels;
|
|
8723
9645
|
|
|
8724
9646
|
//#endregion
|
|
8725
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
9647
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/completions.mjs
|
|
8726
9648
|
var Completions = class extends APIResource {
|
|
8727
9649
|
create(params, options) {
|
|
8728
9650
|
const { betas, ...body } = params;
|
|
@@ -8737,7 +9659,7 @@ var Completions = class extends APIResource {
|
|
|
8737
9659
|
};
|
|
8738
9660
|
|
|
8739
9661
|
//#endregion
|
|
8740
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
9662
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/parser.mjs
|
|
8741
9663
|
function getOutputFormat(params) {
|
|
8742
9664
|
return params?.output_config?.format;
|
|
8743
9665
|
}
|
|
@@ -8799,7 +9721,7 @@ function parseOutputFormat(params, content) {
|
|
|
8799
9721
|
}
|
|
8800
9722
|
|
|
8801
9723
|
//#endregion
|
|
8802
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
9724
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/MessageStream.mjs
|
|
8803
9725
|
var _MessageStream_instances;
|
|
8804
9726
|
var _MessageStream_currentMessageSnapshot;
|
|
8805
9727
|
var _MessageStream_params;
|
|
@@ -8824,7 +9746,6 @@ var _MessageStream_beginRequest;
|
|
|
8824
9746
|
var _MessageStream_addStreamEvent;
|
|
8825
9747
|
var _MessageStream_endRequest;
|
|
8826
9748
|
var _MessageStream_accumulateMessage;
|
|
8827
|
-
const JSON_BUF_PROPERTY = "__json_buf";
|
|
8828
9749
|
function tracksToolInput(content) {
|
|
8829
9750
|
return content.type === "tool_use" || content.type === "server_tool_use";
|
|
8830
9751
|
}
|
|
@@ -8938,7 +9859,7 @@ var MessageStream = class MessageStream {
|
|
|
8938
9859
|
...options,
|
|
8939
9860
|
headers: {
|
|
8940
9861
|
...options?.headers,
|
|
8941
|
-
|
|
9862
|
+
[STAINLESS_HELPER_METHOD_HEADER]: "stream"
|
|
8942
9863
|
}
|
|
8943
9864
|
}));
|
|
8944
9865
|
return runner;
|
|
@@ -9190,7 +10111,7 @@ var MessageStream = class MessageStream {
|
|
|
9190
10111
|
break;
|
|
9191
10112
|
}
|
|
9192
10113
|
case "input_json_delta": {
|
|
9193
|
-
if (tracksToolInput(content) &&
|
|
10114
|
+
if (tracksToolInput(content) && __classPrivateFieldGet(this, _MessageStream_listeners, "f").inputJson?.length) {
|
|
9194
10115
|
this._emit("inputJson", event.delta.partial_json, content.input);
|
|
9195
10116
|
}
|
|
9196
10117
|
break;
|
|
@@ -9296,18 +10217,8 @@ var MessageStream = class MessageStream {
|
|
|
9296
10217
|
}
|
|
9297
10218
|
case "input_json_delta": {
|
|
9298
10219
|
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
const newContent = { ...snapshotContent };
|
|
9302
|
-
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
|
9303
|
-
value: jsonBuf,
|
|
9304
|
-
enumerable: false,
|
|
9305
|
-
writable: true
|
|
9306
|
-
});
|
|
9307
|
-
if (jsonBuf) {
|
|
9308
|
-
newContent.input = partialParse(jsonBuf);
|
|
9309
|
-
}
|
|
9310
|
-
snapshot.content[event.index] = newContent;
|
|
10220
|
+
const jsonBuf = (snapshotContent["__json_buf"] || "") + event.delta.partial_json;
|
|
10221
|
+
snapshot.content[event.index] = withLazyInput(snapshotContent, jsonBuf);
|
|
9311
10222
|
}
|
|
9312
10223
|
break;
|
|
9313
10224
|
}
|
|
@@ -9333,7 +10244,18 @@ var MessageStream = class MessageStream {
|
|
|
9333
10244
|
}
|
|
9334
10245
|
return snapshot;
|
|
9335
10246
|
}
|
|
9336
|
-
case "content_block_stop":
|
|
10247
|
+
case "content_block_stop": {
|
|
10248
|
+
const snapshotContent = snapshot.content.at(event.index);
|
|
10249
|
+
if (snapshotContent && tracksToolInput(snapshotContent) && "__json_buf" in snapshotContent) {
|
|
10250
|
+
Object.defineProperty(snapshotContent, "input", {
|
|
10251
|
+
value: snapshotContent.input,
|
|
10252
|
+
enumerable: true,
|
|
10253
|
+
configurable: true,
|
|
10254
|
+
writable: true
|
|
10255
|
+
});
|
|
10256
|
+
}
|
|
10257
|
+
return snapshot;
|
|
10258
|
+
}
|
|
9337
10259
|
}
|
|
9338
10260
|
}, Symbol.asyncIterator)]() {
|
|
9339
10261
|
const pushQueue = [];
|
|
@@ -9411,7 +10333,7 @@ var MessageStream = class MessageStream {
|
|
|
9411
10333
|
function checkNever(x) {}
|
|
9412
10334
|
|
|
9413
10335
|
//#endregion
|
|
9414
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
10336
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
|
|
9415
10337
|
var Batches = class extends APIResource {
|
|
9416
10338
|
/**
|
|
9417
10339
|
* Send a batch of Message creation requests.
|
|
@@ -9421,7 +10343,7 @@ var Batches = class extends APIResource {
|
|
|
9421
10343
|
* can take up to 24 hours to complete.
|
|
9422
10344
|
*
|
|
9423
10345
|
* Learn more about the Message Batches API in our
|
|
9424
|
-
* [user guide](https://
|
|
10346
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
9425
10347
|
*
|
|
9426
10348
|
* @example
|
|
9427
10349
|
* ```ts
|
|
@@ -9441,10 +10363,12 @@ var Batches = class extends APIResource {
|
|
|
9441
10363
|
* });
|
|
9442
10364
|
* ```
|
|
9443
10365
|
*/
|
|
9444
|
-
create(
|
|
10366
|
+
create(params, options) {
|
|
10367
|
+
const { user_profile_id, ...body } = params;
|
|
9445
10368
|
return this._client.post("/v1/messages/batches", {
|
|
9446
10369
|
body,
|
|
9447
|
-
...options
|
|
10370
|
+
...options,
|
|
10371
|
+
headers: buildHeaders([{ ...user_profile_id != null ? { "anthropic-user-profile-id": user_profile_id } : undefined }, options?.headers])
|
|
9448
10372
|
});
|
|
9449
10373
|
}
|
|
9450
10374
|
/**
|
|
@@ -9453,7 +10377,7 @@ var Batches = class extends APIResource {
|
|
|
9453
10377
|
* `results_url` field in the response.
|
|
9454
10378
|
*
|
|
9455
10379
|
* Learn more about the Message Batches API in our
|
|
9456
|
-
* [user guide](https://
|
|
10380
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
9457
10381
|
*
|
|
9458
10382
|
* @example
|
|
9459
10383
|
* ```ts
|
|
@@ -9470,7 +10394,7 @@ var Batches = class extends APIResource {
|
|
|
9470
10394
|
* returned first.
|
|
9471
10395
|
*
|
|
9472
10396
|
* Learn more about the Message Batches API in our
|
|
9473
|
-
* [user guide](https://
|
|
10397
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
9474
10398
|
*
|
|
9475
10399
|
* @example
|
|
9476
10400
|
* ```ts
|
|
@@ -9493,7 +10417,7 @@ var Batches = class extends APIResource {
|
|
|
9493
10417
|
* like to delete an in-progress batch, you must first cancel it.
|
|
9494
10418
|
*
|
|
9495
10419
|
* Learn more about the Message Batches API in our
|
|
9496
|
-
* [user guide](https://
|
|
10420
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
9497
10421
|
*
|
|
9498
10422
|
* @example
|
|
9499
10423
|
* ```ts
|
|
@@ -9516,7 +10440,7 @@ var Batches = class extends APIResource {
|
|
|
9516
10440
|
* non-interruptible.
|
|
9517
10441
|
*
|
|
9518
10442
|
* Learn more about the Message Batches API in our
|
|
9519
|
-
* [user guide](https://
|
|
10443
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
9520
10444
|
*
|
|
9521
10445
|
* @example
|
|
9522
10446
|
* ```ts
|
|
@@ -9536,7 +10460,7 @@ var Batches = class extends APIResource {
|
|
|
9536
10460
|
* requests. Use the `custom_id` field to match results to requests.
|
|
9537
10461
|
*
|
|
9538
10462
|
* Learn more about the Message Batches API in our
|
|
9539
|
-
* [user guide](https://
|
|
10463
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
|
|
9540
10464
|
*
|
|
9541
10465
|
* @example
|
|
9542
10466
|
* ```ts
|
|
@@ -9559,13 +10483,14 @@ var Batches = class extends APIResource {
|
|
|
9559
10483
|
};
|
|
9560
10484
|
|
|
9561
10485
|
//#endregion
|
|
9562
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
10486
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/messages/messages.mjs
|
|
9563
10487
|
var Messages = class extends APIResource {
|
|
9564
10488
|
constructor() {
|
|
9565
10489
|
super(...arguments);
|
|
9566
10490
|
this.batches = new Batches(this._client);
|
|
9567
10491
|
}
|
|
9568
|
-
create(
|
|
10492
|
+
create(params, options) {
|
|
10493
|
+
const { user_profile_id, ...body } = params;
|
|
9569
10494
|
if (body.model in DEPRECATED_MODELS) {
|
|
9570
10495
|
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
9571
10496
|
}
|
|
@@ -9582,8 +10507,12 @@ var Messages = class extends APIResource {
|
|
|
9582
10507
|
body,
|
|
9583
10508
|
timeout: timeout ?? 6e5,
|
|
9584
10509
|
...options,
|
|
9585
|
-
headers: buildHeaders([
|
|
9586
|
-
|
|
10510
|
+
headers: buildHeaders([
|
|
10511
|
+
{ ...user_profile_id != null ? { "anthropic-user-profile-id": user_profile_id } : undefined },
|
|
10512
|
+
helperHeader,
|
|
10513
|
+
options?.headers
|
|
10514
|
+
]),
|
|
10515
|
+
stream: params.stream ?? false
|
|
9587
10516
|
});
|
|
9588
10517
|
}
|
|
9589
10518
|
/**
|
|
@@ -9638,7 +10567,7 @@ var Messages = class extends APIResource {
|
|
|
9638
10567
|
* including tools, images, and documents, without creating it.
|
|
9639
10568
|
*
|
|
9640
10569
|
* Learn more about token counting in our
|
|
9641
|
-
* [user guide](https://
|
|
10570
|
+
* [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
|
|
9642
10571
|
*
|
|
9643
10572
|
* @example
|
|
9644
10573
|
* ```ts
|
|
@@ -9649,10 +10578,12 @@ var Messages = class extends APIResource {
|
|
|
9649
10578
|
* });
|
|
9650
10579
|
* ```
|
|
9651
10580
|
*/
|
|
9652
|
-
countTokens(
|
|
10581
|
+
countTokens(params, options) {
|
|
10582
|
+
const { user_profile_id, ...body } = params;
|
|
9653
10583
|
return this._client.post("/v1/messages/count_tokens", {
|
|
9654
10584
|
body,
|
|
9655
|
-
...options
|
|
10585
|
+
...options,
|
|
10586
|
+
headers: buildHeaders([{ ...user_profile_id != null ? { "anthropic-user-profile-id": user_profile_id } : undefined }, options?.headers])
|
|
9656
10587
|
});
|
|
9657
10588
|
}
|
|
9658
10589
|
};
|
|
@@ -9675,13 +10606,14 @@ const DEPRECATED_MODELS = {
|
|
|
9675
10606
|
"claude-sonnet-4-0": "June 15th, 2026",
|
|
9676
10607
|
"claude-sonnet-4-20250514": "June 15th, 2026",
|
|
9677
10608
|
"claude-opus-4-1": "August 5th, 2026",
|
|
9678
|
-
"claude-opus-4-1-20250805": "August 5th, 2026"
|
|
10609
|
+
"claude-opus-4-1-20250805": "August 5th, 2026",
|
|
10610
|
+
"claude-mythos-preview": "June 30th, 2026"
|
|
9679
10611
|
};
|
|
9680
10612
|
const MODELS_TO_WARN_WITH_THINKING_ENABLED = ["claude-mythos-preview", "claude-opus-4-6"];
|
|
9681
10613
|
Messages.Batches = Batches;
|
|
9682
10614
|
|
|
9683
10615
|
//#endregion
|
|
9684
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
10616
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/resources/models.mjs
|
|
9685
10617
|
var Models = class extends APIResource {
|
|
9686
10618
|
/**
|
|
9687
10619
|
* Get a specific model.
|
|
@@ -9713,7 +10645,7 @@ var Models = class extends APIResource {
|
|
|
9713
10645
|
};
|
|
9714
10646
|
|
|
9715
10647
|
//#endregion
|
|
9716
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
10648
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/client.mjs
|
|
9717
10649
|
var _BaseAnthropic_instances;
|
|
9718
10650
|
var _a;
|
|
9719
10651
|
var _BaseAnthropic_encoder;
|
|
@@ -9779,9 +10711,8 @@ var BaseAnthropic = class {
|
|
|
9779
10711
|
this._baseURLIsExplicit = opts.__baseURLIsExplicit ?? !!baseURL;
|
|
9780
10712
|
this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT;
|
|
9781
10713
|
this.logger = options.logger ?? console;
|
|
9782
|
-
const defaultLogLevel = "warn";
|
|
9783
10714
|
this.logLevel = defaultLogLevel;
|
|
9784
|
-
this.logLevel = parseLogLevel(options.logLevel, "ClientOptions.logLevel", this) ?? parseLogLevel(readEnv("ANTHROPIC_LOG"), "process.env['ANTHROPIC_LOG']", this) ??
|
|
10715
|
+
this.logLevel = parseLogLevel(options.logLevel, "ClientOptions.logLevel", loggerFor(this)) ?? parseLogLevel(readEnv("ANTHROPIC_LOG"), "process.env['ANTHROPIC_LOG']", loggerFor(this)) ?? "warn";
|
|
9785
10716
|
this.fetchOptions = options.fetchOptions;
|
|
9786
10717
|
this.maxRetries = options.maxRetries ?? 2;
|
|
9787
10718
|
this.fetch = options.fetch ?? getDefaultFetch();
|
|
@@ -9885,7 +10816,7 @@ var BaseAnthropic = class {
|
|
|
9885
10816
|
* same reason, `ctx.options` is undefined for these requests.
|
|
9886
10817
|
*/
|
|
9887
10818
|
_credentialsFetch() {
|
|
9888
|
-
return wrapFetchWithMiddleware(this.fetch, this.middleware);
|
|
10819
|
+
return wrapFetchWithMiddleware(this.fetch, this.middleware, undefined, this);
|
|
9889
10820
|
}
|
|
9890
10821
|
_makeTokenCache(provider) {
|
|
9891
10822
|
return new TokenCache(provider, (err) => {
|
|
@@ -10058,12 +10989,12 @@ var BaseAnthropic = class {
|
|
|
10058
10989
|
* This is useful for cases where you want to add certain headers based off of
|
|
10059
10990
|
* the request properties, e.g. `method` or `url`.
|
|
10060
10991
|
*
|
|
10061
|
-
* Runs after
|
|
10062
|
-
*
|
|
10063
|
-
* wire. Middleware may replay a request by calling `next()`
|
|
10064
|
-
* so this hook can run multiple times per attempt:
|
|
10065
|
-
* idempotent and overwrite
|
|
10066
|
-
*
|
|
10992
|
+
* Runs after all middleware (including {@link backendMiddleware}),
|
|
10993
|
+
* immediately before each underlying fetch call, so it sees exactly what
|
|
10994
|
+
* goes over the wire. Middleware may replay a request by calling `next()`
|
|
10995
|
+
* more than once, so this hook can run multiple times per attempt:
|
|
10996
|
+
* overrides must be idempotent and overwrite headers from a previous
|
|
10997
|
+
* invocation rather than append to them.
|
|
10067
10998
|
*/
|
|
10068
10999
|
async prepareRequest(request, { url, options }) {
|
|
10069
11000
|
if (this._authState.tokenCache && this.apiKey == null) {
|
|
@@ -10078,6 +11009,27 @@ var BaseAnthropic = class {
|
|
|
10078
11009
|
request.headers = headers;
|
|
10079
11010
|
}
|
|
10080
11011
|
}
|
|
11012
|
+
/**
|
|
11013
|
+
* Internal {@link Middleware} composed innermost in the chain — inside both
|
|
11014
|
+
* client-level and per-request middleware, immediately around the underlying
|
|
11015
|
+
* `fetch`. Subclasses for third-party backends override this to adapt the
|
|
11016
|
+
* canonical Anthropic-shaped request to the backend's wire shape (URL/body
|
|
11017
|
+
* rewriting, request signing) and to normalize the wire response back to the
|
|
11018
|
+
* canonical shape (e.g. AWS EventStream to SSE).
|
|
11019
|
+
*
|
|
11020
|
+
* Running inside the user's middleware means user middleware always observes
|
|
11021
|
+
* canonical Anthropic-shaped traffic, and the adaptation re-runs (e.g.
|
|
11022
|
+
* re-signs) on every `next()` invocation, covering whatever the middleware
|
|
11023
|
+
* mutated.
|
|
11024
|
+
*
|
|
11025
|
+
* Errors thrown here follow the middleware error policy: they propagate to
|
|
11026
|
+
* the caller as-is — no retries, no `APIConnectionError` wrapping — unless
|
|
11027
|
+
* retryable (see {@link Middleware}); throw a `RetryableError` to opt into
|
|
11028
|
+
* the retry path.
|
|
11029
|
+
*/
|
|
11030
|
+
backendMiddleware() {
|
|
11031
|
+
return [];
|
|
11032
|
+
}
|
|
10081
11033
|
get(path, opts) {
|
|
10082
11034
|
return this.methodRequest("get", path, opts);
|
|
10083
11035
|
}
|
|
@@ -10133,7 +11085,7 @@ var BaseAnthropic = class {
|
|
|
10133
11085
|
throw new APIUserAbortError();
|
|
10134
11086
|
}
|
|
10135
11087
|
const isTimeout = isAbortError(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
10136
|
-
const hasMiddleware = this.middleware.length > 0 || !!options.middleware?.length;
|
|
11088
|
+
const hasMiddleware = this.middleware.length > 0 || !!options.middleware?.length || this.backendMiddleware().length > 0;
|
|
10137
11089
|
if (hasMiddleware && !isTimeout && !isRetryableError(response)) {
|
|
10138
11090
|
loggerFor(this).info(`[${requestLogID}] middleware error (not retryable)`);
|
|
10139
11091
|
loggerFor(this).debug(`[${requestLogID}] middleware error (not retryable)`, formatRequestDetails({
|
|
@@ -10275,9 +11227,14 @@ var BaseAnthropic = class {
|
|
|
10275
11227
|
}
|
|
10276
11228
|
return timedFetch(innerUrl, innerInit);
|
|
10277
11229
|
});
|
|
10278
|
-
const
|
|
10279
|
-
const
|
|
10280
|
-
|
|
11230
|
+
const requestMiddleware = requestOptions?.middleware;
|
|
11231
|
+
const backendMiddleware = this.backendMiddleware();
|
|
11232
|
+
const allMiddleware = requestMiddleware?.length || backendMiddleware.length ? [
|
|
11233
|
+
...this.middleware,
|
|
11234
|
+
...requestMiddleware ?? [],
|
|
11235
|
+
...backendMiddleware
|
|
11236
|
+
] : this.middleware;
|
|
11237
|
+
return await wrapFetchWithMiddleware(innerFetch, allMiddleware, requestOptions, this)(url, fetchOptions);
|
|
10281
11238
|
}
|
|
10282
11239
|
async shouldRetry(response, options) {
|
|
10283
11240
|
const flags = this._authFlags(options);
|
|
@@ -10469,7 +11426,635 @@ Anthropic.Models = Models;
|
|
|
10469
11426
|
Anthropic.Beta = Beta;
|
|
10470
11427
|
|
|
10471
11428
|
//#endregion
|
|
10472
|
-
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.
|
|
11429
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/lib/middleware.mjs
|
|
11430
|
+
const encoder = new TextEncoder();
|
|
11431
|
+
/** Betas sent by default; override with {@link BetaRefusalFallbackOptions.betas}. */
|
|
11432
|
+
const DEFAULT_BETAS = ["fallback-credit-2026-06-01"];
|
|
11433
|
+
/**
|
|
11434
|
+
* Remove `fallback` blocks replayed in history. They only parse under the
|
|
11435
|
+
* server-side fallback beta, which belongs to the caller-owned server-side
|
|
11436
|
+
* `fallbacks` feature — this middleware never sends it, so a request
|
|
11437
|
+
* replaying them would 400. An assistant turn left empty is dropped whole.
|
|
11438
|
+
*/
|
|
11439
|
+
function stripFallbackBlocks(body) {
|
|
11440
|
+
const messages = body.messages.map((message) => Array.isArray(message.content) ? {
|
|
11441
|
+
...message,
|
|
11442
|
+
content: message.content.filter((block) => block.type !== "fallback")
|
|
11443
|
+
} : message).filter((message) => !Array.isArray(message.content) || message.content.length > 0);
|
|
11444
|
+
return {
|
|
11445
|
+
...body,
|
|
11446
|
+
messages
|
|
11447
|
+
};
|
|
11448
|
+
}
|
|
11449
|
+
/**
|
|
11450
|
+
* Middleware that retries refused `/v1/messages` requests down a fallback chain.
|
|
11451
|
+
*
|
|
11452
|
+
* Non-streaming: when a response comes back with `stop_reason: 'refusal'`, the
|
|
11453
|
+
* request is retried with each entry of `fallbacks` merged over the original
|
|
11454
|
+
* params — passing along the refusal's `fallback_credit_token` — until a model
|
|
11455
|
+
* accepts or the chain is exhausted. A message served by a fallback carries a
|
|
11456
|
+
* `fallback` content block prepended at each model boundary — the same seam
|
|
11457
|
+
* block shape the server-side `fallbacks` param places in `content`, though
|
|
11458
|
+
* the rest of the envelope is the serving hop's as returned (see the
|
|
11459
|
+
* known-divergences note below); an exhausted chain surfaces the final
|
|
11460
|
+
* refusal verbatim.
|
|
11461
|
+
*
|
|
11462
|
+
* Streaming: when the stream ends in `stop_reason: 'refusal'`, a second
|
|
11463
|
+
* request is issued to the fallback model — carrying the refused model's
|
|
11464
|
+
* partial output as a trailing assistant prefill when the refusal grants one
|
|
11465
|
+
* (`fallback_has_prefill_claim`), plus the refusal's `fallback_credit_token`
|
|
11466
|
+
* — and the fallback's events are spliced onto the
|
|
11467
|
+
* still-open stream, so the client sees one continuous message in the
|
|
11468
|
+
* server-side `fallbacks` wire shape: a `fallback` content block at each model
|
|
11469
|
+
* boundary, monotonic block indices, and per-hop `usage.iterations` on the
|
|
11470
|
+
* final `message_delta`. Only `model` is honored from each entry on this path:
|
|
11471
|
+
* the credit token is redeemable only against the refused request's body, so
|
|
11472
|
+
* the other per-entry overrides (`max_tokens`, `thinking`, ...) would be
|
|
11473
|
+
* rejected.
|
|
11474
|
+
*
|
|
11475
|
+
* The fallback-credit beta the credit tokens require is sent by default on
|
|
11476
|
+
* every request the middleware handles; the `betas` option controls this.
|
|
11477
|
+
*
|
|
11478
|
+
* In both modes a fallback that itself refuses with a fresh credit token
|
|
11479
|
+
* continues down the chain. A streaming fallback whose prefill the server
|
|
11480
|
+
* rejects (HTTP 400) is retried once without it; a fallback whose request
|
|
11481
|
+
* fails outright is skipped — its token was never redeemed, so it carries to
|
|
11482
|
+
* the next entry.
|
|
11483
|
+
*
|
|
11484
|
+
* To keep later requests on the model that accepted, pass a
|
|
11485
|
+
* {@link BetaFallbackState} via the `fallbackState` request option; requests
|
|
11486
|
+
* sharing that state start directly at the pinned fallback. Reuse one state
|
|
11487
|
+
* across whatever scope the pin should apply to — typically a conversation.
|
|
11488
|
+
*
|
|
11489
|
+
* @example
|
|
11490
|
+
* ```ts
|
|
11491
|
+
* const client = new Anthropic({
|
|
11492
|
+
* middleware: [betaRefusalFallbackMiddleware([{ model: 'claude-opus-4-8' }])],
|
|
11493
|
+
* });
|
|
11494
|
+
*
|
|
11495
|
+
* const fallbackState = new BetaFallbackState();
|
|
11496
|
+
* const message = await client.beta.messages.create(params, { fallbackState });
|
|
11497
|
+
* ```
|
|
11498
|
+
*/
|
|
11499
|
+
function betaRefusalFallbackMiddleware(fallbacks, options = {}) {
|
|
11500
|
+
let warnedMissingState = false;
|
|
11501
|
+
return async (request, next, ctx) => {
|
|
11502
|
+
const [path, query] = (ctx.options?.path ?? "").split("?");
|
|
11503
|
+
if (fallbacks.length === 0 || ctx.options?.method !== "post" || path !== "/v1/messages" || new URLSearchParams(query).get("beta") !== "true" || typeof ctx.options.body !== "object" || ctx.options.body == null) {
|
|
11504
|
+
return next(request);
|
|
11505
|
+
}
|
|
11506
|
+
if (ctx.options.body.fallbacks != null) {
|
|
11507
|
+
throw new AnthropicError("Sending the `fallbacks:` request param is not supported when using the `betaRefusalFallbackMiddleware`. " + "You should either remove the middleware and send `fallbacks:` with the `server-side-fallback-2026-06-01` beta header to let the API handle refusal fallbacks, " + "or omit the `fallbacks:` param if you'd like `betaRefusalFallbackMiddleware` to handle fallbacks on the client side.");
|
|
11508
|
+
}
|
|
11509
|
+
const onError = options.onError ?? ((error) => ctx.logger.error(`anthropic-sdk: betaRefusalFallbackMiddleware: ${error.message}`));
|
|
11510
|
+
request = withMiddlewareHeaders(request, options.betas ?? DEFAULT_BETAS);
|
|
11511
|
+
const body = stripFallbackBlocks(ctx.options.body);
|
|
11512
|
+
const state = ctx.options.fallbackState;
|
|
11513
|
+
const startIndex = state?.index ?? -1;
|
|
11514
|
+
if (!Number.isInteger(startIndex) || startIndex < -1 || startIndex >= fallbacks.length) {
|
|
11515
|
+
throw new AnthropicError(`fallbackState.index ${startIndex} is out of bounds for a chain of ${fallbacks.length} fallback(s); was the state shared with a different middleware?`);
|
|
11516
|
+
}
|
|
11517
|
+
const pin = (index) => {
|
|
11518
|
+
if (state) {
|
|
11519
|
+
state.index = index;
|
|
11520
|
+
} else if (!warnedMissingState) {
|
|
11521
|
+
warnedMissingState = true;
|
|
11522
|
+
ctx.logger.warn("anthropic-sdk: betaRefusalFallbackMiddleware fell back without a `fallbackState` request option; follow-up requests will retry models that already refused. Pass a shared `{ fallbackState: new BetaFallbackState() }` to pin them to the accepted model.");
|
|
11523
|
+
}
|
|
11524
|
+
};
|
|
11525
|
+
const initialRequest = typeof request.body !== "string" ? request : {
|
|
11526
|
+
...request,
|
|
11527
|
+
body: JSON.stringify(startIndex === -1 ? body : {
|
|
11528
|
+
...body,
|
|
11529
|
+
...fallbacks[startIndex]
|
|
11530
|
+
})
|
|
11531
|
+
};
|
|
11532
|
+
const response = await next(initialRequest);
|
|
11533
|
+
if (!response.ok) {
|
|
11534
|
+
return response;
|
|
11535
|
+
}
|
|
11536
|
+
if (ctx.options.stream === true) {
|
|
11537
|
+
const firstHop = startIndex + 1;
|
|
11538
|
+
if (firstHop >= fallbacks.length || typeof initialRequest.body !== "string") {
|
|
11539
|
+
return response;
|
|
11540
|
+
}
|
|
11541
|
+
return spliceFallbackStream({
|
|
11542
|
+
request: initialRequest,
|
|
11543
|
+
response,
|
|
11544
|
+
next,
|
|
11545
|
+
ctx,
|
|
11546
|
+
fallbacks,
|
|
11547
|
+
firstHop,
|
|
11548
|
+
onError,
|
|
11549
|
+
pin
|
|
11550
|
+
});
|
|
11551
|
+
}
|
|
11552
|
+
let index = startIndex;
|
|
11553
|
+
let res = response;
|
|
11554
|
+
let requestedModel = (startIndex === -1 ? body : {
|
|
11555
|
+
...body,
|
|
11556
|
+
...fallbacks[startIndex]
|
|
11557
|
+
}).model;
|
|
11558
|
+
const fallbackBlocks = [];
|
|
11559
|
+
while (index < fallbacks.length - 1) {
|
|
11560
|
+
const message = await ctx.parse(res);
|
|
11561
|
+
if (message?.type !== "message" || message.stop_reason !== "refusal") {
|
|
11562
|
+
break;
|
|
11563
|
+
}
|
|
11564
|
+
index += 1;
|
|
11565
|
+
pin(index);
|
|
11566
|
+
const entry = fallbacks[index];
|
|
11567
|
+
fallbackBlocks.push({
|
|
11568
|
+
type: "fallback",
|
|
11569
|
+
from: { model: requestedModel ?? message.model },
|
|
11570
|
+
to: { model: entry.model },
|
|
11571
|
+
trigger: {
|
|
11572
|
+
type: "refusal",
|
|
11573
|
+
category: message.stop_details?.category ?? null
|
|
11574
|
+
}
|
|
11575
|
+
});
|
|
11576
|
+
requestedModel = entry.model;
|
|
11577
|
+
res = await next({
|
|
11578
|
+
...request,
|
|
11579
|
+
body: JSON.stringify({
|
|
11580
|
+
...body,
|
|
11581
|
+
...entry,
|
|
11582
|
+
...message.stop_details?.fallback_credit_token ? { fallback_credit_token: message.stop_details.fallback_credit_token } : undefined
|
|
11583
|
+
})
|
|
11584
|
+
});
|
|
11585
|
+
}
|
|
11586
|
+
if (fallbackBlocks.length === 0) {
|
|
11587
|
+
return res;
|
|
11588
|
+
}
|
|
11589
|
+
const served = await ctx.parse(res);
|
|
11590
|
+
if (served?.type !== "message" || served.stop_reason === "refusal" || !Array.isArray(served.content)) {
|
|
11591
|
+
return res;
|
|
11592
|
+
}
|
|
11593
|
+
const headers = new Headers(res.headers);
|
|
11594
|
+
headers.delete("content-length");
|
|
11595
|
+
return new Response(JSON.stringify({
|
|
11596
|
+
...served,
|
|
11597
|
+
content: [...fallbackBlocks, ...served.content]
|
|
11598
|
+
}), {
|
|
11599
|
+
status: res.status,
|
|
11600
|
+
statusText: res.statusText,
|
|
11601
|
+
headers
|
|
11602
|
+
});
|
|
11603
|
+
};
|
|
11604
|
+
}
|
|
11605
|
+
/**
|
|
11606
|
+
* Wrap stream A in a response whose body passes events through until a
|
|
11607
|
+
* retryable refusal, then splices the fallback chain's events on (see
|
|
11608
|
+
* {@link splicedEvents}). Cancelling the returned body tears down whichever
|
|
11609
|
+
* stream is being read and aborts any in-flight fallback request or retry
|
|
11610
|
+
* backoff: hop requests run under `controller`'s signal, which fires on
|
|
11611
|
+
* cancel and mirrors the original request's signal — a user abort has no
|
|
11612
|
+
* other way to reach a hop, since this synthetic body isn't fetch-backed.
|
|
11613
|
+
*/
|
|
11614
|
+
function spliceFallbackStream(args) {
|
|
11615
|
+
const controller = new AbortController();
|
|
11616
|
+
const signal = args.request.signal;
|
|
11617
|
+
if (signal?.aborted) {
|
|
11618
|
+
controller.abort(signal.reason);
|
|
11619
|
+
} else {
|
|
11620
|
+
signal?.addEventListener("abort", makeAbort(controller, signal), { once: true });
|
|
11621
|
+
}
|
|
11622
|
+
const iter = splicedEvents(args, controller);
|
|
11623
|
+
const body = new ReadableStream({
|
|
11624
|
+
async pull(ctrl) {
|
|
11625
|
+
try {
|
|
11626
|
+
const { value, done } = await iter.next();
|
|
11627
|
+
if (done) return ctrl.close();
|
|
11628
|
+
ctrl.enqueue(value);
|
|
11629
|
+
} catch (err) {
|
|
11630
|
+
ctrl.error(err);
|
|
11631
|
+
}
|
|
11632
|
+
},
|
|
11633
|
+
async cancel() {
|
|
11634
|
+
controller.abort();
|
|
11635
|
+
await iter.return?.(undefined);
|
|
11636
|
+
}
|
|
11637
|
+
});
|
|
11638
|
+
return new Response(body, args.response);
|
|
11639
|
+
}
|
|
11640
|
+
async function* splicedEvents({ request, response, next, ctx, fallbacks, firstHop, onError, pin }, controller) {
|
|
11641
|
+
const a = yield* consumeHop({
|
|
11642
|
+
response,
|
|
11643
|
+
controller,
|
|
11644
|
+
indexBase: 0,
|
|
11645
|
+
hasNext: true,
|
|
11646
|
+
onError,
|
|
11647
|
+
splice: null
|
|
11648
|
+
});
|
|
11649
|
+
if (!a.refused) return;
|
|
11650
|
+
let nextIndex = a.nextIndex;
|
|
11651
|
+
let token = a.refused.token;
|
|
11652
|
+
let base = [];
|
|
11653
|
+
let partial = a.refused.hasPrefillClaim ? toPrefillBlocks(a.blocks) : [];
|
|
11654
|
+
let fromModel = a.model ?? "";
|
|
11655
|
+
let lastUsage = a.refused.usage;
|
|
11656
|
+
let refusalDetails = a.refused.stopDetails;
|
|
11657
|
+
const iterations = [toIterationUsage("message", a.model ?? "", a.refused.usage)];
|
|
11658
|
+
for (let hop = firstHop; hop < fallbacks.length; hop++) {
|
|
11659
|
+
const model = fallbacks[hop].model;
|
|
11660
|
+
const hasNext = hop + 1 < fallbacks.length;
|
|
11661
|
+
pin(hop);
|
|
11662
|
+
const fbIndex = nextIndex++;
|
|
11663
|
+
yield emit("content_block_start", {
|
|
11664
|
+
type: "content_block_start",
|
|
11665
|
+
index: fbIndex,
|
|
11666
|
+
content_block: {
|
|
11667
|
+
type: "fallback",
|
|
11668
|
+
from: { model: fromModel },
|
|
11669
|
+
to: { model },
|
|
11670
|
+
trigger: {
|
|
11671
|
+
type: "refusal",
|
|
11672
|
+
category: refusalDetails?.category ?? null
|
|
11673
|
+
}
|
|
11674
|
+
}
|
|
11675
|
+
});
|
|
11676
|
+
yield emit("content_block_stop", {
|
|
11677
|
+
type: "content_block_stop",
|
|
11678
|
+
index: fbIndex
|
|
11679
|
+
});
|
|
11680
|
+
let continuation = [...base, ...partial];
|
|
11681
|
+
let resB = null;
|
|
11682
|
+
let failure = null;
|
|
11683
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
11684
|
+
const reqB = buildFallbackRequest(request, {
|
|
11685
|
+
model,
|
|
11686
|
+
creditToken: token,
|
|
11687
|
+
continuation
|
|
11688
|
+
});
|
|
11689
|
+
reqB.signal = controller.signal;
|
|
11690
|
+
try {
|
|
11691
|
+
resB = await next(reqB);
|
|
11692
|
+
} catch (err) {
|
|
11693
|
+
if (isAbortError(err)) throw err;
|
|
11694
|
+
failure = {
|
|
11695
|
+
kind: "request_failed",
|
|
11696
|
+
message: `fallback request failed: ${err}`,
|
|
11697
|
+
model,
|
|
11698
|
+
status: null,
|
|
11699
|
+
detail: err
|
|
11700
|
+
};
|
|
11701
|
+
break;
|
|
11702
|
+
}
|
|
11703
|
+
if (resB.ok) break;
|
|
11704
|
+
const errBody = await ctx.parse(resB).catch(() => null);
|
|
11705
|
+
if (attempt === 0 && resB.status === 400 && partial.length) {
|
|
11706
|
+
ctx.logger.warn(`anthropic-sdk: betaRefusalFallbackMiddleware: fallback request with the partial output appended was rejected (HTTP 400: ${JSON.stringify(errBody)}); retrying without it`);
|
|
11707
|
+
continuation = base;
|
|
11708
|
+
resB = null;
|
|
11709
|
+
continue;
|
|
11710
|
+
}
|
|
11711
|
+
failure = {
|
|
11712
|
+
kind: "request_failed",
|
|
11713
|
+
message: `fallback request failed: HTTP ${resB.status}: ${JSON.stringify(errBody)}`,
|
|
11714
|
+
model,
|
|
11715
|
+
status: resB.status,
|
|
11716
|
+
detail: errBody
|
|
11717
|
+
};
|
|
11718
|
+
break;
|
|
11719
|
+
}
|
|
11720
|
+
if (failure) {
|
|
11721
|
+
onError(failure);
|
|
11722
|
+
if (hasNext) continue;
|
|
11723
|
+
const stopDetails = {
|
|
11724
|
+
...refusalDetails,
|
|
11725
|
+
recommended_model: model
|
|
11726
|
+
};
|
|
11727
|
+
yield emit("message_delta", {
|
|
11728
|
+
type: "message_delta",
|
|
11729
|
+
context_management: null,
|
|
11730
|
+
delta: {
|
|
11731
|
+
stop_reason: "refusal",
|
|
11732
|
+
stop_sequence: null,
|
|
11733
|
+
container: null,
|
|
11734
|
+
stop_details: stopDetails
|
|
11735
|
+
},
|
|
11736
|
+
usage: lastUsage ?? {}
|
|
11737
|
+
});
|
|
11738
|
+
yield emit("message_stop", { type: "message_stop" });
|
|
11739
|
+
return;
|
|
11740
|
+
}
|
|
11741
|
+
const b = yield* consumeHop({
|
|
11742
|
+
response: resB,
|
|
11743
|
+
controller,
|
|
11744
|
+
indexBase: nextIndex,
|
|
11745
|
+
hasNext,
|
|
11746
|
+
onError,
|
|
11747
|
+
splice: {
|
|
11748
|
+
iterations,
|
|
11749
|
+
model
|
|
11750
|
+
}
|
|
11751
|
+
});
|
|
11752
|
+
if (!b.refused) return;
|
|
11753
|
+
token = b.refused.token;
|
|
11754
|
+
refusalDetails = b.refused.stopDetails;
|
|
11755
|
+
base = continuation;
|
|
11756
|
+
partial = b.refused.hasPrefillClaim ? toPrefillBlocks(b.blocks) : [];
|
|
11757
|
+
iterations.push(toIterationUsage("message", model, b.refused.usage));
|
|
11758
|
+
lastUsage = b.refused.usage;
|
|
11759
|
+
fromModel = model;
|
|
11760
|
+
nextIndex = b.nextIndex;
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11763
|
+
/**
|
|
11764
|
+
* Consume one hop's SSE events, forwarding them to the client while
|
|
11765
|
+
* accumulating its content blocks (returned in the outcome).
|
|
11766
|
+
*
|
|
11767
|
+
* Stream A (`splice: null`) is forwarded in its original wire bytes; a
|
|
11768
|
+
* spliced hop (`splice` set) has its message_start suppressed (the client
|
|
11769
|
+
* already saw A's), its block indices shifted by `indexBase`, and its
|
|
11770
|
+
* terminal message_delta's usage rewritten to the `usage.iterations`
|
|
11771
|
+
* chain shape.
|
|
11772
|
+
*
|
|
11773
|
+
* A refusal that can be chained — it carries a `fallback_credit_token` and a
|
|
11774
|
+
* fallback entry remains — ends the hop early: open blocks are closed, the
|
|
11775
|
+
* terminal message_delta + message_stop are suppressed, and the token+usage
|
|
11776
|
+
* are returned so the caller can issue the next hop. Any other refusal is
|
|
11777
|
+
* reported through `onError` and passes through to the client.
|
|
11778
|
+
*/
|
|
11779
|
+
async function* consumeHop(args) {
|
|
11780
|
+
const { response, controller, indexBase, hasNext, onError, splice } = args;
|
|
11781
|
+
const tracker = new BlockTracker(indexBase);
|
|
11782
|
+
let model;
|
|
11783
|
+
let startUsage = null;
|
|
11784
|
+
for await (const sse of Stream.rawEvents(response, controller)) {
|
|
11785
|
+
const p = safeJSON(sse.data);
|
|
11786
|
+
switch (p?.type) {
|
|
11787
|
+
case "message_start": {
|
|
11788
|
+
model = p.message.model;
|
|
11789
|
+
startUsage = p.message.usage;
|
|
11790
|
+
if (splice) continue;
|
|
11791
|
+
break;
|
|
11792
|
+
}
|
|
11793
|
+
case "content_block_start": {
|
|
11794
|
+
tracker.start(p);
|
|
11795
|
+
if (splice) {
|
|
11796
|
+
yield emit(p.type, p);
|
|
11797
|
+
continue;
|
|
11798
|
+
}
|
|
11799
|
+
break;
|
|
11800
|
+
}
|
|
11801
|
+
case "content_block_delta": {
|
|
11802
|
+
tracker.delta(p);
|
|
11803
|
+
if (splice) {
|
|
11804
|
+
yield emit(p.type, p);
|
|
11805
|
+
continue;
|
|
11806
|
+
}
|
|
11807
|
+
break;
|
|
11808
|
+
}
|
|
11809
|
+
case "content_block_stop": {
|
|
11810
|
+
tracker.stop(p);
|
|
11811
|
+
if (splice) {
|
|
11812
|
+
yield emit(p.type, p);
|
|
11813
|
+
continue;
|
|
11814
|
+
}
|
|
11815
|
+
break;
|
|
11816
|
+
}
|
|
11817
|
+
case "message_delta": {
|
|
11818
|
+
if (p.delta.stop_reason === "refusal") {
|
|
11819
|
+
const details = p.delta.stop_details?.type === "refusal" ? p.delta.stop_details : null;
|
|
11820
|
+
if (details?.fallback_credit_token && hasNext) {
|
|
11821
|
+
const usage = backfill(p.usage, startUsage);
|
|
11822
|
+
yield* tracker.closeOpenBlocks();
|
|
11823
|
+
return {
|
|
11824
|
+
refused: {
|
|
11825
|
+
token: details.fallback_credit_token,
|
|
11826
|
+
hasPrefillClaim: details.fallback_has_prefill_claim === true,
|
|
11827
|
+
usage,
|
|
11828
|
+
stopDetails: details
|
|
11829
|
+
},
|
|
11830
|
+
model,
|
|
11831
|
+
blocks: tracker.contentBlocks(),
|
|
11832
|
+
nextIndex: tracker.nextIndex
|
|
11833
|
+
};
|
|
11834
|
+
}
|
|
11835
|
+
if (!details?.fallback_credit_token) {
|
|
11836
|
+
onError({
|
|
11837
|
+
kind: "no_credit_token",
|
|
11838
|
+
message: "refusal stop_details has no fallback_credit_token",
|
|
11839
|
+
event: p
|
|
11840
|
+
});
|
|
11841
|
+
} else {
|
|
11842
|
+
onError({
|
|
11843
|
+
kind: "chain_exhausted",
|
|
11844
|
+
message: "refusal but no fallback entries remain",
|
|
11845
|
+
event: p
|
|
11846
|
+
});
|
|
11847
|
+
}
|
|
11848
|
+
}
|
|
11849
|
+
if (splice) {
|
|
11850
|
+
const usage = backfill(p.usage, startUsage);
|
|
11851
|
+
usage.iterations = [...splice.iterations, toIterationUsage("fallback_message", splice.model, usage)];
|
|
11852
|
+
p.usage = usage;
|
|
11853
|
+
yield emit("message_delta", p);
|
|
11854
|
+
continue;
|
|
11855
|
+
}
|
|
11856
|
+
break;
|
|
11857
|
+
}
|
|
11858
|
+
}
|
|
11859
|
+
yield passthroughSSE(sse);
|
|
11860
|
+
}
|
|
11861
|
+
return {
|
|
11862
|
+
refused: null,
|
|
11863
|
+
model,
|
|
11864
|
+
blocks: tracker.contentBlocks(),
|
|
11865
|
+
nextIndex: tracker.nextIndex
|
|
11866
|
+
};
|
|
11867
|
+
}
|
|
11868
|
+
/**
|
|
11869
|
+
* Block bookkeeping for one stream of the splice: accumulates each content
|
|
11870
|
+
* block from its deltas (for the continuation prefill), shifts wire indices
|
|
11871
|
+
* by `indexBase` so they stay monotonic across hops, and tracks which blocks
|
|
11872
|
+
* are still open so a refusal that cuts mid-block can close them.
|
|
11873
|
+
*/
|
|
11874
|
+
var BlockTracker = class {
|
|
11875
|
+
constructor(indexBase = 0) {
|
|
11876
|
+
this.indexBase = indexBase;
|
|
11877
|
+
/** The stream's accumulated blocks keyed by their original wire index. */
|
|
11878
|
+
this.blocks = [];
|
|
11879
|
+
/** Shifted indices of blocks started but not yet stopped. */
|
|
11880
|
+
this.open = [];
|
|
11881
|
+
this.nextIndex = indexBase;
|
|
11882
|
+
}
|
|
11883
|
+
/** The accumulated content blocks, in start order. */
|
|
11884
|
+
contentBlocks() {
|
|
11885
|
+
return this.blocks.map((b) => b.block);
|
|
11886
|
+
}
|
|
11887
|
+
/** Track a content_block_start, shifting `event.index`. */
|
|
11888
|
+
start(event) {
|
|
11889
|
+
this.blocks.push({
|
|
11890
|
+
index: event.index,
|
|
11891
|
+
block: { ...event.content_block }
|
|
11892
|
+
});
|
|
11893
|
+
event.index += this.indexBase;
|
|
11894
|
+
this.open.push(event.index);
|
|
11895
|
+
this.nextIndex = Math.max(this.nextIndex, event.index + 1);
|
|
11896
|
+
}
|
|
11897
|
+
/** Apply a content_block_delta to its accumulating block, shifting `event.index`. */
|
|
11898
|
+
delta(event) {
|
|
11899
|
+
applyDelta(this.blocks, event.index, event.delta);
|
|
11900
|
+
event.index += this.indexBase;
|
|
11901
|
+
}
|
|
11902
|
+
/** Track a content_block_stop, shifting `event.index`. */
|
|
11903
|
+
stop(event) {
|
|
11904
|
+
event.index += this.indexBase;
|
|
11905
|
+
const i = this.open.indexOf(event.index);
|
|
11906
|
+
if (i !== -1) this.open.splice(i, 1);
|
|
11907
|
+
this.nextIndex = Math.max(this.nextIndex, event.index + 1);
|
|
11908
|
+
}
|
|
11909
|
+
/** content_block_stop events for any blocks still open. */
|
|
11910
|
+
*closeOpenBlocks() {
|
|
11911
|
+
for (const index of this.open) {
|
|
11912
|
+
yield emit("content_block_stop", {
|
|
11913
|
+
type: "content_block_stop",
|
|
11914
|
+
index
|
|
11915
|
+
});
|
|
11916
|
+
}
|
|
11917
|
+
this.open.length = 0;
|
|
11918
|
+
}
|
|
11919
|
+
};
|
|
11920
|
+
function buildFallbackRequest(orig, { model, creditToken, continuation }) {
|
|
11921
|
+
const body = JSON.parse(orig.body);
|
|
11922
|
+
body.model = model;
|
|
11923
|
+
body.fallback_credit_token = creditToken;
|
|
11924
|
+
if (continuation.length) {
|
|
11925
|
+
body.messages = [...body.messages, {
|
|
11926
|
+
role: "assistant",
|
|
11927
|
+
content: continuation
|
|
11928
|
+
}];
|
|
11929
|
+
}
|
|
11930
|
+
return {
|
|
11931
|
+
...orig,
|
|
11932
|
+
headers: new Headers(orig.headers),
|
|
11933
|
+
body: JSON.stringify(body)
|
|
11934
|
+
};
|
|
11935
|
+
}
|
|
11936
|
+
/** Apply a content_block_delta to the accumulating block at `index`. */
|
|
11937
|
+
function applyDelta(blocks, index, delta) {
|
|
11938
|
+
const block = blocks.find((x) => x.index === index)?.block;
|
|
11939
|
+
if (!block) return;
|
|
11940
|
+
switch (delta.type) {
|
|
11941
|
+
case "text_delta": {
|
|
11942
|
+
block.text = (block.text ?? "") + delta.text;
|
|
11943
|
+
break;
|
|
11944
|
+
}
|
|
11945
|
+
case "input_json_delta": {
|
|
11946
|
+
block._partial_json = (block._partial_json ?? "") + delta.partial_json;
|
|
11947
|
+
break;
|
|
11948
|
+
}
|
|
11949
|
+
case "citations_delta":
|
|
11950
|
+
(block.citations ?? (block.citations = [])).push(delta.citation);
|
|
11951
|
+
break;
|
|
11952
|
+
case "thinking_delta": {
|
|
11953
|
+
block.thinking = (block.thinking ?? "") + delta.thinking;
|
|
11954
|
+
break;
|
|
11955
|
+
}
|
|
11956
|
+
case "signature_delta": {
|
|
11957
|
+
block.signature = delta.signature;
|
|
11958
|
+
break;
|
|
11959
|
+
}
|
|
11960
|
+
case "compaction_delta": {
|
|
11961
|
+
break;
|
|
11962
|
+
}
|
|
11963
|
+
default: ((_) => {})(delta);
|
|
11964
|
+
}
|
|
11965
|
+
}
|
|
11966
|
+
/**
|
|
11967
|
+
* Convert a hop's accumulated response blocks to the appended assistant turn,
|
|
11968
|
+
* as-is: a `fallback_has_prefill_claim` refusal guarantees the partial output
|
|
11969
|
+
* is resendable verbatim, so no client-side filtering is applied. The only
|
|
11970
|
+
* rewrite is reassembling tool inputs from their accumulated
|
|
11971
|
+
* `input_json_delta` JSON (content_block_start carries `input: {}`).
|
|
11972
|
+
*/
|
|
11973
|
+
function toPrefillBlocks(responseBlocks) {
|
|
11974
|
+
return responseBlocks.map((b) => {
|
|
11975
|
+
if (typeof b?._partial_json !== "string") return b;
|
|
11976
|
+
const { _partial_json, ...block } = b;
|
|
11977
|
+
return {
|
|
11978
|
+
...block,
|
|
11979
|
+
input: safeJSON(_partial_json) ?? block.input
|
|
11980
|
+
};
|
|
11981
|
+
});
|
|
11982
|
+
}
|
|
11983
|
+
/**
|
|
11984
|
+
* A copy of `request` with `betas` appended to its `anthropic-beta` header,
|
|
11985
|
+
* skipping values already present (set by the caller or another middleware).
|
|
11986
|
+
*/
|
|
11987
|
+
function withMiddlewareHeaders(request, betas) {
|
|
11988
|
+
const headers = new Headers(request.headers);
|
|
11989
|
+
const existing = new Set(headers.get("anthropic-beta")?.split(",").map((s) => s.trim()));
|
|
11990
|
+
for (const beta of betas) {
|
|
11991
|
+
if (!existing.has(beta)) {
|
|
11992
|
+
headers.append("anthropic-beta", beta);
|
|
11993
|
+
existing.add(beta);
|
|
11994
|
+
}
|
|
11995
|
+
}
|
|
11996
|
+
headers.set(STAINLESS_HELPER_HEADER, appendHeaderValue(headers.get(STAINLESS_HELPER_HEADER), "fallback-refusal-middleware"));
|
|
11997
|
+
return {
|
|
11998
|
+
...request,
|
|
11999
|
+
headers
|
|
12000
|
+
};
|
|
12001
|
+
}
|
|
12002
|
+
function emit(event, payload) {
|
|
12003
|
+
const sse = {
|
|
12004
|
+
event,
|
|
12005
|
+
data: JSON.stringify(payload),
|
|
12006
|
+
raw: []
|
|
12007
|
+
};
|
|
12008
|
+
return encoder.encode(serializeSSE(sse));
|
|
12009
|
+
}
|
|
12010
|
+
/**
|
|
12011
|
+
* Forward a decoded event in its original wire bytes, preserving SSE fields
|
|
12012
|
+
* the decoder doesn't model (`id:`, `retry:`, comment lines). Falls back to
|
|
12013
|
+
* re-serializing for events with no raw lines.
|
|
12014
|
+
*/
|
|
12015
|
+
function passthroughSSE(sse) {
|
|
12016
|
+
return encoder.encode(sse.raw.length ? sse.raw.join("\n") + "\n\n" : serializeSSE(sse));
|
|
12017
|
+
}
|
|
12018
|
+
function toIterationUsage(type, model, u) {
|
|
12019
|
+
return {
|
|
12020
|
+
type,
|
|
12021
|
+
model,
|
|
12022
|
+
input_tokens: u?.input_tokens ?? 0,
|
|
12023
|
+
output_tokens: u?.output_tokens ?? 0,
|
|
12024
|
+
cache_read_input_tokens: u?.cache_read_input_tokens ?? 0,
|
|
12025
|
+
cache_creation_input_tokens: u?.cache_creation_input_tokens ?? 0,
|
|
12026
|
+
cache_creation: u?.cache_creation ?? null
|
|
12027
|
+
};
|
|
12028
|
+
}
|
|
12029
|
+
/** Fill null/undefined fields on `primary` from `fallback`. */
|
|
12030
|
+
function backfill(primary, fallback) {
|
|
12031
|
+
const out = {
|
|
12032
|
+
...fallback ?? {},
|
|
12033
|
+
...primary ?? {}
|
|
12034
|
+
};
|
|
12035
|
+
for (const k of Object.keys(out)) {
|
|
12036
|
+
if (out[k] == null && fallback?.[k] != null) out[k] = fallback[k];
|
|
12037
|
+
}
|
|
12038
|
+
return out;
|
|
12039
|
+
}
|
|
12040
|
+
/**
|
|
12041
|
+
* Serialize a {@link ServerSentEvent} back to its SSE wire form
|
|
12042
|
+
* (`event: ...\ndata: ...\n\n`). Multi-line `data` is emitted as one
|
|
12043
|
+
* `data:` line per line, matching the spec. The inverse of the decoder
|
|
12044
|
+
* behind {@link Stream.rawEvents}.
|
|
12045
|
+
*/
|
|
12046
|
+
function serializeSSE(sse) {
|
|
12047
|
+
let out = "";
|
|
12048
|
+
if (sse.event !== null) out += `event: ${sse.event}\n`;
|
|
12049
|
+
for (const line of sse.data.split("\n")) out += `data: ${line}\n`;
|
|
12050
|
+
return out + "\n";
|
|
12051
|
+
}
|
|
12052
|
+
function makeAbort(controller, signal) {
|
|
12053
|
+
return () => controller.abort(signal.reason);
|
|
12054
|
+
}
|
|
12055
|
+
|
|
12056
|
+
//#endregion
|
|
12057
|
+
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.112.3_zod@4.4.3/node_modules/@anthropic-ai/sdk/index.mjs
|
|
10473
12058
|
var sdk_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
10474
12059
|
AI_PROMPT: () => AI_PROMPT,
|
|
10475
12060
|
HUMAN_PROMPT: () => HUMAN_PROMPT,
|