pi-smart-router 1.2.1 → 1.3.0
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/.pi/extensions/smart-router/delegation-runtime.ts +12 -2
- package/.pi/extensions/smart-router/fleet-bootstrap.ts +22 -0
- package/.pi/extensions/smart-router/routing-context.ts +85 -11
- package/README.md +47 -1
- package/config/benchmark-profiles.json +124 -33
- package/dist/config/defaults.d.ts +2 -2
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +6 -3
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/pi-model-mapper.d.ts +37 -1
- package/dist/config/pi-model-mapper.d.ts.map +1 -1
- package/dist/config/pi-model-mapper.js +120 -7
- package/dist/config/pi-model-mapper.js.map +1 -1
- package/dist/domain/delegation/delegation-context.d.ts +49 -0
- package/dist/domain/delegation/delegation-context.d.ts.map +1 -1
- package/dist/domain/delegation/delegation-context.js +92 -0
- package/dist/domain/delegation/delegation-context.js.map +1 -1
- package/dist/domain/judgment/answer-mapper.d.ts +49 -0
- package/dist/domain/judgment/answer-mapper.d.ts.map +1 -0
- package/dist/domain/judgment/answer-mapper.js +124 -0
- package/dist/domain/judgment/answer-mapper.js.map +1 -0
- package/dist/domain/judgment/index.d.ts +8 -0
- package/dist/domain/judgment/index.d.ts.map +1 -0
- package/dist/domain/judgment/index.js +8 -0
- package/dist/domain/judgment/index.js.map +1 -0
- package/dist/domain/judgment/judge-state.d.ts +70 -0
- package/dist/domain/judgment/judge-state.d.ts.map +1 -0
- package/dist/domain/judgment/judge-state.js +227 -0
- package/dist/domain/judgment/judge-state.js.map +1 -0
- package/dist/domain/judgment/questions.d.ts +58 -0
- package/dist/domain/judgment/questions.d.ts.map +1 -0
- package/dist/domain/judgment/questions.js +157 -0
- package/dist/domain/judgment/questions.js.map +1 -0
- package/dist/domain/matching/hydra-input.d.ts.map +1 -1
- package/dist/domain/matching/hydra-input.js +4 -17
- package/dist/domain/matching/hydra-input.js.map +1 -1
- package/dist/domain/pinning/loop-escalation.d.ts.map +1 -1
- package/dist/domain/pinning/loop-escalation.js +1 -49
- package/dist/domain/pinning/loop-escalation.js.map +1 -1
- package/dist/domain/pinning/tool-failure.d.ts +20 -0
- package/dist/domain/pinning/tool-failure.d.ts.map +1 -0
- package/dist/domain/pinning/tool-failure.js +62 -0
- package/dist/domain/pinning/tool-failure.js.map +1 -0
- package/dist/domain/pipeline/pipeline-stage.d.ts +11 -0
- package/dist/domain/pipeline/pipeline-stage.d.ts.map +1 -1
- package/dist/domain/pipeline/pipeline-stage.js +3 -0
- package/dist/domain/pipeline/pipeline-stage.js.map +1 -1
- package/dist/domain/pipeline/router-pipeline.d.ts +32 -6
- package/dist/domain/pipeline/router-pipeline.d.ts.map +1 -1
- package/dist/domain/pipeline/router-pipeline.js +49 -4
- package/dist/domain/pipeline/router-pipeline.js.map +1 -1
- package/dist/domain/pipeline/typed-judgment-stage.d.ts +44 -0
- package/dist/domain/pipeline/typed-judgment-stage.d.ts.map +1 -0
- package/dist/domain/pipeline/typed-judgment-stage.js +144 -0
- package/dist/domain/pipeline/typed-judgment-stage.js.map +1 -0
- package/dist/domain/ports/typed-judgment-port.d.ts +138 -0
- package/dist/domain/ports/typed-judgment-port.d.ts.map +1 -0
- package/dist/domain/ports/typed-judgment-port.js +28 -0
- package/dist/domain/ports/typed-judgment-port.js.map +1 -0
- package/dist/domain/types/entities.d.ts +42 -1
- package/dist/domain/types/entities.d.ts.map +1 -1
- package/dist/domain/types/index.d.ts +1 -1
- package/dist/domain/types/index.d.ts.map +1 -1
- package/dist/domain/types/schemas.d.ts +140 -0
- package/dist/domain/types/schemas.d.ts.map +1 -1
- package/dist/domain/types/schemas.js +191 -0
- package/dist/domain/types/schemas.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/judgment/jev-typed-judgment-adapter.d.ts +67 -0
- package/dist/infrastructure/judgment/jev-typed-judgment-adapter.d.ts.map +1 -0
- package/dist/infrastructure/judgment/jev-typed-judgment-adapter.js +411 -0
- package/dist/infrastructure/judgment/jev-typed-judgment-adapter.js.map +1 -0
- package/dist/infrastructure/persistence/sqlite-store.d.ts.map +1 -1
- package/dist/infrastructure/persistence/sqlite-store.js +37 -9
- package/dist/infrastructure/persistence/sqlite-store.js.map +1 -1
- package/package.json +1 -1
- package/src/config/defaults.ts +8 -1
- package/src/config/pi-model-mapper.ts +146 -7
- package/src/domain/delegation/delegation-context.ts +123 -0
- package/src/domain/judgment/answer-mapper.ts +210 -0
- package/src/domain/judgment/index.ts +32 -0
- package/src/domain/judgment/judge-state.ts +294 -0
- package/src/domain/judgment/questions.ts +198 -0
- package/src/domain/matching/hydra-input.ts +4 -19
- package/src/domain/pinning/loop-escalation.ts +1 -52
- package/src/domain/pinning/tool-failure.ts +66 -0
- package/src/domain/pipeline/pipeline-stage.ts +17 -0
- package/src/domain/pipeline/router-pipeline.ts +83 -6
- package/src/domain/pipeline/typed-judgment-stage.ts +165 -0
- package/src/domain/ports/typed-judgment-port.ts +186 -0
- package/src/domain/types/entities.ts +54 -0
- package/src/domain/types/index.ts +1 -0
- package/src/domain/types/schemas.ts +206 -0
- package/src/index.ts +19 -2
- package/src/infrastructure/judgment/jev-typed-judgment-adapter.ts +564 -0
- package/src/infrastructure/persistence/sqlite-store.ts +45 -9
|
@@ -48,7 +48,7 @@ import { EMBEDDING_DIM } from '../../domain/matching/embedding-provider.js';
|
|
|
48
48
|
|
|
49
49
|
// ─── Schema version & migrations ────────────────────────────────────────────
|
|
50
50
|
|
|
51
|
-
const CURRENT_SCHEMA_VERSION =
|
|
51
|
+
const CURRENT_SCHEMA_VERSION = 9;
|
|
52
52
|
|
|
53
53
|
const MIGRATION_V1 = `
|
|
54
54
|
CREATE TABLE IF NOT EXISTS pins (
|
|
@@ -203,6 +203,18 @@ const MIGRATION_V8 = `
|
|
|
203
203
|
ALTER TABLE dataset ADD COLUMN embedding_json TEXT;
|
|
204
204
|
`;
|
|
205
205
|
|
|
206
|
+
// SP-301 / #171: persist context-fit gate telemetry so router-explain and
|
|
207
|
+
// exports can surface why a request overflowed after restart. Previously the
|
|
208
|
+
// fields were dropped on insert and read back as null literals.
|
|
209
|
+
const MIGRATION_V9 = `
|
|
210
|
+
ALTER TABLE telemetry ADD COLUMN estimated_input_tokens INTEGER;
|
|
211
|
+
ALTER TABLE telemetry ADD COLUMN context_fit_viable_count INTEGER;
|
|
212
|
+
ALTER TABLE telemetry ADD COLUMN context_fit_rejected_json TEXT;
|
|
213
|
+
ALTER TABLE telemetry ADD COLUMN context_overflow_pin_break INTEGER NOT NULL DEFAULT 0;
|
|
214
|
+
ALTER TABLE telemetry ADD COLUMN selected_model_max_input_tokens INTEGER;
|
|
215
|
+
ALTER TABLE telemetry ADD COLUMN context_fit_reason_code TEXT;
|
|
216
|
+
`;
|
|
217
|
+
|
|
206
218
|
// ─── Token bucket result ────────────────────────────────────────────────────
|
|
207
219
|
|
|
208
220
|
export interface TokenBucketResult {
|
|
@@ -708,14 +720,20 @@ export class SqliteStore implements StorePort {
|
|
|
708
720
|
estimated_cost_usd, routing_latency_ms, pin_reason,
|
|
709
721
|
actual_cost_usd, actual_input_tokens, actual_output_tokens,
|
|
710
722
|
actual_cache_read_tokens, actual_cache_write_tokens,
|
|
711
|
-
reasoning_level_requested, reasoning_level_applied, reasoning_reason_code
|
|
723
|
+
reasoning_level_requested, reasoning_level_applied, reasoning_reason_code,
|
|
724
|
+
estimated_input_tokens, context_fit_viable_count,
|
|
725
|
+
context_fit_rejected_json, context_overflow_pin_break,
|
|
726
|
+
selected_model_max_input_tokens, context_fit_reason_code
|
|
712
727
|
) VALUES (
|
|
713
728
|
@timestamp, @session_id, @request_id, @turn_type,
|
|
714
729
|
@stage, @reason_code, @selected_model_id,
|
|
715
730
|
@estimated_cost_usd, @routing_latency_ms, @pin_reason,
|
|
716
731
|
@actual_cost_usd, @actual_input_tokens, @actual_output_tokens,
|
|
717
732
|
@actual_cache_read_tokens, @actual_cache_write_tokens,
|
|
718
|
-
@reasoning_level_requested, @reasoning_level_applied, @reasoning_reason_code
|
|
733
|
+
@reasoning_level_requested, @reasoning_level_applied, @reasoning_reason_code,
|
|
734
|
+
@estimated_input_tokens, @context_fit_viable_count,
|
|
735
|
+
@context_fit_rejected_json, @context_overflow_pin_break,
|
|
736
|
+
@selected_model_max_input_tokens, @context_fit_reason_code
|
|
719
737
|
)`,
|
|
720
738
|
)
|
|
721
739
|
.run({
|
|
@@ -737,6 +755,12 @@ export class SqliteStore implements StorePort {
|
|
|
737
755
|
reasoning_level_requested: entry.reasoning_level_requested ?? null,
|
|
738
756
|
reasoning_level_applied: entry.reasoning_level_applied ?? null,
|
|
739
757
|
reasoning_reason_code: entry.reasoning_reason_code ?? null,
|
|
758
|
+
estimated_input_tokens: entry.estimated_input_tokens ?? null,
|
|
759
|
+
context_fit_viable_count: entry.context_fit_viable_count ?? null,
|
|
760
|
+
context_fit_rejected_json: entry.context_fit_rejected_json ?? null,
|
|
761
|
+
context_overflow_pin_break: entry.context_overflow_pin_break ? 1 : 0,
|
|
762
|
+
selected_model_max_input_tokens: entry.selected_model_max_input_tokens ?? null,
|
|
763
|
+
context_fit_reason_code: entry.context_fit_reason_code ?? null,
|
|
740
764
|
});
|
|
741
765
|
}
|
|
742
766
|
|
|
@@ -935,6 +959,12 @@ export class SqliteStore implements StorePort {
|
|
|
935
959
|
if (version < 8) {
|
|
936
960
|
this.db.exec(MIGRATION_V8);
|
|
937
961
|
version = 8;
|
|
962
|
+
this.db.pragma(`user_version = ${version}`);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
if (version < 9) {
|
|
966
|
+
this.db.exec(MIGRATION_V9);
|
|
967
|
+
version = 9;
|
|
938
968
|
this.db.pragma(`user_version = ${CURRENT_SCHEMA_VERSION}`);
|
|
939
969
|
}
|
|
940
970
|
}
|
|
@@ -1033,6 +1063,12 @@ interface TelemetryRow {
|
|
|
1033
1063
|
reasoning_level_requested: string | null;
|
|
1034
1064
|
reasoning_level_applied: string | null;
|
|
1035
1065
|
reasoning_reason_code: string | null;
|
|
1066
|
+
estimated_input_tokens: number | null;
|
|
1067
|
+
context_fit_viable_count: number | null;
|
|
1068
|
+
context_fit_rejected_json: string | null;
|
|
1069
|
+
context_overflow_pin_break: number;
|
|
1070
|
+
selected_model_max_input_tokens: number | null;
|
|
1071
|
+
context_fit_reason_code: string | null;
|
|
1036
1072
|
}
|
|
1037
1073
|
|
|
1038
1074
|
interface DatasetRow {
|
|
@@ -1142,12 +1178,12 @@ function telemetryRowToEntity(row: TelemetryRow): RoutingTelemetry {
|
|
|
1142
1178
|
estimated_cost_usd: row.estimated_cost_usd,
|
|
1143
1179
|
routing_latency_ms: row.routing_latency_ms,
|
|
1144
1180
|
pin_reason: row.pin_reason,
|
|
1145
|
-
estimated_input_tokens:
|
|
1146
|
-
context_fit_viable_count:
|
|
1147
|
-
context_fit_rejected_json:
|
|
1148
|
-
context_overflow_pin_break:
|
|
1149
|
-
selected_model_max_input_tokens:
|
|
1150
|
-
context_fit_reason_code:
|
|
1181
|
+
estimated_input_tokens: row.estimated_input_tokens,
|
|
1182
|
+
context_fit_viable_count: row.context_fit_viable_count,
|
|
1183
|
+
context_fit_rejected_json: row.context_fit_rejected_json,
|
|
1184
|
+
context_overflow_pin_break: row.context_overflow_pin_break === 1,
|
|
1185
|
+
selected_model_max_input_tokens: row.selected_model_max_input_tokens,
|
|
1186
|
+
context_fit_reason_code: row.context_fit_reason_code,
|
|
1151
1187
|
cluster_id: null,
|
|
1152
1188
|
cluster_similarity: null,
|
|
1153
1189
|
cluster_margin: null,
|