pinokiod 8.3.12 → 8.3.14
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/kernel/agent_instructions.js +0 -1
- package/kernel/api/index.js +76 -12
- package/kernel/environment.js +1 -1
- package/kernel/index.js +15 -2
- package/kernel/plugin_sources.js +1 -1
- package/kernel/prototype.js +1 -1
- package/kernel/request_file.js +5 -14
- package/kernel/shell.js +12 -0
- package/kernel/shells.js +13 -1
- package/package.json +1 -1
- package/server/index.js +10 -5
- package/server/lib/agent_jobs.js +198 -0
- package/server/lib/agent_sessions.js +131 -0
- package/server/lib/brain.js +161 -91
- package/server/lib/content_validation.js +1 -1
- package/server/public/agent-bar-app.js +28 -6
- package/server/public/agent-bar-compose.css +675 -0
- package/server/public/agent-bar-compose.js +618 -0
- package/server/public/agent-bar-panel.css +2 -0
- package/server/public/agent-bar-panel.js +22 -7
- package/server/public/agent-bar-shell.css +38 -0
- package/server/public/agent-bar-shell.js +128 -34
- package/server/public/agent-bar.css +7 -1
- package/server/public/agent-bar.js +8 -1
- package/server/public/terminal_input_utils.js +9 -1
- package/server/views/app.ejs +5 -1
- package/server/views/partials/main_sidebar.ejs +2 -0
- package/system/plugin/antigravity-cli-auto/pinokio.js +44 -6
- package/system/plugin/claude/pinokio.js +43 -1
- package/system/plugin/claude-auto/pinokio.js +43 -1
- package/system/plugin/codex/pinokio.js +42 -1
- package/system/plugin/codex-auto/pinokio.js +42 -1
- package/system/plugin/grok/pinokio.js +1 -1
- package/system/plugin/grok-auto/pinokio.js +37 -10
- package/system/plugin/opencode/pinokio.js +24 -0
- package/system/plugin/opencode-auto/pinokio.js +82 -10
- package/test/agent-bar-compose.test.js +487 -0
- package/test/agent-bar-shell.test.js +149 -0
- package/test/agent-instructions.test.js +0 -2
- package/test/agent-jobs.test.js +534 -0
- package/test/agent-sessions.test.js +130 -0
- package/test/antigravity-cli-plugin.test.js +63 -18
- package/test/anywhere-api.test.js +1 -1
- package/test/anywhere-onboarding.test.js +1 -2
- package/test/brain.test.js +116 -69
- package/test/grok-plugin.test.js +2 -1
- package/test/opencode-plugin.test.js +7 -4
- package/test/plugin-action-functions.test.js +423 -0
- package/test/request-file.test.js +1 -12
- package/test/shell-log-path.test.js +64 -0
- package/test/shell-stop-while-starting.test.js +70 -0
- package/test/shells-live-error.test.js +66 -2
- package/test/terminal-mouse-input.test.js +27 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
// Agent bar: the compose view.
|
|
2
|
+
//
|
|
3
|
+
// When you go to type in the bar, its field grows into a larger box with the
|
|
4
|
+
// Pinokio face in it. Both bars get it: the one with Ask, Create app, Create
|
|
5
|
+
// plugin and Download (agent-bar.js), and the one on an app's page, which only
|
|
6
|
+
// asks (agent-bar-app.js).
|
|
7
|
+
// The box is the bar's own field made larger: the text area is never replaced
|
|
8
|
+
// or moved in the page, so the cursor and what is typed survive every change.
|
|
9
|
+
//
|
|
10
|
+
// Three shapes, as data-compose on .agent-bar (no attribute: the bar at rest):
|
|
11
|
+
// place desktop, when you go to the bar: grows downward where it is
|
|
12
|
+
// centre desktop, when a pre-filled link opens it: centred, page dimmed
|
|
13
|
+
// screen phones: the part of the screen above the on-screen keyboard
|
|
14
|
+
//
|
|
15
|
+
// Each bar still decides everything it decides today: the modes, the folder
|
|
16
|
+
// names, what is sent. It draws itself again on every change and writes what it
|
|
17
|
+
// shows on .agent-bar (data-item, data-engaged, data-busy). This file watches
|
|
18
|
+
// that and lays the same parts out again. From a bar's own script it uses two
|
|
19
|
+
// things only: leave() and tool(), on PinokioAgentBar or PinokioAgentBarApp.
|
|
20
|
+
(function (window, document) {
|
|
21
|
+
'use strict';
|
|
22
|
+
if (window.PinokioAgentCompose) return;
|
|
23
|
+
const bar = window.PinokioAgentBar;
|
|
24
|
+
if (!bar || !bar.ready) return;
|
|
25
|
+
window.PinokioAgentCompose = true;
|
|
26
|
+
|
|
27
|
+
// A pre-filled link (?universal...). Read now: common.js tidies the address
|
|
28
|
+
// before it hands the link to the bar.
|
|
29
|
+
let linkPending = false;
|
|
30
|
+
try {
|
|
31
|
+
linkPending = new URLSearchParams(window.location.search).has('universal');
|
|
32
|
+
} catch (_) {}
|
|
33
|
+
|
|
34
|
+
const SPEED = 220;
|
|
35
|
+
const EASE = 'cubic-bezier(0.2, 0.8, 0.2, 1)';
|
|
36
|
+
const MAX_LINES = 8;
|
|
37
|
+
const LISTEN_MS = 1200;
|
|
38
|
+
// phone: the big face and the gap under it (the greeting is measured), and
|
|
39
|
+
// the first line of text that stays clear of them
|
|
40
|
+
const HERO_FACE = 84 + 14;
|
|
41
|
+
const GREETING_LINE = 24;
|
|
42
|
+
const FIRST_LINE = 34;
|
|
43
|
+
const GREETINGS = {
|
|
44
|
+
ask: 'What should we do?',
|
|
45
|
+
create_app: 'What should this app do?',
|
|
46
|
+
create_plugin: 'What should this plugin do?',
|
|
47
|
+
download: 'What should we download?',
|
|
48
|
+
};
|
|
49
|
+
const LINK_GREETING = 'Ready when you are';
|
|
50
|
+
// the starter text agent-bar.js gives Create plugin (PLUGIN_PROMPT_SEED there)
|
|
51
|
+
const PLUGIN_SEED = 'A Pinokio plugin for: ';
|
|
52
|
+
// The face: the filled mark the mode chip has at rest, and the same character
|
|
53
|
+
// as an outline (head, nose, two eyes, mouth) once the view is open.
|
|
54
|
+
const FACE = '<svg class="agent-compose__mark" viewBox="9 9 82 82"><path fill="currentColor" fill-rule="evenodd" d="M50 9A41 41 0 1 1 50 91A41 41 0 1 1 50 9ZM34 31H46V42H34V31ZM58 31H70V42H58V31ZM56 47H76A6 6 0 0 1 82 53A6 6 0 0 1 76 59H56V47ZM39 65H70V74H39V65Z"/></svg>'
|
|
55
|
+
+ '<svg class="agent-compose__line" viewBox="5.25 9.25 81.5 81.5">'
|
|
56
|
+
+ '<circle class="agent-compose__head" cx="46" cy="50" r="38" fill="none" stroke="currentColor" stroke-width="5.5"/>'
|
|
57
|
+
+ '<circle class="agent-compose__arc" cx="46" cy="50" r="38" fill="none" stroke="currentColor" stroke-width="5.5" stroke-linecap="round" stroke-dasharray="64 175"/>'
|
|
58
|
+
+ '<path class="agent-compose__nose" d="M60 44H87a7 7 0 0 1 0 14H60" stroke="currentColor" stroke-width="5.5"/>'
|
|
59
|
+
+ '<rect class="agent-compose__eye" x="45" y="28" width="10" height="10" fill="currentColor"/>'
|
|
60
|
+
+ '<rect class="agent-compose__eye" x="65" y="28" width="10" height="10" fill="currentColor"/>'
|
|
61
|
+
+ '<rect class="agent-compose__mouth" x="50" y="68" width="22" height="7" fill="currentColor"/>'
|
|
62
|
+
+ '</svg>';
|
|
63
|
+
|
|
64
|
+
const matches = (query) => Boolean(window.matchMedia && window.matchMedia(query).matches);
|
|
65
|
+
// An app's page has a phone layout of its own, which starts wider. Its bar
|
|
66
|
+
// then sits in the page's strip, and agent-bar-app.js marks the page.
|
|
67
|
+
const APP_PHONE_CLASS = 'agent-bar-app-phone';
|
|
68
|
+
// a finger is the main pointer: there is no Shift+Enter to add a line with
|
|
69
|
+
const isTouch = () => matches('(pointer: coarse)');
|
|
70
|
+
const isStill = () => matches('(prefers-reduced-motion: reduce)');
|
|
71
|
+
|
|
72
|
+
function el(tag, className, text) {
|
|
73
|
+
const node = document.createElement(tag);
|
|
74
|
+
if (className) node.className = className;
|
|
75
|
+
if (text != null) node.textContent = text;
|
|
76
|
+
return node;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function install() {
|
|
80
|
+
const root = document.querySelector('.agent-bar');
|
|
81
|
+
if (!root) return false;
|
|
82
|
+
if (root.classList.contains('agent-compose')) return true;
|
|
83
|
+
// the app page's bar: Ask only, so no mode chip and no folder row
|
|
84
|
+
const isApp = root.dataset.item === 'ask_app';
|
|
85
|
+
const host = isApp ? window.PinokioAgentBarApp : bar;
|
|
86
|
+
if (!host) return false;
|
|
87
|
+
const isPhone = () => (isApp
|
|
88
|
+
? document.documentElement.classList.contains(APP_PHONE_CLASS)
|
|
89
|
+
: matches('(max-width: 768px)'));
|
|
90
|
+
const inner = root.querySelector('.agent-bar__inner');
|
|
91
|
+
const field = root.querySelector('.agent-bar__field');
|
|
92
|
+
const top = root.querySelector('.agent-bar__top');
|
|
93
|
+
const input = root.querySelector('.agent-bar__input');
|
|
94
|
+
const scope = root.querySelector('.agent-bar__scope');
|
|
95
|
+
const go = root.querySelector('.agent-bar__go');
|
|
96
|
+
const agentButton = root.querySelector('.agent-bar__agent');
|
|
97
|
+
const footer = root.querySelector('.agent-bar__footer');
|
|
98
|
+
const note = root.querySelector('.agent-bar__note');
|
|
99
|
+
const menu = root.querySelector('.agent-bar__menu:not(.agent-bar__menu--running)');
|
|
100
|
+
if (!inner || !field || !top || !input || !go || !agentButton || !note || !menu) return false;
|
|
101
|
+
if (!isApp && (!scope || !footer)) return false;
|
|
102
|
+
const nameInputs = footer ? Array.from(footer.querySelectorAll('.agent-bar__name-input')) : [];
|
|
103
|
+
// what the app page's bar says at rest ("Ask Pinokio about <app>…"); it never sets it again
|
|
104
|
+
const restPlaceholder = input.placeholder;
|
|
105
|
+
// made by agent-bar-attach.js and agent-bar-panel.js, possibly after this
|
|
106
|
+
const clip = () => root.querySelector('.agent-bar__attach');
|
|
107
|
+
const files = () => root.querySelector('.agent-bar__files');
|
|
108
|
+
const runChip = () => root.querySelector('.agent-bar__running');
|
|
109
|
+
const runMenu = () => root.querySelector('.agent-bar__menu--running');
|
|
110
|
+
|
|
111
|
+
// ---- what this file adds to the bar ----
|
|
112
|
+
// the box's own background, so it can change size without stretching what is in it
|
|
113
|
+
const bg = el('div', 'agent-compose__bg');
|
|
114
|
+
// phones: close, and where the face sits once you type
|
|
115
|
+
const toprow = el('div', 'agent-compose__toprow');
|
|
116
|
+
const x = el('button', 'agent-compose__x');
|
|
117
|
+
x.type = 'button';
|
|
118
|
+
x.setAttribute('aria-label', 'Close');
|
|
119
|
+
x.innerHTML = '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13"/></svg>';
|
|
120
|
+
const slotTop = el('span', 'agent-compose__slot agent-compose__slot--top');
|
|
121
|
+
toprow.append(x, slotTop);
|
|
122
|
+
// the large face and what it says
|
|
123
|
+
const hero = el('div', 'agent-compose__hero');
|
|
124
|
+
const slotHero = el('span', 'agent-compose__slot agent-compose__slot--hero');
|
|
125
|
+
const greet = el('div', 'agent-compose__greet');
|
|
126
|
+
hero.append(slotHero, greet);
|
|
127
|
+
// the small face beside the text, and at rest in the mode chip
|
|
128
|
+
const slotSide = el('span', 'agent-compose__slot agent-compose__slot--side');
|
|
129
|
+
const slotChip = el('span', 'agent-compose__slot agent-compose__slot--chip');
|
|
130
|
+
const face = el('span', 'agent-compose__face');
|
|
131
|
+
face.setAttribute('aria-hidden', 'true');
|
|
132
|
+
face.dataset.face = 'idle';
|
|
133
|
+
face.innerHTML = FACE;
|
|
134
|
+
slotChip.appendChild(face);
|
|
135
|
+
// the bottom row of the open view: mode at the left; attach, agent and send at the right
|
|
136
|
+
const controls = el('div', 'agent-compose__controls');
|
|
137
|
+
const grow = el('span', 'agent-compose__grow');
|
|
138
|
+
controls.appendChild(grow);
|
|
139
|
+
const agentName = el('span', 'agent-compose__agent-name');
|
|
140
|
+
const dim = el('div', 'agent-compose__dim');
|
|
141
|
+
|
|
142
|
+
field.insertBefore(bg, field.firstChild);
|
|
143
|
+
field.insertBefore(toprow, top);
|
|
144
|
+
field.insertBefore(hero, top);
|
|
145
|
+
top.insertBefore(slotSide, input);
|
|
146
|
+
// (the app page's bar has a bare mark where the home bar has its mode chip)
|
|
147
|
+
if (scope) scope.insertBefore(slotChip, scope.firstChild);
|
|
148
|
+
else top.insertBefore(slotChip, top.firstChild);
|
|
149
|
+
// A message is a row of the box. At rest it hangs below the bar as before.
|
|
150
|
+
field.appendChild(note);
|
|
151
|
+
field.appendChild(controls);
|
|
152
|
+
agentButton.insertBefore(agentName, agentButton.querySelector('.agent-bar__caret'));
|
|
153
|
+
inner.appendChild(dim);
|
|
154
|
+
root.classList.add('agent-compose');
|
|
155
|
+
|
|
156
|
+
// ---- state ----
|
|
157
|
+
let open = false; // the view is open
|
|
158
|
+
let centre = false; // opened by a pre-filled link (desktop: the centred box)
|
|
159
|
+
let arriving = false; // a pre-filled link is being handed to the bar right now
|
|
160
|
+
let wasEngaged = root.dataset.engaged === 'true';
|
|
161
|
+
let shape = ''; // '' | 'place' | 'centre' | 'screen'
|
|
162
|
+
let roomy = true; // phone: the large face fits under the text
|
|
163
|
+
let lastKey = null;
|
|
164
|
+
let cache = null; // where every part was, before the change being made
|
|
165
|
+
let running = []; // moves in flight
|
|
166
|
+
let listenTimer = 0;
|
|
167
|
+
let pushed = false; // phone: a history entry stands for the open view
|
|
168
|
+
let observer = null;
|
|
169
|
+
|
|
170
|
+
const item = () => root.dataset.item || 'ask';
|
|
171
|
+
const isBusy = () => root.dataset.busy === 'true';
|
|
172
|
+
const isDownload = () => item() === 'download';
|
|
173
|
+
const hasFolder = () => ['create_app', 'create_plugin', 'download'].includes(item());
|
|
174
|
+
const leave = () => { if (typeof host.leave === 'function') host.leave(); };
|
|
175
|
+
|
|
176
|
+
// ---- the part of a phone's screen that the keyboard leaves ----
|
|
177
|
+
function syncViewport() {
|
|
178
|
+
const vv = window.visualViewport;
|
|
179
|
+
root.style.setProperty('--agent-compose-vvh', `${vv ? vv.height : window.innerHeight}px`);
|
|
180
|
+
root.style.setProperty('--agent-compose-vvt', `${vv ? vv.offsetTop : 0}px`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ---- where every part is ----
|
|
184
|
+
const movers = () => [bg, scope, input, clip(), agentButton, go, face, footer, runChip()].filter(Boolean);
|
|
185
|
+
// these do not travel: they come in once the box has mostly arrived
|
|
186
|
+
// (the agent, send and the mode's name are among them on a phone, whose bar at rest has none)
|
|
187
|
+
const scopeLabel = scope ? scope.querySelector('.agent-bar__scope-label') : null;
|
|
188
|
+
const faders = () => [clip(), x, greet, footer, note, files(), runChip(), agentName, agentButton, go, scopeLabel].filter(Boolean);
|
|
189
|
+
function measure() {
|
|
190
|
+
const rects = new Map();
|
|
191
|
+
movers().concat(faders()).forEach((node) => rects.set(node, node.getBoundingClientRect()));
|
|
192
|
+
const style = window.getComputedStyle(input);
|
|
193
|
+
return { rects, font: style.fontSize, lead: style.lineHeight, radius: window.getComputedStyle(bg).borderRadius };
|
|
194
|
+
}
|
|
195
|
+
// Taken as an action begins (a press, a key), before the bar reacts to it.
|
|
196
|
+
function snapshot() {
|
|
197
|
+
cache = measure();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const isMoving = () => running.some((animation) => animation.playState === 'running');
|
|
201
|
+
function stopMoves() {
|
|
202
|
+
running.forEach((animation) => { try { animation.cancel(); } catch (_) {} });
|
|
203
|
+
running = [];
|
|
204
|
+
}
|
|
205
|
+
function play(node, frames, options) {
|
|
206
|
+
if (typeof node.animate !== 'function') return;
|
|
207
|
+
running.push(node.animate(frames, options));
|
|
208
|
+
}
|
|
209
|
+
// One change of layout, played as a move: every part goes from where it was
|
|
210
|
+
// to where it now is.
|
|
211
|
+
function move(before, after) {
|
|
212
|
+
const box = field.getBoundingClientRect();
|
|
213
|
+
const options = { duration: SPEED, easing: EASE };
|
|
214
|
+
movers().forEach((node) => {
|
|
215
|
+
const a = before.rects.get(node);
|
|
216
|
+
const b = after.rects.get(node);
|
|
217
|
+
if (!a || !b || !a.width || !b.width) return;
|
|
218
|
+
if (node === bg) {
|
|
219
|
+
// positioned from the field's padding edge
|
|
220
|
+
const left = box.left + field.clientLeft;
|
|
221
|
+
const topEdge = box.top + field.clientTop;
|
|
222
|
+
play(node, [
|
|
223
|
+
{ left: `${a.left - left}px`, top: `${a.top - topEdge}px`, right: 'auto', bottom: 'auto', width: `${a.width}px`, height: `${a.height}px`, borderRadius: before.radius },
|
|
224
|
+
{ left: `${b.left - left}px`, top: `${b.top - topEdge}px`, right: 'auto', bottom: 'auto', width: `${b.width}px`, height: `${b.height}px`, borderRadius: after.radius },
|
|
225
|
+
], options);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const shift = `translate(${a.left - b.left}px, ${a.top - b.top}px)`;
|
|
229
|
+
if (node === input) {
|
|
230
|
+
play(node, [
|
|
231
|
+
{ transform: shift, fontSize: before.font, lineHeight: before.lead },
|
|
232
|
+
{ transform: 'none', fontSize: after.font, lineHeight: after.lead },
|
|
233
|
+
], options);
|
|
234
|
+
} else if (node === footer) {
|
|
235
|
+
play(node, [{ transform: shift }, { transform: 'none' }], options);
|
|
236
|
+
} else {
|
|
237
|
+
play(node, [
|
|
238
|
+
{ transform: `${shift} scale(${a.width / b.width}, ${a.height / b.height})` },
|
|
239
|
+
{ transform: 'none' },
|
|
240
|
+
], options);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
faders().forEach((node) => {
|
|
244
|
+
const a = before.rects.get(node);
|
|
245
|
+
const b = after.rects.get(node);
|
|
246
|
+
if (b && b.width && !(a && a.width)) {
|
|
247
|
+
play(node, [{ opacity: 0 }, { opacity: 0, offset: 0.45 }, { opacity: 1 }], { duration: SPEED, easing: 'linear' });
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---- parts that sit somewhere else while the view is open ----
|
|
253
|
+
// Only buttons are moved in the page, never the text area.
|
|
254
|
+
function placeControls() {
|
|
255
|
+
const paperclip = clip();
|
|
256
|
+
if (shape) {
|
|
257
|
+
if (scope && scope.parentNode !== controls) controls.insertBefore(scope, grow);
|
|
258
|
+
[paperclip, agentButton, go].forEach((node) => {
|
|
259
|
+
if (node && node.parentNode !== controls) controls.appendChild(node);
|
|
260
|
+
});
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (scope && scope.parentNode !== top) top.insertBefore(scope, top.firstChild);
|
|
264
|
+
// after the text: attach, "N running" (already there), agent, send
|
|
265
|
+
const chip = runChip();
|
|
266
|
+
if (paperclip && paperclip.parentNode !== top) {
|
|
267
|
+
top.insertBefore(paperclip, chip && chip.parentNode === top ? chip : null);
|
|
268
|
+
}
|
|
269
|
+
[agentButton, go].forEach((node) => {
|
|
270
|
+
if (node.parentNode !== top) top.appendChild(node);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
// The face: the mode chip (at rest); left of the text, facing it (in place);
|
|
274
|
+
// above the text (centred); the free space under the text (phone, nothing
|
|
275
|
+
// typed, room for it); the top row (phone otherwise).
|
|
276
|
+
const isTyping = () => Boolean(input.value.trim());
|
|
277
|
+
function placeFace() {
|
|
278
|
+
const slot = !shape ? slotChip
|
|
279
|
+
: shape === 'screen' ? (isTyping() || !roomy ? slotTop : slotHero)
|
|
280
|
+
: shape === 'centre' ? slotHero : slotSide;
|
|
281
|
+
if (face.parentNode !== slot) slot.appendChild(face);
|
|
282
|
+
}
|
|
283
|
+
// phone: is there room for the large face, and where is the middle of it
|
|
284
|
+
function fitHero() {
|
|
285
|
+
if (shape !== 'screen') {
|
|
286
|
+
roomy = true;
|
|
287
|
+
hero.style.top = '';
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
// the greeting can run to two lines (an app's long name)
|
|
291
|
+
const shown = greet.style.display;
|
|
292
|
+
greet.style.display = 'block';
|
|
293
|
+
const heroHeight = HERO_FACE + (greet.offsetHeight || GREETING_LINE);
|
|
294
|
+
greet.style.display = shown;
|
|
295
|
+
const row = top.getBoundingClientRect();
|
|
296
|
+
const free = row.height - FIRST_LINE;
|
|
297
|
+
roomy = free >= heroHeight + 24;
|
|
298
|
+
if (roomy) hero.style.top = `${Math.round(row.top - field.getBoundingClientRect().top + FIRST_LINE + (free - heroHeight) / 2)}px`;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// A draft left in a mode other than Ask. A phone's bar at rest names the
|
|
302
|
+
// mode only then (see the stylesheet).
|
|
303
|
+
function hasDraft() {
|
|
304
|
+
if (!hasFolder()) return false;
|
|
305
|
+
const text = item() === 'create_plugin' && input.value.startsWith(PLUGIN_SEED)
|
|
306
|
+
? input.value.slice(PLUGIN_SEED.length)
|
|
307
|
+
: input.value;
|
|
308
|
+
const name = footer && footer.querySelector(isDownload() ? '#agent-bar-download-name' : '#agent-bar-create-name');
|
|
309
|
+
return Boolean(text.trim() || (name && name.value.trim()));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// The greeting is said once: under the large face with an empty text area,
|
|
313
|
+
// or as the placeholder when the face is small. A link is an example of what
|
|
314
|
+
// to paste, so Download keeps its own placeholder.
|
|
315
|
+
// On an app's page the greeting is the bar's own line, which names the app.
|
|
316
|
+
const greetingNow = () => (isApp ? restPlaceholder.replace(/…$/, '') : (GREETINGS[item()] || ''));
|
|
317
|
+
function words() {
|
|
318
|
+
const large = shape === 'centre' || (shape === 'screen' && roomy);
|
|
319
|
+
const greeting = greetingNow();
|
|
320
|
+
greet.textContent = shape === 'centre' ? LINK_GREETING : greeting;
|
|
321
|
+
if (isApp) input.placeholder = shape && large ? '' : restPlaceholder;
|
|
322
|
+
else if (shape && !isDownload()) input.placeholder = large ? '' : greeting;
|
|
323
|
+
// what the on-screen keyboard prints on its Return key
|
|
324
|
+
input.enterKeyHint = isDownload() ? 'go' : (isTouch() ? 'enter' : 'send');
|
|
325
|
+
nameInputs.forEach((nameInput) => { nameInput.enterKeyHint = 'go'; });
|
|
326
|
+
const tool = typeof host.tool === 'function' ? host.tool() : null;
|
|
327
|
+
agentName.textContent = tool && tool.label ? tool.label : 'Agent';
|
|
328
|
+
// In a phone layout the count is just the number, as on the home bar. The
|
|
329
|
+
// app page's bar writes "N running" as one piece of text each time it draws.
|
|
330
|
+
const chip = isApp ? runChip() : null;
|
|
331
|
+
const count = chip && chip.lastChild && chip.lastChild.nodeType === 3 ? chip.lastChild : null;
|
|
332
|
+
if (count && isPhone() && / running$/.test(count.textContent)) {
|
|
333
|
+
chip.setAttribute('aria-label', count.textContent);
|
|
334
|
+
count.textContent = count.textContent.replace(/ running$/, '');
|
|
335
|
+
}
|
|
336
|
+
// Send is named after the mode. The app page's bar draws only the arrow.
|
|
337
|
+
if (isApp && !go.querySelector('.agent-bar__go-label')) {
|
|
338
|
+
go.insertBefore(el('span', 'agent-bar__go-label', 'Ask'), go.firstChild);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// The text area grows with the text, then scrolls. (On a phone it fills the
|
|
343
|
+
// screen; at rest it is one line. The stylesheet does both.)
|
|
344
|
+
function sizeInput() {
|
|
345
|
+
if (shape !== 'place' && shape !== 'centre') return;
|
|
346
|
+
input.style.height = 'auto';
|
|
347
|
+
const line = parseFloat(window.getComputedStyle(input).lineHeight) || 24;
|
|
348
|
+
const max = line * MAX_LINES + 8;
|
|
349
|
+
const wanted = input.scrollHeight;
|
|
350
|
+
input.style.height = `${Math.min(wanted, max)}px`;
|
|
351
|
+
input.style.overflowY = wanted > max ? 'auto' : 'hidden';
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// A menu hangs from its own button, wherever that now is.
|
|
355
|
+
function hang(list, anchor, side) {
|
|
356
|
+
if (!list || list.hidden || !anchor) return;
|
|
357
|
+
if (!shape) {
|
|
358
|
+
['top', 'bottom', 'left', 'right', 'maxHeight'].forEach((name) => { list.style[name] = ''; });
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const a = anchor.getBoundingClientRect();
|
|
362
|
+
const frame = inner.getBoundingClientRect();
|
|
363
|
+
const width = list.getBoundingClientRect().width;
|
|
364
|
+
const edge = side === 'right' ? a.right - width : a.left;
|
|
365
|
+
const left = Math.max(8, Math.min(edge, window.innerWidth - width - 8));
|
|
366
|
+
list.style.right = 'auto';
|
|
367
|
+
list.style.left = `${left - frame.left}px`;
|
|
368
|
+
const below = window.innerHeight - a.bottom - 14;
|
|
369
|
+
const above = a.top - 14;
|
|
370
|
+
if (below < 200 && above > below) {
|
|
371
|
+
list.style.top = 'auto';
|
|
372
|
+
list.style.bottom = `${frame.bottom - a.top + 6}px`;
|
|
373
|
+
list.style.maxHeight = `${Math.min(520, Math.max(120, above))}px`;
|
|
374
|
+
} else {
|
|
375
|
+
list.style.bottom = 'auto';
|
|
376
|
+
list.style.top = `${a.bottom - frame.top + 6}px`;
|
|
377
|
+
list.style.maxHeight = `${Math.min(520, Math.max(120, below))}px`;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function hangMenus() {
|
|
381
|
+
// (the app page's bar shows its running list in the same menu as its agents)
|
|
382
|
+
const which = menu.dataset.menu;
|
|
383
|
+
hang(menu, which === 'agent' ? agentButton : which === 'running' ? runChip() : scope, which === 'mode' ? 'left' : 'right');
|
|
384
|
+
hang(runMenu(), runChip(), 'right');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// ---- the face's reactions ----
|
|
388
|
+
function wake() {
|
|
389
|
+
if (isStill()) return;
|
|
390
|
+
face.querySelectorAll('.agent-compose__eye').forEach((eye) => {
|
|
391
|
+
if (typeof eye.animate !== 'function') return;
|
|
392
|
+
eye.animate(
|
|
393
|
+
[{ transform: 'scaleY(0.1)' }, { transform: 'scaleY(0.1)', offset: 0.55 }, { transform: 'scaleY(1)' }],
|
|
394
|
+
{ duration: SPEED + 180, easing: 'ease-out' }
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
function listen() {
|
|
399
|
+
if (isBusy() || !shape) return;
|
|
400
|
+
face.dataset.face = 'listening';
|
|
401
|
+
window.clearTimeout(listenTimer);
|
|
402
|
+
listenTimer = window.setTimeout(() => {
|
|
403
|
+
if (face.dataset.face === 'listening') face.dataset.face = 'idle';
|
|
404
|
+
}, LISTEN_MS);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ---- phone: the back gesture closes the view ----
|
|
408
|
+
function holdHistory() {
|
|
409
|
+
if (pushed) return;
|
|
410
|
+
try {
|
|
411
|
+
window.history.pushState({ agentCompose: true }, '');
|
|
412
|
+
pushed = true;
|
|
413
|
+
} catch (_) {}
|
|
414
|
+
}
|
|
415
|
+
function releaseHistory() {
|
|
416
|
+
if (!pushed) return;
|
|
417
|
+
pushed = false;
|
|
418
|
+
try {
|
|
419
|
+
if (window.history.state && window.history.state.agentCompose) window.history.back();
|
|
420
|
+
} catch (_) {}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ---- bring everything up to date with what the bar now shows ----
|
|
424
|
+
function sync() {
|
|
425
|
+
const engaged = root.dataset.engaged === 'true';
|
|
426
|
+
// the bar was left (Escape, a click outside, a send that went through)
|
|
427
|
+
if (open && wasEngaged && !engaged && !isBusy()) open = false;
|
|
428
|
+
wasEngaged = engaged;
|
|
429
|
+
if (!open) centre = false;
|
|
430
|
+
|
|
431
|
+
const next = !open ? '' : isPhone() ? 'screen' : (centre ? 'centre' : 'place');
|
|
432
|
+
const opening = Boolean(next) && !shape;
|
|
433
|
+
const key = [
|
|
434
|
+
next, item(), Boolean(footer && !footer.hidden), !note.hidden,
|
|
435
|
+
Boolean(files() && !files().hidden),
|
|
436
|
+
next === 'screen' && isTyping(),
|
|
437
|
+
].join('|');
|
|
438
|
+
const animate = lastKey !== null && key !== lastKey && !isStill() && Boolean(cache);
|
|
439
|
+
const before = animate ? cache : null;
|
|
440
|
+
const closing = !next && Boolean(shape);
|
|
441
|
+
|
|
442
|
+
// A new move starts from where things are; anything else leaves a move
|
|
443
|
+
// that is under way alone.
|
|
444
|
+
if (animate) stopMoves();
|
|
445
|
+
shape = next;
|
|
446
|
+
if (shape) root.dataset.compose = shape;
|
|
447
|
+
else delete root.dataset.compose;
|
|
448
|
+
document.documentElement.classList.toggle('agent-compose-screen', shape === 'screen');
|
|
449
|
+
if (shape === 'screen') syncViewport();
|
|
450
|
+
placeControls();
|
|
451
|
+
sizeInput();
|
|
452
|
+
// (its words first: how many lines they take decides where the face fits)
|
|
453
|
+
greet.textContent = shape === 'centre' ? LINK_GREETING : greetingNow();
|
|
454
|
+
fitHero();
|
|
455
|
+
root.dataset.composeTyping = String(isTyping());
|
|
456
|
+
root.dataset.composeDraft = String(hasDraft());
|
|
457
|
+
root.dataset.composePhone = String(isPhone());
|
|
458
|
+
root.dataset.composeRoomy = String(roomy);
|
|
459
|
+
placeFace();
|
|
460
|
+
words();
|
|
461
|
+
if (isBusy()) {
|
|
462
|
+
window.clearTimeout(listenTimer);
|
|
463
|
+
face.dataset.face = 'working';
|
|
464
|
+
} else if (face.dataset.face === 'working') {
|
|
465
|
+
face.dataset.face = 'idle';
|
|
466
|
+
}
|
|
467
|
+
// Anything of the bar's that reaches below the top bar raises the top bar
|
|
468
|
+
// (see raiseTopBar in agent-bar.js, which runs before the view has opened).
|
|
469
|
+
const header = root.closest('header');
|
|
470
|
+
if (header) {
|
|
471
|
+
const lists = [menu, runMenu()].some((list) => list && !list.hidden);
|
|
472
|
+
header.classList.toggle('agent-bar-raised', Boolean(shape) || lists || !note.hidden);
|
|
473
|
+
}
|
|
474
|
+
hangMenus();
|
|
475
|
+
|
|
476
|
+
if (closing) input.scrollTop = 0;
|
|
477
|
+
if (animate) {
|
|
478
|
+
const after = measure();
|
|
479
|
+
move(before, after);
|
|
480
|
+
cache = after;
|
|
481
|
+
// once it has arrived, that is where everything is
|
|
482
|
+
const batch = running;
|
|
483
|
+
Promise.all(batch.map((animation) => animation.finished)).then(() => {
|
|
484
|
+
if (running === batch) snapshot();
|
|
485
|
+
}).catch(() => {});
|
|
486
|
+
} else if (!isMoving()) {
|
|
487
|
+
cache = measure();
|
|
488
|
+
}
|
|
489
|
+
if (opening) wake();
|
|
490
|
+
lastKey = key;
|
|
491
|
+
|
|
492
|
+
if (shape === 'screen') holdHistory();
|
|
493
|
+
else releaseHistory();
|
|
494
|
+
// what was just written here is not news
|
|
495
|
+
if (observer) observer.takeRecords();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// ---- when it opens ----
|
|
499
|
+
function show(viaLink) {
|
|
500
|
+
if (isBusy()) return;
|
|
501
|
+
if (!open) centre = Boolean(viaLink);
|
|
502
|
+
open = true;
|
|
503
|
+
}
|
|
504
|
+
// the cursor enters the text or the folder name
|
|
505
|
+
root.addEventListener('focusin', (event) => {
|
|
506
|
+
if (event.target !== input && !nameInputs.includes(event.target)) return;
|
|
507
|
+
if (open) return;
|
|
508
|
+
// the bar puts the cursor in the text itself when it takes a link
|
|
509
|
+
show(arriving);
|
|
510
|
+
sync();
|
|
511
|
+
});
|
|
512
|
+
// send pressed on the bar at rest, in a mode that has a folder name: the bar
|
|
513
|
+
// draws itself next, and the view opens with it
|
|
514
|
+
go.addEventListener('click', () => {
|
|
515
|
+
if (!open && hasFolder()) show(false);
|
|
516
|
+
}, true);
|
|
517
|
+
// a pre-filled link, or a button on the page that opens the bar on a mode
|
|
518
|
+
// (only the home bar takes these)
|
|
519
|
+
const openBar = bar.open;
|
|
520
|
+
if (!isApp) bar.open = (defaults) => {
|
|
521
|
+
arriving = linkPending;
|
|
522
|
+
linkPending = false;
|
|
523
|
+
let took = false;
|
|
524
|
+
try {
|
|
525
|
+
took = openBar(defaults);
|
|
526
|
+
if (took) {
|
|
527
|
+
show(arriving);
|
|
528
|
+
sync();
|
|
529
|
+
}
|
|
530
|
+
} finally {
|
|
531
|
+
arriving = false;
|
|
532
|
+
}
|
|
533
|
+
return took;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// A phone's bar at rest is one button: a tap on the mark opens the view like
|
|
537
|
+
// a tap on the text, and not the mode menu, which is in the view.
|
|
538
|
+
inner.addEventListener('click', (event) => {
|
|
539
|
+
if (shape || !isPhone() || !event.target.closest || !event.target.closest('.agent-bar__scope, .agent-compose__slot--chip')) return;
|
|
540
|
+
event.stopPropagation();
|
|
541
|
+
input.focus();
|
|
542
|
+
}, true);
|
|
543
|
+
|
|
544
|
+
// ---- when it closes ----
|
|
545
|
+
x.addEventListener('click', () => {
|
|
546
|
+
leave();
|
|
547
|
+
if (document.activeElement && root.contains(document.activeElement)) document.activeElement.blur();
|
|
548
|
+
});
|
|
549
|
+
// Opening a session from the running list: its window comes up, the view goes.
|
|
550
|
+
inner.addEventListener('click', (event) => {
|
|
551
|
+
if (open && event.target.closest && event.target.closest('.agent-bar__menu--running .agent-bar__row')) leave();
|
|
552
|
+
});
|
|
553
|
+
window.addEventListener('popstate', () => {
|
|
554
|
+
if (!pushed) return;
|
|
555
|
+
pushed = false;
|
|
556
|
+
if (!open) return;
|
|
557
|
+
leave();
|
|
558
|
+
if (document.activeElement && root.contains(document.activeElement)) document.activeElement.blur();
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
// ---- keys ----
|
|
562
|
+
// On a touch screen Return adds a line (there is no Shift+Enter) and the send
|
|
563
|
+
// button sends. A link and a folder name have no lines, so there Return
|
|
564
|
+
// sends, as does Cmd/Ctrl+Enter everywhere. This runs before the bar's own
|
|
565
|
+
// handler, which would send.
|
|
566
|
+
root.addEventListener('keydown', (event) => {
|
|
567
|
+
if (event.target !== input || event.key !== 'Enter' || event.isComposing) return;
|
|
568
|
+
if (isDownload() || event.metaKey || event.ctrlKey || event.shiftKey || !isTouch()) return;
|
|
569
|
+
event.stopPropagation();
|
|
570
|
+
}, true);
|
|
571
|
+
|
|
572
|
+
// The view's own buttons do not take the cursor out of the text: the
|
|
573
|
+
// controls, the App / Plugin switch, "N running", and the rows of the mode
|
|
574
|
+
// and agent menus. (A row of the running list opens a session and closes
|
|
575
|
+
// the view, so it is left alone.)
|
|
576
|
+
const KEEPS_CURSOR = '.agent-compose__controls button, .agent-bar__seg button, .agent-bar__running, '
|
|
577
|
+
+ '.agent-bar__menu:not(.agent-bar__menu--running) .agent-bar__row';
|
|
578
|
+
inner.addEventListener('pointerdown', (event) => {
|
|
579
|
+
if (shape && event.target.closest && event.target.closest(KEEPS_CURSOR)) event.preventDefault();
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
input.addEventListener('input', listen);
|
|
583
|
+
nameInputs.forEach((nameInput) => nameInput.addEventListener('input', listen));
|
|
584
|
+
|
|
585
|
+
['pointerdown', 'keydown'].forEach((type) => document.addEventListener(type, snapshot, true));
|
|
586
|
+
const viewportChanged = () => {
|
|
587
|
+
syncViewport();
|
|
588
|
+
sync();
|
|
589
|
+
};
|
|
590
|
+
window.addEventListener('resize', viewportChanged);
|
|
591
|
+
if (window.visualViewport) {
|
|
592
|
+
window.visualViewport.addEventListener('resize', viewportChanged);
|
|
593
|
+
window.visualViewport.addEventListener('scroll', syncViewport);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
observer = new MutationObserver(sync);
|
|
597
|
+
observer.observe(root, { attributes: true });
|
|
598
|
+
// the folder row, a message, the attached files, a menu: each shows and hides itself
|
|
599
|
+
observer.observe(inner, { attributes: true, attributeFilter: ['hidden'], subtree: true });
|
|
600
|
+
|
|
601
|
+
// an app's page switches between its two layouts and moves its bar with it
|
|
602
|
+
new MutationObserver(sync).observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
603
|
+
|
|
604
|
+
syncViewport();
|
|
605
|
+
sync();
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// The app page's bar may be put in the page after the home bar's script has
|
|
610
|
+
// settled, so this looks again once the page is there.
|
|
611
|
+
let installed = false;
|
|
612
|
+
const tryInstall = () => {
|
|
613
|
+
if (!installed) installed = install() === true;
|
|
614
|
+
};
|
|
615
|
+
bar.ready.then(tryInstall);
|
|
616
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', tryInstall);
|
|
617
|
+
window.addEventListener('load', tryInstall);
|
|
618
|
+
})(window, document);
|
|
@@ -188,6 +188,8 @@ html.agent-bar-panel-still body.main-sidebar-page > main {
|
|
|
188
188
|
}
|
|
189
189
|
.agent-bar-panel {
|
|
190
190
|
border-left: 0;
|
|
191
|
+
/* ends where the on-screen keyboard begins (set in agent-bar-panel.js) */
|
|
192
|
+
bottom: var(--agent-dock-keyboard, 0px);
|
|
191
193
|
}
|
|
192
194
|
/* the narrow bar keeps its room for typing: the count is just the number */
|
|
193
195
|
.agent-bar__running-word {
|