@warmdrift/kgauto-compiler 2.0.0-alpha.22 → 2.0.0-alpha.24

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,6 +1,6 @@
1
- import { G as GlassboxEvent } from '../types-zk238uNL.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-zk238uNL.mjs';
3
- import '../ir-CruZBtpK.mjs';
1
+ import { G as GlassboxEvent } from '../types-D9WndxeD.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-D9WndxeD.mjs';
3
+ import '../ir-B9zqlwjH.mjs';
4
4
  import '../dialect.mjs';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
- import { G as GlassboxEvent } from '../types-BiZKJU41.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-BiZKJU41.js';
3
- import '../ir-Wr5lc8Mi.js';
1
+ import { G as GlassboxEvent } from '../types-DiWBWvxg.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-DiWBWvxg.js';
3
+ import '../ir-B_XX2LAO.js';
4
4
  import '../dialect.js';
5
5
 
6
6
  /**
@@ -1,7 +1,42 @@
1
- import { G as GlassboxEvent } from '../types-zk238uNL.mjs';
2
- import '../ir-CruZBtpK.mjs';
1
+ import { G as GlassboxEvent } from '../types-D9WndxeD.mjs';
2
+ import '../ir-B9zqlwjH.mjs';
3
3
  import '../dialect.mjs';
4
4
 
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
+ interface TraceDetail extends TraceSummary {
34
+ mutationsApplied: unknown[];
35
+ advisories: unknown[];
36
+ rawRequest?: unknown;
37
+ rawResponse?: unknown;
38
+ }
39
+
5
40
  /**
6
41
  * Public entry point for `@warmdrift/kgauto-compiler/glassbox-routes`.
7
42
  *
@@ -12,11 +47,12 @@ import '../dialect.mjs';
12
47
  * // app/api/glassbox/proxy/route.ts
13
48
  * import { createGlassboxRoutes } from '@warmdrift/kgauto-compiler/glassbox-routes';
14
49
  * const { proxy } = createGlassboxRoutes({
15
- * installToken: process.env.GLASSBOX_INSTALL_TOKEN!,
16
- * extensionId: process.env.GLASSBOX_EXTENSION_ID!,
50
+ * installToken: process.env.GLASSBOX_INSTALL_TOKEN!,
51
+ * extensionId: process.env.GLASSBOX_EXTENSION_ID!,
17
52
  * brainEndpoint: process.env.GLASSBOX_BRAIN_ENDPOINT!,
18
- * brainJwt: process.env.GLASSBOX_BRAIN_JWT!,
19
- * appId: 'playbacksam',
53
+ * brainJwt: process.env.GLASSBOX_BRAIN_JWT!, // scoped JWT (RLS via app_id claim)
54
+ * brainAnonKey: process.env.GLASSBOX_BRAIN_ANON_KEY!, // project anon/publishable key (Supabase apikey header)
55
+ * appId: 'playbacksam',
20
56
  * });
21
57
  * export { proxy as GET };
22
58
  *
@@ -41,8 +77,21 @@ interface GlassboxRoutesConfig {
41
77
  extensionId: string;
42
78
  /** Brain endpoint base (e.g. https://kgauto-brain.supabase.co). Used by `proxy` for replay queries. */
43
79
  brainEndpoint: string;
44
- /** Scoped JWT for brain reads. Use the per-consumer JWT minted via migration 013 (claim: app_id). */
80
+ /** Scoped JWT for brain reads. Use the per-consumer JWT minted via migration 013 (claim: app_id). Drives RLS via the `app_id` claim; sent as `Authorization: Bearer <jwt>` only. */
45
81
  brainJwt: string;
82
+ /**
83
+ * Anon/publishable key for the Supabase `apikey` header. Supabase requires
84
+ * `apikey` to be one of the project's known keys (anon or service_role) —
85
+ * the scoped JWT in `brainJwt` doesn't qualify there. Pass the project's
86
+ * legacy `anon` key (JWT format, role=anon) or the modern `sb_publishable_...`
87
+ * key. Safe to expose at the wire (that's what "publishable" means).
88
+ *
89
+ * Pre-alpha.24 this was missing and `brainJwt` was used as apikey too — first
90
+ * real call always 401'd against real Supabase. Catching this required a
91
+ * pre-publish smoke against the real brain; unit tests with mocked fetch
92
+ * couldn't surface it. See L-117 in command-center/learnings.md.
93
+ */
94
+ brainAnonKey: string;
46
95
  /** App scope filter — must match the JWT's app_id claim. */
47
96
  appId: string;
