File size: 1,796 Bytes
0110dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * 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 }
}