@warmdrift/kgauto-compiler 2.0.0-alpha.21 → 2.0.0-alpha.23

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,5 +1,5 @@
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
5
  /**
@@ -1,5 +1,5 @@
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
5
  /**
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';
@@ -326,14 +326,87 @@ declare function countTokens(text: string): number;
326
326
 
327
327
  /** Subset of CompileResult fields the advisor needs. */
328
328
  type AdvisorContext = Pick<CompileResult, 'target' | 'provider' | 'tokensIn' | 'diagnostics'>;
329
+ /**
330
+ * Optional Phase 2 (alpha.22) context — fallback chain + a profile resolver
331
+ * for cross-model comparison. Three new rules
332
+ * (`cost-mismatched-archetype`, `model-stale-evidence`, `tier-down`) consume
333
+ * this to surface measurement-substrate signals (alpha.20 clean-attribution +
334
+ * alpha.21 grounding labels) as actionable consumer guidance.
335
+ *
336
+ * When `fallbackChain` is empty, rules 1 + 3 stay silent (nothing to
337
+ * compare against). When `profileResolver` is omitted, the rules degrade
338
+ * gracefully — they can still inspect the chosen profile but not chain
339
+ * alternatives. Rule 2 (`model-stale-evidence`) is independent of chain
340
+ * shape and works on the chosen model alone.
341
+ */
342
+ interface RunAdvisorPhase2Context {
343
+ fallbackChain: string[];
344
+ profileResolver?: (id: string) => ModelProfile | undefined;
345
+ }
329
346
  /**
330
347
  * Run all phased rules and return collected advisories. Order is fixed so
331
348
  * output is stable across runs. The `policy` argument is alpha.9 — the
332
349
  * `single-model-array` rule needs to know whether the consumer explicitly
333
350
  * declared `posture: 'locked'` (in which case single-model is intentional
334
351
  * and shouldn't warn).
352
+ *
353
+ * `phase2` is alpha.22 — gives the advisor access to the fallback chain +
354
+ * a profile resolver so the three new compile-time recommendation rules
355
+ * (`cost-mismatched-archetype`, `model-stale-evidence`, `tier-down`) can
356
+ * compare the chosen model against in-chain alternatives. Optional for
357
+ * backward compatibility with consumers calling `runAdvisor()` directly.
358
+ */
359
+ declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: ModelProfile, policy?: CompilePolicy, phase2?: RunAdvisorPhase2Context): BestPracticeAdvisory[];
360
+
361
+ /**
362
+ * alpha.22 — sync introspection: is brain-query mode active for a given
363
+ * table? Used by the advisor (`model-stale-evidence` rule) to decide
364
+ * whether a `judgment`-grounded chosen model is a measurement gap worth
365
+ * surfacing. Returns false on cold start, when configureBrain() was never
366
+ * called, or when the consumer explicitly opted the table out via
367
+ * `BrainConfig.brainQuery.<table> = false`.
368
+ */
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.
335
408
  */
336
- declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: ModelProfile, policy?: CompilePolicy): BestPracticeAdvisory[];
409
+ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxisMetrics | null>;
337
410
 
338
411
  /**
339
412
  * env.ts — provider env-key resolution + reachability predicates.
@@ -870,4 +943,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
870
943
  */
871
944
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
872
945
 
873
- 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 SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, 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';
@@ -326,14 +326,87 @@ declare function countTokens(text: string): number;
326
326
 
327
327
  /** Subset of CompileResult fields the advisor needs. */
328
328
  type AdvisorContext = Pick<CompileResult, 'target' | 'provider' | 'tokensIn' | 'diagnostics'>;
329
+ /**
330
+ * Optional Phase 2 (alpha.22) context — fallback chain + a profile resolver
331
+ * for cross-model comparison. Three new rules
332
+ * (`cost-mismatched-archetype`, `model-stale-evidence`, `tier-down`) consume
333
+ * this to surface measurement-substrate signals (alpha.20 clean-attribution +
334
+ * alpha.21 grounding labels) as actionable consumer guidance.
335
+ *
336
+ * When `fallbackChain` is empty, rules 1 + 3 stay silent (nothing to
337
+ * compare against). When `profileResolver` is omitted, the rules degrade
338
+ * gracefully — they can still inspect the chosen profile but not chain
339
+ * alternatives. Rule 2 (`model-stale-evidence`) is independent of chain
340
+ * shape and works on the chosen model alone.
341
+ */
342
+ interface RunAdvisorPhase2Context {
343
+ fallbackChain: string[];
344
+ profileResolver?: (id: string) => ModelProfile | undefined;
345
+ }
329
346
  /**
330
347
  * Run all phased rules and return collected advisories. Order is fixed so
331
348
  * output is stable across runs. The `policy` argument is alpha.9 — the
332
349
  * `single-model-array` rule needs to know whether the consumer explicitly
333
350
  * declared `posture: 'locked'` (in which case single-model is intentional
334
351
  * and shouldn't warn).
352
+ *
353
+ * `phase2` is alpha.22 — gives the advisor access to the fallback chain +
354
+ * a profile resolver so the three new compile-time recommendation rules
355
+ * (`cost-mismatched-archetype`, `model-stale-evidence`, `tier-down`) can
356
+ * compare the chosen model against in-chain alternatives. Optional for
357
+ * backward compatibility with consumers calling `runAdvisor()` directly.
358
+ */
359
+ declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: ModelProfile, policy?: CompilePolicy, phase2?: RunAdvisorPhase2Context): BestPracticeAdvisory[];
360
+
361
+ /**
362
+ * alpha.22 — sync introspection: is brain-query mode active for a given
363
+ * table? Used by the advisor (`model-stale-evidence` rule) to decide
364
+ * whether a `judgment`-grounded chosen model is a measurement gap worth
365
+ * surfacing. Returns false on cold start, when configureBrain() was never
366
+ * called, or when the consumer explicitly opted the table out via
367
+ * `BrainConfig.brainQuery.<table> = false`.
368
+ */
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.
335
408
  */
336
- declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: ModelProfile, policy?: CompilePolicy): BestPracticeAdvisory[];
409
+ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxisMetrics | null>;
337
410
 
338
411
  /**
339
412
  * env.ts — provider env-key resolution + reachability predicates.
@@ -870,4 +943,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
870
943
  */
871
944
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
872
945
 
873
- 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 SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, 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 };