bob-ide / src /lib /nodeKey.ts
SNAPKITTYWEST's picture
push from SNAPKITTYWEST/bob-ide
0110dee verified
Raw
History Blame Contribute Delete
1.8 kB
/**
* Sovereign Node Key β€” SnapKitty execution gate.
* Called before any model routing request fires.
*
* Get your key: licensing@snapkittywest.dev
* Copyright (C) 2026 Bel Esprit D'Accord Irrevocable Trust (EIN 42-697643)
*/
const KEY_PREFIX = 'SNK-'
const KEY_STORAGE = 'snapkitty_node_key'
const KEY_ENV = import.meta.env?.VITE_SNAPKITTY_NODE_KEY
export const SOVEREIGN_WALL = `
╔══════════════════════════════════════════════════╗
β•‘ SOVEREIGN NODE KEY REQUIRED β•‘
β•‘ β•‘
β•‘ BOB IDE requires a valid SnapKitty node key β•‘
β•‘ to activate model routing. β•‘
β•‘ β•‘
β•‘ Get your key: β•‘
β•‘ licensing@snapkittywest.dev β•‘
β•‘ https://github.com/SNAPKITTYWEST β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
`
export function getNodeKey(): string {
return KEY_ENV || localStorage.getItem(KEY_STORAGE) || ''
}
export function setNodeKey(key: string): void {
localStorage.setItem(KEY_STORAGE, key)
}
export function hasNodeKey(): boolean {
const key = getNodeKey()
return key.startsWith(KEY_PREFIX) && key.length > 10
}
export function requireNodeKey(): void {
if (!hasNodeKey()) {
throw new Error(SOVEREIGN_WALL)
}
}
/** Attach node key to fetch headers for model routing requests */
export function nodeKeyHeaders(): HeadersInit {
const key = getNodeKey()
if (!key) return {}
return { 'X-Sovereign-Node-Key': key }
}