@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
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-
|
|
2
|
-
export { m as CallAttempt, n as CallError, o as ChainWithGrounding, p as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, q as MutationApplied, r as NormalizedTokens, s as OutcomeKind, t as PerAxisMetricsByModel, u as PromptSection, v as SectionKind, T as ToolCall, w as ToolDefinition } from './ir-
|
|
1
|
+
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-BiZSAVCJ.mjs';
|
|
2
|
+
export { m as CallAttempt, n as CallError, o as ChainWithGrounding, p as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, q as MutationApplied, r as NormalizedTokens, s as OutcomeKind, t as PerAxisMetricsByModel, u as PromptSection, v as SectionKind, T as ToolCall, w as ToolDefinition } from './ir-BiZSAVCJ.mjs';
|
|
3
3
|
import { ModelProfile } from './profiles.mjs';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, profilesByProvider, tryGetProfile } from './profiles.mjs';
|
|
5
5
|
import { IntentArchetypeName } from './dialect.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-
|
|
2
|
-
export { m as CallAttempt, n as CallError, o as ChainWithGrounding, p as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, q as MutationApplied, r as NormalizedTokens, s as OutcomeKind, t as PerAxisMetricsByModel, u as PromptSection, v as SectionKind, T as ToolCall, w as ToolDefinition } from './ir-
|
|
1
|
+
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-CZ9Ng96k.js';
|
|
2
|
+
export { m as CallAttempt, n as CallError, o as ChainWithGrounding, p as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, q as MutationApplied, r as NormalizedTokens, s as OutcomeKind, t as PerAxisMetricsByModel, u as PromptSection, v as SectionKind, T as ToolCall, w as ToolDefinition } from './ir-CZ9Ng96k.js';
|
|
3
3
|
import { ModelProfile } from './profiles.js';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, profilesByProvider, tryGetProfile } from './profiles.js';
|
|
5
5
|
import { IntentArchetypeName } from './dialect.js';
|
|
@@ -398,6 +398,26 @@ interface BestPracticeAdvisory {
|
|
|
398
398
|
* - `'architecture-change'` — the issue isn't fixable at the kgauto layer
|
|
399
399
|
*/
|
|
400
400
|
recommendationType?: 'model-swap' | 'prompt-fix' | 'caching-fix' | 'no-ai-needed' | 'tier-down' | 'architecture-change';
|
|
401
|
+
/**
|
|
402
|
+
* alpha.36 — architectural recommendation when the call shouldn't be an
|
|
403
|
+
* AI call at all, or should be a cheaper non-AI substitute. Optional and
|
|
404
|
+
* orthogonal to {@link recommendationType}: when set, narrows the
|
|
405
|
+
* `no-ai-needed` / `architecture-change` rec-type into an actionable
|
|
406
|
+
* pattern the consumer can implement.
|
|
407
|
+
*
|
|
408
|
+
* - `'lookup-table'` — deterministic input → output mapping (≥95% agreement at high N). Build a domain table; fall back to AI for novel inputs.
|
|
409
|
+
* - `'memoization-cache'` — same canonical input recurs across sessions with equivalent output. Add an edge/KV cache keyed on canonical input.
|
|
410
|
+
* - `'tier-down'` — cheaper model tier delivers equal-or-better oracle score on this shape. Move primary to the cheaper tier.
|
|
411
|
+
* - `'deterministic-parser'` — `constraints.structuredOutput: true` calls where the schema is regex/JSON-extractable from the input.
|
|
412
|
+
* - `'precompute'` — input is derivable at build / cron / batch time; eliminate the per-request call entirely.
|
|
413
|
+
*
|
|
414
|
+
* Operator-side detection lives in `v2/scripts/no-ai-needed-detector.mjs`
|
|
415
|
+
* (alpha.36); a compile-time advisor rule that consumes the brain-side
|
|
416
|
+
* findings cache follows in a later alpha. Today populated only by the
|
|
417
|
+
* operator-side detector + the brain RPC `get_no_ai_needed_candidates`
|
|
418
|
+
* (migration 021).
|
|
419
|
+
*/
|
|
420
|
+
recommendedArchitecture?: 'lookup-table' | 'memoization-cache' | 'tier-down' | 'deterministic-parser' | 'precompute';
|
|
401
421
|
/**
|
|
402
422
|
* alpha.28 — when a rule wants to surface a specific structural adaptation
|
|
403
423
|
* (not just a swap or a prompt fix), it attaches the adapter shape here.
|
|
@@ -398,6 +398,26 @@ interface BestPracticeAdvisory {
|
|
|
398
398
|
* - `'architecture-change'` — the issue isn't fixable at the kgauto layer
|
|
399
399
|
*/
|
|
400
400
|
recommendationType?: 'model-swap' | 'prompt-fix' | 'caching-fix' | 'no-ai-needed' | 'tier-down' | 'architecture-change';
|
|
401
|
+
/**
|
|
402
|
+
* alpha.36 — architectural recommendation when the call shouldn't be an
|
|
403
|
+
* AI call at all, or should be a cheaper non-AI substitute. Optional and
|
|
404
|
+
* orthogonal to {@link recommendationType}: when set, narrows the
|
|
405
|
+
* `no-ai-needed` / `architecture-change` rec-type into an actionable
|
|
406
|
+
* pattern the consumer can implement.
|
|
407
|
+
*
|
|
408
|
+
* - `'lookup-table'` — deterministic input → output mapping (≥95% agreement at high N). Build a domain table; fall back to AI for novel inputs.
|
|
409
|
+
* - `'memoization-cache'` — same canonical input recurs across sessions with equivalent output. Add an edge/KV cache keyed on canonical input.
|
|
410
|
+
* - `'tier-down'` — cheaper model tier delivers equal-or-better oracle score on this shape. Move primary to the cheaper tier.
|
|
411
|
+
* - `'deterministic-parser'` — `constraints.structuredOutput: true` calls where the schema is regex/JSON-extractable from the input.
|
|
412
|
+
* - `'precompute'` — input is derivable at build / cron / batch time; eliminate the per-request call entirely.
|
|
413
|
+
*
|
|
414
|
+
* Operator-side detection lives in `v2/scripts/no-ai-needed-detector.mjs`
|
|
415
|
+
* (alpha.36); a compile-time advisor rule that consumes the brain-side
|
|
416
|
+
* findings cache follows in a later alpha. Today populated only by the
|
|
417
|
+
* operator-side detector + the brain RPC `get_no_ai_needed_candidates`
|
|
418
|
+
* (migration 021).
|
|
419
|
+
*/
|
|
420
|
+
recommendedArchitecture?: 'lookup-table' | 'memoization-cache' | 'tier-down' | 'deterministic-parser' | 'precompute';
|
|
401
421
|
/**
|
|
402
422
|
* alpha.28 — when a rule wants to surface a specific structural adaptation
|
|
403
423
|
* (not just a swap or a prompt fix), it attaches the adapter shape here.
|
package/dist/profiles.d.mts
CHANGED
package/dist/profiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { q as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-
|
|
1
|
+
import { q as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-CZ9Ng96k.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Glass-Box observability types (alpha.17).
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { i as Adapter, v as SectionKind } from './ir-CZ9Ng96k.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal config + hook types for createGlassboxRoutes().
|
|
5
|
+
*
|
|
6
|
+
* The public contract lives on `GlassboxRoutesConfig` in ./index.ts; these
|
|
7
|
+
* are the narrower per-handler shapes consumed by proxy.ts and stream.ts.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wire contract for the Glass-Box Chrome extension's brain-poll endpoint.
|
|
12
|
+
*
|
|
13
|
+
* The list mode of `proxy(req)` returns `{ traces: TraceSummary[] }`. The
|
|
14
|
+
* detail mode (`?traceId=<id>`) returns a single `TraceDetail`. These are
|
|
15
|
+
* the camelCase shapes the extension renderer expects — distinct from the
|
|
16
|
+
* snake_case `compile_outcomes` row shape that PostgREST returns. The
|
|
17
|
+
* factory's typed `rowToSummary` / `rowToDetail` transformer is the single
|
|
18
|
+
* canonical boundary between the DB shape and the wire shape (see
|
|
19
|
+
* `feedback_typed_boundary_transformers.md` in kgauto memory for the rule).
|
|
20
|
+
*/
|
|
21
|
+
interface TraceSummary {
|
|
22
|
+
traceId: string;
|
|
23
|
+
appId: string;
|
|
24
|
+
archetype: string;
|
|
25
|
+
target: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
tokensIn: number;
|
|
28
|
+
tokensOut: number;
|
|
29
|
+
estimatedCostUsd: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface AdvisoryRecord {
|
|
33
|
+
level: 'info' | 'warn' | 'critical';
|
|
34
|
+
/** Stable advisory identifier, e.g. "caching-off-on-claude". */
|
|
35
|
+
code: string;
|
|
36
|
+
/** Consumer-renderable message — no internal jargon ("L-040", "R3" etc.). */
|
|
37
|
+
message: string;
|
|
38
|
+
/** Optional secondary one-liner. Renders below `message` in italics. */
|
|
39
|
+
suggestion?: string;
|
|
40
|
+
/** Deep link to the relevant section of `interfaces/kgauto.md` or docs. */
|
|
41
|
+
docsUrl?: string;
|
|
42
|
+
/**
|
|
43
|
+
* alpha.28+ — closed-union adaptation hint surfaced by the advisor when
|
|
44
|
+
* the advisory can be auto-mitigated by a config knob. Renderer surfaces
|
|
45
|
+
* as `→ try toolOrchestration: 'sequential'` on the advisory row.
|
|
46
|
+
*
|
|
47
|
+
* MUST stay byte-identical to Builder C's
|
|
48
|
+
* `BestPracticeAdvisory.suggestedAdaptation` shape (verified at Phase 2
|
|
49
|
+
* integration; the Adapter type itself is the contract).
|
|
50
|
+
*/
|
|
51
|
+
suggestedAdaptation?: Adapter;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Cost-equivalent alternative the chain could have served. Computed at
|
|
55
|
+
* detail-view time by `computeCounterfactuals()` against the served row's
|
|
56
|
+
* observed token counts + archetype + cache state. Up to 2 entries, sorted
|
|
57
|
+
* cheapest first.
|
|
58
|
+
*/
|
|
59
|
+
interface TraceCounterfactual {
|
|
60
|
+
modelId: string;
|
|
61
|
+
estimatedCostUsd: number;
|
|
62
|
+
/** servedCostUsd - estimatedCostUsd (always > 0; only ≥10% savings kept). */
|
|
63
|
+
savingsUsd: number;
|
|
64
|
+
/** 0-100. */
|
|
65
|
+
savingsPercent: number;
|
|
66
|
+
/** Plain-English rationale tying archetype + perf score. */
|
|
67
|
+
reason: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Derived axis-health tri-state for the three Glass-Box dots
|
|
71
|
+
* (input-ratio · cache · fallback). Renderer reads; transformer computes.
|
|
72
|
+
*
|
|
73
|
+
* Thresholds (locked in design contract Phase 0):
|
|
74
|
+
* - inputRatio: green ≤ 0.65 · yellow 0.65–0.85 · red > 0.85
|
|
75
|
+
* - cache (only when historyCacheableTokens > 1000):
|
|
76
|
+
* green if inputCacheHitRatio ≥ 0.5
|
|
77
|
+
* yellow if 0.1 ≤ inputCacheHitRatio < 0.5
|
|
78
|
+
* red if inputCacheHitRatio < 0.1
|
|
79
|
+
* na if historyCacheableTokens ≤ 1000
|
|
80
|
+
* - fallback: red iff fellOverFrom !== undefined && fellOverFrom !== target
|
|
81
|
+
*/
|
|
82
|
+
interface TraceHealth {
|
|
83
|
+
inputRatioStatus: 'green' | 'yellow' | 'red';
|
|
84
|
+
cacheStatus: 'green' | 'yellow' | 'red' | 'na';
|
|
85
|
+
fallbackStatus: 'green' | 'red';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* alpha.29+ — wire-boundary representation of a translator section-rewrite.
|
|
89
|
+
*
|
|
90
|
+
* Distinct from the package-internal `SectionRewrite` type in `ir.ts`: this
|
|
91
|
+
* shape drops `originalText` + `transformedText` because those may carry
|
|
92
|
+
* consumer PII. The renderer shows the `rule` + `summary` only. Full text
|
|
93
|
+
* stays on `compile_outcomes.section_rewrites_applied` (Supabase row), gated
|
|
94
|
+
* by RLS for brain-side cross-app learning.
|
|
95
|
+
*/
|
|
96
|
+
interface TraceSectionRewrite {
|
|
97
|
+
/** Stable id of the rewritten section. */
|
|
98
|
+
sectionId: string;
|
|
99
|
+
/** Section-kind discriminator that triggered the rewrite. */
|
|
100
|
+
kind: SectionKind;
|
|
101
|
+
/** Stable rule identifier (e.g. `'sequential-tool-cliff-below-floor'`). */
|
|
102
|
+
rule: string;
|
|
103
|
+
/**
|
|
104
|
+
* Plain-English one-liner describing what fired and why. Renderer surfaces
|
|
105
|
+
* this on the Coaching card; no internal jargon ("L-040", "below floor").
|
|
106
|
+
*/
|
|
107
|
+
summary: string;
|
|
108
|
+
}
|
|
109
|
+
interface TraceDetail extends TraceSummary {
|
|
110
|
+
mutationsApplied: string[];
|
|
111
|
+
advisories: AdvisoryRecord[];
|
|
112
|
+
rawRequest?: string;
|
|
113
|
+
rawResponse?: string;
|
|
114
|
+
/** Set when consumer passed a forceModel / fallback fired. */
|
|
115
|
+
requestedModel?: string;
|
|
116
|
+
/** Provider finish reason — 'stop' / 'max_tokens' / 'tool_use' / etc. */
|
|
117
|
+
finishReason?: string;
|
|
118
|
+
/** Time to first token (ms); populated when provider surfaces it. */
|
|
119
|
+
ttftMs?: number;
|
|
120
|
+
/** End-to-end wall-clock (ms); from migration 018. */
|
|
121
|
+
totalMs?: number;
|
|
122
|
+
/** Tools kept after relevance pass. */
|
|
123
|
+
toolsCount?: number;
|
|
124
|
+
/** Number of history messages at compile time. */
|
|
125
|
+
historyDepth?: number;
|
|
126
|
+
/** Rendered system prompt size in characters. */
|
|
127
|
+
systemPromptChars?: number;
|
|
128
|
+
cacheReadInputTokens: number;
|
|
129
|
+
cacheCreationInputTokens: number;
|
|
130
|
+
historyCacheableTokens: number;
|
|
131
|
+
/** Derived: cacheReadInputTokens / max(tokensIn, 1). 0-1. */
|
|
132
|
+
inputCacheHitRatio: number;
|
|
133
|
+
fellOverFrom?: string;
|
|
134
|
+
fallbackReason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
|
|
135
|
+
/** Up to 2 alternatives. Empty array (not undefined) when none qualify. */
|
|
136
|
+
counterfactuals?: TraceCounterfactual[];
|
|
137
|
+
/** Undefined when 7d volume < 5/day (insufficient data). */
|
|
138
|
+
projectedDailyCostUsd?: number;
|
|
139
|
+
/**
|
|
140
|
+
* alpha.29+ — translator activity for this trace. Empty array (not
|
|
141
|
+
* undefined) when no rewrites fired or pre-019 row. Surfaced in the
|
|
142
|
+
* Glass-Box Coaching card as synthetic info-level rows. PII-safe by
|
|
143
|
+
* construction: only sectionId + kind + rule + summary cross the wire.
|
|
144
|
+
*/
|
|
145
|
+
sectionRewritesApplied: TraceSectionRewrite[];
|
|
146
|
+
health: TraceHealth;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type { AdvisoryRecord as A, TraceHealth as T, TraceDetail as a, TraceSummary as b, TraceCounterfactual as c, TraceSectionRewrite as d };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { q as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-
|
|
1
|
+
import { q as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-BiZSAVCJ.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Glass-Box observability types (alpha.17).
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { i as Adapter, v as SectionKind } from './ir-BiZSAVCJ.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal config + hook types for createGlassboxRoutes().
|
|
5
|
+
*
|
|
6
|
+
* The public contract lives on `GlassboxRoutesConfig` in ./index.ts; these
|
|
7
|
+
* are the narrower per-handler shapes consumed by proxy.ts and stream.ts.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wire contract for the Glass-Box Chrome extension's brain-poll endpoint.
|
|
12
|
+
*
|
|
13
|
+
* The list mode of `proxy(req)` returns `{ traces: TraceSummary[] }`. The
|
|
14
|
+
* detail mode (`?traceId=<id>`) returns a single `TraceDetail`. These are
|
|
15
|
+
* the camelCase shapes the extension renderer expects — distinct from the
|
|
16
|
+
* snake_case `compile_outcomes` row shape that PostgREST returns. The
|
|
17
|
+
* factory's typed `rowToSummary` / `rowToDetail` transformer is the single
|
|
18
|
+
* canonical boundary between the DB shape and the wire shape (see
|
|
19
|
+
* `feedback_typed_boundary_transformers.md` in kgauto memory for the rule).
|
|
20
|
+
*/
|
|
21
|
+
interface TraceSummary {
|
|
22
|
+
traceId: string;
|
|
23
|
+
appId: string;
|
|
24
|
+
archetype: string;
|
|
25
|
+
target: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
tokensIn: number;
|
|
28
|
+
tokensOut: number;
|
|
29
|
+
estimatedCostUsd: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface AdvisoryRecord {
|
|
33
|
+
level: 'info' | 'warn' | 'critical';
|
|
34
|
+
/** Stable advisory identifier, e.g. "caching-off-on-claude". */
|
|
35
|
+
code: string;
|
|
36
|
+
/** Consumer-renderable message — no internal jargon ("L-040", "R3" etc.). */
|
|
37
|
+
message: string;
|
|
38
|
+
/** Optional secondary one-liner. Renders below `message` in italics. */
|
|
39
|
+
suggestion?: string;
|
|
40
|
+
/** Deep link to the relevant section of `interfaces/kgauto.md` or docs. */
|
|
41
|
+
docsUrl?: string;
|
|
42
|
+
/**
|
|
43
|
+
* alpha.28+ — closed-union adaptation hint surfaced by the advisor when
|
|
44
|
+
* the advisory can be auto-mitigated by a config knob. Renderer surfaces
|
|
45
|
+
* as `→ try toolOrchestration: 'sequential'` on the advisory row.
|
|
46
|
+
*
|
|
47
|
+
* MUST stay byte-identical to Builder C's
|
|
48
|
+
* `BestPracticeAdvisory.suggestedAdaptation` shape (verified at Phase 2
|
|
49
|
+
* integration; the Adapter type itself is the contract).
|
|
50
|
+
*/
|
|
51
|
+
suggestedAdaptation?: Adapter;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Cost-equivalent alternative the chain could have served. Computed at
|
|
55
|
+
* detail-view time by `computeCounterfactuals()` against the served row's
|
|
56
|
+
* observed token counts + archetype + cache state. Up to 2 entries, sorted
|
|
57
|
+
* cheapest first.
|
|
58
|
+
*/
|
|
59
|
+
interface TraceCounterfactual {
|
|
60
|
+
modelId: string;
|
|
61
|
+
estimatedCostUsd: number;
|
|
62
|
+
/** servedCostUsd - estimatedCostUsd (always > 0; only ≥10% savings kept). */
|
|
63
|
+
savingsUsd: number;
|
|
64
|
+
/** 0-100. */
|
|
65
|
+
savingsPercent: number;
|
|
66
|
+
/** Plain-English rationale tying archetype + perf score. */
|
|
67
|
+
reason: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Derived axis-health tri-state for the three Glass-Box dots
|
|
71
|
+
* (input-ratio · cache · fallback). Renderer reads; transformer computes.
|
|
72
|
+
*
|
|
73
|
+
* Thresholds (locked in design contract Phase 0):
|
|
74
|
+
* - inputRatio: green ≤ 0.65 · yellow 0.65–0.85 · red > 0.85
|
|
75
|
+
* - cache (only when historyCacheableTokens > 1000):
|
|
76
|
+
* green if inputCacheHitRatio ≥ 0.5
|
|
77
|
+
* yellow if 0.1 ≤ inputCacheHitRatio < 0.5
|
|
78
|
+
* red if inputCacheHitRatio < 0.1
|
|
79
|
+
* na if historyCacheableTokens ≤ 1000
|
|
80
|
+
* - fallback: red iff fellOverFrom !== undefined && fellOverFrom !== target
|
|
81
|
+
*/
|
|
82
|
+
interface TraceHealth {
|
|
83
|
+
inputRatioStatus: 'green' | 'yellow' | 'red';
|
|
84
|
+
cacheStatus: 'green' | 'yellow' | 'red' | 'na';
|
|
85
|
+
fallbackStatus: 'green' | 'red';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* alpha.29+ — wire-boundary representation of a translator section-rewrite.
|
|
89
|
+
*
|
|
90
|
+
* Distinct from the package-internal `SectionRewrite` type in `ir.ts`: this
|
|
91
|
+
* shape drops `originalText` + `transformedText` because those may carry
|
|
92
|
+
* consumer PII. The renderer shows the `rule` + `summary` only. Full text
|
|
93
|
+
* stays on `compile_outcomes.section_rewrites_applied` (Supabase row), gated
|
|
94
|
+
* by RLS for brain-side cross-app learning.
|
|
95
|
+
*/
|
|
96
|
+
interface TraceSectionRewrite {
|
|
97
|
+
/** Stable id of the rewritten section. */
|
|
98
|
+
sectionId: string;
|
|
99
|
+
/** Section-kind discriminator that triggered the rewrite. */
|
|
100
|
+
kind: SectionKind;
|
|
101
|
+
/** Stable rule identifier (e.g. `'sequential-tool-cliff-below-floor'`). */
|
|
102
|
+
rule: string;
|
|
103
|
+
/**
|
|
104
|
+
* Plain-English one-liner describing what fired and why. Renderer surfaces
|
|
105
|
+
* this on the Coaching card; no internal jargon ("L-040", "below floor").
|
|
106
|
+
*/
|
|
107
|
+
summary: string;
|
|
108
|
+
}
|
|
109
|
+
interface TraceDetail extends TraceSummary {
|
|
110
|
+
mutationsApplied: string[];
|
|
111
|
+
advisories: AdvisoryRecord[];
|
|
112
|
+
rawRequest?: string;
|
|
113
|
+
rawResponse?: string;
|
|
114
|
+
/** Set when consumer passed a forceModel / fallback fired. */
|
|
115
|
+
requestedModel?: string;
|
|
116
|
+
/** Provider finish reason — 'stop' / 'max_tokens' / 'tool_use' / etc. */
|
|
117
|
+
finishReason?: string;
|
|
118
|
+
/** Time to first token (ms); populated when provider surfaces it. */
|
|
119
|
+
ttftMs?: number;
|
|
120
|
+
/** End-to-end wall-clock (ms); from migration 018. */
|
|
121
|
+
totalMs?: number;
|
|
122
|
+
/** Tools kept after relevance pass. */
|
|
123
|
+
toolsCount?: number;
|
|
124
|
+
/** Number of history messages at compile time. */
|
|
125
|
+
historyDepth?: number;
|
|
126
|
+
/** Rendered system prompt size in characters. */
|
|
127
|
+
systemPromptChars?: number;
|
|
128
|
+
cacheReadInputTokens: number;
|
|
129
|
+
cacheCreationInputTokens: number;
|
|
130
|
+
historyCacheableTokens: number;
|
|
131
|
+
/** Derived: cacheReadInputTokens / max(tokensIn, 1). 0-1. */
|
|
132
|
+
inputCacheHitRatio: number;
|
|
133
|
+
fellOverFrom?: string;
|
|
134
|
+
fallbackReason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
|
|
135
|
+
/** Up to 2 alternatives. Empty array (not undefined) when none qualify. */
|
|
136
|
+
counterfactuals?: TraceCounterfactual[];
|
|
137
|
+
/** Undefined when 7d volume < 5/day (insufficient data). */
|
|
138
|
+
projectedDailyCostUsd?: number;
|
|
139
|
+
/**
|
|
140
|
+
* alpha.29+ — translator activity for this trace. Empty array (not
|
|
141
|
+
* undefined) when no rewrites fired or pre-019 row. Surfaced in the
|
|
142
|
+
* Glass-Box Coaching card as synthetic info-level rows. PII-safe by
|
|
143
|
+
* construction: only sectionId + kind + rule + summary cross the wire.
|
|
144
|
+
*/
|
|
145
|
+
sectionRewritesApplied: TraceSectionRewrite[];
|
|
146
|
+
health: TraceHealth;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type { AdvisoryRecord as A, TraceHealth as T, TraceDetail as a, TraceSummary as b, TraceCounterfactual as c, TraceSectionRewrite as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warmdrift/kgauto-compiler",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.36",
|
|
4
4
|
"description": "Prompt compiler + central learning brain for multi-model AI apps. Swap models without rewriting prompts.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -30,11 +30,24 @@
|
|
|
30
30
|
"types": "./dist/glassbox-routes/index.d.ts",
|
|
31
31
|
"import": "./dist/glassbox-routes/index.mjs",
|
|
32
32
|
"require": "./dist/glassbox-routes/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./glassbox-routes/format": {
|
|
35
|
+
"types": "./dist/glassbox-routes/format.d.ts",
|
|
36
|
+
"import": "./dist/glassbox-routes/format.mjs",
|
|
37
|
+
"require": "./dist/glassbox-routes/format.js"
|
|
38
|
+
},
|
|
39
|
+
"./glassbox-routes/react": {
|
|
40
|
+
"types": "./dist/glassbox-routes/react/index.d.ts",
|
|
41
|
+
"import": "./dist/glassbox-routes/react/index.mjs",
|
|
42
|
+
"require": "./dist/glassbox-routes/react/index.js"
|
|
33
43
|
}
|
|
34
44
|
},
|
|
35
|
-
"files": [
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
36
49
|
"scripts": {
|
|
37
|
-
"build": "tsup src/index.ts src/dialect.ts src/profiles.ts src/glassbox/index.ts src/glassbox-routes/index.ts --format cjs,esm --dts --clean",
|
|
50
|
+
"build": "tsup src/index.ts src/dialect.ts src/profiles.ts src/glassbox/index.ts src/glassbox-routes/index.ts src/glassbox-routes/format.ts src/glassbox-routes/react/index.ts --format cjs,esm --dts --clean --external react --external react-dom",
|
|
38
51
|
"test": "vitest run",
|
|
39
52
|
"test:watch": "vitest",
|
|
40
53
|
"typecheck": "tsc --noEmit",
|
|
@@ -53,15 +66,28 @@
|
|
|
53
66
|
"self-improving"
|
|
54
67
|
],
|
|
55
68
|
"license": "MIT",
|
|
56
|
-
"dependencies": {},
|
|
57
69
|
"peerDependencies": {
|
|
58
|
-
"js-tiktoken": ">=1.0.0"
|
|
70
|
+
"js-tiktoken": ">=1.0.0",
|
|
71
|
+
"react": ">=18.0.0",
|
|
72
|
+
"react-dom": ">=18.0.0"
|
|
59
73
|
},
|
|
60
74
|
"peerDependenciesMeta": {
|
|
61
|
-
"js-tiktoken": {
|
|
75
|
+
"js-tiktoken": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"react": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"react-dom": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
62
84
|
},
|
|
63
85
|
"devDependencies": {
|
|
64
86
|
"@types/node": "^22.10.0",
|
|
87
|
+
"@types/react": "^19.2.15",
|
|
88
|
+
"@types/react-dom": "^19.2.3",
|
|
89
|
+
"react": "^19.2.6",
|
|
90
|
+
"react-dom": "^19.2.6",
|
|
65
91
|
"tsup": "^8.4.0",
|
|
66
92
|
"typescript": "^5.7.0",
|
|
67
93
|
"vitest": "^3.1.0"
|