@warmdrift/kgauto-compiler 2.0.0-alpha.80 → 2.0.0-alpha.81
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-CIBHU67M.mjs → chunk-OZNAGO4U.mjs} +18 -2
- package/dist/{chunk-PMTT4H5W.mjs → chunk-XPD4I3Q5.mjs} +8 -1
- package/dist/glassbox-routes/index.js +7 -1
- package/dist/glassbox-routes/index.mjs +1 -1
- package/dist/index.d.mts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +38 -5
- package/dist/index.mjs +17 -3
- package/dist/key-health.d.mts +36 -1
- package/dist/key-health.d.ts +36 -1
- package/dist/key-health.js +23 -4
- package/dist/key-health.mjs +9 -3
- package/package.json +1 -1
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
2
|
+
var LIBRARY_VERSION = "2.0.0-alpha.81";
|
|
3
3
|
|
|
4
4
|
// src/key-health.ts
|
|
5
5
|
var JSON_HEADERS = { "Content-Type": "application/json" };
|
|
6
|
+
var KEY_FINGERPRINT_DOMAIN = "kgauto-key-fingerprint-v1:";
|
|
7
|
+
var KEY_FINGERPRINT_LENGTH = 12;
|
|
8
|
+
async function keyFingerprint(key) {
|
|
9
|
+
const trimmed = key?.trim();
|
|
10
|
+
if (!trimmed) return void 0;
|
|
11
|
+
const subtle = globalThis.crypto?.subtle;
|
|
12
|
+
if (!subtle) return void 0;
|
|
13
|
+
const bytes = new TextEncoder().encode(KEY_FINGERPRINT_DOMAIN + trimmed);
|
|
14
|
+
const digest = await subtle.digest("SHA-256", bytes);
|
|
15
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, KEY_FINGERPRINT_LENGTH);
|
|
16
|
+
}
|
|
6
17
|
function jsonResponse(status, body) {
|
|
7
18
|
return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
|
|
8
19
|
}
|
|
@@ -104,11 +115,13 @@ function createKeyHealthRoute(config) {
|
|
|
104
115
|
detail: "key_absent"
|
|
105
116
|
};
|
|
106
117
|
}
|
|
118
|
+
const fingerprint = await keyFingerprint(key);
|
|
107
119
|
const base = {
|
|
108
120
|
provider: spec.provider,
|
|
109
121
|
env: envName,
|
|
110
122
|
present: true,
|
|
111
|
-
valid: null
|
|
123
|
+
valid: null,
|
|
124
|
+
...fingerprint ? { key_fingerprint: fingerprint } : {}
|
|
112
125
|
};
|
|
113
126
|
const { url, headers } = spec.buildRequest(key);
|
|
114
127
|
const started = Date.now();
|
|
@@ -199,5 +212,8 @@ function createKeyHealthRoute(config) {
|
|
|
199
212
|
|
|
200
213
|
export {
|
|
201
214
|
LIBRARY_VERSION,
|
|
215
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
216
|
+
KEY_FINGERPRINT_LENGTH,
|
|
217
|
+
keyFingerprint,
|
|
202
218
|
createKeyHealthRoute
|
|
203
219
|
};
|
|
@@ -412,9 +412,15 @@ var COST_RANKING_REFERENCE_SHAPE = {
|
|
|
412
412
|
inputTokens: 4e3,
|
|
413
413
|
outputTokens: 250
|
|
414
414
|
};
|
|
415
|
-
function
|
|
415
|
+
function estimateModelCostUsd(profile, shape = COST_RANKING_REFERENCE_SHAPE) {
|
|
416
|
+
if (!profile || typeof profile !== "object" || Array.isArray(profile) || typeof profile.costInputPer1m !== "number" || typeof profile.costOutputPer1m !== "number") {
|
|
417
|
+
throw new TypeError(
|
|
418
|
+
`estimateModelCostUsd: expected a single ModelProfile, got ${Array.isArray(profile) ? "an array (a chain? map over it)" : typeof profile}. For a chain: chain.map((id) => estimateModelCostUsd(getProfile(id))).`
|
|
419
|
+
);
|
|
420
|
+
}
|
|
416
421
|
return shape.inputTokens / 1e6 * profile.costInputPer1m + shape.outputTokens / 1e6 * profile.costOutputPer1m;
|
|
417
422
|
}
|
|
423
|
+
var estimateChainCostUsd = estimateModelCostUsd;
|
|
418
424
|
function buildCostOrderedChain(archetype) {
|
|
419
425
|
return allProfiles().filter((p) => p.status === "current").filter(
|
|
420
426
|
(p) => getArchetypePerfScore(p.id, archetype).score >= ARCHETYPE_FLOOR_DEFAULT
|
|
@@ -811,6 +817,7 @@ export {
|
|
|
811
817
|
isSameModelRetryEnabledFromEnv,
|
|
812
818
|
loadChainsFromBrain,
|
|
813
819
|
COST_RANKING_REFERENCE_SHAPE,
|
|
820
|
+
estimateModelCostUsd,
|
|
814
821
|
estimateChainCostUsd,
|
|
815
822
|
chainProviderSpread,
|
|
816
823
|
getDefaultFallbackChain,
|
|
@@ -1956,9 +1956,15 @@ var COST_RANKING_REFERENCE_SHAPE = {
|
|
|
1956
1956
|
inputTokens: 4e3,
|
|
1957
1957
|
outputTokens: 250
|
|
1958
1958
|
};
|
|
1959
|
-
function
|
|
1959
|
+
function estimateModelCostUsd(profile, shape = COST_RANKING_REFERENCE_SHAPE) {
|
|
1960
|
+
if (!profile || typeof profile !== "object" || Array.isArray(profile) || typeof profile.costInputPer1m !== "number" || typeof profile.costOutputPer1m !== "number") {
|
|
1961
|
+
throw new TypeError(
|
|
1962
|
+
`estimateModelCostUsd: expected a single ModelProfile, got ${Array.isArray(profile) ? "an array (a chain? map over it)" : typeof profile}. For a chain: chain.map((id) => estimateModelCostUsd(getProfile(id))).`
|
|
1963
|
+
);
|
|
1964
|
+
}
|
|
1960
1965
|
return shape.inputTokens / 1e6 * profile.costInputPer1m + shape.outputTokens / 1e6 * profile.costOutputPer1m;
|
|
1961
1966
|
}
|
|
1967
|
+
var estimateChainCostUsd = estimateModelCostUsd;
|
|
1962
1968
|
function buildCostOrderedChain(archetype) {
|
|
1963
1969
|
return allProfiles().filter((p) => p.status === "current").filter(
|
|
1964
1970
|
(p) => getArchetypePerfScore(p.id, archetype).score >= ARCHETYPE_FLOOR_DEFAULT
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithG
|
|
|
3
3
|
import { ModelProfile, ArchetypeConvention } from './profiles.mjs';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, latencyTierOf, profilesByProvider, tryGetProfile } from './profiles.mjs';
|
|
5
5
|
export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.mjs';
|
|
6
|
-
export { KeyHealthConfig, KeyHealthProvider, KeyHealthResponseBody, KeyHealthResult, KeyHealthRoute, createKeyHealthRoute } from './key-health.mjs';
|
|
6
|
+
export { KEY_FINGERPRINT_DOMAIN, KEY_FINGERPRINT_LENGTH, KeyHealthConfig, KeyHealthProvider, KeyHealthResponseBody, KeyHealthResult, KeyHealthRoute, createKeyHealthRoute, keyFingerprint } from './key-health.mjs';
|
|
7
7
|
import { IntentArchetypeName, OutputMode } from './dialect.mjs';
|
|
8
8
|
export { ALL_ARCHETYPES, ContextBucket, DIALECT_VERSION, HistoryDepth, INTENT_ARCHETYPES, ShapeSignature, ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey } from './dialect.mjs';
|
|
9
9
|
|
|
@@ -1146,7 +1146,7 @@ declare function runStrategyEvalWithAttribution(opts: Omit<GoldenEvalOptions, 'a
|
|
|
1146
1146
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
1147
1147
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
1148
1148
|
*/
|
|
1149
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
1149
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.81";
|
|
1150
1150
|
|
|
1151
1151
|
/**
|
|
1152
1152
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2540,10 +2540,16 @@ declare const COST_RANKING_REFERENCE_SHAPE: {
|
|
|
2540
2540
|
* consumer-side code share ONE derivation of "what does this model cost
|
|
2541
2541
|
* here" — two independent derivations of one concept will drift (s75).
|
|
2542
2542
|
*/
|
|
2543
|
-
declare function
|
|
2543
|
+
declare function estimateModelCostUsd(profile: ModelProfile, shape?: {
|
|
2544
2544
|
inputTokens: number;
|
|
2545
2545
|
outputTokens: number;
|
|
2546
2546
|
}): number;
|
|
2547
|
+
/**
|
|
2548
|
+
* @deprecated alpha.81 — renamed to {@link estimateModelCostUsd}; it takes a
|
|
2549
|
+
* single MODEL, not a chain. Preserved because alpha.80 shipped this name and
|
|
2550
|
+
* a consumer adopted it within hours. Identical behavior.
|
|
2551
|
+
*/
|
|
2552
|
+
declare const estimateChainCostUsd: typeof estimateModelCostUsd;
|
|
2547
2553
|
/**
|
|
2548
2554
|
* How many distinct providers a chain spans. `1` means every fallback shares
|
|
2549
2555
|
* one provider's fate — the chain buys you retries, not outage independence.
|
|
@@ -3754,4 +3760,4 @@ declare function planDecomposition(args: PlanDecompositionArgs): DecompositionPl
|
|
|
3754
3760
|
*/
|
|
3755
3761
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
3756
3762
|
|
|
3757
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, 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, BRAIN_READ_ENV_NAMES, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, COACH_CFG, COST_RANKING_REFERENCE_SHAPE, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type CreateDelegateOpts, DECOMPOSITION_TEMPLATES, DECOMPOSITION_TEMPLATES_VERSION, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_MEASURED_FAILURE_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, DELEGATE_TOOL_DEFINITION, 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_LIMITATION, SectionRewrite, type ShadowProbeRecordInput, type StrategyAttribution, type StrategyAttributionResult, type StrategyOutcome, type SupportedProvider, type SurfaceFailureRow, type SurfaceStats, SystemModelMessage, TRANSLATOR_FLOOR, _testResetMeasuredFailure, _testResetPromotions, _testWaitForMeasuredFailureRefresh, _testWaitForPromotionsRefresh, altGatesBlockFor, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, awaitMeasuredFailureReady, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, chainProviderSpread, classifyStrategyOutcome, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configureMeasuredFailureBrain, configurePromotionsBrain, countTokens, createDelegate, deriveFamilyFromModelId, deriveOwnership, estimateChainCostUsd, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getMeasuredFailureVerdict, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecentRollback, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, 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, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, runStrategyEvalWithAttribution, setTokenizer, wilsonLowerBound, withAltDisciplineContract, withDisciplineContract };
|
|
3763
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, 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, BRAIN_READ_ENV_NAMES, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, COACH_CFG, COST_RANKING_REFERENCE_SHAPE, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type CreateDelegateOpts, DECOMPOSITION_TEMPLATES, DECOMPOSITION_TEMPLATES_VERSION, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_MEASURED_FAILURE_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, DELEGATE_TOOL_DEFINITION, 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_LIMITATION, SectionRewrite, type ShadowProbeRecordInput, type StrategyAttribution, type StrategyAttributionResult, type StrategyOutcome, type SupportedProvider, type SurfaceFailureRow, type SurfaceStats, SystemModelMessage, TRANSLATOR_FLOOR, _testResetMeasuredFailure, _testResetPromotions, _testWaitForMeasuredFailureRefresh, _testWaitForPromotionsRefresh, altGatesBlockFor, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, awaitMeasuredFailureReady, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, chainProviderSpread, classifyStrategyOutcome, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configureMeasuredFailureBrain, configurePromotionsBrain, countTokens, createDelegate, deriveFamilyFromModelId, deriveOwnership, estimateChainCostUsd, estimateModelCostUsd, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getMeasuredFailureVerdict, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecentRollback, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, 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, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, runStrategyEvalWithAttribution, setTokenizer, wilsonLowerBound, withAltDisciplineContract, withDisciplineContract };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithG
|
|
|
3
3
|
import { ModelProfile, ArchetypeConvention } from './profiles.js';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, latencyTierOf, profilesByProvider, tryGetProfile } from './profiles.js';
|
|
5
5
|
export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.js';
|
|
6
|
-
export { KeyHealthConfig, KeyHealthProvider, KeyHealthResponseBody, KeyHealthResult, KeyHealthRoute, createKeyHealthRoute } from './key-health.js';
|
|
6
|
+
export { KEY_FINGERPRINT_DOMAIN, KEY_FINGERPRINT_LENGTH, KeyHealthConfig, KeyHealthProvider, KeyHealthResponseBody, KeyHealthResult, KeyHealthRoute, createKeyHealthRoute, keyFingerprint } from './key-health.js';
|
|
7
7
|
import { IntentArchetypeName, OutputMode } from './dialect.js';
|
|
8
8
|
export { ALL_ARCHETYPES, ContextBucket, DIALECT_VERSION, HistoryDepth, INTENT_ARCHETYPES, ShapeSignature, ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey } from './dialect.js';
|
|
9
9
|
|
|
@@ -1146,7 +1146,7 @@ declare function runStrategyEvalWithAttribution(opts: Omit<GoldenEvalOptions, 'a
|
|
|
1146
1146
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
1147
1147
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
1148
1148
|
*/
|
|
1149
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
1149
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.81";
|
|
1150
1150
|
|
|
1151
1151
|
/**
|
|
1152
1152
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2540,10 +2540,16 @@ declare const COST_RANKING_REFERENCE_SHAPE: {
|
|
|
2540
2540
|
* consumer-side code share ONE derivation of "what does this model cost
|
|
2541
2541
|
* here" — two independent derivations of one concept will drift (s75).
|
|
2542
2542
|
*/
|
|
2543
|
-
declare function
|
|
2543
|
+
declare function estimateModelCostUsd(profile: ModelProfile, shape?: {
|
|
2544
2544
|
inputTokens: number;
|
|
2545
2545
|
outputTokens: number;
|
|
2546
2546
|
}): number;
|
|
2547
|
+
/**
|
|
2548
|
+
* @deprecated alpha.81 — renamed to {@link estimateModelCostUsd}; it takes a
|
|
2549
|
+
* single MODEL, not a chain. Preserved because alpha.80 shipped this name and
|
|
2550
|
+
* a consumer adopted it within hours. Identical behavior.
|
|
2551
|
+
*/
|
|
2552
|
+
declare const estimateChainCostUsd: typeof estimateModelCostUsd;
|
|
2547
2553
|
/**
|
|
2548
2554
|
* How many distinct providers a chain spans. `1` means every fallback shares
|
|
2549
2555
|
* one provider's fate — the chain buys you retries, not outage independence.
|
|
@@ -3754,4 +3760,4 @@ declare function planDecomposition(args: PlanDecompositionArgs): DecompositionPl
|
|
|
3754
3760
|
*/
|
|
3755
3761
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
3756
3762
|
|
|
3757
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, 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, BRAIN_READ_ENV_NAMES, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, COACH_CFG, COST_RANKING_REFERENCE_SHAPE, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type CreateDelegateOpts, DECOMPOSITION_TEMPLATES, DECOMPOSITION_TEMPLATES_VERSION, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_MEASURED_FAILURE_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, DELEGATE_TOOL_DEFINITION, 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_LIMITATION, SectionRewrite, type ShadowProbeRecordInput, type StrategyAttribution, type StrategyAttributionResult, type StrategyOutcome, type SupportedProvider, type SurfaceFailureRow, type SurfaceStats, SystemModelMessage, TRANSLATOR_FLOOR, _testResetMeasuredFailure, _testResetPromotions, _testWaitForMeasuredFailureRefresh, _testWaitForPromotionsRefresh, altGatesBlockFor, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, awaitMeasuredFailureReady, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, chainProviderSpread, classifyStrategyOutcome, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configureMeasuredFailureBrain, configurePromotionsBrain, countTokens, createDelegate, deriveFamilyFromModelId, deriveOwnership, estimateChainCostUsd, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getMeasuredFailureVerdict, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecentRollback, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, 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, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, runStrategyEvalWithAttribution, setTokenizer, wilsonLowerBound, withAltDisciplineContract, withDisciplineContract };
|
|
3763
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, 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, BRAIN_READ_ENV_NAMES, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, COACH_CFG, COST_RANKING_REFERENCE_SHAPE, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type CreateDelegateOpts, DECOMPOSITION_TEMPLATES, DECOMPOSITION_TEMPLATES_VERSION, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_MEASURED_FAILURE_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, DELEGATE_TOOL_DEFINITION, 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_LIMITATION, SectionRewrite, type ShadowProbeRecordInput, type StrategyAttribution, type StrategyAttributionResult, type StrategyOutcome, type SupportedProvider, type SurfaceFailureRow, type SurfaceStats, SystemModelMessage, TRANSLATOR_FLOOR, _testResetMeasuredFailure, _testResetPromotions, _testWaitForMeasuredFailureRefresh, _testWaitForPromotionsRefresh, altGatesBlockFor, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, awaitMeasuredFailureReady, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, chainProviderSpread, classifyStrategyOutcome, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configureMeasuredFailureBrain, configurePromotionsBrain, countTokens, createDelegate, deriveFamilyFromModelId, deriveOwnership, estimateChainCostUsd, estimateModelCostUsd, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getMeasuredFailureVerdict, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecentRollback, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, 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, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, runStrategyEvalWithAttribution, setTokenizer, wilsonLowerBound, withAltDisciplineContract, withDisciplineContract };
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
FamilyResolutionError: () => FamilyResolutionError,
|
|
41
41
|
INTENT_ARCHETYPES: () => INTENT_ARCHETYPES,
|
|
42
42
|
JUDGE_RUBRICS: () => JUDGE_RUBRICS,
|
|
43
|
+
KEY_FINGERPRINT_DOMAIN: () => KEY_FINGERPRINT_DOMAIN,
|
|
44
|
+
KEY_FINGERPRINT_LENGTH: () => KEY_FINGERPRINT_LENGTH,
|
|
43
45
|
LATENCY_TIER_MS: () => LATENCY_TIER_MS,
|
|
44
46
|
LIBRARY_VERSION: () => LIBRARY_VERSION,
|
|
45
47
|
MEASURED_FAILURE_CFG: () => MEASURED_FAILURE_CFG,
|
|
@@ -88,6 +90,7 @@ __export(index_exports, {
|
|
|
88
90
|
deriveFamilyFromModelId: () => deriveFamilyFromModelId,
|
|
89
91
|
deriveOwnership: () => deriveOwnership,
|
|
90
92
|
estimateChainCostUsd: () => estimateChainCostUsd,
|
|
93
|
+
estimateModelCostUsd: () => estimateModelCostUsd,
|
|
91
94
|
execute: () => execute,
|
|
92
95
|
findBetterFit: () => findBetterFit,
|
|
93
96
|
flushBrainDeadLetter: () => flushBrainDeadLetter,
|
|
@@ -124,6 +127,7 @@ __export(index_exports, {
|
|
|
124
127
|
isPromotionsBrainActive: () => isPromotionsBrainActive,
|
|
125
128
|
isProviderReachable: () => isProviderReachable,
|
|
126
129
|
judgeMeasuredFailure: () => judgeMeasuredFailure,
|
|
130
|
+
keyFingerprint: () => keyFingerprint,
|
|
127
131
|
latencyTierOf: () => latencyTierOf,
|
|
128
132
|
learningKey: () => learningKey,
|
|
129
133
|
loadAliasesFromBrain: () => loadAliasesFromBrain,
|
|
@@ -3868,9 +3872,15 @@ var COST_RANKING_REFERENCE_SHAPE = {
|
|
|
3868
3872
|
inputTokens: 4e3,
|
|
3869
3873
|
outputTokens: 250
|
|
3870
3874
|
};
|
|
3871
|
-
function
|
|
3875
|
+
function estimateModelCostUsd(profile, shape = COST_RANKING_REFERENCE_SHAPE) {
|
|
3876
|
+
if (!profile || typeof profile !== "object" || Array.isArray(profile) || typeof profile.costInputPer1m !== "number" || typeof profile.costOutputPer1m !== "number") {
|
|
3877
|
+
throw new TypeError(
|
|
3878
|
+
`estimateModelCostUsd: expected a single ModelProfile, got ${Array.isArray(profile) ? "an array (a chain? map over it)" : typeof profile}. For a chain: chain.map((id) => estimateModelCostUsd(getProfile(id))).`
|
|
3879
|
+
);
|
|
3880
|
+
}
|
|
3872
3881
|
return shape.inputTokens / 1e6 * profile.costInputPer1m + shape.outputTokens / 1e6 * profile.costOutputPer1m;
|
|
3873
3882
|
}
|
|
3883
|
+
var estimateChainCostUsd = estimateModelCostUsd;
|
|
3874
3884
|
function buildCostOrderedChain(archetype) {
|
|
3875
3885
|
return allProfiles().filter((p) => p.status === "current").filter(
|
|
3876
3886
|
(p) => getArchetypePerfScore(p.id, archetype).score >= ARCHETYPE_FLOOR_DEFAULT
|
|
@@ -5834,6 +5844,9 @@ function validateFinalFit(ir, profile, tokens) {
|
|
|
5834
5844
|
}
|
|
5835
5845
|
}
|
|
5836
5846
|
|
|
5847
|
+
// src/version.ts
|
|
5848
|
+
var LIBRARY_VERSION = "2.0.0-alpha.81";
|
|
5849
|
+
|
|
5837
5850
|
// src/pricing-brain.ts
|
|
5838
5851
|
function isPricingRow(x) {
|
|
5839
5852
|
if (!x || typeof x !== "object") return false;
|
|
@@ -6407,6 +6420,12 @@ function buildAdvisoryRow(outcomeId, a) {
|
|
|
6407
6420
|
outcome_id: outcomeId,
|
|
6408
6421
|
code: a.code,
|
|
6409
6422
|
level: a.level,
|
|
6423
|
+
// alpha.81 (tt-intel s118, migration 053) — the emitting library version.
|
|
6424
|
+
// A corrected rule cannot rewrite firings that are already open, so a
|
|
6425
|
+
// consumer reading a stale suggestion had no way to tell it predated the
|
|
6426
|
+
// fix. tt-intel spent two hours on exactly that. NULL on pre-053 rows
|
|
6427
|
+
// reads as UNKNOWN; from here every firing self-identifies.
|
|
6428
|
+
rule_version: LIBRARY_VERSION,
|
|
6410
6429
|
message: a.message,
|
|
6411
6430
|
recommendation_type: a.recommendationType ?? null,
|
|
6412
6431
|
suggestion: a.suggestion ?? null,
|
|
@@ -9382,11 +9401,19 @@ function createBrainForwardRoutes(config) {
|
|
|
9382
9401
|
return { handle, segments: KNOWN_SEGMENTS };
|
|
9383
9402
|
}
|
|
9384
9403
|
|
|
9385
|
-
// src/version.ts
|
|
9386
|
-
var LIBRARY_VERSION = "2.0.0-alpha.80";
|
|
9387
|
-
|
|
9388
9404
|
// src/key-health.ts
|
|
9389
9405
|
var JSON_HEADERS2 = { "Content-Type": "application/json" };
|
|
9406
|
+
var KEY_FINGERPRINT_DOMAIN = "kgauto-key-fingerprint-v1:";
|
|
9407
|
+
var KEY_FINGERPRINT_LENGTH = 12;
|
|
9408
|
+
async function keyFingerprint(key) {
|
|
9409
|
+
const trimmed = key?.trim();
|
|
9410
|
+
if (!trimmed) return void 0;
|
|
9411
|
+
const subtle = globalThis.crypto?.subtle;
|
|
9412
|
+
if (!subtle) return void 0;
|
|
9413
|
+
const bytes = new TextEncoder().encode(KEY_FINGERPRINT_DOMAIN + trimmed);
|
|
9414
|
+
const digest = await subtle.digest("SHA-256", bytes);
|
|
9415
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, KEY_FINGERPRINT_LENGTH);
|
|
9416
|
+
}
|
|
9390
9417
|
function jsonResponse2(status, body) {
|
|
9391
9418
|
return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS2 });
|
|
9392
9419
|
}
|
|
@@ -9488,11 +9515,13 @@ function createKeyHealthRoute(config) {
|
|
|
9488
9515
|
detail: "key_absent"
|
|
9489
9516
|
};
|
|
9490
9517
|
}
|
|
9518
|
+
const fingerprint = await keyFingerprint(key);
|
|
9491
9519
|
const base = {
|
|
9492
9520
|
provider: spec.provider,
|
|
9493
9521
|
env: envName,
|
|
9494
9522
|
present: true,
|
|
9495
|
-
valid: null
|
|
9523
|
+
valid: null,
|
|
9524
|
+
...fingerprint ? { key_fingerprint: fingerprint } : {}
|
|
9496
9525
|
};
|
|
9497
9526
|
const { url, headers } = spec.buildRequest(key);
|
|
9498
9527
|
const started = Date.now();
|
|
@@ -10440,6 +10469,8 @@ function compile2(ir, opts) {
|
|
|
10440
10469
|
FamilyResolutionError,
|
|
10441
10470
|
INTENT_ARCHETYPES,
|
|
10442
10471
|
JUDGE_RUBRICS,
|
|
10472
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
10473
|
+
KEY_FINGERPRINT_LENGTH,
|
|
10443
10474
|
LATENCY_TIER_MS,
|
|
10444
10475
|
LIBRARY_VERSION,
|
|
10445
10476
|
MEASURED_FAILURE_CFG,
|
|
@@ -10488,6 +10519,7 @@ function compile2(ir, opts) {
|
|
|
10488
10519
|
deriveFamilyFromModelId,
|
|
10489
10520
|
deriveOwnership,
|
|
10490
10521
|
estimateChainCostUsd,
|
|
10522
|
+
estimateModelCostUsd,
|
|
10491
10523
|
execute,
|
|
10492
10524
|
findBetterFit,
|
|
10493
10525
|
flushBrainDeadLetter,
|
|
@@ -10524,6 +10556,7 @@ function compile2(ir, opts) {
|
|
|
10524
10556
|
isPromotionsBrainActive,
|
|
10525
10557
|
isProviderReachable,
|
|
10526
10558
|
judgeMeasuredFailure,
|
|
10559
|
+
keyFingerprint,
|
|
10527
10560
|
latencyTierOf,
|
|
10528
10561
|
learningKey,
|
|
10529
10562
|
loadAliasesFromBrain,
|
package/dist/index.mjs
CHANGED
|
@@ -14,9 +14,12 @@ import {
|
|
|
14
14
|
resolveOutputMode
|
|
15
15
|
} from "./chunk-BVEXV5KC.mjs";
|
|
16
16
|
import {
|
|
17
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
18
|
+
KEY_FINGERPRINT_LENGTH,
|
|
17
19
|
LIBRARY_VERSION,
|
|
18
|
-
createKeyHealthRoute
|
|
19
|
-
|
|
20
|
+
createKeyHealthRoute,
|
|
21
|
+
keyFingerprint
|
|
22
|
+
} from "./chunk-OZNAGO4U.mjs";
|
|
20
23
|
import {
|
|
21
24
|
ABSOLUTE_FLOOR,
|
|
22
25
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
@@ -29,6 +32,7 @@ import {
|
|
|
29
32
|
createBrainQueryCache,
|
|
30
33
|
ensureCrossProviderTail,
|
|
31
34
|
estimateChainCostUsd,
|
|
35
|
+
estimateModelCostUsd,
|
|
32
36
|
getAllStarterChains,
|
|
33
37
|
getAllStarterChainsWithGrounding,
|
|
34
38
|
getArchetypePerfScore,
|
|
@@ -50,7 +54,7 @@ import {
|
|
|
50
54
|
loadChainsFromBrain,
|
|
51
55
|
readBrainReadEnv,
|
|
52
56
|
resolveProviderKey
|
|
53
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-XPD4I3Q5.mjs";
|
|
54
58
|
import {
|
|
55
59
|
ALIASES,
|
|
56
60
|
LATENCY_TIER_MS,
|
|
@@ -3733,6 +3737,12 @@ function buildAdvisoryRow(outcomeId, a) {
|
|
|
3733
3737
|
outcome_id: outcomeId,
|
|
3734
3738
|
code: a.code,
|
|
3735
3739
|
level: a.level,
|
|
3740
|
+
// alpha.81 (tt-intel s118, migration 053) — the emitting library version.
|
|
3741
|
+
// A corrected rule cannot rewrite firings that are already open, so a
|
|
3742
|
+
// consumer reading a stale suggestion had no way to tell it predated the
|
|
3743
|
+
// fix. tt-intel spent two hours on exactly that. NULL on pre-053 rows
|
|
3744
|
+
// reads as UNKNOWN; from here every firing self-identifies.
|
|
3745
|
+
rule_version: LIBRARY_VERSION,
|
|
3736
3746
|
message: a.message,
|
|
3737
3747
|
recommendation_type: a.recommendationType ?? null,
|
|
3738
3748
|
suggestion: a.suggestion ?? null,
|
|
@@ -7099,6 +7109,8 @@ export {
|
|
|
7099
7109
|
FamilyResolutionError,
|
|
7100
7110
|
INTENT_ARCHETYPES,
|
|
7101
7111
|
JUDGE_RUBRICS,
|
|
7112
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
7113
|
+
KEY_FINGERPRINT_LENGTH,
|
|
7102
7114
|
LATENCY_TIER_MS,
|
|
7103
7115
|
LIBRARY_VERSION,
|
|
7104
7116
|
MEASURED_FAILURE_CFG,
|
|
@@ -7147,6 +7159,7 @@ export {
|
|
|
7147
7159
|
deriveFamilyFromModelId,
|
|
7148
7160
|
deriveOwnership,
|
|
7149
7161
|
estimateChainCostUsd,
|
|
7162
|
+
estimateModelCostUsd,
|
|
7150
7163
|
execute,
|
|
7151
7164
|
findBetterFit,
|
|
7152
7165
|
flushBrainDeadLetter,
|
|
@@ -7183,6 +7196,7 @@ export {
|
|
|
7183
7196
|
isPromotionsBrainActive,
|
|
7184
7197
|
isProviderReachable,
|
|
7185
7198
|
judgeMeasuredFailure,
|
|
7199
|
+
keyFingerprint,
|
|
7186
7200
|
latencyTierOf,
|
|
7187
7201
|
learningKey,
|
|
7188
7202
|
loadAliasesFromBrain,
|
package/dist/key-health.d.mts
CHANGED
|
@@ -86,6 +86,34 @@ interface KeyHealthConfig {
|
|
|
86
86
|
/** Per-provider probe timeout in ms. Default 3000. */
|
|
87
87
|
timeoutMs?: number;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* alpha.81 — a NON-REVERSIBLE identity for a provider key, so the fleet can
|
|
91
|
+
* answer "are two consumers on the same key?" without any consumer, or the
|
|
92
|
+
* brain, ever holding a key value.
|
|
93
|
+
*
|
|
94
|
+
* Origin: PB's `one-shared-provider-key-across-four-consumers` (s83). All four
|
|
95
|
+
* provider keys are Vercel team-level Shared Env Vars across four projects, so
|
|
96
|
+
* one exhausted account is a four-consumer outage that each consumer diagnoses
|
|
97
|
+
* locally as its own, and provider spend is a single undifferentiated number.
|
|
98
|
+
* PB's observation that only kgauto can see this is correct: the library runs
|
|
99
|
+
* inside every consumer's process and resolves the key there; no consumer can
|
|
100
|
+
* compare its key against a peer's.
|
|
101
|
+
*
|
|
102
|
+
* **Why truncation is the safety property, not an optimization.** The digest is
|
|
103
|
+
* cut to 12 hex chars (48 bits) — enough that a collision between the handful
|
|
104
|
+
* of keys in one portfolio is negligible, far too little to verify a guessed
|
|
105
|
+
* key against. Provider keys are high-entropy random strings, so even the full
|
|
106
|
+
* digest would not be brute-forceable; the truncation means the stored value is
|
|
107
|
+
* not a verification oracle even if the key space were later reduced. The
|
|
108
|
+
* domain-separation prefix keeps these digests useless against any hash
|
|
109
|
+
* computed for another purpose.
|
|
110
|
+
*
|
|
111
|
+
* Never log, return, or persist the key itself. This function is the only
|
|
112
|
+
* sanctioned way a key becomes a value that may leave the process.
|
|
113
|
+
*/
|
|
114
|
+
declare const KEY_FINGERPRINT_DOMAIN = "kgauto-key-fingerprint-v1:";
|
|
115
|
+
declare const KEY_FINGERPRINT_LENGTH = 12;
|
|
116
|
+
declare function keyFingerprint(key: string): Promise<string | undefined>;
|
|
89
117
|
interface KeyHealthResult {
|
|
90
118
|
provider: KeyHealthProvider;
|
|
91
119
|
/** Canonical env var name probed (the resolved one for Google). */
|
|
@@ -102,6 +130,13 @@ interface KeyHealthResult {
|
|
|
102
130
|
balance_usd?: number;
|
|
103
131
|
/** Failure class when valid is null with a probe attempted (e.g. 'timeout', 'http_500') or 'key_absent'. */
|
|
104
132
|
detail?: string;
|
|
133
|
+
/**
|
|
134
|
+
* alpha.81 — truncated, domain-separated SHA-256 of the resolved key. NEVER
|
|
135
|
+
* the key. Identical values across two consumers mean they resolve the same
|
|
136
|
+
* credential; that is the only question it can answer. Absent when the key is
|
|
137
|
+
* absent or the runtime exposes no WebCrypto. See {@link keyFingerprint}.
|
|
138
|
+
*/
|
|
139
|
+
key_fingerprint?: string;
|
|
105
140
|
}
|
|
106
141
|
interface KeyHealthResponseBody {
|
|
107
142
|
app_id: string;
|
|
@@ -128,4 +163,4 @@ interface KeyHealthRoute {
|
|
|
128
163
|
*/
|
|
129
164
|
declare function createKeyHealthRoute(config: KeyHealthConfig): KeyHealthRoute;
|
|
130
165
|
|
|
131
|
-
export { type KeyHealthConfig, type KeyHealthProvider, type KeyHealthResponseBody, type KeyHealthResult, type KeyHealthRoute, createKeyHealthRoute };
|
|
166
|
+
export { KEY_FINGERPRINT_DOMAIN, KEY_FINGERPRINT_LENGTH, type KeyHealthConfig, type KeyHealthProvider, type KeyHealthResponseBody, type KeyHealthResult, type KeyHealthRoute, createKeyHealthRoute, keyFingerprint };
|
package/dist/key-health.d.ts
CHANGED
|
@@ -86,6 +86,34 @@ interface KeyHealthConfig {
|
|
|
86
86
|
/** Per-provider probe timeout in ms. Default 3000. */
|
|
87
87
|
timeoutMs?: number;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* alpha.81 — a NON-REVERSIBLE identity for a provider key, so the fleet can
|
|
91
|
+
* answer "are two consumers on the same key?" without any consumer, or the
|
|
92
|
+
* brain, ever holding a key value.
|
|
93
|
+
*
|
|
94
|
+
* Origin: PB's `one-shared-provider-key-across-four-consumers` (s83). All four
|
|
95
|
+
* provider keys are Vercel team-level Shared Env Vars across four projects, so
|
|
96
|
+
* one exhausted account is a four-consumer outage that each consumer diagnoses
|
|
97
|
+
* locally as its own, and provider spend is a single undifferentiated number.
|
|
98
|
+
* PB's observation that only kgauto can see this is correct: the library runs
|
|
99
|
+
* inside every consumer's process and resolves the key there; no consumer can
|
|
100
|
+
* compare its key against a peer's.
|
|
101
|
+
*
|
|
102
|
+
* **Why truncation is the safety property, not an optimization.** The digest is
|
|
103
|
+
* cut to 12 hex chars (48 bits) — enough that a collision between the handful
|
|
104
|
+
* of keys in one portfolio is negligible, far too little to verify a guessed
|
|
105
|
+
* key against. Provider keys are high-entropy random strings, so even the full
|
|
106
|
+
* digest would not be brute-forceable; the truncation means the stored value is
|
|
107
|
+
* not a verification oracle even if the key space were later reduced. The
|
|
108
|
+
* domain-separation prefix keeps these digests useless against any hash
|
|
109
|
+
* computed for another purpose.
|
|
110
|
+
*
|
|
111
|
+
* Never log, return, or persist the key itself. This function is the only
|
|
112
|
+
* sanctioned way a key becomes a value that may leave the process.
|
|
113
|
+
*/
|
|
114
|
+
declare const KEY_FINGERPRINT_DOMAIN = "kgauto-key-fingerprint-v1:";
|
|
115
|
+
declare const KEY_FINGERPRINT_LENGTH = 12;
|
|
116
|
+
declare function keyFingerprint(key: string): Promise<string | undefined>;
|
|
89
117
|
interface KeyHealthResult {
|
|
90
118
|
provider: KeyHealthProvider;
|
|
91
119
|
/** Canonical env var name probed (the resolved one for Google). */
|
|
@@ -102,6 +130,13 @@ interface KeyHealthResult {
|
|
|
102
130
|
balance_usd?: number;
|
|
103
131
|
/** Failure class when valid is null with a probe attempted (e.g. 'timeout', 'http_500') or 'key_absent'. */
|
|
104
132
|
detail?: string;
|
|
133
|
+
/**
|
|
134
|
+
* alpha.81 — truncated, domain-separated SHA-256 of the resolved key. NEVER
|
|
135
|
+
* the key. Identical values across two consumers mean they resolve the same
|
|
136
|
+
* credential; that is the only question it can answer. Absent when the key is
|
|
137
|
+
* absent or the runtime exposes no WebCrypto. See {@link keyFingerprint}.
|
|
138
|
+
*/
|
|
139
|
+
key_fingerprint?: string;
|
|
105
140
|
}
|
|
106
141
|
interface KeyHealthResponseBody {
|
|
107
142
|
app_id: string;
|
|
@@ -128,4 +163,4 @@ interface KeyHealthRoute {
|
|
|
128
163
|
*/
|
|
129
164
|
declare function createKeyHealthRoute(config: KeyHealthConfig): KeyHealthRoute;
|
|
130
165
|
|
|
131
|
-
export { type KeyHealthConfig, type KeyHealthProvider, type KeyHealthResponseBody, type KeyHealthResult, type KeyHealthRoute, createKeyHealthRoute };
|
|
166
|
+
export { KEY_FINGERPRINT_DOMAIN, KEY_FINGERPRINT_LENGTH, type KeyHealthConfig, type KeyHealthProvider, type KeyHealthResponseBody, type KeyHealthResult, type KeyHealthRoute, createKeyHealthRoute, keyFingerprint };
|
package/dist/key-health.js
CHANGED
|
@@ -20,15 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/key-health.ts
|
|
21
21
|
var key_health_exports = {};
|
|
22
22
|
__export(key_health_exports, {
|
|
23
|
-
|
|
23
|
+
KEY_FINGERPRINT_DOMAIN: () => KEY_FINGERPRINT_DOMAIN,
|
|
24
|
+
KEY_FINGERPRINT_LENGTH: () => KEY_FINGERPRINT_LENGTH,
|
|
25
|
+
createKeyHealthRoute: () => createKeyHealthRoute,
|
|
26
|
+
keyFingerprint: () => keyFingerprint
|
|
24
27
|
});
|
|
25
28
|
module.exports = __toCommonJS(key_health_exports);
|
|
26
29
|
|
|
27
30
|
// src/version.ts
|
|
28
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
31
|
+
var LIBRARY_VERSION = "2.0.0-alpha.81";
|
|
29
32
|
|
|
30
33
|
// src/key-health.ts
|
|
31
34
|
var JSON_HEADERS = { "Content-Type": "application/json" };
|
|
35
|
+
var KEY_FINGERPRINT_DOMAIN = "kgauto-key-fingerprint-v1:";
|
|
36
|
+
var KEY_FINGERPRINT_LENGTH = 12;
|
|
37
|
+
async function keyFingerprint(key) {
|
|
38
|
+
const trimmed = key?.trim();
|
|
39
|
+
if (!trimmed) return void 0;
|
|
40
|
+
const subtle = globalThis.crypto?.subtle;
|
|
41
|
+
if (!subtle) return void 0;
|
|
42
|
+
const bytes = new TextEncoder().encode(KEY_FINGERPRINT_DOMAIN + trimmed);
|
|
43
|
+
const digest = await subtle.digest("SHA-256", bytes);
|
|
44
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, KEY_FINGERPRINT_LENGTH);
|
|
45
|
+
}
|
|
32
46
|
function jsonResponse(status, body) {
|
|
33
47
|
return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
|
|
34
48
|
}
|
|
@@ -130,11 +144,13 @@ function createKeyHealthRoute(config) {
|
|
|
130
144
|
detail: "key_absent"
|
|
131
145
|
};
|
|
132
146
|
}
|
|
147
|
+
const fingerprint = await keyFingerprint(key);
|
|
133
148
|
const base = {
|
|
134
149
|
provider: spec.provider,
|
|
135
150
|
env: envName,
|
|
136
151
|
present: true,
|
|
137
|
-
valid: null
|
|
152
|
+
valid: null,
|
|
153
|
+
...fingerprint ? { key_fingerprint: fingerprint } : {}
|
|
138
154
|
};
|
|
139
155
|
const { url, headers } = spec.buildRequest(key);
|
|
140
156
|
const started = Date.now();
|
|
@@ -224,5 +240,8 @@ function createKeyHealthRoute(config) {
|
|
|
224
240
|
}
|
|
225
241
|
// Annotate the CommonJS export names for ESM import in node:
|
|
226
242
|
0 && (module.exports = {
|
|
227
|
-
|
|
243
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
244
|
+
KEY_FINGERPRINT_LENGTH,
|
|
245
|
+
createKeyHealthRoute,
|
|
246
|
+
keyFingerprint
|
|
228
247
|
});
|
package/dist/key-health.mjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
3
|
+
KEY_FINGERPRINT_LENGTH,
|
|
4
|
+
createKeyHealthRoute,
|
|
5
|
+
keyFingerprint
|
|
6
|
+
} from "./chunk-OZNAGO4U.mjs";
|
|
4
7
|
export {
|
|
5
|
-
|
|
8
|
+
KEY_FINGERPRINT_DOMAIN,
|
|
9
|
+
KEY_FINGERPRINT_LENGTH,
|
|
10
|
+
createKeyHealthRoute,
|
|
11
|
+
keyFingerprint
|
|
6
12
|
};
|
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.81",
|
|
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",
|