@omercnet/paseo-omp 5.6.1-next.451.1 → 5.6.1-next.453.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-omp",
3
- "version": "5.6.1-next.451.1",
3
+ "version": "5.6.1-next.453.1",
4
4
  "type": "module",
5
5
  "description": "Paseo integration for OMP, including its direct provider and workspace tooling.",
6
6
  "license": "MIT",
@@ -1,2 +1,2 @@
1
1
  /** Release Please keeps this bundle-safe constant aligned with package.json. */
2
- export const PASEO_OMP_PACKAGE_VERSION = "5.6.1-next.451.1"; // x-release-please-version
2
+ export const PASEO_OMP_PACKAGE_VERSION = "5.6.1-next.453.1"; // x-release-please-version
@@ -32,6 +32,8 @@ const MAX_TODOS = 256;
32
32
  const MAX_TURN_NATIVE_IDENTITIES = 1_024;
33
33
  const MAX_REPLAY_NATIVE_IDENTITIES = 100_000;
34
34
  const MAX_PUBLIC_TOOL_PAYLOAD_BYTES = 256 * 1024;
35
+ /** Paseo caps a whole tool_call item at 64K units (0.15), so the ask card keeps clear of it. */
36
+ const MAX_ASK_TEXT_BYTES = 32 * 1024;
35
37
  const MAX_ACTIVE_TOOL_BYTES = 4 * 1024 * 1024;
36
38
  const MAX_REVERT_TARGETS = MAX_REPLAY_NATIVE_IDENTITIES;
37
39
  const REVERT_TOKEN_PATTERN = /^omp-revert:[A-Za-z0-9_-]{43}$/u;
@@ -261,6 +263,154 @@ function resultDetails(value: JsonValue): Record<string, JsonValue> | undefined
261
263
  return jsonRecord(envelope?.details);
262
264
  }
263
265
 
