@ai-sdk/alibaba 1.0.25 → 1.0.26

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/alibaba
2
2
 
3
+ ## 1.0.26
4
+
5
+ ### Patch Changes
6
+
7
+ - bc29fbe: feat(aliababa): add embedding model support
8
+
3
9
  ## 1.0.25
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AI SDK - Alibaba Provider
2
2
 
3
- The **[Alibaba provider](https://ai-sdk.dev/providers/ai-sdk-providers/alibaba)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for [Alibaba Cloud Model Studio](https://modelstudio.console.alibabacloud.com/), including the Qwen model series with advanced reasoning capabilities.
3
+ The **[Alibaba provider](https://ai-sdk.dev/providers/ai-sdk-providers/alibaba)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model, embedding model, and video model support for [Alibaba Cloud Model Studio](https://modelstudio.console.alibabacloud.com/), including the Qwen model series with advanced reasoning capabilities.
4
4
 
5
5
  > **Deploying to Vercel?** With Vercel's AI Gateway you can access Alibaba (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
6
6
 
@@ -63,6 +63,25 @@ console.log('Reasoning:', reasoningText);
63
63
  console.log('Answer:', text);
64
64
  ```
65
65
 
66
+ ## Embedding Model Example
67
+
68
+ ```ts
69
+ import { alibaba, type AlibabaEmbeddingModelOptions } from '@ai-sdk/alibaba';
70
+ import { embed } from 'ai';
71
+
72
+ const { embedding, usage } = await embed({
73
+ model: alibaba.embedding('text-embedding-v4'),
74
+ value: 'sunny day at the beach',
75
+ providerOptions: {
76
+ alibaba: {
77
+ textType: 'document',
78
+ dimension: 1024,
79
+ outputType: 'dense',
80
+ } satisfies AlibabaEmbeddingModelOptions,
81
+ },
82
+ });
83
+ ```
84
+
66
85
  ## Tool Calling Example
67
86
 
68
87
  ```ts
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
- import { ProviderV3, LanguageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
2
+ import { ProviderV3, LanguageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
3
3
  import { FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
5
  type AlibabaChatModelId = 'qwen3.7-max' | 'qwen3-max' | 'qwen3-max-preview' | 'qwen-plus' | 'qwen-plus-latest' | 'qwen-flash' | 'qwen-turbo' | 'qwen-turbo-latest' | 'qwen3-235b-a22b' | 'qwen3-32b' | 'qwen3-30b-a3b' | 'qwen3-14b' | 'qwen3-next-80b-a3b-thinking' | 'qwen3-235b-a22b-thinking-2507' | 'qwen3-30b-a3b-thinking-2507' | 'qwq-plus' | 'qwq-plus-latest' | 'qwq-32b' | 'qwen-coder' | 'qwen3-coder-plus' | 'qwen3-coder-flash' | (string & {});
@@ -14,6 +14,21 @@ type AlibabaCacheControl = {
14
14
  type: string;
15
15
  };
16
16
 
17
+ type AlibabaEmbeddingModelId = 'text-embedding-v4' | 'text-embedding-v3' | (string & {});
18
+ declare const alibabaEmbeddingModelOptions: z.ZodObject<{
19
+ textType: z.ZodOptional<z.ZodEnum<{
20
+ query: "query";
21
+ document: "document";
22
+ }>>;
23
+ dimension: z.ZodOptional<z.ZodNumber>;
24
+ outputType: z.ZodOptional<z.ZodEnum<{
25
+ dense: "dense";
26
+ sparse: "sparse";
27
+ "dense&sparse": "dense&sparse";
28
+ }>>;
29
+ }, z.core.$strip>;
30
+ type AlibabaEmbeddingModelOptions = z.infer<typeof alibabaEmbeddingModelOptions>;
31
+
17
32
  type AlibabaVideoModelId = 'wan2.6-t2v' | 'wan2.5-t2v-preview' | 'wan2.6-i2v' | 'wan2.6-i2v-flash' | 'wan2.6-r2v' | 'wan2.6-r2v-flash' | (string & {});
18
33
 
19
34
  interface AlibabaProvider extends ProviderV3 {
@@ -26,6 +41,26 @@ interface AlibabaProvider extends ProviderV3 {
26
41
  * Creates a chat model for text generation.
27
42
  */
28
43
  chatModel(modelId: AlibabaChatModelId): LanguageModelV3;
44
+ /**
45
+ * Creates a model for text embeddings.
46
+ */
47
+ embedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
48
+ /**
49
+ * Creates a model for text embeddings.
50
+ */
51
+ embeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
52
+ /**
53
+ * Creates a model for text embeddings.
54
+ *
55
+ * @deprecated Use `embedding` instead.
56
+ */
57
+ textEmbedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
58
+ /**
59
+ * Creates a model for text embeddings.
60
+ *
61
+ * @deprecated Use `embeddingModel` instead.
62
+ */
63
+ textEmbeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
29
64
  /**
30
65
  * Creates a model for video generation.
31
66
  */
@@ -47,6 +82,12 @@ interface AlibabaProviderSettings {
47
82
  * The default prefix is `https://dashscope-intl.aliyuncs.com`.
48
83
  */
49
84
  videoBaseURL?: string;
85
+ /**
86
+ * Use a different URL prefix for embedding API calls.
87
+ * The embedding API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
88
+ * The default prefix is `https://dashscope-intl.aliyuncs.com/api/v1`.
89
+ */
90
+ embeddingBaseURL?: string;
50
91
  /**
51
92
  * API key that is being sent using the `Authorization` header.
52
93
  * It defaults to the `ALIBABA_API_KEY` environment variable.
@@ -116,4 +157,4 @@ type AlibabaUsage = {
116
157
 
117
158
  declare const VERSION: string;
118
159
 
119
- export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaLanguageModelOptions, type AlibabaProvider, type AlibabaLanguageModelOptions as AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoModelOptions, type AlibabaVideoModelOptions as AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };
160
+ export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaEmbeddingModelId, type AlibabaEmbeddingModelOptions, type AlibabaLanguageModelOptions, type AlibabaProvider, type AlibabaLanguageModelOptions as AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoModelOptions, type AlibabaVideoModelOptions as AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
- import { ProviderV3, LanguageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
2
+ import { ProviderV3, LanguageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
3
3
  import { FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
5
  type AlibabaChatModelId = 'qwen3.7-max' | 'qwen3-max' | 'qwen3-max-preview' | 'qwen-plus' | 'qwen-plus-latest' | 'qwen-flash' | 'qwen-turbo' | 'qwen-turbo-latest' | 'qwen3-235b-a22b' | 'qwen3-32b' | 'qwen3-30b-a3b' | 'qwen3-14b' | 'qwen3-next-80b-a3b-thinking' | 'qwen3-235b-a22b-thinking-2507' | 'qwen3-30b-a3b-thinking-2507' | 'qwq-plus' | 'qwq-plus-latest' | 'qwq-32b' | 'qwen-coder' | 'qwen3-coder-plus' | 'qwen3-coder-flash' | (string & {});
@@ -14,6 +14,21 @@ type AlibabaCacheControl = {
14
14
  type: string;
15
15
  };
16
16
 
17
+ type AlibabaEmbeddingModelId = 'text-embedding-v4' | 'text-embedding-v3' | (string & {});
18
+ declare const alibabaEmbeddingModelOptions: z.ZodObject<{
19
+ textType: z.ZodOptional<z.ZodEnum<{
20
+ query: "query";
21
+ document: "document";
22
+ }>>;
23
+ dimension: z.ZodOptional<z.ZodNumber>;
24
+ outputType: z.ZodOptional<z.ZodEnum<{
25
+ dense: "dense";
26
+ sparse: "sparse";
27
+ "dense&sparse": "dense&sparse";
28
+ }>>;
29
+ }, z.core.$strip>;
30
+ type AlibabaEmbeddingModelOptions = z.infer<typeof alibabaEmbeddingModelOptions>;
31
+
17
32
  type AlibabaVideoModelId = 'wan2.6-t2v' | 'wan2.5-t2v-preview' | 'wan2.6-i2v' | 'wan2.6-i2v-flash' | 'wan2.6-r2v' | 'wan2.6-r2v-flash' | (string & {});
18
33
 
19
34
  interface AlibabaProvider extends ProviderV3 {
@@ -26,6 +41,26 @@ interface AlibabaProvider extends ProviderV3 {
26
41
  * Creates a chat model for text generation.
27
42
  */
28
43
  chatModel(modelId: AlibabaChatModelId): LanguageModelV3;
44
+ /**
45
+ * Creates a model for text embeddings.
46
+ */
47
+ embedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
48
+ /**
49
+ * Creates a model for text embeddings.
50
+ */
51
+ embeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
52
+ /**
53
+ * Creates a model for text embeddings.
54
+ *
55
+ * @deprecated Use `embedding` instead.
56
+ */
57
+ textEmbedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
58
+ /**
59
+ * Creates a model for text embeddings.
60
+ *
61
+ * @deprecated Use `embeddingModel` instead.
62
+ */
63
+ textEmbeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
29
64
  /**
30
65
  * Creates a model for video generation.
31
66
  */
@@ -47,6 +82,12 @@ interface AlibabaProviderSettings {
47
82
  * The default prefix is `https://dashscope-intl.aliyuncs.com`.
48
83
  */
49
84
  videoBaseURL?: string;
85
+ /**
86
+ * Use a different URL prefix for embedding API calls.
87
+ * The embedding API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
88
+ * The default prefix is `https://dashscope-intl.aliyuncs.com/api/v1`.
89
+ */
90
+ embeddingBaseURL?: string;
50
91
  /**
51
92
  * API key that is being sent using the `Authorization` header.
52
93
  * It defaults to the `ALIBABA_API_KEY` environment variable.
@@ -116,4 +157,4 @@ type AlibabaUsage = {
116
157
 
117
158
  declare const VERSION: string;
118
159
 
119
- export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaLanguageModelOptions, type AlibabaProvider, type AlibabaLanguageModelOptions as AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoModelOptions, type AlibabaVideoModelOptions as AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };
160
+ export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaEmbeddingModelId, type AlibabaEmbeddingModelOptions, type AlibabaLanguageModelOptions, type AlibabaProvider, type AlibabaLanguageModelOptions as AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoModelOptions, type AlibabaVideoModelOptions as AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };
package/dist/index.js CHANGED
@@ -27,8 +27,8 @@ __export(index_exports, {
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/alibaba-provider.ts
30
- var import_provider4 = require("@ai-sdk/provider");
31
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
30
+ var import_provider5 = require("@ai-sdk/provider");
31
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/alibaba-chat-language-model.ts
34
34
  var import_internal2 = require("@ai-sdk/openai-compatible/internal");
@@ -706,61 +706,201 @@ var alibabaChatChunkSchema = import_v43.z.object({
706
706
  // Usage only appears in final chunk
707
707
  });
708
708
 
709
- // src/alibaba-video-model.ts
709
+ // src/alibaba-embedding-model.ts
710
710
  var import_provider3 = require("@ai-sdk/provider");
711
711
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
712
+ var import_v45 = require("zod/v4");
713
+
714
+ // src/alibaba-embedding-options.ts
712
715
  var import_v44 = require("zod/v4");
713
- var alibabaVideoModelOptionsSchema = (0, import_provider_utils4.lazySchema)(
714
- () => (0, import_provider_utils4.zodSchema)(
715
- import_v44.z.object({
716
- negativePrompt: import_v44.z.string().nullish(),
717
- audioUrl: import_v44.z.string().nullish(),
718
- promptExtend: import_v44.z.boolean().nullish(),
719
- shotType: import_v44.z.enum(["single", "multi"]).nullish(),
720
- watermark: import_v44.z.boolean().nullish(),
721
- audio: import_v44.z.boolean().nullish(),
722
- referenceUrls: import_v44.z.array(import_v44.z.string()).nullish(),
723
- pollIntervalMs: import_v44.z.number().positive().nullish(),
724
- pollTimeoutMs: import_v44.z.number().positive().nullish()
716
+ var alibabaEmbeddingModelOptions = import_v44.z.object({
717
+ /**
718
+ * Differentiates query text from document text for asymmetric retrieval tasks.
719
+ * Defaults to `document`.
720
+ */
721
+ textType: import_v44.z.enum(["query", "document"]).optional(),
722
+ /**
723
+ * The dimension of the output embedding vectors. Defaults to 1024.
724
+ *
725
+ * `text-embedding-v4` also supports 1536 and 2048 dimensions.
726
+ */
727
+ dimension: import_v44.z.number().optional(),
728
+ /**
729
+ * The output vector type. Defaults to `dense`.
730
+ *
731
+ * Sparse-only output is not supported by the AI SDK embedding interface,
732
+ * which requires dense number arrays.
733
+ */
734
+ outputType: import_v44.z.enum(["dense", "sparse", "dense&sparse"]).optional()
735
+ });
736
+
737
+ // src/alibaba-embedding-model.ts
738
+ var alibabaEmbeddingFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
739
+ errorSchema: import_v45.z.object({
740
+ code: import_v45.z.string().nullish(),
741
+ message: import_v45.z.string(),
742
+ request_id: import_v45.z.string().nullish()
743
+ }),
744
+ errorToMessage: (data) => data.message
745
+ });
746
+ var AlibabaEmbeddingModel = class {
747
+ constructor(modelId, config) {
748
+ this.specificationVersion = "v3";
749
+ this.maxEmbeddingsPerCall = 10;
750
+ this.supportsParallelCalls = false;
751
+ this.modelId = modelId;
752
+ this.config = config;
753
+ }
754
+ get provider() {
755
+ return this.config.provider;
756
+ }
757
+ async doEmbed({
758
+ values,
759
+ headers,
760
+ abortSignal,
761
+ providerOptions
762
+ }) {
763
+ if (values.length > this.maxEmbeddingsPerCall) {
764
+ throw new import_provider3.TooManyEmbeddingValuesForCallError({
765
+ provider: this.provider,
766
+ modelId: this.modelId,
767
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
768
+ values
769
+ });
770
+ }
771
+ const alibabaOptions = await (0, import_provider_utils4.parseProviderOptions)({
772
+ provider: "alibaba",
773
+ providerOptions,
774
+ schema: alibabaEmbeddingModelOptions
775
+ });
776
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.outputType) === "sparse") {
777
+ throw new import_provider3.UnsupportedFunctionalityError({
778
+ functionality: "Alibaba embedding outputType 'sparse'",
779
+ message: "Alibaba embedding outputType 'sparse' is not supported because AI SDK embeddings require dense number arrays. Use 'dense' or 'dense&sparse' instead."
780
+ });
781
+ }
782
+ const {
783
+ responseHeaders,
784
+ value: response,
785
+ rawValue
786
+ } = await (0, import_provider_utils4.postJsonToApi)({
787
+ url: `${this.config.baseURL}/services/embeddings/text-embedding/text-embedding`,
788
+ headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), headers),
789
+ body: {
790
+ model: this.modelId,
791
+ input: {
792
+ texts: values
793
+ },
794
+ parameters: {
795
+ text_type: alibabaOptions == null ? void 0 : alibabaOptions.textType,
796
+ dimension: alibabaOptions == null ? void 0 : alibabaOptions.dimension,
797
+ output_type: alibabaOptions == null ? void 0 : alibabaOptions.outputType
798
+ }
799
+ },
800
+ failedResponseHandler: alibabaEmbeddingFailedResponseHandler,
801
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
802
+ alibabaTextEmbeddingResponseSchema
803
+ ),
804
+ abortSignal,
805
+ fetch: this.config.fetch
806
+ });
807
+ const sortedEmbeddings = response.output.embeddings.sort(
808
+ (a, b) => a.text_index - b.text_index
809
+ );
810
+ const sparseEmbeddings = sortedEmbeddings.map(
811
+ (item) => item.sparse_embedding == null ? void 0 : {
812
+ textIndex: item.text_index,
813
+ sparseEmbedding: item.sparse_embedding
814
+ }
815
+ ).filter((item) => item != null);
816
+ return {
817
+ warnings: [],
818
+ embeddings: sortedEmbeddings.map((item) => item.embedding),
819
+ usage: response.usage ? { tokens: response.usage.total_tokens } : void 0,
820
+ providerMetadata: sparseEmbeddings.length > 0 ? {
821
+ alibaba: {
822
+ sparseEmbeddings
823
+ }
824
+ } : void 0,
825
+ response: { headers: responseHeaders, body: rawValue }
826
+ };
827
+ }
828
+ };
829
+ var alibabaTextEmbeddingSparseEmbeddingSchema = import_v45.z.object({
830
+ index: import_v45.z.number(),
831
+ value: import_v45.z.number(),
832
+ token: import_v45.z.string().nullish()
833
+ });
834
+ var alibabaTextEmbeddingResponseSchema = import_v45.z.object({
835
+ output: import_v45.z.object({
836
+ embeddings: import_v45.z.array(
837
+ import_v45.z.object({
838
+ embedding: import_v45.z.array(import_v45.z.number()),
839
+ text_index: import_v45.z.number(),
840
+ sparse_embedding: import_v45.z.array(alibabaTextEmbeddingSparseEmbeddingSchema).nullish()
841
+ })
842
+ )
843
+ }),
844
+ usage: import_v45.z.object({
845
+ total_tokens: import_v45.z.number()
846
+ }).nullish()
847
+ });
848
+
849
+ // src/alibaba-video-model.ts
850
+ var import_provider4 = require("@ai-sdk/provider");
851
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
852
+ var import_v46 = require("zod/v4");
853
+ var alibabaVideoModelOptionsSchema = (0, import_provider_utils5.lazySchema)(
854
+ () => (0, import_provider_utils5.zodSchema)(
855
+ import_v46.z.object({
856
+ negativePrompt: import_v46.z.string().nullish(),
857
+ audioUrl: import_v46.z.string().nullish(),
858
+ promptExtend: import_v46.z.boolean().nullish(),
859
+ shotType: import_v46.z.enum(["single", "multi"]).nullish(),
860
+ watermark: import_v46.z.boolean().nullish(),
861
+ audio: import_v46.z.boolean().nullish(),
862
+ referenceUrls: import_v46.z.array(import_v46.z.string()).nullish(),
863
+ pollIntervalMs: import_v46.z.number().positive().nullish(),
864
+ pollTimeoutMs: import_v46.z.number().positive().nullish()
725
865
  }).passthrough()
726
866
  )
727
867
  );
