@engenty/wizards-runtime 0.9.5 → 0.9.7
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/apps/runtime/dist/agents/architect.js +2 -2
- package/apps/runtime/dist/agents/chat-clients.js +299 -0
- package/apps/runtime/dist/agents/company.js +111 -0
- package/apps/runtime/dist/agents/studio-assistant.js +8 -4
- package/apps/runtime/dist/agents/subscription.js +163 -134
- package/apps/runtime/dist/agents/website.js +571 -53
- package/apps/runtime/dist/app.js +6 -3
- package/apps/runtime/dist/assistant/knows.js +5 -5
- package/apps/runtime/dist/assistant/primer.js +3 -3
- package/apps/runtime/dist/auth/account.js +12 -12
- package/apps/runtime/dist/auth/keys.js +18 -8
- package/apps/runtime/dist/cli/account.js +20 -18
- package/apps/runtime/dist/cli/features.js +3 -3
- package/apps/runtime/dist/cli/ui.js +6 -0
- package/apps/runtime/dist/db/schema.js +1 -1
- package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/server.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/studio.md +1 -1
- package/apps/runtime/dist/docs/user-guide/ai-apps.md +1 -1
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -1
- package/apps/runtime/dist/docs/user-guide/create-account.md +6 -6
- package/apps/runtime/dist/docs/user-guide/first-start.md +1 -1
- package/apps/runtime/dist/docs/user-guide/index.md +5 -5
- package/apps/runtime/dist/docs/user-guide/models.md +14 -8
- package/apps/runtime/dist/docs/user-guide/space.md +1 -1
- package/apps/runtime/dist/features.js +4 -4
- package/apps/runtime/dist/harness/cursor.js +4 -0
- package/apps/runtime/dist/manage.js +4 -4
- package/apps/runtime/dist/mcp/auth.js +1 -1
- package/apps/runtime/dist/models.js +75 -5
- package/apps/runtime/dist/routes/lang.js +13 -4
- package/apps/runtime/dist/routes/runs.js +1 -1
- package/apps/runtime/dist/routes/studio.js +66 -37
- package/apps/runtime/dist/services/access.js +3 -3
- package/apps/runtime/dist/services/architect.js +4 -2
- package/apps/runtime/dist/services/assistant-chats.js +10 -1
- package/apps/runtime/dist/services/onboarding.js +268 -48
- package/apps/runtime/dist/services/pages.js +17 -15
- package/apps/runtime/dist/services/wizards.js +2 -2
- package/apps/runtime/dist/texts.js +42 -8
- package/apps/web/dist/assets/{AboutDialog-lUBGgvKu.js → AboutDialog-B3tljxg5.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-B2IJbKX8.js → ChangelogDialog-DfWTNzyl.js} +1 -1
- package/apps/web/dist/assets/EditorPage-XDdz2UM4.js +4 -0
- package/apps/web/dist/assets/{FlowPreview-BUKI8h6o.js → FlowPreview-CKNVCFbp.js} +1 -1
- package/apps/web/dist/assets/{Harness-D35I3Jlp.js → Harness-BCec49Cq.js} +2 -2
- package/apps/web/dist/assets/Marketplace-BuYeaxK2.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-PDeL4f5D.js → NewWizardChannels-DRNji-bk.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-4TpgYOaI.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-Cf52NOIt.js +1 -0
- package/apps/web/dist/assets/PreviewPane-C4yMcZPM.js +4 -0
- package/apps/web/dist/assets/ProjectPage-D6Tah3QK.js +1 -0
- package/apps/web/dist/assets/{PublicRunner-BnT-zZrI.js → PublicRunner-Bftc1c4m.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-C5fdw_kg.js → ReadOnly-DVQm9IYx.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-Cd-osLDu.js +2 -0
- package/apps/web/dist/assets/SetupPage-Dc8U5k5P.js +1 -0
- package/apps/web/dist/assets/{SharePage-BiPJsotS.js → SharePage-Cn-bqSyr.js} +1 -1
- package/apps/web/dist/assets/changelog-CjSBB-a4.js +1 -0
- package/apps/web/dist/assets/{coins-DVGgwSrK.js → coins-DgDTBbeg.js} +1 -1
- package/apps/web/dist/assets/index-DS3zUVw_.css +1 -0
- package/apps/web/dist/assets/index-Da7hPToW.js +14 -0
- package/apps/web/dist/assets/oss-credits-C2JUsf2d.js +1 -0
- package/apps/web/dist/assets/{phone-DD2g0U0Q.js → phone-D1Drdiio.js} +1 -1
- package/apps/web/dist/assets/preload-helper-DpV6A1kQ.js +1 -0
- package/apps/web/dist/assets/{qr-scanner.min-C_UI0gH-.js → qr-scanner.min-BGqShvxG.js} +1 -1
- package/apps/web/dist/assets/{runners-D6mK0B73.js → runners-CTd0YAiA.js} +1 -1
- package/apps/web/dist/assets/{session-BHCBxqVb.js → session-DX2BcTfz.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-DGDn2688.js → settings-menu-ay9jNbQu.js} +1 -1
- package/apps/web/dist/assets/theme-DanjuO1H.js +11 -0
- package/apps/web/dist/assets/ui-CJCF3Mhe.js +137 -0
- package/apps/web/dist/assets/{upload-uc9uftDy.js → upload-Dj7KPL--.js} +1 -1
- package/apps/web/dist/assets/{useMutation-BfQIRblT.js → useMutation-CUSQpD-i.js} +1 -1
- package/apps/web/dist/assets/{volume-2-BlaOos9n.js → volume-2-CcHZOU2m.js} +1 -1
- package/apps/web/dist/assets/{wrench-Cfpkphyw.js → wrench-CfJTFnMJ.js} +1 -1
- package/apps/web/dist/index.html +9 -9
- package/apps/web/dist/mcp/flow.html +56 -56
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +2 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +4 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.js +9 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +5 -5
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +5 -5
- package/node_modules/@engenty/wizards-shared/dist/features.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/features.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/projects.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/projects.js +2 -2
- package/node_modules/@engenty/wizards-shared/dist/providers.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/providers.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/run.js +4 -4
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/EditorPage-B1syriTz.js +0 -4
- package/apps/web/dist/assets/Marketplace-C-ft5u_6.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-BHw086HN.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-BYa8Xekc.js +0 -1
- package/apps/web/dist/assets/PreviewPane-Cuatuhi-.js +0 -4
- package/apps/web/dist/assets/ProjectPage-DTbTN9rE.js +0 -1
- package/apps/web/dist/assets/SettingsPage-Bkd5LuRn.js +0 -2
- package/apps/web/dist/assets/SetupPage-CHnbGccO.js +0 -1
- package/apps/web/dist/assets/changelog-Do_saoEi.js +0 -1
- package/apps/web/dist/assets/index-C-u3ZXBZ.js +0 -14
- package/apps/web/dist/assets/index-DtjKnB3s.css +0 -1
- package/apps/web/dist/assets/oss-credits-D7izqI_0.js +0 -1
- package/apps/web/dist/assets/preload-helper-CNEI7N0N.js +0 -1
- package/apps/web/dist/assets/theme-DQ10nO_L.js +0 -11
- package/apps/web/dist/assets/ui-BV4KP5n2.js +0 -137
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
4
6
|
import { createInterface } from "node:readline";
|
|
5
7
|
import { internalKey } from "../auth/keys.js";
|
|
6
8
|
import { env } from "../env.js";
|
|
7
|
-
import {
|
|
8
|
-
import { detectHarness, signedOut } from "../harness/index.js";
|
|
9
|
-
import { localModelSettings } from "../models.js";
|
|
9
|
+
import { resolveEnv } from "../harness/env.js";
|
|
10
|
+
import { detectHarness, harness, signedOut } from "../harness/index.js";
|
|
11
|
+
import { CHAT_WAYS, chatWayReady, localModelSettings } from "../models.js";
|
|
10
12
|
import { ServiceError } from "../services/errors.js";
|
|
11
13
|
import { deleteSetting, readSetting, writeSetting } from "../settings.js";
|
|
12
14
|
import { serverText } from "../texts.js";
|
|
15
|
+
import { CHAT_CLIENTS, CODEX_KEY_VAR, cursorWorkspace, SUBSCRIPTION_CLIENTS, } from "./chat-clients.js";
|
|
13
16
|
import { thoughtLine } from "./thought.js";
|
|
14
|
-
/** The AI clients installed on this machine whose subscription can answer the studio chat. */
|
|
17
|
+
/** The AI clients installed and signed in on this machine whose subscription can answer the studio chat. */
|
|
15
18
|
export async function subscriptionClients() {
|
|
16
|
-
|
|
19
|
+
const found = await Promise.all(SUBSCRIPTION_CLIENTS.map(async (id) => {
|
|
20
|
+
const h = await detectHarness(id);
|
|
21
|
+
return h?.version && h.auth !== "none" ? id : null;
|
|
22
|
+
}));
|
|
23
|
+
return found.filter((id) => id !== null);
|
|
17
24
|
}
|
|
18
25
|
const workDir = join(env.dataDir, "subscription");
|
|
19
|
-
|
|
26
|
+
const mcpUrl = () => `http://127.0.0.1:${env.port}/api/mcp`;
|
|
27
|
+
/** Claude's MCP config: this server only, signed in with a key made for this process. */
|
|
20
28
|
function mcpConfig() {
|
|
21
29
|
mkdirSync(workDir, { recursive: true });
|
|
22
30
|
const file = join(workDir, "mcp.json");
|
|
@@ -24,13 +32,25 @@ function mcpConfig() {
|
|
|
24
32
|
mcpServers: {
|
|
25
33
|
wizards: {
|
|
26
34
|
type: "http",
|
|
27
|
-
url:
|
|
28
|
-
headers: { Authorization: `Bearer ${internalKey()}` },
|
|
35
|
+
url: mcpUrl(),
|
|
36
|
+
headers: { Authorization: `Bearer ${internalKey("Claude")}` },
|
|
29
37
|
},
|
|
30
38
|
},
|
|
31
39
|
}), { mode: 0o600 });
|
|
32
40
|
return file;
|
|
33
41
|
}
|
|
42
|
+
/** The server names in the person's own Cursor config, which the chat's workspace denies. */
|
|
43
|
+
function ownCursorServers() {
|
|
44
|
+
const file = join(homedir(), ".cursor", "mcp.json");
|
|
45
|
+
try {
|
|
46
|
+
return existsSync(file)
|
|
47
|
+
? Object.keys(JSON.parse(readFileSync(file, "utf8")).mcpServers ?? {})
|
|
48
|
+
: [];
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
34
54
|
const SYSTEM = (wizardId) => [
|
|
35
55
|
"You are the architect in the engenty wizards studio. The admin talks to you in the studio's chat panel, next to a diagram of the wizard.",
|
|
36
56
|
`You work on exactly one wizard: id "${wizardId}". Read it with get_wizard before you change it; change it with edit_wizard and the file tools; never create another wizard and never publish unless the admin asks.`,
|
|
@@ -54,154 +74,163 @@ function activity(name, args, lang = "en") {
|
|
|
54
74
|
const about = [args.path, args.query].find((v) => typeof v === "string" && v.trim());
|
|
55
75
|
return about ? `${label}: ${String(about)} …` : `${label} …`;
|
|
56
76
|
}
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
/** One conversation per wizard and client: another client cannot continue it. */
|
|
78
|
+
const sessionKey = (client, wizardId) => client === "claude" ? `chat-session:${wizardId}` : `chat-session:${client}:${wizardId}`;
|
|
79
|
+
const EXT = {
|
|
80
|
+
"image/png": "png",
|
|
81
|
+
"image/jpeg": "jpg",
|
|
82
|
+
"image/webp": "webp",
|
|
83
|
+
"image/gif": "gif",
|
|
84
|
+
};
|
|
85
|
+
/** One chat turn on a subscription. The client keeps the conversation; we keep its id. */
|
|
59
86
|
export async function subscriptionTurn(input) {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"--mcp-config",
|
|
76
|
-
mcpConfig(),
|
|
77
|
-
"--allowedTools",
|
|
78
|
-
"mcp__wizards",
|
|
79
|
-
"--disable-slash-commands",
|
|
80
|
-
"--setting-sources",
|
|
81
|
-
"",
|
|
82
|
-
"--append-system-prompt",
|
|
83
|
-
SYSTEM(input.wizardId),
|
|
84
|
-
...(session ? ["--resume", session] : []),
|
|
85
|
-
];
|
|
86
|
-
const child = spawn(CLAUDE, args, {
|
|
87
|
-
cwd: workDir,
|
|
88
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
89
|
-
signal: input.signal,
|
|
90
|
-
// The client's own sign-in, as the person's terminal has it; no key of ours reaches it.
|
|
91
|
-
env: await claudeEnv(),
|
|
92
|
-
});
|
|
93
|
-
child.stdin.on("error", () => {
|
|
94
|
-
// A client that is gone already says so on stdout and in its exit code.
|
|
95
|
-
});
|
|
96
|
-
child.stdin.end(`${JSON.stringify({
|
|
97
|
-
type: "user",
|
|
98
|
-
message: {
|
|
99
|
-
role: "user",
|
|
100
|
-
content: [
|
|
101
|
-
{ type: "text", text: input.message },
|
|
102
|
-
...(input.images ?? []).map((i) => ({
|
|
103
|
-
type: "image",
|
|
104
|
-
source: {
|
|
105
|
-
type: "base64",
|
|
106
|
-
media_type: i.mime,
|
|
107
|
-
data: Buffer.from(i.data).toString("base64"),
|
|
108
|
-
},
|
|
109
|
-
})),
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
})}\n`);
|
|
113
|
-
let reply = "";
|
|
114
|
-
let changed = false;
|
|
115
|
-
let failure = "";
|
|
116
|
-
let thinking = "";
|
|
117
|
-
let thought = null;
|
|
118
|
-
let stderr = "";
|
|
119
|
-
child.stderr.on("data", (chunk) => {
|
|
120
|
-
stderr = (stderr + String(chunk)).slice(-2000);
|
|
121
|
-
});
|
|
122
|
-
for await (const line of createInterface({ input: child.stdout })) {
|
|
123
|
-
let event;
|
|
124
|
-
try {
|
|
125
|
-
event = JSON.parse(line);
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
continue;
|
|
87
|
+
const client = CHAT_CLIENTS[input.client];
|
|
88
|
+
const key = sessionKey(input.client, input.wizardId);
|
|
89
|
+
// Cursor Agent keeps its chats per workspace: one folder per wizard.
|
|
90
|
+
const dir = input.client === "cursor" ? join(workDir, "cursor", input.wizardId) : workDir;
|
|
91
|
+
mkdirSync(dir, { recursive: true });
|
|
92
|
+
const system = SYSTEM(input.wizardId);
|
|
93
|
+
if (input.client === "cursor") {
|
|
94
|
+
for (const [path, text] of Object.entries(cursorWorkspace({
|
|
95
|
+
system,
|
|
96
|
+
mcpUrl: mcpUrl(),
|
|
97
|
+
key: internalKey("Cursor"),
|
|
98
|
+
ownServers: ownCursorServers(),
|
|
99
|
+
}))) {
|
|
100
|
+
mkdirSync(dirname(join(dir, path)), { recursive: true });
|
|
101
|
+
writeFileSync(join(dir, path), text, { mode: 0o600 });
|
|
129
102
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (next && next !== thought) {
|
|
142
|
-
thought = next;
|
|
143
|
-
input.onThought?.(next);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
103
|
+
}
|
|
104
|
+
// Codex attaches pictures as files; they go once the turn ends.
|
|
105
|
+
const images = (input.images ?? []).map((i) => ({
|
|
106
|
+
mime: i.mime,
|
|
107
|
+
base64: Buffer.from(i.data).toString("base64"),
|
|
108
|
+
file: join(workDir, "images", `${randomUUID()}.${EXT[i.mime] ?? "png"}`),
|
|
109
|
+
}));
|
|
110
|
+
if (input.client === "codex") {
|
|
111
|
+
for (const [n, image] of images.entries()) {
|
|
112
|
+
mkdirSync(dirname(image.file), { recursive: true });
|
|
113
|
+
writeFileSync(image.file, input.images?.[n]?.data ?? new Uint8Array());
|
|
146
114
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
115
|
+
}
|
|
116
|
+
const call = {
|
|
117
|
+
system,
|
|
118
|
+
message: input.message,
|
|
119
|
+
session: await readSetting(key),
|
|
120
|
+
mcpUrl: mcpUrl(),
|
|
121
|
+
dir,
|
|
122
|
+
mcpConfigFile: input.client === "claude" ? mcpConfig() : undefined,
|
|
123
|
+
images,
|
|
124
|
+
};
|
|
125
|
+
const h = harness(input.client);
|
|
126
|
+
// The client's own sign-in, as the person's terminal has it; no key of ours reaches it.
|
|
127
|
+
const childEnv = h ? (await resolveEnv(h)).env : process.env;
|
|
128
|
+
try {
|
|
129
|
+
const child = spawn(client.bin, client.args(call), {
|
|
130
|
+
cwd: dir,
|
|
131
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
132
|
+
signal: input.signal,
|
|
133
|
+
env: input.client === "codex"
|
|
134
|
+
? { ...childEnv, [CODEX_KEY_VAR]: internalKey("Codex") }
|
|
135
|
+
: childEnv,
|
|
136
|
+
});
|
|
137
|
+
child.stdin.on("error", () => {
|
|
138
|
+
// A client that is gone already says so on stdout and in its exit code.
|
|
139
|
+
});
|
|
140
|
+
child.stdin.end(client.stdin(call));
|
|
141
|
+
let reply = "";
|
|
142
|
+
let changed = false;
|
|
143
|
+
let failure = "";
|
|
144
|
+
let thinking = "";
|
|
145
|
+
let thought = null;
|
|
146
|
+
let stderr = "";
|
|
147
|
+
child.stderr.on("data", (chunk) => {
|
|
148
|
+
stderr = (stderr + String(chunk)).slice(-2000);
|
|
149
|
+
});
|
|
150
|
+
for await (const line of createInterface({ input: child.stdout })) {
|
|
151
|
+
for (const event of client.events(line)) {
|
|
152
|
+
if (event.kind === "text") {
|
|
153
|
+
const text = reply ? `\n\n${event.text}` : event.text;
|
|
151
154
|
reply += text;
|
|
152
155
|
input.onText(text);
|
|
153
156
|
}
|
|
154
|
-
else if (
|
|
155
|
-
|
|
156
|
-
if (BUILDING.test(name)) {
|
|
157
|
+
else if (event.kind === "tool") {
|
|
158
|
+
if (event.started && BUILDING.test(event.name)) {
|
|
157
159
|
changed = true;
|
|
158
160
|
input.onBuilding();
|
|
159
161
|
}
|
|
160
|
-
input.onActivity(activity(name,
|
|
162
|
+
input.onActivity(activity(event.name, event.args, input.lang));
|
|
163
|
+
}
|
|
164
|
+
else if (event.kind === "thinkingStart") {
|
|
165
|
+
thinking = "";
|
|
166
|
+
}
|
|
167
|
+
else if (event.kind === "thinking") {
|
|
168
|
+
thinking += event.text;
|
|
169
|
+
const next = thoughtLine(thinking);
|
|
170
|
+
if (next && next !== thought) {
|
|
171
|
+
thought = next;
|
|
172
|
+
input.onThought?.(next);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (event.kind === "session") {
|
|
176
|
+
await writeSetting(key, event.id);
|
|
177
|
+
}
|
|
178
|
+
else if (event.kind === "failure") {
|
|
179
|
+
failure = event.detail;
|
|
180
|
+
}
|
|
181
|
+
else if (event.kind === "result" && !reply && event.text) {
|
|
182
|
+
reply = event.text;
|
|
183
|
+
input.onText(reply);
|
|
161
184
|
}
|
|
162
185
|
}
|
|
163
186
|
}
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
187
|
+
const code = await new Promise((resolve) => {
|
|
188
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
189
|
+
resolve(child.exitCode);
|
|
167
190
|
}
|
|
168
|
-
|
|
169
|
-
|
|
191
|
+
else {
|
|
192
|
+
child.once("close", resolve);
|
|
170
193
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
194
|
+
});
|
|
195
|
+
if (failure || (code !== 0 && !reply)) {
|
|
196
|
+
// A conversation the client no longer has starts afresh next time.
|
|
197
|
+
await deleteSetting(key);
|
|
198
|
+
const detail = failure || stderr.trim() || `exit ${code}`;
|
|
199
|
+
if (client.signedOut(detail)) {
|
|
200
|
+
throw new ServiceError("refused", signedOut({ id: client.id, name: client.name }));
|
|
174
201
|
}
|
|
202
|
+
throw new Error(`${client.name}: ${detail}`.slice(0, 500));
|
|
175
203
|
}
|
|
204
|
+
return { reply: reply.trim(), changed };
|
|
176
205
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
await deleteSetting(sessionKey(input.wizardId));
|
|
181
|
-
const detail = failure || stderr || `exit ${code}`;
|
|
182
|
-
if (/authenticat|log ?in|oauth|credential/i.test(detail)) {
|
|
183
|
-
throw new ServiceError("refused", signedOut({ id: "claude", name: "Claude Code" }));
|
|
206
|
+
finally {
|
|
207
|
+
for (const image of images) {
|
|
208
|
+
rmSync(image.file, { force: true });
|
|
184
209
|
}
|
|
185
|
-
throw new Error(`Claude Code: ${detail}`.slice(0, 500));
|
|
186
210
|
}
|
|
187
|
-
return { reply: reply.trim(), changed };
|
|
188
211
|
}
|
|
212
|
+
/** The ways that can answer the studio's chats now, in the order the settings offer them. */
|
|
213
|
+
export async function chatWays(textModelReady) {
|
|
214
|
+
const ready = await Promise.all(CHAT_WAYS.map((w) => chatWayReady(w, textModelReady)));
|
|
215
|
+
return CHAT_WAYS.filter((_, i) => ready[i]);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* What answers the studio's chats, Goose and the editor's chat, on a runtime that runs alone: the
|
|
219
|
+
* way chosen while it can answer, else the text classes, or Claude Code where it is the source.
|
|
220
|
+
*/
|
|
189
221
|
export async function chatEngine(textModelReady) {
|
|
190
|
-
const clients = await subscriptionClients();
|
|
191
222
|
const chosen = await readSetting("chat-engine");
|
|
192
|
-
if (chosen
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
if (chosen === "models" && textModelReady) {
|
|
196
|
-
return "models";
|
|
223
|
+
if (chosen && CHAT_WAYS.includes(chosen) && (await chatWayReady(chosen, textModelReady))) {
|
|
224
|
+
return chosen;
|
|
197
225
|
}
|
|
198
|
-
|
|
199
|
-
|
|
226
|
+
const claude = await chatWayReady("claude", textModelReady);
|
|
227
|
+
// Nothing chosen: where Claude Code is the source of models, it answers the chat too.
|
|
228
|
+
if (claude && localModelSettings().source === "claude") {
|
|
200
229
|
return "claude";
|
|
201
230
|
}
|
|
202
|
-
// Else a configured model answers; without one, the subscription does.
|
|
203
|
-
return textModelReady || !
|
|
231
|
+
// Else a configured model answers; without one, the Claude subscription does.
|
|
232
|
+
return textModelReady || !claude ? "models" : "claude";
|
|
204
233
|
}
|
|
205
|
-
export function setChatEngine(
|
|
206
|
-
return writeSetting("chat-engine",
|
|
234
|
+
export function setChatEngine(way) {
|
|
235
|
+
return writeSetting("chat-engine", way);
|
|
207
236
|
}
|