Merged
add cannbot-dsh #271
sundayAdd on 27 days ago
add cannbot-dsh #271
Merged
Merged fromzhou-qilong/cannbotdshintocann/cannbotmaster
Total: 117 files changed+6970-19
| @@ -28,6 +28,7 @@ | |||
| 28 | <filefilter name="defaultPolicyFilter" desc="Filters for compatibility and license header policies"> | 28 | <filefilter name="defaultPolicyFilter" desc="Filters for compatibility and license header policies"> |
| 29 | <filteritem type="filepath" name="plugins-official/tilelang-op-orchestrator/README.OpenSource" desc="Third-party component register in JSON; a comment header would invalidate the format."/> | 29 | <filteritem type="filepath" name="plugins-official/tilelang-op-orchestrator/README.OpenSource" desc="Third-party component register in JSON; a comment header would invalidate the format."/> |
| 30 | <filteritem type="filepath" name="script/.*" desc="The npm installer is distributed under the MIT License in script/LICENSE"/> | 30 | <filteritem type="filepath" name="script/.*" desc="The npm installer is distributed under the MIT License in script/LICENSE"/> |
| 31 | + <filteritem type="filepath" name="dsh/packages/install/.*" desc="The standalone DSH one-click installer package is distributed under the MIT License in dsh/packages/install/LICENSE, matching the script/ npm installer."/> | ||
| 31 | <filteritem type="filename" name="*.golden" desc="Test oracle fixtures, headers would break comparisons"/> | 32 | <filteritem type="filename" name="*.golden" desc="Test oracle fixtures, headers would break comparisons"/> |
| 32 | <filteritem type="filename" name="*.jsonl" desc="JSON Lines data files, cannot carry license header"/> | 33 | <filteritem type="filename" name="*.jsonl" desc="JSON Lines data files, cannot carry license header"/> |
| 33 | <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no license header required"/> | 34 | <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no license header required"/> |
| @@ -58,6 +59,7 @@ | |||
| 58 | <filteritem type="filepath" name="plugins-official/tilelang-op-orchestrator/README.OpenSource" desc="Third-party component register in JSON; a comment header would invalidate the format."/> | 59 | <filteritem type="filepath" name="plugins-official/tilelang-op-orchestrator/README.OpenSource" desc="Third-party component register in JSON; a comment header would invalidate the format."/> |
| 59 | <filteritem type="filepath" name="plugins-official/tilelang-op-orchestrator/workflows/Ascend950/LICENSE" desc="The original MIT license text is checked by the explicit TileLang MIT policy, rather than the default CANN-2.0 header policy."/> | 60 | <filteritem type="filepath" name="plugins-official/tilelang-op-orchestrator/workflows/Ascend950/LICENSE" desc="The original MIT license text is checked by the explicit TileLang MIT policy, rather than the default CANN-2.0 header policy."/> |
| 60 | <filteritem type="filepath" name="script/.*" desc="The npm installer is distributed under the MIT License in script/LICENSE."/> | 61 | <filteritem type="filepath" name="script/.*" desc="The npm installer is distributed under the MIT License in script/LICENSE."/> |
| 62 | + <filteritem type="filepath" name="dsh/packages/install/.*" desc="The standalone DSH one-click installer package is distributed under the MIT License in dsh/packages/install/LICENSE, matching the script/ npm installer."/> | ||
| 61 | <filteritem type="filepath" name="vendor/cannbot-skills/.*" desc="Git submodule distributed under its own repository license."/> | 63 | <filteritem type="filepath" name="vendor/cannbot-skills/.*" desc="Git submodule distributed under its own repository license."/> |
| 62 | <filteritem type="filepath" name="plugins-community/model-recommend-infer-optimize/framework/.*" desc="Bundled GE_SESSION_DEMO inference sample retains upstream Apache-2.0 licensing (LICENSE/NOTICE shipped under framework/); exempt from repository CANN-2.0 header policy."/> | 64 | <filteritem type="filepath" name="plugins-community/model-recommend-infer-optimize/framework/.*" desc="Bundled GE_SESSION_DEMO inference sample retains upstream Apache-2.0 licensing (LICENSE/NOTICE shipped under framework/); exempt from repository CANN-2.0 header policy."/> |
| 63 | <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no license header required"/> | 65 | <filteritem type="filename" name="*.yaml" desc="YAML configuration files, no license header required"/> |
| @@ -0,0 +1,20 @@ | |||
| 1 | +node_modules/ | ||
| 2 | +/lib/ | ||
| 3 | +/dist/ | ||
| 4 | +.acceptance*/ | ||
| 5 | +.acceptance* | ||
| 6 | +**/.acceptance*/ | ||
| 7 | +**/.acceptance* | ||
| 8 | +*.log | ||
| 9 | +*.tgz | ||
| 10 | +.dsh-source.json | ||
| 11 | +.npmrc | ||
| 12 | +.env | ||
| 13 | +.env.* | ||
| 14 | +.credentials* | ||
| 15 | +test-results/ | ||
| 16 | +.DS_Store | ||
| 17 | +Thumbs.db | ||
| 18 | + | ||
| 19 | +# Workflow copies are generated outside this source tree. | ||
| 20 | +/assets/ | ||
| @@ -0,0 +1,81 @@ | |||
| 1 | +# 源码结构与开发 | ||
| 2 | + | ||
| 3 | +当前主插件和短包版本为 **1.0.0-alpha.1**;一键安装器为 **1.0.0**。 | ||
| 4 | + | ||
| 5 | +## 目录 | ||
| 6 | + | ||
| 7 | +| 路径 | 内容 | | ||
| 8 | +| --- | --- | | ||
| 9 | +| `src/` | 插件 Host、工作台、品牌界面、工作流管理与更新 | | ||
| 10 | +| `runtime/` | 初始化兼容层 | | ||
| 11 | +| `scripts/` | 构建、打包、工作流子包构建工具 | | ||
| 12 | +| `tests/` | 主插件的前后端测试 | | ||
| 13 | +| `packages/short/` | `cannbot-dsh` 短包入口,精确依赖完整包 | | ||
| 14 | +| `packages/install/` | `@cannbot-plugin/cannbot-dsh-install` 一键安装器源码及测试 | | ||
| 15 | + | ||
| 16 | +这里不包含 DSH 核心源码。插件使用官方扩展接口,构建时复用官方源码仓的客户端构建预设。 | ||
| 17 | +不提交 `node_modules`、构建产物、个人工作区、凭据、运行日志及临时测试环境。 | ||
| 18 | + | ||
| 19 | +## 主插件开发与构建 | ||
| 20 | + | ||
| 21 | +准备已经按官方说明安装好依赖的 **DSH 0.2.1-rc.3** 源码目录。该版本是开发构建依赖,不代表用户安装插件时必须使用这个版本;用户兼容范围见 `package.json`。 | ||
| 22 | + | ||
| 23 | +在 `dsh/` 目录执行,替换示例中的官方源码路径: | ||
| 24 | + | ||
| 25 | +```sh | ||
| 26 | +node scripts/prepare-dev.mjs /path/to/deepseek-harness | ||
| 27 | +node scripts/build.mjs | ||
| 28 | +node scripts/package.mjs | ||
| 29 | +``` | ||
| 30 | + | ||
| 31 | +`prepare-dev.mjs` 仅建立本地开发依赖链接,并写入被 Git 忽略的 `.dsh-source.json`。 | ||
| 32 | +也可以通过环境变量 `DSH_SOURCE` 指定源码目录。 | ||
| 33 | +打包结果位于 `dist/`,npm 安装包不包含开发依赖和工作流资源。 | ||
| 34 | + | ||
| 35 | +运行检查: | ||
| 36 | + | ||
| 37 | +```sh | ||
| 38 | +node /path/to/deepseek-harness/node_modules/typescript/bin/tsc --noEmit | ||
| 39 | +node /path/to/deepseek-harness/node_modules/vitest/vitest.mjs run | ||
| 40 | +``` | ||
| 41 | + | ||
| 42 | +## 官方资源及 Host 集成测试 | ||
| 43 | + | ||
| 44 | +官方资源直接来自指定 CANNBot 工作区及其 `vendor/cannbot-skills`。每次构建都在系统临时目录重新装配,完成后清理;不读取或维护 `assets/` 快照。实际提交和内容散列写入生成包的 `workflow.json`,许可证保留在包的 `resources/` 中。 | ||
| 45 | +准备满足声明依赖的源码目录后,生成测试使用的工作流包: | ||
| 46 | + | ||
| 47 | +```sh | ||
| 48 | +node scripts/build-workflow-packages.mjs --source /absolute/path/to/cannbot --version 1.0.0 --catalog-version 1.0.0 | ||
| 49 | +node --import tsx --test tests/host.test.mjs tests/workflow-context.test.mjs | ||
| 50 | +``` | ||
| 51 | + | ||
| 52 | +Host 集成测试读取生成的 `dist/workflow-releases/release-1.0.0-report.json`,不能仅运行测试命令而省略构建夹具。 | ||
| 53 | +工作流独立发布步骤见 [WORKFLOW_PUBLISHING.md](WORKFLOW_PUBLISHING.md)。 | ||
| 54 | + | ||
| 55 | +## 短包与一键安装器 | ||
| 56 | + | ||
| 57 | +短包无编译步骤。发布完整包的新正式版后,同步修改 `packages/short/package.json` 的版本和完整包精确依赖,再打包: | ||
| 58 | + | ||
| 59 | +```sh | ||
| 60 | +npm pack ./packages/short --ignore-scripts | ||
| 61 | +``` | ||
| 62 | + | ||
| 63 | +一键安装器的 `lib/` 是手写源码,必须纳入版本控制。在其目录执行: | ||
| 64 | + | ||
| 65 | +```sh | ||
| 66 | +cd packages/install | ||
| 67 | +npm ci | ||
| 68 | +npm test | ||
| 69 | +npm pack --ignore-scripts | ||
| 70 | +``` | ||
| 71 | + | ||
| 72 | +安装器每次安装时查询主插件和工作流的最新版本,因此主插件发布新版本不要求安装器同步升版。 | ||
| 73 | + | ||
| 74 | +## 初始化兼容 | ||
| 75 | + | ||
| 76 | +Windows 上,目录删除后立即复制可能因目录尚未释放而产生 `EIO`。兼容层只在官方初始化器的子进程中对受管目录执行有限重试,不修改 DSH 核心或上游安装器源码。 | ||
| 77 | +初始化前备份相关 Skills、agents、插件资源和配置;失败时尝试恢复,进程中断时下次先恢复。持久性权限错误仍会报告,并保留恢复所需备份。 | ||
| 78 | + | ||
| 79 | +## 本地安装 | ||
| 80 | + | ||
| 81 | +运行 `npm run install:source` 会从父目录当前源码装配 `workflow-defaults.json` 声明的工作流(当前为 3 个)、构建并安装主插件,然后原子切换工作流缓存。未列入 `workflow-defaults.json` 的工作流不参与打包,也不会出现在目录包中。使用 `--source` 指定其他本地仓库,`--repository` 在临时目录获取远端 HEAD。缓存刷新包含同版本内容修改;所有工作流校验完成前不会切换旧缓存。详见 README 的源码安装说明。 | ||
| @@ -0,0 +1,96 @@ | |||
| 1 | +# CANNBot DSH | ||
| 2 | + | ||
| 3 | +CANNBot DSH 是安装在原版 DeepSeek Harness(DSH)中的独立插件,支持 Windows 桌面端与 Linux Web 端,不修改 DSH 核心。 | ||
| 4 | + | ||
| 5 | +当前源码版本为 **1.0.0-alpha.1**。本仓库包含主插件、`packages/short` 短包和 `packages/install` 一键安装器的完整源码;目录结构、构建与检查步骤见 [DEVELOPMENT.md](DEVELOPMENT.md)。 | ||
| 6 | + | ||
| 7 | +## CANNBot 工作台 | ||
| 8 | + | ||
| 9 | +本插件提供 CANNBot 定制工作台,包含三个工作流入口(算子开发、Ascend C Flash 核函数开发、ACLNN / GEIR 注册算子开发)、工作区继承与路径展示、文件输入及原生对话衔接。也可在 DSH 的“插件 → 添加插件 → 本地安装包”中选择对应 `.tgz` 文件;请勿同时安装短包和完整包两个入口。 | ||
| 10 | + | ||
| 11 | +启用 CANNBot DSH 后,左侧新增“CANNBot工作台”,首页不显示“管理工作流”按钮。工作台沿用当前对话所属的工作区并展示真实路径,手动选择优先;无法识别当前工作区时要求明确选择,避免默认使用列表第一项。“选择工作区”使用 DSH 的目录浏览接口,可浏览 Host 目录或输入完整路径;已登记的目录直接复用,选择和取消均不启动任务。目录读取或登记失败在选择窗口内显示并重试。点击工作流卡片会勾选并聚焦输入框,保留已有文字与文件。首页不展示额外输入提示、自动应用说明和工作流数量,正常待机时不展示准备状态。 | ||
| 12 | + | ||
| 13 | +点击“开始”后按实际进展显示工作区准备、工作流依赖准备、文件上传与进入对话;没有文件时跳过上传步骤。准备失败时保留需求和文件,可展开原因并重试。发送后的模型运行错误由原生 DSH 展示,需求保留在草稿或对话记录中。工作流的独立更新、回退及日志在“插件 → CANNBot DSH”中管理。 | ||
| 14 | + | ||
| 15 | +工作流依赖由官方 CANNBot 初始化器按工作区准备,可能需要网络。依赖准备失败会显示错误并保留需求。当前工作台使用 DSH 0.2 系列的公开主面板与会话接口;不具备对应接口的旧版继续显示既有的品牌对话界面。关闭界面开关会移除定制入口,恢复原界面。 | ||
| 16 | + | ||
| 17 | +主程序与工作流包分开发布:主程序负责品牌界面、动态菜单和包管理;每个工作流自己的 npm 包包含 Skills、agents、模板、脚本及初始化入口。更新某个工作流不必更新主程序。 | ||
| 18 | + | ||
| 19 | +## 从本仓库安装(实时读取源码) | ||
| 20 | + | ||
| 21 | +在仓库根目录执行(Node.js >=24.9,先按 DEVELOPMENT.md 配置 DSH 构建依赖): | ||
| 22 | + | ||
| 23 | +```sh | ||
| 24 | +npm --prefix dsh run install:source | ||
| 25 | +``` | ||
| 26 | + | ||
| 27 | +每次安装直接读取当前仓库的 `plugins-official/`、`harness/` 和 `vendor/cannbot-skills/`,包含未提交的内容修改。`dsh/` 不保存这些目录的资源副本。工作流在系统临时目录装配、校验后复制到 `$DSH_HOME/cannbot-dsh-workflows`(默认 `~/.dsh/cannbot-dsh-workflows`),临时文件随后清理。 | ||
| 28 | + | ||
| 29 | +更新源码后重新执行此命令即可,不需要手工同步资源或发布工作流 npm 包。内容散列决定是否刷新缓存及工作区初始化;同版本内容修改也会生效。明确执行源码安装会替换对应工作流的旧缓存及回退固定状态,全部资源校验成功后一次切换;缺少依赖则报错并保留原工作流。 | ||
| 30 | + | ||
| 31 | +也可以指定其他本地源码,或在安装时获取远端仓库当前 HEAD 及其声明的子模块: | ||
| 32 | + | ||
| 33 | +```sh | ||
| 34 | +node dsh/scripts/install-source.mjs --source /path/to/cannbot | ||
| 35 | +node dsh/scripts/install-source.mjs --repository https://gitcode.com/cann/cannbot.git | ||
| 36 | +``` | ||
| 37 | + | ||
| 38 | +本地安装要求共享 Skills 已满足源码声明;不会切换用户工作区的子模块版本。安装后重启 DSH。直接安装主插件 `.tgz` 或 npm 包使用下面的已发布工作流依赖机制,不会读取本地源码。 | ||
| 39 | + | ||
| 40 | +## 安装 | ||
| 41 | + | ||
| 42 | +以下 npm 安装方式需对应版本已发布;本地源码安装使用上面的 `install:source` 命令。 | ||
| 43 | + | ||
| 44 | +在 DSH **插件 → 添加插件** 中输入: | ||
| 45 | + | ||
| 46 | +```text | ||
| 47 | +cannbot-dsh@1.0.0-alpha.1 | ||
| 48 | +``` | ||
| 49 | + | ||
| 50 | +完整包名为 `@cannbot-plugin/cannbot-dsh@1.0.0-alpha.1`。请只选择一种入口安装。 | ||
| 51 | +兼容范围为 DSH `>=0.1.1-rc.1 <0.3.0`,Node.js 24.9 或更新版本;图形包管理依赖 DSH 提供官方认证 Fetch 路由与插件管理接口。 | ||
| 52 | + | ||
| 53 | +目录包将默认工作流声明为标准 npm 必需依赖。DSH 的安装过程会一次下载主插件、目录包与全部 3 个默认工作流包,目前提供 53 个 Skills;任一依赖下载失败,安装阶段就会报错。首次启用只准备本地已安装资源,全部准备完成后插件才启用,不会在后台补装子包。首次安装需要网络;安装完成后可离线加载。 | ||
| 54 | + | ||
| 55 | +Linux 可使用同一个包: | ||
| 56 | + | ||
| 57 | +```sh | ||
| 58 | +dsh plugin --profile web add cannbot-dsh@1.0.0-alpha.1 | ||
| 59 | +dsh web | ||
| 60 | +``` | ||
| 61 | + | ||
| 62 | +## 独立更新工作流 | ||
| 63 | + | ||
| 64 | +插件详情页的 **工作流管理** 为每个工作流显示包名、已安装版本和最新版本,可逐项安装、更新、回退,也可 **更新全部工作流**。 | ||
| 65 | +程序启用时加载已经安装的工作流;下载新版本通过详情页明确触发。回退后固定该版本,批量更新不会将它升回去;主动更新这一项即可恢复跟随最新版。 | ||
| 66 | + | ||
| 67 | +目录包是 `@cannbot-plugin/workflow-catalog`;工作流包统一为 `@cannbot-plugin/workflow-<ID>`。默认工作流集合由 `dsh/workflow-defaults.json` 决定,未列入的工作流不会被打包,也不会出现在目录包中;「检查更新」同样只保留该集合内的工作流。发布已有工作流的新版本只需更新对应小包;新增工作流先发布内容包,再更新小型目录包,无需发布主程序。维护者操作见 [独立工作流发布说明](WORKFLOW_PUBLISHING.md)。 | ||
| 68 | + | ||
| 69 | +主程序提供 **检查更新** 按钮,并支持 Host 后台一键升级:使用 DSH 官方更新接口,旧版 DSH 通过官方安装、卸载接口串联,失败时尝试恢复原版本。 | ||
| 70 | + | ||
| 71 | +## 使用与初始化 | ||
| 72 | + | ||
| 73 | +- 启用后默认显示 CANNBot DSH 品牌与红白主题。左下角的 **CANNBot DSH** 开关可恢复原版界面,工作流 Skills 不受影响。 | ||
| 74 | +- 选择工作区和工作流后,Host 自动准备该工作区。统一安装器工作流直接调用包内保留的上游 Node.js 安装器,指定 `--tool dsh --target <工作目录> --plugin-dir <包内资源目录>`;不需要另外克隆 CANNBot 主仓或共享 Skills 仓。 | ||
| 75 | +- 初始化按工作区、工作流包版本和完整性记录,相同版本不重复执行;更新其他工作流不会重复初始化当前工作流。外部依赖仍按上游 `plugin-install.json` 准备,可能需要 Git、网络及声明的运行环境。没有统一安装器的 `ops-registry-invoke` 保持原生 Skill 自检行为。 | ||
| 76 | +- 准备期间可以继续编辑需求,但该工作流准备完成前不会发送任务。失败时保留原选择,并在插件详情提供日志与重试入口。 | ||
| 77 | +- 用户输入框不会显示或加入 `/工作流名称`。发送时通过 DSH 官方 `agent/pre-step` 加载工作流上下文,用户消息、引用和附件保持原样。 | ||
| 78 | +- 本插件不提供 SSH 或远程连接控件;Linux 使用 DSH 自身的 Web 界面。 | ||
| 79 | + | ||
| 80 | +## 缓存、校验与回退 | ||
| 81 | + | ||
| 82 | +工作流缓存默认位于 `$DSH_HOME/cannbot-dsh-workflows`,未设置时为 `~/.dsh/cannbot-dsh-workflows`;可用 `CANNBOT_DSH_WORKFLOW_ROOT` 指定其他目录。 | ||
| 83 | +资源包通过 npm 官方 `pacote` 库下载并校验 SHA-512,安装时不运行 npm 生命周期脚本。每个版本安装到独立目录,通过格式与资源检查后原子切换;下载失败继续使用旧版。已安装内容可离线加载,首次工作区初始化仍须满足上游依赖条件。 | ||
| 84 | + | ||
| 85 | +卸载主插件不会自动删除工作流缓存或项目内由上游安装器生成的文件。 | ||
| 86 | + | ||
| 87 | +## 构建 | ||
| 88 | + | ||
| 89 | +主程序复用官方 DSH 开源仓库的 Client 构建预设,通过 `DSH_SOURCE` 或开发配置指定官方源码目录,然后运行 `npm run build`、`npm test`、`npm run pack:plugin`。不修改上游核心。 | ||
| 90 | +工作流小包可使用标准 Node.js/npm 构建与发布,具体命令和包格式见 [WORKFLOW_PUBLISHING.md](WORKFLOW_PUBLISHING.md)。 | ||
| 91 | + | ||
| 92 | +## Python 编排与 DSH 原生执行 | ||
| 93 | + | ||
| 94 | +使用 `harness/workflow-orchestrator` 的工作流通过 `cannbot_workflow_run` 启动:传入工作流包 ID、YAML、需求和可选工作目录。Python 保留依赖调度、并发、重试、回退和裁决逻辑;每个节点由 DSH 原生子 Agent loop 执行并继承会话模型,无需选择 Coding Agent CLI provider。用 `cannbot_workflow_status` 查询,用 `cannbot_workflow_cancel` 停止;审批仍使用 Python 工作流的审批脚本。 | ||
| 95 | + | ||
| 96 | +插件通过 `python3 -c` 导入工作流资源中的 `orchestrator.py`,向其通用函数接口注入执行回调;管道适配代码随插件编译,不增加 Python 入口文件或编排器命令行参数。安装时获取 Python 编排器,`dsh/` 不保存其副本。运行要求 Python 3 和 PyYAML,以及 DSH 的原生 spawn 子 Agent 能力。 | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +# Third-party notices | ||
| 2 | + | ||
| 3 | +CANNBot DSH contains the DSH adapter and installation code. Official workflow | ||
| 4 | +resources are copied from the selected CANNBot source and its declared shared | ||
| 5 | +Skills during source installation or workflow-package construction. This source | ||
| 6 | +tree does not retain copies of those resources. | ||
| 7 | +Each generated workflow package retains its CANN Open Software License Agreement | ||
| 8 | +Version 2.0 and shared Skill license in resources/LICENSE and SKILLS_LICENSE. | ||
| 9 | +Its workflow.json records the actual source revisions and content hashes. | ||
| 10 | +Local uncommitted changes are included; revision identifiers alone do not identify | ||
| 11 | +those changes. Published npm installations obtain resources from workflow packages. | ||
| 12 | + | ||
| 13 | +Source-declared symlinks are materialized for portable installation. The upstream | ||
| 14 | +bundler's model-invocation normalization is retained unless the plugin declares | ||
| 15 | +preserveSkillInvocationPolicy. DSH entry Skill adapters are added for official | ||
| 16 | +plugins whose primary instructions are AGENTS.md rather than a same-named Skill. | ||
| 17 | +The original instructions, agents, scripts, hooks and templates are retained. | ||
| 18 | + | ||
| 19 | +The palette and decorative C mark were developed for this plugin. DSH, Cordis, | ||
| 20 | +Schemastery and DSH's UI libraries remain separately installed dependencies with | ||
| 21 | +their original licenses. The build uses the official DSH client bundle preset; | ||
| 22 | +this package contains no redistributed DSH desktop executable or server runtime. | ||
| @@ -0,0 +1,70 @@ | |||
| 1 | +# 独立工作流包的构建与发布 | ||
| 2 | + | ||
| 3 | +主程序:`cannbot-dsh` / `@cannbot-plugin/cannbot-dsh`。 | ||
| 4 | +工作流目录:`@cannbot-plugin/workflow-catalog`。 | ||
| 5 | +内容包:`@cannbot-plugin/workflow-<工作流 ID>`,各包独立版本。 | ||
| 6 | + | ||
| 7 | +## 更新已有工作流 | ||
| 8 | + | ||
| 9 | +先在 CANNBot 源码仓修改内容,准备该源码仓声明的共享 Skills。构建器每次直接读取指定工作区(包含未提交修改),在系统临时目录装配,不维护 `dsh/assets` 副本。正式发布前应提交源码以便追溯。只构建目标工作流: | ||
| 10 | + | ||
| 11 | +```sh | ||
| 12 | +node scripts/build-workflow-packages.mjs --source /path/to/cannbot --id ops-direct-invoke --version 1.0.1 | ||
| 13 | +npm publish dist/workflow-releases/cannbot-plugin-workflow-ops-direct-invoke-1.0.1.tgz --access public | ||
| 14 | +``` | ||
| 15 | + | ||
| 16 | +使用 npm 公共仓库和 `latest` 标签。无需改主程序版本,也无需更新目录包。用户可检查并更新这一项,或更新全部未固定的工作流。发布者先在隔离工作区运行包中的初始化器验证后再发布。 | ||
| 17 | + | ||
| 18 | +## 新增工作流 | ||
| 19 | + | ||
| 20 | +工作流目录、清单与 Skill 需符合现有 CANNBot 结构。先构建并发布新内容包;确认可公开下载后,再构建、发布一个新版本的目录包,使用户能够发现它: | ||
| 21 | + | ||
| 22 | +```sh | ||
| 23 | +node scripts/build-workflow-packages.mjs --source /path/to/cannbot --id new-workflow --version 1.0.0 --catalog true --catalog-version 1.0.1 | ||
| 24 | +``` | ||
| 25 | + | ||
| 26 | +该命令会分别产生新工作流包和目录包。按“内容包先公开、目录包再公开”的顺序发布。主程序无需更新。 | ||
| 27 | + | ||
| 28 | +## 包格式 v1 | ||
| 29 | + | ||
| 30 | +根 `package.json` 声明 `cannbotWorkflow: { "schemaVersion": 1, "id": "..." }`,不声明 npm 安装脚本或额外 npm 依赖。 | ||
| 31 | +`workflow.json` 记录版本、原始源码提交、资源路径、Skill 内容散列与初始化入口;`resources/` 包含物化后的 Skills、agents、模板、脚本和许可证。 | ||
| 32 | +构建器沿用上游 npm 装配方式,将源码专用的 `plugin-sources.json` 转换为包内资源清单。 | ||
| 33 | + | ||
| 34 | +带统一安装器的包保留上游 `script/bin/cannbot.js` 和 `script/lib` 代码,Host 显式调用: | ||
| 35 | + | ||
| 36 | +```sh | ||
| 37 | +node <工作流包>/upstream/bin/cannbot.js install <ID> --tool dsh --target <工作目录> --plugin-dir <工作流包>/resources | ||
| 38 | +``` | ||
| 39 | + | ||
| 40 | +这里使用上游安装器支持的包模式;不需要额外克隆 CANNBot 主仓或共享 Skills 仓。 | ||
| 41 | +初始化声明的外部依赖仍按上游 `plugin-install.json` 准备,因此某些工作流首次初始化仍需要 Git、网络及其运行环境。 | ||
| 42 | +没有统一安装器清单的 `ops-registry-invoke` 保持 Skill 原生自检行为,不伪造 `init.sh`。 | ||
| 43 | + | ||
| 44 | +## 用户侧的版本与回退 | ||
| 45 | + | ||
| 46 | +工作流安装在 `$DSH_HOME/cannbot-dsh-workflows`,与 npm 主程序目录分离。 | ||
| 47 | +下载由 npm 官方 `pacote` 库处理并校验 registry 提供的 SHA-512 完整性;不运行 npm 生命周期脚本。 | ||
| 48 | +新包通过校验后才原子切换该工作流,旧版本目录保留。回退后固定版本,自动同步及“更新全部”不会将它升回去;主动更新这一项即可恢复跟随最新版。 | ||
| 49 | +工作区初始化按“工作区、工作流包版本及完整性”记录,更新无关工作流不会重复初始化当前工作流。 | ||
| 50 | + | ||
| 51 | +仅当主程序界面、加载机制或包格式协议发生不兼容变化时,才需发布新的 DSH 主程序。 | ||
| 52 | + | ||
| 53 | +## 首次安装依赖 | ||
| 54 | + | ||
| 55 | +目录包的 `dependencies` 声明全部默认工作流,版本使用 `>=1.0.0`,让新用户在 DSH 标准 npm 安装阶段一次获取当时可解析的最新稳定包,并排除历史占位版本。主插件依赖目录包 `^1.0.4`。发布目录包前必须确保所有工作流已公开;新增默认工作流同时加入目录及其 `dependencies`。已有工作流发布新版本仍不必重发目录包或主插件。 | ||
| 56 | + | ||
| 57 | +启用时仅从 npm 已安装的依赖准备本地缓存,等待全部完成后才注册工作流能力,不运行 npm 安装脚本,不覆盖缓存内独立升级或固定回退的版本。新版本下载由用户在工作流管理中明确触发。项目级外部依赖依然在选择工作流时按需初始化,不能在未选择项目时提前运行。 | ||
| 58 | + | ||
| 59 | +## 发布主程序 | ||
| 60 | + | ||
| 61 | +```sh | ||
| 62 | +npm publish dist/cannbot-plugin-cannbot-dsh-1.0.0-alpha.1.tgz | ||
| 63 | +npm publish dist/cannbot-dsh-1.0.0-alpha.1.tgz | ||
| 64 | +``` | ||
| 65 | + | ||
| 66 | +发布顺序为完整包、短包、一键安装器:短包精确依赖完整包,完整包未公开时短包安装必然失败。 | ||
| 67 | + | ||
| 68 | +## 无需发布的源码安装 | ||
| 69 | + | ||
| 70 | +在 `dsh/` 执行 `npm run install:source`,安装器会实时复制父仓库源码到 DSH 工作流缓存。它使用与发布相同的装配、许可证保留和校验逻辑,但跳过工作流 npm 打包与发布。重新安装以内容散列刷新缓存,无需修改版本号。`--repository <GitURL>` 会在本次安装中获取远端源码。 | ||
| @@ -0,0 +1,38 @@ | |||
| 1 | +<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128.000000" height="128.000000" fill="none" customFrame="#000000"> | ||
| 2 | + <defs> | ||
| 3 | + <clipPath id="clipPath_12"> | ||
| 4 | + <rect width="128.000000" height="127.999954" x="0.000000" y="0.000000" fill="rgb(255,255,255)" /> | ||
| 5 | + </clipPath> | ||
| 6 | + <linearGradient id="paint_linear_22" x1="29.333334" x2="29.333334" y1="0" y2="73.9391937" gradientUnits="userSpaceOnUse"> | ||
| 7 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="0.300000012" /> | ||
| 8 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 9 | + </linearGradient> | ||
| 10 | + <linearGradient id="paint_linear_23" x1="38.9329453" x2="38.9329453" y1="21.3334961" y2="95.2726898" gradientUnits="userSpaceOnUse"> | ||
| 11 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="1" /> | ||
| 12 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 13 | + </linearGradient> | ||
| 14 | + <linearGradient id="paint_linear_24" x1="49.5993462" x2="49.5993462" y1="54.3999023" y2="71.0362244" gradientUnits="userSpaceOnUse"> | ||
| 15 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="1" /> | ||
| 16 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 17 | + </linearGradient> | ||
| 18 | + <linearGradient id="paint_linear_25" x1="78.4001312" x2="78.4001312" y1="54.3999023" y2="71.0362167" gradientUnits="userSpaceOnUse"> | ||
| 19 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="0.300000012" /> | ||
| 20 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 21 | + </linearGradient> | ||
| 22 | + </defs> | ||
| 23 | + <g id="cannbot-单logo"> | ||
| 24 | + <g id="容器 91334040" customFrame="url(#clipPath_12)"> | ||
| 25 | + <rect id="容器 91334040" width="128.000000" height="127.999954" x="0.000000" y="0.000000" /> | ||
| 26 | + <g id="组合 91334087"> | ||
| 27 | + <path id="矢量 6118" d="M54.656 0.0110097C54.6558 0.0110113 51.7668 3.67457e-05 51.7668 3.67457e-05C51.7668 3.67457e-05 51.7668 3.67636e-05 51.7667 3.68013e-05C51.6899 7.12161e-05 22.9847 0.0158011 22.8369 0.0110097C17.1909 -0.170211 12.3667 1.89873 8.09757 5.25809C2.0998 9.97218 0.125215 16.5951 0.0501712 23.826C-0.0509294 34.2225 0.0204758 43.0968 0.0918716 53.4933C0.0960407 54.0708 0.0996886 54.6486 0.103858 55.2261C0.106463 55.7419 0.108027 56.2585 0.109069 56.7758C0.115844 59.9923 0.122618 63.2318 0.573402 66.3923C2.21707 77.8358 11.1504 85.3226 22.7838 85.3226C23.0056 85.3226 36.8094 85.3316 37.3553 85.3333C39.2975 85.3333 40.6212 84.6508 41.4535 82.8483C42.9799 79.4889 44.6554 76.204 46.2136 72.8553C48.1777 68.6214 46.865 66.6696 42.1263 66.6696L25.9533 66.6696C25.6584 66.6696 25.3623 66.6714 25.0663 66.673L25.0658 66.673C24.0777 66.6787 23.086 66.6844 22.1005 66.6269C20.2969 66.5311 19.1441 65.3365 19.1441 63.5662L19.1441 21.6182C19.1441 20.1997 19.8591 19.24 21.1828 18.8879C22.3246 18.5893 23.5305 18.4294 24.7156 18.4294C36.3276 18.3974 30.8661 18.4081 42.478 18.4294C44.7835 18.4294 47.0891 18.5466 49.3941 18.5573C51.0273 18.5573 52.2864 17.9175 53.0019 16.3605C54.7414 12.5637 56.5665 8.82028 58.2419 5.00214C59.5015 2.12265 57.8578 -0.0210164 54.656 0.0216851L54.656 0.0110097Z" fill="rgb(199,0,11)" fill-rule="evenodd" transform="matrix(-1,0,0,-1,118.4,106.667)" /> | ||
| 28 | + <path id="矢量 6118" d="M51.7668 3.67457e-05L54.6558 0.0110092L54.656 0.0110097L54.6559 0.0193189L54.6559 0.021685L54.656 0.0216844L54.656 0.0216851C54.6897 0.0212351 54.7233 0.0210279 54.7567 0.0210619C54.7853 0.021091 54.8138 0.0212974 54.8422 0.0216798L54.8426 0.0216851C57.2018 0.0536275 58.6667 1.30361 58.6667 3.15649C58.6667 3.72147 58.5305 4.3425 58.2419 5.00214C56.5665 8.82028 54.7414 12.5637 53.0019 16.3605C52.2864 17.9175 51.0273 18.5573 49.3941 18.5573C47.0891 18.5466 44.7835 18.4294 42.478 18.4294C36.672 18.4188 35.1344 18.4107 33.5968 18.4094C32.3003 18.4083 31.0038 18.4119 27.1486 18.4227C26.4316 18.4247 25.6261 18.4269 24.7156 18.4294C23.5305 18.4294 22.3246 18.5893 21.1828 18.8879C19.8591 19.24 19.1441 20.1997 19.1441 21.6182L19.1441 63.5662C19.1441 65.3365 20.2969 66.5311 22.1005 66.6269C23.086 66.6844 24.0777 66.6787 25.0658 66.673L25.0663 66.673C25.3623 66.6714 25.6584 66.6696 25.9533 66.6696L42.1263 66.6696C45.4543 66.6696 47.0926 67.6323 47.0926 69.6722C47.0926 70.5368 46.7983 71.5949 46.2136 72.8553C44.6554 76.204 42.9799 79.4889 41.4535 82.8483C40.6212 84.6508 39.2975 85.3333 37.3553 85.3333C36.8094 85.3316 23.0056 85.3226 22.7838 85.3226C11.1504 85.3226 2.21707 77.8358 0.573402 66.3923C0.122618 63.2318 0.115844 59.9923 0.109069 56.7758C0.108027 56.2585 0.106463 55.7419 0.103858 55.2261C0.0996886 54.6486 0.0960407 54.0708 0.0918716 53.4933C0.0879818 52.9269 0.0840921 52.365 0.0802302 51.8071C0.0384871 45.7771 0 40.2174 0 34.5064C0 31.0478 0.0141155 27.5337 0.0501712 23.826C0.125215 16.5951 2.0998 9.97218 8.09757 5.25809C12.3667 1.89873 17.1909 -0.170211 22.8369 0.0110097C22.9793 0.0156241 49.6082 0.00120531 51.6439 0.000103038L51.7667 3.68013e-05L51.7668 3.67457e-05ZM51.7677 2.00004L51.7676 2.00004L51.7635 2.00004L37.3026 2.00734L22.8051 2.01102L22.7727 2.00998Q21.3984 1.96587 20.0475 2.12341L20.0474 2.12342L20.0473 2.12344Q14.4919 2.7714 9.33436 6.82983Q7.29064 8.43614 5.82839 10.4621L5.82836 10.4622Q4.54626 12.2385 3.71118 14.3376Q2.1069 18.37 2.05006 23.8467Q2.00886 28.084 2.00886 33.8733Q2.00886 41.4901 2.08018 51.7933C2.08533 52.5375 2.08921 53.0996 2.09182 53.4796L2.09781 54.3449L2.10381 55.2123L2.10906 56.7691L2.10907 56.7727C2.11354 58.8976 2.13499 60.4841 2.17341 61.5323C2.23634 63.2493 2.36299 64.7752 2.55336 66.1099C2.92521 68.6987 3.69419 71.0708 4.8603 73.2262Q5.90423 75.1556 7.31957 76.7568L7.31965 76.7569L7.32088 76.7583C7.90805 77.4224 8.54315 78.0442 9.22618 78.6235Q9.92308 79.2147 10.6703 79.7333L10.6705 79.7334L10.6708 79.7336L10.6726 79.7349Q12.7859 81.2012 15.3014 82.0877C17.6377 82.911 20.1318 83.3226 22.7838 83.3226L30.0778 83.3274L37.3569 83.3333Q38.3095 83.3333 38.8118 83.0398C39.1316 82.853 39.4069 82.5097 39.6377 82.0099C40.2064 80.7581 41.0905 78.8958 42.2898 76.4229C43.2395 74.4648 43.943 72.9943 44.4003 72.0116C44.7975 71.1552 45.0242 70.4515 45.0802 69.9004C45.0893 69.8103 45.0939 69.7287 45.0939 69.6557C45.0939 69.4828 45.0683 69.3578 45.017 69.2806C44.9365 69.1592 44.7362 69.0459 44.4163 68.9409C43.8655 68.76 43.1021 68.6696 42.1263 68.6696L25.9533 68.6696L25.091 68.6729L25.077 68.6729L25.0658 68.673C23.7112 68.6808 22.6839 68.6643 21.984 68.6235C21.0321 68.5729 20.1972 68.3297 19.4792 67.8939Q18.951 67.5733 18.5073 67.1138C18.1886 66.7837 17.9258 66.424 17.7188 66.0346C17.3357 65.3136 17.1441 64.4908 17.1441 63.5662L17.1441 21.6182Q17.1441 20.2633 17.7096 19.2128L17.7097 19.2126C17.8136 19.0197 17.9317 18.8345 18.0642 18.657C18.246 18.4133 18.4483 18.1926 18.6708 17.9948L18.6711 17.9946Q19.4873 17.2693 20.6688 16.9551C21.7413 16.6746 22.8196 16.5063 23.9036 16.4504C24.1739 16.4364 24.4446 16.4294 24.7156 16.4294L33.5923 16.4094L42.4825 16.4294C43.3025 16.4294 44.5266 16.4511 46.1547 16.4945C47.6035 16.533 48.6864 16.554 49.4033 16.5573C49.8805 16.5573 50.2577 16.4765 50.535 16.3148Q50.9267 16.0866 51.1846 15.5254C51.6208 14.5734 52.2822 13.1522 53.1688 11.2619Q55.3725 6.56395 56.4105 4.19848Q56.6759 3.59184 56.6759 3.1642C56.6759 2.95121 56.6265 2.77153 56.5277 2.62515C56.5219 2.61651 56.5159 2.60799 56.5098 2.59959Q56.0718 2.00298 54.6826 2.02151L52.656 2.04854L52.656 2.00343L51.7677 2.00004Z" fill="url(#paint_linear_22)" fill-opacity="0" fill-rule="evenodd" transform="matrix(-1,0,0,-1,118.4,106.667)" /> | ||
| 29 | + <path id="矢量 6119" d="M64.2556 21.3445C64.2554 21.3445 61.3665 21.3335 61.3665 21.3335C61.3665 21.3335 61.3664 21.3335 61.3663 21.3335C61.2895 21.3336 32.5843 21.3493 32.4365 21.3445C26.7905 21.1633 21.9663 23.2322 17.6972 26.5916C11.6994 31.3057 9.72482 37.9286 9.64978 45.1595C9.54868 55.556 9.62008 64.4303 9.69148 74.8268C9.69565 75.4043 9.6993 75.9821 9.70347 76.5596C9.70607 77.0754 9.70764 77.592 9.70868 78.1093C9.71545 81.3258 9.72223 84.5653 10.173 87.7258C11.8167 99.1693 20.75 106.656 32.3834 106.656C32.6052 106.656 46.409 106.665 46.9549 106.667C48.8972 106.667 50.2208 105.984 51.0531 104.182C52.5795 100.822 54.255 97.5375 55.8132 94.1888C57.7773 89.9549 56.4646 88.0031 51.7259 88.0031L35.5529 88.0031C35.258 88.0031 34.962 88.0049 34.666 88.0065L34.6654 88.0065C33.6774 88.0122 32.6856 88.0179 31.7002 87.9604C29.8965 87.8646 28.7437 86.67 28.7437 84.8997L28.7437 42.9517C28.7437 41.5332 29.4587 40.5735 30.7824 40.2214C31.9242 39.9228 33.1301 39.7629 34.3152 39.7629C45.9272 39.7309 40.4657 39.7416 52.0776 39.7629C54.3832 39.7629 56.6887 39.8801 58.9937 39.8908C60.6269 39.8908 61.886 39.251 62.6015 37.694C64.341 33.8972 66.1661 30.1538 67.8415 26.3356C69.1011 23.4562 67.4575 21.3125 64.2556 21.3552L64.2556 21.3445Z" fill="rgb(35,23,22)" fill-rule="evenodd" /> | ||
| 30 | + <path id="矢量 6119" d="M61.3665 21.3335L64.2554 21.3445L64.2556 21.3445L64.2556 21.3528L64.2555 21.3552L64.2556 21.3552L64.2556 21.3552C64.2893 21.3547 64.3229 21.3545 64.3563 21.3546C64.3849 21.3546 64.4134 21.3548 64.4418 21.3552L64.4422 21.3552C66.8015 21.3871 68.2663 22.6371 68.2663 24.49C68.2663 25.055 68.1301 25.676 67.8415 26.3356C66.1661 30.1538 64.341 33.8972 62.6015 37.694C61.886 39.251 60.6269 39.8908 58.9937 39.8908C56.6887 39.8801 54.3832 39.7629 52.0776 39.7629C46.2716 39.7522 44.734 39.7442 43.1964 39.7429C41.8999 39.7418 40.6035 39.7454 36.7482 39.7562C36.0312 39.7582 35.2257 39.7604 34.3152 39.7629C33.1301 39.7629 31.9242 39.9228 30.7824 40.2214C29.4587 40.5735 28.7437 41.5332 28.7437 42.9517L28.7437 84.8997C28.7437 86.67 29.8965 87.8646 31.7002 87.9604C32.6856 88.0179 33.6774 88.0122 34.6654 88.0065L34.666 88.0065C34.962 88.0049 35.258 88.0031 35.5529 88.0031L51.7259 88.0031C55.054 88.0031 56.6922 88.9658 56.6922 91.0057C56.6922 91.8703 56.3979 92.9284 55.8132 94.1888C54.255 97.5375 52.5795 100.822 51.0531 104.182C50.2208 105.984 48.8972 106.667 46.9549 106.667C46.409 106.665 32.6052 106.656 32.3834 106.656C20.75 106.656 11.8167 99.1693 10.173 87.7258C9.72223 84.5653 9.71545 81.3258 9.70868 78.1093C9.70764 77.592 9.70607 77.0754 9.70347 76.5596C9.6993 75.9821 9.69565 75.4043 9.69148 74.8268C9.68759 74.2604 9.6837 73.6985 9.67984 73.1406C9.6381 67.1106 9.59961 61.5509 9.59961 55.8399C9.59961 52.3813 9.61372 48.8672 9.64978 45.1595C9.72482 37.9286 11.6994 31.3057 17.6972 26.5916C21.9663 23.2322 26.7905 21.1633 32.4365 21.3445C32.5789 21.3491 59.2078 21.3347 61.2435 21.3336L61.3663 21.3335L61.3665 21.3335ZM61.3673 23.3335L61.3672 23.3335L61.3631 23.3335L46.9022 23.3408L32.4047 23.3445L32.3724 23.3435Q30.9978 23.2994 29.6469 23.4569Q24.0915 24.1049 18.934 28.1633Q16.8903 29.7696 15.428 31.7956L15.428 31.7956L15.4279 31.7957Q14.1459 33.5721 13.3108 35.6711Q11.7065 39.7035 11.6497 45.1802Q11.6085 49.4175 11.6085 55.2068Q11.6085 62.8236 11.6798 73.1268C11.685 73.8733 11.6888 74.4354 11.6914 74.8131L11.6974 75.6784L11.7034 76.5458L11.7087 78.1026L11.7087 78.1062Q11.7154 81.2935 11.773 82.8658Q11.8674 85.4413 12.153 87.4434C12.5248 90.0322 13.2938 92.4043 14.4599 94.5596Q15.5038 96.4891 16.9192 98.0903L16.9193 98.0904L16.9205 98.0918C17.5077 98.7559 18.1428 99.3777 18.8258 99.957Q19.5227 100.548 20.2699 101.067L20.2701 101.067L20.2704 101.067L20.2722 101.068Q22.3855 102.535 24.9011 103.421C27.2373 104.244 29.7314 104.656 32.3834 104.656L39.6774 104.661L46.9565 104.667Q47.9091 104.667 48.4114 104.373C48.7313 104.186 49.0066 103.843 49.2373 103.343C49.806 102.092 50.6901 100.229 51.8894 97.7564C52.8391 95.7983 53.5426 94.3278 53.9999 93.3451C54.3971 92.4887 54.6238 91.785 54.6798 91.2339C54.6889 91.1438 54.6935 91.0622 54.6935 90.9892C54.6935 90.8163 54.6679 90.6913 54.6166 90.6141C54.5361 90.4927 54.3358 90.3794 54.016 90.2744C53.4651 90.0935 52.7017 90.0031 51.7259 90.0031L35.5529 90.0031L34.6906 90.0064L34.6767 90.0064L34.6654 90.0065C33.3108 90.0143 32.2835 89.9978 31.5836 89.957C30.6317 89.9064 29.7968 89.6632 29.0788 89.2274C28.7267 89.0137 28.4027 88.7536 28.1069 88.4473C27.7882 88.1172 27.5254 87.7575 27.3185 87.3681C26.9353 86.6471 26.7437 85.8243 26.7437 84.8997L26.7437 42.9517Q26.7437 41.5968 27.3092 40.5463L27.3093 40.5461C27.4132 40.3532 27.5313 40.168 27.6638 39.9905C27.8457 39.7468 28.0479 39.5261 28.2705 39.3283Q29.0867 38.6029 30.2684 38.2886C31.3409 38.0081 32.4192 37.8398 33.5032 37.7839C33.7735 37.7699 34.0442 37.7629 34.3152 37.7629L43.1919 37.7429L52.0822 37.7629C52.9021 37.7629 54.1262 37.7846 55.7544 37.8279C57.2031 37.8665 58.286 37.8875 59.0029 37.8908C59.4801 37.8908 59.8573 37.81 60.1346 37.6483Q60.5263 37.4201 60.7842 36.8589C61.2204 35.9069 61.8818 34.4857 62.7685 32.5954Q64.9721 27.8974 66.0101 25.532Q66.2755 24.9253 66.2755 24.4977C66.2755 24.2847 66.2261 24.105 66.1273 23.9586C66.1215 23.95 66.1155 23.9415 66.1094 23.9331Q65.6714 23.3365 64.2823 23.355L62.2556 23.382L62.2556 23.3369L61.3673 23.3335Z" fill="url(#paint_linear_23)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 31 | + <path id="矢量 6109" d="M39.5901 73.5999L51.8402 73.5999C54.3694 73.5999 56.6613 72.1104 57.6886 69.7992L62.5328 58.8995C63.4733 56.7834 61.9244 54.3999 59.6086 54.3999L47.3585 54.3999C44.8293 54.3999 42.5373 55.8894 41.5101 58.2006L36.6659 69.1003C35.7254 71.2164 37.2743 73.5999 39.5901 73.5999Z" fill="rgb(35,23,22)" fill-rule="evenodd" /> | ||
| 32 | + <path id="矢量 6109" d="M36.3864 70.401C36.3864 69.9712 36.4748 69.5302 36.6659 69.1003L41.5101 58.2006C42.5373 55.8894 44.8293 54.3999 47.3585 54.3999L59.6086 54.3999C61.4538 54.3999 62.8122 55.9133 62.8122 57.5988C62.8122 58.0286 62.7239 58.4696 62.5328 58.8995L57.6886 69.7992C56.6613 72.1104 54.3694 73.5999 51.8402 73.5999L39.5901 73.5999C37.7448 73.5999 36.3864 72.0865 36.3864 70.401ZM51.8402 71.5999Q52.4922 71.5999 53.0916 71.4222C53.4912 71.3038 53.8733 71.1261 54.2378 70.8893C54.6023 70.6524 54.9198 70.3754 55.1903 70.0583C55.4608 69.7413 55.6844 69.3841 55.8609 68.9869L60.7052 58.0873Q60.8182 57.8331 60.8182 57.5879C60.8182 57.56 60.8171 57.5321 60.8149 57.5044C60.7998 57.3142 60.7331 57.128 60.6148 56.946C60.4965 56.764 60.3535 56.6274 60.1858 56.5364C60.0181 56.4454 59.8257 56.3999 59.6086 56.3999L47.3585 56.3999C46.9238 56.3999 46.5067 56.4591 46.1071 56.5776L46.107 56.5776Q45.5076 56.7552 44.9609 57.1105C44.5964 57.3474 44.2789 57.6244 44.0084 57.9414C43.7379 58.2585 43.5143 58.6157 43.3378 59.0129L38.4935 69.9125Q38.3805 70.1667 38.3805 70.4119Q38.3805 70.4538 38.3838 70.4954Q38.4064 70.7807 38.5839 71.0538C38.7022 71.2358 38.8452 71.3724 39.0129 71.4634L39.0129 71.4634Q39.2644 71.5999 39.5901 71.5999L51.8402 71.5999Z" fill="url(#paint_linear_24)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 33 | + <path id="矢量 6115" d="M68.3908 73.5999L80.6409 73.5999C83.1702 73.5999 85.4621 72.1104 86.4893 69.7992L91.3336 58.8995C92.2741 56.7834 90.7251 54.3999 88.4094 54.3999L76.1593 54.3999C73.6301 54.3999 71.3381 55.8894 70.3109 58.2006L65.4666 69.1003C64.5261 71.2164 66.0751 73.5999 68.3908 73.5999Z" fill="rgb(199,0,11)" fill-rule="evenodd" /> | ||
| 34 | + <path id="矢量 6115" d="M80.6409 73.5999L68.3908 73.5999C66.5456 73.5999 65.1872 72.0865 65.1872 70.401C65.1872 69.9712 65.2756 69.5302 65.4666 69.1003L70.3109 58.2006C71.3381 55.8894 73.6301 54.3999 76.1593 54.3999L88.4094 54.3999C90.2546 54.3999 91.613 55.9133 91.613 57.5988C91.613 58.0286 91.5247 58.4696 91.3336 58.8995L86.4893 69.7992C85.4621 72.1104 83.1702 73.5999 80.6409 73.5999ZM80.6409 71.5999C81.0757 71.5999 81.4928 71.5407 81.8924 71.4222C82.292 71.3038 82.6741 71.1261 83.0386 70.8893C83.4031 70.6524 83.7206 70.3754 83.9911 70.0583C84.2616 69.7413 84.4852 69.3841 84.6617 68.9869L89.506 58.0873C89.5813 57.9178 89.619 57.7514 89.619 57.5879C89.619 57.56 89.6179 57.5321 89.6157 57.5044C89.6006 57.3142 89.5339 57.128 89.4156 56.946C89.2973 56.764 89.1543 56.6274 88.9866 56.5364L88.9865 56.5364Q88.735 56.3999 88.4094 56.3999L76.1593 56.3999Q75.5073 56.3999 74.9079 56.5776Q74.3084 56.7552 73.7617 57.1105Q73.2149 57.4659 72.8092 57.9415C72.5386 58.2585 72.3151 58.6157 72.1385 59.0129L67.2943 69.9125C67.219 70.082 67.1813 70.2484 67.1813 70.4119C67.1813 70.4398 67.1824 70.4677 67.1846 70.4954Q67.2072 70.7807 67.3846 71.0538C67.5029 71.2358 67.6459 71.3723 67.8136 71.4634C67.9813 71.5544 68.1737 71.5999 68.3908 71.5999L80.6409 71.5999Z" fill="url(#paint_linear_25)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 35 | + </g> | ||
| 36 | + </g> | ||
| 37 | + </g> | ||
| 38 | +</svg> | ||
| @@ -0,0 +1 @@ | |||
| 1 | +{ "meta": { "title": "CANNBot DSH", "description": "CANNBot interface with independent workflow packages, per-workflow updates, rollback and automatic workspace initialization.", "detail": "README.md" } } | ||
| @@ -0,0 +1 @@ | |||
| 1 | +{ "meta": { "title": "CANNBot DSH", "description": "品牌界面与独立工作流包,支持逐项更新、回退及工作区自动初始化。", "detail": "README.md" } } | ||
| @@ -0,0 +1,50 @@ | |||
| 1 | +{ | ||
| 2 | + "repository": "https://gitcode.com/cann/cannbot.git", | ||
| 3 | + "plugins": [ | ||
| 4 | + { | ||
| 5 | + "id": "ops-direct-invoke-flash", | ||
| 6 | + "label": "flash", | ||
| 7 | + "title": "Ascend C Flash 核函数开发" | ||
| 8 | + }, | ||
| 9 | + { | ||
| 10 | + "id": "ops-direct-invoke", | ||
| 11 | + "label": "operator", | ||
| 12 | + "title": "算子开发工作流" | ||
| 13 | + }, | ||
| 14 | + { | ||
| 15 | + "id": "ops-registry-invoke", | ||
| 16 | + "label": "registry", | ||
| 17 | + "title": "ACLNN / GEIR 注册算子开发" | ||
| 18 | + }, | ||
| 19 | + { | ||
| 20 | + "id": "model-infer-optimize", | ||
| 21 | + "label": "model", | ||
| 22 | + "title": "NPU 模型推理优化" | ||
| 23 | + }, | ||
| 24 | + { | ||
| 25 | + "id": "hccl-op-generator", | ||
| 26 | + "label": "hccl", | ||
| 27 | + "title": "HCCL 通信算子开发" | ||
| 28 | + }, | ||
| 29 | + { | ||
| 30 | + "id": "triton-op-generator", | ||
| 31 | + "label": "triton", | ||
| 32 | + "title": "Triton 算子开发" | ||
| 33 | + }, | ||
| 34 | + { | ||
| 35 | + "id": "catlass-op-generator", | ||
| 36 | + "label": "catlass", | ||
| 37 | + "title": "CATLASS 算子开发" | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "id": "ops-perf-optimize", | ||
| 41 | + "label": "performance", | ||
| 42 | + "title": "Ascend C 性能调优" | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + "id": "pypto-op-orchestrator", | ||
| 46 | + "label": "pypto", | ||
| 47 | + "title": "PyPTO 算子开发" | ||
| 48 | + } | ||
| 49 | + ] | ||
| 50 | +} | ||
| @@ -0,0 +1,95 @@ | |||
| 1 | +{ | ||
| 2 | + "name": "@cannbot-plugin/cannbot-dsh", | ||
| 3 | + "version": "1.0.0-alpha.1", | ||
| 4 | + "description": "CANNBot DSH: Ascend development workbench with independently versioned workflow packages", | ||
| 5 | + "type": "module", | ||
| 6 | + "license": "SEE LICENSE IN LICENSE", | ||
| 7 | + "main": "lib/index.js", | ||
| 8 | + "exports": { | ||
| 9 | + ".": "./lib/index.js", | ||
| 10 | + "./client": "./lib/client.js", | ||
| 11 | + "./package.json": "./package.json", | ||
| 12 | + "./cordis.patch.yml": "./cordis.patch.yml", | ||
| 13 | + "./locale/*.json": "./locale/*.json" | ||
| 14 | + }, | ||
| 15 | + "files": [ | ||
| 16 | + "lib", | ||
| 17 | + "workflow-defaults.json", | ||
| 18 | + "locale", | ||
| 19 | + "cordis.patch.yml", | ||
| 20 | + "icon.svg", | ||
| 21 | + "README.md", | ||
| 22 | + "WORKFLOW_PUBLISHING.md", | ||
| 23 | + "THIRD_PARTY_NOTICES.md", | ||
| 24 | + "LICENSE", | ||
| 25 | + "official-plugins.json" | ||
| 26 | + ], | ||
| 27 | + "icon": "./icon.svg", | ||
| 28 | + "dsh": { | ||
| 29 | + "bundle": { | ||
| 30 | + "patch": "./cordis.patch.yml" | ||
| 31 | + }, | ||
| 32 | + "client": { | ||
| 33 | + "platform": "web", | ||
| 34 | + "inject": [ | ||
| 35 | + "@deepseek-ai/dsh-client-ui-conversation", | ||
| 36 | + "@deepseek-ai/dsh-client-ui-sidebar", | ||
| 37 | + "@deepseek-ai/dsh-client-ui-theme", | ||
| 38 | + "@deepseek-ai/dsh-client-locale" | ||
| 39 | + ] | ||
| 40 | + } | ||
| 41 | + }, | ||
| 42 | + "engines": { | ||
| 43 | + "node": ">=24.9.0", | ||
| 44 | + "dsh": ">=0.1.1-rc.1 <0.3.0" | ||
| 45 | + }, | ||
| 46 | + "publishConfig": { | ||
| 47 | + "access": "public", | ||
| 48 | + "registry": "https://registry.npmjs.org/" | ||
| 49 | + }, | ||
| 50 | + "keywords": [ | ||
| 51 | + "dsh", | ||
| 52 | + "cannbot", | ||
| 53 | + "workbench", | ||
| 54 | + "ascend" | ||
| 55 | + ], | ||
| 56 | + "peerDependencies": { | ||
| 57 | + "@deepseek-ai/cordis": "^4.0.1", | ||
| 58 | + "@deepseek-ai/dsh-skill-filesystem": ">=0.1.1-0 <0.3.0", | ||
| 59 | + "@deepseek-ai/schemastery": ">=3.18.0 <4", | ||
| 60 | + "@deepseek-ai/dsh-llm": ">=0.1.1-0 <0.3.0", | ||
| 61 | + "@deepseek-ai/dsh-skill": ">=0.1.1-0 <0.3.0", | ||
| 62 | + "@deepseek-ai/dsh-tools": ">=0.2.1-0 <0.3.0" | ||
| 63 | + }, | ||
| 64 | + "dependencies": { | ||
| 65 | + "pacote": "^21.0.3", | ||
| 66 | + "@cannbot-plugin/workflow-catalog": "^1.0.4" | ||
| 67 | + }, | ||
| 68 | + "devDependencies": { | ||
| 69 | + "yaml": "^2.4.2" | ||
| 70 | + }, | ||
| 71 | + "peerDependenciesMeta": { | ||
| 72 | + "@deepseek-ai/dsh-skill-filesystem": { | ||
| 73 | + "optional": true | ||
| 74 | + }, | ||
| 75 | + "@deepseek-ai/schemastery": { | ||
| 76 | + "optional": true | ||
| 77 | + }, | ||
| 78 | + "@deepseek-ai/dsh-llm": { | ||
| 79 | + "optional": true | ||
| 80 | + }, | ||
| 81 | + "@deepseek-ai/dsh-skill": { | ||
| 82 | + "optional": true | ||
| 83 | + }, | ||
| 84 | + "@deepseek-ai/dsh-tools": { | ||
| 85 | + "optional": true | ||
| 86 | + } | ||
| 87 | + }, | ||
| 88 | + "scripts": { | ||
| 89 | + "build": "node scripts/build.mjs", | ||
| 90 | + "test": "vitest run", | ||
| 91 | + "typecheck": "tsc --noEmit", | ||
| 92 | + "pack:plugin": "node scripts/package.mjs", | ||
| 93 | + "install:source": "node scripts/install-source.mjs" | ||
| 94 | + } | ||
| 95 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +MIT License | ||
| 2 | + | ||
| 3 | +Copyright (c) 2026 CANNBot contributors | ||
| 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. | ||
| @@ -0,0 +1,45 @@ | |||
| 1 | +# CANNBot DSH 一键安装器 | ||
| 2 | + | ||
| 3 | +需要 **Node.js 24.9.0 或更新版本(含 npm/npx)**,且必须在 Linux 或 WSL 终端执行(Windows PowerShell 会被拒绝): | ||
| 4 | + | ||
| 5 | +```sh | ||
| 6 | +npx @cannbot-plugin/cannbot-dsh-install@latest | ||
| 7 | +``` | ||
| 8 | + | ||
| 9 | +安装官方 **DSH Web**、最新 CANNBot DSH 和目录中全部默认工作流,核验完整后启动 Web 界面。本工具不安装 Windows Electron 桌面客户端,不修改 DSH 核心,不需要管理员权限,也不改动已有 Desktop 或其他 DSH 安装。 | ||
| 10 | + | ||
| 11 | +本工具使用经过 CANNBot 验证的官方 `@deepseek-ai/dsh@0.2.1-rc.3` 与 `pnpm@11.28.5`。主插件、目录和默认工作流在每次安装时查询所选 registry 的 `latest`,再使用查询得到的确切版本安装;逐项核对实际版本与资源文件。短包与主包发布尚未同步、版本不兼容、网络失败或文件缺失时会报错,不会把旧版或不完整安装报告为成功。 | ||
| 12 | + | ||
| 13 | +固定版本的运行时依赖优先复用 npm 缓存,缺失时再下载;这不会影响主插件和工作流的 latest 查询。首次下载官方完整依赖可能需要较长时间,请等待各阶段完成。中途失败后可重新执行,只有 npm 安装完整结束的运行时才会被标记为可复用。 | ||
| 14 | + | ||
| 15 | +所有阶段使用同一个独立用户目录。安装仅调用标准 npm 和 DSH 官方插件命令;工作流确切版本通过该独立 Web profile 的标准 pnpm overrides 指定,不关闭全局发布时间观察期或其他安全策略。主插件安装时一起下载默认工作流,不需要启用后再后台补装。后续仍可在工作流管理中独立更新、回退;已有工作流缓存与固定回退版本由插件保留。 | ||
| 16 | + | ||
| 17 | +## Linux 服务器 | ||
| 18 | + | ||
| 19 | +```sh | ||
| 20 | +npx @cannbot-plugin/cannbot-dsh-install@latest --no-open | ||
| 21 | +``` | ||
| 22 | + | ||
| 23 | +服务仅监听 `127.0.0.1`,保留终端,按 Ctrl+C 停止。默认端口 3080 已占用时自动选择空闲端口,也可用 `--port 3081` 指定。远程访问请使用自己的 SSH 端口转发,并打开 DSH 打印的完整认证链接(包含 token);工具不公开服务端口、不关闭认证、不安装系统服务。 | ||
| 24 | + | ||
| 25 | +## 仅安装 / 再次启动 | ||
| 26 | + | ||
| 27 | +```sh | ||
| 28 | +npx @cannbot-plugin/cannbot-dsh-install@latest --no-start | ||
| 29 | +npx @cannbot-plugin/cannbot-dsh-install@latest --start-only | ||
| 30 | +``` | ||
| 31 | + | ||
| 32 | +`--no-start` 完成安装与文件验证后退出;`--start-only` 使用已安装环境,不查询新版本。默认命令再次执行会重新查询插件和工作流版本,复用兼容运行时。运行中的该环境需要先在原终端 Ctrl+C 停止,再进行安装更新。 | ||
| 33 | + | ||
| 34 | +首次打开后由用户配置模型账号或 API Key。工作目录相关的外部依赖在选择工作流时由原版 CANNBot 安装器初始化,仍需要相应网络、Git 和开发环境。 | ||
| 35 | + | ||
| 36 | +## 目录与安装源 | ||
| 37 | + | ||
| 38 | +- Linux / WSL:`${XDG_DATA_HOME:-~/.local/share}/cannbot-dsh` | ||
| 39 | +- 运行时位于 `runtime/`,独立 DSH 数据位于 `home/`。 | ||
| 40 | +- `--dir <新目录>` 可选择其他路径,后续启动也须传入同一路径。已有非空、非本安装器所有的目录会被拒绝。 | ||
| 41 | +- `--registry https://registry.npmmirror.com/` 可指定 HTTPS npm 镜像;此时 latest 来自该镜像,可能比 npm 官方源滞后。默认源为 `https://registry.npmjs.org/`。 | ||
| 42 | + | ||
| 43 | +工具不写入系统 PATH。保留了 DSH 原生带认证链接的输出及浏览器启动行为。需要卸载时,在停止服务后移除本工具的独立安装目录即可;其中 `home/` 包含此环境的用户配置与会话,删除前请自行备份。 | ||
| 44 | + | ||
| 45 | +DSH 为 DeepSeek AI 提供的独立开源项目,本工具只编排其公开安装、配置和启动入口。 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +#!/usr/bin/env node | ||
| 2 | +import { main } from '../lib/installer.mjs' | ||
| 3 | +main().catch(error => { console.error(`\n操作未完成:${error.message}`); process.exitCode = 1 }) | ||
| @@ -0,0 +1 @@ | |||
| 1 | +export function acquireFileLock(path: string, timeout?: number): Promise<() => void>; | ||
| @@ -0,0 +1,26 @@ | |||
| 1 | +import { DatabaseSync } from 'node:sqlite' | ||
| 2 | +import { mkdir, open } from 'node:fs/promises' | ||
| 3 | +import { dirname } from 'node:path' | ||
| 4 | + | ||
| 5 | +/** Never unlink this inode. The kernel releases the SQLite transaction on exit. | ||
| 6 | + * The suffix separates legacy JSON locks from the database format. */ | ||
| 7 | +export async function acquireFileLock(path, timeout = 0) { | ||
| 8 | + await mkdir(dirname(path), { recursive: true }) | ||
| 9 | + const file = path + '.sqlite3' | ||
| 10 | + const handle = await open(file, 'a', 0o600) | ||
| 11 | + await handle.close() | ||
| 12 | + const database = new DatabaseSync(file) | ||
| 13 | + const deadline = Date.now() + timeout | ||
| 14 | + try { | ||
| 15 | + for (;;) { | ||
| 16 | + try { database.exec('BEGIN EXCLUSIVE'); break } | ||
| 17 | + catch (error) { | ||
| 18 | + if (error.errcode !== 5) throw error // SQLITE_BUSY | ||
| 19 | + if (Date.now() >= deadline) throw new Error('Another installation or content operation is still running') | ||
| 20 | + await new Promise(resolve => setTimeout(resolve, Math.min(250, Math.max(1, deadline - Date.now())))) | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + } catch (error) { database.close(); throw error } | ||
| 24 | + let released = false | ||
| 25 | + return () => { if (!released) { released = true; database.close() } } | ||
| 26 | +} | ||
| @@ -0,0 +1,179 @@ | |||
| 1 | +import { acquireFileLock } from './file-lock.mjs' | ||
| 2 | +import { spawn } from 'node:child_process' | ||
| 3 | +import { existsSync, readFileSync, realpathSync } from 'node:fs' | ||
| 4 | +import { mkdir, writeFile, readFile, readdir, unlink, rename } from 'node:fs/promises' | ||
| 5 | +import { homedir } from 'node:os' | ||
| 6 | +import { dirname, join, resolve, delimiter, relative, isAbsolute } from 'node:path' | ||
| 7 | +import { createRequire } from 'node:module' | ||
| 8 | +import net from 'node:net' | ||
| 9 | +import { randomUUID } from 'node:crypto' | ||
| 10 | +import semver from 'semver' | ||
| 11 | +import { parse, stringify } from 'yaml' | ||
| 12 | +import { DSH_VERSION, PNPM_VERSION, PLUGIN, CORE, CATALOG, REGISTRY, registryUrl, resolvePlan, manifest } from './plan.mjs' | ||
| 13 | + | ||
| 14 | +const MARK = 'cannbot-dsh-install-v1' | ||
| 15 | +const readJson = file => JSON.parse(readFileSync(file, 'utf8')) | ||
| 16 | +const alive = pid => { try { process.kill(pid, 0); return true } catch (e) { return e.code !== 'ESRCH' } } | ||
| 17 | +const defaultRoot = () => join(process.env.XDG_DATA_HOME || join(homedir(), '.local/share'), 'cannbot-dsh') | ||
| 18 | +export function options(args) { | ||
| 19 | + const result = { root: defaultRoot(), registry: REGISTRY, port: undefined, start: true, open: true, startOnly: false } | ||
| 20 | + for (let i = 0; i < args.length; i++) { | ||
| 21 | + const arg = args[i] | ||
| 22 | + if (arg === '--no-start') result.start = false | ||
| 23 | + else if (arg === '--no-open') result.open = false | ||
| 24 | + else if (arg === '--start-only') result.startOnly = true | ||
| 25 | + else if (['--dir', '--registry', '--port'].includes(arg)) { | ||
| 26 | + const value = args[++i] | ||
| 27 | + if (!value || value.startsWith('--')) throw Error(`${arg} 缺少参数`) | ||
| 28 | + if (arg === '--dir') result.root = resolve(value) | ||
| 29 | + if (arg === '--registry') result.registry = registryUrl(value) | ||
| 30 | + if (arg === '--port') { if (!/^\d+$/.test(value) || +value < 1 || +value > 65535) throw Error('端口应在 1–65535 之间'); result.port = +value } | ||
| 31 | + } else throw Error(`未知参数:${arg}`) | ||
| 32 | + } | ||
| 33 | + result.root = resolve(result.root) | ||
| 34 | + return result | ||
| 35 | +} | ||
| 36 | +export async function claimRoot(root) { | ||
| 37 | + await mkdir(root, { recursive: true }) | ||
| 38 | + const marker = join(root, 'installer.json') | ||
| 39 | + if (existsSync(marker)) { if (readJson(marker).owner !== MARK) throw Error('此目录由其他程序管理,请选择新的 --dir'); return } | ||
| 40 | + if ((await readdir(root)).length) throw Error('安装目录非空且不属于本安装器,请选择新的 --dir') | ||
| 41 | + await writeFile(marker, JSON.stringify({ owner: MARK, created: new Date().toISOString() }), { mode: 0o600, flag: 'wx' }) | ||
| 42 | +} | ||
| 43 | +const lock = root => acquireFileLock(join(root, 'install.lock')) | ||
| 44 | +export function npmCli() { | ||
| 45 | + const candidates = [process.env.npm_execpath, join(dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js'), join(dirname(process.execPath), '../lib/node_modules/npm/bin/npm-cli.js')] | ||
| 46 | + for (const directory of (process.env.PATH || '').split(delimiter)) for (const file of ['npm']) { | ||
| 47 | + try { candidates.push(realpathSync(join(directory, file))) } catch {} | ||
| 48 | + } | ||
| 49 | + for (let candidate of candidates.filter(Boolean)) { | ||
| 50 | + if (candidate.endsWith('npx-cli.js')) candidate = join(dirname(candidate), 'npm-cli.js') | ||
| 51 | + if (existsSync(candidate) && (candidate.endsWith('npm-cli.js') || candidate.endsWith('/bin/npm'))) return candidate | ||
| 52 | + } | ||
| 53 | + throw Error('找不到 npm CLI,请使用包含 npm/npx 的 Node.js 安装') | ||
| 54 | +} | ||
| 55 | +export function reusableRuntimeLock(runtime) { | ||
| 56 | + try { | ||
| 57 | + const pkg = readJson(join(runtime, 'package.json')), lock = readJson(join(runtime, 'package-lock.json')) | ||
| 58 | + return pkg.dependencies?.['@deepseek-ai/dsh'] === DSH_VERSION && pkg.dependencies?.pnpm === PNPM_VERSION | ||
| 59 | + && lock.packages?.['node_modules/@deepseek-ai/dsh']?.version === DSH_VERSION && lock.packages?.['node_modules/pnpm']?.version === PNPM_VERSION | ||
| 60 | + } catch { return false } | ||
| 61 | +} | ||
| 62 | +function run(file, args, { env = process.env, cwd = process.cwd(), onSpawn, allowInterrupt = false } = {}) { | ||
| 63 | + return new Promise((accept, reject) => { | ||
| 64 | + const child = spawn(process.execPath, [file, ...args], { env, cwd, stdio: 'inherit' }) | ||
| 65 | + const signal = name => { try { child.kill(name) } catch {} } | ||
| 66 | + const interrupt = () => signal('SIGINT'), terminate = () => signal('SIGTERM') | ||
| 67 | + process.on('SIGINT', interrupt); process.on('SIGTERM', terminate) | ||
| 68 | + const clear = () => { process.off('SIGINT', interrupt); process.off('SIGTERM', terminate) } | ||
| 69 | + child.on('error', error => { clear(); reject(error) }) | ||
| 70 | + child.on('spawn', () => { try { if (onSpawn) onSpawn(child.pid) } catch (error) { signal('SIGTERM'); clear(); reject(error) } }) | ||
| 71 | + child.on('exit', (code, sig) => { clear(); code === 0 || allowInterrupt && (['SIGINT', 'SIGTERM'].includes(sig) || [130, 143, 3221225786].includes(code)) ? accept() : reject(Error(`子命令未完成(退出码 ${code ?? sig}),请查看上方日志后重试`)) }) | ||
| 72 | + }) | ||
| 73 | +} | ||
| 74 | +export function verify(home, plan) { | ||
| 75 | + const profile = join(home, 'profiles/web'), pluginFile = join(profile, 'node_modules', PLUGIN, 'package.json') | ||
| 76 | + const plugin = readJson(pluginFile), requireCore = createRequire(pluginFile) | ||
| 77 | + const coreFile = requireCore.resolve(`${CORE}/package.json`), core = readJson(coreFile) | ||
| 78 | + const catalogFile = createRequire(coreFile).resolve(`${CATALOG}/package.json`), catalog = readJson(catalogFile), resources = createRequire(catalogFile) | ||
| 79 | + if (plugin.version !== plan.plugin || core.version !== plan.core || catalog.version !== plan.catalog) throw Error('安装版本与查询到的 latest 不一致,未报告成功') | ||
| 80 | + for (const expected of plan.workflows) { | ||
| 81 | + const file = resources.resolve(`${expected.package}/package.json`), installed = readJson(file), descriptor = readJson(join(dirname(file), 'workflow.json')) | ||
| 82 | + if (installed.version !== expected.version || descriptor.id !== expected.id || descriptor.version !== expected.version || !descriptor.skills?.length) throw Error(`工作流未正确安装:${expected.id}`) | ||
| 83 | + for (const skill of descriptor.skills) { | ||
| 84 | + const resource = resolve(dirname(file), 'resources', skill.path), inside = relative(resolve(dirname(file), 'resources'), resource) | ||
| 85 | + if (inside.startsWith('..') || isAbsolute(inside) || !existsSync(resource)) throw Error(`工作流资源不完整:${expected.id}`) | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + if (!readJson(join(profile, 'package.json')).dsh?.profile?.bundles?.includes(PLUGIN)) throw Error('插件已下载但未加入 Web 启用列表,请重试安装') | ||
| 89 | + return { plugin: plan.plugin, catalog: plan.catalog, workflowCount: plan.workflows.length } | ||
| 90 | +} | ||
| 91 | +export async function freePort(port) { | ||
| 92 | + const listen = number => new Promise((accept, reject) => { | ||
| 93 | + const server = net.createServer(); server.once('error', reject) | ||
| 94 | + server.listen(number, '127.0.0.1', () => { const chosen = server.address().port; server.close(error => error ? reject(error) : accept(chosen)) }) | ||
| 95 | + }) | ||
| 96 | + try { return await listen(port ?? 3080) } catch (error) { | ||
| 97 | + if (port !== undefined || error.code !== 'EADDRINUSE') throw Error(`无法使用端口 ${port ?? 3080}:${error.message}`) | ||
| 98 | + return listen(0) | ||
| 99 | + } | ||
| 100 | +} | ||
| 101 | +export async function main(args = process.argv.slice(2)) { | ||
| 102 | + if (args.includes('--help') || args.includes('-h')) { | ||
| 103 | + console.log('CANNBot DSH 一键安装器\n用法:npx @cannbot-plugin/cannbot-dsh-install@latest [选项]\n\n默认:安装官方 DSH Web、最新插件及默认工作流,完成后启动浏览器界面。\n--no-start 仅安装并验证\n--no-open 启动但不打开浏览器(服务器推荐)\n--start-only 复用已安装环境,不查询或安装新版本\n--port N 指定本机监听端口\n--dir PATH 指定独立安装目录\n--registry URL 指定 HTTPS npm 源(镜像的 latest 可能滞后)\n\n需要 Node.js >=24.9.0;Web 保持终端运行,Ctrl+C 停止服务。支持 Linux/WSL,请在 Linux 环境中执行。') | ||
| 104 | + return | ||
| 105 | + } | ||
| 106 | + if (args.includes('--version')) { console.log('1.0.0'); return } | ||
| 107 | + if (process.platform !== 'linux') throw Error('本版安装器仅支持 Linux/WSL,请在 Linux 环境中执行') | ||
| 108 | + if (!semver.satisfies(process.versions.node, '>=24.9.0')) throw Error('请先安装 Node.js 24.9.0 或更新版本(包含 npm/npx)') | ||
| 109 | + const opt = options(args), root = opt.root, runtime = join(root, 'runtime'), home = join(root, 'home'), record = join(root, 'installed.json'), serverFile = join(root, 'server.json') | ||
| 110 | + await claimRoot(root) | ||
| 111 | + const release = await lock(root) | ||
| 112 | + const dsh = join(runtime, 'node_modules/@deepseek-ai/dsh/lib/bin.js') | ||
| 113 | + const runtimeReady = join(runtime, 'ready.json') | ||
| 114 | + const identity = { dsh: DSH_VERSION, pnpm: PNPM_VERSION, nodeMajor: semver.major(process.versions.node), platform: process.platform, arch: process.arch } | ||
| 115 | + const env = { ...process.env, DSH_HOME: home, CANNBOT_DSH_WORKFLOW_ROOT: join(home, 'cannbot-dsh-workflows'), PATH: join(runtime, 'node_modules/.bin') + delimiter + (process.env.PATH || '') } | ||
| 116 | + let plan | ||
| 117 | + try { | ||
| 118 | + if (existsSync(serverFile) && alive(readJson(serverFile).pid)) throw Error('此环境的 Web 服务已运行,请在原终端按 Ctrl+C 停止后重试') | ||
| 119 | + if (opt.startOnly) { | ||
| 120 | + if (!existsSync(record)) throw Error('尚未完成安装,请先不带 --start-only 运行') | ||
| 121 | + plan = readJson(record).plan; verify(home, plan) | ||
| 122 | + if (!existsSync(dsh)) throw Error('DSH 文件缺失,请重新运行安装命令') | ||
| 123 | + try { if (JSON.stringify(readJson(runtimeReady)) !== JSON.stringify(identity)) throw Error() } catch { throw Error('运行时安装尚未完整完成,请先不带 --start-only 重新执行安装') } | ||
| 124 | + } else { | ||
| 125 | + console.log('[1/5] 查询 CANNBot DSH 和默认工作流的 latest 版本…') | ||
| 126 | + plan = await resolvePlan(name => manifest(name, opt.registry)) | ||
| 127 | + console.log(`主插件 ${plan.plugin};目录 ${plan.catalog};${plan.workflows.length} 个默认工作流。`) | ||
| 128 | + console.log(`[2/5] 准备官方 DSH ${DSH_VERSION} 和 pnpm ${PNPM_VERSION}…`) | ||
| 129 | + await mkdir(runtime, { recursive: true }) | ||
| 130 | + const runtimeManifest = join(runtime, 'package.json') | ||
| 131 | + if (!existsSync(runtimeManifest)) await writeFile(runtimeManifest, JSON.stringify({ name: 'cannbot-dsh-private-runtime', private: true }), { flag: 'wx' }) | ||
| 132 | + const pnpmFile = join(runtime, 'node_modules/pnpm/package.json') | ||
| 133 | + let ready = false | ||
| 134 | + try { ready = existsSync(dsh) && readJson(join(runtime, 'node_modules/@deepseek-ai/dsh/package.json')).version === DSH_VERSION && readJson(pnpmFile).version === PNPM_VERSION && JSON.stringify(readJson(runtimeReady)) === JSON.stringify(identity) } catch {} | ||
| 135 | + if (!ready) { | ||
| 136 | + // An interrupted npm operation can leave manifests present while other | ||
| 137 | + // dependencies are missing. Only a completed transaction is reusable. | ||
| 138 | + await writeFile(runtimeReady, JSON.stringify({ ready: false }), { mode: 0o600 }) | ||
| 139 | + const locked = reusableRuntimeLock(runtime) | ||
| 140 | + await run(npmCli(), [locked ? 'ci' : 'install', '--prefix', runtime, '--global=false', '--omit=dev', '--prefer-offline', '--no-audit', '--no-fund', '--fetch-retries=2', '--fetch-timeout=120000', `--registry=${opt.registry}`, ...(locked ? [] : ['--save-exact', `@deepseek-ai/dsh@${DSH_VERSION}`, `pnpm@${PNPM_VERSION}`])], { env }) | ||
| 141 | + const temporary = join(runtime, `ready-${randomUUID()}.json`) | ||
| 142 | + await writeFile(temporary, JSON.stringify(identity), { mode: 0o600 }); await rename(temporary, runtimeReady) | ||
| 143 | + } | ||
| 144 | + console.log('[3/5] 通过 DSH 官方命令安装主插件和全部默认工作流…') | ||
| 145 | + // Initialize only this installation's own web profile; never touch Desktop. | ||
| 146 | + await run(dsh, ['plugin', '--profile', 'web', 'install', `--registry=${opt.registry}`], { env }) | ||
| 147 | + const workspaceFile = join(home, 'profiles/web/pnpm-workspace.yaml') | ||
| 148 | + const workspace = parse(await readFile(workspaceFile, 'utf8')) ?? {} | ||
| 149 | + workspace.overrides = { ...workspace.overrides, [CATALOG]: plan.catalog, ...Object.fromEntries(plan.workflows.map(w => [w.package, w.version])) } | ||
| 150 | + await writeFile(workspaceFile, stringify(workspace)) | ||
| 151 | + await run(dsh, ['plugin', '--profile', 'web', 'add', `${PLUGIN}@${plan.plugin}`, '--save-exact', `--registry=${opt.registry}`], { env }) | ||
| 152 | + // A prior interrupted pnpm operation may have left the package present but | ||
| 153 | + // outside the active bundle list. Repair using official commands only. | ||
| 154 | + if (!readJson(join(home, 'profiles/web/package.json')).dsh?.profile?.bundles?.includes(PLUGIN)) { | ||
| 155 | + await run(dsh, ['plugin', '--profile', 'web', 'remove', PLUGIN], { env }) | ||
| 156 | + await run(dsh, ['plugin', '--profile', 'web', 'add', `${PLUGIN}@${plan.plugin}`, '--save-exact', `--registry=${opt.registry}`], { env }) | ||
| 157 | + } | ||
| 158 | + console.log('[4/5] 核对主插件版本、启用状态和每个工作流资源文件…') | ||
| 159 | + const verified = verify(home, plan) | ||
| 160 | + const tmp = join(root, `installed-${randomUUID()}.json`) | ||
| 161 | + await writeFile(tmp, JSON.stringify({ owner: MARK, plan, verified, installedAt: new Date().toISOString() }, null, 2), { mode: 0o600 }) | ||
| 162 | + await rename(tmp, record) | ||
| 163 | + console.log(`安装完成:CANNBot DSH ${plan.plugin},${verified.workflowCount} 个工作流已到齐。`) | ||
| 164 | + } | ||
| 165 | + } finally { await release() } | ||
| 166 | + if (!opt.start) { console.log('已完成安装验证。下次使用同一命令加 --start-only 启动。'); return } | ||
| 167 | + const releaseStart = await lock(root) | ||
| 168 | + let serverPid | ||
| 169 | + try { | ||
| 170 | + if (existsSync(serverFile) && alive(readJson(serverFile).pid)) throw Error('此环境的 Web 服务已运行') | ||
| 171 | + const port = await freePort(opt.port) | ||
| 172 | + console.log(`[5/5] 启动 DSH Web(127.0.0.1:${port})。首次使用请在界面中配置账号或 API Key。\n请保留终端;Ctrl+C 停止服务。使用 DSH 打印或自动打开的完整认证链接。`) | ||
| 173 | + await run(dsh, ['web', '--host', '127.0.0.1', '--port', String(port), ...(opt.open ? [] : ['--no-open'])], { env, allowInterrupt: true, onSpawn(pid) { serverPid = pid; /* Owned PID only; no authentication tokens are persisted. */ requireWrite(serverFile, { pid }); void releaseStart() } }) | ||
| 174 | + } finally { await releaseStart(); try { if (readJson(serverFile).pid === serverPid) await unlink(serverFile) } catch {} } | ||
| 175 | +} | ||
| 176 | +function requireWrite(file, value) { | ||
| 177 | + // This small synchronous write must finish before another installer can inspect it. | ||
| 178 | + createRequire(import.meta.url)('node:fs').writeFileSync(file, JSON.stringify(value), { mode: 0o600 }) | ||
| 179 | +} | ||
| @@ -0,0 +1,74 @@ | |||
| 1 | +import semver from 'semver' | ||
| 2 | +import https from 'node:https' | ||
| 3 | +import { gunzipSync, brotliDecompressSync, inflateSync } from 'node:zlib' | ||
| 4 | +export const DSH_VERSION = '0.2.1-rc.3' | ||
| 5 | +export const PNPM_VERSION = '11.28.5' | ||
| 6 | +export const PLUGIN = 'cannbot-dsh' | ||
| 7 | +export const CORE = '@cannbot-plugin/cannbot-dsh' | ||
| 8 | +export const CATALOG = '@cannbot-plugin/workflow-catalog' | ||
| 9 | +export const REGISTRY = 'https://registry.npmjs.org/' | ||
| 10 | +export function registryUrl(value) { | ||
| 11 | + const url = new URL(value) | ||
| 12 | + if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) throw Error('安装源必须是无凭据的 HTTPS registry 地址') | ||
| 13 | + return url.href.replace(/\/?$/, '/') | ||
| 14 | +} | ||
| 15 | +// npm metadata is small. Use the standard HTTPS client with normal certificate | ||
| 16 | +// validation; IPv4 avoids failed IPv6 routes on common server networks. | ||
| 17 | +function readManifest(url, redirects = 0) { | ||
| 18 | + return new Promise((accept, reject) => { | ||
| 19 | + const parsed = new URL(url) | ||
| 20 | + if (parsed.protocol !== 'https:' || parsed.username || parsed.password || redirects > 3) { reject(Error('无效的 registry 重定向')); return } | ||
| 21 | + let timer | ||
| 22 | + const request = https.get(parsed, { family: ['registry.npmjs.org', 'registry.npmmirror.com'].includes(parsed.hostname) ? 4 : undefined, headers: { accept: 'application/json', 'accept-encoding': 'identity', 'cache-control': 'no-cache' } }, response => { | ||
| 23 | + if ([301, 302, 303, 307, 308].includes(response.statusCode) && response.headers.location) { | ||
| 24 | + clearTimeout(timer); response.resume(); accept(readManifest(new URL(response.headers.location, parsed), redirects + 1)); return | ||
| 25 | + } | ||
| 26 | + if (response.statusCode !== 200) { clearTimeout(timer); response.resume(); reject(Error(`registry HTTP ${response.statusCode}`)); return } | ||
| 27 | + const chunks = []; let bytes = 0 | ||
| 28 | + response.on('error', error => { clearTimeout(timer); reject(error) }) | ||
| 29 | + response.on('data', chunk => { bytes += chunk.length; if (bytes > 4 * 1024 * 1024) request.destroy(Error('registry 元数据超出大小限制')); else chunks.push(chunk) }) | ||
| 30 | + response.on('end', () => { | ||
| 31 | + clearTimeout(timer) | ||
| 32 | + try { | ||
| 33 | + let data = Buffer.concat(chunks) | ||
| 34 | + const decode = { gzip: gunzipSync, br: brotliDecompressSync, deflate: inflateSync }[response.headers['content-encoding']] | ||
| 35 | + if (decode) data = decode(data, { maxOutputLength: 4 * 1024 * 1024 }) | ||
| 36 | + accept(JSON.parse(data.toString('utf8'))) | ||
| 37 | + } catch (error) { reject(error) } | ||
| 38 | + }) | ||
| 39 | + }) | ||
| 40 | + timer = setTimeout(() => request.destroy(Error('registry 查询超时')), 20000) | ||
| 41 | + request.on('error', error => { clearTimeout(timer); reject(error) }) | ||
| 42 | + }) | ||
| 43 | +} | ||
| 44 | +export async function manifest(name, registry = REGISTRY) { | ||
| 45 | + let last | ||
| 46 | + for (let attempt = 0; attempt < 3; attempt++) { | ||
| 47 | + try { | ||
| 48 | + const value = await readManifest(new URL(`${encodeURIComponent(name).replace(/^%40/, '@')}/latest`, registry)) | ||
| 49 | + if (value.name !== name || !semver.valid(value.version)) throw Error(`${name}: 无效的 npm 版本信息`) | ||
| 50 | + return value | ||
| 51 | + } catch (error) { last = error } | ||
| 52 | + } | ||
| 53 | + throw Error(`无法查询 ${name} 的 latest:${last.message}`) | ||
| 54 | +} | ||
| 55 | +export async function resolvePlan(lookup = manifest, nodeVersion = process.versions.node) { | ||
| 56 | + const plugin = await lookup(PLUGIN), core = await lookup(CORE), catalog = await lookup(CATALOG) | ||
| 57 | + if (plugin.dependencies?.[CORE] !== core.version) throw Error('短包和主插件 latest 尚未同步,请稍后重试') | ||
| 58 | + if (!semver.satisfies(DSH_VERSION, core.engines?.dsh ?? '', { includePrerelease: true })) throw Error('最新插件需要更新的 DSH,请更新此安装器后重试') | ||
| 59 | + if ([plugin, core, catalog].some(value => !semver.satisfies(nodeVersion, value.engines?.node ?? '*'))) throw Error('最新插件需要更新的 Node.js,请升级 Node.js 后重试') | ||
| 60 | + if (!semver.satisfies(catalog.version, core.dependencies?.[CATALOG] ?? '')) throw Error('latest 目录包与主插件不兼容') | ||
| 61 | + const entries = catalog.cannbotWorkflowCatalog?.workflows | ||
| 62 | + if (catalog.cannbotWorkflowCatalog?.schemaVersion !== 1 || !Array.isArray(entries) || !entries.length || new Set(entries.map(x => x.id)).size !== entries.length) throw Error('目录包格式不受支持') | ||
| 63 | + const workflows = [] | ||
| 64 | + for (const entry of entries) { | ||
| 65 | + if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(entry.id) || entry.package !== `@cannbot-plugin/workflow-${entry.id}` || typeof entry.default !== 'boolean') throw Error('工作流目录包含无效条目') | ||
| 66 | + if (!entry.default) continue | ||
| 67 | + const value = await lookup(entry.package) | ||
| 68 | + if (!semver.satisfies(nodeVersion, value.engines?.node ?? '*')) throw Error(`工作流需要更新的 Node.js:${entry.id}`) | ||
| 69 | + if (value.cannbotWorkflow?.schemaVersion !== 1 || value.cannbotWorkflow.id !== entry.id || !semver.satisfies(value.version, catalog.dependencies?.[entry.package] ?? '')) throw Error(`工作流包不兼容:${entry.id}`) | ||
| 70 | + workflows.push({ id: entry.id, package: entry.package, version: value.version }) | ||
| 71 | + } | ||
| 72 | + if (!workflows.length) throw Error('目录中没有默认工作流') | ||
| 73 | + return { plugin: plugin.version, core: core.version, catalog: catalog.version, dsh: DSH_VERSION, pnpm: PNPM_VERSION, workflows } | ||
| 74 | +} | ||
| @@ -0,0 +1,50 @@ | |||
| 1 | +{ | ||
| 2 | + "name": "@cannbot-plugin/cannbot-dsh-install", | ||
| 3 | + "version": "1.0.0", | ||
| 4 | + "lockfileVersion": 3, | ||
| 5 | + "requires": true, | ||
| 6 | + "packages": { | ||
| 7 | + "": { | ||
| 8 | + "name": "@cannbot-plugin/cannbot-dsh-install", | ||
| 9 | + "version": "1.0.0", | ||
| 10 | + "license": "MIT", | ||
| 11 | + "dependencies": { | ||
| 12 | + "semver": "^7.7.2", | ||
| 13 | + "yaml": "^2.8.1" | ||
| 14 | + }, | ||
| 15 | + "bin": { | ||
| 16 | + "cannbot-dsh-install": "bin/install.mjs" | ||
| 17 | + }, | ||
| 18 | + "engines": { | ||
| 19 | + "node": ">=24.9.0" | ||
| 20 | + } | ||
| 21 | + }, | ||
| 22 | + "node_modules/semver": { | ||
| 23 | + "version": "7.8.5", | ||
| 24 | + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", | ||
| 25 | + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", | ||
| 26 | + "license": "ISC", | ||
| 27 | + "bin": { | ||
| 28 | + "semver": "bin/semver.js" | ||
| 29 | + }, | ||
| 30 | + "engines": { | ||
| 31 | + "node": ">=10" | ||
| 32 | + } | ||
| 33 | + }, | ||
| 34 | + "node_modules/yaml": { | ||
| 35 | + "version": "2.9.1", | ||
| 36 | + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", | ||
| 37 | + "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", | ||
| 38 | + "license": "ISC", | ||
| 39 | + "bin": { | ||
| 40 | + "yaml": "bin.mjs" | ||
| 41 | + }, | ||
| 42 | + "engines": { | ||
| 43 | + "node": ">= 14.6" | ||
| 44 | + }, | ||
| 45 | + "funding": { | ||
| 46 | + "url": "https://github.com/sponsors/eemeli" | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | +} | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +{ | ||
| 2 | + "name": "@cannbot-plugin/cannbot-dsh-install", | ||
| 3 | + "version": "1.0.0", | ||
| 4 | + "description": "Install official DSH Web and the latest CANNBot DSH workflows with one command on Linux and WSL", | ||
| 5 | + "type": "module", | ||
| 6 | + "license": "MIT", | ||
| 7 | + "bin": { "cannbot-dsh-install": "bin/install.mjs" }, | ||
| 8 | + "files": ["bin", "lib", "README.md", "LICENSE"], | ||
| 9 | + "engines": { "node": ">=24.9.0" }, | ||
| 10 | + "dependencies": { "semver": "^7.7.2", "yaml": "^2.8.1" }, | ||
| 11 | + "scripts": { "test": "node --test" }, | ||
| 12 | + "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" }, | ||
| 13 | + "keywords": ["cannbot", "dsh", "installer", "workbench"] | ||
| 14 | +} | ||
| @@ -0,0 +1,74 @@ | |||
| 1 | +import test from 'node:test' | ||
| 2 | +import assert from 'node:assert/strict' | ||
| 3 | +import { mkdtemp, writeFile, mkdir, readFile } from 'node:fs/promises' | ||
| 4 | +import { tmpdir } from 'node:os' | ||
| 5 | +import { join } from 'node:path' | ||
| 6 | +import net from 'node:net' | ||
| 7 | +import { options, claimRoot, freePort, verify, reusableRuntimeLock } from '../lib/installer.mjs' | ||
| 8 | +import { resolvePlan, CORE, CATALOG, PLUGIN, DSH_VERSION, PNPM_VERSION } from '../lib/plan.mjs' | ||
| 9 | + | ||
| 10 | +const snapshot = () => ({ | ||
| 11 | + [PLUGIN]: { name: PLUGIN, version: '1.0.0-alpha.1', dependencies: { [CORE]: '1.0.0-alpha.1' } }, | ||
| 12 | + [CORE]: { name: CORE, version: '1.0.0-alpha.1', engines: { dsh: '>=0.1.1-rc.1 <0.3.0' }, dependencies: { [CATALOG]: '^1.0.4' } }, | ||
| 13 | + [CATALOG]: { name: CATALOG, version: '1.0.4', dependencies: { '@cannbot-plugin/workflow-flow-a': '>=1.0.0' }, cannbotWorkflowCatalog: { schemaVersion: 1, workflows: [{ id: 'flow-a', package: '@cannbot-plugin/workflow-flow-a', default: true }] } }, | ||
| 14 | + '@cannbot-plugin/workflow-flow-a': { version: '1.1.0', cannbotWorkflow: { schemaVersion: 1, id: 'flow-a' } }, | ||
| 15 | +}) | ||
| 16 | +test('resolves actual latest versions, including independently updated workflows', async () => { | ||
| 17 | + const values = snapshot(), requests = [] | ||
| 18 | + const plan = await resolvePlan(async name => { requests.push(name); return values[name] }) | ||
| 19 | + assert.equal(plan.plugin, '1.0.0-alpha.1'); assert.equal(plan.workflows[0].version, '1.1.0'); assert.equal(requests.length, 4) | ||
| 20 | +}) | ||
| 21 | +test('refuses out-of-sync short packages and incompatible DSH versions', async () => { | ||
| 22 | + const values = snapshot(); values[PLUGIN].dependencies[CORE] = '1.0.0-alpha.2' | ||
| 23 | + await assert.rejects(resolvePlan(async name => values[name]), /尚未同步/) | ||
| 24 | + values[PLUGIN].dependencies[CORE] = '1.0.0-alpha.1'; values[CORE].engines.dsh = '>=0.3.0' | ||
| 25 | + await assert.rejects(resolvePlan(async name => values[name]), /更新的 DSH/) | ||
| 26 | +}) | ||
| 27 | +test('rejects a foreign workflow publisher before installation', async () => { | ||
| 28 | + const values = snapshot(); values[CATALOG].cannbotWorkflowCatalog.workflows[0].package = '@foreign/flow-a' | ||
| 29 | + await assert.rejects(resolvePlan(async name => values[name]), /无效条目/) | ||
| 30 | +}) | ||
| 31 | +test('refuses newer Node requirements before downloading the runtime', async () => { | ||
| 32 | + const values = snapshot(); values[CORE].engines.node = '>=26' | ||
| 33 | + await assert.rejects(resolvePlan(async name => values[name], '24.9.0'), /更新的 Node.js/) | ||
| 34 | +}) | ||
| 35 | +test('validates options without allowing credential-bearing or insecure registries', () => { | ||
| 36 | + assert.equal(options(['--no-start', '--port', '3100']).port, 3100) | ||
| 37 | + for (const args of [['--registry', 'http://example.test'], ['--registry', 'https://user:pass@example.test'], ['--port', '0'], ['--dir'], ['--unknown']]) assert.throws(() => options(args)) | ||
| 38 | +}) | ||
| 39 | +test('reuses only installer-owned directories and preserves unrelated contents', async () => { | ||
| 40 | + const root = await mkdtemp(join(tmpdir(), 'cannbot-installer-test-')) | ||
| 41 | + await writeFile(join(root, 'keep.txt'), 'user data') | ||
| 42 | + await assert.rejects(claimRoot(root), /非空/) | ||
| 43 | + assert.equal(await readFile(join(root, 'keep.txt'), 'utf8'), 'user data') | ||
| 44 | + const owned = join(root, 'owned'); await claimRoot(owned); await claimRoot(owned) | ||
| 45 | +}) | ||
| 46 | +test('falls back from a busy default port, but never ignores an explicitly requested busy port', async () => { | ||
| 47 | + const server = net.createServer(); await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)) | ||
| 48 | + try { await assert.rejects(freePort(server.address().port), /无法使用端口/); assert(Number.isInteger(await freePort())) } | ||
| 49 | + finally { await new Promise(resolve => server.close(resolve)) } | ||
| 50 | +}) | ||
| 51 | +test('missing plugin resources cannot be reported as a successful installation', async () => { | ||
| 52 | + const root = await mkdtemp(join(tmpdir(), 'cannbot-installer-verification-')) | ||
| 53 | + const modules = join(root, 'profiles/web/node_modules') | ||
| 54 | + const values = snapshot(), plan = await resolvePlan(async name => values[name]) | ||
| 55 | + const put = async (name, value) => { await mkdir(join(modules, name), { recursive: true }); await writeFile(join(modules, name, 'package.json'), JSON.stringify(value)) } | ||
| 56 | + await put(PLUGIN, { version: plan.plugin }); await put(CORE, { version: plan.core }); await put(CATALOG, { version: plan.catalog }) | ||
| 57 | + await put(plan.workflows[0].package, { version: '1.1.0' }) | ||
| 58 | + const workflowRoot = join(modules, plan.workflows[0].package) | ||
| 59 | + await writeFile(join(workflowRoot, 'workflow.json'), JSON.stringify({ id: 'flow-a', version: '1.1.0', skills: [{ path: 'skills/flow-a/SKILL.md' }] })) | ||
| 60 | + await assert.rejects(async () => verify(root, plan), /资源不完整/) | ||
| 61 | + await mkdir(join(workflowRoot, 'resources/skills/flow-a'), { recursive: true }); await writeFile(join(workflowRoot, 'resources/skills/flow-a/SKILL.md'), 'verified') | ||
| 62 | + await writeFile(join(root, 'profiles/web/package.json'), JSON.stringify({ dsh: { profile: { bundles: [PLUGIN] } } })) | ||
| 63 | + assert.equal(verify(root, plan).workflowCount, 1) | ||
| 64 | +}) | ||
| 65 | +test('only a lockfile for the exact qualified runtime can be used for interrupted-install recovery', async () => { | ||
| 66 | + const runtime = await mkdtemp(join(tmpdir(), 'cannbot-runtime-lock-')) | ||
| 67 | + await writeFile(join(runtime, 'package.json'), JSON.stringify({ dependencies: { '@deepseek-ai/dsh': DSH_VERSION, pnpm: PNPM_VERSION } })) | ||
| 68 | + const lock = { packages: { 'node_modules/@deepseek-ai/dsh': { version: DSH_VERSION }, 'node_modules/pnpm': { version: PNPM_VERSION } } } | ||
| 69 | + await writeFile(join(runtime, 'package-lock.json'), JSON.stringify(lock)) | ||
| 70 | + assert.equal(reusableRuntimeLock(runtime), true) | ||
| 71 | + lock.packages['node_modules/@deepseek-ai/dsh'].version = '0.1.0' | ||
| 72 | + await writeFile(join(runtime, 'package-lock.json'), JSON.stringify(lock)) | ||
| 73 | + assert.equal(reusableRuntimeLock(runtime), false) | ||
| 74 | +}) | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +# CANNBot DSH | ||
| 2 | + | ||
| 3 | +`cannbot-dsh@1.0.0-alpha.1` 是 `@cannbot-plugin/cannbot-dsh@1.0.0-alpha.1` 的短包名入口,安装在原版 DSH 中,不修改核心。 | ||
| 4 | + | ||
| 5 | +在 **插件 → 添加插件** 中输入 `cannbot-dsh@1.0.0-alpha.1`。新版本受安装源同步及发布时间观察期影响时,请明确指定版本号。 | ||
| 6 | +Linux 也可执行: | ||
| 7 | + | ||
| 8 | +```sh | ||
| 9 | +dsh plugin --profile web add cannbot-dsh@1.0.0-alpha.1 | ||
| 10 | +dsh web | ||
| 11 | +``` | ||
| 12 | + | ||
| 13 | +安装时通过标准 npm 依赖一次装齐 3 个默认工作流包,目前加载 53 个 Skills;依赖下载失败会让安装阶段报错。首次启用等待本地资源准备完成,不会在后台补装子包。每个 `@cannbot-plugin/workflow-<ID>` 可独立更新和回退,无需升级主程序。目录包 `@cannbot-plugin/workflow-catalog` 用于发现新工作流。 | ||
| 14 | + | ||
| 15 | +启用后从左侧“CANNBot工作台”进入:沿用当前对话的工作区并展示真实路径,支持分类、搜索及圆形勾选工作流。选择卡片后聚焦输入框,不覆盖已有内容;点击“开始”后按实际进展显示准备状态并进入 DSH 原生对话。准备失败保留输入和文件,可展开原因并重试。工作流更新及日志统一在插件详情中管理。 | ||
| 16 | + | ||
| 17 | +插件详情提供逐项更新、回退、检查版本和更新全部。回退版本会固定,主动更新该项即可恢复跟随最新版。主程序自己的“检查更新”和一键升级保留。 | ||
| 18 | + | ||
| 19 | +选择工作目录和工作流时,Host 自动调用包内保留的上游 DSH 安装器准备该工作区;相同工作区和包版本不重复初始化。依赖仓库仍按上游声明获取,某些工作流首次准备需要 Git、网络及其运行条件。输入框不出现 `/工作流名称`,发送时在后台应用工作流。 | ||
| 20 | + | ||
| 21 | +首次下载需要网络;已安装工作流可离线加载。支持 Windows 桌面与 Linux Web,Node.js >=24.9,DSH >=0.1.1-rc.1 <0.3.0;图形管理依赖对应官方接口。界面开关默认开启,关闭后保留工作流能力。 | ||
| @@ -0,0 +1,12 @@ | |||
| 1 | +# Third-party notices | ||
| 2 | + | ||
| 3 | +This package is a DSH bundle entry that depends on the exact published | ||
| 4 | +`@cannbot-plugin/cannbot-dsh` version declared in package.json. | ||
| 5 | +That dependency includes all nine official CANNBot plugins and their declared | ||
| 6 | +shared Skills, with their original license and attribution. | ||
| 7 | +See the dependency's THIRD_PARTY_NOTICES.md and each workflow package's | ||
| 8 | +workflow.json and resources/LICENSE for the CANN Open Software License Agreement 2.0. | ||
| 9 | + | ||
| 10 | +The decorative C mark is the same mark developed for CANNBot DSH. | ||
| 11 | +DSH remains a separately installed product with its original license. | ||
| 12 | +No DSH executable or server runtime is redistributed by this package. | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +- insert: | ||
| 2 | + - id: cannbot-dsh | ||
| 3 | + name: '@cannbot-plugin/cannbot-dsh' | ||
| @@ -0,0 +1,38 @@ | |||
| 1 | +<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128.000000" height="128.000000" fill="none" customFrame="#000000"> | ||
| 2 | + <defs> | ||
| 3 | + <clipPath id="clipPath_12"> | ||
| 4 | + <rect width="128.000000" height="127.999954" x="0.000000" y="0.000000" fill="rgb(255,255,255)" /> | ||
| 5 | + </clipPath> | ||
| 6 | + <linearGradient id="paint_linear_22" x1="29.333334" x2="29.333334" y1="0" y2="73.9391937" gradientUnits="userSpaceOnUse"> | ||
| 7 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="0.300000012" /> | ||
| 8 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 9 | + </linearGradient> | ||
| 10 | + <linearGradient id="paint_linear_23" x1="38.9329453" x2="38.9329453" y1="21.3334961" y2="95.2726898" gradientUnits="userSpaceOnUse"> | ||
| 11 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="1" /> | ||
| 12 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 13 | + </linearGradient> | ||
| 14 | + <linearGradient id="paint_linear_24" x1="49.5993462" x2="49.5993462" y1="54.3999023" y2="71.0362244" gradientUnits="userSpaceOnUse"> | ||
| 15 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="1" /> | ||
| 16 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 17 | + </linearGradient> | ||
| 18 | + <linearGradient id="paint_linear_25" x1="78.4001312" x2="78.4001312" y1="54.3999023" y2="71.0362167" gradientUnits="userSpaceOnUse"> | ||
| 19 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="0.300000012" /> | ||
| 20 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 21 | + </linearGradient> | ||
| 22 | + </defs> | ||
| 23 | + <g id="cannbot-单logo"> | ||
| 24 | + <g id="容器 91334040" customFrame="url(#clipPath_12)"> | ||
| 25 | + <rect id="容器 91334040" width="128.000000" height="127.999954" x="0.000000" y="0.000000" /> | ||
| 26 | + <g id="组合 91334087"> | ||
| 27 | + <path id="矢量 6118" d="M54.656 0.0110097C54.6558 0.0110113 51.7668 3.67457e-05 51.7668 3.67457e-05C51.7668 3.67457e-05 51.7668 3.67636e-05 51.7667 3.68013e-05C51.6899 7.12161e-05 22.9847 0.0158011 22.8369 0.0110097C17.1909 -0.170211 12.3667 1.89873 8.09757 5.25809C2.0998 9.97218 0.125215 16.5951 0.0501712 23.826C-0.0509294 34.2225 0.0204758 43.0968 0.0918716 53.4933C0.0960407 54.0708 0.0996886 54.6486 0.103858 55.2261C0.106463 55.7419 0.108027 56.2585 0.109069 56.7758C0.115844 59.9923 0.122618 63.2318 0.573402 66.3923C2.21707 77.8358 11.1504 85.3226 22.7838 85.3226C23.0056 85.3226 36.8094 85.3316 37.3553 85.3333C39.2975 85.3333 40.6212 84.6508 41.4535 82.8483C42.9799 79.4889 44.6554 76.204 46.2136 72.8553C48.1777 68.6214 46.865 66.6696 42.1263 66.6696L25.9533 66.6696C25.6584 66.6696 25.3623 66.6714 25.0663 66.673L25.0658 66.673C24.0777 66.6787 23.086 66.6844 22.1005 66.6269C20.2969 66.5311 19.1441 65.3365 19.1441 63.5662L19.1441 21.6182C19.1441 20.1997 19.8591 19.24 21.1828 18.8879C22.3246 18.5893 23.5305 18.4294 24.7156 18.4294C36.3276 18.3974 30.8661 18.4081 42.478 18.4294C44.7835 18.4294 47.0891 18.5466 49.3941 18.5573C51.0273 18.5573 52.2864 17.9175 53.0019 16.3605C54.7414 12.5637 56.5665 8.82028 58.2419 5.00214C59.5015 2.12265 57.8578 -0.0210164 54.656 0.0216851L54.656 0.0110097Z" fill="rgb(199,0,11)" fill-rule="evenodd" transform="matrix(-1,0,0,-1,118.4,106.667)" /> | ||
| 28 | + <path id="矢量 6118" d="M51.7668 3.67457e-05L54.6558 0.0110092L54.656 0.0110097L54.6559 0.0193189L54.6559 0.021685L54.656 0.0216844L54.656 0.0216851C54.6897 0.0212351 54.7233 0.0210279 54.7567 0.0210619C54.7853 0.021091 54.8138 0.0212974 54.8422 0.0216798L54.8426 0.0216851C57.2018 0.0536275 58.6667 1.30361 58.6667 3.15649C58.6667 3.72147 58.5305 4.3425 58.2419 5.00214C56.5665 8.82028 54.7414 12.5637 53.0019 16.3605C52.2864 17.9175 51.0273 18.5573 49.3941 18.5573C47.0891 18.5466 44.7835 18.4294 42.478 18.4294C36.672 18.4188 35.1344 18.4107 33.5968 18.4094C32.3003 18.4083 31.0038 18.4119 27.1486 18.4227C26.4316 18.4247 25.6261 18.4269 24.7156 18.4294C23.5305 18.4294 22.3246 18.5893 21.1828 18.8879C19.8591 19.24 19.1441 20.1997 19.1441 21.6182L19.1441 63.5662C19.1441 65.3365 20.2969 66.5311 22.1005 66.6269C23.086 66.6844 24.0777 66.6787 25.0658 66.673L25.0663 66.673C25.3623 66.6714 25.6584 66.6696 25.9533 66.6696L42.1263 66.6696C45.4543 66.6696 47.0926 67.6323 47.0926 69.6722C47.0926 70.5368 46.7983 71.5949 46.2136 72.8553C44.6554 76.204 42.9799 79.4889 41.4535 82.8483C40.6212 84.6508 39.2975 85.3333 37.3553 85.3333C36.8094 85.3316 23.0056 85.3226 22.7838 85.3226C11.1504 85.3226 2.21707 77.8358 0.573402 66.3923C0.122618 63.2318 0.115844 59.9923 0.109069 56.7758C0.108027 56.2585 0.106463 55.7419 0.103858 55.2261C0.0996886 54.6486 0.0960407 54.0708 0.0918716 53.4933C0.0879818 52.9269 0.0840921 52.365 0.0802302 51.8071C0.0384871 45.7771 0 40.2174 0 34.5064C0 31.0478 0.0141155 27.5337 0.0501712 23.826C0.125215 16.5951 2.0998 9.97218 8.09757 5.25809C12.3667 1.89873 17.1909 -0.170211 22.8369 0.0110097C22.9793 0.0156241 49.6082 0.00120531 51.6439 0.000103038L51.7667 3.68013e-05L51.7668 3.67457e-05ZM51.7677 2.00004L51.7676 2.00004L51.7635 2.00004L37.3026 2.00734L22.8051 2.01102L22.7727 2.00998Q21.3984 1.96587 20.0475 2.12341L20.0474 2.12342L20.0473 2.12344Q14.4919 2.7714 9.33436 6.82983Q7.29064 8.43614 5.82839 10.4621L5.82836 10.4622Q4.54626 12.2385 3.71118 14.3376Q2.1069 18.37 2.05006 23.8467Q2.00886 28.084 2.00886 33.8733Q2.00886 41.4901 2.08018 51.7933C2.08533 52.5375 2.08921 53.0996 2.09182 53.4796L2.09781 54.3449L2.10381 55.2123L2.10906 56.7691L2.10907 56.7727C2.11354 58.8976 2.13499 60.4841 2.17341 61.5323C2.23634 63.2493 2.36299 64.7752 2.55336 66.1099C2.92521 68.6987 3.69419 71.0708 4.8603 73.2262Q5.90423 75.1556 7.31957 76.7568L7.31965 76.7569L7.32088 76.7583C7.90805 77.4224 8.54315 78.0442 9.22618 78.6235Q9.92308 79.2147 10.6703 79.7333L10.6705 79.7334L10.6708 79.7336L10.6726 79.7349Q12.7859 81.2012 15.3014 82.0877C17.6377 82.911 20.1318 83.3226 22.7838 83.3226L30.0778 83.3274L37.3569 83.3333Q38.3095 83.3333 38.8118 83.0398C39.1316 82.853 39.4069 82.5097 39.6377 82.0099C40.2064 80.7581 41.0905 78.8958 42.2898 76.4229C43.2395 74.4648 43.943 72.9943 44.4003 72.0116C44.7975 71.1552 45.0242 70.4515 45.0802 69.9004C45.0893 69.8103 45.0939 69.7287 45.0939 69.6557C45.0939 69.4828 45.0683 69.3578 45.017 69.2806C44.9365 69.1592 44.7362 69.0459 44.4163 68.9409C43.8655 68.76 43.1021 68.6696 42.1263 68.6696L25.9533 68.6696L25.091 68.6729L25.077 68.6729L25.0658 68.673C23.7112 68.6808 22.6839 68.6643 21.984 68.6235C21.0321 68.5729 20.1972 68.3297 19.4792 67.8939Q18.951 67.5733 18.5073 67.1138C18.1886 66.7837 17.9258 66.424 17.7188 66.0346C17.3357 65.3136 17.1441 64.4908 17.1441 63.5662L17.1441 21.6182Q17.1441 20.2633 17.7096 19.2128L17.7097 19.2126C17.8136 19.0197 17.9317 18.8345 18.0642 18.657C18.246 18.4133 18.4483 18.1926 18.6708 17.9948L18.6711 17.9946Q19.4873 17.2693 20.6688 16.9551C21.7413 16.6746 22.8196 16.5063 23.9036 16.4504C24.1739 16.4364 24.4446 16.4294 24.7156 16.4294L33.5923 16.4094L42.4825 16.4294C43.3025 16.4294 44.5266 16.4511 46.1547 16.4945C47.6035 16.533 48.6864 16.554 49.4033 16.5573C49.8805 16.5573 50.2577 16.4765 50.535 16.3148Q50.9267 16.0866 51.1846 15.5254C51.6208 14.5734 52.2822 13.1522 53.1688 11.2619Q55.3725 6.56395 56.4105 4.19848Q56.6759 3.59184 56.6759 3.1642C56.6759 2.95121 56.6265 2.77153 56.5277 2.62515C56.5219 2.61651 56.5159 2.60799 56.5098 2.59959Q56.0718 2.00298 54.6826 2.02151L52.656 2.04854L52.656 2.00343L51.7677 2.00004Z" fill="url(#paint_linear_22)" fill-opacity="0" fill-rule="evenodd" transform="matrix(-1,0,0,-1,118.4,106.667)" /> | ||
| 29 | + <path id="矢量 6119" d="M64.2556 21.3445C64.2554 21.3445 61.3665 21.3335 61.3665 21.3335C61.3665 21.3335 61.3664 21.3335 61.3663 21.3335C61.2895 21.3336 32.5843 21.3493 32.4365 21.3445C26.7905 21.1633 21.9663 23.2322 17.6972 26.5916C11.6994 31.3057 9.72482 37.9286 9.64978 45.1595C9.54868 55.556 9.62008 64.4303 9.69148 74.8268C9.69565 75.4043 9.6993 75.9821 9.70347 76.5596C9.70607 77.0754 9.70764 77.592 9.70868 78.1093C9.71545 81.3258 9.72223 84.5653 10.173 87.7258C11.8167 99.1693 20.75 106.656 32.3834 106.656C32.6052 106.656 46.409 106.665 46.9549 106.667C48.8972 106.667 50.2208 105.984 51.0531 104.182C52.5795 100.822 54.255 97.5375 55.8132 94.1888C57.7773 89.9549 56.4646 88.0031 51.7259 88.0031L35.5529 88.0031C35.258 88.0031 34.962 88.0049 34.666 88.0065L34.6654 88.0065C33.6774 88.0122 32.6856 88.0179 31.7002 87.9604C29.8965 87.8646 28.7437 86.67 28.7437 84.8997L28.7437 42.9517C28.7437 41.5332 29.4587 40.5735 30.7824 40.2214C31.9242 39.9228 33.1301 39.7629 34.3152 39.7629C45.9272 39.7309 40.4657 39.7416 52.0776 39.7629C54.3832 39.7629 56.6887 39.8801 58.9937 39.8908C60.6269 39.8908 61.886 39.251 62.6015 37.694C64.341 33.8972 66.1661 30.1538 67.8415 26.3356C69.1011 23.4562 67.4575 21.3125 64.2556 21.3552L64.2556 21.3445Z" fill="rgb(35,23,22)" fill-rule="evenodd" /> | ||
| 30 | + <path id="矢量 6119" d="M61.3665 21.3335L64.2554 21.3445L64.2556 21.3445L64.2556 21.3528L64.2555 21.3552L64.2556 21.3552L64.2556 21.3552C64.2893 21.3547 64.3229 21.3545 64.3563 21.3546C64.3849 21.3546 64.4134 21.3548 64.4418 21.3552L64.4422 21.3552C66.8015 21.3871 68.2663 22.6371 68.2663 24.49C68.2663 25.055 68.1301 25.676 67.8415 26.3356C66.1661 30.1538 64.341 33.8972 62.6015 37.694C61.886 39.251 60.6269 39.8908 58.9937 39.8908C56.6887 39.8801 54.3832 39.7629 52.0776 39.7629C46.2716 39.7522 44.734 39.7442 43.1964 39.7429C41.8999 39.7418 40.6035 39.7454 36.7482 39.7562C36.0312 39.7582 35.2257 39.7604 34.3152 39.7629C33.1301 39.7629 31.9242 39.9228 30.7824 40.2214C29.4587 40.5735 28.7437 41.5332 28.7437 42.9517L28.7437 84.8997C28.7437 86.67 29.8965 87.8646 31.7002 87.9604C32.6856 88.0179 33.6774 88.0122 34.6654 88.0065L34.666 88.0065C34.962 88.0049 35.258 88.0031 35.5529 88.0031L51.7259 88.0031C55.054 88.0031 56.6922 88.9658 56.6922 91.0057C56.6922 91.8703 56.3979 92.9284 55.8132 94.1888C54.255 97.5375 52.5795 100.822 51.0531 104.182C50.2208 105.984 48.8972 106.667 46.9549 106.667C46.409 106.665 32.6052 106.656 32.3834 106.656C20.75 106.656 11.8167 99.1693 10.173 87.7258C9.72223 84.5653 9.71545 81.3258 9.70868 78.1093C9.70764 77.592 9.70607 77.0754 9.70347 76.5596C9.6993 75.9821 9.69565 75.4043 9.69148 74.8268C9.68759 74.2604 9.6837 73.6985 9.67984 73.1406C9.6381 67.1106 9.59961 61.5509 9.59961 55.8399C9.59961 52.3813 9.61372 48.8672 9.64978 45.1595C9.72482 37.9286 11.6994 31.3057 17.6972 26.5916C21.9663 23.2322 26.7905 21.1633 32.4365 21.3445C32.5789 21.3491 59.2078 21.3347 61.2435 21.3336L61.3663 21.3335L61.3665 21.3335ZM61.3673 23.3335L61.3672 23.3335L61.3631 23.3335L46.9022 23.3408L32.4047 23.3445L32.3724 23.3435Q30.9978 23.2994 29.6469 23.4569Q24.0915 24.1049 18.934 28.1633Q16.8903 29.7696 15.428 31.7956L15.428 31.7956L15.4279 31.7957Q14.1459 33.5721 13.3108 35.6711Q11.7065 39.7035 11.6497 45.1802Q11.6085 49.4175 11.6085 55.2068Q11.6085 62.8236 11.6798 73.1268C11.685 73.8733 11.6888 74.4354 11.6914 74.8131L11.6974 75.6784L11.7034 76.5458L11.7087 78.1026L11.7087 78.1062Q11.7154 81.2935 11.773 82.8658Q11.8674 85.4413 12.153 87.4434C12.5248 90.0322 13.2938 92.4043 14.4599 94.5596Q15.5038 96.4891 16.9192 98.0903L16.9193 98.0904L16.9205 98.0918C17.5077 98.7559 18.1428 99.3777 18.8258 99.957Q19.5227 100.548 20.2699 101.067L20.2701 101.067L20.2704 101.067L20.2722 101.068Q22.3855 102.535 24.9011 103.421C27.2373 104.244 29.7314 104.656 32.3834 104.656L39.6774 104.661L46.9565 104.667Q47.9091 104.667 48.4114 104.373C48.7313 104.186 49.0066 103.843 49.2373 103.343C49.806 102.092 50.6901 100.229 51.8894 97.7564C52.8391 95.7983 53.5426 94.3278 53.9999 93.3451C54.3971 92.4887 54.6238 91.785 54.6798 91.2339C54.6889 91.1438 54.6935 91.0622 54.6935 90.9892C54.6935 90.8163 54.6679 90.6913 54.6166 90.6141C54.5361 90.4927 54.3358 90.3794 54.016 90.2744C53.4651 90.0935 52.7017 90.0031 51.7259 90.0031L35.5529 90.0031L34.6906 90.0064L34.6767 90.0064L34.6654 90.0065C33.3108 90.0143 32.2835 89.9978 31.5836 89.957C30.6317 89.9064 29.7968 89.6632 29.0788 89.2274C28.7267 89.0137 28.4027 88.7536 28.1069 88.4473C27.7882 88.1172 27.5254 87.7575 27.3185 87.3681C26.9353 86.6471 26.7437 85.8243 26.7437 84.8997L26.7437 42.9517Q26.7437 41.5968 27.3092 40.5463L27.3093 40.5461C27.4132 40.3532 27.5313 40.168 27.6638 39.9905C27.8457 39.7468 28.0479 39.5261 28.2705 39.3283Q29.0867 38.6029 30.2684 38.2886C31.3409 38.0081 32.4192 37.8398 33.5032 37.7839C33.7735 37.7699 34.0442 37.7629 34.3152 37.7629L43.1919 37.7429L52.0822 37.7629C52.9021 37.7629 54.1262 37.7846 55.7544 37.8279C57.2031 37.8665 58.286 37.8875 59.0029 37.8908C59.4801 37.8908 59.8573 37.81 60.1346 37.6483Q60.5263 37.4201 60.7842 36.8589C61.2204 35.9069 61.8818 34.4857 62.7685 32.5954Q64.9721 27.8974 66.0101 25.532Q66.2755 24.9253 66.2755 24.4977C66.2755 24.2847 66.2261 24.105 66.1273 23.9586C66.1215 23.95 66.1155 23.9415 66.1094 23.9331Q65.6714 23.3365 64.2823 23.355L62.2556 23.382L62.2556 23.3369L61.3673 23.3335Z" fill="url(#paint_linear_23)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 31 | + <path id="矢量 6109" d="M39.5901 73.5999L51.8402 73.5999C54.3694 73.5999 56.6613 72.1104 57.6886 69.7992L62.5328 58.8995C63.4733 56.7834 61.9244 54.3999 59.6086 54.3999L47.3585 54.3999C44.8293 54.3999 42.5373 55.8894 41.5101 58.2006L36.6659 69.1003C35.7254 71.2164 37.2743 73.5999 39.5901 73.5999Z" fill="rgb(35,23,22)" fill-rule="evenodd" /> | ||
| 32 | + <path id="矢量 6109" d="M36.3864 70.401C36.3864 69.9712 36.4748 69.5302 36.6659 69.1003L41.5101 58.2006C42.5373 55.8894 44.8293 54.3999 47.3585 54.3999L59.6086 54.3999C61.4538 54.3999 62.8122 55.9133 62.8122 57.5988C62.8122 58.0286 62.7239 58.4696 62.5328 58.8995L57.6886 69.7992C56.6613 72.1104 54.3694 73.5999 51.8402 73.5999L39.5901 73.5999C37.7448 73.5999 36.3864 72.0865 36.3864 70.401ZM51.8402 71.5999Q52.4922 71.5999 53.0916 71.4222C53.4912 71.3038 53.8733 71.1261 54.2378 70.8893C54.6023 70.6524 54.9198 70.3754 55.1903 70.0583C55.4608 69.7413 55.6844 69.3841 55.8609 68.9869L60.7052 58.0873Q60.8182 57.8331 60.8182 57.5879C60.8182 57.56 60.8171 57.5321 60.8149 57.5044C60.7998 57.3142 60.7331 57.128 60.6148 56.946C60.4965 56.764 60.3535 56.6274 60.1858 56.5364C60.0181 56.4454 59.8257 56.3999 59.6086 56.3999L47.3585 56.3999C46.9238 56.3999 46.5067 56.4591 46.1071 56.5776L46.107 56.5776Q45.5076 56.7552 44.9609 57.1105C44.5964 57.3474 44.2789 57.6244 44.0084 57.9414C43.7379 58.2585 43.5143 58.6157 43.3378 59.0129L38.4935 69.9125Q38.3805 70.1667 38.3805 70.4119Q38.3805 70.4538 38.3838 70.4954Q38.4064 70.7807 38.5839 71.0538C38.7022 71.2358 38.8452 71.3724 39.0129 71.4634L39.0129 71.4634Q39.2644 71.5999 39.5901 71.5999L51.8402 71.5999Z" fill="url(#paint_linear_24)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 33 | + <path id="矢量 6115" d="M68.3908 73.5999L80.6409 73.5999C83.1702 73.5999 85.4621 72.1104 86.4893 69.7992L91.3336 58.8995C92.2741 56.7834 90.7251 54.3999 88.4094 54.3999L76.1593 54.3999C73.6301 54.3999 71.3381 55.8894 70.3109 58.2006L65.4666 69.1003C64.5261 71.2164 66.0751 73.5999 68.3908 73.5999Z" fill="rgb(199,0,11)" fill-rule="evenodd" /> | ||
| 34 | + <path id="矢量 6115" d="M80.6409 73.5999L68.3908 73.5999C66.5456 73.5999 65.1872 72.0865 65.1872 70.401C65.1872 69.9712 65.2756 69.5302 65.4666 69.1003L70.3109 58.2006C71.3381 55.8894 73.6301 54.3999 76.1593 54.3999L88.4094 54.3999C90.2546 54.3999 91.613 55.9133 91.613 57.5988C91.613 58.0286 91.5247 58.4696 91.3336 58.8995L86.4893 69.7992C85.4621 72.1104 83.1702 73.5999 80.6409 73.5999ZM80.6409 71.5999C81.0757 71.5999 81.4928 71.5407 81.8924 71.4222C82.292 71.3038 82.6741 71.1261 83.0386 70.8893C83.4031 70.6524 83.7206 70.3754 83.9911 70.0583C84.2616 69.7413 84.4852 69.3841 84.6617 68.9869L89.506 58.0873C89.5813 57.9178 89.619 57.7514 89.619 57.5879C89.619 57.56 89.6179 57.5321 89.6157 57.5044C89.6006 57.3142 89.5339 57.128 89.4156 56.946C89.2973 56.764 89.1543 56.6274 88.9866 56.5364L88.9865 56.5364Q88.735 56.3999 88.4094 56.3999L76.1593 56.3999Q75.5073 56.3999 74.9079 56.5776Q74.3084 56.7552 73.7617 57.1105Q73.2149 57.4659 72.8092 57.9415C72.5386 58.2585 72.3151 58.6157 72.1385 59.0129L67.2943 69.9125C67.219 70.082 67.1813 70.2484 67.1813 70.4119C67.1813 70.4398 67.1824 70.4677 67.1846 70.4954Q67.2072 70.7807 67.3846 71.0538C67.5029 71.2358 67.6459 71.3723 67.8136 71.4634C67.9813 71.5544 68.1737 71.5999 68.3908 71.5999L80.6409 71.5999Z" fill="url(#paint_linear_25)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 35 | + </g> | ||
| 36 | + </g> | ||
| 37 | + </g> | ||
| 38 | +</svg> | ||
| @@ -0,0 +1 @@ | |||
| 1 | +{ "meta": { "title": "CANNBot DSH", "description": "CANNBot interface with independent workflow packages, per-workflow updates, rollback and automatic workspace initialization.", "detail": "README.md" } } | ||
| @@ -0,0 +1 @@ | |||
| 1 | +{ "meta": { "title": "CANNBot DSH", "description": "品牌界面与独立工作流包,支持逐项更新、回退及工作区自动初始化。", "detail": "README.md" } } | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | +{ | ||
| 2 | + "name": "cannbot-dsh", | ||
| 3 | + "version": "1.0.0-alpha.1", | ||
| 4 | + "description": "CANNBot DSH: Ascend development workbench with independently versioned workflow packages", | ||
| 5 | + "type": "module", | ||
| 6 | + "license": "SEE LICENSE IN LICENSE", | ||
| 7 | + "files": [ | ||
| 8 | + "cordis.patch.yml", | ||
| 9 | + "locale", | ||
| 10 | + "icon.svg", | ||
| 11 | + "README.md", | ||
| 12 | + "THIRD_PARTY_NOTICES.md", | ||
| 13 | + "LICENSE" | ||
| 14 | + ], | ||
| 15 | + "exports": { | ||
| 16 | + "./package.json": "./package.json", | ||
| 17 | + "./cordis.patch.yml": "./cordis.patch.yml", | ||
| 18 | + "./locale/*.json": "./locale/*.json" | ||
| 19 | + }, | ||
| 20 | + "icon": "./icon.svg", | ||
| 21 | + "dsh": { | ||
| 22 | + "bundle": { | ||
| 23 | + "patch": "./cordis.patch.yml" | ||
| 24 | + } | ||
| 25 | + }, | ||
| 26 | + "engines": { | ||
| 27 | + "node": ">=24.9.0", | ||
| 28 | + "dsh": ">=0.1.1-rc.1 <0.3.0" | ||
| 29 | + }, | ||
| 30 | + "publishConfig": { | ||
| 31 | + "access": "public", | ||
| 32 | + "registry": "https://registry.npmjs.org/" | ||
| 33 | + }, | ||
| 34 | + "keywords": [ | ||
| 35 | + "dsh", | ||
| 36 | + "cannbot", | ||
| 37 | + "workbench", | ||
| 38 | + "ascend" | ||
| 39 | + ], | ||
| 40 | + "scripts": { "pack:plugin": "node ../../scripts/package.mjs --short" }, | ||
| 41 | + "dependencies": { | ||
| 42 | + "@cannbot-plugin/cannbot-dsh": "1.0.0-alpha.1" | ||
| 43 | + } | ||
| 44 | +} | ||
| @@ -0,0 +1,28 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +/** Activate a fully assembled source installation through the normal cache validator. */ | ||
| 12 | +import { readFileSync } from 'node:fs' | ||
| 13 | +import { join } from 'node:path' | ||
| 14 | +import { ContentManager } from '../src/content-manager.ts' | ||
| 15 | + | ||
| 16 | +const [reportFile, defaults, cache] = process.argv.slice(2) | ||
| 17 | +const reports = JSON.parse(readFileSync(reportFile, 'utf8')) as { name: string; directory: string }[] | ||
| 18 | +const resolvePackage = (name: string) => { | ||
| 19 | + const report = reports.find(item => item.name === name) | ||
| 20 | + if (!report) throw new Error(`Missing assembled package: ${name}`) | ||
| 21 | + return join(report.directory, 'package.json') | ||
| 22 | +} | ||
| 23 | +const manager = new ContentManager(defaults, cache, { | ||
| 24 | + async manifest() { throw new Error('Source activation must not fetch npm packages') }, | ||
| 25 | + async extract() { throw new Error('Source activation must not fetch npm packages') }, | ||
| 26 | +}) | ||
| 27 | +await manager.installDependencies(resolvePackage('@cannbot-plugin/workflow-catalog'), resolvePackage, true) | ||
| 28 | +console.log(`Activated ${manager.getSource().catalog.plugins.length} workflows from current source.`) | ||
| @@ -0,0 +1,111 @@ | |||
| 1 | +/** Build one or all independent, resource-only workflow packages from a verified source snapshot. */ | ||
| 2 | +import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from 'node:fs' | ||
| 3 | +import { createHash } from 'node:crypto' | ||
| 4 | +import { createRequire } from 'node:module' | ||
| 5 | +import { basename, dirname, join, relative, resolve } from 'node:path' | ||
| 6 | +import { fileURLToPath } from 'node:url' | ||
| 7 | +import { tmpdir } from 'node:os' | ||
| 8 | +import { spawnSync } from 'node:child_process' | ||
| 9 | +const root = fileURLToPath(new URL('..', import.meta.url)) | ||
| 10 | +const options = Object.fromEntries(process.argv.slice(2).reduce((items, arg, i, all) => arg.startsWith('--') ? [...items, [arg.slice(2), all[i + 1]]] : items, [])) | ||
| 11 | +const version = options.version ?? '1.0.0', catalogVersion = options['catalog-version'] ?? '1.0.0' | ||
| 12 | +if (!/^\d+\.\d+\.\d+$/.test(version) || !/^\d+\.\d+\.\d+$/.test(catalogVersion)) throw new Error('Use a stable x.y.z version') | ||
| 13 | +const source = resolve(options.source ?? join(root, '..')) | ||
| 14 | +// Always assemble current source; resource copies never live in the adapter repository. | ||
| 15 | +const temporary = mkdtempSync(join(tmpdir(), 'cannbot-workflows-')) | ||
| 16 | +process.on('exit', () => rmSync(temporary, { recursive: true, force: true })) | ||
| 17 | +const assets = join(temporary, 'official') | ||
| 18 | +const built = spawnSync(process.execPath, [join(root, 'scripts/materialize-workflows.mjs'), source, assets], { stdio: 'inherit' }) | ||
| 19 | +if (built.status !== 0) process.exit(built.status ?? 1) | ||
| 20 | +const catalog = JSON.parse(readFileSync(join(assets, 'catalog.json'), 'utf8')) | ||
| 21 | +const defaults = JSON.parse(readFileSync(join(root, 'workflow-defaults.json'), 'utf8')) | ||
| 22 | +// workflow-defaults.json is the source of truth for which workflows this build ships: | ||
| 23 | +// workflows absent from it are neither packaged nor listed in the catalog. | ||
| 24 | +const shipped = new Set(defaults.workflows.map(item => item.id)) | ||
| 25 | +for (const id of shipped) if (!catalog.plugins.some(item => item.id === id)) throw new Error(`Default workflow is not available in source: ${id}`) | ||
| 26 | +catalog.plugins = catalog.plugins.filter(item => shipped.has(item.id)) | ||
| 27 | +const require = createRequire(import.meta.url) | ||
| 28 | +const { parse } = (()=>{try{return require('yaml')}catch{return createRequire(require.resolve('@deepseek-ai/dsh-skill-filesystem/package.json'))('yaml')}})() | ||
| 29 | +const dist = resolve(options.output ?? join(root, 'dist/workflow-releases')) | ||
| 30 | +mkdirSync(dist, { recursive: true }) | ||
| 31 | +writeFileSync(join(dist, 'source-catalog.json'), JSON.stringify(catalog, null, 2) + '\n') | ||
| 32 | +const workspace = resolve(options['build-root'] ?? join(root, 'dist/workflow-packages')) | ||
| 33 | +const npmCli = [process.env.npm_execpath, resolve(process.execPath,'../node_modules/npm/bin/npm-cli.js'), '/usr/share/nodejs/npm/bin/npm-cli.js', '/usr/lib/node_modules/npm/bin/npm-cli.js'].find(value=>value&&existsSync(value)); | ||
| 34 | +if(!npmCli)throw new Error('Use a Node.js installation with npm to build workflow packages') | ||
| 35 | +const hashTree = path => { | ||
| 36 | + const hash = createHash('sha256') | ||
| 37 | + function walk(value) { | ||
| 38 | + for (const item of readdirSync(value, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) { | ||
| 39 | + const file = join(value, item.name) | ||
| 40 | + if (item.isDirectory()) walk(file) | ||
| 41 | + else { hash.update(relative(path, file).split('\\').join('/')); hash.update('\0'); hash.update(readFileSync(file)); hash.update('\0') } | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + walk(path); return hash.digest('hex') | ||
| 45 | +} | ||
| 46 | +const reports = [] | ||
| 47 | +function pack(directory, manifest) { | ||
| 48 | + if (options['no-pack'] === 'true') { reports.push({ name: manifest.name, version: manifest.version, directory }); return } | ||
| 49 | + const tarball = join(dist, `${manifest.name.replace(/^@/, '').replaceAll('/', '-')}-${manifest.version}.tgz`) | ||
| 50 | + const result = spawnSync(process.execPath, [npmCli, 'pack', '--ignore-scripts', '--json', '--pack-destination', dist, '--loglevel=error', '--logs-max=0'], { cwd: directory, encoding: 'utf8', maxBuffer: 4e6 }) | ||
| 51 | + if (result.status !== 0) throw new Error(result.stderr || result.stdout) | ||
| 52 | + const bytes = readFileSync(tarball) | ||
| 53 | + const report = { name: manifest.name, version: manifest.version, directory, tarball, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex'), integrity: 'sha512-' + createHash('sha512').update(bytes).digest('base64') } | ||
| 54 | + reports.push(report); console.log(JSON.stringify(report)) | ||
| 55 | +} | ||
| 56 | +for (const plugin of catalog.plugins) { | ||
| 57 | + if (options['catalog-only'] === 'true') continue | ||
| 58 | + if (options.id && options.id !== plugin.id) continue | ||
| 59 | + if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(plugin.id)) throw new Error('Invalid workflow id') | ||
| 60 | + const name = `@cannbot-plugin/workflow-${plugin.id}` | ||
| 61 | + const directory = join(workspace, 'packages', plugin.id, version) | ||
| 62 | + if (existsSync(directory)) throw new Error(`Build directory exists; preserve the previous artifact: ${directory}`) | ||
| 63 | + mkdirSync(directory, { recursive: true }) | ||
| 64 | + const resources = join(directory, 'resources') | ||
| 65 | + cpSync(join(assets, plugin.id), resources, { recursive: true }) | ||
| 66 | + const skills = readdirSync(join(resources, 'skills'), { withFileTypes: true }).filter(item => item.isDirectory() && existsSync(join(resources, 'skills', item.name, 'SKILL.md'))).map(item => { | ||
| 67 | + const content = readFileSync(join(resources, 'skills', item.name, 'SKILL.md'), 'utf8') | ||
| 68 | + const frontmatter = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---/.exec(content) | ||
| 69 | + if (!frontmatter) throw new Error(`Missing Skill metadata: ${item.name}`) | ||
| 70 | + const info = parse(frontmatter[1]) | ||
| 71 | + return { name: info.name, path: `skills/${item.name}/SKILL.md`, hash: hashTree(join(resources, 'skills', item.name)), entry: info.name === plugin.id } | ||
| 72 | + }) | ||
| 73 | + const upstreamManifest = join(resources, '.claude-plugin/plugin.json') | ||
| 74 | + const initialization = existsSync(upstreamManifest) ? { kind: 'cannbot-cli', entry: 'upstream/bin/cannbot.js' } : { kind: 'skill-native' } | ||
| 75 | + if (existsSync(upstreamManifest)) { | ||
| 76 | + const manifest = JSON.parse(readFileSync(upstreamManifest, 'utf8')) | ||
| 77 | + manifest.skills = skills.map(item => './' + dirname(item.path).split('\\').join('/')) | ||
| 78 | + delete manifest.dependencies | ||
| 79 | + writeFileSync(upstreamManifest, JSON.stringify(manifest, null, 2) + '\n') | ||
| 80 | + // Like the upstream npm assembler, sealed packages use packaged resources, | ||
| 81 | + // not source-only Git/submodule definitions. The installer itself is unchanged. | ||
| 82 | + const sourceDefinition = join(resources, 'plugin-sources.json') | ||
| 83 | + if (existsSync(sourceDefinition)) unlinkSync(sourceDefinition) | ||
| 84 | + mkdirSync(join(directory, 'upstream/bin'), { recursive: true }) | ||
| 85 | + cpSync(join(source, 'script/bin/cannbot.js'), join(directory, 'upstream/bin/cannbot.js')) | ||
| 86 | + cpSync(join(source, 'script/lib'), join(directory, 'upstream/lib'), { recursive: true }) | ||
| 87 | + writeFileSync(join(directory, 'upstream/package.json'), JSON.stringify({ name, version, type: 'module', license: 'MIT' }, null, 2) + '\n') | ||
| 88 | + cpSync(join(source, 'script/LICENSE'), join(directory, 'upstream/LICENSE')) | ||
| 89 | + } | ||
| 90 | + const contentHash = hashTree(directory) | ||
| 91 | + const descriptor = { contentHash, schemaVersion: 1, id: plugin.id, title: plugin.title, version, initialization, skills, source: { repository: catalog.repository, commit: catalog.commit, skillsCommit: catalog.skillsCommit } } | ||
| 92 | + const manifest = { name, version, description: `CANNBot ${plugin.title}: independently versioned workflow resources for CANNBot DSH`, type: 'module', license: 'SEE LICENSE IN resources/LICENSE', files: ['resources', 'workflow.json', 'README.md', ...initialization.kind === 'cannbot-cli' ? ['upstream'] : []], engines: { node: '>=24.9.0' }, publishConfig: { access: 'public', registry: 'https://registry.npmjs.org/' }, cannbotWorkflow: { schemaVersion: 1, id: plugin.id }, repository: { type: 'git', url: catalog.repository, directory: `plugins-official/${plugin.id}` } } | ||
| 93 | + writeFileSync(join(directory, 'package.json'), JSON.stringify(manifest, null, 2) + '\n') | ||
| 94 | + writeFileSync(join(directory, 'workflow.json'), JSON.stringify(descriptor, null, 2) + '\n') | ||
| 95 | + writeFileSync(join(directory, 'README.md'), `# ${plugin.title}\n\nIndependent workflow package: \`${name}@${version}\`.\n\nInstall and update it from CANNBot DSH workflow management. The source CANNBot installer is preserved and invoked with its DSH target; npm lifecycle scripts are not used.\n\nSource: ${catalog.repository}\nCANNBot: ${catalog.commit}\nSkills: ${catalog.skillsCommit}\n`) | ||
| 96 | + pack(directory, manifest) | ||
| 97 | +} | ||
| 98 | +if (options.id && !reports.length) throw new Error('Workflow was not found') | ||
| 99 | +if (!options.id || options.catalog === 'true') { | ||
| 100 | + const directory = join(workspace, 'catalog', catalogVersion) | ||
| 101 | + if (existsSync(directory)) throw new Error(`Catalog build directory exists: ${directory}`) | ||
| 102 | + mkdirSync(directory, { recursive: true }) | ||
| 103 | + const workflows = catalog.plugins.map(plugin => ({ id: plugin.id, title: plugin.title, package: `@cannbot-plugin/workflow-${plugin.id}`, default: defaults.workflows.find(item => item.id === plugin.id)?.default ?? true })) | ||
| 104 | + const manifest = { name: '@cannbot-plugin/workflow-catalog', version: catalogVersion, description: 'Discover and install independently versioned CANNBot DSH workflows', license: 'MIT', files: ['catalog.json', 'README.md', 'LICENSE'], dependencies: Object.fromEntries(workflows.filter(item => item.default).map(item => [item.package, '>=1.0.0'])), publishConfig: { access: 'public', registry: 'https://registry.npmjs.org/' }, cannbotWorkflowCatalog: { schemaVersion: 1, workflows } } | ||
| 105 | + writeFileSync(join(directory, 'package.json'), JSON.stringify(manifest, null, 2) + '\n') | ||
| 106 | + writeFileSync(join(directory, 'catalog.json'), JSON.stringify(manifest.cannbotWorkflowCatalog, null, 2) + '\n') | ||
| 107 | + writeFileSync(join(directory, 'README.md'), '# CANNBot workflow catalog\n\nOnly republish this small catalog when workflows are added or discovery metadata changes. Updating an existing workflow requires publishing only that workflow package.\n') | ||
| 108 | + writeFileSync(join(directory, 'LICENSE'), readFileSync(join(source, 'script/LICENSE'))) | ||
| 109 | + pack(directory, manifest) | ||
| 110 | +} | ||
| 111 | +writeFileSync(join(dist, options.id ? `${options.id}-${version}-report.json` : `release-${version}-report.json`), JSON.stringify(reports, null, 2) + '\n') | ||
| @@ -0,0 +1,8 @@ | |||
| 1 | +import { spawnSync } from 'node:child_process' | ||
| 2 | +import { resolve } from 'node:path' | ||
| 3 | +import { project, resolveSource } from './source.mjs' | ||
| 4 | +const checkout = resolveSource() | ||
| 5 | +const result = spawnSync(process.execPath, [resolve(checkout, 'node_modules/tsdown/dist/run.mjs'), '--config-loader', 'native', '--config', 'tsdown.config.ts'], { | ||
| 6 | + cwd: project, stdio: 'inherit', env: { ...process.env, DSH_CLIENT_BUILD_PROFILE: 'local' }, | ||
| 7 | +}) | ||
| 8 | +process.exit(result.status ?? 1) | ||
| @@ -0,0 +1,78 @@ | |||
| 1 | +import { withStaging } from './staging.mjs' | ||
| 2 | +import { runProcess } from '../src/process-runner.mjs' | ||
| 3 | +/** Assemble current repository resources at installation time, outside the adapter source tree. */ | ||
| 4 | +import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs' | ||
| 5 | +import { homedir } from 'node:os' | ||
| 6 | +import { join, resolve } from 'node:path' | ||
| 7 | +import { project, resolveSource } from './source.mjs' | ||
| 8 | + | ||
| 9 | +const args = process.argv.slice(2) | ||
| 10 | +if (args.includes('--help')) { | ||
| 11 | + console.log('node scripts/install-source.mjs [--source /path/to/cannbot | --repository GitURL] [--profile web]\nDefaults to the current parent repository, including uncommitted edits. A remote repository is freshly cloned with its declared submodules. DSH_HOME and CANNBOT_DSH_WORKFLOW_ROOT are honored.') | ||
| 12 | + process.exit(0) | ||
| 13 | +} | ||
| 14 | +const options = {} | ||
| 15 | +for (let i = 0; i < args.length; i += 2) { | ||
| 16 | + if (!['--source', '--repository', '--profile'].includes(args[i]) || !args[i + 1] || args[i + 1].startsWith('--')) throw new Error(`Invalid option: ${args[i]}`) | ||
| 17 | + options[args[i].slice(2)] = args[i + 1] | ||
| 18 | +} | ||
| 19 | +if (options.source && options.repository) throw new Error('Choose --source or --repository') | ||
| 20 | +const checkout = resolveSource() | ||
| 21 | +const home = resolve(process.env.DSH_HOME ?? join(homedir(), '.dsh')) | ||
| 22 | +const cache = resolve(process.env.CANNBOT_DSH_WORKFLOW_ROOT ?? join(home, 'cannbot-dsh-workflows')) | ||
| 23 | +await withStaging('cannbot-source-install-', async (temporary, signal) => { | ||
| 24 | + const run = (command, args) => runProcess(command, args, { cwd: project, stdio: 'inherit', signal, env: { ...process.env, TMPDIR: temporary } }) | ||
| 25 | + let source = resolve(options.source ?? join(project, '..')) | ||
| 26 | + if (options.repository) { | ||
| 27 | + source = join(temporary, 'source') | ||
| 28 | + await run('git', ['clone', '--depth', '1', '--recurse-submodules', '--shallow-submodules', '--', options.repository, source]) | ||
| 29 | + } | ||
| 30 | + // Generate all resources before changing the installed plugin or active workflows. | ||
| 31 | + const pkg = JSON.parse(readFileSync(join(project, 'package.json'), 'utf8')) | ||
| 32 | + const catalogRange = pkg.dependencies?.['@cannbot-plugin/workflow-catalog'] ?? '1.0.0' | ||
| 33 | + const catalogVersion = catalogRange.replace(/^[\^~]/, '') | ||
| 34 | + if (!/^\d+\.\d+\.\d+$/.test(catalogVersion)) throw new Error(`Unsupported workflow catalog range: ${catalogRange}`) | ||
| 35 | + const output = join(temporary, 'reports') | ||
| 36 | + await run(process.execPath, [join(project, 'scripts/build-workflow-packages.mjs'), '--source', source, '--build-root', join(temporary, 'packages'), '--output', output, '--no-pack', 'true', '--catalog-version', catalogVersion]) | ||
| 37 | + await run(process.execPath, [join(project, 'scripts/build.mjs')]) | ||
| 38 | + await run(process.execPath, [join(project, 'scripts/package.mjs')]) | ||
| 39 | + const profile = options.profile ?? 'web' | ||
| 40 | + const profileDir = join(home, 'profiles', profile) | ||
| 41 | + const archive = join(project, 'dist', `${pkg.name.replace(/^@/, '').replaceAll('/', '-')}-${pkg.version}.tgz`) | ||
| 42 | + await run('dsh', ['plugin', '--profile', profile, 'add', archive, '--force']) | ||
| 43 | + // pnpm keeps the previously linked files when the package version is unchanged, so the | ||
| 44 | + // rebuilt archive must replace the installed copy before the profile is relinked. | ||
| 45 | + rmSync(join(profileDir, 'node_modules', ...pkg.name.split('/')), { recursive: true, force: true }) | ||
| 46 | + await run('dsh', ['plugin', '--profile', profile, 'install', '--force']) | ||
| 47 | + // Ship the catalog assembled from this source tree: the registry catalog lists workflows | ||
| 48 | + // this build does not contain, and the runtime reads whichever catalog is installed. | ||
| 49 | + const reports = JSON.parse(readFileSync(join(output, 'release-1.0.0-report.json'), 'utf8')) | ||
| 50 | + const catalog = reports.find(item => item.name === '@cannbot-plugin/workflow-catalog') | ||
| 51 | + if (!catalog) throw new Error('Source build did not produce a workflow catalog') | ||
| 52 | + const installedCatalog = join(profileDir, 'node_modules/@cannbot-plugin/workflow-catalog') | ||
| 53 | + rmSync(installedCatalog, { recursive: true, force: true }) | ||
| 54 | + cpSync(catalog.directory, installedCatalog, { recursive: true }) | ||
| 55 | + mkdirSync(cache, { recursive: true }) | ||
| 56 | + await run(process.execPath, [join(checkout, 'node_modules/tsx/dist/cli.mjs'), join(project, 'scripts/activate-source.ts'), join(output, 'release-1.0.0-report.json'), join(project, 'workflow-defaults.json'), cache]) | ||
| 57 | + // Earlier installs leave entries and copies behind; a source install keeps exactly the declared workflows. | ||
| 58 | + const activeFile = join(cache, 'active.json') | ||
| 59 | + if (existsSync(activeFile)) { | ||
| 60 | + const index = JSON.parse(readFileSync(activeFile, 'utf8')) | ||
| 61 | + const defaults = JSON.parse(readFileSync(join(project, 'workflow-defaults.json'), 'utf8')) | ||
| 62 | + const keep = new Set(defaults.workflows.map(item => item.id)) | ||
| 63 | + const dropped = index.entries.filter(item => !keep.has(item.id)) | ||
| 64 | + index.entries = index.entries.filter(item => keep.has(item.id)) | ||
| 65 | + for (const id of Object.keys(index.records)) if (!keep.has(id)) delete index.records[id] | ||
| 66 | + for (const id of Object.keys(index.history ?? {})) if (!keep.has(id)) delete index.history[id] | ||
| 67 | + index.pinned = (index.pinned ?? []).filter(id => keep.has(id)) | ||
| 68 | + if (dropped.length) writeFileSync(activeFile, JSON.stringify(index, null, 2)) | ||
| 69 | + for (const item of dropped) rmSync(join(cache, 'packages', item.id), { recursive: true, force: true }) | ||
| 70 | + for (const id of keep) { | ||
| 71 | + const directory = join(cache, 'packages', id) | ||
| 72 | + if (!existsSync(directory)) continue | ||
| 73 | + const current = index.records[id]?.directory | ||
| 74 | + for (const entry of readdirSync(directory)) if (`packages/${id}/${entry}` !== current) rmSync(join(directory, entry), { recursive: true, force: true }) | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + console.log('Source installation complete. Restart DSH to load the rebuilt plugin.') | ||
| 78 | +}) | ||
| @@ -0,0 +1,186 @@ | |||
| 1 | +/** Copy the selected working tree and declared Skills into a fresh installation staging directory. */ | ||
| 2 | +import { execFileSync } from 'node:child_process' | ||
| 3 | +import { createHash } from 'node:crypto' | ||
| 4 | +import { existsSync, readFileSync, writeFileSync, readdirSync, mkdirSync, rmSync, statSync, copyFileSync, realpathSync, lstatSync, readlinkSync, unlinkSync, renameSync } from 'node:fs' | ||
| 5 | +import { createRequire } from 'node:module' | ||
| 6 | +import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path' | ||
| 7 | +import { fileURLToPath } from 'node:url' | ||
| 8 | +const localRequire = createRequire(import.meta.url) | ||
| 9 | +const { parse } = (() => { | ||
| 10 | + try { return localRequire('yaml') } | ||
| 11 | + catch { return createRequire(realpathSync(localRequire.resolve('@deepseek-ai/dsh-skill-filesystem/package.json')))('yaml') } | ||
| 12 | +})() | ||
| 13 | + | ||
| 14 | +if (!process.argv[2] || !process.argv[3]) throw new Error('Usage: materialize-workflows.mjs <source> <fresh-output>'); | ||
| 15 | +const source = resolve(process.argv[2]); | ||
| 16 | +const target = resolve(process.argv[3]); | ||
| 17 | +if (!source || !target || existsSync(target)) throw new Error('An existing source and a fresh output directory are required'); | ||
| 18 | +const project = fileURLToPath(new URL('..', import.meta.url)); | ||
| 19 | +const known = JSON.parse(readFileSync(join(project, 'official-plugins.json'), 'utf8')); | ||
| 20 | +const json = path => JSON.parse(readFileSync(path, 'utf8')); | ||
| 21 | +const git = (root, ...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim(); | ||
| 22 | +const skillsSource = join(source, 'vendor/cannbot-skills'); | ||
| 23 | +const config = { | ||
| 24 | + repository:known.repository, commit:git(source,'rev-parse','HEAD'), skillsCommit:git(skillsSource,'rev-parse','HEAD'), | ||
| 25 | + plugins:readdirSync(join(source,'plugins-official'),{withFileTypes:true}) | ||
| 26 | + .filter(item=>item.isDirectory()&&/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(item.name) | ||
| 27 | + &&(existsSync(join(source,'plugins-official',item.name,'.claude-plugin/plugin.json')) | ||
| 28 | + ||existsSync(join(source,'plugins-official',item.name,'skills',item.name,'SKILL.md')))) | ||
| 29 | + .map(item=>{ | ||
| 30 | + const file=join(source,'plugins-official',item.name,'.claude-plugin/plugin.json'); | ||
| 31 | + const manifest=existsSync(file)?json(file):{name:item.name}; | ||
| 32 | + if(manifest.name!==item.name)throw new Error('Plugin directory and identity differ'); | ||
| 33 | + return {id:item.name,title:known.plugins.find(old=>old.id===item.name)?.title??manifest.displayName??manifest.name}; | ||
| 34 | + }), | ||
| 35 | +}; | ||
| 36 | +config.plugins.sort((a,b)=>{ const rank=id=>{const n=known.plugins.findIndex(item=>item.id===id);return n<0?100000:n;};return rank(a.id)-rank(b.id)||a.id.localeCompare(b.id);}); | ||
| 37 | +if (!config.plugins.length) throw new Error('No official workflows discovered'); | ||
| 38 | +const within = (root, candidate) => { const path = relative(root,candidate); if(path==='..'||path.startsWith(`..${sep}`)||isAbsolute(path)) throw new Error('Resource escapes repository'); }; | ||
| 39 | +const links = new Map() | ||
| 40 | +for (const root of [source, skillsSource]) { | ||
| 41 | + for (const row of execFileSync('git', ['ls-tree', '-r', '--full-tree', '-z', 'HEAD'], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }).split('\0')) { | ||
| 42 | + if (!row.startsWith('120000 ')) continue | ||
| 43 | + const path = resolve(root, row.slice(row.indexOf('\t') + 1)) | ||
| 44 | + links.set(path, resolve(dirname(path), execFileSync('git', ['show', `HEAD:${row.slice(row.indexOf('\t') + 1)}`], {cwd: root, encoding:'utf8'}).trim())) | ||
| 45 | + } | ||
| 46 | +} | ||
| 47 | +function materialPath(input) { | ||
| 48 | + let path = resolve(input) | ||
| 49 | + const visited = new Set() | ||
| 50 | + for (;;) { | ||
| 51 | + within(source, path) | ||
| 52 | + let replaced = false | ||
| 53 | + for (let cursor = path; cursor !== dirname(cursor); cursor = dirname(cursor)) { | ||
| 54 | + const link = existsSync(cursor) && lstatSync(cursor).isSymbolicLink() | ||
| 55 | + ? resolve(dirname(cursor), readlinkSync(cursor)) : links.get(cursor) | ||
| 56 | + if (link === undefined) continue | ||
| 57 | + if (visited.has(cursor)) throw new Error(`Symlink cycle: ${input}`) | ||
| 58 | + visited.add(cursor) | ||
| 59 | + path = resolve(link, relative(cursor, path)) | ||
| 60 | + replaced = true | ||
| 61 | + break | ||
| 62 | + } | ||
| 63 | + if (!replaced) { | ||
| 64 | + if (!existsSync(path)) throw new Error(`Missing source resource: ${path}. Prepare the Skills declared by this source before installing.`) | ||
| 65 | + within(source, realpathSync(path)); return path | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | +const ignored = new Set(['.git', '.gitignore', '.npmignore', '.agents', '.claude', '.codex', '.opencode', '.pi', 'node_modules', '__pycache__']) | ||
| 70 | +function copyTree(input, output, ancestors = new Set()) { | ||
| 71 | + within(target, resolve(output)) | ||
| 72 | + const path = materialPath(input) | ||
| 73 | + if (statSync(path).isDirectory()) { | ||
| 74 | + if (ancestors.has(path)) throw new Error(`Directory cycle: ${input}`) | ||
| 75 | + mkdirSync(output, { recursive: true }) | ||
| 76 | + const next = new Set([...ancestors, path]) | ||
| 77 | + for (const item of readdirSync(path).sort()) { | ||
| 78 | + if (ignored.has(item) || item.endsWith('.pyc')) continue | ||
| 79 | + copyTree(join(path, item), join(output, item), next) | ||
| 80 | + } | ||
| 81 | + } else { | ||
| 82 | + mkdirSync(dirname(output), { recursive: true }) | ||
| 83 | + copyFileSync(path, output) | ||
| 84 | + } | ||
| 85 | +} | ||
| 86 | +function skillId(value) { | ||
| 87 | + if (typeof value !== 'string' || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value)) throw new Error(`Invalid Skill ID: ${value}`) | ||
| 88 | + return value | ||
| 89 | +} | ||
| 90 | +function skillInfo(path) { | ||
| 91 | + const content = readFileSync(path, 'utf8') | ||
| 92 | + const match = content.match(/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/) | ||
| 93 | + if (!match) throw new Error(`Skill frontmatter is missing: ${path}`) | ||
| 94 | + const metadata = parse(match[1]) | ||
| 95 | + if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(metadata.name) || typeof metadata.description !== 'string' || !metadata.description.trim()) throw new Error(`Invalid Skill identity: ${path}`) | ||
| 96 | + return metadata | ||
| 97 | +} | ||
| 98 | +function treeHash(root) { | ||
| 99 | + const hash = createHash('sha256') | ||
| 100 | + function visit(path) { | ||
| 101 | + if (statSync(path).isDirectory()) { for (const name of readdirSync(path).sort()) visit(join(path, name)); return } | ||
| 102 | + hash.update(relative(root, path).split(sep).join('/')); hash.update('\0'); hash.update(readFileSync(path)); hash.update('\0') | ||
| 103 | + } | ||
| 104 | + visit(root) | ||
| 105 | + return hash.digest('hex') | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +mkdirSync(target, { recursive: true }) | ||
| 109 | +const plugins = [] | ||
| 110 | +const sources = [] | ||
| 111 | +for (const plugin of config.plugins) { | ||
| 112 | + const upstream = join(source, 'plugins-official', plugin.id) | ||
| 113 | + const output = join(target, plugin.id) | ||
| 114 | + const sourceManifest = join(upstream, '.claude-plugin/plugin.json') | ||
| 115 | + const manifest = existsSync(sourceManifest) ? json(sourceManifest) : { name: plugin.id, description: plugin.title } | ||
| 116 | + copyTree(upstream, output) | ||
| 117 | + copyTree(join(source, 'plugins-official/LICENSE'), join(output, 'LICENSE')) | ||
| 118 | + copyTree(join(skillsSource, 'LICENSE'), join(output, 'SKILLS_LICENSE')) | ||
| 119 | + const definitionFile = join(upstream, 'plugin-sources.json') | ||
| 120 | + const definition = existsSync(definitionFile) ? json(definitionFile) : undefined | ||
| 121 | + if (definition) { | ||
| 122 | + for (const path of definition.skills) { | ||
| 123 | + const input = materialPath(resolve(source, definition.skillsRepository, path)) | ||
| 124 | + const destination = join(output, 'skills', basename(input)) | ||
| 125 | + if (!existsSync(join(input, 'SKILL.md'))) throw new Error(`Missing declared Skill: ${input}`) | ||
| 126 | + copyTree(input, destination) | ||
| 127 | + if (definition.preserveSkillInvocationPolicy !== true) { | ||
| 128 | + const skillFile = join(destination, 'SKILL.md') | ||
| 129 | + writeFileSync(skillFile, readFileSync(skillFile, 'utf8').replace(/^disable-model-invocation:\s*true\s*$/m, 'disable-model-invocation: false')) | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + if (plugin.id === 'ops-registry-invoke') { | ||
| 134 | + const dependencies = json(join(upstream, 'skills/ops-registry-invoke/skills.json')) | ||
| 135 | + for (const name of dependencies.skills.external.map(skillId)) copyTree(join(skillsSource, 'ops', name), join(output, 'skills', name)) | ||
| 136 | + for (const name of [...dependencies.skills.native, ...dependencies.skills.external].map(skillId)) { | ||
| 137 | + if (!existsSync(join(output, 'skills', name, 'SKILL.md'))) throw new Error(`Unbundled registry workflow dependency: ${name}`) | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | + if (plugin.id === 'pypto-op-orchestrator') { | ||
| 141 | + const dependencyRoot = join(skillsSource, 'plugins-official/pypto-op-orchestrator') | ||
| 142 | + const assets = json(join(dependencyRoot, 'plugin-assets.json')) | ||
当前 PR 固定的共享 Skills 提交 ![]() ![]() | |||
| 143 | + for (const name of assets.skills.names.map(skillId)) copyTree(join(skillsSource, assets.skills.dir, name), join(output, 'skills', name)) | ||
| 144 | + copyTree(dependencyRoot, join(output, 'dependencies/cannbot-skills/pypto-op-orchestrator')) | ||
| 145 | + } | ||
| 146 | + const entryFile = join(output, 'skills', plugin.id, 'SKILL.md') | ||
| 147 | + let generatedEntry = false | ||
| 148 | + if (!existsSync(entryFile)) { | ||
| 149 | + generatedEntry = true | ||
| 150 | + mkdirSync(dirname(entryFile), { recursive: true }) | ||
| 151 | + const documents = ['AGENTS.md', 'README.md'].filter(path => existsSync(join(output, path))) | ||
| 152 | + writeFileSync(entryFile, `---\nname: ${plugin.id}\ndescription: ${JSON.stringify(manifest.description)}\n---\n\n# ${plugin.title}\n\n此入口加载随包的 CANNBot 官方插件 ${plugin.id}。\n先完整读取以下原始插件文档,再按其中的阶段、输入、执行与验收约定处理用户需求:\n\n${documents.map(path => `- [${path}](../../${path})`).join('\n')}\n\n脚本、角色和模板随原插件目录打包。使用安装包中的绝对路径读取资源,补齐原插件要求的运行环境后执行。\n`) | ||
| 153 | + } | ||
| 154 | + const skillNames = [] | ||
| 155 | + for (const directory of readdirSync(join(output, 'skills'), { withFileTypes: true }).filter(item => item.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) { | ||
| 156 | + const path = join(output, 'skills', directory.name, 'SKILL.md') | ||
| 157 | + if (!existsSync(path)) continue | ||
| 158 | + const metadata = skillInfo(path) | ||
| 159 | + skillNames.push(metadata.name) | ||
| 160 | + sources.push({ pluginId: plugin.id, originalName: metadata.name, path: relative(target, path).split(sep).join('/'), hash: treeHash(dirname(path)), entry: metadata.name === plugin.id }) | ||
| 161 | + } | ||
| 162 | + if (!skillNames.includes(plugin.id)) throw new Error(`Workflow entry is not loadable: ${plugin.id}`) | ||
| 163 | + const dependencyFile = join(upstream, 'plugin-install.json') | ||
| 164 | + plugins.push({ ...plugin, version: manifest.version ?? config.commit, description: manifest.description, generatedEntry, skills: skillNames, runtimeDependencies: existsSync(dependencyFile) ? json(dependencyFile).dependencies ?? [] : [] }) | ||
| 165 | +} | ||
| 166 | +const exposedSkills = [] | ||
| 167 | +const winners = new Map() | ||
| 168 | +for (const skill of sources) { | ||
| 169 | + const previous = winners.get(skill.originalName) | ||
| 170 | + if (!previous) { | ||
| 171 | + winners.set(skill.originalName, skill) | ||
| 172 | + skill.name = skill.originalName | ||
| 173 | + exposedSkills.push(skill) | ||
| 174 | + } else if (previous.hash === skill.hash) skill.name = previous.name | ||
| 175 | + else { | ||
| 176 | + skill.name = `${skill.pluginId}-${skill.originalName}` | ||
| 177 | + if (exposedSkills.some(item => item.name === skill.name)) throw new Error(`Duplicate public Skill name: ${skill.name}`) | ||
| 178 | + exposedSkills.push(skill) | ||
| 179 | + } | ||
| 180 | +} | ||
| 181 | +for (const plugin of plugins) { | ||
| 182 | + plugin.aliases = Object.fromEntries(sources.filter(skill => skill.pluginId === plugin.id && skill.name !== skill.originalName).map(skill => [skill.originalName, skill.name])) | ||
| 183 | +} | ||
| 184 | +const catalog = { generatedBy: 'cannbot-dsh-vendor', repository: config.repository, commit: config.commit, skillsRepository: 'https://gitcode.com/cann/cannbot-skills.git', skillsCommit: config.skillsCommit, plugins, exposedSkills, skillCopies: sources.length } | ||
| 185 | +writeFileSync(join(target, 'catalog.json'), JSON.stringify(catalog, null, 2) + '\n') | ||
| 186 | +console.log(JSON.stringify({plugins:catalog.plugins.length,skills:catalog.exposedSkills.length})); | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +import { withStaging } from './staging.mjs' | ||
| 2 | +import { runProcess } from '../src/process-runner.mjs' | ||
| 3 | +import { mkdirSync, readFileSync, writeFileSync, cpSync } from 'node:fs' | ||
| 4 | +import { createHash } from 'node:crypto' | ||
| 5 | +import { resolve, join } from 'node:path' | ||
| 6 | +import { project, resolveSource } from './source.mjs' | ||
| 7 | +const source = resolveSource() | ||
| 8 | +const packageRoot = process.argv.includes('--short') ? join(project, 'packages/short') : project | ||
| 9 | +mkdirSync(join(project, 'dist'), { recursive: true }) | ||
| 10 | +const manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')) | ||
| 11 | +const file = `${manifest.name.replace(/^@/, '').replaceAll('/', '-')}-${manifest.version}.tgz` | ||
| 12 | +// Stage only the declared release inputs so npm need not traverse isolated | ||
| 13 | +// acceptance runtimes or upstream checkouts beside the project. | ||
| 14 | +await withStaging('cannbot-pack-', async (stage, signal) => { | ||
| 15 | + for (const path of ['package.json', ...manifest.files]) cpSync(path === 'LICENSE' ? join(project, '../LICENSE') : join(packageRoot, path), join(stage, path), { recursive: true }) | ||
| 16 | + await runProcess(process.execPath, [resolve(source, 'node_modules/pnpm/bin/pnpm.mjs'), 'pack', '--out', join(project, 'dist', file)], { | ||
| 17 | + cwd: stage, stdio: 'inherit', signal, | ||
| 18 | + }) | ||
| 19 | +}) | ||
| 20 | +const sha = createHash('sha256').update(readFileSync(join(project, 'dist', file))).digest('hex') | ||
| 21 | +writeFileSync(join(project, 'dist/SHA256SUMS'), `${sha} ${file}\n`) | ||
| @@ -0,0 +1,40 @@ | |||
| 1 | +/** Link the already-installed, pinned official checkout for local development only. */ | ||
| 2 | +import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, symlinkSync, writeFileSync } from 'node:fs' | ||
| 3 | +import { dirname, join, resolve } from 'node:path' | ||
| 4 | +import { project, resolveSource } from './source.mjs' | ||
| 5 | +const checkout = resolveSource(process.argv[2]) | ||
| 6 | +writeFileSync(join(project, '.dsh-source.json'), JSON.stringify({ path: checkout }, null, 2) + '\n') | ||
| 7 | +const modules = join(project, 'node_modules') | ||
| 8 | +mkdirSync(modules, { recursive: true }) | ||
| 9 | +function link(name, target) { | ||
| 10 | + const path = join(modules, name) | ||
| 11 | + if (existsSync(path)) return | ||
| 12 | + mkdirSync(dirname(path), { recursive: true }) | ||
| 13 | + symlinkSync(realpathSync(target), path, 'dir') | ||
| 14 | +} | ||
| 15 | +for (const entry of readdirSync(join(checkout, 'node_modules'), { withFileTypes: true })) { | ||
| 16 | + if (entry.name.startsWith('.')) continue | ||
| 17 | + const path = join(checkout, 'node_modules', entry.name) | ||
| 18 | + if (entry.name.startsWith('@')) { | ||
| 19 | + for (const child of readdirSync(path)) link(`${entry.name}/${child}`, join(path, child)) | ||
| 20 | + } else link(entry.name, path) | ||
| 21 | +} | ||
| 22 | +const workspaces = [] | ||
| 23 | +for (const group of ['vendor', 'packages', 'apps']) { | ||
| 24 | + for (const entry of readdirSync(join(checkout, group), { withFileTypes: true })) { | ||
| 25 | + if (!entry.isDirectory()) continue | ||
| 26 | + const path = join(checkout, group, entry.name) | ||
| 27 | + if (existsSync(join(path, 'package.json'))) workspaces.push(path) | ||
| 28 | + else for (const child of readdirSync(path, { withFileTypes: true })) { | ||
| 29 | + if (child.isDirectory() && existsSync(join(path, child.name, 'package.json'))) workspaces.push(join(path, child.name)) | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | +} | ||
| 33 | +for (const path of workspaces) { | ||
| 34 | + const manifest = JSON.parse(readFileSync(join(path, 'package.json'), 'utf8')) | ||
| 35 | + if (manifest.name) link(manifest.name, path) | ||
| 36 | +} | ||
| 37 | +for (const name of ['react', 'react-dom', '@testing-library/react', '@types/react', '@types/react-dom']) { | ||
| 38 | + link(name, join(checkout, 'packages/client/ui-plugin-manager/node_modules', name)) | ||
| 39 | +} | ||
| 40 | +console.log('Linked the official checkout for plugin development; no runtime files were changed.') | ||
| @@ -0,0 +1,12 @@ | |||
| 1 | +import { existsSync, readFileSync } from 'node:fs' | ||
| 2 | +import { resolve } from 'node:path' | ||
| 3 | +import { fileURLToPath } from 'node:url' | ||
| 4 | +export const project = fileURLToPath(new URL('../', import.meta.url)) | ||
| 5 | +export function resolveSource(explicit) { | ||
| 6 | + const local = resolve(project, '.dsh-source.json') | ||
| 7 | + const saved = existsSync(local) ? JSON.parse(readFileSync(local, 'utf8')).path : undefined | ||
| 8 | + const source = resolve(explicit || process.env.DSH_SOURCE || saved || resolve(project, '../deepseek-harness')) | ||
| 9 | + const manifest = JSON.parse(readFileSync(resolve(source, 'package.json'), 'utf8')) | ||
| 10 | + if (manifest.name !== '@deepseek-ai/dsh-root' || manifest.version !== '0.2.1-rc.3') throw new Error('Use the official DSH 0.2.1-rc.3 source checkout.') | ||
| 11 | + return source | ||
| 12 | +} | ||
| @@ -0,0 +1,18 @@ | |||
| 1 | +import { mkdtempSync, rmSync } from 'node:fs' | ||
| 2 | +import { tmpdir } from 'node:os' | ||
| 3 | +import { join } from 'node:path' | ||
| 4 | + | ||
| 5 | +export async function withStaging(prefix, action) { | ||
| 6 | + const directory = mkdtempSync(join(tmpdir(), prefix)) | ||
| 7 | + const abort = new AbortController() | ||
| 8 | + const interrupt = () => { process.exitCode = 130; abort.abort(new Error('Interrupted')) } | ||
| 9 | + const terminate = () => { process.exitCode = 143; abort.abort(new Error('Terminated')) } | ||
| 10 | + process.on('SIGINT', interrupt) | ||
| 11 | + process.on('SIGTERM', terminate) | ||
| 12 | + try { return await action(directory, abort.signal) } | ||
| 13 | + finally { | ||
| 14 | + rmSync(directory, { recursive: true, force: true }) | ||
| 15 | + process.removeListener('SIGINT', interrupt) | ||
| 16 | + process.removeListener('SIGTERM', terminate) | ||
| 17 | + } | ||
| 18 | +} | ||
| @@ -0,0 +1,23 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import type { HeroBrandMarkOwnerProps } from '@deepseek-ai/dsh-client-ui-conversation/client' | ||
| 12 | +import type { SidebarBrandMarkOwnerProps } from '@deepseek-ai/dsh-client-ui-sidebar/client' | ||
| 13 | +import logo from './logo.svg' | ||
| 14 | + | ||
| 15 | +/** CANNBot brand mark: the packaged logo, scaled by the slot's requested size. */ | ||
| 16 | +export function Mark({ size }: { size: number }) { | ||
| 17 | + return <img src={logo} width={size} height={size} alt="" aria-hidden="true" draggable={false} data-cannbot-dsh-logo="" /> | ||
| 18 | +} | ||
| 19 | +export function SidebarMark({ size }: SidebarBrandMarkOwnerProps) { return <Mark size={size} /> } | ||
| 20 | +export function SidebarName() { return <span className="cannbot-dsh-name">CANNBot</span> } | ||
| 21 | +export function Hero({ size }: HeroBrandMarkOwnerProps) { | ||
| 22 | + return <span data-cannbot-dsh-hero=""><Mark size={size} /><span>CANNBot</span></span> | ||
| 23 | +} | ||
| @@ -0,0 +1,54 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useState, useSyncExternalStore } from 'react' | ||
| 12 | +import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 13 | +import type { ContentStore } from './content-store.ts' | ||
| 14 | +import { newerVersion } from './plugin-update.ts' | ||
| 15 | +import { workflowCopy } from './workflow-copy.ts' | ||
| 16 | +export function ContentCard({ content, t }: { content: ContentStore } & PropsLocale<'cannbotDsh'>) { | ||
| 17 | + const { status } = useSyncExternalStore(content.subscribe, content.getSnapshot) | ||
| 18 | + const [failed, setFailed] = useState(false) | ||
| 19 | + const busy = status?.busy || status?.phase === 'syncing' || status?.phase === 'initializing' | ||
| 20 | + const act = (action: () => Promise<void>) => { setFailed(false); void action().catch(() => setFailed(true)) } | ||
| 21 | + return <section className="cannbot-dsh-update cannbot-dsh-content" aria-label={t('contentTitle')}> | ||
| 22 | + <div className="cannbot-dsh-update-heading"><h4>{t('contentTitle')}</h4> | ||
| 23 | + {status?.catalogVersion && <span>{t('contentCatalog')} {status.catalogVersion}</span>}</div> | ||
| 24 | + <div className="cannbot-dsh-update-actions"> | ||
| 25 | + <button type="button" className="cannbot-dsh-update-button" disabled={busy} onClick={() => act(content.sync)}>{busy ? t('contentBusy') : t('contentSync')}</button> | ||
| 26 | + <button type="button" className="cannbot-dsh-update-recheck" disabled={busy} onClick={() => act(content.check)}>{t('contentCheck')}</button> | ||
| 27 | + </div> | ||
| 28 | + <p role={failed || status?.phase === 'error' ? 'alert' : 'status'} aria-live="polite"> | ||
| 29 | + {failed || status?.phase === 'error' ? t('contentFailed') : status?.phase === 'initializing' ? t('contentInitializing') : status?.phase === 'syncing' ? t('contentDownloading') : status?.fallback ? t('contentFallback') : t('contentReady')} | ||
| 30 | + </p> | ||
| 31 | + {status && <p>{status.plugins.length} {t('contentWorkflows')}</p>} | ||
| 32 | + <div className="cannbot-dsh-workflow-packages"> | ||
| 33 | + {status?.workflows?.map(row => { | ||
| 34 | + const available = row.latest && (!row.version || newerVersion(row.latest, row.version)) | ||
| 35 | + const copy = workflowCopy(row, t) | ||
| 36 | + return <div className="cannbot-dsh-workflow-package" key={row.id}> | ||
| 37 | + <div><strong lang="en">{copy.name}</strong><small>{copy.description}</small><small lang="en">{row.package}</small> | ||
| 38 | + <small>{row.version ? `${t('contentVersion')} ${row.version}` : t('contentNotInstalled')} | ||
| 39 | + {available && ` · ${t('contentLatest')} ${row.latest}`}{row.pinned && ` · ${t('contentPinned')}`}</small> | ||
| 40 | + {row.error && <small role="alert">{row.error}</small>}</div> | ||
| 41 | + <div className="cannbot-dsh-workflow-package-actions"> | ||
| 42 | + {available ? <button type="button" className="cannbot-dsh-update-recheck" disabled={busy} | ||
| 43 | + aria-label={`${row.installed ? t('contentUpdate') : t('contentInstall')} ${copy.name}`} | ||
| 44 | + onClick={() => act(() => content.update(row.id, row.latest!))}>{row.installed ? t('contentUpdate') : t('contentInstall')}</button> | ||
| 45 | + : <small>{row.installed ? row.latest ? t('contentUpToDate') : t('contentUnchecked') : t('contentUnavailable')}</small>} | ||
| 46 | + {row.previous && <button type="button" className="cannbot-dsh-update-recheck" disabled={busy} | ||
| 47 | + aria-label={`${t('contentRollback')} ${copy.name}`} onClick={() => act(() => content.rollback(row.id))}>{t('contentRollback')} {row.previous}</button>} | ||
| 48 | + </div> | ||
| 49 | + </div> | ||
| 50 | + })} | ||
| 51 | + </div> | ||
| 52 | + {(status?.log || status?.message) && <details><summary>{t('contentLogs')}</summary><pre>{status.message}{'\n'}{status.log}</pre></details>} | ||
| 53 | + </section> | ||
| 54 | +} | ||
| @@ -0,0 +1,24 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useSyncExternalStore } from 'react' | ||
| 12 | +import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 13 | +import type { PresentationController } from './presentation.ts' | ||
| 14 | +import { Mark } from './Brand.tsx' | ||
| 15 | +import { PRODUCT } from './locales.ts' | ||
| 16 | + | ||
| 17 | +export function InterfaceToggle({ wide, controller }: PropsRuntime<'sidebar.footer.action'> & { controller: PresentationController }) { | ||
| 18 | + const enabled = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot) | ||
| 19 | + return <div className={`cannbot-dsh-toggle${wide ? '' : ' cannbot-dsh-toggle-compact'}`}> | ||
| 20 | + <span className="cannbot-dsh-toggle-name" title={PRODUCT}><Mark size={20} />{wide && <span>{PRODUCT}</span>}</span> | ||
| 21 | + <button type="button" role="switch" aria-label={PRODUCT} aria-checked={enabled} title={PRODUCT} | ||
| 22 | + className="cannbot-dsh-switch" onClick={() => controller.setEnabled(!enabled)}><span /></button> | ||
| 23 | + </div> | ||
| 24 | +} | ||
| @@ -0,0 +1,45 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useEffect, useSyncExternalStore } from 'react' | ||
| 12 | +import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 13 | +import type { PluginUpdater } from './plugin-update.ts' | ||
| 14 | + | ||
| 15 | +export function PluginUpdateCard({ updater, t }: { updater: PluginUpdater } & PropsLocale<'cannbotDsh'>) { | ||
| 16 | + const state = useSyncExternalStore(updater.subscribe, updater.getSnapshot) | ||
| 17 | + useEffect(() => { void updater.check() }, [updater]) | ||
| 18 | + const busy = state.phase === 'checking' || state.phase === 'updating' | ||
| 19 | + const canUpdate = state.phase === 'available' | ||
| 20 | + const message = state.phase === 'latest' ? t('updateLatest') | ||
| 21 | + : state.phase === 'available' ? t('updateAvailable') | ||
| 22 | + : state.phase === 'updating' ? t('updateRunning') | ||
| 23 | + : state.phase === 'done' ? t('updateDone') | ||
| 24 | + : state.phase === 'restart' ? t('updateRestart') | ||
| 25 | + : state.phase === 'manual' ? t('updateManual') | ||
| 26 | + : state.phase === 'incompatible' ? t('updateIncompatible') | ||
| 27 | + : state.phase === 'error' ? t('updateFailed') : '' | ||
| 28 | + return <section className="cannbot-dsh-update" aria-label={t('updateTitle')}> | ||
| 29 | + <div className="cannbot-dsh-update-heading"><h4>{t('updateTitle')}</h4> | ||
| 30 | + {state.current && <span>{t('updateCurrent')} {state.current}</span>}</div> | ||
| 31 | + <div className="cannbot-dsh-update-actions"> | ||
| 32 | + {state.phase === 'manual' && state.release ? <> | ||
| 33 | + <a className="cannbot-dsh-update-button" href={state.release.tarball} download rel="noreferrer">{t('updateDownload')} {state.release.version}</a> | ||
| 34 | + <button type="button" className="cannbot-dsh-update-recheck" onClick={() => { void updater.check() }}>{t('updateCheck')}</button> | ||
| 35 | + </> : | ||
| 36 | + <button type="button" className="cannbot-dsh-update-button" disabled={busy} | ||
| 37 | + onClick={() => { void (canUpdate ? updater.update() : updater.check()) }}> | ||
| 38 | + {state.phase === 'checking' ? t('updateChecking') : state.phase === 'updating' ? t('updateRunning') | ||
| 39 | + : canUpdate ? `${t('updateTo')} ${state.release?.version}` : t('updateCheck')} | ||
| 40 | + </button> | ||
| 41 | + } | ||
| 42 | + </div> | ||
| 43 | + {message && <p role={state.phase === 'error' ? 'alert' : 'status'} aria-live="polite">{message}</p>} | ||
| 44 | + </section> | ||
| 45 | +} | ||
| @@ -0,0 +1,28 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useSyncExternalStore } from 'react' | ||
| 12 | +import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 13 | +import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' | ||
| 14 | +import type { WorkflowSelection } from './workflow-selection.ts' | ||
| 15 | + | ||
| 16 | +export type SessionWorkflowProps = Pick<PropsRuntime<'conversation.session.header.actions'>, 'sessionId'> | ||
| 17 | + & PropsLocale<'cannbotDsh'> & { selection: WorkflowSelection } | ||
| 18 | + | ||
| 19 | +/** Read the committed selection for this header's Session, including after reload. */ | ||
| 20 | +export function SessionWorkflow({ sessionId, selection, t }: SessionWorkflowProps) { | ||
| 21 | + const saved = useSyncExternalStore(selection.subscribe, selection.getSnapshot) | ||
| 22 | + const workflow = saved.values[sessionId] | ||
| 23 | + if (!workflow) return null | ||
| 24 | + return <span className="cannbot-dsh-session-workflow" title={`${t('currentWorkflow')}: ${workflow}`}> | ||
| 25 | + <span>{t('currentWorkflow')}</span> | ||
| 26 | + <code>{workflow}</code> | ||
| 27 | + </span> | ||
| 28 | +} | ||
| @@ -0,0 +1,47 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useState } from 'react' | ||
| 12 | +import { StateDot } from '@deepseek-ai/dsh-client-ui-primitives' | ||
| 13 | +import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 14 | +import type { TodoItem } from '@deepseek-ai/dsh-tool-todo/client' | ||
| 15 | + | ||
| 16 | +type Props = PropsLocale<'cannbotDsh'> & { todos: readonly TodoItem[] } | ||
| 17 | + | ||
| 18 | +/** One view of the native todos projection, including a compact completion history. */ | ||
| 19 | +export function TaskList({ todos, t }: Props) { | ||
| 20 | + const [expanded, setExpanded] = useState(false) | ||
| 21 | + const [showAll, setShowAll] = useState(false) | ||
| 22 | + if (!todos.length) return null | ||
| 23 | + const done = todos.filter(task => task.status === 'completed') | ||
| 24 | + const open = todos.filter(task => task.status !== 'completed') | ||
| 25 | + const visible = [...(showAll ? done : done.slice(-2)).reverse(), ...open] | ||
| 26 | + return <section className="cannbot-task-list" aria-label={t('tasksTitle')}> | ||
| 27 | + <button className="cannbot-task-list-toggle" type="button" aria-expanded={expanded} onClick={() => setExpanded(value => !value)}> | ||
| 28 | + <strong>{t('tasksTitle')}</strong> | ||
| 29 | + <span role="status">{t('tasksDone')} {done.length} / {todos.length}</span> | ||
| 30 | + <span className="cannbot-task-list-chevron" aria-hidden>{expanded ? '⌄' : '⌃'}</span> | ||
| 31 | + </button> | ||
| 32 | + {expanded && <><ul>{visible.map(task => <li key={task.content} data-status={task.status}> | ||
| 33 | + <span className="cannbot-task-list-icon" aria-hidden>{task.status === 'in_progress' | ||
| 34 | + ? <StateDot state="ongoing" /> : task.status === 'completed' ? '✓' : '○'}</span> | ||
| 35 | + <span>{task.content}</span> | ||
| 36 | + </li>)}</ul> | ||
| 37 | + {done.length > 2 && <button type="button" onClick={() => setShowAll(value => !value)}> | ||
| 38 | + {t(showAll ? 'tasksRecent' : 'tasksAll')} | ||
| 39 | + </button>} | ||
| 40 | + </>} | ||
| 41 | + </section> | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +export function TaskDock({ useProjection, t }: PropsRuntime<'conversation.input.dock'> & PropsLocale<'cannbotDsh'>) { | ||
| 45 | + const todos = useProjection('todos') | ||
| 46 | + return <TaskList todos={todos ?? []} t={t} /> | ||
| 47 | +} | ||
| @@ -0,0 +1,132 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useMemo, useRef, useState, useSyncExternalStore, type FormEvent } from 'react' | ||
| 12 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 13 | +import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client' | ||
| 14 | +import type { MainPanelId } from '@deepseek-ai/dsh-client-ui-layout/client' | ||
| 15 | +import type {} from '@deepseek-ai/dsh-client-ui-workspace/client' | ||
| 16 | +import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client' | ||
| 17 | +import type { WorkflowSelection } from './workflow-selection.ts' | ||
| 18 | +import type { ContentStore, DynamicWorkflow } from './content-store.ts' | ||
| 19 | +import { preparationLabels, type WorkbenchStore } from './workbench-state.ts' | ||
| 20 | +import { cardOrder, categories, guideFor, type Category } from './workbench-data.ts' | ||
| 21 | +import { inheritedWorkspaceId } from './workbench-workspace.ts' | ||
| 22 | +import { WorkbenchIcon } from './WorkbenchIcon.tsx' | ||
| 23 | +import { WorkspaceDirectory } from './WorkspaceDirectory.tsx' | ||
| 24 | +import { workflowCopy } from './workflow-copy.ts' | ||
| 25 | +import { zh, PACKAGE } from './locales.ts' | ||
| 26 | +import { launchWorkbench } from './workbench-launch.ts' | ||
| 27 | +import { newerVersion } from './plugin-update.ts' | ||
| 28 | + | ||
| 29 | +export const HOME_PANEL = 'cannbot-dsh-workbench' as MainPanelId | ||
| 30 | +export const LIBRARY_PANEL = 'cannbot-dsh-workflows' as MainPanelId | ||
| 31 | +const copy = (workflow: DynamicWorkflow) => workflowCopy(workflow, key => zh[key]) | ||
| 32 | +export interface WorkbenchProps { ctx: Context; content: ContentStore; selection: WorkflowSelection; store: WorkbenchStore; library?: boolean } | ||
| 33 | + | ||
| 34 | +export function Workbench({ ctx, content, selection, store, library = false }: WorkbenchProps) { | ||
| 35 | + const state = useSyncExternalStore(store.subscribe, store.getSnapshot) | ||
| 36 | + const { workflows } = useSyncExternalStore(content.subscribe, content.getSnapshot) | ||
| 37 | + const workspaceSource = ctx.workspaces.list | ||
| 38 | + const workspaceBinding = useMemo(() => ({ subscribe: (listener: () => void) => workspaceSource.subscribe(listener), getSnapshot: () => workspaceSource.getSnapshot() }), [workspaceSource]) | ||
| 39 | + const workspaceState = useSyncExternalStore(workspaceBinding.subscribe, workspaceBinding.getSnapshot) | ||
| 40 | + const sessionSource = (ctx.sessions as unknown as ISessions).list | ||
| 41 | + const sessionBinding = useMemo(() => ({ subscribe: (listener: () => void) => sessionSource.subscribe(listener), getSnapshot: () => sessionSource.getSnapshot() }), [sessionSource]) | ||
| 42 | + const sessionState = useSyncExternalStore(sessionBinding.subscribe, sessionBinding.getSnapshot) | ||
| 43 | + const saved = useSyncExternalStore(selection.subscribe, selection.getSnapshot) | ||
| 44 | + const [category, setCategory] = useState<Category>('全部') | ||
| 45 | + const [query, setQuery] = useState('') | ||
| 46 | + const [pickingWorkspace, setPickingWorkspace] = useState(false) | ||
| 47 | + const input = useRef<HTMLTextAreaElement>(null) | ||
| 48 | + const files = useRef<HTMLInputElement>(null) | ||
| 49 | + const ordered = [...workflows].sort((a, b) => (cardOrder.indexOf(a.id) < 0 ? 999 : cardOrder.indexOf(a.id)) - (cardOrder.indexOf(b.id) < 0 ? 999 : cardOrder.indexOf(b.id))) | ||
| 50 | + const visible = ordered.filter(workflow => (category === '全部' || guideFor(workflow.id).category === category) && `${workflow.id} ${copy(workflow).description}`.toLowerCase().includes(query.toLowerCase().trim())) | ||
| 51 | + const inheritedId = inheritedWorkspaceId(workspaceState.items, sessionState) | ||
| 52 | + const workspace = workspaceState.items.find(item => item.workspaceId === (state.workspaceId || inheritedId)) | ||
| 53 | + const inherited = !state.workspaceId && !!workspace && workspace.workspaceId === inheritedId | ||
| 54 | + const selected = workflows.find(item => item.id === state.workflow) | ||
| 55 | + const detail = workflows.find(item => item.id === state.detail) ?? workflows[0] | ||
| 56 | + const navigate = (panel: MainPanelId) => ctx.layout.selectPanel(panel) | ||
| 57 | + const settings = () => ctx.get('pluginNavigation')?.openBundle(PACKAGE) | ||
| 58 | + const fail = (error: unknown) => store.set({ error: error instanceof Error ? error.message : '暂时无法完成,请重试。' }) | ||
| 59 | + const start = async (event?: FormEvent) => { | ||
| 60 | + event?.preventDefault() | ||
| 61 | + if (store.getSnapshot().busy) return | ||
| 62 | + if (!workspace) { store.set({ error: '请先选择或添加工作区。' }); return } | ||
| 63 | + if (!state.prompt.trim() && state.files.length === 0) { input.current?.focus(); return } | ||
| 64 | + store.set({ busy: true, error: '', stage: 'workspace' }) | ||
| 65 | + try { | ||
| 66 | + await launchWorkbench(ctx, selection, { workspaceId: workspace.workspaceId, workflow: state.workflow, prompt: state.prompt, files: state.files }, store.signal, stage => store.set({ stage })) | ||
| 67 | + store.set({ prompt: '', files: [] }) | ||
| 68 | + } catch (error) { fail(error) } finally { store.set({ busy: false, stage: 'idle' }) } | ||
| 69 | + } | ||
| 70 | + const useWorkflow = (id: string, example?: string) => { | ||
| 71 | + store.set({ workflow: id, ...(example && !state.prompt.trim() ? { prompt: example } : {}), error: '' }) | ||
| 72 | + navigate(HOME_PANEL) | ||
| 73 | + } | ||
| 74 | + return <main className="cannbot-workbench" aria-label={library ? 'CANNBot 工作流' : 'CANNBot工作台'}> | ||
| 75 | + <header className="cwb-header"> | ||
| 76 | + <div className="cwb-workspace"><WorkbenchIcon name="folder" /><div className="cwb-workspace-info"><div className="cwb-workspace-choice"> | ||
| 77 | + <select aria-label="当前工作区" value={workspace?.workspaceId ?? ''} disabled={state.busy || workspaceState.phase !== 'ready'} onChange={event => store.set({ workspaceId: event.target.value, error: '' })}> | ||
| 78 | + {!workspace && <option value="">选择工作区</option>} | ||
| 79 | + {workspaceState.items.map(item => <option key={item.workspaceId} value={item.workspaceId}>{item.title === 'default-workspace' ? '默认工作区' : item.title}</option>)} | ||
| 80 | + </select>{inherited && <span className="cwb-inherited">沿用当前对话</span>}</div>{workspace && <span className="cwb-workspace-path" title={workspace.path}>{workspace.path}</span>}</div><button className="cwb-text-button" disabled={state.busy} onClick={() => setPickingWorkspace(true)}>选择工作区</button> | ||
| 81 | + </div> | ||
| 82 | + {library && <button className="cwb-text-button" onClick={settings}>插件设置</button>} | ||
| 83 | + </header> | ||
| 84 | + {pickingWorkspace && <WorkspaceDirectory ctx={ctx} initialPath={workspace?.path} onSelect={workspaceId => { if (!store.signal.aborted) store.set({ workspaceId, error: '' }) }} onClose={() => setPickingWorkspace(false)} />} | ||
| 85 | + <div className="cwb-content"> | ||
| 86 | + <div className="cwb-heading"><h1>{library ? '找到适合你的工作流' : '开始你的 Ascend 开发'}</h1>{library && <p>了解适用场景,准备好输入,再开始。</p>}</div> | ||
| 87 | + {!library && <> | ||
| 88 | + <form className="cwb-composer" onSubmit={event => void start(event)} onDragOver={event => event.preventDefault()} onDrop={event => { event.preventDefault(); if (!state.busy) store.set({ files: [...state.files, ...Array.from(event.dataTransfer.files)] }) }}> | ||
| 89 | + <textarea ref={input} aria-label="开发需求" placeholder={selected ? `例如:${guideFor(selected.id).example}` : '描述算子需求,或添加需要优化的代码。'} value={state.prompt} disabled={state.busy} onChange={event => store.set({ prompt: event.target.value })} /> | ||
| 90 | + {state.files.length > 0 && <ul className="cwb-files">{state.files.map((file, index) => <li key={`${file.name}-${index}`}><WorkbenchIcon name="document" size={14} /><span>{file.name}</span><button type="button" disabled={state.busy} aria-label={`移除 ${file.name}`} onClick={() => store.set({ files: state.files.filter((_, i) => i !== index) })}>×</button></li>)}</ul>} | ||
| 91 | + <div className="cwb-composer-actions"><div className="cwb-composer-tools"> | ||
| 92 | + <input type="file" multiple hidden ref={files} onChange={event => { store.set({ files: [...state.files, ...Array.from(event.target.files ?? [])] }); event.target.value = '' }} /> | ||
| 93 | + <button type="button" className="cwb-text-button" disabled={state.busy} onClick={() => files.current?.click()}><WorkbenchIcon name="clip" size={18} />添加文件</button> | ||
| 94 | + {state.workflow && <span className="cwb-selection"><WorkbenchIcon name={guideFor(state.workflow).icon} size={16} /><span>{state.workflow}</span><button type="button" disabled={state.busy} aria-label="取消工作流选择" onClick={() => store.set({ workflow: '' })}>×</button></span>} | ||
| 95 | + </div><button className="cwb-primary" type="submit" disabled={state.busy || !saved.ready || saved.pending || (!state.prompt.trim() && !state.files.length)}>{state.busy ? '处理中…' : '开始'}<span aria-hidden="true">→</span></button></div> | ||
| 96 | + </form> | ||
| 97 | + {(state.busy || !saved.ready || !workspace) && <p className="cwb-hint" role="status" aria-live="polite">{state.busy ? preparationLabels[state.stage] : !saved.ready ? '正在连接工作流设置…' : '请先选择或添加工作区。'}</p>} | ||
| 98 | + {saved.errorKind === 'settings' && <button className="cwb-text-button" onClick={() => selection.retry()}>重试连接工作流设置</button>} | ||
| 99 | + </>} | ||
| 100 | + {state.error && <div className="cwb-error" role="alert"><div className="cwb-error-heading"><span>暂时无法开始,需求和文件已保留。</span><button type="button" className="cwb-text-button" disabled={state.busy || !saved.ready || saved.pending} onClick={() => void start()}>重试</button></div><details><summary>查看原因</summary><p>{state.error}</p><button className="cwb-text-button" onClick={settings}>打开插件设置</button></details></div>} | ||
| 101 | + {workspaceState.state === 'error' && <p role="alert" className="cwb-error">工作区加载失败,请检查 DSH 连接。</p>} | ||
| 102 | + {!library && state.workflow && !selected && <p role="alert" className="cwb-error">所选工作流已不在当前目录中,请重新选择。</p>} | ||
| 103 | + <section className="cwb-catalog" aria-label="工作流目录"> | ||
| 104 | + <div className="cwb-catalog-heading"><h2>{library ? '全部工作流' : '工作流'}</h2><label className="cwb-search"><WorkbenchIcon name="search" size={17} /><input aria-label="搜索工作流" placeholder="搜索工作流" value={query} onChange={event => setQuery(event.target.value)} /></label></div> | ||
| 105 | + <div className="cwb-categories" role="group" aria-label="工作流分类">{categories.map(item => <button key={item} aria-pressed={category === item} onClick={() => setCategory(item)}>{item}</button>)}</div> | ||
| 106 | + {library ? <div className="cwb-library"><nav aria-label="选择工作流详情" className="cwb-library-list">{visible.map(workflow => <button key={workflow.id} aria-current={detail?.id === workflow.id ? 'true' : undefined} onClick={() => store.set({ detail: workflow.id })}><WorkbenchIcon name={guideFor(workflow.id).icon} /><span><strong>{workflow.id}</strong><small>{copy(workflow).description}</small></span></button>)}{!visible.length && <p className="cwb-empty">没有匹配的工作流</p>}</nav> | ||
| 107 | + {detail ? <WorkflowDetail key={detail.id} workflow={detail} content={content} onUse={() => useWorkflow(detail.id)} onExample={() => useWorkflow(detail.id, guideFor(detail.id).example)} onSettings={settings} /> : <p className="cwb-empty">工作流目录尚未准备完成,请到插件设置查看准备状态。</p>} | ||
| 108 | + </div> : <div className="cwb-grid">{visible.map(workflow => <button type="button" key={workflow.id} className="cwb-card" aria-pressed={state.workflow === workflow.id} disabled={state.busy} onClick={() => { const next = state.workflow === workflow.id ? '' : workflow.id; store.set({ workflow: next, error: '' }); if (next) input.current?.focus() }}> | ||
| 109 | + <span className="cwb-card-icon"><WorkbenchIcon name={guideFor(workflow.id).icon} size={23} /></span><span className="cwb-card-copy"><strong>{workflow.id}</strong><span>{copy(workflow).description}</span></span><span className="cwb-card-corner" aria-hidden="true"><svg width="18" height="18" viewBox="0 0 20 20" fill="none"><circle cx="10" cy="10" r="8" fill={state.workflow === workflow.id ? '#da203e' : 'none'} stroke={state.workflow === workflow.id ? '#da203e' : 'currentColor'} strokeWidth="1.2" />{state.workflow === workflow.id && <path d="m6 10 2.6 2.6L14 7.2" stroke="white" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />}</svg></span> | ||
| 110 | + </button>)}{!visible.length && <p className="cwb-empty">没有匹配的工作流,请换一个关键词或分类。</p>}</div>} | ||
| 111 | + </section> | ||
| 112 | + </div> | ||
| 113 | + </main> | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +function WorkflowDetail({ workflow, content, onUse, onExample, onSettings }: { workflow: DynamicWorkflow; content: ContentStore; onUse(): void; onExample(): void; onSettings(): void }) { | ||
| 117 | + const { status } = useSyncExternalStore(content.subscribe, content.getSnapshot) | ||
| 118 | + const [error, setError] = useState(''), [pending, setPending] = useState(false) | ||
| 119 | + const guide = guideFor(workflow.id), row = status?.workflows?.find(item => item.id === workflow.id) | ||
| 120 | + const busy = pending || status?.busy || status?.phase === 'syncing' || status?.phase === 'initializing' | ||
| 121 | + const act = async (action: () => Promise<void>) => { setError(''); setPending(true); try { await action() } catch { setError('操作未完成,请在插件设置中查看日志后重试。') } finally { setPending(false) } } | ||
| 122 | + return <article className="cwb-detail" key={workflow.id}> | ||
| 123 | + <div className="cwb-detail-title"><span className="cwb-card-icon"><WorkbenchIcon name={guide.icon} size={25} /></span><span><small>{guide.category}</small><h2>{workflow.id}</h2></span></div> | ||
| 124 | + <p className="cwb-detail-summary">{copy(workflow).description}</p> | ||
| 125 | + <button className="cwb-primary" onClick={onUse}>使用此工作流 <span aria-hidden="true">→</span></button> | ||
| 126 | + <div className="cwb-guide-sections">{[['适合做什么', guide.scenes], ['需要提供什么', guide.inputs], ['可以获得什么', guide.outputs]].map(([title, entries]) => <section key={title as string}><h3>{title}</h3><ul>{(entries as string[]).map(line => <li key={line}>{line}</li>)}</ul></section>)}</div> | ||
| 127 | + <section className="cwb-example"><h3>试试这样描述需求</h3><p>{guide.example}</p><button className="cwb-text-button" onClick={onExample}>使用此示例 ↗</button><small>已有需求会保留,不会被示例覆盖。</small></section> | ||
| 128 | + <details className="cwb-version"><summary>版本与更新 {row?.version ? ` · ${row.version}` : ''}</summary><p>{row?.installed ? `已安装 ${row.version ?? ''}` : '安装状态尚未确认,请检查插件设置。'}{row?.latest && ` · 最新版本 ${row.latest}`}</p><div className="cwb-version-actions"><button className="cwb-text-button" disabled={busy} onClick={() => void act(content.check)}>检查更新</button> | ||
| 129 | + {row?.latest && (!row.version || newerVersion(row.latest, row.version)) && <button className="cwb-text-button" disabled={busy} onClick={() => void act(() => content.update(row.id, row.latest!))}>{row.installed ? '更新工作流' : '安装工作流'}</button>} | ||
| 130 | + {row?.previous && <button className="cwb-text-button" disabled={busy} onClick={() => void act(() => content.rollback(row.id))}>回退到 {row.previous}</button>}<button className="cwb-text-button" onClick={onSettings}>准备日志与管理</button></div><p>初始化和验证以当前工作区的实际环境为准。</p>{error && <p role="alert">{error}</p>}</details> | ||
| 131 | + </article> | ||
| 132 | +} | ||
| @@ -0,0 +1,27 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +export function WorkbenchIcon({ name = 'grid', size = 20 }: { name?: string; size?: number }) { | ||
| 12 | + const paths: Record<string, string> = { | ||
| 13 | + grid: 'M3 3h7v7H3z M14 3h7v7h-7z M3 14h7v7H3z M14 14h7v7h-7z', | ||
| 14 | + code: 'm8 6-6 6 6 6 M16 6l6 6-6 6 M14 3l-4 18', | ||
| 15 | + flash: 'm13 2-9 12h7l-1 8 10-13h-7z', | ||
| 16 | + document: 'M5 3h14v18H5z M8 8h8 M8 12h8 M8 16h5', | ||
| 17 | + layers: 'm12 2 10 6-10 6L2 8z M2 12l10 6 10-6 M2 16l10 6 10-6', | ||
| 18 | + nodes: 'M10 2h4v4h-4z M2 18h6v4H2z M16 18h6v4h-6z M12 6v6 M5 18v-6h14v6', | ||
| 19 | + arrows: 'M3 7h17l-4-4 M20 7l-4 4 M21 17H4l4-4 M4 17l4 4', | ||
| 20 | + chart: 'M3 13h4v8H3z M10 8h4v13h-4z M17 3h4v18h-4z', | ||
| 21 | + gear: 'M9 3h6l1 3 3 1 2 5-2 5-3 1-1 3H9l-1-3-3-1-2-5 2-5 3-1z M9 12a3 3 0 1 0 6 0a3 3 0 1 0-6 0', | ||
| 22 | + folder: 'M2 6h8l2 3h10v12H2z M2 6V3h7l3 3h10v3', | ||
| 23 | + search: 'M16 16l6 6 M18 10a8 8 0 1 0-16 0a8 8 0 1 0 16 0', | ||
| 24 | + clip: 'm8 13 7-7a3 3 0 0 1 4 4L9 20a5 5 0 0 1-7-7L13 2 M6 15l9-9', | ||
| 25 | + } | ||
| 26 | + return <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={paths[name] ?? paths.grid} /></svg> | ||
| 27 | +} | ||
| @@ -0,0 +1,36 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useMemo, useSyncExternalStore } from 'react' | ||
| 12 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 13 | +import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' | ||
| 14 | +import { WorkflowSelector, type WorkflowProps } from './WorkflowSelector.tsx' | ||
| 15 | + | ||
| 16 | +/** Older DSH declares the hero seat at root scope. Resolve its current session | ||
| 17 | + * through the public services rather than reaching into the editor or DOM. */ | ||
| 18 | +export function WorkflowCompat({ ctx, ...props }: WorkflowProps & { ctx: Context }) { | ||
| 19 | + return typeof props.useInput === 'function' | ||
| 20 | + ? <WorkflowSelector {...props} /> | ||
| 21 | + : <LegacyWorkflow ctx={ctx} {...props} /> | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +function LegacyWorkflow({ ctx, ...props }: WorkflowProps & { ctx: Context }) { | ||
| 25 | + type Input = ReturnType<Context['conversation']['input']['for']> | ||
| 26 | + const legacy = ctx as unknown as { sessions: { list: { subscribe(listener: () => void): () => void; getSnapshot(): { current?: string } }; scope(id: string): Context | undefined } } | ||
| 27 | + const sessions = useSyncExternalStore(legacy.sessions.list.subscribe, legacy.sessions.list.getSnapshot) | ||
| 28 | + const input = useMemo(() => { | ||
| 29 | + const scope = sessions.current && legacy.sessions.scope(sessions.current) | ||
| 30 | + return scope ? ctx.conversation.input.for(scope) as Input : undefined | ||
| 31 | + }, [ctx, sessions.current]) | ||
| 32 | + const state = useSyncExternalStore(input?.state.subscribe ?? noSubscribe, input?.state.getSnapshot ?? noSnapshot) | ||
| 33 | + return <WorkflowSelector {...props} sessionId={sessions.current as WorkflowProps['sessionId']} useInput={select => state ? select(state) : undefined as never} inputActions={input ? {} as WorkflowProps['inputActions'] : undefined} /> | ||
| 34 | +} | ||
| 35 | +const noSubscribe = () => () => {} | ||
| 36 | +const noSnapshot = () => undefined | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import * as primitives from '@deepseek-ai/dsh-client-ui-primitives' | ||
| 12 | +import type { ComponentType } from 'react' | ||
| 13 | + | ||
| 14 | +/** The exact icon component used by DSH's original Standard mode selector. */ | ||
| 15 | +export function WorkflowIcon({ size = 16 }: { size?: number }) { | ||
| 16 | + const icons = primitives as unknown as Record<string, ComponentType<{ size?: number }>> | ||
| 17 | + const Icon = icons.IconAgentPresetOutlineRegular ?? icons.IconAgentPresetOutline16 ?? icons.IconRefreshOutline16 | ||
| 18 | + return Icon ? <Icon size={size} /> : null | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +export function ChevronIcon({ size = 12 }: { size?: number }) { | ||
| 22 | + const icons = primitives as unknown as Record<string, ComponentType<{ size?: number }>> | ||
| 23 | + const Icon = icons.IconChevronDownOutlineRegular ?? icons.IconChevronDownOutline14 | ||
| 24 | + return Icon ? <Icon size={size} /> : <svg width={size} height={size} viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="m3 4.5 3 3 3-3" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" /></svg> | ||
| 25 | +} | ||
| @@ -0,0 +1,62 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useState, useSyncExternalStore, type ComponentType, type ReactNode } from 'react' | ||
| 12 | +import * as primitives from '@deepseek-ai/dsh-client-ui-primitives' | ||
| 13 | +import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 14 | +import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' | ||
| 15 | +import { workflowCopy } from './workflow-copy.ts' | ||
| 16 | +import { WorkflowIcon, ChevronIcon } from './WorkflowIcon.tsx' | ||
| 17 | +import type { WorkflowSelection } from './workflow-selection.ts' | ||
| 18 | +import { fallbackContent, type ContentStore, type DynamicWorkflow } from './content-store.ts' | ||
| 19 | + | ||
| 20 | +export type WorkflowProps = PropsRuntime<'conversation.hero.agentPreset'> & PropsLocale<'cannbotDsh'> & { selection: WorkflowSelection; content?: ContentStore } | ||
| 21 | + | ||
| 22 | +/** Select a workflow without submitting, replacing text, or discarding reference chips. */ | ||
| 23 | +export function WorkflowSelector({ sessionId, inputActions, useInput, t, selection, content = fallbackContent as ContentStore }: WorkflowProps) { | ||
| 24 | + const { workflows } = useSyncExternalStore(content.subscribe, content.getSnapshot) | ||
| 25 | + const copy = (workflow: DynamicWorkflow) => workflowCopy(workflow, t) | ||
| 26 | + const input = useInput(state => state) | ||
| 27 | + const saved = useSyncExternalStore(selection.subscribe, selection.getSnapshot) | ||
| 28 | + const [open, setOpen] = useState(false) | ||
| 29 | + const selected = workflows.find(workflow => sessionId && saved.values[sessionId] === workflow.id) | ||
| 30 | + const available = !!sessionId && saved.ready && !saved.pending && inputActions !== undefined && input !== undefined && input.phase === 'plain' | ||
| 31 | + const pick = (id: string) => { | ||
| 32 | + setOpen(false) | ||
| 33 | + if (sessionId && available) void selection.choose(sessionId, id, t('saving')) | ||
| 34 | + } | ||
| 35 | + const anchor = ( | ||
| 36 | + <button type="button" className="cannbot-dsh-workflow-trigger" aria-label={t('workflow')} aria-haspopup="menu" aria-expanded={open} | ||
| 37 | + disabled={!available} title={inputActions === undefined ? t('chooseWorkspace') : t('commandHint')} | ||
| 38 | + onClick={() => setOpen(value => !value)}> | ||
| 39 | + <WorkflowIcon /> | ||
| 40 | + <span className="cannbot-dsh-workflow-label" lang={selected ? 'en' : undefined}>{selected ? copy(selected).name : t('workflow')}</span><ChevronIcon size={12} /> | ||
| 41 | + </button> | ||
| 42 | + ) | ||
| 43 | + const label = (workflow: DynamicWorkflow) => <span className="cannbot-dsh-workflow-option"> | ||
| 44 | + <span lang="en">{copy(workflow).name}</span> | ||
| 45 | + {copy(workflow).description && <>{' '}<small>{copy(workflow).description}</small></>} | ||
| 46 | + </span> | ||
| 47 | + const { Menu, MenuItemButton } = primitives | ||
| 48 | + const LegacyMenu = Menu as unknown as ComponentType<{ open: boolean; anchor: ReactNode; portal: boolean; className: string; onClose(): void; selectedId?: string; onSelect(id: string): void; items: { id: string; label: ReactNode; icon: ReactNode }[] }> | ||
| 49 | + return <span className="cannbot-dsh-workflow"> | ||
| 50 | + {typeof MenuItemButton === 'function' ? <Menu open={open} onClose={() => setOpen(false)} portal className="cannbot-dsh-workflow-anchor" anchor={anchor}> | ||
| 51 | + <MenuItemButton icon={<WorkflowIcon />} onSelect={() => pick('')}>{t('ordinary')}</MenuItemButton> | ||
| 52 | + {workflows.map(workflow => <MenuItemButton key={workflow.id} icon={<WorkflowIcon />} onSelect={() => pick(workflow.id)}>{label(workflow)}</MenuItemButton>)} | ||
| 53 | + </Menu> : <LegacyMenu open={open} onClose={() => setOpen(false)} portal className="cannbot-dsh-workflow-anchor" anchor={anchor} | ||
| 54 | + selectedId={selected?.id} items={[{ id: '', label: t('ordinary'), icon: <WorkflowIcon /> }, ...workflows.map(workflow => ({ id: workflow.id, label: label(workflow), icon: <WorkflowIcon /> }))]} | ||
| 55 | + onSelect={pick} />} | ||
| 56 | + {saved.error && <span role="alert" className="cannbot-dsh-error"> | ||
| 57 | + <button type="button" onClick={() => selection.retry()} title={t('insertFailed')}> | ||
| 58 | + {t(saved.errorKind === 'settings' ? 'settingsRetry' : 'workflowRetry')} | ||
| 59 | + </button> | ||
| 60 | + </span>} | ||
| 61 | + </span> | ||
| 62 | +} | ||
| @@ -0,0 +1,75 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { useEffect, useRef, useState } from 'react' | ||
| 12 | +import { WorkbenchIcon } from './WorkbenchIcon.tsx' | ||
| 13 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 14 | +import type {} from '@deepseek-ai/dsh-client-ui-workspace/client' | ||
| 15 | + | ||
| 16 | +type Listing = Awaited<ReturnType<Context['uiWorkspace']['listDirectory']>> | ||
| 17 | + | ||
| 18 | +/** Browse Host directories through the capability shared by Web and desktop pickers. */ | ||
| 19 | +export function WorkspaceDirectory({ ctx, initialPath, onSelect, onClose }: { | ||
| 20 | + ctx: Context; initialPath?: string; onSelect(id: string): void; onClose(): void | ||
| 21 | +}) { | ||
| 22 | + const dialog = useRef<HTMLDialogElement>(null) | ||
| 23 | + const lifetime = useRef<AbortController | null>(null) | ||
| 24 | + const request = useRef<AbortController | null>(null) | ||
| 25 | + const [listing, setListing] = useState<Listing>() | ||
| 26 | + const [path, setPath] = useState(initialPath ?? '') | ||
| 27 | + const [loading, setLoading] = useState(true) | ||
| 28 | + const [saving, setSaving] = useState(false) | ||
| 29 | + const [error, setError] = useState('') | ||
| 30 | + const browse = async (target?: string) => { | ||
| 31 | + request.current?.abort() | ||
| 32 | + const controller = new AbortController() | ||
| 33 | + request.current = controller | ||
| 34 | + setLoading(true); setError(''); setListing(undefined) | ||
| 35 | + try { | ||
| 36 | + const next = await ctx.uiWorkspace.listDirectory(target || undefined, controller.signal) | ||
| 37 | + if (!controller.signal.aborted) { setListing(next); setPath(next.path) } | ||
| 38 | + } catch (reason) { | ||
| 39 | + if (!controller.signal.aborted) setError(reason instanceof Error ? reason.message : '无法读取目录,请重试。') | ||
| 40 | + } finally { if (!controller.signal.aborted) setLoading(false) } | ||
| 41 | + } | ||
| 42 | + useEffect(() => { | ||
| 43 | + lifetime.current = new AbortController() | ||
| 44 | + dialog.current?.showModal() | ||
| 45 | + void browse(initialPath) | ||
| 46 | + return () => { lifetime.current?.abort(); request.current?.abort() } | ||
| 47 | + }, []) | ||
| 48 | + const choose = async () => { | ||
| 49 | + if (!listing || loading || saving) return | ||
| 50 | + setSaving(true); setError('') | ||
| 51 | + try { | ||
| 52 | + const existing = ctx.workspaces.list.getSnapshot().items.find(item => item.path === listing.path) | ||
| 53 | + const selected = existing ?? await ctx.workspaces.create({ path: listing.path }) | ||
| 54 | + if (!lifetime.current?.signal.aborted) { onSelect(selected.workspaceId); onClose() } | ||
| 55 | + } catch (reason) { | ||
| 56 | + if (!lifetime.current?.signal.aborted) setError(reason instanceof Error ? reason.message : '无法选择工作区,请重试。') | ||
| 57 | + } finally { if (!lifetime.current?.signal.aborted) setSaving(false) } | ||
| 58 | + } | ||
| 59 | + return <dialog ref={dialog} className="cwb-directory" aria-label="选择工作区目录" onCancel={event => { event.preventDefault(); if (!saving) onClose() }}> | ||
| 60 | + <h2>选择工作区</h2> | ||
| 61 | + <p>选择 DSH 所在机器上的项目目录。</p> | ||
| 62 | + <form onSubmit={event => { event.preventDefault(); if (!saving) void browse(path) }}> | ||
| 63 | + <input aria-label="目录路径" value={path} disabled={saving} onChange={event => setPath(event.target.value)} /> | ||
| 64 | + <button className="cwb-text-button" disabled={saving} type="submit">打开目录</button> | ||
| 65 | + </form> | ||
| 66 | + <nav aria-label="目录层级">{listing?.crumbs.map(crumb => <button type="button" className="cwb-text-button" key={crumb.path} disabled={saving} onClick={() => void browse(crumb.path)}>{crumb.name || crumb.path}</button>)}</nav> | ||
| 67 | + {loading ? <p role="status">正在读取目录…</p> : listing && <> | ||
| 68 | + <ul className="cwb-directory-list">{listing.entries.map(entry => <li key={entry.path}><button type="button" disabled={saving} onClick={() => void browse(entry.path)}><WorkbenchIcon name="folder" size={16} /> {entry.name}</button></li>)}</ul> | ||
| 69 | + {!listing.entries.length && <p>此目录下没有子目录,可以直接选择当前目录。</p>} | ||
| 70 | + {listing.truncated && <p>目录较多,仅显示部分结果;可输入完整路径打开。</p>} | ||
| 71 | + </>} | ||
| 72 | + {error && <div role="alert" className="cwb-error">{error}</div>} | ||
| 73 | + <footer><button type="button" className="cwb-text-button" disabled={saving} onClick={onClose}>取消</button><button type="button" className="cwb-primary" disabled={loading || saving || !listing || path !== listing.path} onClick={() => void choose()}>{saving ? '正在选择…' : '选择此目录'}</button></footer> | ||
| 74 | + </dialog> | ||
| 75 | +} | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { WORKFLOWS } from '../workflows.ts' | ||
| 12 | +import { CONTENT_PATH, type ContentStatus } from '../content-types.ts' | ||
| 13 | +export interface DynamicWorkflow { id: string; title: string } | ||
| 14 | +const initial: { workflows: DynamicWorkflow[]; status: ContentStatus | undefined } = { workflows: WORKFLOWS.map(({ id }) => ({ id, title: id })), status: undefined } | ||
| 15 | +export function createContentStore() { | ||
| 16 | + let state = initial, closed = false, timer: ReturnType<typeof setTimeout> | undefined | ||
| 17 | + const listeners = new Set<() => void>() | ||
| 18 | + const publish = (status: ContentStatus) => { if (!closed) { state = { status, workflows: status.plugins }; for (const listener of listeners) listener() } } | ||
| 19 | + const endpoint = () => new URL(CONTENT_PATH, document.baseURI) | ||
| 20 | + let requestSequence = 0 | ||
| 21 | + const pull = async () => { | ||
| 22 | + const sequence = ++requestSequence | ||
| 23 | + try { | ||
| 24 | + const response = await fetch(endpoint(), { credentials: 'same-origin', cache: 'no-store', signal: AbortSignal.timeout(15000) }) | ||
| 25 | + if (response.ok) { | ||
| 26 | + const status = await response.json() as ContentStatus | ||
| 27 | + if (sequence === requestSequence && Array.isArray(status.plugins) && status.plugins.every(item => /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(item.id) && typeof item.title === 'string')) publish(status) | ||
| 28 | + } | ||
| 29 | + } catch { /* Keep the last catalog across a short disconnect. */ } | ||
| 30 | + } | ||
| 31 | + const post = async (body: object) => { | ||
| 32 | + ++requestSequence // Invalidate pre-operation snapshots before the POST begins. | ||
| 33 | + const response = await fetch(endpoint(), { method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }) | ||
| 34 | + if (!response.ok) { await pull(); throw new Error(state.status?.message || '工作流准备失败,请检查插件日志。') } | ||
| 35 | + await pull() | ||
| 36 | + } | ||
| 37 | + return { | ||
| 38 | + getSnapshot: () => state, | ||
| 39 | + subscribe(listener: () => void) { listeners.add(listener); return () => { listeners.delete(listener) } }, | ||
| 40 | + start() { | ||
| 41 | + const tick = async () => { await pull(); if (!closed) timer = setTimeout(() => { void tick() }, 3000) } | ||
| 42 | + void tick() | ||
| 43 | + return () => { closed = true; clearTimeout(timer); listeners.clear() } | ||
| 44 | + }, | ||
| 45 | + sync: () => post({ action: 'sync' }), | ||
| 46 | + check: () => post({ action: 'check' }), | ||
| 47 | + update: (id: string, version: string) => post({ action: 'update', id, version }), | ||
| 48 | + rollback: (id: string) => post({ action: 'rollback', id }), | ||
| 49 | + prepare: (sessionId: string, id: string) => post({ action: 'prepare', sessionId, id }), | ||
| 50 | + } | ||
| 51 | +} | ||
| 52 | +export type ContentStore = ReturnType<typeof createContentStore> | ||
| 53 | +export const fallbackContent = { getSnapshot: () => initial, subscribe: (_: () => void) => () => {} } | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +.cannbot-dsh-workflow { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; position: relative; min-width: 120px; max-width: 280px; } | ||
| 2 | +.cannbot-dsh-workflow-anchor { flex: none; min-width: 120px; max-width: 100%; } | ||
| 3 | +.cannbot-dsh-workflow-trigger { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; min-height: 28px; padding: 0 8px; border: 0; border-radius: var(--dsw-radius-sm); background: transparent; color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; line-height: 20px; font-weight: 500; white-space: nowrap; cursor: pointer; } | ||
| 4 | +.cannbot-dsh-workflow-trigger svg { flex: none; } | ||
| 5 | +.cannbot-dsh-workflow-trigger svg:last-child { color: var(--dsw-alias-label-caption); } | ||
| 6 | +.cannbot-dsh-workflow-trigger[aria-expanded='true'] { background: var(--dsw-alias-interactive-bg-hover); } | ||
| 7 | +.cannbot-dsh-workflow-trigger:disabled { cursor: default; color: var(--dsw-alias-label-quaternary); } | ||
| 8 | +.cannbot-dsh-workflow-trigger:focus-visible { outline: 2px solid var(--dsw-focus-ring-color); outline-offset: 2px; } | ||
| 9 | +.cannbot-dsh-workflow-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } | ||
| 10 | +@media (hover: hover) { .cannbot-dsh-workflow-trigger:not(:disabled):hover { background: var(--dsw-alias-interactive-bg-hover); } } | ||
| 11 | +.cannbot-dsh-workflow-option { display: flex; flex-direction: column; gap: 4px; padding: 5px 0; max-width: 320px; white-space: normal; } | ||
| 12 | +.cannbot-dsh-workflow-option small { font-size: 12px; line-height: 1.5; color: var(--dsw-alias-label-secondary); } | ||
| 13 | +.cannbot-dsh-error { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); max-width: 100%; } | ||
| 14 | +.cannbot-dsh-error button { border: 0; padding: 0 8px; background: transparent; color: inherit; font: inherit; text-align: start; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; } | ||
| 15 | +.cannbot-dsh-toggle { display: flex; width: 100%; box-sizing: border-box; align-items: center; justify-content: space-between; gap: 8px; padding: 8px; } | ||
| 16 | +.cannbot-dsh-toggle-name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; color: var(--dsw-alias-label-primary); font-size: 12px; line-height: 20px; } | ||
| 17 | +.cannbot-dsh-toggle-name svg { flex-shrink: 0; } | ||
| 18 | +.cannbot-dsh-toggle-compact { flex-direction: column; gap: 6px; } | ||
| 19 | +.cannbot-dsh-switch { width: 36px; height: 20px; padding: 2px; border: 0; border-radius: 99px; background: var(--dsw-alias-interactive-bg-hover, #d7dadd); cursor: pointer; flex-shrink: 0; } | ||
| 20 | +.cannbot-dsh-switch[aria-checked='true'] { background: #cf1740; } | ||
| 21 | +.cannbot-dsh-switch > span { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; transform: translateX(0); } | ||
| 22 | +.cannbot-dsh-switch[aria-checked='true'] > span { transform: translateX(16px); } | ||
| 23 | +.cannbot-dsh-switch:focus-visible { outline: 2px solid var(--dsw-focus-ring-color, #cf1740); outline-offset: 2px; } | ||
| 24 | +.cannbot-dsh-update { padding: 16px; border: 1px solid var(--dsw-alias-border-l2, #e5e7eb); border-radius: var(--dsw-radius-md, 12px); color: var(--dsw-alias-label-primary); } | ||
| 25 | +.cannbot-dsh-update-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; } | ||
| 26 | +.cannbot-dsh-update h4 { margin: 0; font-size: 14px; font-weight: 600; } | ||
| 27 | +.cannbot-dsh-update-heading > span, .cannbot-dsh-update p { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); } | ||
| 28 | +.cannbot-dsh-update-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; } | ||
| 29 | +.cannbot-dsh-update-button { display: inline-flex; align-items: center; box-sizing: border-box; text-decoration: none; min-height: 32px; padding: 5px 14px; background: var(--dsw-alias-brand-primary, #cf1740); color: white; border: 0; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; } | ||
| 30 | +.cannbot-dsh-update-button:disabled { opacity: .6; cursor: default; } | ||
| 31 | +.cannbot-dsh-update-button:focus-visible, .cannbot-dsh-update-recheck:focus-visible { outline: 2px solid var(--dsw-focus-ring-color, #cf1740); outline-offset: 3px; } | ||
| 32 | +.cannbot-dsh-update-recheck { border: 0; background: transparent; padding: 4px; font: inherit; font-size: 12px; color: var(--dsw-alias-brand-primary, #cf1740); cursor: pointer; } | ||
| 33 | +.cannbot-dsh-update p { margin: 10px 0 0; } | ||
| 34 | +.cannbot-dsh-content { margin-top: 16px; } | ||
| 35 | +.cannbot-dsh-content details { margin-top: 12px; font-size: 12px; } | ||
| 36 | +.cannbot-dsh-content summary { cursor: pointer; } | ||
| 37 | +.cannbot-dsh-content pre { max-height: 220px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; line-height: 1.5; } | ||
| 38 | +.cannbot-dsh-workflow-package { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--dsw-alias-border-l2, #eee); } | ||
| 39 | +.cannbot-dsh-workflow-package > div:first-child { min-width: 0; } | ||
| 40 | +.cannbot-dsh-workflow-package strong { font-size: 13px; font-weight: 500; } | ||
| 41 | +.cannbot-dsh-workflow-package small { display: block; font-size: 11px; line-height: 1.6; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; } | ||
| 42 | +.cannbot-dsh-workflow-package-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; flex-shrink: 0; } | ||
| 43 | +@media (max-width: 480px) { .cannbot-dsh-workflow-package { align-items: flex-start; flex-direction: column; } } | ||
| 44 | +.cannbot-dsh-session-workflow { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: min(320px, 40vw); padding: 3px 8px; border-radius: var(--dsw-radius-sm, 6px); background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 20px; } | ||
| 45 | +.cannbot-dsh-session-workflow > span { flex-shrink: 0; } | ||
| 46 | +.cannbot-dsh-session-workflow code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: inherit; color: var(--dsw-alias-label-primary); } | ||
| 47 | +.cannbot-task-list { margin: 0 auto; width: calc(100% - 48px); max-width: var(--dsh-composer-card-max-width, 760px); padding: 8px 12px; box-sizing: border-box; border-radius: var(--dsw-radius-lg, 12px); background: var(--dsw-specific-menu); color: var(--dsw-alias-label-primary); font-size: 13px; } | ||
| 48 | +.cannbot-task-list .cannbot-task-list-toggle { display: flex; width: 100%; align-items: center; flex-wrap: wrap; gap: 12px; padding: 0; text-align: left; } | ||
| 49 | +.cannbot-task-list-toggle span { color: var(--dsw-alias-label-secondary); } | ||
| 50 | +.cannbot-task-list-chevron { margin-left: auto; } | ||
| 51 | +.cannbot-task-list button { margin-left: auto; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; } | ||
| 52 | +.cannbot-task-list ul { list-style: none; padding: 0; margin: 8px 0 0; max-height: 220px; overflow-y: auto; } | ||
| 53 | +.cannbot-task-list li { display: flex; gap: 8px; padding: 3px 0; overflow-wrap: anywhere; } | ||
| 54 | +.cannbot-task-list li[data-status='completed'] { color: var(--dsw-alias-label-secondary); } | ||
| 55 | +.cannbot-task-list-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 14px; } | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import type { Change } from './plugin-update.ts' | ||
| 12 | +import { en, zh } from './locales.ts' | ||
| 13 | + | ||
| 14 | +/** This notice belongs to the in-flight update, so removing the plugin must not remove it. */ | ||
| 15 | +export async function updateOnHost(name: string, version: string): Promise<{ result: Change; restore?: Change }> { | ||
| 16 | + const words = document.documentElement.lang.startsWith('en') ? en : zh | ||
| 17 | + const notice = document.createElement('div') | ||
| 18 | + notice.setAttribute('role', 'status') | ||
| 19 | + notice.setAttribute('aria-live', 'polite') | ||
| 20 | + notice.dataset.cannbotUpdate = 'progress' | ||
| 21 | + Object.assign(notice.style, { position: 'fixed', bottom: '24px', right: '24px', zIndex: '2147483647', | ||
| 22 | + maxWidth: 'min(380px, calc(100vw - 48px))', padding: '16px', borderRadius: '12px', | ||
| 23 | + background: 'var(--dsw-alias-bg-base, white)', color: 'var(--dsw-alias-label-primary, #222)', | ||
| 24 | + border: '1px solid var(--dsw-alias-border-l2, #ddd)', boxShadow: '0 8px 32px #0002', fontSize: '13px', lineHeight: '1.6' }) | ||
| 25 | + const text = document.createElement('span') | ||
| 26 | + text.textContent = `${words.updateRunning} ${version} · ${words.updateBackground}` | ||
| 27 | + notice.append(text) | ||
| 28 | + document.body.append(notice) | ||
| 29 | + try { | ||
| 30 | + const response = await fetch(new URL('api/cannbot-dsh/update', document.baseURI), { | ||
| 31 | + method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' }, | ||
| 32 | + body: JSON.stringify({ name, version }), | ||
| 33 | + // No plugin-lifetime abort: its own uninstall is expected during the transaction. | ||
| 34 | + }) | ||
| 35 | + if (!response.ok) throw new Error('Host update unavailable') | ||
| 36 | + const answer = await response.json() as { result: Change; restore?: Change } | ||
| 37 | + if (!answer?.result || typeof answer.result.application !== 'string') throw new Error('Invalid update result') | ||
| 38 | + const succeeded = (result: Change) => !result.error && ['applied', 'restart-required'].includes(result.application) | ||
| 39 | + text.textContent = succeeded(answer.result) | ||
| 40 | + ? `${answer.result.application === 'restart-required' ? words.updateRestart : words.updateDone} (${version})` | ||
| 41 | + : answer.restore ? succeeded(answer.restore) ? words.updateRestored : words.updateRepair : words.updateFailed | ||
| 42 | + return answer | ||
| 43 | + } catch (error) { | ||
| 44 | + text.textContent = words.updateConnectionLost | ||
| 45 | + throw error | ||
| 46 | + } finally { | ||
| 47 | + const close = document.createElement('button') | ||
| 48 | + close.type = 'button'; close.textContent = '×'; close.setAttribute('aria-label', words.updateDismiss) | ||
| 49 | + Object.assign(close.style, { marginLeft: '12px', border: '0', background: 'transparent', color: 'inherit', cursor: 'pointer', fontSize: '18px' }) | ||
| 50 | + close.addEventListener('click', () => notice.remove(), { once: true }) | ||
| 51 | + notice.append(close) | ||
| 52 | + } | ||
| 53 | +} | ||
| @@ -0,0 +1,87 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +/** Browser companion using the existing DSH theme, settings and UI slots. */ | ||
| 12 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 13 | +import type {} from '@deepseek-ai/dsh-client-locale/client' | ||
| 14 | +import type {} from '@deepseek-ai/dsh-client-ui-renderer/client' | ||
| 15 | +import type {} from '@deepseek-ai/dsh-client-ui-sidebar/client' | ||
| 16 | +import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' | ||
| 17 | +import type {} from '@deepseek-ai/dsh-client-ui-theme/client' | ||
| 18 | +import { en, zh, NAMESPACE, PACKAGE, type LocaleKey } from './locales.ts' | ||
| 19 | +import { SidebarMark, SidebarName, Hero } from './Brand.tsx' | ||
| 20 | +import { WorkflowCompat } from './WorkflowCompat.tsx' | ||
| 21 | +import { SessionWorkflow } from './SessionWorkflow.tsx' | ||
| 22 | +import { TaskDock } from './TaskList.tsx' | ||
| 23 | +import { cannTheme } from './theme.ts' | ||
| 24 | +import interfaceCss from './interface.css?inline' | ||
| 25 | +import './controls.css' | ||
| 26 | +import { createElement } from 'react' | ||
| 27 | +import { InterfaceToggle } from './InterfaceToggle.tsx' | ||
| 28 | +import { createPresentationController } from './presentation.ts' | ||
| 29 | +import { injectSlot } from './slot-compat.ts' | ||
| 30 | +import { createWorkflowSelection, connectWorkflowSelection, type WorkflowSelection } from './workflow-selection.ts' | ||
| 31 | +import { registerPluginUpdates } from './register-updates.ts' | ||
| 32 | +import { createContentStore, type ContentStore } from './content-store.ts' | ||
| 33 | +import { registerWorkbench } from './register-workbench.ts' | ||
| 34 | + | ||
| 35 | +declare module '@deepseek-ai/dsh-client-ui-slots' { | ||
| 36 | + interface LocaleNamespaceMap { cannbotDsh: LocaleKey } | ||
| 37 | +} | ||
| 38 | +export const inject = ['slots', 'theme', 'locale', 'sessions', 'conversation'] | ||
| 39 | + | ||
| 40 | +/** Register presentation with an explicit disposer so the original entries remain live underneath. */ | ||
| 41 | +function mountInterface(ctx: Context, selection: WorkflowSelection, content: ContentStore): () => void { | ||
| 42 | + const style = document.createElement('style') | ||
| 43 | + style.dataset.cannbotDsh = 'interface' | ||
| 44 | + style.textContent = interfaceCss | ||
| 45 | + document.head.append(style) | ||
| 46 | + const releases = [ | ||
| 47 | + ctx.theme.overrideTokens(PACKAGE, cannTheme), | ||
| 48 | + injectSlot(ctx, 'sidebar.brand.mark', () => ctx.slots.register({ name: 'sidebar.brand.mark', priority: -100 }, SidebarMark)), | ||
| 49 | + injectSlot(ctx, 'sidebar.brand.name', () => ctx.slots.register({ name: 'sidebar.brand.name', priority: -100 }, SidebarName)), | ||
| 50 | + injectSlot(ctx, 'conversation.hero.brand.mark', () => ctx.slots.register({ name: 'conversation.hero.brand.mark', priority: -100 }, Hero)), | ||
| 51 | + injectSlot(ctx, 'conversation.hero.agentPreset', () => ctx.slots.register({ name: 'conversation.hero.agentPreset', priority: -100, locale: NAMESPACE }, props => createElement(WorkflowCompat, { ...props, ctx, selection, content }))), | ||
| 52 | + registerWorkbench(ctx, selection, content), | ||
| 53 | + ] | ||
| 54 | + return () => { for (const release of releases.reverse()) release(); style.remove() } | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +export function apply(ctx: Context): void { | ||
| 58 | + const content = createContentStore() | ||
| 59 | + ctx.effect(() => content.start()) | ||
| 60 | + registerPluginUpdates(ctx, content) | ||
| 61 | + const selection = createWorkflowSelection((sessionId, reason) => { | ||
| 62 | + const blocks = ctx.conversation.blocks | ||
| 63 | + const id = sessionId as Parameters<typeof blocks.set>[0] | ||
| 64 | + const store = blocks.storeFor(id) | ||
| 65 | + // Do not replace a block owned by another DSH plugin. | ||
| 66 | + if (store.getSnapshot() !== undefined) return () => {} | ||
| 67 | + const block = { reason } | ||
| 68 | + blocks.set(id, block) | ||
| 69 | + return () => { if (store.getSnapshot() === block) blocks.set(id, undefined) } | ||
| 70 | + }, content.prepare) | ||
| 71 | + connectWorkflowSelection(ctx, selection) | ||
| 72 | + ctx.effect(() => () => selection.dispose()) | ||
| 73 | + ctx.effect(() => ctx.locale.register(NAMESPACE, { zh, en, ja: en, es: en, fr: en, de: en, ru: en, pt: en })) | ||
| 74 | + ctx.effect(() => injectSlot(ctx, 'conversation.input.dock', () => ctx.slots.register({ | ||
| 75 | + name: 'conversation.input.dock', id: 'todo', priority: -100, order: 0, locale: NAMESPACE, | ||
| 76 | + }, TaskDock))) | ||
| 77 | + ctx.effect(() => injectSlot(ctx, 'conversation.session.header.actions', () => ctx.slots.register({ | ||
| 78 | + name: 'conversation.session.header.actions', id: 'cannbot-session-workflow', order: -100, locale: NAMESPACE, | ||
| 79 | + }, props => createElement(SessionWorkflow, { ...props, selection })))) | ||
| 80 | + ctx.effect(() => { | ||
| 81 | + const controller = createPresentationController(() => mountInterface(ctx, selection, content)) | ||
| 82 | + const releaseToggle = injectSlot(ctx, 'sidebar.footer.action', () => ctx.slots.register({ | ||
| 83 | + name: 'sidebar.footer.action', id: 'cannbot-dsh-interface', order: -100, | ||
| 84 | + }, props => createElement(InterfaceToggle, { ...props, controller }))) | ||
| 85 | + return () => { releaseToggle(); controller.dispose() } | ||
| 86 | + }) | ||
| 87 | +} | ||
| @@ -0,0 +1,6 @@ | |||
| 1 | +/* Anchor the headline adjustment to this plugin's own public-slot occupant, without private DSH class names. */ | ||
| 2 | +span:has(> [data-slot="conversation.hero.brand.mark"] > [data-cannbot-dsh-hero]) { width: auto; height: auto; min-width: 0; } | ||
| 3 | +span:has(> [data-slot="conversation.hero.brand.mark"] > [data-cannbot-dsh-hero]) + span { display: none; } | ||
| 4 | +[data-cannbot-dsh-hero] { display: inline-flex; align-items: center; justify-content: center; gap: 12px; font-size: 26px; line-height: 1.3; font-weight: 650; letter-spacing: -.6px; color: var(--dsw-alias-label-primary); } | ||
| 5 | +[data-cannbot-dsh-hero] svg { flex-shrink: 0; } | ||
| 6 | +.cannbot-dsh-name { font-weight: 650; letter-spacing: -.3px; } | ||
| @@ -0,0 +1,60 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +export const PRODUCT = 'CANNBot' | ||
| 12 | +export const NAMESPACE = 'cannbotDsh' | ||
| 13 | +export const PACKAGE = '@cannbot-plugin/cannbot-dsh' | ||
| 14 | +export const COMMAND = '/ops-direct-invoke' | ||
| 15 | + | ||
| 16 | +export const zh = { | ||
| 17 | + tasksTitle: '任务列表', tasksDone: '已完成', tasksRecent: '仅显示最近完成', tasksAll: '查看全部任务', | ||
| 18 | + currentWorkflow: '工作流', | ||
| 19 | + contentCatalog: '工作流目录', contentCheck: '检查工作流更新', contentVersion: '当前版本', contentLatest: '最新版本', contentPinned: '已固定回退版本', | ||
| 20 | + contentInstall: '安装', contentUpdate: '更新', contentRollback: '回退到', contentUpToDate: '已是最新', contentUnchecked: '已安装,可使用', contentNotInstalled: '未安装', contentUnavailable: '暂不可用', | ||
| 21 | + contentTitle: '工作流管理', contentSync: '更新全部工作流', contentBusy: '正在准备…', contentDownloading: '正在从 npm 获取独立工作流包…', | ||
| 22 | + contentInitializing: '正在执行官方安装器,准备工作区依赖…', contentReady: '工作流已准备完成,可独立更新。选择工作流时自动准备当前工作区。', | ||
| 23 | + contentFailed: '准备未完成。已有工作流版本保留;请查看日志后重试。', contentFallback: '正在准备首次安装的工作流包。', contentWorkflows: '个已安装工作流', contentLogs: '查看准备日志', | ||
| 24 | + updateBackground: '后台正在更新,请勿重复安装。', updateRestored: '更新失败,已恢复旧版。', | ||
| 25 | + updateRepair: '更新和恢复未完成,请在插件页重新安装原版本。', updateConnectionLost: '连接中断,后台更新可能仍在进行。请重新打开插件页确认版本,勿重复安装。', updateDismiss: '关闭更新提示', | ||
| 26 | + updateTitle: '版本更新', updateCurrent: '当前版本', updateCheck: '检查更新', updateChecking: '正在检查…', | ||
| 27 | + updateTo: '更新到', updateRunning: '正在更新…', updateAvailable: '发现新版本,点击上方按钮更新。', | ||
| 28 | + updateLatest: '当前已是最新版本。', updateDone: '更新已完成。', updateRestart: '新版已安装,重启 DSH 后生效。', | ||
| 29 | + updateManual: '当前 DSH 要求先卸载旧版。请先下载新版包,再在插件页卸载旧版并添加下载的安装包。', | ||
| 30 | + updateIncompatible: '当前 DSH 不支持此版本,请先升级 DSH。', updateFailed: '暂时无法完成,请稍后重试。', updateDownload: '下载新版安装包', | ||
| 31 | + workflow: '选择工作流', ordinary: '普通对话', saving: '正在应用工作流…', operator: 'ops-direct-invoke', commandHint: '发送时自动应用所选工作流,只需填写需求。', | ||
| 32 | + flash: 'ops-direct-invoke-flash', registry: 'ops-registry-invoke', | ||
| 33 | + operatorDescription: '开发 Ascend C 算子,通过直调方式接入使用。', | ||
| 34 | + flashDescription: '快速生成并验证 Ascend C 算子。', | ||
| 35 | + registryDescription: '开发 Ascend C 注册算子,通过 ACLNN / GEIR 接入框架。', | ||
| 36 | + chooseWorkspace: '请先选择工作目录。', insertFailed: '工作流准备或设置未完成,请到插件详情查看准备日志后重试。', settingsRetry: '设置连接失败,重试', workflowRetry: '工作流未就绪,重试', | ||
| 37 | +} | ||
| 38 | +export const en: typeof zh = { | ||
| 39 | + tasksTitle: 'Tasks', tasksDone: 'Completed', tasksRecent: 'Show recent completions', tasksAll: 'Show all tasks', | ||
| 40 | + currentWorkflow: 'Workflow', | ||
| 41 | + contentCatalog: 'Workflow catalog', contentCheck: 'Check workflow updates', contentVersion: 'Installed', contentLatest: 'Latest', contentPinned: 'Rolled-back version pinned', | ||
| 42 | + contentInstall: 'Install', contentUpdate: 'Update', contentRollback: 'Roll back to', contentUpToDate: 'Up to date', contentUnchecked: 'Installed and ready', contentNotInstalled: 'Not installed', contentUnavailable: 'Unavailable', | ||
| 43 | + contentTitle: 'Workflow manager', contentSync: 'Update all workflows', contentBusy: 'Preparing…', contentDownloading: 'Fetching independent workflow packages from npm…', | ||
| 44 | + contentInitializing: 'Running the official installer to prepare workspace dependencies…', contentReady: 'Workflows are ready and can be updated independently. Selecting one prepares this workspace automatically.', | ||
| 45 | + contentFailed: 'Preparation did not finish. Existing workflow versions are retained; check the log and retry.', contentFallback: 'Preparing the first workflow package installation.', contentWorkflows: 'installed workflows', contentLogs: 'View preparation log', | ||
| 46 | + updateBackground: 'Updating in the background. Do not install again.', updateRestored: 'Update failed; the previous version was restored.', | ||
| 47 | + updateRepair: 'Update and recovery did not finish. Reinstall the previous version from Plugins.', updateConnectionLost: 'Connection lost. The Host may still be updating. Reopen Plugins to check the version before retrying.', updateDismiss: 'Dismiss update notice', | ||
| 48 | + updateTitle: 'Updates', updateCurrent: 'Installed version', updateCheck: 'Check for updates', updateChecking: 'Checking…', | ||
| 49 | + updateTo: 'Update to', updateRunning: 'Updating…', updateAvailable: 'A new version is available. Use the button above to update.', | ||
| 50 | + updateLatest: 'You are up to date.', updateDone: 'Update completed.', updateRestart: 'The update is installed. Restart DSH to apply it.', | ||
| 51 | + updateManual: 'This DSH version requires removing the old plugin first. Download the update, then uninstall the old plugin and add the downloaded package.', | ||
| 52 | + updateIncompatible: 'This release requires updating DSH first.', updateFailed: 'Unable to complete this operation. Please retry.', updateDownload: 'Download update', | ||
| 53 | + workflow: 'Choose workflow', ordinary: 'Ordinary conversation', saving: 'Applying workflow…', operator: 'ops-direct-invoke', commandHint: 'The selected workflow is applied in the background when you send.', | ||
| 54 | + flash: 'ops-direct-invoke-flash', registry: 'ops-registry-invoke', | ||
| 55 | + operatorDescription: 'Develop Ascend C operators and integrate them through direct invocation.', | ||
| 56 | + flashDescription: 'Quickly generate and validate Ascend C operators.', | ||
| 57 | + registryDescription: 'Develop registered Ascend C operators for framework integration through ACLNN / GEIR.', | ||
| 58 | + chooseWorkspace: 'Choose a working directory first.', insertFailed: 'Workflow preparation or saving failed. Check preparation logs in the plugin details and retry.', settingsRetry: 'Reconnect settings', workflowRetry: 'Retry workflow', | ||
| 59 | +} | ||
| 60 | +export type LocaleKey = keyof typeof zh | ||
| @@ -0,0 +1,38 @@ | |||
| 1 | +<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128.000000" height="128.000000" fill="none" customFrame="#000000"> | ||
| 2 | + <defs> | ||
| 3 | + <clipPath id="clipPath_12"> | ||
| 4 | + <rect width="128.000000" height="127.999954" x="0.000000" y="0.000000" fill="rgb(255,255,255)" /> | ||
| 5 | + </clipPath> | ||
| 6 | + <linearGradient id="paint_linear_22" x1="29.333334" x2="29.333334" y1="0" y2="73.9391937" gradientUnits="userSpaceOnUse"> | ||
| 7 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="0.300000012" /> | ||
| 8 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 9 | + </linearGradient> | ||
| 10 | + <linearGradient id="paint_linear_23" x1="38.9329453" x2="38.9329453" y1="21.3334961" y2="95.2726898" gradientUnits="userSpaceOnUse"> | ||
| 11 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="1" /> | ||
| 12 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 13 | + </linearGradient> | ||
| 14 | + <linearGradient id="paint_linear_24" x1="49.5993462" x2="49.5993462" y1="54.3999023" y2="71.0362244" gradientUnits="userSpaceOnUse"> | ||
| 15 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="1" /> | ||
| 16 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 17 | + </linearGradient> | ||
| 18 | + <linearGradient id="paint_linear_25" x1="78.4001312" x2="78.4001312" y1="54.3999023" y2="71.0362167" gradientUnits="userSpaceOnUse"> | ||
| 19 | + <stop stop-color="rgb(255,255,255)" offset="0" stop-opacity="0.300000012" /> | ||
| 20 | + <stop stop-color="rgb(255,255,255)" offset="1" stop-opacity="0" /> | ||
| 21 | + </linearGradient> | ||
| 22 | + </defs> | ||
| 23 | + <g id="cannbot-单logo"> | ||
| 24 | + <g id="容器 91334040" customFrame="url(#clipPath_12)"> | ||
| 25 | + <rect id="容器 91334040" width="128.000000" height="127.999954" x="0.000000" y="0.000000" /> | ||
| 26 | + <g id="组合 91334087"> | ||
| 27 | + <path id="矢量 6118" d="M54.656 0.0110097C54.6558 0.0110113 51.7668 3.67457e-05 51.7668 3.67457e-05C51.7668 3.67457e-05 51.7668 3.67636e-05 51.7667 3.68013e-05C51.6899 7.12161e-05 22.9847 0.0158011 22.8369 0.0110097C17.1909 -0.170211 12.3667 1.89873 8.09757 5.25809C2.0998 9.97218 0.125215 16.5951 0.0501712 23.826C-0.0509294 34.2225 0.0204758 43.0968 0.0918716 53.4933C0.0960407 54.0708 0.0996886 54.6486 0.103858 55.2261C0.106463 55.7419 0.108027 56.2585 0.109069 56.7758C0.115844 59.9923 0.122618 63.2318 0.573402 66.3923C2.21707 77.8358 11.1504 85.3226 22.7838 85.3226C23.0056 85.3226 36.8094 85.3316 37.3553 85.3333C39.2975 85.3333 40.6212 84.6508 41.4535 82.8483C42.9799 79.4889 44.6554 76.204 46.2136 72.8553C48.1777 68.6214 46.865 66.6696 42.1263 66.6696L25.9533 66.6696C25.6584 66.6696 25.3623 66.6714 25.0663 66.673L25.0658 66.673C24.0777 66.6787 23.086 66.6844 22.1005 66.6269C20.2969 66.5311 19.1441 65.3365 19.1441 63.5662L19.1441 21.6182C19.1441 20.1997 19.8591 19.24 21.1828 18.8879C22.3246 18.5893 23.5305 18.4294 24.7156 18.4294C36.3276 18.3974 30.8661 18.4081 42.478 18.4294C44.7835 18.4294 47.0891 18.5466 49.3941 18.5573C51.0273 18.5573 52.2864 17.9175 53.0019 16.3605C54.7414 12.5637 56.5665 8.82028 58.2419 5.00214C59.5015 2.12265 57.8578 -0.0210164 54.656 0.0216851L54.656 0.0110097Z" fill="rgb(199,0,11)" fill-rule="evenodd" transform="matrix(-1,0,0,-1,118.4,106.667)" /> | ||
| 28 | + <path id="矢量 6118" d="M51.7668 3.67457e-05L54.6558 0.0110092L54.656 0.0110097L54.6559 0.0193189L54.6559 0.021685L54.656 0.0216844L54.656 0.0216851C54.6897 0.0212351 54.7233 0.0210279 54.7567 0.0210619C54.7853 0.021091 54.8138 0.0212974 54.8422 0.0216798L54.8426 0.0216851C57.2018 0.0536275 58.6667 1.30361 58.6667 3.15649C58.6667 3.72147 58.5305 4.3425 58.2419 5.00214C56.5665 8.82028 54.7414 12.5637 53.0019 16.3605C52.2864 17.9175 51.0273 18.5573 49.3941 18.5573C47.0891 18.5466 44.7835 18.4294 42.478 18.4294C36.672 18.4188 35.1344 18.4107 33.5968 18.4094C32.3003 18.4083 31.0038 18.4119 27.1486 18.4227C26.4316 18.4247 25.6261 18.4269 24.7156 18.4294C23.5305 18.4294 22.3246 18.5893 21.1828 18.8879C19.8591 19.24 19.1441 20.1997 19.1441 21.6182L19.1441 63.5662C19.1441 65.3365 20.2969 66.5311 22.1005 66.6269C23.086 66.6844 24.0777 66.6787 25.0658 66.673L25.0663 66.673C25.3623 66.6714 25.6584 66.6696 25.9533 66.6696L42.1263 66.6696C45.4543 66.6696 47.0926 67.6323 47.0926 69.6722C47.0926 70.5368 46.7983 71.5949 46.2136 72.8553C44.6554 76.204 42.9799 79.4889 41.4535 82.8483C40.6212 84.6508 39.2975 85.3333 37.3553 85.3333C36.8094 85.3316 23.0056 85.3226 22.7838 85.3226C11.1504 85.3226 2.21707 77.8358 0.573402 66.3923C0.122618 63.2318 0.115844 59.9923 0.109069 56.7758C0.108027 56.2585 0.106463 55.7419 0.103858 55.2261C0.0996886 54.6486 0.0960407 54.0708 0.0918716 53.4933C0.0879818 52.9269 0.0840921 52.365 0.0802302 51.8071C0.0384871 45.7771 0 40.2174 0 34.5064C0 31.0478 0.0141155 27.5337 0.0501712 23.826C0.125215 16.5951 2.0998 9.97218 8.09757 5.25809C12.3667 1.89873 17.1909 -0.170211 22.8369 0.0110097C22.9793 0.0156241 49.6082 0.00120531 51.6439 0.000103038L51.7667 3.68013e-05L51.7668 3.67457e-05ZM51.7677 2.00004L51.7676 2.00004L51.7635 2.00004L37.3026 2.00734L22.8051 2.01102L22.7727 2.00998Q21.3984 1.96587 20.0475 2.12341L20.0474 2.12342L20.0473 2.12344Q14.4919 2.7714 9.33436 6.82983Q7.29064 8.43614 5.82839 10.4621L5.82836 10.4622Q4.54626 12.2385 3.71118 14.3376Q2.1069 18.37 2.05006 23.8467Q2.00886 28.084 2.00886 33.8733Q2.00886 41.4901 2.08018 51.7933C2.08533 52.5375 2.08921 53.0996 2.09182 53.4796L2.09781 54.3449L2.10381 55.2123L2.10906 56.7691L2.10907 56.7727C2.11354 58.8976 2.13499 60.4841 2.17341 61.5323C2.23634 63.2493 2.36299 64.7752 2.55336 66.1099C2.92521 68.6987 3.69419 71.0708 4.8603 73.2262Q5.90423 75.1556 7.31957 76.7568L7.31965 76.7569L7.32088 76.7583C7.90805 77.4224 8.54315 78.0442 9.22618 78.6235Q9.92308 79.2147 10.6703 79.7333L10.6705 79.7334L10.6708 79.7336L10.6726 79.7349Q12.7859 81.2012 15.3014 82.0877C17.6377 82.911 20.1318 83.3226 22.7838 83.3226L30.0778 83.3274L37.3569 83.3333Q38.3095 83.3333 38.8118 83.0398C39.1316 82.853 39.4069 82.5097 39.6377 82.0099C40.2064 80.7581 41.0905 78.8958 42.2898 76.4229C43.2395 74.4648 43.943 72.9943 44.4003 72.0116C44.7975 71.1552 45.0242 70.4515 45.0802 69.9004C45.0893 69.8103 45.0939 69.7287 45.0939 69.6557C45.0939 69.4828 45.0683 69.3578 45.017 69.2806C44.9365 69.1592 44.7362 69.0459 44.4163 68.9409C43.8655 68.76 43.1021 68.6696 42.1263 68.6696L25.9533 68.6696L25.091 68.6729L25.077 68.6729L25.0658 68.673C23.7112 68.6808 22.6839 68.6643 21.984 68.6235C21.0321 68.5729 20.1972 68.3297 19.4792 67.8939Q18.951 67.5733 18.5073 67.1138C18.1886 66.7837 17.9258 66.424 17.7188 66.0346C17.3357 65.3136 17.1441 64.4908 17.1441 63.5662L17.1441 21.6182Q17.1441 20.2633 17.7096 19.2128L17.7097 19.2126C17.8136 19.0197 17.9317 18.8345 18.0642 18.657C18.246 18.4133 18.4483 18.1926 18.6708 17.9948L18.6711 17.9946Q19.4873 17.2693 20.6688 16.9551C21.7413 16.6746 22.8196 16.5063 23.9036 16.4504C24.1739 16.4364 24.4446 16.4294 24.7156 16.4294L33.5923 16.4094L42.4825 16.4294C43.3025 16.4294 44.5266 16.4511 46.1547 16.4945C47.6035 16.533 48.6864 16.554 49.4033 16.5573C49.8805 16.5573 50.2577 16.4765 50.535 16.3148Q50.9267 16.0866 51.1846 15.5254C51.6208 14.5734 52.2822 13.1522 53.1688 11.2619Q55.3725 6.56395 56.4105 4.19848Q56.6759 3.59184 56.6759 3.1642C56.6759 2.95121 56.6265 2.77153 56.5277 2.62515C56.5219 2.61651 56.5159 2.60799 56.5098 2.59959Q56.0718 2.00298 54.6826 2.02151L52.656 2.04854L52.656 2.00343L51.7677 2.00004Z" fill="url(#paint_linear_22)" fill-opacity="0" fill-rule="evenodd" transform="matrix(-1,0,0,-1,118.4,106.667)" /> | ||
| 29 | + <path id="矢量 6119" d="M64.2556 21.3445C64.2554 21.3445 61.3665 21.3335 61.3665 21.3335C61.3665 21.3335 61.3664 21.3335 61.3663 21.3335C61.2895 21.3336 32.5843 21.3493 32.4365 21.3445C26.7905 21.1633 21.9663 23.2322 17.6972 26.5916C11.6994 31.3057 9.72482 37.9286 9.64978 45.1595C9.54868 55.556 9.62008 64.4303 9.69148 74.8268C9.69565 75.4043 9.6993 75.9821 9.70347 76.5596C9.70607 77.0754 9.70764 77.592 9.70868 78.1093C9.71545 81.3258 9.72223 84.5653 10.173 87.7258C11.8167 99.1693 20.75 106.656 32.3834 106.656C32.6052 106.656 46.409 106.665 46.9549 106.667C48.8972 106.667 50.2208 105.984 51.0531 104.182C52.5795 100.822 54.255 97.5375 55.8132 94.1888C57.7773 89.9549 56.4646 88.0031 51.7259 88.0031L35.5529 88.0031C35.258 88.0031 34.962 88.0049 34.666 88.0065L34.6654 88.0065C33.6774 88.0122 32.6856 88.0179 31.7002 87.9604C29.8965 87.8646 28.7437 86.67 28.7437 84.8997L28.7437 42.9517C28.7437 41.5332 29.4587 40.5735 30.7824 40.2214C31.9242 39.9228 33.1301 39.7629 34.3152 39.7629C45.9272 39.7309 40.4657 39.7416 52.0776 39.7629C54.3832 39.7629 56.6887 39.8801 58.9937 39.8908C60.6269 39.8908 61.886 39.251 62.6015 37.694C64.341 33.8972 66.1661 30.1538 67.8415 26.3356C69.1011 23.4562 67.4575 21.3125 64.2556 21.3552L64.2556 21.3445Z" fill="rgb(35,23,22)" fill-rule="evenodd" /> | ||
| 30 | + <path id="矢量 6119" d="M61.3665 21.3335L64.2554 21.3445L64.2556 21.3445L64.2556 21.3528L64.2555 21.3552L64.2556 21.3552L64.2556 21.3552C64.2893 21.3547 64.3229 21.3545 64.3563 21.3546C64.3849 21.3546 64.4134 21.3548 64.4418 21.3552L64.4422 21.3552C66.8015 21.3871 68.2663 22.6371 68.2663 24.49C68.2663 25.055 68.1301 25.676 67.8415 26.3356C66.1661 30.1538 64.341 33.8972 62.6015 37.694C61.886 39.251 60.6269 39.8908 58.9937 39.8908C56.6887 39.8801 54.3832 39.7629 52.0776 39.7629C46.2716 39.7522 44.734 39.7442 43.1964 39.7429C41.8999 39.7418 40.6035 39.7454 36.7482 39.7562C36.0312 39.7582 35.2257 39.7604 34.3152 39.7629C33.1301 39.7629 31.9242 39.9228 30.7824 40.2214C29.4587 40.5735 28.7437 41.5332 28.7437 42.9517L28.7437 84.8997C28.7437 86.67 29.8965 87.8646 31.7002 87.9604C32.6856 88.0179 33.6774 88.0122 34.6654 88.0065L34.666 88.0065C34.962 88.0049 35.258 88.0031 35.5529 88.0031L51.7259 88.0031C55.054 88.0031 56.6922 88.9658 56.6922 91.0057C56.6922 91.8703 56.3979 92.9284 55.8132 94.1888C54.255 97.5375 52.5795 100.822 51.0531 104.182C50.2208 105.984 48.8972 106.667 46.9549 106.667C46.409 106.665 32.6052 106.656 32.3834 106.656C20.75 106.656 11.8167 99.1693 10.173 87.7258C9.72223 84.5653 9.71545 81.3258 9.70868 78.1093C9.70764 77.592 9.70607 77.0754 9.70347 76.5596C9.6993 75.9821 9.69565 75.4043 9.69148 74.8268C9.68759 74.2604 9.6837 73.6985 9.67984 73.1406C9.6381 67.1106 9.59961 61.5509 9.59961 55.8399C9.59961 52.3813 9.61372 48.8672 9.64978 45.1595C9.72482 37.9286 11.6994 31.3057 17.6972 26.5916C21.9663 23.2322 26.7905 21.1633 32.4365 21.3445C32.5789 21.3491 59.2078 21.3347 61.2435 21.3336L61.3663 21.3335L61.3665 21.3335ZM61.3673 23.3335L61.3672 23.3335L61.3631 23.3335L46.9022 23.3408L32.4047 23.3445L32.3724 23.3435Q30.9978 23.2994 29.6469 23.4569Q24.0915 24.1049 18.934 28.1633Q16.8903 29.7696 15.428 31.7956L15.428 31.7956L15.4279 31.7957Q14.1459 33.5721 13.3108 35.6711Q11.7065 39.7035 11.6497 45.1802Q11.6085 49.4175 11.6085 55.2068Q11.6085 62.8236 11.6798 73.1268C11.685 73.8733 11.6888 74.4354 11.6914 74.8131L11.6974 75.6784L11.7034 76.5458L11.7087 78.1026L11.7087 78.1062Q11.7154 81.2935 11.773 82.8658Q11.8674 85.4413 12.153 87.4434C12.5248 90.0322 13.2938 92.4043 14.4599 94.5596Q15.5038 96.4891 16.9192 98.0903L16.9193 98.0904L16.9205 98.0918C17.5077 98.7559 18.1428 99.3777 18.8258 99.957Q19.5227 100.548 20.2699 101.067L20.2701 101.067L20.2704 101.067L20.2722 101.068Q22.3855 102.535 24.9011 103.421C27.2373 104.244 29.7314 104.656 32.3834 104.656L39.6774 104.661L46.9565 104.667Q47.9091 104.667 48.4114 104.373C48.7313 104.186 49.0066 103.843 49.2373 103.343C49.806 102.092 50.6901 100.229 51.8894 97.7564C52.8391 95.7983 53.5426 94.3278 53.9999 93.3451C54.3971 92.4887 54.6238 91.785 54.6798 91.2339C54.6889 91.1438 54.6935 91.0622 54.6935 90.9892C54.6935 90.8163 54.6679 90.6913 54.6166 90.6141C54.5361 90.4927 54.3358 90.3794 54.016 90.2744C53.4651 90.0935 52.7017 90.0031 51.7259 90.0031L35.5529 90.0031L34.6906 90.0064L34.6767 90.0064L34.6654 90.0065C33.3108 90.0143 32.2835 89.9978 31.5836 89.957C30.6317 89.9064 29.7968 89.6632 29.0788 89.2274C28.7267 89.0137 28.4027 88.7536 28.1069 88.4473C27.7882 88.1172 27.5254 87.7575 27.3185 87.3681C26.9353 86.6471 26.7437 85.8243 26.7437 84.8997L26.7437 42.9517Q26.7437 41.5968 27.3092 40.5463L27.3093 40.5461C27.4132 40.3532 27.5313 40.168 27.6638 39.9905C27.8457 39.7468 28.0479 39.5261 28.2705 39.3283Q29.0867 38.6029 30.2684 38.2886C31.3409 38.0081 32.4192 37.8398 33.5032 37.7839C33.7735 37.7699 34.0442 37.7629 34.3152 37.7629L43.1919 37.7429L52.0822 37.7629C52.9021 37.7629 54.1262 37.7846 55.7544 37.8279C57.2031 37.8665 58.286 37.8875 59.0029 37.8908C59.4801 37.8908 59.8573 37.81 60.1346 37.6483Q60.5263 37.4201 60.7842 36.8589C61.2204 35.9069 61.8818 34.4857 62.7685 32.5954Q64.9721 27.8974 66.0101 25.532Q66.2755 24.9253 66.2755 24.4977C66.2755 24.2847 66.2261 24.105 66.1273 23.9586C66.1215 23.95 66.1155 23.9415 66.1094 23.9331Q65.6714 23.3365 64.2823 23.355L62.2556 23.382L62.2556 23.3369L61.3673 23.3335Z" fill="url(#paint_linear_23)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 31 | + <path id="矢量 6109" d="M39.5901 73.5999L51.8402 73.5999C54.3694 73.5999 56.6613 72.1104 57.6886 69.7992L62.5328 58.8995C63.4733 56.7834 61.9244 54.3999 59.6086 54.3999L47.3585 54.3999C44.8293 54.3999 42.5373 55.8894 41.5101 58.2006L36.6659 69.1003C35.7254 71.2164 37.2743 73.5999 39.5901 73.5999Z" fill="rgb(35,23,22)" fill-rule="evenodd" /> | ||
| 32 | + <path id="矢量 6109" d="M36.3864 70.401C36.3864 69.9712 36.4748 69.5302 36.6659 69.1003L41.5101 58.2006C42.5373 55.8894 44.8293 54.3999 47.3585 54.3999L59.6086 54.3999C61.4538 54.3999 62.8122 55.9133 62.8122 57.5988C62.8122 58.0286 62.7239 58.4696 62.5328 58.8995L57.6886 69.7992C56.6613 72.1104 54.3694 73.5999 51.8402 73.5999L39.5901 73.5999C37.7448 73.5999 36.3864 72.0865 36.3864 70.401ZM51.8402 71.5999Q52.4922 71.5999 53.0916 71.4222C53.4912 71.3038 53.8733 71.1261 54.2378 70.8893C54.6023 70.6524 54.9198 70.3754 55.1903 70.0583C55.4608 69.7413 55.6844 69.3841 55.8609 68.9869L60.7052 58.0873Q60.8182 57.8331 60.8182 57.5879C60.8182 57.56 60.8171 57.5321 60.8149 57.5044C60.7998 57.3142 60.7331 57.128 60.6148 56.946C60.4965 56.764 60.3535 56.6274 60.1858 56.5364C60.0181 56.4454 59.8257 56.3999 59.6086 56.3999L47.3585 56.3999C46.9238 56.3999 46.5067 56.4591 46.1071 56.5776L46.107 56.5776Q45.5076 56.7552 44.9609 57.1105C44.5964 57.3474 44.2789 57.6244 44.0084 57.9414C43.7379 58.2585 43.5143 58.6157 43.3378 59.0129L38.4935 69.9125Q38.3805 70.1667 38.3805 70.4119Q38.3805 70.4538 38.3838 70.4954Q38.4064 70.7807 38.5839 71.0538C38.7022 71.2358 38.8452 71.3724 39.0129 71.4634L39.0129 71.4634Q39.2644 71.5999 39.5901 71.5999L51.8402 71.5999Z" fill="url(#paint_linear_24)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 33 | + <path id="矢量 6115" d="M68.3908 73.5999L80.6409 73.5999C83.1702 73.5999 85.4621 72.1104 86.4893 69.7992L91.3336 58.8995C92.2741 56.7834 90.7251 54.3999 88.4094 54.3999L76.1593 54.3999C73.6301 54.3999 71.3381 55.8894 70.3109 58.2006L65.4666 69.1003C64.5261 71.2164 66.0751 73.5999 68.3908 73.5999Z" fill="rgb(199,0,11)" fill-rule="evenodd" /> | ||
| 34 | + <path id="矢量 6115" d="M80.6409 73.5999L68.3908 73.5999C66.5456 73.5999 65.1872 72.0865 65.1872 70.401C65.1872 69.9712 65.2756 69.5302 65.4666 69.1003L70.3109 58.2006C71.3381 55.8894 73.6301 54.3999 76.1593 54.3999L88.4094 54.3999C90.2546 54.3999 91.613 55.9133 91.613 57.5988C91.613 58.0286 91.5247 58.4696 91.3336 58.8995L86.4893 69.7992C85.4621 72.1104 83.1702 73.5999 80.6409 73.5999ZM80.6409 71.5999C81.0757 71.5999 81.4928 71.5407 81.8924 71.4222C82.292 71.3038 82.6741 71.1261 83.0386 70.8893C83.4031 70.6524 83.7206 70.3754 83.9911 70.0583C84.2616 69.7413 84.4852 69.3841 84.6617 68.9869L89.506 58.0873C89.5813 57.9178 89.619 57.7514 89.619 57.5879C89.619 57.56 89.6179 57.5321 89.6157 57.5044C89.6006 57.3142 89.5339 57.128 89.4156 56.946C89.2973 56.764 89.1543 56.6274 88.9866 56.5364L88.9865 56.5364Q88.735 56.3999 88.4094 56.3999L76.1593 56.3999Q75.5073 56.3999 74.9079 56.5776Q74.3084 56.7552 73.7617 57.1105Q73.2149 57.4659 72.8092 57.9415C72.5386 58.2585 72.3151 58.6157 72.1385 59.0129L67.2943 69.9125C67.219 70.082 67.1813 70.2484 67.1813 70.4119C67.1813 70.4398 67.1824 70.4677 67.1846 70.4954Q67.2072 70.7807 67.3846 71.0538C67.5029 71.2358 67.6459 71.3723 67.8136 71.4634C67.9813 71.5544 68.1737 71.5999 68.3908 71.5999L80.6409 71.5999Z" fill="url(#paint_linear_25)" fill-opacity="0" fill-rule="evenodd" /> | ||
| 35 | + </g> | ||
| 36 | + </g> | ||
| 37 | + </g> | ||
| 38 | +</svg> | ||
| @@ -0,0 +1,106 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +export const UPDATE_PACKAGES = ['cannbot-dsh', '@cannbot-plugin/cannbot-dsh'] as const | ||
| 12 | +export interface InstalledBundle { name: string; version?: string; installed: boolean } | ||
| 13 | +export interface Change { application: string; error?: { code: string }; version?: string } | ||
| 14 | +export interface UpdateBridge { | ||
| 15 | + list(): Promise<InstalledBundle[]> | ||
| 16 | + install(spec: string): Promise<Change> | ||
| 17 | + update?(name: string, version: string): Promise<{ result: Change; restore?: Change }> | ||
| 18 | +} | ||
| 19 | +export interface Release { name: string; version: string; tarball: string } | ||
| 20 | +export type UpdatePhase = 'idle' | 'checking' | 'latest' | 'available' | 'updating' | 'done' | 'restart' | 'manual' | 'incompatible' | 'error' | ||
| 21 | +export interface UpdateSnapshot { phase: UpdatePhase; current?: string; release?: Release; packageName?: string } | ||
| 22 | + | ||
| 23 | +/** Only stable npm releases of our two installation entries may be selected. */ | ||
| 24 | +export function newerVersion(candidate: string, current: string): boolean { | ||
| 25 | + const next = /^(\d+)\.(\d+)\.(\d+)$/.exec(candidate) | ||
| 26 | + const old = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(current) | ||
| 27 | + if (!next || !old) return false | ||
| 28 | + for (let index = 1; index < 4; index++) { | ||
| 29 | + const difference = Number(next[index]) - Number(old[index]) | ||
| 30 | + if (difference) return difference > 0 | ||
| 31 | + } | ||
| 32 | + return /^\d+\.\d+\.\d+-/.test(current) | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +export async function latestRelease(name: string, signal: AbortSignal): Promise<Release> { | ||
| 36 | + if (!UPDATE_PACKAGES.includes(name as typeof UPDATE_PACKAGES[number])) throw new Error('Unsupported update target') | ||
| 37 | + const answers = await Promise.allSettled(['https://registry.npmjs.org/', 'https://registry.npmmirror.com/'].map(async registry => { | ||
| 38 | + const response = await fetch(`${registry}${encodeURIComponent(name)}/latest`, { | ||
| 39 | + signal: AbortSignal.any([signal, AbortSignal.timeout(15000)]), cache: 'no-store', | ||
| 40 | + }) | ||
| 41 | + if (!response.ok) throw new Error('Registry unavailable') | ||
| 42 | + const manifest = await response.json() as { name?: string; version?: string; dist?: { tarball?: string }; dsh?: { bundle?: unknown } } | ||
| 43 | + if (manifest.name !== name || !manifest.version || !/^\d+\.\d+\.\d+$/.test(manifest.version) || !manifest.dsh?.bundle || !manifest.dist?.tarball) throw new Error('Invalid release') | ||
| 44 | + const url = new URL(manifest.dist.tarball) | ||
| 45 | + if (url.protocol !== 'https:' || !['registry.npmjs.org', 'registry.npmmirror.com'].includes(url.hostname)) throw new Error('Invalid download origin') | ||
| 46 | + return { name, version: manifest.version, tarball: url.href } | ||
| 47 | + })) | ||
| 48 | + signal.throwIfAborted() | ||
| 49 | + const releases = answers.flatMap(answer => answer.status === 'fulfilled' ? [answer.value] : []) | ||
| 50 | + const latest = releases.reduce<Release | undefined>((best, release) => !best || newerVersion(release.version, best.version) ? release : best, undefined) | ||
| 51 | + if (!latest) throw new Error('No release available') | ||
| 52 | + return latest | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +export function createPluginUpdater(bridge: UpdateBridge, requestedName: string, lookup = latestRelease) { | ||
| 56 | + let state: UpdateSnapshot = { phase: 'idle' } | ||
| 57 | + let disposed = false | ||
| 58 | + let checking: AbortController | undefined | ||
| 59 | + const listeners = new Set<() => void>() | ||
| 60 | + const publish = (next: UpdateSnapshot) => { if (disposed) return; state = next; for (const listener of listeners) listener() } | ||
| 61 | + const failed = (result: Change) => !['applied', 'restart-required'].includes(result.application) || !!result.error | ||
| 62 | + return { | ||
| 63 | + getSnapshot: () => state, | ||
| 64 | + subscribe(listener: () => void) { listeners.add(listener); return () => { listeners.delete(listener) } }, | ||
| 65 | + async check() { | ||
| 66 | + if (disposed || state.phase === 'checking' || state.phase === 'updating') return | ||
| 67 | + checking?.abort() | ||
| 68 | + const abort = new AbortController() | ||
| 69 | + checking = abort | ||
| 70 | + publish({ ...state, phase: 'checking' }) | ||
| 71 | + try { | ||
| 72 | + const bundles = (await bridge.list()).filter(bundle => bundle.installed && UPDATE_PACKAGES.includes(bundle.name as typeof UPDATE_PACKAGES[number])) | ||
| 73 | + // Update the actual direct dependency, preserving short/long installation form. | ||
| 74 | + const bundle = bundles.find(bundle => bundle.name === requestedName) ?? bundles[0] | ||
| 75 | + if (!bundle?.version) throw new Error('Installed entry unavailable') | ||
| 76 | + publish({ ...state, current: bundle.version, packageName: bundle.name }) | ||
| 77 | + const release = await lookup(bundle.name, abort.signal) | ||
| 78 | + if (checking !== abort || disposed) return | ||
| 79 | + publish({ phase: newerVersion(release.version, bundle.version) ? 'available' : 'latest', current: bundle.version, release, packageName: bundle.name }) | ||
| 80 | + } catch { | ||
| 81 | + if (!abort.signal.aborted) publish({ ...state, phase: 'error' }) | ||
| 82 | + } | ||
| 83 | + }, | ||
| 84 | + async update() { | ||
| 85 | + if (disposed || state.phase !== 'available' || !state.release || !state.packageName) return | ||
| 86 | + const target = state.release, name = state.packageName | ||
| 87 | + publish({ ...state, phase: 'updating' }) | ||
| 88 | + try { | ||
| 89 | + // The Host owns the complete transaction, including self-removal and recovery. | ||
| 90 | + // Frontend disposal must never cancel an update that already started. | ||
| 91 | + const answer = bridge.update | ||
| 92 | + ? await bridge.update(name, target.version) | ||
| 93 | + : { result: await bridge.install(`${name}@${target.version}`) } | ||
| 94 | + const result = answer.result | ||
| 95 | + if (failed(result)) { | ||
| 96 | + const code = result.error?.code | ||
| 97 | + publish({ ...state, phase: code === 'already-installed' || code === 'stop-profile' ? 'manual' : code === 'incompatible-version' ? 'incompatible' : 'error' }) | ||
| 98 | + } else { | ||
| 99 | + publish({ ...state, phase: result.application === 'restart-required' ? 'restart' : 'done', current: target.version }) | ||
| 100 | + } | ||
| 101 | + } catch { publish({ ...state, phase: 'error' }) } | ||
| 102 | + }, | ||
| 103 | + dispose() { disposed = true; checking?.abort(); listeners.clear() }, | ||
| 104 | + } | ||
| 105 | +} | ||
| 106 | +export type PluginUpdater = ReturnType<typeof createPluginUpdater> | ||
| @@ -0,0 +1,35 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +/** Per-activation UI preference: enabling the plugin always starts with its interface on. */ | ||
| 12 | +export interface PresentationController { | ||
| 13 | + getSnapshot(): boolean | ||
| 14 | + subscribe(listener: () => void): () => void | ||
| 15 | + setEnabled(enabled: boolean): void | ||
| 16 | + dispose(): void | ||
| 17 | +} | ||
| 18 | +export function createPresentationController(mount: () => () => void): PresentationController { | ||
| 19 | + let enabled = true | ||
| 20 | + let stopped = false | ||
| 21 | + let unmount: (() => void) | undefined = mount() | ||
| 22 | + const listeners = new Set<() => void>() | ||
| 23 | + return { | ||
| 24 | + getSnapshot: () => enabled, | ||
| 25 | + subscribe(listener) { listeners.add(listener); return () => { listeners.delete(listener) } }, | ||
| 26 | + setEnabled(next) { | ||
| 27 | + if (stopped || next === enabled) return | ||
| 28 | + if (next) unmount = mount() | ||
| 29 | + else { unmount?.(); unmount = undefined } | ||
| 30 | + enabled = next | ||
| 31 | + for (const listener of listeners) listener() | ||
| 32 | + }, | ||
| 33 | + dispose() { if (stopped) return; stopped = true; unmount?.(); unmount = undefined; listeners.clear() }, | ||
| 34 | + } | ||
| 35 | +} | ||
| @@ -0,0 +1,45 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { createElement, Fragment } from 'react' | ||
| 12 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 13 | +import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client' | ||
| 14 | +import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 15 | +import { createPluginUpdater, UPDATE_PACKAGES } from './plugin-update.ts' | ||
| 16 | +import { PluginUpdateCard } from './PluginUpdateCard.tsx' | ||
| 17 | +import { NAMESPACE } from './locales.ts' | ||
| 18 | +import { injectSlot } from './slot-compat.ts' | ||
| 19 | +import { updateOnHost } from './host-update.ts' | ||
| 20 | +import { ContentCard } from './ContentCard.tsx' | ||
| 21 | +import type { ContentStore } from './content-store.ts' | ||
| 22 | + | ||
| 23 | +/** Optional integration: old DSH versions without a Plugins page keep loading. */ | ||
| 24 | +export function registerPluginUpdates(ctx: Context, content?: ContentStore) { | ||
| 25 | + ctx.inject(['remote', 'remote.pluginManager'], scoped => { | ||
| 26 | + const manager = scoped.remote.pluginManager | ||
| 27 | + for (const name of UPDATE_PACKAGES) { | ||
| 28 | + const updater = createPluginUpdater({ | ||
| 29 | + list: async () => unwrap(await manager.listBundles()), | ||
| 30 | + install: async spec => unwrap(await manager.installBundle(spec, { saveExact: true })), | ||
| 31 | + update: updateOnHost, | ||
| 32 | + }, name) | ||
| 33 | + scoped.effect(() => () => updater.dispose()) | ||
| 34 | + scoped.effect(() => injectSlot(scoped, 'plugins.bundle.config', () => scoped.slots.register({ | ||
| 35 | + name: 'plugins.bundle.config', key: name, locale: NAMESPACE, | ||
| 36 | + }, props => createElement(Fragment, null, | ||
| 37 | + createElement(PluginUpdateCard, { ...(props as PropsLocale<'cannbotDsh'>), updater }), | ||
| 38 | + content && createElement(ContentCard, { ...(props as PropsLocale<'cannbotDsh'>), content }))))) | ||
| 39 | + } | ||
| 40 | + }) | ||
| 41 | +} | ||
| 42 | +function unwrap<T>(result: { ok: true; value: T } | { ok: false; error: unknown }): T { | ||
| 43 | + if (!result.ok) throw result.error | ||
| 44 | + return result.value | ||
| 45 | +} | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import { createElement } from 'react' | ||
| 12 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 13 | +import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client' | ||
| 14 | +import type {} from '@deepseek-ai/dsh-client-ui-layout/client' | ||
| 15 | +import type {} from '@deepseek-ai/dsh-client-ui-workspace/client' | ||
| 16 | +import type { WorkflowSelection } from './workflow-selection.ts' | ||
| 17 | +import type { ContentStore } from './content-store.ts' | ||
| 18 | +import { Workbench, HOME_PANEL, LIBRARY_PANEL } from './Workbench.tsx' | ||
| 19 | +import { WorkbenchIcon } from './WorkbenchIcon.tsx' | ||
| 20 | +import { createWorkbenchState } from './workbench-state.ts' | ||
| 21 | +import { injectSlot } from './slot-compat.ts' | ||
| 22 | +import './workbench.css' | ||
| 23 | + | ||
| 24 | +/** Optional public-slot integration: older DSH keeps its existing branded conversation. */ | ||
| 25 | +export function registerWorkbench(ctx: Context, selection: WorkflowSelection, content: ContentStore): () => void { | ||
| 26 | + const fiber = ctx.inject(['layout', 'uiWorkspace', 'workspaces'], scoped => { | ||
| 27 | + if (typeof scoped.uiWorkspace.openSession !== 'function' || typeof (scoped.sessions as unknown as ISessions).retain !== 'function' | ||
| 28 | + || typeof scoped.conversation.input.requestDraftInitialization !== 'function') return | ||
| 29 | + scoped.effect(() => { | ||
| 30 | + const store = createWorkbenchState() | ||
| 31 | + const releases: (() => void)[] = [] | ||
| 32 | + for (const [id, library] of [[HOME_PANEL, false], [LIBRARY_PANEL, true]] as const) { | ||
| 33 | + releases.push(injectSlot(scoped, 'main', () => scoped.slots.register({ name: 'main', key: id }, () => createElement(Workbench, { ctx: scoped, selection, content, store, library })))) | ||
| 34 | + if (!library) releases.push(injectSlot(scoped, 'sidebar.panellist', () => scoped.slots.register({ name: 'sidebar.panellist', id, order: -100, label: 'CANNBot工作台' }, ({ size }) => createElement(WorkbenchIcon, { name: 'grid', size })))) | ||
| 35 | + } | ||
| 36 | + return () => { | ||
| 37 | + store.dispose() | ||
| 38 | + if ([HOME_PANEL, LIBRARY_PANEL].includes(scoped.layout.panelInfo.getSnapshot().activePanelId!)) scoped.layout.selectPanel(null) | ||
| 39 | + for (const release of releases.reverse()) release() | ||
| 40 | + } | ||
| 41 | + }) | ||
| 42 | + }) | ||
| 43 | + return () => { if (typeof fiber?.dispose === 'function') void fiber.dispose() } | ||
| 44 | +} | ||
| @@ -0,0 +1,17 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 12 | +import type { SlotMap } from '@deepseek-ai/dsh-client-ui-slots' | ||
| 13 | + | ||
| 14 | +/** Older DSH declares the injected parent modules before this plugin and uses direct register(). */ | ||
| 15 | +export function injectSlot(ctx: Context, name: keyof SlotMap & string, register: () => () => void): () => void { | ||
| 16 | + return typeof ctx.slots.inject === 'function' ? ctx.slots.inject(name, register) : register() | ||
| 17 | +} | ||
| @@ -0,0 +1,54 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import type { ThemeTokenOverrides } from '@deepseek-ai/dsh-client-ui-theme/client' | ||
| 12 | + | ||
| 13 | +/** Portal design-v2 palette, applied through the documented theme override layer. */ | ||
| 14 | +export const cannTheme: ThemeTokenOverrides = Object.fromEntries(Object.entries({ | ||
| 15 | + '--dsw-alias-bg-base': ['#ffffff', '#101114'], | ||
| 16 | + '--dsw-alias-bg-layer-1': ['#ffffff', '#17191e'], | ||
| 17 | + '--dsw-alias-bg-layer-2': ['#ffffff', '#1d2026'], | ||
| 18 | + '--dsw-alias-bg-layer-3': ['#f6f8fa', '#252830'], | ||
| 19 | + '--dsw-specific-sidebar-fill': ['#f6f8fa', '#14161b'], | ||
| 20 | + '--dsw-specific-input-major': ['#ffffff', '#1d2026'], | ||
| 21 | + '--dsw-specific-sidebar-nav-item-active': ['#fdeef0', '#392029'], | ||
| 22 | + '--dsw-specific-sidebar-nav-item-active-accent': ['#fdeef0', '#392029'], | ||
| 23 | + '--dsw-alias-label-primary': ['#17181d', '#f3f4f6'], | ||
| 24 | + '--dsw-alias-label-primary-foreground': ['#ffffff', '#ffffff'], | ||
| 25 | + '--dsw-alias-label-primary-inverted': ['#ffffff', '#ffffff'], | ||
| 26 | + '--dsw-alias-label-primary-dimmed': ['#30343e', '#dde1e8'], | ||
| 27 | + '--dsw-alias-label-primary-bluish': ['#7f0f26', '#ff9aab'], | ||
| 28 | + '--dsw-alias-label-secondary': ['#59637a', '#b0b8c7'], | ||
| 29 | + '--dsw-alias-label-tertiary': ['#727d91', '#929db0'], | ||
| 30 | + '--dsw-alias-brand-primary': ['#da203e', '#ef4560'], | ||
| 31 | + '--dsw-alias-brand-text': ['#17181d', '#f3f4f6'], | ||
| 32 | + '--dsw-alias-button-primary-hover': ['#b11430', '#ff647d'], | ||
| 33 | + '--dsw-alias-button-info-fill': ['#da203e', '#da203e'], | ||
| 34 | + '--dsw-alias-button-info-hover': ['#b11430', '#b11430'], | ||
| 35 | + '--dsw-alias-state-business-primary': ['#da203e', '#ff8297'], | ||
| 36 | + '--dsw-alias-state-business-tertiary': ['#fdeef0', '#392029'], | ||
| 37 | + '--dsw-alias-link': ['#b11430', '#ff9aab'], | ||
| 38 | + '--dsw-focus-ring-color': ['#da203e', '#ff8297'], | ||
| 39 | + '--dsw-alias-border-l1': ['#f0f1f5', '#252830'], | ||
| 40 | + '--dsw-alias-border-l2': ['#e6e9ef', '#323641'], | ||
| 41 | + '--dsw-alias-border-l3': ['#dce0e8', '#414754'], | ||
| 42 | + '--dsw-alias-border-l4': ['#ced4df', '#505867'], | ||
| 43 | + '--dsw-alias-interactive-bg-hover': ['#eef0f4', '#252830'], | ||
| 44 | + '--dsw-alias-interactive-bg-active': ['#fdeef0', '#392029'], | ||
| 45 | + '--dsw-specific-bubble': ['#fff3f5', '#302027'], | ||
| 46 | + '--dsw-specific-bubble-highlight': ['#fbd6dd', '#59303d'], | ||
| 47 | + '--dsw-radius-panel': ['18px', '18px'], | ||
| 48 | + '--dsw-radius-xl': ['14px', '14px'], | ||
| 49 | + '--dsw-radius-lg': ['12px', '12px'], | ||
| 50 | + '--dsw-radius-md': ['10px', '10px'], | ||
| 51 | + '--cann-grid': ['#e6e9ef', '#323641'], | ||
| 52 | + '--cann-night': ['#0e0f12', '#0e0f12'], | ||
| 53 | + '--cann-night-label': ['#dde1e8', '#dde1e8'], | ||
| 54 | +}).map(([name, values]) => [name, { light: values[0]!, dark: values[1]! }])) | ||
| @@ -0,0 +1,27 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +/** Presentation copy only. Execution and initialization remain owned by the workflow packages. */ | ||
| 12 | +export const categories = ['全部', 'Ascend C'] as const | ||
| 13 | +export type Category = typeof categories[number] | ||
| 14 | +export interface WorkflowGuide { category: Category; icon: string; scenes: string[]; inputs: string[]; outputs: string[]; example: string } | ||
| 15 | +export const guides: Record<string, WorkflowGuide> = { | ||
| 16 | + 'ops-direct-invoke-flash': { category: 'Ascend C', icon: 'flash', scenes: ['快速实现与验证算子原型', '从明确的功能需求开始开发'], inputs: ['必需:算子功能及输入输出规格', '可选:参考代码、测试数据及目标硬件'], outputs: ['Ascend C 算子代码', '在可用环境中执行的编译与精度验证结果'], example: '帮我快速生成并验证一个 Ascend C 的 MatMul 算子,输入使用 float16,请先确认形状约束。' }, | ||
| 17 | + 'ops-direct-invoke': { category: 'Ascend C', icon: 'code', scenes: ['开发新的 Ascend C 算子', '通过直调方式集成算子'], inputs: ['必需:算子功能、输入输出及数据类型', '可选:参考实现、目标硬件及性能要求'], outputs: ['算子实现与直调示例', '按实际环境生成的验证结果及运行说明'], example: '请开发一个 Ascend C 的 Add 算子,输入为两个 float16 张量,并通过直调方式验证结果。' }, | ||
| 18 | + 'ops-registry-invoke': { category: 'Ascend C', icon: 'document', scenes: ['开发需要注册到框架的算子', '通过 ACLNN / GEIR 接入算子'], inputs: ['必需:算子定义、输入输出及接入方式', '可选:现有工程、参考实现及目标环境'], outputs: ['注册算子相关代码及接入示例', '按实际环境完成的验证与使用说明'], example: '开发一个 Ascend C 的自定义算子,并通过 ACLNN 接入。请先检查当前工程及输入输出定义。' }, | ||
| 19 | +} | ||
| 20 | +export const guideFor = (id: string): WorkflowGuide => guides[id] ?? { category: 'Ascend C', icon: 'nodes', scenes: ['使用此工作流完成开发需求'], inputs: ['请描述目标,并提供相关工程或代码'], outputs: ['以工作流实际执行结果为准'], example: '请根据当前工程和我的需求开展工作,开始前先检查必要的输入。' } | ||
| 21 | +export const cardOrder = Object.keys(guides) | ||
| 22 | +const inputHints: Record<string, string> = { | ||
| 23 | + 'ops-direct-invoke': '可补充算子功能、输入形状、数据类型和目标硬件。', | ||
| 24 | + 'ops-direct-invoke-flash': '可补充输入形状、数据类型和目标硬件。', | ||
| 25 | + 'ops-registry-invoke': '可补充输入输出规格,以及 ACLNN / GEIR 接入要求。', | ||
| 26 | +} | ||
| 27 | +export const inputHintFor = (id: string) => inputHints[id] ?? '可补充当前工程、相关代码和预期结果。' | ||
| @@ -0,0 +1,81 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +import type { Context } from '@deepseek-ai/cordis' | ||
| 12 | +import type { ConversationController } from '@deepseek-ai/dsh-client-ui-conversation/client' | ||
| 13 | +import type { WorkspaceId } from '@deepseek-ai/dsh-api-workspace-controller/client' | ||
| 14 | +import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client' | ||
| 15 | +import type {} from '@deepseek-ai/dsh-client-ui-workspace/client' | ||
| 16 | +import type { WorkflowSelection } from './workflow-selection.ts' | ||
| 17 | +import type { PreparationStage } from './workbench-state.ts' | ||
| 18 | + | ||
| 19 | +/** Transfer to the resident DSH composer; its own submit policy remains authoritative. */ | ||
| 20 | +export async function launchWorkbench(ctx: Context, selection: WorkflowSelection, request: { workspaceId: string; workflow: string; prompt: string; files: readonly File[] }, signal: AbortSignal, onStage: (stage: PreparationStage) => void = () => {}) { | ||
| 21 | + if (!selection.getSnapshot().ready || selection.getSnapshot().pending) throw new Error('工作流设置尚未就绪,请稍后重试。') | ||
| 22 | + signal.throwIfAborted() | ||
| 23 | + const startingPanel = ctx.layout.panelInfo.getSnapshot().activePanelId | ||
| 24 | + // The development workspace also includes legacy Context declarations. | ||
| 25 | + const sessions = ctx.sessions as unknown as ISessions | ||
| 26 | + onStage('workspace') | ||
| 27 | + const id = await sessions.create({ workspaceId: request.workspaceId as WorkspaceId }) | ||
| 28 | + signal.throwIfAborted() | ||
| 29 | + const reference = sessions.retain(id, { source: 'controllerOperation', signal }) | ||
| 30 | + const conversation = ctx.conversation as ConversationController | ||
| 31 | + let attachments: ReturnType<ConversationController['createDrafts']> = [] | ||
| 32 | + let transferred = false | ||
| 33 | + try { | ||
| 34 | + const binding = await reference.ready | ||
| 35 | + signal.throwIfAborted() | ||
| 36 | + if (request.workflow) onStage('dependencies') | ||
| 37 | + await selection.choose(id, request.workflow) | ||
| 38 | + signal.throwIfAborted() | ||
| 39 | + const saved = selection.getSnapshot() | ||
| 40 | + if (!saved.ready || saved.pending || saved.error || (saved.values[id] ?? '') !== request.workflow) throw new Error(saved.errorMessage || '工作流准备未完成,请在插件设置中查看日志后重试。') | ||
| 41 | + if (conversation.blocks.storeFor(id).getSnapshot()) throw new Error('当前对话暂时不能发送,请稍后重试。') | ||
| 42 | + const input = conversation.input.for(binding.ctx) | ||
| 43 | + const initialized = conversation.input.requestDraftInitialization(binding, { prompt: request.prompt, whenDraftExists: 'keep' }) | ||
| 44 | + if (initialized !== 'applied') throw new Error('新对话已存在草稿,已保留内容,请重试。') | ||
| 45 | + if (request.files.length) { | ||
| 46 | + onStage('upload') | ||
| 47 | + if (typeof conversation.createDrafts !== 'function') throw new Error('此 DSH 版本请进入对话后添加文件。') | ||
| 48 | + attachments = conversation.createDrafts(id, request.files) | ||
| 49 | + await waitForUploads(conversation, attachments.filter(item => item.kind === 'file').map(item => item.id), signal) | ||
| 50 | + if (!input.addAttachments(attachments.map(item => item.id))) throw new Error('文件暂时无法加入对话,请重试。') | ||
| 51 | + } | ||
| 52 | + signal.throwIfAborted() | ||
| 53 | + if (ctx.layout.panelInfo.getSnapshot().activePanelId !== startingPanel) throw new Error('你已离开工作台,需求已保留;返回后可重新开始。') | ||
| 54 | + // Navigation acquires its own reference before this transaction releases ours. | ||
| 55 | + onStage('conversation') | ||
| 56 | + ctx.uiWorkspace.openSession(id) | ||
| 57 | + transferred = true | ||
| 58 | + input.submit('queue', 'click') | ||
| 59 | + } finally { | ||
| 60 | + if (!transferred) for (const attachment of attachments) conversation.releaseDraftAttachment(attachment.id) | ||
| 61 | + reference.release() | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +function waitForUploads(conversation: ConversationController, ids: readonly string[], signal: AbortSignal): Promise<void> { | ||
| 66 | + return new Promise((resolve, reject) => { | ||
| 67 | + let unsubscribe = () => {}, timer: ReturnType<typeof setTimeout> | undefined | ||
| 68 | + const finish = (error?: unknown) => { unsubscribe(); clearTimeout(timer); signal.removeEventListener('abort', abort); error ? reject(error) : resolve() } | ||
| 69 | + const abort = () => finish(signal.reason ?? new Error('操作已取消。')) | ||
| 70 | + const check = () => { | ||
| 71 | + const uploads = conversation.fileUploads.getSnapshot() | ||
| 72 | + const failed = ids.map(id => uploads[id]).find(upload => upload?.status === 'error') | ||
| 73 | + if (failed?.status === 'error') finish(new Error(`文件上传失败:${failed.message}`)) | ||
| 74 | + else if (ids.every(id => uploads[id]?.status === 'ready')) finish() | ||
| 75 | + } | ||
| 76 | + unsubscribe = conversation.fileUploads.subscribe(check) | ||
| 77 | + timer = setTimeout(() => finish(new Error('文件上传超时,请检查连接后重试。')), 120000) | ||
| 78 | + signal.addEventListener('abort', abort, { once: true }) | ||
| 79 | + if (signal.aborted) abort(); else check() | ||
| 80 | + }) | ||
| 81 | +} | ||
| @@ -0,0 +1,26 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +export type PreparationStage = 'idle' | 'workspace' | 'dependencies' | 'upload' | 'conversation' | ||
| 12 | +export const preparationLabels: Record<PreparationStage, string> = { idle: '', workspace: '正在准备工作区…', dependencies: '正在准备工作流依赖…', upload: '正在上传文件…', conversation: '正在进入对话…' } | ||
| 13 | +export interface WorkbenchState { prompt: string; workflow: string; workspaceId: string; files: File[]; detail: string; busy: boolean; error: string; stage: PreparationStage } | ||
| 14 | +export function createWorkbenchState() { | ||
| 15 | + let state: WorkbenchState = { prompt: '', workflow: 'ops-direct-invoke-flash', workspaceId: '', files: [], detail: 'ops-direct-invoke-flash', busy: false, error: '', stage: 'idle' } | ||
| 16 | + const listeners = new Set<() => void>() | ||
| 17 | + const lifetime = new AbortController() | ||
| 18 | + return { | ||
| 19 | + signal: lifetime.signal, | ||
| 20 | + getSnapshot: () => state, | ||
| 21 | + subscribe(listener: () => void) { listeners.add(listener); return () => { listeners.delete(listener) } }, | ||
| 22 | + set(patch: Partial<WorkbenchState>) { if (lifetime.signal.aborted) return; state = { ...state, ...patch }; for (const listener of listeners) listener() }, | ||
| 23 | + dispose() { lifetime.abort(); listeners.clear() }, | ||
| 24 | + } | ||
| 25 | +} | ||
| 26 | +export type WorkbenchStore = ReturnType<typeof createWorkbenchState> | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +/** Read only the public Session catalog and its main-view retention facts. */ | ||
| 12 | +export function inheritedWorkspaceId(workspaces: readonly { workspaceId: string; sessionIds?: readonly string[] }[], sessions: { current?: string; byId?: Record<string, { id?: string; retainedBy?: { mainView?: number } }> }): string | undefined { | ||
| 13 | + const current = sessions.current ?? Object.entries(sessions.byId ?? {}).find(([, session]) => (session.retainedBy?.mainView ?? 0) > 0)?.[0] | ||
| 14 | + return current ? workspaces.find(workspace => workspace.sessionIds?.includes(current))?.workspaceId : undefined | ||
| 15 | +} | ||


Windows Python 不提供
fcntl,而原生引导在调度前就会导入依赖该模块的orchestrator.py,与文档前面声明的 Windows 支持不一致。建议明确原生编排的平台限制,或替换为跨平台文件锁实现。