@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.
Files changed (177) hide show
  1. package/dist/admin-ui/assets/index-CHJ8lsZp.js +120 -0
  2. package/dist/admin-ui/assets/index-XyqtD-IA.css +1 -0
  3. package/dist/admin-ui/index.html +12 -0
  4. package/dist/blueprint/agent.d.ts +148 -0
  5. package/dist/blueprint/agent.js +1 -0
  6. package/dist/blueprint/declaration-site.d.ts +7 -0
  7. package/dist/blueprint/declaration-site.js +8 -0
  8. package/dist/blueprint/declared-structure.d.ts +145 -0
  9. package/dist/blueprint/declared-structure.js +213 -0
  10. package/dist/blueprint/define-run-state.d.ts +79 -0
  11. package/dist/blueprint/define-run-state.js +89 -0
  12. package/dist/blueprint/load-blueprint.d.ts +28 -0
  13. package/dist/blueprint/load-blueprint.js +85 -0
  14. package/dist/blueprint/outcomes.d.ts +76 -0
  15. package/dist/blueprint/outcomes.js +10 -0
  16. package/dist/blueprint/phase.d.ts +153 -0
  17. package/dist/blueprint/phase.js +1 -0
  18. package/dist/blueprint/places.d.ts +26 -0
  19. package/dist/blueprint/places.js +37 -0
  20. package/dist/blueprint/prompt-file.d.ts +81 -0
  21. package/dist/blueprint/prompt-file.js +131 -0
  22. package/dist/blueprint/reply-reader.d.ts +36 -0
  23. package/dist/blueprint/reply-reader.js +38 -0
  24. package/dist/blueprint/run-settings.d.ts +38 -0
  25. package/dist/blueprint/run-settings.js +1 -0
  26. package/dist/blueprint/serializer.d.ts +14 -0
  27. package/dist/blueprint/serializer.js +4 -0
  28. package/dist/blueprint/write-scope.d.ts +39 -0
  29. package/dist/blueprint/write-scope.js +106 -0
  30. package/dist/command.d.ts +2 -0
  31. package/dist/command.js +148 -0
  32. package/dist/commands/calls-answering.d.ts +16 -0
  33. package/dist/commands/calls-answering.js +63 -0
  34. package/dist/commands/json-file.d.ts +6 -0
  35. package/dist/commands/json-file.js +19 -0
  36. package/dist/commands/run-command.d.ts +23 -0
  37. package/dist/commands/run-command.js +172 -0
  38. package/dist/commands/typed-answers.d.ts +10 -0
  39. package/dist/commands/typed-answers.js +43 -0
  40. package/dist/config.d.ts +27 -0
  41. package/dist/config.js +20 -0
  42. package/dist/devtool-server/app-pages.d.ts +12 -0
  43. package/dist/devtool-server/app-pages.js +68 -0
  44. package/dist/devtool-server/blueprint-description.d.ts +21 -0
  45. package/dist/devtool-server/blueprint-description.js +27 -0
  46. package/dist/devtool-server/connected-runs.d.ts +36 -0
  47. package/dist/devtool-server/connected-runs.js +201 -0
  48. package/dist/devtool-server/devtool-server.d.ts +17 -0
  49. package/dist/devtool-server/devtool-server.js +294 -0
  50. package/dist/devtool-server/devtool-shapes.d.ts +312 -0
  51. package/dist/devtool-server/devtool-shapes.js +24 -0
  52. package/dist/devtool-server/listed-runs.d.ts +17 -0
  53. package/dist/devtool-server/listed-runs.js +42 -0
  54. package/dist/devtool-server/print-blueprint.d.ts +1 -0
  55. package/dist/devtool-server/print-blueprint.js +36 -0
  56. package/dist/example/added-species.d.ts +21 -0
  57. package/dist/example/added-species.js +19 -0
  58. package/dist/example/cover.d.ts +21 -0
  59. package/dist/example/cover.js +67 -0
  60. package/dist/example/cross-references.d.ts +21 -0
  61. package/dist/example/cross-references.js +77 -0
  62. package/dist/example/entry-drafts.d.ts +21 -0
  63. package/dist/example/entry-drafts.js +63 -0
  64. package/dist/example/entry-merge.d.ts +108 -0
  65. package/dist/example/entry-merge.js +284 -0
  66. package/dist/example/field-guide.d.ts +26 -0
  67. package/dist/example/field-guide.js +40 -0
  68. package/dist/example/guide-page.d.ts +21 -0
  69. package/dist/example/guide-page.js +15 -0
  70. package/dist/example/missing-species.d.ts +21 -0
  71. package/dist/example/missing-species.js +59 -0
  72. package/dist/example/run-state.d.ts +803 -0
  73. package/dist/example/run-state.js +58 -0
  74. package/dist/example/serializers.d.ts +32 -0
  75. package/dist/example/serializers.js +42 -0
  76. package/dist/example/species-list.d.ts +47 -0
  77. package/dist/example/species-list.js +93 -0
  78. package/dist/index.d.ts +35 -0
  79. package/dist/index.js +25 -0
  80. package/dist/inference/anthropic-api.d.ts +37 -0
  81. package/dist/inference/anthropic-api.js +197 -0
  82. package/dist/inference/anthropic-prices.d.ts +18 -0
  83. package/dist/inference/anthropic-prices.js +61 -0
  84. package/dist/inference/anthropic-request.d.ts +51 -0
  85. package/dist/inference/anthropic-request.js +208 -0
  86. package/dist/inference/bedrock-api.d.ts +45 -0
  87. package/dist/inference/bedrock-api.js +242 -0
  88. package/dist/inference/bedrock-prices.d.ts +22 -0
  89. package/dist/inference/bedrock-prices.js +79 -0
  90. package/dist/inference/bedrock-request.d.ts +27 -0
  91. package/dist/inference/bedrock-request.js +193 -0
  92. package/dist/inference/call-queue-shapes.d.ts +273 -0
  93. package/dist/inference/call-queue-shapes.js +82 -0
  94. package/dist/inference/call-queue.d.ts +109 -0
  95. package/dist/inference/call-queue.js +408 -0
  96. package/dist/inference/gemini-api.d.ts +44 -0
  97. package/dist/inference/gemini-api.js +191 -0
  98. package/dist/inference/gemini-prices.d.ts +19 -0
  99. package/dist/inference/gemini-prices.js +33 -0
  100. package/dist/inference/gemini-request.d.ts +25 -0
  101. package/dist/inference/gemini-request.js +126 -0
  102. package/dist/inference/inference.d.ts +84 -0
  103. package/dist/inference/inference.js +9 -0
  104. package/dist/inference/openai-api.d.ts +29 -0
  105. package/dist/inference/openai-api.js +138 -0
  106. package/dist/inference/openai-prices.d.ts +12 -0
  107. package/dist/inference/openai-prices.js +25 -0
  108. package/dist/inference/openai-request.d.ts +50 -0
  109. package/dist/inference/openai-request.js +100 -0
  110. package/dist/inference/own-worker.d.ts +6 -0
  111. package/dist/inference/own-worker.js +16 -0
  112. package/dist/inference/scripted.d.ts +146 -0
  113. package/dist/inference/scripted.js +67 -0
  114. package/dist/run/assignments/agent-call.d.ts +32 -0
  115. package/dist/run/assignments/agent-call.js +218 -0
  116. package/dist/run/assignments/agent-phase.d.ts +14 -0
  117. package/dist/run/assignments/agent-phase.js +243 -0
  118. package/dist/run/assignments/assignment-memory.d.ts +42 -0
  119. package/dist/run/assignments/assignment-memory.js +52 -0
  120. package/dist/run/assignments/assignment.d.ts +17 -0
  121. package/dist/run/assignments/assignment.js +252 -0
  122. package/dist/run/assignments/model-settings.d.ts +39 -0
  123. package/dist/run/assignments/model-settings.js +57 -0
  124. package/dist/run/assignments/prepared-call.d.ts +28 -0
  125. package/dist/run/assignments/prepared-call.js +115 -0
  126. package/dist/run/assignments/tool-call.d.ts +26 -0
  127. package/dist/run/assignments/tool-call.js +108 -0
  128. package/dist/run/blueprint-mistake.d.ts +8 -0
  129. package/dist/run/blueprint-mistake.js +14 -0
  130. package/dist/run/code-phase.d.ts +11 -0
  131. package/dist/run/code-phase.js +59 -0
  132. package/dist/run/create-run.d.ts +36 -0
  133. package/dist/run/create-run.js +119 -0
  134. package/dist/run/execute-run.d.ts +7 -0
  135. package/dist/run/execute-run.js +158 -0
  136. package/dist/run/record/apply-event.d.ts +13 -0
  137. package/dist/run/record/apply-event.js +256 -0
  138. package/dist/run/record/events.d.ts +187 -0
  139. package/dist/run/record/events.js +1 -0
  140. package/dist/run/record/postgres-run-store.d.ts +13 -0
  141. package/dist/run/record/postgres-run-store.js +189 -0
  142. package/dist/run/record/progress-projection.d.ts +83 -0
  143. package/dist/run/record/progress-projection.js +167 -0
  144. package/dist/run/record/progress.d.ts +207 -0
  145. package/dist/run/record/progress.js +63 -0
  146. package/dist/run/record/run-store.d.ts +74 -0
  147. package/dist/run/record/run-store.js +1 -0
  148. package/dist/run/record/run-summary.d.ts +8 -0
  149. package/dist/run/record/run-summary.js +19 -0
  150. package/dist/run/record/run-types.d.ts +95 -0
  151. package/dist/run/record/run-types.js +1 -0
  152. package/dist/run/record/state-changes.d.ts +42 -0
  153. package/dist/run/record/state-changes.js +157 -0
  154. package/dist/run/resume-run.d.ts +25 -0
  155. package/dist/run/resume-run.js +99 -0
  156. package/dist/run/run-endings.d.ts +20 -0
  157. package/dist/run/run-endings.js +20 -0
  158. package/dist/run/run-option-shapes.d.ts +176 -0
  159. package/dist/run/run-option-shapes.js +47 -0
  160. package/dist/run/run-session.d.ts +144 -0
  161. package/dist/run/run-session.js +278 -0
  162. package/dist/worker/answer-queued-call.d.ts +19 -0
  163. package/dist/worker/answer-queued-call.js +100 -0
  164. package/dist/worker/launchers/claude-code.d.ts +7 -0
  165. package/dist/worker/launchers/claude-code.js +156 -0
  166. package/dist/worker/launchers/codex.d.ts +6 -0
  167. package/dist/worker/launchers/codex.js +141 -0
  168. package/dist/worker/launchers/launch.d.ts +31 -0
  169. package/dist/worker/launchers/launch.js +6 -0
  170. package/dist/worker/launchers/program-run.d.ts +30 -0
  171. package/dist/worker/launchers/program-run.js +92 -0
  172. package/dist/worker/launchers/tool-server.d.ts +26 -0
  173. package/dist/worker/launchers/tool-server.js +90 -0
  174. package/dist/worker/worker.d.ts +13 -0
  175. package/dist/worker/worker.js +170 -0
  176. package/package.json +43 -4
  177. package/README.md +0 -3
