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/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { bootAcrylHarnessProfile, createAcrylSessionBridge } from "acryl-harness-runtime";
|
|
4
3
|
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
4
|
+
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
5
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
|
|
5
9
|
import { diffLines } from "diff";
|
|
6
10
|
import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
7
11
|
import { spawn } from "node:child_process";
|
|
8
12
|
import { readdir } from "node:fs/promises";
|
|
9
|
-
import { join, relative } from "node:path";
|
|
10
13
|
import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
|
|
11
14
|
import { GoalError } from "@deepseek-ai/dsh-goal";
|
|
12
|
-
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
13
15
|
//#region src/cli/grammar.ts
|
|
14
16
|
const HOST_COMMANDS = /* @__PURE__ */ new Set([
|
|
15
17
|
"tui",
|
|
@@ -85,6 +87,257 @@ function parseAcrylArgs(args) {
|
|
|
85
87
|
...resumeSessionId === void 0 ? {} : { resumeSessionId }
|
|
86
88
|
};
|
|
87
89
|
}
|
|
90
|
+
process.stdout, process.stderr;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region ../acryl-harness-runtime/lib/index.mjs
|
|
93
|
+
function contentText(content) {
|
|
94
|
+
return content.filter((block) => {
|
|
95
|
+
return block.type === "text" && typeof block.text === "string";
|
|
96
|
+
}).map((block) => block.text).join("");
|
|
97
|
+
}
|
|
98
|
+
function transcript(events) {
|
|
99
|
+
const items = [];
|
|
100
|
+
for (const event of events) {
|
|
101
|
+
if (event.type === "user/message" && event.data.source.kind === "user") {
|
|
102
|
+
const text = contentText(event.data.content);
|
|
103
|
+
if (text !== "") items.push(Object.freeze({
|
|
104
|
+
id: `event-${event.seq}`,
|
|
105
|
+
author: "user",
|
|
106
|
+
text
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
if (event.type === "assistant/message") {
|
|
110
|
+
const text = contentText(event.data.message.content);
|
|
111
|
+
if (text !== "") items.push(Object.freeze({
|
|
112
|
+
id: `event-${event.seq}`,
|
|
113
|
+
author: "assistant",
|
|
114
|
+
text
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return Object.freeze(items);
|
|
119
|
+
}
|
|
120
|
+
function tools(events) {
|
|
121
|
+
const current = /* @__PURE__ */ new Map();
|
|
122
|
+
for (const event of events) {
|
|
123
|
+
if (event.type === "tool/call") current.set(event.data.callId, Object.freeze({
|
|
124
|
+
callId: event.data.callId,
|
|
125
|
+
name: event.data.name,
|
|
126
|
+
status: "running"
|
|
127
|
+
}));
|
|
128
|
+
if (event.type === "tool/result") {
|
|
129
|
+
const callId = event.data.message.source.callId;
|
|
130
|
+
const existing = current.get(callId);
|
|
131
|
+
if (existing !== void 0) current.set(callId, Object.freeze({
|
|
132
|
+
...existing,
|
|
133
|
+
status: "succeeded"
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return Object.freeze([...current.values()]);
|
|
138
|
+
}
|
|
139
|
+
function status(agent) {
|
|
140
|
+
return agent.status === "running" ? "running" : "idle";
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Runtime-owned adapter over one native DSH agent/session. It creates or resumes
|
|
144
|
+
* the native agent and derives every presentation value from its durable log.
|
|
145
|
+
*/
|
|
146
|
+
function createAcrylSessionBridge(ctx, options) {
|
|
147
|
+
const handles = /* @__PURE__ */ new Map();
|
|
148
|
+
const subscribers = /* @__PURE__ */ new Map();
|
|
149
|
+
const eventListeners = /* @__PURE__ */ new Map();
|
|
150
|
+
let disposed = false;
|
|
151
|
+
const notify = (sessionId) => {
|
|
152
|
+
const listeners = subscribers.get(sessionId);
|
|
153
|
+
if (listeners === void 0) return;
|
|
154
|
+
snapshot(sessionId).then((next) => {
|
|
155
|
+
for (const listener of listeners) try {
|
|
156
|
+
listener(next);
|
|
157
|
+
} catch {}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
const offSessionEvent = ctx.on("session/event", (session, event) => {
|
|
161
|
+
if (!handles.has(session.id)) return;
|
|
162
|
+
notify(session.id);
|
|
163
|
+
const listeners = eventListeners.get(session.id);
|
|
164
|
+
if (listeners === void 0) return;
|
|
165
|
+
for (const listener of listeners) try {
|
|
166
|
+
listener(event);
|
|
167
|
+
} catch {}
|
|
168
|
+
});
|
|
169
|
+
const snapshot = async (sessionId) => {
|
|
170
|
+
const agent = agentFor(sessionId);
|
|
171
|
+
return Object.freeze({
|
|
172
|
+
profile: options.profile,
|
|
173
|
+
generationId: options.generationId,
|
|
174
|
+
attachment: options.attachment,
|
|
175
|
+
sessionId: agent.id,
|
|
176
|
+
agentStatus: status(agent),
|
|
177
|
+
transcript: transcript(agent.session.events),
|
|
178
|
+
tools: tools(agent.session.events)
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
const agentFor = (sessionId) => {
|
|
182
|
+
if (disposed) throw new Error("ACRYL session bridge is disposed");
|
|
183
|
+
const handle = handles.get(sessionId);
|
|
184
|
+
if (handle === void 0) throw new Error(`ACRYL session ${sessionId} is not active`);
|
|
185
|
+
return handle.agent;
|
|
186
|
+
};
|
|
187
|
+
return Object.freeze({
|
|
188
|
+
async open(resumeSessionId) {
|
|
189
|
+
if (disposed) throw new Error("ACRYL session bridge is disposed");
|
|
190
|
+
if (handles.size !== 0) throw new Error("ACRYL session bridge already has an active session");
|
|
191
|
+
const defaultModel = ctx.get("agentDefaultModel");
|
|
192
|
+
if (defaultModel === void 0) throw new Error("ACRYL profile has no default agent model");
|
|
193
|
+
const selection = defaultModel.currentSelection();
|
|
194
|
+
const handle = resumeSessionId === void 0 ? await ctx.agents.create({
|
|
195
|
+
sessionId: SessionId(`acryl-session-${crypto.randomUUID()}`),
|
|
196
|
+
meta: { cwd: options.cwd },
|
|
197
|
+
agentOptions: {
|
|
198
|
+
provider: selection.provider,
|
|
199
|
+
model: selection.model
|
|
200
|
+
}
|
|
201
|
+
}) : await ctx.agents.resume({
|
|
202
|
+
resumeSessionId: SessionId(resumeSessionId),
|
|
203
|
+
agentOptions: {
|
|
204
|
+
provider: selection.provider,
|
|
205
|
+
model: selection.model
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
handles.set(handle.agent.id, handle);
|
|
209
|
+
return handle.agent.id;
|
|
210
|
+
},
|
|
211
|
+
snapshot,
|
|
212
|
+
events(sessionId) {
|
|
213
|
+
return agentFor(sessionId).session.events;
|
|
214
|
+
},
|
|
215
|
+
async subscribe(sessionId, listener, _onError) {
|
|
216
|
+
agentFor(sessionId);
|
|
217
|
+
const listeners = subscribers.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
218
|
+
subscribers.set(sessionId, listeners);
|
|
219
|
+
listeners.add(listener);
|
|
220
|
+
try {
|
|
221
|
+
listener(await snapshot(sessionId));
|
|
222
|
+
} catch {}
|
|
223
|
+
let active = true;
|
|
224
|
+
return Object.freeze({
|
|
225
|
+
whenError() {
|
|
226
|
+
return new Promise(() => {});
|
|
227
|
+
},
|
|
228
|
+
async dispose() {
|
|
229
|
+
if (!active) return;
|
|
230
|
+
active = false;
|
|
231
|
+
listeners.delete(listener);
|
|
232
|
+
if (listeners.size === 0) subscribers.delete(sessionId);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
async subscribeEvents(sessionId, listener) {
|
|
237
|
+
agentFor(sessionId);
|
|
238
|
+
const listeners = eventListeners.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
239
|
+
eventListeners.set(sessionId, listeners);
|
|
240
|
+
listeners.add(listener);
|
|
241
|
+
let active = true;
|
|
242
|
+
return Object.freeze({ async dispose() {
|
|
243
|
+
if (!active) return;
|
|
244
|
+
active = false;
|
|
245
|
+
listeners.delete(listener);
|
|
246
|
+
if (listeners.size === 0) eventListeners.delete(sessionId);
|
|
247
|
+
} });
|
|
248
|
+
},
|
|
249
|
+
async submitPrompt(input) {
|
|
250
|
+
const agent = agentFor(input.sessionId);
|
|
251
|
+
if (input.text.trim() === "") throw new Error("ACRYL prompt must not be empty");
|
|
252
|
+
const accepted = new Promise((resolve) => {
|
|
253
|
+
const off = ctx.on("session/event", (session, event) => {
|
|
254
|
+
if (session !== agent.session || event.type !== "user/message") return;
|
|
255
|
+
off();
|
|
256
|
+
resolve();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
agent.followup(createUserMessage({
|
|
260
|
+
content: [{
|
|
261
|
+
type: "text",
|
|
262
|
+
text: input.text
|
|
263
|
+
}],
|
|
264
|
+
source: { kind: "user" }
|
|
265
|
+
}));
|
|
266
|
+
await accepted;
|
|
267
|
+
},
|
|
268
|
+
async cancel(sessionId) {
|
|
269
|
+
agentFor(sessionId).cancel({ kind: "user" });
|
|
270
|
+
},
|
|
271
|
+
async dispose() {
|
|
272
|
+
if (disposed) return;
|
|
273
|
+
disposed = true;
|
|
274
|
+
offSessionEvent();
|
|
275
|
+
subscribers.clear();
|
|
276
|
+
eventListeners.clear();
|
|
277
|
+
const activeHandles = [...handles.values()];
|
|
278
|
+
handles.clear();
|
|
279
|
+
const sessions = ctx.get("sessions");
|
|
280
|
+
for (const handle of activeHandles) {
|
|
281
|
+
try {
|
|
282
|
+
await handle.agent.whenIdle();
|
|
283
|
+
} catch {}
|
|
284
|
+
try {
|
|
285
|
+
await sessions?.flush(handle.agent.session);
|
|
286
|
+
} catch {}
|
|
287
|
+
}
|
|
288
|
+
await Promise.all(activeHandles.map((handle) => handle.dispose()));
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
const dshInstallAnchor = createRequire(import.meta.url).resolve("@deepseek-ai/dsh/package.json");
|
|
293
|
+
const profileRoot = "[]\n";
|
|
294
|
+
const shippedPresetsDir = join(resolve(dirname(fileURLToPath(import.meta.url)), "../.."), "deepseek-harness", "packages", "preset", "agent-presets", "presets");
|
|
295
|
+
const ACRYL_RUNTIME_ROWS = [{
|
|
296
|
+
id: "system-prompt",
|
|
297
|
+
name: "@deepseek-ai/dsh-system-prompt",
|
|
298
|
+
config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
|
|
299
|
+
}, { insert: [{
|
|
300
|
+
id: "agent-presets",
|
|
301
|
+
name: "@deepseek-ai/dsh-agent-presets",
|
|
302
|
+
config: {
|
|
303
|
+
default: "standard",
|
|
304
|
+
roots: existsSync(shippedPresetsDir) ? [{
|
|
305
|
+
path: shippedPresetsDir,
|
|
306
|
+
trust: "system"
|
|
307
|
+
}] : [],
|
|
308
|
+
includeShippedRoot: false,
|
|
309
|
+
includeUserRoot: true
|
|
310
|
+
}
|
|
311
|
+
}, {
|
|
312
|
+
id: "session-stats",
|
|
313
|
+
name: "@deepseek-ai/dsh-session-stats"
|
|
314
|
+
}] }];
|
|
315
|
+
/** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
|
|
316
|
+
async function bootAcrylHarnessProfile(options) {
|
|
317
|
+
if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
|
|
318
|
+
initProfile(resolveProfileDir(options.profile), DEFAULT_PROFILE_BUNDLES);
|
|
319
|
+
healProfilesModuleFallback(dshInstallAnchor);
|
|
320
|
+
const profile = loadProfile("acryl", options.profile, dshInstallAnchor);
|
|
321
|
+
const rootConfig = join(profile.dir, "cordis.yml");
|
|
322
|
+
writeFileSync(rootConfig, profileRoot);
|
|
323
|
+
const patches = structuredClone([
|
|
324
|
+
...profile.layers.flatMap((layer) => layer.patches),
|
|
325
|
+
...ACRYL_RUNTIME_ROWS,
|
|
326
|
+
...profile.patches
|
|
327
|
+
]);
|
|
328
|
+
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");
|
|
329
|
+
const ctx = await boot("acryl", rootConfig, patches, options.prepare);
|
|
330
|
+
let disposed = false;
|
|
331
|
+
return Object.freeze({
|
|
332
|
+
ctx,
|
|
333
|
+
profileDirectory: profile.dir,
|
|
334
|
+
async dispose() {
|
|
335
|
+
if (disposed) return;
|
|
336
|
+
disposed = true;
|
|
337
|
+
await ctx.fiber.dispose();
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
88
341
|
//#endregion
|
|
89
342
|
//#region src/host/direct.ts
|
|
90
343
|
/** Start one normal local Harness runtime for this terminal surface. */
|
|
@@ -1356,6 +1609,14 @@ const SLASH_COMMANDS = [
|
|
|
1356
1609
|
command: "/help",
|
|
1357
1610
|
description: "Show help and available commands"
|
|
1358
1611
|
},
|
|
1612
|
+
{
|
|
1613
|
+
command: "/login",
|
|
1614
|
+
description: "Configure provider authentication (API key)"
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
command: "/logout",
|
|
1618
|
+
description: "Remove provider authentication"
|
|
1619
|
+
},
|
|
1359
1620
|
{
|
|
1360
1621
|
command: "/model",
|
|
1361
1622
|
description: "Manage LLM provider profiles"
|
|
@@ -1474,6 +1735,12 @@ function runSlashCommand(command, actions) {
|
|
|
1474
1735
|
case "/model":
|
|
1475
1736
|
actions.openModelProfile();
|
|
1476
1737
|
return;
|
|
1738
|
+
case "/login":
|
|
1739
|
+
actions.login();
|
|
1740
|
+
return;
|
|
1741
|
+
case "/logout":
|
|
1742
|
+
actions.logout();
|
|
1743
|
+
return;
|
|
1477
1744
|
case "/trajectory":
|
|
1478
1745
|
actions.openTrajectory();
|
|
1479
1746
|
return;
|
|
@@ -4638,6 +4905,14 @@ async function walkDirectory(cwd) {
|
|
|
4638
4905
|
return results;
|
|
4639
4906
|
}
|
|
4640
4907
|
//#endregion
|
|
4908
|
+
//#region src/tui/auth-guidance.ts
|
|
4909
|
+
function logoutSuccessMessage(provider) {
|
|
4910
|
+
return `Removed stored authentication for ${provider.trim() === "" ? "provider" : provider}.`;
|
|
4911
|
+
}
|
|
4912
|
+
function logoutNoneMessage() {
|
|
4913
|
+
return "No active provider is selected; nothing to log out.";
|
|
4914
|
+
}
|
|
4915
|
+
//#endregion
|
|
4641
4916
|
//#region src/tui-app/session.ts
|
|
4642
4917
|
/**
|
|
4643
4918
|
* ACRYL terminal host adapter: brings up one normal local runtime, opens or
|
|
@@ -4695,6 +4970,12 @@ function deriveApiKeyRef(route) {
|
|
|
4695
4970
|
const upper = route.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
4696
4971
|
return `${/^[A-Z_]/.test(upper) ? upper : `P_${upper}`}_API_KEY`;
|
|
4697
4972
|
}
|
|
4973
|
+
/** Nest a provider settings section at its path, e.g. `['providers','deepseek']` -> `{ providers: { deepseek: section } }`. */
|
|
4974
|
+
function nestAtPath(path, section) {
|
|
4975
|
+
let patch = section;
|
|
4976
|
+
for (let index = path.length - 1; index >= 0; index--) patch = { [path[index]]: patch };
|
|
4977
|
+
return patch;
|
|
4978
|
+
}
|
|
4698
4979
|
/** English display names for the shipped preset ids (the metadata is authored in Chinese, and there is no server-side locale resolution). */
|
|
4699
4980
|
const PRESET_LABELS = {
|
|
4700
4981
|
standard: "Standard mode",
|
|
@@ -4931,6 +5212,34 @@ async function attachSession(host, resumeId) {
|
|
|
4931
5212
|
store.openModelProfile();
|
|
4932
5213
|
loadProviders();
|
|
4933
5214
|
},
|
|
5215
|
+
login() {
|
|
5216
|
+
store.openModelProfile();
|
|
5217
|
+
loadProviders();
|
|
5218
|
+
},
|
|
5219
|
+
logout() {
|
|
5220
|
+
(async () => {
|
|
5221
|
+
const credentialsSvc = host.ctx.get("credentials");
|
|
5222
|
+
if (credentialsSvc === void 0) {
|
|
5223
|
+
store.setNotice("Credentials are not available in this profile.");
|
|
5224
|
+
return;
|
|
5225
|
+
}
|
|
5226
|
+
const selection = host.ctx.get("agentDefaultModel")?.currentSelection?.();
|
|
5227
|
+
const overlay = store.getSnapshot().overlay;
|
|
5228
|
+
const rows = overlay.kind === "modelProfile" ? overlay.modelProfile.providers : void 0;
|
|
5229
|
+
const row = rows?.find((entry) => entry.route === selection?.provider) ?? (rows !== void 0 && rows.length === 1 ? rows[0] : void 0);
|
|
5230
|
+
if (row === void 0) {
|
|
5231
|
+
store.setNotice(logoutNoneMessage());
|
|
5232
|
+
return;
|
|
5233
|
+
}
|
|
5234
|
+
try {
|
|
5235
|
+
await credentialsSvc.unset(row.apiKeyRef);
|
|
5236
|
+
store.setNotice(logoutSuccessMessage(row.displayName));
|
|
5237
|
+
loadProviders();
|
|
5238
|
+
} catch (error) {
|
|
5239
|
+
store.setNotice(`logout failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5240
|
+
}
|
|
5241
|
+
})();
|
|
5242
|
+
},
|
|
4934
5243
|
openTrajectory() {
|
|
4935
5244
|
store.openTrajectory();
|
|
4936
5245
|
},
|
|
@@ -4967,9 +5276,76 @@ async function attachSession(host, resumeId) {
|
|
|
4967
5276
|
draft: void 0
|
|
4968
5277
|
});
|
|
4969
5278
|
},
|
|
4970
|
-
editProvider() {
|
|
4971
|
-
|
|
4972
|
-
|
|
5279
|
+
editProvider(route) {
|
|
5280
|
+
const overlay = store.getSnapshot().overlay;
|
|
5281
|
+
if (overlay.kind !== "modelProfile") return;
|
|
5282
|
+
const row = overlay.modelProfile.providers?.find((entry) => entry.route === route);
|
|
5283
|
+
if (row === void 0) return;
|
|
5284
|
+
const draft = {
|
|
5285
|
+
route: row.route,
|
|
5286
|
+
isNew: false,
|
|
5287
|
+
settingsNs: row.settingsNs,
|
|
5288
|
+
settingsPath: row.settingsPath,
|
|
5289
|
+
displayName: row.displayName,
|
|
5290
|
+
api: row.api ?? "",
|
|
5291
|
+
baseURL: row.baseURL ?? "",
|
|
5292
|
+
apiKeyRef: row.apiKeyRef,
|
|
5293
|
+
apiKeyConfigured: row.apiKeyConfigured,
|
|
5294
|
+
apiKeyDraft: "",
|
|
5295
|
+
models: row.models,
|
|
5296
|
+
revision: row.revision
|
|
5297
|
+
};
|
|
5298
|
+
store.updateModelProfile({
|
|
5299
|
+
view: "form",
|
|
5300
|
+
draft,
|
|
5301
|
+
formKey: overlay.modelProfile.formKey + 1
|
|
5302
|
+
});
|
|
5303
|
+
},
|
|
5304
|
+
saveProvider(draft) {
|
|
5305
|
+
(async () => {
|
|
5306
|
+
const settingsSvc = host.ctx.get("settings");
|
|
5307
|
+
const credentialsSvc = host.ctx.get("credentials");
|
|
5308
|
+
if (settingsSvc === void 0 || credentialsSvc === void 0) {
|
|
5309
|
+
store.setNotice("Provider settings are not available in this profile.");
|
|
5310
|
+
return;
|
|
5311
|
+
}
|
|
5312
|
+
try {
|
|
5313
|
+
const key = draft.apiKeyDraft.trim();
|
|
5314
|
+
if (key !== "") await credentialsSvc.set(draft.apiKeyRef, key);
|
|
5315
|
+
const section = {
|
|
5316
|
+
displayName: draft.displayName,
|
|
5317
|
+
api: draft.api,
|
|
5318
|
+
baseURL: draft.baseURL,
|
|
5319
|
+
apiKeyEnv: draft.apiKeyRef,
|
|
5320
|
+
models: draft.models
|
|
5321
|
+
};
|
|
5322
|
+
await settingsSvc.update(draft.settingsNs, nestAtPath(draft.settingsPath, section), draft.revision);
|
|
5323
|
+
store.setNotice(`Saved ${draft.displayName || draft.route}.`);
|
|
5324
|
+
store.updateModelProfile({ view: "list" });
|
|
5325
|
+
loadProviders();
|
|
5326
|
+
} catch (error) {
|
|
5327
|
+
store.setNotice(`save failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5328
|
+
}
|
|
5329
|
+
})();
|
|
5330
|
+
},
|
|
5331
|
+
deleteProvider(row) {
|
|
5332
|
+
(async () => {
|
|
5333
|
+
const settingsSvc = host.ctx.get("settings");
|
|
5334
|
+
const credentialsSvc = host.ctx.get("credentials");
|
|
5335
|
+
if (settingsSvc === void 0 || credentialsSvc === void 0) {
|
|
5336
|
+
store.setNotice("Provider settings are not available in this profile.");
|
|
5337
|
+
return;
|
|
5338
|
+
}
|
|
5339
|
+
try {
|
|
5340
|
+
await credentialsSvc.unset(row.apiKeyRef);
|
|
5341
|
+
await settingsSvc.update(row.settingsNs, nestAtPath(row.settingsPath, {}), row.revision);
|
|
5342
|
+
store.setNotice(`Removed ${row.displayName}.`);
|
|
5343
|
+
loadProviders();
|
|
5344
|
+
} catch (error) {
|
|
5345
|
+
store.setNotice(`delete failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5346
|
+
}
|
|
5347
|
+
})();
|
|
5348
|
+
},
|
|
4973
5349
|
discoverModelsForDraft() {},
|
|
4974
5350
|
setActiveModel() {},
|
|
4975
5351
|
closeTrajectory() {
|