@opencode/ai 2.2.6 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -98
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/decision.d.ts +10 -0
- package/dist/decision.js +2 -0
- package/dist/effect.d.ts +14 -7
- package/dist/effect.js +6 -1
- 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.d.ts +0 -4
- package/dist/experimental.js +0 -3
- package/dist/image-client.d.ts +1 -1
- package/dist/image-client.js +2 -6
- package/dist/image.d.ts +0 -1
- package/dist/image.js +0 -3
- package/dist/index.d.ts +18 -50
- package/dist/index.js +35 -13
- package/dist/media-model.d.ts +2 -0
- package/dist/media-model.js +3 -1
- package/dist/media.d.ts +9 -3
- package/dist/media.js +27 -7
- package/dist/protocols/alibaba-chat.d.ts +4 -0
- package/dist/protocols/anthropic-messages.js +3 -3
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-interactions-video.d.ts +43 -0
- package/dist/protocols/google-interactions-video.js +186 -0
- package/dist/protocols/google-interactions.d.ts +14 -1
- package/dist/protocols/google-interactions.js +1 -1
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/index.d.ts +4 -0
- package/dist/protocols/index.js +4 -0
- package/dist/protocols/minimax-video.d.ts +54 -0
- package/dist/protocols/minimax-video.js +292 -0
- package/dist/protocols/open-responses.d.ts +1 -1
- package/dist/protocols/open-responses.js +31 -8
- package/dist/protocols/openai-chat.d.ts +24 -0
- package/dist/protocols/openai-chat.js +37 -11
- package/dist/protocols/openai-compatible-chat.d.ts +1 -0
- package/dist/protocols/openai-decisions.js +14 -1
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- package/dist/protocols/openrouter-video.d.ts +41 -0
- package/dist/protocols/openrouter-video.js +138 -0
- package/dist/protocols/seedance-video.d.ts +50 -0
- package/dist/protocols/seedance-video.js +216 -0
- package/dist/protocols/shared.d.ts +13 -3
- package/dist/protocols/shared.js +27 -4
- package/dist/protocols/system-one.d.ts +45 -1
- package/dist/protocols/system-one.js +50 -8
- package/dist/protocols/utils/responses-compaction.js +1 -1
- package/dist/protocols/venice-chat.d.ts +4 -0
- package/dist/protocols/xai-video.d.ts +8 -2
- package/dist/protocols/xai-video.js +20 -15
- package/dist/protocols/zai-chat.d.ts +4 -0
- package/dist/provider-error.js +7 -1
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba.d.ts +3 -0
- package/dist/providers/alibaba.js +14 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +1 -0
- package/dist/providers/azure/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.js +15 -0
- package/dist/providers/baseten.d.ts +2 -0
- package/dist/providers/byteplus/videos.d.ts +2 -0
- package/dist/providers/byteplus/videos.js +1 -0
- package/dist/providers/byteplus.d.ts +26 -0
- package/dist/providers/byteplus.js +21 -0
- package/dist/providers/cerebras.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +2 -0
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +8 -0
- package/dist/providers/cohere.js +17 -1
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +6 -1
- package/dist/providers/deepinfra.js +15 -1
- package/dist/providers/deepseek.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean.d.ts +10 -0
- package/dist/providers/digitalocean.js +15 -0
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +6 -1
- package/dist/providers/fireworks.js +15 -1
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.js +1 -0
- package/dist/providers/google/videos.d.ts +2 -0
- package/dist/providers/google/videos.js +1 -0
- 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 +1 -0
- package/dist/providers/google-vertex.d.ts +7 -0
- package/dist/providers/google-vertex.js +52 -0
- package/dist/providers/google.d.ts +17 -4
- package/dist/providers/google.js +27 -3
- package/dist/providers/groq.d.ts +5 -0
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/meta.d.ts +1 -0
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +7 -1
- package/dist/providers/minimax.js +10 -1
- package/dist/providers/moonshot.d.ts +1 -0
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.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.d.ts +6 -0
- package/dist/providers/openai-compatible.js +27 -0
- package/dist/providers/openai.d.ts +7 -0
- package/dist/providers/openai.js +14 -0
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +21 -0
- package/dist/providers/openrouter.js +23 -0
- package/dist/providers/togetherai.d.ts +2 -0
- package/dist/providers/venice.d.ts +1 -0
- 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 +4 -0
- package/dist/providers/vercel-ai-gateway.js +15 -1
- package/dist/providers/volcengine/videos.d.ts +2 -0
- package/dist/providers/volcengine/videos.js +1 -0
- package/dist/providers/volcengine.d.ts +26 -0
- package/dist/providers/volcengine.js +21 -0
- package/dist/providers/xai.d.ts +1 -0
- package/dist/providers/zai-coding-plan.d.ts +1 -0
- package/dist/providers/zai.d.ts +1 -0
- package/dist/public.d.ts +4 -0
- package/dist/public.js +2 -0
- package/dist/route/embedding.d.ts +61 -0
- package/dist/route/embedding.js +88 -0
- package/dist/route/executor-service.d.ts +6 -0
- package/dist/route/executor-service.js +7 -0
- package/dist/route/executor.d.ts +7 -1
- package/dist/route/executor.js +7 -2
- package/dist/route/media-protocol.d.ts +12 -11
- package/dist/route/media.d.ts +2 -0
- package/dist/route/media.js +31 -22
- package/dist/route/transport/http.js +1 -1
- package/dist/schema/messages.d.ts +1 -1
- package/dist/schema/messages.js +1 -5
- package/dist/schema/options.d.ts +8 -0
- package/dist/schema/options.js +1 -0
- package/dist/speech-client.d.ts +1 -1
- package/dist/speech-client.js +4 -4
- package/dist/transcription-client.d.ts +1 -1
- package/dist/transcription-client.js +1 -2
- package/dist/video-client.d.ts +16 -84
- package/dist/video-client.js +28 -13
- package/dist/video.d.ts +56 -1072
- package/dist/video.js +28 -65
- package/package.json +355 -255
- package/dist/protocols/google-video.d.ts +0 -26
- package/dist/protocols/google-video.js +0 -146
- package/dist/protocols/runway-video.d.ts +0 -38
- package/dist/protocols/runway-video.js +0 -141
- package/dist/providers/runway.d.ts +0 -20
- package/dist/providers/runway.js +0 -17
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Service, type Execute } from "./embedding-client.js";
|
|
3
|
+
import { Media } from "./media.js";
|
|
4
|
+
import { type AIError, type BaseRequest, type HttpOptions, ModelID, ProviderID, ProviderOptions } from "./schema/index.js";
|
|
5
|
+
/** One value to embed: text, or a media asset for hosts that embed images, audio or documents. */
|
|
6
|
+
export declare const EmbeddingValue: Schema.Union<readonly [Schema.String, Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
7
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
8
|
+
readonly type: Schema.Literal<"bytes">;
|
|
9
|
+
readonly data: Schema.Uint8Array;
|
|
10
|
+
readonly mediaType: Schema.String;
|
|
11
|
+
}>, Schema.Struct<{
|
|
12
|
+
readonly type: Schema.Literal<"base64">;
|
|
13
|
+
readonly data: Schema.String;
|
|
14
|
+
readonly mediaType: Schema.String;
|
|
15
|
+
}>, Schema.Struct<{
|
|
16
|
+
readonly type: Schema.Literal<"url">;
|
|
17
|
+
readonly url: Schema.String;
|
|
18
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
19
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
20
|
+
}>, Schema.Struct<{
|
|
21
|
+
readonly type: Schema.Literal<"ref">;
|
|
22
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
23
|
+
readonly id: Schema.String;
|
|
24
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
25
|
+
}>]>;
|
|
26
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
27
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
28
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
29
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
30
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
31
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
32
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
33
|
+
readonly format: Schema.optional<Schema.String>;
|
|
34
|
+
}>>;
|
|
35
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
36
|
+
}>, never, never>]>;
|
|
37
|
+
export type EmbeddingValue = Schema.Schema.Type<typeof EmbeddingValue>;
|
|
38
|
+
/** A string is always text; media is an `Asset` or plain bytes or a URL, normalized with `Media.make`. */
|
|
39
|
+
export type EmbeddingValueInput = string | Exclude<Media.Input, string>;
|
|
40
|
+
/**
|
|
41
|
+
* What the vectors are for: a search `query`, or a `document` stored to be searched. Hosts without such a field embed
|
|
42
|
+
* both the same way and ignore it.
|
|
43
|
+
*/
|
|
44
|
+
export type EmbeddingInputType = "query" | "document";
|
|
45
|
+
export type EmbeddingOptions = Record<string, unknown>;
|
|
46
|
+
/** What an embedding model's route does; `EmbeddingRoute.make(...).model(...)` builds one from a protocol. */
|
|
47
|
+
export interface EmbeddingModelRoute<Options extends EmbeddingOptions = EmbeddingOptions> {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
generate(request: EmbeddingRequest<EmbeddingModel<Options>>, execute: Execute): Effect.Effect<EmbeddingResponse, AIError>;
|
|
50
|
+
}
|
|
51
|
+
export declare class EmbeddingModel<Options extends EmbeddingOptions = EmbeddingOptions> {
|
|
52
|
+
protected readonly _Options: Options;
|
|
53
|
+
readonly id: ModelID;
|
|
54
|
+
readonly provider: ProviderID;
|
|
55
|
+
readonly route: EmbeddingModelRoute<Options>;
|
|
56
|
+
readonly http?: HttpOptions;
|
|
57
|
+
/** Defaults under each request's `providerOptions`, such as options a provider package reads from its settings. */
|
|
58
|
+
readonly providerOptions?: ProviderOptions;
|
|
59
|
+
constructor(input: EmbeddingModel.Input<Options>);
|
|
60
|
+
static make<Options extends EmbeddingOptions = EmbeddingOptions>(input: EmbeddingModel.MakeInput<Options>): EmbeddingModel<Options>;
|
|
61
|
+
}
|
|
62
|
+
export declare namespace EmbeddingModel {
|
|
63
|
+
interface Input<Options extends EmbeddingOptions = EmbeddingOptions> {
|
|
64
|
+
readonly id: ModelID;
|
|
65
|
+
readonly provider: ProviderID;
|
|
66
|
+
readonly route: EmbeddingModelRoute<Options>;
|
|
67
|
+
readonly http?: HttpOptions;
|
|
68
|
+
readonly providerOptions?: ProviderOptions;
|
|
69
|
+
}
|
|
70
|
+
interface MakeInput<Options extends EmbeddingOptions = EmbeddingOptions> extends Omit<Input<Options>, "id" | "provider"> {
|
|
71
|
+
readonly id: string | ModelID;
|
|
72
|
+
readonly provider: string | ProviderID;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export declare const EmbeddingModelSchema: Schema.declare<EmbeddingModel<EmbeddingOptions>, EmbeddingModel<EmbeddingOptions>>;
|
|
76
|
+
export type EmbeddingModelOptions<Model> = Model extends EmbeddingModel<infer Options> ? Options : never;
|
|
77
|
+
/** A normalized embedding request, the plain object `ai.embedding.request(...)` returns. */
|
|
78
|
+
export interface EmbeddingRequest<Model extends EmbeddingModel = EmbeddingModel> extends BaseRequest<Model, EmbeddingModelOptions<Model>> {
|
|
79
|
+
readonly values: ReadonlyArray<EmbeddingValue>;
|
|
80
|
+
/** Requested vector length, for models that can shorten their output. */
|
|
81
|
+
readonly dimensions?: number;
|
|
82
|
+
readonly inputType?: EmbeddingInputType;
|
|
83
|
+
}
|
|
84
|
+
/** Input accepted by `ai.embedding.request` and `generate`. An `EmbeddingRequest` is also a valid input. */
|
|
85
|
+
export interface EmbeddingRequestInput<Model extends EmbeddingModel = EmbeddingModel> extends BaseRequest<Model, NoInfer<EmbeddingModelOptions<Model>>> {
|
|
86
|
+
readonly values: ReadonlyArray<EmbeddingValueInput>;
|
|
87
|
+
readonly dimensions?: number;
|
|
88
|
+
readonly inputType?: EmbeddingInputType;
|
|
89
|
+
}
|
|
90
|
+
declare const EmbeddingUsage_base: Schema.Class<EmbeddingUsage, Schema.Struct<{
|
|
91
|
+
readonly inputTokens: Schema.optional<Schema.Number>;
|
|
92
|
+
}>, {}>;
|
|
93
|
+
/** What embedding hosts report; their raw usage stays in the response's `providerMetadata`. */
|
|
94
|
+
export declare class EmbeddingUsage extends EmbeddingUsage_base {
|
|
95
|
+
}
|
|
96
|
+
declare const EmbeddingResponse_base: Schema.Class<EmbeddingResponse, Schema.Struct<{
|
|
97
|
+
/** One vector per value, in value order. */
|
|
98
|
+
readonly embeddings: Schema.$Array<Schema.$Array<Schema.Number>>;
|
|
99
|
+
readonly usage: Schema.optional<typeof EmbeddingUsage>;
|
|
100
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
101
|
+
}>, {}>;
|
|
102
|
+
export declare class EmbeddingResponse extends EmbeddingResponse_base {
|
|
103
|
+
}
|
|
104
|
+
/** Normalize embedding request input into a plain `EmbeddingRequest`; non-string values become `Media.Asset`s. */
|
|
105
|
+
export declare const request: <const Model extends EmbeddingModel>(input: EmbeddingRequestInput<Model>) => EmbeddingRequest<Model>;
|
|
106
|
+
export declare function generate<const Model extends EmbeddingModel>(input: EmbeddingRequestInput<Model>): Effect.Effect<EmbeddingResponse, AIError, Service>;
|
|
107
|
+
export declare const Embedding: {
|
|
108
|
+
readonly request: typeof request;
|
|
109
|
+
readonly generate: typeof generate;
|
|
110
|
+
};
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { EmbeddingClient, Service } from "./embedding-client.js";
|
|
3
|
+
import { Media } from "./media.js";
|
|
4
|
+
import { tryRequest } from "./media-model.js";
|
|
5
|
+
import { ModelID, ProviderID, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Input
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
/** One value to embed: text, or a media asset for hosts that embed images, audio or documents. */
|
|
10
|
+
export const EmbeddingValue = Schema.Union([Schema.String, Media.AssetSchema]);
|
|
11
|
+
export class EmbeddingModel {
|
|
12
|
+
id;
|
|
13
|
+
provider;
|
|
14
|
+
route;
|
|
15
|
+
http;
|
|
16
|
+
/** Defaults under each request's `providerOptions`, such as options a provider package reads from its settings. */
|
|
17
|
+
providerOptions;
|
|
18
|
+
constructor(input) {
|
|
19
|
+
this.id = input.id;
|
|
20
|
+
this.provider = input.provider;
|
|
21
|
+
this.route = input.route;
|
|
22
|
+
this.http = input.http;
|
|
23
|
+
this.providerOptions = input.providerOptions;
|
|
24
|
+
}
|
|
25
|
+
static make(input) {
|
|
26
|
+
return new EmbeddingModel({
|
|
27
|
+
...input,
|
|
28
|
+
id: ModelID.make(input.id),
|
|
29
|
+
provider: ProviderID.make(input.provider),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const EmbeddingModelSchema = Schema.declare((value) => value instanceof EmbeddingModel, { expected: "Embedding.Model" });
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Request and response
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
const EmbeddingRequestSchema = Schema.Struct({
|
|
38
|
+
model: EmbeddingModelSchema,
|
|
39
|
+
values: Schema.Array(EmbeddingValue).pipe(Schema.refine((x) => x.length > 0, { message: "Embedding values must not be empty" })),
|
|
40
|
+
dimensions: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
41
|
+
inputType: Schema.optional(Schema.Literals(["query", "document"])),
|
|
42
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
43
|
+
});
|
|
44
|
+
/** What embedding hosts report; their raw usage stays in the response's `providerMetadata`. */
|
|
45
|
+
export class EmbeddingUsage extends Schema.Class("Embedding.Usage")({
|
|
46
|
+
inputTokens: Schema.optional(Schema.Number),
|
|
47
|
+
}) {
|
|
48
|
+
}
|
|
49
|
+
export class EmbeddingResponse extends Schema.Class("Embedding.Response")({
|
|
50
|
+
/** One vector per value, in value order. */
|
|
51
|
+
embeddings: Schema.Array(Schema.Array(Schema.Number)),
|
|
52
|
+
usage: Schema.optional(EmbeddingUsage),
|
|
53
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
54
|
+
}) {
|
|
55
|
+
}
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Call API
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
/** Normalize embedding request input into a plain `EmbeddingRequest`; non-string values become `Media.Asset`s. */
|
|
60
|
+
export const request = (input) => ({
|
|
61
|
+
...input,
|
|
62
|
+
values: input.values.map((value) => (typeof value === "string" ? value : Media.make(value))),
|
|
63
|
+
});
|
|
64
|
+
const validate = Schema.decodeUnknownSync(EmbeddingRequestSchema);
|
|
65
|
+
export function generate(input) {
|
|
66
|
+
return tryRequest(() => {
|
|
67
|
+
const normalized = request(input);
|
|
68
|
+
validate(normalized);
|
|
69
|
+
return normalized;
|
|
70
|
+
}).pipe(Effect.flatMap(EmbeddingClient.generate));
|
|
71
|
+
}
|
|
72
|
+
export const Embedding = {
|
|
73
|
+
request,
|
|
74
|
+
generate,
|
|
75
|
+
};
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
|
-
export type { VideoModelOptions, VideoOptions, VideoRequest, VideoRequestInput, VideoResolution, VideoRoute, } from "./video.js";
|
|
4
|
-
export { Video } from "./video.js";
|
|
5
1
|
export { SpeechClient } from "./speech-client.js";
|
|
6
2
|
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
7
3
|
export type { SpeechFormat, SpeechModelOptions, SpeechOptions, SpeechRequest, SpeechRequestInput, SpeechRoute, } from "./speech.js";
|
package/dist/experimental.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
|
-
export { Video } from "./video.js";
|
|
4
1
|
export { SpeechClient } from "./speech-client.js";
|
|
5
2
|
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
6
3
|
export { Speech } from "./speech.js";
|
package/dist/image-client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ImageEvent, ImageRequest, ImageResponse } from "./image.js";
|
|
4
4
|
export type Interface = MediaClient.Interface<ImageRequest, ImageEvent, ImageResponse>;
|
|
5
5
|
declare const ImageClientService_base: Context.ServiceClass<ImageClientService, "@opencode/ImageClient", Interface>;
|
|
6
6
|
export declare class ImageClientService extends ImageClientService_base {
|
package/dist/image-client.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import { ImageOutputEvent, ImageFinishEvent } from "./image.js";
|
|
4
3
|
export class ImageClientService extends Context.Service()("@opencode/ImageClient") {
|
|
5
4
|
}
|
|
6
5
|
export const Service = ImageClientService;
|
|
@@ -9,11 +8,8 @@ export const ImageClient = {
|
|
|
9
8
|
...MediaClient.make(Service, {
|
|
10
9
|
modality: "image",
|
|
11
10
|
responseEvents: (response) => [
|
|
12
|
-
...response.images.map((image, index) =>
|
|
13
|
-
|
|
14
|
-
usage: response.usage,
|
|
15
|
-
providerMetadata: response.providerMetadata,
|
|
16
|
-
}),
|
|
11
|
+
...response.images.map((image, index) => ({ type: "image", index, image })),
|
|
12
|
+
{ type: "finish", usage: response.usage, providerMetadata: response.providerMetadata },
|
|
17
13
|
],
|
|
18
14
|
}),
|
|
19
15
|
};
|
package/dist/image.d.ts
CHANGED
|
@@ -93,7 +93,6 @@ declare const ImageResponse_base: Schema.Class<ImageResponse, Schema.Struct<{
|
|
|
93
93
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
94
94
|
}>, {}>;
|
|
95
95
|
export declare class ImageResponse extends ImageResponse_base {
|
|
96
|
-
get image(): Media.Asset;
|
|
97
96
|
}
|
|
98
97
|
/** The `index`-th lower-fidelity preview of an image still generating; the `image` event supersedes it. */
|
|
99
98
|
export declare const ImagePartialEvent: Schema.Struct<{
|
package/dist/image.js
CHANGED
|
@@ -37,9 +37,6 @@ export class ImageResponse extends Schema.Class("Image.Response")({
|
|
|
37
37
|
usage: Schema.optional(MediaUsage),
|
|
38
38
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
39
39
|
}) {
|
|
40
|
-
get image() {
|
|
41
|
-
return this.images[0];
|
|
42
|
-
}
|
|
43
40
|
}
|
|
44
41
|
/** The `index`-th lower-fidelity preview of an image still generating; the `image` event supersedes it. */
|
|
45
42
|
export const ImagePartialEvent = Schema.Struct({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Layer, Schema } from "effect";
|
|
2
2
|
import { AIClient } from "./ai-client.js";
|
|
3
3
|
import { type DecisionModel, type DecisionQuestions, type DecisionRequestInput } from "./decision.js";
|
|
4
|
+
import { type EmbeddingModel, type EmbeddingRequestInput } from "./embedding.js";
|
|
4
5
|
import type { AwaitOptions, Event, Snapshot } from "./generation.js";
|
|
5
6
|
import { type ImageModel, type ImageRequest, type ImageRequestInput } from "./image.js";
|
|
6
7
|
import { LLM } from "./llm.js";
|
|
@@ -15,8 +16,8 @@ import type { NoExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolOptio
|
|
|
15
16
|
import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./video.js";
|
|
16
17
|
/**
|
|
17
18
|
* Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
|
|
18
|
-
* transcription and
|
|
19
|
-
* `AIError` unchanged. `file` and `write` load `node:fs/promises` on first use, so importing this module does not.
|
|
19
|
+
* transcription, decision and embedding clients over a request executor; every method runs the corresponding Effect API
|
|
20
|
+
* and rethrows `AIError` unchanged. `file` and `write` load `node:fs/promises` on first use, so importing this module does not.
|
|
20
21
|
*/
|
|
21
22
|
export interface Options {
|
|
22
23
|
/** Executor layer; defaults to `RequestExecutor.fetchLayer`. Inject a recorder or `RequestExecutor.middleware(fn)` here. */
|
|
@@ -52,7 +53,7 @@ export declare const make: (options?: Options) => {
|
|
|
52
53
|
materialize: (asset: Media.Asset, options?: RunOptions) => Promise<Media.Asset>;
|
|
53
54
|
/** Read a file into an asset like `Media.file`: sniffed media type, then the extension's. */
|
|
54
55
|
file: (path: string, options?: Media.AssetOptions & RunOptions) => Promise<Media.Asset>;
|
|
55
|
-
/** Write an asset's bytes like `Media.write
|
|
56
|
+
/** Write an asset's bytes like `Media.write`: streamed through a temporary file that replaces `path` on success. */
|
|
56
57
|
write: (asset: Media.Asset, path: string, options?: RunOptions) => Promise<void>;
|
|
57
58
|
request: typeof LLM.request;
|
|
58
59
|
generate: {
|
|
@@ -136,6 +137,20 @@ export declare const make: (options?: Options) => {
|
|
|
136
137
|
request: typeof import("./decision.js").request;
|
|
137
138
|
generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
|
|
138
139
|
};
|
|
140
|
+
embedding: {
|
|
141
|
+
request: typeof import("./embedding.js").request;
|
|
142
|
+
generate: <const Model extends EmbeddingModel>(input: EmbeddingRequestInput<Model>, options?: RunOptions) => Promise<import("./embedding.js").EmbeddingResponse>;
|
|
143
|
+
};
|
|
144
|
+
video: {
|
|
145
|
+
request: typeof import("./video.js").request;
|
|
146
|
+
/** Submit a generation and return its `{ id, token }` at once; nothing polls. */
|
|
147
|
+
start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<import("./video.js").VideoJob>;
|
|
148
|
+
/** One status read for a stored token. */
|
|
149
|
+
status: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<import("./video.js").VideoStatus>;
|
|
150
|
+
/** The finished videos; fails while the job is still running. */
|
|
151
|
+
result: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<import("./video.js").VideoResponse>;
|
|
152
|
+
cancel: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<void>;
|
|
153
|
+
};
|
|
139
154
|
/** Experimental: may change without compatibility guarantees. */
|
|
140
155
|
experimental: {
|
|
141
156
|
speech: {
|
|
@@ -260,53 +275,6 @@ export declare const make: (options?: Options) => {
|
|
|
260
275
|
start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
261
276
|
resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
262
277
|
};
|
|
263
|
-
video: {
|
|
264
|
-
request: typeof import("./video.js").request;
|
|
265
|
-
start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
|
|
266
|
-
generate: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
|
|
267
|
-
resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
|
|
268
|
-
stream: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
|
|
269
|
-
readonly type: "video";
|
|
270
|
-
readonly index: number;
|
|
271
|
-
readonly video: Media.Asset;
|
|
272
|
-
} | {
|
|
273
|
-
readonly type: "generation-queued";
|
|
274
|
-
readonly id: string;
|
|
275
|
-
readonly position?: number | undefined;
|
|
276
|
-
} | {
|
|
277
|
-
readonly type: "generation-progress";
|
|
278
|
-
readonly id: string;
|
|
279
|
-
readonly progress?: number | undefined;
|
|
280
|
-
} | {
|
|
281
|
-
readonly type: "finish";
|
|
282
|
-
readonly usage?: {
|
|
283
|
-
readonly type: "seconds";
|
|
284
|
-
readonly seconds: number;
|
|
285
|
-
} | {
|
|
286
|
-
readonly type: "characters";
|
|
287
|
-
readonly characters: number;
|
|
288
|
-
} | {
|
|
289
|
-
readonly type: "credits";
|
|
290
|
-
readonly credits: number;
|
|
291
|
-
} | {
|
|
292
|
-
readonly type: "compute";
|
|
293
|
-
readonly seconds: number;
|
|
294
|
-
} | {
|
|
295
|
-
readonly type: "tokens";
|
|
296
|
-
readonly input?: number | undefined;
|
|
297
|
-
readonly output?: number | undefined;
|
|
298
|
-
readonly total?: number | undefined;
|
|
299
|
-
readonly details?: {
|
|
300
|
-
readonly [x: string]: unknown;
|
|
301
|
-
} | undefined;
|
|
302
|
-
} | undefined;
|
|
303
|
-
readonly providerMetadata?: {
|
|
304
|
-
readonly [x: string]: {
|
|
305
|
-
readonly [x: string]: unknown;
|
|
306
|
-
};
|
|
307
|
-
} | undefined;
|
|
308
|
-
}>;
|
|
309
|
-
};
|
|
310
278
|
};
|
|
311
279
|
dispose: () => Promise<void>;
|
|
312
280
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Layer, ManagedRuntime, Schema, Stream } from "effect";
|
|
2
2
|
import { AIClient } from "./ai-client.js";
|
|
3
3
|
import { Decision } from "./decision.js";
|
|
4
|
+
import { Embedding } from "./embedding.js";
|
|
4
5
|
import { Image } from "./image.js";
|
|
5
6
|
import { LLM } from "./llm.js";
|
|
6
7
|
import { Media } from "./media.js";
|
|
@@ -75,13 +76,27 @@ export const make = (options = {}) => {
|
|
|
75
76
|
return Media.bytes(data, fileMediaType(data, path), options);
|
|
76
77
|
})), options);
|
|
77
78
|
},
|
|
78
|
-
/** Write an asset's bytes like `Media.write
|
|
79
|
+
/** Write an asset's bytes like `Media.write`: streamed through a temporary file that replaces `path` on success. */
|
|
79
80
|
write: async (asset, path, options) => {
|
|
80
|
-
const {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const { open, rename, rm } = await import("node:fs/promises");
|
|
82
|
+
const temporary = `${path}.${crypto.randomUUID()}.tmp`;
|
|
83
|
+
try {
|
|
84
|
+
const file = await open(temporary, "w");
|
|
85
|
+
try {
|
|
86
|
+
for await (const chunk of iterate(asset.stream(), options))
|
|
87
|
+
await file.write(chunk);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await file.close();
|
|
91
|
+
}
|
|
92
|
+
await rename(temporary, path);
|
|
93
|
+
}
|
|
94
|
+
catch (cause) {
|
|
95
|
+
await rm(temporary, { force: true });
|
|
96
|
+
if (cause instanceof AIError || cause === options?.signal?.reason)
|
|
97
|
+
throw cause;
|
|
98
|
+
throw fileError(`Failed to write media file ${path}`, cause);
|
|
99
|
+
}
|
|
85
100
|
},
|
|
86
101
|
request: LLM.request,
|
|
87
102
|
generate,
|
|
@@ -103,6 +118,20 @@ export const make = (options = {}) => {
|
|
|
103
118
|
request: Decision.request,
|
|
104
119
|
generate: (input, options) => run(Decision.generate(input), options),
|
|
105
120
|
},
|
|
121
|
+
embedding: {
|
|
122
|
+
request: Embedding.request,
|
|
123
|
+
generate: (input, options) => run(Embedding.generate(input), options),
|
|
124
|
+
},
|
|
125
|
+
video: {
|
|
126
|
+
request: Video.request,
|
|
127
|
+
/** Submit a generation and return its `{ id, token }` at once; nothing polls. */
|
|
128
|
+
start: (input, options) => run(Video.start(input), options),
|
|
129
|
+
/** One status read for a stored token. */
|
|
130
|
+
status: (model, token, options) => run(Video.status(model, token), options),
|
|
131
|
+
/** The finished videos; fails while the job is still running. */
|
|
132
|
+
result: (model, token, options) => run(Video.result(model, token), options),
|
|
133
|
+
cancel: (model, token, options) => run(Video.cancel(model, token), options),
|
|
134
|
+
},
|
|
106
135
|
/** Experimental: may change without compatibility guarantees. */
|
|
107
136
|
experimental: {
|
|
108
137
|
speech: {
|
|
@@ -117,13 +146,6 @@ export const make = (options = {}) => {
|
|
|
117
146
|
start: (input, options) => run(Transcription.start(input), options).then(handle),
|
|
118
147
|
resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
|
|
119
148
|
},
|
|
120
|
-
video: {
|
|
121
|
-
request: Video.request,
|
|
122
|
-
start: (input, options) => run(Video.start(input), options).then(handle),
|
|
123
|
-
generate: (input, options) => run(Video.generate(input, { poll: options?.poll }), options),
|
|
124
|
-
resume: (model, token, options) => run(Video.resume(model, token), options).then(handle),
|
|
125
|
-
stream: (input, options) => iterate(Video.stream(input, { poll: options?.poll }), options),
|
|
126
|
-
},
|
|
127
149
|
},
|
|
128
150
|
dispose: () => runtime.dispose(),
|
|
129
151
|
};
|
package/dist/media-model.d.ts
CHANGED
|
@@ -42,5 +42,7 @@ export declare namespace MediaModel {
|
|
|
42
42
|
}
|
|
43
43
|
/** Compose a protocol route input with one deployment through `MediaRoute.inline`, `queued`, or `stream`. */
|
|
44
44
|
export declare const composeRoute: <Request extends MediaRoute.MediaRequest, Event, Response, Frame, State, Token>(route: MediaModel.AnyRouteInput<Request, Event, Response, Frame, State, Token>, input: MediaRoute.ModelInput, collect: (events: ReadonlyArray<Event>) => Effect.Effect<Response, AIError>) => MediaRoute.AnyRoute<Request, Event, Response>;
|
|
45
|
+
/** Compose a queued protocol route input with one deployment through `MediaRoute.queued`. */
|
|
46
|
+
export declare const composeQueuedRoute: <Request extends MediaRoute.MediaRequest, Response, Token>(route: MediaModel.QueuedRouteInput<Request, Response, Token>, input: MediaRoute.ModelInput) => MediaRoute.QueuedRoute<Request, Response>;
|
|
45
47
|
/** Lift a synchronous Schema-class constructor into a typed `InvalidRequest` failure. */
|
|
46
48
|
export declare const tryRequest: <A>(make: () => A) => Effect.Effect<A, AIError>;
|
package/dist/media-model.js
CHANGED
|
@@ -27,9 +27,11 @@ export const composeRoute = (route, input, collect) => {
|
|
|
27
27
|
if (isStreamInput(route))
|
|
28
28
|
return MediaRoute.stream({ ...composition(route, input), collect });
|
|
29
29
|
if (isQueuedInput(route))
|
|
30
|
-
return
|
|
30
|
+
return composeQueuedRoute(route, input);
|
|
31
31
|
return MediaRoute.inline(composition(route, input));
|
|
32
32
|
};
|
|
33
|
+
/** Compose a queued protocol route input with one deployment through `MediaRoute.queued`. */
|
|
34
|
+
export const composeQueuedRoute = (route, input) => MediaRoute.queued(composition(route, input));
|
|
33
35
|
const composition = (route, input) => ({
|
|
34
36
|
protocol: route.protocol,
|
|
35
37
|
endpoint: Endpoint.path(route.path, { baseURL: input.baseURL ?? route.baseURL }),
|
package/dist/media.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * as Media from "./media.js";
|
|
2
|
-
import { Effect, FileSystem, Schema } from "effect";
|
|
2
|
+
import { Effect, FileSystem, Schema, Stream } from "effect";
|
|
3
3
|
import { ProviderID } from "./schema/ids.js";
|
|
4
4
|
import { AIError } from "./schema/errors.js";
|
|
5
5
|
import { ProviderMetadata } from "./schema/options.js";
|
|
@@ -65,6 +65,8 @@ export declare class Asset {
|
|
|
65
65
|
inline(): Inline | undefined;
|
|
66
66
|
/** Decoded payload; downloads `url` sources through the request executor and caches the result. */
|
|
67
67
|
bytes(): Effect.Effect<Uint8Array, AIError, Service>;
|
|
68
|
+
/** The payload as a byte stream; `url` sources stream from the network without being buffered or cached. */
|
|
69
|
+
stream(): Stream.Stream<Uint8Array, AIError, Service>;
|
|
68
70
|
base64(): Effect.Effect<string, AIError, Service>;
|
|
69
71
|
dataUrl(): Effect.Effect<string, AIError, Service>;
|
|
70
72
|
/**
|
|
@@ -115,7 +117,7 @@ export declare namespace Asset {
|
|
|
115
117
|
readonly info?: Info;
|
|
116
118
|
readonly providerMetadata?: ProviderMetadata;
|
|
117
119
|
/**
|
|
118
|
-
* Headers required to download a `url` source, such as
|
|
120
|
+
* Headers required to download a `url` source, such as a provider API key.
|
|
119
121
|
* They are runtime-only: never part of `source`, `toJSON()`, or `AssetSchema`, so a persisted asset cannot leak
|
|
120
122
|
* credentials and cannot be downloaded again after a round-trip. Call `materialize()` before persisting.
|
|
121
123
|
*/
|
|
@@ -211,5 +213,9 @@ export type Input = Asset | Data;
|
|
|
211
213
|
export declare const make: (input: Input, mediaType?: string) => Asset;
|
|
212
214
|
/** Read a file through `FileSystem` and sniff its media type from magic bytes, then the extension. */
|
|
213
215
|
export declare const file: (path: string, options?: AssetOptions) => Effect.Effect<Asset, AIError, FileSystem.FileSystem>;
|
|
214
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Stream an asset's bytes into a file through `FileSystem` without buffering `url` downloads. The bytes go to a temporary
|
|
218
|
+
* file next to `path` that replaces it only once the download finished, so a failed download leaves an existing file as
|
|
219
|
+
* it was.
|
|
220
|
+
*/
|
|
215
221
|
export declare const write: (asset: Asset, path: string) => Effect.Effect<void, AIError, FileSystem.FileSystem | Service>;
|
package/dist/media.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * as Media from "./media.js";
|
|
2
|
-
import { Effect, FileSystem, Result, Schema, SchemaGetter } from "effect";
|
|
2
|
+
import { Effect, FileSystem, Result, Schema, SchemaGetter, Stream } from "effect";
|
|
3
3
|
import { Base64 } from "effect/encoding";
|
|
4
4
|
import { HttpClientRequest } from "effect/http";
|
|
5
5
|
import { ProviderID } from "./schema/ids.js";
|
|
@@ -29,7 +29,7 @@ const UrlSource = Schema.Struct({
|
|
|
29
29
|
/** Epoch milliseconds after which the provider no longer serves the URL. */
|
|
30
30
|
expiresAt: Schema.optional(Schema.Number),
|
|
31
31
|
});
|
|
32
|
-
/** A provider-side handle: OpenAI `file_id`, Gemini file URI, `gs://`,
|
|
32
|
+
/** A provider-side handle: OpenAI `file_id`, Gemini file URI, `gs://`, or a prior generation id. */
|
|
33
33
|
const RefSource = Schema.Struct({
|
|
34
34
|
type: Schema.Literal("ref"),
|
|
35
35
|
provider: ProviderID,
|
|
@@ -120,6 +120,13 @@ export class Asset {
|
|
|
120
120
|
return decoded.pipe(Effect.tap((data) => Effect.sync(() => (this.#bytes = data))));
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
+
/** The payload as a byte stream; `url` sources stream from the network without being buffered or cached. */
|
|
124
|
+
stream() {
|
|
125
|
+
const source = this.source;
|
|
126
|
+
if (source.type !== "url" || this.#bytes !== undefined)
|
|
127
|
+
return Stream.fromEffect(this.bytes());
|
|
128
|
+
return Stream.unwrap(downloadStream(source, this.headers));
|
|
129
|
+
}
|
|
123
130
|
base64() {
|
|
124
131
|
return Effect.suspend(() => {
|
|
125
132
|
const source = this.source;
|
|
@@ -183,6 +190,17 @@ const download = Effect.fn("Media.download")(function* (source, headers) {
|
|
|
183
190
|
})));
|
|
184
191
|
return new Uint8Array(buffer);
|
|
185
192
|
});
|
|
193
|
+
const downloadStream = Effect.fn("Media.downloadStream")(function* (source, headers) {
|
|
194
|
+
const executor = yield* Service;
|
|
195
|
+
const response = yield* executor.execute(HttpClientRequest.get(source.url).pipe(HttpClientRequest.setHeaders(headers ?? {})));
|
|
196
|
+
return response.stream.pipe(Stream.mapError((cause) => new AIError({
|
|
197
|
+
reason: new InvalidProviderOutputError({
|
|
198
|
+
message: `Failed to read media from ${source.url}`,
|
|
199
|
+
http: responseHttp(response),
|
|
200
|
+
cause,
|
|
201
|
+
}),
|
|
202
|
+
})));
|
|
203
|
+
});
|
|
186
204
|
export const from = (source, options) => new Asset({ ...options, source });
|
|
187
205
|
export const bytes = (data, mediaType, options) => from({ type: "bytes", data, mediaType: mediaType ?? detectMediaType(data) ?? OCTET_STREAM }, options);
|
|
188
206
|
export const base64 = (data, mediaType, options) => from({ type: "base64", data, mediaType }, options);
|
|
@@ -247,11 +265,13 @@ export const file = (path, options) => Effect.gen(function* () {
|
|
|
247
265
|
.pipe(Effect.mapError((cause) => invalid(`Failed to read media file ${path}`, cause)));
|
|
248
266
|
return bytes(data, fileMediaType(data, path), options);
|
|
249
267
|
});
|
|
250
|
-
/**
|
|
268
|
+
/**
|
|
269
|
+
* Stream an asset's bytes into a file through `FileSystem` without buffering `url` downloads. The bytes go to a temporary
|
|
270
|
+
* file next to `path` that replaces it only once the download finished, so a failed download leaves an existing file as
|
|
271
|
+
* it was.
|
|
272
|
+
*/
|
|
251
273
|
export const write = (asset, path) => Effect.gen(function* () {
|
|
252
274
|
const fs = yield* FileSystem.FileSystem;
|
|
253
|
-
const
|
|
254
|
-
yield* fs
|
|
255
|
-
.writeFile(path, data)
|
|
256
|
-
.pipe(Effect.mapError((cause) => invalid(`Failed to write media file ${path}`, cause)));
|
|
275
|
+
const temporary = `${path}.${crypto.randomUUID()}.tmp`;
|
|
276
|
+
yield* asset.stream().pipe(Stream.run(fs.sink(temporary)), Effect.andThen(fs.rename(temporary, path)), Effect.onError(() => fs.remove(temporary).pipe(Effect.ignore)), Effect.mapError((cause) => cause instanceof AIError ? cause : invalid(`Failed to write media file ${path}`, cause)));
|
|
257
277
|
});
|
|
@@ -137,6 +137,7 @@ export declare const protocol: Protocol<{
|
|
|
137
137
|
readonly reasoning?: string | undefined;
|
|
138
138
|
readonly reasoning_text?: string | undefined;
|
|
139
139
|
readonly reasoning_details?: unknown;
|
|
140
|
+
readonly reasoning_opaque?: string | undefined;
|
|
140
141
|
})[];
|
|
141
142
|
readonly tools?: readonly ({
|
|
142
143
|
readonly type: "function";
|
|
@@ -243,6 +244,7 @@ export declare const protocol: Protocol<{
|
|
|
243
244
|
readonly reasoning?: string | null | undefined;
|
|
244
245
|
readonly reasoning_text?: string | null | undefined;
|
|
245
246
|
readonly reasoning_details?: unknown;
|
|
247
|
+
readonly reasoning_opaque?: string | null | undefined;
|
|
246
248
|
readonly tool_calls?: readonly {
|
|
247
249
|
readonly index?: number | null | undefined;
|
|
248
250
|
readonly id?: string | null | undefined;
|
|
@@ -268,6 +270,7 @@ export declare const protocol: Protocol<{
|
|
|
268
270
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
269
271
|
readonly cache_read_input_tokens?: number | null | undefined;
|
|
270
272
|
readonly cache_created_input_tokens?: number | null | undefined;
|
|
273
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
271
274
|
readonly prompt_tokens_details?: {
|
|
272
275
|
readonly [x: string]: unknown;
|
|
273
276
|
readonly cached_tokens?: number | null | undefined;
|
|
@@ -290,6 +293,7 @@ export declare const protocol: Protocol<{
|
|
|
290
293
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
291
294
|
readonly cache_read_input_tokens?: number | null | undefined;
|
|
292
295
|
readonly cache_created_input_tokens?: number | null | undefined;
|
|
296
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
293
297
|
readonly prompt_tokens_details?: {
|
|
294
298
|
readonly [x: string]: unknown;
|
|
295
299
|
readonly cached_tokens?: number | null | undefined;
|
|
@@ -878,7 +878,7 @@ const mapFinishReason = (reason) => {
|
|
|
878
878
|
// inclusive `inputTokens` the rest of the contract expects. Extended
|
|
879
879
|
// thinking tokens are included in `output_tokens`; newer responses also
|
|
880
880
|
// expose that subset through `output_tokens_details.thinking_tokens`.
|
|
881
|
-
const mapUsage = (usage, providerMetadataKey) => {
|
|
881
|
+
const mapUsage = (usage, providerMetadataKey, frame) => {
|
|
882
882
|
if (!usage)
|
|
883
883
|
return undefined;
|
|
884
884
|
const iterations = usage.iterations?.length ? usage.iterations : [usage];
|
|
@@ -899,7 +899,7 @@ const mapUsage = (usage, providerMetadataKey) => {
|
|
|
899
899
|
cacheWriteInputTokens: cacheWrite,
|
|
900
900
|
reasoningTokens: ProviderShared.sumTokens(...iterations.map((item) => item.output_tokens_details?.thinking_tokens)),
|
|
901
901
|
totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
|
|
902
|
-
...ProviderShared.reportedBilling(usage),
|
|
902
|
+
...ProviderShared.reportedBilling(usage, frame),
|
|
903
903
|
providerMetadata: { [providerMetadataKey]: usage },
|
|
904
904
|
});
|
|
905
905
|
};
|
|
@@ -1128,7 +1128,7 @@ const onContentBlockStop = Effect.fnUntraced(function* (state, event) {
|
|
|
1128
1128
|
return [{ ...state, lifecycle, tools: result.tools, reasoningSignatures }, events];
|
|
1129
1129
|
});
|
|
1130
1130
|
const onMessageDelta = (state, event) => {
|
|
1131
|
-
const usage = mergeUsage(state.usage, mapUsage(event.usage, state.providerMetadataKey), state.providerMetadataKey);
|
|
1131
|
+
const usage = mergeUsage(state.usage, mapUsage(event.usage, state.providerMetadataKey, event), state.providerMetadataKey);
|
|
1132
1132
|
const pendingFinish = (() => {
|
|
1133
1133
|
const stopReason = event.delta?.stop_reason;
|
|
1134
1134
|
if (stopReason === null || stopReason === undefined)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
3
|
+
import { type ProviderOptions } from "../schema/index.js";
|
|
4
|
+
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
5
|
+
declare const Options: Schema.Struct<{
|
|
6
|
+
/** Token budget for every image and video input; `ultra_high` applies to images only. */
|
|
7
|
+
readonly mediaResolution: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "medium" | "ultra_high">, import("../schema/options.js").OpenString<"high" | "low" | "medium" | "ultra_high">>>;
|
|
8
|
+
}>;
|
|
9
|
+
/** Known fields map to their wire names; anything else is sent as given. */
|
|
10
|
+
export type OptionsInput = ProviderOptions & typeof Options.Encoded;
|
|
11
|
+
export declare const protocol: DecisionRoute.Protocol;
|
|
12
|
+
export declare const route: DecisionRoute.Route;
|
|
13
|
+
export * as GoogleDecisions from "./google-decisions.js";
|