@opengeni/config 3.2.1 → 3.3.0-canary.37090756480001
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/claude-subscription-capacity.d.ts +9 -0
- package/dist/claude-subscription-usage.d.ts +4 -2
- package/dist/index.d.ts +199 -3
- package/dist/index.js +483 -31
- package/dist/index.js.map +1 -1
- package/dist/subscription-account-selection.d.ts +17 -0
- package/package.json +4 -4
- package/src/claude-subscription-capacity.ts +129 -0
- package/src/claude-subscription-usage.ts +225 -5
- package/src/index.ts +340 -21
- package/src/subscription-account-selection.ts +36 -0
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/managed-user-admission.ts
|
|
2
2
|
function managedUserEmailAllowed(allowedUserEmails, email) {
|
|
3
|
-
return allowedUserEmails === void 0 || typeof email === "string" && allowedUserEmails.some((
|
|
3
|
+
return allowedUserEmails === void 0 || typeof email === "string" && allowedUserEmails.some((allowed2) => allowed2.toLowerCase() === email.trim().toLowerCase());
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// src/index.ts
|
|
7
7
|
import {
|
|
8
|
+
directModelConnectionSpec,
|
|
8
9
|
BillingMode,
|
|
9
10
|
CAPABILITY_DESCRIPTORS,
|
|
10
11
|
agentConfigDeploymentLimitsFromAllowlist,
|
|
@@ -79,13 +80,45 @@ function epoch(value) {
|
|
|
79
80
|
function status(value) {
|
|
80
81
|
return value === "allowed" || value === "allowed_warning" || value === "rejected" ? value : null;
|
|
81
82
|
}
|
|
82
|
-
function
|
|
83
|
+
function latestReset(left, right, observedAt) {
|
|
84
|
+
return new Date(
|
|
85
|
+
Math.max(
|
|
86
|
+
left ? Date.parse(left) : Date.parse(observedAt) + 6e4,
|
|
87
|
+
right ? Date.parse(right) : Date.parse(observedAt) + 6e4
|
|
88
|
+
)
|
|
89
|
+
).toISOString();
|
|
90
|
+
}
|
|
91
|
+
function evidenceKey(item) {
|
|
92
|
+
return JSON.stringify([
|
|
93
|
+
item.upstreamModelId,
|
|
94
|
+
item.upstreamModelId ? null : item.representativeClaim,
|
|
95
|
+
item.source === "provider"
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
function tiedRequest(left, right) {
|
|
99
|
+
const denied = left.status === "rejected" ? left : right.status === "rejected" ? right : null;
|
|
100
|
+
return {
|
|
101
|
+
...denied ?? left,
|
|
102
|
+
resetsAt: denied ? latestReset(
|
|
103
|
+
left.status === "rejected" ? left.resetsAt : denied.resetsAt,
|
|
104
|
+
right.status === "rejected" ? right.resetsAt : denied.resetsAt,
|
|
105
|
+
left.observedAt
|
|
106
|
+
) : null,
|
|
107
|
+
representativeClaim: left.representativeClaim === right.representativeClaim ? left.representativeClaim : null,
|
|
108
|
+
status: denied ? "rejected" : null,
|
|
109
|
+
overageStatus: null,
|
|
110
|
+
overageResetsAt: null
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function parseClaudeUsageHeaders(headers, now = /* @__PURE__ */ new Date(), upstreamModelId) {
|
|
83
114
|
const observedAt = now.toISOString();
|
|
84
115
|
const claim = ClaudeUsageWindowId.safeParse(
|
|
85
116
|
headers.get("anthropic-ratelimit-unified-representative-claim")
|
|
86
117
|
);
|
|
87
118
|
const claimedStatus = status(headers.get("anthropic-ratelimit-unified-status"));
|
|
88
119
|
const claimedReset = epoch(headers.get("anthropic-ratelimit-unified-reset"));
|
|
120
|
+
const overageStatus = status(headers.get("anthropic-ratelimit-unified-overage-status"));
|
|
121
|
+
const overageResetsAt = epoch(headers.get("anthropic-ratelimit-unified-overage-reset"));
|
|
89
122
|
const windows = ClaudeUsageWindowId.options.flatMap((id) => {
|
|
90
123
|
const header = (suffix) => prefixes[id].map(
|
|
91
124
|
(prefix) => headers.get(`anthropic-ratelimit-unified-${prefix}-${suffix}`)
|
|
@@ -97,7 +130,20 @@ function parseClaudeUsageHeaders(headers, now = /* @__PURE__ */ new Date()) {
|
|
|
97
130
|
if (usedPercent === null && resetsAt === null && windowStatus === null) return [];
|
|
98
131
|
return [{ id, usedPercent, resetsAt, status: windowStatus, observedAt }];
|
|
99
132
|
});
|
|
100
|
-
return windows.length
|
|
133
|
+
return windows.length || claimedStatus || overageStatus ? {
|
|
134
|
+
windows,
|
|
135
|
+
observedAt,
|
|
136
|
+
source: "response_headers",
|
|
137
|
+
requestStatus: {
|
|
138
|
+
status: claimedStatus,
|
|
139
|
+
resetsAt: claimedReset,
|
|
140
|
+
representativeClaim: claim.success ? claim.data : null,
|
|
141
|
+
overageStatus,
|
|
142
|
+
overageResetsAt,
|
|
143
|
+
upstreamModelId: upstreamModelId ?? null,
|
|
144
|
+
observedAt
|
|
145
|
+
}
|
|
146
|
+
} : null;
|
|
101
147
|
}
|
|
102
148
|
function parseClaudeUsageResponse(value, now = /* @__PURE__ */ new Date()) {
|
|
103
149
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
@@ -127,17 +173,130 @@ function emptyClaudeUsage(credentialVersion) {
|
|
|
127
173
|
}
|
|
128
174
|
function mergeClaudeUsage(current, observation) {
|
|
129
175
|
const windows = new Map(current.windows.map((window) => [window.id, window]));
|
|
130
|
-
for (const
|
|
176
|
+
for (const incomingWindow of observation.windows) {
|
|
177
|
+
const window = { ...incomingWindow, source: incomingWindow.source ?? observation.source };
|
|
131
178
|
const previous = windows.get(window.id);
|
|
132
|
-
if (!previous || previous.observedAt
|
|
179
|
+
if (!previous || previous.observedAt < window.observedAt) windows.set(window.id, window);
|
|
180
|
+
else if (previous.observedAt === window.observedAt && JSON.stringify(previous) !== JSON.stringify(window)) {
|
|
181
|
+
const rejected = previous.status === "rejected" || window.status === "rejected";
|
|
182
|
+
const full = (previous.usedPercent ?? 0) >= 100 || (window.usedPercent ?? 0) >= 100;
|
|
183
|
+
windows.set(window.id, {
|
|
184
|
+
...previous,
|
|
185
|
+
usedPercent: previous.usedPercent === null ? window.usedPercent : window.usedPercent === null ? previous.usedPercent : Math.max(previous.usedPercent, window.usedPercent),
|
|
186
|
+
status: rejected ? "rejected" : previous.status === window.status ? previous.status : null,
|
|
187
|
+
resetsAt: rejected || full ? latestReset(previous.resetsAt, window.resetsAt, window.observedAt) : previous.resetsAt === window.resetsAt ? previous.resetsAt : null,
|
|
188
|
+
source: previous.source === "response_headers" || window.source === "response_headers" ? "response_headers" : "provider"
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const incoming = observation.requestStatus;
|
|
193
|
+
const restrictions = new Map(
|
|
194
|
+
(current.requestRestrictions ?? []).map((item) => [evidenceKey(item), item])
|
|
195
|
+
);
|
|
196
|
+
for (const item of [
|
|
197
|
+
current.requestStatus?.status ? current.requestStatus : null,
|
|
198
|
+
...observation.requestRestrictions ?? [],
|
|
199
|
+
incoming?.status ? incoming : null
|
|
200
|
+
]) {
|
|
201
|
+
if (!item) continue;
|
|
202
|
+
const key = evidenceKey(item);
|
|
203
|
+
const previous = restrictions.get(key);
|
|
204
|
+
const sanitized = {
|
|
205
|
+
...item,
|
|
206
|
+
overageStatus: null,
|
|
207
|
+
overageResetsAt: null
|
|
208
|
+
};
|
|
209
|
+
if (!previous || item.observedAt > previous.observedAt) restrictions.set(key, sanitized);
|
|
210
|
+
else if (item.observedAt === previous.observedAt && JSON.stringify(previous) !== JSON.stringify(sanitized))
|
|
211
|
+
restrictions.set(key, tiedRequest(previous, sanitized));
|
|
212
|
+
}
|
|
213
|
+
const directWindows = [
|
|
214
|
+
...current.windows.filter(
|
|
215
|
+
(window) => window.source === "provider" || !window.source && current.source === "provider" && current.observedAt === window.observedAt
|
|
216
|
+
),
|
|
217
|
+
...observation.windows.filter((window) => (window.source ?? observation.source) === "provider")
|
|
218
|
+
];
|
|
219
|
+
for (const window of directWindows) {
|
|
220
|
+
if (window.usedPercent === null || window.usedPercent >= 100) continue;
|
|
221
|
+
const proof = {
|
|
222
|
+
status: null,
|
|
223
|
+
resetsAt: null,
|
|
224
|
+
representativeClaim: window.id,
|
|
225
|
+
upstreamModelId: null,
|
|
226
|
+
overageStatus: null,
|
|
227
|
+
overageResetsAt: null,
|
|
228
|
+
observedAt: window.observedAt,
|
|
229
|
+
source: "provider"
|
|
230
|
+
};
|
|
231
|
+
const key = evidenceKey(proof);
|
|
232
|
+
if (!restrictions.has(key) || restrictions.get(key).observedAt < proof.observedAt)
|
|
233
|
+
restrictions.set(key, proof);
|
|
234
|
+
}
|
|
235
|
+
for (const [key, item] of restrictions) {
|
|
236
|
+
if (item.status !== "rejected") continue;
|
|
237
|
+
const proof = [...restrictions.values()].find(
|
|
238
|
+
(candidate) => candidate.source === "provider" && candidate.representativeClaim === item.representativeClaim && candidate.observedAt > item.observedAt && candidate.representativeClaim !== "overage" && candidate.representativeClaim !== "seven_day_overage_included"
|
|
239
|
+
);
|
|
240
|
+
if (proof)
|
|
241
|
+
restrictions.set(key, {
|
|
242
|
+
...item,
|
|
243
|
+
status: null,
|
|
244
|
+
resetsAt: null,
|
|
245
|
+
observedAt: proof.observedAt
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
let requestRestrictions = [...restrictions.values()];
|
|
249
|
+
const evidenceTime = requestRestrictions.reduce(
|
|
250
|
+
(value, item) => item.observedAt > value ? item.observedAt : value,
|
|
251
|
+
observation.observedAt
|
|
252
|
+
);
|
|
253
|
+
const liveDenials = requestRestrictions.filter(
|
|
254
|
+
(item) => item.status === "rejected" && (item.resetsAt ? Date.parse(item.resetsAt) : Date.parse(item.observedAt) + 6e4) > Date.parse(evidenceTime)
|
|
255
|
+
);
|
|
256
|
+
if (requestRestrictions.length > 64 && liveDenials.length === 0) {
|
|
257
|
+
requestRestrictions = requestRestrictions.sort((left, right) => right.observedAt.localeCompare(left.observedAt)).slice(0, 64);
|
|
258
|
+
} else if (requestRestrictions.length > 64) {
|
|
259
|
+
const observedAt = evidenceTime;
|
|
260
|
+
const resetsAt = new Date(
|
|
261
|
+
Math.max(
|
|
262
|
+
...liveDenials.map(
|
|
263
|
+
(item) => item.resetsAt ? Date.parse(item.resetsAt) : Date.parse(item.observedAt) + 6e4
|
|
264
|
+
),
|
|
265
|
+
Date.parse(observedAt) + 6e4
|
|
266
|
+
)
|
|
267
|
+
).toISOString();
|
|
268
|
+
requestRestrictions = [
|
|
269
|
+
{
|
|
270
|
+
status: "rejected",
|
|
271
|
+
resetsAt,
|
|
272
|
+
representativeClaim: null,
|
|
273
|
+
overageStatus: null,
|
|
274
|
+
overageResetsAt: null,
|
|
275
|
+
upstreamModelId: null,
|
|
276
|
+
observedAt
|
|
277
|
+
}
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
const newest = !current.observedAt || current.observedAt < observation.observedAt;
|
|
281
|
+
const tied = current.observedAt === observation.observedAt;
|
|
282
|
+
let requestStatus = current.requestStatus ?? null;
|
|
283
|
+
if (newest) requestStatus = incoming ?? null;
|
|
284
|
+
else if (tied && JSON.stringify(requestStatus) !== JSON.stringify(incoming ?? null)) {
|
|
285
|
+
requestStatus = incoming && requestStatus && evidenceKey(incoming) === evidenceKey(requestStatus) ? tiedRequest(requestStatus, incoming) : null;
|
|
133
286
|
}
|
|
134
|
-
const newest = !current.observedAt || current.observedAt <= observation.observedAt;
|
|
135
287
|
return {
|
|
136
288
|
...current,
|
|
289
|
+
requestRestrictions,
|
|
290
|
+
requestStatus,
|
|
137
291
|
windows: ClaudeUsageWindowId.options.flatMap(
|
|
138
292
|
(id) => windows.has(id) ? [windows.get(id)] : []
|
|
139
293
|
),
|
|
140
|
-
...newest ? {
|
|
294
|
+
...newest ? {
|
|
295
|
+
observedAt: observation.observedAt,
|
|
296
|
+
source: observation.source
|
|
297
|
+
// A newer direct or partial observation cannot retain an older paid
|
|
298
|
+
// fallback authorization. Window readings remain independently merged.
|
|
299
|
+
} : {}
|
|
141
300
|
};
|
|
142
301
|
}
|
|
143
302
|
|
|
@@ -167,6 +326,90 @@ function claudeAuthorizationUrl(input) {
|
|
|
167
326
|
return url.toString();
|
|
168
327
|
}
|
|
169
328
|
|
|
329
|
+
// src/subscription-account-selection.ts
|
|
330
|
+
function subscriptionAccountShardIndex(sessionId, candidateCount) {
|
|
331
|
+
if (!Number.isSafeInteger(candidateCount) || candidateCount <= 0)
|
|
332
|
+
throw new Error("Subscription shard candidate count must be positive");
|
|
333
|
+
let hash = 2166136261;
|
|
334
|
+
for (let index = 0; index < sessionId.length; index += 1) {
|
|
335
|
+
hash ^= sessionId.charCodeAt(index);
|
|
336
|
+
hash = Math.imul(hash, 16777619);
|
|
337
|
+
}
|
|
338
|
+
return (hash >>> 0) % candidateCount;
|
|
339
|
+
}
|
|
340
|
+
function selectSubscriptionAccount(input) {
|
|
341
|
+
const pinned = input.eligible.find((account) => account.id === input.pinnedCredentialId);
|
|
342
|
+
if (input.pinnedCredentialId && input.pinSource !== "policy") return pinned ?? null;
|
|
343
|
+
if (!input.rotationEnabled)
|
|
344
|
+
return input.eligible.find((account) => account.id === input.activeCredentialId) ?? null;
|
|
345
|
+
return pinned ?? (input.eligible.length ? input.eligible[subscriptionAccountShardIndex(input.sessionId, input.eligible.length)] : null);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/claude-subscription-capacity.ts
|
|
349
|
+
var UNKNOWN_RESET_RECHECK_MS = 6e4;
|
|
350
|
+
var allowed = (status2) => status2 === "allowed" || status2 === "allowed_warning";
|
|
351
|
+
function claudeSubscriptionCapacity(usage, upstreamModelId, now, options = {}) {
|
|
352
|
+
const available = { available: true, nextCheckAt: null, blockingWindows: [] };
|
|
353
|
+
if (!usage.connected || usage.refreshStatus === "reconnect")
|
|
354
|
+
return { ...available, available: false };
|
|
355
|
+
const relevant = (id) => {
|
|
356
|
+
if (id === "seven_day_opus") return /^claude-opus-/.test(upstreamModelId);
|
|
357
|
+
if (id === "seven_day_sonnet") return /^claude-sonnet-/.test(upstreamModelId);
|
|
358
|
+
return id === "five_hour" || id === "seven_day";
|
|
359
|
+
};
|
|
360
|
+
const applicable = usage.windows.filter((window) => relevant(window.id));
|
|
361
|
+
const relevantClaim = (id) => id === "seven_day_opus" || id === "seven_day_sonnet" ? relevant(id) : true;
|
|
362
|
+
const restrictions = (usage.requestRestrictions ?? []).filter(
|
|
363
|
+
(item) => item.status === "rejected" && (item.upstreamModelId === upstreamModelId || item.upstreamModelId === null && relevantClaim(item.representativeClaim)) && !applicable.some(
|
|
364
|
+
(window) => window.source === "provider" && window.usedPercent !== null && window.usedPercent < 100 && window.id === item.representativeClaim && window.observedAt > item.observedAt
|
|
365
|
+
) && (item.resetsAt ? Date.parse(item.resetsAt) : Date.parse(item.observedAt) + UNKNOWN_RESET_RECHECK_MS) > now.getTime()
|
|
366
|
+
);
|
|
367
|
+
const blocking = applicable.filter((window) => {
|
|
368
|
+
if ((window.resetsAt ? Date.parse(window.resetsAt) : Date.parse(window.observedAt) + UNKNOWN_RESET_RECHECK_MS) <= now.getTime())
|
|
369
|
+
return false;
|
|
370
|
+
return window.status === "rejected" || window.status === null && (window.usedPercent ?? 0) >= 100;
|
|
371
|
+
});
|
|
372
|
+
const request = usage.requestStatus;
|
|
373
|
+
const exactModel = request?.upstreamModelId === upstreamModelId;
|
|
374
|
+
const relevantRequest = request && (exactModel || request.upstreamModelId === null && relevantClaim(request.representativeClaim));
|
|
375
|
+
const freshRequest = relevantRequest && applicable.every((window) => window.observedAt <= request.observedAt) && restrictions.every((item) => item.observedAt <= request.observedAt);
|
|
376
|
+
const planResetElapsed = request && (request.resetsAt ? Date.parse(request.resetsAt) : Date.parse(request.observedAt) + UNKNOWN_RESET_RECHECK_MS) <= now.getTime();
|
|
377
|
+
const exactAllowance = (usage.requestRestrictions ?? []).find(
|
|
378
|
+
(item) => item.upstreamModelId === upstreamModelId && allowed(item.status) && blocking.every((window) => window.observedAt < item.observedAt) && restrictions.every((restriction) => restriction.observedAt < item.observedAt)
|
|
379
|
+
);
|
|
380
|
+
if (exactAllowance) return available;
|
|
381
|
+
if (freshRequest && exactModel && allowed(request.status) && !planResetElapsed) return available;
|
|
382
|
+
const mayUseOverage = options.allowOverage !== false;
|
|
383
|
+
const overageResetElapsed = request?.overageResetsAt && Date.parse(request.overageResetsAt) <= now.getTime();
|
|
384
|
+
if (freshRequest && request.status === "rejected" && mayUseOverage && allowed(request.overageStatus) && !overageResetElapsed)
|
|
385
|
+
return available;
|
|
386
|
+
const rejectedRequest = freshRequest && request.status === "rejected" && !planResetElapsed;
|
|
387
|
+
if (blocking.length === 0 && !rejectedRequest && restrictions.length === 0) return available;
|
|
388
|
+
const resets = blocking.map(
|
|
389
|
+
(window) => window.resetsAt ? Date.parse(window.resetsAt) : Date.parse(window.observedAt) + UNKNOWN_RESET_RECHECK_MS
|
|
390
|
+
);
|
|
391
|
+
if (rejectedRequest)
|
|
392
|
+
resets.push(
|
|
393
|
+
request.resetsAt ? Date.parse(request.resetsAt) : Date.parse(request.observedAt) + UNKNOWN_RESET_RECHECK_MS
|
|
394
|
+
);
|
|
395
|
+
resets.push(
|
|
396
|
+
...restrictions.map(
|
|
397
|
+
(item) => item.resetsAt ? Date.parse(item.resetsAt) : Date.parse(item.observedAt) + UNKNOWN_RESET_RECHECK_MS
|
|
398
|
+
)
|
|
399
|
+
);
|
|
400
|
+
let nextCheckAt = Math.max(...resets);
|
|
401
|
+
if (rejectedRequest && mayUseOverage && request.overageStatus === "rejected" && request.overageResetsAt) {
|
|
402
|
+
const overageReset = Date.parse(request.overageResetsAt);
|
|
403
|
+
if (overageReset <= now.getTime()) return available;
|
|
404
|
+
nextCheckAt = Math.min(nextCheckAt, overageReset);
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
available: false,
|
|
408
|
+
nextCheckAt: new Date(nextCheckAt),
|
|
409
|
+
blockingWindows: blocking.map((window) => window.id)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
170
413
|
// src/index.ts
|
|
171
414
|
var envName = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
172
415
|
var registryId = /^[A-Za-z0-9_-]+$/;
|
|
@@ -195,6 +438,7 @@ var EnvBoolean = z2.preprocess((value) => {
|
|
|
195
438
|
}
|
|
196
439
|
return value;
|
|
197
440
|
}, z2.boolean());
|
|
441
|
+
var PublicHttpUrl = z2.string().url().max(2048).refine((value) => /^https?:\/\//iu.test(value), "must be an http(s) URL");
|
|
198
442
|
var DEFAULT_GOAL_IDLE_BACKOFF_MS = [3e3, 3e4, 12e4, 3e5];
|
|
199
443
|
var DEFAULT_GOAL_IDLE_BACKOFF_MAX_MS = 6e5;
|
|
200
444
|
var EnvGoalIdleBackoffMs = z2.preprocess((value) => {
|
|
@@ -353,6 +597,15 @@ var SettingsSchema = z2.object({
|
|
|
353
597
|
analyticsPosthogProjectKey: z2.string().min(1).max(256).optional(),
|
|
354
598
|
analyticsPosthogHost: z2.string().url().max(2048).optional(),
|
|
355
599
|
analyticsGa4MeasurementId: z2.string().max(32).regex(/^G-[A-Z0-9]+$/u).optional(),
|
|
600
|
+
// Optional operator-owned legal documents linked from the signed-out console.
|
|
601
|
+
// Unset by default, so a self-hosted deployment never shows another operator's
|
|
602
|
+
// policies; the managed service points these at its own published pages.
|
|
603
|
+
legalPrivacyPolicyUrl: PublicHttpUrl.optional(),
|
|
604
|
+
legalTermsOfServiceUrl: PublicHttpUrl.optional(),
|
|
605
|
+
// Optional operator support address, shown as a "Contact support" mailto link
|
|
606
|
+
// on the signed-out page and in the Help menu. Unset by default for the same
|
|
607
|
+
// reason as the legal links.
|
|
608
|
+
supportEmail: z2.string().trim().email().max(254).optional(),
|
|
356
609
|
publicBaseUrl: z2.string().url().optional(),
|
|
357
610
|
// Product documentation the web console links from its Help menu. Absent
|
|
358
611
|
// means the public OpenGeni docs; `none` hides the link for deployments that
|
|
@@ -1134,6 +1387,28 @@ var SettingsSchema = z2.object({
|
|
|
1134
1387
|
// getSettings caps the default at half a shorter configured Modal lifetime so
|
|
1135
1388
|
// the entire reaper window always fits. Knob: OPENGENI_SANDBOX_IDLE_GRACE_MS.
|
|
1136
1389
|
sandboxIdleGraceMs: z2.coerce.number().int().positive().default(9e5),
|
|
1390
|
+
// Idle command containment. A legacy retained background command (a dev
|
|
1391
|
+
// server, a command whose output is still draining, a stopped command the
|
|
1392
|
+
// provider no longer answers for) keeps its box warm through a non-expiring
|
|
1393
|
+
// process holder, so the zero-holder drain never runs and the box would stay
|
|
1394
|
+
// up until the provider deadline kills it uncaptured. Once every session of
|
|
1395
|
+
// the sandbox group has been unused this long - no open turn or pending
|
|
1396
|
+
// request, no held wait_for_input, no other holder or writer, measured from
|
|
1397
|
+
// durable turn/holder/admission facts - the reaper checkpoints the workspace,
|
|
1398
|
+
// stops the box and settles those commands `lost` with reason
|
|
1399
|
+
// `idle_containment`. Default 30min: twice the default
|
|
1400
|
+
// idle grace, so a lease that is only waiting for a "glanced away" user is
|
|
1401
|
+
// never contained earlier than an idle lease would drain, and well inside
|
|
1402
|
+
// the 1h provider-deadline rotation lead, so an idle box is saved long before
|
|
1403
|
+
// the deadline path has to act. Set 0 to disable new idle enrollments without
|
|
1404
|
+
// disabling provider-deadline containment or cancelling an enrolled drain.
|
|
1405
|
+
// A positive window must exceed OPENGENI_SANDBOX_IDLE_GRACE_MS;
|
|
1406
|
+
// an explicit positive value must also stay below OPENGENI_SANDBOX_ROTATION_LEAD_MS,
|
|
1407
|
+
// and with an explicit OPENGENI_MODAL_IDLE_TIMEOUT_SECONDS the reaper period
|
|
1408
|
+
// plus this window plus the drain capture budget must fit before it.
|
|
1409
|
+
// getSettings derives the unset default between those two for short-lived
|
|
1410
|
+
// provider lifetimes. Knob: OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS.
|
|
1411
|
+
sandboxIdleCommandContainmentMs: z2.coerce.number().int().nonnegative().optional().transform((value) => value === 0 ? void 0 : value),
|
|
1137
1412
|
// MID-SESSION /workspace snapshot cadence (sandbox-file-persistence). The
|
|
1138
1413
|
// reaper's drain-persist only protects boxes the reaper itself kills; a box
|
|
1139
1414
|
// that dies any other way (Modal's hard creation-time timeout on a session
|
|
@@ -1708,6 +1983,8 @@ var RegistryProviderKind = z2.enum([
|
|
|
1708
1983
|
"vercel-gateway-managed",
|
|
1709
1984
|
"vercel-gateway-workspace",
|
|
1710
1985
|
"vercel-gateway-organization",
|
|
1986
|
+
"direct-openai-workspace",
|
|
1987
|
+
"direct-azure-workspace",
|
|
1711
1988
|
"openrouter-workspace",
|
|
1712
1989
|
"openrouter-organization",
|
|
1713
1990
|
"anthropic-organization",
|
|
@@ -2005,7 +2282,10 @@ var CodexCatalogModelSchema = RegistryModelSchema.safeExtend({
|
|
|
2005
2282
|
message: "Codex product id must match its upstream model slug"
|
|
2006
2283
|
});
|
|
2007
2284
|
}
|
|
2008
|
-
})
|
|
2285
|
+
}).transform((model) => ({
|
|
2286
|
+
...model,
|
|
2287
|
+
capabilities: reviewedCodexCatalogCapabilities(model.upstreamModelId, model.capabilities)
|
|
2288
|
+
}));
|
|
2009
2289
|
var ModelCatalogDocument = z2.object({
|
|
2010
2290
|
schemaVersion: z2.literal(1),
|
|
2011
2291
|
/** Canonical deployment default. Omission preserves the V1 first-built-in
|
|
@@ -2060,7 +2340,7 @@ var ModelCatalogDocument = z2.object({
|
|
|
2060
2340
|
});
|
|
2061
2341
|
}
|
|
2062
2342
|
document.registryProviders.forEach((provider, providerIndex) => {
|
|
2063
|
-
if (RESERVED_MODEL_PROVIDER_IDS.has(provider.id)) {
|
|
2343
|
+
if (RESERVED_MODEL_PROVIDER_IDS.has(provider.id) || provider.id.startsWith("workspace-openai-") || provider.id.startsWith("workspace-azure-openai-")) {
|
|
2064
2344
|
context.addIssue({
|
|
2065
2345
|
code: "custom",
|
|
2066
2346
|
path: ["registryProviders", providerIndex, "id"],
|
|
@@ -2576,6 +2856,7 @@ function optionalEnvironmentValue(name, source) {
|
|
|
2576
2856
|
const value = source[name];
|
|
2577
2857
|
return value && value.trim().length > 0 ? value : void 0;
|
|
2578
2858
|
}
|
|
2859
|
+
var idleCommandContainmentDisabledWarned = false;
|
|
2579
2860
|
function getSettings(source = process.env) {
|
|
2580
2861
|
const optional = (name) => optionalEnvironmentValue(name, source);
|
|
2581
2862
|
const modelCatalogSource = optional("OPENGENI_MODEL_CATALOG_SOURCE");
|
|
@@ -2625,6 +2906,9 @@ function getSettings(source = process.env) {
|
|
|
2625
2906
|
analyticsPosthogProjectKey: optional("OPENGENI_ANALYTICS_POSTHOG_PROJECT_KEY"),
|
|
2626
2907
|
analyticsPosthogHost: optional("OPENGENI_ANALYTICS_POSTHOG_HOST"),
|
|
2627
2908
|
analyticsGa4MeasurementId: optional("OPENGENI_ANALYTICS_GA4_MEASUREMENT_ID"),
|
|
2909
|
+
legalPrivacyPolicyUrl: optional("OPENGENI_LEGAL_PRIVACY_POLICY_URL"),
|
|
2910
|
+
legalTermsOfServiceUrl: optional("OPENGENI_LEGAL_TERMS_OF_SERVICE_URL"),
|
|
2911
|
+
supportEmail: optional("OPENGENI_SUPPORT_EMAIL"),
|
|
2628
2912
|
publicBaseUrl: optional("OPENGENI_PUBLIC_BASE_URL"),
|
|
2629
2913
|
documentationUrl: optional("OPENGENI_DOCUMENTATION_URL"),
|
|
2630
2914
|
mcpOauthEnabled: optional("OPENGENI_MCP_OAUTH_ENABLED"),
|
|
@@ -2929,6 +3213,7 @@ function getSettings(source = process.env) {
|
|
|
2929
3213
|
sandboxViewerHolderTtlMs: optional("OPENGENI_SANDBOX_VIEWER_HOLDER_TTL_MS"),
|
|
2930
3214
|
sandboxInteractionHolderTtlMs: optional("OPENGENI_SANDBOX_INTERACTION_HOLDER_TTL_MS"),
|
|
2931
3215
|
sandboxIdleGraceMs: optional("OPENGENI_SANDBOX_IDLE_GRACE_MS"),
|
|
3216
|
+
sandboxIdleCommandContainmentMs: optional("OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS"),
|
|
2932
3217
|
sandboxSnapshotIntervalMs: optional("OPENGENI_SANDBOX_SNAPSHOT_INTERVAL_MS"),
|
|
2933
3218
|
sandboxSnapshotTimeoutMs: optional("OPENGENI_SANDBOX_SNAPSHOT_TIMEOUT_MS"),
|
|
2934
3219
|
sandboxDrainSnapshotTimeoutMs: optional("OPENGENI_SANDBOX_DRAIN_SNAPSHOT_TIMEOUT_MS"),
|
|
@@ -3048,6 +3333,27 @@ function getSettings(source = process.env) {
|
|
|
3048
3333
|
) : parsed.sandboxRotationLeadMs,
|
|
3049
3334
|
mcpServers: ensureBuiltInMcpServers(parsed)
|
|
3050
3335
|
};
|
|
3336
|
+
if (raw.sandboxIdleCommandContainmentMs === void 0) {
|
|
3337
|
+
const modalIdleCeilingMs = settings.sandboxBackend === "modal" && settings.modalIdleTimeoutSeconds !== void 0 ? settings.modalIdleTimeoutSeconds * 1e3 - settings.sandboxLeaseReaperPeriodMs - sandboxArchiveCaptureTimeoutMs({
|
|
3338
|
+
sandboxSnapshotTimeoutMs: effectiveSandboxDrainSnapshotTimeoutMs(settings)
|
|
3339
|
+
}) - 1 : Number.POSITIVE_INFINITY;
|
|
3340
|
+
const derived = Math.min(
|
|
3341
|
+
18e5,
|
|
3342
|
+
Math.floor((settings.sandboxIdleGraceMs + settings.sandboxRotationLeadMs) / 2),
|
|
3343
|
+
modalIdleCeilingMs
|
|
3344
|
+
);
|
|
3345
|
+
if (derived > settings.sandboxIdleGraceMs) {
|
|
3346
|
+
settings.sandboxIdleCommandContainmentMs = derived;
|
|
3347
|
+
} else {
|
|
3348
|
+
settings.sandboxIdleCommandContainmentMs = void 0;
|
|
3349
|
+
if (!idleCommandContainmentDisabledWarned) {
|
|
3350
|
+
idleCommandContainmentDisabledWarned = true;
|
|
3351
|
+
console.warn(
|
|
3352
|
+
`[config] idle command containment disabled: no window fits between OPENGENI_SANDBOX_IDLE_GRACE_MS (${settings.sandboxIdleGraceMs}) and the Modal idle timeout / rotation lead ceiling; set OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS to override.`
|
|
3353
|
+
);
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3051
3357
|
validateSettings(settings, source);
|
|
3052
3358
|
return settings;
|
|
3053
3359
|
}
|
|
@@ -3062,24 +3368,24 @@ function resolveFirstPartyDelegationSecret(settings) {
|
|
|
3062
3368
|
return settings.productAccessMode === "local" && (settings.environment === "local" || settings.environment === "test") ? LOCAL_FIRST_PARTY_DELEGATION_SECRET : void 0;
|
|
3063
3369
|
}
|
|
3064
3370
|
function resolveFirstPartyMcpToolPolicy(settings) {
|
|
3065
|
-
const
|
|
3371
|
+
const allowed2 = currentAgentLearningToolSelection(
|
|
3066
3372
|
settings.allowedFirstPartyMcpTools ?? [...FIRST_PARTY_MCP_TOOL_NAMES]
|
|
3067
3373
|
);
|
|
3068
|
-
const allowedSet = new Set(
|
|
3374
|
+
const allowedSet = new Set(allowed2);
|
|
3069
3375
|
const defaults = currentAgentLearningToolSelection(
|
|
3070
3376
|
settings.defaultFirstPartyMcpTools ?? [...DEFAULT_FIRST_PARTY_MCP_TOOLS]
|
|
3071
3377
|
);
|
|
3072
3378
|
return {
|
|
3073
3379
|
default: defaults.filter((tool) => allowedSet.has(tool)),
|
|
3074
|
-
allowed: [...
|
|
3380
|
+
allowed: [...allowed2]
|
|
3075
3381
|
};
|
|
3076
3382
|
}
|
|
3077
3383
|
function allowedFirstPartyMcpToolsForSession(settings, selected) {
|
|
3078
3384
|
const policy = resolveFirstPartyMcpToolPolicy(settings);
|
|
3079
|
-
const
|
|
3385
|
+
const allowed2 = new Set(policy.allowed);
|
|
3080
3386
|
const tools = new Set(currentAgentLearningToolSelection(selected ?? policy.default));
|
|
3081
3387
|
if (tools.has("goal_pause")) tools.add("goal_resume");
|
|
3082
|
-
return [...tools].filter((tool) =>
|
|
3388
|
+
return [...tools].filter((tool) => allowed2.has(tool));
|
|
3083
3389
|
}
|
|
3084
3390
|
function effectiveModalIdleTimeoutSeconds(settings) {
|
|
3085
3391
|
return settings.modalIdleTimeoutSeconds ?? settings.modalTimeoutSeconds;
|
|
@@ -3578,6 +3884,37 @@ function configuredRegistryProviders(settings) {
|
|
|
3578
3884
|
if (openrouter) injected.push(openrouter);
|
|
3579
3885
|
return injected;
|
|
3580
3886
|
}
|
|
3887
|
+
function withDirectModelProviders(settings, connections) {
|
|
3888
|
+
const providers = parseModelProvidersJson(settings.modelProvidersJson).filter(
|
|
3889
|
+
(provider) => !provider.id.startsWith("workspace-openai-") && !provider.id.startsWith("workspace-azure-openai-")
|
|
3890
|
+
);
|
|
3891
|
+
for (const connection of connections) {
|
|
3892
|
+
const spec = directModelConnectionSpec(connection);
|
|
3893
|
+
if (!spec) continue;
|
|
3894
|
+
providers.push({
|
|
3895
|
+
kind: spec.provider === "openai" ? "direct-openai-workspace" : "direct-azure-workspace",
|
|
3896
|
+
id: spec.providerId,
|
|
3897
|
+
label: spec.provider === "openai" ? "Your OpenAI" : "Your Azure OpenAI",
|
|
3898
|
+
api: "responses",
|
|
3899
|
+
wireProfile: spec.provider === "openai" ? "openai" : "azure-openai",
|
|
3900
|
+
baseUrl: spec.baseUrl,
|
|
3901
|
+
...connection.apiKey ? { apiKey: connection.apiKey } : {},
|
|
3902
|
+
models: [
|
|
3903
|
+
{
|
|
3904
|
+
id: spec.modelId,
|
|
3905
|
+
upstreamModelId: spec.model,
|
|
3906
|
+
label: spec.model,
|
|
3907
|
+
capabilities: legacyModelCapabilities(settings, {
|
|
3908
|
+
reasoningEffort: false,
|
|
3909
|
+
hostedWebSearch: false
|
|
3910
|
+
}),
|
|
3911
|
+
toolOutputTruncationTokens: settings.modelToolOutputTruncationTokens
|
|
3912
|
+
}
|
|
3913
|
+
]
|
|
3914
|
+
});
|
|
3915
|
+
}
|
|
3916
|
+
return { ...settings, modelProvidersJson: JSON.stringify(providers) };
|
|
3917
|
+
}
|
|
3581
3918
|
function withWorkspaceGatewayCatalogProvider(settings, customModels = []) {
|
|
3582
3919
|
const providers = parseModelProvidersJson(settings.modelProvidersJson);
|
|
3583
3920
|
const withoutWorkspace = providers.filter(
|
|
@@ -3723,7 +4060,7 @@ function builtinContextLimitsForModel(settings, modelId) {
|
|
|
3723
4060
|
return { contextWindowTokens: settings.contextWindowTokens };
|
|
3724
4061
|
}
|
|
3725
4062
|
function builtinLatencyModesForModel(modelId) {
|
|
3726
|
-
if (isBuiltinGpt56ModelId(modelId) ||
|
|
4063
|
+
if (isBuiltinGpt56ModelId(modelId) || /^gpt-6(?:\.\d+)?-/u.test(modelId) || modelId.startsWith("codex/gpt-5.6-") || /^codex\/gpt-6(?:\.\d+)?-/u.test(modelId)) {
|
|
3727
4064
|
return [
|
|
3728
4065
|
{ id: "standard", upstream: "supported", runnable: true },
|
|
3729
4066
|
{
|
|
@@ -3736,6 +4073,20 @@ function builtinLatencyModesForModel(modelId) {
|
|
|
3736
4073
|
}
|
|
3737
4074
|
return [{ id: "standard", upstream: "unknown", runnable: true }];
|
|
3738
4075
|
}
|
|
4076
|
+
function isReviewedGptVisionModel(slug) {
|
|
4077
|
+
return slug.startsWith("gpt-5.6-") || /^gpt-6(?:\.\d+)?-/u.test(slug);
|
|
4078
|
+
}
|
|
4079
|
+
function reviewedCodexCatalogCapabilities(slug, capabilities) {
|
|
4080
|
+
if (!/^gpt-6(?:\.\d+)?-/u.test(slug)) return capabilities;
|
|
4081
|
+
const fast = builtinLatencyModesForModel(`${CODEX_MODEL_ID_PREFIX}${slug}`).find(
|
|
4082
|
+
(mode) => mode.id === "fast"
|
|
4083
|
+
);
|
|
4084
|
+
return normalizeCapabilities({
|
|
4085
|
+
...capabilities,
|
|
4086
|
+
inputModalities: [.../* @__PURE__ */ new Set([...capabilities.inputModalities, "image"])],
|
|
4087
|
+
latencyModes: fast && !capabilities.latencyModes.some((mode) => mode.id === "fast") ? [...capabilities.latencyModes, fast] : capabilities.latencyModes
|
|
4088
|
+
});
|
|
4089
|
+
}
|
|
3739
4090
|
function builtinPromptCachingForModel(modelId) {
|
|
3740
4091
|
const slug = modelId.startsWith(CODEX_MODEL_ID_PREFIX) ? modelId.slice(CODEX_MODEL_ID_PREFIX.length) : modelId;
|
|
3741
4092
|
return slug.startsWith("gpt-5.6-") || slug.startsWith("gpt-6-") ? { upstream: "supported", runnable: true, mode: "implicit" } : void 0;
|
|
@@ -3780,11 +4131,21 @@ function runnableLatencyModesForModel(settings, modelId) {
|
|
|
3780
4131
|
function assertLatencyModeRunnable(settings, modelId, latencyMode) {
|
|
3781
4132
|
const runnable = runnableLatencyModesForModel(settings, modelId);
|
|
3782
4133
|
if (!runnable.includes(latencyMode)) {
|
|
3783
|
-
throw new
|
|
3784
|
-
`latency mode ${latencyMode} is not runnable for model ${modelId} (allowed: ${runnable.join(", ")})`
|
|
3785
|
-
);
|
|
4134
|
+
throw new UnsupportedLatencyModeError(modelId, latencyMode, runnable);
|
|
3786
4135
|
}
|
|
3787
4136
|
}
|
|
4137
|
+
var UnsupportedLatencyModeError = class extends Error {
|
|
4138
|
+
constructor(modelId, latencyMode, allowedLatencyModes) {
|
|
4139
|
+
super(
|
|
4140
|
+
`latency mode ${latencyMode} is not runnable for model ${modelId} (allowed: ${allowedLatencyModes.join(", ")})`
|
|
4141
|
+
);
|
|
4142
|
+
this.modelId = modelId;
|
|
4143
|
+
this.latencyMode = latencyMode;
|
|
4144
|
+
this.allowedLatencyModes = allowedLatencyModes;
|
|
4145
|
+
this.name = "UnsupportedLatencyModeError";
|
|
4146
|
+
}
|
|
4147
|
+
code = "UNSUPPORTED_LATENCY_MODE";
|
|
4148
|
+
};
|
|
3788
4149
|
function registryCredentialSource(provider) {
|
|
3789
4150
|
switch (provider.kind) {
|
|
3790
4151
|
case "anonymous":
|
|
@@ -3794,6 +4155,8 @@ function registryCredentialSource(provider) {
|
|
|
3794
4155
|
case "xai-subscription":
|
|
3795
4156
|
return { kind: "connected_subscription", provider: "xai" };
|
|
3796
4157
|
case "vercel-gateway-workspace":
|
|
4158
|
+
case "direct-openai-workspace":
|
|
4159
|
+
case "direct-azure-workspace":
|
|
3797
4160
|
case "openrouter-workspace":
|
|
3798
4161
|
case "anthropic-workspace":
|
|
3799
4162
|
case "claude-subscription-workspace":
|
|
@@ -3822,6 +4185,8 @@ function registryBilling(provider) {
|
|
|
3822
4185
|
case "xai-subscription":
|
|
3823
4186
|
return { upstreamPayer: "connected_subscription", metering: "external" };
|
|
3824
4187
|
case "vercel-gateway-workspace":
|
|
4188
|
+
case "direct-openai-workspace":
|
|
4189
|
+
case "direct-azure-workspace":
|
|
3825
4190
|
case "openrouter-workspace":
|
|
3826
4191
|
case "anthropic-workspace":
|
|
3827
4192
|
case "claude-subscription-workspace":
|
|
@@ -3934,6 +4299,31 @@ function legacyCodexAstraImplicitCachingDefinitionVersionFor(model, provider) {
|
|
|
3934
4299
|
const { promptCaching: _promptCaching, ...capabilities } = model.capabilities;
|
|
3935
4300
|
return definitionVersionFor({ ...modelWithoutVersion, capabilities }, provider);
|
|
3936
4301
|
}
|
|
4302
|
+
function matchesAdditiveCapabilityDefinitionVersion(model, provider, policy) {
|
|
4303
|
+
const { definitionVersion: _definitionVersion, ...modelWithoutVersion } = model;
|
|
4304
|
+
const { latencyModes, inputModalities } = model.capabilities;
|
|
4305
|
+
for (let latencyMask = 1; latencyMask < 1 << latencyModes.length; latencyMask += 1) {
|
|
4306
|
+
const retainedModes = latencyModes.filter((_mode, index) => latencyMask & 1 << index);
|
|
4307
|
+
if (!retainedModes.some((mode) => mode.id === policy.latencyMode && mode.runnable)) {
|
|
4308
|
+
continue;
|
|
4309
|
+
}
|
|
4310
|
+
for (let inputMask = 1; inputMask < 1 << inputModalities.length; inputMask += 1) {
|
|
4311
|
+
const retainedInputs = inputModalities.filter((_modality, index) => inputMask & 1 << index);
|
|
4312
|
+
if (retainedModes.length === latencyModes.length && retainedInputs.length === inputModalities.length) {
|
|
4313
|
+
continue;
|
|
4314
|
+
}
|
|
4315
|
+
const capabilities = {
|
|
4316
|
+
...model.capabilities,
|
|
4317
|
+
latencyModes: retainedModes,
|
|
4318
|
+
inputModalities: retainedInputs
|
|
4319
|
+
};
|
|
4320
|
+
if (policy.definitionVersion === definitionVersionFor({ ...modelWithoutVersion, capabilities }, provider)) {
|
|
4321
|
+
return true;
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
return false;
|
|
4326
|
+
}
|
|
3937
4327
|
function builtinProviderId(settings) {
|
|
3938
4328
|
return settings.openaiProvider === "azure" ? "azure" : "openai";
|
|
3939
4329
|
}
|
|
@@ -4004,7 +4394,7 @@ function withCodexCatalogProvider(settings) {
|
|
|
4004
4394
|
...legacyModelCapabilities(settings, {
|
|
4005
4395
|
reasoningEffort: true,
|
|
4006
4396
|
hostedWebSearch: true,
|
|
4007
|
-
vision:
|
|
4397
|
+
vision: isReviewedGptVisionModel(slug)
|
|
4008
4398
|
}),
|
|
4009
4399
|
...builtinPromptCachingForModel(`${CODEX_MODEL_ID_PREFIX}${slug}`) ? {
|
|
4010
4400
|
promptCaching: builtinPromptCachingForModel(`${CODEX_MODEL_ID_PREFIX}${slug}`)
|
|
@@ -4187,7 +4577,7 @@ function configuredModels(settings, source = process.env) {
|
|
|
4187
4577
|
reasoningEffort: true,
|
|
4188
4578
|
hostedWebSearch: settings.webSearchEnabled,
|
|
4189
4579
|
hostedImageGeneration: builtinHostedImageGenerationForModel(settings, id),
|
|
4190
|
-
vision:
|
|
4580
|
+
vision: isReviewedGptVisionModel(id)
|
|
4191
4581
|
}),
|
|
4192
4582
|
...builtinPromptCachingForModel(id) ? { promptCaching: builtinPromptCachingForModel(id) } : {},
|
|
4193
4583
|
latencyModes: builtinLatencyModesForModel(id)
|
|
@@ -4428,7 +4818,7 @@ function assertTurnExecutionPolicyMatchesConfigV1(settings, policy, expected) {
|
|
|
4428
4818
|
resolved.model,
|
|
4429
4819
|
resolved.provider
|
|
4430
4820
|
);
|
|
4431
|
-
const definitionVersionMatches = parsed.definitionVersion === resolved.model.definitionVersion || parsed.definitionVersion === legacyImplicitOpenAiDefinitionVersion || parsed.definitionVersion === legacyCodexAstraImplicitCachingDefinitionVersionFor(resolved.model, resolved.provider);
|
|
4821
|
+
const definitionVersionMatches = parsed.definitionVersion === resolved.model.definitionVersion || parsed.definitionVersion === legacyImplicitOpenAiDefinitionVersion || parsed.definitionVersion === legacyCodexAstraImplicitCachingDefinitionVersionFor(resolved.model, resolved.provider) || matchesAdditiveCapabilityDefinitionVersion(resolved.model, resolved.provider, parsed);
|
|
4432
4822
|
const identityMismatched = parsed.providerId !== resolved.provider.id || parsed.upstreamModelId !== resolved.model.upstreamModelId || parsed.wireApi !== resolved.model.api || canonicalJson(parsed.credentialSource) !== canonicalJson(resolved.model.credentialSource) || canonicalJson(parsed.billing) !== canonicalJson(resolved.model.billing);
|
|
4433
4823
|
if (identityMismatched) {
|
|
4434
4824
|
throw new Error("Turn execution policy does not match the current provider definition");
|
|
@@ -5686,6 +6076,17 @@ function validateSettings(settings, source = process.env) {
|
|
|
5686
6076
|
`OPENGENI_SANDBOX_ROTATION_LEAD_MS (${rotationLeadMs}) must exceed the legacy command stop grace, largest durable snapshot or drain capture timeout, and two reaper periods (${requiredRotationLeadMs}), including for persisted Modal leases after a default-backend rollout.`
|
|
5687
6077
|
);
|
|
5688
6078
|
}
|
|
6079
|
+
const containmentMs = settings.sandboxIdleCommandContainmentMs;
|
|
6080
|
+
if (containmentMs !== void 0 && !(containmentMs > settings.sandboxIdleGraceMs)) {
|
|
6081
|
+
throw new Error(
|
|
6082
|
+
`OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS (${containmentMs}) must exceed OPENGENI_SANDBOX_IDLE_GRACE_MS (${settings.sandboxIdleGraceMs}): a box kept warm only by retained commands must stay available at least as long as an idle box awaiting drain.`
|
|
6083
|
+
);
|
|
6084
|
+
}
|
|
6085
|
+
if (containmentMs !== void 0 && optionalEnvironmentValue("OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS", source) !== void 0 && !(containmentMs < rotationLeadMs)) {
|
|
6086
|
+
throw new Error(
|
|
6087
|
+
`OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS (${containmentMs}) must be strictly less than OPENGENI_SANDBOX_ROTATION_LEAD_MS (${rotationLeadMs}): an idle box must be checkpointed and stopped well before its provider deadline.`
|
|
6088
|
+
);
|
|
6089
|
+
}
|
|
5689
6090
|
if (settings.sandboxBackend === "modal") {
|
|
5690
6091
|
const idleGraceMs = settings.sandboxIdleGraceMs;
|
|
5691
6092
|
const lifecycle = effectiveSandboxLifecycle(settings, "modal");
|
|
@@ -5716,6 +6117,11 @@ function validateSettings(settings, source = process.env) {
|
|
|
5716
6117
|
`OPENGENI_SANDBOX_LEASE_REAPER_PERIOD_MS + OPENGENI_SANDBOX_IDLE_GRACE_MS (${reaperPeriod} + ${idleGraceMs} = ${reaperPeriod + idleGraceMs}) must be strictly less than the effective box idle timeout (${idleTimeoutMs}): a drained box must SURVIVE its full warm window so the reaper can resume + snapshot /workspace + terminate it on the sweep AFTER the drain grace elapses \u2014 Modal's idle-reap must NOT fire first (or /workspace is lost). Raise OPENGENI_MODAL_IDLE_TIMEOUT_SECONDS (defaults to OPENGENI_MODAL_TIMEOUT_SECONDS) or lower OPENGENI_SANDBOX_IDLE_GRACE_MS.`
|
|
5717
6118
|
);
|
|
5718
6119
|
}
|
|
6120
|
+
if (settings.modalIdleTimeoutSeconds !== void 0 && containmentMs !== void 0 && !(reaperPeriod + containmentMs + drainCaptureTimeoutMs < idleTimeoutMs)) {
|
|
6121
|
+
throw new Error(
|
|
6122
|
+
`OPENGENI_SANDBOX_LEASE_REAPER_PERIOD_MS + OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS + drain capture timeout (${reaperPeriod} + ${containmentMs} + ${drainCaptureTimeoutMs}) must be strictly less than OPENGENI_MODAL_IDLE_TIMEOUT_SECONDS*1000 (${idleTimeoutMs}): idle command containment must checkpoint a box before Modal's own idle reaper stops it. Lower OPENGENI_SANDBOX_IDLE_COMMAND_CONTAINMENT_MS or raise the Modal idle timeout.`
|
|
6123
|
+
);
|
|
6124
|
+
}
|
|
5719
6125
|
}
|
|
5720
6126
|
}
|
|
5721
6127
|
if (settings.sandboxDesktopEnabled && settings.sandboxBackend === "modal" && !["local", "test"].includes(settings.environment)) {
|
|
@@ -5743,7 +6149,7 @@ function validateModelCatalogSettings(settings, source = process.env) {
|
|
|
5743
6149
|
const builtinId = builtinProviderId(settings);
|
|
5744
6150
|
const providerIds = /* @__PURE__ */ new Set();
|
|
5745
6151
|
for (const provider of registryProviders) {
|
|
5746
|
-
if (provider.kind === "vercel-gateway-managed" || provider.kind === "vercel-gateway-workspace" || provider.kind === "vercel-gateway-organization" || provider.kind === "openrouter-workspace" || provider.kind === "openrouter-organization" || provider.kind === "anthropic-organization" || provider.kind === "anthropic-workspace" || provider.kind === "claude-subscription-workspace" || provider.kind === "claude-subscription-organization" || provider.kind === "xai-subscription") {
|
|
6152
|
+
if (provider.kind === "vercel-gateway-managed" || provider.kind === "vercel-gateway-workspace" || provider.kind === "vercel-gateway-organization" || provider.kind === "direct-openai-workspace" || provider.kind === "direct-azure-workspace" || provider.kind === "openrouter-workspace" || provider.kind === "openrouter-organization" || provider.kind === "anthropic-organization" || provider.kind === "anthropic-workspace" || provider.kind === "claude-subscription-workspace" || provider.kind === "claude-subscription-organization" || provider.kind === "xai-subscription") {
|
|
5747
6153
|
throw new Error(
|
|
5748
6154
|
`OPENGENI_MODEL_PROVIDERS_JSON provider kind ${provider.kind} is reserved for a reviewed OpenGeni credential broker`
|
|
5749
6155
|
);
|
|
@@ -5982,6 +6388,45 @@ function delay(ms) {
|
|
|
5982
6388
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5983
6389
|
}
|
|
5984
6390
|
var CLAUDE_CONNECTION_KINDS = ["anthropic", "claude_subscription"];
|
|
6391
|
+
var CLAUDE_NATIVE_MODEL_PROFILES = Object.fromEntries([
|
|
6392
|
+
...[
|
|
6393
|
+
["claude-opus-5-5", "medium"],
|
|
6394
|
+
["claude-sonnet-5-5", "medium"],
|
|
6395
|
+
["claude-opus-5", "high"],
|
|
6396
|
+
["claude-sonnet-5", "high"],
|
|
6397
|
+
["claude-opus-4-8", "high"],
|
|
6398
|
+
["claude-opus-4-7", "xhigh"]
|
|
6399
|
+
].map(([id, defaultEffort]) => [
|
|
6400
|
+
id,
|
|
6401
|
+
{
|
|
6402
|
+
efforts: ["low", "medium", "high", "xhigh", "max"],
|
|
6403
|
+
defaultEffort,
|
|
6404
|
+
contextWindowTokens: 1e6,
|
|
6405
|
+
maxOutputTokens: 128e3
|
|
6406
|
+
}
|
|
6407
|
+
]),
|
|
6408
|
+
...["claude-opus-4-6", "claude-sonnet-4-6"].map((id) => [
|
|
6409
|
+
id,
|
|
6410
|
+
{
|
|
6411
|
+
efforts: ["low", "medium", "high", "max"],
|
|
6412
|
+
defaultEffort: "high",
|
|
6413
|
+
contextWindowTokens: 1e6,
|
|
6414
|
+
maxOutputTokens: 128e3
|
|
6415
|
+
}
|
|
6416
|
+
]),
|
|
6417
|
+
[
|
|
6418
|
+
"claude-haiku-4-5-20251001",
|
|
6419
|
+
{
|
|
6420
|
+
efforts: [],
|
|
6421
|
+
defaultEffort: null,
|
|
6422
|
+
contextWindowTokens: 2e5,
|
|
6423
|
+
maxOutputTokens: 64e3
|
|
6424
|
+
}
|
|
6425
|
+
]
|
|
6426
|
+
]);
|
|
6427
|
+
function claudeNativeModelProfile(upstreamModelId) {
|
|
6428
|
+
return Object.hasOwn(CLAUDE_NATIVE_MODEL_PROFILES, upstreamModelId) ? CLAUDE_NATIVE_MODEL_PROFILES[upstreamModelId] : void 0;
|
|
6429
|
+
}
|
|
5985
6430
|
function claudeProviderId(kind, scope = "organization") {
|
|
5986
6431
|
return `${scope}-${kind === "anthropic" ? "anthropic" : "claude-subscription"}`;
|
|
5987
6432
|
}
|
|
@@ -6007,17 +6452,18 @@ function withClaudeConnectionCatalog(settings, connections, scope = "organizatio
|
|
|
6007
6452
|
anthropic: {
|
|
6008
6453
|
auth: kind === "anthropic" ? "api-key" : "oauth",
|
|
6009
6454
|
cacheTtl: "5m",
|
|
6010
|
-
maxOutputTokens:
|
|
6455
|
+
maxOutputTokens: 128e3,
|
|
6011
6456
|
streamIdleTimeoutMs: 6e5
|
|
6012
6457
|
},
|
|
6013
6458
|
models: connection.models.map((model) => {
|
|
6014
|
-
const
|
|
6015
|
-
|
|
6016
|
-
|
|
6459
|
+
const profile = claudeNativeModelProfile(model.upstreamModelId);
|
|
6460
|
+
const adaptiveThinking = Boolean(profile?.efforts.length);
|
|
6461
|
+
const contextWindowTokens = profile?.contextWindowTokens ?? 2e5;
|
|
6462
|
+
const outputReserve = profile?.maxOutputTokens ?? 32e3;
|
|
6017
6463
|
return {
|
|
6018
|
-
contextWindowTokens
|
|
6019
|
-
effectiveContextWindowTokens:
|
|
6020
|
-
autoCompactTokenLimit: 15e4,
|
|
6464
|
+
contextWindowTokens,
|
|
6465
|
+
effectiveContextWindowTokens: contextWindowTokens - outputReserve,
|
|
6466
|
+
autoCompactTokenLimit: contextWindowTokens === 1e6 ? 8e5 : Math.min(15e4, contextWindowTokens - outputReserve - 18e3),
|
|
6021
6467
|
id: id + "/" + model.upstreamModelId,
|
|
6022
6468
|
upstreamModelId: model.upstreamModelId,
|
|
6023
6469
|
label: model.label ?? (model.upstreamModelId === "claude-opus-5-5" ? "Claude Opus 5.5" : model.upstreamModelId === "claude-sonnet-5-5" ? "Claude Sonnet 5.5" : model.upstreamModelId),
|
|
@@ -6033,8 +6479,8 @@ function withClaudeConnectionCatalog(settings, connections, scope = "organizatio
|
|
|
6033
6479
|
reasoning: {
|
|
6034
6480
|
upstream: adaptiveThinking ? "supported" : "unknown",
|
|
6035
6481
|
runnable: adaptiveThinking,
|
|
6036
|
-
efforts:
|
|
6037
|
-
defaultEffort:
|
|
6482
|
+
efforts: [...profile?.efforts ?? []],
|
|
6483
|
+
defaultEffort: profile?.defaultEffort ?? null,
|
|
6038
6484
|
required: false
|
|
6039
6485
|
},
|
|
6040
6486
|
functionCalling: { upstream: "supported", runnable: true },
|
|
@@ -6129,6 +6575,7 @@ export {
|
|
|
6129
6575
|
SUPERGROK_REALTIME_MODEL_ID,
|
|
6130
6576
|
SocialOAuthClientConfigSchema,
|
|
6131
6577
|
TurnExecutionPolicyDefinitionMismatchError,
|
|
6578
|
+
UnsupportedLatencyModeError,
|
|
6132
6579
|
VERCEL_AI_GATEWAY_AI_SDK_BASE_URL,
|
|
6133
6580
|
VERCEL_AI_GATEWAY_BASE_URL,
|
|
6134
6581
|
VERCEL_AI_GATEWAY_CONNECTION_DOMAIN,
|
|
@@ -6156,7 +6603,9 @@ export {
|
|
|
6156
6603
|
canonicalPublicOrigin,
|
|
6157
6604
|
canonicalizeConfiguredModelId,
|
|
6158
6605
|
claudeAuthorizationUrl,
|
|
6606
|
+
claudeNativeModelProfile,
|
|
6159
6607
|
claudeProviderId,
|
|
6608
|
+
claudeSubscriptionCapacity,
|
|
6160
6609
|
codeSearchDeploymentPolicy,
|
|
6161
6610
|
codemodeWorkspaceUrl,
|
|
6162
6611
|
codexUpstreamModelSlugs,
|
|
@@ -6251,12 +6700,14 @@ export {
|
|
|
6251
6700
|
sandboxPreparationProfiles,
|
|
6252
6701
|
sandboxWarmRateMicrosPerSecond,
|
|
6253
6702
|
selectModelPricing,
|
|
6703
|
+
selectSubscriptionAccount,
|
|
6254
6704
|
serviceTierForLatencyMode,
|
|
6255
6705
|
settingsForAcceptedSubscriptionTurn,
|
|
6256
6706
|
settingsWithResolvedModelContext,
|
|
6257
6707
|
stableSandboxEnvironmentForRun,
|
|
6258
6708
|
startupRetryOptions,
|
|
6259
6709
|
streamTokenDegraded,
|
|
6710
|
+
subscriptionAccountShardIndex,
|
|
6260
6711
|
temporalConnectionOptions,
|
|
6261
6712
|
trustedProxyCidrEntries,
|
|
6262
6713
|
usableJevApiKey,
|
|
@@ -6265,6 +6716,7 @@ export {
|
|
|
6265
6716
|
withClaudeConnectionCatalog,
|
|
6266
6717
|
withClaudeConnectionCredential,
|
|
6267
6718
|
withCodexCatalogProvider,
|
|
6719
|
+
withDirectModelProviders,
|
|
6268
6720
|
withOrganizationGatewayCatalogProvider,
|
|
6269
6721
|
withOrganizationGatewayCredential,
|
|
6270
6722
|
withOrganizationOpenRouterCatalogProvider,
|