feat(core): add command, intent, and routing primitives

This commit is contained in:
William Valentin
2026-02-12 22:47:22 -08:00
parent 7ae0fb51c2
commit 6e8984f788
25 changed files with 1469 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import { describe, it, expect } from 'vitest';
import { RoutingPolicy } from './policy.js';
describe('RoutingPolicy', () => {
it('uses default path when disabled', () => {
const policy = new RoutingPolicy({
enabled: false,
fastPathThreshold: 0.8,
llmThreshold: 0.4,
defaultPath: 'llm',
});
expect(policy.decide({ confidence: 0.99 })).toEqual({ path: 'llm', reason: 'disabled' });
});
it('routes to fast at or above fast threshold', () => {
const policy = new RoutingPolicy({
enabled: true,
fastPathThreshold: 0.8,
llmThreshold: 0.4,
defaultPath: 'llm',
});
expect(policy.decide({ confidence: 0.8 })).toEqual({ path: 'fast', reason: 'high_confidence' });
expect(policy.decide({ confidence: 0.95 })).toEqual({ path: 'fast', reason: 'high_confidence' });
});
it('routes to llm at or below llm threshold', () => {
const policy = new RoutingPolicy({
enabled: true,
fastPathThreshold: 0.8,
llmThreshold: 0.4,
defaultPath: 'fast',
});
expect(policy.decide({ confidence: 0.4 })).toEqual({ path: 'llm', reason: 'low_confidence' });
expect(policy.decide({ confidence: 0.1 })).toEqual({ path: 'llm', reason: 'low_confidence' });
});
it('uses default path between thresholds', () => {
const policy = new RoutingPolicy({
enabled: true,
fastPathThreshold: 0.8,
llmThreshold: 0.4,
defaultPath: 'llm',
});
expect(policy.decide({ confidence: 0.6 })).toEqual({ path: 'llm', reason: 'mid_confidence' });
});
});