basalt-ui 2.13.3 → 2.15.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 +66 -0
- package/MIGRATING.md +42 -12
- package/agent/agents/basalt-design-reviewer.md +83 -0
- package/agent/rules/basalt-batteries.md +1 -2
- package/agent/rules/basalt-charts.md +1 -1
- package/agent/rules/basalt-controls.md +3 -3
- package/agent/rules/basalt-mantine.md +1 -2
- package/agent/rules/basalt-state.md +1 -2
- package/agent/rules/basalt-tokens.md +1 -3
- package/agent/skills/basalt-design/SKILL.md +26 -8
- package/agent/templates/AGENTS-block.md.tpl +7 -0
- package/configs/oxlint-plugin.js +39 -2
- package/configs/oxlint-plugin.test.ts +48 -0
- package/dist/agent/chat/thread-feed-row.d.ts.map +1 -1
- package/dist/agent/chat/thread-feed-row.js +2 -2
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +2 -2
- package/dist/agent/chat/thread-outcome-card.js +2 -2
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +1 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +3 -2
- package/dist/charts/cursor.d.ts +10 -6
- package/dist/charts/cursor.d.ts.map +1 -1
- package/dist/charts/cursor.js +20 -13
- package/dist/charts/legend.d.ts +7 -6
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +3 -3
- package/dist/charts/panel.d.ts +2 -0
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -0
- package/dist/cli/board-freshness.d.ts +25 -0
- package/dist/cli/board-freshness.d.ts.map +1 -0
- package/dist/cli/board-freshness.js +88 -0
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +3 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +9 -3
- package/dist/cli/index.d.ts +15 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +57 -7
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +6 -1
- package/dist/cli/shot/board.d.ts +5 -0
- package/dist/cli/shot/board.d.ts.map +1 -0
- package/dist/cli/shot/board.js +96 -0
- package/dist/cli/shot/capture.d.ts +59 -0
- package/dist/cli/shot/capture.d.ts.map +1 -0
- package/dist/cli/shot/capture.js +473 -0
- package/dist/cli/shot/index.d.ts +45 -0
- package/dist/cli/shot/index.d.ts.map +1 -0
- package/dist/cli/shot/index.js +289 -0
- package/dist/cli/shot/measure.d.ts +28 -0
- package/dist/cli/shot/measure.d.ts.map +1 -0
- package/dist/cli/shot/measure.js +176 -0
- package/dist/cli/shot/playwright.d.ts +101 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -0
- package/dist/cli/shot/playwright.js +60 -0
- package/dist/cli/shot/serve.d.ts +6 -0
- package/dist/cli/shot/serve.d.ts.map +1 -0
- package/dist/cli/shot/serve.js +33 -0
- package/dist/cli/shot/types.d.ts +97 -0
- package/dist/cli/shot/types.d.ts.map +1 -0
- package/dist/cli/shot/types.js +17 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -1
- package/dist/commands/notifications/center.d.ts.map +1 -1
- package/dist/commands/notifications/center.js +2 -11
- package/dist/controls/control-name.d.ts +27 -0
- package/dist/controls/control-name.d.ts.map +1 -0
- package/dist/controls/control-name.js +11 -0
- package/dist/controls/enum-filter.d.ts +3 -6
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -4
- package/dist/controls/filter-base.d.ts +30 -0
- package/dist/controls/filter-base.d.ts.map +1 -0
- package/dist/controls/filter-base.js +0 -0
- package/dist/controls/filter-pill.d.ts +3 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +2 -0
- package/dist/controls/filter-sheet.d.ts +0 -32
- package/dist/controls/filter-sheet.d.ts.map +1 -1
- package/dist/controls/filter-sheet.js +1 -28
- package/dist/controls/glyphs.d.ts +12 -0
- package/dist/controls/glyphs.d.ts.map +1 -1
- package/dist/controls/glyphs.js +23 -2
- package/dist/controls/index.d.ts +2 -1
- package/dist/controls/index.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.d.ts +8 -3
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +27 -10
- package/dist/controls/number-filter.d.ts +3 -12
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +17 -6
- package/dist/controls/panel-row.d.ts +5 -8
- package/dist/controls/panel-row.d.ts.map +1 -1
- package/dist/controls/panel-row.js +3 -0
- package/dist/controls/range-filter.d.ts +14 -14
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +18 -41
- package/dist/controls/search-filter.d.ts +5 -2
- package/dist/controls/search-filter.d.ts.map +1 -1
- package/dist/controls/search-filter.js +74 -40
- package/dist/controls/select-filter.d.ts +2 -15
- package/dist/controls/select-filter.d.ts.map +1 -1
- package/dist/controls/sync-button.d.ts +0 -6
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +6 -36
- package/dist/controls/toggle-filter.d.ts +2 -2
- package/dist/controls/toggle-filter.d.ts.map +1 -1
- package/dist/controls/toggle-filter.js +3 -2
- package/dist/controls/view-tabs.d.ts +3 -4
- package/dist/controls/view-tabs.d.ts.map +1 -1
- package/dist/controls/view-tabs.js +24 -5
- package/dist/format/date.d.ts +43 -10
- package/dist/format/date.d.ts.map +1 -1
- package/dist/format/date.js +109 -18
- package/dist/format/index.d.ts +12 -11
- package/dist/format/index.d.ts.map +1 -1
- package/dist/format/index.js +11 -2
- package/dist/format/measure.d.ts +9 -9
- package/dist/format/measure.d.ts.map +1 -1
- package/dist/format/measure.js +19 -8
- package/dist/format/number.d.ts +35 -27
- package/dist/format/number.d.ts.map +1 -1
- package/dist/format/number.js +41 -20
- package/dist/format/shared.d.ts +38 -7
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +61 -13
- package/dist/provider/index.d.ts +13 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +8 -0
- package/dist/surfaces.d.ts +2 -0
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/llms.txt +35 -14
- package/package.json +1 -1
- package/src/agent/chat/thread-feed-row.tsx +2 -2
- package/src/agent/chat/thread-message.tsx +2 -2
- package/src/agent/chat/thread-outcome-card.tsx +2 -2
- package/src/charts/DualPanel.tsx +1 -0
- package/src/charts/compile.ts +3 -2
- package/src/charts/cursor.ts +44 -27
- package/src/charts/legend.tsx +11 -8
- package/src/charts/panel.tsx +3 -0
- package/src/cli/board-freshness.ts +132 -0
- package/src/cli/doctor.ts +10 -1
- package/src/cli/help.ts +14 -2
- package/src/cli/index.ts +80 -10
- package/src/cli/init.ts +8 -1
- package/src/cli/shot/board.ts +154 -0
- package/src/cli/shot/capture.ts +650 -0
- package/src/cli/shot/index.ts +362 -0
- package/src/cli/shot/measure.ts +225 -0
- package/src/cli/shot/playwright.ts +152 -0
- package/src/cli/shot/serve.ts +35 -0
- package/src/cli/shot/types.ts +91 -0
- package/src/cli/sync.ts +2 -1
- package/src/commands/notifications/center.tsx +2 -14
- package/src/controls/control-name.ts +33 -0
- package/src/controls/enum-filter.tsx +29 -27
- package/src/controls/filter-base.ts +31 -0
- package/src/controls/filter-pill.tsx +4 -0
- package/src/controls/filter-sheet.tsx +0 -56
- package/src/controls/glyphs.tsx +45 -2
- package/src/controls/index.ts +2 -1
- package/src/controls/multi-select-filter.tsx +67 -43
- package/src/controls/number-filter.tsx +47 -47
- package/src/controls/panel-row.tsx +7 -8
- package/src/controls/range-filter.tsx +54 -78
- package/src/controls/search-filter.tsx +107 -54
- package/src/controls/select-filter.tsx +2 -18
- package/src/controls/sync-button.tsx +7 -40
- package/src/controls/toggle-filter.tsx +9 -7
- package/src/controls/view-tabs.tsx +41 -21
- package/src/format/date.ts +189 -36
- package/src/format/index.ts +12 -11
- package/src/format/measure.ts +29 -18
- package/src/format/number.ts +76 -37
- package/src/format/shared.ts +116 -25
- package/src/provider/index.tsx +23 -0
- package/src/surfaces.ts +5 -0
- package/dist/agent/chat/relative-time.d.ts +0 -27
- package/dist/agent/chat/relative-time.d.ts.map +0 -1
- package/dist/agent/chat/relative-time.js +0 -27
- package/src/agent/chat/relative-time.ts +0 -55
package/src/format/shared.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared low-level pieces of `basalt-ui/format
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Shared low-level pieces of `basalt-ui/format`: the {@link NON_FINITE} sentinel, the default
|
|
3
|
+
* locale / time zone ({@link defineFormat}), the memoized `Intl` caches and the number-input
|
|
4
|
+
* guard every formatter in this module reuses. The subpath is the single implementation; the chart
|
|
5
|
+
* layer imports it directly (`docs/V2-SPEC.md` § 9).
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -12,43 +12,134 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export const NON_FINITE = '—'
|
|
14
14
|
|
|
15
|
-
/** Options every number formatter
|
|
15
|
+
/** Options every number/measure formatter accepts. */
|
|
16
16
|
export type LocaleOption = {
|
|
17
|
-
/** BCP-47 tag. Default
|
|
18
|
-
locale?: string
|
|
17
|
+
/** BCP-47 tag. Default: the {@link defineFormat} default, else the runtime's own locale. */
|
|
18
|
+
locale?: string | undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type FormatDefaults = {
|
|
22
|
+
/** BCP-47 tag every formatter uses when a call passes none. */
|
|
23
|
+
locale?: string | undefined
|
|
24
|
+
/** IANA time zone every date formatter uses when a call passes none. */
|
|
25
|
+
timeZone?: string | undefined
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
|
-
* `Intl
|
|
23
|
-
*
|
|
24
|
-
* serialized options because that is exactly what identifies an instance.
|
|
29
|
+
* `Intl` construction is the expensive half of formatting, so instances are memoized per RESOLVED
|
|
30
|
+
* locale (call locale, else the default) — a changed default can never serve a stale instance.
|
|
25
31
|
*/
|
|
26
|
-
const
|
|
32
|
+
const numberCaches = new Map<string, Map<string, Intl.NumberFormat>>()
|
|
33
|
+
const dateCaches = new Map<string, Map<string, Intl.DateTimeFormat>>()
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
let defaults: FormatDefaults = {}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sets the locale / time zone every formatter in `basalt-ui/format` falls back to when a call
|
|
39
|
+
* passes none. Merges: only DEFINED fields are applied, `undefined` leaves the earlier value.
|
|
40
|
+
*
|
|
41
|
+
* The default is ONE module-global per process (formatters are plain functions, not hooks), so it
|
|
42
|
+
* is an app-wide setting, not a per-request one — a server rendering many locales passes `locale`
|
|
43
|
+
* per call instead. `BasaltProvider`'s `locale` / `timeZone` props call this.
|
|
44
|
+
*/
|
|
45
|
+
export function defineFormat(next: FormatDefaults = {}): void {
|
|
46
|
+
const merged: FormatDefaults = {
|
|
47
|
+
locale: next.locale ?? defaults.locale,
|
|
48
|
+
timeZone: next.timeZone ?? defaults.timeZone,
|
|
49
|
+
}
|
|
50
|
+
if (merged.locale === defaults.locale && merged.timeZone === defaults.timeZone) return
|
|
51
|
+
defaults = merged
|
|
52
|
+
numberCaches.clear()
|
|
53
|
+
dateCaches.clear()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Clears the {@link defineFormat} defaults back to the runtime's own locale and zone. */
|
|
57
|
+
export function resetFormatDefaults(): void {
|
|
58
|
+
defaults = {}
|
|
59
|
+
numberCaches.clear()
|
|
60
|
+
dateCaches.clear()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Cache key: the options' own entries, sorted, joined — no serialization of the whole object per
|
|
65
|
+
* call (a chart formats one label per tick per frame). Option values here are primitives.
|
|
66
|
+
*/
|
|
67
|
+
function optionsKey(options: object): string {
|
|
68
|
+
let key = ''
|
|
69
|
+
for (const [name, value] of Object.entries(options).sort(([a], [b]) => (a < b ? -1 : 1))) {
|
|
70
|
+
key += `${name}=${String(value)};`
|
|
71
|
+
}
|
|
72
|
+
return key
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function memoize<T>(
|
|
76
|
+
caches: Map<string, Map<string, T>>,
|
|
29
77
|
locale: string | undefined,
|
|
30
|
-
options:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
78
|
+
options: object,
|
|
79
|
+
create: () => T,
|
|
80
|
+
): T {
|
|
81
|
+
const localeKey = locale ?? ''
|
|
82
|
+
let cache = caches.get(localeKey)
|
|
83
|
+
if (cache === undefined) {
|
|
84
|
+
cache = new Map()
|
|
85
|
+
caches.set(localeKey, cache)
|
|
86
|
+
}
|
|
87
|
+
const key = optionsKey(options)
|
|
88
|
+
const cached = cache.get(key)
|
|
34
89
|
if (cached !== undefined) return cached
|
|
35
|
-
const created =
|
|
36
|
-
|
|
90
|
+
const created = create()
|
|
91
|
+
cache.set(key, created)
|
|
37
92
|
return created
|
|
38
93
|
}
|
|
39
94
|
|
|
40
|
-
|
|
95
|
+
export function numberFormat(
|
|
96
|
+
locale: string | undefined,
|
|
97
|
+
options: Intl.NumberFormatOptions,
|
|
98
|
+
): Intl.NumberFormat {
|
|
99
|
+
const resolved = locale ?? defaults.locale
|
|
100
|
+
return memoize(numberCaches, resolved, options, () => new Intl.NumberFormat(resolved, options))
|
|
101
|
+
}
|
|
41
102
|
|
|
42
103
|
export function dateFormat(
|
|
43
104
|
locale: string | undefined,
|
|
44
105
|
options: Intl.DateTimeFormatOptions,
|
|
45
106
|
): Intl.DateTimeFormat {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
107
|
+
const resolved = locale ?? defaults.locale
|
|
108
|
+
const withZone =
|
|
109
|
+
options.timeZone === undefined && defaults.timeZone !== undefined
|
|
110
|
+
? { ...options, timeZone: defaults.timeZone }
|
|
111
|
+
: options
|
|
112
|
+
return memoize(dateCaches, resolved, withZone, () => new Intl.DateTimeFormat(resolved, withZone))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What every number/measure formatter accepts. */
|
|
116
|
+
export type Numeric = number | null | undefined
|
|
117
|
+
|
|
118
|
+
/** True for a finite number; `null`, `undefined`, `NaN` and `±Infinity` are the inputs every
|
|
119
|
+
* number/measure formatter answers with {@link NON_FINITE}. */
|
|
120
|
+
export function isFiniteNumber(value: Numeric): value is number {
|
|
121
|
+
return typeof value === 'number' && Number.isFinite(value)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Scales `value` down by 1000 per step (up to `maxUnit`) and returns the step. Rounds FIRST, then
|
|
126
|
+
* promotes when the rounded magnitude reaches 1000 — `999.6` at step 0 is `1000` and belongs to
|
|
127
|
+
* the next unit, not `1,000 B`. Step 0 is whole numbers; higher steps round to `digits`.
|
|
128
|
+
*/
|
|
129
|
+
export function scaleThousands(
|
|
130
|
+
value: number,
|
|
131
|
+
digits: number,
|
|
132
|
+
maxUnit: number,
|
|
133
|
+
): { scaled: number; unit: number } {
|
|
134
|
+
let scaled = value
|
|
135
|
+
let unit = 0
|
|
136
|
+
while (unit < maxUnit) {
|
|
137
|
+
const factor = 10 ** (unit === 0 ? 0 : digits)
|
|
138
|
+
if (Math.round(Math.abs(scaled) * factor) / factor < 1000) break
|
|
139
|
+
scaled /= 1000
|
|
140
|
+
unit += 1
|
|
141
|
+
}
|
|
142
|
+
return { scaled, unit }
|
|
52
143
|
}
|
|
53
144
|
|
|
54
145
|
/** Coerces the flexible `Date | number | string` inputs this module's date formatters accept into
|
package/src/provider/index.tsx
CHANGED
|
@@ -32,6 +32,8 @@ import { buildPaletteData } from '../tokens/palette'
|
|
|
32
32
|
import { useMediaQuery } from '../common/use-media-query'
|
|
33
33
|
import { registerColorSchemeSetter } from '../commands/shell-bridge'
|
|
34
34
|
import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
|
|
35
|
+
import { defineFormat } from '../format/shared'
|
|
36
|
+
import type { FormatDefaults } from '../format/shared'
|
|
35
37
|
import { PageTitle } from '../shell/page-title'
|
|
36
38
|
import { SizeClassHintContext } from '../shell/use-size-class'
|
|
37
39
|
import type { SizeClass } from '../shell/use-size-class'
|
|
@@ -98,6 +100,18 @@ type BasaltProviderCommonProps = {
|
|
|
98
100
|
* action wiring mounts.
|
|
99
101
|
*/
|
|
100
102
|
spotlight?: boolean
|
|
103
|
+
/**
|
|
104
|
+
* Default BCP-47 locale for every `basalt-ui/format` formatter that gets no per-call `locale`
|
|
105
|
+
* (`integer(1112)` → `1,112` under `en-US`). App-level config, static for the provider's
|
|
106
|
+
* lifetime: it sets ONE module-global default per process (formatters are plain functions, not
|
|
107
|
+
* hooks) and a per-call `locale` is the override. An unset prop LEAVES the current default in
|
|
108
|
+
* place (it never resets it), and changing the prop at runtime does not re-render formatted
|
|
109
|
+
* children.
|
|
110
|
+
*/
|
|
111
|
+
locale?: string
|
|
112
|
+
/** Default IANA time zone for the date/time formatters; same lifecycle as `locale`. Unset leaves
|
|
113
|
+
* the current default (initially the runtime's zone). */
|
|
114
|
+
timeZone?: string
|
|
101
115
|
} & Omit<MantineProviderProps, 'children' | 'theme' | 'defaultColorScheme' | 'cssVariablesResolver'>
|
|
102
116
|
|
|
103
117
|
/**
|
|
@@ -482,12 +496,21 @@ export function BasaltProvider({
|
|
|
482
496
|
sizeClassHint = 'compact',
|
|
483
497
|
navCommandLabel,
|
|
484
498
|
spotlight = true,
|
|
499
|
+
locale,
|
|
500
|
+
timeZone,
|
|
485
501
|
router: mountedRouter,
|
|
486
502
|
children,
|
|
487
503
|
...rest
|
|
488
504
|
}: BasaltProviderProps) {
|
|
489
505
|
useDuplicateProviderGuard()
|
|
490
506
|
useHostAttribute()
|
|
507
|
+
// Applied during render so the first formatted child already sees it; only when a prop changed,
|
|
508
|
+
// and only the props received (an unset one leaves an earlier value or a manual `defineFormat`).
|
|
509
|
+
const appliedFormat = useRef<FormatDefaults>({})
|
|
510
|
+
if (appliedFormat.current.locale !== locale || appliedFormat.current.timeZone !== timeZone) {
|
|
511
|
+
appliedFormat.current = { locale, timeZone }
|
|
512
|
+
defineFormat({ locale, timeZone })
|
|
513
|
+
}
|
|
491
514
|
|
|
492
515
|
// The sink is read through a ref, so an inline `telemetry` function does not re-subscribe.
|
|
493
516
|
const sink = telemetry ?? (process.env.NODE_ENV === 'production' ? undefined : devConsoleSink)
|
package/src/surfaces.ts
CHANGED
|
@@ -655,6 +655,11 @@ export const SKILL_NAMES = [
|
|
|
655
655
|
),
|
|
656
656
|
] as const satisfies readonly SkillName[]
|
|
657
657
|
|
|
658
|
+
// ── PROJECTION 1c — AGENT_NAMES ───────────────────────────────────────────────────────────────────
|
|
659
|
+
|
|
660
|
+
/** The shipped subagents (`agent/agents/<name>.md`), installed at `.claude/agents/`. */
|
|
661
|
+
export const AGENT_NAMES = ['basalt-design-reviewer'] as const
|
|
662
|
+
|
|
658
663
|
// ── Token-layer-boundary-via-plugin membership ────────────────────────────────────────────────────
|
|
659
664
|
|
|
660
665
|
/**
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* formatRelativeTime — dependency-free relative-time formatting (no date-fns).
|
|
3
|
-
*
|
|
4
|
-
* Shared between `ThreadOutcomeCard` (inbox row timestamps) and `ThreadTranscript` (per-message
|
|
5
|
-
* timestamps). 'en'-hardcoded for now — see the module-level note below for the deferred locale
|
|
6
|
-
* seam.
|
|
7
|
-
*
|
|
8
|
-
* Internal to `agent-chat/` — not part of the public barrel.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Formats an epoch-ms timestamp as a short relative string ("3 hours ago", "just now").
|
|
12
|
-
*
|
|
13
|
-
* A non-finite `timestamp` — `NaN`, `±Infinity`, or a non-number value that slipped past the
|
|
14
|
-
* `ChatMessage.createdAt: number` type at runtime (an ISO string or `undefined`/`null` from a
|
|
15
|
-
* hand-rolled `ThreadsStoreAdapter`, or from JSON-deserialized `localStorage` state) renders as an
|
|
16
|
-
* empty string rather than reaching `Intl.RelativeTimeFormat.format`, which throws a `RangeError`
|
|
17
|
-
* on any non-finite input. This is render-path code — one bad `createdAt` on one message must not
|
|
18
|
-
* blank the whole transcript (the standing rule `spliceText`/`coalesceParts` already hold) — so it
|
|
19
|
-
* degrades instead of throwing, and warns in dev, matching `mergePart`'s clamp-and-warn precedent
|
|
20
|
-
* (`clampOffset` in `../agent/merge.ts`). The warning is NOT deduplicated, also matching that
|
|
21
|
-
* precedent — but note the call sites differ: `clampOffset` runs once per wire event, whereas this
|
|
22
|
-
* runs during render, once per message, so a single bad `createdAt` in a long transcript warns
|
|
23
|
-
* once per message per render. That is loud on purpose (a `createdAt` that isn't a number is an
|
|
24
|
-
* adapter bug worth fixing, not worth muting), and it costs nothing in production.
|
|
25
|
-
*/
|
|
26
|
-
export declare function formatRelativeTime(timestamp: number): string;
|
|
27
|
-
//# sourceMappingURL=relative-time.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relative-time.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/relative-time.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAc5D"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const RELATIVE_TIME_FORMAT = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
|
|
2
|
-
const RELATIVE_TIME_UNITS = [
|
|
3
|
-
{ unit: "year", ms: 31536e6 },
|
|
4
|
-
{ unit: "month", ms: 2628e6 },
|
|
5
|
-
{ unit: "week", ms: 6048e5 },
|
|
6
|
-
{ unit: "day", ms: 864e5 },
|
|
7
|
-
{ unit: "hour", ms: 36e5 },
|
|
8
|
-
{ unit: "minute", ms: 6e4 }
|
|
9
|
-
];
|
|
10
|
-
function formatRelativeTime(timestamp) {
|
|
11
|
-
if (!Number.isFinite(timestamp)) {
|
|
12
|
-
if (process.env.NODE_ENV !== "production") {
|
|
13
|
-
console.warn(
|
|
14
|
-
`[basalt] formatRelativeTime: non-finite timestamp ${String(timestamp)} \u2014 rendering empty string`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
return "";
|
|
18
|
-
}
|
|
19
|
-
const diffMs = timestamp - Date.now();
|
|
20
|
-
const absMs = Math.abs(diffMs);
|
|
21
|
-
if (absMs < 6e4) return "just now";
|
|
22
|
-
const unit = RELATIVE_TIME_UNITS.find(({ ms }) => absMs >= ms) ?? RELATIVE_TIME_UNITS.at(-1);
|
|
23
|
-
return RELATIVE_TIME_FORMAT.format(Math.round(diffMs / unit.ms), unit.unit);
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
formatRelativeTime
|
|
27
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* formatRelativeTime — dependency-free relative-time formatting (no date-fns).
|
|
3
|
-
*
|
|
4
|
-
* Shared between `ThreadOutcomeCard` (inbox row timestamps) and `ThreadTranscript` (per-message
|
|
5
|
-
* timestamps). 'en'-hardcoded for now — see the module-level note below for the deferred locale
|
|
6
|
-
* seam.
|
|
7
|
-
*
|
|
8
|
-
* Internal to `agent-chat/` — not part of the public barrel.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const RELATIVE_TIME_FORMAT = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
|
|
12
|
-
|
|
13
|
-
const RELATIVE_TIME_UNITS: readonly {
|
|
14
|
-
readonly unit: Intl.RelativeTimeFormatUnit
|
|
15
|
-
readonly ms: number
|
|
16
|
-
}[] = [
|
|
17
|
-
{ unit: 'year', ms: 31_536_000_000 },
|
|
18
|
-
{ unit: 'month', ms: 2_628_000_000 },
|
|
19
|
-
{ unit: 'week', ms: 604_800_000 },
|
|
20
|
-
{ unit: 'day', ms: 86_400_000 },
|
|
21
|
-
{ unit: 'hour', ms: 3_600_000 },
|
|
22
|
-
{ unit: 'minute', ms: 60_000 },
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Formats an epoch-ms timestamp as a short relative string ("3 hours ago", "just now").
|
|
27
|
-
*
|
|
28
|
-
* A non-finite `timestamp` — `NaN`, `±Infinity`, or a non-number value that slipped past the
|
|
29
|
-
* `ChatMessage.createdAt: number` type at runtime (an ISO string or `undefined`/`null` from a
|
|
30
|
-
* hand-rolled `ThreadsStoreAdapter`, or from JSON-deserialized `localStorage` state) renders as an
|
|
31
|
-
* empty string rather than reaching `Intl.RelativeTimeFormat.format`, which throws a `RangeError`
|
|
32
|
-
* on any non-finite input. This is render-path code — one bad `createdAt` on one message must not
|
|
33
|
-
* blank the whole transcript (the standing rule `spliceText`/`coalesceParts` already hold) — so it
|
|
34
|
-
* degrades instead of throwing, and warns in dev, matching `mergePart`'s clamp-and-warn precedent
|
|
35
|
-
* (`clampOffset` in `../agent/merge.ts`). The warning is NOT deduplicated, also matching that
|
|
36
|
-
* precedent — but note the call sites differ: `clampOffset` runs once per wire event, whereas this
|
|
37
|
-
* runs during render, once per message, so a single bad `createdAt` in a long transcript warns
|
|
38
|
-
* once per message per render. That is loud on purpose (a `createdAt` that isn't a number is an
|
|
39
|
-
* adapter bug worth fixing, not worth muting), and it costs nothing in production.
|
|
40
|
-
*/
|
|
41
|
-
export function formatRelativeTime(timestamp: number): string {
|
|
42
|
-
if (!Number.isFinite(timestamp)) {
|
|
43
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
-
console.warn(
|
|
45
|
-
`[basalt] formatRelativeTime: non-finite timestamp ${String(timestamp)} — rendering empty string`,
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
return ''
|
|
49
|
-
}
|
|
50
|
-
const diffMs = timestamp - Date.now()
|
|
51
|
-
const absMs = Math.abs(diffMs)
|
|
52
|
-
if (absMs < 60_000) return 'just now'
|
|
53
|
-
const unit = RELATIVE_TIME_UNITS.find(({ ms }) => absMs >= ms) ?? RELATIVE_TIME_UNITS.at(-1)!
|
|
54
|
-
return RELATIVE_TIME_FORMAT.format(Math.round(diffMs / unit.ms), unit.unit)
|
|
55
|
-
}
|