pinokiod 8.3.34 → 8.3.36

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.
@@ -0,0 +1,274 @@
1
+ /* Agent bar: the card for a plugin that opens a desktop app (see
2
+ agent-bar-launch.js). It comes up bottom right, where a session's window
3
+ opens, above the dock's windows and tabs and under every dialog. Its colours,
4
+ corners and shadow are the window's own. */
5
+ .agent-launch {
6
+ position: fixed;
7
+ right: 16px;
8
+ bottom: 46px;
9
+ z-index: 70;
10
+ display: flex;
11
+ flex-direction: column-reverse;
12
+ align-items: flex-end;
13
+ gap: 8px;
14
+ pointer-events: none;
15
+ }
16
+ .agent-launch__card {
17
+ --abp-text: #111827;
18
+ --abp-muted: rgba(55, 65, 81, 0.78);
19
+ --abp-border: rgba(15, 23, 42, 0.12);
20
+ --abp-surface: #ffffff;
21
+ --abp-chip: rgba(15, 23, 42, 0.06);
22
+ --abp-chip-hover: rgba(15, 23, 42, 0.1);
23
+ --agent-launch-ok: #3f9b1f;
24
+ --agent-launch-bad: #c2410c;
25
+ width: min(420px, calc(100vw - 32px));
26
+ box-sizing: border-box;
27
+ overflow: hidden;
28
+ pointer-events: auto;
29
+ border: 1px solid var(--abp-border);
30
+ border-radius: 12px;
31
+ background: var(--abp-surface);
32
+ color: var(--abp-text);
33
+ font: 400 13px system-ui, -apple-system, "Segoe UI", sans-serif;
34
+ letter-spacing: 0;
35
+ text-align: left;
36
+ box-shadow: 0 18px 44px rgba(15, 23, 42, 0.22), 0 2px 8px rgba(15, 23, 42, 0.1);
37
+ opacity: 0;
38
+ transform: translateY(10px);
39
+ visibility: hidden;
40
+ transition: opacity 200ms ease, transform 200ms cubic-bezier(0.25, 1, 0.5, 1), visibility 0s linear 200ms;
41
+ }
42
+ body.dark .agent-launch__card {
43
+ --abp-text: rgba(250, 250, 250, 0.96);
44
+ --abp-muted: rgba(161, 161, 170, 0.92);
45
+ --abp-border: rgba(255, 255, 255, 0.1);
46
+ --abp-surface: #1b1c1d;
47
+ --abp-chip: rgba(255, 255, 255, 0.08);
48
+ --abp-chip-hover: rgba(255, 255, 255, 0.14);
49
+ --agent-launch-ok: #6cc644;
50
+ --agent-launch-bad: #fb923c;
51
+ }
52
+ .agent-launch__card[data-open="true"] {
53
+ opacity: 1;
54
+ transform: none;
55
+ visibility: visible;
56
+ transition: opacity 200ms ease, transform 200ms cubic-bezier(0.25, 1, 0.5, 1), visibility 0s;
57
+ }
58
+ .agent-launch__card [hidden] {
59
+ display: none !important;
60
+ }
61
+ .agent-launch__card button {
62
+ font: inherit;
63
+ letter-spacing: 0;
64
+ color: var(--abp-text);
65
+ cursor: pointer;
66
+ }
67
+ .agent-launch__main {
68
+ display: flex;
69
+ align-items: center;
70
+ gap: 12px;
71
+ padding: 14px 10px 14px 14px;
72
+ }
73
+ .agent-launch__icon {
74
+ flex: none;
75
+ width: 36px;
76
+ height: 36px;
77
+ display: inline-flex;
78
+ align-items: center;
79
+ justify-content: center;
80
+ font-size: 18px;
81
+ color: var(--abp-muted);
82
+ }
83
+ .agent-launch__icon img {
84
+ width: 36px;
85
+ height: 36px;
86
+ object-fit: cover;
87
+ border-radius: 9px;
88
+ }
89
+ .agent-launch__text {
90
+ flex: 1 1 auto;
91
+ min-width: 0;
92
+ }
93
+ .agent-launch__title {
94
+ font-size: 13px;
95
+ font-weight: 600;
96
+ line-height: 17px;
97
+ }
98
+ .agent-launch__sub {
99
+ margin-top: 1px;
100
+ font-size: 12px;
101
+ line-height: 16px;
102
+ color: var(--abp-muted);
103
+ overflow-wrap: anywhere;
104
+ }
105
+ .agent-launch__mark {
106
+ flex: none;
107
+ width: 22px;
108
+ height: 22px;
109
+ display: inline-flex;
110
+ align-items: center;
111
+ justify-content: center;
112
+ }
113
+ .agent-launch__close {
114
+ flex: none;
115
+ align-self: flex-start;
116
+ width: 26px;
117
+ height: 26px;
118
+ margin: -6px -2px 0 0;
119
+ padding: 0;
120
+ display: inline-flex;
121
+ align-items: center;
122
+ justify-content: center;
123
+ border: 0;
124
+ border-radius: 8px;
125
+ background: transparent;
126
+ font-size: 12px;
127
+ }
128
+ .agent-launch__card .agent-launch__close {
129
+ color: var(--abp-muted);
130
+ }
131
+ .agent-launch__close:hover {
132
+ background: var(--abp-chip-hover);
133
+ }
134
+
135
+ .agent-launch__spinner {
136
+ width: 16px;
137
+ height: 16px;
138
+ box-sizing: border-box;
139
+ border-radius: 50%;
140
+ border: 2px solid var(--abp-chip-hover);
141
+ border-top-color: var(--abp-text);
142
+ animation: agent-launch-spin 0.8s linear infinite;
143
+ }
144
+ @keyframes agent-launch-spin {
145
+ to { transform: rotate(360deg); }
146
+ }
147
+ .agent-launch__check {
148
+ position: relative;
149
+ width: 20px;
150
+ height: 20px;
151
+ border-radius: 50%;
152
+ background: var(--agent-launch-ok);
153
+ animation: agent-launch-pop 220ms cubic-bezier(0.25, 1.4, 0.5, 1);
154
+ }
155
+ .agent-launch__check::after {
156
+ content: "";
157
+ position: absolute;
158
+ left: 7px;
159
+ top: 4px;
160
+ width: 4px;
161
+ height: 8px;
162
+ border: solid #ffffff;
163
+ border-width: 0 2px 2px 0;
164
+ transform: rotate(45deg);
165
+ }
166
+ @keyframes agent-launch-pop {
167
+ from { transform: scale(0.4); opacity: 0; }
168
+ }
169
+ .agent-launch__warn {
170
+ width: 20px;
171
+ height: 20px;
172
+ border-radius: 50%;
173
+ background: var(--agent-launch-bad);
174
+ }
175
+ .agent-launch__warn::after {
176
+ content: "!";
177
+ display: block;
178
+ color: #ffffff;
179
+ font-weight: 700;
180
+ font-size: 13px;
181
+ line-height: 20px;
182
+ text-align: center;
183
+ }
184
+
185
+ /* opened: a line that runs out, then the card closes. Pointing at it holds it. */
186
+ .agent-launch__timer {
187
+ height: 2px;
188
+ background: var(--agent-launch-ok);
189
+ transform-origin: left;
190
+ animation: agent-launch-drain 2600ms linear forwards;
191
+ }
192
+ .agent-launch__card:hover .agent-launch__timer {
193
+ animation: none;
194
+ }
195
+ @keyframes agent-launch-drain {
196
+ to { transform: scaleX(0); }
197
+ }
198
+
199
+ /* it did not open */
200
+ .agent-launch__actions {
201
+ display: flex;
202
+ flex-wrap: wrap;
203
+ gap: 6px;
204
+ padding: 0 14px 14px 62px;
205
+ }
206
+ .agent-launch__actions button {
207
+ height: 28px;
208
+ padding: 0 11px;
209
+ border: 1px solid var(--abp-border);
210
+ border-radius: 8px;
211
+ background: var(--abp-chip);
212
+ font-size: 12px;
213
+ font-weight: 600;
214
+ }
215
+ .agent-launch__actions button:hover {
216
+ background: var(--abp-chip-hover);
217
+ }
218
+ .agent-launch__card .agent-launch__actions .agent-launch__primary {
219
+ border-color: transparent;
220
+ background: var(--abp-text);
221
+ color: var(--abp-surface);
222
+ }
223
+ .agent-launch__card .agent-launch__actions .agent-launch__quiet {
224
+ border-color: transparent;
225
+ background: transparent;
226
+ color: var(--abp-muted);
227
+ }
228
+ .agent-launch__details {
229
+ margin: 0;
230
+ padding: 10px 14px;
231
+ max-height: 120px;
232
+ overflow: auto;
233
+ border-top: 1px solid var(--abp-border);
234
+ background: #0b0b0c;
235
+ color: #d4d4d8;
236
+ font: 11px/16px ui-monospace, SFMono-Regular, Menlo, monospace;
237
+ white-space: pre-wrap;
238
+ word-break: break-all;
239
+ }
240
+
241
+ /* The plugin's page. Laid out at a real size so its terminal can measure
242
+ itself, and not on show: the card has no height for it. */
243
+ .agent-launch__stage {
244
+ height: 0;
245
+ overflow: hidden;
246
+ }
247
+ .agent-launch__frame {
248
+ display: block;
249
+ width: 100%;
250
+ height: 440px;
251
+ border: 0;
252
+ }
253
+ /* Pinokio's question about the folder is part of that page: shown while it is up */
254
+ .agent-launch__card[data-stage="true"] {
255
+ width: min(560px, calc(100vw - 32px));
256
+ }
257
+ .agent-launch__card[data-stage="true"] .agent-launch__stage {
258
+ height: min(440px, calc(100vh - 180px));
259
+ border-top: 1px solid var(--abp-border);
260
+ }
261
+ .agent-launch__card[data-stage="true"] .agent-launch__mark {
262
+ display: none;
263
+ }
264
+
265
+ @media (prefers-reduced-motion: reduce) {
266
+ .agent-launch__card,
267
+ .agent-launch__card[data-open="true"] {
268
+ transition: none;
269
+ }
270
+ .agent-launch__check,
271
+ .agent-launch__timer {
272
+ animation: none;
273
+ }
274
+ }
@@ -0,0 +1,333 @@
1
+ // Agent bar: launching a plugin that opens a desktop app (Codex Desktop, Claude
2
+ // Desktop, Cursor, VS Code). Loaded before agent-bar-panel.js, which offers every
3
+ // session it is about to start to take().
4
+ //
5
+ // - Such a plugin has nothing to show in a terminal window: it opens the app and
6
+ // you carry on there. So it gets no window and no tab. A small card comes up
7
+ // bottom right, where a window would have opened: "Opening <app>…", then
8
+ // "Opened in <app>", and it closes by itself. Pointing at it holds it open.
9
+ // - The plugin is started the way every session is: its own page is loaded, here
10
+ // in a frame inside the card that is not on show. The page tells this one what
11
+ // happens (start, the end, an error, a notice, a step that waits for Stop).
12
+ // - A plugin that ends with a step that waits for Stop has opened the app when it
13
+ // gets there. The card presses the page's own Stop, so nothing is left waiting.
14
+ // - If it fails, the card stays and says so, with the error to read and a way to
15
+ // try again. If the plugin says something instead (Cursor: "not installed"),
16
+ // the card stays with the plugin's own words and its link.
17
+ // - If Pinokio first asks whether an agent may work in the folder, that question
18
+ // is shown in the card, at a size it can be answered in.
19
+ // - Anything else (the page never starts the plugin, or the plugin keeps running
20
+ // without getting anywhere) is handed back to the dock, which shows the
21
+ // session's page in a window as before.
22
+ (function (window, document) {
23
+ 'use strict';
24
+ if (window.PinokioAgentBarLaunch) return;
25
+
26
+ // how long each wait lasts, in ms
27
+ const times = {
28
+ close: 2600, // "Opened in ..." stays this long
29
+ start: 10000, // the page has this long to start the plugin
30
+ run: 20000, // and the plugin this long to open the app
31
+ answer: 2500, // after the folder question is answered, this long to start
32
+ poll: 300, // how often the page is looked at for the folder question
33
+ };
34
+ const cards = new Map();
35
+ let host = null;
36
+ let links = null;
37
+
38
+ const helpers = () => (window.PinokioAgentBar && window.PinokioAgentBar.helpers) || null;
39
+
40
+ // Each plugin's own homepage, by the end of its address. Read once.
41
+ function loadLinks() {
42
+ if (!links) {
43
+ links = window.fetch('/api/plugin/menu')
44
+ .then((response) => (response.ok ? response.json() : null))
45
+ .then((payload) => {
46
+ const H = helpers();
47
+ const found = new Map();
48
+ (payload && Array.isArray(payload.menu) ? payload.menu : []).forEach((plugin) => {
49
+ if (plugin && typeof plugin.href === 'string' && typeof plugin.link === 'string' && plugin.link) {
50
+ found.set(H.pluginTail(plugin.href.trim()), plugin.link);
51
+ }
52
+ });
53
+ return found;
54
+ })
55
+ .catch(() => new Map());
56
+ }
57
+ return links;
58
+ }
59
+
60
+ // A step that waits until Stop is pressed: process.wait with nothing to wait for.
61
+ const waitsForStop = (params) => !params
62
+ || !(params.app || params.id || params.name || params.sec || params.min || params.uri || params.url || params.on);
63
+
64
+ const plainText = (html) => {
65
+ const parsed = new window.DOMParser().parseFromString(String(html || ''), 'text/html');
66
+ return (parsed.body ? parsed.body.textContent : '').replace(/\s+/g, ' ').trim();
67
+ };
68
+ // An error as the kernel sends it is a stack: the message, then where it was thrown.
69
+ const errorLines = (text) => String(text || '').split('\n')
70
+ .filter((line) => !/^\s+at\s/.test(line))
71
+ .map((line) => line.replace(/^Error:\s*/, '').trim())
72
+ .filter(Boolean);
73
+ const webAddress = (value) => {
74
+ try {
75
+ const url = new URL(String(value || ''), window.location.origin);
76
+ return /^https?:$/.test(url.protocol) ? url : null;
77
+ } catch (_) {
78
+ return null;
79
+ }
80
+ };
81
+
82
+ function ensureHost() {
83
+ if (!host || !host.isConnected) {
84
+ host = helpers().el('div', 'agent-launch');
85
+ document.body.appendChild(host);
86
+ }
87
+ return host;
88
+ }
89
+
90
+ function build(card) {
91
+ const { el, faIcon, toolIcon } = helpers();
92
+ const element = el('aside', 'agent-launch__card');
93
+ element.setAttribute('role', 'status');
94
+ element.setAttribute('aria-live', 'polite');
95
+ element.dataset.open = 'false';
96
+ const main = el('div', 'agent-launch__main');
97
+ const icon = el('span', 'agent-launch__icon');
98
+ icon.appendChild(toolIcon({ iconSrc: card.tool.iconSrc, iconClass: 'fa-solid fa-arrow-up-right-from-square' }));
99
+ const text = el('div', 'agent-launch__text');
100
+ card.title = el('div', 'agent-launch__title');
101
+ card.sub = el('div', 'agent-launch__sub');
102
+ text.append(card.title, card.sub);
103
+ card.mark = el('span', 'agent-launch__mark');
104
+ card.closer = el('button', 'agent-launch__close');
105
+ card.closer.type = 'button';
106
+ card.closer.setAttribute('aria-label', 'Close');
107
+ card.closer.appendChild(faIcon('fa-solid fa-xmark'));
108
+ card.closer.addEventListener('click', () => close(card));
109
+ main.append(icon, text, card.mark, card.closer);
110
+ card.actions = el('div', 'agent-launch__actions');
111
+ card.details = el('pre', 'agent-launch__details');
112
+ card.stage = el('div', 'agent-launch__stage');
113
+ card.timer = el('div', 'agent-launch__timer');
114
+ element.append(main, card.actions, card.details, card.stage, card.timer);
115
+ // pointing at it holds it open; leaving starts the wait again
116
+ element.addEventListener('mouseenter', () => {
117
+ if (card.state === 'opened') window.clearTimeout(card.closing);
118
+ });
119
+ element.addEventListener('mouseleave', () => {
120
+ if (card.state === 'opened') closeSoon(card);
121
+ });
122
+ card.element = element;
123
+ ensureHost().appendChild(element);
124
+ }
125
+
126
+ function clearTimers(card) {
127
+ ['waiting', 'closing', 'looking'].forEach((name) => {
128
+ window.clearTimeout(card[name]);
129
+ window.clearInterval(card[name]);
130
+ card[name] = null;
131
+ });
132
+ }
133
+
134
+ function draw(card, state, title, sub, mark) {
135
+ card.state = state;
136
+ card.element.dataset.state = state;
137
+ card.title.textContent = title;
138
+ card.sub.textContent = sub || '';
139
+ card.sub.hidden = !sub;
140
+ card.mark.textContent = '';
141
+ card.mark.appendChild(helpers().el('span', `agent-launch__${mark}`));
142
+ card.closer.hidden = state === 'opening';
143
+ card.actions.textContent = '';
144
+ card.actions.hidden = true;
145
+ card.details.hidden = true;
146
+ card.timer.hidden = state !== 'opened';
147
+ }
148
+
149
+ function action(card, label, className, run) {
150
+ const button = helpers().el('button', className, label);
151
+ button.type = 'button';
152
+ button.addEventListener('click', (event) => run(event));
153
+ card.actions.appendChild(button);
154
+ card.actions.hidden = false;
155
+ return button;
156
+ }
157
+
158
+ // The plugin's page, in a frame of the card that is not on show. Loading it is
159
+ // what starts the plugin.
160
+ function begin(card) {
161
+ clearTimers(card);
162
+ card.started = false;
163
+ card.staged = false;
164
+ card.element.dataset.stage = 'false';
165
+ draw(card, 'opening', `Opening ${card.name}…`, card.session.placeName || '', 'spinner');
166
+ if (card.frame) card.frame.remove();
167
+ card.frame = document.createElement('iframe');
168
+ card.frame.className = 'agent-launch__frame';
169
+ card.frame.title = card.name;
170
+ card.frame.tabIndex = -1;
171
+ // the page must not take the keyboard from where you are
172
+ card.frame.setAttribute('data-skip-startup-focus', '');
173
+ card.frame.src = card.launchUrl;
174
+ card.stage.appendChild(card.frame);
175
+ card.waiting = window.setTimeout(() => handOver(card, 'launch'), times.start);
176
+ card.looking = window.setInterval(() => lookForQuestion(card), times.poll);
177
+ card.element.getBoundingClientRect();
178
+ card.element.dataset.open = 'true';
179
+ }
180
+
181
+ // Pinokio asks before an agent works in a folder for the first time. The
182
+ // question is part of the plugin's page, so the page is put on show while it is up.
183
+ function lookForQuestion(card) {
184
+ if (card.state !== 'opening' || card.started) return;
185
+ let asking = false;
186
+ try {
187
+ const doc = card.frame.contentDocument;
188
+ asking = Boolean(doc && doc.querySelector('.ai-consent-overlay.is-visible'));
189
+ } catch (_) {}
190
+ if (asking === card.staged) return;
191
+ card.staged = asking;
192
+ card.element.dataset.stage = String(asking);
193
+ window.clearTimeout(card.waiting);
194
+ if (asking) {
195
+ card.title.textContent = `${card.name} needs your OK`;
196
+ card.closer.hidden = false;
197
+ } else {
198
+ // answered: allowed starts the plugin; cancelled starts nothing, and the card goes
199
+ card.title.textContent = `Opening ${card.name}…`;
200
+ card.closer.hidden = true;
201
+ card.waiting = window.setTimeout(() => close(card), times.answer);
202
+ }
203
+ }
204
+
205
+ function closeSoon(card) {
206
+ window.clearTimeout(card.closing);
207
+ // the line runs out again from the start
208
+ card.timer.style.animation = 'none';
209
+ card.timer.getBoundingClientRect();
210
+ card.timer.style.animation = '';
211
+ card.timer.style.animationDuration = `${times.close}ms`;
212
+ card.closing = window.setTimeout(() => close(card), times.close);
213
+ }
214
+
215
+ function opened(card, waiting) {
216
+ clearTimers(card);
217
+ // the plugin sits in a step that waits for Stop: the page's own Stop ends it
218
+ if (waiting) {
219
+ try {
220
+ const stop = card.frame.contentDocument.querySelector('.stop');
221
+ if (stop) stop.click();
222
+ } catch (_) {}
223
+ }
224
+ draw(card, 'opened', `Opened in ${card.name}`, 'Carry on there.', 'check');
225
+ closeSoon(card);
226
+ }
227
+
228
+ function failed(card, text) {
229
+ clearTimers(card);
230
+ const lines = errorLines(text);
231
+ draw(card, 'failed', `Couldn't open ${card.name}`, lines[0] || 'The plugin stopped with an error.', 'warn');
232
+ loadLinks().then((found) => {
233
+ if (card.state !== 'failed') return;
234
+ const link = webAddress(found.get(card.tail));
235
+ if (link) action(card, `Get ${card.name}`, 'agent-launch__primary', () => window.open(link.href, '_blank', 'noopener'));
236
+ action(card, 'Try again', '', () => begin(card));
237
+ if (lines.length > 1) {
238
+ card.details.textContent = lines.join('\n');
239
+ action(card, 'Show details', 'agent-launch__quiet', (event) => {
240
+ card.details.hidden = !card.details.hidden;
241
+ event.currentTarget.textContent = card.details.hidden ? 'Show details' : 'Hide details';
242
+ });
243
+ }
244
+ });
245
+ }
246
+
247
+ // The plugin said something instead of opening the app. Its words, and its link.
248
+ function said(card, notice) {
249
+ clearTimers(card);
250
+ draw(card, 'said', card.name, plainText(notice && notice.html) || 'The plugin did not open the app.', 'warn');
251
+ const link = webAddress(notice && (notice.uri || notice.href));
252
+ if (link) action(card, `Open ${link.hostname.replace(/^www\./, '')}`, 'agent-launch__primary', () => window.open(link.href, '_blank', 'noopener'));
253
+ action(card, 'Try again', '', () => begin(card));
254
+ }
255
+
256
+ function close(card) {
257
+ clearTimers(card);
258
+ if (cards.get(card.key) === card) cards.delete(card.key);
259
+ card.state = 'closed';
260
+ card.element.dataset.open = 'false';
261
+ // the page goes with it, once the card has faded away
262
+ window.setTimeout(() => card.element.remove(), 220);
263
+ }
264
+
265
+ // Not something a card can show: the dock gives it a window, as before.
266
+ // 'launch' loads the page again (nothing was started); 'attach' shows the
267
+ // session only if it is still running.
268
+ function handOver(card, how) {
269
+ close(card);
270
+ card.element.remove();
271
+ if (how === 'launch') card.dock.open(card.session, { launchUrl: card.launchUrl, window: true });
272
+ else card.dock.show(card.session);
273
+ }
274
+
275
+ window.addEventListener('message', (event) => {
276
+ const data = event && event.data;
277
+ if (!data || typeof data !== 'object' || !cards.size) return;
278
+ let card = null;
279
+ cards.forEach((item) => {
280
+ if (item.frame && item.frame.contentWindow === event.source) card = item;
281
+ });
282
+ if (!card || card.state !== 'opening') return;
283
+ if (data.type === 'start') {
284
+ if (card.started) return;
285
+ card.started = true;
286
+ // the question, if there was one, has been answered: the page is put away again
287
+ if (card.staged) {
288
+ card.staged = false;
289
+ card.element.dataset.stage = 'false';
290
+ card.title.textContent = `Opening ${card.name}…`;
291
+ card.closer.hidden = true;
292
+ }
293
+ window.clearTimeout(card.waiting);
294
+ card.waiting = window.setTimeout(() => handOver(card, 'attach'), times.run);
295
+ } else if (data.type === 'pinokio:session-step') {
296
+ if (data.step === 'error') failed(card, data.data);
297
+ else if (data.step === 'notify') said(card, data.data);
298
+ else if (data.step === 'process.wait.start' && waitsForStop(data.data)) opened(card, true);
299
+ } else if (data.type === 'disconnect' && card.started) {
300
+ // its steps are over and none failed
301
+ opened(card, false);
302
+ }
303
+ });
304
+
305
+ // Offered every session the dock is about to start. True when it is a desktop
306
+ // app's launch and the card has taken it; the dock then opens no window.
307
+ // dock: { tools, open(session, options), show(session) }
308
+ function take(session, launchUrl, dock) {
309
+ const H = helpers();
310
+ if (!H || !document.body || !session || session.kind !== 'agent' || !launchUrl || !dock) return false;
311
+ let tail = '';
312
+ try {
313
+ tail = H.pluginTail(new URL(launchUrl, window.location.origin).pathname);
314
+ } catch (_) {
315
+ return false;
316
+ }
317
+ const tool = (Array.isArray(dock.tools) ? dock.tools : []).find((item) => item.href && H.pluginTail(item.href) === tail);
318
+ if (!tool || tool.category !== 'IDE') return false;
319
+ const before = cards.get(session.key);
320
+ if (before) {
321
+ close(before);
322
+ before.element.remove();
323
+ }
324
+ const card = { key: session.key, session, launchUrl, dock, tool, tail, name: tool.label || session.label || 'the app' };
325
+ cards.set(card.key, card);
326
+ build(card);
327
+ begin(card);
328
+ loadLinks();
329
+ return true;
330
+ }
331
+
332
+ window.PinokioAgentBarLaunch = { take, times };
333
+ })(window, document);
@@ -793,6 +793,8 @@
793
793
  // its session's page keeps it.
