@sweetretry/ai-sdk-volcengine-adapter 0.1.0 → 0.1.2
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/dist/chat/convert-to-volcengine-chat-message.d.ts +3 -0
- package/dist/chat/convert-to-volcengine-chat-message.js +189 -0
- package/dist/chat/convert-to-volcengine-chat-message.js.map +1 -0
- package/dist/chat/convert-volcengine-chat-usage.d.ts +28 -0
- package/dist/chat/convert-volcengine-chat-usage.js +51 -0
- package/dist/chat/convert-volcengine-chat-usage.js.map +1 -0
- package/dist/chat/get-response-metadata.d.ts +9 -0
- package/dist/chat/get-response-metadata.js +9 -0
- package/dist/chat/get-response-metadata.js.map +1 -0
- package/dist/chat/index.d.ts +2 -0
- package/dist/chat/index.js +3 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/map-volcengine-finish-reason.d.ts +2 -0
- package/dist/chat/map-volcengine-finish-reason.js +32 -0
- package/dist/chat/map-volcengine-finish-reason.js.map +1 -0
- package/dist/chat/volcengine-chat-language-model.d.ts +22 -0
- package/dist/chat/volcengine-chat-language-model.js +443 -0
- package/dist/chat/volcengine-chat-language-model.js.map +1 -0
- package/dist/chat/volcengine-chat-options.d.ts +16 -0
- package/dist/chat/volcengine-chat-options.js +29 -0
- package/dist/chat/volcengine-chat-options.js.map +1 -0
- package/dist/chat/volcengine-chat-prompt.d.ts +49 -0
- package/dist/chat/volcengine-chat-prompt.js +4 -0
- package/dist/chat/volcengine-chat-prompt.js.map +1 -0
- package/dist/chat/volcengine-error.d.ts +1 -0
- package/dist/chat/volcengine-error.js +16 -0
- package/dist/chat/volcengine-error.js.map +1 -0
- package/dist/chat/volcengine-prepare-tools.d.ts +30 -0
- package/dist/chat/volcengine-prepare-tools.js +96 -0
- package/dist/chat/volcengine-prepare-tools.js.map +1 -0
- package/dist/convert-to-volcengine-chat-message.js +12 -0
- package/dist/convert-to-volcengine-chat-message.js.map +1 -1
- package/dist/image/index.d.ts +1 -0
- package/dist/image/index.js +3 -0
- package/dist/image/index.js.map +1 -0
- package/dist/image/volcengine-image-api.d.ts +22 -0
- package/dist/image/volcengine-image-api.js +22 -0
- package/dist/image/volcengine-image-api.js.map +1 -0
- package/dist/image/volcengine-image-model.d.ts +29 -0
- package/dist/image/volcengine-image-model.js +99 -0
- package/dist/image/volcengine-image-model.js.map +1 -0
- package/dist/image/volcengine-image-options.d.ts +24 -0
- package/dist/image/volcengine-image-options.js +32 -0
- package/dist/image/volcengine-image-options.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tool/image-generation.d.ts +107 -0
- package/dist/tool/image-generation.js +79 -0
- package/dist/tool/image-generation.js.map +1 -0
- package/dist/tool/web-search.d.ts +70 -2
- package/dist/tool/web-search.js +42 -29
- package/dist/tool/web-search.js.map +1 -1
- package/dist/volcengine-chat-prompt.d.ts +3 -0
- package/dist/volcengine-chat-prompt.js.map +1 -1
- package/dist/volcengine-prepare-tools.js +46 -5
- package/dist/volcengine-prepare-tools.js.map +1 -1
- package/dist/volcengine-provider.d.ts +12 -2
- package/dist/volcengine-provider.js +24 -23
- package/dist/volcengine-provider.js.map +1 -1
- package/dist/volcengine-tools.d.ts +3 -1
- package/package.json +12 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createProviderToolFactoryWithOutputSchema, lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
export const imageGenerationArgsSchema = lazySchema(()=>zodSchema(z.object({
|
|
4
|
+
model: z.string().optional(),
|
|
5
|
+
size: z.enum([
|
|
6
|
+
"2K",
|
|
7
|
+
"4K"
|
|
8
|
+
]).optional(),
|
|
9
|
+
responseFormat: z.enum([
|
|
10
|
+
"url",
|
|
11
|
+
"b64_json"
|
|
12
|
+
]).optional(),
|
|
13
|
+
image: z.union([
|
|
14
|
+
z.string(),
|
|
15
|
+
z.array(z.string())
|
|
16
|
+
]).optional()
|
|
17
|
+
}).strict()));
|
|
18
|
+
const imageGenerationInputSchema = lazySchema(()=>zodSchema(z.object({})));
|
|
19
|
+
export const imageGenerationOutputSchema = lazySchema(()=>zodSchema(z.object({
|
|
20
|
+
model: z.string(),
|
|
21
|
+
created: z.number(),
|
|
22
|
+
data: z.array(z.object({
|
|
23
|
+
url: z.string().optional(),
|
|
24
|
+
b64_json: z.string().optional(),
|
|
25
|
+
size: z.string()
|
|
26
|
+
})),
|
|
27
|
+
usage: z.object({
|
|
28
|
+
generated_images: z.number(),
|
|
29
|
+
output_tokens: z.number(),
|
|
30
|
+
total_tokens: z.number()
|
|
31
|
+
})
|
|
32
|
+
})));
|
|
33
|
+
const imageGenerationToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
34
|
+
id: "volcengine.image_generation",
|
|
35
|
+
inputSchema: imageGenerationInputSchema,
|
|
36
|
+
outputSchema: imageGenerationOutputSchema
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Volcengine Image Generation Tool
|
|
40
|
+
*
|
|
41
|
+
* Enables the model to generate images from text prompts or reference images.
|
|
42
|
+
*
|
|
43
|
+
* Supports three modes:
|
|
44
|
+
* - Text-to-Image: Generate images from text prompts only
|
|
45
|
+
* - Image-to-Image: Generate images using a single reference image
|
|
46
|
+
* - Multi-Image-to-Image: Generate images using multiple reference images
|
|
47
|
+
*
|
|
48
|
+
* @see https://www.volcengine.com/docs/82379/1824121
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // Text-to-Image
|
|
53
|
+
* volcengineTools.imageGeneration({
|
|
54
|
+
* size: "2K",
|
|
55
|
+
* })
|
|
56
|
+
*
|
|
57
|
+
* // Image-to-Image
|
|
58
|
+
* volcengineTools.imageGeneration({
|
|
59
|
+
* size: "2K",
|
|
60
|
+
* image: "https://example.com/reference.png",
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* // Multi-Image-to-Image
|
|
64
|
+
* volcengineTools.imageGeneration({
|
|
65
|
+
* size: "2K",
|
|
66
|
+
* image: ["https://example.com/img1.png", "https://example.com/img2.png"],
|
|
67
|
+
* })
|
|
68
|
+
*
|
|
69
|
+
* // Get Base64 encoded image
|
|
70
|
+
* volcengineTools.imageGeneration({
|
|
71
|
+
* size: "2K",
|
|
72
|
+
* responseFormat: "b64_json",
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/ export const imageGeneration = (args = {})=>{
|
|
76
|
+
return imageGenerationToolFactory(args);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=image-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tool/image-generation.ts"],"sourcesContent":["import {\n createProviderToolFactoryWithOutputSchema,\n lazySchema,\n zodSchema,\n} from \"@ai-sdk/provider-utils\";\nimport { z } from \"zod/v4\";\n\nexport const imageGenerationArgsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n model: z.string().optional(),\n size: z.enum([\"2K\", \"4K\"]).optional(),\n responseFormat: z.enum([\"url\", \"b64_json\"]).optional(),\n image: z.union([z.string(), z.array(z.string())]).optional(),\n })\n .strict()\n )\n);\n\nconst imageGenerationInputSchema = lazySchema(() => zodSchema(z.object({})));\n\nexport const imageGenerationOutputSchema = lazySchema(() =>\n zodSchema(\n z.object({\n model: z.string(),\n created: z.number(),\n data: z.array(\n z.object({\n url: z.string().optional(),\n b64_json: z.string().optional(),\n size: z.string(),\n })\n ),\n usage: z.object({\n generated_images: z.number(),\n output_tokens: z.number(),\n total_tokens: z.number(),\n }),\n })\n )\n);\n\n/**\n * Image generation input options.\n */\nexport interface ImageGenerationArgs {\n /**\n * Model ID for image generation.\n * @default \"doubao-seedream-4-5-251128\"\n */\n model?: string;\n\n /**\n * Image resolution.\n * @default \"2K\"\n */\n size?: \"2K\" | \"4K\";\n\n /**\n * Response format for the generated image.\n * - \"url\": Returns image download URL (valid for 24 hours)\n * - \"b64_json\": Returns Base64 encoded image data\n * @default \"url\"\n */\n responseFormat?: \"url\" | \"b64_json\";\n\n /**\n * Reference image URL(s) for image-to-image generation.\n * - Single URL string for single image reference\n * - Array of URLs for multi-image reference\n */\n image?: string | string[];\n}\n\n/**\n * Image generation output.\n */\nexport interface ImageGenerationOutput {\n model: string;\n created: number;\n data: Array<{\n /** Image URL, returned when response_format is url */\n url?: string;\n /** Base64 encoded image, returned when response_format is b64_json */\n b64_json?: string;\n /** Image dimensions (e.g., \"3104x1312\") */\n size: string;\n }>;\n usage: {\n generated_images: number;\n output_tokens: number;\n total_tokens: number;\n };\n}\n\nconst imageGenerationToolFactory = createProviderToolFactoryWithOutputSchema<\n {},\n ImageGenerationOutput,\n ImageGenerationArgs\n>({\n id: \"volcengine.image_generation\",\n inputSchema: imageGenerationInputSchema,\n outputSchema: imageGenerationOutputSchema,\n});\n\n/**\n * Volcengine Image Generation Tool\n *\n * Enables the model to generate images from text prompts or reference images.\n *\n * Supports three modes:\n * - Text-to-Image: Generate images from text prompts only\n * - Image-to-Image: Generate images using a single reference image\n * - Multi-Image-to-Image: Generate images using multiple reference images\n *\n * @see https://www.volcengine.com/docs/82379/1824121\n *\n * @example\n * ```ts\n * // Text-to-Image\n * volcengineTools.imageGeneration({\n * size: \"2K\",\n * })\n *\n * // Image-to-Image\n * volcengineTools.imageGeneration({\n * size: \"2K\",\n * image: \"https://example.com/reference.png\",\n * })\n *\n * // Multi-Image-to-Image\n * volcengineTools.imageGeneration({\n * size: \"2K\",\n * image: [\"https://example.com/img1.png\", \"https://example.com/img2.png\"],\n * })\n *\n * // Get Base64 encoded image\n * volcengineTools.imageGeneration({\n * size: \"2K\",\n * responseFormat: \"b64_json\",\n * })\n * ```\n */\nexport const imageGeneration = (args: ImageGenerationArgs = {}) => {\n return imageGenerationToolFactory(args);\n};\n"],"names":["createProviderToolFactoryWithOutputSchema","lazySchema","zodSchema","z","imageGenerationArgsSchema","object","model","string","optional","size","enum","responseFormat","image","union","array","strict","imageGenerationInputSchema","imageGenerationOutputSchema","created","number","data","url","b64_json","usage","generated_images","output_tokens","total_tokens","imageGenerationToolFactory","id","inputSchema","outputSchema","imageGeneration","args"],"mappings":"AAAA,SACEA,yCAAyC,EACzCC,UAAU,EACVC,SAAS,QACJ,yBAAyB;AAChC,SAASC,CAAC,QAAQ,SAAS;AAE3B,OAAO,MAAMC,4BAA4BH,WAAW,IAClDC,UACEC,EACGE,MAAM,CAAC;QACNC,OAAOH,EAAEI,MAAM,GAAGC,QAAQ;QAC1BC,MAAMN,EAAEO,IAAI,CAAC;YAAC;YAAM;SAAK,EAAEF,QAAQ;QACnCG,gBAAgBR,EAAEO,IAAI,CAAC;YAAC;YAAO;SAAW,EAAEF,QAAQ;QACpDI,OAAOT,EAAEU,KAAK,CAAC;YAACV,EAAEI,MAAM;YAAIJ,EAAEW,KAAK,CAACX,EAAEI,MAAM;SAAI,EAAEC,QAAQ;IAC5D,GACCO,MAAM,KAEX;AAEF,MAAMC,6BAA6Bf,WAAW,IAAMC,UAAUC,EAAEE,MAAM,CAAC,CAAC;AAExE,OAAO,MAAMY,8BAA8BhB,WAAW,IACpDC,UACEC,EAAEE,MAAM,CAAC;QACPC,OAAOH,EAAEI,MAAM;QACfW,SAASf,EAAEgB,MAAM;QACjBC,MAAMjB,EAAEW,KAAK,CACXX,EAAEE,MAAM,CAAC;YACPgB,KAAKlB,EAAEI,MAAM,GAAGC,QAAQ;YACxBc,UAAUnB,EAAEI,MAAM,GAAGC,QAAQ;YAC7BC,MAAMN,EAAEI,MAAM;QAChB;QAEFgB,OAAOpB,EAAEE,MAAM,CAAC;YACdmB,kBAAkBrB,EAAEgB,MAAM;YAC1BM,eAAetB,EAAEgB,MAAM;YACvBO,cAAcvB,EAAEgB,MAAM;QACxB;IACF,KAEF;AAuDF,MAAMQ,6BAA6B3B,0CAIjC;IACA4B,IAAI;IACJC,aAAab;IACbc,cAAcb;AAChB;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCC,GACD,OAAO,MAAMc,kBAAkB,CAACC,OAA4B,CAAC,CAAC;IAC5D,OAAOL,2BAA2BK;AACpC,EAAE"}
|
|
@@ -1,12 +1,60 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const webSearchArgsSchema: import("@ai-sdk/provider-utils").LazySchema<{
|
|
2
|
+
maxKeyword?: number | undefined;
|
|
3
|
+
limit?: number | undefined;
|
|
4
|
+
maxToolCalls?: number | undefined;
|
|
5
|
+
sources?: string[] | undefined;
|
|
6
|
+
userLocation?: {
|
|
7
|
+
type?: "approximate" | undefined;
|
|
8
|
+
country?: string | undefined;
|
|
9
|
+
region?: string | undefined;
|
|
10
|
+
city?: string | undefined;
|
|
11
|
+
} | undefined;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const webSearchOutputSchema: import("@ai-sdk/provider-utils").LazySchema<{
|
|
14
|
+
result: string;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Web search input options.
|
|
18
|
+
*/
|
|
19
|
+
export interface WebSearchArgs {
|
|
20
|
+
/**
|
|
21
|
+
* Maximum number of keywords to extract from the query.
|
|
22
|
+
*/
|
|
2
23
|
maxKeyword?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum number of search results to return.
|
|
26
|
+
* @default 10
|
|
27
|
+
*/
|
|
3
28
|
limit?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum number of tool calls.
|
|
31
|
+
* @default 3
|
|
32
|
+
*/
|
|
4
33
|
maxToolCalls?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Sources to search from (e.g., "douyin", "toutiao").
|
|
36
|
+
*/
|
|
5
37
|
sources?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* User location for optimizing search results.
|
|
40
|
+
*/
|
|
6
41
|
userLocation?: {
|
|
42
|
+
/**
|
|
43
|
+
* Location type.
|
|
44
|
+
* @default "approximate"
|
|
45
|
+
*/
|
|
7
46
|
type?: "approximate";
|
|
47
|
+
/**
|
|
48
|
+
* Country name (e.g., "中国").
|
|
49
|
+
*/
|
|
8
50
|
country?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Region/Province name (e.g., "浙江").
|
|
53
|
+
*/
|
|
9
54
|
region?: string;
|
|
55
|
+
/**
|
|
56
|
+
* City name (e.g., "杭州").
|
|
57
|
+
*/
|
|
10
58
|
city?: string;
|
|
11
59
|
};
|
|
12
60
|
}
|
|
@@ -16,5 +64,25 @@ export interface WebSearchInput {
|
|
|
16
64
|
* Enables the model to perform web searches to retrieve up-to-date information.
|
|
17
65
|
*
|
|
18
66
|
* @see https://www.volcengine.com/docs/82379/1756990
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* volcengineTools.webSearch({
|
|
71
|
+
* maxKeyword: 5,
|
|
72
|
+
* limit: 20,
|
|
73
|
+
* sources: ["douyin", "toutiao"],
|
|
74
|
+
* userLocation: {
|
|
75
|
+
* type: "approximate",
|
|
76
|
+
* country: "中国",
|
|
77
|
+
* region: "浙江",
|
|
78
|
+
* city: "杭州",
|
|
79
|
+
* },
|
|
80
|
+
* })
|
|
81
|
+
* ```
|
|
19
82
|
*/
|
|
20
|
-
export declare const webSearch: import("@ai-sdk/provider-utils").
|
|
83
|
+
export declare const webSearch: (args?: WebSearchArgs) => import("@ai-sdk/provider-utils").Tool<{}, {
|
|
84
|
+
/**
|
|
85
|
+
* The search result.
|
|
86
|
+
*/
|
|
87
|
+
result: string;
|
|
88
|
+
}>;
|
package/dist/tool/web-search.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/ const userLocationSchema = z.object({
|
|
6
|
-
/**
|
|
7
|
-
* Location type.
|
|
8
|
-
* @default "approximate"
|
|
9
|
-
*/ type: z.enum([
|
|
1
|
+
import { createProviderToolFactoryWithOutputSchema, lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
const userLocationSchema = z.object({
|
|
4
|
+
type: z.enum([
|
|
10
5
|
"approximate"
|
|
11
|
-
]).
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
]).optional(),
|
|
7
|
+
country: z.string().optional(),
|
|
8
|
+
region: z.string().optional(),
|
|
9
|
+
city: z.string().optional()
|
|
10
|
+
}).strict();
|
|
11
|
+
export const webSearchArgsSchema = lazySchema(()=>zodSchema(z.object({
|
|
12
|
+
maxKeyword: z.number().int().min(1).max(50).optional(),
|
|
13
|
+
limit: z.number().int().min(1).max(50).optional(),
|
|
14
|
+
maxToolCalls: z.number().int().min(1).max(10).optional(),
|
|
15
|
+
sources: z.array(z.string()).optional(),
|
|
16
|
+
userLocation: userLocationSchema.optional()
|
|
17
|
+
}).strict()));
|
|
18
|
+
const webSearchInputSchema = lazySchema(()=>zodSchema(z.object({})));
|
|
19
|
+
export const webSearchOutputSchema = lazySchema(()=>zodSchema(z.object({
|
|
20
|
+
result: z.string()
|
|
21
|
+
})));
|
|
22
|
+
const webSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
23
|
+
id: "volcengine.web_search",
|
|
24
|
+
inputSchema: webSearchInputSchema,
|
|
25
|
+
outputSchema: webSearchOutputSchema
|
|
21
26
|
});
|
|
22
27
|
/**
|
|
23
28
|
* Volcengine Web Search Tool
|
|
@@ -25,15 +30,23 @@ import { z } from "zod";
|
|
|
25
30
|
* Enables the model to perform web searches to retrieve up-to-date information.
|
|
26
31
|
*
|
|
27
32
|
* @see https://www.volcengine.com/docs/82379/1756990
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* volcengineTools.webSearch({
|
|
37
|
+
* maxKeyword: 5,
|
|
38
|
+
* limit: 20,
|
|
39
|
+
* sources: ["douyin", "toutiao"],
|
|
40
|
+
* userLocation: {
|
|
41
|
+
* type: "approximate",
|
|
42
|
+
* country: "中国",
|
|
43
|
+
* region: "浙江",
|
|
44
|
+
* city: "杭州",
|
|
45
|
+
* },
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/ export const webSearch = (args = {})=>{
|
|
49
|
+
return webSearchToolFactory(args);
|
|
50
|
+
};
|
|
38
51
|
|
|
39
52
|
//# sourceMappingURL=web-search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tool/web-search.ts"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"sources":["../../src/tool/web-search.ts"],"sourcesContent":["import {\n createProviderToolFactoryWithOutputSchema,\n lazySchema,\n zodSchema,\n} from \"@ai-sdk/provider-utils\";\nimport { z } from \"zod/v4\";\n\nconst userLocationSchema = z\n .object({\n type: z.enum([\"approximate\"]).optional(),\n country: z.string().optional(),\n region: z.string().optional(),\n city: z.string().optional(),\n })\n .strict();\n\nexport const webSearchArgsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n maxKeyword: z.number().int().min(1).max(50).optional(),\n limit: z.number().int().min(1).max(50).optional(),\n maxToolCalls: z.number().int().min(1).max(10).optional(),\n sources: z.array(z.string()).optional(),\n userLocation: userLocationSchema.optional(),\n })\n .strict()\n )\n);\n\nconst webSearchInputSchema = lazySchema(() => zodSchema(z.object({})));\n\nexport const webSearchOutputSchema = lazySchema(() =>\n zodSchema(z.object({ result: z.string() }))\n);\n\n/**\n * Web search input options.\n */\nexport interface WebSearchArgs {\n /**\n * Maximum number of keywords to extract from the query.\n */\n maxKeyword?: number;\n\n /**\n * Maximum number of search results to return.\n * @default 10\n */\n limit?: number;\n\n /**\n * Maximum number of tool calls.\n * @default 3\n */\n maxToolCalls?: number;\n\n /**\n * Sources to search from (e.g., \"douyin\", \"toutiao\").\n */\n sources?: string[];\n\n /**\n * User location for optimizing search results.\n */\n userLocation?: {\n /**\n * Location type.\n * @default \"approximate\"\n */\n type?: \"approximate\";\n /**\n * Country name (e.g., \"中国\").\n */\n country?: string;\n /**\n * Region/Province name (e.g., \"浙江\").\n */\n region?: string;\n /**\n * City name (e.g., \"杭州\").\n */\n city?: string;\n };\n}\n\nconst webSearchToolFactory = createProviderToolFactoryWithOutputSchema<\n {},\n {\n /**\n * The search result.\n */\n result: string;\n },\n WebSearchArgs\n>({\n id: \"volcengine.web_search\",\n inputSchema: webSearchInputSchema,\n outputSchema: webSearchOutputSchema,\n});\n\n/**\n * Volcengine Web Search Tool\n *\n * Enables the model to perform web searches to retrieve up-to-date information.\n *\n * @see https://www.volcengine.com/docs/82379/1756990\n *\n * @example\n * ```ts\n * volcengineTools.webSearch({\n * maxKeyword: 5,\n * limit: 20,\n * sources: [\"douyin\", \"toutiao\"],\n * userLocation: {\n * type: \"approximate\",\n * country: \"中国\",\n * region: \"浙江\",\n * city: \"杭州\",\n * },\n * })\n * ```\n */\nexport const webSearch = (args: WebSearchArgs = {}) => {\n return webSearchToolFactory(args);\n};\n"],"names":["createProviderToolFactoryWithOutputSchema","lazySchema","zodSchema","z","userLocationSchema","object","type","enum","optional","country","string","region","city","strict","webSearchArgsSchema","maxKeyword","number","int","min","max","limit","maxToolCalls","sources","array","userLocation","webSearchInputSchema","webSearchOutputSchema","result","webSearchToolFactory","id","inputSchema","outputSchema","webSearch","args"],"mappings":"AAAA,SACEA,yCAAyC,EACzCC,UAAU,EACVC,SAAS,QACJ,yBAAyB;AAChC,SAASC,CAAC,QAAQ,SAAS;AAE3B,MAAMC,qBAAqBD,EACxBE,MAAM,CAAC;IACNC,MAAMH,EAAEI,IAAI,CAAC;QAAC;KAAc,EAAEC,QAAQ;IACtCC,SAASN,EAAEO,MAAM,GAAGF,QAAQ;IAC5BG,QAAQR,EAAEO,MAAM,GAAGF,QAAQ;IAC3BI,MAAMT,EAAEO,MAAM,GAAGF,QAAQ;AAC3B,GACCK,MAAM;AAET,OAAO,MAAMC,sBAAsBb,WAAW,IAC5CC,UACEC,EACGE,MAAM,CAAC;QACNU,YAAYZ,EAAEa,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIX,QAAQ;QACpDY,OAAOjB,EAAEa,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIX,QAAQ;QAC/Ca,cAAclB,EAAEa,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIX,QAAQ;QACtDc,SAASnB,EAAEoB,KAAK,CAACpB,EAAEO,MAAM,IAAIF,QAAQ;QACrCgB,cAAcpB,mBAAmBI,QAAQ;IAC3C,GACCK,MAAM,KAEX;AAEF,MAAMY,uBAAuBxB,WAAW,IAAMC,UAAUC,EAAEE,MAAM,CAAC,CAAC;AAElE,OAAO,MAAMqB,wBAAwBzB,WAAW,IAC9CC,UAAUC,EAAEE,MAAM,CAAC;QAAEsB,QAAQxB,EAAEO,MAAM;IAAG,KACxC;AAoDF,MAAMkB,uBAAuB5B,0CAS3B;IACA6B,IAAI;IACJC,aAAaL;IACbM,cAAcL;AAChB;AAEA;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,MAAMM,YAAY,CAACC,OAAsB,CAAC,CAAC;IAChD,OAAOL,qBAAqBK;AAC9B,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/volcengine-chat-prompt.ts"],"sourcesContent":["// export type MistralPrompt = Array<MistralMessage>;\nexport type VolcengineChatPrompt = Array<VolcengineChatMessage>;\n\nexport type VolcengineChatMessage =\n | VolcengineChatSystemMessage\n | VolcengineChatUserMessage\n | VolcengineChatAssistantMessage\n | VolcengineChatToolMessage;\n\nexport interface VolcengineChatSystemMessage {\n role: 'system';\n content: string;\n}\n\nexport interface VolcengineChatUserMessage {\n role: 'user';\n content: Array<VolcengineChatUserMessageContent>;\n}\n\nexport type VolcengineChatUserMessageContent =\n | { type: 'text'; text: string }\n | { type: 'image_url'; image_url: { url: string
|
|
1
|
+
{"version":3,"sources":["../src/volcengine-chat-prompt.ts"],"sourcesContent":["// export type MistralPrompt = Array<MistralMessage>;\nexport type VolcengineChatPrompt = Array<VolcengineChatMessage>;\n\nexport type VolcengineChatMessage =\n | VolcengineChatSystemMessage\n | VolcengineChatUserMessage\n | VolcengineChatAssistantMessage\n | VolcengineChatToolMessage;\n\nexport interface VolcengineChatSystemMessage {\n role: 'system';\n content: string;\n}\n\nexport interface VolcengineChatUserMessage {\n role: 'user';\n content: Array<VolcengineChatUserMessageContent>;\n}\n\nexport type VolcengineChatUserMessageContent =\n | { type: 'text'; text: string }\n | { type: 'image_url'; image_url: { url: string } }\n | { type: 'video_url'; video_url: { url: string } }\n | { type: 'input_file'; file_url: string }\n\nexport interface VolcengineChatAssistantMessage {\n role: 'assistant';\n reasoning_content?: string;\n content: string;\n tool_calls?: Array<{\n id: string;\n type: 'function';\n function: { name: string; arguments: string };\n }>;\n}\n\nexport interface VolcengineChatToolMessage {\n role: 'tool';\n content: string;\n tool_call_id: string;\n}"],"names":[],"mappings":"AAAA,qDAAqD;AAoCrD,WAIC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
2
|
-
|
|
2
|
+
import { validateTypes } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { webSearchArgsSchema } from './tool/web-search';
|
|
4
|
+
import { imageGenerationArgsSchema } from './tool/image-generation';
|
|
5
|
+
export async function prepareTools({ tools, toolChoice }) {
|
|
3
6
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
4
7
|
tools = tools?.length ? tools : undefined;
|
|
5
8
|
const toolWarnings = [];
|
|
@@ -13,10 +16,48 @@ export function prepareTools({ tools, toolChoice }) {
|
|
|
13
16
|
const volcengineTools = [];
|
|
14
17
|
for (const tool of tools){
|
|
15
18
|
if (tool.type === 'provider') {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const toolId = tool.id;
|
|
20
|
+
switch(toolId){
|
|
21
|
+
case 'volcengine.web_search':
|
|
22
|
+
{
|
|
23
|
+
const args = await validateTypes({
|
|
24
|
+
value: tool.args,
|
|
25
|
+
schema: webSearchArgsSchema
|
|
26
|
+
});
|
|
27
|
+
volcengineTools.push({
|
|
28
|
+
type: 'web_search',
|
|
29
|
+
web_search: {
|
|
30
|
+
max_keyword: args.maxKeyword,
|
|
31
|
+
limit: args.limit,
|
|
32
|
+
max_tool_calls: args.maxToolCalls
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'volcengine.image_generation':
|
|
38
|
+
{
|
|
39
|
+
const args = await validateTypes({
|
|
40
|
+
value: tool.args,
|
|
41
|
+
schema: imageGenerationArgsSchema
|
|
42
|
+
});
|
|
43
|
+
volcengineTools.push({
|
|
44
|
+
type: 'image_generation',
|
|
45
|
+
image_generation: {
|
|
46
|
+
size: args.size,
|
|
47
|
+
watermark: false,
|
|
48
|
+
response_format: args.responseFormat,
|
|
49
|
+
image: args.image,
|
|
50
|
+
sequential_image_generation: 'disabled'
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
toolWarnings.push({
|
|
57
|
+
type: 'unsupported',
|
|
58
|
+
feature: `provider-defined tool ${toolId}`
|
|
59
|
+
});
|
|
60
|
+
}
|
|
20
61
|
} else {
|
|
21
62
|
volcengineTools.push({
|
|
22
63
|
type: 'function',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/volcengine-prepare-tools.ts"],"sourcesContent":["import {\n LanguageModelV3CallOptions,\n SharedV3Warning,\n UnsupportedFunctionalityError,\n} from '@ai-sdk/provider';\n\nexport type VolcengineToolChoice =\n | 'auto'\n | 'none'\n | 'required'\n | { type: 'function'; function: { name: string } };\n\nexport type VolcengineTool
|
|
1
|
+
{"version":3,"sources":["../src/volcengine-prepare-tools.ts"],"sourcesContent":["import {\n LanguageModelV3CallOptions,\n SharedV3Warning,\n UnsupportedFunctionalityError,\n} from '@ai-sdk/provider';\nimport { validateTypes } from '@ai-sdk/provider-utils';\nimport { webSearchArgsSchema } from './tool/web-search';\nimport { imageGenerationArgsSchema } from './tool/image-generation';\n\nexport type VolcengineToolChoice =\n | 'auto'\n | 'none'\n | 'required'\n | { type: 'function'; function: { name: string } };\n\nexport type VolcengineTool =\n | {\n type: 'function';\n function: {\n name: string;\n description: string | undefined;\n parameters: unknown;\n };\n }\n | {\n type: 'web_search';\n web_search?: {\n max_keyword?: number;\n limit?: number;\n max_tool_calls?: number;\n };\n }\n | {\n type: 'image_generation';\n image_generation?: {\n size?: '2K' | '4K';\n watermark: false;\n response_format?: 'url' | 'b64_json';\n image?: string | string[];\n sequential_image_generation: 'disabled';\n };\n };\n\nexport async function prepareTools({\n tools,\n toolChoice,\n}: {\n tools: LanguageModelV3CallOptions['tools'];\n toolChoice?: LanguageModelV3CallOptions['toolChoice'];\n}): Promise<{\n tools: VolcengineTool[] | undefined;\n toolChoice: VolcengineToolChoice | undefined;\n toolWarnings: SharedV3Warning[];\n}> {\n // when the tools array is empty, change it to undefined to prevent errors:\n tools = tools?.length ? tools : undefined;\n\n const toolWarnings: SharedV3Warning[] = [];\n\n if (tools == null) {\n return { tools: undefined, toolChoice: undefined, toolWarnings };\n }\n\n const volcengineTools: VolcengineTool[] = [];\n\n for (const tool of tools) {\n if (tool.type === 'provider') {\n const toolId = tool.id;\n\n switch (toolId) {\n case 'volcengine.web_search': {\n const args = await validateTypes({\n value: tool.args,\n schema: webSearchArgsSchema,\n });\n\n volcengineTools.push({\n type: 'web_search',\n web_search: {\n max_keyword: args.maxKeyword,\n limit: args.limit,\n max_tool_calls: args.maxToolCalls,\n },\n });\n break;\n }\n\n case 'volcengine.image_generation': {\n const args = await validateTypes({\n value: tool.args,\n schema: imageGenerationArgsSchema,\n });\n\n volcengineTools.push({\n type: 'image_generation',\n image_generation: {\n size: args.size,\n watermark: false,\n response_format: args.responseFormat,\n image: args.image,\n sequential_image_generation: 'disabled',\n },\n });\n break;\n }\n\n default:\n toolWarnings.push({\n type: 'unsupported',\n feature: `provider-defined tool ${toolId}`,\n });\n }\n } else {\n volcengineTools.push({\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n });\n }\n }\n\n if (toolChoice == null) {\n return { tools: volcengineTools, toolChoice: undefined, toolWarnings };\n }\n\n const type = toolChoice.type;\n\n switch (type) {\n case 'auto':\n case 'none':\n return { tools: volcengineTools, toolChoice: type, toolWarnings };\n case 'required':\n return { tools: volcengineTools, toolChoice: 'required', toolWarnings };\n case 'tool':\n return {\n tools: volcengineTools,\n toolChoice: {\n type: 'function',\n function: { name: toolChoice.toolName },\n },\n toolWarnings,\n };\n default: {\n const _exhaustiveCheck: never = type;\n throw new UnsupportedFunctionalityError({\n functionality: `tool choice type: ${_exhaustiveCheck}`,\n });\n }\n }\n}\n"],"names":["UnsupportedFunctionalityError","validateTypes","webSearchArgsSchema","imageGenerationArgsSchema","prepareTools","tools","toolChoice","length","undefined","toolWarnings","volcengineTools","tool","type","toolId","id","args","value","schema","push","web_search","max_keyword","maxKeyword","limit","max_tool_calls","maxToolCalls","image_generation","size","watermark","response_format","responseFormat","image","sequential_image_generation","feature","function","name","description","parameters","inputSchema","toolName","_exhaustiveCheck","functionality"],"mappings":"AAAA,SAGEA,6BAA6B,QACxB,mBAAmB;AAC1B,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,mBAAmB,QAAQ,oBAAoB;AACxD,SAASC,yBAAyB,QAAQ,0BAA0B;AAoCpE,OAAO,eAAeC,aAAa,EACjCC,KAAK,EACLC,UAAU,EAIX;IAKC,2EAA2E;IAC3ED,QAAQA,OAAOE,SAASF,QAAQG;IAEhC,MAAMC,eAAkC,EAAE;IAE1C,IAAIJ,SAAS,MAAM;QACjB,OAAO;YAAEA,OAAOG;YAAWF,YAAYE;YAAWC;QAAa;IACjE;IAEA,MAAMC,kBAAoC,EAAE;IAE5C,KAAK,MAAMC,QAAQN,MAAO;QACxB,IAAIM,KAAKC,IAAI,KAAK,YAAY;YAC5B,MAAMC,SAASF,KAAKG,EAAE;YAEtB,OAAQD;gBACN,KAAK;oBAAyB;wBAC5B,MAAME,OAAO,MAAMd,cAAc;4BAC/Be,OAAOL,KAAKI,IAAI;4BAChBE,QAAQf;wBACV;wBAEAQ,gBAAgBQ,IAAI,CAAC;4BACnBN,MAAM;4BACNO,YAAY;gCACVC,aAAaL,KAAKM,UAAU;gCAC5BC,OAAOP,KAAKO,KAAK;gCACjBC,gBAAgBR,KAAKS,YAAY;4BACnC;wBACF;wBACA;oBACF;gBAEA,KAAK;oBAA+B;wBAClC,MAAMT,OAAO,MAAMd,cAAc;4BAC/Be,OAAOL,KAAKI,IAAI;4BAChBE,QAAQd;wBACV;wBAEAO,gBAAgBQ,IAAI,CAAC;4BACnBN,MAAM;4BACNa,kBAAkB;gCAChBC,MAAMX,KAAKW,IAAI;gCACfC,WAAW;gCACXC,iBAAiBb,KAAKc,cAAc;gCACpCC,OAAOf,KAAKe,KAAK;gCACjBC,6BAA6B;4BAC/B;wBACF;wBACA;oBACF;gBAEA;oBACEtB,aAAaS,IAAI,CAAC;wBAChBN,MAAM;wBACNoB,SAAS,CAAC,sBAAsB,EAAEnB,QAAQ;oBAC5C;YACJ;QACF,OAAO;YACLH,gBAAgBQ,IAAI,CAAC;gBACnBN,MAAM;gBACNqB,UAAU;oBACRC,MAAMvB,KAAKuB,IAAI;oBACfC,aAAaxB,KAAKwB,WAAW;oBAC7BC,YAAYzB,KAAK0B,WAAW;gBAC9B;YACF;QACF;IACF;IAEA,IAAI/B,cAAc,MAAM;QACtB,OAAO;YAAED,OAAOK;YAAiBJ,YAAYE;YAAWC;QAAa;IACvE;IAEA,MAAMG,OAAON,WAAWM,IAAI;IAE5B,OAAQA;QACN,KAAK;QACL,KAAK;YACH,OAAO;gBAAEP,OAAOK;gBAAiBJ,YAAYM;gBAAMH;YAAa;QAClE,KAAK;YACH,OAAO;gBAAEJ,OAAOK;gBAAiBJ,YAAY;gBAAYG;YAAa;QACxE,KAAK;YACH,OAAO;gBACLJ,OAAOK;gBACPJ,YAAY;oBACVM,MAAM;oBACNqB,UAAU;wBAAEC,MAAM5B,WAAWgC,QAAQ;oBAAC;gBACxC;gBACA7B;YACF;QACF;YAAS;gBACP,MAAM8B,mBAA0B3B;gBAChC,MAAM,IAAIZ,8BAA8B;oBACtCwC,eAAe,CAAC,kBAAkB,EAAED,kBAAkB;gBACxD;YACF;IACF;AACF"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { LanguageModelV3, ProviderV3 } from "@ai-sdk/provider";
|
|
1
|
+
import { ImageModelV3, LanguageModelV3, ProviderV3 } from "@ai-sdk/provider";
|
|
2
2
|
import { FetchFunction } from "@ai-sdk/provider-utils";
|
|
3
|
-
import { VolcengineModelId } from "./
|
|
3
|
+
import { VolcengineModelId } from "./chat";
|
|
4
|
+
import { VolcengineImageModelId } from "./image";
|
|
5
|
+
import { volcengineTools } from "./volcengine-tools";
|
|
4
6
|
export interface VolcengineProviderSettings {
|
|
5
7
|
/**
|
|
6
8
|
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
@@ -34,9 +36,17 @@ export interface VolcengineProvider extends ProviderV3 {
|
|
|
34
36
|
*/
|
|
35
37
|
chat(modelId: VolcengineModelId): LanguageModelV3;
|
|
36
38
|
/**
|
|
39
|
+
Creates a model for image generation.
|
|
40
|
+
*/
|
|
41
|
+
imageModel(modelId: VolcengineImageModelId): ImageModelV3;
|
|
42
|
+
/**
|
|
37
43
|
Creates a model for text embeddings.
|
|
38
44
|
*/
|
|
39
45
|
embeddingModel(modelId: VolcengineModelId): never;
|
|
46
|
+
/**
|
|
47
|
+
Volcengine-specific tools.
|
|
48
|
+
*/
|
|
49
|
+
tools: typeof volcengineTools;
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
Create a Volcengine provider instance.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
2
2
|
import { loadApiKey, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { VERSION } from "./version";
|
|
4
|
-
import { VolcengineChatLanguageModel } from "./
|
|
4
|
+
import { VolcengineChatLanguageModel } from "./chat";
|
|
5
|
+
import { VolcengineImageModel } from "./image";
|
|
6
|
+
import { volcengineTools } from "./volcengine-tools";
|
|
5
7
|
/**
|
|
6
8
|
Create a Volcengine provider instance.
|
|
7
9
|
*/ export function createVolcengine(options = {}) {
|
|
@@ -15,34 +17,33 @@ Create a Volcengine provider instance.
|
|
|
15
17
|
...options.headers
|
|
16
18
|
}, `ai-sdk/volcengine/${VERSION}`);
|
|
17
19
|
const createChatModel = (modelId)=>new VolcengineChatLanguageModel(modelId, {
|
|
18
|
-
provider: "volcengine",
|
|
20
|
+
provider: "volcengine.chat",
|
|
19
21
|
baseURL,
|
|
20
22
|
headers: getHeaders,
|
|
21
23
|
fetch: options.fetch,
|
|
22
24
|
generateId: options.generateId
|
|
23
25
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const createImageModel = (modelId)=>new VolcengineImageModel(modelId, {
|
|
27
|
+
provider: "volcengine.image",
|
|
28
|
+
baseURL,
|
|
29
|
+
headers: getHeaders,
|
|
30
|
+
fetch: options.fetch
|
|
31
|
+
});
|
|
32
|
+
const provider = function(modelId) {
|
|
28
33
|
return createChatModel(modelId);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
modelType: "imageModel"
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
34
|
+
};
|
|
35
|
+
provider.specificationVersion = "v3";
|
|
36
|
+
provider.languageModel = createChatModel;
|
|
37
|
+
provider.chat = createChatModel;
|
|
38
|
+
provider.imageModel = createImageModel;
|
|
39
|
+
provider.embeddingModel = (modelId)=>{
|
|
40
|
+
throw new NoSuchModelError({
|
|
41
|
+
modelId,
|
|
42
|
+
modelType: "embeddingModel"
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
provider.tools = volcengineTools;
|
|
46
|
+
return provider;
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
Default Volcengine provider instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/volcengine-provider.ts"],"sourcesContent":["import {\n LanguageModelV3,\n NoSuchModelError,\n ProviderV3\n} from \"@ai-sdk/provider\";\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n withoutTrailingSlash\n} from \"@ai-sdk/provider-utils\";\nimport { VERSION } from \"./version\";\nimport { VolcengineChatLanguageModel } from \"./
|
|
1
|
+
{"version":3,"sources":["../src/volcengine-provider.ts"],"sourcesContent":["import {\n ImageModelV3,\n LanguageModelV3,\n NoSuchModelError,\n ProviderV3\n} from \"@ai-sdk/provider\";\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n withoutTrailingSlash\n} from \"@ai-sdk/provider-utils\";\nimport { VERSION } from \"./version\";\nimport { VolcengineChatLanguageModel, VolcengineModelId } from \"./chat\";\nimport { VolcengineImageModel, VolcengineImageModelId } from \"./image\";\nimport { volcengineTools } from \"./volcengine-tools\";\n\nexport interface VolcengineProviderSettings {\n /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://ark.cn-beijing.volces.com/api/v3`.\n */\n baseURL?: string;\n\n /**\nAPI key that is sent using the `Authorization` header.\nIt defaults to the `ARK_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n generateId?: () => string;\n}\n\nexport interface VolcengineProvider extends ProviderV3 {\n (modelId: VolcengineModelId): LanguageModelV3;\n\n /**\nCreates a model for text generation using the Chat Completions API.\n*/\n languageModel(modelId: VolcengineModelId): LanguageModelV3;\n\n /**\nCreates a model for text generation using the Chat Completions API.\n*/\n chat(modelId: VolcengineModelId): LanguageModelV3;\n\n /**\nCreates a model for image generation.\n*/\n imageModel(\n modelId: VolcengineImageModelId,\n\n ): ImageModelV3;\n\n /**\nCreates a model for text embeddings.\n*/\n embeddingModel(modelId: VolcengineModelId): never;\n\n /**\nVolcengine-specific tools.\n*/\n tools: typeof volcengineTools;\n}\n\n/**\nCreate a Volcengine provider instance.\n */\nexport function createVolcengine(\n options: VolcengineProviderSettings = {}\n): VolcengineProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n \"https://ark.cn-beijing.volces.com/api/v3\";\n\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: \"ARK_API_KEY\",\n description: \"Volcengine\"\n })}`,\n ...options.headers\n },\n `ai-sdk/volcengine/${VERSION}`\n );\n\n const createChatModel = (modelId: string) =>\n new VolcengineChatLanguageModel(modelId, {\n provider: \"volcengine.chat\",\n baseURL,\n headers: getHeaders,\n fetch: options.fetch,\n generateId: options.generateId\n });\n\n const createImageModel = (\n modelId: string,\n ) =>\n new VolcengineImageModel(modelId, {\n provider: \"volcengine.image\",\n baseURL,\n headers: getHeaders,\n fetch: options.fetch\n });\n\n const provider = function (modelId: VolcengineModelId) {\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = \"v3\" as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.imageModel = createImageModel;\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n };\n provider.tools = volcengineTools;\n\n return provider as VolcengineProvider;\n}\n\n/**\nDefault Volcengine provider instance.\n */\nexport const volcengine = createVolcengine();\n"],"names":["NoSuchModelError","loadApiKey","withUserAgentSuffix","withoutTrailingSlash","VERSION","VolcengineChatLanguageModel","VolcengineImageModel","volcengineTools","createVolcengine","options","baseURL","getHeaders","Authorization","apiKey","environmentVariableName","description","headers","createChatModel","modelId","provider","fetch","generateId","createImageModel","specificationVersion","languageModel","chat","imageModel","embeddingModel","modelType","tools","volcengine"],"mappings":"AAAA,SAGEA,gBAAgB,QAEX,mBAAmB;AAC1B,SAEEC,UAAU,EACVC,mBAAmB,EACnBC,oBAAoB,QACf,yBAAyB;AAChC,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,2BAA2B,QAA2B,SAAS;AACxE,SAASC,oBAAoB,QAAgC,UAAU;AACvE,SAASC,eAAe,QAAQ,qBAAqB;AA6DrD;;CAEC,GACD,OAAO,SAASC,iBACdC,UAAsC,CAAC,CAAC;IAExC,MAAMC,UACJP,qBAAqBM,QAAQC,OAAO,KACpC;IAEF,MAAMC,aAAa,IACjBT,oBACE;YACEU,eAAe,CAAC,OAAO,EAAEX,WAAW;gBAClCY,QAAQJ,QAAQI,MAAM;gBACtBC,yBAAyB;gBACzBC,aAAa;YACf,IAAI;YACJ,GAAGN,QAAQO,OAAO;QACpB,GACA,CAAC,kBAAkB,EAAEZ,SAAS;IAGlC,MAAMa,kBAAkB,CAACC,UACvB,IAAIb,4BAA4Ba,SAAS;YACvCC,UAAU;YACVT;YACAM,SAASL;YACTS,OAAOX,QAAQW,KAAK;YACpBC,YAAYZ,QAAQY,UAAU;QAChC;IAEF,MAAMC,mBAAmB,CACvBJ,UAEA,IAAIZ,qBAAqBY,SAAS;YAChCC,UAAU;YACVT;YACAM,SAASL;YACTS,OAAOX,QAAQW,KAAK;QACtB;IAEF,MAAMD,WAAW,SAAUD,OAA0B;QACnD,OAAOD,gBAAgBC;IACzB;IAEAC,SAASI,oBAAoB,GAAG;IAChCJ,SAASK,aAAa,GAAGP;IACzBE,SAASM,IAAI,GAAGR;IAChBE,SAASO,UAAU,GAAGJ;IACtBH,SAASQ,cAAc,GAAG,CAACT;QACzB,MAAM,IAAIlB,iBAAiB;YAAEkB;YAASU,WAAW;QAAiB;IACpE;IACAT,SAASU,KAAK,GAAGtB;IAEjB,OAAOY;AACT;AAEA;;CAEC,GACD,OAAO,MAAMW,aAAatB,mBAAmB"}
|
|
@@ -38,5 +38,7 @@ export declare const volcengineTools: {
|
|
|
38
38
|
* })
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
webSearch:
|
|
41
|
+
webSearch: (args?: import("./tool/web-search").WebSearchArgs) => import("@ai-sdk/provider-utils").Tool<{}, {
|
|
42
|
+
result: string;
|
|
43
|
+
}>;
|
|
42
44
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sweetretry/ai-sdk-volcengine-adapter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Volcengine adapter for AI SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SweetRetry <zimin.zhang2000@gmail.com>",
|
|
7
|
+
"homepage": "https://github.com/SweetRetry/ai-sdk-volcengine-adapter#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/SweetRetry/ai-sdk-volcengine-adapter.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/SweetRetry/ai-sdk-volcengine-adapter/issues"
|
|
14
|
+
},
|
|
7
15
|
"keywords": [
|
|
8
16
|
"ai",
|
|
9
17
|
"ai-sdk",
|
|
@@ -23,7 +31,8 @@
|
|
|
23
31
|
}
|
|
24
32
|
},
|
|
25
33
|
"files": [
|
|
26
|
-
"dist"
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md"
|
|
27
36
|
],
|
|
28
37
|
"sideEffects": false,
|
|
29
38
|
"scripts": {
|
|
@@ -48,7 +57,7 @@
|
|
|
48
57
|
},
|
|
49
58
|
"dependencies": {
|
|
50
59
|
"@ai-sdk/provider": "^3.0.2",
|
|
51
|
-
"@ai-sdk/provider-utils": "^4.0.
|
|
60
|
+
"@ai-sdk/provider-utils": "^4.0.5",
|
|
52
61
|
"zod": "^4.3.5"
|
|
53
62
|
}
|
|
54
63
|
}
|