@zeyos/zx 5.5.0 → 5.6.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.
- package/CHANGELOG.md +56 -0
- package/dist/types/components/agent-thread/agent-thread.d.ts +583 -0
- package/dist/types/components/approval-card/approval-card.d.ts +596 -0
- package/dist/types/components/avatar/avatar.d.ts +91 -4
- package/dist/types/components/block-view/block-view.d.ts +205 -0
- package/dist/types/components/composer/composer.d.ts +736 -0
- package/dist/types/components/run-status/run-status.d.ts +393 -0
- package/dist/types/components/run-trace/run-trace.d.ts +624 -0
- package/dist/types/components/source-list/source-list.d.ts +177 -0
- package/dist/types/core/messages.d.ts +135 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/internal/agent-model.d.ts +587 -0
- package/dist/types/internal/highlight.d.ts +24 -0
- package/dist/types/internal/presence-loop.d.ts +148 -0
- package/dist/zx-zeyos.esm.js +4648 -4513
- package/dist/zx-zeyos.esm.min.js +2 -2
- package/dist/zx.css +1927 -1
- package/dist/zx.esm.js +15769 -9194
- package/dist/zx.esm.min.js +27 -8
- package/dist/zx.global.js +15769 -9194
- package/dist/zx.global.min.js +27 -8
- package/dist/zx.min.css +1 -1
- package/docs/api.json +1166 -5
- package/docs/llms.md +455 -2
- package/docs/llms.txt +10 -1
- package/package.json +1 -1
- package/src/components/agent-thread/agent-thread.css +417 -0
- package/src/components/agent-thread/agent-thread.js +1365 -0
- package/src/components/approval-card/approval-card.css +289 -0
- package/src/components/approval-card/approval-card.js +1377 -0
- package/src/components/avatar/avatar.css +56 -1
- package/src/components/avatar/avatar.js +148 -26
- package/src/components/block-view/block-view.css +300 -0
- package/src/components/block-view/block-view.js +523 -0
- package/src/components/composer/composer.css +403 -0
- package/src/components/composer/composer.js +1441 -0
- package/src/components/run-status/run-status.css +208 -0
- package/src/components/run-status/run-status.js +782 -0
- package/src/components/run-trace/run-trace.css +443 -0
- package/src/components/run-trace/run-trace.js +1209 -0
- package/src/components/source-list/source-list.css +208 -0
- package/src/components/source-list/source-list.js +355 -0
- package/src/core/messages.js +143 -0
- package/src/index.js +8 -0
- package/src/internal/agent-model.js +488 -0
- package/src/internal/highlight.js +104 -0
- package/src/internal/presence-loop.js +343 -0
- package/styles/zx.css +7 -0
package/src/core/messages.js
CHANGED
|
@@ -24,6 +24,47 @@ export const defaultMessages = Object.freeze({
|
|
|
24
24
|
'activityItem.pending': 'Sending…',
|
|
25
25
|
'activityItem.untitled': 'activity',
|
|
26
26
|
|
|
27
|
+
'agent.activity.blocked': 'Blocked',
|
|
28
|
+
'agent.activity.idle': 'Idle',
|
|
29
|
+
'agent.activity.needsYou': 'Needs you',
|
|
30
|
+
'agent.activity.offline': 'Offline',
|
|
31
|
+
'agent.activity.thinking': 'Thinking',
|
|
32
|
+
'agent.activity.working': 'Working',
|
|
33
|
+
'agent.status.done': 'Done',
|
|
34
|
+
'agent.status.failed': 'Failed',
|
|
35
|
+
'agent.status.paused': 'Paused',
|
|
36
|
+
'agent.status.queued': 'Not started',
|
|
37
|
+
'agent.status.running': 'Running',
|
|
38
|
+
'agent.status.skipped': 'Skipped',
|
|
39
|
+
'agent.status.stopped': 'Stopped',
|
|
40
|
+
'agent.status.waiting': 'Waiting for you',
|
|
41
|
+
'agent.status.blocked': 'Blocked',
|
|
42
|
+
|
|
43
|
+
'agentThread.agent': 'Agent',
|
|
44
|
+
'agentThread.answered': '%1 answered',
|
|
45
|
+
'agentThread.attachments': 'Attachments',
|
|
46
|
+
'agentThread.branch': 'Branch into a new conversation',
|
|
47
|
+
'agentThread.copy': 'Copy answer',
|
|
48
|
+
'agentThread.label': 'Conversation',
|
|
49
|
+
'agentThread.latest': 'Jump to latest',
|
|
50
|
+
'agentThread.needsApproval': '%1 needs your approval',
|
|
51
|
+
'agentThread.nextVersion': 'Next version',
|
|
52
|
+
'agentThread.previousVersion': 'Previous version',
|
|
53
|
+
'agentThread.rateDown': 'Not helpful',
|
|
54
|
+
'agentThread.rateUp': 'Helpful',
|
|
55
|
+
'agentThread.regenerate': 'Regenerate answer',
|
|
56
|
+
'agentThread.sources': 'Sources',
|
|
57
|
+
'agentThread.stopped': 'Stopped',
|
|
58
|
+
'agentThread.stoppedAnnounce': 'Stopped',
|
|
59
|
+
'agentThread.version': 'Version %1 of %2',
|
|
60
|
+
'agentThread.via': 'via %1',
|
|
61
|
+
'agentThread.working': '%1 is working',
|
|
62
|
+
'agentThread.writing': '%1 is writing an answer',
|
|
63
|
+
'agentThread.you': 'You',
|
|
64
|
+
'agentThread.writingNow': '%1 is writing…',
|
|
65
|
+
'agentThread.edit': 'Edit message',
|
|
66
|
+
'agentThread.copyMessage': 'Copy message',
|
|
67
|
+
|
|
27
68
|
'appRail.subNavigation': '%1 sub-navigation',
|
|
28
69
|
|
|
29
70
|
'appSidebar.expand': 'Expand application sidebar',
|
|
@@ -34,6 +75,44 @@ export const defaultMessages = Object.freeze({
|
|
|
34
75
|
'appSidebar.presentationCompact': 'Module menu collapsed',
|
|
35
76
|
'appSidebar.presentationExpanded': 'Both menus expanded',
|
|
36
77
|
|
|
78
|
+
'approvalCard.approve': 'Approve',
|
|
79
|
+
'approvalCard.approvedBy': 'Approved by %1 at %2',
|
|
80
|
+
'approvalCard.approvedByUndated': 'Approved by %1',
|
|
81
|
+
'approvalCard.cancel': 'Cancel',
|
|
82
|
+
'approvalCard.edit': 'Edit',
|
|
83
|
+
'approvalCard.editTitle': 'Edit the request',
|
|
84
|
+
'approvalCard.editedBy': 'Edited by %1',
|
|
85
|
+
'approvalCard.expiredAt': 'Expired at %1',
|
|
86
|
+
'approvalCard.expiredUndated': 'Expired without an answer',
|
|
87
|
+
'approvalCard.paused': 'The run is paused until you answer.',
|
|
88
|
+
'approvalCard.preview': 'Preview',
|
|
89
|
+
'approvalCard.reason': 'Reason',
|
|
90
|
+
'approvalCard.reasonLabel': 'Why not?',
|
|
91
|
+
'approvalCard.reasonMissing': 'Say why, so the agent can do better next time.',
|
|
92
|
+
'approvalCard.reasonOptional': 'Optional. Your reason stays with the request.',
|
|
93
|
+
'approvalCard.reasonRequired': 'Your reason stays with the request.',
|
|
94
|
+
'approvalCard.reject': 'Reject',
|
|
95
|
+
'approvalCard.rejectTitle': 'Reject the request?',
|
|
96
|
+
'approvalCard.rejectedBy': 'Rejected by %1 at %2',
|
|
97
|
+
'approvalCard.rejectedByUndated': 'Rejected by %1',
|
|
98
|
+
'approvalCard.required': 'Fill this in to save.',
|
|
99
|
+
'approvalCard.save': 'Save changes',
|
|
100
|
+
'approvalCard.status.approved': 'Approved',
|
|
101
|
+
'approvalCard.status.expired': 'Expired',
|
|
102
|
+
'approvalCard.status.pending': 'Waiting for you',
|
|
103
|
+
'approvalCard.status.rejected': 'Rejected',
|
|
104
|
+
'approvalCard.you': 'you',
|
|
105
|
+
|
|
106
|
+
'blockView.cite': 'Source %1',
|
|
107
|
+
'blockView.citeTitled': 'Source %1: %2',
|
|
108
|
+
'blockView.code': 'Code',
|
|
109
|
+
'blockView.copyCode': 'Copy code',
|
|
110
|
+
'blockView.document': 'Document',
|
|
111
|
+
'blockView.stopped': 'Stopped here.',
|
|
112
|
+
'blockView.table': 'Table',
|
|
113
|
+
'blockView.version': '1 version',
|
|
114
|
+
'blockView.versions': '%1 versions',
|
|
115
|
+
|
|
37
116
|
'breadcrumb.label': 'Breadcrumb',
|
|
38
117
|
'breadcrumb.more': 'Show hidden levels',
|
|
39
118
|
|
|
@@ -77,6 +156,20 @@ export const defaultMessages = Object.freeze({
|
|
|
77
156
|
'checklist.label': 'Checklist',
|
|
78
157
|
'checklist.search': 'Search',
|
|
79
158
|
|
|
159
|
+
'composer.attach': 'Attach files',
|
|
160
|
+
'composer.attachments': 'Attachments',
|
|
161
|
+
'composer.commands': 'Commands',
|
|
162
|
+
'composer.commandsPlaceholder': 'Search commands',
|
|
163
|
+
'composer.context': 'Context',
|
|
164
|
+
'composer.drop': 'Drop files to attach',
|
|
165
|
+
'composer.label': 'Message',
|
|
166
|
+
'composer.match': '1 suggestion',
|
|
167
|
+
'composer.matches': '%1 suggestions',
|
|
168
|
+
'composer.remove': 'Remove %1',
|
|
169
|
+
'composer.send': 'Send',
|
|
170
|
+
'composer.stop': 'Stop',
|
|
171
|
+
'composer.suggestions': 'Suggestions',
|
|
172
|
+
|
|
80
173
|
'dataFilter.all': 'All',
|
|
81
174
|
'dataFilter.clear': 'Clear',
|
|
82
175
|
|
|
@@ -277,6 +370,53 @@ export const defaultMessages = Object.freeze({
|
|
|
277
370
|
'recordView.moveFieldDown': 'Move %1 down',
|
|
278
371
|
'recordView.moveFieldUp': 'Move %1 up',
|
|
279
372
|
|
|
373
|
+
'runStatus.cost': '%1 of %2',
|
|
374
|
+
'runStatus.costLabel': 'Cost',
|
|
375
|
+
'runStatus.dateTimeFormat': '%e %b, %H:%M',
|
|
376
|
+
'runStatus.failedAt': 'Failed at',
|
|
377
|
+
'runStatus.finished': 'Finished',
|
|
378
|
+
'runStatus.model': 'Model',
|
|
379
|
+
'runStatus.started': 'Started',
|
|
380
|
+
'runStatus.steps': '%1 of %2 steps',
|
|
381
|
+
'runStatus.stepsLabel': 'Steps done',
|
|
382
|
+
'runStatus.stoppedAt': 'Stopped at',
|
|
383
|
+
'runStatus.timeFormat': '%H:%M',
|
|
384
|
+
'runStatus.tokens': 'Tokens',
|
|
385
|
+
'runStatus.tokensValue': '%1 in · %2 out',
|
|
386
|
+
'runStatus.waitingSince': 'Waiting since',
|
|
387
|
+
'runStatus.workingTime': 'Working time',
|
|
388
|
+
'runStatus.blockedSince': 'Blocked since',
|
|
389
|
+
'runStatus.tokenBudget': '%1 of %2 tokens',
|
|
390
|
+
|
|
391
|
+
'runTrace.arguments': 'Arguments',
|
|
392
|
+
'runTrace.awaiting': 'Waiting for the result…',
|
|
393
|
+
'runTrace.call': '1 tool call',
|
|
394
|
+
'runTrace.calls': '%1 tool calls',
|
|
395
|
+
'runTrace.copied': 'Copied',
|
|
396
|
+
'runTrace.copyArguments': 'Copy arguments',
|
|
397
|
+
'runTrace.copyError': 'Copy error',
|
|
398
|
+
'runTrace.copyResult': 'Copy result',
|
|
399
|
+
'runTrace.doing': '%1…',
|
|
400
|
+
'runTrace.error': 'Error',
|
|
401
|
+
'runTrace.failedAfter': 'Failed after %1',
|
|
402
|
+
'runTrace.handoff': '%1 handed over to %2',
|
|
403
|
+
'runTrace.label': 'Steps',
|
|
404
|
+
'runTrace.result': 'Result',
|
|
405
|
+
'runTrace.retried': 'Retried',
|
|
406
|
+
'runTrace.retries': '%1 retries',
|
|
407
|
+
'runTrace.retry': '1 retry',
|
|
408
|
+
'runTrace.showAll': 'Show all',
|
|
409
|
+
'runTrace.source': '1 source',
|
|
410
|
+
'runTrace.sources': '%1 sources',
|
|
411
|
+
'runTrace.step': '1 step',
|
|
412
|
+
'runTrace.steps': '%1 steps',
|
|
413
|
+
'runTrace.stoppedAfter': 'Stopped after %1',
|
|
414
|
+
'runTrace.worked': 'Worked for %1',
|
|
415
|
+
'runTrace.working': 'Working…',
|
|
416
|
+
'runTrace.blockedAfter': 'Blocked after %1',
|
|
417
|
+
'runTrace.token': '1 token',
|
|
418
|
+
'runTrace.tokens': '%1 tokens',
|
|
419
|
+
|
|
280
420
|
'search.clear': 'Clear search',
|
|
281
421
|
'search.label': 'Search',
|
|
282
422
|
'search.submit': 'Submit search',
|
|
@@ -290,6 +430,9 @@ export const defaultMessages = Object.freeze({
|
|
|
290
430
|
|
|
291
431
|
'sheet.resize': 'Resize sheet',
|
|
292
432
|
|
|
433
|
+
'sourceList.label': 'Sources',
|
|
434
|
+
'sourceList.source': 'Source',
|
|
435
|
+
|
|
293
436
|
'statTile.down': 'down %1',
|
|
294
437
|
'statTile.loading': 'Loading',
|
|
295
438
|
'statTile.unchanged': 'no change',
|
package/src/index.js
CHANGED
|
@@ -124,6 +124,14 @@ export {
|
|
|
124
124
|
export {
|
|
125
125
|
ActivityList, groupActivityItems, normalizeActivityItems
|
|
126
126
|
} from './components/activity-list/activity-list.js';
|
|
127
|
+
export { BlockView, renderBlocks } from './components/block-view/block-view.js';
|
|
128
|
+
export { blocksToMarkdown, blocksToText } from './internal/agent-model.js';
|
|
129
|
+
export { RunStatus } from './components/run-status/run-status.js';
|
|
130
|
+
export { Composer } from './components/composer/composer.js';
|
|
131
|
+
export { ApprovalCard } from './components/approval-card/approval-card.js';
|
|
132
|
+
export { RunTrace } from './components/run-trace/run-trace.js';
|
|
133
|
+
export { SourceList } from './components/source-list/source-list.js';
|
|
134
|
+
export { AgentThread } from './components/agent-thread/agent-thread.js';
|
|
127
135
|
export { AccountMenu } from './components/account-menu/account-menu.js';
|
|
128
136
|
export { WorkspaceSwitcher } from './components/workspace-switcher/workspace-switcher.js';
|
|
129
137
|
export { normalizeAppItems } from './internal/app-rail.js';
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* The agent data model every agent component reads: a conversation thread as a list of plain JSON
|
|
4
|
+
* items, the blocks an answer is made of, the steps a run took, the sources it cites, and the one
|
|
5
|
+
* mapping from a run or agent state to the glyph, tone, and word that show it.
|
|
6
|
+
*
|
|
7
|
+
* The model holds no functions and no DOM nodes, so an agent can produce it directly and an
|
|
8
|
+
* application can store, send, and replay it. Behaviour comes in through component options and
|
|
9
|
+
* events, never through the model.
|
|
10
|
+
*/
|
|
11
|
+
import { formatNumber } from '../core/format.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Where a run, or one step of it, stands.
|
|
15
|
+
* @typedef {'queued'|'running'|'waiting'|'paused'|'blocked'|'done'|'failed'|'stopped'|'skipped'} RunState
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What an agent is doing, shown beside its avatar.
|
|
20
|
+
* @typedef {'idle'|'thinking'|'working'|'needs-you'|'blocked'|'offline'} AgentActivity
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A row of figures: what it is, a muted detail, and the value. The tuple form is shorthand for the
|
|
25
|
+
* object form; `call` names the trace step the value came from.
|
|
26
|
+
* @typedef {[string, string, string]|{label: string, detail?: string, value: string, call?: string}} FigureRow
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* One block of an answer. Text runs use the inline grammar of `parseInline()`; nothing in a block
|
|
31
|
+
* is ever read as HTML.
|
|
32
|
+
* @typedef {{type: 'p', text: string}
|
|
33
|
+
* | {type: 'quote', text: string}
|
|
34
|
+
* | {type: 'heading', level?: 2|3, text: string}
|
|
35
|
+
* | {type: 'list', ordered?: boolean, items: string[]}
|
|
36
|
+
* | {type: 'code', language?: string, code: string, lines?: boolean}
|
|
37
|
+
* | {type: 'table', columns: string[], rows: string[][], align?: Array<'start'|'center'|'end'|null>}
|
|
38
|
+
* | {type: 'figures', rows: FigureRow[]}
|
|
39
|
+
* | {type: 'callout', tone?: 'info'|'success'|'warning'|'danger', title?: string, text: string}
|
|
40
|
+
* | {type: 'artifact', id: string, title: string, kind?: 'document'|'code', versions?: number}} Block
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A source an answer draws on. `web` sources may carry an `href`; a `record` names an application
|
|
45
|
+
* record; a `call` names the trace step it came from.
|
|
46
|
+
* @typedef {Object} Source
|
|
47
|
+
* @property {string} id Stable identity.
|
|
48
|
+
* @property {string} title Full title, shown in the source card.
|
|
49
|
+
* @property {'web'|'file'|'record'|'call'} [kind='web'] What the source is.
|
|
50
|
+
* @property {string} [site] Short name shown on the chip: a host, a file name, a record type.
|
|
51
|
+
* @property {string} [snippet] The passage the answer used.
|
|
52
|
+
* @property {string} [href] Address of a `web` source.
|
|
53
|
+
* @property {{entity: string, id: string}} [ref] The application record a `record` source names.
|
|
54
|
+
* @property {string} [call] The trace step the source came from.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A link from an item or a step to something of the application's own — a task, a file, a
|
|
59
|
+
* record. The application resolves it; the components only draw the label and report the click.
|
|
60
|
+
* @typedef {Object} ItemRef
|
|
61
|
+
* @property {string} id Stable identity, handed back on activation.
|
|
62
|
+
* @property {string} label What the link says.
|
|
63
|
+
* @property {string} [icon] Glyph name.
|
|
64
|
+
* @property {string} [entity] What kind of thing it is, for the application: `task`, `file`, …
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* One thing an agent did during a run.
|
|
69
|
+
* @typedef {Object} TraceStep
|
|
70
|
+
* @property {string} id Stable identity.
|
|
71
|
+
* @property {'search'|'read'|'query'|'write'|'run'|'call'|'handoff'|'think'|'task'|'ask'|'decision'} [kind='call']
|
|
72
|
+
* What kind of step it is; sets the glyph and how the summary counts it. `task` is a planned step,
|
|
73
|
+
* `ask` a request a person made, `decision` a person's answer; with `think` and `handoff` they are
|
|
74
|
+
* not tool calls.
|
|
75
|
+
* @property {string} label What was done, in the past tense: "Read the dunning policy".
|
|
76
|
+
* @property {RunState} [status='done'] Where the step stands.
|
|
77
|
+
* @property {string} [doing] The present-tense line shown while it runs: "Reading the policy".
|
|
78
|
+
* @property {string} [detail] A muted detail.
|
|
79
|
+
* @property {number} [ms] How long it took.
|
|
80
|
+
* @property {string} [count] A short result count: "42 rows".
|
|
81
|
+
* @property {number} [sources] How many sources a search looked at.
|
|
82
|
+
* @property {string} [tool] The tool's name, shown in mono.
|
|
83
|
+
* @property {string} [args] The call's arguments, JSON or text.
|
|
84
|
+
* @property {string} [result] What the call returned.
|
|
85
|
+
* @property {string} [error] Why the call failed.
|
|
86
|
+
* @property {string} [retryOf] The id of the step this one repeats.
|
|
87
|
+
* @property {string} [actor] Author key of whoever took the step.
|
|
88
|
+
* @property {string} [to] Author key a `handoff` hands over to.
|
|
89
|
+
* @property {string} [at] Local ISO date-time it started; a running step's clock counts from it.
|
|
90
|
+
* @property {number} [tokens] Tokens the step used.
|
|
91
|
+
* @property {ItemRef[]} [refs] Links to what the step touched — a file it wrote, a record it read.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Who wrote an item or took a step.
|
|
96
|
+
* @typedef {Object} Author
|
|
97
|
+
* @property {string} name Display name.
|
|
98
|
+
* @property {'person'|'agent'|'model'} [kind='agent'] What the author is.
|
|
99
|
+
* @property {string} [initials] Avatar initials; derived from the name when absent.
|
|
100
|
+
* @property {string} [tone] Categorical avatar tone.
|
|
101
|
+
* @property {AgentActivity|null} [activity] What an agent is doing now.
|
|
102
|
+
* @property {string} [via] The model an agent answers through, shown in the byline.
|
|
103
|
+
* @property {string} [icon] A glyph drawn in a tinted tile instead of initials — a model's mark.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/** @typedef {{name: string, size?: number, type?: string}} Attachment */
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One version of a regenerated answer.
|
|
110
|
+
* @typedef {{blocks: Block[], sources?: Source[], steps?: TraceStep[], at?: string, model?: string,
|
|
111
|
+
* stopped?: boolean, rating?: 'up'|'down'|null}} AnswerVersion
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* One item in a conversation thread.
|
|
116
|
+
* `refs` on any item draws links to the application's own things after its content; `mentions` on a
|
|
117
|
+
* person's message marks each `@name` in the text; an answer's `steps` show the work it did inline,
|
|
118
|
+
* above its text, and change with its version.
|
|
119
|
+
* @typedef {{id: string, type: 'user', at?: string, author?: string, text: string, files?: Attachment[],
|
|
120
|
+
* mentions?: Array<string|{name: string, tone?: string}>, refs?: ItemRef[]}
|
|
121
|
+
* | {id: string, type: 'text', at?: string, author?: string, text: string, refs?: ItemRef[]}
|
|
122
|
+
* | {id: string, type: 'answer', at?: string, author?: string, blocks: Block[], sources?: Source[],
|
|
123
|
+
* steps?: TraceStep[], stepsOpen?: boolean, streaming?: boolean, stopped?: boolean, versions?: AnswerVersion[],
|
|
124
|
+
* version?: number, rating?: 'up'|'down'|null, refs?: ItemRef[]}
|
|
125
|
+
* | {id: string, type: 'trace', at?: string, author?: string, steps: TraceStep[], open?: boolean,
|
|
126
|
+
* title?: string, refs?: ItemRef[]}
|
|
127
|
+
* | {id: string, type: 'approval', at?: string, author?: string, title: string, description?: string,
|
|
128
|
+
* icon?: string|null, tone?: string,
|
|
129
|
+
* status?: 'pending'|'approved'|'rejected'|'expired', details?: Block[],
|
|
130
|
+
* preview?: {label: string, blocks: Block[]}, fields?: Record<string, Record<string, unknown>>,
|
|
131
|
+
* values?: Record<string, unknown>, confirmText?: string|null, reason?: 'optional'|'required'|'none',
|
|
132
|
+
* edited?: boolean, editedKeys?: string[]|null, rejectReason?: string|null, answeredBy?: string,
|
|
133
|
+
* answeredAt?: string}
|
|
134
|
+
* | {id: string, type: 'notice', at?: string, author?: string, text: string,
|
|
135
|
+
* tone?: 'neutral'|'info'|'success'|'warning'|'danger', action?: {id: string, label: string}}
|
|
136
|
+
* | {id: string, type: string, at?: string, author?: string, [key: string]: unknown}} ThreadItem
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/** @typedef {'neutral'|'info'|'success'|'warning'|'danger'|'muted'} StateTone */
|
|
140
|
+
/** @typedef {{status: string, tone: StateTone, key: string}} StateEntry */
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* How each run or step state is drawn: the `statusIcon()` status, its tone, and the message key of
|
|
144
|
+
* the word beside it. A state is always a glyph and a word; its colour never stands alone.
|
|
145
|
+
* @type {Readonly<Record<RunState, StateEntry>>}
|
|
146
|
+
*/
|
|
147
|
+
export const STATUS = Object.freeze({
|
|
148
|
+
queued: { status: 'todo', tone: 'neutral', key: 'agent.status.queued' },
|
|
149
|
+
running: { status: 'in-progress', tone: 'info', key: 'agent.status.running' },
|
|
150
|
+
waiting: { status: 'waiting', tone: 'warning', key: 'agent.status.waiting' },
|
|
151
|
+
paused: { status: 'in-progress', tone: 'muted', key: 'agent.status.paused' },
|
|
152
|
+
blocked: { status: 'waiting', tone: 'danger', key: 'agent.status.blocked' },
|
|
153
|
+
done: { status: 'done', tone: 'success', key: 'agent.status.done' },
|
|
154
|
+
failed: { status: 'canceled', tone: 'danger', key: 'agent.status.failed' },
|
|
155
|
+
stopped: { status: 'canceled', tone: 'muted', key: 'agent.status.stopped' },
|
|
156
|
+
skipped: { status: 'canceled', tone: 'muted', key: 'agent.status.skipped' }
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* How each agent activity is drawn beside an avatar: the tone of its dot and the message key of
|
|
161
|
+
* its word.
|
|
162
|
+
* @type {Readonly<Record<AgentActivity, {tone: StateTone, key: string}>>}
|
|
163
|
+
*/
|
|
164
|
+
export const ACTIVITY = Object.freeze({
|
|
165
|
+
'needs-you': { tone: 'warning', key: 'agent.activity.needsYou' },
|
|
166
|
+
blocked: { tone: 'danger', key: 'agent.activity.blocked' },
|
|
167
|
+
working: { tone: 'success', key: 'agent.activity.working' },
|
|
168
|
+
thinking: { tone: 'info', key: 'agent.activity.thinking' },
|
|
169
|
+
idle: { tone: 'neutral', key: 'agent.activity.idle' },
|
|
170
|
+
offline: { tone: 'muted', key: 'agent.activity.offline' }
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The English words for `STATUS` and `ACTIVITY`, for a component's `msg` defaults.
|
|
175
|
+
* @type {Readonly<Record<string, string>>}
|
|
176
|
+
*/
|
|
177
|
+
export const AGENT_MESSAGES = Object.freeze({
|
|
178
|
+
'agent.status.queued': 'Not started',
|
|
179
|
+
'agent.status.running': 'Running',
|
|
180
|
+
'agent.status.waiting': 'Waiting for you',
|
|
181
|
+
'agent.status.paused': 'Paused',
|
|
182
|
+
'agent.status.blocked': 'Blocked',
|
|
183
|
+
'agent.status.done': 'Done',
|
|
184
|
+
'agent.status.failed': 'Failed',
|
|
185
|
+
'agent.status.stopped': 'Stopped',
|
|
186
|
+
'agent.status.skipped': 'Skipped',
|
|
187
|
+
'agent.activity.needsYou': 'Needs you',
|
|
188
|
+
'agent.activity.blocked': 'Blocked',
|
|
189
|
+
'agent.activity.working': 'Working',
|
|
190
|
+
'agent.activity.thinking': 'Thinking',
|
|
191
|
+
'agent.activity.idle': 'Idle',
|
|
192
|
+
'agent.activity.offline': 'Offline'
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Reads a state, falling back to `done` for anything the model does not know.
|
|
197
|
+
* @param {unknown} state
|
|
198
|
+
* @returns {RunState}
|
|
199
|
+
*/
|
|
200
|
+
export function normalizeRunState(state) {
|
|
201
|
+
return typeof state === 'string' && Object.hasOwn(STATUS, state) ? /** @type {RunState} */ (state) : 'done';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Reads an activity, or null for none or anything unknown.
|
|
206
|
+
* @param {unknown} activity
|
|
207
|
+
* @returns {AgentActivity|null}
|
|
208
|
+
*/
|
|
209
|
+
export function normalizeActivity(activity) {
|
|
210
|
+
return typeof activity === 'string' && Object.hasOwn(ACTIVITY, activity) ? /** @type {AgentActivity} */ (activity) : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* ------------------------------------------------------------------ inline grammar -- */
|
|
214
|
+
|
|
215
|
+
/** @typedef {{kind: 'text'|'strong'|'code', text: string}|{kind: 'cite', text: string, n: number}} InlineSegment */
|
|
216
|
+
|
|
217
|
+
/** Characters a backslash makes literal. */
|
|
218
|
+
const ESCAPABLE = '*`[\\';
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Splits a run of model text into plain text, `**bold**`, `` `code` ``, and `[n]` citation
|
|
222
|
+
* segments. That is the whole grammar: there are no links, no HTML, and no nesting. A backslash
|
|
223
|
+
* makes the next `*`, `` ` ``, `[`, or backslash literal; a marker that is never closed stays
|
|
224
|
+
* literal text, which is also what a half-streamed marker looks like until its close arrives.
|
|
225
|
+
* Code spans are verbatim: escapes inside them are not processed.
|
|
226
|
+
* @param {unknown} text
|
|
227
|
+
* @returns {InlineSegment[]}
|
|
228
|
+
*/
|
|
229
|
+
export function parseInline(text) {
|
|
230
|
+
const source = text == null ? '' : String(text);
|
|
231
|
+
/** @type {InlineSegment[]} */
|
|
232
|
+
const out = [];
|
|
233
|
+
let buffer = '';
|
|
234
|
+
const flush = () => {
|
|
235
|
+
if (!buffer) return;
|
|
236
|
+
const last = out.at(-1);
|
|
237
|
+
if (last?.kind === 'text') last.text += buffer;
|
|
238
|
+
else out.push({ kind: 'text', text: buffer });
|
|
239
|
+
buffer = '';
|
|
240
|
+
};
|
|
241
|
+
let index = 0;
|
|
242
|
+
while (index < source.length) {
|
|
243
|
+
const char = source[index];
|
|
244
|
+
if (char === '\\' && index + 1 < source.length && ESCAPABLE.includes(source[index + 1])) {
|
|
245
|
+
buffer += source[index + 1];
|
|
246
|
+
index += 2;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (char === '*' && source[index + 1] === '*') {
|
|
250
|
+
const close = findStrongClose(source, index + 2);
|
|
251
|
+
if (close > index + 2) {
|
|
252
|
+
flush();
|
|
253
|
+
out.push({ kind: 'strong', text: unescapeInline(source.slice(index + 2, close)) });
|
|
254
|
+
index = close + 2;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (char === '`') {
|
|
259
|
+
const close = source.indexOf('`', index + 1);
|
|
260
|
+
if (close > index + 1) {
|
|
261
|
+
flush();
|
|
262
|
+
out.push({ kind: 'code', text: source.slice(index + 1, close) });
|
|
263
|
+
index = close + 1;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (char === '[') {
|
|
268
|
+
const match = /^\[(\d{1,3})\]/.exec(source.slice(index, index + 5));
|
|
269
|
+
if (match && Number(match[1]) > 0) {
|
|
270
|
+
flush();
|
|
271
|
+
out.push({ kind: 'cite', text: match[0], n: Number(match[1]) });
|
|
272
|
+
index += match[0].length;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
buffer += char;
|
|
277
|
+
index += 1;
|
|
278
|
+
}
|
|
279
|
+
flush();
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Finds the `**` that closes a bold run opened just before `from`, skipping escaped asterisks.
|
|
285
|
+
* @param {string} source
|
|
286
|
+
* @param {number} from
|
|
287
|
+
* @returns {number} Index of the closing marker, or -1.
|
|
288
|
+
*/
|
|
289
|
+
function findStrongClose(source, from) {
|
|
290
|
+
for (let index = from; index < source.length - 1; index += 1) {
|
|
291
|
+
if (source[index] === '\\') {
|
|
292
|
+
index += 1;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (source[index] === '*' && source[index + 1] === '*') return index;
|
|
296
|
+
}
|
|
297
|
+
return -1;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** @param {string} text @returns {string} The text with its backslash escapes resolved. */
|
|
301
|
+
function unescapeInline(text) {
|
|
302
|
+
return text.replace(/\\([*`[\\])/g, '$1');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The visible text of a run of model text: markers dropped, citations kept as `[n]`.
|
|
307
|
+
* @param {unknown} text
|
|
308
|
+
* @returns {string}
|
|
309
|
+
*/
|
|
310
|
+
export function inlineText(text) {
|
|
311
|
+
return parseInline(text).map((segment) => segment.text).join('');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* ------------------------------------------------------------------ figures -- */
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Reads a figures row in either form.
|
|
318
|
+
* @param {FigureRow} row
|
|
319
|
+
* @returns {{label: string, detail: string, value: string, call: string|null}}
|
|
320
|
+
*/
|
|
321
|
+
export function figureRow(row) {
|
|
322
|
+
if (Array.isArray(row)) return { label: String(row[0] ?? ''), detail: String(row[1] ?? ''), value: String(row[2] ?? ''), call: null };
|
|
323
|
+
return {
|
|
324
|
+
label: String(row?.label ?? ''),
|
|
325
|
+
detail: String(row?.detail ?? ''),
|
|
326
|
+
value: String(row?.value ?? ''),
|
|
327
|
+
call: typeof row?.call === 'string' && row.call ? row.call : null
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/* ------------------------------------------------------------------ export -- */
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* An answer as plain text, for search and screen-reader summaries: markers dropped, one blank line
|
|
335
|
+
* between blocks.
|
|
336
|
+
* @param {Block[]} blocks
|
|
337
|
+
* @returns {string}
|
|
338
|
+
*/
|
|
339
|
+
export function blocksToText(blocks) {
|
|
340
|
+
return (Array.isArray(blocks) ? blocks : []).map((block) => {
|
|
341
|
+
switch (block?.type) {
|
|
342
|
+
case 'list': return block.items.map((item) => inlineText(item)).join('\n');
|
|
343
|
+
case 'code': return block.code;
|
|
344
|
+
case 'table': return [block.columns, ...block.rows].map((row) => row.map((cell) => inlineText(cell)).join('\t')).join('\n');
|
|
345
|
+
case 'figures': return block.rows.map((row) => {
|
|
346
|
+
const { label, detail, value } = figureRow(row);
|
|
347
|
+
return [label, detail, value].filter(Boolean).join('\t');
|
|
348
|
+
}).join('\n');
|
|
349
|
+
case 'callout': return [block.title, inlineText(block.text)].filter(Boolean).join('\n');
|
|
350
|
+
case 'artifact': return block.title;
|
|
351
|
+
default: return inlineText(/** @type {{text?: string}} */ (block)?.text ?? '');
|
|
352
|
+
}
|
|
353
|
+
}).filter(Boolean).join('\n\n');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** @param {string} cell @returns {string} A table cell safe inside a Markdown pipe row. */
|
|
357
|
+
function markdownCell(cell) {
|
|
358
|
+
return String(cell ?? '').replaceAll('|', '\\|').replaceAll('\n', ' ');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* An answer as Markdown, for copying and export. Inline markers are already Markdown and pass
|
|
363
|
+
* through as written.
|
|
364
|
+
* @param {Block[]} blocks
|
|
365
|
+
* @returns {string}
|
|
366
|
+
*/
|
|
367
|
+
export function blocksToMarkdown(blocks) {
|
|
368
|
+
return (Array.isArray(blocks) ? blocks : []).map((block) => {
|
|
369
|
+
switch (block?.type) {
|
|
370
|
+
case 'heading': return `${'#'.repeat(block.level === 3 ? 3 : 2)} ${block.text}`;
|
|
371
|
+
case 'quote': return block.text.split('\n').map((line) => `> ${line}`).join('\n');
|
|
372
|
+
case 'list': return block.items.map((item, index) => `${block.ordered ? `${index + 1}.` : '-'} ${item}`).join('\n');
|
|
373
|
+
case 'code': return `\`\`\`${block.language ?? ''}\n${block.code}\n\`\`\``;
|
|
374
|
+
case 'table': {
|
|
375
|
+
const rows = [block.columns, block.columns.map(() => '---'), ...block.rows];
|
|
376
|
+
return rows.map((row) => `| ${row.map(markdownCell).join(' | ')} |`).join('\n');
|
|
377
|
+
}
|
|
378
|
+
case 'figures': return block.rows.map((row) => {
|
|
379
|
+
const { label, detail, value } = figureRow(row);
|
|
380
|
+
return `- ${label}${detail ? ` (${detail})` : ''}: **${value}**`;
|
|
381
|
+
}).join('\n');
|
|
382
|
+
case 'callout': return `> ${block.title ? `**${block.title}** ` : ''}${block.text}`;
|
|
383
|
+
case 'artifact': return `**${block.title}**`;
|
|
384
|
+
default: return /** @type {{text?: string}} */ (block)?.text ?? '';
|
|
385
|
+
}
|
|
386
|
+
}).filter(Boolean).join('\n\n');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/* ------------------------------------------------------------------ runs -- */
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @typedef {Object} TraceSummary
|
|
393
|
+
* @property {number} steps Steps that are not retries.
|
|
394
|
+
* @property {number} calls Tool calls made, retries included.
|
|
395
|
+
* @property {number} retries Steps that repeat another.
|
|
396
|
+
* @property {number} failed Steps that failed and were not retried successfully.
|
|
397
|
+
* @property {number} sources Sources looked at, across all searches.
|
|
398
|
+
* @property {number} ms Time spent on finished steps.
|
|
399
|
+
* @property {TraceStep|null} running The step running now, if any.
|
|
400
|
+
* @property {TraceStep|null} stopped The step the run was stopped at, if any.
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
/** Step kinds that are not tool calls. */
|
|
404
|
+
const NOT_CALLS = new Set(['think', 'handoff', 'task', 'ask', 'decision']);
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* What a run's steps add up to, for the one-line summary its trace folds into.
|
|
408
|
+
* @param {TraceStep[]} steps
|
|
409
|
+
* @returns {TraceSummary}
|
|
410
|
+
*/
|
|
411
|
+
export function traceSummary(steps) {
|
|
412
|
+
const list = Array.isArray(steps) ? steps : [];
|
|
413
|
+
const retried = new Set(list.map((step) => step.retryOf).filter(Boolean));
|
|
414
|
+
let calls = 0;
|
|
415
|
+
let retries = 0;
|
|
416
|
+
let failed = 0;
|
|
417
|
+
let sources = 0;
|
|
418
|
+
let ms = 0;
|
|
419
|
+
/** @type {TraceStep|null} */
|
|
420
|
+
let running = null;
|
|
421
|
+
/** @type {TraceStep|null} */
|
|
422
|
+
let stopped = null;
|
|
423
|
+
for (const step of list) {
|
|
424
|
+
const status = normalizeRunState(step.status ?? 'done');
|
|
425
|
+
if (!NOT_CALLS.has(step.kind ?? 'call')) calls += 1;
|
|
426
|
+
if (step.retryOf) retries += 1;
|
|
427
|
+
if (status === 'failed' && !retried.has(step.id)) failed += 1;
|
|
428
|
+
if (typeof step.sources === 'number' && Number.isFinite(step.sources)) sources += step.sources;
|
|
429
|
+
if (status === 'running' && !running) running = step;
|
|
430
|
+
if (status === 'stopped' && !stopped) stopped = step;
|
|
431
|
+
if (status !== 'running' && typeof step.ms === 'number' && Number.isFinite(step.ms)) ms += step.ms;
|
|
432
|
+
}
|
|
433
|
+
return { steps: list.length - retries, calls, retries, failed, sources, ms, running, stopped };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* How long something took, the way a person says it: "0.8 s" below ten seconds, then "12 s",
|
|
438
|
+
* "1 min 42 s", "1 h 5 min".
|
|
439
|
+
* @param {number} ms
|
|
440
|
+
* @param {{locale?: string}} [options]
|
|
441
|
+
* @returns {string}
|
|
442
|
+
*/
|
|
443
|
+
export function formatDuration(ms, options = {}) {
|
|
444
|
+
const value = Number(ms);
|
|
445
|
+
if (!Number.isFinite(value) || value < 0) return '';
|
|
446
|
+
if (value < 10_000) return `${formatNumber(value / 1000, { decimals: 1, locale: options.locale })} s`;
|
|
447
|
+
return formatElapsed(value);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* A running clock in whole units: "2 s", "41 s", "1 min 42 s", "1 h 5 min".
|
|
452
|
+
* @param {number} ms
|
|
453
|
+
* @returns {string}
|
|
454
|
+
*/
|
|
455
|
+
export function formatElapsed(ms) {
|
|
456
|
+
const value = Number(ms);
|
|
457
|
+
if (!Number.isFinite(value) || value < 0) return '';
|
|
458
|
+
const seconds = Math.floor(value / 1000);
|
|
459
|
+
if (seconds < 60) return `${seconds} s`;
|
|
460
|
+
const minutes = Math.floor(seconds / 60);
|
|
461
|
+
if (minutes < 60) return `${minutes} min ${seconds % 60} s`;
|
|
462
|
+
return `${Math.floor(minutes / 60)} h ${minutes % 60} min`;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* What a run cost, from its token counts and per-token prices.
|
|
467
|
+
* @param {[number, number]|null|undefined} tokens Input and output tokens.
|
|
468
|
+
* @param {{in: number, out: number}} price Price per input and per output token.
|
|
469
|
+
* @returns {number}
|
|
470
|
+
*/
|
|
471
|
+
export function runCost(tokens, price) {
|
|
472
|
+
if (!Array.isArray(tokens) || !price) return 0;
|
|
473
|
+
const input = Number(tokens[0]) || 0;
|
|
474
|
+
const output = Number(tokens[1]) || 0;
|
|
475
|
+
return input * (Number(price.in) || 0) + output * (Number(price.out) || 0);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Initials for an avatar from a name: "Finance agent" → "FA".
|
|
480
|
+
* @param {string} name
|
|
481
|
+
* @returns {string}
|
|
482
|
+
*/
|
|
483
|
+
export function initialsOf(name) {
|
|
484
|
+
const words = String(name ?? '').trim().split(/\s+/).filter(Boolean);
|
|
485
|
+
if (words.length === 0) return '?';
|
|
486
|
+
const letters = words.length === 1 ? [...words[0]].slice(0, 2) : [[...words[0]][0], [...words.at(-1) ?? ''][0]];
|
|
487
|
+
return letters.join('').toUpperCase();
|
|
488
|
+
}
|