Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

test(sdk): give the Vercel withHeadroom fixtures a LanguageModelV3 result (#3949)

Shubham Srivastava265148974593
diff --git a/sdk/typescript/test/adapters/vercel-ai.test.ts b/sdk/typescript/test/adapters/vercel-ai.test.ts
index cc4ab6e98..82959a346 100644
--- a/sdk/typescript/test/adapters/vercel-ai.test.ts
+++ b/sdk/typescript/test/adapters/vercel-ai.test.ts
@@ -1,4 +1,5 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
+import type { LanguageModelV3 } from "@ai-sdk/provider";
import {
headroomMiddleware,
compressVercelMessages,
@@ -240,12 +241,17 @@ describe("withHeadroom", () => {
provider: "test-provider",
modelId: "test-model",
supportedUrls: {},
+ // A real LanguageModelV3 result (type-checked below): `ai` >= 7.0.119 wraps v3 models
+ // in a v4 adapter that maps over `content` and forwards the rest unchanged.
doGenerate: vi.fn().mockResolvedValue({
- text: "response",
- usage: { promptTokens: 10, completionTokens: 5 },
- finishReason: "stop",
- rawCall: { rawPrompt: null, rawSettings: {} },
- }),
+ content: [{ type: "text", text: "response" }],
+ finishReason: { unified: "stop", raw: "stop" },
+ usage: {
+ inputTokens: { total: 10, noCache: 10, cacheRead: undefined, cacheWrite: undefined },
+ outputTokens: { total: 5, text: 5, reasoning: undefined },
+ },
+ warnings: [],
+ } satisfies Awaited<ReturnType<LanguageModelV3["doGenerate"]>>),
doStream: vi.fn(),
};
@@ -277,12 +283,17 @@ describe("withHeadroom", () => {
provider: "test",
modelId: "test-model",
supportedUrls: {},
+ // A real LanguageModelV3 result (type-checked below): `ai` >= 7.0.119 wraps v3 models
+ // in a v4 adapter that maps over `content` and forwards the rest unchanged.
doGenerate: vi.fn().mockResolvedValue({
- text: "ok",
- usage: { promptTokens: 5, completionTokens: 3 },
- finishReason: "stop",
- rawCall: { rawPrompt: null, rawSettings: {} },
- }),
+ content: [{ type: "text", text: "ok" }],
+ finishReason: { unified: "stop", raw: "stop" },
+ usage: {
+ inputTokens: { total: 5, noCache: 5, cacheRead: undefined, cacheWrite: undefined },
+ outputTokens: { total: 3, text: 3, reasoning: undefined },
+ },
+ warnings: [],
+ } satisfies Awaited<ReturnType<LanguageModelV3["doGenerate"]>>),
doStream: vi.fn(),
};
@@ -311,12 +322,17 @@ describe("withHeadroom", () => {
provider: "test",
modelId: "test-model",
supportedUrls: {},
+ // A real LanguageModelV3 result (type-checked below): `ai` >= 7.0.119 wraps v3 models
+ // in a v4 adapter that maps over `content` and forwards the rest unchanged.
doGenerate: vi.fn().mockResolvedValue({
- text: "ok",
- usage: { promptTokens: 5, completionTokens: 3 },
- finishReason: "stop",
- rawCall: { rawPrompt: null, rawSettings: {} },
- }),
+ content: [{ type: "text", text: "ok" }],
+ finishReason: { unified: "stop", raw: "stop" },
+ usage: {
+ inputTokens: { total: 5, noCache: 5, cacheRead: undefined, cacheWrite: undefined },
+ outputTokens: { total: 3, text: 3, reasoning: undefined },
+ },
+ warnings: [],
+ } satisfies Awaited<ReturnType<LanguageModelV3["doGenerate"]>>),
doStream: vi.fn(),
};
diff --git a/sdk/typescript/tsconfig.typecheck.json b/sdk/typescript/tsconfig.typecheck.json
index 599f44738..04a811943 100644
--- a/sdk/typescript/tsconfig.typecheck.json
+++ b/sdk/typescript/tsconfig.typecheck.json
@@ -4,6 +4,6 @@
"rootDir": ".",
"noEmit": true
},
- "include": ["src", "test/**/*.test-d.ts"],
+ "include": ["src", "test/**/*.test-d.ts", "test/adapters/vercel-ai.test.ts"],
"exclude": ["node_modules", "dist"]
}