cornfield 0.15.0 → 0.17.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.
@@ -10,6 +10,7 @@
10
10
  * GET /api/agent-runs/<runId> one run
11
11
  * POST /api/agent-runs the dashboard's Start an agent: the same body as the API
12
12
  * POST /api/agent-runs/<runId>/stop { note? } asks the runner to stop
13
+ * POST /api/agent-runs/<runId>/answer { action: 'continue' | 'stop' | 'reply', text? } answers a run that reported `waiting`
13
14
  *
14
15
  * **The call takes an agent token and nothing else,** exactly as the review API takes a review token (server/review-api.js): it runs
15
16
  * before the sign-in guard (a script has no cookie), reads no cookie, needs no same-origin check (a browser never adds an `Authorization`
@@ -156,7 +157,7 @@ export async function serveAgentCall(req, res, ctx) {
156
157
  * @returns {Promise<boolean>} whether the path was one of these
157
158
  */
158
159
  export async function serveRunRoutes(req, res, reqPath, ctx) {
159
- const m = /^\/api\/agent-runs(?:\/(run-[0-9A-Za-z]{26}))?(\/stop)?$/.exec(reqPath);
160
+ const m = /^\/api\/agent-runs(?:\/(run-[0-9A-Za-z]{26}))?(\/stop|\/answer)?$/.exec(reqPath);
160
161
  if (!m || (m[2] && !m[1])) return false;
161
162
  const { auth, runs, session } = ctx;
162
163
  const runId = m[1] ?? null;
@@ -183,7 +184,10 @@ export async function serveRunRoutes(req, res, reqPath, ctx) {
183
184
  const url = new URL(req.url || '/', 'http://localhost');
184
185
  if (url.searchParams.get('follow') === '1') {
185
186
  try {
186
- await runs.follow(auth.forgeFor(session));
187
+ const forge = auth.forgeFor(session);
188
+ // Requests written by hand first, so a run just found is followed in the same look
189
+ await runs.discover(forge);
190
+ await runs.follow(forge);
187
191
  } catch (err) {
188
192
  console.error(`[cornfield] agent runs: the dashboard's look at the forge could not begin: ${err instanceof Error ? err.message : err}`);
189
193
  }
@@ -211,9 +215,15 @@ export async function serveRunRoutes(req, res, reqPath, ctx) {
211
215
  problem = { status: 400, message: 'The request could not be read.' };
212
216
  }
213
217
  }
214
- if (runId && !problem && (body === null || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some((k) => k !== 'note'))) problem = { status: 400, message: 'A stop request is { note? }.' };
218
+ const answering = m[2] === '/answer';
219
+ if (runId && !problem && (body === null || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some((k) => !(answering ? ['action', 'text'] : ['note']).includes(k)))) {
220
+ problem = { status: 400, message: answering ? 'An answer is { action: "continue" | "stop" | "reply", text? }.' : 'A stop request is { note? }.' };
221
+ }
215
222
  try {
216
- if (runId) {
223
+ if (runId && answering) {
224
+ const answered = await runs.answer(ask, { runId, action: /** @type {any} */ (body)?.action, text: /** @type {any} */ (body)?.text, problem });
225
+ send(res, 200, { ok: true, ...answered });
226
+ } else if (runId) {
217
227
  const stopped = await runs.stop(ask, { runId, note: /** @type {any} */ (body)?.note, problem });
218
228
  send(res, 200, { ok: true, ...stopped });
219
229
  } else {