@opencode/ai 2.2.5 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -72
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +30 -125
- package/dist/decision.js +27 -15
- package/dist/effect.d.ts +10 -15
- package/dist/effect.js +6 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/embedding-client.d.ts +21 -0
- package/dist/embedding-client.js +30 -0
- package/dist/embedding.d.ts +111 -0
- package/dist/embedding.js +75 -0
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -465
- package/dist/image.js +17 -18
- package/dist/index.d.ts +35 -467
- package/dist/index.js +23 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +9 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -176
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +54 -72
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +7 -10
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +2 -22
- package/dist/protocols/open-responses.js +41 -23
- package/dist/protocols/openai-chat.d.ts +27 -23
- package/dist/protocols/openai-chat.js +62 -57
- package/dist/protocols/openai-compatible-chat.d.ts +2 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +15 -2
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +14 -7
- package/dist/protocols/shared.js +40 -15
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/system-one.js +8 -1
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +7 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +9 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +7 -80
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba.d.ts +70 -4
- package/dist/providers/alibaba.js +20 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +7 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +325 -7
- package/dist/providers/azure.js +40 -9
- package/dist/providers/baseten.d.ts +7 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +7 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +23 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +6 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +14 -5
- package/dist/providers/cohere.js +23 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +10 -5
- package/dist/providers/deepinfra.js +20 -14
- package/dist/providers/deepseek.d.ts +7 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean.d.ts +18 -5
- package/dist/providers/digitalocean.js +28 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +10 -5
- package/dist/providers/fireworks.js +17 -14
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex/embeddings.d.ts +2 -0
- package/dist/providers/google-vertex/embeddings.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +4 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +10 -3
- package/dist/providers/google-vertex.js +52 -0
- package/dist/providers/google.d.ts +21 -13
- package/dist/providers/google.js +23 -19
- package/dist/providers/groq.d.ts +10 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +6 -5
- package/dist/providers/meta.js +10 -23
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +6 -5
- package/dist/providers/minimax.js +7 -22
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +6 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
- package/dist/providers/openai-compatible/embeddings.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +10 -7
- package/dist/providers/openai-compatible.js +17 -10
- package/dist/providers/openai.d.ts +11 -4
- package/dist/providers/openai.js +17 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter.d.ts +24 -5
- package/dist/providers/openrouter.js +31 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +7 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +5 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +9 -5
- package/dist/providers/vercel-ai-gateway.js +30 -29
- package/dist/providers/xai.d.ts +5 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +6 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +6 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +14 -0
- package/dist/public.js +6 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/embedding.d.ts +61 -0
- package/dist/route/embedding.js +88 -0
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +309 -257
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
|
@@ -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
|
+
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { ExtractionModel, ExtractionResponse, type
|
|
1
|
+
import { ExtractionModel, ExtractionResponse, type ExtractionRequest } from "./extraction.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
/** Posts Clairic's `{ model, state, fields }` body to Cloudflare's `/ai/run/{model}`. */
|
|
5
|
-
export declare const protocol: MediaProtocol.Inline<
|
|
5
|
+
export declare const protocol: MediaProtocol.Inline<ExtractionRequest<ExtractionModel<{
|
|
6
|
+
readonly [x: string]: unknown;
|
|
7
|
+
}>, Readonly<Record<string, import("./extraction.js").ExtractionField>>>, ExtractionResponse>;
|
|
6
8
|
/** `baseURL` is the Run API base, `.../client/v4/accounts/{account}/ai/run`. */
|
|
7
9
|
export declare const model: (input: MediaRoute.ModelInput) => ExtractionModel<{
|
|
8
10
|
readonly [x: string]: unknown;
|
|
9
11
|
}>;
|
|
10
12
|
export declare const CloudflareRunExtraction: {
|
|
11
|
-
readonly protocol: MediaProtocol.Inline<
|
|
13
|
+
readonly protocol: MediaProtocol.Inline<ExtractionRequest<ExtractionModel<{
|
|
14
|
+
readonly [x: string]: unknown;
|
|
15
|
+
}>, Readonly<Record<string, import("./extraction.js").ExtractionField>>>, ExtractionResponse>;
|
|
12
16
|
readonly model: typeof model;
|
|
13
17
|
};
|
|
@@ -16,7 +16,10 @@ const decodeEnvelope = route.decodeJson(Schema.Struct({
|
|
|
16
16
|
answers: Schema.Record(Schema.String, JsonObject),
|
|
17
17
|
truncated: Schema.optional(Schema.Boolean),
|
|
18
18
|
state_text: Schema.optional(Schema.String),
|
|
19
|
-
usage: Schema.optional(Schema.StructWithRest(Schema.Struct({
|
|
19
|
+
usage: Schema.optional(Schema.StructWithRest(Schema.Struct({
|
|
20
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
21
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
22
|
+
}), [JsonObject])),
|
|
20
23
|
}),
|
|
21
24
|
}));
|
|
22
25
|
/** Posts Clairic's `{ model, state, fields }` body to Cloudflare's `/ai/run/{model}`. */
|
|
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { MediaModel } from "../media-model.js";
|
|
3
3
|
import { RequestExecutor } from "../route/executor.js";
|
|
4
4
|
import type { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { AIError,
|
|
5
|
+
import { AIError, Usage, type BaseRequest, type OpenString } from "../schema/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* The answer schema for each field type Clairic documents, decoding its wire keys (`p_null` and friends). Answers to
|
|
8
8
|
* other field types pass through as sent.
|
|
@@ -116,50 +116,22 @@ export type ExtractionField = typeof ExtractionFieldSchema.Type & {
|
|
|
116
116
|
};
|
|
117
117
|
export type ExtractionFields = Readonly<Record<string, ExtractionField>>;
|
|
118
118
|
export type ExtractionOptions = MediaModel.Options;
|
|
119
|
-
export type ExtractionRoute = MediaRoute.InlineRoute<
|
|
119
|
+
export type ExtractionRoute = MediaRoute.InlineRoute<ExtractionRequest, ExtractionResponse>;
|
|
120
120
|
export declare class ExtractionModel<Options extends ExtractionOptions = ExtractionOptions> extends MediaModel<ExtractionRoute, Options> {
|
|
121
121
|
protected readonly _ExtractionModel: void;
|
|
122
122
|
}
|
|
123
123
|
export type ExtractionModelOptions<Model> = Model extends ExtractionModel<infer Options> ? Options : never;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
readonly [x: string]: unknown;
|
|
127
|
-
}>, unknown>;
|
|
124
|
+
/** A normalized extraction request, the plain object `Extraction.request(...)` returns. */
|
|
125
|
+
export interface ExtractionRequest<Model extends ExtractionModel = ExtractionModel, Fields extends ExtractionFields = ExtractionFields> extends BaseRequest<Model, ExtractionModelOptions<Model>> {
|
|
128
126
|
/** The text to read; text answers carry spans into it. */
|
|
129
|
-
readonly input: Schema.String;
|
|
130
|
-
readonly fields: Schema.refine<{
|
|
131
|
-
readonly [x: string]: {
|
|
132
|
-
readonly [x: string]: unknown;
|
|
133
|
-
readonly type: string;
|
|
134
|
-
readonly instructions?: string | undefined;
|
|
135
|
-
readonly nullThreshold?: number | undefined;
|
|
136
|
-
};
|
|
137
|
-
}, Schema.$Record<Schema.String, Schema.StructWithRest<Schema.Struct<{
|
|
138
|
-
readonly type: Schema.String;
|
|
139
|
-
readonly instructions: Schema.optional<Schema.String>;
|
|
140
|
-
/** Probability of null above which the value is null; the host's default is 0.5. */
|
|
141
|
-
readonly nullThreshold: Schema.optional<Schema.Number>;
|
|
142
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
|
|
143
|
-
/** ISO date that anchors dates written without a year. */
|
|
144
|
-
readonly referenceDate: Schema.optional<Schema.String>;
|
|
145
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
146
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
147
|
-
}>, {}>;
|
|
148
|
-
export declare class ExtractionRequest extends ExtractionRequest_base {
|
|
149
|
-
protected readonly _ExtractionRequest: void;
|
|
150
|
-
}
|
|
151
|
-
export type ExtractionRequestFor<Options extends ExtractionOptions = ExtractionOptions, Fields extends ExtractionFields = ExtractionFields> = Omit<ExtractionRequest, "model" | "fields" | "providerOptions"> & {
|
|
152
|
-
readonly model: ExtractionModel<Options>;
|
|
153
|
-
readonly fields: Fields;
|
|
154
|
-
readonly providerOptions?: Options;
|
|
155
|
-
};
|
|
156
|
-
export type ExtractionRequestInput<Model extends ExtractionModel = ExtractionModel, Fields extends ExtractionFields = ExtractionFields> = {
|
|
157
|
-
readonly model: Model;
|
|
158
127
|
readonly input: string;
|
|
159
128
|
readonly fields: Fields;
|
|
129
|
+
/** ISO date that anchors dates written without a year. */
|
|
160
130
|
readonly referenceDate?: string;
|
|
131
|
+
}
|
|
132
|
+
/** Input accepted by `Extraction.request` and `generate`; an `ExtractionRequest` is also a valid input. */
|
|
133
|
+
export type ExtractionRequestInput<Model extends ExtractionModel = ExtractionModel, Fields extends ExtractionFields = ExtractionFields> = Omit<ExtractionRequest<Model, Fields>, "providerOptions"> & {
|
|
161
134
|
readonly providerOptions?: NoInfer<ExtractionModelOptions<Model>>;
|
|
162
|
-
readonly http?: HttpOptions.Input;
|
|
163
135
|
};
|
|
164
136
|
declare const ExtractionResponse_base: Schema.Class<ExtractionResponse, Schema.Struct<{
|
|
165
137
|
readonly answers: Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
@@ -171,11 +143,9 @@ export declare class ExtractionResponse extends ExtractionResponse_base {
|
|
|
171
143
|
export type ExtractionResponseFor<Fields extends ExtractionFields> = Omit<ExtractionResponse, "answers"> & {
|
|
172
144
|
readonly answers: ExtractionAnswersFor<Fields>;
|
|
173
145
|
};
|
|
174
|
-
|
|
175
|
-
export declare
|
|
176
|
-
export declare function request(input: ExtractionRequest | ExtractionRequestInput): ExtractionRequest;
|
|
146
|
+
/** Normalize extraction request input into a plain `ExtractionRequest`. */
|
|
147
|
+
export declare const request: <const Model extends ExtractionModel, const Fields extends ExtractionFields>(input: ExtractionRequestInput<Model, Fields>) => ExtractionRequest<Model, Fields>;
|
|
177
148
|
export declare function generate<const Model extends ExtractionModel, const Fields extends ExtractionFields>(input: ExtractionRequestInput<Model, Fields>): Effect.Effect<ExtractionResponseFor<Fields>, AIError, RequestExecutor.Service>;
|
|
178
|
-
export declare function generate(input: ExtractionRequest): Effect.Effect<ExtractionResponse, AIError, RequestExecutor.Service>;
|
|
179
149
|
export declare const Extraction: {
|
|
180
150
|
readonly request: typeof request;
|
|
181
151
|
readonly generate: typeof generate;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { MediaModel, tryRequest } from "../media-model.js";
|
|
3
3
|
import { RequestExecutor } from "../route/executor.js";
|
|
4
|
-
import { AIError,
|
|
4
|
+
import { AIError, ProviderMetadata, ProviderOptions, Usage, } from "../schema/index.js";
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
6
|
// Answers
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
@@ -65,34 +65,35 @@ export class ExtractionModel extends MediaModel {
|
|
|
65
65
|
// ---------------------------------------------------------------------------
|
|
66
66
|
// Request and response
|
|
67
67
|
// ---------------------------------------------------------------------------
|
|
68
|
-
|
|
68
|
+
const ExtractionRequestSchema = Schema.Struct({
|
|
69
69
|
model: Schema.declare((value) => value instanceof ExtractionModel, {
|
|
70
70
|
expected: "Extraction.Model",
|
|
71
71
|
}),
|
|
72
|
-
/** The text to read; text answers carry spans into it. */
|
|
73
72
|
input: Schema.String,
|
|
74
73
|
fields: Schema.Record(Schema.String, ExtractionFieldSchema).pipe(Schema.refine((x) => Object.keys(x).length > 0, { message: "Extraction fields must not be empty" })),
|
|
75
|
-
/** ISO date that anchors dates written without a year. */
|
|
76
74
|
referenceDate: Schema.optional(Schema.String),
|
|
77
75
|
providerOptions: Schema.optional(ProviderOptions),
|
|
78
|
-
|
|
79
|
-
}) {
|
|
80
|
-
}
|
|
76
|
+
});
|
|
81
77
|
export class ExtractionResponse extends Schema.Class("Extraction.Response")({
|
|
82
78
|
answers: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown)),
|
|
83
79
|
usage: Schema.optional(Usage),
|
|
84
80
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
85
81
|
}) {
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Call API
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
/** Normalize extraction request input into a plain `ExtractionRequest`. */
|
|
87
|
+
export const request = (input) => ({ ...input });
|
|
88
|
+
const validate = Schema.decodeUnknownSync(ExtractionRequestSchema);
|
|
92
89
|
export function generate(input) {
|
|
93
90
|
return Effect.gen(function* () {
|
|
94
91
|
const executor = yield* RequestExecutor.Service;
|
|
95
|
-
const built = yield* tryRequest(() =>
|
|
92
|
+
const built = yield* tryRequest(() => {
|
|
93
|
+
const normalized = request(input);
|
|
94
|
+
validate(normalized);
|
|
95
|
+
return normalized;
|
|
96
|
+
});
|
|
96
97
|
return yield* built.model.route.generate(built, executor.execute);
|
|
97
98
|
});
|
|
98
99
|
}
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema,
|
|
3
|
-
export type { VideoModelOptions, VideoOptions,
|
|
2
|
+
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
|
+
export type { VideoModelOptions, VideoOptions, VideoRequest, VideoRequestInput, VideoResolution, VideoRoute, } from "./video.js";
|
|
4
4
|
export { Video } from "./video.js";
|
|
5
5
|
export { SpeechClient } from "./speech-client.js";
|
|
6
|
-
export { SpeechEvent, SpeechModel, SpeechModelSchema,
|
|
7
|
-
export type { SpeechFormat, SpeechModelOptions, SpeechOptions,
|
|
6
|
+
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
7
|
+
export type { SpeechFormat, SpeechModelOptions, SpeechOptions, SpeechRequest, SpeechRequestInput, SpeechRoute, } from "./speech.js";
|
|
8
8
|
export { Speech } from "./speech.js";
|
|
9
9
|
export { TranscriptionClient } from "./transcription-client.js";
|
|
10
|
-
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema,
|
|
11
|
-
export type { TranscriptionModelOptions, TranscriptionOptions,
|
|
10
|
+
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema, TranscriptionResponse, TranscriptionSegment, TranscriptionTimestamps, TranscriptionWord, } from "./transcription.js";
|
|
11
|
+
export type { TranscriptionModelOptions, TranscriptionOptions, TranscriptionRequest, TranscriptionRequestInput, TranscriptionRoute, } from "./transcription.js";
|
|
12
12
|
export { Transcription } from "./transcription.js";
|
|
13
|
-
export { Extraction, ExtractionModel,
|
|
14
|
-
export type { ExtractionAnswerFor, ExtractionAnswersFor, ExtractionField, ExtractionFields, ExtractionModelOptions, ExtractionOptions,
|
|
13
|
+
export { Extraction, ExtractionModel, ExtractionResponse } from "./experimental/extraction.js";
|
|
14
|
+
export type { ExtractionAnswerFor, ExtractionAnswersFor, ExtractionField, ExtractionFields, ExtractionModelOptions, ExtractionOptions, ExtractionRequest, ExtractionRequestInput, ExtractionResponseFor, ExtractionRoute, } from "./experimental/extraction.js";
|
|
15
15
|
export { Realtime } from "./experimental/realtime.js";
|
|
16
16
|
export type { RealtimeConnectInput, RealtimeSession, RealtimeTransport, RealtimeTransportInput, RealtimeTransportType, } from "./experimental/realtime.js";
|
package/dist/experimental.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema,
|
|
2
|
+
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
3
|
export { Video } from "./video.js";
|
|
4
4
|
export { SpeechClient } from "./speech-client.js";
|
|
5
|
-
export { SpeechEvent, SpeechModel, SpeechModelSchema,
|
|
5
|
+
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
6
6
|
export { Speech } from "./speech.js";
|
|
7
7
|
export { TranscriptionClient } from "./transcription-client.js";
|
|
8
|
-
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema,
|
|
8
|
+
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema, TranscriptionResponse, TranscriptionSegment, TranscriptionTimestamps, TranscriptionWord, } from "./transcription.js";
|
|
9
9
|
export { Transcription } from "./transcription.js";
|
|
10
|
-
export { Extraction, ExtractionModel,
|
|
10
|
+
export { Extraction, ExtractionModel, ExtractionResponse } from "./experimental/extraction.js";
|
|
11
11
|
export { Realtime } from "./experimental/realtime.js";
|
package/dist/generation.d.ts
CHANGED
|
@@ -26,8 +26,6 @@ export interface Poll {
|
|
|
26
26
|
export interface AwaitOptions {
|
|
27
27
|
readonly poll?: Poll;
|
|
28
28
|
}
|
|
29
|
-
export declare const DEFAULT_POLL_INTERVAL: Duration.Duration;
|
|
30
|
-
export declare const DEFAULT_POLL_TIMEOUT: Duration.Duration;
|
|
31
29
|
export declare const QueuedEvent: Schema.Struct<{
|
|
32
30
|
readonly type: Schema.tag<"generation-queued">;
|
|
33
31
|
readonly id: Schema.String;
|
package/dist/generation.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Clock, Duration, Effect, Schedule, Schema, Stream } from "effect";
|
|
2
2
|
import { AIError, TimeoutError } from "./schema/errors.js";
|
|
3
3
|
export const Status = Schema.Literals(["queued", "running", "completed", "failed", "cancelled", "expired"]);
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const DEFAULT_POLL_INTERVAL = Duration.seconds(5);
|
|
5
|
+
const DEFAULT_POLL_TIMEOUT = Duration.minutes(10);
|
|
6
6
|
export const QueuedEvent = Schema.Struct({
|
|
7
7
|
type: Schema.tag("generation-queued"),
|
|
8
8
|
id: Schema.String,
|
package/dist/image-client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import { type ImageEvent, type
|
|
4
|
-
export type Interface = MediaClient.Interface<
|
|
3
|
+
import { type ImageEvent, type ImageRequest, type ImageResponse } from "./image.js";
|
|
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 {
|
|
7
7
|
}
|
|
@@ -54,8 +54,12 @@ export declare const ImageClient: {
|
|
|
54
54
|
} | undefined;
|
|
55
55
|
})[];
|
|
56
56
|
readonly layer: import("effect/Layer").Layer<ImageClientService, never, import("./route.js").RequestExecutorService>;
|
|
57
|
-
readonly generate: (request:
|
|
58
|
-
|
|
57
|
+
readonly generate: (request: ImageRequest<import("./image.js").ImageModel<{
|
|
58
|
+
readonly [x: string]: unknown;
|
|
59
|
+
}>>, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<ImageResponse, import("./public.js").AIError, ImageClientService>;
|
|
60
|
+
readonly stream: (request: ImageRequest<import("./image.js").ImageModel<{
|
|
61
|
+
readonly [x: string]: unknown;
|
|
62
|
+
}>>, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
|
|
59
63
|
readonly type: "image-partial";
|
|
60
64
|
readonly index: number;
|
|
61
65
|
readonly image: import("./media.js").Asset;
|
|
@@ -91,11 +95,13 @@ export declare const ImageClient: {
|
|
|
91
95
|
readonly [x: string]: unknown;
|
|
92
96
|
};
|
|
93
97
|
} | undefined;
|
|
94
|
-
} | import("./generation.js").Observation, import("./
|
|
95
|
-
readonly start: (request:
|
|
98
|
+
} | import("./generation.js").Observation, import("./public.js").AIError, ImageClientService>;
|
|
99
|
+
readonly start: (request: ImageRequest<import("./image.js").ImageModel<{
|
|
100
|
+
readonly [x: string]: unknown;
|
|
101
|
+
}>>) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./public.js").AIError, ImageClientService>;
|
|
96
102
|
readonly resume: (model: import("./image.js").ImageModel<{
|
|
97
103
|
readonly [x: string]: unknown;
|
|
98
|
-
}>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./
|
|
104
|
+
}>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./public.js").AIError, ImageClientService>;
|
|
99
105
|
readonly Service: typeof ImageClientService;
|
|
100
106
|
};
|
|
101
107
|
export {};
|
package/dist/image-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import { ImageOutputEvent, ImageFinishEvent
|
|
3
|
+
import { ImageOutputEvent, ImageFinishEvent } from "./image.js";
|
|
4
4
|
export class ImageClientService extends Context.Service()("@opencode/ImageClient") {
|
|
5
5
|
}
|
|
6
6
|
export const Service = ImageClientService;
|