@mupt-ai/dari-gateway 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/bun.d.ts +2 -0
- package/dist/bun.js +4 -0
- package/dist/context/eval_catalog.d.ts +3 -0
- package/dist/context/eval_catalog.js +7 -0
- package/dist/context/interaction_fingerprint.d.ts +27 -0
- package/dist/context/interaction_fingerprint.js +519 -0
- package/dist/context/interaction_fingerprint_format.d.ts +42 -0
- package/dist/context/interaction_fingerprint_format.js +113 -0
- package/dist/context/interaction_lease_depth.d.ts +2 -0
- package/dist/context/interaction_lease_depth.js +110 -0
- package/dist/context/lease_history.d.ts +7 -0
- package/dist/context/lease_history.js +158 -0
- package/dist/context/pricing.d.ts +4 -0
- package/dist/context/pricing.js +23 -0
- package/dist/context/provider_prompt_accounting.d.ts +14 -0
- package/dist/context/provider_prompt_accounting.js +187 -0
- package/dist/context/routing_context.d.ts +40 -0
- package/dist/context/routing_context.js +211 -0
- package/dist/http/auth.d.ts +2 -0
- package/dist/http/auth.js +35 -0
- package/dist/http/errors.d.ts +19 -0
- package/dist/http/errors.js +89 -0
- package/dist/http/handler.d.ts +12 -0
- package/dist/http/handler.js +81 -0
- package/dist/http/http2_server.d.ts +6 -0
- package/dist/http/http2_server.js +103 -0
- package/dist/http/serve.d.ts +20 -0
- package/dist/http/serve.js +78 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/ingress/anthropic_messages.d.ts +3 -0
- package/dist/ingress/anthropic_messages.js +122 -0
- package/dist/ingress/anthropic_models.d.ts +1 -0
- package/dist/ingress/anthropic_models.js +23 -0
- package/dist/ingress/chat_completions.d.ts +2 -0
- package/dist/ingress/chat_completions.js +37 -0
- package/dist/ingress/claude_code/request_context.d.ts +2 -0
- package/dist/ingress/claude_code/request_context.js +31 -0
- package/dist/ingress/codex.d.ts +3 -0
- package/dist/ingress/codex.js +65 -0
- package/dist/ingress/codex_models.d.ts +2 -0
- package/dist/ingress/codex_models.js +89 -0
- package/dist/ingress/json.d.ts +1 -0
- package/dist/ingress/json.js +95 -0
- package/dist/ingress/models.d.ts +1 -0
- package/dist/ingress/models.js +53 -0
- package/dist/interaction/capabilities.d.ts +3 -0
- package/dist/interaction/capabilities.js +24 -0
- package/dist/interaction/image.d.ts +4 -0
- package/dist/interaction/image.js +13 -0
- package/dist/interaction/portable_reasoning_state.d.ts +4 -0
- package/dist/interaction/portable_reasoning_state.js +18 -0
- package/dist/interaction/provider_continuation_state.d.ts +6 -0
- package/dist/interaction/provider_continuation_state.js +27 -0
- package/dist/interaction/tool_identity.d.ts +10 -0
- package/dist/interaction/tool_identity.js +41 -0
- package/dist/interaction/types.d.ts +203 -0
- package/dist/interaction/types.js +5 -0
- package/dist/models/context_limits.d.ts +2 -0
- package/dist/models/context_limits.js +7 -0
- package/dist/models/execution_provider.d.ts +8 -0
- package/dist/models/execution_provider.js +13 -0
- package/dist/models/gateways.d.ts +11 -0
- package/dist/models/gateways.js +45 -0
- package/dist/models/ids.d.ts +1 -0
- package/dist/models/ids.js +15 -0
- package/dist/models/provider_defaults.d.ts +4 -0
- package/dist/models/provider_defaults.js +41 -0
- package/dist/models/runtime_overrides.d.ts +4 -0
- package/dist/models/runtime_overrides.js +209 -0
- package/dist/observability/errors.d.ts +8 -0
- package/dist/observability/errors.js +11 -0
- package/dist/platform/platform.d.ts +152 -0
- package/dist/platform/platform.js +11 -0
- package/dist/platform/routing_contract.d.ts +2 -0
- package/dist/platform/routing_contract.js +5 -0
- package/dist/protocol/input/anthropic_messages.d.ts +2 -0
- package/dist/protocol/input/anthropic_messages.js +494 -0
- package/dist/protocol/input/chat_completions.d.ts +4 -0
- package/dist/protocol/input/chat_completions.js +212 -0
- package/dist/protocol/input/chat_completions_validation.d.ts +2 -0
- package/dist/protocol/input/chat_completions_validation.js +257 -0
- package/dist/protocol/input/openai_responses.d.ts +2 -0
- package/dist/protocol/input/openai_responses.js +666 -0
- package/dist/protocol/input/router_model.d.ts +7 -0
- package/dist/protocol/input/router_model.js +43 -0
- package/dist/protocol/output/anthropic_messages.d.ts +10 -0
- package/dist/protocol/output/anthropic_messages.js +15 -0
- package/dist/protocol/output/anthropic_messages_output.d.ts +10 -0
- package/dist/protocol/output/anthropic_messages_output.js +124 -0
- package/dist/protocol/output/anthropic_messages_stream.d.ts +16 -0
- package/dist/protocol/output/anthropic_messages_stream.js +267 -0
- package/dist/protocol/output/chat_completions.d.ts +29 -0
- package/dist/protocol/output/chat_completions.js +406 -0
- package/dist/protocol/output/chat_reasoning_detail.d.ts +2 -0
- package/dist/protocol/output/chat_reasoning_detail.js +13 -0
- package/dist/protocol/output/delivered_stream_snapshot.d.ts +10 -0
- package/dist/protocol/output/delivered_stream_snapshot.js +31 -0
- package/dist/protocol/output/openai_responses.d.ts +10 -0
- package/dist/protocol/output/openai_responses.js +14 -0
- package/dist/protocol/output/openai_responses_output.d.ts +14 -0
- package/dist/protocol/output/openai_responses_output.js +125 -0
- package/dist/protocol/output/openai_responses_stream.d.ts +18 -0
- package/dist/protocol/output/openai_responses_stream.js +546 -0
- package/dist/protocol/output/sse_stream.d.ts +31 -0
- package/dist/protocol/output/sse_stream.js +67 -0
- package/dist/providers/anthropic_safeguards.d.ts +11 -0
- package/dist/providers/anthropic_safeguards.js +81 -0
- package/dist/providers/aws_assume_role.d.ts +17 -0
- package/dist/providers/aws_assume_role.js +107 -0
- package/dist/providers/cancel_estimate.d.ts +43 -0
- package/dist/providers/cancel_estimate.js +89 -0
- package/dist/providers/execution.d.ts +72 -0
- package/dist/providers/execution.js +491 -0
- package/dist/providers/model_capabilities.d.ts +11 -0
- package/dist/providers/model_capabilities.js +29 -0
- package/dist/providers/pi.d.ts +65 -0
- package/dist/providers/pi.js +319 -0
- package/dist/providers/pi_context.d.ts +7 -0
- package/dist/providers/pi_context.js +405 -0
- package/dist/providers/pi_options.d.ts +11 -0
- package/dist/providers/pi_options.js +398 -0
- package/dist/providers/pi_output.d.ts +2 -0
- package/dist/providers/pi_output.js +453 -0
- package/dist/providers/provider_attempt_runner.d.ts +55 -0
- package/dist/providers/provider_attempt_runner.js +90 -0
- package/dist/providers/provider_call.d.ts +77 -0
- package/dist/providers/provider_call.js +292 -0
- package/dist/providers/provider_reported_cost.d.ts +10 -0
- package/dist/providers/provider_reported_cost.js +123 -0
- package/dist/providers/reasoning.d.ts +12 -0
- package/dist/providers/reasoning.js +30 -0
- package/dist/providers/response_capture.d.ts +23 -0
- package/dist/providers/response_capture.js +47 -0
- package/dist/providers/stream_finalization.d.ts +46 -0
- package/dist/providers/stream_finalization.js +165 -0
- package/dist/providers/subscription_limits.d.ts +31 -0
- package/dist/providers/subscription_limits.js +163 -0
- package/dist/providers/subscription_usage.d.ts +10 -0
- package/dist/providers/subscription_usage.js +79 -0
- package/dist/runtime/claude_code/auxiliary_routing.d.ts +3 -0
- package/dist/runtime/claude_code/auxiliary_routing.js +60 -0
- package/dist/runtime/customer_disconnect.d.ts +20 -0
- package/dist/runtime/customer_disconnect.js +49 -0
- package/dist/runtime/explicit_model.d.ts +4 -0
- package/dist/runtime/explicit_model.js +53 -0
- package/dist/runtime/harness_identity/conversation.d.ts +33 -0
- package/dist/runtime/harness_identity/conversation.js +39 -0
- package/dist/runtime/harness_identity/extract.d.ts +8 -0
- package/dist/runtime/harness_identity/extract.js +214 -0
- package/dist/runtime/harness_identity/index.d.ts +2 -0
- package/dist/runtime/harness_identity/index.js +2 -0
- package/dist/runtime/prepare_routed_completion.d.ts +33 -0
- package/dist/runtime/prepare_routed_completion.js +167 -0
- package/dist/runtime/provider_stream_lifecycle.d.ts +31 -0
- package/dist/runtime/provider_stream_lifecycle.js +88 -0
- package/dist/runtime/provider_stream_outcome.d.ts +23 -0
- package/dist/runtime/provider_stream_outcome.js +55 -0
- package/dist/runtime/request_tags.d.ts +7 -0
- package/dist/runtime/request_tags.js +33 -0
- package/dist/runtime/routed_completion.d.ts +17 -0
- package/dist/runtime/routed_completion.js +80 -0
- package/dist/runtime/routed_protocol.d.ts +30 -0
- package/dist/runtime/routed_protocol.js +1 -0
- package/dist/runtime/routed_runtime.d.ts +40 -0
- package/dist/runtime/routed_runtime.js +535 -0
- package/dist/runtime/routing_lease.d.ts +26 -0
- package/dist/runtime/routing_lease.js +210 -0
- package/dist/runtime/runtime_reporter.d.ts +71 -0
- package/dist/runtime/runtime_reporter.js +35 -0
- package/dist/self_host/config.d.ts +46 -0
- package/dist/self_host/config.js +105 -0
- package/dist/self_host/main.d.ts +16 -0
- package/dist/self_host/main.js +95 -0
- package/dist/self_host/platform.d.ts +13 -0
- package/dist/self_host/platform.js +50 -0
- package/dist/self_host/prefix_store.d.ts +46 -0
- package/dist/self_host/prefix_store.js +261 -0
- package/dist/self_host/resolve.d.ts +28 -0
- package/dist/self_host/resolve.js +171 -0
- package/dist/self_host/subscriptions/access.d.ts +10 -0
- package/dist/self_host/subscriptions/access.js +37 -0
- package/dist/self_host/subscriptions/http.d.ts +15 -0
- package/dist/self_host/subscriptions/http.js +187 -0
- package/dist/self_host/subscriptions/index.d.ts +24 -0
- package/dist/self_host/subscriptions/index.js +24 -0
- package/dist/self_host/subscriptions/oauth.d.ts +55 -0
- package/dist/self_host/subscriptions/oauth.js +281 -0
- package/dist/self_host/subscriptions/store.d.ts +78 -0
- package/dist/self_host/subscriptions/store.js +235 -0
- package/dist/strategies/auto_routing_selector.d.ts +12 -0
- package/dist/strategies/auto_routing_selector.js +61 -0
- package/dist/strategies/eval_relevance.d.ts +17 -0
- package/dist/strategies/eval_relevance.js +32 -0
- package/dist/strategies/fallback_decision.d.ts +8 -0
- package/dist/strategies/fallback_decision.js +17 -0
- package/dist/strategies/priority_selector.d.ts +7 -0
- package/dist/strategies/priority_selector.js +37 -0
- package/dist/strategies/route_decision.d.ts +22 -0
- package/dist/strategies/route_decision.js +65 -0
- package/dist/strategies/routing.d.ts +74 -0
- package/dist/strategies/routing.js +280 -0
- package/dist/strategies/selector_projection.d.ts +15 -0
- package/dist/strategies/selector_projection.js +161 -0
- package/dist/telemetry/background.d.ts +7 -0
- package/dist/telemetry/background.js +33 -0
- package/dist/telemetry/benchmark_replay.d.ts +37 -0
- package/dist/telemetry/benchmark_replay.js +108 -0
- package/dist/telemetry/billing_finalization.d.ts +64 -0
- package/dist/telemetry/billing_finalization.js +96 -0
- package/dist/telemetry/ingest_values.d.ts +4 -0
- package/dist/telemetry/ingest_values.js +12 -0
- package/dist/telemetry/model_cost.d.ts +3 -0
- package/dist/telemetry/model_cost.js +15 -0
- package/dist/telemetry/prefix_state.d.ts +47 -0
- package/dist/telemetry/prefix_state.js +116 -0
- package/dist/telemetry/report.d.ts +88 -0
- package/dist/telemetry/report.js +621 -0
- package/dist/telemetry/requests/interaction_observability.d.ts +45 -0
- package/dist/telemetry/requests/interaction_observability.js +180 -0
- package/dist/telemetry/requests/retained_interaction_request.d.ts +8 -0
- package/dist/telemetry/requests/retained_interaction_request.js +10 -0
- package/dist/telemetry/scrub.d.ts +2 -0
- package/dist/telemetry/scrub.js +31 -0
- package/dist/telemetry/skills/claude/catalog.d.ts +6 -0
- package/dist/telemetry/skills/claude/catalog.js +99 -0
- package/dist/telemetry/skills/claude/file_reads.d.ts +4 -0
- package/dist/telemetry/skills/claude/file_reads.js +110 -0
- package/dist/telemetry/skills/claude/observations.d.ts +3 -0
- package/dist/telemetry/skills/claude/observations.js +366 -0
- package/dist/telemetry/skills/codex/catalog.d.ts +11 -0
- package/dist/telemetry/skills/codex/catalog.js +138 -0
- package/dist/telemetry/skills/codex/exec_file_reads.d.ts +9 -0
- package/dist/telemetry/skills/codex/exec_file_reads.js +36 -0
- package/dist/telemetry/skills/codex/explicit.d.ts +3 -0
- package/dist/telemetry/skills/codex/explicit.js +90 -0
- package/dist/telemetry/skills/codex/file_reads.d.ts +4 -0
- package/dist/telemetry/skills/codex/file_reads.js +37 -0
- package/dist/telemetry/skills/codex/identity.d.ts +2 -0
- package/dist/telemetry/skills/codex/identity.js +20 -0
- package/dist/telemetry/skills/observations.d.ts +21 -0
- package/dist/telemetry/skills/observations.js +41 -0
- package/dist/telemetry/skills/paths.d.ts +11 -0
- package/dist/telemetry/skills/paths.js +61 -0
- package/dist/telemetry/skills/pi.d.ts +6 -0
- package/dist/telemetry/skills/pi.js +223 -0
- package/dist/telemetry/skills/shell_file_reads.d.ts +7 -0
- package/dist/telemetry/skills/shell_file_reads.js +226 -0
- package/dist/telemetry/skills/shell_words.d.ts +13 -0
- package/dist/telemetry/skills/shell_words.js +189 -0
- package/dist/telemetry/tools/input.d.ts +2 -0
- package/dist/telemetry/tools/input.js +14 -0
- package/dist/telemetry/tools/observations.d.ts +29 -0
- package/dist/telemetry/tools/observations.js +247 -0
- package/dist/telemetry/usage.d.ts +57 -0
- package/dist/telemetry/usage.js +136 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.js +1 -0
- package/package.json +22 -5
- package/src/bun.ts +4 -0
- package/src/context/eval_catalog.ts +1 -1
- package/src/context/interaction_fingerprint.ts +9 -9
- package/src/context/interaction_fingerprint_format.ts +1 -1
- package/src/context/interaction_lease_depth.ts +1 -1
- package/src/context/pricing.ts +1 -1
- package/src/context/provider_prompt_accounting.ts +5 -5
- package/src/context/routing_context.ts +17 -17
- package/src/http/auth.ts +1 -1
- package/src/http/handler.ts +8 -8
- package/src/http/serve.ts +3 -3
- package/src/index.ts +10 -9
- package/src/ingress/anthropic_messages.ts +12 -12
- package/src/ingress/anthropic_models.ts +1 -1
- package/src/ingress/chat_completions.ts +9 -9
- package/src/ingress/claude_code/request_context.ts +2 -2
- package/src/ingress/codex.ts +10 -10
- package/src/ingress/codex_models.ts +4 -4
- package/src/ingress/json.ts +1 -1
- package/src/ingress/models.ts +10 -10
- package/src/interaction/capabilities.ts +1 -1
- package/src/interaction/portable_reasoning_state.ts +1 -1
- package/src/interaction/provider_continuation_state.ts +1 -1
- package/src/interaction/tool_identity.ts +2 -2
- package/src/interaction/types.ts +3 -0
- package/src/models/context_limits.ts +1 -1
- package/src/models/execution_provider.ts +1 -1
- package/src/models/ids.ts +1 -1
- package/src/models/provider_defaults.ts +1 -1
- package/src/models/runtime_overrides.ts +1 -1
- package/src/observability/errors.ts +2 -2
- package/src/platform/platform.ts +36 -4
- package/src/protocol/input/anthropic_messages.ts +7 -7
- package/src/protocol/input/chat_completions.ts +5 -5
- package/src/protocol/input/chat_completions_validation.ts +4 -4
- package/src/protocol/input/openai_responses.ts +6 -6
- package/src/protocol/output/anthropic_messages.ts +3 -3
- package/src/protocol/output/anthropic_messages_output.ts +6 -4
- package/src/protocol/output/anthropic_messages_stream.ts +7 -7
- package/src/protocol/output/chat_completions.ts +13 -13
- package/src/protocol/output/chat_reasoning_detail.ts +1 -1
- package/src/protocol/output/openai_responses.ts +3 -3
- package/src/protocol/output/openai_responses_output.ts +4 -2
- package/src/protocol/output/openai_responses_stream.ts +6 -6
- package/src/protocol/output/sse_stream.ts +3 -3
- package/src/providers/anthropic_safeguards.ts +2 -2
- package/src/providers/aws_assume_role.ts +2 -2
- package/src/providers/cancel_estimate.ts +1 -1
- package/src/providers/execution.ts +17 -17
- package/src/providers/pi.ts +115 -41
- package/src/providers/pi_context.ts +6 -6
- package/src/providers/pi_options.ts +283 -453
- package/src/providers/pi_output.ts +6 -5
- package/src/providers/provider_attempt_runner.ts +1 -1
- package/src/providers/provider_call.ts +37 -18
- package/src/providers/provider_reported_cost.ts +138 -0
- package/src/providers/reasoning.ts +2 -2
- package/src/providers/stream_finalization.ts +10 -10
- package/src/providers/subscription_limits.ts +3 -3
- package/src/runtime/claude_code/auxiliary_routing.ts +5 -5
- package/src/runtime/customer_disconnect.ts +1 -1
- package/src/runtime/explicit_model.ts +31 -4
- package/src/runtime/harness_identity/conversation.ts +1 -1
- package/src/runtime/harness_identity/extract.ts +3 -3
- package/src/runtime/harness_identity/index.ts +2 -2
- package/src/runtime/prepare_routed_completion.ts +46 -10
- package/src/runtime/provider_stream_lifecycle.ts +1 -1
- package/src/runtime/provider_stream_outcome.ts +2 -2
- package/src/runtime/request_tags.ts +34 -0
- package/src/runtime/routed_completion.ts +13 -11
- package/src/runtime/routed_protocol.ts +2 -2
- package/src/runtime/routed_runtime.ts +38 -20
- package/src/runtime/routing_lease.ts +7 -7
- package/src/runtime/runtime_reporter.ts +3 -3
- package/src/self_host/main.ts +19 -14
- package/src/self_host/platform.ts +5 -5
- package/src/self_host/prefix_store.ts +2 -2
- package/src/self_host/resolve.ts +11 -11
- package/src/self_host/subscriptions/access.ts +2 -2
- package/src/self_host/subscriptions/http.ts +2 -2
- package/src/self_host/subscriptions/index.ts +4 -4
- package/src/self_host/subscriptions/store.ts +1 -1
- package/src/strategies/auto_routing_selector.ts +2 -2
- package/src/strategies/eval_relevance.ts +3 -3
- package/src/strategies/priority_selector.ts +1 -1
- package/src/strategies/route_decision.ts +7 -7
- package/src/strategies/routing.ts +11 -11
- package/src/strategies/selector_projection.ts +2 -2
- package/src/telemetry/billing_finalization.ts +3 -3
- package/src/telemetry/model_cost.ts +1 -1
- package/src/telemetry/prefix_state.ts +4 -4
- package/src/telemetry/report.ts +30 -25
- package/src/telemetry/requests/interaction_observability.ts +1 -1
- package/src/telemetry/requests/retained_interaction_request.ts +1 -1
- package/src/telemetry/skills/claude/catalog.ts +1 -1
- package/src/telemetry/skills/claude/file_reads.ts +6 -6
- package/src/telemetry/skills/claude/observations.ts +3 -3
- package/src/telemetry/skills/codex/catalog.ts +3 -3
- package/src/telemetry/skills/codex/exec_file_reads.ts +4 -4
- package/src/telemetry/skills/codex/explicit.ts +3 -3
- package/src/telemetry/skills/codex/file_reads.ts +5 -5
- package/src/telemetry/skills/observations.ts +7 -7
- package/src/telemetry/skills/pi.ts +3 -3
- package/src/telemetry/skills/shell_file_reads.ts +2 -2
- package/src/telemetry/skills/shell_words.ts +1 -1
- package/src/telemetry/tools/input.ts +1 -1
- package/src/telemetry/tools/observations.ts +9 -9
- package/src/telemetry/usage.ts +9 -5
- package/src/types.ts +15 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type OperationalErrorContext, type RequestErrorContext } from "../platform/platform.js";
|
|
2
|
+
export type { OperationalErrorCode } from "../platform/platform.js";
|
|
3
|
+
export declare function captureRequestError(error: unknown, context: RequestErrorContext): void;
|
|
4
|
+
/**
|
|
5
|
+
* Report failures deliberately caught outside the ingress exception path,
|
|
6
|
+
* including work after a response has started and process shutdown.
|
|
7
|
+
*/
|
|
8
|
+
export declare function captureOperationalError(error: unknown, context: OperationalErrorContext): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { gatewayPlatform, } from "../platform/platform.js";
|
|
2
|
+
export function captureRequestError(error, context) {
|
|
3
|
+
gatewayPlatform().captureRequestError(error, context);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Report failures deliberately caught outside the ingress exception path,
|
|
7
|
+
* including work after a response has started and process shutdown.
|
|
8
|
+
*/
|
|
9
|
+
export function captureOperationalError(error, context) {
|
|
10
|
+
gatewayPlatform().captureOperationalError(error, context);
|
|
11
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { Provider, ReasoningEffort, RoutingStrategy } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
+
import type { HarnessConversationIdentity } from "../runtime/harness_identity/index.js";
|
|
3
|
+
import type { InteractionRequest, SourceProtocol } from "../interaction/types.js";
|
|
4
|
+
import type { SubscriptionUsageLimit } from "../providers/subscription_limits.js";
|
|
5
|
+
import type { ClientHarness, ProviderCredential, ProviderKeySource, ResolvedRouter } from "../types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Everything the gateway runtime needs from the deployment around it: router
|
|
8
|
+
* configuration and credentials, durable routing state, accounting sinks, and
|
|
9
|
+
* error reporting. The self-hosted gateway implements it with a local config
|
|
10
|
+
* file and SQLite (`self_host/`); other deployments supply their own.
|
|
11
|
+
*
|
|
12
|
+
* Methods may throw. Call sites that must not fail a served request catch,
|
|
13
|
+
* log, and continue.
|
|
14
|
+
*/
|
|
15
|
+
export type GatewayPlatform = {
|
|
16
|
+
/**
|
|
17
|
+
* Authenticate the request's key and return the router it may use, with
|
|
18
|
+
* decrypted provider credentials and the prefix-cache evidence matching
|
|
19
|
+
* `prefixHashes`. Throws HttpError(401) for an unknown key.
|
|
20
|
+
*/
|
|
21
|
+
resolveRouter(request: ResolveRouterRequest): Promise<ResolvedRouter>;
|
|
22
|
+
/**
|
|
23
|
+
* Optional. Supply the credential for one enabled model of this request,
|
|
24
|
+
* consulted after `resolveRouter` and before its provider keys (for the
|
|
25
|
+
* self-hosted gateway, its environment keys), so an embedder can serve
|
|
26
|
+
* per-tenant keys from its own store. Undefined keeps the resolved key.
|
|
27
|
+
*/
|
|
28
|
+
resolveProviderCredential?(request: ProviderCredentialRequest): Promise<ProviderCredential | undefined>;
|
|
29
|
+
/** Persist one completed turn's prefix entry and/or refresh a read entry. */
|
|
30
|
+
writePrefixState(write: PrefixStateWrite): Promise<void>;
|
|
31
|
+
/** Set or clear a conversation's prefetched routing lease. */
|
|
32
|
+
writePendingLease(write: PendingLeaseWrite): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Hold an exhausted personal subscription until it resets. Resolves whether
|
|
35
|
+
* another connected subscription for the same provider can serve a retry.
|
|
36
|
+
*/
|
|
37
|
+
markSubscriptionUnavailable(hold: SubscriptionHold): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Account one call served on a platform-managed provider key. Only reached
|
|
40
|
+
* when `resolveRouter` reports a "managed" key source.
|
|
41
|
+
*/
|
|
42
|
+
recordUsage(usage: Record<string, unknown>): Promise<void>;
|
|
43
|
+
/** Receive the finished request's log row. Must not throw. */
|
|
44
|
+
recordRequest(record: RequestRecord): void;
|
|
45
|
+
captureRequestError(error: unknown, context: RequestErrorContext): void;
|
|
46
|
+
captureOperationalError(error: unknown, context: OperationalErrorContext): void;
|
|
47
|
+
};
|
|
48
|
+
export type ResolveRouterRequest = {
|
|
49
|
+
routerId: string;
|
|
50
|
+
apiKey: string;
|
|
51
|
+
prefixHashes?: string[];
|
|
52
|
+
conversationId?: string;
|
|
53
|
+
includePublicEvalCatalog?: boolean;
|
|
54
|
+
clientHarness?: ClientHarness;
|
|
55
|
+
};
|
|
56
|
+
export type ProviderCredentialRequest = {
|
|
57
|
+
provider: Provider;
|
|
58
|
+
model: string;
|
|
59
|
+
routerId: string;
|
|
60
|
+
organizationId: string;
|
|
61
|
+
apiKey: string;
|
|
62
|
+
};
|
|
63
|
+
export type PrefixStateWrite = {
|
|
64
|
+
organization_id: string;
|
|
65
|
+
router_id: string;
|
|
66
|
+
received_at: string;
|
|
67
|
+
zdr: boolean;
|
|
68
|
+
prefix_entry: Record<string, unknown> | null;
|
|
69
|
+
touched_prefix_hash: string | null;
|
|
70
|
+
};
|
|
71
|
+
export type PendingLeaseWrite = {
|
|
72
|
+
router_id: string;
|
|
73
|
+
conversation_id: string;
|
|
74
|
+
decided_at_depth: number;
|
|
75
|
+
pending_lease: {
|
|
76
|
+
model: string;
|
|
77
|
+
reasoning_effort: string;
|
|
78
|
+
turns: number;
|
|
79
|
+
reason: string;
|
|
80
|
+
output_text: string | null;
|
|
81
|
+
} | null;
|
|
82
|
+
};
|
|
83
|
+
export type SubscriptionHold = {
|
|
84
|
+
userId: string;
|
|
85
|
+
credentialId: string | undefined;
|
|
86
|
+
limit: SubscriptionUsageLimit;
|
|
87
|
+
};
|
|
88
|
+
export type RequestRecord = {
|
|
89
|
+
row: Record<string, unknown>;
|
|
90
|
+
summary: RequestSummary;
|
|
91
|
+
distinctId: string;
|
|
92
|
+
interaction: InteractionRequest;
|
|
93
|
+
isNewConversation: boolean;
|
|
94
|
+
zdr: boolean;
|
|
95
|
+
harnessConversationIdentity?: HarnessConversationIdentity;
|
|
96
|
+
tags: RequestTags;
|
|
97
|
+
};
|
|
98
|
+
export type RequestTags = Record<string, string>;
|
|
99
|
+
export type RequestSummary = {
|
|
100
|
+
request_id: string;
|
|
101
|
+
organization_id: string;
|
|
102
|
+
router_id: string;
|
|
103
|
+
api_key_id: string | null;
|
|
104
|
+
source_protocol: SourceProtocol;
|
|
105
|
+
request_kind: "user_message" | "tool_continuation" | "other";
|
|
106
|
+
status: "completed" | "provider_error" | "selector_error" | "aborted";
|
|
107
|
+
error_code: string | null;
|
|
108
|
+
stream: boolean;
|
|
109
|
+
zdr: boolean;
|
|
110
|
+
strategy: RoutingStrategy;
|
|
111
|
+
selected_model: string | null;
|
|
112
|
+
selected_provider: Provider | null;
|
|
113
|
+
selected_reasoning_effort: ReasoningEffort | null;
|
|
114
|
+
next_model: string | null;
|
|
115
|
+
next_reasoning_effort: ReasoningEffort | null;
|
|
116
|
+
fallback_model: string | null;
|
|
117
|
+
fallback_reasoning_effort: ReasoningEffort | null;
|
|
118
|
+
provider_key_source: ProviderKeySource | null;
|
|
119
|
+
message_count: number;
|
|
120
|
+
tool_count: number;
|
|
121
|
+
candidate_count: number;
|
|
122
|
+
provider_attempt_count: number;
|
|
123
|
+
prefix_match_depth: number | null;
|
|
124
|
+
prefix_warm_tokens: number | null;
|
|
125
|
+
selector_latency_ms: number | null;
|
|
126
|
+
provider_latency_ms: number | null;
|
|
127
|
+
total_latency_ms: number;
|
|
128
|
+
input_tokens: number | null;
|
|
129
|
+
cache_read_tokens: number | null;
|
|
130
|
+
cache_write_tokens: number | null;
|
|
131
|
+
output_tokens: number | null;
|
|
132
|
+
total_tokens: number | null;
|
|
133
|
+
total_cost_usd: number | null;
|
|
134
|
+
cost_source: "provider" | "pricing" | null;
|
|
135
|
+
pricing_known: boolean | null;
|
|
136
|
+
};
|
|
137
|
+
export type RequestErrorContext = {
|
|
138
|
+
request: Request;
|
|
139
|
+
routerId: string;
|
|
140
|
+
requestId?: string;
|
|
141
|
+
sourceProtocol: SourceProtocol | "openai_models" | "anthropic_models";
|
|
142
|
+
status: number;
|
|
143
|
+
};
|
|
144
|
+
export type OperationalErrorCode = "background_drain_timeout" | "billing_usage_report_failed" | "routing_report_assembly_failed" | "routing_report_barrier_failed" | "server_force_stop_failed" | "stream_report_finalization_failed" | "subscription_unavailable_ingest_failed";
|
|
145
|
+
export type OperationalErrorContext = {
|
|
146
|
+
code: OperationalErrorCode;
|
|
147
|
+
requestId?: string;
|
|
148
|
+
routerId?: string;
|
|
149
|
+
};
|
|
150
|
+
/** Bind the platform every request uses. The latest binding wins. */
|
|
151
|
+
export declare function bindGatewayPlatform(platform: GatewayPlatform): void;
|
|
152
|
+
export declare function gatewayPlatform(): GatewayPlatform;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let bound = null;
|
|
2
|
+
/** Bind the platform every request uses. The latest binding wins. */
|
|
3
|
+
export function bindGatewayPlatform(platform) {
|
|
4
|
+
bound = platform;
|
|
5
|
+
}
|
|
6
|
+
export function gatewayPlatform() {
|
|
7
|
+
if (bound === null) {
|
|
8
|
+
throw new Error("No gateway platform is bound; create the request handler first.");
|
|
9
|
+
}
|
|
10
|
+
return bound;
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Stable public identity for the standard /v1 router. Platforms resolve it
|
|
2
|
+
// to the caller's default router.
|
|
3
|
+
export const DEFAULT_ROUTER_ALIAS = "default";
|
|
4
|
+
// The most prefix hashes one router resolution looks up.
|
|
5
|
+
export const ROUTING_PREFIX_HASHES_MAX_COUNT = 200;
|