feat(agents) : Hugging Face Inference provider first-class support and Together API fix and Direct Injection Refactor Auths [AI-assisted] (#13472)

* initial commit

* removes assesment from docs

* resolves automated review comments

* resolves lint , type , tests , refactors , and submits

* solves : why do we have to lint the tests xD

* adds greptile fixes

* solves a type error

* solves a ci error

* refactors auths

* solves a failing test after i pulled from main lol

* solves a failing test after i pulled from main lol

* resolves token naming issue to comply with better practices when using hf / huggingface

* fixes curly lints !

* fixes failing tests for google api from main

* solve merge conflicts

* solve failing tests with a defensive check 'undefined' openrouterapi key

* fix: preserve Hugging Face auth-choice intent and token behavior (#13472) (thanks @Josephrp)

* test: resolve auth-choice cherry-pick conflict cleanup (#13472)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
Tonic
2026-02-13 16:18:16 +01:00
committed by GitHub
parent e50ce897b0
commit 08b7932df0
27 changed files with 1617 additions and 355 deletions

View File

@@ -532,4 +532,79 @@ describe("getApiKeyForModel", () => {
}
}
});
it("resolveEnvApiKey('huggingface') returns HUGGINGFACE_HUB_TOKEN when set", async () => {
const prevHub = process.env.HUGGINGFACE_HUB_TOKEN;
const prevHf = process.env.HF_TOKEN;
try {
delete process.env.HF_TOKEN;
process.env.HUGGINGFACE_HUB_TOKEN = "hf_hub_xyz";
vi.resetModules();
const { resolveEnvApiKey } = await import("./model-auth.js");
const resolved = resolveEnvApiKey("huggingface");
expect(resolved?.apiKey).toBe("hf_hub_xyz");
expect(resolved?.source).toContain("HUGGINGFACE_HUB_TOKEN");
} finally {
if (prevHub === undefined) {
delete process.env.HUGGINGFACE_HUB_TOKEN;
} else {
process.env.HUGGINGFACE_HUB_TOKEN = prevHub;
}
if (prevHf === undefined) {
delete process.env.HF_TOKEN;
} else {
process.env.HF_TOKEN = prevHf;
}
}
});
it("resolveEnvApiKey('huggingface') prefers HUGGINGFACE_HUB_TOKEN over HF_TOKEN when both set", async () => {
const prevHub = process.env.HUGGINGFACE_HUB_TOKEN;
const prevHf = process.env.HF_TOKEN;
try {
process.env.HUGGINGFACE_HUB_TOKEN = "hf_hub_first";
process.env.HF_TOKEN = "hf_second";
vi.resetModules();
const { resolveEnvApiKey } = await import("./model-auth.js");
const resolved = resolveEnvApiKey("huggingface");
expect(resolved?.apiKey).toBe("hf_hub_first");
expect(resolved?.source).toContain("HUGGINGFACE_HUB_TOKEN");
} finally {
if (prevHub === undefined) {
delete process.env.HUGGINGFACE_HUB_TOKEN;
} else {
process.env.HUGGINGFACE_HUB_TOKEN = prevHub;
}
if (prevHf === undefined) {
delete process.env.HF_TOKEN;
} else {
process.env.HF_TOKEN = prevHf;
}
}
});
it("resolveEnvApiKey('huggingface') returns HF_TOKEN when only HF_TOKEN set", async () => {
const prevHub = process.env.HUGGINGFACE_HUB_TOKEN;
const prevHf = process.env.HF_TOKEN;
try {
delete process.env.HUGGINGFACE_HUB_TOKEN;
process.env.HF_TOKEN = "hf_abc123";
vi.resetModules();
const { resolveEnvApiKey } = await import("./model-auth.js");
const resolved = resolveEnvApiKey("huggingface");
expect(resolved?.apiKey).toBe("hf_abc123");
expect(resolved?.source).toContain("HF_TOKEN");
} finally {
if (prevHub === undefined) {
delete process.env.HUGGINGFACE_HUB_TOKEN;
} else {
process.env.HUGGINGFACE_HUB_TOKEN = prevHub;
}
if (prevHf === undefined) {
delete process.env.HF_TOKEN;
} else {
process.env.HF_TOKEN = prevHf;
}
}
});
});