@qwen-code/sdk 0.1.0-preview.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/README.md ADDED
@@ -0,0 +1,377 @@
1
+ # @qwen-code/sdk
2
+
3
+ A minimum experimental TypeScript SDK for programmatic access to Qwen Code.
4
+
5
+ Feel free to submit a feature request/issue/PR.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @qwen-code/sdk
11
+ ```
12
+
13
+ ## Requirements
14
+
15
+ - Node.js >= 20.0.0
16
+ - [Qwen Code](https://github.com/QwenLM/qwen-code) >= 0.4.0 (stable) installed and accessible in PATH
17
+
18
+ > **Note for nvm users**: If you use nvm to manage Node.js versions, the SDK may not be able to auto-detect the Qwen Code executable. You should explicitly set the `pathToQwenExecutable` option to the full path of the `qwen` binary.
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ import { query } from '@qwen-code/sdk';
24
+
25
+ // Single-turn query
26
+ const result = query({
27
+ prompt: 'What files are in the current directory?',
28
+ options: {
29
+ cwd: '/path/to/project',
30
+ },
31
+ });
32
+
33
+ // Iterate over messages
34
+ for await (const message of result) {
35
+ if (message.type === 'assistant') {
36
+ console.log('Assistant:', message.message.content);
37
+ } else if (message.type === 'result') {
38
+ console.log('Result:', message.result);
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## API Reference
44
+
45
+ ### `query(config)`
46
+
47
+ Creates a new query session with the Qwen Code.
48
+
49
+ #### Parameters
50
+
51
+ - `prompt`: `string | AsyncIterable<SDKUserMessage>` - The prompt to send. Use a string for single-turn queries or an async iterable for multi-turn conversations.
52
+ - `options`: `QueryOptions` - Configuration options for the query session.
53
+
54
+ #### QueryOptions
55
+
56
+ | Option | Type | Default | Description |
57
+ | ------------------------ | ---------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
58
+ | `cwd` | `string` | `process.cwd()` | The working directory for the query session. Determines the context in which file operations and commands are executed. |
59
+ | `model` | `string` | - | The AI model to use (e.g., `'qwen-max'`, `'qwen-plus'`, `'qwen-turbo'`). Takes precedence over `OPENAI_MODEL` and `QWEN_MODEL` environment variables. |
60
+ | `pathToQwenExecutable` | `string` | Auto-detected | Path to the Qwen Code executable. Supports multiple formats: `'qwen'` (native binary from PATH), `'/path/to/qwen'` (explicit path), `'/path/to/cli.js'` (Node.js bundle), `'node:/path/to/cli.js'` (force Node.js runtime), `'bun:/path/to/cli.js'` (force Bun runtime). If not provided, auto-detects from: `QWEN_CODE_CLI_PATH` env var, `~/.volta/bin/qwen`, `~/.npm-global/bin/qwen`, `/usr/local/bin/qwen`, `~/.local/bin/qwen`, `~/node_modules/.bin/qwen`, `~/.yarn/bin/qwen`. |
61
+ | `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
62
+ | `canUseTool` | `CanUseTool` | - | Custom permission handler for tool execution approval. Invoked when a tool requires confirmation. Must respond within 30 seconds or the request will be auto-denied. See [Custom Permission Handler](#custom-permission-handler). |
63
+ | `env` | `Record<string, string>` | - | Environment variables to pass to the Qwen Code process. Merged with the current process environment. |
64
+ | `mcpServers` | `Record<string, McpServerConfig>` | - | MCP (Model Context Protocol) servers to connect. Supports external servers (stdio/SSE/HTTP) and SDK-embedded servers. External servers are configured with transport options like `command`, `args`, `url`, `httpUrl`, etc. SDK servers use `{ type: 'sdk', name: string, instance: Server }`. |
65
+ | `abortController` | `AbortController` | - | Controller to cancel the query session. Call `abortController.abort()` to terminate the session and cleanup resources. |
66
+ | `debug` | `boolean` | `false` | Enable debug mode for verbose logging from the CLI process. |
67
+ | `maxSessionTurns` | `number` | `-1` (unlimited) | Maximum number of conversation turns before the session automatically terminates. A turn consists of a user message and an assistant response. |
68
+ | `coreTools` | `string[]` | - | Equivalent to `tool.core` in settings.json. If specified, only these tools will be available to the AI. Example: `['read_file', 'write_file', 'run_terminal_cmd']`. |
69
+ | `excludeTools` | `string[]` | - | Equivalent to `tool.exclude` in settings.json. Excluded tools return a permission error immediately. Takes highest priority over all other permission settings. Supports pattern matching: tool name (`'write_file'`), tool class (`'ShellTool'`), or shell command prefix (`'ShellTool(rm )'`). |
70
+ | `allowedTools` | `string[]` | - | Equivalent to `tool.allowed` in settings.json. Matching tools bypass `canUseTool` callback and execute automatically. Only applies when tool requires confirmation. Supports same pattern matching as `excludeTools`. |
71
+ | `authType` | `'openai' \| 'qwen-oauth'` | `'openai'` | Authentication type for the AI service. Using `'qwen-oauth'` in SDK is not recommended as credentials are stored in `~/.qwen` and may need periodic refresh. |
72
+ | `agents` | `SubagentConfig[]` | - | Configuration for subagents that can be invoked during the session. Subagents are specialized AI agents for specific tasks or domains. |
73
+ | `includePartialMessages` | `boolean` | `false` | When `true`, the SDK emits incomplete messages as they are being generated, allowing real-time streaming of the AI's response. |
74
+
75
+ ### Timeouts
76
+
77
+ The SDK enforces the following default timeouts:
78
+
79
+ | Timeout | Default | Description |
80
+ | ---------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
81
+ | `canUseTool` | 30 seconds | Maximum time for `canUseTool` callback to respond. If exceeded, the tool request is auto-denied. |
82
+ | `mcpRequest` | 1 minute | Maximum time for SDK MCP tool calls to complete. |
83
+ | `controlRequest` | 30 seconds | Maximum time for control operations like `initialize()`, `setModel()`, `setPermissionMode()`, and `interrupt()` to complete. |
84
+ | `streamClose` | 1 minute | Maximum time to wait for initialization to complete before closing CLI stdin in multi-turn mode with SDK MCP servers. |
85
+
86
+ You can customize these timeouts via the `timeout` option:
87
+
88
+ ```typescript
89
+ const query = qwen.query('Your prompt', {
90
+ timeout: {
91
+ canUseTool: 60000, // 60 seconds for permission callback
92
+ mcpRequest: 600000, // 10 minutes for MCP tool calls
93
+ controlRequest: 60000, // 60 seconds for control requests
94
+ streamClose: 15000, // 15 seconds for stream close wait
95
+ },
96
+ });
97
+ ```
98
+
99
+ ### Message Types
100
+
101
+ The SDK provides type guards to identify different message types:
102
+
103
+ ```typescript
104
+ import {
105
+ isSDKUserMessage,
106
+ isSDKAssistantMessage,
107
+ isSDKSystemMessage,
108
+ isSDKResultMessage,
109
+ isSDKPartialAssistantMessage,
110
+ } from '@qwen-code/sdk';
111
+
112
+ for await (const message of result) {
113
+ if (isSDKAssistantMessage(message)) {
114
+ // Handle assistant message
115
+ } else if (isSDKResultMessage(message)) {
116
+ // Handle result message
117
+ }
118
+ }
119
+ ```
120
+
121
+ ### Query Instance Methods
122
+
123
+ The `Query` instance returned by `query()` provides several methods:
124
+
125
+ ```typescript
126
+ const q = query({ prompt: 'Hello', options: {} });
127
+
128
+ // Get session ID
129
+ const sessionId = q.getSessionId();
130
+
131
+ // Check if closed
132
+ const closed = q.isClosed();
133
+
134
+ // Interrupt the current operation
135
+ await q.interrupt();
136
+
137
+ // Change permission mode mid-session
138
+ await q.setPermissionMode('yolo');
139
+
140
+ // Change model mid-session
141
+ await q.setModel('qwen-max');
142
+
143
+ // Close the session
144
+ await q.close();
145
+ ```
146
+
147
+ ## Permission Modes
148
+
149
+ The SDK supports different permission modes for controlling tool execution:
150
+
151
+ - **`default`**: Write tools are denied unless approved via `canUseTool` callback or in `allowedTools`. Read-only tools execute without confirmation.
152
+ - **`plan`**: Blocks all write tools, instructing AI to present a plan first.
153
+ - **`auto-edit`**: Auto-approve edit tools (edit, write_file) while other tools require confirmation.
154
+ - **`yolo`**: All tools execute automatically without confirmation.
155
+
156
+ ### Permission Priority Chain
157
+
158
+ 1. `excludeTools` - Blocks tools completely
159
+ 2. `permissionMode: 'plan'` - Blocks non-read-only tools
160
+ 3. `permissionMode: 'yolo'` - Auto-approves all tools
161
+ 4. `allowedTools` - Auto-approves matching tools
162
+ 5. `canUseTool` callback - Custom approval logic
163
+ 6. Default behavior - Auto-deny in SDK mode
164
+
165
+ ## Examples
166
+
167
+ ### Multi-turn Conversation
168
+
169
+ ```typescript
170
+ import { query, type SDKUserMessage } from '@qwen-code/sdk';
171
+
172
+ async function* generateMessages(): AsyncIterable<SDKUserMessage> {
173
+ yield {
174
+ type: 'user',
175
+ session_id: 'my-session',
176
+ message: { role: 'user', content: 'Create a hello.txt file' },
177
+ parent_tool_use_id: null,
178
+ };
179
+
180
+ // Wait for some condition or user input
181
+ yield {
182
+ type: 'user',
183
+ session_id: 'my-session',
184
+ message: { role: 'user', content: 'Now read the file back' },
185
+ parent_tool_use_id: null,
186
+ };
187
+ }
188
+
189
+ const result = query({
190
+ prompt: generateMessages(),
191
+ options: {
192
+ permissionMode: 'auto-edit',
193
+ },
194
+ });
195
+
196
+ for await (const message of result) {
197
+ console.log(message);
198
+ }
199
+ ```
200
+
201
+ ### Custom Permission Handler
202
+
203
+ ```typescript
204
+ import { query, type CanUseTool } from '@qwen-code/sdk';
205
+
206
+ const canUseTool: CanUseTool = async (toolName, input, { signal }) => {
207
+ // Allow all read operations
208
+ if (toolName.startsWith('read_')) {
209
+ return { behavior: 'allow', updatedInput: input };
210
+ }
211
+
212
+ // Prompt user for write operations (in a real app)
213
+ const userApproved = await promptUser(`Allow ${toolName}?`);
214
+
215
+ if (userApproved) {
216
+ return { behavior: 'allow', updatedInput: input };
217
+ }
218
+
219
+ return { behavior: 'deny', message: 'User denied the operation' };
220
+ };
221
+
222
+ const result = query({
223
+ prompt: 'Create a new file',
224
+ options: {
225
+ canUseTool,
226
+ },
227
+ });
228
+ ```
229
+
230
+ ### With External MCP Servers
231
+
232
+ ```typescript
233
+ import { query } from '@qwen-code/sdk';
234
+
235
+ const result = query({
236
+ prompt: 'Use the custom tool from my MCP server',
237
+ options: {
238
+ mcpServers: {
239
+ 'my-server': {
240
+ command: 'node',
241
+ args: ['path/to/mcp-server.js'],
242
+ env: { PORT: '3000' },
243
+ },
244
+ },
245
+ },
246
+ });
247
+ ```
248
+
249
+ ### With SDK-Embedded MCP Servers
250
+
251
+ The SDK provides `tool` and `createSdkMcpServer` to create MCP servers that run in the same process as your SDK application. This is useful when you want to expose custom tools to the AI without running a separate server process.
252
+
253
+ #### `tool(name, description, inputSchema, handler)`
254
+
255
+ Creates a tool definition with Zod schema type inference.
256
+
257
+ | Parameter | Type | Description |
258
+ | ------------- | ---------------------------------- | ------------------------------------------------------------------------ |
259
+ | `name` | `string` | Tool name (1-64 chars, starts with letter, alphanumeric and underscores) |
260
+ | `description` | `string` | Human-readable description of what the tool does |
261
+ | `inputSchema` | `ZodRawShape` | Zod schema object defining the tool's input parameters |
262
+ | `handler` | `(args, extra) => Promise<Result>` | Async function that executes the tool and returns MCP content blocks |
263
+
264
+ The handler must return a `CallToolResult` object with the following structure:
265
+
266
+ ```typescript
267
+ {
268
+ content: Array<
269
+ | { type: 'text'; text: string }
270
+ | { type: 'image'; data: string; mimeType: string }
271
+ | { type: 'resource'; uri: string; mimeType?: string; text?: string }
272
+ >;
273
+ isError?: boolean;
274
+ }
275
+ ```
276
+
277
+ #### `createSdkMcpServer(options)`
278
+
279
+ Creates an SDK-embedded MCP server instance.
280
+
281
+ | Option | Type | Default | Description |
282
+ | --------- | ------------------------ | --------- | ------------------------------------ |
283
+ | `name` | `string` | Required | Unique name for the MCP server |
284
+ | `version` | `string` | `'1.0.0'` | Server version |
285
+ | `tools` | `SdkMcpToolDefinition[]` | - | Array of tools created with `tool()` |
286
+
287
+ Returns a `McpSdkServerConfigWithInstance` object that can be passed directly to the `mcpServers` option.
288
+
289
+ #### Example
290
+
291
+ ```typescript
292
+ import { z } from 'zod';
293
+ import { query, tool, createSdkMcpServer } from '@qwen-code/sdk';
294
+
295
+ // Define a tool with Zod schema
296
+ const calculatorTool = tool(
297
+ 'calculate_sum',
298
+ 'Add two numbers',
299
+ { a: z.number(), b: z.number() },
300
+ async (args) => ({
301
+ content: [{ type: 'text', text: String(args.a + args.b) }],
302
+ }),
303
+ );
304
+
305
+ // Create the MCP server
306
+ const server = createSdkMcpServer({
307
+ name: 'calculator',
308
+ tools: [calculatorTool],
309
+ });
310
+
311
+ // Use the server in a query
312
+ const result = query({
313
+ prompt: 'What is 42 + 17?',
314
+ options: {
315
+ permissionMode: 'yolo',
316
+ mcpServers: {
317
+ calculator: server,
318
+ },
319
+ },
320
+ });
321
+
322
+ for await (const message of result) {
323
+ console.log(message);
324
+ }
325
+ ```
326
+
327
+ ### Abort a Query
328
+
329
+ ```typescript
330
+ import { query, isAbortError } from '@qwen-code/sdk';
331
+
332
+ const abortController = new AbortController();
333
+
334
+ const result = query({
335
+ prompt: 'Long running task...',
336
+ options: {
337
+ abortController,
338
+ },
339
+ });
340
+
341
+ // Abort after 5 seconds
342
+ setTimeout(() => abortController.abort(), 5000);
343
+
344
+ try {
345
+ for await (const message of result) {
346
+ console.log(message);
347
+ }
348
+ } catch (error) {
349
+ if (isAbortError(error)) {
350
+ console.log('Query was aborted');
351
+ } else {
352
+ throw error;
353
+ }
354
+ }
355
+ ```
356
+
357
+ ## Error Handling
358
+
359
+ The SDK provides an `AbortError` class for handling aborted queries:
360
+
361
+ ```typescript
362
+ import { AbortError, isAbortError } from '@qwen-code/sdk';
363
+
364
+ try {
365
+ // ... query operations
366
+ } catch (error) {
367
+ if (isAbortError(error)) {
368
+ // Handle abort
369
+ } else {
370
+ // Handle other errors
371
+ }
372
+ }
373
+ ```
374
+
375
+ ## License
376
+
377
+ Apache-2.0 - see [LICENSE](./LICENSE) for details.
package/dist/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2025 Google LLC
191
+ Copyright 2025 Qwen
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.