opencode-azure-devops-pr-review 0.4.1 → 0.4.3
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/CHANGELOG.md +193 -0
- package/README.md +209 -47
- package/package.json +11 -3
- package/src/attribution.mjs +16 -2
- package/src/azure.mjs +12 -2
- package/src/comment-work.mjs +5 -3
- package/src/config.mjs +66 -14
- package/src/runtime.mjs +81 -22
- package/src/session.mjs +13 -5
- package/src/setup.mjs +998 -86
- package/src/tui-model.mjs +566 -0
- package/src/tui-setup.mjs +344 -0
- package/src/tui-view.jsx +678 -0
- package/src/tui.js +989 -0
package/src/tui.js
ADDED
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
// Generated from tui-view.jsx by scripts/build-tui.mjs (@babel/core 7.29.7, babel-preset-solid 1.9.16; Solid universal renderer from @opentui/solid).
|
|
2
|
+
// Do not edit this file: change tui-view.jsx and run "npm run build:tui". "npm run check" fails when the two differ.
|
|
3
|
+
import { use as _$use } from "@opentui/solid";
|
|
4
|
+
import { createTextNode as _$createTextNode } from "@opentui/solid";
|
|
5
|
+
import { insertNode as _$insertNode } from "@opentui/solid";
|
|
6
|
+
import { createComponent as _$createComponent } from "@opentui/solid";
|
|
7
|
+
import { effect as _$effect } from "@opentui/solid";
|
|
8
|
+
import { insert as _$insert } from "@opentui/solid";
|
|
9
|
+
import { memo as _$memo } from "@opentui/solid";
|
|
10
|
+
import { setProp as _$setProp } from "@opentui/solid";
|
|
11
|
+
import { createElement as _$createElement } from "@opentui/solid";
|
|
12
|
+
// AZPR's part in OpenCode's terminal UI: a panel beside the conversation, and the dialogs of /pr-setup.
|
|
13
|
+
//
|
|
14
|
+
// Its upper part lists the sessions of the run under way or last ended, each a row that opens
|
|
15
|
+
// that session when it is clicked; its lower part shows the newest report or comment preview as
|
|
16
|
+
// rendered Markdown. A run that starts, and a report or preview that arrives, opens the panel in
|
|
17
|
+
// the session on screen and leaves the keyboard with the prompt; with the setting
|
|
18
|
+
// terminalPanel: manual it opens only with /pr-panel, its one command.
|
|
19
|
+
//
|
|
20
|
+
// The panel only reads: AZPR's own notices in the conversation, the report queued to a review
|
|
21
|
+
// session, and the sessions' `metadata.azpr` (src/tui-model.mjs works out what to show). It sends
|
|
22
|
+
// no prompt, runs no command of the server part and reads no settings file: the server part writes
|
|
23
|
+
// that setting into the metadata of its notices.
|
|
24
|
+
//
|
|
25
|
+
// The dialogs of /pr-setup ask for AZPR's settings (src/tui-setup.mjs says what and in which order) and
|
|
26
|
+
// hand every answer to the server part over the plugin's RPC. They read and write no file and make no
|
|
27
|
+
// request to Azure DevOps; a token is typed into a field that shows nothing of it, and is kept nowhere.
|
|
28
|
+
//
|
|
29
|
+
// This is the source. OpenCode loads src/tui.js, which scripts/build-tui.mjs compiles from it:
|
|
30
|
+
// OpenCode 2.3.0 compiles no JSX of a package it installed, so the package carries the result.
|
|
31
|
+
import { For, Show, createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js";
|
|
32
|
+
import { MouseButton, SyntaxStyle, TextAttributes } from "@opentui/core";
|
|
33
|
+
import { PANEL, buildPanel, conversationOf, createReader, opensPanel } from "./tui-model.mjs";
|
|
34
|
+
import { SETUP_RPC, createSetup, isSetupNotice } from "./tui-setup.mjs";
|
|
35
|
+
|
|
36
|
+
// Short enough for one line of a toast, which the host wraps at about fifty characters.
|
|
37
|
+
const READY = "AZPR: report or preview ready. /pr-panel shows it.";
|
|
38
|
+
|
|
39
|
+
/** The first of these theme tokens that this OpenCode defines; their names have changed between releases. */
|
|
40
|
+
const token = (theme, ...paths) => {
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
const value = path.split(".").reduce((node, name) => node?.[name], theme);
|
|
43
|
+
if (value !== undefined) return value;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const colors = theme => {
|
|
47
|
+
const base = token(theme, "text.base", "text.default");
|
|
48
|
+
return {
|
|
49
|
+
base,
|
|
50
|
+
muted: token(theme, "text.muted", "text.subdued") ?? base,
|
|
51
|
+
running: token(theme, "text.feedback.info.base") ?? base,
|
|
52
|
+
failed: token(theme, "text.feedback.error.base") ?? base,
|
|
53
|
+
done: token(theme, "text.feedback.success.base") ?? base,
|
|
54
|
+
link: token(theme, "markdown.link") ?? base,
|
|
55
|
+
text: token(theme, "markdown.text") ?? base,
|
|
56
|
+
surface: token(theme, "background.raised.base"),
|
|
57
|
+
hover: token(theme, "background.raised.high")
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Markdown colors from the theme's own tokens, for the renderer of this TUI. */
|
|
62
|
+
function markdownStyle(context) {
|
|
63
|
+
const theme = context.theme;
|
|
64
|
+
const base = token(theme, "text.base", "text.default");
|
|
65
|
+
const of = name => token(theme, `markdown.${name}`) ?? base;
|
|
66
|
+
const styles = {
|
|
67
|
+
default: {
|
|
68
|
+
fg: of("text")
|
|
69
|
+
},
|
|
70
|
+
"markup.heading": {
|
|
71
|
+
fg: of("heading"),
|
|
72
|
+
bold: true
|
|
73
|
+
},
|
|
74
|
+
"markup.strong": {
|
|
75
|
+
fg: of("strong"),
|
|
76
|
+
bold: true
|
|
77
|
+
},
|
|
78
|
+
"markup.bold": {
|
|
79
|
+
fg: of("strong"),
|
|
80
|
+
bold: true
|
|
81
|
+
},
|
|
82
|
+
"markup.italic": {
|
|
83
|
+
fg: of("emphasis"),
|
|
84
|
+
italic: true
|
|
85
|
+
},
|
|
86
|
+
"markup.strikethrough": {
|
|
87
|
+
fg: token(theme, "text.muted", "text.subdued") ?? base,
|
|
88
|
+
dim: true
|
|
89
|
+
},
|
|
90
|
+
"markup.raw": {
|
|
91
|
+
fg: of("code")
|
|
92
|
+
},
|
|
93
|
+
"markup.raw.inline": {
|
|
94
|
+
fg: of("code")
|
|
95
|
+
},
|
|
96
|
+
"markup.raw.block": {
|
|
97
|
+
fg: of("codeBlock")
|
|
98
|
+
},
|
|
99
|
+
"markup.link": {
|
|
100
|
+
fg: of("link"),
|
|
101
|
+
underline: true
|
|
102
|
+
},
|
|
103
|
+
"markup.link.label": {
|
|
104
|
+
fg: of("linkText"),
|
|
105
|
+
underline: true
|
|
106
|
+
},
|
|
107
|
+
"markup.link.url": {
|
|
108
|
+
fg: of("link"),
|
|
109
|
+
underline: true
|
|
110
|
+
},
|
|
111
|
+
"markup.list": {
|
|
112
|
+
fg: of("listItem")
|
|
113
|
+
},
|
|
114
|
+
"markup.quote": {
|
|
115
|
+
fg: of("blockQuote"),
|
|
116
|
+
italic: true
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
for (const level of [1, 2, 3, 4, 5, 6]) styles[`markup.heading.${level}`] = {
|
|
120
|
+
fg: of("heading"),
|
|
121
|
+
bold: true
|
|
122
|
+
};
|
|
123
|
+
return SyntaxStyle.fromStyles(styles, context.renderer.nativeScene);
|
|
124
|
+
}
|
|
125
|
+
function Row(props) {
|
|
126
|
+
const [hover, setHover] = createSignal(false);
|
|
127
|
+
const mark = () => props.row.state === "running" ? props.colors.running : props.row.state === "failed" ? props.colors.failed : props.colors.done;
|
|
128
|
+
return (() => {
|
|
129
|
+
var _el$ = _$createElement("box"),
|
|
130
|
+
_el$2 = _$createElement("text"),
|
|
131
|
+
_el$3 = _$createElement("text"),
|
|
132
|
+
_el$4 = _$createElement("text");
|
|
133
|
+
_$insertNode(_el$, _el$2);
|
|
134
|
+
_$insertNode(_el$, _el$3);
|
|
135
|
+
_$insertNode(_el$, _el$4);
|
|
136
|
+
_$setProp(_el$, "flexDirection", "row");
|
|
137
|
+
_$setProp(_el$, "gap", 1);
|
|
138
|
+
_$setProp(_el$, "onMouseOver", () => setHover(true));
|
|
139
|
+
_$setProp(_el$, "onMouseOut", () => setHover(false));
|
|
140
|
+
_$setProp(_el$, "onMouseUp", event => {
|
|
141
|
+
if (event.button !== MouseButton.LEFT) return;
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
props.open(props.row.id);
|
|
144
|
+
});
|
|
145
|
+
_$setProp(_el$2, "flexShrink", 0);
|
|
146
|
+
_$setProp(_el$2, "selectable", false);
|
|
147
|
+
_$insert(_el$2, () => props.row.state === "running" ? "●" : "○");
|
|
148
|
+
_$setProp(_el$3, "flexShrink", 0);
|
|
149
|
+
_$setProp(_el$3, "selectable", false);
|
|
150
|
+
_$insert(_el$3, () => props.row.label, null);
|
|
151
|
+
_$insert(_el$3, () => props.row.report ? " (report)" : "", null);
|
|
152
|
+
_$setProp(_el$4, "flexShrink", 0);
|
|
153
|
+
_$setProp(_el$4, "selectable", false);
|
|
154
|
+
_$insert(_el$4, () => props.row.state);
|
|
155
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
156
|
+
get when() {
|
|
157
|
+
return props.wide;
|
|
158
|
+
},
|
|
159
|
+
get children() {
|
|
160
|
+
var _el$5 = _$createElement("text");
|
|
161
|
+
_$setProp(_el$5, "wrapMode", "none");
|
|
162
|
+
_$setProp(_el$5, "selectable", false);
|
|
163
|
+
_$insert(_el$5, () => props.row.id);
|
|
164
|
+
_$effect(_p$ => {
|
|
165
|
+
var _v$ = props.colors.link,
|
|
166
|
+
_v$2 = TextAttributes.UNDERLINE;
|
|
167
|
+
_v$ !== _p$.e && (_p$.e = _$setProp(_el$5, "fg", _v$, _p$.e));
|
|
168
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp(_el$5, "attributes", _v$2, _p$.t));
|
|
169
|
+
return _p$;
|
|
170
|
+
}, {
|
|
171
|
+
e: undefined,
|
|
172
|
+
t: undefined
|
|
173
|
+
});
|
|
174
|
+
return _el$5;
|
|
175
|
+
}
|
|
176
|
+
}), null);
|
|
177
|
+
_$effect(_p$ => {
|
|
178
|
+
var _v$3 = hover() ? props.colors.hover : undefined,
|
|
179
|
+
_v$4 = mark(),
|
|
180
|
+
_v$5 = props.colors.base,
|
|
181
|
+
_v$6 = props.colors.muted;
|
|
182
|
+
_v$3 !== _p$.e && (_p$.e = _$setProp(_el$, "backgroundColor", _v$3, _p$.e));
|
|
183
|
+
_v$4 !== _p$.t && (_p$.t = _$setProp(_el$2, "fg", _v$4, _p$.t));
|
|
184
|
+
_v$5 !== _p$.a && (_p$.a = _$setProp(_el$3, "fg", _v$5, _p$.a));
|
|
185
|
+
_v$6 !== _p$.o && (_p$.o = _$setProp(_el$4, "fg", _v$6, _p$.o));
|
|
186
|
+
return _p$;
|
|
187
|
+
}, {
|
|
188
|
+
e: undefined,
|
|
189
|
+
t: undefined,
|
|
190
|
+
a: undefined,
|
|
191
|
+
o: undefined
|
|
192
|
+
});
|
|
193
|
+
return _el$;
|
|
194
|
+
})();
|
|
195
|
+
}
|
|
196
|
+
function Panel(props) {
|
|
197
|
+
const context = props.context;
|
|
198
|
+
const state = props.state;
|
|
199
|
+
const model = createMemo(() => buildPanel(state.source, props.panel.sessionID, {
|
|
200
|
+
known: state.known(),
|
|
201
|
+
read: state.read(),
|
|
202
|
+
titles: state.titles
|
|
203
|
+
}));
|
|
204
|
+
const palette = createMemo(() => colors(context.theme));
|
|
205
|
+
let scroll;
|
|
206
|
+
|
|
207
|
+
// The style follows the theme; a style no longer drawn is destroyed once the renderer is idle.
|
|
208
|
+
const release = style => Promise.resolve(context.renderer.idle?.()).catch(() => undefined).finally(() => style.destroy?.());
|
|
209
|
+
const syntax = createMemo(previous => {
|
|
210
|
+
const next = markdownStyle(context);
|
|
211
|
+
if (previous) release(previous);
|
|
212
|
+
return next;
|
|
213
|
+
});
|
|
214
|
+
onCleanup(() => release(syntax()));
|
|
215
|
+
const close = () => {
|
|
216
|
+
state.dismiss(props.panel.sessionID);
|
|
217
|
+
props.panel.close();
|
|
218
|
+
};
|
|
219
|
+
const open = sessionID => context.ui.router.navigate({
|
|
220
|
+
type: "session",
|
|
221
|
+
sessionID
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// The host gives the keyboard to a panel that opens, and has no way to open one without it. AZPR is
|
|
225
|
+
// driven by commands, so the panel hands the keyboard back to the prompt: the next command can be typed
|
|
226
|
+
// while the report is on screen, and a click in the panel (or the host's "Focus right pane") gives it
|
|
227
|
+
// the keyboard. A terminal too narrow for two panes shows the panel alone, with no prompt to return to.
|
|
228
|
+
// A panel that opened by itself must never be left with the keyboard: where it cannot hand it back, it
|
|
229
|
+
// closes again, and says that something is ready when a notice opened it.
|
|
230
|
+
// The two steps below run a moment after the panel mounted. By then the host may show another plugin's panel in
|
|
231
|
+
// this place, or another session: each step acts only while this panel is the one open here, and none outlives it.
|
|
232
|
+
const timers = new Set();
|
|
233
|
+
const mine = () => {
|
|
234
|
+
const current = context.ui.panel.current();
|
|
235
|
+
return current?.name === PANEL && current.sessionID === props.panel.sessionID;
|
|
236
|
+
};
|
|
237
|
+
const later = (step, delay) => {
|
|
238
|
+
const timer = setTimeout(() => {
|
|
239
|
+
timers.delete(timer);
|
|
240
|
+
if (mine()) step();
|
|
241
|
+
}, delay);
|
|
242
|
+
timers.add(timer);
|
|
243
|
+
};
|
|
244
|
+
onCleanup(() => {
|
|
245
|
+
for (const timer of timers) clearTimeout(timer);
|
|
246
|
+
timers.clear();
|
|
247
|
+
});
|
|
248
|
+
onMount(() => {
|
|
249
|
+
const unasked = state.takeUnasked();
|
|
250
|
+
const withdraw = () => {
|
|
251
|
+
state.dismiss(props.panel.sessionID);
|
|
252
|
+
props.panel.close();
|
|
253
|
+
if (unasked === "notice") context.ui.toast.show({
|
|
254
|
+
message: READY,
|
|
255
|
+
variant: "info"
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
if (props.panel.presentation === "fullscreen") return unasked ? withdraw() : undefined;
|
|
259
|
+
later(() => {
|
|
260
|
+
context.keymap.dispatch("pane.focus.left");
|
|
261
|
+
if (unasked) later(() => props.panel.focused && withdraw(), 50);
|
|
262
|
+
}, 0);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Sessions the host has not loaded here: a run's sessions after a TUI restart, the conversation of one of them.
|
|
266
|
+
createEffect(() => {
|
|
267
|
+
for (const sessionID of model().needs) void state.lookup(sessionID);
|
|
268
|
+
});
|
|
269
|
+
// The report of a review waits in its session's inbox; in one of AZPR's own sessions the notices are in the
|
|
270
|
+
// conversation's. The model names an inbox only once the session proved to be this conversation's.
|
|
271
|
+
createEffect(() => {
|
|
272
|
+
const inbox = model().inbox;
|
|
273
|
+
if (inbox) state.readInbox(inbox.sessionID, inbox.token, true);
|
|
274
|
+
const notices = model().notices;
|
|
275
|
+
if (notices) state.readInbox(notices.sessionID, notices.token, false);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Active only while the panel has the keyboard; the IDs let a user bind other keys in the TUI's configuration.
|
|
279
|
+
const page = () => Math.max(4, (scroll?.viewport?.height ?? scroll?.height ?? 10) - 2);
|
|
280
|
+
context.keymap.layer(() => ({
|
|
281
|
+
commands: [{
|
|
282
|
+
id: "azpr.panel.close",
|
|
283
|
+
title: "Close the AZPR panel",
|
|
284
|
+
group: "AZPR",
|
|
285
|
+
bind: "escape,q",
|
|
286
|
+
run: close
|
|
287
|
+
}, {
|
|
288
|
+
id: "azpr.panel.up",
|
|
289
|
+
title: "AZPR panel: scroll up",
|
|
290
|
+
group: "AZPR",
|
|
291
|
+
bind: "up,k",
|
|
292
|
+
run: () => scroll?.scrollBy(-1)
|
|
293
|
+
}, {
|
|
294
|
+
id: "azpr.panel.down",
|
|
295
|
+
title: "AZPR panel: scroll down",
|
|
296
|
+
group: "AZPR",
|
|
297
|
+
bind: "down,j",
|
|
298
|
+
run: () => scroll?.scrollBy(1)
|
|
299
|
+
}, {
|
|
300
|
+
id: "azpr.panel.page.up",
|
|
301
|
+
title: "AZPR panel: page up",
|
|
302
|
+
group: "AZPR",
|
|
303
|
+
bind: "pageup",
|
|
304
|
+
run: () => scroll?.scrollBy(-page())
|
|
305
|
+
}, {
|
|
306
|
+
id: "azpr.panel.page.down",
|
|
307
|
+
title: "AZPR panel: page down",
|
|
308
|
+
group: "AZPR",
|
|
309
|
+
bind: "pagedown",
|
|
310
|
+
run: () => scroll?.scrollBy(page())
|
|
311
|
+
}, {
|
|
312
|
+
id: "azpr.panel.top",
|
|
313
|
+
title: "AZPR panel: go to the top",
|
|
314
|
+
group: "AZPR",
|
|
315
|
+
bind: "home",
|
|
316
|
+
run: () => scroll?.scrollTo(0)
|
|
317
|
+
}, {
|
|
318
|
+
id: "azpr.panel.bottom",
|
|
319
|
+
title: "AZPR panel: go to the end",
|
|
320
|
+
group: "AZPR",
|
|
321
|
+
bind: "end",
|
|
322
|
+
run: () => scroll?.scrollTo(scroll.scrollHeight)
|
|
323
|
+
}]
|
|
324
|
+
}));
|
|
325
|
+
|
|
326
|
+
// Rows are keyed by session, so a row keeps its place and its hover while the list is worked out again.
|
|
327
|
+
const ids = createMemo(() => model().rows.map(row => row.id), [], {
|
|
328
|
+
equals: (a, b) => a.length === b.length && a.every((id, index) => id === b[index])
|
|
329
|
+
});
|
|
330
|
+
const row = id => model().rows.find(item => item.id === id) ?? {
|
|
331
|
+
id,
|
|
332
|
+
label: "",
|
|
333
|
+
state: "",
|
|
334
|
+
report: false
|
|
335
|
+
};
|
|
336
|
+
return (() => {
|
|
337
|
+
var _el$6 = _$createElement("box"),
|
|
338
|
+
_el$7 = _$createElement("box"),
|
|
339
|
+
_el$8 = _$createElement("text"),
|
|
340
|
+
_el$9 = _$createElement("b"),
|
|
341
|
+
_el$13 = _$createElement("box"),
|
|
342
|
+
_el$14 = _$createElement("text"),
|
|
343
|
+
_el$17 = _$createElement("scrollbox");
|
|
344
|
+
_$insertNode(_el$6, _el$7);
|
|
345
|
+
_$insertNode(_el$6, _el$17);
|
|
346
|
+
_$setProp(_el$6, "flexDirection", "column");
|
|
347
|
+
_$setProp(_el$6, "flexGrow", 1);
|
|
348
|
+
_$setProp(_el$6, "minHeight", 0);
|
|
349
|
+
_$setProp(_el$6, "paddingLeft", 2);
|
|
350
|
+
_$setProp(_el$6, "paddingRight", 2);
|
|
351
|
+
_$setProp(_el$6, "paddingTop", 1);
|
|
352
|
+
_$insertNode(_el$7, _el$8);
|
|
353
|
+
_$insertNode(_el$7, _el$13);
|
|
354
|
+
_$insertNode(_el$7, _el$14);
|
|
355
|
+
_$setProp(_el$7, "flexDirection", "row");
|
|
356
|
+
_$setProp(_el$7, "flexShrink", 0);
|
|
357
|
+
_$insertNode(_el$8, _el$9);
|
|
358
|
+
_$setProp(_el$8, "flexShrink", 0);
|
|
359
|
+
_$insertNode(_el$9, _$createTextNode(`AZPR`));
|
|
360
|
+
_$insert(_el$8, _$createComponent(Show, {
|
|
361
|
+
get when() {
|
|
362
|
+
return model().run;
|
|
363
|
+
},
|
|
364
|
+
get children() {
|
|
365
|
+
var _el$1 = _$createElement("span"),
|
|
366
|
+
_el$10 = _$createTextNode(` `);
|
|
367
|
+
_$insertNode(_el$1, _el$10);
|
|
368
|
+
_$insert(_el$1, () => model().run, null);
|
|
369
|
+
return _el$1;
|
|
370
|
+
}
|
|
371
|
+
}), null);
|
|
372
|
+
_$insert(_el$8, _$createComponent(Show, {
|
|
373
|
+
get when() {
|
|
374
|
+
return model().status;
|
|
375
|
+
},
|
|
376
|
+
get children() {
|
|
377
|
+
var _el$11 = _$createElement("span"),
|
|
378
|
+
_el$12 = _$createTextNode(` · `);
|
|
379
|
+
_$insertNode(_el$11, _el$12);
|
|
380
|
+
_$insert(_el$11, () => model().status, null);
|
|
381
|
+
_$effect(_$p => _$setProp(_el$11, "style", {
|
|
382
|
+
fg: palette().muted
|
|
383
|
+
}, _$p));
|
|
384
|
+
return _el$11;
|
|
385
|
+
}
|
|
386
|
+
}), null);
|
|
387
|
+
_$setProp(_el$13, "flexGrow", 1);
|
|
388
|
+
_$insertNode(_el$14, _$createTextNode(`close`));
|
|
389
|
+
_$setProp(_el$14, "flexShrink", 0);
|
|
390
|
+
_$setProp(_el$14, "selectable", false);
|
|
391
|
+
_$setProp(_el$14, "onMouseUp", event => {
|
|
392
|
+
if (event.button !== MouseButton.LEFT) return;
|
|
393
|
+
event.stopPropagation();
|
|
394
|
+
close();
|
|
395
|
+
});
|
|
396
|
+
_$insert(_el$6, _$createComponent(Show, {
|
|
397
|
+
get when() {
|
|
398
|
+
return model().progress;
|
|
399
|
+
},
|
|
400
|
+
get children() {
|
|
401
|
+
var _el$16 = _$createElement("text");
|
|
402
|
+
_$setProp(_el$16, "flexShrink", 0);
|
|
403
|
+
_$insert(_el$16, () => model().progress);
|
|
404
|
+
_$effect(_$p => _$setProp(_el$16, "fg", palette().muted, _$p));
|
|
405
|
+
return _el$16;
|
|
406
|
+
}
|
|
407
|
+
}), _el$17);
|
|
408
|
+
_$use(element => scroll = element, _el$17);
|
|
409
|
+
_$setProp(_el$17, "flexGrow", 1);
|
|
410
|
+
_$setProp(_el$17, "minHeight", 0);
|
|
411
|
+
_$setProp(_el$17, "paddingTop", 1);
|
|
412
|
+
_$setProp(_el$17, "verticalScrollbarOptions", {
|
|
413
|
+
visible: false
|
|
414
|
+
});
|
|
415
|
+
_$setProp(_el$17, "contentOptions", {
|
|
416
|
+
minHeight: 0
|
|
417
|
+
});
|
|
418
|
+
_$insert(_el$17, _$createComponent(Show, {
|
|
419
|
+
get when() {
|
|
420
|
+
return ids().length > 0 || model().deleted > 0;
|
|
421
|
+
},
|
|
422
|
+
get children() {
|
|
423
|
+
var _el$18 = _$createElement("box");
|
|
424
|
+
_$setProp(_el$18, "flexDirection", "column");
|
|
425
|
+
_$setProp(_el$18, "flexShrink", 0);
|
|
426
|
+
_$setProp(_el$18, "paddingBottom", 1);
|
|
427
|
+
_$insert(_el$18, _$createComponent(Show, {
|
|
428
|
+
get when() {
|
|
429
|
+
return ids().length > 0;
|
|
430
|
+
},
|
|
431
|
+
get children() {
|
|
432
|
+
var _el$19 = _$createElement("text");
|
|
433
|
+
_$insertNode(_el$19, _$createTextNode(`Sessions (click one to open it)`));
|
|
434
|
+
_$setProp(_el$19, "selectable", false);
|
|
435
|
+
_$effect(_$p => _$setProp(_el$19, "fg", palette().muted, _$p));
|
|
436
|
+
return _el$19;
|
|
437
|
+
}
|
|
438
|
+
}), null);
|
|
439
|
+
_$insert(_el$18, _$createComponent(For, {
|
|
440
|
+
get each() {
|
|
441
|
+
return ids();
|
|
442
|
+
},
|
|
443
|
+
children: id => _$createComponent(Row, {
|
|
444
|
+
get row() {
|
|
445
|
+
return row(id);
|
|
446
|
+
},
|
|
447
|
+
get colors() {
|
|
448
|
+
return palette();
|
|
449
|
+
},
|
|
450
|
+
get wide() {
|
|
451
|
+
return props.panel.width >= 64;
|
|
452
|
+
},
|
|
453
|
+
open: open
|
|
454
|
+
})
|
|
455
|
+
}), null);
|
|
456
|
+
_$insert(_el$18, _$createComponent(Show, {
|
|
457
|
+
get when() {
|
|
458
|
+
return model().deleted > 0;
|
|
459
|
+
},
|
|
460
|
+
get children() {
|
|
461
|
+
var _el$21 = _$createElement("text"),
|
|
462
|
+
_el$22 = _$createTextNode(` session(s) were deleted when their run ended.`);
|
|
463
|
+
_$insertNode(_el$21, _el$22);
|
|
464
|
+
_$insert(_el$21, () => model().deleted, _el$22);
|
|
465
|
+
_$effect(_$p => _$setProp(_el$21, "fg", palette().muted, _$p));
|
|
466
|
+
return _el$21;
|
|
467
|
+
}
|
|
468
|
+
}), null);
|
|
469
|
+
return _el$18;
|
|
470
|
+
}
|
|
471
|
+
}), null);
|
|
472
|
+
_$insert(_el$17, _$createComponent(Show, {
|
|
473
|
+
get when() {
|
|
474
|
+
return model().markdown;
|
|
475
|
+
},
|
|
476
|
+
get fallback() {
|
|
477
|
+
return (() => {
|
|
478
|
+
var _el$25 = _$createElement("text");
|
|
479
|
+
_$insert(_el$25, (() => {
|
|
480
|
+
var _c$ = _$memo(() => !!model().loading);
|
|
481
|
+
return () => _c$() ? "Loading the report…" : _$memo(() => !!model().inbox)() ? "The report is in its session: open it above." : model().run ? "No report or preview yet." : "No AZPR run in this conversation yet.";
|
|
482
|
+
})());
|
|
483
|
+
_$effect(_$p => _$setProp(_el$25, "fg", palette().muted, _$p));
|
|
484
|
+
return _el$25;
|
|
485
|
+
})();
|
|
486
|
+
},
|
|
487
|
+
get children() {
|
|
488
|
+
return [_$createComponent(Show, {
|
|
489
|
+
get when() {
|
|
490
|
+
return model().documentHead;
|
|
491
|
+
},
|
|
492
|
+
get children() {
|
|
493
|
+
var _el$23 = _$createElement("text");
|
|
494
|
+
_$setProp(_el$23, "flexShrink", 0);
|
|
495
|
+
_$setProp(_el$23, "paddingBottom", 1);
|
|
496
|
+
_$insert(_el$23, () => model().documentHead);
|
|
497
|
+
_$effect(_$p => _$setProp(_el$23, "fg", palette().muted, _$p));
|
|
498
|
+
return _el$23;
|
|
499
|
+
}
|
|
500
|
+
}), (() => {
|
|
501
|
+
var _el$24 = _$createElement("markdown");
|
|
502
|
+
_$setProp(_el$24, "conceal", true);
|
|
503
|
+
_$setProp(_el$24, "tableOptions", {
|
|
504
|
+
style: "grid",
|
|
505
|
+
cellPaddingX: 1
|
|
506
|
+
});
|
|
507
|
+
_$effect(_p$ => {
|
|
508
|
+
var _v$7 = syntax(),
|
|
509
|
+
_v$8 = model().markdown,
|
|
510
|
+
_v$9 = palette().text,
|
|
511
|
+
_v$0 = palette().surface;
|
|
512
|
+
_v$7 !== _p$.e && (_p$.e = _$setProp(_el$24, "syntaxStyle", _v$7, _p$.e));
|
|
513
|
+
_v$8 !== _p$.t && (_p$.t = _$setProp(_el$24, "content", _v$8, _p$.t));
|
|
514
|
+
_v$9 !== _p$.a && (_p$.a = _$setProp(_el$24, "fg", _v$9, _p$.a));
|
|
515
|
+
_v$0 !== _p$.o && (_p$.o = _$setProp(_el$24, "bg", _v$0, _p$.o));
|
|
516
|
+
return _p$;
|
|
517
|
+
}, {
|
|
518
|
+
e: undefined,
|
|
519
|
+
t: undefined,
|
|
520
|
+
a: undefined,
|
|
521
|
+
o: undefined
|
|
522
|
+
});
|
|
523
|
+
return _el$24;
|
|
524
|
+
})()];
|
|
525
|
+
}
|
|
526
|
+
}), null);
|
|
527
|
+
_$effect(_p$ => {
|
|
528
|
+
var _v$1 = palette().base,
|
|
529
|
+
_v$10 = palette().muted;
|
|
530
|
+
_v$1 !== _p$.e && (_p$.e = _$setProp(_el$8, "fg", _v$1, _p$.e));
|
|
531
|
+
_v$10 !== _p$.t && (_p$.t = _$setProp(_el$14, "fg", _v$10, _p$.t));
|
|
532
|
+
return _p$;
|
|
533
|
+
}, {
|
|
534
|
+
e: undefined,
|
|
535
|
+
t: undefined
|
|
536
|
+
});
|
|
537
|
+
return _el$6;
|
|
538
|
+
})();
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** The review panel: opens by itself or with /pr-panel, and only reads. Returns its cleanup, or nothing on a host without a place for it. */
|
|
542
|
+
function panelPart(context) {
|
|
543
|
+
// A host without these parts of the plugin API has no place for the panel: stay out of its way.
|
|
544
|
+
const needed = [context?.ui?.slot, context?.ui?.panel?.open, context?.ui?.router?.navigate, context?.keymap?.layer, context?.data?.listen, context?.data?.session?.pending?.list];
|
|
545
|
+
if (needed.some(part => typeof part !== "function")) return undefined;
|
|
546
|
+
const data = context.data;
|
|
547
|
+
// Set when the TUI unloads the plugin: nothing is asked of the host after that.
|
|
548
|
+
let disposed = false;
|
|
549
|
+
// The host keeps the messages and the inbox of the session on screen and of open tabs, and drops those of
|
|
550
|
+
// other sessions again. What the panel needs of another session (the report waiting in a review session's
|
|
551
|
+
// inbox, the notices of the conversation when one of AZPR's own sessions is on screen) is read from the
|
|
552
|
+
// server by the reader in tui-model.mjs, which also knows which sessions are gone. `version` makes what it
|
|
553
|
+
// holds reactive.
|
|
554
|
+
const [version, setVersion] = createSignal(0);
|
|
555
|
+
const reader = createReader({
|
|
556
|
+
inbox: sessionID => context.client.session.inbox.list({
|
|
557
|
+
sessionID
|
|
558
|
+
}),
|
|
559
|
+
context: typeof context.client?.session?.context === "function" ? sessionID => context.client.session.context({
|
|
560
|
+
sessionID
|
|
561
|
+
}) : undefined,
|
|
562
|
+
lookup: sessionID => data.session.sync(sessionID),
|
|
563
|
+
present: sessionID => data.session.get(sessionID),
|
|
564
|
+
list: cursor => context.client.session.list(cursor ? {
|
|
565
|
+
cursor
|
|
566
|
+
} : {}),
|
|
567
|
+
changed: () => setVersion(count => count + 1)
|
|
568
|
+
});
|
|
569
|
+
const source = {
|
|
570
|
+
session: id => data.session.get(id),
|
|
571
|
+
sessions: () => data.session.list(),
|
|
572
|
+
status: id => data.session.status(id),
|
|
573
|
+
messages: id => data.session.message.list(id),
|
|
574
|
+
pending: id => (version(), [...data.session.pending.list(id), ...reader.entries(id)])
|
|
575
|
+
};
|
|
576
|
+
const known = () => (version(), reader.known());
|
|
577
|
+
const read = () => (version(), reader.read());
|
|
578
|
+
|
|
579
|
+
// Sessions whose panel this plugin opened and the user has not closed. The host closes a panel when the
|
|
580
|
+
// screen leaves its session; coming back to such a session opens it again.
|
|
581
|
+
const wanted = new Set();
|
|
582
|
+
// Why the panel is being opened without the user asking: "notice" or "return"; undefined when asked.
|
|
583
|
+
let unasked;
|
|
584
|
+
// The session in which another plugin's panel is open; the host shows one panel at a time.
|
|
585
|
+
let occupied;
|
|
586
|
+
const state = {
|
|
587
|
+
source,
|
|
588
|
+
known,
|
|
589
|
+
read,
|
|
590
|
+
titles: new Map(),
|
|
591
|
+
lookup: reader.lookup,
|
|
592
|
+
readInbox: reader.readInbox,
|
|
593
|
+
dismiss: sessionID => void wanted.delete(sessionID),
|
|
594
|
+
takeUnasked: () => {
|
|
595
|
+
const value = unasked;
|
|
596
|
+
unasked = undefined;
|
|
597
|
+
return value;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
context.ui.slot({
|
|
601
|
+
append: "session.panel",
|
|
602
|
+
render: panel => {
|
|
603
|
+
// Every contribution is told which panel is open: remember where it is someone else's.
|
|
604
|
+
createEffect(() => {
|
|
605
|
+
occupied = panel.name === PANEL ? undefined : panel.sessionID;
|
|
606
|
+
});
|
|
607
|
+
onCleanup(() => {
|
|
608
|
+
occupied = undefined;
|
|
609
|
+
});
|
|
610
|
+
return _$createComponent(Show, {
|
|
611
|
+
get when() {
|
|
612
|
+
return panel.name === PANEL;
|
|
613
|
+
},
|
|
614
|
+
get children() {
|
|
615
|
+
return _$createComponent(Panel, {
|
|
616
|
+
context: context,
|
|
617
|
+
panel: panel,
|
|
618
|
+
state: state
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
const shown = sessionID => {
|
|
625
|
+
const current = context.ui.panel.current();
|
|
626
|
+
return current?.name === PANEL && current.sessionID === sessionID;
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* Show the panel in the session on screen. `byItself` says why when the user did not ask ("notice": one
|
|
630
|
+
* arrived; "return": the screen came back to a session that had the panel): then neither a dialog nor
|
|
631
|
+
* another plugin's panel is disturbed.
|
|
632
|
+
*/
|
|
633
|
+
const show = byItself => {
|
|
634
|
+
if (disposed) return false;
|
|
635
|
+
const route = context.ui.router.current();
|
|
636
|
+
if (route.type !== "session") return false;
|
|
637
|
+
const sessionID = route.sessionID;
|
|
638
|
+
// After a TUI restart the host has not loaded a run's sessions: the reader asks the server for them.
|
|
639
|
+
void reader.discover(conversationOf(data.session.get(sessionID)) ?? sessionID);
|
|
640
|
+
wanted.add(sessionID);
|
|
641
|
+
if (shown(sessionID)) return true;
|
|
642
|
+
if (byItself && (occupied === sessionID || context.keymap.mode?.current?.() === "modal")) {
|
|
643
|
+
if (byItself === "notice") context.ui.toast.show({
|
|
644
|
+
message: READY,
|
|
645
|
+
variant: "info"
|
|
646
|
+
});
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
unasked = byItself;
|
|
650
|
+
return context.ui.panel.open(PANEL);
|
|
651
|
+
};
|
|
652
|
+
const stop = data.listen(event => {
|
|
653
|
+
if (disposed) return;
|
|
654
|
+
const details = event?.details;
|
|
655
|
+
if (details?.type === "session.deleted") return reader.deleted(details.data?.sessionID);
|
|
656
|
+
if (details?.type === "server.connected") {
|
|
657
|
+
// What was published while the TUI was away was missed: look everything up again, and let nothing that
|
|
658
|
+
// was asked before the reconnection answer for now.
|
|
659
|
+
reader.reconnected();
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
if (details?.type !== "session.inbox.enqueued") return;
|
|
663
|
+
const item = details.data?.item;
|
|
664
|
+
// What was read of a session from the server is kept current: the host tells of each new notice.
|
|
665
|
+
reader.arrived(details.data?.sessionID, item);
|
|
666
|
+
// A run that starts, and a report or preview that arrives, opens the panel in the session on screen,
|
|
667
|
+
// unless the notice says that the settings leave the panel to /pr-panel.
|
|
668
|
+
if (item?.type !== "synthetic" || !opensPanel(item.payload?.text, item.payload?.metadata)) return;
|
|
669
|
+
const route = context.ui.router.current();
|
|
670
|
+
if (route.type === "session" && route.sessionID === details.data.sessionID) show("notice");
|
|
671
|
+
});
|
|
672
|
+
context.ui.slot({
|
|
673
|
+
append: "app",
|
|
674
|
+
render: () => {
|
|
675
|
+
createEffect(() => {
|
|
676
|
+
const route = context.ui.router.current();
|
|
677
|
+
if (route.type !== "session" || !wanted.has(route.sessionID)) return;
|
|
678
|
+
const sessionID = route.sessionID;
|
|
679
|
+
// After the session's view has mounted.
|
|
680
|
+
setTimeout(() => {
|
|
681
|
+
const now = context.ui.router.current();
|
|
682
|
+
if (now.type === "session" && now.sessionID === sessionID && wanted.has(sessionID)) show("return");
|
|
683
|
+
}, 0);
|
|
684
|
+
});
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
context.keymap.layer(() => ({
|
|
689
|
+
mode: "global",
|
|
690
|
+
commands: [{
|
|
691
|
+
id: "azpr.panel",
|
|
692
|
+
title: "AZPR: show or hide the review panel",
|
|
693
|
+
description: "The sessions of the review in this conversation and its report or comment preview, rendered.",
|
|
694
|
+
group: "AZPR",
|
|
695
|
+
palette: true,
|
|
696
|
+
slash: {
|
|
697
|
+
name: "pr-panel"
|
|
698
|
+
},
|
|
699
|
+
run() {
|
|
700
|
+
const route = context.ui.router.current();
|
|
701
|
+
if (route.type !== "session") {
|
|
702
|
+
context.ui.toast.show({
|
|
703
|
+
message: "AZPR: open a conversation first.",
|
|
704
|
+
variant: "info"
|
|
705
|
+
});
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (shown(route.sessionID)) {
|
|
709
|
+
wanted.delete(route.sessionID);
|
|
710
|
+
context.ui.panel.close();
|
|
711
|
+
} else show();
|
|
712
|
+
}
|
|
713
|
+
}]
|
|
714
|
+
}));
|
|
715
|
+
return () => {
|
|
716
|
+
disposed = true;
|
|
717
|
+
reader.dispose();
|
|
718
|
+
stop?.();
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* A dialog that takes a secret and shows nothing of it. The host's own text prompt shows what is typed, and
|
|
724
|
+
* its text fields have no hidden mode, so keys and pastes are taken here: the value lives in this closure
|
|
725
|
+
* only and the screen holds bullets and a count, which neither a glance nor the terminal's own copy can read.
|
|
726
|
+
* Resolves with the value ('' only where `optional`), or with undefined when the dialog was closed.
|
|
727
|
+
*/
|
|
728
|
+
function askSecret(context, options) {
|
|
729
|
+
return new Promise(resolve => {
|
|
730
|
+
let settled = false;
|
|
731
|
+
const done = value => {
|
|
732
|
+
if (settled) return;
|
|
733
|
+
settled = true;
|
|
734
|
+
resolve(value);
|
|
735
|
+
};
|
|
736
|
+
context.ui.dialog.show(() => _$createComponent(Secret, {
|
|
737
|
+
context: context,
|
|
738
|
+
options: options,
|
|
739
|
+
done: value => {
|
|
740
|
+
done(value);
|
|
741
|
+
context.ui.dialog.clear();
|
|
742
|
+
}
|
|
743
|
+
}), () => done(undefined));
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function Secret(props) {
|
|
747
|
+
let field;
|
|
748
|
+
let value = "";
|
|
749
|
+
const [length, setLength] = createSignal(0);
|
|
750
|
+
const palette = createMemo(() => colors(props.context.theme));
|
|
751
|
+
// Far longer than any token: what is pasted beyond that is not kept.
|
|
752
|
+
const set = next => {
|
|
753
|
+
value = next.slice(0, 2048);
|
|
754
|
+
setLength(value.length);
|
|
755
|
+
};
|
|
756
|
+
const submit = () => {
|
|
757
|
+
if (value || props.options.optional) props.done(value);
|
|
758
|
+
};
|
|
759
|
+
const key = event => {
|
|
760
|
+
const name = event?.name;
|
|
761
|
+
if (name === "return" || name === "enter" || name === "kpenter") {
|
|
762
|
+
event.preventDefault?.();
|
|
763
|
+
return submit();
|
|
764
|
+
}
|
|
765
|
+
if (name === "backspace" || name === "delete") {
|
|
766
|
+
event.preventDefault?.();
|
|
767
|
+
return set(value.slice(0, -1));
|
|
768
|
+
}
|
|
769
|
+
if (event?.ctrl && name === "u") {
|
|
770
|
+
event.preventDefault?.();
|
|
771
|
+
return set("");
|
|
772
|
+
}
|
|
773
|
+
const typed = event?.sequence;
|
|
774
|
+
// One printable character; what a terminal sends for other keys is longer or starts with a control character.
|
|
775
|
+
if (!event?.ctrl && !event?.meta && typeof typed === "string" && [...typed].length === 1 && typed >= " " && typed !== "\x7f") {
|
|
776
|
+
event.preventDefault?.();
|
|
777
|
+
set(value + typed);
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
// A token is one word: line breaks and blanks around a pasted one are not part of it.
|
|
781
|
+
const paste = event => {
|
|
782
|
+
event?.preventDefault?.();
|
|
783
|
+
let pasted = "";
|
|
784
|
+
try {
|
|
785
|
+
pasted = new TextDecoder().decode(event?.bytes ?? new Uint8Array());
|
|
786
|
+
} catch {}
|
|
787
|
+
set(value + pasted.replace(/\s+/g, ""));
|
|
788
|
+
};
|
|
789
|
+
onMount(() => {
|
|
790
|
+
const timer = setTimeout(() => {
|
|
791
|
+
if (field && !field.isDestroyed) field.focus();
|
|
792
|
+
}, 1);
|
|
793
|
+
onCleanup(() => clearTimeout(timer));
|
|
794
|
+
});
|
|
795
|
+
onCleanup(() => {
|
|
796
|
+
value = "";
|
|
797
|
+
});
|
|
798
|
+
return (() => {
|
|
799
|
+
var _el$26 = _$createElement("box"),
|
|
800
|
+
_el$27 = _$createElement("text"),
|
|
801
|
+
_el$28 = _$createElement("b"),
|
|
802
|
+
_el$30 = _$createElement("text"),
|
|
803
|
+
_el$31 = _$createElement("box"),
|
|
804
|
+
_el$32 = _$createElement("text"),
|
|
805
|
+
_el$33 = _$createElement("text");
|
|
806
|
+
_$insertNode(_el$26, _el$27);
|
|
807
|
+
_$insertNode(_el$26, _el$30);
|
|
808
|
+
_$insertNode(_el$26, _el$31);
|
|
809
|
+
_$insertNode(_el$26, _el$33);
|
|
810
|
+
_$setProp(_el$26, "flexDirection", "column");
|
|
811
|
+
_$setProp(_el$26, "paddingLeft", 2);
|
|
812
|
+
_$setProp(_el$26, "paddingRight", 2);
|
|
813
|
+
_$setProp(_el$26, "paddingTop", 1);
|
|
814
|
+
_$setProp(_el$26, "paddingBottom", 1);
|
|
815
|
+
_$setProp(_el$26, "gap", 1);
|
|
816
|
+
_$insertNode(_el$27, _el$28);
|
|
817
|
+
_$insert(_el$28, () => props.options.title);
|
|
818
|
+
_$insert(_el$26, _$createComponent(Show, {
|
|
819
|
+
get when() {
|
|
820
|
+
return props.options.problem;
|
|
821
|
+
},
|
|
822
|
+
get children() {
|
|
823
|
+
var _el$29 = _$createElement("text");
|
|
824
|
+
_$insert(_el$29, () => props.options.problem);
|
|
825
|
+
_$effect(_$p => _$setProp(_el$29, "fg", palette().failed, _$p));
|
|
826
|
+
return _el$29;
|
|
827
|
+
}
|
|
828
|
+
}), _el$30);
|
|
829
|
+
_$insert(_el$30, () => props.options.description);
|
|
830
|
+
_$insertNode(_el$31, _el$32);
|
|
831
|
+
_$use(node => {
|
|
832
|
+
field = node;
|
|
833
|
+
}, _el$31);
|
|
834
|
+
_$setProp(_el$31, "focusable", true);
|
|
835
|
+
_$setProp(_el$31, "onKeyDown", key);
|
|
836
|
+
_$setProp(_el$31, "onPaste", paste);
|
|
837
|
+
_$setProp(_el$31, "onMouseDown", () => {
|
|
838
|
+
if (field && !field.isDestroyed) field.focus();
|
|
839
|
+
});
|
|
840
|
+
_$setProp(_el$31, "height", 1);
|
|
841
|
+
_$setProp(_el$31, "paddingLeft", 1);
|
|
842
|
+
_$setProp(_el$31, "flexShrink", 0);
|
|
843
|
+
_$insert(_el$32, (() => {
|
|
844
|
+
var _c$2 = _$memo(() => !!length());
|
|
845
|
+
return () => _c$2() ? `${"•".repeat(Math.min(length(), 16))} (${length()} characters, hidden)` : "Paste the token here; it is not shown";
|
|
846
|
+
})());
|
|
847
|
+
_$insertNode(_el$33, _$createTextNode(`enter save · ctrl+u clear · esc leave`));
|
|
848
|
+
_$effect(_p$ => {
|
|
849
|
+
var _v$11 = palette().base,
|
|
850
|
+
_v$12 = palette().muted,
|
|
851
|
+
_v$13 = palette().hover ?? palette().surface,
|
|
852
|
+
_v$14 = length() ? palette().base : palette().muted,
|
|
853
|
+
_v$15 = palette().muted;
|
|
854
|
+
_v$11 !== _p$.e && (_p$.e = _$setProp(_el$27, "fg", _v$11, _p$.e));
|
|
855
|
+
_v$12 !== _p$.t && (_p$.t = _$setProp(_el$30, "fg", _v$12, _p$.t));
|
|
856
|
+
_v$13 !== _p$.a && (_p$.a = _$setProp(_el$31, "backgroundColor", _v$13, _p$.a));
|
|
857
|
+
_v$14 !== _p$.o && (_p$.o = _$setProp(_el$32, "fg", _v$14, _p$.o));
|
|
858
|
+
_v$15 !== _p$.i && (_p$.i = _$setProp(_el$33, "fg", _v$15, _p$.i));
|
|
859
|
+
return _p$;
|
|
860
|
+
}, {
|
|
861
|
+
e: undefined,
|
|
862
|
+
t: undefined,
|
|
863
|
+
a: undefined,
|
|
864
|
+
o: undefined,
|
|
865
|
+
i: undefined
|
|
866
|
+
});
|
|
867
|
+
return _el$26;
|
|
868
|
+
})();
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* The dialogs of /pr-setup: they open when the server part answers /pr-setup without options in the session
|
|
873
|
+
* on screen, and from the command palette. Returns its cleanup, or nothing on a host without dialogs or RPC.
|
|
874
|
+
*/
|
|
875
|
+
function setupPart(context) {
|
|
876
|
+
const needed = [context?.ui?.dialog?.select, context?.ui?.dialog?.prompt, context?.ui?.dialog?.confirm, context?.ui?.dialog?.alert, context?.ui?.dialog?.show, context?.ui?.toast?.show, context?.client?.rpc, context?.keymap?.layer, context?.data?.listen, context?.data?.location?.model?.list];
|
|
877
|
+
if (needed.some(part => typeof part !== "function")) return undefined;
|
|
878
|
+
let disposed = false;
|
|
879
|
+
const rpc = context.client.rpc(SETUP_RPC);
|
|
880
|
+
// Each project directory has a server part of its own. Setup talks to the one of the session on screen, where
|
|
881
|
+
// the review commands that follow will run; without a session, to the one of the directory this TUI works in.
|
|
882
|
+
const onScreen = () => {
|
|
883
|
+
const route = context.ui.router?.current?.();
|
|
884
|
+
const session = route?.type === "session" ? context.data.session?.get?.(route.sessionID) : undefined;
|
|
885
|
+
return session?.location ?? context.location ?? context.data.location.default?.();
|
|
886
|
+
};
|
|
887
|
+
// While a setup is open its place is fixed: another project's session may come on screen meanwhile, and what
|
|
888
|
+
// was checked for one project's server part must not be saved by another's.
|
|
889
|
+
let pinned;
|
|
890
|
+
const place = () => pinned ? pinned.at : onScreen();
|
|
891
|
+
const call = (method, input = {}) => {
|
|
892
|
+
const directory = place()?.directory;
|
|
893
|
+
return rpc[method](input, directory ? {
|
|
894
|
+
location: {
|
|
895
|
+
directory
|
|
896
|
+
}
|
|
897
|
+
} : undefined);
|
|
898
|
+
};
|
|
899
|
+
// The models the host offers that can call tools, as the server part will accept them.
|
|
900
|
+
const models = async () => {
|
|
901
|
+
const at = place();
|
|
902
|
+
await Promise.all([context.data.location.model.sync?.(at), context.data.location.provider?.sync?.(at)]).catch(() => {});
|
|
903
|
+
const providers = new Map((context.data.location.provider?.list?.(at) ?? []).map(provider => [provider.id, provider.name ?? provider.id]));
|
|
904
|
+
return (context.data.location.model.list(at) ?? []).filter(model => model?.enabled !== false && model?.capabilities?.tools === true && typeof model.providerID === "string" && typeof model.id === "string").map(model => ({
|
|
905
|
+
id: `${model.providerID}/${model.id}`,
|
|
906
|
+
name: typeof model.name === "string" && model.name ? model.name : model.id,
|
|
907
|
+
provider: providers.get(model.providerID) ?? model.providerID,
|
|
908
|
+
variants: (Array.isArray(model.variants) ? model.variants : []).map(variant => variant?.id).filter(id => typeof id === "string" && id)
|
|
909
|
+
}));
|
|
910
|
+
};
|
|
911
|
+
// The commands as the server has them now. OpenCode 2.3.0 does not tell its clients where commands changed
|
|
912
|
+
// when a plugin changes them after it was loaded, so after a first setup the list is read again here.
|
|
913
|
+
const commandsChanged = () => {
|
|
914
|
+
if (disposed) return;
|
|
915
|
+
const at = place();
|
|
916
|
+
try {
|
|
917
|
+
context.data.location.command?.invalidate?.(at);
|
|
918
|
+
void Promise.resolve(context.data.location.command?.sync?.(at)).catch(() => {});
|
|
919
|
+
} catch {}
|
|
920
|
+
};
|
|
921
|
+
const setup = createSetup({
|
|
922
|
+
call,
|
|
923
|
+
dialog: context.ui.dialog,
|
|
924
|
+
secret: options => askSecret(context, options),
|
|
925
|
+
toast: options => {
|
|
926
|
+
if (!disposed) context.ui.toast.show(options);
|
|
927
|
+
},
|
|
928
|
+
models,
|
|
929
|
+
loaded: commandsChanged,
|
|
930
|
+
pin: () => {
|
|
931
|
+
const mine = pinned = {
|
|
932
|
+
at: onScreen()
|
|
933
|
+
};
|
|
934
|
+
return () => {
|
|
935
|
+
if (pinned === mine) pinned = undefined;
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
// Also when the settings were saved with options, or loaded by another command: the server part says so.
|
|
940
|
+
let unsubscribe;
|
|
941
|
+
try {
|
|
942
|
+
unsubscribe = rpc.events?.on?.("loaded", commandsChanged);
|
|
943
|
+
} catch {}
|
|
944
|
+
const stop = context.data.listen(event => {
|
|
945
|
+
if (disposed) return;
|
|
946
|
+
const details = event?.details;
|
|
947
|
+
if (details?.type !== "session.inbox.enqueued") return;
|
|
948
|
+
const item = details.data?.item;
|
|
949
|
+
if (item?.type !== "synthetic" || !isSetupNotice(item.payload?.metadata)) return;
|
|
950
|
+
// Only where the person just typed /pr-setup: the session on screen.
|
|
951
|
+
const route = context.ui.router?.current?.();
|
|
952
|
+
if (route?.type === "session" && route.sessionID === details.data.sessionID) void setup.open();
|
|
953
|
+
});
|
|
954
|
+
context.keymap.layer(() => ({
|
|
955
|
+
mode: "global",
|
|
956
|
+
commands: [{
|
|
957
|
+
id: "azpr.setup",
|
|
958
|
+
title: "AZPR: settings",
|
|
959
|
+
description: "Set AZPR up, or show and change its settings: organization, token, proxy, models and more.",
|
|
960
|
+
group: "AZPR",
|
|
961
|
+
palette: true,
|
|
962
|
+
run() {
|
|
963
|
+
void setup.open();
|
|
964
|
+
}
|
|
965
|
+
}]
|
|
966
|
+
}));
|
|
967
|
+
|
|
968
|
+
// Say once how to set AZPR up when it has no usable settings. The server part may still be loading when the
|
|
969
|
+
// TUI starts, so it is asked a second time a little later; neither timer outlives this part.
|
|
970
|
+
const timers = [1500, 6000].map(delay => setTimeout(() => !disposed && void setup.hint(), delay));
|
|
971
|
+
return () => {
|
|
972
|
+
disposed = true;
|
|
973
|
+
// A setup that is open ends at its next step: nothing is saved by a part that was unloaded.
|
|
974
|
+
setup.stop();
|
|
975
|
+
timers.forEach(clearTimeout);
|
|
976
|
+
stop?.();
|
|
977
|
+
try {
|
|
978
|
+
unsubscribe?.();
|
|
979
|
+
} catch {}
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
export default {
|
|
983
|
+
id: "azpr.tui",
|
|
984
|
+
setup(context) {
|
|
985
|
+
// Each part checks for itself what it needs of the host, and stays out of the way where that is missing.
|
|
986
|
+
const stops = [panelPart(context), setupPart(context)].filter(stop => typeof stop === "function");
|
|
987
|
+
return () => stops.forEach(stop => stop());
|
|
988
|
+
}
|
|
989
|
+
};
|