48
97
  /**
@@ -70,4 +119,4 @@ interface GlassboxRoutes {
70
119
  }
71
120
  declare function createGlassboxRoutes(config: GlassboxRoutesConfig): GlassboxRoutes;
72
121
 
73
- export { type GlassboxRoutes, type GlassboxRoutesConfig, createGlassboxRoutes };
122
+ export { type GlassboxRoutes, type GlassboxRoutesConfig, type TraceDetail, type TraceSummary, createGlassboxRoutes };
@@ -1,7 +1,42 @@
1
- import { G as GlassboxEvent } from '../types-BiZKJU41.js';
2
- import '../ir-Wr5lc8Mi.js';
1
+ import { G as GlassboxEvent } from '../types-DiWBWvxg.js';
2
+ import '../ir-B_XX2LAO.js';
3
3
  import '../dialect.js';
4
4
 
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
+ interface TraceDetail extends TraceSummary {
34
+ mutationsApplied: unknown[];
35
+ advisories: unknown[];
36
+ rawRequest?: unknown;
37
+ rawResponse?: unknown;
38
+ }
39
+
5
40
  /**
6
41
  * Public entry point for `@warmdrift/kgauto-compiler/glassbox-routes`.
7
42
  *
@@ -12,11 +47,12 @@ import '../dialect.js';
12
47
  * // app/api/glassbox/proxy/route.ts
13
48
  * import { createGlassboxRoutes } from '@warmdrift/kgauto-compiler/glassbox-routes';
14
49
  * const { proxy } = createGlassboxRoutes({
15
- * installToken: process.env.GLASSBOX_INSTALL_TOKEN!,
16
- * extensionId: process.env.GLASSBOX_EXTENSION_ID!,
50
+ * installToken: process.env.GLASSBOX_INSTALL_TOKEN!,
51
+ * extensionId: process.env.GLASSBOX_EXTENSION_ID!,
17
52
  * brainEndpoint: process.env.GLASSBOX_BRAIN_ENDPOINT!,
18
- * brainJwt: process.env.GLASSBOX_BRAIN_JWT!,
19
- * appId: 'playbacksam',
53
+ * brainJwt: process.env.GLASSBOX_BRAIN_JWT!, // scoped JWT (RLS via app_id claim)
54
+ * brainAnonKey: process.env.GLASSBOX_BRAIN_ANON_KEY!, // project anon/publishable key (Supabase apikey header)
55
+ * appId: 'playbacksam',
20
56
  * });
21
57
  * export { proxy as GET };
22
58
  *
@@ -41,8 +77,21 @@ interface GlassboxRoutesConfig {
41
77
  extensionId: string;
42
78
  /** Brain endpoint base (e.g. https://kgauto-brain.supabase.co). Used by `proxy` for replay queries. */
43
79
  brainEndpoint: string;
44
- /** Scoped JWT for brain reads. Use the per-consumer JWT minted via migration 013 (claim: app_id). */
80
+ /** Scoped JWT for brain reads. Use the per-consumer JWT minted via migration 013 (claim: app_id). Drives RLS via the `app_id` claim; sent as `Authorization: Bearer <jwt>` only. */
45
81
  brainJwt: string;
82
+ /**
83
+ * Anon/publishable key for the Supabase `apikey` header. Supabase requires
84
+ * `apikey` to be one of the project's known keys (anon or service_role) —
85
+ * the scoped JWT in `brainJwt` doesn't qualify there. Pass the project's
86
+ * legacy `anon` key (JWT format, role=anon) or the modern `sb_publishable_...`
87
+ * key. Safe to expose at the wire (that's what "publishable" means).
88
+ *
89
+ * Pre-alpha.24 this was missing and `brainJwt` was used as apikey too — first
90
+ * real call always 401'd against real Supabase. Catching this required a
91
+ * pre-publish smoke against the real brain; unit tests with mocked fetch
92
+ * couldn't surface it. See L-117 in command-center/learnings.md.
93
+ */
94
+ brainAnonKey: string;
46
95
  /** App scope filter — must match the JWT's app_id claim. */
47
96
  appId: string;
