create-deepagent-server 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +218 -2
- package/bin/create-deepagent-server.js +27 -0
- package/package.json +50 -4
- package/src/args.js +193 -0
- package/src/cli.js +269 -0
- package/src/dependencies.js +34 -0
- package/src/prompts.js +85 -0
- package/src/registry.js +68 -0
- package/src/scaffold.js +182 -0
- package/src/setup.js +77 -0
- package/src/ui.js +43 -0
- package/src/version.js +1 -0
- package/src/versions.js +29 -0
- package/templates/deepagent/js/deployment/Dockerfile +19 -0
- package/templates/deepagent/js/scripts/check.js +74 -0
- package/templates/deepagent/js/scripts/dev.js +31 -0
- package/templates/deepagent/js/src/agents/factory.js +10 -0
- package/templates/deepagent/js/src/agents/index.js +4 -0
- package/templates/deepagent/js/src/agents/prompts/index.js +2 -0
- package/templates/deepagent/js/src/agents/prompts/loader.js +44 -0
- package/templates/deepagent/js/src/agents/prompts/subagents/analyst.md +17 -0
- package/templates/deepagent/js/src/agents/prompts/subagents/coder.md +17 -0
- package/templates/deepagent/js/src/agents/prompts/subagents/researcher.md +16 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.js +17 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.md +42 -0
- package/templates/deepagent/js/src/agents/state/index.js +1 -0
- package/templates/deepagent/js/src/agents/state/types.js +10 -0
- package/templates/deepagent/js/src/agents/subagents/analyst.js +11 -0
- package/templates/deepagent/js/src/agents/subagents/coder.js +11 -0
- package/templates/deepagent/js/src/agents/subagents/index.js +8 -0
- package/templates/deepagent/js/src/agents/subagents/researcher.js +12 -0
- package/templates/deepagent/js/src/agents/supervisor.js +56 -0
- package/templates/deepagent/js/src/api/app.js +22 -0
- package/templates/deepagent/js/src/api/middleware/auth.js +27 -0
- package/templates/deepagent/js/src/api/middleware/error.js +26 -0
- package/templates/deepagent/js/src/api/routes/agent.js +73 -0
- package/templates/deepagent/js/src/api/routes/health.js +31 -0
- package/templates/deepagent/js/src/api/routes/session.js +62 -0
- package/templates/deepagent/js/src/app.js +79 -0
- package/templates/deepagent/js/src/backends/composite.js +20 -0
- package/templates/deepagent/js/src/backends/filesystem.js +8 -0
- package/templates/deepagent/js/src/backends/index.js +28 -0
- package/templates/deepagent/js/src/backends/sandbox.js +23 -0
- package/templates/deepagent/js/src/config/agent.js +13 -0
- package/templates/deepagent/js/src/config/env.js +73 -0
- package/templates/deepagent/js/src/config/index.js +35 -0
- package/templates/deepagent/js/src/config/model.js +34 -0
- package/templates/deepagent/js/src/graph/checkpointer.js +20 -0
- package/templates/deepagent/js/src/graph/compile.js +8 -0
- package/templates/deepagent/js/src/graph/index.js +3 -0
- package/templates/deepagent/js/src/graph/store.js +20 -0
- package/templates/deepagent/js/src/index.js +32 -0
- package/templates/deepagent/js/src/infrastructure/database/client.js +43 -0
- package/templates/deepagent/js/src/infrastructure/database/migrations/001_init.sql +20 -0
- package/templates/deepagent/js/src/infrastructure/logger/index.js +19 -0
- package/templates/deepagent/js/src/infrastructure/redis/client.js +45 -0
- package/templates/deepagent/js/src/infrastructure/shutdown/index.js +51 -0
- package/templates/deepagent/js/src/memory/index.js +6 -0
- package/templates/deepagent/js/src/memory/manager.js +39 -0
- package/templates/deepagent/js/src/memory/store.js +36 -0
- package/templates/deepagent/js/src/middleware/approval.js +42 -0
- package/templates/deepagent/js/src/middleware/context.js +30 -0
- package/templates/deepagent/js/src/middleware/index.js +9 -0
- package/templates/deepagent/js/src/middleware/logging.js +66 -0
- package/templates/deepagent/js/src/middleware/security.js +51 -0
- package/templates/deepagent/js/src/schemas/agent.js +33 -0
- package/templates/deepagent/js/src/schemas/common.js +19 -0
- package/templates/deepagent/js/src/schemas/locale.js +3 -0
- package/templates/deepagent/js/src/schemas/session.js +23 -0
- package/templates/deepagent/js/src/services/agent.service.js +117 -0
- package/templates/deepagent/js/src/services/memory.service.js +27 -0
- package/templates/deepagent/js/src/services/session.service.js +92 -0
- package/templates/deepagent/js/src/skills/index.js +17 -0
- package/templates/deepagent/js/src/skills/loader.js +65 -0
- package/templates/deepagent/js/src/tools/database/index.js +1 -0
- package/templates/deepagent/js/src/tools/database/query.js +62 -0
- package/templates/deepagent/js/src/tools/filesystem/index.js +86 -0
- package/templates/deepagent/js/src/tools/index.js +30 -0
- package/templates/deepagent/js/src/tools/mcp/client.js +35 -0
- package/templates/deepagent/js/src/tools/mcp/connections.js +54 -0
- package/templates/deepagent/js/src/tools/mcp/index.js +8 -0
- package/templates/deepagent/js/src/tools/mcp/registry.js +32 -0
- package/templates/deepagent/js/src/tools/search/index.js +1 -0
- package/templates/deepagent/js/src/tools/search/web-search.js +54 -0
- package/templates/deepagent/js/src/utils/errors.js +64 -0
- package/templates/deepagent/js/src/utils/helpers.js +42 -0
- package/templates/deepagent/js/tests/agents/prompts.test.js +24 -0
- package/templates/deepagent/js/tests/agents/supervisor.test.js +34 -0
- package/templates/deepagent/js/tests/integration/api.test.js +99 -0
- package/templates/deepagent/js/tests/middleware/security.test.js +24 -0
- package/templates/deepagent/js/tests/tools/query.test.js +23 -0
- package/templates/deepagent/shared/README.md +162 -0
- package/templates/deepagent/shared/_editorconfig +12 -0
- package/templates/deepagent/shared/_env.example +56 -0
- package/templates/deepagent/shared/_gitignore +22 -0
- package/templates/deepagent/shared/deployment/docker-compose.yml +56 -0
- package/templates/deepagent/shared/resources/AGENTS.md +32 -0
- package/templates/deepagent/shared/resources/knowledge/README.md +5 -0
- package/templates/deepagent/shared/skills/analysis/SKILL.md +28 -0
- package/templates/deepagent/shared/skills/coding/SKILL.md +28 -0
- package/templates/deepagent/shared/skills/research/SKILL.md +31 -0
- package/templates/deepagent/shared/workspaces/README.md +5 -0
- package/templates/deepagent/ts/deployment/Dockerfile +25 -0
- package/templates/deepagent/ts/scripts/check.ts +91 -0
- package/templates/deepagent/ts/scripts/copy-assets.ts +35 -0
- package/templates/deepagent/ts/scripts/dev.ts +40 -0
- package/templates/deepagent/ts/src/agents/factory.ts +11 -0
- package/templates/deepagent/ts/src/agents/index.ts +4 -0
- package/templates/deepagent/ts/src/agents/prompts/index.ts +2 -0
- package/templates/deepagent/ts/src/agents/prompts/loader.ts +52 -0
- package/templates/deepagent/ts/src/agents/prompts/subagents/analyst.md +17 -0
- package/templates/deepagent/ts/src/agents/prompts/subagents/coder.md +17 -0
- package/templates/deepagent/ts/src/agents/prompts/subagents/researcher.md +16 -0
- package/templates/deepagent/ts/src/agents/prompts/supervisor.md +42 -0
- package/templates/deepagent/ts/src/agents/prompts/supervisor.ts +33 -0
- package/templates/deepagent/ts/src/agents/state/index.ts +1 -0
- package/templates/deepagent/ts/src/agents/state/types.ts +13 -0
- package/templates/deepagent/ts/src/agents/subagents/analyst.ts +14 -0
- package/templates/deepagent/ts/src/agents/subagents/coder.ts +14 -0
- package/templates/deepagent/ts/src/agents/subagents/index.ts +10 -0
- package/templates/deepagent/ts/src/agents/subagents/researcher.ts +15 -0
- package/templates/deepagent/ts/src/agents/supervisor.ts +80 -0
- package/templates/deepagent/ts/src/api/app.ts +48 -0
- package/templates/deepagent/ts/src/api/middleware/auth.ts +37 -0
- package/templates/deepagent/ts/src/api/middleware/error.ts +33 -0
- package/templates/deepagent/ts/src/api/routes/agent.ts +93 -0
- package/templates/deepagent/ts/src/api/routes/health.ts +45 -0
- package/templates/deepagent/ts/src/api/routes/session.ts +77 -0
- package/templates/deepagent/ts/src/app.ts +104 -0
- package/templates/deepagent/ts/src/backends/composite.ts +34 -0
- package/templates/deepagent/ts/src/backends/filesystem.ts +19 -0
- package/templates/deepagent/ts/src/backends/index.ts +42 -0
- package/templates/deepagent/ts/src/backends/sandbox.ts +32 -0
- package/templates/deepagent/ts/src/config/agent.ts +37 -0
- package/templates/deepagent/ts/src/config/env.ts +102 -0
- package/templates/deepagent/ts/src/config/index.ts +76 -0
- package/templates/deepagent/ts/src/config/model.ts +49 -0
- package/templates/deepagent/ts/src/graph/checkpointer.ts +26 -0
- package/templates/deepagent/ts/src/graph/compile.ts +15 -0
- package/templates/deepagent/ts/src/graph/index.ts +3 -0
- package/templates/deepagent/ts/src/graph/store.ts +26 -0
- package/templates/deepagent/ts/src/index.ts +39 -0
- package/templates/deepagent/ts/src/infrastructure/database/client.ts +61 -0
- package/templates/deepagent/ts/src/infrastructure/database/migrations/001_init.sql +20 -0
- package/templates/deepagent/ts/src/infrastructure/logger/index.ts +25 -0
- package/templates/deepagent/ts/src/infrastructure/redis/client.ts +64 -0
- package/templates/deepagent/ts/src/infrastructure/shutdown/index.ts +85 -0
- package/templates/deepagent/ts/src/memory/index.ts +11 -0
- package/templates/deepagent/ts/src/memory/manager.ts +74 -0
- package/templates/deepagent/ts/src/memory/store.ts +57 -0
- package/templates/deepagent/ts/src/middleware/approval.ts +49 -0
- package/templates/deepagent/ts/src/middleware/context.ts +37 -0
- package/templates/deepagent/ts/src/middleware/index.ts +9 -0
- package/templates/deepagent/ts/src/middleware/logging.ts +72 -0
- package/templates/deepagent/ts/src/middleware/security.ts +60 -0
- package/templates/deepagent/ts/src/schemas/agent.ts +48 -0
- package/templates/deepagent/ts/src/schemas/common.ts +26 -0
- package/templates/deepagent/ts/src/schemas/locale.ts +4 -0
- package/templates/deepagent/ts/src/schemas/session.ts +31 -0
- package/templates/deepagent/ts/src/services/agent.service.ts +170 -0
- package/templates/deepagent/ts/src/services/memory.service.ts +43 -0
- package/templates/deepagent/ts/src/services/session.service.ts +148 -0
- package/templates/deepagent/ts/src/skills/index.ts +26 -0
- package/templates/deepagent/ts/src/skills/loader.ts +94 -0
- package/templates/deepagent/ts/src/tools/database/index.ts +1 -0
- package/templates/deepagent/ts/src/tools/database/query.ts +71 -0
- package/templates/deepagent/ts/src/tools/filesystem/index.ts +108 -0
- package/templates/deepagent/ts/src/tools/index.ts +41 -0
- package/templates/deepagent/ts/src/tools/mcp/client.ts +53 -0
- package/templates/deepagent/ts/src/tools/mcp/connections.ts +68 -0
- package/templates/deepagent/ts/src/tools/mcp/index.ts +10 -0
- package/templates/deepagent/ts/src/tools/mcp/registry.ts +48 -0
- package/templates/deepagent/ts/src/tools/search/index.ts +1 -0
- package/templates/deepagent/ts/src/tools/search/web-search.ts +82 -0
- package/templates/deepagent/ts/src/utils/errors.ts +95 -0
- package/templates/deepagent/ts/src/utils/helpers.ts +52 -0
- package/templates/deepagent/ts/tests/agents/prompts.test.ts +30 -0
- package/templates/deepagent/ts/tests/agents/supervisor.test.ts +42 -0
- package/templates/deepagent/ts/tests/integration/api.test.ts +123 -0
- package/templates/deepagent/ts/tests/middleware/security.test.ts +27 -0
- package/templates/deepagent/ts/tests/tools/query.test.ts +27 -0
- package/templates/deepagent/ts/tsconfig.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 create-deepagent-server 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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,219 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-deepagent-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
几秒钟内创建一个面向生产的 [Deep Agents](https://docs.langchain.com/oss/javascript/deepagents/overview) 项目。
|
|
4
|
+
|
|
5
|
+
内置主 Agent、专职子 Agent、挂载式文件系统、长期记忆、Skills、MCP 工具、Express API、测试和 Docker 配置,依赖版本在生成时自动解析到最新发布版。
|
|
6
|
+
|
|
7
|
+
- **默认 JavaScript**,传 `--ts` 切换 TypeScript
|
|
8
|
+
- **仅使用 ESM**,现代 ES6+ 语法,相对导入显式带 `.js`
|
|
9
|
+
- **`deepagents` + LangGraph**:checkpointer/store 默认内存,可切换 PostgreSQL
|
|
10
|
+
- **Zod** 校验、**pino** 日志、优雅关闭、SSE 流式输出
|
|
11
|
+
- CLI 本身零运行时依赖
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# npm
|
|
17
|
+
npm create deepagent-server@latest my-agent
|
|
18
|
+
|
|
19
|
+
# 或直接运行 CLI
|
|
20
|
+
npx create-deepagent-server@latest my-agent
|
|
21
|
+
|
|
22
|
+
# TypeScript + pnpm,跳过依赖安装
|
|
23
|
+
npm create deepagent-server@latest my-agent -- --ts --pm pnpm --no-install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 交互式提示
|
|
27
|
+
|
|
28
|
+
在终端中运行(包括 `npx` / `npm create`)时,CLI 会依次询问所有选项,并把推荐项作为默认值:
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
? 项目目录 (my-deepagent)
|
|
32
|
+
? 项目语言
|
|
33
|
+
❯ 1. JavaScript — 推荐
|
|
34
|
+
2. TypeScript — 类型检查
|
|
35
|
+
? 包管理器
|
|
36
|
+
❯ 1. npm — 已检测
|
|
37
|
+
2. pnpm
|
|
38
|
+
3. yarn
|
|
39
|
+
4. bun
|
|
40
|
+
? 是否立即安装依赖?(Y/n)
|
|
41
|
+
? 是否初始化 Git 仓库?(Y/n)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
直接回车使用默认值。传入对应参数会跳过该项提问(`--ts` 跳过语言、`--no-install` 跳过安装确认等)。传 `-y` 跳过全部提问,使用默认值:JavaScript、自动检测的包管理器、安装依赖、初始化 Git。
|
|
45
|
+
|
|
46
|
+
只有未传项目名时才会出现“项目目录”提问。
|
|
47
|
+
|
|
48
|
+
### 选项
|
|
49
|
+
|
|
50
|
+
| 参数 | 说明 |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `-t, --template <name>` | 项目模板(目前只有 `deepagent`) |
|
|
53
|
+
| `--js` | JavaScript 项目(默认) |
|
|
54
|
+
| `--ts, --typescript` | TypeScript 项目 |
|
|
55
|
+
| `--pm <name>` | `npm`、`pnpm`、`yarn`、`bun` |
|
|
56
|
+
| `--no-install` | 跳过依赖安装 |
|
|
57
|
+
| `--no-git` | 跳过 `git init` |
|
|
58
|
+
| `--no-latest` | 使用 CLI 内置版本,不解析 npm 最新版 |
|
|
59
|
+
| `-y, --yes` | 使用默认值并跳过所有提问 |
|
|
60
|
+
| `-f, --force` | 允许写入非空目录 |
|
|
61
|
+
| `-h, --help` | 显示帮助 |
|
|
62
|
+
| `-v, --version` | 显示 CLI 版本 |
|
|
63
|
+
|
|
64
|
+
生成项目时会从 npm registry 并行解析所有模板依赖的最新版本(5 秒超时);无法访问 registry 时回退到 `src/versions.js` 中的内置版本。
|
|
65
|
+
|
|
66
|
+
## 生成的项目
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
my-agent/
|
|
70
|
+
├── src/
|
|
71
|
+
│ ├── index.(js|ts) # 服务入口
|
|
72
|
+
│ ├── app.(js|ts) # 配置 → 基础设施 → Agent → HTTP
|
|
73
|
+
│ ├── config/ # 环境变量、模型与 Agent 配置
|
|
74
|
+
│ ├── agents/
|
|
75
|
+
│ │ ├── factory.ts # createDeepAgent 封装
|
|
76
|
+
│ │ ├── supervisor.ts # 主 Agent
|
|
77
|
+
│ │ ├── subagents/ # researcher、coder、analyst
|
|
78
|
+
│ │ ├── prompts/ # supervisor.md + subagents/*.md
|
|
79
|
+
│ │ └── state/ # 自定义 LangGraph 状态
|
|
80
|
+
│ ├── tools/ # Web 搜索、SQL、工作区文件、MCP
|
|
81
|
+
│ ├── middleware/ # 日志、安全、审批、上下文
|
|
82
|
+
│ ├── backends/ # 文件系统、沙箱、组合后端
|
|
83
|
+
│ ├── memory/ # 长期记忆 store 与管理器
|
|
84
|
+
│ ├── skills/ # SKILL.md 发现与校验
|
|
85
|
+
│ ├── graph/ # 编译、checkpointer、store
|
|
86
|
+
│ ├── services/ # Agent、会话、记忆服务
|
|
87
|
+
│ ├── api/ # Express 应用、路由、中间件
|
|
88
|
+
│ ├── schemas/ # Zod 结构
|
|
89
|
+
│ ├── infrastructure/ # PostgreSQL、Redis、日志、优雅关闭
|
|
90
|
+
│ └── utils/
|
|
91
|
+
├── resources/
|
|
92
|
+
│ ├── AGENTS.md # Agent 记忆 → /resources/AGENTS.md
|
|
93
|
+
│ └── knowledge/
|
|
94
|
+
├── skills/ # research / coding / analysis SKILL.md
|
|
95
|
+
├── workspaces/ # Agent 可写沙箱 → /workspace/
|
|
96
|
+
├── tests/ # agents、tools、middleware、integration
|
|
97
|
+
├── scripts/ # 交互终端 + 预检脚本
|
|
98
|
+
├── deployment/ # Dockerfile + docker-compose
|
|
99
|
+
├── .editorconfig
|
|
100
|
+
├── .env.example
|
|
101
|
+
├── package.json
|
|
102
|
+
└── tsconfig.json # 仅 TypeScript
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Agent 是如何装配的
|
|
106
|
+
|
|
107
|
+
`createSupervisorAgent` 构建一个 Deep Agent:
|
|
108
|
+
|
|
109
|
+
- **后端** —— `CompositeBackend` 把 `/workspace/`、`/resources/`、`/skills/` 挂载到磁盘,把 `/memories/` 挂载到 LangGraph store。`ENABLE_SHELL=true` 时默认后端切换为 `LocalShellBackend` 并暴露 `execute`。
|
|
110
|
+
- **子 Agent** —— `researcher`(Tavily 搜索)、`coder`(工作区改代码)、`analyst`(只读 SQL)。每个都是声明式 `SubAgent`,拥有独立提示词与技能挂载。
|
|
111
|
+
- **提示词** —— `supervisor.md`、`subagents/*.md` 等 Markdown 文件,由 `loadPrompt()` 加载,`renderPrompt()` 填充 `{{占位符}}`(例如团队列表)。
|
|
112
|
+
- **中间件** —— 调用日志、危险命令拦截(返回 `ToolMessage` 错误)、按请求注入租户/用户上下文。
|
|
113
|
+
- **审批** —— `APPROVAL_MODE=sensitive`(默认)通过 `interruptOn` 暂停修改类工具;用同一个 `thread_id` 恢复。
|
|
114
|
+
- **记忆** —— 启动时注入 `AGENTS.md`,`/memories/` 配合 `MemoryManager` 持久化长期事实。
|
|
115
|
+
- **API** —— `/health`、`/health/ready`、`POST /api/agents/invoke`、`POST /api/agents/stream`(SSE)、`POST /api/agents/resume`、会话 CRUD、可选 Bearer 鉴权。
|
|
116
|
+
|
|
117
|
+
### 生成项目的脚本
|
|
118
|
+
|
|
119
|
+
| 脚本 | JavaScript | TypeScript |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `npm run dev` | `node --watch src/index.js` | `tsx watch src/index.ts` |
|
|
122
|
+
| `npm start` | `node src/index.js` | `node dist/index.js` |
|
|
123
|
+
| `npm run agent` | 交互式终端会话 | 同左 |
|
|
124
|
+
| `npm run check` | 预检 | 同左 |
|
|
125
|
+
| `npm test` | `node --test` | `node --import tsx --test` |
|
|
126
|
+
| `npm run build` | — | `tsc` + `scripts/copy-assets.ts` |
|
|
127
|
+
| `npm run typecheck` | — | `tsc --noEmit` |
|
|
128
|
+
|
|
129
|
+
## 本 CLI 的仓库结构
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
bin/create-deepagent-server.js 可执行入口
|
|
133
|
+
src/
|
|
134
|
+
├── cli.js 主流程
|
|
135
|
+
├── args.js 零依赖参数解析
|
|
136
|
+
├── prompts.js readline 交互
|
|
137
|
+
├── registry.js 最新版本解析 + 回退
|
|
138
|
+
├── scaffold.js 模板合并 + package.json 生成
|
|
139
|
+
├── setup.js 安装 / git 辅助
|
|
140
|
+
├── dependencies.js 按语言划分的依赖列表
|
|
141
|
+
└── versions.js 内置兜底版本
|
|
142
|
+
templates/deepagent/
|
|
143
|
+
├── shared/ 两种语言共用的文件
|
|
144
|
+
├── ts/ TypeScript 源码(唯一事实来源)
|
|
145
|
+
└── js/ 由 ts/ 转译生成(已提交)
|
|
146
|
+
test/cli.test.js
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 模板生成
|
|
150
|
+
|
|
151
|
+
`src/`、`scripts/`、`tests/` 下的 TypeScript 是唯一源码。JavaScript 模板通过 TypeScript 编译器做类型擦除生成(不打包):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npm install
|
|
155
|
+
npm run build:templates
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`templates/deepagent/js` 已提交到仓库,发布后的包不需要 TypeScript 运行时。共享文件(`README.md`、`.env.example`、resources、skills、docker-compose 等)在生成项目时合并,因此仓库中只保留一份;每种语言各自保留自己的 `deployment/Dockerfile`,因为 TypeScript 镜像需要构建阶段。
|
|
159
|
+
|
|
160
|
+
修改 TypeScript 模板后,请执行 `npm run build:templates` 并提交更新后的 `js/` 产物。
|
|
161
|
+
|
|
162
|
+
## 开发
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npm install
|
|
166
|
+
npm run build:templates
|
|
167
|
+
npm run lint # ES6+ 语法守卫
|
|
168
|
+
npm test
|
|
169
|
+
node bin/create-deepagent-server.js /tmp/demo-js --js --no-install --no-git --no-latest
|
|
170
|
+
node bin/create-deepagent-server.js /tmp/demo-ts --ts --no-install --no-git --no-latest
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
CLI 没有运行时依赖;开发依赖只有 TypeScript(生成模板、解析语法)和 Prettier(统一代码风格)。
|
|
174
|
+
|
|
175
|
+
### 代码风格:ES6+ 优先
|
|
176
|
+
|
|
177
|
+
仓库内所有 `.js` / `.ts` 文件(`bin/`、`src/`、`scripts/`、`test/` 与 `templates/deepagent/`)遵循同一套 ES6+ 优先约定:
|
|
178
|
+
|
|
179
|
+
| 约定 | 用 | 不用 |
|
|
180
|
+
| --- | --- | --- |
|
|
181
|
+
| 变量声明 | `const` / `let` | `var` |
|
|
182
|
+
| 模块 | `import` / `export`(ESM) | `require` / `module.exports` |
|
|
183
|
+
| 函数 | 箭头函数(具名导出用 `const name = (...) => {}`)、方法简写 | `function` 声明 / 表达式、`key: function () {}` |
|
|
184
|
+
| 字符串 | 模板字符串 | `+` 拼接 |
|
|
185
|
+
| 参数 | 剩余参数 `...args`、默认值 | `arguments` |
|
|
186
|
+
| 对象 | 展开 `{ ...source }`、属性简写 | `Object.assign({}, ...)`、`key: key` |
|
|
187
|
+
| 继承 | `class` | 原型链 |
|
|
188
|
+
| 数组 | 字面量、`includes()` | `new Array()`、`indexOf() === -1` |
|
|
189
|
+
|
|
190
|
+
统一使用箭头函数:具名导出也写成 `const name = (...) => {}`,不再使用 `function` 声明;箭头函数没有提升,调用必须出现在定义之后。
|
|
191
|
+
|
|
192
|
+
三目运算尽量写在同一行:条件或分支过长时,优先提取局部变量、常量或提前返回,而不是让 Prettier 把 `? :` 拆成多行。
|
|
193
|
+
|
|
194
|
+
`npm run lint`(`scripts/check-es6.js`)用 TypeScript 编译器 API 解析语法树做校验,不会误伤注释和字符串,也不需要额外依赖;`npm test` 前会自动执行,违反约定会直接失败。
|
|
195
|
+
|
|
196
|
+
## 环境要求
|
|
197
|
+
|
|
198
|
+
- Node.js **22.6+**(生成项目的测试脚本使用 `node --test` glob 参数,并使用 ESM `NodeNext` 解析)
|
|
199
|
+
- 模型 API Key:`OPENAI_API_KEY` 或 `ANTHROPIC_API_KEY`
|
|
200
|
+
|
|
201
|
+
`deepagents` 把 LangChain 运行时声明为 **peer dependencies**。npm 7+ 和 pnpm 8+ 会自动安装;**Yarn 用户需要显式添加**:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
yarn add @langchain/core @langchain/langgraph @langchain/langgraph-checkpoint @langchain/langgraph-sdk langchain langsmith
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 发布
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
npm run build:templates # 重新生成 templates/deepagent/js
|
|
211
|
+
npm test
|
|
212
|
+
npm publish
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`files` 白名单包含 `bin`、`src`、`templates`;`.npmignore` 会额外排除本地测试/构建文件、编辑器目录和 lockfile,同时保留模板内部的 `scripts/`、`tests/`、`deployment/` 目录。
|
|
216
|
+
|
|
217
|
+
## 许可证
|
|
218
|
+
|
|
219
|
+
MIT
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/cli.js";
|
|
4
|
+
|
|
5
|
+
process.on("SIGINT", () => {
|
|
6
|
+
process.stdout.write("\n");
|
|
7
|
+
process.exit(130);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const code = await main();
|
|
12
|
+
process.exitCode = code ?? 0;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error?.name === "AbortError" || error?.code === "ABORT_ERR") {
|
|
15
|
+
process.stderr.write("\n已取消。\n");
|
|
16
|
+
process.exitCode = 130;
|
|
17
|
+
} else {
|
|
18
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
+
process.stderr.write(`\n✖ ${message}\n`);
|
|
20
|
+
|
|
21
|
+
if (process.env.DEBUG) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-deepagent-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "快速创建生产可用的 Deep Agents(deepagents + LangGraph)项目,支持 JavaScript/TypeScript,仅使用 ESM。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-deepagent-server": "bin/create-deepagent-server.js",
|
|
8
|
+
"create-deepagent": "bin/create-deepagent-server.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
"templates"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.6.0"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build:templates": "node scripts/build-templates.js",
|
|
20
|
+
"lint": "node scripts/check-es6.js",
|
|
21
|
+
"pretest": "node scripts/check-es6.js",
|
|
22
|
+
"test": "node --test \"test/**/*.test.js\"",
|
|
23
|
+
"prepublishOnly": "npm run build:templates && npm test",
|
|
24
|
+
"format": "prettier --write \"src/**/*.js\" \"scripts/**/*.js\" \"test/**/*.js\" \"templates/deepagent/ts/**/*.ts\" \"templates/deepagent/js/**/*.js\" \"templates/deepagent/ts/tsconfig.json\" package.json .prettierrc.json",
|
|
25
|
+
"format:check": "prettier --check \"src/**/*.js\" \"scripts/**/*.js\" \"test/**/*.js\" \"templates/deepagent/ts/**/*.ts\" \"templates/deepagent/js/**/*.js\" \"templates/deepagent/ts/tsconfig.json\" package.json .prettierrc.json"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"deepagents",
|
|
29
|
+
"deep-agents",
|
|
30
|
+
"langgraph",
|
|
31
|
+
"langchain",
|
|
32
|
+
"ai",
|
|
33
|
+
"agent",
|
|
34
|
+
"agents",
|
|
35
|
+
"cli",
|
|
36
|
+
"scaffold",
|
|
37
|
+
"create",
|
|
38
|
+
"starter",
|
|
39
|
+
"template",
|
|
40
|
+
"typescript",
|
|
41
|
+
"javascript",
|
|
42
|
+
"esm"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"prettier": "^3.6.2",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/args.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export class UsageError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "UsageError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const TEMPLATES = ["deepagent"];
|
|
9
|
+
export const PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
10
|
+
|
|
11
|
+
export const HELP_TEXT = `create-deepagent-server —— 快速创建 Deep Agents 项目
|
|
12
|
+
|
|
13
|
+
用法:
|
|
14
|
+
create-deepagent-server [项目名] [选项]
|
|
15
|
+
npm create deepagent-server@latest -- [项目名] [选项]
|
|
16
|
+
|
|
17
|
+
选项:
|
|
18
|
+
-t, --template <name> 项目模板(默认:deepagent)
|
|
19
|
+
--js JavaScript 项目(默认)
|
|
20
|
+
--ts, --typescript TypeScript 项目
|
|
21
|
+
--pm <name> 包管理器:npm、pnpm、yarn、bun
|
|
22
|
+
--no-install 跳过依赖安装
|
|
23
|
+
--no-git 跳过 git 初始化
|
|
24
|
+
--no-latest 使用 CLI 内置版本,不解析 npm 最新版本
|
|
25
|
+
-y, --yes 使用默认值并跳过所有交互
|
|
26
|
+
-f, --force 允许写入非空目录
|
|
27
|
+
-h, --help 显示帮助
|
|
28
|
+
-v, --version 显示版本
|
|
29
|
+
|
|
30
|
+
示例:
|
|
31
|
+
npm create deepagent-server@latest my-agent
|
|
32
|
+
npm create deepagent-server@latest my-agent -- --ts --pm pnpm
|
|
33
|
+
npx create-deepagent-server@latest my-agent --no-install
|
|
34
|
+
|
|
35
|
+
生成的项目结构:
|
|
36
|
+
my-agent/
|
|
37
|
+
├── src/
|
|
38
|
+
│ ├── index.(js|ts) # 服务入口
|
|
39
|
+
│ ├── app.(js|ts) # 应用装配
|
|
40
|
+
│ ├── config/ # 环境变量、模型与 Agent 配置
|
|
41
|
+
│ ├── agents/ # 主 Agent、子 Agent、提示词与状态
|
|
42
|
+
│ ├── tools/ # 搜索、数据库、文件系统、MCP
|
|
43
|
+
│ ├── middleware/ # 日志、安全、审批、上下文
|
|
44
|
+
│ ├── backends/ # 文件系统 / 沙箱 / 组合后端
|
|
45
|
+
│ ├── memory/ # 长期记忆存储与管理
|
|
46
|
+
│ ├── skills/ # SKILL.md 发现与校验
|
|
47
|
+
│ ├── graph/ # LangGraph 编译、checkpointer、store
|
|
48
|
+
│ ├── services/ # Agent、会话与记忆服务
|
|
49
|
+
│ ├── api/ # Express 路由与中间件
|
|
50
|
+
│ ├── schemas/ # Zod 请求/响应结构
|
|
51
|
+
│ ├── infrastructure/ # PostgreSQL、Redis、日志与优雅关闭
|
|
52
|
+
│ └── utils/
|
|
53
|
+
├── resources/ # AGENTS.md 与知识库
|
|
54
|
+
├── skills/ # research、coding、analysis 技能
|
|
55
|
+
├── workspaces/ # Agent 工作目录
|
|
56
|
+
├── tests/ # 单元测试与集成测试
|
|
57
|
+
├── scripts/ # 交互终端与预检脚本
|
|
58
|
+
└── deployment/ # Dockerfile 与 docker-compose`;
|
|
59
|
+
|
|
60
|
+
const isValueFlag = (flag) => ["-t", "--template", "--pm"].includes(flag);
|
|
61
|
+
|
|
62
|
+
const readValue = (argv, index, flag, inlineValue) => {
|
|
63
|
+
if (inlineValue !== undefined) {
|
|
64
|
+
if (inlineValue === "") throw new UsageError(`${flag} 缺少参数值。`);
|
|
65
|
+
return { value: inlineValue, index };
|
|
66
|
+
}
|
|
67
|
+
const next = argv[index + 1];
|
|
68
|
+
if (next === undefined || (next.startsWith("-") && next !== "-")) {
|
|
69
|
+
throw new UsageError(`${flag} 缺少参数值。`);
|
|
70
|
+
}
|
|
71
|
+
return { value: next, index: index + 1 };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 不依赖第三方库解析命令行参数。
|
|
76
|
+
* 显式支持否定形式的参数(--no-install、--no-git、--no-latest)。
|
|
77
|
+
*/
|
|
78
|
+
export const parseArgs = (argv) => {
|
|
79
|
+
const options = {
|
|
80
|
+
template: "deepagent",
|
|
81
|
+
language: undefined,
|
|
82
|
+
pm: undefined,
|
|
83
|
+
install: undefined,
|
|
84
|
+
git: undefined,
|
|
85
|
+
latest: true,
|
|
86
|
+
yes: false,
|
|
87
|
+
force: false,
|
|
88
|
+
help: false,
|
|
89
|
+
version: false,
|
|
90
|
+
};
|
|
91
|
+
const provided = new Set();
|
|
92
|
+
const positionals = [];
|
|
93
|
+
|
|
94
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
95
|
+
const raw = argv[i];
|
|
96
|
+
|
|
97
|
+
if (raw === "--") {
|
|
98
|
+
positionals.push(...argv.slice(i + 1));
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!raw.startsWith("-") || raw === "-") {
|
|
103
|
+
positionals.push(raw);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const equalsIndex = raw.indexOf("=");
|
|
108
|
+
const flag = equalsIndex === -1 ? raw : raw.slice(0, equalsIndex);
|
|
109
|
+
const inlineValue = equalsIndex === -1 ? undefined : raw.slice(equalsIndex + 1);
|
|
110
|
+
|
|
111
|
+
if (isValueFlag(flag)) {
|
|
112
|
+
const parsed = readValue(argv, i, flag, inlineValue);
|
|
113
|
+
i = parsed.index;
|
|
114
|
+
|
|
115
|
+
if (flag === "-t" || flag === "--template") {
|
|
116
|
+
if (!TEMPLATES.includes(parsed.value)) {
|
|
117
|
+
throw new UsageError(`未知模板 "${parsed.value}"。可用模板:${TEMPLATES.join("、")}。`);
|
|
118
|
+
}
|
|
119
|
+
options.template = parsed.value;
|
|
120
|
+
provided.add("template");
|
|
121
|
+
} else {
|
|
122
|
+
if (!PACKAGE_MANAGERS.includes(parsed.value)) {
|
|
123
|
+
throw new UsageError(
|
|
124
|
+
`未知包管理器 "${parsed.value}"。可选值:${PACKAGE_MANAGERS.join("、")}。`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
options.pm = parsed.value;
|
|
128
|
+
provided.add("pm");
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
switch (flag) {
|
|
134
|
+
case "-h":
|
|
135
|
+
case "--help":
|
|
136
|
+
options.help = true;
|
|
137
|
+
break;
|
|
138
|
+
case "-v":
|
|
139
|
+
case "--version":
|
|
140
|
+
options.version = true;
|
|
141
|
+
break;
|
|
142
|
+
case "-y":
|
|
143
|
+
case "--yes":
|
|
144
|
+
options.yes = true;
|
|
145
|
+
break;
|
|
146
|
+
case "-f":
|
|
147
|
+
case "--force":
|
|
148
|
+
options.force = true;
|
|
149
|
+
break;
|
|
150
|
+
case "--js":
|
|
151
|
+
options.language = "js";
|
|
152
|
+
provided.add("language");
|
|
153
|
+
break;
|
|
154
|
+
case "--ts":
|
|
155
|
+
case "--typescript":
|
|
156
|
+
options.language = "ts";
|
|
157
|
+
provided.add("language");
|
|
158
|
+
break;
|
|
159
|
+
case "--install":
|
|
160
|
+
options.install = true;
|
|
161
|
+
provided.add("install");
|
|
162
|
+
break;
|
|
163
|
+
case "--no-install":
|
|
164
|
+
options.install = false;
|
|
165
|
+
provided.add("install");
|
|
166
|
+
break;
|
|
167
|
+
case "--git":
|
|
168
|
+
options.git = true;
|
|
169
|
+
provided.add("git");
|
|
170
|
+
break;
|
|
171
|
+
case "--no-git":
|
|
172
|
+
options.git = false;
|
|
173
|
+
provided.add("git");
|
|
174
|
+
break;
|
|
175
|
+
case "--latest":
|
|
176
|
+
options.latest = true;
|
|
177
|
+
break;
|
|
178
|
+
case "--no-latest":
|
|
179
|
+
options.latest = false;
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
throw new UsageError(
|
|
183
|
+
`未知选项:${flag}\n\n运行 "create-deepagent-server --help" 查看用法。`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (positionals.length > 1) {
|
|
189
|
+
throw new UsageError(`多余的参数:${positionals[1]}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return { options, positionals, provided };
|
|
193
|
+
};
|