@mupt-ai/dari-gateway 0.2.0 → 0.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/README.md +8 -4
- 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 +27 -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 +88 -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 +7 -0
- package/dist/index.js +9 -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 +44 -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 +69 -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 +65 -0
- package/dist/ingress/muse_code.d.ts +2 -0
- package/dist/ingress/muse_code.js +8 -0
- package/dist/ingress/muse_models.d.ts +9 -0
- package/dist/ingress/muse_models.js +32 -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 +204 -0
- package/dist/interaction/types.js +5 -0
- package/dist/models/catalog.d.ts +35 -0
- package/dist/models/catalog.js +232 -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 +9 -0
- package/dist/models/execution_provider.js +17 -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 +44 -0
- package/dist/models/runtime_overrides.d.ts +7 -0
- package/dist/models/runtime_overrides.js +226 -0
- package/dist/models/subscriptions.d.ts +8 -0
- package/dist/models/subscriptions.js +37 -0
- package/dist/observability/errors.d.ts +8 -0
- package/dist/observability/errors.js +11 -0
- package/dist/platform/platform.d.ts +156 -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 +214 -0
- package/dist/protocol/input/chat_completions_validation.d.ts +2 -0
- package/dist/protocol/input/chat_completions_validation.js +258 -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 +325 -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 +410 -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 +296 -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 +33 -0
- package/dist/providers/subscription_limits.js +179 -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 +7 -0
- package/dist/runtime/explicit_model.js +57 -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 +186 -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/runtime/strict_provider_access.d.ts +6 -0
- package/dist/runtime/strict_provider_access.js +40 -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 +167 -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 +59 -0
- package/dist/self_host/subscriptions/oauth.js +376 -0
- package/dist/self_host/subscriptions/store.d.ts +78 -0
- package/dist/self_host/subscriptions/store.js +236 -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 +97 -0
- package/dist/types.js +1 -0
- package/package.json +22 -7
- package/src/bun.ts +2 -2
- 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 +6 -3
- package/src/context/provider_prompt_accounting.ts +5 -5
- package/src/context/routing_context.ts +16 -16
- package/src/http/auth.ts +1 -1
- package/src/http/handler.ts +15 -8
- package/src/http/serve.ts +3 -3
- package/src/index.ts +14 -6
- package/src/ingress/anthropic_messages.ts +12 -12
- package/src/ingress/anthropic_models.ts +1 -1
- package/src/ingress/chat_completions.ts +17 -10
- package/src/ingress/claude_code/request_context.ts +2 -2
- package/src/ingress/codex.ts +14 -10
- package/src/ingress/codex_models.ts +4 -4
- package/src/ingress/json.ts +1 -1
- package/src/ingress/models.ts +22 -10
- package/src/ingress/muse_code.ts +9 -0
- package/src/ingress/muse_models.ts +36 -0
- 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 +2 -0
- package/src/models/catalog.ts +310 -0
- package/src/models/context_limits.ts +1 -1
- package/src/models/execution_provider.ts +5 -2
- package/src/models/ids.ts +1 -1
- package/src/models/provider_defaults.ts +4 -1
- package/src/models/runtime_overrides.ts +23 -1
- package/src/models/subscriptions.ts +54 -0
- package/src/observability/errors.ts +2 -2
- package/src/platform/platform.ts +9 -5
- package/src/protocol/input/anthropic_messages.ts +7 -7
- package/src/protocol/input/chat_completions.ts +8 -6
- package/src/protocol/input/chat_completions_validation.ts +6 -5
- 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 +34 -19
- package/src/providers/pi_context.ts +6 -6
- package/src/providers/pi_options.ts +27 -11
- package/src/providers/pi_output.ts +5 -5
- package/src/providers/provider_attempt_runner.ts +1 -1
- package/src/providers/provider_call.ts +21 -17
- package/src/providers/provider_reported_cost.ts +3 -3
- package/src/providers/reasoning.ts +2 -2
- package/src/providers/stream_finalization.ts +9 -9
- package/src/providers/subscription_limits.ts +24 -7
- package/src/runtime/claude_code/auxiliary_routing.ts +5 -5
- package/src/runtime/customer_disconnect.ts +1 -1
- package/src/runtime/explicit_model.ts +19 -20
- 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 +35 -16
- package/src/runtime/provider_stream_lifecycle.ts +1 -1
- package/src/runtime/provider_stream_outcome.ts +2 -2
- package/src/runtime/request_tags.ts +2 -2
- package/src/runtime/routed_completion.ts +11 -11
- package/src/runtime/routed_protocol.ts +2 -2
- package/src/runtime/routed_runtime.ts +20 -19
- package/src/runtime/routing_lease.ts +7 -7
- package/src/runtime/runtime_reporter.ts +3 -3
- package/src/runtime/strict_provider_access.ts +42 -0
- package/src/self_host/main.ts +12 -12
- package/src/self_host/platform.ts +5 -5
- package/src/self_host/prefix_store.ts +2 -2
- package/src/self_host/resolve.ts +17 -31
- 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/oauth.ts +139 -8
- package/src/self_host/subscriptions/store.ts +2 -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 +10 -10
- 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 +21 -21
- 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 +5 -5
- package/src/types.ts +20 -3
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { BedrockOptions } from "@mupt-ai/pi-ai/api/bedrock-converse-stream";
|
|
2
2
|
import { isReasoningEffort, isRecord, type ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
|
|
3
|
-
import type { InteractionRequest, InteractionResponseFormat, InteractionToolChoice } from "../interaction/types";
|
|
4
|
-
import { requiredCapabilitiesFor } from "../interaction/capabilities";
|
|
5
|
-
import { toolWireName, toolsByWireName } from "../interaction/tool_identity";
|
|
6
|
-
import { gatewayFor, payloadWithGatewayFields } from "../models/gateways";
|
|
7
|
-
import { offRequiresWireNone } from "../models/runtime_overrides";
|
|
8
|
-
import { effectiveReasoningForModel, validateReasoningEffortForModel } from "./reasoning";
|
|
9
|
-
import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities";
|
|
10
|
-
import type { ResolvedProviderAuth } from "../types";
|
|
11
|
-
import type { ProviderFetch } from "./response_capture";
|
|
12
|
-
import { forwardsAnthropicSafeguards, payloadWithSafeguards } from "./anthropic_safeguards";
|
|
3
|
+
import type { InteractionRequest, InteractionResponseFormat, InteractionToolChoice } from "../interaction/types.js";
|
|
4
|
+
import { requiredCapabilitiesFor } from "../interaction/capabilities.js";
|
|
5
|
+
import { toolWireName, toolsByWireName } from "../interaction/tool_identity.js";
|
|
6
|
+
import { gatewayFor, payloadWithGatewayFields } from "../models/gateways.js";
|
|
7
|
+
import { offRequiresWireNone } from "../models/runtime_overrides.js";
|
|
8
|
+
import { effectiveReasoningForModel, validateReasoningEffortForModel } from "./reasoning.js";
|
|
9
|
+
import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
10
|
+
import type { ResolvedProviderAuth } from "../types.js";
|
|
11
|
+
import type { ProviderFetch } from "./response_capture.js";
|
|
12
|
+
import { forwardsAnthropicSafeguards, payloadWithSafeguards } from "./anthropic_safeguards.js";
|
|
13
13
|
|
|
14
14
|
type PiOptionsSupport = {
|
|
15
15
|
getSupportedThinkingLevels?: (model: Record<string, unknown>) => string[];
|
|
@@ -51,8 +51,10 @@ export function buildOptions(
|
|
|
51
51
|
const providerAuth: ResolvedProviderAuth = typeof auth === "string" ? { type: "bearer", apiKey: auth } : auth;
|
|
52
52
|
const { generation, toolChoice, parallelToolCalls, responseFormat } = request;
|
|
53
53
|
const headers: Record<string, string> = {};
|
|
54
|
+
const bearerHeader = sendsBearerToMessages(providerAuth, model);
|
|
55
|
+
if (bearerHeader) headers.authorization = `Bearer ${providerAuth.apiKey}`;
|
|
54
56
|
const options: Record<string, unknown> = {
|
|
55
|
-
...authenticationOptions(providerAuth, api),
|
|
57
|
+
...(bearerHeader ? {} : authenticationOptions(providerAuth, api)),
|
|
56
58
|
maxRetries: 0,
|
|
57
59
|
timeoutMs,
|
|
58
60
|
signal,
|
|
@@ -67,6 +69,9 @@ export function buildOptions(
|
|
|
67
69
|
if (isClaudeCodeOAuth(providerAuth, api)) {
|
|
68
70
|
headers["user-agent"] = request.claudeCodeUserAgent ?? CLAUDE_CODE_USER_AGENT;
|
|
69
71
|
}
|
|
72
|
+
if (model.provider === "meta" && request.museCodeClientId !== undefined) {
|
|
73
|
+
headers["x-client-id"] = request.museCodeClientId;
|
|
74
|
+
}
|
|
70
75
|
// Pi's Anthropic transport honors compat.supportsTemperature; the OpenAI
|
|
71
76
|
// transports forward temperature regardless, so drop it here for models
|
|
72
77
|
// that reject it instead of failing the whole request.
|
|
@@ -207,6 +212,17 @@ function authenticationOptions(auth: ResolvedProviderAuth, api: unknown): Bedroc
|
|
|
207
212
|
};
|
|
208
213
|
}
|
|
209
214
|
|
|
215
|
+
// Anthropic Messages endpoints outside Anthropic that take the key as a bearer
|
|
216
|
+
// token (Claude Code's ANTHROPIC_AUTH_TOKEN) and reject x-api-key.
|
|
217
|
+
const BEARER_MESSAGES_PROVIDERS: ReadonlySet<unknown> = new Set(["meta"]);
|
|
218
|
+
|
|
219
|
+
function sendsBearerToMessages(
|
|
220
|
+
auth: ResolvedProviderAuth,
|
|
221
|
+
model: Model,
|
|
222
|
+
): auth is Extract<ResolvedProviderAuth, { type: "bearer" }> {
|
|
223
|
+
return auth.type === "bearer" && isAnthropic(model.api) && BEARER_MESSAGES_PROVIDERS.has(model.provider);
|
|
224
|
+
}
|
|
225
|
+
|
|
210
226
|
function isClaudeCodeOAuth(auth: ResolvedProviderAuth, api: unknown): boolean {
|
|
211
227
|
return auth.type === "bearer" && isAnthropic(api) && auth.apiKey.includes("sk-ant-oat");
|
|
212
228
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { HttpError } from "../http/errors";
|
|
4
|
-
import { providerToolCallIdentity, toolsByWireName } from "../interaction/tool_identity";
|
|
5
|
-
import { isAnthropicEffort } from "../interaction/provider_continuation_state";
|
|
6
|
-
import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities";
|
|
3
|
+
import { HttpError } from "../http/errors.js";
|
|
4
|
+
import { providerToolCallIdentity, toolsByWireName } from "../interaction/tool_identity.js";
|
|
5
|
+
import { isAnthropicEffort } from "../interaction/provider_continuation_state.js";
|
|
6
|
+
import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
7
7
|
import type {
|
|
8
8
|
InteractionItem,
|
|
9
9
|
InteractionOutput,
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
ProviderContinuationState,
|
|
14
14
|
ProviderIdentity,
|
|
15
15
|
ToolKind,
|
|
16
|
-
} from "../interaction/types";
|
|
16
|
+
} from "../interaction/types.js";
|
|
17
17
|
|
|
18
18
|
export function piMessageToInteractionOutput(
|
|
19
19
|
message: Record<string, unknown>,
|
|
@@ -8,46 +8,46 @@ import {
|
|
|
8
8
|
type RoutingDecision,
|
|
9
9
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
10
10
|
|
|
11
|
-
import { executionProviderForModel, keySourceForModel } from "../models/execution_provider";
|
|
12
|
-
import { HttpError } from "../http/errors";
|
|
13
|
-
import type { RequestTags } from "../platform/platform";
|
|
14
|
-
import type { InteractionRequest, ProviderIdentity } from "../interaction/types";
|
|
11
|
+
import { executionProviderForModel, keySourceForModel } from "../models/execution_provider.js";
|
|
12
|
+
import { HttpError } from "../http/errors.js";
|
|
13
|
+
import type { RequestTags } from "../platform/platform.js";
|
|
14
|
+
import type { InteractionRequest, ProviderIdentity } from "../interaction/types.js";
|
|
15
15
|
import {
|
|
16
16
|
CustomerDisconnectedError,
|
|
17
17
|
createProviderAttemptAbort,
|
|
18
18
|
type ProviderAttemptAbort,
|
|
19
|
-
} from "../runtime/customer_disconnect";
|
|
19
|
+
} from "../runtime/customer_disconnect.js";
|
|
20
20
|
import {
|
|
21
21
|
isProviderFailureMessage,
|
|
22
22
|
providerFailureFromCaught,
|
|
23
23
|
providerFailureFromEvent,
|
|
24
|
-
} from "../runtime/provider_stream_outcome";
|
|
25
|
-
import { providerAuthForSelectedModel } from "../strategies/routing";
|
|
26
|
-
import { scrubSecretValues } from "../telemetry/scrub";
|
|
24
|
+
} from "../runtime/provider_stream_outcome.js";
|
|
25
|
+
import { providerAuthForSelectedModel } from "../strategies/routing.js";
|
|
26
|
+
import { scrubSecretValues } from "../telemetry/scrub.js";
|
|
27
27
|
import {
|
|
28
28
|
usageContextFor,
|
|
29
29
|
type RoutingUsageContext,
|
|
30
|
-
} from "../telemetry/usage";
|
|
30
|
+
} from "../telemetry/usage.js";
|
|
31
31
|
import type {
|
|
32
32
|
ProviderAuth,
|
|
33
33
|
ProviderKeySource,
|
|
34
34
|
ResolvedRouter,
|
|
35
35
|
ResolvedRouterModelConfig,
|
|
36
|
-
} from "../types";
|
|
37
|
-
import { awsRoleCredentials } from "./aws_assume_role";
|
|
36
|
+
} from "../types.js";
|
|
37
|
+
import { awsRoleCredentials } from "./aws_assume_role.js";
|
|
38
38
|
import {
|
|
39
39
|
attachProviderResponseCapture,
|
|
40
40
|
createProviderResponseCapture,
|
|
41
41
|
type ProviderFetch,
|
|
42
42
|
type ProviderResponseCapture,
|
|
43
|
-
} from "./response_capture";
|
|
43
|
+
} from "./response_capture.js";
|
|
44
44
|
import {
|
|
45
45
|
completeInteractionModel,
|
|
46
46
|
streamInteractionModel,
|
|
47
47
|
type ProviderEndpoint,
|
|
48
48
|
type ProviderEventStream,
|
|
49
|
-
} from "./pi";
|
|
50
|
-
import { promptTokenEstimateFor, type PromptTokenEstimate } from "./cancel_estimate";
|
|
49
|
+
} from "./pi.js";
|
|
50
|
+
import { promptTokenEstimateFor, type PromptTokenEstimate } from "./cancel_estimate.js";
|
|
51
51
|
|
|
52
52
|
type ProviderCallConfig = {
|
|
53
53
|
model: string;
|
|
@@ -115,8 +115,10 @@ export function prepareProviderExecution(args: {
|
|
|
115
115
|
}
|
|
116
116
|
const provider = executionProviderForModel(args.credentials, model);
|
|
117
117
|
const supplied = args.credentials.provider_credentials?.[model];
|
|
118
|
-
const providerKeySource =
|
|
119
|
-
|
|
118
|
+
const providerKeySource = keySourceForModel(args.credentials, model);
|
|
119
|
+
// A strict router serves a plan only when the platform supplied it for this
|
|
120
|
+
// request, never a pooled or personal one it resolved.
|
|
121
|
+
if (args.credentials.strict === true && providerKeySource === "subscription" && !supplied) {
|
|
120
122
|
throw new HttpError(
|
|
121
123
|
400,
|
|
122
124
|
`Strict routers do not serve '${model}' from a personal subscription.`,
|
|
@@ -148,7 +150,9 @@ export function prepareProviderExecution(args: {
|
|
|
148
150
|
: {}),
|
|
149
151
|
provider,
|
|
150
152
|
providerKeySource,
|
|
151
|
-
|
|
153
|
+
// Only resolved personal subscriptions are held at their usage limit;
|
|
154
|
+
// the platform manages the plans it supplies.
|
|
155
|
+
...(providerKeySource === "subscription" && !supplied && args.credentials.attributed_user_id
|
|
152
156
|
? {
|
|
153
157
|
subscriptionUserId: args.credentials.attributed_user_id,
|
|
154
158
|
subscriptionCredentialId: args.credentials.subscription_credential_ids?.[provider],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { gatewayFor } from "../models/gateways";
|
|
4
|
-
import { providerFailureFromCaught } from "../runtime/provider_stream_outcome";
|
|
5
|
-
import type { ProviderFetch } from "./response_capture";
|
|
3
|
+
import { gatewayFor } from "../models/gateways.js";
|
|
4
|
+
import { providerFailureFromCaught } from "../runtime/provider_stream_outcome.js";
|
|
5
|
+
import type { ProviderFetch } from "./response_capture.js";
|
|
6
6
|
|
|
7
7
|
// Gateways bill per call and say what they billed: OpenRouter as `usage.cost`
|
|
8
8
|
// on the final chunk, Vercel AI Gateway as `providerMetadata.gateway.cost`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import { HttpError } from "../http/errors";
|
|
3
|
-
import type { InteractionRequest } from "../interaction/types";
|
|
2
|
+
import { HttpError } from "../http/errors.js";
|
|
3
|
+
import type { InteractionRequest } from "../interaction/types.js";
|
|
4
4
|
|
|
5
5
|
type ReasoningRequest = Pick<InteractionRequest, "reasoning">;
|
|
6
6
|
|
|
@@ -3,32 +3,32 @@ import type {
|
|
|
3
3
|
RoutingDecision,
|
|
4
4
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
5
5
|
|
|
6
|
-
import type { InteractionRequest, ProviderIdentity } from "../interaction/types";
|
|
6
|
+
import type { InteractionRequest, ProviderIdentity } from "../interaction/types.js";
|
|
7
7
|
import {
|
|
8
8
|
captureOperationalError,
|
|
9
9
|
type OperationalErrorCode,
|
|
10
|
-
} from "../observability/errors";
|
|
11
|
-
import type { ProviderStreamOutcome } from "../runtime/provider_stream_outcome";
|
|
12
|
-
import type { RoutedProtocol } from "../runtime/routed_protocol";
|
|
10
|
+
} from "../observability/errors.js";
|
|
11
|
+
import type { ProviderStreamOutcome } from "../runtime/provider_stream_outcome.js";
|
|
12
|
+
import type { RoutedProtocol } from "../runtime/routed_protocol.js";
|
|
13
13
|
import {
|
|
14
14
|
reportedExecution,
|
|
15
15
|
type FrozenProviderTerminal,
|
|
16
16
|
type ProviderAttemptRecord,
|
|
17
17
|
type ReportableProviderOutcome,
|
|
18
18
|
type RoutedRuntimeReporter,
|
|
19
|
-
} from "../runtime/runtime_reporter";
|
|
20
|
-
import type { ProviderKeySource } from "../types";
|
|
19
|
+
} from "../runtime/runtime_reporter.js";
|
|
20
|
+
import type { ProviderKeySource } from "../types.js";
|
|
21
21
|
import {
|
|
22
22
|
reportRoutingUsage,
|
|
23
23
|
type RoutingUsageContext,
|
|
24
|
-
} from "../telemetry/usage";
|
|
25
|
-
import { customerCanceledProviderMessage } from "../runtime/customer_disconnect";
|
|
24
|
+
} from "../telemetry/usage.js";
|
|
25
|
+
import { customerCanceledProviderMessage } from "../runtime/customer_disconnect.js";
|
|
26
26
|
import {
|
|
27
27
|
estimatedCancelUsage,
|
|
28
28
|
partialInteractionOutput,
|
|
29
29
|
type DeliveredOutput,
|
|
30
30
|
type PromptTokenEstimate,
|
|
31
|
-
} from "./cancel_estimate";
|
|
31
|
+
} from "./cancel_estimate.js";
|
|
32
32
|
|
|
33
33
|
// Structurally a subset of ProviderExecution. The narrowing is deliberate: it
|
|
34
34
|
// keeps apiKey and auth out of the finalizer.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { providerFailureMessage } from "../runtime/provider_stream_outcome";
|
|
4
|
-
import type { ProviderKeySource } from "../types";
|
|
5
|
-
import type { CapturedProviderResponse } from "./response_capture";
|
|
3
|
+
import { providerFailureMessage } from "../runtime/provider_stream_outcome.js";
|
|
4
|
+
import type { ProviderKeySource } from "../types.js";
|
|
5
|
+
import type { CapturedProviderResponse } from "./response_capture.js";
|
|
6
6
|
|
|
7
|
-
export type SubscriptionOAuthProvider = "anthropic_claude_code" | "openai_codex";
|
|
7
|
+
export type SubscriptionOAuthProvider = "anthropic_claude_code" | "openai_codex" | "meta_muse";
|
|
8
8
|
|
|
9
9
|
export type SubscriptionUsageLimit = {
|
|
10
10
|
oauthProvider: SubscriptionOAuthProvider;
|
|
@@ -25,6 +25,7 @@ const FAILURE_MARKER = "subscription_usage_limit";
|
|
|
25
25
|
const SUBSCRIPTION_LABEL: Record<SubscriptionOAuthProvider, string> = {
|
|
26
26
|
anthropic_claude_code: "Claude Code",
|
|
27
27
|
openai_codex: "ChatGPT",
|
|
28
|
+
meta_muse: "Muse Code",
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export function subscriptionOAuthProviderFor(
|
|
@@ -34,13 +35,16 @@ export function subscriptionOAuthProviderFor(
|
|
|
34
35
|
if (keySource !== "subscription") return null;
|
|
35
36
|
if (provider === "anthropic") return "anthropic_claude_code";
|
|
36
37
|
if (provider === "openai" || provider === "openai-codex") return "openai_codex";
|
|
38
|
+
if (provider === "meta") return "meta_muse";
|
|
37
39
|
return null;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* Recognize a personal subscription that has run out of quota. Claude Code
|
|
42
44
|
* answers 429 with the unified rate-limit headers; the ChatGPT backend answers
|
|
43
|
-
* 429 with a structured `error.code` and `resets_at`.
|
|
45
|
+
* 429 with a structured `error.code` and `resets_at`. Meta documents no
|
|
46
|
+
* usage-limit signature for Muse Code plans, so any 429 on one holds it until
|
|
47
|
+
* the reset Meta gives, if any. The Codex WebSocket
|
|
44
48
|
* transport bypasses fetch, so its usage-limit error only survives as message
|
|
45
49
|
* text and is matched there without a reset time.
|
|
46
50
|
*/
|
|
@@ -57,6 +61,7 @@ export function detectSubscriptionUsageLimit(args: {
|
|
|
57
61
|
if (oauthProvider === "anthropic_claude_code") {
|
|
58
62
|
return anthropicUsageLimit(args.captured, now);
|
|
59
63
|
}
|
|
64
|
+
if (oauthProvider === "meta_muse") return museUsageLimit(args.captured, now);
|
|
60
65
|
return codexUsageLimit(args.captured, providerFailureMessage(args.failure), now);
|
|
61
66
|
}
|
|
62
67
|
|
|
@@ -109,6 +114,18 @@ function codexUsageLimit(
|
|
|
109
114
|
};
|
|
110
115
|
}
|
|
111
116
|
|
|
117
|
+
function museUsageLimit(
|
|
118
|
+
captured: CapturedProviderResponse | undefined,
|
|
119
|
+
now: Date,
|
|
120
|
+
): SubscriptionUsageLimit | null {
|
|
121
|
+
if (captured === undefined || captured.status !== 429) return null;
|
|
122
|
+
return {
|
|
123
|
+
oauthProvider: "meta_muse",
|
|
124
|
+
resetsAt: laterReset(codexErrorBody(captured.bodyText)?.resets_at, captured.headers, now),
|
|
125
|
+
reason: "Muse Code usage limit reached.",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
112
129
|
function codexErrorBody(bodyText: string): Record<string, unknown> | null {
|
|
113
130
|
try {
|
|
114
131
|
const parsed: unknown = JSON.parse(bodyText);
|
|
@@ -178,13 +195,13 @@ export function subscriptionUsageLimitFromFailure(
|
|
|
178
195
|
const oauthProvider = marker.oauth_provider;
|
|
179
196
|
const resetsAt = typeof marker.resets_at === "string" ? new Date(marker.resets_at) : null;
|
|
180
197
|
if (
|
|
181
|
-
|
|
198
|
+
typeof oauthProvider !== "string" || !(oauthProvider in SUBSCRIPTION_LABEL)
|
|
182
199
|
|| resetsAt === null || Number.isNaN(resetsAt.getTime())
|
|
183
200
|
) {
|
|
184
201
|
return null;
|
|
185
202
|
}
|
|
186
203
|
return {
|
|
187
|
-
oauthProvider,
|
|
204
|
+
oauthProvider: oauthProvider as SubscriptionOAuthProvider,
|
|
188
205
|
resetsAt,
|
|
189
206
|
reason: typeof marker.reason === "string" ? marker.reason : "Subscription usage limit reached.",
|
|
190
207
|
...(marker.switched === true ? { switched: true } : {}),
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
type RoutingDecision,
|
|
5
5
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
6
6
|
|
|
7
|
-
import type { RoutedDecision } from "../../strategies/route_decision";
|
|
8
|
-
import { isBackgroundRequest } from "../../interaction/types";
|
|
9
|
-
import { HttpError } from "../../http/errors";
|
|
10
|
-
import { assertCreditAvailableBeforeRouting } from "../../telemetry/usage";
|
|
11
|
-
import type { PreparedRoutedCompletion } from "../prepare_routed_completion";
|
|
7
|
+
import type { RoutedDecision } from "../../strategies/route_decision.js";
|
|
8
|
+
import { isBackgroundRequest } from "../../interaction/types.js";
|
|
9
|
+
import { HttpError } from "../../http/errors.js";
|
|
10
|
+
import { assertCreditAvailableBeforeRouting } from "../../telemetry/usage.js";
|
|
11
|
+
import type { PreparedRoutedCompletion } from "../prepare_routed_completion.js";
|
|
12
12
|
import { leaseFallbackDecision } from "../routing_lease.js";
|
|
13
13
|
|
|
14
14
|
// Explicit background classes bypass the selector and every lease path.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { RoutingCandidate, RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { HttpError } from "../http/errors";
|
|
4
|
-
import { explicitModelId } from "../protocol/input/router_model";
|
|
5
|
-
import type { RoutedDecision } from "../strategies/route_decision";
|
|
6
|
-
import type { PreparedRoutedCompletion } from "./prepare_routed_completion";
|
|
3
|
+
import { HttpError } from "../http/errors.js";
|
|
4
|
+
import { explicitModelId } from "../protocol/input/router_model.js";
|
|
5
|
+
import type { RoutedDecision } from "../strategies/route_decision.js";
|
|
6
|
+
import type { PreparedRoutedCompletion } from "./prepare_routed_completion.js";
|
|
7
7
|
|
|
8
8
|
/* A request for `dari/model/<id>` is served by exactly that enabled model,
|
|
9
9
|
with no selector, lease, or fallback: the user chose it, like picking a
|
|
@@ -14,14 +14,7 @@ export function explicitModelDecision(
|
|
|
14
14
|
): RoutedDecision | null {
|
|
15
15
|
const modelId = explicitModelId(prepared.interaction.model);
|
|
16
16
|
if (modelId === null) return null;
|
|
17
|
-
if (!prepared.credentials.enabled_models.includes(modelId))
|
|
18
|
-
throw new HttpError(
|
|
19
|
-
400,
|
|
20
|
-
`Model '${modelId}' is not enabled on this router.`,
|
|
21
|
-
"model_not_enabled",
|
|
22
|
-
"model",
|
|
23
|
-
);
|
|
24
|
-
}
|
|
17
|
+
if (!prepared.credentials.enabled_models.includes(modelId)) throw modelNotEnabled(modelId);
|
|
25
18
|
const candidates = prepared.routing.candidateResolution.candidates.filter(
|
|
26
19
|
(candidate) => candidate.model === modelId,
|
|
27
20
|
);
|
|
@@ -63,14 +56,7 @@ function pickCandidate(
|
|
|
63
56
|
refuses everything else instead of substituting. */
|
|
64
57
|
export function strictModelDecision(prepared: PreparedRoutedCompletion): RoutedDecision {
|
|
65
58
|
const modelId = explicitModelId(prepared.interaction.model);
|
|
66
|
-
if (modelId === null)
|
|
67
|
-
throw new HttpError(
|
|
68
|
-
400,
|
|
69
|
-
"This router is strict: request a pinned model as 'dari/model/<id>'.",
|
|
70
|
-
"strict_model_required",
|
|
71
|
-
"model",
|
|
72
|
-
);
|
|
73
|
-
}
|
|
59
|
+
if (modelId === null) throw strictModelRequired();
|
|
74
60
|
const { decision } = explicitModelDecision(prepared)!;
|
|
75
61
|
const requested = prepared.interaction.reasoning?.effort
|
|
76
62
|
?? prepared.credentials.model_configs?.[modelId]?.default_thinking_level;
|
|
@@ -84,3 +70,16 @@ export function strictModelDecision(prepared: PreparedRoutedCompletion): RoutedD
|
|
|
84
70
|
}
|
|
85
71
|
return { decision };
|
|
86
72
|
}
|
|
73
|
+
|
|
74
|
+
export function modelNotEnabled(modelId: string): HttpError {
|
|
75
|
+
return new HttpError(400, `Model '${modelId}' is not enabled on this router.`, "model_not_enabled", "model");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function strictModelRequired(): HttpError {
|
|
79
|
+
return new HttpError(
|
|
80
|
+
400,
|
|
81
|
+
"This router is strict: request a pinned model as 'dari/model/<id>'.",
|
|
82
|
+
"strict_model_required",
|
|
83
|
+
"model",
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { HttpError } from "../../http/errors";
|
|
3
|
+
import { HttpError } from "../../http/errors.js";
|
|
4
4
|
import type {
|
|
5
5
|
AgentRequestClass,
|
|
6
6
|
AgentRequestContext,
|
|
7
7
|
InteractionRequestPurpose,
|
|
8
|
-
} from "../../interaction/types";
|
|
9
|
-
import type { HarnessConversationIdentity } from "./conversation";
|
|
8
|
+
} from "../../interaction/types.js";
|
|
9
|
+
import type { HarnessConversationIdentity } from "./conversation.js";
|
|
10
10
|
|
|
11
11
|
const MAX_ID_CHARS = 200;
|
|
12
12
|
|
|
@@ -3,7 +3,7 @@ export {
|
|
|
3
3
|
scopedHarnessSessionId,
|
|
4
4
|
type HarnessConversationIdentity,
|
|
5
5
|
type HarnessConversationScope,
|
|
6
|
-
} from "./conversation";
|
|
6
|
+
} from "./conversation.js";
|
|
7
7
|
export {
|
|
8
8
|
chatCompletionsConversationIdentity,
|
|
9
9
|
claudeCodeConversationIdentity,
|
|
@@ -11,4 +11,4 @@ export {
|
|
|
11
11
|
codexRequestPurpose,
|
|
12
12
|
codexRequestContext,
|
|
13
13
|
openCodeRequestContext,
|
|
14
|
-
} from "./extract";
|
|
14
|
+
} from "./extract.js";
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import type { CandidatePruningAudit } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { interactionConversationPrefix } from "../context/interaction_fingerprint";
|
|
3
|
+
import { interactionConversationPrefix } from "../context/interaction_fingerprint.js";
|
|
4
4
|
import {
|
|
5
5
|
buildRoutingContext,
|
|
6
6
|
derivePrefixLookupHashes,
|
|
7
7
|
type ImageCapabilityPrunedModel,
|
|
8
8
|
type RoutingContext,
|
|
9
|
-
} from "../context/routing_context";
|
|
10
|
-
import { isBackgroundRequest, type InteractionRequest } from "../interaction/types";
|
|
11
|
-
import { executionProviderForModel } from "../models/execution_provider";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
import
|
|
9
|
+
} from "../context/routing_context.js";
|
|
10
|
+
import { isBackgroundRequest, type InteractionRequest } from "../interaction/types.js";
|
|
11
|
+
import { executionProviderForModel } from "../models/execution_provider.js";
|
|
12
|
+
import { codexModelConfig, subscriptionServes } from "../models/subscriptions.js";
|
|
13
|
+
import { gatewayPlatform, type RequestTags } from "../platform/platform.js";
|
|
14
|
+
import { resolveRouter } from "../strategies/routing.js";
|
|
15
|
+
import { RequestReporter, type ReportedCandidatePruning } from "../telemetry/report.js";
|
|
16
|
+
import { RoutingBillingFinalization } from "../telemetry/billing_finalization.js";
|
|
17
|
+
import type { ClientHarness, ProviderCredential, ResolvedRouter } from "../types.js";
|
|
18
|
+
import { requestTags } from "./request_tags.js";
|
|
19
|
+
import { strictProviderAccess } from "./strict_provider_access.js";
|
|
20
|
+
import type { RoutedRuntimeReporter } from "./runtime_reporter.js";
|
|
21
|
+
import type { RoutedProtocol } from "./routed_protocol.js";
|
|
20
22
|
import {
|
|
21
23
|
scopedHarnessConversationId,
|
|
22
24
|
scopedHarnessSessionId,
|
|
23
25
|
type HarnessConversationIdentity,
|
|
24
|
-
} from "./harness_identity";
|
|
26
|
+
} from "./harness_identity/index.js";
|
|
25
27
|
|
|
26
28
|
export type PreparedRoutedCompletion = {
|
|
27
29
|
requestId: string;
|
|
@@ -125,7 +127,10 @@ export async function prepareRoutedCompletion(args: {
|
|
|
125
127
|
}
|
|
126
128
|
credentials = conversationCredentials;
|
|
127
129
|
}
|
|
128
|
-
|
|
130
|
+
const access = strictProviderAccess(credentials, args.interaction);
|
|
131
|
+
credentials = access.credentials;
|
|
132
|
+
args = { ...args, interaction: access.interaction };
|
|
133
|
+
credentials = await withProviderCredentials(credentials, args.apiKey, args.clientHarness);
|
|
129
134
|
const billable = true;
|
|
130
135
|
const routing = await buildRoutingContext({
|
|
131
136
|
routerId: prefixFingerprintRouterId,
|
|
@@ -188,6 +193,7 @@ export async function prepareRoutedCompletion(args: {
|
|
|
188
193
|
async function withProviderCredentials(
|
|
189
194
|
credentials: ResolvedRouter,
|
|
190
195
|
apiKey: string,
|
|
196
|
+
clientHarness: ClientHarness | undefined,
|
|
191
197
|
): Promise<ResolvedRouter> {
|
|
192
198
|
const platform = gatewayPlatform();
|
|
193
199
|
if (platform.resolveProviderCredential === undefined) return credentials;
|
|
@@ -200,14 +206,27 @@ async function withProviderCredentials(
|
|
|
200
206
|
routerId: credentials.router_id,
|
|
201
207
|
organizationId: credentials.organization_id,
|
|
202
208
|
apiKey,
|
|
209
|
+
...(clientHarness ? { clientHarness } : {}),
|
|
203
210
|
}),
|
|
204
211
|
] as const),
|
|
205
212
|
);
|
|
206
213
|
const provider_credentials: Record<string, ProviderCredential> = {};
|
|
214
|
+
const model_configs = { ...credentials.model_configs };
|
|
207
215
|
for (const [model, credential] of resolved) {
|
|
208
|
-
if (credential?.apiKey.trim())
|
|
216
|
+
if (!credential?.apiKey.trim()) continue;
|
|
217
|
+
const plan = credential.subscription;
|
|
218
|
+
if (plan !== undefined && !subscriptionServes(plan, model, clientHarness)) continue;
|
|
219
|
+
provider_credentials[model] = credential;
|
|
220
|
+
if (plan === "openai_codex") {
|
|
221
|
+
// Keep the catalog's limits and thinking levels; only the serving
|
|
222
|
+
// endpoint changes.
|
|
223
|
+
model_configs[model] = {
|
|
224
|
+
...model_configs[model],
|
|
225
|
+
...codexModelConfig(model, credentials.model_prices?.[model] ?? null),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
209
228
|
}
|
|
210
|
-
return { ...credentials, provider_credentials };
|
|
229
|
+
return { ...credentials, provider_credentials, model_configs };
|
|
211
230
|
}
|
|
212
231
|
|
|
213
232
|
// Core's cache-aware pruning audit, extended with the context layer's image
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import type { InteractionOutput } from "../interaction/types";
|
|
3
|
-
import { scrubSecrets } from "../telemetry/scrub";
|
|
2
|
+
import type { InteractionOutput } from "../interaction/types.js";
|
|
3
|
+
import { scrubSecrets } from "../telemetry/scrub.js";
|
|
4
4
|
|
|
5
5
|
export type ProviderStreamOutcome =
|
|
6
6
|
| {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpError } from "../http/errors";
|
|
2
|
-
import type { RequestTags } from "../platform/platform";
|
|
1
|
+
import { HttpError } from "../http/errors.js";
|
|
2
|
+
import type { RequestTags } from "../platform/platform.js";
|
|
3
3
|
|
|
4
4
|
const TAGS_MAX_CHARS = 2048;
|
|
5
5
|
const TAGS_MAX_COUNT = 32;
|
|
@@ -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;
|
|
@@ -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;
|