728
- var alibabaVideoErrorSchema = import_v44.z.object({
729
- code: import_v44.z.string().nullish(),
730
- message: import_v44.z.string(),
731
- request_id: import_v44.z.string().nullish()
868
+ var alibabaVideoErrorSchema = import_v46.z.object({
869
+ code: import_v46.z.string().nullish(),
870
+ message: import_v46.z.string(),
871
+ request_id: import_v46.z.string().nullish()
732
872
  });
733
- var alibabaVideoFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
873
+ var alibabaVideoFailedResponseHandler = (0, import_provider_utils5.createJsonErrorResponseHandler)({
734
874
  errorSchema: alibabaVideoErrorSchema,
735
875
  errorToMessage: (data) => data.message
736
876
  });
737
- var alibabaVideoCreateTaskSchema = import_v44.z.object({
738
- output: import_v44.z.object({
739
- task_status: import_v44.z.string(),
740
- task_id: import_v44.z.string()
877
+ var alibabaVideoCreateTaskSchema = import_v46.z.object({
878
+ output: import_v46.z.object({
879
+ task_status: import_v46.z.string(),
880
+ task_id: import_v46.z.string()
741
881
  }).nullish(),
742
- request_id: import_v44.z.string().nullish()
882
+ request_id: import_v46.z.string().nullish()
743
883
  });
744
- var alibabaVideoTaskStatusSchema = import_v44.z.object({
745
- output: import_v44.z.object({
746
- task_id: import_v44.z.string(),
747
- task_status: import_v44.z.string(),
748
- video_url: import_v44.z.string().nullish(),
749
- submit_time: import_v44.z.string().nullish(),
750
- scheduled_time: import_v44.z.string().nullish(),
751
- end_time: import_v44.z.string().nullish(),
752
- orig_prompt: import_v44.z.string().nullish(),
753
- actual_prompt: import_v44.z.string().nullish(),
754
- code: import_v44.z.string().nullish(),
755
- message: import_v44.z.string().nullish()
884
+ var alibabaVideoTaskStatusSchema = import_v46.z.object({
885
+ output: import_v46.z.object({
886
+ task_id: import_v46.z.string(),
887
+ task_status: import_v46.z.string(),
888
+ video_url: import_v46.z.string().nullish(),
889
+ submit_time: import_v46.z.string().nullish(),
890
+ scheduled_time: import_v46.z.string().nullish(),
891
+ end_time: import_v46.z.string().nullish(),
892
+ orig_prompt: import_v46.z.string().nullish(),
893
+ actual_prompt: import_v46.z.string().nullish(),
894
+ code: import_v46.z.string().nullish(),
895
+ message: import_v46.z.string().nullish()
756
896
  }).nullish(),
757
- usage: import_v44.z.object({
758
- duration: import_v44.z.number().nullish(),
759
- output_video_duration: import_v44.z.number().nullish(),
760
- SR: import_v44.z.number().nullish(),
761
- size: import_v44.z.string().nullish()
897
+ usage: import_v46.z.object({
898
+ duration: import_v46.z.number().nullish(),
899
+ output_video_duration: import_v46.z.number().nullish(),
900
+ SR: import_v46.z.number().nullish(),
901
+ size: import_v46.z.string().nullish()
762
902
  }).nullish(),
763
- request_id: import_v44.z.string().nullish()
903
+ request_id: import_v46.z.string().nullish()
764
904
  });
765
905
  function detectMode(modelId) {
766
906
  if (modelId.includes("-i2v")) return "i2v";
@@ -782,7 +922,7 @@ var AlibabaVideoModel = class {
782
922
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
783
923
  const warnings = [];
784
924
  const mode = detectMode(this.modelId);
785
- const alibabaOptions = await (0, import_provider_utils4.parseProviderOptions)({
925
+ const alibabaOptions = await (0, import_provider_utils5.parseProviderOptions)({
786
926
  provider: "alibaba",
787
927
  providerOptions: options.providerOptions,
788
928
  schema: alibabaVideoModelOptionsSchema
@@ -801,7 +941,7 @@ var AlibabaVideoModel = class {
801
941
  if (options.image.type === "url") {
802
942
  input.img_url = options.image.url;
803
943
  } else {
804
- const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils4.convertUint8ArrayToBase64)(options.image.data);
944
+ const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils5.convertUint8ArrayToBase64)(options.image.data);
805
945
  input.img_url = base64Data;
806
946
  }
807
947
  }
@@ -870,10 +1010,10 @@ var AlibabaVideoModel = class {
870
1010
  details: "Alibaba video models only support generating 1 video per call."
871
1011
  });
872
1012
  }
873
- const { value: createResponse } = await (0, import_provider_utils4.postJsonToApi)({
1013
+ const { value: createResponse } = await (0, import_provider_utils5.postJsonToApi)({
874
1014
  url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
875
- headers: (0, import_provider_utils4.combineHeaders)(
876
- await (0, import_provider_utils4.resolve)(this.config.headers),
1015
+ headers: (0, import_provider_utils5.combineHeaders)(
1016
+ await (0, import_provider_utils5.resolve)(this.config.headers),
877
1017
  options.headers,
878
1018
  {
879
1019
  "X-DashScope-Async": "enable"
@@ -884,7 +1024,7 @@ var AlibabaVideoModel = class {
884
1024
  input,
885
1025
  parameters
886
1026
  },
887
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1027
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
888
1028
  alibabaVideoCreateTaskSchema
889
1029
  ),
890
1030
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -893,7 +1033,7 @@ var AlibabaVideoModel = class {
893
1033
  });
894
1034
  const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
895
1035
  if (!taskId) {
896
- throw new import_provider3.AISDKError({
1036
+ throw new import_provider4.AISDKError({
897
1037
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
898
1038
  message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
899
1039
  });
@@ -904,20 +1044,20 @@ var AlibabaVideoModel = class {
904
1044
  let finalResponse;
905
1045
  let responseHeaders;
906
1046
  while (true) {
907
- await (0, import_provider_utils4.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
1047
+ await (0, import_provider_utils5.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
908
1048
  if (Date.now() - startTime > pollTimeoutMs) {
909
- throw new import_provider3.AISDKError({
1049
+ throw new import_provider4.AISDKError({
910
1050
  name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
911
1051
  message: `Video generation timed out after ${pollTimeoutMs}ms`
912
1052
  });
913
1053
  }
914
- const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils4.getFromApi)({
1054
+ const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils5.getFromApi)({
915
1055
  url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
916
- headers: (0, import_provider_utils4.combineHeaders)(
917
- await (0, import_provider_utils4.resolve)(this.config.headers),
1056
+ headers: (0, import_provider_utils5.combineHeaders)(
1057
+ await (0, import_provider_utils5.resolve)(this.config.headers),
918
1058
  options.headers
919
1059
  ),
920
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1060
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
921
1061
  alibabaVideoTaskStatusSchema
922
1062
  ),
923
1063
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -931,7 +1071,7 @@ var AlibabaVideoModel = class {
931
1071
  break;
932
1072
  }
933
1073
  if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
934
- throw new import_provider3.AISDKError({
1074
+ throw new import_provider4.AISDKError({
935
1075
  name: "ALIBABA_VIDEO_GENERATION_FAILED",
936
1076
  message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
937
1077
  });
@@ -939,7 +1079,7 @@ var AlibabaVideoModel = class {
939
1079
  }
940
1080
  const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
941
1081
  if (!videoUrl) {
942
- throw new import_provider3.AISDKError({
1082
+ throw new import_provider4.AISDKError({
943
1083
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
944
1084
  message: `No video URL in response. Task ID: ${taskId}`
945
1085
  });
@@ -978,16 +1118,17 @@ var AlibabaVideoModel = class {
978
1118
  };
979
1119
 
980
1120
  // src/version.ts
981
- var VERSION = true ? "1.0.25" : "0.0.0-test";
1121
+ var VERSION = true ? "1.0.26" : "0.0.0-test";
982
1122
 
983
1123
  // src/alibaba-provider.ts
984
1124
  function createAlibaba(options = {}) {
985
- var _a, _b;
986
- const baseURL = (_a = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
987
- const videoBaseURL = (_b = (0, import_provider_utils5.withoutTrailingSlash)(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
988
- const getHeaders = () => (0, import_provider_utils5.withUserAgentSuffix)(
1125
+ var _a, _b, _c;
1126
+ const baseURL = (_a = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
1127
+ const videoBaseURL = (_b = (0, import_provider_utils6.withoutTrailingSlash)(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
1128
+ const embeddingBaseURL = (_c = (0, import_provider_utils6.withoutTrailingSlash)(options.embeddingBaseURL)) != null ? _c : "https://dashscope-intl.aliyuncs.com/api/v1";
1129
+ const getHeaders = () => (0, import_provider_utils6.withUserAgentSuffix)(
989
1130
  {
990
- Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({
1131
+ Authorization: `Bearer ${(0, import_provider_utils6.loadApiKey)({
991
1132
  apiKey: options.apiKey,
992
1133
  environmentVariableName: "ALIBABA_API_KEY",
993
1134
  description: "Alibaba Cloud (DashScope)"
@@ -1006,6 +1147,12 @@ function createAlibaba(options = {}) {
1006
1147
  includeUsage: (_a2 = options.includeUsage) != null ? _a2 : true
1007
1148
  });
1008
1149
  };
1150
+ const createEmbeddingModel = (modelId) => new AlibabaEmbeddingModel(modelId, {
1151
+ provider: "alibaba.embedding",
1152
+ baseURL: embeddingBaseURL,
1153
+ headers: getHeaders,
1154
+ fetch: options.fetch
1155
+ });
1009
1156
  const createVideoModel = (modelId) => new AlibabaVideoModel(modelId, {
1010
1157
  provider: "alibaba.video",
1011
1158
  baseURL: videoBaseURL,
@@ -1023,13 +1170,14 @@ function createAlibaba(options = {}) {
1023
1170
  provider.specificationVersion = "v3";
1024
1171
  provider.languageModel = createLanguageModel;
1025
1172
  provider.chatModel = createLanguageModel;
1173
+ provider.embedding = createEmbeddingModel;
1174
+ provider.embeddingModel = createEmbeddingModel;
1175
+ provider.textEmbedding = createEmbeddingModel;
1176
+ provider.textEmbeddingModel = createEmbeddingModel;
1026
1177
  provider.video = createVideoModel;
1027
1178
  provider.videoModel = createVideoModel;
1028
1179
  provider.imageModel = (modelId) => {
1029
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1030
- };
1031
- provider.embeddingModel = (modelId) => {
1032
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
1180
+ throw new import_provider5.NoSuchModelError({ modelId, modelType: "imageModel" });
1033
1181
  };
1034
1182
  return provider;
1035
1183
  }