create-nisc 0.9.2 → 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.
- package/CHANGELOG.md +17 -0
- package/README.md +20 -22
- package/dist/{chunk-RUHOVTHF.js → chunk-2W7KLXCO.js} +3 -3
- package/dist/{chunk-RUHOVTHF.js.map → chunk-2W7KLXCO.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/base/files/src/ui/kit.css +8 -41
- package/templates/dom/files/src/ui/kit.ts +2 -8
- package/templates/dom/files/src/ui/registry.ts +2 -2
- package/templates/model-first/agents-section.md +31 -25
- package/templates/model-first/files/src/app/action-catalog.ts +4 -3
- package/templates/model-first/files/src/app/actions/answer/turn.action.ts +23 -0
- package/templates/model-first/files/src/app/actions/ask/dock.action.ts +10 -33
- package/templates/model-first/files/src/app/actions/ask/dock.layout.ts +7 -39
- package/templates/model-first/files/src/app/actions/guide/guide.actions.ts +16 -19
- package/templates/model-first/files/src/app/app.ts +4 -3
- package/templates/model-first/files/src/app/charter/charter.ts +1 -1
- package/templates/model-first/files/src/app/screens.ts +27 -48
- package/templates/model-first/files/src/app/shell/frame.layout.ts +5 -1
- package/templates/model-first/files/src/app/shell/shell.ts +7 -10
- package/templates/model-first/files/src/dev/all-checks.ts +3 -3
- package/templates/model-first/files/src/dev/artifacts-check.ts +14 -25
- package/templates/model-first/files/src/dev/compose-check.ts +87 -136
- package/templates/model-first/files/src/dev/guide-check.ts +41 -58
- package/templates/model-first/files/src/dev/live-ask.ts +43 -138
- package/templates/model-first/files/src/dev/scripted.ts +24 -102
- package/templates/model-first/files/src/dev/shape-check.ts +2 -6
- package/templates/model-first/files/src/dev/strata.ts +2 -2
- package/templates/model-first/files/src/server/boot.ts +2 -2
- package/templates/model-first/files/src/server/compose/catalog.ts +10 -28
- package/templates/model-first/files/src/server/compose/composer.agent.ts +13 -11
- package/templates/model-first/files/src/server/compose/index.ts +55 -132
- package/templates/model-first/files/src/server/compose/knowledge.ts +22 -43
- package/templates/model-first/files/src/server/compose/turn.schema.ts +55 -0
- package/templates/model-first/files/src/server/models/index.ts +5 -23
- package/templates/model-first/item.json +28 -38
- package/templates/react/files/src/ui/kit.tsx +14 -25
- package/templates/react/files/src/ui/registry.ts +2 -2
- package/templates/model-first/files/src/app/arrangements.ts +0 -17
- package/templates/model-first/files/src/app/shell/areas.ts +0 -3
- package/templates/model-first/files/src/server/compose/answer.ts +0 -145
- package/templates/model-first/files/src/server/compose/history.ts +0 -45
- package/templates/model-first/files/src/server/compose/layout.ts +0 -70
- package/templates/model-first/files/src/server/compose/pick.ts +0 -44
- package/templates/model-first/files/src/server/compose/plan.ts +0 -45
- package/templates/model-first/files/src/server/compose/reply.schema.ts +0 -70
- package/templates/model-first/files/src/server/compose/screen.ts +0 -40
|
@@ -3,11 +3,9 @@ import { ActionDefinitionSchema, LayoutNodeSchema } from '@niscorp/nova';
|
|
|
3
3
|
import type { LayoutNode } from '@niscorp/nova';
|
|
4
4
|
import { componentsOf, walkNodes } from '@niscorp/nova/reflect';
|
|
5
5
|
import { actions } from '../app/action-catalog';
|
|
6
|
-
import { ARRANGEMENTS } from '../app/arrangements';
|
|
7
6
|
import { assignments } from '../app/charter/assignments';
|
|
8
7
|
import { charter } from '../app/charter/charter';
|
|
9
8
|
import { SCREENS } from '../app/screens';
|
|
10
|
-
import { AREAS } from '../app/shell/areas';
|
|
11
9
|
import { shell } from '../app/shell/shell';
|
|
12
10
|
import { inputKeysOf } from '../server/compose/catalog';
|
|
13
11
|
import { isRecord } from '../server/compose/record';
|
|
@@ -52,44 +50,35 @@ for (const [id, definition] of Object.entries(actions)) {
|
|
|
52
50
|
const registered = new Set(buildRegistry().list());
|
|
53
51
|
const layouts: [string, LayoutNode | undefined][] = [
|
|
54
52
|
['the frame', shell.layout],
|
|
53
|
+
...(shell.canvases ?? []).map((canvas): [string, LayoutNode | undefined] => [`canvas "${canvas.id}"`, typeof canvas.actionLayout === 'string' ? undefined : canvas.actionLayout]),
|
|
55
54
|
...Object.values(actions).map((definition): [string, LayoutNode | undefined] => [`action "${definition.id}"`, definition.layout]),
|
|
56
|
-
...ARRANGEMENTS.map((arrangement): [string, LayoutNode | undefined] => [`arrangement "${arrangement.id}"`, arrangement.layout]),
|
|
57
55
|
];
|
|
58
56
|
for (const [name, layout] of layouts) {
|
|
59
57
|
const missing = [...componentsOf(layout)].filter((component) => !registered.has(component));
|
|
60
58
|
check(`${name} names only components the kit has`, missing.length === 0, missing.join(', '));
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const held: string[] = [];
|
|
61
|
+
const slotsIn = (layout: unknown): string[] => {
|
|
62
|
+
const slots: string[] = [];
|
|
66
63
|
walkNodes(layout, (node) => {
|
|
67
|
-
if (node['component'] === 'CanvasSlot' && isRecord(node['props']) && typeof node['props']['canvasId'] === 'string')
|
|
64
|
+
if (node['component'] === 'CanvasSlot' && isRecord(node['props']) && typeof node['props']['canvasId'] === 'string') slots.push(node['props']['canvasId']);
|
|
68
65
|
});
|
|
69
|
-
return
|
|
66
|
+
return slots;
|
|
70
67
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const held = canvasesIn(arrangement.layout);
|
|
74
|
-
check(`arrangement "${arrangement.id}" holds only areas the shell has, each once`, held.every((name) => AREAS.some((area) => area === name)) && new Set(held).size === held.length, held.join(', '));
|
|
75
|
-
check(`arrangement "${arrangement.id}" holds the ${arrangement.areaCount} it says, the first areas in order`, held.join(',') === AREAS.slice(0, arrangement.areaCount).join(','), held.join(', '));
|
|
76
|
-
}
|
|
77
|
-
check('the frame has the region an arrangement is swapped into, and the first one in it', JSON.stringify(shell.layout).includes('"ref":"answers"') && shell.layoutStore?.['answers'] !== undefined);
|
|
68
|
+
const drawn = [...slotsIn(shell.layout), ...Object.values(actions).flatMap((definition) => slotsIn(definition.layout))];
|
|
69
|
+
for (const canvas of shell.canvases ?? []) check(`canvas "${canvas.id}" is drawn once: in the frame, or in an action`, drawn.filter((id) => id === canvas.id).length === 1, drawn.join(', '));
|
|
78
70
|
|
|
79
71
|
pure('the screens', SCREENS);
|
|
80
72
|
for (const screen of SCREENS) {
|
|
81
|
-
for (const [at,
|
|
82
|
-
const action = actions[
|
|
83
|
-
const named = `screen "${screen.id}"
|
|
84
|
-
check(`${named} opens an action the app has`, action !== undefined,
|
|
85
|
-
const extra = Object.keys(
|
|
86
|
-
check(`${named} gives only inputs ${
|
|
87
|
-
const parsed = action?.input === undefined ? undefined : z.fromJSONSchema(action.input).safeParse(
|
|
73
|
+
for (const [at, card] of screen.cards.entries()) {
|
|
74
|
+
const action = actions[card.action];
|
|
75
|
+
const named = `screen "${screen.id}" card ${String(at + 1)}`;
|
|
76
|
+
check(`${named} opens an action the app has`, action !== undefined, card.action);
|
|
77
|
+
const extra = Object.keys(card.input).filter((key) => !inputKeysOf(action?.input).includes(key));
|
|
78
|
+
check(`${named} gives only inputs ${card.action} takes`, extra.length === 0, extra.join(', '));
|
|
79
|
+
const parsed = action?.input === undefined ? undefined : z.fromJSONSchema(action.input).safeParse(card.input);
|
|
88
80
|
check(`${named} is opened with an input its action’s schema takes`, parsed === undefined || parsed.success, parsed?.error?.message ?? '');
|
|
89
|
-
check(`${named} says why it is there`, canvas.intent.trim() !== '');
|
|
90
81
|
}
|
|
91
|
-
const arrangement = ARRANGEMENTS.find((candidate) => candidate.id === screen.arrangement);
|
|
92
|
-
check(`screen "${screen.id}" is laid out in an arrangement there is, with room for its canvases`, arrangement !== undefined && arrangement.areaCount >= screen.canvases.length, `${screen.arrangement}: ${screen.canvases.length} canvases`);
|
|
93
82
|
}
|
|
94
83
|
|
|
95
84
|
finish();
|
|
@@ -1,189 +1,140 @@
|
|
|
1
1
|
import { renderDocument } from '@niscorp/moss';
|
|
2
|
-
import {
|
|
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
|
|
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
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
'
|
|
62
|
-
|
|
63
|
-
JSON.stringify(
|
|
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('
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
'
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
99
|
-
await ask('keep what is not there');
|
|
61
|
+
await ask('and then?');
|
|
100
62
|
check(
|
|
101
|
-
'
|
|
102
|
-
(
|
|
103
|
-
|
|
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('
|
|
122
|
-
check('a
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
'
|
|
129
|
-
|
|
130
|
-
`${
|
|
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
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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('
|
|
152
|
-
check('a model that cannot be reached
|
|
153
|
-
check('and its run is recorded as failed: one step, nothing spent', runs[
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
176
|
-
|
|
177
|
-
await
|
|
178
|
-
check('
|
|
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
|
-
|
|
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('
|
|
186
|
-
check('with no key, the
|
|
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: '
|
|
14
|
-
'A counter that starts at 100': [{
|
|
15
|
-
'A
|
|
16
|
-
'
|
|
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,
|
|
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.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
check('the counter counts what is pressed, up and down', await until(() =>
|
|
37
|
-
|
|
38
|
-
check('the quick check, picked right, says so and why', await until(() => drawn().includes('Right. Links act at once')), JSON.stringify(
|
|
39
|
-
|
|
40
|
-
check('a step ticked off moves from the steps to do to the ones done', await until(() => rows('
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(
|
|
47
|
+
const link = recordOf(rows(charter, 'links')[0]);
|
|
58
48
|
const promptsBeforeLink = prompts.length;
|
|
59
|
-
|
|
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
|
|
62
|
-
(await until(() =>
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
JSON.stringify(
|
|
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
|
|
81
|
-
|
|
82
|
-
|
|
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') &&
|
|
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
|
}
|