agentfootprint 2.5.1 → 2.6.1
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/adapters/llm/BrowserAnthropicProvider.js +68 -0
- package/dist/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/cache/CacheDecisionSubflow.js +172 -0
- package/dist/cache/CacheDecisionSubflow.js.map +1 -0
- package/dist/cache/CacheGateDecider.js +122 -0
- package/dist/cache/CacheGateDecider.js.map +1 -0
- package/dist/cache/applyCachePolicy.js +55 -0
- package/dist/cache/applyCachePolicy.js.map +1 -0
- package/dist/cache/cacheRecorder.js +120 -0
- package/dist/cache/cacheRecorder.js.map +1 -0
- package/dist/cache/index.js +47 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/strategies/AnthropicCacheStrategy.js +102 -0
- package/dist/cache/strategies/AnthropicCacheStrategy.js.map +1 -0
- package/dist/cache/strategies/BedrockCacheStrategy.js +81 -0
- package/dist/cache/strategies/BedrockCacheStrategy.js.map +1 -0
- package/dist/cache/strategies/NoOpCacheStrategy.js +40 -0
- package/dist/cache/strategies/NoOpCacheStrategy.js.map +1 -0
- package/dist/cache/strategies/OpenAICacheStrategy.js +75 -0
- package/dist/cache/strategies/OpenAICacheStrategy.js.map +1 -0
- package/dist/cache/strategyRegistry.js +80 -0
- package/dist/cache/strategyRegistry.js.map +1 -0
- package/dist/cache/types.js +25 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/conventions.js +18 -0
- package/dist/conventions.js.map +1 -1
- package/dist/core/Agent.js +157 -4
- package/dist/core/Agent.js.map +1 -1
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js +68 -0
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/esm/cache/CacheDecisionSubflow.js +166 -0
- package/dist/esm/cache/CacheDecisionSubflow.js.map +1 -0
- package/dist/esm/cache/CacheGateDecider.js +116 -0
- package/dist/esm/cache/CacheGateDecider.js.map +1 -0
- package/dist/esm/cache/applyCachePolicy.js +50 -0
- package/dist/esm/cache/applyCachePolicy.js.map +1 -0
- package/dist/esm/cache/cacheRecorder.js +116 -0
- package/dist/esm/cache/cacheRecorder.js.map +1 -0
- package/dist/esm/cache/index.js +36 -0
- package/dist/esm/cache/index.js.map +1 -0
- package/dist/esm/cache/strategies/AnthropicCacheStrategy.js +98 -0
- package/dist/esm/cache/strategies/AnthropicCacheStrategy.js.map +1 -0
- package/dist/esm/cache/strategies/BedrockCacheStrategy.js +77 -0
- package/dist/esm/cache/strategies/BedrockCacheStrategy.js.map +1 -0
- package/dist/esm/cache/strategies/NoOpCacheStrategy.js +36 -0
- package/dist/esm/cache/strategies/NoOpCacheStrategy.js.map +1 -0
- package/dist/esm/cache/strategies/OpenAICacheStrategy.js +71 -0
- package/dist/esm/cache/strategies/OpenAICacheStrategy.js.map +1 -0
- package/dist/esm/cache/strategyRegistry.js +73 -0
- package/dist/esm/cache/strategyRegistry.js.map +1 -0
- package/dist/esm/cache/types.js +24 -0
- package/dist/esm/cache/types.js.map +1 -0
- package/dist/esm/conventions.js +18 -0
- package/dist/esm/conventions.js.map +1 -1
- package/dist/esm/core/Agent.js +157 -4
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/factories/defineFact.js +3 -0
- package/dist/esm/lib/injection-engine/factories/defineFact.js.map +1 -1
- package/dist/esm/lib/injection-engine/factories/defineInstruction.js +3 -0
- package/dist/esm/lib/injection-engine/factories/defineInstruction.js.map +1 -1
- package/dist/esm/lib/injection-engine/factories/defineSkill.js +5 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.js.map +1 -1
- package/dist/esm/lib/injection-engine/factories/defineSteering.js +3 -0
- package/dist/esm/lib/injection-engine/factories/defineSteering.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineFact.js +3 -0
- package/dist/lib/injection-engine/factories/defineFact.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineInstruction.js +3 -0
- package/dist/lib/injection-engine/factories/defineInstruction.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineSkill.js +5 -0
- package/dist/lib/injection-engine/factories/defineSkill.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineSteering.js +3 -0
- package/dist/lib/injection-engine/factories/defineSteering.js.map +1 -1
- package/dist/types/adapters/types.d.ts +11 -0
- package/dist/types/adapters/types.d.ts.map +1 -1
- package/dist/types/cache/CacheDecisionSubflow.d.ts +89 -0
- package/dist/types/cache/CacheDecisionSubflow.d.ts.map +1 -0
- package/dist/types/cache/CacheGateDecider.d.ts +114 -0
- package/dist/types/cache/CacheGateDecider.d.ts.map +1 -0
- package/dist/types/cache/applyCachePolicy.d.ts +38 -0
- package/dist/types/cache/applyCachePolicy.d.ts.map +1 -0
- package/dist/types/cache/cacheRecorder.d.ts +86 -0
- package/dist/types/cache/cacheRecorder.d.ts.map +1 -0
- package/dist/types/cache/index.d.ts +34 -0
- package/dist/types/cache/index.d.ts.map +1 -0
- package/dist/types/cache/strategies/AnthropicCacheStrategy.d.ts +39 -0
- package/dist/types/cache/strategies/AnthropicCacheStrategy.d.ts.map +1 -0
- package/dist/types/cache/strategies/BedrockCacheStrategy.d.ts +34 -0
- package/dist/types/cache/strategies/BedrockCacheStrategy.d.ts.map +1 -0
- package/dist/types/cache/strategies/NoOpCacheStrategy.d.ts +30 -0
- package/dist/types/cache/strategies/NoOpCacheStrategy.d.ts.map +1 -0
- package/dist/types/cache/strategies/OpenAICacheStrategy.d.ts +37 -0
- package/dist/types/cache/strategies/OpenAICacheStrategy.d.ts.map +1 -0
- package/dist/types/cache/strategyRegistry.d.ts +46 -0
- package/dist/types/cache/strategyRegistry.d.ts.map +1 -0
- package/dist/types/cache/types.d.ts +244 -0
- package/dist/types/cache/types.d.ts.map +1 -0
- package/dist/types/conventions.d.ts +18 -0
- package/dist/types/conventions.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +86 -2
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineFact.d.ts +9 -0
- package/dist/types/lib/injection-engine/factories/defineFact.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineInstruction.d.ts +11 -0
- package/dist/types/lib/injection-engine/factories/defineInstruction.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineSkill.d.ts +15 -0
- package/dist/types/lib/injection-engine/factories/defineSkill.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineSteering.d.ts +12 -0
- package/dist/types/lib/injection-engine/factories/defineSteering.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* agentfootprint/cache — public surface for the cache layer (v2.6+).
|
|
4
|
+
*
|
|
5
|
+
* Importing this module side-effect-registers every built-in cache
|
|
6
|
+
* strategy in the registry. The agentfootprint main barrel imports
|
|
7
|
+
* from here so consumers get the registered strategies without
|
|
8
|
+
* needing to know they exist.
|
|
9
|
+
*
|
|
10
|
+
* Strategies registered as of v2.6:
|
|
11
|
+
* - NoOp (wildcard '*' fallback) — always available, registered by
|
|
12
|
+
* the registry module itself
|
|
13
|
+
* - AnthropicCacheStrategy ('anthropic', 'browser-anthropic')
|
|
14
|
+
*
|
|
15
|
+
* Future strategies (Phase 8+):
|
|
16
|
+
* - OpenAICacheStrategy
|
|
17
|
+
* - BedrockCacheStrategy
|
|
18
|
+
* - GeminiCacheStrategy (v2.7+, async handle-based)
|
|
19
|
+
*
|
|
20
|
+
* Public types (re-exported for consumers):
|
|
21
|
+
* - CachePolicy, CacheMarker, CacheStrategy, CacheCapabilities,
|
|
22
|
+
* CacheMetrics, CachePolicyContext, CacheStrategyContext
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.cacheRecorder = exports.BedrockCacheStrategy = exports.OpenAICacheStrategy = exports.AnthropicCacheStrategy = exports.NoOpCacheStrategy = exports.listRegisteredStrategies = exports.registerCacheStrategy = exports.getDefaultCacheStrategy = void 0;
|
|
26
|
+
// Side-effect imports — register strategies on module load.
|
|
27
|
+
require("./strategies/AnthropicCacheStrategy.js");
|
|
28
|
+
require("./strategies/OpenAICacheStrategy.js");
|
|
29
|
+
require("./strategies/BedrockCacheStrategy.js");
|
|
30
|
+
// Strategy registry
|
|
31
|
+
var strategyRegistry_js_1 = require("./strategyRegistry.js");
|
|
32
|
+
Object.defineProperty(exports, "getDefaultCacheStrategy", { enumerable: true, get: function () { return strategyRegistry_js_1.getDefaultCacheStrategy; } });
|
|
33
|
+
Object.defineProperty(exports, "registerCacheStrategy", { enumerable: true, get: function () { return strategyRegistry_js_1.registerCacheStrategy; } });
|
|
34
|
+
Object.defineProperty(exports, "listRegisteredStrategies", { enumerable: true, get: function () { return strategyRegistry_js_1.listRegisteredStrategies; } });
|
|
35
|
+
// Built-in strategy classes (for consumers who want explicit overrides)
|
|
36
|
+
var NoOpCacheStrategy_js_1 = require("./strategies/NoOpCacheStrategy.js");
|
|
37
|
+
Object.defineProperty(exports, "NoOpCacheStrategy", { enumerable: true, get: function () { return NoOpCacheStrategy_js_1.NoOpCacheStrategy; } });
|
|
38
|
+
var AnthropicCacheStrategy_js_1 = require("./strategies/AnthropicCacheStrategy.js");
|
|
39
|
+
Object.defineProperty(exports, "AnthropicCacheStrategy", { enumerable: true, get: function () { return AnthropicCacheStrategy_js_1.AnthropicCacheStrategy; } });
|
|
40
|
+
var OpenAICacheStrategy_js_1 = require("./strategies/OpenAICacheStrategy.js");
|
|
41
|
+
Object.defineProperty(exports, "OpenAICacheStrategy", { enumerable: true, get: function () { return OpenAICacheStrategy_js_1.OpenAICacheStrategy; } });
|
|
42
|
+
var BedrockCacheStrategy_js_1 = require("./strategies/BedrockCacheStrategy.js");
|
|
43
|
+
Object.defineProperty(exports, "BedrockCacheStrategy", { enumerable: true, get: function () { return BedrockCacheStrategy_js_1.BedrockCacheStrategy; } });
|
|
44
|
+
// Recorder
|
|
45
|
+
var cacheRecorder_js_1 = require("./cacheRecorder.js");
|
|
46
|
+
Object.defineProperty(exports, "cacheRecorder", { enumerable: true, get: function () { return cacheRecorder_js_1.cacheRecorder; } });
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,4DAA4D;AAC5D,kDAAgD;AAChD,+CAA6C;AAC7C,gDAA8C;AAa9C,oBAAoB;AACpB,6DAI+B;AAH7B,8HAAA,uBAAuB,OAAA;AACvB,4HAAA,qBAAqB,OAAA;AACrB,+HAAA,wBAAwB,OAAA;AAG1B,wEAAwE;AACxE,0EAAsE;AAA7D,yHAAA,iBAAiB,OAAA;AAC1B,oFAAgF;AAAvE,mIAAA,sBAAsB,OAAA;AAC/B,8EAA0E;AAAjE,6HAAA,mBAAmB,OAAA;AAC5B,gFAA4E;AAAnE,+HAAA,oBAAoB,OAAA;AAE7B,WAAW;AACX,uDAAmD;AAA1C,iHAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AnthropicCacheStrategy — translates agnostic CacheMarker[] to
|
|
4
|
+
* Anthropic API's `cache_control: { type: 'ephemeral' }` markers.
|
|
5
|
+
*
|
|
6
|
+
* Anthropic-specific behaviors honored:
|
|
7
|
+
* - **4-marker limit**: Anthropic allows ≤4 cache breakpoints per
|
|
8
|
+
* request. Strategy clamps oversize candidate sets, keeping the
|
|
9
|
+
* first 4 in slot order.
|
|
10
|
+
* - **TTL mapping**: 'short' → default 5min ephemeral; 'long' →
|
|
11
|
+
* `ttl: '1h'` (1-hour beta).
|
|
12
|
+
* - **Provider-side hashing**: this strategy doesn't hash — Anthropic
|
|
13
|
+
* keys cache by exact byte prefix server-side. We don't need
|
|
14
|
+
* content hashes for the v2.6 surface; reserved for v2.7+ if a
|
|
15
|
+
* pre-flight cache-warm-check API ships.
|
|
16
|
+
*
|
|
17
|
+
* What this strategy DOES vs DOESN'T do:
|
|
18
|
+
* - DOES: clamp markers, attach to LLMRequest.cacheMarkers,
|
|
19
|
+
* extract metrics from response.usage
|
|
20
|
+
* - DOES NOT: rewrite the wire body. The provider
|
|
21
|
+
* (BrowserAnthropicProvider) reads `cacheMarkers` and applies
|
|
22
|
+
* `cache_control` blocks during body construction. Separation of
|
|
23
|
+
* concerns: strategy decides WHAT to cache; provider knows HOW
|
|
24
|
+
* to encode on its specific wire.
|
|
25
|
+
*
|
|
26
|
+
* Auto-registers in the strategy registry on module import for
|
|
27
|
+
* provider names: 'anthropic', 'browser-anthropic'.
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.AnthropicCacheStrategy = void 0;
|
|
31
|
+
const strategyRegistry_js_1 = require("../strategyRegistry.js");
|
|
32
|
+
/** Anthropic enforces 4 cache breakpoints per request. */
|
|
33
|
+
const ANTHROPIC_MAX_MARKERS = 4;
|
|
34
|
+
const ANTHROPIC_CAPABILITIES = Object.freeze({
|
|
35
|
+
enabled: true,
|
|
36
|
+
maxMarkers: ANTHROPIC_MAX_MARKERS,
|
|
37
|
+
ttls: ['short', 'long'],
|
|
38
|
+
fields: ['system', 'tools', 'messages'],
|
|
39
|
+
automatic: false,
|
|
40
|
+
});
|
|
41
|
+
class AnthropicCacheStrategy {
|
|
42
|
+
providerName = 'anthropic';
|
|
43
|
+
capabilities = ANTHROPIC_CAPABILITIES;
|
|
44
|
+
async prepareRequest(req, candidates, ctx) {
|
|
45
|
+
// Honor the agent-side kill switch even if reached this far —
|
|
46
|
+
// belt-and-suspenders. CacheGate should have routed to no-markers
|
|
47
|
+
// already, leaving `candidates` empty, but if a buggy gate lets
|
|
48
|
+
// markers through with cachingDisabled=true, we still respect it.
|
|
49
|
+
if (ctx.cachingDisabled) {
|
|
50
|
+
return { request: req, markersApplied: [] };
|
|
51
|
+
}
|
|
52
|
+
if (candidates.length === 0) {
|
|
53
|
+
return { request: req, markersApplied: [] };
|
|
54
|
+
}
|
|
55
|
+
// Clamp to Anthropic's 4-marker limit. Keep the first N in
|
|
56
|
+
// slot order so we cover the most-stable prefixes (system /
|
|
57
|
+
// always-on injections / tools) before less-stable trailing ones.
|
|
58
|
+
const markersApplied = candidates.length <= ANTHROPIC_MAX_MARKERS
|
|
59
|
+
? candidates
|
|
60
|
+
: candidates.slice(0, ANTHROPIC_MAX_MARKERS);
|
|
61
|
+
const request = {
|
|
62
|
+
...req,
|
|
63
|
+
cacheMarkers: markersApplied,
|
|
64
|
+
};
|
|
65
|
+
return { request, markersApplied };
|
|
66
|
+
}
|
|
67
|
+
extractMetrics(usage) {
|
|
68
|
+
if (!usage || typeof usage !== 'object')
|
|
69
|
+
return undefined;
|
|
70
|
+
const u = usage;
|
|
71
|
+
const cacheRead = u.cache_read_input_tokens ?? 0;
|
|
72
|
+
const cacheWrite = u.cache_creation_input_tokens ?? 0;
|
|
73
|
+
const fresh = u.input_tokens ?? 0;
|
|
74
|
+
// If neither cache field present, response didn't involve caching.
|
|
75
|
+
// Returning undefined signals "no cache info" so cacheRecorder
|
|
76
|
+
// doesn't compute a misleading 0% hit rate.
|
|
77
|
+
if (cacheRead === 0 && cacheWrite === 0)
|
|
78
|
+
return undefined;
|
|
79
|
+
return {
|
|
80
|
+
cacheReadTokens: cacheRead,
|
|
81
|
+
cacheWriteTokens: cacheWrite,
|
|
82
|
+
freshInputTokens: fresh,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.AnthropicCacheStrategy = AnthropicCacheStrategy;
|
|
87
|
+
// Auto-register on module import. Both 'anthropic' (server-side) and
|
|
88
|
+
// 'browser-anthropic' (browser fetch) providers map to this strategy.
|
|
89
|
+
{
|
|
90
|
+
const strategy = new AnthropicCacheStrategy();
|
|
91
|
+
(0, strategyRegistry_js_1.registerCacheStrategy)(strategy);
|
|
92
|
+
// Register the browser variant by cloning with the matching provider name.
|
|
93
|
+
// Same behavior, different provider.name match-key.
|
|
94
|
+
const browserStrategy = {
|
|
95
|
+
providerName: 'browser-anthropic',
|
|
96
|
+
capabilities: strategy.capabilities,
|
|
97
|
+
prepareRequest: strategy.prepareRequest.bind(strategy),
|
|
98
|
+
extractMetrics: strategy.extractMetrics.bind(strategy),
|
|
99
|
+
};
|
|
100
|
+
(0, strategyRegistry_js_1.registerCacheStrategy)(browserStrategy);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=AnthropicCacheStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnthropicCacheStrategy.js","sourceRoot":"","sources":["../../../src/cache/strategies/AnthropicCacheStrategy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAUH,gEAA+D;AAE/D,0DAA0D;AAC1D,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC,MAAM,sBAAsB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC9D,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,qBAAqB;IACjC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAkC;IACxD,MAAM,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAiD;IACvF,SAAS,EAAE,KAAK;CACjB,CAAC,CAAC;AAEH,MAAa,sBAAsB;IACxB,YAAY,GAAG,WAAW,CAAC;IAC3B,YAAY,GAAG,sBAAsB,CAAC;IAE/C,KAAK,CAAC,cAAc,CAClB,GAAe,EACf,UAAkC,EAClC,GAAyB;QAKzB,8DAA8D;QAC9D,kEAAkE;QAClE,gEAAgE;QAChE,kEAAkE;Q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C,MAAM,QAAQ,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAC9C,IAAA,2CAAqB,EAAC,QAAQ,CAAC,CAAC;IAChC,2EAA2E;IAC3E,oDAAoD;IACpD,MAAM,eAAe,GAAkB;QACrC,YAAY,EAAE,mBAAmB;QACjC,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;QACtD,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;KACvD,CAAC;IACF,IAAA,2CAAqB,EAAC,eAAe,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BedrockCacheStrategy — model-aware strategy for AWS Bedrock.
|
|
4
|
+
*
|
|
5
|
+
* Bedrock hosts multiple model families. Cache support varies:
|
|
6
|
+
* - Claude on Bedrock → identical mechanics to direct Anthropic
|
|
7
|
+
* (`cache_control: { type: 'ephemeral' }` markers, 4-marker
|
|
8
|
+
* limit). Strategy delegates to Anthropic-shaped behavior.
|
|
9
|
+
* - Llama / Mistral / Cohere on Bedrock → no cache support today
|
|
10
|
+
* (as of 2026-04-30). Strategy passes through, returns no metrics.
|
|
11
|
+
*
|
|
12
|
+
* Auto-detection: inspects `req.model` to decide. Claude model IDs
|
|
13
|
+
* start with `'anthropic.claude'` on Bedrock (e.g.,
|
|
14
|
+
* `anthropic.claude-3-5-sonnet-20240620-v1:0`).
|
|
15
|
+
*
|
|
16
|
+
* Auto-registers under provider name `'bedrock'`.
|
|
17
|
+
*
|
|
18
|
+
* Per the Phase 1 review (Reviewer 6 — Provider SDK expert): for
|
|
19
|
+
* non-Claude Bedrock models the strategy reports `enabled: false` in
|
|
20
|
+
* its capabilities so the CacheDecision subflow can short-circuit
|
|
21
|
+
* marker emission (potential v2.7 optimization). Today markers still
|
|
22
|
+
* emit and we drop them silently in prepareRequest.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.BedrockCacheStrategy = void 0;
|
|
26
|
+
const strategyRegistry_js_1 = require("../strategyRegistry.js");
|
|
27
|
+
/** Match Bedrock-Claude model ids: `anthropic.claude-...` */
|
|
28
|
+
const BEDROCK_CLAUDE_RE = /^anthropic\.claude/i;
|
|
29
|
+
/** Anthropic's 4-marker limit applies to Bedrock-Claude too. */
|
|
30
|
+
const BEDROCK_MAX_MARKERS = 4;
|
|
31
|
+
const BEDROCK_CAPABILITIES = Object.freeze({
|
|
32
|
+
// We say `enabled: true` at the capability level because Bedrock-
|
|
33
|
+
// Claude DOES support caching. Bedrock-Llama/Mistral land in the
|
|
34
|
+
// model-aware code path inside prepareRequest (no markers applied).
|
|
35
|
+
enabled: true,
|
|
36
|
+
maxMarkers: BEDROCK_MAX_MARKERS,
|
|
37
|
+
ttls: ['short', 'long'],
|
|
38
|
+
fields: ['system', 'tools', 'messages'],
|
|
39
|
+
automatic: false,
|
|
40
|
+
});
|
|
41
|
+
class BedrockCacheStrategy {
|
|
42
|
+
providerName = 'bedrock';
|
|
43
|
+
capabilities = BEDROCK_CAPABILITIES;
|
|
44
|
+
async prepareRequest(req, candidates, ctx) {
|
|
45
|
+
if (ctx.cachingDisabled || candidates.length === 0) {
|
|
46
|
+
return { request: req, markersApplied: [] };
|
|
47
|
+
}
|
|
48
|
+
// Model-aware: only Claude on Bedrock supports cache_control.
|
|
49
|
+
// Other model families silently drop the markers.
|
|
50
|
+
if (!BEDROCK_CLAUDE_RE.test(req.model)) {
|
|
51
|
+
return { request: req, markersApplied: [] };
|
|
52
|
+
}
|
|
53
|
+
const markersApplied = candidates.length <= BEDROCK_MAX_MARKERS
|
|
54
|
+
? candidates
|
|
55
|
+
: candidates.slice(0, BEDROCK_MAX_MARKERS);
|
|
56
|
+
return {
|
|
57
|
+
request: { ...req, cacheMarkers: markersApplied },
|
|
58
|
+
markersApplied,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
extractMetrics(usage) {
|
|
62
|
+
// Bedrock returns the SAME usage shape as Anthropic for Claude
|
|
63
|
+
// models — same cache_creation_input_tokens / cache_read_input_tokens
|
|
64
|
+
// fields. Reuse identical extraction.
|
|
65
|
+
if (!usage || typeof usage !== 'object')
|
|
66
|
+
return undefined;
|
|
67
|
+
const u = usage;
|
|
68
|
+
const cacheRead = u.cache_read_input_tokens ?? 0;
|
|
69
|
+
const cacheWrite = u.cache_creation_input_tokens ?? 0;
|
|
70
|
+
if (cacheRead === 0 && cacheWrite === 0)
|
|
71
|
+
return undefined;
|
|
72
|
+
return {
|
|
73
|
+
cacheReadTokens: cacheRead,
|
|
74
|
+
cacheWriteTokens: cacheWrite,
|
|
75
|
+
freshInputTokens: u.input_tokens ?? 0,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.BedrockCacheStrategy = BedrockCacheStrategy;
|
|
80
|
+
(0, strategyRegistry_js_1.registerCacheStrategy)(new BedrockCacheStrategy());
|
|
81
|
+
//# sourceMappingURL=BedrockCacheStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BedrockCacheStrategy.js","sourceRoot":"","sources":["../../../src/cache/strategies/BedrockCacheStrategy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAUH,gEAA+D;AAE/D,6DAA6D;AAC7D,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD,gEAAgE;AAChE,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,MAAM,oBAAoB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC5D,kEAAkE;IAClE,iEAAiE;IACjE,oEAAoE;IACpE,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,mBAAmB;IAC/B,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAkC;IACxD,MAAM,EAAE,CAAC,QAAQ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C;QAC1D,OAAO;YACL,eAAe,EAAE,SAAS;YAC1B,gBAAgB,EAAE,UAAU;YAC5B,gBAAgB,EAAE,CAAC,CAAC,YAAY,IAAI,CAAC;SACtC,CAAC;IACJ,CAAC;CACF;AAjDD,oDAiDC;AAED,IAAA,2CAAqB,EAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NoOpCacheStrategy — fallback strategy for providers without cache
|
|
4
|
+
* support (Mock, unknown providers, intentional opt-out).
|
|
5
|
+
*
|
|
6
|
+
* Returns the request unchanged; reports no metrics. The
|
|
7
|
+
* `capabilities.enabled` flag is `false` so the CacheDecision subflow
|
|
8
|
+
* could choose to skip emitting markers entirely (potential v2.7
|
|
9
|
+
* optimization), though current Phase 4+5 always emit markers and
|
|
10
|
+
* let the strategy decide what to do with them.
|
|
11
|
+
*
|
|
12
|
+
* Always-available default. Registered against the special wildcard
|
|
13
|
+
* `'*'` so any unrecognized provider name falls back to NoOp.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.NoOpCacheStrategy = void 0;
|
|
17
|
+
const NOOP_CAPABILITIES = Object.freeze({
|
|
18
|
+
enabled: false,
|
|
19
|
+
maxMarkers: 0,
|
|
20
|
+
ttls: [],
|
|
21
|
+
fields: [],
|
|
22
|
+
automatic: false,
|
|
23
|
+
});
|
|
24
|
+
class NoOpCacheStrategy {
|
|
25
|
+
/**
|
|
26
|
+
* Wildcard provider name. The strategy registry treats this as the
|
|
27
|
+
* fallback for any provider that doesn't have a specific strategy
|
|
28
|
+
* registered.
|
|
29
|
+
*/
|
|
30
|
+
providerName = '*';
|
|
31
|
+
capabilities = NOOP_CAPABILITIES;
|
|
32
|
+
async prepareRequest(req, _candidates, _ctx) {
|
|
33
|
+
return { request: req, markersApplied: [] };
|
|
34
|
+
}
|
|
35
|
+
extractMetrics(_usage) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.NoOpCacheStrategy = NoOpCacheStrategy;
|
|
40
|
+
//# sourceMappingURL=NoOpCacheStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoOpCacheStrategy.js","sourceRoot":"","sources":["../../../src/cache/strategies/NoOpCacheStrategy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAWH,MAAM,iBAAiB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACzD,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,CAAC;IACb,IAAI,EAAE,EAAmC;IACzC,MAAM,EAAE,EAAkD;IAC1D,SAAS,EAAE,KAAK;CACjB,CAAC,CAAC;AAEH,MAAa,iBAAiB;IAC5B;;;;OAIG;IACM,YAAY,GAAG,GAAG,CAAC;IACnB,YAAY,GAAG,iBAAiB,CAAC;IAE1C,KAAK,CAAC,cAAc,CAClB,GAAe,EACf,WAAmC,EACnC,IAA0B;QAK1B,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;IAC9C,CAAC;IAED,cAAc,CAAC,MAAe;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAvBD,8CAuBC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenAICacheStrategy — metrics-only strategy for OpenAI providers.
|
|
4
|
+
*
|
|
5
|
+
* OpenAI auto-caches request prefixes ≥1024 tokens at 50% off.
|
|
6
|
+
* No client-side opt-in markers needed (and no way to influence
|
|
7
|
+
* cache behavior from the client). The strategy:
|
|
8
|
+
*
|
|
9
|
+
* - **prepareRequest**: pass-through. We can't tell OpenAI what
|
|
10
|
+
* to cache; they decide automatically. Markers are silently
|
|
11
|
+
* dropped (the 80% case for OpenAI consumers is "I declared
|
|
12
|
+
* cache: 'always' for my injections" — that's still meaningful
|
|
13
|
+
* because (a) it's portable across providers, (b) for OpenAI
|
|
14
|
+
* the auto-cache may still hit on stable prefixes regardless).
|
|
15
|
+
* - **extractMetrics**: reads `prompt_tokens_details.cached_tokens`
|
|
16
|
+
* from OpenAI's usage response so cacheRecorder can surface
|
|
17
|
+
* hit rates / dollar savings.
|
|
18
|
+
*
|
|
19
|
+
* Auto-registers on module import for: 'openai', 'browser-openai'.
|
|
20
|
+
*
|
|
21
|
+
* Documentation note for consumers (Phase 12 docs): the `cache:`
|
|
22
|
+
* directive on injection definitions is portable but has NO LOCAL
|
|
23
|
+
* EFFECT on OpenAI runs — the provider auto-caches based on prefix
|
|
24
|
+
* length. The directive still ships correctly with the agent and
|
|
25
|
+
* lights up automatically when you swap to Anthropic / Bedrock.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.OpenAICacheStrategy = void 0;
|
|
29
|
+
const strategyRegistry_js_1 = require("../strategyRegistry.js");
|
|
30
|
+
const OPENAI_CAPABILITIES = Object.freeze({
|
|
31
|
+
// `enabled: true` because metrics ARE extracted (cacheRecorder shows
|
|
32
|
+
// hit rates). The `automatic: true` flag tells consumers the markers
|
|
33
|
+
// are inert here — OpenAI decides what to cache, not us.
|
|
34
|
+
enabled: true,
|
|
35
|
+
maxMarkers: 0,
|
|
36
|
+
ttls: ['short'],
|
|
37
|
+
fields: [],
|
|
38
|
+
automatic: true,
|
|
39
|
+
});
|
|
40
|
+
class OpenAICacheStrategy {
|
|
41
|
+
providerName = 'openai';
|
|
42
|
+
capabilities = OPENAI_CAPABILITIES;
|
|
43
|
+
async prepareRequest(req, _candidates, _ctx) {
|
|
44
|
+
// Pass-through. OpenAI auto-caches; no opt-in needed.
|
|
45
|
+
return { request: req, markersApplied: [] };
|
|
46
|
+
}
|
|
47
|
+
extractMetrics(usage) {
|
|
48
|
+
if (!usage || typeof usage !== 'object')
|
|
49
|
+
return undefined;
|
|
50
|
+
const u = usage;
|
|
51
|
+
const cached = u.prompt_tokens_details?.cached_tokens ?? 0;
|
|
52
|
+
if (cached === 0)
|
|
53
|
+
return undefined;
|
|
54
|
+
const totalPrompt = u.prompt_tokens ?? cached;
|
|
55
|
+
return {
|
|
56
|
+
cacheReadTokens: cached,
|
|
57
|
+
cacheWriteTokens: 0, // OpenAI doesn't charge a write premium
|
|
58
|
+
freshInputTokens: Math.max(0, totalPrompt - cached),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.OpenAICacheStrategy = OpenAICacheStrategy;
|
|
63
|
+
// Auto-register for both server-side and browser variants.
|
|
64
|
+
{
|
|
65
|
+
const strategy = new OpenAICacheStrategy();
|
|
66
|
+
(0, strategyRegistry_js_1.registerCacheStrategy)(strategy);
|
|
67
|
+
const browserStrategy = {
|
|
68
|
+
providerName: 'browser-openai',
|
|
69
|
+
capabilities: strategy.capabilities,
|
|
70
|
+
prepareRequest: strategy.prepareRequest.bind(strategy),
|
|
71
|
+
extractMetrics: strategy.extractMetrics.bind(strategy),
|
|
72
|
+
};
|
|
73
|
+
(0, strategyRegistry_js_1.registerCacheStrategy)(browserStrategy);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=OpenAICacheStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAICacheStrategy.js","sourceRoot":"","sources":["../../../src/cache/strategies/OpenAICacheStrategy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAUH,gEAA+D;AAE/D,MAAM,mBAAmB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC3D,qEAAqE;IACrE,qEAAqE;IACrE,yDAAyD;IACzD,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,CAAC;IACb,IAAI,EAAE,CAAC,OAAO,CAAkC;IAChD,MAAM,EAAE,EAAkD;IAC1D,SAAS,EAAE,IAAI;CAChB,CAAC,CAAC;AAEH,MAAa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strict";
|
|
2
|
+
/**
|
|
3
|
+
* Strategy registry — maps provider name → CacheStrategy.
|
|
4
|
+
*
|
|
5
|
+
* Auto-resolution at agent build time: agentfootprint inspects
|
|
6
|
+
* `provider.name` and looks up the registered strategy for that
|
|
7
|
+
* name. Falls back to `NoOpCacheStrategy` (registered under wildcard
|
|
8
|
+
* `'*'`) when the provider isn't recognized.
|
|
9
|
+
*
|
|
10
|
+
* Phases shipping registered strategies:
|
|
11
|
+
* - v2.6 Phase 6 (this phase): NoOp
|
|
12
|
+
* - v2.6 Phase 7: AnthropicCacheStrategy ('anthropic',
|
|
13
|
+
* 'browser-anthropic')
|
|
14
|
+
* - v2.6 Phase 8: OpenAICacheStrategy ('openai', 'browser-openai'),
|
|
15
|
+
* BedrockCacheStrategy ('bedrock')
|
|
16
|
+
* - v2.7+ : GeminiCacheStrategy (handle-based, async, deferred)
|
|
17
|
+
*
|
|
18
|
+
* Consumers can register their own strategy via
|
|
19
|
+
* `registerCacheStrategy(strategy)`. Useful for in-house LLM proxies
|
|
20
|
+
* or test mocks.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports._resetRegistryForTests = exports.listRegisteredStrategies = exports.registerCacheStrategy = exports.getDefaultCacheStrategy = void 0;
|
|
24
|
+
const NoOpCacheStrategy_js_1 = require("./strategies/NoOpCacheStrategy.js");
|
|
25
|
+
/**
|
|
26
|
+
* Registry singleton. Populated by individual strategy modules
|
|
27
|
+
* importing this and calling `registerCacheStrategy` at module load
|
|
28
|
+
* time, OR by the consumer at agent build time.
|
|
29
|
+
*
|
|
30
|
+
* Contains the wildcard `'*'` → NoOp entry by default; never empty.
|
|
31
|
+
*/
|
|
32
|
+
const REGISTRY = new Map([['*', new NoOpCacheStrategy_js_1.NoOpCacheStrategy()]]);
|
|
33
|
+
/**
|
|
34
|
+
* Look up a CacheStrategy by provider name. Falls back to the
|
|
35
|
+
* wildcard NoOp strategy if no match.
|
|
36
|
+
*
|
|
37
|
+
* Lookup is case-insensitive on the provider name.
|
|
38
|
+
*/
|
|
39
|
+
function getDefaultCacheStrategy(providerName) {
|
|
40
|
+
const exact = REGISTRY.get(providerName);
|
|
41
|
+
if (exact !== undefined)
|
|
42
|
+
return exact;
|
|
43
|
+
const lower = providerName.toLowerCase();
|
|
44
|
+
if (lower !== providerName) {
|
|
45
|
+
const lowercased = REGISTRY.get(lower);
|
|
46
|
+
if (lowercased !== undefined)
|
|
47
|
+
return lowercased;
|
|
48
|
+
}
|
|
49
|
+
// Fallback wildcard always present
|
|
50
|
+
return REGISTRY.get('*');
|
|
51
|
+
}
|
|
52
|
+
exports.getDefaultCacheStrategy = getDefaultCacheStrategy;
|
|
53
|
+
/**
|
|
54
|
+
* Register (or replace) a strategy for a provider name. Called by
|
|
55
|
+
* strategy modules (v2.6 Phase 7+) at module load OR by consumers
|
|
56
|
+
* needing a custom backend. Replacing an existing strategy is allowed
|
|
57
|
+
* — the most-recent registration wins.
|
|
58
|
+
*/
|
|
59
|
+
function registerCacheStrategy(strategy) {
|
|
60
|
+
REGISTRY.set(strategy.providerName, strategy);
|
|
61
|
+
}
|
|
62
|
+
exports.registerCacheStrategy = registerCacheStrategy;
|
|
63
|
+
/**
|
|
64
|
+
* Read-only view of registered strategy names. Useful for diagnostics
|
|
65
|
+
* (e.g., logging "we have strategies for: anthropic, openai, *").
|
|
66
|
+
*/
|
|
67
|
+
function listRegisteredStrategies() {
|
|
68
|
+
return [...REGISTRY.keys()];
|
|
69
|
+
}
|
|
70
|
+
exports.listRegisteredStrategies = listRegisteredStrategies;
|
|
71
|
+
/**
|
|
72
|
+
* Internal helper for tests: reset the registry to the default
|
|
73
|
+
* (wildcard → NoOp only). Not exported from the public barrel.
|
|
74
|
+
*/
|
|
75
|
+
function _resetRegistryForTests() {
|
|
76
|
+
REGISTRY.clear();
|
|
77
|
+
REGISTRY.set('*', new NoOpCacheStrategy_js_1.NoOpCacheStrategy());
|
|
78
|
+
}
|
|
79
|
+
exports._resetRegistryForTests = _resetRegistryForTests;
|
|
80
|
+
//# sourceMappingURL=strategyRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategyRegistry.js","sourceRoot":"","sources":["../../src/cache/strategyRegistry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAGH,4EAAsE;AAEtE;;;;;;GAMG;AACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAwB,CAAC,CAAC,GAAG,EAAE,IAAI,wCAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;AAElF;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,YAAoB;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACzC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,KAAK,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IACzC,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,UAAU,KAAK,SAAS;YAAE,OAAO,UAAU,CAAC;IAClD,CAAC;IACD,mCAAmC;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;AAC5B,CAAC;AAVD,0DAUC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,QAAuB;IAC3D,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC;AAFD,sDAEC;AAED;;;GAGG;AACH,SAAgB,wBAAwB;IACtC,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAC9B,CAAC;AAFD,4DAEC;AAED;;;GAGG;AACH,SAAgB,sBAAsB;IACpC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,wCAAiB,EAAE,CAAC,CAAC;AAC7C,CAAC;AAHD,wDAGC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cache layer — public types.
|
|
4
|
+
*
|
|
5
|
+
* Three layers, each with one responsibility:
|
|
6
|
+
*
|
|
7
|
+
* 1. CONSUMER DSL — `CachePolicy` field on every injection factory.
|
|
8
|
+
* Declarative, like GraphQL schema input. Says WHAT should be
|
|
9
|
+
* cacheable. Examples: `cache: 'always'`, `cache: 'while-active'`.
|
|
10
|
+
*
|
|
11
|
+
* 2. AGNOSTIC MARKERS — `CacheMarker[]` produced by the
|
|
12
|
+
* `CacheDecision` subflow at runtime. Provider-independent
|
|
13
|
+
* identification of "cacheable prefix in field X up to index Y".
|
|
14
|
+
*
|
|
15
|
+
* 3. PROVIDER STRATEGY — one `CacheStrategy` implementation per
|
|
16
|
+
* provider (Anthropic / OpenAI / Bedrock / NoOp). Translates
|
|
17
|
+
* agnostic markers to provider-specific wire format AND extracts
|
|
18
|
+
* cache metrics from the provider's response.
|
|
19
|
+
*
|
|
20
|
+
* The interfaces are read-only / immutable by convention. Strategies
|
|
21
|
+
* MUST be stateless across runs; per-run state lives in the
|
|
22
|
+
* `CacheStrategyContext` passed into `prepareRequest`.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/cache/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
package/dist/conventions.js
CHANGED
|
@@ -31,6 +31,9 @@ exports.SUBFLOW_IDS = {
|
|
|
31
31
|
MERGE: 'sf-merge',
|
|
32
32
|
/** Final-answer composition inside Agent. */
|
|
33
33
|
FINAL: 'sf-final',
|
|
34
|
+
/** Cache decision subflow (v2.6). Walks activeInjections, emits
|
|
35
|
+
* agnostic CacheMarker[]. Provider-independent. */
|
|
36
|
+
CACHE_DECISION: 'sf-cache-decision',
|
|
34
37
|
};
|
|
35
38
|
/** Stage IDs — plain function stages that builders mount. */
|
|
36
39
|
exports.STAGE_IDS = {
|
|
@@ -40,6 +43,21 @@ exports.STAGE_IDS = {
|
|
|
40
43
|
FORMAT_MERGE: 'format-merge',
|
|
41
44
|
MERGE_LLM: 'merge-llm',
|
|
42
45
|
EXTRACT_MERGE: 'extract-merge',
|
|
46
|
+
/** Updates the rolling skill-history window before CacheGate
|
|
47
|
+
* evaluates skill-churn (v2.6). */
|
|
48
|
+
UPDATE_SKILL_HISTORY: 'update-skill-history',
|
|
49
|
+
/** CacheGate decider stage — routes to apply-markers / no-markers
|
|
50
|
+
* based on kill switch / hit rate / skill churn (v2.6). */
|
|
51
|
+
CACHE_GATE: 'cache-gate',
|
|
52
|
+
/** CacheGate branch (routing key) when markers SHOULD be applied
|
|
53
|
+
* this iteration. Pass-through stage; markers stay in scope. (v2.6) */
|
|
54
|
+
APPLY_MARKERS: 'apply-markers',
|
|
55
|
+
/** CacheGate branch (routing key) when markers should be SKIPPED
|
|
56
|
+
* this iteration. Stage clears scope.cacheMarkers. (v2.6) */
|
|
57
|
+
SKIP_CACHING: 'no-markers',
|
|
58
|
+
/** BuildLLMRequest stage — calls strategy.prepareRequest to apply
|
|
59
|
+
* markers to the wire request (v2.6). */
|
|
60
|
+
BUILD_LLM_REQUEST: 'build-llm-request',
|
|
43
61
|
};
|
|
44
62
|
// ─── Type guards ─────────────────────────────────────────────────────
|
|
45
63
|
/** True when a subflow id corresponds to one of the 3 context slots. */
|
package/dist/conventions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conventions.js","sourceRoot":"","sources":["../src/conventions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAIH,gEAAgE;AACnD,QAAA,WAAW,GAAG;IACzB;0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