@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
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import type { DecisionOptions, DecisionQuestions,
|
|
2
|
+
import type { DecisionModel, DecisionOptions, DecisionQuestions, DecisionRequest, DecisionResponseFor } from "./decision.js";
|
|
3
3
|
import { RequestExecutor } from "./route/executor.js";
|
|
4
4
|
import { AIError } from "./schema/index.js";
|
|
5
5
|
export type Execute = RequestExecutor.Interface["execute"];
|
|
6
6
|
export interface Interface {
|
|
7
|
-
readonly generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request:
|
|
7
|
+
readonly generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request: DecisionRequest<DecisionModel<Options>, Questions>) => Effect.Effect<DecisionResponseFor<Questions>, AIError>;
|
|
8
8
|
}
|
|
9
9
|
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/DecisionClient", Interface>;
|
|
10
10
|
export declare class Service extends Service_base {
|
|
11
11
|
}
|
|
12
|
-
export declare const generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request:
|
|
12
|
+
export declare const generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request: DecisionRequest<DecisionModel<Options>, Questions>) => Effect.Effect<DecisionResponseFor<Questions>, AIError, Service>;
|
|
13
13
|
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
14
14
|
export declare const fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
|
|
15
15
|
export declare const DecisionClient: {
|
package/dist/decision.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Service, type Execute } from "./decision-client.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
|
-
import { AIError, HttpOptions, ModelID, ProviderID, ProviderOptions, type OpenString } from "./schema/index.js";
|
|
4
|
+
import { AIError, type BaseRequest, type HttpOptions, ModelID, ProviderID, ProviderOptions, type OpenString } from "./schema/index.js";
|
|
5
5
|
export declare const DecisionTextPart: Schema.Struct<{
|
|
6
6
|
readonly type: Schema.Literal<"text">;
|
|
7
7
|
readonly text: Schema.String;
|
|
@@ -87,8 +87,16 @@ export declare const DecisionPart: Schema.toTaggedUnion<"type", readonly [Schema
|
|
|
87
87
|
readonly filename: Schema.optional<Schema.String>;
|
|
88
88
|
}>]>;
|
|
89
89
|
export type DecisionPart = Schema.Schema.Type<typeof DecisionPart>;
|
|
90
|
+
/** A media part as input: `media` may be plain data, with `mediaType` naming its type when the content can't. */
|
|
91
|
+
export type DecisionMediaPartInput = Omit<typeof DecisionMediaPart.Type, "media"> & {
|
|
92
|
+
readonly media: Media.Input;
|
|
93
|
+
readonly mediaType?: string;
|
|
94
|
+
};
|
|
95
|
+
export type DecisionPartInput = Exclude<DecisionPart, {
|
|
96
|
+
readonly type: "media";
|
|
97
|
+
}> | DecisionMediaPartInput;
|
|
90
98
|
/** A plain object is one `json` part. */
|
|
91
|
-
export type DecisionInput = typeof Schema.JsonObject.Type | ReadonlyArray<
|
|
99
|
+
export type DecisionInput = typeof Schema.JsonObject.Type | ReadonlyArray<DecisionPartInput>;
|
|
92
100
|
/** Choice values are typed: `true` and `"true"` are different values. */
|
|
93
101
|
export declare const ChoiceValue: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
|
|
94
102
|
export type ChoiceValue = Schema.Schema.Type<typeof ChoiceValue>;
|
|
@@ -96,6 +104,11 @@ export declare const PredicateQuestion: Schema.Struct<{
|
|
|
96
104
|
readonly name: Schema.String;
|
|
97
105
|
readonly type: Schema.Literal<"predicate">;
|
|
98
106
|
readonly instructions: Schema.String;
|
|
107
|
+
/** What counts as true and as false, for statements the instructions alone leave ambiguous. */
|
|
108
|
+
readonly criteria: Schema.optional<Schema.Struct<{
|
|
109
|
+
readonly true: Schema.optional<Schema.String>;
|
|
110
|
+
readonly false: Schema.optional<Schema.String>;
|
|
111
|
+
}>>;
|
|
99
112
|
}>;
|
|
100
113
|
export type PredicateQuestion = Schema.Schema.Type<typeof PredicateQuestion>;
|
|
101
114
|
export declare const ChoiceQuestion: Schema.Struct<{
|
|
@@ -122,6 +135,11 @@ export declare const DecisionQuestion: Schema.toTaggedUnion<"type", readonly [Sc
|
|
|
122
135
|
readonly name: Schema.String;
|
|
123
136
|
readonly type: Schema.Literal<"predicate">;
|
|
124
137
|
readonly instructions: Schema.String;
|
|
138
|
+
/** What counts as true and as false, for statements the instructions alone leave ambiguous. */
|
|
139
|
+
readonly criteria: Schema.optional<Schema.Struct<{
|
|
140
|
+
readonly true: Schema.optional<Schema.String>;
|
|
141
|
+
readonly false: Schema.optional<Schema.String>;
|
|
142
|
+
}>>;
|
|
125
143
|
}>, Schema.Struct<{
|
|
126
144
|
readonly name: Schema.String;
|
|
127
145
|
readonly type: Schema.Literal<"choice">;
|
|
@@ -245,7 +263,7 @@ export type DecisionOptions = Record<string, unknown>;
|
|
|
245
263
|
/** What a decision model's route does; `DecisionRoute.make(...).model(...)` builds one from a protocol. */
|
|
246
264
|
export interface DecisionModelRoute<Options extends DecisionOptions = DecisionOptions> {
|
|
247
265
|
readonly id: string;
|
|
248
|
-
generate(request:
|
|
266
|
+
generate(request: DecisionRequest<DecisionModel<Options>>, execute: Execute): Effect.Effect<DecisionResponse, AIError>;
|
|
249
267
|
}
|
|
250
268
|
declare const DecisionModelCompatibility_base: Schema.Class<DecisionModelCompatibility, Schema.Struct<{
|
|
251
269
|
/**
|
|
@@ -290,128 +308,16 @@ export declare namespace DecisionModel {
|
|
|
290
308
|
}
|
|
291
309
|
export declare const DecisionModelSchema: Schema.declare<DecisionModel<DecisionOptions>, DecisionModel<DecisionOptions>>;
|
|
292
310
|
export type DecisionModelOptions<Model> = Model extends DecisionModel<infer Options> ? Options : never;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
readonly input:
|
|
296
|
-
readonly type: Schema.Literal<"text">;
|
|
297
|
-
readonly text: Schema.String;
|
|
298
|
-
}>, Schema.Struct<{
|
|
299
|
-
readonly type: Schema.Literal<"json">;
|
|
300
|
-
readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
301
|
-
}>, Schema.Struct<{
|
|
302
|
-
readonly type: Schema.Literal<"media">;
|
|
303
|
-
readonly media: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
304
|
-
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
305
|
-
readonly type: Schema.Literal<"bytes">;
|
|
306
|
-
readonly data: Schema.Uint8Array;
|
|
307
|
-
readonly mediaType: Schema.String;
|
|
308
|
-
}>, Schema.Struct<{
|
|
309
|
-
readonly type: Schema.Literal<"base64">;
|
|
310
|
-
readonly data: Schema.String;
|
|
311
|
-
readonly mediaType: Schema.String;
|
|
312
|
-
}>, Schema.Struct<{
|
|
313
|
-
readonly type: Schema.Literal<"url">;
|
|
314
|
-
readonly url: Schema.String;
|
|
315
|
-
readonly mediaType: Schema.optional<Schema.String>;
|
|
316
|
-
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
317
|
-
}>, Schema.Struct<{
|
|
318
|
-
readonly type: Schema.Literal<"ref">;
|
|
319
|
-
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
320
|
-
readonly id: Schema.String;
|
|
321
|
-
readonly mediaType: Schema.optional<Schema.String>;
|
|
322
|
-
}>]>;
|
|
323
|
-
readonly info: Schema.optional<Schema.Struct<{
|
|
324
|
-
readonly width: Schema.optional<Schema.Number>;
|
|
325
|
-
readonly height: Schema.optional<Schema.Number>;
|
|
326
|
-
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
327
|
-
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
328
|
-
readonly channels: Schema.optional<Schema.Number>;
|
|
329
|
-
readonly encoding: Schema.optional<Schema.String>;
|
|
330
|
-
readonly format: Schema.optional<Schema.String>;
|
|
331
|
-
}>>;
|
|
332
|
-
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
333
|
-
}>, never, never>;
|
|
334
|
-
readonly filename: Schema.optional<Schema.String>;
|
|
335
|
-
}>]>>;
|
|
336
|
-
readonly questions: Schema.refine<readonly ({
|
|
337
|
-
readonly name: string;
|
|
338
|
-
readonly type: "predicate";
|
|
339
|
-
readonly instructions: string;
|
|
340
|
-
} | {
|
|
341
|
-
readonly name: string;
|
|
342
|
-
readonly type: "choice";
|
|
343
|
-
readonly instructions: string;
|
|
344
|
-
readonly choices: readonly {
|
|
345
|
-
readonly value: string | boolean;
|
|
346
|
-
readonly description?: string | undefined;
|
|
347
|
-
}[];
|
|
348
|
-
} | {
|
|
349
|
-
readonly name: string;
|
|
350
|
-
readonly type: "score";
|
|
351
|
-
readonly instructions: string;
|
|
352
|
-
readonly levels: readonly {
|
|
353
|
-
readonly label: string;
|
|
354
|
-
readonly description?: string | undefined;
|
|
355
|
-
}[];
|
|
356
|
-
})[], Schema.refine<readonly ({
|
|
357
|
-
readonly name: string;
|
|
358
|
-
readonly type: "predicate";
|
|
359
|
-
readonly instructions: string;
|
|
360
|
-
} | {
|
|
361
|
-
readonly name: string;
|
|
362
|
-
readonly type: "choice";
|
|
363
|
-
readonly instructions: string;
|
|
364
|
-
readonly choices: readonly {
|
|
365
|
-
readonly value: string | boolean;
|
|
366
|
-
readonly description?: string | undefined;
|
|
367
|
-
}[];
|
|
368
|
-
} | {
|
|
369
|
-
readonly name: string;
|
|
370
|
-
readonly type: "score";
|
|
371
|
-
readonly instructions: string;
|
|
372
|
-
readonly levels: readonly {
|
|
373
|
-
readonly label: string;
|
|
374
|
-
readonly description?: string | undefined;
|
|
375
|
-
}[];
|
|
376
|
-
})[], Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
377
|
-
readonly name: Schema.String;
|
|
378
|
-
readonly type: Schema.Literal<"predicate">;
|
|
379
|
-
readonly instructions: Schema.String;
|
|
380
|
-
}>, Schema.Struct<{
|
|
381
|
-
readonly name: Schema.String;
|
|
382
|
-
readonly type: Schema.Literal<"choice">;
|
|
383
|
-
readonly instructions: Schema.String;
|
|
384
|
-
readonly choices: Schema.$Array<Schema.Struct<{
|
|
385
|
-
readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
|
|
386
|
-
readonly description: Schema.optional<Schema.String>;
|
|
387
|
-
}>>;
|
|
388
|
-
}>, Schema.Struct<{
|
|
389
|
-
readonly name: Schema.String;
|
|
390
|
-
readonly type: Schema.Literal<"score">;
|
|
391
|
-
readonly instructions: Schema.String;
|
|
392
|
-
readonly levels: Schema.$Array<Schema.Struct<{
|
|
393
|
-
readonly label: Schema.String;
|
|
394
|
-
readonly description: Schema.optional<Schema.String>;
|
|
395
|
-
}>>;
|
|
396
|
-
}>]>>>>;
|
|
397
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
398
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
399
|
-
}>, {}>;
|
|
400
|
-
export declare class DecisionRequest extends DecisionRequest_base {
|
|
401
|
-
protected readonly _DecisionRequest: void;
|
|
402
|
-
}
|
|
403
|
-
export type DecisionRequestFor<Options extends DecisionOptions = DecisionOptions, Questions extends DecisionQuestions = DecisionQuestions> = Omit<DecisionRequest, "model" | "questions" | "providerOptions"> & {
|
|
404
|
-
readonly model: DecisionModel<Options>;
|
|
311
|
+
/** A normalized decision request, the plain object `ai.decision.request(...)` returns. */
|
|
312
|
+
export interface DecisionRequest<Model extends DecisionModel = DecisionModel, Questions extends DecisionQuestions = DecisionQuestions> extends BaseRequest<Model, DecisionModelOptions<Model>> {
|
|
313
|
+
readonly input: ReadonlyArray<DecisionPart>;
|
|
405
314
|
readonly questions: Questions;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
export
|
|
409
|
-
readonly model: Model;
|
|
315
|
+
}
|
|
316
|
+
/** Input accepted by `ai.decision.request` and `generate`. A `DecisionRequest` is also a valid input. */
|
|
317
|
+
export interface DecisionRequestInput<Model extends DecisionModel = DecisionModel, Questions extends DecisionQuestions = DecisionQuestions> extends BaseRequest<Model, NoInfer<DecisionModelOptions<Model>>> {
|
|
410
318
|
readonly input: DecisionInput;
|
|
411
319
|
readonly questions: Questions;
|
|
412
|
-
|
|
413
|
-
readonly http?: HttpOptions.Input;
|
|
414
|
-
};
|
|
320
|
+
}
|
|
415
321
|
declare const DecisionUsage_base: Schema.Class<DecisionUsage, Schema.Struct<{
|
|
416
322
|
readonly inputTokens: Schema.optional<Schema.Number>;
|
|
417
323
|
readonly outputTokens: Schema.optional<Schema.Number>;
|
|
@@ -460,9 +366,8 @@ export declare class DecisionResponse extends DecisionResponse_base {
|
|
|
460
366
|
export type DecisionResponseFor<Questions extends DecisionQuestions> = Omit<DecisionResponse, "answers"> & {
|
|
461
367
|
readonly answers: AnswersFor<Questions>;
|
|
462
368
|
};
|
|
463
|
-
|
|
464
|
-
export declare
|
|
465
|
-
export declare function request(input: DecisionRequest | DecisionRequestInput): DecisionRequest;
|
|
369
|
+
/** Normalize decision request input into a plain `DecisionRequest`; a plain object `input` becomes one `json` part. */
|
|
370
|
+
export declare const request: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>) => DecisionRequest<Model, Questions>;
|
|
466
371
|
export declare function generate<const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>): Effect.Effect<DecisionResponseFor<Questions>, AIError, Service>;
|
|
467
372
|
export declare const Decision: {
|
|
468
373
|
readonly request: typeof request;
|
package/dist/decision.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { DecisionClient, Service } from "./decision-client.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { tryRequest } from "./media-model.js";
|
|
5
|
-
import { AIError,
|
|
5
|
+
import { AIError, ModelID, ProviderID, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
// Input
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
@@ -23,6 +23,8 @@ export const PredicateQuestion = Schema.Struct({
|
|
|
23
23
|
name: Schema.String,
|
|
24
24
|
type: Schema.Literal("predicate"),
|
|
25
25
|
instructions: Schema.String,
|
|
26
|
+
/** What counts as true and as false, for statements the instructions alone leave ambiguous. */
|
|
27
|
+
criteria: Schema.optional(Schema.Struct({ true: Schema.optional(Schema.String), false: Schema.optional(Schema.String) })),
|
|
26
28
|
});
|
|
27
29
|
export const ChoiceQuestion = Schema.Struct({
|
|
28
30
|
name: Schema.String,
|
|
@@ -117,14 +119,12 @@ export const DecisionModelSchema = Schema.declare((value) => value instanceof De
|
|
|
117
119
|
// ---------------------------------------------------------------------------
|
|
118
120
|
// Request and response
|
|
119
121
|
// ---------------------------------------------------------------------------
|
|
120
|
-
|
|
122
|
+
const DecisionRequestSchema = Schema.Struct({
|
|
121
123
|
model: DecisionModelSchema,
|
|
122
124
|
input: Schema.Array(DecisionPart),
|
|
123
125
|
questions: DecisionQuestionList,
|
|
124
126
|
providerOptions: Schema.optional(ProviderOptions),
|
|
125
|
-
|
|
126
|
-
}) {
|
|
127
|
-
}
|
|
127
|
+
});
|
|
128
128
|
/** What decision hosts report; their raw usage stays in the response's `providerMetadata`. */
|
|
129
129
|
export class DecisionUsage extends Schema.Class("Decision.Usage")({
|
|
130
130
|
inputTokens: Schema.optional(Schema.Number),
|
|
@@ -140,17 +140,29 @@ export class DecisionResponse extends Schema.Class("Decision.Response")({
|
|
|
140
140
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
141
141
|
}) {
|
|
142
142
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// Call API
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
/** Normalize decision request input into a plain `DecisionRequest`; a plain object `input` becomes one `json` part. */
|
|
147
|
+
export const request = (input) => ({
|
|
148
|
+
...input,
|
|
149
|
+
input: isParts(input.input) ? input.input.map(decisionPart) : [{ type: "json", value: input.input }],
|
|
150
|
+
});
|
|
151
|
+
const validate = Schema.decodeUnknownSync(DecisionRequestSchema);
|
|
152
|
+
// `Array.isArray` doesn't narrow a readonly array union, so the object branch would keep the parts type.
|
|
153
|
+
const isParts = (input) => Array.isArray(input);
|
|
154
|
+
const decisionPart = (part) => {
|
|
155
|
+
if (part.type !== "media")
|
|
156
|
+
return part;
|
|
157
|
+
const { mediaType, ...rest } = part;
|
|
158
|
+
return { ...rest, media: Media.make(part.media, mediaType) };
|
|
159
|
+
};
|
|
152
160
|
export function generate(input) {
|
|
153
|
-
return tryRequest(() =>
|
|
161
|
+
return tryRequest(() => {
|
|
162
|
+
const normalized = request(input);
|
|
163
|
+
validate(normalized);
|
|
164
|
+
return normalized;
|
|
165
|
+
}).pipe(Effect.flatMap(DecisionClient.generate));
|
|
154
166
|
}
|
|
155
167
|
export const Decision = {
|
|
156
168
|
request,
|
package/dist/effect.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const ai: {
|
|
|
5
5
|
readonly generate: typeof LLM.generate;
|
|
6
6
|
readonly stream: typeof LLM.stream;
|
|
7
7
|
readonly loop: typeof LLM.loop;
|
|
8
|
-
readonly
|
|
8
|
+
readonly collect: typeof LLM.collect;
|
|
9
9
|
readonly compact: typeof LLM.compact;
|
|
10
10
|
readonly canCompact: typeof LLM.canCompact;
|
|
11
11
|
readonly image: {
|
|
@@ -19,6 +19,10 @@ export declare const ai: {
|
|
|
19
19
|
readonly request: typeof import("./decision.js").request;
|
|
20
20
|
readonly generate: typeof import("./decision.js").generate;
|
|
21
21
|
};
|
|
22
|
+
readonly embedding: {
|
|
23
|
+
readonly request: typeof import("./embedding.js").request;
|
|
24
|
+
readonly generate: typeof import("./embedding.js").generate;
|
|
25
|
+
};
|
|
22
26
|
/** Experimental: may change without compatibility guarantees. */
|
|
23
27
|
readonly experimental: {
|
|
24
28
|
readonly speech: {
|
|
@@ -47,22 +51,13 @@ export { LLMClient } from "./route/client.js";
|
|
|
47
51
|
export { ImageClient } from "./image-client.js";
|
|
48
52
|
export { Auth } from "./route/auth.js";
|
|
49
53
|
export { ProviderPackage } from "./provider-package.js";
|
|
50
|
-
export {
|
|
51
|
-
export type { Interface as LLMClientShape, LLMClientService } from "./route/client.js";
|
|
52
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
53
|
-
export type { GenerationOptionsFields, GenerationOptionsInput, LanguageModelInput, LanguageModelProviderOptions, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, UsageInput, } from "./schema/index.js";
|
|
54
|
-
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
55
|
-
export type { ImageModelOptions, ImageOptions, ImageRequestFor, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
|
54
|
+
export type { LLMClientService } from "./route/client.js";
|
|
56
55
|
export { DecisionClient } from "./decision-client.js";
|
|
57
|
-
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
58
|
-
export type { AnswerFor, AnswersFor, DecisionInput, DecisionModelOptions, DecisionOptions, DecisionQuestions, DecisionRequestFor, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
59
56
|
export { DecisionRoute } from "./route/decision.js";
|
|
60
|
-
export {
|
|
57
|
+
export { EmbeddingClient } from "./embedding-client.js";
|
|
58
|
+
export { EmbeddingRoute } from "./route/embedding.js";
|
|
61
59
|
export { Generation } from "./generation.js";
|
|
62
|
-
export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
|
|
63
60
|
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
|
|
64
61
|
export { ToolRuntime } from "./tool-runtime.js";
|
|
65
|
-
export type {
|
|
66
|
-
export
|
|
67
|
-
export type { LLM } from "./llm.js";
|
|
68
|
-
export type { Definition as ProviderPackageDefinition, Settings as ProviderPackageSettings, } from "./provider-package.js";
|
|
62
|
+
export type { ToolSettlement } from "./tool-runtime.js";
|
|
63
|
+
export * from "./public.js";
|
package/dist/effect.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Decision } from "./decision.js";
|
|
2
|
+
import { Embedding } from "./embedding.js";
|
|
2
3
|
import { Image } from "./image.js";
|
|
3
4
|
import { LLM } from "./llm.js";
|
|
4
5
|
import { Speech } from "./speech.js";
|
|
@@ -10,11 +11,12 @@ export const ai = {
|
|
|
10
11
|
generate: LLM.generate,
|
|
11
12
|
stream: LLM.stream,
|
|
12
13
|
loop: LLM.loop,
|
|
13
|
-
|
|
14
|
+
collect: LLM.collect,
|
|
14
15
|
compact: LLM.compact,
|
|
15
16
|
canCompact: LLM.canCompact,
|
|
16
17
|
image: Image,
|
|
17
18
|
decision: Decision,
|
|
19
|
+
embedding: Embedding,
|
|
18
20
|
/** Experimental: may change without compatibility guarantees. */
|
|
19
21
|
experimental: {
|
|
20
22
|
speech: Speech,
|
|
@@ -27,13 +29,11 @@ export { LLMClient } from "./route/client.js";
|
|
|
27
29
|
export { ImageClient } from "./image-client.js";
|
|
28
30
|
export { Auth } from "./route/auth.js";
|
|
29
31
|
export { ProviderPackage } from "./provider-package.js";
|
|
30
|
-
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
31
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
32
|
-
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
33
32
|
export { DecisionClient } from "./decision-client.js";
|
|
34
|
-
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
35
33
|
export { DecisionRoute } from "./route/decision.js";
|
|
36
|
-
export {
|
|
34
|
+
export { EmbeddingClient } from "./embedding-client.js";
|
|
35
|
+
export { EmbeddingRoute } from "./route/embedding.js";
|
|
37
36
|
export { Generation } from "./generation.js";
|
|
38
37
|
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
|
|
39
38
|
export { ToolRuntime } from "./tool-runtime.js";
|
|
39
|
+
export * from "./public.js";
|
package/dist/effort-updates.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { LLMRequest, type EffortPart, type Message } from "./schema/messages.js";
|
|
1
|
+
import { type LLMRequest, type EffortPart, type Message } from "./schema/messages.js";
|
|
2
2
|
export declare const effortUpdate: (message: Message) => EffortPart | undefined;
|
|
3
|
-
export declare const stripEffortUpdates: (request: LLMRequest) => LLMRequest<import("./
|
|
3
|
+
export declare const stripEffortUpdates: (request: LLMRequest) => LLMRequest<import("./public.js").LanguageModel<{
|
|
4
4
|
readonly [x: string]: unknown;
|
|
5
5
|
}, import("./route.js").CompactionOperations | undefined>>;
|
|
6
6
|
export declare const applyEffortUpdates: (request: LLMRequest) => LLMRequest;
|
|
7
7
|
export declare const resolveEffortUpdates: (request: LLMRequest, current: string | undefined) => {
|
|
8
|
-
request: LLMRequest<import("./
|
|
8
|
+
request: LLMRequest<import("./public.js").LanguageModel<{
|
|
9
9
|
readonly [x: string]: unknown;
|
|
10
10
|
}, import("./route.js").CompactionOperations | undefined>>;
|
|
11
11
|
effort: string | undefined;
|
package/dist/effort-updates.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Changing the top-level reasoning effort invalidates the provider prompt cache. Protocols with a native
|
|
2
2
|
// per-message update keep it frozen and lower `Message.effort(...)` markers instead; other routes strip them.
|
|
3
|
-
import {
|
|
3
|
+
import {} from "./schema/messages.js";
|
|
4
4
|
export const effortUpdate = (message) => {
|
|
5
5
|
if (message.role !== "system" || message.content.length !== 1)
|
|
6
6
|
return undefined;
|
|
@@ -9,7 +9,7 @@ export const effortUpdate = (message) => {
|
|
|
9
9
|
};
|
|
10
10
|
export const stripEffortUpdates = (request) => {
|
|
11
11
|
const messages = request.messages.filter((message) => effortUpdate(message) === undefined);
|
|
12
|
-
return messages.length === request.messages.length ? request :
|
|
12
|
+
return messages.length === request.messages.length ? request : { ...request, messages };
|
|
13
13
|
};
|
|
14
14
|
export const applyEffortUpdates = (request) => request.model.route.supportsEffortUpdates?.(request) ? request : stripEffortUpdates(request);
|
|
15
15
|
// Reverted or forked history can leave the last marker disagreeing with the requested effort.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import type { EmbeddingModel, EmbeddingOptions, EmbeddingRequest, EmbeddingResponse } from "./embedding.js";
|
|
3
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
4
|
+
import { AIError } from "./schema/index.js";
|
|
5
|
+
export type Execute = RequestExecutor.Interface["execute"];
|
|
6
|
+
export interface Interface {
|
|
7
|
+
readonly generate: <Options extends EmbeddingOptions>(request: EmbeddingRequest<EmbeddingModel<Options>>) => Effect.Effect<EmbeddingResponse, AIError>;
|
|
8
|
+
}
|
|
9
|
+
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/EmbeddingClient", Interface>;
|
|
10
|
+
export declare class Service extends Service_base {
|
|
11
|
+
}
|
|
12
|
+
export declare const generate: <Options extends EmbeddingOptions>(request: EmbeddingRequest<EmbeddingModel<Options>>) => Effect.Effect<EmbeddingResponse, AIError, Service>;
|
|
13
|
+
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
14
|
+
export declare const fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
|
|
15
|
+
export declare const EmbeddingClient: {
|
|
16
|
+
readonly Service: typeof Service;
|
|
17
|
+
readonly layer: Layer.Layer<Service, never, RequestExecutor.RequestExecutorService>;
|
|
18
|
+
readonly fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
|
|
19
|
+
readonly generate: typeof generate;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
3
|
+
import { AIError, InvalidProviderOutputError } from "./schema/index.js";
|
|
4
|
+
export class Service extends Context.Service()("@opencode/AI/EmbeddingClient") {
|
|
5
|
+
}
|
|
6
|
+
export const generate = (request) => Effect.flatMap(Service, (client) => client.generate(request));
|
|
7
|
+
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
8
|
+
const executor = yield* RequestExecutor.Service;
|
|
9
|
+
return Service.of({
|
|
10
|
+
generate: Effect.fnUntraced(function* (request) {
|
|
11
|
+
const route = request.model.route;
|
|
12
|
+
const response = yield* route.generate(request, executor.execute);
|
|
13
|
+
if (response.embeddings.length === request.values.length)
|
|
14
|
+
return response;
|
|
15
|
+
return yield* new AIError({
|
|
16
|
+
reason: new InvalidProviderOutputError({
|
|
17
|
+
route: route.id,
|
|
18
|
+
message: `Expected ${request.values.length} embeddings, got ${response.embeddings.length}`,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
}));
|
|
24
|
+
export const fetchLayer = layer.pipe(Layer.provideMerge(RequestExecutor.fetchLayer));
|
|
25
|
+
export const EmbeddingClient = {
|
|
26
|
+
Service,
|
|
27
|
+
layer,
|
|
28
|
+
fetchLayer,
|
|
29
|
+
generate,
|
|
30
|
+
};
|
|
@@ -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 {};
|