Skip to content

Commit d52c224

Browse files
committed
fix(dashboard-agent): merge the step breakpoint into the message's anthropic options
Setting the breakpoint replaced the whole `anthropic` provider-options object on the last message, dropping any other Anthropic option it carried.
1 parent afc0cfa commit d52c224

2 files changed

Lines changed: 41 additions & 1 deletion

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
@@ -97,6 +97,21 @@ describe("the step cache breakpoint", () => {
9797
expect(ttlOf(marked.at(-1))).toBe("5m");
9898
});
9999

100+
it("keeps the marked message's other anthropic options when it sets the breakpoint", () => {
101+
const marked = markStepCacheBreakpoint([
102+
turnHistory(),
103+
{
104+
...toolResult(MIN_STEP_CACHE_CHARS),
105+
providerOptions: { anthropic: { anotherOption: "keep" }, openai: { store: false } },
106+
},
107+
]);
108+
109+
expect(marked.at(-1)!.providerOptions).toEqual({
110+
anthropic: { anotherOption: "keep", cacheControl: STEP_CACHE_CONTROL },
111+
openai: { store: false },
112+
});
113+
});
114+
100115
it("leaves no empty anthropic object behind", () => {
101116
const marked = markStepCacheBreakpoint([
102117
stepBreakpointWith({}),
@@ -133,6 +148,24 @@ describe("wrapping the SDK's prepareStep", () => {
133148
expect(ttlOf(prepared!.messages!.at(-1) as Message)).toBe("5m");
134149
});
135150

151+
it("keeps the last message's other anthropic options", async () => {
152+
const inner = () => ({
153+
messages: [
154+
turnHistory(),
155+
{
156+
...toolResult(MIN_STEP_CACHE_CHARS),
157+
providerOptions: { anthropic: { anotherOption: "keep" } },
158+
},
159+
],
160+
});
161+
162+
const prepared = await withStepCacheBreakpoint(inner as never)({ messages: [] } as never);
163+
164+
expect((prepared!.messages!.at(-1) as Message).providerOptions).toEqual({
165+
anthropic: { anotherOption: "keep", cacheControl: STEP_CACHE_CONTROL },
166+
});
167+
});
168+
136169
it("keeps the rest of the inner result", async () => {
137170
const inner = () => ({ toolChoice: "none", messages: [turnHistory()] });
138171
const prepared = (await withStepCacheBreakpoint(inner as never)({

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ function cacheControlTtl(message: MaybeCached): string | undefined {
3030
return typeof ttl === "string" ? ttl : undefined;
3131
}
3232

33+
function anthropicOptions(message: MaybeCached): Record<string, unknown> {
34+
const anthropic = message.providerOptions?.anthropic;
35+
return typeof anthropic === "object" && anthropic !== null
36+
? (anthropic as Record<string, unknown>)
37+
: {};
38+
}
39+
3340
function withoutStepBreakpoint<T extends MaybeCached>(message: T): T {
3441
if (cacheControlTtl(message) !== STEP_CACHE_CONTROL.ttl) return message;
3542
const { anthropic, ...rest } = message.providerOptions as Record<string, unknown>;
@@ -63,7 +70,7 @@ export function markStepCacheBreakpoint<T extends MaybeCached>(messages: T[]): T
6370
...last,
6471
providerOptions: {
6572
...last.providerOptions,
66-
anthropic: { cacheControl: STEP_CACHE_CONTROL },
73+
anthropic: { ...anthropicOptions(last), cacheControl: STEP_CACHE_CONTROL },
6774
},
6875
},
6976
];

0 commit comments

Comments
 (0)