@jsb188/ai-chat 1.1.2 → 1.1.13
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/LICENSE +21 -0
- package/README.md +1 -1
- package/package.json +17 -9
- package/src/main.ts +2 -0
- package/src/modules/AgentNoteActionsMenu.tsx +18 -5
- package/src/modules/AgentNoteItem.helpers.ts +9 -17
- package/src/modules/AgentNoteItem.tsx +43 -35
- package/src/modules/AgentNotes.constants.ts +2 -1
- package/src/modules/AgentNotes.helpers.ts +5 -6
- package/src/modules/AgentNotes.hooks.ts +1 -1
- package/src/modules/ChatLinkHandlerContext.ts +4 -0
- package/src/ui/AIChatUI.css +2 -1
- package/src/ui/AIChatUI.tsx +38 -75
- package/src/ui/AgentNotesUI.tsx +6 -4
- package/src/ui/ChatInline.tsx +11 -4
- package/src/utils/parseInline.helpers.ts +1 -27
- package/VERIFICATION.md +0 -118
- package/benchmarks/browser.mjs +0 -204
- package/benchmarks/streaming.mjs +0 -89
- package/tests/AgentNotes.test.tsx +0 -1672
- package/tests/fixtures/content.ts +0 -13
- package/tests/parseContent.test.ts +0 -227
- package/tests/parseCsv.test.ts +0 -82
- package/tests/parseInline.test.ts +0 -222
- package/tests/renderContent.ssr.test.tsx +0 -19
- package/tests/renderContent.test.tsx +0 -282
- package/tests/streaming.test.ts +0 -51
- package/tests/streamingEquivalence.test.ts +0 -265
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -18
package/benchmarks/browser.mjs
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { createServer } from 'node:http';
|
|
5
|
-
import { extname, resolve, sep } from 'node:path';
|
|
6
|
-
import { chromium } from 'playwright';
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Serve a prebuilt synthetic preview on an approved local development port.
|
|
10
|
-
*/
|
|
11
|
-
async function serve(directory) {
|
|
12
|
-
const root = resolve(directory);
|
|
13
|
-
const server = createServer(async (request, response) => {
|
|
14
|
-
try {
|
|
15
|
-
const path = resolve(root, `.${new URL(request.url, 'http://localhost').pathname}`);
|
|
16
|
-
if (!path.startsWith(`${root}${sep}`)) throw new Error('Invalid fixture path.');
|
|
17
|
-
const body = await readFile(path);
|
|
18
|
-
response.setHeader(
|
|
19
|
-
'Content-Type',
|
|
20
|
-
{ '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css' }[extname(path)] || 'application/octet-stream',
|
|
21
|
-
);
|
|
22
|
-
response.end(body);
|
|
23
|
-
} catch {
|
|
24
|
-
response.writeHead(404).end();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
for (const port of [3010, 3011]) {
|
|
28
|
-
try {
|
|
29
|
-
await new Promise((resolve, reject) => {
|
|
30
|
-
server.once('error', reject);
|
|
31
|
-
server.listen(port, '127.0.0.1', resolve);
|
|
32
|
-
});
|
|
33
|
-
server.removeAllListeners('error');
|
|
34
|
-
return { server, url: `http://127.0.0.1:${port}/tests/fixtures/AIChatContentPreview.html` };
|
|
35
|
-
} catch (error) {
|
|
36
|
-
server.removeAllListeners('error');
|
|
37
|
-
if (error.code !== 'EADDRINUSE' || port === 3011) throw error;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/*
|
|
43
|
-
* Read browser CPU counters separately from the React-only profiling duration.
|
|
44
|
-
*/
|
|
45
|
-
async function metrics(session) {
|
|
46
|
-
return Object.fromEntries((await session.send('Performance.getMetrics')).metrics.map(({ name, value }) => [name, value]));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
* Exercise the unchanged table interactions, overflow, themes, and status-only CSV finalization in the real message container.
|
|
51
|
-
*/
|
|
52
|
-
async function verifyInteractions(browser, url, output) {
|
|
53
|
-
const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
|
|
54
|
-
try {
|
|
55
|
-
await page.goto(url);
|
|
56
|
-
for (const width of [320, 420, 780]) {
|
|
57
|
-
await page.getByRole('button', { name: `${width}px`, exact: true }).click();
|
|
58
|
-
await page.getByRole('button', { name: 'Measure', exact: true }).click();
|
|
59
|
-
const report = JSON.parse(await page.locator('output').textContent());
|
|
60
|
-
assert.equal(report.pageOverflow, false);
|
|
61
|
-
assert.equal(report.containerOverflow, false);
|
|
62
|
-
}
|
|
63
|
-
await page.setViewportSize({ width: 375, height: 900 });
|
|
64
|
-
await page.getByRole('button', { name: '320px', exact: true }).click();
|
|
65
|
-
await page.getByRole('button', { name: 'Toggle theme', exact: true }).click();
|
|
66
|
-
const scroll = page.locator('[role="table"]').first().locator('..');
|
|
67
|
-
await scroll.focus();
|
|
68
|
-
await page.keyboard.press('ArrowRight');
|
|
69
|
-
await page.waitForFunction(() => document.querySelector('[role="table"]')?.parentElement.scrollLeft > 0);
|
|
70
|
-
await page.waitForTimeout(300);
|
|
71
|
-
await page.getByRole('button', { name: 'Append prose', exact: true }).click();
|
|
72
|
-
await page.getByRole('button', { name: 'Measure', exact: true }).click();
|
|
73
|
-
const appended = JSON.parse(await page.locator('output').textContent());
|
|
74
|
-
assert.equal(appended.sameTable, true);
|
|
75
|
-
assert.equal(appended.scrollRetained, true);
|
|
76
|
-
assert.equal(appended.pageOverflow, false);
|
|
77
|
-
assert.equal(appended.containerOverflow, false);
|
|
78
|
-
await page.locator('[data-theme] > div:last-child').screenshot({ path: `${output}.mobile-dark.png` });
|
|
79
|
-
const downloading = page.waitForEvent('download');
|
|
80
|
-
await page.getByRole('button', { name: 'Download CSV', exact: true }).first().click();
|
|
81
|
-
const download = await downloading;
|
|
82
|
-
const csv = await readFile(await download.path(), 'utf8');
|
|
83
|
-
assert.ok(csv.includes('001') && csv.includes('Coffee beans'));
|
|
84
|
-
await page.getByRole('button', { name: 'csv', exact: true }).click();
|
|
85
|
-
await page.getByRole('button', { name: 'streaming', exact: true }).click();
|
|
86
|
-
assert.equal(await page.locator('[role="table"]').count(), 0);
|
|
87
|
-
await page.getByRole('button', { name: 'interrupted', exact: true }).click();
|
|
88
|
-
assert.equal(await page.locator('[role="table"]').count(), 0);
|
|
89
|
-
await page.getByRole('button', { name: 'complete', exact: true }).click();
|
|
90
|
-
assert.equal(await page.locator('[role="table"]').count(), 1);
|
|
91
|
-
return {
|
|
92
|
-
widths: [320, 420, 780],
|
|
93
|
-
mobileDark: true,
|
|
94
|
-
keyboardScroll: true,
|
|
95
|
-
preservedScroll: true,
|
|
96
|
-
csvStatusTransitions: true,
|
|
97
|
-
csvDownloadHash: createHash('sha256').update(csv).digest('hex'),
|
|
98
|
-
};
|
|
99
|
-
} finally {
|
|
100
|
-
await page.close();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/*
|
|
105
|
-
* Measure a table mount and deterministic stream, retaining DOM hashes for paired output checks.
|
|
106
|
-
*/
|
|
107
|
-
async function measure(browser, url, fixture) {
|
|
108
|
-
const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
|
|
109
|
-
const errors = [];
|
|
110
|
-
page.on('pageerror', (error) => errors.push(error.message));
|
|
111
|
-
try {
|
|
112
|
-
await page.goto(url);
|
|
113
|
-
await page.getByRole('button', { name: 'csv', exact: true }).click();
|
|
114
|
-
await page.getByRole('button', { name: 'streaming', exact: true }).click();
|
|
115
|
-
// Start both builds after the existing 250 ms message-animation warm-up has settled.
|
|
116
|
-
await page.waitForTimeout(300);
|
|
117
|
-
// The open CSV is code, so the next fixture mounts its table rows from scratch.
|
|
118
|
-
await page.getByRole('button', { name: fixture, exact: true }).click();
|
|
119
|
-
await page.getByRole('button', { name: 'Measure', exact: true }).click();
|
|
120
|
-
const mount = JSON.parse(await page.locator('output').textContent());
|
|
121
|
-
const session = await page.context().newCDPSession(page);
|
|
122
|
-
await session.send('Performance.enable');
|
|
123
|
-
const before = await metrics(session);
|
|
124
|
-
await page.evaluate(() => {
|
|
125
|
-
window.benchmarkFrames = [];
|
|
126
|
-
window.benchmarkFrameActive = true;
|
|
127
|
-
let previous;
|
|
128
|
-
/* Record browser frame intervals while the synthetic response streams. */
|
|
129
|
-
function frame(now) {
|
|
130
|
-
if (!window.benchmarkFrameActive) return;
|
|
131
|
-
if (previous !== undefined) window.benchmarkFrames.push(now - previous);
|
|
132
|
-
previous = now;
|
|
133
|
-
requestAnimationFrame(frame);
|
|
134
|
-
}
|
|
135
|
-
requestAnimationFrame(frame);
|
|
136
|
-
});
|
|
137
|
-
await page.getByRole('button', { name: 'Stream fixture', exact: true }).click();
|
|
138
|
-
await page.waitForFunction(() => document.querySelector('[data-theme] > p')?.textContent?.includes('complete'));
|
|
139
|
-
const after = await metrics(session);
|
|
140
|
-
const frames = await page.evaluate(() => {
|
|
141
|
-
window.benchmarkFrameActive = false;
|
|
142
|
-
return window.benchmarkFrames;
|
|
143
|
-
});
|
|
144
|
-
await page.getByRole('button', { name: 'Measure', exact: true }).click();
|
|
145
|
-
const stream = JSON.parse(await page.locator('output').textContent());
|
|
146
|
-
const html = await page.locator('[data-theme] > div:last-child').innerHTML();
|
|
147
|
-
const cpu = Object.fromEntries(
|
|
148
|
-
['ScriptDuration', 'LayoutDuration', 'RecalcStyleDuration', 'TaskDuration'].map((name) => [
|
|
149
|
-
name,
|
|
150
|
-
+(1000 * (after[name] - before[name])).toFixed(2),
|
|
151
|
-
]),
|
|
152
|
-
);
|
|
153
|
-
assert.deepEqual(errors, []);
|
|
154
|
-
assert.equal(stream.pageOverflow, false);
|
|
155
|
-
assert.equal(stream.containerOverflow, false);
|
|
156
|
-
return {
|
|
157
|
-
html,
|
|
158
|
-
fixture,
|
|
159
|
-
mountMs: mount.maxCommitMs,
|
|
160
|
-
streamMs: stream.maxCommitMs,
|
|
161
|
-
nodes: stream.nodes,
|
|
162
|
-
htmlHash: createHash('sha256').update(html).digest('hex'),
|
|
163
|
-
frameMaxMs: +Math.max(...frames).toFixed(2),
|
|
164
|
-
cpu,
|
|
165
|
-
};
|
|
166
|
-
} finally {
|
|
167
|
-
await page.close();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/*
|
|
172
|
-
* Compare fixed builds using one warm-up and five recorded runs; this never calls application APIs.
|
|
173
|
-
*/
|
|
174
|
-
async function main() {
|
|
175
|
-
const [directory, output, samples = '5'] = process.argv.slice(2);
|
|
176
|
-
assert.ok(directory && output, 'Usage: node benchmarks/browser.mjs BUILD_DIRECTORY OUTPUT.json [SAMPLES=5]');
|
|
177
|
-
assert.ok(Number.isInteger(Number(samples)) && Number(samples) > 0, 'SAMPLES must be a positive integer.');
|
|
178
|
-
const { server, url } = await serve(directory);
|
|
179
|
-
let browser;
|
|
180
|
-
try {
|
|
181
|
-
browser = await chromium.launch({ headless: true });
|
|
182
|
-
const interactions = await verifyInteractions(browser, url, output);
|
|
183
|
-
const results = [];
|
|
184
|
-
const snapshots = new Set();
|
|
185
|
-
for (let run = 0; run <= Number(samples); run++) {
|
|
186
|
-
for (const fixture of ['receipt', 'long', 'limit', 'paragraph']) {
|
|
187
|
-
const { html, ...result } = await measure(browser, url, fixture);
|
|
188
|
-
if (!snapshots.has(result.htmlHash)) {
|
|
189
|
-
await writeFile(`${output}.${fixture}.${result.htmlHash}.html`, html);
|
|
190
|
-
snapshots.add(result.htmlHash);
|
|
191
|
-
}
|
|
192
|
-
if (run) results.push({ run, ...result });
|
|
193
|
-
}
|
|
194
|
-
console.log(`Finished ${run ? `sample ${run}/${samples}` : 'warm-up'}`);
|
|
195
|
-
}
|
|
196
|
-
await writeFile(output, `${JSON.stringify({ browser: browser.version(), interactions, results }, null, 2)}\n`);
|
|
197
|
-
console.log(`Saved ${output}`);
|
|
198
|
-
} finally {
|
|
199
|
-
await browser?.close();
|
|
200
|
-
await new Promise((resolve) => server.close(resolve));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
await main();
|
package/benchmarks/streaming.mjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import { cpus } from 'node:os';
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { reconcileContentDocument } from '../src/utils/contentIdentity.ts';
|
|
6
|
-
import { parseContent } from '../src/utils/parseContent.ts';
|
|
7
|
-
import { parseContentIncrementally } from '../src/utils/parseContentIncrementally.ts';
|
|
8
|
-
|
|
9
|
-
const fixtures = {
|
|
10
|
-
receipt: '## Receipt\n\n| Item | Count |\n| --- | --- |\n| Tea | 001 |\n\nDone **today**.',
|
|
11
|
-
long: Array.from(
|
|
12
|
-
{ length: 10 },
|
|
13
|
-
(_, index) =>
|
|
14
|
-
`## Table ${index + 1}\n\n| Name | Description | Code |\n| --- | --- | --- |\n${Array.from({ length: 35 }, (_, row) => `| Item ${row} | A longer synthetic description for wrapping in chat. | 000${row} |`).join('\n')}\n\n`,
|
|
15
|
-
).join(''),
|
|
16
|
-
limit: `| A | B | C | D | E |\n| - | - | - | - | - |\n${Array.from({ length: 500 }, (_, row) => `| ${row} | ${'description '.repeat(24)} | 0001 | **Value** | More text |`).join('\n')}\n`,
|
|
17
|
-
paragraph: 'An unfinished paragraph '.repeat(8000),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* Measure all synchronous parsing and identity reconciliation across fixed-size transport updates.
|
|
22
|
-
*/
|
|
23
|
-
function measure(source, chunkSize, parse) {
|
|
24
|
-
let previous = null;
|
|
25
|
-
const durations = [];
|
|
26
|
-
for (let end = chunkSize; end < source.length + chunkSize; end += chunkSize) {
|
|
27
|
-
const prefix = source.slice(0, end);
|
|
28
|
-
const status = end >= source.length ? 'complete' : 'streaming';
|
|
29
|
-
const start = performance.now();
|
|
30
|
-
previous = reconcileContentDocument(previous, parse(previous, prefix, status));
|
|
31
|
-
durations.push(performance.now() - start);
|
|
32
|
-
}
|
|
33
|
-
const totalMs = durations.reduce((sum, duration) => sum + duration, 0);
|
|
34
|
-
durations.sort((a, b) => a - b);
|
|
35
|
-
assert.deepEqual(previous, parseContent(source));
|
|
36
|
-
return { updates: durations.length, totalMs, p95Ms: durations[Math.ceil(durations.length * 0.95) - 1], maxMs: durations.at(-1) };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/*
|
|
40
|
-
* Summarize repeated samples without treating noisy wall-clock measurements as test assertions.
|
|
41
|
-
*/
|
|
42
|
-
function median(samples, key) {
|
|
43
|
-
return +samples
|
|
44
|
-
.map((sample) => sample[key])
|
|
45
|
-
.sort((a, b) => a - b)
|
|
46
|
-
[Math.floor(samples.length / 2)].toFixed(3);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
* Compare full parsing with incremental rendering using either the current oracle or a saved baseline bundle.
|
|
51
|
-
*/
|
|
52
|
-
async function main() {
|
|
53
|
-
const [output, baselinePath] = process.argv.slice(2);
|
|
54
|
-
assert.ok(output, 'Usage: node benchmarks/streaming.mjs OUTPUT.json [BASELINE_PARSER.mjs]');
|
|
55
|
-
const baseline = baselinePath ? (await import(pathToFileURL(baselinePath).href)).parseContent : parseContent;
|
|
56
|
-
const parsers = { full: (_previous, source, status) => baseline(source, status), incremental: parseContentIncrementally };
|
|
57
|
-
const results = [];
|
|
58
|
-
for (const [fixture, source] of Object.entries(fixtures)) {
|
|
59
|
-
for (const chunkSize of [256, 2048]) {
|
|
60
|
-
const samples = { full: [], incremental: [] };
|
|
61
|
-
for (let run = 0; run < 6; run++) {
|
|
62
|
-
// Alternate order to avoid always warming or cooling the same implementation first.
|
|
63
|
-
for (const name of run % 2 ? ['incremental', 'full'] : ['full', 'incremental']) {
|
|
64
|
-
const result = measure(source, chunkSize, parsers[name]);
|
|
65
|
-
if (run) samples[name].push(result);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (const [parser, values] of Object.entries(samples))
|
|
69
|
-
results.push({
|
|
70
|
-
fixture,
|
|
71
|
-
chars: source.length,
|
|
72
|
-
chunkSize,
|
|
73
|
-
parser,
|
|
74
|
-
updates: values[0].updates,
|
|
75
|
-
totalMs: median(values, 'totalMs'),
|
|
76
|
-
p95Ms: median(values, 'p95Ms'),
|
|
77
|
-
maxMs: median(values, 'maxMs'),
|
|
78
|
-
samples: values,
|
|
79
|
-
});
|
|
80
|
-
console.log(`Measured ${fixture}, ${chunkSize}-character chunks`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
await writeFile(
|
|
84
|
-
output,
|
|
85
|
-
`${JSON.stringify({ node: process.version, cpu: cpus()[0]?.model, baseline: baselinePath || 'current full parser', results }, null, 2)}\n`,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
await main();
|