@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/index.js
CHANGED
|
@@ -2183,9 +2183,11 @@ var KeyLeaseError = class extends Error {
|
|
|
2183
2183
|
);
|
|
2184
2184
|
this.code = code;
|
|
2185
2185
|
this.name = "KeyLeaseError";
|
|
2186
|
+
this.rejection = options?.rejection;
|
|
2186
2187
|
this.statusCode = options?.statusCode;
|
|
2187
2188
|
}
|
|
2188
2189
|
code;
|
|
2190
|
+
rejection;
|
|
2189
2191
|
statusCode;
|
|
2190
2192
|
};
|
|
2191
2193
|
|
|
@@ -2350,6 +2352,33 @@ var commitStagedReplacement = async (stage, save, persist) => {
|
|
|
2350
2352
|
}
|
|
2351
2353
|
};
|
|
2352
2354
|
|
|
2355
|
+
// src/management/management-error/management-error.ts
|
|
2356
|
+
var ManagementError = class extends Error {
|
|
2357
|
+
constructor(code, options) {
|
|
2358
|
+
super(
|
|
2359
|
+
"Route 33 management request failed",
|
|
2360
|
+
options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
|
|
2361
|
+
);
|
|
2362
|
+
this.code = code;
|
|
2363
|
+
this.name = "ManagementError";
|
|
2364
|
+
this.rejection = options?.rejection;
|
|
2365
|
+
this.statusCode = options?.statusCode;
|
|
2366
|
+
}
|
|
2367
|
+
code;
|
|
2368
|
+
rejection;
|
|
2369
|
+
statusCode;
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
// src/key-lease/mint-failure/mint-failure.ts
|
|
2373
|
+
var mintFailure = (cause) => {
|
|
2374
|
+
const response = cause instanceof ManagementError ? cause : void 0;
|
|
2375
|
+
return new KeyLeaseError("KEY_LEASE_MINT_FAILED", {
|
|
2376
|
+
cause,
|
|
2377
|
+
...response?.rejection === void 0 ? {} : { rejection: response.rejection },
|
|
2378
|
+
...response?.statusCode === void 0 ? {} : { statusCode: response.statusCode }
|
|
2379
|
+
});
|
|
2380
|
+
};
|
|
2381
|
+
|
|
2353
2382
|
// src/key-lease/mint-fresh-lease/mint-fresh-lease.ts
|
|
2354
2383
|
var mintFreshLease = async (deps) => {
|
|
2355
2384
|
const now = deps.clock();
|
|
@@ -2380,7 +2409,7 @@ var mintFreshLease = async (deps) => {
|
|
|
2380
2409
|
input
|
|
2381
2410
|
);
|
|
2382
2411
|
} catch (cause) {
|
|
2383
|
-
throw
|
|
2412
|
+
throw mintFailure(cause);
|
|
2384
2413
|
}
|
|
2385
2414
|
const minted = {
|
|
2386
2415
|
key: material.key,
|
|
@@ -2463,21 +2492,6 @@ var rejectLease = async (options) => {
|
|
|
2463
2492
|
}
|
|
2464
2493
|
};
|
|
2465
2494
|
|
|
2466
|
-
// src/management/management-error/management-error.ts
|
|
2467
|
-
var ManagementError = class extends Error {
|
|
2468
|
-
constructor(code, options) {
|
|
2469
|
-
super(
|
|
2470
|
-
"Route 33 management request failed",
|
|
2471
|
-
options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
|
|
2472
|
-
);
|
|
2473
|
-
this.code = code;
|
|
2474
|
-
this.name = "ManagementError";
|
|
2475
|
-
this.statusCode = options?.statusCode;
|
|
2476
|
-
}
|
|
2477
|
-
code;
|
|
2478
|
-
statusCode;
|
|
2479
|
-
};
|
|
2480
|
-
|
|
2481
2495
|
// src/key-lease/mint-key/mint-key.ts
|
|
2482
2496
|
var mintKey = async (options) => {
|
|
2483
2497
|
const now = options.clock();
|
|
@@ -2511,10 +2525,7 @@ var mintKey = async (options) => {
|
|
|
2511
2525
|
if (isManagementUnauthorized(cause)) {
|
|
2512
2526
|
throw new KeyLeaseError("KEY_LEASE_UNAUTHORIZED", { cause });
|
|
2513
2527
|
}
|
|
2514
|
-
throw
|
|
2515
|
-
cause,
|
|
2516
|
-
...cause instanceof ManagementError && cause.statusCode !== void 0 ? { statusCode: cause.statusCode } : {}
|
|
2517
|
-
});
|
|
2528
|
+
throw mintFailure(cause);
|
|
2518
2529
|
}
|
|
2519
2530
|
return {
|
|
2520
2531
|
key: material.key,
|
|
@@ -2852,6 +2863,7 @@ var inspectSession = (options) => {
|
|
|
2852
2863
|
const lease = options.readLease();
|
|
2853
2864
|
return {
|
|
2854
2865
|
attribution,
|
|
2866
|
+
connected: options.connected,
|
|
2855
2867
|
...lease === void 0 ? {} : { lease: { expiresAt: lease.expiresAt, keyId: lease.keyId } }
|
|
2856
2868
|
};
|
|
2857
2869
|
};
|
|
@@ -2882,10 +2894,10 @@ var WorkspaceKeyBinding = class {
|
|
|
2882
2894
|
* @returns Secret-free options; local options do not need destructive consent.
|
|
2883
2895
|
*/
|
|
2884
2896
|
async candidates(choice) {
|
|
2885
|
-
const listing = this.#listings.get(choice.orgId) ?? this.
|
|
2897
|
+
const listing = this.#listings.get(choice.orgId) ?? this.listKeys(choice.orgId);
|
|
2886
2898
|
this.#listings.set(choice.orgId, listing);
|
|
2887
2899
|
const rows = await listing;
|
|
2888
|
-
const keys = rows.
|
|
2900
|
+
const keys = rows.filter((row) => this.matches(row, choice));
|
|
2889
2901
|
if (keys.length === 0) return [];
|
|
2890
2902
|
const local = await this.localKeys(new Set(keys.map((row) => row.id)));
|
|
2891
2903
|
return keys.map((row) => ({
|
|
@@ -2894,8 +2906,18 @@ var WorkspaceKeyBinding = class {
|
|
|
2894
2906
|
local: local.has(row.id)
|
|
2895
2907
|
}));
|
|
2896
2908
|
}
|
|
2909
|
+
async listKeys(orgId) {
|
|
2910
|
+
try {
|
|
2911
|
+
return (await this.deps.client.list(this.deps.token, orgId)).data;
|
|
2912
|
+
} catch {
|
|
2913
|
+
logger.warn(
|
|
2914
|
+
"Existing keys could not be listed; only new keys can be offered."
|
|
2915
|
+
);
|
|
2916
|
+
return [];
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2897
2919
|
matches(row, choice) {
|
|
2898
|
-
return row.status === "active" && !row.revoked && Date.parse(row.expires_at) > this.deps.now && (choice.orgId === void 0 || row.org_id === choice.orgId) && row.
|
|
2920
|
+
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");
|
|
2899
2921
|
}
|
|
2900
2922
|
async localKeys(ids) {
|
|
2901
2923
|
const found = /* @__PURE__ */ new Map();
|
|
@@ -2994,6 +3016,8 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
2994
3016
|
return `Personal \u2014 your own key${marker}${orgSuffix}`;
|
|
2995
3017
|
};
|
|
2996
3018
|
const budgetAllowance = (project) => {
|
|
3019
|
+
if (project.memberCap !== void 0)
|
|
3020
|
+
return `cap ${String(project.memberCap)} EUR`;
|
|
2997
3021
|
const budget = project.effective_budget ?? project.max_budget;
|
|
2998
3022
|
return budget === null ? "no cap set" : `cap ${budget.amount} ${budget.currency}`;
|
|
2999
3023
|
};
|
|
@@ -3008,6 +3032,7 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
3008
3032
|
};
|
|
3009
3033
|
return {
|
|
3010
3034
|
label: `${project.organisation.name} \xB7 ${project.name} \u2014 ${budgetAllowance(project)}`,
|
|
3035
|
+
maximum: project.memberCap,
|
|
3011
3036
|
selection
|
|
3012
3037
|
};
|
|
3013
3038
|
});
|
|
@@ -3027,6 +3052,7 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
3027
3052
|
choicesBySelection[personal] = { kind: "personal", orgId: org.id };
|
|
3028
3053
|
promptOptions.push({
|
|
3029
3054
|
label: personalLabel(options.orgs.length > 1 ? org.name : void 0),
|
|
3055
|
+
maximum: org.personalBudget?.cap ?? void 0,
|
|
3030
3056
|
selection: personal
|
|
3031
3057
|
});
|
|
3032
3058
|
}
|
|
@@ -3042,6 +3068,7 @@ var createAttributionPrompt = (projects, options = {}) => {
|
|
|
3042
3068
|
};
|
|
3043
3069
|
promptOptions.push({
|
|
3044
3070
|
label: `${project.organisation.name} \xB7 ${project.name} \u2014 ${budgetAllowance(project)}`,
|
|
3071
|
+
maximum: project.memberCap,
|
|
3045
3072
|
selection
|
|
3046
3073
|
});
|
|
3047
3074
|
}
|
|
@@ -3061,8 +3088,8 @@ var isPersonalSelection = (selection) => selection === "personal" || selection.e
|
|
|
3061
3088
|
// src/ux/attribution-prompt-error/attribution-prompt-error.ts
|
|
3062
3089
|
var MESSAGES = {
|
|
3063
3090
|
ATTRIBUTION_BACK: "Left budget selection without changing attribution.",
|
|
3064
|
-
ATTRIBUTION_PRESENTER_UNAVAILABLE: "
|
|
3065
|
-
ATTRIBUTION_SELECTION_INVALID: "That Route 33 option is no longer available
|
|
3091
|
+
ATTRIBUTION_PRESENTER_UNAVAILABLE: "Update to OpenCode v2 to assign a Route 33 budget in this folder.",
|
|
3092
|
+
ATTRIBUTION_SELECTION_INVALID: "That Route 33 option is no longer available; choose another budget."
|
|
3066
3093
|
};
|
|
3067
3094
|
var AttributionPromptError = class extends GatewayCredentialError {
|
|
3068
3095
|
code;
|
|
@@ -3181,7 +3208,7 @@ import {
|
|
|
3181
3208
|
} from "@r-33/auth-browser";
|
|
3182
3209
|
|
|
3183
3210
|
// src/requested-scopes/requested-scopes.ts
|
|
3184
|
-
var REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read profile projects:read users:read keys:read keys:write";
|
|
3211
|
+
var REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read profile projects:read users:read keys:read keys:write models:read";
|
|
3185
3212
|
|
|
3186
3213
|
// src/route33-login/route33-login.ts
|
|
3187
3214
|
var route33Login = async (options) => {
|
|
@@ -3210,20 +3237,34 @@ var LoginSession = class {
|
|
|
3210
3237
|
#options;
|
|
3211
3238
|
#result;
|
|
3212
3239
|
#expiresAt;
|
|
3240
|
+
#clears = 0;
|
|
3213
3241
|
constructor(options) {
|
|
3214
3242
|
this.#options = options;
|
|
3215
3243
|
}
|
|
3216
3244
|
/**
|
|
3217
3245
|
* Clears the session: the cached login result and the stored refresh
|
|
3218
3246
|
* token. The next login starts from scratch — /r33 logout and the
|
|
3219
|
-
* auto-reconnect path both land here.
|
|
3247
|
+
* auto-reconnect path both land here. A refresh still on its way to the
|
|
3248
|
+
* auth server is disowned: its rotated token is never stored.
|
|
3220
3249
|
* @returns Resolved once the session and the stored refresh token are gone.
|
|
3221
3250
|
*/
|
|
3222
3251
|
async clear() {
|
|
3252
|
+
this.#clears += 1;
|
|
3223
3253
|
this.#result = void 0;
|
|
3224
3254
|
this.#expiresAt = void 0;
|
|
3225
3255
|
await this.#options.tokenStore?.set(void 0);
|
|
3226
3256
|
}
|
|
3257
|
+
/**
|
|
3258
|
+
* Whether a session exists, judged without using it: a login resolved or
|
|
3259
|
+
* in flight in this process, or a stored refresh token. Read-only — the
|
|
3260
|
+
* token is never presented, so asking cannot rotate or revoke anything.
|
|
3261
|
+
* @returns True when there is a session to sign in with.
|
|
3262
|
+
*/
|
|
3263
|
+
async hasSession() {
|
|
3264
|
+
if (this.#result !== void 0) return true;
|
|
3265
|
+
const stored = await this.#options.tokenStore?.get().catch(() => void 0);
|
|
3266
|
+
return stored !== void 0 && stored !== "";
|
|
3267
|
+
}
|
|
3227
3268
|
/**
|
|
3228
3269
|
* Resolves the login once per process, sharing in-flight attempts.
|
|
3229
3270
|
* @param policy - Whether this attempt may start a browser login; an in-flight attempt is always shared.
|
|
@@ -3232,11 +3273,15 @@ var LoginSession = class {
|
|
|
3232
3273
|
result(policy = {}) {
|
|
3233
3274
|
if (this.#result !== void 0 && this.#expiresAt !== void 0 && Date.now() >= this.#expiresAt - EXPIRY_SKEW_MS) {
|
|
3234
3275
|
this.#result = void 0;
|
|
3276
|
+
this.#expiresAt = void 0;
|
|
3277
|
+
}
|
|
3278
|
+
if (this.#result === void 0) {
|
|
3279
|
+
const attempt = this.#start(policy).catch((cause) => {
|
|
3280
|
+
if (this.#result === attempt) this.#result = void 0;
|
|
3281
|
+
throw cause;
|
|
3282
|
+
});
|
|
3283
|
+
this.#result = attempt;
|
|
3235
3284
|
}
|
|
3236
|
-
this.#result ??= this.#start(policy).catch((cause) => {
|
|
3237
|
-
this.#result = void 0;
|
|
3238
|
-
throw cause;
|
|
3239
|
-
});
|
|
3240
3285
|
return this.#result;
|
|
3241
3286
|
}
|
|
3242
3287
|
/**
|
|
@@ -3266,6 +3311,7 @@ var LoginSession = class {
|
|
|
3266
3311
|
if (tokenStore === void 0) {
|
|
3267
3312
|
return void 0;
|
|
3268
3313
|
}
|
|
3314
|
+
const clears = this.#clears;
|
|
3269
3315
|
const stored = await tokenStore.get();
|
|
3270
3316
|
if (stored === void 0 || stored === "") {
|
|
3271
3317
|
return void 0;
|
|
@@ -3274,6 +3320,9 @@ var LoginSession = class {
|
|
|
3274
3320
|
if (tokenSet === void 0) {
|
|
3275
3321
|
return void 0;
|
|
3276
3322
|
}
|
|
3323
|
+
if (clears !== this.#clears) {
|
|
3324
|
+
throw new AuthError2("AUTH_REAUTHENTICATION_REQUIRED");
|
|
3325
|
+
}
|
|
3277
3326
|
let credential;
|
|
3278
3327
|
try {
|
|
3279
3328
|
credential = parseManagementJwt(tokenSet.access_token);
|
|
@@ -3407,7 +3456,7 @@ var Route33Runtime = class {
|
|
|
3407
3456
|
const projectsById = new Map(
|
|
3408
3457
|
listings.flatMap(({ data }) => data).map((project) => [project.id, project])
|
|
3409
3458
|
);
|
|
3410
|
-
return rows.flatMap(({ org_id, project_id }) => {
|
|
3459
|
+
return rows.flatMap(({ org_id, project_id, cap }) => {
|
|
3411
3460
|
const project = projectsById.get(project_id);
|
|
3412
3461
|
if (project === void 0) {
|
|
3413
3462
|
return [];
|
|
@@ -3415,6 +3464,7 @@ var Route33Runtime = class {
|
|
|
3415
3464
|
return [
|
|
3416
3465
|
{
|
|
3417
3466
|
...project,
|
|
3467
|
+
memberCap: cap,
|
|
3418
3468
|
organisation: {
|
|
3419
3469
|
id: org_id,
|
|
3420
3470
|
name: organisationNames.get(org_id) ?? org_id
|
|
@@ -3544,6 +3594,7 @@ var Route33Runtime = class {
|
|
|
3544
3594
|
await this.#hydrateState(installation);
|
|
3545
3595
|
}
|
|
3546
3596
|
const base = inspectSession({
|
|
3597
|
+
connected: await this.#session.hasSession(),
|
|
3547
3598
|
readAttribution: () => attribution,
|
|
3548
3599
|
readLease: () => installation?.state.snapshot()
|
|
3549
3600
|
});
|
|
@@ -3551,10 +3602,9 @@ var Route33Runtime = class {
|
|
|
3551
3602
|
if (attribution === void 0 || keyId === void 0) {
|
|
3552
3603
|
return base;
|
|
3553
3604
|
}
|
|
3605
|
+
const credential = await this.#session.credential({ allowBrowser: false }).catch(() => void 0);
|
|
3606
|
+
if (credential === void 0) return { ...base, connected: false };
|
|
3554
3607
|
try {
|
|
3555
|
-
const credential = await this.#session.credential({
|
|
3556
|
-
allowBrowser: false
|
|
3557
|
-
});
|
|
3558
3608
|
const details = await enrichInspection({
|
|
3559
3609
|
attribution,
|
|
3560
3610
|
client: this.#client(),
|
|
@@ -3567,16 +3617,24 @@ var Route33Runtime = class {
|
|
|
3567
3617
|
return base;
|
|
3568
3618
|
}
|
|
3569
3619
|
}
|
|
3620
|
+
/**
|
|
3621
|
+
* Lists the models a key on this budget may be limited to. Never opens a
|
|
3622
|
+
* browser; an organisation-level (personal) catalog needs the `models:read`
|
|
3623
|
+
* grant, so sessions signed in before that grant reject here.
|
|
3624
|
+
* @param scope - The budget being configured.
|
|
3625
|
+
* @returns Key-facing model ids with their readable names.
|
|
3626
|
+
*/
|
|
3627
|
+
async catalogModelChoices(scope) {
|
|
3628
|
+
const credential = await this.#session.credential({ allowBrowser: false });
|
|
3629
|
+
return this.#client().listModelChoices(credential, scope);
|
|
3630
|
+
}
|
|
3570
3631
|
/**
|
|
3571
3632
|
* @param scope - The budget being configured. Omit to discover models for the current key.
|
|
3572
3633
|
* @returns The management catalog for a budget, or the current key's gateway catalog.
|
|
3573
3634
|
*/
|
|
3574
3635
|
async catalogModelIds(scope) {
|
|
3575
3636
|
if (scope !== void 0) {
|
|
3576
|
-
|
|
3577
|
-
allowBrowser: false
|
|
3578
|
-
});
|
|
3579
|
-
return this.#client().listModelIds(credential, scope);
|
|
3637
|
+
return (await this.catalogModelChoices(scope)).map(({ id }) => id);
|
|
3580
3638
|
}
|
|
3581
3639
|
const workspace = await this.storedReusableKey();
|
|
3582
3640
|
const personal = workspace === void 0 ? await this.#storedPersonalKey() : void 0;
|
|
@@ -3585,7 +3643,8 @@ var Route33Runtime = class {
|
|
|
3585
3643
|
const credential = await this.#session.credential({
|
|
3586
3644
|
allowBrowser: false
|
|
3587
3645
|
});
|
|
3588
|
-
|
|
3646
|
+
const choices = await this.#client().listModelChoices(credential, {});
|
|
3647
|
+
return choices.map(({ id }) => id);
|
|
3589
3648
|
}
|
|
3590
3649
|
return gatewayModelIds({
|
|
3591
3650
|
baseURL: readEnvBaseUrl() ?? DEFAULT_BASE_URL,
|
|
@@ -3666,6 +3725,29 @@ var Route33Runtime = class {
|
|
|
3666
3725
|
const key = keys.find((item) => item.id === keyId);
|
|
3667
3726
|
return key === void 0 ? void 0 : { allowedModels: key.allowed_models };
|
|
3668
3727
|
}
|
|
3728
|
+
/** V1 captures only the choice, not the plan; read only that owner's policy.
|
|
3729
|
+
* @param choice - The selected budget and its active organisation.
|
|
3730
|
+
* @returns The effective EUR cap, if the owner has a readable allowance.
|
|
3731
|
+
*/
|
|
3732
|
+
async ownerBudgetCap(choice) {
|
|
3733
|
+
const token = await this.#session.credential({ allowBrowser: false });
|
|
3734
|
+
const subject = this.#subject(token);
|
|
3735
|
+
const client = this.#client();
|
|
3736
|
+
if (choice.kind === "personal") {
|
|
3737
|
+
const policy = await client.listBudgetPolicy(
|
|
3738
|
+
token,
|
|
3739
|
+
subject,
|
|
3740
|
+
choice.orgId
|
|
3741
|
+
);
|
|
3742
|
+
return policy.cap ?? void 0;
|
|
3743
|
+
}
|
|
3744
|
+
const budgets = await client.listProjectBudgets(
|
|
3745
|
+
token,
|
|
3746
|
+
subject,
|
|
3747
|
+
choice.orgId
|
|
3748
|
+
);
|
|
3749
|
+
return budgets.data.find((row) => row.project_id === choice.projectId)?.cap;
|
|
3750
|
+
}
|
|
3669
3751
|
#client() {
|
|
3670
3752
|
const client = this.#options.management.client;
|
|
3671
3753
|
if (typeof client !== "function") {
|
|
@@ -3781,8 +3863,8 @@ var Route33Runtime = class {
|
|
|
3781
3863
|
};
|
|
3782
3864
|
|
|
3783
3865
|
// src/v1-entry/unattributed-prompt-gate/unattributed-prompt-gate.ts
|
|
3784
|
-
var CONNECTION_COPY = "
|
|
3785
|
-
var ATTRIBUTION_COPY = "This folder has no Route 33 budget
|
|
3866
|
+
var CONNECTION_COPY = "To sign in, run /connect and choose Route 33.";
|
|
3867
|
+
var ATTRIBUTION_COPY = "This folder has no Route 33 budget; open /r33 and choose Change budget.";
|
|
3786
3868
|
var createUnattributedPromptGate = ({ directory, isConnected, outsideWorktree }) => async (input) => {
|
|
3787
3869
|
if (input.model?.providerID !== "route_33") return Promise.resolve();
|
|
3788
3870
|
if (!await isConnected()) throw new Error(CONNECTION_COPY);
|
|
@@ -3929,7 +4011,7 @@ var parseApiKey = (value) => {
|
|
|
3929
4011
|
name: field("name"),
|
|
3930
4012
|
org_id: field("org_id"),
|
|
3931
4013
|
ownership_type: value["ownership_type"],
|
|
3932
|
-
...
|
|
4014
|
+
...isNullableString(value["user_id"]) ? { user_id: value["user_id"] } : {},
|
|
3933
4015
|
project_id: value["project_id"],
|
|
3934
4016
|
revoked: value["revoked"] === true,
|
|
3935
4017
|
status
|
|
@@ -4172,6 +4254,18 @@ var keyReadOperations = (call) => {
|
|
|
4172
4254
|
url.searchParams.set("cursor", cursor);
|
|
4173
4255
|
return new Request(url, request);
|
|
4174
4256
|
};
|
|
4257
|
+
const parsePage = (page) => {
|
|
4258
|
+
const collection = parseCollection(page, (row) => row);
|
|
4259
|
+
const data = collection.data.flatMap((row) => {
|
|
4260
|
+
try {
|
|
4261
|
+
return [parseApiKey(row)];
|
|
4262
|
+
} catch (error) {
|
|
4263
|
+
if (error instanceof ContractParseError) return [];
|
|
4264
|
+
throw error;
|
|
4265
|
+
}
|
|
4266
|
+
});
|
|
4267
|
+
return { ...collection, data };
|
|
4268
|
+
};
|
|
4175
4269
|
return {
|
|
4176
4270
|
get: async (accessToken, id, orgId) => parseApiKey(
|
|
4177
4271
|
await call(
|
|
@@ -4186,7 +4280,7 @@ var keyReadOperations = (call) => {
|
|
|
4186
4280
|
(cursor) => call(accessToken, orgId, (client) => {
|
|
4187
4281
|
if (cursor !== "") client.use({ onRequest: withCursor(cursor) });
|
|
4188
4282
|
return client.GET("/api/v1/api-keys", {});
|
|
4189
|
-
}).then(
|
|
4283
|
+
}).then(parsePage)
|
|
4190
4284
|
)
|
|
4191
4285
|
};
|
|
4192
4286
|
};
|
|
@@ -4250,29 +4344,55 @@ var keyWriteOperations = (call) => ({
|
|
|
4250
4344
|
)
|
|
4251
4345
|
});
|
|
4252
4346
|
|
|
4253
|
-
// src/management/
|
|
4254
|
-
var
|
|
4255
|
-
const
|
|
4347
|
+
// src/management/client-model-id/client-model-id.ts
|
|
4348
|
+
var clientModelId = (offeringId) => {
|
|
4349
|
+
const [provider, region, scope, vendor, ...modelParts] = offeringId.split(":");
|
|
4350
|
+
const slugParts = modelParts.at(-1) === "zdr" ? modelParts.slice(0, -1) : modelParts;
|
|
4351
|
+
const parts = [provider, region, scope, vendor, slugParts.join(":")];
|
|
4352
|
+
return parts.some((part) => part === void 0 || part === "") || /[\s,]/u.test(offeringId) ? void 0 : `${vendor ?? ""}/${slugParts.join(":")}`;
|
|
4353
|
+
};
|
|
4354
|
+
|
|
4355
|
+
// src/management/exposed-catalog-models/catalog-row-choices/catalog-row-choices.ts
|
|
4356
|
+
var catalogRowChoices = (row) => {
|
|
4357
|
+
if (!isRecord(row) || typeof row.id !== "string" || !row.id.trim() || typeof row.status !== "string")
|
|
4358
|
+
throw new ContractParseError("invalid model catalog item");
|
|
4359
|
+
if (row.status !== "exposed" || !Array.isArray(row.offerings)) return [];
|
|
4360
|
+
const label = typeof row.name === "string" && row.name.trim() !== "" ? row.name.trim() : void 0;
|
|
4361
|
+
return row.offerings.flatMap((offering) => {
|
|
4362
|
+
if (!isRecord(offering) || typeof offering.id !== "string" || offering.enabled !== true)
|
|
4363
|
+
return [];
|
|
4364
|
+
const id = clientModelId(offering.id);
|
|
4365
|
+
return id === void 0 ? [] : [{ id, name: label ?? id }];
|
|
4366
|
+
});
|
|
4367
|
+
};
|
|
4368
|
+
|
|
4369
|
+
// src/management/exposed-catalog-models/exposed-catalog-models.ts
|
|
4370
|
+
var exposedCatalogModels = async (readPage) => {
|
|
4371
|
+
const readRows = async (offset2) => {
|
|
4372
|
+
const page = await readPage(offset2);
|
|
4373
|
+
if (!isRecord(page) || !Array.isArray(page.models) || page.offset !== offset2 || typeof page.total !== "number" || !Number.isSafeInteger(page.total) || page.total < 0) {
|
|
4374
|
+
throw new ContractParseError("invalid model catalog page");
|
|
4375
|
+
}
|
|
4376
|
+
return { rows: page.models, total: page.total };
|
|
4377
|
+
};
|
|
4378
|
+
const names = /* @__PURE__ */ new Map();
|
|
4256
4379
|
let offset = 0;
|
|
4257
4380
|
for (; ; ) {
|
|
4258
|
-
const
|
|
4259
|
-
|
|
4260
|
-
|
|
4381
|
+
const { rows, total } = await readRows(offset);
|
|
4382
|
+
for (const { id, name } of rows.flatMap(catalogRowChoices)) {
|
|
4383
|
+
names.set(id, name);
|
|
4261
4384
|
}
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
throw new ContractParseError("invalid model catalog item");
|
|
4265
|
-
if (row.status === "exposed") ids.add(row.id);
|
|
4266
|
-
});
|
|
4267
|
-
offset += page.models.length;
|
|
4268
|
-
if (offset >= page.total || page.models.length === 0)
|
|
4269
|
-
return [...ids].sort((left, right) => left.localeCompare(right));
|
|
4385
|
+
offset += rows.length;
|
|
4386
|
+
if (offset >= total || rows.length === 0) break;
|
|
4270
4387
|
}
|
|
4388
|
+
return [...names].map(([id, name]) => ({ id, name })).sort(
|
|
4389
|
+
(left, right) => left.name.localeCompare(right.name) || left.id.localeCompare(right.id)
|
|
4390
|
+
);
|
|
4271
4391
|
};
|
|
4272
4392
|
|
|
4273
4393
|
// src/management/model-catalog-operations/model-catalog-operations.ts
|
|
4274
4394
|
var modelCatalogOperations = (call) => ({
|
|
4275
|
-
|
|
4395
|
+
listModelChoices: (token, { orgId, projectId }) => exposedCatalogModels(
|
|
4276
4396
|
(offset) => call(token, orgId, (client) => {
|
|
4277
4397
|
const query = { offset };
|
|
4278
4398
|
if (projectId !== void 0)
|
|
@@ -4329,6 +4449,29 @@ import {
|
|
|
4329
4449
|
createRoute33Client,
|
|
4330
4450
|
Route33SdkError
|
|
4331
4451
|
} from "@r-33/sdk";
|
|
4452
|
+
|
|
4453
|
+
// src/management/sdk-management-call/rejection-of/rejection-of.ts
|
|
4454
|
+
var REFUSED = 422;
|
|
4455
|
+
var REJECTION_MAX_LENGTH = 200;
|
|
4456
|
+
var CONTROL = /\p{Cc}+/gu;
|
|
4457
|
+
var SECRET_PREFIXES = ["r33_", "eyj", "bearer "];
|
|
4458
|
+
var OPAQUE_MIN_LENGTH = 20;
|
|
4459
|
+
var rejectionOf = (outcome) => {
|
|
4460
|
+
const body = outcome.error;
|
|
4461
|
+
if (outcome.response?.status !== REFUSED || !isRecord(body)) return void 0;
|
|
4462
|
+
const raw = body["error"];
|
|
4463
|
+
if (typeof raw !== "string" || raw.length > REJECTION_MAX_LENGTH) {
|
|
4464
|
+
return void 0;
|
|
4465
|
+
}
|
|
4466
|
+
const sentence = raw.replaceAll(CONTROL, " ").replaceAll(/\s+/gu, " ").trim();
|
|
4467
|
+
const lower = sentence.toLowerCase();
|
|
4468
|
+
const secretShaped = SECRET_PREFIXES.some((prefix) => lower.includes(prefix)) || lower.split(" ").some(
|
|
4469
|
+
(word) => word.length >= OPAQUE_MIN_LENGTH && /\d/u.test(word) && /[a-z]/u.test(word)
|
|
4470
|
+
);
|
|
4471
|
+
return sentence === "" || secretShaped ? void 0 : sentence;
|
|
4472
|
+
};
|
|
4473
|
+
|
|
4474
|
+
// src/management/sdk-management-call/sdk-management-call.ts
|
|
4332
4475
|
var API_PREFIX_PATTERN = /\/api\/v1\/?$/;
|
|
4333
4476
|
var ACTIVE_ORG_HEADER = "X-Active-Org-Id";
|
|
4334
4477
|
var createSdkCall = (options) => {
|
|
@@ -4375,9 +4518,13 @@ var createSdkCall = (options) => {
|
|
|
4375
4518
|
const outcome = await run(callClient(accessToken, activeOrgId));
|
|
4376
4519
|
const code = outcome.response?.status;
|
|
4377
4520
|
if (code === void 0 || code < 200 || code >= 300) {
|
|
4521
|
+
const rejection = rejectionOf(outcome);
|
|
4378
4522
|
throw new ManagementError(
|
|
4379
4523
|
code === 401 ? "MANAGEMENT_UNAUTHORIZED" : "MANAGEMENT_HTTP_ERROR",
|
|
4380
|
-
{
|
|
4524
|
+
{
|
|
4525
|
+
...rejection === void 0 ? {} : { rejection },
|
|
4526
|
+
statusCode: code
|
|
4527
|
+
}
|
|
4381
4528
|
);
|
|
4382
4529
|
}
|
|
4383
4530
|
return outcome.data;
|