@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/index.mjs CHANGED
@@ -11,11 +11,13 @@ import {
11
11
  } from "./chunk-5TI6PNSK.mjs";
12
12
  import {
13
13
  ALIASES,
14
+ _setProfileBrainHook,
14
15
  allProfiles,
16
+ allProfilesRaw,
15
17
  getProfile,
16
18
  profilesByProvider,
17
19
  tryGetProfile
18
- } from "./chunk-3KVKELZN.mjs";
20
+ } from "./chunk-DICCTQLG.mjs";
19
21
 
20
22
  // src/tokenizer.ts
21
23
  var tokenizerImpl = defaultCharBasedCounter;
@@ -909,14 +911,170 @@ function validateFinalFit(ir, profile, tokens) {
909
911
  }
910
912
  }
911
913
 
914
+ // src/brain-query.ts
915
+ var FRESH_SNAPSHOT = {
916
+ data: null,
917
+ expiresAt: 0,
918
+ refreshing: false,
919
+ warned: false
920
+ };
921
+ var snapshot = { ...FRESH_SNAPSHOT };
922
+ var runtime;
923
+ function configureBrainQuery(rt) {
924
+ runtime = rt;
925
+ snapshot = { ...FRESH_SNAPSHOT };
926
+ }
927
+ function createBrainQueryCache(opts) {
928
+ return () => {
929
+ const rt = runtime;
930
+ if (!rt || !rt.enabledTables.has(opts.table)) {
931
+ return opts.bundledFallback();
932
+ }
933
+ const now = Date.now();
934
+ const stale = snapshot.expiresAt <= now;
935
+ if (stale && !snapshot.refreshing) {
936
+ snapshot.refreshing = true;
937
+ void asyncRefresh(rt);
938
+ }
939
+ if (snapshot.data) {
940
+ const rows = snapshot.data[opts.table];
941
+ if (Array.isArray(rows) && rows.length > 0) {
942
+ try {
943
+ return opts.mapRows(rows);
944
+ } catch {
945
+ return opts.bundledFallback();
946
+ }
947
+ }
948
+ }
949
+ return opts.bundledFallback();
950
+ };
951
+ }
952
+ var pendingRefresh;
953
+ async function asyncRefresh(rt) {
954
+ const promise = doRefresh(rt);
955
+ pendingRefresh = promise;
956
+ try {
957
+ await promise;
958
+ } finally {
959
+ if (pendingRefresh === promise) pendingRefresh = void 0;
960
+ }
961
+ }
962
+ var DEFAULT_CONFIG_URL = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/config";
963
+ async function doRefresh(rt) {
964
+ const url = rt.configEndpoint ?? DEFAULT_CONFIG_URL;
965
+ try {
966
+ const res = await rt.fetchImpl(url, { method: "GET" });
967
+ if (!res.ok) {
968
+ throw new Error(`brain-query ${res.status}: ${res.statusText}`);
969
+ }
970
+ const body = await res.json();
971
+ if (runtime !== rt) return;
972
+ snapshot = {
973
+ data: body,
974
+ expiresAt: Date.now() + rt.ttlMs,
975
+ refreshing: false,
976
+ warned: snapshot.warned
977
+ };
978
+ } catch (err) {
979
+ if (runtime !== rt) return;
980
+ snapshot.refreshing = false;
981
+ snapshot.expiresAt = Date.now() + rt.ttlMs;
982
+ if (!snapshot.warned) {
983
+ snapshot.warned = true;
984
+ (rt.onError ?? defaultOnError)(err);
985
+ }
986
+ }
987
+ }
988
+ function defaultOnError(err) {
989
+ console.warn("[kgauto] brain-query failed (using bundled fallback):", err);
990
+ }
991
+
992
+ // src/pricing-brain.ts
993
+ function isPricingRow(x) {
994
+ if (!x || typeof x !== "object") return false;
995
+ const r = x;
996
+ return typeof r.model_id === "string" && typeof r.cost_input_per_1m === "number" && typeof r.cost_output_per_1m === "number" && typeof r.valid_from === "string";
997
+ }
998
+ function mapRowsToPricing(rows) {
999
+ const out = [];
1000
+ for (const row of rows) {
1001
+ if (!isPricingRow(row)) continue;
1002
+ out.push({
1003
+ modelId: row.model_id,
1004
+ costInputPer1m: row.cost_input_per_1m,
1005
+ costOutputPer1m: row.cost_output_per_1m,
1006
+ cacheInputPer1m: row.cache_input_per_1m ?? void 0,
1007
+ cacheCreationPer1m: row.cache_creation_per_1m ?? void 0,
1008
+ validFrom: Date.parse(row.valid_from),
1009
+ validUntil: row.valid_until == null ? void 0 : Date.parse(row.valid_until),
1010
+ source: row.source ?? void 0
1011
+ });
1012
+ }
1013
+ return out;
1014
+ }
1015
+ function bundledPricing() {
1016
+ const out = [];
1017
+ for (const profile of allProfiles()) {
1018
+ out.push({
1019
+ modelId: profile.id,
1020
+ costInputPer1m: profile.costInputPer1m,
1021
+ costOutputPer1m: profile.costOutputPer1m,
1022
+ cacheInputPer1m: profile.lowering.cache.discount !== void 0 && profile.lowering.cache.discount > 0 ? profile.costInputPer1m * profile.lowering.cache.discount : void 0,
1023
+ validFrom: 0,
1024
+ validUntil: void 0,
1025
+ source: "profile_seed"
1026
+ });
1027
+ }
1028
+ return out;
1029
+ }
1030
+ var loadPricingFromBrain = createBrainQueryCache({
1031
+ table: "kgauto_pricing",
1032
+ mapRows: mapRowsToPricing,
1033
+ bundledFallback: bundledPricing
1034
+ });
1035
+ function resolvePricingAt(modelId, at = /* @__PURE__ */ new Date()) {
1036
+ const ts = at.getTime();
1037
+ const all = loadPricingFromBrain();
1038
+ let best;
1039
+ for (const row of all) {
1040
+ if (row.modelId !== modelId) continue;
1041
+ if (row.validFrom > ts) continue;
1042
+ if (row.validUntil !== void 0 && row.validUntil <= ts) continue;
1043
+ if (!best || row.validFrom > best.validFrom) best = row;
1044
+ }
1045
+ return best;
1046
+ }
1047
+
912
1048
  // src/brain.ts
