c12be01a5f
packages/ai: - fix: hardened OpenAI tool-call JSON parsing for malformed trailing arguments - feat: routed GitHub Copilot Claude 4.x models through anthropic-messages - feat: centralized dynamic Copilot headers and anthropic bearer auth handling - feat: added optional StreamOptions.metadata propagation - test: added Copilot headers/auth/routing coverage - fix: updated model generator and models.json for Copilot Claude API mapping packages/coding-agent: - fix: made CLI model resolution deterministic with provider-aware pattern parsing - fix: corrected compaction boundary/context usage handling after compaction - feat: expanded extension events and terminal input hook integration - fix: hardened git source parsing to avoid local-path misclassification - test: added git-url parser coverage and model-resolver cases packages/tui: - fix: scoped @ fuzzy autocomplete to typed path prefixes - feat: added Windows VT input mode support via bun:ffi docs: - chore: updated porting sync point to 5133697
121 lines
3.3 KiB
TypeScript
121 lines
3.3 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { buildAnthropicClientOptions } from "../src/providers/anthropic";
|
|
import type { Model } from "../src/types";
|
|
|
|
const COPILOT_HEADERS = {
|
|
"User-Agent": "GitHubCopilotChat/0.35.0",
|
|
"Editor-Version": "vscode/1.107.0",
|
|
"Editor-Plugin-Version": "copilot-chat/0.35.0",
|
|
"Copilot-Integration-Id": "vscode-chat",
|
|
};
|
|
|
|
function makeCopilotClaudeModel(): Model<"anthropic-messages"> {
|
|
return {
|
|
id: "claude-sonnet-4",
|
|
name: "Claude Sonnet 4",
|
|
api: "anthropic-messages",
|
|
provider: "github-copilot",
|
|
baseUrl: "https://api.individual.githubcopilot.com",
|
|
headers: { ...COPILOT_HEADERS },
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 128000,
|
|
maxTokens: 16000,
|
|
};
|
|
}
|
|
|
|
describe("Anthropic Copilot auth config", () => {
|
|
it("uses apiKey: null and Authorization Bearer for Copilot models", () => {
|
|
const model = makeCopilotClaudeModel();
|
|
const token = "ghu_test_token_12345";
|
|
const options = buildAnthropicClientOptions({
|
|
model,
|
|
apiKey: token,
|
|
extraBetas: ["interleaved-thinking-2025-05-14"],
|
|
stream: true,
|
|
dynamicHeaders: {
|
|
"X-Initiator": "user",
|
|
"Openai-Intent": "conversation-edits",
|
|
},
|
|
});
|
|
|
|
expect(options.apiKey).toBeNull();
|
|
expect(options.defaultHeaders.Authorization).toBe(`Bearer ${token}`);
|
|
});
|
|
|
|
it("includes Copilot static headers from model.headers", () => {
|
|
const model = makeCopilotClaudeModel();
|
|
const options = buildAnthropicClientOptions({
|
|
model,
|
|
apiKey: "ghu_test",
|
|
extraBetas: [],
|
|
stream: true,
|
|
dynamicHeaders: {},
|
|
});
|
|
|
|
expect(options.defaultHeaders["User-Agent"]).toContain("GitHubCopilotChat");
|
|
expect(options.defaultHeaders["Copilot-Integration-Id"]).toBe("vscode-chat");
|
|
});
|
|
|
|
it("includes interleaved-thinking beta header when enabled", () => {
|
|
const model = makeCopilotClaudeModel();
|
|
const options = buildAnthropicClientOptions({
|
|
model,
|
|
apiKey: "ghu_test",
|
|
extraBetas: ["interleaved-thinking-2025-05-14"],
|
|
stream: true,
|
|
dynamicHeaders: {},
|
|
});
|
|
|
|
const beta = options.defaultHeaders["anthropic-beta"];
|
|
expect(beta).toBeDefined();
|
|
expect(beta).toContain("interleaved-thinking-2025-05-14");
|
|
});
|
|
|
|
it("does not include interleaved-thinking beta when disabled", () => {
|
|
const model = makeCopilotClaudeModel();
|
|
const options = buildAnthropicClientOptions({
|
|
model,
|
|
apiKey: "ghu_test",
|
|
extraBetas: [],
|
|
stream: true,
|
|
dynamicHeaders: {},
|
|
});
|
|
|
|
const beta = options.defaultHeaders["anthropic-beta"];
|
|
if (beta) {
|
|
expect(beta).not.toContain("interleaved-thinking-2025-05-14");
|
|
}
|
|
});
|
|
|
|
it("does not include fine-grained-tool-streaming beta for Copilot", () => {
|
|
const model = makeCopilotClaudeModel();
|
|
const options = buildAnthropicClientOptions({
|
|
model,
|
|
apiKey: "ghu_test",
|
|
extraBetas: ["interleaved-thinking-2025-05-14"],
|
|
stream: true,
|
|
dynamicHeaders: {},
|
|
});
|
|
|
|
const beta = options.defaultHeaders["anthropic-beta"];
|
|
if (beta) {
|
|
expect(beta).not.toContain("fine-grained-tool-streaming");
|
|
}
|
|
});
|
|
|
|
it("does not set isOAuthToken for Copilot models", () => {
|
|
const model = makeCopilotClaudeModel();
|
|
const result = buildAnthropicClientOptions({
|
|
model,
|
|
apiKey: "ghu_test",
|
|
extraBetas: [],
|
|
stream: true,
|
|
dynamicHeaders: {},
|
|
});
|
|
|
|
expect(result.isOAuthToken).toBe(false);
|
|
});
|
|
});
|