Skip to content

Commit 2e23a09

Browse files
committed
fix(webapp): keep the other Anthropic options when the step breakpoint rolls off
1 parent 49a1504 commit 2e23a09

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

internal-packages/dashboard-agent/src/step-cache.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ function turnHistory(): Message {
2626
};
2727
}
2828

29+
function stepBreakpointWith(otherAnthropicOptions: Record<string, unknown>): Message {
30+
return {
31+
role: "tool",
32+
content: "ok",
33+
providerOptions: {
34+
anthropic: { cacheControl: STEP_CACHE_CONTROL, ...otherAnthropicOptions },
35+
openai: { store: false },
36+
},
37+
};
38+
}
39+
2940
function ttlOf(message: Message | undefined): unknown {
3041
return (message?.providerOptions?.anthropic as { cacheControl?: { ttl?: unknown } } | undefined)
3142
?.cacheControl?.ttl;
@@ -73,6 +84,28 @@ describe("the step cache breakpoint", () => {
7384
expect(compacted.filter((message) => ttlOf(message) === "5m")).toHaveLength(0);
7485
});
7586

87+
it("keeps the other anthropic options when it rolls the breakpoint off", () => {
88+
const marked = markStepCacheBreakpoint([
89+
stepBreakpointWith({ anotherOption: "keep" }),
90+
toolResult(MIN_STEP_CACHE_CHARS),
91+
]);
92+
93+
expect(marked[0]!.providerOptions).toEqual({
94+
anthropic: { anotherOption: "keep" },
95+
openai: { store: false },
96+
});
97+
expect(ttlOf(marked.at(-1))).toBe("5m");
98+
});
99+
100+
it("leaves no empty anthropic object behind", () => {
101+
const marked = markStepCacheBreakpoint([
102+
stepBreakpointWith({}),
103+
toolResult(MIN_STEP_CACHE_CHARS),
104+
]);
105+
106+
expect(marked[0]!.providerOptions).toEqual({ openai: { store: false } });
107+
});
108+
76109
it("does nothing to an empty step", () => {
77110
const empty: Message[] = [];
78111
expect(markStepCacheBreakpoint(empty)).toBe(empty);

internal-packages/dashboard-agent/src/step-cache.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ function cacheControlTtl(message: MaybeCached): string | undefined {
3232

3333
function withoutStepBreakpoint<T extends MaybeCached>(message: T): T {
3434
if (cacheControlTtl(message) !== STEP_CACHE_CONTROL.ttl) return message;
35-
const { anthropic: _dropped, ...rest } = message.providerOptions as Record<string, unknown>;
36-
return { ...message, providerOptions: rest };
35+
const { anthropic, ...rest } = message.providerOptions as Record<string, unknown>;
36+
const { cacheControl: _dropped, ...anthropicRest } = anthropic as Record<string, unknown>;
37+
// An empty `anthropic` is not the same as no Anthropic options, so drop the key.
38+
const providerOptions =
39+
Object.keys(anthropicRest).length > 0 ? { ...rest, anthropic: anthropicRest } : rest;
40+
return { ...message, providerOptions };
3741
}
3842

3943
// Only ever one step breakpoint at a time: Anthropic allows four in total, and the

0 commit comments

Comments
 (0)