create-deepagent-server 0.0.0-stage → 0.2.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 +292 -2
- package/bin/create-deepagent-server.js +27 -0
- package/package.json +50 -4
- package/src/args.js +195 -0
- package/src/cli.js +269 -0
- package/src/dependencies.js +34 -0
- package/src/prompts.js +86 -0
- package/src/registry.js +68 -0
- package/src/scaffold.js +181 -0
- package/src/setup.js +79 -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 +97 -0
- package/templates/deepagent/js/scripts/dev.js +40 -0
- package/templates/deepagent/js/src/agents/factory.js +11 -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 +53 -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/supervisor.js +21 -0
- package/templates/deepagent/js/src/agents/prompts/supervisor.md +41 -0
- package/templates/deepagent/js/src/agents/state/index.js +1 -0
- package/templates/deepagent/js/src/agents/state/types.js +11 -0
- package/templates/deepagent/js/src/agents/subagents/analyst.js +12 -0
- package/templates/deepagent/js/src/agents/subagents/coder.js +12 -0
- package/templates/deepagent/js/src/agents/subagents/index.js +9 -0
- package/templates/deepagent/js/src/agents/supervisor.js +64 -0
- package/templates/deepagent/js/src/api/app.js +29 -0
- package/templates/deepagent/js/src/api/middleware/auth.js +36 -0
- package/templates/deepagent/js/src/api/middleware/error.js +30 -0
- package/templates/deepagent/js/src/api/routes/agent.js +43 -0
- package/templates/deepagent/js/src/api/routes/health.js +40 -0
- package/templates/deepagent/js/src/api/routes/session.js +42 -0
- package/templates/deepagent/js/src/app.js +98 -0
- package/templates/deepagent/js/src/backends/composite.js +22 -0
- package/templates/deepagent/js/src/backends/filesystem.js +9 -0
- package/templates/deepagent/js/src/backends/index.js +60 -0
- package/templates/deepagent/js/src/backends/sandbox.js +26 -0
- package/templates/deepagent/js/src/config/agent.js +14 -0
- package/templates/deepagent/js/src/config/database.js +19 -0
- package/templates/deepagent/js/src/config/env.js +96 -0
- package/templates/deepagent/js/src/config/index.js +45 -0
- package/templates/deepagent/js/src/graph/checkpointer.js +28 -0
- package/templates/deepagent/js/src/graph/compile.js +9 -0
- package/templates/deepagent/js/src/graph/index.js +3 -0
- package/templates/deepagent/js/src/graph/store.js +28 -0
- package/templates/deepagent/js/src/index.js +39 -0
- package/templates/deepagent/js/src/memory/index.js +8 -0
- package/templates/deepagent/js/src/memory/manager.js +50 -0
- package/templates/deepagent/js/src/memory/store.js +43 -0
- package/templates/deepagent/js/src/middleware/approval.js +47 -0
- package/templates/deepagent/js/src/middleware/context.js +35 -0
- package/templates/deepagent/js/src/middleware/index.js +9 -0
- package/templates/deepagent/js/src/middleware/logging.js +70 -0
- package/templates/deepagent/js/src/middleware/security.js +58 -0
- package/templates/deepagent/js/src/model/config.js +38 -0
- package/templates/deepagent/js/src/model/index.js +9 -0
- package/templates/deepagent/js/src/model/openai-compatible.js +18 -0
- package/templates/deepagent/js/src/model/presets.js +71 -0
- package/templates/deepagent/js/src/sandbox/config.js +12 -0
- package/templates/deepagent/js/src/sandbox/index.js +3 -0
- package/templates/deepagent/js/src/sandbox/manager.js +161 -0
- package/templates/deepagent/js/src/sandbox/opensandbox.js +195 -0
- package/templates/deepagent/js/src/schemas/agent.js +40 -0
- package/templates/deepagent/js/src/schemas/common.js +24 -0
- package/templates/deepagent/js/src/schemas/locale.js +4 -0
- package/templates/deepagent/js/src/schemas/session.js +27 -0
- package/templates/deepagent/js/src/services/agent.js +136 -0
- package/templates/deepagent/js/src/services/memory.js +33 -0
- package/templates/deepagent/js/src/services/session.js +118 -0
- package/templates/deepagent/js/src/skills/index.js +21 -0
- package/templates/deepagent/js/src/skills/loader.js +75 -0
- package/templates/deepagent/js/src/storage/database/client.js +57 -0
- package/templates/deepagent/js/src/storage/database/migrations/001_init.sql +20 -0
- package/templates/deepagent/js/src/storage/logger/index.js +21 -0
- package/templates/deepagent/js/src/storage/redis/client.js +51 -0
- package/templates/deepagent/js/src/storage/shutdown/index.js +58 -0
- package/templates/deepagent/js/src/tools/database/index.js +1 -0
- package/templates/deepagent/js/src/tools/database/query.js +74 -0
- package/templates/deepagent/js/src/tools/filesystem/index.js +102 -0
- package/templates/deepagent/js/src/tools/index.js +25 -0
- package/templates/deepagent/js/src/tools/mcp/client.js +42 -0
- package/templates/deepagent/js/src/tools/mcp/connections.js +64 -0
- package/templates/deepagent/js/src/tools/mcp/index.js +10 -0
- package/templates/deepagent/js/src/tools/mcp/registry.js +36 -0
- package/templates/deepagent/js/src/utils/errors.js +73 -0
- package/templates/deepagent/js/src/utils/helpers.js +57 -0
- package/templates/deepagent/js/src/utils/validation.js +15 -0
- package/templates/deepagent/js/tests/agents/prompts.test.js +30 -0
- package/templates/deepagent/js/tests/agents/supervisor.test.js +42 -0
- package/templates/deepagent/js/tests/config/database.test.js +40 -0
- package/templates/deepagent/js/tests/integration/api.test.js +114 -0
- package/templates/deepagent/js/tests/middleware/security.test.js +27 -0
- package/templates/deepagent/js/tests/model/config.test.js +61 -0
- package/templates/deepagent/js/tests/sandbox/config.test.js +46 -0
- package/templates/deepagent/js/tests/sandbox/manager.test.js +236 -0
- package/templates/deepagent/js/tests/sandbox/opensandbox.test.js +173 -0
- package/templates/deepagent/js/tests/services/session.test.js +41 -0
- package/templates/deepagent/js/tests/tools/query.test.js +27 -0
- package/templates/deepagent/shared/README.md +249 -0
- package/templates/deepagent/shared/_editorconfig +12 -0
- package/templates/deepagent/shared/_env.example +86 -0
- package/templates/deepagent/shared/_gitignore +22 -0
- package/templates/deepagent/shared/deployment/docker-compose.yml +60 -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/workspaces/README.md +5 -0
- package/templates/deepagent/ts/deployment/Dockerfile +25 -0
- package/templates/deepagent/ts/scripts/check.ts +99 -0
- package/templates/deepagent/ts/scripts/copy-assets.ts +37 -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 +53 -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/supervisor.md +41 -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 +18 -0
- package/templates/deepagent/ts/src/agents/subagents/coder.ts +14 -0
- package/templates/deepagent/ts/src/agents/subagents/index.ts +9 -0
- package/templates/deepagent/ts/src/agents/supervisor.ts +82 -0
- package/templates/deepagent/ts/src/api/app.ts +48 -0
- package/templates/deepagent/ts/src/api/middleware/auth.ts +38 -0
- package/templates/deepagent/ts/src/api/middleware/error.ts +33 -0
- package/templates/deepagent/ts/src/api/routes/agent.ts +48 -0
- package/templates/deepagent/ts/src/api/routes/health.ts +47 -0
- package/templates/deepagent/ts/src/api/routes/session.ts +47 -0
- package/templates/deepagent/ts/src/app.ts +111 -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 +76 -0
- package/templates/deepagent/ts/src/backends/sandbox.ts +33 -0
- package/templates/deepagent/ts/src/config/agent.ts +37 -0
- package/templates/deepagent/ts/src/config/database.ts +21 -0
- package/templates/deepagent/ts/src/config/env.ts +106 -0
- package/templates/deepagent/ts/src/config/index.ts +84 -0
- package/templates/deepagent/ts/src/graph/checkpointer.ts +29 -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 +29 -0
- package/templates/deepagent/ts/src/index.ts +39 -0
- package/templates/deepagent/ts/src/memory/index.ts +11 -0
- package/templates/deepagent/ts/src/memory/manager.ts +76 -0
- package/templates/deepagent/ts/src/memory/store.ts +59 -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 +71 -0
- package/templates/deepagent/ts/src/middleware/security.ts +61 -0
- package/templates/deepagent/ts/src/model/config.ts +56 -0
- package/templates/deepagent/ts/src/model/index.ts +14 -0
- package/templates/deepagent/ts/src/model/openai-compatible.ts +21 -0
- package/templates/deepagent/ts/src/model/presets.ts +82 -0
- package/templates/deepagent/ts/src/sandbox/config.ts +30 -0
- package/templates/deepagent/ts/src/sandbox/index.ts +7 -0
- package/templates/deepagent/ts/src/sandbox/manager.ts +176 -0
- package/templates/deepagent/ts/src/sandbox/opensandbox.ts +216 -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.ts +170 -0
- package/templates/deepagent/ts/src/services/memory.ts +43 -0
- package/templates/deepagent/ts/src/services/session.ts +158 -0
- package/templates/deepagent/ts/src/skills/index.ts +26 -0
- package/templates/deepagent/ts/src/skills/loader.ts +90 -0
- package/templates/deepagent/ts/src/storage/database/client.ts +65 -0
- package/templates/deepagent/ts/src/storage/database/migrations/001_init.sql +20 -0
- package/templates/deepagent/ts/src/storage/logger/index.ts +25 -0
- package/templates/deepagent/ts/src/storage/redis/client.ts +57 -0
- package/templates/deepagent/ts/src/storage/shutdown/index.ts +82 -0
- package/templates/deepagent/ts/src/tools/database/index.ts +5 -0
- package/templates/deepagent/ts/src/tools/database/query.ts +79 -0
- package/templates/deepagent/ts/src/tools/filesystem/index.ts +110 -0
- package/templates/deepagent/ts/src/tools/index.ts +43 -0
- package/templates/deepagent/ts/src/tools/mcp/client.ts +54 -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 +45 -0
- package/templates/deepagent/ts/src/utils/errors.ts +95 -0
- package/templates/deepagent/ts/src/utils/helpers.ts +57 -0
- package/templates/deepagent/ts/src/utils/validation.ts +17 -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/config/database.test.ts +40 -0
- package/templates/deepagent/ts/tests/integration/api.test.ts +122 -0
- package/templates/deepagent/ts/tests/middleware/security.test.ts +27 -0
- package/templates/deepagent/ts/tests/model/config.test.ts +61 -0
- package/templates/deepagent/ts/tests/sandbox/config.test.ts +46 -0
- package/templates/deepagent/ts/tests/sandbox/manager.test.ts +241 -0
- package/templates/deepagent/ts/tests/sandbox/opensandbox.test.ts +188 -0
- package/templates/deepagent/ts/tests/services/session.test.ts +45 -0
- package/templates/deepagent/ts/tests/tools/query.test.ts +27 -0
- package/templates/deepagent/ts/tsconfig.json +19 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { SandboxApiException } from "@alibaba-group/opensandbox";
|
|
5
|
+
|
|
6
|
+
import { OpenSandboxBackend } from "../../src/sandbox/index.js";
|
|
7
|
+
|
|
8
|
+
const createFakeSandbox = ({ failFirstRun = false } = {}) => {
|
|
9
|
+
const calls = {
|
|
10
|
+
sessions: [],
|
|
11
|
+
run: [],
|
|
12
|
+
deleted: [],
|
|
13
|
+
directories: [],
|
|
14
|
+
writes: [],
|
|
15
|
+
reads: [],
|
|
16
|
+
renewals: [],
|
|
17
|
+
killed: false,
|
|
18
|
+
closed: false,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let created = 0;
|
|
22
|
+
let remainingFailures = failFirstRun ? 1 : 0;
|
|
23
|
+
|
|
24
|
+
const sandbox = {
|
|
25
|
+
id: "sbx-test",
|
|
26
|
+
commands: {
|
|
27
|
+
createSession: async (options) => {
|
|
28
|
+
calls.sessions.push({ workingDirectory: options?.workingDirectory });
|
|
29
|
+
created += 1;
|
|
30
|
+
return `session-${created}`;
|
|
31
|
+
},
|
|
32
|
+
runInSession: async (sessionId, command) => {
|
|
33
|
+
if (remainingFailures > 0) {
|
|
34
|
+
remainingFailures -= 1;
|
|
35
|
+
throw new SandboxApiException({ statusCode: 404, message: "session not found" });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
calls.run.push({ sessionId, command });
|
|
39
|
+
return {
|
|
40
|
+
logs: {
|
|
41
|
+
stdout: [{ text: "hello", timestamp: 0 }],
|
|
42
|
+
stderr: [{ text: "boom", timestamp: 0 }],
|
|
43
|
+
},
|
|
44
|
+
exitCode: 0,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
deleteSession: async (sessionId) => {
|
|
48
|
+
calls.deleted.push(sessionId);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
files: {
|
|
52
|
+
createDirectories: async (entries) => {
|
|
53
|
+
calls.directories.push(...entries.map((entry) => entry.path));
|
|
54
|
+
},
|
|
55
|
+
writeFiles: async (entries) => {
|
|
56
|
+
calls.writes.push(...entries.map((entry) => entry.path));
|
|
57
|
+
},
|
|
58
|
+
readBytes: async (path) => {
|
|
59
|
+
calls.reads.push(path);
|
|
60
|
+
return new Uint8Array([104, 105]);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
renew: async (timeoutSeconds) => {
|
|
64
|
+
calls.renewals.push(timeoutSeconds);
|
|
65
|
+
},
|
|
66
|
+
kill: async () => {
|
|
67
|
+
calls.killed = true;
|
|
68
|
+
},
|
|
69
|
+
close: async () => {
|
|
70
|
+
calls.closed = true;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return { sandbox, calls };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
test("execute 在持久 session 中组合 stdout/stderr", async () => {
|
|
78
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
79
|
+
const backend = new OpenSandboxBackend({ sandbox, workspaceRoot: "/workspace" });
|
|
80
|
+
|
|
81
|
+
const result = await backend.execute("echo hello");
|
|
82
|
+
|
|
83
|
+
assert.equal(result.output, "hello\n[stderr] boom");
|
|
84
|
+
assert.equal(result.exitCode, 0);
|
|
85
|
+
assert.equal(result.truncated, false);
|
|
86
|
+
assert.deepEqual(calls.sessions, [{ workingDirectory: "/workspace" }]);
|
|
87
|
+
assert.deepEqual(calls.run, [{ sessionId: "session-1", command: "echo hello" }]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("连续命令复用同一个 session,并按顺序执行", async () => {
|
|
91
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
92
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
93
|
+
|
|
94
|
+
await backend.execute("cd /tmp");
|
|
95
|
+
await backend.execute("pwd");
|
|
96
|
+
await Promise.all([backend.execute("echo a"), backend.execute("echo b")]);
|
|
97
|
+
|
|
98
|
+
assert.equal(calls.sessions.length, 1);
|
|
99
|
+
assert.deepEqual(
|
|
100
|
+
calls.run.map(({ sessionId }) => sessionId),
|
|
101
|
+
["session-1", "session-1", "session-1", "session-1"],
|
|
102
|
+
);
|
|
103
|
+
assert.deepEqual(
|
|
104
|
+
calls.run.map(({ command }) => command),
|
|
105
|
+
["cd /tmp", "pwd", "echo a", "echo b"],
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("session 失效时重建并重试一次", async () => {
|
|
110
|
+
const { sandbox, calls } = createFakeSandbox({ failFirstRun: true });
|
|
111
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
112
|
+
|
|
113
|
+
const result = await backend.execute("echo hello");
|
|
114
|
+
|
|
115
|
+
assert.equal(result.exitCode, 0);
|
|
116
|
+
assert.equal(calls.sessions.length, 2);
|
|
117
|
+
assert.deepEqual(calls.run, [{ sessionId: "session-2", command: "echo hello" }]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("renew 向服务端续期 TTL", async () => {
|
|
121
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
122
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
123
|
+
|
|
124
|
+
await backend.renew(1800);
|
|
125
|
+
|
|
126
|
+
assert.deepEqual(calls.renewals, [1800]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("uploadFiles 先创建父目录再写入文件", async () => {
|
|
130
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
131
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
132
|
+
|
|
133
|
+
const result = await backend.uploadFiles([
|
|
134
|
+
["/workspace/notes/today.md", new Uint8Array([35, 32])],
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
assert.deepEqual(result, [{ path: "/workspace/notes/today.md", error: null }]);
|
|
138
|
+
assert.deepEqual(calls.directories, ["/workspace/notes"]);
|
|
139
|
+
assert.deepEqual(calls.writes, ["/workspace/notes/today.md"]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("downloadFiles 返回文件字节", async () => {
|
|
143
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
144
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
145
|
+
|
|
146
|
+
const result = await backend.downloadFiles(["/workspace/notes/today.md"]);
|
|
147
|
+
|
|
148
|
+
assert.deepEqual(calls.reads, ["/workspace/notes/today.md"]);
|
|
149
|
+
assert.equal(result[0]?.error, null);
|
|
150
|
+
assert.deepEqual(result[0]?.content, new Uint8Array([104, 105]));
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("destroy 删除 session、终止自建沙箱并关闭连接", async () => {
|
|
154
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
155
|
+
const backend = new OpenSandboxBackend({ sandbox });
|
|
156
|
+
|
|
157
|
+
await backend.execute("echo hello");
|
|
158
|
+
await backend.destroy();
|
|
159
|
+
|
|
160
|
+
assert.deepEqual(calls.deleted, ["session-1"]);
|
|
161
|
+
assert.equal(calls.killed, true);
|
|
162
|
+
assert.equal(calls.closed, true);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("复用已有沙箱时只关闭连接,不 kill", async () => {
|
|
166
|
+
const { sandbox, calls } = createFakeSandbox();
|
|
167
|
+
const backend = new OpenSandboxBackend({ sandbox, owned: false });
|
|
168
|
+
|
|
169
|
+
await backend.destroy();
|
|
170
|
+
|
|
171
|
+
assert.equal(calls.killed, false);
|
|
172
|
+
assert.equal(calls.closed, true);
|
|
173
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { SessionService } from "../../src/services/session.js";
|
|
5
|
+
|
|
6
|
+
test("删除会话时释放对应沙箱", async () => {
|
|
7
|
+
const deletedThreads = [];
|
|
8
|
+
const deletedKeys = [];
|
|
9
|
+
const released = [];
|
|
10
|
+
|
|
11
|
+
const checkpointer = {
|
|
12
|
+
deleteThread: async (threadId) => {
|
|
13
|
+
deletedThreads.push(threadId);
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const store = {
|
|
18
|
+
delete: async (key, value) => {
|
|
19
|
+
deletedKeys.push([key, value]);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const sandboxes = {
|
|
24
|
+
release: async (threadId) => {
|
|
25
|
+
released.push(threadId);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const service = new SessionService({
|
|
30
|
+
graph: {},
|
|
31
|
+
checkpointer,
|
|
32
|
+
store,
|
|
33
|
+
sandboxes,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await service.remove("thread-1", "tenant-1");
|
|
37
|
+
|
|
38
|
+
assert.deepEqual(deletedThreads, ["thread-1"]);
|
|
39
|
+
assert.deepEqual(deletedKeys, [[["sessions", "tenant-1"], "thread-1"]]);
|
|
40
|
+
assert.deepEqual(released, ["thread-1"]);
|
|
41
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { assertReadOnlyQuery } from "../../src/tools/database/index.js";
|
|
5
|
+
|
|
6
|
+
test("接受 SELECT 与 WITH 语句", () => {
|
|
7
|
+
assert.doesNotThrow(() => assertReadOnlyQuery("select id, name from users"));
|
|
8
|
+
assert.doesNotThrow(() =>
|
|
9
|
+
assertReadOnlyQuery("with recent as (select * from events) select count(*) from recent"),
|
|
10
|
+
);
|
|
11
|
+
assert.doesNotThrow(() => assertReadOnlyQuery("select 1;"));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("拒绝写入与 DDL", () => {
|
|
15
|
+
for (const sql of [
|
|
16
|
+
"delete from users",
|
|
17
|
+
"update users set admin = true",
|
|
18
|
+
"drop table users",
|
|
19
|
+
"insert into users values (1)",
|
|
20
|
+
]) {
|
|
21
|
+
assert.throws(() => assertReadOnlyQuery(sql));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("拒绝多条语句拼接", () => {
|
|
26
|
+
assert.throws(() => assertReadOnlyQuery("select 1; delete from users"), /只允许单条 SQL 语句/);
|
|
27
|
+
});
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# __PROJECT_NAME__
|
|
2
|
+
|
|
3
|
+
一个面向生产的 [Deep Agents](https://docs.langchain.com/oss/javascript/deepagents/overview) 项目:主 Agent 加专职子 Agent、挂载式文件系统、长期记忆、Skills、MCP 工具以及 HTTP API。
|
|
4
|
+
|
|
5
|
+
- 仅使用 ESM、现代 ES6+ 语法,Node.js 22.6+
|
|
6
|
+
- 默认 JavaScript,可选 TypeScript
|
|
7
|
+
- 模型统一走 OpenAI 兼容协议,默认 MiniMax M3;改环境变量即可切换 OpenAI / DeepSeek / Kimi / MiniMax / 通义千问 / 智谱 / OpenRouter / vLLM / Ollama
|
|
8
|
+
- 可选 OpenSandbox 远程沙箱:`SANDBOX_ENABLED=true` 时 `execute` 与 `/workspace/` 都落在隔离环境中
|
|
9
|
+
- LangGraph checkpointer + store(默认内存,可切换 PostgreSQL)
|
|
10
|
+
- Express 5 API:Bearer 鉴权、SSE 流式输出、结构化日志
|
|
11
|
+
|
|
12
|
+
## 快速开始
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
cp .env.example .env # 填入 MODEL_API_KEY(示例默认 MiniMax M3)
|
|
16
|
+
npm run check # 可选:启动前环境检查
|
|
17
|
+
npm run dev # http://localhost:3000/health
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
在终端里直接和 Agent 对话:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm run agent
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
通过 HTTP 调用:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
curl -X POST http://localhost:3000/api/agents/invoke \
|
|
30
|
+
-H 'content-type: application/json' \
|
|
31
|
+
-d '{"message":"调研 Deep Agents,并把摘要写到 /workspace/summary.md"}'
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 脚本
|
|
35
|
+
|
|
36
|
+
| 脚本 | 说明 |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `npm run dev` | 启动 API 并监听文件变化 |
|
|
39
|
+
| `npm start` | 启动 API(TypeScript 项目运行 `dist/`,需先构建) |
|
|
40
|
+
| `npm run agent` | 与主 Agent 进行交互式终端会话 |
|
|
41
|
+
| `npm run check` | 预检:模型凭证、目录、Skills、PostgreSQL/Redis |
|
|
42
|
+
| `npm test` | 单元测试与 HTTP 集成测试 |
|
|
43
|
+
| `npm run build` | 编译 TypeScript 并复制提示词/SQL 资源(仅 TypeScript) |
|
|
44
|
+
| `npm run typecheck` | 只做类型检查,不产出文件(仅 TypeScript) |
|
|
45
|
+
|
|
46
|
+
## 目录结构
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
src/
|
|
50
|
+
├── index.ts|js 入口:配置 → 应用 → HTTP 服务
|
|
51
|
+
├── app.ts 应用装配(测试和脚本复用同一套装配)
|
|
52
|
+
├── config/ 环境变量与 Agent 配置
|
|
53
|
+
├── model/ 模型配置:OpenAI 兼容接入、服务商预设
|
|
54
|
+
├── agents/ 主 Agent、子 Agent、提示词、自定义状态
|
|
55
|
+
├── tools/ 只读 SQL、工作区文件、MCP
|
|
56
|
+
├── middleware/ 日志、安全、审批、运行时上下文
|
|
57
|
+
├── backends/ 文件系统 / 沙箱 / 组合后端
|
|
58
|
+
├── sandbox/ OpenSandbox 远程沙箱(可选执行后端)
|
|
59
|
+
├── memory/ 长期记忆(BaseStore)封装
|
|
60
|
+
├── skills/ SKILL.md 发现与校验
|
|
61
|
+
├── graph/ createDeepAgent 编译、checkpointer、store
|
|
62
|
+
├── services/ Agent、会话、记忆服务
|
|
63
|
+
├── api/ Express 应用、路由与中间件
|
|
64
|
+
├── schemas/ Zod 请求/响应结构
|
|
65
|
+
├── storage/ PostgreSQL、Redis、pino 日志、优雅关闭
|
|
66
|
+
└── utils/
|
|
67
|
+
resources/ AGENTS.md + 知识库,挂载到 /resources/
|
|
68
|
+
skills/ SKILL.md,挂载到 /skills/
|
|
69
|
+
workspaces/ Agent 可写工作区,挂载到 /workspace/
|
|
70
|
+
tests/ 单元测试 + 集成测试
|
|
71
|
+
scripts/ 交互终端与预检脚本
|
|
72
|
+
deployment/ Dockerfile + docker-compose
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Agent 是如何装配的
|
|
76
|
+
|
|
77
|
+
`src/app.ts` 通过 `createSupervisorAgent` 构建一个主 Agent:
|
|
78
|
+
|
|
79
|
+
- **模型** —— `src/model/`:`resolveModelConfig()` 解析环境变量,`createChatModel()` 用 `ChatOpenAI` 指向任意 OpenAI 兼容地址,整个进程共用一个实例。服务商预设见 `src/model/presets`。
|
|
80
|
+
- **后端** —— `src/backends/composite.ts` 把 `/workspace/`、`/resources/`、`/skills/` 挂载到磁盘,把 `/memories/` 挂载到 LangGraph store。`ENABLE_SHELL=true` 时默认后端切换为 `LocalShellBackend` 并暴露 `execute`;`SANDBOX_ENABLED=true` 时后端按 `threadId` 切换为对应会话的 OpenSandbox,`/workspace/` 与 `execute` 都落在该会话的远程沙箱内。
|
|
81
|
+
- **子 Agent** —— `coder`(工作区改代码)、`analyst`(只读 SQL)。它们都是声明式 `SubAgent`,各自拥有独立上下文窗口。
|
|
82
|
+
- **提示词** —— `src/agents/prompts/` 下的纯 Markdown。`loadPrompt()` 读取文件,`renderPrompt()` 填充 `{{占位符}}`;TypeScript 项目构建时会把 `.md` 复制到 `dist/`。提示词在 Agent 构建时读取,修改后需重启 dev server。
|
|
83
|
+
- **中间件** —— 调用日志、危险工具拦截、按请求注入租户/用户上下文。
|
|
84
|
+
- **审批** —— `APPROVAL_MODE=sensitive`(默认)会通过 `interruptOn` 暂停有副作用的工具。中断响应包含 `interrupts`,用同一个 `threadId` 调用 `POST /api/agents/resume` 批准后继续。
|
|
85
|
+
- **记忆** —— 启动时注入 `/resources/AGENTS.md`;`/memories/` 和 `MemoryManager` 用于持久化长期事实。
|
|
86
|
+
|
|
87
|
+
## API
|
|
88
|
+
|
|
89
|
+
| 方法 | 路径 | 用途 |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| `GET` | `/health` | 存活检查(公开) |
|
|
92
|
+
| `GET` | `/health/ready` | PostgreSQL / Redis / MCP 就绪检查 |
|
|
93
|
+
| `POST` | `/api/agents/invoke` | 在指定会话中运行主 Agent |
|
|
94
|
+
| `POST` | `/api/agents/stream` | 以 SSE 流式返回 Agent 状态快照 |
|
|
95
|
+
| `POST` | `/api/agents/resume` | 恢复被审批中断的运行 |
|
|
96
|
+
| `POST` | `/api/sessions` | 创建会话记录 |
|
|
97
|
+
| `GET` | `/api/sessions?tenantId=default` | 会话列表 |
|
|
98
|
+
| `GET` | `/api/sessions/:threadId` | 会话元数据与消息数 |
|
|
99
|
+
| `GET` | `/api/sessions/:threadId/messages` | 会话历史 |
|
|
100
|
+
| `DELETE` | `/api/sessions/:threadId` | 删除会话 |
|
|
101
|
+
|
|
102
|
+
设置 `AGENT_API_KEY` 后,`/api/*` 需要携带 `Authorization: Bearer <key>`。
|
|
103
|
+
|
|
104
|
+
批准一次中断:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
curl -X POST http://localhost:3000/api/agents/resume \
|
|
108
|
+
-H 'content-type: application/json' \
|
|
109
|
+
-d '{"threadId":"<thread-id>","decisions":[{"type":"approve"}]}'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
SSE 流式调用:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
curl -N -X POST http://localhost:3000/api/agents/stream \
|
|
116
|
+
-H 'content-type: application/json' \
|
|
117
|
+
-d '{"message":"规划一份上线检查清单"}'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 配置
|
|
121
|
+
|
|
122
|
+
所有环境变量都在 `src/config/env.ts` 中校验,完整列表见 `.env.example`。常用项:
|
|
123
|
+
|
|
124
|
+
| 变量 | 默认值 | 说明 |
|
|
125
|
+
| --- | --- | --- |
|
|
126
|
+
| `MODEL_PROVIDER` | `minimax` | 预设地址:`openai`、`deepseek`、`moonshot`、`minimax`、`qwen`、`zhipu`、`openrouter`、`ollama`、`vllm`、`custom` |
|
|
127
|
+
| `MODEL_NAME` | 按预设选择 | 模型名,默认 `MiniMax-M3`;切换服务商时同步修改 |
|
|
128
|
+
| `MODEL_MAX_COMPLETION_TOKENS` | `32768` | 生成上限(含思考 token);M3 最高 128K |
|
|
129
|
+
| `MODEL_BASE_URL` | 预设地址 | 覆盖预设,用于自建网关、代理或私有化部署 |
|
|
130
|
+
| `MODEL_API_KEY` | — | 所接入服务的 Key;本地服务可填任意非空值 |
|
|
131
|
+
| `APPROVAL_MODE` | `sensitive` | `none`、`sensitive`、`all` |
|
|
132
|
+
| `ENABLE_SHELL` | `false` | 是否在宿主机暴露 `execute` |
|
|
133
|
+
| `SANDBOX_ENABLED` | `false` | 开启 OpenSandbox 远程沙箱,作为执行后端(按会话惰性创建) |
|
|
134
|
+
| `OPEN_SANDBOX_DOMAIN` / `OPEN_SANDBOX_API_KEY` | `localhost:8080` / — | OpenSandbox 服务地址与 API Key |
|
|
135
|
+
| `OPEN_SANDBOX_PROTOCOL` | `http` | `http` 或 `https` |
|
|
136
|
+
| `OPEN_SANDBOX_ID` | — | 共享模式:所有会话连接同一个已有沙箱,退出时只关闭连接 |
|
|
137
|
+
| `SANDBOX_IMAGE` / `SANDBOX_TIMEOUT_SECONDS` | `python:3.12` / `1800` | 沙箱镜像与 TTL(秒);使用中按 TTL/3 续期,`0` 表示不过期 |
|
|
138
|
+
| `SANDBOX_WORKSPACE_ROOT` | `/workspace` | 沙箱工作目录,也是 `execute` 的默认 cwd |
|
|
139
|
+
| `CHECKPOINTER` / `STORE` | `memory` | 设为 `postgres` 时启用 PostgreSQL 持久化 |
|
|
140
|
+
| `POSTGRES_HOST` / `POSTGRES_PORT` | `localhost` / `5432` | PostgreSQL 地址 |
|
|
141
|
+
| `POSTGRES_USERNAME` / `POSTGRES_PASSWORD` | `postgres` / `postgres` | PostgreSQL 凭证 |
|
|
142
|
+
| `POSTGRES_DATABASE` | `deepagent` | PostgreSQL 数据库名 |
|
|
143
|
+
| `DATABASE_URL` | — | 可选完整连接串,优先于上面的 `POSTGRES_*` |
|
|
144
|
+
| `MCP_SERVERS` | — | MCP 服务器的 JSON 映射 |
|
|
145
|
+
| `LANGSMITH_TRACING` | `false` | 配合 `LANGSMITH_API_KEY` 开启链路追踪 |
|
|
146
|
+
|
|
147
|
+
### 接入模型
|
|
148
|
+
|
|
149
|
+
模型层只依赖 OpenAI 兼容协议(`POST {baseUrl}/chat/completions`),更换服务商不需要改代码:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# DeepSeek
|
|
153
|
+
MODEL_PROVIDER=deepseek
|
|
154
|
+
MODEL_NAME=deepseek-chat
|
|
155
|
+
MODEL_API_KEY=sk-...
|
|
156
|
+
|
|
157
|
+
# MiniMax(国内站;国际站用 MODEL_BASE_URL=https://api.minimax.io/v1)
|
|
158
|
+
MODEL_PROVIDER=minimax
|
|
159
|
+
MODEL_NAME=MiniMax-M3
|
|
160
|
+
MODEL_API_KEY=sk-...
|
|
161
|
+
|
|
162
|
+
# 通义千问(阿里云百炼)
|
|
163
|
+
MODEL_PROVIDER=qwen
|
|
164
|
+
MODEL_NAME=qwen-plus
|
|
165
|
+
MODEL_API_KEY=sk-...
|
|
166
|
+
|
|
167
|
+
# 本地 Ollama:Key 可填任意非空值
|
|
168
|
+
MODEL_PROVIDER=ollama
|
|
169
|
+
MODEL_NAME=qwen3:8b
|
|
170
|
+
MODEL_API_KEY=ollama
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
自建网关或私有化部署用 `MODEL_PROVIDER=custom` 并同时指定 `MODEL_BASE_URL` 与 `MODEL_NAME`。
|
|
174
|
+
预设列表和默认模型在 `src/model/presets`;需要额外参数(超时、重试、自定义请求头等)时,调整 `src/model/openai-compatible` 里 `ChatOpenAI` 的构造参数即可。
|
|
175
|
+
|
|
176
|
+
### PostgreSQL
|
|
177
|
+
|
|
178
|
+
设置 `CHECKPOINTER=postgres` 或 `STORE=postgres` 后,服务会用 `POSTGRES_*` 分项拼装连接信息;同时设置 `DATABASE_URL` 时优先使用完整连接串。
|
|
179
|
+
|
|
180
|
+
| 变量 | 默认值 |
|
|
181
|
+
| --- | --- |
|
|
182
|
+
| `POSTGRES_HOST` | `localhost` |
|
|
183
|
+
| `POSTGRES_PORT` | `5432` |
|
|
184
|
+
| `POSTGRES_USERNAME` | `postgres` |
|
|
185
|
+
| `POSTGRES_PASSWORD` | `postgres` |
|
|
186
|
+
| `POSTGRES_DATABASE` | `deepagent` |
|
|
187
|
+
|
|
188
|
+
本地启动数据库:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
docker compose -f deployment/docker-compose.yml up -d postgres
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`PostgresSaver.setup()` / `PostgresStore.setup()` 会在启动时自动建表。`src/storage/database/migrations/001_init.sql` 提供了一个可选的审计日志表。
|
|
195
|
+
|
|
196
|
+
### MCP
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
MCP_SERVERS='{"filesystem":{"transport":"stdio","command":"npx","args":["-y","@modelcontextprotocol/server-filesystem","."]}}'
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
工具会在启动时加载,并合并进主 Agent 的工具列表。
|
|
203
|
+
|
|
204
|
+
### 沙箱(OpenSandbox)
|
|
205
|
+
|
|
206
|
+
[OpenSandbox](https://open-sandbox.ai/) 为 Agent 提供隔离的代码执行环境。先启动服务(默认 `http://127.0.0.1:8080`):
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
uvx opensandbox-server init-config ~/.sandbox.toml --example docker
|
|
210
|
+
uvx opensandbox-server
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
然后在 `.env` 中开启:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
SANDBOX_ENABLED=true
|
|
217
|
+
OPEN_SANDBOX_DOMAIN=localhost:8080
|
|
218
|
+
SANDBOX_IMAGE=python:3.12
|
|
219
|
+
SANDBOX_TIMEOUT_SECONDS=1800
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
开启后:
|
|
223
|
+
|
|
224
|
+
- **按会话隔离**:每个 `threadId` 第一次运行 Agent 时惰性创建一个沙箱(不是在服务启动时),该会话后续的消息、工具调用和子 Agent 都复用同一个后端;不同会话互不影响;
|
|
225
|
+
- `/workspace/` 与 `execute` 在各自会话的沙箱内执行;`AGENTS.md`、`SKILL.md` 仍在启动时从本地读取并注入提示词,`/memories/` 继续使用 LangGraph store;
|
|
226
|
+
- 开启沙箱后 `ENABLE_SHELL` 不再生效,宿主机的 `execute` 不会被暴露;
|
|
227
|
+
- `execute` 在该会话的沙箱内维护一个持久 bash session,`cd`、`export`、函数定义等状态跨命令保留;同一会话的命令串行排队,避免互相覆盖 shell 状态;
|
|
228
|
+
- **过期与续期**:沙箱默认 TTL 1800 秒,每次使用间隔超过 TTL 的三分之一会调用 `renew` 续期,所以活跃会话不会被回收;空闲超过 TTL 由服务端回收,下次访问自动重建(沙箱内的 `/workspace` 内容随之丢失);
|
|
229
|
+
- `DELETE /api/sessions/:threadId` 会释放对应沙箱;进程退出时销毁所有沙箱;
|
|
230
|
+
- 设置 `OPEN_SANDBOX_ID` 时切换为共享模式:所有会话连接同一个已有沙箱,退出时只关闭连接、不会 `kill` 它。
|
|
231
|
+
|
|
232
|
+
> `SANDBOX_TIMEOUT_SECONDS=0` 表示不设置服务端 TTL,完全由应用在删除会话 / 退出时清理;进程崩溃时会留下无人回收的沙箱,生产环境建议保留默认 TTL。
|
|
233
|
+
|
|
234
|
+
实现位于 `src/sandbox/`:`OpenSandboxBackend` 继承 deepagents 的 `BaseSandbox`,只实现 `execute` 与文件上传/下载,`ls`、`read`、`grep` 等由 `BaseSandbox` 复用同一 session 完成。
|
|
235
|
+
|
|
236
|
+
## Docker
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
docker compose -f deployment/docker-compose.yml up --build
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## 安全说明
|
|
243
|
+
|
|
244
|
+
Deep Agents 遵循“信任模型”的策略:工具允许什么,Agent 就能做什么。模板提供了一些纵深防御(危险命令拦截、只读 SQL 事务、审批、工作区隔离),但真正的边界必须在部署层保证:
|
|
245
|
+
|
|
246
|
+
- 除非运行在一次性容器中,否则保持 `ENABLE_SHELL=false`。
|
|
247
|
+
- PostgreSQL 连接使用只读数据库角色。
|
|
248
|
+
- 对公网部署时,在 API 前增加鉴权与限流。
|
|
249
|
+
- 仔细审查新增的 `SKILL.md` 和 `AGENTS.md`,它们会成为模型指令。
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# ---------------------------------------------------------------------------
|
|
2
|
+
# 服务
|
|
3
|
+
# ---------------------------------------------------------------------------
|
|
4
|
+
NODE_ENV=development
|
|
5
|
+
HOST=0.0.0.0
|
|
6
|
+
PORT=3000
|
|
7
|
+
LOG_LEVEL=info
|
|
8
|
+
|
|
9
|
+
# ---------------------------------------------------------------------------
|
|
10
|
+
# 模型:统一通过 OpenAI 兼容协议接入
|
|
11
|
+
#
|
|
12
|
+
# 默认使用 MiniMax M3(国内站 https://api.minimaxi.com/v1)
|
|
13
|
+
# MODEL_PROVIDER 选择预设地址:openai | deepseek | moonshot | minimax | qwen |
|
|
14
|
+
# zhipu | openrouter | ollama | vllm | custom(预设见 src/model/presets)
|
|
15
|
+
# ---------------------------------------------------------------------------
|
|
16
|
+
MODEL_PROVIDER=minimax
|
|
17
|
+
# 不填时使用预设的默认模型;换服务商时请一并修改
|
|
18
|
+
MODEL_NAME=MiniMax-M3
|
|
19
|
+
MODEL_TEMPERATURE=0.2
|
|
20
|
+
# 单次生成上限(含思考 token);M3 最高 128K,长文/长代码场景可调大
|
|
21
|
+
MODEL_MAX_COMPLETION_TOKENS=32768
|
|
22
|
+
# 所接入服务的 API Key;本地服务(Ollama、vLLM)可填任意非空值
|
|
23
|
+
MODEL_API_KEY=
|
|
24
|
+
# 覆盖预设地址,用于自建网关、代理或私有化部署
|
|
25
|
+
# MiniMax 国际站为 https://api.minimax.io/v1
|
|
26
|
+
# MODEL_BASE_URL=https://api.minimaxi.com/v1
|
|
27
|
+
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
# Agent
|
|
30
|
+
# ---------------------------------------------------------------------------
|
|
31
|
+
AGENT_NAME=deepagent
|
|
32
|
+
AGENT_RECURSION_LIMIT=50
|
|
33
|
+
# none | sensitive | all
|
|
34
|
+
APPROVAL_MODE=sensitive
|
|
35
|
+
# 是否暴露在宿主机执行命令的 `execute` 工具;除非运行在容器中,否则保持 false
|
|
36
|
+
ENABLE_SHELL=false
|
|
37
|
+
# /api/* 的可选 Bearer Token
|
|
38
|
+
AGENT_API_KEY=
|
|
39
|
+
WORKSPACE_ROOT=workspaces
|
|
40
|
+
RESOURCES_ROOT=resources
|
|
41
|
+
SKILLS_ROOT=skills
|
|
42
|
+
|
|
43
|
+
# ---------------------------------------------------------------------------
|
|
44
|
+
# 沙箱(OpenSandbox):开启后按会话(threadId)惰性创建并复用远程沙箱
|
|
45
|
+
# ---------------------------------------------------------------------------
|
|
46
|
+
SANDBOX_ENABLED=false
|
|
47
|
+
OPEN_SANDBOX_DOMAIN=localhost:8080
|
|
48
|
+
OPEN_SANDBOX_PROTOCOL=http
|
|
49
|
+
OPEN_SANDBOX_API_KEY=
|
|
50
|
+
# 共享已有沙箱:设置 ID 后所有会话连接同一个沙箱,退出时不会 kill 它
|
|
51
|
+
# OPEN_SANDBOX_ID=
|
|
52
|
+
SANDBOX_IMAGE=python:3.12
|
|
53
|
+
# 沙箱 TTL(秒):使用中按 TTL/3 自动续期,空闲超过该时长由服务端回收;
|
|
54
|
+
# 到期后再次访问会自动重建(沙箱内的 /workspace 内容随之丢失)。0 表示不设置 TTL。
|
|
55
|
+
SANDBOX_TIMEOUT_SECONDS=1800
|
|
56
|
+
SANDBOX_WORKSPACE_ROOT=/workspace
|
|
57
|
+
|
|
58
|
+
# ---------------------------------------------------------------------------
|
|
59
|
+
# 工具
|
|
60
|
+
# ---------------------------------------------------------------------------
|
|
61
|
+
# MCP 服务器 JSON 配置,例如:
|
|
62
|
+
# MCP_SERVERS={"filesystem":{"transport":"stdio","command":"npx","args":["-y","@modelcontextprotocol/server-filesystem","."]}}
|
|
63
|
+
|
|
64
|
+
# ---------------------------------------------------------------------------
|
|
65
|
+
# 持久化:PostgreSQL / Redis
|
|
66
|
+
#
|
|
67
|
+
# CHECKPOINTER/STORE 设为 postgres 时,用下面的 POSTGRES_* 分项拼装连接串;
|
|
68
|
+
# 若同时设置 DATABASE_URL,则以 DATABASE_URL 为准。
|
|
69
|
+
# ---------------------------------------------------------------------------
|
|
70
|
+
# memory | postgres
|
|
71
|
+
CHECKPOINTER=memory
|
|
72
|
+
STORE=memory
|
|
73
|
+
# DATABASE_URL=postgresql://postgres:postgres@localhost:5432/deepagent
|
|
74
|
+
POSTGRES_HOST=localhost
|
|
75
|
+
POSTGRES_PORT=5432
|
|
76
|
+
POSTGRES_USERNAME=postgres
|
|
77
|
+
POSTGRES_PASSWORD=postgres
|
|
78
|
+
POSTGRES_DATABASE=deepagent
|
|
79
|
+
REDIS_URL=
|
|
80
|
+
|
|
81
|
+
# ---------------------------------------------------------------------------
|
|
82
|
+
# LangSmith 链路追踪(可选)
|
|
83
|
+
# ---------------------------------------------------------------------------
|
|
84
|
+
LANGSMITH_TRACING=false
|
|
85
|
+
LANGSMITH_API_KEY=
|
|
86
|
+
LANGSMITH_PROJECT=deepagent
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ---------------------------------------------------------------------------
|
|
2
|
+
# 服务
|
|
3
|
+
# ---------------------------------------------------------------------------
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
coverage/
|
|
7
|
+
*.log
|
|
8
|
+
|
|
9
|
+
.env
|
|
10
|
+
.env.*
|
|
11
|
+
!.env.example
|
|
12
|
+
|
|
13
|
+
.idea/
|
|
14
|
+
.vscode/
|
|
15
|
+
.DS_Store
|
|
16
|
+
|
|
17
|
+
# Agent 草稿区:保留目录,忽略内容
|
|
18
|
+
workspaces/*
|
|
19
|
+
!workspaces/README.md
|
|
20
|
+
|
|
21
|
+
# 本地 LangGraph / Deep Agents 状态
|
|
22
|
+
.deepagents/
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
services:
|
|
2
|
+
# Agent API
|
|
3
|
+
agent:
|
|
4
|
+
build:
|
|
5
|
+
context: ..
|
|
6
|
+
dockerfile: deployment/Dockerfile
|
|
7
|
+
ports:
|
|
8
|
+
- "3000:3000"
|
|
9
|
+
env_file:
|
|
10
|
+
- ../.env
|
|
11
|
+
environment:
|
|
12
|
+
NODE_ENV: production
|
|
13
|
+
HOST: 0.0.0.0
|
|
14
|
+
POSTGRES_HOST: postgres
|
|
15
|
+
POSTGRES_PORT: "5432"
|
|
16
|
+
POSTGRES_USERNAME: postgres
|
|
17
|
+
POSTGRES_PASSWORD: postgres
|
|
18
|
+
POSTGRES_DATABASE: deepagent
|
|
19
|
+
REDIS_URL: redis://redis:6379
|
|
20
|
+
CHECKPOINTER: postgres
|
|
21
|
+
STORE: postgres
|
|
22
|
+
depends_on:
|
|
23
|
+
postgres:
|
|
24
|
+
condition: service_healthy
|
|
25
|
+
redis:
|
|
26
|
+
condition: service_healthy
|
|
27
|
+
|
|
28
|
+
# PostgreSQL(CHECKPOINTER/STORE=postgres 时使用)
|
|
29
|
+
postgres:
|
|
30
|
+
image: postgres:17-alpine
|
|
31
|
+
environment:
|
|
32
|
+
POSTGRES_USER: postgres
|
|
33
|
+
POSTGRES_PASSWORD: postgres
|
|
34
|
+
POSTGRES_DB: deepagent
|
|
35
|
+
ports:
|
|
36
|
+
- "5432:5432"
|
|
37
|
+
volumes:
|
|
38
|
+
- postgres-data:/var/lib/postgresql/data
|
|
39
|
+
healthcheck:
|
|
40
|
+
test: ["CMD-SHELL", "pg_isready -U postgres -d deepagent"]
|
|
41
|
+
interval: 5s
|
|
42
|
+
timeout: 5s
|
|
43
|
+
retries: 10
|
|
44
|
+
|
|
45
|
+
# Redis(可选)
|
|
46
|
+
redis:
|
|
47
|
+
image: redis:7-alpine
|
|
48
|
+
ports:
|
|
49
|
+
- "6379:6379"
|
|
50
|
+
volumes:
|
|
51
|
+
- redis-data:/data
|
|
52
|
+
healthcheck:
|
|
53
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
54
|
+
interval: 5s
|
|
55
|
+
timeout: 3s
|
|
56
|
+
retries: 10
|
|
57
|
+
|
|
58
|
+
volumes:
|
|
59
|
+
postgres-data:
|
|
60
|
+
redis-data:
|