@opencode/ai 2.1.4 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +339 -166
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +50 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1444 -34
- package/dist/index.js +139 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +3 -1
- package/dist/media-client.js +1 -0
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +59 -4
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +26 -6
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +10 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +46 -6
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +212 -27
- package/dist/protocols/open-responses.js +116 -54
- package/dist/protocols/openai-chat.d.ts +1135 -31
- package/dist/protocols/openai-chat.js +155 -60
- package/dist/protocols/openai-compatible-chat.d.ts +57 -5
- package/dist/protocols/openai-compatible-responses.d.ts +28 -8
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +36 -24
- package/dist/protocols/openai-images.js +137 -39
- package/dist/protocols/openai-responses.d.ts +202 -42
- package/dist/protocols/openai-responses.js +49 -10
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +58 -4
- package/dist/protocols/venice-chat.js +2 -2
- package/dist/protocols/xai-images.d.ts +7 -2
- package/dist/protocols/xai-images.js +11 -5
- package/dist/protocols/xai-responses.d.ts +30 -3
- package/dist/protocols/xai-responses.js +30 -3
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +60 -4
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +23 -7
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +137 -28
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +259 -145
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +53 -18
- package/dist/providers/anthropic.d.ts +53 -18
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +129 -24
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +124 -12
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +115 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +290 -60
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +128 -12
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +115 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +115 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +115 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +390 -20
- package/dist/providers/digitalocean.js +53 -11
- package/dist/providers/fireworks.d.ts +115 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +57 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +53 -18
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +24 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +4 -2
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +6 -5
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +119 -15
- package/dist/providers/groq.js +1 -7
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +254 -146
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +139 -26
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +132 -25
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +24 -4
- package/dist/providers/openai-compatible.d.ts +62 -8
- package/dist/providers/openai-compatible.js +29 -10
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +103 -18
- package/dist/providers/openai.js +23 -5
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +11 -12
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +446 -35
- package/dist/providers/openrouter.js +78 -27
- package/dist/providers/togetherai.d.ts +115 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +11 -12
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +261 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +16 -22
- package/dist/providers/vercel-ai-gateway.js +41 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +66 -12
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +132 -25
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +62 -9
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +3 -4
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +6 -2
- package/dist/route/media.js +8 -6
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +41 -3
- package/dist/schema/messages.js +23 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +53 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +35 -45
- package/dist/testing.js +14 -75
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +69 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +46 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +497 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/protocols/bfl-images.d.ts +0 -38
- package/dist/protocols/bfl-images.js +0 -153
- package/dist/protocols/fal-images.d.ts +0 -25
- package/dist/protocols/fal-images.js +0 -104
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -39
- package/dist/protocols/stability-images.js +0 -136
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
3
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { SystemOne } from "./system-one.js";
|
|
6
|
+
const ID = "cloudflare-run-decisions";
|
|
7
|
+
const NAME = "Cloudflare Run";
|
|
8
|
+
// Workers AI models answer with the System One response; third-party models such as TypeSafe Jev wrap it in a
|
|
9
|
+
// completed run record.
|
|
10
|
+
const Envelope = Schema.Struct({
|
|
11
|
+
result: Schema.Union([
|
|
12
|
+
SystemOne.Response,
|
|
13
|
+
Schema.Struct({ state: Schema.Literal("Completed"), result: SystemOne.Response }),
|
|
14
|
+
]),
|
|
15
|
+
});
|
|
16
|
+
const decodeEnvelope = MediaProtocol.identity({ id: ID, name: NAME, provider: "cloudflare-workers-ai" }).decodeJson(Envelope);
|
|
17
|
+
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One body as `input`; media defaults to Clef's top-level lists. */
|
|
18
|
+
export const protocol = DecisionRoute.protocol({
|
|
19
|
+
id: ID,
|
|
20
|
+
name: NAME,
|
|
21
|
+
inlineMedia: true,
|
|
22
|
+
body: {
|
|
23
|
+
from: (request) => SystemOne.encodeBody(request, "root").pipe(Effect.map((input) => ({ model: request.model.id, input }))),
|
|
24
|
+
},
|
|
25
|
+
response: {
|
|
26
|
+
decode: (response, context) => decodeEnvelope(response).pipe(Effect.flatMap((output) => SystemOne.toResponse("answers" in output.value.result ? output.value.result : output.value.result.result, context.request, context.providerMetadataKey, output.invalid))),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
/** Providers set the Run API base, `.../client/v4/accounts/{account}/ai/run`, with `route.with(...)`. */
|
|
30
|
+
export const route = DecisionRoute.make({
|
|
31
|
+
id: ID,
|
|
32
|
+
provider: "cloudflare-workers-ai",
|
|
33
|
+
protocol,
|
|
34
|
+
endpoint: Endpoint.path(""),
|
|
35
|
+
});
|
|
36
|
+
export const CloudflareRunDecisions = { protocol, route };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import type { MediaRoute } from "../route/media.js";
|
|
4
|
+
/**
|
|
5
|
+
* Native Run API inputs. Step counts are `steps` on FLUX and Lucid Origin and `num_steps` on the other models;
|
|
6
|
+
* `aspect` and `resolution` lower to `width` and `height`.
|
|
7
|
+
*/
|
|
8
|
+
export type CloudflareWorkersAIImageOptions = {
|
|
9
|
+
readonly width?: number;
|
|
10
|
+
readonly height?: number;
|
|
11
|
+
readonly seed?: number;
|
|
12
|
+
readonly steps?: number;
|
|
13
|
+
readonly num_steps?: number;
|
|
14
|
+
readonly guidance?: number;
|
|
15
|
+
readonly negative_prompt?: string;
|
|
16
|
+
} & Record<string, unknown>;
|
|
17
|
+
export type Request = ImageRequestFor<CloudflareWorkersAIImageOptions>;
|
|
18
|
+
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
19
|
+
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<CloudflareWorkersAIImageOptions>;
|
|
20
|
+
export declare const CloudflareWorkersAIImages: {
|
|
21
|
+
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
22
|
+
readonly model: typeof model;
|
|
23
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
+
import { Media } from "../media.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
8
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
9
|
+
const route = MediaProtocol.identity({
|
|
10
|
+
id: "cloudflare-workers-ai-images",
|
|
11
|
+
name: "Cloudflare Workers AI",
|
|
12
|
+
provider: "cloudflare-workers-ai",
|
|
13
|
+
});
|
|
14
|
+
/** FLUX.2 models only accept multipart form fields, even for a prompt alone. */
|
|
15
|
+
const MULTIPART_MODEL_PREFIX = "@cf/black-forest-labs/flux-2-";
|
|
16
|
+
const RESERVED_FORM_FIELDS = new Set(["prompt"]);
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// 2. Response schema
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
const RunResponse = Schema.Struct({
|
|
21
|
+
result: Schema.Struct({
|
|
22
|
+
image: Schema.optional(Schema.String),
|
|
23
|
+
usage: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// 5. Request body construction
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
const fromRequest = Effect.fn("CloudflareWorkersAIImages.fromRequest")(function* (request) {
|
|
30
|
+
if (request.n !== undefined && request.n > 1)
|
|
31
|
+
return yield* route.unsupported("media.n", `${route.name} generates one image per request; call it once per image`);
|
|
32
|
+
const fields = {
|
|
33
|
+
prompt: request.prompt,
|
|
34
|
+
...(yield* ImageSizing.exact(route, request, { multiple: 16, minEdge: 256, maxEdge: 2048 })),
|
|
35
|
+
};
|
|
36
|
+
const native = mergeJsonRecords(request.providerOptions, request.http?.body);
|
|
37
|
+
const images = request.images ?? [];
|
|
38
|
+
if (!request.model.id.startsWith(MULTIPART_MODEL_PREFIX)) {
|
|
39
|
+
if (images.length > 1)
|
|
40
|
+
return yield* route.unsupported("media.images", `${request.model.id} takes one input image as image_b64`);
|
|
41
|
+
const image = images[0]?.inline();
|
|
42
|
+
if (images[0] !== undefined && image === undefined)
|
|
43
|
+
return yield* ProviderShared.inlineRequired(route.id, images[0]);
|
|
44
|
+
return MediaProtocol.json(mergeJsonRecords({ ...fields, image_b64: image?.base64 }, native) ?? {});
|
|
45
|
+
}
|
|
46
|
+
const body = new FormData();
|
|
47
|
+
MediaInput.appendFields(body, fields, { overlay: native, reserved: RESERVED_FORM_FIELDS });
|
|
48
|
+
yield* Effect.forEach(images, (image, index) => MediaInput.inlineBytes(route.id, image).pipe(Effect.map((bytes) => body.append(`input_image_${index}`, MediaInput.blob(bytes, image.mediaType), `image_${index}`))));
|
|
49
|
+
return MediaProtocol.multipart(body);
|
|
50
|
+
});
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// 6. Response decoding
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
const decodeDocument = route.decodeJson(RunResponse);
|
|
55
|
+
// FLUX and Lucid Origin wrap base64 in the Run API envelope; the Stable Diffusion family, DreamShaper, and Phoenix
|
|
56
|
+
// answer with the raw image, whose declared content type does not always match the bytes.
|
|
57
|
+
const decodeResponse = Effect.fn("CloudflareWorkersAIImages.decodeResponse")(function* (response) {
|
|
58
|
+
if (!response.headers["content-type"]?.startsWith("application/json"))
|
|
59
|
+
return new ImageResponse({ images: [Media.bytes(yield* route.bytes(response))] });
|
|
60
|
+
const output = yield* decodeDocument(response);
|
|
61
|
+
const result = output.value.result;
|
|
62
|
+
if (result.image === undefined)
|
|
63
|
+
return yield* output.invalid(`${route.name} returned no image`);
|
|
64
|
+
return new ImageResponse({
|
|
65
|
+
images: [yield* MediaInput.decodedAsset(output.invalid, `${route.name} result`, result.image, undefined)],
|
|
66
|
+
providerMetadata: result.usage === undefined ? undefined : { "cloudflare-workers-ai": { usage: result.usage } },
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// 7. Protocol and route
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
73
|
+
body: { from: fromRequest },
|
|
74
|
+
response: { decode: decodeResponse },
|
|
75
|
+
});
|
|
76
|
+
export const model = (input) => ImageModel.fromRoute({ protocol, path: ({ request }) => `/${request.model.id}` }, input);
|
|
77
|
+
export const CloudflareWorkersAIImages = {
|
|
78
|
+
protocol,
|
|
79
|
+
model,
|
|
80
|
+
};
|
|
@@ -57,15 +57,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
57
57
|
readonly [x: string]: unknown;
|
|
58
58
|
} | undefined;
|
|
59
59
|
} | undefined;
|
|
60
|
-
readonly notices?: readonly {
|
|
61
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
62
|
-
readonly message: string;
|
|
63
|
-
readonly providerMetadata?: {
|
|
64
|
-
readonly [x: string]: {
|
|
65
|
-
readonly [x: string]: unknown;
|
|
66
|
-
};
|
|
67
|
-
} | undefined;
|
|
68
|
-
}[] | undefined;
|
|
69
60
|
readonly providerMetadata?: {
|
|
70
61
|
readonly [x: string]: {
|
|
71
62
|
readonly [x: string]: unknown;
|
|
@@ -116,15 +107,6 @@ export declare const DeepgramSpeech: {
|
|
|
116
107
|
readonly [x: string]: unknown;
|
|
117
108
|
} | undefined;
|
|
118
109
|
} | undefined;
|
|
119
|
-
readonly notices?: readonly {
|
|
120
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
121
|
-
readonly message: string;
|
|
122
|
-
readonly providerMetadata?: {
|
|
123
|
-
readonly [x: string]: {
|
|
124
|
-
readonly [x: string]: unknown;
|
|
125
|
-
};
|
|
126
|
-
} | undefined;
|
|
127
|
-
}[] | undefined;
|
|
128
110
|
readonly providerMetadata?: {
|
|
129
111
|
readonly [x: string]: {
|
|
130
112
|
readonly [x: string]: unknown;
|
|
@@ -60,15 +60,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
60
60
|
readonly [x: string]: unknown;
|
|
61
61
|
} | undefined;
|
|
62
62
|
} | undefined;
|
|
63
|
-
readonly notices?: readonly {
|
|
64
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
65
|
-
readonly message: string;
|
|
66
|
-
readonly providerMetadata?: {
|
|
67
|
-
readonly [x: string]: {
|
|
68
|
-
readonly [x: string]: unknown;
|
|
69
|
-
};
|
|
70
|
-
} | undefined;
|
|
71
|
-
}[] | undefined;
|
|
72
63
|
readonly providerMetadata?: {
|
|
73
64
|
readonly [x: string]: {
|
|
74
65
|
readonly [x: string]: unknown;
|
|
@@ -119,15 +110,6 @@ export declare const ElevenLabsSpeech: {
|
|
|
119
110
|
readonly [x: string]: unknown;
|
|
120
111
|
} | undefined;
|
|
121
112
|
} | undefined;
|
|
122
|
-
readonly notices?: readonly {
|
|
123
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
124
|
-
readonly message: string;
|
|
125
|
-
readonly providerMetadata?: {
|
|
126
|
-
readonly [x: string]: {
|
|
127
|
-
readonly [x: string]: unknown;
|
|
128
|
-
};
|
|
129
|
-
} | undefined;
|
|
130
|
-
}[] | undefined;
|
|
131
113
|
readonly providerMetadata?: {
|
|
132
114
|
readonly [x: string]: {
|
|
133
115
|
readonly [x: string]: unknown;
|
|
@@ -105,6 +105,7 @@ declare const GeminiBody: Schema.Struct<{
|
|
|
105
105
|
}>;
|
|
106
106
|
export type GeminiBody = Schema.Schema.Type<typeof GeminiBody>;
|
|
107
107
|
declare const GeminiUsage: Schema.Struct<{
|
|
108
|
+
readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
|
|
108
109
|
readonly cachedContentTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
109
110
|
readonly thoughtsTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
110
111
|
readonly promptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
@@ -259,6 +260,7 @@ export declare const protocol: Protocol<{
|
|
|
259
260
|
readonly safetyRatings?: unknown;
|
|
260
261
|
} | null | undefined;
|
|
261
262
|
readonly usageMetadata?: {
|
|
263
|
+
readonly cost?: number | undefined;
|
|
262
264
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
263
265
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
264
266
|
readonly promptTokenCount?: number | null | undefined;
|
|
@@ -286,6 +288,7 @@ export declare const protocol: Protocol<{
|
|
|
286
288
|
readonly safetyRatings?: unknown;
|
|
287
289
|
} | null | undefined;
|
|
288
290
|
readonly usageMetadata?: {
|
|
291
|
+
readonly cost?: number | undefined;
|
|
289
292
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
290
293
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
291
294
|
readonly promptTokenCount?: number | null | undefined;
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -59,7 +59,6 @@ const GeminiInlineDataPart = Schema.Struct({
|
|
|
59
59
|
}),
|
|
60
60
|
thoughtSignature: optionalNull(Schema.String),
|
|
61
61
|
});
|
|
62
|
-
/** Gemini Files API reference; the only remote input Gemini accepts. */
|
|
63
62
|
const GeminiFileDataPart = Schema.Struct({
|
|
64
63
|
fileData: Schema.Struct({
|
|
65
64
|
mimeType: Schema.String,
|
|
@@ -172,6 +171,7 @@ const GeminiUsage = Schema.Struct({
|
|
|
172
171
|
promptTokenCount: optionalNull(Schema.Number),
|
|
173
172
|
candidatesTokenCount: optionalNull(Schema.Number),
|
|
174
173
|
totalTokenCount: optionalNull(Schema.Number),
|
|
174
|
+
...ProviderShared.ReportedBilling.fields,
|
|
175
175
|
});
|
|
176
176
|
const GeminiCandidate = Schema.Struct({
|
|
177
177
|
content: optionalNull(GeminiResponseContent),
|
|
@@ -329,11 +329,13 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
329
329
|
for (const item of content) {
|
|
330
330
|
if (item.type === "text")
|
|
331
331
|
continue;
|
|
332
|
-
const value = yield*
|
|
333
|
-
|
|
332
|
+
const value = yield* GeminiGenerateContent.mediaPart("Gemini", GeminiGenerateContent.toolMedia(item));
|
|
333
|
+
// Nested fileData can be accepted without the model seeing the video, even on newer Gemini models.
|
|
334
|
+
if (legacyToolMedia || "fileData" in value)
|
|
335
|
+
(pendingMedia ??= []).push(value);
|
|
336
|
+
else
|
|
337
|
+
media.push(value);
|
|
334
338
|
}
|
|
335
|
-
if (legacyToolMedia && media.length > 0)
|
|
336
|
-
(pendingMedia ??= []).push(...media);
|
|
337
339
|
parts.push({
|
|
338
340
|
functionResponse: {
|
|
339
341
|
...(omitCallIds ? {} : { id: part.id }),
|
|
@@ -342,7 +344,7 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
342
344
|
name: part.name,
|
|
343
345
|
content: text.join("\n"),
|
|
344
346
|
},
|
|
345
|
-
parts:
|
|
347
|
+
parts: media.length === 0 ? undefined : media,
|
|
346
348
|
},
|
|
347
349
|
});
|
|
348
350
|
}
|
|
@@ -430,6 +432,7 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
|
430
432
|
cacheReadInputTokens: cached,
|
|
431
433
|
reasoningTokens: thoughts,
|
|
432
434
|
totalTokens: ProviderShared.totalTokens(promptTokens, outputTokens, usage.totalTokenCount ?? undefined),
|
|
435
|
+
cost: usage.cost,
|
|
433
436
|
providerMetadata: providerMetadata(metadataKey, metadata),
|
|
434
437
|
});
|
|
435
438
|
};
|
|
@@ -443,6 +446,8 @@ const mapContinuedUsage = (requests, metadataKey) => {
|
|
|
443
446
|
cachedContentTokenCount: requests[0].cachedContentTokenCount,
|
|
444
447
|
candidatesTokenCount: sum("candidatesTokenCount"),
|
|
445
448
|
thoughtsTokenCount: sum("thoughtsTokenCount"),
|
|
449
|
+
// Every continued request is billed on its own.
|
|
450
|
+
cost: sum("cost"),
|
|
446
451
|
}, metadataKey, {
|
|
447
452
|
promptTokenCount: sum("promptTokenCount"),
|
|
448
453
|
cachedContentTokenCount: sum("cachedContentTokenCount"),
|
|
@@ -3,9 +3,9 @@ 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
5
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
6
|
-
/** Provider-native
|
|
6
|
+
/** Provider-native `generationConfig` fields. Common fields (`aspect`, `resolution`, `images`) live on the request. */
|
|
7
7
|
export type GoogleImageOptions = {
|
|
8
|
-
readonly
|
|
8
|
+
readonly seed?: number;
|
|
9
9
|
readonly thinkingLevel?: OpenString<"MINIMAL" | "LOW" | "MEDIUM" | "HIGH">;
|
|
10
10
|
readonly includeThoughts?: boolean;
|
|
11
11
|
} & Record<string, unknown>;
|
|
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
3
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
4
|
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
5
|
+
import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
|
|
6
6
|
import { ProviderShared } from "./shared.js";
|
|
7
7
|
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
8
8
|
import { MediaInput } from "./utils/media-input.js";
|
|
@@ -49,13 +49,14 @@ const GoogleImageResponse = Schema.Struct({
|
|
|
49
49
|
// 5. Request body construction
|
|
50
50
|
// ---------------------------------------------------------------------------
|
|
51
51
|
const generationConfig = (request) => {
|
|
52
|
-
const {
|
|
53
|
-
|
|
52
|
+
const { thinkingLevel, includeThoughts, ...native } = request.providerOptions ?? {};
|
|
53
|
+
// Google names the half tier `512` and rejects `0.5K`.
|
|
54
|
+
const imageSize = request.resolution?.toUpperCase() === "0.5K" ? "512" : request.resolution?.toUpperCase();
|
|
55
|
+
const imageConfig = { aspectRatio: request.aspect, imageSize };
|
|
54
56
|
const thinkingConfig = { thinkingLevel, includeThoughts };
|
|
55
57
|
return (mergeJsonRecords({
|
|
56
58
|
responseModalities: ["IMAGE"],
|
|
57
59
|
imageConfig: Object.values(imageConfig).some((value) => value !== undefined) ? imageConfig : undefined,
|
|
58
|
-
seed: request.seed,
|
|
59
60
|
thinkingConfig: Object.values(thinkingConfig).some((value) => value !== undefined) ? thinkingConfig : undefined,
|
|
60
61
|
}, native) ?? { responseModalities: ["IMAGE"] });
|
|
61
62
|
};
|
|
@@ -119,45 +120,18 @@ const decodeResponse = Effect.fn("GoogleImages.decodeResponse")(function* (respo
|
|
|
119
120
|
}));
|
|
120
121
|
if (images.length === 0) {
|
|
121
122
|
const finishReasons = candidates.flatMap((candidate) => candidate.finishReason === undefined ? [] : [candidate.finishReason]);
|
|
123
|
+
// Safety and recitation stops are Google refusing the prompt, not a malformed response.
|
|
124
|
+
if (finishReasons.some(GeminiGenerateContent.contentFiltered))
|
|
125
|
+
return yield* output.contentPolicy(`${route.name} withheld its images (finish reasons: ${finishReasons.join(", ")})`);
|
|
122
126
|
return yield* output.invalid(`${route.name} returned no final images${finishReasons.length === 0 ? "" : ` (finish reasons: ${finishReasons.join(", ")})`}; inspect body for prompt feedback and candidate details`);
|
|
123
127
|
}
|
|
124
|
-
// Candidates that stopped for a safety or policy reason are partial results, not a silent drop.
|
|
125
|
-
const notices = [
|
|
126
|
-
...(decoded.promptFeedback === undefined
|
|
127
|
-
? []
|
|
128
|
-
: [
|
|
129
|
-
{
|
|
130
|
-
type: "filtered",
|
|
131
|
-
message: `${route.name} reported prompt feedback`,
|
|
132
|
-
providerMetadata: { google: { promptFeedback: decoded.promptFeedback } },
|
|
133
|
-
},
|
|
134
|
-
]),
|
|
135
|
-
...candidates.flatMap((candidate, index) => candidate.finishReason === undefined || candidate.finishReason === "STOP"
|
|
136
|
-
? []
|
|
137
|
-
: [
|
|
138
|
-
{
|
|
139
|
-
type: "filtered",
|
|
140
|
-
message: `${route.name} candidate ${candidate.index ?? index} finished with ${candidate.finishReason}${candidate.finishMessage === undefined ? "" : `: ${candidate.finishMessage}`}`,
|
|
141
|
-
providerMetadata: {
|
|
142
|
-
google: {
|
|
143
|
-
candidateIndex: candidate.index ?? index,
|
|
144
|
-
finishReason: candidate.finishReason,
|
|
145
|
-
finishMessage: candidate.finishMessage,
|
|
146
|
-
safetyRatings: candidate.safetyRatings,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
]),
|
|
151
|
-
];
|
|
152
128
|
const usage = decoded.usageMetadata;
|
|
153
129
|
const outputTokens = usage?.candidatesTokenCount === undefined ? undefined : usage.candidatesTokenCount + (usage.thoughtsTokenCount ?? 0);
|
|
154
130
|
return new ImageResponse({
|
|
155
131
|
images,
|
|
156
|
-
notices: notices.length === 0 ? undefined : notices,
|
|
157
132
|
usage: usage === undefined
|
|
158
133
|
? undefined
|
|
159
|
-
: {
|
|
160
|
-
type: "tokens",
|
|
134
|
+
: tokenUsage({
|
|
161
135
|
input: usage.promptTokenCount,
|
|
162
136
|
output: outputTokens,
|
|
163
137
|
total: ProviderShared.totalTokens(usage.promptTokenCount, outputTokens, usage.totalTokenCount),
|
|
@@ -166,7 +140,7 @@ const decodeResponse = Effect.fn("GoogleImages.decodeResponse")(function* (respo
|
|
|
166
140
|
cacheReadInputTokens: usage.cachedContentTokenCount,
|
|
167
141
|
google: usage,
|
|
168
142
|
},
|
|
169
|
-
},
|
|
143
|
+
}),
|
|
170
144
|
providerMetadata: {
|
|
171
145
|
google: {
|
|
172
146
|
modelVersion: decoded.modelVersion,
|
|
@@ -181,7 +155,6 @@ const decodeResponse = Effect.fn("GoogleImages.decodeResponse")(function* (respo
|
|
|
181
155
|
// 7. Protocol and route
|
|
182
156
|
// ---------------------------------------------------------------------------
|
|
183
157
|
export const protocol = MediaProtocol.inline(route, {
|
|
184
|
-
unsupported: ["mask", "size", "format"],
|
|
185
158
|
body: { from: fromRequest },
|
|
186
159
|
response: { decode: decodeResponse },
|
|
187
160
|
});
|
|
@@ -165,6 +165,10 @@ export declare const protocol: Protocol<{
|
|
|
165
165
|
readonly total_tokens?: number | null | undefined;
|
|
166
166
|
readonly raw_prompt_token?: number | null | undefined;
|
|
167
167
|
} | undefined;
|
|
168
|
+
readonly errors?: readonly {
|
|
169
|
+
readonly code?: string | undefined;
|
|
170
|
+
readonly message?: string | undefined;
|
|
171
|
+
}[] | undefined;
|
|
168
172
|
};
|
|
169
173
|
} | {
|
|
170
174
|
readonly event_type: "error";
|
|
@@ -11,6 +11,7 @@ import { encodeJson } from "../utils/json.js";
|
|
|
11
11
|
import { JsonObject, knownString, lenient, optionalNull, ProviderShared } from "./shared.js";
|
|
12
12
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
13
13
|
import { MediaInput } from "./utils/media-input.js";
|
|
14
|
+
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
14
15
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
15
16
|
const ADAPTER = "google-interactions";
|
|
16
17
|
export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
@@ -127,6 +128,7 @@ const Interaction = Schema.StructWithRest(Schema.Struct({
|
|
|
127
128
|
id: Schema.optional(Schema.String),
|
|
128
129
|
status: Schema.String,
|
|
129
130
|
usage: Schema.optional(RawUsage),
|
|
131
|
+
errors: Schema.optional(Schema.Array(Schema.Struct({ code: Schema.optional(Schema.String), message: Schema.optional(Schema.String) }))),
|
|
130
132
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
131
133
|
const KNOWN_EVENT_TYPES = new Set([
|
|
132
134
|
"step.start",
|
|
@@ -172,7 +174,9 @@ const mediaContent = Effect.fnUntraced(function* (asset) {
|
|
|
172
174
|
asset.mediaType !== "text/csv")
|
|
173
175
|
return yield* ProviderShared.invalidRequest(`Google Interactions does not support ${asset.mediaType} document input`);
|
|
174
176
|
const type = asset.kind === "image" || asset.kind === "audio" || asset.kind === "video" ? asset.kind : "document";
|
|
175
|
-
const uri =
|
|
177
|
+
const uri = asset.kind === "video" && asset.source.type === "url" && /^https?:\/\//i.test(asset.source.url)
|
|
178
|
+
? asset.source.url
|
|
179
|
+
: MediaInput.refID(asset, ProviderID.make("google"));
|
|
176
180
|
if (uri !== undefined)
|
|
177
181
|
return { type, uri, mime_type: asset.mediaType };
|
|
178
182
|
const inline = yield* ProviderShared.requireInlineMedia("Google Interactions", asset);
|
|
@@ -253,7 +257,7 @@ const lowerToolResult = Effect.fnUntraced(function* (part) {
|
|
|
253
257
|
return yield* Effect.forEach(part.result.value, (item) => {
|
|
254
258
|
if (item.type === "text")
|
|
255
259
|
return Effect.succeed({ type: "text", text: item.text });
|
|
256
|
-
return mediaContent(
|
|
260
|
+
return mediaContent(GeminiGenerateContent.toolMedia(item));
|
|
257
261
|
});
|
|
258
262
|
});
|
|
259
263
|
const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (request) {
|
|
@@ -437,14 +441,17 @@ const step = Effect.fnUntraced(function* (state, event) {
|
|
|
437
441
|
});
|
|
438
442
|
case "interaction.completed": {
|
|
439
443
|
const interaction = event.interaction;
|
|
440
|
-
if (interaction.status === "failed" || interaction.status === "cancelled")
|
|
444
|
+
if (interaction.status === "failed" || interaction.status === "cancelled") {
|
|
445
|
+
const messages = (interaction.errors ?? []).flatMap((error) => (error.message?.trim() ? [error.message] : []));
|
|
441
446
|
return yield* new AIError({
|
|
442
447
|
reason: classifyProviderFailure({
|
|
443
|
-
message: `Google Interactions ${interaction.status}`,
|
|
444
|
-
|
|
448
|
+
message: messages.length > 0 ? messages.join("\n") : `Google Interactions ${interaction.status}`,
|
|
449
|
+
// The first coded error decides the classification; every message stays visible.
|
|
450
|
+
data: interaction.errors?.find((error) => error.code) ?? interaction,
|
|
445
451
|
rawBody: encodeJson(event),
|
|
446
452
|
}),
|
|
447
453
|
});
|
|
454
|
+
}
|
|
448
455
|
if (!["completed", "requires_action", "incomplete"].includes(interaction.status))
|
|
449
456
|
return yield* ProviderShared.eventError(ADAPTER, `Unexpected terminal Interactions status: ${interaction.status}`, encodeJson(event));
|
|
450
457
|
const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
|
|
@@ -67,15 +67,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
67
67
|
readonly [x: string]: unknown;
|
|
68
68
|
} | undefined;
|
|
69
69
|
} | undefined;
|
|
70
|
-
readonly notices?: readonly {
|
|
71
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
72
|
-
readonly message: string;
|
|
73
|
-
readonly providerMetadata?: {
|
|
74
|
-
readonly [x: string]: {
|
|
75
|
-
readonly [x: string]: unknown;
|
|
76
|
-
};
|
|
77
|
-
} | undefined;
|
|
78
|
-
}[] | undefined;
|
|
79
70
|
readonly providerMetadata?: {
|
|
80
71
|
readonly [x: string]: {
|
|
81
72
|
readonly [x: string]: unknown;
|
|
@@ -126,15 +117,6 @@ export declare const GoogleSpeech: {
|
|
|
126
117
|
readonly [x: string]: unknown;
|
|
127
118
|
} | undefined;
|
|
128
119
|
} | undefined;
|
|
129
|
-
readonly notices?: readonly {
|
|
130
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
131
|
-
readonly message: string;
|
|
132
|
-
readonly providerMetadata?: {
|
|
133
|
-
readonly [x: string]: {
|
|
134
|
-
readonly [x: string]: unknown;
|
|
135
|
-
};
|
|
136
|
-
} | undefined;
|
|
137
|
-
}[] | undefined;
|
|
138
120
|
readonly providerMetadata?: {
|
|
139
121
|
readonly [x: string]: {
|
|
140
122
|
readonly [x: string]: unknown;
|
|
@@ -67,7 +67,6 @@ const finish = (state, context) => {
|
|
|
67
67
|
return SpeechStream.finish(route, state, {
|
|
68
68
|
...output,
|
|
69
69
|
usage: GeminiGenerateContent.usage(state.usage),
|
|
70
|
-
notices: GeminiGenerateContent.notices(route.name, state),
|
|
71
70
|
providerMetadata: GeminiGenerateContent.providerMetadata(state),
|
|
72
71
|
detail: `finish reason: ${state.finishReason}`,
|
|
73
72
|
});
|
|
@@ -78,15 +78,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
78
78
|
readonly [x: string]: unknown;
|
|
79
79
|
} | undefined;
|
|
80
80
|
} | undefined;
|
|
81
|
-
readonly notices?: readonly {
|
|
82
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
83
|
-
readonly message: string;
|
|
84
|
-
readonly providerMetadata?: {
|
|
85
|
-
readonly [x: string]: {
|
|
86
|
-
readonly [x: string]: unknown;
|
|
87
|
-
};
|
|
88
|
-
} | undefined;
|
|
89
|
-
}[] | undefined;
|
|
90
81
|
readonly providerMetadata?: {
|
|
91
82
|
readonly [x: string]: {
|
|
92
83
|
readonly [x: string]: unknown;
|
|
@@ -153,15 +144,6 @@ export declare const GoogleTranscription: {
|
|
|
153
144
|
readonly [x: string]: unknown;
|
|
154
145
|
} | undefined;
|
|
155
146
|
} | undefined;
|
|
156
|
-
readonly notices?: readonly {
|
|
157
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
158
|
-
readonly message: string;
|
|
159
|
-
readonly providerMetadata?: {
|
|
160
|
-
readonly [x: string]: {
|
|
161
|
-
readonly [x: string]: unknown;
|
|
162
|
-
};
|
|
163
|
-
} | undefined;
|
|
164
|
-
}[] | undefined;
|
|
165
147
|
readonly providerMetadata?: {
|
|
166
148
|
readonly [x: string]: {
|
|
167
149
|
readonly [x: string]: unknown;
|
|
@@ -103,7 +103,6 @@ const finish = (state) => {
|
|
|
103
103
|
segments: state.segments.length === 0 ? undefined : state.segments,
|
|
104
104
|
words: state.words.length === 0 ? undefined : state.words,
|
|
105
105
|
usage: GeminiGenerateContent.usage(state.usage),
|
|
106
|
-
notices: GeminiGenerateContent.notices(route.name, state),
|
|
107
106
|
providerMetadata: GeminiGenerateContent.providerMetadata(state),
|
|
108
107
|
}),
|
|
109
108
|
]);
|
|
@@ -4,7 +4,7 @@ import { MediaRoute } from "../route/media.js";
|
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
5
|
import { VideoModel, VideoResponse, type VideoRequestFor } from "../video.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
|
-
/** Provider-native `parameters`. Common fields (`
|
|
7
|
+
/** Provider-native `parameters`. Common fields (`aspect`, `resolution`, `durationSeconds`, `seed`) live on the request. */
|
|
8
8
|
export type GoogleVideoOptions = {
|
|
9
9
|
readonly personGeneration?: OpenString<"allow_all" | "allow_adult" | "dont_allow">;
|
|
10
10
|
} & Record<string, unknown>;
|
|
@@ -68,7 +68,7 @@ const fromRequest = Effect.fn("GoogleVideo.fromRequest")(function* (request) {
|
|
|
68
68
|
},
|
|
69
69
|
],
|
|
70
70
|
parameters: mergeJsonRecords({
|
|
71
|
-
aspectRatio: request.
|
|
71
|
+
aspectRatio: request.aspect,
|
|
72
72
|
resolution: request.resolution,
|
|
73
73
|
durationSeconds: request.durationSeconds,
|
|
74
74
|
negativePrompt: request.negativePrompt,
|
|
@@ -109,22 +109,17 @@ const decodeResult = Effect.fn("GoogleVideo.decodeResult")(function* (response,
|
|
|
109
109
|
headers: context.auth,
|
|
110
110
|
}));
|
|
111
111
|
const reasons = generated?.raiMediaFilteredReasons ?? [];
|
|
112
|
-
const notices = reasons.map((reason) => ({
|
|
113
|
-
type: "filtered",
|
|
114
|
-
message: `${route.name} filtered media: ${reason}`,
|
|
115
|
-
providerMetadata: { google: { raiMediaFilteredReason: reason } },
|
|
116
|
-
}));
|
|
117
112
|
if (videos.length === 0 && (reasons.length > 0 || (generated?.raiMediaFilteredCount ?? 0) > 0))
|
|
118
113
|
return yield* output.contentPolicy(`${route.name} filtered every video${reasons.length === 0 ? "" : `: ${reasons.join("; ")}`}`);
|
|
119
114
|
if (videos.length === 0)
|
|
120
115
|
return yield* output.invalid(`${route.name} operation completed without any video`);
|
|
121
116
|
return new VideoResponse({
|
|
122
117
|
videos,
|
|
123
|
-
notices: notices.length === 0 ? undefined : notices,
|
|
124
118
|
providerMetadata: {
|
|
125
119
|
google: {
|
|
126
120
|
operation: context.token.operation,
|
|
127
121
|
raiMediaFilteredCount: generated?.raiMediaFilteredCount,
|
|
122
|
+
raiMediaFilteredReasons: generated?.raiMediaFilteredReasons,
|
|
128
123
|
metadata: operation.metadata,
|
|
129
124
|
},
|
|
130
125
|
},
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
|
|
3
4
|
export * as CohereChat from "./cohere-chat.js";
|
|
4
5
|
export * as Gemini from "./gemini.js";
|
|
5
6
|
export * as GoogleInteractions from "./google-interactions.js";
|
|
6
7
|
export * as MistralChat from "./mistral-chat.js";
|
|
7
8
|
export * as OpenAIChat from "./openai-chat.js";
|
|
9
|
+
export * as OpenAIDecisions from "./openai-decisions.js";
|
|
8
10
|
export * as OpenAIImages from "./openai-images.js";
|
|
9
11
|
export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
|
|
10
12
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
11
13
|
export * as OpenAIResponses from "./openai-responses.js";
|
|
12
14
|
export * as OpenResponses from "./open-responses.js";
|
|
13
15
|
export * as OpenResponsesChannel from "./open-responses-channel.js";
|
|
16
|
+
export * as SystemOne from "./system-one.js";
|
|
14
17
|
export * as XAIResponses from "./xai-responses.js";
|
package/dist/protocols/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
|
|
3
4
|
export * as CohereChat from "./cohere-chat.js";
|
|
4
5
|
export * as Gemini from "./gemini.js";
|
|
5
6
|
export * as GoogleInteractions from "./google-interactions.js";
|
|
6
7
|
export * as MistralChat from "./mistral-chat.js";
|
|
7
8
|
export * as OpenAIChat from "./openai-chat.js";
|
|
9
|
+
export * as OpenAIDecisions from "./openai-decisions.js";
|
|
8
10
|
export * as OpenAIImages from "./openai-images.js";
|
|
9
11
|
export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
|
|
10
12
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
11
13
|
export * as OpenAIResponses from "./openai-responses.js";
|
|
12
14
|
export * as OpenResponses from "./open-responses.js";
|
|
13
15
|
export * as OpenResponsesChannel from "./open-responses-channel.js";
|
|
16
|
+
export * as SystemOne from "./system-one.js";
|
|
14
17
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -3,8 +3,14 @@ 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
5
|
export declare const DEFAULT_BASE_URL = "https://api.meta.ai/v1";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Provider-native options. Common fields (`n`, `aspect`, `images`) live on the request; Meta picks its own output
|
|
8
|
+
* resolution (about 2.5 megapixels), so `resolution` is ignored.
|
|
9
|
+
*/
|
|
7
10
|
export type ImageOptions = {
|
|
11
|
+
/** `WIDTHxHEIGHT` aspect ratio hint; it replaces `aspect`, so setting both fails. */
|
|
12
|
+
readonly size?: string;
|
|
13
|
+
readonly outputFormat?: OpenString<"webp" | "png" | "jpeg">;
|
|
8
14
|
readonly responseFormat?: OpenString<"b64_json" | "url">;
|
|
9
15
|
readonly reasoningStrength?: OpenString<"low" | "high">;
|
|
10
16
|
readonly toolEnablement?: {
|