@adecore/agents-react 0.55.0 → 0.55.2

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 (55) hide show
  1. package/dist/agents/account-limits.js +5 -2
  2. package/dist/chat/logic/resume-compaction.js +2 -2
  3. package/dist/chat/logic/timeline.d.ts +1 -0
  4. package/dist/chat/logic/timeline.js +4 -1
  5. package/dist/chat/ui/RunSettings.js +63 -58
  6. package/dist/chat/ui/composer/ComposerMenu.js +0 -3
  7. package/dist/chat/ui/index.d.ts +1 -1
  8. package/dist/chat/ui/intelligent-ui/UiBlockFrame.js +130 -121
  9. package/dist/chat/ui/intelligent-ui/UiReply.js +28 -9
  10. package/dist/chat/ui/intelligent-ui/render-context.d.ts +2 -0
  11. package/dist/chat/ui/intelligent-ui/renderers/data.js +124 -94
  12. package/dist/chat/ui/intelligent-ui/use-ui-queries.d.ts +8 -2
  13. package/dist/chat/ui/intelligent-ui/use-ui-queries.js +162 -74
  14. package/dist/chat/ui/rows/MessageRows.d.ts +2 -1
  15. package/dist/chat/ui/rows/MessageRows.js +48 -40
  16. package/dist/chat/ui/rows/Rows.js +32 -30
  17. package/dist/locales/en/agent-chat.d.ts +3 -0
  18. package/dist/locales/en/agent-chat.js +3 -0
  19. package/dist/locales/en/agent-usage.d.ts +10 -0
  20. package/dist/locales/en/agent-usage.js +10 -0
  21. package/dist/locales/nl/agent-chat.d.ts +3 -0
  22. package/dist/locales/nl/agent-chat.js +3 -0
  23. package/dist/locales/nl/agent-usage.d.ts +10 -0
  24. package/dist/locales/nl/agent-usage.js +10 -0
  25. package/dist/theme.css +9 -4
  26. package/dist/usage/LimitProvenance.d.ts +5 -0
  27. package/dist/usage/LimitProvenance.js +104 -0
  28. package/dist/usage/LimitsList.js +153 -131
  29. package/dist/usage/UsageLimits.d.ts +1 -1
  30. package/dist/usage/UsageLimits.js +241 -158
  31. package/dist/usage/limit-groups.d.ts +2 -0
  32. package/dist/usage/limit-groups.js +12 -3
  33. package/package.json +9 -9
  34. package/src/agents/account-limits.ts +6 -2
  35. package/src/chat/logic/resume-compaction.ts +2 -2
  36. package/src/chat/logic/timeline.ts +7 -2
  37. package/src/chat/ui/RunSettings.tsx +9 -3
  38. package/src/chat/ui/composer/ComposerMenu.tsx +0 -1
  39. package/src/chat/ui/index.ts +1 -0
  40. package/src/chat/ui/intelligent-ui/UiBlockFrame.tsx +5 -2
  41. package/src/chat/ui/intelligent-ui/UiReply.tsx +25 -6
  42. package/src/chat/ui/intelligent-ui/render-context.ts +5 -0
  43. package/src/chat/ui/intelligent-ui/renderers/data.tsx +58 -27
  44. package/src/chat/ui/intelligent-ui/use-ui-queries.ts +81 -61
  45. package/src/chat/ui/rows/MessageRows.tsx +11 -2
  46. package/src/chat/ui/rows/Rows.tsx +1 -1
  47. package/src/locales/en/agent-chat.ts +3 -0
  48. package/src/locales/en/agent-usage.ts +10 -0
  49. package/src/locales/nl/agent-chat.ts +3 -0
  50. package/src/locales/nl/agent-usage.ts +10 -0
  51. package/src/theme.css +9 -4
  52. package/src/usage/LimitProvenance.tsx +23 -0
  53. package/src/usage/LimitsList.tsx +10 -4
  54. package/src/usage/UsageLimits.tsx +88 -18
  55. package/src/usage/limit-groups.ts +16 -3
