@warmdrift/kgauto-compiler 2.0.0-alpha.79 → 2.0.0-alpha.80
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-DRYCOR6G.mjs → chunk-CIBHU67M.mjs} +1 -1
- package/dist/{chunk-FT2FN6ZP.mjs → chunk-PMTT4H5W.mjs} +97 -3
- package/dist/glassbox-routes/index.js +87 -6
- package/dist/glassbox-routes/index.mjs +1 -1
- package/dist/index.d.mts +80 -6
- package/dist/index.d.ts +80 -6
- package/dist/index.js +3238 -3167
- package/dist/index.mjs +51 -62
- package/dist/key-health.js +1 -1
- package/dist/key-health.mjs +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -16,17 +16,22 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
LIBRARY_VERSION,
|
|
18
18
|
createKeyHealthRoute
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-CIBHU67M.mjs";
|
|
20
20
|
import {
|
|
21
21
|
ABSOLUTE_FLOOR,
|
|
22
22
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
23
23
|
BRAIN_READ_ENV_NAMES,
|
|
24
|
+
COST_RANKING_REFERENCE_SHAPE,
|
|
25
|
+
MEASURED_GROUNDING_MIN_N,
|
|
24
26
|
PROVIDER_ENV_KEYS,
|
|
27
|
+
chainProviderSpread,
|
|
25
28
|
configureBrainQuery,
|
|
26
29
|
createBrainQueryCache,
|
|
27
30
|
ensureCrossProviderTail,
|
|
31
|
+
estimateChainCostUsd,
|
|
28
32
|
getAllStarterChains,
|
|
29
33
|
getAllStarterChainsWithGrounding,
|
|
34
|
+
getArchetypePerfScore,
|
|
30
35
|
getDefaultFallbackChain,
|
|
31
36
|
getDefaultFallbackChainWithGrounding,
|
|
32
37
|
getModelCompatibility,
|
|
@@ -40,10 +45,12 @@ import {
|
|
|
40
45
|
isModelReachable,
|
|
41
46
|
isProviderReachable,
|
|
42
47
|
isSameModelRetryEnabledFromEnv,
|
|
48
|
+
loadArchetypePerfFromBrain,
|
|
49
|
+
loadArchetypePerfNFromBrain,
|
|
43
50
|
loadChainsFromBrain,
|
|
44
51
|
readBrainReadEnv,
|
|
45
52
|
resolveProviderKey
|
|
46
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-PMTT4H5W.mjs";
|
|
47
54
|
import {
|
|
48
55
|
ALIASES,
|
|
49
56
|
LATENCY_TIER_MS,
|
|
@@ -1533,63 +1540,6 @@ function setNestedField(obj, path, value) {
|
|
|
1533
1540
|
cursor[parts[parts.length - 1]] = value;
|
|
1534
1541
|
}
|
|
1535
1542
|
|
|
1536
|
-
// src/archetype-perf-brain.ts
|
|
1537
|
-
function isPerfRow(x) {
|
|
1538
|
-
if (!x || typeof x !== "object") return false;
|
|
1539
|
-
const r = x;
|
|
1540
|
-
return typeof r.model_id === "string" && typeof r.archetype === "string" && typeof r.perf_score === "number";
|
|
1541
|
-
}
|
|
1542
|
-
function mapRowsToPerfMap(rows) {
|
|
1543
|
-
const out = /* @__PURE__ */ new Map();
|
|
1544
|
-
for (const row of rows) {
|
|
1545
|
-
if (!isPerfRow(row)) continue;
|
|
1546
|
-
const existing = out.get(row.model_id) ?? {};
|
|
1547
|
-
existing[row.archetype] = row.perf_score;
|
|
1548
|
-
out.set(row.model_id, existing);
|
|
1549
|
-
}
|
|
1550
|
-
return out;
|
|
1551
|
-
}
|
|
1552
|
-
function mapRowsToNMap(rows) {
|
|
1553
|
-
const out = /* @__PURE__ */ new Map();
|
|
1554
|
-
for (const row of rows) {
|
|
1555
|
-
if (!isPerfRow(row)) continue;
|
|
1556
|
-
if (typeof row.n !== "number") continue;
|
|
1557
|
-
const existing = out.get(row.model_id) ?? {};
|
|
1558
|
-
existing[row.archetype] = row.n;
|
|
1559
|
-
out.set(row.model_id, existing);
|
|
1560
|
-
}
|
|
1561
|
-
return out;
|
|
1562
|
-
}
|
|
1563
|
-
function bundledArchetypePerf() {
|
|
1564
|
-
const out = /* @__PURE__ */ new Map();
|
|
1565
|
-
for (const profile of allProfiles()) {
|
|
1566
|
-
if (profile.archetypePerf) out.set(profile.id, profile.archetypePerf);
|
|
1567
|
-
}
|
|
1568
|
-
return out;
|
|
1569
|
-
}
|
|
1570
|
-
function bundledArchetypePerfN() {
|
|
1571
|
-
return /* @__PURE__ */ new Map();
|
|
1572
|
-
}
|
|
1573
|
-
var loadArchetypePerfFromBrain = createBrainQueryCache({
|
|
1574
|
-
table: "kgauto_archetype_perf",
|
|
1575
|
-
mapRows: mapRowsToPerfMap,
|
|
1576
|
-
bundledFallback: bundledArchetypePerf
|
|
1577
|
-
});
|
|
1578
|
-
var loadArchetypePerfNFromBrain = createBrainQueryCache(
|
|
1579
|
-
{
|
|
1580
|
-
table: "kgauto_archetype_perf",
|
|
1581
|
-
mapRows: mapRowsToNMap,
|
|
1582
|
-
bundledFallback: bundledArchetypePerfN
|
|
1583
|
-
}
|
|
1584
|
-
);
|
|
1585
|
-
var MEASURED_GROUNDING_MIN_N = 10;
|
|
1586
|
-
function getArchetypePerfScore(modelId, archetype) {
|
|
1587
|
-
const score = loadArchetypePerfFromBrain().get(modelId)?.[archetype] ?? 5;
|
|
1588
|
-
const n = loadArchetypePerfNFromBrain().get(modelId)?.[archetype] ?? 0;
|
|
1589
|
-
const grounding = n >= MEASURED_GROUNDING_MIN_N ? "measured" : "judgment";
|
|
1590
|
-
return { score, n, grounding };
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
1543
|
// src/measured-failure-brain.ts
|
|
1594
1544
|
function coerceCount(v) {
|
|
1595
1545
|
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
|
@@ -2542,11 +2492,37 @@ function detectSingleModelArray(ir, policy) {
|
|
|
2542
2492
|
level: "warn",
|
|
2543
2493
|
code: "single-model-array",
|
|
2544
2494
|
message: `\`ir.models\` has length 1 (only "${only}") and posture is not 'locked'. A single-model chain has no safety net \u2014 the first 429 / 5xx / cliff hits the user as a failure. Master plan \xA71.2 closes the reliability gap with a 2-step minimum.`,
|
|
2545
|
-
|
|
2495
|
+
// alpha.80: `posture: 'preferred'` keeps the consumer's current model at
|
|
2496
|
+
// position 0 and is therefore cost-neutral; `'open'` re-picks the
|
|
2497
|
+
// primary and is NOT. This rule is about reliability, not cost, so both
|
|
2498
|
+
// stay on offer — but the cost consequence of the second is now stated,
|
|
2499
|
+
// since a reliability fix should not silently become a repricing.
|
|
2500
|
+
suggestion: "Use `getDefaultFallbackChain({ archetype: ir.intent.archetype, primary: '" + only + "', posture: 'preferred' })` for a user-anchored chain \u2014 this keeps `" + only + "` as your primary and only adds fallbacks, so your cost profile is unchanged. `getDefaultFallbackChain({ archetype, posture: 'open' })` instead lets the library pick the PRIMARY, ordered by archetype performance rather than cost \u2014 check what it returns before adopting it. If single-model is intentional (compliance/brand promise), set `policy.posture = 'locked'` to silence this rule.",
|
|
2546
2501
|
docsUrl: "https://github.com/stue/command-center/blob/main/interfaces/kgauto.md#single-model-array"
|
|
2547
2502
|
}
|
|
2548
2503
|
];
|
|
2549
2504
|
}
|
|
2505
|
+
function openPostureRemedyClause(archetype, recommended, resolveProfile) {
|
|
2506
|
+
const openChain = getDefaultFallbackChain({ archetype, posture: "open" });
|
|
2507
|
+
const openPrimaryId = openChain[0];
|
|
2508
|
+
if (!openPrimaryId) return void 0;
|
|
2509
|
+
const openPrimary = resolveProfile(openPrimaryId);
|
|
2510
|
+
if (!openPrimary) return void 0;
|
|
2511
|
+
const openCost = estimateChainCostUsd(openPrimary);
|
|
2512
|
+
const recommendedCost = estimateChainCostUsd(recommended);
|
|
2513
|
+
if (openCost >= recommendedCost) return void 0;
|
|
2514
|
+
const ratio = recommendedCost / openCost;
|
|
2515
|
+
return ` Relaxing to \`policy.posture = 'open'\` is also viable here \u2014 it selects \`${openPrimaryId}\`, which is ${ratio >= 1.1 ? `about ${ratio.toFixed(1)}x cheaper than` : "priced comparably to"} \`${recommended.id}\` at a reference call shape. Note the library chain is ordered by archetype performance, not cost; it happens to agree with the cost recommendation for this archetype.`;
|
|
2516
|
+
}
|
|
2517
|
+
function openPostureCostWarningClause(archetype, recommended, resolveProfile) {
|
|
2518
|
+
const openChain = getDefaultFallbackChain({ archetype, posture: "open" });
|
|
2519
|
+
const openPrimaryId = openChain[0];
|
|
2520
|
+
const openPrimary = openPrimaryId ? resolveProfile(openPrimaryId) : void 0;
|
|
2521
|
+
if (!openPrimary || !openPrimaryId) return "";
|
|
2522
|
+
const ratio = estimateChainCostUsd(openPrimary) / estimateChainCostUsd(recommended);
|
|
2523
|
+
if (ratio < 1) return "";
|
|
2524
|
+
return ` Do NOT reach for \`posture = 'open'\` as a cost fix here: the library chain is ordered by archetype performance, not cost, and would select \`${openPrimaryId}\` \u2014 roughly ${ratio.toFixed(1)}x the cost of \`${recommended.id}\`. Pass \`getDefaultFallbackChain({ archetype: '${archetype}', posture: 'open', optimizeFor: 'cost' })\` if you want a library-picked chain that is actually cost-ordered.`;
|
|
2525
|
+
}
|
|
2550
2526
|
function detectCostMismatchedArchetype(ir, profile, phase2) {
|
|
2551
2527
|
if (!phase2 || phase2.fallbackChain.length === 0) return [];
|
|
2552
2528
|
if (!phase2.profileResolver) return [];
|
|
@@ -2596,7 +2572,12 @@ function detectCostMismatchedArchetype(ir, profile, phase2) {
|
|
|
2596
2572
|
level: "warn",
|
|
2597
2573
|
code: "cost-mismatched-archetype",
|
|
2598
2574
|
message: `Cost-mismatched-archetype: target=${profile.id} (${chosenGrounding}) selected for ${archetype}. Alternative ${bestAlt.id} (${altGrounding}) is cheaper ($${bestAlt.profile.costInputPer1m}/$${bestAlt.profile.costOutputPer1m} vs $${profile.costInputPer1m}/$${profile.costOutputPer1m} per 1M) at equal-or-better quality.`,
|
|
2599
|
-
|
|
2575
|
+
// alpha.80 (tt-intel's `chain-builder-and-cost-advisories-give-opposite-answers`):
|
|
2576
|
+
// this field used to offer `posture='open'` unconditionally, alongside
|
|
2577
|
+
// the cheap-model swap, as if the two were equivalent remedies. They
|
|
2578
|
+
// point in opposite directions. Both branches are now computed from
|
|
2579
|
+
// the chain builder rather than assumed.
|
|
2580
|
+
suggestion: `Consider declaring \`${bestAlt.id}\` as the primary model for this archetype.` + (openPostureRemedyClause(archetype, bestAlt.profile, phase2.profileResolver) ?? openPostureCostWarningClause(archetype, bestAlt.profile, phase2.profileResolver)) + ` If the chosen model is required for compliance/brand reasons, set \`policy.posture = 'locked'\` to silence this rule.`,
|
|
2600
2581
|
recommendationType: profile.provider === bestAlt.profile.provider ? "tier-down" : "model-swap",
|
|
2601
2582
|
docsUrl: "https://github.com/stue/command-center/blob/main/interfaces/kgauto.md#best-practice-advisories"
|
|
2602
2583
|
}
|
|
@@ -2675,7 +2656,12 @@ function detectArchetypePerfFloorBreach(ir, profile) {
|
|
|
2675
2656
|
level: "critical",
|
|
2676
2657
|
code: "archetype-perf-floor-breach",
|
|
2677
2658
|
message: `${profile.id} sits below the archetype floor for ${ir.intent.archetype} (score ${compat.archetypePerf}/10, floor ${6}) and no known adapter would lift it. ${compat.reason}`,
|
|
2678
|
-
|
|
2659
|
+
// alpha.80: this rule's advice is correct on the QUALITY axis and was
|
|
2660
|
+
// silent on cost, so a consumer reading it as a general "let the
|
|
2661
|
+
// library pick" endorsement could land on a materially pricier
|
|
2662
|
+
// primary. The floor recommendation stands; the axis is now named,
|
|
2663
|
+
// and the cost-ordered variant is offered alongside it.
|
|
2664
|
+
suggestion: `Swap to a model whose archetypePerf for ${ir.intent.archetype} clears the floor. Use \`getModelCompatibility(candidateId, { archetype: '${ir.intent.archetype}' })\` to vet candidates, or \`getDefaultFallbackChain({ archetype: '${ir.intent.archetype}', posture: 'open' })\` for a library-picked chain that respects the floor by construction \u2014 note that chain is ordered by archetype performance, NOT cost, so it may select a pricier primary than you run today. Add \`optimizeFor: 'cost'\` for a chain that clears the same floor cheapest-first.`,
|
|
2679
2665
|
recommendationType: "model-swap",
|
|
2680
2666
|
docsUrl: "https://github.com/stue/command-center/blob/main/interfaces/kgauto.md#best-practice-advisories"
|
|
2681
2667
|
}
|
|
@@ -7100,6 +7086,7 @@ export {
|
|
|
7100
7086
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
7101
7087
|
BRAIN_READ_ENV_NAMES,
|
|
7102
7088
|
COACH_CFG,
|
|
7089
|
+
COST_RANKING_REFERENCE_SHAPE,
|
|
7103
7090
|
CallError,
|
|
7104
7091
|
DECOMPOSITION_TEMPLATES,
|
|
7105
7092
|
DECOMPOSITION_TEMPLATES_VERSION,
|
|
@@ -7144,6 +7131,7 @@ export {
|
|
|
7144
7131
|
buildShadowProbeRow,
|
|
7145
7132
|
call,
|
|
7146
7133
|
captureGoldenIr,
|
|
7134
|
+
chainProviderSpread,
|
|
7147
7135
|
classifyStrategyOutcome,
|
|
7148
7136
|
clearBrain,
|
|
7149
7137
|
combineOrderSwappedVerdicts,
|
|
@@ -7158,6 +7146,7 @@ export {
|
|
|
7158
7146
|
createKeyHealthRoute,
|
|
7159
7147
|
deriveFamilyFromModelId,
|
|
7160
7148
|
deriveOwnership,
|
|
7149
|
+
estimateChainCostUsd,
|
|
7161
7150
|
execute,
|
|
7162
7151
|
findBetterFit,
|
|
7163
7152
|
flushBrainDeadLetter,
|
package/dist/key-health.js
CHANGED
|
@@ -25,7 +25,7 @@ __export(key_health_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(key_health_exports);
|
|
26
26
|
|
|
27
27
|
// src/version.ts
|
|
28
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
28
|
+
var LIBRARY_VERSION = "2.0.0-alpha.80";
|
|
29
29
|
|
|
30
30
|
// src/key-health.ts
|
|
31
31
|
var JSON_HEADERS = { "Content-Type": "application/json" };
|
package/dist/key-health.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warmdrift/kgauto-compiler",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.80",
|
|
4
4
|
"description": "Prompt compiler with executable provider knowledge for multi-model AI apps: normalized multi-provider transport with fallback chains, compile-time cliff guards, a curated model registry, and a telemetry flight recorder. Swap models without rewriting prompts.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|