@opencode/ai 0.0.0-dev-1074 → 0.0.0-dev-1111

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.
Files changed (74) hide show
  1. package/README.md +94 -4
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/effect.d.ts +6 -0
  5. package/dist/effect.js +4 -0
  6. package/dist/embedding-client.d.ts +21 -0
  7. package/dist/embedding-client.js +30 -0
  8. package/dist/embedding.d.ts +111 -0
  9. package/dist/embedding.js +75 -0
  10. package/dist/image.d.ts +0 -1
  11. package/dist/image.js +0 -3
  12. package/dist/index.d.ts +7 -2
  13. package/dist/index.js +5 -0
  14. package/dist/protocols/google-embed-content.d.ts +34 -0
  15. package/dist/protocols/google-embed-content.js +110 -0
  16. package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
  17. package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
  18. package/dist/protocols/index.d.ts +3 -0
  19. package/dist/protocols/index.js +3 -0
  20. package/dist/protocols/openai-embeddings.d.ts +16 -0
  21. package/dist/protocols/openai-embeddings.js +76 -0
  22. package/dist/providers/alibaba/embeddings.d.ts +2 -0
  23. package/dist/providers/alibaba/embeddings.js +1 -0
  24. package/dist/providers/alibaba.d.ts +2 -0
  25. package/dist/providers/alibaba.js +14 -1
  26. package/dist/providers/azure/embeddings.d.ts +2 -0
  27. package/dist/providers/azure/embeddings.js +1 -0
  28. package/dist/providers/azure.d.ts +2 -0
  29. package/dist/providers/azure.js +15 -0
  30. package/dist/providers/cohere/embeddings.d.ts +2 -0
  31. package/dist/providers/cohere/embeddings.js +1 -0
  32. package/dist/providers/cohere.d.ts +6 -0
  33. package/dist/providers/cohere.js +17 -1
  34. package/dist/providers/deepinfra/embeddings.d.ts +2 -0
  35. package/dist/providers/deepinfra/embeddings.js +1 -0
  36. package/dist/providers/deepinfra.d.ts +4 -1
  37. package/dist/providers/deepinfra.js +15 -1
  38. package/dist/providers/digitalocean/embeddings.d.ts +2 -0
  39. package/dist/providers/digitalocean/embeddings.js +1 -0
  40. package/dist/providers/digitalocean.d.ts +4 -0
  41. package/dist/providers/digitalocean.js +15 -0
  42. package/dist/providers/fireworks/embeddings.d.ts +2 -0
  43. package/dist/providers/fireworks/embeddings.js +1 -0
  44. package/dist/providers/fireworks.d.ts +4 -1
  45. package/dist/providers/fireworks.js +15 -1
  46. package/dist/providers/google/embeddings.d.ts +2 -0
  47. package/dist/providers/google/embeddings.js +1 -0
  48. package/dist/providers/google-vertex/embeddings.d.ts +2 -0
  49. package/dist/providers/google-vertex/embeddings.js +1 -0
  50. package/dist/providers/google-vertex.d.ts +7 -0
  51. package/dist/providers/google-vertex.js +52 -0
  52. package/dist/providers/google.d.ts +6 -0
  53. package/dist/providers/google.js +14 -0
  54. package/dist/providers/openai/embeddings.d.ts +2 -0
  55. package/dist/providers/openai/embeddings.js +1 -0
  56. package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
  57. package/dist/providers/openai-compatible/embeddings.js +1 -0
  58. package/dist/providers/openai-compatible.d.ts +3 -0
  59. package/dist/providers/openai-compatible.js +13 -0
  60. package/dist/providers/openai.d.ts +6 -0
  61. package/dist/providers/openai.js +14 -0
  62. package/dist/providers/openrouter/embeddings.d.ts +2 -0
  63. package/dist/providers/openrouter/embeddings.js +1 -0
  64. package/dist/providers/openrouter.d.ts +9 -0
  65. package/dist/providers/openrouter.js +15 -0
  66. package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
  67. package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
  68. package/dist/providers/vercel-ai-gateway.d.ts +4 -0
  69. package/dist/providers/vercel-ai-gateway.js +15 -1
  70. package/dist/public.d.ts +2 -0
  71. package/dist/public.js +1 -0
  72. package/dist/route/embedding.d.ts +61 -0
  73. package/dist/route/embedding.js +88 -0
  74. package/package.json +55 -3
