@cat-factory/app 0.6.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +1,52 @@
1
- // Formatting + derivation helpers for the LLM observability surfaces (inline step
2
- // rollups + the drill-down panel). Kept here so the components stay declarative and
3
- // the number-crunching is unit-testable.
4
-
5
- import type { StepMetrics } from '~/types/execution'
6
-
7
- /** Compact token count: 1234 → "1.2k", 980 → "980", 2_500_000 → "2.5M". */
8
- export function formatTokens(n: number): string {
9
- if (n < 1000) return `${n}`
10
- if (n < 1_000_000) return `${(n / 1000).toFixed(n < 10_000 ? 1 : 0)}k`
11
- return `${(n / 1_000_000).toFixed(1)}M`
12
- }
13
-
14
- /** Compact duration: 850 → "850ms", 1500 → "1.5s", 90_000 → "1m 30s". */
15
- export function formatMs(ms: number): string {
16
- if (ms < 1000) return `${Math.round(ms)}ms`
17
- const totalSec = ms / 1000
18
- if (totalSec < 60) return `${totalSec.toFixed(totalSec < 10 ? 1 : 0)}s`
19
- const m = Math.floor(totalSec / 60)
20
- const sec = Math.round(totalSec % 60)
21
- return sec ? `${m}m ${sec}s` : `${m}m`
22
- }
23
-
24
- /** A ratio (0..1) as a whole-number percentage. */
25
- export function pct(ratio: number): number {
26
- return Math.round(ratio * 100)
27
- }
28
-
29
- /**
30
- * Output-limit headroom for a step's rollup: the fraction of the output ceiling the
31
- * closest call consumed (0..1), or null when the ceiling is unknown. 1 (or any
32
- * truncated call) means a call hit the limit and was cut short.
33
- */
34
- export function headroomRatio(
35
- m: Pick<StepMetrics, 'peakCompletionTokens' | 'maxOutputTokens'>,
36
- ): number | null {
37
- if (m.maxOutputTokens == null || m.maxOutputTokens <= 0) return null
38
- return Math.min(1, m.peakCompletionTokens / m.maxOutputTokens)
39
- }
40
-
41
- /** Share of a step's latency spent in transport/proxy overhead (0..1), or null. */
42
- export function transportRatio(m: Pick<StepMetrics, 'upstreamMs' | 'overheadMs'>): number | null {
43
- const total = m.upstreamMs + m.overheadMs
44
- return total > 0 ? m.overheadMs / total : null
45
- }
46
-
47
- /** Tailwind text/bg colour for an output-headroom level (green → amber → red). */
48
- export function headroomColor(ratio: number | null, truncated: boolean): string {
49
- if (truncated || (ratio != null && ratio >= 0.98)) return 'text-rose-400'
50
- if (ratio != null && ratio >= 0.8) return 'text-amber-400'
51
- return 'text-emerald-400'
52
- }
1
+ // Formatting + derivation helpers for the LLM observability surfaces (inline step
2
+ // rollups + the drill-down panel). Kept here so the components stay declarative and
3
+ // the number-crunching is unit-testable.
4
+
5
+ import type { StepMetrics } from '~/types/execution'
6
+
7
+ /** Compact token count: 1234 → "1.2k", 980 → "980", 2_500_000 → "2.5M". */
8
+ export function formatTokens(n: number): string {
9
+ if (n < 1000) return `${n}`
10
+ if (n < 1_000_000) return `${(n / 1000).toFixed(n < 10_000 ? 1 : 0)}k`
11
+ return `${(n / 1_000_000).toFixed(1)}M`
12
+ }
13
+
14
+ /** Compact duration: 850 → "850ms", 1500 → "1.5s", 90_000 → "1m 30s". */
15
+ export function formatMs(ms: number): string {
16
+ if (ms < 1000) return `${Math.round(ms)}ms`
17
+ const totalSec = ms / 1000
18
+ if (totalSec < 60) return `${totalSec.toFixed(totalSec < 10 ? 1 : 0)}s`
19
+ const m = Math.floor(totalSec / 60)
20
+ const sec = Math.round(totalSec % 60)
21
+ return sec ? `${m}m ${sec}s` : `${m}m`
22
+ }
23
+
24
+ /** A ratio (0..1) as a whole-number percentage. */
25
+ export function pct(ratio: number): number {
26
+ return Math.round(ratio * 100)
27
+ }
28
+
29
+ /**
30
+ * Output-limit headroom for a step's rollup: the fraction of the output ceiling the
31
+ * closest call consumed (0..1), or null when the ceiling is unknown. 1 (or any
32
+ * truncated call) means a call hit the limit and was cut short.
33
+ */
34
+ export function headroomRatio(
35
+ m: Pick<StepMetrics, 'peakCompletionTokens' | 'maxOutputTokens'>,
36
+ ): number | null {
37
+ if (m.maxOutputTokens == null || m.maxOutputTokens <= 0) return null
38
+ return Math.min(1, m.peakCompletionTokens / m.maxOutputTokens)
39
+ }
40
+
41
+ /** Share of a step's latency spent in transport/proxy overhead (0..1), or null. */
42
+ export function transportRatio(m: Pick<StepMetrics, 'upstreamMs' | 'overheadMs'>): number | null {
43
+ const total = m.upstreamMs + m.overheadMs
44
+ return total > 0 ? m.overheadMs / total : null
45
+ }
46
+
47
+ /** Tailwind text/bg colour for an output-headroom level (green → amber → red). */
48
+ export function headroomColor(ratio: number | null, truncated: boolean): string {
49
+ if (truncated || (ratio != null && ratio >= 0.98)) return 'text-rose-400'
50
+ if (ratio != null && ratio >= 0.8) return 'text-amber-400'
51
+ return 'text-emerald-400'
52
+ }
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@cat-factory/app",
3
- "version": "0.6.0",
3
+ "version": "0.7.2",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/kibertoad/cat-factory.git",
7
+ "directory": "frontend/app"
8
+ },
4
9
  "description": "Reusable Nuxt layer for the Agent Architecture Board SPA (components, stores, composables, pages). Consume it from a thin deployment app via `extends: ['@cat-factory/app']` and point it at your backend with NUXT_PUBLIC_API_BASE. See deploy/frontend for an example.",
5
10
  "files": [
6
11
  "app",