@agentor/dashscope 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Demo Macro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,264 @@
1
+ # @agentor/dashscope
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@agentor/dashscope)
4
+ ![npm downloads](https://img.shields.io/npm/dw/@agentor/dashscope)
5
+ ![npm license](https://img.shields.io/npm/l/@agentor/dashscope)
6
+
7
+ > [AI SDK](https://ai-sdk.dev/) provider for [Alibaba Cloud DashScope (Bailian)](https://help.aliyun.com/en/model-studio/) API.
8
+
9
+ ## Features
10
+
11
+ - **Chat Completions API** - Standard `/chat/completions` with function calling, streaming, and reasoning
12
+ - **Responses API** - `/responses` endpoint with built-in tools support
13
+ - **Built-in Tools** - Web search, code interpreter, web extractor, file search, image search, MCP integration
14
+ - **Thinking Mode** - Enable reasoning/thinking with configurable budget
15
+ - **Multi-region** - Beijing, Singapore, US, Germany regions
16
+ - **TypeScript-First** - Full type safety with comprehensive TypeScript support
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # Install with npm
22
+ $ npm install @agentor/dashscope
23
+
24
+ # Install with yarn
25
+ $ yarn add @agentor/dashscope
26
+
27
+ # Install with pnpm
28
+ $ pnpm add @agentor/dashscope
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ### Setup
34
+
35
+ ```typescript
36
+ import { createDashScope } from "@agentor/dashscope";
37
+
38
+ const dashscope = createDashScope({
39
+ apiKey: process.env.DASHSCOPE_API_KEY,
40
+ });
41
+ ```
42
+
43
+ Or use the default instance (reads `DASHSCOPE_API_KEY` from environment):
44
+
45
+ ```typescript
46
+ import { dashscope } from "@agentor/dashscope";
47
+ ```
48
+
49
+ ### Basic Chat
50
+
51
+ ```typescript
52
+ import { dashscope } from "@agentor/dashscope";
53
+ import { generateText } from "ai";
54
+
55
+ const result = await generateText({
56
+ model: dashscope("qwen3.5-flash"),
57
+ prompt: "Introduce yourself in one sentence.",
58
+ });
59
+
60
+ console.log(result.text);
61
+ ```
62
+
63
+ ### Streaming
64
+
65
+ ```typescript
66
+ import { streamText } from "ai";
67
+
68
+ const result = streamText({
69
+ model: dashscope("qwen3.5-flash"),
70
+ prompt: "Explain the Vercel AI SDK in three sentences.",
71
+ });
72
+
73
+ for await (const part of result.textStream) {
74
+ process.stdout.write(part);
75
+ }
76
+ ```
77
+
78
+ ### Function Calling
79
+
80
+ ```typescript
81
+ import { generateText, hasToolCall, tool } from "ai";
82
+ import { z } from "zod/v4";
83
+
84
+ const result = await generateText({
85
+ model: dashscope("qwen3.5-flash"),
86
+ tools: {
87
+ weather: tool({
88
+ description: "Get weather information for a city",
89
+ inputSchema: z.object({
90
+ city: z.string().describe("City name"),
91
+ }),
92
+ execute: async ({ city }) => {
93
+ return `${city}: Sunny, 25°C`;
94
+ },
95
+ }),
96
+ },
97
+ prompt: "What's the weather in Beijing?",
98
+ stopWhen: hasToolCall("weather"),
99
+ });
100
+ ```
101
+
102
+ ## Chat Completions API
103
+
104
+ ### Web Search
105
+
106
+ Enable web search via `providerOptions`:
107
+
108
+ ```typescript
109
+ await generateText({
110
+ model: dashscope("qwen3.5-flash"),
111
+ providerOptions: {
112
+ dashscope: {
113
+ enableSearch: true,
114
+ },
115
+ },
116
+ prompt: "What are the latest tech news today?",
117
+ });
118
+ ```
119
+
120
+ ### Code Interpreter
121
+
122
+ Enable code interpreter (requires thinking mode):
123
+
124
+ ```typescript
125
+ await generateText({
126
+ model: dashscope("qwen3.5-flash"),
127
+ providerOptions: {
128
+ dashscope: {
129
+ enableCodeInterpreter: true,
130
+ enableThinking: true,
131
+ },
132
+ },
133
+ prompt: "Calculate the sum of the first 20 Fibonacci numbers.",
134
+ });
135
+ ```
136
+
137
+ ### Thinking Mode
138
+
139
+ Enable reasoning with configurable budget:
140
+
141
+ ```typescript
142
+ await generateText({
143
+ model: dashscope("qwen3.5-flash"),
144
+ providerOptions: {
145
+ dashscope: {
146
+ enableThinking: true,
147
+ thinkingBudget: 5000,
148
+ },
149
+ },
150
+ prompt: "Which is larger, 9.11 or 9.9?",
151
+ });
152
+ ```
153
+
154
+ ## Responses API
155
+
156
+ Use the `responses` namespace for the Responses API with built-in tools:
157
+
158
+ ```typescript
159
+ import { generateText } from "ai";
160
+
161
+ const result = await generateText({
162
+ model: dashscope.responses("qwen3.5-flash"),
163
+ prompt: "Search the web for the latest news.",
164
+ });
165
+ ```
166
+
167
+ ### Built-in Tools
168
+
169
+ #### Web Search
170
+
171
+ ```typescript
172
+ import { dashscope } from "@agentor/dashscope";
173
+ import { generateText } from "ai";
174
+
175
+ const result = await generateText({
176
+ model: dashscope.responses("qwen3.5-flash"),
177
+ tools: [dashscope.responses.tools.webSearch()],
178
+ prompt: "What are the latest tech news today?",
179
+ });
180
+ ```
181
+
182
+ #### Code Interpreter
183
+
184
+ ```typescript
185
+ const result = await generateText({
186
+ model: dashscope.responses("qwen3.5-flash"),
187
+ tools: [dashscope.responses.tools.codeInterpreter()],
188
+ prompt: "Calculate the sum of the first 20 Fibonacci numbers.",
189
+ });
190
+ ```
191
+
192
+ #### Web Extractor
193
+
194
+ ```typescript
195
+ const result = await generateText({
196
+ model: dashscope.responses("qwen3.5-flash"),
197
+ tools: [dashscope.responses.tools.webExtractor()],
198
+ prompt: "Extract the main content from https://example.com",
199
+ });
200
+ ```
201
+
202
+ #### File Search
203
+
204
+ ```typescript
205
+ const result = await generateText({
206
+ model: dashscope.responses("qwen3.5-flash"),
207
+ tools: [
208
+ dashscope.responses.tools.fileSearch({
209
+ vectorStoreIds: ["vs-xxx"],
210
+ }),
211
+ ],
212
+ prompt: "Find documents about machine learning.",
213
+ });
214
+ ```
215
+
216
+ #### MCP Integration
217
+
218
+ ```typescript
219
+ const result = await generateText({
220
+ model: dashscope.responses("qwen3.5-flash"),
221
+ tools: [
222
+ dashscope.responses.tools.mcp({
223
+ serverProtocol: "sse",
224
+ serverLabel: "my-mcp-server",
225
+ serverUrl: "https://example.com/mcp/sse",
226
+ }),
227
+ ],
228
+ prompt: "Use the MCP tool to get data.",
229
+ });
230
+ ```
231
+
232
+ ### Multi-turn Conversation
233
+
234
+ Use `previousResponseId` for multi-turn conversations:
235
+
236
+ ```typescript
237
+ const first = await generateText({
238
+ model: dashscope.responses("qwen3.5-flash"),
239
+ providerOptions: {
240
+ dashscope: {
241
+ previousResponseId: first.response.id,
242
+ },
243
+ },
244
+ prompt: "Follow up question...",
245
+ });
246
+ ```
247
+
248
+ ## Provider Configuration
249
+
250
+ ```typescript
251
+ import { createDashScope } from "@agentor/dashscope";
252
+
253
+ const dashscope = createDashScope({
254
+ apiKey: "sk-xxx", // or set DASHSCOPE_API_KEY env var
255
+ region: "beijing", // beijing | singapore | us | germany
256
+ workspaceId: "ws-xxx", // required for germany region
257
+ baseURL: "https://custom-endpoint.com", // override default base URL
258
+ headers: { "X-Custom-Header": "value" }, // custom headers
259
+ });
260
+ ```
261
+
262
+ ## License
263
+
264
+ MIT © [Demo Macro](https://www.demomacro.com/)
@@ -0,0 +1,210 @@
1
+ import * as _$_ai_sdk_provider_utils0 from "@ai-sdk/provider-utils";
2
+ import { FetchFunction } from "@ai-sdk/provider-utils";
3
+ import { LanguageModelV3 } from "@ai-sdk/provider";
4
+
5
+ //#region src/tools.d.ts
6
+ declare const webSearchToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
7
+ query?: string;
8
+ sources?: Array<{
9
+ type: "url";
10
+ url: string;
11
+ }>;
12
+ }, {
13
+ /** Force web search even when the model doesn't think it's necessary. */forcedSearch?: boolean;
14
+ /**
15
+ * Search strategy. Only applicable to qwen3-max thinking mode.
16
+ * - "enable": enable search
17
+ * - "enable_with_history": enable search with history context
18
+ */
19
+ searchStrategy?: "enable" | "enable_with_history";
20
+ }>;
21
+ declare const codeInterpreterToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
22
+ code?: string;
23
+ outputs?: Array<{
24
+ type: "logs";
25
+ logs?: string;
26
+ }>;
27
+ }, Record<string, never>>;
28
+ declare const webExtractorToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
29
+ urls?: string[];
30
+ goal?: string;
31
+ output?: string;
32
+ }, Record<string, never>>;
33
+ declare const fileSearchToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
34
+ queries?: string[];
35
+ results?: Array<{
36
+ fileId?: string;
37
+ filename?: string;
38
+ score?: number;
39
+ text?: string;
40
+ }>;
41
+ }, {
42
+ /** Vector store IDs (knowledge base IDs) to search. Currently only 1 is supported. */vectorStoreIds: string[];
43
+ }>;
44
+ declare const webSearchImageToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
45
+ queries?: string[];
46
+ }, Record<string, never>>;
47
+ declare const imageSearchToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, Record<string, never>, Record<string, never>>;
48
+ declare const mcpToolFactory: _$_ai_sdk_provider_utils0.ProviderToolFactoryWithOutputSchema<Record<string, never>, Record<string, never>, {
49
+ /** Communication protocol with the MCP service, e.g. "sse". */serverProtocol: string; /** Label to identify the MCP server. */
50
+ serverLabel: string; /** URL for the MCP server endpoint. */
51
+ serverUrl: string; /** Description of the MCP server. */
52
+ serverDescription?: string; /** Headers for authentication, e.g. Authorization. */
53
+ headers?: Record<string, string>;
54
+ }>;
55
+ /**
56
+ * Built-in tools for the Responses API.
57
+ * Access via `dashscope.responses.tools`.
58
+ */
59
+ declare const responsesTools: {
60
+ /**
61
+ * Web search tool. Allows the model to search the internet for up-to-date information.
62
+ *
63
+ * @see https://help.aliyun.com/zh/model-studio/web-search
64
+ */
65
+ webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, {
66
+ query?: string;
67
+ sources?: Array<{
68
+ type: "url";
69
+ url: string;
70
+ }>;
71
+ }>;
72
+ /**
73
+ * Code interpreter tool. Allows the model to write and execute code.
74
+ *
75
+ * @see https://help.aliyun.com/zh/model-studio/qwen-code-interpreter
76
+ */
77
+ codeInterpreter: (args?: Parameters<typeof codeInterpreterToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, {
78
+ code?: string;
79
+ outputs?: Array<{
80
+ type: "logs";
81
+ logs?: string;
82
+ }>;
83
+ }>;
84
+ /**
85
+ * Web extractor tool. Allows the model to access and extract content from web pages.
86
+ * Must be used together with webSearch.
87
+ *
88
+ * @see https://help.aliyun.com/zh/model-studio/web-extractor
89
+ */
90
+ webExtractor: (args?: Parameters<typeof webExtractorToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, {
91
+ urls?: string[];
92
+ goal?: string;
93
+ output?: string;
94
+ }>;
95
+ /**
96
+ * File search tool. Search within uploaded or associated knowledge bases.
97
+ *
98
+ * @see https://help.aliyun.com/zh/model-studio/file-search
99
+ */
100
+ fileSearch: (args: Parameters<typeof fileSearchToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, {
101
+ queries?: string[];
102
+ results?: Array<{
103
+ fileId?: string;
104
+ filename?: string;
105
+ score?: number;
106
+ text?: string;
107
+ }>;
108
+ }>;
109
+ /**
110
+ * Text-to-image search. Search images based on text description.
111
+ *
112
+ * @see https://help.aliyun.com/zh/model-studio/web-search-image
113
+ */
114
+ webSearchImage: (args?: Parameters<typeof webSearchImageToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, {
115
+ queries?: string[];
116
+ }>;
117
+ /**
118
+ * Image-to-image search. Search similar images based on an input image.
119
+ *
120
+ * @see https://help.aliyun.com/zh/model-studio/image-search
121
+ */
122
+ imageSearch: (args?: Parameters<typeof imageSearchToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, Record<string, never>>;
123
+ /**
124
+ * MCP (Model Context Protocol) tool. Allows calling external services via MCP.
125
+ *
126
+ * @see https://help.aliyun.com/zh/model-studio/mcp
127
+ */
128
+ mcp: (args: Parameters<typeof mcpToolFactory>[0]) => _$_ai_sdk_provider_utils0.Tool<Record<string, never>, Record<string, never>>;
129
+ };
130
+ type DashScopeResponsesTools = typeof responsesTools;
131
+ //#endregion
132
+ //#region src/types.d.ts
133
+ type DashScopeRegion = "beijing" | "singapore" | "us" | "germany";
134
+ declare const DASHSCOPE_REGION_BASE_URLS: Record<DashScopeRegion, {
135
+ baseURL: string;
136
+ videoBaseURL: string;
137
+ }>;
138
+ interface DashScopeProviderSettings {
139
+ apiKey?: string;
140
+ region?: DashScopeRegion;
141
+ workspaceId?: string;
142
+ baseURL?: string;
143
+ videoBaseURL?: string;
144
+ headers?: Record<string, string>;
145
+ fetch?: FetchFunction;
146
+ includeUsage?: boolean;
147
+ }
148
+ interface DashScopeChatOptions {
149
+ /** Enable thinking/reasoning mode. */
150
+ enableThinking?: boolean;
151
+ /** Maximum reasoning tokens. */
152
+ thinkingBudget?: number;
153
+ /** Enable parallel tool calls. */
154
+ parallelToolCalls?: boolean;
155
+ /** Enable web search. */
156
+ enableSearch?: boolean;
157
+ /**
158
+ * Search strategy.
159
+ * - "enable": enable search
160
+ * - "enable_with_history": enable search with history context
161
+ * - "agent_max": enable web extraction (requires enableSearch + enableThinking)
162
+ */
163
+ searchStrategy?: "enable" | "enable_with_history" | "agent_max";
164
+ /** Enable code interpreter (requires enableThinking). */
165
+ enableCodeInterpreter?: boolean;
166
+ }
167
+ interface DashScopeChatConfig {
168
+ provider: string;
169
+ baseURL: string;
170
+ headers: () => Record<string, string>;
171
+ fetch?: FetchFunction;
172
+ includeUsage?: boolean;
173
+ }
174
+ interface DashScopeResponsesOptions {
175
+ enableThinking?: boolean;
176
+ reasoning?: {
177
+ effort: "none" | "minimal" | "low" | "medium" | "high";
178
+ };
179
+ previousResponseId?: string;
180
+ conversation?: string;
181
+ instructions?: string;
182
+ includeUsage?: boolean;
183
+ }
184
+ interface DashScopeResponsesNamespace {
185
+ (modelId: string): LanguageModelV3;
186
+ tools: DashScopeResponsesTools;
187
+ }
188
+ interface DashScopeProvider {
189
+ (modelId: string): LanguageModelV3;
190
+ languageModel(modelId: string): LanguageModelV3;
191
+ chatOptions: (options: DashScopeChatOptions) => {
192
+ providerOptions: {
193
+ dashscope: DashScopeChatOptions;
194
+ };
195
+ };
196
+ responsesOptions: (options: DashScopeResponsesOptions) => {
197
+ providerOptions: {
198
+ dashscope: DashScopeResponsesOptions;
199
+ };
200
+ };
201
+ responses: DashScopeResponsesNamespace;
202
+ }
203
+ //#endregion
204
+ //#region src/provider.d.ts
205
+ declare function createDashScope(options?: DashScopeProviderSettings): DashScopeProvider;
206
+ //#endregion
207
+ //#region src/index.d.ts
208
+ declare const dashscope: DashScopeProvider;
209
+ //#endregion
210
+ export { DASHSCOPE_REGION_BASE_URLS, DashScopeChatConfig, DashScopeChatOptions, DashScopeProvider, DashScopeProviderSettings, DashScopeRegion, DashScopeResponsesNamespace, DashScopeResponsesOptions, DashScopeResponsesTools, createDashScope, dashscope, responsesTools };