@warmdrift/kgauto-compiler 2.0.0-alpha.91 → 2.0.0-alpha.93
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-BTP5WK3B.mjs +3448 -0
- package/dist/{chunk-BVEXV5KC.mjs → chunk-FEMPY6EC.mjs} +5 -1
- package/dist/{chunk-54IXD5BT.mjs → chunk-S4PA2BDB.mjs} +8 -3
- package/dist/{chunk-AUZTO6Q5.mjs → chunk-WFLDRRY7.mjs} +1 -1
- package/dist/{chunk-T53ISC2F.mjs → chunk-YO2ZLPSD.mjs} +10 -0
- package/dist/compile-BlMXv6QT.d.ts +53 -0
- package/dist/compile-C2IfAGV1.d.mts +53 -0
- package/dist/dialect.d.mts +11 -1
- package/dist/dialect.d.ts +11 -1
- package/dist/dialect.js +7 -2
- package/dist/dialect.mjs +5 -3
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/format.d.mts +2 -2
- package/dist/glassbox-routes/format.d.ts +2 -2
- package/dist/glassbox-routes/index.d.mts +4 -4
- package/dist/glassbox-routes/index.d.ts +4 -4
- package/dist/glassbox-routes/index.js +7 -2
- package/dist/glassbox-routes/index.mjs +2 -2
- package/dist/glassbox-routes/react/index.d.mts +2 -2
- package/dist/glassbox-routes/react/index.d.ts +2 -2
- package/dist/index.d.mts +13 -49
- package/dist/index.d.ts +13 -49
- package/dist/index.js +95 -11
- package/dist/index.mjs +197 -3425
- package/dist/{ir-CTx026t0.d.ts → ir-DbvOFKF-.d.ts} +96 -2
- package/dist/{ir-DeYMLWge.d.mts → ir-DyMJ84je.d.mts} +96 -2
- package/dist/key-health.js +1 -1
- package/dist/key-health.mjs +1 -1
- package/dist/probe.d.mts +46 -0
- package/dist/probe.d.ts +46 -0
- package/dist/probe.js +5767 -0
- package/dist/probe.mjs +45 -0
- package/dist/profiles.d.mts +30 -2
- package/dist/profiles.d.ts +30 -2
- package/dist/profiles.js +11 -0
- package/dist/profiles.mjs +3 -1
- package/dist/{types-Cp9ot1HV.d.ts → types-5TqjBeZD.d.ts} +1 -1
- package/dist/{types-BKbRtmUb.d.ts → types-BlrbNQfj.d.ts} +1 -1
- package/dist/{types-DD36cCbZ.d.mts → types-D441T-KC.d.mts} +1 -1
- package/dist/{types-cBzinzUR.d.mts → types-_myk4bxn.d.mts} +1 -1
- package/package.json +7 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, _testClearConsumerProfiles, allProfiles, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile } from './profiles.js';
|
|
1
|
+
import { C as CompileOptions } from './compile-BlMXv6QT.js';
|
|
2
|
+
import { N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, C as CompiledRequest, a as CompilePolicy, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, F as FallbackReason, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OutcomeSource, i as OracleScore, j as Adapter, k as PerAxisMetrics, l as Provider, m as ChainEntry, G as Grounding } from './ir-DbvOFKF-.js';
|
|
3
|
+
export { n as CallAttempt, o as CallError, p as ChainModelEntry, q as ChainWithGrounding, r as Constraints, E as EffortLevel, s as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, t as MutationApplied, u as NormalizedTokens, v as OutcomeKind, w as PerAxisMetricsByModel, x as PromptSection, y as SectionKind, z as ShadowProbeConfig, T as ToolCall, D as ToolDefinition, J as captureGoldenIr, K as hasMutation, L as mutationId, Q as parseGoldenCaptureRate, U as resolveGoldenCaptureRate, V as shouldCaptureGolden } from './ir-DbvOFKF-.js';
|
|
5
4
|
export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.js';
|
|
6
5
|
export { KEY_FINGERPRINT_DOMAIN, KEY_FINGERPRINT_LENGTH, KeyHealthConfig, KeyHealthProvider, KeyHealthResponseBody, KeyHealthResult, KeyHealthRoute, createKeyHealthRoute, keyFingerprint } from './key-health.js';
|
|
6
|
+
import { ModelProfile, ArchetypeConvention } from './profiles.js';
|
|
7
|
+
export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, _testClearConsumerProfiles, allProfiles, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile } from './profiles.js';
|
|
7
8
|
import { IntentArchetypeName, OutputMode } from './dialect.js';
|
|
8
9
|
export { ALL_ARCHETYPES, ContextBucket, DIALECT_VERSION, HistoryDepth, INTENT_ARCHETYPES, ShapeSignature, ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey } from './dialect.js';
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
* compile() — the main orchestrator.
|
|
12
|
-
*
|
|
13
|
-
* Runs all passes in order, picks a target, lowers to wire format, returns
|
|
14
|
-
* a CompileResult the caller uses to make the actual provider call.
|
|
15
|
-
*
|
|
16
|
-
* Pure function in v2.0.0-alpha.1: no network, no I/O, no mutation cache yet.
|
|
17
|
-
* Mutation cache will be added in v2.1 when the brain has data to push.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
interface CompileOptions {
|
|
21
|
-
/** Custom profile resolver — for tests or custom profile sets. */
|
|
22
|
-
profileResolver?: (id: string) => ModelProfile;
|
|
23
|
-
/** Tool relevance threshold (default 0.2). */
|
|
24
|
-
toolRelevanceThreshold?: number;
|
|
25
|
-
/** History compression — turns count threshold (default 8). */
|
|
26
|
-
compressHistoryAfter?: number;
|
|
27
|
-
/**
|
|
28
|
-
* History compression — token threshold (alpha.7). When total history
|
|
29
|
-
* tokens exceed this AND there are more recent turns to keep, compress
|
|
30
|
-
* even when count threshold is below `compressHistoryAfter`. Catches
|
|
31
|
-
* fat-message bloat (tool-using agents pack many tool-call/result pairs
|
|
32
|
-
* into single assistant messages — count stays low, tokens explode).
|
|
33
|
-
* Default undefined (disabled — backward-compatible).
|
|
34
|
-
*/
|
|
35
|
-
compressHistoryAboveTokens?: number;
|
|
36
|
-
/**
|
|
37
|
-
* Consumer-declared policy. Filters blocked models, enforces cost
|
|
38
|
-
* ceiling, boosts preferred. See CompilePolicy in ir.ts.
|
|
39
|
-
*/
|
|
40
|
-
policy?: CompilePolicy;
|
|
41
|
-
/**
|
|
42
|
-
* alpha.68 / Release A (delegation-fanout-accelerator §5.0, R0 linkage) —
|
|
43
|
-
* transport for the fan-out parent handle. Threaded from
|
|
44
|
-
* `CallOptions.parentHandle` on the call() path (and settable directly on the
|
|
45
|
-
* public compile() path). Release A does NOT route on it — it only labels the
|
|
46
|
-
* outcome row (fanout_role / trace_id / parent_handle) at record-registration
|
|
47
|
-
* time. `registerCompile` reads it to derive the linkage. Absent ⇒ root call.
|
|
48
|
-
*/
|
|
49
|
-
parentHandle?: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
11
|
/**
|
|
53
12
|
* execute() — fire a CompiledRequest at the right provider, normalize the
|
|
54
13
|
* response shape across providers.
|
|
@@ -666,6 +625,10 @@ interface OutcomePayload {
|
|
|
666
625
|
provider?: string;
|
|
667
626
|
shape_key?: string;
|
|
668
627
|
learning_key?: string;
|
|
628
|
+
/** alpha.92 (migration 067) — route identity: 'direct' | 'openrouter'. */
|
|
629
|
+
route?: string;
|
|
630
|
+
/** alpha.92 — gateway-reported serving host (OpenRouter `provider` field). */
|
|
631
|
+
route_host?: string;
|
|
669
632
|
mutations_applied: string[];
|
|
670
633
|
tokens_in: number;
|
|
671
634
|
tokens_out: number;
|
|
@@ -862,6 +825,7 @@ declare function buildShadowProbeRow(input: ShadowProbeRecordInput): {
|
|
|
862
825
|
latency_candidate_ms: number | null;
|
|
863
826
|
prompt_fidelity: number;
|
|
864
827
|
replay_source: 'inline-full-ir';
|
|
828
|
+
evidence_basis: 'controlled';
|
|
865
829
|
outcome: 'completed' | 'aborted_latency_budget' | 'skipped_slow_tier_sync' | 'candidate_error';
|
|
866
830
|
error_class: string | null;
|
|
867
831
|
};
|
|
@@ -1270,7 +1234,7 @@ declare function runStrategyEvalWithAttribution(opts: Omit<GoldenEvalOptions, 'a
|
|
|
1270
1234
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
1271
1235
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
1272
1236
|
*/
|
|
1273
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
1237
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.93";
|
|
1274
1238
|
|
|
1275
1239
|
/**
|
|
1276
1240
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2668,7 +2632,7 @@ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxis
|
|
|
2668
2632
|
* no execute() handler, no env-var convention). Narrowing here keeps the
|
|
2669
2633
|
* reachability check structurally honest.
|
|
2670
2634
|
*/
|
|
2671
|
-
type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot';
|
|
2635
|
+
type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'openrouter';
|
|
2672
2636
|
/**
|
|
2673
2637
|
* Per-provider env var names kgauto recognizes. Order doesn't matter —
|
|
2674
2638
|
* first-present wins. Multiple names per provider supported because Google
|
|
@@ -4091,4 +4055,4 @@ declare function planDecomposition(args: PlanDecompositionArgs): DecompositionPl
|
|
|
4091
4055
|
*/
|
|
4092
4056
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
4093
4057
|
|
|
4094
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ALT_BLIND_TOKEN_BUDGET_BREACH, ALT_STRATEGY_IDS, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryEvidenceWindow, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BLOCKED_MODEL_FAMILY_SIBLING_SERVED_CODE, BLOCKED_MODEL_NOT_IN_ROSTER_CODE, BRAIN_READ_ENV_NAMES, BURST_SPAN_MS, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, COACH_CFG, COST_RANKING_REFERENCE_SHAPE, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result,
|
|
4058
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ALT_BLIND_TOKEN_BUDGET_BREACH, ALT_STRATEGY_IDS, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryEvidenceWindow, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BLOCKED_MODEL_FAMILY_SIBLING_SERVED_CODE, BLOCKED_MODEL_NOT_IN_ROSTER_CODE, BRAIN_READ_ENV_NAMES, BURST_SPAN_MS, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, COACH_CFG, COST_RANKING_REFERENCE_SHAPE, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type CreateDelegateOpts, DECOMPOSITION_TEMPLATES, DECOMPOSITION_TEMPLATES_VERSION, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_JUDGE_MODEL, DEFAULT_MEASURED_FAILURE_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, DELEGATE_TOOL_DEFINITION, DISCIPLINE_GATES_V1_ALT_BLIND_HEADER, DISCIPLINE_GATES_V1_ALT_HEADER, type DecompositionPlan, type DecompositionStep, type DecompositionTemplate, type DelegateHandle, type DelegateRefusalReason, type DelegateResult, type DelegateToolArgs, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type ExecutorCandidate, type FallbackPosture, FallbackReason, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetApplicablePromotionOpts, type GetDefaultFallbackChainOpts, type GetMeasuredFailureOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalAxis, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenEvalStrategyId, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_FAILURE_CFG, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type MeasuredFailureRuntime, type MeasuredFailureVerdict, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, OutputMode, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PlannedStep, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, type PromotionRow, type PromotionsRuntime, PromptIR, Provider, ProviderOverrides, type ProviderReachability, ROLLBACK_SUPPRESSION_WINDOW_DAYS, RULE_DISCIPLINE_GATES_V1, RULE_DISCIPLINE_GATES_V1_STRUCTURED, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, STRATEGY_AUTHORSHIP_INDEPENDENT, STRATEGY_AUTHORSHIP_LIMITATION, SectionRewrite, type ShadowProbeRecordInput, type StrategyAttribution, type StrategyAttributionResult, type StrategyOutcome, type SupportedProvider, type SurfaceFailureRow, type SurfaceStats, SystemModelMessage, TRANSLATOR_FLOOR, _testResetMeasuredFailure, _testResetOutcomeSourceWarning, _testResetPromotions, _testWaitForMeasuredFailureRefresh, _testWaitForPromotionsRefresh, altBlindGatesBlockFor, altGatesBlockFor, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, awaitMeasuredFailureReady, awaitPromotionsReady, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, burstCaveat, call, chainProviderSpread, classifyEvidenceWindow, classifyStrategyOutcome, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configureMeasuredFailureBrain, configurePromotionsBrain, countTokens, createDelegate, deriveFamilyFromModelId, deriveOwnership, estimateChainCostUsd, estimateModelCostUsd, execute, findBetterFit, flushBrainDeadLetter, formatEvidenceSpan, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getMeasuredFailureVerdict, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecentRollback, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isAltStrategy, isAutoPromoteEnabledFromEnv, isBrainQueryActiveFor, isBrainSync, isDelegateEnabledFromEnv, isExclusionFindingsBrainActive, isMeasuredFailureBrainActive, isMeasuredFailureGateEnabledFromEnv, isModelReachable, isPromotionsBrainActive, isProviderReachable, judgeMeasuredFailure, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, mapMeasuredFailureRows, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, planDecomposition, prefetchMeasuredFailure, prefetchPromotions, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolveOutcomeSource, resolvePricingAt, resolveProviderKey, rowToAdvisory, rubricFor, runAdvisor, runGoldenEval, runStrategyEvalWithAttribution, setTokenizer, wilsonLowerBound, withAltBlindDisciplineContract, withAltDisciplineContract, withDisciplineContract };
|
package/dist/index.js
CHANGED
|
@@ -2977,6 +2977,9 @@ function hashShape(s) {
|
|
|
2977
2977
|
function learningKey(archetype, model, shape) {
|
|
2978
2978
|
return `${DIALECT_VERSION}::${archetype}::${model}::${hashShape(shape)}`;
|
|
2979
2979
|
}
|
|
2980
|
+
function routeScopedModel(model, route) {
|
|
2981
|
+
return route === "openrouter" ? `${model}@openrouter` : model;
|
|
2982
|
+
}
|
|
2980
2983
|
|
|
2981
2984
|
// src/passes.ts
|
|
2982
2985
|
function passSlice(ir) {
|
|
@@ -3634,7 +3637,26 @@ function passApplyConventions(ir, profile) {
|
|
|
3634
3637
|
}
|
|
3635
3638
|
|
|
3636
3639
|
// src/lower.ts
|
|
3640
|
+
var OPENROUTER_VENDOR_SLUG = {
|
|
3641
|
+
anthropic: "anthropic",
|
|
3642
|
+
google: "google",
|
|
3643
|
+
openai: "openai",
|
|
3644
|
+
deepseek: "deepseek",
|
|
3645
|
+
zai: "z-ai",
|
|
3646
|
+
moonshot: "moonshotai"
|
|
3647
|
+
};
|
|
3648
|
+
var OPENROUTER_ID_OVERRIDES = Object.freeze({});
|
|
3649
|
+
function openRouterModelId(profile) {
|
|
3650
|
+
const override = OPENROUTER_ID_OVERRIDES[profile.id];
|
|
3651
|
+
if (override) return override;
|
|
3652
|
+
const slug = OPENROUTER_VENDOR_SLUG[profile.provider];
|
|
3653
|
+
if (!slug) throw new Error(`No OpenRouter vendor slug for provider ${profile.provider} (model ${profile.id})`);
|
|
3654
|
+
return `${slug}/${profile.id}`;
|
|
3655
|
+
}
|
|
3637
3656
|
function lower(ir, profile, hints = {}) {
|
|
3657
|
+
if (hints.route === "openrouter") {
|
|
3658
|
+
return lowerOpenRouter(ir, profile);
|
|
3659
|
+
}
|
|
3638
3660
|
switch (profile.provider) {
|
|
3639
3661
|
case "anthropic":
|
|
3640
3662
|
return lowerAnthropic(ir, profile, hints);
|
|
@@ -3987,6 +4009,23 @@ function lowerZai(ir, profile, hints) {
|
|
|
3987
4009
|
}
|
|
3988
4010
|
};
|
|
3989
4011
|
}
|
|
4012
|
+
function lowerOpenRouter(ir, profile) {
|
|
4013
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
4014
|
+
return {
|
|
4015
|
+
request: {
|
|
4016
|
+
provider: "openrouter",
|
|
4017
|
+
model: openRouterModelId(profile),
|
|
4018
|
+
messages: parts.messages,
|
|
4019
|
+
tools: parts.tools,
|
|
4020
|
+
response_format: parts.response_format
|
|
4021
|
+
},
|
|
4022
|
+
diagnostics: {
|
|
4023
|
+
cacheableTokens: 0,
|
|
4024
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
4025
|
+
estimatedCacheSavingsUsd: 0
|
|
4026
|
+
}
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
3990
4029
|
function lowerMoonshot(ir, profile) {
|
|
3991
4030
|
const parts = buildOpenAICompatibleParts(ir);
|
|
3992
4031
|
return {
|
|
@@ -4088,7 +4127,8 @@ var SUPPORTED_PROVIDERS = Object.freeze([
|
|
|
4088
4127
|
"openai",
|
|
4089
4128
|
"deepseek",
|
|
4090
4129
|
"zai",
|
|
4091
|
-
"moonshot"
|
|
4130
|
+
"moonshot",
|
|
4131
|
+
"openrouter"
|
|
4092
4132
|
]);
|
|
4093
4133
|
function isSupportedProvider(p) {
|
|
4094
4134
|
return SUPPORTED_PROVIDERS.includes(p);
|
|
@@ -4109,7 +4149,11 @@ var PROVIDER_ENV_KEYS = Object.freeze({
|
|
|
4109
4149
|
// alpha.65 — Moonshot AI (Kimi family). MOONSHOT_API_KEY is canonical
|
|
4110
4150
|
// (api.moonshot.ai); KIMI_API_KEY covers the platform.kimi.ai rebrand
|
|
4111
4151
|
// surface so consumers keyed under either name resolve.
|
|
4112
|
-
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"])
|
|
4152
|
+
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"]),
|
|
4153
|
+
// alpha.92 — the OpenRouter gateway route (execute-leg contract). This is
|
|
4154
|
+
// a ROUTE key, not a vendor key: it never makes a vendor "reachable" for
|
|
4155
|
+
// chain composition — only explicit `route: 'openrouter'` calls use it.
|
|
4156
|
+
openrouter: Object.freeze(["OPENROUTER_API_KEY"])
|
|
4113
4157
|
});
|
|
4114
4158
|
function defaultEnv() {
|
|
4115
4159
|
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
@@ -6187,12 +6231,13 @@ function compile(ir, opts = {}) {
|
|
|
6187
6231
|
const lowered = lower(workingIR, profile, {
|
|
6188
6232
|
forceThinkingZero: cliffs.value.loweringHints.forceThinkingZero,
|
|
6189
6233
|
forceTerseOutput: cliffs.value.loweringHints.forceTerseOutput,
|
|
6190
|
-
wireOverrides
|
|
6234
|
+
wireOverrides,
|
|
6235
|
+
route: opts.route
|
|
6191
6236
|
});
|
|
6192
6237
|
validateFinalFit(workingIR, profile, inputTokens);
|
|
6193
6238
|
const handle = makeHandle();
|
|
6194
6239
|
const finalShape = computeShape(workingIR, inputTokens);
|
|
6195
|
-
const _learningKey = learningKey(ir.intent.archetype, profile.id, finalShape);
|
|
6240
|
+
const _learningKey = learningKey(ir.intent.archetype, routeScopedModel(profile.id, opts.route), finalShape);
|
|
6196
6241
|
const historyCacheMarkIndex = computeHistoryCacheMarkIndex(workingIR);
|
|
6197
6242
|
const systemMessages = buildSystemMessages(workingIR, profile.provider);
|
|
6198
6243
|
const systemCacheMarkIndex = lastCacheableSystemIndex(systemMessages);
|
|
@@ -6419,7 +6464,7 @@ function validateFinalFit(ir, profile, tokens) {
|
|
|
6419
6464
|
}
|
|
6420
6465
|
|
|
6421
6466
|
// src/version.ts
|
|
6422
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
6467
|
+
var LIBRARY_VERSION = "2.0.0-alpha.93";
|
|
6423
6468
|
|
|
6424
6469
|
// src/pricing-brain.ts
|
|
6425
6470
|
function isPricingRow(x) {
|
|
@@ -6694,7 +6739,7 @@ async function flushBrainDeadLetter() {
|
|
|
6694
6739
|
}
|
|
6695
6740
|
var compileRegistry = /* @__PURE__ */ new Map();
|
|
6696
6741
|
var REGISTRY_MAX_ENTRIES = 1e4;
|
|
6697
|
-
function registerCompile(appId, archetype, ir, result, parentHandle) {
|
|
6742
|
+
function registerCompile(appId, archetype, ir, result, parentHandle, route) {
|
|
6698
6743
|
if (compileRegistry.size >= REGISTRY_MAX_ENTRIES) {
|
|
6699
6744
|
const cutoff = Math.floor(REGISTRY_MAX_ENTRIES * 0.25);
|
|
6700
6745
|
let evicted = 0;
|
|
@@ -6726,7 +6771,10 @@ function registerCompile(appId, archetype, ir, result, parentHandle) {
|
|
|
6726
6771
|
model: result.target,
|
|
6727
6772
|
provider: result.provider,
|
|
6728
6773
|
shapeKey,
|
|
6729
|
-
|
|
6774
|
+
route: route ?? "direct",
|
|
6775
|
+
// alpha.92 — route-scoped for non-direct routes: the same model id on a
|
|
6776
|
+
// gateway is a different serving stack (Venice/StreamLake, 2026-08-26).
|
|
6777
|
+
learningKey: learningKey(archetype, routeScopedModel(result.target, route), shape),
|
|
6730
6778
|
estimatedTokensIn: tokens,
|
|
6731
6779
|
mutationsApplied: result.mutationsApplied.map((m) => m.id),
|
|
6732
6780
|
// alpha.30: cache the in-memory advisories so record() can auto-persist
|
|
@@ -6920,6 +6968,11 @@ function buildPayload(input, reg) {
|
|
|
6920
6968
|
provider: reg?.provider,
|
|
6921
6969
|
shape_key: reg?.shapeKey,
|
|
6922
6970
|
learning_key: reg?.learningKey,
|
|
6971
|
+
// alpha.92 (migration 067) — route identity on every row. Input wins
|
|
6972
|
+
// (a manual record() replaying through a gateway states its own route);
|
|
6973
|
+
// registry fills the call() path; column default covers legacy writers.
|
|
6974
|
+
route: input.route ?? reg?.route ?? "direct",
|
|
6975
|
+
route_host: input.routeHost,
|
|
6923
6976
|
mutations_applied: mutationsApplied,
|
|
6924
6977
|
tokens_in: input.tokensIn,
|
|
6925
6978
|
tokens_out: input.tokensOut,
|
|
@@ -7110,6 +7163,12 @@ function buildShadowProbeRow(input) {
|
|
|
7110
7163
|
// prompt-fidelity guard never fires on these rows.
|
|
7111
7164
|
prompt_fidelity: 1,
|
|
7112
7165
|
replay_source: "inline-full-ir",
|
|
7166
|
+
// alpha.93 (migration 068) — shadow probes replay the SAME full IR to
|
|
7167
|
+
// the candidate: controlled by construction. Written at write time, per
|
|
7168
|
+
// the mig-057 lesson (a marker inferred later can disagree with itself).
|
|
7169
|
+
// The column default is 'observational' precisely so only writers that
|
|
7170
|
+
// KNOW they are controlled say so.
|
|
7171
|
+
evidence_basis: "controlled",
|
|
7113
7172
|
// alpha — migration 029. 'completed' is the default completed-probe shape;
|
|
7114
7173
|
// diagnostic rows (aborted/skipped/errored) pass the explicit class.
|
|
7115
7174
|
outcome: input.outcome ?? "completed",
|
|
@@ -7714,6 +7773,7 @@ var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
|
|
|
7714
7773
|
var DEEPSEEK_URL = "https://api.deepseek.com/chat/completions";
|
|
7715
7774
|
var ZAI_URL = "https://api.z.ai/api/paas/v4/chat/completions";
|
|
7716
7775
|
var MOONSHOT_URL = "https://api.moonshot.ai/v1/chat/completions";
|
|
7776
|
+
var OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions";
|
|
7717
7777
|
async function execute(request, opts = {}) {
|
|
7718
7778
|
const merged = applyOverrides(request, opts.providerOverrides);
|
|
7719
7779
|
switch (merged.provider) {
|
|
@@ -7737,6 +7797,12 @@ async function execute(request, opts = {}) {
|
|
|
7737
7797
|
opts,
|
|
7738
7798
|
{ provider: "moonshot", url: MOONSHOT_URL, missingKeyMessage: "MOONSHOT_API_KEY missing" }
|
|
7739
7799
|
);
|
|
7800
|
+
case "openrouter":
|
|
7801
|
+
return executeOpenAICompatible(
|
|
7802
|
+
merged,
|
|
7803
|
+
opts,
|
|
7804
|
+
{ provider: "openrouter", url: OPENROUTER_URL, missingKeyMessage: "OPENROUTER_API_KEY missing" }
|
|
7805
|
+
);
|
|
7740
7806
|
default: {
|
|
7741
7807
|
const _exhaustive = merged;
|
|
7742
7808
|
throw new Error(`execute(): no executor for provider: ${JSON.stringify(_exhaustive)}`);
|
|
@@ -7936,6 +8002,7 @@ function normalizeOpenAILike(raw) {
|
|
|
7936
8002
|
const r = raw;
|
|
7937
8003
|
const choice = r.choices?.[0];
|
|
7938
8004
|
const text = choice?.message?.content ?? "";
|
|
8005
|
+
const routeHost = typeof raw?.provider === "string" ? raw.provider : void 0;
|
|
7939
8006
|
const toolCalls = (choice?.message?.tool_calls ?? []).filter((tc) => tc.function?.name).map((tc, i) => ({
|
|
7940
8007
|
id: tc.id ?? `tc-${i}`,
|
|
7941
8008
|
name: tc.function.name,
|
|
@@ -7948,7 +8015,7 @@ function normalizeOpenAILike(raw) {
|
|
|
7948
8015
|
total: u.total_tokens ?? (u.prompt_tokens ?? 0) + (u.completion_tokens ?? 0),
|
|
7949
8016
|
cached: u.prompt_tokens_details?.cached_tokens
|
|
7950
8017
|
};
|
|
7951
|
-
return { text, structuredOutput: null, toolCalls, tokens, finishReason: choice?.finish_reason, raw };
|
|
8018
|
+
return { text, structuredOutput: null, toolCalls, tokens, finishReason: choice?.finish_reason, routeHost, raw };
|
|
7952
8019
|
}
|
|
7953
8020
|
function applyOverrides(request, overrides) {
|
|
7954
8021
|
if (!overrides) return request;
|
|
@@ -8387,6 +8454,7 @@ async function call(ir, opts = {}) {
|
|
|
8387
8454
|
handle: initial.handle,
|
|
8388
8455
|
source: opts.source,
|
|
8389
8456
|
endUserId: opts.endUserId,
|
|
8457
|
+
route: opts.route,
|
|
8390
8458
|
tokensIn: 0,
|
|
8391
8459
|
tokensOut: 0,
|
|
8392
8460
|
latencyMs: latencyMs2,
|
|
@@ -8441,6 +8509,7 @@ async function call(ir, opts = {}) {
|
|
|
8441
8509
|
handle: initial.handle,
|
|
8442
8510
|
source: opts.source,
|
|
8443
8511
|
endUserId: opts.endUserId,
|
|
8512
|
+
route: opts.route,
|
|
8444
8513
|
tokensIn: 0,
|
|
8445
8514
|
tokensOut: 0,
|
|
8446
8515
|
latencyMs: latencyMs2,
|
|
@@ -8584,6 +8653,11 @@ async function call(ir, opts = {}) {
|
|
|
8584
8653
|
handle: initial.handle,
|
|
8585
8654
|
source: opts.source,
|
|
8586
8655
|
endUserId: opts.endUserId,
|
|
8656
|
+
// alpha.92 — route identity on the row (registry also carries it;
|
|
8657
|
+
// input wins in buildPayload, so state it explicitly here with the
|
|
8658
|
+
// host the gateway reported for the WINNING attempt).
|
|
8659
|
+
route: opts.route,
|
|
8660
|
+
routeHost: validated.response.routeHost,
|
|
8587
8661
|
tokensIn: validated.response.tokens.input,
|
|
8588
8662
|
tokensOut: validated.response.tokens.output,
|
|
8589
8663
|
latencyMs: latencyMs2,
|
|
@@ -8664,6 +8738,12 @@ async function call(ir, opts = {}) {
|
|
|
8664
8738
|
provider: activeCompile.provider,
|
|
8665
8739
|
response: validated.response,
|
|
8666
8740
|
latencyMs: latencyMs2,
|
|
8741
|
+
// alpha.92 — route identity + the served profile's cliffs flagged
|
|
8742
|
+
// route-unverified on a non-direct route (guards still fired; their
|
|
8743
|
+
// evidence is vendor-route evidence — see the execute-leg contract).
|
|
8744
|
+
route: opts.route ?? "direct",
|
|
8745
|
+
routeHost: validated.response.routeHost,
|
|
8746
|
+
routeUnverifiedCliffs: opts.route === "openrouter" ? (tryGetProfile(targetModel)?.cliffs ?? []).map((c) => c.metric) : void 0,
|
|
8667
8747
|
mutationsApplied: activeCompile.mutationsApplied,
|
|
8668
8748
|
attempts,
|
|
8669
8749
|
servedBy: targetModel,
|
|
@@ -8708,6 +8788,7 @@ async function call(ir, opts = {}) {
|
|
|
8708
8788
|
handle: initial.handle,
|
|
8709
8789
|
source: opts.source,
|
|
8710
8790
|
endUserId: opts.endUserId,
|
|
8791
|
+
route: opts.route,
|
|
8711
8792
|
tokensIn: lastErr?.tokens?.input ?? 0,
|
|
8712
8793
|
tokensOut: lastErr?.tokens?.output ?? 0,
|
|
8713
8794
|
latencyMs,
|
|
@@ -8751,9 +8832,12 @@ function compileAndRegister(ir, opts) {
|
|
|
8751
8832
|
toolRelevanceThreshold: opts.toolRelevanceThreshold,
|
|
8752
8833
|
compressHistoryAfter: opts.compressHistoryAfter,
|
|
8753
8834
|
// alpha.68 / Release A — carry the fan-out parent handle through to compile.
|
|
8754
|
-
parentHandle: opts.parentHandle
|
|
8835
|
+
parentHandle: opts.parentHandle,
|
|
8836
|
+
// alpha.92 — gateway route (execute-leg contract): changes the wire +
|
|
8837
|
+
// learning-key encoding, never the pass pipeline.
|
|
8838
|
+
route: opts.route
|
|
8755
8839
|
});
|
|
8756
|
-
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts.parentHandle);
|
|
8840
|
+
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts.parentHandle, opts.route);
|
|
8757
8841
|
return result;
|
|
8758
8842
|
}
|
|
8759
8843
|
function extractPromptPreview(ir) {
|
|
@@ -11192,7 +11276,7 @@ function planDecomposition(args) {
|
|
|
11192
11276
|
// src/index.ts
|
|
11193
11277
|
function compile2(ir, opts) {
|
|
11194
11278
|
const result = compile(ir, opts);
|
|
11195
|
-
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts?.parentHandle);
|
|
11279
|
+
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts?.parentHandle, opts?.route);
|
|
11196
11280
|
return result;
|
|
11197
11281
|
}
|
|
11198
11282
|
// Annotate the CommonJS export names for ESM import in node:
|