acryl 0.1.13 → 0.1.15
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 +451 -7
- package/lib/bin.js.map +1 -1
- package/lib/index.js +382 -6
- package/lib/index.js.map +1 -1
- package/package.json +1 -3
- package/lib/types/bin.d.ts +0 -4
- package/lib/types/cli/grammar.d.ts +0 -10
- package/lib/types/cli/node-launcher.d.ts +0 -9
- package/lib/types/cli/run.d.ts +0 -32
- package/lib/types/host/direct.d.ts +0 -18
- package/lib/types/index.d.ts +0 -3
- package/lib/types/markdown.d.ts +0 -28
- package/lib/types/render.d.ts +0 -78
- package/lib/types/sessionId.d.ts +0 -12
- package/lib/types/tui/CustomEditor.d.ts +0 -51
- package/lib/types/tui/Spinner.d.ts +0 -18
- package/lib/types/tui/TuiApp.d.ts +0 -64
- package/lib/types/tui/actions.d.ts +0 -85
- package/lib/types/tui/agentPresets/AgentPresetsOverlay.d.ts +0 -19
- package/lib/types/tui/agentPresets/types.d.ts +0 -18
- package/lib/types/tui/bannerText.d.ts +0 -19
- package/lib/types/tui/commands.d.ts +0 -54
- package/lib/types/tui/context/ContextOverlay.d.ts +0 -17
- package/lib/types/tui/fileIndex.d.ts +0 -17
- package/lib/types/tui/fileMention.d.ts +0 -31
- package/lib/types/tui/interaction/ApprovalOverlay.d.ts +0 -18
- package/lib/types/tui/interaction/QuestionOverlay.d.ts +0 -26
- package/lib/types/tui/interaction/types.d.ts +0 -36
- package/lib/types/tui/liveText.d.ts +0 -60
- package/lib/types/tui/logoArt.generated.d.ts +0 -9
- package/lib/types/tui/miniTextField.d.ts +0 -20
- package/lib/types/tui/modelProfile/ModelProfileOverlay.d.ts +0 -48
- package/lib/types/tui/modelProfile/types.d.ts +0 -63
- package/lib/types/tui/piTheme.d.ts +0 -10
- package/lib/types/tui/plugins/PluginsOverlay.d.ts +0 -22
- package/lib/types/tui/plugins/types.d.ts +0 -18
- package/lib/types/tui/promptAutocomplete.d.ts +0 -29
- package/lib/types/tui/statsFormat.d.ts +0 -89
- package/lib/types/tui/store.d.ts +0 -246
- package/lib/types/tui/text.d.ts +0 -21
- package/lib/types/tui/theme.d.ts +0 -35
- package/lib/types/tui/toolCards/ToolCardsOverlay.d.ts +0 -33
- package/lib/types/tui/trajectory/TrajectoryDetail.d.ts +0 -13
- package/lib/types/tui/trajectory/TrajectoryLedger.d.ts +0 -9
- package/lib/types/tui/trajectory/TrajectoryOverlay.d.ts +0 -39
- package/lib/types/tui/trajectory/detail.d.ts +0 -10
- package/lib/types/tui/trajectory/layout.d.ts +0 -16
- package/lib/types/tui/trajectory/types.d.ts +0 -74
- package/lib/types/tui-app/session.d.ts +0 -21
- package/lib/types/version.d.ts +0 -2
- package/lib/types/yly/yly-frames.generated.d.ts +0 -18
- package/lib/types/yly/yly-pet.d.ts +0 -46
- package/lib/types/yly/yly-programs.d.ts +0 -41
package/lib/bin.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { realpathSync } from "node:fs";
|
|
5
|
-
import { join, relative, resolve } from "node:path";
|
|
4
|
+
import { existsSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
-
import { bootAcrylHarnessProfile, bootAcrylWebProfile, createAcrylSessionBridge } from "acryl-harness-runtime";
|
|
9
8
|
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
9
|
+
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
10
|
+
import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
|
|
10
11
|
import { diffLines } from "diff";
|
|
11
12
|
import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
12
13
|
import { readdir } from "node:fs/promises";
|
|
13
14
|
import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
|
|
14
15
|
import { GoalError } from "@deepseek-ai/dsh-goal";
|
|
15
|
-
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
16
16
|
//#region src/cli/node-launcher.ts
|
|
17
17
|
/** Return the child Node invocation required to expose Cordis HMR internals. */
|
|
18
18
|
function exposedInternalsInvocation(input) {
|
|
@@ -37,6 +37,327 @@ async function relaunchWithExposedInternals(input) {
|
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
|
+
//#region ../node_modules/.pnpm/@deepseek-ai+dsh-cmdline@0.1.1-rc.2_@deepseek-ai+cordis-plugin-loader@1.0.2_@deepseek-a_1bc57e8c58566d7b9c3fbf261d0f481e/node_modules/@deepseek-ai/dsh-cmdline/lib/index.js
|
|
41
|
+
/**
|
|
42
|
+
* @deepseek-ai/dsh-cmdline — the command line a dsh launcher hands to the app
|
|
43
|
+
* it boots.
|
|
44
|
+
*
|
|
45
|
+
* The launcher parses only its own flags (`--profile`, `--patch`, the config
|
|
46
|
+
* dumps) and hands everything after them to the tree verbatim through the
|
|
47
|
+
* {@link CmdlineArgs} service, so an app owns its flag family, its `--help`
|
|
48
|
+
* text, and its parse errors instead of the launcher knowing them.
|
|
49
|
+
*
|
|
50
|
+
* Any app plugin can inject `cmdlineArgs` and call {@link parseCmdline}. A
|
|
51
|
+
* provider may publish the parsed values as its own service from its program's
|
|
52
|
+
* commander action, and ordinary rows
|
|
53
|
+
* can inject that service and read it from lazily resolved config —
|
|
54
|
+
* `port: !!js ctx.webStartup.port ?? 3080` — so a flag beats the value written
|
|
55
|
+
* beside it. No row has launcher-level command-line status.
|
|
56
|
+
* @module @deepseek-ai/dsh-cmdline
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Provide the command line and the exit request on a host context before any
|
|
60
|
+
* tree entry mounts. Both are launcher facts, not config: an embedding host
|
|
61
|
+
* with no command line provides an empty argument list.
|
|
62
|
+
* @param ctx - the host context the tree will mount under.
|
|
63
|
+
* @param host - the invocation's arguments and its exit request.
|
|
64
|
+
*/
|
|
65
|
+
function provideCmdline(ctx, host) {
|
|
66
|
+
const snapshot = Object.freeze([...host.args]);
|
|
67
|
+
ctx.provide("cmdlineArgs", { get: () => snapshot });
|
|
68
|
+
ctx.provide("appExit", host.exit);
|
|
69
|
+
}
|
|
70
|
+
process.stdout, process.stderr;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region ../acryl-harness-runtime/lib/index.mjs
|
|
73
|
+
function contentText(content) {
|
|
74
|
+
return content.filter((block) => {
|
|
75
|
+
return block.type === "text" && typeof block.text === "string";
|
|
76
|
+
}).map((block) => block.text).join("");
|
|
77
|
+
}
|
|
78
|
+
function transcript(events) {
|
|
79
|
+
const items = [];
|
|
80
|
+
for (const event of events) {
|
|
81
|
+
if (event.type === "user/message" && event.data.source.kind === "user") {
|
|
82
|
+
const text = contentText(event.data.content);
|
|
83
|
+
if (text !== "") items.push(Object.freeze({
|
|
84
|
+
id: `event-${event.seq}`,
|
|
85
|
+
author: "user",
|
|
86
|
+
text
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
if (event.type === "assistant/message") {
|
|
90
|
+
const text = contentText(event.data.message.content);
|
|
91
|
+
if (text !== "") items.push(Object.freeze({
|
|
92
|
+
id: `event-${event.seq}`,
|
|
93
|
+
author: "assistant",
|
|
94
|
+
text
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return Object.freeze(items);
|
|
99
|
+
}
|
|
100
|
+
function tools(events) {
|
|
101
|
+
const current = /* @__PURE__ */ new Map();
|
|
102
|
+
for (const event of events) {
|
|
103
|
+
if (event.type === "tool/call") current.set(event.data.callId, Object.freeze({
|
|
104
|
+
callId: event.data.callId,
|
|
105
|
+
name: event.data.name,
|
|
106
|
+
status: "running"
|
|
107
|
+
}));
|
|
108
|
+
if (event.type === "tool/result") {
|
|
109
|
+
const callId = event.data.message.source.callId;
|
|
110
|
+
const existing = current.get(callId);
|
|
111
|
+
if (existing !== void 0) current.set(callId, Object.freeze({
|
|
112
|
+
...existing,
|
|
113
|
+
status: "succeeded"
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return Object.freeze([...current.values()]);
|
|
118
|
+
}
|
|
119
|
+
function status(agent) {
|
|
120
|
+
return agent.status === "running" ? "running" : "idle";
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Runtime-owned adapter over one native DSH agent/session. It creates or resumes
|
|
124
|
+
* the native agent and derives every presentation value from its durable log.
|
|
125
|
+
*/
|
|
126
|
+
function createAcrylSessionBridge(ctx, options) {
|
|
127
|
+
const handles = /* @__PURE__ */ new Map();
|
|
128
|
+
const subscribers = /* @__PURE__ */ new Map();
|
|
129
|
+
const eventListeners = /* @__PURE__ */ new Map();
|
|
130
|
+
let disposed = false;
|
|
131
|
+
const notify = (sessionId) => {
|
|
132
|
+
const listeners = subscribers.get(sessionId);
|
|
133
|
+
if (listeners === void 0) return;
|
|
134
|
+
snapshot(sessionId).then((next) => {
|
|
135
|
+
for (const listener of listeners) try {
|
|
136
|
+
listener(next);
|
|
137
|
+
} catch {}
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const offSessionEvent = ctx.on("session/event", (session, event) => {
|
|
141
|
+
if (!handles.has(session.id)) return;
|
|
142
|
+
notify(session.id);
|
|
143
|
+
const listeners = eventListeners.get(session.id);
|
|
144
|
+
if (listeners === void 0) return;
|
|
145
|
+
for (const listener of listeners) try {
|
|
146
|
+
listener(event);
|
|
147
|
+
} catch {}
|
|
148
|
+
});
|
|
149
|
+
const snapshot = async (sessionId) => {
|
|
150
|
+
const agent = agentFor(sessionId);
|
|
151
|
+
return Object.freeze({
|
|
152
|
+
profile: options.profile,
|
|
153
|
+
generationId: options.generationId,
|
|
154
|
+
attachment: options.attachment,
|
|
155
|
+
sessionId: agent.id,
|
|
156
|
+
agentStatus: status(agent),
|
|
157
|
+
transcript: transcript(agent.session.events),
|
|
158
|
+
tools: tools(agent.session.events)
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const agentFor = (sessionId) => {
|
|
162
|
+
if (disposed) throw new Error("ACRYL session bridge is disposed");
|
|
163
|
+
const handle = handles.get(sessionId);
|
|
164
|
+
if (handle === void 0) throw new Error(`ACRYL session ${sessionId} is not active`);
|
|
165
|
+
return handle.agent;
|
|
166
|
+
};
|
|
167
|
+
return Object.freeze({
|
|
168
|
+
async open(resumeSessionId) {
|
|
169
|
+
if (disposed) throw new Error("ACRYL session bridge is disposed");
|
|
170
|
+
if (handles.size !== 0) throw new Error("ACRYL session bridge already has an active session");
|
|
171
|
+
const defaultModel = ctx.get("agentDefaultModel");
|
|
172
|
+
if (defaultModel === void 0) throw new Error("ACRYL profile has no default agent model");
|
|
173
|
+
const selection = defaultModel.currentSelection();
|
|
174
|
+
const handle = resumeSessionId === void 0 ? await ctx.agents.create({
|
|
175
|
+
sessionId: SessionId(`acryl-session-${crypto.randomUUID()}`),
|
|
176
|
+
meta: { cwd: options.cwd },
|
|
177
|
+
agentOptions: {
|
|
178
|
+
provider: selection.provider,
|
|
179
|
+
model: selection.model
|
|
180
|
+
}
|
|
181
|
+
}) : await ctx.agents.resume({
|
|
182
|
+
resumeSessionId: SessionId(resumeSessionId),
|
|
183
|
+
agentOptions: {
|
|
184
|
+
provider: selection.provider,
|
|
185
|
+
model: selection.model
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
handles.set(handle.agent.id, handle);
|
|
189
|
+
return handle.agent.id;
|
|
190
|
+
},
|
|
191
|
+
snapshot,
|
|
192
|
+
events(sessionId) {
|
|
193
|
+
return agentFor(sessionId).session.events;
|
|
194
|
+
},
|
|
195
|
+
async subscribe(sessionId, listener, _onError) {
|
|
196
|
+
agentFor(sessionId);
|
|
197
|
+
const listeners = subscribers.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
198
|
+
subscribers.set(sessionId, listeners);
|
|
199
|
+
listeners.add(listener);
|
|
200
|
+
try {
|
|
201
|
+
listener(await snapshot(sessionId));
|
|
202
|
+
} catch {}
|
|
203
|
+
let active = true;
|
|
204
|
+
return Object.freeze({
|
|
205
|
+
whenError() {
|
|
206
|
+
return new Promise(() => {});
|
|
207
|
+
},
|
|
208
|
+
async dispose() {
|
|
209
|
+
if (!active) return;
|
|
210
|
+
active = false;
|
|
211
|
+
listeners.delete(listener);
|
|
212
|
+
if (listeners.size === 0) subscribers.delete(sessionId);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
async subscribeEvents(sessionId, listener) {
|
|
217
|
+
agentFor(sessionId);
|
|
218
|
+
const listeners = eventListeners.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
219
|
+
eventListeners.set(sessionId, listeners);
|
|
220
|
+
listeners.add(listener);
|
|
221
|
+
let active = true;
|
|
222
|
+
return Object.freeze({ async dispose() {
|
|
223
|
+
if (!active) return;
|
|
224
|
+
active = false;
|
|
225
|
+
listeners.delete(listener);
|
|
226
|
+
if (listeners.size === 0) eventListeners.delete(sessionId);
|
|
227
|
+
} });
|
|
228
|
+
},
|
|
229
|
+
async submitPrompt(input) {
|
|
230
|
+
const agent = agentFor(input.sessionId);
|
|
231
|
+
if (input.text.trim() === "") throw new Error("ACRYL prompt must not be empty");
|
|
232
|
+
const accepted = new Promise((resolve) => {
|
|
233
|
+
const off = ctx.on("session/event", (session, event) => {
|
|
234
|
+
if (session !== agent.session || event.type !== "user/message") return;
|
|
235
|
+
off();
|
|
236
|
+
resolve();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
agent.followup(createUserMessage({
|
|
240
|
+
content: [{
|
|
241
|
+
type: "text",
|
|
242
|
+
text: input.text
|
|
243
|
+
}],
|
|
244
|
+
source: { kind: "user" }
|
|
245
|
+
}));
|
|
246
|
+
await accepted;
|
|
247
|
+
},
|
|
248
|
+
async cancel(sessionId) {
|
|
249
|
+
agentFor(sessionId).cancel({ kind: "user" });
|
|
250
|
+
},
|
|
251
|
+
async dispose() {
|
|
252
|
+
if (disposed) return;
|
|
253
|
+
disposed = true;
|
|
254
|
+
offSessionEvent();
|
|
255
|
+
subscribers.clear();
|
|
256
|
+
eventListeners.clear();
|
|
257
|
+
const activeHandles = [...handles.values()];
|
|
258
|
+
handles.clear();
|
|
259
|
+
const sessions = ctx.get("sessions");
|
|
260
|
+
for (const handle of activeHandles) {
|
|
261
|
+
try {
|
|
262
|
+
await handle.agent.whenIdle();
|
|
263
|
+
} catch {}
|
|
264
|
+
try {
|
|
265
|
+
await sessions?.flush(handle.agent.session);
|
|
266
|
+
} catch {}
|
|
267
|
+
}
|
|
268
|
+
await Promise.all(activeHandles.map((handle) => handle.dispose()));
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const dshInstallAnchor = createRequire(import.meta.url).resolve("@deepseek-ai/dsh/package.json");
|
|
273
|
+
const profileRoot = "[]\n";
|
|
274
|
+
const shippedPresetsDir = join(resolve(dirname(fileURLToPath(import.meta.url)), "../.."), "deepseek-harness", "packages", "preset", "agent-presets", "presets");
|
|
275
|
+
const ACRYL_RUNTIME_ROWS = [{
|
|
276
|
+
id: "system-prompt",
|
|
277
|
+
name: "@deepseek-ai/dsh-system-prompt",
|
|
278
|
+
config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
|
|
279
|
+
}, { insert: [{
|
|
280
|
+
id: "agent-presets",
|
|
281
|
+
name: "@deepseek-ai/dsh-agent-presets",
|
|
282
|
+
config: {
|
|
283
|
+
default: "standard",
|
|
284
|
+
roots: existsSync(shippedPresetsDir) ? [{
|
|
285
|
+
path: shippedPresetsDir,
|
|
286
|
+
trust: "system"
|
|
287
|
+
}] : [],
|
|
288
|
+
includeShippedRoot: false,
|
|
289
|
+
includeUserRoot: true
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
292
|
+
id: "session-stats",
|
|
293
|
+
name: "@deepseek-ai/dsh-session-stats"
|
|
294
|
+
}] }];
|
|
295
|
+
/** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
|
|
296
|
+
async function bootAcrylHarnessProfile(options) {
|
|
297
|
+
if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
|
|
298
|
+
initProfile(resolveProfileDir(options.profile), DEFAULT_PROFILE_BUNDLES);
|
|
299
|
+
healProfilesModuleFallback(dshInstallAnchor);
|
|
300
|
+
const profile = loadProfile("acryl", options.profile, dshInstallAnchor);
|
|
301
|
+
const rootConfig = join(profile.dir, "cordis.yml");
|
|
302
|
+
writeFileSync(rootConfig, profileRoot);
|
|
303
|
+
const patches = structuredClone([
|
|
304
|
+
...profile.layers.flatMap((layer) => layer.patches),
|
|
305
|
+
...ACRYL_RUNTIME_ROWS,
|
|
306
|
+
...profile.patches
|
|
307
|
+
]);
|
|
308
|
+
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");
|
|
309
|
+
const ctx = await boot("acryl", rootConfig, patches, options.prepare);
|
|
310
|
+
let disposed = false;
|
|
311
|
+
return Object.freeze({
|
|
312
|
+
ctx,
|
|
313
|
+
profileDirectory: profile.dir,
|
|
314
|
+
async dispose() {
|
|
315
|
+
if (disposed) return;
|
|
316
|
+
disposed = true;
|
|
317
|
+
await ctx.fiber.dispose();
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Boot the DSH browser surface (the `web` profile: `dsh-base` + `dsh-web-app`)
|
|
323
|
+
* as one normal ACRYL runtime, so `pnpm acryl-web` serves the same DSH
|
|
324
|
+
* HTTP/WebSocket seam the web surface always uses. The web profile already
|
|
325
|
+
* composes the persona/agent rows ACRYL's terminal surface adds, so no
|
|
326
|
+
* ACRYL_RUNTIME_ROWS are re-inserted (that would duplicate `system-prompt`).
|
|
327
|
+
*/
|
|
328
|
+
async function bootAcrylWebProfile(options = {}) {
|
|
329
|
+
const profileName = "web";
|
|
330
|
+
initProfile(resolveProfileDir(profileName), DEFAULT_PROFILE_BUNDLES);
|
|
331
|
+
healProfilesModuleFallback(dshInstallAnchor);
|
|
332
|
+
const profile = loadProfile("web", profileName, dshInstallAnchor);
|
|
333
|
+
const rootConfig = join(profile.dir, "cordis.yml");
|
|
334
|
+
writeFileSync(rootConfig, profileRoot);
|
|
335
|
+
const patches = structuredClone([...profile.layers.flatMap((layer) => layer.patches), ...profile.patches]);
|
|
336
|
+
const cmdlineArgs = options.cmdlineArgs ?? [];
|
|
337
|
+
const ctx = await boot("web", rootConfig, patches, (hostCtx) => {
|
|
338
|
+
provideCmdline(hostCtx, {
|
|
339
|
+
args: [...cmdlineArgs],
|
|
340
|
+
exit: (code) => {
|
|
341
|
+
process.exitCode = code;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
return options.prepare?.(hostCtx);
|
|
345
|
+
});
|
|
346
|
+
const startup = ctx.get("webStartup");
|
|
347
|
+
const url = `http://${startup?.host ?? "127.0.0.1"}:${startup?.port ?? 3080}`;
|
|
348
|
+
let disposed = false;
|
|
349
|
+
return Object.freeze({
|
|
350
|
+
ctx,
|
|
351
|
+
url,
|
|
352
|
+
profileDirectory: profile.dir,
|
|
353
|
+
async dispose() {
|
|
354
|
+
if (disposed) return;
|
|
355
|
+
disposed = true;
|
|
356
|
+
await ctx.fiber.dispose();
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
40
361
|
//#region src/host/direct.ts
|
|
41
362
|
/** Start one normal local Harness runtime for this terminal surface. */
|
|
42
363
|
/**
|
|
@@ -1307,6 +1628,14 @@ const SLASH_COMMANDS = [
|
|
|
1307
1628
|
command: "/help",
|
|
1308
1629
|
description: "Show help and available commands"
|
|
1309
1630
|
},
|
|
1631
|
+
{
|
|
1632
|
+
command: "/login",
|
|
1633
|
+
description: "Configure provider authentication (API key)"
|
|
1634
|
+
},
|
|
1635
|
+
{
|
|
1636
|
+
command: "/logout",
|
|
1637
|
+
description: "Remove provider authentication"
|
|
1638
|
+
},
|
|
1310
1639
|
{
|
|
1311
1640
|
command: "/model",
|
|
1312
1641
|
description: "Manage LLM provider profiles"
|
|
@@ -1425,6 +1754,12 @@ function runSlashCommand(command, actions) {
|
|
|
1425
1754
|
case "/model":
|
|
1426
1755
|
actions.openModelProfile();
|
|
1427
1756
|
return;
|
|
1757
|
+
case "/login":
|
|
1758
|
+
actions.login();
|
|
1759
|
+
return;
|
|
1760
|
+
case "/logout":
|
|
1761
|
+
actions.logout();
|
|
1762
|
+
return;
|
|
1428
1763
|
case "/trajectory":
|
|
1429
1764
|
actions.openTrajectory();
|
|
1430
1765
|
return;
|
|
@@ -4588,6 +4923,14 @@ async function walkDirectory(cwd) {
|
|
|
4588
4923
|
}
|
|
4589
4924
|
return results;
|
|
4590
4925
|
}
|
|
4926
|
+
//#endregion
|
|
4927
|
+
//#region src/tui/auth-guidance.ts
|
|
4928
|
+
function logoutSuccessMessage(provider) {
|
|
4929
|
+
return `Removed stored authentication for ${provider.trim() === "" ? "provider" : provider}.`;
|
|
4930
|
+
}
|
|
4931
|
+
function logoutNoneMessage() {
|
|
4932
|
+
return "No active provider is selected; nothing to log out.";
|
|
4933
|
+
}
|
|
4591
4934
|
/** Canonical ACRYL version string used by the CLI and the release smoke checks. */
|
|
4592
4935
|
const ACRYL_VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
4593
4936
|
//#endregion
|
|
@@ -4648,6 +4991,12 @@ function deriveApiKeyRef(route) {
|
|
|
4648
4991
|
const upper = route.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
4649
4992
|
return `${/^[A-Z_]/.test(upper) ? upper : `P_${upper}`}_API_KEY`;
|
|
4650
4993
|
}
|
|
4994
|
+
/** Nest a provider settings section at its path, e.g. `['providers','deepseek']` -> `{ providers: { deepseek: section } }`. */
|
|
4995
|
+
function nestAtPath(path, section) {
|
|
4996
|
+
let patch = section;
|
|
4997
|
+
for (let index = path.length - 1; index >= 0; index--) patch = { [path[index]]: patch };
|
|
4998
|
+
return patch;
|
|
4999
|
+
}
|
|
4651
5000
|
/** English display names for the shipped preset ids (the metadata is authored in Chinese, and there is no server-side locale resolution). */
|
|
4652
5001
|
const PRESET_LABELS = {
|
|
4653
5002
|
standard: "Standard mode",
|
|
@@ -4884,6 +5233,34 @@ async function attachSession(host, resumeId) {
|
|
|
4884
5233
|
store.openModelProfile();
|
|
4885
5234
|
loadProviders();
|
|
4886
5235
|
},
|
|
5236
|
+
login() {
|
|
5237
|
+
store.openModelProfile();
|
|
5238
|
+
loadProviders();
|
|
5239
|
+
},
|
|
5240
|
+
logout() {
|
|
5241
|
+
(async () => {
|
|
5242
|
+
const credentialsSvc = host.ctx.get("credentials");
|
|
5243
|
+
if (credentialsSvc === void 0) {
|
|
5244
|
+
store.setNotice("Credentials are not available in this profile.");
|
|
5245
|
+
return;
|
|
5246
|
+
}
|
|
5247
|
+
const selection = host.ctx.get("agentDefaultModel")?.currentSelection?.();
|
|
5248
|
+
const overlay = store.getSnapshot().overlay;
|
|
5249
|
+
const rows = overlay.kind === "modelProfile" ? overlay.modelProfile.providers : void 0;
|
|
5250
|
+
const row = rows?.find((entry) => entry.route === selection?.provider) ?? (rows !== void 0 && rows.length === 1 ? rows[0] : void 0);
|
|
5251
|
+
if (row === void 0) {
|
|
5252
|
+
store.setNotice(logoutNoneMessage());
|
|
5253
|
+
return;
|
|
5254
|
+
}
|
|
5255
|
+
try {
|
|
5256
|
+
await credentialsSvc.unset(row.apiKeyRef);
|
|
5257
|
+
store.setNotice(logoutSuccessMessage(row.displayName));
|
|
5258
|
+
loadProviders();
|
|
5259
|
+
} catch (error) {
|
|
5260
|
+
store.setNotice(`logout failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5261
|
+
}
|
|
5262
|
+
})();
|
|
5263
|
+
},
|
|
4887
5264
|
openTrajectory() {
|
|
4888
5265
|
store.openTrajectory();
|
|
4889
5266
|
},
|
|
@@ -4920,9 +5297,76 @@ async function attachSession(host, resumeId) {
|
|
|
4920
5297
|
draft: void 0
|
|
4921
5298
|
});
|
|
4922
5299
|
},
|
|
4923
|
-
editProvider() {
|
|
4924
|
-
|
|
4925
|
-
|
|
5300
|
+
editProvider(route) {
|
|
5301
|
+
const overlay = store.getSnapshot().overlay;
|
|
5302
|
+
if (overlay.kind !== "modelProfile") return;
|
|
5303
|
+
const row = overlay.modelProfile.providers?.find((entry) => entry.route === route);
|
|
5304
|
+
if (row === void 0) return;
|
|
5305
|
+
const draft = {
|
|
5306
|
+
route: row.route,
|
|
5307
|
+
isNew: false,
|
|
5308
|
+
settingsNs: row.settingsNs,
|
|
5309
|
+
settingsPath: row.settingsPath,
|
|
5310
|
+
displayName: row.displayName,
|
|
5311
|
+
api: row.api ?? "",
|
|
5312
|
+
baseURL: row.baseURL ?? "",
|
|
5313
|
+
apiKeyRef: row.apiKeyRef,
|
|
5314
|
+
apiKeyConfigured: row.apiKeyConfigured,
|
|
5315
|
+
apiKeyDraft: "",
|
|
5316
|
+
models: row.models,
|
|
5317
|
+
revision: row.revision
|
|
5318
|
+
};
|
|
5319
|
+
store.updateModelProfile({
|
|
5320
|
+
view: "form",
|
|
5321
|
+
draft,
|
|
5322
|
+
formKey: overlay.modelProfile.formKey + 1
|
|
5323
|
+
});
|
|
5324
|
+
},
|
|
5325
|
+
saveProvider(draft) {
|
|
5326
|
+
(async () => {
|
|
5327
|
+
const settingsSvc = host.ctx.get("settings");
|
|
5328
|
+
const credentialsSvc = host.ctx.get("credentials");
|
|
5329
|
+
if (settingsSvc === void 0 || credentialsSvc === void 0) {
|
|
5330
|
+
store.setNotice("Provider settings are not available in this profile.");
|
|
5331
|
+
return;
|
|
5332
|
+
}
|
|
5333
|
+
try {
|
|
5334
|
+
const key = draft.apiKeyDraft.trim();
|
|
5335
|
+
if (key !== "") await credentialsSvc.set(draft.apiKeyRef, key);
|
|
5336
|
+
const section = {
|
|
5337
|
+
displayName: draft.displayName,
|
|
5338
|
+
api: draft.api,
|
|
5339
|
+
baseURL: draft.baseURL,
|
|
5340
|
+
apiKeyEnv: draft.apiKeyRef,
|
|
5341
|
+
models: draft.models
|
|
5342
|
+
};
|
|
5343
|
+
await settingsSvc.update(draft.settingsNs, nestAtPath(draft.settingsPath, section), draft.revision);
|
|
5344
|
+
store.setNotice(`Saved ${draft.displayName || draft.route}.`);
|
|
5345
|
+
store.updateModelProfile({ view: "list" });
|
|
5346
|
+
loadProviders();
|
|
5347
|
+
} catch (error) {
|
|
5348
|
+
store.setNotice(`save failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5349
|
+
}
|
|
5350
|
+
})();
|
|
5351
|
+
},
|
|
5352
|
+
deleteProvider(row) {
|
|
5353
|
+
(async () => {
|
|
5354
|
+
const settingsSvc = host.ctx.get("settings");
|
|
5355
|
+
const credentialsSvc = host.ctx.get("credentials");
|
|
5356
|
+
if (settingsSvc === void 0 || credentialsSvc === void 0) {
|
|
5357
|
+
store.setNotice("Provider settings are not available in this profile.");
|
|
5358
|
+
return;
|
|
5359
|
+
}
|
|
5360
|
+
try {
|
|
5361
|
+
await credentialsSvc.unset(row.apiKeyRef);
|
|
5362
|
+
await settingsSvc.update(row.settingsNs, nestAtPath(row.settingsPath, {}), row.revision);
|
|
5363
|
+
store.setNotice(`Removed ${row.displayName}.`);
|
|
5364
|
+
loadProviders();
|
|
5365
|
+
} catch (error) {
|
|
5366
|
+
store.setNotice(`delete failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5367
|
+
}
|
|
5368
|
+
})();
|
|
5369
|
+
},
|
|
4926
5370
|
discoverModelsForDraft() {},
|
|
4927
5371
|
setActiveModel() {},
|
|
4928
5372
|
closeTrajectory() {
|