create-deepagent-server 0.1.0 → 1.0.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.
Files changed (175) hide show
  1. package/README.md +83 -8
  2. package/package.json +1 -1
  3. package/src/args.js +6 -4
  4. package/src/cli.js +1 -4
  5. package/src/dependencies.js +1 -1
  6. package/src/prompts.js +1 -0
  7. package/src/registry.js +8 -8
  8. package/src/scaffold.js +21 -7
  9. package/src/setup.js +2 -0
  10. package/src/version.js +1 -1
  11. package/src/versions.js +1 -1
  12. package/templates/deepagent/js/scripts/check.js +34 -11
  13. package/templates/deepagent/js/scripts/dev.js +9 -0
  14. package/templates/deepagent/js/src/agents/factory.js +2 -1
  15. package/templates/deepagent/js/src/agents/prompts/loader.js +9 -0
  16. package/templates/deepagent/js/src/agents/prompts/supervisor.js +4 -0
  17. package/templates/deepagent/js/src/agents/prompts/supervisor.md +1 -2
  18. package/templates/deepagent/js/src/agents/state/types.js +1 -0
  19. package/templates/deepagent/js/src/agents/subagents/analyst.js +4 -3
  20. package/templates/deepagent/js/src/agents/subagents/coder.js +1 -0
  21. package/templates/deepagent/js/src/agents/subagents/index.js +5 -4
  22. package/templates/deepagent/js/src/agents/supervisor.js +12 -4
  23. package/templates/deepagent/js/src/api/app.js +7 -0
  24. package/templates/deepagent/js/src/api/middleware/auth.js +9 -0
  25. package/templates/deepagent/js/src/api/middleware/error.js +4 -0
  26. package/templates/deepagent/js/src/api/routes/agent.js +19 -49
  27. package/templates/deepagent/js/src/api/routes/health.js +12 -3
  28. package/templates/deepagent/js/src/api/routes/session.js +28 -48
  29. package/templates/deepagent/js/src/app.js +31 -12
  30. package/templates/deepagent/js/src/backends/composite.js +2 -0
  31. package/templates/deepagent/js/src/backends/filesystem.js +1 -0
  32. package/templates/deepagent/js/src/backends/index.js +35 -3
  33. package/templates/deepagent/js/src/backends/sandbox.js +3 -0
  34. package/templates/deepagent/js/src/config/agent.js +1 -0
  35. package/templates/deepagent/js/src/config/database.js +19 -0
  36. package/templates/deepagent/js/src/config/env.js +46 -23
  37. package/templates/deepagent/js/src/config/index.js +13 -3
  38. package/templates/deepagent/js/src/graph/checkpointer.js +10 -2
  39. package/templates/deepagent/js/src/graph/compile.js +1 -0
  40. package/templates/deepagent/js/src/graph/store.js +10 -2
  41. package/templates/deepagent/js/src/index.js +9 -2
  42. package/templates/deepagent/js/src/memory/index.js +2 -0
  43. package/templates/deepagent/js/src/memory/manager.js +21 -10
  44. package/templates/deepagent/js/src/memory/store.js +7 -0
  45. package/templates/deepagent/js/src/middleware/approval.js +6 -1
  46. package/templates/deepagent/js/src/middleware/context.js +5 -0
  47. package/templates/deepagent/js/src/middleware/logging.js +47 -43
  48. package/templates/deepagent/js/src/middleware/security.js +7 -0
  49. package/templates/deepagent/js/src/model/config.js +38 -0
  50. package/templates/deepagent/js/src/model/index.js +9 -0
  51. package/templates/deepagent/js/src/model/openai-compatible.js +18 -0
  52. package/templates/deepagent/js/src/model/presets.js +71 -0
  53. package/templates/deepagent/js/src/sandbox/config.js +12 -0
  54. package/templates/deepagent/js/src/sandbox/index.js +3 -0
  55. package/templates/deepagent/js/src/sandbox/manager.js +161 -0
  56. package/templates/deepagent/js/src/sandbox/opensandbox.js +195 -0
  57. package/templates/deepagent/js/src/schemas/agent.js +7 -0
  58. package/templates/deepagent/js/src/schemas/common.js +5 -0
  59. package/templates/deepagent/js/src/schemas/locale.js +1 -0
  60. package/templates/deepagent/js/src/schemas/session.js +4 -0
  61. package/templates/deepagent/js/src/services/{agent.service.js → agent.js} +39 -20
  62. package/templates/deepagent/js/src/services/{memory.service.js → memory.js} +13 -7
  63. package/templates/deepagent/js/src/services/{session.service.js → session.js} +43 -17
  64. package/templates/deepagent/js/src/skills/index.js +4 -0
  65. package/templates/deepagent/js/src/skills/loader.js +20 -10
  66. package/templates/deepagent/js/src/storage/database/client.js +57 -0
  67. package/templates/deepagent/{ts/src/infrastructure → js/src/storage}/database/migrations/001_init.sql +1 -1
  68. package/templates/deepagent/js/src/{infrastructure → storage}/logger/index.js +2 -0
  69. package/templates/deepagent/js/src/{infrastructure → storage}/redis/client.js +25 -19
  70. package/templates/deepagent/js/src/{infrastructure → storage}/shutdown/index.js +20 -13
  71. package/templates/deepagent/js/src/tools/database/index.js +1 -1
  72. package/templates/deepagent/js/src/tools/database/query.js +44 -32
  73. package/templates/deepagent/js/src/tools/filesystem/index.js +16 -0
  74. package/templates/deepagent/js/src/tools/index.js +6 -11
  75. package/templates/deepagent/js/src/tools/mcp/client.js +7 -0
  76. package/templates/deepagent/js/src/tools/mcp/connections.js +13 -3
  77. package/templates/deepagent/js/src/tools/mcp/index.js +2 -0
  78. package/templates/deepagent/js/src/tools/mcp/registry.js +15 -11
  79. package/templates/deepagent/js/src/utils/errors.js +9 -0
  80. package/templates/deepagent/js/src/utils/helpers.js +15 -0
  81. package/templates/deepagent/js/src/utils/validation.js +15 -0
  82. package/templates/deepagent/js/tests/agents/prompts.test.js +9 -3
  83. package/templates/deepagent/js/tests/agents/supervisor.test.js +13 -5
  84. package/templates/deepagent/js/tests/config/database.test.js +40 -0
  85. package/templates/deepagent/js/tests/integration/api.test.js +18 -3
  86. package/templates/deepagent/js/tests/middleware/security.test.js +4 -1
  87. package/templates/deepagent/js/tests/model/config.test.js +61 -0
  88. package/templates/deepagent/js/tests/sandbox/config.test.js +46 -0
  89. package/templates/deepagent/js/tests/sandbox/manager.test.js +236 -0
  90. package/templates/deepagent/js/tests/sandbox/opensandbox.test.js +173 -0
  91. package/templates/deepagent/js/tests/services/session.test.js +41 -0
  92. package/templates/deepagent/js/tests/tools/query.test.js +5 -1
  93. package/templates/deepagent/shared/README.md +101 -14
  94. package/templates/deepagent/shared/_env.example +40 -10
  95. package/templates/deepagent/shared/deployment/docker-compose.yml +8 -4
  96. package/templates/deepagent/shared/resources/AGENTS.md +1 -1
  97. package/templates/deepagent/ts/scripts/check.ts +19 -11
  98. package/templates/deepagent/ts/scripts/copy-assets.ts +2 -0
  99. package/templates/deepagent/ts/src/agents/factory.ts +1 -1
  100. package/templates/deepagent/ts/src/agents/prompts/loader.ts +1 -0
  101. package/templates/deepagent/ts/src/agents/prompts/supervisor.md +1 -2
  102. package/templates/deepagent/ts/src/agents/prompts/supervisor.ts +1 -1
  103. package/templates/deepagent/ts/src/agents/subagents/analyst.ts +7 -3
  104. package/templates/deepagent/ts/src/agents/subagents/index.ts +4 -5
  105. package/templates/deepagent/ts/src/agents/supervisor.ts +11 -9
  106. package/templates/deepagent/ts/src/api/app.ts +4 -4
  107. package/templates/deepagent/ts/src/api/middleware/auth.ts +1 -0
  108. package/templates/deepagent/ts/src/api/middleware/error.ts +1 -1
  109. package/templates/deepagent/ts/src/api/routes/agent.ts +13 -58
  110. package/templates/deepagent/ts/src/api/routes/health.ts +5 -3
  111. package/templates/deepagent/ts/src/api/routes/session.ts +21 -51
  112. package/templates/deepagent/ts/src/app.ts +19 -12
  113. package/templates/deepagent/ts/src/backends/index.ts +41 -7
  114. package/templates/deepagent/ts/src/backends/sandbox.ts +1 -0
  115. package/templates/deepagent/ts/src/config/database.ts +21 -0
  116. package/templates/deepagent/ts/src/config/env.ts +32 -28
  117. package/templates/deepagent/ts/src/config/index.ts +12 -4
  118. package/templates/deepagent/ts/src/graph/checkpointer.ts +5 -2
  119. package/templates/deepagent/ts/src/graph/store.ts +5 -2
  120. package/templates/deepagent/ts/src/index.ts +2 -2
  121. package/templates/deepagent/ts/src/memory/manager.ts +12 -10
  122. package/templates/deepagent/ts/src/memory/store.ts +2 -0
  123. package/templates/deepagent/ts/src/middleware/approval.ts +2 -2
  124. package/templates/deepagent/ts/src/middleware/logging.ts +43 -44
  125. package/templates/deepagent/ts/src/middleware/security.ts +1 -0
  126. package/templates/deepagent/ts/src/model/config.ts +56 -0
  127. package/templates/deepagent/ts/src/model/index.ts +14 -0
  128. package/templates/deepagent/ts/src/model/openai-compatible.ts +21 -0
  129. package/templates/deepagent/ts/src/model/presets.ts +82 -0
  130. package/templates/deepagent/ts/src/sandbox/config.ts +30 -0
  131. package/templates/deepagent/ts/src/sandbox/index.ts +7 -0
  132. package/templates/deepagent/ts/src/sandbox/manager.ts +176 -0
  133. package/templates/deepagent/ts/src/sandbox/opensandbox.ts +216 -0
  134. package/templates/deepagent/ts/src/services/{agent.service.ts → agent.ts} +22 -22
  135. package/templates/deepagent/ts/src/services/{memory.service.ts → memory.ts} +7 -7
  136. package/templates/deepagent/ts/src/services/{session.service.ts → session.ts} +29 -19
  137. package/templates/deepagent/ts/src/skills/loader.ts +6 -10
  138. package/templates/deepagent/ts/src/storage/database/client.ts +65 -0
  139. package/templates/deepagent/{js/src/infrastructure → ts/src/storage}/database/migrations/001_init.sql +1 -1
  140. package/templates/deepagent/ts/src/{infrastructure → storage}/redis/client.ts +14 -21
  141. package/templates/deepagent/ts/src/{infrastructure → storage}/shutdown/index.ts +10 -13
  142. package/templates/deepagent/ts/src/tools/database/index.ts +5 -1
  143. package/templates/deepagent/ts/src/tools/database/query.ts +40 -32
  144. package/templates/deepagent/ts/src/tools/filesystem/index.ts +2 -0
  145. package/templates/deepagent/ts/src/tools/index.ts +10 -8
  146. package/templates/deepagent/ts/src/tools/mcp/client.ts +1 -0
  147. package/templates/deepagent/ts/src/tools/mcp/connections.ts +3 -3
  148. package/templates/deepagent/ts/src/tools/mcp/registry.ts +9 -12
  149. package/templates/deepagent/ts/src/utils/helpers.ts +5 -0
  150. package/templates/deepagent/ts/src/utils/validation.ts +17 -0
  151. package/templates/deepagent/ts/tests/agents/prompts.test.ts +3 -3
  152. package/templates/deepagent/ts/tests/agents/supervisor.test.ts +5 -5
  153. package/templates/deepagent/ts/tests/config/database.test.ts +40 -0
  154. package/templates/deepagent/ts/tests/integration/api.test.ts +5 -6
  155. package/templates/deepagent/ts/tests/middleware/security.test.ts +1 -1
  156. package/templates/deepagent/ts/tests/model/config.test.ts +61 -0
  157. package/templates/deepagent/ts/tests/sandbox/config.test.ts +46 -0
  158. package/templates/deepagent/ts/tests/sandbox/manager.test.ts +241 -0
  159. package/templates/deepagent/ts/tests/sandbox/opensandbox.test.ts +188 -0
  160. package/templates/deepagent/ts/tests/services/session.test.ts +45 -0
  161. package/templates/deepagent/ts/tests/tools/query.test.ts +1 -1
  162. package/templates/deepagent/js/src/agents/prompts/subagents/researcher.md +0 -16
  163. package/templates/deepagent/js/src/agents/subagents/researcher.js +0 -12
  164. package/templates/deepagent/js/src/config/model.js +0 -34
  165. package/templates/deepagent/js/src/infrastructure/database/client.js +0 -43
  166. package/templates/deepagent/js/src/tools/search/index.js +0 -1
  167. package/templates/deepagent/js/src/tools/search/web-search.js +0 -54
  168. package/templates/deepagent/shared/skills/research/SKILL.md +0 -31
  169. package/templates/deepagent/ts/src/agents/prompts/subagents/researcher.md +0 -16
  170. package/templates/deepagent/ts/src/agents/subagents/researcher.ts +0 -15
  171. package/templates/deepagent/ts/src/config/model.ts +0 -49
  172. package/templates/deepagent/ts/src/infrastructure/database/client.ts +0 -61
  173. package/templates/deepagent/ts/src/tools/search/index.ts +0 -1
  174. package/templates/deepagent/ts/src/tools/search/web-search.ts +0 -82
  175. /package/templates/deepagent/ts/src/{infrastructure → storage}/logger/index.ts +0 -0
