pinokiod 8.4.0 → 8.4.1
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/package.json +1 -1
- package/server/public/agent-bar-compose.js +7 -0
- package/server/public/agent-bar-launch.js +45 -0
- package/server/public/agent-bar-search.css +45 -0
- package/server/public/agent-bar-search.js +265 -0
- package/server/public/agent-bar-shortcut.css +30 -0
- package/server/public/agent-bar-shortcut.js +103 -0
- package/server/public/agent-bar.js +3 -1
- package/server/public/request-strip.js +146 -0
- package/server/views/app.ejs +2 -0
- package/server/views/partials/main_sidebar.ejs +4 -0
- package/server/views/terminal.ejs +5 -0
- package/system/plugin/cursor/pinokio.js +11 -0
- package/system/plugin/vscode/pinokio.js +78 -12
- package/test/agent-bar-launch.test.js +47 -0
- package/test/agent-bar-search.test.js +314 -0
- package/test/agent-bar-shortcut.test.js +215 -0
- package/test/desktop-plugin-requests.test.js +112 -0
- package/test/request-strip.test.js +110 -0
package/package.json
CHANGED
|
@@ -535,10 +535,17 @@
|
|
|
535
535
|
root.addEventListener('focusin', (event) => {
|
|
536
536
|
if (event.target !== input && !nameInputs.includes(event.target)) return;
|
|
537
537
|
if (open) return;
|
|
538
|
+
// on arriving at home the cursor is put in the bar, which stays closed (agent-bar-search.js)
|
|
539
|
+
if (!arriving && typeof host.holdView === 'function' && host.holdView()) return;
|
|
538
540
|
// the bar puts the cursor in the text itself when it takes a link
|
|
539
541
|
show(arriving);
|
|
540
542
|
sync();
|
|
541
543
|
});
|
|
544
|
+
// opened from outside, with the cursor where it is (agent-bar-search.js)
|
|
545
|
+
host.view = {
|
|
546
|
+
show: () => { show(false); sync(); },
|
|
547
|
+
isOpen: () => open,
|
|
548
|
+
};
|
|
542
549
|
// send pressed on the bar at rest, in a mode that has a folder name: the bar
|
|
543
550
|
// draws itself next, and the view opens with it
|
|
544
551
|
go.addEventListener('click', () => {
|
|
@@ -212,6 +212,47 @@
|
|
|
212
212
|
card.closing = window.setTimeout(() => close(card), times.close);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
// The request line the plugin was started with, if any (the launch address carries it).
|
|
216
|
+
function requestLine(card) {
|
|
217
|
+
try {
|
|
218
|
+
return (new URL(card.launchUrl, window.location.origin).searchParams.get('prompt') || '').trim();
|
|
219
|
+
} catch (_) {
|
|
220
|
+
return '';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function copyRequest(card, button) {
|
|
225
|
+
const line = requestLine(card);
|
|
226
|
+
const done = (ok) => {
|
|
227
|
+
button.textContent = ok ? 'Copied' : 'Could not copy';
|
|
228
|
+
window.setTimeout(() => { button.textContent = 'Copy message'; }, 1800);
|
|
229
|
+
};
|
|
230
|
+
const byHand = () => {
|
|
231
|
+
const area = document.createElement('textarea');
|
|
232
|
+
area.value = line;
|
|
233
|
+
area.style.cssText = 'position:fixed;opacity:0';
|
|
234
|
+
document.body.appendChild(area);
|
|
235
|
+
area.select();
|
|
236
|
+
let ok = false;
|
|
237
|
+
try {
|
|
238
|
+
ok = document.execCommand('copy');
|
|
239
|
+
} catch (_) {}
|
|
240
|
+
area.remove();
|
|
241
|
+
done(ok);
|
|
242
|
+
};
|
|
243
|
+
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(line).then(() => done(true), byHand);
|
|
244
|
+
else byHand();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// The app is open and the launch had a request. Whether the app took it cannot
|
|
248
|
+
// be seen from here: a plugin may hand it over and the app still not show it
|
|
249
|
+
// (signed out, no chat set up, another window). So the card stays, with the
|
|
250
|
+
// request to copy.
|
|
251
|
+
function openedWithRequest(card) {
|
|
252
|
+
draw(card, 'request', `Opened in ${card.name}`, 'If your message isn\'t in the chat, copy it and paste it.', 'check');
|
|
253
|
+
action(card, 'Copy message', 'agent-launch__primary', (event) => copyRequest(card, event.currentTarget));
|
|
254
|
+
}
|
|
255
|
+
|
|
215
256
|
function opened(card, waiting) {
|
|
216
257
|
clearTimers(card);
|
|
217
258
|
// the plugin sits in a step that waits for Stop: the page's own Stop ends it
|
|
@@ -221,6 +262,10 @@
|
|
|
221
262
|
if (stop) stop.click();
|
|
222
263
|
} catch (_) {}
|
|
223
264
|
}
|
|
265
|
+
if (requestLine(card)) {
|
|
266
|
+
openedWithRequest(card);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
224
269
|
draw(card, 'opened', `Opened in ${card.name}`, 'Carry on there.', 'check');
|
|
225
270
|
closeSoon(card);
|
|
226
271
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* Agent bar: the apps that match what is typed, as rows inside the open box
|
|
2
|
+
(agent-bar-search.js). */
|
|
3
|
+
.agent-bar-search__rows {
|
|
4
|
+
display: none;
|
|
5
|
+
}
|
|
6
|
+
.agent-bar[data-compose] .agent-bar-search__rows:not([hidden]) {
|
|
7
|
+
/* after the text (which has the same order and comes first in the page) */
|
|
8
|
+
order: 2;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
gap: 1px;
|
|
12
|
+
/* five rows, then it scrolls */
|
|
13
|
+
max-height: 172px;
|
|
14
|
+
overflow-y: auto;
|
|
15
|
+
margin: 0 -4px;
|
|
16
|
+
padding-top: 8px;
|
|
17
|
+
border-top: 1px solid var(--agent-bar-border);
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
.agent-bar-search__rows .agent-bar__row {
|
|
21
|
+
flex: none;
|
|
22
|
+
color: inherit;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
}
|
|
25
|
+
.agent-bar-search__rows .agent-bar__row-label {
|
|
26
|
+
flex: 0 1 auto;
|
|
27
|
+
}
|
|
28
|
+
.agent-bar-search__folder {
|
|
29
|
+
flex: 1 1 0;
|
|
30
|
+
min-width: 0;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
text-overflow: ellipsis;
|
|
34
|
+
font-size: 12px;
|
|
35
|
+
color: var(--agent-bar-muted);
|
|
36
|
+
}
|
|
37
|
+
.agent-bar-search__rows .agent-bar__row-note {
|
|
38
|
+
margin-left: auto;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* Home's own search box is hidden, not removed: the bar does its job on a
|
|
42
|
+
desktop-width page, and the class is only set while it does. */
|
|
43
|
+
html.agent-bar-search-home .home-search-form input[type='search'] {
|
|
44
|
+
display: none;
|
|
45
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Agent bar: it also finds your apps.
|
|
2
|
+
//
|
|
3
|
+
// While the bar's box is open on a plain one-line Ask, the installed apps that
|
|
4
|
+
// match what is typed are listed as rows inside the box, between the text and
|
|
5
|
+
// the controls. The page behind does not change.
|
|
6
|
+
//
|
|
7
|
+
// Enter asks, as always.
|
|
8
|
+
// Down / Up step into the rows: the app Enter would open is shown as
|
|
9
|
+
// picked ("Open"), and Enter then opens its page. Up from the
|
|
10
|
+
// first row, or typing, goes back to asking.
|
|
11
|
+
// a click on a row opens that app.
|
|
12
|
+
//
|
|
13
|
+
// Text that matches no app shows no rows: the box is then the plain ask box.
|
|
14
|
+
// Nothing is listed in another mode, for an Ask pointed at one app, once the
|
|
15
|
+
// text has a second line, while a send is under way, or in a phone's
|
|
16
|
+
// full-screen view.
|
|
17
|
+
//
|
|
18
|
+
// This is on every page that has the bar with the modes (not an app's page).
|
|
19
|
+
// Home, which had a "Search apps" box of its own above its list, differs in
|
|
20
|
+
// two ways: that box is hidden (see the stylesheet), and the cursor starts in
|
|
21
|
+
// the bar as it started in that box. The bar's box stays closed until the
|
|
22
|
+
// first key or click, and until then the arrows and Enter are the page's, as
|
|
23
|
+
// they were with the cursor in the search box.
|
|
24
|
+
//
|
|
25
|
+
// The apps are read from /info/apps (folder, title, description, icon) each
|
|
26
|
+
// time the bar is gone to.
|
|
27
|
+
//
|
|
28
|
+
// The bar draws itself (agent-bar.js) and the compose view opens and closes
|
|
29
|
+
// itself (agent-bar-compose.js). From them this file uses, on PinokioAgentBar:
|
|
30
|
+
// helpers, navigate, holdView (asked before the view opens for the cursor),
|
|
31
|
+
// view.show / isOpen, engage, refresh, greeting and askHint.
|
|
32
|
+
(function (window, document) {
|
|
33
|
+
'use strict';
|
|
34
|
+
|
|
35
|
+
if (window.PinokioAgentBarSearch) return;
|
|
36
|
+
const bar = window.PinokioAgentBar;
|
|
37
|
+
if (!bar || !bar.ready || !bar.helpers) return;
|
|
38
|
+
|
|
39
|
+
const PAGE_CLASS = 'agent-bar-search';
|
|
40
|
+
const HOME_CLASS = 'agent-bar-search-home';
|
|
41
|
+
const HINT = 'Search apps or ask Pinokio…';
|
|
42
|
+
const HOME_BOX = '.home-search-form input[type="search"]';
|
|
43
|
+
const PHONE = '(max-width: 768px)';
|
|
44
|
+
const STALE_MS = 10000;
|
|
45
|
+
|
|
46
|
+
// A pre-filled link fills the bar itself. Read now: common.js tidies the
|
|
47
|
+
// address before it hands the link over.
|
|
48
|
+
let linkPending = false;
|
|
49
|
+
try {
|
|
50
|
+
linkPending = new URLSearchParams(window.location.search).has('universal');
|
|
51
|
+
} catch (_) {}
|
|
52
|
+
|
|
53
|
+
const matches = (query) => Boolean(window.matchMedia && window.matchMedia(query).matches);
|
|
54
|
+
const clean = (text) => String(text || '').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
55
|
+
|
|
56
|
+
// How well an app matches, best first: its title starts with the text; a
|
|
57
|
+
// word of its title does; its title holds it; its folder's name does; its
|
|
58
|
+
// description does. -1: not at all.
|
|
59
|
+
function rank(app, query) {
|
|
60
|
+
const title = clean(app.title || app.name);
|
|
61
|
+
const at = title.indexOf(query);
|
|
62
|
+
if (at === 0) return 0;
|
|
63
|
+
if (at > 0 && !/[a-z0-9]/.test(title[at - 1])) return 1;
|
|
64
|
+
if (at > 0) return 2;
|
|
65
|
+
if (clean(app.name).includes(query)) return 3;
|
|
66
|
+
if (clean(app.description).includes(query)) return 4;
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function install() {
|
|
71
|
+
const root = document.querySelector('.agent-bar');
|
|
72
|
+
// only the bar with the modes; an app's page has its own
|
|
73
|
+
if (!root || root.dataset.item === 'ask_app') return false;
|
|
74
|
+
const input = root.querySelector('.agent-bar__input');
|
|
75
|
+
const field = root.querySelector('.agent-bar__field');
|
|
76
|
+
const controls = root.querySelector('.agent-compose__controls');
|
|
77
|
+
if (!input || !field || !controls || !bar.view || typeof bar.engage !== 'function') return false;
|
|
78
|
+
window.PinokioAgentBarSearch = true;
|
|
79
|
+
const H = bar.helpers;
|
|
80
|
+
const homeBox = document.querySelector(HOME_BOX);
|
|
81
|
+
const active = () => !matches(PHONE);
|
|
82
|
+
|
|
83
|
+
const box = H.el('div', 'agent-bar-search__rows');
|
|
84
|
+
box.hidden = true;
|
|
85
|
+
box.setAttribute('role', 'listbox');
|
|
86
|
+
box.setAttribute('aria-label', 'Apps');
|
|
87
|
+
field.insertBefore(box, controls);
|
|
88
|
+
// a press on a row does not take the cursor out of the text
|
|
89
|
+
box.addEventListener('pointerdown', (event) => event.preventDefault());
|
|
90
|
+
|
|
91
|
+
let apps = [];
|
|
92
|
+
let loadedAt = 0;
|
|
93
|
+
let loading = false;
|
|
94
|
+
let found = []; // the apps listed now
|
|
95
|
+
let picked = -1; // which of them Enter would open (-1: Enter asks)
|
|
96
|
+
let drawn = '';
|
|
97
|
+
|
|
98
|
+
function load() {
|
|
99
|
+
if (loading || (loadedAt && Date.now() - loadedAt < STALE_MS)) return;
|
|
100
|
+
loading = true;
|
|
101
|
+
window.fetch('/info/apps')
|
|
102
|
+
.then((response) => (response && response.ok ? response.json() : null))
|
|
103
|
+
.then((body) => {
|
|
104
|
+
if (body && Array.isArray(body.apps)) {
|
|
105
|
+
apps = body.apps.filter((app) => app && app.name);
|
|
106
|
+
loadedAt = Date.now();
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
.catch(() => {})
|
|
110
|
+
.then(() => {
|
|
111
|
+
loading = false;
|
|
112
|
+
draw();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function search() {
|
|
117
|
+
const shape = root.dataset.compose;
|
|
118
|
+
const plain = root.dataset.item === 'ask' && !root.dataset.about && !/\n/.test(input.value);
|
|
119
|
+
const query = clean(input.value);
|
|
120
|
+
if (!active() || !shape || shape === 'screen' || !plain || !query || root.dataset.busy === 'true') return [];
|
|
121
|
+
return apps
|
|
122
|
+
.map((app, index) => ({ app, index, score: rank(app, query) }))
|
|
123
|
+
.filter((hit) => hit.score >= 0)
|
|
124
|
+
.sort((a, b) => a.score - b.score || a.index - b.index)
|
|
125
|
+
.map((hit) => hit.app);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Home's own row for the app opens it the way a click on that row does;
|
|
129
|
+
// anywhere else the app's page is gone to.
|
|
130
|
+
function openApp(app) {
|
|
131
|
+
if (!app) return;
|
|
132
|
+
const line = homeBox && Array.from(document.querySelectorAll('.home-app-line[data-uri]'))
|
|
133
|
+
.find((node) => node.dataset.uri === app.name);
|
|
134
|
+
if (line) line.click();
|
|
135
|
+
else bar.navigate(`/p/${encodeURIComponent(app.name)}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function draw() {
|
|
139
|
+
found = search();
|
|
140
|
+
if (picked >= found.length) picked = -1;
|
|
141
|
+
const key = `${found.map((app) => app.name).join('\n')}|${picked}`;
|
|
142
|
+
if (key === drawn) return;
|
|
143
|
+
drawn = key;
|
|
144
|
+
box.textContent = '';
|
|
145
|
+
found.forEach((app, index) => {
|
|
146
|
+
const icon = H.el('img', 'agent-bar__row-img');
|
|
147
|
+
icon.alt = '';
|
|
148
|
+
icon.src = app.icon || '/pinokio-black.png';
|
|
149
|
+
icon.addEventListener('error', () => { icon.style.visibility = 'hidden'; });
|
|
150
|
+
const title = app.title || app.name;
|
|
151
|
+
const row = H.menuRow(icon, title, index === picked ? 'Open ↵' : '', false, () => openApp(app));
|
|
152
|
+
// its folder, so two apps of one name can be told apart
|
|
153
|
+
if (clean(app.name) !== clean(title)) {
|
|
154
|
+
row.insertBefore(H.el('span', 'agent-bar-search__folder', app.name), row.querySelector('.agent-bar__row-label').nextSibling);
|
|
155
|
+
}
|
|
156
|
+
row.setAttribute('role', 'option');
|
|
157
|
+
row.setAttribute('aria-selected', String(index === picked));
|
|
158
|
+
row.classList.toggle('is-current', index === picked);
|
|
159
|
+
box.appendChild(row);
|
|
160
|
+
});
|
|
161
|
+
const hidden = !found.length;
|
|
162
|
+
if (box.hidden !== hidden) box.hidden = hidden;
|
|
163
|
+
const at = box.children[picked];
|
|
164
|
+
if (at && typeof at.scrollIntoView === 'function') at.scrollIntoView({ block: 'nearest' });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ---- home, on arriving: the cursor is in the bar and its box waits ----
|
|
168
|
+
let holding = false;
|
|
169
|
+
bar.holdView = () => holding && active();
|
|
170
|
+
function release() {
|
|
171
|
+
if (!holding) return;
|
|
172
|
+
holding = false;
|
|
173
|
+
if (document.activeElement !== input || bar.view.isOpen()) return;
|
|
174
|
+
if (root.dataset.engaged !== 'true') bar.engage();
|
|
175
|
+
bar.view.show();
|
|
176
|
+
}
|
|
177
|
+
input.addEventListener('pointerdown', release);
|
|
178
|
+
// The wait ends when the cursor goes elsewhere in the page. (Another window
|
|
179
|
+
// coming to the front takes the cursor too, and gives it back.)
|
|
180
|
+
input.addEventListener('blur', () => {
|
|
181
|
+
if (document.hasFocus()) holding = false;
|
|
182
|
+
});
|
|
183
|
+
input.addEventListener('input', () => {
|
|
184
|
+
release();
|
|
185
|
+
picked = -1;
|
|
186
|
+
load();
|
|
187
|
+
draw();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// ---- keys (before the bar's own handler, which would send) ----
|
|
191
|
+
root.addEventListener('keydown', (event) => {
|
|
192
|
+
if (event.target !== input || event.isComposing) return;
|
|
193
|
+
const arrow = event.key === 'ArrowDown' || event.key === 'ArrowUp';
|
|
194
|
+
const enter = event.key === 'Enter' && !event.shiftKey && !event.metaKey && !event.ctrlKey;
|
|
195
|
+
// Home, before the box has opened: these keys are the page's, which
|
|
196
|
+
// walks its list with them. (A stray Enter must not start an agent.)
|
|
197
|
+
if (holding && !bar.view.isOpen() && !input.value && (arrow || enter)) {
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
event.stopPropagation();
|
|
200
|
+
document.body.dispatchEvent(new window.KeyboardEvent('keydown', { key: event.key, bubbles: true, cancelable: true }));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (event.key === 'ArrowDown' && found.length) {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
picked = Math.min(found.length - 1, picked + 1);
|
|
206
|
+
draw();
|
|
207
|
+
} else if (event.key === 'ArrowUp' && picked >= 0) {
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
picked -= 1;
|
|
210
|
+
draw();
|
|
211
|
+
} else if (enter && picked >= 0) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
event.stopPropagation();
|
|
214
|
+
openApp(found[picked]);
|
|
215
|
+
}
|
|
216
|
+
}, true);
|
|
217
|
+
|
|
218
|
+
// The bar writes what it shows on itself each time it draws.
|
|
219
|
+
function follow() {
|
|
220
|
+
document.documentElement.classList.toggle(PAGE_CLASS, active());
|
|
221
|
+
document.documentElement.classList.toggle(HOME_CLASS, active() && Boolean(homeBox));
|
|
222
|
+
// what the empty bar says
|
|
223
|
+
const hint = active() ? HINT : '';
|
|
224
|
+
if (bar.askHint !== hint) {
|
|
225
|
+
bar.askHint = hint;
|
|
226
|
+
bar.refresh();
|
|
227
|
+
}
|
|
228
|
+
if (root.dataset.engaged === 'true') load();
|
|
229
|
+
draw();
|
|
230
|
+
}
|
|
231
|
+
new MutationObserver(follow).observe(root, { attributes: true });
|
|
232
|
+
window.addEventListener('resize', follow);
|
|
233
|
+
|
|
234
|
+
// what the open box's empty text says on Ask
|
|
235
|
+
const greeting = bar.greeting;
|
|
236
|
+
bar.greeting = () => (typeof greeting === 'function' && greeting())
|
|
237
|
+
|| (active() && root.dataset.item === 'ask' ? HINT.replace(/…$/, '') : '');
|
|
238
|
+
|
|
239
|
+
follow();
|
|
240
|
+
if (homeBox && active() && !linkPending) {
|
|
241
|
+
// a search the hidden box was given by the address is dropped
|
|
242
|
+
if (homeBox.value) {
|
|
243
|
+
homeBox.value = '';
|
|
244
|
+
homeBox.dispatchEvent(new window.Event('input', { bubbles: true }));
|
|
245
|
+
}
|
|
246
|
+
// the cursor starts in the bar, as it started in the search box
|
|
247
|
+
const at = document.activeElement;
|
|
248
|
+
if (!at || at === document.body || at === homeBox) {
|
|
249
|
+
holding = true;
|
|
250
|
+
try { input.focus({ preventScroll: true }); } catch (_) { input.focus(); }
|
|
251
|
+
if (document.activeElement !== input) holding = false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// after the compose view has been installed on the bar
|
|
258
|
+
let installed = false;
|
|
259
|
+
const tryInstall = () => {
|
|
260
|
+
if (!installed) installed = install() === true;
|
|
261
|
+
};
|
|
262
|
+
bar.ready.then(() => window.setTimeout(tryInstall, 0));
|
|
263
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => window.setTimeout(tryInstall, 0));
|
|
264
|
+
window.addEventListener('load', tryInstall);
|
|
265
|
+
})(window, document);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* Agent bar: the key that takes you to it, shown at the end of the empty bar
|
|
2
|
+
at rest (agent-bar-shortcut.js). */
|
|
3
|
+
.agent-bar-shortcut__hint {
|
|
4
|
+
display: none;
|
|
5
|
+
flex: none;
|
|
6
|
+
align-items: center;
|
|
7
|
+
height: 18px;
|
|
8
|
+
padding: 0 5px;
|
|
9
|
+
border: 1px solid var(--agent-bar-border);
|
|
10
|
+
border-radius: 5px;
|
|
11
|
+
font: 500 11px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
12
|
+
letter-spacing: 0.02em;
|
|
13
|
+
color: var(--agent-bar-muted);
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
pointer-events: none;
|
|
16
|
+
user-select: none;
|
|
17
|
+
}
|
|
18
|
+
/* only while the bar is at rest and empty */
|
|
19
|
+
.agent-bar:not([data-compose]):not([data-engaged="true"]):not([data-busy="true"]) .agent-bar__input:placeholder-shown ~ .agent-bar-shortcut__hint:not([hidden]) {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
}
|
|
22
|
+
/* no keyboard to press it on */
|
|
23
|
+
@media (max-width: 768px), (pointer: coarse) {
|
|
24
|
+
.agent-bar .agent-bar-shortcut__hint {
|
|
25
|
+
display: none !important;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
html.agent-bar-app-phone .agent-bar .agent-bar-shortcut__hint {
|
|
29
|
+
display: none !important;
|
|
30
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Agent bar: a key that takes you to it.
|
|
2
|
+
//
|
|
3
|
+
// Cmd+K (macOS) / Ctrl+K (elsewhere) go to the bar: the cursor is in its
|
|
4
|
+
// text and its box is open, as after a
|
|
5
|
+
// click. Pressed again from inside the
|
|
6
|
+
// bar, it leaves the bar.
|
|
7
|
+
// / the same, when you are not typing in
|
|
8
|
+
// a field. (In a field it is a slash.)
|
|
9
|
+
//
|
|
10
|
+
// Both bars: the one with the modes, and the one on an app's page.
|
|
11
|
+
//
|
|
12
|
+
// The empty bar at rest shows the first key at the end of its text, so the
|
|
13
|
+
// key can be found: "⌘K", or "Ctrl K". It is not shown while the cursor is in
|
|
14
|
+
// the bar, once anything is typed, on a touch screen, or where the bar is too
|
|
15
|
+
// narrow for it (see the stylesheet for all but the last).
|
|
16
|
+
//
|
|
17
|
+
// The keys are left alone inside a terminal or a code editor, where Ctrl+K
|
|
18
|
+
// and Cmd+K have meanings of their own. Keys pressed inside a frame (an app's
|
|
19
|
+
// own page, a session's window) never reach this page, so they do nothing
|
|
20
|
+
// there. In a layout with several panes the key goes to the pane you are in.
|
|
21
|
+
(function (window, document) {
|
|
22
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
if (window.PinokioAgentBarShortcut) return;
|
|
25
|
+
window.PinokioAgentBarShortcut = true;
|
|
26
|
+
|
|
27
|
+
const OWN_KEYS = '.xterm, .ace_editor, .monaco-editor, .cm-editor, .CodeMirror';
|
|
28
|
+
const FIELD = 'input, textarea, select, [contenteditable=""], [contenteditable="true"]';
|
|
29
|
+
|
|
30
|
+
const isMac = () => /Mac|iPhone|iPad/.test((window.navigator && window.navigator.platform) || '');
|
|
31
|
+
const within = (node, selector) => Boolean(node && node.closest && node.closest(selector));
|
|
32
|
+
|
|
33
|
+
function wanted(event) {
|
|
34
|
+
if (event.isComposing || event.altKey || event.shiftKey) return false;
|
|
35
|
+
if (within(event.target, OWN_KEYS)) return false;
|
|
36
|
+
if (event.key === '/') {
|
|
37
|
+
return !event.metaKey && !event.ctrlKey && !within(event.target, FIELD);
|
|
38
|
+
}
|
|
39
|
+
if (String(event.key).toLowerCase() !== 'k') return false;
|
|
40
|
+
return isMac() ? (event.metaKey && !event.ctrlKey) : (event.ctrlKey && !event.metaKey);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ---- the key, shown in the empty bar ----
|
|
44
|
+
// narrower than this and the bar's own line is already cut short
|
|
45
|
+
const HINT_MIN_WIDTH = 260;
|
|
46
|
+
function showHint() {
|
|
47
|
+
const root = document.querySelector('.agent-bar');
|
|
48
|
+
const input = root && root.querySelector('.agent-bar__input');
|
|
49
|
+
if (!input) return false;
|
|
50
|
+
let hint = root.querySelector('.agent-bar-shortcut__hint');
|
|
51
|
+
if (!hint) {
|
|
52
|
+
hint = document.createElement('span');
|
|
53
|
+
hint.className = 'agent-bar-shortcut__hint';
|
|
54
|
+
hint.setAttribute('aria-hidden', 'true');
|
|
55
|
+
hint.textContent = isMac() ? '⌘K' : 'Ctrl K';
|
|
56
|
+
input.parentNode.insertBefore(hint, input.nextSibling);
|
|
57
|
+
const fit = () => {
|
|
58
|
+
// (measured with the key out of the way, so showing it cannot hide it again)
|
|
59
|
+
hint.hidden = true;
|
|
60
|
+
hint.hidden = Boolean(input.clientWidth) && input.clientWidth < HINT_MIN_WIDTH;
|
|
61
|
+
};
|
|
62
|
+
window.addEventListener('resize', fit);
|
|
63
|
+
if (typeof window.ResizeObserver === 'function') new window.ResizeObserver(fit).observe(root);
|
|
64
|
+
fit();
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
// The app page's bar may be put in the page after this has run.
|
|
69
|
+
let hinted = false;
|
|
70
|
+
const tryHint = () => { if (!hinted) hinted = showHint(); };
|
|
71
|
+
const bar = window.PinokioAgentBar;
|
|
72
|
+
if (bar && bar.ready) bar.ready.then(() => window.setTimeout(tryHint, 0));
|
|
73
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => window.setTimeout(tryHint, 0));
|
|
74
|
+
window.addEventListener('load', tryHint);
|
|
75
|
+
|
|
76
|
+
window.addEventListener('keydown', (event) => {
|
|
77
|
+
if (!wanted(event)) return;
|
|
78
|
+
const root = document.querySelector('.agent-bar');
|
|
79
|
+
const input = root && root.querySelector('.agent-bar__input');
|
|
80
|
+
// no bar on this page, or it is not on screen, or a send is under way
|
|
81
|
+
if (!input || input.disabled || !root.getClientRects().length) return;
|
|
82
|
+
const host = root.dataset.item === 'ask_app' ? window.PinokioAgentBarApp : window.PinokioAgentBar;
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
event.stopPropagation();
|
|
85
|
+
const view = host && host.view;
|
|
86
|
+
const open = view ? view.isOpen() : root.dataset.engaged === 'true';
|
|
87
|
+
if (root.contains(document.activeElement) && open) {
|
|
88
|
+
// from inside the bar: leave it
|
|
89
|
+
if (host && typeof host.leave === 'function') host.leave();
|
|
90
|
+
if (root.contains(document.activeElement)) document.activeElement.blur();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (document.activeElement !== input) {
|
|
94
|
+
try { input.focus({ preventScroll: true }); } catch (_) { input.focus(); }
|
|
95
|
+
input.setSelectionRange(input.value.length, input.value.length);
|
|
96
|
+
}
|
|
97
|
+
// the cursor was already there with the box closed (home, on arriving)
|
|
98
|
+
if (view && !view.isOpen() && document.activeElement === input) {
|
|
99
|
+
if (root.dataset.engaged !== 'true' && typeof host.engage === 'function') host.engage();
|
|
100
|
+
view.show();
|
|
101
|
+
}
|
|
102
|
+
}, true);
|
|
103
|
+
})(window, document);
|
|
@@ -798,7 +798,8 @@
|
|
|
798
798
|
const aboutApp = () => (state.item === 'ask' ? api.about.app() : null);
|
|
799
799
|
const hintNow = () => {
|
|
800
800
|
const about = aboutApp();
|
|
801
|
-
|
|
801
|
+
// (the bar also finds apps and says so: agent-bar-search.js)
|
|
802
|
+
return about ? `Ask Pinokio about ${about.name}…` : ((state.item === 'ask' && api.askHint) || ITEMS[state.item].placeholder);
|
|
802
803
|
};
|
|
803
804
|
const promptText = () => (state.item === 'create_plugin' && input.value.startsWith(PLUGIN_PROMPT_SEED)
|
|
804
805
|
? input.value.slice(PLUGIN_PROMPT_SEED.length)
|
|
@@ -1000,6 +1001,7 @@
|
|
|
1000
1001
|
// for the compose view (agent-bar-compose.js): leave the bar; the chosen agent;
|
|
1001
1002
|
// what the empty text says at rest
|
|
1002
1003
|
api.leave = leave;
|
|
1004
|
+
api.engage = engage;
|
|
1003
1005
|
api.tool = selectedTool;
|
|
1004
1006
|
api.hint = hintNow;
|
|
1005
1007
|
// what the open view's face says, when it is not the mode's own line
|