create-nisc 0.9.3 → 0.9.4

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +20 -22
  3. package/dist/{chunk-IJ5E5SA2.js → chunk-2W7KLXCO.js} +3 -3
  4. package/dist/{chunk-IJ5E5SA2.js.map → chunk-2W7KLXCO.js.map} +1 -1
  5. package/dist/cli.js +1 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +1 -1
  8. package/templates/base/files/src/ui/kit.css +8 -41
  9. package/templates/dom/files/src/ui/kit.ts +2 -8
  10. package/templates/dom/files/src/ui/registry.ts +2 -2
  11. package/templates/model-first/agents-section.md +31 -25
  12. package/templates/model-first/files/src/app/action-catalog.ts +4 -3
  13. package/templates/model-first/files/src/app/actions/answer/turn.action.ts +23 -0
  14. package/templates/model-first/files/src/app/actions/ask/dock.action.ts +10 -33
  15. package/templates/model-first/files/src/app/actions/ask/dock.layout.ts +7 -39
  16. package/templates/model-first/files/src/app/actions/guide/guide.actions.ts +16 -19
  17. package/templates/model-first/files/src/app/app.ts +4 -3
  18. package/templates/model-first/files/src/app/charter/charter.ts +1 -1
  19. package/templates/model-first/files/src/app/screens.ts +27 -48
  20. package/templates/model-first/files/src/app/shell/frame.layout.ts +5 -1
  21. package/templates/model-first/files/src/app/shell/shell.ts +7 -10
  22. package/templates/model-first/files/src/dev/all-checks.ts +3 -3
  23. package/templates/model-first/files/src/dev/artifacts-check.ts +14 -25
  24. package/templates/model-first/files/src/dev/compose-check.ts +87 -136
  25. package/templates/model-first/files/src/dev/guide-check.ts +41 -58
  26. package/templates/model-first/files/src/dev/live-ask.ts +43 -138
  27. package/templates/model-first/files/src/dev/scripted.ts +24 -102
  28. package/templates/model-first/files/src/dev/shape-check.ts +2 -6
  29. package/templates/model-first/files/src/dev/strata.ts +2 -2
  30. package/templates/model-first/files/src/server/boot.ts +2 -2
  31. package/templates/model-first/files/src/server/compose/catalog.ts +10 -28
  32. package/templates/model-first/files/src/server/compose/composer.agent.ts +13 -11
  33. package/templates/model-first/files/src/server/compose/index.ts +55 -132
  34. package/templates/model-first/files/src/server/compose/knowledge.ts +22 -43
  35. package/templates/model-first/files/src/server/compose/turn.schema.ts +55 -0
  36. package/templates/model-first/files/src/server/models/index.ts +5 -23
  37. package/templates/model-first/item.json +28 -38
  38. package/templates/react/files/src/ui/kit.tsx +14 -25
  39. package/templates/react/files/src/ui/registry.ts +2 -2
  40. package/templates/model-first/files/src/app/arrangements.ts +0 -17
  41. package/templates/model-first/files/src/app/shell/areas.ts +0 -3
  42. package/templates/model-first/files/src/server/compose/answer.ts +0 -145
  43. package/templates/model-first/files/src/server/compose/history.ts +0 -45
  44. package/templates/model-first/files/src/server/compose/layout.ts +0 -70
  45. package/templates/model-first/files/src/server/compose/pick.ts +0 -44
  46. package/templates/model-first/files/src/server/compose/plan.ts +0 -45
  47. package/templates/model-first/files/src/server/compose/reply.schema.ts +0 -70
  48. package/templates/model-first/files/src/server/compose/screen.ts +0 -40
@@ -1,189 +1,140 @@
1
1
  import { renderDocument } from '@niscorp/moss';
2
- import { ARRANGEMENTS } from '../app/arrangements';
2
+ import { placeable } from '../app/action-catalog';
3
3
  import { SCREENS } from '../app/screens';
4
- import { AREAS } from '../app/shell/areas';
5
- import { recordOf } from '../server/compose/record';
6
4
  import { drawing } from '../server/document';
7
5
  import { checks } from './checks';
8
6
  import { scriptedModels, settle, startApp, until } from './scripted';
9
- import type { Script } from './scripted';
7
+ import type { Script, Shown } from './scripted';
10
8
 
11
9
  const [FIRST] = SCREENS;
10
+ const LAST = SCREENS[SCREENS.length - 1] ?? FIRST;
11
+ // One of the app's own cards, if it has any: what the model shows is checked with it.
12
+ const [ONE] = placeable;
12
13
 
13
- const keep = (area: string, from = area) => ({ area, keep: from });
14
- const say = (area: string, title: string, text = `About ${title}.`) => ({ area, say: { title, text } });
15
- const gridOf = (columns: number, ...areas: [string, number][]): unknown => ({ columns, areas: areas.map(([name, span]) => ({ name, span })) });
14
+ const say = (title: string, text = `About ${title}.`) => ({ say: { title, text } });
16
15
 