@@ -1,16 +0,0 @@
1
- 你是 researcher(研究)子 Agent。你负责收集可验证的信息,并整理成主 Agent 可信赖的笔记。
2
-
3
- ## 工作流程
4
-
5
- 1. 把问题拆成 2-5 个具体的子问题。
6
- 2. 使用 `web_search` 搜索。优先选择一手来源(官方文档、论文、源码),而不是聚合站点。
7
- 3. 阅读最有价值的来源,只提取能回答子问题的事实。
8
- 4. 把笔记写入 `/workspace/research/<主题>.md`,包含简短摘要和来源列表。
9
- 5. 返回摘要和文件路径。
10
-
11
- ## 规则
12
-
13
- - 每个事实性结论都必须附 URL。无法验证的来源要明确说明。
14
- - 时间敏感的信息要记录发布日期,并标注可能过时的内容。
15
- - 控制引用篇幅,不要大段复制原文。
16
- - 搜索工具不可用时明确说明,并标注所给信息为“未经验证”。
@@ -1,15 +0,0 @@
1
- import type { SubAgent } from "deepagents";
2
-
3
- import { webSearchTool } from "../../tools/search/index.js";
4
- import { loadPrompt } from "../prompts/index.js";
5
-
6
- export const createResearcherSubagent = (): SubAgent => {
7
- return {
8
- name: "researcher",
9
- description:
10
- "从网络收集可验证的信息,阅读来源,并把带引用的研究笔记写入 /workspace/research/。",
11
- systemPrompt: loadPrompt("subagents/researcher"),
12
- tools: [webSearchTool],
13
- skills: ["/skills/research/"],
14
- };
15
- };
@@ -1,49 +0,0 @@
1
- import { ChatAnthropic } from "@langchain/anthropic";
2
- import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
3
- import { ChatOpenAI } from "@langchain/openai";
4
-
5
- import type { Env } from "./env.js";
6
-
7
- export interface ModelConfig {
8
- provider: "openai" | "anthropic";
9
- name: string;
10
- temperature: number;
11
- maxTokens: number;
12
- baseUrl?: string;
13
- }
14
-
15
- export const DEFAULT_MODELS = {
16
- openai: "gpt-4.1-mini",
17
- anthropic: "claude-sonnet-4-5",
18
- } as const;
19
-
20
- export const resolveModelConfig = (env: Env): ModelConfig => {
21
- return {
22
- provider: env.MODEL_PROVIDER,
23
- name: env.MODEL_NAME ?? DEFAULT_MODELS[env.MODEL_PROVIDER],
24
- temperature: env.MODEL_TEMPERATURE,
25
- maxTokens: env.MODEL_MAX_TOKENS,
26
- ...(env.OPENAI_BASE_URL ? { baseUrl: env.OPENAI_BASE_URL } : {}),
27
- };
28
- };
29
-
30
- /**
31
- * 构建主 Agent 和所有子 Agent 共用的聊天模型。
32
- * 要接入其他提供商(Bedrock、Vertex、Ollama 等),替换此函数即可。
33
- */
34
- export const createChatModel = (config: ModelConfig): BaseChatModel => {
35
- if (config.provider === "anthropic") {
36
- return new ChatAnthropic({
37
- model: config.name,
38
- temperature: config.temperature,
39
- maxTokens: config.maxTokens,
40
- });
41
- }
42
-
43
- return new ChatOpenAI({
44
- model: config.name,
45
- temperature: config.temperature,
46
- maxTokens: config.maxTokens,
47
- ...(config.baseUrl ? { configuration: { baseURL: config.baseUrl } } : {}),
48
- });
49
- };
@@ -1,61 +0,0 @@
1
- import { performance } from "node:perf_hooks";
2
-
3
- import { Pool, type PoolClient } from "pg";
4
-
5
- import { ConfigurationError } from "../../utils/errors.js";
6
-
7
- let pool: Pool | undefined;
8
-
9
- /** 懒加载共享的 PostgreSQL 连接池。 */
10
- export const getPool = (connectionString = process.env.DATABASE_URL): Pool => {
11
- if (!connectionString) {
12
- throw new ConfigurationError("未配置 DATABASE_URL。请先在 .env 中设置后再使用数据库功能。");
13
- }
14
-
15
- pool ??= new Pool({
16
- connectionString,
17
- max: 10,
18
- idleTimeoutMillis: 30_000,
19
- connectionTimeoutMillis: 5_000,
20
- });
21
-
22
- return pool;
23
- };
24
-
25
- export interface DatabaseHealth {
26
- ok: boolean;
27
- latencyMs?: number;
28
- error?: string;
29
- }
30
-
31
- export const checkDatabase = async (): Promise<DatabaseHealth> => {
32
- if (!process.env.DATABASE_URL) {
33
- return { ok: false, error: "未配置 DATABASE_URL" };
34
- }
35
-
36
- const startedAt = performance.now();
37
-
38
- try {
39
- const client: PoolClient = await getPool().connect();
40
- try {
41
- await client.query("select 1");
42
- } finally {
43
- client.release();
44
- }
45
-
46
- return { ok: true, latencyMs: Math.round(performance.now() - startedAt) };
47
- } catch (error) {
48
- return {
49
- ok: false,
50
- error: error instanceof Error ? error.message : String(error),
51
- };
52
- }
53
- };
54
-
55
- export const closeDatabase = async (): Promise<void> => {
56
- if (!pool) return;
57
-
58
- const current = pool;
59
- pool = undefined;
60
- await current.end();
61
- };
@@ -1 +0,0 @@
1
- export { createWebSearchTool, webSearchTool, type WebSearchToolOptions } from "./web-search.js";
@@ -1,82 +0,0 @@
1
- import { tool } from "@langchain/core/tools";
2
- import { z } from "zod";
3
-
4
- const TAVILY_ENDPOINT = "https://api.tavily.com/search";
5
-
6
- interface TavilyResult {
7
- title?: string;
8
- url?: string;
9
- content?: string;
10
- score?: number;
11
- }
12
-
13
- interface TavilyResponse {
14
- answer?: string;
15
- results?: TavilyResult[];
16
- }
17
-
18
- export interface WebSearchToolOptions {
19
- apiKey?: string;
20
- maxResults?: number;
21
- }
22
-
23
- const webSearchSchema = z.object({
24
- query: z.string().min(2).describe("搜索关键词。"),
25
- maxResults: z.number().int().min(1).max(10).default(5).describe("返回结果数量(1-10)。"),
26
- });
27
-
28
- /**
29
- * 基于 Tavily 的 Web 搜索。API Key 延迟读取,因此即使未配置搜索也能注册
30
- * 该工具;真正调用时会返回清晰错误,供模型报告。
31
- */
32
- export const createWebSearchTool = ({
33
- apiKey,
34
- maxResults: defaultMaxResults = 5,
35
- }: WebSearchToolOptions = {}) => {
36
- return tool(
37
- async ({ query, maxResults }: z.infer<typeof webSearchSchema>) => {
38
- const key = apiKey ?? process.env.TAVILY_API_KEY;
39
- if (!key) {
40
- throw new Error("未设置 TAVILY_API_KEY。请在 .env 中添加后启用 Web 搜索。");
41
- }
42
-
43
- const response = await fetch(TAVILY_ENDPOINT, {
44
- method: "POST",
45
- headers: { "content-type": "application/json" },
46
- body: JSON.stringify({
47
- api_key: key,
48
- query,
49
- max_results: Math.min(maxResults ?? defaultMaxResults, 10),
50
- search_depth: "basic",
51
- include_answer: false,
52
- include_raw_content: false,
53
- }),
54
- signal: AbortSignal.timeout(20_000),
55
- });
56
-
57
- if (!response.ok) {
58
- const detail = await response.text().catch(() => "");
59
- throw new Error(
60
- `Web 搜索失败,HTTP ${response.status}${detail ? `:${detail.slice(0, 300)}` : ""}`,
61
- );
62
- }
63
-
64
- const data = (await response.json()) as TavilyResponse;
65
- const results = (data.results ?? []).map((result) => ({
66
- title: result.title ?? "",
67
- url: result.url ?? "",
68
- snippet: result.content ?? "",
69
- score: result.score ?? 0,
70
- }));
71
-
72
- return JSON.stringify({ query, results }, null, 2);
73
- },
74
- {
75
- name: "web_search",
76
- description: "搜索公开网络,返回标题、URL 和摘要。用于获取最新信息,并引用实际使用的来源。",
77
- schema: webSearchSchema,
78
- },
79
- );
80
- };
81
-
82
- export const webSearchTool = createWebSearchTool();