thebird 1.2.21 → 1.2.23
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/CHANGELOG.md +6 -0
- package/docs/index.html +9 -4
- package/docs/terminal.js +52 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -18,3 +18,9 @@
|
|
|
18
18
|
### Added
|
|
19
19
|
- `docs/terminal.js`: WebContainer-powered in-browser terminal with xterm.js, IndexedDB FS persistence, npm install on boot, @anthropic-ai/sdk pre-installed. `window.__debug.container` and `window.__debug.term` live.
|
|
20
20
|
- `docs/index.html`: tabs (Chat / Terminal), coi-serviceworker shim for SharedArrayBuffer on GitHub Pages, xterm CSS.
|
|
21
|
+
|
|
22
|
+
## [Unreleased - 4]
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- `docs/index.html`: Preview tab with iframe (`#preview-frame`), `switchTab` extended to dispatch over `['chat','term','preview']`.
|
|
26
|
+
- `docs/terminal.js`: DEFAULT_FILES now includes `server.js` (HTTP server on port 3000, JSON status endpoint) and updated `index.js` (loads @anthropic-ai/sdk, hits server). Server auto-starts after `npm install`. `container.on('server-ready')` wires iframe src + `window.__debug.previewUrl`. Shell upgraded from `sh` loop to `jsh` with PTY resize. `window.__debug.srv` and `window.__debug.shell` live.
|
package/docs/index.html
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<meta name="version" content="1.2.22">
|
|
6
7
|
<title>thebird — Gemini chat + terminal</title>
|
|
7
8
|
<script src="coi-serviceworker.js"></script>
|
|
8
9
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
<div class="flex border-b border-base-300 bg-base-200 gap-2 px-4 pt-2 shrink-0">
|
|
23
24
|
<button id="tab-chat" class="px-3 py-1 text-sm tab-active" onclick="switchTab('chat')">Chat</button>
|
|
24
25
|
<button id="tab-term" class="px-3 py-1 text-sm" onclick="switchTab('term')">Terminal</button>
|
|
26
|
+
<button id="tab-preview" class="px-3 py-1 text-sm" onclick="switchTab('preview')">Preview</button>
|
|
25
27
|
</div>
|
|
26
28
|
<div id="pane-chat" class="flex-1 overflow-hidden">
|
|
27
29
|
<bird-chat></bird-chat>
|
|
@@ -29,13 +31,16 @@
|
|
|
29
31
|
<div id="pane-term" class="flex-1 overflow-hidden hidden p-2 bg-black">
|
|
30
32
|
<div id="term-container" style="height:100%"></div>
|
|
31
33
|
</div>
|
|
34
|
+
<div id="pane-preview" class="flex-1 overflow-hidden hidden">
|
|
35
|
+
<iframe id="preview-frame" class="w-full h-full border-0" src="about:blank" allow="cross-origin-isolated *"></iframe>
|
|
36
|
+
</div>
|
|
32
37
|
</div>
|
|
33
38
|
<script>
|
|
34
39
|
function switchTab(t) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
['chat', 'term', 'preview'].forEach(id => {
|
|
41
|
+
document.getElementById('pane-' + id).classList.toggle('hidden', id !== t);
|
|
42
|
+
document.getElementById('tab-' + id).classList.toggle('tab-active', id === t);
|
|
43
|
+
});
|
|
39
44
|
}
|
|
40
45
|
</script>
|
|
41
46
|
<script type="module" src="app.js"></script>
|
package/docs/terminal.js
CHANGED
|
@@ -3,9 +3,34 @@ import { Terminal } from 'https://esm.sh/@xterm/xterm';
|
|
|
3
3
|
import { FitAddon } from 'https://esm.sh/@xterm/addon-fit';
|
|
4
4
|
|
|
5
5
|
const IDB_KEY = 'thebird_fs';
|
|
6
|
+
|
|
7
|
+
const SERVER_JS = [
|
|
8
|
+
'const http = require("http");',
|
|
9
|
+
'const state = { requests: 0, start: Date.now() };',
|
|
10
|
+
'http.createServer((req, res) => {',
|
|
11
|
+
' state.requests++;',
|
|
12
|
+
' res.setHeader("Content-Type", "application/json");',
|
|
13
|
+
' res.setHeader("Access-Control-Allow-Origin", "*");',
|
|
14
|
+
' res.end(JSON.stringify({ ok: true, path: req.url, requests: state.requests, uptime: Date.now() - state.start }));',
|
|
15
|
+
'}).listen(3000, () => console.log("server ready on :3000"));',
|
|
16
|
+
].join('\n') + '\n';
|
|
17
|
+
|
|
18
|
+
const INDEX_JS = [
|
|
19
|
+
'const { default: Anthropic } = require("@anthropic-ai/sdk");',
|
|
20
|
+
'const http = require("http");',
|
|
21
|
+
'const client = new Anthropic({ apiKey: "x", baseURL: "http://localhost:3000" });',
|
|
22
|
+
'console.log("sdk:", client.constructor.name);',
|
|
23
|
+
'http.get("http://localhost:3000/status", r => {',
|
|
24
|
+
' let d = "";',
|
|
25
|
+
' r.on("data", c => d += c);',
|
|
26
|
+
' r.on("end", () => console.log("server:", d));',
|
|
27
|
+
'});',
|
|
28
|
+
].join('\n') + '\n';
|
|
29
|
+
|
|
6
30
|
const DEFAULT_FILES = {
|
|
7
31
|
'package.json': JSON.stringify({ name: 'app', dependencies: { '@anthropic-ai/sdk': '^0.88.0' } }, null, 2),
|
|
8
|
-
'
|
|
32
|
+
'server.js': SERVER_JS,
|
|
33
|
+
'index.js': INDEX_JS,
|
|
9
34
|
};
|
|
10
35
|
|
|
11
36
|
async function idbLoad() {
|
|
@@ -65,40 +90,46 @@ async function boot() {
|
|
|
65
90
|
try {
|
|
66
91
|
container = await WebContainer.boot();
|
|
67
92
|
} catch (e) {
|
|
68
|
-
term.write('\x1b[
|
|
93
|
+
term.write('\x1b[31mBoot failed: ' + e.message + '\x1b[0m\r\n');
|
|
69
94
|
throw e;
|
|
70
95
|
}
|
|
71
96
|
await container.mount(mountTree);
|
|
72
|
-
term.write('Installing dependencies...\r\n');
|
|
73
97
|
|
|
98
|
+
container.on('server-ready', (port, url) => {
|
|
99
|
+
const frame = document.getElementById('preview-frame');
|
|
100
|
+
if (frame) frame.src = url;
|
|
101
|
+
window.__debug.previewUrl = url;
|
|
102
|
+
const btn = document.getElementById('tab-preview');
|
|
103
|
+
if (btn) btn.textContent = 'Preview :' + port;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
term.write('Installing dependencies...\r\n');
|
|
74
107
|
const install = await container.spawn('npm', ['install']);
|
|
75
108
|
install.output.pipeTo(new WritableStream({ write: d => term.write(d) }));
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
109
|
+
const exitCode = await install.exit;
|
|
110
|
+
if (exitCode !== 0) throw new Error('npm install failed: ' + exitCode);
|
|
78
111
|
|
|
79
|
-
|
|
112
|
+
const srv = await container.spawn('node', ['server.js']);
|
|
113
|
+
srv.output.pipeTo(new WritableStream({ write: d => term.write(d) }));
|
|
80
114
|
|
|
81
|
-
|
|
82
|
-
shell.output.pipeTo(new WritableStream({ write: d => term.write(d) }));
|
|
115
|
+
term.write('\x1b[32mReady.\x1b[0m\r\n');
|
|
83
116
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (data === '\r') {
|
|
87
|
-
term.write('\r\n');
|
|
88
|
-
await shell.input.write(buf + '\n');
|
|
89
|
-
await snapshotToIDB(container, files);
|
|
90
|
-
buf = '';
|
|
91
|
-
} else if (data === '\x7f') {
|
|
92
|
-
if (buf.length > 0) { buf = buf.slice(0, -1); term.write('\b \b'); }
|
|
93
|
-
} else {
|
|
94
|
-
buf += data;
|
|
95
|
-
term.write(data);
|
|
96
|
-
}
|
|
117
|
+
const shell = await container.spawn('jsh', [], {
|
|
118
|
+
terminal: { cols: term.cols, rows: term.rows },
|
|
97
119
|
});
|
|
120
|
+
shell.output.pipeTo(new WritableStream({ write: d => term.write(d) }));
|
|
121
|
+
term.onResize(({ cols, rows }) => shell.resize({ cols, rows }));
|
|
122
|
+
const writer = shell.input.getWriter();
|
|
123
|
+
term.onData(data => writer.write(data));
|
|
124
|
+
|
|
125
|
+
await snapshotToIDB(container, files);
|
|
98
126
|
|
|
99
127
|
window.__debug = window.__debug || {};
|
|
100
128
|
window.__debug.container = container;
|
|
101
129
|
window.__debug.term = term;
|
|
130
|
+
window.__debug.previewUrl = null;
|
|
131
|
+
window.__debug.shell = shell;
|
|
132
|
+
window.__debug.srv = srv;
|
|
102
133
|
}
|
|
103
134
|
|
|
104
135
|
boot().catch(e => console.error('[terminal] boot error:', e));
|
package/package.json
CHANGED