@warmdrift/kgauto-compiler 2.0.0-alpha.62 → 2.0.0-alpha.64
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-ABFXMO73.mjs → chunk-DGPYLFDG.mjs} +1 -1
- package/dist/index.d.mts +146 -2
- package/dist/index.d.ts +146 -2
- package/dist/index.js +201 -11
- package/dist/index.mjs +194 -11
- package/dist/key-health.js +1 -1
- package/dist/key-health.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -376,6 +376,14 @@ interface BrainQueryConfig {
|
|
|
376
376
|
* advisory).
|
|
377
377
|
*/
|
|
378
378
|
findingsExclusions?: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* alpha.64 — hard opt-out of the surface-promotions fetch layer (Stage 2).
|
|
381
|
+
* Default true; only matters when consent (`BrainConfig.autoPromote` /
|
|
382
|
+
* `KGAUTO_AUTO_PROMOTE`) is present — without consent the layer is off
|
|
383
|
+
* regardless. Set `false` to disable the fetch even while consented
|
|
384
|
+
* (debug/emergency lever).
|
|
385
|
+
*/
|
|
386
|
+
promotions?: boolean;
|
|
379
387
|
/** SWR window in ms. Default 300_000 (5 min). */
|
|
380
388
|
cacheTtlMs?: number;
|
|
381
389
|
/** Override the GET URL when the read endpoint differs from the write one.
|
|
@@ -388,6 +396,13 @@ interface BrainQueryConfig {
|
|
|
388
396
|
* Defaults to `https://kgauto-dashboard.vercel.app/api/kgauto-v2/findings/exclusions`.
|
|
389
397
|
*/
|
|
390
398
|
findingsEndpoint?: string;
|
|
399
|
+
/**
|
|
400
|
+
* alpha.64 — override the surface-promotions endpoint (Stage 2). Only
|
|
401
|
+
* consulted when the consumer opted in via `BrainConfig.autoPromote` /
|
|
402
|
+
* `KGAUTO_AUTO_PROMOTE`. Library appends `?app_id=X`. Defaults to
|
|
403
|
+
* `https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions`.
|
|
404
|
+
*/
|
|
405
|
+
promotionsEndpoint?: string;
|
|
391
406
|
}
|
|
392
407
|
interface BrainConfig {
|
|
393
408
|
/** Brain HTTP endpoint base URL (e.g., https://kgauto-brain.vercel.app/api). */
|
|
@@ -437,6 +452,27 @@ interface BrainConfig {
|
|
|
437
452
|
* not affected.
|
|
438
453
|
*/
|
|
439
454
|
timeoutMs?: number;
|
|
455
|
+
/**
|
|
456
|
+
* alpha.64 (Stage 2 of the eval trust ladder) — consent switch for the
|
|
457
|
+
* surface-promotion routing effect. Default OFF.
|
|
458
|
+
*
|
|
459
|
+
* When true (or when the `KGAUTO_AUTO_PROMOTE` env var is '1'/'true' and
|
|
460
|
+
* this field is left undefined — env-as-consent, the KGAUTO_GOLDEN_CAPTURE
|
|
461
|
+
* precedent; an explicit `false` here overrides the env), compile()
|
|
462
|
+
* consults the brain's active `kgauto_promotions` rows for this app and
|
|
463
|
+
* boosts the promoted model at scoring time. Promotions are written only
|
|
464
|
+
* by the automated golden-eval trigger after a promote-ready verdict on a
|
|
465
|
+
* price-dominant (cheaper) candidate, and every promotion sits behind the
|
|
466
|
+
* 7-day rollback guard (daily watcher auto-reverts on regression vs the
|
|
467
|
+
* frozen baseline).
|
|
468
|
+
*
|
|
469
|
+
* Not opted in ⇒ promotions have ZERO routing effect (they remain visible
|
|
470
|
+
* as advisories + dashboard rows). Consumer sovereignty is preserved even
|
|
471
|
+
* when opted in: `forceModel`, `policy.blockedModels`, and cost ceilings
|
|
472
|
+
* always win, and a non-empty `policy.preferredModels` defers the
|
|
473
|
+
* promotion entirely.
|
|
474
|
+
*/
|
|
475
|
+
autoPromote?: boolean;
|
|
440
476
|
}
|
|
441
477
|
declare function configureBrain(config: BrainConfig): void;
|
|
442
478
|
declare function clearBrain(): void;
|
|
@@ -887,7 +923,7 @@ declare function runGoldenEval(opts: GoldenEvalOptions): Promise<GoldenEvalRunRe
|
|
|
887
923
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
888
924
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
889
925
|
*/
|
|
890
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
926
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.64";
|
|
891
927
|
|
|
892
928
|
/**
|
|
893
929
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2630,6 +2666,114 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
|
|
|
2630
2666
|
reason: string;
|
|
2631
2667
|
}>;
|
|
2632
2668
|
|
|
2669
|
+
/**
|
|
2670
|
+
* promotions-brain — alpha.64 Stage-2 substrate.
|
|
2671
|
+
*
|
|
2672
|
+
* Per-tenant SWR cache for the `kgauto_promotions` table populated by the
|
|
2673
|
+
* golden-eval trigger's auto-promote actor (Stage 2 of the eval trust
|
|
2674
|
+
* ladder: auto-promote downswaps behind the 7-day rollback guard). Mirrors
|
|
2675
|
+
* `promote-ready-brain.ts` shape where applicable; this is the read-side
|
|
2676
|
+
* substrate for the compile-time promotion boost in `passScoreTargets`.
|
|
2677
|
+
*
|
|
2678
|
+
* Design contract:
|
|
2679
|
+
* command-center/advisory/kgauto/2026-07-18_stage2-auto-promote-design.md
|
|
2680
|
+
*
|
|
2681
|
+
* Consent posture: the routing effect is OPT-IN, default OFF. The cache is
|
|
2682
|
+
* only activated by `configureBrain()` when the consumer opted in via
|
|
2683
|
+
* `BrainConfig.autoPromote: true` or the `KGAUTO_AUTO_PROMOTE` env var
|
|
2684
|
+
* (config field wins when both are present — mirror of the
|
|
2685
|
+
* `KGAUTO_GOLDEN_CAPTURE` env-as-consent precedent). Not opted in ⇒ this
|
|
2686
|
+
* module never fetches and `getApplicablePromotion` returns undefined ⇒
|
|
2687
|
+
* zero behavior change anywhere in compile().
|
|
2688
|
+
*
|
|
2689
|
+
* Architecture (mirror of promote-ready-brain):
|
|
2690
|
+
* - Sync API surface: `getApplicablePromotion({ appId, archetype })`
|
|
2691
|
+
* returns immediately. First call returns undefined (cold) and fires an
|
|
2692
|
+
* async refresh; subsequent calls within TTL return brain data.
|
|
2693
|
+
* - Per-appId snapshot; one fetch per appId per TTL window.
|
|
2694
|
+
* - Tolerant: brain down / misconfigured / unexpected shape → undefined.
|
|
2695
|
+
* Never throws. Warns once per process.
|
|
2696
|
+
*
|
|
2697
|
+
* A rollback (`status='rolled_back'` PATCHed by the promotion-guard
|
|
2698
|
+
* watcher) drops the row from the endpoint's `status=active` filter, so
|
|
2699
|
+
* routing reverts within one TTL window — the mechanism the 7-day guard's
|
|
2700
|
+
* auto-revert rests on.
|
|
2701
|
+
*/
|
|
2702
|
+
|
|
2703
|
+
/**
|
|
2704
|
+
* One active surface promotion, camelCase-mapped at the boundary from the
|
|
2705
|
+
* snake_case endpoint row (typed-boundary-transformer convention).
|
|
2706
|
+
*/
|
|
2707
|
+
interface PromotionRow {
|
|
2708
|
+
/** Brain row id — cited in the `promotion-applied` mutation for Glass-Box. */
|
|
2709
|
+
id: number;
|
|
2710
|
+
/** Intent archetype the promotion applies to. */
|
|
2711
|
+
archetype: string;
|
|
2712
|
+
/** The model this surface now routes to. */
|
|
2713
|
+
promotedModel: string;
|
|
2714
|
+
/** The model it replaced (the eval's incumbent). */
|
|
2715
|
+
incumbentModel: string;
|
|
2716
|
+
/** The promote-ready kgauto_golden_eval_runs row this rests on. */
|
|
2717
|
+
evalRunId: number | null;
|
|
2718
|
+
/**
|
|
2719
|
+
* Evidence-supersedes-judgment: skip the alpha.49 schema-weak
|
|
2720
|
+
* quality-gate penalty for the promoted model on this surface (the eval
|
|
2721
|
+
* measured the schema floor holding on real workload).
|
|
2722
|
+
*/
|
|
2723
|
+
suppressQualityGate: boolean;
|
|
2724
|
+
/** ISO timestamp the promotion went active. */
|
|
2725
|
+
promotedAt: string;
|
|
2726
|
+
}
|
|
2727
|
+
interface PromotionsRuntime {
|
|
2728
|
+
/** Endpoint base URL. The library appends `?app_id=<id>`. */
|
|
2729
|
+
endpoint: string;
|
|
2730
|
+
/** Stale-while-revalidate window in ms. */
|
|
2731
|
+
ttlMs: number;
|
|
2732
|
+
/** Pluggable fetch. */
|
|
2733
|
+
fetchImpl: typeof fetch;
|
|
2734
|
+
/** Optional warn hook. */
|
|
2735
|
+
onError?: (err: unknown) => void;
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Default endpoint hosted on the kgauto-dashboard. Serves `status='active'`
|
|
2739
|
+
* kgauto_promotions rows for one app_id. Mirrors the findings convention.
|
|
2740
|
+
*/
|
|
2741
|
+
declare const DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
|
|
2742
|
+
/**
|
|
2743
|
+
* True when the KGAUTO_AUTO_PROMOTE env var opts this process in.
|
|
2744
|
+
* Accepted truthy forms: '1', 'true' (case-insensitive). Everything else —
|
|
2745
|
+
* unset, '', '0', 'false' — is OFF. Read at configureBrain() time, not per
|
|
2746
|
+
* call.
|
|
2747
|
+
*/
|
|
2748
|
+
declare function isAutoPromoteEnabledFromEnv(envSource?: Record<string, string | undefined>): boolean;
|
|
2749
|
+
/**
|
|
2750
|
+
* Wire (or rewire) the runtime. Pass undefined to disable. Resets all
|
|
2751
|
+
* snapshots. Called from `configureBrain()` ONLY when the consumer opted in.
|
|
2752
|
+
*/
|
|
2753
|
+
declare function configurePromotionsBrain(rt: PromotionsRuntime | undefined): void;
|
|
2754
|
+
/** Sync introspection — is the promotions brain active (i.e. opted in)? */
|
|
2755
|
+
declare function isPromotionsBrainActive(): boolean;
|
|
2756
|
+
interface GetApplicablePromotionOpts {
|
|
2757
|
+
/** App id to read promotions for. Required. */
|
|
2758
|
+
appId: string;
|
|
2759
|
+
/** Archetype of the compile in flight. Required. */
|
|
2760
|
+
archetype: IntentArchetypeName | string;
|
|
2761
|
+
}
|
|
2762
|
+
/**
|
|
2763
|
+
* Sync reader. Returns the active promotion for `(appId, archetype)` or
|
|
2764
|
+
* undefined. First call returns undefined and triggers async refresh;
|
|
2765
|
+
* subsequent calls within TTL return brain data. The brain enforces one
|
|
2766
|
+
* active promotion per surface (partial unique index), so at most one row
|
|
2767
|
+
* matches.
|
|
2768
|
+
*
|
|
2769
|
+
* NEVER throws. Not configured / brain down / cold → undefined.
|
|
2770
|
+
*/
|
|
2771
|
+
declare function getApplicablePromotion(opts: GetApplicablePromotionOpts): PromotionRow | undefined;
|
|
2772
|
+
/** Reset module state. Tests must call between cases. */
|
|
2773
|
+
declare function _testResetPromotions(): void;
|
|
2774
|
+
/** Wait for any in-flight refresh to settle. */
|
|
2775
|
+
declare function _testWaitForPromotionsRefresh(): Promise<void>;
|
|
2776
|
+
|
|
2633
2777
|
/**
|
|
2634
2778
|
* @warmdrift/kgauto v2 — prompt compiler + central learning brain.
|
|
2635
2779
|
*
|
|
@@ -2676,4 +2820,4 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
|
|
|
2676
2820
|
*/
|
|
2677
2821
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
2678
2822
|
|
|
2679
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
|
|
2823
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetApplicablePromotionOpts, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, type PromotionRow, type PromotionsRuntime, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, _testResetPromotions, _testWaitForPromotionsRefresh, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configurePromotionsBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isAutoPromoteEnabledFromEnv, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isPromotionsBrainActive, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
|
package/dist/index.d.ts
CHANGED
|
@@ -376,6 +376,14 @@ interface BrainQueryConfig {
|
|
|
376
376
|
* advisory).
|
|
377
377
|
*/
|
|
378
378
|
findingsExclusions?: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* alpha.64 — hard opt-out of the surface-promotions fetch layer (Stage 2).
|
|
381
|
+
* Default true; only matters when consent (`BrainConfig.autoPromote` /
|
|
382
|
+
* `KGAUTO_AUTO_PROMOTE`) is present — without consent the layer is off
|
|
383
|
+
* regardless. Set `false` to disable the fetch even while consented
|
|
384
|
+
* (debug/emergency lever).
|
|
385
|
+
*/
|
|
386
|
+
promotions?: boolean;
|
|
379
387
|
/** SWR window in ms. Default 300_000 (5 min). */
|
|
380
388
|
cacheTtlMs?: number;
|
|
381
389
|
/** Override the GET URL when the read endpoint differs from the write one.
|
|
@@ -388,6 +396,13 @@ interface BrainQueryConfig {
|
|
|
388
396
|
* Defaults to `https://kgauto-dashboard.vercel.app/api/kgauto-v2/findings/exclusions`.
|
|
389
397
|
*/
|
|
390
398
|
findingsEndpoint?: string;
|
|
399
|
+
/**
|
|
400
|
+
* alpha.64 — override the surface-promotions endpoint (Stage 2). Only
|
|
401
|
+
* consulted when the consumer opted in via `BrainConfig.autoPromote` /
|
|
402
|
+
* `KGAUTO_AUTO_PROMOTE`. Library appends `?app_id=X`. Defaults to
|
|
403
|
+
* `https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions`.
|
|
404
|
+
*/
|
|
405
|
+
promotionsEndpoint?: string;
|
|
391
406
|
}
|
|
392
407
|
interface BrainConfig {
|
|
393
408
|
/** Brain HTTP endpoint base URL (e.g., https://kgauto-brain.vercel.app/api). */
|
|
@@ -437,6 +452,27 @@ interface BrainConfig {
|
|
|
437
452
|
* not affected.
|
|
438
453
|
*/
|
|
439
454
|
timeoutMs?: number;
|
|
455
|
+
/**
|
|
456
|
+
* alpha.64 (Stage 2 of the eval trust ladder) — consent switch for the
|
|
457
|
+
* surface-promotion routing effect. Default OFF.
|
|
458
|
+
*
|
|
459
|
+
* When true (or when the `KGAUTO_AUTO_PROMOTE` env var is '1'/'true' and
|
|
460
|
+
* this field is left undefined — env-as-consent, the KGAUTO_GOLDEN_CAPTURE
|
|
461
|
+
* precedent; an explicit `false` here overrides the env), compile()
|
|
462
|
+
* consults the brain's active `kgauto_promotions` rows for this app and
|
|
463
|
+
* boosts the promoted model at scoring time. Promotions are written only
|
|
464
|
+
* by the automated golden-eval trigger after a promote-ready verdict on a
|
|
465
|
+
* price-dominant (cheaper) candidate, and every promotion sits behind the
|
|
466
|
+
* 7-day rollback guard (daily watcher auto-reverts on regression vs the
|
|
467
|
+
* frozen baseline).
|
|
468
|
+
*
|
|
469
|
+
* Not opted in ⇒ promotions have ZERO routing effect (they remain visible
|
|
470
|
+
* as advisories + dashboard rows). Consumer sovereignty is preserved even
|
|
471
|
+
* when opted in: `forceModel`, `policy.blockedModels`, and cost ceilings
|
|
472
|
+
* always win, and a non-empty `policy.preferredModels` defers the
|
|
473
|
+
* promotion entirely.
|
|
474
|
+
*/
|
|
475
|
+
autoPromote?: boolean;
|
|
440
476
|
}
|
|
441
477
|
declare function configureBrain(config: BrainConfig): void;
|
|
442
478
|
declare function clearBrain(): void;
|
|
@@ -887,7 +923,7 @@ declare function runGoldenEval(opts: GoldenEvalOptions): Promise<GoldenEvalRunRe
|
|
|
887
923
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
888
924
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
889
925
|
*/
|
|
890
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
926
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.64";
|
|
891
927
|
|
|
892
928
|
/**
|
|
893
929
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2630,6 +2666,114 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
|
|
|
2630
2666
|
reason: string;
|
|
2631
2667
|
}>;
|
|
2632
2668
|
|
|
2669
|
+
/**
|
|
2670
|
+
* promotions-brain — alpha.64 Stage-2 substrate.
|
|
2671
|
+
*
|
|
2672
|
+
* Per-tenant SWR cache for the `kgauto_promotions` table populated by the
|
|
2673
|
+
* golden-eval trigger's auto-promote actor (Stage 2 of the eval trust
|
|
2674
|
+
* ladder: auto-promote downswaps behind the 7-day rollback guard). Mirrors
|
|
2675
|
+
* `promote-ready-brain.ts` shape where applicable; this is the read-side
|
|
2676
|
+
* substrate for the compile-time promotion boost in `passScoreTargets`.
|
|
2677
|
+
*
|
|
2678
|
+
* Design contract:
|
|
2679
|
+
* command-center/advisory/kgauto/2026-07-18_stage2-auto-promote-design.md
|
|
2680
|
+
*
|
|
2681
|
+
* Consent posture: the routing effect is OPT-IN, default OFF. The cache is
|
|
2682
|
+
* only activated by `configureBrain()` when the consumer opted in via
|
|
2683
|
+
* `BrainConfig.autoPromote: true` or the `KGAUTO_AUTO_PROMOTE` env var
|
|
2684
|
+
* (config field wins when both are present — mirror of the
|
|
2685
|
+
* `KGAUTO_GOLDEN_CAPTURE` env-as-consent precedent). Not opted in ⇒ this
|
|
2686
|
+
* module never fetches and `getApplicablePromotion` returns undefined ⇒
|
|
2687
|
+
* zero behavior change anywhere in compile().
|
|
2688
|
+
*
|
|
2689
|
+
* Architecture (mirror of promote-ready-brain):
|
|
2690
|
+
* - Sync API surface: `getApplicablePromotion({ appId, archetype })`
|
|
2691
|
+
* returns immediately. First call returns undefined (cold) and fires an
|
|
2692
|
+
* async refresh; subsequent calls within TTL return brain data.
|
|
2693
|
+
* - Per-appId snapshot; one fetch per appId per TTL window.
|
|
2694
|
+
* - Tolerant: brain down / misconfigured / unexpected shape → undefined.
|
|
2695
|
+
* Never throws. Warns once per process.
|
|
2696
|
+
*
|
|
2697
|
+
* A rollback (`status='rolled_back'` PATCHed by the promotion-guard
|
|
2698
|
+
* watcher) drops the row from the endpoint's `status=active` filter, so
|
|
2699
|
+
* routing reverts within one TTL window — the mechanism the 7-day guard's
|
|
2700
|
+
* auto-revert rests on.
|
|
2701
|
+
*/
|
|
2702
|
+
|
|
2703
|
+
/**
|
|
2704
|
+
* One active surface promotion, camelCase-mapped at the boundary from the
|
|
2705
|
+
* snake_case endpoint row (typed-boundary-transformer convention).
|
|
2706
|
+
*/
|
|
2707
|
+
interface PromotionRow {
|
|
2708
|
+
/** Brain row id — cited in the `promotion-applied` mutation for Glass-Box. */
|
|
2709
|
+
id: number;
|
|
2710
|
+
/** Intent archetype the promotion applies to. */
|
|
2711
|
+
archetype: string;
|
|
2712
|
+
/** The model this surface now routes to. */
|
|
2713
|
+
promotedModel: string;
|
|
2714
|
+
/** The model it replaced (the eval's incumbent). */
|
|
2715
|
+
incumbentModel: string;
|
|
2716
|
+
/** The promote-ready kgauto_golden_eval_runs row this rests on. */
|
|
2717
|
+
evalRunId: number | null;
|
|
2718
|
+
/**
|
|
2719
|
+
* Evidence-supersedes-judgment: skip the alpha.49 schema-weak
|
|
2720
|
+
* quality-gate penalty for the promoted model on this surface (the eval
|
|
2721
|
+
* measured the schema floor holding on real workload).
|
|
2722
|
+
*/
|
|
2723
|
+
suppressQualityGate: boolean;
|
|
2724
|
+
/** ISO timestamp the promotion went active. */
|
|
2725
|
+
promotedAt: string;
|
|
2726
|
+
}
|
|
2727
|
+
interface PromotionsRuntime {
|
|
2728
|
+
/** Endpoint base URL. The library appends `?app_id=<id>`. */
|
|
2729
|
+
endpoint: string;
|
|
2730
|
+
/** Stale-while-revalidate window in ms. */
|
|
2731
|
+
ttlMs: number;
|
|
2732
|
+
/** Pluggable fetch. */
|
|
2733
|
+
fetchImpl: typeof fetch;
|
|
2734
|
+
/** Optional warn hook. */
|
|
2735
|
+
onError?: (err: unknown) => void;
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Default endpoint hosted on the kgauto-dashboard. Serves `status='active'`
|
|
2739
|
+
* kgauto_promotions rows for one app_id. Mirrors the findings convention.
|
|
2740
|
+
*/
|
|
2741
|
+
declare const DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
|
|
2742
|
+
/**
|
|
2743
|
+
* True when the KGAUTO_AUTO_PROMOTE env var opts this process in.
|
|
2744
|
+
* Accepted truthy forms: '1', 'true' (case-insensitive). Everything else —
|
|
2745
|
+
* unset, '', '0', 'false' — is OFF. Read at configureBrain() time, not per
|
|
2746
|
+
* call.
|
|
2747
|
+
*/
|
|
2748
|
+
declare function isAutoPromoteEnabledFromEnv(envSource?: Record<string, string | undefined>): boolean;
|
|
2749
|
+
/**
|
|
2750
|
+
* Wire (or rewire) the runtime. Pass undefined to disable. Resets all
|
|
2751
|
+
* snapshots. Called from `configureBrain()` ONLY when the consumer opted in.
|
|
2752
|
+
*/
|
|
2753
|
+
declare function configurePromotionsBrain(rt: PromotionsRuntime | undefined): void;
|
|
2754
|
+
/** Sync introspection — is the promotions brain active (i.e. opted in)? */
|
|
2755
|
+
declare function isPromotionsBrainActive(): boolean;
|
|
2756
|
+
interface GetApplicablePromotionOpts {
|
|
2757
|
+
/** App id to read promotions for. Required. */
|
|
2758
|
+
appId: string;
|
|
2759
|
+
/** Archetype of the compile in flight. Required. */
|
|
2760
|
+
archetype: IntentArchetypeName | string;
|
|
2761
|
+
}
|
|
2762
|
+
/**
|
|
2763
|
+
* Sync reader. Returns the active promotion for `(appId, archetype)` or
|
|
2764
|
+
* undefined. First call returns undefined and triggers async refresh;
|
|
2765
|
+
* subsequent calls within TTL return brain data. The brain enforces one
|
|
2766
|
+
* active promotion per surface (partial unique index), so at most one row
|
|
2767
|
+
* matches.
|
|
2768
|
+
*
|
|
2769
|
+
* NEVER throws. Not configured / brain down / cold → undefined.
|
|
2770
|
+
*/
|
|
2771
|
+
declare function getApplicablePromotion(opts: GetApplicablePromotionOpts): PromotionRow | undefined;
|
|
2772
|
+
/** Reset module state. Tests must call between cases. */
|
|
2773
|
+
declare function _testResetPromotions(): void;
|
|
2774
|
+
/** Wait for any in-flight refresh to settle. */
|
|
2775
|
+
declare function _testWaitForPromotionsRefresh(): Promise<void>;
|
|
2776
|
+
|
|
2633
2777
|
/**
|
|
2634
2778
|
* @warmdrift/kgauto v2 — prompt compiler + central learning brain.
|
|
2635
2779
|
*
|
|
@@ -2676,4 +2820,4 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
|
|
|
2676
2820
|
*/
|
|
2677
2821
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
2678
2822
|
|
|
2679
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
|
|
2823
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetApplicablePromotionOpts, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, type PromotionRow, type PromotionsRuntime, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, _testResetPromotions, _testWaitForPromotionsRefresh, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configurePromotionsBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isAutoPromoteEnabledFromEnv, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isPromotionsBrainActive, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
ARCHETYPE_FLOOR_DEFAULT: () => ARCHETYPE_FLOOR_DEFAULT,
|
|
28
28
|
CallError: () => CallError,
|
|
29
29
|
DEFAULT_FINDINGS_ENDPOINT: () => DEFAULT_FINDINGS_ENDPOINT,
|
|
30
|
+
DEFAULT_PROMOTIONS_ENDPOINT: () => DEFAULT_PROMOTIONS_ENDPOINT,
|
|
30
31
|
DIALECT_VERSION: () => DIALECT_VERSION,
|
|
31
32
|
FamilyResolutionError: () => FamilyResolutionError,
|
|
32
33
|
INTENT_ARCHETYPES: () => INTENT_ARCHETYPES,
|
|
@@ -38,6 +39,8 @@ __export(index_exports, {
|
|
|
38
39
|
PROVIDER_ENV_KEYS: () => PROVIDER_ENV_KEYS,
|
|
39
40
|
RULE_SEQUENTIAL_TOOL_CLIFF: () => RULE_SEQUENTIAL_TOOL_CLIFF,
|
|
40
41
|
TRANSLATOR_FLOOR: () => TRANSLATOR_FLOOR,
|
|
42
|
+
_testResetPromotions: () => _testResetPromotions,
|
|
43
|
+
_testWaitForPromotionsRefresh: () => _testWaitForPromotionsRefresh,
|
|
41
44
|
allProfiles: () => allProfiles,
|
|
42
45
|
applyArchetypeConvention: () => applyArchetypeConvention,
|
|
43
46
|
applySectionRewrites: () => applySectionRewrites,
|
|
@@ -57,6 +60,7 @@ __export(index_exports, {
|
|
|
57
60
|
compile: () => compile2,
|
|
58
61
|
compileForAISDKv6: () => compileForAISDKv6,
|
|
59
62
|
configureBrain: () => configureBrain,
|
|
63
|
+
configurePromotionsBrain: () => configurePromotionsBrain,
|
|
60
64
|
countTokens: () => countTokens,
|
|
61
65
|
createBrainForwardRoutes: () => createBrainForwardRoutes,
|
|
62
66
|
createKeyHealthRoute: () => createKeyHealthRoute,
|
|
@@ -68,6 +72,7 @@ __export(index_exports, {
|
|
|
68
72
|
getActionableAdvisories: () => getActionableAdvisories,
|
|
69
73
|
getAllStarterChains: () => getAllStarterChains,
|
|
70
74
|
getAllStarterChainsWithGrounding: () => getAllStarterChainsWithGrounding,
|
|
75
|
+
getApplicablePromotion: () => getApplicablePromotion,
|
|
71
76
|
getArchetypePerfScore: () => getArchetypePerfScore,
|
|
72
77
|
getDefaultFallbackChain: () => getDefaultFallbackChain,
|
|
73
78
|
getDefaultFallbackChainWithGrounding: () => getDefaultFallbackChainWithGrounding,
|
|
@@ -83,10 +88,12 @@ __export(index_exports, {
|
|
|
83
88
|
getStarterChainWithGrounding: () => getStarterChainWithGrounding,
|
|
84
89
|
hashShape: () => hashShape,
|
|
85
90
|
isArchetype: () => isArchetype,
|
|
91
|
+
isAutoPromoteEnabledFromEnv: () => isAutoPromoteEnabledFromEnv,
|
|
86
92
|
isBrainQueryActiveFor: () => isBrainQueryActiveFor,
|
|
87
93
|
isBrainSync: () => isBrainSync,
|
|
88
94
|
isExclusionFindingsBrainActive: () => isExclusionFindingsBrainActive,
|
|
89
95
|
isModelReachable: () => isModelReachable,
|
|
96
|
+
isPromotionsBrainActive: () => isPromotionsBrainActive,
|
|
90
97
|
isProviderReachable: () => isProviderReachable,
|
|
91
98
|
latencyTierOf: () => latencyTierOf,
|
|
92
99
|
learningKey: () => learningKey,
|
|
@@ -2602,6 +2609,7 @@ function passApplyCliffs(ir, profile, estimatedInputTokens) {
|
|
|
2602
2609
|
var LATENCY_OVERAGE_WEIGHT = 0.6;
|
|
2603
2610
|
var LATENCY_PENALTY_CAP = 1;
|
|
2604
2611
|
var QUALITY_GATE_PENALTY = 4;
|
|
2612
|
+
var PROMOTION_BOOST = 5;
|
|
2605
2613
|
function effectiveConventions(profile) {
|
|
2606
2614
|
const own = profile.archetypeConventions ?? [];
|
|
2607
2615
|
if (own.length > 0) return own;
|
|
@@ -2619,6 +2627,9 @@ function passScoreTargets(ir, opts) {
|
|
|
2619
2627
|
const preferredSet = new Set(policy.preferredModels ?? []);
|
|
2620
2628
|
const scores = [];
|
|
2621
2629
|
const policyMutations = [];
|
|
2630
|
+
const rawPromotion = opts.promotion;
|
|
2631
|
+
const promotionDeferred = rawPromotion !== void 0 && (policy.preferredModels?.length ?? 0) > 0;
|
|
2632
|
+
const promotion = promotionDeferred ? void 0 : rawPromotion;
|
|
2622
2633
|
const modelIds = ir.models.filter((m) => typeof m === "string");
|
|
2623
2634
|
for (const modelId of modelIds) {
|
|
2624
2635
|
let profile;
|
|
@@ -2683,7 +2694,12 @@ function passScoreTargets(ir, opts) {
|
|
|
2683
2694
|
);
|
|
2684
2695
|
if (schemaWeak) qualityGatePenalty = QUALITY_GATE_PENALTY;
|
|
2685
2696
|
}
|
|
2686
|
-
const
|
|
2697
|
+
const isPromoted = promotion?.promotedModel === modelId;
|
|
2698
|
+
if (isPromoted && promotion.suppressQualityGate) {
|
|
2699
|
+
qualityGatePenalty = 0;
|
|
2700
|
+
}
|
|
2701
|
+
const promotionBoost = isPromoted ? PROMOTION_BOOST : 0;
|
|
2702
|
+
const rank = qualityScore + callerOrderBoost - costPenalty - reasons.length * 10 + preferredBoost - latencyPenalty - qualityGatePenalty + promotionBoost;
|
|
2687
2703
|
scores.push({
|
|
2688
2704
|
modelId,
|
|
2689
2705
|
estimatedCostUsd,
|
|
@@ -2733,6 +2749,22 @@ function passScoreTargets(ir, opts) {
|
|
|
2733
2749
|
description: `Model ${modelId} gated below the quality floor for archetype '${ir.intent.archetype}' \u2014 declared structuredOutput + kgauto convention flags it schema-weak for this contract (structuredOutputHint:'avoid'). Down-ranked out of leadership; retained as graceful fallback only.`
|
|
2734
2750
|
});
|
|
2735
2751
|
}
|
|
2752
|
+
if (isPromoted && reasons.length === 0) {
|
|
2753
|
+
policyMutations.push({
|
|
2754
|
+
id: `promotion-applied-${modelId}`,
|
|
2755
|
+
source: "surface_promotion",
|
|
2756
|
+
passName: "score_targets",
|
|
2757
|
+
description: `Model ${modelId} boosted to surface leadership by active promotion #${promotion.id} (golden-eval run ${promotion.evalRunId ?? "n/a"}, Stage 2 auto-promote, 7-day rollback guard)` + (promotion.suppressQualityGate ? " \u2014 schema-weak quality gate suppressed for this tuple (eval measured the floor holding on real workload)" : "")
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
if (promotionDeferred && rawPromotion && modelIds.includes(rawPromotion.promotedModel)) {
|
|
2762
|
+
policyMutations.push({
|
|
2763
|
+
id: `promotion-deferred-consumer-preference-${rawPromotion.promotedModel}`,
|
|
2764
|
+
source: "surface_promotion",
|
|
2765
|
+
passName: "score_targets",
|
|
2766
|
+
description: `Active promotion #${rawPromotion.id} for ${rawPromotion.promotedModel} deferred \u2014 CompilePolicy.preferredModels is declared and explicit consumer preference outranks brain evidence.`
|
|
2767
|
+
});
|
|
2736
2768
|
}
|
|
2737
2769
|
return { value: scores, mutations: policyMutations };
|
|
2738
2770
|
}
|
|
@@ -4121,6 +4153,130 @@ ${originalText}`;
|
|
|
4121
4153
|
return { rewrittenIR, rewrites };
|
|
4122
4154
|
}
|
|
4123
4155
|
|
|
4156
|
+
// src/promotions-brain.ts
|
|
4157
|
+
function isRawPromotionRow(x) {
|
|
4158
|
+
if (!x || typeof x !== "object") return false;
|
|
4159
|
+
const r = x;
|
|
4160
|
+
return (typeof r.id === "number" || typeof r.id === "string") && typeof r.intent_archetype === "string" && typeof r.promoted_model === "string" && typeof r.incumbent_model === "string";
|
|
4161
|
+
}
|
|
4162
|
+
function coerceId(v) {
|
|
4163
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
|
4164
|
+
if (typeof v === "string") {
|
|
4165
|
+
const n = Number(v);
|
|
4166
|
+
return Number.isFinite(n) ? n : null;
|
|
4167
|
+
}
|
|
4168
|
+
return null;
|
|
4169
|
+
}
|
|
4170
|
+
function mapRowsToPromotions(rows) {
|
|
4171
|
+
const out = [];
|
|
4172
|
+
for (const row of rows) {
|
|
4173
|
+
if (!isRawPromotionRow(row)) continue;
|
|
4174
|
+
const id = coerceId(row.id);
|
|
4175
|
+
if (id === null) continue;
|
|
4176
|
+
out.push({
|
|
4177
|
+
id,
|
|
4178
|
+
archetype: row.intent_archetype,
|
|
4179
|
+
promotedModel: row.promoted_model,
|
|
4180
|
+
incumbentModel: row.incumbent_model,
|
|
4181
|
+
evalRunId: coerceId(row.eval_run_id ?? null),
|
|
4182
|
+
suppressQualityGate: row.suppress_quality_gate === true,
|
|
4183
|
+
promotedAt: typeof row.promoted_at === "string" ? row.promoted_at : ""
|
|
4184
|
+
});
|
|
4185
|
+
}
|
|
4186
|
+
return out;
|
|
4187
|
+
}
|
|
4188
|
+
var snapshots4 = /* @__PURE__ */ new Map();
|
|
4189
|
+
var runtime5;
|
|
4190
|
+
var warnedOnce4 = false;
|
|
4191
|
+
var DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
|
|
4192
|
+
function isAutoPromoteEnabledFromEnv(envSource) {
|
|
4193
|
+
const env = envSource ?? (typeof process !== "undefined" && process.env ? process.env : {});
|
|
4194
|
+
const raw = (env.KGAUTO_AUTO_PROMOTE ?? "").trim().toLowerCase();
|
|
4195
|
+
return raw === "1" || raw === "true";
|
|
4196
|
+
}
|
|
4197
|
+
function configurePromotionsBrain(rt) {
|
|
4198
|
+
runtime5 = rt;
|
|
4199
|
+
snapshots4.clear();
|
|
4200
|
+
warnedOnce4 = false;
|
|
4201
|
+
}
|
|
4202
|
+
function isPromotionsBrainActive() {
|
|
4203
|
+
return runtime5 !== void 0;
|
|
4204
|
+
}
|
|
4205
|
+
function getApplicablePromotion(opts) {
|
|
4206
|
+
const rt = runtime5;
|
|
4207
|
+
if (!rt) return void 0;
|
|
4208
|
+
const appId = opts.appId;
|
|
4209
|
+
if (!appId || !opts.archetype) return void 0;
|
|
4210
|
+
let snap = snapshots4.get(appId);
|
|
4211
|
+
if (!snap) {
|
|
4212
|
+
snap = { data: [], expiresAt: 0, refreshing: false };
|
|
4213
|
+
snapshots4.set(appId, snap);
|
|
4214
|
+
}
|
|
4215
|
+
const now = Date.now();
|
|
4216
|
+
const stale = snap.expiresAt <= now;
|
|
4217
|
+
if (stale && !snap.refreshing) {
|
|
4218
|
+
snap.refreshing = true;
|
|
4219
|
+
void asyncRefresh5(rt, appId);
|
|
4220
|
+
}
|
|
4221
|
+
return snap.data.find((p) => p.archetype === opts.archetype);
|
|
4222
|
+
}
|
|
4223
|
+
var pendingRefreshes4 = /* @__PURE__ */ new Map();
|
|
4224
|
+
async function asyncRefresh5(rt, appId) {
|
|
4225
|
+
const promise = doRefresh5(rt, appId);
|
|
4226
|
+
pendingRefreshes4.set(appId, promise);
|
|
4227
|
+
try {
|
|
4228
|
+
await promise;
|
|
4229
|
+
} finally {
|
|
4230
|
+
if (pendingRefreshes4.get(appId) === promise) {
|
|
4231
|
+
pendingRefreshes4.delete(appId);
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
}
|
|
4235
|
+
async function doRefresh5(rt, appId) {
|
|
4236
|
+
const url = `${rt.endpoint}?app_id=${encodeURIComponent(appId)}`;
|
|
4237
|
+
let snap = snapshots4.get(appId);
|
|
4238
|
+
if (!snap) {
|
|
4239
|
+
snap = { data: [], expiresAt: 0, refreshing: false };
|
|
4240
|
+
snapshots4.set(appId, snap);
|
|
4241
|
+
}
|
|
4242
|
+
try {
|
|
4243
|
+
const res = await rt.fetchImpl(url, { method: "GET" });
|
|
4244
|
+
if (!res.ok) {
|
|
4245
|
+
throw new Error(`promotions ${res.status}: ${res.statusText}`);
|
|
4246
|
+
}
|
|
4247
|
+
const body = await res.json();
|
|
4248
|
+
if (runtime5 !== rt) return;
|
|
4249
|
+
const rows = Array.isArray(body) ? mapRowsToPromotions(body) : [];
|
|
4250
|
+
snap.data = rows;
|
|
4251
|
+
snap.expiresAt = Date.now() + rt.ttlMs;
|
|
4252
|
+
snap.refreshing = false;
|
|
4253
|
+
} catch (err) {
|
|
4254
|
+
if (runtime5 !== rt) return;
|
|
4255
|
+
snap.refreshing = false;
|
|
4256
|
+
snap.expiresAt = Date.now() + rt.ttlMs;
|
|
4257
|
+
if (!warnedOnce4) {
|
|
4258
|
+
warnedOnce4 = true;
|
|
4259
|
+
(rt.onError ?? defaultOnError5)(err);
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
function defaultOnError5(err) {
|
|
4264
|
+
console.warn(
|
|
4265
|
+
"[kgauto] promotions fetch failed (promotion boost inactive until next refresh):",
|
|
4266
|
+
err
|
|
4267
|
+
);
|
|
4268
|
+
}
|
|
4269
|
+
function _testResetPromotions() {
|
|
4270
|
+
runtime5 = void 0;
|
|
4271
|
+
snapshots4.clear();
|
|
4272
|
+
pendingRefreshes4 = /* @__PURE__ */ new Map();
|
|
4273
|
+
warnedOnce4 = false;
|
|
4274
|
+
}
|
|
4275
|
+
async function _testWaitForPromotionsRefresh() {
|
|
4276
|
+
const pending = Array.from(pendingRefreshes4.values());
|
|
4277
|
+
if (pending.length > 0) await Promise.all(pending);
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4124
4280
|
// src/compile.ts
|
|
4125
4281
|
var counter = 0;
|
|
4126
4282
|
function makeHandle() {
|
|
@@ -4147,11 +4303,22 @@ function compile(ir, opts = {}) {
|
|
|
4147
4303
|
...toolFiltered.mutations,
|
|
4148
4304
|
...compressed.mutations
|
|
4149
4305
|
];
|
|
4306
|
+
const activePromotion = getApplicablePromotion({
|
|
4307
|
+
appId: ir.appId,
|
|
4308
|
+
archetype: ir.intent.archetype
|
|
4309
|
+
});
|
|
4310
|
+
const promotion = activePromotion ? {
|
|
4311
|
+
id: activePromotion.id,
|
|
4312
|
+
promotedModel: activePromotion.promotedModel,
|
|
4313
|
+
evalRunId: activePromotion.evalRunId,
|
|
4314
|
+
suppressQualityGate: activePromotion.suppressQualityGate
|
|
4315
|
+
} : void 0;
|
|
4150
4316
|
const inputTokens = estimateInputTokens(workingIR);
|
|
4151
4317
|
const scores = passScoreTargets(workingIR, {
|
|
4152
4318
|
estimatedInputTokens: inputTokens,
|
|
4153
4319
|
profilesById: resolver,
|
|
4154
|
-
policy: opts.policy
|
|
4320
|
+
policy: opts.policy,
|
|
4321
|
+
promotion
|
|
4155
4322
|
});
|
|
4156
4323
|
accumulatedMutations.push(...scores.mutations);
|
|
4157
4324
|
const target = pickTarget(workingIR, scores.value);
|
|
@@ -4483,11 +4650,23 @@ function configureBrain(config) {
|
|
|
4483
4650
|
} else {
|
|
4484
4651
|
configureExclusionFindingsBrain(void 0);
|
|
4485
4652
|
}
|
|
4653
|
+
const promotionsConsent = config.autoPromote ?? isAutoPromoteEnabledFromEnv();
|
|
4654
|
+
if (promotionsConsent && bq.promotions !== false) {
|
|
4655
|
+
configurePromotionsBrain({
|
|
4656
|
+
endpoint: bq.promotionsEndpoint ?? DEFAULT_PROMOTIONS_ENDPOINT,
|
|
4657
|
+
ttlMs: bq.cacheTtlMs ?? 3e5,
|
|
4658
|
+
fetchImpl: config.fetchImpl ?? fetch,
|
|
4659
|
+
onError: config.onError
|
|
4660
|
+
});
|
|
4661
|
+
} else {
|
|
4662
|
+
configurePromotionsBrain(void 0);
|
|
4663
|
+
}
|
|
4486
4664
|
}
|
|
4487
4665
|
function clearBrain() {
|
|
4488
4666
|
activeConfig = void 0;
|
|
4489
4667
|
configureBrainQuery(void 0);
|
|
4490
4668
|
configureExclusionFindingsBrain(void 0);
|
|
4669
|
+
configurePromotionsBrain(void 0);
|
|
4491
4670
|
}
|
|
4492
4671
|
var DEAD_LETTER_MAX_ENTRIES = 50;
|
|
4493
4672
|
var DEAD_LETTER_MAX_ATTEMPTS = 3;
|
|
@@ -4604,7 +4783,7 @@ async function flushBrainDeadLetter() {
|
|
|
4604
4783
|
if (entry.attempts >= DEAD_LETTER_MAX_ATTEMPTS) {
|
|
4605
4784
|
const idx = deadLetter.indexOf(entry);
|
|
4606
4785
|
if (idx !== -1) deadLetter.splice(idx, 1);
|
|
4607
|
-
(config.onError ??
|
|
4786
|
+
(config.onError ?? defaultOnError6)(
|
|
4608
4787
|
new Error(
|
|
4609
4788
|
`brain dead-letter: dropping ${entry.route} payload after ${entry.attempts} attempts \u2014 last error: ${entry.lastError}`
|
|
4610
4789
|
)
|
|
@@ -4754,7 +4933,7 @@ async function record(input) {
|
|
|
4754
4933
|
} catch (err) {
|
|
4755
4934
|
noteFailure(err);
|
|
4756
4935
|
pushDeadLetter("outcomes", config.endpoint, payload, err);
|
|
4757
|
-
(config.onError ??
|
|
4936
|
+
(config.onError ?? defaultOnError6)(err);
|
|
4758
4937
|
return;
|
|
4759
4938
|
}
|
|
4760
4939
|
maybeAutoFlush();
|
|
@@ -4782,7 +4961,7 @@ async function record(input) {
|
|
|
4782
4961
|
} catch (err) {
|
|
4783
4962
|
noteFailure(err);
|
|
4784
4963
|
pushDeadLetter("compile_outcome_advisories", config.endpoint, advisoryPayload, err);
|
|
4785
|
-
(config.onError ??
|
|
4964
|
+
(config.onError ?? defaultOnError6)(err);
|
|
4786
4965
|
}
|
|
4787
4966
|
};
|
|
4788
4967
|
if (config.sync) {
|
|
@@ -4791,7 +4970,7 @@ async function record(input) {
|
|
|
4791
4970
|
void send();
|
|
4792
4971
|
}
|
|
4793
4972
|
}
|
|
4794
|
-
function
|
|
4973
|
+
function defaultOnError6(err) {
|
|
4795
4974
|
console.warn("[kgauto] brain record failed:", err);
|
|
4796
4975
|
}
|
|
4797
4976
|
function describeBrainWriteFailure(status, route, body) {
|
|
@@ -4943,7 +5122,7 @@ async function recordOutcome(input) {
|
|
|
4943
5122
|
} catch (err) {
|
|
4944
5123
|
noteFailure(err);
|
|
4945
5124
|
pushDeadLetter("compile_outcome_quality", config.endpoint, payload, err);
|
|
4946
|
-
(config.onError ??
|
|
5125
|
+
(config.onError ?? defaultOnError6)(err);
|
|
4947
5126
|
return { ok: false, reason: "persistence_failed" };
|
|
4948
5127
|
}
|
|
4949
5128
|
};
|
|
@@ -5014,7 +5193,7 @@ async function recordShadowProbe(input) {
|
|
|
5014
5193
|
} catch (err) {
|
|
5015
5194
|
noteFailure(err);
|
|
5016
5195
|
pushDeadLetter("probe_outcomes", config.endpoint, row, err);
|
|
5017
|
-
(config.onError ??
|
|
5196
|
+
(config.onError ?? defaultOnError6)(err);
|
|
5018
5197
|
}
|
|
5019
5198
|
};
|
|
5020
5199
|
if (config.sync) {
|
|
@@ -5069,7 +5248,7 @@ async function recordGoldenIr(input) {
|
|
|
5069
5248
|
} catch (err) {
|
|
5070
5249
|
noteFailure(err);
|
|
5071
5250
|
pushDeadLetter("golden_irs", config.endpoint, row, err);
|
|
5072
|
-
(config.onError ??
|
|
5251
|
+
(config.onError ?? defaultOnError6)(err);
|
|
5073
5252
|
}
|
|
5074
5253
|
};
|
|
5075
5254
|
if (config.sync) {
|
|
@@ -7173,6 +7352,9 @@ function combineOrderSwappedVerdicts(run1, run2) {
|
|
|
7173
7352
|
if (run1 === run2) return run1;
|
|
7174
7353
|
return "tied";
|
|
7175
7354
|
}
|
|
7355
|
+
function replayRetryDelayMs(errorCode) {
|
|
7356
|
+
return errorCode === "rate_limit" ? 65e3 : 2e3;
|
|
7357
|
+
}
|
|
7176
7358
|
function p50(values) {
|
|
7177
7359
|
if (values.length === 0) return null;
|
|
7178
7360
|
const sorted = [...values].sort((a, b) => a - b);
|
|
@@ -7258,7 +7440,8 @@ async function runGoldenEval(opts) {
|
|
|
7258
7440
|
let started = Date.now();
|
|
7259
7441
|
let exec = await attempt();
|
|
7260
7442
|
if (!exec.ok && exec.errorType === "retryable") {
|
|
7261
|
-
|
|
7443
|
+
const delayMs = replayRetryDelayMs(exec.errorCode);
|
|
7444
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
7262
7445
|
started = Date.now();
|
|
7263
7446
|
exec = await attempt();
|
|
7264
7447
|
}
|
|
@@ -7765,7 +7948,7 @@ function createBrainForwardRoutes(config) {
|
|
|
7765
7948
|
}
|
|
7766
7949
|
|
|
7767
7950
|
// src/version.ts
|
|
7768
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
7951
|
+
var LIBRARY_VERSION = "2.0.0-alpha.64";
|
|
7769
7952
|
|
|
7770
7953
|
// src/key-health.ts
|
|
7771
7954
|
var JSON_HEADERS2 = { "Content-Type": "application/json" };
|
|
@@ -8385,6 +8568,7 @@ function compile2(ir, opts) {
|
|
|
8385
8568
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
8386
8569
|
CallError,
|
|
8387
8570
|
DEFAULT_FINDINGS_ENDPOINT,
|
|
8571
|
+
DEFAULT_PROMOTIONS_ENDPOINT,
|
|
8388
8572
|
DIALECT_VERSION,
|
|
8389
8573
|
FamilyResolutionError,
|
|
8390
8574
|
INTENT_ARCHETYPES,
|
|
@@ -8396,6 +8580,8 @@ function compile2(ir, opts) {
|
|
|
8396
8580
|
PROVIDER_ENV_KEYS,
|
|
8397
8581
|
RULE_SEQUENTIAL_TOOL_CLIFF,
|
|
8398
8582
|
TRANSLATOR_FLOOR,
|
|
8583
|
+
_testResetPromotions,
|
|
8584
|
+
_testWaitForPromotionsRefresh,
|
|
8399
8585
|
allProfiles,
|
|
8400
8586
|
applyArchetypeConvention,
|
|
8401
8587
|
applySectionRewrites,
|
|
@@ -8415,6 +8601,7 @@ function compile2(ir, opts) {
|
|
|
8415
8601
|
compile,
|
|
8416
8602
|
compileForAISDKv6,
|
|
8417
8603
|
configureBrain,
|
|
8604
|
+
configurePromotionsBrain,
|
|
8418
8605
|
countTokens,
|
|
8419
8606
|
createBrainForwardRoutes,
|
|
8420
8607
|
createKeyHealthRoute,
|
|
@@ -8426,6 +8613,7 @@ function compile2(ir, opts) {
|
|
|
8426
8613
|
getActionableAdvisories,
|
|
8427
8614
|
getAllStarterChains,
|
|
8428
8615
|
getAllStarterChainsWithGrounding,
|
|
8616
|
+
getApplicablePromotion,
|
|
8429
8617
|
getArchetypePerfScore,
|
|
8430
8618
|
getDefaultFallbackChain,
|
|
8431
8619
|
getDefaultFallbackChainWithGrounding,
|
|
@@ -8441,10 +8629,12 @@ function compile2(ir, opts) {
|
|
|
8441
8629
|
getStarterChainWithGrounding,
|
|
8442
8630
|
hashShape,
|
|
8443
8631
|
isArchetype,
|
|
8632
|
+
isAutoPromoteEnabledFromEnv,
|
|
8444
8633
|
isBrainQueryActiveFor,
|
|
8445
8634
|
isBrainSync,
|
|
8446
8635
|
isExclusionFindingsBrainActive,
|
|
8447
8636
|
isModelReachable,
|
|
8637
|
+
isPromotionsBrainActive,
|
|
8448
8638
|
isProviderReachable,
|
|
8449
8639
|
latencyTierOf,
|
|
8450
8640
|
learningKey,
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
LIBRARY_VERSION,
|
|
17
17
|
createKeyHealthRoute
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-DGPYLFDG.mjs";
|
|
19
19
|
import {
|
|
20
20
|
ABSOLUTE_FLOOR,
|
|
21
21
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
@@ -739,6 +739,7 @@ function passApplyCliffs(ir, profile, estimatedInputTokens) {
|
|
|
739
739
|
var LATENCY_OVERAGE_WEIGHT = 0.6;
|
|
740
740
|
var LATENCY_PENALTY_CAP = 1;
|
|
741
741
|
var QUALITY_GATE_PENALTY = 4;
|
|
742
|
+
var PROMOTION_BOOST = 5;
|
|
742
743
|
function effectiveConventions(profile) {
|
|
743
744
|
const own = profile.archetypeConventions ?? [];
|
|
744
745
|
if (own.length > 0) return own;
|
|
@@ -756,6 +757,9 @@ function passScoreTargets(ir, opts) {
|
|
|
756
757
|
const preferredSet = new Set(policy.preferredModels ?? []);
|
|
757
758
|
const scores = [];
|
|
758
759
|
const policyMutations = [];
|
|
760
|
+
const rawPromotion = opts.promotion;
|
|
761
|
+
const promotionDeferred = rawPromotion !== void 0 && (policy.preferredModels?.length ?? 0) > 0;
|
|
762
|
+
const promotion = promotionDeferred ? void 0 : rawPromotion;
|
|
759
763
|
const modelIds = ir.models.filter((m) => typeof m === "string");
|
|
760
764
|
for (const modelId of modelIds) {
|
|
761
765
|
let profile;
|
|
@@ -820,7 +824,12 @@ function passScoreTargets(ir, opts) {
|
|
|
820
824
|
);
|
|
821
825
|
if (schemaWeak) qualityGatePenalty = QUALITY_GATE_PENALTY;
|
|
822
826
|
}
|
|
823
|
-
const
|
|
827
|
+
const isPromoted = promotion?.promotedModel === modelId;
|
|
828
|
+
if (isPromoted && promotion.suppressQualityGate) {
|
|
829
|
+
qualityGatePenalty = 0;
|
|
830
|
+
}
|
|
831
|
+
const promotionBoost = isPromoted ? PROMOTION_BOOST : 0;
|
|
832
|
+
const rank = qualityScore + callerOrderBoost - costPenalty - reasons.length * 10 + preferredBoost - latencyPenalty - qualityGatePenalty + promotionBoost;
|
|
824
833
|
scores.push({
|
|
825
834
|
modelId,
|
|
826
835
|
estimatedCostUsd,
|
|
@@ -870,6 +879,22 @@ function passScoreTargets(ir, opts) {
|
|
|
870
879
|
description: `Model ${modelId} gated below the quality floor for archetype '${ir.intent.archetype}' \u2014 declared structuredOutput + kgauto convention flags it schema-weak for this contract (structuredOutputHint:'avoid'). Down-ranked out of leadership; retained as graceful fallback only.`
|
|
871
880
|
});
|
|
872
881
|
}
|
|
882
|
+
if (isPromoted && reasons.length === 0) {
|
|
883
|
+
policyMutations.push({
|
|
884
|
+
id: `promotion-applied-${modelId}`,
|
|
885
|
+
source: "surface_promotion",
|
|
886
|
+
passName: "score_targets",
|
|
887
|
+
description: `Model ${modelId} boosted to surface leadership by active promotion #${promotion.id} (golden-eval run ${promotion.evalRunId ?? "n/a"}, Stage 2 auto-promote, 7-day rollback guard)` + (promotion.suppressQualityGate ? " \u2014 schema-weak quality gate suppressed for this tuple (eval measured the floor holding on real workload)" : "")
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (promotionDeferred && rawPromotion && modelIds.includes(rawPromotion.promotedModel)) {
|
|
892
|
+
policyMutations.push({
|
|
893
|
+
id: `promotion-deferred-consumer-preference-${rawPromotion.promotedModel}`,
|
|
894
|
+
source: "surface_promotion",
|
|
895
|
+
passName: "score_targets",
|
|
896
|
+
description: `Active promotion #${rawPromotion.id} for ${rawPromotion.promotedModel} deferred \u2014 CompilePolicy.preferredModels is declared and explicit consumer preference outranks brain evidence.`
|
|
897
|
+
});
|
|
873
898
|
}
|
|
874
899
|
return { value: scores, mutations: policyMutations };
|
|
875
900
|
}
|
|
@@ -2258,6 +2283,130 @@ ${originalText}`;
|
|
|
2258
2283
|
return { rewrittenIR, rewrites };
|
|
2259
2284
|
}
|
|
2260
2285
|
|
|
2286
|
+
// src/promotions-brain.ts
|
|
2287
|
+
function isRawPromotionRow(x) {
|
|
2288
|
+
if (!x || typeof x !== "object") return false;
|
|
2289
|
+
const r = x;
|
|
2290
|
+
return (typeof r.id === "number" || typeof r.id === "string") && typeof r.intent_archetype === "string" && typeof r.promoted_model === "string" && typeof r.incumbent_model === "string";
|
|
2291
|
+
}
|
|
2292
|
+
function coerceId(v) {
|
|
2293
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
|
2294
|
+
if (typeof v === "string") {
|
|
2295
|
+
const n = Number(v);
|
|
2296
|
+
return Number.isFinite(n) ? n : null;
|
|
2297
|
+
}
|
|
2298
|
+
return null;
|
|
2299
|
+
}
|
|
2300
|
+
function mapRowsToPromotions(rows) {
|
|
2301
|
+
const out = [];
|
|
2302
|
+
for (const row of rows) {
|
|
2303
|
+
if (!isRawPromotionRow(row)) continue;
|
|
2304
|
+
const id = coerceId(row.id);
|
|
2305
|
+
if (id === null) continue;
|
|
2306
|
+
out.push({
|
|
2307
|
+
id,
|
|
2308
|
+
archetype: row.intent_archetype,
|
|
2309
|
+
promotedModel: row.promoted_model,
|
|
2310
|
+
incumbentModel: row.incumbent_model,
|
|
2311
|
+
evalRunId: coerceId(row.eval_run_id ?? null),
|
|
2312
|
+
suppressQualityGate: row.suppress_quality_gate === true,
|
|
2313
|
+
promotedAt: typeof row.promoted_at === "string" ? row.promoted_at : ""
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
return out;
|
|
2317
|
+
}
|
|
2318
|
+
var snapshots4 = /* @__PURE__ */ new Map();
|
|
2319
|
+
var runtime4;
|
|
2320
|
+
var warnedOnce4 = false;
|
|
2321
|
+
var DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
|
|
2322
|
+
function isAutoPromoteEnabledFromEnv(envSource) {
|
|
2323
|
+
const env = envSource ?? (typeof process !== "undefined" && process.env ? process.env : {});
|
|
2324
|
+
const raw = (env.KGAUTO_AUTO_PROMOTE ?? "").trim().toLowerCase();
|
|
2325
|
+
return raw === "1" || raw === "true";
|
|
2326
|
+
}
|
|
2327
|
+
function configurePromotionsBrain(rt) {
|
|
2328
|
+
runtime4 = rt;
|
|
2329
|
+
snapshots4.clear();
|
|
2330
|
+
warnedOnce4 = false;
|
|
2331
|
+
}
|
|
2332
|
+
function isPromotionsBrainActive() {
|
|
2333
|
+
return runtime4 !== void 0;
|
|
2334
|
+
}
|
|
2335
|
+
function getApplicablePromotion(opts) {
|
|
2336
|
+
const rt = runtime4;
|
|
2337
|
+
if (!rt) return void 0;
|
|
2338
|
+
const appId = opts.appId;
|
|
2339
|
+
if (!appId || !opts.archetype) return void 0;
|
|
2340
|
+
let snap = snapshots4.get(appId);
|
|
2341
|
+
if (!snap) {
|
|
2342
|
+
snap = { data: [], expiresAt: 0, refreshing: false };
|
|
2343
|
+
snapshots4.set(appId, snap);
|
|
2344
|
+
}
|
|
2345
|
+
const now = Date.now();
|
|
2346
|
+
const stale = snap.expiresAt <= now;
|
|
2347
|
+
if (stale && !snap.refreshing) {
|
|
2348
|
+
snap.refreshing = true;
|
|
2349
|
+
void asyncRefresh4(rt, appId);
|
|
2350
|
+
}
|
|
2351
|
+
return snap.data.find((p) => p.archetype === opts.archetype);
|
|
2352
|
+
}
|
|
2353
|
+
var pendingRefreshes4 = /* @__PURE__ */ new Map();
|
|
2354
|
+
async function asyncRefresh4(rt, appId) {
|
|
2355
|
+
const promise = doRefresh4(rt, appId);
|
|
2356
|
+
pendingRefreshes4.set(appId, promise);
|
|
2357
|
+
try {
|
|
2358
|
+
await promise;
|
|
2359
|
+
} finally {
|
|
2360
|
+
if (pendingRefreshes4.get(appId) === promise) {
|
|
2361
|
+
pendingRefreshes4.delete(appId);
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
async function doRefresh4(rt, appId) {
|
|
2366
|
+
const url = `${rt.endpoint}?app_id=${encodeURIComponent(appId)}`;
|
|
2367
|
+
let snap = snapshots4.get(appId);
|
|
2368
|
+
if (!snap) {
|
|
2369
|
+
snap = { data: [], expiresAt: 0, refreshing: false };
|
|
2370
|
+
snapshots4.set(appId, snap);
|
|
2371
|
+
}
|
|
2372
|
+
try {
|
|
2373
|
+
const res = await rt.fetchImpl(url, { method: "GET" });
|
|
2374
|
+
if (!res.ok) {
|
|
2375
|
+
throw new Error(`promotions ${res.status}: ${res.statusText}`);
|
|
2376
|
+
}
|
|
2377
|
+
const body = await res.json();
|
|
2378
|
+
if (runtime4 !== rt) return;
|
|
2379
|
+
const rows = Array.isArray(body) ? mapRowsToPromotions(body) : [];
|
|
2380
|
+
snap.data = rows;
|
|
2381
|
+
snap.expiresAt = Date.now() + rt.ttlMs;
|
|
2382
|
+
snap.refreshing = false;
|
|
2383
|
+
} catch (err) {
|
|
2384
|
+
if (runtime4 !== rt) return;
|
|
2385
|
+
snap.refreshing = false;
|
|
2386
|
+
snap.expiresAt = Date.now() + rt.ttlMs;
|
|
2387
|
+
if (!warnedOnce4) {
|
|
2388
|
+
warnedOnce4 = true;
|
|
2389
|
+
(rt.onError ?? defaultOnError4)(err);
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
function defaultOnError4(err) {
|
|
2394
|
+
console.warn(
|
|
2395
|
+
"[kgauto] promotions fetch failed (promotion boost inactive until next refresh):",
|
|
2396
|
+
err
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
function _testResetPromotions() {
|
|
2400
|
+
runtime4 = void 0;
|
|
2401
|
+
snapshots4.clear();
|
|
2402
|
+
pendingRefreshes4 = /* @__PURE__ */ new Map();
|
|
2403
|
+
warnedOnce4 = false;
|
|
2404
|
+
}
|
|
2405
|
+
async function _testWaitForPromotionsRefresh() {
|
|
2406
|
+
const pending = Array.from(pendingRefreshes4.values());
|
|
2407
|
+
if (pending.length > 0) await Promise.all(pending);
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2261
2410
|
// src/compile.ts
|
|
2262
2411
|
var counter = 0;
|
|
2263
2412
|
function makeHandle() {
|
|
@@ -2284,11 +2433,22 @@ function compile(ir, opts = {}) {
|
|
|
2284
2433
|
...toolFiltered.mutations,
|
|
2285
2434
|
...compressed.mutations
|
|
2286
2435
|
];
|
|
2436
|
+
const activePromotion = getApplicablePromotion({
|
|
2437
|
+
appId: ir.appId,
|
|
2438
|
+
archetype: ir.intent.archetype
|
|
2439
|
+
});
|
|
2440
|
+
const promotion = activePromotion ? {
|
|
2441
|
+
id: activePromotion.id,
|
|
2442
|
+
promotedModel: activePromotion.promotedModel,
|
|
2443
|
+
evalRunId: activePromotion.evalRunId,
|
|
2444
|
+
suppressQualityGate: activePromotion.suppressQualityGate
|
|
2445
|
+
} : void 0;
|
|
2287
2446
|
const inputTokens = estimateInputTokens(workingIR);
|
|
2288
2447
|
const scores = passScoreTargets(workingIR, {
|
|
2289
2448
|
estimatedInputTokens: inputTokens,
|
|
2290
2449
|
profilesById: resolver,
|
|
2291
|
-
policy: opts.policy
|
|
2450
|
+
policy: opts.policy,
|
|
2451
|
+
promotion
|
|
2292
2452
|
});
|
|
2293
2453
|
accumulatedMutations.push(...scores.mutations);
|
|
2294
2454
|
const target = pickTarget(workingIR, scores.value);
|
|
@@ -2620,11 +2780,23 @@ function configureBrain(config) {
|
|
|
2620
2780
|
} else {
|
|
2621
2781
|
configureExclusionFindingsBrain(void 0);
|
|
2622
2782
|
}
|
|
2783
|
+
const promotionsConsent = config.autoPromote ?? isAutoPromoteEnabledFromEnv();
|
|
2784
|
+
if (promotionsConsent && bq.promotions !== false) {
|
|
2785
|
+
configurePromotionsBrain({
|
|
2786
|
+
endpoint: bq.promotionsEndpoint ?? DEFAULT_PROMOTIONS_ENDPOINT,
|
|
2787
|
+
ttlMs: bq.cacheTtlMs ?? 3e5,
|
|
2788
|
+
fetchImpl: config.fetchImpl ?? fetch,
|
|
2789
|
+
onError: config.onError
|
|
2790
|
+
});
|
|
2791
|
+
} else {
|
|
2792
|
+
configurePromotionsBrain(void 0);
|
|
2793
|
+
}
|
|
2623
2794
|
}
|
|
2624
2795
|
function clearBrain() {
|
|
2625
2796
|
activeConfig = void 0;
|
|
2626
2797
|
configureBrainQuery(void 0);
|
|
2627
2798
|
configureExclusionFindingsBrain(void 0);
|
|
2799
|
+
configurePromotionsBrain(void 0);
|
|
2628
2800
|
}
|
|
2629
2801
|
var DEAD_LETTER_MAX_ENTRIES = 50;
|
|
2630
2802
|
var DEAD_LETTER_MAX_ATTEMPTS = 3;
|
|
@@ -2741,7 +2913,7 @@ async function flushBrainDeadLetter() {
|
|
|
2741
2913
|
if (entry.attempts >= DEAD_LETTER_MAX_ATTEMPTS) {
|
|
2742
2914
|
const idx = deadLetter.indexOf(entry);
|
|
2743
2915
|
if (idx !== -1) deadLetter.splice(idx, 1);
|
|
2744
|
-
(config.onError ??
|
|
2916
|
+
(config.onError ?? defaultOnError5)(
|
|
2745
2917
|
new Error(
|
|
2746
2918
|
`brain dead-letter: dropping ${entry.route} payload after ${entry.attempts} attempts \u2014 last error: ${entry.lastError}`
|
|
2747
2919
|
)
|
|
@@ -2891,7 +3063,7 @@ async function record(input) {
|
|
|
2891
3063
|
} catch (err) {
|
|
2892
3064
|
noteFailure(err);
|
|
2893
3065
|
pushDeadLetter("outcomes", config.endpoint, payload, err);
|
|
2894
|
-
(config.onError ??
|
|
3066
|
+
(config.onError ?? defaultOnError5)(err);
|
|
2895
3067
|
return;
|
|
2896
3068
|
}
|
|
2897
3069
|
maybeAutoFlush();
|
|
@@ -2919,7 +3091,7 @@ async function record(input) {
|
|
|
2919
3091
|
} catch (err) {
|
|
2920
3092
|
noteFailure(err);
|
|
2921
3093
|
pushDeadLetter("compile_outcome_advisories", config.endpoint, advisoryPayload, err);
|
|
2922
|
-
(config.onError ??
|
|
3094
|
+
(config.onError ?? defaultOnError5)(err);
|
|
2923
3095
|
}
|
|
2924
3096
|
};
|
|
2925
3097
|
if (config.sync) {
|
|
@@ -2928,7 +3100,7 @@ async function record(input) {
|
|
|
2928
3100
|
void send();
|
|
2929
3101
|
}
|
|
2930
3102
|
}
|
|
2931
|
-
function
|
|
3103
|
+
function defaultOnError5(err) {
|
|
2932
3104
|
console.warn("[kgauto] brain record failed:", err);
|
|
2933
3105
|
}
|
|
2934
3106
|
function describeBrainWriteFailure(status, route, body) {
|
|
@@ -3080,7 +3252,7 @@ async function recordOutcome(input) {
|
|
|
3080
3252
|
} catch (err) {
|
|
3081
3253
|
noteFailure(err);
|
|
3082
3254
|
pushDeadLetter("compile_outcome_quality", config.endpoint, payload, err);
|
|
3083
|
-
(config.onError ??
|
|
3255
|
+
(config.onError ?? defaultOnError5)(err);
|
|
3084
3256
|
return { ok: false, reason: "persistence_failed" };
|
|
3085
3257
|
}
|
|
3086
3258
|
};
|
|
@@ -3151,7 +3323,7 @@ async function recordShadowProbe(input) {
|
|
|
3151
3323
|
} catch (err) {
|
|
3152
3324
|
noteFailure(err);
|
|
3153
3325
|
pushDeadLetter("probe_outcomes", config.endpoint, row, err);
|
|
3154
|
-
(config.onError ??
|
|
3326
|
+
(config.onError ?? defaultOnError5)(err);
|
|
3155
3327
|
}
|
|
3156
3328
|
};
|
|
3157
3329
|
if (config.sync) {
|
|
@@ -3206,7 +3378,7 @@ async function recordGoldenIr(input) {
|
|
|
3206
3378
|
} catch (err) {
|
|
3207
3379
|
noteFailure(err);
|
|
3208
3380
|
pushDeadLetter("golden_irs", config.endpoint, row, err);
|
|
3209
|
-
(config.onError ??
|
|
3381
|
+
(config.onError ?? defaultOnError5)(err);
|
|
3210
3382
|
}
|
|
3211
3383
|
};
|
|
3212
3384
|
if (config.sync) {
|
|
@@ -4585,6 +4757,9 @@ function combineOrderSwappedVerdicts(run1, run2) {
|
|
|
4585
4757
|
if (run1 === run2) return run1;
|
|
4586
4758
|
return "tied";
|
|
4587
4759
|
}
|
|
4760
|
+
function replayRetryDelayMs(errorCode) {
|
|
4761
|
+
return errorCode === "rate_limit" ? 65e3 : 2e3;
|
|
4762
|
+
}
|
|
4588
4763
|
function p50(values) {
|
|
4589
4764
|
if (values.length === 0) return null;
|
|
4590
4765
|
const sorted = [...values].sort((a, b) => a - b);
|
|
@@ -4670,7 +4845,8 @@ async function runGoldenEval(opts) {
|
|
|
4670
4845
|
let started = Date.now();
|
|
4671
4846
|
let exec = await attempt();
|
|
4672
4847
|
if (!exec.ok && exec.errorType === "retryable") {
|
|
4673
|
-
|
|
4848
|
+
const delayMs = replayRetryDelayMs(exec.errorCode);
|
|
4849
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
4674
4850
|
started = Date.now();
|
|
4675
4851
|
exec = await attempt();
|
|
4676
4852
|
}
|
|
@@ -5444,6 +5620,7 @@ export {
|
|
|
5444
5620
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
5445
5621
|
CallError,
|
|
5446
5622
|
DEFAULT_FINDINGS_ENDPOINT,
|
|
5623
|
+
DEFAULT_PROMOTIONS_ENDPOINT,
|
|
5447
5624
|
DIALECT_VERSION,
|
|
5448
5625
|
FamilyResolutionError,
|
|
5449
5626
|
INTENT_ARCHETYPES,
|
|
@@ -5455,6 +5632,8 @@ export {
|
|
|
5455
5632
|
PROVIDER_ENV_KEYS,
|
|
5456
5633
|
RULE_SEQUENTIAL_TOOL_CLIFF,
|
|
5457
5634
|
TRANSLATOR_FLOOR,
|
|
5635
|
+
_testResetPromotions,
|
|
5636
|
+
_testWaitForPromotionsRefresh,
|
|
5458
5637
|
allProfiles,
|
|
5459
5638
|
applyArchetypeConvention,
|
|
5460
5639
|
applySectionRewrites,
|
|
@@ -5474,6 +5653,7 @@ export {
|
|
|
5474
5653
|
compile2 as compile,
|
|
5475
5654
|
compileForAISDKv6,
|
|
5476
5655
|
configureBrain,
|
|
5656
|
+
configurePromotionsBrain,
|
|
5477
5657
|
countTokens,
|
|
5478
5658
|
createBrainForwardRoutes,
|
|
5479
5659
|
createKeyHealthRoute,
|
|
@@ -5485,6 +5665,7 @@ export {
|
|
|
5485
5665
|
getActionableAdvisories,
|
|
5486
5666
|
getAllStarterChains,
|
|
5487
5667
|
getAllStarterChainsWithGrounding,
|
|
5668
|
+
getApplicablePromotion,
|
|
5488
5669
|
getArchetypePerfScore,
|
|
5489
5670
|
getDefaultFallbackChain,
|
|
5490
5671
|
getDefaultFallbackChainWithGrounding,
|
|
@@ -5500,10 +5681,12 @@ export {
|
|
|
5500
5681
|
getStarterChainWithGrounding,
|
|
5501
5682
|
hashShape,
|
|
5502
5683
|
isArchetype,
|
|
5684
|
+
isAutoPromoteEnabledFromEnv,
|
|
5503
5685
|
isBrainQueryActiveFor,
|
|
5504
5686
|
isBrainSync,
|
|
5505
5687
|
isExclusionFindingsBrainActive,
|
|
5506
5688
|
isModelReachable,
|
|
5689
|
+
isPromotionsBrainActive,
|
|
5507
5690
|
isProviderReachable,
|
|
5508
5691
|
latencyTierOf,
|
|
5509
5692
|
learningKey,
|
package/dist/key-health.js
CHANGED
|
@@ -25,7 +25,7 @@ __export(key_health_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(key_health_exports);
|
|
26
26
|
|
|
27
27
|
// src/version.ts
|
|
28
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
28
|
+
var LIBRARY_VERSION = "2.0.0-alpha.64";
|
|
29
29
|
|
|
30
30
|
// src/key-health.ts
|
|
31
31
|
var JSON_HEADERS = { "Content-Type": "application/json" };
|
package/dist/key-health.mjs
CHANGED
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.64",
|
|
4
4
|
"description": "Prompt compiler with executable provider knowledge for multi-model AI apps: normalized multi-provider transport with fallback chains, compile-time cliff guards, a curated model registry, and a telemetry flight recorder. Swap models without rewriting prompts.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|