@gabrielsmartin/orbit-sdk 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/fingerprint.js +37 -0
- package/src/index.js +15 -10
- package/src/router.js +23 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gabrielsmartin/orbit-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Rule-based LLM router. Classifies queries across 8 axes and picks the optimal model. Fast, deterministic, zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=16"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|
package/src/fingerprint.js
CHANGED
|
@@ -100,3 +100,40 @@ export function fingerprint(text) {
|
|
|
100
100
|
domain,
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Apply signal bias to a fingerprint before routing.
|
|
106
|
+
* 777 = completion → quality floor (never cheap out on final form)
|
|
107
|
+
* 555 = variation → inject creativity + recency (break the expected model)
|
|
108
|
+
* 333 = foundation → cost floor (strip to minimum — ethics override still wins)
|
|
109
|
+
*
|
|
110
|
+
* @param {Object} scores - Raw 8-axis fingerprint
|
|
111
|
+
* @param {string|null} signalCode - "777" | "555" | "333" | null
|
|
112
|
+
* @returns {Object} Biased fingerprint
|
|
113
|
+
*/
|
|
114
|
+
export function applySignalBias(scores, signalCode) {
|
|
115
|
+
if (!signalCode) return scores;
|
|
116
|
+
const s = { ...scores };
|
|
117
|
+
|
|
118
|
+
if (signalCode === "777") {
|
|
119
|
+
s.cost_tolerance = Math.max(s.cost_tolerance, 8);
|
|
120
|
+
s.complexity = Math.max(s.complexity, 6);
|
|
121
|
+
s.signal_applied = "777";
|
|
122
|
+
s.signal_reason = "Completion bias — quality floor raised. Final form deserves the best model.";
|
|
123
|
+
} else if (signalCode === "555") {
|
|
124
|
+
s.creativity = Math.max(s.creativity, 6);
|
|
125
|
+
s.recency = Math.max(s.recency, 5);
|
|
126
|
+
s.variation_mode = true;
|
|
127
|
+
s.signal_applied = "555";
|
|
128
|
+
s.signal_reason = "Variation bias — creativity + recency floors raised. Breaking the default pattern.";
|
|
129
|
+
} else if (signalCode === "333") {
|
|
130
|
+
if ((s.emotional_weight ?? 0) < 7) {
|
|
131
|
+
s.cost_tolerance = 1;
|
|
132
|
+
s.complexity = Math.min(s.complexity, 4);
|
|
133
|
+
}
|
|
134
|
+
s.signal_applied = "333";
|
|
135
|
+
s.signal_reason = "Foundation bias — cost minimized. Strip to essentials.";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return s;
|
|
139
|
+
}
|
package/src/index.js
CHANGED
|
@@ -7,12 +7,10 @@
|
|
|
7
7
|
* 777 · 555 · 333
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { fingerprint } from './fingerprint.js';
|
|
10
|
+
import { fingerprint, applySignalBias } from './fingerprint.js';
|
|
11
11
|
import { route, calculateSavings, MODEL_MATRIX } from './router.js';
|
|
12
12
|
|
|
13
|
-
export { fingerprint, route, calculateSavings, MODEL_MATRIX };
|
|
14
|
-
|
|
15
|
-
const GATEWAY_URL = 'https://gtll-soul-guide-81e596e1.base44.app/functions/orbitGateway';
|
|
13
|
+
export { fingerprint, applySignalBias, route, calculateSavings, MODEL_MATRIX };
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* OrbitClient — the main class
|
|
@@ -52,19 +50,19 @@ export class OrbitClient {
|
|
|
52
50
|
* @returns {{ model, reason, rule, scores, savings, timestamp }}
|
|
53
51
|
*/
|
|
54
52
|
route(text, options = {}) {
|
|
55
|
-
|
|
53
|
+
let scores = fingerprint(text);
|
|
56
54
|
|
|
57
55
|
if (options.cost_tolerance) {
|
|
58
56
|
scores.cost_tolerance = options.cost_tolerance === 'low' ? 2
|
|
59
57
|
: options.cost_tolerance === 'high' ? 9 : 5;
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
60
|
+
// Apply signal bias (777/555/333) — modifies axes before routing
|
|
61
|
+
if (options.signal) {
|
|
62
|
+
scores = applySignalBias(scores, options.signal);
|
|
63
|
+
}
|
|
67
64
|
|
|
65
|
+
const config = { ...this.config, ...options };
|
|
68
66
|
const decision = route(scores, config);
|
|
69
67
|
const savings = calculateSavings(decision.model, options.estimated_tokens || 500);
|
|
70
68
|
|
|
@@ -72,6 +70,8 @@ export class OrbitClient {
|
|
|
72
70
|
model: decision.model,
|
|
73
71
|
reason: decision.reason,
|
|
74
72
|
rule: decision.rule,
|
|
73
|
+
signal: options.signal || null,
|
|
74
|
+
signal_reason: scores.signal_reason || null,
|
|
75
75
|
scores,
|
|
76
76
|
savings,
|
|
77
77
|
timestamp: new Date().toISOString(),
|
|
@@ -85,6 +85,11 @@ export class OrbitClient {
|
|
|
85
85
|
|
|
86
86
|
if (this.config.log) {
|
|
87
87
|
console.log(`[ORBIT] → ${decision.model.name} | ${decision.rule} | saved $${savings.savings.toFixed(5)} (${savings.reductionPct}% vs GPT-4o)`);
|
|
88
|
+
|
|
89
|
+
// Nudge unauthenticated users toward API key
|
|
90
|
+
if (!this.config.apiKey && this._stats.total_queries === 3) {
|
|
91
|
+
console.warn(`[ORBIT] Free tier: 15 API queries/day. Get your key → https://gtll-soul-guide-81e596e1.base44.app/functions/orbitWaitlist (POST { action: "get_key", email })`);
|
|
92
|
+
}
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
if (this.config.on_route) {
|
package/src/router.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
export const MODEL_MATRIX = {
|
|
13
13
|
claude_sonnet: {
|
|
14
|
-
id: 'claude-sonnet-
|
|
14
|
+
id: 'claude-sonnet-4-6',
|
|
15
15
|
name: 'Claude Sonnet',
|
|
16
16
|
provider: 'anthropic',
|
|
17
17
|
costPer1M: 15,
|
|
@@ -20,7 +20,7 @@ export const MODEL_MATRIX = {
|
|
|
20
20
|
tier: 'medium',
|
|
21
21
|
},
|
|
22
22
|
claude_haiku: {
|
|
23
|
-
id: 'claude-haiku-
|
|
23
|
+
id: 'claude-haiku-4-5',
|
|
24
24
|
name: 'Claude Haiku',
|
|
25
25
|
provider: 'anthropic',
|
|
26
26
|
costPer1M: 1,
|
|
@@ -84,6 +84,27 @@ export function route(scores, config = {}) {
|
|
|
84
84
|
|
|
85
85
|
const blocked = config.blocked_models || [];
|
|
86
86
|
const preferLow = config.cost_tolerance === 'low' || cost_tolerance <= 3;
|
|
87
|
+
const preferHigh = config.cost_tolerance === 'high' || cost_tolerance >= 8;
|
|
88
|
+
const variationMode = scores.variation_mode ?? false;
|
|
89
|
+
|
|
90
|
+
// Rule 0: SIGNAL 555 VARIATION — break the default pattern before all other rules
|
|
91
|
+
if (variationMode && recency >= 5 && !blocked.includes('grok')) {
|
|
92
|
+
return {
|
|
93
|
+
model: MODEL_MATRIX.grok,
|
|
94
|
+
reason: `Signal 555 — variation mode active, recency ${recency}/10. Grok selected to break the default routing.`,
|
|
95
|
+
rule: 'signal_555_variation',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Rule 0: SIGNAL 555 VARIATION — break the default pattern before all other rules
|
|
100
|
+
if (variationMode && recency >= 5 && !blocked.includes('grok')) {
|
|
101
|
+
return {
|
|
102
|
+
model: MODEL_MATRIX.grok,
|
|
103
|
+
reason: `Signal 555 — variation mode active, recency ${recency}/10. Grok selected to break the default routing.`,
|
|
104
|
+
rule: 'signal_555_variation',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
87
108
|
|
|
88
109
|
// Signal override (777/555/333) — always wins if set
|
|
89
110
|
if (config.signal === '777') {
|