@mupt-ai/dari-gateway 0.1.0 → 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 +8 -1
- package/dist/bun.d.ts +2 -0
- package/dist/bun.js +4 -0
- package/dist/context/eval_catalog.d.ts +3 -0
- package/dist/context/eval_catalog.js +7 -0
- package/dist/context/interaction_fingerprint.d.ts +27 -0
- package/dist/context/interaction_fingerprint.js +519 -0
- package/dist/context/interaction_fingerprint_format.d.ts +42 -0
- package/dist/context/interaction_fingerprint_format.js +113 -0
- package/dist/context/interaction_lease_depth.d.ts +2 -0
- package/dist/context/interaction_lease_depth.js +110 -0
- package/dist/context/lease_history.d.ts +7 -0
- package/dist/context/lease_history.js +158 -0
- package/dist/context/pricing.d.ts +4 -0
- package/dist/context/pricing.js +23 -0
- package/dist/context/provider_prompt_accounting.d.ts +14 -0
- package/dist/context/provider_prompt_accounting.js +187 -0
- package/dist/context/routing_context.d.ts +40 -0
- package/dist/context/routing_context.js +211 -0
- package/dist/http/auth.d.ts +2 -0
- package/dist/http/auth.js +35 -0
- package/dist/http/errors.d.ts +19 -0
- package/dist/http/errors.js +89 -0
- package/dist/http/handler.d.ts +12 -0
- package/dist/http/handler.js +81 -0
- package/dist/http/http2_server.d.ts +6 -0
- package/dist/http/http2_server.js +103 -0
- package/dist/http/serve.d.ts +20 -0
- package/dist/http/serve.js +78 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/ingress/anthropic_messages.d.ts +3 -0
- package/dist/ingress/anthropic_messages.js +122 -0
- package/dist/ingress/anthropic_models.d.ts +1 -0
- package/dist/ingress/anthropic_models.js +23 -0
- package/dist/ingress/chat_completions.d.ts +2 -0
- package/dist/ingress/chat_completions.js +37 -0
- package/dist/ingress/claude_code/request_context.d.ts +2 -0
- package/dist/ingress/claude_code/request_context.js +31 -0
- package/dist/ingress/codex.d.ts +3 -0
- package/dist/ingress/codex.js +65 -0
- package/dist/ingress/codex_models.d.ts +2 -0
- package/dist/ingress/codex_models.js +89 -0
- package/dist/ingress/json.d.ts +1 -0
- package/dist/ingress/json.js +95 -0
- package/dist/ingress/models.d.ts +1 -0
- package/dist/ingress/models.js +53 -0
- package/dist/interaction/capabilities.d.ts +3 -0
- package/dist/interaction/capabilities.js +24 -0
- package/dist/interaction/image.d.ts +4 -0
- package/dist/interaction/image.js +13 -0
- package/dist/interaction/portable_reasoning_state.d.ts +4 -0
- package/dist/interaction/portable_reasoning_state.js +18 -0
- package/dist/interaction/provider_continuation_state.d.ts +6 -0
- package/dist/interaction/provider_continuation_state.js +27 -0
- package/dist/interaction/tool_identity.d.ts +10 -0
- package/dist/interaction/tool_identity.js +41 -0
- package/dist/interaction/types.d.ts +203 -0
- package/dist/interaction/types.js +5 -0
- package/dist/models/context_limits.d.ts +2 -0
- package/dist/models/context_limits.js +7 -0
- package/dist/models/execution_provider.d.ts +8 -0
- package/dist/models/execution_provider.js +13 -0
- package/dist/models/gateways.d.ts +11 -0
- package/dist/models/gateways.js +45 -0
- package/dist/models/ids.d.ts +1 -0
- package/dist/models/ids.js +15 -0
- package/dist/models/provider_defaults.d.ts +4 -0
- package/dist/models/provider_defaults.js +41 -0
- package/dist/models/runtime_overrides.d.ts +4 -0
- package/dist/models/runtime_overrides.js +209 -0
- package/dist/observability/errors.d.ts +8 -0
- package/dist/observability/errors.js +11 -0
- package/dist/platform/platform.d.ts +152 -0
- package/dist/platform/platform.js +11 -0
- package/dist/platform/routing_contract.d.ts +2 -0
- package/dist/platform/routing_contract.js +5 -0
- package/dist/protocol/input/anthropic_messages.d.ts +2 -0
- package/dist/protocol/input/anthropic_messages.js +494 -0
- package/dist/protocol/input/chat_completions.d.ts +4 -0
- package/dist/protocol/input/chat_completions.js +212 -0
- package/dist/protocol/input/chat_completions_validation.d.ts +2 -0
- package/dist/protocol/input/chat_completions_validation.js +257 -0
- package/dist/protocol/input/openai_responses.d.ts +2 -0
- package/dist/protocol/input/openai_responses.js +666 -0
- package/dist/protocol/input/router_model.d.ts +7 -0
- package/dist/protocol/input/router_model.js +43 -0
- package/dist/protocol/output/anthropic_messages.d.ts +10 -0
- package/dist/protocol/output/anthropic_messages.js +15 -0
- package/dist/protocol/output/anthropic_messages_output.d.ts +10 -0
- package/dist/protocol/output/anthropic_messages_output.js +124 -0
- package/dist/protocol/output/anthropic_messages_stream.d.ts +16 -0
- package/dist/protocol/output/anthropic_messages_stream.js +267 -0
- package/dist/protocol/output/chat_completions.d.ts +29 -0
- package/dist/protocol/output/chat_completions.js +406 -0
- package/dist/protocol/output/chat_reasoning_detail.d.ts +2 -0
- package/dist/protocol/output/chat_reasoning_detail.js +13 -0
- package/dist/protocol/output/delivered_stream_snapshot.d.ts +10 -0
- package/dist/protocol/output/delivered_stream_snapshot.js +31 -0
- package/dist/protocol/output/openai_responses.d.ts +10 -0
- package/dist/protocol/output/openai_responses.js +14 -0
- package/dist/protocol/output/openai_responses_output.d.ts +14 -0
- package/dist/protocol/output/openai_responses_output.js +125 -0
- package/dist/protocol/output/openai_responses_stream.d.ts +18 -0
- package/dist/protocol/output/openai_responses_stream.js +546 -0
- package/dist/protocol/output/sse_stream.d.ts +31 -0
- package/dist/protocol/output/sse_stream.js +67 -0
- package/dist/providers/anthropic_safeguards.d.ts +11 -0
- package/dist/providers/anthropic_safeguards.js +81 -0
- package/dist/providers/aws_assume_role.d.ts +17 -0
- package/dist/providers/aws_assume_role.js +107 -0
- package/dist/providers/cancel_estimate.d.ts +43 -0
- package/dist/providers/cancel_estimate.js +89 -0
- package/dist/providers/execution.d.ts +72 -0
- package/dist/providers/execution.js +491 -0
- package/dist/providers/model_capabilities.d.ts +11 -0
- package/dist/providers/model_capabilities.js +29 -0
- package/dist/providers/pi.d.ts +65 -0
- package/dist/providers/pi.js +319 -0
- package/dist/providers/pi_context.d.ts +7 -0
- package/dist/providers/pi_context.js +405 -0
- package/dist/providers/pi_options.d.ts +11 -0
- package/dist/providers/pi_options.js +398 -0
- package/dist/providers/pi_output.d.ts +2 -0
- package/dist/providers/pi_output.js +453 -0
- package/dist/providers/provider_attempt_runner.d.ts +55 -0
- package/dist/providers/provider_attempt_runner.js +90 -0
- package/dist/providers/provider_call.d.ts +77 -0
- package/dist/providers/provider_call.js +292 -0
- package/dist/providers/provider_reported_cost.d.ts +10 -0
- package/dist/providers/provider_reported_cost.js +123 -0
- package/dist/providers/reasoning.d.ts +12 -0
- package/dist/providers/reasoning.js +30 -0
- package/dist/providers/response_capture.d.ts +23 -0
- package/dist/providers/response_capture.js +47 -0
- package/dist/providers/stream_finalization.d.ts +46 -0
- package/dist/providers/stream_finalization.js +165 -0
- package/dist/providers/subscription_limits.d.ts +31 -0
- package/dist/providers/subscription_limits.js +163 -0
- package/dist/providers/subscription_usage.d.ts +10 -0
- package/dist/providers/subscription_usage.js +79 -0
- package/dist/runtime/claude_code/auxiliary_routing.d.ts +3 -0
- package/dist/runtime/claude_code/auxiliary_routing.js +60 -0
- package/dist/runtime/customer_disconnect.d.ts +20 -0
- package/dist/runtime/customer_disconnect.js +49 -0
- package/dist/runtime/explicit_model.d.ts +4 -0
- package/dist/runtime/explicit_model.js +53 -0
- package/dist/runtime/harness_identity/conversation.d.ts +33 -0
- package/dist/runtime/harness_identity/conversation.js +39 -0
- package/dist/runtime/harness_identity/extract.d.ts +8 -0
- package/dist/runtime/harness_identity/extract.js +214 -0
- package/dist/runtime/harness_identity/index.d.ts +2 -0
- package/dist/runtime/harness_identity/index.js +2 -0
- package/dist/runtime/prepare_routed_completion.d.ts +33 -0
- package/dist/runtime/prepare_routed_completion.js +167 -0
- package/dist/runtime/provider_stream_lifecycle.d.ts +31 -0
- package/dist/runtime/provider_stream_lifecycle.js +88 -0
- package/dist/runtime/provider_stream_outcome.d.ts +23 -0
- package/dist/runtime/provider_stream_outcome.js +55 -0
- package/dist/runtime/request_tags.d.ts +7 -0
- package/dist/runtime/request_tags.js +33 -0
- package/dist/runtime/routed_completion.d.ts +17 -0
- package/dist/runtime/routed_completion.js +80 -0
- package/dist/runtime/routed_protocol.d.ts +30 -0
- package/dist/runtime/routed_protocol.js +1 -0
- package/dist/runtime/routed_runtime.d.ts +40 -0
- package/dist/runtime/routed_runtime.js +535 -0
- package/dist/runtime/routing_lease.d.ts +26 -0
- package/dist/runtime/routing_lease.js +210 -0
- package/dist/runtime/runtime_reporter.d.ts +71 -0
- package/dist/runtime/runtime_reporter.js +35 -0
- package/dist/self_host/config.d.ts +46 -0
- package/dist/self_host/config.js +105 -0
- package/dist/self_host/main.d.ts +16 -0
- package/dist/self_host/main.js +95 -0
- package/dist/self_host/platform.d.ts +13 -0
- package/dist/self_host/platform.js +50 -0
- package/dist/self_host/prefix_store.d.ts +46 -0
- package/dist/self_host/prefix_store.js +261 -0
- package/dist/self_host/resolve.d.ts +28 -0
- package/dist/self_host/resolve.js +171 -0
- package/dist/self_host/subscriptions/access.d.ts +10 -0
- package/dist/self_host/subscriptions/access.js +37 -0
- package/dist/self_host/subscriptions/http.d.ts +15 -0
- package/dist/self_host/subscriptions/http.js +187 -0
- package/dist/self_host/subscriptions/index.d.ts +24 -0
- package/dist/self_host/subscriptions/index.js +24 -0
- package/dist/self_host/subscriptions/oauth.d.ts +55 -0
- package/dist/self_host/subscriptions/oauth.js +281 -0
- package/dist/self_host/subscriptions/store.d.ts +78 -0
- package/dist/self_host/subscriptions/store.js +235 -0
- package/dist/strategies/auto_routing_selector.d.ts +12 -0
- package/dist/strategies/auto_routing_selector.js +61 -0
- package/dist/strategies/eval_relevance.d.ts +17 -0
- package/dist/strategies/eval_relevance.js +32 -0
- package/dist/strategies/fallback_decision.d.ts +8 -0
- package/dist/strategies/fallback_decision.js +17 -0
- package/dist/strategies/priority_selector.d.ts +7 -0
- package/dist/strategies/priority_selector.js +37 -0
- package/dist/strategies/route_decision.d.ts +22 -0
- package/dist/strategies/route_decision.js +65 -0
- package/dist/strategies/routing.d.ts +74 -0
- package/dist/strategies/routing.js +280 -0
- package/dist/strategies/selector_projection.d.ts +15 -0
- package/dist/strategies/selector_projection.js +161 -0
- package/dist/telemetry/background.d.ts +7 -0
- package/dist/telemetry/background.js +33 -0
- package/dist/telemetry/benchmark_replay.d.ts +37 -0
- package/dist/telemetry/benchmark_replay.js +108 -0
- package/dist/telemetry/billing_finalization.d.ts +64 -0
- package/dist/telemetry/billing_finalization.js +96 -0
- package/dist/telemetry/ingest_values.d.ts +4 -0
- package/dist/telemetry/ingest_values.js +12 -0
- package/dist/telemetry/model_cost.d.ts +3 -0
- package/dist/telemetry/model_cost.js +15 -0
- package/dist/telemetry/prefix_state.d.ts +47 -0
- package/dist/telemetry/prefix_state.js +116 -0
- package/dist/telemetry/report.d.ts +88 -0
- package/dist/telemetry/report.js +621 -0
- package/dist/telemetry/requests/interaction_observability.d.ts +45 -0
- package/dist/telemetry/requests/interaction_observability.js +180 -0
- package/dist/telemetry/requests/retained_interaction_request.d.ts +8 -0
- package/dist/telemetry/requests/retained_interaction_request.js +10 -0
- package/dist/telemetry/scrub.d.ts +2 -0
- package/dist/telemetry/scrub.js +31 -0
- package/dist/telemetry/skills/claude/catalog.d.ts +6 -0
- package/dist/telemetry/skills/claude/catalog.js +99 -0
- package/dist/telemetry/skills/claude/file_reads.d.ts +4 -0
- package/dist/telemetry/skills/claude/file_reads.js +110 -0
- package/dist/telemetry/skills/claude/observations.d.ts +3 -0
- package/dist/telemetry/skills/claude/observations.js +366 -0
- package/dist/telemetry/skills/codex/catalog.d.ts +11 -0
- package/dist/telemetry/skills/codex/catalog.js +138 -0
- package/dist/telemetry/skills/codex/exec_file_reads.d.ts +9 -0
- package/dist/telemetry/skills/codex/exec_file_reads.js +36 -0
- package/dist/telemetry/skills/codex/explicit.d.ts +3 -0
- package/dist/telemetry/skills/codex/explicit.js +90 -0
- package/dist/telemetry/skills/codex/file_reads.d.ts +4 -0
- package/dist/telemetry/skills/codex/file_reads.js +37 -0
- package/dist/telemetry/skills/codex/identity.d.ts +2 -0
- package/dist/telemetry/skills/codex/identity.js +20 -0
- package/dist/telemetry/skills/observations.d.ts +21 -0
- package/dist/telemetry/skills/observations.js +41 -0
- package/dist/telemetry/skills/paths.d.ts +11 -0
- package/dist/telemetry/skills/paths.js +61 -0
- package/dist/telemetry/skills/pi.d.ts +6 -0
- package/dist/telemetry/skills/pi.js +223 -0
- package/dist/telemetry/skills/shell_file_reads.d.ts +7 -0
- package/dist/telemetry/skills/shell_file_reads.js +226 -0
- package/dist/telemetry/skills/shell_words.d.ts +13 -0
- package/dist/telemetry/skills/shell_words.js +189 -0
- package/dist/telemetry/tools/input.d.ts +2 -0
- package/dist/telemetry/tools/input.js +14 -0
- package/dist/telemetry/tools/observations.d.ts +29 -0
- package/dist/telemetry/tools/observations.js +247 -0
- package/dist/telemetry/usage.d.ts +57 -0
- package/dist/telemetry/usage.js +136 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.js +1 -0
- package/package.json +22 -5
- package/src/bun.ts +4 -0
- package/src/context/eval_catalog.ts +1 -1
- package/src/context/interaction_fingerprint.ts +9 -9
- package/src/context/interaction_fingerprint_format.ts +1 -1
- package/src/context/interaction_lease_depth.ts +1 -1
- package/src/context/pricing.ts +1 -1
- package/src/context/provider_prompt_accounting.ts +5 -5
- package/src/context/routing_context.ts +17 -17
- package/src/http/auth.ts +1 -1
- package/src/http/handler.ts +8 -8
- package/src/http/serve.ts +3 -3
- package/src/index.ts +10 -9
- package/src/ingress/anthropic_messages.ts +12 -12
- package/src/ingress/anthropic_models.ts +1 -1
- package/src/ingress/chat_completions.ts +9 -9
- package/src/ingress/claude_code/request_context.ts +2 -2
- package/src/ingress/codex.ts +10 -10
- package/src/ingress/codex_models.ts +4 -4
- package/src/ingress/json.ts +1 -1
- package/src/ingress/models.ts +10 -10
- package/src/interaction/capabilities.ts +1 -1
- package/src/interaction/portable_reasoning_state.ts +1 -1
- package/src/interaction/provider_continuation_state.ts +1 -1
- package/src/interaction/tool_identity.ts +2 -2
- package/src/interaction/types.ts +3 -0
- package/src/models/context_limits.ts +1 -1
- package/src/models/execution_provider.ts +1 -1
- package/src/models/ids.ts +1 -1
- package/src/models/provider_defaults.ts +1 -1
- package/src/models/runtime_overrides.ts +1 -1
- package/src/observability/errors.ts +2 -2
- package/src/platform/platform.ts +36 -4
- package/src/protocol/input/anthropic_messages.ts +7 -7
- package/src/protocol/input/chat_completions.ts +5 -5
- package/src/protocol/input/chat_completions_validation.ts +4 -4
- package/src/protocol/input/openai_responses.ts +6 -6
- package/src/protocol/output/anthropic_messages.ts +3 -3
- package/src/protocol/output/anthropic_messages_output.ts +6 -4
- package/src/protocol/output/anthropic_messages_stream.ts +7 -7
- package/src/protocol/output/chat_completions.ts +13 -13
- package/src/protocol/output/chat_reasoning_detail.ts +1 -1
- package/src/protocol/output/openai_responses.ts +3 -3
- package/src/protocol/output/openai_responses_output.ts +4 -2
- package/src/protocol/output/openai_responses_stream.ts +6 -6
- package/src/protocol/output/sse_stream.ts +3 -3
- package/src/providers/anthropic_safeguards.ts +2 -2
- package/src/providers/aws_assume_role.ts +2 -2
- package/src/providers/cancel_estimate.ts +1 -1
- package/src/providers/execution.ts +17 -17
- package/src/providers/pi.ts +115 -41
- package/src/providers/pi_context.ts +6 -6
- package/src/providers/pi_options.ts +283 -453
- package/src/providers/pi_output.ts +6 -5
- package/src/providers/provider_attempt_runner.ts +1 -1
- package/src/providers/provider_call.ts +37 -18
- package/src/providers/provider_reported_cost.ts +138 -0
- package/src/providers/reasoning.ts +2 -2
- package/src/providers/stream_finalization.ts +10 -10
- package/src/providers/subscription_limits.ts +3 -3
- package/src/runtime/claude_code/auxiliary_routing.ts +5 -5
- package/src/runtime/customer_disconnect.ts +1 -1
- package/src/runtime/explicit_model.ts +31 -4
- package/src/runtime/harness_identity/conversation.ts +1 -1
- package/src/runtime/harness_identity/extract.ts +3 -3
- package/src/runtime/harness_identity/index.ts +2 -2
- package/src/runtime/prepare_routed_completion.ts +46 -10
- package/src/runtime/provider_stream_lifecycle.ts +1 -1
- package/src/runtime/provider_stream_outcome.ts +2 -2
- package/src/runtime/request_tags.ts +34 -0
- package/src/runtime/routed_completion.ts +13 -11
- package/src/runtime/routed_protocol.ts +2 -2
- package/src/runtime/routed_runtime.ts +38 -20
- package/src/runtime/routing_lease.ts +7 -7
- package/src/runtime/runtime_reporter.ts +3 -3
- package/src/self_host/main.ts +19 -14
- package/src/self_host/platform.ts +5 -5
- package/src/self_host/prefix_store.ts +2 -2
- package/src/self_host/resolve.ts +11 -11
- package/src/self_host/subscriptions/access.ts +2 -2
- package/src/self_host/subscriptions/http.ts +2 -2
- package/src/self_host/subscriptions/index.ts +4 -4
- package/src/self_host/subscriptions/store.ts +1 -1
- package/src/strategies/auto_routing_selector.ts +2 -2
- package/src/strategies/eval_relevance.ts +3 -3
- package/src/strategies/priority_selector.ts +1 -1
- package/src/strategies/route_decision.ts +7 -7
- package/src/strategies/routing.ts +11 -11
- package/src/strategies/selector_projection.ts +2 -2
- package/src/telemetry/billing_finalization.ts +3 -3
- package/src/telemetry/model_cost.ts +1 -1
- package/src/telemetry/prefix_state.ts +4 -4
- package/src/telemetry/report.ts +30 -25
- package/src/telemetry/requests/interaction_observability.ts +1 -1
- package/src/telemetry/requests/retained_interaction_request.ts +1 -1
- package/src/telemetry/skills/claude/catalog.ts +1 -1
- package/src/telemetry/skills/claude/file_reads.ts +6 -6
- package/src/telemetry/skills/claude/observations.ts +3 -3
- package/src/telemetry/skills/codex/catalog.ts +3 -3
- package/src/telemetry/skills/codex/exec_file_reads.ts +4 -4
- package/src/telemetry/skills/codex/explicit.ts +3 -3
- package/src/telemetry/skills/codex/file_reads.ts +5 -5
- package/src/telemetry/skills/observations.ts +7 -7
- package/src/telemetry/skills/pi.ts +3 -3
- package/src/telemetry/skills/shell_file_reads.ts +2 -2
- package/src/telemetry/skills/shell_words.ts +1 -1
- package/src/telemetry/tools/input.ts +1 -1
- package/src/telemetry/tools/observations.ts +9 -9
- package/src/telemetry/usage.ts +9 -5
- package/src/types.ts +15 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
|
|
3
|
-
import { isBackgroundRequest, type InteractionRequest } from "../interaction/types";
|
|
4
|
-
import { explicitModelId } from "../protocol/input/router_model";
|
|
5
|
-
import { captureRequestError } from "../observability/errors";
|
|
6
|
-
import type { SelectorBackend } from "../strategies/routing";
|
|
7
|
-
import type { ClientHarness } from "../types";
|
|
8
|
-
import { assertAutoroutingAllowed, assertCreditAvailableBeforeRouting, routerSelectsModels } from "../telemetry/usage";
|
|
9
|
-
import type { HarnessConversationIdentity } from "./harness_identity";
|
|
10
|
-
import { CustomerDisconnectedError } from "./customer_disconnect";
|
|
11
|
-
import { prepareRoutedCompletion } from "./prepare_routed_completion";
|
|
12
|
-
import type { RoutedProtocol } from "./routed_protocol";
|
|
13
|
-
import { runPreparedRoutedCompletion } from "./routed_runtime";
|
|
3
|
+
import { isBackgroundRequest, type InteractionRequest } from "../interaction/types.js";
|
|
4
|
+
import { explicitModelId } from "../protocol/input/router_model.js";
|
|
5
|
+
import { captureRequestError } from "../observability/errors.js";
|
|
6
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
7
|
+
import type { ClientHarness } from "../types.js";
|
|
8
|
+
import { assertAutoroutingAllowed, assertCreditAvailableBeforeRouting, routerSelectsModels } from "../telemetry/usage.js";
|
|
9
|
+
import type { HarnessConversationIdentity } from "./harness_identity/index.js";
|
|
10
|
+
import { CustomerDisconnectedError } from "./customer_disconnect.js";
|
|
11
|
+
import { prepareRoutedCompletion } from "./prepare_routed_completion.js";
|
|
12
|
+
import type { RoutedProtocol } from "./routed_protocol.js";
|
|
13
|
+
import { runPreparedRoutedCompletion } from "./routed_runtime.js";
|
|
14
14
|
|
|
15
15
|
export async function handleRoutedCompletion(args: {
|
|
16
16
|
request: Request;
|
|
@@ -37,6 +37,7 @@ export async function handleRoutedCompletion(args: {
|
|
|
37
37
|
startedMs,
|
|
38
38
|
requestId,
|
|
39
39
|
clientRequestId,
|
|
40
|
+
tagsHeader: args.request.headers.get("x-dari-tags"),
|
|
40
41
|
clientHarness: args.clientHarness,
|
|
41
42
|
harnessConversationIdentity: args.harnessConversationIdentity,
|
|
42
43
|
}).catch((error: unknown) => ({ error }));
|
|
@@ -56,6 +57,7 @@ export async function handleRoutedCompletion(args: {
|
|
|
56
57
|
// Only auto-selection needs the plan: an explicitly requested model and
|
|
57
58
|
// background work are served without the selector.
|
|
58
59
|
const selects =
|
|
60
|
+
prepared.credentials.strict !== true &&
|
|
59
61
|
explicitModelId(prepared.interaction.model) === null &&
|
|
60
62
|
!isBackgroundRequest(prepared.interaction) &&
|
|
61
63
|
routerSelectsModels(prepared.credentials);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import type { InteractionOutput, InteractionRequest, ProviderIdentity } from "../interaction/types";
|
|
3
|
-
import type { ProviderStreamOutcome } from "./provider_stream_outcome";
|
|
2
|
+
import type { InteractionOutput, InteractionRequest, ProviderIdentity } from "../interaction/types.js";
|
|
3
|
+
import type { ProviderStreamOutcome } from "./provider_stream_outcome.js";
|
|
4
4
|
|
|
5
5
|
export type RoutedCompletionResponseArgs = {
|
|
6
6
|
id: string;
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
type RoutingDecision,
|
|
9
9
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
10
10
|
|
|
11
|
-
import { buildRoutingContext } from "../context/routing_context";
|
|
12
|
-
import type { InteractionRequest } from "../interaction/types";
|
|
11
|
+
import { buildRoutingContext } from "../context/routing_context.js";
|
|
12
|
+
import type { InteractionRequest } from "../interaction/types.js";
|
|
13
13
|
import {
|
|
14
14
|
completeNonStreaming,
|
|
15
15
|
executeNonStreaming,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
prepareStreamingExecution,
|
|
18
18
|
type CompletedNonStreamingExecution,
|
|
19
19
|
type ProviderChoice,
|
|
20
|
-
} from "../providers/execution";
|
|
20
|
+
} from "../providers/execution.js";
|
|
21
21
|
import {
|
|
22
22
|
prepareProviderExecution,
|
|
23
23
|
startProviderCompletion,
|
|
@@ -25,18 +25,18 @@ import {
|
|
|
25
25
|
type ProviderExecution,
|
|
26
26
|
type StartedCompletion,
|
|
27
27
|
type StartedStream,
|
|
28
|
-
} from "../providers/provider_call";
|
|
29
|
-
import type { SelectorBackend } from "../strategies/routing";
|
|
30
|
-
import { routeDecision, type RoutedDecision } from "../strategies/route_decision";
|
|
31
|
-
import { executionProviderForModel } from "../models/execution_provider";
|
|
32
|
-
import { trackBackgroundTelemetry } from "../telemetry/background";
|
|
33
|
-
import { estimateBenchmarkReplay } from "../telemetry/benchmark_replay";
|
|
34
|
-
import { buildCompletedPrefixHit } from "../telemetry/prefix_state";
|
|
35
|
-
import { scrubSecrets } from "../telemetry/scrub";
|
|
36
|
-
import type { ResolvedRouter } from "../types";
|
|
37
|
-
import type { PreparedRoutedCompletion } from "./prepare_routed_completion";
|
|
28
|
+
} from "../providers/provider_call.js";
|
|
29
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
30
|
+
import { routeDecision, type RoutedDecision } from "../strategies/route_decision.js";
|
|
31
|
+
import { executionProviderForModel } from "../models/execution_provider.js";
|
|
32
|
+
import { trackBackgroundTelemetry } from "../telemetry/background.js";
|
|
33
|
+
import { estimateBenchmarkReplay } from "../telemetry/benchmark_replay.js";
|
|
34
|
+
import { buildCompletedPrefixHit } from "../telemetry/prefix_state.js";
|
|
35
|
+
import { scrubSecrets } from "../telemetry/scrub.js";
|
|
36
|
+
import type { ResolvedRouter } from "../types.js";
|
|
37
|
+
import type { PreparedRoutedCompletion } from "./prepare_routed_completion.js";
|
|
38
38
|
import { auxiliaryDecision } from "./claude_code/auxiliary_routing.js";
|
|
39
|
-
import { explicitModelDecision } from "./explicit_model.js";
|
|
39
|
+
import { explicitModelDecision, strictModelDecision } from "./explicit_model.js";
|
|
40
40
|
import {
|
|
41
41
|
clearPendingLease,
|
|
42
42
|
committedLeaseDecision,
|
|
@@ -47,12 +47,12 @@ import {
|
|
|
47
47
|
prefetchNextLease,
|
|
48
48
|
selectorNegotiatesLeases,
|
|
49
49
|
} from "./routing_lease.js";
|
|
50
|
-
import type { RoutedProtocol } from "./routed_protocol";
|
|
50
|
+
import type { RoutedProtocol } from "./routed_protocol.js";
|
|
51
51
|
import {
|
|
52
52
|
createExperimentRoutedRuntimeReporter,
|
|
53
53
|
type RoutedRuntimeReporter,
|
|
54
|
-
} from "./runtime_reporter";
|
|
55
|
-
import { HttpError } from "../http/errors";
|
|
54
|
+
} from "./runtime_reporter.js";
|
|
55
|
+
import { HttpError } from "../http/errors.js";
|
|
56
56
|
|
|
57
57
|
type SpeculativeExecution = {
|
|
58
58
|
decision: RoutingDecision;
|
|
@@ -113,12 +113,12 @@ export type {
|
|
|
113
113
|
SelectorAdapterArgs,
|
|
114
114
|
SelectorBackend,
|
|
115
115
|
SelectorRun,
|
|
116
|
-
} from "../strategies/routing";
|
|
116
|
+
} from "../strategies/routing.js";
|
|
117
117
|
export type {
|
|
118
118
|
ExperimentRoutedRuntimeReporter,
|
|
119
119
|
RoutedRuntimeReporter,
|
|
120
|
-
} from "./runtime_reporter";
|
|
121
|
-
export { createExperimentRoutedRuntimeReporter } from "./runtime_reporter";
|
|
120
|
+
} from "./runtime_reporter.js";
|
|
121
|
+
export { createExperimentRoutedRuntimeReporter } from "./runtime_reporter.js";
|
|
122
122
|
|
|
123
123
|
export async function runPreparedRoutedCompletion(args: {
|
|
124
124
|
prepared: PreparedRoutedCompletion;
|
|
@@ -238,6 +238,7 @@ async function prepareExplicitRoutedCompletion(
|
|
|
238
238
|
protocol: inProcessProtocol,
|
|
239
239
|
credentials: args.credentials,
|
|
240
240
|
billable: args.billable ?? false,
|
|
241
|
+
tags: {},
|
|
241
242
|
harnessConversationIdentity: undefined,
|
|
242
243
|
routing,
|
|
243
244
|
reporter: args.reporter ?? createExperimentRoutedRuntimeReporter(),
|
|
@@ -252,6 +253,21 @@ async function prepareRuntimeExecution(args: {
|
|
|
252
253
|
}): Promise<RuntimeExecutionPlan> {
|
|
253
254
|
const { prepared } = args;
|
|
254
255
|
|
|
256
|
+
// A strict router never selects, leases, or falls back: the pinned pair or
|
|
257
|
+
// an error.
|
|
258
|
+
if (prepared.credentials.strict === true) {
|
|
259
|
+
const pinned = strictModelDecision(prepared);
|
|
260
|
+
prepared.reporter.attachServingDecision(pinned.decision);
|
|
261
|
+
prepared.reporter.attachDecisionDetails({
|
|
262
|
+
decision_source: "strict_model",
|
|
263
|
+
explicit_model: {
|
|
264
|
+
model: pinned.decision.selectedModel,
|
|
265
|
+
reasoning_effort: pinned.decision.reasoningEffort,
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
return selectedExecutionPlan(prepared, pinned);
|
|
269
|
+
}
|
|
270
|
+
|
|
255
271
|
// A requested `dari/model/<id>` is served as chosen, before any lease.
|
|
256
272
|
const explicit = args.requireSelectorDecision ? null : explicitModelDecision(prepared);
|
|
257
273
|
if (explicit) {
|
|
@@ -621,6 +637,7 @@ function providerExecution(
|
|
|
621
637
|
conversationId: prepared.routing.conversationId,
|
|
622
638
|
costEstimates: prepared.routing.reportingCostEstimates,
|
|
623
639
|
promptCacheKey: prepared.interaction.promptCacheKey,
|
|
640
|
+
tags: prepared.tags,
|
|
624
641
|
});
|
|
625
642
|
}
|
|
626
643
|
|
|
@@ -692,6 +709,7 @@ const inProcessProtocol: RoutedProtocol = {
|
|
|
692
709
|
selected_model: args.routing.selectedModel,
|
|
693
710
|
reasoning_effort: args.routing.reasoningEffort,
|
|
694
711
|
reason: args.routing.reason,
|
|
712
|
+
request_id: args.id,
|
|
695
713
|
...(args.conversationId ? { conversation_id: args.conversationId } : {}),
|
|
696
714
|
},
|
|
697
715
|
}),
|
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
type RoutingDecision,
|
|
7
7
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
8
8
|
|
|
9
|
-
import { deriveFallbackDecision } from "../strategies/fallback_decision";
|
|
10
|
-
import { executionProviderForModel } from "../models/execution_provider";
|
|
11
|
-
import type { SelectorBackend } from "../strategies/routing";
|
|
9
|
+
import { deriveFallbackDecision } from "../strategies/fallback_decision.js";
|
|
10
|
+
import { executionProviderForModel } from "../models/execution_provider.js";
|
|
11
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
12
12
|
import {
|
|
13
13
|
routeDecision,
|
|
14
14
|
type RoutedDecision,
|
|
15
|
-
} from "../strategies/route_decision";
|
|
16
|
-
import { reportPendingLease } from "../telemetry/prefix_state";
|
|
17
|
-
import { scrubSecrets } from "../telemetry/scrub";
|
|
18
|
-
import type { PreparedRoutedCompletion } from "./prepare_routed_completion";
|
|
15
|
+
} from "../strategies/route_decision.js";
|
|
16
|
+
import { reportPendingLease } from "../telemetry/prefix_state.js";
|
|
17
|
+
import { scrubSecrets } from "../telemetry/scrub.js";
|
|
18
|
+
import type { PreparedRoutedCompletion } from "./prepare_routed_completion.js";
|
|
19
19
|
|
|
20
20
|
export type RoutingLeaseDecision = {
|
|
21
21
|
decision: RoutingDecision;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import type { InteractionOutput } from "../interaction/types";
|
|
3
|
-
import type { SelectorRun } from "../strategies/routing";
|
|
4
|
-
import type { ProviderKeySource } from "../types";
|
|
2
|
+
import type { InteractionOutput } from "../interaction/types.js";
|
|
3
|
+
import type { SelectorRun } from "../strategies/routing.js";
|
|
4
|
+
import type { ProviderKeySource } from "../types.js";
|
|
5
5
|
|
|
6
6
|
export type ReportedProviderExecution = {
|
|
7
7
|
provider: string;
|
package/src/self_host/main.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { chmodSync, existsSync } from "node:fs";
|
|
3
3
|
import { Database } from "bun:sqlite";
|
|
4
|
-
import {
|
|
4
|
+
import { builtinModels } from "@mupt-ai/pi-ai/providers/all";
|
|
5
5
|
|
|
6
|
-
import { bearerToken } from "../http/auth";
|
|
7
|
-
import { errorResponse, HttpError } from "../http/errors";
|
|
8
|
-
import { createRequestHandler } from "../http/handler";
|
|
9
|
-
import { installShutdownHandlers, startServer } from "../http/serve";
|
|
10
|
-
import { createAutoRoutingSelectorBackend } from "../strategies/auto_routing_selector";
|
|
11
|
-
import { createPrioritySelectorBackend } from "../strategies/priority_selector";
|
|
12
|
-
import type { SelectorBackend } from "../strategies/routing";
|
|
13
|
-
import { loadGatewayConfig } from "./config";
|
|
14
|
-
import { createSelfHostedPlatform } from "./platform";
|
|
15
|
-
import { gatewayKeyIndex } from "./resolve";
|
|
16
|
-
import { PrefixStore } from "./prefix_store";
|
|
17
|
-
import { handleSubscriptionRequest, SubscriptionStore } from "./subscriptions";
|
|
6
|
+
import { bearerToken } from "../http/auth.js";
|
|
7
|
+
import { errorResponse, HttpError } from "../http/errors.js";
|
|
8
|
+
import { createRequestHandler } from "../http/handler.js";
|
|
9
|
+
import { installShutdownHandlers, startServer } from "../http/serve.js";
|
|
10
|
+
import { createAutoRoutingSelectorBackend } from "../strategies/auto_routing_selector.js";
|
|
11
|
+
import { createPrioritySelectorBackend } from "../strategies/priority_selector.js";
|
|
12
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
13
|
+
import { loadGatewayConfig } from "./config.js";
|
|
14
|
+
import { createSelfHostedPlatform } from "./platform.js";
|
|
15
|
+
import { gatewayKeyIndex } from "./resolve.js";
|
|
16
|
+
import { PrefixStore } from "./prefix_store.js";
|
|
17
|
+
import { handleSubscriptionRequest, SubscriptionStore } from "./subscriptions/index.js";
|
|
18
18
|
|
|
19
19
|
const SUBSCRIPTION_ROUTES = "/v1/organizations/current/credentials";
|
|
20
20
|
|
|
@@ -45,13 +45,18 @@ export async function startSelfHostedGateway(env: Record<string, string> = proce
|
|
|
45
45
|
db.exec("PRAGMA journal_mode = WAL");
|
|
46
46
|
const subscriptions = new SubscriptionStore(db);
|
|
47
47
|
const prefixes = new PrefixStore(db);
|
|
48
|
+
// Pi's provider auth reads each provider's standard key variable, such as
|
|
49
|
+
// OPENAI_API_KEY, from this environment only.
|
|
50
|
+
const piModels = builtinModels({
|
|
51
|
+
authContext: { env: async (name) => env[name], fileExists: async () => false },
|
|
52
|
+
});
|
|
48
53
|
|
|
49
54
|
const platform = createSelfHostedPlatform({
|
|
50
55
|
config,
|
|
51
56
|
gatewayKeys,
|
|
52
57
|
subscriptions,
|
|
53
58
|
prefixes,
|
|
54
|
-
providerApiKey: (provider) =>
|
|
59
|
+
providerApiKey: async (provider) => (await piModels.getAuth(provider))?.auth.apiKey,
|
|
55
60
|
env,
|
|
56
61
|
fetch,
|
|
57
62
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { errorCode } from "../http/errors";
|
|
2
|
-
import type { GatewayPlatform } from "../platform/platform";
|
|
3
|
-
import type { PrefixStore } from "./prefix_store";
|
|
4
|
-
import { resolveSelfHostedRouter, type SelfHostedResolverDeps } from "./resolve";
|
|
5
|
-
import type { SubscriptionStore } from "./subscriptions";
|
|
1
|
+
import { errorCode } from "../http/errors.js";
|
|
2
|
+
import type { GatewayPlatform } from "../platform/platform.js";
|
|
3
|
+
import type { PrefixStore } from "./prefix_store.js";
|
|
4
|
+
import { resolveSelfHostedRouter, type SelfHostedResolverDeps } from "./resolve.js";
|
|
5
|
+
import type { SubscriptionStore } from "./subscriptions/index.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The self-hosted platform: routers from the config file, subscriptions and
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
import type { Database } from "bun:sqlite";
|
|
15
15
|
import type { ReasoningEffort, RouterPrefixHit } from "@mupt-ai/dari-router/policy-engine";
|
|
16
16
|
|
|
17
|
-
import type { PendingLeaseWrite, PrefixStateWrite } from "../platform/platform";
|
|
18
|
-
import { ROUTING_PREFIX_HASHES_MAX_COUNT } from "../platform/routing_contract";
|
|
17
|
+
import type { PendingLeaseWrite, PrefixStateWrite } from "../platform/platform.js";
|
|
18
|
+
import { ROUTING_PREFIX_HASHES_MAX_COUNT } from "../platform/routing_contract.js";
|
|
19
19
|
|
|
20
20
|
// Resolve returns entries up to this age so a continuation after a pause still
|
|
21
21
|
// recovers its conversation id and previous decision; the runtime itself
|
package/src/self_host/resolve.ts
CHANGED
|
@@ -7,22 +7,22 @@ import {
|
|
|
7
7
|
type RouterModelPrice,
|
|
8
8
|
type RouterPrefixHit,
|
|
9
9
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
10
|
-
import { HttpError } from "../http/errors";
|
|
11
|
-
import type { ResolveRouterRequest } from "../platform/platform";
|
|
12
|
-
import { registeredModelPrice } from "../providers/pi";
|
|
10
|
+
import { HttpError } from "../http/errors.js";
|
|
11
|
+
import type { ResolveRouterRequest } from "../platform/platform.js";
|
|
12
|
+
import { registeredModelPrice } from "../providers/pi.js";
|
|
13
13
|
import type {
|
|
14
14
|
ProviderKeySource,
|
|
15
15
|
ResolvedRouter,
|
|
16
16
|
ResolvedRouterModelConfig,
|
|
17
|
-
} from "../types";
|
|
18
|
-
import type { GatewayConfig, RouterConfig } from "./config";
|
|
17
|
+
} from "../types.js";
|
|
18
|
+
import type { GatewayConfig, RouterConfig } from "./config.js";
|
|
19
19
|
import {
|
|
20
20
|
freshAccessToken,
|
|
21
21
|
type OAuthFetch,
|
|
22
22
|
type SubscriptionCredential,
|
|
23
23
|
type SubscriptionProvider,
|
|
24
24
|
type SubscriptionStore,
|
|
25
|
-
} from "./subscriptions";
|
|
25
|
+
} from "./subscriptions/index.js";
|
|
26
26
|
|
|
27
27
|
// A self-hosted gateway is one tenant; these stand in for the hosted
|
|
28
28
|
// organization and the user a personal subscription belongs to.
|
|
@@ -41,7 +41,7 @@ export type SelfHostedResolverDeps = {
|
|
|
41
41
|
conversationId?: string;
|
|
42
42
|
}) => RouterPrefixHit[];
|
|
43
43
|
// The provider's API key from its standard environment variable.
|
|
44
|
-
providerApiKey: (provider: string) => string | undefined
|
|
44
|
+
providerApiKey: (provider: string) => Promise<string | undefined>;
|
|
45
45
|
env: Record<string, string | undefined>;
|
|
46
46
|
fetch: OAuthFetch;
|
|
47
47
|
};
|
|
@@ -92,7 +92,7 @@ export async function resolveSelfHostedRouter(
|
|
|
92
92
|
if (subscription !== null && deps.subscriptions.list(subscription).length > 0) {
|
|
93
93
|
exhausted.add(subscription);
|
|
94
94
|
}
|
|
95
|
-
const apiKey = providerApiKey(deps, provider);
|
|
95
|
+
const apiKey = await providerApiKey(deps, provider);
|
|
96
96
|
credentials.set(provider, apiKey ? { key: apiKey, source: "user" } : null);
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -137,7 +137,7 @@ export async function resolveSelfHostedRouter(
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
for (const model of models) {
|
|
140
|
-
const price =
|
|
140
|
+
const price = registeredModelPrice(model.id);
|
|
141
141
|
if (price !== null) resolved.model_prices![model.id] = price;
|
|
142
142
|
const provider = providerForModel(model.id);
|
|
143
143
|
const endpoint = deps.config.providers[provider];
|
|
@@ -158,9 +158,9 @@ export async function resolveSelfHostedRouter(
|
|
|
158
158
|
|
|
159
159
|
// Configured endpoints read their own key variable, or send a placeholder
|
|
160
160
|
// when they take none; known providers use their standard variable.
|
|
161
|
-
function providerApiKey(deps: SelfHostedResolverDeps, provider: string): string | undefined {
|
|
161
|
+
async function providerApiKey(deps: SelfHostedResolverDeps, provider: string): Promise<string | undefined> {
|
|
162
162
|
const endpoint = deps.config.providers[provider];
|
|
163
|
-
if (endpoint === undefined) return deps.providerApiKey(provider)?.trim() || undefined;
|
|
163
|
+
if (endpoint === undefined) return (await deps.providerApiKey(provider))?.trim() || undefined;
|
|
164
164
|
if (endpoint.apiKeyEnv === undefined) return "no-key";
|
|
165
165
|
return deps.env[endpoint.apiKeyEnv]?.trim() || undefined;
|
|
166
166
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { refreshOAuth, type OAuthFetch } from "./oauth";
|
|
2
|
-
import type { SubscriptionCredential, SubscriptionStore } from "./store";
|
|
1
|
+
import { refreshOAuth, type OAuthFetch } from "./oauth.js";
|
|
2
|
+
import type { SubscriptionCredential, SubscriptionStore } from "./store.js";
|
|
3
3
|
|
|
4
4
|
const REFRESH_MARGIN_MS = 5 * 60_000;
|
|
5
5
|
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
startOAuth,
|
|
13
13
|
type OAuthFetch,
|
|
14
14
|
type SubscriptionProvider,
|
|
15
|
-
} from "./oauth";
|
|
16
|
-
import { isHeld, type SubscriptionCredential, type SubscriptionStore } from "./store";
|
|
15
|
+
} from "./oauth.js";
|
|
16
|
+
import { isHeld, type SubscriptionCredential, type SubscriptionStore } from "./store.js";
|
|
17
17
|
|
|
18
18
|
export type SubscriptionHttpDeps = {
|
|
19
19
|
store: SubscriptionStore;
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* `store.markUnavailable` holds that subscription until its reset and says
|
|
19
19
|
* whether another one can serve the retry.
|
|
20
20
|
*/
|
|
21
|
-
export { freshAccessToken } from "./access";
|
|
22
|
-
export { handleSubscriptionRequest, type SubscriptionHttpDeps } from "./http";
|
|
21
|
+
export { freshAccessToken } from "./access.js";
|
|
22
|
+
export { handleSubscriptionRequest, type SubscriptionHttpDeps } from "./http.js";
|
|
23
23
|
export {
|
|
24
24
|
CODEX_APPROVAL_PENDING,
|
|
25
25
|
SUBSCRIPTION_PROVIDERS,
|
|
@@ -34,10 +34,10 @@ export {
|
|
|
34
34
|
type OAuthOptions,
|
|
35
35
|
type OAuthTokens,
|
|
36
36
|
type SubscriptionProvider,
|
|
37
|
-
} from "./oauth";
|
|
37
|
+
} from "./oauth.js";
|
|
38
38
|
export {
|
|
39
39
|
SubscriptionStore,
|
|
40
40
|
isHeld,
|
|
41
41
|
type PendingOAuthSession,
|
|
42
42
|
type SubscriptionCredential,
|
|
43
|
-
} from "./store";
|
|
43
|
+
} from "./store.js";
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import type { Database } from "bun:sqlite";
|
|
14
14
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
15
15
|
|
|
16
|
-
import type { OAuthTokens, SubscriptionProvider } from "./oauth";
|
|
16
|
+
import type { OAuthTokens, SubscriptionProvider } from "./oauth.js";
|
|
17
17
|
|
|
18
18
|
export type SubscriptionCredential = {
|
|
19
19
|
id: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseSelectorDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import { HttpError } from "../http/errors";
|
|
3
|
-
import type { SelectorBackend } from "./routing";
|
|
2
|
+
import { HttpError } from "../http/errors.js";
|
|
3
|
+
import type { SelectorBackend } from "./routing.js";
|
|
4
4
|
|
|
5
5
|
export const DARI_AUTO_ROUTING_ENDPOINT = "https://routing.dari.dev/v1/auto-router";
|
|
6
6
|
// Same selector identity and input budget as `createAutoRouter` in
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
type RouterEval,
|
|
9
9
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
10
10
|
|
|
11
|
-
import { publicCatalogSelectorEvals } from "../context/eval_catalog";
|
|
12
|
-
import { scrubSecrets } from "../telemetry/scrub";
|
|
13
|
-
import type { ResolvedRouter } from "../types";
|
|
11
|
+
import { publicCatalogSelectorEvals } from "../context/eval_catalog.js";
|
|
12
|
+
import { scrubSecrets } from "../telemetry/scrub.js";
|
|
13
|
+
import type { ResolvedRouter } from "../types.js";
|
|
14
14
|
|
|
15
15
|
export type EvalRelevanceDetails =
|
|
16
16
|
| {
|
|
@@ -5,13 +5,13 @@ import type {
|
|
|
5
5
|
StrategyCandidateResolution,
|
|
6
6
|
SelectorLeaseHistoryEntry,
|
|
7
7
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
8
|
-
import { publicCatalogSelectorEvals } from "../context/eval_catalog";
|
|
9
|
-
import { HttpError } from "../http/errors";
|
|
10
|
-
import { relevantEvals } from "./eval_relevance";
|
|
11
|
-
import { executionProviderForModel } from "../models/execution_provider";
|
|
12
|
-
import { selectModel, type SelectorBackend, type SelectorRun } from "./routing";
|
|
13
|
-
import type { SelectorImage } from "./selector_projection";
|
|
14
|
-
import type { ResolvedRouter } from "../types";
|
|
8
|
+
import { publicCatalogSelectorEvals } from "../context/eval_catalog.js";
|
|
9
|
+
import { HttpError } from "../http/errors.js";
|
|
10
|
+
import { relevantEvals } from "./eval_relevance.js";
|
|
11
|
+
import { executionProviderForModel } from "../models/execution_provider.js";
|
|
12
|
+
import { selectModel, type SelectorBackend, type SelectorRun } from "./routing.js";
|
|
13
|
+
import type { SelectorImage } from "./selector_projection.js";
|
|
14
|
+
import type { ResolvedRouter } from "../types.js";
|
|
15
15
|
|
|
16
16
|
export type RoutedDecision = {
|
|
17
17
|
decision: RoutingDecision;
|
|
@@ -21,21 +21,21 @@ import {
|
|
|
21
21
|
type SelectorInput,
|
|
22
22
|
type SelectorLeaseHistoryEntry,
|
|
23
23
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
24
|
-
import { HttpError } from "../http/errors";
|
|
25
|
-
import { executionProviderForModel } from "../models/execution_provider";
|
|
26
|
-
import { providerLabel } from "../models/provider_defaults";
|
|
27
|
-
import { internalChatCompletionsToInteraction } from "../protocol/input/chat_completions";
|
|
28
|
-
import { gatewayPlatform, type ResolveRouterRequest } from "../platform/platform";
|
|
29
|
-
import { isBedrockApi } from "../providers/model_capabilities";
|
|
30
|
-
import { completeInteractionModel, modelContextWindow } from "../providers/pi";
|
|
24
|
+
import { HttpError } from "../http/errors.js";
|
|
25
|
+
import { executionProviderForModel } from "../models/execution_provider.js";
|
|
26
|
+
import { providerLabel } from "../models/provider_defaults.js";
|
|
27
|
+
import { internalChatCompletionsToInteraction } from "../protocol/input/chat_completions.js";
|
|
28
|
+
import { gatewayPlatform, type ResolveRouterRequest } from "../platform/platform.js";
|
|
29
|
+
import { isBedrockApi } from "../providers/model_capabilities.js";
|
|
30
|
+
import { completeInteractionModel, modelContextWindow } from "../providers/pi.js";
|
|
31
31
|
import type {
|
|
32
32
|
AwsAssumeRoleProviderAuth,
|
|
33
33
|
AwsSigV4ProviderAuth,
|
|
34
34
|
ProviderAuth,
|
|
35
35
|
ResolvedRouter,
|
|
36
|
-
} from "../types";
|
|
37
|
-
import { deriveFallbackDecision } from "./fallback_decision";
|
|
38
|
-
import type { SelectorImage } from "./selector_projection";
|
|
36
|
+
} from "../types.js";
|
|
37
|
+
import { deriveFallbackDecision } from "./fallback_decision.js";
|
|
38
|
+
import type { SelectorImage } from "./selector_projection.js";
|
|
39
39
|
|
|
40
40
|
export function resolveRouter(args: ResolveRouterRequest): Promise<ResolvedRouter> {
|
|
41
41
|
return gatewayPlatform().resolveRouter(args);
|
|
@@ -188,7 +188,7 @@ export async function selectModel(
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
async function selectorContextWindowChars(selectorModel: string): Promise<number> {
|
|
191
|
-
const contextWindow =
|
|
191
|
+
const contextWindow = modelContextWindow(selectorModel);
|
|
192
192
|
if (contextWindow === null) {
|
|
193
193
|
throw new HttpError(
|
|
194
194
|
500,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ChatMessage } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { toolWireName } from "../interaction/tool_identity";
|
|
3
|
+
import { toolWireName } from "../interaction/tool_identity.js";
|
|
4
4
|
import type {
|
|
5
5
|
InteractionContent,
|
|
6
6
|
InteractionMessage,
|
|
7
7
|
InteractionRequest,
|
|
8
8
|
InteractionToolCall,
|
|
9
|
-
} from "../interaction/types";
|
|
9
|
+
} from "../interaction/types.js";
|
|
10
10
|
|
|
11
11
|
export const IMAGE_OMITTED = "<image omitted>";
|
|
12
12
|
// Matches every numbered placeholder in a rendered selector prompt.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { InteractionUsage } from "../interaction/types";
|
|
2
|
-
import type { ProviderKeySource } from "../types";
|
|
3
|
-
import { finiteNumber, isRecord, tokenCount } from "./ingest_values";
|
|
1
|
+
import type { InteractionUsage } from "../interaction/types.js";
|
|
2
|
+
import type { ProviderKeySource } from "../types.js";
|
|
3
|
+
import { finiteNumber, isRecord, tokenCount } from "./ingest_values.js";
|
|
4
4
|
|
|
5
5
|
const BILLING_EVENT_SCHEMA_VERSION = 1;
|
|
6
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RoutingBillingProviderAttemptFacts } from "./billing_finalization";
|
|
1
|
+
import type { RoutingBillingProviderAttemptFacts } from "./billing_finalization.js";
|
|
2
2
|
|
|
3
3
|
/** Model reference cost only, including retries; unknown/estimated usage is never free. */
|
|
4
4
|
export function modelCost(attempts: readonly RoutingBillingProviderAttemptFacts[]): number | null {
|
|
@@ -6,15 +6,15 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
extendInteractionChain,
|
|
8
8
|
extendInteractionLooseChain,
|
|
9
|
-
} from "../context/interaction_fingerprint";
|
|
9
|
+
} from "../context/interaction_fingerprint.js";
|
|
10
10
|
import type {
|
|
11
11
|
InteractionOutput,
|
|
12
12
|
InteractionRequest,
|
|
13
13
|
InteractionUsage,
|
|
14
14
|
ProviderIdentity,
|
|
15
|
-
} from "../interaction/types";
|
|
16
|
-
import { gatewayPlatform, type PrefixStateWrite } from "../platform/platform";
|
|
17
|
-
import { tokenCount } from "./ingest_values";
|
|
15
|
+
} from "../interaction/types.js";
|
|
16
|
+
import { gatewayPlatform, type PrefixStateWrite } from "../platform/platform.js";
|
|
17
|
+
import { tokenCount } from "./ingest_values.js";
|
|
18
18
|
|
|
19
19
|
export type CompletedPrefixHit = Omit<RouterPrefixHit, "updated_at"> & {
|
|
20
20
|
lease_depth: number;
|