@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
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { CustomRouterConfig, Provider, ReasoningEffort, RouterEval, RouterEvalScore, RouterModelPrice, RouterPrefixHit, RoutingStrategy } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
+
export type ProviderKeySource = "user" | "managed" | "subscription";
|
|
3
|
+
export type BearerProviderAuth = {
|
|
4
|
+
type: "bearer";
|
|
5
|
+
apiKey: string;
|
|
6
|
+
};
|
|
7
|
+
export type AwsSigV4ProviderAuth = {
|
|
8
|
+
type: "aws_sigv4";
|
|
9
|
+
access_key_id: string;
|
|
10
|
+
secret_access_key: string;
|
|
11
|
+
session_token?: string | null;
|
|
12
|
+
region: string;
|
|
13
|
+
};
|
|
14
|
+
export type AwsAssumeRoleProviderAuth = {
|
|
15
|
+
type: "aws_assume_role";
|
|
16
|
+
role_arn: string;
|
|
17
|
+
external_id: string;
|
|
18
|
+
region: string;
|
|
19
|
+
};
|
|
20
|
+
export type ResolvedProviderAuth = BearerProviderAuth | AwsSigV4ProviderAuth;
|
|
21
|
+
export type SubscriptionKind = "openai_codex" | "anthropic_claude_code" | "meta_muse";
|
|
22
|
+
export type ProviderCredential = {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
subscription?: SubscriptionKind;
|
|
27
|
+
};
|
|
28
|
+
export type ProviderAuth = ResolvedProviderAuth | AwsAssumeRoleProviderAuth;
|
|
29
|
+
export type AwsProviderAuth = AwsSigV4ProviderAuth | AwsAssumeRoleProviderAuth;
|
|
30
|
+
export type PublicEvalCatalogScore = RouterEvalScore & {
|
|
31
|
+
source_row_name?: string | null;
|
|
32
|
+
source_date?: string | null;
|
|
33
|
+
last_synced_at?: string | null;
|
|
34
|
+
sample_count?: number | null;
|
|
35
|
+
};
|
|
36
|
+
export type PublicEvalCatalogCard = Omit<RouterEval, "scores"> & {
|
|
37
|
+
source_id: string;
|
|
38
|
+
source_name: string;
|
|
39
|
+
source_url: string;
|
|
40
|
+
harness: string;
|
|
41
|
+
updated_at: string | null;
|
|
42
|
+
scores: PublicEvalCatalogScore[];
|
|
43
|
+
};
|
|
44
|
+
export type ClientHarness = "claude_code" | "muse_code";
|
|
45
|
+
export type ResolvedRouterModelConfig = {
|
|
46
|
+
provider: string;
|
|
47
|
+
native_model_id: string;
|
|
48
|
+
api: string;
|
|
49
|
+
base_url?: string | null;
|
|
50
|
+
context_window?: number | null;
|
|
51
|
+
standard_context_limit?: number | null;
|
|
52
|
+
allow_long_context?: boolean;
|
|
53
|
+
max_output_tokens?: number | null;
|
|
54
|
+
supported_thinking_levels?: ReasoningEffort[] | null;
|
|
55
|
+
default_thinking_level?: ReasoningEffort | null;
|
|
56
|
+
average_output_tokens?: Partial<Record<ReasoningEffort, number>> | null;
|
|
57
|
+
cost: RouterModelPrice;
|
|
58
|
+
supports_managed_key?: boolean;
|
|
59
|
+
fast_mode?: boolean;
|
|
60
|
+
fast_mode_cost?: RouterModelPrice | null;
|
|
61
|
+
zdr?: boolean;
|
|
62
|
+
};
|
|
63
|
+
export type ResolvedRouter = {
|
|
64
|
+
router_id: string;
|
|
65
|
+
organization_id: string;
|
|
66
|
+
api_key_id: string | null;
|
|
67
|
+
attributed_user_id: string | null;
|
|
68
|
+
enabled_models: string[];
|
|
69
|
+
provider_keys: Partial<Record<Provider, string>>;
|
|
70
|
+
provider_auth?: Partial<Record<Provider, AwsProviderAuth>>;
|
|
71
|
+
provider_key_sources?: Partial<Record<Provider, ProviderKeySource>>;
|
|
72
|
+
provider_credentials?: Record<string, ProviderCredential>;
|
|
73
|
+
subscription_credential_ids?: Partial<Record<Provider, string>>;
|
|
74
|
+
zdr?: boolean;
|
|
75
|
+
allow_long_context?: boolean;
|
|
76
|
+
speculative_routing?: boolean;
|
|
77
|
+
primary_retries?: number;
|
|
78
|
+
strict?: boolean;
|
|
79
|
+
strict_providers?: string[];
|
|
80
|
+
model_fallback_enabled?: boolean;
|
|
81
|
+
fallback_requires_different_provider?: boolean;
|
|
82
|
+
evals?: RouterEval[];
|
|
83
|
+
eval_score_imputation?: boolean;
|
|
84
|
+
image_capability_filtering?: boolean;
|
|
85
|
+
lease_context_enabled?: boolean;
|
|
86
|
+
selector_image_input_enabled?: boolean;
|
|
87
|
+
public_eval_catalog?: PublicEvalCatalogCard[] | null;
|
|
88
|
+
prefix_hits?: RouterPrefixHit[];
|
|
89
|
+
routing_strategy?: RoutingStrategy;
|
|
90
|
+
custom_config?: CustomRouterConfig | null;
|
|
91
|
+
model_thinking_levels?: Record<string, ReasoningEffort[]>;
|
|
92
|
+
fast_models?: string[];
|
|
93
|
+
model_prices?: Record<string, RouterModelPrice>;
|
|
94
|
+
model_configs?: Record<string, ResolvedRouterModelConfig>;
|
|
95
|
+
credit_exhausted?: boolean;
|
|
96
|
+
autorouting_enabled?: boolean;
|
|
97
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mupt-ai/dari-gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Self-hostable LLM gateway for coding agents and APIs: one endpoint for Anthropic Messages, OpenAI Chat Completions, and OpenAI Responses, with subscription pooling, failover, and prompt-cache-aware routing.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -9,14 +9,27 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
|
-
".":
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
".": {
|
|
13
|
+
"bun": "./src/index.ts",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./bun": {
|
|
18
|
+
"bun": "./src/bun.ts",
|
|
19
|
+
"types": "./dist/bun.d.ts",
|
|
20
|
+
"default": "./dist/bun.js"
|
|
21
|
+
},
|
|
22
|
+
"./*": {
|
|
23
|
+
"bun": "./src/*.ts",
|
|
24
|
+
"types": "./dist/*.d.ts",
|
|
25
|
+
"default": "./dist/*.js"
|
|
26
|
+
}
|
|
15
27
|
},
|
|
16
28
|
"bin": {
|
|
17
|
-
"dari-gateway": "./
|
|
29
|
+
"dari-gateway": "./dist/self_host/main.js"
|
|
18
30
|
},
|
|
19
31
|
"files": [
|
|
32
|
+
"dist",
|
|
20
33
|
"src",
|
|
21
34
|
"!src/**/*.test.ts",
|
|
22
35
|
"!src/**/*.fixtures.ts",
|
|
@@ -29,12 +42,14 @@
|
|
|
29
42
|
],
|
|
30
43
|
"scripts": {
|
|
31
44
|
"start": "bun run src/self_host/main.ts",
|
|
45
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
32
46
|
"typecheck": "tsc --noEmit",
|
|
33
|
-
"test": "bun test"
|
|
47
|
+
"test": "bun test",
|
|
48
|
+
"prepack": "bun run build"
|
|
34
49
|
},
|
|
35
50
|
"dependencies": {
|
|
36
51
|
"@aws-sdk/client-sts": "3.1063.0",
|
|
37
|
-
"@mupt-ai/dari-router": "0.2.
|
|
52
|
+
"@mupt-ai/dari-router": "0.2.5",
|
|
38
53
|
"@mupt-ai/pi-ai": "1.4.0-mupt.1"
|
|
39
54
|
},
|
|
40
55
|
"devDependencies": {
|
package/src/bun.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Bun-only entry points: the Bun.serve HTTP server and the self-hosted
|
|
2
2
|
// gateway, whose state lives in bun:sqlite.
|
|
3
|
-
export { installShutdownHandlers, startServer } from "./http/serve";
|
|
4
|
-
export { startSelfHostedGateway } from "./self_host/main";
|
|
3
|
+
export { installShutdownHandlers, startServer } from "./http/serve.js";
|
|
4
|
+
export { startSelfHostedGateway } from "./self_host/main.js";
|
|
@@ -2,20 +2,20 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
|
|
3
3
|
import { stableStringify } from "@mupt-ai/dari-router/policy-engine";
|
|
4
4
|
|
|
5
|
-
import { anthropicMessagesToInteraction } from "../protocol/input/anthropic_messages";
|
|
6
|
-
import { internalChatCompletionsToInteraction } from "../protocol/input/chat_completions";
|
|
7
|
-
import { anthropicContent } from "../protocol/output/anthropic_messages_output";
|
|
8
|
-
import { assistantMessagePayload } from "../protocol/output/chat_completions";
|
|
9
|
-
import { compatibleProviderContinuation } from "../interaction/provider_continuation_state";
|
|
5
|
+
import { anthropicMessagesToInteraction } from "../protocol/input/anthropic_messages.js";
|
|
6
|
+
import { internalChatCompletionsToInteraction } from "../protocol/input/chat_completions.js";
|
|
7
|
+
import { anthropicContent } from "../protocol/output/anthropic_messages_output.js";
|
|
8
|
+
import { assistantMessagePayload } from "../protocol/output/chat_completions.js";
|
|
9
|
+
import { compatibleProviderContinuation } from "../interaction/provider_continuation_state.js";
|
|
10
10
|
import type {
|
|
11
11
|
InteractionItem,
|
|
12
12
|
InteractionOutput,
|
|
13
13
|
InteractionRequest,
|
|
14
14
|
ProviderContinuationState,
|
|
15
15
|
ProviderIdentity,
|
|
16
|
-
} from "../interaction/types";
|
|
17
|
-
import { providerToolCallId, toolWireName } from "../interaction/tool_identity";
|
|
18
|
-
import { ROUTING_PREFIX_HASHES_MAX_COUNT } from "../platform/routing_contract";
|
|
16
|
+
} from "../interaction/types.js";
|
|
17
|
+
import { providerToolCallId, toolWireName } from "../interaction/tool_identity.js";
|
|
18
|
+
import { ROUTING_PREFIX_HASHES_MAX_COUNT } from "../platform/routing_contract.js";
|
|
19
19
|
import {
|
|
20
20
|
appendFingerprintContentText,
|
|
21
21
|
canonicalInteractionFingerprintStep,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
normalizedAssistantFingerprintContent,
|
|
26
26
|
type InteractionFingerprintStep,
|
|
27
27
|
type ReasoningFingerprint,
|
|
28
|
-
} from "./interaction_fingerprint_format";
|
|
28
|
+
} from "./interaction_fingerprint_format.js";
|
|
29
29
|
|
|
30
30
|
const MAX_CONTINUATION_TARGETS = 16;
|
|
31
31
|
|
|
@@ -5,7 +5,7 @@ import { stableStringify } from "@mupt-ai/dari-router/policy-engine";
|
|
|
5
5
|
import type {
|
|
6
6
|
InteractionContent,
|
|
7
7
|
InteractionRequest,
|
|
8
|
-
} from "../interaction/types";
|
|
8
|
+
} from "../interaction/types.js";
|
|
9
9
|
|
|
10
10
|
// Bump when canonical fingerprint semantics change so persisted hashes from
|
|
11
11
|
// incompatible contracts remain disjoint.
|
package/src/context/pricing.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ModelPricing, PricingLookup } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { registeredModelPrice } from "../providers/pi.js";
|
|
3
|
+
import type { ResolvedRouter } from "../types.js";
|
|
4
4
|
|
|
5
5
|
export function pricingLookupForRouter(credentials: ResolvedRouter): PricingLookup {
|
|
6
6
|
return (model: string): ModelPricing | null => modelPricingForRouter(credentials, model);
|
|
@@ -10,7 +10,10 @@ export function modelPricingForRouter(
|
|
|
10
10
|
credentials: ResolvedRouter,
|
|
11
11
|
model: string,
|
|
12
12
|
): ModelPricing | null {
|
|
13
|
-
|
|
13
|
+
// A model the platform neither prices nor configures is served from Pi's
|
|
14
|
+
// catalog (see buildModel), so its catalog price is the one it is billed at.
|
|
15
|
+
const price = credentials.model_prices?.[model]
|
|
16
|
+
?? (credentials.model_configs?.[model] === undefined ? registeredModelPrice(model) : null);
|
|
14
17
|
if (!price || typeof price.input !== "number" || typeof price.output !== "number") return null;
|
|
15
18
|
// Null cached rates mean the provider publishes none: bill cached prompt
|
|
16
19
|
// buckets at the input rate, never for free.
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
type CandidatePromptAccounting,
|
|
5
5
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
6
6
|
|
|
7
|
-
import { toolsByWireName } from "../interaction/tool_identity";
|
|
7
|
+
import { toolsByWireName } from "../interaction/tool_identity.js";
|
|
8
8
|
import type {
|
|
9
9
|
InteractionContent,
|
|
10
10
|
InteractionRequest,
|
|
11
11
|
ProviderIdentity,
|
|
12
|
-
} from "../interaction/types";
|
|
13
|
-
import { buildContext } from "../providers/pi_context";
|
|
14
|
-
import { isOpenAIResponsesApi } from "../providers/model_capabilities";
|
|
15
|
-
import type { InteractionPrefixContext } from "./interaction_fingerprint";
|
|
12
|
+
} from "../interaction/types.js";
|
|
13
|
+
import { buildContext } from "../providers/pi_context.js";
|
|
14
|
+
import { isOpenAIResponsesApi } from "../providers/model_capabilities.js";
|
|
15
|
+
import type { InteractionPrefixContext } from "./interaction_fingerprint.js";
|
|
16
16
|
|
|
17
17
|
type PromptMetrics = {
|
|
18
18
|
blockDepth: number;
|
|
@@ -15,34 +15,34 @@ import {
|
|
|
15
15
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
16
16
|
import { randomUUID } from "node:crypto";
|
|
17
17
|
|
|
18
|
-
import { HttpError } from "../http/errors";
|
|
19
|
-
import { effectiveContextWindow } from "../models/context_limits";
|
|
20
|
-
import { keySourceForModel } from "../models/execution_provider";
|
|
21
|
-
import { requiredCapabilitiesFor } from "../interaction/capabilities";
|
|
22
|
-
import { providerIdentityFromModel } from "../interaction/provider_continuation_state";
|
|
23
|
-
import { isBackgroundRequest, type InteractionRequest, type ProviderIdentity } from "../interaction/types";
|
|
24
|
-
import { requireCandidateModels } from "../models/ids";
|
|
25
|
-
import { modelMetadataLookup } from "../providers/pi";
|
|
18
|
+
import { HttpError } from "../http/errors.js";
|
|
19
|
+
import { effectiveContextWindow } from "../models/context_limits.js";
|
|
20
|
+
import { keySourceForModel } from "../models/execution_provider.js";
|
|
21
|
+
import { requiredCapabilitiesFor } from "../interaction/capabilities.js";
|
|
22
|
+
import { providerIdentityFromModel } from "../interaction/provider_continuation_state.js";
|
|
23
|
+
import { isBackgroundRequest, type InteractionRequest, type ProviderIdentity } from "../interaction/types.js";
|
|
24
|
+
import { requireCandidateModels } from "../models/ids.js";
|
|
25
|
+
import { modelMetadataLookup } from "../providers/pi.js";
|
|
26
26
|
import {
|
|
27
27
|
modelSupportsImageInput,
|
|
28
28
|
modelSupportsHostedWebSearch,
|
|
29
29
|
modelSupportsReasoningConfigurationUpdate,
|
|
30
30
|
providerApiCanSerializeResponseFormat,
|
|
31
|
-
} from "../providers/model_capabilities";
|
|
31
|
+
} from "../providers/model_capabilities.js";
|
|
32
32
|
import {
|
|
33
33
|
selectorMessagesForInteraction,
|
|
34
34
|
type SelectorImage,
|
|
35
|
-
} from "../strategies/selector_projection";
|
|
36
|
-
import type { ResolvedRouter } from "../types";
|
|
35
|
+
} from "../strategies/selector_projection.js";
|
|
36
|
+
import type { ResolvedRouter } from "../types.js";
|
|
37
37
|
import {
|
|
38
38
|
interactionPrefixContext,
|
|
39
39
|
interactionPrefixLookupHashes,
|
|
40
40
|
type InteractionPrefixContext,
|
|
41
|
-
} from "./interaction_fingerprint";
|
|
42
|
-
import { pricingLookupForRouter } from "./pricing";
|
|
43
|
-
import { providerPromptAccounting } from "./provider_prompt_accounting";
|
|
44
|
-
import { leaseHistoryFromPrefixHits } from "./lease_history";
|
|
45
|
-
import { interactionLeaseFenceDepth } from "./interaction_lease_depth";
|
|
41
|
+
} from "./interaction_fingerprint.js";
|
|
42
|
+
import { pricingLookupForRouter } from "./pricing.js";
|
|
43
|
+
import { providerPromptAccounting } from "./provider_prompt_accounting.js";
|
|
44
|
+
import { leaseHistoryFromPrefixHits } from "./lease_history.js";
|
|
45
|
+
import { interactionLeaseFenceDepth } from "./interaction_lease_depth.js";
|
|
46
46
|
|
|
47
47
|
export type ImageCapabilityPrunedModel = {
|
|
48
48
|
model: string;
|
package/src/http/auth.ts
CHANGED
package/src/http/handler.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleResponses,
|
|
3
3
|
handleResponsesWebSocketFallback,
|
|
4
|
-
} from "../ingress/codex";
|
|
5
|
-
import { handleModels } from "../ingress/models";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
4
|
+
} from "../ingress/codex.js";
|
|
5
|
+
import { handleModels } from "../ingress/models.js";
|
|
6
|
+
import { handleMuseCodeModels } from "../ingress/muse_models.js";
|
|
7
|
+
import { handleChatCompletions } from "../ingress/chat_completions.js";
|
|
8
|
+
import { handleAnthropicMessages } from "../ingress/anthropic_messages.js";
|
|
9
|
+
import { bindGatewayPlatform, type GatewayPlatform } from "../platform/platform.js";
|
|
10
|
+
import { DEFAULT_ROUTER_ALIAS } from "../platform/routing_contract.js";
|
|
11
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
12
|
+
import { errorResponse, HttpError } from "./errors.js";
|
|
12
13
|
|
|
13
14
|
export type GatewayHandlerOptions = {
|
|
14
15
|
platform: GatewayPlatform;
|
|
@@ -31,6 +32,12 @@ export function createRequestHandler(options: GatewayHandlerOptions) {
|
|
|
31
32
|
) {
|
|
32
33
|
return Response.json({ status: "ok" });
|
|
33
34
|
}
|
|
35
|
+
// Muse Code reads its model list from its base URL's origin; `dari muse`
|
|
36
|
+
// forwards it to the router's own path.
|
|
37
|
+
const museModels = url.pathname.match(/^(?:\/([^/]+))?\/muse-code\/models$/);
|
|
38
|
+
if (request.method === "GET" && museModels !== null) {
|
|
39
|
+
return await handleMuseCodeModels(request, museModels[1] ?? DEFAULT_ROUTER_ALIAS);
|
|
40
|
+
}
|
|
34
41
|
// Claude Code probes this first-party endpoint before its Messages call
|
|
35
42
|
// when ANTHROPIC_BASE_URL points at a compatible gateway.
|
|
36
43
|
if (request.method === "HEAD" && url.pathname === "/api/hello") {
|
package/src/http/serve.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { captureOperationalError } from "../observability/errors";
|
|
2
|
-
import { drainBackgroundTelemetryFor } from "../telemetry/background";
|
|
3
|
-
import { startHttp2Server } from "./http2_server";
|
|
1
|
+
import { captureOperationalError } from "../observability/errors.js";
|
|
2
|
+
import { drainBackgroundTelemetryFor } from "../telemetry/background.js";
|
|
3
|
+
import { startHttp2Server } from "./http2_server.js";
|
|
4
4
|
|
|
5
5
|
const GRACEFUL_SERVER_STOP_TIMEOUT_MS = 5_000;
|
|
6
6
|
const FORCE_STOP_SETTLE_TIMEOUT_MS = 250;
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// (`@mupt-ai/dari-gateway/<dir>/<module>`) for deployments that compose the
|
|
3
3
|
// gateway with their own platform. This entry needs no Bun APIs; the Bun
|
|
4
4
|
// server and the SQLite-backed self-hosted gateway live in `./bun`.
|
|
5
|
-
export { createRequestHandler, type GatewayHandlerOptions } from "./http/handler";
|
|
5
|
+
export { createRequestHandler, type GatewayHandlerOptions } from "./http/handler.js";
|
|
6
6
|
export type {
|
|
7
7
|
GatewayPlatform,
|
|
8
8
|
OperationalErrorContext,
|
|
@@ -15,8 +15,16 @@ export type {
|
|
|
15
15
|
RequestTags,
|
|
16
16
|
ResolveRouterRequest,
|
|
17
17
|
SubscriptionHold,
|
|
18
|
-
} from "./platform/platform";
|
|
19
|
-
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
} from "./platform/platform.js";
|
|
19
|
+
export {
|
|
20
|
+
DEFAULT_CATALOG_PROVIDERS,
|
|
21
|
+
listModelCatalog,
|
|
22
|
+
type CatalogModel,
|
|
23
|
+
type CatalogModelPrice,
|
|
24
|
+
type CatalogPriceTier,
|
|
25
|
+
type ModelCatalogOptions,
|
|
26
|
+
} from "./models/catalog.js";
|
|
27
|
+
export { createAutoRoutingSelectorBackend } from "./strategies/auto_routing_selector.js";
|
|
28
|
+
export { createPrioritySelectorBackend } from "./strategies/priority_selector.js";
|
|
29
|
+
export { createLlmSelectorBackend, type SelectorBackend } from "./strategies/routing.js";
|
|
30
|
+
export type { ProviderCredential, ResolvedRouter, SubscriptionKind } from "./types.js";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import { anthropicMessagesResponse } from "../protocol/output/anthropic_messages";
|
|
3
|
-
import { anthropicMessagesSseStream } from "../protocol/output/anthropic_messages_stream";
|
|
4
|
-
import { anthropicToken } from "../http/auth";
|
|
5
|
-
import { errorResponseHeaders, normalizeError } from "../http/errors";
|
|
6
|
-
import { captureRequestError } from "../observability/errors";
|
|
7
|
-
import { anthropicMessagesToInteraction } from "../protocol/input/anthropic_messages";
|
|
8
|
-
import { handleRoutedCompletion } from "../runtime/routed_completion";
|
|
9
|
-
import type { SelectorBackend } from "../strategies/routing";
|
|
10
|
-
import { claudeCodeRequestContext } from "./claude_code/request_context";
|
|
2
|
+
import { anthropicMessagesResponse } from "../protocol/output/anthropic_messages.js";
|
|
3
|
+
import { anthropicMessagesSseStream } from "../protocol/output/anthropic_messages_stream.js";
|
|
4
|
+
import { anthropicToken } from "../http/auth.js";
|
|
5
|
+
import { errorResponseHeaders, normalizeError } from "../http/errors.js";
|
|
6
|
+
import { captureRequestError } from "../observability/errors.js";
|
|
7
|
+
import { anthropicMessagesToInteraction } from "../protocol/input/anthropic_messages.js";
|
|
8
|
+
import { handleRoutedCompletion } from "../runtime/routed_completion.js";
|
|
9
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
10
|
+
import { claudeCodeRequestContext } from "./claude_code/request_context.js";
|
|
11
11
|
import {
|
|
12
12
|
claudeCodeConversationIdentity,
|
|
13
|
-
} from "../runtime/harness_identity";
|
|
14
|
-
import { parseJsonRequest } from "./json";
|
|
15
|
-
import type { AnthropicSafeguards } from "../interaction/types";
|
|
13
|
+
} from "../runtime/harness_identity/index.js";
|
|
14
|
+
import { parseJsonRequest } from "./json.js";
|
|
15
|
+
import type { AnthropicSafeguards } from "../interaction/types.js";
|
|
16
16
|
|
|
17
17
|
type AnthropicErrorType =
|
|
18
18
|
| "authentication_error"
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
is rejected, bare tier names classify). Fixed created_at keeps the response
|
|
7
7
|
byte-stable. */
|
|
8
8
|
|
|
9
|
-
import { ANTHROPIC_ROUTER_MODEL_TIERS } from "../protocol/input/router_model";
|
|
9
|
+
import { ANTHROPIC_ROUTER_MODEL_TIERS } from "../protocol/input/router_model.js";
|
|
10
10
|
|
|
11
11
|
const ROUTER_MODEL_CREATED_AT = "2026-01-01T00:00:00Z";
|
|
12
12
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { ChatCompletionRequest } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import { bearerToken } from "../http/auth";
|
|
3
|
-
import { errorResponse } from "../http/errors";
|
|
4
|
-
import { captureRequestError } from "../observability/errors";
|
|
5
|
-
import { chatCompletionResponse, chatCompletionsSseStream } from "../protocol/output/chat_completions";
|
|
6
|
-
import { chatCompletionsToInteraction } from "../protocol/input/chat_completions";
|
|
7
|
-
import { handleRoutedCompletion } from "../runtime/routed_completion";
|
|
8
|
-
import type { SelectorBackend } from "../strategies/routing";
|
|
2
|
+
import { bearerToken } from "../http/auth.js";
|
|
3
|
+
import { errorResponse } from "../http/errors.js";
|
|
4
|
+
import { captureRequestError } from "../observability/errors.js";
|
|
5
|
+
import { chatCompletionResponse, chatCompletionsSseStream } from "../protocol/output/chat_completions.js";
|
|
6
|
+
import { chatCompletionsToInteraction } from "../protocol/input/chat_completions.js";
|
|
7
|
+
import { handleRoutedCompletion } from "../runtime/routed_completion.js";
|
|
8
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
9
9
|
import {
|
|
10
10
|
chatCompletionsConversationIdentity,
|
|
11
11
|
openCodeRequestContext,
|
|
12
|
-
} from "../runtime/harness_identity";
|
|
13
|
-
import { parseJsonRequest } from "./json";
|
|
12
|
+
} from "../runtime/harness_identity/index.js";
|
|
13
|
+
import { parseJsonRequest } from "./json.js";
|
|
14
|
+
import { museCodeClientId } from "./muse_code.js";
|
|
14
15
|
|
|
15
16
|
export async function handleChatCompletions(
|
|
16
17
|
request: Request,
|
|
@@ -22,15 +23,21 @@ export async function handleChatCompletions(
|
|
|
22
23
|
const payload = await parseJsonRequest<ChatCompletionRequest>(request);
|
|
23
24
|
const interaction = chatCompletionsToInteraction({ ...payload, source_protocol: "openai_chat" });
|
|
24
25
|
const agentContext = openCodeRequestContext(request.headers);
|
|
26
|
+
const museClientId = museCodeClientId(request.headers);
|
|
25
27
|
return await handleRoutedCompletion({
|
|
26
28
|
request,
|
|
27
29
|
routerId,
|
|
28
30
|
apiKey,
|
|
29
|
-
payload:
|
|
31
|
+
payload: {
|
|
32
|
+
...interaction,
|
|
33
|
+
...(agentContext === undefined ? {} : { agentContext }),
|
|
34
|
+
...(museClientId === undefined ? {} : { museCodeClientId: museClientId }),
|
|
35
|
+
},
|
|
30
36
|
responseBody: chatCompletionResponse,
|
|
31
37
|
streamBody: chatCompletionsSseStream,
|
|
32
38
|
errorResponse,
|
|
33
39
|
selectorBackend,
|
|
40
|
+
clientHarness: museClientId === undefined ? undefined : "muse_code",
|
|
34
41
|
harnessConversationIdentity: chatCompletionsConversationIdentity(
|
|
35
42
|
request.headers,
|
|
36
43
|
payload.prompt_cache_key,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpError } from "../../http/errors";
|
|
2
|
-
import type { AgentRequestContext, AgentRequestClass } from "../../interaction/types";
|
|
1
|
+
import { HttpError } from "../../http/errors.js";
|
|
2
|
+
import type { AgentRequestContext, AgentRequestClass } from "../../interaction/types.js";
|
|
3
3
|
|
|
4
4
|
const REQUEST_CLASSES = new Set<AgentRequestClass>([
|
|
5
5
|
"main", "subagent", "workflow", "auxiliary", "compaction", "side_reply",
|
package/src/ingress/codex.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { bearerToken } from "../http/auth";
|
|
2
|
-
import { errorResponse } from "../http/errors";
|
|
3
|
-
import { captureRequestError } from "../observability/errors";
|
|
4
|
-
import { openAIResponsesResponse } from "../protocol/output/openai_responses";
|
|
5
|
-
import { openAIResponsesSseStream } from "../protocol/output/openai_responses_stream";
|
|
6
|
-
import { openAIResponsesToInteraction } from "../protocol/input/openai_responses";
|
|
7
|
-
import { parseJsonRequest } from "./json";
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
1
|
+
import { bearerToken } from "../http/auth.js";
|
|
2
|
+
import { errorResponse } from "../http/errors.js";
|
|
3
|
+
import { captureRequestError } from "../observability/errors.js";
|
|
4
|
+
import { openAIResponsesResponse } from "../protocol/output/openai_responses.js";
|
|
5
|
+
import { openAIResponsesSseStream } from "../protocol/output/openai_responses_stream.js";
|
|
6
|
+
import { openAIResponsesToInteraction } from "../protocol/input/openai_responses.js";
|
|
7
|
+
import { parseJsonRequest } from "./json.js";
|
|
8
|
+
import { museCodeClientId } from "./muse_code.js";
|
|
9
|
+
import { handleRoutedCompletion } from "../runtime/routed_completion.js";
|
|
10
|
+
import type { SelectorBackend } from "../strategies/routing.js";
|
|
10
11
|
import {
|
|
11
12
|
codexConversationIdentity,
|
|
12
13
|
codexRequestPurpose,
|
|
13
14
|
codexRequestContext,
|
|
14
|
-
} from "../runtime/harness_identity";
|
|
15
|
+
} from "../runtime/harness_identity/index.js";
|
|
15
16
|
|
|
16
17
|
export async function handleResponses(
|
|
17
18
|
request: Request,
|
|
@@ -24,10 +25,12 @@ export async function handleResponses(
|
|
|
24
25
|
const interaction = openAIResponsesToInteraction(rawPayload);
|
|
25
26
|
const requestPurpose = codexRequestPurpose(request.headers, rawPayload);
|
|
26
27
|
const agentContext = codexRequestContext(request.headers, rawPayload);
|
|
28
|
+
const museClientId = museCodeClientId(request.headers);
|
|
27
29
|
const payload = {
|
|
28
30
|
...interaction,
|
|
29
31
|
...(requestPurpose === undefined ? {} : { requestPurpose }),
|
|
30
32
|
...(agentContext === undefined ? {} : { agentContext }),
|
|
33
|
+
...(museClientId === undefined ? {} : { museCodeClientId: museClientId }),
|
|
31
34
|
};
|
|
32
35
|
const harnessConversationIdentity = codexConversationIdentity(
|
|
33
36
|
request.headers,
|
|
@@ -47,6 +50,7 @@ export async function handleResponses(
|
|
|
47
50
|
streamBody: openAIResponsesSseStream,
|
|
48
51
|
errorResponse,
|
|
49
52
|
selectorBackend,
|
|
53
|
+
clientHarness: museClientId === undefined ? undefined : "muse_code",
|
|
50
54
|
harnessConversationIdentity,
|
|
51
55
|
});
|
|
52
56
|
} catch (error) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ResolvedRouter } from "../types";
|
|
2
|
-
import { CANONICAL_ROUTER_MODEL, explicitModelSlug } from "../protocol/input/router_model";
|
|
3
|
-
import { effectiveContextWindow } from "../models/context_limits";
|
|
4
|
-
import { modelSupportsHostedWebSearch } from "../providers/model_capabilities";
|
|
1
|
+
import type { ResolvedRouter } from "../types.js";
|
|
2
|
+
import { CANONICAL_ROUTER_MODEL, explicitModelSlug } from "../protocol/input/router_model.js";
|
|
3
|
+
import { effectiveContextWindow } from "../models/context_limits.js";
|
|
4
|
+
import { modelSupportsHostedWebSearch } from "../providers/model_capabilities.js";
|
|
5
5
|
|
|
6
6
|
const DEFAULT_CODEX_CONTEXT_WINDOW = 128_000;
|
|
7
7
|
|
package/src/ingress/json.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
createZstdDecompress,
|
|
7
7
|
} from "node:zlib";
|
|
8
8
|
|
|
9
|
-
import { HttpError } from "../http/errors";
|
|
9
|
+
import { HttpError } from "../http/errors.js";
|
|
10
10
|
|
|
11
11
|
const MAX_ENCODED_JSON_REQUEST_BYTES = 64 * 1024 * 1024;
|
|
12
12
|
const MAX_DECODED_JSON_REQUEST_BYTES = 64 * 1024 * 1024;
|