@@ -0,0 +1,110 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
3
+ import { EmbeddingRoute } from "../route/embedding.js";
4
+ import { Endpoint } from "../route/endpoint.js";
5
+ import { MediaProtocol } from "../route/media-protocol.js";
6
+ import { mergeJsonRecords } from "../schema/index.js";
7
+ import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
8
+ const ID = "google-embed-content";
9
+ const NAME = "Google embedContent";
10
+ export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
11
+ /** `batchEmbedContents` takes at most 100 requests. */
12
+ export const MAX_BATCH = 100;
13
+ const Values = Schema.Struct({ values: Schema.Array(Schema.Number) });
14
+ const UsageMetadata = Schema.StructWithRest(Schema.Struct({ promptTokenCount: Schema.optional(Schema.Number) }), [
15
+ Schema.Record(Schema.String, Schema.Unknown),
16
+ ]);
17
+ const BatchResponse = Schema.Struct({
18
+ embeddings: Schema.Array(Values),
19
+ usageMetadata: Schema.optional(UsageMetadata),
20
+ });
21
+ const SingleResponse = Schema.Struct({
22
+ embedding: Values,
23
+ usageMetadata: Schema.optional(UsageMetadata),
24
+ truncated: Schema.optional(Schema.Boolean),
25
+ });
26
+ const TASK_TYPES = { query: "RETRIEVAL_QUERY", document: "RETRIEVAL_DOCUMENT" };
27
+ // Each value is its own content: several parts in one content embed into one aggregated vector.
28
+ const content = (value) => typeof value === "string"
29
+ ? Effect.succeed({ parts: [{ text: value }] })
30
+ : GeminiGenerateContent.mediaPart(NAME, value).pipe(Effect.map((part) => ({ parts: [part] })));
31
+ const config = (request) => ({
32
+ ...(request.inputType === undefined ? {} : { taskType: TASK_TYPES[request.inputType] }),
33
+ ...(request.dimensions === undefined ? {} : { outputDimensionality: request.dimensions }),
34
+ ...request.providerOptions,
35
+ });
36
+ const identity = MediaProtocol.identity({ id: ID, name: NAME, provider: "google" });
37
+ const decodeBatch = identity.decodeJson(BatchResponse);
38
+ const decodeSingle = identity.decodeJson(SingleResponse);
39
+ const usage = (metadata) => metadata?.promptTokenCount === undefined ? undefined : new EmbeddingUsage({ inputTokens: metadata.promptTokenCount });
40
+ /** Gemini API `batchEmbedContents`: one request per value, so every value gets its own vector. */
41
+ export const protocol = EmbeddingRoute.protocol({
42
+ id: ID,
43
+ name: NAME,
44
+ body: {
45
+ from: Effect.fn("GoogleEmbedContent.fromRequest")(function* (request) {
46
+ const contents = yield* Effect.forEach(request.values, content);
47
+ const fields = config(request);
48
+ return (mergeJsonRecords({ requests: contents.map((item) => ({ model: `models/${request.model.id}`, content: item, ...fields })) }, request.http?.body) ?? {});
49
+ }),
50
+ },
51
+ response: {
52
+ decode: Effect.fn("GoogleEmbedContent.decodeResponse")(function* (response, context) {
53
+ const output = yield* decodeBatch(response);
54
+ return new EmbeddingResponse({
55
+ embeddings: output.value.embeddings.map((item) => item.values),
56
+ usage: usage(output.value.usageMetadata),
57
+ providerMetadata: {
58
+ [context.providerMetadataKey]: output.value.usageMetadata === undefined ? {} : { usageMetadata: output.value.usageMetadata },
59
+ },
60
+ });
61
+ }),
62
+ },
63
+ });
64
+ /**
65
+ * Vertex `embedContent`: one content per request, with options under `embedContentConfig`. Routes using it set
66
+ * `maxValues: 1`.
67
+ */
68
+ export const vertexProtocol = EmbeddingRoute.protocol({
69
+ id: "google-vertex-embed-content",
70
+ name: "Google Vertex embedContent",
71
+ body: {
72
+ from: Effect.fn("GoogleEmbedContent.vertexFromRequest")(function* (request) {
73
+ const contents = yield* Effect.forEach(request.values, content);
74
+ const fields = config(request);
75
+ return (mergeJsonRecords({
76
+ content: contents[0],
77
+ ...(Object.keys(fields).length === 0 ? {} : { embedContentConfig: fields }),
78
+ }, request.http?.body) ?? {});
79
+ }),
80
+ },
81
+ response: {
82
+ decode: Effect.fn("GoogleEmbedContent.vertexDecodeResponse")(function* (response, context) {
83
+ const output = yield* decodeSingle(response);
84
+ return new EmbeddingResponse({
85
+ embeddings: [output.value.embedding.values],
86
+ usage: usage(output.value.usageMetadata),
87
+ providerMetadata: {
88
+ [context.providerMetadataKey]: {
89
+ ...(output.value.usageMetadata === undefined ? {} : { usageMetadata: output.value.usageMetadata }),
90
+ ...(output.value.truncated === undefined ? {} : { truncated: output.value.truncated }),
91
+ },
92
+ },
93
+ });
94
+ }),
95
+ },
96
+ });
97
+ export const route = EmbeddingRoute.make({
98
+ id: ID,
99
+ provider: "google",
100
+ protocol,
101
+ endpoint: Endpoint.path(({ request }) => `/models/${request.model.id}:batchEmbedContents`, {
102
+ baseURL: DEFAULT_BASE_URL,
103
+ }),
104
+ maxValues: MAX_BATCH,
105
+ });
106
+ export const GoogleEmbedContent = {
107
+ protocol,
108
+ vertexProtocol,
109
+ route,
110
+ };
@@ -0,0 +1,18 @@
1
+ import { EmbeddingRoute } from "../route/embedding.js";
2
+ import type { TaskType } from "./google-embed-content.js";
3
+ /** `text-embedding-005` and `text-multilingual-embedding-002` take up to 250 instances per request. */
4
+ export declare const MAX_INSTANCES = 250;
5
+ /**
6
+ * The same option names as `embedContent`, so a model can move between the two APIs: `taskType` and `title` go on
7
+ * each instance (`task_type`, `title`), and `autoTruncate` and anything else go under `parameters`.
8
+ */
9
+ export interface OptionsInput {
10
+ readonly [key: string]: unknown;
11
+ readonly taskType?: TaskType;
12
+ readonly title?: string;
13
+ readonly autoTruncate?: boolean;
14
+ }
15
+ export declare const protocol: EmbeddingRoute.Protocol;
16
+ export declare const GoogleVertexPredictEmbeddings: {
17
+ readonly protocol: EmbeddingRoute.Protocol;
18
+ };
@@ -0,0 +1,74 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
3
+ import { EmbeddingRoute } from "../route/embedding.js";
4
+ import { MediaProtocol } from "../route/media-protocol.js";
5
+ import { AIError, UnsupportedOperationError, mergeJsonRecords } from "../schema/index.js";
6
+ const ID = "google-vertex-predict-embeddings";
7
+ const NAME = "Google Vertex text embeddings";
8
+ /** `text-embedding-005` and `text-multilingual-embedding-002` take up to 250 instances per request. */
9
+ export const MAX_INSTANCES = 250;
10
+ const Statistics = Schema.StructWithRest(Schema.Struct({ token_count: Schema.optional(Schema.Number), truncated: Schema.optional(Schema.Boolean) }), [Schema.Record(Schema.String, Schema.Unknown)]);
11
+ const Response = Schema.Struct({
12
+ predictions: Schema.Array(Schema.Struct({
13
+ embeddings: Schema.Struct({ values: Schema.Array(Schema.Number), statistics: Schema.optional(Statistics) }),
14
+ })),
15
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
16
+ });
17
+ const TASK_TYPES = { query: "RETRIEVAL_QUERY", document: "RETRIEVAL_DOCUMENT" };
18
+ const fromRequest = Effect.fn("GoogleVertexPredictEmbeddings.fromRequest")(function* (request) {
19
+ const contents = request.values.filter((value) => typeof value === "string");
20
+ if (contents.length !== request.values.length)
21
+ return yield* new AIError({
22
+ reason: new UnsupportedOperationError({
23
+ operation: "embedding.media",
24
+ provider: request.model.provider,
25
+ route: request.model.route.id,
26
+ message: `${request.model.id} on Vertex :predict embeds text only; use gemini-embedding-2 for media values`,
27
+ }),
28
+ });
29
+ const { taskType, title, ...parameters } = request.providerOptions ?? {};
30
+ const instance = {
31
+ ...(taskType === undefined
32
+ ? request.inputType === undefined
33
+ ? {}
34
+ : { task_type: TASK_TYPES[request.inputType] }
35
+ : { task_type: taskType }),
36
+ ...(title === undefined ? {} : { title }),
37
+ };
38
+ const merged = {
39
+ ...(request.dimensions === undefined ? {} : { outputDimensionality: request.dimensions }),
40
+ ...parameters,
41
+ };
42
+ return (mergeJsonRecords({
43
+ instances: contents.map((content) => ({ content, ...instance })),
44
+ ...(Object.keys(merged).length === 0 ? {} : { parameters: merged }),
45
+ }, request.http?.body) ?? {});
46
+ });
47
+ const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "google-vertex" }).decodeJson(Response);
48
+ export const protocol = EmbeddingRoute.protocol({
49
+ id: ID,
50
+ name: NAME,
51
+ body: { from: fromRequest },
52
+ response: {
53
+ decode: Effect.fn("GoogleVertexPredictEmbeddings.decodeResponse")(function* (response, context) {
54
+ const output = yield* decodeDocument(response);
55
+ const statistics = output.value.predictions.map((prediction) => prediction.embeddings.statistics ?? {});
56
+ const tokens = statistics.map((item) => item.token_count);
57
+ return new EmbeddingResponse({
58
+ embeddings: output.value.predictions.map((prediction) => prediction.embeddings.values),
59
+ usage: tokens.every((count) => count !== undefined)
60
+ ? new EmbeddingUsage({ inputTokens: tokens.reduce((sum, count) => sum + count, 0) })
61
+ : undefined,
62
+ providerMetadata: {
63
+ [context.providerMetadataKey]: {
64
+ statistics,
65
+ ...(output.value.metadata === undefined ? {} : { metadata: output.value.metadata }),
66
+ },
67
+ },
68
+ });
69
+ }),
70
+ },
71
+ });
72
+ export const GoogleVertexPredictEmbeddings = {
73
+ protocol,
74
+ };
@@ -3,10 +3,13 @@ export * as BedrockConverse from "./bedrock-converse.js";
3
3
  export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