266
+ type AskProjectedAnswer = {
267
+ id?: string;
268
+ question: string;
269
+ multi: boolean;
270
+ selected: string[];
271
+ custom?: string;
272
+ note?: string;
273
+ noteOption?: string;
274
+ timedOut: boolean;
275
+ };
276
+
277
+ /** OMP folds `\r` runs in ids and questions inside `execute`, after the call args are published. */
278
+ function askKey(value: string): string {
279
+ return value.replaceAll("\r\n", "\n").replace(/\r+/gu, " ");
280
+ }
281
+
282
+ function askQuestionRecords(
283
+ input: Record<string, JsonValue> | undefined,
284
+ ): Array<{ id?: string; question: string }> {
285
+ const questions = input?.questions;
286
+ if (!Array.isArray(questions)) return [];
287
+ return questions.flatMap((value) => {
288
+ const record = jsonRecord(value);
289
+ const question = firstString(record, "question");
290
+ return question === undefined ? [] : [{ id: firstString(record, "id"), question }];
291
+ });
292
+ }
293
+
294
+ function askAnswerRecord(value: JsonValue | undefined): AskProjectedAnswer | undefined {
295
+ const record = jsonRecord(value);
296
+ const question = firstString(record, "question");
297
+ if (question === undefined) return undefined;
298
+ const selectedOptions = record?.selectedOptions;
299
+ return {
300
+ id: firstString(record, "id"),
301
+ question,
302
+ multi: record?.multi === true,
303
+ selected: Array.isArray(selectedOptions)
304
+ ? selectedOptions.flatMap((option) => (typeof option === "string" ? [option] : []))
305
+ : [],
306
+ custom: firstString(record, "customInput"),
307
+ note: firstString(record, "note"),
308
+ noteOption: firstString(record, "noteOption"),
309
+ timedOut: record?.timedOut === true,
310
+ };
311
+ }
312
+
313
+ /** OMP reports a single answered question inline and several as `results`; both carry labels. */
314
+ function askAnswerRecords(details: Record<string, JsonValue> | undefined): AskProjectedAnswer[] {
315
+ const results = details?.results;
316
+ if (Array.isArray(results)) {
317
+ return results.flatMap((value) => {
318
+ const answer = askAnswerRecord(value);
319
+ return answer ? [answer] : [];
320
+ });
321
+ }
322
+ const single = askAnswerRecord(details);
323
+ return single ? [single] : [];
324
+ }
325
+
326
+ /** Claims the answer for one asked question; claimed answers are never rendered twice. */
327
+ function takeAskAnswer(
328
+ asked: { id?: string; question: string },
329
+ index: number,
330
+ answers: readonly AskProjectedAnswer[],
331
+ used: Set<number>,
332
+ ): AskProjectedAnswer | undefined {
333
+ const open = (candidate: number) => candidate >= 0 && !used.has(candidate);
334
+ const askedId = asked.id === undefined ? undefined : askKey(asked.id);
335
+ let found =
336
+ askedId === undefined
337
+ ? -1
338
+ : answers.findIndex(
339
+ (answer, candidate) =>
340
+ open(candidate) && answer.id !== undefined && askKey(answer.id) === askedId,
341
+ );
342
+ // Single-question results are flat and carry no id.
343
+ if (found < 0 && answers.length === 1 && answers[0]?.id === undefined && open(0)) found = 0;
344
+ if (found < 0) {
345
+ const askedQuestion = askKey(asked.question);
346
+ found = answers.findIndex(
347
+ (answer, candidate) => open(candidate) && askKey(answer.question) === askedQuestion,
348
+ );
349
+ }
350
+ if (found < 0 && open(index)) {
351
+ const positional = answers[index];
352
+ if (askedId === undefined || positional?.id === undefined) found = index;
353
+ }
354
+ if (found < 0) return undefined;
355
+ used.add(found);
356
+ return answers[found];
357
+ }
358
+
359
+ function askAnswerLines(answer: AskProjectedAnswer): string[] {
360
+ const lines: string[] = [];
361
+ const selected = [...answer.selected];
362
+ if (answer.custom) selected.push(answer.custom);
363
+ if (selected.length > 0) {
364
+ lines.push(`${selected.join(", ")}${answer.timedOut ? " (auto-selected after timeout)" : ""}`);
365
+ } else {
366
+ lines.push(answer.multi ? "(none selected)" : "(no answer)");
367
+ }
368
+ if (answer.note) {
369
+ lines.push(
370
+ answer.noteOption === undefined
371
+ ? `Note: ${answer.note}`
372
+ : `Note on ${answer.noteOption}: ${answer.note}`,
373
+ );
374
+ }
375
+ return lines;
376
+ }
377
+
378
+ /** Renders OMP's `ask` tool as the questions asked plus the answers a user chose. */
379
+ function askToolText(
380
+ input: Record<string, JsonValue> | undefined,
381
+ details: Record<string, JsonValue> | undefined,
382
+ resultText: string | undefined,
383
+ ): string | undefined {
384
+ // OMP's chat redirect text already lists every question asked.
385
+ if (details?.chatRedirect === true && resultText !== undefined) return resultText;
386
+ const answers = askAnswerRecords(details);
387
+ const asked = askQuestionRecords(input);
388
+ const chatQuestions = Array.isArray(details?.questions)
389
+ ? details.questions.flatMap((value) => (typeof value === "string" ? [value] : []))
390
+ : [];
391
+ const used = new Set<number>();
392
+ let unanswered = false;
393
+ const blocks = asked.map((entry, index) => {
394
+ const answer = takeAskAnswer(entry, index, answers, used);
395
+ if (!answer) unanswered = true;
396
+ return [entry.question, ...(answer ? askAnswerLines(answer) : [])].join("\n");
397
+ });
398
+ // Answers whose question is missing from the published args (cut down, or ids OMP rewrote)
399
+ // still carry their own question text.
400
+ answers.forEach((answer, index) => {
401
+ if (!used.has(index)) blocks.push([answer.question, ...askAnswerLines(answer)].join("\n"));
402
+ });
403
+ if (blocks.length === 0 && chatQuestions.length > 0) {
404
+ blocks.push(...chatQuestions);
405
+ unanswered = true;
406
+ }
407
+ if (blocks.length === 0) return resultText;
408
+ const text = blocks.join("\n\n");
409
+ // Unanswered questions (cancelled, running, or a dropped details payload) keep OMP's own
410
+ // result text, which says why no answer is there without inventing a label for it.
411
+ return !unanswered || resultText === undefined ? text : `${text}\n\n${resultText}`;
412
+ }
413
+
264
414
  type NativeImageEnvelope = {
265
415
  images: NativeImage[];
266
416
  text?: string;
@@ -1811,6 +1961,16 @@ export class OmpTimelineProjector {
1811
1961
  if (name === "todo") {
1812
1962
  return { type: "plan", text: resultText ?? JSON.stringify(snapshot.input) };
1813
1963
  }
1964
+ if (name === "ask") {
1965
+ const text = askToolText(nestedInput, details, resultText);
1966
+ if (text !== undefined) {
1967
+ return {
1968
+ type: "plain_text",
1969
+ label: snapshot.name,
1970
+ text: this.dataFilter.text(text, MAX_ASK_TEXT_BYTES),
1971
+ };
1972
+ }
1973
+ }
1814
1974
  return { type: "unknown", input: snapshot.input, output: snapshot.output };
1815
1975
  }
1816
1976
 
@@ -19,18 +19,18 @@ export type OmpTurnRowReader = (
19
19
  * turn of such an agent, every reader may append one timeline row built from that file.
20
20
  */
21
21
  export function registerOmpTurnRows(
22
- server: Pick<PluginServerContext, "addHook">,
22
+ server: Pick<PluginServerContext, "on">,
23
23
  readers: readonly OmpTurnRowReader[],
24
24
  ): () => void {
25
25
  // One Paseo turn can report several native turn starts; keep the earliest. Hooks run
26
26
  // concurrently, so state is read and cleared before the first await.
27
27
  const turnStarts = new Map<string, number>();
28
28
  const turnKey = (agentId: string, turnId: string | null) => `${agentId}\0${turnId ?? ""}`;
29
- const removeBefore = server.addHook("agent.turn.before", async ({ agent, turnId }) => {
29
+ const removeBefore = server.on("agent.turn_started", async ({ agent, turnId }) => {
30
30
  const key = turnKey(agent.id, turnId);
31
31
  if (agent.provider === "omp" && !turnStarts.has(key)) turnStarts.set(key, Date.now());
32
32
  });
33
- const removeAfter = server.addHook("agent.turn.after", async ({ agent, turnId }, { paseo }) => {
33
+ const removeAfter = server.on("agent.turn_ended", async ({ agent, turnId }, { paseo }) => {
34
34
  const key = turnKey(agent.id, turnId);
35
35
  const since = turnStarts.get(key);
36
36
  const until = Date.now();