nexum-code 0.6.14

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 lwl
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.md ADDED
@@ -0,0 +1,322 @@
1
+ <p align="center">
2
+ <img width="108" height="108" alt="Nexum Code" src="https://github.com/user-attachments/assets/26b707fa-1fd7-4dda-8484-e8c6b0bd7523" />
3
+ </p>
4
+
5
+ <h1 align="center">Nexum Code</h1>
6
+
7
+ <p align="center">
8
+ <strong>一个真正为中文工作流设计的本地 AI Agent 工作台</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ 不只是会写代码的终端助手。Nexum Code 把目标循环、长期记忆、多 Agent 协同、MCP 扩展、后端 API 和远程聊天控制放进同一个本地运行的系统里,让 AI 可以稳定地替你执行复杂任务,也可以作为 Web 端智能体系统的底座。
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://www.npmjs.com/package/nexum-code"><img src="https://img.shields.io/npm/v/nexum-code?style=for-the-badge&logo=npm&logoColor=white&color=111827" alt="npm version"></a>
17
+ <a href="https://www.npmjs.com/package/nexum-code"><img src="https://img.shields.io/npm/dm/nexum-code?style=for-the-badge&logo=npm&logoColor=white&color=2563eb" alt="npm downloads"></a>
18
+ <a href="https://github.com/Hsssliu/nexum-code/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Hsssliu/nexum-code?style=for-the-badge&color=0f766e" alt="license"></a>
19
+ <a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node.js-%3E%3D22-16a34a?style=for-the-badge&logo=node.js&logoColor=white" alt="node version"></a>
20
+ </p>
21
+
22
+ <p align="center">
23
+ <a href="https://nexum.chat">官网</a>
24
+ ·
25
+ <a href="#快速开始">快速开始</a>
26
+ ·
27
+ <a href="#核心优势">核心优势</a>
28
+ <a href="#系统架构">系统架构</a>
29
+ ·
30
+ <a href="#web-端智能体底座">Web 智能体</a>
31
+ ·
32
+ <a href="#远程控制">远程控制</a>
33
+ </p>
34
+
35
+ ---
36
+
37
+ ## 一句话介绍
38
+
39
+ Nexum Code 是一个本地优先的 AI Agent 系统。你可以用中文或英文直接下达目标,它会读取项目、编辑文件、运行命令、调用工具、拆分任务、记录记忆,并在需要时通过审批面板保护你的机器。它也可以通过后端服务和 Node SDK 接入 Web 产品,构建网页端智能体、工作台、自动化平台或企业内部 Agent 系统。
40
+
41
+ 它适合这些场景:
42
+
43
+ - 写代码、改项目、跑测试、整理仓库
44
+ - 查资料、读文档、写报告、做研究
45
+ - 让多个子 Agent 并行处理复杂任务
46
+ - 把常用工作流沉淀成 Skill
47
+ - 接到自己的后端,做 Web 端智能体系统
48
+ - 通过微信、飞书、钉钉等聊天入口远程控制本地 Agent
49
+
50
+ ---
51
+
52
+ ## 核心优势
53
+
54
+ <table>
55
+ <tr>
56
+ <td width="50%">
57
+ <h3>目标驱动,不是空转循环</h3>
58
+ <p>Nexum Code 内置 Goal 系统。你给出目标后,它会围绕目标持续推进,并由独立裁判判断是否完成,支持轮次、Token 和时间预算。</p>
59
+ </td>
60
+ <td width="50%">
61
+ <h3>多 Agent 并行协作</h3>
62
+ <p>Wolfpack 模式可以把复杂任务拆给多个子 Agent 并行执行。探索、编码、规划、验证、写作可以分工处理,适合多文件、多步骤的大任务。</p>
63
+ </td>
64
+ </tr>
65
+ <tr>
66
+ <td width="50%">
67
+ <h3>长期记忆,不靠聊天记录硬撑</h3>
68
+ <p>记忆系统支持 SQLite、FTS5 全文检索、Tag 归类和向量检索。它能跨会话保留偏好、约定、项目经验和反复出现的痛点。</p>
69
+ </td>
70
+ <td width="50%">
71
+ <h3>本地运行,权限可控</h3>
72
+ <p>文件写入、命令执行、敏感路径访问都会经过权限策略。默认安全,必要时可切换模式,让效率和控制感都在线。</p>
73
+ </td>
74
+ </tr>
75
+ <tr>
76
+ <td width="50%">
77
+ <h3>MCP / Skill / 插件扩展</h3>
78
+ <p>你可以连接数据库、浏览器、API、代码工具,也可以把自己的流程封装成 Skill。Nexum Code 更像一个可扩展的本地 Agent 底座。</p>
79
+ </td>
80
+ <td width="50%">
81
+ <h3>可接后端和 Web 端</h3>
82
+ <p>内置服务端 API 和 Node SDK,可以把会话、子 Agent、提示、取消、模型切换、权限控制等能力接入自己的 Web 应用。</p>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td width="50%">
87
+ <h3>中文体验优先</h3>
88
+ <p>从配置、审批、提示到常用命令都围绕中文用户设计。不是把英文工具翻译一遍,而是从使用习惯上降低门槛。</p>
89
+ </td>
90
+ <td width="50%">
91
+ <h3>终端、服务端、远程入口统一</h3>
92
+ <p>同一套 Agent Core 可以跑在 TUI、后端服务和远程聊天入口后面。你可以先自己用,再把它产品化给团队使用。</p>
93
+ </td>
94
+ </tr>
95
+ </table>
96
+
97
+ ---
98
+
99
+ ## 快速开始
100
+
101
+ ### 环境要求
102
+
103
+ - Node.js >= 22.0.0
104
+ - Git
105
+ - 一个可用的模型服务,例如 DeepSeek、OpenAI、Anthropic、通义千问、硅基流动或任何 OpenAI-compatible API
106
+
107
+ ### npm 安装
108
+
109
+ ```bash
110
+ npm install -g nexum-code
111
+ ```
112
+
113
+ 安装完成后,启动 Nexum:
114
+
115
+ ```bash
116
+ nexum
117
+ ```
118
+
119
+ ### macOS / Linux 一键安装
120
+
121
+ ```bash
122
+ curl -fsSL https://raw.githubusercontent.com/Hsssliu/nexum-code/main/install.sh | bash
123
+ ```
124
+
125
+ ### Windows PowerShell 一键安装
126
+
127
+ ```powershell
128
+ irm https://raw.githubusercontent.com/Hsssliu/nexum-code/main/install.ps1 | iex
129
+ ```
130
+
131
+ 首次启动时,如果还没有配置模型,Nexum Code 会进入交互式配置向导。你也可以随时输入:
132
+
133
+ ```text
134
+ /config
135
+ ```
136
+
137
+ 配置完成后,用下面的命令切换模型:
138
+
139
+ ```text
140
+ /model
141
+ ```
142
+
143
+ ---
144
+
145
+ ## 你可以怎么用
146
+
147
+ ```text
148
+ 帮我理解这个项目的架构,并指出最重要的入口文件
149
+ ```
150
+
151
+ ```text
152
+ 修复 pnpm test 里的失败用例,改完后再跑一遍验证
153
+ ```
154
+
155
+ ```text
156
+ /goal 在不破坏现有 API 的前提下,把这套工具调用逻辑整理清楚,并补上必要测试
157
+ ```
158
+
159
+ ```text
160
+ /memory 记住:这个项目优先使用 pnpm,不要引入不必要的新依赖
161
+ ```
162
+
163
+ ```text
164
+ /wolfpack 帮我并行检查 README、安装脚本、CLI 参数和服务端 API 是否一致
165
+ ```
166
+
167
+ ---
168
+
169
+ ## 能力地图
170
+
171
+ | 能力 | Nexum Code 做什么 |
172
+ |---|---|
173
+ | 对话式执行 | 用自然语言描述任务,自动读文件、改代码、跑命令 |
174
+ | 审批面板 | 修改文件和执行命令前展示审批,降低误操作风险 |
175
+ | 权限策略 | 支持默认模式、计划模式、自动模式、YOLO 模式等 |
176
+ | Goal 循环 | 目标驱动的多轮执行,支持预算和完成度裁决 |
177
+ | 多 Agent | 子 Agent 并行处理探索、编码、验证、写作等任务 |
178
+ | 记忆系统 | 跨会话沉淀偏好、项目经验、问题记录和工作约定 |
179
+ | MCP 扩展 | 连接外部工具、数据库、浏览器、内部 API 等能力 |
180
+ | Skill 系统 | 把常用流程封装成可复用技能 |
181
+ | 后端 API | 通过服务端接口创建会话、发送提示、控制 Agent 和读取状态 |
182
+ | Node SDK | 在自己的 Node 后端里集成 Nexum Agent 能力 |
183
+ | Web 智能体 | 可作为网页端 Agent 工作台、企业自动化系统或内部 Copilot 底座 |
184
+ | 后台任务 | 支持长任务、后台命令和任务输出读取 |
185
+ | 会话恢复 | 中断后继续,支持历史记录、分叉、导出和撤销 |
186
+ | 远程聊天 | 通过 cc-connect 接入微信、飞书、钉钉、Slack 等平台 |
187
+
188
+ ---
189
+
190
+ ## 系统架构
191
+
192
+ 这个仓库是一个 TypeScript monorepo,核心模块大致如下:
193
+
194
+ ```text
195
+ aiflowy-agent/
196
+ apps/
197
+ nexum-code/ # 终端入口与 TUI
198
+ nexum-agent-server/ # Agent 服务入口
199
+ packages/
200
+ agent-core/ # Agent 循环、工具、权限、会话、MCP、LSP
201
+ node-sdk/ # Node SDK 与 RPC 客户端
202
+ nexum-server/ # HTTP API 与会话控制
203
+ memory/ # 长期记忆、检索、整理
204
+ ltod/ # 模型与工具调用抽象
205
+ jian/ # 本地运行时能力封装
206
+ config/ # 共享配置与身份信息
207
+ ```
208
+
209
+ 关键设计思路:
210
+
211
+ - `agent-core` 负责 Agent 的大脑,包括工具注册、权限评估、执行循环、子 Agent 和会话状态。
212
+ - `nexum-code` 负责终端用户体验,包括命令、审批面板、消息渲染和交互状态。
213
+ - `nexum-server` 和 `node-sdk` 让 Nexum 不只存在于终端,也能被后端服务、Web 应用、桌面端或其他客户端驱动。
214
+ - `memory` 独立成包,避免记忆能力被某一次会话绑定,方便跨项目和跨场景复用。
215
+
216
+ ---
217
+
218
+ ## Web 端智能体底座
219
+
220
+ Nexum Code 不是只能在终端里跑。它的核心能力已经拆成可复用的服务端和 SDK 层,适合接入自己的产品后端。
221
+
222
+ 你可以用它构建:
223
+
224
+ - Web 端 AI 编程助手
225
+ - 企业内部 Agent 工作台
226
+ - 自动化任务执行平台
227
+ - 多 Agent 协作系统
228
+ - 带记忆、权限和会话恢复的私有 Copilot
229
+
230
+ 后端可以围绕这些能力组织业务:
231
+
232
+ | 能力 | 适合做成什么产品功能 |
233
+ |---|---|
234
+ | Session API | 创建会话、恢复会话、分叉会话、导出会话 |
235
+ | Agent API | 发送任务、取消任务、切换模型、调整思考和权限模式 |
236
+ | Subagent Host | 在 Web 端展示多个子 Agent 的并行执行状态 |
237
+ | Permission System | 做企业级审批、敏感操作拦截和审计记录 |
238
+ | Memory Store | 做用户偏好、项目知识库和跨会话上下文 |
239
+ | MCP / Skill | 给 Web 产品接入数据库、浏览器、内部系统和自定义流程 |
240
+
241
+ 这意味着 Nexum Code 可以从“一个本地工具”升级成“你的 Agent 产品底座”:前端负责交互,后端负责业务权限和数据,Nexum 负责智能体执行、工具调度、记忆和多 Agent 编排。
242
+
243
+ ---
244
+
245
+ ## 常用命令
246
+
247
+ | 命令 | 说明 |
248
+ |---|---|
249
+ | `/config` | 配置模型服务 |
250
+ | `/model` | 切换或管理模型 |
251
+ | `/memory` | 打开记忆管理 |
252
+ | `/dream` | 整理重复或过期记忆 |
253
+ | `/goal` | 开启目标循环 |
254
+ | `/wolfpack` | 开启多 Agent 协作 |
255
+ | `/cc-connect` | 配置聊天平台远程控制 |
256
+ | `/mode` | 查看或切换权限模式 |
257
+
258
+ 开发仓库时常用:
259
+
260
+ ```bash
261
+ pnpm install
262
+ pnpm run dev:cli
263
+ pnpm run typecheck
264
+ pnpm run lint
265
+ pnpm run test
266
+ pnpm run build
267
+ ```
268
+
269
+ ---
270
+
271
+ ## 远程控制
272
+
273
+ Nexum Code 可以通过 `cc-connect` 接入聊天平台。配置后,即使终端不在眼前,也能在聊天窗口里创建会话、发送任务、上传文件和切换模式。
274
+
275
+ ```bash
276
+ npm install -g cc-connect
277
+ ```
278
+
279
+ 在 Nexum Code 中启动配置:
280
+
281
+ ```text
282
+ /cc-connect
283
+ ```
284
+
285
+ 常用远程指令:
286
+
287
+ | 指令 | 用途 |
288
+ |---|---|
289
+ | `/new` | 创建新会话 |
290
+ | `/bind setup` | 开启文件传送,支持图片、PDF 等 |
291
+ | `/mode` | 查看可用模式 |
292
+ | `/mode yolo` | 自动批准所有工具调用 |
293
+ | `/mode default` | 每次工具调用前询问 |
294
+
295
+ ---
296
+
297
+ ## 为什么做 Nexum Code
298
+
299
+ 我想要的不是一个只会补全代码的工具,而是一个能长期陪我处理真实工作流的本地 Agent:
300
+
301
+ - 它要能记住项目里的约定,而不是每次从零开始。
302
+ - 它要能拆任务、分工、验证,而不是只会单线程聊天。
303
+ - 它要能接入我已有的工具和聊天入口,而不是把我锁在一个界面里。
304
+ - 它要尊重本地机器的安全边界,而不是为了方便牺牲控制权。
305
+
306
+ 所以 Nexum Code 选择了 TypeScript monorepo、本地优先、权限策略、长期记忆、多 Agent 和可扩展工具系统这条路线。它不是功能堆叠,而是把高频 Agent 工作流收敛成一个稳定的底座。
307
+
308
+ ---
309
+
310
+ ## 项目链接
311
+
312
+ - 官网:https://nexum.chat
313
+ - npm:https://www.npmjs.com/package/nexum-code
314
+ - 许可证:[MIT](LICENSE)
315
+
316
+ ---
317
+
318
+ <p align="center">
319
+ <strong>Nexum Code</strong>
320
+ <br />
321
+ Local first. Agent native. Built for real workflows.
322
+ </p>
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
3
+ import { dirname as __cjsShimDirname } from 'node:path';
4
+ const __filename = __cjsShimFileURLToPath(import.meta.url);
5
+ const __dirname = __cjsShimDirname(__filename);
6
+ //#region src/utils/aiflowy-bot-sync.ts
7
+ function resolveAiflowyBotSyncConfig(env = process.env) {
8
+ const apiUrl = (env.NEXUM_AIFLOWY_API_URL ?? env.AIFLOWY_API_URL)?.trim();
9
+ const token = (env.NEXUM_AIFLOWY_TOKEN ?? env.AIFLOWY_TOKEN)?.trim();
10
+ if (apiUrl === void 0 || apiUrl.length === 0 || token === void 0 || token.length === 0) return null;
11
+ return {
12
+ apiUrl: apiUrl.replace(/\/+$/, ""),
13
+ token
14
+ };
15
+ }
16
+ async function syncAiflowyBotModel(options) {
17
+ return postAiflowyBotConfig({
18
+ botId: options.botId,
19
+ path: "/api/v1/nexum/bot-config/model",
20
+ body: { model: options.model },
21
+ env: options.env,
22
+ fetchImpl: options.fetchImpl
23
+ });
24
+ }
25
+ async function syncAiflowyBotConfigPatch(options) {
26
+ return postAiflowyBotConfig({
27
+ botId: options.botId,
28
+ path: "/api/v1/nexum/bot-config/patch",
29
+ body: { config: options.config },
30
+ env: options.env,
31
+ fetchImpl: options.fetchImpl
32
+ });
33
+ }
34
+ async function syncAiflowyBotSkill(options) {
35
+ return postAiflowyBotConfig({
36
+ botId: options.botId,
37
+ path: `/api/v1/nexum/bot-config/skill/${options.action}`,
38
+ body: { skill: options.skill },
39
+ env: options.env,
40
+ fetchImpl: options.fetchImpl
41
+ });
42
+ }
43
+ async function postAiflowyBotConfig(options) {
44
+ const botId = options.botId?.trim();
45
+ if (botId === void 0 || botId.length === 0) return {
46
+ status: "skipped",
47
+ reason: "missing_bot_id"
48
+ };
49
+ const config = resolveAiflowyBotSyncConfig(options.env ?? process.env);
50
+ if (config === null) return {
51
+ status: "skipped",
52
+ reason: "missing_config"
53
+ };
54
+ const response = await (options.fetchImpl ?? fetch)(`${config.apiUrl}${options.path}`, {
55
+ method: "POST",
56
+ headers: aiflowyHeaders(config.token),
57
+ body: JSON.stringify({
58
+ botId,
59
+ ...options.body
60
+ })
61
+ });
62
+ const payload = await parseAiflowyResponse(response);
63
+ if (!response.ok) throw new Error(`HTTP ${response.status}${formatSyncPayloadMessage(payload)}`);
64
+ if (isAiflowyFailure(payload)) throw new Error(formatSyncPayloadMessage(payload).replace(/^: /, "") || "AIFlowy sync failed");
65
+ return { status: "synced" };
66
+ }
67
+ function aiflowyHeaders(token) {
68
+ return {
69
+ "Content-Type": "application/json",
70
+ "aiflowy-token": token,
71
+ satoken: token
72
+ };
73
+ }
74
+ async function parseAiflowyResponse(response) {
75
+ const responseText = await response.text();
76
+ if (responseText.trim().length === 0) return null;
77
+ try {
78
+ return JSON.parse(responseText);
79
+ } catch {
80
+ return responseText;
81
+ }
82
+ }
83
+ function isAiflowyFailure(payload) {
84
+ return typeof payload === "object" && payload !== null && "errorCode" in payload && typeof payload.errorCode === "number" && payload.errorCode !== 0;
85
+ }
86
+ function formatSyncPayloadMessage(payload) {
87
+ if (typeof payload === "object" && payload !== null && "message" in payload) {
88
+ const message = payload.message;
89
+ if (typeof message === "string" && message.trim().length > 0) return `: ${message}`;
90
+ }
91
+ if (typeof payload === "string" && payload.trim().length > 0) return `: ${payload}`;
92
+ return "";
93
+ }
94
+ async function fetchAiflowyBotList(options = {}) {
95
+ const config = resolveAiflowyBotSyncConfig(options.env ?? process.env);
96
+ if (config === null) throw new Error("未配置 AIFlowy API(NEXUM_AIFLOWY_API_URL / NEXUM_AIFLOWY_TOKEN)。");
97
+ const agentEngine = options.agentEngine ?? "nexum";
98
+ const fetchImpl = options.fetchImpl ?? fetch;
99
+ try {
100
+ const response = await fetchImpl(`${config.apiUrl}/api/v1/bot/list?agentEngine=${encodeURIComponent(agentEngine)}`, {
101
+ method: "GET",
102
+ headers: aiflowyHeaders(config.token)
103
+ });
104
+ const payload = await parseAiflowyResponse(response);
105
+ if (!response.ok) throw new Error(`HTTP ${response.status}${formatSyncPayloadMessage(payload)}`);
106
+ const bots = normalizeBotList(payload);
107
+ if (bots !== null) return bots;
108
+ } catch (error) {
109
+ if (error instanceof Error && error.message.includes("未配置")) throw error;
110
+ }
111
+ const pageResponse = await fetchImpl(`${config.apiUrl}/api/v1/bot/page?page=1&size=100&agentEngine=${encodeURIComponent(agentEngine)}`, {
112
+ method: "GET",
113
+ headers: aiflowyHeaders(config.token)
114
+ });
115
+ const pagePayload = await parseAiflowyResponse(pageResponse);
116
+ if (!pageResponse.ok) throw new Error(`HTTP ${pageResponse.status}${formatSyncPayloadMessage(pagePayload)}`);
117
+ return normalizeBotList(pagePayload) ?? [];
118
+ }
119
+ function normalizeBotList(payload) {
120
+ if (!Array.isArray(payload)) {
121
+ if (typeof payload === "object" && payload !== null) {
122
+ const record = payload;
123
+ const data = record["data"];
124
+ if (Array.isArray(data)) return normalizeBotList(data);
125
+ if (typeof data === "object" && data !== null) {
126
+ const records = data["records"];
127
+ if (Array.isArray(records)) return normalizeBotList(records);
128
+ }
129
+ const records = record["records"];
130
+ if (Array.isArray(records)) return normalizeBotList(records);
131
+ }
132
+ return null;
133
+ }
134
+ return payload.map((item) => {
135
+ if (typeof item !== "object" || item === null) return null;
136
+ const record = item;
137
+ const id = String(record["id"] ?? "");
138
+ const title = String(record["title"] ?? "");
139
+ if (id.length === 0 || title.length === 0) return null;
140
+ return {
141
+ id,
142
+ title,
143
+ description: optionalString(record["description"]),
144
+ alias: optionalString(record["alias"]),
145
+ agentEngine: optionalString(record["agentEngine"])
146
+ };
147
+ }).filter((item) => item !== null);
148
+ }
149
+ async function fetchAiflowyBotDetail(options) {
150
+ const config = resolveAiflowyBotSyncConfig(options.env ?? process.env);
151
+ if (config === null) throw new Error("未配置 AIFlowy API(NEXUM_AIFLOWY_API_URL / NEXUM_AIFLOWY_TOKEN)。");
152
+ const response = await (options.fetchImpl ?? fetch)(`${config.apiUrl}/api/v1/bot/detail?id=${encodeURIComponent(options.botId)}`, {
153
+ method: "GET",
154
+ headers: aiflowyHeaders(config.token)
155
+ });
156
+ const payload = await parseAiflowyResponse(response);
157
+ if (!response.ok) throw new Error(`HTTP ${response.status}${formatSyncPayloadMessage(payload)}`);
158
+ if (isAiflowyFailure(payload)) throw new Error(formatSyncPayloadMessage(payload).replace(/^: /, "") || "AIFlowy bot detail failed");
159
+ const detail = unwrapData(payload) ?? payload;
160
+ if (typeof detail !== "object" || detail === null) throw new Error("AIFlowy bot detail returned unexpected payload");
161
+ return detail;
162
+ }
163
+ function unwrapData(payload) {
164
+ if (typeof payload !== "object" || payload === null) return payload;
165
+ const data = payload["data"];
166
+ return data !== void 0 ? data : payload;
167
+ }
168
+ function optionalString(value) {
169
+ if (typeof value === "string" && value.length > 0) return value;
170
+ }
171
+ async function createAiflowyBot(options) {
172
+ const config = resolveAiflowyBotSyncConfig(options.env ?? process.env);
173
+ if (config === null) throw new Error("未配置 AIFlowy API(NEXUM_AIFLOWY_API_URL / NEXUM_AIFLOWY_TOKEN)。");
174
+ const fetchImpl = options.fetchImpl ?? fetch;
175
+ const body = {
176
+ title: options.title,
177
+ agentEngine: options.agentEngine ?? "nexum"
178
+ };
179
+ if (options.alias !== void 0) body["alias"] = options.alias;
180
+ if (options.description !== void 0) body["description"] = options.description;
181
+ if (options.nexumConfig !== void 0) body["nexumConfig"] = options.nexumConfig;
182
+ const response = await fetchImpl(`${config.apiUrl}/api/v1/bot/save`, {
183
+ method: "POST",
184
+ headers: aiflowyHeaders(config.token),
185
+ body: JSON.stringify(body)
186
+ });
187
+ const payload = await parseAiflowyResponse(response);
188
+ if (!response.ok) throw new Error(`HTTP ${response.status}${formatSyncPayloadMessage(payload)}`);
189
+ if (isAiflowyFailure(payload)) throw new Error(formatSyncPayloadMessage(payload).replace(/^: /, "") || "AIFlowy bot creation failed");
190
+ const detail = unwrapData(payload) ?? payload;
191
+ if (typeof detail !== "object" || detail === null) throw new Error("AIFlowy bot creation returned unexpected payload");
192
+ return detail;
193
+ }
194
+ async function updateAiflowyBot(options) {
195
+ const config = resolveAiflowyBotSyncConfig(options.env ?? process.env);
196
+ if (config === null) throw new Error("未配置 AIFlowy API(NEXUM_AIFLOWY_API_URL / NEXUM_AIFLOWY_TOKEN)。");
197
+ const fetchImpl = options.fetchImpl ?? fetch;
198
+ const body = { id: options.botId };
199
+ if (options.title !== void 0) body["title"] = options.title;
200
+ if (options.alias !== void 0) body["alias"] = options.alias;
201
+ if (options.description !== void 0) body["description"] = options.description;
202
+ if (options.agentEngine !== void 0) body["agentEngine"] = options.agentEngine;
203
+ if (options.nexumConfig !== void 0) body["nexumConfig"] = options.nexumConfig;
204
+ const response = await fetchImpl(`${config.apiUrl}/api/v1/bot/update`, {
205
+ method: "POST",
206
+ headers: aiflowyHeaders(config.token),
207
+ body: JSON.stringify(body)
208
+ });
209
+ const payload = await parseAiflowyResponse(response);
210
+ if (!response.ok) throw new Error(`HTTP ${response.status}${formatSyncPayloadMessage(payload)}`);
211
+ if (isAiflowyFailure(payload)) throw new Error(formatSyncPayloadMessage(payload).replace(/^: /, "") || "AIFlowy bot update failed");
212
+ const detail = unwrapData(payload) ?? payload;
213
+ if (typeof detail !== "object" || detail === null) throw new Error("AIFlowy bot update returned unexpected payload");
214
+ return detail;
215
+ }
216
+ /** Alias exported for callers that prefer the Nexum-centric name. */
217
+ const patchNexumBotConfig = syncAiflowyBotConfigPatch;
218
+ //#endregion
219
+ export { resolveAiflowyBotSyncConfig as a, syncAiflowyBotSkill as c, patchNexumBotConfig as i, updateAiflowyBot as l, fetchAiflowyBotDetail as n, syncAiflowyBotConfigPatch as o, fetchAiflowyBotList as r, syncAiflowyBotModel as s, createAiflowyBot as t };
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
3
+ import { dirname as __cjsShimDirname } from 'node:path';
4
+ const __filename = __cjsShimFileURLToPath(import.meta.url);
5
+ const __dirname = __cjsShimDirname(__filename);
6
+ import { l as updateAiflowyBot } from "./aiflowy-bot-sync-BMV5Lg3y.mjs";
7
+ export { updateAiflowyBot };