@protolabsai/proto 0.14.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 +203 -0
- package/README.md +286 -0
- package/dist/bundled/adversarial-verification/SKILL.md +98 -0
- package/dist/bundled/brainstorming/SKILL.md +171 -0
- package/dist/bundled/coding-agent-standards/SKILL.md +67 -0
- package/dist/bundled/dispatching-parallel-agents/SKILL.md +193 -0
- package/dist/bundled/executing-plans/SKILL.md +77 -0
- package/dist/bundled/finishing-a-development-branch/SKILL.md +213 -0
- package/dist/bundled/loop/SKILL.md +61 -0
- package/dist/bundled/qc-helper/SKILL.md +151 -0
- package/dist/bundled/qc-helper/docs/_meta.ts +30 -0
- package/dist/bundled/qc-helper/docs/common-workflow.md +571 -0
- package/dist/bundled/qc-helper/docs/configuration/_meta.ts +10 -0
- package/dist/bundled/qc-helper/docs/configuration/auth.md +366 -0
- package/dist/bundled/qc-helper/docs/configuration/memory.md +0 -0
- package/dist/bundled/qc-helper/docs/configuration/model-providers.md +542 -0
- package/dist/bundled/qc-helper/docs/configuration/qwen-ignore.md +55 -0
- package/dist/bundled/qc-helper/docs/configuration/settings.md +652 -0
- package/dist/bundled/qc-helper/docs/configuration/themes.md +160 -0
- package/dist/bundled/qc-helper/docs/configuration/trusted-folders.md +61 -0
- package/dist/bundled/qc-helper/docs/extension/_meta.ts +9 -0
- package/dist/bundled/qc-helper/docs/extension/extension-releasing.md +121 -0
- package/dist/bundled/qc-helper/docs/extension/getting-started-extensions.md +299 -0
- package/dist/bundled/qc-helper/docs/extension/introduction.md +303 -0
- package/dist/bundled/qc-helper/docs/features/_meta.ts +18 -0
- package/dist/bundled/qc-helper/docs/features/approval-mode.md +263 -0
- package/dist/bundled/qc-helper/docs/features/arena.md +218 -0
- package/dist/bundled/qc-helper/docs/features/checkpointing.md +77 -0
- package/dist/bundled/qc-helper/docs/features/commands.md +312 -0
- package/dist/bundled/qc-helper/docs/features/headless.md +318 -0
- package/dist/bundled/qc-helper/docs/features/hooks.md +343 -0
- package/dist/bundled/qc-helper/docs/features/language.md +139 -0
- package/dist/bundled/qc-helper/docs/features/lsp.md +453 -0
- package/dist/bundled/qc-helper/docs/features/mcp.md +281 -0
- package/dist/bundled/qc-helper/docs/features/sandbox.md +241 -0
- package/dist/bundled/qc-helper/docs/features/scheduled-tasks.md +139 -0
- package/dist/bundled/qc-helper/docs/features/skills.md +289 -0
- package/dist/bundled/qc-helper/docs/features/sub-agents.md +307 -0
- package/dist/bundled/qc-helper/docs/features/token-caching.md +29 -0
- package/dist/bundled/qc-helper/docs/ide-integration/_meta.ts +4 -0
- package/dist/bundled/qc-helper/docs/ide-integration/ide-companion-spec.md +182 -0
- package/dist/bundled/qc-helper/docs/ide-integration/ide-integration.md +144 -0
- package/dist/bundled/qc-helper/docs/integration-github-action.md +241 -0
- package/dist/bundled/qc-helper/docs/integration-jetbrains.md +81 -0
- package/dist/bundled/qc-helper/docs/integration-vscode.md +39 -0
- package/dist/bundled/qc-helper/docs/integration-zed.md +72 -0
- package/dist/bundled/qc-helper/docs/overview.md +64 -0
- package/dist/bundled/qc-helper/docs/quickstart.md +273 -0
- package/dist/bundled/qc-helper/docs/reference/_meta.ts +4 -0
- package/dist/bundled/qc-helper/docs/reference/keyboard-shortcuts.md +72 -0
- package/dist/bundled/qc-helper/docs/reference/sdk-api.md +524 -0
- package/dist/bundled/qc-helper/docs/support/Uninstall.md +42 -0
- package/dist/bundled/qc-helper/docs/support/_meta.ts +6 -0
- package/dist/bundled/qc-helper/docs/support/tos-privacy.md +112 -0
- package/dist/bundled/qc-helper/docs/support/troubleshooting.md +123 -0
- package/dist/bundled/receiving-code-review/SKILL.md +226 -0
- package/dist/bundled/requesting-code-review/SKILL.md +115 -0
- package/dist/bundled/review/SKILL.md +123 -0
- package/dist/bundled/subagent-driven-development/SKILL.md +292 -0
- package/dist/bundled/subagent-driven-development/code-quality-reviewer-prompt.md +27 -0
- package/dist/bundled/subagent-driven-development/implementer-prompt.md +113 -0
- package/dist/bundled/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/dist/bundled/systematic-debugging/SKILL.md +305 -0
- package/dist/bundled/test-driven-development/SKILL.md +396 -0
- package/dist/bundled/using-git-worktrees/SKILL.md +223 -0
- package/dist/bundled/using-superpowers/SKILL.md +117 -0
- package/dist/bundled/verification-before-completion/SKILL.md +147 -0
- package/dist/bundled/writing-plans/SKILL.md +159 -0
- package/dist/bundled/writing-skills/SKILL.md +716 -0
- package/dist/cli.js +483432 -0
- package/dist/sandbox-macos-permissive-closed.sb +32 -0
- package/dist/sandbox-macos-permissive-open.sb +27 -0
- package/dist/sandbox-macos-permissive-proxied.sb +37 -0
- package/dist/sandbox-macos-restrictive-closed.sb +93 -0
- package/dist/sandbox-macos-restrictive-open.sb +96 -0
- package/dist/sandbox-macos-restrictive-proxied.sb +98 -0
- package/dist/vendor/ripgrep/COPYING +3 -0
- package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/dist/vendor/tree-sitter/tree-sitter-bash.wasm +0 -0
- package/dist/vendor/tree-sitter/tree-sitter.wasm +0 -0
- package/package.json +143 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
# SDK API Reference
|
|
2
|
+
|
|
3
|
+
Complete API reference for `@qwen-code/sdk`. For a guided introduction, see the [TypeScript SDK](../../developers/sdk-typescript.md) developer guide.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @qwen-code/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node.js >= 20.0.0 and Qwen Code >= 0.4.0 installed in PATH.
|
|
12
|
+
|
|
13
|
+
## query()
|
|
14
|
+
|
|
15
|
+
Creates a new query session with the Qwen Code CLI.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { query } from '@qwen-code/sdk';
|
|
19
|
+
|
|
20
|
+
const conversation = query({
|
|
21
|
+
prompt: 'What files are in the current directory?',
|
|
22
|
+
options: { cwd: '/path/to/project' },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
for await (const message of conversation) {
|
|
26
|
+
// process messages
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Parameters
|
|
31
|
+
|
|
32
|
+
| Parameter | Type | Description |
|
|
33
|
+
| --------- | ----------------------------------------- | ------------------------------------------------------------ |
|
|
34
|
+
| `prompt` | `string \| AsyncIterable<SDKUserMessage>` | String for single-turn, async iterable for multi-turn |
|
|
35
|
+
| `options` | `QueryOptions` | Session configuration (all fields optional, see table below) |
|
|
36
|
+
|
|
37
|
+
### Return value
|
|
38
|
+
|
|
39
|
+
Returns a `Query` instance that implements `AsyncIterable<SDKMessage>`. Iterate with `for await...of` to receive messages.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## QueryOptions
|
|
44
|
+
|
|
45
|
+
All fields are optional.
|
|
46
|
+
|
|
47
|
+
### Core options
|
|
48
|
+
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
| ------------------------ | ---------------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| `cwd` | `string` | `process.cwd()` | Working directory for file operations and commands |
|
|
52
|
+
| `model` | `string` | - | Model ID (e.g., `'qwen-max'`, `'qwen-plus'`) |
|
|
53
|
+
| `pathToQwenExecutable` | `string` | Auto-detected | Path to Qwen Code binary. See [SDK guide](../../developers/sdk-typescript.md#queryoptions) for detection logic |
|
|
54
|
+
| `env` | `Record<string, string>` | - | Environment variables merged into CLI process |
|
|
55
|
+
| `systemPrompt` | `string \| QuerySystemPromptPreset` | - | Override or extend the built-in system prompt |
|
|
56
|
+
| `maxSessionTurns` | `number` | `-1` (unlimited) | Max conversation turns before auto-termination |
|
|
57
|
+
| `debug` | `boolean` | `false` | Enable verbose logging from CLI |
|
|
58
|
+
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error'` | `'error'` | SDK log verbosity |
|
|
59
|
+
| `stderr` | `(message: string) => void` | - | Handler for CLI stderr output |
|
|
60
|
+
| `abortController` | `AbortController` | Auto-created | Call `.abort()` to terminate the session |
|
|
61
|
+
| `includePartialMessages` | `boolean` | `false` | Emit streaming events as they arrive |
|
|
62
|
+
|
|
63
|
+
### Permission options
|
|
64
|
+
|
|
65
|
+
| Option | Type | Default | Description |
|
|
66
|
+
| ---------------- | ---------------------------------------------- | ----------- | ------------------------------------------------------------------------------- |
|
|
67
|
+
| `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'yolo'` | `'default'` | Tool execution approval strategy |
|
|
68
|
+
| `canUseTool` | `CanUseTool` | - | Custom permission callback (see below) |
|
|
69
|
+
| `allowedTools` | `string[]` | - | Tools auto-approved without confirmation |
|
|
70
|
+
| `excludeTools` | `string[]` | - | Tools blocked completely (highest priority) |
|
|
71
|
+
| `coreTools` | `string[]` | - | If set, only these tools are available |
|
|
72
|
+
| `authType` | `AuthType` | `'openai'` | Auth type: `'openai'`, `'anthropic'`, `'qwen-oauth'`, `'gemini'`, `'vertex-ai'` |
|
|
73
|
+
|
|
74
|
+
### Session options
|
|
75
|
+
|
|
76
|
+
| Option | Type | Default | Description |
|
|
77
|
+
| --------------- | --------- | -------------- | ----------------------------------------------- |
|
|
78
|
+
| `resume` | `string` | - | Session ID to resume (loads prior conversation) |
|
|
79
|
+
| `sessionId` | `string` | Auto-generated | Explicit session ID for SDK-CLI alignment |
|
|
80
|
+
| `chatRecording` | `boolean` | `true` | Set to `false` to disable session persistence |
|
|
81
|
+
| `sandbox` | `boolean` | `false` | Isolated execution with restricted file access |
|
|
82
|
+
|
|
83
|
+
### Agent and tool options
|
|
84
|
+
|
|
85
|
+
| Option | Type | Default | Description |
|
|
86
|
+
| ------------- | --------------------------------- | ------- | ----------------------------------------------------------------------------------------------- |
|
|
87
|
+
| `agents` | `SubagentConfig[]` | - | Subagent configurations. See [Sub-Agents](../features/sub-agents.md#sdk-subagent-configuration) |
|
|
88
|
+
| `mcpServers` | `Record<string, McpServerConfig>` | - | MCP servers (external or SDK-embedded) |
|
|
89
|
+
| `extensions` | `string[]` | - | Extension names to enable |
|
|
90
|
+
| `includeDirs` | `string[]` | - | Additional workspace directories |
|
|
91
|
+
| `lsp` | `boolean` | `false` | Enable LSP code intelligence (goToDefinition, diagnostics, etc.). See [LSP](../features/lsp.md) |
|
|
92
|
+
|
|
93
|
+
### Hook options
|
|
94
|
+
|
|
95
|
+
| Option | Type | Default | Description |
|
|
96
|
+
| --------------- | ------------------------------------------------------------ | ------- | ----------------------------------------------------------------------------- |
|
|
97
|
+
| `hooks` | `boolean` | `false` | Enable CLI hook system. Auto-enabled when `hookCallbacks` is set |
|
|
98
|
+
| `hookCallbacks` | `Partial<Record<HookEvent, HookCallback \| HookCallback[]>>` | - | SDK-side hook callbacks. See [Hooks](../features/hooks.md#sdk-hook-callbacks) |
|
|
99
|
+
|
|
100
|
+
### Web search options
|
|
101
|
+
|
|
102
|
+
| Option | Type | Default | Description |
|
|
103
|
+
| ----------- | -------- | ------- | --------------------------------------------------------------------------- |
|
|
104
|
+
| `webSearch` | `object` | - | `{ tavilyApiKey?, googleApiKey?, googleSearchEngineId?, defaultProvider? }` |
|
|
105
|
+
|
|
106
|
+
### Timeout options
|
|
107
|
+
|
|
108
|
+
All values in milliseconds. Pass via `timeout` object.
|
|
109
|
+
|
|
110
|
+
| Key | Default | Description |
|
|
111
|
+
| ---------------- | ------- | ---------------------------------------------------- |
|
|
112
|
+
| `canUseTool` | `60000` | Max time for permission callback |
|
|
113
|
+
| `mcpRequest` | `60000` | Max time for SDK MCP tool calls |
|
|
114
|
+
| `controlRequest` | `60000` | Max time for control operations (init, model change) |
|
|
115
|
+
| `streamClose` | `60000` | Max wait before closing stdin in multi-turn mode |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Query instance
|
|
120
|
+
|
|
121
|
+
The object returned by `query()`.
|
|
122
|
+
|
|
123
|
+
### Methods
|
|
124
|
+
|
|
125
|
+
| Method | Return | Description |
|
|
126
|
+
| -------------------------- | --------------- | ---------------------------------- |
|
|
127
|
+
| `getSessionId()` | `string` | The session ID for this query |
|
|
128
|
+
| `isClosed()` | `boolean` | Whether the session has ended |
|
|
129
|
+
| `interrupt()` | `Promise<void>` | Interrupt the current operation |
|
|
130
|
+
| `setPermissionMode(mode)` | `Promise<void>` | Change permission mode mid-session |
|
|
131
|
+
| `setModel(model)` | `Promise<void>` | Change model mid-session |
|
|
132
|
+
| `close()` | `Promise<void>` | Terminate the session |
|
|
133
|
+
| `[Symbol.asyncIterator]()` | `AsyncIterator` | Iterate over `SDKMessage` objects |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Message types
|
|
138
|
+
|
|
139
|
+
All messages extend a common shape with `type`, `uuid`, and `session_id`.
|
|
140
|
+
|
|
141
|
+
### SDKAssistantMessage
|
|
142
|
+
|
|
143
|
+
Emitted when the model produces a response.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
{
|
|
147
|
+
type: 'assistant';
|
|
148
|
+
uuid: string;
|
|
149
|
+
session_id: string;
|
|
150
|
+
message: {
|
|
151
|
+
id: string;
|
|
152
|
+
type: 'message';
|
|
153
|
+
role: 'assistant';
|
|
154
|
+
model: string;
|
|
155
|
+
content: ContentBlock[];
|
|
156
|
+
stop_reason?: string | null;
|
|
157
|
+
usage: Usage;
|
|
158
|
+
};
|
|
159
|
+
parent_tool_use_id: string | null;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### SDKUserMessage
|
|
164
|
+
|
|
165
|
+
Echoed back when a user message is processed.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
{
|
|
169
|
+
type: 'user';
|
|
170
|
+
uuid?: string;
|
|
171
|
+
session_id: string;
|
|
172
|
+
message: { role: 'user'; content: string | ContentBlock[] };
|
|
173
|
+
parent_tool_use_id: string | null;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### SDKSystemMessage
|
|
178
|
+
|
|
179
|
+
System events (session init, compaction, etc.).
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
{
|
|
183
|
+
type: 'system';
|
|
184
|
+
subtype: string;
|
|
185
|
+
uuid: string;
|
|
186
|
+
session_id: string;
|
|
187
|
+
data?: unknown;
|
|
188
|
+
cwd?: string;
|
|
189
|
+
tools?: string[];
|
|
190
|
+
model?: string;
|
|
191
|
+
permission_mode?: string;
|
|
192
|
+
// ... additional optional fields
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### SDKResultMessage
|
|
197
|
+
|
|
198
|
+
Terminal message when the session ends.
|
|
199
|
+
|
|
200
|
+
**Success variant:**
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
{
|
|
204
|
+
type: 'result';
|
|
205
|
+
subtype: 'success';
|
|
206
|
+
is_error: false;
|
|
207
|
+
duration_ms: number;
|
|
208
|
+
duration_api_ms: number;
|
|
209
|
+
num_turns: number;
|
|
210
|
+
result: string;
|
|
211
|
+
usage: ExtendedUsage;
|
|
212
|
+
modelUsage?: Record<string, ModelUsage>;
|
|
213
|
+
permission_denials: CLIPermissionDenial[];
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Error variant:**
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
{
|
|
221
|
+
type: 'result';
|
|
222
|
+
subtype: 'error_max_turns' | 'error_during_execution';
|
|
223
|
+
is_error: true;
|
|
224
|
+
duration_ms: number;
|
|
225
|
+
num_turns: number;
|
|
226
|
+
error?: { type?: string; message: string };
|
|
227
|
+
usage: ExtendedUsage;
|
|
228
|
+
permission_denials: CLIPermissionDenial[];
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### SDKPartialAssistantMessage
|
|
233
|
+
|
|
234
|
+
Streaming tokens (only when `includePartialMessages: true`).
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
{
|
|
238
|
+
type: 'stream_event';
|
|
239
|
+
uuid: string;
|
|
240
|
+
session_id: string;
|
|
241
|
+
event: StreamEvent;
|
|
242
|
+
parent_tool_use_id: string | null;
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`StreamEvent` is one of: `MessageStartStreamEvent`, `ContentBlockStartEvent`, `ContentBlockDeltaEvent`, `ContentBlockStopEvent`, `MessageStopStreamEvent`.
|
|
247
|
+
|
|
248
|
+
### SDKTaskEvent
|
|
249
|
+
|
|
250
|
+
Task lifecycle event. Check with `isTaskEvent()`.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
{
|
|
254
|
+
type: 'system';
|
|
255
|
+
subtype: 'task_event';
|
|
256
|
+
data: {
|
|
257
|
+
action: 'created' | 'updated' | 'completed' | 'claimed' | 'stopped';
|
|
258
|
+
task: { id: string; title: string; status: string; assignee?: string; parentId?: string };
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### SDKMemoryEvent
|
|
264
|
+
|
|
265
|
+
Memory lifecycle event. Check with `isMemoryEvent()`.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
{
|
|
269
|
+
type: 'system';
|
|
270
|
+
subtype: 'memory_event';
|
|
271
|
+
data: {
|
|
272
|
+
action: 'saved' | 'updated' | 'deleted';
|
|
273
|
+
memory: {
|
|
274
|
+
name: string;
|
|
275
|
+
type: string;
|
|
276
|
+
file: string;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### SDKLspDiagnosticEvent
|
|
283
|
+
|
|
284
|
+
LSP diagnostic event. Check with `isLspDiagnosticEvent()`. Emitted when language servers report errors/warnings after file edits.
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
{
|
|
288
|
+
type: 'system';
|
|
289
|
+
subtype: 'lsp_diagnostic';
|
|
290
|
+
data: {
|
|
291
|
+
uri: string;
|
|
292
|
+
serverName?: string;
|
|
293
|
+
diagnostics: Array<{
|
|
294
|
+
severity: 'error' | 'warning' | 'info' | 'hint';
|
|
295
|
+
message: string;
|
|
296
|
+
range: { start: { line: number; character: number }; end: { line: number; character: number } };
|
|
297
|
+
source?: string;
|
|
298
|
+
code?: string | number;
|
|
299
|
+
}>;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Content blocks
|
|
307
|
+
|
|
308
|
+
The `content` array in assistant messages contains these block types:
|
|
309
|
+
|
|
310
|
+
| Type | Key fields | Description |
|
|
311
|
+
| ----------------- | ---------------------------------------------- | --------------- |
|
|
312
|
+
| `TextBlock` | `text: string` | Text content |
|
|
313
|
+
| `ThinkingBlock` | `thinking: string` | Model reasoning |
|
|
314
|
+
| `ToolUseBlock` | `id: string`, `name: string`, `input` | Tool invocation |
|
|
315
|
+
| `ToolResultBlock` | `tool_use_id: string`, `content?`, `is_error?` | Tool result |
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Type guards
|
|
320
|
+
|
|
321
|
+
All type guards accept `unknown` and return a type predicate.
|
|
322
|
+
|
|
323
|
+
| Guard | Narrows to |
|
|
324
|
+
| ----------------------------------- | ---------------------------- |
|
|
325
|
+
| `isSDKUserMessage(msg)` | `SDKUserMessage` |
|
|
326
|
+
| `isSDKAssistantMessage(msg)` | `SDKAssistantMessage` |
|
|
327
|
+
| `isSDKSystemMessage(msg)` | `SDKSystemMessage` |
|
|
328
|
+
| `isSDKResultMessage(msg)` | `SDKResultMessage` |
|
|
329
|
+
| `isSDKPartialAssistantMessage(msg)` | `SDKPartialAssistantMessage` |
|
|
330
|
+
| `isTaskEvent(msg)` | `SDKTaskEvent` |
|
|
331
|
+
| `isMemoryEvent(msg)` | `SDKMemoryEvent` |
|
|
332
|
+
| `isLspDiagnosticEvent(msg)` | `SDKLspDiagnosticEvent` |
|
|
333
|
+
| `isControlRequest(msg)` | `CLIControlRequest` |
|
|
334
|
+
| `isControlResponse(msg)` | `CLIControlResponse` |
|
|
335
|
+
| `isControlCancel(msg)` | `ControlCancelRequest` |
|
|
336
|
+
| `isTextBlock(block)` | `TextBlock` |
|
|
337
|
+
| `isThinkingBlock(block)` | `ThinkingBlock` |
|
|
338
|
+
| `isToolUseBlock(block)` | `ToolUseBlock` |
|
|
339
|
+
| `isToolResultBlock(block)` | `ToolResultBlock` |
|
|
340
|
+
| `isSdkMcpServerConfig(config)` | `SDKMcpServerConfig` |
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Callback types
|
|
345
|
+
|
|
346
|
+
### CanUseTool
|
|
347
|
+
|
|
348
|
+
Custom permission handler invoked when a tool requires confirmation.
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
type CanUseTool = (
|
|
352
|
+
toolName: string,
|
|
353
|
+
input: Record<string, unknown>,
|
|
354
|
+
options: {
|
|
355
|
+
signal: AbortSignal;
|
|
356
|
+
suggestions?: PermissionSuggestion[] | null;
|
|
357
|
+
},
|
|
358
|
+
) => Promise<PermissionResult>;
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Return:**
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// Allow
|
|
365
|
+
{ behavior: 'allow'; updatedInput: Record<string, unknown> }
|
|
366
|
+
|
|
367
|
+
// Deny
|
|
368
|
+
{ behavior: 'deny'; message: string; interrupt?: boolean }
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### HookCallback
|
|
372
|
+
|
|
373
|
+
SDK-side hook callback invoked when a hook event fires.
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
type HookCallback = (
|
|
377
|
+
input: unknown,
|
|
378
|
+
toolUseId: string | null,
|
|
379
|
+
) => Promise<HookCallbackResult> | HookCallbackResult;
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Return (`HookCallbackResult`):**
|
|
383
|
+
|
|
384
|
+
| Field | Type | Effect |
|
|
385
|
+
| ----------------- | --------- | --------------------------------------- |
|
|
386
|
+
| `shouldSkip` | `boolean` | Skip this tool call (`PreToolUse` only) |
|
|
387
|
+
| `shouldInterrupt` | `boolean` | Stop the agent immediately |
|
|
388
|
+
| `suppressOutput` | `boolean` | Hide tool output from conversation |
|
|
389
|
+
| `message` | `string` | Feedback string sent to the agent |
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## SubagentConfig
|
|
394
|
+
|
|
395
|
+
Configuration for subagents passed via the `agents` option.
|
|
396
|
+
|
|
397
|
+
| Field | Required | Type | Description |
|
|
398
|
+
| ---------------------------- | -------- | ----------- | ------------------------------------ |
|
|
399
|
+
| `name` | Yes | `string` | Unique identifier |
|
|
400
|
+
| `description` | Yes | `string` | When to delegate to this agent |
|
|
401
|
+
| `systemPrompt` | Yes | `string` | System prompt for the subagent |
|
|
402
|
+
| `level` | Yes | `'session'` | Subagent scope |
|
|
403
|
+
| `tools` | No | `string[]` | Tool allowlist. Omit to inherit all. |
|
|
404
|
+
| `modelConfig.model` | No | `string` | Model ID or alias |
|
|
405
|
+
| `modelConfig.temp` | No | `number` | Temperature (0-2) |
|
|
406
|
+
| `runConfig.max_turns` | No | `number` | Maximum agentic turns |
|
|
407
|
+
| `runConfig.max_time_minutes` | No | `number` | Maximum execution time in minutes |
|
|
408
|
+
| `color` | No | `string` | Display color |
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
## MCP server configuration
|
|
413
|
+
|
|
414
|
+
The `mcpServers` option accepts a record of server configs. Each value is either a `CLIMcpServerConfig` (external) or `SDKMcpServerConfig` (in-process).
|
|
415
|
+
|
|
416
|
+
### External servers (CLIMcpServerConfig)
|
|
417
|
+
|
|
418
|
+
| Field | Type | Description |
|
|
419
|
+
| -------------- | ------------------------ | ----------------------------------- |
|
|
420
|
+
| `command` | `string` | Stdio transport: executable command |
|
|
421
|
+
| `args` | `string[]` | Command arguments |
|
|
422
|
+
| `env` | `Record<string, string>` | Environment variables for process |
|
|
423
|
+
| `cwd` | `string` | Working directory for process |
|
|
424
|
+
| `url` | `string` | SSE transport URL |
|
|
425
|
+
| `httpUrl` | `string` | Streamable HTTP transport URL |
|
|
426
|
+
| `headers` | `Record<string, string>` | HTTP headers |
|
|
427
|
+
| `tcp` | `string` | WebSocket transport address |
|
|
428
|
+
| `timeout` | `number` | Connection timeout (ms) |
|
|
429
|
+
| `trust` | `boolean` | Trust this server (skip prompts) |
|
|
430
|
+
| `includeTools` | `string[]` | Only expose these tools |
|
|
431
|
+
| `excludeTools` | `string[]` | Hide these tools |
|
|
432
|
+
| `description` | `string` | Human-readable server description |
|
|
433
|
+
|
|
434
|
+
### SDK-embedded servers (SDKMcpServerConfig)
|
|
435
|
+
|
|
436
|
+
Created via `createSdkMcpServer()`. Runs in the SDK process with in-memory transport.
|
|
437
|
+
|
|
438
|
+
```typescript
|
|
439
|
+
import { tool, createSdkMcpServer } from '@qwen-code/sdk';
|
|
440
|
+
|
|
441
|
+
const myTool = tool('my_tool', 'Does something', { input: z.string() }, handler);
|
|
442
|
+
const server = createSdkMcpServer({ name: 'my-server', tools: [myTool] });
|
|
443
|
+
|
|
444
|
+
// Pass directly to mcpServers
|
|
445
|
+
mcpServers: { 'my-server': server }
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## SDK MCP helpers
|
|
451
|
+
|
|
452
|
+
### tool()
|
|
453
|
+
|
|
454
|
+
Creates a tool definition with Zod schema type inference.
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
function tool(
|
|
458
|
+
name: string,
|
|
459
|
+
description: string,
|
|
460
|
+
inputSchema: ZodRawShape,
|
|
461
|
+
handler: (
|
|
462
|
+
args: Inferred,
|
|
463
|
+
extra: RequestHandlerExtra,
|
|
464
|
+
) => Promise<CallToolResult>,
|
|
465
|
+
): SdkMcpToolDefinition;
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### createSdkMcpServer()
|
|
469
|
+
|
|
470
|
+
Creates an SDK-embedded MCP server.
|
|
471
|
+
|
|
472
|
+
```typescript
|
|
473
|
+
function createSdkMcpServer(options: {
|
|
474
|
+
name: string;
|
|
475
|
+
version?: string; // default '1.0.0'
|
|
476
|
+
tools: SdkMcpToolDefinition[];
|
|
477
|
+
}): McpSdkServerConfigWithInstance;
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## Error handling
|
|
483
|
+
|
|
484
|
+
### AbortError
|
|
485
|
+
|
|
486
|
+
Thrown when a session is aborted via `AbortController`.
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
import { isAbortError } from '@qwen-code/sdk';
|
|
490
|
+
|
|
491
|
+
try {
|
|
492
|
+
for await (const message of conversation) {
|
|
493
|
+
/* ... */
|
|
494
|
+
}
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (isAbortError(error)) {
|
|
497
|
+
console.log('Session was aborted');
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## Exported types
|
|
505
|
+
|
|
506
|
+
All types are available as named imports from `@qwen-code/sdk`:
|
|
507
|
+
|
|
508
|
+
**Message types:** `SDKMessage`, `SDKUserMessage`, `SDKAssistantMessage`, `SDKSystemMessage`, `SDKResultMessage`, `SDKPartialAssistantMessage`, `SDKTaskEvent`, `SDKMemoryEvent`, `SDKLspDiagnosticEvent`
|
|
509
|
+
|
|
510
|
+
**Content types:** `ContentBlock`, `TextBlock`, `ThinkingBlock`, `ToolUseBlock`, `ToolResultBlock`
|
|
511
|
+
|
|
512
|
+
**Config types:** `QueryOptions`, `QuerySystemPrompt`, `QuerySystemPromptPreset`, `SubagentConfig`, `SubagentLevel`, `ModelConfig`, `RunConfig`, `McpServerConfig`, `CLIMcpServerConfig`, `SDKMcpServerConfig`, `McpOAuthConfig`, `McpAuthProviderType`
|
|
513
|
+
|
|
514
|
+
**Permission types:** `PermissionMode`, `CanUseTool`, `PermissionResult`
|
|
515
|
+
|
|
516
|
+
**Hook types:** `HookEvent`, `HookCallback`, `HookCallbackResult`, `HookRegistration`
|
|
517
|
+
|
|
518
|
+
**Control protocol types:** `ControlMessage`, `CLIControlRequest`, `CLIControlResponse`, `ControlCancelRequest`
|
|
519
|
+
|
|
520
|
+
**Utility types:** `Usage`, `ExtendedUsage`, `ModelUsage`, `CLIPermissionDenial`, `StreamEvent`
|
|
521
|
+
|
|
522
|
+
**Functions:** `query`, `tool`, `createSdkMcpServer`, `isSdkMcpServerConfig`, `isAbortError`, `SdkLogger`
|
|
523
|
+
|
|
524
|
+
**Type guards:** `isSDKUserMessage`, `isSDKAssistantMessage`, `isSDKSystemMessage`, `isSDKResultMessage`, `isSDKPartialAssistantMessage`, `isTaskEvent`, `isMemoryEvent`, `isLspDiagnosticEvent`, `isControlRequest`, `isControlResponse`, `isControlCancel`, `isTextBlock`, `isThinkingBlock`, `isToolUseBlock`, `isToolResultBlock`
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Uninstall
|
|
2
|
+
|
|
3
|
+
Your uninstall method depends on how you ran the CLI. Follow the instructions for either npx or a global npm installation.
|
|
4
|
+
|
|
5
|
+
## Method 1: Using npx
|
|
6
|
+
|
|
7
|
+
npx runs packages from a temporary cache without a permanent installation. To "uninstall" the CLI, you must clear this cache, which will remove qwen-code and any other packages previously executed with npx.
|
|
8
|
+
|
|
9
|
+
The npx cache is a directory named `_npx` inside your main npm cache folder. You can find your npm cache path by running `npm config get cache`.
|
|
10
|
+
|
|
11
|
+
**For macOS / Linux**
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# The path is typically ~/.npm/_npx
|
|
15
|
+
rm -rf "$(npm config get cache)/_npx"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**For Windows**
|
|
19
|
+
|
|
20
|
+
_Command Prompt_
|
|
21
|
+
|
|
22
|
+
```cmd
|
|
23
|
+
:: The path is typically %LocalAppData%\npm-cache\_npx
|
|
24
|
+
rmdir /s /q "%LocalAppData%\npm-cache\_npx"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
_PowerShell_
|
|
28
|
+
|
|
29
|
+
```powershell
|
|
30
|
+
# The path is typically $env:LocalAppData\npm-cache\_npx
|
|
31
|
+
Remove-Item -Path (Join-Path $env:LocalAppData "npm-cache\_npx") -Recurse -Force
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Method 2: Using npm (Global Install)
|
|
35
|
+
|
|
36
|
+
If you installed the CLI globally (e.g. `npm install -g @qwen-code/qwen-code`), use the `npm uninstall` command with the `-g` flag to remove it.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm uninstall -g @qwen-code/qwen-code
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This command completely removes the package from your system.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Qwen Code: Terms of Service and Privacy Notice
|
|
2
|
+
|
|
3
|
+
Qwen Code is an open-source AI coding assistant tool maintained by the Qwen Code team. This document outlines the terms of service and privacy policies that apply when using Qwen Code's authentication methods and AI model services.
|
|
4
|
+
|
|
5
|
+
## How to determine your authentication method
|
|
6
|
+
|
|
7
|
+
Qwen Code supports three authentication methods to access AI models. Your authentication method determines which terms of service and privacy policies apply to your usage:
|
|
8
|
+
|
|
9
|
+
1. **Qwen OAuth** — Log in with your qwen.ai account (free daily quota)
|
|
10
|
+
2. **Alibaba Cloud Coding Plan** — Use an API key from Alibaba Cloud
|
|
11
|
+
3. **API Key** — Bring your own API key
|
|
12
|
+
|
|
13
|
+
For each authentication method, different Terms of Service and Privacy Notices may apply depending on the underlying service provider.
|
|
14
|
+
|
|
15
|
+
| Authentication Method | Provider | Terms of Service | Privacy Notice |
|
|
16
|
+
| :------------------------ | :---------------- | :----------------------------------------------------------------- | :----------------------------------------------------------------- |
|
|
17
|
+
| Qwen OAuth | Qwen AI | [Qwen Terms of Service](https://qwen.ai/termsservice) | [Qwen Privacy Policy](https://qwen.ai/privacypolicy) |
|
|
18
|
+
| Alibaba Cloud Coding Plan | Alibaba Cloud | See [details below](#2-if-you-are-using-alibaba-cloud-coding-plan) | See [details below](#2-if-you-are-using-alibaba-cloud-coding-plan) |
|
|
19
|
+
| API Key | Various Providers | Depends on your chosen API provider (OpenAI, Anthropic, etc.) | Depends on your chosen API provider |
|
|
20
|
+
|
|
21
|
+
## 1. If you are using Qwen OAuth Authentication
|
|
22
|
+
|
|
23
|
+
When you authenticate using your qwen.ai account, these Terms of Service and Privacy Notice documents apply:
|
|
24
|
+
|
|
25
|
+
- **Terms of Service:** Your use is governed by the [Qwen Terms of Service](https://qwen.ai/termsservice).
|
|
26
|
+
- **Privacy Notice:** The collection and use of your data is described in the [Qwen Privacy Policy](https://qwen.ai/privacypolicy).
|
|
27
|
+
|
|
28
|
+
For details about authentication setup, quotas, and supported features, see [Authentication Setup](../configuration/settings).
|
|
29
|
+
|
|
30
|
+
## 2. If you are using Alibaba Cloud Coding Plan
|
|
31
|
+
|
|
32
|
+
When you authenticate using an API key from Alibaba Cloud, the applicable Terms of Service and Privacy Notice from Alibaba Cloud apply.
|
|
33
|
+
|
|
34
|
+
Alibaba Cloud Coding Plan is available in two regions:
|
|
35
|
+
|
|
36
|
+
- **阿里云百炼 (aliyun.com)** — [bailian.console.aliyun.com](https://bailian.console.aliyun.com)
|
|
37
|
+
- **Alibaba Cloud (alibabacloud.com)** — [bailian.console.alibabacloud.com](https://bailian.console.alibabacloud.com)
|
|
38
|
+
|
|
39
|
+
> [!important]
|
|
40
|
+
>
|
|
41
|
+
> When using Alibaba Cloud Coding Plan, you are subject to Alibaba Cloud's terms and privacy policies. Please review their documentation for specific details about data usage, retention, and privacy practices.
|
|
42
|
+
|
|
43
|
+
## 3. If you are using your own API Key
|
|
44
|
+
|
|
45
|
+
When you authenticate using API keys from other providers, the applicable Terms of Service and Privacy Notice depend on your chosen provider.
|
|
46
|
+
|
|
47
|
+
> [!important]
|
|
48
|
+
>
|
|
49
|
+
> When using your own API key, you are subject to the terms and privacy policies of your chosen API provider, not Qwen Code's terms. Please review your provider's documentation for specific details about data usage, retention, and privacy practices.
|
|
50
|
+
|
|
51
|
+
Qwen Code supports various OpenAI-compatible providers. Please refer to your specific provider's terms of service and privacy policy for detailed information.
|
|
52
|
+
|
|
53
|
+
## Usage Statistics and Telemetry
|
|
54
|
+
|
|
55
|
+
Qwen Code may collect anonymous usage statistics and [telemetry](../../developers/development/telemetry) data to improve the user experience and product quality. This data collection is optional and can be controlled through configuration settings.
|
|
56
|
+
|
|
57
|
+
### What Data is Collected
|
|
58
|
+
|
|
59
|
+
When enabled, Qwen Code may collect:
|
|
60
|
+
|
|
61
|
+
- Anonymous usage statistics (commands run, performance metrics)
|
|
62
|
+
- Error reports and crash data
|
|
63
|
+
- Feature usage patterns
|
|
64
|
+
|
|
65
|
+
### Data Collection by Authentication Method
|
|
66
|
+
|
|
67
|
+
- **Qwen OAuth:** Usage statistics are governed by Qwen's privacy policy. You can opt-out through Qwen Code's configuration settings.
|
|
68
|
+
- **Alibaba Cloud Coding Plan:** Usage statistics are governed by Alibaba Cloud's privacy policy. You can opt-out through Qwen Code's configuration settings.
|
|
69
|
+
- **API Key:** No additional data is collected by Qwen Code beyond what your chosen API provider collects.
|
|
70
|
+
|
|
71
|
+
## Frequently Asked Questions (FAQ)
|
|
72
|
+
|
|
73
|
+
### 1. Is my code, including prompts and answers, used to train AI models?
|
|
74
|
+
|
|
75
|
+
Whether your code, including prompts and answers, is used to train AI models depends on your authentication method and the specific AI service provider you use:
|
|
76
|
+
|
|
77
|
+
- **Qwen OAuth**: Data usage is governed by [Qwen's Privacy Policy](https://qwen.ai/privacy). Please refer to their policy for specific details about data collection and model training practices.
|
|
78
|
+
|
|
79
|
+
- **Alibaba Cloud Coding Plan**: Data usage is governed by Alibaba Cloud's privacy policy. Please refer to their policy for specific details about data collection and model training practices.
|
|
80
|
+
|
|
81
|
+
- **API Key**: Data usage depends entirely on your chosen API provider. Each provider has their own data usage policies. Please review the privacy policy and terms of service of your specific provider.
|
|
82
|
+
|
|
83
|
+
**Important**: Qwen Code itself does not use your prompts, code, or responses for model training. Any data usage for training purposes would be governed by the policies of the AI service provider you authenticate with.
|
|
84
|
+
|
|
85
|
+
### 2. What are Usage Statistics and what does the opt-out control?
|
|
86
|
+
|
|
87
|
+
The **Usage Statistics** setting controls optional data collection by Qwen Code for improving the user experience and product quality.
|
|
88
|
+
|
|
89
|
+
When enabled, Qwen Code may collect:
|
|
90
|
+
|
|
91
|
+
- Anonymous telemetry (commands run, performance metrics, feature usage)
|
|
92
|
+
- Error reports and crash data
|
|
93
|
+
- General usage patterns
|
|
94
|
+
|
|
95
|
+
**What is NOT collected by Qwen Code:**
|
|
96
|
+
|
|
97
|
+
- Your code content
|
|
98
|
+
- Prompts sent to AI models
|
|
99
|
+
- Responses from AI models
|
|
100
|
+
- Personal information
|
|
101
|
+
|
|
102
|
+
The Usage Statistics setting only controls data collection by Qwen Code itself. It does not affect what data your chosen AI service provider (Qwen, OpenAI, etc.) may collect according to their own privacy policies.
|
|
103
|
+
|
|
104
|
+
### 3. How do I switch between authentication methods?
|
|
105
|
+
|
|
106
|
+
You can switch between Qwen OAuth, Alibaba Cloud Coding Plan, and your own API key at any time:
|
|
107
|
+
|
|
108
|
+
1. **During startup**: Choose your preferred authentication method when prompted
|
|
109
|
+
2. **Within the CLI**: Use the `/auth` command to reconfigure your authentication method
|
|
110
|
+
3. **Environment variables**: Set up `.env` files for automatic API key authentication
|
|
111
|
+
|
|
112
|
+
For detailed instructions, see the [Authentication Setup](../configuration/settings#environment-variables-for-api-access) documentation.
|