4
4
  export * as CohereChat from "./cohere-chat.js";
5
5
  export * as Gemini from "./gemini.js";
6
+ export * as GoogleEmbedContent from "./google-embed-content.js";
6
7
  export * as GoogleInteractions from "./google-interactions.js";
8
+ export * as GoogleVertexPredictEmbeddings from "./google-vertex-predict-embeddings.js";
7
9
  export * as MistralChat from "./mistral-chat.js";
8
10
  export * as OpenAIChat from "./openai-chat.js";
9
11
  export * as OpenAIDecisions from "./openai-decisions.js";
12
+ export * as OpenAIEmbeddings from "./openai-embeddings.js";
10
13
  export * as OpenAIImages from "./openai-images.js";
11
14
  export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
12
15
  export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
@@ -3,10 +3,13 @@ export * as BedrockConverse from "./bedrock-converse.js";
3
3
  export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
4
4
  export * as CohereChat from "./cohere-chat.js";
5
5
  export * as Gemini from "./gemini.js";
6
+ export * as GoogleEmbedContent from "./google-embed-content.js";
6
7
  export * as GoogleInteractions from "./google-interactions.js";
8
+ export * as GoogleVertexPredictEmbeddings from "./google-vertex-predict-embeddings.js";
7
9
  export * as MistralChat from "./mistral-chat.js";
