-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(hermes): add provider onboarding foundation #3237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
shannonsands
wants to merge
8
commits into
NVIDIA:main
from
NousResearch:ns322/hermes-provider-foundation
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8e63bf1
feat(hermes): add provider onboarding foundation
shannonsands 1b68049
feat(hermes): refine provider onboarding foundation
shannonsands c4c50e6
fix(hermes): collect slack allowed member ids
shannonsands 8a4aa5e
fix(hermes): use host auth state for rebuild
shannonsands 931a798
test(hermes): cover recovered dashboard ports
shannonsands a11efe4
fix(hermes): use modular provider auth imports
shannonsands 537875d
refactor(hermes): defer port recovery changes
shannonsands 8ebe6c7
feat(hermes): load recommended provider models dynamically
shannonsands File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { createRequire } from "node:module"; | ||
|
|
||
| import { afterEach, describe, expect, it } from "vitest"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const DIST_AUTH = path.join( | ||
| import.meta.dirname, | ||
| "..", | ||
| "..", | ||
| "dist", | ||
| "lib", | ||
| "hermes-provider-auth.js", | ||
| ); | ||
| const DIST_CREDS = path.join( | ||
| import.meta.dirname, | ||
| "..", | ||
| "..", | ||
| "dist", | ||
| "lib", | ||
| "credentials.js", | ||
| ); | ||
|
|
||
| function clearDistModule(modulePath: string): void { | ||
| try { | ||
| delete require.cache[require.resolve(modulePath)]; | ||
| } catch { | ||
| // not loaded | ||
| } | ||
| } | ||
|
|
||
| function loadAuthForHome(home: string): Record<string, any> { | ||
| process.env.HOME = home; | ||
| clearDistModule(DIST_AUTH); | ||
| clearDistModule(DIST_CREDS); | ||
| return require(DIST_AUTH); | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| clearDistModule(DIST_AUTH); | ||
| clearDistModule(DIST_CREDS); | ||
| }); | ||
|
|
||
| describe("Hermes provider host auth", () => { | ||
| it("persists API-key inference state with private permissions and registers OpenShell provider", async () => { | ||
| const originalHome = process.env.HOME; | ||
| const tmp = fs.mkdtempSync( | ||
| path.join(os.tmpdir(), "nemoclaw-hermes-api-key-"), | ||
| ); | ||
| try { | ||
| const auth = loadAuthForHome(tmp); | ||
| const calls: Array<{ args: string[]; env?: Record<string, string> }> = []; | ||
| const state = await auth.ensureHermesProviderApiKeyCredentials( | ||
| "my-assistant", | ||
| { | ||
| apiKey: "nous-key-1", | ||
| runOpenshell: ( | ||
| args: string[], | ||
| opts: { env?: Record<string, string> } = {}, | ||
| ) => { | ||
| calls.push({ args, env: opts.env }); | ||
| if (args[0] === "provider" && args[1] === "get") { | ||
| return { status: 1, stdout: "", stderr: "" }; | ||
| } | ||
| return { status: 0, stdout: "", stderr: "" }; | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(state.auth_method).toBe("api_key"); | ||
| const statePath = auth.getHermesOAuthStatePath("my-assistant"); | ||
| expect(fs.statSync(path.dirname(statePath)).mode & 0o777).toBe(0o700); | ||
| expect(fs.statSync(statePath).mode & 0o777).toBe(0o600); | ||
| expect(JSON.parse(fs.readFileSync(statePath, "utf8")).api_key).toBe( | ||
| "nous-key-1", | ||
| ); | ||
| expect(calls.some((call) => call.args.includes("hermes-provider"))).toBe( | ||
| true, | ||
| ); | ||
| expect(calls.some((call) => call.args.includes("NOUS_API_KEY"))).toBe( | ||
| true, | ||
| ); | ||
| expect( | ||
| calls.some((call) => call.env?.NOUS_API_KEY === "nous-key-1"), | ||
| ).toBe(true); | ||
| } finally { | ||
| if (originalHome === undefined) delete process.env.HOME; | ||
| else process.env.HOME = originalHome; | ||
| fs.rmSync(tmp, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("refreshes OAuth state and mints an inference agent key", async () => { | ||
| const originalHome = process.env.HOME; | ||
| const tmp = fs.mkdtempSync( | ||
| path.join(os.tmpdir(), "nemoclaw-hermes-oauth-"), | ||
| ); | ||
| try { | ||
| const auth = loadAuthForHome(tmp); | ||
| auth.persistHermesOAuthState("my-assistant", { | ||
| auth_method: "oauth", | ||
| access_token: "old-access", | ||
| refresh_token: "refresh-1", | ||
| expires_at: "2000-01-01T00:00:00.000Z", | ||
| }); | ||
| const calls: Array<{ url: string; auth: string | null; body: string }> = | ||
| []; | ||
| const state = await auth.ensureHermesProviderOAuthCredentials( | ||
| "my-assistant", | ||
| { | ||
| allowInteractiveLogin: false, | ||
| fetch: (async (url, init) => { | ||
| const headers = new Headers(init?.headers); | ||
| calls.push({ | ||
| url: String(url), | ||
| auth: headers.get("authorization"), | ||
| body: String(init?.body ?? ""), | ||
| }); | ||
| if (String(url).endsWith("/api/oauth/token")) { | ||
| return new Response( | ||
| JSON.stringify({ | ||
| access_token: "access-2", | ||
| refresh_token: "refresh-2", | ||
| expires_in: 900, | ||
| token_type: "Bearer", | ||
| }), | ||
| { | ||
| status: 200, | ||
| headers: { "Content-Type": "application/json" }, | ||
| }, | ||
| ); | ||
| } | ||
| return new Response( | ||
| JSON.stringify({ | ||
| api_key: "agent-key-1", | ||
| key_id: "agent-key-id", | ||
| expires_in: 1800, | ||
| }), | ||
| { status: 200, headers: { "Content-Type": "application/json" } }, | ||
| ); | ||
| }) as typeof fetch, | ||
| runOpenshell: ( | ||
| args: string[], | ||
| opts: { env?: Record<string, string> } = {}, | ||
| ) => { | ||
| if (args[0] === "provider" && args[1] === "get") { | ||
| return { status: 1, stdout: "", stderr: "" }; | ||
| } | ||
| expect(opts.env?.OPENAI_API_KEY).toBe("agent-key-1"); | ||
| return { status: 0, stdout: "", stderr: "" }; | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(state.refresh_token).toBe("refresh-2"); | ||
| expect(state.agent_key).toBe("agent-key-1"); | ||
| expect(calls[0]?.body).toContain("refresh_token=refresh-1"); | ||
| expect(calls[1]?.auth).toBe("Bearer access-2"); | ||
| } finally { | ||
| if (originalHome === undefined) delete process.env.HOME; | ||
| else process.env.HOME = originalHome; | ||
| fs.rmSync(tmp, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't infer OAuth when
NOUS_API_KEYis the only recovery material.When
session?.hermesAuthMethodandstate?.auth_methodare missing, this falls back to OAuth unlesscredentialEnvequals the Hermes API-key env. For Hermes rebuilds that value comes from the registry path and isOPENAI_API_KEY, so an exportedNOUS_API_KEYis ignored and preflight fails even though the error text tells users to use it.Suggested fix
function preflightHermesProviderCredentials( sandboxName: string, session: Session | null, credentialEnv: string | null, log: (msg: string) => void, ): boolean { const state = hermesProviderAuth.loadHermesOAuthState(sandboxName); + const envKey = hydrateCredentialEnv(hermesProviderAuth.HERMES_NOUS_API_KEY_CREDENTIAL_ENV); const authMethod = normalizeHermesRebuildAuthMethod(session?.hermesAuthMethod) || normalizeHermesRebuildAuthMethod(state?.auth_method) || + (envKey ? "api_key" : null) || (credentialEnv === hermesProviderAuth.HERMES_NOUS_API_KEY_CREDENTIAL_ENV ? "api_key" : "oauth"); if (authMethod === "api_key") { const hostStateKey = nonEmptyString(state?.api_key) || nonEmptyString(state?.access_token); - const envKey = hydrateCredentialEnv(hermesProviderAuth.HERMES_NOUS_API_KEY_CREDENTIAL_ENV); log( `Hermes Provider rebuild preflight: api_key state=${hostStateKey ? "present" : "missing"} env=${envKey ? "present" : "missing"}`, );📝 Committable suggestion
🤖 Prompt for AI Agents