48
97
  /**
@@ -70,4 +119,4 @@ interface GlassboxRoutes {
70
119
  }
71
120
  declare function createGlassboxRoutes(config: GlassboxRoutesConfig): GlassboxRoutes;
72
121
 
73
- export { type GlassboxRoutes, type GlassboxRoutesConfig, createGlassboxRoutes };
122
+ export { type GlassboxRoutes, type GlassboxRoutesConfig, type TraceDetail, type TraceSummary, createGlassboxRoutes };
@@ -48,8 +48,11 @@ function checkAuth(req, config) {
48
48
  return jsonError(401, "unauthorized");
49
49
  }
50
50
  const origin = req.headers.get("Origin") ?? "";
51
- const expected = `chrome-extension://${config.extensionId}`;
52
- if (origin !== expected) {
51
+ const xExtId = req.headers.get("X-Glassbox-Extension-Id") ?? "";
52
+ const expectedOrigin = `chrome-extension://${config.extensionId}`;
53
+ const originOk = origin === expectedOrigin;
54
+ const xExtOk = xExtId.length > 0 && tokensEqual(xExtId, config.extensionId);
55
+ if (!originOk && !xExtOk) {
53
56
  return jsonError(403, "forbidden_origin");
54
57
  }
55
58
  return null;
@@ -82,12 +85,35 @@ function parseLimit(raw) {
82
85
  if (!Number.isFinite(n) || n <= 0) return DEFAULT_LIMIT;
83
86
  return Math.min(n, MAX_LIMIT);
84
87
  }
88
+ function rowToSummary(row) {
89
+ return {
90
+ traceId: typeof row.handle === "string" ? row.handle : "",
91
+ appId: typeof row.app_id === "string" ? row.app_id : "",
92
+ archetype: typeof row.intent_archetype === "string" ? row.intent_archetype : "",
93
+ target: typeof row.model === "string" ? row.model : "",
94
+ createdAt: typeof row.created_at === "string" ? row.created_at : "",
95
+ tokensIn: typeof row.tokens_in === "number" ? row.tokens_in : 0,
96
+ tokensOut: typeof row.tokens_out === "number" ? row.tokens_out : 0,
97
+ estimatedCostUsd: typeof row.cost_usd_actual === "number" ? row.cost_usd_actual : 0
98
+ };
99
+ }
100
+ function rowToDetail(row) {
101
+ return {
102
+ ...rowToSummary(row),
103
+ mutationsApplied: Array.isArray(row.mutations_applied) ? row.mutations_applied : [],
104
+ advisories: [],
105
+ // compile_outcomes has no advisories column today
106
+ rawRequest: row.prompt_preview ?? void 0,
107
+ rawResponse: row.response_preview ?? void 0
108
+ };
109
+ }
85
110
  function createProxyHandler(config) {
86
111
  const {
87
112
  installToken,
88
113
  extensionId,
89
114
  brainEndpoint,
90
115
  brainJwt,
116
+ brainAnonKey,
91
117
  appId,
92
118
  scrub,
93
119
  fetch: fetchImpl
@@ -114,8 +140,13 @@ function createProxyHandler(config) {
114
140
  brainRes = await doFetch(brainUrl, {
115
141
  method: "GET",
116
142
  headers: {
143
+ // Authorization carries the scoped JWT — drives RLS via app_id claim.
117
144
  Authorization: `Bearer ${brainJwt}`,
118
- apikey: brainJwt,
145
+ // apikey MUST be one of the project's known keys (anon or
146
+ // service_role). Supabase rejects any other JWT here, even when
147
+ // HS256-signed with the same secret. Pre-alpha.24 this was set to
148
+ // brainJwt and silently 401'd against real Supabase. See L-117.
149
+ apikey: brainAnonKey,
119
150
  Accept: "application/json"
120
151
  }
121
152
  });
@@ -140,8 +171,15 @@ function createProxyHandler(config) {
140
171
  if (!Array.isArray(rows)) {
141
172
  return jsonError2(502, "brain_unavailable");
142
173
  }
143
- const scrubbed = rows.map((row) => applyScrub(row, scrub));
144
- return jsonResponse(200, scrubbed);
174
+ const scrubbed = rows.map(
175
+ (row) => applyScrub(row, scrub)
176
+ );
177
+ if (traceId) {
178
+ const first = scrubbed[0];
179
+ if (!first) return jsonError2(404, "not_found");
180
+ return jsonResponse(200, rowToDetail(first));
181
+ }
182
+ return jsonResponse(200, { traces: scrubbed.map(rowToSummary) });
145
183
  };
146
184
  }
147
185
 
@@ -533,12 +571,14 @@ function createGlassboxRoutes(config) {
533
571
  const extensionId = requireString("extensionId", config.extensionId);
534
572
  const brainEndpoint = requireString("brainEndpoint", config.brainEndpoint);
535
573
  const brainJwt = requireString("brainJwt", config.brainJwt);
574
+ const brainAnonKey = requireString("brainAnonKey", config.brainAnonKey);
536
575
  const appId = requireString("appId", config.appId);
537
576
  const proxy = createProxyHandler({
538
577
  installToken,
539
578
  extensionId,
540
579
  brainEndpoint,
541
580
  brainJwt,
581
+ brainAnonKey,
542
582
  appId,
543
583
  scrub: config.scrub,
544
584
  fetch: config.fetch
@@ -27,8 +27,11 @@ function checkAuth(req, config) {
27
27
  return jsonError(401, "unauthorized");
28
28
  }
29
29
  const origin = req.headers.get("Origin") ?? "";
30
- const expected = `chrome-extension://${config.extensionId}`;
31
- if (origin !== expected) {
30
+ const xExtId = req.headers.get("X-Glassbox-Extension-Id") ?? "";
31
+ const expectedOrigin = `chrome-extension://${config.extensionId}`;
32
+ const originOk = origin === expectedOrigin;
33
+ const xExtOk = xExtId.length > 0 && tokensEqual(xExtId, config.extensionId);
34
+ if (!originOk && !xExtOk) {
32
35
  return jsonError(403, "forbidden_origin");
33
36
  }
34
37
  return null;
@@ -61,12 +64,35 @@ function parseLimit(raw) {
61
64
  if (!Number.isFinite(n) || n <= 0) return DEFAULT_LIMIT;
62
65
  return Math.min(n, MAX_LIMIT);
63
66
  }
67
+ function rowToSummary(row) {
68
+ return {
69
+ traceId: typeof row.handle === "string" ? row.handle : "",
70
+ appId: typeof row.app_id === "string" ? row.app_id : "",
71
+ archetype: typeof row.intent_archetype === "string" ? row.intent_archetype : "",
72
+ target: typeof row.model === "string" ? row.model : "",
73
+ createdAt: typeof row.created_at === "string" ? row.created_at : "",
74
+ tokensIn: typeof row.tokens_in === "number" ? row.tokens_in : 0,
75
+ tokensOut: typeof row.tokens_out === "number" ? row.tokens_out : 0,
76
+ estimatedCostUsd: typeof row.cost_usd_actual === "number" ? row.cost_usd_actual : 0
77
+ };
78
+ }
79
+ function rowToDetail(row) {
80
+ return {
81
+ ...rowToSummary(row),
82
+ mutationsApplied: Array.isArray(row.mutations_applied) ? row.mutations_applied : [],
83
+ advisories: [],
84
+ // compile_outcomes has no advisories column today
85
+ rawRequest: row.prompt_preview ?? void 0,
86
+ rawResponse: row.response_preview ?? void 0
87
+ };
88
+ }
64
89
  function createProxyHandler(config) {
65
90
  const {
66
91
  installToken,
67
92
  extensionId,
68
93
  brainEndpoint,
69
94
  brainJwt,
95
+ brainAnonKey,
70
96
  appId,
71
97
  scrub,
72
98
  fetch: fetchImpl
@@ -93,8 +119,13 @@ function createProxyHandler(config) {
93
119
  brainRes = await doFetch(brainUrl, {
94
120
  method: "GET",
95
121
  headers: {
122
+ // Authorization carries the scoped JWT — drives RLS via app_id claim.
96
123
  Authorization: `Bearer ${brainJwt}`,
97
- apikey: brainJwt,
124
+ // apikey MUST be one of the project's known keys (anon or
125
+ // service_role). Supabase rejects any other JWT here, even when
126
+ // HS256-signed with the same secret. Pre-alpha.24 this was set to
127
+ // brainJwt and silently 401'd against real Supabase. See L-117.
128
+ apikey: brainAnonKey,
98
129
  Accept: "application/json"
99
130
  }
100
131
  });
@@ -119,8 +150,15 @@ function createProxyHandler(config) {
119
150
  if (!Array.isArray(rows)) {
120
151
  return jsonError2(502, "brain_unavailable");
121
152
  }
122
- const scrubbed = rows.map((row) => applyScrub(row, scrub));
123
- return jsonResponse(200, scrubbed);
153
+ const scrubbed = rows.map(
154
+ (row) => applyScrub(row, scrub)
155
+ );
156
+ if (traceId) {
157
+ const first = scrubbed[0];
158
+ if (!first) return jsonError2(404, "not_found");
159
+ return jsonResponse(200, rowToDetail(first));
160
+ }
161
+ return jsonResponse(200, { traces: scrubbed.map(rowToSummary) });
124
162
  };
125
163
  }
126
164
 
@@ -243,12 +281,14 @@ function createGlassboxRoutes(config) {
243
281
  const extensionId = requireString("extensionId", config.extensionId);
244
282
  const brainEndpoint = requireString("brainEndpoint", config.brainEndpoint);
245
283
  const brainJwt = requireString("brainJwt", config.brainJwt);
284
+ const brainAnonKey = requireString("brainAnonKey", config.brainAnonKey);
246
285
  const appId = requireString("appId", config.appId);
247
286
  const proxy = createProxyHandler({
248
287
  installToken,
249
288
  extensionId,
250
289
  brainEndpoint,
251
290
  brainJwt,
291
+ brainAnonKey,
252
292
  appId,
253
293
  scrub: config.scrub,
254
294
  fetch: config.fetch
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as Provider, i as ChainEntry, G as Grounding } from './ir-CruZBtpK.mjs';
2
- export { j as CallAttempt, k as CallError, l as ChainWithGrounding, m as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, n as MutationApplied, o as NormalizedTokens, p as OutcomeKind, q as PromptSection, T as ToolCall, r as ToolDefinition } from './ir-CruZBtpK.mjs';
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as PerAxisMetrics, i as Provider, j as ChainEntry, G as Grounding } from './ir-B9zqlwjH.mjs';
2
+ export { k as CallAttempt, l as CallError, m as ChainWithGrounding, n as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, o as MutationApplied, p as NormalizedTokens, q as OutcomeKind, r as PerAxisMetricsByModel, s as PromptSection, T as ToolCall, t as ToolDefinition } from './ir-B9zqlwjH.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';
@@ -367,6 +367,46 @@ declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: Model
367
367
  * `BrainConfig.brainQuery.<table> = false`.
368
368
  */
