@tangle-network/agent-app 0.60.276 → 0.60.278

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ReasoningRow,
3
3
  chatToolCallPart
4
- } from "../chunk-SKI2F3NL.js";
4
+ } from "../chunk-YI2XZCTP.js";
5
5
  import "../chunk-BDEBQ4WO.js";
6
6
  import "../chunk-3HUFJ5LO.js";
7
7
  import "../chunk-FBVLEGEG.js";
@@ -6330,10 +6330,21 @@ import { useEffect as useEffect15, useRef as useRef15, useState as useState22 }
6330
6330
  import { Button as Button5, PageHeader } from "@tangle-network/ui/primitives";
6331
6331
  import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
6332
6332
  var revisionKey = (item) => JSON.stringify([item.id, item.revision]);
6333
+ function comparisonOrder(items, seed) {
6334
+ const result = [...items].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
6335
+ let state = 2166136261;
6336
+ for (const character of seed) state = Math.imul(state ^ character.charCodeAt(0), 16777619) >>> 0;
6337
+ for (let index = result.length - 1; index > 0; index--) {
6338
+ state = Math.imul(state, 1664525) + 1013904223 >>> 0;
6339
+ const other = Math.floor(state / 4294967296 * (index + 1));
6340
+ [result[index], result[other]] = [result[other], result[index]];
6341
+ }
6342
+ return result;
6343
+ }
6333
6344
  function ordered(items) {
6334
6345
  return [...items].sort((left, right) => left.createdAt - right.createdAt || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
6335
6346
  }
6336
- function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedback, loading = false, error, onRefresh }) {
6347
+ function ReviewInbox({ items, initialSelectedId, renderItem, renderCompareBrief, onVerdict, onFeedback, loading = false, error, onRefresh }) {
6337
6348
  const [round2, setRound] = useState22(() => ordered(items).map((item) => item.id));
6338
6349
  const [answered, setAnswered] = useState22(/* @__PURE__ */ new Set());
6339
6350
  const [resolvedElsewhere, setResolvedElsewhere] = useState22(/* @__PURE__ */ new Set());
@@ -6343,16 +6354,22 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6343
6354
  const [restart, setRestart] = useState22(false);
6344
6355
  const [refreshError, setRefreshError] = useState22("");
6345
6356
  const cache = useRef15(/* @__PURE__ */ new Map());
6357
+ const comparisons = useRef15(/* @__PURE__ */ new Map());
6346
6358
  const drafts = useRef15(/* @__PURE__ */ new Map());
6347
6359
  const pending = useRef15(false);
6348
6360
  const section = useRef15(null);
6349
6361
  const form = useRef15(null);
6350
- for (const item of items) cache.current.set(item.id, item);
6362
+ for (const item of items) {
6363
+ cache.current.set(item.id, item);
6364
+ if (!comparisons.current.has(item.id)) comparisons.current.set(item.id, item.compare ? { ...item.compare } : void 0);
6365
+ }
6351
6366
  const currentItems = new Map(items.map((item) => [item.id, item]));
6352
6367
  const missing = loading || error || busy || refreshing ? resolvedElsewhere : new Set(round2.filter((id) => !currentItems.has(id)));
6368
+ const savedComparisonVerdict = (item) => !!comparisons.current.get(item.id) && item.feedback?.verdict !== void 0;
6369
+ const isAnswered = (item) => answered.has(revisionKey(item)) || savedComparisonVerdict(item);
6353
6370
  const unanswered = round2.filter((id) => {
6354
6371
  const item = cache.current.get(id);
6355
- return item && !answered.has(revisionKey(item)) && !missing.has(id);
6372
+ return item && !isAnswered(item) && !missing.has(id);
6356
6373
  });
6357
6374
  const currentId = activeId && unanswered.includes(activeId) ? activeId : unanswered.find((id) => round2.indexOf(id) > round2.indexOf(activeId ?? "")) ?? unanswered[0];
6358
6375
  const active = currentId ? cache.current.get(currentId) : void 0;
@@ -6361,9 +6378,22 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6361
6378
  const canReview = !!active && available && active.canReview;
6362
6379
  const rank = currentId ? round2.indexOf(currentId) + 1 : round2.length;
6363
6380
  const reviewed = round2.length - unanswered.length;
6381
+ const compare = active ? comparisons.current.get(active.id) : void 0;
6382
+ const compareItems = compare ? comparisonOrder(round2.flatMap((id) => {
6383
+ const item = cache.current.get(id);
6384
+ return item && comparisons.current.get(id)?.rowId === compare.rowId ? [item] : [];
6385
+ }), compare.seed) : [];
6386
+ const compareValid = !!compare?.rowId && !!compare.seed && compareItems.length > 0 && compareItems.every((item) => item.compare?.rowId === compare.rowId && item.compare.seed === compare.seed);
6387
+ const positionOf = (item) => compareValid && item.compare ? {
6388
+ rowId: item.compare.rowId,
6389
+ seed: item.compare.seed,
6390
+ position: compareItems.findIndex((cell) => cell.id === item.id),
6391
+ itemIds: compareItems.map((cell) => cell.id)
6392
+ } : void 0;
6364
6393
  useEffect15(() => {
6365
6394
  if (loading || !restart && (round2.length > 0 || items.length === 0)) return;
6366
6395
  const next = ordered(items).map((item) => item.id);
6396
+ comparisons.current = new Map(items.map((item) => [item.id, item.compare ? { ...item.compare } : void 0]));
6367
6397
  setRound(next);
6368
6398
  setActiveId(initialSelectedId && next.includes(initialSelectedId) ? initialSelectedId : next[0] ?? null);
6369
6399
  setAnswered(/* @__PURE__ */ new Set());
@@ -6380,24 +6410,24 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6380
6410
  }, [items, loading, error, busy, refreshing, round2]);
6381
6411
  useEffect15(() => {
6382
6412
  setActiveId(currentId ?? null);
6383
- section.current?.focus({ preventScroll: true });
6384
- }, [currentKey]);
6413
+ if (!compare) section.current?.focus({ preventScroll: true });
6414
+ }, [currentKey, !!compare]);
6385
6415
  function navigate(direction) {
6386
6416
  if (pending.current || unanswered.length < 2) return;
6387
6417
  const index = Math.max(0, unanswered.indexOf(currentId));
6388
6418
  setActiveId(unanswered[(index + direction + unanswered.length) % unanswered.length]);
6389
6419
  }
