@opencode/ai 2.2.5 → 2.2.6
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 +133 -69
- 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 +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- 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 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -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 +5 -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 +54 -173
- 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-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-video.d.ts +2 -2
- 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 +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -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 +1 -1
- 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 +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- 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 +3 -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 +5 -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.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -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/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -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 +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -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 +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -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 +5 -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 +5 -5
- package/dist/providers/moonshot.js +4 -16
- 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 +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -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 +5 -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 +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -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 +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -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/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 +9 -9
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
|
-
import { TranscriptionModel, type
|
|
4
|
+
import { TranscriptionModel, type TranscriptionRequest, type TranscriptionSegment } from "../transcription.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
6
6
|
export declare const PATH = "/audio/transcriptions";
|
|
7
7
|
export type OpenAITranscriptionOptions = {
|
|
@@ -17,7 +17,7 @@ export type OpenAITranscriptionOptions = {
|
|
|
17
17
|
readonly known_speaker_references?: ReadonlyArray<string>;
|
|
18
18
|
readonly temperature?: number;
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
|
-
export type Request =
|
|
20
|
+
export type Request = TranscriptionRequest<TranscriptionModel<OpenAITranscriptionOptions>>;
|
|
21
21
|
declare const Transcript: Schema.Struct<{
|
|
22
22
|
text: Schema.String;
|
|
23
23
|
language: Schema.optional<Schema.String>;
|
|
@@ -2,7 +2,7 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
import { VideoModel, VideoResponse, type
|
|
5
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.dev.runwayml.com/v1";
|
|
7
7
|
/** Every Runway request must pin the API version. */
|
|
8
8
|
export declare const API_VERSION = "2024-11-06";
|
|
@@ -21,7 +21,7 @@ export type RunwayVideoOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
readonly outputFormat?: OpenString<"mp4" | "prores" | "png_sequence">;
|
|
23
23
|
} & Record<string, unknown>;
|
|
24
|
-
export type Request =
|
|
24
|
+
export type Request = VideoRequest<VideoModel<RunwayVideoOptions>>;
|
|
25
25
|
export declare const Token: Schema.Struct<{
|
|
26
26
|
readonly taskID: Schema.String;
|
|
27
27
|
}>;
|
|
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool";
|
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
import { Headers, HttpClientRequest } from "effect/http";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
|
-
import { AIError, LLMRequest, Message, ToolDefinition, type ContentPart, type MediaPart, type OpenString, type ProviderID, type RequestEncoding, type ToolEntry, type ToolResultPart } from "../schema/index.js";
|
|
5
|
+
import { AIError, type LLMRequest, Message, ToolDefinition, type ContentPart, type MediaPart, type OpenString, type ProviderID, type RequestEncoding, type ToolEntry, type ToolResultPart } from "../schema/index.js";
|
|
6
6
|
import { Json, decodeJson, encodeJson } from "../utils/json.js";
|
|
7
7
|
import { isRecord } from "../utils/record.js";
|
|
8
8
|
export { Json, decodeJson, encodeJson, isRecord };
|
|
@@ -113,9 +113,6 @@ export declare const systemUpdateText: (route: string, message: Message) => Effe
|
|
|
113
113
|
readonly type: "text";
|
|
114
114
|
readonly text: string;
|
|
115
115
|
readonly cache?: import("../schema/options.js").CacheHint | undefined;
|
|
116
|
-
readonly metadata?: {
|
|
117
|
-
readonly [x: string]: unknown;
|
|
118
|
-
} | undefined;
|
|
119
116
|
readonly providerMetadata?: {
|
|
120
117
|
readonly [x: string]: {
|
|
121
118
|
readonly [x: string]: unknown;
|
package/dist/protocols/shared.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool";
|
|
|
2
2
|
import { Effect, Option, Predicate, Schema, SchemaGetter, SchemaTransformation } from "effect";
|
|
3
3
|
import { Headers, HttpClientRequest } from "effect/http";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
|
-
import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError,
|
|
5
|
+
import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, AssistantMessage, Message, ToolDefinition, ToolMessage, } from "../schema/index.js";
|
|
6
6
|
import { Json, decodeJson, encodeJson } from "../utils/json.js";
|
|
7
7
|
import { isRecord } from "../utils/record.js";
|
|
8
8
|
export { Json, decodeJson, encodeJson, isRecord };
|
|
@@ -46,7 +46,7 @@ export const knownString = () => Schema.declare((value) => typeof value === "str
|
|
|
46
46
|
export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
47
47
|
// Body-level `prompt_cache_key` is off when caching is disabled or the model
|
|
48
48
|
// explicitly rejects the field. Header-based affinity is unaffected.
|
|
49
|
-
export const sendsPromptCacheKey = (request) => request.cache !== "none" && request.model.
|
|
49
|
+
export const sendsPromptCacheKey = (request) => request.cache !== "none" && request.model.capabilities?.promptCacheKey !== false;
|
|
50
50
|
// OpenAI limits `prompt_cache_key` to 64 chars; DeepSeek and Zai inherit the same
|
|
51
51
|
// limit via their OpenAI-compatible APIs. Clamp with unicode-aware slicing.
|
|
52
52
|
export const promptCacheKey = (request) => {
|
|
@@ -260,22 +260,24 @@ export const flattenTools = (tools, path = []) => {
|
|
|
260
260
|
};
|
|
261
261
|
export const flattenToolRequest = (request) => {
|
|
262
262
|
const messages = request.messages.map((message) => {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
if (message.role === "assistant") {
|
|
264
|
+
const content = message.content.map((part) => part.type === "tool-call" || part.type === "tool-result" ? flattenToolName(part) : part);
|
|
265
|
+
return sameParts(content, message.content) ? message : new AssistantMessage({ ...message, content });
|
|
266
|
+
}
|
|
267
|
+
if (message.role !== "tool")
|
|
268
|
+
return message;
|
|
269
|
+
const content = message.content.map(flattenToolName);
|
|
270
|
+
return sameParts(content, message.content) ? message : new ToolMessage({ ...message, content });
|
|
271
271
|
});
|
|
272
272
|
return {
|
|
273
273
|
tools: flattenTools(request.tools),
|
|
274
274
|
request: messages.every((message, index) => message === request.messages[index])
|
|
275
275
|
? request
|
|
276
|
-
:
|
|
276
|
+
: { ...request, messages },
|
|
277
277
|
};
|
|
278
278
|
};
|
|
279
|
+
const flattenToolName = (part) => part.namespace === undefined ? part : { ...part, name: `${part.namespace}_${part.name}`, namespace: undefined };
|
|
280
|
+
const sameParts = (next, previous) => next.every((part, index) => part === previous[index]);
|
|
279
281
|
export const matchToolChoice = (route, toolChoice, cases) => Effect.gen(function* () {
|
|
280
282
|
if (toolChoice.type === "auto")
|
|
281
283
|
return cases.auto();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { DecisionResponse, type DecisionModelCompatibility, type
|
|
2
|
+
import { DecisionResponse, type DecisionModelCompatibility, type DecisionRequest } from "../decision.js";
|
|
3
3
|
import { DecisionRoute } from "../route/decision.js";
|
|
4
4
|
import { AIError } from "../schema/index.js";
|
|
5
5
|
export declare const DEFAULT_PATH = "/systemone";
|
|
@@ -33,7 +33,7 @@ export declare const Response: Schema.Struct<{
|
|
|
33
33
|
}>;
|
|
34
34
|
export type Response = Schema.Schema.Type<typeof Response>;
|
|
35
35
|
/** The System One body without `model`; media goes where the model's `mediaInput` says, else `fallback`. */
|
|
36
|
-
export declare const encodeBody: (request:
|
|
36
|
+
export declare const encodeBody: (request: DecisionRequest<import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>, import("../decision.js").DecisionQuestions>, fallback: MediaInput) => Effect.Effect<{
|
|
37
37
|
questions: any;
|
|
38
38
|
state: unknown;
|
|
39
39
|
assets?: undefined;
|
|
@@ -49,7 +49,7 @@ export declare const encodeBody: (request: DecisionRequestFor, fallback: MediaIn
|
|
|
49
49
|
};
|
|
50
50
|
}, AIError, never>;
|
|
51
51
|
/** Map System One's answers, keyed by question name, back to the request's question order. */
|
|
52
|
-
export declare const toResponse: (data: Response, request:
|
|
52
|
+
export declare const toResponse: (data: Response, request: DecisionRequest, providerMetadataKey: string, invalid: (message: string) => AIError) => Effect.Effect<never, AIError, never> | Effect.Effect<DecisionResponse, never, never>;
|
|
53
53
|
export declare const protocol: DecisionRoute.Protocol;
|
|
54
54
|
/** TypeSafe's API, the reference System One host; other hosts change the endpoint and auth with `route.with(...)`. */
|
|
55
55
|
export declare const route: DecisionRoute.Route;
|
|
@@ -79,7 +79,7 @@ export declare const SystemOne: {
|
|
|
79
79
|
readonly provider: Schema.optional<Schema.String>;
|
|
80
80
|
readonly provider_metadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
81
81
|
}>;
|
|
82
|
-
readonly encodeBody: (request:
|
|
82
|
+
readonly encodeBody: (request: DecisionRequest<import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>, import("../decision.js").DecisionQuestions>, fallback: MediaInput) => Effect.Effect<{
|
|
83
83
|
questions: any;
|
|
84
84
|
state: unknown;
|
|
85
85
|
assets?: undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { CacheTTL } from "../../schema/index.js";
|
|
3
|
-
import { newBreakpoints } from "./cache.js";
|
|
3
|
+
import { newBreakpoints, take } from "./cache.js";
|
|
4
4
|
// Bedrock cache markers are positional: emit a `cachePoint` block immediately
|
|
5
5
|
// after the content the caller wants treated as a cacheable prefix. Bedrock
|
|
6
6
|
// accepts an optional `ttl` such as "5m" or "1h" on cachePoint.
|
|
@@ -40,11 +40,8 @@ export const block = (breakpoints, cache) => {
|
|
|
40
40
|
return undefined;
|
|
41
41
|
if (cache?.type !== "ephemeral" && cache?.type !== "persistent")
|
|
42
42
|
return undefined;
|
|
43
|
-
if (breakpoints
|
|
44
|
-
breakpoints.dropped += 1;
|
|
43
|
+
if (!take(breakpoints))
|
|
45
44
|
return undefined;
|
|
46
|
-
}
|
|
47
|
-
breakpoints.remaining -= 1;
|
|
48
45
|
// Older Claude releases cache for five minutes only, so a one-hour request falls back to the default.
|
|
49
46
|
const ttl = cache.ttl === "1h" && !breakpoints.ttl1h ? undefined : cache.ttl;
|
|
50
47
|
return { cachePoint: { type: "default", ...(ttl === undefined ? {} : { ttl }) } };
|
|
@@ -27,9 +27,6 @@ export declare const lower: (part: {
|
|
|
27
27
|
readonly media: import("../../media.js").Asset;
|
|
28
28
|
readonly filename?: string | undefined;
|
|
29
29
|
readonly cache?: import("../../schema/options.js").CacheHint | undefined;
|
|
30
|
-
readonly metadata?: {
|
|
31
|
-
readonly [x: string]: unknown;
|
|
32
|
-
} | undefined;
|
|
33
30
|
readonly providerMetadata?: {
|
|
34
31
|
readonly [x: string]: {
|
|
35
32
|
readonly [x: string]: unknown;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import type { CacheHint, CacheTTL } from "../../schema/index.js";
|
|
2
3
|
export interface Breakpoints {
|
|
3
4
|
remaining: number;
|
|
4
5
|
dropped: number;
|
|
5
6
|
}
|
|
6
7
|
export declare const newBreakpoints: (cap: number) => Breakpoints;
|
|
8
|
+
export declare const take: (breakpoints: Breakpoints) => boolean;
|
|
9
|
+
export declare const warnDropped: (breakpoints: Breakpoints, protocol: string, cap: number) => Effect.Effect<void, never, never>;
|
|
7
10
|
export declare const cacheControl: () => (cache: CacheHint | undefined) => {
|
|
8
11
|
type: "ephemeral";
|
|
9
12
|
ttl: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
// Shared counter and lifetime mapping for provider cache lowering.
|
|
2
|
+
import { Effect } from "effect";
|
|
1
3
|
export const newBreakpoints = (cap) => ({ remaining: cap, dropped: 0 });
|
|
4
|
+
// Spends one breakpoint, or records it as dropped once the budget is gone.
|
|
5
|
+
export const take = (breakpoints) => {
|
|
6
|
+
if (breakpoints.remaining <= 0) {
|
|
7
|
+
breakpoints.dropped += 1;
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
breakpoints.remaining -= 1;
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
export const warnDropped = (breakpoints, protocol, cap) => breakpoints.dropped === 0
|
|
14
|
+
? Effect.void
|
|
15
|
+
: Effect.logWarning(`${protocol}: dropped ${breakpoints.dropped} cache breakpoint(s); the API allows at most ${cap} per request.`);
|
|
2
16
|
export const cacheControl = () => {
|
|
3
17
|
const breakpoints = newBreakpoints(4);
|
|
4
18
|
return (cache) => {
|
|
5
|
-
if (cache === undefined || breakpoints
|
|
19
|
+
if (cache === undefined || !take(breakpoints))
|
|
6
20
|
return undefined;
|
|
7
|
-
breakpoints.remaining -= 1;
|
|
8
21
|
return { type: "ephemeral", ttl: cache.ttl };
|
|
9
22
|
};
|
|
10
23
|
};
|
|
@@ -27,5 +27,5 @@ export declare const fit: (shape: Shape, limits: Limits) => Size;
|
|
|
27
27
|
/** The listed size closest to the shape: nearest aspect ratio first, then nearest pixel count. */
|
|
28
28
|
export declare const nearest: (shape: Shape, sizes: ReadonlyArray<Size>) => Size;
|
|
29
29
|
/** Free width and height that must honor the shape; a size that misses it fails. */
|
|
30
|
-
export declare const exact: (route: MediaProtocol.Identity, shape: Shape, limits: Limits) => Effect.Effect<undefined, never, never> | Effect.Effect<never, import("../../
|
|
30
|
+
export declare const exact: (route: MediaProtocol.Identity, shape: Shape, limits: Limits) => Effect.Effect<undefined, never, never> | Effect.Effect<never, import("../../public.js").AIError, never> | Effect.Effect<Size, never, never>;
|
|
31
31
|
export * as ImageSizing from "./image-sizing.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
2
|
import { Route } from "../../route/client.js";
|
|
3
3
|
import { Protocol } from "../../route/protocol.js";
|
|
4
|
-
import { CompactionCheckpointResponse, LLMEvent
|
|
4
|
+
import { CompactionCheckpointResponse, LLMEvent } from "../../schema/index.js";
|
|
5
5
|
import { OpenResponses } from "../open-responses.js";
|
|
6
6
|
import { ProviderShared } from "../shared.js";
|
|
7
7
|
const onOutputItem = Effect.fnUntraced(function* (state, input) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { AIError, LLMRequest } from "../../schema/index.js";
|
|
2
|
+
import { AIError, type LLMRequest } from "../../schema/index.js";
|
|
3
3
|
import type { CompactOperation } from "../../route/client.js";
|
|
4
4
|
import { OpenResponses } from "../open-responses.js";
|
|
5
5
|
export declare const make: (adapter: OpenResponses.ProviderAdapter, lowerTools: (request: LLMRequest) => Effect.Effect<ReadonlyArray<Record<string, unknown>>, AIError>) => CompactOperation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse,
|
|
2
|
+
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, Message, mergeJsonRecords, } from "../../schema/index.js";
|
|
3
3
|
import { stripEffortUpdates } from "../../effort-updates.js";
|
|
4
4
|
import { Endpoint } from "../../route/endpoint.js";
|
|
5
5
|
import { RequestExecutor } from "../../route/executor.js";
|
|
@@ -79,9 +79,10 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
79
79
|
const url = Endpoint.render(route.endpoint, { request, body: native });
|
|
80
80
|
url.pathname = `${url.pathname.replace(/\/$/, "")}/compact`;
|
|
81
81
|
const parts = yield* HttpTransport.jsonRequestParts({
|
|
82
|
-
request:
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
request: {
|
|
83
|
+
...request,
|
|
84
|
+
http: request.http === undefined ? undefined : { ...request.http, body: undefined },
|
|
85
|
+
},
|
|
85
86
|
body,
|
|
86
87
|
endpoint: Endpoint.path(url.toString()),
|
|
87
88
|
auth: route.auth,
|
|
@@ -92,7 +93,7 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
|
|
|
92
93
|
body: parts.bodyText,
|
|
93
94
|
headers: parts.headers,
|
|
94
95
|
encoding: request.http?.encoding,
|
|
95
|
-
}), options?.http);
|
|
96
|
+
}), RequestExecutor.withFetch(request.fetch, options?.http));
|
|
96
97
|
const text = yield* RequestExecutor.responseStream(response).pipe(Stream.decodeText(), Stream.runFold(() => "", (text, chunk) => text + chunk));
|
|
97
98
|
const invalid = (message, cause) => new AIError({
|
|
98
99
|
reason: new InvalidProviderOutputError({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { type AIError, type ToolResultPart } from "../../schema/index.js";
|
|
2
|
+
import { type AIError, type LLMRequest, type ToolResultPart } from "../../schema/index.js";
|
|
3
3
|
import { OpenResponses } from "../open-responses.js";
|
|
4
4
|
export type Item = OpenResponses.OutputItem & {
|
|
5
5
|
readonly status?: string;
|
|
@@ -21,6 +21,102 @@ export interface Definition {
|
|
|
21
21
|
readonly result?: (item: Item) => Effect.Effect<ToolResultPart["result"], AIError>;
|
|
22
22
|
}
|
|
23
23
|
export type Definitions = Readonly<Record<string, Definition>>;
|
|
24
|
+
/** Hosted tools that several Responses providers report with the same item shape. */
|
|
25
|
+
export declare const common: {
|
|
26
|
+
readonly web_search_call: {
|
|
27
|
+
readonly name: "web_search";
|
|
28
|
+
readonly input: (item: Item) => {};
|
|
29
|
+
};
|
|
30
|
+
readonly file_search_call: {
|
|
31
|
+
readonly name: "file_search";
|
|
32
|
+
readonly input: (item: Item) => {
|
|
33
|
+
queries: {};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly code_interpreter_call: {
|
|
37
|
+
readonly name: "code_interpreter";
|
|
38
|
+
readonly input: (item: Item) => {
|
|
39
|
+
code: string | undefined;
|
|
40
|
+
container_id: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly mcp_call: {
|
|
44
|
+
readonly name: "mcp";
|
|
45
|
+
readonly input: (item: Item) => {
|
|
46
|
+
server_label: string | undefined;
|
|
47
|
+
name: string | undefined;
|
|
48
|
+
arguments: string | undefined;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
24
52
|
export declare const isItem: <Tools extends Definitions>(item: OpenResponses.OutputItem, tools: Tools) => item is Item;
|
|
53
|
+
/**
|
|
54
|
+
* Responses stream that turns completed hosted tool items into a provider-executed
|
|
55
|
+
* tool call and result. `override` sees each normalized event first and may handle it.
|
|
56
|
+
*/
|
|
57
|
+
export declare const stream: (adapter: OpenResponses.ProviderAdapter, tools: Definitions, override?: (state: OpenResponses.ParserState, event: OpenResponses.NormalizedEvent) => Effect.Effect<OpenResponses.StepResult, AIError> | undefined) => {
|
|
58
|
+
event: import("effect/Schema").Codec<{
|
|
59
|
+
readonly [x: string]: unknown;
|
|
60
|
+
readonly type: string;
|
|
61
|
+
readonly delta?: string | undefined;
|
|
62
|
+
readonly arguments?: string | undefined;
|
|
63
|
+
readonly text?: string | undefined;
|
|
64
|
+
readonly item_id?: string | undefined;
|
|
65
|
+
readonly output_index?: number | undefined;
|
|
66
|
+
readonly summary_index?: number | undefined;
|
|
67
|
+
readonly item?: {
|
|
68
|
+
readonly [x: string]: unknown;
|
|
69
|
+
readonly type: string;
|
|
70
|
+
readonly id?: string | undefined;
|
|
71
|
+
readonly call_id?: string | undefined;
|
|
72
|
+
readonly name?: string | undefined;
|
|
73
|
+
readonly namespace?: string | undefined;
|
|
74
|
+
readonly arguments?: string | undefined;
|
|
75
|
+
readonly encrypted_content?: string | null | undefined;
|
|
76
|
+
} | null | undefined;
|
|
77
|
+
readonly response?: {
|
|
78
|
+
readonly [x: string]: unknown;
|
|
79
|
+
readonly id?: string | undefined;
|
|
80
|
+
readonly service_tier?: string | null | undefined;
|
|
81
|
+
readonly incomplete_details?: {
|
|
82
|
+
readonly reason?: string | undefined;
|
|
83
|
+
} | null | undefined;
|
|
84
|
+
readonly output?: readonly {
|
|
85
|
+
readonly [x: string]: unknown;
|
|
86
|
+
readonly type: string;
|
|
87
|
+
readonly id?: string | undefined;
|
|
88
|
+
readonly call_id?: string | undefined;
|
|
89
|
+
readonly name?: string | undefined;
|
|
90
|
+
readonly namespace?: string | undefined;
|
|
91
|
+
readonly arguments?: string | undefined;
|
|
92
|
+
readonly encrypted_content?: string | null | undefined;
|
|
93
|
+
}[] | undefined;
|
|
94
|
+
readonly usage?: {
|
|
95
|
+
readonly [x: string]: unknown;
|
|
96
|
+
readonly input_tokens?: number | undefined;
|
|
97
|
+
readonly input_tokens_details?: {
|
|
98
|
+
readonly [x: string]: unknown;
|
|
99
|
+
readonly cached_tokens?: number | undefined;
|
|
100
|
+
readonly cache_write_tokens?: number | undefined;
|
|
101
|
+
} | null | undefined;
|
|
102
|
+
readonly output_tokens?: number | undefined;
|
|
103
|
+
readonly output_tokens_details?: {
|
|
104
|
+
readonly [x: string]: unknown;
|
|
105
|
+
readonly reasoning_tokens?: number | undefined;
|
|
106
|
+
} | null | undefined;
|
|
107
|
+
readonly total_tokens?: number | undefined;
|
|
108
|
+
} | null | undefined;
|
|
109
|
+
readonly error?: unknown;
|
|
110
|
+
} | undefined;
|
|
111
|
+
readonly code?: unknown;
|
|
112
|
+
readonly message?: unknown;
|
|
113
|
+
readonly error?: unknown;
|
|
114
|
+
readonly status?: unknown;
|
|
115
|
+
readonly status_code?: unknown;
|
|
116
|
+
}, string, never, never>;
|
|
117
|
+
initial: (request: LLMRequest) => OpenResponses.ParserState;
|
|
118
|
+
step: (state: OpenResponses.ParserState, input: OpenResponses.Event) => AIError | Effect.Effect<OpenResponses.StepResult, AIError, never>;
|
|
119
|
+
terminal: typeof OpenResponses.terminal;
|
|
120
|
+
};
|
|
25
121
|
export declare const onDone: (state: OpenResponses.ParserState, item: Item, tools: Definitions) => Effect.Effect<OpenResponses.StepResult, AIError>;
|
|
26
122
|
export * as ResponsesHostedTools from "./responses-hosted-tools.js";
|
|
@@ -2,7 +2,38 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { LLMEvent } from "../../schema/index.js";
|
|
3
3
|
import { OpenResponses } from "../open-responses.js";
|
|
4
4
|
import { Lifecycle } from "./lifecycle.js";
|
|
5
|
+
/** Hosted tools that several Responses providers report with the same item shape. */
|
|
6
|
+
export const common = {
|
|
7
|
+
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
8
|
+
file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
|
|
9
|
+
code_interpreter_call: {
|
|
10
|
+
name: "code_interpreter",
|
|
11
|
+
input: (item) => ({ code: item.code, container_id: item.container_id }),
|
|
12
|
+
},
|
|
13
|
+
mcp_call: {
|
|
14
|
+
name: "mcp",
|
|
15
|
+
input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
5
18
|
export const isItem = (item, tools) => item.type in tools;
|
|
19
|
+
/**
|
|
20
|
+
* Responses stream that turns completed hosted tool items into a provider-executed
|
|
21
|
+
* tool call and result. `override` sees each normalized event first and may handle it.
|
|
22
|
+
*/
|
|
23
|
+
export const stream = (adapter, tools, override) => ({
|
|
24
|
+
event: OpenResponses.protocol.stream.event,
|
|
25
|
+
initial: (request) => OpenResponses.initial(request, adapter),
|
|
26
|
+
step: (state, input) => {
|
|
27
|
+
const event = OpenResponses.normalize(state, input);
|
|
28
|
+
const handled = override?.(state, event);
|
|
29
|
+
if (handled)
|
|
30
|
+
return handled;
|
|
31
|
+
if (event.type === "response.output_item.done" && event.item && isItem(event.item, tools))
|
|
32
|
+
return onDone(state, event.item, tools);
|
|
33
|
+
return OpenResponses.step(state, event);
|
|
34
|
+
},
|
|
35
|
+
terminal: OpenResponses.terminal,
|
|
36
|
+
});
|
|
6
37
|
export const onDone = Effect.fnUntraced(function* (state, item, tools) {
|
|
7
38
|
const tool = tools[item.type];
|
|
8
39
|
if (!tool)
|