| import type { StreamFn } from "@mariozechner/pi-agent-core"; |
| import { describe, expect, it, vi } from "vitest"; |
| import { applyExtraParamsToAgent } from "../pi-embedded-runner.js"; |
|
|
| |
| vi.mock("./logger.js", () => ({ |
| log: { |
| debug: vi.fn(), |
| warn: vi.fn(), |
| }, |
| })); |
|
|
| describe("cacheRetention default behavior", () => { |
| it("returns 'short' for Anthropic when not configured", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = undefined; |
| const provider = "anthropic"; |
| const modelId = "claude-3-sonnet"; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId); |
|
|
| |
| expect(agent.streamFn).toBeDefined(); |
|
|
| |
| |
| |
| }); |
|
|
| it("respects explicit 'none' config", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = { |
| agents: { |
| defaults: { |
| models: { |
| "anthropic/claude-3-sonnet": { |
| params: { |
| cacheRetention: "none" as const, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }; |
| const provider = "anthropic"; |
| const modelId = "claude-3-sonnet"; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId); |
|
|
| |
| expect(agent.streamFn).toBeDefined(); |
| }); |
|
|
| it("respects explicit 'long' config", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = { |
| agents: { |
| defaults: { |
| models: { |
| "anthropic/claude-3-opus": { |
| params: { |
| cacheRetention: "long" as const, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }; |
| const provider = "anthropic"; |
| const modelId = "claude-3-opus"; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId); |
|
|
| |
| expect(agent.streamFn).toBeDefined(); |
| }); |
|
|
| it("respects legacy cacheControlTtl config", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = { |
| agents: { |
| defaults: { |
| models: { |
| "anthropic/claude-3-haiku": { |
| params: { |
| cacheControlTtl: "1h", |
| }, |
| }, |
| }, |
| }, |
| }, |
| }; |
| const provider = "anthropic"; |
| const modelId = "claude-3-haiku"; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId); |
|
|
| |
| expect(agent.streamFn).toBeDefined(); |
| }); |
|
|
| it("returns undefined for non-Anthropic providers", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = undefined; |
| const provider = "openai"; |
| const modelId = "gpt-4"; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId); |
|
|
| |
| |
| |
| }); |
|
|
| it("prefers explicit cacheRetention over default", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = { |
| agents: { |
| defaults: { |
| models: { |
| "anthropic/claude-3-sonnet": { |
| params: { |
| cacheRetention: "long" as const, |
| temperature: 0.7, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }; |
| const provider = "anthropic"; |
| const modelId = "claude-3-sonnet"; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId); |
|
|
| |
| expect(agent.streamFn).toBeDefined(); |
| }); |
|
|
| it("works with extraParamsOverride", () => { |
| const agent: { streamFn?: StreamFn } = {}; |
| const cfg = undefined; |
| const provider = "anthropic"; |
| const modelId = "claude-3-sonnet"; |
| const extraParamsOverride = { |
| cacheRetention: "none" as const, |
| }; |
|
|
| applyExtraParamsToAgent(agent, cfg, provider, modelId, extraParamsOverride); |
|
|
| |
| expect(agent.streamFn).toBeDefined(); |
| }); |
| }); |
|
|