@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
package/src/providers/pi.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSupportedThinkingLevels,
|
|
3
|
+
normalizeContext,
|
|
4
|
+
type Api,
|
|
5
|
+
type AssistantMessageEventStream,
|
|
6
|
+
type Context,
|
|
7
|
+
type Model,
|
|
8
|
+
type ProviderStreams,
|
|
9
|
+
} from "@mupt-ai/pi-ai";
|
|
10
|
+
import { anthropicMessagesApi } from "@mupt-ai/pi-ai/api/anthropic-messages.lazy";
|
|
11
|
+
import { azureOpenAIResponsesApi } from "@mupt-ai/pi-ai/api/azure-openai-responses.lazy";
|
|
12
|
+
import { bedrockConverseStreamApi } from "@mupt-ai/pi-ai/api/bedrock-converse-stream.lazy";
|
|
13
|
+
import { googleGenerativeAIApi } from "@mupt-ai/pi-ai/api/google-generative-ai.lazy";
|
|
14
|
+
import { googleVertexApi } from "@mupt-ai/pi-ai/api/google-vertex.lazy";
|
|
15
|
+
import { mistralConversationsApi } from "@mupt-ai/pi-ai/api/mistral-conversations.lazy";
|
|
16
|
+
import { openAICodexResponsesApi } from "@mupt-ai/pi-ai/api/openai-codex-responses.lazy";
|
|
17
|
+
import { openAICompletionsApi } from "@mupt-ai/pi-ai/api/openai-completions.lazy";
|
|
18
|
+
import { openAIResponsesApi } from "@mupt-ai/pi-ai/api/openai-responses.lazy";
|
|
19
|
+
import { getBuiltinModel } from "@mupt-ai/pi-ai/providers/all";
|
|
1
20
|
import {
|
|
2
21
|
REASONING_EFFORTS,
|
|
3
22
|
isRecord,
|
|
@@ -7,29 +26,35 @@ import {
|
|
|
7
26
|
type ReasoningEffort,
|
|
8
27
|
type RouterModelPrice,
|
|
9
28
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
10
|
-
import { HttpError } from "../http/errors";
|
|
11
|
-
import { effectiveContextWindow } from "../models/context_limits";
|
|
12
|
-
import { defaultBaseUrl } from "../models/provider_defaults";
|
|
13
|
-
import { contextWindowOverride, inputModalitiesOverride, runtimeCompat } from "../models/runtime_overrides";
|
|
14
|
-
import { BEDROCK_API } from "./model_capabilities";
|
|
15
|
-
import { buildContext } from "./pi_context";
|
|
16
|
-
import { providerIdentityFromModel } from "../interaction/provider_continuation_state";
|
|
17
|
-
import { buildOptions, supportedThinkingLevels } from "./pi_options";
|
|
18
|
-
import type { ProviderFetch } from "./response_capture";
|
|
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 { contextWindowOverride, inputModalitiesOverride, runtimeCompat } from "../models/runtime_overrides.js";
|
|
33
|
+
import { BEDROCK_API } from "./model_capabilities.js";
|
|
34
|
+
import { buildContext } from "./pi_context.js";
|
|
35
|
+
import { providerIdentityFromModel } from "../interaction/provider_continuation_state.js";
|
|
36
|
+
import { buildOptions, supportedThinkingLevels } from "./pi_options.js";
|
|
37
|
+
import type { ProviderFetch } from "./response_capture.js";
|
|
19
38
|
import {
|
|
20
39
|
eventsWithSafeguardResults,
|
|
21
40
|
forwardsAnthropicSafeguards,
|
|
22
41
|
messageWithSafeguardResults,
|
|
23
42
|
safeguardResultsTap,
|
|
24
|
-
} from "./anthropic_safeguards";
|
|
43
|
+
} from "./anthropic_safeguards.js";
|
|
44
|
+
import {
|
|
45
|
+
eventsWithProviderReportedCost,
|
|
46
|
+
messageWithProviderReportedCost,
|
|
47
|
+
providerReportedCostTap,
|
|
48
|
+
reportsProviderCost,
|
|
49
|
+
} from "./provider_reported_cost.js";
|
|
25
50
|
import {
|
|
26
51
|
eventsWithSubscriptionCacheWrites,
|
|
27
52
|
messageWithSubscriptionCacheWrites,
|
|
28
53
|
modelPricingFromPiModel,
|
|
29
54
|
type SubscriptionUsageContext,
|
|
30
|
-
} from "./subscription_usage";
|
|
31
|
-
import type { InteractionRequest, ProviderIdentity } from "../interaction/types";
|
|
32
|
-
import type { ResolvedProviderAuth, ResolvedRouterModelConfig } from "../types";
|
|
55
|
+
} from "./subscription_usage.js";
|
|
56
|
+
import type { InteractionRequest, ProviderIdentity } from "../interaction/types.js";
|
|
57
|
+
import type { ResolvedProviderAuth, ResolvedRouterModelConfig } from "../types.js";
|
|
33
58
|
|
|
34
59
|
type PiAi = {
|
|
35
60
|
completeSimple: (model: Record<string, unknown>, context: Record<string, unknown>, options: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
@@ -43,6 +68,12 @@ export type ModelRuntimeMetadata = {
|
|
|
43
68
|
supportedThinkingLevels: string[];
|
|
44
69
|
};
|
|
45
70
|
|
|
71
|
+
// A platform-supplied endpoint for one call (see ProviderCredential).
|
|
72
|
+
export type ProviderEndpoint = {
|
|
73
|
+
baseUrl?: string;
|
|
74
|
+
headers?: Record<string, string>;
|
|
75
|
+
};
|
|
76
|
+
|
|
46
77
|
export type ProviderCompletion = {
|
|
47
78
|
message: Record<string, unknown>;
|
|
48
79
|
source: ProviderIdentity;
|
|
@@ -55,14 +86,40 @@ export type ProviderEventStream = {
|
|
|
55
86
|
|
|
56
87
|
export type ModelMetadataLookup = (modelId: string, pricing?: ModelPricing | null) => ModelRuntimeMetadata;
|
|
57
88
|
|
|
58
|
-
|
|
89
|
+
// Pi's built-in providers stream through these API implementations unchanged.
|
|
90
|
+
// Dari always passes resolved credentials, so it dispatches on the API rather
|
|
91
|
+
// than through a Models collection with its own auth resolution.
|
|
92
|
+
const PI_APIS: Record<string, ProviderStreams> = {
|
|
93
|
+
"anthropic-messages": anthropicMessagesApi(),
|
|
94
|
+
"azure-openai-responses": azureOpenAIResponsesApi(),
|
|
95
|
+
"bedrock-converse-stream": bedrockConverseStreamApi(),
|
|
96
|
+
"google-generative-ai": googleGenerativeAIApi(),
|
|
97
|
+
"google-vertex": googleVertexApi(),
|
|
98
|
+
"mistral-conversations": mistralConversationsApi(),
|
|
99
|
+
"openai-codex-responses": openAICodexResponsesApi(),
|
|
100
|
+
"openai-completions": openAICompletionsApi(),
|
|
101
|
+
"openai-responses": openAIResponsesApi(),
|
|
102
|
+
};
|
|
59
103
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
104
|
+
function piStreamSimple(
|
|
105
|
+
model: Record<string, unknown>,
|
|
106
|
+
context: Record<string, unknown>,
|
|
107
|
+
options: Record<string, unknown>,
|
|
108
|
+
): AssistantMessageEventStream {
|
|
109
|
+
const api = PI_APIS[String(model.api)];
|
|
110
|
+
if (!api) throw new Error(`No Pi API implementation for ${String(model.api)}.`);
|
|
111
|
+
return api.streamSimple(model as unknown as Model<Api>, normalizeContext(context as unknown as Context), options);
|
|
64
112
|
}
|
|
65
113
|
|
|
114
|
+
export const pi: PiAi = {
|
|
115
|
+
completeSimple: async (model, context, options) =>
|
|
116
|
+
await piStreamSimple(model, context, options).result() as unknown as Record<string, unknown>,
|
|
117
|
+
streamSimple: (model, context, options) =>
|
|
118
|
+
piStreamSimple(model, context, options) as unknown as AsyncIterable<Record<string, unknown>>,
|
|
119
|
+
getModel: (provider, id) => getBuiltinModel(provider as never, id as never) as unknown as Record<string, unknown> | undefined,
|
|
120
|
+
getSupportedThinkingLevels: (model) => getSupportedThinkingLevels(model as unknown as Model<Api>),
|
|
121
|
+
};
|
|
122
|
+
|
|
66
123
|
export async function completeInteractionModel(args: {
|
|
67
124
|
model: string;
|
|
68
125
|
request: InteractionRequest;
|
|
@@ -70,18 +127,19 @@ export async function completeInteractionModel(args: {
|
|
|
70
127
|
auth?: ResolvedProviderAuth;
|
|
71
128
|
pricing?: ModelPricing | null;
|
|
72
129
|
config?: ResolvedRouterModelConfig;
|
|
130
|
+
endpoint?: ProviderEndpoint;
|
|
73
131
|
sessionId?: string;
|
|
74
132
|
selectedReasoningEffort?: ReasoningEffort;
|
|
75
133
|
timeoutMs?: number;
|
|
76
134
|
signal?: AbortSignal;
|
|
77
135
|
fetch?: ProviderFetch;
|
|
78
136
|
}): Promise<ProviderCompletion> {
|
|
79
|
-
const
|
|
80
|
-
const model = buildModel(pi, args.model, args.pricing, args.config);
|
|
137
|
+
const model = modelAtEndpoint(buildModel(pi, args.model, args.pricing, args.config), args.endpoint);
|
|
81
138
|
const source = providerIdentityFromModel(model);
|
|
82
139
|
const context = buildContext(args.request, source);
|
|
140
|
+
const costTap = reportsProviderCost(model) ? providerReportedCostTap(args.fetch) : undefined;
|
|
83
141
|
const safeguards = forwardsAnthropicSafeguards(args.request, model)
|
|
84
|
-
? safeguardResultsTap(args.fetch)
|
|
142
|
+
? safeguardResultsTap(costTap?.fetch ?? args.fetch)
|
|
85
143
|
: undefined;
|
|
86
144
|
const options = buildOptions(
|
|
87
145
|
args.request,
|
|
@@ -93,16 +151,19 @@ export async function completeInteractionModel(args: {
|
|
|
93
151
|
args.selectedReasoningEffort,
|
|
94
152
|
args.timeoutMs,
|
|
95
153
|
args.signal,
|
|
96
|
-
safeguards?.fetch ?? args.fetch,
|
|
154
|
+
safeguards?.fetch ?? costTap?.fetch ?? args.fetch,
|
|
97
155
|
);
|
|
98
156
|
const usageContext = subscriptionUsageContext(args.model, model, source);
|
|
99
157
|
const message = options.emitProviderEvents === true
|
|
100
158
|
? await completeProviderEventStream(pi.streamSimple(model, context, options))
|
|
101
159
|
: await pi.completeSimple(model, context, options);
|
|
102
160
|
return {
|
|
103
|
-
message:
|
|
104
|
-
|
|
105
|
-
|
|
161
|
+
message: messageWithProviderReportedCost(
|
|
162
|
+
messageWithSubscriptionCacheWrites(
|
|
163
|
+
messageWithSafeguardResults(message, safeguards?.results()),
|
|
164
|
+
usageContext
|
|
165
|
+
),
|
|
166
|
+
costTap?.cost(),
|
|
106
167
|
),
|
|
107
168
|
source,
|
|
108
169
|
};
|
|
@@ -167,16 +228,17 @@ export async function streamInteractionModel(args: {
|
|
|
167
228
|
auth?: ResolvedProviderAuth;
|
|
168
229
|
pricing?: ModelPricing | null;
|
|
169
230
|
config?: ResolvedRouterModelConfig;
|
|
231
|
+
endpoint?: ProviderEndpoint;
|
|
170
232
|
sessionId?: string;
|
|
171
233
|
selectedReasoningEffort?: ReasoningEffort;
|
|
172
234
|
signal?: AbortSignal;
|
|
173
235
|
fetch?: ProviderFetch;
|
|
174
236
|
}): Promise<ProviderEventStream> {
|
|
175
|
-
const
|
|
176
|
-
const model = buildModel(pi, args.model, args.pricing, args.config);
|
|
237
|
+
const model = modelAtEndpoint(buildModel(pi, args.model, args.pricing, args.config), args.endpoint);
|
|
177
238
|
const source = providerIdentityFromModel(model);
|
|
239
|
+
const costTap = reportsProviderCost(model) ? providerReportedCostTap(args.fetch) : undefined;
|
|
178
240
|
const safeguards = forwardsAnthropicSafeguards(args.request, model)
|
|
179
|
-
? safeguardResultsTap(args.fetch)
|
|
241
|
+
? safeguardResultsTap(costTap?.fetch ?? args.fetch)
|
|
180
242
|
: undefined;
|
|
181
243
|
const events = pi.streamSimple(
|
|
182
244
|
model,
|
|
@@ -191,20 +253,34 @@ export async function streamInteractionModel(args: {
|
|
|
191
253
|
args.selectedReasoningEffort,
|
|
192
254
|
undefined,
|
|
193
255
|
args.signal,
|
|
194
|
-
safeguards?.fetch ?? args.fetch,
|
|
256
|
+
safeguards?.fetch ?? costTap?.fetch ?? args.fetch,
|
|
195
257
|
)
|
|
196
258
|
);
|
|
259
|
+
const withCacheWrites = eventsWithSubscriptionCacheWrites(
|
|
260
|
+
safeguards ? eventsWithSafeguardResults(events, safeguards) : events,
|
|
261
|
+
subscriptionUsageContext(args.model, model, source)
|
|
262
|
+
);
|
|
197
263
|
return {
|
|
198
|
-
events:
|
|
199
|
-
safeguards ? eventsWithSafeguardResults(events, safeguards) : events,
|
|
200
|
-
subscriptionUsageContext(args.model, model, source)
|
|
201
|
-
),
|
|
264
|
+
events: costTap ? eventsWithProviderReportedCost(withCacheWrites, costTap) : withCacheWrites,
|
|
202
265
|
source,
|
|
203
266
|
};
|
|
204
267
|
}
|
|
205
268
|
|
|
206
|
-
|
|
207
|
-
|
|
269
|
+
function modelAtEndpoint(
|
|
270
|
+
model: Record<string, unknown>,
|
|
271
|
+
endpoint: ProviderEndpoint | undefined,
|
|
272
|
+
): Record<string, unknown> {
|
|
273
|
+
if (endpoint === undefined) return model;
|
|
274
|
+
return {
|
|
275
|
+
...model,
|
|
276
|
+
...(endpoint.baseUrl ? { baseUrl: endpoint.baseUrl } : {}),
|
|
277
|
+
...(endpoint.headers
|
|
278
|
+
? { headers: { ...(isRecord(model.headers) ? model.headers : {}), ...endpoint.headers } }
|
|
279
|
+
: {}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function modelContextWindow(modelId: string): number | null {
|
|
208
284
|
const provider = providerForModel(modelId);
|
|
209
285
|
const nativeId = nativeModelId(modelId);
|
|
210
286
|
const registered = resolveModelMetadata(pi, provider, modelId, nativeId);
|
|
@@ -215,11 +291,10 @@ export async function modelContextWindow(modelId: string): Promise<number | null
|
|
|
215
291
|
* Pi's catalog price for a canonical model served by `provider`, in USD per
|
|
216
292
|
* million tokens. Null when Pi does not list the model.
|
|
217
293
|
*/
|
|
218
|
-
export
|
|
294
|
+
export function registeredModelPrice(
|
|
219
295
|
modelId: string,
|
|
220
296
|
provider: string = providerForModel(modelId),
|
|
221
|
-
):
|
|
222
|
-
const pi = await piAi();
|
|
297
|
+
): RouterModelPrice | null {
|
|
223
298
|
const registered = resolveModelMetadata(pi, provider, modelId, nativeModelId(modelId));
|
|
224
299
|
const cost = registered?.cost;
|
|
225
300
|
if (!isRecord(cost) || typeof cost.input !== "number" || typeof cost.output !== "number") {
|
|
@@ -233,10 +308,9 @@ export async function registeredModelPrice(
|
|
|
233
308
|
};
|
|
234
309
|
}
|
|
235
310
|
|
|
236
|
-
export
|
|
311
|
+
export function modelMetadataLookup(
|
|
237
312
|
configs?: Record<string, ResolvedRouterModelConfig>
|
|
238
|
-
):
|
|
239
|
-
const pi = await piAi();
|
|
313
|
+
): ModelMetadataLookup {
|
|
240
314
|
return (modelId: string, pricing?: ModelPricing | null) => {
|
|
241
315
|
const model = buildModel(pi, modelId, pricing, configs?.[modelId]);
|
|
242
316
|
return {
|
|
@@ -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",
|