@warmdrift/kgauto-compiler 2.0.0-alpha.11 → 2.0.0-alpha.13

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.d.mts CHANGED
@@ -596,6 +596,66 @@ declare function resolvePricingAt(modelId: string, at?: Date): PricingRow | unde
596
596
  * status. Deprecation (`active=false`) affects chain composition only.
597
597
  */
598
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;
599
659
  /**
600
660
  * Sync reader for the brain-driven model registry. Returns bundled
601
661
  * PROFILES_RAW when brain-query is disabled, cold, or unreachable.
@@ -656,4 +716,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
656
716
  */
657
717
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
658
718
 
659
- 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, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, PROVIDER_ENV_KEYS, type PricingRow, 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, record, resetTokenizer, resolvePricingAt, 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
@@ -596,6 +596,66 @@ declare function resolvePricingAt(modelId: string, at?: Date): PricingRow | unde
596
596
  * status. Deprecation (`active=false`) affects chain composition only.
597
597
  */
598
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;
599
659
  /**
600
660
  * Sync reader for the brain-driven model registry. Returns bundled
601
661
  * PROFILES_RAW when brain-query is disabled, cold, or unreachable.
@@ -656,4 +716,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
656
716
  */
657
717
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
658
718
 
659
- 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, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, PROVIDER_ENV_KEYS, type PricingRow, 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, record, resetTokenizer, resolvePricingAt, 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.js CHANGED
@@ -53,6 +53,7 @@ __export(index_exports, {
53
53
  loadChainsFromBrain: () => loadChainsFromBrain,
54
54
  loadModelsFromBrain: () => loadModelsFromBrain,
55
55
  loadPricingFromBrain: () => loadPricingFromBrain,
56
+ profileToRow: () => profileToRow,
56
57
  profilesByProvider: () => profilesByProvider,
57
58
  record: () => record,
58
59
  resetTokenizer: () => resetTokenizer,
@@ -2031,13 +2032,18 @@ var PROVIDER_ENV_KEYS = Object.freeze({
2031
2032
  function defaultEnv() {
2032
2033
  return typeof process !== "undefined" && process.env ? process.env : {};
2033
2034
  }
2035
+ function readKeyValue(raw) {
2036
+ if (raw === void 0) return void 0;
2037
+ const trimmed = raw.trim();
2038
+ return trimmed.length > 0 ? trimmed : void 0;
2039
+ }
2034
2040
  function resolveProviderKey(provider, opts = {}) {
2035
2041
  if (!isSupportedProvider(provider)) return void 0;
2036
- const explicit = opts.apiKeys?.[provider];
2042
+ const explicit = readKeyValue(opts.apiKeys?.[provider]);
2037
2043
  if (explicit) return explicit;
2038
2044
  const env = opts.envSource ?? defaultEnv();
2039
2045
  for (const name of PROVIDER_ENV_KEYS[provider]) {
2040
- const v = env[name];
2046
+ const v = readKeyValue(env[name]);
2041
2047
  if (v) return v;
2042
2048
  }
2043
2049
  return void 0;
@@ -2054,11 +2060,11 @@ function getReachabilityDiagnostic(opts = {}) {
2054
2060
  const env = opts.envSource ?? defaultEnv();
2055
2061
  const out = {};
2056
2062
  for (const provider of SUPPORTED_PROVIDERS) {
2057
- if (opts.apiKeys?.[provider]) {
2063
+ if (readKeyValue(opts.apiKeys?.[provider])) {
2058
2064
  out[provider] = { reachable: true, via: "apiKeys" };
2059
2065
  continue;
2060
2066
  }
2061
- const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => env[name]);
2067
+ const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => readKeyValue(env[name]));
2062
2068
  out[provider] = envKeyFound ? { reachable: true, via: "env", envKeyFound } : { reachable: false, via: null };
2063
2069
  }
2064
2070
  return out;
@@ -2805,6 +2811,39 @@ function rowToProfile(row) {
2805
2811
  return null;
2806
2812
  }
2807
2813
  }
2814
+ function profileToRow(profile, opts = {}) {
2815
+ const row = {
2816
+ model_id: profile.id,
2817
+ provider: profile.provider,
2818
+ status: profile.status,
2819
+ max_context_tokens: profile.maxContextTokens,
2820
+ max_output_tokens: profile.maxOutputTokens,
2821
+ max_tools: profile.maxTools,
2822
+ parallel_tool_calls: profile.parallelToolCalls,
2823
+ structured_output: profile.structuredOutput,
2824
+ system_prompt_mode: profile.systemPromptMode,
2825
+ streaming: profile.streaming,
2826
+ cliffs: profile.cliffs,
2827
+ cost_input_per_1m: profile.costInputPer1m,
2828
+ cost_output_per_1m: profile.costOutputPer1m,
2829
+ lowering: profile.lowering,
2830
+ recovery: profile.recovery,
2831
+ strengths: profile.strengths,
2832
+ weaknesses: profile.weaknesses,
2833
+ notes: profile.notes ?? null,
2834
+ archetype_perf: profile.archetypePerf ?? null,
2835
+ active: opts.active ?? true
2836
+ };
2837
+ if (opts.verifiedAgainstDocs !== void 0) {
2838
+ row.verified_against_docs = opts.verifiedAgainstDocs;
2839
+ } else if (profile.verifiedAgainstDocs !== void 0) {
2840
+ const v = profile.verifiedAgainstDocs;
2841
+ row.verified_against_docs = /^\d{4}-\d{2}-\d{2}/.test(v) ? v : null;
2842
+ }
2843
+ if (opts.versionAdded !== void 0) row.version_added = opts.versionAdded;
2844
+ if (opts.versionRemoved !== void 0) row.version_removed = opts.versionRemoved;
2845
+ return row;
2846
+ }
2808
2847
  function mapRowsToModels(rows) {
2809
2848
  const out = /* @__PURE__ */ new Map();
2810
2849
  for (const row of rows) {
@@ -2884,6 +2923,7 @@ function compile2(ir, opts) {
2884
2923
  loadChainsFromBrain,
2885
2924
  loadModelsFromBrain,
2886
2925
  loadPricingFromBrain,
2926
+ profileToRow,
2887
2927
  profilesByProvider,
2888
2928
  record,
2889
2929
  resetTokenizer,
package/dist/index.mjs CHANGED
@@ -1242,13 +1242,18 @@ var PROVIDER_ENV_KEYS = Object.freeze({
1242
1242
  function defaultEnv() {
1243
1243
  return typeof process !== "undefined" && process.env ? process.env : {};
1244
1244
  }
1245
+ function readKeyValue(raw) {
1246
+ if (raw === void 0) return void 0;
1247
+ const trimmed = raw.trim();
1248
+ return trimmed.length > 0 ? trimmed : void 0;
1249
+ }
1245
1250
  function resolveProviderKey(provider, opts = {}) {
1246
1251
  if (!isSupportedProvider(provider)) return void 0;
1247
- const explicit = opts.apiKeys?.[provider];
1252
+ const explicit = readKeyValue(opts.apiKeys?.[provider]);
1248
1253
  if (explicit) return explicit;
1249
1254
  const env = opts.envSource ?? defaultEnv();
1250
1255
  for (const name of PROVIDER_ENV_KEYS[provider]) {
1251
- const v = env[name];
1256
+ const v = readKeyValue(env[name]);
1252
1257
  if (v) return v;
1253
1258
  }
1254
1259
  return void 0;
@@ -1265,11 +1270,11 @@ function getReachabilityDiagnostic(opts = {}) {
1265
1270
  const env = opts.envSource ?? defaultEnv();
1266
1271
  const out = {};
1267
1272
  for (const provider of SUPPORTED_PROVIDERS) {
1268
- if (opts.apiKeys?.[provider]) {
1273
+ if (readKeyValue(opts.apiKeys?.[provider])) {
1269
1274
  out[provider] = { reachable: true, via: "apiKeys" };
1270
1275
  continue;
1271
1276
  }
1272
- const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => env[name]);
1277
+ const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => readKeyValue(env[name]));
1273
1278
  out[provider] = envKeyFound ? { reachable: true, via: "env", envKeyFound } : { reachable: false, via: null };
1274
1279
  }
1275
1280
  return out;
@@ -2016,6 +2021,39 @@ function rowToProfile(row) {
2016
2021
  return null;
2017
2022
  }
2018
2023
  }
2024
+ function profileToRow(profile, opts = {}) {
2025
+ const row = {
2026
+ model_id: profile.id,
2027
+ provider: profile.provider,
2028
+ status: profile.status,
2029
+ max_context_tokens: profile.maxContextTokens,
2030
+ max_output_tokens: profile.maxOutputTokens,
2031
+ max_tools: profile.maxTools,
2032
+ parallel_tool_calls: profile.parallelToolCalls,
2033
+ structured_output: profile.structuredOutput,
2034
+ system_prompt_mode: profile.systemPromptMode,
2035
+ streaming: profile.streaming,
2036
+ cliffs: profile.cliffs,
2037
+ cost_input_per_1m: profile.costInputPer1m,
2038
+ cost_output_per_1m: profile.costOutputPer1m,
2039
+ lowering: profile.lowering,
2040
+ recovery: profile.recovery,
2041
+ strengths: profile.strengths,
2042
+ weaknesses: profile.weaknesses,
2043
+ notes: profile.notes ?? null,
2044
+ archetype_perf: profile.archetypePerf ?? null,
2045
+ active: opts.active ?? true
2046
+ };
2047
+ if (opts.verifiedAgainstDocs !== void 0) {
2048
+ row.verified_against_docs = opts.verifiedAgainstDocs;
2049
+ } else if (profile.verifiedAgainstDocs !== void 0) {
2050
+ const v = profile.verifiedAgainstDocs;
2051
+ row.verified_against_docs = /^\d{4}-\d{2}-\d{2}/.test(v) ? v : null;
2052
+ }
2053
+ if (opts.versionAdded !== void 0) row.version_added = opts.versionAdded;
2054
+ if (opts.versionRemoved !== void 0) row.version_removed = opts.versionRemoved;
2055
+ return row;
2056
+ }
2019
2057
  function mapRowsToModels(rows) {
2020
2058
  const out = /* @__PURE__ */ new Map();
2021
2059
  for (const row of rows) {
@@ -2094,6 +2132,7 @@ export {
2094
2132
  loadChainsFromBrain,
2095
2133
  loadModelsFromBrain,
2096
2134
  loadPricingFromBrain,
2135
+ profileToRow,
2097
2136
  profilesByProvider,
2098
2137
  record,
2099
2138
  resetTokenizer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warmdrift/kgauto-compiler",
3
- "version": "2.0.0-alpha.11",
3
+ "version": "2.0.0-alpha.13",
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",