@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,11 +1,11 @@
|
|
|
1
1
|
import { isReasoningEffort, isRecord, type ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { HttpError } from "../../http/errors";
|
|
4
|
-
import { parseDataImageUrl } from "../../interaction/image";
|
|
5
|
-
import { decodeUntrustedProviderContinuationState } from "../../interaction/provider_continuation_state";
|
|
6
|
-
import { decodeUntrustedPortableReasoningState } from "../../interaction/portable_reasoning_state";
|
|
7
|
-
import { toolsByWireName } from "../../interaction/tool_identity";
|
|
8
|
-
import { explicitModelId, isAnthropicRouterModel, unsupportedModelMessage } from "./router_model";
|
|
3
|
+
import { HttpError } from "../../http/errors.js";
|
|
4
|
+
import { parseDataImageUrl } from "../../interaction/image.js";
|
|
5
|
+
import { decodeUntrustedProviderContinuationState } from "../../interaction/provider_continuation_state.js";
|
|
6
|
+
import { decodeUntrustedPortableReasoningState } from "../../interaction/portable_reasoning_state.js";
|
|
7
|
+
import { toolsByWireName } from "../../interaction/tool_identity.js";
|
|
8
|
+
import { explicitModelId, isAnthropicRouterModel, unsupportedModelMessage } from "./router_model.js";
|
|
9
9
|
import type {
|
|
10
10
|
ClientTool,
|
|
11
11
|
InteractionContent,
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
InteractionToolReference,
|
|
18
18
|
ReasoningControls,
|
|
19
19
|
ServerToolKind,
|
|
20
|
-
} from "../../interaction/types";
|
|
20
|
+
} from "../../interaction/types.js";
|
|
21
21
|
|
|
22
22
|
const SUPPORTED_SERVER_TOOL_TYPES: readonly ServerToolKind[] = [
|
|
23
23
|
"bash_20250124",
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type ResponseFormat,
|
|
6
6
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
7
7
|
|
|
8
|
-
import { HttpError } from "../../http/errors";
|
|
8
|
+
import { HttpError } from "../../http/errors.js";
|
|
9
9
|
import type {
|
|
10
10
|
InteractionContent,
|
|
11
11
|
InteractionItem,
|
|
@@ -14,10 +14,10 @@ import type {
|
|
|
14
14
|
InteractionResponseFormat,
|
|
15
15
|
InteractionTool,
|
|
16
16
|
InteractionToolChoice,
|
|
17
|
-
} from "../../interaction/types";
|
|
18
|
-
import { toolsByWireName } from "../../interaction/tool_identity";
|
|
19
|
-
import { decodeUntrustedProviderContinuationState } from "../../interaction/provider_continuation_state";
|
|
20
|
-
import { validateChatCompletionsRequest } from "./chat_completions_validation";
|
|
17
|
+
} from "../../interaction/types.js";
|
|
18
|
+
import { toolsByWireName } from "../../interaction/tool_identity.js";
|
|
19
|
+
import { decodeUntrustedProviderContinuationState } from "../../interaction/provider_continuation_state.js";
|
|
20
|
+
import { validateChatCompletionsRequest } from "./chat_completions_validation.js";
|
|
21
21
|
|
|
22
22
|
export function chatCompletionsToInteraction(request: ChatCompletionRequest): InteractionRequest {
|
|
23
23
|
validateChatCompletionsRequest(request);
|
|
@@ -80,7 +80,9 @@ export function internalChatCompletionsToInteraction(request: ChatCompletionRequ
|
|
|
80
80
|
const tools = chatTools(request.tools);
|
|
81
81
|
toolsByWireName(tools);
|
|
82
82
|
const responseFormat = toInteractionResponseFormat(request.response_format);
|
|
83
|
-
|
|
83
|
+
// OpenAI spells the non-reasoning effort "none"; Dari spells it "off".
|
|
84
|
+
const requestedEffort: string | undefined = request.reasoning_effort;
|
|
85
|
+
const reasoningEffort = requestedEffort === "none" ? "off" : request.reasoning_effort;
|
|
84
86
|
return {
|
|
85
87
|
sourceProtocol: request.source_protocol ?? "openai_chat",
|
|
86
88
|
model: request.model,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isReasoningEffort, isRecord, type ChatCompletionRequest } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { HttpError } from "../../http/errors";
|
|
4
|
-
import { parseDataImageUrl } from "../../interaction/image";
|
|
5
|
-
import { CANONICAL_ROUTER_MODEL, explicitModelId, unsupportedModelMessage } from "./router_model";
|
|
3
|
+
import { HttpError } from "../../http/errors.js";
|
|
4
|
+
import { parseDataImageUrl } from "../../interaction/image.js";
|
|
5
|
+
import { CANONICAL_ROUTER_MODEL, explicitModelId, unsupportedModelMessage } from "./router_model.js";
|
|
6
6
|
import {
|
|
7
7
|
isProtocolToolCallId,
|
|
8
8
|
TOOL_CALL_ID_MAX_LENGTH,
|
|
9
|
-
} from "../../interaction/tool_identity";
|
|
9
|
+
} from "../../interaction/tool_identity.js";
|
|
10
10
|
|
|
11
11
|
export function validateChatCompletionsRequest(request: ChatCompletionRequest): void {
|
|
12
12
|
if (request.model !== CANONICAL_ROUTER_MODEL && explicitModelId(request.model) === null) {
|
|
@@ -214,7 +214,8 @@ function validateReasoning(request: ChatCompletionRequest): void {
|
|
|
214
214
|
"reasoning"
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
const effort: unknown = request.reasoning_effort;
|
|
218
|
+
if (effort !== undefined && effort !== "none" && !isReasoningEffort(effort)) {
|
|
218
219
|
throw new HttpError(
|
|
219
220
|
400,
|
|
220
221
|
"reasoning_effort is not supported.",
|
|
@@ -2,15 +2,15 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
|
|
3
3
|
import { isReasoningEffort, isRecord, type ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
|
|
4
4
|
|
|
5
|
-
import { HttpError } from "../../http/errors";
|
|
6
|
-
import { parseDataImageUrl } from "../../interaction/image";
|
|
7
|
-
import { decodeUntrustedProviderContinuationState } from "../../interaction/provider_continuation_state";
|
|
8
|
-
import { CANONICAL_ROUTER_MODEL, explicitModelId, unsupportedModelMessage } from "./router_model";
|
|
5
|
+
import { HttpError } from "../../http/errors.js";
|
|
6
|
+
import { parseDataImageUrl } from "../../interaction/image.js";
|
|
7
|
+
import { decodeUntrustedProviderContinuationState } from "../../interaction/provider_continuation_state.js";
|
|
8
|
+
import { CANONICAL_ROUTER_MODEL, explicitModelId, unsupportedModelMessage } from "./router_model.js";
|
|
9
9
|
import {
|
|
10
10
|
isProtocolToolCallId,
|
|
11
11
|
TOOL_CALL_ID_MAX_LENGTH,
|
|
12
12
|
toolsByWireName,
|
|
13
|
-
} from "../../interaction/tool_identity";
|
|
13
|
+
} from "../../interaction/tool_identity.js";
|
|
14
14
|
import type {
|
|
15
15
|
InteractionContent,
|
|
16
16
|
InteractionItem,
|
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
InteractionTool,
|
|
21
21
|
InteractionToolChoice,
|
|
22
22
|
ToolKind,
|
|
23
|
-
} from "../../interaction/types";
|
|
23
|
+
} from "../../interaction/types.js";
|
|
24
24
|
|
|
25
25
|
const UNSUPPORTED_INPUT_ITEM_TYPES = new Set([
|
|
26
26
|
"additional_tools",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import type { InteractionOutput, InteractionRequest } from "../../interaction/types";
|
|
3
|
+
import type { InteractionOutput, InteractionRequest } from "../../interaction/types.js";
|
|
4
4
|
import {
|
|
5
5
|
anthropicContent,
|
|
6
6
|
anthropicMessageId,
|
|
7
7
|
anthropicRouting,
|
|
8
8
|
anthropicStopReason,
|
|
9
9
|
anthropicUsage,
|
|
10
|
-
} from "./anthropic_messages_output";
|
|
10
|
+
} from "./anthropic_messages_output.js";
|
|
11
11
|
|
|
12
12
|
export function anthropicMessagesResponse(args: {
|
|
13
13
|
id: string;
|
|
@@ -27,6 +27,6 @@ export function anthropicMessagesResponse(args: {
|
|
|
27
27
|
stop_sequence: null,
|
|
28
28
|
usage: anthropicUsage(args.output),
|
|
29
29
|
...(args.output.safeguardResults ? { safeguard_results: args.output.safeguardResults } : {}),
|
|
30
|
-
dari_routing: anthropicRouting(args.routing, args.conversationId),
|
|
30
|
+
dari_routing: anthropicRouting(args.routing, args.id, args.conversationId),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { parseDataImageUrl } from "../../interaction/image";
|
|
2
|
-
import { encodeProviderContinuationState } from "../../interaction/provider_continuation_state";
|
|
3
|
-
import { encodePortableReasoningState } from "../../interaction/portable_reasoning_state";
|
|
4
|
-
import type { InteractionOutput } from "../../interaction/types";
|
|
1
|
+
import { parseDataImageUrl } from "../../interaction/image.js";
|
|
2
|
+
import { encodeProviderContinuationState } from "../../interaction/provider_continuation_state.js";
|
|
3
|
+
import { encodePortableReasoningState } from "../../interaction/portable_reasoning_state.js";
|
|
4
|
+
import type { InteractionOutput } from "../../interaction/types.js";
|
|
5
5
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
6
6
|
|
|
7
7
|
export function anthropicMessageId(requestId: string): string {
|
|
@@ -100,6 +100,7 @@ export function anthropicUsage(output: Pick<InteractionOutput, "usage">): Record
|
|
|
100
100
|
|
|
101
101
|
export function anthropicRouting(
|
|
102
102
|
decision: RoutingDecision,
|
|
103
|
+
requestId: string,
|
|
103
104
|
conversationId?: string
|
|
104
105
|
): Record<string, unknown> {
|
|
105
106
|
return {
|
|
@@ -107,6 +108,7 @@ export function anthropicRouting(
|
|
|
107
108
|
selected_model: decision.selectedModel,
|
|
108
109
|
reasoning_effort: decision.reasoningEffort,
|
|
109
110
|
reason: decision.reason,
|
|
111
|
+
request_id: requestId,
|
|
110
112
|
...(conversationId ? { conversation_id: conversationId } : {}),
|
|
111
113
|
...(decision.leaseTurnsRemaining === undefined
|
|
112
114
|
? {}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { piMessageToInteractionOutput } from "../../providers/pi_output";
|
|
2
|
-
import { providerToolCallIdentity } from "../../interaction/tool_identity";
|
|
3
|
-
import type { InteractionOutput, InteractionRequest, ProviderIdentity } from "../../interaction/types";
|
|
1
|
+
import { piMessageToInteractionOutput } from "../../providers/pi_output.js";
|
|
2
|
+
import { providerToolCallIdentity } from "../../interaction/tool_identity.js";
|
|
3
|
+
import type { InteractionOutput, InteractionRequest, ProviderIdentity } from "../../interaction/types.js";
|
|
4
4
|
import {
|
|
5
5
|
isProviderFailureMessage,
|
|
6
6
|
providerFailureFromEvent,
|
|
7
7
|
providerFailureMessage,
|
|
8
8
|
type ProviderStreamOutcome,
|
|
9
|
-
} from "../../runtime/provider_stream_outcome";
|
|
10
|
-
import { sseStream } from "./sse_stream";
|
|
9
|
+
} from "../../runtime/provider_stream_outcome.js";
|
|
10
|
+
import { sseStream } from "./sse_stream.js";
|
|
11
11
|
import {
|
|
12
12
|
anthropicMessageId,
|
|
13
13
|
anthropicReasoningBlock,
|
|
14
14
|
anthropicRouting,
|
|
15
15
|
anthropicStopReason,
|
|
16
16
|
anthropicUsage,
|
|
17
|
-
} from "./anthropic_messages_output";
|
|
17
|
+
} from "./anthropic_messages_output.js";
|
|
18
18
|
|
|
19
19
|
export function anthropicMessagesSseStream(args: {
|
|
20
20
|
id: string;
|
|
@@ -58,7 +58,7 @@ export function anthropicMessagesSseStream(args: {
|
|
|
58
58
|
stop_reason: null,
|
|
59
59
|
stop_sequence: null,
|
|
60
60
|
usage: { input_tokens: 0, output_tokens: 0 },
|
|
61
|
-
dari_routing: anthropicRouting(args.routing, args.conversationId),
|
|
61
|
+
dari_routing: anthropicRouting(args.routing, args.id, args.conversationId),
|
|
62
62
|
},
|
|
63
63
|
});
|
|
64
64
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { isRecord, type ChatMessage, type RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import { piMessageToInteractionOutput } from "../../providers/pi_output";
|
|
4
|
-
import { providerToolCallIdentity } from "../../interaction/tool_identity";
|
|
5
|
-
import { encodeProviderContinuationState } from "../../interaction/provider_continuation_state";
|
|
6
|
-
import { chatReasoningDetailId } from "./chat_reasoning_detail";
|
|
7
|
-
import type { InteractionOutput, InteractionRequest, ProviderContinuationState, ProviderIdentity } from "../../interaction/types";
|
|
3
|
+
import { piMessageToInteractionOutput } from "../../providers/pi_output.js";
|
|
4
|
+
import { providerToolCallIdentity } from "../../interaction/tool_identity.js";
|
|
5
|
+
import { encodeProviderContinuationState } from "../../interaction/provider_continuation_state.js";
|
|
6
|
+
import { chatReasoningDetailId } from "./chat_reasoning_detail.js";
|
|
7
|
+
import type { InteractionOutput, InteractionRequest, ProviderContinuationState, ProviderIdentity } from "../../interaction/types.js";
|
|
8
8
|
import {
|
|
9
9
|
isProviderFailureMessage,
|
|
10
10
|
providerFailureFromEvent,
|
|
11
11
|
providerFailureMessage,
|
|
12
12
|
type ProviderStreamOutcome,
|
|
13
|
-
} from "../../runtime/provider_stream_outcome";
|
|
14
|
-
import { sseStream } from "./sse_stream";
|
|
13
|
+
} from "../../runtime/provider_stream_outcome.js";
|
|
14
|
+
import { sseStream } from "./sse_stream.js";
|
|
15
15
|
|
|
16
16
|
export function chatCompletionResponse(args: {
|
|
17
17
|
id: string;
|
|
@@ -34,7 +34,7 @@ export function chatCompletionResponse(args: {
|
|
|
34
34
|
},
|
|
35
35
|
],
|
|
36
36
|
usage: usagePayload(args.output, args.modelCost),
|
|
37
|
-
dari_routing: routingPayload(args.routing, args.conversationId),
|
|
37
|
+
dari_routing: routingPayload(args.routing, args.id, args.conversationId),
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -75,7 +75,7 @@ export function chatCompletionsSseStream(args: {
|
|
|
75
75
|
usage: usagePayload(message, args.modelCost?.(message, true)) });
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
send(chunk({ completion, created, model: args.model, delta: {}, finishReason: null, routing: args.routing,
|
|
78
|
+
send(chunk({ completion, created, model: args.model, delta: {}, finishReason: null, routing: routingPayload(args.routing, args.id, args.conversationId) }));
|
|
79
79
|
send(chunk({ completion, created, model: args.model, delta: { role: "assistant" }, finishReason: null }));
|
|
80
80
|
|
|
81
81
|
const argumentDeltaSeen = new Set<string>();
|
|
@@ -208,12 +208,13 @@ export function chatCompletionsSseStream(args: {
|
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
function routingPayload(decision: RoutingDecision, conversationId?: string): Record<string, unknown> {
|
|
211
|
+
function routingPayload(decision: RoutingDecision, requestId: string, conversationId?: string): Record<string, unknown> {
|
|
212
212
|
return {
|
|
213
213
|
requested_model: "dari/routing",
|
|
214
214
|
selected_model: decision.selectedModel,
|
|
215
215
|
reasoning_effort: decision.reasoningEffort,
|
|
216
216
|
reason: decision.reason,
|
|
217
|
+
request_id: requestId,
|
|
217
218
|
...(conversationId ? { conversation_id: conversationId } : {}),
|
|
218
219
|
};
|
|
219
220
|
}
|
|
@@ -224,9 +225,8 @@ function chunk(args: {
|
|
|
224
225
|
model: string;
|
|
225
226
|
delta: Record<string, unknown>;
|
|
226
227
|
finishReason: string | null;
|
|
227
|
-
routing?:
|
|
228
|
+
routing?: Record<string, unknown>;
|
|
228
229
|
usage?: Record<string, unknown>;
|
|
229
|
-
conversationId?: string;
|
|
230
230
|
}): Record<string, unknown> {
|
|
231
231
|
return {
|
|
232
232
|
id: args.completion,
|
|
@@ -234,7 +234,7 @@ function chunk(args: {
|
|
|
234
234
|
created: args.created,
|
|
235
235
|
model: args.model,
|
|
236
236
|
choices: [{ index: 0, delta: args.delta, finish_reason: args.finishReason }],
|
|
237
|
-
...(args.routing ? { dari_routing:
|
|
237
|
+
...(args.routing ? { dari_routing: args.routing } : {}),
|
|
238
238
|
...(args.usage ? { usage: args.usage } : {}),
|
|
239
239
|
};
|
|
240
240
|
}
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
openAIResponsesRouting,
|
|
5
5
|
openAIResponsesTerminal,
|
|
6
6
|
openAIResponsesUsage,
|
|
7
|
-
} from "./openai_responses_output";
|
|
8
|
-
import type { InteractionOutput, InteractionRequest } from "../../interaction/types";
|
|
7
|
+
} from "./openai_responses_output.js";
|
|
8
|
+
import type { InteractionOutput, InteractionRequest } from "../../interaction/types.js";
|
|
9
9
|
|
|
10
10
|
export function openAIResponsesResponse(args: {
|
|
11
11
|
id: string;
|
|
@@ -24,7 +24,7 @@ export function openAIResponsesResponse(args: {
|
|
|
24
24
|
output: openAIResponsesOutputItems(args.output),
|
|
25
25
|
usage: openAIResponsesUsage(args.output),
|
|
26
26
|
parallel_tool_calls: args.request.parallelToolCalls ?? true,
|
|
27
|
-
dari_routing: openAIResponsesRouting(args.routing, args.conversationId),
|
|
27
|
+
dari_routing: openAIResponsesRouting(args.routing, args.id, args.conversationId),
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { encodeProviderContinuationState } from "../../interaction/provider_continuation_state";
|
|
2
|
-
import type { InteractionOutput } from "../../interaction/types";
|
|
1
|
+
import { encodeProviderContinuationState } from "../../interaction/provider_continuation_state.js";
|
|
2
|
+
import type { InteractionOutput } from "../../interaction/types.js";
|
|
3
3
|
|
|
4
4
|
export function openAIResponsesResponseId(requestId: string): string {
|
|
5
5
|
return `resp_${requestId}`;
|
|
@@ -44,6 +44,7 @@ export function openAIResponsesUsage(output: Pick<InteractionOutput, "usage">):
|
|
|
44
44
|
|
|
45
45
|
export function openAIResponsesRouting(
|
|
46
46
|
decision: RoutingDecision,
|
|
47
|
+
requestId: string,
|
|
47
48
|
conversationId?: string
|
|
48
49
|
): Record<string, unknown> {
|
|
49
50
|
return {
|
|
@@ -51,6 +52,7 @@ export function openAIResponsesRouting(
|
|
|
51
52
|
selected_model: decision.selectedModel,
|
|
52
53
|
reasoning_effort: decision.reasoningEffort,
|
|
53
54
|
reason: decision.reason,
|
|
55
|
+
request_id: requestId,
|
|
54
56
|
...(conversationId ? { conversation_id: conversationId } : {}),
|
|
55
57
|
};
|
|
56
58
|
}
|
|
@@ -5,21 +5,21 @@ import {
|
|
|
5
5
|
openAIResponsesRouting,
|
|
6
6
|
openAIResponsesTerminal,
|
|
7
7
|
openAIResponsesUsage,
|
|
8
|
-
} from "./openai_responses_output";
|
|
9
|
-
import { piMessageToInteractionOutput } from "../../providers/pi_output";
|
|
8
|
+
} from "./openai_responses_output.js";
|
|
9
|
+
import { piMessageToInteractionOutput } from "../../providers/pi_output.js";
|
|
10
10
|
import type {
|
|
11
11
|
InteractionOutput,
|
|
12
12
|
InteractionOutputItem,
|
|
13
13
|
InteractionRequest,
|
|
14
14
|
ProviderIdentity,
|
|
15
|
-
} from "../../interaction/types";
|
|
15
|
+
} from "../../interaction/types.js";
|
|
16
16
|
import {
|
|
17
17
|
isProviderFailureMessage,
|
|
18
18
|
providerFailureFromEvent,
|
|
19
19
|
providerFailureMessage,
|
|
20
20
|
type ProviderStreamOutcome,
|
|
21
|
-
} from "../../runtime/provider_stream_outcome";
|
|
22
|
-
import { sseStream } from "./sse_stream";
|
|
21
|
+
} from "../../runtime/provider_stream_outcome.js";
|
|
22
|
+
import { sseStream } from "./sse_stream.js";
|
|
23
23
|
|
|
24
24
|
type StreamArgs = {
|
|
25
25
|
id: string;
|
|
@@ -600,7 +600,7 @@ function responseEnvelope(
|
|
|
600
600
|
output,
|
|
601
601
|
parallel_tool_calls: args.request.parallelToolCalls ?? true,
|
|
602
602
|
...(interaction ? { usage: openAIResponsesUsage(interaction) } : {}),
|
|
603
|
-
dari_routing: openAIResponsesRouting(args.routing, args.conversationId),
|
|
603
|
+
dari_routing: openAIResponsesRouting(args.routing, args.id, args.conversationId),
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
606
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ProviderStreamLifecycle } from "../../runtime/provider_stream_lifecycle";
|
|
1
|
+
import { ProviderStreamLifecycle } from "../../runtime/provider_stream_lifecycle.js";
|
|
2
2
|
import {
|
|
3
3
|
providerFailure,
|
|
4
4
|
providerFailureFromCaught,
|
|
5
5
|
providerFailureFromTerminal,
|
|
6
6
|
type ProviderStreamOutcome,
|
|
7
|
-
} from "../../runtime/provider_stream_outcome";
|
|
8
|
-
import { DeliveredStreamSnapshot } from "./delivered_stream_snapshot";
|
|
7
|
+
} from "../../runtime/provider_stream_outcome.js";
|
|
8
|
+
import { DeliveredStreamSnapshot } from "./delivered_stream_snapshot.js";
|
|
9
9
|
|
|
10
10
|
export type SseStreamLifecycleArgs = {
|
|
11
11
|
onFinal?: (outcome: ProviderStreamOutcome) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
2
|
|
|
3
|
-
import type { AnthropicSafeguards, InteractionRequest } from "../interaction/types";
|
|
4
|
-
import type { ProviderFetch } from "./response_capture";
|
|
3
|
+
import type { AnthropicSafeguards, InteractionRequest } from "../interaction/types.js";
|
|
4
|
+
import type { ProviderFetch } from "./response_capture.js";
|
|
5
5
|
|
|
6
6
|
// Claude Code's auto mode asks the Anthropic API to run its dangerous-tool-use
|
|
7
7
|
// classifier server-side, at no charge, by sending `safeguards` with a paired
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts";
|
|
2
2
|
|
|
3
|
-
import { HttpError } from "../http/errors";
|
|
3
|
+
import { HttpError } from "../http/errors.js";
|
|
4
4
|
import type {
|
|
5
5
|
AwsAssumeRoleProviderAuth,
|
|
6
6
|
AwsSigV4ProviderAuth,
|
|
7
7
|
ProviderAuth,
|
|
8
8
|
ResolvedProviderAuth,
|
|
9
|
-
} from "../types";
|
|
9
|
+
} from "../types.js";
|
|
10
10
|
|
|
11
11
|
const ROLE_SESSION_NAME = "dari-routing";
|
|
12
12
|
// AssumeRole always goes through this regional STS endpoint. The customer's
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
InteractionOutput,
|
|
9
9
|
InteractionUsage,
|
|
10
10
|
ProviderIdentity,
|
|
11
|
-
} from "../interaction/types";
|
|
11
|
+
} from "../interaction/types.js";
|
|
12
12
|
|
|
13
13
|
/** Prose from current models averages about 4.8 characters per token. */
|
|
14
14
|
export const ESTIMATED_CHARS_PER_TOKEN = 4.8;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
-
import { HttpError } from "../http/errors";
|
|
3
|
-
import { piMessageToInteractionOutput } from "./pi_output";
|
|
4
|
-
import type { InteractionRequest } from "../interaction/types";
|
|
5
|
-
import { captureOperationalError } from "../observability/errors";
|
|
2
|
+
import { HttpError } from "../http/errors.js";
|
|
3
|
+
import { piMessageToInteractionOutput } from "./pi_output.js";
|
|
4
|
+
import type { InteractionRequest } from "../interaction/types.js";
|
|
5
|
+
import { captureOperationalError } from "../observability/errors.js";
|
|
6
6
|
import {
|
|
7
7
|
CustomerDisconnectedError,
|
|
8
8
|
customerCanceledProviderMessage,
|
|
9
|
-
} from "../runtime/customer_disconnect";
|
|
9
|
+
} from "../runtime/customer_disconnect.js";
|
|
10
10
|
import {
|
|
11
11
|
isProviderFailureMessage,
|
|
12
12
|
providerFailureFromCaught,
|
|
13
13
|
providerFailureFromTerminal,
|
|
14
14
|
providerFailureMessage,
|
|
15
|
-
} from "../runtime/provider_stream_outcome";
|
|
15
|
+
} from "../runtime/provider_stream_outcome.js";
|
|
16
16
|
import {
|
|
17
17
|
reportedExecution,
|
|
18
18
|
type ReportableProviderOutcome,
|
|
19
19
|
type RoutedRuntimeReporter,
|
|
20
|
-
} from "../runtime/runtime_reporter";
|
|
21
|
-
import type { RoutedProtocol } from "../runtime/routed_protocol";
|
|
22
|
-
import { trackBackgroundTelemetry } from "../telemetry/background";
|
|
23
|
-
import { gatewayPlatform, type SubscriptionHold } from "../platform/platform";
|
|
24
|
-
import { reportRoutingUsage } from "../telemetry/usage";
|
|
20
|
+
} from "../runtime/runtime_reporter.js";
|
|
21
|
+
import type { RoutedProtocol } from "../runtime/routed_protocol.js";
|
|
22
|
+
import { trackBackgroundTelemetry } from "../telemetry/background.js";
|
|
23
|
+
import { gatewayPlatform, type SubscriptionHold } from "../platform/platform.js";
|
|
24
|
+
import { reportRoutingUsage } from "../telemetry/usage.js";
|
|
25
25
|
import {
|
|
26
26
|
prepareProviderExecution,
|
|
27
27
|
primeProviderStream,
|
|
@@ -32,20 +32,20 @@ import {
|
|
|
32
32
|
type ProviderExecution,
|
|
33
33
|
type StartedCompletion,
|
|
34
34
|
type StartedStream,
|
|
35
|
-
} from "./provider_call";
|
|
35
|
+
} from "./provider_call.js";
|
|
36
36
|
import {
|
|
37
37
|
runProviderAttemptPlan,
|
|
38
38
|
type ProviderAttemptFailure,
|
|
39
39
|
type ProviderAttemptPlanResult,
|
|
40
40
|
type ProviderAttemptResult,
|
|
41
|
-
} from "./provider_attempt_runner";
|
|
41
|
+
} from "./provider_attempt_runner.js";
|
|
42
42
|
import {
|
|
43
43
|
estimatedCancelUsage,
|
|
44
44
|
NO_DELIVERED_OUTPUT,
|
|
45
45
|
observeDeliveredOutput,
|
|
46
|
-
} from "./cancel_estimate";
|
|
47
|
-
import { providerResponseCaptureFromError, type ProviderResponseCapture } from "./response_capture";
|
|
48
|
-
import { createStreamFinalizer } from "./stream_finalization";
|
|
46
|
+
} from "./cancel_estimate.js";
|
|
47
|
+
import { providerResponseCaptureFromError, type ProviderResponseCapture } from "./response_capture.js";
|
|
48
|
+
import { createStreamFinalizer } from "./stream_finalization.js";
|
|
49
49
|
import {
|
|
50
50
|
detectSubscriptionUsageLimit,
|
|
51
51
|
failureWithSubscriptionUsageLimit,
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
subscriptionUsageLimitFromFailure,
|
|
54
54
|
subscriptionSwitchedMessage,
|
|
55
55
|
subscriptionUsageLimitMessage,
|
|
56
|
-
} from "./subscription_limits";
|
|
56
|
+
} from "./subscription_limits.js";
|
|
57
57
|
|
|
58
58
|
export type ProviderChoice = {
|
|
59
59
|
decision: RoutingDecision;
|
package/src/providers/pi.ts
CHANGED
|
@@ -26,35 +26,41 @@ import {
|
|
|
26
26
|
type ReasoningEffort,
|
|
27
27
|
type RouterModelPrice,
|
|
28
28
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
29
|
-
import { HttpError } from "../http/errors";
|
|
30
|
-
import { effectiveContextWindow } from "../models/context_limits";
|
|
31
|
-
import { defaultBaseUrl } from "../models/provider_defaults";
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
import { HttpError } from "../http/errors.js";
|
|
30
|
+
import { effectiveContextWindow } from "../models/context_limits.js";
|
|
31
|
+
import { defaultBaseUrl } from "../models/provider_defaults.js";
|
|
32
|
+
import {
|
|
33
|
+
contextWindowOverride,
|
|
34
|
+
inputModalitiesOverride,
|
|
35
|
+
providerThinkingLevelOverrides,
|
|
36
|
+
runtimeCompat,
|
|
37
|
+
withThinkingLevelOverrides,
|
|
38
|
+
} from "../models/runtime_overrides.js";
|
|
39
|
+
import { BEDROCK_API } from "./model_capabilities.js";
|
|
40
|
+
import { buildContext } from "./pi_context.js";
|
|
41
|
+
import { providerIdentityFromModel } from "../interaction/provider_continuation_state.js";
|
|
42
|
+
import { buildOptions, supportedThinkingLevels } from "./pi_options.js";
|
|
43
|
+
import type { ProviderFetch } from "./response_capture.js";
|
|
38
44
|
import {
|
|
39
45
|
eventsWithSafeguardResults,
|
|
40
46
|
forwardsAnthropicSafeguards,
|
|
41
47
|
messageWithSafeguardResults,
|
|
42
48
|
safeguardResultsTap,
|
|
43
|
-
} from "./anthropic_safeguards";
|
|
49
|
+
} from "./anthropic_safeguards.js";
|
|
44
50
|
import {
|
|
45
51
|
eventsWithProviderReportedCost,
|
|
46
52
|
messageWithProviderReportedCost,
|
|
47
53
|
providerReportedCostTap,
|
|
48
54
|
reportsProviderCost,
|
|
49
|
-
} from "./provider_reported_cost";
|
|
55
|
+
} from "./provider_reported_cost.js";
|
|
50
56
|
import {
|
|
51
57
|
eventsWithSubscriptionCacheWrites,
|
|
52
58
|
messageWithSubscriptionCacheWrites,
|
|
53
59
|
modelPricingFromPiModel,
|
|
54
60
|
type SubscriptionUsageContext,
|
|
55
|
-
} from "./subscription_usage";
|
|
56
|
-
import type { InteractionRequest, ProviderIdentity } from "../interaction/types";
|
|
57
|
-
import type { ResolvedProviderAuth, ResolvedRouterModelConfig } from "../types";
|
|
61
|
+
} from "./subscription_usage.js";
|
|
62
|
+
import type { InteractionRequest, ProviderIdentity } from "../interaction/types.js";
|
|
63
|
+
import type { ResolvedProviderAuth, ResolvedRouterModelConfig } from "../types.js";
|
|
58
64
|
|
|
59
65
|
type PiAi = {
|
|
60
66
|
completeSimple: (model: Record<string, unknown>, context: Record<string, unknown>, options: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
@@ -335,16 +341,21 @@ export function buildModel(
|
|
|
335
341
|
// A null catalog value delegates to Pi's registry when it knows the model.
|
|
336
342
|
// Custom OpenAI-compatible models are not necessarily registered, so keep
|
|
337
343
|
// the public effort set permissive and let the provider validate the wire
|
|
338
|
-
// value instead of silently treating an unknown model as off-only.
|
|
344
|
+
// value instead of silently treating an unknown model as off-only. A
|
|
345
|
+
// built-in provider with its own thinking levels (Meta) serves ids newer
|
|
346
|
+
// than the registry the same way, with only its key configured.
|
|
347
|
+
const providerThinking = providerThinkingLevelOverrides(provider);
|
|
339
348
|
const fallbackThinkingLevels =
|
|
340
|
-
config !== undefined
|
|
349
|
+
(config !== undefined || providerThinking !== undefined) &&
|
|
350
|
+
configuredThinkingLevels == null &&
|
|
351
|
+
registered === undefined
|
|
341
352
|
? REASONING_EFFORTS
|
|
342
353
|
: undefined;
|
|
343
354
|
const effectiveThinkingLevels = Array.isArray(configuredThinkingLevels)
|
|
344
355
|
? configuredThinkingLevels
|
|
345
356
|
: fallbackThinkingLevels;
|
|
346
357
|
const configuredThinking = effectiveThinkingLevels
|
|
347
|
-
? thinkingMetadata(effectiveThinkingLevels, registered)
|
|
358
|
+
? thinkingMetadata(effectiveThinkingLevels, registered ?? { thinkingLevelMap: providerThinking })
|
|
348
359
|
: null;
|
|
349
360
|
const defaultThinkingLevel = config?.default_thinking_level ?? undefined;
|
|
350
361
|
const api = config?.api ?? registered?.api ?? defaultApi(provider);
|
|
@@ -415,7 +426,10 @@ function resolveModelMetadata(
|
|
|
415
426
|
nativeId: string
|
|
416
427
|
): Record<string, unknown> | undefined {
|
|
417
428
|
const registry = registryProvider(provider, modelId);
|
|
418
|
-
return
|
|
429
|
+
return withThinkingLevelOverrides(
|
|
430
|
+
provider,
|
|
431
|
+
pi.getModel?.(registry, nativeId) ?? pi.getModel?.(registry, modelId),
|
|
432
|
+
);
|
|
419
433
|
}
|
|
420
434
|
|
|
421
435
|
// Dari's "azure" provider has no Pi registry of its own. One Foundry resource
|
|
@@ -491,7 +505,8 @@ function executionPricing(
|
|
|
491
505
|
}
|
|
492
506
|
|
|
493
507
|
function defaultApi(provider: string): string {
|
|
494
|
-
|
|
508
|
+
// Meta recommends Responses: its Chat Completions drops reasoning between turns.
|
|
509
|
+
if (provider === "openai" || provider === "xai" || provider === "meta") return "openai-responses";
|
|
495
510
|
if (provider === "anthropic") return "anthropic-messages";
|
|
496
511
|
if (provider === "amazon-bedrock") return BEDROCK_API;
|
|
497
512
|
if (provider === "azure") return "azure-openai-responses";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encodeOpenAIReasoningSignature } from "@mupt-ai/dari-router/protocols";
|
|
2
2
|
import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
3
3
|
|
|
4
|
-
import { HttpError } from "../http/errors";
|
|
4
|
+
import { HttpError } from "../http/errors.js";
|
|
5
5
|
import type {
|
|
6
6
|
InteractionContent,
|
|
7
7
|
InteractionItem,
|
|
@@ -9,14 +9,14 @@ import type {
|
|
|
9
9
|
InteractionTool,
|
|
10
10
|
ProviderContinuationState,
|
|
11
11
|
ProviderIdentity,
|
|
12
|
-
} from "../interaction/types";
|
|
13
|
-
import { parseDataImageUrl } from "../interaction/image";
|
|
14
|
-
import { providerToolCallId, toolWireName } from "../interaction/tool_identity";
|
|
12
|
+
} from "../interaction/types.js";
|
|
13
|
+
import { parseDataImageUrl } from "../interaction/image.js";
|
|
14
|
+
import { providerToolCallId, toolWireName } from "../interaction/tool_identity.js";
|
|
15
15
|
import {
|
|
16
16
|
compatibleProviderContinuation,
|
|
17
17
|
sameProviderIdentity,
|
|
18
|
-
} from "../interaction/provider_continuation_state";
|
|
19
|
-
import { isOpenAIResponsesApi } from "./model_capabilities";
|
|
18
|
+
} from "../interaction/provider_continuation_state.js";
|
|
19
|
+
import { isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
20
20
|
|
|
21
21
|
const UNKNOWN_SOURCE: ProviderIdentity = {
|
|
22
22
|
provider: "dari",
|