@antondanv/brainyard 0.1.0 → 0.2.0
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 +108 -0
- package/README.md +322 -104
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +23 -0
- package/dist/ask.js.map +1 -1
- package/dist/brains/adapter.d.ts +16 -2
- package/dist/brains/adapter.d.ts.map +1 -1
- package/dist/brains/adapter.js.map +1 -1
- package/dist/brains/index.d.ts.map +1 -1
- package/dist/brains/index.js +2 -1
- package/dist/brains/index.js.map +1 -1
- package/dist/brains/info.d.ts.map +1 -1
- package/dist/brains/info.js +22 -0
- package/dist/brains/info.js.map +1 -1
- package/dist/brains/opencode-bridge.d.ts +2 -0
- package/dist/brains/opencode-bridge.d.ts.map +1 -0
- package/dist/brains/opencode-bridge.js +332 -0
- package/dist/brains/opencode-bridge.js.map +1 -0
- package/dist/brains/opencode.d.ts +14 -0
- package/dist/brains/opencode.d.ts.map +1 -0
- package/dist/brains/opencode.js +474 -0
- package/dist/brains/opencode.js.map +1 -0
- package/dist/catalog.d.ts +8 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +100 -1
- package/dist/catalog.js.map +1 -1
- package/dist/codex-live.d.ts +12 -0
- package/dist/codex-live.d.ts.map +1 -0
- package/dist/codex-live.js +188 -0
- package/dist/codex-live.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/flags.d.ts.map +1 -1
- package/dist/flags.js +7 -5
- package/dist/flags.js.map +1 -1
- package/dist/humanize.d.ts.map +1 -1
- package/dist/humanize.js +19 -2
- package/dist/humanize.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/open.d.ts +87 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +324 -0
- package/dist/open.js.map +1 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +4 -2
- package/dist/options.js.map +1 -1
- package/dist/panes.d.ts +118 -0
- package/dist/panes.d.ts.map +1 -0
- package/dist/panes.js +478 -0
- package/dist/panes.js.map +1 -0
- package/dist/process.d.ts +26 -0
- package/dist/process.d.ts.map +1 -1
- package/dist/process.js +92 -2
- package/dist/process.js.map +1 -1
- package/dist/run.d.ts +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +11 -3
- package/dist/run.js.map +1 -1
- package/dist/sessions.d.ts +137 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/sessions.js +1023 -0
- package/dist/sessions.js.map +1 -0
- package/dist/status.d.ts +1 -1
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +28 -7
- package/dist/status.js.map +1 -1
- package/dist/subscription-limits.d.ts +12 -0
- package/dist/subscription-limits.d.ts.map +1 -0
- package/dist/subscription-limits.js +281 -0
- package/dist/subscription-limits.js.map +1 -0
- package/dist/types.d.ts +14 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/dist/usage-readers.d.ts +16 -0
- package/dist/usage-readers.d.ts.map +1 -0
- package/dist/usage-readers.js +194 -0
- package/dist/usage-readers.js.map +1 -0
- package/dist/usage.d.ts +71 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +403 -0
- package/dist/usage.js.map +1 -0
- package/package.json +7 -23
- package/README.ru.md +0 -334
- package/dist/cli/main.d.ts +0 -3
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js +0 -520
- package/dist/cli/main.js.map +0 -1
- package/dist/cli/term.d.ts +0 -20
- package/dist/cli/term.d.ts.map +0 -1
- package/dist/cli/term.js +0 -87
- package/dist/cli/term.js.map +0 -1
- package/dist/ui/dashboard.html +0 -693
- package/dist/ui/page.d.ts +0 -9
- package/dist/ui/page.d.ts.map +0 -1
- package/dist/ui/page.js +0 -12
- package/dist/ui/page.js.map +0 -1
- package/dist/ui/server.d.ts +0 -20
- package/dist/ui/server.d.ts.map +0 -1
- package/dist/ui/server.js +0 -409
- package/dist/ui/server.js.map +0 -1
package/dist/ui/dashboard.html
DELETED
|
@@ -1,693 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en" data-theme="dark">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>Brainyard</title>
|
|
7
|
-
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
8
|
-
<style>
|
|
9
|
-
:root {
|
|
10
|
-
--bg: #0b0d11;
|
|
11
|
-
--raise: #12151b;
|
|
12
|
-
--hover: #1b2029;
|
|
13
|
-
--line: #2a2f3a;
|
|
14
|
-
--text: #d4d8e1;
|
|
15
|
-
--bright: #f5f7fa;
|
|
16
|
-
--muted: #858d9c;
|
|
17
|
-
--faint: #5b6372;
|
|
18
|
-
--accent: #7d8cff;
|
|
19
|
-
--accent-ink: #0b0d11;
|
|
20
|
-
--green: #5ad08a;
|
|
21
|
-
--yellow: #e6c46e;
|
|
22
|
-
--red: #ff6b6b;
|
|
23
|
-
--blue: #6ea8ff;
|
|
24
|
-
--magenta: #c792ea;
|
|
25
|
-
--cyan: #5ccfe0;
|
|
26
|
-
--gray: #6b7280;
|
|
27
|
-
--claude: #e08a5f;
|
|
28
|
-
--codex: #4fbf9f;
|
|
29
|
-
--antigravity: #6ea8ff;
|
|
30
|
-
--mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
|
|
31
|
-
color-scheme: dark;
|
|
32
|
-
}
|
|
33
|
-
:root[data-theme="light"] {
|
|
34
|
-
--bg: #fbfaf7;
|
|
35
|
-
--raise: #f3f1eb;
|
|
36
|
-
--hover: #e9e6de;
|
|
37
|
-
--line: #d8d4c9;
|
|
38
|
-
--text: #25282e;
|
|
39
|
-
--bright: #0d0f12;
|
|
40
|
-
--muted: #6b6f78;
|
|
41
|
-
--faint: #9d9b95;
|
|
42
|
-
--accent: #4452e0;
|
|
43
|
-
--accent-ink: #ffffff;
|
|
44
|
-
--green: #17804a;
|
|
45
|
-
--yellow: #9a6a00;
|
|
46
|
-
--red: #cc3b36;
|
|
47
|
-
--blue: #2f6fdc;
|
|
48
|
-
--magenta: #8b4fd1;
|
|
49
|
-
--cyan: #137f8b;
|
|
50
|
-
--gray: #8a8f99;
|
|
51
|
-
--claude: #c0643c;
|
|
52
|
-
--codex: #178a6c;
|
|
53
|
-
--antigravity: #2f6fdc;
|
|
54
|
-
color-scheme: light;
|
|
55
|
-
}
|
|
56
|
-
* { box-sizing: border-box; }
|
|
57
|
-
/* biome-ignore lint/complexity/noImportantStyles: the hidden attribute must beat every display rule */
|
|
58
|
-
[hidden] { display: none !important; }
|
|
59
|
-
html, body { margin: 0; }
|
|
60
|
-
body { background: var(--bg); color: var(--text); font: 13px/1.6 var(--mono); font-variant-ligatures: none; -webkit-font-smoothing: antialiased; }
|
|
61
|
-
button, input, select, textarea { font: inherit; color: inherit; }
|
|
62
|
-
a { color: var(--accent); }
|
|
63
|
-
::selection { background: color-mix(in srgb, var(--accent) 38%, transparent); }
|
|
64
|
-
::placeholder { color: var(--faint); opacity: 1; }
|
|
65
|
-
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
|
|
66
|
-
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px 40px; }
|
|
67
|
-
.grow { flex: 1; }
|
|
68
|
-
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
|
|
69
|
-
|
|
70
|
-
/* ----- chrome: header, buttons, prompt-line headings --------------------- */
|
|
71
|
-
header { display: flex; align-items: center; gap: 6px; padding: 16px 0 12px; border-bottom: 1px solid var(--line); }
|
|
72
|
-
.brand { display: flex; align-items: baseline; gap: 1ch; font-weight: 700; color: var(--bright); }
|
|
73
|
-
.logo { color: var(--accent); }
|
|
74
|
-
.logo span:nth-child(2) { opacity: .75; }
|
|
75
|
-
.logo span:nth-child(3) { opacity: .5; }
|
|
76
|
-
.brand .ver { color: var(--muted); font-weight: 400; }
|
|
77
|
-
.btn { background: none; border: 0; border-radius: 3px; padding: 1px 4px; cursor: pointer; white-space: nowrap; color: var(--text); }
|
|
78
|
-
.btn::before { content: "[ "; color: var(--faint); }
|
|
79
|
-
.btn::after { content: " ]"; color: var(--faint); }
|
|
80
|
-
.btn:hover:not(:disabled) { background: var(--hover); color: var(--bright); }
|
|
81
|
-
.btn:active:not(:disabled) { background: var(--text); color: var(--bg); }
|
|
82
|
-
.btn:disabled { color: var(--faint); cursor: default; }
|
|
83
|
-
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 2px 14px; }
|
|
84
|
-
.btn.primary::before, .btn.primary::after { content: none; }
|
|
85
|
-
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 82%, var(--bright)); color: var(--accent-ink); }
|
|
86
|
-
.btn.danger { color: var(--red); }
|
|
87
|
-
|
|
88
|
-
h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 1ch; margin: 36px 0 4px; font-size: inherit; font-weight: 700; color: var(--bright); }
|
|
89
|
-
header + h2 { margin-top: 24px; }
|
|
90
|
-
h2 .ps1 { color: var(--accent); }
|
|
91
|
-
h2 small { font-size: inherit; font-weight: 400; color: var(--faint); }
|
|
92
|
-
.summary { color: var(--muted); min-height: 1.6em; }
|
|
93
|
-
.summary strong { color: var(--bright); }
|
|
94
|
-
.busy { color: var(--muted); }
|
|
95
|
-
.busy::before { content: "⠋"; display: inline-block; width: 2ch; color: var(--accent); animation: spin .8s step-end infinite; }
|
|
96
|
-
@keyframes spin {
|
|
97
|
-
0% { content: "⠋"; }
|
|
98
|
-
10% { content: "⠙"; }
|
|
99
|
-
20% { content: "⠹"; }
|
|
100
|
-
30% { content: "⠸"; }
|
|
101
|
-
40% { content: "⠼"; }
|
|
102
|
-
50% { content: "⠴"; }
|
|
103
|
-
60% { content: "⠦"; }
|
|
104
|
-
70% { content: "⠧"; }
|
|
105
|
-
80% { content: "⠇"; }
|
|
106
|
-
90% { content: "⠏"; }
|
|
107
|
-
}
|
|
108
|
-
@keyframes blink { 50% { opacity: 0; } }
|
|
109
|
-
.banner { border: 1px solid color-mix(in srgb, var(--yellow) 50%, var(--line)); border-radius: 6px; color: var(--yellow); padding: 8px 12px; margin: 8px 0 4px; }
|
|
110
|
-
.banner::before { content: "! "; }
|
|
111
|
-
.banner.error { border-color: color-mix(in srgb, var(--red) 50%, var(--line)); color: var(--red); }
|
|
112
|
-
.banner.error::before { content: "✗ "; }
|
|
113
|
-
|
|
114
|
-
/* ----- panels: a box with its title on the top border, like a TUI -------- */
|
|
115
|
-
.panel { position: relative; border: 1px solid var(--line); border-radius: 6px; }
|
|
116
|
-
.legend { position: absolute; top: 0; left: 10px; right: 10px; transform: translateY(-50%); display: flex; align-items: center; line-height: 1.3; white-space: nowrap; }
|
|
117
|
-
.legend > * { background: var(--bg); padding: 0 1ch; }
|
|
118
|
-
.legend > * + * { margin-left: 1ch; }
|
|
119
|
-
.legend > .grow { background: none; padding: 0; min-width: 1ch; }
|
|
120
|
-
[data-brain="claude"] { --brand: var(--claude); }
|
|
121
|
-
[data-brain="codex"] { --brand: var(--codex); }
|
|
122
|
-
[data-brain="antigravity"] { --brand: var(--antigravity); }
|
|
123
|
-
|
|
124
|
-
/* ----- status cards ------------------------------------------------------ */
|
|
125
|
-
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 26px 16px; margin-top: 20px; }
|
|
126
|
-
@media (max-width: 900px) { .cards { grid-template-columns: 1fr; } }
|
|
127
|
-
.cards[aria-busy="true"] > .card { opacity: .55; }
|
|
128
|
-
.card { display: flex; flex-direction: column; gap: 10px; padding: 16px 16px 12px; border-color: color-mix(in srgb, var(--brand, var(--line)) 45%, var(--line)); transition: opacity .2s; }
|
|
129
|
-
.card h3 { margin: 0; font-size: inherit; font-weight: 700; color: var(--brand, var(--bright)); }
|
|
130
|
-
.vendor { color: var(--muted); }
|
|
131
|
-
.badge { flex: none; }
|
|
132
|
-
.badge::before { content: "● "; }
|
|
133
|
-
.s-ready .badge { color: var(--green); }
|
|
134
|
-
.s-needs_login .badge, .s-limited .badge, .s-unknown .badge { color: var(--yellow); }
|
|
135
|
-
.s-error .badge { color: var(--red); }
|
|
136
|
-
.s-not_installed .badge { color: var(--gray); }
|
|
137
|
-
.card.s-not_installed { border-color: var(--line); opacity: .72; }
|
|
138
|
-
.kv { display: grid; grid-template-columns: 8ch minmax(0, 1fr); gap: 0 1ch; margin: 0; }
|
|
139
|
-
.kv dt { color: var(--muted); }
|
|
140
|
-
.kv dd { margin: 0; overflow-wrap: anywhere; }
|
|
141
|
-
.kv code { font: inherit; color: var(--muted); }
|
|
142
|
-
.ping { color: var(--muted); overflow-wrap: anywhere; }
|
|
143
|
-
.ping b { color: var(--bright); font-weight: 400; }
|
|
144
|
-
.bar { display: flex; gap: 1ch; color: var(--muted); white-space: nowrap; }
|
|
145
|
-
.bar .label { min-width: 10ch; }
|
|
146
|
-
.meter { color: var(--faint); overflow: hidden; }
|
|
147
|
-
.meter .fill { color: var(--green); }
|
|
148
|
-
.meter .fill.warn { color: var(--yellow); }
|
|
149
|
-
.meter .fill.full { color: var(--red); }
|
|
150
|
-
.caps { display: flex; flex-wrap: wrap; gap: 0 2ch; margin: 0; padding: 0; list-style: none; color: var(--faint); }
|
|
151
|
-
.caps li::before { content: "·"; display: inline-block; width: 2ch; }
|
|
152
|
-
.caps li.on { color: var(--text); }
|
|
153
|
-
.caps li.on::before { content: "✓"; color: var(--green); }
|
|
154
|
-
details.models summary { width: fit-content; cursor: pointer; color: var(--muted); list-style: none; }
|
|
155
|
-
details.models summary::-webkit-details-marker { display: none; }
|
|
156
|
-
details.models summary::before { content: "▸ "; }
|
|
157
|
-
details.models[open] summary::before { content: "▾ "; }
|
|
158
|
-
details.models summary:hover { color: var(--text); }
|
|
159
|
-
details.models table { width: 100%; border-collapse: collapse; margin-top: 2px; }
|
|
160
|
-
details.models td { padding: 0; vertical-align: top; }
|
|
161
|
-
details.models td:first-child { white-space: nowrap; padding-right: 2ch; }
|
|
162
|
-
details.models td:first-child::before { content: "├─ "; color: var(--faint); }
|
|
163
|
-
details.models tr:last-child td:first-child::before { content: "└─ "; }
|
|
164
|
-
details.models td:last-child { color: var(--muted); }
|
|
165
|
-
.fix { display: flex; gap: 1ch; align-items: flex-start; }
|
|
166
|
-
.fix::before { content: "→"; color: var(--yellow); }
|
|
167
|
-
.fix span { flex: 1; overflow-wrap: anywhere; }
|
|
168
|
-
.fix button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
|
|
169
|
-
.skeleton { min-height: 15.5em; padding: 14px 16px; border-style: dashed; }
|
|
170
|
-
|
|
171
|
-
/* ----- playground -------------------------------------------------------- */
|
|
172
|
-
.play { display: grid; gap: 12px; margin-top: 10px; padding: 14px 16px 16px; transition: border-color .15s; }
|
|
173
|
-
.play:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
|
|
174
|
-
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 3ch; }
|
|
175
|
-
.field { display: inline-flex; align-items: center; gap: 1ch; color: var(--muted); }
|
|
176
|
-
.select { position: relative; display: inline-flex; min-width: 0; }
|
|
177
|
-
.select::after { content: "▾"; position: absolute; right: 1ch; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
|
|
178
|
-
select, input[type="text"], textarea { background: var(--raise); border: 1px solid var(--line); border-radius: 4px; color: var(--text); }
|
|
179
|
-
select { appearance: none; max-width: 100%; padding: 2px 3ch 2px 1ch; cursor: pointer; text-overflow: ellipsis; }
|
|
180
|
-
select:disabled { color: var(--faint); cursor: default; }
|
|
181
|
-
input[type="text"] { padding: 2px 1ch; }
|
|
182
|
-
select:focus, input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
|
|
183
|
-
.seg { display: inline-flex; margin: 0; padding: 0; min-inline-size: 0; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
|
|
184
|
-
.seg button { background: none; border: 0; padding: 2px 1.5ch; cursor: pointer; color: var(--muted); }
|
|
185
|
-
.seg button + button { border-left: 1px solid var(--line); }
|
|
186
|
-
.seg button:hover { color: var(--text); }
|
|
187
|
-
.seg button:focus-visible { outline-offset: -3px; }
|
|
188
|
-
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
|
|
189
|
-
.check { position: relative; display: inline-flex; align-items: center; gap: 1ch; cursor: pointer; }
|
|
190
|
-
.check input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
|
|
191
|
-
.tick::before { content: "[ ]"; color: var(--muted); white-space: pre; }
|
|
192
|
-
.check:hover .tick::before { color: var(--text); }
|
|
193
|
-
.check input:checked + .tick::before { content: "[x]"; color: var(--green); }
|
|
194
|
-
.check input:focus-visible + .tick { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
|
|
195
|
-
.field.wide { display: flex; }
|
|
196
|
-
.field.wide input { flex: 1; min-width: 0; }
|
|
197
|
-
textarea { display: block; width: 100%; min-height: 7em; resize: vertical; padding: 8px 1.5ch; line-height: 1.6; caret-color: var(--accent); }
|
|
198
|
-
.submit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 2ch; }
|
|
199
|
-
.note { color: var(--faint); }
|
|
200
|
-
.chip { display: inline-flex; align-items: center; gap: 1ch; padding: 0 1ch; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 3px; color: var(--accent); }
|
|
201
|
-
.chip button { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; }
|
|
202
|
-
|
|
203
|
-
/* ----- session: one panel per ask or run --------------------------------- */
|
|
204
|
-
.session { display: grid; gap: 28px; margin-top: 20px; }
|
|
205
|
-
.run { padding-top: 12px; transition: border-color .2s; }
|
|
206
|
-
.run.live { border-color: color-mix(in srgb, var(--brand, var(--accent)) 60%, var(--line)); }
|
|
207
|
-
.run-head .title { flex: none; font-weight: 700; color: var(--brand, var(--bright)); }
|
|
208
|
-
.run-head .prompt { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
|
|
209
|
-
.run-head .clock { flex: none; color: var(--muted); }
|
|
210
|
-
.run-head .btn { flex: none; }
|
|
211
|
-
.feed { list-style: none; margin: 0; padding: 4px 0 10px; max-height: 420px; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
|
|
212
|
-
.feed li { display: grid; grid-template-columns: 6ch 2ch minmax(0, 1fr); column-gap: 1ch; padding: 0 16px; }
|
|
213
|
-
.feed .t { color: var(--faint); text-align: right; }
|
|
214
|
-
.feed .m { color: var(--gray); text-align: center; }
|
|
215
|
-
.feed .s { overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
216
|
-
.run.live .feed::after { content: ""; display: block; width: 1ch; height: 1.3em; margin: 2px 0 0 calc(16px + 10ch); background: var(--accent); animation: blink 1s step-end infinite; }
|
|
217
|
-
.k-message .m { color: var(--cyan); }
|
|
218
|
-
.k-init .s, .k-init .m { color: var(--blue); }
|
|
219
|
-
.k-hint .s, .k-hint .m { color: var(--magenta); }
|
|
220
|
-
.k-warning .s, .k-warning .m { color: var(--yellow); }
|
|
221
|
-
.k-thinking .s, .k-thinking .m, .k-tool_result .s, .k-tool_result .m { color: var(--muted); }
|
|
222
|
-
.k-error .s, .k-error .m, .k-denied .s, .k-denied .m, .k-stopped .s, .k-stopped .m, .is-error .s, .is-error .m { color: var(--red); }
|
|
223
|
-
.k-done .s, .k-done .m { color: var(--green); }
|
|
224
|
-
.k-done.failed .s, .k-done.failed .m { color: var(--red); }
|
|
225
|
-
.steer { display: flex; align-items: center; gap: 1ch; padding: 8px 16px; border-top: 1px dashed var(--line); }
|
|
226
|
-
.steer::before { content: "☞"; color: var(--magenta); }
|
|
227
|
-
.steer input { flex: 1; min-width: 0; }
|
|
228
|
-
.answer { padding: 10px 16px 12px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--bright); }
|
|
229
|
-
.run-head + .answer { border-top: 0; }
|
|
230
|
-
.answer.error { color: var(--red); }
|
|
231
|
-
.stats { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 2ch; padding: 5px 16px; border-top: 1px solid var(--line); border-radius: 0 0 5px 5px; background: var(--raise); color: var(--muted); }
|
|
232
|
-
.stats b { color: var(--bright); }
|
|
233
|
-
.stats .where { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 2ch; margin-left: auto; }
|
|
234
|
-
.stats .link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
|
|
235
|
-
.stats .link:hover { text-decoration: underline; }
|
|
236
|
-
footer { margin-top: 48px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--faint); }
|
|
237
|
-
@media (max-width: 560px) {
|
|
238
|
-
.wrap { padding: 0 14px 32px; }
|
|
239
|
-
header { flex-wrap: wrap; }
|
|
240
|
-
header .brand { flex: 1 1 100%; }
|
|
241
|
-
header .grow { display: none; }
|
|
242
|
-
.controls { gap: 8px 2ch; }
|
|
243
|
-
.field:not(.check) { flex: 1 1 100%; }
|
|
244
|
-
.field > span:first-child { min-width: 7ch; }
|
|
245
|
-
.field .select { flex: 1; }
|
|
246
|
-
.field select { width: 100%; }
|
|
247
|
-
}
|
|
248
|
-
@media (prefers-reduced-motion: reduce) {
|
|
249
|
-
.busy::before, .run.live .feed::after { animation: none; }
|
|
250
|
-
}
|
|
251
|
-
</style>
|
|
252
|
-
</head>
|
|
253
|
-
<body>
|
|
254
|
-
<div class="wrap">
|
|
255
|
-
<header>
|
|
256
|
-
<div class="brand">
|
|
257
|
-
<span class="logo" aria-hidden="true"><span>●</span><span>●</span><span>●</span></span>
|
|
258
|
-
brainyard <span class="ver">{{VERSION}}</span>
|
|
259
|
-
</div>
|
|
260
|
-
<div class="grow"></div>
|
|
261
|
-
<button class="btn" id="refresh" type="button" title="Check again (free)">refresh</button>
|
|
262
|
-
<button class="btn" id="live" type="button" title="One tiny real call per installed CLI — costs a fraction of a cent">live check</button>
|
|
263
|
-
<button class="btn" id="theme" type="button" title="Switch theme" aria-label="Switch theme">◐</button>
|
|
264
|
-
</header>
|
|
265
|
-
|
|
266
|
-
<h2><span class="ps1" aria-hidden="true">❯</span> <span id="status-cmd">brainyard status</span></h2>
|
|
267
|
-
<div id="banner"></div>
|
|
268
|
-
<div class="summary" id="summary" aria-live="polite"></div>
|
|
269
|
-
<section class="cards" id="cards" aria-label="Agent CLIs">
|
|
270
|
-
<div class="panel skeleton"><span class="busy">checking</span></div>
|
|
271
|
-
<div class="panel skeleton"><span class="busy">checking</span></div>
|
|
272
|
-
<div class="panel skeleton"><span class="busy">checking</span></div>
|
|
273
|
-
</section>
|
|
274
|
-
|
|
275
|
-
<h2><span class="ps1" aria-hidden="true">❯</span> <span id="play-cmd">brainyard ask</span> <small># ask a question, or give an agent a task and watch it work</small></h2>
|
|
276
|
-
<form class="play panel" id="form" autocomplete="off">
|
|
277
|
-
<div class="controls">
|
|
278
|
-
<label class="field"><span>brain</span><span class="select"><select id="brain"></select></span></label>
|
|
279
|
-
<div class="field"><span>mode</span>
|
|
280
|
-
<fieldset class="seg" aria-label="Mode">
|
|
281
|
-
<button type="button" data-mode="ask" aria-pressed="true">ask</button>
|
|
282
|
-
<button type="button" data-mode="run" aria-pressed="false">agent</button>
|
|
283
|
-
</fieldset>
|
|
284
|
-
</div>
|
|
285
|
-
<label class="field"><span>model</span><span class="select"><select id="model"></select></span></label>
|
|
286
|
-
<label class="field"><span>effort</span><span class="select"><select id="effort"></select></span></label>
|
|
287
|
-
<label class="field" data-for="run"><span>access</span><span class="select">
|
|
288
|
-
<select id="access">
|
|
289
|
-
<option value="workspace">workspace</option>
|
|
290
|
-
<option value="readonly">read-only</option>
|
|
291
|
-
<option value="full">full</option>
|
|
292
|
-
</select>
|
|
293
|
-
</span></label>
|
|
294
|
-
<label class="field check"><input type="checkbox" id="web"><span class="tick" aria-hidden="true"></span>web</label>
|
|
295
|
-
</div>
|
|
296
|
-
<label class="field wide" data-for="run"><span>folder</span><input type="text" id="cwd" placeholder="empty: a new temporary folder" spellcheck="false"></label>
|
|
297
|
-
<label class="sr" for="prompt">Prompt</label>
|
|
298
|
-
<textarea id="prompt" placeholder="Ask something…"></textarea>
|
|
299
|
-
<div class="submit-row">
|
|
300
|
-
<button class="btn primary" id="go" type="submit">ask</button>
|
|
301
|
-
<span id="resume"></span>
|
|
302
|
-
<span class="note" id="note">⌘/Ctrl + Enter</span>
|
|
303
|
-
</div>
|
|
304
|
-
</form>
|
|
305
|
-
|
|
306
|
-
<h2 id="session-title" hidden><span class="ps1" aria-hidden="true">❯</span> history <small># this session</small></h2>
|
|
307
|
-
<div class="session" id="session"></div>
|
|
308
|
-
<footer># Brainyard runs locally. The agents run on this machine, with your CLIs and your accounts.</footer>
|
|
309
|
-
</div>
|
|
310
|
-
|
|
311
|
-
<script>
|
|
312
|
-
'use strict';
|
|
313
|
-
(() => {
|
|
314
|
-
const $ = (id) => document.getElementById(id);
|
|
315
|
-
const h = (tag, props, ...children) => {
|
|
316
|
-
const node = document.createElement(tag);
|
|
317
|
-
for (const [key, value] of Object.entries(props || {})) {
|
|
318
|
-
if (value === undefined || value === null || value === false) continue;
|
|
319
|
-
if (key === 'class') node.className = value;
|
|
320
|
-
else if (key === 'dataset') Object.assign(node.dataset, value);
|
|
321
|
-
else if (key.startsWith('on')) node.addEventListener(key.slice(2), value);
|
|
322
|
-
else node.setAttribute(key, value === true ? '' : String(value));
|
|
323
|
-
}
|
|
324
|
-
for (const child of children.flat(Number.POSITIVE_INFINITY)) {
|
|
325
|
-
if (child === undefined || child === null || child === false) continue;
|
|
326
|
-
node.append(child instanceof Node ? child : document.createTextNode(String(child)));
|
|
327
|
-
}
|
|
328
|
-
return node;
|
|
329
|
-
};
|
|
330
|
-
const store = {
|
|
331
|
-
get(key) { try { return localStorage.getItem(key); } catch { return null; } },
|
|
332
|
-
set(key, value) { try { localStorage.setItem(key, value); } catch { /* private mode */ } },
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
// ----- theme -------------------------------------------------------------
|
|
336
|
-
const setTheme = (theme) => { document.documentElement.dataset.theme = theme; store.set('brainyard.theme', theme); };
|
|
337
|
-
setTheme(store.get('brainyard.theme') || 'dark');
|
|
338
|
-
$('theme').addEventListener('click', () => setTheme(document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'));
|
|
339
|
-
|
|
340
|
-
// ----- token: from the #fragment, kept for this tab only -------------------
|
|
341
|
-
const token = (() => {
|
|
342
|
-
const found = /token=([^&]+)/.exec(location.hash);
|
|
343
|
-
if (found) {
|
|
344
|
-
try { sessionStorage.setItem('brainyard.token', found[1]); } catch { /* ignore */ }
|
|
345
|
-
history.replaceState(null, '', location.pathname);
|
|
346
|
-
return found[1];
|
|
347
|
-
}
|
|
348
|
-
try { return sessionStorage.getItem('brainyard.token') || ''; } catch { return ''; }
|
|
349
|
-
})();
|
|
350
|
-
|
|
351
|
-
const banner = (text, kind) => {
|
|
352
|
-
const box = $('banner');
|
|
353
|
-
box.replaceChildren();
|
|
354
|
-
if (text) box.append(h('div', { class: `banner ${kind || ''}` }, text));
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
async function api(path, options = {}) {
|
|
358
|
-
const init = { method: options.method || 'GET', headers: { Authorization: `Bearer ${token}` } };
|
|
359
|
-
if (options.body !== undefined) {
|
|
360
|
-
init.headers['Content-Type'] = 'application/json';
|
|
361
|
-
init.body = JSON.stringify(options.body);
|
|
362
|
-
}
|
|
363
|
-
const res = await fetch(path, init);
|
|
364
|
-
const data = await res.json().catch(() => ({}));
|
|
365
|
-
if (!res.ok) {
|
|
366
|
-
const error = new Error((data.error?.message) || res.statusText);
|
|
367
|
-
error.kind = data.error?.kind;
|
|
368
|
-
error.fix = data.error?.fix;
|
|
369
|
-
error.status = res.status;
|
|
370
|
-
throw error;
|
|
371
|
-
}
|
|
372
|
-
return data;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// ----- status ------------------------------------------------------------
|
|
376
|
-
const WORDS = { ready: 'ready', needs_login: 'sign in', limited: 'limited', unknown: 'unknown', not_installed: 'not installed', error: 'error' };
|
|
377
|
-
const CAPS = [['steering', 'hints mid-run'], ['resume', 'resume'], ['mcp', 'MCP'], ['reportsCost', 'reports cost'], ['modelList', 'model list']];
|
|
378
|
-
const METER = 20;
|
|
379
|
-
const state = { report: null, brains: {}, mode: 'ask', resume: null };
|
|
380
|
-
|
|
381
|
-
function card(brain) {
|
|
382
|
-
const how = [brain.auth.method, brain.auth.plan].filter(Boolean).join(', ');
|
|
383
|
-
const rows = [];
|
|
384
|
-
if (brain.installed) {
|
|
385
|
-
rows.push(['version', brain.version || '—']);
|
|
386
|
-
let signed = { logged_in: 'signed in', logged_out: 'not signed in', unknown: 'not confirmed' }[brain.auth.state];
|
|
387
|
-
if (how) signed += ` · ${how}`;
|
|
388
|
-
if (brain.auth.account) signed += ` · ${brain.auth.account}`;
|
|
389
|
-
rows.push(['account', signed]);
|
|
390
|
-
if (brain.defaultModel) rows.push(['model', `${brain.defaultModel} (default)`]);
|
|
391
|
-
if (brain.path) rows.push(['binary', h('code', {}, brain.path)]);
|
|
392
|
-
}
|
|
393
|
-
const node = h('article', { class: `card panel s-${brain.availability}`, dataset: { brain: brain.id } },
|
|
394
|
-
h('div', { class: 'legend' },
|
|
395
|
-
h('h3', {}, brain.label),
|
|
396
|
-
h('span', { class: 'grow' }),
|
|
397
|
-
h('span', { class: 'badge' }, WORDS[brain.availability] || brain.availability),
|
|
398
|
-
),
|
|
399
|
-
h('div', { class: 'vendor' }, `${brain.vendor} · ${brain.binary}`),
|
|
400
|
-
rows.length ? h('dl', { class: 'kv' }, rows.map(([k, v]) => [h('dt', {}, k), h('dd', {}, v)])) : null,
|
|
401
|
-
);
|
|
402
|
-
if (brain.ping) {
|
|
403
|
-
if (brain.ping.ok) {
|
|
404
|
-
const cost = brain.ping.costUsd === null ? '' : ` · $${brain.ping.costUsd.toFixed(4)}`;
|
|
405
|
-
node.append(h('div', { class: 'ping' }, 'live: answered ', h('b', {}, `“${brain.ping.text}”`), ` in ${(brain.ping.ms / 1000).toFixed(1)}s${cost}${brain.ping.model ? ` · ${brain.ping.model}` : ''}`));
|
|
406
|
-
} else if (brain.ping.error) {
|
|
407
|
-
node.append(h('div', { class: 'ping' }, 'live: ', h('b', {}, brain.ping.error.kind), ` — ${brain.ping.error.message}`));
|
|
408
|
-
}
|
|
409
|
-
const windows = brain.ping.limits || [];
|
|
410
|
-
if (windows.length) {
|
|
411
|
-
node.append(h('div', { class: 'bars' }, windows.map((w) => {
|
|
412
|
-
const pct = Math.round(w.utilization * 100);
|
|
413
|
-
const cells = Math.max(0, Math.min(METER, Math.round((pct / 100) * METER)));
|
|
414
|
-
const resets = w.resetsAt ? ` · resets ${new Date(w.resetsAt * 1000).toLocaleString()}` : '';
|
|
415
|
-
return h('div', { class: 'bar', title: `${w.window}: ${pct}% used${resets}` },
|
|
416
|
-
h('span', { class: 'label' }, w.window.replace('_', '-')),
|
|
417
|
-
h('span', { class: 'meter', 'aria-hidden': 'true' },
|
|
418
|
-
h('span', { class: `fill ${pct >= 90 ? 'full' : pct >= 70 ? 'warn' : ''}` }, '█'.repeat(cells)), '░'.repeat(METER - cells)),
|
|
419
|
-
h('span', {}, `${pct}%`));
|
|
420
|
-
})));
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
node.append(h('ul', { class: 'caps', 'aria-label': 'Capabilities' },
|
|
424
|
-
CAPS.map(([key, label]) => h('li', { class: brain.capabilities[key] ? 'on' : '' }, label))));
|
|
425
|
-
if (brain.models?.models.length) {
|
|
426
|
-
node.append(h('details', { class: 'models' },
|
|
427
|
-
h('summary', {}, `${brain.models.models.length} models${brain.models.source === 'builtin' ? ' (built-in list)' : ''}`),
|
|
428
|
-
h('table', {}, h('tbody', {}, brain.models.models.map((m) => h('tr', {},
|
|
429
|
-
h('td', {}, m.id),
|
|
430
|
-
h('td', {}, m.efforts.length ? m.efforts.join(' · ') + (m.defaultEffort ? ` (default ${m.defaultEffort})` : '') : 'no effort setting')))))));
|
|
431
|
-
}
|
|
432
|
-
if (brain.fix && brain.availability !== 'ready') {
|
|
433
|
-
const text = brain.fix;
|
|
434
|
-
node.append(h('div', { class: 'fix' }, h('span', {}, text),
|
|
435
|
-
h('button', { type: 'button', onclick: (e) => { navigator.clipboard?.writeText(text); e.target.textContent = 'copied'; } }, 'copy')));
|
|
436
|
-
}
|
|
437
|
-
return node;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
async function loadStatus(live) {
|
|
441
|
-
$('refresh').disabled = true;
|
|
442
|
-
$('live').disabled = true;
|
|
443
|
-
$('status-cmd').textContent = `brainyard status${live ? ' --live' : ''}`;
|
|
444
|
-
$('cards').setAttribute('aria-busy', 'true');
|
|
445
|
-
$('summary').replaceChildren(h('span', { class: 'busy' }, live ? 'checking with a real call to each CLI…' : 'checking…'));
|
|
446
|
-
try {
|
|
447
|
-
const report = await api(`/api/status${live ? '?live=1' : ''}`);
|
|
448
|
-
state.report = report;
|
|
449
|
-
state.brains = Object.fromEntries(report.brains.map((b) => [b.id, b]));
|
|
450
|
-
$('cards').replaceChildren(...report.brains.map(card));
|
|
451
|
-
const at = new Date(report.checkedAt).toLocaleTimeString();
|
|
452
|
-
$('summary').replaceChildren(
|
|
453
|
-
h('strong', {}, `${report.ready.length} of ${report.brains.length} ready`),
|
|
454
|
-
` · checked ${at}${live ? ' with live calls' : ''} · node ${report.node} · ${report.platform}`);
|
|
455
|
-
fillBrains();
|
|
456
|
-
banner('');
|
|
457
|
-
} catch (error) {
|
|
458
|
-
$('summary').textContent = '';
|
|
459
|
-
$('cards').replaceChildren();
|
|
460
|
-
if (error.status === 401) banner('This page needs the access token. Open the link printed in the terminal where you ran `brainyard ui`.', 'error');
|
|
461
|
-
else banner(`Could not check: ${error.message}`, 'error');
|
|
462
|
-
} finally {
|
|
463
|
-
$('refresh').disabled = false;
|
|
464
|
-
$('live').disabled = false;
|
|
465
|
-
$('cards').removeAttribute('aria-busy');
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
$('refresh').addEventListener('click', () => loadStatus(false));
|
|
469
|
-
$('live').addEventListener('click', () => loadStatus(true));
|
|
470
|
-
|
|
471
|
-
// ----- playground controls -------------------------------------------------
|
|
472
|
-
function fillBrains() {
|
|
473
|
-
const select = $('brain');
|
|
474
|
-
const previous = select.value || store.get('brainyard.brain');
|
|
475
|
-
const installed = state.report.brains.filter((b) => b.installed);
|
|
476
|
-
select.replaceChildren(...installed.map((b) => h('option', { value: b.id }, `${b.label}${b.availability === 'ready' ? '' : ` (${WORDS[b.availability]})`}`)));
|
|
477
|
-
if (!installed.length) select.append(h('option', { value: '' }, 'no CLI installed'));
|
|
478
|
-
if (previous && installed.some((b) => b.id === previous)) select.value = previous;
|
|
479
|
-
fillModels();
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function catalog() {
|
|
483
|
-
const brain = state.brains[$('brain').value];
|
|
484
|
-
return brain?.models;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function fillModels() {
|
|
488
|
-
const models = catalog();
|
|
489
|
-
const select = $('model');
|
|
490
|
-
select.replaceChildren(h('option', { value: '' }, 'default'));
|
|
491
|
-
for (const m of (models?.models) || []) select.append(h('option', { value: m.id }, m.label && m.label !== m.id ? `${m.id} — ${m.label}` : m.id));
|
|
492
|
-
fillEfforts();
|
|
493
|
-
updateMode();
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
function fillEfforts() {
|
|
497
|
-
const models = catalog();
|
|
498
|
-
const chosen = models?.models.find((m) => m.id === $('model').value);
|
|
499
|
-
const efforts = chosen ? chosen.efforts : ((models?.defaultEfforts) || []);
|
|
500
|
-
const select = $('effort');
|
|
501
|
-
select.replaceChildren(h('option', { value: '' }, chosen?.defaultEffort ? `default (${chosen.defaultEffort})` : 'default'));
|
|
502
|
-
for (const e of efforts) select.append(h('option', { value: e }, e));
|
|
503
|
-
select.disabled = efforts.length === 0;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
$('brain').addEventListener('change', () => { store.set('brainyard.brain', $('brain').value); state.resume = null; showResume(); fillModels(); });
|
|
507
|
-
$('model').addEventListener('change', fillEfforts);
|
|
508
|
-
|
|
509
|
-
function updateMode() {
|
|
510
|
-
for (const button of document.querySelectorAll('.seg button')) button.setAttribute('aria-pressed', String(button.dataset.mode === state.mode));
|
|
511
|
-
for (const node of document.querySelectorAll('[data-for="run"]')) node.hidden = state.mode !== 'run';
|
|
512
|
-
$('prompt').placeholder = state.mode === 'run' ? 'Give the agent a task — it works in the folder above…' : 'Ask something…';
|
|
513
|
-
$('go').textContent = state.mode === 'run' ? 'start agent' : 'ask';
|
|
514
|
-
$('play-cmd').textContent = ['brainyard', state.mode, $('brain').value].filter(Boolean).join(' ');
|
|
515
|
-
}
|
|
516
|
-
for (const button of document.querySelectorAll('.seg button')) {
|
|
517
|
-
button.addEventListener('click', () => { state.mode = button.dataset.mode; if (state.mode === 'ask') { state.resume = null; showResume(); } updateMode(); });
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
function showResume() {
|
|
521
|
-
const box = $('resume');
|
|
522
|
-
box.replaceChildren();
|
|
523
|
-
if (!state.resume) return;
|
|
524
|
-
box.append(h('span', { class: 'chip' }, `continuing ${state.resume.slice(0, 8)}…`,
|
|
525
|
-
h('button', { type: 'button', title: 'Start a new conversation', onclick: () => { state.resume = null; showResume(); } }, '✕')));
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
$('prompt').addEventListener('keydown', (event) => {
|
|
529
|
-
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) { event.preventDefault(); $('form').requestSubmit(); }
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
// ----- running ----------------------------------------------------------------
|
|
533
|
-
const MARKS = { init: '◆', message: '›', thinking: '…', tool_call: '▸', command: '$', file_write: '✎', tool_result: '←', hint: '☞', denied: '⊘', warning: '!', error: '✗', stopped: '■', done: '✓' };
|
|
534
|
-
const labelOf = (id) => (state.brains[id]?.label) || id;
|
|
535
|
-
|
|
536
|
-
function panel(brainId, prompt) {
|
|
537
|
-
$('session-title').hidden = false;
|
|
538
|
-
const started = Date.now();
|
|
539
|
-
const clock = h('span', { class: 'clock' }, '0.0s');
|
|
540
|
-
const timer = setInterval(() => { clock.textContent = `${((Date.now() - started) / 1000).toFixed(1)}s`; }, 100);
|
|
541
|
-
const head = h('div', { class: 'legend run-head' }, h('span', { class: 'title' }, labelOf(brainId)), h('span', { class: 'prompt', title: prompt }, prompt), h('span', { class: 'grow' }), clock);
|
|
542
|
-
const node = h('section', { class: 'run panel live', dataset: { brain: brainId } }, head);
|
|
543
|
-
$('session').prepend(node);
|
|
544
|
-
return { node, head, started, clock, stopTimer: () => { clearInterval(timer); node.classList.remove('live'); } };
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
function stats(result) {
|
|
548
|
-
const parts = [];
|
|
549
|
-
parts.push(h('span', {}, h('b', {}, `${(result.durationMs / 1000).toFixed(1)}s`)));
|
|
550
|
-
if (result.costUsd !== null && result.costUsd !== undefined) parts.push(h('span', {}, h('b', {}, `$${result.costUsd.toFixed(4)}`), result.costSource === 'estimate' ? ' est.' : ''));
|
|
551
|
-
if (result.model) parts.push(h('span', {}, result.model));
|
|
552
|
-
const u = result.usage || {};
|
|
553
|
-
const tokens = (u.inputTokens || 0) + (u.cacheReadTokens || 0) + (u.cacheWriteTokens || 0);
|
|
554
|
-
parts.push(h('span', {}, `${tokens.toLocaleString()} in · ${(u.outputTokens || 0).toLocaleString()} out`));
|
|
555
|
-
if (result.toolCalls !== undefined) parts.push(h('span', {}, `${result.toolCalls} actions`));
|
|
556
|
-
return parts;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
async function doAsk(body) {
|
|
560
|
-
const view = panel(body.brain, body.prompt);
|
|
561
|
-
const answer = h('div', { class: 'answer' }, h('span', { class: 'busy' }, 'thinking…'));
|
|
562
|
-
view.node.append(answer);
|
|
563
|
-
try {
|
|
564
|
-
const result = await api('/api/ask', { method: 'POST', body });
|
|
565
|
-
answer.replaceChildren(result.text);
|
|
566
|
-
view.node.append(h('div', { class: 'stats' }, stats(result)));
|
|
567
|
-
} catch (error) {
|
|
568
|
-
answer.className = 'answer error';
|
|
569
|
-
answer.replaceChildren(`${error.kind || 'error'}: ${error.message}`, error.fix ? `\n→ ${error.fix}` : '');
|
|
570
|
-
} finally {
|
|
571
|
-
view.stopTimer();
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
async function doRun(body) {
|
|
576
|
-
let created;
|
|
577
|
-
try {
|
|
578
|
-
created = await api('/api/runs', { method: 'POST', body });
|
|
579
|
-
} catch (error) {
|
|
580
|
-
const view = panel(body.brain, body.prompt);
|
|
581
|
-
view.stopTimer();
|
|
582
|
-
view.node.append(h('div', { class: 'answer error' }, `${error.kind || 'error'}: ${error.message}${error.fix ? `\n→ ${error.fix}` : ''}`));
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
const view = panel(body.brain, body.prompt);
|
|
586
|
-
const feed = h('ol', { class: 'feed', 'aria-live': 'polite' });
|
|
587
|
-
const stop = h('button', { class: 'btn danger', type: 'button', onclick: () => api(`/api/runs/${created.id}/stop`, { method: 'POST', body: {} }).catch(() => {}) }, 'stop');
|
|
588
|
-
view.head.append(stop);
|
|
589
|
-
view.node.append(feed);
|
|
590
|
-
let steer = null;
|
|
591
|
-
if (created.steerable) {
|
|
592
|
-
const input = h('input', { type: 'text', placeholder: 'Message the agent while it works…', 'aria-label': 'Hint' });
|
|
593
|
-
const send = async () => {
|
|
594
|
-
const text = input.value.trim();
|
|
595
|
-
if (!text) return;
|
|
596
|
-
input.value = '';
|
|
597
|
-
await api(`/api/runs/${created.id}/hint`, { method: 'POST', body: { text } }).catch(() => {});
|
|
598
|
-
};
|
|
599
|
-
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); send(); } });
|
|
600
|
-
steer = h('div', { class: 'steer' }, input, h('button', { class: 'btn', type: 'button', onclick: send }, 'send'));
|
|
601
|
-
view.node.append(steer);
|
|
602
|
-
}
|
|
603
|
-
const add = (event) => {
|
|
604
|
-
const offset = Math.max(0, (Date.parse(event.at) - view.started) / 1000);
|
|
605
|
-
const failed = event.kind === 'done' && event.data && event.data.ok === false;
|
|
606
|
-
const classes = [`k-${event.kind}`, event.data?.isError ? 'is-error' : '', failed ? 'failed' : ''].join(' ');
|
|
607
|
-
const nearBottom = feed.scrollHeight - feed.scrollTop - feed.clientHeight < 40;
|
|
608
|
-
feed.append(h('li', { class: classes }, h('span', { class: 't' }, `${offset.toFixed(1)}s`), h('span', { class: 'm' }, failed ? '✗' : MARKS[event.kind] || '·'), h('span', { class: 's' }, event.summary)));
|
|
609
|
-
if (nearBottom) feed.scrollTop = feed.scrollHeight;
|
|
610
|
-
};
|
|
611
|
-
try {
|
|
612
|
-
await follow(created.id, (name, data) => {
|
|
613
|
-
if (name === 'agent' && data.feed) add(data);
|
|
614
|
-
if (name === 'result') finish(data);
|
|
615
|
-
if (name === 'failure') view.node.append(h('div', { class: 'answer error' }, `${data.error.kind}: ${data.error.message}`));
|
|
616
|
-
});
|
|
617
|
-
} catch (error) {
|
|
618
|
-
view.node.append(h('div', { class: 'answer error' }, `stream lost: ${error.message}`));
|
|
619
|
-
} finally {
|
|
620
|
-
view.stopTimer();
|
|
621
|
-
stop.remove();
|
|
622
|
-
if (steer) steer.remove();
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
function finish(result) {
|
|
626
|
-
if (result.text?.trim()) view.node.append(h('div', { class: 'answer' }, result.text.trim()));
|
|
627
|
-
else if (!result.ok && result.error) view.node.append(h('div', { class: 'answer error' }, `${result.error.kind}: ${result.error.message}`));
|
|
628
|
-
const folder = created.cwd.split(/[\\/]/).filter(Boolean).pop() || created.cwd;
|
|
629
|
-
const copy = h('button', { class: 'link', type: 'button', title: created.cwd, onclick: (e) => { navigator.clipboard?.writeText(created.cwd); e.target.textContent = 'copied'; } }, 'copy path');
|
|
630
|
-
const where = h('span', { class: 'where' }, h('span', { title: created.cwd }, `folder …/${folder}`), copy);
|
|
631
|
-
const row = h('div', { class: 'stats' }, stats(result), where);
|
|
632
|
-
if (result.sessionId) {
|
|
633
|
-
where.append(h('button', { class: 'btn', type: 'button', onclick: () => {
|
|
634
|
-
state.mode = 'run'; state.resume = result.sessionId;
|
|
635
|
-
$('brain').value = body.brain; fillModels(); $('cwd').value = created.cwd; updateMode(); showResume(); $('prompt').focus();
|
|
636
|
-
} }, 'continue'));
|
|
637
|
-
}
|
|
638
|
-
view.node.append(row);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
async function follow(id, onEvent) {
|
|
643
|
-
const res = await fetch(`/api/runs/${id}/events`, { headers: { Authorization: `Bearer ${token}` } });
|
|
644
|
-
if (!res.ok || !res.body) throw new Error(res.statusText || 'no stream');
|
|
645
|
-
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
646
|
-
let buffer = '';
|
|
647
|
-
for (;;) {
|
|
648
|
-
const { value, done } = await reader.read();
|
|
649
|
-
if (done) break;
|
|
650
|
-
buffer += value;
|
|
651
|
-
for (let cut = buffer.indexOf('\n\n'); cut >= 0; cut = buffer.indexOf('\n\n')) {
|
|
652
|
-
const chunk = buffer.slice(0, cut);
|
|
653
|
-
buffer = buffer.slice(cut + 2);
|
|
654
|
-
let name = 'message';
|
|
655
|
-
let data = '';
|
|
656
|
-
for (const line of chunk.split('\n')) {
|
|
657
|
-
if (line.startsWith('event: ')) name = line.slice(7);
|
|
658
|
-
else if (line.startsWith('data: ')) data += line.slice(6);
|
|
659
|
-
}
|
|
660
|
-
if (data) onEvent(name, JSON.parse(data));
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
$('form').addEventListener('submit', async (event) => {
|
|
666
|
-
event.preventDefault();
|
|
667
|
-
const prompt = $('prompt').value.trim();
|
|
668
|
-
const brain = $('brain').value;
|
|
669
|
-
if (!prompt || !brain) { $('prompt').focus(); return; }
|
|
670
|
-
const body = { brain, prompt };
|
|
671
|
-
if ($('model').value) body.model = $('model').value;
|
|
672
|
-
if ($('effort').value) body.effort = $('effort').value;
|
|
673
|
-
body.web = $('web').checked;
|
|
674
|
-
$('prompt').value = '';
|
|
675
|
-
if (state.mode === 'ask') {
|
|
676
|
-
await doAsk(body);
|
|
677
|
-
} else {
|
|
678
|
-
body.access = $('access').value;
|
|
679
|
-
if ($('cwd').value.trim()) body.cwd = $('cwd').value.trim();
|
|
680
|
-
if (state.resume) body.resume = state.resume;
|
|
681
|
-
await doRun(body);
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
updateMode();
|
|
686
|
-
if (!token) {
|
|
687
|
-
$('cards').replaceChildren();
|
|
688
|
-
banner('This page needs the access token. Open the link printed in the terminal where you ran `brainyard ui`.', 'error');
|
|
689
|
-
} else loadStatus(false);
|
|
690
|
-
})();
|
|
691
|
-
</script>
|
|
692
|
-
</body>
|
|
693
|
-
</html>
|