369
369
  declare function isBrainQueryActiveFor(table: string): boolean;
370
+ interface GetPerAxisMetricsOpts {
371
+ /** App id to filter on. Required. */
372
+ appId: string;
373
+ /** Intent archetype to filter on. Required. */
374
+ archetype: string;
375
+ /** Canonical model id to filter on. Required. */
376
+ model: string;
377
+ /**
378
+ * Window in days. Default 30. Only rows with
379
+ * `created_at > now() - windowDays` are counted.
380
+ */
381
+ windowDays?: number;
382
+ /**
383
+ * Consumer-declared quality floor (0..1 oracle/approve-rate scale).
384
+ * When set, the response's `qualityFloorMet` is true/false; when omitted,
385
+ * `qualityFloorMet` is null (no floor declared, no judgment).
386
+ */
387
+ qualityFloor?: number;
388
+ /** Pluggable fetch (tests inject mock). Defaults to global fetch. */
389
+ fetch?: typeof fetch;
390
+ /**
391
+ * PostgREST base endpoint (e.g. `https://kgauto-brain.vercel.app/api`).
392
+ * When omitted, falls back to the active configureBrainQuery runtime's
393
+ * endpoint. Returns null when neither is set.
394
+ */
395
+ endpoint?: string;
396
+ /** Bearer token. Forwarded as `Authorization: Bearer ${apiKey}`. */
397
+ apiKey?: string;
398
+ }
399
+ /**
400
+ * Call the `get_per_axis_metrics` RPC and return the typed result.
401
+ *
402
+ * Returns null when:
403
+ * - no endpoint provided AND no configureBrainQuery runtime active
404
+ * - RPC returns empty / null / unexpected shape
405
+ * - brain unreachable / fetch throws / HTTP error
406
+ *
407
+ * Never throws — operator-facing query, must not blow up the caller.
408
+ */
409
+ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxisMetrics | null>;
370
410
 