913
1049
  var activeConfig;
914
1050
  function configureBrain(config) {
915
1051
  const endpoint = config.endpoint.replace(/\/outcomes\/?$/, "");
916
1052
  activeConfig = { ...config, endpoint };
1053
+ const bq = config.brainQuery ?? {};
1054
+ const enabledTables = /* @__PURE__ */ new Set();
1055
+ if (bq.chains !== false) enabledTables.add("kgauto_chains");
1056
+ if (bq.perf !== false) enabledTables.add("kgauto_archetype_perf");
1057
+ if (bq.pricing !== false) enabledTables.add("kgauto_pricing");
1058
+ if (bq.models !== false) {
1059
+ enabledTables.add("kgauto_models");
1060
+ enabledTables.add("kgauto_aliases");
1061
+ }
1062
+ if (enabledTables.size === 0) {
1063
+ configureBrainQuery(void 0);
1064
+ return;
1065
+ }
1066
+ configureBrainQuery({
1067
+ endpoint,
1068
+ configEndpoint: bq.configEndpoint,
1069
+ ttlMs: bq.cacheTtlMs ?? 3e5,
1070
+ fetchImpl: config.fetchImpl ?? fetch,
1071
+ enabledTables,
1072
+ onError: config.onError
1073
+ });
917
1074
  }
918
1075
  function clearBrain() {
919
1076
  activeConfig = void 0;
1077
+ configureBrainQuery(void 0);
920
1078
  }
921
1079
  var compileRegistry = /* @__PURE__ */ new Map();
922
1080
  var REGISTRY_MAX_ENTRIES = 1e4;
@@ -981,7 +1139,7 @@ async function record(input) {
981
1139
  throw new Error(`brain ${res.status}: ${text}`);
982
1140
  }
983
1141
  } catch (err) {
984
- (config.onError ?? defaultOnError)(err);
1142
+ (config.onError ?? defaultOnError2)(err);
985
1143
  }
986
1144
  };
987
1145
  if (config.sync) {
@@ -990,7 +1148,7 @@ async function record(input) {
990
1148
  void send();
991
1149
  }
992
1150
  }
