pinokiod 8.3.35 → 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.
package/package.json
CHANGED
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
// With nothing typed and nothing attached there is no request:
|
|
20
20
|
// the agent just starts in the app's folder, as on the app's page.
|
|
21
21
|
//
|
|
22
|
+
// A plugin's "Open in" on the Plugins page points the bar the same way, with
|
|
23
|
+
// that plugin as the agent (PinokioAgentBar.pointAt).
|
|
24
|
+
//
|
|
22
25
|
// The bar draws itself (agent-bar.js); this file only holds which app it is
|
|
23
26
|
// pointed at and readies the send. On PinokioAgentBar it replaces `about`.
|
|
24
27
|
(function (window, document) {
|
|
@@ -121,6 +124,16 @@
|
|
|
121
124
|
sync();
|
|
122
125
|
}
|
|
123
126
|
|
|
127
|
+
// The Plugins page's "Open in" (plugin-detail.js) points the bar at an app,
|
|
128
|
+
// with that plugin as the agent: the same as a row's button, without the button.
|
|
129
|
+
function point(next, toolValue) {
|
|
130
|
+
if (isBusy()) return;
|
|
131
|
+
bar.useTool(toolValue);
|
|
132
|
+
app = next;
|
|
133
|
+
bar.choose('ask');
|
|
134
|
+
sync();
|
|
135
|
+
}
|
|
136
|
+
|
|
124
137
|
// The user took the app off: an ordinary Ask, the cursor still in the text.
|
|
125
138
|
function unpoint() {
|
|
126
139
|
if (!app || isBusy()) return;
|
|
@@ -179,6 +192,7 @@
|
|
|
179
192
|
root = null;
|
|
180
193
|
return;
|
|
181
194
|
}
|
|
195
|
+
bar.pointAt = point;
|
|
182
196
|
bar.about = {
|
|
183
197
|
app: () => app,
|
|
184
198
|
prepare,
|
|
@@ -1014,6 +1014,15 @@
|
|
|
1014
1014
|
// (This can be the first thing done in the bar, so the agents are read here
|
|
1015
1015
|
// too: going to the text afterwards no longer does it, the bar is already in use.)
|
|
1016
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
|
+
};
|
|
1017
1026
|
|
|
1018
1027
|
function toggleMenu(which) {
|
|
1019
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">
|
|
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
|
|
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">×</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 ? `
|
|
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
|
|
681
|
+
descriptionEl.textContent = "Choose a project to ask about with this plugin.";
|
|
672
682
|
}
|
|
673
683
|
renderList("");
|
|
674
684
|
dropdownEl.style.display = "grid";
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
<div class="plugin-detail-action-card" data-plugin-action-card="open">
|
|
103
103
|
<div class="plugin-detail-action-copy">
|
|
104
104
|
<div class="plugin-detail-action-label">Open in</div>
|
|
105
|
-
<div class="plugin-detail-action-meta">Choose a project and
|
|
105
|
+
<div class="plugin-detail-action-meta">Choose a project and ask about it with this plugin.</div>
|
|
106
106
|
</div>
|
|
107
107
|
<button class="task-button primary" type="button" data-plugin-open>
|
|
108
108
|
<i class="fa-solid fa-bolt" aria-hidden="true"></i>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// "Open in" on a plugin's page (server/public/plugin-detail.js): after a project
|
|
2
|
+
// is picked, the agent bar at the top of the same page opens on Ask about that
|
|
3
|
+
// project, with this plugin as the agent, the way a row's Ask button does on
|
|
4
|
+
// home. The page is not left and nothing starts until the Ask is sent.
|
|
5
|
+
//
|
|
6
|
+
// The real agent-bar.js, agent-bar-compose.js, agent-bar-about.js and
|
|
7
|
+
// plugin-detail.js run here in a page that has only what they look for.
|
|
8
|
+
const assert = require('node:assert/strict')
|
|
9
|
+
const fs = require('node:fs')
|
|
10
|
+
const path = require('node:path')
|
|
11
|
+
const test = require('node:test')
|
|
12
|
+
const { JSDOM, VirtualConsole } = require('jsdom')
|
|
13
|
+
|
|
14
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
15
|
+
|
|
16
|
+
const PLUGIN = '/pinokio/run/plugin/opencode/pinokio.js'
|
|
17
|
+
const BOOTSTRAP = {
|
|
18
|
+
plugin: { title: 'Opencode', cwd: '', pluginPath: PLUGIN, extraParams: [] },
|
|
19
|
+
share: { manageable: false },
|
|
20
|
+
apps: [{ name: 'demo', title: 'Demo App', cwd: '/home/api/demo', displayPath: '~/api/demo', icon: '/icon.png' }],
|
|
21
|
+
stateUrl: '',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function settle(window) {
|
|
25
|
+
for (let i = 0; i < 8; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function pluginPage(t, { bar = true } = {}) {
|
|
29
|
+
const navigations = []
|
|
30
|
+
const virtualConsole = new VirtualConsole()
|
|
31
|
+
// jsdom cannot leave the page; it says so instead
|
|
32
|
+
virtualConsole.on('jsdomError', (error) => {
|
|
33
|
+
if (/navigation/i.test(String(error && error.message))) navigations.push(error.message)
|
|
34
|
+
})
|
|
35
|
+
const dom = new JSDOM('<!doctype html><body class="main-sidebar-page">'
|
|
36
|
+
+ '<header class="navheader"><h1><div class="flexible"></div></h1></header>'
|
|
37
|
+
+ '<button type="button" data-plugin-open>Open in</button>'
|
|
38
|
+
+ `<script id="plugin-detail-bootstrap" type="application/json">${JSON.stringify(BOOTSTRAP)}</script>`
|
|
39
|
+
+ '</body>', {
|
|
40
|
+
url: 'http://127.0.0.1:42000/plugin?path=%2Fpinokio%2Frun%2Fplugin%2Fopencode%2Fpinokio.js',
|
|
41
|
+
runScripts: 'dangerously',
|
|
42
|
+
pretendToBeVisual: true,
|
|
43
|
+
virtualConsole,
|
|
44
|
+
beforeParse(window) {
|
|
45
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
46
|
+
window.Element.prototype.animate = () => ({ cancel() {}, finished: Promise.resolve(), addEventListener() {} })
|
|
47
|
+
window.requestAnimationFrame = (fn) => window.setTimeout(fn, 0)
|
|
48
|
+
window.fetch = async (url) => {
|
|
49
|
+
const address = String(url)
|
|
50
|
+
if (address.split('?')[0] === '/api/plugin/menu') {
|
|
51
|
+
return {
|
|
52
|
+
ok: true,
|
|
53
|
+
json: async () => ({
|
|
54
|
+
menu: [
|
|
55
|
+
{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true },
|
|
56
|
+
{ href: PLUGIN, title: 'Opencode' },
|
|
57
|
+
],
|
|
58
|
+
projectShell: { items: [] },
|
|
59
|
+
}),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { ok: false, json: async () => ({}) }
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
t.after(() => dom.window.close())
|
|
67
|
+
const { window } = dom
|
|
68
|
+
const { document } = window
|
|
69
|
+
const delivered = []
|
|
70
|
+
if (bar) {
|
|
71
|
+
window.eval(script('agent-bar.js'))
|
|
72
|
+
window.eval(script('agent-bar-compose.js'))
|
|
73
|
+
window.eval(script('agent-bar-about.js'))
|
|
74
|
+
await window.PinokioAgentBar.ready
|
|
75
|
+
window.PinokioAgentBar.deliver = (info) => { delivered.push(info); return true }
|
|
76
|
+
await settle(window)
|
|
77
|
+
}
|
|
78
|
+
window.eval(script('plugin-detail.js'))
|
|
79
|
+
await settle(window)
|
|
80
|
+
const root = document.querySelector('.agent-bar')
|
|
81
|
+
return {
|
|
82
|
+
window,
|
|
83
|
+
document,
|
|
84
|
+
root,
|
|
85
|
+
delivered,
|
|
86
|
+
navigations,
|
|
87
|
+
// Open in, then the project in the list
|
|
88
|
+
async openIn() {
|
|
89
|
+
document.querySelector('[data-plugin-open]').click()
|
|
90
|
+
await settle(window)
|
|
91
|
+
document.querySelector('[data-app-index="0"]').click()
|
|
92
|
+
await settle(window)
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
test('Open in opens the bar on Ask about the picked app, with this plugin as the agent, and stays on the page', async (t) => {
|
|
98
|
+
const p = await pluginPage(t)
|
|
99
|
+
assert.equal(p.window.PinokioAgentBar.tool().value, 'codex', 'the remembered agent before')
|
|
100
|
+
await p.openIn()
|
|
101
|
+
assert.equal(p.root.dataset.item, 'ask')
|
|
102
|
+
assert.equal(p.root.dataset.about, 'demo')
|
|
103
|
+
const chip = p.root.querySelector('.agent-bar__about')
|
|
104
|
+
assert.equal(chip.hidden, false)
|
|
105
|
+
assert.equal(chip.querySelector('.agent-bar__about-name').textContent, 'Demo App')
|
|
106
|
+
assert.equal(chip.querySelector('.agent-bar__about-icon').getAttribute('src'), '/icon.png')
|
|
107
|
+
assert.equal(p.window.PinokioAgentBar.hint(), 'Ask Pinokio about Demo App…')
|
|
108
|
+
// this plugin is the agent, and the one remembered from now on
|
|
109
|
+
assert.equal(p.window.PinokioAgentBar.tool().value, 'pinokio/run/plugin/opencode')
|
|
110
|
+
assert.match(p.root.querySelector('.agent-bar__agent').textContent, /Opencode/)
|
|
111
|
+
assert.equal(p.window.localStorage.getItem('pinokio.universalLauncher.tool'), 'pinokio/run/plugin/opencode')
|
|
112
|
+
// the cursor is in the text; nothing left the page, nothing started
|
|
113
|
+
assert.equal(p.document.activeElement, p.root.querySelector('.agent-bar__input'))
|
|
114
|
+
assert.deepEqual(p.navigations, [])
|
|
115
|
+
assert.equal(p.window.location.pathname, '/plugin')
|
|
116
|
+
assert.deepEqual(p.delivered, [])
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('sending with nothing typed starts this plugin in the app\'s folder, from this page', async (t) => {
|
|
120
|
+
const p = await pluginPage(t)
|
|
121
|
+
await p.openIn()
|
|
122
|
+
p.root.querySelector('.agent-bar__go').click()
|
|
123
|
+
await settle(p.window)
|
|
124
|
+
await settle(p.window)
|
|
125
|
+
assert.equal(p.delivered.length, 1)
|
|
126
|
+
assert.equal(p.delivered[0].cwd, '/home/api/demo')
|
|
127
|
+
const started = new URL(p.delivered[0].url, 'http://x')
|
|
128
|
+
assert.equal(started.pathname, PLUGIN)
|
|
129
|
+
assert.equal(started.searchParams.get('cwd'), '/home/api/demo')
|
|
130
|
+
assert.deepEqual(p.navigations, [])
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('while the bar is sending, Open in changes nothing and does not leave the page', async (t) => {
|
|
134
|
+
const p = await pluginPage(t)
|
|
135
|
+
p.root.dataset.busy = 'true'
|
|
136
|
+
await p.openIn()
|
|
137
|
+
assert.deepEqual(p.navigations, [])
|
|
138
|
+
assert.equal(p.root.dataset.about, '')
|
|
139
|
+
assert.equal(p.window.PinokioAgentBar.tool().value, 'codex')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('a page without the bar still opens the app\'s page, with the plugin in its address', async (t) => {
|
|
143
|
+
const p = await pluginPage(t, { bar: false })
|
|
144
|
+
await p.openIn()
|
|
145
|
+
assert.equal(p.navigations.length, 1)
|
|
146
|
+
})
|