@r-33/opencode 0.4.7-rc.30 → 0.4.7-rc.31
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/README.md +47 -13
- package/dist/cli/production-smoke/production-smoke.js +115 -39
- package/dist/index.js +207 -60
- package/dist/tui-entry/index.js +760 -287
- package/dist/v2-entry/index.js +396 -111
- package/package.json +1 -1
package/dist/v2-entry/index.js
CHANGED
|
@@ -2148,9 +2148,11 @@ var KeyLeaseError = class extends Error {
|
|
|
2148
2148
|
);
|
|
2149
2149
|
this.code = code;
|
|
2150
2150
|
this.name = "KeyLeaseError";
|
|
2151
|
+
this.rejection = options?.rejection;
|
|
2151
2152
|
this.statusCode = options?.statusCode;
|
|
2152
2153
|
}
|
|
2153
2154
|
code;
|
|
2155
|
+
rejection;
|
|
2154
2156
|
statusCode;
|
|
2155
2157
|
};
|
|
2156
2158
|
|
|
@@ -2315,6 +2317,33 @@ var commitStagedReplacement = async (stage, save, persist) => {
|
|
|
2315
2317
|
}
|
|
2316
2318
|
};
|
|
2317
2319
|
|
|
2320
|
+
// src/management/management-error/management-error.ts
|
|
2321
|
+
var ManagementError = class extends Error {
|
|
2322
|
+
constructor(code, options) {
|
|
2323
|
+
super(
|
|
2324
|
+
"Route 33 management request failed",
|
|
2325
|
+
options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
|
|
2326
|
+
);
|
|
2327
|
+
this.code = code;
|
|
2328
|
+
this.name = "ManagementError";
|
|
2329
|
+
this.rejection = options?.rejection;
|
|
2330
|
+
this.statusCode = options?.statusCode;
|
|
2331
|
+
}
|
|
2332
|
+
code;
|
|
2333
|
+
rejection;
|
|
2334
|
+
statusCode;
|
|
2335
|
+
};
|
|
2336
|
+
|
|
2337
|
+
// src/key-lease/mint-failure/mint-failure.ts
|
|
2338
|
+
var mintFailure = (cause) => {
|
|
2339
|
+
const response = cause instanceof ManagementError ? cause : void 0;
|
|
2340
|
+
return new KeyLeaseError("KEY_LEASE_MINT_FAILED", {
|
|
2341
|
+
cause,
|
|
2342
|
+
...response?.rejection === void 0 ? {} : { rejection: response.rejection },
|
|
2343
|
+
...response?.statusCode === void 0 ? {} : { statusCode: response.statusCode }
|
|
2344
|
+
});
|
|
2345
|
+
};
|
|
2346
|
+
|
|
2318
2347
|
// src/key-lease/mint-fresh-lease/mint-fresh-lease.ts
|
|
2319
2348
|
var mintFreshLease = async (deps) => {
|
|
2320
2349
|
const now = deps.clock();
|
|
@@ -2345,7 +2374,7 @@ var mintFreshLease = async (deps) => {
|
|
|
2345
2374
|
input
|
|
2346
2375
|
);
|
|
2347
2376
|
} catch (cause) {
|
|
2348
|
-
throw
|
|
2377
|
+
throw mintFailure(cause);
|
|
2349
2378
|
}
|
|
2350
2379
|
const minted = {
|
|
2351
2380
|
key: material.key,
|
|
@@ -2428,21 +2457,6 @@ var rejectLease = async (options) => {
|
|
|
2428
2457
|
}
|
|
2429
2458
|
};
|
|
2430
2459
|
|
|
2431
|
-
// src/management/management-error/management-error.ts
|
|
2432
|
-
var ManagementError = class extends Error {
|
|
2433
|
-
constructor(code, options) {
|
|
2434
|
-
super(
|
|
2435
|
-
"Route 33 management request failed",
|
|
2436
|
-
options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
|
|
2437
|
-
);
|
|
2438
|
-
this.code = code;
|
|
2439
|
-
this.name = "ManagementError";
|
|
2440
|
-
this.statusCode = options?.statusCode;
|
|
2441
|
-
}
|
|
2442
|
-
code;
|
|
2443
|
-
statusCode;
|
|
2444
|
-
};
|
|
2445
|
-
|
|
2446
2460
|
// src/key-lease/mint-key/mint-key.ts
|
|
2447
2461
|
var mintKey = async (options) => {
|
|
2448
2462
|
const now = options.clock();
|
|
@@ -2476,10 +2490,7 @@ var mintKey = async (options) => {
|
|
|
2476
2490
|
if (isManagementUnauthorized(cause)) {
|
|
2477
2491
|
throw new KeyLeaseError("KEY_LEASE_UNAUTHORIZED", { cause });
|
|
2478
2492
|
}
|
|
2479
|
-
throw
|
|
2480
|
-
cause,
|
|
2481
|
-
...cause instanceof ManagementError && cause.statusCode !== void 0 ? { statusCode: cause.statusCode } : {}
|
|
2482
|
-
});
|
|
2493
|
+
throw mintFailure(cause);
|
|
2483
2494
|
}
|
|
2484
2495
|
return {
|
|
2485
2496
|
key: material.key,
|
|
@@ -2817,6 +2828,7 @@ var inspectSession = (options) => {
|
|
|
2817
2828
|
const lease = options.readLease();
|
|
2818
2829
|
return {
|
|
2819
2830
|
attribution,
|
|
2831
|
+
connected: options.connected,
|
|
2820
2832
|
...lease === void 0 ? {} : { lease: { expiresAt: lease.expiresAt, keyId: lease.keyId } }
|
|
2821
2833
|
};
|
|
2822
2834
|
};
|
|
@@ -2847,10 +2859,10 @@ var WorkspaceKeyBinding = class {
|
|
|
2847
2859
|
* @returns Secret-free options; local options do not need destructive consent.
|
|
2848
2860
|
*/
|
|
2849
2861
|
async candidates(choice) {
|
|
2850
|
-
const listing = this.#listings.get(choice.orgId) ?? this.
|
|
2862
|
+
const listing = this.#listings.get(choice.orgId) ?? this.listKeys(choice.orgId);
|
|
2851
2863
|
this.#listings.set(choice.orgId, listing);
|
|
2852
2864
|
const rows = await listing;
|
|
2853
|
-
const keys = rows.
|
|
2865
|
+
const keys = rows.filter((row) => this.matches(row, choice));
|
|
2854
2866
|
if (keys.length === 0) return [];
|
|
2855
2867
|
const local = await this.localKeys(new Set(keys.map((row) => row.id)));
|
|
2856
2868
|
return keys.map((row) => ({
|
|
@@ -2859,8 +2871,18 @@ var WorkspaceKeyBinding = class {
|
|
|
2859
2871
|
local: local.has(row.id)
|
|
2860
2872
|
}));
|
|
2861
2873
|
}
|
|
2874
|
+
async listKeys(orgId) {
|
|
2875
|
+
try {
|
|
2876
|
+
return (await this.deps.client.list(this.deps.token, orgId)).data;
|
|
2877
|
+
} catch {
|
|
2878
|
+
logger.warn(
|
|
2879
|
+
"Existing keys could not be listed; only new keys can be offered."
|
|
2880
|
+
);
|
|
2881
|
+
return [];
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2862
2884
|
matches(row, choice) {
|
|
2863
|
-
return row.status === "active" && !row.revoked && Date.parse(row.expires_at) > this.deps.now && (choice.orgId === void 0 || row.org_id === choice.orgId) && row.
|
|
2885
|
+
return row.status === "active" && !row.revoked && Date.parse(row.expires_at) > this.deps.now && (choice.orgId === void 0 || row.org_id === choice.orgId) && row.user_id === this.deps.subject && (choice.kind === "project" ? row.project_id === choice.projectId && row.ownership_type === "user_project" : row.project_id === null && row.ownership_type === "user_personal");
|
|
2864
2886
|
}
|
|
2865
2887
|
async localKeys(ids) {
|
|
2866
2888
|
const found = /* @__PURE__ */ new Map();
|
|
@@ -2959,6 +2981,8 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
2959
2981
|
return `Personal \u2014 your own key${marker}${orgSuffix}`;
|
|
2960
2982
|
};
|
|
2961
2983
|
const budgetAllowance = (project) => {
|
|
2984
|
+
if (project.memberCap !== void 0)
|
|
2985
|
+
return `cap ${String(project.memberCap)} EUR`;
|
|
2962
2986
|
const budget = project.effective_budget ?? project.max_budget;
|
|
2963
2987
|
return budget === null ? "no cap set" : `cap ${budget.amount} ${budget.currency}`;
|
|
2964
2988
|
};
|
|
@@ -2973,6 +2997,7 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
2973
2997
|
};
|
|
2974
2998
|
return {
|
|
2975
2999
|
label: `${project.organisation.name} \xB7 ${project.name} \u2014 ${budgetAllowance(project)}`,
|
|
3000
|
+
maximum: project.memberCap,
|
|
2976
3001
|
selection
|
|
2977
3002
|
};
|
|
2978
3003
|
});
|
|
@@ -2992,6 +3017,7 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
2992
3017
|
choicesBySelection[personal] = { kind: "personal", orgId: org.id };
|
|
2993
3018
|
promptOptions.push({
|
|
2994
3019
|
label: personalLabel(options.orgs.length > 1 ? org.name : void 0),
|
|
3020
|
+
maximum: org.personalBudget?.cap ?? void 0,
|
|
2995
3021
|
selection: personal
|
|
2996
3022
|
});
|
|
2997
3023
|
}
|
|
@@ -3007,6 +3033,7 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
3007
3033
|
};
|
|
3008
3034
|
promptOptions.push({
|
|
3009
3035
|
label: `${project.organisation.name} \xB7 ${project.name} \u2014 ${budgetAllowance(project)}`,
|
|
3036
|
+
maximum: project.memberCap,
|
|
3010
3037
|
selection
|
|
3011
3038
|
});
|
|
3012
3039
|
}
|
|
@@ -3022,8 +3049,8 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
3022
3049
|
// src/ux/attribution-prompt-error/attribution-prompt-error.ts
|
|
3023
3050
|
var MESSAGES = {
|
|
3024
3051
|
ATTRIBUTION_BACK: "Left budget selection without changing attribution.",
|
|
3025
|
-
ATTRIBUTION_PRESENTER_UNAVAILABLE: "
|
|
3026
|
-
ATTRIBUTION_SELECTION_INVALID: "That Route 33 option is no longer available
|
|
3052
|
+
ATTRIBUTION_PRESENTER_UNAVAILABLE: "Update to OpenCode v2 to assign a Route 33 budget in this folder.",
|
|
3053
|
+
ATTRIBUTION_SELECTION_INVALID: "That Route 33 option is no longer available; choose another budget."
|
|
3027
3054
|
};
|
|
3028
3055
|
var AttributionPromptError = class extends GatewayCredentialError {
|
|
3029
3056
|
code;
|
|
@@ -3142,7 +3169,7 @@ import {
|
|
|
3142
3169
|
} from "@r-33/auth-browser";
|
|
3143
3170
|
|
|
3144
3171
|
// src/requested-scopes/requested-scopes.ts
|
|
3145
|
-
var REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read profile projects:read users:read keys:read keys:write";
|
|
3172
|
+
var REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read profile projects:read users:read keys:read keys:write models:read";
|
|
3146
3173
|
|
|
3147
3174
|
// src/route33-login/route33-login.ts
|
|
3148
3175
|
var route33Login = async (options) => {
|
|
@@ -3171,20 +3198,34 @@ var LoginSession = class {
|
|
|
3171
3198
|
#options;
|
|
3172
3199
|
#result;
|
|
3173
3200
|
#expiresAt;
|
|
3201
|
+
#clears = 0;
|
|
3174
3202
|
constructor(options) {
|
|
3175
3203
|
this.#options = options;
|
|
3176
3204
|
}
|
|
3177
3205
|
/**
|
|
3178
3206
|
* Clears the session: the cached login result and the stored refresh
|
|
3179
3207
|
* token. The next login starts from scratch — /r33 logout and the
|
|
3180
|
-
* auto-reconnect path both land here.
|
|
3208
|
+
* auto-reconnect path both land here. A refresh still on its way to the
|
|
3209
|
+
* auth server is disowned: its rotated token is never stored.
|
|
3181
3210
|
* @returns Resolved once the session and the stored refresh token are gone.
|
|
3182
3211
|
*/
|
|
3183
3212
|
async clear() {
|
|
3213
|
+
this.#clears += 1;
|
|
3184
3214
|
this.#result = void 0;
|
|
3185
3215
|
this.#expiresAt = void 0;
|
|
3186
3216
|
await this.#options.tokenStore?.set(void 0);
|
|
3187
3217
|
}
|
|
3218
|
+
/**
|
|
3219
|
+
* Whether a session exists, judged without using it: a login resolved or
|
|
3220
|
+
* in flight in this process, or a stored refresh token. Read-only — the
|
|
3221
|
+
* token is never presented, so asking cannot rotate or revoke anything.
|
|
3222
|
+
* @returns True when there is a session to sign in with.
|
|
3223
|
+
*/
|
|
3224
|
+
async hasSession() {
|
|
3225
|
+
if (this.#result !== void 0) return true;
|
|
3226
|
+
const stored = await this.#options.tokenStore?.get().catch(() => void 0);
|
|
3227
|
+
return stored !== void 0 && stored !== "";
|
|
3228
|
+
}
|
|
3188
3229
|
/**
|
|
3189
3230
|
* Resolves the login once per process, sharing in-flight attempts.
|
|
3190
3231
|
* @param policy - Whether this attempt may start a browser login; an in-flight attempt is always shared.
|
|
@@ -3193,11 +3234,15 @@ var LoginSession = class {
|
|
|
3193
3234
|
result(policy = {}) {
|
|
3194
3235
|
if (this.#result !== void 0 && this.#expiresAt !== void 0 && Date.now() >= this.#expiresAt - EXPIRY_SKEW_MS) {
|
|
3195
3236
|
this.#result = void 0;
|
|
3237
|
+
this.#expiresAt = void 0;
|
|
3238
|
+
}
|
|
3239
|
+
if (this.#result === void 0) {
|
|
3240
|
+
const attempt = this.#start(policy).catch((cause) => {
|
|
3241
|
+
if (this.#result === attempt) this.#result = void 0;
|
|
3242
|
+
throw cause;
|
|
3243
|
+
});
|
|
3244
|
+
this.#result = attempt;
|
|
3196
3245
|
}
|
|
3197
|
-
this.#result ??= this.#start(policy).catch((cause) => {
|
|
3198
|
-
this.#result = void 0;
|
|
3199
|
-
throw cause;
|
|
3200
|
-
});
|
|
3201
3246
|
return this.#result;
|
|
3202
3247
|
}
|
|
3203
3248
|
/**
|
|
@@ -3227,6 +3272,7 @@ var LoginSession = class {
|
|
|
3227
3272
|
if (tokenStore === void 0) {
|
|
3228
3273
|
return void 0;
|
|
3229
3274
|
}
|
|
3275
|
+
const clears = this.#clears;
|
|
3230
3276
|
const stored = await tokenStore.get();
|
|
3231
3277
|
if (stored === void 0 || stored === "") {
|
|
3232
3278
|
return void 0;
|
|
@@ -3235,6 +3281,9 @@ var LoginSession = class {
|
|
|
3235
3281
|
if (tokenSet === void 0) {
|
|
3236
3282
|
return void 0;
|
|
3237
3283
|
}
|
|
3284
|
+
if (clears !== this.#clears) {
|
|
3285
|
+
throw new AuthError2("AUTH_REAUTHENTICATION_REQUIRED");
|
|
3286
|
+
}
|
|
3238
3287
|
let credential;
|
|
3239
3288
|
try {
|
|
3240
3289
|
credential = parseManagementJwt(tokenSet.access_token);
|
|
@@ -3368,7 +3417,7 @@ var Route33Runtime = class {
|
|
|
3368
3417
|
const projectsById = new Map(
|
|
3369
3418
|
listings.flatMap(({ data }) => data).map((project) => [project.id, project])
|
|
3370
3419
|
);
|
|
3371
|
-
return rows.flatMap(({ org_id, project_id }) => {
|
|
3420
|
+
return rows.flatMap(({ org_id, project_id, cap }) => {
|
|
3372
3421
|
const project = projectsById.get(project_id);
|
|
3373
3422
|
if (project === void 0) {
|
|
3374
3423
|
return [];
|
|
@@ -3376,6 +3425,7 @@ var Route33Runtime = class {
|
|
|
3376
3425
|
return [
|
|
3377
3426
|
{
|
|
3378
3427
|
...project,
|
|
3428
|
+
memberCap: cap,
|
|
3379
3429
|
organisation: {
|
|
3380
3430
|
id: org_id,
|
|
3381
3431
|
name: organisationNames.get(org_id) ?? org_id
|
|
@@ -3505,6 +3555,7 @@ var Route33Runtime = class {
|
|
|
3505
3555
|
await this.#hydrateState(installation);
|
|
3506
3556
|
}
|
|
3507
3557
|
const base = inspectSession({
|
|
3558
|
+
connected: await this.#session.hasSession(),
|
|
3508
3559
|
readAttribution: () => attribution,
|
|
3509
3560
|
readLease: () => installation?.state.snapshot()
|
|
3510
3561
|
});
|
|
@@ -3512,10 +3563,9 @@ var Route33Runtime = class {
|
|
|
3512
3563
|
if (attribution === void 0 || keyId === void 0) {
|
|
3513
3564
|
return base;
|
|
3514
3565
|
}
|
|
3566
|
+
const credential = await this.#session.credential({ allowBrowser: false }).catch(() => void 0);
|
|
3567
|
+
if (credential === void 0) return { ...base, connected: false };
|
|
3515
3568
|
try {
|
|
3516
|
-
const credential = await this.#session.credential({
|
|
3517
|
-
allowBrowser: false
|
|
3518
|
-
});
|
|
3519
3569
|
const details = await enrichInspection({
|
|
3520
3570
|
attribution,
|
|
3521
3571
|
client: this.#client(),
|
|
@@ -3528,16 +3578,24 @@ var Route33Runtime = class {
|
|
|
3528
3578
|
return base;
|
|
3529
3579
|
}
|
|
3530
3580
|
}
|
|
3581
|
+
/**
|
|
3582
|
+
* Lists the models a key on this budget may be limited to. Never opens a
|
|
3583
|
+
* browser; an organisation-level (personal) catalog needs the `models:read`
|
|
3584
|
+
* grant, so sessions signed in before that grant reject here.
|
|
3585
|
+
* @param scope - The budget being configured.
|
|
3586
|
+
* @returns Key-facing model ids with their readable names.
|
|
3587
|
+
*/
|
|
3588
|
+
async catalogModelChoices(scope) {
|
|
3589
|
+
const credential = await this.#session.credential({ allowBrowser: false });
|
|
3590
|
+
return this.#client().listModelChoices(credential, scope);
|
|
3591
|
+
}
|
|
3531
3592
|
/**
|
|
3532
3593
|
* @param scope - The budget being configured. Omit to discover models for the current key.
|
|
3533
3594
|
* @returns The management catalog for a budget, or the current key's gateway catalog.
|
|
3534
3595
|
*/
|
|
3535
3596
|
async catalogModelIds(scope) {
|
|
3536
3597
|
if (scope !== void 0) {
|
|
3537
|
-
|
|
3538
|
-
allowBrowser: false
|
|
3539
|
-
});
|
|
3540
|
-
return this.#client().listModelIds(credential, scope);
|
|
3598
|
+
return (await this.catalogModelChoices(scope)).map(({ id }) => id);
|
|
3541
3599
|
}
|
|
3542
3600
|
const workspace = await this.storedReusableKey();
|
|
3543
3601
|
const personal = workspace === void 0 ? await this.#storedPersonalKey() : void 0;
|
|
@@ -3546,7 +3604,8 @@ var Route33Runtime = class {
|
|
|
3546
3604
|
const credential = await this.#session.credential({
|
|
3547
3605
|
allowBrowser: false
|
|
3548
3606
|
});
|
|
3549
|
-
|
|
3607
|
+
const choices = await this.#client().listModelChoices(credential, {});
|
|
3608
|
+
return choices.map(({ id }) => id);
|
|
3550
3609
|
}
|
|
3551
3610
|
return gatewayModelIds({
|
|
3552
3611
|
baseURL: readEnvBaseUrl() ?? DEFAULT_BASE_URL,
|
|
@@ -3627,6 +3686,29 @@ var Route33Runtime = class {
|
|
|
3627
3686
|
const key = keys.find((item) => item.id === keyId);
|
|
3628
3687
|
return key === void 0 ? void 0 : { allowedModels: key.allowed_models };
|
|
3629
3688
|
}
|
|
3689
|
+
/** V1 captures only the choice, not the plan; read only that owner's policy.
|
|
3690
|
+
* @param choice - The selected budget and its active organisation.
|
|
3691
|
+
* @returns The effective EUR cap, if the owner has a readable allowance.
|
|
3692
|
+
*/
|
|
3693
|
+
async ownerBudgetCap(choice) {
|
|
3694
|
+
const token = await this.#session.credential({ allowBrowser: false });
|
|
3695
|
+
const subject = this.#subject(token);
|
|
3696
|
+
const client = this.#client();
|
|
3697
|
+
if (choice.kind === "personal") {
|
|
3698
|
+
const policy = await client.listBudgetPolicy(
|
|
3699
|
+
token,
|
|
3700
|
+
subject,
|
|
3701
|
+
choice.orgId
|
|
3702
|
+
);
|
|
3703
|
+
return policy.cap ?? void 0;
|
|
3704
|
+
}
|
|
3705
|
+
const budgets = await client.listProjectBudgets(
|
|
3706
|
+
token,
|
|
3707
|
+
subject,
|
|
3708
|
+
choice.orgId
|
|
3709
|
+
);
|
|
3710
|
+
return budgets.data.find((row) => row.project_id === choice.projectId)?.cap;
|
|
3711
|
+
}
|
|
3630
3712
|
#client() {
|
|
3631
3713
|
const client = this.#options.management.client;
|
|
3632
3714
|
if (typeof client !== "function") {
|
|
@@ -3742,8 +3824,8 @@ var Route33Runtime = class {
|
|
|
3742
3824
|
};
|
|
3743
3825
|
|
|
3744
3826
|
// src/v1-entry/unattributed-prompt-gate/unattributed-prompt-gate.ts
|
|
3745
|
-
var CONNECTION_COPY = "
|
|
3746
|
-
var ATTRIBUTION_COPY = "This folder has no Route 33 budget
|
|
3827
|
+
var CONNECTION_COPY = "To sign in, run /connect and choose Route 33.";
|
|
3828
|
+
var ATTRIBUTION_COPY = "This folder has no Route 33 budget; open /r33 and choose Change budget.";
|
|
3747
3829
|
var createUnattributedPromptGate = ({ directory, isConnected, outsideWorktree }) => async (input) => {
|
|
3748
3830
|
if (input.model?.providerID !== "route_33") return Promise.resolve();
|
|
3749
3831
|
if (!await isConnected()) throw new Error(CONNECTION_COPY);
|
|
@@ -3890,7 +3972,7 @@ var parseApiKey = (value) => {
|
|
|
3890
3972
|
name: field("name"),
|
|
3891
3973
|
org_id: field("org_id"),
|
|
3892
3974
|
ownership_type: value["ownership_type"],
|
|
3893
|
-
...
|
|
3975
|
+
...isNullableString(value["user_id"]) ? { user_id: value["user_id"] } : {},
|
|
3894
3976
|
project_id: value["project_id"],
|
|
3895
3977
|
revoked: value["revoked"] === true,
|
|
3896
3978
|
status
|
|
@@ -4133,6 +4215,18 @@ var keyReadOperations = (call) => {
|
|
|
4133
4215
|
url.searchParams.set("cursor", cursor);
|
|
4134
4216
|
return new Request(url, request);
|
|
4135
4217
|
};
|
|
4218
|
+
const parsePage = (page) => {
|
|
4219
|
+
const collection = parseCollection(page, (row) => row);
|
|
4220
|
+
const data = collection.data.flatMap((row) => {
|
|
4221
|
+
try {
|
|
4222
|
+
return [parseApiKey(row)];
|
|
4223
|
+
} catch (error) {
|
|
4224
|
+
if (error instanceof ContractParseError) return [];
|
|
4225
|
+
throw error;
|
|
4226
|
+
}
|
|
4227
|
+
});
|
|
4228
|
+
return { ...collection, data };
|
|
4229
|
+
};
|
|
4136
4230
|
return {
|
|
4137
4231
|
get: async (accessToken, id, orgId) => parseApiKey(
|
|
4138
4232
|
await call(
|
|
@@ -4147,7 +4241,7 @@ var keyReadOperations = (call) => {
|
|
|
4147
4241
|
(cursor) => call(accessToken, orgId, (client) => {
|
|
4148
4242
|
if (cursor !== "") client.use({ onRequest: withCursor(cursor) });
|
|
4149
4243
|
return client.GET("/api/v1/api-keys", {});
|
|
4150
|
-
}).then(
|
|
4244
|
+
}).then(parsePage)
|
|
4151
4245
|
)
|
|
4152
4246
|
};
|
|
4153
4247
|
};
|
|
@@ -4211,29 +4305,55 @@ var keyWriteOperations = (call) => ({
|
|
|
4211
4305
|
)
|
|
4212
4306
|
});
|
|
4213
4307
|
|
|
4214
|
-
// src/management/
|
|
4215
|
-
var
|
|
4216
|
-
const
|
|
4308
|
+
// src/management/client-model-id/client-model-id.ts
|
|
4309
|
+
var clientModelId = (offeringId) => {
|
|
4310
|
+
const [provider, region, scope, vendor, ...modelParts] = offeringId.split(":");
|
|
4311
|
+
const slugParts = modelParts.at(-1) === "zdr" ? modelParts.slice(0, -1) : modelParts;
|
|
4312
|
+
const parts = [provider, region, scope, vendor, slugParts.join(":")];
|
|
4313
|
+
return parts.some((part) => part === void 0 || part === "") || /[\s,]/u.test(offeringId) ? void 0 : `${vendor ?? ""}/${slugParts.join(":")}`;
|
|
4314
|
+
};
|
|
4315
|
+
|
|
4316
|
+
// src/management/exposed-catalog-models/catalog-row-choices/catalog-row-choices.ts
|
|
4317
|
+
var catalogRowChoices = (row) => {
|
|
4318
|
+
if (!isRecord(row) || typeof row.id !== "string" || !row.id.trim() || typeof row.status !== "string")
|
|
4319
|
+
throw new ContractParseError("invalid model catalog item");
|
|
4320
|
+
if (row.status !== "exposed" || !Array.isArray(row.offerings)) return [];
|
|
4321
|
+
const label = typeof row.name === "string" && row.name.trim() !== "" ? row.name.trim() : void 0;
|
|
4322
|
+
return row.offerings.flatMap((offering) => {
|
|
4323
|
+
if (!isRecord(offering) || typeof offering.id !== "string" || offering.enabled !== true)
|
|
4324
|
+
return [];
|
|
4325
|
+
const id = clientModelId(offering.id);
|
|
4326
|
+
return id === void 0 ? [] : [{ id, name: label ?? id }];
|
|
4327
|
+
});
|
|
4328
|
+
};
|
|
4329
|
+
|
|
4330
|
+
// src/management/exposed-catalog-models/exposed-catalog-models.ts
|
|
4331
|
+
var exposedCatalogModels = async (readPage) => {
|
|
4332
|
+
const readRows = async (offset2) => {
|
|
4333
|
+
const page = await readPage(offset2);
|
|
4334
|
+
if (!isRecord(page) || !Array.isArray(page.models) || page.offset !== offset2 || typeof page.total !== "number" || !Number.isSafeInteger(page.total) || page.total < 0) {
|
|
4335
|
+
throw new ContractParseError("invalid model catalog page");
|
|
4336
|
+
}
|
|
4337
|
+
return { rows: page.models, total: page.total };
|
|
4338
|
+
};
|
|
4339
|
+
const names = /* @__PURE__ */ new Map();
|
|
4217
4340
|
let offset = 0;
|
|
4218
4341
|
for (; ; ) {
|
|
4219
|
-
const
|
|
4220
|
-
|
|
4221
|
-
|
|
4342
|
+
const { rows, total } = await readRows(offset);
|
|
4343
|
+
for (const { id, name } of rows.flatMap(catalogRowChoices)) {
|
|
4344
|
+
names.set(id, name);
|
|
4222
4345
|
}
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
throw new ContractParseError("invalid model catalog item");
|
|
4226
|
-
if (row.status === "exposed") ids.add(row.id);
|
|
4227
|
-
});
|
|
4228
|
-
offset += page.models.length;
|
|
4229
|
-
if (offset >= page.total || page.models.length === 0)
|
|
4230
|
-
return [...ids].sort((left, right) => left.localeCompare(right));
|
|
4346
|
+
offset += rows.length;
|
|
4347
|
+
if (offset >= total || rows.length === 0) break;
|
|
4231
4348
|
}
|
|
4349
|
+
return [...names].map(([id, name]) => ({ id, name })).sort(
|
|
4350
|
+
(left, right) => left.name.localeCompare(right.name) || left.id.localeCompare(right.id)
|
|
4351
|
+
);
|
|
4232
4352
|
};
|
|
4233
4353
|
|
|
4234
4354
|
// src/management/model-catalog-operations/model-catalog-operations.ts
|
|
4235
4355
|
var modelCatalogOperations = (call) => ({
|
|
4236
|
-
|
|
4356
|
+
listModelChoices: (token, { orgId, projectId }) => exposedCatalogModels(
|
|
4237
4357
|
(offset) => call(token, orgId, (client) => {
|
|
4238
4358
|
const query = { offset };
|
|
4239
4359
|
if (projectId !== void 0)
|
|
@@ -4290,6 +4410,29 @@ import {
|
|
|
4290
4410
|
createRoute33Client,
|
|
4291
4411
|
Route33SdkError
|
|
4292
4412
|
} from "@r-33/sdk";
|
|
4413
|
+
|
|
4414
|
+
// src/management/sdk-management-call/rejection-of/rejection-of.ts
|
|
4415
|
+
var REFUSED = 422;
|
|
4416
|
+
var REJECTION_MAX_LENGTH = 200;
|
|
4417
|
+
var CONTROL = /\p{Cc}+/gu;
|
|
4418
|
+
var SECRET_PREFIXES = ["r33_", "eyj", "bearer "];
|
|
4419
|
+
var OPAQUE_MIN_LENGTH = 20;
|
|
4420
|
+
var rejectionOf = (outcome) => {
|
|
4421
|
+
const body = outcome.error;
|
|
4422
|
+
if (outcome.response?.status !== REFUSED || !isRecord(body)) return void 0;
|
|
4423
|
+
const raw = body["error"];
|
|
4424
|
+
if (typeof raw !== "string" || raw.length > REJECTION_MAX_LENGTH) {
|
|
4425
|
+
return void 0;
|
|
4426
|
+
}
|
|
4427
|
+
const sentence = raw.replaceAll(CONTROL, " ").replaceAll(/\s+/gu, " ").trim();
|
|
4428
|
+
const lower = sentence.toLowerCase();
|
|
4429
|
+
const secretShaped = SECRET_PREFIXES.some((prefix) => lower.includes(prefix)) || lower.split(" ").some(
|
|
4430
|
+
(word) => word.length >= OPAQUE_MIN_LENGTH && /\d/u.test(word) && /[a-z]/u.test(word)
|
|
4431
|
+
);
|
|
4432
|
+
return sentence === "" || secretShaped ? void 0 : sentence;
|
|
4433
|
+
};
|
|
4434
|
+
|
|
4435
|
+
// src/management/sdk-management-call/sdk-management-call.ts
|
|
4293
4436
|
var API_PREFIX_PATTERN = /\/api\/v1\/?$/;
|
|
4294
4437
|
var ACTIVE_ORG_HEADER = "X-Active-Org-Id";
|
|
4295
4438
|
var createSdkCall = (options) => {
|
|
@@ -4336,9 +4479,13 @@ var createSdkCall = (options) => {
|
|
|
4336
4479
|
const outcome = await run(callClient(accessToken, activeOrgId));
|
|
4337
4480
|
const code = outcome.response?.status;
|
|
4338
4481
|
if (code === void 0 || code < 200 || code >= 300) {
|
|
4482
|
+
const rejection = rejectionOf(outcome);
|
|
4339
4483
|
throw new ManagementError(
|
|
4340
4484
|
code === 401 ? "MANAGEMENT_UNAUTHORIZED" : "MANAGEMENT_HTTP_ERROR",
|
|
4341
|
-
{
|
|
4485
|
+
{
|
|
4486
|
+
...rejection === void 0 ? {} : { rejection },
|
|
4487
|
+
statusCode: code
|
|
4488
|
+
}
|
|
4342
4489
|
);
|
|
4343
4490
|
}
|
|
4344
4491
|
return outcome.data;
|
|
@@ -4653,10 +4800,43 @@ import { createAuthorizationUrlStash as createAuthorizationUrlStash2 } from "@r-
|
|
|
4653
4800
|
import { Integration, Provider } from "@opencode/plugin";
|
|
4654
4801
|
|
|
4655
4802
|
// src/v2-entry/map-route33-model/map-route33-model.ts
|
|
4656
|
-
import { Model as
|
|
4803
|
+
import { Model as Model3 } from "@opencode/plugin";
|
|
4657
4804
|
|
|
4658
|
-
// src/v2-entry/map-route33-
|
|
4805
|
+
// src/v2-entry/map-route33-cost/map-route33-cost.ts
|
|
4659
4806
|
import { Model } from "@opencode/plugin";
|
|
4807
|
+
var LONG_CONTEXT_TOKENS = 2e5;
|
|
4808
|
+
var mapRoute33Cost = (cost) => {
|
|
4809
|
+
const rate = Model.Cost.fields.input;
|
|
4810
|
+
const read = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
4811
|
+
const tier = (rates) => {
|
|
4812
|
+
if (!isRecord(rates)) return [];
|
|
4813
|
+
const input = read(rates["input"]);
|
|
4814
|
+
const output = read(rates["output"]);
|
|
4815
|
+
if (input === void 0 || output === void 0) return [];
|
|
4816
|
+
return [
|
|
4817
|
+
{
|
|
4818
|
+
cache: {
|
|
4819
|
+
read: rate.make(read(rates["cache_read"]) ?? 0),
|
|
4820
|
+
write: rate.make(read(rates["cache_write"]) ?? 0)
|
|
4821
|
+
},
|
|
4822
|
+
input: rate.make(input),
|
|
4823
|
+
output: rate.make(output)
|
|
4824
|
+
}
|
|
4825
|
+
];
|
|
4826
|
+
};
|
|
4827
|
+
const base = tier(cost);
|
|
4828
|
+
if (base.length === 0 || !isRecord(cost)) return [];
|
|
4829
|
+
return [
|
|
4830
|
+
...base,
|
|
4831
|
+
...tier(cost["context_over_200k"]).map((rates) => ({
|
|
4832
|
+
...rates,
|
|
4833
|
+
tier: { size: LONG_CONTEXT_TOKENS, type: "context" }
|
|
4834
|
+
}))
|
|
4835
|
+
];
|
|
4836
|
+
};
|
|
4837
|
+
|
|
4838
|
+
// src/v2-entry/map-route33-variant/map-route33-variant.ts
|
|
4839
|
+
import { Model as Model2 } from "@opencode/plugin";
|
|
4660
4840
|
var mapRoute33Variant = (variants) => {
|
|
4661
4841
|
if (variants === void 0) {
|
|
4662
4842
|
return [];
|
|
@@ -4667,7 +4847,7 @@ var mapRoute33Variant = (variants) => {
|
|
|
4667
4847
|
continue;
|
|
4668
4848
|
}
|
|
4669
4849
|
mapped.push({
|
|
4670
|
-
id:
|
|
4850
|
+
id: Model2.VariantID.make(variantID),
|
|
4671
4851
|
settings: structuredClone(overlay)
|
|
4672
4852
|
});
|
|
4673
4853
|
}
|
|
@@ -4676,8 +4856,9 @@ var mapRoute33Variant = (variants) => {
|
|
|
4676
4856
|
|
|
4677
4857
|
// src/v2-entry/map-route33-model/map-route33-model.ts
|
|
4678
4858
|
var mapRoute33Model = (providerID, modelID, model) => ({
|
|
4679
|
-
...
|
|
4859
|
+
...Model3.Info.default(providerID, Model3.ID.make(modelID)),
|
|
4680
4860
|
name: typeof model.name === "string" ? model.name : modelID,
|
|
4861
|
+
cost: mapRoute33Cost(model.cost),
|
|
4681
4862
|
...model.variants === void 0 ? {} : {
|
|
4682
4863
|
variants: mapRoute33Variant(
|
|
4683
4864
|
model.variants
|
|
@@ -4721,11 +4902,12 @@ var bootstrapProvider = async (deps, sink) => {
|
|
|
4721
4902
|
if (runtime2 === void 0) {
|
|
4722
4903
|
return;
|
|
4723
4904
|
}
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4905
|
+
const signedIn = await runtime2.login({ allowBrowser: false }).then(
|
|
4906
|
+
() => true,
|
|
4907
|
+
() => false
|
|
4908
|
+
);
|
|
4728
4909
|
await deps.registerProjectForm().catch(() => void 0);
|
|
4910
|
+
if (!signedIn) return;
|
|
4729
4911
|
try {
|
|
4730
4912
|
const config = {};
|
|
4731
4913
|
await deps.runConfig(config);
|
|
@@ -4761,18 +4943,24 @@ var readAllowedModels = (answer) => {
|
|
|
4761
4943
|
};
|
|
4762
4944
|
|
|
4763
4945
|
// src/v2-entry/parse-budget-answer/read-budget-cap/read-budget-cap.ts
|
|
4764
|
-
var readBudgetCap = (answer) => {
|
|
4765
|
-
const value = answer["budget_cap"];
|
|
4766
|
-
if (value === void 0 || value === null) return null;
|
|
4946
|
+
var readBudgetCap = (answer, maximum) => {
|
|
4947
|
+
const value = answer["budget_cap"] ?? "";
|
|
4767
4948
|
if (typeof value !== "string" && typeof value !== "number") {
|
|
4768
4949
|
throw new TypeError("Budget cap must be a number or unlimited");
|
|
4769
4950
|
}
|
|
4770
|
-
if (typeof value === "string" &&
|
|
4951
|
+
if (typeof value === "string" && ["", "unlimited"].includes(value.trim().toLowerCase())) {
|
|
4771
4952
|
return null;
|
|
4772
4953
|
}
|
|
4773
4954
|
const parsed = Number(value);
|
|
4774
|
-
if (Number.isFinite(parsed)
|
|
4775
|
-
|
|
4955
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
4956
|
+
throw new RangeError("Budget cap must be a finite positive number");
|
|
4957
|
+
}
|
|
4958
|
+
if (maximum !== void 0 && parsed > maximum) {
|
|
4959
|
+
throw new RangeError(
|
|
4960
|
+
`Entered ${String(value)} EUR; the selected budget allows at most ${String(maximum)} EUR.`
|
|
4961
|
+
);
|
|
4962
|
+
}
|
|
4963
|
+
return parsed;
|
|
4776
4964
|
};
|
|
4777
4965
|
|
|
4778
4966
|
// src/v2-entry/parse-budget-answer/read-budget-description/read-budget-description.ts
|
|
@@ -4798,7 +4986,7 @@ var readBudgetName = (answer) => {
|
|
|
4798
4986
|
};
|
|
4799
4987
|
|
|
4800
4988
|
// src/v2-entry/parse-budget-answer/parse-budget-answer.ts
|
|
4801
|
-
var parseBudgetAnswer = (answer) => {
|
|
4989
|
+
var parseBudgetAnswer = (answer, maximum) => {
|
|
4802
4990
|
const attribution = parseConnectAnswer(answer);
|
|
4803
4991
|
if (attribution === void 0) {
|
|
4804
4992
|
return void 0;
|
|
@@ -4809,7 +4997,7 @@ var parseBudgetAnswer = (answer) => {
|
|
|
4809
4997
|
allowedModels: readAllowedModels(answer),
|
|
4810
4998
|
description: readBudgetDescription(answer),
|
|
4811
4999
|
expiryDays: readBudgetExpiry(answer),
|
|
4812
|
-
maxBudgetAmount: readBudgetCap(answer),
|
|
5000
|
+
maxBudgetAmount: readBudgetCap(answer, maximum),
|
|
4813
5001
|
name: readBudgetName(answer)
|
|
4814
5002
|
}
|
|
4815
5003
|
};
|
|
@@ -4817,23 +5005,32 @@ var parseBudgetAnswer = (answer) => {
|
|
|
4817
5005
|
|
|
4818
5006
|
// src/v2-entry/connect-copy/connect-copy.ts
|
|
4819
5007
|
var CONNECT_COPY = {
|
|
4820
|
-
failFastClientId: "This Route 33 build has no OAuth client
|
|
4821
|
-
failFastWorktree: "
|
|
4822
|
-
selectionInvalid: "That Route 33 option is no longer available
|
|
4823
|
-
signedInNextStep: "Signed in to Route 33
|
|
4824
|
-
budgetSelected: "Budget selected
|
|
4825
|
-
|
|
5008
|
+
failFastClientId: "This Route 33 build has no OAuth client ID; reinstall it from the opencode-dist ref.",
|
|
5009
|
+
failFastWorktree: "To assign a Route 33 budget, open a Git repository.",
|
|
5010
|
+
selectionInvalid: "That Route 33 option is no longer available; open /r33 and choose Attribute.",
|
|
5011
|
+
signedInNextStep: "Signed in to Route 33; open /r33 and choose Attribute to assign a budget.",
|
|
5012
|
+
budgetSelected: "Budget selected but not assigned; open /r33 and choose Attribute to finish setup."
|
|
5013
|
+
};
|
|
5014
|
+
var KEY_FORM_COPY = {
|
|
5015
|
+
/** Prefix of a key the management API refused; its reason follows. */
|
|
5016
|
+
mintRefused: "Route 33 refused this key:",
|
|
5017
|
+
mintRefusedUnknown: "its settings are not allowed for this budget.",
|
|
5018
|
+
modelsNeedSignIn: "Choosing individual models needs a fresh Route 33 sign-in.",
|
|
5019
|
+
modelsUnavailable: "The model list is unavailable right now."
|
|
4826
5020
|
};
|
|
4827
5021
|
|
|
4828
5022
|
// src/v2-entry/apply-wizard-answer/map-mint-failure/map-mint-failure.ts
|
|
4829
|
-
var
|
|
4830
|
-
var mapMintFailure = (cause) => cause instanceof KeyLeaseError && cause.statusCode ===
|
|
5023
|
+
var MINT_REFUSED_STATUS = 422;
|
|
5024
|
+
var mapMintFailure = (cause) => cause instanceof KeyLeaseError && cause.statusCode === MINT_REFUSED_STATUS ? new GatewayCredentialError(
|
|
5025
|
+
`${KEY_FORM_COPY.mintRefused} ${cause.rejection ?? KEY_FORM_COPY.mintRefusedUnknown}`
|
|
5026
|
+
) : cause;
|
|
4831
5027
|
|
|
4832
5028
|
// src/v2-entry/apply-wizard-answer/apply-wizard-answer.ts
|
|
4833
5029
|
var applyWizardAnswer = async (deps, answer) => {
|
|
4834
5030
|
const selection = parseConnectAnswer(answer);
|
|
4835
5031
|
if (selection === void 0) return;
|
|
4836
|
-
const
|
|
5032
|
+
const plan = deps.getPlan();
|
|
5033
|
+
const choice = plan?.choicesBySelection[selection];
|
|
4837
5034
|
if (choice === void 0) {
|
|
4838
5035
|
throw new AttributionPromptError("ATTRIBUTION_SELECTION_INVALID");
|
|
4839
5036
|
}
|
|
@@ -4844,9 +5041,12 @@ var applyWizardAnswer = async (deps, answer) => {
|
|
|
4844
5041
|
);
|
|
4845
5042
|
}
|
|
4846
5043
|
};
|
|
5044
|
+
const maximum = plan?.options.find(
|
|
5045
|
+
(option) => option.selection === selection
|
|
5046
|
+
)?.maximum;
|
|
4847
5047
|
const acquire = async (existing) => {
|
|
4848
5048
|
if (existing === void 0 || existing === "new") {
|
|
4849
|
-
const budget = parseBudgetAnswer(answer);
|
|
5049
|
+
const budget = parseBudgetAnswer(answer, maximum);
|
|
4850
5050
|
if (budget && deps.mintWorkspaceKey) {
|
|
4851
5051
|
try {
|
|
4852
5052
|
await deps.mintWorkspaceKey(choice, budget.extras, () => {
|
|
@@ -4885,7 +5085,7 @@ var createConnectAuthorize = (deps) => async (answer = {}) => {
|
|
|
4885
5085
|
}
|
|
4886
5086
|
const callback = (async () => {
|
|
4887
5087
|
const emptyAnswer = Object.keys(answer).length === 0;
|
|
4888
|
-
if (emptyAnswer
|
|
5088
|
+
if (emptyAnswer) {
|
|
4889
5089
|
const runtime2 = deps.getRuntime();
|
|
4890
5090
|
if (runtime2 === void 0) {
|
|
4891
5091
|
throw new GatewayCredentialError(
|
|
@@ -4893,11 +5093,13 @@ var createConnectAuthorize = (deps) => async (answer = {}) => {
|
|
|
4893
5093
|
);
|
|
4894
5094
|
}
|
|
4895
5095
|
await runtime2.login();
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
5096
|
+
if (readAttribution(deps.state) === void 0) {
|
|
5097
|
+
try {
|
|
5098
|
+
return await deps.resolveCredential();
|
|
5099
|
+
} catch {
|
|
5100
|
+
await deps.registerProjectForm();
|
|
5101
|
+
throw new GatewayCredentialError(CONNECT_COPY.signedInNextStep);
|
|
5102
|
+
}
|
|
4901
5103
|
}
|
|
4902
5104
|
}
|
|
4903
5105
|
const selection = parseConnectAnswer(answer);
|
|
@@ -4908,7 +5110,9 @@ var createConnectAuthorize = (deps) => async (answer = {}) => {
|
|
|
4908
5110
|
if (readAttribution(deps.state) === void 0) {
|
|
4909
5111
|
throw new GatewayCredentialError(CONNECT_COPY.selectionInvalid);
|
|
4910
5112
|
}
|
|
4911
|
-
|
|
5113
|
+
const credential = await deps.resolveCredential();
|
|
5114
|
+
if (emptyAnswer) await deps.registerProjectForm().catch(() => void 0);
|
|
5115
|
+
return credential;
|
|
4912
5116
|
})();
|
|
4913
5117
|
const decision = await deps.stash.urlForConnect(
|
|
4914
5118
|
callback.then(() => void 0)
|
|
@@ -4926,9 +5130,14 @@ var ATTRIBUTION_FIELD_KEY2 = "attribution";
|
|
|
4926
5130
|
var ORGANISATION_FIELD_KEY = "organisation";
|
|
4927
5131
|
var BUDGET_NAME_FIELD_KEY = "budget_name";
|
|
4928
5132
|
var BUDGET_CAP_FIELD_KEY = "budget_cap";
|
|
5133
|
+
var BUDGET_CAP_MAX_FIELD_KEY = "budget_cap_max";
|
|
5134
|
+
var PREPARED_BUDGET_FIELD_KEY = "prepared_budget";
|
|
4929
5135
|
var BUDGET_DESCRIPTION_FIELD_KEY = "budget_description";
|
|
4930
5136
|
var BUDGET_EXPIRY_FIELD_KEY = "budget_expiry";
|
|
4931
5137
|
var ALLOWED_MODELS_FIELD_KEY = "allowed_models";
|
|
5138
|
+
var ALLOWED_MODELS_TITLE = "Which models may this key use?";
|
|
5139
|
+
var ALL_MODELS_VALUE = "all";
|
|
5140
|
+
var ALL_MODELS_LABEL = "All models (inherit)";
|
|
4932
5141
|
var ORGANISATION_FIELD_TITLE = "Which Route 33 organisation covers this folder?";
|
|
4933
5142
|
var EXPIRY_OPTIONS = [
|
|
4934
5143
|
{ label: "30 days", value: "30" },
|
|
@@ -4936,7 +5145,8 @@ var EXPIRY_OPTIONS = [
|
|
|
4936
5145
|
{ label: "180 days", value: "180" },
|
|
4937
5146
|
{ label: "1 year", value: "365" }
|
|
4938
5147
|
];
|
|
4939
|
-
var buildConnectForm = (plan,
|
|
5148
|
+
var buildConnectForm = (plan, key) => {
|
|
5149
|
+
const maximum = key?.maximum;
|
|
4940
5150
|
const orgs = plan.orgs ?? [];
|
|
4941
5151
|
const organisationField = {
|
|
4942
5152
|
key: ORGANISATION_FIELD_KEY,
|
|
@@ -4958,7 +5168,7 @@ var buildConnectForm = (plan, modelIds) => {
|
|
|
4958
5168
|
type: "string"
|
|
4959
5169
|
};
|
|
4960
5170
|
const budgetFields = orgs.length > 1 ? [organisationField, attributionField] : [attributionField];
|
|
4961
|
-
if (
|
|
5171
|
+
if (key === void 0) return budgetFields;
|
|
4962
5172
|
const promptFields = [
|
|
4963
5173
|
{
|
|
4964
5174
|
key: BUDGET_NAME_FIELD_KEY,
|
|
@@ -4969,7 +5179,7 @@ var buildConnectForm = (plan, modelIds) => {
|
|
|
4969
5179
|
{
|
|
4970
5180
|
key: BUDGET_CAP_FIELD_KEY,
|
|
4971
5181
|
placeholder: "e.g. 50; blank or unlimited = no cap",
|
|
4972
|
-
title: "Monthly budget cap in EUR"
|
|
5182
|
+
title: maximum === void 0 ? "Monthly budget cap in EUR" : `Monthly budget cap in EUR (max ${String(maximum)})`,
|
|
4973
5183
|
type: "string"
|
|
4974
5184
|
},
|
|
4975
5185
|
{
|
|
@@ -4983,17 +5193,41 @@ var buildConnectForm = (plan, modelIds) => {
|
|
|
4983
5193
|
title: "When should the key expire?",
|
|
4984
5194
|
type: "string"
|
|
4985
5195
|
},
|
|
4986
|
-
{
|
|
5196
|
+
key.models.length === 0 ? {
|
|
4987
5197
|
key: ALLOWED_MODELS_FIELD_KEY,
|
|
4988
5198
|
options: [
|
|
4989
|
-
{
|
|
4990
|
-
|
|
5199
|
+
{
|
|
5200
|
+
...key.modelsNote === void 0 ? {} : { description: key.modelsNote },
|
|
5201
|
+
label: ALL_MODELS_LABEL,
|
|
5202
|
+
value: ALL_MODELS_VALUE
|
|
5203
|
+
}
|
|
4991
5204
|
],
|
|
4992
|
-
title:
|
|
5205
|
+
title: ALLOWED_MODELS_TITLE,
|
|
4993
5206
|
type: "string"
|
|
5207
|
+
} : {
|
|
5208
|
+
description: "Select none to allow all models.",
|
|
5209
|
+
key: ALLOWED_MODELS_FIELD_KEY,
|
|
5210
|
+
options: key.models.map(({ id, name }) => ({
|
|
5211
|
+
description: id,
|
|
5212
|
+
label: name,
|
|
5213
|
+
value: id
|
|
5214
|
+
})),
|
|
5215
|
+
title: ALLOWED_MODELS_TITLE,
|
|
5216
|
+
type: "multiselect"
|
|
4994
5217
|
}
|
|
4995
5218
|
];
|
|
4996
|
-
|
|
5219
|
+
const helper = (name, value) => ({
|
|
5220
|
+
hidden: true,
|
|
5221
|
+
key: name,
|
|
5222
|
+
placeholder: value,
|
|
5223
|
+
type: "string"
|
|
5224
|
+
});
|
|
5225
|
+
return [
|
|
5226
|
+
...budgetFields,
|
|
5227
|
+
...promptFields,
|
|
5228
|
+
...maximum === void 0 ? [] : [helper(BUDGET_CAP_MAX_FIELD_KEY, String(maximum))],
|
|
5229
|
+
...key.prepared === void 0 ? [] : [helper(PREPARED_BUDGET_FIELD_KEY, key.prepared)]
|
|
5230
|
+
];
|
|
4997
5231
|
};
|
|
4998
5232
|
|
|
4999
5233
|
// src/v2-entry/direct-key-mode/direct-key-mode.ts
|
|
@@ -5132,8 +5366,8 @@ var gateFallback = async (deps, input, directory) => {
|
|
|
5132
5366
|
};
|
|
5133
5367
|
|
|
5134
5368
|
// src/v2-entry/v2-unattributed-model-gate/v2-unattributed-model-gate.ts
|
|
5135
|
-
var CONNECTION_COPY2 = "
|
|
5136
|
-
var ATTRIBUTION_COPY2 = "This folder has no Route 33 budget
|
|
5369
|
+
var CONNECTION_COPY2 = "To sign in, run /connect and choose Route 33.";
|
|
5370
|
+
var ATTRIBUTION_COPY2 = "This folder has no Route 33 budget; open /r33 and choose Attribute.";
|
|
5137
5371
|
var createV2UnattributedModelGate = (deps) => async (input) => {
|
|
5138
5372
|
if (input.model.providerID !== "route_33") return;
|
|
5139
5373
|
if (!await deps.isConnected()) throw new Error(CONNECTION_COPY2);
|
|
@@ -5173,6 +5407,33 @@ var registerRoute33ModelGate = async (deps) => deps.session.hook(
|
|
|
5173
5407
|
{ providerID: "route_33" }
|
|
5174
5408
|
);
|
|
5175
5409
|
|
|
5410
|
+
// src/v2-entry/session-rpc/session-rpc.ts
|
|
5411
|
+
var ROUTE33_SESSION_RPC = {
|
|
5412
|
+
events: {},
|
|
5413
|
+
id: "route33",
|
|
5414
|
+
methods: {
|
|
5415
|
+
/** Ends the Route 33 session; answers `signedOut: true` once it is gone. */
|
|
5416
|
+
logout: {
|
|
5417
|
+
input: { additionalProperties: false, properties: {}, type: "object" },
|
|
5418
|
+
output: {
|
|
5419
|
+
additionalProperties: false,
|
|
5420
|
+
properties: { signedOut: { type: "boolean" } },
|
|
5421
|
+
required: ["signedOut"],
|
|
5422
|
+
type: "object"
|
|
5423
|
+
}
|
|
5424
|
+
}
|
|
5425
|
+
}
|
|
5426
|
+
};
|
|
5427
|
+
|
|
5428
|
+
// src/v2-entry/register-session-rpc/register-session-rpc.ts
|
|
5429
|
+
var registerSessionRpc = (rpc, deps) => rpc.register(ROUTE33_SESSION_RPC, {
|
|
5430
|
+
logout: async () => {
|
|
5431
|
+
await deps.getRuntime()?.commandHandlers().logout();
|
|
5432
|
+
await deps.registerProjectForm().catch(() => void 0);
|
|
5433
|
+
return { signedOut: true };
|
|
5434
|
+
}
|
|
5435
|
+
});
|
|
5436
|
+
|
|
5176
5437
|
// src/v2-entry/resolve-host-credential/resolve-host-credential.ts
|
|
5177
5438
|
var NO_USABLE_LEASE_MESSAGE = "Signed in to Route 33 \u2713. One more step: this folder has no gateway key yet \u2014 pick its budget to finish setup.";
|
|
5178
5439
|
var resolveHostCredential = async (deps) => {
|
|
@@ -5198,7 +5459,7 @@ var bindingFields = async (plan, binding) => {
|
|
|
5198
5459
|
const confirmations = /* @__PURE__ */ new Map();
|
|
5199
5460
|
const fields = [];
|
|
5200
5461
|
for (const [selection, choice] of Object.entries(plan.choicesBySelection)) {
|
|
5201
|
-
const keys = await binding.candidates(choice)
|
|
5462
|
+
const keys = await binding.candidates(choice);
|
|
5202
5463
|
if (!keys.length) continue;
|
|
5203
5464
|
for (const key of keys) if (!key.local) confirmations.set(key.id, key.name);
|
|
5204
5465
|
fields.push({
|
|
@@ -5230,6 +5491,19 @@ var bindingFields = async (plan, binding) => {
|
|
|
5230
5491
|
return fields;
|
|
5231
5492
|
};
|
|
5232
5493
|
|
|
5494
|
+
// src/v2-entry/selected-budget-form/read-model-choices/read-model-choices.ts
|
|
5495
|
+
var FORBIDDEN = 403;
|
|
5496
|
+
var readModelChoices = async (read) => {
|
|
5497
|
+
try {
|
|
5498
|
+
return { models: await read() };
|
|
5499
|
+
} catch (cause) {
|
|
5500
|
+
return {
|
|
5501
|
+
models: [],
|
|
5502
|
+
modelsNote: cause instanceof ManagementError && cause.statusCode === FORBIDDEN ? KEY_FORM_COPY.modelsNeedSignIn : KEY_FORM_COPY.modelsUnavailable
|
|
5503
|
+
};
|
|
5504
|
+
}
|
|
5505
|
+
};
|
|
5506
|
+
|
|
5233
5507
|
// src/v2-entry/selected-budget-form/selected-budget-form.ts
|
|
5234
5508
|
var selectedBudgetForm = async (plan, selection, runtime2) => {
|
|
5235
5509
|
const option = plan.options.find((row) => row.selection === selection);
|
|
@@ -5241,9 +5515,18 @@ var selectedBudgetForm = async (plan, selection, runtime2) => {
|
|
|
5241
5515
|
options: [option],
|
|
5242
5516
|
choicesBySelection: { [selection]: choice }
|
|
5243
5517
|
};
|
|
5244
|
-
const
|
|
5518
|
+
const choices = await readModelChoices(
|
|
5519
|
+
() => runtime2.catalogModelChoices(choice)
|
|
5520
|
+
);
|
|
5245
5521
|
const keys = await bindingFields(scoped, await runtime2.workspaceKeyBinding());
|
|
5246
|
-
return [
|
|
5522
|
+
return [
|
|
5523
|
+
...buildConnectForm(plan, {
|
|
5524
|
+
...choices,
|
|
5525
|
+
...option.maximum === void 0 ? {} : { maximum: option.maximum },
|
|
5526
|
+
prepared: selection
|
|
5527
|
+
}),
|
|
5528
|
+
...keys
|
|
5529
|
+
];
|
|
5247
5530
|
};
|
|
5248
5531
|
|
|
5249
5532
|
// src/v2-entry/workspace-key-request-hook/workspace-key-request-hook.ts
|
|
@@ -5403,10 +5686,7 @@ var createRoute33V2Plugin = (options = {}) => {
|
|
|
5403
5686
|
"http.request",
|
|
5404
5687
|
createWorkspaceKeyHook({
|
|
5405
5688
|
gatewayBase: readEnvBaseUrl() ?? DEFAULT_BASE_URL,
|
|
5406
|
-
resolveKey: (directory) =>
|
|
5407
|
-
const active = runtime2;
|
|
5408
|
-
return active === void 0 ? Promise.resolve(void 0) : active.resolveWorkspaceCredential(directory);
|
|
5409
|
-
},
|
|
5689
|
+
resolveKey: (directory) => runtime2?.resolveWorkspaceCredential(directory) ?? Promise.resolve(void 0),
|
|
5410
5690
|
session: context.session
|
|
5411
5691
|
})
|
|
5412
5692
|
);
|
|
@@ -5416,6 +5696,10 @@ var createRoute33V2Plugin = (options = {}) => {
|
|
|
5416
5696
|
listSessions: async () => (await context.session.list()).data,
|
|
5417
5697
|
session: context.session
|
|
5418
5698
|
});
|
|
5699
|
+
const sessionRpc = await registerSessionRpc(context.rpc, {
|
|
5700
|
+
getRuntime: () => runtime2,
|
|
5701
|
+
registerProjectForm
|
|
5702
|
+
});
|
|
5419
5703
|
await bootstrapProvider(
|
|
5420
5704
|
{
|
|
5421
5705
|
getRuntime: () => runtime2,
|
|
@@ -5435,7 +5719,8 @@ var createRoute33V2Plugin = (options = {}) => {
|
|
|
5435
5719
|
integrationTransform.dispose(),
|
|
5436
5720
|
providerTransform.dispose(),
|
|
5437
5721
|
sessionHook.dispose(),
|
|
5438
|
-
modelGate.dispose()
|
|
5722
|
+
modelGate.dispose(),
|
|
5723
|
+
sessionRpc.dispose()
|
|
5439
5724
|
]);
|
|
5440
5725
|
};
|
|
5441
5726
|
}
|