17
16
  const SCRIPT: Script = {
18
- 'Two things side by side': [{ response: 'Put the two side by side.', title: 'Two things', areas: [say('a', 'One'), say('b', 'Two')], arrangement: 'pair' }],
19
- 'drop the second': [{ title: 'One thing', areas: [{ area: 'b', drop: true }] }],
20
- 'the second again, beside it': [{ title: 'Second again', areas: [keep('a'), say('b', 'Two')] }],
21
- 'swap them': [{ title: 'Swapped', areas: [keep('a', 'b'), keep('b', 'a')] }],
22
- 'other words for the first': [{ title: 'Said again', areas: [say('b', 'One', 'Said again.')] }],
23
- 'keep what is not there': [{ areas: [keep('a', 'f'), say('c', 'Three')] }, { areas: [keep('a')] }],
24
- 'Show me the weather card': [{ areas: [{ area: 'a', action: 'weather.card', input: {}, intent: 'the weather' }] }],
25
- 'Three things, the last wide beneath': [{ title: 'Three things', areas: [say('a', 'One'), say('b', 'Two'), say('c', 'Three')], grid: gridOf(2, ['a', 1], ['b', 1], ['c', 2]) }],
26
- 'Two things, in a grid of my own': [
27
- { areas: [say('a', 'One'), say('b', 'Two'), { area: 'c', drop: true }], grid: gridOf(2, ['a', 1], ['a', 1]) },
28
- { title: 'Two again', areas: [say('a', 'One'), say('b', 'Two'), { area: 'c', drop: true }] },
29
- ],
30
- 'What can you do?': [{ title: 'What it does', areas: [say('a', 'What this app does', 'It answers with screens.')], arrangement: 'single' }],
31
- 'Show the first screen': [{ screen: FIRST.id }],
32
- 'What is the weather in Vienna?': [{ response: 'Nothing in this app shows the weather.', areas: [] }],
33
- 'Name it at length': [{ title: 'A title that runs on well past the forty characters a title may have', areas: [] }],
34
- 'Only one thing': [{ areas: [say('a', 'One')], arrangement: 'single' }],
17
+ 'What can you do?': [{ response: 'I answer with this app’s cards.', cards: [say('What this app does', 'It answers with cards.')] }],
18
+ 'and then?': [{ response: 'Then you ask again.', cards: [] }],
19
+ 'Show me the weather card': [{ cards: [{ action: 'weather.card', input: {} }] }, { response: 'There is no weather here.', cards: [say('No weather')] }],
20
+ 'Words and a card at once': [{ cards: [{ action: 'weather.card', input: {}, say: { title: 'Both', text: 'Both.' } }] }, { cards: [say('One of them')] }],
21
+ 'Never a card that is there': [{ cards: [{ action: 'weather.card', input: {} }] }],
22
+ 'Too many cards': [{ cards: [say('One'), say('Two'), say('Three'), say('Four')] }],
23
+ 'One of your cards': [{ response: 'Here it is.', cards: [{ action: ONE?.id ?? 'answer.text', input: {} }] }],
35
24
  };
36
25
 
37
26
  const { check, finish } = checks('compose');
38
- const START = FIRST.canvases.map((canvas) => canvas.action).join(' ');
39
- const opened = AREAS.slice(0, FIRST.canvases.length);
40
-
27
+ const actionsOf = (shown: Shown[]): string => shown.map((one) => one.action).join(' ');
41
28
  const scripted = scriptedModels(SCRIPT);
42
29
  const { prompts } = scripted;
43
30
  const lastPrompt = (): string => prompts[prompts.length - 1] ?? '';
44
31
  const app = await startApp(scripted.models);
