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,238 @@
|
|
|
1
|
+
// An Ask pointed at one app, from home (server/public/agent-bar-about.js): the
|
|
2
|
+
// button on each row of My Apps points the bar at the top of the page at that
|
|
3
|
+
// app, and a send then starts the agent in the app's folder, without opening
|
|
4
|
+
// the app's page.
|
|
5
|
+
//
|
|
6
|
+
// The real agent-bar.js, agent-bar-compose.js and agent-bar-about.js run here
|
|
7
|
+
// in a page that has only what they look for. Layout is not covered.
|
|
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 ejs = require('ejs')
|
|
13
|
+
const { JSDOM } = require('jsdom')
|
|
14
|
+
|
|
15
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
16
|
+
const BUTTON = path.resolve(__dirname, '../server/views/partials/home_ask_button.ejs')
|
|
17
|
+
const button = (data) => ejs.renderFile(BUTTON, data)
|
|
18
|
+
|
|
19
|
+
async function settle(window) {
|
|
20
|
+
for (let i = 0; i < 8; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test('the row button carries the app\'s folder name, path, name and icon', async () => {
|
|
24
|
+
const html = await button({ folder: '/home/api/demo.git', name: 'Demo "App"', icon: '/asset/api/demo.git/icon.png' })
|
|
25
|
+
const node = new JSDOM(html).window.document.querySelector('button.home-ask-button')
|
|
26
|
+
assert.ok(node)
|
|
27
|
+
assert.equal(node.dataset.askApp, 'demo.git')
|
|
28
|
+
assert.equal(node.dataset.askFolder, '/home/api/demo.git')
|
|
29
|
+
assert.equal(node.dataset.askName, 'Demo "App"')
|
|
30
|
+
assert.equal(node.dataset.askIcon, '/asset/api/demo.git/icon.png')
|
|
31
|
+
assert.equal(node.getAttribute('aria-label'), 'Ask Pinokio about Demo "App"')
|
|
32
|
+
assert.ok(node.classList.contains('home-icon-btn'))
|
|
33
|
+
// a Windows path names the app the same way
|
|
34
|
+
const win = new JSDOM(await button({ folder: 'C:\\pinokio\\api\\demo', name: 'Demo' })).window.document.querySelector('button')
|
|
35
|
+
assert.equal(win.dataset.askApp, 'demo')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('no folder, no button', async () => {
|
|
39
|
+
assert.equal((await button({ folder: undefined, name: 'Demo' })).trim(), '')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
async function home(t, options = {}) {
|
|
43
|
+
const posts = []
|
|
44
|
+
const delivered = []
|
|
45
|
+
const rowClicks = []
|
|
46
|
+
const dom = new JSDOM('<!doctype html><body class="is-home main-sidebar-page">'
|
|
47
|
+
+ '<header class="navheader"><h1><div class="flexible"></div></h1></header>'
|
|
48
|
+
+ '<div class="home-app-line" id="demo" role="link" tabindex="0"><div class="menu-btns">'
|
|
49
|
+
+ await button({ folder: '/home/api/demo', name: 'Demo App', icon: '/icon.png' })
|
|
50
|
+
+ '</div></div>'
|
|
51
|
+
+ '<div class="home-app-line" id="other" role="link" tabindex="0"><div class="menu-btns">'
|
|
52
|
+
+ await button({ folder: '/home/api/other', name: 'Other' })
|
|
53
|
+
+ '</div></div></body>', {
|
|
54
|
+
url: 'http://127.0.0.1:42000/home',
|
|
55
|
+
runScripts: 'outside-only',
|
|
56
|
+
pretendToBeVisual: true,
|
|
57
|
+
beforeParse(window) {
|
|
58
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
59
|
+
window.Element.prototype.animate = () => ({ cancel() {}, finished: Promise.resolve(), addEventListener() {} })
|
|
60
|
+
window.fetch = async (url, init) => {
|
|
61
|
+
const address = String(url)
|
|
62
|
+
if (address.split('?')[0] === '/api/plugin/menu') {
|
|
63
|
+
return { ok: true, json: async () => ({ menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }], projectShell: { items: [] } }) }
|
|
64
|
+
}
|
|
65
|
+
if (address === '/brain/ask') {
|
|
66
|
+
const body = JSON.parse(init.body)
|
|
67
|
+
posts.push(body)
|
|
68
|
+
if (options.refuse) return { ok: false, json: async () => ({ ok: false, error: 'App not found.' }) }
|
|
69
|
+
const cwd = body.app ? `/home/api/${body.app}` : '/home/brain'
|
|
70
|
+
return { ok: true, json: async () => ({ ok: true, id: 's1', cwd, url: `/run/plugin/codex/pinokio.js?cwd=${encodeURIComponent(cwd)}&chrome=full&session=s1&prompt=read` }) }
|
|
71
|
+
}
|
|
72
|
+
return { ok: false, json: async () => ({}) }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
t.after(() => dom.window.close())
|
|
77
|
+
const { window } = dom
|
|
78
|
+
const { document } = window
|
|
79
|
+
document.addEventListener('click', (event) => {
|
|
80
|
+
if (event.target.closest('.home-app-line')) rowClicks.push('click')
|
|
81
|
+
})
|
|
82
|
+
window.eval(script('agent-bar.js'))
|
|
83
|
+
if (options.compose !== false) window.eval(script('agent-bar-compose.js'))
|
|
84
|
+
window.eval(script('agent-bar-about.js'))
|
|
85
|
+
const bar = window.PinokioAgentBar
|
|
86
|
+
await bar.ready
|
|
87
|
+
bar.deliver = (info) => { delivered.push(info); return true }
|
|
88
|
+
bar.attachments.paths = async (appId) => (options.files ? options.files.map((name) => `/home/api/${appId}/.pinokio-temp/uploads/${name}`) : [])
|
|
89
|
+
await settle(window)
|
|
90
|
+
const root = document.querySelector('.agent-bar')
|
|
91
|
+
const input = root.querySelector('.agent-bar__input')
|
|
92
|
+
return {
|
|
93
|
+
window,
|
|
94
|
+
document,
|
|
95
|
+
bar,
|
|
96
|
+
root,
|
|
97
|
+
input,
|
|
98
|
+
posts,
|
|
99
|
+
delivered,
|
|
100
|
+
rowClicks,
|
|
101
|
+
label: () => root.querySelector('.agent-bar__scope-label').textContent,
|
|
102
|
+
chip: () => root.querySelector('.agent-bar__about'),
|
|
103
|
+
settle: () => settle(window),
|
|
104
|
+
async click(node) {
|
|
105
|
+
node.dispatchEvent(new window.MouseEvent('click', { bubbles: true, cancelable: true }))
|
|
106
|
+
await settle(window)
|
|
107
|
+
},
|
|
108
|
+
askButton: (id) => document.querySelector(`#${id} .home-ask-button`),
|
|
109
|
+
async send(text) {
|
|
110
|
+
input.value = text
|
|
111
|
+
root.querySelector('.agent-bar__go').click()
|
|
112
|
+
await settle(window)
|
|
113
|
+
await settle(window)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
test('a click on a row\'s button points the bar at that app and does not open the app', async (t) => {
|
|
119
|
+
const p = await home(t)
|
|
120
|
+
assert.equal(p.root.dataset.about, '')
|
|
121
|
+
assert.equal(p.label(), 'Ask')
|
|
122
|
+
await p.click(p.askButton('demo'))
|
|
123
|
+
assert.equal(p.root.dataset.about, 'demo')
|
|
124
|
+
assert.equal(p.root.dataset.item, 'ask')
|
|
125
|
+
assert.equal(p.label(), 'Ask · Demo App')
|
|
126
|
+
assert.equal(p.bar.hint(), 'Ask Pinokio about Demo App…')
|
|
127
|
+
assert.equal(p.bar.greeting(), 'Ask Pinokio about Demo App')
|
|
128
|
+
// the cursor is in the text
|
|
129
|
+
assert.equal(p.document.activeElement, p.input)
|
|
130
|
+
assert.deepEqual(p.rowClicks, [])
|
|
131
|
+
assert.deepEqual(p.posts, [])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('the open view has a chip with the app\'s name and icon; its x makes it an ordinary Ask', async (t) => {
|
|
135
|
+
const p = await home(t)
|
|
136
|
+
await p.click(p.askButton('demo'))
|
|
137
|
+
const chip = p.chip()
|
|
138
|
+
assert.ok(chip)
|
|
139
|
+
assert.equal(chip.hidden, false)
|
|
140
|
+
assert.equal(chip.querySelector('.agent-bar__about-name').textContent, 'Demo App')
|
|
141
|
+
assert.equal(chip.querySelector('.agent-bar__about-icon').getAttribute('src'), '/icon.png')
|
|
142
|
+
// at the left of the bottom row
|
|
143
|
+
assert.ok(chip.nextSibling.classList.contains('agent-compose__grow'))
|
|
144
|
+
await p.click(chip.querySelector('.agent-bar__about-x'))
|
|
145
|
+
assert.equal(p.root.dataset.about, '')
|
|
146
|
+
assert.equal(p.label(), 'Ask')
|
|
147
|
+
assert.equal(p.bar.hint(), 'Ask Pinokio anything…')
|
|
148
|
+
assert.equal(p.bar.greeting(), '')
|
|
149
|
+
assert.equal(chip.hidden, true)
|
|
150
|
+
assert.equal(p.document.activeElement, p.input)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('another row\'s button points the bar at the other app', async (t) => {
|
|
154
|
+
const p = await home(t)
|
|
155
|
+
await p.click(p.askButton('demo'))
|
|
156
|
+
await p.click(p.askButton('other'))
|
|
157
|
+
assert.equal(p.root.dataset.about, 'other')
|
|
158
|
+
assert.equal(p.label(), 'Ask · Other')
|
|
159
|
+
// no icon: the chip shows the name alone
|
|
160
|
+
assert.equal(p.chip().querySelector('.agent-bar__about-icon').hidden, true)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
test('a send asks about the app, in the app\'s folder, and the bar is an ordinary Ask again', async (t) => {
|
|
164
|
+
const p = await home(t)
|
|
165
|
+
await p.click(p.askButton('demo'))
|
|
166
|
+
await p.send('why does it crash')
|
|
167
|
+
assert.deepEqual(p.posts, [{ app: 'demo', prompt: 'why does it crash', tool: 'codex', files: [] }])
|
|
168
|
+
assert.equal(p.delivered.length, 1)
|
|
169
|
+
assert.equal(p.delivered[0].type, 'ask')
|
|
170
|
+
assert.equal(p.delivered[0].cwd, '/home/api/demo')
|
|
171
|
+
assert.match(p.delivered[0].url, /^\/run\/plugin\/codex\/pinokio\.js\?cwd=%2Fhome%2Fapi%2Fdemo&/)
|
|
172
|
+
assert.equal(p.delivered[0].prompt, 'why does it crash')
|
|
173
|
+
await p.settle()
|
|
174
|
+
assert.equal(p.root.dataset.about, '')
|
|
175
|
+
assert.equal(p.label(), 'Ask')
|
|
176
|
+
assert.equal(p.chip().hidden, true)
|
|
177
|
+
assert.equal(p.input.value, '')
|
|
178
|
+
// the next send is the shared Ask
|
|
179
|
+
await p.send('hello')
|
|
180
|
+
assert.deepEqual(p.posts[1], { prompt: 'hello', tool: 'codex', uploadToken: '' })
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('attached files go to the app and are named in the request', async (t) => {
|
|
184
|
+
const p = await home(t, { files: ['shot.png'] })
|
|
185
|
+
await p.click(p.askButton('demo'))
|
|
186
|
+
await p.send('')
|
|
187
|
+
assert.deepEqual(p.posts, [{ app: 'demo', prompt: '', tool: 'codex', files: ['/home/api/demo/.pinokio-temp/uploads/shot.png'] }])
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
test('with nothing typed the agent just starts in the app\'s folder', async (t) => {
|
|
191
|
+
const p = await home(t)
|
|
192
|
+
await p.click(p.askButton('demo'))
|
|
193
|
+
await p.send('')
|
|
194
|
+
assert.deepEqual(p.posts, [])
|
|
195
|
+
assert.equal(p.delivered.length, 1)
|
|
196
|
+
assert.equal(p.delivered[0].cwd, '/home/api/demo')
|
|
197
|
+
assert.match(p.delivered[0].url, /^\/run\/plugin\/codex\/pinokio\.js\?cwd=%2Fhome%2Fapi%2Fdemo&session=[^&]+$/)
|
|
198
|
+
assert.equal(p.root.dataset.about, '')
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test('a refused send says why and stays pointed at the app', async (t) => {
|
|
202
|
+
const p = await home(t, { refuse: true })
|
|
203
|
+
await p.click(p.askButton('demo'))
|
|
204
|
+
await p.send('hello')
|
|
205
|
+
assert.deepEqual(p.delivered, [])
|
|
206
|
+
assert.match(p.root.querySelector('.agent-bar__note').textContent, /App not found\./)
|
|
207
|
+
assert.equal(p.root.dataset.about, 'demo')
|
|
208
|
+
assert.equal(p.input.value, 'hello')
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
test('another mode drops the app; coming back to Ask is an ordinary Ask', async (t) => {
|
|
212
|
+
const p = await home(t)
|
|
213
|
+
await p.click(p.askButton('demo'))
|
|
214
|
+
p.bar.choose('create_app')
|
|
215
|
+
await p.settle()
|
|
216
|
+
assert.equal(p.root.dataset.about, '')
|
|
217
|
+
assert.equal(p.chip().hidden, true)
|
|
218
|
+
p.bar.choose('ask')
|
|
219
|
+
await p.settle()
|
|
220
|
+
assert.equal(p.root.dataset.about, '')
|
|
221
|
+
assert.equal(p.label(), 'Ask')
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('an ordinary Ask is unchanged', async (t) => {
|
|
225
|
+
const p = await home(t)
|
|
226
|
+
await p.send('hello')
|
|
227
|
+
assert.deepEqual(p.posts, [{ prompt: 'hello', tool: 'codex', uploadToken: '' }])
|
|
228
|
+
assert.equal(p.delivered[0].cwd, '/home/brain')
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('without the compose view the bar still says which app and sends about it', async (t) => {
|
|
232
|
+
const p = await home(t, { compose: false })
|
|
233
|
+
await p.click(p.askButton('demo'))
|
|
234
|
+
assert.equal(p.chip(), null)
|
|
235
|
+
assert.equal(p.label(), 'Ask · Demo App')
|
|
236
|
+
await p.send('hi')
|
|
237
|
+
assert.equal(p.posts[0].app, 'demo')
|
|
238
|
+
})
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// The agent bar's row of modes (server/public/agent-bar-modes.js): in the open
|
|
2
|
+
// view on a desktop every mode is named along the top of the box, the one in use
|
|
3
|
+
// is marked, and a click on another switches to it.
|
|
4
|
+
//
|
|
5
|
+
// The real agent-bar.js, agent-bar-compose.js and agent-bar-modes.js run here in
|
|
6
|
+
// a page that has only a top bar. This page lays nothing out, so widths are
|
|
7
|
+
// given by the test where a case is about room.
|
|
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 } = require('jsdom')
|
|
13
|
+
|
|
14
|
+
const publicDir = path.resolve(__dirname, '../server/public')
|
|
15
|
+
const read = (name) => fs.readFileSync(path.join(publicDir, name), 'utf8')
|
|
16
|
+
const barScript = read('agent-bar.js')
|
|
17
|
+
const appScript = read('agent-bar-app.js')
|
|
18
|
+
const composeScript = read('agent-bar-compose.js')
|
|
19
|
+
const modesScript = read('agent-bar-modes.js')
|
|
20
|
+
|
|
21
|
+
const PHONE = '(max-width: 768px)'
|
|
22
|
+
const HOME_PAGE = '<!doctype html><body><header class="navheader"><h1><div class="flexible"></div></h1></header><main id="page"></main></body>'
|
|
23
|
+
const APP_PAGE = '<!doctype html><body class="app-page"><header class="navheader"><h1>'
|
|
24
|
+
+ '<div class="app-header-identity"><span class="app-header-identity-title">Demo App</span></div>'
|
|
25
|
+
+ '<button id="ask-ai-tab" data-workspace-cwd="/home/api/demo"></button><div class="flexible"></div></h1></header>'
|
|
26
|
+
+ '<div class="appcanvas"><aside id="app-sidebar"><div class="menu-scroller"></div></aside><main id="page"></main>'
|
|
27
|
+
+ '<div class="mobile-bottom-nav"><div class="mobile-bottom-nav__identity"></div></div></div></body>'
|
|
28
|
+
|
|
29
|
+
async function settle(window) {
|
|
30
|
+
for (let i = 0; i < 4; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function page(t, options = {}) {
|
|
34
|
+
const media = new Set(options.media || [])
|
|
35
|
+
const dom = new JSDOM(options.app ? APP_PAGE : HOME_PAGE, {
|
|
36
|
+
url: `http://127.0.0.1:42000/${options.app ? 'p/demo' : 'home'}`,
|
|
37
|
+
runScripts: 'outside-only',
|
|
38
|
+
pretendToBeVisual: true,
|
|
39
|
+
beforeParse(window) {
|
|
40
|
+
window.matchMedia = (query) => ({ matches: media.has(query), addEventListener() {}, removeEventListener() {} })
|
|
41
|
+
window.Element.prototype.getBoundingClientRect = function () {
|
|
42
|
+
return { left: 300, top: 8, right: 900, bottom: 608, width: 600, height: 600, x: 300, y: 8 }
|
|
43
|
+
}
|
|
44
|
+
window.fetch = async (url) => {
|
|
45
|
+
if (String(url) === '/info/shells') return { ok: true, json: async () => [] }
|
|
46
|
+
if (String(url).split('?')[0] === '/api/plugin/menu') {
|
|
47
|
+
return { ok: true, json: async () => ({ menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }] }) }
|
|
48
|
+
}
|
|
49
|
+
if (String(url) === '/pinokio/install/exists') return { ok: true, json: async () => ({ exists: false }) }
|
|
50
|
+
return { ok: false, json: async () => ({ ok: false, error: 'not sent in this test' }) }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
t.after(() => dom.window.close())
|
|
55
|
+
const { window } = dom
|
|
56
|
+
window.eval(barScript)
|
|
57
|
+
if (options.app) window.eval(appScript)
|
|
58
|
+
window.eval(composeScript)
|
|
59
|
+
window.eval(modesScript)
|
|
60
|
+
await window.PinokioAgentBar.ready
|
|
61
|
+
await settle(window)
|
|
62
|
+
const { document } = window
|
|
63
|
+
const root = document.querySelector('.agent-bar')
|
|
64
|
+
const input = root.querySelector('.agent-bar__input')
|
|
65
|
+
const items = () => Array.from(root.querySelectorAll('.agent-bar-modes__item'))
|
|
66
|
+
// nothing is laid out here, so every width reads 0: the box is given one
|
|
67
|
+
const field = root.querySelector('.agent-bar__field')
|
|
68
|
+
const box = { width: 600 }
|
|
69
|
+
Object.defineProperty(field, 'clientWidth', { configurable: true, get: () => box.width })
|
|
70
|
+
return {
|
|
71
|
+
window,
|
|
72
|
+
root,
|
|
73
|
+
input,
|
|
74
|
+
items,
|
|
75
|
+
field,
|
|
76
|
+
box,
|
|
77
|
+
checked: () => items().filter((item) => item.getAttribute('aria-checked') === 'true').map((item) => item.textContent),
|
|
78
|
+
async focus() {
|
|
79
|
+
input.focus()
|
|
80
|
+
await settle(window)
|
|
81
|
+
},
|
|
82
|
+
async click(label) {
|
|
83
|
+
items().find((item) => item.textContent === label).click()
|
|
84
|
+
await settle(window)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
test('the open view names every mode and marks the one in use', async (t) => {
|
|
90
|
+
const p = await page(t)
|
|
91
|
+
await p.focus()
|
|
92
|
+
assert.equal(p.root.dataset.compose, 'place')
|
|
93
|
+
assert.deepEqual(p.items().map((item) => item.textContent), ['Ask', 'Create app', 'Create plugin', 'Download'])
|
|
94
|
+
assert.deepEqual(p.checked(), ['Ask'])
|
|
95
|
+
assert.equal(p.root.dataset.modes, 'row')
|
|
96
|
+
// the row is the first row of the box, before the text
|
|
97
|
+
const row = p.root.querySelector('.agent-bar-modes')
|
|
98
|
+
assert.equal(row.parentNode, p.field)
|
|
99
|
+
assert.ok(row.compareDocumentPosition(p.root.querySelector('.agent-bar__top')) & p.window.Node.DOCUMENT_POSITION_FOLLOWING)
|
|
100
|
+
assert.equal(p.root.querySelector('.agent-compose__controls .agent-bar-modes'), null, 'it is not among the controls')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('a click on another mode switches to it and keeps the cursor in the text', async (t) => {
|
|
104
|
+
const p = await page(t)
|
|
105
|
+
await p.focus()
|
|
106
|
+
await p.click('Create app')
|
|
107
|
+
assert.equal(p.root.dataset.item, 'create_app')
|
|
108
|
+
assert.deepEqual(p.checked(), ['Create app'])
|
|
109
|
+
assert.equal(p.input.placeholder, 'What should this app do?')
|
|
110
|
+
assert.equal(p.root.querySelector('.agent-bar__footer').hidden, false, 'the folder row is shown')
|
|
111
|
+
assert.equal(p.window.document.activeElement, p.input)
|
|
112
|
+
assert.equal(p.root.dataset.compose, 'place', 'the view stays open')
|
|
113
|
+
|
|
114
|
+
await p.click('Download')
|
|
115
|
+
assert.equal(p.root.dataset.item, 'download')
|
|
116
|
+
assert.deepEqual(p.checked(), ['Download'])
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('what was typed is kept when the mode changes', async (t) => {
|
|
120
|
+
const p = await page(t)
|
|
121
|
+
await p.focus()
|
|
122
|
+
p.input.value = 'a draft'
|
|
123
|
+
p.input.dispatchEvent(new p.window.Event('input', { bubbles: true }))
|
|
124
|
+
await settle(p.window)
|
|
125
|
+
await p.click('Create app')
|
|
126
|
+
assert.equal(p.input.value, 'a draft')
|
|
127
|
+
await p.click('Ask')
|
|
128
|
+
assert.equal(p.input.value, 'a draft')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('a mode chosen from the chip\'s menu marks the row too', async (t) => {
|
|
132
|
+
const p = await page(t)
|
|
133
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
134
|
+
await settle(p.window)
|
|
135
|
+
p.root.querySelectorAll('.agent-bar__menu .agent-bar__row')[2].click()
|
|
136
|
+
await settle(p.window)
|
|
137
|
+
assert.deepEqual(p.checked(), ['Create plugin'])
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('send keeps the mode\'s full name', async (t) => {
|
|
141
|
+
const p = await page(t)
|
|
142
|
+
await p.focus()
|
|
143
|
+
await p.click('Create plugin')
|
|
144
|
+
assert.equal(p.root.querySelector('.agent-bar__go-label').textContent, 'Create plugin')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('a press on a name does not take the cursor out of the text', async (t) => {
|
|
148
|
+
const p = await page(t)
|
|
149
|
+
await p.focus()
|
|
150
|
+
const press = new p.window.Event('pointerdown', { bubbles: true, cancelable: true })
|
|
151
|
+
p.items()[1].dispatchEvent(press)
|
|
152
|
+
assert.equal(press.defaultPrevented, true)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('a box too narrow for the four names keeps the chip, whatever the mode', async (t) => {
|
|
156
|
+
const p = await page(t)
|
|
157
|
+
// each name is 80 wide: the four need 320
|
|
158
|
+
Object.defineProperty(p.window.HTMLElement.prototype, 'offsetWidth', {
|
|
159
|
+
configurable: true,
|
|
160
|
+
get() { return this.classList.contains('agent-bar-modes__item') ? 80 : 0 }
|
|
161
|
+
})
|
|
162
|
+
p.box.width = 300
|
|
163
|
+
await p.focus()
|
|
164
|
+
assert.equal(p.root.dataset.modes, 'menu')
|
|
165
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
166
|
+
await settle(p.window)
|
|
167
|
+
p.root.querySelectorAll('.agent-bar__menu .agent-bar__row')[1].click()
|
|
168
|
+
await settle(p.window)
|
|
169
|
+
assert.equal(p.root.dataset.modes, 'menu')
|
|
170
|
+
|
|
171
|
+
// the window is made wider
|
|
172
|
+
p.box.width = 400
|
|
173
|
+
p.window.dispatchEvent(new p.window.Event('resize'))
|
|
174
|
+
await settle(p.window)
|
|
175
|
+
assert.equal(p.root.dataset.modes, 'row')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('a phone keeps the chip and its menu', async (t) => {
|
|
179
|
+
const p = await page(t, { media: [PHONE] })
|
|
180
|
+
await p.focus()
|
|
181
|
+
assert.equal(p.root.dataset.compose, 'screen')
|
|
182
|
+
// the stylesheet shows the row only in the two desktop shapes
|
|
183
|
+
assert.notEqual(p.root.dataset.compose, 'place')
|
|
184
|
+
assert.ok(p.root.querySelector('.agent-bar__scope').closest('.agent-compose__controls'), 'the chip is in the controls row')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('an app page\'s bar, which only asks, has no row', async (t) => {
|
|
188
|
+
const p = await page(t, { app: true })
|
|
189
|
+
assert.equal(p.items().length, 0)
|
|
190
|
+
assert.equal(p.root.classList.contains('agent-bar--modes'), false)
|
|
191
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// "Open in a new tab" in a session window's menu opens a top-level Pinokio
|
|
2
|
+
// window that shows the session's own page. In the desktop app only that
|
|
3
|
+
// top-level page has the strip a window is dragged by.
|
|
4
|
+
const assert = require('node:assert/strict')
|
|
5
|
+
const fs = require('node:fs')
|
|
6
|
+
const path = require('node:path')
|
|
7
|
+
const test = require('node:test')
|
|
8
|
+
const { JSDOM, ResourceLoader } = require('jsdom')
|
|
9
|
+
|
|
10
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
11
|
+
|
|
12
|
+
class TerminalPage extends ResourceLoader {
|
|
13
|
+
fetch() {
|
|
14
|
+
return Promise.resolve(Buffer.from('<!doctype html><div id="terminal"><textarea></textarea></div>'))
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('"Open in a new tab" opens the session\'s page inside a top-level window', { timeout: 3000 }, async (t) => {
|
|
19
|
+
const dom = new JSDOM('<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header></body>', {
|
|
20
|
+
url: 'http://127.0.0.1:42000/home',
|
|
21
|
+
resources: new TerminalPage(),
|
|
22
|
+
runScripts: 'outside-only',
|
|
23
|
+
pretendToBeVisual: true,
|
|
24
|
+
})
|
|
25
|
+
t.after(() => dom.window.close())
|
|
26
|
+
const { window } = dom
|
|
27
|
+
const { document } = window
|
|
28
|
+
window.innerWidth = 1760
|
|
29
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
30
|
+
window.Element.prototype.getBoundingClientRect = () => ({ left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32 })
|
|
31
|
+
window.sessionStorage.setItem('pinokio.agentBar.dock.tabs', JSON.stringify([
|
|
32
|
+
{ key: '/plugin/codex/pinokio.js|/home/brain|s1', kind: 'agent', open: true, z: 1 },
|
|
33
|
+
]))
|
|
34
|
+
window.fetch = async (url) => {
|
|
35
|
+
if (url === '/info/shells') {
|
|
36
|
+
return { ok: true, json: async () => [{ id: 'agent', group: '/home/plugin/codex/pinokio.js?cwd=/home/brain&session=s1' }] }
|
|
37
|
+
}
|
|
38
|
+
return { ok: true, json: async () => ({ menu: [{ href: '/pinokio/run/plugin/codex/pinokio.js', title: 'Codex', default: true }] }) }
|
|
39
|
+
}
|
|
40
|
+
const opened = new Promise((resolve) => { window.open = (...args) => resolve(args) })
|
|
41
|
+
for (const name of ['agent-bar.js', 'agent-bar-panel.js']) window.eval(script(name))
|
|
42
|
+
await window.PinokioAgentBar.ready
|
|
43
|
+
let row = null
|
|
44
|
+
for (let i = 0; i < 50 && !row; i += 1) {
|
|
45
|
+
await new Promise((resolve) => window.setTimeout(resolve, 10))
|
|
46
|
+
row = Array.from(document.querySelectorAll('.agent-dock__more-row')).find((item) => item.textContent === 'Open in a new tab')
|
|
47
|
+
}
|
|
48
|
+
assert.ok(row, 'the session window has the row')
|
|
49
|
+
row.click()
|
|
50
|
+
|
|
51
|
+
const [address, target] = await opened
|
|
52
|
+
assert.equal(target, '_blank')
|
|
53
|
+
const top = new URL(address, window.location.href)
|
|
54
|
+
assert.equal(top.pathname, '/', 'the new window is the top-level page')
|
|
55
|
+
const shown = new URL(top.searchParams.get('page'), window.location.href)
|
|
56
|
+
assert.equal(shown.pathname, '/pinokio/run/plugin/codex/pinokio.js')
|
|
57
|
+
assert.equal(shown.searchParams.get('cwd'), '/home/brain')
|
|
58
|
+
assert.equal(shown.searchParams.get('session'), 's1')
|
|
59
|
+
assert.equal(shown.searchParams.get('chrome'), 'full')
|
|
60
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The app page's Files and Git tabs: which tab a page opens on, where old Dev
|
|
2
|
+
// addresses go, and the Git page's address.
|
|
3
|
+
const assert = require('node:assert/strict')
|
|
4
|
+
const fs = require('node:fs')
|
|
5
|
+
const os = require('node:os')
|
|
6
|
+
const path = require('node:path')
|
|
7
|
+
const test = require('node:test')
|
|
8
|
+
|
|
9
|
+
const AppRunTabs = require('../server/lib/app_run_tabs')
|
|
10
|
+
const registerGitPageRoutes = require('../server/routes/git_page')
|
|
11
|
+
|
|
12
|
+
const tempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'pinokio-tabs-'))
|
|
13
|
+
const launcherMenu = { menu: [{ default: true, text: 'Start', href: 'start.js' }] }
|
|
14
|
+
const htmlOnly = { menu: [{ default: true, text: 'index.html', href: '/asset/api/demo/index.html' }] }
|
|
15
|
+
const listingOnly = { menu: [{ default: true, text: 'Project Files', href: '/files/api/demo' }] }
|
|
16
|
+
|
|
17
|
+
const page = (query) => ({ params: { name: 'demo' }, query })
|
|
18
|
+
|
|
19
|
+
test('a link that asks for a tab is recognised, so the page opens without launching the app', () => {
|
|
20
|
+
assert.equal(AppRunTabs.chosen(page({ pinokio_tab: 'files' })), 'files')
|
|
21
|
+
assert.equal(AppRunTabs.chosen(page({ pinokio_tab: 'git' })), 'git')
|
|
22
|
+
assert.equal(AppRunTabs.chosen(page({ git_publish: '1' })), 'git')
|
|
23
|
+
assert.equal(AppRunTabs.chosen(page({ pinokio_tab: 'other' })), '')
|
|
24
|
+
assert.equal(AppRunTabs.chosen(page({})), '')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('the page opens on the tab that was asked for', () => {
|
|
28
|
+
assert.deepEqual(AppRunTabs.locals(page({ pinokio_tab: 'git' }), 'run', launcherMenu), { run_initial_tab: 'git', git_initial_publish: false })
|
|
29
|
+
assert.deepEqual(AppRunTabs.locals(page({ git_publish: '1' }), 'run', launcherMenu), { run_initial_tab: 'git', git_initial_publish: true })
|
|
30
|
+
assert.deepEqual(AppRunTabs.locals(page({}), 'run', launcherMenu), { run_initial_tab: '', git_initial_publish: false })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('a folder with only an index.html keeps opening on that page', () => {
|
|
34
|
+
assert.equal(AppRunTabs.locals(page({}), 'run', htmlOnly).run_initial_tab, '')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('a folder with nothing of its own to show opens on Files', () => {
|
|
38
|
+
assert.equal(AppRunTabs.locals(page({}), 'run', listingOnly).run_initial_tab, 'files')
|
|
39
|
+
// unless the link came for something else: a plugin to start, Settings from Home, a file to reveal
|
|
40
|
+
for (const query of [{ plugin: '/plugin/x' }, { pinokio_home_select: '{}' }, { reveal: 'a.bin' }]) {
|
|
41
|
+
assert.equal(AppRunTabs.locals(page(query), 'run', listingOnly).run_initial_tab, '')
|
|
42
|
+
}
|
|
43
|
+
// or its launcher chose a page of its own, even one under the same address
|
|
44
|
+
const docs = { menu: [{ default: true, text: 'Docs', href: '/files/api/demo/docs' }] }
|
|
45
|
+
assert.equal(AppRunTabs.locals(page({}), 'run', docs).run_initial_tab, '')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('old Dev addresses go to the app page without launching, on the matching tab', () => {
|
|
49
|
+
const redirect = (query, tab) => {
|
|
50
|
+
let target = ''
|
|
51
|
+
AppRunTabs.redirectDev({ params: { name: 'my app' }, query }, { redirect: (url) => { target = url } }, tab)
|
|
52
|
+
return target
|
|
53
|
+
}
|
|
54
|
+
assert.equal(redirect({}), '/v/my%20app')
|
|
55
|
+
assert.equal(redirect({}, 'files'), '/v/my%20app?pinokio_tab=files')
|
|
56
|
+
assert.equal(redirect({ pinokio_dev_tab: 'files' }), '/v/my%20app?pinokio_tab=files')
|
|
57
|
+
assert.equal(redirect({ 'pinokio.publish': '1' }), '/v/my%20app?git_publish=1')
|
|
58
|
+
assert.equal(redirect({ plugin: '/plugin/x', prompt: 'hi' }), '/v/my%20app?plugin=%2Fplugin%2Fx&prompt=hi')
|
|
59
|
+
assert.equal(redirect({ prompt: ['first', 'second'] }), '/v/my%20app?prompt=first&prompt=second')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('the Git page only opens for a folder directly inside the apps folder', async () => {
|
|
63
|
+
const apiRoot = tempDir()
|
|
64
|
+
fs.mkdirSync(path.join(apiRoot, 'demo'))
|
|
65
|
+
let handler
|
|
66
|
+
registerGitPageRoutes({ get: (route, fn) => { handler = fn } }, {
|
|
67
|
+
kernel: { path: (first, ...rest) => path.join(apiRoot, ...rest) },
|
|
68
|
+
getPageContext: () => ({ theme: 'light' }),
|
|
69
|
+
})
|
|
70
|
+
const open = async (name) => {
|
|
71
|
+
const result = {}
|
|
72
|
+
await handler({ params: { name }, query: {} }, {
|
|
73
|
+
status: (code) => { result.status = code; return { send: () => {} } },
|
|
74
|
+
render: (view, locals) => { result.view = view; result.locals = locals },
|
|
75
|
+
})
|
|
76
|
+
return result
|
|
77
|
+
}
|
|
78
|
+
const ok = await open('demo')
|
|
79
|
+
assert.equal(ok.view, 'git_page')
|
|
80
|
+
assert.equal(ok.locals.cwd, path.join(apiRoot, 'demo'))
|
|
81
|
+
for (const name of ['..', '.', 'missing', 'a/b', 'a\\b']) {
|
|
82
|
+
assert.equal((await open(name)).status, 404, name)
|
|
83
|
+
}
|
|
84
|
+
})
|