pinokiod 8.3.26 → 8.3.29
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/shell.js +3 -0
- package/kernel/shell_size.js +99 -0
- package/kernel/shells.js +2 -0
- package/package.json +1 -1
- package/server/index.js +7 -3
- package/server/lib/app_run_tabs.js +29 -17
- package/server/public/agent-bar-about.css +67 -0
- package/server/public/agent-bar-about.js +205 -0
- package/server/public/agent-bar-compose.js +4 -1
- package/server/public/agent-bar-modes.css +78 -0
- package/server/public/agent-bar-modes.js +97 -0
- package/server/public/agent-bar-panel.js +41 -13
- package/server/public/agent-bar.css +7 -5
- package/server/public/agent-bar.js +37 -9
- package/server/public/app-run-tabs.js +0 -10
- package/server/public/files-app/open-folder.js +58 -41
- package/server/public/files-app/toolbar.css +27 -5
- package/server/public/git-page.css +0 -1
- package/server/public/git-page.js +269 -149
- package/server/public/home-actions-menu.css +188 -0
- package/server/public/home-actions-menu.js +135 -0
- package/server/public/home-shell.css +121 -0
- package/server/public/home-shell.js +290 -0
- package/server/routes/git_page.js +4 -6
- package/server/views/app.ejs +19 -5
- package/server/views/file_browser.ejs +3 -4
- package/server/views/index.ejs +42 -3
- package/server/views/partials/home_action_modal.ejs +1 -1
- package/server/views/partials/home_ask_button.ejs +15 -0
- package/server/views/partials/home_shell_button.ejs +21 -0
- package/server/views/partials/main_sidebar.ejs +5 -1
- package/server/views/pre.ejs +1 -1
- package/test/agent-bar-about.test.js +238 -0
- package/test/agent-bar-modes.test.js +191 -0
- package/test/agent-bar-new-tab.test.js +60 -0
- package/test/app-git-files-tabs.test.js +84 -0
- package/test/home-actions-menu.test.js +187 -0
- package/test/home-shell.test.js +358 -0
- package/test/shell-size.test.js +166 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The agent bar's modes, all named at once.
|
|
2
|
+
//
|
|
3
|
+
// In the open view on a desktop the mode chip (one name and a menu) gives way to
|
|
4
|
+
// a row along the top of the box that names every mode: Ask, Create app, Create
|
|
5
|
+
// plugin, Download. The one in use has the chip's pill; a click on another
|
|
6
|
+
// switches to it. Nothing has to be opened to learn what the bar can do.
|
|
7
|
+
//
|
|
8
|
+
// The row has a line of its own, so it does not depend on what else the box
|
|
9
|
+
// holds: the agent's name, however long, or what send says.
|
|
10
|
+
//
|
|
11
|
+
// The chip and its menu stay where there is no row: the bar at rest, a phone,
|
|
12
|
+
// and a box too narrow for the four names.
|
|
13
|
+
//
|
|
14
|
+
// This file only adds the row. The modes and what choosing one does are the
|
|
15
|
+
// bar's own (agent-bar.js: `modes`, `choose`); the box is the compose view's
|
|
16
|
+
// (agent-bar-compose.js).
|
|
17
|
+
(function (window, document) {
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const bar = window.PinokioAgentBar;
|
|
21
|
+
if (!bar) return;
|
|
22
|
+
|
|
23
|
+
function install() {
|
|
24
|
+
const root = document.querySelector('.agent-bar');
|
|
25
|
+
if (!root) return false;
|
|
26
|
+
// the app page's bar only asks
|
|
27
|
+
if (root.dataset.item === 'ask_app') return true;
|
|
28
|
+
if (root.classList.contains('agent-bar--modes')) return true;
|
|
29
|
+
const field = root.querySelector('.agent-bar__field');
|
|
30
|
+
// (made by the compose view, whose box this row is part of)
|
|
31
|
+
const controls = root.querySelector('.agent-compose__controls');
|
|
32
|
+
const scope = root.querySelector('.agent-bar__scope');
|
|
33
|
+
if (!field || !controls || !scope || typeof bar.modes !== 'function' || typeof bar.choose !== 'function') return false;
|
|
34
|
+
|
|
35
|
+
const row = document.createElement('div');
|
|
36
|
+
row.className = 'agent-bar-modes';
|
|
37
|
+
row.setAttribute('role', 'radiogroup');
|
|
38
|
+
row.setAttribute('aria-label', 'What to do');
|
|
39
|
+
const buttons = bar.modes().map((mode) => {
|
|
40
|
+
const button = document.createElement('button');
|
|
41
|
+
button.type = 'button';
|
|
42
|
+
button.className = 'agent-bar-modes__item';
|
|
43
|
+
button.setAttribute('role', 'radio');
|
|
44
|
+
button.dataset.mode = mode.key;
|
|
45
|
+
button.textContent = mode.label;
|
|
46
|
+
button.addEventListener('click', () => bar.choose(mode.key));
|
|
47
|
+
row.appendChild(button);
|
|
48
|
+
return button;
|
|
49
|
+
});
|
|
50
|
+
// the first row of the box (the stylesheet orders the rows)
|
|
51
|
+
field.insertBefore(row, field.querySelector('.agent-compose__toprow') || field.firstChild);
|
|
52
|
+
root.classList.add('agent-bar--modes');
|
|
53
|
+
// like the view's other buttons, the names do not take the cursor out of the text
|
|
54
|
+
row.addEventListener('pointerdown', (event) => {
|
|
55
|
+
if (event.target.closest && event.target.closest('button')) event.preventDefault();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Is the box wide enough for the four names? (While it is not, the row is
|
|
59
|
+
// out of sight but still laid out, so it can be measured. Widths are read in
|
|
60
|
+
// whole pixels, so a little is kept in hand.)
|
|
61
|
+
function fits() {
|
|
62
|
+
const style = window.getComputedStyle(row);
|
|
63
|
+
const between = parseFloat(style.columnGap) || 0;
|
|
64
|
+
const sides = (parseFloat(style.paddingLeft) || 0) + (parseFloat(style.paddingRight) || 0);
|
|
65
|
+
const names = buttons.reduce((sum, button) => sum + button.offsetWidth, 0) + between * (buttons.length - 1);
|
|
66
|
+
return names + sides + 2 <= field.clientWidth;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function sync() {
|
|
70
|
+
const busy = root.dataset.busy === 'true';
|
|
71
|
+
buttons.forEach((button) => {
|
|
72
|
+
button.setAttribute('aria-checked', String(button.dataset.mode === root.dataset.item));
|
|
73
|
+
button.disabled = busy;
|
|
74
|
+
});
|
|
75
|
+
const shape = root.dataset.compose;
|
|
76
|
+
const next = (shape === 'place' || shape === 'centre') && !fits() ? 'menu' : 'row';
|
|
77
|
+
if (root.dataset.modes !== next) root.dataset.modes = next;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
new MutationObserver(sync).observe(root, {
|
|
81
|
+
attributes: true,
|
|
82
|
+
attributeFilter: ['data-item', 'data-busy', 'data-compose'],
|
|
83
|
+
});
|
|
84
|
+
window.addEventListener('resize', sync);
|
|
85
|
+
sync();
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// after the compose view, which makes the box
|
|
90
|
+
let installed = false;
|
|
91
|
+
const tryInstall = () => {
|
|
92
|
+
if (!installed) installed = install() === true;
|
|
93
|
+
};
|
|
94
|
+
bar.ready.then(tryInstall);
|
|
95
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', tryInstall);
|
|
96
|
+
window.addEventListener('load', tryInstall);
|
|
97
|
+
})(window, document);
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
// and shows the agent's own page (the page Pinokio opened before) in the
|
|
7
7
|
// window. Download is not an agent session and still leaves the page.
|
|
8
8
|
// - "N running" in that bar: every running agent session, in workspaces and in
|
|
9
|
-
// apps, and shells opened inside an app
|
|
10
|
-
// listed. Grouped by where it runs. Each row can
|
|
9
|
+
// apps, and shells opened inside an app or in Pinokio's own folder. An app's
|
|
10
|
+
// own running scripts are not listed. Grouped by where it runs. Each row can
|
|
11
|
+
// be opened or stopped.
|
|
12
|
+
// - A shell picked on home (home-shell.js) is handed to PinokioAgentBar.openShell
|
|
13
|
+
// and opens in the window like any other session.
|
|
11
14
|
// - App pages: the app's own bar (agent-bar-app.js) opens its sessions through
|
|
12
15
|
// window.PinokioAgentDock, which this file provides there. Its "N running" is
|
|
13
16
|
// the same count and the same list, with the app's own sessions first.
|
|
@@ -195,10 +198,16 @@
|
|
|
195
198
|
return `${tail}|${cleanPath(cwd)}|${session || ''}`;
|
|
196
199
|
}
|
|
197
200
|
|
|
201
|
+
// Pinokio's own folder, which the server puts on this script's tag
|
|
202
|
+
const homeTag = document.querySelector('script[data-agent-bar-panel]');
|
|
203
|
+
const homeDir = cleanPath(homeTag && homeTag.dataset.pinokioHome);
|
|
204
|
+
|
|
198
205
|
// Where a folder is: a Pinokio workspace, an app (PINOKIO_HOME/api/<folder>),
|
|
199
|
-
// a plugin, or some other folder (shown like a
|
|
206
|
+
// a plugin, Pinokio's own folder, or some other folder (shown like a
|
|
207
|
+
// workspace, by its name).
|
|
200
208
|
function placeOf(rawPath) {
|
|
201
209
|
const path = cleanPath(rawPath);
|
|
210
|
+
if (homeDir && path === homeDir) return { placeKind: 'home', placeName: 'Pinokio home', folder: '', rootPath: path };
|
|
202
211
|
const match = path.match(/^(.*?\/(api|workspaces|plugin)\/([^/]+))(?:\/|$)/);
|
|
203
212
|
// the brain: the one folder every Ask from the home bar runs in
|
|
204
213
|
if (!match && /\/brain$/.test(path)) return { placeKind: 'ask', placeName: 'Ask', folder: '', rootPath: path };
|
|
@@ -257,11 +266,12 @@
|
|
|
257
266
|
}, place));
|
|
258
267
|
return;
|
|
259
268
|
}
|
|
260
|
-
// A shell the user opened inside an app
|
|
261
|
-
// running scripts) was not started from a bar
|
|
269
|
+
// A shell the user opened inside an app or in Pinokio's own folder.
|
|
270
|
+
// Anything else (an app's own running scripts) was not started from a bar
|
|
271
|
+
// and is not listed.
|
|
262
272
|
if (!id.startsWith('shell/')) return;
|
|
263
273
|
const place = placeOf(shell.path);
|
|
264
|
-
if (place.placeKind !== 'app') return;
|
|
274
|
+
if (place.placeKind !== 'app' && place.placeKind !== 'home') return;
|
|
265
275
|
if (seen.has(id)) return;
|
|
266
276
|
seen.add(id);
|
|
267
277
|
const idQuery = id.indexOf('?');
|
|
@@ -278,7 +288,7 @@
|
|
|
278
288
|
shellSession,
|
|
279
289
|
url: '',
|
|
280
290
|
fullUrl: '',
|
|
281
|
-
appHref: `/p/${encodeURIComponent(place.folder)}
|
|
291
|
+
appHref: place.placeKind === 'app' ? `/p/${encodeURIComponent(place.folder)}` : '',
|
|
282
292
|
}, place));
|
|
283
293
|
});
|
|
284
294
|
found.sort((a, b) => Number(b.start || 0) - Number(a.start || 0));
|
|
@@ -605,7 +615,9 @@
|
|
|
605
615
|
moreRow('Open in a new tab', 'fa-solid fa-arrow-up-right-from-square', () => {
|
|
606
616
|
const session = win.session;
|
|
607
617
|
const url = session && (session.tabUrl || session.fullUrl || session.url);
|
|
608
|
-
|
|
618
|
+
// opened inside a top-level Pinokio window, which in the desktop app is what
|
|
619
|
+
// carries the bar the window is dragged by
|
|
620
|
+
if (url) whenRunning(session, () => window.open(`/?page=${encodeURIComponent(url)}`, '_blank', 'noopener'));
|
|
609
621
|
});
|
|
610
622
|
// the session page's own appearance button, pressed from here (see embed below). Its
|
|
611
623
|
// "sync size" button has no row: Refresh reloads the page, which sends the size too.
|
|
@@ -1268,7 +1280,9 @@
|
|
|
1268
1280
|
}
|
|
1269
1281
|
// The session an address belongs to: the running one, as the list has it, or
|
|
1270
1282
|
// one made up from the address (a session that is only being started now).
|
|
1271
|
-
|
|
1283
|
+
// `folder` is where a shell that is being started runs, when it is not this
|
|
1284
|
+
// page's own app (a shell opened from home).
|
|
1285
|
+
function sessionAt(url, label, folder) {
|
|
1272
1286
|
const sessionId = url.searchParams.get('session') || '';
|
|
1273
1287
|
const address = `${url.pathname}${url.search}`;
|
|
1274
1288
|
if (url.pathname.startsWith('/shell/')) {
|
|
@@ -1280,11 +1294,12 @@
|
|
|
1280
1294
|
}
|
|
1281
1295
|
const running = sessions.find((item) => item.kind === 'shell' && item.shellId === shellId && (item.shellSession || '') === sessionId);
|
|
1282
1296
|
if (running) return Object.assign({}, running, { url: address, tabUrl: address });
|
|
1283
|
-
const place = placeOf(appCwd);
|
|
1297
|
+
const place = placeOf(folder || appCwd);
|
|
1284
1298
|
return Object.assign({
|
|
1285
1299
|
key: shellKey(shellId, sessionId), kind: 'shell', label: label || 'Shell',
|
|
1286
1300
|
iconClass: 'fa-solid fa-terminal', start: Date.now(), shellId, shellSession: sessionId,
|
|
1287
|
-
url: address, fullUrl: '', tabUrl: address,
|
|
1301
|
+
url: address, fullUrl: '', tabUrl: address,
|
|
1302
|
+
appHref: place.placeKind === 'app' ? `/p/${encodeURIComponent(place.folder)}` : '',
|
|
1288
1303
|
}, place);
|
|
1289
1304
|
}
|
|
1290
1305
|
const tail = H.pluginTail(url.pathname);
|
|
@@ -1306,7 +1321,7 @@
|
|
|
1306
1321
|
const settings = options || {};
|
|
1307
1322
|
const prompt = typeof settings.prompt === 'string' ? settings.prompt.trim() : '';
|
|
1308
1323
|
const url = launchAddress(rawUrl, prompt);
|
|
1309
|
-
const session = url ? sessionAt(url, settings.label) : null;
|
|
1324
|
+
const session = url ? sessionAt(url, settings.label, settings.folder) : null;
|
|
1310
1325
|
if (!session) return false;
|
|
1311
1326
|
const address = `${url.pathname}${url.search}`;
|
|
1312
1327
|
// What the session is listed by is the user's words (`said`), not the line
|
|
@@ -1325,6 +1340,16 @@
|
|
|
1325
1340
|
}
|
|
1326
1341
|
return true;
|
|
1327
1342
|
}
|
|
1343
|
+
// Pages with the main sidebar: a new shell in `folder` (an app's folder, or
|
|
1344
|
+
// Pinokio's own), with a session of its own. False when there is no docked
|
|
1345
|
+
// window to show it in; the caller then opens the shell's own page.
|
|
1346
|
+
function openShellIn(shell, folder) {
|
|
1347
|
+
if (!shell || typeof shell.href !== 'string' || !folder) return false;
|
|
1348
|
+
if (!document.querySelector('.agent-bar__top')) return false;
|
|
1349
|
+
let href = shell.href;
|
|
1350
|
+
if (!href.includes('session=')) href += `${href.includes('?') ? '&' : '?'}session=${encodeURIComponent(H.newSession())}`;
|
|
1351
|
+
return openFromUrl(href, { launch: true, label: shell.label, folder });
|
|
1352
|
+
}
|
|
1328
1353
|
function offerDock() {
|
|
1329
1354
|
const drawer = document.getElementById('ask-ai-drawer');
|
|
1330
1355
|
appCwd = drawer ? (drawer.dataset.workspaceCwd || '') : '';
|
|
@@ -1943,7 +1968,10 @@
|
|
|
1943
1968
|
}
|
|
1944
1969
|
H = bar.helpers;
|
|
1945
1970
|
if (APP) offerDock();
|
|
1946
|
-
else
|
|
1971
|
+
else {
|
|
1972
|
+
bar.deliver = deliver;
|
|
1973
|
+
bar.openShell = openShellIn;
|
|
1974
|
+
}
|
|
1947
1975
|
document.addEventListener('pointerdown', (event) => {
|
|
1948
1976
|
wins.forEach((win) => {
|
|
1949
1977
|
const part = win.part;
|
|
@@ -842,20 +842,22 @@ body.dark.is-home form.home-search-form input[type="search"]:focus {
|
|
|
842
842
|
background: rgba(255, 255, 255, 0.055);
|
|
843
843
|
}
|
|
844
844
|
|
|
845
|
-
/* the
|
|
846
|
-
|
|
845
|
+
/* the row's boxed buttons (Stop, a status) stay crisp on the highlight instead
|
|
846
|
+
of sinking into it; the icon-only ones (star, actions, share, shell) have
|
|
847
|
+
no box, here or anywhere */
|
|
848
|
+
body.is-home .home-app-line:hover .menu-btns > .btn:not(.home-icon-btn):not(.open-actions-modal) {
|
|
847
849
|
border-color: rgba(15, 23, 42, 0.12) !important;
|
|
848
850
|
background: #ffffff !important;
|
|
849
851
|
}
|
|
850
|
-
body.dark.is-home .home-app-line:hover .menu-btns > .btn {
|
|
852
|
+
body.dark.is-home .home-app-line:hover .menu-btns > .btn:not(.home-icon-btn):not(.open-actions-modal) {
|
|
851
853
|
border-color: rgba(255, 255, 255, 0.12) !important;
|
|
852
854
|
background: rgba(255, 255, 255, 0.08) !important;
|
|
853
855
|
}
|
|
854
|
-
body.is-home .home-app-line:hover .menu-btns > .btn:hover {
|
|
856
|
+
body.is-home .home-app-line:hover .menu-btns > .btn:not(.home-icon-btn):not(.open-actions-modal):hover {
|
|
855
857
|
border-color: rgba(15, 23, 42, 0.22) !important;
|
|
856
858
|
background: #ffffff !important;
|
|
857
859
|
}
|
|
858
|
-
body.dark.is-home .home-app-line:hover .menu-btns > .btn:hover {
|
|
860
|
+
body.dark.is-home .home-app-line:hover .menu-btns > .btn:not(.home-icon-btn):not(.open-actions-modal):hover {
|
|
859
861
|
border-color: rgba(255, 255, 255, 0.22) !important;
|
|
860
862
|
background: rgba(255, 255, 255, 0.13) !important;
|
|
861
863
|
}
|
|
@@ -123,6 +123,11 @@
|
|
|
123
123
|
// and resolves to where each one is; `clear` drops them once a send has
|
|
124
124
|
// been handed over.
|
|
125
125
|
attachments: { token: async () => '', paths: async () => [], clear: () => {} },
|
|
126
|
+
// An Ask pointed at one app (see agent-bar-about.js, which replaces these):
|
|
127
|
+
// `app` is that app ({ id, name }) or null; `prepare` readies its Ask and
|
|
128
|
+
// resolves to what the bar's own request resolves to; `clear` points the
|
|
129
|
+
// bar back at nothing once a send has been handed over.
|
|
130
|
+
about: { app: () => null, prepare: null, clear: () => {} },
|
|
126
131
|
// shared with agent-bar-app.js (function declarations below are hoisted)
|
|
127
132
|
helpers: {
|
|
128
133
|
el, faIcon, menuRow, toolIcon, mapPluginMenuToTools, getStoredTool, setStoredTool,
|
|
@@ -786,6 +791,12 @@
|
|
|
786
791
|
const isDownload = () => state.item === 'download';
|
|
787
792
|
const activeName = () => (isDownload() ? downloadName : (isCreate() ? createName : null));
|
|
788
793
|
const selectedTool = () => state.tools.find((tool) => tool.value === state.tool) || null;
|
|
794
|
+
// the app an Ask is pointed at, if any (only Ask can be)
|
|
795
|
+
const aboutApp = () => (state.item === 'ask' ? api.about.app() : null);
|
|
796
|
+
const hintNow = () => {
|
|
797
|
+
const about = aboutApp();
|
|
798
|
+
return about ? `Ask Pinokio about ${about.name}…` : ITEMS[state.item].placeholder;
|
|
799
|
+
};
|
|
789
800
|
const promptText = () => (state.item === 'create_plugin' && input.value.startsWith(PLUGIN_PROMPT_SEED)
|
|
790
801
|
? input.value.slice(PLUGIN_PROMPT_SEED.length)
|
|
791
802
|
: input.value);
|
|
@@ -918,11 +929,13 @@
|
|
|
918
929
|
root.dataset.item = state.item;
|
|
919
930
|
root.dataset.busy = String(state.busy);
|
|
920
931
|
root.dataset.engaged = String(state.engaged);
|
|
921
|
-
|
|
932
|
+
const about = aboutApp();
|
|
933
|
+
root.dataset.about = about ? about.id : '';
|
|
934
|
+
scopeLabel.textContent = about ? `${item.label} · ${about.name}` : item.label;
|
|
922
935
|
scope.disabled = state.busy;
|
|
923
936
|
scope.classList.toggle('is-open', state.menu === 'mode');
|
|
924
937
|
scope.setAttribute('aria-expanded', String(state.menu === 'mode'));
|
|
925
|
-
input.placeholder =
|
|
938
|
+
input.placeholder = hintNow();
|
|
926
939
|
input.disabled = state.busy;
|
|
927
940
|
input.setAttribute('aria-label', download ? 'Git URL' : 'Message for the agent');
|
|
928
941
|
// the agent: one small icon in the field. Download does not use one.
|
|
@@ -985,7 +998,17 @@
|
|
|
985
998
|
// what the empty text says at rest
|
|
986
999
|
api.leave = leave;
|
|
987
1000
|
api.tool = selectedTool;
|
|
988
|
-
api.hint =
|
|
1001
|
+
api.hint = hintNow;
|
|
1002
|
+
// what the open view's face says, when it is not the mode's own line
|
|
1003
|
+
api.greeting = () => {
|
|
1004
|
+
const about = aboutApp();
|
|
1005
|
+
return about ? `Ask Pinokio about ${about.name}` : '';
|
|
1006
|
+
};
|
|
1007
|
+
// draw the bar again (what an Ask is pointed at changed)
|
|
1008
|
+
api.refresh = () => render();
|
|
1009
|
+
// the modes and choosing one, for the row that names them all (agent-bar-modes.js)
|
|
1010
|
+
api.modes = () => Object.keys(ITEMS).map((key) => ({ key, label: ITEMS[key].label }));
|
|
1011
|
+
api.choose = (key) => { setItem(key); focusInputAtEnd(); };
|
|
989
1012
|
|
|
990
1013
|
function toggleMenu(which) {
|
|
991
1014
|
if (state.busy) return;
|
|
@@ -1118,6 +1141,7 @@
|
|
|
1118
1141
|
setInputValue('');
|
|
1119
1142
|
createName.setValue('');
|
|
1120
1143
|
api.attachments.clear();
|
|
1144
|
+
api.about.clear();
|
|
1121
1145
|
setMsg('');
|
|
1122
1146
|
if (document.activeElement && root.contains(document.activeElement)) document.activeElement.blur();
|
|
1123
1147
|
render();
|
|
@@ -1129,12 +1153,16 @@
|
|
|
1129
1153
|
if (!tool) return;
|
|
1130
1154
|
setBusy(true);
|
|
1131
1155
|
try {
|
|
1132
|
-
//
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1156
|
+
// An Ask from this bar runs in the one shared brain folder
|
|
1157
|
+
// (server/lib/brain.js); one pointed at an app runs in that app's folder.
|
|
1158
|
+
const about = aboutApp();
|
|
1159
|
+
const { response, payload } = about && api.about.prepare
|
|
1160
|
+
? await api.about.prepare(about, input.value.trim(), tool)
|
|
1161
|
+
: await postJson('/brain/ask', {
|
|
1162
|
+
prompt: input.value.trim(),
|
|
1163
|
+
tool: tool.value,
|
|
1164
|
+
uploadToken: await api.attachments.token(),
|
|
1165
|
+
});
|
|
1138
1166
|
if (!response.ok || !payload || !payload.ok || !payload.url) {
|
|
1139
1167
|
throw new Error(payload && payload.error ? payload.error : 'Failed to prepare launcher.');
|
|
1140
1168
|
}
|
|
@@ -9,16 +9,6 @@
|
|
|
9
9
|
const script = document.currentScript
|
|
10
10
|
const tab = script && script.dataset ? script.dataset.tab : ''
|
|
11
11
|
|
|
12
|
-
try {
|
|
13
|
-
const url = new URL(window.location.href)
|
|
14
|
-
const had = url.searchParams.has('pinokio_tab') || url.searchParams.has('git_publish')
|
|
15
|
-
url.searchParams.delete('pinokio_tab')
|
|
16
|
-
url.searchParams.delete('git_publish')
|
|
17
|
-
if (had) {
|
|
18
|
-
window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`)
|
|
19
|
-
}
|
|
20
|
-
} catch (_) {}
|
|
21
|
-
|
|
22
12
|
const link = tab === 'files' || tab === 'git' ? document.querySelector(`#${tab}-tab.frame-link`) : null
|
|
23
13
|
if (link && typeof renderSelection === 'function') {
|
|
24
14
|
renderSelection({ target: link, force: true })
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// The File Explorer button on the Files page (server/views/file_browser.ejs).
|
|
2
2
|
//
|
|
3
|
-
// Opens a folder in the system's file explorer
|
|
4
|
-
// in the file list
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// nothing -> the app's own folder
|
|
3
|
+
// Opens a folder in the system's file explorer:
|
|
4
|
+
// a folder was clicked in the file list -> that folder
|
|
5
|
+
// otherwise -> the folder of the file being edited
|
|
6
|
+
// nothing is open -> the app's own folder
|
|
8
7
|
//
|
|
9
8
|
// The file list itself only highlights the open file; clicking a folder just
|
|
10
|
-
// expands it. So this
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// expands it. So this highlights the clicked folder too, to show which folder
|
|
10
|
+
// the button will open, and the button's tooltip names it. Opening or switching
|
|
11
|
+
// to a file afterwards takes over again.
|
|
13
12
|
(() => {
|
|
14
13
|
const button = document.getElementById('files-app-open-explorer')
|
|
15
14
|
const tree = document.getElementById('files-app-tree')
|
|
@@ -17,59 +16,77 @@
|
|
|
17
16
|
return
|
|
18
17
|
}
|
|
19
18
|
const root = button.dataset.root || ''
|
|
20
|
-
|
|
21
|
-
let
|
|
19
|
+
const editedFile = () => (window.FilesApp && window.FilesApp.state && window.FilesApp.state.activePath) || ''
|
|
20
|
+
let clicked = null // the clicked folder: { path, row, edited: the file being edited at that moment }
|
|
22
21
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const forget = () => {
|
|
23
|
+
if (clicked && clicked.row.isConnected) {
|
|
24
|
+
clicked.row.dataset.selected = 'false'
|
|
25
|
+
}
|
|
26
|
+
clicked = null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// the folder to open, relative to the app's folder; '' is the app's folder
|
|
30
|
+
const target = () => {
|
|
31
|
+
if (clicked && !clicked.row.isConnected) {
|
|
32
|
+
// the list was redrawn: the folder is still the target if it is still listed
|
|
33
|
+
const row = Array.from(tree.querySelectorAll('.files-app__tree-row'))
|
|
34
|
+
.find((item) => item.dataset.type === 'directory' && item.dataset.path === clicked.row.dataset.path)
|
|
35
|
+
if (row) {
|
|
36
|
+
row.dataset.selected = 'true'
|
|
37
|
+
clicked.row = row
|
|
38
|
+
} else {
|
|
39
|
+
clicked = null
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (clicked && clicked.edited !== editedFile()) {
|
|
43
|
+
forget()
|
|
44
|
+
}
|
|
45
|
+
if (clicked) {
|
|
46
|
+
return clicked.path
|
|
47
|
+
}
|
|
48
|
+
return editedFile().split('/').filter(Boolean).slice(0, -1).join('/')
|
|
27
49
|
}
|
|
28
50
|
|
|
29
51
|
tree.addEventListener('click', (event) => {
|
|
30
52
|
const row = event.target.closest('.files-app__tree-row')
|
|
31
|
-
if (!row || !tree.contains(row)) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
53
|
// the row's own buttons (open, rename, delete, more) are not a selection
|
|
35
|
-
if (event.target.closest('.files-app__tree-actions, .files-app__tree-more')) {
|
|
54
|
+
if (!row || event.target.closest('.files-app__tree-actions, .files-app__tree-more')) {
|
|
36
55
|
return
|
|
37
56
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (markedRow && markedRow !== row) {
|
|
41
|
-
markedRow.dataset.selected = 'false'
|
|
42
|
-
}
|
|
43
|
-
markedRow = null
|
|
44
|
-
const parts = path.split('/').filter(Boolean)
|
|
45
|
-
if (isFolder) {
|
|
57
|
+
forget()
|
|
58
|
+
if (row.dataset.type === 'directory') {
|
|
46
59
|
row.dataset.selected = 'true'
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
parts.pop()
|
|
60
|
+
clicked = { path: (row.dataset.path || '').split('/').filter(Boolean).join('/'), row, edited: editedFile() }
|
|
50
61
|
}
|
|
51
|
-
target = parts.join('/')
|
|
52
|
-
describe()
|
|
53
62
|
})
|
|
54
63
|
|
|
64
|
+
const describe = () => {
|
|
65
|
+
const label = `Open ${target() || 'the app folder'} in File Explorer`
|
|
66
|
+
button.title = label
|
|
67
|
+
button.setAttribute('aria-label', label)
|
|
68
|
+
}
|
|
69
|
+
button.addEventListener('pointerenter', describe)
|
|
70
|
+
button.addEventListener('focus', describe)
|
|
71
|
+
// switching to another open file takes over from a clicked folder right away
|
|
72
|
+
const tabs = document.getElementById('files-app-tabs')
|
|
73
|
+
if (tabs) {
|
|
74
|
+
tabs.addEventListener('click', () => setTimeout(describe, 0))
|
|
75
|
+
}
|
|
76
|
+
|
|
55
77
|
button.addEventListener('click', () => {
|
|
56
78
|
if (!root) {
|
|
57
79
|
return
|
|
58
80
|
}
|
|
59
|
-
|
|
60
|
-
if (markedRow && !markedRow.isConnected) {
|
|
61
|
-
markedRow = null
|
|
62
|
-
target = ''
|
|
63
|
-
describe()
|
|
64
|
-
}
|
|
81
|
+
const folder = target()
|
|
65
82
|
const separator = root.includes('\\') ? '\\' : '/'
|
|
66
|
-
const folder = target
|
|
67
|
-
? `${root.replace(/[\\/]+$/, '')}${separator}${target.split('/').join(separator)}`
|
|
68
|
-
: root
|
|
69
83
|
fetch('/openfs', {
|
|
70
84
|
method: 'POST',
|
|
71
85
|
headers: { 'Content-Type': 'application/json' },
|
|
72
|
-
body: JSON.stringify({
|
|
86
|
+
body: JSON.stringify({
|
|
87
|
+
path: folder ? `${root.replace(/[\\/]+$/, '')}${separator}${folder.split('/').join(separator)}` : root,
|
|
88
|
+
command: 'open',
|
|
89
|
+
}),
|
|
73
90
|
}).catch(() => {})
|
|
74
91
|
})
|
|
75
92
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* The Files page has no header. Its
|
|
2
|
-
open-file tabs
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* The Files page has no header. Its buttons sit in the bar that holds the
|
|
2
|
+
open-file tabs: at the left, the one that hides or shows the file list (on a
|
|
3
|
+
phone, "back to files" instead); at the right, File Explorer (opens the
|
|
4
|
+
folder selected in the file list) and Save. */
|
|
5
5
|
.files-app__tabbar {
|
|
6
6
|
display: flex;
|
|
7
7
|
align-items: center;
|
|
@@ -23,6 +23,28 @@
|
|
|
23
23
|
}
|
|
24
24
|
.files-app__tabbar .files-app__meta,
|
|
25
25
|
.files-app__tabbar .files-app__save,
|
|
26
|
-
.files-app__tabbar .files-app__mobile-back
|
|
26
|
+
.files-app__tabbar .files-app__mobile-back,
|
|
27
|
+
.files-app__tabbar .files-app__sidebar-toggle {
|
|
27
28
|
flex: 0 0 auto;
|
|
28
29
|
}
|
|
30
|
+
/* On a phone the file list and the editor take turns. The bar stays above the
|
|
31
|
+
file list too, so Save and File Explorer are there in both. */
|
|
32
|
+
.files-app.files-app--mobile[data-mobile-view='list'] .files-app__main {
|
|
33
|
+
display: block;
|
|
34
|
+
flex: 0 0 auto;
|
|
35
|
+
order: -1;
|
|
36
|
+
}
|
|
37
|
+
.files-app.files-app--mobile[data-mobile-view='list'] .files-app__editor,
|
|
38
|
+
.files-app.files-app--mobile[data-mobile-view='list'] .files-app__status {
|
|
39
|
+
display: none;
|
|
40
|
+
}
|
|
41
|
+
/* an ordinary button in the bar, not a tab floating over the edge of the file list */
|
|
42
|
+
.files-app__tabbar .files-app__sidebar-toggle {
|
|
43
|
+
position: static;
|
|
44
|
+
transform: none;
|
|
45
|
+
width: 28px;
|
|
46
|
+
height: 28px;
|
|
47
|
+
border: 1px solid var(--border-color);
|
|
48
|
+
border-radius: 6px;
|
|
49
|
+
box-shadow: none;
|
|
50
|
+
}
|
|
@@ -12,7 +12,6 @@ body.git-page {
|
|
|
12
12
|
--git-danger: #b42318;
|
|
13
13
|
--git-add-bg: #e6ffed;
|
|
14
14
|
--git-del-bg: #ffeef0;
|
|
15
|
-
--git-dirty-bg: rgba(234, 179, 8, 0.18);
|
|
16
15
|
--git-dirty-text: #92600a;
|
|
17
16
|
--git-clean-text: #1c7a43;
|
|
18
17
|
/* the shared stylesheet makes body a flex row, which would shrink the page to its content */
|