45
- const { on, current, total, grid, areas, ids, without, said, drawn, marked, runs, ask, session } = app;
32
+ const { on, said, runs, ask, session } = app;
46
33
  try {
47
34
  const template = '<!doctype html><html><head></head><body><div id="root"></div></body></html>';
48
35
  const page = await renderDocument({ ...drawing, server: app.server, template, request: { path: '/', cookie: null } });
49
- check('the page arrives drawn: the first screen, and the dock with the screens and the line to ask in', page.drawn && ['k-frame', 'k-dock', 'k-prompt'].every((part) => page.html.includes(part)), page.html.slice(0, 300));
36
+ check('the page arrives drawn: the first screen, and the dock with the line to ask in', page.drawn && ['k-frame', 'k-dock', 'k-prompt'].every((part) => page.html.includes(part)), page.html.slice(0, 300));
50
37
 
51
- check('the app opens on the first screen, every one of its canvases an area of its own, and the stack starts there', areas() === START && on('dock').action === 'ask.dock' && current().position === 1 && total() === 1, areas());
52
- const room = ARRANGEMENTS.find((arrangement) => arrangement.id === FIRST.arrangement)?.areaCount;
53
- check('the frame’s region holds the first screen’s arrangement', current().arrangement === FIRST.arrangement && grid().split(' ').length - 1 === room, `${String(current().arrangement)} — ${grid()}`);
38
+ const START = FIRST.cards.map((card) => card.action).join(' ');
39
+ check('the app opens on the first screen, its cards in order, and the conversation empty', actionsOf(on('screen')) === START && on('talk').length === 0, actionsOf(on('screen')));
40
+ const screenIds = on('screen').map((one) => one.id).join();
54
41
 
55
- runs.length = 0;
56
- scripted.likely([FIRST.id]);
57
- await ask('Two things side by side');
58
- scripted.likely([]);
59
- const jev = scripted.asked[scripted.asked.length - 1];
42
+ await ask('What can you do?');
43
+ const talk = on('talk');
60
44
  check(
61
- 'each message is recorded as two runs: Jev\'s pass and the model\'s, each with its model, what it spent and how it ended',
62
- runs.map((run) => `${run.agentId} ${run.model} ${run.outcome} ${run.steps} ${run.totalTokens} ${run.label}`).join(' | ') === 'nisc-template-app.jev jev ok 1 110 Two things side by side | nisc-template-app.compose chat ok 1 110 Two things side by side',
63
- JSON.stringify(runs),
45
+ 'a message is answered with a turn: what was asked and the sentence, then its cards — words as the words card',
46
+ actionsOf(talk) === 'answer.turn answer.text' && talk[0]?.data['question'] === 'What can you do?' && talk[0]?.data['reply'] === 'I answer with this app’s cards.' && talk[1]?.data['title'] === 'What this app does',
47
+ JSON.stringify(talk.map((one) => one.data)),
64
48
  );
65
- check('Jev is asked about the message with the open screen: an intent for each canvas', jev?.state['message'] === 'Two things side by side' && Object.keys(recordOf(jev?.state['open_screen'])).join() === opened.join(), JSON.stringify(jev?.state['open_screen']));
49
+ check('the screen behind the conversation stays as it was', on('screen').map((one) => one.id).join() === screenIds, actionsOf(on('screen')));
66
50
  check(
67
- 'the model is given the open screen by area — where each area is, what each holds — and what Jev thinks',
68
- prompts[0]?.includes(`arrangement ${FIRST.arrangement}: `) === true && prompts[0].includes(`- a: ${FIRST.canvases[0]?.action ?? ''}`) && prompts[0].includes(`A FAST PICKER THINKS (a hint; how likely each belongs in the answer): actions none; reads none; writes none; screens ${FIRST.id} 0.90`),
69
- prompts[0]?.slice(0, 600) ?? '',
51
+ 'the model is told the cards the person may be shown, and the message, with nothing said before it',
52
+ lastPrompt().includes('CONVERSATION SO FAR\nnothing yet') && lastPrompt().includes('MESSAGE: What can you do?') && prompts.some((prompt) => prompt.includes('CARDS — what each shows')),
53
+ lastPrompt().slice(-400),
70
54
  );
71
- check('words the model says are placed where it says, in the room it gives', areas() === 'answer.text answer.text' && on('a').data['title'] === 'One' && on('b').data['title'] === 'Two' && grid() === '2: a b', `${areas()} — ${grid()}`);
72
- check('the areas the answer changed are outlined', marked() === 'a b', marked());
73
- check('the chip in the dock names the answer shown by its title, and where it stands among the answers', drawn().includes('"Two things · 2/2"'), drawn().match(/"label":"[^"]*· \d+\/\d+"/)?.[0] ?? '');
74
- session.dispatch('dock', { type: 'ui:click', ref: 'stack' });
75
- await settle();
76
55
  check(
77
- 'opening the chip shows what was asked, what the model said it did, and the answers to go back to',
78
- current().response === 'Put the two side by side.' && drawn().includes('side by side.') && drawn().includes(`1. ${FIRST.label}`) && drawn().includes('2. Two things') && drawn().includes('Two things side by side'),
79
- String(current().response),
56
+ 'each message is recorded as a run: the model, what it spent and how it ended',
57
+ runs.map((run) => `${run.agentId} ${run.model} ${run.outcome} ${run.steps} ${run.totalTokens}`).join(' | ') === 'nisc-template-app.compose chat ok 1 110',
58
+ JSON.stringify(runs),
80
59
  );
81
- session.dispatch('dock', { type: 'ui:click', ref: 'stack' });
82
-
83
- const pairIds = ids();
84
- await ask('drop the second');
85
- check('when Jev finds nothing likely, the model is given no hint', !lastPrompt().includes('FAST PICKER'), lastPrompt().slice(-300));
86
- check('an answer that only empties an area outlines nothing', marked() === '', marked());
87
- check('an area the model drops is emptied, and every other stays as it was', on('b').id === '' && without('b', ids()) === without('b', pairIds), `${ids()} vs ${pairIds}`);
88
- const first = on('a').id;
89
- await ask('the second again, beside it');
90
- check('a canvas kept stays the same canvas, in its area; what is new goes where the model puts it', on('a').id === first && on('b').data['title'] === 'Two', `${ids()}`);
91
- await ask('swap them');
92
- check('the answer streams in: an area is placed while the rest of the reply is still being written', app.streamed() > 0, String(app.streamed()));
93
- check('a canvas the model keeps from another area moves there', on('a').data['title'] === 'Two' && on('b').data['title'] === 'One', `${String(on('a').data['title'])} ${String(on('b').data['title'])}`);
94
- const inB = on('b').id;
95
- await ask('other words for the first');
96
- check('a canvas the model writes again keeps its place and its instance, and takes what it is given', on('b').id === inB && on('b').data['text'] === 'Said again.', JSON.stringify(on('b').data));
97
60
 
98
- prompts.length = 0;
99
- await ask('keep what is not there');
61
+ await ask('and then?');
100
62
  check(
101
- 'keeping an area that is empty, or using one the arrangement does not have, is sent back saying so',
102
- (prompts[1] ?? '').includes('there is nothing in area f to keep') && (prompts[1] ?? '').includes('has no area c'),
103
- prompts[1]?.slice(-400) ?? '',
63
+ 'a message that follows on is told the conversation so far: what was asked, said and shown',
64
+ lastPrompt().includes('they asked: "What can you do?" — you said: "I answer with this app’s cards." — shown: words') && on('talk').length === 3,
65
+ lastPrompt().slice(-400),
104
66
  );
67
+ check('a turn with no cards is the turn alone', on('talk').at(-1)?.action === 'answer.turn' && on('talk').at(-1)?.data['reply'] === 'Then you ask again.', actionsOf(on('talk')));
105
68
 
106
- const beforeWeatherCard = ids();
107
- const stackBeforeWeatherCard = total();
108
69
  prompts.length = 0;
109
- runs.length = 0;
110
70
  await ask('Show me the weather card');
111
- check(
112
- 'an answer refused three times leaves the screen as it was, and the line says so',
113
- prompts.length === 3 && prompts[1]?.includes('there is no action "weather.card"') === true && ids() === beforeWeatherCard && total() === stackBeforeWeatherCard && said().includes('did not fit'),
114
- `${ids()} — ${said()}`,
115
- );
116
- check('a model run refused three times is recorded as failed, with its three steps', runs[1]?.outcome === 'failed' && runs[1]?.steps === 3 && runs[1]?.totalTokens === 330, JSON.stringify(runs[1]));
117
-
118
- await ask('Three things, the last wide beneath');
119
- check('a layout the model wrote is the one the answer is laid out in', current().arrangement === 'written' && grid() === '2: a b c×2' && areas() === 'answer.text answer.text answer.text', `${String(current().arrangement)} — ${grid()} — ${areas()}`);
71
+ check('a card the app does not have is sent back saying so, and the corrected answer is shown', (prompts[1] ?? '').includes('there is no card "weather.card"') && on('talk').at(-1)?.data['title'] === 'No weather', prompts[1]?.slice(-300) ?? '');
120
72
  prompts.length = 0;
121
- await ask('Two things, in a grid of my own');
122
- check('a grid that names an area twice is sent back saying so, and the arrangement on screen stays', (prompts[1] ?? '').includes('the grid names an area twice') && current().arrangement === 'written' && areas() === 'answer.text answer.text', `${String(current().arrangement)} — ${areas()}`);
73
+ await ask('Words and a card at once');
74
+ check('a card that is both words and a card is sent back saying so', (prompts[1] ?? '').includes('give exactly one of "action" with "input", or "say"') && on('talk').at(-1)?.data['title'] === 'One of them', prompts[1]?.slice(-300) ?? '');
123
75
 
124
- const stacked = total();
125
- const promptsBeforeOpen = prompts.length;
126
- session.shell.publish('open', FIRST.id);
76
+ prompts.length = 0;
77
+ runs.length = 0;
78
+ const before = on('talk').length;
79
+ await ask('Never a card that is there');
127
80
  check(
128
- 'a screen asked for on `open` — a card’s link — is shown at once, gone back to where it is in the stack, and nothing is asked of the model',
129
- (await until(() => current().screen === FIRST.id)) && areas() === START && current().position === 1 && total() === stacked && prompts.length === promptsBeforeOpen,
130
- `${areas()} — ${String(current().position)} of ${total()}`,
81
+ 'an answer refused every time is a turn that says so, and the screen stays as it was',
82
+ prompts.length === 5 && on('talk').length === before + 1 && String(on('talk').at(-1)?.data['reply']).includes('could not answer') && on('screen').map((one) => one.id).join() === screenIds,
83
+ `${String(prompts.length)} tries — ${String(on('talk').at(-1)?.data['reply'])}`,
131
84
  );
132
- await settle();
133
-
134
- const answeredBefore = app.answered();
135
- session.shell.publish('ask', 'What can you do?');
136
- check('a message sent on `ask` — a card’s thing to ask — is asked as if typed', (await until(() => app.answered() > answeredBefore)) && lastPrompt().includes('MESSAGE: What can you do?'), lastPrompt().slice(-200));
137
- await settle();
138
- check('words the model says are shown as words', areas() === 'answer.text' && on('a').data['title'] === 'What this app does', areas());
139
-
140
- await ask('Show the first screen');
141
- check('the model can answer with one of the app’s screens: gone back to where it is in the stack', current().screen === FIRST.id && current().position === 1, `${String(current().position)} of ${total()}`);
85
+ check('its run is recorded as failed, with every try', runs[0]?.outcome === 'failed' && runs[0]?.steps === 5, JSON.stringify(runs[0]));
142
86
 
143
- const beforeWeather = ids();
144
- const stackBeforeWeather = total();
145
- await ask('What is the weather in Vienna?');
146
- check('an answer that changes nothing leaves the screen as it was, and adds nothing to the stack', ids() === beforeWeather && total() === stackBeforeWeather && said() === '', `${ids()} — ${String(total())} — ${said()}`);
147
- check('and the bar says what was asked, and why nothing changed', current().question === 'What is the weather in Vienna?' && current().response === 'Nothing in this app shows the weather.', JSON.stringify(current()).slice(0, 200));
87
+ await ask('Too many cards');
88
+ check('more cards than a turn may have is refused, and the turn says so', String(on('talk').at(-1)?.data['reply']).includes('could not answer'), String(on('talk').at(-1)?.data['reply']));
148
89
 
149
90
  scripted.unreachable(true);
150
91
  runs.length = 0;
151
- await ask('Only one thing');
152
- check('a model that cannot be reached leaves the screen as it was, and the line says so', ids() === beforeWeather && said().includes('could not be reached'), said());
153
- check('and its run is recorded as failed: one step, nothing spent', runs[1]?.agentId === 'nisc-template-app.compose' && runs[1]?.outcome === 'failed' && runs[1]?.steps === 1 && runs[1]?.totalTokens === 0, JSON.stringify(runs[1]));
92
+ await ask('and then?');
93
+ check('a model that cannot be reached is a turn that says so', String(on('talk').at(-1)?.data['reply']).includes('could not be reached') && said() === '', String(on('talk').at(-1)?.data['reply']));
94
+ check('and its run is recorded as failed: one step, nothing spent', runs[0]?.outcome === 'failed' && runs[0]?.steps === 1 && runs[0]?.totalTokens === 0, JSON.stringify(runs[0]));
154
95
  scripted.unreachable(false);
155
96
 
156
- runs.length = 0;
157
- await ask('Name it at length');
158
- check('a reply that does not fit the reply’s schema is refused: the screen stays, and the line says it did not fit', ids() === beforeWeather && said().includes('did not fit'), said());
159
- check('and its run is recorded as failed, with its three steps', runs[1]?.outcome === 'failed' && runs[1]?.steps === 3, JSON.stringify(runs[1]));
160
-
161
- session.dispatch('dock', { type: 'ui:click', ref: 'forward' });
162
- check('forward from the first screen is the answer after it, as it was', await until(() => current().position === 2 && current().question === 'Two things side by side' && on('a').data['title'] === 'One'), `position ${String(current().position)}, ${areas()}`);
163
- session.dispatch('dock', { type: 'ui:click', ref: 'back' });
164
- check('back is the first screen again', await until(() => current().position === 1 && current().screen === FIRST.id), `position ${String(current().position)}`);
165
-
166
- session.dispatch('dock', { type: 'ui:click', ref: 'stack' });
167
- const stack = current().stack ?? [];
168
- check('the chip opens the stack: every answer, by its title or the screen it is', on('dock').data['listing'] === true && stack.length === total() && stack[0]?.label === FIRST.label && stack[1]?.label === 'Two things', JSON.stringify(stack.slice(0, 3)));
169
- session.dispatch('dock', { type: 'ui:click', ref: 'entry', payload: 4 });
170
- check('an answer picked from the stack is shown as it was, and the list closes', await until(() => current().position === 4 && on('b').data['title'] === 'Two' && on('dock').data['listing'] === false), `${String(current().position)}, ${areas()}`);
171
- } finally {
172
- app.server.close();
173
- }
97
+ if (ONE !== undefined) {
98
+ await ask('One of your cards');
99
+ const shown = on('talk').at(-1);
100
+ check('one of the app’s cards the model shows goes under its turn, opened with its whole input', shown?.action === ONE.id && Object.keys(ONE.data ?? {}).every((key) => shown.data[key] !== undefined), JSON.stringify(shown));
101
+ }
174
102
 
175
- const jevless = await startApp(scriptedModels(SCRIPT, { jevFails: true }).models);
176
- try {
177
- await jevless.ask('Only one thing');
178
- check('when Jev cannot answer, the model answers alone', jevless.areas() === 'answer.text' && jevless.on('a').data['title'] === 'One', jevless.areas());
103
+ const turns = on('talk').length;
104
+ session.shell.back();
105
+ await settle();
106
+ check('a turn is never a step Back takes', on('talk').length === turns, String(on('talk').length));
107
+
108
+ const asked = prompts.length;
109
+ session.shell.publish('ask', 'What can you do?');
110
+ check('a message sent on `ask` — a card’s thing to ask — is asked as if typed', (await until(() => prompts.length > asked)) && lastPrompt().includes('MESSAGE: What can you do?'), lastPrompt().slice(-200));
111
+ await settle();
112
+
113
+ const turnsBefore = on('talk').filter((one) => one.action === 'answer.turn').length;
114
+ session.shell.publish('ask', 'What can you do?');
115
+ session.shell.publish('ask', 'and then?');
116
+ const both = await until(() => on('talk').filter((one) => one.action === 'answer.turn' && one.data['thinking'] === false).length === turnsBefore + 2);
117
+ const lastTwo = on('talk').filter((one) => one.action === 'answer.turn').slice(-2);
118
+ check(
119
+ 'two messages sent at once are both answered, one after the other, in the order they were sent',
120
+ both && lastTwo.map((one) => one.data['question']).join(' | ') === 'What can you do? | and then?' && lastPrompt().includes('they asked: "What can you do?"'),
121
+ JSON.stringify(lastTwo.map((one) => one.data)),
122
+ );
123
+ await settle();
124
+
125
+ const promptsBeforeOpen = prompts.length;
126
+ await app.openScreen(LAST.id);
127
+ check('a screen opened from the dock is its cards, in order, and asks nothing of the model', actionsOf(on('screen')) === LAST.cards.map((card) => card.action).join(' ') && prompts.length === promptsBeforeOpen, actionsOf(on('screen')));
128
+ session.shell.publish('open', FIRST.id);
129
+ check('a screen asked for on `open` — a card’s link — is shown at once', await until(() => actionsOf(on('screen')) === START), actionsOf(on('screen')));
179
130
  } finally {
180
- jevless.server.close();
131
+ app.server.close();
181
132
  }
182
133
 
183
134
  const keyless = await startApp(scriptedModels(SCRIPT, { keyless: true }).models);
184
135
  try {
185
- await keyless.ask('Only one thing');
186
- check('with no key, the line names the key, and the screen stays as it was', keyless.said().includes('GROQ_API_KEY'), keyless.said());
136
+ await keyless.ask('What can you do?');
137
+ check('with no key, the turn names the key to set', String(keyless.on('talk').at(-1)?.data['reply']).includes('GROQ_API_KEY'), JSON.stringify(keyless.on('talk').map((one) => one.data)));
187
138
  } finally {
188
139
  keyless.server.close();
189
140
  }
@@ -3,18 +3,13 @@ import { SCREENS } from '../app/screens';
3
3
  import { recordOf } from '../server/compose/record';
4
4
  import { checks } from './checks';
5
5
  import { scriptedModels, settle, startApp, until } from './scripted';
6
- import type { Script } from './scripted';
7
-
8
- const card = (action: string) => ({ action, input: {}, intent: action });
9
- const counter = (title: string, count: number) => ({ action: 'guide.counter', input: { title, count }, intent: 'a counter' });
10
- const checklist = (title: string, todo: string[]) => ({ action: 'guide.checklist', input: { title, todo }, intent: 'a checklist' });
6
+ import type { Script, Shown } from './scripted';
11
7
 
12
8
  const SCRIPT: Script = {
13
- 'What is the charter?': [{ response: 'Put the charter where the nisc card was; the rest stays.', title: 'The charter', areas: [{ area: 'e', ...card('guide.charter') }] }],
14
- 'A counter that starts at 100': [{ areas: [{ area: 'b', ...counter('From 100', 100) }] }],
15
- 'A checklist with no steps': [{ areas: [{ area: 'd', ...checklist('Empty', []) }] }, { areas: [{ area: 'd', ...checklist('Mine', ['One step']) }] }],
16
- 'the nisc card at the top too': [{ areas: [{ area: 'a', ...card('guide.nisc') }] }, { areas: [] }],
17
- 'a counter at 5, no title': [{ areas: [{ area: 'b', action: 'guide.counter', input: { title: null, count: 5 }, intent: 'a counter' }] }],
9
+ 'What is the charter?': [{ response: 'The charter says who may do what.', cards: [{ action: 'guide.charter', input: {} }] }],
10
+ 'A counter that starts at 100': [{ cards: [{ action: 'guide.counter', input: { title: 'From 100', count: 100 } }] }],
11
+ 'A counter at 5, no title': [{ cards: [{ action: 'guide.counter', input: { title: null, count: 5 } }] }],
12
+ 'A checklist with no steps': [{ cards: [{ action: 'guide.checklist', input: { title: 'Empty', todo: [] } }] }, { cards: [{ action: 'guide.checklist', input: { title: 'Mine', todo: ['One step'] } }] }],
18
13
  };
19
14
 
20
15
  const { check, finish } = checks('guide');
@@ -24,71 +19,59 @@ check('every link on a card opens a screen there is', nowhere.length === 0, nowh
24
19
 
25
20
  const scripted = scriptedModels(SCRIPT);
26
21
  const { prompts } = scripted;
27
- const lastPrompt = (): string => prompts[prompts.length - 1] ?? '';
28
22
  const app = await startApp(scripted.models);
29
- const { on, rows, ids, without, current, drawn, areas, ask, session } = app;
23
+ const { on, ask, session } = app;
24
+ const card = (canvas: 'screen' | 'talk', action: string): Shown | undefined => [...on(canvas)].reverse().find((one) => one.action === action);
25
+ const press = (canvas: 'screen' | 'talk', shown: Shown | undefined, event: Record<string, unknown>): void => session.dispatch(canvas, { ...event, origin: shown?.id ?? '' });
26
+ const rows = (shown: Shown | undefined, key: string): unknown[] => {
27
+ const value = shown?.data[key];
28
+ return Array.isArray(value) ? value : [];
29
+ };
30
30
  try {
31
- app.draw();
32
- session.dispatch('b', { type: 'ui:click', ref: 'up' });
33
- session.dispatch('b', { type: 'ui:click', ref: 'up' });
34
- session.dispatch('b', { type: 'ui:click', ref: 'down' });
35
- session.dispatch('b', { type: 'ui:click', ref: 'up' });
36
- check('the counter counts what is pressed, up and down', await until(() => on('b').data['count'] === 2), JSON.stringify(on('b').data));
37
- session.dispatch('c', { type: 'ui:click', ref: 'pick', payload: 1 });
38
- check('the quick check, picked right, says so and why', await until(() => drawn().includes('Right. Links act at once')), JSON.stringify(on('c').data));
39
- session.dispatch('d', { type: 'ui:click', ref: 'tick', payload: 0 });
40
- check('a step ticked off moves from the steps to do to the ones done', await until(() => rows('d', 'done').join() === 'Press the counter' && rows('d', 'todo').length === 4), JSON.stringify(on('d').data));
41
- app.draw();
42
- session.dispatch('d', { type: 'ui:model', ref: 'adding', payload: 'Read the charter' });
43
- session.dispatch('d', { type: 'ui:click', ref: 'add' });
44
- check('a step typed and added goes last among the steps to do, and the line empties', await until(() => rows('d', 'todo').at(-1) === 'Read the charter' && on('d').data['adding'] === ''), JSON.stringify(on('d').data));
31
+ app.drawn();
32
+ press('screen', card('screen', 'guide.counter'), { type: 'ui:click', ref: 'up' });
33
+ press('screen', card('screen', 'guide.counter'), { type: 'ui:click', ref: 'up' });
34
+ press('screen', card('screen', 'guide.counter'), { type: 'ui:click', ref: 'down' });
35
+ press('screen', card('screen', 'guide.counter'), { type: 'ui:click', ref: 'up' });
36
+ check('the counter counts what is pressed, up and down', await until(() => card('screen', 'guide.counter')?.data['count'] === 2), JSON.stringify(card('screen', 'guide.counter')?.data));
37
+ press('screen', card('screen', 'guide.quiz'), { type: 'ui:click', ref: 'pick', payload: 1 });
38
+ check('the quick check, picked right, says so and why', await until(() => app.drawn().includes('Right. Links act at once')), JSON.stringify(card('screen', 'guide.quiz')?.data));
39
+ press('screen', card('screen', 'guide.checklist'), { type: 'ui:click', ref: 'tick', payload: 0 });
40
+ check('a step ticked off moves from the steps to do to the ones done', await until(() => rows(card('screen', 'guide.checklist'), 'done').join() === 'Press the counter'), JSON.stringify(card('screen', 'guide.checklist')?.data));
45
41
 
46
- const startIds = ids();
47
42
  await ask('What is the charter?');
48
- check(
49
- 'the model is given each card as the person left it: the count pressed, the steps ticked and added, the pick made',
50
- lastPrompt().includes('input {"title":"Press me","count":2}') && lastPrompt().includes('"done":["Press the counter"]') && lastPrompt().includes('"Ask the model to change a card","Read the charter"]') && lastPrompt().includes('"picked":1}'),
51
- lastPrompt().slice(0, 1600),
52
- );
53
- check('a card the model puts on the screen goes where it says, and nothing else moves', without('e', ids()) === without('e', startIds) && on('e').action === 'guide.charter', `${ids()} vs ${startIds}`);
54
- check('a card the answer leaves alone keeps what the person did to it', on('b').data['count'] === 2 && rows('d', 'done').length === 1 && on('c').data['picked'] === 1, JSON.stringify(on('b').data));
55
- check('a guide card holds its own text: its lead, its example, and where it leads', on('e').data['title'] === 'The charter' && String(on('e').data['example']).includes('"public"') && rows('e', 'links').length === 1, JSON.stringify(on('e').data).slice(0, 200));
43
+ const charter = card('talk', 'guide.charter');
44
+ check('a card the model shows goes under its turn, with its own text', charter !== undefined && charter.data['title'] === 'The charter' && String(charter.data['example']).includes('"public"'), JSON.stringify(charter?.data).slice(0, 200));
45
+ check('the screen behind keeps what the person did to it', card('screen', 'guide.counter')?.data['count'] === 2 && rows(card('screen', 'guide.checklist'), 'done').length === 1, JSON.stringify(card('screen', 'guide.counter')?.data));
56
46
 
57
- const link = recordOf(rows('e', 'links')[0]);
47
+ const link = recordOf(rows(charter, 'links')[0]);
58
48
  const promptsBeforeLink = prompts.length;
59
- session.dispatch('e', { type: 'ui:click', ref: 'link', payload: link['screen'] });
49
+ press('talk', charter, { type: 'ui:click', ref: 'link', payload: link['screen'] });
50
+ const linked = SCREENS.find((screen) => screen.id === link['screen']);
60
51
  check(
61
- 'a card’s link opens its screen at once, and asks nothing of the model',
62
- (await until(() => current().screen === link['screen'])) && prompts.length === promptsBeforeLink && areas() === 'guide.yours guide.checklist',
63
- `${String(current().screen)} — ${areas()}`,
52
+ 'a link on a card in the conversation opens its screen at once, and asks nothing of the model',
53
+ (await until(() => on('screen').map((one) => one.action).join(' ') === linked?.cards.map((one) => one.action).join(' '))) && prompts.length === promptsBeforeLink,
54
+ on('screen').map((one) => one.action).join(' '),
64
55
  );
65
56
  await settle();
66
- await app.openScreen('start');
67
- check('a screen gone back to is as the person left it', on('b').data['count'] === 2 && rows('d', 'done').join() === 'Press the counter' && on('c').data['picked'] === 1, `${JSON.stringify(on('b').data)} ${JSON.stringify(on('d').data)}`);
68
- await app.openScreen('asking');
69
- check('another quick check where an answered one was opens unanswered', on('c').action === 'guide.quiz' && on('c').data['picked'] === -1, JSON.stringify(on('c').data));
57
+
70
58
  await app.openScreen('rules');
71
59
  check(
72
60
  'the packages card replays its read: every row of the table, in order, worded by the read’s mapping',
73
- on('d').action === 'guide.packages' && (await until(() => rows('d', 'points').length === 12)) && JSON.stringify(rows('d', 'points')[0]) === JSON.stringify({ title: '@niscorp/nova', text: 'The screen: shells, canvases, actions and their layouts.' }),
74
- JSON.stringify(on('d').data).slice(0, 300),
61
+ (await until(() => rows(card('screen', 'guide.packages'), 'points').length === 12)) && JSON.stringify(rows(card('screen', 'guide.packages'), 'points')[0]) === JSON.stringify({ title: '@niscorp/nova', text: 'The screen: shells, canvases, actions and their layouts.' }),
62
+ JSON.stringify(card('screen', 'guide.packages')?.data).slice(0, 300),
75
63
  );
76
- await app.openScreen('start');
77
64
 
78
- const counterId = on('b').id;
79
65
  await ask('A counter that starts at 100');
80
- check('a card the model opens again with another input keeps its place and its instance, and takes the input', on('b').id === counterId && on('b').data['count'] === 100 && on('b').data['title'] === 'From 100', JSON.stringify(on('b').data));
81
- session.dispatch('b', { type: 'ui:click', ref: 'reset' });
82
- check('Reset sets the counter back to zero, whatever it was opened with', await until(() => on('b').data['count'] === 0), JSON.stringify(on('b').data));
66
+ check('a card the model fills in is opened with what it was given', card('talk', 'guide.counter')?.data['count'] === 100 && card('talk', 'guide.counter')?.data['title'] === 'From 100', JSON.stringify(card('talk', 'guide.counter')?.data));
67
+ const counter = card('talk', 'guide.counter');
68
+ press('talk', counter, { type: 'ui:click', ref: 'reset' });
69
+ check('a card in the conversation works as it does on a screen', await until(() => on('talk').find((one) => one.id === counter?.id)?.data['count'] === 0), JSON.stringify(on('talk').find((one) => one.id === counter?.id)?.data));
70
+ await ask('A counter at 5, no title');
71
+ check('a value the model says is null is its card’s default', card('talk', 'guide.counter')?.data['count'] === 5 && card('talk', 'guide.counter')?.data['title'] === 'Press me', JSON.stringify(card('talk', 'guide.counter')?.data));
83
72
  prompts.length = 0;
84
73
  await ask('A checklist with no steps');
85
- check('a checklist with no steps is sent back saying so', (prompts[1] ?? '').includes('input.todo') && on('d').data['title'] === 'Mine', prompts[1]?.slice(-300) ?? '');
86
- check('a checklist the model writes where another was keeps none of its ticks', rows('d', 'done').length === 0 && rows('d', 'todo').join() === 'One step', JSON.stringify(on('d').data));
87
- prompts.length = 0;
88
- await ask('the nisc card at the top too');
89
- check('the same card in two areas is sent back saying so', (prompts[1] ?? '').includes('areas a and e would show the same thing; show it once'), prompts[1]?.slice(-300) ?? '');
90
- await ask('a counter at 5, no title');
91
- check('a value the model says is null is its card’s default', on('b').data['count'] === 5 && on('b').data['title'] === 'Press me', JSON.stringify(on('b').data));
74
+ check('a checklist with no steps is sent back saying so', (prompts[1] ?? '').includes('input.todo') && card('talk', 'guide.checklist')?.data['title'] === 'Mine', prompts[1]?.slice(-300) ?? '');
92
75
  } finally {
93
76
  app.server.close();
94
77
  }