claude-use 11.9.0 → 11.10.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/cli.cjs +583 -288
- package/dist/index.cjs +58 -35
- package/dist/index.mjs +58 -35
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -27010,12 +27010,12 @@ var init_schema = __esm({
|
|
|
27010
27010
|
ANTIGRAVITY_TIERS = ["fable", "opus", "sonnet", "haiku"];
|
|
27011
27011
|
ANTIGRAVITY_EFFORTS = ["none", "low", "medium", "high", "xhigh", "max"];
|
|
27012
27012
|
ANTIGRAVITY_DEFAULT_MODE = "cloud";
|
|
27013
|
-
ANTIGRAVITY_DEFAULT_MODEL = "gemini-
|
|
27013
|
+
ANTIGRAVITY_DEFAULT_MODEL = "gemini-3.8-flash-high";
|
|
27014
27014
|
ANTIGRAVITY_DEFAULT_TIER_MODELS = Object.freeze({
|
|
27015
|
-
fable: "gemini-
|
|
27016
|
-
opus: "gemini-
|
|
27017
|
-
sonnet: "gemini-
|
|
27018
|
-
haiku: "gemini-
|
|
27015
|
+
fable: "gemini-3.8-flash-high",
|
|
27016
|
+
opus: "gemini-3.8-flash-high",
|
|
27017
|
+
sonnet: "gemini-3.8-flash-medium",
|
|
27018
|
+
haiku: "gemini-3.8-flash-low"
|
|
27019
27019
|
});
|
|
27020
27020
|
ANTIGRAVITY_DEFAULT_EFFORT = "low";
|
|
27021
27021
|
AntigravityProviderConfigSchema = external_exports.strictObject({
|
|
@@ -33962,11 +33962,33 @@ function formatCredentialSummary(summary) {
|
|
|
33962
33962
|
function describeCredential(credential) {
|
|
33963
33963
|
return formatCredentialSummary(summariseCredential(credential));
|
|
33964
33964
|
}
|
|
33965
|
+
function isRecord2(value2) {
|
|
33966
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
33967
|
+
}
|
|
33968
|
+
function unpackKeyringToken(raw) {
|
|
33969
|
+
const trimmed = raw.trim();
|
|
33970
|
+
if (!trimmed.startsWith(GO_KEYRING_BASE64_PREFIX)) {
|
|
33971
|
+
return trimmed;
|
|
33972
|
+
}
|
|
33973
|
+
try {
|
|
33974
|
+
const base64Str = trimmed.slice(GO_KEYRING_BASE64_PREFIX.length);
|
|
33975
|
+
const decoded = Buffer.from(base64Str, "base64").toString("utf8");
|
|
33976
|
+
const parsed = JSON.parse(decoded);
|
|
33977
|
+
if (isRecord2(parsed) && isRecord2(parsed.token)) {
|
|
33978
|
+
const accessToken = parsed.token.access_token;
|
|
33979
|
+
if (typeof accessToken === "string" && accessToken.trim() !== "") {
|
|
33980
|
+
return accessToken.trim();
|
|
33981
|
+
}
|
|
33982
|
+
}
|
|
33983
|
+
} catch {
|
|
33984
|
+
}
|
|
33985
|
+
return trimmed;
|
|
33986
|
+
}
|
|
33965
33987
|
function trySource(source, params) {
|
|
33966
33988
|
const none = (reason, warn = false) => ({ ok: false, reason, warn });
|
|
33967
33989
|
if ("env" in source) {
|
|
33968
33990
|
const value2 = params.env[source.env];
|
|
33969
|
-
return value2 === void 0 || value2 === "" ? none("is unset or empty") : { ok: true, token: value2 };
|
|
33991
|
+
return value2 === void 0 || value2 === "" ? none("is unset or empty") : { ok: true, token: unpackKeyringToken(value2) };
|
|
33970
33992
|
}
|
|
33971
33993
|
if ("literal" in source) {
|
|
33972
33994
|
return { ok: true, token: source.literal };
|
|
@@ -33982,7 +34004,7 @@ function trySource(source, params) {
|
|
|
33982
34004
|
true
|
|
33983
34005
|
);
|
|
33984
34006
|
}
|
|
33985
|
-
const token2 = read.content.trim();
|
|
34007
|
+
const token2 = unpackKeyringToken(read.content.trim());
|
|
33986
34008
|
return token2 === "" ? none("is empty") : { ok: true, token: token2 };
|
|
33987
34009
|
}
|
|
33988
34010
|
const argv = commandArgv(source);
|
|
@@ -34000,7 +34022,7 @@ function trySource(source, params) {
|
|
|
34000
34022
|
const outcome = result.status === null ? "could not be run or was killed by a signal" : `exited with status ${String(result.status)}`;
|
|
34001
34023
|
return none(`${outcome}${stderr === "" ? "" : `: ${stderr}`}`);
|
|
34002
34024
|
}
|
|
34003
|
-
const token = result.stdout.trim();
|
|
34025
|
+
const token = unpackKeyringToken(result.stdout.trim());
|
|
34004
34026
|
return token === "" ? none("printed no token") : { ok: true, token };
|
|
34005
34027
|
}
|
|
34006
34028
|
function warmCommandFor(subject) {
|
|
@@ -34044,7 +34066,7 @@ function credentialVariables(target, token) {
|
|
|
34044
34066
|
CLAUDE_CODE_OAUTH_TOKEN: target === "oauthToken" ? token : void 0
|
|
34045
34067
|
};
|
|
34046
34068
|
}
|
|
34047
|
-
var CREDENTIAL_UNAVAILABLE_EXIT, CREDENTIAL_COMMAND_TIMEOUT_MS, CREDENTIAL_INTERACTIVE_TIMEOUT_MS, GROUP_OTHER_PERMISSION_BITS, PERMISSION_BITS2, OCTAL_RADIX2;
|
|
34069
|
+
var CREDENTIAL_UNAVAILABLE_EXIT, CREDENTIAL_COMMAND_TIMEOUT_MS, CREDENTIAL_INTERACTIVE_TIMEOUT_MS, GROUP_OTHER_PERMISSION_BITS, PERMISSION_BITS2, OCTAL_RADIX2, GO_KEYRING_BASE64_PREFIX;
|
|
34048
34070
|
var init_credential = __esm({
|
|
34049
34071
|
"src/credential.ts"() {
|
|
34050
34072
|
"use strict";
|
|
@@ -34055,6 +34077,7 @@ var init_credential = __esm({
|
|
|
34055
34077
|
GROUP_OTHER_PERMISSION_BITS = 63;
|
|
34056
34078
|
PERMISSION_BITS2 = 511;
|
|
34057
34079
|
OCTAL_RADIX2 = 8;
|
|
34080
|
+
GO_KEYRING_BASE64_PREFIX = "go-keyring-base64:";
|
|
34058
34081
|
}
|
|
34059
34082
|
});
|
|
34060
34083
|
|
|
@@ -34064,7 +34087,7 @@ var init_package = __esm({
|
|
|
34064
34087
|
"package.json"() {
|
|
34065
34088
|
package_default = {
|
|
34066
34089
|
name: "claude-use",
|
|
34067
|
-
version: "11.
|
|
34090
|
+
version: "11.10.0",
|
|
34068
34091
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
34069
34092
|
license: "MIT",
|
|
34070
34093
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -35634,14 +35657,14 @@ function providerJsonPath(paths, name) {
|
|
|
35634
35657
|
function providerExists(paths, name) {
|
|
35635
35658
|
return import_node_fs10.default.existsSync(providerJsonPath(paths, name));
|
|
35636
35659
|
}
|
|
35637
|
-
function
|
|
35660
|
+
function isRecord3(value2) {
|
|
35638
35661
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
35639
35662
|
}
|
|
35640
35663
|
function legacyProviderConversion(raw) {
|
|
35641
|
-
if (!
|
|
35664
|
+
if (!isRecord3(raw) || "credential" in raw) {
|
|
35642
35665
|
return void 0;
|
|
35643
35666
|
}
|
|
35644
|
-
const env =
|
|
35667
|
+
const env = isRecord3(raw.env) ? raw.env : void 0;
|
|
35645
35668
|
const legacyEnvKeys = env === void 0 ? [] : Object.keys(env).filter((key) => LEGACY_ENV_CREDENTIAL_KEYS.includes(key));
|
|
35646
35669
|
const fields = [...LEGACY_PROVIDER_FIELDS.filter((field) => field in raw), ...legacyEnvKeys.map((key) => `env.${key}`)];
|
|
35647
35670
|
if (fields.length === 0) {
|
|
@@ -112646,7 +112669,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
112646
112669
|
}
|
|
112647
112670
|
|
|
112648
112671
|
// src/frontdoor/commands.ts
|
|
112649
|
-
var
|
|
112672
|
+
var import_node_crypto24 = require("node:crypto");
|
|
112650
112673
|
var import_node_path51 = __toESM(require("node:path"), 1);
|
|
112651
112674
|
var import_node_fs19 = __toESM(require("node:fs"), 1);
|
|
112652
112675
|
init_commandDeps();
|
|
@@ -114864,7 +114887,7 @@ var LiveTaskSchema = external_exports.strictObject({
|
|
|
114864
114887
|
observedAt: external_exports.number()
|
|
114865
114888
|
});
|
|
114866
114889
|
var SYSTEM_SUBTYPES = ["task_started", "task_progress", "task_updated", "task_notification", "background_tasks_changed"];
|
|
114867
|
-
function
|
|
114890
|
+
function isRecord4(value2) {
|
|
114868
114891
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
114869
114892
|
}
|
|
114870
114893
|
function stringField(record2, field) {
|
|
@@ -114881,7 +114904,7 @@ function booleanField(record2, field) {
|
|
|
114881
114904
|
}
|
|
114882
114905
|
function usageOf(record2) {
|
|
114883
114906
|
const raw = record2.usage;
|
|
114884
|
-
if (!
|
|
114907
|
+
if (!isRecord4(raw)) {
|
|
114885
114908
|
return void 0;
|
|
114886
114909
|
}
|
|
114887
114910
|
const totalTokens = numberField(raw, "total_tokens");
|
|
@@ -114913,7 +114936,7 @@ function bounded(book) {
|
|
|
114913
114936
|
return book;
|
|
114914
114937
|
}
|
|
114915
114938
|
function applyAgentTaskEvent(book, sessionId, payload, observedAt2) {
|
|
114916
|
-
if (!
|
|
114939
|
+
if (!isRecord4(payload) || payload.type !== "system") {
|
|
114917
114940
|
return book;
|
|
114918
114941
|
}
|
|
114919
114942
|
const subtype = payload.subtype;
|
|
@@ -114929,8 +114952,8 @@ function applyAgentTaskEvent(book, sessionId, payload, observedAt2) {
|
|
|
114929
114952
|
if (subtype === "background_tasks_changed") {
|
|
114930
114953
|
const tasks = Array.isArray(payload.tasks) ? payload.tasks : [];
|
|
114931
114954
|
for (const raw of tasks) {
|
|
114932
|
-
const taskId2 =
|
|
114933
|
-
if (
|
|
114955
|
+
const taskId2 = isRecord4(raw) ? stringField(raw, "task_id") : void 0;
|
|
114956
|
+
if (isRecord4(raw) && taskId2 !== void 0) {
|
|
114934
114957
|
upsert(taskId2, { runId: stringField(raw, "run_id"), taskType: stringField(raw, "task_type"), description: stringField(raw, "description") });
|
|
114935
114958
|
}
|
|
114936
114959
|
}
|
|
@@ -114953,7 +114976,7 @@ function applyAgentTaskEvent(book, sessionId, payload, observedAt2) {
|
|
|
114953
114976
|
} else if (subtype === "task_progress") {
|
|
114954
114977
|
upsert(taskId, { ...common, subagentType: stringField(payload, "subagent_type"), lastToolName: stringField(payload, "last_tool_name"), usage: usageOf(payload) });
|
|
114955
114978
|
} else if (subtype === "task_updated") {
|
|
114956
|
-
const patch =
|
|
114979
|
+
const patch = isRecord4(payload.patch) ? payload.patch : {};
|
|
114957
114980
|
upsert(taskId, { runId: stringField(payload, "run_id"), status: stringField(patch, "status") });
|
|
114958
114981
|
} else {
|
|
114959
114982
|
upsert(taskId, { ...common, status: stringField(payload, "status"), outputFile: stringField(payload, "output_file"), summary: stringField(payload, "summary"), usage: usageOf(payload) });
|
|
@@ -115035,7 +115058,7 @@ function sessionCreateId(body) {
|
|
|
115035
115058
|
const id2 = session.id;
|
|
115036
115059
|
return typeof id2 === "string" && id2.startsWith(RC_SESSION_ID_PREFIX) ? id2 : void 0;
|
|
115037
115060
|
}
|
|
115038
|
-
function
|
|
115061
|
+
function isRecord5(value2) {
|
|
115039
115062
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
115040
115063
|
}
|
|
115041
115064
|
function parseJsonObject(body) {
|
|
@@ -115045,7 +115068,7 @@ function parseJsonObject(body) {
|
|
|
115045
115068
|
} catch {
|
|
115046
115069
|
return void 0;
|
|
115047
115070
|
}
|
|
115048
|
-
return
|
|
115071
|
+
return isRecord5(parsed) ? parsed : void 0;
|
|
115049
115072
|
}
|
|
115050
115073
|
function nonEmptyString(record2, field) {
|
|
115051
115074
|
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
@@ -115066,11 +115089,11 @@ function payloadEventsOf(body) {
|
|
|
115066
115089
|
}
|
|
115067
115090
|
const payloads = [];
|
|
115068
115091
|
for (const event of events) {
|
|
115069
|
-
if (!
|
|
115092
|
+
if (!isRecord5(event)) {
|
|
115070
115093
|
continue;
|
|
115071
115094
|
}
|
|
115072
115095
|
const payload = event.payload;
|
|
115073
|
-
if (!
|
|
115096
|
+
if (!isRecord5(payload)) {
|
|
115074
115097
|
continue;
|
|
115075
115098
|
}
|
|
115076
115099
|
payloads.push(payload);
|
|
@@ -115085,7 +115108,7 @@ function pendingOfControlRequestPayload(payload) {
|
|
|
115085
115108
|
if (requestId === void 0) {
|
|
115086
115109
|
return void 0;
|
|
115087
115110
|
}
|
|
115088
|
-
const request7 =
|
|
115111
|
+
const request7 = isRecord5(payload.request) ? payload.request : void 0;
|
|
115089
115112
|
const subtype = nonEmptyString(request7, "subtype");
|
|
115090
115113
|
const type2 = subtype ?? "control_request";
|
|
115091
115114
|
let summary = "";
|
|
@@ -115102,7 +115125,7 @@ function answeredRequestIdsOfControlResponsePayload(payload) {
|
|
|
115102
115125
|
if (payload.type !== "control_response") {
|
|
115103
115126
|
return [];
|
|
115104
115127
|
}
|
|
115105
|
-
const response =
|
|
115128
|
+
const response = isRecord5(payload.response) ? payload.response : void 0;
|
|
115106
115129
|
const id2 = nonEmptyString(response, "request_id") ?? nonEmptyString(payload, "request_id") ?? nonEmptyString(payload, "uuid");
|
|
115107
115130
|
return id2 === void 0 ? [] : [id2];
|
|
115108
115131
|
}
|
|
@@ -115331,7 +115354,7 @@ function createRcSessionTracker(deps) {
|
|
|
115331
115354
|
return;
|
|
115332
115355
|
}
|
|
115333
115356
|
entry.sequenceNum = entry.sequenceNum === void 0 || event.sequence_num > entry.sequenceNum ? event.sequence_num : entry.sequenceNum;
|
|
115334
|
-
if (!
|
|
115357
|
+
if (!isRecord5(event.payload)) {
|
|
115335
115358
|
return;
|
|
115336
115359
|
}
|
|
115337
115360
|
entry.liveTasks = applyAgentTaskEvent(entry.liveTasks, sessionId, event.payload, deps.now());
|
|
@@ -120209,7 +120232,7 @@ var HTTP_METHODS_UP_TO_V31 = [
|
|
|
120209
120232
|
function operationFields(convert) {
|
|
120210
120233
|
return Object.fromEntries(HTTP_METHODS_UP_TO_V31.map((method) => [method, convert]));
|
|
120211
120234
|
}
|
|
120212
|
-
function
|
|
120235
|
+
function isRecord6(value2) {
|
|
120213
120236
|
if (typeof value2 !== "object" || value2 === null) {
|
|
120214
120237
|
return false;
|
|
120215
120238
|
}
|
|
@@ -120229,7 +120252,7 @@ function setOwn2(object3, key, value2) {
|
|
|
120229
120252
|
}
|
|
120230
120253
|
}
|
|
120231
120254
|
function cloneValue(value2, seen) {
|
|
120232
|
-
if (!(Array.isArray(value2) ||
|
|
120255
|
+
if (!(Array.isArray(value2) || isRecord6(value2))) {
|
|
120233
120256
|
return value2;
|
|
120234
120257
|
}
|
|
120235
120258
|
const existing = seen.get(value2);
|
|
@@ -120252,14 +120275,14 @@ function cloneValue(value2, seen) {
|
|
|
120252
120275
|
return out;
|
|
120253
120276
|
}
|
|
120254
120277
|
function deepClone(value2) {
|
|
120255
|
-
if (!(Array.isArray(value2) ||
|
|
120278
|
+
if (!(Array.isArray(value2) || isRecord6(value2))) {
|
|
120256
120279
|
return value2;
|
|
120257
120280
|
}
|
|
120258
120281
|
return cloneValue(value2, /* @__PURE__ */ new WeakMap());
|
|
120259
120282
|
}
|
|
120260
120283
|
var converting = /* @__PURE__ */ new WeakMap();
|
|
120261
120284
|
function convertRecord(value2, fields, finish) {
|
|
120262
|
-
if (!
|
|
120285
|
+
if (!isRecord6(value2)) {
|
|
120263
120286
|
return deepClone(value2);
|
|
120264
120287
|
}
|
|
120265
120288
|
const inProgress = converting.get(value2);
|
|
@@ -120285,7 +120308,7 @@ function convertRecord(value2, fields, finish) {
|
|
|
120285
120308
|
}
|
|
120286
120309
|
}
|
|
120287
120310
|
function mapRecord(value2, convert) {
|
|
120288
|
-
if (!
|
|
120311
|
+
if (!isRecord6(value2)) {
|
|
120289
120312
|
return deepClone(value2);
|
|
120290
120313
|
}
|
|
120291
120314
|
const out = {};
|
|
@@ -120304,7 +120327,7 @@ function mapArray(value2, convert) {
|
|
|
120304
120327
|
return value2.map((item) => convert(item)).filter((item) => item !== DROP);
|
|
120305
120328
|
}
|
|
120306
120329
|
function getRef(value2) {
|
|
120307
|
-
if (
|
|
120330
|
+
if (isRecord6(value2) && typeof value2.$ref === "string") {
|
|
120308
120331
|
return value2.$ref;
|
|
120309
120332
|
}
|
|
120310
120333
|
return void 0;
|
|
@@ -120510,7 +120533,7 @@ function convertSchema2(schema) {
|
|
|
120510
120533
|
if (schema === false) {
|
|
120511
120534
|
return { not: {} };
|
|
120512
120535
|
}
|
|
120513
|
-
if (
|
|
120536
|
+
if (isRecord6(schema) && typeof schema.$ref === "string" && Object.keys(schema).length === 1) {
|
|
120514
120537
|
return { $ref: schema.$ref };
|
|
120515
120538
|
}
|
|
120516
120539
|
return convertRecord(schema, SCHEMA_FIELDS, finishSchema);
|
|
@@ -120522,7 +120545,7 @@ function resolveSchemeType(name, schemes, seen) {
|
|
|
120522
120545
|
return void 0;
|
|
120523
120546
|
}
|
|
120524
120547
|
const scheme = schemes[name];
|
|
120525
|
-
if (!
|
|
120548
|
+
if (!isRecord6(scheme)) {
|
|
120526
120549
|
return void 0;
|
|
120527
120550
|
}
|
|
120528
120551
|
if (typeof scheme.type === "string") {
|
|
@@ -120539,11 +120562,11 @@ function resolveSchemeType(name, schemes, seen) {
|
|
|
120539
120562
|
return void 0;
|
|
120540
120563
|
}
|
|
120541
120564
|
function createContext(spec) {
|
|
120542
|
-
const components =
|
|
120543
|
-
const pathItems =
|
|
120544
|
-
const schemes =
|
|
120565
|
+
const components = isRecord6(spec) ? spec.components : void 0;
|
|
120566
|
+
const pathItems = isRecord6(components) ? components.pathItems : void 0;
|
|
120567
|
+
const schemes = isRecord6(components) ? components.securitySchemes : void 0;
|
|
120545
120568
|
const schemeTypes = /* @__PURE__ */ new Map();
|
|
120546
|
-
if (
|
|
120569
|
+
if (isRecord6(schemes)) {
|
|
120547
120570
|
for (const name of Object.keys(schemes)) {
|
|
120548
120571
|
const type2 = resolveSchemeType(name, schemes, /* @__PURE__ */ new Set());
|
|
120549
120572
|
if (type2 !== void 0) {
|
|
@@ -120553,7 +120576,7 @@ function createContext(spec) {
|
|
|
120553
120576
|
}
|
|
120554
120577
|
return {
|
|
120555
120578
|
inlining: /* @__PURE__ */ new Set(),
|
|
120556
|
-
pathItems:
|
|
120579
|
+
pathItems: isRecord6(pathItems) ? pathItems : void 0,
|
|
120557
120580
|
schemeTypes
|
|
120558
120581
|
};
|
|
120559
120582
|
}
|
|
@@ -120561,7 +120584,7 @@ function isMutualTls(name, context) {
|
|
|
120561
120584
|
return context.schemeTypes.get(name) === "mutualTLS";
|
|
120562
120585
|
}
|
|
120563
120586
|
function convertRequirement(value2, context) {
|
|
120564
|
-
if (!
|
|
120587
|
+
if (!isRecord6(value2)) {
|
|
120565
120588
|
return deepClone(value2);
|
|
120566
120589
|
}
|
|
120567
120590
|
const entries = Object.entries(value2);
|
|
@@ -120661,10 +120684,10 @@ function resolvePathItemRef(value2, context) {
|
|
|
120661
120684
|
return void 0;
|
|
120662
120685
|
}
|
|
120663
120686
|
const target = context.pathItems[name];
|
|
120664
|
-
return
|
|
120687
|
+
return isRecord6(target) ? [name, target] : void 0;
|
|
120665
120688
|
}
|
|
120666
120689
|
function convertPathItem(value2, context) {
|
|
120667
|
-
if (!
|
|
120690
|
+
if (!isRecord6(value2)) {
|
|
120668
120691
|
return deepClone(value2);
|
|
120669
120692
|
}
|
|
120670
120693
|
const resolved = resolvePathItemRef(value2, context);
|
|
@@ -120764,7 +120787,7 @@ function convertExample(value2) {
|
|
|
120764
120787
|
});
|
|
120765
120788
|
}
|
|
120766
120789
|
function isQuerystringParameter(value2) {
|
|
120767
|
-
return
|
|
120790
|
+
return isRecord6(value2) && value2.in === "querystring";
|
|
120768
120791
|
}
|
|
120769
120792
|
function isRemovedRef(value2, removed) {
|
|
120770
120793
|
const ref = getRef(value2);
|
|
@@ -120780,7 +120803,7 @@ function convertParameterOrHeader2(value2, context) {
|
|
|
120780
120803
|
style: (item) => item === "cookie" ? DROP : deepClone(item)
|
|
120781
120804
|
},
|
|
120782
120805
|
(out, parameter) => {
|
|
120783
|
-
const lostContent =
|
|
120806
|
+
const lostContent = isRecord6(parameter.content) && Object.keys(parameter.content).length > 0 && isRecord6(out.content) && Object.keys(out.content).length === 0;
|
|
120784
120807
|
return lostContent ? DROP : out;
|
|
120785
120808
|
}
|
|
120786
120809
|
);
|
|
@@ -120901,7 +120924,7 @@ function convertComponents2(value2, context) {
|
|
|
120901
120924
|
});
|
|
120902
120925
|
}
|
|
120903
120926
|
function losesEntireContent(value2, mediaTypes) {
|
|
120904
|
-
if (!(
|
|
120927
|
+
if (!(isRecord6(value2) && isRecord6(value2.content))) {
|
|
120905
120928
|
return false;
|
|
120906
120929
|
}
|
|
120907
120930
|
const entries = Object.values(value2.content);
|
|
@@ -120909,7 +120932,7 @@ function losesEntireContent(value2, mediaTypes) {
|
|
|
120909
120932
|
}
|
|
120910
120933
|
function indexRemovedComponentRefs(map2, prefix, mediaTypes, isDirectlyRemoved) {
|
|
120911
120934
|
const removed = /* @__PURE__ */ new Set();
|
|
120912
|
-
if (!
|
|
120935
|
+
if (!isRecord6(map2)) {
|
|
120913
120936
|
return removed;
|
|
120914
120937
|
}
|
|
120915
120938
|
const entries = Object.entries(map2);
|
|
@@ -120931,12 +120954,12 @@ function indexRemovedComponentRefs(map2, prefix, mediaTypes, isDirectlyRemoved)
|
|
|
120931
120954
|
return removed;
|
|
120932
120955
|
}
|
|
120933
120956
|
function createContext2(spec) {
|
|
120934
|
-
const components =
|
|
120935
|
-
const mediaTypes =
|
|
120957
|
+
const components = isRecord6(spec) ? spec.components : void 0;
|
|
120958
|
+
const mediaTypes = isRecord6(components) && isRecord6(components.mediaTypes) ? components.mediaTypes : void 0;
|
|
120936
120959
|
return {
|
|
120937
120960
|
mediaTypes,
|
|
120938
|
-
removedHeaderRefs: indexRemovedComponentRefs(
|
|
120939
|
-
removedParameterRefs: indexRemovedComponentRefs(
|
|
120961
|
+
removedHeaderRefs: indexRemovedComponentRefs(isRecord6(components) ? components.headers : void 0, HEADERS_REF_PREFIX, mediaTypes, () => false),
|
|
120962
|
+
removedParameterRefs: indexRemovedComponentRefs(isRecord6(components) ? components.parameters : void 0, PARAMETERS_REF_PREFIX, mediaTypes, isQuerystringParameter)
|
|
120940
120963
|
};
|
|
120941
120964
|
}
|
|
120942
120965
|
function convertJsonSchemaDialect(value2) {
|
|
@@ -127530,6 +127553,24 @@ function translateRequest(body, config2) {
|
|
|
127530
127553
|
|
|
127531
127554
|
// src/antigravity/translate.ts
|
|
127532
127555
|
var import_node_crypto20 = require("node:crypto");
|
|
127556
|
+
|
|
127557
|
+
// src/antigravity/signatures.ts
|
|
127558
|
+
var MAX_REMEMBERED = 1024;
|
|
127559
|
+
var signatures = /* @__PURE__ */ new Map();
|
|
127560
|
+
function rememberToolCallSignature(toolUseId, signature) {
|
|
127561
|
+
signatures.set(toolUseId, signature);
|
|
127562
|
+
if (signatures.size > MAX_REMEMBERED) {
|
|
127563
|
+
const oldest = signatures.keys().next();
|
|
127564
|
+
if (oldest.done !== true) {
|
|
127565
|
+
signatures.delete(oldest.value);
|
|
127566
|
+
}
|
|
127567
|
+
}
|
|
127568
|
+
}
|
|
127569
|
+
function toolCallSignatureOf(toolUseId) {
|
|
127570
|
+
return signatures.get(toolUseId);
|
|
127571
|
+
}
|
|
127572
|
+
|
|
127573
|
+
// src/antigravity/translate.ts
|
|
127533
127574
|
init_schema();
|
|
127534
127575
|
function resolveAntigravityConfig(config2) {
|
|
127535
127576
|
const overrides = config2?.models;
|
|
@@ -127625,7 +127666,7 @@ function turnBlocks2(message) {
|
|
|
127625
127666
|
}
|
|
127626
127667
|
return blocks.map((block2) => isTextBlock(block2) ? { ...block2, text: systemReminder2(block2.text) } : block2);
|
|
127627
127668
|
}
|
|
127628
|
-
function
|
|
127669
|
+
function isRecord7(value2) {
|
|
127629
127670
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
127630
127671
|
}
|
|
127631
127672
|
function messagesToGeminiContents(messages, names, toolIdToName) {
|
|
@@ -127667,11 +127708,14 @@ function messagesToGeminiContents(messages, names, toolIdToName) {
|
|
|
127667
127708
|
} else if (isToolUseBlock(block2)) {
|
|
127668
127709
|
const sanitizedName = shortToolName2(block2.name, names);
|
|
127669
127710
|
toolIdToName.set(block2.id, sanitizedName);
|
|
127711
|
+
const signature = toolCallSignatureOf(block2.id);
|
|
127670
127712
|
ensureRole("model").push({
|
|
127671
127713
|
functionCall: {
|
|
127672
127714
|
name: sanitizedName,
|
|
127673
|
-
args:
|
|
127674
|
-
}
|
|
127715
|
+
args: isRecord7(block2.input) ? block2.input : {}
|
|
127716
|
+
},
|
|
127717
|
+
// The relay remembered the signature the backend attached to this exact call; echoing it back is what the backend requires of a repeated function call.
|
|
127718
|
+
...signature === void 0 ? {} : { thoughtSignature: signature }
|
|
127675
127719
|
});
|
|
127676
127720
|
} else if (isToolResultBlock(block2)) {
|
|
127677
127721
|
const toolName = toolIdToName.get(block2.tool_use_id) ?? "unknown_tool";
|
|
@@ -127688,21 +127732,110 @@ function messagesToGeminiContents(messages, names, toolIdToName) {
|
|
|
127688
127732
|
return contents;
|
|
127689
127733
|
}
|
|
127690
127734
|
var EMPTY_SCHEMA = { type: "object", properties: {} };
|
|
127735
|
+
var GEMINI_SCHEMA_KEYS = /* @__PURE__ */ new Set(["type", "format", "description", "nullable", "enum", "anyOf", "items", "properties", "required", "minimum", "maximum", "minItems", "maxItems"]);
|
|
127736
|
+
function describeSchemaValue(node2) {
|
|
127737
|
+
if (!isRecord7(node2)) {
|
|
127738
|
+
return "any value";
|
|
127739
|
+
}
|
|
127740
|
+
const type2 = node2.type;
|
|
127741
|
+
const name = typeof type2 === "string" ? type2 : Array.isArray(type2) && typeof type2[0] === "string" ? type2[0] : "value";
|
|
127742
|
+
if (name === "array") {
|
|
127743
|
+
return `a list of ${describeSchemaValue(node2.items)}`;
|
|
127744
|
+
}
|
|
127745
|
+
return name === "object" ? "an object" : `a ${name}`;
|
|
127746
|
+
}
|
|
127747
|
+
function toGeminiSchema(node2) {
|
|
127748
|
+
if (!isRecord7(node2)) {
|
|
127749
|
+
return node2;
|
|
127750
|
+
}
|
|
127751
|
+
const out = {};
|
|
127752
|
+
const notes = [];
|
|
127753
|
+
let nullable2 = false;
|
|
127754
|
+
for (const [key, value2] of Object.entries(node2)) {
|
|
127755
|
+
if (key === "type" && Array.isArray(value2)) {
|
|
127756
|
+
const named = value2.filter((entry) => entry !== "null");
|
|
127757
|
+
if (named.length > 0 && typeof named[0] === "string") {
|
|
127758
|
+
out.type = named[0];
|
|
127759
|
+
}
|
|
127760
|
+
nullable2 = value2.includes("null");
|
|
127761
|
+
continue;
|
|
127762
|
+
}
|
|
127763
|
+
if (!GEMINI_SCHEMA_KEYS.has(key)) {
|
|
127764
|
+
if (key === "additionalProperties" && value2 !== false) {
|
|
127765
|
+
notes.push(`Each value is ${describeSchemaValue(value2)}.`);
|
|
127766
|
+
} else if (key === "propertyNames" && isRecord7(value2) && typeof value2.pattern === "string") {
|
|
127767
|
+
notes.push(`Keys match ${value2.pattern}.`);
|
|
127768
|
+
}
|
|
127769
|
+
continue;
|
|
127770
|
+
}
|
|
127771
|
+
out[key] = value2;
|
|
127772
|
+
}
|
|
127773
|
+
if (out.type === "null") {
|
|
127774
|
+
delete out.type;
|
|
127775
|
+
}
|
|
127776
|
+
if (nullable2 && out.type !== void 0) {
|
|
127777
|
+
out.nullable = true;
|
|
127778
|
+
}
|
|
127779
|
+
if (notes.length > 0) {
|
|
127780
|
+
const description = typeof out.description === "string" ? out.description : "";
|
|
127781
|
+
out.description = `${description}${description === "" ? "" : " "}${notes.join(" ")}`;
|
|
127782
|
+
}
|
|
127783
|
+
if ("properties" in out && isRecord7(out.properties)) {
|
|
127784
|
+
out.properties = Object.fromEntries(Object.entries(out.properties).map(([name, child]) => [name, toGeminiSchema(child)]));
|
|
127785
|
+
}
|
|
127786
|
+
if ("items" in out) {
|
|
127787
|
+
out.items = toGeminiSchema(out.items);
|
|
127788
|
+
} else if (out.type === "array") {
|
|
127789
|
+
out.items = {};
|
|
127790
|
+
}
|
|
127791
|
+
if (Array.isArray(out.anyOf)) {
|
|
127792
|
+
out.anyOf = out.anyOf.map(toGeminiSchema);
|
|
127793
|
+
}
|
|
127794
|
+
return out;
|
|
127795
|
+
}
|
|
127691
127796
|
function mapTools2(tools, names) {
|
|
127692
127797
|
if (tools === void 0 || tools.length === 0) {
|
|
127693
127798
|
return void 0;
|
|
127694
127799
|
}
|
|
127695
|
-
const declarations = tools.map((tool) =>
|
|
127696
|
-
|
|
127697
|
-
|
|
127698
|
-
|
|
127699
|
-
|
|
127800
|
+
const declarations = tools.map((tool) => {
|
|
127801
|
+
const converted = tool.input_schema === void 0 ? void 0 : toGeminiSchema(tool.input_schema);
|
|
127802
|
+
return {
|
|
127803
|
+
name: shortToolName2(tool.name, names),
|
|
127804
|
+
description: tool.description,
|
|
127805
|
+
parameters: isRecord7(converted) ? converted : EMPTY_SCHEMA
|
|
127806
|
+
};
|
|
127807
|
+
});
|
|
127700
127808
|
return [{ functionDeclarations: declarations }];
|
|
127701
127809
|
}
|
|
127810
|
+
var EFFORT_SUFFIXES = /* @__PURE__ */ new Set(["low", "medium", "high"]);
|
|
127811
|
+
function effortSuffixOf(level) {
|
|
127812
|
+
if (level === "medium") {
|
|
127813
|
+
return "medium";
|
|
127814
|
+
}
|
|
127815
|
+
return level === "none" || level === "low" ? "low" : "high";
|
|
127816
|
+
}
|
|
127817
|
+
function splitEffortSuffix(model) {
|
|
127818
|
+
const index = model.lastIndexOf("-");
|
|
127819
|
+
if (index === -1) {
|
|
127820
|
+
return void 0;
|
|
127821
|
+
}
|
|
127822
|
+
const suffix = model.slice(index + 1);
|
|
127823
|
+
return EFFORT_SUFFIXES.has(suffix) ? { base: model.slice(0, index), suffix } : void 0;
|
|
127824
|
+
}
|
|
127825
|
+
function completeEffortSuffix(model, request7, config2) {
|
|
127826
|
+
if (splitEffortSuffix(model) !== void 0) {
|
|
127827
|
+
return model;
|
|
127828
|
+
}
|
|
127829
|
+
const configured = [config2.defaultModel, ...Object.values(config2.models)];
|
|
127830
|
+
const effort = request7.output_config?.effort;
|
|
127831
|
+
const level = ANTIGRAVITY_EFFORTS.find((candidate) => candidate === effort) ?? config2.effort;
|
|
127832
|
+
const suffixed = `${model}-${effortSuffixOf(level)}`;
|
|
127833
|
+
return configured.some((entry) => entry === suffixed || splitEffortSuffix(entry)?.base === model) ? suffixed : model;
|
|
127834
|
+
}
|
|
127702
127835
|
function translateRequest2(request7, config2) {
|
|
127703
127836
|
const toolNames = /* @__PURE__ */ new Map();
|
|
127704
127837
|
const toolIdToName = /* @__PURE__ */ new Map();
|
|
127705
|
-
const model = mapModel2(request7.model ?? "", config2);
|
|
127838
|
+
const model = completeEffortSuffix(mapModel2(request7.model ?? "", config2), request7, config2);
|
|
127706
127839
|
const thinkingBudget = mapEffort2(request7, config2);
|
|
127707
127840
|
const systemInstruction = systemToInstruction(request7.system);
|
|
127708
127841
|
const contents = messagesToGeminiContents(request7.messages, toolNames, toolIdToName);
|
|
@@ -127720,6 +127853,302 @@ function translateRequest2(request7, config2) {
|
|
|
127720
127853
|
};
|
|
127721
127854
|
}
|
|
127722
127855
|
|
|
127856
|
+
// src/antigravity/cloudUpstream.ts
|
|
127857
|
+
var import_node_crypto21 = require("node:crypto");
|
|
127858
|
+
var CCPA_ENDPOINT = "https://daily-cloudcode-pa.googleapis.com";
|
|
127859
|
+
var CCPA_DEFAULT_PROJECT_ID = "aicode-consumers";
|
|
127860
|
+
var CCPA_USER_AGENT = "antigravity/cli/1.3.5 (aidev_client; os_type=darwin; arch=arm64; cl=998863838; auth_method=consumer)";
|
|
127861
|
+
function isCcpaEndpoint(endpoint) {
|
|
127862
|
+
return endpoint.includes("cloudcode-pa.googleapis.com");
|
|
127863
|
+
}
|
|
127864
|
+
function buildCloudUrl(config2, model) {
|
|
127865
|
+
const { cloud } = config2;
|
|
127866
|
+
if (cloud.projectId !== void 0 && cloud.location !== void 0) {
|
|
127867
|
+
const base2 = cloud.endpoint ?? `https://${cloud.location}-aiplatform.googleapis.com`;
|
|
127868
|
+
return `${base2}/v1/projects/${cloud.projectId}/locations/${cloud.location}/publishers/google/models/${encodeURIComponent(model)}:streamGenerateContent?alt=sse`;
|
|
127869
|
+
}
|
|
127870
|
+
const base = cloud.endpoint ?? CCPA_ENDPOINT;
|
|
127871
|
+
if (isCcpaEndpoint(base)) {
|
|
127872
|
+
return `${base}/v1internal:streamGenerateContent?alt=sse`;
|
|
127873
|
+
}
|
|
127874
|
+
return `${base}/v1beta/models/${encodeURIComponent(model)}:streamGenerateContent?alt=sse`;
|
|
127875
|
+
}
|
|
127876
|
+
function buildCloudHeaders(token, credentialTarget, endpoint) {
|
|
127877
|
+
const headers = {
|
|
127878
|
+
"Content-Type": "application/json",
|
|
127879
|
+
Accept: "text/event-stream"
|
|
127880
|
+
};
|
|
127881
|
+
const target = credentialTarget ?? "bearer";
|
|
127882
|
+
if (target === "apiKey") {
|
|
127883
|
+
headers["x-goog-api-key"] = token;
|
|
127884
|
+
} else {
|
|
127885
|
+
headers.Authorization = `Bearer ${token}`;
|
|
127886
|
+
}
|
|
127887
|
+
const base = endpoint ?? CCPA_ENDPOINT;
|
|
127888
|
+
if (isCcpaEndpoint(base)) {
|
|
127889
|
+
headers["User-Agent"] = CCPA_USER_AGENT;
|
|
127890
|
+
}
|
|
127891
|
+
return headers;
|
|
127892
|
+
}
|
|
127893
|
+
function buildCloudRequestBody(params) {
|
|
127894
|
+
const base = params.config.cloud.endpoint ?? CCPA_ENDPOINT;
|
|
127895
|
+
if (isCcpaEndpoint(base)) {
|
|
127896
|
+
return JSON.stringify({
|
|
127897
|
+
project: params.config.cloud.projectId ?? CCPA_DEFAULT_PROJECT_ID,
|
|
127898
|
+
requestId: `agent/${(0, import_node_crypto21.randomUUID)()}/${String(Date.now())}/1`,
|
|
127899
|
+
request: params.request,
|
|
127900
|
+
model: params.model,
|
|
127901
|
+
userAgent: "antigravity"
|
|
127902
|
+
});
|
|
127903
|
+
}
|
|
127904
|
+
return JSON.stringify(params.request);
|
|
127905
|
+
}
|
|
127906
|
+
function isRecord8(value2) {
|
|
127907
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
127908
|
+
}
|
|
127909
|
+
function isGeminiChunk(value2) {
|
|
127910
|
+
return isRecord8(value2);
|
|
127911
|
+
}
|
|
127912
|
+
var AntigravityUpstreamError = class extends Error {
|
|
127913
|
+
status;
|
|
127914
|
+
retryAfter;
|
|
127915
|
+
constructor(status, message, retryAfter) {
|
|
127916
|
+
super(`Google Antigravity API error (${String(status)}): ${message}`);
|
|
127917
|
+
this.name = "AntigravityUpstreamError";
|
|
127918
|
+
this.status = status;
|
|
127919
|
+
this.retryAfter = retryAfter;
|
|
127920
|
+
}
|
|
127921
|
+
};
|
|
127922
|
+
async function* callCloudAntigravity(params, fetchFn = fetch) {
|
|
127923
|
+
const url2 = buildCloudUrl(params.config, params.model);
|
|
127924
|
+
const headers = buildCloudHeaders(params.token, params.credentialTarget, params.config.cloud.endpoint);
|
|
127925
|
+
const body = buildCloudRequestBody(params);
|
|
127926
|
+
const response = await fetchFn(url2, {
|
|
127927
|
+
method: "POST",
|
|
127928
|
+
headers,
|
|
127929
|
+
body,
|
|
127930
|
+
signal: params.signal
|
|
127931
|
+
});
|
|
127932
|
+
if (!response.ok) {
|
|
127933
|
+
const errorText = await response.text();
|
|
127934
|
+
const retryAfter = response.headers.get("retry-after");
|
|
127935
|
+
throw new AntigravityUpstreamError(response.status, errorText, retryAfter);
|
|
127936
|
+
}
|
|
127937
|
+
if (response.body === null) {
|
|
127938
|
+
return;
|
|
127939
|
+
}
|
|
127940
|
+
const decoder = new TextDecoder("utf-8");
|
|
127941
|
+
let buffer2 = "";
|
|
127942
|
+
const sseDataPrefix = "data:";
|
|
127943
|
+
for await (const rawChunk of response.body) {
|
|
127944
|
+
const chunk = rawChunk instanceof Uint8Array ? rawChunk : Buffer.from(String(rawChunk));
|
|
127945
|
+
buffer2 += decoder.decode(chunk, { stream: true });
|
|
127946
|
+
const lines = buffer2.split("\n");
|
|
127947
|
+
buffer2 = lines.pop() ?? "";
|
|
127948
|
+
for (const line of lines) {
|
|
127949
|
+
const trimmed = line.trim();
|
|
127950
|
+
if (trimmed.startsWith(sseDataPrefix)) {
|
|
127951
|
+
const jsonStr = trimmed.slice(sseDataPrefix.length).trim();
|
|
127952
|
+
if (jsonStr.length > 0) {
|
|
127953
|
+
try {
|
|
127954
|
+
const parsed = JSON.parse(jsonStr);
|
|
127955
|
+
if (isRecord8(parsed)) {
|
|
127956
|
+
const unwrapped = isRecord8(parsed.response) ? parsed.response : parsed;
|
|
127957
|
+
if (isGeminiChunk(unwrapped)) {
|
|
127958
|
+
yield unwrapped;
|
|
127959
|
+
}
|
|
127960
|
+
}
|
|
127961
|
+
} catch {
|
|
127962
|
+
}
|
|
127963
|
+
}
|
|
127964
|
+
}
|
|
127965
|
+
}
|
|
127966
|
+
}
|
|
127967
|
+
}
|
|
127968
|
+
|
|
127969
|
+
// src/antigravity/quota.ts
|
|
127970
|
+
var MS_PER_SECOND8 = 1e3;
|
|
127971
|
+
var DEFAULT_RETRY_AFTER_SECONDS = 60;
|
|
127972
|
+
var PERCENT_MULTIPLIER = 100;
|
|
127973
|
+
var EXHAUSTED_PERCENT = "100";
|
|
127974
|
+
var GEMINI_5H_KEYS = ["gemini-5h", "gemini_5h", "gemini"];
|
|
127975
|
+
var GEMINI_WEEKLY_KEYS = ["gemini-weekly", "gemini_weekly"];
|
|
127976
|
+
var THIRD_PARTY_5H_KEYS = ["3p-5h", "claude-5h", "3p_5h", "claude_5h", "claude"];
|
|
127977
|
+
var THIRD_PARTY_WEEKLY_KEYS = ["3p-weekly", "claude-weekly", "3p_weekly", "claude_weekly"];
|
|
127978
|
+
function findBucket(quota, keys) {
|
|
127979
|
+
for (const key of keys) {
|
|
127980
|
+
const bucket = quota[key];
|
|
127981
|
+
if (bucket !== void 0) {
|
|
127982
|
+
return bucket;
|
|
127983
|
+
}
|
|
127984
|
+
}
|
|
127985
|
+
return void 0;
|
|
127986
|
+
}
|
|
127987
|
+
function calculateUtilization(remainingFraction) {
|
|
127988
|
+
if (remainingFraction === void 0 || !Number.isFinite(remainingFraction)) {
|
|
127989
|
+
return void 0;
|
|
127990
|
+
}
|
|
127991
|
+
const clampedRem = Math.max(0, Math.min(1, remainingFraction));
|
|
127992
|
+
const used = Math.max(0, 1 - clampedRem);
|
|
127993
|
+
return String(Math.round(used * PERCENT_MULTIPLIER));
|
|
127994
|
+
}
|
|
127995
|
+
function calculateResetTimestamp(nowSec, resetInSeconds) {
|
|
127996
|
+
if (resetInSeconds === void 0 || !Number.isFinite(resetInSeconds) || resetInSeconds < 0) {
|
|
127997
|
+
return void 0;
|
|
127998
|
+
}
|
|
127999
|
+
return String(nowSec + Math.ceil(resetInSeconds));
|
|
128000
|
+
}
|
|
128001
|
+
function parseRetryAfterSeconds(raw, defaultSeconds = DEFAULT_RETRY_AFTER_SECONDS) {
|
|
128002
|
+
if (raw === null || raw === void 0 || raw.trim() === "") {
|
|
128003
|
+
return defaultSeconds;
|
|
128004
|
+
}
|
|
128005
|
+
const numeric = Number(raw);
|
|
128006
|
+
if (Number.isFinite(numeric) && numeric > 0) {
|
|
128007
|
+
return Math.ceil(numeric);
|
|
128008
|
+
}
|
|
128009
|
+
const parsedDate = Date.parse(raw);
|
|
128010
|
+
if (!Number.isNaN(parsedDate)) {
|
|
128011
|
+
const diffSec = Math.ceil((parsedDate - Date.now()) / MS_PER_SECOND8);
|
|
128012
|
+
return Math.max(1, diffSec);
|
|
128013
|
+
}
|
|
128014
|
+
return defaultSeconds;
|
|
128015
|
+
}
|
|
128016
|
+
function unifiedAntigravityQuotaHeaders(params) {
|
|
128017
|
+
const rejected = params.rejected === true;
|
|
128018
|
+
const nowSec = Math.floor(params.nowMs / MS_PER_SECOND8);
|
|
128019
|
+
const headers = {
|
|
128020
|
+
"anthropic-ratelimit-unified-status": rejected ? "rejected" : "allowed"
|
|
128021
|
+
};
|
|
128022
|
+
const modelLower = (params.model ?? "").toLowerCase();
|
|
128023
|
+
const isGemini = modelLower.includes("gemini");
|
|
128024
|
+
const fiveHourKeys = isGemini ? GEMINI_5H_KEYS : THIRD_PARTY_5H_KEYS;
|
|
128025
|
+
const weeklyKeys = isGemini ? GEMINI_WEEKLY_KEYS : THIRD_PARTY_WEEKLY_KEYS;
|
|
128026
|
+
const quota = params.quota ?? {};
|
|
128027
|
+
const b5h = findBucket(quota, fiveHourKeys);
|
|
128028
|
+
const bWk = findBucket(quota, weeklyKeys);
|
|
128029
|
+
const used5h = calculateUtilization(b5h?.remaining_fraction);
|
|
128030
|
+
const reset5h = calculateResetTimestamp(nowSec, b5h?.reset_in_seconds);
|
|
128031
|
+
const used7d = calculateUtilization(bWk?.remaining_fraction);
|
|
128032
|
+
const reset7d = calculateResetTimestamp(nowSec, bWk?.reset_in_seconds);
|
|
128033
|
+
let earliestResetSec;
|
|
128034
|
+
if (used5h !== void 0 && reset5h !== void 0) {
|
|
128035
|
+
headers["anthropic-ratelimit-unified-5h-utilization"] = used5h;
|
|
128036
|
+
headers["anthropic-ratelimit-unified-5h-reset"] = reset5h;
|
|
128037
|
+
earliestResetSec = Number(reset5h);
|
|
128038
|
+
}
|
|
128039
|
+
if (used7d !== void 0 && reset7d !== void 0) {
|
|
128040
|
+
headers["anthropic-ratelimit-unified-7d-utilization"] = used7d;
|
|
128041
|
+
headers["anthropic-ratelimit-unified-7d-reset"] = reset7d;
|
|
128042
|
+
const reset7dSec = Number(reset7d);
|
|
128043
|
+
earliestResetSec = earliestResetSec === void 0 ? reset7dSec : Math.min(earliestResetSec, reset7dSec);
|
|
128044
|
+
}
|
|
128045
|
+
if (rejected) {
|
|
128046
|
+
const retrySec = params.retryAfterSeconds ?? DEFAULT_RETRY_AFTER_SECONDS;
|
|
128047
|
+
const fallbackReset = String(nowSec + retrySec);
|
|
128048
|
+
if (headers["anthropic-ratelimit-unified-5h-utilization"] === void 0) {
|
|
128049
|
+
headers["anthropic-ratelimit-unified-5h-utilization"] = EXHAUSTED_PERCENT;
|
|
128050
|
+
headers["anthropic-ratelimit-unified-5h-reset"] = fallbackReset;
|
|
128051
|
+
}
|
|
128052
|
+
if (headers["anthropic-ratelimit-unified-7d-utilization"] === void 0) {
|
|
128053
|
+
headers["anthropic-ratelimit-unified-7d-utilization"] = EXHAUSTED_PERCENT;
|
|
128054
|
+
headers["anthropic-ratelimit-unified-7d-reset"] = fallbackReset;
|
|
128055
|
+
}
|
|
128056
|
+
earliestResetSec = earliestResetSec === void 0 ? nowSec + retrySec : Math.min(earliestResetSec, nowSec + retrySec);
|
|
128057
|
+
}
|
|
128058
|
+
if (earliestResetSec !== void 0) {
|
|
128059
|
+
headers["anthropic-ratelimit-unified-reset"] = String(earliestResetSec);
|
|
128060
|
+
}
|
|
128061
|
+
return headers;
|
|
128062
|
+
}
|
|
128063
|
+
function isRecord9(value2) {
|
|
128064
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
128065
|
+
}
|
|
128066
|
+
function bucketToEntry(bucket, nowMs) {
|
|
128067
|
+
if (!isRecord9(bucket) || typeof bucket.bucketId !== "string") {
|
|
128068
|
+
return void 0;
|
|
128069
|
+
}
|
|
128070
|
+
const remainingFraction = typeof bucket.remainingFraction === "number" && Number.isFinite(bucket.remainingFraction) ? bucket.remainingFraction : void 0;
|
|
128071
|
+
const resetMs = typeof bucket.resetTime === "string" ? Date.parse(bucket.resetTime) : Number.NaN;
|
|
128072
|
+
const resetInSeconds = Number.isNaN(resetMs) ? void 0 : Math.max(0, Math.ceil((resetMs - nowMs) / MS_PER_SECOND8));
|
|
128073
|
+
if (remainingFraction === void 0 && resetInSeconds === void 0) {
|
|
128074
|
+
return void 0;
|
|
128075
|
+
}
|
|
128076
|
+
return {
|
|
128077
|
+
key: bucket.bucketId,
|
|
128078
|
+
entry: {
|
|
128079
|
+
...remainingFraction === void 0 ? {} : { remaining_fraction: remainingFraction },
|
|
128080
|
+
...resetInSeconds === void 0 ? {} : { reset_in_seconds: resetInSeconds }
|
|
128081
|
+
}
|
|
128082
|
+
};
|
|
128083
|
+
}
|
|
128084
|
+
async function fetchAntigravityQuotaSummary(params) {
|
|
128085
|
+
const fetchFn = params.fetchFn ?? fetch;
|
|
128086
|
+
let response;
|
|
128087
|
+
try {
|
|
128088
|
+
response = await fetchFn(`${params.endpoint ?? CCPA_ENDPOINT}/v1internal:retrieveUserQuotaSummary`, {
|
|
128089
|
+
method: "POST",
|
|
128090
|
+
headers: {
|
|
128091
|
+
"Content-Type": "application/json",
|
|
128092
|
+
Authorization: `Bearer ${params.token}`,
|
|
128093
|
+
"User-Agent": CCPA_USER_AGENT
|
|
128094
|
+
},
|
|
128095
|
+
body: JSON.stringify({ project: params.projectId ?? CCPA_DEFAULT_PROJECT_ID })
|
|
128096
|
+
});
|
|
128097
|
+
} catch {
|
|
128098
|
+
return void 0;
|
|
128099
|
+
}
|
|
128100
|
+
if (!response.ok) {
|
|
128101
|
+
return void 0;
|
|
128102
|
+
}
|
|
128103
|
+
let parsed;
|
|
128104
|
+
try {
|
|
128105
|
+
parsed = await response.json();
|
|
128106
|
+
} catch {
|
|
128107
|
+
return void 0;
|
|
128108
|
+
}
|
|
128109
|
+
if (!isRecord9(parsed) || !Array.isArray(parsed.groups)) {
|
|
128110
|
+
return void 0;
|
|
128111
|
+
}
|
|
128112
|
+
const map2 = {};
|
|
128113
|
+
for (const group of parsed.groups) {
|
|
128114
|
+
if (!isRecord9(group) || !Array.isArray(group.buckets)) {
|
|
128115
|
+
continue;
|
|
128116
|
+
}
|
|
128117
|
+
for (const bucket of group.buckets) {
|
|
128118
|
+
const read = bucketToEntry(bucket, params.nowMs);
|
|
128119
|
+
if (read !== void 0) {
|
|
128120
|
+
map2[read.key] = read.entry;
|
|
128121
|
+
}
|
|
128122
|
+
}
|
|
128123
|
+
}
|
|
128124
|
+
return Object.keys(map2).length > 0 ? map2 : void 0;
|
|
128125
|
+
}
|
|
128126
|
+
var ANTIGRAVITY_QUOTA_REFRESH_MS = 6e4;
|
|
128127
|
+
function createCachedAntigravityQuotaSource(params) {
|
|
128128
|
+
let cachedAt = Number.NEGATIVE_INFINITY;
|
|
128129
|
+
let cached2;
|
|
128130
|
+
let refresh;
|
|
128131
|
+
const refreshMs = params.refreshMs ?? ANTIGRAVITY_QUOTA_REFRESH_MS;
|
|
128132
|
+
const run = async () => {
|
|
128133
|
+
const nowMs = params.now();
|
|
128134
|
+
const read = await params.fetchSummary(nowMs);
|
|
128135
|
+
if (read !== void 0) {
|
|
128136
|
+
cached2 = read;
|
|
128137
|
+
}
|
|
128138
|
+
cachedAt = params.now();
|
|
128139
|
+
};
|
|
128140
|
+
return () => {
|
|
128141
|
+
const nowMs = params.now();
|
|
128142
|
+
if (nowMs - cachedAt < refreshMs) {
|
|
128143
|
+
return cached2;
|
|
128144
|
+
}
|
|
128145
|
+
refresh ??= run().finally(() => {
|
|
128146
|
+
refresh = void 0;
|
|
128147
|
+
});
|
|
128148
|
+
return cached2;
|
|
128149
|
+
};
|
|
128150
|
+
}
|
|
128151
|
+
|
|
127723
128152
|
// src/frontdoor/providerRoute.ts
|
|
127724
128153
|
init_credential();
|
|
127725
128154
|
init_providersStore();
|
|
@@ -127856,10 +128285,10 @@ function quotaHeaders(upstream) {
|
|
|
127856
128285
|
}
|
|
127857
128286
|
return headers;
|
|
127858
128287
|
}
|
|
127859
|
-
var
|
|
128288
|
+
var EXHAUSTED_PERCENT2 = "100";
|
|
127860
128289
|
function unifiedQuotaHeaders(upstream, rejected, quotaError) {
|
|
127861
128290
|
const headers = { "anthropic-ratelimit-unified-status": rejected ? "rejected" : "allowed" };
|
|
127862
|
-
const used7d = upstream.get("x-codex-primary-used-percent") ?? (rejected ?
|
|
128291
|
+
const used7d = upstream.get("x-codex-primary-used-percent") ?? (rejected ? EXHAUSTED_PERCENT2 : null);
|
|
127863
128292
|
const reset7d = upstream.get("x-codex-primary-reset-at") ?? (quotaError?.resets_at === void 0 ? null : String(quotaError.resets_at));
|
|
127864
128293
|
if (used7d !== null && reset7d !== null) {
|
|
127865
128294
|
headers["anthropic-ratelimit-unified-7d-utilization"] = used7d;
|
|
@@ -127880,17 +128309,17 @@ function unifiedQuotaHeaders(upstream, rejected, quotaError) {
|
|
|
127880
128309
|
}
|
|
127881
128310
|
return headers;
|
|
127882
128311
|
}
|
|
127883
|
-
var
|
|
128312
|
+
var MS_PER_SECOND9 = 1e3;
|
|
127884
128313
|
function buildUsageSnapshot(upstream, quotaError, nowMs) {
|
|
127885
|
-
const used7 = upstream.get("x-codex-primary-used-percent") ?? (quotaError === void 0 ? null :
|
|
128314
|
+
const used7 = upstream.get("x-codex-primary-used-percent") ?? (quotaError === void 0 ? null : EXHAUSTED_PERCENT2);
|
|
127886
128315
|
const reset7 = upstream.get("x-codex-primary-reset-at") ?? (quotaError?.resets_at === void 0 ? null : String(quotaError.resets_at));
|
|
127887
|
-
const sevenDay = used7 !== null && reset7 !== null ? { used_percentage: Number(used7), resets_at: new Date(Number(reset7) *
|
|
128316
|
+
const sevenDay = used7 !== null && reset7 !== null ? { used_percentage: Number(used7), resets_at: new Date(Number(reset7) * MS_PER_SECOND9).toISOString() } : void 0;
|
|
127888
128317
|
let fiveHour;
|
|
127889
128318
|
if (Number(upstream.get("x-codex-secondary-window-minutes")) > 0) {
|
|
127890
128319
|
const used5 = upstream.get("x-codex-secondary-used-percent");
|
|
127891
128320
|
const reset5 = upstream.get("x-codex-secondary-reset-at");
|
|
127892
128321
|
if (used5 !== null && reset5 !== null) {
|
|
127893
|
-
fiveHour = { used_percentage: Number(used5), resets_at: new Date(Number(reset5) *
|
|
128322
|
+
fiveHour = { used_percentage: Number(used5), resets_at: new Date(Number(reset5) * MS_PER_SECOND9).toISOString() };
|
|
127894
128323
|
}
|
|
127895
128324
|
}
|
|
127896
128325
|
if (sevenDay === void 0 && fiveHour === void 0) {
|
|
@@ -128313,7 +128742,7 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
128313
128742
|
}
|
|
128314
128743
|
|
|
128315
128744
|
// src/antigravity/route.ts
|
|
128316
|
-
var
|
|
128745
|
+
var import_node_crypto22 = require("node:crypto");
|
|
128317
128746
|
init_route();
|
|
128318
128747
|
|
|
128319
128748
|
// src/antigravity/relay.ts
|
|
@@ -128384,7 +128813,7 @@ function createAntigravityRelay(params) {
|
|
|
128384
128813
|
const candidate = chunk.candidates?.[0];
|
|
128385
128814
|
if (candidate?.content?.parts !== void 0) {
|
|
128386
128815
|
for (const part of candidate.content.parts) {
|
|
128387
|
-
if ("text" in part && typeof part.text === "string" && part.text.length > 0) {
|
|
128816
|
+
if ("text" in part && typeof part.text === "string" && (part.thoughtSignature === void 0 || part.text.length > 0)) {
|
|
128388
128817
|
if (activeBlockType !== "text") {
|
|
128389
128818
|
closeActiveBlock();
|
|
128390
128819
|
currentBlockIndex += 1;
|
|
@@ -128414,6 +128843,9 @@ function createAntigravityRelay(params) {
|
|
|
128414
128843
|
const callName = part.functionCall.name;
|
|
128415
128844
|
const originalName = params.toolNames.get(callName) ?? callName;
|
|
128416
128845
|
const callId = params.fallbackId();
|
|
128846
|
+
if (typeof part.thoughtSignature === "string") {
|
|
128847
|
+
rememberToolCallSignature(callId, part.thoughtSignature);
|
|
128848
|
+
}
|
|
128417
128849
|
frames.push({
|
|
128418
128850
|
event: "content_block_start",
|
|
128419
128851
|
data: {
|
|
@@ -128487,82 +128919,6 @@ function createAntigravityRelay(params) {
|
|
|
128487
128919
|
return { pushChunk, finish };
|
|
128488
128920
|
}
|
|
128489
128921
|
|
|
128490
|
-
// src/antigravity/cloudUpstream.ts
|
|
128491
|
-
var GEMINI_API_BASE_URL = "https://generativelanguage.googleapis.com";
|
|
128492
|
-
function buildCloudUrl(config2, model) {
|
|
128493
|
-
const { cloud } = config2;
|
|
128494
|
-
if (cloud.projectId !== void 0 && cloud.location !== void 0) {
|
|
128495
|
-
const base2 = cloud.endpoint ?? `https://${cloud.location}-aiplatform.googleapis.com`;
|
|
128496
|
-
return `${base2}/v1/projects/${cloud.projectId}/locations/${cloud.location}/publishers/google/models/${encodeURIComponent(model)}:streamGenerateContent?alt=sse`;
|
|
128497
|
-
}
|
|
128498
|
-
const base = cloud.endpoint ?? GEMINI_API_BASE_URL;
|
|
128499
|
-
return `${base}/v1beta/models/${encodeURIComponent(model)}:streamGenerateContent?alt=sse`;
|
|
128500
|
-
}
|
|
128501
|
-
function buildCloudHeaders(token, credentialTarget) {
|
|
128502
|
-
const headers = {
|
|
128503
|
-
"Content-Type": "application/json",
|
|
128504
|
-
Accept: "text/event-stream"
|
|
128505
|
-
};
|
|
128506
|
-
if (credentialTarget === "apiKey") {
|
|
128507
|
-
headers["x-goog-api-key"] = token;
|
|
128508
|
-
} else {
|
|
128509
|
-
headers.Authorization = `Bearer ${token}`;
|
|
128510
|
-
}
|
|
128511
|
-
return headers;
|
|
128512
|
-
}
|
|
128513
|
-
var AntigravityUpstreamError = class extends Error {
|
|
128514
|
-
status;
|
|
128515
|
-
retryAfter;
|
|
128516
|
-
constructor(status, message, retryAfter) {
|
|
128517
|
-
super(`Google Antigravity API error (${String(status)}): ${message}`);
|
|
128518
|
-
this.name = "AntigravityUpstreamError";
|
|
128519
|
-
this.status = status;
|
|
128520
|
-
this.retryAfter = retryAfter;
|
|
128521
|
-
}
|
|
128522
|
-
};
|
|
128523
|
-
async function* callCloudAntigravity(params, fetchFn = fetch) {
|
|
128524
|
-
const url2 = buildCloudUrl(params.config, params.model);
|
|
128525
|
-
const headers = buildCloudHeaders(params.token, params.credentialTarget);
|
|
128526
|
-
const response = await fetchFn(url2, {
|
|
128527
|
-
method: "POST",
|
|
128528
|
-
headers,
|
|
128529
|
-
body: JSON.stringify(params.request),
|
|
128530
|
-
signal: params.signal
|
|
128531
|
-
});
|
|
128532
|
-
if (!response.ok) {
|
|
128533
|
-
const errorText = await response.text();
|
|
128534
|
-
const retryAfter = response.headers.get("retry-after");
|
|
128535
|
-
throw new AntigravityUpstreamError(response.status, errorText, retryAfter);
|
|
128536
|
-
}
|
|
128537
|
-
if (response.body === null) {
|
|
128538
|
-
return;
|
|
128539
|
-
}
|
|
128540
|
-
const decoder = new TextDecoder("utf-8");
|
|
128541
|
-
let buffer2 = "";
|
|
128542
|
-
const sseDataPrefix = "data:";
|
|
128543
|
-
for await (const rawChunk of response.body) {
|
|
128544
|
-
const chunk = rawChunk instanceof Uint8Array ? rawChunk : Buffer.from(String(rawChunk));
|
|
128545
|
-
buffer2 += decoder.decode(chunk, { stream: true });
|
|
128546
|
-
const lines = buffer2.split("\n");
|
|
128547
|
-
buffer2 = lines.pop() ?? "";
|
|
128548
|
-
for (const line of lines) {
|
|
128549
|
-
const trimmed = line.trim();
|
|
128550
|
-
if (trimmed.startsWith(sseDataPrefix)) {
|
|
128551
|
-
const jsonStr = trimmed.slice(sseDataPrefix.length).trim();
|
|
128552
|
-
if (jsonStr.length > 0) {
|
|
128553
|
-
try {
|
|
128554
|
-
const parsed = JSON.parse(jsonStr);
|
|
128555
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
128556
|
-
yield parsed;
|
|
128557
|
-
}
|
|
128558
|
-
} catch {
|
|
128559
|
-
}
|
|
128560
|
-
}
|
|
128561
|
-
}
|
|
128562
|
-
}
|
|
128563
|
-
}
|
|
128564
|
-
}
|
|
128565
|
-
|
|
128566
128922
|
// src/antigravity/localUpstream.ts
|
|
128567
128923
|
var import_node_child_process6 = require("node:child_process");
|
|
128568
128924
|
var import_node_net2 = __toESM(require("node:net"), 1);
|
|
@@ -128631,7 +128987,7 @@ var AcpStreamMessageSchema = external_exports.looseObject({
|
|
|
128631
128987
|
chunk: external_exports.looseObject({}).optional()
|
|
128632
128988
|
}).optional()
|
|
128633
128989
|
});
|
|
128634
|
-
function
|
|
128990
|
+
function isRecord10(value2) {
|
|
128635
128991
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
128636
128992
|
}
|
|
128637
128993
|
function normalizeFinishReason(reason) {
|
|
@@ -128656,7 +129012,7 @@ function parseJsonRecord(raw) {
|
|
|
128656
129012
|
}
|
|
128657
129013
|
try {
|
|
128658
129014
|
const parsed = JSON.parse(raw);
|
|
128659
|
-
if (
|
|
129015
|
+
if (isRecord10(parsed)) {
|
|
128660
129016
|
return parsed;
|
|
128661
129017
|
}
|
|
128662
129018
|
} catch {
|
|
@@ -128742,104 +129098,9 @@ async function* callLocalAntigravity(params) {
|
|
|
128742
129098
|
}
|
|
128743
129099
|
}
|
|
128744
129100
|
|
|
128745
|
-
// src/antigravity/quota.ts
|
|
128746
|
-
var MS_PER_SECOND9 = 1e3;
|
|
128747
|
-
var DEFAULT_RETRY_AFTER_SECONDS = 60;
|
|
128748
|
-
var PERCENT_MULTIPLIER = 100;
|
|
128749
|
-
var EXHAUSTED_PERCENT2 = "100";
|
|
128750
|
-
var GEMINI_5H_KEYS = ["gemini-5h", "gemini_5h", "gemini"];
|
|
128751
|
-
var GEMINI_WEEKLY_KEYS = ["gemini-weekly", "gemini_weekly"];
|
|
128752
|
-
var THIRD_PARTY_5H_KEYS = ["3p-5h", "claude-5h", "3p_5h", "claude_5h", "claude"];
|
|
128753
|
-
var THIRD_PARTY_WEEKLY_KEYS = ["3p-weekly", "claude-weekly", "3p_weekly", "claude_weekly"];
|
|
128754
|
-
function findBucket(quota, keys) {
|
|
128755
|
-
for (const key of keys) {
|
|
128756
|
-
const bucket = quota[key];
|
|
128757
|
-
if (bucket !== void 0) {
|
|
128758
|
-
return bucket;
|
|
128759
|
-
}
|
|
128760
|
-
}
|
|
128761
|
-
return void 0;
|
|
128762
|
-
}
|
|
128763
|
-
function calculateUtilization(remainingFraction) {
|
|
128764
|
-
if (remainingFraction === void 0 || !Number.isFinite(remainingFraction)) {
|
|
128765
|
-
return void 0;
|
|
128766
|
-
}
|
|
128767
|
-
const clampedRem = Math.max(0, Math.min(1, remainingFraction));
|
|
128768
|
-
const used = Math.max(0, 1 - clampedRem);
|
|
128769
|
-
return String(Math.round(used * PERCENT_MULTIPLIER));
|
|
128770
|
-
}
|
|
128771
|
-
function calculateResetTimestamp(nowSec, resetInSeconds) {
|
|
128772
|
-
if (resetInSeconds === void 0 || !Number.isFinite(resetInSeconds) || resetInSeconds < 0) {
|
|
128773
|
-
return void 0;
|
|
128774
|
-
}
|
|
128775
|
-
return String(nowSec + Math.ceil(resetInSeconds));
|
|
128776
|
-
}
|
|
128777
|
-
function parseRetryAfterSeconds(raw, defaultSeconds = DEFAULT_RETRY_AFTER_SECONDS) {
|
|
128778
|
-
if (raw === null || raw === void 0 || raw.trim() === "") {
|
|
128779
|
-
return defaultSeconds;
|
|
128780
|
-
}
|
|
128781
|
-
const numeric = Number(raw);
|
|
128782
|
-
if (Number.isFinite(numeric) && numeric > 0) {
|
|
128783
|
-
return Math.ceil(numeric);
|
|
128784
|
-
}
|
|
128785
|
-
const parsedDate = Date.parse(raw);
|
|
128786
|
-
if (!Number.isNaN(parsedDate)) {
|
|
128787
|
-
const diffSec = Math.ceil((parsedDate - Date.now()) / MS_PER_SECOND9);
|
|
128788
|
-
return Math.max(1, diffSec);
|
|
128789
|
-
}
|
|
128790
|
-
return defaultSeconds;
|
|
128791
|
-
}
|
|
128792
|
-
function unifiedAntigravityQuotaHeaders(params) {
|
|
128793
|
-
const rejected = params.rejected === true;
|
|
128794
|
-
const nowSec = Math.floor(params.nowMs / MS_PER_SECOND9);
|
|
128795
|
-
const headers = {
|
|
128796
|
-
"anthropic-ratelimit-unified-status": rejected ? "rejected" : "allowed"
|
|
128797
|
-
};
|
|
128798
|
-
const modelLower = (params.model ?? "").toLowerCase();
|
|
128799
|
-
const isGemini = modelLower.includes("gemini");
|
|
128800
|
-
const fiveHourKeys = isGemini ? GEMINI_5H_KEYS : THIRD_PARTY_5H_KEYS;
|
|
128801
|
-
const weeklyKeys = isGemini ? GEMINI_WEEKLY_KEYS : THIRD_PARTY_WEEKLY_KEYS;
|
|
128802
|
-
const quota = params.quota ?? {};
|
|
128803
|
-
const b5h = findBucket(quota, fiveHourKeys);
|
|
128804
|
-
const bWk = findBucket(quota, weeklyKeys);
|
|
128805
|
-
const used5h = calculateUtilization(b5h?.remaining_fraction);
|
|
128806
|
-
const reset5h = calculateResetTimestamp(nowSec, b5h?.reset_in_seconds);
|
|
128807
|
-
const used7d = calculateUtilization(bWk?.remaining_fraction);
|
|
128808
|
-
const reset7d = calculateResetTimestamp(nowSec, bWk?.reset_in_seconds);
|
|
128809
|
-
let earliestResetSec;
|
|
128810
|
-
if (used5h !== void 0 && reset5h !== void 0) {
|
|
128811
|
-
headers["anthropic-ratelimit-unified-5h-utilization"] = used5h;
|
|
128812
|
-
headers["anthropic-ratelimit-unified-5h-reset"] = reset5h;
|
|
128813
|
-
earliestResetSec = Number(reset5h);
|
|
128814
|
-
}
|
|
128815
|
-
if (used7d !== void 0 && reset7d !== void 0) {
|
|
128816
|
-
headers["anthropic-ratelimit-unified-7d-utilization"] = used7d;
|
|
128817
|
-
headers["anthropic-ratelimit-unified-7d-reset"] = reset7d;
|
|
128818
|
-
const reset7dSec = Number(reset7d);
|
|
128819
|
-
earliestResetSec = earliestResetSec === void 0 ? reset7dSec : Math.min(earliestResetSec, reset7dSec);
|
|
128820
|
-
}
|
|
128821
|
-
if (rejected) {
|
|
128822
|
-
const retrySec = params.retryAfterSeconds ?? DEFAULT_RETRY_AFTER_SECONDS;
|
|
128823
|
-
const fallbackReset = String(nowSec + retrySec);
|
|
128824
|
-
if (headers["anthropic-ratelimit-unified-5h-utilization"] === void 0) {
|
|
128825
|
-
headers["anthropic-ratelimit-unified-5h-utilization"] = EXHAUSTED_PERCENT2;
|
|
128826
|
-
headers["anthropic-ratelimit-unified-5h-reset"] = fallbackReset;
|
|
128827
|
-
}
|
|
128828
|
-
if (headers["anthropic-ratelimit-unified-7d-utilization"] === void 0) {
|
|
128829
|
-
headers["anthropic-ratelimit-unified-7d-utilization"] = EXHAUSTED_PERCENT2;
|
|
128830
|
-
headers["anthropic-ratelimit-unified-7d-reset"] = fallbackReset;
|
|
128831
|
-
}
|
|
128832
|
-
earliestResetSec = earliestResetSec === void 0 ? nowSec + retrySec : Math.min(earliestResetSec, nowSec + retrySec);
|
|
128833
|
-
}
|
|
128834
|
-
if (earliestResetSec !== void 0) {
|
|
128835
|
-
headers["anthropic-ratelimit-unified-reset"] = String(earliestResetSec);
|
|
128836
|
-
}
|
|
128837
|
-
return headers;
|
|
128838
|
-
}
|
|
128839
|
-
|
|
128840
129101
|
// src/antigravity/route.ts
|
|
128841
129102
|
function createAntigravityRoute(ports) {
|
|
128842
|
-
const fallbackId = ports.fallbackId ?? (() => (0,
|
|
129103
|
+
const fallbackId = ports.fallbackId ?? (() => (0, import_node_crypto22.randomUUID)());
|
|
128843
129104
|
return async (request7) => {
|
|
128844
129105
|
await Promise.resolve();
|
|
128845
129106
|
if (request7.method !== "POST") {
|
|
@@ -129240,9 +129501,43 @@ async function scanRequestHead(request7, wholeBody = false) {
|
|
|
129240
129501
|
}
|
|
129241
129502
|
|
|
129242
129503
|
// src/frontdoor/providerRoute.ts
|
|
129504
|
+
var isRcSelfHostPath = (path59) => path59 === "/v1/code/sessions" || path59.startsWith("/v1/code/sessions/") || path59 === "/v1/sessions" || path59.startsWith("/v1/sessions/");
|
|
129505
|
+
function scopeSessionProviderPath(request7) {
|
|
129506
|
+
if (request7.session.provider === void 0) {
|
|
129507
|
+
return request7;
|
|
129508
|
+
}
|
|
129509
|
+
const path59 = new URL(request7.url, "http://127.0.0.1").pathname;
|
|
129510
|
+
if (!path59.startsWith("/v1/") || isRcSelfHostPath(path59)) {
|
|
129511
|
+
return request7;
|
|
129512
|
+
}
|
|
129513
|
+
return { ...request7, url: `${PROVIDER_PATH_PREFIX}${encodeURIComponent(request7.session.provider)}${request7.url}` };
|
|
129514
|
+
}
|
|
129243
129515
|
function createProviderRouteResolver(deps) {
|
|
129244
|
-
const isRcSelfHostPath = (path59) => path59 === "/v1/code/sessions" || path59.startsWith("/v1/code/sessions/") || path59 === "/v1/sessions" || path59.startsWith("/v1/sessions/");
|
|
129245
129516
|
const oauthRoute = createPassthroughRoute("anthropic", { baseUrl: `https://${CONNECT_INTERCEPT_HOST}:${String(HTTPS_PORT)}`, stripPrefix: void 0, headroomUpstream: void 0 });
|
|
129517
|
+
const antigravityQuotaSources = /* @__PURE__ */ new Map();
|
|
129518
|
+
const antigravityQuotaOf = (provider, definition, config2) => {
|
|
129519
|
+
const existing = antigravityQuotaSources.get(provider);
|
|
129520
|
+
if (existing !== void 0) {
|
|
129521
|
+
return existing;
|
|
129522
|
+
}
|
|
129523
|
+
const source = createCachedAntigravityQuotaSource({
|
|
129524
|
+
now: () => Date.now(),
|
|
129525
|
+
fetchSummary: async (nowMs) => {
|
|
129526
|
+
const res = resolveCredential({ credential: definition.credential, env: deps.env, port: deps.credentials, subject: `provider ${provider}` });
|
|
129527
|
+
if (!res.ok) {
|
|
129528
|
+
return void 0;
|
|
129529
|
+
}
|
|
129530
|
+
return fetchAntigravityQuotaSummary({
|
|
129531
|
+
token: res.credential.token,
|
|
129532
|
+
endpoint: config2.cloud.endpoint ?? void 0,
|
|
129533
|
+
projectId: config2.cloud.projectId ?? void 0,
|
|
129534
|
+
nowMs
|
|
129535
|
+
});
|
|
129536
|
+
}
|
|
129537
|
+
});
|
|
129538
|
+
antigravityQuotaSources.set(provider, source);
|
|
129539
|
+
return source;
|
|
129540
|
+
};
|
|
129246
129541
|
const passthroughByTarget = /* @__PURE__ */ new Map();
|
|
129247
129542
|
const passthroughFor = (name, target) => {
|
|
129248
129543
|
const key = `${name}\0${target.baseUrl}\0${target.stripPrefix ?? ""}\0${target.headroomUpstream ?? ""}`;
|
|
@@ -129261,9 +129556,6 @@ function createProviderRouteResolver(deps) {
|
|
|
129261
129556
|
if (deps.rcSelfHostRoute !== void 0 && isRcSelfHostPath(path59)) {
|
|
129262
129557
|
return { ok: true, route: deps.rcSelfHostRoute };
|
|
129263
129558
|
}
|
|
129264
|
-
if (request7.session.provider !== void 0 && path59.startsWith("/v1/") && !isRcSelfHostPath(path59)) {
|
|
129265
|
-
return resolve2({ ...request7, url: `${PROVIDER_PATH_PREFIX}${encodeURIComponent(request7.session.provider)}${request7.url}` });
|
|
129266
|
-
}
|
|
129267
129559
|
return path59.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path59}` };
|
|
129268
129560
|
}
|
|
129269
129561
|
const { provider } = scoped;
|
|
@@ -129313,7 +129605,8 @@ function createProviderRouteResolver(deps) {
|
|
|
129313
129605
|
token: res.credential.token,
|
|
129314
129606
|
credentialTarget: antigravityProvider.credential.target
|
|
129315
129607
|
};
|
|
129316
|
-
}
|
|
129608
|
+
},
|
|
129609
|
+
quotaSource: antigravityQuotaOf(provider, antigravityProvider, config2)
|
|
129317
129610
|
},
|
|
129318
129611
|
directOrigin2(deps.directPort()),
|
|
129319
129612
|
provider
|
|
@@ -129343,7 +129636,9 @@ function createProviderRouteResolver(deps) {
|
|
|
129343
129636
|
}
|
|
129344
129637
|
});
|
|
129345
129638
|
return async (request7) => {
|
|
129346
|
-
|
|
129639
|
+
const scopedRequest = scopeSessionProviderPath(request7);
|
|
129640
|
+
const serveScoped = (resolution) => scopedRequest === request7 ? resolution : { ok: true, route: servingRewritten(resolution.route, scopedRequest) };
|
|
129641
|
+
let current = scopedRequest;
|
|
129347
129642
|
let replay;
|
|
129348
129643
|
const visited = /* @__PURE__ */ new Set();
|
|
129349
129644
|
for (; ; ) {
|
|
@@ -129365,7 +129660,7 @@ function createProviderRouteResolver(deps) {
|
|
|
129365
129660
|
}
|
|
129366
129661
|
if (routes === void 0 || routes.length === 0) {
|
|
129367
129662
|
const resolution = resolve2(current);
|
|
129368
|
-
return resolution.ok && replay !== void 0 ? { ok: true, route: servingRewritten(resolution.route, { ...replay, url: current.url }) } : resolution;
|
|
129663
|
+
return resolution.ok && replay !== void 0 ? { ok: true, route: servingRewritten(resolution.route, { ...replay, url: current.url }) } : resolution.ok ? serveScoped(resolution) : resolution;
|
|
129369
129664
|
}
|
|
129370
129665
|
const whole = routes.some((entry) => entry.model !== void 0 || referencesFact(entry.when, "request.hasImage"));
|
|
129371
129666
|
const snapshot = deps.usageSnapshotOf?.(current.session.identity);
|
|
@@ -129377,7 +129672,7 @@ function createProviderRouteResolver(deps) {
|
|
|
129377
129672
|
const scan = await scanRequestHead(current, whole);
|
|
129378
129673
|
if (scan.replayed === void 0) {
|
|
129379
129674
|
const resolution = resolve2(current);
|
|
129380
|
-
return resolution.ok && replay !== void 0 ? { ok: true, route: servingRewritten(resolution.route, { ...replay, url: current.url }) } : resolution;
|
|
129675
|
+
return resolution.ok && replay !== void 0 ? { ok: true, route: servingRewritten(resolution.route, { ...replay, url: current.url }) } : resolution.ok ? serveScoped(resolution) : resolution;
|
|
129381
129676
|
}
|
|
129382
129677
|
replay = scan.replayed;
|
|
129383
129678
|
const requestFacts = {
|
|
@@ -129439,7 +129734,7 @@ function attachingProviderCredential(route, deps) {
|
|
|
129439
129734
|
init_realFrontDoorPort();
|
|
129440
129735
|
|
|
129441
129736
|
// src/frontdoor/rcCommands.ts
|
|
129442
|
-
var
|
|
129737
|
+
var import_node_crypto23 = require("node:crypto");
|
|
129443
129738
|
init_commandDeps();
|
|
129444
129739
|
init_cliError();
|
|
129445
129740
|
init_realPorts();
|
|
@@ -129478,15 +129773,15 @@ function readFrontDoorControlMaterial(fsPort, paths, purpose) {
|
|
|
129478
129773
|
|
|
129479
129774
|
// src/frontdoor/rcLiveUsage.ts
|
|
129480
129775
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
129481
|
-
function
|
|
129776
|
+
function isRecord11(value2) {
|
|
129482
129777
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
129483
129778
|
}
|
|
129484
129779
|
function rcRateLimitInfoOf(event) {
|
|
129485
129780
|
const payload = event.envelope.payload;
|
|
129486
|
-
if (!
|
|
129781
|
+
if (!isRecord11(payload) || payload.type !== RC_RATE_LIMIT_EVENT_TYPE) {
|
|
129487
129782
|
return void 0;
|
|
129488
129783
|
}
|
|
129489
|
-
if (!
|
|
129784
|
+
if (!isRecord11(payload.rate_limit_info)) {
|
|
129490
129785
|
return void 0;
|
|
129491
129786
|
}
|
|
129492
129787
|
const parsed = RcRateLimitInfoSchema.safeParse(payload.rate_limit_info);
|
|
@@ -129522,7 +129817,7 @@ var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:
|
|
|
129522
129817
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
129523
129818
|
var MS_PER_SECOND10 = 1e3;
|
|
129524
129819
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
129525
|
-
function
|
|
129820
|
+
function isRecord12(value2) {
|
|
129526
129821
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
129527
129822
|
}
|
|
129528
129823
|
function parseJsonObject2(body) {
|
|
@@ -129532,7 +129827,7 @@ function parseJsonObject2(body) {
|
|
|
129532
129827
|
} catch {
|
|
129533
129828
|
return void 0;
|
|
129534
129829
|
}
|
|
129535
|
-
return
|
|
129830
|
+
return isRecord12(parsed) ? parsed : void 0;
|
|
129536
129831
|
}
|
|
129537
129832
|
function growthBookFeatures() {
|
|
129538
129833
|
return {
|
|
@@ -129626,7 +129921,7 @@ var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
|
129626
129921
|
var RC_SELF_HOST_RECORD_FILE = "credential.json";
|
|
129627
129922
|
var SELF_HOST_EMAIL = "selfhost@agent-shim.invalid";
|
|
129628
129923
|
var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
129629
|
-
function
|
|
129924
|
+
function isRecord13(value2) {
|
|
129630
129925
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
129631
129926
|
}
|
|
129632
129927
|
function readJsonObject(fs24, file2) {
|
|
@@ -129640,7 +129935,7 @@ function readJsonObject(fs24, file2) {
|
|
|
129640
129935
|
} catch {
|
|
129641
129936
|
return void 0;
|
|
129642
129937
|
}
|
|
129643
|
-
return
|
|
129938
|
+
return isRecord13(parsed) ? parsed : void 0;
|
|
129644
129939
|
}
|
|
129645
129940
|
function readRcSelfHostRecord(fs24, frontdoorDir) {
|
|
129646
129941
|
const parsed = readJsonObject(fs24, import_node_path49.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
@@ -129664,7 +129959,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
129664
129959
|
const recordFile = import_node_path49.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
129665
129960
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
129666
129961
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
129667
|
-
const existingOauth =
|
|
129962
|
+
const existingOauth = isRecord13(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
129668
129963
|
const existingToken = typeof existingOauth?.accessToken === "string" && existingOauth.accessToken !== "" ? existingOauth.accessToken : void 0;
|
|
129669
129964
|
const existingIsOwn = existingToken !== void 0 && previousRecord?.accessToken === existingToken;
|
|
129670
129965
|
if (existingToken !== void 0 && !existingIsOwn && !deps.force) {
|
|
@@ -129681,7 +129976,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
129681
129976
|
deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
|
|
129682
129977
|
`);
|
|
129683
129978
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
129684
|
-
const existingBlock = (value2) =>
|
|
129979
|
+
const existingBlock = (value2) => isRecord13(value2) ? value2 : {};
|
|
129685
129980
|
deps.fs.writeFilePrivate(claudeJsonFile, `${JSON.stringify({
|
|
129686
129981
|
...claudeJson,
|
|
129687
129982
|
oauthAccount: {
|
|
@@ -130046,8 +130341,8 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
130046
130341
|
identitiesDir: paths.identitiesDir,
|
|
130047
130342
|
frontdoorDir: paths.frontdoorDir,
|
|
130048
130343
|
identity,
|
|
130049
|
-
newUuid:
|
|
130050
|
-
randomToken: () => (0,
|
|
130344
|
+
newUuid: import_node_crypto23.randomUUID,
|
|
130345
|
+
randomToken: () => (0, import_node_crypto23.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
130051
130346
|
force: options.force === true,
|
|
130052
130347
|
now: () => Date.now()
|
|
130053
130348
|
});
|
|
@@ -130068,11 +130363,11 @@ var import_node_path50 = __toESM(require("node:path"), 1);
|
|
|
130068
130363
|
function isSafeSessionId(sessionId) {
|
|
130069
130364
|
return /^[A-Za-z0-9_-]+$/.test(sessionId);
|
|
130070
130365
|
}
|
|
130071
|
-
function
|
|
130366
|
+
function isRecord14(value2) {
|
|
130072
130367
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
130073
130368
|
}
|
|
130074
130369
|
function credentialOfJson(parsed) {
|
|
130075
|
-
if (!
|
|
130370
|
+
if (!isRecord14(parsed)) {
|
|
130076
130371
|
return void 0;
|
|
130077
130372
|
}
|
|
130078
130373
|
const { authorization, anthropicVersion, anthropicClientPlatform } = parsed;
|
|
@@ -130102,7 +130397,7 @@ function createRcCredentialStore(fs24, dir) {
|
|
|
130102
130397
|
} catch {
|
|
130103
130398
|
return void 0;
|
|
130104
130399
|
}
|
|
130105
|
-
return
|
|
130400
|
+
return isRecord14(parsed) ? parsed : void 0;
|
|
130106
130401
|
};
|
|
130107
130402
|
return {
|
|
130108
130403
|
read: (sessionId) => {
|
|
@@ -130670,7 +130965,7 @@ init_capability();
|
|
|
130670
130965
|
// src/frontdoor/rcSelfHostEndpoints.ts
|
|
130671
130966
|
var RC_SOURCE_WORKER = "worker";
|
|
130672
130967
|
var RC_SOURCE_CLIENT = "client";
|
|
130673
|
-
function
|
|
130968
|
+
function isRecord15(value2) {
|
|
130674
130969
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
130675
130970
|
}
|
|
130676
130971
|
function parseJsonObject3(body) {
|
|
@@ -130680,7 +130975,7 @@ function parseJsonObject3(body) {
|
|
|
130680
130975
|
} catch {
|
|
130681
130976
|
return void 0;
|
|
130682
130977
|
}
|
|
130683
|
-
return
|
|
130978
|
+
return isRecord15(parsed) ? parsed : void 0;
|
|
130684
130979
|
}
|
|
130685
130980
|
function nonEmptyString2(record2, field) {
|
|
130686
130981
|
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
@@ -130754,7 +131049,7 @@ async function serveRcClientChannels(ctx, tail, method, maxBatchEvents) {
|
|
|
130754
131049
|
}
|
|
130755
131050
|
const results = [];
|
|
130756
131051
|
for (const event of events) {
|
|
130757
|
-
if (!
|
|
131052
|
+
if (!isRecord15(event) || !isRecord15(event.payload)) {
|
|
130758
131053
|
await ctx.answerJson(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a teleport write is an object carrying one payload object" } });
|
|
130759
131054
|
return true;
|
|
130760
131055
|
}
|
|
@@ -130854,7 +131149,7 @@ async function serveRcCompatSessions(ctx, pathname, compatPath) {
|
|
|
130854
131149
|
// src/frontdoor/rcSelfHostConversations.ts
|
|
130855
131150
|
var RC_CONVERSATIONS_PATH_PREFIX = "/v1/code/conversations";
|
|
130856
131151
|
var RC_CONVERSATION_ID_PREFIX = "conv_";
|
|
130857
|
-
function
|
|
131152
|
+
function isRecord16(value2) {
|
|
130858
131153
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
130859
131154
|
}
|
|
130860
131155
|
function parseJsonObject4(body) {
|
|
@@ -130864,7 +131159,7 @@ function parseJsonObject4(body) {
|
|
|
130864
131159
|
} catch {
|
|
130865
131160
|
return void 0;
|
|
130866
131161
|
}
|
|
130867
|
-
return
|
|
131162
|
+
return isRecord16(parsed) ? parsed : void 0;
|
|
130868
131163
|
}
|
|
130869
131164
|
function nonEmptyString3(record2, field) {
|
|
130870
131165
|
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
@@ -130918,7 +131213,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
130918
131213
|
}
|
|
130919
131214
|
const results = [];
|
|
130920
131215
|
for (const event of events) {
|
|
130921
|
-
if (!
|
|
131216
|
+
if (!isRecord16(event) || !isRecord16(event.payload)) {
|
|
130922
131217
|
await ctx.answerJson(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
130923
131218
|
return;
|
|
130924
131219
|
}
|
|
@@ -131211,7 +131506,7 @@ var RC_SELF_HOST_WORKER_EPOCH = 1;
|
|
|
131211
131506
|
var RC_STREAM_EVENT_NAME = "client_event";
|
|
131212
131507
|
var CONFLICT_REASON_HEADER2 = "x-ccr-conflict-reason";
|
|
131213
131508
|
var CONFLICT_REASON_EPOCH_STALE = "epoch_stale";
|
|
131214
|
-
function
|
|
131509
|
+
function isRecord17(value2) {
|
|
131215
131510
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
131216
131511
|
}
|
|
131217
131512
|
function isWebSearchRefusal(value2) {
|
|
@@ -131295,7 +131590,7 @@ function parseJsonObject5(body) {
|
|
|
131295
131590
|
} catch {
|
|
131296
131591
|
return void 0;
|
|
131297
131592
|
}
|
|
131298
|
-
return
|
|
131593
|
+
return isRecord17(parsed) ? parsed : void 0;
|
|
131299
131594
|
}
|
|
131300
131595
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
131301
131596
|
const encode3 = (value2) => Buffer.from(JSON.stringify(value2), "utf8").toString("base64url");
|
|
@@ -131555,7 +131850,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
131555
131850
|
if (status !== void 0) {
|
|
131556
131851
|
session.workerStatus = status;
|
|
131557
131852
|
}
|
|
131558
|
-
if (
|
|
131853
|
+
if (isRecord17(body?.external_metadata)) {
|
|
131559
131854
|
session.externalMetadata = body.external_metadata;
|
|
131560
131855
|
}
|
|
131561
131856
|
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
@@ -131585,7 +131880,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
131585
131880
|
}
|
|
131586
131881
|
const results = [];
|
|
131587
131882
|
for (const event of events) {
|
|
131588
|
-
if (!
|
|
131883
|
+
if (!isRecord17(event) || !isRecord17(event.payload)) {
|
|
131589
131884
|
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a batch is an object carrying one payload object" } });
|
|
131590
131885
|
return;
|
|
131591
131886
|
}
|
|
@@ -131618,7 +131913,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
131618
131913
|
return;
|
|
131619
131914
|
}
|
|
131620
131915
|
for (const event of events) {
|
|
131621
|
-
if (
|
|
131916
|
+
if (isRecord17(event)) {
|
|
131622
131917
|
session.internalEvents.push({ eventId: deps.newUuid(), body: event });
|
|
131623
131918
|
}
|
|
131624
131919
|
}
|
|
@@ -131714,7 +132009,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
131714
132009
|
}
|
|
131715
132010
|
const results = [];
|
|
131716
132011
|
for (const event of events) {
|
|
131717
|
-
if (!
|
|
132012
|
+
if (!isRecord17(event) || !isRecord17(event.payload)) {
|
|
131718
132013
|
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
131719
132014
|
return;
|
|
131720
132015
|
}
|
|
@@ -131904,7 +132199,7 @@ function createSseParser() {
|
|
|
131904
132199
|
}
|
|
131905
132200
|
};
|
|
131906
132201
|
}
|
|
131907
|
-
function
|
|
132202
|
+
function isRecord18(value2) {
|
|
131908
132203
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
131909
132204
|
}
|
|
131910
132205
|
function sequenceNumOf(value2) {
|
|
@@ -131926,7 +132221,7 @@ function parseRcStreamEnvelope(parsed) {
|
|
|
131926
132221
|
} catch {
|
|
131927
132222
|
return void 0;
|
|
131928
132223
|
}
|
|
131929
|
-
if (!
|
|
132224
|
+
if (!isRecord18(data)) {
|
|
131930
132225
|
return void 0;
|
|
131931
132226
|
}
|
|
131932
132227
|
const eventType = data.event_type;
|
|
@@ -132433,8 +132728,8 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
132433
132728
|
};
|
|
132434
132729
|
const rcSelfHostSurface = rcSelfHost ? createRcSelfHostSurface({
|
|
132435
132730
|
now: () => Date.now(),
|
|
132436
|
-
newUuid:
|
|
132437
|
-
randomToken: () => (0,
|
|
132731
|
+
newUuid: import_node_crypto24.randomUUID,
|
|
132732
|
+
randomToken: () => (0, import_node_crypto24.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
132438
132733
|
credentialRecord: () => readRcSelfHostRecord(realFarmFs, paths.frontdoorDir),
|
|
132439
132734
|
webFetch: realRcWebFetch({ allowPrivate: rcWebFetchAllowsPrivateFromEnv(process.env) }),
|
|
132440
132735
|
log
|
|
@@ -132457,7 +132752,7 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
132457
132752
|
saveSequenceNum: rcCredentialStore.writeCursor,
|
|
132458
132753
|
dial: rcSelfHost ? lateRcStreamDial(rcSelfHostDialTarget) : realRcStreamDial(),
|
|
132459
132754
|
fanout: rcFanout,
|
|
132460
|
-
newClientId:
|
|
132755
|
+
newClientId: import_node_crypto24.randomUUID,
|
|
132461
132756
|
backoffMs: RC_STREAM_BACKOFF_MS,
|
|
132462
132757
|
sleep: async (ms2) => {
|
|
132463
132758
|
await new Promise((resolve2) => {
|
|
@@ -132469,7 +132764,7 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
132469
132764
|
}
|
|
132470
132765
|
});
|
|
132471
132766
|
const routingSnapshots = /* @__PURE__ */ new Map();
|
|
132472
|
-
const rcControlToken = (0,
|
|
132767
|
+
const rcControlToken = (0, import_node_crypto24.randomUUID)();
|
|
132473
132768
|
const resolveRoute = rcObservingResolver(
|
|
132474
132769
|
createProviderRouteResolver({
|
|
132475
132770
|
fs: realFsPort,
|
|
@@ -132585,9 +132880,9 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
132585
132880
|
now: () => Date.now(),
|
|
132586
132881
|
headroomSocket: () => headroomSocketTarget(realFarmFs, realHeadroomSocketTrust, paths),
|
|
132587
132882
|
// The per-generation capability the direct listener demands: held only in this process's memory, so a loopback process that discovers the direct port still cannot use it.
|
|
132588
|
-
hopSecret: (0,
|
|
132883
|
+
hopSecret: (0, import_node_crypto24.randomUUID)(),
|
|
132589
132884
|
headroomDecision,
|
|
132590
|
-
custody: createCredentialCustody(() => (0,
|
|
132885
|
+
custody: createCredentialCustody(() => (0, import_node_crypto24.randomUUID)()),
|
|
132591
132886
|
log
|
|
132592
132887
|
});
|
|
132593
132888
|
const onListenerError = (name) => (error63) => {
|
|
@@ -132610,9 +132905,9 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
132610
132905
|
startProviderListener: async (preferredPort) => {
|
|
132611
132906
|
const authority = loadCa();
|
|
132612
132907
|
const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
|
|
132613
|
-
const rcInject = async (sessionId, text2) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid:
|
|
132908
|
+
const rcInject = async (sessionId, text2) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto24.randomUUID }, sessionId, text2);
|
|
132614
132909
|
const rcAnswer = async (sessionId, requestId, decision) => await answerRcControlRequest({ credentialOf: rcTracker.credentialOf, pendingOf: (id2) => rcTracker.pendingOf(id2), completePending: rcTracker.completePending, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial }, sessionId, requestId, decision);
|
|
132615
|
-
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid:
|
|
132910
|
+
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto24.randomUUID };
|
|
132616
132911
|
const rcInterrupt = async (sessionId) => await interruptRcSession(rcControlRequestDeps, sessionId);
|
|
132617
132912
|
const rcSetModel = async (sessionId, model) => await setRcSessionModel(rcControlRequestDeps, sessionId, model);
|
|
132618
132913
|
const rcSetPermissionMode = async (sessionId, mode) => await setRcSessionPermissionMode(rcControlRequestDeps, sessionId, mode);
|
|
@@ -132711,7 +133006,7 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
132711
133006
|
},
|
|
132712
133007
|
startConnectListener: async (preferredPort) => {
|
|
132713
133008
|
const wantedTransparentPort = process.env.AGENT_SHIM_TRANSPARENT_SURFACE === void 0 ? void 0 : Number(process.env.AGENT_SHIM_TRANSPARENT_SURFACE);
|
|
132714
|
-
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0,
|
|
133009
|
+
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0, import_node_crypto24.randomUUID)();
|
|
132715
133010
|
if (transparentCapability !== void 0) {
|
|
132716
133011
|
writeFrontDoorSession(realFarmFs, paths.frontdoorSessionsDir, { pid: process.pid, startedAt: Date.now(), token: transparentCapability });
|
|
132717
133012
|
}
|