@gabrielsmartin/orbit-sdk 0.1.2 → 0.2.1
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/README.md +134 -98
- package/index.js +14 -0
- package/package.json +23 -26
- package/src/index.js +20 -6
- package/src/router.js +64 -16
- package/src/signal.js +105 -0
- package/src/signalBias.js +85 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# orbit-ai
|
|
2
2
|
|
|
3
3
|
> Stop blasting every query at GPT-4o. Route intelligently. Save 85%.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`orbit-ai` is a drop-in routing layer that reads the fingerprint of every AI query and sends it to the optimal model — automatically, in under 1ms.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install
|
|
8
|
+
npm install orbit-ai
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
**Built by [Gabriel Martin](https://www.linkedin.com/in/gabrielsmartin) · [orbit-model-flow.base44.app](https://orbit-model-flow.base44.app)**
|
|
12
|
-
|
|
13
11
|
---
|
|
14
12
|
|
|
15
13
|
## The problem
|
|
@@ -20,147 +18,185 @@ You're probably doing this:
|
|
|
20
18
|
const res = await openai.chat.completions.create({
|
|
21
19
|
model: "gpt-4o", // $30/1M tokens — every single query
|
|
22
20
|
messages
|
|
23
|
-
})
|
|
21
|
+
})
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
GPT-4o costs **30x more per token** than Gemini Flash. For "what's 2+2?" — you're paying Ferrari prices to drive to the mailbox.
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
ORBIT fixes this. One line.
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
---
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
import orbit from '@gabrielsmartin/orbit-sdk'
|
|
30
|
+
## How it works
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
// → { model: "Claude Sonnet", reason: "High creativity — Claude Sonnet for nuanced generation", savings: { reductionPct: 50 } }
|
|
32
|
+
Every query gets fingerprinted across **8 axes** in under 1ms:
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
| Axis | What it measures |
|
|
35
|
+
|---|---|
|
|
36
|
+
| **Complexity** | Depth of reasoning required |
|
|
37
|
+
| **Creativity** | Open-ended vs deterministic |
|
|
38
|
+
| **Emotional Weight** | Sensitivity — crisis queries always go to Claude |
|
|
39
|
+
| **Recency** | Need for live/current data → Grok |
|
|
40
|
+
| **Context Load** | Window size needed → Claude 200k |
|
|
41
|
+
| **Speed** | Latency sensitivity |
|
|
42
|
+
| **Domain** | Code · Creative · Medical · Legal · General |
|
|
43
|
+
| **Cost Tolerance** | Budget tier (overridable) |
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
// → { model: "Claude Sonnet", reason: "Emotional weight detected — ethics-first routing. Never a cheap model." }
|
|
43
|
-
```
|
|
45
|
+
Then it routes to the right model. Invisibly.
|
|
44
46
|
|
|
45
47
|
---
|
|
46
48
|
|
|
47
|
-
##
|
|
49
|
+
## Usage
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| Axis | What it detects |
|
|
52
|
-
|------|----------------|
|
|
53
|
-
| `complexity` | Depth of reasoning required |
|
|
54
|
-
| `creativity` | Open-ended vs. factual generation |
|
|
55
|
-
| `emotional_weight` | Sensitive or crisis content |
|
|
56
|
-
| `recency` | Need for real-time / live web data |
|
|
57
|
-
| `context_load` | Long-document or multi-turn depth |
|
|
58
|
-
| `speed` | Latency sensitivity |
|
|
59
|
-
| `domain` | Code, legal, medical, creative, general |
|
|
60
|
-
| `cost_tolerance` | Budget flexibility signal |
|
|
61
|
-
|
|
62
|
-
The SMM (Selective Model Matching) engine then routes:
|
|
63
|
-
|
|
64
|
-
| Signal | → Model | Why |
|
|
65
|
-
|--------|---------|-----|
|
|
66
|
-
| Emotional weight > 6 | Claude Sonnet | Ethics-first. Always. |
|
|
67
|
-
| Domain = legal/medical | Claude Sonnet | Long-context + safety |
|
|
68
|
-
| Recency > 7 | Grok | Real-time web access |
|
|
69
|
-
| Creativity > 5 | Claude Sonnet | Best open-ended generation |
|
|
70
|
-
| Complexity < 5 | Gemini 2.5 Flash | 98% cheaper, 95% quality |
|
|
71
|
-
| Trivial query | GPT-4o Mini | 99% cheaper than GPT-4o |
|
|
51
|
+
### Zero-config routing decision
|
|
72
52
|
|
|
73
|
-
|
|
53
|
+
```javascript
|
|
54
|
+
import orbit from 'orbit-ai'
|
|
74
55
|
|
|
75
|
-
|
|
56
|
+
// Get the routing decision
|
|
57
|
+
const decision = orbit.route("write a haiku about recursion")
|
|
76
58
|
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
console.log(decision.model.name) // "Claude Sonnet"
|
|
60
|
+
console.log(decision.reason) // "High creativity score (8/10)..."
|
|
61
|
+
console.log(decision.savings) // { savings: 0.007245, reductionPct: 97 }
|
|
62
|
+
```
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
const result = orbit.route(queryText)
|
|
82
|
-
// Returns: { model, reason, savings: { reductionPct, estimatedCost, premiumCost } }
|
|
64
|
+
### With your own API keys
|
|
83
65
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Returns: { queries_routed, total_savings_formatted, breakdown }
|
|
66
|
+
```javascript
|
|
67
|
+
import { OrbitClient } from 'orbit-ai'
|
|
87
68
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
blocked_models: ['gpt4o'],
|
|
69
|
+
const orbit = new OrbitClient({
|
|
70
|
+
cost_tolerance: 'low', // 'low' | 'medium' | 'high'
|
|
71
|
+
log: true, // logs routing decisions to console
|
|
92
72
|
})
|
|
93
73
|
|
|
94
|
-
//
|
|
95
|
-
const
|
|
96
|
-
//
|
|
97
|
-
```
|
|
74
|
+
// Route the query
|
|
75
|
+
const { model, reason, savings } = orbit.route("explain blockchain simply")
|
|
76
|
+
// [ORBIT] → Gemini 2.5 Flash | cost_gemini | saved $0.01455 (97% reduction)
|
|
98
77
|
|
|
99
|
-
|
|
78
|
+
// Now call the model yourself with your keys
|
|
79
|
+
// model.id = 'gemini-2.5-flash', model.provider = 'google'
|
|
80
|
+
```
|
|
100
81
|
|
|
101
|
-
|
|
82
|
+
### Full pipeline example (with Anthropic SDK)
|
|
102
83
|
|
|
84
|
+
```javascript
|
|
85
|
+
import { OrbitClient } from 'orbit-ai'
|
|
86
|
+
import Anthropic from '@anthropic-ai/sdk'
|
|
87
|
+
import OpenAI from 'openai'
|
|
88
|
+
import { GoogleGenerativeAI } from '@google/generative-ai'
|
|
89
|
+
|
|
90
|
+
const orbit = new OrbitClient({ log: true })
|
|
91
|
+
|
|
92
|
+
async function smartQuery(text) {
|
|
93
|
+
const { model, reason } = orbit.route(text)
|
|
94
|
+
|
|
95
|
+
if (model.provider === 'anthropic') {
|
|
96
|
+
const client = new Anthropic()
|
|
97
|
+
return client.messages.create({
|
|
98
|
+
model: model.id,
|
|
99
|
+
max_tokens: 1024,
|
|
100
|
+
messages: [{ role: 'user', content: text }]
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (model.provider === 'openai') {
|
|
105
|
+
const client = new OpenAI()
|
|
106
|
+
return client.chat.completions.create({
|
|
107
|
+
model: model.id,
|
|
108
|
+
messages: [{ role: 'user', content: text }]
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (model.provider === 'google') {
|
|
113
|
+
const client = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY)
|
|
114
|
+
const genModel = client.getGenerativeModel({ model: model.id })
|
|
115
|
+
return genModel.generateContent(text)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Routes each query to the optimal model
|
|
120
|
+
await smartQuery("write a poem about the ocean") // → Claude Sonnet
|
|
121
|
+
await smartQuery("what's the latest news on AI funding?") // → Grok
|
|
122
|
+
await smartQuery("what is 2+2") // → Gemini Flash
|
|
123
|
+
await smartQuery("I've been feeling really overwhelmed") // → Claude Sonnet (ethics-first)
|
|
103
124
|
```
|
|
104
|
-
$ node test.js
|
|
105
125
|
|
|
106
|
-
|
|
107
|
-
[ORBIT] → Gemini 2.5 Flash | cost_gemini | saved $0.01475 (98% reduction)
|
|
108
|
-
[ORBIT] → Claude Sonnet | default | saved $0.00750 (50% reduction)
|
|
126
|
+
### Session stats
|
|
109
127
|
|
|
110
|
-
|
|
128
|
+
```javascript
|
|
129
|
+
const stats = orbit.stats()
|
|
130
|
+
console.log(stats.total_savings_formatted) // "$0.2341"
|
|
131
|
+
console.log(stats.model_usage) // { "Claude Sonnet": 4, "Gemini 2.5 Flash": 12, ... }
|
|
111
132
|
```
|
|
112
133
|
|
|
113
|
-
|
|
134
|
+
### Fingerprint only (no routing)
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
import { fingerprint } from 'orbit-ai'
|
|
138
|
+
|
|
139
|
+
const scores = fingerprint("architect a distributed caching system for 10M users")
|
|
140
|
+
// {
|
|
141
|
+
// complexity: 9,
|
|
142
|
+
// creativity: 0,
|
|
143
|
+
// domain: 'code',
|
|
144
|
+
// emotional_weight: 0,
|
|
145
|
+
// recency: 0,
|
|
146
|
+
// context_load: 3,
|
|
147
|
+
// ...
|
|
148
|
+
// }
|
|
149
|
+
```
|
|
114
150
|
|
|
115
151
|
---
|
|
116
152
|
|
|
117
|
-
##
|
|
153
|
+
## Model matrix
|
|
118
154
|
|
|
119
|
-
|
|
155
|
+
| Model | Provider | Cost/1M | Best for |
|
|
156
|
+
|---|---|---|---|
|
|
157
|
+
| Claude Sonnet | Anthropic | $15 | Complex reasoning · Ethics · Long context |
|
|
158
|
+
| Claude Haiku | Anthropic | $1 | Speed · Summaries · Medium tasks |
|
|
159
|
+
| Gemini 2.5 Flash | Google | $0.50 | High volume · Simple queries · Cost |
|
|
160
|
+
| GPT-4o | OpenAI | $30 | Structured output · Broad knowledge |
|
|
161
|
+
| GPT-4o Mini | OpenAI | $0.30 | Classification · Filler tasks |
|
|
162
|
+
| Grok | xAI | $10 | Trending · Real-time web |
|
|
120
163
|
|
|
121
|
-
|
|
164
|
+
---
|
|
122
165
|
|
|
123
|
-
|
|
124
|
-
- Routing policy editor (block models, set cost caps)
|
|
125
|
-
- Team analytics dashboard
|
|
126
|
-
- A/B cost testing across routing strategies
|
|
127
|
-
- Custom model matrix + private model support
|
|
128
|
-
- Enterprise compliance mode + SLA guarantee
|
|
166
|
+
## The math
|
|
129
167
|
|
|
130
|
-
**
|
|
131
|
-
| Tier | Price | Queries |
|
|
132
|
-
|------|-------|---------|
|
|
133
|
-
| Free | $0/mo | 100/day |
|
|
134
|
-
| Pro | $19/mo | Unlimited |
|
|
135
|
-
| Team | $99/mo | Unlimited · 5 seats |
|
|
136
|
-
| Enterprise | Custom | Custom + 15% savings-share |
|
|
168
|
+
Validated by [RouteLLM (UC Berkeley · ICLR 2025)](https://arxiv.org/abs/2406.18665): intelligent routing achieves **85% cost reduction** while maintaining 95% of quality.
|
|
137
169
|
|
|
138
|
-
|
|
139
|
-
|
|
170
|
+
For a team running 100k queries/month at GPT-4o:
|
|
171
|
+
- Without ORBIT: **$1,500/month**
|
|
172
|
+
- With ORBIT: **~$225/month**
|
|
173
|
+
- Savings: **$1,275/month · $15,300/year**
|
|
140
174
|
|
|
141
175
|
---
|
|
142
176
|
|
|
143
|
-
##
|
|
177
|
+
## Live demo
|
|
144
178
|
|
|
145
|
-
-
|
|
146
|
-
- **OpenRouter** ($500M+ valuation) proves the market. ORBIT adds the intelligence layer they're missing.
|
|
147
|
-
- **Martian** (Accenture-backed) proves enterprises pay for routing. ORBIT is the frictionless version for everyone else.
|
|
179
|
+
[orbit-model-flow.base44.app](https://orbit-model-flow.base44.app) — route a real query, see the fingerprint radar, watch the savings counter.
|
|
148
180
|
|
|
149
181
|
---
|
|
150
182
|
|
|
151
183
|
## Roadmap
|
|
152
184
|
|
|
153
|
-
- [x]
|
|
154
|
-
- [x]
|
|
155
|
-
- [
|
|
156
|
-
- [ ]
|
|
157
|
-
- [ ]
|
|
158
|
-
- [ ]
|
|
185
|
+
- [x] 8-axis fingerprinting engine
|
|
186
|
+
- [x] 6-model routing matrix
|
|
187
|
+
- [x] TypeScript types
|
|
188
|
+
- [ ] Streaming support
|
|
189
|
+
- [ ] Custom model matrix (bring your own models)
|
|
190
|
+
- [ ] Automatic provider failover
|
|
191
|
+
- [ ] Usage analytics dashboard integration
|
|
192
|
+
- [ ] Browser extension
|
|
159
193
|
|
|
160
194
|
---
|
|
161
195
|
|
|
162
196
|
## License
|
|
163
197
|
|
|
164
|
-
MIT
|
|
198
|
+
MIT · Built by [Gabriel Martin](https://github.com/gabrielsmartin)
|
|
199
|
+
|
|
200
|
+
*"Every model has a gravitational pull. ORBIT decides which one you need."*
|
|
165
201
|
|
|
166
|
-
|
|
202
|
+
777 · 555 · 333
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gabrielsmartin/orbit-sdk
|
|
3
|
+
* Intelligent AI model routing — routes every query to the optimal model in <1ms
|
|
4
|
+
*
|
|
5
|
+
* 777 · 555 · 333
|
|
6
|
+
* github.com/gtllco/orbit
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export { fingerprint, route, calculateSavings, MODEL_MATRIX, OrbitClient } from './src/index.js';
|
|
10
|
+
|
|
11
|
+
// Default export — zero-config instance
|
|
12
|
+
import { OrbitClient } from './src/index.js';
|
|
13
|
+
const orbit = new OrbitClient();
|
|
14
|
+
export default orbit;
|
package/package.json
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gabrielsmartin/orbit-sdk",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Intelligent AI model routing
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"types": "src/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./src/index.js",
|
|
11
|
-
"types": "./src/index.d.ts"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Intelligent AI model routing with signal layer. 85% cost savings. 777\u00b7555\u00b7333",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
14
7
|
"files": [
|
|
15
|
-
"
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"src/",
|
|
16
11
|
"README.md"
|
|
17
12
|
],
|
|
18
13
|
"scripts": {
|
|
@@ -27,26 +22,28 @@
|
|
|
27
22
|
"gemini",
|
|
28
23
|
"orbit",
|
|
29
24
|
"cost-optimization",
|
|
30
|
-
"model-routing"
|
|
31
|
-
"selective-model-matching",
|
|
32
|
-
"gpt4",
|
|
33
|
-
"claude",
|
|
34
|
-
"gemini-flash",
|
|
35
|
-
"grok",
|
|
36
|
-
"ai-infrastructure"
|
|
25
|
+
"model-routing"
|
|
37
26
|
],
|
|
38
|
-
"author": "Gabriel Martin <
|
|
27
|
+
"author": "Gabriel Martin <admin@gtll.app>",
|
|
39
28
|
"license": "MIT",
|
|
40
29
|
"repository": {
|
|
41
30
|
"type": "git",
|
|
42
|
-
"url": "
|
|
43
|
-
"directory": "sdk"
|
|
31
|
+
"url": "https://github.com/gtllco/orbit"
|
|
44
32
|
},
|
|
45
|
-
"homepage": "https://orbit-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
33
|
+
"homepage": "https://orbit-sdk.base44.app",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"module": "index.js",
|
|
39
|
+
"type": "module",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"import": "./index.js",
|
|
43
|
+
"types": "./index.d.ts"
|
|
44
|
+
}
|
|
48
45
|
},
|
|
49
46
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
47
|
+
"node": ">=18.0.0"
|
|
51
48
|
}
|
|
52
49
|
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* orbit-ai · v0.
|
|
3
|
-
* Intelligent AI model routing. Drop in. Save 85%.
|
|
2
|
+
* orbit-ai · v0.2.0
|
|
3
|
+
* Intelligent AI model routing with signal layer. Drop in. Save 85%.
|
|
4
4
|
*
|
|
5
5
|
* https://orbit-model-flow.base44.app
|
|
6
6
|
* github.com/gabrielsmartin/orbit
|
|
@@ -20,6 +20,9 @@ export { fingerprint, route, calculateSavings, MODEL_MATRIX };
|
|
|
20
20
|
* import { OrbitClient } from 'orbit-ai'
|
|
21
21
|
* const orbit = new OrbitClient({ apiKey: 'your-orbit-key' })
|
|
22
22
|
* const result = await orbit.query("explain quantum entanglement simply")
|
|
23
|
+
*
|
|
24
|
+
* // With signal
|
|
25
|
+
* const result = await orbit.query("final investor memo", { signal: "777" })
|
|
23
26
|
*/
|
|
24
27
|
export class OrbitClient {
|
|
25
28
|
constructor(config = {}) {
|
|
@@ -39,19 +42,22 @@ export class OrbitClient {
|
|
|
39
42
|
total_queries: 0,
|
|
40
43
|
total_savings: 0,
|
|
41
44
|
model_usage: {},
|
|
45
|
+
signal_usage: { '777': 0, '555': 0, '333': 0, null: 0 },
|
|
42
46
|
};
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
|
-
* Route a query to the optimal model
|
|
50
|
+
* Route a query to the optimal model with optional signal bias
|
|
47
51
|
* Returns the routing decision — you call the model yourself with your keys
|
|
48
52
|
*
|
|
49
53
|
* @param {string} text - The query text
|
|
50
54
|
* @param {Object} options - Override options for this query
|
|
51
|
-
* @
|
|
55
|
+
* @param {string} options.signal - Optional semantic intent flag ('777' | '555' | '333')
|
|
56
|
+
* @returns {Object} decision - { model, reason, rule, scores, signal_applied, signal_reason, savings }
|
|
52
57
|
*/
|
|
53
58
|
route(text, options = {}) {
|
|
54
59
|
const scores = fingerprint(text);
|
|
60
|
+
const signal = options.signal || null;
|
|
55
61
|
|
|
56
62
|
// Allow per-query cost_tolerance override
|
|
57
63
|
if (options.cost_tolerance) {
|
|
@@ -60,13 +66,15 @@ export class OrbitClient {
|
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
const config = { ...this.config, ...options };
|
|
63
|
-
const decision = route(scores, config);
|
|
69
|
+
const decision = route(scores, signal, config);
|
|
64
70
|
const savings = calculateSavings(decision.model, options.estimated_tokens || 500);
|
|
65
71
|
|
|
66
72
|
const result = {
|
|
67
73
|
model: decision.model,
|
|
68
74
|
reason: decision.reason,
|
|
69
75
|
rule: decision.rule,
|
|
76
|
+
signal_applied: decision.signal_applied,
|
|
77
|
+
signal_reason: decision.signal_reason,
|
|
70
78
|
scores,
|
|
71
79
|
savings,
|
|
72
80
|
timestamp: new Date().toISOString(),
|
|
@@ -77,10 +85,12 @@ export class OrbitClient {
|
|
|
77
85
|
this._stats.total_savings += savings.savings;
|
|
78
86
|
const modelName = decision.model.name;
|
|
79
87
|
this._stats.model_usage[modelName] = (this._stats.model_usage[modelName] || 0) + 1;
|
|
88
|
+
this._stats.signal_usage[signal || 'null']++;
|
|
80
89
|
|
|
81
90
|
// Log routing decision
|
|
82
91
|
if (this.config.log) {
|
|
83
|
-
|
|
92
|
+
const signalStr = signal ? ` [signal: ${signal}]` : '';
|
|
93
|
+
console.log(`[ORBIT] → ${decision.model.name} | ${decision.rule}${signalStr} | saved $${savings.savings.toFixed(5)} (${savings.reductionPct}% reduction)`);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
// Fire callback
|
|
@@ -117,6 +127,10 @@ export class OrbitClient {
|
|
|
117
127
|
* import orbit from 'orbit-ai'
|
|
118
128
|
* const decision = orbit.route("write a haiku about recursion")
|
|
119
129
|
* // → { model: { name: 'Claude Sonnet', ... }, reason: '...', savings: { ... } }
|
|
130
|
+
*
|
|
131
|
+
* // With signal
|
|
132
|
+
* const decision = orbit.route("final investor memo", { signal: "777" })
|
|
133
|
+
* // → { model: { name: 'Claude Sonnet', ... }, signal_applied: '777', signal_reason: '...', ... }
|
|
120
134
|
*/
|
|
121
135
|
const orbit = new OrbitClient();
|
|
122
136
|
export default orbit;
|
package/src/router.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ORBIT · Selective Model Matching (SMM) Router
|
|
3
|
-
* Routes queries to optimal models based on 8-axis fingerprints
|
|
3
|
+
* Routes queries to optimal models based on 8-axis fingerprints + signal codes
|
|
4
4
|
*
|
|
5
5
|
* Proprietary routing logic — open SDK, closed engine weights
|
|
6
6
|
* 777 · 555 · 333
|
|
@@ -64,34 +64,82 @@ export const MODEL_MATRIX = {
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Core SMM routing logic
|
|
67
|
+
* Core SMM routing logic — Signal-aware
|
|
68
68
|
* Returns the selected model + reasoning
|
|
69
69
|
*
|
|
70
|
-
* @param {Object} scores - 8-axis fingerprint scores
|
|
70
|
+
* @param {Object} scores - 8-axis fingerprint scores (post-signal-bias)
|
|
71
71
|
* @param {Object} config - User config (cost_tolerance override, blocked_models, etc.)
|
|
72
72
|
* @returns {Object} { model, reason, fallback }
|
|
73
73
|
*/
|
|
74
74
|
export function route(scores, config = {}) {
|
|
75
75
|
const {
|
|
76
76
|
complexity, creativity, speed, emotional_weight,
|
|
77
|
-
recency, context_load, domain, cost_tolerance
|
|
77
|
+
recency, context_load, domain, cost_tolerance,
|
|
78
|
+
signal_code, variation_mode
|
|
78
79
|
} = scores;
|
|
79
80
|
|
|
80
81
|
const blocked = config.blocked_models || [];
|
|
81
|
-
const preferLow =
|
|
82
|
-
const preferHigh =
|
|
82
|
+
const preferLow = cost_tolerance <= 3;
|
|
83
|
+
const preferHigh = cost_tolerance >= 8;
|
|
83
84
|
|
|
84
|
-
//
|
|
85
|
+
// ── SIGNAL OVERRIDES (applied before all other rules) ──────────────────────
|
|
86
|
+
|
|
87
|
+
// 777 — Completion Bias: cost_tolerance and complexity already raised by applySignalBias.
|
|
88
|
+
// But explicitly block sub-tier models when signal=777.
|
|
89
|
+
if (signal_code === '777') {
|
|
90
|
+
// Minimum floor: Claude Haiku. Prefer Sonnet if complexity >= 5.
|
|
91
|
+
if (complexity >= 5 && !blocked.includes('claude_sonnet')) {
|
|
92
|
+
return {
|
|
93
|
+
model: MODEL_MATRIX.claude_sonnet,
|
|
94
|
+
reason: `Completion bias (777) — complexity ${complexity}/10 meets threshold. Claude Sonnet mandatory. This output is final form.`,
|
|
95
|
+
rule: 'signal_777_sonnet',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// complexity < 5 but still 777: Claude Haiku minimum, no Gemini Flash/GPT-4o Mini
|
|
99
|
+
if (!blocked.includes('claude_haiku')) {
|
|
100
|
+
return {
|
|
101
|
+
model: MODEL_MATRIX.claude_haiku,
|
|
102
|
+
reason: `Completion bias (777) — complexity ${complexity}/10 below Sonnet threshold but 777 enforces Claude Haiku minimum. No sub-tier models on completion events.`,
|
|
103
|
+
rule: 'signal_777_haiku',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 555 — Variation Bias: variation_mode=true, creativity and recency already boosted.
|
|
109
|
+
// Prefer Grok when recency is elevated. Otherwise prefer creative non-default models.
|
|
110
|
+
if (signal_code === '555') {
|
|
111
|
+
if (recency >= 5 && !blocked.includes('grok')) {
|
|
112
|
+
return {
|
|
113
|
+
model: MODEL_MATRIX.grok,
|
|
114
|
+
reason: `Variation bias (555) — recency boosted to ${recency}/10. Grok for live web intelligence and unexpected angles. Destabilize the expected.`,
|
|
115
|
+
rule: 'signal_555_grok',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (creativity >= 6 && !blocked.includes('claude_sonnet')) {
|
|
119
|
+
return {
|
|
120
|
+
model: MODEL_MATRIX.claude_sonnet,
|
|
121
|
+
reason: `Variation bias (555) — creativity at ${creativity}/10. Claude Sonnet for nuanced, surprising creative output.`,
|
|
122
|
+
rule: 'signal_555_claude',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 333 — Foundation Bias: cost_tolerance dropped to 1 by applySignalBias (unless emotional override).
|
|
128
|
+
// Emotional safety net is handled by ethics rule below — it fires first.
|
|
129
|
+
|
|
130
|
+
// ── CORE ROUTING RULES ─────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
// Rule 1: ETHICS FIRST — emotional/crisis queries always go to Claude (even on 333)
|
|
85
133
|
if (emotional_weight >= 6) {
|
|
86
134
|
return {
|
|
87
135
|
model: MODEL_MATRIX.claude_sonnet,
|
|
88
|
-
reason:
|
|
136
|
+
reason: `Emotional weight ${emotional_weight}/10 — routing to Claude for ethics-first handling. Never use a cheap model for sensitive content.${signal_code === '333' ? ' (333 foundation bias overridden by emotional safety rule)' : ''}`,
|
|
89
137
|
rule: 'ethics_first',
|
|
90
138
|
};
|
|
91
139
|
}
|
|
92
140
|
|
|
93
141
|
// Rule 2: Realtime / current events → Grok
|
|
94
|
-
if (recency >= 7 && !blocked.includes('grok')) {
|
|
142
|
+
if (recency >= 7 && !blocked.includes('grok') && signal_code !== '777') {
|
|
95
143
|
return {
|
|
96
144
|
model: MODEL_MATRIX.grok,
|
|
97
145
|
reason: `High recency score (${recency}/10) — Grok has live web access for current events and trending topics.`,
|
|
@@ -100,7 +148,7 @@ export function route(scores, config = {}) {
|
|
|
100
148
|
}
|
|
101
149
|
|
|
102
150
|
// Rule 3: Long context load → Claude Sonnet (200k window)
|
|
103
|
-
if (context_load >= 8 && !blocked.includes('claude_sonnet')) {
|
|
151
|
+
if (context_load >= 8 && !blocked.includes('claude_sonnet') && signal_code !== '333') {
|
|
104
152
|
return {
|
|
105
153
|
model: MODEL_MATRIX.claude_sonnet,
|
|
106
154
|
reason: `High context load (${context_load}/10) — Claude's 200k window is the only safe choice.`,
|
|
@@ -117,8 +165,8 @@ export function route(scores, config = {}) {
|
|
|
117
165
|
};
|
|
118
166
|
}
|
|
119
167
|
|
|
120
|
-
// Rule 5: High complexity general → GPT-4o (if cost tolerance allows)
|
|
121
|
-
if (complexity >= 7 && !preferLow && !blocked.includes('gpt4o')) {
|
|
168
|
+
// Rule 5: High complexity general → GPT-4o (if cost tolerance allows and not 777/333)
|
|
169
|
+
if (complexity >= 7 && !preferLow && !blocked.includes('gpt4o') && signal_code !== '777' && signal_code !== '333') {
|
|
122
170
|
return {
|
|
123
171
|
model: MODEL_MATRIX.gpt4o,
|
|
124
172
|
reason: `High complexity (${complexity}/10) — GPT-4o for broad knowledge and structured output.`,
|
|
@@ -126,8 +174,8 @@ export function route(scores, config = {}) {
|
|
|
126
174
|
};
|
|
127
175
|
}
|
|
128
176
|
|
|
129
|
-
// Rule 6: Creative writing → Claude Sonnet
|
|
130
|
-
if (creativity >= 5 && !blocked.includes('claude_sonnet')) {
|
|
177
|
+
// Rule 6: Creative writing → Claude Sonnet (unless 333 forcing minimum)
|
|
178
|
+
if (creativity >= 5 && !blocked.includes('claude_sonnet') && !preferLow) {
|
|
131
179
|
return {
|
|
132
180
|
model: MODEL_MATRIX.claude_sonnet,
|
|
133
181
|
reason: `High creativity score (${creativity}/10) — Claude Sonnet for nuanced creative writing.`,
|
|
@@ -135,11 +183,11 @@ export function route(scores, config = {}) {
|
|
|
135
183
|
};
|
|
136
184
|
}
|
|
137
185
|
|
|
138
|
-
// Rule 7: Cost sensitive OR simple queries → Gemini Flash
|
|
186
|
+
// Rule 7: Cost sensitive OR simple queries OR 333 foundation → Gemini Flash
|
|
139
187
|
if ((preferLow || complexity <= 3) && !blocked.includes('gemini_flash')) {
|
|
140
188
|
return {
|
|
141
189
|
model: MODEL_MATRIX.gemini_flash,
|
|
142
|
-
reason:
|
|
190
|
+
reason: `${signal_code === '333' ? 'Foundation bias (333) — ' : ''}Low complexity (${complexity}/10) — Gemini 2.5 Flash delivers 95% quality at 2% of GPT-4o cost.`,
|
|
143
191
|
rule: 'cost_gemini',
|
|
144
192
|
};
|
|
145
193
|
}
|
package/src/signal.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ORBIT · Signal Layer — Priority-Aware Routing Bias
|
|
3
|
+
*
|
|
4
|
+
* Signal codes connect the routing layer to the agent network.
|
|
5
|
+
* A 777 event means something is landing — never cut corners.
|
|
6
|
+
* A 555 event means something is shifting — route to variation.
|
|
7
|
+
* A 333 event means ambient/background — route to minimum cost.
|
|
8
|
+
*
|
|
9
|
+
* interval(n) = base / 2^n — Recursive Beat Engine
|
|
10
|
+
* 777 · 555 · 333
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Apply signal bias to a fingerprint before routing.
|
|
15
|
+
* Mutates a COPY of the fingerprint — never the original.
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} fingerprint - 8-axis fingerprint from fingerprint.js
|
|
18
|
+
* @param {string|null} signal_code - "777" | "555" | "333" | null
|
|
19
|
+
* @returns {Object} biased fingerprint + signal metadata
|
|
20
|
+
*/
|
|
21
|
+
export function applySignalBias(fingerprint, signal_code) {
|
|
22
|
+
// No signal = no change
|
|
23
|
+
if (!signal_code || !['777', '555', '333'].includes(signal_code)) {
|
|
24
|
+
return { ...fingerprint, signal_code: null, signal_applied: false };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const f = { ...fingerprint };
|
|
28
|
+
|
|
29
|
+
if (signal_code === '777') {
|
|
30
|
+
// Completion Bias — this output is final form. Never cut corners.
|
|
31
|
+
// Force quality floor: raise cost_tolerance and complexity minimums.
|
|
32
|
+
f.cost_tolerance = Math.max(f.cost_tolerance, 7);
|
|
33
|
+
f.complexity = Math.max(f.complexity, 6);
|
|
34
|
+
// Note: emotional_weight guard is handled in router — Claude always if emotional_weight >= 6 anyway
|
|
35
|
+
f.signal_code = '777';
|
|
36
|
+
f.signal_applied = true;
|
|
37
|
+
f.signal_reason = 'Completion bias — cost floor raised, complexity floor raised. Quality is non-negotiable on 777 events.';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (signal_code === '555') {
|
|
41
|
+
// Variation Bias — something is shifting. Route to surprise.
|
|
42
|
+
// Boost creativity and recency to prefer Grok/Perplexity and non-default models.
|
|
43
|
+
f.creativity = Math.max(f.creativity, 6);
|
|
44
|
+
f.recency = Math.max(f.recency, 5);
|
|
45
|
+
f.variation_mode = true; // router reads this to prefer non-default choices
|
|
46
|
+
f.signal_code = '555';
|
|
47
|
+
f.signal_applied = true;
|
|
48
|
+
f.signal_reason = 'Variation bias — creativity and recency boosted. Routing to destabilize the expected.';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (signal_code === '333') {
|
|
52
|
+
// Foundation Bias — ambient/background. Strip cost aggressively.
|
|
53
|
+
// Exception: emotional_weight >= 7 always upgrades (crisis never gets a cheap model).
|
|
54
|
+
if (f.emotional_weight < 7) {
|
|
55
|
+
f.cost_tolerance = 1; // force minimum cost
|
|
56
|
+
f.complexity = Math.min(f.complexity, 4); // cap complexity perception
|
|
57
|
+
f.signal_code = '333';
|
|
58
|
+
f.signal_applied = true;
|
|
59
|
+
f.signal_reason = 'Foundation bias — cost floor dropped to minimum. Routing to cheapest capable model.';
|
|
60
|
+
} else {
|
|
61
|
+
// Emotional override — even on 333, safety first
|
|
62
|
+
f.signal_code = '333';
|
|
63
|
+
f.signal_applied = true;
|
|
64
|
+
f.signal_reason = 'Foundation bias requested, but emotional_weight >= 7 — safety override active. Routing to Claude.';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return f;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Infer signal code from neural hub event priority.
|
|
73
|
+
* When coral1 fires an AgentEvent, the priority field maps directly to signal codes.
|
|
74
|
+
* This is how the neural hub auto-injects signal into ORBIT routing.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} eventPriority - "777" | "555" | "333" | "444"
|
|
77
|
+
* @returns {string|null} signal_code
|
|
78
|
+
*/
|
|
79
|
+
export function inferSignalFromEvent(eventPriority) {
|
|
80
|
+
const map = { '777': '777', '555': '555', '333': '333' };
|
|
81
|
+
return map[eventPriority] || null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Format signal metadata for API responses.
|
|
86
|
+
*
|
|
87
|
+
* @param {Object} biasedFingerprint - fingerprint after applySignalBias
|
|
88
|
+
* @param {Object} routingDecision - result from route()
|
|
89
|
+
* @returns {Object} signal metadata for API response
|
|
90
|
+
*/
|
|
91
|
+
export function formatSignalResponse(biasedFingerprint, routingDecision) {
|
|
92
|
+
if (!biasedFingerprint.signal_applied) {
|
|
93
|
+
return { signal_applied: null };
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
signal_applied: biasedFingerprint.signal_code,
|
|
97
|
+
signal_reason: biasedFingerprint.signal_reason,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const SIGNAL_DESCRIPTIONS = {
|
|
102
|
+
'777': 'Completion · Return · Alignment — This output is final form. Quality is mandatory.',
|
|
103
|
+
'555': 'Transformation · Breakthrough — This query is exploratory. Route to variation and surprise.',
|
|
104
|
+
'333': 'Foundation · Breath · Ground — This is ambient. Route to minimum cost. Strip everything.',
|
|
105
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ORBIT Signal Layer — Semantic Intent Routing Bias
|
|
3
|
+
*
|
|
4
|
+
* Signal codes are semantic flags that travel with a query and adjust the routing
|
|
5
|
+
* decision before model selection. They connect ORBIT to the organizational priority
|
|
6
|
+
* layer (the neural hub, event priorities, etc).
|
|
7
|
+
*
|
|
8
|
+
* 777 · 555 · 333
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Apply signal-based routing bias to a fingerprint
|
|
13
|
+
* Modifies the fingerprint scores before model selection happens
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} fingerprint - 8-axis scores from orbitFingerprint()
|
|
16
|
+
* @param {string} signal - '777' | '555' | '333' | null
|
|
17
|
+
* @returns {Object} biased fingerprint
|
|
18
|
+
*/
|
|
19
|
+
export function applySignalBias(fingerprint, signal) {
|
|
20
|
+
if (!signal) return fingerprint;
|
|
21
|
+
|
|
22
|
+
const biased = { ...fingerprint };
|
|
23
|
+
|
|
24
|
+
if (signal === '777') {
|
|
25
|
+
// COMPLETION BIAS
|
|
26
|
+
// 777 = This output is final. Quality floor raised. Never cut corners.
|
|
27
|
+
// - Force high-capability model floor
|
|
28
|
+
// - Never route to sub-tier models (Flash, Mini, Haiku)
|
|
29
|
+
// - If complexity >= 5: Claude Sonnet mandatory
|
|
30
|
+
// - If complexity < 5: Claude Haiku minimum
|
|
31
|
+
// - If emotional_weight >= 7: Claude always (never change this)
|
|
32
|
+
|
|
33
|
+
biased.cost_tolerance = Math.max(biased.cost_tolerance, 7);
|
|
34
|
+
biased.complexity = Math.max(biased.complexity, 5);
|
|
35
|
+
biased.signal_applied = '777';
|
|
36
|
+
biased.signal_reason = 'Completion bias — cost floor raised, quality mandatory';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (signal === '555') {
|
|
40
|
+
// VARIATION BIAS
|
|
41
|
+
// 555 = This query is exploratory. Break the expected pattern. Surprise.
|
|
42
|
+
// - Introduce controlled model diversity
|
|
43
|
+
// - Prefer non-default choices
|
|
44
|
+
// - If creativity >= 5: weight variation higher
|
|
45
|
+
// - If recency >= 6: Perplexity-like model over Claude
|
|
46
|
+
// - If complexity >= 6: allow GPT-4o instead of Claude
|
|
47
|
+
|
|
48
|
+
biased.creativity = Math.max(biased.creativity, 5);
|
|
49
|
+
biased.recency = Math.max(biased.recency, 4);
|
|
50
|
+
biased.variation_mode = true;
|
|
51
|
+
biased.signal_applied = '555';
|
|
52
|
+
biased.signal_reason = 'Variation bias — introduce model diversity, break the pattern';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (signal === '333') {
|
|
56
|
+
// FOUNDATION BIAS
|
|
57
|
+
// 333 = This is ambient/background. Strip to minimum. Cost floor.
|
|
58
|
+
// - Aggressively route to minimum viable model
|
|
59
|
+
// - If emotional_weight < 7: force cost_tolerance to 1 (ignore user config)
|
|
60
|
+
// - If complexity > 5: cap it at 4 (don't overpay)
|
|
61
|
+
// - Exception: emotional_weight >= 7 ALWAYS upgrades to Claude
|
|
62
|
+
// (never route crisis/sensitive to cheap models, even on 333)
|
|
63
|
+
|
|
64
|
+
if (biased.emotional_weight < 7) {
|
|
65
|
+
biased.cost_tolerance = 1; // force minimum cost
|
|
66
|
+
biased.complexity = Math.min(biased.complexity, 4); // cap complexity
|
|
67
|
+
}
|
|
68
|
+
biased.signal_applied = '333';
|
|
69
|
+
biased.signal_reason = 'Foundation bias — cost floor, ambient routing';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return biased;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create signal explanation for response
|
|
77
|
+
*/
|
|
78
|
+
export function getSignalExplanation(signal) {
|
|
79
|
+
const explanations = {
|
|
80
|
+
'777': 'Completion bias applied — cost floor raised, complexity floor raised. Routed to highest-capability model.',
|
|
81
|
+
'555': 'Variation bias applied — model diversity prioritized. Unexpected routing choice for exploratory output.',
|
|
82
|
+
'333': 'Foundation bias applied — cost floor enforced. Minimum viable model selected for ambient routing.',
|
|
83
|
+
};
|
|
84
|
+
return explanations[signal] || null;
|
|
85
|
+
}
|
|
File without changes
|