mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 09:22:45 +00:00
feat(agents): support Anthropic 1M context beta header
This commit is contained in:
@@ -112,6 +112,122 @@ describe("applyExtraParamsToAgent", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("adds Anthropic 1M beta header when context1m is enabled for Opus/Sonnet", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-opus-4-6": {
|
||||
params: {
|
||||
context1m: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg, "anthropic", "claude-opus-4-6");
|
||||
|
||||
const model = {
|
||||
api: "anthropic-messages",
|
||||
provider: "anthropic",
|
||||
id: "claude-opus-4-6",
|
||||
} as Model<"anthropic-messages">;
|
||||
const context: Context = { messages: [] };
|
||||
|
||||
void agent.streamFn?.(model, context, { headers: { "X-Custom": "1" } });
|
||||
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0]?.headers).toEqual({
|
||||
"X-Custom": "1",
|
||||
"anthropic-beta": "context-1m-2025-08-07",
|
||||
});
|
||||
});
|
||||
|
||||
it("merges existing anthropic-beta headers with configured betas", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-sonnet-4-5": {
|
||||
params: {
|
||||
context1m: true,
|
||||
anthropicBeta: ["files-api-2025-04-14"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg, "anthropic", "claude-sonnet-4-5");
|
||||
|
||||
const model = {
|
||||
api: "anthropic-messages",
|
||||
provider: "anthropic",
|
||||
id: "claude-sonnet-4-5",
|
||||
} as Model<"anthropic-messages">;
|
||||
const context: Context = { messages: [] };
|
||||
|
||||
void agent.streamFn?.(model, context, {
|
||||
headers: { "anthropic-beta": "prompt-caching-2024-07-31" },
|
||||
});
|
||||
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0]?.headers).toEqual({
|
||||
"anthropic-beta": "prompt-caching-2024-07-31,files-api-2025-04-14,context-1m-2025-08-07",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores context1m for non-Opus/Sonnet Anthropic models", () => {
|
||||
const calls: Array<SimpleStreamOptions | undefined> = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
calls.push(options);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-haiku-3-5": {
|
||||
params: {
|
||||
context1m: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg, "anthropic", "claude-haiku-3-5");
|
||||
|
||||
const model = {
|
||||
api: "anthropic-messages",
|
||||
provider: "anthropic",
|
||||
id: "claude-haiku-3-5",
|
||||
} as Model<"anthropic-messages">;
|
||||
const context: Context = { messages: [] };
|
||||
|
||||
void agent.streamFn?.(model, context, { headers: { "X-Custom": "1" } });
|
||||
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0]?.headers).toEqual({ "X-Custom": "1" });
|
||||
});
|
||||
|
||||
it("forces store=true for direct OpenAI Responses payloads", () => {
|
||||
const payload = runStoreMutationCase({
|
||||
applyProvider: "openai",
|
||||
|
||||
Reference in New Issue
Block a user