okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0215-asknotify: chat: an agent's question notifies like an approval does (#5617)e9a1215f0

main
2.1 KiB27 linesraw
1// #5617: a question from the agent (ask_user_question) waited for the person with no notification, although an approval, which waits the same
2// way, notifies when "Notify me when Strata needs an answer" is on. The question now gets that notification: the approval's own title, no body.
3import test from 'node:test';
4import assert from 'node:assert/strict';
5import { readFileSync } from 'node:fs';
6import { build } from 'esbuild';
7
8const compiled = await build({ stdin: { contents: "export * from './src/lib/attention'; export * from './src/lib/i18n';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
9const A = await import(`data:text/javascript;base64,${Buffer.from(compiled.outputFiles[0].text).toString('base64')}`);
10const src = name => readFileSync(new URL(`../src/${name}`, import.meta.url), 'utf8').replace(/\r\n/g, '\n');
11
12test('the question notice is the approval notice\'s title with no new sentence, under the same opt-in', async () => {
13  assert.deepEqual(A.questionNotice(), { title: 'Strata needs your answer', body: '' });
14  assert.equal(A.questionNotice().title, A.approvalNotice('x').title);
15  assert.equal(await A.questionAsked(false, false), false, 'off unless the person turned it on');
16  assert.equal(await A.questionAsked(true, true), false, 'the person is looking at Strata');
17});
18
19test('a new question notifies once; the same question again (a reload, a repeat frame) does not', () => {
20  const store = src('lib/store.ts');
21  assert.match(store, /import \{ approvalNeeded, questionAsked, workFinished \} from '\.\/attention';/);
22  const at = store.indexOf('export function addAgentAsk(');
23  const body = store.slice(at, store.indexOf('\n}\n', at));
24  assert.match(body, /if \(ask && loopScheduler\.isRunning\(sessionId\)\) \{[^\n]*return; \}/, 'a /loop question is skipped before anything else');
25  assert.match(body, /const known = \(state\.agentAsks\[sessionId\] \?\? \[\]\)\.some\(a => a\.callId === ask\.callId\);/);
26  assert.match(body, /if \(!known\) void questionAsked\(state\.approvalNotify\);/);
27});