@r-33/opencode 0.4.7-rc.31 → 0.4.7-rc.32
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 +4 -1
- package/dist/index.js +6 -3
- package/dist/tui-entry/index.js +96 -61
- package/dist/v2-entry/index.js +153 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,7 +80,10 @@ silently.
|
|
|
80
80
|
| `/r33 inspect` | Show the assigned budget, the active key, and its rotation state |
|
|
81
81
|
| `/r33 rotate` | Rotate the key immediately |
|
|
82
82
|
| `/r33 reset` | Clear the assigned budget — the wizard runs again on the next start |
|
|
83
|
-
|
|
83
|
+
|
|
84
|
+
To sign out, run `/connect`, choose Route 33, select your account and press
|
|
85
|
+
Ctrl+D twice. Once the last account is removed, the plugin forgets its
|
|
86
|
+
sign-in on this machine; your key and budget stay.
|
|
84
87
|
|
|
85
88
|
The menu's budget entry — **Attribute** on OpenCode v2, **Change budget**
|
|
86
89
|
on v1 — reopens the budget picker and the key setup for this folder.
|
package/dist/index.js
CHANGED
|
@@ -3243,8 +3243,8 @@ var LoginSession = class {
|
|
|
3243
3243
|
}
|
|
3244
3244
|
/**
|
|
3245
3245
|
* Clears the session: the cached login result and the stored refresh
|
|
3246
|
-
* token. The next login starts from scratch —
|
|
3247
|
-
* auto-reconnect path both land here. A refresh still on its way to the
|
|
3246
|
+
* token. The next login starts from scratch — the removal of the host's
|
|
3247
|
+
* last Route 33 account and the auto-reconnect path both land here. A refresh still on its way to the
|
|
3248
3248
|
* auth server is disowned: its rotated token is never stored.
|
|
3249
3249
|
* @returns Resolved once the session and the stored refresh token are gone.
|
|
3250
3250
|
*/
|
|
@@ -3580,7 +3580,10 @@ var Route33Runtime = class {
|
|
|
3580
3580
|
}),
|
|
3581
3581
|
logout: () => this.#session.clear(),
|
|
3582
3582
|
"rotate-now": () => rotateNow({
|
|
3583
|
-
lease: (policy) =>
|
|
3583
|
+
lease: async (policy) => {
|
|
3584
|
+
await this.#session.credential({ allowBrowser: false });
|
|
3585
|
+
return this.#lease({ ...this.#options.policy, ...policy });
|
|
3586
|
+
}
|
|
3584
3587
|
})
|
|
3585
3588
|
};
|
|
3586
3589
|
}
|
package/dist/tui-entry/index.js
CHANGED
|
@@ -6272,8 +6272,8 @@ var init_login_session = __esm({
|
|
|
6272
6272
|
}
|
|
6273
6273
|
/**
|
|
6274
6274
|
* Clears the session: the cached login result and the stored refresh
|
|
6275
|
-
* token. The next login starts from scratch —
|
|
6276
|
-
* auto-reconnect path both land here. A refresh still on its way to the
|
|
6275
|
+
* token. The next login starts from scratch — the removal of the host's
|
|
6276
|
+
* last Route 33 account and the auto-reconnect path both land here. A refresh still on its way to the
|
|
6277
6277
|
* auth server is disowned: its rotated token is never stored.
|
|
6278
6278
|
* @returns Resolved once the session and the stored refresh token are gone.
|
|
6279
6279
|
*/
|
|
@@ -6637,7 +6637,10 @@ var init_route33_runtime = __esm({
|
|
|
6637
6637
|
}),
|
|
6638
6638
|
logout: () => this.#session.clear(),
|
|
6639
6639
|
"rotate-now": () => rotateNow({
|
|
6640
|
-
lease: (policy) =>
|
|
6640
|
+
lease: async (policy) => {
|
|
6641
|
+
await this.#session.credential({ allowBrowser: false });
|
|
6642
|
+
return this.#lease({ ...this.#options.policy, ...policy });
|
|
6643
|
+
}
|
|
6641
6644
|
})
|
|
6642
6645
|
};
|
|
6643
6646
|
}
|
|
@@ -7815,6 +7818,9 @@ var selectFromDialog = async (api, input) => new Promise((resolve2) => {
|
|
|
7815
7818
|
// src/tui-entry/r33-command-reply/r33-command-reply.ts
|
|
7816
7819
|
init_create_route33_plugin2();
|
|
7817
7820
|
|
|
7821
|
+
// src/v2-entry/r33-command/r33-command.ts
|
|
7822
|
+
import { AuthError as AuthError3 } from "@r-33/auth-browser";
|
|
7823
|
+
|
|
7818
7824
|
// src/v2-entry/format-inspect-reply/format-inspect-reply.ts
|
|
7819
7825
|
var formatInspectReply = (inspection, budgetAction) => {
|
|
7820
7826
|
const { attribution, budget, key } = inspection;
|
|
@@ -7852,7 +7858,7 @@ var formatInspectReply = (inspection, budgetAction) => {
|
|
|
7852
7858
|
};
|
|
7853
7859
|
|
|
7854
7860
|
// src/v2-entry/parse-r33-subcommand/parse-r33-subcommand.ts
|
|
7855
|
-
var SUBCOMMANDS = ["inspect", "
|
|
7861
|
+
var SUBCOMMANDS = ["inspect", "rotate", "reset"];
|
|
7856
7862
|
var parseR33Subcommand = (promptText) => {
|
|
7857
7863
|
const [first = "", ...rest] = promptText.trim().split(/\s+/u).filter(Boolean);
|
|
7858
7864
|
const name = first.replace(/^\/+/u, "").split(":")[0] ?? "";
|
|
@@ -7877,13 +7883,15 @@ var executeR33Command = async (input) => {
|
|
|
7877
7883
|
}
|
|
7878
7884
|
switch (subcommand) {
|
|
7879
7885
|
case "rotate": {
|
|
7880
|
-
const lease = await input.handlers["rotate-now"]()
|
|
7886
|
+
const lease = await input.handlers["rotate-now"]().catch(
|
|
7887
|
+
(error) => {
|
|
7888
|
+
if (error instanceof AuthError3) return void 0;
|
|
7889
|
+
throw error;
|
|
7890
|
+
}
|
|
7891
|
+
);
|
|
7892
|
+
if (lease === void 0) return SIGN_IN_COPY;
|
|
7881
7893
|
return `Route 33 key rotated. Key ${lease.keyId} is valid until ${lease.expiresAt}.`;
|
|
7882
7894
|
}
|
|
7883
|
-
case "logout": {
|
|
7884
|
-
await input.handlers["logout"]();
|
|
7885
|
-
return `Logged out of Route 33. ${SIGN_IN_COPY}`;
|
|
7886
|
-
}
|
|
7887
7895
|
case "reset": {
|
|
7888
7896
|
await input.handlers["reset-attribution"]();
|
|
7889
7897
|
const { connected } = await input.handlers["inspect-session"]();
|
|
@@ -8523,7 +8531,7 @@ var V2_CONNECT_COPY = {
|
|
|
8523
8531
|
refusedTitle: "Route 33 \u2014 key not created",
|
|
8524
8532
|
setupIncomplete: "Route 33 budget setup did not complete.",
|
|
8525
8533
|
signInFailed: "Sign-in did not complete; run /connect and choose Route 33.",
|
|
8526
|
-
|
|
8534
|
+
rotateFailed: "Route 33 could not rotate the key; restart OpenCode and try again.",
|
|
8527
8535
|
legacyKeyConverted: "Route 33 key converted \u2713 \u2014 signing in to mint a fresh key for this folder.",
|
|
8528
8536
|
legacyKeyMessage: "A Route 33 key from a previous version was found in this folder. Convert it to your personal budget?",
|
|
8529
8537
|
legacyKeyTitle: "Route 33 \u2014 key from a previous version",
|
|
@@ -9317,22 +9325,18 @@ var v2Autoconnect = async (context, options = {}) => {
|
|
|
9317
9325
|
var runR33MenuAction = async (context, action, deps) => {
|
|
9318
9326
|
try {
|
|
9319
9327
|
const handlers = deps.handlers();
|
|
9320
|
-
const
|
|
9328
|
+
const local = () => executeR33Command({
|
|
9321
9329
|
budgetAction: "Attribute",
|
|
9322
9330
|
handlers: handlers && {
|
|
9323
9331
|
...handlers,
|
|
9324
9332
|
"inspect-session": async () => {
|
|
9325
9333
|
const inspection = await handlers["inspect-session"]();
|
|
9326
9334
|
return inspection.connected || deps.signedIn === void 0 ? inspection : { ...inspection, connected: await deps.signedIn() };
|
|
9327
|
-
},
|
|
9328
|
-
logout: async () => {
|
|
9329
|
-
if (deps.logout === void 0) return handlers.logout();
|
|
9330
|
-
await deps.logout();
|
|
9331
|
-
await handlers.logout().catch(() => void 0);
|
|
9332
9335
|
}
|
|
9333
9336
|
},
|
|
9334
9337
|
promptText: `/r33 ${action}`
|
|
9335
9338
|
});
|
|
9339
|
+
const reply = action === "rotate" && deps.rotate !== void 0 ? await deps.rotate() : await local();
|
|
9336
9340
|
context.ui.toast.show({ message: reply, variant: "info" });
|
|
9337
9341
|
} catch (error) {
|
|
9338
9342
|
context.ui.toast.show({
|
|
@@ -9355,10 +9359,6 @@ var menuOptions2 = [
|
|
|
9355
9359
|
{
|
|
9356
9360
|
title: "Rotate key now",
|
|
9357
9361
|
value: "rotate"
|
|
9358
|
-
},
|
|
9359
|
-
{
|
|
9360
|
-
title: "Log out of Route 33",
|
|
9361
|
-
value: "logout"
|
|
9362
9362
|
}
|
|
9363
9363
|
];
|
|
9364
9364
|
var showR33Menu = async (context, deps) => {
|
|
@@ -9383,6 +9383,40 @@ var showR33Menu = async (context, deps) => {
|
|
|
9383
9383
|
await runR33MenuAction(context, selection, deps);
|
|
9384
9384
|
};
|
|
9385
9385
|
|
|
9386
|
+
// src/v2-entry/is-account-removed/is-account-removed.ts
|
|
9387
|
+
init_predicates();
|
|
9388
|
+
var isAccountRemoved = (event) => {
|
|
9389
|
+
if (!isRecord(event) || event["type"] !== "credential.switched") return false;
|
|
9390
|
+
const data = event["data"];
|
|
9391
|
+
return isRecord(data) && data["integrationID"] === "route33" && data["credentialID"] === null;
|
|
9392
|
+
};
|
|
9393
|
+
|
|
9394
|
+
// src/tui-entry/v2-account-removal/v2-account-removal.ts
|
|
9395
|
+
var registerV2AccountRemoval = (deps) => {
|
|
9396
|
+
let awaitingWithdrawal = false;
|
|
9397
|
+
const integration = deps.data?.location.integration;
|
|
9398
|
+
const settle = (work) => {
|
|
9399
|
+
void Promise.resolve().then(work).catch(() => void 0);
|
|
9400
|
+
};
|
|
9401
|
+
const refresh = () => {
|
|
9402
|
+
settle(() => {
|
|
9403
|
+
integration?.invalidate?.(deps.location);
|
|
9404
|
+
return integration?.sync?.(deps.location);
|
|
9405
|
+
});
|
|
9406
|
+
};
|
|
9407
|
+
deps.data?.listen?.(({ details }) => {
|
|
9408
|
+
if (isAccountRemoved(details)) {
|
|
9409
|
+
awaitingWithdrawal = true;
|
|
9410
|
+
settle(() => deps.runtime?.commandHandlers().logout());
|
|
9411
|
+
refresh();
|
|
9412
|
+
return;
|
|
9413
|
+
}
|
|
9414
|
+
if (!awaitingWithdrawal || details.type !== "integration.updated") return;
|
|
9415
|
+
awaitingWithdrawal = false;
|
|
9416
|
+
refresh();
|
|
9417
|
+
});
|
|
9418
|
+
};
|
|
9419
|
+
|
|
9386
9420
|
// src/tui-entry/v2-attribution-field/v2-attribution-field.ts
|
|
9387
9421
|
var v2AttributionField = (methods) => {
|
|
9388
9422
|
const browserMethods = methods?.filter(
|
|
@@ -9473,7 +9507,7 @@ var v2BootSessionProbe = async (deps) => {
|
|
|
9473
9507
|
return token !== void 0 ? "alive" : "dead";
|
|
9474
9508
|
};
|
|
9475
9509
|
|
|
9476
|
-
// src/tui-entry/v2-server-
|
|
9510
|
+
// src/tui-entry/v2-server-rotate/v2-server-rotate.ts
|
|
9477
9511
|
init_config();
|
|
9478
9512
|
init_predicates();
|
|
9479
9513
|
|
|
@@ -9482,35 +9516,37 @@ var ROUTE33_SESSION_RPC = {
|
|
|
9482
9516
|
events: {},
|
|
9483
9517
|
id: "route33",
|
|
9484
9518
|
methods: {
|
|
9485
|
-
/**
|
|
9486
|
-
|
|
9519
|
+
/**
|
|
9520
|
+
* Rotates this folder's key and answers with the text to show. A handler
|
|
9521
|
+
* that throws reaches the caller without its message, so a refused
|
|
9522
|
+
* rotation is answered too: `failed` marks the reply as the reason.
|
|
9523
|
+
*/
|
|
9524
|
+
rotate: {
|
|
9487
9525
|
input: { additionalProperties: false, properties: {}, type: "object" },
|
|
9488
9526
|
output: {
|
|
9489
9527
|
additionalProperties: false,
|
|
9490
|
-
properties: {
|
|
9491
|
-
required: ["
|
|
9528
|
+
properties: { failed: { type: "boolean" }, reply: { type: "string" } },
|
|
9529
|
+
required: ["failed", "reply"],
|
|
9492
9530
|
type: "object"
|
|
9493
9531
|
}
|
|
9494
9532
|
}
|
|
9495
9533
|
}
|
|
9496
9534
|
};
|
|
9497
9535
|
|
|
9498
|
-
// src/tui-entry/v2-server-
|
|
9499
|
-
var
|
|
9536
|
+
// src/tui-entry/v2-server-rotate/v2-server-rotate.ts
|
|
9537
|
+
var v2ServerRotate = async (context) => {
|
|
9500
9538
|
const { client, location } = context;
|
|
9501
|
-
const
|
|
9502
|
-
if (location === void 0) return
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
return integration?.sync?.(location);
|
|
9513
|
-
}).catch(() => void 0);
|
|
9539
|
+
const answer = await (async () => {
|
|
9540
|
+
if (location === void 0) return void 0;
|
|
9541
|
+
return client?.rpc?.(ROUTE33_SESSION_RPC).rotate({}, { location: { directory: location.directory } });
|
|
9542
|
+
})().catch(() => void 0);
|
|
9543
|
+
const reply = isRecord(answer) ? answer["reply"] : void 0;
|
|
9544
|
+
const failed = isRecord(answer) ? answer["failed"] : void 0;
|
|
9545
|
+
if (typeof reply !== "string" || typeof failed !== "boolean") {
|
|
9546
|
+
throw new GatewayCredentialError(V2_CONNECT_COPY.rotateFailed);
|
|
9547
|
+
}
|
|
9548
|
+
if (failed) throw new GatewayCredentialError(reply);
|
|
9549
|
+
return reply;
|
|
9514
9550
|
};
|
|
9515
9551
|
|
|
9516
9552
|
// src/tui-entry/v2-session-watch/v2-session-watch.ts
|
|
@@ -9724,15 +9760,19 @@ var v2WizardControl = () => {
|
|
|
9724
9760
|
var v2Route33ModelCandidate = (model) => model.providerID === "route_33" && model.enabled !== false;
|
|
9725
9761
|
|
|
9726
9762
|
// src/tui-entry/v2-auto-select-target/v2-auto-select-target.ts
|
|
9763
|
+
var SKIP = "\0skip";
|
|
9727
9764
|
var v2AutoSelectTarget = async (models, dialog) => {
|
|
9728
9765
|
const candidates = models.filter(v2Route33ModelCandidate);
|
|
9729
9766
|
if (candidates.length === 0) return void 0;
|
|
9730
9767
|
const selected = await dialog.select({
|
|
9731
9768
|
title: "Choose a Route 33 model",
|
|
9732
|
-
options:
|
|
9733
|
-
title:
|
|
9734
|
-
|
|
9735
|
-
|
|
9769
|
+
options: [
|
|
9770
|
+
{ title: "Skip \u2014 keep the current model", value: SKIP },
|
|
9771
|
+
...candidates.map(({ id, name }) => ({
|
|
9772
|
+
title: name ?? id,
|
|
9773
|
+
value: id
|
|
9774
|
+
}))
|
|
9775
|
+
]
|
|
9736
9776
|
});
|
|
9737
9777
|
return candidates.find(({ id }) => id === selected);
|
|
9738
9778
|
};
|
|
@@ -9741,24 +9781,18 @@ var v2AutoSelectTarget = async (models, dialog) => {
|
|
|
9741
9781
|
var v2AutoSelectModel = async (context) => {
|
|
9742
9782
|
const { ui, client, location } = context;
|
|
9743
9783
|
const route = ui.router?.current();
|
|
9784
|
+
const session = client?.session;
|
|
9785
|
+
if (route?.type !== "session" || !session?.switchModel || !location) return;
|
|
9744
9786
|
const pick = async () => {
|
|
9745
|
-
if (
|
|
9746
|
-
return void 0;
|
|
9787
|
+
if (ui.model?.current()?.providerID === "route_33") return void 0;
|
|
9747
9788
|
const listed = await client?.model?.list?.({ location });
|
|
9748
9789
|
return v2AutoSelectTarget(listed?.data ?? [], ui.dialog);
|
|
9749
9790
|
};
|
|
9750
9791
|
const model = await pick();
|
|
9751
9792
|
if (!model) return;
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
sessionID: route.sessionID
|
|
9756
|
-
});
|
|
9757
|
-
return;
|
|
9758
|
-
}
|
|
9759
|
-
ui.toast.show({
|
|
9760
|
-
message: `Open /models and choose ${model.name ?? model.id} under Route 33 to use it.`,
|
|
9761
|
-
variant: "info"
|
|
9793
|
+
await session.switchModel({
|
|
9794
|
+
model: { id: model.id, providerID: model.providerID },
|
|
9795
|
+
sessionID: route.sessionID
|
|
9762
9796
|
});
|
|
9763
9797
|
};
|
|
9764
9798
|
|
|
@@ -9824,11 +9858,7 @@ var createV2Tui = () => ({
|
|
|
9824
9858
|
) !== void 0;
|
|
9825
9859
|
const menu = (host) => showR33Menu(host, {
|
|
9826
9860
|
handlers: menuHandlers,
|
|
9827
|
-
|
|
9828
|
-
client: context.client,
|
|
9829
|
-
data: context.data,
|
|
9830
|
-
location
|
|
9831
|
-
}),
|
|
9861
|
+
rotate: () => v2ServerRotate({ client: context.client, location }),
|
|
9832
9862
|
signedIn
|
|
9833
9863
|
});
|
|
9834
9864
|
context.keymap?.layer(() => ({
|
|
@@ -9949,6 +9979,11 @@ var createV2Tui = () => ({
|
|
|
9949
9979
|
return false;
|
|
9950
9980
|
}
|
|
9951
9981
|
});
|
|
9982
|
+
registerV2AccountRemoval({
|
|
9983
|
+
data: context.data,
|
|
9984
|
+
location,
|
|
9985
|
+
runtime: tuiRuntime
|
|
9986
|
+
});
|
|
9952
9987
|
}
|
|
9953
9988
|
});
|
|
9954
9989
|
|
package/dist/v2-entry/index.js
CHANGED
|
@@ -3204,8 +3204,8 @@ var LoginSession = class {
|
|
|
3204
3204
|
}
|
|
3205
3205
|
/**
|
|
3206
3206
|
* Clears the session: the cached login result and the stored refresh
|
|
3207
|
-
* token. The next login starts from scratch —
|
|
3208
|
-
* auto-reconnect path both land here. A refresh still on its way to the
|
|
3207
|
+
* token. The next login starts from scratch — the removal of the host's
|
|
3208
|
+
* last Route 33 account and the auto-reconnect path both land here. A refresh still on its way to the
|
|
3209
3209
|
* auth server is disowned: its rotated token is never stored.
|
|
3210
3210
|
* @returns Resolved once the session and the stored refresh token are gone.
|
|
3211
3211
|
*/
|
|
@@ -3541,7 +3541,10 @@ var Route33Runtime = class {
|
|
|
3541
3541
|
}),
|
|
3542
3542
|
logout: () => this.#session.clear(),
|
|
3543
3543
|
"rotate-now": () => rotateNow({
|
|
3544
|
-
lease: (policy) =>
|
|
3544
|
+
lease: async (policy) => {
|
|
3545
|
+
await this.#session.credential({ allowBrowser: false });
|
|
3546
|
+
return this.#lease({ ...this.#options.policy, ...policy });
|
|
3547
|
+
}
|
|
3545
3548
|
})
|
|
3546
3549
|
};
|
|
3547
3550
|
}
|
|
@@ -5407,18 +5410,110 @@ var registerRoute33ModelGate = async (deps) => deps.session.hook(
|
|
|
5407
5410
|
{ providerID: "route_33" }
|
|
5408
5411
|
);
|
|
5409
5412
|
|
|
5413
|
+
// src/v2-entry/r33-command/r33-command.ts
|
|
5414
|
+
import { AuthError as AuthError3 } from "@r-33/auth-browser";
|
|
5415
|
+
|
|
5416
|
+
// src/v2-entry/format-inspect-reply/format-inspect-reply.ts
|
|
5417
|
+
var formatInspectReply = (inspection, budgetAction) => {
|
|
5418
|
+
const { attribution, budget, key } = inspection;
|
|
5419
|
+
if (attribution === void 0) {
|
|
5420
|
+
return inspection.connected ? `This folder has no Route 33 budget; open /r33 and choose ${budgetAction}.` : "To sign in, run /connect and choose Route 33.";
|
|
5421
|
+
}
|
|
5422
|
+
const { organisationName, projectName } = { ...key };
|
|
5423
|
+
let label;
|
|
5424
|
+
let keyScope;
|
|
5425
|
+
switch (attribution.kind) {
|
|
5426
|
+
case "personal":
|
|
5427
|
+
label = "Personal";
|
|
5428
|
+
keyScope = "your personal budget";
|
|
5429
|
+
break;
|
|
5430
|
+
case "project":
|
|
5431
|
+
label = `Project ${projectName ?? attribution.projectId}`;
|
|
5432
|
+
keyScope = [organisationName, projectName].filter(Boolean).join(" \xB7 ");
|
|
5433
|
+
break;
|
|
5434
|
+
default: {
|
|
5435
|
+
const unexpected = attribution;
|
|
5436
|
+
throw new TypeError(`Unexpected attribution: ${String(unexpected)}`);
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5439
|
+
const cap = budget === void 0 ? "" : [" \u2014 cap", budget.amount, budget.currency].filter((part) => part !== null).join(" ");
|
|
5440
|
+
const lines = [`Budget: ${label}${cap}`];
|
|
5441
|
+
if (key !== void 0) {
|
|
5442
|
+
const scope = keyScope === "" ? "" : ` on ${keyScope}`;
|
|
5443
|
+
lines.push(`Key: ${key.name}${scope}`);
|
|
5444
|
+
}
|
|
5445
|
+
if (inspection.lease !== void 0) {
|
|
5446
|
+
lines.push(`Expires: ${inspection.lease.expiresAt}`);
|
|
5447
|
+
lines.push(`Key id: ${inspection.lease.keyId}`);
|
|
5448
|
+
}
|
|
5449
|
+
return lines.join("\n");
|
|
5450
|
+
};
|
|
5451
|
+
|
|
5452
|
+
// src/v2-entry/parse-r33-subcommand/parse-r33-subcommand.ts
|
|
5453
|
+
var SUBCOMMANDS = ["inspect", "rotate", "reset"];
|
|
5454
|
+
var parseR33Subcommand = (promptText) => {
|
|
5455
|
+
const [first = "", ...rest] = promptText.trim().split(/\s+/u).filter(Boolean);
|
|
5456
|
+
const name = first.replace(/^\/+/u, "").split(":")[0] ?? "";
|
|
5457
|
+
const argument = name === "r33" ? rest[0] : first;
|
|
5458
|
+
if (argument === void 0 || argument === "") {
|
|
5459
|
+
return "inspect";
|
|
5460
|
+
}
|
|
5461
|
+
return SUBCOMMANDS.includes(argument) ? argument : "help";
|
|
5462
|
+
};
|
|
5463
|
+
|
|
5464
|
+
// src/v2-entry/r33-command/r33-command.ts
|
|
5465
|
+
var SIGN_IN_COPY = "To sign in, run /connect and choose Route 33.";
|
|
5466
|
+
var executeR33Command = async (input) => {
|
|
5467
|
+
const subcommand = parseR33Subcommand(input.promptText);
|
|
5468
|
+
if (input.handlers === void 0) {
|
|
5469
|
+
return SIGN_IN_COPY;
|
|
5470
|
+
}
|
|
5471
|
+
const budgetAction = input.budgetAction ?? "Change budget";
|
|
5472
|
+
if (subcommand === "help") {
|
|
5473
|
+
const { connected } = await input.handlers["inspect-session"]();
|
|
5474
|
+
return connected ? `To assign a budget, open /r33 and choose ${budgetAction}.` : SIGN_IN_COPY;
|
|
5475
|
+
}
|
|
5476
|
+
switch (subcommand) {
|
|
5477
|
+
case "rotate": {
|
|
5478
|
+
const lease = await input.handlers["rotate-now"]().catch(
|
|
5479
|
+
(error) => {
|
|
5480
|
+
if (error instanceof AuthError3) return void 0;
|
|
5481
|
+
throw error;
|
|
5482
|
+
}
|
|
5483
|
+
);
|
|
5484
|
+
if (lease === void 0) return SIGN_IN_COPY;
|
|
5485
|
+
return `Route 33 key rotated. Key ${lease.keyId} is valid until ${lease.expiresAt}.`;
|
|
5486
|
+
}
|
|
5487
|
+
case "reset": {
|
|
5488
|
+
await input.handlers["reset-attribution"]();
|
|
5489
|
+
const { connected } = await input.handlers["inspect-session"]();
|
|
5490
|
+
return connected ? `Budget cleared; open /r33 and choose ${budgetAction}.` : `Budget cleared. ${SIGN_IN_COPY}`;
|
|
5491
|
+
}
|
|
5492
|
+
default: {
|
|
5493
|
+
return formatInspectReply(
|
|
5494
|
+
await input.handlers["inspect-session"](),
|
|
5495
|
+
budgetAction
|
|
5496
|
+
);
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
};
|
|
5500
|
+
|
|
5410
5501
|
// src/v2-entry/session-rpc/session-rpc.ts
|
|
5411
5502
|
var ROUTE33_SESSION_RPC = {
|
|
5412
5503
|
events: {},
|
|
5413
5504
|
id: "route33",
|
|
5414
5505
|
methods: {
|
|
5415
|
-
/**
|
|
5416
|
-
|
|
5506
|
+
/**
|
|
5507
|
+
* Rotates this folder's key and answers with the text to show. A handler
|
|
5508
|
+
* that throws reaches the caller without its message, so a refused
|
|
5509
|
+
* rotation is answered too: `failed` marks the reply as the reason.
|
|
5510
|
+
*/
|
|
5511
|
+
rotate: {
|
|
5417
5512
|
input: { additionalProperties: false, properties: {}, type: "object" },
|
|
5418
5513
|
output: {
|
|
5419
5514
|
additionalProperties: false,
|
|
5420
|
-
properties: {
|
|
5421
|
-
required: ["
|
|
5515
|
+
properties: { failed: { type: "boolean" }, reply: { type: "string" } },
|
|
5516
|
+
required: ["failed", "reply"],
|
|
5422
5517
|
type: "object"
|
|
5423
5518
|
}
|
|
5424
5519
|
}
|
|
@@ -5427,10 +5522,17 @@ var ROUTE33_SESSION_RPC = {
|
|
|
5427
5522
|
|
|
5428
5523
|
// src/v2-entry/register-session-rpc/register-session-rpc.ts
|
|
5429
5524
|
var registerSessionRpc = (rpc, deps) => rpc.register(ROUTE33_SESSION_RPC, {
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5525
|
+
rotate: async () => {
|
|
5526
|
+
try {
|
|
5527
|
+
const reply = await executeR33Command({
|
|
5528
|
+
handlers: deps.getRuntime()?.commandHandlers(),
|
|
5529
|
+
promptText: "rotate"
|
|
5530
|
+
});
|
|
5531
|
+
return { failed: false, reply };
|
|
5532
|
+
} catch (error) {
|
|
5533
|
+
const reply = error instanceof Error ? error.message : String(error);
|
|
5534
|
+
return { failed: true, reply };
|
|
5535
|
+
}
|
|
5434
5536
|
}
|
|
5435
5537
|
});
|
|
5436
5538
|
|
|
@@ -5529,6 +5631,42 @@ var selectedBudgetForm = async (plan, selection, runtime2) => {
|
|
|
5529
5631
|
];
|
|
5530
5632
|
};
|
|
5531
5633
|
|
|
5634
|
+
// src/v2-entry/is-account-removed/is-account-removed.ts
|
|
5635
|
+
var isAccountRemoved = (event) => {
|
|
5636
|
+
if (!isRecord(event) || event["type"] !== "credential.switched") return false;
|
|
5637
|
+
const data = event["data"];
|
|
5638
|
+
return isRecord(data) && data["integrationID"] === "route33" && data["credentialID"] === null;
|
|
5639
|
+
};
|
|
5640
|
+
|
|
5641
|
+
// src/v2-entry/watch-account-removal/watch-account-removal.ts
|
|
5642
|
+
var watchAccountRemoval = (events, deps) => {
|
|
5643
|
+
const stop = new AbortController();
|
|
5644
|
+
const forget = async () => {
|
|
5645
|
+
await deps.getRuntime()?.commandHandlers().logout();
|
|
5646
|
+
await deps.registerProjectForm().catch(() => void 0);
|
|
5647
|
+
};
|
|
5648
|
+
const watch = async () => {
|
|
5649
|
+
const switches = events.subscribe({
|
|
5650
|
+
signal: stop.signal,
|
|
5651
|
+
types: ["credential.switched"]
|
|
5652
|
+
});
|
|
5653
|
+
for await (const event of switches) {
|
|
5654
|
+
if (!isAccountRemoved(event)) continue;
|
|
5655
|
+
await forget().catch(() => {
|
|
5656
|
+
logger.warn("account.removed.sign-in-not-forgotten");
|
|
5657
|
+
});
|
|
5658
|
+
}
|
|
5659
|
+
};
|
|
5660
|
+
void watch().catch(() => {
|
|
5661
|
+
if (!stop.signal.aborted) logger.warn("account.removed.watch-stopped");
|
|
5662
|
+
});
|
|
5663
|
+
return {
|
|
5664
|
+
dispose: () => {
|
|
5665
|
+
stop.abort();
|
|
5666
|
+
}
|
|
5667
|
+
};
|
|
5668
|
+
};
|
|
5669
|
+
|
|
5532
5670
|
// src/v2-entry/workspace-key-request-hook/workspace-key-request-hook.ts
|
|
5533
5671
|
var createWorkspaceKeyHook = (deps) => async (input) => {
|
|
5534
5672
|
const target = new URL(input.request.url);
|
|
@@ -5696,10 +5834,9 @@ var createRoute33V2Plugin = (options = {}) => {
|
|
|
5696
5834
|
listSessions: async () => (await context.session.list()).data,
|
|
5697
5835
|
session: context.session
|
|
5698
5836
|
});
|
|
5699
|
-
const
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
});
|
|
5837
|
+
const session = { getRuntime: () => runtime2, registerProjectForm };
|
|
5838
|
+
const sessionRpc = await registerSessionRpc(context.rpc, session);
|
|
5839
|
+
const accountWatch = watchAccountRemoval(context.event, session);
|
|
5703
5840
|
await bootstrapProvider(
|
|
5704
5841
|
{
|
|
5705
5842
|
getRuntime: () => runtime2,
|
|
@@ -5715,6 +5852,7 @@ var createRoute33V2Plugin = (options = {}) => {
|
|
|
5715
5852
|
context.provider.reload()
|
|
5716
5853
|
]);
|
|
5717
5854
|
return async () => {
|
|
5855
|
+
accountWatch.dispose();
|
|
5718
5856
|
await Promise.all([
|
|
5719
5857
|
integrationTransform.dispose(),
|
|
5720
5858
|
providerTransform.dispose(),
|