6390
6420
  async function verdict(item, value) {
6391
- if (pending.current || !item.canReview || !currentItems.has(item.id)) return;
6421
+ if (pending.current || !item.canReview || !currentItems.has(item.id) || comparisons.current.get(item.id) && !compareValid) return;
6392
6422
  pending.current = true;
6393
6423
  setBusy(true);
6394
6424
  try {
6395
- await onVerdict(item, value);
6425
+ await onVerdict(item, { ...value, ...comparisons.current.get(item.id) ? { comparison: positionOf(item) } : {} });
6396
6426
  const nextAnswered = new Set(answered).add(revisionKey(item));
6397
6427
  setAnswered(nextAnswered);
6398
6428
  const remaining = round2.filter((id) => {
6399
6429
  const candidate = cache.current.get(id);
6400
- return candidate && !nextAnswered.has(revisionKey(candidate));
6430
+ return candidate && !nextAnswered.has(revisionKey(candidate)) && !savedComparisonVerdict(candidate);
6401
6431
  });
6402
6432
  const position = round2.indexOf(item.id);
6403
6433
  setActiveId(remaining.find((id) => round2.indexOf(id) > position) ?? remaining[0] ?? null);
@@ -6407,11 +6437,11 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6407
6437
  }
6408
6438
  }