371
411
  /**
372
412
  * env.ts — provider env-key resolution + reachability predicates.
@@ -903,4 +943,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
903
943
  */
904
944
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
905
945
 
906
- export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
946
+ export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as Provider, i as ChainEntry, G as Grounding } from './ir-Wr5lc8Mi.js';
2
- export { j as CallAttempt, k as CallError, l as ChainWithGrounding, m as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, n as MutationApplied, o as NormalizedTokens, p as OutcomeKind, q as PromptSection, T as ToolCall, r as ToolDefinition } from './ir-Wr5lc8Mi.js';
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as PerAxisMetrics, i as Provider, j as ChainEntry, G as Grounding } from './ir-B_XX2LAO.js';
2
+ export { k as CallAttempt, l as CallError, m as ChainWithGrounding, n as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, o as MutationApplied, p as NormalizedTokens, q as OutcomeKind, r as PerAxisMetricsByModel, s as PromptSection, T as ToolCall, t as ToolDefinition } from './ir-B_XX2LAO.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';
@@ -367,6 +367,46 @@ declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: Model
367
367
  * `BrainConfig.brainQuery.<table> = false`.
368
368
  */
369
369
  declare function isBrainQueryActiveFor(table: string): boolean;
370
+ interface GetPerAxisMetricsOpts {
371
+ /** App id to filter on. Required. */
372
+ appId: string;
373
+ /** Intent archetype to filter on. Required. */
374
+ archetype: string;
375
+ /** Canonical model id to filter on. Required. */
376
+ model: string;
377
+ /**
378
+ * Window in days. Default 30. Only rows with
379
+ * `created_at > now() - windowDays` are counted.
380
+ */
381
+ windowDays?: number;
382
+ /**
383
+ * Consumer-declared quality floor (0..1 oracle/approve-rate scale).
384
+ * When set, the response's `qualityFloorMet` is true/false; when omitted,
385
+ * `qualityFloorMet` is null (no floor declared, no judgment).
386
+ */
387
+ qualityFloor?: number;
388
+ /** Pluggable fetch (tests inject mock). Defaults to global fetch. */
389
+ fetch?: typeof fetch;
390
+ /**
391
+ * PostgREST base endpoint (e.g. `https://kgauto-brain.vercel.app/api`).
392
+ * When omitted, falls back to the active configureBrainQuery runtime's
393
+ * endpoint. Returns null when neither is set.
394
+ */
395
+ endpoint?: string;
396
+ /** Bearer token. Forwarded as `Authorization: Bearer ${apiKey}`. */
397
+ apiKey?: string;
398
+ }
399
+ /**
400
+ * Call the `get_per_axis_metrics` RPC and return the typed result.
401
+ *
402
+ * Returns null when:
403
+ * - no endpoint provided AND no configureBrainQuery runtime active
404
+ * - RPC returns empty / null / unexpected shape
405
+ * - brain unreachable / fetch throws / HTTP error
406
+ *
407
+ * Never throws — operator-facing query, must not blow up the caller.
408
+ */
409
+ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxisMetrics | null>;
370
410
 
371
411
  /**
372
412
  * env.ts — provider env-key resolution + reachability predicates.
@@ -903,4 +943,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
903
943
  */
904
944
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
905
945
 