8
10
  export * as OpenAIChat from "./openai-chat.js";
9
11
  export * as OpenAIDecisions from "./openai-decisions.js";
12
+ export * as OpenAIEmbeddings from "./openai-embeddings.js";
10
13
  export * as OpenAIImages from "./openai-images.js";
11
14
  export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
12
15
  export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
@@ -0,0 +1,16 @@
1
+ import { EmbeddingRoute } from "../route/embedding.js";
2
+ import { type OpenString } from "../schema/index.js";
3
+ export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
4
+ export declare const PATH = "/embeddings";
5
+ /** Sent as given; anything else a host accepts (`input_type`, `truncate`, …) goes alongside. */
6
+ export interface OptionsInput {
7
+ readonly [key: string]: unknown;
8
+ readonly user?: string;
9
+ readonly encoding_format?: OpenString<"float" | "base64">;
10
+ }
11
+ export declare const protocol: EmbeddingRoute.Protocol;
12
+ export declare const route: EmbeddingRoute.Route;
13
+ export declare const OpenAIEmbeddings: {
14
+ readonly protocol: EmbeddingRoute.Protocol;
15
+ readonly route: EmbeddingRoute.Route;
16
+ };
@@ -0,0 +1,76 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Base64 } from "effect/encoding";
3
+ import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
4
+ import { EmbeddingRoute } from "../route/embedding.js";
5
+ import { Endpoint } from "../route/endpoint.js";
6
+ import { MediaProtocol } from "../route/media-protocol.js";
7
+ import { AIError, UnsupportedOperationError, mergeJsonRecords } from "../schema/index.js";
8
+ const ID = "openai-embeddings";
9
+ const NAME = "OpenAI Embeddings";
10
+ export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
11
+ export const PATH = "/embeddings";
12
+ const Response = Schema.Struct({
13
+ data: Schema.Array(Schema.Struct({
14
+ index: Schema.optional(Schema.Int),
15
+ // `base64` encoding returns little-endian float32 bytes instead of a number list.
16
+ embedding: Schema.Union([Schema.Array(Schema.Number), Schema.String]),
17
+ })),
18
+ model: Schema.optional(Schema.String),
19
+ usage: Schema.optional(Schema.StructWithRest(Schema.Struct({ prompt_tokens: Schema.optional(Schema.Number), total_tokens: Schema.optional(Schema.Number) }), [Schema.Record(Schema.String, Schema.Unknown)])),
20
+ });
21
+ // `inputType` has no field here; OpenAI's models embed queries and documents the same way.
22
+ const fromRequest = Effect.fn("OpenAIEmbeddings.fromRequest")(function* (request) {
23
+ const input = request.values.filter((value) => typeof value === "string");
24
+ if (input.length !== request.values.length)
25
+ return yield* new AIError({
26
+ reason: new UnsupportedOperationError({
27
+ operation: "embedding.media",
28
+ provider: request.model.provider,
29
+ route: request.model.route.id,
30
+ message: `${NAME} embeds text only; pass media values to a host with a multimodal embedding API`,
31
+ }),
32
+ });
33
+ return {
34
+ ...mergeJsonRecords({ encoding_format: "float", ...request.providerOptions }, request.http?.body),
35
+ model: request.model.id,
36
+ input,
37
+ ...(request.dimensions === undefined ? {} : { dimensions: request.dimensions }),
38
+ };
39
+ });
40
+ const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "openai" }).decodeJson(Response);
41
+ export const protocol = EmbeddingRoute.protocol({
42
+ id: ID,
43
+ name: NAME,
44
+ body: { from: fromRequest },
45
+ response: {
46
+ decode: Effect.fn("OpenAIEmbeddings.decodeResponse")(function* (response, context) {
47
+ const output = yield* decodeDocument(response);
48
+ const embeddings = yield* Effect.forEach(output.value.data
49
+ .map((item, position) => ({ index: item.index ?? position, embedding: item.embedding }))
50
+ .toSorted((a, b) => a.index - b.index), (item) => typeof item.embedding !== "string"
51
+ ? Effect.succeed(item.embedding)
52
+ : Effect.fromResult(Base64.decode(item.embedding)).pipe(Effect.map((bytes) => Array.from(new Float32Array(bytes.slice().buffer))), Effect.mapError((cause) => output.invalid(`${NAME} returned an invalid base64 embedding`, cause))));
53
+ const usage = output.value.usage;
54
+ return new EmbeddingResponse({
55
+ embeddings,
56
+ usage: usage?.prompt_tokens === undefined ? undefined : new EmbeddingUsage({ inputTokens: usage.prompt_tokens }),
57
+ providerMetadata: {
58
+ [context.providerMetadataKey]: {
59
+ ...(output.value.model === undefined ? {} : { model: output.value.model }),
60
+ ...(usage === undefined ? {} : { usage }),
61
+ },
62
+ },
63
+ });
64
+ }),
65
+ },
66
+ });
67
+ export const route = EmbeddingRoute.make({
68
+ id: ID,
69
+ provider: "openai",
70
+ protocol,
71
+ endpoint: Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL }),
72
+ });
73
+ export const OpenAIEmbeddings = {
74
+ protocol,
75
+ route,
76
+ };
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../alibaba.js";
2
+ export type { Settings } from "../alibaba.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../alibaba.js";
@@ -776,6 +776,7 @@ export declare const configure: (input: Config) => {
776
776
  readonly conversation?: string | undefined;
777
777
  }, import("../route/client.js").CompactionOperations | undefined>;
