@jmanuelcorral/bond-app 0.1.4 → 0.1.5
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/README.md +41 -1
- package/app/mods/bond-agents/config.js +4 -0
- package/app/mods/bond-agents/main.js +10 -5
- package/app/mods/bond-agents/model.js +47 -2
- package/app/mods/bond-board/config.js +4 -0
- package/app/mods/bond-board/main.js +500 -54
- package/app/mods/bond-board/model.js +47 -0
- package/app/mods/bond-settings/config.js +4 -0
- package/app/mods/bond-settings/main.js +689 -12
- package/app/mods/bond-settings/pi-models.js +144 -0
- package/app/mods/bond-status/config.js +4 -0
- package/app/mods/bond-titlebar/main.js +47 -43
- package/package.json +1 -1
- package/runner/Dockerfile +42 -13
- package/runner/SPIKE-BOND.md +85 -0
- package/runner/build-config/.none +0 -0
- package/runner/build-creds/.none +0 -0
- package/runner/config.example/README.md +27 -0
- package/runner/config.example/pi/models.json +22 -0
- package/runner/credentials.example.env +27 -0
- package/runner/setup.sh +496 -0
- package/runner/versions.env +30 -0
- package/scripts/app-install.ts +4 -0
- package/src/config.ts +8 -0
- package/src/core/hub-session.ts +9 -7
- package/src/core/orchestrator.ts +459 -99
- package/src/core/setup.ts +178 -0
- package/src/db/database.ts +14 -0
- package/src/db/settings-repo.ts +108 -0
- package/src/db/ticket-repo.ts +34 -4
- package/src/runner/docker-client.ts +29 -0
- package/src/runner/github-client.ts +119 -0
- package/src/runner/hc-client.ts +9 -2
- package/src/runner/image-builder.ts +146 -6
- package/src/server/app.ts +211 -7
- package/src/types.ts +40 -0
|
@@ -5,16 +5,38 @@
|
|
|
5
5
|
// P6: a side panel of the bond layout that folds away (node `settings`, toggled from the
|
|
6
6
|
// title bar or the status bar; its ✕ hides it). The versions moved to the status bar.
|
|
7
7
|
//
|
|
8
|
+
// W-P2: the setup wizard lives here too (D-W1): { view: "wizard", step } opened as an
|
|
9
|
+
// overlay — 1 agents, 2 credentials, 3 GitHub, 4 image — and the panel gained a
|
|
10
|
+
// «Configuración» section (GET/PUT /setup) with «Reabrir asistente» (D-W2).
|
|
11
|
+
//
|
|
12
|
+
// W-P3: pi's credential dialog is a builder, not a JSON paste: «modelo local /
|
|
13
|
+
// OpenAI-compatible» asks provider name, base URL, optional API key and model ids and
|
|
14
|
+
// builds the models.json itself (pi-models.js); the full-JSON paste stays as «modo
|
|
15
|
+
// avanzado», and any pasted JSON is parsed before saving.
|
|
16
|
+
//
|
|
17
|
+
// W-P4: nobody types model ids. With a base URL, «Cargar del provider» asks the
|
|
18
|
+
// orchestrator to proxy GET {base}/models (POST /setup/models — the key never goes to
|
|
19
|
+
// the log) and the ids arrive as a checkbox list; if the network fails the textarea
|
|
20
|
+
// stays the way in. Among the checked ones one model is picked «para sugerencias»
|
|
21
|
+
// (heuristic free → cheap → first, or «sin sugerencias»); the choice is saved with
|
|
22
|
+
// PUT /setup { suggestions_model } and the orchestrator injects it per run as
|
|
23
|
+
// ~/.pi/agent/supi/config.json next to the models.json.
|
|
24
|
+
//
|
|
8
25
|
// Props: none (the panel), or { view: "credential", agent, provider } /
|
|
9
|
-
// { view: "rebuild" } when this mod is opened as a
|
|
26
|
+
// { view: "rebuild" } / { view: "wizard", step } when this mod is opened as a
|
|
27
|
+
// dialog or overlay by itself or by bond-board.
|
|
10
28
|
import { View, div } from "gpui-kit";
|
|
11
29
|
import { v_flex, h_flex, InputState, Input, TextareaState, Textarea } from "gpui-base";
|
|
12
30
|
import { props, theme, openOverlay, closeOverlay, notify, shared, setShared, exec, run } from "herdr";
|
|
13
31
|
import { api } from "./api.js";
|
|
14
32
|
import { UI } from "./brand.js";
|
|
33
|
+
import { buildPiModelsDoc, validateConfigJson, normalizeBaseUrl, parseModelIds, suggestSuggestionModel, suggestDefaultModel, toggleModelLine } from "./pi-models.js";
|
|
15
34
|
|
|
16
35
|
const RELOAD_KEY = "bond.settings.reload";
|
|
17
36
|
|
|
37
|
+
/** DOM-safe id fragment for a provider model id (they carry :, / and spaces). */
|
|
38
|
+
const slug = (s) => String(s).replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
39
|
+
|
|
18
40
|
export default class BondSettings extends View {
|
|
19
41
|
init(_props, cx) {
|
|
20
42
|
const p = props() ?? {};
|
|
@@ -23,10 +45,75 @@ export default class BondSettings extends View {
|
|
|
23
45
|
this.error = null;
|
|
24
46
|
this.handle = cx.focus_handle();
|
|
25
47
|
if (this.view === "credential") {
|
|
48
|
+
// W-P3: pi gets the provider builder by default (the user rejected making people
|
|
49
|
+
// hand-write models.json); the raw JSON paste stays as «modo avanzado». The other
|
|
50
|
+
// agents only have the paste, as before.
|
|
51
|
+
this.isPi = p.agent === "pi";
|
|
52
|
+
this.advanced = !this.isPi;
|
|
53
|
+
this.piName = InputState.new({ placeholder: "sin espacios; p. ej. lan u ollama", value: p.provider ?? "" });
|
|
54
|
+
this.piUrl = InputState.new({ placeholder: "p. ej. http://192.168.1.20:11434/v1" });
|
|
55
|
+
this.piKey = InputState.new({ placeholder: "vacío si el endpoint no la pide" });
|
|
56
|
+
this.piModels = TextareaState.new({ placeholder: "un id por línea; p. ej. qwen2.5-coder:7b" });
|
|
57
|
+
this.piModels.set_rows(4);
|
|
58
|
+
// W-P4: the model multiselector. The textarea stays the source of truth of the
|
|
59
|
+
// checked ids (criterion 2: only the marked models reach models.json); «Cargar del
|
|
60
|
+
// provider» fills the list through the orchestrator's proxy.
|
|
61
|
+
this.piModelList = null; // ids loaded from the provider
|
|
62
|
+
this.piListBusy = false;
|
|
63
|
+
this.piListError = null; // network problems: aviso, and manual entry stays open
|
|
64
|
+
this.piSuggest = undefined; // undefined = untouched (the heuristic proposes); "" = «sin sugerencias»
|
|
65
|
+
this.piSavedSuggestions = null; // suggestions_model as the orchestrator has it (GET /setup)
|
|
66
|
+
this.piDefault = undefined; // undefined = untouched; "" = «sin modelo por defecto»
|
|
67
|
+
this.piSavedDefault = null; // default_model as the orchestrator has it (GET /setup)
|
|
68
|
+
this.piProviderName = String(p.provider ?? "").trim(); // fallback prefix for full ids
|
|
69
|
+
// W-P5: the list loads by itself when the URL field loses focus (no button), and
|
|
70
|
+
// a small animated line marks the wait.
|
|
71
|
+
this.piLoadedUrl = null; // base URL the current list (or its error) reflects
|
|
72
|
+
this.piSpin = 0;
|
|
73
|
+
this.piUrl.on("blur", (_ev, cx) => {
|
|
74
|
+
const url = normalizeBaseUrl(this.piUrl.value());
|
|
75
|
+
if (!url || url === this.piLoadedUrl || this.piListBusy) return;
|
|
76
|
+
this.loadPiModels(cx);
|
|
77
|
+
});
|
|
78
|
+
cx.timer.every(220, (cx) => {
|
|
79
|
+
if (!this.piListBusy) return;
|
|
80
|
+
this.piSpin = (this.piSpin + 1) % 4;
|
|
81
|
+
cx.notify();
|
|
82
|
+
});
|
|
83
|
+
cx.spawn(async (cx) => {
|
|
84
|
+
try {
|
|
85
|
+
const s = await api("/setup");
|
|
86
|
+
if (typeof s?.suggestions_model === "string") this.piSavedSuggestions = s.suggestions_model;
|
|
87
|
+
if (typeof s?.default_model === "string") this.piSavedDefault = s.default_model;
|
|
88
|
+
if (Array.isArray(s?.models) && s.models.length > 0 && !this.piModels.value().trim()) {
|
|
89
|
+
let currentProv = this.piName.value().trim() || this.piProviderName;
|
|
90
|
+
if (!currentProv) {
|
|
91
|
+
const firstSlash = s.models[0].indexOf("/");
|
|
92
|
+
if (firstSlash > 0) {
|
|
93
|
+
currentProv = s.models[0].slice(0, firstSlash);
|
|
94
|
+
this.piName.set_value(currentProv);
|
|
95
|
+
this.piProviderName = currentProv;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const bareModels = s.models.map((m) => {
|
|
99
|
+
if (currentProv && m.startsWith(`${currentProv}/`)) {
|
|
100
|
+
return m.slice(currentProv.length + 1);
|
|
101
|
+
}
|
|
102
|
+
const slash = m.indexOf("/");
|
|
103
|
+
return slash >= 0 ? m.slice(slash + 1) : m;
|
|
104
|
+
});
|
|
105
|
+
this.piModels.set_value(bareModels.join("\n"));
|
|
106
|
+
}
|
|
107
|
+
cx.notify();
|
|
108
|
+
} catch {
|
|
109
|
+
/* orchestrator unreachable: the form works without the saved choice */
|
|
110
|
+
}
|
|
111
|
+
});
|
|
26
112
|
this.provider = InputState.new({ placeholder: "proveedor (opcional)", value: p.provider ?? "" });
|
|
27
113
|
this.config = TextareaState.new({ placeholder: "config JSON del agente: sustituye a la anterior" });
|
|
28
114
|
this.config.set_rows(8);
|
|
29
|
-
this.config.focus();
|
|
115
|
+
if (this.advanced) this.config.focus();
|
|
116
|
+
else this.piName.focus();
|
|
30
117
|
return;
|
|
31
118
|
}
|
|
32
119
|
if (this.view === "rebuild") return;
|
|
@@ -36,6 +123,18 @@ export default class BondSettings extends View {
|
|
|
36
123
|
this.github = null; // what the orchestrator has stored: { configured, login }
|
|
37
124
|
this.ghLocal = null; // the host's gh session: { installed, login, ok }
|
|
38
125
|
this.ghBusy = false;
|
|
126
|
+
this.setup = null; // W-P2 «Configuración»: el agregado de GET /setup
|
|
127
|
+
if (this.view === "wizard") {
|
|
128
|
+
// W-P2: the four wizard steps. Every piece of progress lives in the orchestrator
|
|
129
|
+
// (selection, credentials, gh), so Esc never loses anything: it reopens from
|
|
130
|
+
// Ajustes showing the real state (D-W2).
|
|
131
|
+
this.step = Math.min(4, Math.max(1, Number(p.step) || 1));
|
|
132
|
+
this.wizSelection = null; // what the user ticked in step 1; null until they touch it
|
|
133
|
+
this.rbBusy = false;
|
|
134
|
+
this.loadWizard(cx);
|
|
135
|
+
cx.timer.every(2000, (cx) => this.loadWizard(cx));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
39
138
|
this.seenReload = shared(RELOAD_KEY) ?? null;
|
|
40
139
|
this.load(cx);
|
|
41
140
|
cx.timer.every(1000, (cx) => {
|
|
@@ -51,6 +150,24 @@ export default class BondSettings extends View {
|
|
|
51
150
|
load(cx) {
|
|
52
151
|
cx.spawn(async (cx) => {
|
|
53
152
|
try {
|
|
153
|
+
this.creds = (await api("/settings/credentials")) ?? [];
|
|
154
|
+
this.github = (await api("/settings/github")) ?? { configured: false };
|
|
155
|
+
this.setup = (await api("/setup")) ?? null;
|
|
156
|
+
this.loadError = null;
|
|
157
|
+
} catch (e) {
|
|
158
|
+
this.loadError = String(e?.message ?? e);
|
|
159
|
+
}
|
|
160
|
+
this.ghLocal = await this.ghSession();
|
|
161
|
+
cx.notify();
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// W-P2: the wizard re-reads everything it shows (the aggregate, the credential dates,
|
|
166
|
+
// gh), so a credential saved in its own dialog shows up here without reopening.
|
|
167
|
+
loadWizard(cx) {
|
|
168
|
+
cx.spawn(async (cx) => {
|
|
169
|
+
try {
|
|
170
|
+
this.setup = (await api("/setup")) ?? null;
|
|
54
171
|
this.creds = (await api("/settings/credentials")) ?? [];
|
|
55
172
|
this.github = (await api("/settings/github")) ?? { configured: false };
|
|
56
173
|
this.loadError = null;
|
|
@@ -144,11 +261,39 @@ export default class BondSettings extends View {
|
|
|
144
261
|
saveCredential(cx) {
|
|
145
262
|
if (this.busy) return;
|
|
146
263
|
const p = props();
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
264
|
+
let configJson;
|
|
265
|
+
let provider;
|
|
266
|
+
if (this.isPi && !this.advanced) {
|
|
267
|
+
// W-P3: the builder produces the very document PUT /settings/credentials/pi
|
|
268
|
+
// already accepts; nothing goes to the network here — an unreachable LAN URL is
|
|
269
|
+
// saved as entered.
|
|
270
|
+
const built = buildPiModelsDoc({
|
|
271
|
+
name: this.piName.value(),
|
|
272
|
+
baseUrl: this.piUrl.value(),
|
|
273
|
+
apiKey: this.piKey.value(),
|
|
274
|
+
modelsText: this.piModels.value(),
|
|
275
|
+
});
|
|
276
|
+
if (built.error) {
|
|
277
|
+
this.error = built.error;
|
|
278
|
+
cx.notify();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
configJson = built.configJson;
|
|
282
|
+
provider = built.name;
|
|
283
|
+
} else {
|
|
284
|
+
configJson = this.config.value().trim();
|
|
285
|
+
if (!configJson) {
|
|
286
|
+
this.error = "La config no puede estar vacía.";
|
|
287
|
+
cx.notify();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const badJson = validateConfigJson(configJson); // criterion 4: invalid JSON never leaves the dialog
|
|
291
|
+
if (badJson) {
|
|
292
|
+
this.error = badJson;
|
|
293
|
+
cx.notify();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
provider = this.provider.value().trim() || undefined;
|
|
152
297
|
}
|
|
153
298
|
this.busy = true;
|
|
154
299
|
this.error = null;
|
|
@@ -157,8 +302,34 @@ export default class BondSettings extends View {
|
|
|
157
302
|
try {
|
|
158
303
|
await api(`/settings/credentials/${encodeURIComponent(p.agent)}`, {
|
|
159
304
|
method: "PUT",
|
|
160
|
-
body: { config_json: configJson, provider
|
|
305
|
+
body: { config_json: configJson, provider },
|
|
161
306
|
});
|
|
307
|
+
// W-P4: the suggestions model travels in PUT /setup next to the credential. It
|
|
308
|
+
// is only sent when there is something to say (checked models or an explicit
|
|
309
|
+
// pick), so «Renovar» without touching the selector never erases the stored one.
|
|
310
|
+
if (this.isPi && !this.advanced && (this.checkedModels().length > 0 || this.piSuggest !== undefined)) {
|
|
311
|
+
const cur = this.currentSuggest();
|
|
312
|
+
try {
|
|
313
|
+
await api("/setup", { method: "PUT", body: { suggestions_model: cur ? this.piFullId(cur) : null } });
|
|
314
|
+
} catch (e) {
|
|
315
|
+
notify({ title: "Credencial guardada, pero no el modelo de sugerencias", body: String(e?.message ?? e), level: "warning" });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (this.isPi && !this.advanced && (this.checkedModels().length > 0 || this.piDefault !== undefined)) {
|
|
319
|
+
const curDef = this.currentDefault();
|
|
320
|
+
const models = this.checkedModels().map((id) => this.piFullId(id));
|
|
321
|
+
try {
|
|
322
|
+
await api("/setup", {
|
|
323
|
+
method: "PUT",
|
|
324
|
+
body: {
|
|
325
|
+
default_model: curDef ? this.piFullId(curDef) : null,
|
|
326
|
+
models,
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
} catch (e) {
|
|
330
|
+
notify({ title: "Credencial guardada, pero no el modelo por defecto", body: String(e?.message ?? e), level: "warning" });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
162
333
|
notify({ title: `Credencial de ${p.agent} guardada`, level: "success" });
|
|
163
334
|
setShared(RELOAD_KEY, Date.now());
|
|
164
335
|
closeOverlay(p.overlay);
|
|
@@ -170,6 +341,129 @@ export default class BondSettings extends View {
|
|
|
170
341
|
});
|
|
171
342
|
}
|
|
172
343
|
|
|
344
|
+
// ---- W-P4: model multiselector and suggestions pick (pi dialog) -----------------------
|
|
345
|
+
|
|
346
|
+
/** The checked model ids: the textarea lines, same list the builder will serialize. */
|
|
347
|
+
checkedModels() {
|
|
348
|
+
return parseModelIds(this.piModels.value());
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// W-P5: pi habilita modelos como `<provider>/<id>` y supi espera ese id completo;
|
|
352
|
+
// el diálogo trabaja con ids pelados y aquí se prefija con el nombre del provider.
|
|
353
|
+
piFullId(id) {
|
|
354
|
+
const name = this.piName.value().trim() || this.piProviderName || "pi";
|
|
355
|
+
return `${name}/${id}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Current suggestions pick: the explicit one (only while its model stays checked),
|
|
359
|
+
* else the saved one if still checked, else the heuristic proposal
|
|
360
|
+
* (free → cheap → first) over the checked models. */
|
|
361
|
+
currentSuggest() {
|
|
362
|
+
const checked = this.checkedModels();
|
|
363
|
+
if (this.piSuggest !== undefined) {
|
|
364
|
+
if (!this.piSuggest) return null; // «sin sugerencias» explícito
|
|
365
|
+
// W-P5: la elección explícita manda sobre los marcados; si su modelo se desmarcó,
|
|
366
|
+
// se cae al guardado/heurística en vez de quedarse anclado en el primero.
|
|
367
|
+
if (checked.includes(this.piSuggest)) return this.piSuggest;
|
|
368
|
+
}
|
|
369
|
+
if (this.piSavedSuggestions) {
|
|
370
|
+
const saved = checked.find((id) => this.piFullId(id) === this.piSavedSuggestions || id === this.piSavedSuggestions);
|
|
371
|
+
if (saved) return saved;
|
|
372
|
+
}
|
|
373
|
+
return suggestSuggestionModel(checked);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** D-M1: current default working model for pi: explicit choice if still checked,
|
|
377
|
+
* else saved choice if still checked, else heuristic (tools first, else first). */
|
|
378
|
+
currentDefault() {
|
|
379
|
+
const checked = this.checkedModels();
|
|
380
|
+
if (this.piDefault !== undefined) {
|
|
381
|
+
if (!this.piDefault) return null; // «sin modelo por defecto» explícito
|
|
382
|
+
if (checked.includes(this.piDefault)) return this.piDefault;
|
|
383
|
+
}
|
|
384
|
+
if (this.piSavedDefault) {
|
|
385
|
+
const saved = checked.find((id) => this.piFullId(id) === this.piSavedDefault || id === this.piSavedDefault);
|
|
386
|
+
if (saved) return saved;
|
|
387
|
+
}
|
|
388
|
+
return suggestDefaultModel(checked);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Ask the orchestrator to proxy GET {base}/models (POST /setup/models). The provider
|
|
392
|
+
// is never reached from here directly, and a failure is only an aviso: the textarea
|
|
393
|
+
// stays the manual way in (criterion 1).
|
|
394
|
+
loadPiModels(cx) {
|
|
395
|
+
if (this.piListBusy) return;
|
|
396
|
+
const url = normalizeBaseUrl(this.piUrl.value());
|
|
397
|
+
if (!url) {
|
|
398
|
+
this.piListError = "Pon antes una base URL http(s) válida.";
|
|
399
|
+
cx.notify();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
this.piListBusy = true;
|
|
403
|
+
this.piListError = null;
|
|
404
|
+
this.piUrl.set_loading(true);
|
|
405
|
+
cx.notify();
|
|
406
|
+
cx.spawn(async (cx) => {
|
|
407
|
+
try {
|
|
408
|
+
const body = { base_url: url };
|
|
409
|
+
const key = this.piKey.value().trim();
|
|
410
|
+
if (key) body.api_key = key; // only in this request's body; never logged
|
|
411
|
+
const res = await api("/setup/models", { method: "POST", body });
|
|
412
|
+
this.piModelList = Array.isArray(res?.models) ? res.models : [];
|
|
413
|
+
if (this.piModelList.length === 0) this.piListError = "El provider no devolvió modelos: escríbelos a mano.";
|
|
414
|
+
} catch (e) {
|
|
415
|
+
this.piListError = `No se pudieron listar los modelos (${String(e?.message ?? e)}). Escribe los ids a mano, uno por línea:`;
|
|
416
|
+
this.piModelList = null;
|
|
417
|
+
} finally {
|
|
418
|
+
this.piLoadedUrl = url; // same URL blurring again must not nag-reload
|
|
419
|
+
this.piListBusy = false;
|
|
420
|
+
this.piUrl.set_loading(false);
|
|
421
|
+
cx.notify();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// A checkbox adds or removes the id's line in the textarea (source of truth).
|
|
427
|
+
togglePiModel(cx, id) {
|
|
428
|
+
this.piModels.set_value(toggleModelLine(this.piModels.value(), id));
|
|
429
|
+
cx.notify();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
setPiSuggest(cx, id) {
|
|
433
|
+
this.piSuggest = id ?? "";
|
|
434
|
+
cx.notify();
|
|
435
|
+
// W-P5: la elección se persiste al hacer clic (no solo al Guardar), así al reabrir
|
|
436
|
+
// el diálogo sale marcada la misma y no la primera.
|
|
437
|
+
cx.spawn(async () => {
|
|
438
|
+
const cur = this.currentSuggest();
|
|
439
|
+
try {
|
|
440
|
+
await api("/setup", { method: "PUT", body: { suggestions_model: cur ? this.piFullId(cur) : null } });
|
|
441
|
+
} catch {
|
|
442
|
+
/* orquestador no alcanza: Guardar lo reintenta */
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
setPiDefault(cx, id) {
|
|
448
|
+
this.piDefault = id ?? "";
|
|
449
|
+
cx.notify();
|
|
450
|
+
cx.spawn(async () => {
|
|
451
|
+
const cur = this.currentDefault();
|
|
452
|
+
const models = this.checkedModels().map((m) => this.piFullId(m));
|
|
453
|
+
try {
|
|
454
|
+
await api("/setup", {
|
|
455
|
+
method: "PUT",
|
|
456
|
+
body: {
|
|
457
|
+
default_model: cur ? this.piFullId(cur) : null,
|
|
458
|
+
models,
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
} catch {
|
|
462
|
+
/* orquestador no alcanza: Guardar lo reintenta */
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
|
|
173
467
|
rebuild(cx) {
|
|
174
468
|
if (this.busy) return;
|
|
175
469
|
const p = props();
|
|
@@ -189,6 +483,159 @@ export default class BondSettings extends View {
|
|
|
189
483
|
});
|
|
190
484
|
}
|
|
191
485
|
|
|
486
|
+
// ---- W-P2: wizard (D-W1) -----------------------------------------------------------
|
|
487
|
+
|
|
488
|
+
// What the orchestrator is missing; empty when complete. Used by the panel section and
|
|
489
|
+
// by step 4 so the person sees what «Finalizar» would be leaving pending.
|
|
490
|
+
pendingParts(s) {
|
|
491
|
+
if (!s) return ["sin datos del orquestador"];
|
|
492
|
+
const parts = [];
|
|
493
|
+
if (!s.agents_selected.length) parts.push("sin agentes elegidos");
|
|
494
|
+
if (!(s.agents ?? []).some((a) => a.configured)) parts.push("ningún agente con credencial");
|
|
495
|
+
if (!s.github?.configured) parts.push("GitHub");
|
|
496
|
+
if (!s.image?.present) parts.push("imagen del runner");
|
|
497
|
+
return parts;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
selectedAgents() {
|
|
501
|
+
return this.wizSelection ?? (this.setup?.agents_selected ?? []);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
anyCredential() {
|
|
505
|
+
return (this.setup?.agents ?? []).some((a) => a.configured);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
toggleAgent(cx, name) {
|
|
509
|
+
const sel = [...this.selectedAgents()];
|
|
510
|
+
const i = sel.indexOf(name);
|
|
511
|
+
if (i >= 0) sel.splice(i, 1);
|
|
512
|
+
else sel.push(name);
|
|
513
|
+
this.wizSelection = sel;
|
|
514
|
+
this.error = null;
|
|
515
|
+
cx.notify();
|
|
516
|
+
// Criterio 2 del plan W-P2: cada clic guarda (PUT /setup), no esperar a finalizar;
|
|
517
|
+
// cerrar con Esc nunca pierde la selección.
|
|
518
|
+
if (!this.setup || this.busy) return;
|
|
519
|
+
this.busy = true;
|
|
520
|
+
cx.notify();
|
|
521
|
+
cx.spawn(async (cx) => {
|
|
522
|
+
try {
|
|
523
|
+
this.setup = await api("/setup", { method: "PUT", body: { agents_selected: sel } });
|
|
524
|
+
this.wizSelection = null;
|
|
525
|
+
} catch (e) {
|
|
526
|
+
this.error = String(e?.message ?? e);
|
|
527
|
+
}
|
|
528
|
+
this.busy = false;
|
|
529
|
+
cx.notify();
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
wizBack(cx) {
|
|
534
|
+
this.step = Math.max(1, this.step - 1);
|
|
535
|
+
this.error = null;
|
|
536
|
+
cx.notify();
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
wizNext(cx) {
|
|
540
|
+
if (this.busy || !this.setup) return;
|
|
541
|
+
if (this.step === 1) {
|
|
542
|
+
const sel = this.selectedAgents();
|
|
543
|
+
if (sel.length === 0) {
|
|
544
|
+
this.error = "Elige al menos un agente para continuar.";
|
|
545
|
+
cx.notify();
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
// Criterio 2: la selección ya se guardó con cada clic; si alguno falló,
|
|
549
|
+
// se reintenta aquí antes de colar al paso 2.
|
|
550
|
+
if (this.wizSelection === null) {
|
|
551
|
+
this.step = 2;
|
|
552
|
+
this.error = null;
|
|
553
|
+
cx.notify();
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
this.busy = true;
|
|
557
|
+
this.error = null;
|
|
558
|
+
cx.notify();
|
|
559
|
+
cx.spawn(async (cx) => {
|
|
560
|
+
try {
|
|
561
|
+
this.setup = await api("/setup", { method: "PUT", body: { agents_selected: sel } });
|
|
562
|
+
this.wizSelection = null;
|
|
563
|
+
this.step = 2;
|
|
564
|
+
} catch (e) {
|
|
565
|
+
this.error = String(e?.message ?? e);
|
|
566
|
+
}
|
|
567
|
+
this.busy = false;
|
|
568
|
+
cx.notify();
|
|
569
|
+
});
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (this.step === 2 && !this.anyCredential()) {
|
|
573
|
+
// criterion 3: «Finalizar» exige al menos un agente con credencial; no dejar
|
|
574
|
+
// colar eso tan tarde.
|
|
575
|
+
this.error = "Finalizar exige al menos un agente con credencial: guarda una arriba.";
|
|
576
|
+
cx.notify();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
this.step = Math.min(4, this.step + 1);
|
|
580
|
+
this.error = null;
|
|
581
|
+
cx.notify();
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
wizFinish(cx) {
|
|
585
|
+
if (this.busy) return;
|
|
586
|
+
if (!this.anyCredential()) {
|
|
587
|
+
this.error = "Finalizar exige al menos un agente con credencial.";
|
|
588
|
+
cx.notify();
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
this.busy = true;
|
|
592
|
+
this.error = null;
|
|
593
|
+
cx.notify();
|
|
594
|
+
cx.spawn(async (cx) => {
|
|
595
|
+
try {
|
|
596
|
+
// criterion 5: setup_done only via this explicit write (W-P1); the wizard never
|
|
597
|
+
// bothers again, Ajustes keeps showing and editing the state.
|
|
598
|
+
this.setup = await api("/setup", { method: "PUT", body: { setup_done: true } });
|
|
599
|
+
notify({ title: "Configuración guardada", body: "Ajustes siempre muestra y edita el estado.", level: "success" });
|
|
600
|
+
setShared(RELOAD_KEY, Date.now());
|
|
601
|
+
closeOverlay(props().overlay);
|
|
602
|
+
} catch (e) {
|
|
603
|
+
this.error = String(e?.message ?? e);
|
|
604
|
+
this.busy = false;
|
|
605
|
+
cx.notify();
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// Step 4 rebuild (image plan P2): carries the agents chosen in step 1 so the image is
|
|
611
|
+
// built with runner/setup.sh installing exactly those; it keeps the wizard open to
|
|
612
|
+
// finish after.
|
|
613
|
+
wizRebuild(cx) {
|
|
614
|
+
if (this.rbBusy) return;
|
|
615
|
+
const agents = this.selectedAgents();
|
|
616
|
+
if (!agents.length) {
|
|
617
|
+
this.error = "Elige al menos un agente en el paso 1 antes de reconstruir.";
|
|
618
|
+
cx.notify();
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
this.rbBusy = true;
|
|
622
|
+
this.error = null;
|
|
623
|
+
cx.notify();
|
|
624
|
+
cx.spawn(async (cx) => {
|
|
625
|
+
try {
|
|
626
|
+
const res = await api("/system/rebuild", { method: "POST", body: { agents } });
|
|
627
|
+
notify({ title: "Imagen reconstruida", body: String(res?.image ?? ""), level: "success" });
|
|
628
|
+
} catch (e) {
|
|
629
|
+
this.error = String(e?.message ?? e);
|
|
630
|
+
}
|
|
631
|
+
this.rbBusy = false;
|
|
632
|
+
try {
|
|
633
|
+
this.setup = (await api("/setup")) ?? this.setup;
|
|
634
|
+
} catch {}
|
|
635
|
+
cx.notify();
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
|
|
192
639
|
key(e, cx) {
|
|
193
640
|
if (e.key === "escape") {
|
|
194
641
|
closeOverlay(props().overlay);
|
|
@@ -204,6 +651,33 @@ export default class BondSettings extends View {
|
|
|
204
651
|
.cursor_pointer().hover((s) => s.opacity(0.85)).on_click((_e, cx) => action(cx)).child(text);
|
|
205
652
|
}
|
|
206
653
|
|
|
654
|
+
// W-P2: «Configuración» in the Ajustes panel: the aggregated state at a glance, with
|
|
655
|
+
// «Reabrir asistente» always visible (D-W2). Each piece is edited by the sections below.
|
|
656
|
+
setupSection() {
|
|
657
|
+
const t = theme();
|
|
658
|
+
const s = this.setup;
|
|
659
|
+
const pend = this.pendingParts(s);
|
|
660
|
+
const mark = (name) => {
|
|
661
|
+
const a = s?.agents?.find((x) => x.agent === name);
|
|
662
|
+
return `${name}${a?.configured ? " ✓" : " ✗"}`;
|
|
663
|
+
};
|
|
664
|
+
return v_flex().gap(4)
|
|
665
|
+
.child(div().text_size(11).font_semibold().text_color(t.muted).child("CONFIGURACIÓN (W-P2)"))
|
|
666
|
+
.child(div().id("setup-status").text_size(11.5).font_semibold()
|
|
667
|
+
.text_color(!s ? t.dim : s.complete ? t.working : t.blocked)
|
|
668
|
+
.child(!s ? "Sin datos del orquestador" : s.complete ? "Configuración completa" : `Pendiente: ${pend.join(" · ")}`))
|
|
669
|
+
.when(Boolean(s), (el) => el
|
|
670
|
+
.child(div().text_size(11).text_color(t.dim)
|
|
671
|
+
.child(`Agentes elegidos: ${s.agents_selected.length ? s.agents_selected.map(mark).join(" ") : "ninguno"}`))
|
|
672
|
+
.child(div().text_size(11).text_color(t.dim).child(`Asistente: ${s.setup_done ? "terminado" : "sin terminar"}`)))
|
|
673
|
+
.child(h_flex().pt(2)
|
|
674
|
+
.child(this.button("wiz-reopen", "Reabrir asistente", false, () => openOverlay({
|
|
675
|
+
mod: "bond-settings", kind: "dialog", modal: true, width: 560, height: 0.92,
|
|
676
|
+
props: { view: "wizard", step: 1 },
|
|
677
|
+
}))))
|
|
678
|
+
.child(div().text_size(11).text_color(t.dim).child("Cada pieza se edita abajo: gh, credenciales y rebuild."));
|
|
679
|
+
}
|
|
680
|
+
|
|
207
681
|
renderPanel() {
|
|
208
682
|
const t = theme();
|
|
209
683
|
const row = (c) => h_flex().id(`cred-${c.agent}`).gap(8).items_center().py(4).font_family("JetBrains Mono")
|
|
@@ -211,7 +685,7 @@ export default class BondSettings extends View {
|
|
|
211
685
|
.child(div().flex_1().text_size(UI.text.small).text_color(c.configured ? t.working : t.dim).truncate()
|
|
212
686
|
.child(c.configured ? `credencial${c.provider ? ` · ${c.provider}` : ""}` : "sin credencial"))
|
|
213
687
|
.child(this.button(`renew-${c.agent}`, c.configured ? "Renovar" : "Iniciar", false, () => openOverlay({
|
|
214
|
-
mod: "bond-settings", kind: "dialog", modal: true, width: 480,
|
|
688
|
+
mod: "bond-settings", kind: "dialog", modal: true, width: 480, height: 0.92,
|
|
215
689
|
props: { view: "credential", agent: c.agent, provider: c.provider ?? "" },
|
|
216
690
|
})));
|
|
217
691
|
return v_flex().id("bond-settings").size_full().p(10).gap(8).bg(t.chrome).text_color(t.foreground).font_family("JetBrains Mono").overflow_y_scrollbar()
|
|
@@ -220,6 +694,7 @@ export default class BondSettings extends View {
|
|
|
220
694
|
.child(div().id("settings-close").w(24).h(22).rounded(UI.radius).flex().items_center().justify_center()
|
|
221
695
|
.text_color(t.muted).cursor_pointer().hover((s) => s.bg(t.hover).text_color(t.foreground))
|
|
222
696
|
.on_click(() => run("layout.toggle", { id: "settings" })).child("✕")))
|
|
697
|
+
.child(this.setupSection())
|
|
223
698
|
.child(this.githubSection())
|
|
224
699
|
.child(div().text_size(UI.text.small).font_semibold().text_color(t.muted).child("CREDENCIALES DE AGENTES (D7)"))
|
|
225
700
|
.when(Boolean(this.loadError), (el) => el.child(div().text_size(UI.text.small).text_color(t.blocked).child(`API: ${this.loadError}`)))
|
|
@@ -233,20 +708,222 @@ export default class BondSettings extends View {
|
|
|
233
708
|
.child(div().text_size(UI.text.small).text_color(t.dim).child("El rebuild no toca ni renueva las credenciales."));
|
|
234
709
|
}
|
|
235
710
|
|
|
236
|
-
renderDialog(title, body, actions) {
|
|
711
|
+
renderDialog(title, body, actions, fit = false) {
|
|
237
712
|
const t = theme();
|
|
713
|
+
// W-P5: con `fit` el diálogo ocupa la altura acotada del overlay (height: 0.92)
|
|
714
|
+
// y el cuerpo rota dentro de ella; sin `fit`, tope de 520 px y botones fijos.
|
|
715
|
+
const bodyWrap = fit
|
|
716
|
+
? v_flex().flex_1().min_h(0).overflow_y_scrollbar()
|
|
717
|
+
: v_flex().max_h(520).overflow_y_scrollbar();
|
|
238
718
|
return v_flex().id("bond-settings-dialog").track_focus(this.handle).on_key_down((e, cx) => this.key(e, cx))
|
|
239
719
|
.w_full().p(18).gap(10).bg(t.popover).rounded(UI.radiusLg).border_1().border_color(t.border).text_color(t.foreground).font_family("JetBrains Mono")
|
|
720
|
+
.when(fit, (el) => el.h_full())
|
|
240
721
|
.child(h_flex().items_center().child(div().flex_1().text_size(UI.text.title + 2).font_semibold().child(title))
|
|
241
722
|
.child(div().text_size(UI.text.small).text_color(t.dim).child("Esc")))
|
|
242
|
-
.children(body)
|
|
723
|
+
.child(bodyWrap.gap(10).children(body))
|
|
243
724
|
.when(Boolean(this.error), (el) => el.child(div().text_size(UI.text.small).text_color(t.blocked).child(this.error)))
|
|
244
725
|
.child(h_flex().pt(8).gap(8).justify_end().children(actions));
|
|
245
726
|
}
|
|
246
727
|
|
|
728
|
+
// ---- W-P2: the wizard itself ---------------------------------------------------------
|
|
729
|
+
|
|
730
|
+
wizardStepBody() {
|
|
731
|
+
const t = theme();
|
|
732
|
+
if (!this.setup) return div().text_size(UI.text.small).text_color(t.muted).child("Comprobando estado de la configuración…");
|
|
733
|
+
if (this.step === 1) {
|
|
734
|
+
const sel = this.selectedAgents();
|
|
735
|
+
const rows = (this.setup.agents ?? []).map((a) =>
|
|
736
|
+
h_flex().id(`wiz-agent-${a.agent}`).gap(8).items_center().px(4).py(4).rounded(UI.radius).cursor_pointer()
|
|
737
|
+
.hover((s) => s.bg(t.hover))
|
|
738
|
+
.on_click((_e, cx) => this.toggleAgent(cx, a.agent))
|
|
739
|
+
.child(div().w(30).text_size(UI.text.body).text_color(sel.includes(a.agent) ? t.working : t.dim)
|
|
740
|
+
.child(sel.includes(a.agent) ? "[x]" : "[ ]"))
|
|
741
|
+
.child(div().text_size(UI.text.body).text_color(t.foreground).child(a.agent)));
|
|
742
|
+
return v_flex().gap(6)
|
|
743
|
+
.child(div().text_size(11.5).text_color(t.muted).child("Con qué agentes vas a trabajar. La imagen del runner soporta estos cinco; los demás entrarán cuando la imagen los soporte."))
|
|
744
|
+
.children(rows)
|
|
745
|
+
.child(div().text_size(11).text_color(t.dim).child("Aquí solo se guarda la selección; las credenciales son en el siguiente paso."));
|
|
746
|
+
}
|
|
747
|
+
if (this.step === 2) {
|
|
748
|
+
const s = this.setup;
|
|
749
|
+
const rows = (s.agents_selected ?? []).map((name) => {
|
|
750
|
+
const state = (s.agents ?? []).find((a) => a.agent === name);
|
|
751
|
+
const c = this.creds.find((x) => x.agent === name);
|
|
752
|
+
const configured = Boolean(state?.configured);
|
|
753
|
+
const bits = [c?.provider, c?.updated_at ? String(c.updated_at).slice(0, 10) : null].filter(Boolean);
|
|
754
|
+
const status = configured ? ["credencial", ...bits].join(" · ") : "sin credencial";
|
|
755
|
+
return h_flex().id(`wiz-cred-row-${name}`).gap(8).items_center().py(4).font_family("JetBrains Mono")
|
|
756
|
+
.child(div().w(70).text_size(UI.text.body).text_color(t.foreground).child(name))
|
|
757
|
+
.child(div().flex_1().text_size(UI.text.small).text_color(configured ? t.working : t.dim).truncate().child(status))
|
|
758
|
+
.child(this.button(`wiz-cred-${name}`, configured ? "Renovar" : "Iniciar", false, () => openOverlay({
|
|
759
|
+
mod: "bond-settings", kind: "dialog", modal: true, width: 480, height: 0.92,
|
|
760
|
+
props: { view: "credential", agent: name, provider: c?.provider ?? "" },
|
|
761
|
+
})));
|
|
762
|
+
});
|
|
763
|
+
return v_flex().gap(6)
|
|
764
|
+
.child(div().text_size(11.5).text_color(t.muted).child("Inicia sesión con cada agente y pega aquí su config (D7). Hace falta al menos un agente con credencial para poder finalizar."))
|
|
765
|
+
.child(div().text_size(11).text_color(t.dim).child("pi no necesita escribir JSON: «Iniciar» abre el formulario «modelo local / OpenAI-compatible» (nombre, URL, clave opcional); al salir del campo URL se cargan los modelos del provider para marcarlos con checkboxes, y entre ellos se elige el de sugerencias. El paquete supi aún no está en la imagen del runner (P2 del plan de la imagen, pendiente): la elección se guarda y queda inactiva hasta que lo incluya. La config completa se sigue pudiendo pegar en «modo avanzado»."))
|
|
766
|
+
.when(rows.length === 0, (el) => el.child(div().text_size(UI.text.small).text_color(t.dim).child("No hay agentes elegidos: vuelve atrás y elige al menos uno.")))
|
|
767
|
+
.children(rows)
|
|
768
|
+
.when(!this.anyCredential(), (el) => el.child(div().text_size(11).text_color(t.blocked).child("Finalizar exige al menos un agente con credencial.")));
|
|
769
|
+
}
|
|
770
|
+
if (this.step === 3) {
|
|
771
|
+
return v_flex().gap(6)
|
|
772
|
+
.child(this.githubSection())
|
|
773
|
+
.child(div().text_size(11).text_color(t.dim).child("Sin GitHub no se podrán clonar los repos al lanzar tickets; puedes conectarlo luego desde Ajustes."));
|
|
774
|
+
}
|
|
775
|
+
const img = this.setup.image ?? {};
|
|
776
|
+
return v_flex().gap(6)
|
|
777
|
+
.child(div().text_size(11.5).text_color(t.muted).child("La imagen del runner se construye con «Rebuild», con las versiones fijadas de bond, hc y los agentes elegidos en el paso 1."))
|
|
778
|
+
.child(div().id("wiz-image-state").text_size(UI.text.small).font_semibold()
|
|
779
|
+
.text_color(img.present ? t.working : t.blocked)
|
|
780
|
+
.child(img.present ? `imagen presente${img.agents?.length ? ` · agentes en la imagen: ${img.agents.join(", ")}` : ""}` : "imagen ausente: «Rebuild» la construye"))
|
|
781
|
+
.child(div().text_size(11).text_color(t.dim)
|
|
782
|
+
.child(this.selectedAgents().length
|
|
783
|
+
? `Rebuild instalará en la imagen: ${this.selectedAgents().join(", ")} (más gh y la CLI de Azure DevOps).`
|
|
784
|
+
: "Aún no has elegido agentes: «Rebuild» construiría la imagen mínima (pi)."))
|
|
785
|
+
.child(h_flex().gap(6)
|
|
786
|
+
.child(this.button("wiz-rebuild", this.rbBusy ? "Reconstruyendo…" : "Rebuild", false, (cx) => this.wizRebuild(cx))))
|
|
787
|
+
.when(!this.setup.complete, (el) => el.child(div().text_size(11).text_color(t.dim).child(`Al finalizar quedará pendiente: ${this.pendingParts(this.setup).join(" · ")}. Podrás arreglarlo desde Ajustes.`)));
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
renderWizard() {
|
|
791
|
+
const t = theme();
|
|
792
|
+
const titles = ["agentes", "credenciales", "GitHub", "imagen"];
|
|
793
|
+
const steps = h_flex().gap(10).items_center()
|
|
794
|
+
.children(titles.map((title, i) => div().id(`wiz-step-${i + 1}`).text_size(UI.text.tiny).font_semibold()
|
|
795
|
+
.text_color(this.step === i + 1 ? t.accent : t.dim).child(`${i + 1} ${title}`)));
|
|
796
|
+
const actions = [];
|
|
797
|
+
if (this.step > 1) actions.push(this.button("wiz-back", "Atrás", false, (cx) => this.wizBack(cx)));
|
|
798
|
+
actions.push(this.step < 4
|
|
799
|
+
? this.button("wiz-next", this.busy && this.step === 1 ? "Guardando…" : "Siguiente", true, (cx) => this.wizNext(cx))
|
|
800
|
+
: this.button("wiz-finish", this.busy ? "Guardando…" : "Finalizar", true, (cx) => this.wizFinish(cx)));
|
|
801
|
+
return v_flex().id("bond-wizard").track_focus(this.handle).on_key_down((e, cx) => this.key(e, cx))
|
|
802
|
+
.w_full().h_full().p(18).gap(10).bg(t.popover).rounded(UI.radiusLg).border_1().border_color(t.border).text_color(t.foreground).font_family("JetBrains Mono")
|
|
803
|
+
.child(h_flex().items_center().child(div().flex_1().text_size(UI.text.title + 2).font_semibold().child("Asistente de configuración"))
|
|
804
|
+
.child(div().text_size(UI.text.small).text_color(t.dim).child(`PASO ${this.step} DE 4 · Esc`)))
|
|
805
|
+
.child(steps)
|
|
806
|
+
.child(v_flex().flex_1().min_h(0).overflow_y_scrollbar().gap(10).child(this.wizardStepBody()))
|
|
807
|
+
.when(Boolean(this.loadError), (el) => el.child(div().text_size(UI.text.small).text_color(t.blocked).child(`API: ${this.loadError}`)))
|
|
808
|
+
.when(Boolean(this.error), (el) => el.child(div().text_size(UI.text.small).text_color(t.blocked).child(this.error)))
|
|
809
|
+
.child(h_flex().pt(8).gap(8).justify_end().children(actions))
|
|
810
|
+
.child(div().text_size(UI.text.tiny).text_color(t.dim).child("Esc cierra sin perder lo guardado; «Reabrir asistente» en Ajustes abre de nuevo cuando quieras."));
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// W-P3: the pi credential dialog, built from the four fields (pi-models.js makes the
|
|
814
|
+
// models.json); «modo avanzado» swaps to the full-JSON paste from W-P2.
|
|
815
|
+
renderPiCredential(p) {
|
|
816
|
+
const t = theme();
|
|
817
|
+
const label = (txt) => div().text_size(11).font_semibold().text_color(t.muted).child(txt);
|
|
818
|
+
const input = (state) => Input.new(state).h(32).px(10).rounded(8).border_1().border_color(t.input).bg(t.background).text_size(12.5);
|
|
819
|
+
if (this.advanced) {
|
|
820
|
+
return this.renderDialog(`Credencial de ${p.agent}`, [
|
|
821
|
+
div().text_size(11.5).text_color(t.dim).child("Modo avanzado: pega el models.json completo del agente (D7). Se guarda en el orquestador y llega a cada run por stdin; no va en la imagen."),
|
|
822
|
+
Input.new(this.provider).h(32).px(10).rounded(8).border_1().border_color(t.input).bg(t.background).text_size(12.5),
|
|
823
|
+
Textarea.new(this.config).h(150).p(8).rounded(8).border_1().border_color(t.input).bg(t.background).text_size(12),
|
|
824
|
+
], [
|
|
825
|
+
this.button("cred-back", "Volver", false, () => closeOverlay(p.overlay)),
|
|
826
|
+
this.button("cred-mode", "Usar el formulario", false, (cx) => this.toggleMode(cx)),
|
|
827
|
+
this.button("cred-save", this.busy ? "Guardando…" : "Guardar", true, (cx) => this.saveCredential(cx)),
|
|
828
|
+
], true);
|
|
829
|
+
}
|
|
830
|
+
return this.renderDialog("Credencial de pi · modelo local / OpenAI-compatible", [
|
|
831
|
+
div().text_size(11.5).text_color(t.dim).child("Pi se conecta a un endpoint compatible (Ollama, LM Studio, vLLM, una LAN…). El wizard monta el models.json por ti; no se comprueba la red: se guarda tal cual. La lista de modelos se carga sola al salir del campo URL."),
|
|
832
|
+
label("NOMBRE DEL PROVIDER"),
|
|
833
|
+
input(this.piName),
|
|
834
|
+
label("BASE URL"),
|
|
835
|
+
input(this.piUrl),
|
|
836
|
+
div().text_size(11).text_color(t.dim).child("Si no le pones ruta, se añade /v1 (donde suelen servir estos servidores)."),
|
|
837
|
+
label("API KEY (OPCIONAL)"),
|
|
838
|
+
input(this.piKey),
|
|
839
|
+
div().text_size(11).text_color(t.dim).child("pi exige que el provider lleve una clave aunque el servidor no la compruebe: si la tuya no pide, escribe «none». Con una URL vacía, rellénala siempre."),
|
|
840
|
+
// W-P5: no «Cargar» button and no duplicated MODELOS field: the list loads on the
|
|
841
|
+
// URL blur (tiny animated line while waiting) and the checkboxes are the only UI.
|
|
842
|
+
...(this.piListBusy
|
|
843
|
+
? [h_flex().id("pi-loading").gap(6).items_center().child(div().text_size(11).text_color(t.working)
|
|
844
|
+
.child(`Cargando modelos del provider ${"·".repeat(this.piSpin + 1)}`))]
|
|
845
|
+
: []),
|
|
846
|
+
// Criterio 1: with an unreachable URL the only fallback is this compact manual field.
|
|
847
|
+
...(this.piListError
|
|
848
|
+
? [div().id("pi-list-error").text_size(11).text_color(t.blocked).child(this.piListError),
|
|
849
|
+
label("MODELOS (IDS, UNO POR LÍNEA)"),
|
|
850
|
+
Textarea.new(this.piModels).h(72).p(8).rounded(8).border_1().border_color(t.input).bg(t.background).text_size(12)]
|
|
851
|
+
: []),
|
|
852
|
+
...(this.piModelList
|
|
853
|
+
? [div().text_size(11).text_color(t.dim)
|
|
854
|
+
.child(`${this.piModelList.length} del provider: marca los que vayas a usar; solo esos entran en el models.json.`),
|
|
855
|
+
...[...new Set([...this.piModelList, ...this.checkedModels()])].map((id) => {
|
|
856
|
+
const on = this.checkedModels().includes(id);
|
|
857
|
+
return h_flex().id(`pi-model-${slug(id)}`).gap(8).items_center().px(4).py(2).rounded(UI.radius).cursor_pointer()
|
|
858
|
+
.hover((s) => s.bg(t.hover))
|
|
859
|
+
.on_click((_e, cx) => this.togglePiModel(cx, id))
|
|
860
|
+
.child(div().w(34).text_size(UI.text.body).text_color(on ? t.working : t.dim).child(on ? "[x]" : "[ ]"))
|
|
861
|
+
.child(div().flex_1().text_size(UI.text.small).text_color(t.foreground).truncate().child(id));
|
|
862
|
+
})]
|
|
863
|
+
: []),
|
|
864
|
+
// Elegir modelo de trabajo por defecto y «para sugerencias» solo entre los marcados.
|
|
865
|
+
...(this.checkedModels().length > 0 ? [this.piDefaultModelArea(), this.piSuggestionsArea()] : []),
|
|
866
|
+
], [
|
|
867
|
+
this.button("cred-back", "Volver", false, () => closeOverlay(p.overlay)),
|
|
868
|
+
this.button("cred-mode", "Modo avanzado: pegar JSON", false, (cx) => this.toggleMode(cx)),
|
|
869
|
+
this.button("cred-save", this.busy ? "Guardando…" : "Guardar", true, (cx) => this.saveCredential(cx)),
|
|
870
|
+
], true);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
toggleMode(cx) {
|
|
874
|
+
this.advanced = !this.advanced;
|
|
875
|
+
this.error = null;
|
|
876
|
+
cx.notify();
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** D-M1: «modelo por defecto» se elige entre los marcados; primero con tools si se puede. */
|
|
880
|
+
piDefaultModelArea() {
|
|
881
|
+
const t = theme();
|
|
882
|
+
const cur = this.currentDefault();
|
|
883
|
+
const row = (domId, value, text) => {
|
|
884
|
+
const on = cur === value;
|
|
885
|
+
return h_flex().id(domId).gap(8).items_center().px(4).py(2).rounded(UI.radius).cursor_pointer()
|
|
886
|
+
.hover((s) => s.bg(t.hover))
|
|
887
|
+
.on_click((_e, cx) => this.setPiDefault(cx, value))
|
|
888
|
+
.child(div().w(34).text_size(UI.text.body).text_color(on ? t.working : t.dim).child(on ? "[•]" : "[ ]"))
|
|
889
|
+
.child(div().flex_1().text_size(UI.text.small).text_color(t.foreground).truncate().child(text));
|
|
890
|
+
};
|
|
891
|
+
return v_flex().gap(2)
|
|
892
|
+
.child(div().text_size(11).font_semibold().text_color(t.muted).child("MODELO DE TRABAJO POR DEFECTO"))
|
|
893
|
+
.children(this.checkedModels().map((id) =>
|
|
894
|
+
row(`pi-def-${slug(id)}`, id, id + (this.piDefault === undefined && cur === id ? " · sugerido" : ""))))
|
|
895
|
+
.child(row("pi-def-none", null, "sin modelo por defecto"))
|
|
896
|
+
.child(div().text_size(11).text_color(t.dim)
|
|
897
|
+
.child("Se usa en los runs de tickets que no especifiquen modelo. Si el ticket trae uno explícito, manda el del ticket."));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** W-P4: «para sugerencias» se elige solo entre los marcados; la heurística propone
|
|
901
|
+
* cuando nadie ha tocado todavía, y «sin sugerencias» guarda null. */
|
|
902
|
+
piSuggestionsArea() {
|
|
903
|
+
const t = theme();
|
|
904
|
+
const cur = this.currentSuggest();
|
|
905
|
+
const row = (domId, value, text) => {
|
|
906
|
+
const on = cur === value;
|
|
907
|
+
return h_flex().id(domId).gap(8).items_center().px(4).py(2).rounded(UI.radius).cursor_pointer()
|
|
908
|
+
.hover((s) => s.bg(t.hover))
|
|
909
|
+
.on_click((_e, cx) => this.setPiSuggest(cx, value))
|
|
910
|
+
.child(div().w(34).text_size(UI.text.body).text_color(on ? t.working : t.dim).child(on ? "[•]" : "[ ]"))
|
|
911
|
+
.child(div().flex_1().text_size(UI.text.small).text_color(t.foreground).truncate().child(text));
|
|
912
|
+
};
|
|
913
|
+
return v_flex().gap(2)
|
|
914
|
+
.child(div().text_size(11).font_semibold().text_color(t.muted).child("MODELO PARA SUGERENCIAS"))
|
|
915
|
+
.children(this.checkedModels().map((id) =>
|
|
916
|
+
row(`pi-sug-${slug(id)}`, id, id + (this.piSuggest === undefined && cur === id ? " · sugerido" : ""))))
|
|
917
|
+
.child(row("pi-sug-none", null, "sin sugerencias"))
|
|
918
|
+
.child(div().text_size(11).text_color(t.dim)
|
|
919
|
+
.child("Lo usa el paquete supi dentro del contenedor. Mientras la imagen del runner no lo incluya (P2 del plan de la imagen, pendiente), la elección se guarda y queda inactiva."));
|
|
920
|
+
}
|
|
921
|
+
|
|
247
922
|
render() {
|
|
248
923
|
const t = theme();
|
|
249
924
|
const p = props() ?? {};
|
|
925
|
+
if (this.view === "wizard") return this.renderWizard();
|
|
926
|
+
if (this.view === "credential" && this.isPi) return this.renderPiCredential(p);
|
|
250
927
|
if (this.view === "credential") {
|
|
251
928
|
return this.renderDialog(`Credencial de ${p.agent}`, [
|
|
252
929
|
div().text_size(11.5).text_color(t.dim).child("Pega la config del agente tras iniciar sesión (D7). Se guarda en el orquestador y llega a cada run por stdin; no va en la imagen."),
|
|
@@ -255,7 +932,7 @@ export default class BondSettings extends View {
|
|
|
255
932
|
], [
|
|
256
933
|
this.button("cred-back", "Volver", false, () => closeOverlay(p.overlay)),
|
|
257
934
|
this.button("cred-save", this.busy ? "Guardando…" : "Guardar", true, (cx) => this.saveCredential(cx)),
|
|
258
|
-
]);
|
|
935
|
+
], true);
|
|
259
936
|
}
|
|
260
937
|
if (this.view === "rebuild") {
|
|
261
938
|
return this.renderDialog("¿Reconstruir la imagen del runner?", [
|