workspace out of cache; welcome.md

This commit is contained in:
2026-04-13 22:24:12 -04:00
parent 45a21ac933
commit dacfa9c1a3
5 changed files with 70 additions and 44 deletions

View File

@@ -42,13 +42,14 @@ export class AnthropicCachingMiddleware implements ModelMiddleware {
addCacheControl(systemMsg);
}
// 2. Tag the last cacheable message that isn't the current user input.
// The current user message is always the last element; we want the one before it.
// We look backwards for the last AIMessage or HumanMessage (excluding the final message).
// 2. Tag the last AIMessage (assistant turn) before the current user input.
// Workspace state is injected as a HumanMessage just before the current user input;
// by matching only 'ai' we ensure the cache boundary is the last assistant response,
// leaving workspace context and the new user input uncached (always fresh).
const candidates = result.slice(0, -1);
for (let i = candidates.length - 1; i >= 0; i--) {
const t = candidates[i]._getType();
if (t === 'ai' || t === 'human') {
if (t === 'ai') {
addCacheControl(candidates[i]);
break;
}