codeassembly-agent-logic 0.2.0 → 0.3.0
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/.meta/changelog.json +72 -0
- package/CHANGELOG.md +29 -0
- package/README.md +69 -7
- package/bin/agent-logic.js +1 -0
- package/dist/esm/agent/convert-with-agent.d.ts +53 -0
- package/dist/esm/agent/convert-with-agent.js +111 -0
- package/dist/esm/agent/create-conversion-session.d.ts +34 -0
- package/dist/esm/agent/create-conversion-session.js +62 -0
- package/dist/esm/agent/index.d.ts +3 -0
- package/dist/esm/agent/index.js +2 -0
- package/dist/esm/cli/check-coverage-command.js +7 -10
- package/dist/esm/cli/convert-command.d.ts +8 -0
- package/dist/esm/cli/convert-command.js +3 -1
- package/dist/esm/cli/convert-with-agent-command.d.ts +11 -0
- package/dist/esm/cli/convert-with-agent-command.js +183 -0
- package/dist/esm/cli/index.js +3 -3
- package/dist/esm/cli/run.d.ts +1 -1
- package/dist/esm/cli/run.js +9 -5
- package/dist/esm/client/create-conversion-client.d.ts +44 -0
- package/dist/esm/client/create-conversion-client.js +86 -0
- package/dist/esm/client/index.d.ts +3 -0
- package/dist/esm/client/index.js +1 -0
- package/dist/esm/conversion-protocol/conversion-schemas.d.ts +70 -0
- package/dist/esm/conversion-protocol/conversion-schemas.js +32 -0
- package/dist/esm/coverage-map/format-coverage-result.d.ts +6 -0
- package/dist/esm/coverage-map/format-coverage-result.js +7 -0
- package/dist/esm/react/hooks/describe-load-outcome.d.ts +0 -2
- package/dist/esm/react/hooks/describe-load-outcome.js +0 -3
- package/dist/esm/react/index.d.ts +0 -7
- package/dist/esm/react/index.js +0 -7
- package/dist/esm/server/conversion-store.d.ts +13 -0
- package/dist/esm/server/conversion-store.js +1 -0
- package/dist/esm/server/create-conversion-handler.d.ts +36 -0
- package/dist/esm/server/create-conversion-handler.js +199 -0
- package/dist/esm/server/create-memory-conversion-store.d.ts +12 -0
- package/dist/esm/server/create-memory-conversion-store.js +30 -0
- package/dist/esm/server/index.d.ts +5 -7
- package/dist/esm/server/index.js +2 -6
- package/docs/agent-instructions.md +19 -0
- package/package.json +24 -16
- package/dist/esm/contract/built-in-harnesses.d.ts +0 -22
- package/dist/esm/contract/built-in-harnesses.js +0 -30
- package/dist/esm/contract/conversion-job.d.ts +0 -36
- package/dist/esm/contract/conversion-job.js +0 -17
- package/dist/esm/contract/index.d.ts +0 -4
- package/dist/esm/contract/index.js +0 -3
- package/dist/esm/contract/viewer-contract.d.ts +0 -804
- package/dist/esm/contract/viewer-contract.js +0 -38
- package/dist/esm/react/hooks/conversion-client.d.ts +0 -77
- package/dist/esm/react/hooks/conversion-client.js +0 -132
- package/dist/esm/react/hooks/describe-agent-selection.d.ts +0 -6
- package/dist/esm/react/hooks/describe-agent-selection.js +0 -18
- package/dist/esm/react/hooks/useAgentBridge.d.ts +0 -28
- package/dist/esm/react/hooks/useAgentBridge.js +0 -52
- package/dist/esm/react/hooks/useAgentSync.d.ts +0 -29
- package/dist/esm/react/hooks/useAgentSync.js +0 -75
- package/dist/esm/react/hooks/useConversion.d.ts +0 -31
- package/dist/esm/react/hooks/useConversion.js +0 -177
- package/dist/esm/react/hooks/useHarnessList.d.ts +0 -26
- package/dist/esm/react/hooks/useHarnessList.js +0 -24
- package/dist/esm/react/hooks/usePromptDirectory.d.ts +0 -27
- package/dist/esm/react/hooks/usePromptDirectory.js +0 -34
- package/dist/esm/server/conversion-job-implementation.d.ts +0 -11
- package/dist/esm/server/conversion-job-implementation.js +0 -84
- package/dist/esm/server/create-prompts-app.d.ts +0 -26
- package/dist/esm/server/create-prompts-app.js +0 -41
- package/dist/esm/server/create-viewer-server-plugins.d.ts +0 -15
- package/dist/esm/server/create-viewer-server-plugins.js +0 -76
- package/dist/esm/server/prompt-directory-schemas.d.ts +0 -30
- package/dist/esm/server/prompt-directory-schemas.js +0 -11
- package/dist/esm/server/prompt-directory.d.ts +0 -40
- package/dist/esm/server/prompt-directory.js +0 -86
- package/dist/esm/server/viewer-contract-implementation.d.ts +0 -12
- package/dist/esm/server/viewer-contract-implementation.js +0 -85
- /package/dist/esm/{cli → package-files}/find-package-root.d.ts +0 -0
- /package/dist/esm/{cli → package-files}/find-package-root.js +0 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
3
|
+
import { convertWithAgent } from "../agent/convert-with-agent.js";
|
|
4
|
+
import { MAX_PROMPT_BYTES, startConversionRequestSchema, } from "../conversion-protocol/conversion-schemas.js";
|
|
5
|
+
import { formatPath } from "../schema/validate-config.js";
|
|
6
|
+
const MAX_BODY_BYTES = 4 * MAX_PROMPT_BYTES;
|
|
7
|
+
export const createConversionHandler = createConversionHandlerWith(convertWithAgent);
|
|
8
|
+
export function createConversionHandlerWith(convert) {
|
|
9
|
+
return ({ agent, store, authorize, timeoutMs, basePath = '' }) => {
|
|
10
|
+
const base = basePath.replace(/\/+$/, '');
|
|
11
|
+
const runs = new Map();
|
|
12
|
+
async function endByTimeout(state) {
|
|
13
|
+
const reason = `The conversion did not finish within ${formatDuration(timeoutMs)}.`;
|
|
14
|
+
try {
|
|
15
|
+
await store.finish(state.id, { status: 'failed', id: state.id, name: state.name, reason });
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
runs.get(state.id)?.controller.abort();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function endTimedOutRun(state) {
|
|
22
|
+
try {
|
|
23
|
+
await endByTimeout(state);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function readCurrent(id) {
|
|
29
|
+
const state = await store.read(id);
|
|
30
|
+
if (state?.status !== 'running' || Date.parse(state.deadline) > Date.now())
|
|
31
|
+
return state;
|
|
32
|
+
await endByTimeout(state);
|
|
33
|
+
return store.read(id);
|
|
34
|
+
}
|
|
35
|
+
async function run(request, signal) {
|
|
36
|
+
const { id, name, prompt } = request;
|
|
37
|
+
try {
|
|
38
|
+
let ended = {
|
|
39
|
+
status: 'failed',
|
|
40
|
+
id,
|
|
41
|
+
name,
|
|
42
|
+
reason: 'The conversion ended without a result.',
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
const events = convert({ prompt, name, agent, signal });
|
|
46
|
+
for await (const event of events) {
|
|
47
|
+
if (event.type === 'result')
|
|
48
|
+
ended = { status: 'done', id, name, result: toConversionResult(event.result) };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
ended = { status: 'failed', id, name, reason: describeError(error) };
|
|
53
|
+
}
|
|
54
|
+
await store.finish(id, ended);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
const entry = runs.get(id);
|
|
60
|
+
if (entry !== undefined)
|
|
61
|
+
clearTimeout(entry.timer);
|
|
62
|
+
runs.delete(id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function start(request) {
|
|
66
|
+
const text = await readLimitedText(request, MAX_BODY_BYTES);
|
|
67
|
+
if (text === undefined)
|
|
68
|
+
return respondWithProblem(413, `The request body must not exceed ${MAX_BODY_BYTES} bytes.`);
|
|
69
|
+
let body;
|
|
70
|
+
try {
|
|
71
|
+
body = JSON.parse(text);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return respondWithProblem(400, 'The request body is not JSON.');
|
|
75
|
+
}
|
|
76
|
+
const parsed = startConversionRequestSchema.safeParse(body);
|
|
77
|
+
if (!parsed.success) {
|
|
78
|
+
const problems = parsed.error.issues.map(({ path, message }) => ({ path: formatPath(path), message }));
|
|
79
|
+
return Response.json({ problems }, { status: 400 });
|
|
80
|
+
}
|
|
81
|
+
const { prompt, name } = parsed.data;
|
|
82
|
+
const id = randomUUID();
|
|
83
|
+
const startedAt = Date.now();
|
|
84
|
+
const state = {
|
|
85
|
+
status: 'running',
|
|
86
|
+
id,
|
|
87
|
+
name,
|
|
88
|
+
startedAt: new Date(startedAt).toISOString(),
|
|
89
|
+
deadline: new Date(startedAt + timeoutMs).toISOString(),
|
|
90
|
+
};
|
|
91
|
+
await store.create(state);
|
|
92
|
+
const controller = new AbortController();
|
|
93
|
+
const timer = setTimeout(() => void endTimedOutRun(state), timeoutMs);
|
|
94
|
+
runs.set(id, { controller, timer });
|
|
95
|
+
void run({ id, name, prompt }, controller.signal);
|
|
96
|
+
return Response.json(state, { status: 201, headers: { Location: `${base}/${encodeURIComponent(id)}` } });
|
|
97
|
+
}
|
|
98
|
+
async function cancel(id) {
|
|
99
|
+
const state = await readCurrent(id);
|
|
100
|
+
if (state === undefined)
|
|
101
|
+
return respondWithNotFound();
|
|
102
|
+
if (state.status === 'running') {
|
|
103
|
+
const cancelled = { status: 'cancelled', id, name: state.name };
|
|
104
|
+
if (await store.finish(id, cancelled)) {
|
|
105
|
+
runs.get(id)?.controller.abort();
|
|
106
|
+
return Response.json(cancelled, { status: 200 });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const ended = await store.read(id);
|
|
110
|
+
return ended === undefined ? respondWithNotFound() : Response.json(ended, { status: 409 });
|
|
111
|
+
}
|
|
112
|
+
async function serve(request, id) {
|
|
113
|
+
if (!(await authorize(request)))
|
|
114
|
+
return respondWithProblem(403, 'The request is not authorized.');
|
|
115
|
+
if (id === undefined)
|
|
116
|
+
return start(request);
|
|
117
|
+
if (request.method === 'DELETE')
|
|
118
|
+
return cancel(id);
|
|
119
|
+
const state = await readCurrent(id);
|
|
120
|
+
return state === undefined ? respondWithNotFound() : Response.json(state, { status: 200 });
|
|
121
|
+
}
|
|
122
|
+
return async (request) => {
|
|
123
|
+
const route = matchRoute(base, new URL(request.url).pathname);
|
|
124
|
+
if (route === undefined)
|
|
125
|
+
return respondWithProblem(404, 'The path is not served.');
|
|
126
|
+
const allowed = route.id === undefined ? ['POST'] : ['DELETE', 'GET'];
|
|
127
|
+
if (!allowed.includes(request.method)) {
|
|
128
|
+
const message = `The method ${request.method} is not allowed here.`;
|
|
129
|
+
return respondWithProblem(405, message, { Allow: allowed.join(', ') });
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return await serve(request, route.id);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return respondWithProblem(500, `The conversion handler failed: ${describeError(error)}`);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function formatDuration(durationMs) {
|
|
141
|
+
const minutes = durationMs / 60_000;
|
|
142
|
+
if (Number.isSafeInteger(minutes))
|
|
143
|
+
return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`;
|
|
144
|
+
const seconds = durationMs / 1000;
|
|
145
|
+
return `${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
|
|
146
|
+
}
|
|
147
|
+
function matchRoute(base, pathname) {
|
|
148
|
+
if (!pathname.startsWith(base))
|
|
149
|
+
return undefined;
|
|
150
|
+
const rest = pathname.slice(base.length);
|
|
151
|
+
if (rest === '' || rest === '/')
|
|
152
|
+
return { id: undefined };
|
|
153
|
+
const match = /^\/([^/]+)\/?$/.exec(rest);
|
|
154
|
+
const segment = match?.[1];
|
|
155
|
+
if (segment === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
try {
|
|
158
|
+
return { id: decodeURIComponent(segment) };
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function readLimitedText(request, limit) {
|
|
165
|
+
if (Number(request.headers.get('Content-Length')) > limit)
|
|
166
|
+
return undefined;
|
|
167
|
+
if (request.body === null)
|
|
168
|
+
return '';
|
|
169
|
+
const reader = request.body.getReader();
|
|
170
|
+
const chunks = [];
|
|
171
|
+
let length = 0;
|
|
172
|
+
for (let chunk = await reader.read(); !chunk.done; chunk = await reader.read()) {
|
|
173
|
+
length += chunk.value.byteLength;
|
|
174
|
+
if (length > limit) {
|
|
175
|
+
await reader.cancel();
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
chunks.push(chunk.value);
|
|
179
|
+
}
|
|
180
|
+
const bytes = new Uint8Array(length);
|
|
181
|
+
let offset = 0;
|
|
182
|
+
for (const chunk of chunks) {
|
|
183
|
+
bytes.set(chunk, offset);
|
|
184
|
+
offset += chunk.byteLength;
|
|
185
|
+
}
|
|
186
|
+
return new TextDecoder().decode(bytes);
|
|
187
|
+
}
|
|
188
|
+
function respondWithNotFound() {
|
|
189
|
+
return respondWithProblem(404, 'The conversion was not found.');
|
|
190
|
+
}
|
|
191
|
+
function respondWithProblem(status, message, headers) {
|
|
192
|
+
const problems = [{ path: '', message }];
|
|
193
|
+
return Response.json({ problems }, { status, ...(headers !== undefined && { headers }) });
|
|
194
|
+
}
|
|
195
|
+
function toConversionResult(result) {
|
|
196
|
+
if (result.ok)
|
|
197
|
+
return { ok: true, text: result.text };
|
|
198
|
+
return 'problems' in result ? { ok: false, problems: result.problems } : { ok: false, outOfScope: result.outOfScope };
|
|
199
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConversionStore } from './conversion-store.js';
|
|
2
|
+
export interface MemoryConversionStoreOptions {
|
|
3
|
+
/** How long the store keeps a conversion after it ends; one hour by default. */
|
|
4
|
+
readonly retentionMs?: number;
|
|
5
|
+
/** Returns the current time in milliseconds; `Date.now` by default. */
|
|
6
|
+
readonly now?: () => number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a store that keeps conversions in this process's memory and drops each ended one once its retention period
|
|
10
|
+
* has passed, which every access checks.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMemoryConversionStore({ retentionMs, now, }?: MemoryConversionStoreOptions): ConversionStore;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const DEFAULT_RETENTION_MS = 60 * 60 * 1000;
|
|
2
|
+
export function createMemoryConversionStore({ retentionMs = DEFAULT_RETENTION_MS, now = Date.now, } = {}) {
|
|
3
|
+
const entries = new Map();
|
|
4
|
+
function sweep() {
|
|
5
|
+
const cutoff = now() - retentionMs;
|
|
6
|
+
for (const [id, { endedAt }] of entries) {
|
|
7
|
+
if (endedAt !== undefined && endedAt <= cutoff)
|
|
8
|
+
entries.delete(id);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
create(state) {
|
|
13
|
+
sweep();
|
|
14
|
+
entries.set(state.id, { state, endedAt: state.status === 'running' ? undefined : now() });
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
},
|
|
17
|
+
finish(id, ended) {
|
|
18
|
+
sweep();
|
|
19
|
+
const entry = entries.get(id);
|
|
20
|
+
if (entry?.state.status !== 'running')
|
|
21
|
+
return Promise.resolve(false);
|
|
22
|
+
entries.set(id, { state: ended, endedAt: now() });
|
|
23
|
+
return Promise.resolve(true);
|
|
24
|
+
},
|
|
25
|
+
read(id) {
|
|
26
|
+
sweep();
|
|
27
|
+
return Promise.resolve(entries.get(id)?.state);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/** `./server` entry: the
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export * from './prompt-directory-schemas.js';
|
|
7
|
-
export * from './viewer-contract-implementation.js';
|
|
1
|
+
/** `./server` entry: the conversion handler, its stores, and the types of the conversion protocol. */
|
|
2
|
+
export type { ConversionResult, ConversionState, EndedConversionState, StartConversionRequest, } from '../conversion-protocol/conversion-schemas.js';
|
|
3
|
+
export type { ConversionStore } from './conversion-store.js';
|
|
4
|
+
export { type ConversionHandlerOptions, createConversionHandler } from './create-conversion-handler.js';
|
|
5
|
+
export { createMemoryConversionStore, type MemoryConversionStoreOptions } from './create-memory-conversion-store.js';
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from "./create-viewer-server-plugins.js";
|
|
4
|
-
export * from "./prompt-directory.js";
|
|
5
|
-
export * from "./prompt-directory-schemas.js";
|
|
6
|
-
export * from "./viewer-contract-implementation.js";
|
|
1
|
+
export { createConversionHandler } from "./create-conversion-handler.js";
|
|
2
|
+
export { createMemoryConversionStore } from "./create-memory-conversion-store.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Converting a prompt with the conversion tools
|
|
2
|
+
|
|
3
|
+
You convert an agent's prompt into a draft of its logic, following the extraction rules below. The message contains a header line that names the prompt's file, a blank line, and then the prompt: Everything after that blank line is the prompt, verbatim, and every quote is copied from it. You have two tools, and no others:
|
|
4
|
+
|
|
5
|
+
- `check_coverage` checks a coverage map of the prompt against the prompt.
|
|
6
|
+
- `submit_draft` converts a draft into an agent-logic config, or reports the problems that prevent it. Where the rules speak of the `convert` script, they mean this tool.
|
|
7
|
+
|
|
8
|
+
## Procedure
|
|
9
|
+
|
|
10
|
+
1. Read the prompt in full, then read the extraction rules in full.
|
|
11
|
+
2. Judge whether the prompt is out of scope by the rules' condition, then write the draft that they describe, or the out-of-scope draft. An out-of-scope draft skips step 3.
|
|
12
|
+
3. Check the draft against the prompt, and correct it where a check fails:
|
|
13
|
+
- **Coverage.** Read the prompt again from the top, one paragraph or list item at a time, and write a coverage map: an array with an entry `{ "quote": "...", "element": "..." }` for each instruction in it. The `quote` copies the instruction verbatim and occurs in the prompt exactly once. The `element` names the state, action, or transition that holds it, or is `ambient`, `unconverted`, or `none`. A list item or paragraph that states three instructions takes three entries. Include the instructions inside a dense step, each of which is an action of that step's state, and the rules of a section that states how to format output, such as an option format. Add each instruction whose entry names `none` to the draft where the rules' "What to extract", "Ambient instructions", and "Passages you cannot convert" place it, and name its element in the entry.
|
|
14
|
+
- **Map check.** Call `check_coverage` with the map. It lists each block of the prompt that no entry quotes, as `line <N>: <opening words>`, and each entry whose quote does not occur exactly once. Map every instruction of each listed block, holding it in the draft as the Coverage bullet says, lengthen each listed quote until it occurs once, and call it again. The tool answers 3 calls; after the third, go on to the next check, whatever it reported.
|
|
15
|
+
- **Inputs.** List each input that the prompt tells the agent to read, fetch, or receive, such as a page, a list, or a field of the request. For each one, find an element that uses what the input supplies: a later action, a guard, or an ambient rule. Record an `unused-input` finding, as the rules' "Findings" section states, for each input that no element uses.
|
|
16
|
+
- **Inferred quotes.** Read the quote of each element that has `meta.inferred` on its own, and ask whether those words name the element, as the rules' "Quotes" section requires. Replace a quote that names a neighbouring step or the question that precedes the element.
|
|
17
|
+
4. Call `submit_draft` with the draft's JSON text.
|
|
18
|
+
5. When it reports problems, it lists each one by its path in the draft. Correct every listed entry and submit the draft again. The tool accepts 5 submissions; when it says that it accepts no more, stop.
|
|
19
|
+
6. When it reports that the config is accepted, or that the prompt is out of scope, end your turn without submitting again: The last submission is the conversion's result.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeassembly-agent-logic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Model of an agent prompt's states and transitions, with React and server entries for the apps that present it",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -28,10 +28,14 @@
|
|
|
28
28
|
"types": "./dist/esm/index.d.ts",
|
|
29
29
|
"import": "./dist/esm/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./agent": {
|
|
32
|
+
"types": "./dist/esm/agent/index.d.ts",
|
|
33
|
+
"import": "./dist/esm/agent/index.js"
|
|
34
|
+
},
|
|
31
35
|
"./agent-logic.schema.json": "./schema/agent-logic.schema.json",
|
|
32
|
-
"./
|
|
33
|
-
"types": "./dist/esm/
|
|
34
|
-
"import": "./dist/esm/
|
|
36
|
+
"./client": {
|
|
37
|
+
"types": "./dist/esm/client/index.d.ts",
|
|
38
|
+
"import": "./dist/esm/client/index.js"
|
|
35
39
|
},
|
|
36
40
|
"./react": {
|
|
37
41
|
"types": "./dist/esm/react/index.d.ts",
|
|
@@ -56,42 +60,46 @@
|
|
|
56
60
|
".meta/changelog.json"
|
|
57
61
|
],
|
|
58
62
|
"dependencies": {
|
|
59
|
-
"@
|
|
60
|
-
"@williamthorsen/toolbelt.errors": "0.9.0",
|
|
63
|
+
"@williamthorsen/toolbelt.errors": "0.11.1",
|
|
61
64
|
"@xyflow/react": "12.12.1",
|
|
62
65
|
"elkjs": "0.12.1",
|
|
63
|
-
"hono": "4.13.17",
|
|
64
66
|
"zod": "4.6.7"
|
|
65
67
|
},
|
|
66
68
|
"devDependencies": {
|
|
69
|
+
"@modelcontextprotocol/client": "2.4.0",
|
|
70
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
67
71
|
"@testing-library/dom": "10.4.2",
|
|
68
72
|
"@testing-library/jest-dom": "7.0.1",
|
|
69
73
|
"@testing-library/react": "16.3.3",
|
|
70
|
-
"@testing-library/user-event": "14.6.
|
|
74
|
+
"@testing-library/user-event": "14.6.10",
|
|
71
75
|
"@types/node": "24.19.2",
|
|
72
76
|
"@types/react": "19.3.0",
|
|
73
77
|
"@types/react-dom": "19.3.0",
|
|
74
|
-
"@vitejs/plugin-react": "6.
|
|
75
|
-
"@williamthorsen/nmr": "
|
|
76
|
-
"@williamthorsen/
|
|
77
|
-
"eslint": "10.
|
|
78
|
-
"eslint-plugin-jest-dom": "5.10.
|
|
78
|
+
"@vitejs/plugin-react": "6.3.0",
|
|
79
|
+
"@williamthorsen/nmr": "2.2.2",
|
|
80
|
+
"@williamthorsen/toolbelt.acp": "0.3.0",
|
|
81
|
+
"eslint": "10.15.0",
|
|
82
|
+
"eslint-plugin-jest-dom": "5.10.2",
|
|
79
83
|
"eslint-plugin-react": "7.37.5",
|
|
80
84
|
"eslint-plugin-react-hooks": "7.1.1",
|
|
81
85
|
"eslint-plugin-testing-library": "7.16.2",
|
|
82
86
|
"happy-dom": "21.0.4",
|
|
83
87
|
"react": "19.3.1",
|
|
84
88
|
"react-dom": "19.3.1",
|
|
85
|
-
"vite": "8.3.
|
|
89
|
+
"vite": "8.3.8",
|
|
86
90
|
"vitest": "5.1.0",
|
|
87
91
|
"xstate": "5.33.4"
|
|
88
92
|
},
|
|
89
93
|
"peerDependencies": {
|
|
90
|
-
"@
|
|
94
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
95
|
+
"@williamthorsen/toolbelt.acp": "^0.3.0",
|
|
91
96
|
"react": "^19.0.0"
|
|
92
97
|
},
|
|
93
98
|
"peerDependenciesMeta": {
|
|
94
|
-
"@
|
|
99
|
+
"@modelcontextprotocol/server": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"@williamthorsen/toolbelt.acp": {
|
|
95
103
|
"optional": true
|
|
96
104
|
},
|
|
97
105
|
"react": {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/** The prompts directory, relative to the config file's directory, when the config names none. */
|
|
3
|
-
export declare const DEFAULT_PROMPTS_DIRECTORY = "prompts";
|
|
4
|
-
/** The harnesses that apply when neither the environment variable nor the config file defines any. */
|
|
5
|
-
export declare const viewerBuiltInHarnesses: {
|
|
6
|
-
default: string;
|
|
7
|
-
harnesses: {
|
|
8
|
-
'claude-code': {
|
|
9
|
-
label: string;
|
|
10
|
-
command: string[];
|
|
11
|
-
test: string[];
|
|
12
|
-
interactive: string[];
|
|
13
|
-
mcpArgs: string[];
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
/** The viewer's own keys in `harness.config.json`: `promptsDirectory` is resolved against the file's directory. */
|
|
18
|
-
export declare const viewerConfigSchema: z.ZodObject<{
|
|
19
|
-
promptsDirectory: z.ZodDefault<z.ZodString>;
|
|
20
|
-
}, z.core.$strip>;
|
|
21
|
-
/** Returns the text of a `harness.config.json` that defines the built-in settings. */
|
|
22
|
-
export declare function buildConfigTemplate(): string;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export const DEFAULT_PROMPTS_DIRECTORY = 'prompts';
|
|
3
|
-
export const viewerBuiltInHarnesses = {
|
|
4
|
-
default: 'claude-code',
|
|
5
|
-
harnesses: {
|
|
6
|
-
'claude-code': {
|
|
7
|
-
label: 'Claude Code',
|
|
8
|
-
command: [
|
|
9
|
-
'claude',
|
|
10
|
-
'-p',
|
|
11
|
-
'Run the convert-agent-prompt skill on the prompt file {prompt}, with the output path {output} and the problems path {problems}.',
|
|
12
|
-
'--allowedTools',
|
|
13
|
-
'Read',
|
|
14
|
-
'Write',
|
|
15
|
-
'Skill',
|
|
16
|
-
'Bash(pnpm *)',
|
|
17
|
-
],
|
|
18
|
-
test: ['claude', '-p', 'Reply with OK.'],
|
|
19
|
-
interactive: ['claude'],
|
|
20
|
-
mcpArgs: ['--mcp-config', '{"mcpServers":{"agent-logic":{"type":"http","url":"{mcpUrl}"}}}'],
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
export const viewerConfigSchema = z.object({
|
|
25
|
-
promptsDirectory: z.string().min(1, 'Name a directory').default(DEFAULT_PROMPTS_DIRECTORY),
|
|
26
|
-
});
|
|
27
|
-
export function buildConfigTemplate() {
|
|
28
|
-
const template = { ...viewerBuiltInHarnesses, promptsDirectory: DEFAULT_PROMPTS_DIRECTORY };
|
|
29
|
-
return `${JSON.stringify(template, null, 2)}\n`;
|
|
30
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Job } from '@williamthorsen/telefactor/client';
|
|
2
|
-
import { type JobRequest, type JobResult } from '@williamthorsen/telefactor/contract';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
/** The shape of the problems file that `convert --problems-file` writes for a draft that cannot be converted. */
|
|
5
|
-
export declare const problemsFileSchema: z.ZodObject<{
|
|
6
|
-
problems: z.ZodArray<z.ZodObject<{
|
|
7
|
-
path: z.ZodString;
|
|
8
|
-
message: z.ZodString;
|
|
9
|
-
}, z.core.$strip>>;
|
|
10
|
-
}, z.core.$strip>;
|
|
11
|
-
/**
|
|
12
|
-
* The conversion job: The page sends the prompt and a name, and a `done` job returns the outcome of the `convert`
|
|
13
|
-
* script. A client loads `text` through its own parse-and-validate path, so `config` is not described here.
|
|
14
|
-
*/
|
|
15
|
-
export declare const conversionJob: import("@williamthorsen/telefactor/contract").JobDeclaration<z.ZodObject<{
|
|
16
|
-
name: z.ZodString;
|
|
17
|
-
}, z.core.$strip>, z.ZodUnion<readonly [z.ZodObject<{
|
|
18
|
-
ok: z.ZodLiteral<true>;
|
|
19
|
-
config: z.ZodUnknown;
|
|
20
|
-
text: z.ZodString;
|
|
21
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
22
|
-
ok: z.ZodLiteral<false>;
|
|
23
|
-
problems: z.ZodArray<z.ZodObject<{
|
|
24
|
-
path: z.ZodString;
|
|
25
|
-
message: z.ZodString;
|
|
26
|
-
}, z.core.$strip>>;
|
|
27
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
28
|
-
ok: z.ZodLiteral<false>;
|
|
29
|
-
outOfScope: z.ZodObject<{
|
|
30
|
-
reason: z.ZodString;
|
|
31
|
-
}, z.core.$strip>;
|
|
32
|
-
}, z.core.$strip>]>>;
|
|
33
|
-
/** The body that starts a conversion: the prompt, its name, and the harness, the default harness when omitted. */
|
|
34
|
-
export type ConversionRequest = JobRequest<typeof conversionJob>;
|
|
35
|
-
/** A conversion job. `result` is present when the job is `done`, and `error` when it is `failed`. */
|
|
36
|
-
export type ConversionJob = Job<JobResult<typeof conversionJob>>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineJob } from '@williamthorsen/telefactor/contract';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
const problemSchema = z.object({ path: z.string(), message: z.string() });
|
|
4
|
-
export const problemsFileSchema = z.object({ problems: z.array(problemSchema) });
|
|
5
|
-
export const conversionJob = defineJob({
|
|
6
|
-
input: z.object({
|
|
7
|
-
name: z
|
|
8
|
-
.string()
|
|
9
|
-
.max(100)
|
|
10
|
-
.refine((value) => value.trim() !== '', 'Enter a name'),
|
|
11
|
-
}),
|
|
12
|
-
result: z.union([
|
|
13
|
-
z.object({ ok: z.literal(true), config: z.unknown(), text: z.string() }),
|
|
14
|
-
z.object({ ok: z.literal(false), problems: z.array(problemSchema) }),
|
|
15
|
-
z.object({ ok: z.literal(false), outOfScope: z.object({ reason: z.string() }) }),
|
|
16
|
-
]),
|
|
17
|
-
});
|