@warmdrift/kgauto-compiler 2.0.0-alpha.12 → 2.0.0-alpha.14

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
@@ -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-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';
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-DTnIzGsA.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-DTnIzGsA.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
 
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-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';
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-D0y6aLk0.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-D0y6aLk0.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
 
package/dist/index.js CHANGED
@@ -2032,13 +2032,18 @@ var PROVIDER_ENV_KEYS = Object.freeze({
2032
2032
  function defaultEnv() {
2033
2033
  return typeof process !== "undefined" && process.env ? process.env : {};
2034
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
+ }
2035
2040
  function resolveProviderKey(provider, opts = {}) {
2036
2041
  if (!isSupportedProvider(provider)) return void 0;
2037
- const explicit = opts.apiKeys?.[provider];
2042
+ const explicit = readKeyValue(opts.apiKeys?.[provider]);
2038
2043
  if (explicit) return explicit;
2039
2044
  const env = opts.envSource ?? defaultEnv();
2040
2045
  for (const name of PROVIDER_ENV_KEYS[provider]) {
2041
- const v = env[name];
2046
+ const v = readKeyValue(env[name]);
2042
2047
  if (v) return v;
2043
2048
  }
2044
2049
  return void 0;
@@ -2055,11 +2060,11 @@ function getReachabilityDiagnostic(opts = {}) {
2055
2060
  const env = opts.envSource ?? defaultEnv();
2056
2061
  const out = {};
2057
2062
  for (const provider of SUPPORTED_PROVIDERS) {
2058
- if (opts.apiKeys?.[provider]) {
2063
+ if (readKeyValue(opts.apiKeys?.[provider])) {
2059
2064
  out[provider] = { reachable: true, via: "apiKeys" };
2060
2065
  continue;
2061
2066
  }
2062
- const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => env[name]);
2067
+ const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => readKeyValue(env[name]));
2063
2068
  out[provider] = envKeyFound ? { reachable: true, via: "env", envKeyFound } : { reachable: false, via: null };
2064
2069
  }
2065
2070
  return out;
@@ -2331,8 +2336,19 @@ async function call(ir, opts = {}) {
2331
2336
  }
2332
2337
  let activeCompile = initial;
2333
2338
  let lastErr;
2339
+ const failedProviders = /* @__PURE__ */ new Set();
2334
2340
  for (let i = 0; i < targetsToTry.length; i++) {
2335
2341
  const targetModel = targetsToTry[i];
2342
+ const targetProfile = tryGetProfile(targetModel);
2343
+ if (targetProfile && failedProviders.has(targetProfile.provider) && !opts.noFallback) {
2344
+ attempts.push({
2345
+ model: targetModel,
2346
+ status: "terminal",
2347
+ errorCode: "auth_inferred",
2348
+ message: `Skipped \u2014 provider ${targetProfile.provider} returned 401/403 earlier in this call; same key inferred to fail`
2349
+ });
2350
+ continue;
2351
+ }
2336
2352
  if (targetModel !== initial.target) {
2337
2353
  try {
2338
2354
  activeCompile = compileAndRegister(
@@ -2401,6 +2417,10 @@ async function call(ir, opts = {}) {
2401
2417
  });
2402
2418
  lastErr = validated;
2403
2419
  if (validated.errorType === "terminal" || opts.noFallback) {
2420
+ if (validated.errorCode === "auth" && !opts.noFallback && activeCompile.provider) {
2421
+ failedProviders.add(activeCompile.provider);
2422
+ continue;
2423
+ }
2404
2424
  break;
2405
2425
  }
2406
2426
  }
@@ -2479,6 +2499,7 @@ function normalizeFallbackReason(attempts) {
2479
2499
  return "cliff";
2480
2500
  }
2481
2501
  if (code === "cost_cap_exceeded") return "cost_cap";
2502
+ if (code === "auth" || code === "auth_inferred") return "provider_auth_failed";
2482
2503
  return "provider_error";
2483
2504
  }
2484
2505
 
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;
@@ -1541,8 +1546,19 @@ async function call(ir, opts = {}) {
1541
1546
  }
1542
1547
  let activeCompile = initial;
1543
1548
  let lastErr;
1549
+ const failedProviders = /* @__PURE__ */ new Set();
1544
1550
  for (let i = 0; i < targetsToTry.length; i++) {
1545
1551
  const targetModel = targetsToTry[i];
1552
+ const targetProfile = tryGetProfile(targetModel);
1553
+ if (targetProfile && failedProviders.has(targetProfile.provider) && !opts.noFallback) {
1554
+ attempts.push({
1555
+ model: targetModel,
1556
+ status: "terminal",
1557
+ errorCode: "auth_inferred",
1558
+ message: `Skipped \u2014 provider ${targetProfile.provider} returned 401/403 earlier in this call; same key inferred to fail`
1559
+ });
1560
+ continue;
1561
+ }
1546
1562
  if (targetModel !== initial.target) {
1547
1563
  try {
1548
1564
  activeCompile = compileAndRegister(
@@ -1611,6 +1627,10 @@ async function call(ir, opts = {}) {
1611
1627
  });
1612
1628
  lastErr = validated;
1613
1629
  if (validated.errorType === "terminal" || opts.noFallback) {
1630
+ if (validated.errorCode === "auth" && !opts.noFallback && activeCompile.provider) {
1631
+ failedProviders.add(activeCompile.provider);
1632
+ continue;
1633
+ }
1614
1634
  break;
1615
1635
  }
1616
1636
  }
@@ -1689,6 +1709,7 @@ function normalizeFallbackReason(attempts) {
1689
1709
  return "cliff";
1690
1710
  }
1691
1711
  if (code === "cost_cap_exceeded") return "cost_cap";
1712
+ if (code === "auth" || code === "auth_inferred") return "provider_auth_failed";
1692
1713
  return "provider_error";
1693
1714
  }
1694
1715
 
@@ -458,15 +458,21 @@ interface CallAttempt {
458
458
  /**
459
459
  * Why fallback fired. Normalized for `CallResult.fallbackReason` (alpha.9).
460
460
  *
461
- * - `rate_limit` provider returned 429
462
- * - `provider_error` 5xx, network, or other retryable upstream issue
463
- * - `cost_cap` preflight policy.maxCostPerCallUsd rejected target
464
- * - `cliff` alpha.8 contract violation (MAX_TOKENS on
465
- * structured output, parse-failed JSON)
466
- * - `contract_violation` other compile-time-contract failures (reserved
467
- * for alpha.10+ — e.g. mid-stream policy rejects)
461
+ * - `rate_limit` provider returned 429
462
+ * - `provider_error` 5xx, network, or other retryable upstream issue
463
+ * - `cost_cap` preflight policy.maxCostPerCallUsd rejected target
464
+ * - `cliff` alpha.8 contract violation (MAX_TOKENS on
465
+ * structured output, parse-failed JSON)
466
+ * - `contract_violation` other compile-time-contract failures (reserved
467
+ * for alpha.10+ — e.g. mid-stream policy rejects)
468
+ * - `provider_auth_failed` alpha.14 — initial provider returned 401/403
469
+ * (upstream key revocation, malformed-but-truthy
470
+ * key, billing lapse). The chain walks to the
471
+ * next non-same-provider target instead of
472
+ * short-circuiting; same-provider remaining
473
+ * entries skip with errorCode='auth_inferred'.
468
474
  */
469
- type FallbackReason = 'rate_limit' | 'provider_error' | 'cost_cap' | 'cliff' | 'contract_violation';
475
+ type FallbackReason = 'rate_limit' | 'provider_error' | 'cost_cap' | 'cliff' | 'contract_violation' | 'provider_auth_failed';
470
476
  interface CallResult {
471
477
  /** Compile handle (still valid for record() if consumer wants to add oracle scores later). */
472
478
  handle: string;
@@ -458,15 +458,21 @@ interface CallAttempt {
458
458
  /**
459
459
  * Why fallback fired. Normalized for `CallResult.fallbackReason` (alpha.9).
460
460
  *
461
- * - `rate_limit` provider returned 429
462
- * - `provider_error` 5xx, network, or other retryable upstream issue
463
- * - `cost_cap` preflight policy.maxCostPerCallUsd rejected target
464
- * - `cliff` alpha.8 contract violation (MAX_TOKENS on
465
- * structured output, parse-failed JSON)
466
- * - `contract_violation` other compile-time-contract failures (reserved
467
- * for alpha.10+ — e.g. mid-stream policy rejects)
461
+ * - `rate_limit` provider returned 429
462
+ * - `provider_error` 5xx, network, or other retryable upstream issue
463
+ * - `cost_cap` preflight policy.maxCostPerCallUsd rejected target
464
+ * - `cliff` alpha.8 contract violation (MAX_TOKENS on
465
+ * structured output, parse-failed JSON)
466
+ * - `contract_violation` other compile-time-contract failures (reserved
467
+ * for alpha.10+ — e.g. mid-stream policy rejects)
468
+ * - `provider_auth_failed` alpha.14 — initial provider returned 401/403
469
+ * (upstream key revocation, malformed-but-truthy
470
+ * key, billing lapse). The chain walks to the
471
+ * next non-same-provider target instead of
472
+ * short-circuiting; same-provider remaining
473
+ * entries skip with errorCode='auth_inferred'.
468
474
  */
469
- type FallbackReason = 'rate_limit' | 'provider_error' | 'cost_cap' | 'cliff' | 'contract_violation';
475
+ type FallbackReason = 'rate_limit' | 'provider_error' | 'cost_cap' | 'cliff' | 'contract_violation' | 'provider_auth_failed';
470
476
  interface CallResult {
471
477
  /** Compile handle (still valid for record() if consumer wants to add oracle scores later). */
472
478
  handle: string;
@@ -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, _ as _setProfileBrainHook, t as allProfiles, x as allProfilesRaw, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B5MCp_0L.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-DTnIzGsA.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, _ as _setProfileBrainHook, t as allProfiles, x as allProfilesRaw, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B_sMA2eU.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-D0y6aLk0.js';
2
2
  import './dialect.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warmdrift/kgauto-compiler",
3
- "version": "2.0.0-alpha.12",
3
+ "version": "2.0.0-alpha.14",
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",