@x-code-cli/core 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Guangzhi Tan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,15 @@
1
+ # @x-code-cli/core
2
+
3
+ [简体中文](./README.md) · [English](./README.en.md)
4
+
5
+ Core AI engine powering [X-Code CLI](https://github.com/woai3c/x-code-cli).
6
+
7
+ This package is the headless runtime consumed by `@x-code-cli/cli` — agent loop, tools, provider registry, and permission system. It has **no UI dependencies** and can in principle be embedded in other tools.
8
+
9
+ > ⚠️ The public API is not yet stable — breaking changes may happen between minor versions. If you just want the CLI, install [`@x-code-cli/cli`](https://www.npmjs.com/package/@x-code-cli/cli) directly.
10
+
11
+ For full installation, API key setup, and usage, see the [main repo README](https://github.com/woai3c/x-code-cli).
12
+
13
+ ## License
14
+
15
+ [MIT](https://github.com/woai3c/x-code-cli/blob/main/LICENSE)
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @x-code-cli/core
2
+
3
+ [简体中文](./README.md) · [English](./README.en.md)
4
+
5
+ [X-Code CLI](https://github.com/woai3c/x-code-cli) 的核心 AI 引擎。
6
+
7
+ 本包是 `@x-code-cli/cli` 使用的无头(headless)运行时,包含 Agent 循环、工具、模型厂商适配、权限系统等逻辑,**不依赖任何 UI 框架**,理论上可以嵌入到其他工具中使用。
8
+
9
+ > ⚠️ 公共 API 尚未稳定,小版本之间可能会有破坏性变更。如果你只是想使用 CLI,请直接安装 [`@x-code-cli/cli`](https://www.npmjs.com/package/@x-code-cli/cli)。
10
+
11
+ 完整的安装说明、API Key 配置、使用方式请看 [主仓库 README](https://github.com/woai3c/x-code-cli)。
12
+
13
+ ## License
14
+
15
+ [MIT](https://github.com/woai3c/x-code-cli/blob/main/LICENSE)
@@ -2,7 +2,7 @@
2
2
  import { zhipu } from 'zhipu-ai-provider';
3
3
  import { createAlibaba } from '@ai-sdk/alibaba';
4
4
  import { anthropic } from '@ai-sdk/anthropic';
5
- import { deepseek } from '@ai-sdk/deepseek';
5
+ import { createDeepSeek } from '@ai-sdk/deepseek';
6
6
  import { google } from '@ai-sdk/google';
7
7
  import { moonshotai } from '@ai-sdk/moonshotai';
8
8
  import { createOpenAI } from '@ai-sdk/openai';
@@ -23,7 +23,7 @@ export function createModelRegistry() {
23
23
  if (opts.xai)
24
24
  providers.xai = xai;
25
25
  if (opts.deepseek)
26
- providers.deepseek = deepseek;
26
+ providers.deepseek = createDeepSeek({ fetch: deepseekReasoningFetch });
27
27
  if (opts.alibaba) {
28
28
  providers.alibaba = createAlibaba({
29
29
  baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
@@ -43,4 +43,34 @@ export function createModelRegistry() {
43
43
  }
44
44
  return createProviderRegistry(providers);
45
45
  }
46
+ /**
47
+ * Back-fill `reasoning_content: ""` on every assistant message in the request
48
+ * body before it reaches DeepSeek V4. The upstream `@ai-sdk/deepseek` converter
49
+ * (convert-to-deepseek-chat-messages.ts) strips `reasoning_content` from any
50
+ * assistant message at or before the last user message — correct for
51
+ * deepseek-reasoner (R1), which forbids passing reasoning back, but wrong for
52
+ * deepseek-v4-*, which *requires* it. Without this, the second turn 400s with
53
+ * "reasoning_content in the thinking mode must be passed back to the API."
54
+ * Scoped to v4 so R1 keeps its documented behavior. Remove once upstream
55
+ * differentiates by model.
56
+ */
57
+ const deepseekReasoningFetch = async (input, init) => {
58
+ if (!init?.body || typeof init.body !== 'string')
59
+ return fetch(input, init);
60
+ try {
61
+ const body = JSON.parse(init.body);
62
+ if (typeof body.model === 'string' && body.model.includes('deepseek-v4') && Array.isArray(body.messages)) {
63
+ for (const msg of body.messages) {
64
+ if (msg.role === 'assistant' && msg.reasoning_content == null) {
65
+ msg.reasoning_content = '';
66
+ }
67
+ }
68
+ return fetch(input, { ...init, body: JSON.stringify(body) });
69
+ }
70
+ }
71
+ catch {
72
+ // Body wasn't JSON we recognize — pass through unchanged.
73
+ }
74
+ return fetch(input, init);
75
+ };
46
76
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/providers/registry.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C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AAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChC,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;oBAC9D,GAAG,CAAC,iBAAiB,GAAG,EAAE,CAAA;gBAC5B,CAAC;YACH,CAAC;YACD,OAAO,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC9D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0DAA0D;IAC5D,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC3B,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-code-cli/core",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/woai3c/x-code-cli",
@@ -19,10 +19,6 @@
19
19
  "engines": {
20
20
  "node": ">=20.19.0"
21
21
  },
22
- "scripts": {
23
- "build": "tsc -b",
24
- "dev": "tsc -b --watch"
25
- },
26
22
  "dependencies": {
27
23
  "ai": "^6.0.0",
28
24
  "@ai-sdk/anthropic": "^3.0.0",
@@ -43,5 +39,9 @@
43
39
  "turndown": "^7.2.0",
44
40
  "diff": "^8.0.0",
45
41
  "chalk": "^5.4.0"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc -b",
45
+ "dev": "tsc -b --watch"
46
46
  }
47
- }
47
+ }