6409
6439
  async function feedback(item, value) {
6410
- if (!onFeedback || pending.current || !item.canReview || !currentItems.has(item.id)) return;
6440
+ if (!onFeedback || pending.current || !item.canReview || !currentItems.has(item.id) || comparisons.current.get(item.id) && !compareValid) return;
6411
6441
  pending.current = true;
6412
6442
  setBusy(true);
6413
6443
  try {
6414
- await onFeedback(item, value);
6444
+ await onFeedback(item, { ...value, ...comparisons.current.get(item.id) ? { comparison: positionOf(item) } : {} });
6415
6445
  } finally {
6416
6446
  pending.current = false;
6417
6447
  setBusy(false);
@@ -6450,10 +6480,10 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6450
6480
  } else if (key === "k") {
6451
6481
  event.preventDefault();
6452
6482
  navigate(-1);
6453
- } else if (active && canReview && key === "s") {
6483
+ } else if (!compare && active && canReview && key === "s") {
6454
6484
  event.preventDefault();
6455
6485
  form.current?.focusScore();
6456
- } else if (active && canReview && (key === "a" || key === "r")) {
6486
+ } else if (!compare && active && canReview && (key === "a" || key === "r")) {
6457
6487
  event.preventDefault();
6458
6488
  void form.current?.submitVerdict(key === "a" ? "approve" : "request_changes");
6459
6489
  }
@@ -6468,7 +6498,7 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6468
6498
  tabIndex: -1,
6469
6499
  "aria-label": "Review inbox",
6470
6500
  "aria-busy": busy || refreshing || loading,
6471
- className: "mx-auto min-w-0 max-w-4xl space-y-5 outline-none",
6501
+ className: `mx-auto min-w-0 space-y-5 outline-none ${compare ? "max-w-none" : "max-w-4xl"}`,
6472
6502
  "data-review-inbox": true,
6473
6503
  children: [
6474
6504
  /* @__PURE__ */ jsx22(
@@ -6477,7 +6507,7 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6477
6507
  title: "Review inbox",
6478
6508
  description: "Review the oldest work first. Every decision includes your score and feedback.",
6479
6509
  actions: onRefresh && /* @__PURE__ */ jsx22(Button5, { variant: "outline", disabled: busy || refreshing || loading, onClick: () => void refresh(), children: refreshing ? "Refreshing\u2026" : "Refresh" }),
6480
- meta: /* @__PURE__ */ jsx22("p", { role: "status", "data-review-progress": true, children: active ? `${rank} of ${round2.length}` : `${reviewed} of ${round2.length} resolved` })
6510
+ meta: /* @__PURE__ */ jsx22("p", { role: "status", "data-review-progress": true, children: active ? `${compare ? reviewed : rank} of ${round2.length}${compare ? " resolved" : ""}` : `${reviewed} of ${round2.length} resolved` })
6481
6511
  }
6482
6512
  ),
6483
6513
  (error || refreshError) && /* @__PURE__ */ jsx22("p", { role: "alert", className: "text-sm text-[var(--surface-danger-text)]", children: error || refreshError }),
@@ -6493,34 +6523,79 @@ function ReviewInbox({ items, initialSelectedId, renderItem, onVerdict, onFeedba
6493
6523
  ] }) : /* @__PURE__ */ jsxs21(Fragment8, { children: [
6494
6524
  /* @__PURE__ */ jsxs21("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
6495
6525
  /* @__PURE__ */ jsxs21("div", { className: "min-w-0", children: [
6496
- /* @__PURE__ */ jsx22("p", { className: "text-sm text-muted-foreground", children: active.kind }),
6497
- /* @__PURE__ */ jsx22("h2", { className: "break-words text-lg font-semibold", "data-review-title": true, children: active.title })
6526
+ !compare && /* @__PURE__ */ jsx22("p", { className: "text-sm text-muted-foreground", children: active.kind }),
6527
+ /* @__PURE__ */ jsx22("h2", { className: "break-words text-lg font-semibold", "data-review-title": true, children: compare ? "Compare drafts" : active.title })
6498
6528
  ] }),
6499
6529
  /* @__PURE__ */ jsxs21("div", { className: "flex gap-2", children: [
6500
6530
  /* @__PURE__ */ jsx22(Button5, { variant: "outline", "aria-keyshortcuts": "K", disabled: busy || unanswered.length < 2, onClick: () => navigate(-1), children: "Previous" }),
6501
6531
  /* @__PURE__ */ jsx22(Button5, { variant: "outline", "aria-keyshortcuts": "J", disabled: busy || unanswered.length < 2, onClick: () => navigate(1), children: "Next" })
6502
6532
  ] })
6503
6533
  ] }),
6504
- available && !active.canReview && /* @__PURE__ */ jsx22("p", { className: "text-sm text-muted-foreground", children: "You do not have permission to review this item." }),
6505
- /* @__PURE__ */ jsx22("div", { className: "min-w-0", "data-review-content": true, children: renderItem(active) }),
6506
- /* @__PURE__ */ jsx22(
6507
- ReviewFeedbackForm,
6508
- {
6509
- ref: form,
6510
- draftKey: currentKey,
6511
- drafts: drafts.current,
6512
- input: active.input,
6513
- preview: active.preview,
6514
- feedback: active.feedback,
6515
- disabled: !canReview || busy || loading,
6516
- approveLabel: active.approveLabel,
6517
- allowedVerdicts: active.allowedVerdicts,
6518
- onVerdict: (decision, value) => verdict(active, { verdict: decision, ...value }),
6519
- onFeedback: onFeedback ? (value) => feedback(active, value) : void 0
6520
- },
6521
- currentKey
6522
- ),
6523
- /* @__PURE__ */ jsx22("p", { className: "text-xs leading-5 text-muted-foreground", children: "A approve \xB7 R request changes \xB7 S score \xB7 J/K next/previous \xB7 Esc leave a field. Shortcuts pause while typing." })
6534
+ compare ? /* @__PURE__ */ jsxs21(Fragment8, { children: [
6535
+ renderCompareBrief && /* @__PURE__ */ jsx22("div", { "data-review-compare-brief": true, children: renderCompareBrief(compare.rowId) }),
6536
+ !compareValid && /* @__PURE__ */ jsx22("p", { role: "alert", children: "This comparison changed. Refresh the inbox before reviewing it." }),
6537
+ /* @__PURE__ */ jsx22("div", { className: "grid min-w-0 grid-cols-1 gap-4 lg:grid-cols-2 xl:grid-cols-3", "data-review-compare-row": true, children: compareItems.map((item, index) => {
6538
+ const key = revisionKey(item);
6539
+ const done = isAnswered(item);
6540
+ const present = currentItems.has(item.id);
6541
+ return /* @__PURE__ */ jsxs21(
6542
+ "article",
6543
+ {
6544
+ "aria-label": `Draft ${index + 1}`,
6545
+ className: "min-w-0 space-y-3 rounded-lg border p-4",
6546
+ "data-review-compare-position": index,
6547
+ onFocusCapture: () => {
6548
+ if (!done && present) setActiveId(item.id);
6549
+ },
6550
+ children: [
6551
+ /* @__PURE__ */ jsxs21("h3", { className: "text-lg font-semibold", children: [
6552
+ "Draft ",
6553
+ index + 1
6554
+ ] }),
6555
+ /* @__PURE__ */ jsx22("div", { className: "min-w-0", "data-review-content": true, children: renderItem(item) }),
6556
+ present && !done && !item.canReview && /* @__PURE__ */ jsx22("p", { className: "text-sm text-muted-foreground", children: "You do not have permission to review this item." }),
6557
+ done ? /* @__PURE__ */ jsx22("p", { role: "status", children: "Review saved" }) : !present ? /* @__PURE__ */ jsx22("p", { role: "status", children: "This draft is no longer waiting." }) : /* @__PURE__ */ jsx22(
6558
+ ReviewFeedbackForm,
6559
+ {
6560
+ draftKey: key,
6561
+ drafts: drafts.current,
6562
+ input: item.input,
6563
+ feedback: item.feedback,
6564
+ disabled: !compareValid || !item.canReview || busy || loading,
6565
+ approveLabel: item.approveLabel,
6566
+ allowedVerdicts: item.allowedVerdicts,
6567
+ onVerdict: (decision, value) => verdict(item, { verdict: decision, ...value }),
6568
+ onFeedback: onFeedback ? (value) => feedback(item, value) : void 0
6569
+ },
6570
+ key
6571
+ )
6572
+ ]
6573
+ },
6574
+ key
6575
+ );
6576
+ }) })
6577
+ ] }) : /* @__PURE__ */ jsxs21(Fragment8, { children: [
6578
+ available && !active.canReview && /* @__PURE__ */ jsx22("p", { className: "text-sm text-muted-foreground", children: "You do not have permission to review this item." }),
6579
+ /* @__PURE__ */ jsx22("div", { className: "min-w-0", "data-review-content": true, children: renderItem(active) }),
6580
+ /* @__PURE__ */ jsx22(
6581
+ ReviewFeedbackForm,
6582
+ {
6583
+ ref: form,
6584
+ draftKey: currentKey,
6585
+ drafts: drafts.current,
6586
+ input: active.input,
6587
+ preview: active.preview,
6588
+ feedback: active.feedback,
6589
+ disabled: !canReview || busy || loading,
6590
+ approveLabel: active.approveLabel,
6591
+ allowedVerdicts: active.allowedVerdicts,
6592
+ onVerdict: (decision, value) => verdict(active, { verdict: decision, ...value }),
6593
+ onFeedback: onFeedback ? (value) => feedback(active, value) : void 0
6594
+ },
6595
+ currentKey
6596
+ )
6597
+ ] }),
6598
+ !compare && /* @__PURE__ */ jsx22("p", { className: "text-xs leading-5 text-muted-foreground", children: "A approve \xB7 R request changes \xB7 S score \xB7 J/K next/previous \xB7 Esc leave a field. Shortcuts pause while typing." })
6524
6599
  ] })
6525
6600
  ]
6526
6601
  }
@@ -7916,4 +7991,4 @@ export {
7916
7991
  AgentProfileChoices,
7917
7992
  ComposerProfilePill
7918
7993
  };
7919
- //# sourceMappingURL=chunk-SKI2F3NL.js.map
7994
+ //# sourceMappingURL=chunk-YI2XZCTP.js.map