@warmdrift/kgauto-compiler 2.0.0-alpha.10 → 2.0.0-alpha.12
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-3KVKELZN.mjs → chunk-DICCTQLG.mjs} +14 -2
- package/dist/index.d.mts +213 -3
- package/dist/index.d.ts +213 -3
- package/dist/index.js +377 -6
- package/dist/index.mjs +360 -5
- package/dist/{profiles-DO6R9moS.d.mts → profiles-B5MCp_0L.d.mts} +10 -1
- package/dist/{profiles-Bgri1pe7.d.ts → profiles-B_sMA2eU.d.ts} +10 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/profiles.js +16 -2
- package/dist/profiles.mjs +5 -1
- package/package.json +1 -1
|
@@ -623,14 +623,20 @@ var ALIASES = {
|
|
|
623
623
|
// Legacy kgauto typo — actual API alias is dash-form (alpha.1 had dot).
|
|
624
624
|
"claude-haiku-4.5": "claude-haiku-4-5"
|
|
625
625
|
};
|
|
626
|
+
var brainHook = {};
|
|
627
|
+
function _setProfileBrainHook(hook) {
|
|
628
|
+
brainHook = hook;
|
|
629
|
+
}
|
|
626
630
|
function canonicalId(id) {
|
|
627
|
-
return ALIASES[id] ?? id;
|
|
631
|
+
return brainHook.resolveAlias?.(id) ?? ALIASES[id] ?? id;
|
|
628
632
|
}
|
|
629
633
|
var PROFILE_INDEX = new Map(
|
|
630
634
|
PROFILES_RAW.map((p) => [p.id, p])
|
|
631
635
|
);
|
|
632
636
|
function getProfile(id) {
|
|
633
637
|
const canonical = canonicalId(id);
|
|
638
|
+
const fromBrain = brainHook.getProfile?.(canonical);
|
|
639
|
+
if (fromBrain) return fromBrain;
|
|
634
640
|
const p = PROFILE_INDEX.get(canonical);
|
|
635
641
|
if (!p) {
|
|
636
642
|
const known = [...PROFILE_INDEX.keys(), ...Object.keys(ALIASES)].join(", ");
|
|
@@ -639,19 +645,25 @@ function getProfile(id) {
|
|
|
639
645
|
return p;
|
|
640
646
|
}
|
|
641
647
|
function tryGetProfile(id) {
|
|
642
|
-
|
|
648
|
+
const canonical = canonicalId(id);
|
|
649
|
+
return brainHook.getProfile?.(canonical) ?? PROFILE_INDEX.get(canonical);
|
|
643
650
|
}
|
|
644
651
|
function allProfiles() {
|
|
645
652
|
return PROFILES_RAW;
|
|
646
653
|
}
|
|
654
|
+
function allProfilesRaw() {
|
|
655
|
+
return PROFILES_RAW;
|
|
656
|
+
}
|
|
647
657
|
function profilesByProvider(provider) {
|
|
648
658
|
return PROFILES_RAW.filter((p) => p.provider === provider);
|
|
649
659
|
}
|
|
650
660
|
|
|
651
661
|
export {
|
|
652
662
|
ALIASES,
|
|
663
|
+
_setProfileBrainHook,
|
|
653
664
|
getProfile,
|
|
654
665
|
tryGetProfile,
|
|
655
666
|
allProfiles,
|
|
667
|
+
allProfilesRaw,
|
|
656
668
|
profilesByProvider
|
|
657
669
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as ModelProfile, 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, O as OracleScore, e as CompileResult, B as BestPracticeAdvisory, f as Provider } from './profiles-
|
|
2
|
-
export { g as ALIASES, h as CacheStrategy, i as CallAttempt, j as CallError, k as CliffRule, l as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, L as LoweringSpec, m as Message, n as MutationApplied, o as NormalizedTokens, p as PromptSection, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, T as ToolCall, s as ToolDefinition, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-
|
|
1
|
+
import { M as ModelProfile, 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, O as OracleScore, e as CompileResult, B as BestPracticeAdvisory, f as Provider } from './profiles-B5MCp_0L.mjs';
|
|
2
|
+
export { g as ALIASES, h as CacheStrategy, i as CallAttempt, j as CallError, k as CliffRule, l as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, L as LoweringSpec, m as Message, n as MutationApplied, o as NormalizedTokens, p as PromptSection, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, T as ToolCall, s as ToolDefinition, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B5MCp_0L.mjs';
|
|
3
3
|
import { IntentArchetypeName } from './dialect.mjs';
|
|
4
4
|
export { ALL_ARCHETYPES, ContextBucket, DIALECT_VERSION, HistoryDepth, INTENT_ARCHETYPES, OutputMode, ShapeSignature, ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey } from './dialect.mjs';
|
|
5
5
|
|
|
@@ -102,6 +102,29 @@ declare function call(ir: PromptIR, opts?: CallOptions): Promise<CallResult>;
|
|
|
102
102
|
* onError hook). Uses fetch() — works in Node 18+, Edge runtimes, and browsers.
|
|
103
103
|
*/
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* alpha.11 — opt-in nested config for brain-query mode (chains / archetype
|
|
107
|
+
* perf / pricing / models registry). Enabled by default when endpoint is
|
|
108
|
+
* set; per-table opt-out via explicit `false`.
|
|
109
|
+
*
|
|
110
|
+
* Locked via /plan-eng-review 2026-05-15 (decision D3). Structured group
|
|
111
|
+
* keeps the BrainConfig surface clean as more brain-driven tables ship.
|
|
112
|
+
*/
|
|
113
|
+
interface BrainQueryConfig {
|
|
114
|
+
/** Default true when endpoint set. Brain-driven fallback chains. */
|
|
115
|
+
chains?: boolean;
|
|
116
|
+
/** Default true when endpoint set. Brain-driven archetype perf scores. */
|
|
117
|
+
perf?: boolean;
|
|
118
|
+
/** Default true when endpoint set. Brain-driven pricing with at-time resolution. */
|
|
119
|
+
pricing?: boolean;
|
|
120
|
+
/** Default true when endpoint set. Brain-driven model registry + aliases. */
|
|
121
|
+
models?: boolean;
|
|
122
|
+
/** SWR window in ms. Default 300_000 (5 min). */
|
|
123
|
+
cacheTtlMs?: number;
|
|
124
|
+
/** Override the GET URL when the read endpoint differs from the write one.
|
|
125
|
+
* Defaults to `${endpoint}/v2/config` when omitted. */
|
|
126
|
+
configEndpoint?: string;
|
|
127
|
+
}
|
|
105
128
|
interface BrainConfig {
|
|
106
129
|
/** Brain HTTP endpoint base URL (e.g., https://kgauto-brain.vercel.app/api). */
|
|
107
130
|
endpoint: string;
|
|
@@ -113,6 +136,9 @@ interface BrainConfig {
|
|
|
113
136
|
sync?: boolean;
|
|
114
137
|
/** Optional fetch override (for tests). */
|
|
115
138
|
fetchImpl?: typeof fetch;
|
|
139
|
+
/** alpha.11 — brain-query mode for config tables. Default-on per table
|
|
140
|
+
* when endpoint is set; opt-out via `false`. See BrainQueryConfig. */
|
|
141
|
+
brainQuery?: BrainQueryConfig;
|
|
116
142
|
}
|
|
117
143
|
declare function configureBrain(config: BrainConfig): void;
|
|
118
144
|
declare function clearBrain(): void;
|
|
@@ -460,6 +486,190 @@ declare function getStarterChain(archetype: IntentArchetypeName): string[];
|
|
|
460
486
|
*/
|
|
461
487
|
declare function getAllStarterChains(): Record<IntentArchetypeName, string[]>;
|
|
462
488
|
|
|
489
|
+
/**
|
|
490
|
+
* chains-brain — alpha.11 KG-11 adapter.
|
|
491
|
+
*
|
|
492
|
+
* Brain-driven STARTER_CHAINS for `getDefaultFallbackChain`. Reads
|
|
493
|
+
* `kgauto_chains` table via the shared brain-query SWR cache (D6 + D8);
|
|
494
|
+
* falls back to bundled STARTER_CHAINS on cold-start, brain-down, or
|
|
495
|
+
* empty/missing table (D2 + D4).
|
|
496
|
+
*
|
|
497
|
+
* Behavioral note (locked via D2): the sync API surface returns bundled on
|
|
498
|
+
* cold-start, with a background refresh fired. Subsequent calls within the
|
|
499
|
+
* 5-min TTL return brain data. Vercel cold-start consumers see the seed
|
|
500
|
+
* snapshot (functionally identical to pre-alpha.11); warm-start consumers
|
|
501
|
+
* see live brain mutations within 5 min.
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* Sync reader for the brain-driven chains map. Returns bundled
|
|
505
|
+
* STARTER_CHAINS when brain-query is disabled, cold, or unreachable.
|
|
506
|
+
*/
|
|
507
|
+
declare const loadChainsFromBrain: () => Record<"ask" | "hunt" | "classify" | "summarize" | "generate" | "extract" | "plan" | "critique" | "transform", string[]>;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* archetype-perf-brain — alpha.11 KG-12 adapter.
|
|
511
|
+
*
|
|
512
|
+
* Brain-driven archetypePerf scores. Substrate for the future closed-loop
|
|
513
|
+
* tuning engine (KG-12.5): brain telemetry → human or automated bumps →
|
|
514
|
+
* brain UPDATE → consumers see new scores within 5-min cache TTL with
|
|
515
|
+
* zero refresh.
|
|
516
|
+
*
|
|
517
|
+
* Today: data migrates to brain. No runtime call site reads archetypePerf
|
|
518
|
+
* (it's metadata for the master plan §2.5 anti-hallucination guardrail +
|
|
519
|
+
* future auto-tuning). The adapter exists so future readers — auto-tuning
|
|
520
|
+
* + operator scripts + KG-12.5 — have a shipped substrate to consume.
|
|
521
|
+
*/
|
|
522
|
+
|
|
523
|
+
type ArchetypePerfMap = Map<string, Partial<Record<IntentArchetypeName, number>>>;
|
|
524
|
+
/**
|
|
525
|
+
* Sync reader for the brain-driven archetypePerf map. Returns bundled
|
|
526
|
+
* profile.archetypePerf data when brain-query is disabled, cold, or
|
|
527
|
+
* unreachable. Identical shape pre/post-alpha.11 by design (D2).
|
|
528
|
+
*/
|
|
529
|
+
declare const loadArchetypePerfFromBrain: () => ArchetypePerfMap;
|
|
530
|
+
/**
|
|
531
|
+
* Per-model accessor. Returns 5 (neutral) when no entry is found —
|
|
532
|
+
* consistent with the master plan §3.3 "missing archetypes default to 5"
|
|
533
|
+
* convention documented in profiles.ts ModelProfile.archetypePerf.
|
|
534
|
+
*/
|
|
535
|
+
declare function getArchetypePerfScore(modelId: string, archetype: IntentArchetypeName): number;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* pricing-brain — alpha.11 KG-13 adapter.
|
|
539
|
+
*
|
|
540
|
+
* Brain-driven pricing data with **time-bounded resolution** (`valid_from`
|
|
541
|
+
* / `valid_until` columns). The V4-Pro 75%-off promo through 2026-05-31
|
|
542
|
+
* gets modeled as two rows; `at` parameter resolution picks the correct
|
|
543
|
+
* row per call timestamp. Promo flips happen automatically at the
|
|
544
|
+
* boundary without alpha cuts.
|
|
545
|
+
*
|
|
546
|
+
* SWR cache holds the FULL pricing snapshot (all active rows for all
|
|
547
|
+
* models). Per-call `at` filtering is in-memory — keeps the SWR semantics
|
|
548
|
+
* uniform with other adapters (one cache, one snapshot, sync reads).
|
|
549
|
+
*/
|
|
550
|
+
interface PricingRow {
|
|
551
|
+
modelId: string;
|
|
552
|
+
costInputPer1m: number;
|
|
553
|
+
costOutputPer1m: number;
|
|
554
|
+
cacheInputPer1m?: number;
|
|
555
|
+
cacheCreationPer1m?: number;
|
|
556
|
+
validFrom: number;
|
|
557
|
+
validUntil?: number;
|
|
558
|
+
source?: string;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Sync reader for the brain-driven pricing snapshot. Returns bundled
|
|
562
|
+
* profile pricing when brain-query is disabled, cold, or unreachable.
|
|
563
|
+
* Caller filters by `at` via {@link resolvePricingAt}.
|
|
564
|
+
*/
|
|
565
|
+
declare const loadPricingFromBrain: () => PricingRow[];
|
|
566
|
+
/**
|
|
567
|
+
* Resolve the active pricing row for a model at a given timestamp.
|
|
568
|
+
* Picks the row with the latest `valid_from <= at` whose
|
|
569
|
+
* `valid_until > at` (or NULL — open-ended).
|
|
570
|
+
*
|
|
571
|
+
* Returns `undefined` when no row matches. Callers should fall back to
|
|
572
|
+
* profile static pricing in that case.
|
|
573
|
+
*/
|
|
574
|
+
declare function resolvePricingAt(modelId: string, at?: Date): PricingRow | undefined;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* models-brain — alpha.11 KG-14 adapter (the largest of the four).
|
|
578
|
+
*
|
|
579
|
+
* Brain-driven model registry + aliases. Two adapters share the same
|
|
580
|
+
* SWR snapshot:
|
|
581
|
+
*
|
|
582
|
+
* - `loadModelsFromBrain()` — `Map<modelId, ModelProfile>` from
|
|
583
|
+
* `kgauto_models` table (cliffs/lowering/recovery as JSONB columns).
|
|
584
|
+
* - `loadAliasesFromBrain()` — `Record<aliasId, canonicalId>` from
|
|
585
|
+
* `kgauto_aliases` table.
|
|
586
|
+
*
|
|
587
|
+
* After alpha.11, new-model onboarding becomes brain INSERT (vs PR + alpha
|
|
588
|
+
* cut + 3 consumer refreshes). The auto-onboard pipeline
|
|
589
|
+
* (`scripts/check-model-releases.mjs`) shifts from emitting profile.ts
|
|
590
|
+
* edits to writing brain rows directly.
|
|
591
|
+
*
|
|
592
|
+
* **D5 — alias resolution stable regardless of canonical's active state.**
|
|
593
|
+
* `canonicalId('deepseek-chat') → 'deepseek-v4-flash'` even when the
|
|
594
|
+
* canonical row is `active=false`. Aliases are wire-format contracts;
|
|
595
|
+
* legacy callers' resolution promise outlives the canonical's active
|
|
596
|
+
* status. Deprecation (`active=false`) affects chain composition only.
|
|
597
|
+
*/
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Exported brain-row shape for `kgauto_models`. Mirrors the SQL table
|
|
601
|
+
* (`v2/brain/migrations/010_kgauto_models_and_aliases.sql`) — column names
|
|
602
|
+
* are snake_case to match PostgREST. Used by operator scripts that write
|
|
603
|
+
* to brain (auto-onboard, promote-model) — see `profileToRow()`.
|
|
604
|
+
*
|
|
605
|
+
* Read path stays internal via `RawModelRow` to keep `rowToProfile()`'s
|
|
606
|
+
* tolerance contract from leaking into write callers.
|
|
607
|
+
*/
|
|
608
|
+
interface ModelBrainRow {
|
|
609
|
+
model_id: string;
|
|
610
|
+
provider: string;
|
|
611
|
+
status?: string;
|
|
612
|
+
max_context_tokens?: number;
|
|
613
|
+
max_output_tokens?: number;
|
|
614
|
+
max_tools?: number;
|
|
615
|
+
parallel_tool_calls?: boolean;
|
|
616
|
+
structured_output?: string;
|
|
617
|
+
system_prompt_mode?: string;
|
|
618
|
+
streaming?: boolean;
|
|
619
|
+
cliffs?: unknown;
|
|
620
|
+
lowering?: unknown;
|
|
621
|
+
recovery?: unknown;
|
|
622
|
+
strengths?: string[] | null;
|
|
623
|
+
weaknesses?: string[] | null;
|
|
624
|
+
cost_input_per_1m?: number;
|
|
625
|
+
cost_output_per_1m?: number;
|
|
626
|
+
notes?: string | null;
|
|
627
|
+
verified_against_docs?: string | null;
|
|
628
|
+
archetype_perf?: Record<string, number> | null;
|
|
629
|
+
version_added?: string;
|
|
630
|
+
version_removed?: string | null;
|
|
631
|
+
active?: boolean;
|
|
632
|
+
}
|
|
633
|
+
interface ProfileToRowOptions {
|
|
634
|
+
/** e.g. `'2.0.0-alpha.12'` — leave undefined to omit from row. */
|
|
635
|
+
versionAdded?: string;
|
|
636
|
+
/** Pass `null` to clear; omit to leave field unset. */
|
|
637
|
+
versionRemoved?: string | null;
|
|
638
|
+
/** Defaults to true if omitted. */
|
|
639
|
+
active?: boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Override verifiedAgainstDocs (e.g. set to `null` for auto-onboard).
|
|
642
|
+
* When omitted, the profile's own value is used. Pass `null` explicitly
|
|
643
|
+
* to write a SQL NULL (e.g. unverified auto-onboard rows).
|
|
644
|
+
*/
|
|
645
|
+
verifiedAgainstDocs?: string | null;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Inverse of `rowToProfile` — serialize a `ModelProfile` to a `kgauto_models`
|
|
649
|
+
* row payload for INSERT/UPSERT. Used by operator scripts that write to
|
|
650
|
+
* brain (auto-onboard pipeline, promote-model verification CLI).
|
|
651
|
+
*
|
|
652
|
+
* Row-level fields (`version_added`, `version_removed`, `active`) are
|
|
653
|
+
* operator-controlled and pass through `opts`. `verifiedAgainstDocs` can
|
|
654
|
+
* also be overridden via `opts` — auto-onboard explicitly passes `null` to
|
|
655
|
+
* mark unverified rows (the column is DATE, doesn't accept the
|
|
656
|
+
* `'UNVERIFIED-AUTO-ONBOARD'` sentinel used in PROFILES_RAW).
|
|
657
|
+
*/
|
|
658
|
+
declare function profileToRow(profile: ModelProfile, opts?: ProfileToRowOptions): ModelBrainRow;
|
|
659
|
+
/**
|
|
660
|
+
* Sync reader for the brain-driven model registry. Returns bundled
|
|
661
|
+
* PROFILES_RAW when brain-query is disabled, cold, or unreachable.
|
|
662
|
+
*/
|
|
663
|
+
declare const loadModelsFromBrain: () => Map<string, ModelProfile>;
|
|
664
|
+
/**
|
|
665
|
+
* Sync reader for the brain-driven aliases map. Returns bundled ALIASES
|
|
666
|
+
* when brain-query is disabled, cold, or unreachable.
|
|
667
|
+
*
|
|
668
|
+
* D5: this map carries both active and inactive canonical mappings —
|
|
669
|
+
* alias resolution is stable regardless of canonical's `active` state.
|
|
670
|
+
*/
|
|
671
|
+
declare const loadAliasesFromBrain: () => Record<string, string>;
|
|
672
|
+
|
|
463
673
|
/**
|
|
464
674
|
* @warmdrift/kgauto v2 — prompt compiler + central learning brain.
|
|
465
675
|
*
|
|
@@ -506,4 +716,4 @@ declare function getAllStarterChains(): Record<IntentArchetypeName, string[]>;
|
|
|
506
716
|
*/
|
|
507
717
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
508
718
|
|
|
509
|
-
export { ApiKeys, type AppOracle, BestPracticeAdvisory, type BrainConfig, CallOptions, CallResult, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, IntentArchetypeName, type LLMJudgeOptions, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, PROVIDER_ENV_KEYS, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getDefaultFallbackChain, getReachabilityDiagnostic, getStarterChain, isModelReachable, isProviderReachable, record, resetTokenizer, resolveProviderKey, runAdvisor, setTokenizer };
|
|
719
|
+
export { ApiKeys, type AppOracle, type ArchetypePerfMap, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, IntentArchetypeName, type LLMJudgeOptions, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, PROVIDER_ENV_KEYS, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getArchetypePerfScore, getDefaultFallbackChain, getReachabilityDiagnostic, getStarterChain, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as ModelProfile, 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, O as OracleScore, e as CompileResult, B as BestPracticeAdvisory, f as Provider } from './profiles-
|
|
2
|
-
export { g as ALIASES, h as CacheStrategy, i as CallAttempt, j as CallError, k as CliffRule, l as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, L as LoweringSpec, m as Message, n as MutationApplied, o as NormalizedTokens, p as PromptSection, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, T as ToolCall, s as ToolDefinition, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-
|
|
1
|
+
import { M as ModelProfile, 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, O as OracleScore, e as CompileResult, B as BestPracticeAdvisory, f as Provider } from './profiles-B_sMA2eU.js';
|
|
2
|
+
export { g as ALIASES, h as CacheStrategy, i as CallAttempt, j as CallError, k as CliffRule, l as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, L as LoweringSpec, m as Message, n as MutationApplied, o as NormalizedTokens, p as PromptSection, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, T as ToolCall, s as ToolDefinition, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B_sMA2eU.js';
|
|
3
3
|
import { IntentArchetypeName } from './dialect.js';
|
|
4
4
|
export { ALL_ARCHETYPES, ContextBucket, DIALECT_VERSION, HistoryDepth, INTENT_ARCHETYPES, OutputMode, ShapeSignature, ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey } from './dialect.js';
|
|
5
5
|
|
|
@@ -102,6 +102,29 @@ declare function call(ir: PromptIR, opts?: CallOptions): Promise<CallResult>;
|
|
|
102
102
|
* onError hook). Uses fetch() — works in Node 18+, Edge runtimes, and browsers.
|
|
103
103
|
*/
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* alpha.11 — opt-in nested config for brain-query mode (chains / archetype
|
|
107
|
+
* perf / pricing / models registry). Enabled by default when endpoint is
|
|
108
|
+
* set; per-table opt-out via explicit `false`.
|
|
109
|
+
*
|
|
110
|
+
* Locked via /plan-eng-review 2026-05-15 (decision D3). Structured group
|
|
111
|
+
* keeps the BrainConfig surface clean as more brain-driven tables ship.
|
|
112
|
+
*/
|
|
113
|
+
interface BrainQueryConfig {
|
|
114
|
+
/** Default true when endpoint set. Brain-driven fallback chains. */
|
|
115
|
+
chains?: boolean;
|
|
116
|
+
/** Default true when endpoint set. Brain-driven archetype perf scores. */
|
|
117
|
+
perf?: boolean;
|
|
118
|
+
/** Default true when endpoint set. Brain-driven pricing with at-time resolution. */
|
|
119
|
+
pricing?: boolean;
|
|
120
|
+
/** Default true when endpoint set. Brain-driven model registry + aliases. */
|
|
121
|
+
models?: boolean;
|
|
122
|
+
/** SWR window in ms. Default 300_000 (5 min). */
|
|
123
|
+
cacheTtlMs?: number;
|
|
124
|
+
/** Override the GET URL when the read endpoint differs from the write one.
|
|
125
|
+
* Defaults to `${endpoint}/v2/config` when omitted. */
|
|
126
|
+
configEndpoint?: string;
|
|
127
|
+
}
|
|
105
128
|
interface BrainConfig {
|
|
106
129
|
/** Brain HTTP endpoint base URL (e.g., https://kgauto-brain.vercel.app/api). */
|
|
107
130
|
endpoint: string;
|
|
@@ -113,6 +136,9 @@ interface BrainConfig {
|
|
|
113
136
|
sync?: boolean;
|
|
114
137
|
/** Optional fetch override (for tests). */
|
|
115
138
|
fetchImpl?: typeof fetch;
|
|
139
|
+
/** alpha.11 — brain-query mode for config tables. Default-on per table
|
|
140
|
+
* when endpoint is set; opt-out via `false`. See BrainQueryConfig. */
|
|
141
|
+
brainQuery?: BrainQueryConfig;
|
|
116
142
|
}
|
|
117
143
|
declare function configureBrain(config: BrainConfig): void;
|
|
118
144
|
declare function clearBrain(): void;
|
|
@@ -460,6 +486,190 @@ declare function getStarterChain(archetype: IntentArchetypeName): string[];
|
|
|
460
486
|
*/
|
|
461
487
|
declare function getAllStarterChains(): Record<IntentArchetypeName, string[]>;
|
|
462
488
|
|
|
489
|
+
/**
|
|
490
|
+
* chains-brain — alpha.11 KG-11 adapter.
|
|
491
|
+
*
|
|
492
|
+
* Brain-driven STARTER_CHAINS for `getDefaultFallbackChain`. Reads
|
|
493
|
+
* `kgauto_chains` table via the shared brain-query SWR cache (D6 + D8);
|
|
494
|
+
* falls back to bundled STARTER_CHAINS on cold-start, brain-down, or
|
|
495
|
+
* empty/missing table (D2 + D4).
|
|
496
|
+
*
|
|
497
|
+
* Behavioral note (locked via D2): the sync API surface returns bundled on
|
|
498
|
+
* cold-start, with a background refresh fired. Subsequent calls within the
|
|
499
|
+
* 5-min TTL return brain data. Vercel cold-start consumers see the seed
|
|
500
|
+
* snapshot (functionally identical to pre-alpha.11); warm-start consumers
|
|
501
|
+
* see live brain mutations within 5 min.
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* Sync reader for the brain-driven chains map. Returns bundled
|
|
505
|
+
* STARTER_CHAINS when brain-query is disabled, cold, or unreachable.
|
|
506
|
+
*/
|
|
507
|
+
declare const loadChainsFromBrain: () => Record<"ask" | "hunt" | "classify" | "summarize" | "generate" | "extract" | "plan" | "critique" | "transform", string[]>;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* archetype-perf-brain — alpha.11 KG-12 adapter.
|
|
511
|
+
*
|
|
512
|
+
* Brain-driven archetypePerf scores. Substrate for the future closed-loop
|
|
513
|
+
* tuning engine (KG-12.5): brain telemetry → human or automated bumps →
|
|
514
|
+
* brain UPDATE → consumers see new scores within 5-min cache TTL with
|
|
515
|
+
* zero refresh.
|
|
516
|
+
*
|
|
517
|
+
* Today: data migrates to brain. No runtime call site reads archetypePerf
|
|
518
|
+
* (it's metadata for the master plan §2.5 anti-hallucination guardrail +
|
|
519
|
+
* future auto-tuning). The adapter exists so future readers — auto-tuning
|
|
520
|
+
* + operator scripts + KG-12.5 — have a shipped substrate to consume.
|
|
521
|
+
*/
|
|
522
|
+
|
|
523
|
+
type ArchetypePerfMap = Map<string, Partial<Record<IntentArchetypeName, number>>>;
|
|
524
|
+
/**
|
|
525
|
+
* Sync reader for the brain-driven archetypePerf map. Returns bundled
|
|
526
|
+
* profile.archetypePerf data when brain-query is disabled, cold, or
|
|
527
|
+
* unreachable. Identical shape pre/post-alpha.11 by design (D2).
|
|
528
|
+
*/
|
|
529
|
+
declare const loadArchetypePerfFromBrain: () => ArchetypePerfMap;
|
|
530
|
+
/**
|
|
531
|
+
* Per-model accessor. Returns 5 (neutral) when no entry is found —
|
|
532
|
+
* consistent with the master plan §3.3 "missing archetypes default to 5"
|
|
533
|
+
* convention documented in profiles.ts ModelProfile.archetypePerf.
|
|
534
|
+
*/
|
|
535
|
+
declare function getArchetypePerfScore(modelId: string, archetype: IntentArchetypeName): number;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* pricing-brain — alpha.11 KG-13 adapter.
|
|
539
|
+
*
|
|
540
|
+
* Brain-driven pricing data with **time-bounded resolution** (`valid_from`
|
|
541
|
+
* / `valid_until` columns). The V4-Pro 75%-off promo through 2026-05-31
|
|
542
|
+
* gets modeled as two rows; `at` parameter resolution picks the correct
|
|
543
|
+
* row per call timestamp. Promo flips happen automatically at the
|
|
544
|
+
* boundary without alpha cuts.
|
|
545
|
+
*
|
|
546
|
+
* SWR cache holds the FULL pricing snapshot (all active rows for all
|
|
547
|
+
* models). Per-call `at` filtering is in-memory — keeps the SWR semantics
|
|
548
|
+
* uniform with other adapters (one cache, one snapshot, sync reads).
|
|
549
|
+
*/
|
|
550
|
+
interface PricingRow {
|
|
551
|
+
modelId: string;
|
|
552
|
+
costInputPer1m: number;
|
|
553
|
+
costOutputPer1m: number;
|
|
554
|
+
cacheInputPer1m?: number;
|
|
555
|
+
cacheCreationPer1m?: number;
|
|
556
|
+
validFrom: number;
|
|
557
|
+
validUntil?: number;
|
|
558
|
+
source?: string;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Sync reader for the brain-driven pricing snapshot. Returns bundled
|
|
562
|
+
* profile pricing when brain-query is disabled, cold, or unreachable.
|
|
563
|
+
* Caller filters by `at` via {@link resolvePricingAt}.
|
|
564
|
+
*/
|
|
565
|
+
declare const loadPricingFromBrain: () => PricingRow[];
|
|
566
|
+
/**
|
|
567
|
+
* Resolve the active pricing row for a model at a given timestamp.
|
|
568
|
+
* Picks the row with the latest `valid_from <= at` whose
|
|
569
|
+
* `valid_until > at` (or NULL — open-ended).
|
|
570
|
+
*
|
|
571
|
+
* Returns `undefined` when no row matches. Callers should fall back to
|
|
572
|
+
* profile static pricing in that case.
|
|
573
|
+
*/
|
|
574
|
+
declare function resolvePricingAt(modelId: string, at?: Date): PricingRow | undefined;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* models-brain — alpha.11 KG-14 adapter (the largest of the four).
|
|
578
|
+
*
|
|
579
|
+
* Brain-driven model registry + aliases. Two adapters share the same
|
|
580
|
+
* SWR snapshot:
|
|
581
|
+
*
|
|
582
|
+
* - `loadModelsFromBrain()` — `Map<modelId, ModelProfile>` from
|
|
583
|
+
* `kgauto_models` table (cliffs/lowering/recovery as JSONB columns).
|
|
584
|
+
* - `loadAliasesFromBrain()` — `Record<aliasId, canonicalId>` from
|
|
585
|
+
* `kgauto_aliases` table.
|
|
586
|
+
*
|
|
587
|
+
* After alpha.11, new-model onboarding becomes brain INSERT (vs PR + alpha
|
|
588
|
+
* cut + 3 consumer refreshes). The auto-onboard pipeline
|
|
589
|
+
* (`scripts/check-model-releases.mjs`) shifts from emitting profile.ts
|
|
590
|
+
* edits to writing brain rows directly.
|
|
591
|
+
*
|
|
592
|
+
* **D5 — alias resolution stable regardless of canonical's active state.**
|
|
593
|
+
* `canonicalId('deepseek-chat') → 'deepseek-v4-flash'` even when the
|
|
594
|
+
* canonical row is `active=false`. Aliases are wire-format contracts;
|
|
595
|
+
* legacy callers' resolution promise outlives the canonical's active
|
|
596
|
+
* status. Deprecation (`active=false`) affects chain composition only.
|
|
597
|
+
*/
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Exported brain-row shape for `kgauto_models`. Mirrors the SQL table
|
|
601
|
+
* (`v2/brain/migrations/010_kgauto_models_and_aliases.sql`) — column names
|
|
602
|
+
* are snake_case to match PostgREST. Used by operator scripts that write
|
|
603
|
+
* to brain (auto-onboard, promote-model) — see `profileToRow()`.
|
|
604
|
+
*
|
|
605
|
+
* Read path stays internal via `RawModelRow` to keep `rowToProfile()`'s
|
|
606
|
+
* tolerance contract from leaking into write callers.
|
|
607
|
+
*/
|
|
608
|
+
interface ModelBrainRow {
|
|
609
|
+
model_id: string;
|
|
610
|
+
provider: string;
|
|
611
|
+
status?: string;
|
|
612
|
+
max_context_tokens?: number;
|
|
613
|
+
max_output_tokens?: number;
|
|
614
|
+
max_tools?: number;
|
|
615
|
+
parallel_tool_calls?: boolean;
|
|
616
|
+
structured_output?: string;
|
|
617
|
+
system_prompt_mode?: string;
|
|
618
|
+
streaming?: boolean;
|
|
619
|
+
cliffs?: unknown;
|
|
620
|
+
lowering?: unknown;
|
|
621
|
+
recovery?: unknown;
|
|
622
|
+
strengths?: string[] | null;
|
|
623
|
+
weaknesses?: string[] | null;
|
|
624
|
+
cost_input_per_1m?: number;
|
|
625
|
+
cost_output_per_1m?: number;
|
|
626
|
+
notes?: string | null;
|
|
627
|
+
verified_against_docs?: string | null;
|
|
628
|
+
archetype_perf?: Record<string, number> | null;
|
|
629
|
+
version_added?: string;
|
|
630
|
+
version_removed?: string | null;
|
|
631
|
+
active?: boolean;
|
|
632
|
+
}
|
|
633
|
+
interface ProfileToRowOptions {
|
|
634
|
+
/** e.g. `'2.0.0-alpha.12'` — leave undefined to omit from row. */
|
|
635
|
+
versionAdded?: string;
|
|
636
|
+
/** Pass `null` to clear; omit to leave field unset. */
|
|
637
|
+
versionRemoved?: string | null;
|
|
638
|
+
/** Defaults to true if omitted. */
|
|
639
|
+
active?: boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Override verifiedAgainstDocs (e.g. set to `null` for auto-onboard).
|
|
642
|
+
* When omitted, the profile's own value is used. Pass `null` explicitly
|
|
643
|
+
* to write a SQL NULL (e.g. unverified auto-onboard rows).
|
|
644
|
+
*/
|
|
645
|
+
verifiedAgainstDocs?: string | null;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Inverse of `rowToProfile` — serialize a `ModelProfile` to a `kgauto_models`
|
|
649
|
+
* row payload for INSERT/UPSERT. Used by operator scripts that write to
|
|
650
|
+
* brain (auto-onboard pipeline, promote-model verification CLI).
|
|
651
|
+
*
|
|
652
|
+
* Row-level fields (`version_added`, `version_removed`, `active`) are
|
|
653
|
+
* operator-controlled and pass through `opts`. `verifiedAgainstDocs` can
|
|
654
|
+
* also be overridden via `opts` — auto-onboard explicitly passes `null` to
|
|
655
|
+
* mark unverified rows (the column is DATE, doesn't accept the
|
|
656
|
+
* `'UNVERIFIED-AUTO-ONBOARD'` sentinel used in PROFILES_RAW).
|
|
657
|
+
*/
|
|
658
|
+
declare function profileToRow(profile: ModelProfile, opts?: ProfileToRowOptions): ModelBrainRow;
|
|
659
|
+
/**
|
|
660
|
+
* Sync reader for the brain-driven model registry. Returns bundled
|
|
661
|
+
* PROFILES_RAW when brain-query is disabled, cold, or unreachable.
|
|
662
|
+
*/
|
|
663
|
+
declare const loadModelsFromBrain: () => Map<string, ModelProfile>;
|
|
664
|
+
/**
|
|
665
|
+
* Sync reader for the brain-driven aliases map. Returns bundled ALIASES
|
|
666
|
+
* when brain-query is disabled, cold, or unreachable.
|
|
667
|
+
*
|
|
668
|
+
* D5: this map carries both active and inactive canonical mappings —
|
|
669
|
+
* alias resolution is stable regardless of canonical's `active` state.
|
|
670
|
+
*/
|
|
671
|
+
declare const loadAliasesFromBrain: () => Record<string, string>;
|
|
672
|
+
|
|
463
673
|
/**
|
|
464
674
|
* @warmdrift/kgauto v2 — prompt compiler + central learning brain.
|
|
465
675
|
*
|
|
@@ -506,4 +716,4 @@ declare function getAllStarterChains(): Record<IntentArchetypeName, string[]>;
|
|
|
506
716
|
*/
|
|
507
717
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
508
718
|
|
|
509
|
-
export { ApiKeys, type AppOracle, BestPracticeAdvisory, type BrainConfig, CallOptions, CallResult, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, IntentArchetypeName, type LLMJudgeOptions, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, PROVIDER_ENV_KEYS, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getDefaultFallbackChain, getReachabilityDiagnostic, getStarterChain, isModelReachable, isProviderReachable, record, resetTokenizer, resolveProviderKey, runAdvisor, setTokenizer };
|
|
719
|
+
export { ApiKeys, type AppOracle, type ArchetypePerfMap, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, IntentArchetypeName, type LLMJudgeOptions, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, PROVIDER_ENV_KEYS, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getArchetypePerfScore, getDefaultFallbackChain, getReachabilityDiagnostic, getStarterChain, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|