@@ -346,15 +346,30 @@ function UiNodes({
346
346
  texts,
347
347
  context
348
348
  }) {
349
- const drawn = node => /*#__PURE__*/_jsx(UiNodeBoundary, {
350
- node: node,
351
- children: /*#__PURE__*/_jsx(UiNodeBody, {
349
+ const drawn = node => {
350
+ const body = /*#__PURE__*/_jsx(UiNodeBoundary, {
352
351
  node: node,
353
- parent: parent,
354
- texts: texts,
355
- context: context
356
- })
357
- }, node.id);
352
+ children: /*#__PURE__*/_jsx(UiNodeBody, {
353
+ node: node,
354
+ parent: parent,
355
+ texts: texts,
356
+ context: context
357
+ })
358
+ });
359
+ const live = context.liveNode?.(node.id);
360
+ if (live === undefined) {
361
+ return /*#__PURE__*/_jsx(Fragment, {
362
+ children: body
363
+ }, node.id);
364
+ }
365
+ // Every node that reads live data has this wrapper, stale or not, so a failed read never mounts a map or a chart again.
366
+ // Text has no element of its own to dim, so its wrapper is an inline box rather than none.
367
+ const shape = node.type === '$text' ? 'chat-ui-live-text' : 'chat-ui-live contents';
368
+ return /*#__PURE__*/_jsx("span", {
369
+ className: live === 'stale' ? `${shape} chat-ui-stale` : shape,
370
+ children: body
371
+ }, node.id);
372
+ };
358
373
  const paragraph = PARAGRAPHS[parent];
359
374
  if (parent === 'Choices') {
360
375
  // A primary choice stands first in the order a keyboard and a screen reader meet it too, not only on screen.
@@ -592,7 +607,10 @@ function UiBlockBody({
592
607
  void revealUiSource(element, source.id, source.ancestors);
593
608
  } : undefined
594
609
  }), [sources, element]);
595
- const liveValue = useUiLiveValues(block, evaluation.nodes, queries.currentReadings);
610
+ const {
611
+ liveValue,
612
+ liveNode
613
+ } = useUiLiveValues(block, evaluation.nodes, queries.currentReadings);
596
614
  const sendChoice = host.intelligentUi?.sendChoice;
597
615
  const place = useMemo(() => placeReader(frozen, block.revision, unrecorded), [frozen, block.revision, unrecorded]);