794
794
  function open(session, options) {
795
795
  const settings = options || {};
796
+ // a desktop app's launch has a card of its own and no window (agent-bar-launch.js)
797
+ if (settings.launchUrl && !settings.window && window.PinokioAgentBarLaunch && window.PinokioAgentBarLaunch.take(session, settings.launchUrl, { tools, open, show })) return;
796
798
  syncTop();
797
799
  let tab = tabOf(session.key);
798
800
  const fresh = !tab || !tab.open;
@@ -244,6 +244,7 @@
244
244
  // The agent menu's rows: agents by name, then desktop apps. `pick(tool)` is
245
245
  // called with the one that was chosen.
246
246
  function agentMenuRows(menu, tools, loaded, current, pick) {
247
+ if (window.PinokioAgentMenu) return window.PinokioAgentMenu.fill(menu, tools, loaded, current, pick);
247
248
  const byLabel = (a, b) => String(a.label).toLowerCase().localeCompare(String(b.label).toLowerCase());
248
249
  const addTool = (tool) => menu.appendChild(menuRow(toolIcon(tool), tool.label, '', tool.value === current, () => pick(tool)));
249
250
  menu.appendChild(el('div', 'agent-bar__menu-title', 'Runs with'));
@@ -1013,6 +1014,15 @@
1013
1014
  // (This can be the first thing done in the bar, so the agents are read here
1014
1015
  // too: going to the text afterwards no longer does it, the bar is already in use.)
1015
1016
  api.choose = (key) => { loadTools(); setItem(key); focusInputAtEnd(); };
1017
+ // the agent picked from outside the bar, as a row of its agent menu picks it
1018
+ // and remembers it (the Plugins page's "Open in", through agent-bar-about.js)
1019
+ api.useTool = (value) => {
1020
+ if (!value) return;
1021
+ setStoredTool(value);
1022
+ if (state.tools.some((tool) => tool.value === value)) state.tool = value;
1023
+ loadTools();
1024
+ render();
1025
+ };
1016
1026
 
1017
1027
  function toggleMenu(which) {
1018
1028
  if (state.busy) return;
@@ -434,9 +434,9 @@
434
434
  <div class="plugin-modal-heading">
435
435
  <div class="plugin-modal-title-row">
436
436
  ${pluginArt}
437
- <h3 id="plugin-modal-title">Run ${escapeHtml(pluginTitle)}</h3>
437
+ <h3 id="plugin-modal-title">Open ${escapeHtml(pluginTitle)} in…</h3>
438
438
  </div>
439
- <p class="url-modal-description plugin-modal-description" id="plugin-modal-description">Choose a project to launch this plugin in.</p>
439
+ <p class="url-modal-description plugin-modal-description" id="plugin-modal-description">Choose a project to ask about with this plugin.</p>
440
440
  </div>
441
441
  <button type="button" class="url-modal-close plugin-modal-close" aria-label="Close">&times;</button>
442
442
  </div>
@@ -616,6 +616,16 @@
616
616
  alert("Select a project to continue.");
617
617
  return;
618
618
  }
619
+ // The agent bar at the top of this page opens on Ask about that app, with
620
+ // this plugin as the agent; nothing starts until the Ask is sent. A page
621
+ // without the bar opens the app's page, as before.
622
+ const bar = window.PinokioAgentBar;
623
+ if (bar && typeof bar.pointAt === "function") {
624
+ closeModal();
625
+ const tool = bar.helpers.mapPluginMenuToTools([{ href: plugin.pluginPath }])[0];
626
+ bar.pointAt({ id: app.name, name: app.title || app.name, folder: app.cwd, icon: app.icon }, tool ? tool.value : "");
627
+ return;
628
+ }
619
629
  const target = buildPluginLaunchTarget(app);
620
630
  if (!target) {
621
631
  closeModal();
@@ -664,11 +674,11 @@
664
674
 
665
675
  return {
666
676
  open() {
667
- titleEl.textContent = plugin && plugin.title ? `Run ${plugin.title}` : "Run Plugin";
677
+ titleEl.textContent = plugin && plugin.title ? `Open ${plugin.title} in…` : "Open plugin in…";
668
678
  if (state.apps.length === 0) {
669
679
  descriptionEl.textContent = "No projects found under ~/pinokio/api. Create or download a project to continue.";
670
680
  } else {
671
- descriptionEl.textContent = "Choose a project to launch this plugin in.";
681
+ descriptionEl.textContent = "Choose a project to ask about with this plugin.";
672
682
  }
673
683
  renderList("");
674
684
  dropdownEl.style.display = "grid";