906
- export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
946
+ export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(index_exports, {
43
43
  getArchetypePerfScore: () => getArchetypePerfScore,
44
44
  getDefaultFallbackChain: () => getDefaultFallbackChain,
45
45
  getDefaultFallbackChainWithGrounding: () => getDefaultFallbackChainWithGrounding,
46
+ getPerAxisMetrics: () => getPerAxisMetrics,
46
47
  getProfile: () => getProfile,
47
48
  getReachabilityDiagnostic: () => getReachabilityDiagnostic,
48
49
  getSequentialStarterChain: () => getSequentialStarterChain,
@@ -2025,6 +2026,96 @@ function defaultOnError(err) {
2025
2026
  function isBrainQueryActiveFor(table) {
2026
2027
  return runtime !== void 0 && runtime.enabledTables.has(table);
2027
2028
  }
2029
+ async function getPerAxisMetrics(opts) {
2030
+ const fetchFn = opts.fetch ?? fetch;
2031
+ const endpoint = opts.endpoint ?? runtime?.endpoint;
2032
+ if (!endpoint) return null;
2033
+ const windowDays = opts.windowDays ?? 30;
2034
+ const body = {
2035
+ p_app_id: opts.appId,
2036
+ p_archetype: opts.archetype,
2037
+ p_model: opts.model,
2038
+ p_window_days: windowDays,
2039
+ p_quality_floor: opts.qualityFloor ?? null
2040
+ };
2041
+ const headers = {
2042
+ Accept: "application/json",
2043
+ "Content-Type": "application/json",
2044
+ ...opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {}
2045
+ };
2046
+ try {
2047
+ const res = await fetchFn(`${endpoint}/rpc/get_per_axis_metrics`, {
2048
+ method: "POST",
2049
+ headers,
2050
+ body: JSON.stringify(body)
2051
+ });
2052
+ if (!res.ok) return null;
2053
+ const raw = await res.json();
2054
+ return mapPerAxisMetrics(raw, opts.appId, opts.archetype, opts.model, windowDays);
2055
+ } catch {
2056
+ return null;
2057
+ }
2058
+ }
2059
+ function mapPerAxisMetrics(raw, fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays) {
2060
+ if (raw === null || raw === void 0) return null;
2061
+ if (typeof raw !== "object") return null;
2062
+ const r = raw;
2063
+ if (Array.isArray(raw)) {
2064
+ if (raw.length === 0) return null;
2065
+ return mapPerAxisMetrics(raw[0], fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays);
2066
+ }
2067
+ const num = (v) => {
2068
+ if (v === null || v === void 0) return null;
2069
+ if (typeof v === "number") return Number.isFinite(v) ? v : null;
2070
+ if (typeof v === "string") {
2071
+ const n = Number(v);
2072
+ return Number.isFinite(n) ? n : null;
2073
+ }
2074
+ return null;
2075
+ };
2076
+ const int = (v) => {
2077
+ const n = num(v);
2078
+ return n === null ? 0 : Math.trunc(n);
2079
+ };
2080
+ const bool = (v) => {
2081
+ if (v === null || v === void 0) return null;
2082
+ if (typeof v === "boolean") return v;
2083
+ return null;
2084
+ };
2085
+ const str = (v, fallback) => typeof v === "string" ? v : fallback;
2086
+ const cost = r.cost_efficiency ?? {};
2087
+ const time = r.time_efficiency ?? {};
2088
+ const rel = r.reliability ?? {};
2089
+ return {
2090
+ appId: str(r.app_id, fallbackAppId),
2091
+ archetype: str(r.archetype, fallbackArchetype),
2092
+ model: str(r.model, fallbackModel),
2093
+ windowDays: num(r.window_days) ?? fallbackWindowDays,
2094
+ nRows: int(r.n_rows),
2095
+ nRowsClean: int(r.n_rows_clean),
2096
+ nQualityOutcomes: int(r.n_quality_outcomes),
2097
+ magicRate: num(r.magic_rate),
2098
+ qualityFloorMet: bool(r.quality_floor_met),
2099
+ costEfficiency: {
2100
+ avgCostUsd: num(cost.avg_cost_usd),
2101
+ avgCostUsdClean: num(cost.avg_cost_usd_clean),
2102
+ avgInputTokens: num(cost.avg_input_tokens),
2103
+ avgOutputTokens: num(cost.avg_output_tokens),
2104
+ inputTokenRatio: num(cost.input_token_ratio)
2105
+ },
2106
+ timeEfficiency: {
2107
+ avgLatencyMs: num(time.avg_latency_ms),
2108
+ avgTtftMs: num(time.avg_ttft_ms)
2109
+ },
2110
+ reliability: {
2111
+ successRate: num(rel.success_rate),
2112
+ successRateClean: num(rel.success_rate_clean),
2113
+ emptyRate: num(rel.empty_rate),
2114
+ emptyRateClean: num(rel.empty_rate_clean)
2115
+ },
2116
+ evidenceFreshnessDays: num(r.evidence_freshness_days)
2117
+ };
2118
+ }
2028
2119
 
2029
2120
  // src/archetype-perf-brain.ts
2030
2121
  function isPerfRow(x) {
@@ -4238,6 +4329,7 @@ function compile2(ir, opts) {
4238
4329
  getArchetypePerfScore,
4239
4330
  getDefaultFallbackChain,
4240
4331
  getDefaultFallbackChainWithGrounding,
4332
+ getPerAxisMetrics,
4241
4333
  getProfile,
4242
4334
  getReachabilityDiagnostic,
4243
4335
  getSequentialStarterChain,
package/dist/index.mjs CHANGED
@@ -820,6 +820,96 @@ function defaultOnError(err) {
820
820
  function isBrainQueryActiveFor(table) {
821
821
  return runtime !== void 0 && runtime.enabledTables.has(table);
822
822
  }
823
+ async function getPerAxisMetrics(opts) {
824
+ const fetchFn = opts.fetch ?? fetch;
825
+ const endpoint = opts.endpoint ?? runtime?.endpoint;
826
+ if (!endpoint) return null;
827
+ const windowDays = opts.windowDays ?? 30;
828
+ const body = {
829
+ p_app_id: opts.appId,
830
+ p_archetype: opts.archetype,
831
+ p_model: opts.model,
832
+ p_window_days: windowDays,
833
+ p_quality_floor: opts.qualityFloor ?? null
834
+ };
835
+ const headers = {
836
+ Accept: "application/json",
837
+ "Content-Type": "application/json",
838
+ ...opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {}
839
+ };
840
+ try {
841
+ const res = await fetchFn(`${endpoint}/rpc/get_per_axis_metrics`, {
842
+ method: "POST",
843
+ headers,
844
+ body: JSON.stringify(body)
845
+ });
846
+ if (!res.ok) return null;
847
+ const raw = await res.json();
848
+ return mapPerAxisMetrics(raw, opts.appId, opts.archetype, opts.model, windowDays);
849
+ } catch {
850
+ return null;
851
+ }
852
+ }
853
+ function mapPerAxisMetrics(raw, fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays) {
854
+ if (raw === null || raw === void 0) return null;
855
+ if (typeof raw !== "object") return null;
856
+ const r = raw;
857
+ if (Array.isArray(raw)) {
858
+ if (raw.length === 0) return null;
859
+ return mapPerAxisMetrics(raw[0], fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays);
860
+ }
861
+ const num = (v) => {
862
+ if (v === null || v === void 0) return null;
863
+ if (typeof v === "number") return Number.isFinite(v) ? v : null;
864
+ if (typeof v === "string") {
865
+ const n = Number(v);
866
+ return Number.isFinite(n) ? n : null;
867
+ }
868
+ return null;
869
+ };
870
+ const int = (v) => {
871
+ const n = num(v);
872
+ return n === null ? 0 : Math.trunc(n);
873
+ };
874
+ const bool = (v) => {
875
+ if (v === null || v === void 0) return null;
876
+ if (typeof v === "boolean") return v;
877
+ return null;
878
+ };
879
+ const str = (v, fallback) => typeof v === "string" ? v : fallback;
880
+ const cost = r.cost_efficiency ?? {};
881
+ const time = r.time_efficiency ?? {};
882
+ const rel = r.reliability ?? {};
883
+ return {
884
+ appId: str(r.app_id, fallbackAppId),
885
+ archetype: str(r.archetype, fallbackArchetype),
886
+ model: str(r.model, fallbackModel),
887
+ windowDays: num(r.window_days) ?? fallbackWindowDays,
888
+ nRows: int(r.n_rows),
889
+ nRowsClean: int(r.n_rows_clean),
890
+ nQualityOutcomes: int(r.n_quality_outcomes),
891
+ magicRate: num(r.magic_rate),
892
+ qualityFloorMet: bool(r.quality_floor_met),
893
+ costEfficiency: {
894
+ avgCostUsd: num(cost.avg_cost_usd),
895
+ avgCostUsdClean: num(cost.avg_cost_usd_clean),
896
+ avgInputTokens: num(cost.avg_input_tokens),
897
+ avgOutputTokens: num(cost.avg_output_tokens),
898
+ inputTokenRatio: num(cost.input_token_ratio)
899
+ },
900
+ timeEfficiency: {
901
+ avgLatencyMs: num(time.avg_latency_ms),
902
+ avgTtftMs: num(time.avg_ttft_ms)
903
+ },
904
+ reliability: {
905
+ successRate: num(rel.success_rate),
906
+ successRateClean: num(rel.success_rate_clean),
907
+ emptyRate: num(rel.empty_rate),
908
+ emptyRateClean: num(rel.empty_rate_clean)
909
+ },
910
+ evidenceFreshnessDays: num(r.evidence_freshness_days)
911
+ };
912
+ }
823
913
 
824
914
  // src/archetype-perf-brain.ts
825
915
  function isPerfRow(x) {
@@ -2744,6 +2834,7 @@ export {
2744
2834
  getArchetypePerfScore,
2745
2835
  getDefaultFallbackChain,
2746
2836
  getDefaultFallbackChainWithGrounding,
2837
+ getPerAxisMetrics,
2747
2838
  getProfile,
2748
2839
  getReachabilityDiagnostic,
2749
2840
  getSequentialStarterChain,
@@ -796,5 +796,42 @@ interface ChainWithGrounding {
796
796
  /** Ordered: position 0 = primary, rising index = fallback positions. */
797
797
  entries: ChainEntry[];
798
798
  }
799
+ /** alpha.23 (s78 Phase 3): per-axis metrics returned by the brain RPC. */
800
+ interface PerAxisMetrics {
801
+ appId: string;
802
+ archetype: string;
803
+ model: string;
804
+ windowDays: number;
805
+ /** Total brain rows for this tuple in the window. */
806
+ nRows: number;
807
+ /** Subset of nRows with zero advisories fired — the "clean signal" comparator. */
808
+ nRowsClean: number;
809
+ /** Count of compile_outcome_quality entries joining to this tuple's outcomes. */
810
+ nQualityOutcomes: number;
811
+ /** Approve rate from quality outcomes. null when nQualityOutcomes === 0. */
812
+ magicRate: number | null;
813
+ /** Whether magicRate >= consumer-declared qualityFloor. null when no floor declared OR no outcomes. */
814
+ qualityFloorMet: boolean | null;
815
+ costEfficiency: {
816
+ avgCostUsd: number | null;
817
+ avgCostUsdClean: number | null;
818
+ avgInputTokens: number | null;
819
+ avgOutputTokens: number | null;
820
+ inputTokenRatio: number | null;
821
+ };
822
+ timeEfficiency: {
823
+ avgLatencyMs: number | null;
824
+ avgTtftMs: number | null;
825
+ };
826
+ reliability: {
827
+ successRate: number | null;
828
+ successRateClean: number | null;
829
+ emptyRate: number | null;
830
+ emptyRateClean: number | null;
831
+ };
832
+ evidenceFreshnessDays: number | null;
833
+ }
834
+ /** Per-axis metrics keyed by model — used for chain-comparison views. */
835
+ type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
799
836
 
800
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type Provider as h, type ChainEntry as i, type CallAttempt as j, CallError as k, type ChainWithGrounding as l, type Constraints as m, type MutationApplied as n, type NormalizedTokens as o, type OutcomeKind as p, type PromptSection as q, type ToolDefinition as r };
837
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type PerAxisMetrics as h, type Provider as i, type ChainEntry as j, type CallAttempt as k, CallError as l, type ChainWithGrounding as m, type Constraints as n, type MutationApplied as o, type NormalizedTokens as p, type OutcomeKind as q, type PerAxisMetricsByModel as r, type PromptSection as s, type ToolDefinition as t };
@@ -796,5 +796,42 @@ interface ChainWithGrounding {
796
796
  /** Ordered: position 0 = primary, rising index = fallback positions. */
797
797
  entries: ChainEntry[];
798
798
  }
799
+ /** alpha.23 (s78 Phase 3): per-axis metrics returned by the brain RPC. */
800
+ interface PerAxisMetrics {
801
+ appId: string;
802
+ archetype: string;
803
+ model: string;
804
+ windowDays: number;
805
+ /** Total brain rows for this tuple in the window. */
806
+ nRows: number;
807
+ /** Subset of nRows with zero advisories fired — the "clean signal" comparator. */
808
+ nRowsClean: number;
809
+ /** Count of compile_outcome_quality entries joining to this tuple's outcomes. */
810
+ nQualityOutcomes: number;
811
+ /** Approve rate from quality outcomes. null when nQualityOutcomes === 0. */
812
+ magicRate: number | null;
813
+ /** Whether magicRate >= consumer-declared qualityFloor. null when no floor declared OR no outcomes. */
814
+ qualityFloorMet: boolean | null;
815
+ costEfficiency: {
816
+ avgCostUsd: number | null;
817
+ avgCostUsdClean: number | null;
818
+ avgInputTokens: number | null;
819
+ avgOutputTokens: number | null;
820
+ inputTokenRatio: number | null;
821
+ };
822
+ timeEfficiency: {
823
+ avgLatencyMs: number | null;
824
+ avgTtftMs: number | null;
825
+ };
826
+ reliability: {
827
+ successRate: number | null;
828
+ successRateClean: number | null;
829
+ emptyRate: number | null;
830
+ emptyRateClean: number | null;
831
+ };
832
+ evidenceFreshnessDays: number | null;
833
+ }
834
+ /** Per-axis metrics keyed by model — used for chain-comparison views. */
835
+ type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
799
836
 
800
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type Provider as h, type ChainEntry as i, type CallAttempt as j, CallError as k, type ChainWithGrounding as l, type Constraints as m, type MutationApplied as n, type NormalizedTokens as o, type OutcomeKind as p, type PromptSection as q, type ToolDefinition as r };
837
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type PerAxisMetrics as h, type Provider as i, type ChainEntry as j, type CallAttempt as k, CallError as l, type ChainWithGrounding as m, type Constraints as n, type MutationApplied as o, type NormalizedTokens as p, type OutcomeKind as q, type PerAxisMetricsByModel as r, type PromptSection as s, type ToolDefinition as t };
@@ -1,4 +1,4 @@
1
- import { h as Provider } from './ir-CruZBtpK.mjs';
1
+ import { i as Provider } from './ir-B9zqlwjH.mjs';
2
2
  import { IntentArchetypeName } from './dialect.mjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { h as Provider } from './ir-Wr5lc8Mi.js';
1
+ import { i as Provider } from './ir-B_XX2LAO.js';
2
2
  import { IntentArchetypeName } from './dialect.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { n as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, j as CallAttempt } from './ir-CruZBtpK.mjs';
1
+ import { o as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, k as CallAttempt } from './ir-B9zqlwjH.mjs';
2
2
 
3
3
  /**
4
4
  * Glass-Box observability types (alpha.17).
@@ -1,4 +1,4 @@
1
- import { n as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, j as CallAttempt } from './ir-Wr5lc8Mi.js';
1
+ import { o as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, k as CallAttempt } from './ir-B_XX2LAO.js';
2
2
 
3
3
  /**
4
4
  * Glass-Box observability types (alpha.17).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warmdrift/kgauto-compiler",
3
- "version": "2.0.0-alpha.22",
3
+ "version": "2.0.0-alpha.24",
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",