993
- function defaultOnError(err) {
1151
+ function defaultOnError2(err) {
994
1152
  console.warn("[kgauto] brain record failed:", err);
995
1153
  }
996
1154
  function buildPayload(input, reg) {
@@ -1034,6 +1192,12 @@ function buildPayload(input, reg) {
1034
1192
  }
1035
1193
  function computeCostUsd(modelId, tokensIn, tokensOut) {
1036
1194
  if (tokensIn === 0 && tokensOut === 0) return void 0;
1195
+ const brainRow = resolvePricingAt(modelId);
1196
+ if (brainRow && (brainRow.costInputPer1m > 0 || brainRow.costOutputPer1m > 0)) {
1197
+ const inUsd2 = tokensIn / 1e6 * brainRow.costInputPer1m;
1198
+ const outUsd2 = tokensOut / 1e6 * brainRow.costOutputPer1m;
1199
+ return Math.round((inUsd2 + outUsd2) * 1e6) / 1e6;
1200
+ }
1037
1201
  const profile = tryGetProfile(modelId);
1038
1202
  if (!profile) return void 0;
1039
1203
  const inUsd = tokensIn / 1e6 * profile.costInputPer1m;
@@ -1616,6 +1780,37 @@ function clamp(n) {
1616
1780
  return Math.max(0, Math.min(1, n));
1617
1781
  }
1618
1782
 
1783
+ // src/chains-brain.ts
1784
+ function isChainsRow(x) {
1785
+ if (!x || typeof x !== "object") return false;
1786
+ const r = x;
1787
+ return typeof r.archetype === "string" && typeof r.tier === "number" && typeof r.model_id === "string";
1788
+ }
1789
+ function mapRowsToChains(rows) {
1790
+ const grouped = /* @__PURE__ */ new Map();
1791
+ for (const row of rows) {
1792
+ if (!isChainsRow(row)) continue;
1793
+ const list = grouped.get(row.archetype) ?? [];
1794
+ list.push(row);
1795
+ grouped.set(row.archetype, list);
1796
+ }
1797
+ const out = {};
1798
+ for (const [archetype, group] of grouped.entries()) {
1799
+ group.sort((a, b) => a.tier - b.tier);
1800
+ out[archetype] = group.map((r) => r.model_id);
1801
+ }
1802
+ const bundled = getAllStarterChains();
1803
+ for (const archetype of Object.keys(bundled)) {
1804
+ if (!out[archetype]) out[archetype] = bundled[archetype];
1805
+ }
1806
+ return out;
1807
+ }
1808
+ var loadChainsFromBrain = createBrainQueryCache({
1809
+ table: "kgauto_chains",
1810
+ mapRows: mapRowsToChains,
1811
+ bundledFallback: getAllStarterChains
1812
+ });
1813
+
1619
1814
  // src/fallback.ts
1620
1815
  var STARTER_CHAINS = {
1621
1816
  // Reasoning floor — never degrade. Walk UP on 429 to Opus → cross-provider.
@@ -1693,10 +1888,11 @@ function getDefaultFallbackChain(opts) {
1693
1888
  `getDefaultFallbackChain: maxDepth must be >= 1, got ${maxDepth}`
1694
1889
  );
1695
1890
  }
1696
- const starter = STARTER_CHAINS[archetype];
1891
+ const allChains = loadChainsFromBrain();
1892
+ const starter = allChains[archetype];
1697
1893
  if (!starter) {
1698
1894
  throw new Error(
1699
- `getDefaultFallbackChain: unknown archetype "${archetype}". Known: ${Object.keys(STARTER_CHAINS).join(", ")}`
1895
+ `getDefaultFallbackChain: unknown archetype "${archetype}". Known: ${Object.keys(allChains).join(", ")}`
1700
1896
  );
1701
1897
  }
1702
1898
  let chain;
@@ -1740,6 +1936,157 @@ function getAllStarterChains() {
1740
1936
  return out;
1741
1937
  }
1742
1938
 
1939
+ // src/archetype-perf-brain.ts
1940
+ function isPerfRow(x) {
1941
+ if (!x || typeof x !== "object") return false;
1942
+ const r = x;
1943
+ return typeof r.model_id === "string" && typeof r.archetype === "string" && typeof r.perf_score === "number";
1944
+ }
1945
+ function mapRowsToPerfMap(rows) {
1946
+ const out = /* @__PURE__ */ new Map();
1947
+ for (const row of rows) {
1948
+ if (!isPerfRow(row)) continue;
1949
+ const existing = out.get(row.model_id) ?? {};
1950
+ existing[row.archetype] = row.perf_score;
1951
+ out.set(row.model_id, existing);
1952
+ }
1953
+ return out;
1954
+ }
1955
+ function bundledArchetypePerf() {
1956
+ const out = /* @__PURE__ */ new Map();
1957
+ for (const profile of allProfiles()) {
1958
+ if (profile.archetypePerf) out.set(profile.id, profile.archetypePerf);
1959
+ }
1960
+ return out;
1961
+ }
1962
+ var loadArchetypePerfFromBrain = createBrainQueryCache({
1963
+ table: "kgauto_archetype_perf",
1964
+ mapRows: mapRowsToPerfMap,
1965
+ bundledFallback: bundledArchetypePerf
1966
+ });
1967
+ function getArchetypePerfScore(modelId, archetype) {
1968
+ return loadArchetypePerfFromBrain().get(modelId)?.[archetype] ?? 5;
1969
+ }
1970
+
1971
+ // src/models-brain.ts
1972
+ function isModelRow(x) {
1973
+ if (!x || typeof x !== "object") return false;
1974
+ const r = x;
1975
+ return typeof r.model_id === "string" && typeof r.provider === "string";
1976
+ }
1977
+ function isAliasRow(x) {
1978
+ if (!x || typeof x !== "object") return false;
1979
+ const r = x;
1980
+ return typeof r.alias_id === "string" && typeof r.canonical_id === "string";
1981
+ }
1982
+ function rowToProfile(row) {
1983
+ try {
1984
+ if (row.cliffs !== void 0 && row.cliffs !== null && !Array.isArray(row.cliffs)) {
1985
+ return null;
1986
+ }
1987
+ if (row.recovery !== void 0 && row.recovery !== null && !Array.isArray(row.recovery)) {
1988
+ return null;
1989
+ }
1990
+ if (row.lowering !== void 0 && row.lowering !== null && (typeof row.lowering !== "object" || Array.isArray(row.lowering))) {
1991
+ return null;
1992
+ }
1993
+ return {
1994
+ id: row.model_id,
1995
+ provider: row.provider,
1996
+ status: row.status ?? "current",
1997
+ maxContextTokens: row.max_context_tokens ?? 0,
1998
+ maxOutputTokens: row.max_output_tokens ?? 0,
1999
+ maxTools: row.max_tools ?? 0,
2000
+ parallelToolCalls: row.parallel_tool_calls ?? false,
2001
+ structuredOutput: row.structured_output ?? "none",
2002
+ systemPromptMode: row.system_prompt_mode ?? "inline",
2003
+ streaming: row.streaming ?? true,
2004
+ cliffs: row.cliffs ?? [],
2005
+ costInputPer1m: row.cost_input_per_1m ?? 0,
2006
+ costOutputPer1m: row.cost_output_per_1m ?? 0,
2007
+ lowering: row.lowering ?? { system: { mode: "inline" }, cache: { strategy: "unsupported" } },
2008
+ recovery: row.recovery ?? [],
2009
+ strengths: row.strengths ?? [],
2010
+ weaknesses: row.weaknesses ?? [],
2011
+ notes: row.notes ?? void 0,
2012
+ verifiedAgainstDocs: row.verified_against_docs ?? void 0,
2013
+ archetypePerf: row.archetype_perf ?? void 0
2014
+ };
2015
+ } catch {
2016
+ return null;
2017
+ }
2018
+ }
2019
+ function profileToRow(profile, opts = {}) {
2020
+ const row = {
2021
+ model_id: profile.id,
2022
+ provider: profile.provider,
2023
+ status: profile.status,
2024
+ max_context_tokens: profile.maxContextTokens,
2025
+ max_output_tokens: profile.maxOutputTokens,
2026
+ max_tools: profile.maxTools,
2027
+ parallel_tool_calls: profile.parallelToolCalls,
2028
+ structured_output: profile.structuredOutput,
2029
+ system_prompt_mode: profile.systemPromptMode,
2030
+ streaming: profile.streaming,
2031
+ cliffs: profile.cliffs,
2032
+ cost_input_per_1m: profile.costInputPer1m,
2033
+ cost_output_per_1m: profile.costOutputPer1m,
2034
+ lowering: profile.lowering,
2035
+ recovery: profile.recovery,
2036
+ strengths: profile.strengths,
2037
+ weaknesses: profile.weaknesses,
2038
+ notes: profile.notes ?? null,
2039
+ archetype_perf: profile.archetypePerf ?? null,
2040
+ active: opts.active ?? true
2041
+ };
2042
+ if (opts.verifiedAgainstDocs !== void 0) {
2043
+ row.verified_against_docs = opts.verifiedAgainstDocs;
2044
+ } else if (profile.verifiedAgainstDocs !== void 0) {
2045
+ const v = profile.verifiedAgainstDocs;
2046
+ row.verified_against_docs = /^\d{4}-\d{2}-\d{2}/.test(v) ? v : null;
2047
+ }
2048
+ if (opts.versionAdded !== void 0) row.version_added = opts.versionAdded;
2049
+ if (opts.versionRemoved !== void 0) row.version_removed = opts.versionRemoved;
2050
+ return row;
2051
+ }
2052
+ function mapRowsToModels(rows) {
2053
+ const out = /* @__PURE__ */ new Map();
2054
+ for (const row of rows) {
2055
+ if (!isModelRow(row)) continue;
2056
+ const profile = rowToProfile(row);
2057
+ if (profile) out.set(profile.id, profile);
2058
+ }
2059
+ return out;
2060
+ }
2061
+ function mapRowsToAliases(rows) {
2062
+ const out = {};
2063
+ for (const row of rows) {
2064
+ if (!isAliasRow(row)) continue;
2065
+ out[row.alias_id] = row.canonical_id;
2066
+ }
2067
+ return out;
2068
+ }
2069
+ function bundledModels() {
2070
+ return new Map(allProfilesRaw().map((p) => [p.id, p]));
2071
+ }
2072
+ function bundledAliases() {
2073
+ return { ...ALIASES };
2074
+ }
2075
+ var loadModelsFromBrain = createBrainQueryCache({
2076
+ table: "kgauto_models",
2077
+ mapRows: mapRowsToModels,
2078
+ bundledFallback: bundledModels
2079
+ });
2080
+ var loadAliasesFromBrain = createBrainQueryCache({
2081
+ table: "kgauto_aliases",
2082
+ mapRows: mapRowsToAliases,
2083
+ bundledFallback: bundledAliases
2084
+ });
2085
+ _setProfileBrainHook({
2086
+ getProfile: (canonical) => loadModelsFromBrain().get(canonical),
2087
+ resolveAlias: (id) => loadAliasesFromBrain()[id]
2088
+ });
2089
+
1743
2090
  // src/index.ts
1744
2091
  function compile2(ir, opts) {
1745
2092
  const result = compile(ir, opts);
@@ -1765,6 +2112,7 @@ export {
1765
2112
  countTokens,
1766
2113
  execute,
1767
2114
  getAllStarterChains,
2115
+ getArchetypePerfScore,
1768
2116
  getDefaultFallbackChain,
1769
2117
  getProfile,
1770
2118
  getReachabilityDiagnostic,
@@ -1774,9 +2122,16 @@ export {
1774
2122
  isModelReachable,
1775
2123
  isProviderReachable,
1776
2124
  learningKey,
2125
+ loadAliasesFromBrain,
2126
+ loadArchetypePerfFromBrain,
2127
+ loadChainsFromBrain,
2128
+ loadModelsFromBrain,
2129
+ loadPricingFromBrain,
2130
+ profileToRow,
1777
2131
  profilesByProvider,
1778
2132
  record,
1779
2133
  resetTokenizer,
2134
+ resolvePricingAt,
1780
2135
  resolveProviderKey,
1781
2136
  runAdvisor,
1782
2137
  setTokenizer,
@@ -720,9 +720,18 @@ interface ModelProfile {
720
720
  archetypePerf?: Partial<Record<IntentArchetypeName, number>>;
721
721
  }
722
722
  declare const ALIASES: Record<string, string>;
723
+ interface ProfileBrainHook {
724
+ getProfile?: (canonicalId: string) => ModelProfile | undefined;
725
+ resolveAlias?: (id: string) => string | undefined;
726
+ }
727
+ /** @internal — called by models-brain.ts at module load. */
728
+ declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
723
729
  declare function getProfile(id: string): ModelProfile;
724
730
  declare function tryGetProfile(id: string): ModelProfile | undefined;
725
731
  declare function allProfiles(): readonly ModelProfile[];
732
+ /** @internal — bundled-only access for adapters that need a non-brain
733
+ * fallback baseline (avoids a brain → profiles → brain re-entry). */
734
+ declare function allProfilesRaw(): readonly ModelProfile[];
726
735
  declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
727
736
 
728
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type HistoryCachePolicy as H, type IntentDeclaration as I, type LoweringSpec as L, type ModelProfile as M, type NormalizedResponse as N, type OracleScore as O, type ProviderOverrides as P, type RecordInput as R, type StructuredOutputCapability as S, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type Provider as f, ALIASES as g, type CacheStrategy as h, type CallAttempt as i, CallError as j, type CliffRule as k, type Constraints as l, type Message as m, type MutationApplied as n, type NormalizedTokens as o, type PromptSection as p, type RecoveryRule as q, type SystemPromptMode as r, type ToolDefinition as s, allProfiles as t, getProfile as u, profilesByProvider as v, tryGetProfile as w };
737
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type HistoryCachePolicy as H, type IntentDeclaration as I, type LoweringSpec as L, type ModelProfile as M, type NormalizedResponse as N, type OracleScore as O, type ProviderOverrides as P, type RecordInput as R, type StructuredOutputCapability as S, type ToolCall as T, _setProfileBrainHook as _, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type Provider as f, ALIASES as g, type CacheStrategy as h, type CallAttempt as i, CallError as j, type CliffRule as k, type Constraints as l, type Message as m, type MutationApplied as n, type NormalizedTokens as o, type PromptSection as p, type RecoveryRule as q, type SystemPromptMode as r, type ToolDefinition as s, allProfiles as t, getProfile as u, profilesByProvider as v, tryGetProfile as w, allProfilesRaw as x };
@@ -720,9 +720,18 @@ interface ModelProfile {
720
720
  archetypePerf?: Partial<Record<IntentArchetypeName, number>>;
721
721
  }
722
722
  declare const ALIASES: Record<string, string>;
723
+ interface ProfileBrainHook {
724
+ getProfile?: (canonicalId: string) => ModelProfile | undefined;
725
+ resolveAlias?: (id: string) => string | undefined;
726
+ }
727
+ /** @internal — called by models-brain.ts at module load. */
728
+ declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
723
729
  declare function getProfile(id: string): ModelProfile;
724
730
  declare function tryGetProfile(id: string): ModelProfile | undefined;
725
731
  declare function allProfiles(): readonly ModelProfile[];
732
+ /** @internal — bundled-only access for adapters that need a non-brain
733
+ * fallback baseline (avoids a brain → profiles → brain re-entry). */
734
+ declare function allProfilesRaw(): readonly ModelProfile[];
726
735
  declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
727
736
 
728
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type HistoryCachePolicy as H, type IntentDeclaration as I, type LoweringSpec as L, type ModelProfile as M, type NormalizedResponse as N, type OracleScore as O, type ProviderOverrides as P, type RecordInput as R, type StructuredOutputCapability as S, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type Provider as f, ALIASES as g, type CacheStrategy as h, type CallAttempt as i, CallError as j, type CliffRule as k, type Constraints as l, type Message as m, type MutationApplied as n, type NormalizedTokens as o, type PromptSection as p, type RecoveryRule as q, type SystemPromptMode as r, type ToolDefinition as s, allProfiles as t, getProfile as u, profilesByProvider as v, tryGetProfile as w };
737
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type HistoryCachePolicy as H, type IntentDeclaration as I, type LoweringSpec as L, type ModelProfile as M, type NormalizedResponse as N, type OracleScore as O, type ProviderOverrides as P, type RecordInput as R, type StructuredOutputCapability as S, type ToolCall as T, _setProfileBrainHook as _, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type Provider as f, ALIASES as g, type CacheStrategy as h, type CallAttempt as i, CallError as j, type CliffRule as k, type Constraints as l, type Message as m, type MutationApplied as n, type NormalizedTokens as o, type PromptSection as p, type RecoveryRule as q, type SystemPromptMode as r, type ToolDefinition as s, allProfiles as t, getProfile as u, profilesByProvider as v, tryGetProfile as w, allProfilesRaw as x };
@@ -1,2 +1,2 @@
1
- export { g as ALIASES, h as CacheStrategy, k as CliffRule, L as LoweringSpec, M as ModelProfile, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-DO6R9moS.mjs';
1
+ export { g as ALIASES, h as CacheStrategy, k as CliffRule, L as LoweringSpec, M as ModelProfile, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, _ as _setProfileBrainHook, t as allProfiles, x as allProfilesRaw, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B5MCp_0L.mjs';
2
2
  import './dialect.mjs';
@@ -1,2 +1,2 @@
1
- export { g as ALIASES, h as CacheStrategy, k as CliffRule, L as LoweringSpec, M as ModelProfile, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-Bgri1pe7.js';
1
+ export { g as ALIASES, h as CacheStrategy, k as CliffRule, L as LoweringSpec, M as ModelProfile, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, _ as _setProfileBrainHook, t as allProfiles, x as allProfilesRaw, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B_sMA2eU.js';
2
2
  import './dialect.js';
package/dist/profiles.js CHANGED
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var profiles_exports = {};
22
22
  __export(profiles_exports, {
23
23
  ALIASES: () => ALIASES,
24
+ _setProfileBrainHook: () => _setProfileBrainHook,
24
25
  allProfiles: () => allProfiles,
26
+ allProfilesRaw: () => allProfilesRaw,
25
27
  getProfile: () => getProfile,
26
28
  profilesByProvider: () => profilesByProvider,
27
29
  tryGetProfile: () => tryGetProfile
@@ -651,14 +653,20 @@ var ALIASES = {
651
653
  // Legacy kgauto typo — actual API alias is dash-form (alpha.1 had dot).
652
654
  "claude-haiku-4.5": "claude-haiku-4-5"
653
655
  };
656
+ var brainHook = {};
657
+ function _setProfileBrainHook(hook) {
658
+ brainHook = hook;
659
+ }
654
660
  function canonicalId(id) {
655
- return ALIASES[id] ?? id;
661
+ return brainHook.resolveAlias?.(id) ?? ALIASES[id] ?? id;
656
662
  }
657
663
  var PROFILE_INDEX = new Map(
658
664
  PROFILES_RAW.map((p) => [p.id, p])
659
665
  );
660
666
  function getProfile(id) {
661
667
  const canonical = canonicalId(id);
668
+ const fromBrain = brainHook.getProfile?.(canonical);
669
+ if (fromBrain) return fromBrain;
662
670
  const p = PROFILE_INDEX.get(canonical);
663
671
  if (!p) {
664
672
  const known = [...PROFILE_INDEX.keys(), ...Object.keys(ALIASES)].join(", ");
@@ -667,18 +675,24 @@ function getProfile(id) {
667
675
  return p;
668
676
  }
669
677
  function tryGetProfile(id) {
670
- return PROFILE_INDEX.get(canonicalId(id));
678
+ const canonical = canonicalId(id);
679
+ return brainHook.getProfile?.(canonical) ?? PROFILE_INDEX.get(canonical);
671
680
  }
672
681
  function allProfiles() {
673
682
  return PROFILES_RAW;
674
683
  }
684
+ function allProfilesRaw() {
685
+ return PROFILES_RAW;
686
+ }
675
687
  function profilesByProvider(provider) {
676
688
  return PROFILES_RAW.filter((p) => p.provider === provider);
677
689
  }
678
690
  // Annotate the CommonJS export names for ESM import in node:
679
691
  0 && (module.exports = {
680
692
  ALIASES,
693
+ _setProfileBrainHook,
681
694
  allProfiles,
695
+ allProfilesRaw,
682
696
  getProfile,
683
697
  profilesByProvider,
684
698
  tryGetProfile
package/dist/profiles.mjs CHANGED
@@ -1,13 +1,17 @@
1
1
  import {
2
2
  ALIASES,
3
+ _setProfileBrainHook,
3
4
  allProfiles,
5
+ allProfilesRaw,
4
6
  getProfile,
5
7
  profilesByProvider,
6
8
  tryGetProfile
7
- } from "./chunk-3KVKELZN.mjs";
9
+ } from "./chunk-DICCTQLG.mjs";
8
10
  export {
9
11
  ALIASES,
12
+ _setProfileBrainHook,
10
13
  allProfiles,
14
+ allProfilesRaw,
11
15
  getProfile,
12
16
  profilesByProvider,
13
17
  tryGetProfile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warmdrift/kgauto-compiler",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.12",
4
4
  "description": "Prompt compiler + central learning brain for multi-model AI apps. Swap models without rewriting prompts.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",