pi-smart-router 0.1.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/command-formatters.ts +167 -0
- package/.pi/extensions/smart-router/commands.ts +242 -0
- package/.pi/extensions/smart-router/dataset-export.ts +142 -0
- package/.pi/extensions/smart-router/delegate-stream.ts +105 -0
- package/.pi/extensions/smart-router/delegation-runtime.ts +355 -0
- package/.pi/extensions/smart-router/extension-setup.ts +115 -0
- package/.pi/extensions/smart-router/fleet-bootstrap.ts +244 -0
- package/.pi/extensions/smart-router/index.ts +115 -0
- package/.pi/extensions/smart-router/package.json +3 -0
- package/.pi/extensions/smart-router/pi-model-scope.ts +55 -0
- package/.pi/extensions/smart-router/pricing-lifecycle.ts +43 -0
- package/.pi/extensions/smart-router/route-and-delegate.ts +562 -0
- package/.pi/extensions/smart-router/routing-context.ts +171 -0
- package/.pi/extensions/smart-router/routing-outcomes.ts +44 -0
- package/.pi/extensions/smart-router/session-lifecycle.ts +140 -0
- package/.pi/extensions/smart-router/stream-delegation.ts +75 -0
- package/.pi/extensions/smart-router/types.ts +90 -0
- package/.pi/extensions/smart-router/utils.ts +58 -0
- package/README.md +593 -0
- package/bin/pi-smart-router.mjs +79 -0
- package/config/.gitkeep +0 -0
- package/config/hydra-projection-weights.json.example +1169 -0
- package/config/models.yaml.example +58 -0
- package/config/p-success-weights.json.example +19 -0
- package/config/routing-calibration.json.example +1605 -0
- package/config/routing-centroids.json.example +1570 -0
- package/config/routing-clusters.yaml.example +41 -0
- package/data/contrib/example.json +25 -0
- package/dist/api/explain/router-explain.d.ts +47 -0
- package/dist/api/explain/router-explain.d.ts.map +1 -0
- package/dist/api/explain/router-explain.js +101 -0
- package/dist/api/explain/router-explain.js.map +1 -0
- package/dist/api/middleware/pi-router-middleware.d.ts +86 -0
- package/dist/api/middleware/pi-router-middleware.d.ts.map +1 -0
- package/dist/api/middleware/pi-router-middleware.js +83 -0
- package/dist/api/middleware/pi-router-middleware.js.map +1 -0
- package/dist/cli/smart-router-cli.d.ts +85 -0
- package/dist/cli/smart-router-cli.d.ts.map +1 -0
- package/dist/cli/smart-router-cli.js +293 -0
- package/dist/cli/smart-router-cli.js.map +1 -0
- package/dist/config/defaults.d.ts +7 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +33 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/models-loader.d.ts +22 -0
- package/dist/config/models-loader.d.ts.map +1 -0
- package/dist/config/models-loader.js +51 -0
- package/dist/config/models-loader.js.map +1 -0
- package/dist/config/pi-model-mapper.d.ts +40 -0
- package/dist/config/pi-model-mapper.d.ts.map +1 -0
- package/dist/config/pi-model-mapper.js +216 -0
- package/dist/config/pi-model-mapper.js.map +1 -0
- package/dist/config/routing-clusters-loader.d.ts +35 -0
- package/dist/config/routing-clusters-loader.d.ts.map +1 -0
- package/dist/config/routing-clusters-loader.js +100 -0
- package/dist/config/routing-clusters-loader.js.map +1 -0
- package/dist/domain/delegation/delegation-context.d.ts +23 -0
- package/dist/domain/delegation/delegation-context.d.ts.map +1 -0
- package/dist/domain/delegation/delegation-context.js +73 -0
- package/dist/domain/delegation/delegation-context.js.map +1 -0
- package/dist/domain/delegation/execution-ledger.d.ts +19 -0
- package/dist/domain/delegation/execution-ledger.d.ts.map +1 -0
- package/dist/domain/delegation/execution-ledger.js +23 -0
- package/dist/domain/delegation/execution-ledger.js.map +1 -0
- package/dist/domain/delegation/output-headroom.d.ts +39 -0
- package/dist/domain/delegation/output-headroom.d.ts.map +1 -0
- package/dist/domain/delegation/output-headroom.js +78 -0
- package/dist/domain/delegation/output-headroom.js.map +1 -0
- package/dist/domain/matching/cluster-matcher.d.ts +69 -0
- package/dist/domain/matching/cluster-matcher.d.ts.map +1 -0
- package/dist/domain/matching/cluster-matcher.js +294 -0
- package/dist/domain/matching/cluster-matcher.js.map +1 -0
- package/dist/domain/matching/embedding-provider.d.ts +21 -0
- package/dist/domain/matching/embedding-provider.d.ts.map +1 -0
- package/dist/domain/matching/embedding-provider.js +42 -0
- package/dist/domain/matching/embedding-provider.js.map +1 -0
- package/dist/domain/matching/hydra-input.d.ts +18 -0
- package/dist/domain/matching/hydra-input.d.ts.map +1 -0
- package/dist/domain/matching/hydra-input.js +40 -0
- package/dist/domain/matching/hydra-input.js.map +1 -0
- package/dist/domain/matching/hydra-matcher.d.ts +103 -0
- package/dist/domain/matching/hydra-matcher.d.ts.map +1 -0
- package/dist/domain/matching/hydra-matcher.js +275 -0
- package/dist/domain/matching/hydra-matcher.js.map +1 -0
- package/dist/domain/pinning/cache-economics.d.ts +53 -0
- package/dist/domain/pinning/cache-economics.d.ts.map +1 -0
- package/dist/domain/pinning/cache-economics.js +72 -0
- package/dist/domain/pinning/cache-economics.js.map +1 -0
- package/dist/domain/pinning/loop-escalation.d.ts +41 -0
- package/dist/domain/pinning/loop-escalation.d.ts.map +1 -0
- package/dist/domain/pinning/loop-escalation.js +137 -0
- package/dist/domain/pinning/loop-escalation.js.map +1 -0
- package/dist/domain/pinning/session-pinner.d.ts +81 -0
- package/dist/domain/pinning/session-pinner.d.ts.map +1 -0
- package/dist/domain/pinning/session-pinner.js +237 -0
- package/dist/domain/pinning/session-pinner.js.map +1 -0
- package/dist/domain/pinning/sub-route-policy.d.ts +41 -0
- package/dist/domain/pinning/sub-route-policy.d.ts.map +1 -0
- package/dist/domain/pinning/sub-route-policy.js +72 -0
- package/dist/domain/pinning/sub-route-policy.js.map +1 -0
- package/dist/domain/pipeline/router-pipeline.d.ts +180 -0
- package/dist/domain/pipeline/router-pipeline.d.ts.map +1 -0
- package/dist/domain/pipeline/router-pipeline.js +807 -0
- package/dist/domain/pipeline/router-pipeline.js.map +1 -0
- package/dist/domain/pipeline/safe-default.d.ts +25 -0
- package/dist/domain/pipeline/safe-default.d.ts.map +1 -0
- package/dist/domain/pipeline/safe-default.js +41 -0
- package/dist/domain/pipeline/safe-default.js.map +1 -0
- package/dist/domain/refactor-guardrails.d.ts +48 -0
- package/dist/domain/refactor-guardrails.d.ts.map +1 -0
- package/dist/domain/refactor-guardrails.js +129 -0
- package/dist/domain/refactor-guardrails.js.map +1 -0
- package/dist/domain/routing/context-fit.d.ts +53 -0
- package/dist/domain/routing/context-fit.d.ts.map +1 -0
- package/dist/domain/routing/context-fit.js +142 -0
- package/dist/domain/routing/context-fit.js.map +1 -0
- package/dist/domain/routing/expected-cost.d.ts +63 -0
- package/dist/domain/routing/expected-cost.d.ts.map +1 -0
- package/dist/domain/routing/expected-cost.js +177 -0
- package/dist/domain/routing/expected-cost.js.map +1 -0
- package/dist/domain/routing/p-success-classifier.d.ts +130 -0
- package/dist/domain/routing/p-success-classifier.d.ts.map +1 -0
- package/dist/domain/routing/p-success-classifier.js +350 -0
- package/dist/domain/routing/p-success-classifier.js.map +1 -0
- package/dist/domain/routing/tier-features.d.ts +70 -0
- package/dist/domain/routing/tier-features.d.ts.map +1 -0
- package/dist/domain/routing/tier-features.js +174 -0
- package/dist/domain/routing/tier-features.js.map +1 -0
- package/dist/domain/routing/tool-history-guard.d.ts +32 -0
- package/dist/domain/routing/tool-history-guard.d.ts.map +1 -0
- package/dist/domain/routing/tool-history-guard.js +110 -0
- package/dist/domain/routing/tool-history-guard.js.map +1 -0
- package/dist/domain/scoring/multi-objective.d.ts +48 -0
- package/dist/domain/scoring/multi-objective.d.ts.map +1 -0
- package/dist/domain/scoring/multi-objective.js +116 -0
- package/dist/domain/scoring/multi-objective.js.map +1 -0
- package/dist/domain/triage/triage-engine.d.ts +43 -0
- package/dist/domain/triage/triage-engine.d.ts.map +1 -0
- package/dist/domain/triage/triage-engine.js +317 -0
- package/dist/domain/triage/triage-engine.js.map +1 -0
- package/dist/domain/triage/turn-envelope.d.ts +17 -0
- package/dist/domain/triage/turn-envelope.d.ts.map +1 -0
- package/dist/domain/triage/turn-envelope.js +81 -0
- package/dist/domain/triage/turn-envelope.js.map +1 -0
- package/dist/domain/types/entities.d.ts +303 -0
- package/dist/domain/types/entities.d.ts.map +1 -0
- package/dist/domain/types/entities.js +6 -0
- package/dist/domain/types/entities.js.map +1 -0
- package/dist/domain/types/index.d.ts +4 -0
- package/dist/domain/types/index.d.ts.map +1 -0
- package/dist/domain/types/index.js +2 -0
- package/dist/domain/types/index.js.map +1 -0
- package/dist/domain/types/schemas.d.ts +346 -0
- package/dist/domain/types/schemas.d.ts.map +1 -0
- package/dist/domain/types/schemas.js +241 -0
- package/dist/domain/types/schemas.js.map +1 -0
- package/dist/domain/types/store-port.d.ts +44 -0
- package/dist/domain/types/store-port.d.ts.map +1 -0
- package/dist/domain/types/store-port.js +6 -0
- package/dist/domain/types/store-port.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/infra/gemini-provider.d.ts +28 -0
- package/dist/infra/gemini-provider.d.ts.map +1 -0
- package/dist/infra/gemini-provider.js +112 -0
- package/dist/infra/gemini-provider.js.map +1 -0
- package/dist/infra/telemetry.d.ts +51 -0
- package/dist/infra/telemetry.d.ts.map +1 -0
- package/dist/infra/telemetry.js +100 -0
- package/dist/infra/telemetry.js.map +1 -0
- package/dist/infrastructure/delegation/provider-error.d.ts +44 -0
- package/dist/infrastructure/delegation/provider-error.d.ts.map +1 -0
- package/dist/infrastructure/delegation/provider-error.js +179 -0
- package/dist/infrastructure/delegation/provider-error.js.map +1 -0
- package/dist/infrastructure/gateway/circuit-breaker.d.ts +68 -0
- package/dist/infrastructure/gateway/circuit-breaker.d.ts.map +1 -0
- package/dist/infrastructure/gateway/circuit-breaker.js +150 -0
- package/dist/infrastructure/gateway/circuit-breaker.js.map +1 -0
- package/dist/infrastructure/gateway/gateway-dispatch.d.ts +138 -0
- package/dist/infrastructure/gateway/gateway-dispatch.d.ts.map +1 -0
- package/dist/infrastructure/gateway/gateway-dispatch.js +308 -0
- package/dist/infrastructure/gateway/gateway-dispatch.js.map +1 -0
- package/dist/infrastructure/hardware/hardware-probe.d.ts +32 -0
- package/dist/infrastructure/hardware/hardware-probe.d.ts.map +1 -0
- package/dist/infrastructure/hardware/hardware-probe.js +199 -0
- package/dist/infrastructure/hardware/hardware-probe.js.map +1 -0
- package/dist/infrastructure/local/local-zero-tier.d.ts +47 -0
- package/dist/infrastructure/local/local-zero-tier.d.ts.map +1 -0
- package/dist/infrastructure/local/local-zero-tier.js +92 -0
- package/dist/infrastructure/local/local-zero-tier.js.map +1 -0
- package/dist/infrastructure/persistence/memory-store.d.ts +31 -0
- package/dist/infrastructure/persistence/memory-store.d.ts.map +1 -0
- package/dist/infrastructure/persistence/memory-store.js +87 -0
- package/dist/infrastructure/persistence/memory-store.js.map +1 -0
- package/dist/infrastructure/persistence/sqlite-store.d.ts +81 -0
- package/dist/infrastructure/persistence/sqlite-store.d.ts.map +1 -0
- package/dist/infrastructure/persistence/sqlite-store.js +658 -0
- package/dist/infrastructure/persistence/sqlite-store.js.map +1 -0
- package/dist/infrastructure/pricing/litellm-fetch.d.ts +46 -0
- package/dist/infrastructure/pricing/litellm-fetch.d.ts.map +1 -0
- package/dist/infrastructure/pricing/litellm-fetch.js +145 -0
- package/dist/infrastructure/pricing/litellm-fetch.js.map +1 -0
- package/dist/infrastructure/pricing/price-broker.d.ts +56 -0
- package/dist/infrastructure/pricing/price-broker.d.ts.map +1 -0
- package/dist/infrastructure/pricing/price-broker.js +133 -0
- package/dist/infrastructure/pricing/price-broker.js.map +1 -0
- package/dist/infrastructure/pricing/pricing-monitor.d.ts +27 -0
- package/dist/infrastructure/pricing/pricing-monitor.d.ts.map +1 -0
- package/dist/infrastructure/pricing/pricing-monitor.js +46 -0
- package/dist/infrastructure/pricing/pricing-monitor.js.map +1 -0
- package/dist/infrastructure/telemetry/dataset-limits.d.ts +13 -0
- package/dist/infrastructure/telemetry/dataset-limits.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/dataset-limits.js +28 -0
- package/dist/infrastructure/telemetry/dataset-limits.js.map +1 -0
- package/dist/infrastructure/telemetry/dataset-recorder.d.ts +48 -0
- package/dist/infrastructure/telemetry/dataset-recorder.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/dataset-recorder.js +154 -0
- package/dist/infrastructure/telemetry/dataset-recorder.js.map +1 -0
- package/dist/infrastructure/telemetry/outcome-limits.d.ts +12 -0
- package/dist/infrastructure/telemetry/outcome-limits.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/outcome-limits.js +28 -0
- package/dist/infrastructure/telemetry/outcome-limits.js.map +1 -0
- package/dist/infrastructure/telemetry/outcome-recorder.d.ts +29 -0
- package/dist/infrastructure/telemetry/outcome-recorder.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/outcome-recorder.js +49 -0
- package/dist/infrastructure/telemetry/outcome-recorder.js.map +1 -0
- package/dist/infrastructure/telemetry/routing-telemetry.d.ts +115 -0
- package/dist/infrastructure/telemetry/routing-telemetry.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/routing-telemetry.js +529 -0
- package/dist/infrastructure/telemetry/routing-telemetry.js.map +1 -0
- package/dist/infrastructure/telemetry/telemetry-limits.d.ts +16 -0
- package/dist/infrastructure/telemetry/telemetry-limits.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/telemetry-limits.js +35 -0
- package/dist/infrastructure/telemetry/telemetry-limits.js.map +1 -0
- package/package.json +110 -0
- package/skills/router-backlog-orchestrator/SKILL.md +183 -0
- package/skills/router-backlog-orchestrator/references/github-router-issue-template.md +78 -0
- package/skills/router-backlog-orchestrator/references/packet-from-issue.md +99 -0
- package/skills/router-backlog-orchestrator/references/prioritization-rubric.md +65 -0
- package/skills/router-backlog-orchestrator/scripts/collect-backlog.sh +44 -0
- package/specs/001-build-smart-router/contracts/telemetry-contrib.schema.json +151 -0
- package/src/api/explain/.gitkeep +0 -0
- package/src/api/explain/router-explain.ts +146 -0
- package/src/api/middleware/.gitkeep +0 -0
- package/src/api/middleware/pi-router-middleware.ts +169 -0
- package/src/cli/smart-router-cli.ts +436 -0
- package/src/config/.gitkeep +0 -0
- package/src/config/defaults.ts +35 -0
- package/src/config/models-loader.ts +68 -0
- package/src/config/pi-model-mapper.ts +285 -0
- package/src/config/routing-clusters-loader.ts +148 -0
- package/src/domain/delegation/delegation-context.ts +111 -0
- package/src/domain/delegation/execution-ledger.ts +34 -0
- package/src/domain/delegation/output-headroom.ts +131 -0
- package/src/domain/matching/.gitkeep +0 -0
- package/src/domain/matching/cluster-matcher.ts +474 -0
- package/src/domain/matching/embedding-provider.ts +79 -0
- package/src/domain/matching/hydra-input.ts +53 -0
- package/src/domain/matching/hydra-matcher.ts +454 -0
- package/src/domain/pinning/.gitkeep +0 -0
- package/src/domain/pinning/cache-economics.ts +128 -0
- package/src/domain/pinning/loop-escalation.ts +181 -0
- package/src/domain/pinning/session-pinner.ts +388 -0
- package/src/domain/pinning/sub-route-policy.ts +119 -0
- package/src/domain/pipeline/.gitkeep +0 -0
- package/src/domain/pipeline/router-pipeline.ts +1139 -0
- package/src/domain/pipeline/safe-default.ts +70 -0
- package/src/domain/refactor-guardrails.ts +202 -0
- package/src/domain/routing/context-fit.ts +221 -0
- package/src/domain/routing/expected-cost.ts +320 -0
- package/src/domain/routing/p-success-classifier.ts +511 -0
- package/src/domain/routing/tier-features.ts +290 -0
- package/src/domain/routing/tool-history-guard.ts +159 -0
- package/src/domain/scoring/.gitkeep +0 -0
- package/src/domain/scoring/multi-objective.ts +175 -0
- package/src/domain/triage/.gitkeep +0 -0
- package/src/domain/triage/triage-engine.ts +373 -0
- package/src/domain/triage/turn-envelope.ts +104 -0
- package/src/domain/types/.gitkeep +0 -0
- package/src/domain/types/entities.ts +384 -0
- package/src/domain/types/index.ts +41 -0
- package/src/domain/types/schemas.ts +289 -0
- package/src/domain/types/store-port.ts +59 -0
- package/src/index.ts +103 -0
- package/src/infra/gemini-provider.ts +142 -0
- package/src/infra/telemetry.ts +169 -0
- package/src/infrastructure/delegation/provider-error.ts +251 -0
- package/src/infrastructure/gateway/.gitkeep +0 -0
- package/src/infrastructure/gateway/circuit-breaker.ts +196 -0
- package/src/infrastructure/gateway/gateway-dispatch.ts +444 -0
- package/src/infrastructure/hardware/.gitkeep +0 -0
- package/src/infrastructure/hardware/hardware-probe.ts +276 -0
- package/src/infrastructure/local/.gitkeep +0 -0
- package/src/infrastructure/local/local-zero-tier.ts +151 -0
- package/src/infrastructure/persistence/.gitkeep +0 -0
- package/src/infrastructure/persistence/memory-store.ts +122 -0
- package/src/infrastructure/persistence/sqlite-store.ts +900 -0
- package/src/infrastructure/pricing/.gitkeep +0 -0
- package/src/infrastructure/pricing/litellm-fetch.ts +215 -0
- package/src/infrastructure/pricing/price-broker.ts +183 -0
- package/src/infrastructure/pricing/pricing-monitor.ts +65 -0
- package/src/infrastructure/telemetry/.gitkeep +0 -0
- package/src/infrastructure/telemetry/dataset-limits.ts +39 -0
- package/src/infrastructure/telemetry/dataset-recorder.ts +215 -0
- package/src/infrastructure/telemetry/outcome-limits.ts +42 -0
- package/src/infrastructure/telemetry/outcome-recorder.ts +118 -0
- package/src/infrastructure/telemetry/routing-telemetry.ts +824 -0
- package/src/infrastructure/telemetry/telemetry-limits.ts +50 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-smart-router project-local extension.
|
|
3
|
+
*
|
|
4
|
+
* Discovers authenticated models from pi's model registry, maps them to a
|
|
5
|
+
* router fleet, registers the smart-router/auto provider, and wires middleware
|
|
6
|
+
* hooks for routing state. Stream delegation routes each request through the
|
|
7
|
+
* pipeline and forwards to the selected provider's built-in streaming API.
|
|
8
|
+
*
|
|
9
|
+
* Imports from ../../../src/** (not dist/) because the extension is loaded by pi
|
|
10
|
+
* from source at dev time and is excluded from the npm dist artifact.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
14
|
+
|
|
15
|
+
import { getSmartRouterArgumentCompletions } from './commands.js';
|
|
16
|
+
import {
|
|
17
|
+
createExtensionDatasetRecorder,
|
|
18
|
+
createExtensionOutcomeRecorder,
|
|
19
|
+
exportDatasetToFile,
|
|
20
|
+
formatDatasetExportJsonl,
|
|
21
|
+
formatDatasetExportTimestamp,
|
|
22
|
+
getDatasetExportPath,
|
|
23
|
+
toDatasetExportRecord,
|
|
24
|
+
} from './dataset-export.js';
|
|
25
|
+
import {
|
|
26
|
+
createDispatchOptions,
|
|
27
|
+
discoverFleet,
|
|
28
|
+
formatLmuStatus,
|
|
29
|
+
initHydraMatcher,
|
|
30
|
+
bindSharedModelRegistry,
|
|
31
|
+
computeCurrentFleetScopeFingerprint,
|
|
32
|
+
computeFleetScopeFingerprint,
|
|
33
|
+
ensureFleetFresh,
|
|
34
|
+
rebuildFleet,
|
|
35
|
+
} from './fleet-bootstrap.js';
|
|
36
|
+
import {
|
|
37
|
+
formatHistoryMessage,
|
|
38
|
+
formatStatusMessage,
|
|
39
|
+
parseSmartRouterArgs,
|
|
40
|
+
} from './command-formatters.js';
|
|
41
|
+
import { formatPricingStalenessLine, refreshPricingCatalog } from './pricing-lifecycle.js';
|
|
42
|
+
import {
|
|
43
|
+
buildRoutingRequest,
|
|
44
|
+
deriveTurnType,
|
|
45
|
+
extractPromptText,
|
|
46
|
+
mapContextMessages,
|
|
47
|
+
} from './routing-context.js';
|
|
48
|
+
import { capturePreRouteOutcomes, updateSessionRoutingSnapshot } from './routing-outcomes.js';
|
|
49
|
+
import {
|
|
50
|
+
buildDelegationContext,
|
|
51
|
+
createStreamSimple,
|
|
52
|
+
getRoutingFeatureSidecar,
|
|
53
|
+
logRoutingDecision,
|
|
54
|
+
resolveDelegationOptions,
|
|
55
|
+
} from './stream-delegation.js';
|
|
56
|
+
import { createSmartRouterRuntime, wireSmartRouterExtension } from './extension-setup.js';
|
|
57
|
+
import { getRouterStateDbPath } from './utils.js';
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
buildRoutingRequest,
|
|
61
|
+
buildDelegationContext,
|
|
62
|
+
createDispatchOptions,
|
|
63
|
+
createExtensionDatasetRecorder,
|
|
64
|
+
createExtensionOutcomeRecorder,
|
|
65
|
+
createSmartRouterRuntime,
|
|
66
|
+
createStreamSimple,
|
|
67
|
+
deriveTurnType,
|
|
68
|
+
discoverFleet,
|
|
69
|
+
bindSharedModelRegistry,
|
|
70
|
+
computeCurrentFleetScopeFingerprint,
|
|
71
|
+
computeFleetScopeFingerprint,
|
|
72
|
+
ensureFleetFresh,
|
|
73
|
+
rebuildFleet,
|
|
74
|
+
exportDatasetToFile,
|
|
75
|
+
extractPromptText,
|
|
76
|
+
formatDatasetExportJsonl,
|
|
77
|
+
formatDatasetExportTimestamp,
|
|
78
|
+
formatLmuStatus,
|
|
79
|
+
formatPricingStalenessLine,
|
|
80
|
+
formatHistoryMessage,
|
|
81
|
+
formatStatusMessage,
|
|
82
|
+
getDatasetExportPath,
|
|
83
|
+
getRouterStateDbPath,
|
|
84
|
+
getRoutingFeatureSidecar,
|
|
85
|
+
getSmartRouterArgumentCompletions,
|
|
86
|
+
mapContextMessages,
|
|
87
|
+
parseSmartRouterArgs,
|
|
88
|
+
refreshPricingCatalog,
|
|
89
|
+
resolveDelegationOptions,
|
|
90
|
+
logRoutingDecision,
|
|
91
|
+
toDatasetExportRecord,
|
|
92
|
+
capturePreRouteOutcomes,
|
|
93
|
+
updateSessionRoutingSnapshot,
|
|
94
|
+
initHydraMatcher,
|
|
95
|
+
wireSmartRouterExtension,
|
|
96
|
+
};
|
|
97
|
+
export { SMART_ROUTER_FULL_INVOCATIONS, SMART_ROUTER_USAGE } from './commands.js';
|
|
98
|
+
export { routeAndDelegate } from './route-and-delegate.js';
|
|
99
|
+
export {
|
|
100
|
+
formatGeminiThoughtSignatureErrorMessage,
|
|
101
|
+
isGeminiThoughtSignatureAssistantError,
|
|
102
|
+
} from '../../../src/infrastructure/delegation/provider-error.js';
|
|
103
|
+
export {
|
|
104
|
+
GEMINI_TOOL_HISTORY_EXCLUDED,
|
|
105
|
+
hasToolCallHistory,
|
|
106
|
+
hasToolCallHistoryFromContext,
|
|
107
|
+
isGoogleGeminiProfile,
|
|
108
|
+
resolveEffectiveFleet,
|
|
109
|
+
} from '../../../src/domain/routing/tool-history-guard.js';
|
|
110
|
+
|
|
111
|
+
export default async function smartRouterExtension(pi: ExtensionAPI): Promise<void> {
|
|
112
|
+
const cwd = process.cwd();
|
|
113
|
+
const { runtime, datasetNotify } = await createSmartRouterRuntime(cwd);
|
|
114
|
+
await wireSmartRouterExtension(pi, runtime, datasetNotify);
|
|
115
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
import type { ModelRegistry } from '@earendil-works/pi-coding-agent';
|
|
6
|
+
import type { Api, Model } from '@earendil-works/pi-ai/compat';
|
|
7
|
+
|
|
8
|
+
export interface ScopedModel {
|
|
9
|
+
model: Model<Api>;
|
|
10
|
+
thinkingLevel?: 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type ResolveModelScopeFn = (
|
|
14
|
+
patterns: string[],
|
|
15
|
+
modelRegistry: ModelRegistry,
|
|
16
|
+
) => Promise<ScopedModel[]>;
|
|
17
|
+
|
|
18
|
+
function findPiCodingAgentDir(): string {
|
|
19
|
+
const candidates: string[] = [];
|
|
20
|
+
const roots = [dirname(fileURLToPath(import.meta.url)), process.cwd()];
|
|
21
|
+
|
|
22
|
+
for (const start of roots) {
|
|
23
|
+
let dir = start;
|
|
24
|
+
for (let i = 0; i < 12; i++) {
|
|
25
|
+
candidates.push(join(dir, 'node_modules/@earendil-works/pi-coding-agent'));
|
|
26
|
+
const parent = dirname(dir);
|
|
27
|
+
if (parent === dir) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
dir = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const candidate of candidates) {
|
|
35
|
+
if (existsSync(join(candidate, 'dist/core/model-resolver.js'))) {
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw new Error('Unable to locate @earendil-works/pi-coding-agent for resolveModelScope');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const piPkgDir = findPiCodingAgentDir();
|
|
44
|
+
const modelResolver = await import(
|
|
45
|
+
pathToFileURL(join(piPkgDir, 'dist/core/model-resolver.js')).href
|
|
46
|
+
);
|
|
47
|
+
const piResolveModelScope = modelResolver.resolveModelScope as ResolveModelScopeFn;
|
|
48
|
+
|
|
49
|
+
/** Delegate to pi's resolveModelScope (not yet on the public package export surface). */
|
|
50
|
+
export function resolveModelScope(
|
|
51
|
+
patterns: string[],
|
|
52
|
+
modelRegistry: ModelRegistry,
|
|
53
|
+
): Promise<ScopedModel[]> {
|
|
54
|
+
return piResolveModelScope(patterns, modelRegistry);
|
|
55
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DEFAULT_OPERATOR_CONFIG } from '../../../src/config/defaults.js';
|
|
2
|
+
import type { PriceCatalog } from '../../../src/domain/types/index.js';
|
|
3
|
+
import { fetchLitellmPriceCatalog } from '../../../src/infrastructure/pricing/litellm-fetch.js';
|
|
4
|
+
import { checkStaleness } from '../../../src/infrastructure/pricing/pricing-monitor.js';
|
|
5
|
+
import type { SmartRouterRuntime } from './types.js';
|
|
6
|
+
|
|
7
|
+
export async function refreshPricingCatalog(
|
|
8
|
+
runtime: SmartRouterRuntime,
|
|
9
|
+
fetchFn?: typeof fetch,
|
|
10
|
+
): Promise<{ modelCount: number; lastUpdated: string }> {
|
|
11
|
+
const existing = await runtime.store.getPriceCatalog();
|
|
12
|
+
const { catalog: fetched, model_count: modelCount } = await fetchLitellmPriceCatalog(
|
|
13
|
+
fetchFn ? { fetchFn } : {},
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const catalog: PriceCatalog = {
|
|
17
|
+
...fetched,
|
|
18
|
+
user_overrides: existing?.user_overrides ?? {},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
await runtime.store.putPriceCatalog(catalog);
|
|
22
|
+
runtime.priceCatalog = catalog;
|
|
23
|
+
|
|
24
|
+
return { modelCount, lastUpdated: catalog.last_updated };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function formatPricingStalenessLine(catalog: PriceCatalog | null): string | undefined {
|
|
28
|
+
const staleness = checkStaleness(
|
|
29
|
+
catalog,
|
|
30
|
+
DEFAULT_OPERATOR_CONFIG.pricing.staleness_days,
|
|
31
|
+
);
|
|
32
|
+
return staleness.warning;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function notifyPricingStalenessIfNeeded(
|
|
36
|
+
runtime: SmartRouterRuntime,
|
|
37
|
+
notify: (message: string, level: 'info' | 'warning' | 'error') => void,
|
|
38
|
+
): void {
|
|
39
|
+
const stalenessLine = formatPricingStalenessLine(runtime.priceCatalog);
|
|
40
|
+
if (stalenessLine) {
|
|
41
|
+
notify(stalenessLine, 'warning');
|
|
42
|
+
}
|
|
43
|
+
}
|