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/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
5
5
|
import { existsSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join, relative, resolve } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
|
|
9
|
+
import { execFile, spawn } from "node:child_process";
|
|
9
10
|
import { diffLines } from "diff";
|
|
10
11
|
import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
11
|
-
import { execFile, spawn } from "node:child_process";
|
|
12
12
|
import { readdir } from "node:fs/promises";
|
|
13
|
-
import { createServer } from "node:http";
|
|
14
13
|
import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
|
|
15
14
|
import { GoalError } from "@deepseek-ai/dsh-goal";
|
|
16
15
|
//#region src/cli/grammar.ts
|
|
@@ -297,22 +296,29 @@ const ACRYL_RUNTIME_ROWS = [{
|
|
|
297
296
|
id: "system-prompt",
|
|
298
297
|
name: "@deepseek-ai/dsh-system-prompt",
|
|
299
298
|
config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
|
|
300
|
-
}, { insert: [
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
299
|
+
}, { insert: [
|
|
300
|
+
{
|
|
301
|
+
id: "agent-presets",
|
|
302
|
+
name: "@deepseek-ai/dsh-agent-presets",
|
|
303
|
+
config: {
|
|
304
|
+
default: "standard",
|
|
305
|
+
roots: existsSync(shippedPresetsDir) ? [{
|
|
306
|
+
path: shippedPresetsDir,
|
|
307
|
+
trust: "system"
|
|
308
|
+
}] : [],
|
|
309
|
+
includeShippedRoot: false,
|
|
310
|
+
includeUserRoot: true
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: "session-stats",
|
|
315
|
+
name: "@deepseek-ai/dsh-session-stats"
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
id: "authorization",
|
|
319
|
+
name: "@deepseek-ai/dsh-authorization"
|
|
311
320
|
}
|
|
312
|
-
}
|
|
313
|
-
id: "session-stats",
|
|
314
|
-
name: "@deepseek-ai/dsh-session-stats"
|
|
315
|
-
}] }];
|
|
321
|
+
] }];
|
|
316
322
|
/** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
|
|
317
323
|
async function bootAcrylHarnessProfile(options) {
|
|
318
324
|
if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
|
|
@@ -421,7 +427,7 @@ const ESC = "\x1B[";
|
|
|
421
427
|
const dim$2 = fg(theme.muted);
|
|
422
428
|
const cyan$1 = fg(theme.secondary);
|
|
423
429
|
const primary = fg(theme.primary);
|
|
424
|
-
const bold$
|
|
430
|
+
const bold$11 = (s) => `${ESC}1m${s}${ESC}0m`;
|
|
425
431
|
const italic = (s) => `${ESC}3m${s}${ESC}0m`;
|
|
426
432
|
const strike = (s) => `${ESC}9m${s}${ESC}0m`;
|
|
427
433
|
const underline = (s) => `${ESC}4m${s}${ESC}0m`;
|
|
@@ -465,7 +471,7 @@ function looksLikeMarkdown(text) {
|
|
|
465
471
|
/** Style links, bold, strikethrough, and emphasis in a span already known to contain no inline code. */
|
|
466
472
|
function applyNonCodeInline(text) {
|
|
467
473
|
let working = text.replaceAll(LINK_RE_G, (_match, label, url) => hyperlink(url, underline(primary(label))));
|
|
468
|
-
working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$
|
|
474
|
+
working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$11(a ?? b ?? ""));
|
|
469
475
|
working = working.replaceAll(STRIKE_RE_G, (_match, t) => strike(t));
|
|
470
476
|
return working.replaceAll(ITALIC_RE_G, (_match, a, b) => italic(a ?? b ?? ""));
|
|
471
477
|
}
|
|
@@ -531,7 +537,7 @@ function padCell(styled, width, align) {
|
|
|
531
537
|
}
|
|
532
538
|
/** Pad one row of already-styled cells (header or body) to a single column-aligned line. */
|
|
533
539
|
function formatTableRow(styledCells, widths, aligns, isHeader) {
|
|
534
|
-
return widths.map((width, i) => padCell(isHeader ? bold$
|
|
540
|
+
return widths.map((width, i) => padCell(isHeader ? bold$11(styledCells[i] ?? "") : styledCells[i] ?? "", width, aligns[i] ?? "left")).join(dim$2(" │ "));
|
|
535
541
|
}
|
|
536
542
|
/** A dim horizontal rule under the header row, with a cross at each column boundary. */
|
|
537
543
|
function formatTableRule(widths) {
|
|
@@ -588,7 +594,7 @@ function renderMarkdown(text) {
|
|
|
588
594
|
if (header !== null) {
|
|
589
595
|
const level = header[1].length;
|
|
590
596
|
const content = applyInline(header[2]);
|
|
591
|
-
out.push(level === 1 ? bold$
|
|
597
|
+
out.push(level === 1 ? bold$11(primary(content)) : level === 2 ? bold$11(cyan$1(content)) : bold$11(content));
|
|
592
598
|
continue;
|
|
593
599
|
}
|
|
594
600
|
if (HR_RE.test(line)) {
|
|
@@ -1213,6 +1219,31 @@ var TuiStore = class {
|
|
|
1213
1219
|
}
|
|
1214
1220
|
} });
|
|
1215
1221
|
}
|
|
1222
|
+
/** Open the `/login` sign-in overlay to a fresh, loading flow list. */
|
|
1223
|
+
openLogin() {
|
|
1224
|
+
this.set({ overlay: {
|
|
1225
|
+
kind: "login",
|
|
1226
|
+
login: {
|
|
1227
|
+
flows: void 0,
|
|
1228
|
+
selected: 0,
|
|
1229
|
+
signingIn: void 0,
|
|
1230
|
+
prompt: void 0,
|
|
1231
|
+
busy: true,
|
|
1232
|
+
error: void 0
|
|
1233
|
+
}
|
|
1234
|
+
} });
|
|
1235
|
+
}
|
|
1236
|
+
/** Patch the open `/login` overlay's sub-state; a no-op once it's closed. */
|
|
1237
|
+
updateLogin(patch) {
|
|
1238
|
+
if (this.state.overlay.kind !== "login") return;
|
|
1239
|
+
this.set({ overlay: {
|
|
1240
|
+
kind: "login",
|
|
1241
|
+
login: {
|
|
1242
|
+
...this.state.overlay.login,
|
|
1243
|
+
...patch
|
|
1244
|
+
}
|
|
1245
|
+
} });
|
|
1246
|
+
}
|
|
1216
1247
|
/** Open the `/trajectory` ledger overlay. */
|
|
1217
1248
|
openTrajectory() {
|
|
1218
1249
|
this.set({ overlay: { kind: "trajectory" } });
|
|
@@ -1764,10 +1795,10 @@ function runSlashCommand(command, actions) {
|
|
|
1764
1795
|
}
|
|
1765
1796
|
//#endregion
|
|
1766
1797
|
//#region src/tui/piTheme.ts
|
|
1767
|
-
const bold$
|
|
1798
|
+
const bold$10 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
1768
1799
|
const selectListTheme = {
|
|
1769
1800
|
selectedPrefix: fg(theme.primary),
|
|
1770
|
-
selectedText: (s) => bold$
|
|
1801
|
+
selectedText: (s) => bold$10(fg(theme.primary)(s)),
|
|
1771
1802
|
description: fg(theme.muted),
|
|
1772
1803
|
scrollInfo: fg(theme.muted),
|
|
1773
1804
|
noMatch: fg(theme.muted)
|
|
@@ -2092,6 +2123,68 @@ var Spinner = class {
|
|
|
2092
2123
|
}
|
|
2093
2124
|
};
|
|
2094
2125
|
//#endregion
|
|
2126
|
+
//#region src/tui/clipboard.ts
|
|
2127
|
+
/**
|
|
2128
|
+
* System-clipboard read, used for right-click paste. Node has no built-in
|
|
2129
|
+
* clipboard API, so this shells out to the platform's clipboard tool via
|
|
2130
|
+
* `execFile` (the same `node:child_process` approach used elsewhere for
|
|
2131
|
+
* platform launchers like `open`/`xdg-open`).
|
|
2132
|
+
* @module @tomowang/dsh-tui/tui/clipboard
|
|
2133
|
+
*/
|
|
2134
|
+
function clipboardCommands() {
|
|
2135
|
+
switch (process.platform) {
|
|
2136
|
+
case "darwin": return [["pbpaste", []]];
|
|
2137
|
+
case "win32": return [["powershell.exe", [
|
|
2138
|
+
"-NoProfile",
|
|
2139
|
+
"-NonInteractive",
|
|
2140
|
+
"-Command",
|
|
2141
|
+
"Get-Clipboard"
|
|
2142
|
+
]]];
|
|
2143
|
+
default: return [
|
|
2144
|
+
["xclip", [
|
|
2145
|
+
"-selection",
|
|
2146
|
+
"clipboard",
|
|
2147
|
+
"-o"
|
|
2148
|
+
]],
|
|
2149
|
+
["xsel", ["--clipboard", "--output"]],
|
|
2150
|
+
["wl-paste", ["--no-newline"]]
|
|
2151
|
+
];
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Read the system clipboard. Resolves with the clipboard text (possibly empty).
|
|
2156
|
+
* Rejects when no supported clipboard tool is available on this host.
|
|
2157
|
+
*
|
|
2158
|
+
* A single trailing newline is stripped: `pbpaste` prints the clipboard verbatim,
|
|
2159
|
+
* while `xclip`/`xsel`/`Get-Clipboard` append one, so this keeps the result
|
|
2160
|
+
* consistent with a native terminal paste (which inserts exactly what was copied).
|
|
2161
|
+
*/
|
|
2162
|
+
function readClipboard() {
|
|
2163
|
+
return new Promise((resolve, reject) => {
|
|
2164
|
+
const commands = clipboardCommands();
|
|
2165
|
+
let index = 0;
|
|
2166
|
+
const attempt = () => {
|
|
2167
|
+
if (index >= commands.length) {
|
|
2168
|
+
reject(/* @__PURE__ */ new Error("no clipboard tool available"));
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
const [command, args] = commands[index];
|
|
2172
|
+
index += 1;
|
|
2173
|
+
execFile(command, args, {
|
|
2174
|
+
encoding: "utf8",
|
|
2175
|
+
maxBuffer: 10 * 1024 * 1024
|
|
2176
|
+
}, (error, stdout) => {
|
|
2177
|
+
if (error) {
|
|
2178
|
+
attempt();
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
resolve(stdout.replace(/\r?\n$/, ""));
|
|
2182
|
+
});
|
|
2183
|
+
};
|
|
2184
|
+
attempt();
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
//#endregion
|
|
2095
2188
|
//#region src/yly/yly-frames.generated.ts
|
|
2096
2189
|
const YLY_FRAMES = {
|
|
2097
2190
|
"small": [
|
|
@@ -3011,6 +3104,15 @@ var YlyPet = class {
|
|
|
3011
3104
|
* delegate keystrokes to a field nested inside a larger custom overlay.
|
|
3012
3105
|
* @module @tomowang/dsh-tui/tui/miniTextField
|
|
3013
3106
|
*/
|
|
3107
|
+
const BRACKETED_PASTE_START = "\x1B[200~";
|
|
3108
|
+
const BRACKETED_PASTE_END = "\x1B[201~";
|
|
3109
|
+
/** Extract the content of one bracketed-paste sequence, or `undefined` if `data` is not one. */
|
|
3110
|
+
function extractBracketedPaste(data) {
|
|
3111
|
+
if (!data.startsWith(BRACKETED_PASTE_START)) return void 0;
|
|
3112
|
+
const end = data.indexOf(BRACKETED_PASTE_END);
|
|
3113
|
+
if (end === -1) return void 0;
|
|
3114
|
+
return data.slice(6, end);
|
|
3115
|
+
}
|
|
3014
3116
|
function emptyMiniTextField(value = "") {
|
|
3015
3117
|
return {
|
|
3016
3118
|
value,
|
|
@@ -3049,6 +3151,15 @@ function miniTextFieldInput(state, data) {
|
|
|
3049
3151
|
cursor: state.cursor
|
|
3050
3152
|
};
|
|
3051
3153
|
}
|
|
3154
|
+
const paste = extractBracketedPaste(data);
|
|
3155
|
+
if (paste !== void 0) {
|
|
3156
|
+
const text = paste.replace(/[\r\n]+/g, "");
|
|
3157
|
+
if (text.length === 0) return state;
|
|
3158
|
+
return {
|
|
3159
|
+
value: state.value.slice(0, state.cursor) + text + state.value.slice(state.cursor),
|
|
3160
|
+
cursor: state.cursor + text.length
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3052
3163
|
if (data.length > 0 && !data.startsWith("\x1B") && data !== "\r" && data !== "\n" && data !== " ") return {
|
|
3053
3164
|
value: state.value.slice(0, state.cursor) + data + state.value.slice(state.cursor),
|
|
3054
3165
|
cursor: state.cursor + data.length
|
|
@@ -3062,11 +3173,11 @@ function renderMiniTextField(state, cursorVisible, mask) {
|
|
|
3062
3173
|
}
|
|
3063
3174
|
//#endregion
|
|
3064
3175
|
//#region src/tui/modelProfile/ModelProfileOverlay.ts
|
|
3065
|
-
const bold$
|
|
3066
|
-
const secondary$
|
|
3067
|
-
const muted$
|
|
3068
|
-
const errorColor$
|
|
3069
|
-
const invert$
|
|
3176
|
+
const bold$9 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
3177
|
+
const secondary$9 = fg(theme.secondary);
|
|
3178
|
+
const muted$10 = fg(theme.muted);
|
|
3179
|
+
const errorColor$5 = fg(theme.error);
|
|
3180
|
+
const invert$5 = (s) => `\x1b[7m${s}\x1b[0m`;
|
|
3070
3181
|
var ModelProfileOverlay = class {
|
|
3071
3182
|
store;
|
|
3072
3183
|
actions;
|
|
@@ -3143,21 +3254,19 @@ var ModelProfileOverlay = class {
|
|
|
3143
3254
|
}
|
|
3144
3255
|
renderList(mp) {
|
|
3145
3256
|
const { providers, selected, busy, error } = mp;
|
|
3146
|
-
const lines = [bold$
|
|
3147
|
-
if (error !== void 0) lines.push(errorColor$
|
|
3148
|
-
if (busy && providers === void 0) lines.push(muted$
|
|
3257
|
+
const lines = [bold$9(secondary$9("Model providers"))];
|
|
3258
|
+
if (error !== void 0) lines.push(errorColor$5(error));
|
|
3259
|
+
if (busy && providers === void 0) lines.push(muted$10("Loading…"));
|
|
3149
3260
|
providers?.forEach((row, index) => {
|
|
3150
3261
|
const marker = row.configured ? "● " : "○ ";
|
|
3151
3262
|
const active = row.live ? " (active)" : "";
|
|
3152
3263
|
const noKey = row.apiKeyConfigured ? "" : " [no api key]";
|
|
3153
|
-
const oauthStatus = row.oauth === void 0 ? "" : row.grantConfigured ? " [oauth ✓]" : " [oauth]";
|
|
3154
3264
|
const confirm = this.confirmDelete === index ? " — press d again to delete" : "";
|
|
3155
|
-
const text = `${index === selected ? "› " : " "}${marker}${row.displayName}${active}${noKey}${
|
|
3156
|
-
lines.push(index === selected ? invert$
|
|
3265
|
+
const text = `${index === selected ? "› " : " "}${marker}${row.displayName}${active}${noKey}${confirm}`;
|
|
3266
|
+
lines.push(index === selected ? invert$5(text) : text);
|
|
3157
3267
|
});
|
|
3158
|
-
if (providers?.length === 0) lines.push(muted$
|
|
3159
|
-
|
|
3160
|
-
lines.push(muted$9(`↑↓ select · enter edit · a add · d delete · s set active model${hasOauth ? " · o login with oauth" : ""} · esc close`));
|
|
3268
|
+
if (providers?.length === 0) lines.push(muted$10("No providers configured yet — press a to add one."));
|
|
3269
|
+
lines.push(muted$10("↑↓ select · enter edit · a add · d delete · s set active model · esc close"));
|
|
3161
3270
|
return lines;
|
|
3162
3271
|
}
|
|
3163
3272
|
handleListInput(data, mp) {
|
|
@@ -3194,11 +3303,6 @@ var ModelProfileOverlay = class {
|
|
|
3194
3303
|
if (model !== void 0) this.actions.setActiveModel(row.route, model.id);
|
|
3195
3304
|
return;
|
|
3196
3305
|
}
|
|
3197
|
-
if (data === "o") {
|
|
3198
|
-
const row = providers[selected];
|
|
3199
|
-
if (row.oauth !== void 0) this.actions.loginWithOAuth(row.route);
|
|
3200
|
-
return;
|
|
3201
|
-
}
|
|
3202
3306
|
if (data === "d") {
|
|
3203
3307
|
if (this.confirmDelete === selected) {
|
|
3204
3308
|
this.confirmDelete = void 0;
|
|
@@ -3226,8 +3330,8 @@ var ModelProfileOverlay = class {
|
|
|
3226
3330
|
baseURL: "Base URL",
|
|
3227
3331
|
apiKey: draft.apiKeyConfigured ? "API key (set — leave blank to keep)" : "API key"
|
|
3228
3332
|
};
|
|
3229
|
-
const lines = [bold$
|
|
3230
|
-
if (mp.error !== void 0) lines.push(errorColor$
|
|
3333
|
+
const lines = [bold$9(secondary$9(draft.isNew ? "Add provider" : `Edit ${draft.displayName || draft.route}`))];
|
|
3334
|
+
if (mp.error !== void 0) lines.push(errorColor$5(mp.error));
|
|
3231
3335
|
textFields.forEach((field, index) => {
|
|
3232
3336
|
const isFocused = this.focused === index;
|
|
3233
3337
|
const mask = field === "apiKey" ? "*" : void 0;
|
|
@@ -3235,10 +3339,10 @@ var ModelProfileOverlay = class {
|
|
|
3235
3339
|
lines.push(`${prefix}${renderMiniTextField(fieldState[field], isFocused, mask)}`);
|
|
3236
3340
|
});
|
|
3237
3341
|
const modelsText = `${this.focused === modelsRow ? "› " : " "}Models (${this.models.length}) — enter to edit`;
|
|
3238
|
-
lines.push(this.focused === modelsRow ? invert$
|
|
3342
|
+
lines.push(this.focused === modelsRow ? invert$5(modelsText) : modelsText);
|
|
3239
3343
|
const saveText = `${this.focused === saveRow ? "› " : " "}${mp.busy ? "Saving…" : "Save"}`;
|
|
3240
|
-
lines.push(this.focused === saveRow ? invert$
|
|
3241
|
-
lines.push(muted$
|
|
3344
|
+
lines.push(this.focused === saveRow ? invert$5(saveText) : saveText);
|
|
3345
|
+
lines.push(muted$10("tab/shift+tab move · enter confirm field / activate row · esc cancel"));
|
|
3242
3346
|
return lines;
|
|
3243
3347
|
}
|
|
3244
3348
|
handleFormInput(data, draft) {
|
|
@@ -3288,21 +3392,21 @@ var ModelProfileOverlay = class {
|
|
|
3288
3392
|
}
|
|
3289
3393
|
}
|
|
3290
3394
|
renderModelListEditor(mp) {
|
|
3291
|
-
const lines = [bold$
|
|
3395
|
+
const lines = [bold$9(secondary$9("Models"))];
|
|
3292
3396
|
this.models.forEach((model, index) => {
|
|
3293
3397
|
const isSelected = !this.modelInputFocused && index === this.modelSelected;
|
|
3294
3398
|
const text = `${isSelected ? "› " : " "}${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`;
|
|
3295
|
-
lines.push(isSelected ? invert$
|
|
3399
|
+
lines.push(isSelected ? invert$5(text) : text);
|
|
3296
3400
|
});
|
|
3297
|
-
if (this.models.length === 0) lines.push(muted$
|
|
3401
|
+
if (this.models.length === 0) lines.push(muted$10("No models yet."));
|
|
3298
3402
|
lines.push(`${this.modelInputFocused ? "› " : " "}Add id: ${renderMiniTextField(this.modelDraftId, this.modelInputFocused)}`);
|
|
3299
|
-
if (mp.busy) lines.push(muted$
|
|
3300
|
-
if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$
|
|
3403
|
+
if (mp.busy) lines.push(muted$10("Discovering…"));
|
|
3404
|
+
if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$10("No models discovered."));
|
|
3301
3405
|
else {
|
|
3302
|
-
lines.push(muted$
|
|
3303
|
-
for (const model of mp.discovered) lines.push(muted$
|
|
3406
|
+
lines.push(muted$10("Discovered — tab to the id field and type one to adopt it:"));
|
|
3407
|
+
for (const model of mp.discovered) lines.push(muted$10(` ${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`));
|
|
3304
3408
|
}
|
|
3305
|
-
lines.push(muted$
|
|
3409
|
+
lines.push(muted$10("tab toggle list/input · ↑↓ select · x remove · g discover · esc back"));
|
|
3306
3410
|
return lines;
|
|
3307
3411
|
}
|
|
3308
3412
|
addModel(id) {
|
|
@@ -3363,6 +3467,111 @@ var ModelProfileOverlay = class {
|
|
|
3363
3467
|
}
|
|
3364
3468
|
};
|
|
3365
3469
|
//#endregion
|
|
3470
|
+
//#region src/tui/login/LoginOverlay.ts
|
|
3471
|
+
const bold$8 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
3472
|
+
const secondary$8 = fg(theme.secondary);
|
|
3473
|
+
const muted$9 = fg(theme.muted);
|
|
3474
|
+
const errorColor$4 = fg(theme.error);
|
|
3475
|
+
const invert$4 = (s) => `\x1b[7m${s}\x1b[0m`;
|
|
3476
|
+
var LoginOverlay = class {
|
|
3477
|
+
store;
|
|
3478
|
+
actions;
|
|
3479
|
+
promptField = emptyMiniTextField();
|
|
3480
|
+
promptCursor = 0;
|
|
3481
|
+
constructor(store, actions) {
|
|
3482
|
+
this.store = store;
|
|
3483
|
+
this.actions = actions;
|
|
3484
|
+
}
|
|
3485
|
+
invalidate() {}
|
|
3486
|
+
renderList(login) {
|
|
3487
|
+
const lines = [bold$8(secondary$8("Sign in"))];
|
|
3488
|
+
if (login.error !== void 0) lines.push(errorColor$4(login.error));
|
|
3489
|
+
if (login.busy && login.flows === void 0) lines.push(muted$9("Loading…"));
|
|
3490
|
+
login.flows?.forEach((flow, index) => {
|
|
3491
|
+
const marker = flow.inFlight ? "· " : "○ ";
|
|
3492
|
+
const signingIn = login.signingIn === flow.key ? " — signing in…" : "";
|
|
3493
|
+
const text = `${index === login.selected ? "› " : " "}${marker}${flow.label}${signingIn}`;
|
|
3494
|
+
lines.push(index === login.selected ? invert$4(text) : text);
|
|
3495
|
+
});
|
|
3496
|
+
if (login.flows?.length === 0) lines.push(muted$9("No sign-in providers are available in this profile."));
|
|
3497
|
+
lines.push(muted$9("↑↓ select · enter sign in · esc close"));
|
|
3498
|
+
return lines;
|
|
3499
|
+
}
|
|
3500
|
+
renderPrompt(prompt) {
|
|
3501
|
+
const lines = [bold$8(secondary$8("Sign in"))];
|
|
3502
|
+
lines.push(prompt.message);
|
|
3503
|
+
if (prompt.kind === "select") {
|
|
3504
|
+
prompt.options.forEach((option, index) => {
|
|
3505
|
+
const row = `${index === this.promptCursor ? "› " : " "}${option.label}`;
|
|
3506
|
+
lines.push(index === this.promptCursor ? invert$4(row) : row);
|
|
3507
|
+
if (option.description !== void 0) lines.push(muted$9(` ${option.description}`));
|
|
3508
|
+
});
|
|
3509
|
+
lines.push(muted$9("↑↓ choose · enter select · esc cancel"));
|
|
3510
|
+
} else {
|
|
3511
|
+
const mask = prompt.kind === "secret" ? "•" : void 0;
|
|
3512
|
+
const placeholder = prompt.placeholder ?? (prompt.kind === "secret" ? "API key" : "code");
|
|
3513
|
+
const field = this.promptField.value === "" ? `(${placeholder})` : renderMiniTextField(this.promptField, true, mask);
|
|
3514
|
+
lines.push(`> ${field}`);
|
|
3515
|
+
lines.push(muted$9("type + enter submit · esc cancel"));
|
|
3516
|
+
}
|
|
3517
|
+
return lines;
|
|
3518
|
+
}
|
|
3519
|
+
render(_width) {
|
|
3520
|
+
const overlay = this.store.getSnapshot().overlay;
|
|
3521
|
+
if (overlay.kind !== "login") return [];
|
|
3522
|
+
const { prompt } = overlay.login;
|
|
3523
|
+
return prompt === void 0 ? this.renderList(overlay.login) : this.renderPrompt(prompt);
|
|
3524
|
+
}
|
|
3525
|
+
handleInput(data) {
|
|
3526
|
+
const overlay = this.store.getSnapshot().overlay;
|
|
3527
|
+
if (overlay.kind !== "login") return;
|
|
3528
|
+
const { prompt } = overlay.login;
|
|
3529
|
+
if (prompt !== void 0) this.handlePromptInput(data, prompt);
|
|
3530
|
+
else this.handleListInput(data, overlay.login);
|
|
3531
|
+
}
|
|
3532
|
+
handlePromptInput(data, prompt) {
|
|
3533
|
+
if (matchesKey(data, Key.escape)) {
|
|
3534
|
+
this.actions.answerAuthorizationPrompt("");
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
if (prompt.kind === "select") {
|
|
3538
|
+
if (matchesKey(data, Key.up)) {
|
|
3539
|
+
this.promptCursor = Math.max(0, this.promptCursor - 1);
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
if (matchesKey(data, Key.down)) {
|
|
3543
|
+
this.promptCursor = Math.min(prompt.options.length - 1, this.promptCursor + 1);
|
|
3544
|
+
return;
|
|
3545
|
+
}
|
|
3546
|
+
if (matchesKey(data, Key.enter)) this.actions.answerAuthorizationPrompt(prompt.options[this.promptCursor].id);
|
|
3547
|
+
return;
|
|
3548
|
+
}
|
|
3549
|
+
if (matchesKey(data, Key.enter)) {
|
|
3550
|
+
this.actions.answerAuthorizationPrompt(this.promptField.value.trim());
|
|
3551
|
+
return;
|
|
3552
|
+
}
|
|
3553
|
+
const next = miniTextFieldInput(this.promptField, data);
|
|
3554
|
+
if (next !== void 0) this.promptField = next;
|
|
3555
|
+
}
|
|
3556
|
+
handleListInput(data, login) {
|
|
3557
|
+
if (matchesKey(data, Key.escape)) {
|
|
3558
|
+
this.actions.closeLogin();
|
|
3559
|
+
return;
|
|
3560
|
+
}
|
|
3561
|
+
const flows = login.flows;
|
|
3562
|
+
if (flows === void 0 || flows.length === 0) return;
|
|
3563
|
+
if (matchesKey(data, Key.up)) {
|
|
3564
|
+
this.actions.selectLoginFlow(Math.max(0, login.selected - 1));
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
if (matchesKey(data, Key.down)) {
|
|
3568
|
+
this.actions.selectLoginFlow(Math.min(flows.length - 1, login.selected + 1));
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
if (matchesKey(data, Key.enter)) this.actions.beginAuthorization(flows[login.selected].key);
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
//#endregion
|
|
3366
3575
|
//#region src/tui/trajectory/layout.ts
|
|
3367
3576
|
const LABEL_LIMIT = 100;
|
|
3368
3577
|
function prettyJson(raw) {
|
|
@@ -4602,7 +4811,12 @@ var TuiApp = class {
|
|
|
4602
4811
|
this.options = options;
|
|
4603
4812
|
const { store, actions } = options;
|
|
4604
4813
|
const terminal = new ProcessTerminal();
|
|
4605
|
-
this.tui = new TuiAltScreen(terminal, true, void 0, {
|
|
4814
|
+
this.tui = new TuiAltScreen(terminal, true, void 0, {
|
|
4815
|
+
mouse: true,
|
|
4816
|
+
onRightClickPaste: () => {
|
|
4817
|
+
readClipboard().then((text) => this.tui.getFocusedComponent()?.handleInput?.(`\x1b[200~${text}\x1b[201~`)).catch(() => {});
|
|
4818
|
+
}
|
|
4819
|
+
});
|
|
4606
4820
|
this.spinner = new Spinner(this.tui);
|
|
4607
4821
|
this.pet = new YlyPet(this.tui);
|
|
4608
4822
|
const transcriptScrollView = new ScrollView(this.documentContainer, {
|
|
@@ -4790,6 +5004,7 @@ var TuiApp = class {
|
|
|
4790
5004
|
switch (overlay.kind) {
|
|
4791
5005
|
case "none": return;
|
|
4792
5006
|
case "modelProfile": return new ModelProfileOverlay(store, actions);
|
|
5007
|
+
case "login": return new LoginOverlay(store, actions);
|
|
4793
5008
|
case "trajectory": return new TrajectoryOverlay(this.tui, store, actions, getTool);
|
|
4794
5009
|
case "toolCards": return new ToolCardsOverlay(this.tui, store, actions, getTool, getToolCall);
|
|
4795
5010
|
case "context": return new ContextOverlay(store, actions);
|
|
@@ -4920,170 +5135,6 @@ function logoutSuccessMessage(provider) {
|
|
|
4920
5135
|
function logoutNoneMessage() {
|
|
4921
5136
|
return "No active provider is selected; nothing to log out.";
|
|
4922
5137
|
}
|
|
4923
|
-
/** The DSH credential-key segment grammar: lowercase hyphenated identifier. */
|
|
4924
|
-
const KEY_SEGMENT_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
4925
|
-
/**
|
|
4926
|
-
* Build the `<scope>/<id>` CredentialKey address for one provider's grant
|
|
4927
|
-
* record. Mirrors the DSH `credentialKey` grammar so the record space stays
|
|
4928
|
-
* valid without a runtime dependency on `@deepseek-ai/dsh-credentials`.
|
|
4929
|
-
*/
|
|
4930
|
-
function grantKey(meta) {
|
|
4931
|
-
const scope = meta.ownerScope ?? "acryl-tui";
|
|
4932
|
-
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`);
|
|
4933
|
-
return `${scope}/${meta.route}`;
|
|
4934
|
-
}
|
|
4935
|
-
/** The OAuth-capable providers shipped with ACRYL. Empty until a real provider is wired. */
|
|
4936
|
-
const OAUTH_PROVIDERS = [];
|
|
4937
|
-
/** Resolve metadata for a provider route, or undefined when it is not OAuth-capable. */
|
|
4938
|
-
function oauthProviderFor(route) {
|
|
4939
|
-
return OAUTH_PROVIDERS.find((entry) => entry.route === route);
|
|
4940
|
-
}
|
|
4941
|
-
//#endregion
|
|
4942
|
-
//#region src/tui/oauth/flow.ts
|
|
4943
|
-
/**
|
|
4944
|
-
* OAuth authorization-code flow (L010 + L011): PKCE, a one-shot loopback
|
|
4945
|
-
* redirect listener, the code→token exchange, and grant persistence through
|
|
4946
|
-
* the `credentials` record seam (`modifyRecord`/`readRecord`/`deleteRecord`).
|
|
4947
|
-
*
|
|
4948
|
-
* The flow owns exactly one transient resource — an `http.Server` bound to
|
|
4949
|
-
* `127.0.0.1:0` — which is opened and closed inside `runOAuthLogin`. The PKCE
|
|
4950
|
-
* verifier and `state` are in-memory only and never surface to a transcript.
|
|
4951
|
-
* @module @tomowang/dsh-tui/tui/oauth/flow
|
|
4952
|
-
*/
|
|
4953
|
-
function base64Url(input) {
|
|
4954
|
-
return input.toString("base64url");
|
|
4955
|
-
}
|
|
4956
|
-
function makePkce() {
|
|
4957
|
-
const verifier = base64Url(randomBytes(32));
|
|
4958
|
-
return {
|
|
4959
|
-
verifier,
|
|
4960
|
-
challenge: base64Url(createHash("sha256").update(verifier).digest()),
|
|
4961
|
-
state: base64Url(randomBytes(16))
|
|
4962
|
-
};
|
|
4963
|
-
}
|
|
4964
|
-
function toGrantPayload(tokens) {
|
|
4965
|
-
return {
|
|
4966
|
-
accessToken: tokens.access_token,
|
|
4967
|
-
refreshToken: tokens.refresh_token,
|
|
4968
|
-
tokenType: tokens.token_type,
|
|
4969
|
-
expiresAt: tokens.expires_in !== void 0 ? Date.now() + tokens.expires_in * 1e3 : void 0
|
|
4970
|
-
};
|
|
4971
|
-
}
|
|
4972
|
-
function buildAuthorizeUrl(meta, redirectUri, pkce) {
|
|
4973
|
-
const params = new URLSearchParams({
|
|
4974
|
-
response_type: "code",
|
|
4975
|
-
client_id: meta.clientId,
|
|
4976
|
-
redirect_uri: redirectUri,
|
|
4977
|
-
scope: meta.scopes.join(" "),
|
|
4978
|
-
state: pkce.state
|
|
4979
|
-
});
|
|
4980
|
-
if (meta.pkce) {
|
|
4981
|
-
params.set("code_challenge", pkce.challenge);
|
|
4982
|
-
params.set("code_challenge_method", "S256");
|
|
4983
|
-
}
|
|
4984
|
-
if (meta.audience !== void 0) params.set("audience", meta.audience);
|
|
4985
|
-
return `${meta.authorizeUrl}?${params.toString()}`;
|
|
4986
|
-
}
|
|
4987
|
-
/** Attach the one-shot callback handler and return a promise for the code. */
|
|
4988
|
-
function awaitCallback(server, state, timeoutMs) {
|
|
4989
|
-
return new Promise((resolve, reject) => {
|
|
4990
|
-
const timer = setTimeout(() => {
|
|
4991
|
-
reject(/* @__PURE__ */ new Error("OAuth login timed out waiting for the redirect."));
|
|
4992
|
-
server.close();
|
|
4993
|
-
}, timeoutMs);
|
|
4994
|
-
server.on("request", (request, response) => {
|
|
4995
|
-
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
4996
|
-
if (url.pathname !== "/callback") {
|
|
4997
|
-
response.writeHead(404).end();
|
|
4998
|
-
return;
|
|
4999
|
-
}
|
|
5000
|
-
clearTimeout(timer);
|
|
5001
|
-
response.writeHead(200, { "content-type": "text/plain" }).end("Authorization complete. You can return to ACRYL.");
|
|
5002
|
-
const code = url.searchParams.get("code");
|
|
5003
|
-
const returnedState = url.searchParams.get("state");
|
|
5004
|
-
server.close();
|
|
5005
|
-
if (returnedState !== state) reject(/* @__PURE__ */ new Error("OAuth state mismatch."));
|
|
5006
|
-
else if (code === null) reject(/* @__PURE__ */ new Error("OAuth redirect did not include an authorization code."));
|
|
5007
|
-
else resolve(code);
|
|
5008
|
-
});
|
|
5009
|
-
});
|
|
5010
|
-
}
|
|
5011
|
-
/** Open the authorize URL in the platform's default browser. */
|
|
5012
|
-
function defaultOpenUrl(url) {
|
|
5013
|
-
const platform = process.platform;
|
|
5014
|
-
const command = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", [
|
|
5015
|
-
"/c",
|
|
5016
|
-
"start",
|
|
5017
|
-
"",
|
|
5018
|
-
url
|
|
5019
|
-
]] : ["xdg-open", [url]];
|
|
5020
|
-
return new Promise((resolve) => {
|
|
5021
|
-
execFile(command[0], command[1], () => resolve());
|
|
5022
|
-
});
|
|
5023
|
-
}
|
|
5024
|
-
/** POST the authorization code to the token endpoint and normalize the body. */
|
|
5025
|
-
async function exchangeCode(meta, code, redirectUri, pkce) {
|
|
5026
|
-
const body = new URLSearchParams({
|
|
5027
|
-
grant_type: "authorization_code",
|
|
5028
|
-
code,
|
|
5029
|
-
redirect_uri: redirectUri,
|
|
5030
|
-
client_id: meta.clientId
|
|
5031
|
-
});
|
|
5032
|
-
if (meta.pkce) body.set("code_verifier", pkce.verifier);
|
|
5033
|
-
return postToken(meta, body);
|
|
5034
|
-
}
|
|
5035
|
-
/** POST to the token endpoint; shared by the code and refresh exchanges. */
|
|
5036
|
-
async function postToken(meta, body) {
|
|
5037
|
-
const response = await fetch(meta.tokenUrl, {
|
|
5038
|
-
method: "POST",
|
|
5039
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
5040
|
-
body: body.toString()
|
|
5041
|
-
});
|
|
5042
|
-
if (!response.ok) {
|
|
5043
|
-
const text = await response.text().catch(() => "");
|
|
5044
|
-
throw new Error(`token request failed (${response.status}): ${text}`);
|
|
5045
|
-
}
|
|
5046
|
-
return await response.json();
|
|
5047
|
-
}
|
|
5048
|
-
/** Run the full authorization-code flow and persist the resulting grant. */
|
|
5049
|
-
async function runOAuthLogin(meta, credentials, options = {}) {
|
|
5050
|
-
const server = createServer();
|
|
5051
|
-
try {
|
|
5052
|
-
const pkce = makePkce();
|
|
5053
|
-
await new Promise((resolve, reject) => {
|
|
5054
|
-
server.once("error", reject);
|
|
5055
|
-
server.listen(0, "127.0.0.1", resolve);
|
|
5056
|
-
});
|
|
5057
|
-
const { port } = server.address();
|
|
5058
|
-
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
5059
|
-
const authorizeUrl = buildAuthorizeUrl(meta, redirectUri, pkce);
|
|
5060
|
-
const codePromise = awaitCallback(server, pkce.state, options.timeoutMs ?? 3e5);
|
|
5061
|
-
codePromise.catch(() => {});
|
|
5062
|
-
await (options.openUrl ?? defaultOpenUrl)(authorizeUrl);
|
|
5063
|
-
const tokens = await exchangeCode(meta, await codePromise, redirectUri, pkce);
|
|
5064
|
-
await credentials.modifyRecord(grantKey(meta), async () => ({
|
|
5065
|
-
kind: "grant",
|
|
5066
|
-
payload: toGrantPayload(tokens)
|
|
5067
|
-
}));
|
|
5068
|
-
return { ok: true };
|
|
5069
|
-
} catch (error) {
|
|
5070
|
-
return {
|
|
5071
|
-
ok: false,
|
|
5072
|
-
error: error instanceof Error ? error.message : String(error)
|
|
5073
|
-
};
|
|
5074
|
-
} finally {
|
|
5075
|
-
if (server.listening) server.close();
|
|
5076
|
-
}
|
|
5077
|
-
}
|
|
5078
|
-
/** Read the stored grant for a provider, or undefined when none is stored. */
|
|
5079
|
-
async function readOAuthGrant(meta, credentials) {
|
|
5080
|
-
const record = await credentials.readRecord(grantKey(meta));
|
|
5081
|
-
return record?.kind === "grant" ? record.payload : void 0;
|
|
5082
|
-
}
|
|
5083
|
-
/** Revoke (delete) a provider's stored grant. Removing an absent record is a no-op. */
|
|
5084
|
-
async function revokeOAuthGrant(meta, credentials) {
|
|
5085
|
-
await credentials.deleteRecord(grantKey(meta));
|
|
5086
|
-
}
|
|
5087
5138
|
//#endregion
|
|
5088
5139
|
//#region src/tui-app/session.ts
|
|
5089
5140
|
/**
|
|
@@ -5142,6 +5193,19 @@ function deriveApiKeyRef(route) {
|
|
|
5142
5193
|
const upper = route.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
5143
5194
|
return `${/^[A-Z_]/.test(upper) ? upper : `P_${upper}`}_API_KEY`;
|
|
5144
5195
|
}
|
|
5196
|
+
/** Open a URL in the platform's default browser (fire-and-forget). */
|
|
5197
|
+
function openBrowser(url) {
|
|
5198
|
+
const platform = process.platform;
|
|
5199
|
+
const command = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", [
|
|
5200
|
+
"/c",
|
|
5201
|
+
"start",
|
|
5202
|
+
"",
|
|
5203
|
+
url
|
|
5204
|
+
]] : ["xdg-open", [url]];
|
|
5205
|
+
return new Promise((resolve) => {
|
|
5206
|
+
execFile(command[0], command[1], () => resolve());
|
|
5207
|
+
});
|
|
5208
|
+
}
|
|
5145
5209
|
/** Nest a provider settings section at its path, e.g. `['providers','deepseek']` -> `{ providers: { deepseek: section } }`. */
|
|
5146
5210
|
function nestAtPath(path, section) {
|
|
5147
5211
|
let patch = section;
|
|
@@ -5215,8 +5279,6 @@ async function attachSession(host, resumeId) {
|
|
|
5215
5279
|
const userValue = descriptor === void 0 ? void 0 : getAtPath(descriptor.user, entry.settingsPath);
|
|
5216
5280
|
const apiKeyRef = value?.apiKeyEnv ?? deriveApiKeyRef(entry.provider);
|
|
5217
5281
|
const info = await credentialsSvc.describe(apiKeyRef);
|
|
5218
|
-
const oauth = oauthProviderFor(entry.provider);
|
|
5219
|
-
const grant = oauth === void 0 ? void 0 : await readOAuthGrant(oauth, credentialsSvc);
|
|
5220
5282
|
rows.push({
|
|
5221
5283
|
route: entry.provider,
|
|
5222
5284
|
displayName: value?.displayName ?? entry.displayName,
|
|
@@ -5228,8 +5290,6 @@ async function attachSession(host, resumeId) {
|
|
|
5228
5290
|
baseURL: value?.baseURL,
|
|
5229
5291
|
apiKeyRef,
|
|
5230
5292
|
apiKeyConfigured: info.configured,
|
|
5231
|
-
oauth,
|
|
5232
|
-
grantConfigured: grant !== void 0,
|
|
5233
5293
|
models: value?.models ?? [],
|
|
5234
5294
|
revision: descriptor?.revision
|
|
5235
5295
|
});
|
|
@@ -5241,6 +5301,30 @@ async function attachSession(host, resumeId) {
|
|
|
5241
5301
|
selected: 0
|
|
5242
5302
|
});
|
|
5243
5303
|
}
|
|
5304
|
+
async function loadAuthorizationFlows() {
|
|
5305
|
+
const authSvc = host.ctx.get("authorization");
|
|
5306
|
+
if (authSvc === void 0) {
|
|
5307
|
+
store.updateLogin({
|
|
5308
|
+
flows: [],
|
|
5309
|
+
busy: false,
|
|
5310
|
+
error: "Sign-in is not available in this profile."
|
|
5311
|
+
});
|
|
5312
|
+
return;
|
|
5313
|
+
}
|
|
5314
|
+
try {
|
|
5315
|
+
const list = authSvc.list();
|
|
5316
|
+
store.updateLogin({
|
|
5317
|
+
flows: list,
|
|
5318
|
+
busy: false,
|
|
5319
|
+
error: void 0
|
|
5320
|
+
});
|
|
5321
|
+
} catch (error) {
|
|
5322
|
+
store.updateLogin({
|
|
5323
|
+
busy: false,
|
|
5324
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5325
|
+
});
|
|
5326
|
+
}
|
|
5327
|
+
}
|
|
5244
5328
|
async function loadAgentPresets() {
|
|
5245
5329
|
const presetsSvc = host.ctx.get("agentPresets");
|
|
5246
5330
|
if (presetsSvc === void 0) {
|
|
@@ -5271,6 +5355,7 @@ async function attachSession(host, resumeId) {
|
|
|
5271
5355
|
});
|
|
5272
5356
|
}
|
|
5273
5357
|
}
|
|
5358
|
+
let pendingPromptResolve;
|
|
5274
5359
|
const actions = {
|
|
5275
5360
|
send(text) {
|
|
5276
5361
|
store.setNotice(void 0);
|
|
@@ -5389,29 +5474,84 @@ async function attachSession(host, resumeId) {
|
|
|
5389
5474
|
loadProviders();
|
|
5390
5475
|
},
|
|
5391
5476
|
login() {
|
|
5392
|
-
store.
|
|
5393
|
-
|
|
5477
|
+
store.openLogin();
|
|
5478
|
+
loadAuthorizationFlows();
|
|
5479
|
+
},
|
|
5480
|
+
closeLogin() {
|
|
5481
|
+
store.closeOverlay();
|
|
5394
5482
|
},
|
|
5395
|
-
|
|
5483
|
+
selectLoginFlow(index) {
|
|
5484
|
+
store.updateLogin({ selected: index });
|
|
5485
|
+
},
|
|
5486
|
+
beginAuthorization(key) {
|
|
5396
5487
|
(async () => {
|
|
5397
|
-
const
|
|
5398
|
-
if (
|
|
5399
|
-
store.setNotice("
|
|
5488
|
+
const authSvc = host.ctx.get("authorization");
|
|
5489
|
+
if (authSvc === void 0) {
|
|
5490
|
+
store.setNotice("Sign-in is not available in this profile.");
|
|
5400
5491
|
return;
|
|
5401
5492
|
}
|
|
5402
|
-
const
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5493
|
+
const overlay = store.getSnapshot().overlay;
|
|
5494
|
+
const flow = overlay.kind === "login" ? overlay.login.flows?.find((entry) => entry.key === key) : void 0;
|
|
5495
|
+
if (flow === void 0) return;
|
|
5496
|
+
store.updateLogin({ signingIn: key });
|
|
5497
|
+
const interaction = {
|
|
5498
|
+
notify(notice) {
|
|
5499
|
+
if (notice.url !== void 0) openBrowser(notice.url);
|
|
5500
|
+
const parts = [notice.message];
|
|
5501
|
+
if (notice.url !== void 0) parts.push(notice.url);
|
|
5502
|
+
if (notice.code !== void 0) parts.push(`Code: ${notice.code}`);
|
|
5503
|
+
store.setNotice(parts.join("\n"));
|
|
5504
|
+
},
|
|
5505
|
+
async prompt(prompt) {
|
|
5506
|
+
return await new Promise((resolve, reject) => {
|
|
5507
|
+
if (prompt.signal?.aborted) {
|
|
5508
|
+
reject(/* @__PURE__ */ new Error("authorization prompt withdrawn"));
|
|
5509
|
+
return;
|
|
5510
|
+
}
|
|
5511
|
+
pendingPromptResolve = resolve;
|
|
5512
|
+
const state = prompt.kind === "select" ? {
|
|
5513
|
+
kind: "select",
|
|
5514
|
+
message: prompt.message,
|
|
5515
|
+
options: (prompt.options ?? []).map((option) => ({
|
|
5516
|
+
id: option.id,
|
|
5517
|
+
label: option.label,
|
|
5518
|
+
description: option.description
|
|
5519
|
+
}))
|
|
5520
|
+
} : {
|
|
5521
|
+
kind: prompt.kind,
|
|
5522
|
+
message: prompt.message,
|
|
5523
|
+
placeholder: prompt.placeholder
|
|
5524
|
+
};
|
|
5525
|
+
store.updateLogin({ prompt: state });
|
|
5526
|
+
prompt.signal?.addEventListener("abort", () => {
|
|
5527
|
+
if (pendingPromptResolve === resolve) pendingPromptResolve = void 0;
|
|
5528
|
+
store.updateLogin({ prompt: void 0 });
|
|
5529
|
+
reject(/* @__PURE__ */ new Error("authorization prompt withdrawn"));
|
|
5530
|
+
}, { once: true });
|
|
5531
|
+
});
|
|
5532
|
+
}
|
|
5533
|
+
};
|
|
5534
|
+
try {
|
|
5535
|
+
if ((await authSvc.begin({
|
|
5536
|
+
key,
|
|
5537
|
+
interaction
|
|
5538
|
+
})).status === "authorized") {
|
|
5539
|
+
store.setNotice(`Signed in to ${flow.label}.`);
|
|
5540
|
+
loadAuthorizationFlows();
|
|
5541
|
+
} else store.setNotice("Sign-in cancelled.");
|
|
5542
|
+
} catch (error) {
|
|
5543
|
+
store.setNotice(`Sign-in failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5544
|
+
} finally {
|
|
5545
|
+
store.updateLogin({ signingIn: void 0 });
|
|
5406
5546
|
}
|
|
5407
|
-
store.setNotice(`Opening ${meta.route} OAuth login…`);
|
|
5408
|
-
const result = await runOAuthLogin(meta, credentialsSvc);
|
|
5409
|
-
if (result.ok) {
|
|
5410
|
-
store.setNotice(`OAuth login complete for ${meta.route}.`);
|
|
5411
|
-
loadProviders();
|
|
5412
|
-
} else store.setNotice(`OAuth login failed: ${result.error}`);
|
|
5413
5547
|
})();
|
|
5414
5548
|
},
|
|
5549
|
+
answerAuthorizationPrompt(value) {
|
|
5550
|
+
const resolve = pendingPromptResolve;
|
|
5551
|
+
pendingPromptResolve = void 0;
|
|
5552
|
+
store.updateLogin({ prompt: void 0 });
|
|
5553
|
+
if (resolve !== void 0) resolve(value);
|
|
5554
|
+
},
|
|
5415
5555
|
logout() {
|
|
5416
5556
|
(async () => {
|
|
5417
5557
|
const credentialsSvc = host.ctx.get("credentials");
|
|
@@ -5428,8 +5568,6 @@ async function attachSession(host, resumeId) {
|
|
|
5428
5568
|
return;
|
|
5429
5569
|
}
|
|
5430
5570
|
try {
|
|
5431
|
-
const oauth = oauthProviderFor(row.route);
|
|
5432
|
-
if (oauth !== void 0) await revokeOAuthGrant(oauth, credentialsSvc);
|
|
5433
5571
|
await credentialsSvc.unset(row.apiKeyRef);
|
|
5434
5572
|
store.setNotice(logoutSuccessMessage(row.displayName));
|
|
5435
5573
|
loadProviders();
|