@warmdrift/kgauto-compiler 2.0.0-alpha.27 → 2.0.0-alpha.28
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-WXCFWUCN.mjs +678 -0
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/index.d.mts +88 -6
- package/dist/glassbox-routes/index.d.ts +88 -6
- package/dist/glassbox-routes/index.js +1820 -8
- package/dist/glassbox-routes/index.mjs +320 -8
- package/dist/index.d.mts +184 -3
- package/dist/index.d.ts +184 -3
- package/dist/index.js +161 -5
- package/dist/index.mjs +107 -580
- package/dist/{ir-B_XX2LAO.d.ts → ir-5W0efxt9.d.ts} +86 -1
- package/dist/{ir-B9zqlwjH.d.mts → ir-MXCJA8L7.d.mts} +86 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-bt0aVJb8.d.ts → types-CiZ9HLIU.d.ts} +1 -1
- package/dist/{types-o9etg93a.d.mts → types-sDZQzPM6.d.mts} +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { 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, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as
|
|
2
|
-
export {
|
|
1
|
+
import { 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, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as Adapter, i as PerAxisMetrics, j as Provider, k as ChainEntry, G as Grounding } from './ir-5W0efxt9.js';
|
|
2
|
+
export { l as CallAttempt, m as CallError, n as ChainWithGrounding, o as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, p as MutationApplied, q as NormalizedTokens, r as OutcomeKind, s as PerAxisMetricsByModel, t as PromptSection, T as ToolCall, u as ToolDefinition } from './ir-5W0efxt9.js';
|
|
3
3
|
import { ModelProfile } from './profiles.js';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, profilesByProvider, tryGetProfile } from './profiles.js';
|
|
5
5
|
import { IntentArchetypeName } from './dialect.js';
|
|
@@ -205,6 +205,13 @@ interface OutcomePayload {
|
|
|
205
205
|
* cliff lumps DeepSeek sequential perf with parallel without this).
|
|
206
206
|
*/
|
|
207
207
|
tool_orchestration?: 'parallel' | 'sequential' | 'either' | null;
|
|
208
|
+
finish_reason?: string;
|
|
209
|
+
total_ms?: number;
|
|
210
|
+
tools_count?: number;
|
|
211
|
+
history_depth?: number;
|
|
212
|
+
system_prompt_chars?: number;
|
|
213
|
+
fell_over_from?: string;
|
|
214
|
+
fallback_reason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
|
|
208
215
|
}
|
|
209
216
|
/**
|
|
210
217
|
* alpha.20 Entry 4: record a quality outcome for a previously-compiled call.
|
|
@@ -358,6 +365,180 @@ interface RunAdvisorPhase2Context {
|
|
|
358
365
|
*/
|
|
359
366
|
declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: ModelProfile, policy?: CompilePolicy, phase2?: RunAdvisorPhase2Context): BestPracticeAdvisory[];
|
|
360
367
|
|
|
368
|
+
/**
|
|
369
|
+
* Archetype-cliff compatibility — alpha.28 (tt-intel-Cairn ratified).
|
|
370
|
+
*
|
|
371
|
+
* One question, one answer: *given this model and this intent, can it work
|
|
372
|
+
* — and if not, what adapter (if any) would make it work?*
|
|
373
|
+
*
|
|
374
|
+
* Replaces the silent-archetype-cliff failure mode where a consumer picks a
|
|
375
|
+
* model that's structurally wrong for the intent and kgauto compiles cleanly
|
|
376
|
+
* without surfacing the gap. The triggering incident: tt-intel shipped
|
|
377
|
+
* `deepseek-v4-pro` as the hunt default per a local spec; the kgauto coord
|
|
378
|
+
* doc said L-040 — V4 is structurally wrong for hunt (sequential tools).
|
|
379
|
+
* `archetypePerf.hunt = 4` was already in the profile data. The compiler
|
|
380
|
+
* stayed silent. This API + the matching advisor rule surfaces it.
|
|
381
|
+
*
|
|
382
|
+
* Pure function. No network. No brain query. No side effects. ~1ms.
|
|
383
|
+
*
|
|
384
|
+
* Consultation doc:
|
|
385
|
+
* command-center/advisory/kgauto/2026-05-21_archetype-cliff-advisor.md
|
|
386
|
+
*
|
|
387
|
+
* Refinements applied per tt-intel-Cairn ratification (2026-05-21):
|
|
388
|
+
* R1: every variant carries `archetypePerf: number` (raw score) — and
|
|
389
|
+
* `requires-adapter` adds `archetypePerfWithAdapter: number` so
|
|
390
|
+
* consumer policy can be expressed as "accept adapter only when score
|
|
391
|
+
* crosses some threshold WITH the adapter on."
|
|
392
|
+
* R2: every variant carries a plain-English `reason: string`. No internal
|
|
393
|
+
* jargon ("L-040", "archetypePerf=4") — the consumer chooses whether
|
|
394
|
+
* to render it as UI hint or operator-tooling tooltip.
|
|
395
|
+
* R3: `Adapter` is a CLOSED discriminated union, not `| string`. alpha.28
|
|
396
|
+
* ships ONE variant (`toolOrchestration: 'sequential'`). Future
|
|
397
|
+
* adapter parameters extend the union explicitly in named releases.
|
|
398
|
+
* NO escape hatch — the whole point is catching "I added a new
|
|
399
|
+
* adapter and forgot to update consumer policy" at compile time.
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Minimum `archetypePerf[archetype]` score to count as `compatible` under
|
|
404
|
+
* Option A (default policy). Below this, a documented adapter is needed
|
|
405
|
+
* to lift the model above the floor; if no adapter exists, the model is
|
|
406
|
+
* rejected.
|
|
407
|
+
*
|
|
408
|
+
* Matches `QUALITY_FLOOR_FOR_RECOMMENDATION` in `advisor.ts` — kgauto's
|
|
409
|
+
* library-wide convention for "below this score, swap recommendations stop."
|
|
410
|
+
*/
|
|
411
|
+
declare const ARCHETYPE_FLOOR_DEFAULT = 6;
|
|
412
|
+
/**
|
|
413
|
+
* Absolute floor — below this, the cliff is too steep for ANY adapter to
|
|
414
|
+
* lift cleanly. Reserved under Option A (unused today; every below-floor
|
|
415
|
+
* case is gated by adapter availability). Would gate `reject` vs
|
|
416
|
+
* `requires-adapter` under a future Option B per consultation doc Q1.
|
|
417
|
+
*
|
|
418
|
+
* Exported so consumer-side policy can read it (e.g. "accept adapter only
|
|
419
|
+
* when archetypePerf >= ABSOLUTE_FLOOR + 1"). Not used internally by
|
|
420
|
+
* `getModelCompatibility` today — the gate is "does an adapter exist for
|
|
421
|
+
* this cliff?", not score-based.
|
|
422
|
+
*/
|
|
423
|
+
declare const ABSOLUTE_FLOOR = 4;
|
|
424
|
+
/**
|
|
425
|
+
* The intent the call is expressing — archetype + optional orchestration
|
|
426
|
+
* mode. Same shape as `ir.intent.archetype` + `ir.constraints.toolOrchestration`
|
|
427
|
+
* so a consumer can pass `{ archetype: ir.intent.archetype,
|
|
428
|
+
* toolOrchestration: ir.constraints?.toolOrchestration }` directly.
|
|
429
|
+
*/
|
|
430
|
+
interface CompatibilityIntent {
|
|
431
|
+
archetype: IntentArchetypeName;
|
|
432
|
+
toolOrchestration?: 'parallel' | 'sequential' | 'either';
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* `Adapter` — re-exported above. Canonical definition lives in `ir.ts` to
|
|
436
|
+
* avoid an import cycle (compatibility.ts → profiles.ts → ir.ts).
|
|
437
|
+
*
|
|
438
|
+
* **CLOSED discriminated union per R3.** Future adapter parameters extend
|
|
439
|
+
* the union explicitly in named alpha releases. No `| string` escape hatch
|
|
440
|
+
* — consumer policy code SHOULD write exhaustive `switch (adapter.parameter)`
|
|
441
|
+
* and rely on the compiler to flag "I added a new adapter parameter and
|
|
442
|
+
* forgot to update the consumer's policy."
|
|
443
|
+
*
|
|
444
|
+
* alpha.28 variants:
|
|
445
|
+
* - `{ parameter: 'toolOrchestration'; value: 'sequential'; consequence }`
|
|
446
|
+
* Lifts DeepSeek V4-family on `hunt` from sequential-tool cliff (L-040).
|
|
447
|
+
* The "consequence" plain-English-ifies the trade-off:
|
|
448
|
+
* "Tool calls run one at a time — slower but reliable."
|
|
449
|
+
*
|
|
450
|
+
* alpha.29+ likely additions (per tt-intel-Cairn priority list):
|
|
451
|
+
* - `{ parameter: 'parallelToolCalls'; value: false; consequence }`
|
|
452
|
+
* - `{ parameter: 'maxTools'; value: number; consequence }`
|
|
453
|
+
* - `{ parameter: 'thinkingBudget'; value: 0; consequence }`
|
|
454
|
+
*
|
|
455
|
+
* Each new variant lands in its own named release with the union extended
|
|
456
|
+
* in `ir.ts`. Consumers see the change at compile time.
|
|
457
|
+
*/
|
|
458
|
+
/**
|
|
459
|
+
* The compatibility verdict for a (model, intent) pair. Discriminated union
|
|
460
|
+
* on `status` — `compatible` | `requires-adapter` | `reject`.
|
|
461
|
+
*
|
|
462
|
+
* **Every variant carries `archetypePerf` (R1) + `reason` (R2):**
|
|
463
|
+
* - `archetypePerf` — the raw 0-10 score for (model, archetype). Lets
|
|
464
|
+
* consumers build their own thresholds without re-importing the profile
|
|
465
|
+
* registry.
|
|
466
|
+
* - `reason` — plain-English, consumer-renderable. NOT internal jargon
|
|
467
|
+
* like "L-040 cliff" or "archetypePerf=4". Examples in R2 ratification:
|
|
468
|
+
* - compatible: "Suited for hunt-style parallel discovery."
|
|
469
|
+
* - requires-adapter: "Best with sequential tool calls for hunt — slower but works."
|
|
470
|
+
* - reject: "Not suited for hunt — would underperform significantly."
|
|
471
|
+
*
|
|
472
|
+
* `requires-adapter` additionally carries:
|
|
473
|
+
* - `archetypePerfWithAdapter` — estimated post-adapter score. May be an
|
|
474
|
+
* estimate (we don't measure post-adapter scores yet); kgauto's prior is
|
|
475
|
+
* "adapter lifts to ARCHETYPE_FLOOR_DEFAULT + 1" unless brain-evidenced.
|
|
476
|
+
* - `adapter` — the closed-union variant describing the structural change.
|
|
477
|
+
*
|
|
478
|
+
* Backward-compat: an unknown model returns `reject` with a "model not
|
|
479
|
+
* registered" reason; callers never throw. Unknown archetype is impossible
|
|
480
|
+
* at the type level (`IntentArchetypeName` is a closed union).
|
|
481
|
+
*/
|
|
482
|
+
type ModelCompatibility = {
|
|
483
|
+
status: 'compatible';
|
|
484
|
+
reason: string;
|
|
485
|
+
archetypePerf: number;
|
|
486
|
+
} | {
|
|
487
|
+
status: 'requires-adapter';
|
|
488
|
+
reason: string;
|
|
489
|
+
archetypePerf: number;
|
|
490
|
+
archetypePerfWithAdapter: number;
|
|
491
|
+
adapter: Adapter;
|
|
492
|
+
} | {
|
|
493
|
+
status: 'reject';
|
|
494
|
+
reason: string;
|
|
495
|
+
archetypePerf: number;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Compatibility query — *does this model fit this intent, and if not,
|
|
499
|
+
* what would?*
|
|
500
|
+
*
|
|
501
|
+
* **Rules (Option A from consultation doc Q1):**
|
|
502
|
+
* 1. If model is unregistered → `reject` with "model not registered" reason.
|
|
503
|
+
* 2. If intent provides `toolOrchestration: 'sequential'` AND that adapter
|
|
504
|
+
* silences the cliff (because the cliff IS the sequential-tool one)
|
|
505
|
+
* → return `compatible` with raw score (NOT the post-adapter estimate
|
|
506
|
+
* — caller already paid the adapter, score reflects reality).
|
|
507
|
+
* 3. If raw `archetypePerf[archetype] >= ARCHETYPE_FLOOR_DEFAULT`
|
|
508
|
+
* → `compatible`.
|
|
509
|
+
* 4. If below floor BUT a documented adapter exists that lifts to floor
|
|
510
|
+
* → `requires-adapter` with adapter + estimated post-adapter score.
|
|
511
|
+
* 5. If below floor AND no adapter exists → `reject`.
|
|
512
|
+
*
|
|
513
|
+
* **Pure function.** Deterministic for `(modelId, intent)`. No I/O.
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```ts
|
|
517
|
+
* import { getModelCompatibility } from '@warmdrift/kgauto-compiler';
|
|
518
|
+
*
|
|
519
|
+
* const c = getModelCompatibility('deepseek-v4-pro', { archetype: 'hunt' });
|
|
520
|
+
* // → { status: 'requires-adapter',
|
|
521
|
+
* // reason: 'Best with sequential tool calls for hunt — slower but works.',
|
|
522
|
+
* // archetypePerf: 4,
|
|
523
|
+
* // archetypePerfWithAdapter: 7,
|
|
524
|
+
* // adapter: {
|
|
525
|
+
* // parameter: 'toolOrchestration',
|
|
526
|
+
* // value: 'sequential',
|
|
527
|
+
* // consequence: 'Tool calls run one at a time...'
|
|
528
|
+
* // } }
|
|
529
|
+
*
|
|
530
|
+
* // With the adapter already declared:
|
|
531
|
+
* const c2 = getModelCompatibility('deepseek-v4-pro', {
|
|
532
|
+
* archetype: 'hunt',
|
|
533
|
+
* toolOrchestration: 'sequential',
|
|
534
|
+
* });
|
|
535
|
+
* // → { status: 'compatible',
|
|
536
|
+
* // reason: 'Suited for hunt with sequential tool calls.',
|
|
537
|
+
* // archetypePerf: 4 }
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
declare function getModelCompatibility(modelId: string, intent: CompatibilityIntent): ModelCompatibility;
|
|
541
|
+
|
|
361
542
|
/**
|
|
362
543
|
* alpha.22 — sync introspection: is brain-query mode active for a given
|
|
363
544
|
* table? Used by the advisor (`model-stale-evidence` rule) to decide
|
|
@@ -943,4 +1124,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
|
|
|
943
1124
|
*/
|
|
944
1125
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
945
1126
|
|
|
946
|
-
export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
|
1127
|
+
export { ABSOLUTE_FLOOR, ARCHETYPE_FLOOR_DEFAULT, Adapter, ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
package/dist/index.js
CHANGED
|
@@ -20,8 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ABSOLUTE_FLOOR: () => ABSOLUTE_FLOOR,
|
|
23
24
|
ALIASES: () => ALIASES,
|
|
24
25
|
ALL_ARCHETYPES: () => ALL_ARCHETYPES,
|
|
26
|
+
ARCHETYPE_FLOOR_DEFAULT: () => ARCHETYPE_FLOOR_DEFAULT,
|
|
25
27
|
CallError: () => CallError,
|
|
26
28
|
DIALECT_VERSION: () => DIALECT_VERSION,
|
|
27
29
|
INTENT_ARCHETYPES: () => INTENT_ARCHETYPES,
|
|
@@ -43,6 +45,7 @@ __export(index_exports, {
|
|
|
43
45
|
getArchetypePerfScore: () => getArchetypePerfScore,
|
|
44
46
|
getDefaultFallbackChain: () => getDefaultFallbackChain,
|
|
45
47
|
getDefaultFallbackChainWithGrounding: () => getDefaultFallbackChainWithGrounding,
|
|
48
|
+
getModelCompatibility: () => getModelCompatibility,
|
|
46
49
|
getPerAxisMetrics: () => getPerAxisMetrics,
|
|
47
50
|
getProfile: () => getProfile,
|
|
48
51
|
getReachabilityDiagnostic: () => getReachabilityDiagnostic,
|
|
@@ -2307,6 +2310,86 @@ function getArchetypePerfScore(modelId, archetype) {
|
|
|
2307
2310
|
return { score, n, grounding };
|
|
2308
2311
|
}
|
|
2309
2312
|
|
|
2313
|
+
// src/compatibility.ts
|
|
2314
|
+
var ARCHETYPE_FLOOR_DEFAULT = 6;
|
|
2315
|
+
var ABSOLUTE_FLOOR = 4;
|
|
2316
|
+
function rawArchetypePerf(profile, archetype) {
|
|
2317
|
+
return profile.archetypePerf?.[archetype] ?? 5;
|
|
2318
|
+
}
|
|
2319
|
+
function hasSequentialToolCliffForHunt(profile) {
|
|
2320
|
+
if (profile.parallelToolCalls !== false) return false;
|
|
2321
|
+
const huntScore = profile.archetypePerf?.hunt ?? 5;
|
|
2322
|
+
return huntScore < ARCHETYPE_FLOOR_DEFAULT;
|
|
2323
|
+
}
|
|
2324
|
+
function adapterForCliff(profile, archetype) {
|
|
2325
|
+
if (archetype === "hunt" && hasSequentialToolCliffForHunt(profile)) {
|
|
2326
|
+
const otherScores = [];
|
|
2327
|
+
if (profile.archetypePerf) {
|
|
2328
|
+
for (const [k, v] of Object.entries(profile.archetypePerf)) {
|
|
2329
|
+
if (k === "hunt") continue;
|
|
2330
|
+
if (typeof v === "number") otherScores.push(v);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
const sorted = [...otherScores].sort((a, b) => a - b);
|
|
2334
|
+
const median = sorted.length === 0 ? ARCHETYPE_FLOOR_DEFAULT + 1 : sorted[Math.floor(sorted.length / 2)] ?? ARCHETYPE_FLOOR_DEFAULT + 1;
|
|
2335
|
+
const estimated = Math.max(ARCHETYPE_FLOOR_DEFAULT + 1, median);
|
|
2336
|
+
return {
|
|
2337
|
+
adapter: {
|
|
2338
|
+
parameter: "toolOrchestration",
|
|
2339
|
+
value: "sequential",
|
|
2340
|
+
consequence: "Tool calls run one at a time instead of in parallel \u2014 slower per step but reliable for this model."
|
|
2341
|
+
},
|
|
2342
|
+
estimatedScoreWithAdapter: estimated
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
return void 0;
|
|
2346
|
+
}
|
|
2347
|
+
function archetypeDescriptor(archetype) {
|
|
2348
|
+
return archetype;
|
|
2349
|
+
}
|
|
2350
|
+
function getModelCompatibility(modelId, intent) {
|
|
2351
|
+
const profile = tryGetProfile(modelId);
|
|
2352
|
+
if (!profile) {
|
|
2353
|
+
return {
|
|
2354
|
+
status: "reject",
|
|
2355
|
+
reason: `Model "${modelId}" is not registered with kgauto \u2014 no compatibility data available.`,
|
|
2356
|
+
archetypePerf: 0
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
const { archetype, toolOrchestration } = intent;
|
|
2360
|
+
const rawScore = rawArchetypePerf(profile, archetype);
|
|
2361
|
+
const descriptor = archetypeDescriptor(archetype);
|
|
2362
|
+
const adapterMatch = adapterForCliff(profile, archetype);
|
|
2363
|
+
if (toolOrchestration === "sequential" && adapterMatch && adapterMatch.adapter.parameter === "toolOrchestration" && adapterMatch.adapter.value === "sequential") {
|
|
2364
|
+
return {
|
|
2365
|
+
status: "compatible",
|
|
2366
|
+
reason: `Suited for ${descriptor} with sequential tool calls.`,
|
|
2367
|
+
archetypePerf: rawScore
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
if (rawScore >= ARCHETYPE_FLOOR_DEFAULT) {
|
|
2371
|
+
return {
|
|
2372
|
+
status: "compatible",
|
|
2373
|
+
reason: `Suited for ${descriptor}.`,
|
|
2374
|
+
archetypePerf: rawScore
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
if (adapterMatch) {
|
|
2378
|
+
return {
|
|
2379
|
+
status: "requires-adapter",
|
|
2380
|
+
reason: `Best with ${adapterMatch.adapter.value} ${adapterMatch.adapter.parameter === "toolOrchestration" ? "tool calls" : adapterMatch.adapter.parameter} for ${descriptor} \u2014 slower but works.`,
|
|
2381
|
+
archetypePerf: rawScore,
|
|
2382
|
+
archetypePerfWithAdapter: adapterMatch.estimatedScoreWithAdapter,
|
|
2383
|
+
adapter: adapterMatch.adapter
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
return {
|
|
2387
|
+
status: "reject",
|
|
2388
|
+
reason: `Not suited for ${descriptor} \u2014 would underperform significantly.`,
|
|
2389
|
+
archetypePerf: rawScore
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2310
2393
|
// src/advisor.ts
|
|
2311
2394
|
var QUALITY_FLOOR_FOR_RECOMMENDATION = 6;
|
|
2312
2395
|
var TIER_DOWN_COST_RATIO = 0.5;
|
|
@@ -2323,6 +2406,7 @@ function runAdvisor(ir, result, profile, policy, phase2) {
|
|
|
2323
2406
|
out.push(...detectModelStaleEvidence(ir, profile));
|
|
2324
2407
|
out.push(...detectTierDown(ir, profile, phase2));
|
|
2325
2408
|
}
|
|
2409
|
+
out.push(...detectArchetypePerfFloorBreach(ir, profile));
|
|
2326
2410
|
return out;
|
|
2327
2411
|
}
|
|
2328
2412
|
function detectCachingOff(ir, profile) {
|
|
@@ -2493,6 +2577,36 @@ function detectTierDown(ir, profile, phase2) {
|
|
|
2493
2577
|
}
|
|
2494
2578
|
];
|
|
2495
2579
|
}
|
|
2580
|
+
function detectArchetypePerfFloorBreach(ir, profile) {
|
|
2581
|
+
const compat = getModelCompatibility(profile.id, {
|
|
2582
|
+
archetype: ir.intent.archetype,
|
|
2583
|
+
toolOrchestration: ir.constraints?.toolOrchestration
|
|
2584
|
+
});
|
|
2585
|
+
if (compat.status === "compatible") return [];
|
|
2586
|
+
if (compat.status === "requires-adapter") {
|
|
2587
|
+
return [
|
|
2588
|
+
{
|
|
2589
|
+
level: "warn",
|
|
2590
|
+
code: "archetype-perf-floor-breach",
|
|
2591
|
+
message: `${profile.id} sits below the archetype floor for ${ir.intent.archetype} (score ${compat.archetypePerf}/10, floor ${6}). A known adapter would lift it: ${compat.adapter.parameter}=${compat.adapter.value}. ${compat.adapter.consequence}`,
|
|
2592
|
+
suggestion: `Pass \`ir.constraints.${compat.adapter.parameter} = '${compat.adapter.value}'\` for this call, OR pick a model whose archetypePerf for ${ir.intent.archetype} already clears the floor (call \`getModelCompatibility(modelId, { archetype: '${ir.intent.archetype}' })\` to check). Estimated post-adapter score: ${compat.archetypePerfWithAdapter}/10.`,
|
|
2593
|
+
recommendationType: "prompt-fix",
|
|
2594
|
+
suggestedAdaptation: compat.adapter,
|
|
2595
|
+
docsUrl: "https://github.com/stue/command-center/blob/main/interfaces/kgauto.md#best-practice-advisories"
|
|
2596
|
+
}
|
|
2597
|
+
];
|
|
2598
|
+
}
|
|
2599
|
+
return [
|
|
2600
|
+
{
|
|
2601
|
+
level: "critical",
|
|
2602
|
+
code: "archetype-perf-floor-breach",
|
|
2603
|
+
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}`,
|
|
2604
|
+
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.`,
|
|
2605
|
+
recommendationType: "model-swap",
|
|
2606
|
+
docsUrl: "https://github.com/stue/command-center/blob/main/interfaces/kgauto.md#best-practice-advisories"
|
|
2607
|
+
}
|
|
2608
|
+
];
|
|
2609
|
+
}
|
|
2496
2610
|
|
|
2497
2611
|
// src/compile.ts
|
|
2498
2612
|
var counter = 0;
|
|
@@ -2753,6 +2867,9 @@ function registerCompile(appId, archetype, ir, result) {
|
|
|
2753
2867
|
tokens
|
|
2754
2868
|
);
|
|
2755
2869
|
const shapeKey = `${shape.contextBucket}-${shape.toolCountBucket}-${shape.historyDepth}-${shape.outputMode}`;
|
|
2870
|
+
const toolsCount = result.diagnostics.toolsKept;
|
|
2871
|
+
const historyDepth = Array.isArray(ir.history) ? ir.history.length : 0;
|
|
2872
|
+
const systemPromptChars = estimateSystemPromptChars(ir.sections);
|
|
2756
2873
|
compileRegistry.set(result.handle, {
|
|
2757
2874
|
appId,
|
|
2758
2875
|
archetype,
|
|
@@ -2766,9 +2883,24 @@ function registerCompile(appId, archetype, ir, result) {
|
|
|
2766
2883
|
historyCacheableTokens: result.diagnostics.historyCacheableTokens,
|
|
2767
2884
|
historyTokensTotal: result.diagnostics.historyTokensTotal,
|
|
2768
2885
|
// alpha.20 E3: capture consumer's declared mode for the brain payload.
|
|
2769
|
-
toolOrchestration: result.diagnostics.toolOrchestration
|
|
2886
|
+
toolOrchestration: result.diagnostics.toolOrchestration,
|
|
2887
|
+
// alpha.28: shape fields for Glass-Box renderer.
|
|
2888
|
+
toolsCount,
|
|
2889
|
+
historyDepth,
|
|
2890
|
+
systemPromptChars
|
|
2770
2891
|
});
|
|
2771
2892
|
}
|
|
2893
|
+
function estimateSystemPromptChars(sections) {
|
|
2894
|
+
if (!Array.isArray(sections) || sections.length === 0) return void 0;
|
|
2895
|
+
let total = 0;
|
|
2896
|
+
for (const s of sections) {
|
|
2897
|
+
if (s && typeof s === "object") {
|
|
2898
|
+
const content = s.content;
|
|
2899
|
+
if (typeof content === "string") total += content.length;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
return total > 0 ? total : void 0;
|
|
2903
|
+
}
|
|
2772
2904
|
async function record(input) {
|
|
2773
2905
|
const reg = compileRegistry.get(input.handle);
|
|
2774
2906
|
if (reg) compileRegistry.delete(input.handle);
|
|
@@ -2846,6 +2978,8 @@ function buildPayload(input, reg) {
|
|
|
2846
2978
|
const mutationsApplied = input.mutationsApplied ?? reg?.mutationsApplied ?? [];
|
|
2847
2979
|
const costModel = actual;
|
|
2848
2980
|
const costUsdActual = costModel ? computeCostUsd(costModel, input.tokensIn, input.tokensOut) : void 0;
|
|
2981
|
+
const fellOverFrom = input.fellOverFrom ?? requested;
|
|
2982
|
+
const fallbackReason = fellOverFrom ? input.fallbackReason : void 0;
|
|
2849
2983
|
return {
|
|
2850
2984
|
handle: input.handle,
|
|
2851
2985
|
app_id: reg?.appId,
|
|
@@ -2880,7 +3014,16 @@ function buildPayload(input, reg) {
|
|
|
2880
3014
|
// the brain can measure per-mode model perf separately (DeepSeek in
|
|
2881
3015
|
// sequential vs parallel mode is two different stories — L-040).
|
|
2882
3016
|
// Null when consumer hadn't adopted the constraint yet.
|
|
2883
|
-
tool_orchestration: reg?.toolOrchestration ?? null
|
|
3017
|
+
tool_orchestration: reg?.toolOrchestration ?? null,
|
|
3018
|
+
// alpha.28 — Glass-Box renderer substrate (migration 018). All optional;
|
|
3019
|
+
// omitted-undefined PostgREST inserts store NULL → renderer renders "—".
|
|
3020
|
+
finish_reason: input.finishReason,
|
|
3021
|
+
total_ms: input.totalMs ?? input.latencyMs,
|
|
3022
|
+
tools_count: input.toolsCount ?? reg?.toolsCount,
|
|
3023
|
+
history_depth: input.historyDepth ?? reg?.historyDepth,
|
|
3024
|
+
system_prompt_chars: input.systemPromptChars ?? reg?.systemPromptChars,
|
|
3025
|
+
fell_over_from: fellOverFrom,
|
|
3026
|
+
fallback_reason: fallbackReason
|
|
2884
3027
|
};
|
|
2885
3028
|
}
|
|
2886
3029
|
function computeCostUsd(modelId, tokensIn, tokensOut) {
|
|
@@ -4078,6 +4221,8 @@ async function call(ir, opts = {}) {
|
|
|
4078
4221
|
latencyMs: latencyMs2
|
|
4079
4222
|
})
|
|
4080
4223
|
);
|
|
4224
|
+
const fellOver = targetModel !== initial.target;
|
|
4225
|
+
const fallbackReason = fellOver ? normalizeFallbackReason(attempts) : void 0;
|
|
4081
4226
|
await record({
|
|
4082
4227
|
handle: initial.handle,
|
|
4083
4228
|
tokensIn: validated.response.tokens.input,
|
|
@@ -4091,10 +4236,18 @@ async function call(ir, opts = {}) {
|
|
|
4091
4236
|
promptPreview: extractPromptPreview(ir),
|
|
4092
4237
|
responsePreview: validated.response.text.slice(0, 200),
|
|
4093
4238
|
cacheReadInputTokens: validated.response.tokens.cached,
|
|
4094
|
-
cacheCreationInputTokens: validated.response.tokens.cacheCreated
|
|
4239
|
+
cacheCreationInputTokens: validated.response.tokens.cacheCreated,
|
|
4240
|
+
// alpha.28 — Glass-Box renderer substrate (migration 018). call()
|
|
4241
|
+
// owns the lifecycle so it has direct visibility into finishReason
|
|
4242
|
+
// (from the normalized provider response), totalMs (mirrors latencyMs
|
|
4243
|
+
// for non-streaming; future streaming variant may diverge), and the
|
|
4244
|
+
// fell-over-from / fallback-reason pair (already computed above for
|
|
4245
|
+
// the CallResult return shape).
|
|
4246
|
+
finishReason: validated.response.finishReason,
|
|
4247
|
+
totalMs: latencyMs2,
|
|
4248
|
+
fellOverFrom: fellOver ? initial.target : void 0,
|
|
4249
|
+
fallbackReason
|
|
4095
4250
|
});
|
|
4096
|
-
const fellOver = targetModel !== initial.target;
|
|
4097
|
-
const fallbackReason = fellOver ? normalizeFallbackReason(attempts) : void 0;
|
|
4098
4251
|
if (fellOver) {
|
|
4099
4252
|
const firstFailed = attempts.find((a) => a.status !== "success");
|
|
4100
4253
|
if (firstFailed) {
|
|
@@ -4452,8 +4605,10 @@ function compile2(ir, opts) {
|
|
|
4452
4605
|
}
|
|
4453
4606
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4454
4607
|
0 && (module.exports = {
|
|
4608
|
+
ABSOLUTE_FLOOR,
|
|
4455
4609
|
ALIASES,
|
|
4456
4610
|
ALL_ARCHETYPES,
|
|
4611
|
+
ARCHETYPE_FLOOR_DEFAULT,
|
|
4457
4612
|
CallError,
|
|
4458
4613
|
DIALECT_VERSION,
|
|
4459
4614
|
INTENT_ARCHETYPES,
|
|
@@ -4475,6 +4630,7 @@ function compile2(ir, opts) {
|
|
|
4475
4630
|
getArchetypePerfScore,
|
|
4476
4631
|
getDefaultFallbackChain,
|
|
4477
4632
|
getDefaultFallbackChainWithGrounding,
|
|
4633
|
+
getModelCompatibility,
|
|
4478
4634
|
getPerAxisMetrics,
|
|
4479
4635
|
getProfile,
|
|
4480
4636
|
getReachabilityDiagnostic,
|