598
616
  const rendering = {
@@ -603,6 +621,7 @@ function UiBlockBody({
603
621
  failedChoiceId,
604
622
  live: queries.live,
605
623
  liveValue,
624
+ liveNode,
606
625
  choiceReason: uiLiveChoiceReason(t, queries.live),
607
626
  onChoose: !queries.ready || queries.reading ? undefined : sendChoice && block.revision && block.complete && context.phase === 'final' ? choiceId => {
608
627
  if (pending.current || answer || queries.reading) {
@@ -25,6 +25,7 @@ export interface UiLiveStatus {
25
25
  reason?: string;
26
26
  code?: string;
27
27
  }
28
+ export type UiLiveNodeState = 'live' | 'stale';
28
29
  export interface UiLiveValue {
29
30
  previous?: unknown;
30
31
  changed: boolean;
@@ -46,6 +47,7 @@ export interface UiRenderContext {
46
47
  choiceReason?: string | null;
47
48
  place?(nodeId: string, address: string): UiPlacePoint | null | undefined;
48
49
  liveValue?(nodeId: string, prop: string, path?: readonly [row: number, key: string]): UiLiveValue | undefined;
50
+ liveNode?(nodeId: string): UiLiveNodeState | undefined;
49
51
  }
50
52
  export interface UiRendererProps<Props> {
51
53
  node: UiViewNode<Props>;
@@ -11,14 +11,15 @@ import { isNumericColumn, UI_TABLE_ROWS, uiTableCell, uiTableColumns } from '../
11
11
  import { UI_TONE_PILL } from '../tones.js';
12
12
  import { UiFallbackPart } from '../UiFallbackPart.js';
13
13
  /* EntityList draws a hairline between its rows from this many on. */
14
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
15
  const DIVIDED_FROM = 7;
16
16
  /* Up to this many entries an EntityList is a row of tiles; a longer one is a list in one tile. */
17
17
  const TILED_UP_TO = 4;
18
18
  const EntityTiles = createContext(false);
19
19
  /*
20
- * A number that live readings keep up to date. Keyed by its text, so a value that changed mounts
21
- * again and lights up once, even when it changes again before the last light settled.
20
+ * A value that live readings keep up to date. Keyed by its text, so a value that changed mounts
21
+ * again and lights up once, even when it changes again before the last light settled. A stale
22
+ * value is dimmed by the node around it, not here.
22
23
  */
23
24
  function LiveFigure(t0) {
24
25
  const $ = _c(7);
@@ -26,34 +27,34 @@ function LiveFigure(t0) {
26
27
  text,
27
28
  previous,
28
29
  live,
29
- className
30
+ className,
31
+ children
30
32
  } = t0;
31
33
  const lit = live !== undefined && live.changed && !live.stale && previous !== text;
32
- const t1 = live?.stale ? "text-text-muted" : "text-text";
33
- const t2 = lit && "chat-ui-changed";
34
- let t3;
35
- if ($[0] !== className || $[1] !== t1 || $[2] !== t2) {
36
- t3 = clsx(t1, t2, className);
34
+ let t1;
35
+ if ($[0] !== className || $[1] !== lit) {
36
+ t1 = clsx(lit && "chat-ui-changed", className) || undefined;
37
37
  $[0] = className;
38
- $[1] = t1;
39
- $[2] = t2;
40
- $[3] = t3;
38
+ $[1] = lit;
39
+ $[2] = t1;
41
40
  } else {
42
- t3 = $[3];
41
+ t1 = $[2];
43
42
  }
44
- let t4;
45
- if ($[4] !== t3 || $[5] !== text) {
46
- t4 = /*#__PURE__*/_jsx("span", {
47
- className: t3,
48
- children: text
43
+ const t2 = children ?? text;
44
+ let t3;
45
+ if ($[3] !== t1 || $[4] !== t2 || $[5] !== text) {
46
+ t3 = /*#__PURE__*/_jsx("span", {
47
+ className: t1,
48
+ children: t2
49
49
  }, text);
50
- $[4] = t3;
50
+ $[3] = t1;
51
+ $[4] = t2;
51
52
  $[5] = text;
52
- $[6] = t4;
53
+ $[6] = t3;
53
54
  } else {
54
- t4 = $[6];
55
+ t3 = $[6];
55
56
  }
56
- return t4;
57
+ return t3;
57
58
  }
58
59
  export function StatsRenderer(t0) {
59
60
  const $ = _c(2);
@@ -186,7 +187,7 @@ export function StatRenderer(t0) {
186
187
  text: t1,
187
188
  previous: t2,
188
189
  live: live,
189
- className: "max-w-full truncate text-lg font-semibold tabular-nums"
190
+ className: "max-w-full truncate text-lg font-semibold text-text tabular-nums"
190
191
  });
191
192
  $[30] = T0;
192
193
  $[31] = live;
@@ -377,94 +378,123 @@ export function EntryRenderer(t0) {
377
378
  function numberText(cell, unit) {
378
379
  return cell.as === 'bytes' ? formatBytes(cell.value) : cell.as === 'duration' ? formatDuration(cell.value) : uiWithUnit(formatRounded(cell.value, 2), unit);
379
380
  }
381
+ /* What a cell reads as, so two readings that draw the same do not light up. */
382
+ function cellText(cell, column) {
383
+ switch (cell.kind) {
384
+ case 'empty':
385
+ return '';
386
+ case 'text':
387
+ case 'tag':
388
+ return cell.text;
389
+ case 'number':
390
+ return numberText(cell, column.unit);
391
+ case 'date':
392
+ return formatMoment(cell.at);
393
+ case 'file':
394
+ return cell.path;
395
+ }
396
+ }
397
+ function cellContent(cell, column) {
398
+ switch (cell.kind) {
399
+ case 'text':
400
+ return cell.text;
401
+ case 'number':
402
+ return numberText(cell, column.unit);
403
+ case 'date':
404
+ return /*#__PURE__*/_jsx("time", {
405
+ dateTime: new Date(cell.at).toISOString(),
406
+ children: formatMoment(cell.at)
407
+ });
408
+ case 'file':
409
+ // A cell is no link target the host checked, so its path stays text.
410
+ return /*#__PURE__*/_jsx("span", {
411
+ className: "font-mono text-code break-all",
412
+ children: cell.path
413
+ });
414
+ case 'tag':
415
+ return /*#__PURE__*/_jsx(Pill, {
416
+ shape: "tag",
417
+ size: "sm",
418
+ children: cell.text
419
+ });
420
+ }
421
+ }
380
422
  function Cell(t0) {
381
- const $ = _c(8);
423
+ const $ = _c(18);
382
424
  const {
383
425
  value,
384
426
  column,
385
427
  live
386
428
  } = t0;
429
+ let T0;
387
430
  let t1;
431
+ let t2;
432
+ let t3;
433
+ let t4;
434
+ let t5;
388
435
  if ($[0] !== column || $[1] !== live || $[2] !== value) {
389
- t1 = Symbol.for("react.early_return_sentinel");
436
+ t5 = Symbol.for("react.early_return_sentinel");
390
437
  bb0: {
391
438
  const cell = uiTableCell(value, column);
392
- switch (cell.kind) {
393
- case "empty":
394
- {
395
- t1 = null;
396
- break bb0;
397
- }
398
- case "text":
399
- {
400
- t1 = /*#__PURE__*/_jsx(_Fragment, {
401
- children: cell.text
402
- });
403
- break bb0;
404
- }
405
- case "number":
406
- {
407
- const before = live?.previous === undefined ? undefined : uiTableCell(live.previous, column);
408
- t1 = /*#__PURE__*/_jsx(LiveFigure, {
409
- text: numberText(cell, column.unit),
410
- previous: before?.kind === "number" ? numberText(before, column.unit) : undefined,
411
- live: live
412
- });
413
- break bb0;
414
- }
415
- case "date":
416
- {
417
- t1 = /*#__PURE__*/_jsx("time", {
418
- dateTime: new Date(cell.at).toISOString(),
419
- children: formatMoment(cell.at)
420
- });
421
- break bb0;
422
- }
423
- case "file":
424
- {
425
- let t2;
426
- if ($[4] !== cell) {
427
- t2 = /*#__PURE__*/_jsx("span", {
428
- className: "font-mono text-code break-all",
429
- children: cell.path
430
- });
431
- $[4] = cell;
432
- $[5] = t2;
433
- } else {
434
- t2 = $[5];
435
- }
436
- t1 = t2;
437
- break bb0;
438
- }
439
- case "tag":
440
- {
441
- let t2;
442
- if ($[6] !== cell) {
443
- t2 = /*#__PURE__*/_jsx(Pill, {
444
- shape: "tag",
445
- size: "sm",
446
- children: cell.text
447
- });
448
- $[6] = cell;
449
- $[7] = t2;
450
- } else {
451
- t2 = $[7];
452
- }
453
- t1 = t2;
454
- break bb0;
455
- }
439
+ if (cell.kind === "empty") {
440
+ t5 = null;
441
+ break bb0;
442
+ }
443
+ const text = cellText(cell, column);
444
+ let t6;
445
+ if ($[9] !== column || $[10] !== live) {
446
+ t6 = live?.previous === undefined ? undefined : cellText(uiTableCell(live.previous, column), column);
447
+ $[9] = column;
448
+ $[10] = live;
449
+ $[11] = t6;
450
+ } else {
451
+ t6 = $[11];
456
452
  }
453
+ const previous = t6;
454
+ T0 = LiveFigure;
455
+ t1 = text;
456
+ t2 = previous;
457
+ t3 = live;
458
+ t4 = cellContent(cell, column);
457
459
  }
458
460
  $[0] = column;
459
461
  $[1] = live;
460
462
  $[2] = value;
461
- $[3] = t1;
463
+ $[3] = T0;
464
+ $[4] = t1;
465
+ $[5] = t2;
466
+ $[6] = t3;
467
+ $[7] = t4;
468
+ $[8] = t5;
462
469
  } else {
463
- t1 = $[3];
470
+ T0 = $[3];
471
+ t1 = $[4];
472
+ t2 = $[5];
473
+ t3 = $[6];
474
+ t4 = $[7];
475
+ t5 = $[8];
464
476
  }
465
- if (t1 !== Symbol.for("react.early_return_sentinel")) {
466
- return t1;
477
+ if (t5 !== Symbol.for("react.early_return_sentinel")) {
478
+ return t5;
479
+ }
480
+ let t6;
481
+ if ($[12] !== T0 || $[13] !== t1 || $[14] !== t2 || $[15] !== t3 || $[16] !== t4) {
482
+ t6 = /*#__PURE__*/_jsx(T0, {
483
+ text: t1,
484
+ previous: t2,
485
+ live: t3,
486
+ children: t4
487
+ });
488
+ $[12] = T0;
489
+ $[13] = t1;
490
+ $[14] = t2;
491
+ $[15] = t3;
492
+ $[16] = t4;
493
+ $[17] = t6;
494
+ } else {
495
+ t6 = $[17];
467
496
  }
497
+ return t6;
468
498
  }
469
499
  /*
470
500
  * Rows under a sticky head, scrolling inside 320px and sideways when wider than the column. Rows
@@ -549,7 +579,7 @@ export function TableRenderer(t0) {
549
579
  children: /*#__PURE__*/_jsx(Cell, {
550
580
  value: row[column_1.key],
551
581
  column: column_1,
552
- live: isNumericColumn(column_1) ? context.liveValue?.(node.id, "rows", [index, column_1.key]) : undefined
582
+ live: context.liveValue?.(node.id, "rows", [index, column_1.key])
553
583
  })
554
584
  }, column_1.key))
555
585
  }, index));
@@ -1,6 +1,6 @@
1
1
  import type { ChatUiQueryReading, ChatUiQueryState } from '@adecore/agent-contracts';
2
2
  import { UiState, type UiBlock, type UiViewNode } from '@adecore/intelligent-ui';
3
- import type { UiLiveValue, UiLiveStatus, UiRenderContext } from './render-context.js';
3
+ import type { UiLiveNodeState, UiLiveValue, UiLiveStatus, UiRenderContext } from './render-context.js';
4
4
  export declare function useUiQueries(block: UiBlock, state: UiState, context: Pick<UiRenderContext, 'scopeId' | 'chatId' | 'itemId' | 'phase'>, element: HTMLDivElement | null, frozen?: ChatUiQueryState['blocks'][string]): {
5
5
  live: UiLiveStatus | undefined;
6
6
  reads: Record<string, string>;
@@ -18,4 +18,10 @@ export declare function useUiQueries(block: UiBlock, state: UiState, context: Pi
18
18
  };
19
19
  };
20
20
  };
21
- export declare function useUiLiveValues(block: UiBlock, nodes: readonly UiViewNode[], readings: Readonly<Record<string, ChatUiQueryReading>>): ((id: string, prop: string, path?: readonly [number, string]) => UiLiveValue | undefined) | undefined;
21
+ export declare function useUiLiveValues(block: UiBlock, nodes: readonly UiViewNode[], readings: Readonly<Record<string, ChatUiQueryReading>>): {
22
+ liveValue: undefined;
23
+ liveNode: undefined;
24
+ } | {
25
+ liveValue: (id: string, prop: string, path?: readonly [number, string]) => UiLiveValue | undefined;
26
+ liveNode: (id: string) => UiLiveNodeState | undefined;
27
+ };
@@ -1,9 +1,15 @@
1
- import { uiInputValues, UI_CATALOG_VERSION, UI_HOST_LIMITS, UiState } from '@adecore/intelligent-ui';
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { uiInputValues, uiNodeQueries, UI_CATALOG_VERSION, UI_HOST_LIMITS, UiState } from '@adecore/intelligent-ui';
2
3
  import { useEffect, useMemo, useRef, useState } from 'react';
3
4
  import { useChatHost } from '../../../host.js';
5
+ import { UiPageMemory } from './block-local.js';
4
6
  const NO_READINGS = {};
5
7
  // A changed input reads once it has rested this long, so dragging a slider reads its last value only.
6
8
  const INPUT_SETTLE_MS = 300;
9
+ // What each block last read, so a block the thread unmounts while scrolling comes back with its own last value rather than the frozen first one.
10
+ const remembered = new UiPageMemory(64);
11
+ /* Answers for a read the host never tried; while a value stands they say nothing about it. */
12
+ const NOT_TRIED = new Set(['busy', 'refresh-limit']);
7
13
  /* The reading that holds for these inputs: this view's own read of them, or the frozen first one for the inputs the block starts with. */
8
14
  function successfulReading(local, initial, identity, signature, defaultInputs) {
9
15
  if (local?.identity === identity && local.successful?.inputs === signature) {
@@ -19,7 +25,11 @@ function documentVisible() {
19
25
  }
20
26
  export function useUiQueries(block, state, context, element, frozen) {
21
27
  const host = useChatHost();
22
- const [readings, setReadings] = useState({});
28
+ const memoryKey = JSON.stringify([context.scopeId, context.chatId, context.itemId, block.id]);
29
+ const [readings, setReadings] = useState(() => remembered.get(memoryKey) ?? {});
30
+ useEffect(() => {
31
+ remembered.set(memoryKey, readings);
32
+ }, [memoryKey, readings]);
23
33
  const [busyInput, setBusyInput] = useState(null);
24
34
  const lastRead = useRef({
25
35
  inputKey: '',
@@ -112,17 +122,24 @@ export function useUiQueries(block, state, context, element, frozen) {
112
122
  if (reading_0.state === 'fresh') {
113
123
  state.setQuery(name_2, reading_0.value, block);
114
124
  }
115
- setReadings(previous_0 => ({
116
- ...previous_0,
117
- [name_2]: {
118
- identity,
119
- reading: reading_0,
120
- successful: reading_0.state === 'fresh' ? {
121
- inputs,
122
- reading: reading_0
123
- } : previous_0[name_2]?.identity === identity ? previous_0[name_2].successful : undefined
125
+ setReadings(previous_0 => {
126
+ const untried = reading_0.state === 'failed' && reading_0.code !== undefined && NOT_TRIED.has(reading_0.code);
127
+ // The next refresh tries again; until then the value and any real reason it failed stay as they are.
128
+ if (untried && successfulReading(previous_0[name_2], initial[name_2], identity, inputs, defaultInputs) !== undefined) {
129
+ return previous_0;
124
130
  }
125
- }));
131
+ return {
132
+ ...previous_0,
133
+ [name_2]: {
134
+ identity,
135
+ reading: reading_0,
136
+ successful: reading_0.state === 'fresh' ? {
137
+ inputs,
138
+ reading: reading_0
139
+ } : previous_0[name_2]?.identity === identity ? previous_0[name_2].successful : undefined
140
+ }
141
+ };
142
+ });
126
143
  } catch (error) {
127
144
  if (stopped) {
128
145
  return;
@@ -181,7 +198,7 @@ export function useUiQueries(block, state, context, element, frozen) {
181
198
  clearTimeout(timer);
182
199
  }
183
200
  };
184
- }, [block, state, context.scopeId, context.chatId, context.itemId, context.phase, inputs, query, subscribe, element, identity, inputKey]);
201
+ }, [block, state, context.scopeId, context.chatId, context.itemId, context.phase, inputs, query, subscribe, element, identity, inputKey, initial, defaultInputs]);
185
202
  const currentReadings = Object.fromEntries(names.flatMap(name_3 => {
186
203
  const local_0 = readings[name_3];
187
204
  const reading_1 = local_0?.identity === identity ? local_0.reading : initial[name_3];
@@ -191,7 +208,8 @@ export function useUiQueries(block, state, context, element, frozen) {
191
208
  const live = names.length ? {
192
209
  state: reading || !ready && !failed ? 'reading' : failed?.[1].state ?? 'fresh',
193
210
  sources: names.map(name_4 => block.queries[name_4].source),
194
- readAt: Object.values(currentReadings).filter(reading_2 => reading_2.state === 'fresh').reduce((at, value_0) => at === null ? value_0.readAt : Math.min(at, value_0.readAt), null),
211
+ // From the readings that hold, so a failure does not take away when the value on screen was read.
212
+ readAt: names.flatMap(name_5 => successfulFor(name_5, inputs) ?? []).reduce((at, value_0) => at === null ? value_0.readAt : Math.min(at, value_0.readAt), null),
195
213
  source: failed ? block.queries[failed[0]]?.source : undefined,
196
214
  reason: failed?.[1].reason,
197
215
  code: failed?.[1].code
@@ -206,52 +224,63 @@ export function useUiQueries(block, state, context, element, frozen) {
206
224
  };
207
225
  }
208
226
  export function useUiLiveValues(block, nodes, readings) {
209
- const [committed, setCommitted] = useState({
210
- token: '',
211
- values: new Map(),
212
- previous: new Map()
213
- });
214
- const dependencies = new Map();
227
+ const $ = _c(24);
228
+ let t0;
229
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
230
+ t0 = {
231
+ token: "",
232
+ values: new Map(),
233
+ previous: new Map()
234
+ };
235
+ $[0] = t0;
236
+ } else {
237
+ t0 = $[0];
238
+ }
239
+ const [committed, setCommitted] = useState(t0);
240
+ let t1;
241
+ if ($[1] !== block) {
242
+ t1 = uiNodeQueries(block);
243
+ $[1] = block;
244
+ $[2] = t1;
245
+ } else {
246
+ t1 = $[2];
247
+ }
248
+ const dependencies = t1;
215
249
  const names = new Set(Object.keys(block.queries));
216
- const references = (value, into) => {
217
- if (!value || typeof value !== 'object') {
218
- return;
219
- }
220
- const expression = value;
221
- if (expression.kind === 'reference' && names.has(String(expression.name))) {
222
- into.add(String(expression.name));
223
- }
224
- for (const child of Object.values(expression)) {
225
- if (Array.isArray(child)) {
226
- child.forEach(item => references(item, into));
227
- } else if (typeof child === 'object') {
228
- references(child, into);
229
- }
230
- }
231
- };
232
- const written = (nodes_0, inherited = new Set()) => {
233
- for (const node of nodes_0) {
234
- const related = new Set(inherited);
235
- references(node.expressions, related);
236
- dependencies.set(node.id, related);
237
- written(node.children, node.type === 'Each' ? related : inherited);
238
- }
239
- };
240
- written(block.nodes);
241
- const values = new Map();
242
- const sources = new Map();
243
- const collect = nodes_1 => {
244
- for (const node_0 of nodes_1) {
245
- const related_0 = dependencies.get(node_0.sourceId ?? node_0.id);
246
- if (related_0?.size && !node_0.error) {
247
- values.set(node_0.id, node_0.props);
248
- sources.set(node_0.id, related_0);
250
+ let sources;
251
+ let values;
252
+ if ($[3] !== dependencies || $[4] !== nodes) {
253
+ values = new Map();
254
+ sources = new Map();
255
+ const collect = nodes_0 => {
256
+ for (const node of nodes_0) {
257
+ const related = dependencies[node.sourceId ?? node.id];
258
+ if (related !== undefined && !node.error) {
259
+ values.set(node.id, node.props);
260
+ sources.set(node.id, related);
261
+ }
262
+ collect(node.children);
249
263
  }
250
- collect(node_0.children);
251
- }
252
- };
253
- collect(nodes);
254
- const token = JSON.stringify([block.revision, Object.entries(readings).map(([name, reading]) => [name, reading.state, reading.readId, reading.readAt])]);
264
+ };
265
+ collect(nodes);
266
+ $[3] = dependencies;
267
+ $[4] = nodes;
268
+ $[5] = sources;
269
+ $[6] = values;
270
+ } else {
271
+ sources = $[5];
272
+ values = $[6];
273
+ }
274
+ let t2;
275
+ if ($[7] !== block.revision || $[8] !== readings) {
276
+ t2 = JSON.stringify([block.revision, Object.entries(readings).map(_temp)]);
277
+ $[7] = block.revision;
278
+ $[8] = readings;
279
+ $[9] = t2;
280
+ } else {
281
+ t2 = $[9];
282
+ }
283
+ const token = t2;
255
284
  const previous = committed.token === token ? committed.previous : committed.values;
256
285
  if (committed.token !== token) {
257
286
  setCommitted({
@@ -261,23 +290,82 @@ export function useUiLiveValues(block, nodes, readings) {
261
290
  });
262
291
  }
263
292
  if (!names.size) {
264
- return undefined;
265
- }
266
- return (id, prop, path) => {
267
- const related_1 = sources.get(id);
268
- if (!related_1) {
269
- return undefined;
293
+ let t3;
294
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
295
+ t3 = {
296
+ liveValue: undefined,
297
+ liveNode: undefined
298
+ };
299
+ $[10] = t3;
300
+ } else {
301
+ t3 = $[10];
270
302
  }
271
- const get = props => {
272
- const value_0 = props?.[prop];
273
- return path && Array.isArray(value_0) ? value_0[path[0]]?.[path[1]] : value_0;
303
+ return t3;
304
+ }
305
+ let t3;
306
+ if ($[11] !== readings) {
307
+ t3 = related_0 => related_0.some(name_0 => readings[name_0]?.state === "failed" || readings[name_0]?.state === "refused");
308
+ $[11] = readings;
309
+ $[12] = t3;
310
+ } else {
311
+ t3 = $[12];
312
+ }
313
+ const stale = t3;
314
+ let t4;
315
+ if ($[13] !== previous || $[14] !== sources || $[15] !== stale || $[16] !== values) {
316
+ t4 = (id, prop, path) => {
317
+ const related_1 = sources.get(id);
318
+ if (!related_1) {
319
+ return;
320
+ }
321
+ const before = previous.get(id)?.[prop];
322
+ const now = values.get(id)?.[prop];
323
+ const moved = path !== undefined && (!Array.isArray(before) || !Array.isArray(now) || before.length !== now.length);
324
+ const was = path && Array.isArray(before) ? before[path[0]]?.[path[1]] : before;
325
+ const is = path && Array.isArray(now) ? now[path[0]]?.[path[1]] : now;
326
+ return {
327
+ previous: moved ? undefined : was,
328
+ changed: !moved && was !== undefined && JSON.stringify(was) !== JSON.stringify(is),
329
+ stale: stale(related_1)
330
+ };
274
331
  };
275
- const before = get(previous.get(id));
276
- const value_1 = get(values.get(id));
277
- return {
278
- previous: before,
279
- changed: before !== undefined && JSON.stringify(before) !== JSON.stringify(value_1),
280
- stale: [...related_1].some(name_0 => readings[name_0]?.state === 'failed' || readings[name_0]?.state === 'refused')
332
+ $[13] = previous;
333
+ $[14] = sources;
334
+ $[15] = stale;
335
+ $[16] = values;
336
+ $[17] = t4;
337
+ } else {
338
+ t4 = $[17];
339
+ }
340
+ const liveValue = t4;
341
+ let t5;
342
+ if ($[18] !== sources || $[19] !== stale) {
343
+ t5 = id_0 => {
344
+ const related_2 = sources.get(id_0);
345
+ return related_2 === undefined ? undefined : stale(related_2) ? "stale" : "live";
281
346
  };
282
- };
347
+ $[18] = sources;
348
+ $[19] = stale;
349
+ $[20] = t5;
350
+ } else {
351
+ t5 = $[20];
352
+ }
353
+ const liveNode = t5;
354
+ let t6;
355
+ if ($[21] !== liveNode || $[22] !== liveValue) {
356
+ t6 = {
357
+ liveValue,
358
+ liveNode
359
+ };
360
+ $[21] = liveNode;
361
+ $[22] = liveValue;
362
+ $[23] = t6;
363
+ } else {
364
+ t6 = $[23];
365
+ }
366
+ return t6;
367
+ }
368
+ function _temp(t0) {
369
+ const [name, reading] = t0;
370
+ return [name, reading.state, reading.readId, reading.readAt];
283
371
  }
@@ -46,8 +46,9 @@ export declare function AgentTurnRow({ label, onOpen }: {
46
46
  label: string;
47
47
  onOpen?: () => void;
48
48
  }): import("react").JSX.Element;
49
- export declare function CompactionRow({ preTokens }: {
49
+ export declare function CompactionRow({ preTokens, postTokens }: {
50
50
  preTokens: number | null;
51
+ postTokens?: number;
51
52
  }): import("react").JSX.Element;
52
53
  export declare function SelectionSwitchRow({ chatId, from, to }: {
53
54
  chatId: string;