acryl 0.1.16 → 0.1.18
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 +416 -253
- package/lib/bin.js.map +1 -1
- package/lib/index.js +411 -252
- package/lib/index.js.map +1 -1
- package/package.json +12 -525
package/lib/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
3
|
-
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
4
|
-
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
5
3
|
import { existsSync, writeFileSync } from "node:fs";
|
|
6
4
|
import { dirname, join, relative, resolve } from "node:path";
|
|
7
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
7
|
+
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
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
|
|
@@ -91,6 +90,55 @@ function parseAcrylArgs(args) {
|
|
|
91
90
|
process.stdout, process.stderr;
|
|
92
91
|
//#endregion
|
|
93
92
|
//#region ../acryl-harness-runtime/lib/index.mjs
|
|
93
|
+
const shippedPresetsDir = join(resolve(dirname(fileURLToPath(import.meta.url)), "../.."), "deepseek-harness", "packages", "preset", "agent-presets", "presets");
|
|
94
|
+
const authorizationCapabilityPatches = [{
|
|
95
|
+
id: "system-prompt",
|
|
96
|
+
name: "@deepseek-ai/dsh-system-prompt",
|
|
97
|
+
config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
|
|
98
|
+
}, { insert: [
|
|
99
|
+
{
|
|
100
|
+
id: "agent-presets",
|
|
101
|
+
name: "@deepseek-ai/dsh-agent-presets",
|
|
102
|
+
config: {
|
|
103
|
+
default: "standard",
|
|
104
|
+
roots: existsSync(shippedPresetsDir) ? [{
|
|
105
|
+
path: shippedPresetsDir,
|
|
106
|
+
trust: "system"
|
|
107
|
+
}] : [],
|
|
108
|
+
includeShippedRoot: false,
|
|
109
|
+
includeUserRoot: true
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: "session-stats",
|
|
114
|
+
name: "@deepseek-ai/dsh-session-stats"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "authorization",
|
|
118
|
+
name: "@deepseek-ai/dsh-authorization"
|
|
119
|
+
}
|
|
120
|
+
] }];
|
|
121
|
+
const NON_TUI_SHARED_ROW_IDS = /* @__PURE__ */ new Set(["authorization"]);
|
|
122
|
+
function selectNonTuiCapabilityPatches(patches) {
|
|
123
|
+
return patches.flatMap((patch) => {
|
|
124
|
+
if (!("insert" in patch) || !Array.isArray(patch.insert)) return [];
|
|
125
|
+
const insert = patch.insert.filter((row) => NON_TUI_SHARED_ROW_IDS.has(row.id));
|
|
126
|
+
return insert.length === 0 ? [] : [{ insert }];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const ACRYL_CODING_CAPABILITIES = [{
|
|
130
|
+
id: "authorization",
|
|
131
|
+
surfaces: [
|
|
132
|
+
"tui",
|
|
133
|
+
"web",
|
|
134
|
+
"desktop"
|
|
135
|
+
],
|
|
136
|
+
loaderPatches: authorizationCapabilityPatches
|
|
137
|
+
}];
|
|
138
|
+
function createAcrylCodingCapabilityPatches(surfaces) {
|
|
139
|
+
const includeSharedCodingRows = surfaces.has("tui");
|
|
140
|
+
return structuredClone(ACRYL_CODING_CAPABILITIES.filter((capability) => capability.surfaces.some((surface) => surfaces.has(surface))).flatMap((capability) => includeSharedCodingRows ? capability.loaderPatches : selectNonTuiCapabilityPatches(capability.loaderPatches)));
|
|
141
|
+
}
|
|
94
142
|
function contentText(content) {
|
|
95
143
|
return content.filter((block) => {
|
|
96
144
|
return block.type === "text" && typeof block.text === "string";
|
|
@@ -292,27 +340,6 @@ function createAcrylSessionBridge(ctx, options) {
|
|
|
292
340
|
}
|
|
293
341
|
const dshInstallAnchor = createRequire(import.meta.url).resolve("@deepseek-ai/dsh/package.json");
|
|
294
342
|
const profileRoot = "[]\n";
|
|
295
|
-
const shippedPresetsDir = join(resolve(dirname(fileURLToPath(import.meta.url)), "../.."), "deepseek-harness", "packages", "preset", "agent-presets", "presets");
|
|
296
|
-
const ACRYL_RUNTIME_ROWS = [{
|
|
297
|
-
id: "system-prompt",
|
|
298
|
-
name: "@deepseek-ai/dsh-system-prompt",
|
|
299
|
-
config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
|
|
300
|
-
}, { insert: [{
|
|
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
|
-
id: "session-stats",
|
|
314
|
-
name: "@deepseek-ai/dsh-session-stats"
|
|
315
|
-
}] }];
|
|
316
343
|
/** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
|
|
317
344
|
async function bootAcrylHarnessProfile(options) {
|
|
318
345
|
if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
|
|
@@ -323,7 +350,7 @@ async function bootAcrylHarnessProfile(options) {
|
|
|
323
350
|
writeFileSync(rootConfig, profileRoot);
|
|
324
351
|
const patches = structuredClone([
|
|
325
352
|
...profile.layers.flatMap((layer) => layer.patches),
|
|
326
|
-
...
|
|
353
|
+
...createAcrylCodingCapabilityPatches(/* @__PURE__ */ new Set(["tui"])),
|
|
327
354
|
...profile.patches
|
|
328
355
|
]);
|
|
329
356
|
if (composeEntries([patches]).find((entry) => entry.id === "hmr")?.disabled !== true && !process.execArgv.includes("--expose-internals")) throw new Error("ACRYL profile enables Cordis HMR and must be launched with Node --expose-internals");
|
|
@@ -421,7 +448,7 @@ const ESC = "\x1B[";
|
|
|
421
448
|
const dim$2 = fg(theme.muted);
|
|
422
449
|
const cyan$1 = fg(theme.secondary);
|
|
423
450
|
const primary = fg(theme.primary);
|
|
424
|
-
const bold$
|
|
451
|
+
const bold$11 = (s) => `${ESC}1m${s}${ESC}0m`;
|
|
425
452
|
const italic = (s) => `${ESC}3m${s}${ESC}0m`;
|
|
426
453
|
const strike = (s) => `${ESC}9m${s}${ESC}0m`;
|
|
427
454
|
const underline = (s) => `${ESC}4m${s}${ESC}0m`;
|
|
@@ -465,7 +492,7 @@ function looksLikeMarkdown(text) {
|
|
|
465
492
|
/** Style links, bold, strikethrough, and emphasis in a span already known to contain no inline code. */
|
|
466
493
|
function applyNonCodeInline(text) {
|
|
467
494
|
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$
|
|
495
|
+
working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$11(a ?? b ?? ""));
|
|
469
496
|
working = working.replaceAll(STRIKE_RE_G, (_match, t) => strike(t));
|
|
470
497
|
return working.replaceAll(ITALIC_RE_G, (_match, a, b) => italic(a ?? b ?? ""));
|
|
471
498
|
}
|
|
@@ -531,7 +558,7 @@ function padCell(styled, width, align) {
|
|
|
531
558
|
}
|
|
532
559
|
/** Pad one row of already-styled cells (header or body) to a single column-aligned line. */
|
|
533
560
|
function formatTableRow(styledCells, widths, aligns, isHeader) {
|
|
534
|
-
return widths.map((width, i) => padCell(isHeader ? bold$
|
|
561
|
+
return widths.map((width, i) => padCell(isHeader ? bold$11(styledCells[i] ?? "") : styledCells[i] ?? "", width, aligns[i] ?? "left")).join(dim$2(" │ "));
|
|
535
562
|
}
|
|
536
563
|
/** A dim horizontal rule under the header row, with a cross at each column boundary. */
|
|
537
564
|
function formatTableRule(widths) {
|
|
@@ -588,7 +615,7 @@ function renderMarkdown(text) {
|
|
|
588
615
|
if (header !== null) {
|
|
589
616
|
const level = header[1].length;
|
|
590
617
|
const content = applyInline(header[2]);
|
|
591
|
-
out.push(level === 1 ? bold$
|
|
618
|
+
out.push(level === 1 ? bold$11(primary(content)) : level === 2 ? bold$11(cyan$1(content)) : bold$11(content));
|
|
592
619
|
continue;
|
|
593
620
|
}
|
|
594
621
|
if (HR_RE.test(line)) {
|
|
@@ -1213,6 +1240,31 @@ var TuiStore = class {
|
|
|
1213
1240
|
}
|
|
1214
1241
|
} });
|
|
1215
1242
|
}
|
|
1243
|
+
/** Open the `/login` sign-in overlay to a fresh, loading flow list. */
|
|
1244
|
+
openLogin() {
|
|
1245
|
+
this.set({ overlay: {
|
|
1246
|
+
kind: "login",
|
|
1247
|
+
login: {
|
|
1248
|
+
flows: void 0,
|
|
1249
|
+
selected: 0,
|
|
1250
|
+
signingIn: void 0,
|
|
1251
|
+
prompt: void 0,
|
|
1252
|
+
busy: true,
|
|
1253
|
+
error: void 0
|
|
1254
|
+
}
|
|
1255
|
+
} });
|
|
1256
|
+
}
|
|
1257
|
+
/** Patch the open `/login` overlay's sub-state; a no-op once it's closed. */
|
|
1258
|
+
updateLogin(patch) {
|
|
1259
|
+
if (this.state.overlay.kind !== "login") return;
|
|
1260
|
+
this.set({ overlay: {
|
|
1261
|
+
kind: "login",
|
|
1262
|
+
login: {
|
|
1263
|
+
...this.state.overlay.login,
|
|
1264
|
+
...patch
|
|
1265
|
+
}
|
|
1266
|
+
} });
|
|
1267
|
+
}
|
|
1216
1268
|
/** Open the `/trajectory` ledger overlay. */
|
|
1217
1269
|
openTrajectory() {
|
|
1218
1270
|
this.set({ overlay: { kind: "trajectory" } });
|
|
@@ -1764,10 +1816,10 @@ function runSlashCommand(command, actions) {
|
|
|
1764
1816
|
}
|
|
1765
1817
|
//#endregion
|
|
1766
1818
|
//#region src/tui/piTheme.ts
|
|
1767
|
-
const bold$
|
|
1819
|
+
const bold$10 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
1768
1820
|
const selectListTheme = {
|
|
1769
1821
|
selectedPrefix: fg(theme.primary),
|
|
1770
|
-
selectedText: (s) => bold$
|
|
1822
|
+
selectedText: (s) => bold$10(fg(theme.primary)(s)),
|
|
1771
1823
|
description: fg(theme.muted),
|
|
1772
1824
|
scrollInfo: fg(theme.muted),
|
|
1773
1825
|
noMatch: fg(theme.muted)
|
|
@@ -2092,6 +2144,68 @@ var Spinner = class {
|
|
|
2092
2144
|
}
|
|
2093
2145
|
};
|
|
2094
2146
|
//#endregion
|
|
2147
|
+
//#region src/tui/clipboard.ts
|
|
2148
|
+
/**
|
|
2149
|
+
* System-clipboard read, used for right-click paste. Node has no built-in
|
|
2150
|
+
* clipboard API, so this shells out to the platform's clipboard tool via
|
|
2151
|
+
* `execFile` (the same `node:child_process` approach used elsewhere for
|
|
2152
|
+
* platform launchers like `open`/`xdg-open`).
|
|
2153
|
+
* @module @tomowang/dsh-tui/tui/clipboard
|
|
2154
|
+
*/
|
|
2155
|
+
function clipboardCommands() {
|
|
2156
|
+
switch (process.platform) {
|
|
2157
|
+
case "darwin": return [["pbpaste", []]];
|
|
2158
|
+
case "win32": return [["powershell.exe", [
|
|
2159
|
+
"-NoProfile",
|
|
2160
|
+
"-NonInteractive",
|
|
2161
|
+
"-Command",
|
|
2162
|
+
"Get-Clipboard"
|
|
2163
|
+
]]];
|
|
2164
|
+
default: return [
|
|
2165
|
+
["xclip", [
|
|
2166
|
+
"-selection",
|
|
2167
|
+
"clipboard",
|
|
2168
|
+
"-o"
|
|
2169
|
+
]],
|
|
2170
|
+
["xsel", ["--clipboard", "--output"]],
|
|
2171
|
+
["wl-paste", ["--no-newline"]]
|
|
2172
|
+
];
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* Read the system clipboard. Resolves with the clipboard text (possibly empty).
|
|
2177
|
+
* Rejects when no supported clipboard tool is available on this host.
|
|
2178
|
+
*
|
|
2179
|
+
* A single trailing newline is stripped: `pbpaste` prints the clipboard verbatim,
|
|
2180
|
+
* while `xclip`/`xsel`/`Get-Clipboard` append one, so this keeps the result
|
|
2181
|
+
* consistent with a native terminal paste (which inserts exactly what was copied).
|
|
2182
|
+
*/
|
|
2183
|
+
function readClipboard() {
|
|
2184
|
+
return new Promise((resolve, reject) => {
|
|
2185
|
+
const commands = clipboardCommands();
|
|
2186
|
+
let index = 0;
|
|
2187
|
+
const attempt = () => {
|
|
2188
|
+
if (index >= commands.length) {
|
|
2189
|
+
reject(/* @__PURE__ */ new Error("no clipboard tool available"));
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
const [command, args] = commands[index];
|
|
2193
|
+
index += 1;
|
|
2194
|
+
execFile(command, args, {
|
|
2195
|
+
encoding: "utf8",
|
|
2196
|
+
maxBuffer: 10 * 1024 * 1024
|
|
2197
|
+
}, (error, stdout) => {
|
|
2198
|
+
if (error) {
|
|
2199
|
+
attempt();
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
resolve(stdout.replace(/\r?\n$/, ""));
|
|
2203
|
+
});
|
|
2204
|
+
};
|
|
2205
|
+
attempt();
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
//#endregion
|
|
2095
2209
|
//#region src/yly/yly-frames.generated.ts
|
|
2096
2210
|
const YLY_FRAMES = {
|
|
2097
2211
|
"small": [
|
|
@@ -3011,6 +3125,15 @@ var YlyPet = class {
|
|
|
3011
3125
|
* delegate keystrokes to a field nested inside a larger custom overlay.
|
|
3012
3126
|
* @module @tomowang/dsh-tui/tui/miniTextField
|
|
3013
3127
|
*/
|
|
3128
|
+
const BRACKETED_PASTE_START = "\x1B[200~";
|
|
3129
|
+
const BRACKETED_PASTE_END = "\x1B[201~";
|
|
3130
|
+
/** Extract the content of one bracketed-paste sequence, or `undefined` if `data` is not one. */
|
|
3131
|
+
function extractBracketedPaste(data) {
|
|
3132
|
+
if (!data.startsWith(BRACKETED_PASTE_START)) return void 0;
|
|
3133
|
+
const end = data.indexOf(BRACKETED_PASTE_END);
|
|
3134
|
+
if (end === -1) return void 0;
|
|
3135
|
+
return data.slice(6, end);
|
|
3136
|
+
}
|
|
3014
3137
|
function emptyMiniTextField(value = "") {
|
|
3015
3138
|
return {
|
|
3016
3139
|
value,
|
|
@@ -3049,6 +3172,15 @@ function miniTextFieldInput(state, data) {
|
|
|
3049
3172
|
cursor: state.cursor
|
|
3050
3173
|
};
|
|
3051
3174
|
}
|
|
3175
|
+
const paste = extractBracketedPaste(data);
|
|
3176
|
+
if (paste !== void 0) {
|
|
3177
|
+
const text = paste.replace(/[\r\n]+/g, "");
|
|
3178
|
+
if (text.length === 0) return state;
|
|
3179
|
+
return {
|
|
3180
|
+
value: state.value.slice(0, state.cursor) + text + state.value.slice(state.cursor),
|
|
3181
|
+
cursor: state.cursor + text.length
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3052
3184
|
if (data.length > 0 && !data.startsWith("\x1B") && data !== "\r" && data !== "\n" && data !== " ") return {
|
|
3053
3185
|
value: state.value.slice(0, state.cursor) + data + state.value.slice(state.cursor),
|
|
3054
3186
|
cursor: state.cursor + data.length
|
|
@@ -3062,11 +3194,11 @@ function renderMiniTextField(state, cursorVisible, mask) {
|
|
|
3062
3194
|
}
|
|
3063
3195
|
//#endregion
|
|
3064
3196
|
//#region src/tui/modelProfile/ModelProfileOverlay.ts
|
|
3065
|
-
const bold$
|
|
3066
|
-
const secondary$
|
|
3067
|
-
const muted$
|
|
3068
|
-
const errorColor$
|
|
3069
|
-
const invert$
|
|
3197
|
+
const bold$9 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
3198
|
+
const secondary$9 = fg(theme.secondary);
|
|
3199
|
+
const muted$10 = fg(theme.muted);
|
|
3200
|
+
const errorColor$5 = fg(theme.error);
|
|
3201
|
+
const invert$5 = (s) => `\x1b[7m${s}\x1b[0m`;
|
|
3070
3202
|
var ModelProfileOverlay = class {
|
|
3071
3203
|
store;
|
|
3072
3204
|
actions;
|
|
@@ -3143,21 +3275,19 @@ var ModelProfileOverlay = class {
|
|
|
3143
3275
|
}
|
|
3144
3276
|
renderList(mp) {
|
|
3145
3277
|
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$
|
|
3278
|
+
const lines = [bold$9(secondary$9("Model providers"))];
|
|
3279
|
+
if (error !== void 0) lines.push(errorColor$5(error));
|
|
3280
|
+
if (busy && providers === void 0) lines.push(muted$10("Loading…"));
|
|
3149
3281
|
providers?.forEach((row, index) => {
|
|
3150
3282
|
const marker = row.configured ? "● " : "○ ";
|
|
3151
3283
|
const active = row.live ? " (active)" : "";
|
|
3152
3284
|
const noKey = row.apiKeyConfigured ? "" : " [no api key]";
|
|
3153
|
-
const oauthStatus = row.oauth === void 0 ? "" : row.grantConfigured ? " [oauth ✓]" : " [oauth]";
|
|
3154
3285
|
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$
|
|
3286
|
+
const text = `${index === selected ? "› " : " "}${marker}${row.displayName}${active}${noKey}${confirm}`;
|
|
3287
|
+
lines.push(index === selected ? invert$5(text) : text);
|
|
3157
3288
|
});
|
|
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`));
|
|
3289
|
+
if (providers?.length === 0) lines.push(muted$10("No providers configured yet — press a to add one."));
|
|
3290
|
+
lines.push(muted$10("↑↓ select · enter edit · a add · d delete · s set active model · esc close"));
|
|
3161
3291
|
return lines;
|
|
3162
3292
|
}
|
|
3163
3293
|
handleListInput(data, mp) {
|
|
@@ -3194,11 +3324,6 @@ var ModelProfileOverlay = class {
|
|
|
3194
3324
|
if (model !== void 0) this.actions.setActiveModel(row.route, model.id);
|
|
3195
3325
|
return;
|
|
3196
3326
|
}
|
|
3197
|
-
if (data === "o") {
|
|
3198
|
-
const row = providers[selected];
|
|
3199
|
-
if (row.oauth !== void 0) this.actions.loginWithOAuth(row.route);
|
|
3200
|
-
return;
|
|
3201
|
-
}
|
|
3202
3327
|
if (data === "d") {
|
|
3203
3328
|
if (this.confirmDelete === selected) {
|
|
3204
3329
|
this.confirmDelete = void 0;
|
|
@@ -3226,8 +3351,8 @@ var ModelProfileOverlay = class {
|
|
|
3226
3351
|
baseURL: "Base URL",
|
|
3227
3352
|
apiKey: draft.apiKeyConfigured ? "API key (set — leave blank to keep)" : "API key"
|
|
3228
3353
|
};
|
|
3229
|
-
const lines = [bold$
|
|
3230
|
-
if (mp.error !== void 0) lines.push(errorColor$
|
|
3354
|
+
const lines = [bold$9(secondary$9(draft.isNew ? "Add provider" : `Edit ${draft.displayName || draft.route}`))];
|
|
3355
|
+
if (mp.error !== void 0) lines.push(errorColor$5(mp.error));
|
|
3231
3356
|
textFields.forEach((field, index) => {
|
|
3232
3357
|
const isFocused = this.focused === index;
|
|
3233
3358
|
const mask = field === "apiKey" ? "*" : void 0;
|
|
@@ -3235,10 +3360,10 @@ var ModelProfileOverlay = class {
|
|
|
3235
3360
|
lines.push(`${prefix}${renderMiniTextField(fieldState[field], isFocused, mask)}`);
|
|
3236
3361
|
});
|
|
3237
3362
|
const modelsText = `${this.focused === modelsRow ? "› " : " "}Models (${this.models.length}) — enter to edit`;
|
|
3238
|
-
lines.push(this.focused === modelsRow ? invert$
|
|
3363
|
+
lines.push(this.focused === modelsRow ? invert$5(modelsText) : modelsText);
|
|
3239
3364
|
const saveText = `${this.focused === saveRow ? "› " : " "}${mp.busy ? "Saving…" : "Save"}`;
|
|
3240
|
-
lines.push(this.focused === saveRow ? invert$
|
|
3241
|
-
lines.push(muted$
|
|
3365
|
+
lines.push(this.focused === saveRow ? invert$5(saveText) : saveText);
|
|
3366
|
+
lines.push(muted$10("tab/shift+tab move · enter confirm field / activate row · esc cancel"));
|
|
3242
3367
|
return lines;
|
|
3243
3368
|
}
|
|
3244
3369
|
handleFormInput(data, draft) {
|
|
@@ -3288,21 +3413,21 @@ var ModelProfileOverlay = class {
|
|
|
3288
3413
|
}
|
|
3289
3414
|
}
|
|
3290
3415
|
renderModelListEditor(mp) {
|
|
3291
|
-
const lines = [bold$
|
|
3416
|
+
const lines = [bold$9(secondary$9("Models"))];
|
|
3292
3417
|
this.models.forEach((model, index) => {
|
|
3293
3418
|
const isSelected = !this.modelInputFocused && index === this.modelSelected;
|
|
3294
3419
|
const text = `${isSelected ? "› " : " "}${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`;
|
|
3295
|
-
lines.push(isSelected ? invert$
|
|
3420
|
+
lines.push(isSelected ? invert$5(text) : text);
|
|
3296
3421
|
});
|
|
3297
|
-
if (this.models.length === 0) lines.push(muted$
|
|
3422
|
+
if (this.models.length === 0) lines.push(muted$10("No models yet."));
|
|
3298
3423
|
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$
|
|
3424
|
+
if (mp.busy) lines.push(muted$10("Discovering…"));
|
|
3425
|
+
if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$10("No models discovered."));
|
|
3301
3426
|
else {
|
|
3302
|
-
lines.push(muted$
|
|
3303
|
-
for (const model of mp.discovered) lines.push(muted$
|
|
3427
|
+
lines.push(muted$10("Discovered — tab to the id field and type one to adopt it:"));
|
|
3428
|
+
for (const model of mp.discovered) lines.push(muted$10(` ${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`));
|
|
3304
3429
|
}
|
|
3305
|
-
lines.push(muted$
|
|
3430
|
+
lines.push(muted$10("tab toggle list/input · ↑↓ select · x remove · g discover · esc back"));
|
|
3306
3431
|
return lines;
|
|
3307
3432
|
}
|
|
3308
3433
|
addModel(id) {
|
|
@@ -3363,6 +3488,111 @@ var ModelProfileOverlay = class {
|
|
|
3363
3488
|
}
|
|
3364
3489
|
};
|
|
3365
3490
|
//#endregion
|
|
3491
|
+
//#region src/tui/login/LoginOverlay.ts
|
|
3492
|
+
const bold$8 = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
3493
|
+
const secondary$8 = fg(theme.secondary);
|
|
3494
|
+
const muted$9 = fg(theme.muted);
|
|
3495
|
+
const errorColor$4 = fg(theme.error);
|
|
3496
|
+
const invert$4 = (s) => `\x1b[7m${s}\x1b[0m`;
|
|
3497
|
+
var LoginOverlay = class {
|
|
3498
|
+
store;
|
|
3499
|
+
actions;
|
|
3500
|
+
promptField = emptyMiniTextField();
|
|
3501
|
+
promptCursor = 0;
|
|
3502
|
+
constructor(store, actions) {
|
|
3503
|
+
this.store = store;
|
|
3504
|
+
this.actions = actions;
|
|
3505
|
+
}
|
|
3506
|
+
invalidate() {}
|
|
3507
|
+
renderList(login) {
|
|
3508
|
+
const lines = [bold$8(secondary$8("Sign in"))];
|
|
3509
|
+
if (login.error !== void 0) lines.push(errorColor$4(login.error));
|
|
3510
|
+
if (login.busy && login.flows === void 0) lines.push(muted$9("Loading…"));
|
|
3511
|
+
login.flows?.forEach((flow, index) => {
|
|
3512
|
+
const marker = flow.inFlight ? "· " : "○ ";
|
|
3513
|
+
const signingIn = login.signingIn === flow.key ? " — signing in…" : "";
|
|
3514
|
+
const text = `${index === login.selected ? "› " : " "}${marker}${flow.label}${signingIn}`;
|
|
3515
|
+
lines.push(index === login.selected ? invert$4(text) : text);
|
|
3516
|
+
});
|
|
3517
|
+
if (login.flows?.length === 0) lines.push(muted$9("No sign-in providers are available in this profile."));
|
|
3518
|
+
lines.push(muted$9("↑↓ select · enter sign in · esc close"));
|
|
3519
|
+
return lines;
|
|
3520
|
+
}
|
|
3521
|
+
renderPrompt(prompt) {
|
|
3522
|
+
const lines = [bold$8(secondary$8("Sign in"))];
|
|
3523
|
+
lines.push(prompt.message);
|
|
3524
|
+
if (prompt.kind === "select") {
|
|
3525
|
+
prompt.options.forEach((option, index) => {
|
|
3526
|
+
const row = `${index === this.promptCursor ? "› " : " "}${option.label}`;
|
|
3527
|
+
lines.push(index === this.promptCursor ? invert$4(row) : row);
|
|
3528
|
+
if (option.description !== void 0) lines.push(muted$9(` ${option.description}`));
|
|
3529
|
+
});
|
|
3530
|
+
lines.push(muted$9("↑↓ choose · enter select · esc cancel"));
|
|
3531
|
+
} else {
|
|
3532
|
+
const mask = prompt.kind === "secret" ? "•" : void 0;
|
|
3533
|
+
const placeholder = prompt.placeholder ?? (prompt.kind === "secret" ? "API key" : "code");
|
|
3534
|
+
const field = this.promptField.value === "" ? `(${placeholder})` : renderMiniTextField(this.promptField, true, mask);
|
|
3535
|
+
lines.push(`> ${field}`);
|
|
3536
|
+
lines.push(muted$9("type + enter submit · esc cancel"));
|
|
3537
|
+
}
|
|
3538
|
+
return lines;
|
|
3539
|
+
}
|
|
3540
|
+
render(_width) {
|
|
3541
|
+
const overlay = this.store.getSnapshot().overlay;
|
|
3542
|
+
if (overlay.kind !== "login") return [];
|
|
3543
|
+
const { prompt } = overlay.login;
|
|
3544
|
+
return prompt === void 0 ? this.renderList(overlay.login) : this.renderPrompt(prompt);
|
|
3545
|
+
}
|
|
3546
|
+
handleInput(data) {
|
|
3547
|
+
const overlay = this.store.getSnapshot().overlay;
|
|
3548
|
+
if (overlay.kind !== "login") return;
|
|
3549
|
+
const { prompt } = overlay.login;
|
|
3550
|
+
if (prompt !== void 0) this.handlePromptInput(data, prompt);
|
|
3551
|
+
else this.handleListInput(data, overlay.login);
|
|
3552
|
+
}
|
|
3553
|
+
handlePromptInput(data, prompt) {
|
|
3554
|
+
if (matchesKey(data, Key.escape)) {
|
|
3555
|
+
this.actions.answerAuthorizationPrompt("");
|
|
3556
|
+
return;
|
|
3557
|
+
}
|
|
3558
|
+
if (prompt.kind === "select") {
|
|
3559
|
+
if (matchesKey(data, Key.up)) {
|
|
3560
|
+
this.promptCursor = Math.max(0, this.promptCursor - 1);
|
|
3561
|
+
return;
|
|
3562
|
+
}
|
|
3563
|
+
if (matchesKey(data, Key.down)) {
|
|
3564
|
+
this.promptCursor = Math.min(prompt.options.length - 1, this.promptCursor + 1);
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
if (matchesKey(data, Key.enter)) this.actions.answerAuthorizationPrompt(prompt.options[this.promptCursor].id);
|
|
3568
|
+
return;
|
|
3569
|
+
}
|
|
3570
|
+
if (matchesKey(data, Key.enter)) {
|
|
3571
|
+
this.actions.answerAuthorizationPrompt(this.promptField.value.trim());
|
|
3572
|
+
return;
|
|
3573
|
+
}
|
|
3574
|
+
const next = miniTextFieldInput(this.promptField, data);
|
|
3575
|
+
if (next !== void 0) this.promptField = next;
|
|
3576
|
+
}
|
|
3577
|
+
handleListInput(data, login) {
|
|
3578
|
+
if (matchesKey(data, Key.escape)) {
|
|
3579
|
+
this.actions.closeLogin();
|
|
3580
|
+
return;
|
|
3581
|
+
}
|
|
3582
|
+
const flows = login.flows;
|
|
3583
|
+
if (flows === void 0 || flows.length === 0) return;
|
|
3584
|
+
if (matchesKey(data, Key.up)) {
|
|
3585
|
+
this.actions.selectLoginFlow(Math.max(0, login.selected - 1));
|
|
3586
|
+
return;
|
|
3587
|
+
}
|
|
3588
|
+
if (matchesKey(data, Key.down)) {
|
|
3589
|
+
this.actions.selectLoginFlow(Math.min(flows.length - 1, login.selected + 1));
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3592
|
+
if (matchesKey(data, Key.enter)) this.actions.beginAuthorization(flows[login.selected].key);
|
|
3593
|
+
}
|
|
3594
|
+
};
|
|
3595
|
+
//#endregion
|
|
3366
3596
|
//#region src/tui/trajectory/layout.ts
|
|
3367
3597
|
const LABEL_LIMIT = 100;
|
|
3368
3598
|
function prettyJson(raw) {
|
|
@@ -4602,7 +4832,12 @@ var TuiApp = class {
|
|
|
4602
4832
|
this.options = options;
|
|
4603
4833
|
const { store, actions } = options;
|
|
4604
4834
|
const terminal = new ProcessTerminal();
|
|
4605
|
-
this.tui = new TuiAltScreen(terminal, true, void 0, {
|
|
4835
|
+
this.tui = new TuiAltScreen(terminal, true, void 0, {
|
|
4836
|
+
mouse: true,
|
|
4837
|
+
onRightClickPaste: () => {
|
|
4838
|
+
readClipboard().then((text) => this.tui.getFocusedComponent()?.handleInput?.(`\x1b[200~${text}\x1b[201~`)).catch(() => {});
|
|
4839
|
+
}
|
|
4840
|
+
});
|
|
4606
4841
|
this.spinner = new Spinner(this.tui);
|
|
4607
4842
|
this.pet = new YlyPet(this.tui);
|
|
4608
4843
|
const transcriptScrollView = new ScrollView(this.documentContainer, {
|
|
@@ -4790,6 +5025,7 @@ var TuiApp = class {
|
|
|
4790
5025
|
switch (overlay.kind) {
|
|
4791
5026
|
case "none": return;
|
|
4792
5027
|
case "modelProfile": return new ModelProfileOverlay(store, actions);
|
|
5028
|
+
case "login": return new LoginOverlay(store, actions);
|
|
4793
5029
|
case "trajectory": return new TrajectoryOverlay(this.tui, store, actions, getTool);
|
|
4794
5030
|
case "toolCards": return new ToolCardsOverlay(this.tui, store, actions, getTool, getToolCall);
|
|
4795
5031
|
case "context": return new ContextOverlay(store, actions);
|
|
@@ -4920,170 +5156,6 @@ function logoutSuccessMessage(provider) {
|
|
|
4920
5156
|
function logoutNoneMessage() {
|
|
4921
5157
|
return "No active provider is selected; nothing to log out.";
|
|
4922
5158
|
}
|
|
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
5159
|
//#endregion
|
|
5088
5160
|
//#region src/tui-app/session.ts
|
|
5089
5161
|
/**
|
|
@@ -5142,6 +5214,19 @@ function deriveApiKeyRef(route) {
|
|
|
5142
5214
|
const upper = route.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
5143
5215
|
return `${/^[A-Z_]/.test(upper) ? upper : `P_${upper}`}_API_KEY`;
|
|
5144
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
|
+
}
|
|
5145
5230
|
/** Nest a provider settings section at its path, e.g. `['providers','deepseek']` -> `{ providers: { deepseek: section } }`. */
|
|
5146
5231
|
function nestAtPath(path, section) {
|
|
5147
5232
|
let patch = section;
|
|
@@ -5215,8 +5300,6 @@ async function attachSession(host, resumeId) {
|
|
|
5215
5300
|
const userValue = descriptor === void 0 ? void 0 : getAtPath(descriptor.user, entry.settingsPath);
|
|
5216
5301
|
const apiKeyRef = value?.apiKeyEnv ?? deriveApiKeyRef(entry.provider);
|
|
5217
5302
|
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
5303
|
rows.push({
|
|
5221
5304
|
route: entry.provider,
|
|
5222
5305
|
displayName: value?.displayName ?? entry.displayName,
|
|
@@ -5228,8 +5311,6 @@ async function attachSession(host, resumeId) {
|
|
|
5228
5311
|
baseURL: value?.baseURL,
|
|
5229
5312
|
apiKeyRef,
|
|
5230
5313
|
apiKeyConfigured: info.configured,
|
|
5231
|
-
oauth,
|
|
5232
|
-
grantConfigured: grant !== void 0,
|
|
5233
5314
|
models: value?.models ?? [],
|
|
5234
5315
|
revision: descriptor?.revision
|
|
5235
5316
|
});
|
|
@@ -5241,6 +5322,30 @@ async function attachSession(host, resumeId) {
|
|
|
5241
5322
|
selected: 0
|
|
5242
5323
|
});
|
|
5243
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
|
+
}
|
|
5244
5349
|
async function loadAgentPresets() {
|
|
5245
5350
|
const presetsSvc = host.ctx.get("agentPresets");
|
|
5246
5351
|
if (presetsSvc === void 0) {
|
|
@@ -5271,6 +5376,7 @@ async function attachSession(host, resumeId) {
|
|
|
5271
5376
|
});
|
|
5272
5377
|
}
|
|
5273
5378
|
}
|
|
5379
|
+
let pendingPromptResolve;
|
|
5274
5380
|
const actions = {
|
|
5275
5381
|
send(text) {
|
|
5276
5382
|
store.setNotice(void 0);
|
|
@@ -5389,29 +5495,84 @@ async function attachSession(host, resumeId) {
|
|
|
5389
5495
|
loadProviders();
|
|
5390
5496
|
},
|
|
5391
5497
|
login() {
|
|
5392
|
-
store.
|
|
5393
|
-
|
|
5498
|
+
store.openLogin();
|
|
5499
|
+
loadAuthorizationFlows();
|
|
5500
|
+
},
|
|
5501
|
+
closeLogin() {
|
|
5502
|
+
store.closeOverlay();
|
|
5503
|
+
},
|
|
5504
|
+
selectLoginFlow(index) {
|
|
5505
|
+
store.updateLogin({ selected: index });
|
|
5394
5506
|
},
|
|
5395
|
-
|
|
5507
|
+
beginAuthorization(key) {
|
|
5396
5508
|
(async () => {
|
|
5397
|
-
const
|
|
5398
|
-
if (
|
|
5399
|
-
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.");
|
|
5400
5512
|
return;
|
|
5401
5513
|
}
|
|
5402
|
-
const
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
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 });
|
|
5406
5567
|
}
|
|
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
5568
|
})();
|
|
5414
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
|
+
},
|
|
5415
5576
|
logout() {
|
|
5416
5577
|
(async () => {
|
|
5417
5578
|
const credentialsSvc = host.ctx.get("credentials");
|
|
@@ -5428,8 +5589,6 @@ async function attachSession(host, resumeId) {
|
|
|
5428
5589
|
return;
|
|
5429
5590
|
}
|
|
5430
5591
|
try {
|
|
5431
|
-
const oauth = oauthProviderFor(row.route);
|
|
5432
|
-
if (oauth !== void 0) await revokeOAuthGrant(oauth, credentialsSvc);
|
|
5433
5592
|
await credentialsSvc.unset(row.apiKeyRef);
|
|
5434
5593
|
store.setNotice(logoutSuccessMessage(row.displayName));
|
|
5435
5594
|
loadProviders();
|