feat(core): add command, intent, and routing primitives
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
export type RoutingPath = 'fast' | 'llm';
|
||||
|
||||
export interface RoutingPolicyConfig {
|
||||
enabled: boolean;
|
||||
fastPathThreshold: number;
|
||||
llmThreshold: number;
|
||||
defaultPath: RoutingPath;
|
||||
}
|
||||
|
||||
export interface RoutingDecisionInput {
|
||||
confidence: number | null;
|
||||
}
|
||||
|
||||
export interface RoutingDecision {
|
||||
path: RoutingPath;
|
||||
reason: 'disabled' | 'no_match' | 'high_confidence' | 'low_confidence' | 'mid_confidence';
|
||||
}
|
||||
|
||||
export class RoutingPolicy {
|
||||
private readonly config: RoutingPolicyConfig;
|
||||
|
||||
constructor(config: RoutingPolicyConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
return this.config.enabled;
|
||||
}
|
||||
|
||||
decide(input: RoutingDecisionInput): RoutingDecision {
|
||||
if (!this.config.enabled) {
|
||||
return {
|
||||
path: this.config.defaultPath,
|
||||
reason: 'disabled',
|
||||
};
|
||||
}
|
||||
|
||||
if (input.confidence === null) {
|
||||
return {
|
||||
path: this.config.defaultPath,
|
||||
reason: 'no_match',
|
||||
};
|
||||
}
|
||||
|
||||
if (input.confidence >= this.config.fastPathThreshold) {
|
||||
return {
|
||||
path: 'fast',
|
||||
reason: 'high_confidence',
|
||||
};
|
||||
}
|
||||
|
||||
if (input.confidence <= this.config.llmThreshold) {
|
||||
return {
|
||||
path: 'llm',
|
||||
reason: 'low_confidence',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
path: this.config.defaultPath,
|
||||
reason: 'mid_confidence',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user