@warmdrift/kgauto-compiler 2.0.0-alpha.34 → 2.0.0-alpha.36
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/dist/chunk-P3TOAEG4.mjs +56 -0
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/format.d.mts +24 -0
- package/dist/glassbox-routes/format.d.ts +24 -0
- package/dist/glassbox-routes/format.js +86 -0
- package/dist/glassbox-routes/format.mjs +18 -0
- package/dist/glassbox-routes/index.d.mts +5 -149
- package/dist/glassbox-routes/index.d.ts +5 -149
- package/dist/glassbox-routes/react/index.d.mts +74 -0
- package/dist/glassbox-routes/react/index.d.ts +74 -0
- package/dist/glassbox-routes/react/index.js +819 -0
- package/dist/glassbox-routes/react/index.mjs +754 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/{ir-BAAHLfFL.d.mts → ir-BiZSAVCJ.d.mts} +20 -0
- package/dist/{ir-B_ygNURd.d.ts → ir-CZ9Ng96k.d.ts} +20 -0
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-CXyKj6-K.d.ts → types-CsFP-H-U.d.ts} +1 -1
- package/dist/types-HEl2tS4P.d.ts +149 -0
- package/dist/{types-BoqPXoUb.d.mts → types-f7idIVsm.d.mts} +1 -1
- package/dist/types-kzYpX7wB.d.mts +149 -0
- package/package.json +32 -6
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/glassbox-routes/format.ts
|
|
2
|
+
function formatAgo(iso, now = Date.now()) {
|
|
3
|
+
const t = Date.parse(iso);
|
|
4
|
+
if (Number.isNaN(t)) return iso;
|
|
5
|
+
const sec = Math.max(0, Math.floor((now - t) / 1e3));
|
|
6
|
+
if (sec < 60) return `${sec}s ago`;
|
|
7
|
+
if (sec < 3600) return `${Math.floor(sec / 60)}m ago`;
|
|
8
|
+
if (sec < 86400) return `${Math.floor(sec / 3600)}h ago`;
|
|
9
|
+
return `${Math.floor(sec / 86400)}d ago`;
|
|
10
|
+
}
|
|
11
|
+
function shortTraceId(traceId) {
|
|
12
|
+
return traceId.slice(-6);
|
|
13
|
+
}
|
|
14
|
+
function formatCost(usd) {
|
|
15
|
+
if (usd === void 0 || usd === null || Number.isNaN(usd)) return "\u2014";
|
|
16
|
+
if (usd === 0) return "$0.0000";
|
|
17
|
+
if (usd < 0.01) return `$${usd.toFixed(4)}`;
|
|
18
|
+
return `$${usd.toFixed(3)}`;
|
|
19
|
+
}
|
|
20
|
+
function formatMs(ms) {
|
|
21
|
+
if (ms === void 0 || ms === null) return "\u2014";
|
|
22
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
23
|
+
return `${(ms / 1e3).toFixed(1)}s`;
|
|
24
|
+
}
|
|
25
|
+
function formatOrDash(v) {
|
|
26
|
+
if (v === void 0 || v === null) return "\u2014";
|
|
27
|
+
if (typeof v === "number") return v.toLocaleString();
|
|
28
|
+
return v;
|
|
29
|
+
}
|
|
30
|
+
function inputRatioLabel(status) {
|
|
31
|
+
switch (status) {
|
|
32
|
+
case "green":
|
|
33
|
+
return "healthy";
|
|
34
|
+
case "yellow":
|
|
35
|
+
return "borderline";
|
|
36
|
+
case "red":
|
|
37
|
+
return "input-heavy";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function formatMutation(mutation) {
|
|
41
|
+
const m = /^(.*)-(\d+)-to-(\d+)$/.exec(mutation);
|
|
42
|
+
if (m) {
|
|
43
|
+
return `${m[1]} (${m[2]} \u2192 ${m[3]})`;
|
|
44
|
+
}
|
|
45
|
+
return mutation;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
formatAgo,
|
|
50
|
+
shortTraceId,
|
|
51
|
+
formatCost,
|
|
52
|
+
formatMs,
|
|
53
|
+
formatOrDash,
|
|
54
|
+
inputRatioLabel,
|
|
55
|
+
formatMutation
|
|
56
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-
|
|
3
|
-
import '../ir-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-f7idIVsm.mjs';
|
|
2
|
+
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-f7idIVsm.mjs';
|
|
3
|
+
import '../ir-BiZSAVCJ.mjs';
|
|
4
4
|
import '../dialect.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/glassbox/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-
|
|
3
|
-
import '../ir-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-CsFP-H-U.js';
|
|
2
|
+
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-CsFP-H-U.js';
|
|
3
|
+
import '../ir-CZ9Ng96k.js';
|
|
4
4
|
import '../dialect.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { T as TraceHealth } from '../types-kzYpX7wB.mjs';
|
|
2
|
+
import '../ir-BiZSAVCJ.mjs';
|
|
3
|
+
import '../dialect.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pure formatting helpers for Glass-Box trace display.
|
|
7
|
+
*
|
|
8
|
+
* Zero deps, no React, no design tokens. Safe to import from any consumer
|
|
9
|
+
* (React component, server route, CLI, Edge worker).
|
|
10
|
+
*
|
|
11
|
+
* Extracted from the alpha.32 tt-intelligence reference component port in
|
|
12
|
+
* alpha.35 so multiple consumer dashboards can render trace data with
|
|
13
|
+
* matching formatting without re-implementing each helper.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
declare function formatAgo(iso: string, now?: number): string;
|
|
17
|
+
declare function shortTraceId(traceId: string): string;
|
|
18
|
+
declare function formatCost(usd: number | undefined | null): string;
|
|
19
|
+
declare function formatMs(ms: number | undefined | null): string;
|
|
20
|
+
declare function formatOrDash(v: number | string | undefined | null): string;
|
|
21
|
+
declare function inputRatioLabel(status: TraceHealth['inputRatioStatus']): string;
|
|
22
|
+
declare function formatMutation(mutation: string): string;
|
|
23
|
+
|
|
24
|
+
export { formatAgo, formatCost, formatMs, formatMutation, formatOrDash, inputRatioLabel, shortTraceId };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { T as TraceHealth } from '../types-HEl2tS4P.js';
|
|
2
|
+
import '../ir-CZ9Ng96k.js';
|
|
3
|
+
import '../dialect.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pure formatting helpers for Glass-Box trace display.
|
|
7
|
+
*
|
|
8
|
+
* Zero deps, no React, no design tokens. Safe to import from any consumer
|
|
9
|
+
* (React component, server route, CLI, Edge worker).
|
|
10
|
+
*
|
|
11
|
+
* Extracted from the alpha.32 tt-intelligence reference component port in
|
|
12
|
+
* alpha.35 so multiple consumer dashboards can render trace data with
|
|
13
|
+
* matching formatting without re-implementing each helper.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
declare function formatAgo(iso: string, now?: number): string;
|
|
17
|
+
declare function shortTraceId(traceId: string): string;
|
|
18
|
+
declare function formatCost(usd: number | undefined | null): string;
|
|
19
|
+
declare function formatMs(ms: number | undefined | null): string;
|
|
20
|
+
declare function formatOrDash(v: number | string | undefined | null): string;
|
|
21
|
+
declare function inputRatioLabel(status: TraceHealth['inputRatioStatus']): string;
|
|
22
|
+
declare function formatMutation(mutation: string): string;
|
|
23
|
+
|
|
24
|
+
export { formatAgo, formatCost, formatMs, formatMutation, formatOrDash, inputRatioLabel, shortTraceId };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/glassbox-routes/format.ts
|
|
21
|
+
var format_exports = {};
|
|
22
|
+
__export(format_exports, {
|
|
23
|
+
formatAgo: () => formatAgo,
|
|
24
|
+
formatCost: () => formatCost,
|
|
25
|
+
formatMs: () => formatMs,
|
|
26
|
+
formatMutation: () => formatMutation,
|
|
27
|
+
formatOrDash: () => formatOrDash,
|
|
28
|
+
inputRatioLabel: () => inputRatioLabel,
|
|
29
|
+
shortTraceId: () => shortTraceId
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(format_exports);
|
|
32
|
+
function formatAgo(iso, now = Date.now()) {
|
|
33
|
+
const t = Date.parse(iso);
|
|
34
|
+
if (Number.isNaN(t)) return iso;
|
|
35
|
+
const sec = Math.max(0, Math.floor((now - t) / 1e3));
|
|
36
|
+
if (sec < 60) return `${sec}s ago`;
|
|
37
|
+
if (sec < 3600) return `${Math.floor(sec / 60)}m ago`;
|
|
38
|
+
if (sec < 86400) return `${Math.floor(sec / 3600)}h ago`;
|
|
39
|
+
return `${Math.floor(sec / 86400)}d ago`;
|
|
40
|
+
}
|
|
41
|
+
function shortTraceId(traceId) {
|
|
42
|
+
return traceId.slice(-6);
|
|
43
|
+
}
|
|
44
|
+
function formatCost(usd) {
|
|
45
|
+
if (usd === void 0 || usd === null || Number.isNaN(usd)) return "\u2014";
|
|
46
|
+
if (usd === 0) return "$0.0000";
|
|
47
|
+
if (usd < 0.01) return `$${usd.toFixed(4)}`;
|
|
48
|
+
return `$${usd.toFixed(3)}`;
|
|
49
|
+
}
|
|
50
|
+
function formatMs(ms) {
|
|
51
|
+
if (ms === void 0 || ms === null) return "\u2014";
|
|
52
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
53
|
+
return `${(ms / 1e3).toFixed(1)}s`;
|
|
54
|
+
}
|
|
55
|
+
function formatOrDash(v) {
|
|
56
|
+
if (v === void 0 || v === null) return "\u2014";
|
|
57
|
+
if (typeof v === "number") return v.toLocaleString();
|
|
58
|
+
return v;
|
|
59
|
+
}
|
|
60
|
+
function inputRatioLabel(status) {
|
|
61
|
+
switch (status) {
|
|
62
|
+
case "green":
|
|
63
|
+
return "healthy";
|
|
64
|
+
case "yellow":
|
|
65
|
+
return "borderline";
|
|
66
|
+
case "red":
|
|
67
|
+
return "input-heavy";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function formatMutation(mutation) {
|
|
71
|
+
const m = /^(.*)-(\d+)-to-(\d+)$/.exec(mutation);
|
|
72
|
+
if (m) {
|
|
73
|
+
return `${m[1]} (${m[2]} \u2192 ${m[3]})`;
|
|
74
|
+
}
|
|
75
|
+
return mutation;
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
formatAgo,
|
|
80
|
+
formatCost,
|
|
81
|
+
formatMs,
|
|
82
|
+
formatMutation,
|
|
83
|
+
formatOrDash,
|
|
84
|
+
inputRatioLabel,
|
|
85
|
+
shortTraceId
|
|
86
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatAgo,
|
|
3
|
+
formatCost,
|
|
4
|
+
formatMs,
|
|
5
|
+
formatMutation,
|
|
6
|
+
formatOrDash,
|
|
7
|
+
inputRatioLabel,
|
|
8
|
+
shortTraceId
|
|
9
|
+
} from "../chunk-P3TOAEG4.mjs";
|
|
10
|
+
export {
|
|
11
|
+
formatAgo,
|
|
12
|
+
formatCost,
|
|
13
|
+
formatMs,
|
|
14
|
+
formatMutation,
|
|
15
|
+
formatOrDash,
|
|
16
|
+
inputRatioLabel,
|
|
17
|
+
shortTraceId
|
|
18
|
+
};
|
|
@@ -1,153 +1,9 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
import {
|
|
1
|
+
import { G as GlassboxEvent } from '../types-f7idIVsm.mjs';
|
|
2
|
+
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-kzYpX7wB.mjs';
|
|
3
|
+
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-kzYpX7wB.mjs';
|
|
4
|
+
import '../ir-BiZSAVCJ.mjs';
|
|
3
5
|
import '../dialect.mjs';
|
|
4
6
|
|
|
5
|
-
/**
|
|
6
|
-
* Internal config + hook types for createGlassboxRoutes().
|
|
7
|
-
*
|
|
8
|
-
* The public contract lives on `GlassboxRoutesConfig` in ./index.ts; these
|
|
9
|
-
* are the narrower per-handler shapes consumed by proxy.ts and stream.ts.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Wire contract for the Glass-Box Chrome extension's brain-poll endpoint.
|
|
14
|
-
*
|
|
15
|
-
* The list mode of `proxy(req)` returns `{ traces: TraceSummary[] }`. The
|
|
16
|
-
* detail mode (`?traceId=<id>`) returns a single `TraceDetail`. These are
|
|
17
|
-
* the camelCase shapes the extension renderer expects — distinct from the
|
|
18
|
-
* snake_case `compile_outcomes` row shape that PostgREST returns. The
|
|
19
|
-
* factory's typed `rowToSummary` / `rowToDetail` transformer is the single
|
|
20
|
-
* canonical boundary between the DB shape and the wire shape (see
|
|
21
|
-
* `feedback_typed_boundary_transformers.md` in kgauto memory for the rule).
|
|
22
|
-
*/
|
|
23
|
-
interface TraceSummary {
|
|
24
|
-
traceId: string;
|
|
25
|
-
appId: string;
|
|
26
|
-
archetype: string;
|
|
27
|
-
target: string;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
tokensIn: number;
|
|
30
|
-
tokensOut: number;
|
|
31
|
-
estimatedCostUsd: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface AdvisoryRecord {
|
|
35
|
-
level: 'info' | 'warn' | 'critical';
|
|
36
|
-
/** Stable advisory identifier, e.g. "caching-off-on-claude". */
|
|
37
|
-
code: string;
|
|
38
|
-
/** Consumer-renderable message — no internal jargon ("L-040", "R3" etc.). */
|
|
39
|
-
message: string;
|
|
40
|
-
/** Optional secondary one-liner. Renders below `message` in italics. */
|
|
41
|
-
suggestion?: string;
|
|
42
|
-
/** Deep link to the relevant section of `interfaces/kgauto.md` or docs. */
|
|
43
|
-
docsUrl?: string;
|
|
44
|
-
/**
|
|
45
|
-
* alpha.28+ — closed-union adaptation hint surfaced by the advisor when
|
|
46
|
-
* the advisory can be auto-mitigated by a config knob. Renderer surfaces
|
|
47
|
-
* as `→ try toolOrchestration: 'sequential'` on the advisory row.
|
|
48
|
-
*
|
|
49
|
-
* MUST stay byte-identical to Builder C's
|
|
50
|
-
* `BestPracticeAdvisory.suggestedAdaptation` shape (verified at Phase 2
|
|
51
|
-
* integration; the Adapter type itself is the contract).
|
|
52
|
-
*/
|
|
53
|
-
suggestedAdaptation?: Adapter;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Cost-equivalent alternative the chain could have served. Computed at
|
|
57
|
-
* detail-view time by `computeCounterfactuals()` against the served row's
|
|
58
|
-
* observed token counts + archetype + cache state. Up to 2 entries, sorted
|
|
59
|
-
* cheapest first.
|
|
60
|
-
*/
|
|
61
|
-
interface TraceCounterfactual {
|
|
62
|
-
modelId: string;
|
|
63
|
-
estimatedCostUsd: number;
|
|
64
|
-
/** servedCostUsd - estimatedCostUsd (always > 0; only ≥10% savings kept). */
|
|
65
|
-
savingsUsd: number;
|
|
66
|
-
/** 0-100. */
|
|
67
|
-
savingsPercent: number;
|
|
68
|
-
/** Plain-English rationale tying archetype + perf score. */
|
|
69
|
-
reason: string;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Derived axis-health tri-state for the three Glass-Box dots
|
|
73
|
-
* (input-ratio · cache · fallback). Renderer reads; transformer computes.
|
|
74
|
-
*
|
|
75
|
-
* Thresholds (locked in design contract Phase 0):
|
|
76
|
-
* - inputRatio: green ≤ 0.65 · yellow 0.65–0.85 · red > 0.85
|
|
77
|
-
* - cache (only when historyCacheableTokens > 1000):
|
|
78
|
-
* green if inputCacheHitRatio ≥ 0.5
|
|
79
|
-
* yellow if 0.1 ≤ inputCacheHitRatio < 0.5
|
|
80
|
-
* red if inputCacheHitRatio < 0.1
|
|
81
|
-
* na if historyCacheableTokens ≤ 1000
|
|
82
|
-
* - fallback: red iff fellOverFrom !== undefined && fellOverFrom !== target
|
|
83
|
-
*/
|
|
84
|
-
interface TraceHealth {
|
|
85
|
-
inputRatioStatus: 'green' | 'yellow' | 'red';
|
|
86
|
-
cacheStatus: 'green' | 'yellow' | 'red' | 'na';
|
|
87
|
-
fallbackStatus: 'green' | 'red';
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* alpha.29+ — wire-boundary representation of a translator section-rewrite.
|
|
91
|
-
*
|
|
92
|
-
* Distinct from the package-internal `SectionRewrite` type in `ir.ts`: this
|
|
93
|
-
* shape drops `originalText` + `transformedText` because those may carry
|
|
94
|
-
* consumer PII. The renderer shows the `rule` + `summary` only. Full text
|
|
95
|
-
* stays on `compile_outcomes.section_rewrites_applied` (Supabase row), gated
|
|
96
|
-
* by RLS for brain-side cross-app learning.
|
|
97
|
-
*/
|
|
98
|
-
interface TraceSectionRewrite {
|
|
99
|
-
/** Stable id of the rewritten section. */
|
|
100
|
-
sectionId: string;
|
|
101
|
-
/** Section-kind discriminator that triggered the rewrite. */
|
|
102
|
-
kind: SectionKind;
|
|
103
|
-
/** Stable rule identifier (e.g. `'sequential-tool-cliff-below-floor'`). */
|
|
104
|
-
rule: string;
|
|
105
|
-
/**
|
|
106
|
-
* Plain-English one-liner describing what fired and why. Renderer surfaces
|
|
107
|
-
* this on the Coaching card; no internal jargon ("L-040", "below floor").
|
|
108
|
-
*/
|
|
109
|
-
summary: string;
|
|
110
|
-
}
|
|
111
|
-
interface TraceDetail extends TraceSummary {
|
|
112
|
-
mutationsApplied: string[];
|
|
113
|
-
advisories: AdvisoryRecord[];
|
|
114
|
-
rawRequest?: string;
|
|
115
|
-
rawResponse?: string;
|
|
116
|
-
/** Set when consumer passed a forceModel / fallback fired. */
|
|
117
|
-
requestedModel?: string;
|
|
118
|
-
/** Provider finish reason — 'stop' / 'max_tokens' / 'tool_use' / etc. */
|
|
119
|
-
finishReason?: string;
|
|
120
|
-
/** Time to first token (ms); populated when provider surfaces it. */
|
|
121
|
-
ttftMs?: number;
|
|
122
|
-
/** End-to-end wall-clock (ms); from migration 018. */
|
|
123
|
-
totalMs?: number;
|
|
124
|
-
/** Tools kept after relevance pass. */
|
|
125
|
-
toolsCount?: number;
|
|
126
|
-
/** Number of history messages at compile time. */
|
|
127
|
-
historyDepth?: number;
|
|
128
|
-
/** Rendered system prompt size in characters. */
|
|
129
|
-
systemPromptChars?: number;
|
|
130
|
-
cacheReadInputTokens: number;
|
|
131
|
-
cacheCreationInputTokens: number;
|
|
132
|
-
historyCacheableTokens: number;
|
|
133
|
-
/** Derived: cacheReadInputTokens / max(tokensIn, 1). 0-1. */
|
|
134
|
-
inputCacheHitRatio: number;
|
|
135
|
-
fellOverFrom?: string;
|
|
136
|
-
fallbackReason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
|
|
137
|
-
/** Up to 2 alternatives. Empty array (not undefined) when none qualify. */
|
|
138
|
-
counterfactuals?: TraceCounterfactual[];
|
|
139
|
-
/** Undefined when 7d volume < 5/day (insufficient data). */
|
|
140
|
-
projectedDailyCostUsd?: number;
|
|
141
|
-
/**
|
|
142
|
-
* alpha.29+ — translator activity for this trace. Empty array (not
|
|
143
|
-
* undefined) when no rewrites fired or pre-019 row. Surfaced in the
|
|
144
|
-
* Glass-Box Coaching card as synthetic info-level rows. PII-safe by
|
|
145
|
-
* construction: only sectionId + kind + rule + summary cross the wire.
|
|
146
|
-
*/
|
|
147
|
-
sectionRewritesApplied: TraceSectionRewrite[];
|
|
148
|
-
health: TraceHealth;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
7
|
/**
|
|
152
8
|
* proxy(req) — Glass-Box replay query handler.
|
|
153
9
|
*
|
|
@@ -332,4 +188,4 @@ interface GlassboxRoutes {
|
|
|
332
188
|
}
|
|
333
189
|
declare function createGlassboxRoutes(config: GlassboxRoutesConfig): GlassboxRoutes;
|
|
334
190
|
|
|
335
|
-
export {
|
|
191
|
+
export { COUNTERFACTUAL_MAX_RESULTS, COUNTERFACTUAL_MIN_SAVINGS_RATIO, type ComputeCounterfactualsArgs, type GlassboxRoutes, type GlassboxRoutesConfig, TraceCounterfactual, TraceDetail, TraceSummary, computeCounterfactuals, createGlassboxRoutes, rowToDetail, rowToSummary };
|
|
@@ -1,153 +1,9 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
import {
|
|
1
|
+
import { G as GlassboxEvent } from '../types-CsFP-H-U.js';
|
|
2
|
+
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-HEl2tS4P.js';
|
|
3
|
+
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-HEl2tS4P.js';
|
|
4
|
+
import '../ir-CZ9Ng96k.js';
|
|
3
5
|
import '../dialect.js';
|
|
4
6
|
|
|
5
|
-
/**
|
|
6
|
-
* Internal config + hook types for createGlassboxRoutes().
|
|
7
|
-
*
|
|
8
|
-
* The public contract lives on `GlassboxRoutesConfig` in ./index.ts; these
|
|
9
|
-
* are the narrower per-handler shapes consumed by proxy.ts and stream.ts.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Wire contract for the Glass-Box Chrome extension's brain-poll endpoint.
|
|
14
|
-
*
|
|
15
|
-
* The list mode of `proxy(req)` returns `{ traces: TraceSummary[] }`. The
|
|
16
|
-
* detail mode (`?traceId=<id>`) returns a single `TraceDetail`. These are
|
|
17
|
-
* the camelCase shapes the extension renderer expects — distinct from the
|
|
18
|
-
* snake_case `compile_outcomes` row shape that PostgREST returns. The
|
|
19
|
-
* factory's typed `rowToSummary` / `rowToDetail` transformer is the single
|
|
20
|
-
* canonical boundary between the DB shape and the wire shape (see
|
|
21
|
-
* `feedback_typed_boundary_transformers.md` in kgauto memory for the rule).
|
|
22
|
-
*/
|
|
23
|
-
interface TraceSummary {
|
|
24
|
-
traceId: string;
|
|
25
|
-
appId: string;
|
|
26
|
-
archetype: string;
|
|
27
|
-
target: string;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
tokensIn: number;
|
|
30
|
-
tokensOut: number;
|
|
31
|
-
estimatedCostUsd: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface AdvisoryRecord {
|
|
35
|
-
level: 'info' | 'warn' | 'critical';
|
|
36
|
-
/** Stable advisory identifier, e.g. "caching-off-on-claude". */
|
|
37
|
-
code: string;
|
|
38
|
-
/** Consumer-renderable message — no internal jargon ("L-040", "R3" etc.). */
|
|
39
|
-
message: string;
|
|
40
|
-
/** Optional secondary one-liner. Renders below `message` in italics. */
|
|
41
|
-
suggestion?: string;
|
|
42
|
-
/** Deep link to the relevant section of `interfaces/kgauto.md` or docs. */
|
|
43
|
-
docsUrl?: string;
|
|
44
|
-
/**
|
|
45
|
-
* alpha.28+ — closed-union adaptation hint surfaced by the advisor when
|
|
46
|
-
* the advisory can be auto-mitigated by a config knob. Renderer surfaces
|
|
47
|
-
* as `→ try toolOrchestration: 'sequential'` on the advisory row.
|
|
48
|
-
*
|
|
49
|
-
* MUST stay byte-identical to Builder C's
|
|
50
|
-
* `BestPracticeAdvisory.suggestedAdaptation` shape (verified at Phase 2
|
|
51
|
-
* integration; the Adapter type itself is the contract).
|
|
52
|
-
*/
|
|
53
|
-
suggestedAdaptation?: Adapter;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Cost-equivalent alternative the chain could have served. Computed at
|
|
57
|
-
* detail-view time by `computeCounterfactuals()` against the served row's
|
|
58
|
-
* observed token counts + archetype + cache state. Up to 2 entries, sorted
|
|
59
|
-
* cheapest first.
|
|
60
|
-
*/
|
|
61
|
-
interface TraceCounterfactual {
|
|
62
|
-
modelId: string;
|
|
63
|
-
estimatedCostUsd: number;
|
|
64
|
-
/** servedCostUsd - estimatedCostUsd (always > 0; only ≥10% savings kept). */
|
|
65
|
-
savingsUsd: number;
|
|
66
|
-
/** 0-100. */
|
|
67
|
-
savingsPercent: number;
|
|
68
|
-
/** Plain-English rationale tying archetype + perf score. */
|
|
69
|
-
reason: string;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Derived axis-health tri-state for the three Glass-Box dots
|
|
73
|
-
* (input-ratio · cache · fallback). Renderer reads; transformer computes.
|
|
74
|
-
*
|
|
75
|
-
* Thresholds (locked in design contract Phase 0):
|
|
76
|
-
* - inputRatio: green ≤ 0.65 · yellow 0.65–0.85 · red > 0.85
|
|
77
|
-
* - cache (only when historyCacheableTokens > 1000):
|
|
78
|
-
* green if inputCacheHitRatio ≥ 0.5
|
|
79
|
-
* yellow if 0.1 ≤ inputCacheHitRatio < 0.5
|
|
80
|
-
* red if inputCacheHitRatio < 0.1
|
|
81
|
-
* na if historyCacheableTokens ≤ 1000
|
|
82
|
-
* - fallback: red iff fellOverFrom !== undefined && fellOverFrom !== target
|
|
83
|
-
*/
|
|
84
|
-
interface TraceHealth {
|
|
85
|
-
inputRatioStatus: 'green' | 'yellow' | 'red';
|
|
86
|
-
cacheStatus: 'green' | 'yellow' | 'red' | 'na';
|
|
87
|
-
fallbackStatus: 'green' | 'red';
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* alpha.29+ — wire-boundary representation of a translator section-rewrite.
|
|
91
|
-
*
|
|
92
|
-
* Distinct from the package-internal `SectionRewrite` type in `ir.ts`: this
|
|
93
|
-
* shape drops `originalText` + `transformedText` because those may carry
|
|
94
|
-
* consumer PII. The renderer shows the `rule` + `summary` only. Full text
|
|
95
|
-
* stays on `compile_outcomes.section_rewrites_applied` (Supabase row), gated
|
|
96
|
-
* by RLS for brain-side cross-app learning.
|
|
97
|
-
*/
|
|
98
|
-
interface TraceSectionRewrite {
|
|
99
|
-
/** Stable id of the rewritten section. */
|
|
100
|
-
sectionId: string;
|
|
101
|
-
/** Section-kind discriminator that triggered the rewrite. */
|
|
102
|
-
kind: SectionKind;
|
|
103
|
-
/** Stable rule identifier (e.g. `'sequential-tool-cliff-below-floor'`). */
|
|
104
|
-
rule: string;
|
|
105
|
-
/**
|
|
106
|
-
* Plain-English one-liner describing what fired and why. Renderer surfaces
|
|
107
|
-
* this on the Coaching card; no internal jargon ("L-040", "below floor").
|
|
108
|
-
*/
|
|
109
|
-
summary: string;
|
|
110
|
-
}
|
|
111
|
-
interface TraceDetail extends TraceSummary {
|
|
112
|
-
mutationsApplied: string[];
|
|
113
|
-
advisories: AdvisoryRecord[];
|
|
114
|
-
rawRequest?: string;
|
|
115
|
-
rawResponse?: string;
|
|
116
|
-
/** Set when consumer passed a forceModel / fallback fired. */
|
|
117
|
-
requestedModel?: string;
|
|
118
|
-
/** Provider finish reason — 'stop' / 'max_tokens' / 'tool_use' / etc. */
|
|
119
|
-
finishReason?: string;
|
|
120
|
-
/** Time to first token (ms); populated when provider surfaces it. */
|
|
121
|
-
ttftMs?: number;
|
|
122
|
-
/** End-to-end wall-clock (ms); from migration 018. */
|
|
123
|
-
totalMs?: number;
|
|
124
|
-
/** Tools kept after relevance pass. */
|
|
125
|
-
toolsCount?: number;
|
|
126
|
-
/** Number of history messages at compile time. */
|
|
127
|
-
historyDepth?: number;
|
|
128
|
-
/** Rendered system prompt size in characters. */
|
|
129
|
-
systemPromptChars?: number;
|
|
130
|
-
cacheReadInputTokens: number;
|
|
131
|
-
cacheCreationInputTokens: number;
|
|
132
|
-
historyCacheableTokens: number;
|
|
133
|
-
/** Derived: cacheReadInputTokens / max(tokensIn, 1). 0-1. */
|
|
134
|
-
inputCacheHitRatio: number;
|
|
135
|
-
fellOverFrom?: string;
|
|
136
|
-
fallbackReason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
|
|
137
|
-
/** Up to 2 alternatives. Empty array (not undefined) when none qualify. */
|
|
138
|
-
counterfactuals?: TraceCounterfactual[];
|
|
139
|
-
/** Undefined when 7d volume < 5/day (insufficient data). */
|
|
140
|
-
projectedDailyCostUsd?: number;
|
|
141
|
-
/**
|
|
142
|
-
* alpha.29+ — translator activity for this trace. Empty array (not
|
|
143
|
-
* undefined) when no rewrites fired or pre-019 row. Surfaced in the
|
|
144
|
-
* Glass-Box Coaching card as synthetic info-level rows. PII-safe by
|
|
145
|
-
* construction: only sectionId + kind + rule + summary cross the wire.
|
|
146
|
-
*/
|
|
147
|
-
sectionRewritesApplied: TraceSectionRewrite[];
|
|
148
|
-
health: TraceHealth;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
7
|
/**
|
|
152
8
|
* proxy(req) — Glass-Box replay query handler.
|
|
153
9
|
*
|
|
@@ -332,4 +188,4 @@ interface GlassboxRoutes {
|
|
|
332
188
|
}
|
|
333
189
|
declare function createGlassboxRoutes(config: GlassboxRoutesConfig): GlassboxRoutes;
|
|
334
190
|
|
|
335
|
-
export {
|
|
191
|
+
export { COUNTERFACTUAL_MAX_RESULTS, COUNTERFACTUAL_MIN_SAVINGS_RATIO, type ComputeCounterfactualsArgs, type GlassboxRoutes, type GlassboxRoutesConfig, TraceCounterfactual, TraceDetail, TraceSummary, computeCounterfactuals, createGlassboxRoutes, rowToDetail, rowToSummary };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { a as TraceDetail } from '../../types-kzYpX7wB.mjs';
|
|
3
|
+
import '../../ir-BiZSAVCJ.mjs';
|
|
4
|
+
import '../../dialect.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GlassboxTheme — visual tokens consumed by <GlassboxTraceCard>.
|
|
8
|
+
*
|
|
9
|
+
* Pass via `theme` prop to override the neutral default with your dashboard's
|
|
10
|
+
* design system. All 14 tokens are required; spread the default and override
|
|
11
|
+
* what you need:
|
|
12
|
+
*
|
|
13
|
+
* import { DEFAULT_GLASSBOX_THEME } from '@warmdrift/kgauto-compiler/glassbox-routes/react';
|
|
14
|
+
* const myTheme = { ...DEFAULT_GLASSBOX_THEME, colors: { ...DEFAULT_GLASSBOX_THEME.colors, warn: '#C75B7A' } };
|
|
15
|
+
*
|
|
16
|
+
* The default is a deliberately neutral cool slate palette + system fonts —
|
|
17
|
+
* NOT tt-intelligence's warm brand. Consumers should override with their own
|
|
18
|
+
* brand tokens; the substrate stays brand-agnostic.
|
|
19
|
+
*/
|
|
20
|
+
interface GlassboxThemeColors {
|
|
21
|
+
/** Page/section background (behind cards). */
|
|
22
|
+
surface: string;
|
|
23
|
+
/** Card / row border. */
|
|
24
|
+
border: string;
|
|
25
|
+
/** Softer border for inner dividers. */
|
|
26
|
+
borderSoft: string;
|
|
27
|
+
/** Card background. */
|
|
28
|
+
cardBg: string;
|
|
29
|
+
/** Primary text. */
|
|
30
|
+
text: string;
|
|
31
|
+
/** Secondary text (labels, metadata). */
|
|
32
|
+
textMuted: string;
|
|
33
|
+
/** Tertiary text (annotations). */
|
|
34
|
+
textFaint: string;
|
|
35
|
+
/** Healthy / success state marker. */
|
|
36
|
+
ok: string;
|
|
37
|
+
/** Warning / borderline / coaching state marker. Reserved for state, not decoration. */
|
|
38
|
+
warn: string;
|
|
39
|
+
/** Failure / error state marker. */
|
|
40
|
+
fail: string;
|
|
41
|
+
/** Informational state marker (advisory link, counterfactual). */
|
|
42
|
+
info: string;
|
|
43
|
+
}
|
|
44
|
+
interface GlassboxThemeFonts {
|
|
45
|
+
/** UI sans-serif stack. */
|
|
46
|
+
sans: string;
|
|
47
|
+
/** Display / heading stack. */
|
|
48
|
+
serif: string;
|
|
49
|
+
/** Monospace stack for IDs, traceIds, raw payloads. */
|
|
50
|
+
mono: string;
|
|
51
|
+
}
|
|
52
|
+
interface GlassboxTheme {
|
|
53
|
+
colors: GlassboxThemeColors;
|
|
54
|
+
fonts: GlassboxThemeFonts;
|
|
55
|
+
}
|
|
56
|
+
declare const DEFAULT_GLASSBOX_THEME: GlassboxTheme;
|
|
57
|
+
|
|
58
|
+
interface GlassboxTraceCardProps {
|
|
59
|
+
detail: TraceDetail;
|
|
60
|
+
/**
|
|
61
|
+
* Optional theme override. Defaults to a neutral cool slate palette + system
|
|
62
|
+
* fonts (NOT tt-intelligence's warm brand). Consumer dashboards should pass
|
|
63
|
+
* their own design tokens.
|
|
64
|
+
*/
|
|
65
|
+
theme?: GlassboxTheme;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Render one TraceDetail as a stacked-card view. Server component (no
|
|
69
|
+
* client JS). Cards with empty data hide automatically per the alpha.28
|
|
70
|
+
* design contract.
|
|
71
|
+
*/
|
|
72
|
+
declare function GlassboxTraceCard({ detail, theme, }: GlassboxTraceCardProps): react_jsx_runtime.JSX.Element;
|
|
73
|
+
|
|
74
|
+
export { DEFAULT_GLASSBOX_THEME, type GlassboxTheme, type GlassboxThemeColors, type GlassboxThemeFonts, GlassboxTraceCard, type GlassboxTraceCardProps };
|