778
778
  image: (id: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
779
+ embedding: (id: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
779
780
  configure: typeof configure;
780
781
  };
781
782
  export declare const provider: {
@@ -849,6 +850,7 @@ export declare const responses: ProviderPackage.Model<Settings<{
849
850
  readonly conversation?: string | undefined;
850
851
  }, import("../route/client.js").CompactionOperations | undefined>;
851
852
  export declare const imageModel: (id: string, settings: Settings) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
853
+ export declare const embeddingModel: (id: string, settings: Settings) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
852
854
  export declare const webSearch: () => ToolDefinition;
853
855
  export declare const webExtractor: () => ToolDefinition;
854
856
  export declare const codeInterpreter: () => ToolDefinition;
@@ -1,6 +1,7 @@
1
1
  import { Struct } from "effect";
2
2
  import { AlibabaChat } from "../protocols/alibaba-chat.js";
3
3
  import { AlibabaImages } from "../protocols/alibaba-images.js";
4
+ import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
4
5
  import { AlibabaMessages } from "../protocols/alibaba-messages.js";
5
6
  import { AlibabaResponses } from "../protocols/alibaba-responses.js";
6
7
  import { AuthOptions } from "../route/auth-options.js";
@@ -72,7 +73,15 @@ export const configure = (input) => {
72
73
  const responses = (id) => responsesRoute.with(common).model({ id });
73
74
  const media = MediaRoute.deployment({ ...input, baseURL: baseURL ?? `https://${host}/api/v1` }, opts.auth);
74
75
  const image = (id, providerOptions) => AlibabaImages.model({ ...media, id, providerOptions });
75
- return { id, model: chat, chat, messages, responses, image, configure };
76
+ const embeddingRoute = OpenAIEmbeddings.route.with({
77
+ provider: id,
78
+ endpoint: common.endpoint,
79
+ auth: opts.auth,
80
+ headers: input.headers,
81
+ http: input.http,
82
+ });
83
+ const embedding = (id, providerOptions) => embeddingRoute.model({ id, providerOptions });
84
+ return { id, model: chat, chat, messages, responses, image, embedding, configure };
76
85
  };
77
86
  export const provider = { id, configure };
78
87
  export const model = (id, input) => configure(config(input)).chat(id);
@@ -85,6 +94,10 @@ export const imageModel = (id, settings) => {
85
94
  const input = config(settings);
86
95
  return configure(input).image(id, input.providerOptions);
87
96
  };
97
+ export const embeddingModel = (id, settings) => {
98
+ const input = config(settings);
99
+ return configure(input).embedding(id, input.providerOptions);
100
+ };
88
101
  function config(input) {
89
102
  const { body, ...rest } = input;
90
103
  return {
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../azure.js";
2
+ export type { Settings } from "../azure.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../azure.js";
@@ -978,6 +978,7 @@ export declare const configure: (input: Config) => {
978
978
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, CompactionOperations | undefined>;
979
979
  messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<AnthropicMessages.OptionsInput, CompactionOperations | undefined>;
980
980
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
981
+ embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
981
982
  configure: typeof configure;
982
983
  };
983
984
  export declare const provider: {
@@ -988,6 +989,7 @@ export declare const responsesModel: ProviderPackage.Model<Settings, OpenAIProvi
988
989
  export declare const chatModel: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
989
990
  export declare const messagesModel: ProviderPackage.Model<MessagesSettings, AnthropicMessages.ProviderOptionsInput>;
990
991
  export declare const imageModel: (modelID: string, settings: Settings) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
992
+ export declare const embeddingModel: (modelID: string, settings: Settings) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
991
993
  export declare const model: ProviderPackage.Model<Settings<import("./openai-options.js").OpenAIOptionsInput>, import("./openai-options.js").OpenAIOptionsInput, {
992
994
  endpoint: import("../route/client.js").CompactOperation;
993
995
  }>;
@@ -5,6 +5,7 @@ import { MediaRoute } from "../route/media.js";
5
5
  import { ProviderConfigurationError, ProviderID, } from "../schema/index.js";
6
6
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
7
7
  import { OpenAIImages } from "../protocols/openai-images.js";
8
+ import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
8
9
  import * as OpenAIChat from "../protocols/openai-chat.js";
9
10
  import * as OpenAIResponses from "../protocols/openai-responses.js";
10
11
  import { withOpenAIOptions } from "./openai-options.js";
@@ -100,6 +101,15 @@ export const configure = (input) => {
100
101
  http: { ...media.http, query: { ...media.http?.query, ...target.query } },
101
102
  });
102
103
  };
104
+ const embedding = (modelID, providerOptions) => OpenAIEmbeddings.route
105
+ .with({
106
+ provider: id,
107
+ endpoint: endpoint(input, modelID),
108
+ auth: auth(input),
109
+ headers: input.headers,
110
+ http: input.http,
111
+ })
112
+ .model({ id: modelID, providerOptions });
103
113
  return {
104
114
  id,
105
115
  model: responses,
@@ -107,6 +117,7 @@ export const configure = (input) => {
107
117
  chat,
108
118
  messages,
109
119
  image,
120
+ embedding,
110
121
  configure,
111
122
  };
112
123
  };
@@ -137,6 +148,10 @@ export const imageModel = (modelID, settings) => {
137
148
  const input = config(settings);
138
149
  return configure(input).image(modelID, input.providerOptions);
139
150
  };
151
+ export const embeddingModel = (modelID, settings) => {
152
+ const input = config(settings);
153
+ return configure(input).embedding(modelID, input.providerOptions);
154
+ };
140
155
  export const model = responsesModel;
141
156
  export const responses = responsesModel;
142
157
  export const chat = chatModel;
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../cohere.js";
2
+ export type { Settings } from "../cohere.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../cohere.js";
@@ -478,6 +478,8 @@ export declare const configure: (input?: Config) => {
478
478
  } | undefined;
479
479
  }, import("../route/client.js").CompactionOperations | undefined>;
480
480
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
481
+ /** Embeddings through the OpenAI-compatible API; the native `/v2/embed` API is not wired up. */
482
+ embedding: (modelID: string | ModelID, providerOptions?: Readonly<Record<string, unknown>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
481
483
  configure: typeof configure;
482
484
  };
483
485
  export declare const provider: {
@@ -489,8 +491,12 @@ export declare const provider: {
489
491
  } | undefined;
490
492
  }, import("../route/client.js").CompactionOperations | undefined>;
491
493
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
494
+ /** Embeddings through the OpenAI-compatible API; the native `/v2/embed` API is not wired up. */
495
+ embedding: (modelID: string | ModelID, providerOptions?: Readonly<Record<string, unknown>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
492
496
  configure: typeof configure;
493
497
  };
494
498
  export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
499
+ export declare const embedding: (modelID: string | ModelID, providerOptions?: Readonly<Record<string, unknown>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
495
500
  export declare const model: ProviderPackage.Model<Settings, CohereChat.ProviderOptionsInput>;
501
+ export declare const embeddingModel: (modelID: string, settings?: Settings<Readonly<Record<string, unknown>>>) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
496
502
  export * as Cohere from "./cohere.js";
@@ -1,5 +1,6 @@
1
1
  import { CohereChat } from "../protocols/cohere-chat.js";
2
2
  import { OpenAIChat } from "../protocols/openai-chat.js";
3
+ import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
3
4
  import { Route } from "../route/client.js";
4
5
  import { Endpoint } from "../route/endpoint.js";
5
6
  import { ProviderID } from "../schema/index.js";
@@ -19,7 +20,15 @@ export const routes = [route, chatRoute];
19
20
  export const configure = (input = {}) => {
20
21
  const options = bearerRouteDefaults(input, "COHERE_API_KEY", CohereChat.DEFAULT_BASE_URL);
21
22
  const native = route.with(options);
22
- const chat = chatRoute.with({ ...options, endpoint: { baseURL: input.baseURL ?? COMPATIBILITY_BASE_URL } });
23
+ const compatibility = { ...options, endpoint: { baseURL: input.baseURL ?? COMPATIBILITY_BASE_URL } };
24
+ const chat = chatRoute.with(compatibility);
25
+ const embeddingRoute = OpenAIEmbeddings.route.with({
26
+ provider: id,
27
+ endpoint: compatibility.endpoint,
28
+ auth: options.auth,
29
+ headers: input.headers,
30
+ http: input.http,
31
+ });
23
32
  return {
24
33
  id,
25
34
  model: (modelID) => native.model({ id: modelID }),
@@ -31,10 +40,17 @@ export const configure = (input = {}) => {
31
40
  },
32
41
  capabilities: { tools: { strict: false } },
33
42
  }),
43
+ /** Embeddings through the OpenAI-compatible API; the native `/v2/embed` API is not wired up. */
44
+ embedding: (modelID, providerOptions) => embeddingRoute.model({ id: modelID, providerOptions }),
34
45
  configure,
35
46
  };
36
47
  };
37
48
  export const provider = configure();
38
49
  export const chat = provider.chat;
50
+ export const embedding = provider.embedding;
39
51
  export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
52
+ export const embeddingModel = (modelID, settings) => {
53
+ const input = toConfig(settings);
54
+ return configure(input).embedding(modelID, input.providerOptions);
55
+ };
40
56
  export * as Cohere from "./cohere.js";
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../deepinfra.js";
2
+ export type { Settings } from "../deepinfra.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../deepinfra.js";
@@ -1,7 +1,7 @@
1
1
  import type { ProviderPackage } from "../provider-package.js";
2
2
  import type { ProviderAuthOption } from "../route/auth-options.js";
3
3
  import { Route } from "../route/client.js";
4
- import { type ModelID, type RequestOptions } from "../schema/index.js";
4
+ import { type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js";
5
5
  import type { OpenAIProviderOptionsInput } from "./openai-options.js";
6
6
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
7
  export type Config = Omit<RequestOptions, "providerOptions"> & ProviderAuthOption<"optional"> & {
@@ -365,11 +365,14 @@ export declare const routes: Route<{
365
365
  export declare const configure: (input?: Config) => {
366
366
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
367
367
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
368
+ embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
368
369
  configure: typeof configure;
369
370
  };
370
371
  export declare const provider: {
371
372
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
372
373
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
374
+ embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
373
375
  configure: typeof configure;
374
376
  };
375
377
  export declare const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
378
+ export declare const embeddingModel: (modelID: string, settings?: Settings) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
@@ -1,4 +1,5 @@
1
1
  import { OpenAIChat } from "../protocols/openai-chat.js";
2
+ import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
2
3
  import { Route } from "../route/client.js";
3
4
  import { Endpoint } from "../route/endpoint.js";
4
5
  import { ProviderID } from "../schema/index.js";
@@ -16,11 +17,19 @@ export const route = Route.make({
16
17
  export const routes = [route];
17
18
  export const configure = (input = {}) => {
18
19
  const root = input.baseURL?.replace(/\/+$/, "");
19
- const configured = route.with({
20
+ const options = {
20
21
  ...bearerRouteDefaults(input, "DEEPINFRA_API_KEY"),
21
22
  endpoint: {
22
23
  baseURL: root === undefined ? baseURL : root.endsWith("/openai") ? root : `${root}/openai`,
23
24
  },
25
+ };
26
+ const configured = route.with(options);
27
+ const embeddingRoute = OpenAIEmbeddings.route.with({
28
+ provider: id,
29
+ endpoint: options.endpoint,
30
+ auth: options.auth,
31
+ headers: input.headers,
32
+ http: input.http,
24
33
  });
25
34
  return {
26
35
  id,
@@ -32,8 +41,13 @@ export const configure = (input = {}) => {
32
41
  },
33
42
  capabilities: { promptCacheKey: true },
34
43
  }),
44
+ embedding: (modelID, providerOptions) => embeddingRoute.model({ id: modelID, providerOptions }),
35
45
  configure,
36
46
  };
37
47
  };
38
48
  export const provider = configure();
39
49
  export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
50
+ export const embeddingModel = (modelID, settings) => {
51
+ const input = toConfig(settings);
52
+ return configure(input).embedding(modelID, input.providerOptions);
53
+ };
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../digitalocean.js";
2
+ export type { Settings } from "../digitalocean.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../digitalocean.js";
@@ -822,6 +822,7 @@ export declare const configure: (input?: Config) => {
822
822
  responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
823
823
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
824
824
  decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
825
+ embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
825
826
  configure: typeof configure;
826
827
  };
827
828
  export declare const provider: {
@@ -831,9 +832,11 @@ export declare const provider: {
831
832
  responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
832
833
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
833
834
  decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
835
+ embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
834
836
  configure: typeof configure;
835
837
  };
836
838
  export declare const decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
839
+ export declare const embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
837
840
  export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
838
841
  export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
839
842
  export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
@@ -841,4 +844,5 @@ export declare const model: ProviderPackage.Model<Settings, OpenAIProviderOption
841
844
  export declare const responsesModel: ProviderPackage.Model<Settings<OpenResponsesProviderOptionsInput>, OpenResponsesProviderOptionsInput>;
842
845
  export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
843
846
  export declare const decisionModel: (modelID: string, settings?: Settings) => import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>;
847
+ export declare const embeddingModel: (modelID: string, settings?: Settings) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
844
848
  export * as DigitalOcean from "./digitalocean.js";