UNPKG

@sellable/install

Version:

One-command installer for Sellable MCP in Claude Code, Codex, and Hermes

202 lines (189 loc) • 6.48 kB
// Plan sign-ins a machine can have besides its Codex and OpenRouter keys: // Google Antigravity (agy, Gemini 4 Neon) and Claude Code (Opus 5.5). Owner, // 2026-12-02: "get claucde code and agy working on cuostmer machiens too and // make it configuraboule for both admina nd csutoemr machiens". // // A sign-in is made by staff on one machine (`sellable-model-signin`), with the // provider's own program and its own sign-in flow. Nothing here writes, copies // or sends a token. A machine without a sign-in is unchanged, so customers' // machines keep Codex and OpenRouter. Sign in only Sellable's own machines: an // agent can run commands on its machine, so whoever uses that agent could read // the sign-in. import { accessSync, constants, lstatSync, readFileSync, rmSync, statSync, symlinkSync, } from "node:fs"; import { join } from "node:path"; export const CLAUDE_SIGNIN_PROVIDER = "claude-subscription-directsdk-experimental"; export const CLAUDE_SIGNIN_MODEL = "claude-opus-5-5"; export const ANTIGRAVITY_SIGNIN_PROVIDER = "antigravity-subscription-directsdk"; export const ANTIGRAVITY_SIGNIN_MODEL = "gemini-4-neon"; export const MODEL_PROVIDER_PLUGINS_ROOT = "/opt/hermes/plugins/model-providers"; /** Where a customer image keeps the add-ons: Hermes never looks here. */ export const MODEL_PROVIDER_SHELF_ROOT = "/usr/local/lib/sellable-agent/model-providers"; // Each turn starts the program and thinks, so these legs get a longer ceiling // than the HTTP providers' 60 seconds. export const MODEL_SIGNIN_REQUEST_TIMEOUT_SECONDS = 180; const MAX_TOKEN_BYTES = 64 * 1024; /** Where `sellable-model-signin` keeps the programs and the Claude login. */ export function modelSigninPaths(dataRoot) { const root = join(dataRoot, "model-signins"); return Object.freeze({ claudeCommand: join(root, "claude-code", "node_modules", ".bin", "claude"), claudeConfigDir: join(root, "claude"), agyCommand: join(root, "agy", "agy"), agyConfigDir: join(dataRoot, ".gemini", "antigravity-cli"), }); } /** A private file of a sane size, never a link. Any doubt answers null. */ function privateJson(path) { try { const stat = lstatSync(path); if ( stat.isSymbolicLink() || !stat.isFile() || (stat.mode & 0o077) !== 0 || stat.size < 16 || stat.size > MAX_TOKEN_BYTES ) return null; return JSON.parse(readFileSync(path, "utf8")); } catch { return null; } } function isFile(path) { try { return statSync(path).isFile(); } catch { return false; } } function installed(command, plugin, pluginsRoot, shelfRoot) { try { accessSync(command, constants.X_OK); } catch { return false; } return [pluginsRoot, shelfRoot].some((root) => isFile(join(root, plugin, "__init__.py")) ); } /** * Give Hermes only the add-ons this machine is signed in to, at boot and as * root. Hermes loads every add-on it finds, and one of them prints "npm * install ..." on a machine without its program; the startup check refuses * that, so no customer machine could start (release of 2026-12-03). */ export function placeModelProviderAddons( { claude, antigravity }, { pluginsRoot = MODEL_PROVIDER_PLUGINS_ROOT, shelfRoot = MODEL_PROVIDER_SHELF_ROOT, } = {} ) { for (const [plugin, signedIn] of [ [CLAUDE_SIGNIN_PROVIDER, claude], [ANTIGRAVITY_SIGNIN_PROVIDER, antigravity], ]) { const source = join(shelfRoot, plugin); if (!isFile(join(source, "__init__.py"))) continue; const target = join(pluginsRoot, plugin); rmSync(target, { recursive: true, force: true }); if (signedIn === true) symlinkSync(source, target); } } /** True only with the program, the add-on and a login that can refresh. */ export function claudeSignedIn({ command, configDir, pluginsRoot = MODEL_PROVIDER_PLUGINS_ROOT, shelfRoot = MODEL_PROVIDER_SHELF_ROOT, }) { if (!installed(command, CLAUDE_SIGNIN_PROVIDER, pluginsRoot, shelfRoot)) return false; const token = privateJson(join(configDir, ".credentials.json"))?.claudeAiOauth ?.refreshToken; return typeof token === "string" && token.length > 0; } /** True only with agy, the add-on and a login that can refresh. */ export function antigravitySignedIn({ command, configDir, pluginsRoot = MODEL_PROVIDER_PLUGINS_ROOT, shelfRoot = MODEL_PROVIDER_SHELF_ROOT, }) { if (!installed(command, ANTIGRAVITY_SIGNIN_PROVIDER, pluginsRoot, shelfRoot)) return false; const token = privateJson(join(configDir, "antigravity-oauth-token"))?.token ?.refresh_token; return typeof token === "string" && token.length > 0; } /** The models a machine's sign-ins add, for the staff's model order. */ export function signedInModels({ claude, antigravity }) { return Object.freeze([ ...(antigravity === true ? [ Object.freeze({ provider: ANTIGRAVITY_SIGNIN_PROVIDER, model: ANTIGRAVITY_SIGNIN_MODEL, }), ] : []), ...(claude === true ? [ Object.freeze({ provider: CLAUDE_SIGNIN_PROVIDER, model: CLAUDE_SIGNIN_MODEL, }), ] : []), ]); } /** This machine's sign-ins, read once from its volume. */ export function machineSignins(dataRoot) { const paths = modelSigninPaths(dataRoot); return Object.freeze({ paths, claude: claudeSignedIn({ command: paths.claudeCommand, configDir: paths.claudeConfigDir, }), antigravity: antigravitySignedIn({ command: paths.agyCommand, configDir: paths.agyConfigDir, }), }); } /** * What the gateway's add-ons need to find the programs and the sign-ins. * Nothing on a machine without one: a customer's gateway starts as before. */ export function modelSigninEnvironment({ paths, claude, antigravity }) { return Object.freeze({ ...(claude === true ? { CLAUDE_SUBSCRIPTION_DIRECTSDK_COMMAND: paths.claudeCommand, CLAUDE_SUBSCRIPTION_DIRECTSDK_CONFIG_DIR: paths.claudeConfigDir, } : {}), ...(antigravity === true ? { ANTIGRAVITY_CONFIG_DIR: paths.agyConfigDir, ANTIGRAVITY_COMMAND: paths.agyCommand, // agy gets a minimal environment, never the gateway's credentials. ANTIGRAVITY_ENV_STRICT: "1", // Each idle agy worker holds about 250 MB; released after 2 minutes. ANTIGRAVITY_WORKER_IDLE_SECONDS: "120", } : {}), }); }