@praudent/dagma 0.0.0-stage → 0.1.1
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/dist/admin-ui/assets/index-CHJ8lsZp.js +120 -0
- package/dist/admin-ui/assets/index-XyqtD-IA.css +1 -0
- package/dist/admin-ui/index.html +12 -0
- package/dist/blueprint/agent.d.ts +148 -0
- package/dist/blueprint/agent.js +1 -0
- package/dist/blueprint/declaration-site.d.ts +7 -0
- package/dist/blueprint/declaration-site.js +8 -0
- package/dist/blueprint/declared-structure.d.ts +145 -0
- package/dist/blueprint/declared-structure.js +213 -0
- package/dist/blueprint/define-run-state.d.ts +79 -0
- package/dist/blueprint/define-run-state.js +89 -0
- package/dist/blueprint/load-blueprint.d.ts +28 -0
- package/dist/blueprint/load-blueprint.js +85 -0
- package/dist/blueprint/outcomes.d.ts +76 -0
- package/dist/blueprint/outcomes.js +10 -0
- package/dist/blueprint/phase.d.ts +153 -0
- package/dist/blueprint/phase.js +1 -0
- package/dist/blueprint/places.d.ts +26 -0
- package/dist/blueprint/places.js +37 -0
- package/dist/blueprint/prompt-file.d.ts +81 -0
- package/dist/blueprint/prompt-file.js +131 -0
- package/dist/blueprint/reply-reader.d.ts +36 -0
- package/dist/blueprint/reply-reader.js +38 -0
- package/dist/blueprint/run-settings.d.ts +38 -0
- package/dist/blueprint/run-settings.js +1 -0
- package/dist/blueprint/serializer.d.ts +14 -0
- package/dist/blueprint/serializer.js +4 -0
- package/dist/blueprint/write-scope.d.ts +39 -0
- package/dist/blueprint/write-scope.js +106 -0
- package/dist/command.d.ts +2 -0
- package/dist/command.js +148 -0
- package/dist/commands/calls-answering.d.ts +16 -0
- package/dist/commands/calls-answering.js +63 -0
- package/dist/commands/json-file.d.ts +6 -0
- package/dist/commands/json-file.js +19 -0
- package/dist/commands/run-command.d.ts +23 -0
- package/dist/commands/run-command.js +172 -0
- package/dist/commands/typed-answers.d.ts +10 -0
- package/dist/commands/typed-answers.js +43 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +20 -0
- package/dist/devtool-server/app-pages.d.ts +12 -0
- package/dist/devtool-server/app-pages.js +68 -0
- package/dist/devtool-server/blueprint-description.d.ts +21 -0
- package/dist/devtool-server/blueprint-description.js +27 -0
- package/dist/devtool-server/connected-runs.d.ts +36 -0
- package/dist/devtool-server/connected-runs.js +201 -0
- package/dist/devtool-server/devtool-server.d.ts +17 -0
- package/dist/devtool-server/devtool-server.js +294 -0
- package/dist/devtool-server/devtool-shapes.d.ts +312 -0
- package/dist/devtool-server/devtool-shapes.js +24 -0
- package/dist/devtool-server/listed-runs.d.ts +17 -0
- package/dist/devtool-server/listed-runs.js +42 -0
- package/dist/devtool-server/print-blueprint.d.ts +1 -0
- package/dist/devtool-server/print-blueprint.js +36 -0
- package/dist/example/added-species.d.ts +21 -0
- package/dist/example/added-species.js +19 -0
- package/dist/example/cover.d.ts +21 -0
- package/dist/example/cover.js +67 -0
- package/dist/example/cross-references.d.ts +21 -0
- package/dist/example/cross-references.js +77 -0
- package/dist/example/entry-drafts.d.ts +21 -0
- package/dist/example/entry-drafts.js +63 -0
- package/dist/example/entry-merge.d.ts +108 -0
- package/dist/example/entry-merge.js +284 -0
- package/dist/example/field-guide.d.ts +26 -0
- package/dist/example/field-guide.js +40 -0
- package/dist/example/guide-page.d.ts +21 -0
- package/dist/example/guide-page.js +15 -0
- package/dist/example/missing-species.d.ts +21 -0
- package/dist/example/missing-species.js +59 -0
- package/dist/example/run-state.d.ts +803 -0
- package/dist/example/run-state.js +58 -0
- package/dist/example/serializers.d.ts +32 -0
- package/dist/example/serializers.js +42 -0
- package/dist/example/species-list.d.ts +47 -0
- package/dist/example/species-list.js +93 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +25 -0
- package/dist/inference/anthropic-api.d.ts +37 -0
- package/dist/inference/anthropic-api.js +197 -0
- package/dist/inference/anthropic-prices.d.ts +18 -0
- package/dist/inference/anthropic-prices.js +61 -0
- package/dist/inference/anthropic-request.d.ts +51 -0
- package/dist/inference/anthropic-request.js +208 -0
- package/dist/inference/bedrock-api.d.ts +45 -0
- package/dist/inference/bedrock-api.js +242 -0
- package/dist/inference/bedrock-prices.d.ts +22 -0
- package/dist/inference/bedrock-prices.js +79 -0
- package/dist/inference/bedrock-request.d.ts +27 -0
- package/dist/inference/bedrock-request.js +193 -0
- package/dist/inference/call-queue-shapes.d.ts +273 -0
- package/dist/inference/call-queue-shapes.js +82 -0
- package/dist/inference/call-queue.d.ts +109 -0
- package/dist/inference/call-queue.js +408 -0
- package/dist/inference/gemini-api.d.ts +44 -0
- package/dist/inference/gemini-api.js +191 -0
- package/dist/inference/gemini-prices.d.ts +19 -0
- package/dist/inference/gemini-prices.js +33 -0
- package/dist/inference/gemini-request.d.ts +25 -0
- package/dist/inference/gemini-request.js +126 -0
- package/dist/inference/inference.d.ts +84 -0
- package/dist/inference/inference.js +9 -0
- package/dist/inference/openai-api.d.ts +29 -0
- package/dist/inference/openai-api.js +138 -0
- package/dist/inference/openai-prices.d.ts +12 -0
- package/dist/inference/openai-prices.js +25 -0
- package/dist/inference/openai-request.d.ts +50 -0
- package/dist/inference/openai-request.js +100 -0
- package/dist/inference/own-worker.d.ts +6 -0
- package/dist/inference/own-worker.js +16 -0
- package/dist/inference/scripted.d.ts +146 -0
- package/dist/inference/scripted.js +67 -0
- package/dist/run/assignments/agent-call.d.ts +32 -0
- package/dist/run/assignments/agent-call.js +218 -0
- package/dist/run/assignments/agent-phase.d.ts +14 -0
- package/dist/run/assignments/agent-phase.js +243 -0
- package/dist/run/assignments/assignment-memory.d.ts +42 -0
- package/dist/run/assignments/assignment-memory.js +52 -0
- package/dist/run/assignments/assignment.d.ts +17 -0
- package/dist/run/assignments/assignment.js +252 -0
- package/dist/run/assignments/model-settings.d.ts +39 -0
- package/dist/run/assignments/model-settings.js +57 -0
- package/dist/run/assignments/prepared-call.d.ts +28 -0
- package/dist/run/assignments/prepared-call.js +115 -0
- package/dist/run/assignments/tool-call.d.ts +26 -0
- package/dist/run/assignments/tool-call.js +108 -0
- package/dist/run/blueprint-mistake.d.ts +8 -0
- package/dist/run/blueprint-mistake.js +14 -0
- package/dist/run/code-phase.d.ts +11 -0
- package/dist/run/code-phase.js +59 -0
- package/dist/run/create-run.d.ts +36 -0
- package/dist/run/create-run.js +119 -0
- package/dist/run/execute-run.d.ts +7 -0
- package/dist/run/execute-run.js +158 -0
- package/dist/run/record/apply-event.d.ts +13 -0
- package/dist/run/record/apply-event.js +256 -0
- package/dist/run/record/events.d.ts +187 -0
- package/dist/run/record/events.js +1 -0
- package/dist/run/record/postgres-run-store.d.ts +13 -0
- package/dist/run/record/postgres-run-store.js +189 -0
- package/dist/run/record/progress-projection.d.ts +83 -0
- package/dist/run/record/progress-projection.js +167 -0
- package/dist/run/record/progress.d.ts +207 -0
- package/dist/run/record/progress.js +63 -0
- package/dist/run/record/run-store.d.ts +74 -0
- package/dist/run/record/run-store.js +1 -0
- package/dist/run/record/run-summary.d.ts +8 -0
- package/dist/run/record/run-summary.js +19 -0
- package/dist/run/record/run-types.d.ts +95 -0
- package/dist/run/record/run-types.js +1 -0
- package/dist/run/record/state-changes.d.ts +42 -0
- package/dist/run/record/state-changes.js +157 -0
- package/dist/run/resume-run.d.ts +25 -0
- package/dist/run/resume-run.js +99 -0
- package/dist/run/run-endings.d.ts +20 -0
- package/dist/run/run-endings.js +20 -0
- package/dist/run/run-option-shapes.d.ts +176 -0
- package/dist/run/run-option-shapes.js +47 -0
- package/dist/run/run-session.d.ts +144 -0
- package/dist/run/run-session.js +278 -0
- package/dist/worker/answer-queued-call.d.ts +19 -0
- package/dist/worker/answer-queued-call.js +100 -0
- package/dist/worker/launchers/claude-code.d.ts +7 -0
- package/dist/worker/launchers/claude-code.js +156 -0
- package/dist/worker/launchers/codex.d.ts +6 -0
- package/dist/worker/launchers/codex.js +141 -0
- package/dist/worker/launchers/launch.d.ts +31 -0
- package/dist/worker/launchers/launch.js +6 -0
- package/dist/worker/launchers/program-run.d.ts +30 -0
- package/dist/worker/launchers/program-run.js +92 -0
- package/dist/worker/launchers/tool-server.d.ts +26 -0
- package/dist/worker/launchers/tool-server.js +90 -0
- package/dist/worker/worker.d.ts +13 -0
- package/dist/worker/worker.js +170 -0
- package/package.json +43 -4
- package/README.md +0 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const INPUT_TEXT_LENGTH = 200;
|
|
2
|
+
/** The texts and numbers an input holds, in the order written, in one line cut short. */
|
|
3
|
+
export function inputInOneLine({ input }) {
|
|
4
|
+
const values = [];
|
|
5
|
+
let length = 0;
|
|
6
|
+
const collect = (value) => {
|
|
7
|
+
if (length > INPUT_TEXT_LENGTH)
|
|
8
|
+
return;
|
|
9
|
+
if (value !== null && typeof value === 'object')
|
|
10
|
+
return Object.values(value).forEach(collect);
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return;
|
|
13
|
+
const text = String(value);
|
|
14
|
+
values.push(text);
|
|
15
|
+
length += text.length;
|
|
16
|
+
};
|
|
17
|
+
collect(input);
|
|
18
|
+
const line = values.join(', ').replace(/\s+/g, ' ');
|
|
19
|
+
return line.length > INPUT_TEXT_LENGTH ? `${line.slice(0, INPUT_TEXT_LENGTH)}…` : line;
|
|
20
|
+
}
|
|
21
|
+
/** One run's row, read from the store; undefined when no run with this id exists. */
|
|
22
|
+
export async function listedRun({ store, runId, }) {
|
|
23
|
+
const summary = await store.readRunSummary({ runId });
|
|
24
|
+
if (!summary)
|
|
25
|
+
return undefined;
|
|
26
|
+
const input = await store.readInput({ runId }).catch(() => undefined);
|
|
27
|
+
return {
|
|
28
|
+
summary,
|
|
29
|
+
inputText: inputInOneLine({ input }),
|
|
30
|
+
connected: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Every run in the store, newest first. `connectedRows` are the rows of the runs the devtool
|
|
34
|
+
* is connected to, which are more current than their stored summaries. */
|
|
35
|
+
export async function listedRuns({ store, connectedRows, }) {
|
|
36
|
+
const stored = await store.listRunSummaries();
|
|
37
|
+
return stored.map(({ summary, input }) => connectedRows.find((row) => row.summary.runId === summary.runId) ?? {
|
|
38
|
+
summary,
|
|
39
|
+
inputText: inputInOneLine({ input }),
|
|
40
|
+
connected: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
|
+
import { loadBlueprint } from '../blueprint/load-blueprint.js';
|
|
4
|
+
import { BLUEPRINT_LINE_MARK } from './blueprint-description.js';
|
|
5
|
+
/** A short process of its own: reads the blueprint file named as its argument and prints it as
|
|
6
|
+
* plain data on one marked line. The devtool starts it each time it needs the blueprint, so
|
|
7
|
+
* edited files always take effect. With a second argument, a file holding a run input as JSON,
|
|
8
|
+
* the line also says what keeps that input from fitting the blueprint's input shape. */
|
|
9
|
+
async function printBlueprint() {
|
|
10
|
+
const [file, inputFile] = process.argv.slice(2);
|
|
11
|
+
if (!file)
|
|
12
|
+
throw new Error('Name the blueprint file to read.');
|
|
13
|
+
const loaded = await loadBlueprint({ file });
|
|
14
|
+
const checked = inputFile
|
|
15
|
+
? loaded.blueprint.input.safeParse(JSON.parse(await readFile(inputFile, 'utf8')))
|
|
16
|
+
: undefined;
|
|
17
|
+
const description = {
|
|
18
|
+
structure: loaded.structure,
|
|
19
|
+
hash: loaded.hash,
|
|
20
|
+
inputSchema: zodToJsonSchema(loaded.blueprint.input, { $refStrategy: 'none' }),
|
|
21
|
+
loadedAt: new Date().toISOString(),
|
|
22
|
+
...(checked
|
|
23
|
+
? {
|
|
24
|
+
inputProblems: checked.success
|
|
25
|
+
? []
|
|
26
|
+
: checked.error.issues.map((issue) => `${issue.path.join('.') || 'input'}: ${issue.message}`),
|
|
27
|
+
}
|
|
28
|
+
: {}),
|
|
29
|
+
};
|
|
30
|
+
// The blueprint's own files may print while they load; the marked line is the last one.
|
|
31
|
+
process.stdout.write(`\n${BLUEPRINT_LINE_MARK}${JSON.stringify(description)}\n`);
|
|
32
|
+
}
|
|
33
|
+
printBlueprint().catch((error) => {
|
|
34
|
+
console.error(error instanceof Error ? error.message : error);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const addedSpecies: import("../blueprint/phase.js").SideLine<{
|
|
2
|
+
entries: {
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
speciesId: string;
|
|
6
|
+
mentions: string[];
|
|
7
|
+
seeAlso: string[] | null;
|
|
8
|
+
}[];
|
|
9
|
+
topic: string;
|
|
10
|
+
species: {
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
subspecies: string[];
|
|
14
|
+
}[];
|
|
15
|
+
drafts: {
|
|
16
|
+
text: string;
|
|
17
|
+
speciesId: string;
|
|
18
|
+
}[];
|
|
19
|
+
missingSpecies: string[];
|
|
20
|
+
title: string | null;
|
|
21
|
+
}, unknown>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { entryDrafts } from './entry-drafts.js';
|
|
2
|
+
import { entryMerge } from './entry-merge.js';
|
|
3
|
+
import { defineSideLine, speciesNotStarted } from './run-state.js';
|
|
4
|
+
// added-species: a side line beside entry-merge and missing-species, the two trunk phases that
|
|
5
|
+
// can add a species to the list after the drafts were written: an entry may mention a species
|
|
6
|
+
// the guide does not list, and the gap finder may name one. Shows: a side line that can be
|
|
7
|
+
// entered from more than one trunk phase, and more than once in a run. Each visit drafts and
|
|
8
|
+
// merges only the species added since, with the two phases the trunk already has.
|
|
9
|
+
export const addedSpecies = defineSideLine({
|
|
10
|
+
name: 'added-species',
|
|
11
|
+
description: 'Writes the entries of the species added to the list after the drafts were written.',
|
|
12
|
+
beside: ['entry-merge', 'missing-species'],
|
|
13
|
+
entersWhen: {
|
|
14
|
+
description: 'A species on the list has neither a draft nor an entry.',
|
|
15
|
+
test: ({ state }) => speciesNotStarted({ state }).length > 0,
|
|
16
|
+
},
|
|
17
|
+
atMost: 3,
|
|
18
|
+
phases: [entryDrafts, entryMerge],
|
|
19
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const cover: import("../index.js").Phase<{
|
|
2
|
+
entries: {
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
speciesId: string;
|
|
6
|
+
mentions: string[];
|
|
7
|
+
seeAlso: string[] | null;
|
|
8
|
+
}[];
|
|
9
|
+
topic: string;
|
|
10
|
+
species: {
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
subspecies: string[];
|
|
14
|
+
}[];
|
|
15
|
+
drafts: {
|
|
16
|
+
text: string;
|
|
17
|
+
speciesId: string;
|
|
18
|
+
}[];
|
|
19
|
+
missingSpecies: string[];
|
|
20
|
+
title: string | null;
|
|
21
|
+
}, unknown>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { jsonReply, sendBack } from '../index.js';
|
|
3
|
+
import { accept, ask, defineAgent, defineAgentPhase } from './run-state.js';
|
|
4
|
+
import { correctionText, jsonReplyCorrection, namesText, topicText } from './serializers.js';
|
|
5
|
+
// cover: once, only when the guide has an entry; cover-author.
|
|
6
|
+
// Shows: proposes three titles and asks the person to choose, with a recommendation; the outcome
|
|
7
|
+
// saves the choice without another call.
|
|
8
|
+
const coverAuthor = defineAgent({
|
|
9
|
+
name: 'cover-author',
|
|
10
|
+
description: 'Proposes three titles for the guide and recommends one.',
|
|
11
|
+
prompt: 'cover-author.md',
|
|
12
|
+
inputs: {
|
|
13
|
+
topic: {
|
|
14
|
+
description: 'The topic the person gave.',
|
|
15
|
+
serializer: topicText,
|
|
16
|
+
from: ({ state }) => ({ topic: state.topic }),
|
|
17
|
+
},
|
|
18
|
+
species: {
|
|
19
|
+
description: 'Every species of the guide.',
|
|
20
|
+
serializer: namesText,
|
|
21
|
+
from: ({ state }) => ({ names: state.species.map((species) => species.name) }),
|
|
22
|
+
},
|
|
23
|
+
correction: {
|
|
24
|
+
description: 'The reply that was sent back and why, on a call after one.',
|
|
25
|
+
serializer: correctionText,
|
|
26
|
+
from: ({ correction }) => ({ correction }),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
replyReader: jsonReply({
|
|
30
|
+
schema: z
|
|
31
|
+
.object({ titles: z.string().array(), recommended: z.string(), reason: z.string() })
|
|
32
|
+
.strict(),
|
|
33
|
+
correctionFor: jsonReplyCorrection,
|
|
34
|
+
}),
|
|
35
|
+
replyOutcome: {
|
|
36
|
+
description: 'Proposes exactly three titles and recommends one of them. The person chooses; the chosen title is saved.',
|
|
37
|
+
decide: ({ reply, answers }) => {
|
|
38
|
+
if (reply.titles.length !== 3 || !reply.titles.includes(reply.recommended))
|
|
39
|
+
return sendBack({ correction: 'Propose exactly three titles and recommend one of them.' });
|
|
40
|
+
// Runs a second time on the same reply once the person has answered: no second model call.
|
|
41
|
+
const [chosen] = answers;
|
|
42
|
+
if (chosen)
|
|
43
|
+
return accept({ change: (current) => ({ ...current, title: chosen.answer }) });
|
|
44
|
+
return ask({
|
|
45
|
+
questions: [
|
|
46
|
+
{
|
|
47
|
+
text: 'Which title should the guide have?',
|
|
48
|
+
choices: reply.titles,
|
|
49
|
+
recommended: { choice: reply.recommended, reason: reply.reason },
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
maxCorrections: 1,
|
|
56
|
+
asks: 'Which of the three proposed titles the guide should have.',
|
|
57
|
+
});
|
|
58
|
+
export const cover = defineAgentPhase({
|
|
59
|
+
name: 'cover',
|
|
60
|
+
description: 'Proposes titles and asks the person to choose one.',
|
|
61
|
+
assignments: 'once',
|
|
62
|
+
onlyWhen: {
|
|
63
|
+
description: 'The guide has an entry.',
|
|
64
|
+
test: ({ state }) => state.entries.length > 0,
|
|
65
|
+
},
|
|
66
|
+
chain: [coverAuthor],
|
|
67
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const crossReferences: import("../index.js").Phase<{
|
|
2
|
+
entries: {
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
speciesId: string;
|
|
6
|
+
mentions: string[];
|
|
7
|
+
seeAlso: string[] | null;
|
|
8
|
+
}[];
|
|
9
|
+
topic: string;
|
|
10
|
+
species: {
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
subspecies: string[];
|
|
14
|
+
}[];
|
|
15
|
+
drafts: {
|
|
16
|
+
text: string;
|
|
17
|
+
speciesId: string;
|
|
18
|
+
}[];
|
|
19
|
+
missingSpecies: string[];
|
|
20
|
+
title: string | null;
|
|
21
|
+
}, unknown>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { jsonReply, sendBack } from '../index.js';
|
|
3
|
+
import { accept, defineAgent, defineAgentPhase, entriesMentionedBefore, EntrySchema, } from './run-state.js';
|
|
4
|
+
import { correctionText, entriesText, jsonReplyCorrection } from './serializers.js';
|
|
5
|
+
// cross-references: per entry that mentions another, 4 at once; an entry waits until every entry
|
|
6
|
+
// it mentions earlier in the list has its "see also" list; cross-referencer.
|
|
7
|
+
// Shows: a wait; no assignments when nothing is mentioned.
|
|
8
|
+
const crossReferencer = defineAgent({
|
|
9
|
+
name: 'cross-referencer',
|
|
10
|
+
description: 'Writes the "see also" list of its entry.',
|
|
11
|
+
subject: EntrySchema,
|
|
12
|
+
prompt: 'cross-referencer.md',
|
|
13
|
+
inputs: {
|
|
14
|
+
entry: {
|
|
15
|
+
description: 'The entry this list is for.',
|
|
16
|
+
serializer: entriesText,
|
|
17
|
+
from: ({ subject }) => ({ entries: [subject] }),
|
|
18
|
+
},
|
|
19
|
+
mentioned: {
|
|
20
|
+
description: 'The entries this entry mentions, as they stand now.',
|
|
21
|
+
serializer: entriesText,
|
|
22
|
+
from: ({ state, subject }) => ({
|
|
23
|
+
entries: state.entries.filter((entry) => subject.mentions.includes(entry.name)),
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
correction: {
|
|
27
|
+
description: 'The reply that was sent back and why, on a call after one.',
|
|
28
|
+
serializer: correctionText,
|
|
29
|
+
from: ({ correction }) => ({ correction }),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
replyReader: jsonReply({
|
|
33
|
+
schema: z.object({ seeAlso: z.string().array() }).strict(),
|
|
34
|
+
correctionFor: jsonReplyCorrection,
|
|
35
|
+
}),
|
|
36
|
+
replyOutcome: {
|
|
37
|
+
description: 'Every name is an entry of the guide, and no entry it mentions was rewritten while it worked. Changes only this entry\'s "see also" list.',
|
|
38
|
+
decide: ({ reply, state, stateAtPrompt, subject }) => {
|
|
39
|
+
const unknownNames = reply.seeAlso.filter((name) => !state.entries.some((entry) => entry.name === name));
|
|
40
|
+
if (unknownNames.length)
|
|
41
|
+
return sendBack({ correction: `These are not entries: ${unknownNames.join(', ')}.` });
|
|
42
|
+
const rewritten = state.entries.filter((entry) => subject.mentions.includes(entry.name) &&
|
|
43
|
+
stateAtPrompt.entries.find((before) => before.speciesId === entry.speciesId)?.text !==
|
|
44
|
+
entry.text);
|
|
45
|
+
if (rewritten.length)
|
|
46
|
+
return sendBack({
|
|
47
|
+
correction: `These entries changed: ${rewritten.map((entry) => entry.name).join(', ')}.`,
|
|
48
|
+
});
|
|
49
|
+
return accept({
|
|
50
|
+
change: (current) => ({
|
|
51
|
+
...current,
|
|
52
|
+
entries: current.entries.map((entry) => entry.speciesId === subject.speciesId ? { ...entry, seeAlso: reply.seeAlso } : entry),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
maxCorrections: 2,
|
|
58
|
+
});
|
|
59
|
+
export const crossReferences = defineAgentPhase({
|
|
60
|
+
name: 'cross-references',
|
|
61
|
+
description: 'Gives every entry that mentions another its "see also" list.',
|
|
62
|
+
assignments: {
|
|
63
|
+
forEach: {
|
|
64
|
+
description: 'One per entry that mentions another and has no "see also" list.',
|
|
65
|
+
subjectName: 'entry',
|
|
66
|
+
subjects: ({ state }) => state.entries
|
|
67
|
+
.filter((entry) => entry.mentions.length > 0 && entry.seeAlso === null)
|
|
68
|
+
.map((entry) => ({ key: entry.speciesId, label: entry.name, subject: entry })),
|
|
69
|
+
},
|
|
70
|
+
concurrency: 4,
|
|
71
|
+
startsWhen: {
|
|
72
|
+
description: 'An entry waits until every entry it mentions earlier in the list has its "see also" list.',
|
|
73
|
+
test: ({ state, subject }) => entriesMentionedBefore({ state, entry: subject }).every((entry) => entry.mentions.length === 0 || entry.seeAlso !== null),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
chain: [crossReferencer],
|
|
77
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const entryDrafts: import("../index.js").Phase<{
|
|
2
|
+
entries: {
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
speciesId: string;
|
|
6
|
+
mentions: string[];
|
|
7
|
+
seeAlso: string[] | null;
|
|
8
|
+
}[];
|
|
9
|
+
topic: string;
|
|
10
|
+
species: {
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
subspecies: string[];
|
|
14
|
+
}[];
|
|
15
|
+
drafts: {
|
|
16
|
+
text: string;
|
|
17
|
+
speciesId: string;
|
|
18
|
+
}[];
|
|
19
|
+
missingSpecies: string[];
|
|
20
|
+
title: string | null;
|
|
21
|
+
}, unknown>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { sendBack } from '../index.js';
|
|
2
|
+
import { accept, defineAgent, defineAgentPhase, SpeciesSchema, speciesWithoutEntry, } from './run-state.js';
|
|
3
|
+
import { correctionText, draftAngleText, speciesText } from './serializers.js';
|
|
4
|
+
// entry-drafts: per species without an entry, 2 repeats, 8 at once; entry-drafter.
|
|
5
|
+
// Shows: repeats, parallel work, no reviewer; the drafter answers in plain text read by its own
|
|
6
|
+
// reader. It stands on the trunk and on the side line added-species.
|
|
7
|
+
const entryDrafter = defineAgent({
|
|
8
|
+
name: 'entry-drafter',
|
|
9
|
+
description: 'Writes one draft of the entry for its species.',
|
|
10
|
+
subject: SpeciesSchema,
|
|
11
|
+
prompt: 'entry-drafter.md',
|
|
12
|
+
inputs: {
|
|
13
|
+
species: {
|
|
14
|
+
description: 'The species this draft is for.',
|
|
15
|
+
serializer: speciesText,
|
|
16
|
+
from: ({ subject }) => ({ species: subject }),
|
|
17
|
+
},
|
|
18
|
+
angle: {
|
|
19
|
+
description: 'Which of the two drafts this is.',
|
|
20
|
+
serializer: draftAngleText,
|
|
21
|
+
from: ({ repeat }) => ({ repeat }),
|
|
22
|
+
},
|
|
23
|
+
correction: {
|
|
24
|
+
description: 'The reply that was sent back and why, on a call after one.',
|
|
25
|
+
serializer: correctionText,
|
|
26
|
+
from: ({ correction }) => ({ correction }),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
// The agent's own reader: the reply is plain text and the whole of it is the draft.
|
|
30
|
+
replyReader: {
|
|
31
|
+
description: 'The whole reply is the draft. An empty reply is sent back.',
|
|
32
|
+
read: ({ replyText }) => replyText.trim() || sendBack({ correction: 'Write the draft.' }),
|
|
33
|
+
},
|
|
34
|
+
replyOutcome: {
|
|
35
|
+
description: 'Any draft is kept. Adds one draft of this species.',
|
|
36
|
+
decide: ({ reply, subject }) => accept({
|
|
37
|
+
change: (current) => ({
|
|
38
|
+
...current,
|
|
39
|
+
drafts: [...current.drafts, { speciesId: subject.id, text: reply }],
|
|
40
|
+
}),
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
maxCorrections: 1,
|
|
44
|
+
modelSettings: { effort: 'low' },
|
|
45
|
+
});
|
|
46
|
+
export const entryDrafts = defineAgentPhase({
|
|
47
|
+
name: 'entry-drafts',
|
|
48
|
+
description: 'Drafts every entry twice, each draft written without seeing the other.',
|
|
49
|
+
assignments: {
|
|
50
|
+
forEach: {
|
|
51
|
+
description: 'One per species without a merged entry.',
|
|
52
|
+
subjectName: 'species',
|
|
53
|
+
subjects: ({ state }) => speciesWithoutEntry({ state }).map((species) => ({
|
|
54
|
+
key: species.id,
|
|
55
|
+
label: species.name,
|
|
56
|
+
subject: species,
|
|
57
|
+
})),
|
|
58
|
+
},
|
|
59
|
+
repeats: 2,
|
|
60
|
+
concurrency: 8,
|
|
61
|
+
},
|
|
62
|
+
chain: [entryDrafter],
|
|
63
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export declare const entryMerger: import("../index.js").Agent<{
|
|
2
|
+
entries: {
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
speciesId: string;
|
|
6
|
+
mentions: string[];
|
|
7
|
+
seeAlso: string[] | null;
|
|
8
|
+
}[];
|
|
9
|
+
topic: string;
|
|
10
|
+
species: {
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
subspecies: string[];
|
|
14
|
+
}[];
|
|
15
|
+
drafts: {
|
|
16
|
+
text: string;
|
|
17
|
+
speciesId: string;
|
|
18
|
+
}[];
|
|
19
|
+
missingSpecies: string[];
|
|
20
|
+
title: string | null;
|
|
21
|
+
}, {
|
|
22
|
+
name: string;
|
|
23
|
+
id: string;
|
|
24
|
+
subspecies: string[];
|
|
25
|
+
}, {
|
|
26
|
+
text: string;
|
|
27
|
+
mentions: string[];
|
|
28
|
+
}>;
|
|
29
|
+
export declare const subspeciesMerger: import("../index.js").Agent<{
|
|
30
|
+
entries: {
|
|
31
|
+
name: string;
|
|
32
|
+
text: string;
|
|
33
|
+
speciesId: string;
|
|
34
|
+
mentions: string[];
|
|
35
|
+
seeAlso: string[] | null;
|
|
36
|
+
}[];
|
|
37
|
+
topic: string;
|
|
38
|
+
species: {
|
|
39
|
+
name: string;
|
|
40
|
+
id: string;
|
|
41
|
+
subspecies: string[];
|
|
42
|
+
}[];
|
|
43
|
+
drafts: {
|
|
44
|
+
text: string;
|
|
45
|
+
speciesId: string;
|
|
46
|
+
}[];
|
|
47
|
+
missingSpecies: string[];
|
|
48
|
+
title: string | null;
|
|
49
|
+
}, {
|
|
50
|
+
name: string;
|
|
51
|
+
id: string;
|
|
52
|
+
subspecies: string[];
|
|
53
|
+
}, {
|
|
54
|
+
text: string;
|
|
55
|
+
mentions: string[];
|
|
56
|
+
subspeciesDrafts: {
|
|
57
|
+
name: string;
|
|
58
|
+
text: string;
|
|
59
|
+
}[];
|
|
60
|
+
}>;
|
|
61
|
+
export declare const entryReviewer: import("../index.js").Agent<{
|
|
62
|
+
entries: {
|
|
63
|
+
name: string;
|
|
64
|
+
text: string;
|
|
65
|
+
speciesId: string;
|
|
66
|
+
mentions: string[];
|
|
67
|
+
seeAlso: string[] | null;
|
|
68
|
+
}[];
|
|
69
|
+
topic: string;
|
|
70
|
+
species: {
|
|
71
|
+
name: string;
|
|
72
|
+
id: string;
|
|
73
|
+
subspecies: string[];
|
|
74
|
+
}[];
|
|
75
|
+
drafts: {
|
|
76
|
+
text: string;
|
|
77
|
+
speciesId: string;
|
|
78
|
+
}[];
|
|
79
|
+
missingSpecies: string[];
|
|
80
|
+
title: string | null;
|
|
81
|
+
}, {
|
|
82
|
+
name: string;
|
|
83
|
+
id: string;
|
|
84
|
+
subspecies: string[];
|
|
85
|
+
}, {
|
|
86
|
+
correctedText: string | null;
|
|
87
|
+
}>;
|
|
88
|
+
export declare const entryMerge: import("../index.js").Phase<{
|
|
89
|
+
entries: {
|
|
90
|
+
name: string;
|
|
91
|
+
text: string;
|
|
92
|
+
speciesId: string;
|
|
93
|
+
mentions: string[];
|
|
94
|
+
seeAlso: string[] | null;
|
|
95
|
+
}[];
|
|
96
|
+
topic: string;
|
|
97
|
+
species: {
|
|
98
|
+
name: string;
|
|
99
|
+
id: string;
|
|
100
|
+
subspecies: string[];
|
|
101
|
+
}[];
|
|
102
|
+
drafts: {
|
|
103
|
+
text: string;
|
|
104
|
+
speciesId: string;
|
|
105
|
+
}[];
|
|
106
|
+
missingSpecies: string[];
|
|
107
|
+
title: string | null;
|
|
108
|
+
}, unknown>;
|