@opencode/ai 2.2.5 → 2.2.7
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 +228 -72
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +30 -125
- package/dist/decision.js +27 -15
- package/dist/effect.d.ts +10 -15
- package/dist/effect.js +6 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/embedding-client.d.ts +21 -0
- package/dist/embedding-client.js +30 -0
- package/dist/embedding.d.ts +111 -0
- package/dist/embedding.js +75 -0
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -465
- package/dist/image.js +17 -18
- package/dist/index.d.ts +35 -467
- package/dist/index.js +23 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +9 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -176
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +54 -72
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +7 -10
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +2 -22
- package/dist/protocols/open-responses.js +41 -23
- package/dist/protocols/openai-chat.d.ts +27 -23
- package/dist/protocols/openai-chat.js +62 -57
- package/dist/protocols/openai-compatible-chat.d.ts +2 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +15 -2
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +14 -7
- package/dist/protocols/shared.js +40 -15
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/system-one.js +8 -1
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +7 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +9 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +7 -80
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba.d.ts +70 -4
- package/dist/providers/alibaba.js +20 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +7 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +325 -7
- package/dist/providers/azure.js +40 -9
- package/dist/providers/baseten.d.ts +7 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +7 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +23 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +6 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +14 -5
- package/dist/providers/cohere.js +23 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +10 -5
- package/dist/providers/deepinfra.js +20 -14
- package/dist/providers/deepseek.d.ts +7 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean.d.ts +18 -5
- package/dist/providers/digitalocean.js +28 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +10 -5
- package/dist/providers/fireworks.js +17 -14
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex/embeddings.d.ts +2 -0
- package/dist/providers/google-vertex/embeddings.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +4 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +10 -3
- package/dist/providers/google-vertex.js +52 -0
- package/dist/providers/google.d.ts +21 -13
- package/dist/providers/google.js +23 -19
- package/dist/providers/groq.d.ts +10 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +6 -5
- package/dist/providers/meta.js +10 -23
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +6 -5
- package/dist/providers/minimax.js +7 -22
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +6 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
- package/dist/providers/openai-compatible/embeddings.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +10 -7
- package/dist/providers/openai-compatible.js +17 -10
- package/dist/providers/openai.d.ts +11 -4
- package/dist/providers/openai.js +17 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter.d.ts +24 -5
- package/dist/providers/openrouter.js +31 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +7 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +5 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +9 -5
- package/dist/providers/vercel-ai-gateway.js +30 -29
- package/dist/providers/xai.d.ts +5 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +6 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +6 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +14 -0
- package/dist/public.js +6 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/embedding.d.ts +61 -0
- package/dist/route/embedding.js +88 -0
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +309 -257
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
|
@@ -3,7 +3,7 @@ import { Route } from "../route/client.js";
|
|
|
3
3
|
import { Framing } from "../route/framing.js";
|
|
4
4
|
import { HttpTransport } from "../route/transport/index.js";
|
|
5
5
|
import { Protocol } from "../route/protocol.js";
|
|
6
|
-
import { AIError, LLMEvent, Usage, type FinishReasonDetails, type CacheHint, type LLMRequest } from "../schema/index.js";
|
|
6
|
+
import { AIError, LLMEvent, Usage, type FinishReasonDetails, type AssistantMessage, type CacheHint, type LLMRequest } from "../schema/index.js";
|
|
7
7
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
8
8
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
9
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
@@ -158,6 +158,7 @@ export declare const OpenAIChatMessage: Schema.toTaggedUnion<"role", readonly [S
|
|
|
158
158
|
readonly reasoning: Schema.optional<Schema.String>;
|
|
159
159
|
readonly reasoning_text: Schema.optional<Schema.String>;
|
|
160
160
|
readonly reasoning_details: Schema.optional<Schema.Unknown>;
|
|
161
|
+
readonly reasoning_opaque: Schema.optional<Schema.String>;
|
|
161
162
|
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
|
|
162
163
|
readonly role: Schema.Literal<"tool">;
|
|
163
164
|
readonly tool_call_id: Schema.String;
|
|
@@ -259,6 +260,7 @@ export declare const bodyFields: {
|
|
|
259
260
|
readonly reasoning: Schema.optional<Schema.String>;
|
|
260
261
|
readonly reasoning_text: Schema.optional<Schema.String>;
|
|
261
262
|
readonly reasoning_details: Schema.optional<Schema.Unknown>;
|
|
263
|
+
readonly reasoning_opaque: Schema.optional<Schema.String>;
|
|
262
264
|
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
|
|
263
265
|
readonly role: Schema.Literal<"tool">;
|
|
264
266
|
readonly tool_call_id: Schema.String;
|
|
@@ -428,6 +430,7 @@ declare const OpenAIChatBody: Schema.Struct<{
|
|
|
428
430
|
readonly reasoning: Schema.optional<Schema.String>;
|
|
429
431
|
readonly reasoning_text: Schema.optional<Schema.String>;
|
|
430
432
|
readonly reasoning_details: Schema.optional<Schema.Unknown>;
|
|
433
|
+
readonly reasoning_opaque: Schema.optional<Schema.String>;
|
|
431
434
|
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
|
|
432
435
|
readonly role: Schema.Literal<"tool">;
|
|
433
436
|
readonly tool_call_id: Schema.String;
|
|
@@ -518,6 +521,7 @@ export declare const OpenAIChatUsage: Schema.StructWithRest<Schema.Struct<{
|
|
|
518
521
|
readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
519
522
|
readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
520
523
|
readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
524
|
+
readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
521
525
|
readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
|
|
522
526
|
readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
523
527
|
readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
@@ -548,6 +552,7 @@ export declare const OpenAIChatDelta: Schema.StructWithRest<Schema.Struct<{
|
|
|
548
552
|
readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
549
553
|
readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
550
554
|
readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
|
|
555
|
+
readonly reasoning_opaque: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
551
556
|
readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
|
|
552
557
|
readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
553
558
|
readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
@@ -570,6 +575,7 @@ export declare const OpenAIChatChoice: Schema.StructWithRest<Schema.Struct<{
|
|
|
570
575
|
readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
571
576
|
readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
572
577
|
readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
|
|
578
|
+
readonly reasoning_opaque: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
573
579
|
readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
|
|
574
580
|
readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
575
581
|
readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
@@ -594,6 +600,7 @@ export declare const OpenAIChatChoice: Schema.StructWithRest<Schema.Struct<{
|
|
|
594
600
|
readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
595
601
|
readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
596
602
|
readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
603
|
+
readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
597
604
|
readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
|
|
598
605
|
readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
599
606
|
readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
@@ -614,6 +621,7 @@ export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
|
|
|
614
621
|
readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
615
622
|
readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
616
623
|
readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
|
|
624
|
+
readonly reasoning_opaque: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
617
625
|
readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
|
|
618
626
|
readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
619
627
|
readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
@@ -638,6 +646,7 @@ export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
|
|
|
638
646
|
readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
639
647
|
readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
640
648
|
readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
649
|
+
readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
641
650
|
readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
|
|
642
651
|
readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
643
652
|
readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
@@ -657,6 +666,7 @@ export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
|
|
|
657
666
|
readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
658
667
|
readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
659
668
|
readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
669
|
+
readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
660
670
|
readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
|
|
661
671
|
readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
662
672
|
readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
@@ -695,6 +705,8 @@ export interface ParserState {
|
|
|
695
705
|
readonly reasoningTextObserved: boolean;
|
|
696
706
|
readonly reasoningDetails: Array<ReasoningDetail>;
|
|
697
707
|
readonly reasoningDetailsObserved: boolean;
|
|
708
|
+
/** Latest `reasoning_opaque`; interleaved reasoning sends a new one before each tool call. */
|
|
709
|
+
readonly reasoningOpaque?: string;
|
|
698
710
|
readonly reasoningEmitted: boolean;
|
|
699
711
|
readonly latestToolIndex?: number;
|
|
700
712
|
readonly nextToolIndex: number;
|
|
@@ -704,7 +716,7 @@ interface LoweringOptions {
|
|
|
704
716
|
readonly cacheControl?: (cache: CacheHint | undefined) => OpenAIChatCacheControl | undefined;
|
|
705
717
|
readonly toolCallID?: (id: string) => string;
|
|
706
718
|
/** Project provider-specific fields from the exact source, even when other messages are dropped during lowering. */
|
|
707
|
-
readonly assistant?: (source:
|
|
719
|
+
readonly assistant?: (source: AssistantMessage, message: OpenAIChatMessage) => OpenAIChatMessage;
|
|
708
720
|
}
|
|
709
721
|
export declare const fromRequest: (request: LLMRequest<import("../schema/options.js").LanguageModel<{
|
|
710
722
|
readonly [x: string]: unknown;
|
|
@@ -820,6 +832,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
820
832
|
readonly reasoning?: string | undefined;
|
|
821
833
|
readonly reasoning_text?: string | undefined;
|
|
822
834
|
readonly reasoning_details?: unknown;
|
|
835
|
+
readonly reasoning_opaque?: string | undefined;
|
|
823
836
|
})[];
|
|
824
837
|
tools: ({
|
|
825
838
|
readonly type: "function";
|
|
@@ -992,6 +1005,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
992
1005
|
readonly reasoning?: string | undefined;
|
|
993
1006
|
readonly reasoning_text?: string | undefined;
|
|
994
1007
|
readonly reasoning_details?: unknown;
|
|
1008
|
+
readonly reasoning_opaque?: string | undefined;
|
|
995
1009
|
})[];
|
|
996
1010
|
tools: ({
|
|
997
1011
|
readonly type: "function";
|
|
@@ -1166,6 +1180,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
1166
1180
|
readonly reasoning?: string | undefined;
|
|
1167
1181
|
readonly reasoning_text?: string | undefined;
|
|
1168
1182
|
readonly reasoning_details?: unknown;
|
|
1183
|
+
readonly reasoning_opaque?: string | undefined;
|
|
1169
1184
|
})[];
|
|
1170
1185
|
tools: ({
|
|
1171
1186
|
readonly type: "function";
|
|
@@ -1338,6 +1353,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
1338
1353
|
readonly reasoning?: string | undefined;
|
|
1339
1354
|
readonly reasoning_text?: string | undefined;
|
|
1340
1355
|
readonly reasoning_details?: unknown;
|
|
1356
|
+
readonly reasoning_opaque?: string | undefined;
|
|
1341
1357
|
})[];
|
|
1342
1358
|
tools: ({
|
|
1343
1359
|
readonly type: "function";
|
|
@@ -1510,6 +1526,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
1510
1526
|
readonly reasoning?: string | undefined;
|
|
1511
1527
|
readonly reasoning_text?: string | undefined;
|
|
1512
1528
|
readonly reasoning_details?: unknown;
|
|
1529
|
+
readonly reasoning_opaque?: string | undefined;
|
|
1513
1530
|
})[];
|
|
1514
1531
|
tools: ({
|
|
1515
1532
|
readonly type: "function";
|
|
@@ -1684,6 +1701,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
1684
1701
|
readonly reasoning?: string | undefined;
|
|
1685
1702
|
readonly reasoning_text?: string | undefined;
|
|
1686
1703
|
readonly reasoning_details?: unknown;
|
|
1704
|
+
readonly reasoning_opaque?: string | undefined;
|
|
1687
1705
|
})[];
|
|
1688
1706
|
tools: ({
|
|
1689
1707
|
readonly type: "function";
|
|
@@ -1893,18 +1911,6 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1893
1911
|
readonly [x: string]: unknown;
|
|
1894
1912
|
};
|
|
1895
1913
|
} | undefined;
|
|
1896
|
-
} | {
|
|
1897
|
-
readonly type: "tool-error";
|
|
1898
|
-
readonly id: string;
|
|
1899
|
-
readonly name: string;
|
|
1900
|
-
readonly namespace?: string | undefined;
|
|
1901
|
-
readonly message: string;
|
|
1902
|
-
readonly error?: unknown;
|
|
1903
|
-
readonly providerMetadata?: {
|
|
1904
|
-
readonly [x: string]: {
|
|
1905
|
-
readonly [x: string]: unknown;
|
|
1906
|
-
};
|
|
1907
|
-
} | undefined;
|
|
1908
1914
|
} | {
|
|
1909
1915
|
readonly type: "step-finish";
|
|
1910
1916
|
readonly index: number;
|
|
@@ -1929,6 +1935,7 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1929
1935
|
readonly explanation?: string | undefined;
|
|
1930
1936
|
};
|
|
1931
1937
|
readonly usage?: Usage | undefined;
|
|
1938
|
+
readonly message?: AssistantMessage | undefined;
|
|
1932
1939
|
readonly providerMetadata?: {
|
|
1933
1940
|
readonly [x: string]: {
|
|
1934
1941
|
readonly [x: string]: unknown;
|
|
@@ -1942,15 +1949,6 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1942
1949
|
readonly [x: string]: unknown;
|
|
1943
1950
|
};
|
|
1944
1951
|
} | undefined;
|
|
1945
|
-
} | {
|
|
1946
|
-
readonly type: "provider-error";
|
|
1947
|
-
readonly message: string;
|
|
1948
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1949
|
-
readonly providerMetadata?: {
|
|
1950
|
-
readonly [x: string]: {
|
|
1951
|
-
readonly [x: string]: unknown;
|
|
1952
|
-
};
|
|
1953
|
-
} | undefined;
|
|
1954
1952
|
} | ({
|
|
1955
1953
|
readonly type: "compaction";
|
|
1956
1954
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -2070,6 +2068,7 @@ export declare const protocol: Protocol<{
|
|
|
2070
2068
|
readonly reasoning?: string | undefined;
|
|
2071
2069
|
readonly reasoning_text?: string | undefined;
|
|
2072
2070
|
readonly reasoning_details?: unknown;
|
|
2071
|
+
readonly reasoning_opaque?: string | undefined;
|
|
2073
2072
|
})[];
|
|
2074
2073
|
readonly tools?: readonly ({
|
|
2075
2074
|
readonly type: "function";
|
|
@@ -2155,6 +2154,7 @@ export declare const protocol: Protocol<{
|
|
|
2155
2154
|
readonly reasoning?: string | null | undefined;
|
|
2156
2155
|
readonly reasoning_text?: string | null | undefined;
|
|
2157
2156
|
readonly reasoning_details?: unknown;
|
|
2157
|
+
readonly reasoning_opaque?: string | null | undefined;
|
|
2158
2158
|
readonly tool_calls?: readonly {
|
|
2159
2159
|
readonly index?: number | null | undefined;
|
|
2160
2160
|
readonly id?: string | null | undefined;
|
|
@@ -2180,6 +2180,7 @@ export declare const protocol: Protocol<{
|
|
|
2180
2180
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
2181
2181
|
readonly cache_read_input_tokens?: number | null | undefined;
|
|
2182
2182
|
readonly cache_created_input_tokens?: number | null | undefined;
|
|
2183
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
2183
2184
|
readonly prompt_tokens_details?: {
|
|
2184
2185
|
readonly [x: string]: unknown;
|
|
2185
2186
|
readonly cached_tokens?: number | null | undefined;
|
|
@@ -2202,6 +2203,7 @@ export declare const protocol: Protocol<{
|
|
|
2202
2203
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
2203
2204
|
readonly cache_read_input_tokens?: number | null | undefined;
|
|
2204
2205
|
readonly cache_created_input_tokens?: number | null | undefined;
|
|
2206
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
2205
2207
|
readonly prompt_tokens_details?: {
|
|
2206
2208
|
readonly [x: string]: unknown;
|
|
2207
2209
|
readonly cached_tokens?: number | null | undefined;
|
|
@@ -2321,6 +2323,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
2321
2323
|
readonly reasoning?: string | undefined;
|
|
2322
2324
|
readonly reasoning_text?: string | undefined;
|
|
2323
2325
|
readonly reasoning_details?: unknown;
|
|
2326
|
+
readonly reasoning_opaque?: string | undefined;
|
|
2324
2327
|
})[];
|
|
2325
2328
|
readonly tools?: readonly ({
|
|
2326
2329
|
readonly type: "function";
|
|
@@ -2495,6 +2498,7 @@ export declare const route: Route<{
|
|
|
2495
2498
|
readonly reasoning?: string | undefined;
|
|
2496
2499
|
readonly reasoning_text?: string | undefined;
|
|
2497
2500
|
readonly reasoning_details?: unknown;
|
|
2501
|
+
readonly reasoning_opaque?: string | undefined;
|
|
2498
2502
|
})[];
|
|
2499
2503
|
readonly tools?: readonly ({
|
|
2500
2504
|
readonly type: "function";
|
|
@@ -8,7 +8,7 @@ import { HttpTransport } from "../route/transport/index.js";
|
|
|
8
8
|
import { Protocol } from "../route/protocol.js";
|
|
9
9
|
import { AIError, AIErrorReason, InvalidProviderOutputError, LLMEvent, ProviderInternalError, UnknownProviderError, Usage, } from "../schema/index.js";
|
|
10
10
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
11
|
-
import {
|
|
11
|
+
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
12
12
|
import { placesMarkers, requestTTL } from "../cache-policy.js";
|
|
13
13
|
import * as Cache from "./utils/cache.js";
|
|
14
14
|
import { resolveParallelToolCalls } from "./open-responses.js";
|
|
@@ -95,7 +95,11 @@ const OpenRouterDetailFields = {
|
|
|
95
95
|
signature: Schema.optional(Schema.NullOr(Schema.String)),
|
|
96
96
|
};
|
|
97
97
|
const ReasoningDetail = Schema.Union([
|
|
98
|
-
Schema.StructWithRest(Schema.Struct({
|
|
98
|
+
Schema.StructWithRest(Schema.Struct({
|
|
99
|
+
type: Schema.Literal("reasoning.text"),
|
|
100
|
+
text: Schema.optional(Schema.String),
|
|
101
|
+
...OpenRouterDetailFields,
|
|
102
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]),
|
|
99
103
|
Schema.StructWithRest(Schema.Struct({
|
|
100
104
|
type: Schema.Literal("reasoning.summary"),
|
|
101
105
|
summary: Schema.optional(Schema.String),
|
|
@@ -144,6 +148,7 @@ export const OpenAIChatMessage = Schema.Union([
|
|
|
144
148
|
reasoning: Schema.optional(Schema.String),
|
|
145
149
|
reasoning_text: Schema.optional(Schema.String),
|
|
146
150
|
reasoning_details: Schema.optional(Schema.Unknown),
|
|
151
|
+
reasoning_opaque: Schema.optional(Schema.String),
|
|
147
152
|
}), [Schema.Record(Schema.String, Schema.Unknown)]),
|
|
148
153
|
Schema.Struct({
|
|
149
154
|
role: Schema.Literal("tool"),
|
|
@@ -205,6 +210,8 @@ export const OpenAIChatUsage = Schema.StructWithRest(Schema.Struct({
|
|
|
205
210
|
prompt_cache_hit_tokens: optionalNull(Schema.Number),
|
|
206
211
|
cache_read_input_tokens: optionalNull(Schema.Number),
|
|
207
212
|
cache_created_input_tokens: optionalNull(Schema.Number),
|
|
213
|
+
// GitHub Copilot reports reasoning at the top level instead of in `completion_tokens_details`.
|
|
214
|
+
reasoning_tokens: optionalNull(Schema.Number),
|
|
208
215
|
prompt_tokens_details: optionalNull(Schema.StructWithRest(Schema.Struct({
|
|
209
216
|
cached_tokens: optionalNull(Schema.Number),
|
|
210
217
|
cache_write_tokens: optionalNull(Schema.Number),
|
|
@@ -233,6 +240,8 @@ export const OpenAIChatDelta = Schema.StructWithRest(Schema.Struct({
|
|
|
233
240
|
reasoning: optionalNull(Schema.String),
|
|
234
241
|
reasoning_text: optionalNull(Schema.String),
|
|
235
242
|
reasoning_details: optionalNull(Schema.Unknown),
|
|
243
|
+
// GitHub Copilot's opaque reasoning state, which must be replayed for multi-turn reasoning.
|
|
244
|
+
reasoning_opaque: optionalNull(Schema.String),
|
|
236
245
|
tool_calls: optionalNull(Schema.Array(OpenAIChatToolCallDelta)),
|
|
237
246
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
238
247
|
export const OpenAIChatChoice = Schema.StructWithRest(Schema.Struct({
|
|
@@ -321,20 +330,17 @@ const lowerMedia = Effect.fnUntraced(function* (part) {
|
|
|
321
330
|
return { type: "video_url", video_url: { url } };
|
|
322
331
|
return { type: "image_url", image_url: { url } };
|
|
323
332
|
});
|
|
324
|
-
const openAICompatibleReasoningContent = (native) => isRecord(native) && typeof native.reasoning_content === "string" ? native.reasoning_content : undefined;
|
|
325
333
|
const reasoningField = (part, providerMetadataKey) => {
|
|
326
334
|
const field = part.providerMetadata?.[providerMetadataKey]?.reasoningField;
|
|
327
335
|
return typeof field === "string" ? field : undefined;
|
|
328
336
|
};
|
|
329
|
-
const reasoningDetails = (parts,
|
|
337
|
+
const reasoningDetails = (parts, providerMetadataKey) => {
|
|
330
338
|
const observed = parts.flatMap((part) => {
|
|
331
339
|
const details = part.providerMetadata?.[providerMetadataKey]?.reasoningDetails;
|
|
332
340
|
return Array.isArray(details) ? details : [];
|
|
333
341
|
});
|
|
334
342
|
if (parts.some((part) => Array.isArray(part.providerMetadata?.[providerMetadataKey]?.reasoningDetails)))
|
|
335
343
|
return knownReasoningDetails(observed).map(lowerReasoningDetail);
|
|
336
|
-
if (isRecord(native) && Array.isArray(native.reasoning_details))
|
|
337
|
-
return knownReasoningDetails(native.reasoning_details).map(lowerReasoningDetail);
|
|
338
344
|
};
|
|
339
345
|
// Kimi rejects its stream-only `index` on requests
|
|
340
346
|
// ("the reasoning_details ... must not contain streaming index").
|
|
@@ -345,6 +351,11 @@ const lowerReasoningDetail = (detail) => {
|
|
|
345
351
|
return { type: detail.type, encrypted: detail.encrypted };
|
|
346
352
|
return detail;
|
|
347
353
|
};
|
|
354
|
+
// Interleaved reasoning yields one opaque value per segment; like the Copilot VS Code
|
|
355
|
+
// client, replay the latest one with the concatenated reasoning text.
|
|
356
|
+
const reasoningOpaque = (parts, providerMetadataKey) => parts
|
|
357
|
+
.map((part) => part.providerMetadata?.[providerMetadataKey]?.reasoningOpaque)
|
|
358
|
+
.findLast((value) => typeof value === "string");
|
|
348
359
|
const isKimiDetail = (detail) => detail.type === "summary" || detail.type === "encrypted";
|
|
349
360
|
const lowerUserMessage = Effect.fnUntraced(function* (message, options) {
|
|
350
361
|
const content = [];
|
|
@@ -357,7 +368,6 @@ const lowerUserMessage = Effect.fnUntraced(function* (message, options) {
|
|
|
357
368
|
content.push(yield* lowerMedia(part));
|
|
358
369
|
continue;
|
|
359
370
|
}
|
|
360
|
-
return yield* ProviderShared.unsupportedContent("OpenAI Chat", "user", ["text", "media"]);
|
|
361
371
|
}
|
|
362
372
|
if (content.every((part) => part.type === "text" && part.cache_control === undefined))
|
|
363
373
|
return {
|
|
@@ -387,21 +397,18 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
387
397
|
}
|
|
388
398
|
}
|
|
389
399
|
const text = reasoning.map((part) => part.text).join("");
|
|
390
|
-
const details = reasoningDetails(reasoning,
|
|
400
|
+
const details = reasoningDetails(reasoning, options.providerMetadataKey);
|
|
391
401
|
const observedField = reasoning
|
|
392
402
|
.map((part) => reasoningField(part, options.providerMetadataKey))
|
|
393
403
|
.find((value) => value !== undefined);
|
|
394
|
-
const nativeReasoning = openAICompatibleReasoningContent(message.native?.openaiCompatible);
|
|
395
404
|
const fullyStructured = reasoning.every((part) => Array.isArray(part.providerMetadata?.[options.providerMetadataKey]?.reasoningDetails));
|
|
396
405
|
const field = (() => {
|
|
397
|
-
if (configuredField !== undefined && (requireReasoning || reasoning.length > 0
|
|
406
|
+
if (configuredField !== undefined && (requireReasoning || reasoning.length > 0))
|
|
398
407
|
return configuredField;
|
|
399
408
|
if (reasoning.length === 0)
|
|
400
409
|
return requireReasoning ? "reasoning_content" : undefined;
|
|
401
410
|
if (observedField !== undefined)
|
|
402
411
|
return observedField;
|
|
403
|
-
if (nativeReasoning !== undefined)
|
|
404
|
-
return "reasoning_content";
|
|
405
412
|
if (!fullyStructured || requireReasoning)
|
|
406
413
|
return "reasoning_content";
|
|
407
414
|
// Kimi always expects `reasoning_content` on replayed assistant messages,
|
|
@@ -409,13 +416,8 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
409
416
|
if (details?.some(isKimiDetail))
|
|
410
417
|
return "reasoning_content";
|
|
411
418
|
})();
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
return reasoning.length === 0 ? (nativeReasoning ?? (requireReasoning ? "" : undefined)) : text;
|
|
415
|
-
if (reasoning.length === 0)
|
|
416
|
-
return nativeReasoning ?? (requireReasoning ? "" : undefined);
|
|
417
|
-
return text;
|
|
418
|
-
})();
|
|
419
|
+
const opaque = reasoningOpaque(reasoning, options.providerMetadataKey);
|
|
420
|
+
const reasoningText = reasoning.length === 0 || (opaque !== undefined && text === "") ? (requireReasoning ? "" : undefined) : text;
|
|
419
421
|
const result = {
|
|
420
422
|
role: "assistant",
|
|
421
423
|
content: (() => {
|
|
@@ -427,6 +429,7 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
427
429
|
})(),
|
|
428
430
|
...(toolCalls.length > 0 ? { tool_calls: toolCalls } : {}),
|
|
429
431
|
...(details !== undefined ? { reasoning_details: details } : {}),
|
|
432
|
+
...(opaque !== undefined ? { reasoning_opaque: opaque } : {}),
|
|
430
433
|
};
|
|
431
434
|
if (field === undefined || reasoningText === undefined)
|
|
432
435
|
return result;
|
|
@@ -436,8 +439,6 @@ const lowerToolMessages = Effect.fnUntraced(function* (message, options) {
|
|
|
436
439
|
const messages = [];
|
|
437
440
|
const attachments = [];
|
|
438
441
|
for (const part of message.content) {
|
|
439
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
440
|
-
return yield* ProviderShared.unsupportedContent("OpenAI Chat", "tool", ["tool-result"]);
|
|
441
442
|
if (part.result.type !== "content") {
|
|
442
443
|
messages.push(toolMessage(options.toolCallID?.(part.id) ?? part.id, ProviderShared.toolResultText(part), options.cacheControl?.(part.cache)));
|
|
443
444
|
continue;
|
|
@@ -459,11 +460,8 @@ const toolMessage = (toolCallID, text, cacheControl) => ({
|
|
|
459
460
|
const lowerMessage = Effect.fnUntraced(function* (message, reasoningField, requireReasoning, options) {
|
|
460
461
|
if (message.role === "user")
|
|
461
462
|
return [yield* lowerUserMessage(message, options)];
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
return [options.assistant?.(message, lowered) ?? lowered];
|
|
465
|
-
}
|
|
466
|
-
return (yield* lowerToolMessages(message, options)).messages;
|
|
463
|
+
const lowered = yield* lowerAssistantMessage(message, reasoningField, requireReasoning, options);
|
|
464
|
+
return [options.assistant?.(message, lowered) ?? lowered];
|
|
467
465
|
});
|
|
468
466
|
const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
469
467
|
const system = request.system.length === 0
|
|
@@ -526,10 +524,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
|
526
524
|
if (pendingAttachments.length > 0) {
|
|
527
525
|
messages.push({
|
|
528
526
|
role: "user",
|
|
529
|
-
content: [
|
|
530
|
-
...pendingAttachments.splice(0),
|
|
531
|
-
{ type: "text", text: part.text, cache_control: cacheControl },
|
|
532
|
-
],
|
|
527
|
+
content: [...pendingAttachments.splice(0), { type: "text", text: part.text, cache_control: cacheControl }],
|
|
533
528
|
});
|
|
534
529
|
continue;
|
|
535
530
|
}
|
|
@@ -547,10 +542,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
|
547
542
|
else if (previous?.role === "user" && Array.isArray(previous.content))
|
|
548
543
|
messages[messages.length - 1] = {
|
|
549
544
|
role: "user",
|
|
550
|
-
content: [
|
|
551
|
-
...previous.content,
|
|
552
|
-
{ type: "text", text: part.text, cache_control: cacheControl },
|
|
553
|
-
],
|
|
545
|
+
content: [...previous.content, { type: "text", text: part.text, cache_control: cacheControl }],
|
|
554
546
|
};
|
|
555
547
|
else
|
|
556
548
|
messages.push(cacheControl
|
|
@@ -666,7 +658,7 @@ const lowerOptions = (request, supportsStore, hasActiveTools) => {
|
|
|
666
658
|
// Default off: strict providers 400 on unknown body fields, so only send
|
|
667
659
|
// the key where compatibility explicitly allows it. Header-based affinity
|
|
668
660
|
// (x-session-affinity, x-grok-conv-id, ...) is unaffected.
|
|
669
|
-
const cacheKey = (request.model.
|
|
661
|
+
const cacheKey = (request.model.capabilities?.promptCacheKey ?? false) ? ProviderShared.promptCacheKey(request) : undefined;
|
|
670
662
|
return {
|
|
671
663
|
...(supportsStore ? { store: options.store ?? false } : {}),
|
|
672
664
|
...(cacheKey ? { prompt_cache_key: cacheKey } : {}),
|
|
@@ -686,14 +678,13 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
|
|
|
686
678
|
const reasoningField = request.model.compatibility?.reasoningField;
|
|
687
679
|
if (reasoningField && RESERVED_REASONING_FIELDS.has(reasoningField))
|
|
688
680
|
return yield* ProviderShared.invalidRequest(`OpenAI Chat reasoning field conflicts with reserved field ${reasoningField}`);
|
|
689
|
-
const generation = request.generation;
|
|
690
681
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
691
682
|
const provider = request.model.provider;
|
|
692
683
|
const baseURL = request.model.route.endpoint.baseURL;
|
|
693
684
|
const detectedMaxTokensField = detectMaxTokensField(provider, baseURL);
|
|
694
685
|
const maxTokensField = request.model.compatibility?.maxTokensField ?? detectedMaxTokensField;
|
|
695
|
-
const supportsStore = request.model.
|
|
696
|
-
const supportsStrictMode = request.model.
|
|
686
|
+
const supportsStore = request.model.capabilities?.store ?? detectSupportsStore(provider, baseURL);
|
|
687
|
+
const supportsStrictMode = request.model.capabilities?.tools?.strict ?? detectSupportsStrictMode(provider, baseURL);
|
|
697
688
|
const zaiToolStream = request.model.compatibility?.zaiToolStream ?? detectZaiToolStream(provider, baseURL, request.model.id);
|
|
698
689
|
const hasHistory = hasToolHistory(request.messages);
|
|
699
690
|
const hasActiveTools = flattened.tools.length > 0;
|
|
@@ -709,17 +700,17 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
|
|
|
709
700
|
: flattened.tools.map((tool) => lowerTool(tool, lowering, supportsStrictMode, custom.get(tool.name))),
|
|
710
701
|
tool_choice: hasActiveTools && request.toolChoice ? yield* lowerToolChoice(request.toolChoice, custom) : undefined,
|
|
711
702
|
stream: true,
|
|
712
|
-
...((request.model.
|
|
703
|
+
...((request.model.capabilities?.streamUsage ?? true) ? { stream_options: { include_usage: true } } : {}),
|
|
713
704
|
...(zaiToolStream && hasActiveTools ? { tool_stream: true } : {}),
|
|
714
705
|
...(maxTokensField === "max_completion_tokens"
|
|
715
|
-
? { max_completion_tokens:
|
|
716
|
-
: { max_tokens:
|
|
717
|
-
temperature:
|
|
718
|
-
top_p:
|
|
719
|
-
frequency_penalty:
|
|
720
|
-
presence_penalty:
|
|
721
|
-
seed:
|
|
722
|
-
stop:
|
|
706
|
+
? { max_completion_tokens: request.maxTokens }
|
|
707
|
+
: { max_tokens: request.maxTokens }),
|
|
708
|
+
temperature: request.temperature,
|
|
709
|
+
top_p: request.topP,
|
|
710
|
+
frequency_penalty: request.frequencyPenalty,
|
|
711
|
+
presence_penalty: request.presencePenalty,
|
|
712
|
+
seed: request.seed,
|
|
713
|
+
stop: request.stop,
|
|
723
714
|
...lowerOptions(request, supportsStore, hasActiveTools),
|
|
724
715
|
};
|
|
725
716
|
});
|
|
@@ -770,18 +761,24 @@ const mapFinishReason = Effect.fnUntraced(function* (event, reason) {
|
|
|
770
761
|
// `prompt_tokens_details.cached_tokens`, DeepSeek uses
|
|
771
762
|
// `prompt_cache_hit_tokens`, Zai uses top-level `cached_tokens`, and
|
|
772
763
|
// DigitalOcean uses top-level `cache_read_input_tokens` / `cache_created_input_tokens`.
|
|
773
|
-
const mapUsage = (usage, providerMetadataKey) => {
|
|
764
|
+
const mapUsage = (usage, providerMetadataKey, frame) => {
|
|
774
765
|
if (!usage)
|
|
775
766
|
return undefined;
|
|
776
767
|
const input = usage.prompt_tokens ?? undefined;
|
|
777
|
-
const
|
|
768
|
+
const completion = usage.completion_tokens ?? undefined;
|
|
778
769
|
const cached = usage.prompt_tokens_details?.cached_tokens ??
|
|
779
770
|
usage.prompt_cache_hit_tokens ??
|
|
780
771
|
usage.cached_tokens ??
|
|
781
772
|
usage.cache_read_input_tokens ??
|
|
782
773
|
undefined;
|
|
783
774
|
const cacheWrite = usage.prompt_tokens_details?.cache_write_tokens ?? usage.cache_created_input_tokens ?? undefined;
|
|
784
|
-
const reasoning = usage.completion_tokens_details?.reasoning_tokens ?? undefined;
|
|
775
|
+
const reasoning = usage.completion_tokens_details?.reasoning_tokens ?? usage.reasoning_tokens ?? undefined;
|
|
776
|
+
// Copilot's Gemini counts reasoning beside `completion_tokens` rather than inside it; the total tells which.
|
|
777
|
+
const output = completion !== undefined &&
|
|
778
|
+
reasoning !== undefined &&
|
|
779
|
+
usage.total_tokens === ProviderShared.sumTokens(input, completion, reasoning)
|
|
780
|
+
? completion + reasoning
|
|
781
|
+
: completion;
|
|
785
782
|
const nonCached = ProviderShared.subtractTokens(input, ProviderShared.sumTokens(cached, cacheWrite));
|
|
786
783
|
return new Usage({
|
|
787
784
|
inputTokens: input,
|
|
@@ -791,7 +788,7 @@ const mapUsage = (usage, providerMetadataKey) => {
|
|
|
791
788
|
cacheWriteInputTokens: cacheWrite,
|
|
792
789
|
reasoningTokens: reasoning,
|
|
793
790
|
totalTokens: ProviderShared.totalTokens(input, output, usage.total_tokens ?? undefined),
|
|
794
|
-
...ProviderShared.reportedBilling(usage),
|
|
791
|
+
...ProviderShared.reportedBilling(usage, frame),
|
|
795
792
|
providerMetadata: { [providerMetadataKey]: usage },
|
|
796
793
|
});
|
|
797
794
|
};
|
|
@@ -878,10 +875,11 @@ const conflictingReasoningDetails = (previous, current) => conflictingDetailValu
|
|
|
878
875
|
conflictingDetailValue(previous.format, current.format) ||
|
|
879
876
|
(Boolean(previous.signature) && Boolean(current.signature) && previous.signature !== current.signature);
|
|
880
877
|
const conflictingDetailValue = (previous, current) => previous !== undefined && previous !== null && current !== undefined && current !== null && previous !== current;
|
|
881
|
-
const reasoningMetadata = (providerMetadataKey, field, details) => ({
|
|
878
|
+
const reasoningMetadata = (providerMetadataKey, field, details, opaque) => ({
|
|
882
879
|
[providerMetadataKey]: {
|
|
883
880
|
...(field ? { reasoningField: field } : {}),
|
|
884
881
|
...(details ? { reasoningDetails: details } : {}),
|
|
882
|
+
...(opaque ? { reasoningOpaque: opaque } : {}),
|
|
885
883
|
},
|
|
886
884
|
});
|
|
887
885
|
const step = (state, event) => Effect.gen(function* () {
|
|
@@ -899,14 +897,19 @@ const step = (state, event) => Effect.gen(function* () {
|
|
|
899
897
|
const choice = event.choices?.[0];
|
|
900
898
|
// Moonshot (and a few other OpenAI-compatible providers) attach usage to
|
|
901
899
|
// `choice.usage` instead of the top-level `usage` field.
|
|
902
|
-
const usage = mapUsage(event.usage, state.providerMetadataKey) ??
|
|
903
|
-
mapUsage(choice?.usage, state.providerMetadataKey) ??
|
|
900
|
+
const usage = mapUsage(event.usage, state.providerMetadataKey, event) ??
|
|
901
|
+
mapUsage(choice?.usage, state.providerMetadataKey, event) ??
|
|
904
902
|
state.usage;
|
|
905
903
|
const rawFinishReason = choice?.finish_reason;
|
|
906
904
|
const finishReason = rawFinishReason
|
|
907
905
|
? {
|
|
908
906
|
normalized: yield* mapFinishReason(event, rawFinishReason),
|
|
909
907
|
raw: choice?.native_finish_reason ?? rawFinishReason,
|
|
908
|
+
...(rawFinishReason === "content_filter"
|
|
909
|
+
? {
|
|
910
|
+
category: ProviderShared.contentFilterCategory(choice?.delta?.copilot_annotations, choice?.content_filter_results),
|
|
911
|
+
}
|
|
912
|
+
: {}),
|
|
910
913
|
}
|
|
911
914
|
: state.finishReason;
|
|
912
915
|
const delta = choice?.delta;
|
|
@@ -932,13 +935,14 @@ const step = (state, event) => Effect.gen(function* () {
|
|
|
932
935
|
if (detailDelta !== undefined)
|
|
933
936
|
appendReasoningDetails(state.reasoningDetails, detailDelta);
|
|
934
937
|
const reasoningDetailsObserved = state.reasoningDetailsObserved || detailDelta !== undefined;
|
|
938
|
+
const reasoningOpaque = delta?.reasoning_opaque || state.reasoningOpaque;
|
|
935
939
|
const deltaMetadata = reasoningMetadata(state.providerMetadataKey, reasoningField);
|
|
936
940
|
const text = detailDelta?.length
|
|
937
941
|
? (detailText(detailDelta, reasoningTextObserved) ?? reasoning?.text)
|
|
938
942
|
: reasoning?.text;
|
|
939
943
|
if (text !== undefined)
|
|
940
944
|
lifecycle = Lifecycle.reasoningDelta(lifecycle, events, "reasoning-0", text, deltaMetadata);
|
|
941
|
-
else if (reasoningDetailsObserved &&
|
|
945
|
+
else if ((reasoningDetailsObserved || reasoningOpaque !== undefined) &&
|
|
942
946
|
!lifecycle.reasoning.has("reasoning-0") &&
|
|
943
947
|
(Boolean(delta?.content) || Boolean(delta?.refusal) || toolDeltas.length > 0))
|
|
944
948
|
lifecycle = Lifecycle.reasoningStart(lifecycle, events, "reasoning-0", deltaMetadata);
|
|
@@ -1034,6 +1038,7 @@ const step = (state, event) => Effect.gen(function* () {
|
|
|
1034
1038
|
reasoningTextObserved,
|
|
1035
1039
|
reasoningDetails: state.reasoningDetails,
|
|
1036
1040
|
reasoningDetailsObserved,
|
|
1041
|
+
reasoningOpaque,
|
|
1037
1042
|
reasoningEmitted,
|
|
1038
1043
|
latestToolIndex,
|
|
1039
1044
|
nextToolIndex,
|
|
@@ -1070,8 +1075,8 @@ export const finishEvents = Effect.fnUntraced(function* (state) {
|
|
|
1070
1075
|
: { normalized: hasToolCalls ? "tool-calls" : "stop" };
|
|
1071
1076
|
// Snapshot details at publish time so the emitted event never observes later
|
|
1072
1077
|
// mutation of the accumulated `reasoningDetails` array.
|
|
1073
|
-
const metadata = reasoningMetadata(state.providerMetadataKey, state.reasoningField, state.reasoningDetailsObserved ? [...state.reasoningDetails] : undefined);
|
|
1074
|
-
const started = state.reasoningDetailsObserved && !state.reasoningEmitted
|
|
1078
|
+
const metadata = reasoningMetadata(state.providerMetadataKey, state.reasoningField, state.reasoningDetailsObserved ? [...state.reasoningDetails] : undefined, state.reasoningOpaque);
|
|
1079
|
+
const started = (state.reasoningDetailsObserved || state.reasoningOpaque !== undefined) && !state.reasoningEmitted
|
|
1075
1080
|
? Lifecycle.reasoningStart(state.lifecycle, events, "reasoning-0", reasoningMetadata(state.providerMetadataKey, state.reasoningField))
|
|
1076
1081
|
: state.lifecycle;
|
|
1077
1082
|
const ended = Lifecycle.reasoningEnd(started, events, "reasoning-0", metadata);
|
|
@@ -106,6 +106,7 @@ export declare const route: Route<{
|
|
|
106
106
|
readonly reasoning?: string | undefined;
|
|
107
107
|
readonly reasoning_text?: string | undefined;
|
|
108
108
|
readonly reasoning_details?: unknown;
|
|
109
|
+
readonly reasoning_opaque?: string | undefined;
|
|
109
110
|
})[];
|
|
110
111
|
readonly tools?: readonly ({
|
|
111
112
|
readonly type: "function";
|
|
@@ -162,7 +163,7 @@ export declare const route: Route<{
|
|
|
162
163
|
readonly prompt_cache_options?: {
|
|
163
164
|
readonly ttl?: string | undefined;
|
|
164
165
|
} | undefined;
|
|
165
|
-
readonly reasoning_effort?: import("../
|
|
166
|
+
readonly reasoning_effort?: import("../public.js").ReasoningEffort | undefined;
|
|
166
167
|
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
167
168
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
168
169
|
readonly parallel_tool_calls?: boolean | undefined;
|
|
@@ -9,7 +9,7 @@ export declare const route: Route<{
|
|
|
9
9
|
readonly input: readonly ({
|
|
10
10
|
readonly type: "configuration_update";
|
|
11
11
|
readonly reasoning: {
|
|
12
|
-
readonly effort: import("../
|
|
12
|
+
readonly effort: import("../public.js").ReasoningEffort;
|
|
13
13
|
};
|
|
14
14
|
} | {
|
|
15
15
|
readonly type: "message";
|
|
@@ -187,7 +187,7 @@ export declare const route: Route<{
|
|
|
187
187
|
readonly prompt_cache_key?: string | undefined;
|
|
188
188
|
readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
189
189
|
readonly reasoning?: {
|
|
190
|
-
readonly effort?: import("../
|
|
190
|
+
readonly effort?: import("../public.js").ReasoningEffort | undefined;
|
|
191
191
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
192
192
|
} | undefined;
|
|
193
193
|
readonly text?: {
|
|
@@ -13,6 +13,6 @@ export const route = Route.make({
|
|
|
13
13
|
protocol: OpenResponses.protocol,
|
|
14
14
|
endpoint: Endpoint.path(OpenResponses.PATH),
|
|
15
15
|
transport: OpenResponses.httpTransport,
|
|
16
|
-
|
|
16
|
+
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
|
17
17
|
});
|
|
18
18
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { DecisionResponse, DecisionUsage } from "../decision.js";
|
|
2
|
+
import { DecisionResponse, DecisionUsage, } from "../decision.js";
|
|
3
3
|
import { DecisionRoute } from "../route/decision.js";
|
|
4
4
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
5
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
@@ -54,7 +54,20 @@ const fromRequest = Effect.fn("OpenAIDecisions.fromRequest")(function* (request)
|
|
|
54
54
|
}, request.http?.body),
|
|
55
55
|
model: request.model.id,
|
|
56
56
|
input: [{ role: "user", content: yield* Effect.forEach(request.input, (part) => inputPart(request, part)) }],
|
|
57
|
-
questions: request.questions
|
|
57
|
+
questions: request.questions.map((question) => {
|
|
58
|
+
if (question.type !== "predicate")
|
|
59
|
+
return question;
|
|
60
|
+
// Predicates have no criteria field, so what true and false mean is appended to the instructions.
|
|
61
|
+
const meanings = [
|
|
62
|
+
question.criteria?.true === undefined ? [] : [`True means: ${question.criteria.true}`],
|
|
63
|
+
question.criteria?.false === undefined ? [] : [`False means: ${question.criteria.false}`],
|
|
64
|
+
].flat();
|
|
65
|
+
return {
|
|
66
|
+
name: question.name,
|
|
67
|
+
type: question.type,
|
|
68
|
+
instructions: meanings.length === 0 ? question.instructions : `${question.instructions}\n\n${meanings.join("\n")}`,
|
|
69
|
+
};
|
|
70
|
+
}),
|
|
58
71
|
};
|
|
59
72
|
});
|
|
60
73
|
// `input_json` takes an object or a list of objects; other JSON values go as text.
|