@@ -0,0 +1,294 @@
1
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises';
2
+ import { createServer } from 'node:http';
3
+ import { tmpdir } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+ import { z } from 'zod';
6
+ import { prepareBlueprint } from '../blueprint/load-blueprint.js';
7
+ import { GivenAnswerSchema } from '../run/run-option-shapes.js';
8
+ import { appPages } from './app-pages.js';
9
+ import { readBlueprintDescription } from './blueprint-description.js';
10
+ import { connectedRuns } from './connected-runs.js';
11
+ import { NewRunRequestSchema, ResumeRequestSchema, } from './devtool-shapes.js';
12
+ import { listedRun, listedRuns } from './listed-runs.js';
13
+ const KEEP_ALIVE_MS = 25_000;
14
+ const MAX_BODY_BYTES = 32 * 1024 * 1024;
15
+ const MEDIA_TYPE = /^[\w.+-]+\/[\w.+-]+$/;
16
+ /** An answer that is not 200: the status and what to tell the person. */
17
+ class Refusal extends Error {
18
+ status;
19
+ constructor(status, message) {
20
+ super(message);
21
+ this.status = status;
22
+ }
23
+ }
24
+ async function readJsonBody(request) {
25
+ const chunks = [];
26
+ let size = 0;
27
+ for await (const chunk of request) {
28
+ size += chunk.length;
29
+ if (size > MAX_BODY_BYTES)
30
+ throw new Refusal(413, 'The request is too large.');
31
+ chunks.push(chunk);
32
+ }
33
+ return chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : {};
34
+ }
35
+ function sendJson({ response, status = 200, body, }) {
36
+ response.writeHead(status, { 'content-type': 'application/json', 'cache-control': 'no-store' });
37
+ response.end(JSON.stringify(body));
38
+ }
39
+ function sendBytes({ response, contentType, bytes, sandbox = false, }) {
40
+ const buffer = Buffer.from(bytes);
41
+ response.writeHead(200, {
42
+ 'content-type': contentType.startsWith('text/') ? `${contentType}; charset=utf-8` : contentType,
43
+ 'content-length': buffer.byteLength,
44
+ 'cache-control': 'no-store',
45
+ 'x-content-type-options': 'nosniff',
46
+ ...(sandbox ? { 'content-security-policy': 'sandbox' } : {}),
47
+ });
48
+ response.end(buffer);
49
+ }
50
+ /** Starts the Dagma admin UI server backed by `store` (Postgres). Inspecting runs only requires
51
+ * `store`; starting or resuming runs uses `blueprintFile` (or a configured blueprint). */
52
+ export async function startDevtool({ store, databaseUrl, blueprintFile, blueprint, port, scriptedRepliesFile, }) {
53
+ await store.ensureSchema?.();
54
+ const streams = [];
55
+ const broadcast = (message) => {
56
+ for (const stream of streams)
57
+ stream.write(`data: ${JSON.stringify(message)}\n\n`);
58
+ };
59
+ /** Describes the active blueprint when configured via file or in-memory value. */
60
+ const describeBlueprint = async () => {
61
+ if (blueprint) {
62
+ const prepared = prepareBlueprint({ blueprint });
63
+ return {
64
+ structure: prepared.structure,
65
+ hash: prepared.hash,
66
+ inputSchema: {},
67
+ loadedAt: new Date().toISOString(),
68
+ };
69
+ }
70
+ if (blueprintFile) {
71
+ return readBlueprintDescription({ blueprintFile }).catch((error) => {
72
+ throw new Refusal(422, error instanceof Error ? error.message : String(error));
73
+ });
74
+ }
75
+ throw new Refusal(404, 'No blueprint is configured. Inspect any stored run from the Runs screen, or configure blueprints in dagma.config.ts.');
76
+ };
77
+ /** What keeps a typed input from fitting the blueprint's input shape; nothing when it fits. */
78
+ const inputProblems = async ({ input }) => {
79
+ if (blueprint) {
80
+ const parsed = blueprint.input.safeParse(input);
81
+ return parsed.success
82
+ ? []
83
+ : parsed.error.issues.map((issue) => `${issue.path.join('.') || 'input'}: ${issue.message}`);
84
+ }
85
+ if (!blueprintFile)
86
+ return ['No blueprint is configured.'];
87
+ const folder = await mkdtemp(join(tmpdir(), 'dagma-devtool-'));
88
+ try {
89
+ const inputFile = join(folder, 'input.json');
90
+ await writeFile(inputFile, JSON.stringify(input));
91
+ const description = await readBlueprintDescription({ blueprintFile, inputFile });
92
+ return description.inputProblems ?? [];
93
+ }
94
+ finally {
95
+ await rm(folder, { recursive: true, force: true });
96
+ }
97
+ };
98
+ const runs = connectedRuns({
99
+ blueprintFile,
100
+ store,
101
+ databaseUrl,
102
+ onRunEvent: ({ runId, event }) => broadcast({ kind: 'run-event', runId, event }),
103
+ onRowChanged: (row) => broadcast({ kind: 'run-row', row }),
104
+ });
105
+ const settings = () => ({
106
+ blueprintFile: blueprintFile ? resolve(blueprintFile) : (blueprint?.name ?? 'Postgres store'),
107
+ ...(scriptedRepliesFile ? { scriptedRepliesFile: resolve(scriptedRepliesFile) } : {}),
108
+ openAiKeyIsSet: !!process.env.OPENAI_API_KEY,
109
+ anthropicKeyIsSet: !!process.env.ANTHROPIC_API_KEY,
110
+ });
111
+ const openStream = ({ request, response, }) => {
112
+ response.writeHead(200, { 'content-type': 'text/event-stream', 'cache-control': 'no-store' });
113
+ response.write(': connected\n\n');
114
+ streams.push(response);
115
+ const keepAlive = setInterval(() => response.write(': keep-alive\n\n'), KEEP_ALIVE_MS);
116
+ request.on('close', () => {
117
+ clearInterval(keepAlive);
118
+ streams.splice(streams.indexOf(response), 1);
119
+ });
120
+ };
121
+ /** Serves one stored record of a run from Postgres under the existing `/files/*` paths. */
122
+ const sendRunRecord = async ({ response, runId, path, mediaType, }) => {
123
+ if (path === 'input.json') {
124
+ const input = await store.readInput({ runId });
125
+ return sendJson({ response, body: input ?? null });
126
+ }
127
+ if (path === 'events.jsonl') {
128
+ const events = await store.readEvents({ runId });
129
+ const ndjson = events.map((event) => JSON.stringify(event)).join('\n');
130
+ return sendBytes({
131
+ response,
132
+ contentType: 'application/x-ndjson',
133
+ bytes: Buffer.from(ndjson ? `${ndjson}\n` : '', 'utf8'),
134
+ });
135
+ }
136
+ if (/^blueprint-\d+\.json$/.test(path)) {
137
+ const structure = await store.readStructure({ runId, name: path });
138
+ if (!structure)
139
+ throw new Refusal(404, `${path} was not found for run ${runId}.`);
140
+ return sendJson({ response, body: structure });
141
+ }
142
+ if (path.startsWith('checkpoints/') && path.endsWith('.json')) {
143
+ const name = path.slice('checkpoints/'.length, -'.json'.length);
144
+ const checkpoint = await store.readCheckpoint({ runId, name });
145
+ if (!checkpoint)
146
+ throw new Refusal(404, `Checkpoint ${name} was not found for run ${runId}.`);
147
+ return sendJson({ response, body: checkpoint });
148
+ }
149
+ if (path.startsWith('calls/') && path.endsWith('.json')) {
150
+ const callId = path.slice('calls/'.length, -'.json'.length);
151
+ const call = await store.readCall({ runId, callId });
152
+ if (!call)
153
+ throw new Refusal(404, `Call ${callId} was not found for run ${runId}.`);
154
+ return sendJson({ response, body: call });
155
+ }
156
+ if (path.startsWith('artifacts/')) {
157
+ const [, artifactId, ...nameParts] = path.split('/');
158
+ const name = nameParts.join('/');
159
+ if (!artifactId || !name)
160
+ throw new Refusal(404, 'There is no such artifact.');
161
+ const artifact = await store
162
+ .readArtifact({
163
+ runId,
164
+ saved: {
165
+ id: artifactId,
166
+ name,
167
+ mediaType: mediaType && MEDIA_TYPE.test(mediaType) ? mediaType : 'application/octet-stream',
168
+ sizeInBytes: 0,
169
+ },
170
+ })
171
+ .catch(() => undefined);
172
+ if (!artifact)
173
+ throw new Refusal(404, `Artifact ${name} was not found for run ${runId}.`);
174
+ const safeType = mediaType && MEDIA_TYPE.test(mediaType)
175
+ ? mediaType
176
+ : MEDIA_TYPE.test(artifact.mediaType)
177
+ ? artifact.mediaType
178
+ : 'application/octet-stream';
179
+ return sendBytes({
180
+ response,
181
+ contentType: safeType,
182
+ bytes: artifact.bytes,
183
+ sandbox: true,
184
+ });
185
+ }
186
+ throw new Refusal(404, 'There is no such file.');
187
+ };
188
+ const answerApi = async ({ request, response, url, }) => {
189
+ const [area, runId, action, ...rest] = url.pathname.split('/').slice(2).map(decodeURIComponent);
190
+ const reads = request.method === 'GET';
191
+ const acts = request.method === 'POST';
192
+ if (reads && area === 'stream')
193
+ return openStream({ request, response });
194
+ if (reads && area === 'blueprint')
195
+ return sendJson({ response, body: await describeBlueprint() });
196
+ if (reads && area === 'settings')
197
+ return sendJson({ response, body: settings() });
198
+ if (acts && area === 'input-check')
199
+ return sendJson({
200
+ response,
201
+ body: { problems: await inputProblems({ input: await readJsonBody(request) }) },
202
+ });
203
+ if (area !== 'runs' || (!reads && !acts))
204
+ throw new Refusal(404, 'There is no such address.');
205
+ if (!runId) {
206
+ if (reads)
207
+ return sendJson({
208
+ response,
209
+ body: await listedRuns({ store, connectedRows: runs.rows() }),
210
+ });
211
+ await describeBlueprint();
212
+ const started = await runs.start({
213
+ request: NewRunRequestSchema.parse(await readJsonBody(request)),
214
+ });
215
+ return sendJson({ response, body: started });
216
+ }
217
+ if (!/^[\w-]+$/.test(runId))
218
+ throw new Refusal(404, 'There is no such run.');
219
+ if (reads && action === 'files')
220
+ return sendRunRecord({
221
+ response,
222
+ runId,
223
+ path: rest.join('/'),
224
+ mediaType: url.searchParams.get('type'),
225
+ });
226
+ if (reads && !action) {
227
+ const row = runs.rows().find((each) => each.summary.runId === runId) ??
228
+ (await listedRun({ store, runId }));
229
+ if (!row)
230
+ throw new Refusal(404, `There is no run ${runId}.`);
231
+ return sendJson({ response, body: row });
232
+ }
233
+ if (!acts)
234
+ throw new Refusal(404, 'There is no such address.');
235
+ const body = await readJsonBody(request);
236
+ if (action === 'stop')
237
+ runs.stop({ runId });
238
+ else if (action === 'resume')
239
+ await runs.resume({ runId, request: ResumeRequestSchema.parse(body) });
240
+ else if (action === 'answers')
241
+ await runs.answer({ runId, given: GivenAnswerSchema.parse(body) });
242
+ else
243
+ throw new Refusal(404, 'There is no such address.');
244
+ return sendJson({ response, body: { done: true } });
245
+ };
246
+ let listeningPort = port;
247
+ const server = createServer((request, response) => {
248
+ const host = request.headers.host ?? '';
249
+ const url = new URL(request.url ?? '/', `http://${host}`);
250
+ const { origin } = request.headers;
251
+ if (![`127.0.0.1:${listeningPort}`, `localhost:${listeningPort}`].includes(host) ||
252
+ (origin !== undefined && origin !== `http://${host}`) ||
253
+ (request.method !== 'GET' && origin === undefined)) {
254
+ response.writeHead(403).end();
255
+ return;
256
+ }
257
+ if (!url.pathname.startsWith('/api/'))
258
+ return pages.handle(request, response);
259
+ answerApi({ request, response, url }).catch((error) => {
260
+ if (response.headersSent)
261
+ return response.end();
262
+ const message = error instanceof z.ZodError
263
+ ? error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ')
264
+ : error instanceof Error
265
+ ? error.message
266
+ : String(error);
267
+ sendJson({
268
+ response,
269
+ status: error instanceof Refusal ? error.status : 400,
270
+ body: { message },
271
+ });
272
+ });
273
+ });
274
+ const pages = await appPages({ server });
275
+ await new Promise((resolveListening, reject) => {
276
+ server.once('error', reject);
277
+ server.listen(port, '127.0.0.1', resolveListening);
278
+ });
279
+ const bound = server.address();
280
+ if (bound && typeof bound === 'object')
281
+ listeningPort = bound.port;
282
+ return {
283
+ address: `http://127.0.0.1:${listeningPort}`,
284
+ /** Stops the runs the devtool started, then stops answering. */
285
+ async close() {
286
+ await runs.stopAll();
287
+ for (const stream of streams)
288
+ stream.end();
289
+ await pages.close();
290
+ server.closeAllConnections();
291
+ await new Promise((resolveClosed) => server.close(() => resolveClosed()));
292
+ },
293
+ };
294
+ }
@@ -0,0 +1,312 @@
1
+ import { z } from 'zod';
2
+ import type { RunEvent } from '../run/record/events.js';
3
+ import type { RunSummary } from '../run/record/run-types.js';
4
+ import { GivenAnswerSchema } from '../run/run-option-shapes.js';
5
+ /** What the devtool's page and its server exchange. */
6
+ /** One row of the Runs table. */
7
+ export type ListedRun = {
8
+ /** What the run's own files say. A run marked running whose process is gone reads stopped. */
9
+ summary: RunSummary;
10
+ /** The values of the run's input in one line, cut short. */
11
+ inputText: string;
12
+ /** The devtool started this run and is still connected to it: its events arrive as they
13
+ * happen, and it can be stopped from the page. */
14
+ connected: boolean;
15
+ };
16
+ /** What the server sends on its stream. A run's events arrive only while it is connected. */
17
+ export type StreamMessage = {
18
+ kind: 'run-event';
19
+ runId: string;
20
+ event: RunEvent;
21
+ } | {
22
+ kind: 'run-row';
23
+ row: ListedRun;
24
+ };
25
+ /** What the page needs to know about the devtool itself. */
26
+ export type DevtoolSettings = {
27
+ blueprintFile: string;
28
+ /** The folder that holds the runs, once the blueprint has been read. */
29
+ root?: string;
30
+ /** The replies file New run offers for a scripted run. */
31
+ scriptedRepliesFile?: string;
32
+ openAiKeyIsSet: boolean;
33
+ anthropicKeyIsSet: boolean;
34
+ };
35
+ export declare const NewRunRequestSchema: z.ZodObject<{
36
+ /** The input typed in, or copied from an earlier run. Left out when `from` is given. */
37
+ input: z.ZodOptional<z.ZodUnknown>;
38
+ /** The earlier run and the checkpoint of it this run starts from. */
39
+ from: z.ZodOptional<z.ZodObject<{
40
+ runId: z.ZodString;
41
+ checkpoint: z.ZodString;
42
+ }, "strict", z.ZodTypeAny, {
43
+ runId: string;
44
+ checkpoint: string;
45
+ }, {
46
+ runId: string;
47
+ checkpoint: string;
48
+ }>>;
49
+ stopAfter: z.ZodOptional<z.ZodString>;
50
+ callsAnsweredBy: z.ZodEnum<["codex", "claude-code", "openai-api", "anthropic-api", "bedrock-api", "gemini-api", "scripted"]>;
51
+ scriptedRepliesFile: z.ZodOptional<z.ZodString>;
52
+ questionsAnsweredBy: z.ZodEnum<["person", "recommendation"]>;
53
+ overrides: z.ZodOptional<z.ZodArray<z.ZodObject<{
54
+ phase: z.ZodOptional<z.ZodString>;
55
+ agent: z.ZodOptional<z.ZodString>;
56
+ modelSettings: z.ZodObject<{
57
+ effort: z.ZodOptional<z.ZodEnum<["none", "low", "medium", "high"]>>;
58
+ model: z.ZodOptional<z.ZodObject<{
59
+ codex: z.ZodOptional<z.ZodString>;
60
+ 'claude-code': z.ZodOptional<z.ZodString>;
61
+ 'openai-api': z.ZodOptional<z.ZodString>;
62
+ 'anthropic-api': z.ZodOptional<z.ZodString>;
63
+ 'bedrock-api': z.ZodOptional<z.ZodString>;
64
+ 'gemini-api': z.ZodOptional<z.ZodString>;
65
+ }, "strict", z.ZodTypeAny, {
66
+ codex?: string | undefined;
67
+ 'claude-code'?: string | undefined;
68
+ 'openai-api'?: string | undefined;
69
+ 'anthropic-api'?: string | undefined;
70
+ 'bedrock-api'?: string | undefined;
71
+ 'gemini-api'?: string | undefined;
72
+ }, {
73
+ codex?: string | undefined;
74
+ 'claude-code'?: string | undefined;
75
+ 'openai-api'?: string | undefined;
76
+ 'anthropic-api'?: string | undefined;
77
+ 'bedrock-api'?: string | undefined;
78
+ 'gemini-api'?: string | undefined;
79
+ }>>;
80
+ }, "strict", z.ZodTypeAny, {
81
+ model?: {
82
+ codex?: string | undefined;
83
+ 'claude-code'?: string | undefined;
84
+ 'openai-api'?: string | undefined;
85
+ 'anthropic-api'?: string | undefined;
86
+ 'bedrock-api'?: string | undefined;
87
+ 'gemini-api'?: string | undefined;
88
+ } | undefined;
89
+ effort?: "none" | "low" | "medium" | "high" | undefined;
90
+ }, {
91
+ model?: {
92
+ codex?: string | undefined;
93
+ 'claude-code'?: string | undefined;
94
+ 'openai-api'?: string | undefined;
95
+ 'anthropic-api'?: string | undefined;
96
+ 'bedrock-api'?: string | undefined;
97
+ 'gemini-api'?: string | undefined;
98
+ } | undefined;
99
+ effort?: "none" | "low" | "medium" | "high" | undefined;
100
+ }>;
101
+ }, "strict", z.ZodTypeAny, {
102
+ modelSettings: {
103
+ model?: {
104
+ codex?: string | undefined;
105
+ 'claude-code'?: string | undefined;
106
+ 'openai-api'?: string | undefined;
107
+ 'anthropic-api'?: string | undefined;
108
+ 'bedrock-api'?: string | undefined;
109
+ 'gemini-api'?: string | undefined;
110
+ } | undefined;
111
+ effort?: "none" | "low" | "medium" | "high" | undefined;
112
+ };
113
+ phase?: string | undefined;
114
+ agent?: string | undefined;
115
+ }, {
116
+ modelSettings: {
117
+ model?: {
118
+ codex?: string | undefined;
119
+ 'claude-code'?: string | undefined;
120
+ 'openai-api'?: string | undefined;
121
+ 'anthropic-api'?: string | undefined;
122
+ 'bedrock-api'?: string | undefined;
123
+ 'gemini-api'?: string | undefined;
124
+ } | undefined;
125
+ effort?: "none" | "low" | "medium" | "high" | undefined;
126
+ };
127
+ phase?: string | undefined;
128
+ agent?: string | undefined;
129
+ }>, "many">>;
130
+ }, "strict", z.ZodTypeAny, {
131
+ callsAnsweredBy: "codex" | "claude-code" | "openai-api" | "anthropic-api" | "bedrock-api" | "gemini-api" | "scripted";
132
+ questionsAnsweredBy: "person" | "recommendation";
133
+ input?: unknown;
134
+ overrides?: {
135
+ modelSettings: {
136
+ model?: {
137
+ codex?: string | undefined;
138
+ 'claude-code'?: string | undefined;
139
+ 'openai-api'?: string | undefined;
140
+ 'anthropic-api'?: string | undefined;
141
+ 'bedrock-api'?: string | undefined;
142
+ 'gemini-api'?: string | undefined;
143
+ } | undefined;
144
+ effort?: "none" | "low" | "medium" | "high" | undefined;
145
+ };
146
+ phase?: string | undefined;
147
+ agent?: string | undefined;
148
+ }[] | undefined;
149
+ stopAfter?: string | undefined;
150
+ scriptedRepliesFile?: string | undefined;
151
+ from?: {
152
+ runId: string;
153
+ checkpoint: string;
154
+ } | undefined;
155
+ }, {
156
+ callsAnsweredBy: "codex" | "claude-code" | "openai-api" | "anthropic-api" | "bedrock-api" | "gemini-api" | "scripted";
157
+ questionsAnsweredBy: "person" | "recommendation";
158
+ input?: unknown;
159
+ overrides?: {
160
+ modelSettings: {
161
+ model?: {
162
+ codex?: string | undefined;
163
+ 'claude-code'?: string | undefined;
164
+ 'openai-api'?: string | undefined;
165
+ 'anthropic-api'?: string | undefined;
166
+ 'bedrock-api'?: string | undefined;
167
+ 'gemini-api'?: string | undefined;
168
+ } | undefined;
169
+ effort?: "none" | "low" | "medium" | "high" | undefined;
170
+ };
171
+ phase?: string | undefined;
172
+ agent?: string | undefined;
173
+ }[] | undefined;
174
+ stopAfter?: string | undefined;
175
+ scriptedRepliesFile?: string | undefined;
176
+ from?: {
177
+ runId: string;
178
+ checkpoint: string;
179
+ } | undefined;
180
+ }>;
181
+ export declare const ResumeRequestSchema: z.ZodObject<{
182
+ answers: z.ZodOptional<z.ZodArray<z.ZodObject<{
183
+ questionId: z.ZodString;
184
+ answer: z.ZodString;
185
+ }, "strict", z.ZodTypeAny, {
186
+ questionId: string;
187
+ answer: string;
188
+ }, {
189
+ questionId: string;
190
+ answer: string;
191
+ }>, "many">>;
192
+ overrides: z.ZodOptional<z.ZodArray<z.ZodObject<{
193
+ phase: z.ZodOptional<z.ZodString>;
194
+ agent: z.ZodOptional<z.ZodString>;
195
+ modelSettings: z.ZodObject<{
196
+ effort: z.ZodOptional<z.ZodEnum<["none", "low", "medium", "high"]>>;
197
+ model: z.ZodOptional<z.ZodObject<{
198
+ codex: z.ZodOptional<z.ZodString>;
199
+ 'claude-code': z.ZodOptional<z.ZodString>;
200
+ 'openai-api': z.ZodOptional<z.ZodString>;
201
+ 'anthropic-api': z.ZodOptional<z.ZodString>;
202
+ 'bedrock-api': z.ZodOptional<z.ZodString>;
203
+ 'gemini-api': z.ZodOptional<z.ZodString>;
204
+ }, "strict", z.ZodTypeAny, {
205
+ codex?: string | undefined;
206
+ 'claude-code'?: string | undefined;
207
+ 'openai-api'?: string | undefined;
208
+ 'anthropic-api'?: string | undefined;
209
+ 'bedrock-api'?: string | undefined;
210
+ 'gemini-api'?: string | undefined;
211
+ }, {
212
+ codex?: string | undefined;
213
+ 'claude-code'?: string | undefined;
214
+ 'openai-api'?: string | undefined;
215
+ 'anthropic-api'?: string | undefined;
216
+ 'bedrock-api'?: string | undefined;
217
+ 'gemini-api'?: string | undefined;
218
+ }>>;
219
+ }, "strict", z.ZodTypeAny, {
220
+ model?: {
221
+ codex?: string | undefined;
222
+ 'claude-code'?: string | undefined;
223
+ 'openai-api'?: string | undefined;
224
+ 'anthropic-api'?: string | undefined;
225
+ 'bedrock-api'?: string | undefined;
226
+ 'gemini-api'?: string | undefined;
227
+ } | undefined;
228
+ effort?: "none" | "low" | "medium" | "high" | undefined;
229
+ }, {
230
+ model?: {
231
+ codex?: string | undefined;
232
+ 'claude-code'?: string | undefined;
233
+ 'openai-api'?: string | undefined;
234
+ 'anthropic-api'?: string | undefined;
235
+ 'bedrock-api'?: string | undefined;
236
+ 'gemini-api'?: string | undefined;
237
+ } | undefined;
238
+ effort?: "none" | "low" | "medium" | "high" | undefined;
239
+ }>;
240
+ }, "strict", z.ZodTypeAny, {
241
+ modelSettings: {
242
+ model?: {
243
+ codex?: string | undefined;
244
+ 'claude-code'?: string | undefined;
245
+ 'openai-api'?: string | undefined;
246
+ 'anthropic-api'?: string | undefined;
247
+ 'bedrock-api'?: string | undefined;
248
+ 'gemini-api'?: string | undefined;
249
+ } | undefined;
250
+ effort?: "none" | "low" | "medium" | "high" | undefined;
251
+ };
252
+ phase?: string | undefined;
253
+ agent?: string | undefined;
254
+ }, {
255
+ modelSettings: {
256
+ model?: {
257
+ codex?: string | undefined;
258
+ 'claude-code'?: string | undefined;
259
+ 'openai-api'?: string | undefined;
260
+ 'anthropic-api'?: string | undefined;
261
+ 'bedrock-api'?: string | undefined;
262
+ 'gemini-api'?: string | undefined;
263
+ } | undefined;
264
+ effort?: "none" | "low" | "medium" | "high" | undefined;
265
+ };
266
+ phase?: string | undefined;
267
+ agent?: string | undefined;
268
+ }>, "many">>;
269
+ }, "strict", z.ZodTypeAny, {
270
+ overrides?: {
271
+ modelSettings: {
272
+ model?: {
273
+ codex?: string | undefined;
274
+ 'claude-code'?: string | undefined;
275
+ 'openai-api'?: string | undefined;
276
+ 'anthropic-api'?: string | undefined;
277
+ 'bedrock-api'?: string | undefined;
278
+ 'gemini-api'?: string | undefined;
279
+ } | undefined;
280
+ effort?: "none" | "low" | "medium" | "high" | undefined;
281
+ };
282
+ phase?: string | undefined;
283
+ agent?: string | undefined;
284
+ }[] | undefined;
285
+ answers?: {
286
+ questionId: string;
287
+ answer: string;
288
+ }[] | undefined;
289
+ }, {
290
+ overrides?: {
291
+ modelSettings: {
292
+ model?: {
293
+ codex?: string | undefined;
294
+ 'claude-code'?: string | undefined;
295
+ 'openai-api'?: string | undefined;
296
+ 'anthropic-api'?: string | undefined;
297
+ 'bedrock-api'?: string | undefined;
298
+ 'gemini-api'?: string | undefined;
299
+ } | undefined;
300
+ effort?: "none" | "low" | "medium" | "high" | undefined;
301
+ };
302
+ phase?: string | undefined;
303
+ agent?: string | undefined;
304
+ }[] | undefined;
305
+ answers?: {
306
+ questionId: string;
307
+ answer: string;
308
+ }[] | undefined;
309
+ }>;
310
+ export type NewRunRequest = z.infer<typeof NewRunRequestSchema>;
311
+ export type ResumeRequest = z.infer<typeof ResumeRequestSchema>;
312
+ export type GivenAnswer = z.infer<typeof GivenAnswerSchema>;
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ import { CallsAnsweredBySchema, GivenAnswerSchema, ModelOverridesSchema, QuestionsAnsweredBySchema, } from '../run/run-option-shapes.js';
3
+ export const NewRunRequestSchema = z
4
+ .object({
5
+ /** The input typed in, or copied from an earlier run. Left out when `from` is given. */
6
+ input: z.unknown().optional(),
7
+ /** The earlier run and the checkpoint of it this run starts from. */
8
+ from: z
9
+ .object({ runId: z.string().regex(/^\d+$/), checkpoint: z.string().min(1) })
10
+ .strict()
11
+ .optional(),
12
+ stopAfter: z.string().optional(),
13
+ callsAnsweredBy: CallsAnsweredBySchema,
14
+ scriptedRepliesFile: z.string().optional(),
15
+ questionsAnsweredBy: QuestionsAnsweredBySchema,
16
+ overrides: ModelOverridesSchema.optional(),
17
+ })
18
+ .strict();
19
+ export const ResumeRequestSchema = z
20
+ .object({
21
+ answers: GivenAnswerSchema.array().optional(),
22
+ overrides: ModelOverridesSchema.optional(),
23
+ })
24
+ .strict();
@@ -0,0 +1,17 @@
1
+ import type { RunStore } from '../run/record/run-store.js';
2
+ import type { ListedRun } from './devtool-shapes.js';
3
+ /** The texts and numbers an input holds, in the order written, in one line cut short. */
4
+ export declare function inputInOneLine({ input }: {
5
+ input: unknown;
6
+ }): string;
7
+ /** One run's row, read from the store; undefined when no run with this id exists. */
8
+ export declare function listedRun({ store, runId, }: {
9
+ store: RunStore;
10
+ runId: string;
11
+ }): Promise<ListedRun | undefined>;
12
+ /** Every run in the store, newest first. `connectedRows` are the rows of the runs the devtool
13
+ * is connected to, which are more current than their stored summaries. */
14
+ export declare function listedRuns({ store, connectedRows, }: {
15
+ store: RunStore;
16
+ connectedRows: ListedRun[];
17
+ }): Promise<ListedRun[]>;