@2lab.ai/ui 0.0.0-stage → 0.1.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 (52) hide show
  1. package/README.md +54 -2
  2. package/dist/agent-inbox.js +1061 -0
  3. package/dist/agent-inbox.js.map +1 -0
  4. package/dist/agent-queue.js +1610 -0
  5. package/dist/agent-queue.js.map +1 -0
  6. package/dist/agent-run.js +859 -0
  7. package/dist/agent-run.js.map +1 -0
  8. package/dist/ai-answer.js +687 -0
  9. package/dist/ai-answer.js.map +1 -0
  10. package/dist/components/agent-inbox/agent-inbox.d.ts +158 -0
  11. package/dist/components/agent-inbox/index.d.ts +2 -0
  12. package/dist/components/agent-inbox/styles.d.ts +6 -0
  13. package/dist/components/agent-queue/agent-queue.d.ts +41 -0
  14. package/dist/components/agent-queue/index.d.ts +6 -0
  15. package/dist/components/agent-queue/logic.d.ts +261 -0
  16. package/dist/components/agent-queue/strings.d.ts +473 -0
  17. package/dist/components/agent-queue/styles.d.ts +8 -0
  18. package/dist/components/agent-run/agent-run.d.ts +273 -0
  19. package/dist/components/agent-run/index.d.ts +2 -0
  20. package/dist/components/agent-run/styles.d.ts +6 -0
  21. package/dist/components/ai-answer/ai-answer.d.ts +92 -0
  22. package/dist/components/ai-answer/index.d.ts +2 -0
  23. package/dist/components/ai-answer/styles.d.ts +2 -0
  24. package/dist/components/context-window/context-window.d.ts +156 -0
  25. package/dist/components/context-window/index.d.ts +2 -0
  26. package/dist/components/context-window/styles.d.ts +2 -0
  27. package/dist/components/memory-panel/index.d.ts +2 -0
  28. package/dist/components/memory-panel/memory-panel.d.ts +101 -0
  29. package/dist/components/memory-panel/styles.d.ts +2 -0
  30. package/dist/components/model-picker/index.d.ts +2 -0
  31. package/dist/components/model-picker/model-picker.d.ts +136 -0
  32. package/dist/components/model-picker/morph.d.ts +9 -0
  33. package/dist/components/model-picker/styles.d.ts +6 -0
  34. package/dist/context-window.js +384 -0
  35. package/dist/context-window.js.map +1 -0
  36. package/dist/core/element.d.ts +39 -0
  37. package/dist/core/format.d.ts +14 -0
  38. package/dist/core/html.d.ts +10 -0
  39. package/dist/core/tokens.d.ts +14 -0
  40. package/dist/format-BBGWXPzk.js +51 -0
  41. package/dist/format-BBGWXPzk.js.map +1 -0
  42. package/dist/html-DZWnrdcg.js +167 -0
  43. package/dist/html-DZWnrdcg.js.map +1 -0
  44. package/dist/index.d.ts +15 -0
  45. package/dist/index.js +116 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/memory-panel.js +1255 -0
  48. package/dist/memory-panel.js.map +1 -0
  49. package/dist/model-picker.js +858 -0
  50. package/dist/model-picker.js.map +1 -0
  51. package/dist/tokens.css +4 -0
  52. package/package.json +75 -4
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Pure data helpers for `<ui-agent-queue>` — ported from the soma-work dashboard (`aq*`, `cap*`, `cron*` in
3
+ * dash-main.ts, .prd/affectui/re-agent-queue.md D3·D8–D10·D13·D16–D19). No DOM, no clock: every function takes `now`.
4
+ * Every time here is epoch **milliseconds**; seconds are converted once, at the boundary (`normalize`, `toMs`).
5
+ */
6
+ /** Unit of every epoch field in the data (`now`, `fetchedAt`, `measuredAt`, `returnAt`, `refills[].at`, `nextRunAt`, `runs[].at`). */
7
+ export type TimeUnit = 'ms' | 's';
8
+ /** Pool state of a provider. `low` = the primary measure is under {@link LOW_PCT}% of the total. */
9
+ export type AqPoolState = 'ok' | 'low' | 'empty' | 'unknown';
10
+ /**
11
+ * One account (a worker).
12
+ * - `available` — usable now (its dot says which window binds first).
13
+ * - `limited` — counted but blocked by a limit; shows the reason and the time left (`returnAt`).
14
+ * - `paused` — held out of the totals (paused, auth failure …).
15
+ * - `spent` — counted, not blocked, nothing usable now.
16
+ * - `unmeasured` — counted, no 5-hour reading.
17
+ * - `excluded` — not counted (no measurement, unknown tier …).
18
+ */
19
+ export type AqAccountState = 'available' | 'limited' | 'paused' | 'spent' | 'unmeasured' | 'excluded';
20
+ /** Known reason keys (translated). Any other string is shown as given. */
21
+ export type AqReason = 'weekly' | '5h' | 'model' | 'cooldown' | 'paused' | 'auth' | 'held' | 'noMeasure' | 'unknownTier';
22
+ export interface AqAccount {
23
+ /** Stable identity (the open card, the roving stop and focus follow it across updates). */
24
+ id: string;
25
+ name: string;
26
+ state: AqAccountState;
27
+ /** Why it is limited / paused / excluded: a known key (translated) or free text. */
28
+ reason?: AqReason | (string & {});
29
+ /** When every block has lifted (epoch, see `timeUnit`). Limited accounts count down to it. */
30
+ returnAt?: number;
31
+ /** Which window binds a usable account first — colours its dot (5h teal, 7d violet). */
32
+ binding?: '5h' | '7d';
33
+ /** Plan label, e.g. `Max x5`. */
34
+ tier?: string;
35
+ /** The tier is assumed (no configured or reported plan). */
36
+ tierAssumed?: boolean;
37
+ /** This account's own 5-hour remaining, 0..1 (account card only). */
38
+ fiveHour?: number;
39
+ /** This account's own weekly remaining, 0..1 (account card only). */
40
+ weekly?: number;
41
+ /** A passed reset decides a number this account contributes. */
42
+ estimated?: boolean;
43
+ }
44
+ /** A replayed reset: what comes back, and when. Gains are in accounts' worth. */
45
+ export interface AqRefill {
46
+ at: number;
47
+ /** `5h` reset (dot), `7d` weekly reset (diamond), or a block lifting. */
48
+ cause: '5h' | '7d' | 'release';
49
+ /** Gain to the 5-hour measure. */
50
+ fiveHour?: number;
51
+ /** Gain to the weekly measure. */
52
+ weekly?: number;
53
+ /** Account name (titles only). */
54
+ account?: string;
55
+ }
56
+ export interface AqProvider {
57
+ id: string;
58
+ name: string;
59
+ /** Where the numbers come from, e.g. `llmux`. */
60
+ source?: string;
61
+ /** Pool size in accounts' worth (tier-weighted). Nothing is computed without it. */
62
+ total: number;
63
+ /** Usable now (5-hour window), accounts' worth. Omit for providers without a 5-hour window. */
64
+ fiveHour?: number;
65
+ /** Left this week, accounts' worth. */
66
+ weekly?: number;
67
+ /** Pool state. Derived from the primary measure when omitted (see {@link poolState}). */
68
+ state?: AqPoolState;
69
+ /** Accounts in the pool (default `accounts.length`). */
70
+ accountCount?: number;
71
+ /** Accounts counted in the totals (default: accounts not paused / excluded). */
72
+ countedAccounts?: number;
73
+ /** Accounts left out of the totals, by reason (default: derived from `accounts`). */
74
+ excluded?: {
75
+ held?: number;
76
+ unknownTier?: number;
77
+ noMeasure?: number;
78
+ };
79
+ /** Accounts whose numbers are estimated (default: derived). */
80
+ estimated?: number;
81
+ /** Accounts without a 5-hour reading (default: derived). */
82
+ unmeasured5h?: number;
83
+ /** Oldest measurement behind the numbers (epoch) — “measured 4h ago”, flagged past a day. */
84
+ measuredAt?: number;
85
+ /** Replayed resets in time order (next 7 days). */
86
+ refills?: AqRefill[];
87
+ accounts?: AqAccount[];
88
+ }
89
+ /**
90
+ * A run record. `unknown` = a run whose result is not known — counted apart, never as success.
91
+ * `running` / `waiting` = recorded, and its session is busy now (stacked as “in progress”).
92
+ */
93
+ export type AqRunStatus = 'ok' | 'running' | 'waiting' | 'failed' | 'unknown';
94
+ export interface AqRun {
95
+ at: number;
96
+ status: AqRunStatus;
97
+ /** Owning job (only needed in `lane.runs24h`). */
98
+ jobId?: string;
99
+ /** What the run was, e.g. a session headline or `Thread reply (no session)`. */
100
+ label?: string;
101
+ /** Error text of a failed run. */
102
+ error?: string;
103
+ }
104
+ export interface AqJob {
105
+ id: string;
106
+ name: string;
107
+ /** Schedule in words. Derived from `expression` for common shapes when omitted. */
108
+ schedule?: string;
109
+ /** Raw cron expression (shown as the schedule's tooltip). */
110
+ expression?: string;
111
+ /** Next fire (epoch). Jobs without one are left out of the up-next queue. */
112
+ nextRunAt?: number;
113
+ /** Kept run records, any order. */
114
+ runs?: AqRun[];
115
+ /** “Past runs N” (default `runs.length`). */
116
+ pastRuns?: number;
117
+ /** Live state now: a running session, or one waiting for a reply. */
118
+ state?: 'running' | 'waiting' | 'idle';
119
+ /** History is FIFO-capped at this many runs: counts in a window it no longer covers become “≥ n”. */
120
+ historyCap?: number;
121
+ }
122
+ export interface AqLane {
123
+ /** Lane title (default `CRON`). */
124
+ title?: string;
125
+ jobs: AqJob[];
126
+ /** Run records of the last 24 hours for the stats and the chart. Default: every job's `runs`. */
127
+ runs24h?: AqRun[];
128
+ }
129
+ export interface AgentQueueData {
130
+ /** Provider capacity. Omit to hide the section. */
131
+ providers?: AqProvider[];
132
+ /** Muted note beside the capacity title, e.g. `account = one top-plan account's worth · llmux`. */
133
+ capacityNote?: string;
134
+ /** When the capacity was read (epoch) — “updated 12s ago”, ticking. */
135
+ fetchedAt?: number;
136
+ /** The capacity could not be read: shown instead of the cards. */
137
+ capacityError?: string;
138
+ /** The scheduled-job lane. Omit to hide the section. */
139
+ lane?: AqLane;
140
+ /** The clock (epoch). Default `Date.now()`; countdowns tick on from it. */
141
+ now?: number;
142
+ /** Unit of every epoch field. Default `ms`. Capacity servers that speak epoch seconds pass `s`. */
143
+ timeUnit?: TimeUnit;
144
+ }
145
+ export declare const SEC = 1000;
146
+ export declare const HOUR = 3600000;
147
+ export declare const DAY = 86400000;
148
+ export declare const H5: number;
149
+ export declare const D7: number;
150
+ /** Under this % of the total a pool reads `low` (dashboard CAP_LOW_PCT = capacity-view CAPACITY_LOW_PCT). */
151
+ export declare const LOW_PCT = 20;
152
+ /** An epoch in the given unit as milliseconds; `undefined` for anything not finite. */
153
+ export declare function toMs(v: unknown, unit?: TimeUnit): number | undefined;
154
+ /** A copy of the data with every epoch in milliseconds — the one place units are converted. */
155
+ export declare function normalize(d: AgentQueueData): AgentQueueData;
156
+ /** Tool- or user-written text as one plain line for the live region: control chars / whitespace runs → one space, capped. */
157
+ export declare function plain(s: unknown, max?: number): string;
158
+ /** `HH:MM` today, `M/D HH:MM` on another day (viewer's zone). */
159
+ export declare function clockLabel(atMs: number, nowMs: number): string;
160
+ /** `HH:MM` (chart bins). */
161
+ export declare function hm(ms: number): string;
162
+ /** Elapsed span, minutes floored: `<1m`, `11m`, `3h 5m`, `1d 6h` (the dashboard's capCountdown). */
163
+ export declare function spanShort(secs: number): string;
164
+ /** One decimal: `3.5`. */
165
+ export declare function fmt1(x: number): string;
166
+ /** “2.37 / 2.4”, never “2.4 / 2.4 99%”: a value that rounds to the total but is not full keeps two decimals. */
167
+ export declare function fmtCount(v: number, total: number): string;
168
+ /** % from the raw ratio: 100% only when full; `—` without a total. */
169
+ export declare function fmtPct(v: number, total: number): string;
170
+ export type MeasureKey = 'fiveHour' | 'weekly';
171
+ /** The provider has a 5-hour window (two bars) — otherwise the weekly measure is primary. */
172
+ export declare function has5h(p: AqProvider): boolean;
173
+ /** The measure that decides empty / low: 5-hour when present, else weekly. */
174
+ export declare function primaryKey(p: AqProvider): MeasureKey;
175
+ /** Host-supplied enums are checked at the boundary: an unknown value never reaches markup. */
176
+ export declare function accountState(v: unknown): AqAccountState;
177
+ export declare function poolState(p: AqProvider): AqPoolState;
178
+ /** Refills whose time has come are folded into the measures they moved, so nothing past reads as “to come”. */
179
+ export declare function advanceProvider(p: AqProvider, nowMs: number): AqProvider;
180
+ /** The first gain ≥ 0.05 within 7 days that raises this measure, or null. */
181
+ export declare function nextRefill(p: AqProvider, key: MeasureKey, nowMs: number): AqRefill | null;
182
+ /** Sum of the gains to this measure within the span (small gains are summed, never dropped). */
183
+ export declare function gainWithin(p: AqProvider, key: MeasureKey, nowMs: number, span?: number): number;
184
+ /** Accounts that are counted but limited right now. */
185
+ export declare function limitedAccounts(p: AqProvider): AqAccount[];
186
+ /** The earliest return among the limited accounts (epoch ms), or null. */
187
+ export declare function firstReturn(p: AqProvider): number | null;
188
+ /** When an empty pool gets something back: the first return, else the first refill of the primary measure. */
189
+ export declare function emptyReturnAt(p: AqProvider, nowMs: number): number | null;
190
+ /** Accounts counted in the totals (not paused, not excluded). */
191
+ export declare function countedAccounts(p: AqProvider): number;
192
+ /** Exclusions by reason: given, else from the accounts (paused → held; excluded by its reason key). */
193
+ export declare function exclusions(p: AqProvider): {
194
+ held: number;
195
+ unknownTier: number;
196
+ noMeasure: number;
197
+ };
198
+ /** now → 24h takes 55% of the axis (0·1·3·6·12·24h), then days to 7d. Offset in ms → 0..1. */
199
+ export declare function axisPos(offsetMs: number): number;
200
+ export interface TimelineMark {
201
+ /** `h5` = 5-hour reset (dot, label above), `wk` = weekly reset (diamond, label below). */
202
+ c: 'h5' | 'wk';
203
+ x0: number;
204
+ x1: number;
205
+ gain: number;
206
+ n: number;
207
+ names: string[];
208
+ at: number;
209
+ }
210
+ /**
211
+ * The 7-day timeline's marks at width W (px): refills that raise a measure (5h by the 5-hour gain, weekly by the
212
+ * weekly gain); same-type marks closer than a label merge into one with a short span.
213
+ */
214
+ export declare function timelineMarks(p: AqProvider, W: number, nowMs: number, pad?: number): TimelineMark[];
215
+ export type RunKind = 'ok' | 'run' | 'fail' | 'unknown';
216
+ /** ok → ok, running / waiting → in progress, failed → fail, anything else → unknown (never ok). */
217
+ export declare function runKind(status: unknown): RunKind;
218
+ export interface DayRuns {
219
+ from: number;
220
+ runs: Array<{
221
+ at: number;
222
+ kind: 'ok' | 'run' | 'fail';
223
+ }>;
224
+ n: number;
225
+ ok: number;
226
+ fail: number;
227
+ run: number;
228
+ /** Runs with an unknown result: counted apart, never drawn, never success. */
229
+ unknown: number;
230
+ /** Jobs whose capped history starts inside the window: counts are lower bounds from `from`. */
231
+ cut: Array<{
232
+ name: string;
233
+ from: number;
234
+ cap: number;
235
+ }>;
236
+ cutFrom: number;
237
+ }
238
+ /** The last 24 hours of run records: `lane.runs24h` when given, else every job's runs. */
239
+ export declare function dayRuns(lane: AqLane, nowMs: number): DayRuns;
240
+ export interface RunBin {
241
+ at: number;
242
+ ok: number;
243
+ run: number;
244
+ fail: number;
245
+ }
246
+ /** 24 rolling one-hour bins ending now (each labelled by its start). */
247
+ export declare function runBins(day: DayRuns, nowMs: number): RunBin[];
248
+ export declare const NICE: number[];
249
+ /** Chart y max: max(peak, 4) rounded up to a nice value. */
250
+ export declare function niceMax(peak: number): number;
251
+ /** Lane order: waiting for a reply, then running, then the newest run, then the next fire, then the name. */
252
+ export declare function orderJobs(jobs: AqJob[]): AqJob[];
253
+ /** The up-next queue: jobs with a next fire, soonest first. */
254
+ export declare function upNext(jobs: AqJob[]): AqJob[];
255
+ /** A job's runs, newest first. */
256
+ export declare function jobRuns(j: AqJob): AqRun[];
257
+ /**
258
+ * Schedule in words for the common cron shapes; anything else stays the raw expression. Clock times read in
259
+ * the viewer's zone from the next fire (the expression is UTC).
260
+ */
261
+ export declare function scheduleLabel(expr: string | undefined, nextRunAt: number | undefined, lang?: 'en' | 'ko'): string;