acryl 0.1.16 → 0.1.17
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/lib/bin.js +380 -242
- package/lib/bin.js.map +1 -1
- package/lib/index.js +381 -243
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/bin.js
CHANGED
|
@@ -4,14 +4,13 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { existsSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { dirname, join, relative, resolve } from "node:path";
|
|
6
6
|
import { execFile, spawn } from "node:child_process";
|
|
7
|
-
import {
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
8
|
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
9
9
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
10
10
|
import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
|
|
11
11
|
import { diffLines } from "diff";
|
|
12
12
|
import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
13
13
|
import { readdir } from "node:fs/promises";
|
|
14
|
-
import { createServer } from "node:http";
|
|
15
14
|
import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
|
|
16
15
|
import { GoalError } from "@deepseek-ai/dsh-goal";
|
|
17
16
|
//#region src/cli/node-launcher.ts
|
|
@@ -277,22 +276,29 @@ const ACRYL_RUNTIME_ROWS = [{
|
|
|
277
276
|
id: "system-prompt",
|
|
278
277
|
name: "@deepseek-ai/dsh-system-prompt",
|
|
279
278
|
config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
|
|
280
|
-
}, { insert: [
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
279
|
+
}, { insert: [
|
|
280
|
+
{
|
|
281
|
+
id: "agent-presets",
|
|
282
|
+
name: "@deepseek-ai/dsh-agent-presets",
|
|
283
|
+
config: {
|
|
284
|
+
default: "standard",
|
|
285
|
+
roots: existsSync(shippedPresetsDir) ? [{
|
|
286
|
+
path: shippedPresetsDir,
|
|
287
|
+
trust: "system"
|
|
288
|
+
}] : [],
|
|
289
|
+
includeShippedRoot: false,
|
|
290
|
+
includeUserRoot: true
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
id: "session-stats",
|
|
295
|
+
name: "@deepseek-ai/dsh-session-stats"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
id: "authorization",
|
|
299
|
+
name: "@deepseek-ai/dsh-authorization"
|
|
291
300
|
}
|
|
292
|
-
}
|
|
293
|
-
id: "session-stats",
|
|
294
|
-
name: "@deepseek-ai/dsh-session-stats"
|
|
295
|
-
}] }];
|
|
301
|
+
] }];
|
|
296
302
|
/** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
|
|
297
303
|
async function bootAcrylHarnessProfile(options) {
|
|
298
304
|
if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
|
|
@@ -440,7 +446,7 @@ const ESC = "\x1B[";
|
|
|
440
446
|
const dim$2 = fg(theme.muted);
|
|
441
447
|
const cyan$1 = fg(theme.secondary);
|
|
442
448
|
const primary = fg(theme.primary);
|
|
443
|
-
const bold$
|
|
449
|
+
const bold$11 = (s) => `${ESC}1m${s}${ESC}0m`;
|
|
444
450
|
const italic = (s) => `${ESC}3m${s}${ESC}0m`;
|
|
445
451
|
const strike = (s) => `${ESC}9m${s}${ESC}0m`;
|
|
446
452
|
const underline = (s) => `${ESC}4m${s}${ESC}0m`;
|
|
@@ -484,7 +490,7 @@ function looksLikeMarkdown(text) {
|
|
|
484
490
|
/** Style links, bold, strikethrough, and emphasis in a span already known to contain no inline code. */
|
|
485
491
|
function applyNonCodeInline(text) {
|
|
486
492
|
let working = text.replaceAll(LINK_RE_G, (_match, label, url) => hyperlink(url, underline(primary(label))));
|
|
487
|
-
working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$
|
|
493
|
+
working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$11(a ?? b ?? ""));
|
|
488
494
|
working = working.replaceAll(STRIKE_RE_G, (_match, t) => strike(t));
|
|
489
495
|
return working.replaceAll(ITALIC_RE_G, (_match, a, b) => italic(a ?? b ?? ""));
|
|
490
496
|
}
|
|
@@ -550,7 +556,7 @@ function padCell(styled, width, align) {
|
|
|
550
556
|
}
|
|
551
557
|
/** Pad one row of already-styled cells (header or body) to a single column-aligned line. */
|
|
552
558
|
function formatTableRow(styledCells, widths, aligns, isHeader) {
|
|
553
|
-
return widths.map((width, i) => padCell(isHeader ? bold$
|
|
559
|
+
return widths.map((width, i) => padCell(isHeader ? bold$11(styledCells[i] ?? "") : styledCells[i] ?? "", width, aligns[i] ?? "left")).join(dim$2(" │ "));
|
|
554
560
|
}
|
|
555
561
|
/** A dim horizontal rule under the header row, with a cross at each column boundary. */
|
|
556
562
|
function formatTableRule(widths) {
|
|
@@ -607,7 +613,7 @@ function renderMarkdown(text) {
|
|
|
607
613
|
if (header !== null) {
|
|
608
614
|
const level = header[1].length;
|
|
609
615
|
const content = applyInline(header[2]);
|
|
610
|
-
out.push(level === 1 ? bold$
|
|
616
|
+
out.push(level === 1 ? bold$11(primary(content)) : level === 2 ? bold$11(cyan$1(content)) : bold$11(content));
|
|
611
617
|
continue;
|
|
612
618
|
}
|
|
613
619
|
if (HR_RE.test(line)) {
|
|
@@ -1232,6 +1238,31 @@ var TuiStore = class {
|
|
|
1232
1238
|
}
|
|
1233
1239
|
} });
|
|
1234
1240
|
}
|
|
1241
|
+
/** Open the `/login` sign-in overlay to a fresh, loading flow list. */
|
|
1242
|
+
openLogin() {
|
|
1243
|
+
this.set({ overlay: {
|
|
1244
|
+
kind: "login",
|
|
1245
|
+
login: {
|
|
1246
|
+
flows: void 0,
|
|
1247
|
+
selected: 0,
|
|
1248
|
+
signingIn: void 0,
|
|
1249
|
+
prompt: void 0,
|
|
1250
|
+
busy: true,
|
|
1251
|
+
error: void 0
|
|
1252
|
+
}
|
|
1253
|
+
} });
|
|
1254
|
+
}
|
|
1255
|
+
/** Patch the open `/login` overlay's sub-state; a no-op once it's closed. */
|
|
1256
|
+
updateLogin(patch) {
|
|
1257
|
+
if (this.state.overlay.kind !== "login") return;
|
|
1258
|
+
this.set({ overlay: {
|
|
1259
|
+
kind: "login",
|
|
1260
|
+
login: {
|
|
1261
|
+
...this.state.overlay.login,
|
|
1262
|
+
...patch
|
|
1263
|
+
}
|
|
1264
|
+
} });
|
|
1265
|
+
}
|
|
1235
1266
|
/** Open the `/trajectory` ledger overlay. */
|
|
1236
1267
|
openTrajectory() {
|
|
1237
1268
|
this.set({ overlay: { kind: "trajectory" } });
|
|
@@ -1783,10 +1814,10 @@ function runSlashCommand(command, actions) {
|
|
|
1783
1814
|
}
|
|
1784
1815
|
//#endregion
|
|
1785
1816
|
//#region src/tui/piTheme.ts
|
|
1786
|
-
const bold$
|
|
1817
|
+
const bold$10 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
1787
1818
|
const selectListTheme = {
|
|
1788
1819
|
selectedPrefix: fg(theme.primary),
|
|
1789
|
-
selectedText: (s) => bold$
|
|
1820
|
+
selectedText: (s) => bold$10(fg(theme.primary)(s)),
|
|
1790
1821
|
description: fg(theme.muted),
|
|
1791
1822
|
scrollInfo: fg(theme.muted),
|
|
1792
1823
|
noMatch: fg(theme.muted)
|
|
@@ -2111,6 +2142,68 @@ var Spinner = class {
|
|
|
2111
2142
|
}
|
|
2112
2143
|
};
|
|
2113
2144
|
//#endregion
|
|
2145
|
+
//#region src/tui/clipboard.ts
|
|
2146
|
+
/**
|
|
2147
|
+
* System-clipboard read, used for right-click paste. Node has no built-in
|
|
2148
|
+
* clipboard API, so this shells out to the platform's clipboard tool via
|
|
2149
|
+
* `execFile` (the same `node:child_process` approach used elsewhere for
|
|
2150
|
+
* platform launchers like `open`/`xdg-open`).
|
|
2151
|
+
* @module @tomowang/dsh-tui/tui/clipboard
|
|
2152
|
+
*/
|
|
2153
|
+
function clipboardCommands() {
|
|
2154
|
+
switch (process.platform) {
|
|
2155
|
+
case "darwin": return [["pbpaste", []]];
|
|
2156
|
+
case "win32": return [["powershell.exe", [
|
|
2157
|
+
"-NoProfile",
|
|
2158
|
+
"-NonInteractive",
|
|
2159
|
+
"-Command",
|
|
2160
|
+
"Get-Clipboard"
|
|
2161
|
+
]]];
|
|
2162
|
+
default: return [
|
|
2163
|
+
["xclip", [
|
|
2164
|
+
"-selection",
|
|
2165
|
+
"clipboard",
|
|
2166
|
+
"-o"
|
|
2167
|
+
]],
|
|
2168
|
+
["xsel", ["--clipboard", "--output"]],
|
|
2169
|
+
["wl-paste", ["--no-newline"]]
|
|
2170
|
+
];
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Read the system clipboard. Resolves with the clipboard text (possibly empty).
|
|
2175
|
+
* Rejects when no supported clipboard tool is available on this host.
|
|
2176
|
+
*
|
|
2177
|
+
* A single trailing newline is stripped: `pbpaste` prints the clipboard verbatim,
|
|
2178
|
+
* while `xclip`/`xsel`/`Get-Clipboard` append one, so this keeps the result
|
|
2179
|
+
* consistent with a native terminal paste (which inserts exactly what was copied).
|
|
2180
|
+
*/
|
|
2181
|
+
function readClipboard() {
|
|
2182
|
+
return new Promise((resolve, reject) => {
|
|
2183
|
+
const commands = clipboardCommands();
|
|
2184
|
+
let index = 0;
|
|
2185
|
+
const attempt = () => {
|
|
2186
|
+
if (index >= commands.length) {
|
|
2187
|
+
reject(/* @__PURE__ */ new Error("no clipboard tool available"));
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
const [command, args] = commands[index];
|
|
2191
|
+
index += 1;
|
|
2192
|
+
execFile(command, args, {
|
|
2193
|
+
encoding: "utf8",
|
|
2194
|
+
maxBuffer: 10 * 1024 * 1024
|
|
2195
|
+
}, (error, stdout) => {
|
|
2196
|
+
if (error) {
|
|
2197
|
+
attempt();
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
resolve(stdout.replace(/\r?\n$/, ""));
|
|
2201
|
+
});
|
|
2202
|
+
};
|
|
2203
|
+
attempt();
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
//#endregion
|
|
2114
2207
|
//#region src/yly/yly-frames.generated.ts
|
|
2115
2208
|
const YLY_FRAMES = {
|
|
2116
2209
|
"small": [
|
|
@@ -3030,6 +3123,15 @@ var YlyPet = class {
|
|
|
3030
3123
|
* delegate keystrokes to a field nested inside a larger custom overlay.
|
|
3031
3124
|
* @module @tomowang/dsh-tui/tui/miniTextField
|
|
3032
3125
|
*/
|
|
3126
|
+
const BRACKETED_PASTE_START = "\x1B[200~";
|
|
3127
|
+
const BRACKETED_PASTE_END = "\x1B[201~";
|
|
3128
|
+
/** Extract the content of one bracketed-paste sequence, or `undefined` if `data` is not one. */
|
|
3129
|
+
function extractBracketedPaste(data) {
|
|
3130
|
+
if (!data.startsWith(BRACKETED_PASTE_START)) return void 0;
|
|
3131
|
+
const end = data.indexOf(BRACKETED_PASTE_END);
|
|
3132
|
+
if (end === -1) return void 0;
|
|
3133
|
+
return data.slice(6, end);
|
|
3134
|
+
}
|
|
3033
3135
|
function emptyMiniTextField(value = "") {
|
|
3034
3136
|
return {
|
|
3035
3137
|
value,
|
|
@@ -3068,6 +3170,15 @@ function miniTextFieldInput(state, data) {
|
|
|
3068
3170
|
cursor: state.cursor
|
|
3069
3171
|
};
|
|
3070
3172
|
}
|
|
3173
|
+
const paste = extractBracketedPaste(data);
|
|
3174
|
+
if (paste !== void 0) {
|
|
3175
|
+
const text = paste.replace(/[\r\n]+/g, "");
|
|
3176
|
+
if (text.length === 0) return state;
|
|
3177
|
+
return {
|
|
3178
|
+
value: state.value.slice(0, state.cursor) + text + state.value.slice(state.cursor),
|
|
3179
|
+
cursor: state.cursor + text.length
|
|
3180
|
+
};
|
|
3181
|
+
}
|
|
3071
3182
|
if (data.length > 0 && !data.startsWith("\x1B") && data !== "\r" && data !== "\n" && data !== " ") return {
|
|
3072
3183
|
value: state.value.slice(0, state.cursor) + data + state.value.slice(state.cursor),
|
|
3073
3184
|
cursor: state.cursor + data.length
|
|
@@ -3081,11 +3192,11 @@ function renderMiniTextField(state, cursorVisible, mask) {
|
|
|
3081
3192
|
}
|
|
3082
3193
|
//#endregion
|
|
3083
3194
|
//#region src/tui/modelProfile/ModelProfileOverlay.ts
|
|
3084
|
-
const bold$
|
|
3085
|
-
const secondary$
|
|
3086
|
-
const muted$
|
|
3087
|
-
const errorColor$
|
|
3088
|
-
const invert$
|
|
3195
|
+
const bold$9 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
3196
|
+
const secondary$9 = fg(theme.secondary);
|
|
3197
|
+
const muted$10 = fg(theme.muted);
|
|
3198
|
+
const errorColor$5 = fg(theme.error);
|
|
3199
|
+
const invert$5 = (s) => `\x1b[7m${s}\x1b[0m`;
|
|
3089
3200
|
var ModelProfileOverlay = class {
|
|
3090
3201
|
store;
|
|
3091
3202
|
actions;
|
|
@@ -3162,21 +3273,19 @@ var ModelProfileOverlay = class {
|
|
|
3162
3273
|
}
|
|
3163
3274
|
renderList(mp) {
|
|
3164
3275
|
const { providers, selected, busy, error } = mp;
|
|
3165
|
-
const lines = [bold$
|
|
3166
|
-
if (error !== void 0) lines.push(errorColor$
|
|
3167
|
-
if (busy && providers === void 0) lines.push(muted$
|
|
3276
|
+
const lines = [bold$9(secondary$9("Model providers"))];
|
|
3277
|
+
if (error !== void 0) lines.push(errorColor$5(error));
|
|
3278
|
+
if (busy && providers === void 0) lines.push(muted$10("Loading…"));
|
|
3168
3279
|
providers?.forEach((row, index) => {
|
|
3169
3280
|
const marker = row.configured ? "● " : "○ ";
|
|
3170
3281
|
const active = row.live ? " (active)" : "";
|
|
3171
3282
|
const noKey = row.apiKeyConfigured ? "" : " [no api key]";
|
|
3172
|
-
const oauthStatus = row.oauth === void 0 ? "" : row.grantConfigured ? " [oauth ✓]" : " [oauth]";
|
|
3173
3283
|
const confirm = this.confirmDelete === index ? " — press d again to delete" : "";
|
|
3174
|
-
const text = `${index === selected ? "› " : " "}${marker}${row.displayName}${active}${noKey}${
|
|
3175
|
-
lines.push(index === selected ? invert$
|
|
3284
|
+
const text = `${index === selected ? "› " : " "}${marker}${row.displayName}${active}${noKey}${confirm}`;
|
|
3285
|
+
lines.push(index === selected ? invert$5(text) : text);
|
|
3176
3286
|
});
|
|
3177
|
-
if (providers?.length === 0) lines.push(muted$
|
|
3178
|
-
|
|
3179
|
-
lines.push(muted$9(`↑↓ select · enter edit · a add · d delete · s set active model${hasOauth ? " · o login with oauth" : ""} · esc close`));
|
|
3287
|
+
if (providers?.length === 0) lines.push(muted$10("No providers configured yet — press a to add one."));
|
|
3288
|
+
lines.push(muted$10("↑↓ select · enter edit · a add · d delete · s set active model · esc close"));
|
|
3180
3289
|
return lines;
|
|
3181
3290
|
}
|
|
3182
3291
|
handleListInput(data, mp) {
|
|
@@ -3213,11 +3322,6 @@ var ModelProfileOverlay = class {
|
|
|
3213
3322
|
if (model !== void 0) this.actions.setActiveModel(row.route, model.id);
|
|
3214
3323
|
return;
|
|
3215
3324
|
}
|
|
3216
|
-
if (data === "o") {
|
|
3217
|
-
const row = providers[selected];
|
|
3218
|
-
if (row.oauth !== void 0) this.actions.loginWithOAuth(row.route);
|
|
3219
|
-
return;
|
|
3220
|
-
}
|
|
3221
3325
|
if (data === "d") {
|
|
3222
3326
|
if (this.confirmDelete === selected) {
|
|
3223
3327
|
this.confirmDelete = void 0;
|
|
@@ -3245,8 +3349,8 @@ var ModelProfileOverlay = class {
|
|
|
3245
3349
|
baseURL: "Base URL",
|
|
3246
3350
|
apiKey: draft.apiKeyConfigured ? "API key (set — leave blank to keep)" : "API key"
|
|
3247
3351
|
};
|
|
3248
|
-
const lines = [bold$
|
|
3249
|
-
if (mp.error !== void 0) lines.push(errorColor$
|
|
3352
|
+
const lines = [bold$9(secondary$9(draft.isNew ? "Add provider" : `Edit ${draft.displayName || draft.route}`))];
|
|
3353
|
+
if (mp.error !== void 0) lines.push(errorColor$5(mp.error));
|
|
3250
3354
|
textFields.forEach((field, index) => {
|
|
3251
3355
|
const isFocused = this.focused === index;
|
|
3252
3356
|
const mask = field === "apiKey" ? "*" : void 0;
|
|
@@ -3254,10 +3358,10 @@ var ModelProfileOverlay = class {
|
|
|
3254
3358
|
lines.push(`${prefix}${renderMiniTextField(fieldState[field], isFocused, mask)}`);
|
|
3255
3359
|
});
|
|
3256
3360
|
const modelsText = `${this.focused === modelsRow ? "› " : " "}Models (${this.models.length}) — enter to edit`;
|
|
3257
|
-
lines.push(this.focused === modelsRow ? invert$
|
|
3361
|
+
lines.push(this.focused === modelsRow ? invert$5(modelsText) : modelsText);
|
|
3258
3362
|
const saveText = `${this.focused === saveRow ? "› " : " "}${mp.busy ? "Saving…" : "Save"}`;
|
|
3259
|
-
lines.push(this.focused === saveRow ? invert$
|
|
3260
|
-
lines.push(muted$
|
|
3363
|
+
lines.push(this.focused === saveRow ? invert$5(saveText) : saveText);
|
|
3364
|
+
lines.push(muted$10("tab/shift+tab move · enter confirm field / activate row · esc cancel"));
|
|
3261
3365
|
return lines;
|
|
3262
3366
|
}
|
|
3263
3367
|
handleFormInput(data, draft) {
|
|
@@ -3307,21 +3411,21 @@ var ModelProfileOverlay = class {
|
|
|
3307
3411
|
}
|
|
3308
3412
|
}
|
|
3309
3413
|
renderModelListEditor(mp) {
|
|
3310
|
-
const lines = [bold$
|
|
3414
|
+
const lines = [bold$9(secondary$9("Models"))];
|
|
3311
3415
|
this.models.forEach((model, index) => {
|
|
3312
3416
|
const isSelected = !this.modelInputFocused && index === this.modelSelected;
|
|
3313
3417
|
const text = `${isSelected ? "› " : " "}${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`;
|
|
3314
|
-
lines.push(isSelected ? invert$
|
|
3418
|
+
lines.push(isSelected ? invert$5(text) : text);
|
|
3315
3419
|
});
|
|
3316
|
-
if (this.models.length === 0) lines.push(muted$
|
|
3420
|
+
if (this.models.length === 0) lines.push(muted$10("No models yet."));
|
|
3317
3421
|
lines.push(`${this.modelInputFocused ? "› " : " "}Add id: ${renderMiniTextField(this.modelDraftId, this.modelInputFocused)}`);
|
|
3318
|
-
if (mp.busy) lines.push(muted$
|
|
3319
|
-
if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$
|
|
3422
|
+
if (mp.busy) lines.push(muted$10("Discovering…"));
|
|
3423
|
+
if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$10("No models discovered."));
|
|
3320
3424
|
else {
|
|
3321
|
-
lines.push(muted$
|
|
3322
|
-
for (const model of mp.discovered) lines.push(muted$
|
|
3425
|
+
lines.push(muted$10("Discovered — tab to the id field and type one to adopt it:"));
|
|
3426
|
+
for (const model of mp.discovered) lines.push(muted$10(` ${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`));
|
|
3323
3427
|
}
|
|
3324
|
-
lines.push(muted$
|
|
3428
|
+
lines.push(muted$10("tab toggle list/input · ↑↓ select · x remove · g discover · esc back"));
|
|
3325
3429
|
return lines;
|
|
3326
3430
|
}
|
|
3327
3431
|
addModel(id) {
|
|
@@ -3382,6 +3486,111 @@ var ModelProfileOverlay = class {
|
|
|
3382
3486
|
}
|
|
3383
3487
|
};
|
|
3384
3488
|
//#endregion
|
|
3489
|
+
//#region src/tui/login/LoginOverlay.ts
|
|
3490
|
+
const bold$8 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
3491
|
+
const secondary$8 = fg(theme.secondary);
|
|
3492
|
+
const muted$9 = fg(theme.muted);
|
|
3493
|
+
const errorColor$4 = fg(theme.error);
|
|
3494
|
+
const invert$4 = (s) => `\x1b[7m${s}\x1b[0m`;
|
|
3495
|
+
var LoginOverlay = class {
|
|
3496
|
+
store;
|
|
3497
|
+
actions;
|
|
3498
|
+
promptField = emptyMiniTextField();
|
|
3499
|
+
promptCursor = 0;
|
|
3500
|
+
constructor(store, actions) {
|
|
3501
|
+
this.store = store;
|
|
3502
|
+
this.actions = actions;
|
|
3503
|
+
}
|
|
3504
|
+
invalidate() {}
|
|
3505
|
+
renderList(login) {
|
|
3506
|
+
const lines = [bold$8(secondary$8("Sign in"))];
|
|
3507
|
+
if (login.error !== void 0) lines.push(errorColor$4(login.error));
|
|
3508
|
+
if (login.busy && login.flows === void 0) lines.push(muted$9("Loading…"));
|
|
3509
|
+
login.flows?.forEach((flow, index) => {
|
|
3510
|
+
const marker = flow.inFlight ? "· " : "○ ";
|
|
3511
|
+
const signingIn = login.signingIn === flow.key ? " — signing in…" : "";
|
|
3512
|
+
const text = `${index === login.selected ? "› " : " "}${marker}${flow.label}${signingIn}`;
|
|
3513
|
+
lines.push(index === login.selected ? invert$4(text) : text);
|
|
3514
|
+
});
|
|
3515
|
+
if (login.flows?.length === 0) lines.push(muted$9("No sign-in providers are available in this profile."));
|
|
3516
|
+
lines.push(muted$9("↑↓ select · enter sign in · esc close"));
|
|
3517
|
+
return lines;
|
|
3518
|
+
}
|
|
3519
|
+
renderPrompt(prompt) {
|
|
3520
|
+
const lines = [bold$8(secondary$8("Sign in"))];
|
|
3521
|
+
lines.push(prompt.message);
|
|
3522
|
+
if (prompt.kind === "select") {
|
|
3523
|
+
prompt.options.forEach((option, index) => {
|
|
3524
|
+
const row = `${index === this.promptCursor ? "› " : " "}${option.label}`;
|
|
3525
|
+
lines.push(index === this.promptCursor ? invert$4(row) : row);
|
|
3526
|
+
if (option.description !== void 0) lines.push(muted$9(` ${option.description}`));
|
|
3527
|
+
});
|
|
3528
|
+
lines.push(muted$9("↑↓ choose · enter select · esc cancel"));
|
|
3529
|
+
} else {
|
|
3530
|
+
const mask = prompt.kind === "secret" ? "•" : void 0;
|
|
3531
|
+
const placeholder = prompt.placeholder ?? (prompt.kind === "secret" ? "API key" : "code");
|
|
3532
|
+
const field = this.promptField.value === "" ? `(${placeholder})` : renderMiniTextField(this.promptField, true, mask);
|
|
3533
|
+
lines.push(`> ${field}`);
|
|
3534
|
+
lines.push(muted$9("type + enter submit · esc cancel"));
|
|
3535
|
+
}
|
|
3536
|
+
return lines;
|
|
3537
|
+
}
|
|
3538
|
+
render(_width) {
|
|
3539
|
+
const overlay = this.store.getSnapshot().overlay;
|
|
3540
|
+
if (overlay.kind !== "login") return [];
|
|
3541
|
+
const { prompt } = overlay.login;
|
|
3542
|
+
return prompt === void 0 ? this.renderList(overlay.login) : this.renderPrompt(prompt);
|
|
3543
|
+
}
|
|
3544
|
+
handleInput(data) {
|
|
3545
|
+
const overlay = this.store.getSnapshot().overlay;
|
|
3546
|
+
if (overlay.kind !== "login") return;
|
|
3547
|
+
const { prompt } = overlay.login;
|
|
3548
|
+
if (prompt !== void 0) this.handlePromptInput(data, prompt);
|
|
3549
|
+
else this.handleListInput(data, overlay.login);
|
|
3550
|
+
}
|
|
3551
|
+
handlePromptInput(data, prompt) {
|
|
3552
|
+
if (matchesKey(data, Key.escape)) {
|
|
3553
|
+
this.actions.answerAuthorizationPrompt("");
|
|
3554
|
+
return;
|
|
3555
|
+
}
|
|
3556
|
+
if (prompt.kind === "select") {
|
|
3557
|
+
if (matchesKey(data, Key.up)) {
|
|
3558
|
+
this.promptCursor = Math.max(0, this.promptCursor - 1);
|
|
3559
|
+
return;
|
|
3560
|
+
}
|
|
3561
|
+
if (matchesKey(data, Key.down)) {
|
|
3562
|
+
this.promptCursor = Math.min(prompt.options.length - 1, this.promptCursor + 1);
|
|
3563
|
+
return;
|
|
3564
|
+
}
|
|
3565
|
+
if (matchesKey(data, Key.enter)) this.actions.answerAuthorizationPrompt(prompt.options[this.promptCursor].id);
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
if (matchesKey(data, Key.enter)) {
|
|
3569
|
+
this.actions.answerAuthorizationPrompt(this.promptField.value.trim());
|
|
3570
|
+
return;
|
|
3571
|
+
}
|
|
3572
|
+
const next = miniTextFieldInput(this.promptField, data);
|
|
3573
|
+
if (next !== void 0) this.promptField = next;
|
|
3574
|
+
}
|
|
3575
|
+
handleListInput(data, login) {
|
|
3576
|
+
if (matchesKey(data, Key.escape)) {
|
|
3577
|
+
this.actions.closeLogin();
|
|
3578
|
+
return;
|
|
3579
|
+
}
|
|
3580
|
+
const flows = login.flows;
|
|
3581
|
+
if (flows === void 0 || flows.length === 0) return;
|
|
3582
|
+
if (matchesKey(data, Key.up)) {
|
|
3583
|
+
this.actions.selectLoginFlow(Math.max(0, login.selected - 1));
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
if (matchesKey(data, Key.down)) {
|
|
3587
|
+
this.actions.selectLoginFlow(Math.min(flows.length - 1, login.selected + 1));
|
|
3588
|
+
return;
|
|
3589
|
+
}
|
|
3590
|
+
if (matchesKey(data, Key.enter)) this.actions.beginAuthorization(flows[login.selected].key);
|
|
3591
|
+
}
|
|
3592
|
+
};
|
|
3593
|
+
//#endregion
|
|
3385
3594
|
//#region src/tui/trajectory/layout.ts
|
|
3386
3595
|
const LABEL_LIMIT = 100;
|
|
3387
3596
|
function prettyJson(raw) {
|
|
@@ -4621,7 +4830,12 @@ var TuiApp = class {
|
|
|
4621
4830
|
this.options = options;
|
|
4622
4831
|
const { store, actions } = options;
|
|
4623
4832
|
const terminal = new ProcessTerminal();
|
|
4624
|
-
this.tui = new TuiAltScreen(terminal, true, void 0, {
|
|
4833
|
+
this.tui = new TuiAltScreen(terminal, true, void 0, {
|
|
4834
|
+
mouse: true,
|
|
4835
|
+
onRightClickPaste: () => {
|
|
4836
|
+
readClipboard().then((text) => this.tui.getFocusedComponent()?.handleInput?.(`\x1b[200~${text}\x1b[201~`)).catch(() => {});
|
|
4837
|
+
}
|
|
4838
|
+
});
|
|
4625
4839
|
this.spinner = new Spinner(this.tui);
|
|
4626
4840
|
this.pet = new YlyPet(this.tui);
|
|
4627
4841
|
const transcriptScrollView = new ScrollView(this.documentContainer, {
|
|
@@ -4809,6 +5023,7 @@ var TuiApp = class {
|
|
|
4809
5023
|
switch (overlay.kind) {
|
|
4810
5024
|
case "none": return;
|
|
4811
5025
|
case "modelProfile": return new ModelProfileOverlay(store, actions);
|
|
5026
|
+
case "login": return new LoginOverlay(store, actions);
|
|
4812
5027
|
case "trajectory": return new TrajectoryOverlay(this.tui, store, actions, getTool);
|
|
4813
5028
|
case "toolCards": return new ToolCardsOverlay(this.tui, store, actions, getTool, getToolCall);
|
|
4814
5029
|
case "context": return new ContextOverlay(store, actions);
|
|
@@ -4939,170 +5154,6 @@ function logoutSuccessMessage(provider) {
|
|
|
4939
5154
|
function logoutNoneMessage() {
|
|
4940
5155
|
return "No active provider is selected; nothing to log out.";
|
|
4941
5156
|
}
|
|
4942
|
-
/** The DSH credential-key segment grammar: lowercase hyphenated identifier. */
|
|
4943
|
-
const KEY_SEGMENT_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
4944
|
-
/**
|
|
4945
|
-
* Build the `<scope>/<id>` CredentialKey address for one provider's grant
|
|
4946
|
-
* record. Mirrors the DSH `credentialKey` grammar so the record space stays
|
|
4947
|
-
* valid without a runtime dependency on `@deepseek-ai/dsh-credentials`.
|
|
4948
|
-
*/
|
|
4949
|
-
function grantKey(meta) {
|
|
4950
|
-
const scope = meta.ownerScope ?? "acryl-tui";
|
|
4951
|
-
for (const segment of [scope, meta.route]) if (!KEY_SEGMENT_PATTERN.test(segment)) throw new TypeError(`credential key segment "${segment}" must be a lowercase hyphenated identifier`);
|
|
4952
|
-
return `${scope}/${meta.route}`;
|
|
4953
|
-
}
|
|
4954
|
-
/** The OAuth-capable providers shipped with ACRYL. Empty until a real provider is wired. */
|
|
4955
|
-
const OAUTH_PROVIDERS = [];
|
|
4956
|
-
/** Resolve metadata for a provider route, or undefined when it is not OAuth-capable. */
|
|
4957
|
-
function oauthProviderFor(route) {
|
|
4958
|
-
return OAUTH_PROVIDERS.find((entry) => entry.route === route);
|
|
4959
|
-
}
|
|
4960
|
-
//#endregion
|
|
4961
|
-
//#region src/tui/oauth/flow.ts
|
|
4962
|
-
/**
|
|
4963
|
-
* OAuth authorization-code flow (L010 + L011): PKCE, a one-shot loopback
|
|
4964
|
-
* redirect listener, the code→token exchange, and grant persistence through
|
|
4965
|
-
* the `credentials` record seam (`modifyRecord`/`readRecord`/`deleteRecord`).
|
|
4966
|
-
*
|
|
4967
|
-
* The flow owns exactly one transient resource — an `http.Server` bound to
|
|
4968
|
-
* `127.0.0.1:0` — which is opened and closed inside `runOAuthLogin`. The PKCE
|
|
4969
|
-
* verifier and `state` are in-memory only and never surface to a transcript.
|
|
4970
|
-
* @module @tomowang/dsh-tui/tui/oauth/flow
|
|
4971
|
-
*/
|
|
4972
|
-
function base64Url(input) {
|
|
4973
|
-
return input.toString("base64url");
|
|
4974
|
-
}
|
|
4975
|
-
function makePkce() {
|
|
4976
|
-
const verifier = base64Url(randomBytes(32));
|
|
4977
|
-
return {
|
|
4978
|
-
verifier,
|
|
4979
|
-
challenge: base64Url(createHash("sha256").update(verifier).digest()),
|
|
4980
|
-
state: base64Url(randomBytes(16))
|
|
4981
|
-
};
|
|
4982
|
-
}
|
|
4983
|
-
function toGrantPayload(tokens) {
|
|
4984
|
-
return {
|
|
4985
|
-
accessToken: tokens.access_token,
|
|
4986
|
-
refreshToken: tokens.refresh_token,
|
|
4987
|
-
tokenType: tokens.token_type,
|
|
4988
|
-
expiresAt: tokens.expires_in !== void 0 ? Date.now() + tokens.expires_in * 1e3 : void 0
|
|
4989
|
-
};
|
|
4990
|
-
}
|
|
4991
|
-
function buildAuthorizeUrl(meta, redirectUri, pkce) {
|
|
4992
|
-
const params = new URLSearchParams({
|
|
4993
|
-
response_type: "code",
|
|
4994
|
-
client_id: meta.clientId,
|
|
4995
|
-
redirect_uri: redirectUri,
|
|
4996
|
-
scope: meta.scopes.join(" "),
|
|
4997
|
-
state: pkce.state
|
|
4998
|
-
});
|
|
4999
|
-
if (meta.pkce) {
|
|
5000
|
-
params.set("code_challenge", pkce.challenge);
|
|
5001
|
-
params.set("code_challenge_method", "S256");
|
|
5002
|
-
}
|
|
5003
|
-
if (meta.audience !== void 0) params.set("audience", meta.audience);
|
|
5004
|
-
return `${meta.authorizeUrl}?${params.toString()}`;
|
|
5005
|
-
}
|
|
5006
|
-
/** Attach the one-shot callback handler and return a promise for the code. */
|
|
5007
|
-
function awaitCallback(server, state, timeoutMs) {
|
|
5008
|
-
return new Promise((resolve, reject) => {
|
|
5009
|
-
const timer = setTimeout(() => {
|
|
5010
|
-
reject(/* @__PURE__ */ new Error("OAuth login timed out waiting for the redirect."));
|
|
5011
|
-
server.close();
|
|
5012
|
-
}, timeoutMs);
|
|
5013
|
-
server.on("request", (request, response) => {
|
|
5014
|
-
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
5015
|
-
if (url.pathname !== "/callback") {
|
|
5016
|
-
response.writeHead(404).end();
|
|
5017
|
-
return;
|
|
5018
|
-
}
|
|
5019
|
-
clearTimeout(timer);
|
|
5020
|
-
response.writeHead(200, { "content-type": "text/plain" }).end("Authorization complete. You can return to ACRYL.");
|
|
5021
|
-
const code = url.searchParams.get("code");
|
|
5022
|
-
const returnedState = url.searchParams.get("state");
|
|
5023
|
-
server.close();
|
|
5024
|
-
if (returnedState !== state) reject(/* @__PURE__ */ new Error("OAuth state mismatch."));
|
|
5025
|
-
else if (code === null) reject(/* @__PURE__ */ new Error("OAuth redirect did not include an authorization code."));
|
|
5026
|
-
else resolve(code);
|
|
5027
|
-
});
|
|
5028
|
-
});
|
|
5029
|
-
}
|
|
5030
|
-
/** Open the authorize URL in the platform's default browser. */
|
|
5031
|
-
function defaultOpenUrl(url) {
|
|
5032
|
-
const platform = process.platform;
|
|
5033
|
-
const command = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", [
|
|
5034
|
-
"/c",
|
|
5035
|
-
"start",
|
|
5036
|
-
"",
|
|
5037
|
-
url
|
|
5038
|
-
]] : ["xdg-open", [url]];
|
|
5039
|
-
return new Promise((resolve) => {
|
|
5040
|
-
execFile(command[0], command[1], () => resolve());
|
|
5041
|
-
});
|
|
5042
|
-
}
|
|
5043
|
-
/** POST the authorization code to the token endpoint and normalize the body. */
|
|
5044
|
-
async function exchangeCode(meta, code, redirectUri, pkce) {
|
|
5045
|
-
const body = new URLSearchParams({
|
|
5046
|
-
grant_type: "authorization_code",
|
|
5047
|
-
code,
|
|
5048
|
-
redirect_uri: redirectUri,
|
|
5049
|
-
client_id: meta.clientId
|
|
5050
|
-
});
|
|
5051
|
-
if (meta.pkce) body.set("code_verifier", pkce.verifier);
|
|
5052
|
-
return postToken(meta, body);
|
|
5053
|
-
}
|
|
5054
|
-
/** POST to the token endpoint; shared by the code and refresh exchanges. */
|
|
5055
|
-
async function postToken(meta, body) {
|
|
5056
|
-
const response = await fetch(meta.tokenUrl, {
|
|
5057
|
-
method: "POST",
|
|
5058
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
5059
|
-
body: body.toString()
|
|
5060
|
-
});
|
|
5061
|
-
if (!response.ok) {
|
|
5062
|
-
const text = await response.text().catch(() => "");
|
|
5063
|
-
throw new Error(`token request failed (${response.status}): ${text}`);
|
|
5064
|
-
}
|
|
5065
|
-
return await response.json();
|
|
5066
|
-
}
|
|
5067
|
-
/** Run the full authorization-code flow and persist the resulting grant. */
|
|
5068
|
-
async function runOAuthLogin(meta, credentials, options = {}) {
|
|
5069
|
-
const server = createServer();
|
|
5070
|
-
try {
|
|
5071
|
-
const pkce = makePkce();
|
|
5072
|
-
await new Promise((resolve, reject) => {
|
|
5073
|
-
server.once("error", reject);
|
|
5074
|
-
server.listen(0, "127.0.0.1", resolve);
|
|
5075
|
-
});
|
|
5076
|
-
const { port } = server.address();
|
|
5077
|
-
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
5078
|
-
const authorizeUrl = buildAuthorizeUrl(meta, redirectUri, pkce);
|
|
5079
|
-
const codePromise = awaitCallback(server, pkce.state, options.timeoutMs ?? 3e5);
|
|
5080
|
-
codePromise.catch(() => {});
|
|
5081
|
-
await (options.openUrl ?? defaultOpenUrl)(authorizeUrl);
|
|
5082
|
-
const tokens = await exchangeCode(meta, await codePromise, redirectUri, pkce);
|
|
5083
|
-
await credentials.modifyRecord(grantKey(meta), async () => ({
|
|
5084
|
-
kind: "grant",
|
|
5085
|
-
payload: toGrantPayload(tokens)
|
|
5086
|
-
}));
|
|
5087
|
-
return { ok: true };
|
|
5088
|
-
} catch (error) {
|
|
5089
|
-
return {
|
|
5090
|
-
ok: false,
|
|
5091
|
-
error: error instanceof Error ? error.message : String(error)
|
|
5092
|
-
};
|
|
5093
|
-
} finally {
|
|
5094
|
-
if (server.listening) server.close();
|
|
5095
|
-
}
|
|
5096
|
-
}
|
|
5097
|
-
/** Read the stored grant for a provider, or undefined when none is stored. */
|
|
5098
|
-
async function readOAuthGrant(meta, credentials) {
|
|
5099
|
-
const record = await credentials.readRecord(grantKey(meta));
|
|
5100
|
-
return record?.kind === "grant" ? record.payload : void 0;
|
|
5101
|
-
}
|
|
5102
|
-
/** Revoke (delete) a provider's stored grant. Removing an absent record is a no-op. */
|
|
5103
|
-
async function revokeOAuthGrant(meta, credentials) {
|
|
5104
|
-
await credentials.deleteRecord(grantKey(meta));
|
|
5105
|
-
}
|
|
5106
5157
|
/** Canonical ACRYL version string used by the CLI and the release smoke checks. */
|
|
5107
5158
|
const ACRYL_VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
5108
5159
|
//#endregion
|
|
@@ -5163,6 +5214,19 @@ function deriveApiKeyRef(route) {
|
|
|
5163
5214
|
const upper = route.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
5164
5215
|
return `${/^[A-Z_]/.test(upper) ? upper : `P_${upper}`}_API_KEY`;
|
|
5165
5216
|
}
|
|
5217
|
+
/** Open a URL in the platform's default browser (fire-and-forget). */
|
|
5218
|
+
function openBrowser(url) {
|
|
5219
|
+
const platform = process.platform;
|
|
5220
|
+
const command = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", [
|
|
5221
|
+
"/c",
|
|
5222
|
+
"start",
|
|
5223
|
+
"",
|
|
5224
|
+
url
|
|
5225
|
+
]] : ["xdg-open", [url]];
|
|
5226
|
+
return new Promise((resolve) => {
|
|
5227
|
+
execFile(command[0], command[1], () => resolve());
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
5166
5230
|
/** Nest a provider settings section at its path, e.g. `['providers','deepseek']` -> `{ providers: { deepseek: section } }`. */
|
|
5167
5231
|
function nestAtPath(path, section) {
|
|
5168
5232
|
let patch = section;
|
|
@@ -5236,8 +5300,6 @@ async function attachSession(host, resumeId) {
|
|
|
5236
5300
|
const userValue = descriptor === void 0 ? void 0 : getAtPath(descriptor.user, entry.settingsPath);
|
|
5237
5301
|
const apiKeyRef = value?.apiKeyEnv ?? deriveApiKeyRef(entry.provider);
|
|
5238
5302
|
const info = await credentialsSvc.describe(apiKeyRef);
|
|
5239
|
-
const oauth = oauthProviderFor(entry.provider);
|
|
5240
|
-
const grant = oauth === void 0 ? void 0 : await readOAuthGrant(oauth, credentialsSvc);
|
|
5241
5303
|
rows.push({
|
|
5242
5304
|
route: entry.provider,
|
|
5243
5305
|
displayName: value?.displayName ?? entry.displayName,
|
|
@@ -5249,8 +5311,6 @@ async function attachSession(host, resumeId) {
|
|
|
5249
5311
|
baseURL: value?.baseURL,
|
|
5250
5312
|
apiKeyRef,
|
|
5251
5313
|
apiKeyConfigured: info.configured,
|
|
5252
|
-
oauth,
|
|
5253
|
-
grantConfigured: grant !== void 0,
|
|
5254
5314
|
models: value?.models ?? [],
|
|
5255
5315
|
revision: descriptor?.revision
|
|
5256
5316
|
});
|
|
@@ -5262,6 +5322,30 @@ async function attachSession(host, resumeId) {
|
|
|
5262
5322
|
selected: 0
|
|
5263
5323
|
});
|
|
5264
5324
|
}
|
|
5325
|
+
async function loadAuthorizationFlows() {
|
|
5326
|
+
const authSvc = host.ctx.get("authorization");
|
|
5327
|
+
if (authSvc === void 0) {
|
|
5328
|
+
store.updateLogin({
|
|
5329
|
+
flows: [],
|
|
5330
|
+
busy: false,
|
|
5331
|
+
error: "Sign-in is not available in this profile."
|
|
5332
|
+
});
|
|
5333
|
+
return;
|
|
5334
|
+
}
|
|
5335
|
+
try {
|
|
5336
|
+
const list = authSvc.list();
|
|
5337
|
+
store.updateLogin({
|
|
5338
|
+
flows: list,
|
|
5339
|
+
busy: false,
|
|
5340
|
+
error: void 0
|
|
5341
|
+
});
|
|
5342
|
+
} catch (error) {
|
|
5343
|
+
store.updateLogin({
|
|
5344
|
+
busy: false,
|
|
5345
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5346
|
+
});
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5265
5349
|
async function loadAgentPresets() {
|
|
5266
5350
|
const presetsSvc = host.ctx.get("agentPresets");
|
|
5267
5351
|
if (presetsSvc === void 0) {
|
|
@@ -5292,6 +5376,7 @@ async function attachSession(host, resumeId) {
|
|
|
5292
5376
|
});
|
|
5293
5377
|
}
|
|
5294
5378
|
}
|
|
5379
|
+
let pendingPromptResolve;
|
|
5295
5380
|
const actions = {
|
|
5296
5381
|
send(text) {
|
|
5297
5382
|
store.setNotice(void 0);
|
|
@@ -5410,29 +5495,84 @@ async function attachSession(host, resumeId) {
|
|
|
5410
5495
|
loadProviders();
|
|
5411
5496
|
},
|
|
5412
5497
|
login() {
|
|
5413
|
-
store.
|
|
5414
|
-
|
|
5498
|
+
store.openLogin();
|
|
5499
|
+
loadAuthorizationFlows();
|
|
5500
|
+
},
|
|
5501
|
+
closeLogin() {
|
|
5502
|
+
store.closeOverlay();
|
|
5415
5503
|
},
|
|
5416
|
-
|
|
5504
|
+
selectLoginFlow(index) {
|
|
5505
|
+
store.updateLogin({ selected: index });
|
|
5506
|
+
},
|
|
5507
|
+
beginAuthorization(key) {
|
|
5417
5508
|
(async () => {
|
|
5418
|
-
const
|
|
5419
|
-
if (
|
|
5420
|
-
store.setNotice("
|
|
5509
|
+
const authSvc = host.ctx.get("authorization");
|
|
5510
|
+
if (authSvc === void 0) {
|
|
5511
|
+
store.setNotice("Sign-in is not available in this profile.");
|
|
5421
5512
|
return;
|
|
5422
5513
|
}
|
|
5423
|
-
const
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5514
|
+
const overlay = store.getSnapshot().overlay;
|
|
5515
|
+
const flow = overlay.kind === "login" ? overlay.login.flows?.find((entry) => entry.key === key) : void 0;
|
|
5516
|
+
if (flow === void 0) return;
|
|
5517
|
+
store.updateLogin({ signingIn: key });
|
|
5518
|
+
const interaction = {
|
|
5519
|
+
notify(notice) {
|
|
5520
|
+
if (notice.url !== void 0) openBrowser(notice.url);
|
|
5521
|
+
const parts = [notice.message];
|
|
5522
|
+
if (notice.url !== void 0) parts.push(notice.url);
|
|
5523
|
+
if (notice.code !== void 0) parts.push(`Code: ${notice.code}`);
|
|
5524
|
+
store.setNotice(parts.join("\n"));
|
|
5525
|
+
},
|
|
5526
|
+
async prompt(prompt) {
|
|
5527
|
+
return await new Promise((resolve, reject) => {
|
|
5528
|
+
if (prompt.signal?.aborted) {
|
|
5529
|
+
reject(/* @__PURE__ */ new Error("authorization prompt withdrawn"));
|
|
5530
|
+
return;
|
|
5531
|
+
}
|
|
5532
|
+
pendingPromptResolve = resolve;
|
|
5533
|
+
const state = prompt.kind === "select" ? {
|
|
5534
|
+
kind: "select",
|
|
5535
|
+
message: prompt.message,
|
|
5536
|
+
options: (prompt.options ?? []).map((option) => ({
|
|
5537
|
+
id: option.id,
|
|
5538
|
+
label: option.label,
|
|
5539
|
+
description: option.description
|
|
5540
|
+
}))
|
|
5541
|
+
} : {
|
|
5542
|
+
kind: prompt.kind,
|
|
5543
|
+
message: prompt.message,
|
|
5544
|
+
placeholder: prompt.placeholder
|
|
5545
|
+
};
|
|
5546
|
+
store.updateLogin({ prompt: state });
|
|
5547
|
+
prompt.signal?.addEventListener("abort", () => {
|
|
5548
|
+
if (pendingPromptResolve === resolve) pendingPromptResolve = void 0;
|
|
5549
|
+
store.updateLogin({ prompt: void 0 });
|
|
5550
|
+
reject(/* @__PURE__ */ new Error("authorization prompt withdrawn"));
|
|
5551
|
+
}, { once: true });
|
|
5552
|
+
});
|
|
5553
|
+
}
|
|
5554
|
+
};
|
|
5555
|
+
try {
|
|
5556
|
+
if ((await authSvc.begin({
|
|
5557
|
+
key,
|
|
5558
|
+
interaction
|
|
5559
|
+
})).status === "authorized") {
|
|
5560
|
+
store.setNotice(`Signed in to ${flow.label}.`);
|
|
5561
|
+
loadAuthorizationFlows();
|
|
5562
|
+
} else store.setNotice("Sign-in cancelled.");
|
|
5563
|
+
} catch (error) {
|
|
5564
|
+
store.setNotice(`Sign-in failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5565
|
+
} finally {
|
|
5566
|
+
store.updateLogin({ signingIn: void 0 });
|
|
5427
5567
|
}
|
|
5428
|
-
store.setNotice(`Opening ${meta.route} OAuth login…`);
|
|
5429
|
-
const result = await runOAuthLogin(meta, credentialsSvc);
|
|
5430
|
-
if (result.ok) {
|
|
5431
|
-
store.setNotice(`OAuth login complete for ${meta.route}.`);
|
|
5432
|
-
loadProviders();
|
|
5433
|
-
} else store.setNotice(`OAuth login failed: ${result.error}`);
|
|
5434
5568
|
})();
|
|
5435
5569
|
},
|
|
5570
|
+
answerAuthorizationPrompt(value) {
|
|
5571
|
+
const resolve = pendingPromptResolve;
|
|
5572
|
+
pendingPromptResolve = void 0;
|
|
5573
|
+
store.updateLogin({ prompt: void 0 });
|
|
5574
|
+
if (resolve !== void 0) resolve(value);
|
|
5575
|
+
},
|
|
5436
5576
|
logout() {
|
|
5437
5577
|
(async () => {
|
|
5438
5578
|
const credentialsSvc = host.ctx.get("credentials");
|
|
@@ -5449,8 +5589,6 @@ async function attachSession(host, resumeId) {
|
|
|
5449
5589
|
return;
|
|
5450
5590
|
}
|
|
5451
5591
|
try {
|
|
5452
|
-
const oauth = oauthProviderFor(row.route);
|
|
5453
|
-
if (oauth !== void 0) await revokeOAuthGrant(oauth, credentialsSvc);
|
|
5454
5592
|
await credentialsSvc.unset(row.apiKeyRef);
|
|
5455
5593
|
store.setNotice(logoutSuccessMessage(row.displayName));
|
|
5456
5594
|
loadProviders();
|