@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,153 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AgentInChain } from './agent.js';
|
|
3
|
+
import type { DeclarationSite } from './declaration-site.js';
|
|
4
|
+
import type { Answer, ArtifactReader, CodePhaseOutcome } from './outcomes.js';
|
|
5
|
+
import type { BlueprintWorkers, Condition, ModelSettings, StateReads } from './run-settings.js';
|
|
6
|
+
/** One subject of a `forEach` lane: the key that identifies it, the label shown for it and the
|
|
7
|
+
* value blueprint functions receive as `subject`. The value must be plain JSON data. */
|
|
8
|
+
export type SubjectEntry<Subject> = {
|
|
9
|
+
key: string;
|
|
10
|
+
label: string;
|
|
11
|
+
subject: Subject;
|
|
12
|
+
};
|
|
13
|
+
/** One assignment per subject. `SubjectMade` is what `subjects` returns and `SubjectRead` what
|
|
14
|
+
* the lane's other functions take; they are the same type for a declared lane and differ only in
|
|
15
|
+
* the stored form, where a blueprint lists lanes with different subjects. */
|
|
16
|
+
export type ForEachOf<State, SubjectMade, SubjectRead> = {
|
|
17
|
+
forEach: {
|
|
18
|
+
description: string;
|
|
19
|
+
/** The word the devtool uses for one subject, as in "per species". */
|
|
20
|
+
subjectName: string;
|
|
21
|
+
/** Runs when the phase starts and again each time one of its assignments finishes. */
|
|
22
|
+
subjects: (reads: StateReads<State>) => SubjectEntry<SubjectMade>[];
|
|
23
|
+
};
|
|
24
|
+
/** How many independent assignments each subject gets. One when left out. */
|
|
25
|
+
repeats?: number;
|
|
26
|
+
/** How many of the lane's assignments run at once. */
|
|
27
|
+
concurrency: number;
|
|
28
|
+
/** Whether one assignment may start yet. `finishedKeys` are the keys of this lane whose
|
|
29
|
+
* assignments have all finished. */
|
|
30
|
+
startsWhen?: Condition<StateReads<State> & {
|
|
31
|
+
subject: SubjectRead;
|
|
32
|
+
finishedKeys: string[];
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
/** What a lane declares besides its name: `'once'`, optionally with `onlyWhen`, or `forEach`; and
|
|
36
|
+
* the chain each assignment runs. */
|
|
37
|
+
type LaneWork<State, SubjectMade, SubjectRead> = {
|
|
38
|
+
/** The agents each assignment runs, in order. */
|
|
39
|
+
chain: AgentInChain<State, SubjectRead>[];
|
|
40
|
+
} & ({
|
|
41
|
+
/** Work that runs once has no subject, so `'once'` is allowed only when no agent of the
|
|
42
|
+
* chain needs one. */
|
|
43
|
+
assignments: undefined extends SubjectMade ? 'once' : never;
|
|
44
|
+
onlyWhen?: Condition<StateReads<State>>;
|
|
45
|
+
} | {
|
|
46
|
+
assignments: ForEachOf<State, SubjectMade, SubjectRead>;
|
|
47
|
+
onlyWhen?: never;
|
|
48
|
+
});
|
|
49
|
+
/** One kind of work in an agent phase: its own subjects, its own wait and its own chain. */
|
|
50
|
+
export type LaneDeclaration<State, Subject> = {
|
|
51
|
+
name: string;
|
|
52
|
+
label?: string;
|
|
53
|
+
} & LaneWork<State, Subject, Subject>;
|
|
54
|
+
/** A lane as a phase lists it, whatever its subject. */
|
|
55
|
+
export type Lane<State> = {
|
|
56
|
+
name: string;
|
|
57
|
+
label?: string;
|
|
58
|
+
declaredAt: DeclarationSite;
|
|
59
|
+
} & LaneWork<State, unknown, never>;
|
|
60
|
+
type PhaseBasics = {
|
|
61
|
+
name: string;
|
|
62
|
+
/** Optional human-readable label for progress streams and worker UIs. */
|
|
63
|
+
label?: string;
|
|
64
|
+
description: string;
|
|
65
|
+
};
|
|
66
|
+
/** An agent phase declares its one lane's work directly, or several lanes. */
|
|
67
|
+
export type AgentPhaseDeclaration<State, Subject> = PhaseBasics & {
|
|
68
|
+
worker?: string;
|
|
69
|
+
modelSettings?: ModelSettings;
|
|
70
|
+
} & ((LaneWork<State, Subject, Subject> & {
|
|
71
|
+
lanes?: never;
|
|
72
|
+
}) | {
|
|
73
|
+
lanes: Lane<State>[];
|
|
74
|
+
assignments?: never;
|
|
75
|
+
chain?: never;
|
|
76
|
+
onlyWhen?: never;
|
|
77
|
+
});
|
|
78
|
+
/** What a code phase's `run` receives. `answers` holds each question this code phase asked
|
|
79
|
+
* with its answer; it is empty the first time. */
|
|
80
|
+
export type RunReads<State, Services = unknown> = StateReads<State> & {
|
|
81
|
+
artifacts: ArtifactReader;
|
|
82
|
+
stopSignal: AbortSignal;
|
|
83
|
+
answers: Answer[];
|
|
84
|
+
services: Services;
|
|
85
|
+
};
|
|
86
|
+
export type CodePhaseDeclaration<State, Services = unknown> = PhaseBasics & {
|
|
87
|
+
run: (reads: RunReads<State, Services>) => CodePhaseOutcome<State> | Promise<CodePhaseOutcome<State>>;
|
|
88
|
+
/** One plain sentence saying what it asks the person. Required for a code phase that asks. */
|
|
89
|
+
asks?: string;
|
|
90
|
+
};
|
|
91
|
+
/** A phase as a blueprint holds it. An agent phase always holds its lanes as a list; a phase
|
|
92
|
+
* declared without `lanes` has one, named for the phase. */
|
|
93
|
+
export type Phase<State, Services = any> = PhaseBasics & {
|
|
94
|
+
declaredAt: DeclarationSite;
|
|
95
|
+
} & ({
|
|
96
|
+
kind: 'agents';
|
|
97
|
+
worker?: string;
|
|
98
|
+
modelSettings?: ModelSettings;
|
|
99
|
+
lanes: Lane<State>[];
|
|
100
|
+
} | ({
|
|
101
|
+
kind: 'code';
|
|
102
|
+
} & Omit<CodePhaseDeclaration<State, Services>, keyof PhaseBasics>));
|
|
103
|
+
export type AgentPhase<State> = Extract<Phase<State, any>, {
|
|
104
|
+
kind: 'agents';
|
|
105
|
+
}>;
|
|
106
|
+
export type CodePhase<State, Services = any> = Extract<Phase<State, Services>, {
|
|
107
|
+
kind: 'code';
|
|
108
|
+
}>;
|
|
109
|
+
/** A line of phases beside the trunk that a run goes onto only when its condition holds. While
|
|
110
|
+
* one of the trunk phases it runs beside is open and has nothing left that can run, the condition
|
|
111
|
+
* is checked; when it holds the run goes onto the side line, runs its phases in order and comes
|
|
112
|
+
* back into that trunk phase. A phase declared once may stand on the trunk and on a side line. */
|
|
113
|
+
export type SideLineDeclaration<State, Services = any> = {
|
|
114
|
+
name: string;
|
|
115
|
+
description: string;
|
|
116
|
+
/** The names of the trunk phases during which the run may go onto the line and come back. */
|
|
117
|
+
beside: string[];
|
|
118
|
+
entersWhen: Condition<StateReads<State>>;
|
|
119
|
+
/** How many times a run may go onto the line. Once when left out. */
|
|
120
|
+
atMost?: number;
|
|
121
|
+
phases: Phase<State, Services>[];
|
|
122
|
+
};
|
|
123
|
+
export type SideLine<State, Services = any> = Required<SideLineDeclaration<State, Services>> & {
|
|
124
|
+
declaredAt: DeclarationSite;
|
|
125
|
+
};
|
|
126
|
+
/** One declared pipeline. */
|
|
127
|
+
export type Blueprint<State = unknown, Input = unknown, Services = any> = {
|
|
128
|
+
name: string;
|
|
129
|
+
description: string;
|
|
130
|
+
input: z.ZodType<Input, z.ZodTypeDef, unknown>;
|
|
131
|
+
startingState: {
|
|
132
|
+
description: string;
|
|
133
|
+
from: (reads: {
|
|
134
|
+
input: Input;
|
|
135
|
+
}) => State;
|
|
136
|
+
};
|
|
137
|
+
/** A path relative to the blueprint file. */
|
|
138
|
+
promptFolder: string;
|
|
139
|
+
/** Each template's name and the path of its file under the prompt folder. A prompt places a
|
|
140
|
+
* template with the placeholder of its name. */
|
|
141
|
+
templates: {
|
|
142
|
+
[name: string]: string;
|
|
143
|
+
};
|
|
144
|
+
modelSettings: ModelSettings;
|
|
145
|
+
/** Named worker types with per-plugin default settings; `'default'` is always present. */
|
|
146
|
+
workers: BlueprintWorkers;
|
|
147
|
+
/** The phases every run goes through, in order, each once. */
|
|
148
|
+
trunk: readonly Phase<State, Services>[];
|
|
149
|
+
sideLines: readonly SideLine<State, Services>[];
|
|
150
|
+
runStateSchema: z.ZodType<State, z.ZodTypeDef, unknown>;
|
|
151
|
+
declaredAt: DeclarationSite;
|
|
152
|
+
};
|
|
153
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Blueprint, Phase } from './phase.js';
|
|
2
|
+
/** Where a phase runs: on the trunk, or on a side line during one of the run's visits to it. */
|
|
3
|
+
export type Place = {
|
|
4
|
+
phase: string;
|
|
5
|
+
sideLine?: {
|
|
6
|
+
name: string;
|
|
7
|
+
visit: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/** A place's name, as events, checkpoints and addresses carry it: the phase's name on the trunk;
|
|
11
|
+
* on a side line the line's name first, and from the second visit on the visit's number between
|
|
12
|
+
* the two. Names declared in a blueprint hold no dot, so the parts can be read back. */
|
|
13
|
+
export declare function placeName({ phase, sideLine }: Place): string;
|
|
14
|
+
export declare function placeNamed({ name }: {
|
|
15
|
+
name: string;
|
|
16
|
+
}): Place;
|
|
17
|
+
/** Every phase a blueprint declares, each once: the trunk's in order, then those that stand only
|
|
18
|
+
* on a side line. */
|
|
19
|
+
export declare function declaredPhases<State>({ blueprint, }: {
|
|
20
|
+
blueprint: Blueprint<State, any, any>;
|
|
21
|
+
}): Phase<State>[];
|
|
22
|
+
/** The phase declared for a place; undefined when the blueprint no longer has it there. */
|
|
23
|
+
export declare function phaseAtPlace<State>({ blueprint, name, }: {
|
|
24
|
+
blueprint: Blueprint<State, any, any>;
|
|
25
|
+
name: string;
|
|
26
|
+
}): Phase<State, any> | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** A place's name, as events, checkpoints and addresses carry it: the phase's name on the trunk;
|
|
2
|
+
* on a side line the line's name first, and from the second visit on the visit's number between
|
|
3
|
+
* the two. Names declared in a blueprint hold no dot, so the parts can be read back. */
|
|
4
|
+
export function placeName({ phase, sideLine }) {
|
|
5
|
+
if (!sideLine)
|
|
6
|
+
return phase;
|
|
7
|
+
return sideLine.visit === 1
|
|
8
|
+
? `${sideLine.name}.${phase}`
|
|
9
|
+
: `${sideLine.name}.${sideLine.visit}.${phase}`;
|
|
10
|
+
}
|
|
11
|
+
export function placeNamed({ name }) {
|
|
12
|
+
const parts = name.split('.');
|
|
13
|
+
if (parts.length === 1)
|
|
14
|
+
return { phase: name };
|
|
15
|
+
return {
|
|
16
|
+
phase: parts.at(-1),
|
|
17
|
+
sideLine: { name: parts[0], visit: parts.length === 3 ? Number(parts[1]) : 1 },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Every phase a blueprint declares, each once: the trunk's in order, then those that stand only
|
|
21
|
+
* on a side line. */
|
|
22
|
+
export function declaredPhases({ blueprint, }) {
|
|
23
|
+
const phases = [...blueprint.trunk];
|
|
24
|
+
for (const sideLine of blueprint.sideLines)
|
|
25
|
+
for (const phase of sideLine.phases)
|
|
26
|
+
if (!phases.includes(phase))
|
|
27
|
+
phases.push(phase);
|
|
28
|
+
return phases;
|
|
29
|
+
}
|
|
30
|
+
/** The phase declared for a place; undefined when the blueprint no longer has it there. */
|
|
31
|
+
export function phaseAtPlace({ blueprint, name, }) {
|
|
32
|
+
const { phase, sideLine } = placeNamed({ name });
|
|
33
|
+
const line = sideLine
|
|
34
|
+
? blueprint.sideLines.find((each) => each.name === sideLine.name)?.phases
|
|
35
|
+
: blueprint.trunk;
|
|
36
|
+
return line?.find((each) => each.name === phase);
|
|
37
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Lifetime of an explicit prompt-cache breakpoint. Longer TTLs must precede shorter ones. */
|
|
2
|
+
export type PromptCacheTtl = '5m' | '1h';
|
|
3
|
+
/** One contiguous slice of a rendered prompt, with an optional cache breakpoint at its end. */
|
|
4
|
+
export type PromptBlock = {
|
|
5
|
+
text: string;
|
|
6
|
+
cache?: PromptCacheTtl;
|
|
7
|
+
};
|
|
8
|
+
/** One stretch of a prompt file: fixed text, the text of a template the prompt places, the
|
|
9
|
+
* place an input's text goes, or a prompt-cache breakpoint. */
|
|
10
|
+
export type PromptPiece = {
|
|
11
|
+
kind: 'text';
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'template';
|
|
15
|
+
template: string;
|
|
16
|
+
text: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'input';
|
|
19
|
+
placeholder: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'cache';
|
|
22
|
+
ttl: PromptCacheTtl;
|
|
23
|
+
};
|
|
24
|
+
/** An agent's prompt file as written, and as the ordered pieces a call is built from. */
|
|
25
|
+
export type PromptFile = {
|
|
26
|
+
path: string;
|
|
27
|
+
text: string;
|
|
28
|
+
/** The names of the templates it places, in order of first use. */
|
|
29
|
+
templates: string[];
|
|
30
|
+
pieces: PromptPiece[];
|
|
31
|
+
};
|
|
32
|
+
/** A stretch of a rendered prompt, as character offsets. */
|
|
33
|
+
export type PromptRange = {
|
|
34
|
+
start: number;
|
|
35
|
+
end: number;
|
|
36
|
+
};
|
|
37
|
+
/** The complete prompt of one call, where each input and template sits in it, and its
|
|
38
|
+
* cache-delimited blocks (when cache markers are present, or a single uncached block otherwise). */
|
|
39
|
+
export type RenderedPrompt = {
|
|
40
|
+
prompt: string;
|
|
41
|
+
promptBlocks: PromptBlock[];
|
|
42
|
+
inputs: {
|
|
43
|
+
placeholder: string;
|
|
44
|
+
ranges: PromptRange[];
|
|
45
|
+
}[];
|
|
46
|
+
templates: {
|
|
47
|
+
template: string;
|
|
48
|
+
ranges: PromptRange[];
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
export declare const PROMPT_PATH: RegExp;
|
|
52
|
+
/** Reads an agent's prompt file. Its one construct is `{{name}}`: a placeholder naming one of the
|
|
53
|
+
* blueprint's templates is the place that template's text goes; every other placeholder is the
|
|
54
|
+
* place an input's text goes. A template's text is placed as written and holds no placeholders. */
|
|
55
|
+
export declare function readPromptFile({ readFile, path, templates, }: {
|
|
56
|
+
/** The text of a file under the prompt folder. */
|
|
57
|
+
readFile: (path: string) => string;
|
|
58
|
+
path: string;
|
|
59
|
+
/** Each template's name and the path of its file under the prompt folder. */
|
|
60
|
+
templates: {
|
|
61
|
+
[name: string]: string;
|
|
62
|
+
};
|
|
63
|
+
}): PromptFile;
|
|
64
|
+
/** The input placeholders of a prompt file, each once, in order of first use. */
|
|
65
|
+
export declare function promptPlaceholders({ promptFile }: {
|
|
66
|
+
promptFile: PromptFile;
|
|
67
|
+
}): string[];
|
|
68
|
+
/** What is wrong between a prompt file and its agent's inputs: every placeholder needs an input
|
|
69
|
+
* and every input a placeholder. Empty when they match. */
|
|
70
|
+
export declare function promptInputProblems({ promptFile, inputNames, }: {
|
|
71
|
+
promptFile: PromptFile;
|
|
72
|
+
inputNames: string[];
|
|
73
|
+
}): string[];
|
|
74
|
+
/** Fills a prompt file's placeholders once. An input's text is never scanned for placeholders. */
|
|
75
|
+
export declare function renderPrompt({ promptFile, inputTexts, }: {
|
|
76
|
+
promptFile: PromptFile;
|
|
77
|
+
/** The serialized text of each input, by placeholder. */
|
|
78
|
+
inputTexts: {
|
|
79
|
+
[placeholder: string]: string;
|
|
80
|
+
};
|
|
81
|
+
}): RenderedPrompt;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The path rule and the placeholder rule are those of Praudent's prompt loader
|
|
2
|
+
// (packages/shared/src/product-model-builder/prompt-template.ts), so its prompt files load
|
|
3
|
+
// unchanged. `SKILL` is that loader's one upper-case name.
|
|
4
|
+
export const PROMPT_PATH = /^(?:[a-z0-9-]+\/)*(?:[a-z0-9-]+|SKILL)\.md$/;
|
|
5
|
+
const PROMPT_TOKEN = /\{\{([A-Za-z_]\w*)\}\}|(?:^|(?<=\n))[ \t]*<!--\s*cache(?::(5m|1h))?\s*-->[ \t]*(?:\r?\n)?|<!--\s*cache(?::(5m|1h))?\s*-->/g;
|
|
6
|
+
/** Reads an agent's prompt file. Its one construct is `{{name}}`: a placeholder naming one of the
|
|
7
|
+
* blueprint's templates is the place that template's text goes; every other placeholder is the
|
|
8
|
+
* place an input's text goes. A template's text is placed as written and holds no placeholders. */
|
|
9
|
+
export function readPromptFile({ readFile, path, templates, }) {
|
|
10
|
+
if (!PROMPT_PATH.test(path))
|
|
11
|
+
throw new Error(`Invalid prompt path: ${path}`);
|
|
12
|
+
const text = readFile(path);
|
|
13
|
+
const placed = [];
|
|
14
|
+
const pieces = [];
|
|
15
|
+
let position = 0;
|
|
16
|
+
let sawShortTtl = false;
|
|
17
|
+
for (const match of text.matchAll(PROMPT_TOKEN)) {
|
|
18
|
+
const before = text.slice(position, match.index);
|
|
19
|
+
if (before)
|
|
20
|
+
pieces.push({ kind: 'text', text: before });
|
|
21
|
+
position = match.index + match[0].length;
|
|
22
|
+
const name = match[1];
|
|
23
|
+
if (name === undefined) {
|
|
24
|
+
const ttl = (match[2] ?? match[3] ?? '5m');
|
|
25
|
+
if (ttl === '1h' && sawShortTtl)
|
|
26
|
+
throw new Error(`Prompt ${path} puts a 1h cache breakpoint after a 5m cache breakpoint; longer TTLs must come first.`);
|
|
27
|
+
if (ttl === '5m')
|
|
28
|
+
sawShortTtl = true;
|
|
29
|
+
pieces.push({ kind: 'cache', ttl });
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!Object.hasOwn(templates, name)) {
|
|
33
|
+
pieces.push({ kind: 'input', placeholder: name });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const templateText = readFile(templates[name]).trim();
|
|
37
|
+
if (!templateText)
|
|
38
|
+
throw new Error(`The template ${name} (${templates[name]}) is empty.`);
|
|
39
|
+
if (!placed.includes(name))
|
|
40
|
+
placed.push(name);
|
|
41
|
+
pieces.push({ kind: 'template', template: name, text: templateText });
|
|
42
|
+
}
|
|
43
|
+
const rest = text.slice(position);
|
|
44
|
+
if (rest)
|
|
45
|
+
pieces.push({ kind: 'text', text: rest });
|
|
46
|
+
return { path, text, templates: placed, pieces };
|
|
47
|
+
}
|
|
48
|
+
/** The input placeholders of a prompt file, each once, in order of first use. */
|
|
49
|
+
export function promptPlaceholders({ promptFile }) {
|
|
50
|
+
const placeholders = [];
|
|
51
|
+
for (const piece of promptFile.pieces)
|
|
52
|
+
if (piece.kind === 'input' && !placeholders.includes(piece.placeholder))
|
|
53
|
+
placeholders.push(piece.placeholder);
|
|
54
|
+
return placeholders;
|
|
55
|
+
}
|
|
56
|
+
/** What is wrong between a prompt file and its agent's inputs: every placeholder needs an input
|
|
57
|
+
* and every input a placeholder. Empty when they match. */
|
|
58
|
+
export function promptInputProblems({ promptFile, inputNames, }) {
|
|
59
|
+
const placeholders = promptPlaceholders({ promptFile });
|
|
60
|
+
return [
|
|
61
|
+
...placeholders
|
|
62
|
+
.filter((placeholder) => !inputNames.includes(placeholder))
|
|
63
|
+
.map((placeholder) => `${promptFile.path} has {{${placeholder}}} and the agent has no such input`),
|
|
64
|
+
...inputNames
|
|
65
|
+
.filter((name) => !placeholders.includes(name))
|
|
66
|
+
.map((name) => promptFile.templates.includes(name)
|
|
67
|
+
? `the input ${name} has the name of a template, which fills {{${name}}} in ${promptFile.path}`
|
|
68
|
+
: `${promptFile.path} has no {{${name}}} placeholder for the agent's input`),
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
/** Adds a stretch to the entry of its name, joining it to the stretch before when they touch. */
|
|
72
|
+
function addRange({ entries, isNamed, newEntry, range, }) {
|
|
73
|
+
if (range.end === range.start)
|
|
74
|
+
return;
|
|
75
|
+
const entry = entries.find(isNamed);
|
|
76
|
+
const last = entry?.ranges.at(-1);
|
|
77
|
+
if (last && last.end === range.start)
|
|
78
|
+
last.end = range.end;
|
|
79
|
+
else if (entry)
|
|
80
|
+
entry.ranges.push(range);
|
|
81
|
+
else
|
|
82
|
+
entries.push({ ...newEntry(), ranges: [range] });
|
|
83
|
+
}
|
|
84
|
+
/** Fills a prompt file's placeholders once. An input's text is never scanned for placeholders. */
|
|
85
|
+
export function renderPrompt({ promptFile, inputTexts, }) {
|
|
86
|
+
let prompt = '';
|
|
87
|
+
let currentBlock = '';
|
|
88
|
+
const promptBlocks = [];
|
|
89
|
+
const inputs = [];
|
|
90
|
+
const templates = [];
|
|
91
|
+
for (const piece of promptFile.pieces) {
|
|
92
|
+
if (piece.kind === 'cache') {
|
|
93
|
+
if (currentBlock) {
|
|
94
|
+
promptBlocks.push({ text: currentBlock, cache: piece.ttl });
|
|
95
|
+
currentBlock = '';
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const start = prompt.length;
|
|
100
|
+
if (piece.kind === 'text') {
|
|
101
|
+
prompt += piece.text;
|
|
102
|
+
currentBlock += piece.text;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (piece.kind === 'template') {
|
|
106
|
+
prompt += piece.text;
|
|
107
|
+
currentBlock += piece.text;
|
|
108
|
+
addRange({
|
|
109
|
+
entries: templates,
|
|
110
|
+
isNamed: (entry) => entry.template === piece.template,
|
|
111
|
+
newEntry: () => ({ template: piece.template, ranges: [] }),
|
|
112
|
+
range: { start, end: prompt.length },
|
|
113
|
+
});
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (!Object.hasOwn(inputTexts, piece.placeholder))
|
|
117
|
+
throw new Error(`Prompt ${promptFile.path} requires ${piece.placeholder}`);
|
|
118
|
+
const inputText = inputTexts[piece.placeholder];
|
|
119
|
+
prompt += inputText;
|
|
120
|
+
currentBlock += inputText;
|
|
121
|
+
addRange({
|
|
122
|
+
entries: inputs,
|
|
123
|
+
isNamed: (entry) => entry.placeholder === piece.placeholder,
|
|
124
|
+
newEntry: () => ({ placeholder: piece.placeholder, ranges: [] }),
|
|
125
|
+
range: { start, end: prompt.length },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (currentBlock)
|
|
129
|
+
promptBlocks.push({ text: currentBlock });
|
|
130
|
+
return { prompt, promptBlocks, inputs, templates };
|
|
131
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { type SentBack } from './outcomes.js';
|
|
3
|
+
/** How an agent's reply text becomes the value its outcome judges. `read` returns the parsed
|
|
4
|
+
* value, or sends the text back with a correction. */
|
|
5
|
+
export type ReplyReader<Reply> = {
|
|
6
|
+
description: string;
|
|
7
|
+
/** JSON Schema for the expected reply shape, when the reader validates against one. */
|
|
8
|
+
schema?: {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
read: (reads: {
|
|
12
|
+
replyText: string;
|
|
13
|
+
}) => Reply | SentBack;
|
|
14
|
+
};
|
|
15
|
+
/** Default correction wording for a rejected JSON reply: lists every problem and includes the
|
|
16
|
+
* full expected JSON Schema so the model can see every allowed field. */
|
|
17
|
+
export declare function formatJsonReplyCorrection({ issues, schema, }: {
|
|
18
|
+
issues: z.ZodIssue[];
|
|
19
|
+
schema: {
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
}): string;
|
|
23
|
+
/** A reader of one JSON value, bare or in one fenced block, checked against a Zod schema. When
|
|
24
|
+
* `correctionFor` is omitted, a rejected reply receives the validation issues and the full JSON
|
|
25
|
+
* schema. When provided, `correctionFor` receives the issues and the schema (`issues` is empty
|
|
26
|
+
* when the text is not one JSON value). */
|
|
27
|
+
export declare function jsonReply<Reply>({ schema, correctionFor, }: {
|
|
28
|
+
schema: z.ZodType<Reply, z.ZodTypeDef, unknown>;
|
|
29
|
+
correctionFor?: (problem: {
|
|
30
|
+
replyText: string;
|
|
31
|
+
issues: z.ZodIssue[];
|
|
32
|
+
schema: {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
}) => string;
|
|
36
|
+
}): ReplyReader<Reply>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
2
|
+
import { sendBack } from './outcomes.js';
|
|
3
|
+
/** Default correction wording for a rejected JSON reply: lists every problem and includes the
|
|
4
|
+
* full expected JSON Schema so the model can see every allowed field. */
|
|
5
|
+
export function formatJsonReplyCorrection({ issues, schema, }) {
|
|
6
|
+
const problems = issues.length === 0
|
|
7
|
+
? 'Reply with one JSON value and nothing else.'
|
|
8
|
+
: issues.map((issue) => `${issue.path.join('.') || 'reply'}: ${issue.message}`).join('\n');
|
|
9
|
+
return `${problems}\n\nExpected JSON schema:\n${JSON.stringify(schema, null, 2)}`;
|
|
10
|
+
}
|
|
11
|
+
/** A reader of one JSON value, bare or in one fenced block, checked against a Zod schema. When
|
|
12
|
+
* `correctionFor` is omitted, a rejected reply receives the validation issues and the full JSON
|
|
13
|
+
* schema. When provided, `correctionFor` receives the issues and the schema (`issues` is empty
|
|
14
|
+
* when the text is not one JSON value). */
|
|
15
|
+
export function jsonReply({ schema, correctionFor, }) {
|
|
16
|
+
const jsonSchema = zodToJsonSchema(schema, { $refStrategy: 'none' });
|
|
17
|
+
const format = correctionFor ?? (({ issues }) => formatJsonReplyCorrection({ issues, schema: jsonSchema }));
|
|
18
|
+
return {
|
|
19
|
+
description: 'One JSON value, bare or in one fenced block.',
|
|
20
|
+
schema: jsonSchema,
|
|
21
|
+
read: ({ replyText }) => {
|
|
22
|
+
const fenced = /^\s*```(?:json)?\n([\s\S]*?)\n```\s*$/.exec(replyText);
|
|
23
|
+
let value;
|
|
24
|
+
try {
|
|
25
|
+
value = JSON.parse(fenced ? fenced[1] : replyText);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return sendBack({ correction: format({ replyText, issues: [], schema: jsonSchema }) });
|
|
29
|
+
}
|
|
30
|
+
const parsed = schema.safeParse(value);
|
|
31
|
+
if (parsed.success)
|
|
32
|
+
return parsed.data;
|
|
33
|
+
return sendBack({
|
|
34
|
+
correction: format({ replyText, issues: parsed.error.issues, schema: jsonSchema }),
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Who answers a run's questions: the person, or the recommendation each question carries. */
|
|
2
|
+
export type QuestionsAnsweredBy = 'person' | 'recommendation';
|
|
3
|
+
/** What every blueprint function that reads the run state receives. */
|
|
4
|
+
export type StateReads<State> = {
|
|
5
|
+
state: State;
|
|
6
|
+
questionsAnsweredBy: QuestionsAnsweredBy;
|
|
7
|
+
};
|
|
8
|
+
/** A yes-or-no judgment with the plain sentence the devtool shows for it. */
|
|
9
|
+
export type Condition<Reads> = {
|
|
10
|
+
description: string;
|
|
11
|
+
test: (reads: Reads) => boolean;
|
|
12
|
+
};
|
|
13
|
+
export type Effort = 'none' | 'low' | 'medium' | 'high';
|
|
14
|
+
/** What answers a run's model calls. `'custom'` delegates routing and validation to the host's `infer`. */
|
|
15
|
+
export type CallsAnsweredBy = 'codex' | 'claude-code' | 'openai-api' | 'anthropic-api' | 'bedrock-api' | 'gemini-api' | 'scripted' | 'custom';
|
|
16
|
+
/** The model and effort of a call. The agent's value wins over the phase's, the phase's over the
|
|
17
|
+
* worker type's, and the worker type's over the blueprint's; a run's own overrides win over all. */
|
|
18
|
+
export type ModelSettings = {
|
|
19
|
+
effort?: Effort;
|
|
20
|
+
model?: {
|
|
21
|
+
codex?: string;
|
|
22
|
+
'claude-code'?: string;
|
|
23
|
+
'openai-api'?: string;
|
|
24
|
+
'anthropic-api'?: string;
|
|
25
|
+
'bedrock-api'?: string;
|
|
26
|
+
'gemini-api'?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** One named worker type declared by a blueprint (for example `'default'` or `'visual-design'`),
|
|
30
|
+
* carrying its optional label and default model settings for each supported client/plugin. */
|
|
31
|
+
export type WorkerDefinition = {
|
|
32
|
+
label?: string;
|
|
33
|
+
modelSettings: ModelSettings;
|
|
34
|
+
};
|
|
35
|
+
/** Map of worker type name to its definition. `'default'` is always available. */
|
|
36
|
+
export type BlueprintWorkers = {
|
|
37
|
+
[name: string]: WorkerDefinition;
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DeclarationSite } from './declaration-site.js';
|
|
2
|
+
/** A named, described function from typed arguments to prompt text. One name is one
|
|
3
|
+
* presentation; a different presentation is a different serializer. */
|
|
4
|
+
export type Serializer<Arguments> = {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
render: (serializerArguments: Arguments) => string;
|
|
8
|
+
declaredAt: DeclarationSite;
|
|
9
|
+
};
|
|
10
|
+
export declare function defineSerializer<Arguments>(serializer: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
render: (serializerArguments: Arguments) => string;
|
|
14
|
+
}): Serializer<Arguments>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type CollectionAction = 'create' | 'update' | 'delete';
|
|
2
|
+
/** Restricts changes to an array of records identified by `idField` (default `'id'`). */
|
|
3
|
+
export type RecordScope<State, Subject = unknown> = {
|
|
4
|
+
/** Identifying key on each record. Defaults to `'id'`. */
|
|
5
|
+
idField?: string;
|
|
6
|
+
/** Which record operations are allowed. Defaults to create, update and delete. */
|
|
7
|
+
actions?: CollectionAction[];
|
|
8
|
+
/** When set, updates may change only these top-level fields on a record. */
|
|
9
|
+
fields?: string[];
|
|
10
|
+
/** Top-level fields on a record that may never change. */
|
|
11
|
+
forbiddenFields?: string[];
|
|
12
|
+
/** When set, only records whose id is in the returned list may be touched by this rule. */
|
|
13
|
+
onlyIds?: (reads: {
|
|
14
|
+
state: State;
|
|
15
|
+
subject: Subject;
|
|
16
|
+
}) => readonly string[];
|
|
17
|
+
};
|
|
18
|
+
/** One declarative rule stating what part of the run state an agent may change. Multiple rules
|
|
19
|
+
* for the same `path` are unioned: a change is allowed when at least one matching rule permits it. */
|
|
20
|
+
export type WriteScopeRule<State, Subject = unknown> = {
|
|
21
|
+
/** Top-level key of the run state this rule covers. */
|
|
22
|
+
path: keyof State & string;
|
|
23
|
+
/** Plain-language summary shown in the Blueprint devtool. Derived from the rule when omitted. */
|
|
24
|
+
description?: string;
|
|
25
|
+
/** For an array of records with an id field, restrict which records, actions and fields may
|
|
26
|
+
* change. Omit to allow any change under `path`. */
|
|
27
|
+
records?: RecordScope<State, Subject>;
|
|
28
|
+
};
|
|
29
|
+
/** Plain-language description of a write-scope rule for the Blueprint devtool. */
|
|
30
|
+
export declare function describeWriteScopeRule<State, Subject>(rule: WriteScopeRule<State, Subject>): string;
|
|
31
|
+
/** Checks a proposed state transition against an agent's `mayChange` rules. Returns a list of
|
|
32
|
+
* human-readable violation messages; empty when every change is within scope. */
|
|
33
|
+
export declare function writeScopeViolations<State, Subject>({ before, after, rules, state, subject, }: {
|
|
34
|
+
before: unknown;
|
|
35
|
+
after: unknown;
|
|
36
|
+
rules: readonly WriteScopeRule<State, Subject>[];
|
|
37
|
+
state: State;
|
|
38
|
+
subject: Subject;
|
|
39
|
+
}): string[];
|