@protolabsai/sdk 0.2.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,441 @@
1
+ # @protolabsai/sdk
2
+
3
+ A TypeScript SDK for programmatic access to protoCLI.
4
+
5
+ Feel free to submit a feature request/issue/PR.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @protolabsai/sdk
11
+ ```
12
+
13
+ ## Requirements
14
+
15
+ - Node.js >= 20.0.0
16
+
17
+ > From v0.1.1, the CLI is bundled with the SDK. So no standalone CLI installation is needed.
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { query } from '@protolabsai/sdk';
23
+
24
+ // Single-turn query
25
+ const result = query({
26
+ prompt: 'What files are in the current directory?',
27
+ options: {
28
+ cwd: '/path/to/project',
29
+ },
30
+ });
31
+
32
+ // Iterate over messages
33
+ for await (const message of result) {
34
+ if (message.type === 'assistant') {
35
+ console.log('Assistant:', message.message.content);
36
+ } else if (message.type === 'result') {
37
+ console.log('Result:', message.result);
38
+ }
39
+ }
40
+ ```
41
+
42
+ ## API Reference
43
+
44
+ ### `query(config)`
45
+
46
+ Creates a new query session with protoCLI.
47
+
48
+ #### Parameters
49
+
50
+ - `prompt`: `string | AsyncIterable<SDKUserMessage>` - The prompt to send. Use a string for single-turn queries or an async iterable for multi-turn conversations.
51
+ - `options`: `QueryOptions` - Configuration options for the query session.
52
+
53
+ #### QueryOptions
54
+
55
+ | Option | Type | Default | Description |
56
+ | ------------------------ | ---------------------------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
57
+ | `cwd` | `string` | `process.cwd()` | The working directory for the query session. Determines the context in which file operations and commands are executed. |
58
+ | `model` | `string` | - | The AI model to use (e.g., `'claude-opus-4-6'`, `'claude-sonnet-4-6'`, `'claude-haiku-4-5-20251001'`). Takes precedence over the `OPENAI_MODEL` environment variable. |
59
+ | `pathToQwenExecutable` | `string` | Auto-detected | Path to the proto CLI executable. Supports multiple formats: `'proto'` (native binary from PATH), `'/path/to/proto'` (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 the bundled CLI. |
60
+ | `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
61
+ | `canUseTool` | `CanUseTool` | - | Custom permission handler for tool execution approval. Invoked when a tool requires confirmation. Must respond within 60 seconds or the request will be auto-denied. See [Custom Permission Handler](#custom-permission-handler). |
62
+ | `baseURL` | `string` | - | Base URL for the AI provider API. Routes requests through a custom gateway or proxy instead of calling the provider directly. Sets `OPENAI_BASE_URL` in the CLI process environment. Example: `'http://gateway:4000/v1'`. |
63
+ | `env` | `Record<string, string>` | - | Environment variables to pass to the proto CLI process. Merged with the current process environment. |
64
+ | `systemPrompt` | `string \| QuerySystemPromptPreset` | - | System prompt configuration for the main session. Use a string to fully override the built-in protoCLI system prompt, or a preset object to keep the built-in prompt and append extra instructions. |
65
+ | `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 }`. |
66
+ | `abortController` | `AbortController` | - | Controller to cancel the query session. Call `abortController.abort()` to terminate the session and cleanup resources. |
67
+ | `debug` | `boolean` | `false` | Enable debug mode for verbose logging from the CLI process. |
68
+ | `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. |
69
+ | `coreTools` | `string[]` | - | Equivalent to `permissions.allow` in settings.json as an allowlist. If specified, only these tools will be available to the AI (all other tools are disabled at registry level). Supports tool name aliases and pattern matching. Example: `['Read', 'Edit', 'Bash(git *)']`. |
70
+ | `excludeTools` | `string[]` | - | Equivalent to `permissions.deny` in settings.json. Excluded tools return a permission error immediately. Takes highest priority over all other permission settings. Supports tool name aliases and pattern matching: tool name (`'write_file'`), shell command prefix (`'Bash(rm *)'`), or path patterns (`'Read(.env)'`, `'Edit(/src/**)'`). |
71
+ | `allowedTools` | `string[]` | - | Equivalent to `permissions.allow` in settings.json. Matching tools bypass `canUseTool` callback and execute automatically. Only applies when tool requires confirmation. Supports same pattern matching as `excludeTools`. Example: `['ShellTool(git status)', 'ShellTool(npm test)']`. |
72
+ | `authType` | `'openai'` | `'openai'` | Authentication type for the AI service. Authenticates via OpenAI-compatible API using `ANTHROPIC_API_KEY` or `OPENAI_API_KEY`. |
73
+ | `agents` | `SubagentConfig[]` | - | Configuration for subagents that can be invoked during the session. Subagents are specialized AI agents for specific tasks or domains. |
74
+ | `includePartialMessages` | `boolean` | `false` | When `true`, the SDK emits incomplete messages as they are being generated, allowing real-time streaming of the AI's response. |
75
+ | `resume` | `string` | - | Resume a previous session by providing its session ID. Equivalent to CLI's `--resume` flag. |
76
+ | `sessionId` | `string` | - | Specify a session ID for the new session. Ensures SDK and CLI use the same ID without resuming history. Equivalent to CLI's `--session-id` flag. |
77
+
78
+ > [!tip]
79
+ > When configuring `coreTools`, `excludeTools`, or `allowedTools`, use tool name aliases and pattern matching syntax (e.g., `Bash(git *)`, `Read(.env)`, `Edit(/src/**)`) to target specific tools or shell commands.
80
+
81
+ ### Timeouts
82
+
83
+ The SDK enforces the following default timeouts:
84
+
85
+ | Timeout | Default | Description |
86
+ | ---------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
87
+ | `canUseTool` | 1 minute | Maximum time for `canUseTool` callback to respond. If exceeded, the tool request is auto-denied. |
88
+ | `mcpRequest` | 1 minute | Maximum time for SDK MCP tool calls to complete. |
89
+ | `controlRequest` | 1 minute | Maximum time for control operations like `initialize()`, `setModel()`, `setPermissionMode()`, and `interrupt()` to complete. |
90
+ | `streamClose` | 1 minute | Maximum time to wait for initialization to complete before closing CLI stdin in multi-turn mode with SDK MCP servers. |
91
+
92
+ You can customize these timeouts via the `timeout` option:
93
+
94
+ ```typescript
95
+ const q = query({
96
+ prompt: 'Your prompt',
97
+ options: {
98
+ timeout: {
99
+ canUseTool: 60000, // 60 seconds for permission callback
100
+ mcpRequest: 600000, // 10 minutes for MCP tool calls
101
+ controlRequest: 60000, // 60 seconds for control requests
102
+ streamClose: 15000, // 15 seconds for stream close wait
103
+ },
104
+ },
105
+ });
106
+ ```
107
+
108
+ ### Message Types
109
+
110
+ The SDK provides type guards to identify different message types:
111
+
112
+ ```typescript
113
+ import {
114
+ isSDKUserMessage,
115
+ isSDKAssistantMessage,
116
+ isSDKSystemMessage,
117
+ isSDKResultMessage,
118
+ isSDKPartialAssistantMessage,
119
+ } from '@protolabsai/sdk';
120
+
121
+ for await (const message of result) {
122
+ if (isSDKAssistantMessage(message)) {
123
+ // Handle assistant message
124
+ } else if (isSDKResultMessage(message)) {
125
+ // Handle result message
126
+ }
127
+ }
128
+ ```
129
+
130
+ ### Query Instance Methods
131
+
132
+ The `Query` instance returned by `query()` provides several methods:
133
+
134
+ ```typescript
135
+ const q = query({ prompt: 'Hello', options: {} });
136
+
137
+ // Get session ID
138
+ const sessionId = q.getSessionId();
139
+
140
+ // Check if closed
141
+ const closed = q.isClosed();
142
+
143
+ // Interrupt the current operation
144
+ await q.interrupt();
145
+
146
+ // Change permission mode mid-session
147
+ await q.setPermissionMode('yolo');
148
+
149
+ // Change model mid-session
150
+ await q.setModel('claude-sonnet-4-6');
151
+
152
+ // Close the session
153
+ await q.close();
154
+ ```
155
+
156
+ ## Permission Modes
157
+
158
+ The SDK supports different permission modes for controlling tool execution:
159
+
160
+ - **`default`**: Write tools are denied unless approved via `canUseTool` callback or in `allowedTools`. Read-only tools execute without confirmation.
161
+ - **`plan`**: Blocks all write tools, instructing AI to present a plan first.
162
+ - **`auto-edit`**: Auto-approve edit tools (edit, write_file) while other tools require confirmation.
163
+ - **`yolo`**: All tools execute automatically without confirmation.
164
+
165
+ ### Permission Priority Chain
166
+
167
+ Decision priority (highest first): `deny` > `ask` > `allow` > _(default/interactive mode)_
168
+
169
+ The first matching rule wins.
170
+
171
+ 1. `excludeTools` / `permissions.deny` - Blocks tools completely (returns permission error)
172
+ 2. `permissions.ask` - Always requires user confirmation
173
+ 3. `permissionMode: 'plan'` - Blocks all non-read-only tools
174
+ 4. `permissionMode: 'yolo'` - Auto-approves all tools
175
+ 5. `allowedTools` / `permissions.allow` - Auto-approves matching tools
176
+ 6. `canUseTool` callback - Custom approval logic (if provided, not called for allowed tools)
177
+ 7. Default behavior - Auto-deny in SDK mode (write tools require explicit approval)
178
+
179
+ ## Examples
180
+
181
+ ### Multi-turn Conversation
182
+
183
+ ```typescript
184
+ import { query, type SDKUserMessage } from '@protolabsai/sdk';
185
+
186
+ async function* generateMessages(): AsyncIterable<SDKUserMessage> {
187
+ yield {
188
+ type: 'user',
189
+ session_id: 'my-session',
190
+ message: { role: 'user', content: 'Create a hello.txt file' },
191
+ parent_tool_use_id: null,
192
+ };
193
+
194
+ // Wait for some condition or user input
195
+ yield {
196
+ type: 'user',
197
+ session_id: 'my-session',
198
+ message: { role: 'user', content: 'Now read the file back' },
199
+ parent_tool_use_id: null,
200
+ };
201
+ }
202
+
203
+ const result = query({
204
+ prompt: generateMessages(),
205
+ options: {
206
+ permissionMode: 'auto-edit',
207
+ },
208
+ });
209
+
210
+ for await (const message of result) {
211
+ console.log(message);
212
+ }
213
+ ```
214
+
215
+ ### Custom Permission Handler
216
+
217
+ ```typescript
218
+ import { query, type CanUseTool } from '@protolabsai/sdk';
219
+
220
+ const canUseTool: CanUseTool = async (toolName, input, { signal }) => {
221
+ // Allow all read operations
222
+ if (toolName.startsWith('read_')) {
223
+ return { behavior: 'allow', updatedInput: input };
224
+ }
225
+
226
+ // Prompt user for write operations (in a real app)
227
+ const userApproved = await promptUser(`Allow ${toolName}?`);
228
+
229
+ if (userApproved) {
230
+ return { behavior: 'allow', updatedInput: input };
231
+ }
232
+
233
+ return { behavior: 'deny', message: 'User denied the operation' };
234
+ };
235
+
236
+ const result = query({
237
+ prompt: 'Create a new file',
238
+ options: {
239
+ canUseTool,
240
+ },
241
+ });
242
+ ```
243
+
244
+ ### With External MCP Servers
245
+
246
+ ```typescript
247
+ import { query } from '@protolabsai/sdk';
248
+
249
+ const result = query({
250
+ prompt: 'Use the custom tool from my MCP server',
251
+ options: {
252
+ mcpServers: {
253
+ 'my-server': {
254
+ command: 'node',
255
+ args: ['path/to/mcp-server.js'],
256
+ env: { PORT: '3000' },
257
+ },
258
+ },
259
+ },
260
+ });
261
+ ```
262
+
263
+ ### Route Through a Custom Gateway
264
+
265
+ ```typescript
266
+ import { query } from '@protolabsai/sdk';
267
+
268
+ // Route through a gateway or proxy instead of calling the API directly
269
+ const result = query({
270
+ prompt: 'What is the status of this project?',
271
+ options: {
272
+ model: 'claude-opus-4-6',
273
+ baseURL: 'http://gateway:4000/v1',
274
+ cwd: '/path/to/project',
275
+ },
276
+ });
277
+
278
+ for await (const message of result) {
279
+ if (message.type === 'result') {
280
+ console.log(message.result);
281
+ }
282
+ }
283
+ ```
284
+
285
+ ### Override the System Prompt
286
+
287
+ ```typescript
288
+ import { query } from '@protolabsai/sdk';
289
+
290
+ const result = query({
291
+ prompt: 'Say hello in one sentence.',
292
+ options: {
293
+ systemPrompt: 'You are a terse assistant. Answer in exactly one sentence.',
294
+ },
295
+ });
296
+ ```
297
+
298
+ ### Append to the Built-in System Prompt
299
+
300
+ ```typescript
301
+ import { query } from '@protolabsai/sdk';
302
+
303
+ const result = query({
304
+ prompt: 'Review the current directory.',
305
+ options: {
306
+ systemPrompt: {
307
+ append: 'Be terse and focus on concrete findings.',
308
+ },
309
+ },
310
+ });
311
+ ```
312
+
313
+ ### With SDK-Embedded MCP Servers
314
+
315
+ 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.
316
+
317
+ #### `tool(name, description, inputSchema, handler)`
318
+
319
+ Creates a tool definition with Zod schema type inference.
320
+
321
+ | Parameter | Type | Description |
322
+ | ------------- | ---------------------------------- | ------------------------------------------------------------------------ |
323
+ | `name` | `string` | Tool name (1-64 chars, starts with letter, alphanumeric and underscores) |
324
+ | `description` | `string` | Human-readable description of what the tool does |
325
+ | `inputSchema` | `ZodRawShape` | Zod schema object defining the tool's input parameters |
326
+ | `handler` | `(args, extra) => Promise<Result>` | Async function that executes the tool and returns MCP content blocks |
327
+
328
+ The handler must return a `CallToolResult` object with the following structure:
329
+
330
+ ```typescript
331
+ {
332
+ content: Array<
333
+ | { type: 'text'; text: string }
334
+ | { type: 'image'; data: string; mimeType: string }
335
+ | { type: 'resource'; uri: string; mimeType?: string; text?: string }
336
+ >;
337
+ isError?: boolean;
338
+ }
339
+ ```
340
+
341
+ #### `createSdkMcpServer(options)`
342
+
343
+ Creates an SDK-embedded MCP server instance.
344
+
345
+ | Option | Type | Default | Description |
346
+ | --------- | ------------------------ | --------- | ------------------------------------ |
347
+ | `name` | `string` | Required | Unique name for the MCP server |
348
+ | `version` | `string` | `'1.0.0'` | Server version |
349
+ | `tools` | `SdkMcpToolDefinition[]` | - | Array of tools created with `tool()` |
350
+
351
+ Returns a `McpSdkServerConfigWithInstance` object that can be passed directly to the `mcpServers` option.
352
+
353
+ #### Example
354
+
355
+ ```typescript
356
+ import { z } from 'zod';
357
+ import { query, tool, createSdkMcpServer } from '@protolabsai/sdk';
358
+
359
+ // Define a tool with Zod schema
360
+ const calculatorTool = tool(
361
+ 'calculate_sum',
362
+ 'Add two numbers',
363
+ { a: z.number(), b: z.number() },
364
+ async (args) => ({
365
+ content: [{ type: 'text', text: String(args.a + args.b) }],
366
+ }),
367
+ );
368
+
369
+ // Create the MCP server
370
+ const server = createSdkMcpServer({
371
+ name: 'calculator',
372
+ tools: [calculatorTool],
373
+ });
374
+
375
+ // Use the server in a query
376
+ const result = query({
377
+ prompt: 'What is 42 + 17?',
378
+ options: {
379
+ permissionMode: 'yolo',
380
+ mcpServers: {
381
+ calculator: server,
382
+ },
383
+ },
384
+ });
385
+
386
+ for await (const message of result) {
387
+ console.log(message);
388
+ }
389
+ ```
390
+
391
+ ### Abort a Query
392
+
393
+ ```typescript
394
+ import { query, isAbortError } from '@protolabsai/sdk';
395
+
396
+ const abortController = new AbortController();
397
+
398
+ const result = query({
399
+ prompt: 'Long running task...',
400
+ options: {
401
+ abortController,
402
+ },
403
+ });
404
+
405
+ // Abort after 5 seconds
406
+ setTimeout(() => abortController.abort(), 5000);
407
+
408
+ try {
409
+ for await (const message of result) {
410
+ console.log(message);
411
+ }
412
+ } catch (error) {
413
+ if (isAbortError(error)) {
414
+ console.log('Query was aborted');
415
+ } else {
416
+ throw error;
417
+ }
418
+ }
419
+ ```
420
+
421
+ ## Error Handling
422
+
423
+ The SDK provides an `AbortError` class for handling aborted queries:
424
+
425
+ ```typescript
426
+ import { AbortError, isAbortError } from '@protolabsai/sdk';
427
+
428
+ try {
429
+ // ... query operations
430
+ } catch (error) {
431
+ if (isAbortError(error)) {
432
+ // Handle abort
433
+ } else {
434
+ // Handle other errors
435
+ }
436
+ }
437
+ ```
438
+
439
+ ## License
440
+
441
+ 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.