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
|
@@ -1,115 +1,46 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import type { SignalClient } from '@niscorp/cortex';
|
|
3
|
-
import {
|
|
4
|
-
import type { Chat, Jev } from '../server/compose';
|
|
3
|
+
import type { Chat } from '../server/compose';
|
|
5
4
|
import { modelsFromEnv } from '../server/models';
|
|
6
5
|
import { startApp } from './scripted';
|
|
6
|
+
import type { Shown } from './scripted';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
|
|
8
|
+
// A turn as the person sees it: the sentence, and the cards under it.
|
|
9
|
+
type Turn = { reply: string; cards: Shown[] };
|
|
10
|
+
// A case: a message, and what the turn it gets must be; a case that follows on from the one before it says so.
|
|
11
|
+
type Case = { ask: string; want: (turn: Turn) => string | undefined; follows?: boolean };
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
// Two areas showing the same card with the same content is never the screen a message wants.
|
|
17
|
-
const twice = (now: Screen): string | undefined => {
|
|
18
|
-
const seen = now.canvases.filter((shown) => shown.action !== 'answer.text').map((shown) => JSON.stringify([shown.action, shown.data]));
|
|
13
|
+
const shows = (action: string) => (turn: Turn): string | undefined => (turn.cards.some((card) => card.action === action) ? undefined : `want ${action}`);
|
|
14
|
+
const twice = (turn: Turn): string | undefined => {
|
|
15
|
+
const seen = turn.cards.map((card) => JSON.stringify([card.action, card.data]));
|
|
19
16
|
return new Set(seen).size === seen.length ? undefined : 'the same card is shown twice';
|
|
20
17
|
};
|
|
21
18
|
|
|
22
|
-
const
|
|
23
|
-
const listOf = (value: unknown): unknown[] => (Array.isArray(value) ? value : []);
|
|
24
|
-
const tour = (screen: Screen): Shown | undefined => screen.canvases.find((shown) => is(shown, 'guide.checklist'));
|
|
25
|
-
|
|
26
|
-
const RUN: readonly Step[] = [
|
|
27
|
-
{ open: 'start' },
|
|
19
|
+
const CASES: readonly Case[] = [
|
|
28
20
|
{ ask: 'What is an action?', want: shows('guide.actions') },
|
|
29
|
-
{ open: 'start' },
|
|
30
21
|
{ ask: 'Who may do what?', want: shows('guide.charter') },
|
|
31
|
-
{
|
|
32
|
-
{ ask: 'How
|
|
33
|
-
{
|
|
34
|
-
{ ask: 'A counter that starts at 100', want: (
|
|
35
|
-
{
|
|
36
|
-
{ ask: '
|
|
37
|
-
{
|
|
38
|
-
{
|
|
39
|
-
ask: 'Quiz me on the charter',
|
|
40
|
-
want: (now, before) => {
|
|
41
|
-
const asked = new Set(before.canvases.filter((shown) => is(shown, 'guide.quiz')).map((shown) => String(shown.data['question'])));
|
|
42
|
-
return now.canvases.some((shown) => is(shown, 'guide.quiz') && !asked.has(String(shown.data['question']))) ? undefined : 'want a new quick check';
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{ open: 'start' },
|
|
46
|
-
{
|
|
47
|
-
ask: 'tick off the first step of my tour',
|
|
48
|
-
want: (now, before) => (tour(now)?.id === tour(before)?.id && listOf(tour(now)?.data['done']).includes('Press the counter') ? undefined : 'want "Press the counter" ticked off, on the same checklist'),
|
|
49
|
-
},
|
|
50
|
-
{ ask: 'add "Read the charter" to the tour', want: (now) => (listOf(tour(now)?.data['todo']).some((step) => /charter/i.test(String(step))) ? undefined : 'want the step added to the tour') },
|
|
51
|
-
{ open: 'start' },
|
|
52
|
-
{
|
|
53
|
-
ask: 'Put the charter beside the counter',
|
|
54
|
-
want: (now, before) => {
|
|
55
|
-
const counter = before.canvases.find((shown) => is(shown, 'guide.counter'));
|
|
56
|
-
return counter !== undefined && at(now, counter.area)?.id === counter.id && has(now, 'guide.charter') ? undefined : 'want the counter where it was, and the charter';
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
{ open: 'start' },
|
|
60
|
-
{ ask: 'What can you do?', want: (now) => (has(now, 'answer.text') || has(now, 'guide.welcome') ? undefined : 'want words, or the welcome') },
|
|
61
|
-
{ open: 'asking' },
|
|
62
|
-
{ ask: 'Only the steps, please', want: (now) => (now.canvases.length === 1 && is(now.canvases[0], 'guide.answers') ? undefined : 'want the steps alone') },
|
|
63
|
-
{ open: 'start' },
|
|
64
|
-
{ ask: 'What are layouts?', want: shows('guide.layouts') },
|
|
65
|
-
{
|
|
66
|
-
ask: 'and the shell beside it',
|
|
67
|
-
want: (now, before) => {
|
|
68
|
-
const layouts = before.canvases.find((shown) => shown.action === 'guide.layouts');
|
|
69
|
-
return layouts !== undefined && at(now, layouts.area)?.id === layouts.id && has(now, 'guide.shell') ? undefined : 'want the layouts card where it was, and the shell';
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
ask: 'now the charter instead of the shell',
|
|
74
|
-
want: (now, before) => {
|
|
75
|
-
const shell = before.canvases.find((shown) => shown.action === 'guide.shell');
|
|
76
|
-
const layouts = before.canvases.find((shown) => shown.action === 'guide.layouts');
|
|
77
|
-
const there = shell === undefined ? undefined : at(now, shell.area);
|
|
78
|
-
return is(there, 'guide.charter') && (layouts === undefined || at(now, layouts.area)?.id === layouts.id) ? undefined : 'want the charter where the shell was, and the layouts card untouched';
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
{ ask: 'Show me the rules lesson', want: (now) => (now.screen === 'rules' ? undefined : 'want the rules screen') },
|
|
82
|
-
{ open: 'start' },
|
|
83
|
-
{ ask: 'How do I make this app mine?', want: shows('guide.yours') },
|
|
22
|
+
{ ask: 'How is my message answered?', want: shows('guide.answers') },
|
|
23
|
+
{ ask: 'How do reads work?', want: shows('guide.data') },
|
|
24
|
+
{ ask: 'and what is the shell?', want: shows('guide.shell'), follows: true },
|
|
25
|
+
{ ask: 'A counter that starts at 100', want: (turn) => (turn.cards.some((card) => card.action === 'guide.counter' && card.data['count'] === 100) ? undefined : 'want a counter at 100') },
|
|
26
|
+
{ ask: 'A checklist for my first nisc app', want: (turn) => (turn.cards.some((card) => card.action === 'guide.checklist' && Array.isArray(card.data['todo']) && card.data['todo'].length > 0) ? undefined : 'want a checklist with steps') },
|
|
27
|
+
{ ask: 'Quiz me on the charter', want: shows('guide.quiz') },
|
|
28
|
+
{ ask: 'What is the weather in Vienna?', want: (turn) => (turn.reply !== '' && !turn.reply.startsWith('I could not') && turn.cards.every((card) => card.action === 'answer.text') ? undefined : 'want a sentence and no card: nothing here shows the weather') },
|
|
84
29
|
];
|
|
85
30
|
|
|
86
31
|
const prompts = process.argv.includes('--prompts');
|
|
87
32
|
const why = prompts || process.argv.includes('--why');
|
|
88
33
|
const runs = Number(process.argv.find((arg) => arg.startsWith('--runs='))?.slice('--runs='.length) ?? 1);
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
const steps: readonly Step[] = own.length > 0 ? own.map((arg): Step => (arg.startsWith('--screen=') ? { open: arg.slice('--screen='.length) } : { ask: arg })) : RUN;
|
|
34
|
+
const own = process.argv.slice(2).filter((arg) => !arg.startsWith('--'));
|
|
35
|
+
const cases: readonly Case[] = own.length > 0 ? own.map((ask) => ({ ask, want: () => undefined, follows: true })) : CASES;
|
|
92
36
|
|
|
93
37
|
if (existsSync('.env')) process.loadEnvFile('.env');
|
|
94
38
|
const models = modelsFromEnv(process.env);
|
|
39
|
+
if (models.chat === undefined) {
|
|
40
|
+
console.log(`Set ${models.missing.join(' and ')} in .env: live-ask asks the real model.`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
95
43
|
const said: string[] = [];
|
|
96
|
-
const jevWith = noJev ? undefined : models.jev;
|
|
97
|
-
const jev: Jev | undefined = jevWith && {
|
|
98
|
-
...jevWith,
|
|
99
|
-
decide: async (state, questions) => {
|
|
100
|
-
const answered = await jevWith.decide(state, questions);
|
|
101
|
-
const picked = answered.picked;
|
|
102
|
-
if (prompts) said.push(`──── JEV STATE
|
|
103
|
-
${JSON.stringify(state, null, 2)}
|
|
104
|
-
──── JEV QUESTIONS
|
|
105
|
-
${JSON.stringify(questions, null, 2)}
|
|
106
|
-
──── JEV ANSWERED
|
|
107
|
-
${JSON.stringify(picked, null, 2)}`);
|
|
108
|
-
const yes = Object.entries(picked).flatMap(([name, one]) => (one.yes ? [name] : []));
|
|
109
|
-
said.push(` Jev: ${yes.join(' ')}`);
|
|
110
|
-
return answered;
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
44
|
const told = (llm: SignalClient): SignalClient => ({
|
|
114
45
|
...llm,
|
|
115
46
|
stepStream: (request, options) =>
|
|
@@ -121,65 +52,39 @@ const told = (llm: SignalClient): SignalClient => ({
|
|
|
121
52
|
}
|
|
122
53
|
})(),
|
|
123
54
|
});
|
|
124
|
-
const chat: Chat
|
|
55
|
+
const chat: Chat = { ...models.chat, llm: told(models.chat.llm) };
|
|
125
56
|
|
|
126
57
|
const times: number[] = [];
|
|
127
|
-
|
|
128
|
-
const misses = new Map<string, number>();
|
|
58
|
+
let missed = 0;
|
|
129
59
|
for (let run = 1; run <= runs; run += 1) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
canvases: AREAS.flatMap((area): Shown[] => {
|
|
133
|
-
const { id, action, data } = app.on(area);
|
|
134
|
-
return id === '' ? [] : [{ area, id, action, title: String(data['title'] ?? ''), data }];
|
|
135
|
-
}),
|
|
136
|
-
arrangement: app.current().arrangement ?? '',
|
|
137
|
-
screen: app.current().screen ?? '',
|
|
138
|
-
said: app.said(),
|
|
139
|
-
response: app.current().response ?? '',
|
|
140
|
-
title: app.current().label ?? '',
|
|
141
|
-
});
|
|
142
|
-
const print = (screen: Screen): string => screen.canvases.map((shown) => ` ${shown.area}: ${shown.action} — ${shown.title}`).join('\n');
|
|
143
|
-
|
|
60
|
+
console.log(`\n═══ run ${String(run)}`);
|
|
61
|
+
let app = await startApp({ chat, missing: [] }, 60_000);
|
|
144
62
|
let right = 0;
|
|
145
|
-
let scored = 0;
|
|
146
|
-
console.log(`\n═══ run ${run}`);
|
|
147
63
|
try {
|
|
148
|
-
for (const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
64
|
+
for (const one of cases) {
|
|
65
|
+
// A case that does not follow on is asked in a conversation of its own.
|
|
66
|
+
if (one.follows !== true) {
|
|
67
|
+
app.server.close();
|
|
68
|
+
app = await startApp({ chat, missing: [] }, 60_000);
|
|
153
69
|
}
|
|
154
|
-
const before =
|
|
155
|
-
const took = await app.ask(
|
|
70
|
+
const before = app.on('talk').length;
|
|
71
|
+
const took = await app.ask(one.ask);
|
|
156
72
|
if (took !== undefined) times.push(took);
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
const verdict = step.want === undefined ? '' : miss === undefined ? ' ✓' : ` ✗ ${miss}`;
|
|
165
|
-
console.log(`» "${step.ask}" — ${Math.round(took ?? 0)} ms ·${screen.arrangement}${verdict}${screen.said !== '' ? ` · the line says: ${screen.said}` : ''}\n title: ${screen.title} · response: ${screen.response}\n${print(screen)}`);
|
|
73
|
+
const added = app.on('talk').slice(before);
|
|
74
|
+
const turn: Turn = { reply: String(added[0]?.data['reply'] ?? ''), cards: added.slice(1) };
|
|
75
|
+
const miss = took === undefined ? 'no answer in 60 s' : (twice(turn) ?? one.want(turn));
|
|
76
|
+
if (miss === undefined) right += 1;
|
|
77
|
+
else missed += 1;
|
|
78
|
+
console.log(`» "${one.ask}" — ${String(Math.round(took ?? 0))} ms ${miss === undefined ? '✓' : `✗ ${miss}`}\n ${turn.reply}\n${turn.cards.map((card) => ` ${card.action}`).join('\n')}`);
|
|
166
79
|
if (why) console.log(said.join('\n'));
|
|
167
80
|
said.length = 0;
|
|
168
81
|
}
|
|
169
82
|
} finally {
|
|
170
83
|
app.server.close();
|
|
171
84
|
}
|
|
172
|
-
|
|
173
|
-
scores.push(right);
|
|
174
|
-
console.log(`run ${run}: ${right}/${scored} right`);
|
|
175
|
-
}
|
|
85
|
+
console.log(`run ${String(run)}: ${String(right)}/${String(cases.length)} right`);
|
|
176
86
|
}
|
|
177
87
|
|
|
178
88
|
const sorted = [...times].sort((one, other) => one - other);
|
|
179
|
-
console.log(`\n${times.length} messages · median ${Math.round(sorted[Math.floor(sorted.length / 2)] ?? 0)} ms · slowest ${Math.round(sorted[sorted.length - 1] ?? 0)} ms`);
|
|
180
|
-
|
|
181
|
-
const scoredSteps = steps.filter((step) => 'ask' in step && step.want !== undefined).length;
|
|
182
|
-
console.log(`right: ${scores.join(', ')} of ${scoredSteps} · ${scores.reduce((sum, score) => sum + score, 0)}/${scoredSteps * scores.length} in all`);
|
|
183
|
-
for (const [ask, count] of misses) console.log(` missed ${count}×: "${ask}"`);
|
|
184
|
-
}
|
|
185
|
-
process.exit(0);
|
|
89
|
+
console.log(`\n${String(times.length)} messages · median ${String(Math.round(sorted[Math.floor(sorted.length / 2)] ?? 0))} ms · slowest ${String(Math.round(sorted[sorted.length - 1] ?? 0))} ms · ${String(missed)} missed`);
|
|
90
|
+
process.exit(missed === 0 ? 0 : 1);
|
|
@@ -2,11 +2,8 @@ import type { SignalClient, Usage } from '@niscorp/cortex';
|
|
|
2
2
|
import type { MossServer, RunRecord } from '@niscorp/moss';
|
|
3
3
|
import { routeResponse } from '@niscorp/signal';
|
|
4
4
|
import type { StepRequest, StepResult } from '@niscorp/signal';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
import { AREAS } from '../app/shell/areas';
|
|
7
5
|
import { boot } from '../server/boot';
|
|
8
|
-
import type {
|
|
9
|
-
import { recordOf } from '../server/compose/record';
|
|
6
|
+
import type { Models } from '../server/compose';
|
|
10
7
|
|
|
11
8
|
// Each message, and the replies the chat model gives it, one a call: the last one again and again.
|
|
12
9
|
export type Script = Record<string, Record<string, unknown>[]>;
|
|
@@ -23,30 +20,14 @@ export const settle = (): Promise<void> => new Promise((done) => setTimeout(done
|
|
|
23
20
|
|
|
24
21
|
const SPENT: Usage = { inputTokens: 100, outputTokens: 10, totalTokens: 110, reported: true };
|
|
25
22
|
|
|
26
|
-
export type Scripted = {
|
|
27
|
-
models: Models;
|
|
28
|
-
prompts: string[];
|
|
29
|
-
asked: { state: Record<string, unknown>; questions: Record<string, unknown> }[];
|
|
30
|
-
likely: (ids: readonly string[]) => void;
|
|
31
|
-
unreachable: (is: boolean) => void;
|
|
32
|
-
};
|
|
23
|
+
export type Scripted = { models: Models; prompts: string[]; unreachable: (is: boolean) => void };
|
|
33
24
|
|
|
34
|
-
// Offline, and the same every run: a
|
|
35
|
-
|
|
36
|
-
export const scriptedModels = (script: Script, options: { jevFails?: boolean; keyless?: boolean } = {}): Scripted => {
|
|
37
|
-
let likely: readonly string[] = [];
|
|
25
|
+
// Offline, and the same every run: a chat model that answers each message in the run's input with its script.
|
|
26
|
+
export const scriptedModels = (script: Script, options: { keyless?: boolean } = {}): Scripted => {
|
|
38
27
|
let unreachable = false;
|
|
39
28
|
const prompts: string[] = [];
|
|
40
|
-
const asked: Scripted['asked'] = [];
|
|
41
29
|
const turns = new Map<string, number>();
|
|
42
30
|
|
|
43
|
-
const decide: Decide = async (state, questions) => {
|
|
44
|
-
if (options.jevFails === true) throw new Error('Jev did not answer');
|
|
45
|
-
asked.push({ state, questions });
|
|
46
|
-
const answer = (instructions: string): { yes: boolean; probability: number } => (likely.some((id) => instructions.includes(`"${id}"`)) ? { yes: true, probability: 0.9 } : { yes: false, probability: 0.1 });
|
|
47
|
-
return { picked: Object.fromEntries(Object.entries(questions).map(([key, question]) => [key, answer(question.instructions)])), usage: SPENT };
|
|
48
|
-
};
|
|
49
|
-
|
|
50
31
|
const scripted = (request: StepRequest): StepResult => {
|
|
51
32
|
const user = request.messages.map((message) => (typeof message.content === 'string' ? message.content : '')).join('\n\n');
|
|
52
33
|
prompts.push(user);
|
|
@@ -54,9 +35,9 @@ export const scriptedModels = (script: Script, options: { jevFails?: boolean; ke
|
|
|
54
35
|
const message = /^MESSAGE: (.*)$/m.exec(user)?.[1] ?? '';
|
|
55
36
|
const turn = turns.get(message) ?? 0;
|
|
56
37
|
turns.set(message, turn + 1);
|
|
57
|
-
const replies = script[message] ?? [{
|
|
38
|
+
const replies = script[message] ?? [{ cards: [] }];
|
|
58
39
|
const { response = 'Scripted.', ...data } = replies[Math.min(turn, replies.length - 1)] ?? {};
|
|
59
|
-
const content = JSON.stringify({ response, data
|
|
40
|
+
const content = JSON.stringify({ response, data });
|
|
60
41
|
const base: StepResult = { content, toolCalls: [], usage: SPENT, finishReason: 'stop', raw: null };
|
|
61
42
|
if (request.output === undefined) return base;
|
|
62
43
|
const routed = routeResponse({ content, toolCalls: [], declared: new Set(), accept: request.output.accept, responseStrategies: [] });
|
|
@@ -66,12 +47,8 @@ export const scriptedModels = (script: Script, options: { jevFails?: boolean; ke
|
|
|
66
47
|
step: async (request) => scripted(request),
|
|
67
48
|
stepStream: (request) => {
|
|
68
49
|
const result = scripted(request);
|
|
69
|
-
// In pieces, as a provider streams it, so the reply is read while it is written.
|
|
70
50
|
return (async function* () {
|
|
71
|
-
|
|
72
|
-
yield { type: 'text' as const, text: result.content.slice(at, at + 24) };
|
|
73
|
-
await new Promise((done) => setTimeout(done, 1));
|
|
74
|
-
}
|
|
51
|
+
yield { type: 'text' as const, text: result.content };
|
|
75
52
|
yield { type: 'done' as const, result };
|
|
76
53
|
})();
|
|
77
54
|
},
|
|
@@ -79,42 +56,21 @@ export const scriptedModels = (script: Script, options: { jevFails?: boolean; ke
|
|
|
79
56
|
describe: () => ({ provider: 'scripted', model: 'chat', kind: 'chat', modelKnown: false, capabilities: { nativeTools: true, nativeJsonSchema: false, nativeJsonMode: true, toolsWithStructuredOutput: false, validatesToolArgs: true, manglesNestedToolArgs: false, multimodal: false, supportsEmbedding: false } }),
|
|
80
57
|
};
|
|
81
58
|
|
|
82
|
-
const models: Models = options.keyless === true ? { missing: ['GROQ_API_KEY'] } : {
|
|
83
|
-
return { models, prompts,
|
|
59
|
+
const models: Models = options.keyless === true ? { missing: ['GROQ_API_KEY'] } : { chat: { provider: 'scripted', model: 'chat', llm: chat, timeoutMs: 5000 }, missing: [] };
|
|
60
|
+
return { models, prompts, unreachable: (is) => void (unreachable = is) };
|
|
84
61
|
};
|
|
85
62
|
|
|
86
|
-
const ShownSchema = z.looseObject({
|
|
87
|
-
question: z.string().optional(),
|
|
88
|
-
response: z.string().optional(),
|
|
89
|
-
label: z.string().optional(),
|
|
90
|
-
screen: z.string().optional(),
|
|
91
|
-
arrangement: z.string().optional(),
|
|
92
|
-
position: z.number().optional(),
|
|
93
|
-
total: z.number().optional(),
|
|
94
|
-
stack: z.array(z.looseObject({ position: z.number(), label: z.string() })).optional(),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
63
|
type Session = Awaited<ReturnType<NonNullable<MossServer['shells']>['session']>>;
|
|
98
|
-
type
|
|
64
|
+
export type Shown = { id: string; action: string; data: Record<string, unknown> };
|
|
99
65
|
|
|
100
66
|
export type App = {
|
|
101
67
|
server: MossServer;
|
|
102
68
|
session: Session;
|
|
103
69
|
runs: RunRecord[];
|
|
104
|
-
on
|
|
105
|
-
|
|
106
|
-
draw: () => void;
|
|
107
|
-
answered: () => number;
|
|
108
|
-
streamed: () => number;
|
|
109
|
-
areas: () => string;
|
|
110
|
-
ids: () => string;
|
|
111
|
-
without: (area: string, of: string) => string;
|
|
112
|
-
rows: (canvas: string, key: string) => unknown[];
|
|
113
|
-
total: () => number;
|
|
70
|
+
// What is on a canvas, in order: the screen's cards, or the conversation's turns and cards.
|
|
71
|
+
on: (canvas: 'screen' | 'talk') => Shown[];
|
|
114
72
|
said: () => string;
|
|
115
73
|
drawn: () => string;
|
|
116
|
-
grid: () => string;
|
|
117
|
-
marked: () => string;
|
|
118
74
|
ask: (text: string) => Promise<number | undefined>;
|
|
119
75
|
openScreen: (id: string) => Promise<void>;
|
|
120
76
|
};
|
|
@@ -129,79 +85,45 @@ export const startApp = async (models: Models, answerWithinMs = 5000): Promise<A
|
|
|
129
85
|
const shell = session.shell;
|
|
130
86
|
|
|
131
87
|
let answered = 0;
|
|
132
|
-
let
|
|
133
|
-
let movesWhenAnswered = 0;
|
|
88
|
+
let opened = 0;
|
|
134
89
|
shell.onEndpoint((event) => {
|
|
135
90
|
if (event.canvasId !== 'dock') return;
|
|
136
|
-
if (event.name === '
|
|
137
|
-
if (event.name === '
|
|
138
|
-
answered += 1;
|
|
139
|
-
movesWhenAnswered = moves;
|
|
140
|
-
}
|
|
91
|
+
if (event.name === 'ask') answered += 1;
|
|
92
|
+
if (event.name === 'open') opened += 1;
|
|
141
93
|
});
|
|
142
94
|
|
|
143
|
-
const on = (canvas:
|
|
144
|
-
|
|
145
|
-
|
|
95
|
+
const on = (canvas: 'screen' | 'talk'): Shown[] =>
|
|
96
|
+
(shell.getState().canvases[canvas]?.stack ?? []).map((instance) => ({ id: instance.id, action: instance.definitionId, data: shell.getRuntime(instance.id)?.getData() ?? {} }));
|
|
97
|
+
const dock = (): Record<string, unknown> => {
|
|
98
|
+
const active = shell.getState().canvases['dock']?.active;
|
|
99
|
+
return active === undefined ? {} : (shell.getRuntime(active.id)?.getData() ?? {});
|
|
146
100
|
};
|
|
147
|
-
const nodesOf = (value: unknown): Record<string, unknown>[] => (Array.isArray(value) ? value.map(recordOf) : []);
|
|
148
|
-
const named = (name: string, nodes: unknown): Record<string, unknown>[] => nodesOf(nodes).flatMap((node) => (node['name'] === name ? [node] : named(name, node['children'])));
|
|
149
|
-
const current = (): z.infer<typeof ShownSchema> => ShownSchema.safeParse(on('dock').data['current']).data ?? {};
|
|
150
101
|
// An input takes what is typed into it once it has been drawn.
|
|
151
102
|
const draw = (): void => void shell.flattenRenderTree(shell.getShellRenderTree());
|
|
152
|
-
let streamed = 0;
|
|
153
103
|
|
|
154
104
|
return {
|
|
155
105
|
server,
|
|
156
106
|
session,
|
|
157
107
|
runs,
|
|
158
108
|
on,
|
|
159
|
-
|
|
160
|
-
draw,
|
|
161
|
-
answered: () => answered,
|
|
162
|
-
streamed: () => streamed,
|
|
163
|
-
areas: () => AREAS.map((area) => on(area).action).filter((action) => action !== '').join(' '),
|
|
164
|
-
ids: () => AREAS.map((area) => `${area}:${on(area).id}`).join(' '),
|
|
165
|
-
without: (area, of) => of.replace(new RegExp(`${area}:\\S*`), ''),
|
|
166
|
-
rows: (canvas, key) => {
|
|
167
|
-
const value = on(canvas).data[key];
|
|
168
|
-
return Array.isArray(value) ? value : [];
|
|
169
|
-
},
|
|
170
|
-
total: () => Number(current().total),
|
|
171
|
-
said: () => String(on('dock').data['error'] ?? ''),
|
|
109
|
+
said: () => String(dock()['error'] ?? ''),
|
|
172
110
|
drawn: () => JSON.stringify(shell.flattenRenderTree(shell.getShellRenderTree())),
|
|
173
|
-
//
|
|
174
|
-
grid: () => {
|
|
175
|
-
const answers = named('Grid', shell.getShellRenderTree())[0] ?? {};
|
|
176
|
-
const held = nodesOf(answers['children']).map((area) => {
|
|
177
|
-
const own = recordOf(area['props']);
|
|
178
|
-
return `${String(own['name'])}${Number(own['span'] ?? 1) > 1 ? `×${String(own['span'])}` : ''}`;
|
|
179
|
-
});
|
|
180
|
-
return `${String(recordOf(answers['props'])['columns'])}: ${held.join(' ')}`;
|
|
181
|
-
},
|
|
182
|
-
marked: () =>
|
|
183
|
-
named('Area', shell.getShellRenderTree())
|
|
184
|
-
.map((area) => recordOf(area['props']))
|
|
185
|
-
.filter((props) => props['changed'] === true)
|
|
186
|
-
.map((props) => String(props['name']))
|
|
187
|
-
.join(' '),
|
|
188
|
-
// A message is answered when the line's `ask` call ends, whatever it leaves on screen: how long that took, if it did.
|
|
111
|
+
// A message is answered when the line's `ask` call ends: how long that took, if it did.
|
|
189
112
|
ask: async (text) => {
|
|
190
113
|
draw();
|
|
191
114
|
const seen = answered;
|
|
192
|
-
const movesBefore = moves;
|
|
193
115
|
const started = performance.now();
|
|
194
116
|
session.dispatch('dock', { type: 'ui:model', ref: 'text', payload: text });
|
|
195
117
|
session.dispatch('dock', { type: 'ui:key', ref: 'text', key: 'Enter' });
|
|
196
118
|
const done = await until(() => answered > seen, answerWithinMs);
|
|
197
119
|
const took = performance.now() - started;
|
|
198
|
-
streamed = movesWhenAnswered - movesBefore;
|
|
199
120
|
await settle();
|
|
200
121
|
return done ? took : undefined;
|
|
201
122
|
},
|
|
202
123
|
openScreen: async (id) => {
|
|
124
|
+
const seen = opened;
|
|
203
125
|
session.dispatch('dock', { type: 'ui:click', ref: 'screen', payload: id });
|
|
204
|
-
await until(() =>
|
|
126
|
+
await until(() => opened > seen);
|
|
205
127
|
await settle();
|
|
206
128
|
},
|
|
207
129
|
};
|
|
@@ -10,12 +10,8 @@ process.exit(
|
|
|
10
10
|
entries: ENTRIES,
|
|
11
11
|
// Every server function an action calls (an `fn:` endpoint), and what it does that a vex read or write cannot.
|
|
12
12
|
functions: {
|
|
13
|
-
ask: 'the model
|
|
14
|
-
'screens.open': 'the
|
|
15
|
-
'answers.back': 'the answers given live in the person’s shell, not in rows',
|
|
16
|
-
'answers.forward': 'the answers given live in the person’s shell, not in rows',
|
|
17
|
-
'answers.go': 'the answers given live in the person’s shell, not in rows',
|
|
18
|
-
'answers.current': 'the answers given live in the person’s shell, not in rows',
|
|
13
|
+
ask: 'the model answers a message, and the turn goes into the conversation in the person’s shell',
|
|
14
|
+
'screens.open': 'the screen shown lives in the person’s shell, not in rows',
|
|
19
15
|
},
|
|
20
16
|
// What the app is allowed, per rule, per file, each with why: { formatting: { 'src/server/today.ts': '…' } }.
|
|
21
17
|
allow: {},
|
|
@@ -4,7 +4,7 @@ import { evaluate } from '@niscorp/prism';
|
|
|
4
4
|
import { PRISM_SCHEMAS, PRISM_SEQUENCE } from '@niscorp/prism/migrations';
|
|
5
5
|
import { runSourceUpgrade } from '@niscorp/strata/node';
|
|
6
6
|
import { actions } from '../app/action-catalog';
|
|
7
|
-
import {
|
|
7
|
+
import { shell } from '../app/shell/shell';
|
|
8
8
|
import { frameLayout } from '../app/shell/frame.layout';
|
|
9
9
|
|
|
10
10
|
const root = fileURLToPath(new URL('../..', import.meta.url));
|
|
@@ -19,7 +19,7 @@ process.exit(
|
|
|
19
19
|
documents: async () => [
|
|
20
20
|
...Object.values(actions).map((document) => ({ kind: 'nisc.nova/action', id: document.id, document })),
|
|
21
21
|
{ kind: 'nisc.nova/layout', id: 'shell.frame', document: frameLayout },
|
|
22
|
-
...
|
|
22
|
+
...(shell.canvases ?? []).flatMap((canvas) => (canvas.actionLayout === undefined || typeof canvas.actionLayout === 'string' ? [] : [{ kind: 'nisc.nova/layout', id: `canvas.${canvas.id}`, document: canvas.actionLayout }])),
|
|
23
23
|
],
|
|
24
24
|
},
|
|
25
25
|
process.argv.slice(2),
|
|
@@ -3,7 +3,7 @@ import { createServer } from '@niscorp/moss';
|
|
|
3
3
|
import type { MossServer, NiscRuntime, RunSink } from '@niscorp/moss';
|
|
4
4
|
import { buildApp } from '../app/app';
|
|
5
5
|
import { APP_SEQUENCE } from '../db/schema';
|
|
6
|
-
import { composer } from './compose';
|
|
6
|
+
import { composer, firstScreen } from './compose';
|
|
7
7
|
import type { Models } from './compose';
|
|
8
8
|
import { modelsFromEnv } from './models';
|
|
9
9
|
import { logRun } from './runs';
|
|
@@ -25,5 +25,5 @@ export const runtime = async (): Promise<NiscRuntime> => ({ ...(await database()
|
|
|
25
25
|
export const app = buildApp({ functions: () => [], runs: logRun });
|
|
26
26
|
|
|
27
27
|
export const boot = async (config: BootConfig = {}): Promise<{ server: MossServer }> => ({
|
|
28
|
-
server: await createServer(buildApp({ functions: composer(config.models ?? fromEnvFile()), runs: config.runs ?? logRun }), await runtime()),
|
|
28
|
+
server: await createServer(buildApp({ functions: composer(config.models ?? fromEnvFile()), runs: config.runs ?? logRun, seeds: firstScreen }), await runtime()),
|
|
29
29
|
});
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ActionDefinition } from '@niscorp/nova';
|
|
3
|
-
import type { SeedEntry, SeedMutation } from '@niscorp/vex';
|
|
4
3
|
import { placeable } from '../../app/action-catalog';
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
7
|
-
import { isRecord, recordOf } from './record';
|
|
4
|
+
import type { Card } from '../../app/screens';
|
|
5
|
+
import { recordOf } from './record';
|
|
8
6
|
|
|
9
7
|
type Placeable = { id: string; description: string; schema: Record<string, unknown>; check: z.ZodType; defaults: Record<string, unknown> };
|
|
10
|
-
type
|
|
11
|
-
type Write = { fingerprint: string; intent: string; contextKeys: string[] };
|
|
12
|
-
export type Catalog = { actions: Placeable[]; reads: Read[]; writes: Write[] };
|
|
13
|
-
|
|
14
|
-
// An action that declares no input is opened with none.
|
|
15
|
-
const NO_INPUT = z.toJSONSchema(z.object({}).strict());
|
|
8
|
+
export type Catalog = { actions: Placeable[] };
|
|
16
9
|
|
|
17
10
|
export const inputKeysOf = (schema: unknown): string[] => Object.keys(recordOf(recordOf(schema)['properties']));
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!isRecord(node)) return [];
|
|
22
|
-
const named = node['$context'];
|
|
23
|
-
return typeof named === 'string' ? [named] : Object.values(node).flatMap(contextOf);
|
|
24
|
-
};
|
|
12
|
+
// An action that declares no input is opened with none.
|
|
13
|
+
const NO_INPUT = z.toJSONSchema(z.object({}).strict());
|
|
25
14
|
|
|
26
15
|
const placeableOf = (action: ActionDefinition): Placeable => {
|
|
27
16
|
const schema = action.input ?? NO_INPUT;
|
|
@@ -30,17 +19,10 @@ const placeableOf = (action: ActionDefinition): Placeable => {
|
|
|
30
19
|
return { id: action.id, description: action.description ?? '', schema, check: z.fromJSONSchema(schema), defaults };
|
|
31
20
|
};
|
|
32
21
|
|
|
33
|
-
// A
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...
|
|
37
|
-
input: { ...catalog.actions.find((action) => action.id === canvas.action)?.defaults, ...Object.fromEntries(Object.entries(canvas.input).filter(([, value]) => value !== null)) },
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const catalogOf = (actions: readonly ActionDefinition[], entries: readonly (SeedEntry | SeedMutation)[]): Catalog => ({
|
|
41
|
-
actions: actions.map(placeableOf),
|
|
42
|
-
reads: entries.flatMap((entry) => ('dsl' in entry ? [{ fingerprint: entry.fingerprint, intent: entry.intent ?? '', shape: entry.shape, contextKeys: [...new Set(contextOf(entry.dsl))] }] : [])),
|
|
43
|
-
writes: entries.flatMap((entry) => ('mutation' in entry ? [{ fingerprint: entry.fingerprint, intent: entry.intent ?? '', contextKeys: [...new Set(contextOf(entry.mutation))] }] : [])),
|
|
22
|
+
// A card is opened with its whole input: what the model leaves out, or says is null, is its action's default.
|
|
23
|
+
export const opened = (card: Card, catalog: Catalog): Card => ({
|
|
24
|
+
...card,
|
|
25
|
+
input: { ...catalog.actions.find((action) => action.id === card.action)?.defaults, ...Object.fromEntries(Object.entries(card.input).filter(([, value]) => value !== null)) },
|
|
44
26
|
});
|
|
45
27
|
|
|
46
|
-
export const CATALOG: Catalog =
|
|
28
|
+
export const CATALOG: Catalog = { actions: placeable.map(placeableOf) };
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { defineAgent } from '@niscorp/cortex';
|
|
1
|
+
import { defineAgent, outputRetries, stepCount } from '@niscorp/cortex';
|
|
2
2
|
import type { AgentDefinition, OutputValidator } from '@niscorp/cortex';
|
|
3
|
-
import {
|
|
3
|
+
import { cardCatalog, INSTRUCTIONS } from './knowledge';
|
|
4
4
|
import type { ComposerDeps } from './knowledge';
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
5
|
+
import { TurnSchema } from './turn.schema';
|
|
6
|
+
import type { Turn } from './turn.schema';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
defineAgent<Reply, ComposerDeps>({
|
|
8
|
+
export const composerAgent = (validate: OutputValidator<Turn>): AgentDefinition<Turn, ComposerDeps> =>
|
|
9
|
+
defineAgent<Turn, ComposerDeps>({
|
|
11
10
|
id: 'nisc-template-app.compose',
|
|
12
|
-
description: 'Answers a message with a
|
|
11
|
+
description: 'Answers a message with a turn of the conversation: a sentence, and the app’s own cards that show the answer.',
|
|
13
12
|
instructions: INSTRUCTIONS,
|
|
14
|
-
context: [
|
|
13
|
+
context: [cardCatalog],
|
|
15
14
|
// An agent with no tools on Groq would be sent the envelope as Groq's loose JSON schema, and gpt-oss answers this one
|
|
16
|
-
// worse there: emit carries the contract in the prompt
|
|
17
|
-
output: { schema:
|
|
15
|
+
// worse there: emit carries the contract in the prompt.
|
|
16
|
+
output: { schema: TurnSchema, response: 'required', strategy: 'emit', validate },
|
|
17
|
+
// gpt-oss now and then answers with its reasoning alone, which counts as a refused answer: five tries, each about a
|
|
18
|
+
// second, inside the chat model's budget.
|
|
19
|
+
stopWhen: [stepCount(8), outputRetries(5)],
|
|
18
20
|
});
|