@adecore/agents-react 0.65.2 → 0.66.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.
Files changed (116) hide show
  1. package/dist/chat/activity.d.ts +5 -2
  2. package/dist/chat/activity.js +13 -2
  3. package/dist/chat/logic/bookmarks.d.ts +3 -2
  4. package/dist/chat/logic/continue-after-stop.d.ts +2 -2
  5. package/dist/chat/logic/fork.d.ts +7 -6
  6. package/dist/chat/logic/goal.d.ts +8 -3
  7. package/dist/chat/logic/goal.js +7 -1
  8. package/dist/chat/logic/handback.d.ts +2 -2
  9. package/dist/chat/logic/limit.d.ts +2 -2
  10. package/dist/chat/logic/limit.js +8 -0
  11. package/dist/chat/logic/resume-compaction.d.ts +4 -3
  12. package/dist/chat/logic/scrubber.d.ts +3 -2
  13. package/dist/chat/logic/timeline-target.d.ts +4 -3
  14. package/dist/chat/logic/timeline.d.ts +5 -4
  15. package/dist/chat/logic/timeline.js +9 -0
  16. package/dist/chat/recent-messages.d.ts +3 -3
  17. package/dist/chat/runtime-modes.d.ts +2 -1
  18. package/dist/chat/runtime-modes.js +5 -1
  19. package/dist/chat/subagent-conversation.d.ts +5 -4
  20. package/dist/chat/subagent-conversation.js +3 -2
  21. package/dist/chat/subagent-list.d.ts +4 -3
  22. package/dist/chat/subagent-view.d.ts +4 -3
  23. package/dist/chat/ui/ChatActivity.js +19 -15
  24. package/dist/chat/ui/Composer.d.ts +3 -2
  25. package/dist/chat/ui/GoalDock.d.ts +3 -2
  26. package/dist/chat/ui/GoalDock.js +19 -28
  27. package/dist/chat/ui/LimitState.d.ts +2 -2
  28. package/dist/chat/ui/RunSettings.d.ts +3 -2
  29. package/dist/chat/ui/RunSettings.js +318 -298
  30. package/dist/chat/ui/composer/ComposerControls.d.ts +2 -2
  31. package/dist/chat/ui/composer/use-chat-controls.d.ts +3 -2
  32. package/dist/chat/ui/composer/use-compaction-offer.d.ts +3 -2
  33. package/dist/chat/ui/composer/use-composer-menus.d.ts +3 -2
  34. package/dist/chat/ui/composer/use-continuable-turn.d.ts +2 -2
  35. package/dist/chat/ui/composer/use-effort-stepper.d.ts +3 -2
  36. package/dist/chat/ui/reply-context.d.ts +2 -2
  37. package/dist/chat/ui/rows/MessageRows.d.ts +4 -0
  38. package/dist/chat/ui/rows/MessageRows.js +61 -1
  39. package/dist/chat/ui/rows/Rows.js +42 -26
  40. package/dist/chat/ui/rows/SubagentRow.d.ts +3 -2
  41. package/dist/chat/ui/rows/WorkRows.d.ts +3 -2
  42. package/dist/chat/waiting-on.d.ts +5 -4
  43. package/dist/chat/waiting-on.js +2 -1
  44. package/dist/chat/workflow-list.d.ts +3 -2
  45. package/dist/chat-client.d.ts +2 -1
  46. package/dist/chat-sink.d.ts +16 -9
  47. package/dist/host/host-hooks.d.ts +2 -1
  48. package/dist/host/host-hooks.js +5 -0
  49. package/dist/host/host.d.ts +8 -2
  50. package/dist/host/timeline-row.d.ts +10 -4
  51. package/dist/index.d.ts +2 -2
  52. package/dist/locales/en/agent-chat.d.ts +16 -0
  53. package/dist/locales/en/agent-chat.js +17 -1
  54. package/dist/locales/nl/agent-chat.d.ts +16 -0
  55. package/dist/locales/nl/agent-chat.js +17 -1
  56. package/dist/port-transport.d.ts +10 -1
  57. package/dist/port-transport.js +14 -3
  58. package/dist/state/chats.d.ts +17 -15
  59. package/dist/state/chats.js +7 -0
  60. package/dist/state/index.d.ts +1 -1
  61. package/dist/state/usage.d.ts +3 -2
  62. package/dist/state/usage.js +34 -3
  63. package/dist/transport.d.ts +3 -2
  64. package/dist/usage/limit-groups.js +1 -1
  65. package/package.json +9 -9
  66. package/src/chat/activity.ts +19 -6
  67. package/src/chat/forks.ts +3 -3
  68. package/src/chat/logic/bookmarks.ts +3 -2
  69. package/src/chat/logic/continue-after-stop.ts +3 -2
  70. package/src/chat/logic/fork.ts +8 -7
  71. package/src/chat/logic/goal.ts +13 -4
  72. package/src/chat/logic/handback.ts +2 -3
  73. package/src/chat/logic/limit.ts +7 -2
  74. package/src/chat/logic/resume-compaction.ts +7 -6
  75. package/src/chat/logic/scrubber.ts +4 -3
  76. package/src/chat/logic/timeline-target.ts +4 -3
  77. package/src/chat/logic/timeline.ts +22 -16
  78. package/src/chat/pending-prompts.ts +3 -2
  79. package/src/chat/recent-messages.ts +5 -6
  80. package/src/chat/runtime-modes.ts +7 -2
  81. package/src/chat/subagent-conversation.ts +12 -9
  82. package/src/chat/subagent-list.ts +4 -3
  83. package/src/chat/subagent-view.ts +4 -3
  84. package/src/chat/ui/ChatActivity.tsx +11 -7
  85. package/src/chat/ui/Composer.tsx +3 -2
  86. package/src/chat/ui/GoalDock.tsx +6 -5
  87. package/src/chat/ui/LimitState.tsx +5 -5
  88. package/src/chat/ui/RunSettings.tsx +17 -9
  89. package/src/chat/ui/composer/ComposerControls.tsx +3 -2
  90. package/src/chat/ui/composer/use-chat-controls.ts +3 -2
  91. package/src/chat/ui/composer/use-compaction-offer.ts +4 -3
  92. package/src/chat/ui/composer/use-composer-menus.ts +3 -2
  93. package/src/chat/ui/composer/use-continuable-turn.ts +3 -3
  94. package/src/chat/ui/composer/use-effort-stepper.ts +3 -2
  95. package/src/chat/ui/reply-context.ts +2 -2
  96. package/src/chat/ui/rows/MessageRows.tsx +17 -1
  97. package/src/chat/ui/rows/Rows.tsx +3 -0
  98. package/src/chat/ui/rows/SubagentRow.tsx +5 -4
  99. package/src/chat/ui/rows/WorkRows.tsx +3 -2
  100. package/src/chat/ui/thread-references.ts +3 -3
  101. package/src/chat/waiting-on.ts +8 -7
  102. package/src/chat/workflow-list.ts +3 -2
  103. package/src/chat-client.ts +3 -2
  104. package/src/chat-sink.ts +21 -9
  105. package/src/host/host-hooks.ts +9 -1
  106. package/src/host/host.ts +13 -2
  107. package/src/host/timeline-row.ts +7 -5
  108. package/src/index.ts +2 -1
  109. package/src/locales/en/agent-chat.ts +17 -1
  110. package/src/locales/nl/agent-chat.ts +17 -1
  111. package/src/port-transport.ts +20 -3
  112. package/src/state/chats.ts +34 -35
  113. package/src/state/index.ts +1 -1
  114. package/src/state/usage.ts +45 -5
  115. package/src/transport.ts +4 -2
  116. package/src/usage/limit-groups.ts +1 -1
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ export {
19
19
  type VisualHost,
20
20
  type HostMenuAction,
21
21
  type ReplyAuthor,
22
+ type UnknownItemWords,
22
23
  type ChatHost,
23
24
  type UiMapSource,
24
25
  type UiModelViewProps,
@@ -48,7 +49,7 @@ export {
48
49
  isConnectionError
49
50
  } from './transport';
50
51
 
51
- export { portTransport, type PortTransport } from './port-transport';
52
+ export { portTransport, type PortTransport, type PortTransportOptions } from './port-transport';
52
53
  export { configureChatStorage } from './storage';
53
54
  export { type MountedEntry, MountedRegistry } from './mounted-registry';
54
55
  export { PROVIDERS_SECTION, USAGE_SECTION, settingsSection } from './settings/sections';
@@ -60,7 +60,8 @@ export default {
60
60
  blocked: 'Goal blocked',
61
61
  'usage-limited': 'Goal stopped on a usage limit',
62
62
  'budget-limited': 'Goal used up its token budget',
63
- complete: 'Goal met'
63
+ complete: 'Goal met',
64
+ unknown: 'Goal in a state this version does not know'
64
65
  },
65
66
  pill: 'Goal',
66
67
  checks_one: '{{count}} check not met yet',
@@ -74,6 +75,10 @@ export default {
74
75
  failed: 'Could not change goal'
75
76
  },
76
77
  limit: {
78
+ other: {
79
+ pill: 'Stopped',
80
+ title: 'Stopped on a limit'
81
+ },
77
82
  usage: {
78
83
  pill: 'Limited',
79
84
  pillUntil: 'Limited until {{time}}',
@@ -154,6 +159,10 @@ export default {
154
159
  thoughtFor: 'Thought for {{duration}}',
155
160
  thought: 'Thought'
156
161
  },
162
+ unknown: {
163
+ item: 'Update the app to see this.',
164
+ request: 'Answer this on the machine, or update the app to answer here.'
165
+ },
157
166
  note: {
158
167
  hide: 'Hide',
159
168
  show: 'Show',
@@ -480,6 +489,9 @@ export default {
480
489
  },
481
490
  shell: 'Shell',
482
491
  monitor: 'Monitor',
492
+ other: 'Background task',
493
+ others_one: '{{count}} background task',
494
+ others_other: '{{count}} background tasks',
483
495
  stop: 'Stop',
484
496
  stopFailed: 'Could not stop task'
485
497
  },
@@ -534,6 +546,10 @@ export default {
534
546
  label: 'Full access',
535
547
  hint: 'Never asks for approval',
536
548
  short: 'Full access'
549
+ },
550
+ unknown: {
551
+ label: 'Set on the machine',
552
+ short: 'On the machine'
537
553
  }
538
554
  },
539
555
  pickers: {
@@ -60,7 +60,8 @@ export default {
60
60
  blocked: 'Doel geblokkeerd',
61
61
  'usage-limited': 'Doel gestopt op een verbruikslimiet',
62
62
  'budget-limited': 'Doel heeft zijn tokenbudget op',
63
- complete: 'Doel bereikt'
63
+ complete: 'Doel bereikt',
64
+ unknown: 'Doel in een toestand die deze versie niet kent'
64
65
  },
65
66
  pill: 'Doel',
66
67
  checks_one: '{{count}} controle nog niet gehaald',
@@ -74,6 +75,10 @@ export default {
74
75
  failed: 'Kon het doel niet wijzigen'
75
76
  },
76
77
  limit: {
78
+ other: {
79
+ pill: 'Gestopt',
80
+ title: 'Gestopt op een limiet'
81
+ },
77
82
  usage: {
78
83
  pill: 'Limiet bereikt',
79
84
  pillUntil: 'Limiet tot {{time}}',
@@ -154,6 +159,10 @@ export default {
154
159
  thoughtFor: 'Nagedacht, {{duration}}',
155
160
  thought: 'Gedachte'
156
161
  },
162
+ unknown: {
163
+ item: 'Werk de app bij om dit te zien.',
164
+ request: 'Beantwoord dit op de machine, of werk de app bij om hier te antwoorden.'
165
+ },
157
166
  note: {
158
167
  hide: 'Verbergen',
159
168
  show: 'Tonen',
@@ -480,6 +489,9 @@ export default {
480
489
  },
481
490
  shell: 'Shell',
482
491
  monitor: 'Monitor',
492
+ other: 'Achtergrondtaak',
493
+ others_one: '{{count}} achtergrondtaak',
494
+ others_other: '{{count}} achtergrondtaken',
483
495
  stop: 'Stoppen',
484
496
  stopFailed: 'Kon de taak niet stoppen'
485
497
  },
@@ -534,6 +546,10 @@ export default {
534
546
  label: 'Volledige toegang',
535
547
  hint: 'Vraagt nooit om goedkeuring',
536
548
  short: 'Volledig'
549
+ },
550
+ unknown: {
551
+ label: 'Ingesteld op de machine',
552
+ short: 'Op de machine'
537
553
  }
538
554
  },
539
555
  pickers: {
@@ -1,6 +1,7 @@
1
1
  import { parseServerFrame } from '@adecore/agent-contracts/envelope';
2
2
  import type { FramePort } from '@adecore/agent-contracts/port';
3
3
  import { AGENT_EVENT_SCHEMAS, AGENT_REQUEST_SCHEMAS, type AgentEventType, type AgentRequestType } from '@adecore/agent-contracts/protocol';
4
+ import { readTolerant, type WireDegradation } from '@adecore/agent-contracts/tolerance';
4
5
  import i18next from 'i18next';
5
6
  import { ChatTransportError, type ChatEventMap, type ChatRequestMap, type ChatTransport, type ChatTransportStatus } from './transport';
6
7
 
@@ -9,6 +10,14 @@ export interface PortTransport extends ChatTransport {
9
10
  close(): void;
10
11
  }
11
12
 
13
+ export interface PortTransportOptions {
14
+ /*
15
+ * A reply or event of a newer host that was read by giving something up, with what; for the app to report, since
16
+ * this package keeps no telemetry. It runs for every such frame, so an app that reports keeps its own count.
17
+ */
18
+ onDegraded?(source: { readonly request: AgentRequestType } | { readonly event: AgentEventType }, degraded: readonly WireDegradation[]): void;
19
+ }
20
+
12
21
  interface Pending {
13
22
  type: AgentRequestType;
14
23
  resolve(result: unknown): void;
@@ -25,7 +34,7 @@ function isEventType(event: string): event is AgentEventType {
25
34
  * until `close`. Frames are checked where they arrive, and a frame that does not hold up is dropped
26
35
  * with a warning, the way the socket transport of an app drops one.
27
36
  */
28
- export function portTransport(port: FramePort): PortTransport {
37
+ export function portTransport(port: FramePort, options: PortTransportOptions = {}): PortTransport {
29
38
  let status: ChatTransportStatus = 'open';
30
39
  let nextId = 1;
31
40
  const pending = new Map<string, Pending>();
@@ -47,7 +56,7 @@ export function portTransport(port: FramePort): PortTransport {
47
56
  return;
48
57
  }
49
58
 
50
- const result = AGENT_REQUEST_SCHEMAS[entry.type].result.safeParse(frame.result);
59
+ const result = readTolerant(AGENT_REQUEST_SCHEMAS[entry.type].result, frame.result);
51
60
 
52
61
  if (!result.success) {
53
62
  entry.reject(new ChatTransportError('bad-reply', i18next.t('agent-chat:transport.badReply', { type: entry.type })));
@@ -55,6 +64,10 @@ export function portTransport(port: FramePort): PortTransport {
55
64
  return;
56
65
  }
57
66
 
67
+ if (result.degraded.length > 0) {
68
+ options.onDegraded?.({ request: entry.type }, result.degraded);
69
+ }
70
+
58
71
  entry.resolve(result.data);
59
72
  };
60
73
 
@@ -65,7 +78,7 @@ export function portTransport(port: FramePort): PortTransport {
65
78
  return;
66
79
  }
67
80
 
68
- const parsed = AGENT_EVENT_SCHEMAS[event].safeParse(payload);
81
+ const parsed = readTolerant(AGENT_EVENT_SCHEMAS[event], payload);
69
82
 
70
83
  if (!parsed.success) {
71
84
  console.warn(`Dropped a malformed ${event} event`);
@@ -73,6 +86,10 @@ export function portTransport(port: FramePort): PortTransport {
73
86
  return;
74
87
  }
75
88
 
89
+ if (parsed.degraded.length > 0) {
90
+ options.onDegraded?.({ event }, parsed.degraded);
91
+ }
92
+
76
93
  // A copy, so a handler that unsubscribes while it runs does not change the set being walked.
77
94
  for (const handler of [...(eventHandlers.get(event) ?? [])]) {
78
95
  (handler as (payload: unknown) => void)(parsed.data);
@@ -1,30 +1,21 @@
1
- import type {
2
- AgentKind,
3
- ChatApprovalItem,
4
- ChatBookmark,
5
- ChatEvent,
6
- ChatHistoryResult,
7
- ChatInfo,
8
- ChatItem,
9
- ChatQuestionItem,
10
- ChatVisual
11
- } from '@adecore/agent-contracts';
1
+ import type { AgentKind, ChatApprovalItem, ChatBookmark, ChatHistoryResult, ChatQuestionItem, ChatUnknownItem, ChatVisual } from '@adecore/agent-contracts';
12
2
  import { appendToolOutput } from '@adecore/agent-contracts/text';
3
+ import type { Tolerant } from '@adecore/agent-contracts/tolerance';
13
4
  import { useContext } from 'react';
14
5
  import { create } from 'zustand';
15
- import type { ChatHistoryPage, ChatPage, ChatSink } from '../chat-sink';
6
+ import type { ChatHistoryPage, ChatPage, ChatSink, ChatThreadEvent, ChatThreadInfo, ChatThreadItem } from '../chat-sink';
16
7
  import { ChatScopeContext, useChatScope } from '../scope';
17
8
 
18
9
  export interface ChatState {
19
- info: ChatInfo;
10
+ info: ChatThreadInfo;
20
11
  /* Status and live events do not establish where the initial history begins. */
21
12
  historyPending?: boolean;
22
- items: Record<string, ChatItem>;
13
+ items: Record<string, ChatThreadItem>;
23
14
  /*
24
15
  * `items`, except that a delta growing a reply or thought that has text, or a running call's output,
25
16
  * leaves it as it was. The rows derive from this, so a word redraws only its row (`useCurrentItem`).
26
17
  */
27
- structure: Record<string, ChatItem>;
18
+ structure: Record<string, ChatThreadItem>;
28
19
  order: string[];
29
20
  /* Where the part of the thread this client holds begins; absent when it holds the whole thread. */
30
21
  history?: ChatHistoryPage;
@@ -47,7 +38,7 @@ export interface ChatState {
47
38
  * The outline of the thread before that part (`outlineItems`), cut down and kept apart from
48
39
  * `items`, so the scrubber has a tick for every message before a scroll reaches it.
49
40
  */
50
- outlineBefore?: ChatItem[];
41
+ outlineBefore?: ChatThreadItem[];
51
42
  /* The messages marked to come back to, as the host last said; absent until it said anything. */
52
43
  bookmarks?: ChatBookmark[];
53
44
  /* The pages agents published in the chat, as the host last said; absent until it said anything. */
@@ -64,11 +55,11 @@ interface ChatsStore {
64
55
  byKey: ChatsById;
65
56
  /* Replaced only when a chat's info is, never for a streamed word, so what reads the status alone is not redrawn by one. */
66
57
  statusByKey: ChatStatuses;
67
- reset(key: string, info: ChatInfo, items: ChatItem[], page?: ChatPage): void;
68
- prepend(key: string, cursor: string, page: ChatHistoryResult): void;
69
- apply(key: string, event: ChatEvent): void;
70
- replay(key: string, events: readonly ChatEvent[]): void;
71
- status(key: string, info: ChatInfo): void;
58
+ reset(key: string, info: ChatThreadInfo, items: ChatThreadItem[], page?: ChatPage): void;
59
+ prepend(key: string, cursor: string, page: Tolerant<ChatHistoryResult>): void;
60
+ apply(key: string, event: ChatThreadEvent): void;
61
+ replay(key: string, events: readonly ChatThreadEvent[]): void;
62
+ status(key: string, info: ChatThreadInfo): void;
72
63
  bookmarks(key: string, bookmarks: ChatBookmark[]): void;
73
64
  visuals(key: string, visuals: ChatVisual[]): void;
74
65
  forget(key: string): void;
@@ -76,11 +67,16 @@ interface ChatsStore {
76
67
  forgetWhere(matches: (key: string) => boolean): void;
77
68
  }
78
69
 
79
- export function isWaiting(item: ChatItem | undefined): item is ChatApprovalItem | ChatQuestionItem {
70
+ export function isWaiting(item: ChatThreadItem | undefined): item is ChatApprovalItem | ChatQuestionItem {
80
71
  return (item?.kind === 'approval' && item.decision === 'pending') || (item?.kind === 'question' && item.state === 'pending');
81
72
  }
82
73
 
83
- function stateOf(info: ChatInfo, items: ChatItem[], page?: ChatPage): ChatState {
74
+ /* An approval or question of a newer host that still waits; this version never answers it, so its row says where to. */
75
+ export function waitsOnTheHost(item: ChatUnknownItem): boolean {
76
+ return (item.raw.kind === 'approval' && item.raw.decision === 'pending') || (item.raw.kind === 'question' && item.raw.state === 'pending');
77
+ }
78
+
79
+ function stateOf(info: ChatThreadInfo, items: ChatThreadItem[], page?: ChatPage): ChatState {
84
80
  const byId = Object.fromEntries(items.map((item) => [item.id, item]));
85
81
  const order = items.map((item) => item.id);
86
82
 
@@ -114,10 +110,10 @@ function isBeforePage(state: ChatState, historyIndex: number | undefined): boole
114
110
  return state.history !== undefined && historyIndex !== undefined && historyIndex < state.history.start;
115
111
  }
116
112
 
117
- type ItemWriter = (state: ChatState, item: ChatItem, structural?: boolean) => ChatState;
113
+ type ItemWriter = (state: ChatState, item: ChatThreadItem, structural?: boolean) => ChatState;
118
114
 
119
115
  /* An item from before the page this client holds matters only as a sub-agent, a workflow, a request that waits, or one that stopped waiting. */
120
- function withEarlierItem(state: ChatState, item: ChatItem, write: ItemWriter): ChatState {
116
+ function withEarlierItem(state: ChatState, item: ChatThreadItem, write: ItemWriter): ChatState {
121
117
  if (item.kind === 'subagent') {
122
118
  const subagents = state.subagentsBefore ?? [];
123
119
 
@@ -141,7 +137,7 @@ function withEarlierItem(state: ChatState, item: ChatItem, write: ItemWriter): C
141
137
  }
142
138
 
143
139
  /* The page before the one a chat holds, unless the thread was read again since that page was asked for. */
144
- export function prependPage(state: ChatState, cursor: string, page: ChatHistoryResult): ChatState {
140
+ export function prependPage(state: ChatState, cursor: string, page: Tolerant<ChatHistoryResult>): ChatState {
145
141
  if (state.history?.cursor !== cursor) {
146
142
  return state;
147
143
  }
@@ -185,18 +181,18 @@ export function waitingRequestsOf(chat: Pick<ChatState, 'structure' | 'order' |
185
181
  return [...(chat?.waitingBefore ?? []), ...(chat?.order ?? [])].map((id) => chat?.structure[id]).filter(isWaiting);
186
182
  }
187
183
 
188
- function withItem(state: ChatState, item: ChatItem, structural = true): ChatState {
184
+ function withItem(state: ChatState, item: ChatThreadItem, structural = true): ChatState {
189
185
  const items = { ...state.items, [item.id]: item };
190
186
 
191
187
  return structural ? { ...state, items, structure: items } : { ...state, items };
192
188
  }
193
189
 
194
190
  /* Cheap enough, since a status only arrives when the host saw one change, never on a streamed word. */
195
- function sameInfo(left: ChatInfo, right: ChatInfo): boolean {
191
+ function sameInfo(left: ChatThreadInfo, right: ChatThreadInfo): boolean {
196
192
  return JSON.stringify(left) === JSON.stringify(right);
197
193
  }
198
194
 
199
- function withStatus(statuses: ChatStatuses, key: string, info: ChatInfo): ChatStatuses {
195
+ function withStatus(statuses: ChatStatuses, key: string, info: ChatThreadInfo): ChatStatuses {
200
196
  return statuses[key]?.info === info ? statuses : { ...statuses, [key]: { info } };
201
197
  }
202
198
 
@@ -204,12 +200,12 @@ function without<T>(rows: Record<string, T>, matches: (key: string) => boolean):
204
200
  return Object.fromEntries(Object.entries(rows).filter(([key]) => !matches(key)));
205
201
  }
206
202
 
207
- export function applyEvent(state: ChatState, event: ChatEvent): ChatState {
203
+ export function applyEvent(state: ChatState, event: ChatThreadEvent): ChatState {
208
204
  return applyUpdate(state, event, withItem);
209
205
  }
210
206
 
211
- function replayEvents(state: ChatState, events: readonly ChatEvent[]): ChatState {
212
- let draft: Record<string, ChatItem> | undefined;
207
+ function replayEvents(state: ChatState, events: readonly ChatThreadEvent[]): ChatState {
208
+ let draft: Record<string, ChatThreadItem> | undefined;
213
209
 
214
210
  const write: ItemWriter = (current, item, structural = true) => {
215
211
  // A text delta must leave the last structural snapshot intact, including within this replay.
@@ -230,7 +226,7 @@ function replayEvents(state: ChatState, events: readonly ChatEvent[]): ChatState
230
226
  return state;
231
227
  }
232
228
 
233
- function applyUpdate(state: ChatState, event: ChatEvent, write: ItemWriter): ChatState {
229
+ function applyUpdate(state: ChatState, event: ChatThreadEvent, write: ItemWriter): ChatState {
234
230
  switch (event.type) {
235
231
  case 'item': {
236
232
  if (isBeforePage(state, event.historyIndex)) {
@@ -250,7 +246,7 @@ function applyUpdate(state: ChatState, event: ChatEvent, write: ItemWriter): Cha
250
246
  const grown = event.text === '' ? state : applyUpdate(state, text, write);
251
247
  const reply = grown.items[event.itemId] ?? item;
252
248
 
253
- return write(grown, { ...reply, uiQueries } as ChatItem, false);
249
+ return write(grown, { ...reply, uiQueries } as ChatThreadItem, false);
254
250
  }
255
251
 
256
252
  if (event.ui !== undefined && event.text === '') {
@@ -280,6 +276,9 @@ function applyUpdate(state: ChatState, event: ChatEvent, write: ItemWriter): Cha
280
276
  return { ...state, info: event.info };
281
277
  case 'reset':
282
278
  return stateOf(event.info, event.items);
279
+ // A newer host's event; guessing what it does could only leave the thread wrong.
280
+ case 'unknown':
281
+ return state;
283
282
  }
284
283
  }
285
284
 
@@ -464,7 +463,7 @@ export function useAwaitsApproval(chatId: string, toolUseId: string): boolean {
464
463
  }
465
464
 
466
465
  /* The item as the thread holds it now, for a row derived from the structure, which a delta leaves alone. */
467
- export function useCurrentItem<T extends ChatItem>(chatId: string, derived: T): T {
466
+ export function useCurrentItem<T extends ChatThreadItem>(chatId: string, derived: T): T {
468
467
  return useChatRow(chatId, (row) => {
469
468
  const item = row?.items[derived.id];
470
469
 
@@ -1,6 +1,6 @@
1
1
  // Public API: exports.test.ts snapshots this list, so a name added or dropped here is an API change.
2
2
  export { type ChatState, type ChatsById, type ChatStatuses, waitingRequestsOf, applyEvent, useChats, chatSink, useChatRow } from './chats';
3
- export type { ChatHistoryPage, ChatSink } from '../chat-sink';
3
+ export type { ChatHistoryPage, ChatSink, ChatThreadEvent, ChatThreadInfo, ChatThreadItem, ChatThreadTurn } from '../chat-sink';
4
4
 
5
5
  export { useProviderAccountsStore, useProviderAccounts, providerAccountsOf, knownAccounts, watchProviderAccounts } from './provider-accounts';
6
6
 
@@ -1,4 +1,13 @@
1
- import { UsageRateSchema, type UsageLimitsSnapshot, type UsageRate, type UsageSummaryPayload, type UsageSummaryResult } from '@adecore/agent-contracts';
1
+ import {
2
+ UsageProviderSchema,
3
+ UsageRateSchema,
4
+ type UsageLimitsSnapshot,
5
+ type UsageProvider,
6
+ type UsageRate,
7
+ type UsageSummaryPayload,
8
+ type UsageSummaryResult
9
+ } from '@adecore/agent-contracts';
10
+ import type { Tolerant } from '@adecore/agent-contracts/tolerance';
2
11
  import { localTimeZone } from '@adecore/ui/format';
3
12
  import { persistedJson } from '../persisted-json';
4
13
  import { useChatScope } from '../scope';
@@ -103,6 +112,35 @@ interface UsageRow {
103
112
  limits: UsageLimitsSnapshot | null;
104
113
  }
105
114
 
115
+ /* A row of a provider a newer host reads is left off: this version has no name, color or price basis for it. */
116
+ function isUsageProvider(word: string): word is UsageProvider {
117
+ return (UsageProviderSchema.options as readonly string[]).includes(word);
118
+ }
119
+
120
+ function knownProvider<Row extends { provider: string }>(row: Row): row is Row & { provider: UsageProvider } {
121
+ return isUsageProvider(row.provider);
122
+ }
123
+
124
+ function knownKind<Row extends { kind: string }>(row: Row): row is Row & { kind: UsageProvider } {
125
+ return isUsageProvider(row.kind);
126
+ }
127
+
128
+ function knownSummary(summary: Tolerant<UsageSummaryResult>): UsageSummaryResult {
129
+ const { accounts, ...rest } = summary;
130
+
131
+ return {
132
+ ...rest,
133
+ buckets: summary.buckets.filter(knownProvider),
134
+ models: summary.models.filter(knownProvider),
135
+ roots: summary.roots.filter(knownProvider),
136
+ ...(accounts === undefined ? {} : { accounts: accounts.filter(knownKind) })
137
+ };
138
+ }
139
+
140
+ function knownLimits(limits: Tolerant<UsageLimitsSnapshot>): UsageLimitsSnapshot {
141
+ return { providers: limits.providers.filter(knownKind) };
142
+ }
143
+
106
144
  /* One object for a host nothing was read from yet, so a selector gets a stable snapshot. */
107
145
  const EMPTY: UsageRow = { asked: null, summary: null, loading: false, failed: false, limits: null };
108
146
 
@@ -118,9 +156,9 @@ interface UsageStore extends Preferences {
118
156
  setMetric(metric: UsageMetric): void;
119
157
  setCurrency(currency: UsageCurrency): void;
120
158
  setLoading(scopeId: string, loading: boolean): void;
121
- receive(scopeId: string, asked: string, summary: UsageSummaryResult): void;
159
+ receive(scopeId: string, asked: string, summary: Tolerant<UsageSummaryResult>): void;
122
160
  fail(scopeId: string): void;
123
- setLimits(scopeId: string, limits: UsageLimitsSnapshot): void;
161
+ setLimits(scopeId: string, limits: Tolerant<UsageLimitsSnapshot>): void;
124
162
  /* A host that is forgotten takes its numbers with it; the three preferences are the viewer's and stay. */
125
163
  forget(scopeId: string): void;
126
164
  }
@@ -160,7 +198,9 @@ export const useUsageStore = createChatStore<UsageStore>(
160
198
  setLoading(scopeId, loading) {
161
199
  patchRow(scopeId, { loading });
162
200
  },
163
- receive(scopeId, asked, summary) {
201
+ receive(scopeId, asked, read) {
202
+ const summary = knownSummary(read);
203
+
164
204
  patchRow(scopeId, { asked, summary, loading: false, failed: false });
165
205
 
166
206
  if (summary.rate !== null && JSON.stringify(summary.rate) !== JSON.stringify(get().rate)) {
@@ -171,7 +211,7 @@ export const useUsageStore = createChatStore<UsageStore>(
171
211
  patchRow(scopeId, { loading: false, failed: true });
172
212
  },
173
213
  setLimits(scopeId, limits) {
174
- patchRow(scopeId, { limits });
214
+ patchRow(scopeId, { limits: knownLimits(limits) });
175
215
  },
176
216
  forget(scopeId) {
177
217
  const { [scopeId]: _gone, ...rest } = get().byScope;
package/src/transport.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import type { AGENT_EVENT_SCHEMAS, AGENT_REQUEST_SCHEMAS, AgentEventType, AgentRequestType } from '@adecore/agent-contracts/protocol';
2
+ import type { Tolerant } from '@adecore/agent-contracts/tolerance';
2
3
  import type { z } from 'zod';
3
4
 
5
+ // What a client sends stays strict; what it reads may come from a newer host, as `readTolerant` reads it.
4
6
  export type ChatRequestMap = {
5
7
  [T in AgentRequestType]: {
6
8
  payload: z.infer<(typeof AGENT_REQUEST_SCHEMAS)[T]['payload']>;
7
- result: z.infer<(typeof AGENT_REQUEST_SCHEMAS)[T]['result']>;
9
+ result: Tolerant<z.infer<(typeof AGENT_REQUEST_SCHEMAS)[T]['result']>>;
8
10
  };
9
11
  };
10
12
 
11
13
  export type ChatEventMap = {
12
- [E in AgentEventType]: z.infer<(typeof AGENT_EVENT_SCHEMAS)[E]>;
14
+ [E in AgentEventType]: Tolerant<z.infer<(typeof AGENT_EVENT_SCHEMAS)[E]>>;
13
15
  };
14
16
 
15
17
  export type ChatTransportStatus = 'connecting' | 'open' | 'closed';
@@ -180,7 +180,7 @@ export function explain(provider: UsageLimitsProvider): string | null {
180
180
  return provider.unavailable.message ?? i18next.t('agent-usage:limits.noSubscription');
181
181
  }
182
182
 
183
- return provider.unavailable.message ?? i18next.t('agent-usage:limits.unreachable');
183
+ return i18next.t('agent-usage:limits.unreachable');
184
184
  }
185
185
 
186
186
  /* The explanation for an account, including a failed read beside retained bars. An account the machine does not read says what its login is doing. */