Commit graph

44 commits

Author SHA1 Message Date
chinesepowered
ed6f9e056e
fix(sdk): settle pending next() promise in Stream.return() to prevent hangs (#2981)
* fix(sdk): settle pending next() promise in Stream.return() to prevent hangs

* test(sdk): add regression tests for Stream.return() pending-promise cleanup
2026-04-18 09:46:56 +08:00
Reid
d439e7d738
fix(sdk): avoid leaking process exit listeners in ProcessTransport (#3295)
* fix(sdk): avoid leaking process exit listeners in ProcessTransport

* Strengthen ProcessTransport cleanup during process exit.

  This updates the shared process-exit cleanup path to use a best-effort
  SIGTERM/SIGKILL sequence and adds coverage to verify the global exit
  handler terminates all active child processes.

  It keeps the listener leak fix in place while closing the remaining gaps
  found in review.
2026-04-16 10:52:19 +08:00
Shaojin Wen
1486e85385
feat(cli/sdk): expose /context usage data in non-interactive mode and SDK API (#2916)
Some checks are pending
Qwen Code CI / Post Coverage Comment (push) Blocked by required conditions
Qwen Code CI / Lint (push) Waiting to run
Qwen Code CI / Test (push) Blocked by required conditions
Qwen Code CI / Test-1 (push) Blocked by required conditions
Qwen Code CI / Test-2 (push) Blocked by required conditions
Qwen Code CI / Test-3 (push) Blocked by required conditions
Qwen Code CI / Test-4 (push) Blocked by required conditions
Qwen Code CI / Test-5 (push) Blocked by required conditions
Qwen Code CI / Test-6 (push) Blocked by required conditions
Qwen Code CI / Test-7 (push) Blocked by required conditions
Qwen Code CI / Test-8 (push) Blocked by required conditions
Qwen Code CI / CodeQL (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run
* feat(cli): implement non-interactive /context output and diagnostic

- Extract collectContextData() from contextCommand.ts for shared usage.
- Register /context in ALLOWED_BUILTIN_COMMANDS_NON_INTERACTIVE.
- Extend SDK control protocol with GET_CONTEXT_USAGE request.
- Implement handleGetContextUsage in SystemController for programmatic token queries.
- Expose getContextUsage() method in the TypeScript SDK Query interface.

* fix: address review feedback and fix critical bugs in context usage feature

- Add missing `get_context_usage` route in ControlDispatcher (SDK calls would throw)
- Fix `executionMode` defaulting: use `?? 'interactive'` to match other commands
- Validate dynamic import of `collectContextData` before invoking
- Preserve original error message in handleGetContextUsage catch block
- Add ControlDispatcher test for get_context_usage routing
- Add JSDoc comment for context command in non-interactive allowlist

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: re-check abort signal after async operations in handleGetContextUsage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add getContextUsage() to SDK TypeScript documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: clarify getContextUsage showDetails is a display hint, not a data filter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: make showDetails affect response shape, add getContextUsage test

- When showDetails is false, return empty detail arrays instead of full
  data so /context and /context detail produce different payloads
- Add unit test for Query.getContextUsage() covering request payload
  and response handling

* fix: strip UI type from SDK response, sync Java SDK protocol

- Remove leaked `type: 'context_usage'` from control response payload
- Add GET_CONTEXT_USAGE to Java SDK protocol mirror (enum, interface,
  union type)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 03:28:32 +08:00
tanzhenxin
5d58b2f112 feat: simplify subagent model configuration with model selector
Refactor subagent model configuration from nested modelConfig object to a simple model string field for better UX and clarity.

Changes:
- Replace modelConfig object with model string in SubagentConfig interface
- Add model-selection.ts utility for parsing and validating model selectors
- Support 'inherit' keyword and bare model IDs (e.g., 'glm-5', 'claude-sonnet-4-6')
- Maintain backward compatibility by parsing legacy modelConfig frontmatter
- Update validation to reject cross-provider authType-prefixed selectors
- Update SDK types (TypeScript and Java) to reflect new schema
- Add comprehensive tests for model selection and validation
- Update documentation with model selection examples

Breaking changes:
- modelConfig.frontmatter field deprecated in favor of model field
- Cross-provider model selectors (e.g., 'openai:gpt-4') not supported for subagents

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 11:49:45 +08:00
DragonnZhang
ee33a3c35e feat: add system prompt customization options in SDK and CLI 2026-03-16 02:57:31 +08:00
mingholy.lmh
82dc79629c feat: enhance session ID handling and error propagation 2026-02-13 21:41:38 +08:00
mingholy.lmh
5d939fdb83 feat: add --session-id support for CLI and SDK
- Add --session-id flag to CLI for specifying custom session ID
- Add sessionId option to SDK QueryOptions
- Implement UUID validation for session IDs
- Pass session ID from SDK to CLI via --session-id argument
- Add integration tests for session-id functionality
- Update unit tests for ProcessTransport

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-13 21:40:57 +08:00
LaZzyMan
3f04217458 fix: prevent AbortSignal listener memory leak
- Add abort listener cleanup in Query.close() to prevent memory leak
- Add abort listener cleanup in ControlDispatcher.shutdown()
- Remove AbortController recreation in Session.handleInterrupt()

This fixes the MaxListenersExceededWarning that occurred when:
- Creating 11+ Query instances in SDK/non-interactive mode
- Multiple user interrupts (Ctrl+C) in interactive mode
- Intensive control request scenarios
2026-02-12 10:39:19 +08:00
tanzhenxin
a4ffc6eb24 feat: promote Agent Skills from experimental to stable
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-06 13:04:08 +08:00
tanzhenxin
7d50f5363f
Merge pull request #1726 from QwenLM/mingholy/fix/sdk-resume-usage
feat(sdk): add resume, continue options and extend authType support
2026-02-05 19:03:25 +08:00
tanzhenxin
03b2cfbbde
Merge pull request #1719 from QwenLM/mingholy/fix/patch-process-transport-for-electron
Add FORK_MODE support to ProcessTransport for Electron IPC integration
2026-02-05 19:02:30 +08:00
mingholy.lmh
675a8fd058 feat(sdk): add resume, continue options and extend authType support
- Add 'resume' and 'continue' options to TransportOptions for session restoration
- Extend authType to support all CLI authentication types:
  - use_openai, use_anthropic, qwen_oauth, use_gemini, use_vertex_ai
- Update type definitions and validation schemas accordingly

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-05 17:53:03 +08:00
mingholy.lmh
ed3ffe2aa2 fix(sdk): improve FORK_MODE to support bun and fallback to spawn for native type
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-05 17:39:12 +08:00
Mingholy
2d75d82ec8 feat(sdk): add FORK_MODE support for Electron integration
- Rename USE_FORK_FOR_ELECTRON to FORK_MODE
- Add fork mode in ProcessTransport for Electron IPC support
- Add comprehensive unit tests for fork mode

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-04 23:14:26 +08:00
DragonnZhang
417007d243 feat(query): add support for resuming sessions with session ID 2026-02-04 14:53:22 +08:00
mingholy.lmh
b05de7a187 test: improve sdk integration tests 2026-01-27 17:10:36 +08:00
mingholy.lmh
f578ff07a2 fix: cli input stream handling and error management, improve e2e and unit tests 2026-01-23 13:56:38 +08:00
mingholy.lmh
64291db926 fix: misc issues in qwen-oauth models, sdk cli path resolving.
1. remove `generationConfig`` of qwen-oauth models
2. fix esm issues when sdk trying to spawn cli
2026-01-13 17:19:15 +08:00
mingholy.lmh
9670456a56 fix: simplify JavaScript runtime detection to fix powershell spawning process issue 2026-01-12 13:42:24 +08:00
mingholy.lmh
7d40e1470c chore: add CODEOWNERS for SDK TypeScript package and remove legacy CLI path alias 2026-01-11 21:24:45 +08:00
mingholy.lmh
8705f734d0 fix: improve bundled CLI path finding and support --experimental-skills 2026-01-09 16:32:55 +08:00
mingholy.lmh
8c109be48c refactor: unified allow list of supported commands in ACP or non-interactive mode 2025-12-26 17:55:03 +08:00
Mingholy
add35d2904
Merge pull request #1321 from QwenLM/mingholy/fix/sdk-cli-path
fix: cli path parsing issue in Windows
2025-12-24 10:35:52 +08:00
mingholy.lmh
4f970c9987 fix: cli path parsing issue in Windows 2025-12-23 19:00:43 +08:00
tanzhenxin
fefc138485 Merge branch 'main' into feat/gemini-3-integration 2025-12-22 10:08:15 +08:00
tanzhenxin
17129024f4 Add Gemini provider, remove legacy Google OAuth, and tune generation defaults 2025-12-19 16:26:54 +08:00
mingholy.lmh
fa7d857945 fix: remove unused cli finding code 2025-12-19 16:18:22 +08:00
mingholy.lmh
156134d3d4 chore(sdk): bundle CLI into SDK package and inherit the dependencies 2025-12-19 15:44:04 +08:00
DragonnZhang
60a58ad8e5 feat: add support for the channel field to CLI parameters and configurations 2025-12-12 01:06:00 +08:00
mingholy.lmh
bf6abf7752 fix: update timeout settings and default logging level in SDK 2025-12-06 12:27:16 +08:00
mingholy.lmh
96d458fa8c chore: rename @qwen-code/sdk-typescript to @qwen-code/sdk 2025-12-05 21:47:26 +08:00
mingholy.lmh
c218048551 fix: prevent sending control request when query is closed 2025-12-05 18:46:51 +08:00
mingholy.lmh
322ce80e2c feat: implement SDK MCP server support and enhance control request handling
- Added new `SdkMcpController` to manage communication between CLI MCP clients and SDK MCP servers.
- Introduced `createSdkMcpServer` function for creating SDK-embedded MCP servers.
- Updated configuration options to support both external and SDK MCP servers.
- Enhanced timeout settings for various SDK operations, including MCP requests.
- Refactored existing control request handling to accommodate new SDK MCP server functionality.
- Updated tests to cover new SDK MCP server features and ensure proper integration.
2025-12-05 13:14:54 +08:00
mingholy.lmh
3056f8a63d feat(tests): move SDK integration tests to integration-tests to share globalSetup 2025-12-04 17:10:23 +08:00
mingholy.lmh
8035be6f8d fix: plan mode adjustments 2025-12-04 17:10:22 +08:00
mingholy.lmh
249b141f19 feat: add allowedTools for SDK use and re-organize test setup 2025-12-04 17:10:22 +08:00
mingholy.lmh
56957a687b refactor: rename ambiguous exported types 2025-12-04 17:10:21 +08:00
mingholy.lmh
638b7bb466 feat: add allowedTools support 2025-12-04 17:10:21 +08:00
mingholy.lmh
769a438fa4 feat: enhance logging capabilities and update query options in sdk-typescript
- Introduced a new logging system with adjustable log levels (debug, info, warn, error).
- Updated query options to include a logLevel parameter for controlling verbosity.
- Refactored existing code to utilize the new logging system for better error handling and debugging.
- Cleaned up unused code and improved the structure of the SDK.
2025-12-04 17:10:20 +08:00
mingholy.lmh
49dc84ac0e feat: add support for includePartialMessages option in query and transport layers 2025-12-04 17:10:20 +08:00
mingholy.lmh
ac6aecb622 refactor: update test structure and clean up unused code in cli and sdk 2025-12-04 17:10:20 +08:00
mingholy.lmh
ad9ba914e1 refactor: clean up exports in sdk-typescript index file 2025-12-04 17:10:20 +08:00
mingholy.lmh
d76cdf1076 feat: sdk subagent support 2025-12-04 17:10:20 +08:00
mingholy.lmh
e1ffaec499 feat: create draft framework for cli & sdk 2025-12-04 17:10:16 +08:00