create-deepagent-server 1.0.0 → 1.0.1
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/package.json +1 -1
- package/src/args.js +7 -7
- package/src/cli.js +7 -7
- package/src/dependencies.js +3 -3
- package/src/registry.js +5 -5
- package/src/scaffold.js +15 -15
- package/src/setup.js +2 -2
- package/src/version.js +1 -1
- package/src/versions.js +8 -8
- package/templates/deepagent/js/src/agents/prompts/loader.js +2 -2
- package/templates/deepagent/js/src/agents/prompts/supervisor.js +3 -3
- package/templates/deepagent/js/src/api/middleware/auth.js +2 -2
- package/templates/deepagent/js/src/config/agent.js +2 -2
- package/templates/deepagent/js/src/config/env.js +2 -2
- package/templates/deepagent/js/src/middleware/approval.js +6 -6
- package/templates/deepagent/js/src/middleware/index.js +3 -3
- package/templates/deepagent/js/src/middleware/security.js +2 -2
- package/templates/deepagent/js/src/model/config.js +4 -4
- package/templates/deepagent/js/src/model/index.js +1 -1
- package/templates/deepagent/js/src/model/presets.js +2 -2
- package/templates/deepagent/js/src/sandbox/opensandbox.js +3 -3
- package/templates/deepagent/js/src/skills/index.js +1 -1
- package/templates/deepagent/js/src/storage/logger/index.js +2 -2
- package/templates/deepagent/js/src/tools/database/query.js +4 -4
- package/templates/deepagent/ts/scripts/copy-assets.ts +6 -6
- package/templates/deepagent/ts/src/agents/prompts/loader.ts +2 -2
- package/templates/deepagent/ts/src/agents/prompts/supervisor.ts +3 -3
- package/templates/deepagent/ts/src/api/middleware/auth.ts +2 -2
- package/templates/deepagent/ts/src/config/agent.ts +2 -2
- package/templates/deepagent/ts/src/config/env.ts +2 -2
- package/templates/deepagent/ts/src/middleware/approval.ts +6 -6
- package/templates/deepagent/ts/src/middleware/index.ts +3 -3
- package/templates/deepagent/ts/src/middleware/security.ts +2 -2
- package/templates/deepagent/ts/src/model/config.ts +4 -4
- package/templates/deepagent/ts/src/model/index.ts +2 -2
- package/templates/deepagent/ts/src/model/presets.ts +3 -3
- package/templates/deepagent/ts/src/sandbox/opensandbox.ts +3 -3
- package/templates/deepagent/ts/src/skills/index.ts +1 -1
- package/templates/deepagent/ts/src/storage/logger/index.ts +2 -2
- package/templates/deepagent/ts/src/tools/database/query.ts +4 -4
package/package.json
CHANGED
package/src/args.js
CHANGED
|
@@ -5,10 +5,10 @@ export class UsageError extends Error {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
8
|
+
export const templates = ["deepagent"];
|
|
9
|
+
export const package_managers = ["npm", "pnpm", "yarn", "bun"];
|
|
10
10
|
|
|
11
|
-
export const
|
|
11
|
+
export const help_text = `create-deepagent-server —— 快速创建 Deep Agents 项目
|
|
12
12
|
|
|
13
13
|
用法:
|
|
14
14
|
create-deepagent-server [项目名] [选项]
|
|
@@ -115,15 +115,15 @@ export const parseArgs = (argv) => {
|
|
|
115
115
|
i = parsed.index;
|
|
116
116
|
|
|
117
117
|
if (flag === "-t" || flag === "--template") {
|
|
118
|
-
if (!
|
|
119
|
-
throw new UsageError(`未知模板 "${parsed.value}"。可用模板:${
|
|
118
|
+
if (!templates.includes(parsed.value)) {
|
|
119
|
+
throw new UsageError(`未知模板 "${parsed.value}"。可用模板:${templates.join("、")}。`);
|
|
120
120
|
}
|
|
121
121
|
options.template = parsed.value;
|
|
122
122
|
provided.add("template");
|
|
123
123
|
} else {
|
|
124
|
-
if (!
|
|
124
|
+
if (!package_managers.includes(parsed.value)) {
|
|
125
125
|
throw new UsageError(
|
|
126
|
-
`未知包管理器 "${parsed.value}"。可选值:${
|
|
126
|
+
`未知包管理器 "${parsed.value}"。可选值:${package_managers.join("、")}。`,
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
options.pm = parsed.value;
|
package/src/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { help_text, package_managers, UsageError, parseArgs } from "./args.js";
|
|
4
4
|
import { packagesFor } from "./dependencies.js";
|
|
5
5
|
import { createPrompter, isInteractive } from "./prompts.js";
|
|
6
6
|
import { bundledVersions, resolveVersions } from "./registry.js";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
runScriptText,
|
|
14
14
|
} from "./setup.js";
|
|
15
15
|
import { banner, blank, bold, dim, green, info, step, success, warn } from "./ui.js";
|
|
16
|
-
import {
|
|
16
|
+
import { version } from "./version.js";
|
|
17
17
|
|
|
18
18
|
export const toPackageName = (input) => {
|
|
19
19
|
const name = String(input)
|
|
@@ -105,12 +105,12 @@ export const main = async (argv = process.argv.slice(2)) => {
|
|
|
105
105
|
const { options, positionals } = parseArgs(argv);
|
|
106
106
|
|
|
107
107
|
if (options.help) {
|
|
108
|
-
console.log(
|
|
108
|
+
console.log(help_text);
|
|
109
109
|
return 0;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (options.version) {
|
|
113
|
-
console.log(
|
|
113
|
+
console.log(version);
|
|
114
114
|
return 0;
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -119,7 +119,7 @@ export const main = async (argv = process.argv.slice(2)) => {
|
|
|
119
119
|
const prompter = interactive ? createPrompter() : null;
|
|
120
120
|
|
|
121
121
|
try {
|
|
122
|
-
banner("create-deepagent-server",
|
|
122
|
+
banner("create-deepagent-server", version);
|
|
123
123
|
|
|
124
124
|
let projectArgument = positionals[0];
|
|
125
125
|
|
|
@@ -177,13 +177,13 @@ export const main = async (argv = process.argv.slice(2)) => {
|
|
|
177
177
|
(interactive
|
|
178
178
|
? await prompter.select(
|
|
179
179
|
"包管理器",
|
|
180
|
-
|
|
180
|
+
package_managers.map((name) => ({
|
|
181
181
|
label: name,
|
|
182
182
|
value: name,
|
|
183
183
|
hint: name === detected ? "已检测" : undefined,
|
|
184
184
|
})),
|
|
185
185
|
{
|
|
186
|
-
defaultIndex: Math.max(0,
|
|
186
|
+
defaultIndex: Math.max(0, package_managers.indexOf(detected)),
|
|
187
187
|
},
|
|
188
188
|
)
|
|
189
189
|
: detected);
|
package/src/dependencies.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 每个生成项目都会安装的依赖。
|
|
3
3
|
* 版本在生成项目时从 npm 解析,保证模板始终使用当前发布版本。
|
|
4
4
|
*/
|
|
5
|
-
export const
|
|
5
|
+
export const runtime_packages = [
|
|
6
6
|
"@alibaba-group/opensandbox",
|
|
7
7
|
"@langchain/core",
|
|
8
8
|
"@langchain/langgraph",
|
|
@@ -21,7 +21,7 @@ export const RUNTIME_PACKAGES = [
|
|
|
21
21
|
"zod",
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const typescript_packages = [
|
|
25
25
|
"typescript",
|
|
26
26
|
"tsx",
|
|
27
27
|
"@types/node",
|
|
@@ -30,5 +30,5 @@ export const TYPESCRIPT_PACKAGES = [
|
|
|
30
30
|
];
|
|
31
31
|
|
|
32
32
|
export const packagesFor = (language) => {
|
|
33
|
-
return language === "ts" ? [...
|
|
33
|
+
return language === "ts" ? [...runtime_packages, ...typescript_packages] : runtime_packages;
|
|
34
34
|
};
|
package/src/registry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fallback_versions } from "./versions.js";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const registry = (
|
|
4
4
|
process.env.DEEPAGENT_CLI_REGISTRY ||
|
|
5
5
|
process.env.npm_config_registry ||
|
|
6
6
|
"https://registry.npmjs.org"
|
|
@@ -12,7 +12,7 @@ const encodePackageName = (name) => {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
const fetchLatestVersion = async (name, timeoutMs) => {
|
|
15
|
-
const response = await fetch(`${
|
|
15
|
+
const response = await fetch(`${registry}/${encodePackageName(name)}/latest`, {
|
|
16
16
|
headers: { accept: "application/json" },
|
|
17
17
|
signal: AbortSignal.timeout(timeoutMs),
|
|
18
18
|
});
|
|
@@ -39,7 +39,7 @@ export const resolveVersions = async (packages, { timeoutMs = 5000 } = {}) => {
|
|
|
39
39
|
const version = await fetchLatestVersion(name, timeoutMs).catch(() => undefined);
|
|
40
40
|
if (version !== undefined) return { name, version, isFallback: false };
|
|
41
41
|
|
|
42
|
-
const fallback =
|
|
42
|
+
const fallback = fallback_versions[name];
|
|
43
43
|
if (!fallback) {
|
|
44
44
|
throw new Error(`无法解析 ${name} 的版本,且没有内置回退版本。`);
|
|
45
45
|
}
|
|
@@ -57,7 +57,7 @@ export const resolveVersions = async (packages, { timeoutMs = 5000 } = {}) => {
|
|
|
57
57
|
export const bundledVersions = (packages) => {
|
|
58
58
|
return Object.fromEntries(
|
|
59
59
|
packages.map((name) => {
|
|
60
|
-
const version =
|
|
60
|
+
const version = fallback_versions[name];
|
|
61
61
|
if (!version) {
|
|
62
62
|
throw new Error(`没有为 ${name} 内置回退版本。`);
|
|
63
63
|
}
|
package/src/scaffold.js
CHANGED
|
@@ -2,21 +2,21 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { runtime_packages, typescript_packages } from "./dependencies.js";
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const templates_dir = path.join(here, "..", "templates");
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const templates = ["deepagent"];
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const template_filenames = new Map([
|
|
13
13
|
["_gitignore", ".gitignore"],
|
|
14
14
|
["_env.example", ".env.example"],
|
|
15
15
|
["_editorconfig", ".editorconfig"],
|
|
16
16
|
]);
|
|
17
17
|
|
|
18
18
|
const mapTemplateFilename = (name) => {
|
|
19
|
-
return
|
|
19
|
+
return template_filenames.get(name) ?? name;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const walk = async (directory, prefix = "") => {
|
|
@@ -56,7 +56,7 @@ export const ensureEmptyTarget = async (targetDir, { force = false } = {}) => {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
const assertVersions = (versions, language) => {
|
|
59
|
-
const required = [...
|
|
59
|
+
const required = [...runtime_packages, ...(language === "ts" ? typescript_packages : [])];
|
|
60
60
|
const missing = required.filter((name) => !versions?.[name]);
|
|
61
61
|
|
|
62
62
|
if (missing.length > 0) {
|
|
@@ -64,7 +64,7 @@ const assertVersions = (versions, language) => {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
const
|
|
67
|
+
const typescript_scripts = {
|
|
68
68
|
dev: "tsx watch src/index.ts",
|
|
69
69
|
build: "tsc -p tsconfig.json && tsx scripts/copy-assets.ts",
|
|
70
70
|
start: "node dist/index.js",
|
|
@@ -74,7 +74,7 @@ const TYPESCRIPT_SCRIPTS = {
|
|
|
74
74
|
test: 'node --import tsx --test "tests/**/*.test.ts"',
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
const
|
|
77
|
+
const javascript_scripts = {
|
|
78
78
|
dev: "node --watch src/index.js",
|
|
79
79
|
start: "node src/index.js",
|
|
80
80
|
agent: "node scripts/dev.js",
|
|
@@ -84,16 +84,16 @@ const JAVASCRIPT_SCRIPTS = {
|
|
|
84
84
|
|
|
85
85
|
export const buildPackageJson = ({ packageName, language, versions }) => {
|
|
86
86
|
const dependencies = Object.fromEntries(
|
|
87
|
-
|
|
87
|
+
runtime_packages.map((name) => [name, `^${versions[name]}`]),
|
|
88
88
|
);
|
|
89
89
|
|
|
90
90
|
const typescriptDependencies = Object.fromEntries(
|
|
91
|
-
|
|
91
|
+
typescript_packages.map((name) => [name, `^${versions[name]}`]),
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
const devDependencies = language === "ts" ? typescriptDependencies : {};
|
|
95
95
|
|
|
96
|
-
const scripts = language === "ts" ?
|
|
96
|
+
const scripts = language === "ts" ? typescript_scripts : javascript_scripts;
|
|
97
97
|
|
|
98
98
|
const manifest = {
|
|
99
99
|
name: packageName,
|
|
@@ -122,8 +122,8 @@ export const scaffold = async ({
|
|
|
122
122
|
versions,
|
|
123
123
|
force = false,
|
|
124
124
|
}) => {
|
|
125
|
-
if (!
|
|
126
|
-
throw new Error(`未知模板 "${template}"。可用模板:${
|
|
125
|
+
if (!templates.includes(template)) {
|
|
126
|
+
throw new Error(`未知模板 "${template}"。可用模板:${templates.join("、")}。`);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (language !== "js" && language !== "ts") {
|
|
@@ -138,7 +138,7 @@ export const scaffold = async ({
|
|
|
138
138
|
await ensureEmptyTarget(targetDir, { force });
|
|
139
139
|
|
|
140
140
|
// 先写入共享文件,再用语言专属文件覆盖同名文件。
|
|
141
|
-
const templateRoot = path.join(
|
|
141
|
+
const templateRoot = path.join(templates_dir, template);
|
|
142
142
|
|
|
143
143
|
const entries = await Promise.all(
|
|
144
144
|
[path.join(templateRoot, "shared"), path.join(templateRoot, language)].map(async (directory) =>
|
package/src/setup.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const lockfiles = [
|
|
6
6
|
["pnpm-lock.yaml", "pnpm"],
|
|
7
7
|
["yarn.lock", "yarn"],
|
|
8
8
|
["bun.lockb", "bun"],
|
|
@@ -18,7 +18,7 @@ export const detectPackageManager = ({ cwd = process.cwd(), env = process.env }
|
|
|
18
18
|
if (userAgent.startsWith(`${packageManager}/`)) return packageManager;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
for (const [lockfile, packageManager] of
|
|
21
|
+
for (const [lockfile, packageManager] of lockfiles) {
|
|
22
22
|
if (existsSync(path.join(cwd, lockfile))) return packageManager;
|
|
23
23
|
}
|
|
24
24
|
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const version = "1.0.1";
|
package/src/versions.js
CHANGED
|
@@ -4,24 +4,24 @@
|
|
|
4
4
|
* 正常生成项目时会在运行时从 registry 解析 `latest`;这里的值仅作回退,
|
|
5
5
|
* 随 CLI 发版一起更新。
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
7
|
+
export const fallback_versions = {
|
|
8
8
|
"@alibaba-group/opensandbox": "1.2.1",
|
|
9
|
-
"@langchain/core": "1.4.
|
|
10
|
-
"@langchain/langgraph": "1.7.
|
|
11
|
-
"@langchain/langgraph-checkpoint": "1.2.
|
|
12
|
-
"@langchain/langgraph-checkpoint-postgres": "1.1.
|
|
9
|
+
"@langchain/core": "1.4.1",
|
|
10
|
+
"@langchain/langgraph": "1.7.5",
|
|
11
|
+
"@langchain/langgraph-checkpoint": "1.2.3",
|
|
12
|
+
"@langchain/langgraph-checkpoint-postgres": "1.1.4",
|
|
13
13
|
"@langchain/mcp-adapters": "2.0.3",
|
|
14
14
|
"@langchain/openai": "1.8.4",
|
|
15
|
-
deepagents: "1.
|
|
15
|
+
deepagents: "1.17.0",
|
|
16
16
|
dotenv: "18.0.10",
|
|
17
17
|
express: "5.3.0",
|
|
18
18
|
ioredis: "6.0.0",
|
|
19
|
-
langchain: "1.6.
|
|
19
|
+
langchain: "1.6.6",
|
|
20
20
|
pg: "8.23.1",
|
|
21
21
|
pino: "10.4.0",
|
|
22
22
|
"pino-pretty": "13.2.0",
|
|
23
23
|
zod: "4.6.7",
|
|
24
|
-
typescript: "
|
|
24
|
+
typescript: "7.0.2",
|
|
25
25
|
tsx: "4.23.15",
|
|
26
26
|
"@types/node": "26.6.6",
|
|
27
27
|
"@types/express": "5.0.6",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const valid_name = /^[a-z0-9][a-z0-9/_-]*$/i;
|
|
5
5
|
const cache = new Map();
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -10,7 +10,7 @@ const cache = new Map();
|
|
|
10
10
|
* 相对路径保持一致。
|
|
11
11
|
*/
|
|
12
12
|
export const loadPrompt = (name) => {
|
|
13
|
-
if (!
|
|
13
|
+
if (!valid_name.test(name) || name.includes("..")) {
|
|
14
14
|
throw new Error(`非法的提示词名称:${name}`);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loadPrompt, renderPrompt } from "./loader.js";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const no_approval_policy = "工具调用无需人工审批,直接执行。";
|
|
4
|
+
const approval_policy =
|
|
5
5
|
"有副作用的工具调用会暂停以等待人工审批。请说明为什么需要该工具,然后等待决定。";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -11,7 +11,7 @@ const APPROVAL_POLICY =
|
|
|
11
11
|
export const buildSupervisorPrompt = ({ name, subagents, approvalMode }) => {
|
|
12
12
|
const team = subagents.map((agent) => `- **${agent.name}** — ${agent.description}`).join("\n");
|
|
13
13
|
|
|
14
|
-
const approvalPolicy = approvalMode === "none" ?
|
|
14
|
+
const approvalPolicy = approvalMode === "none" ? no_approval_policy : approval_policy;
|
|
15
15
|
|
|
16
16
|
return renderPrompt(loadPrompt("supervisor"), {
|
|
17
17
|
agentName: name,
|
|
@@ -2,7 +2,7 @@ import { timingSafeEqual } from "node:crypto";
|
|
|
2
2
|
|
|
3
3
|
import { UnauthorizedError } from "../../utils/errors.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const bearer_prefix = "Bearer ";
|
|
6
6
|
|
|
7
7
|
const safeEqual = (provided, expected) => {
|
|
8
8
|
const actual = Buffer.from(provided);
|
|
@@ -24,7 +24,7 @@ export const createAuthMiddleware = (apiKey) => {
|
|
|
24
24
|
|
|
25
25
|
return (req, _res, next) => {
|
|
26
26
|
const header = req.header("authorization") ?? "";
|
|
27
|
-
const token = header.startsWith(
|
|
27
|
+
const token = header.startsWith(bearer_prefix) ? header.slice(bearer_prefix.length).trim() : "";
|
|
28
28
|
|
|
29
29
|
if (!token || !safeEqual(token, apiKey)) {
|
|
30
30
|
next(new UnauthorizedError());
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const default_agent_description =
|
|
2
2
|
"负责规划任务、把工作分派给专职子 Agent,并维护工作区文件的主 Agent。";
|
|
3
3
|
|
|
4
4
|
export const resolveAgentConfig = (env) => {
|
|
5
5
|
return {
|
|
6
6
|
name: env.AGENT_NAME,
|
|
7
|
-
description:
|
|
7
|
+
description: default_agent_description,
|
|
8
8
|
recursionLimit: env.AGENT_RECURSION_LIMIT,
|
|
9
9
|
approvals: env.APPROVAL_MODE,
|
|
10
10
|
enableShell: env.ENABLE_SHELL,
|
|
@@ -2,7 +2,7 @@ import "../schemas/locale.js";
|
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { model_providers } from "../model/index.js";
|
|
6
6
|
import { ConfigurationError } from "../utils/errors.js";
|
|
7
7
|
|
|
8
8
|
const booleanFlag = z
|
|
@@ -25,7 +25,7 @@ export const envSchema = z.object({
|
|
|
25
25
|
LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace", "silent"]).default("info"),
|
|
26
26
|
|
|
27
27
|
// 模型统一通过 OpenAI 兼容协议接入,服务商预设见 src/model/presets。
|
|
28
|
-
MODEL_PROVIDER: z.enum(
|
|
28
|
+
MODEL_PROVIDER: z.enum(model_providers).default("minimax"),
|
|
29
29
|
MODEL_NAME: optionalString,
|
|
30
30
|
MODEL_BASE_URL: optionalString,
|
|
31
31
|
MODEL_API_KEY: optionalString,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 会修改状态或操作基础设施的工具。它们会通过 `interruptOn` 暂停,
|
|
3
3
|
* 等待人工批准后再执行。
|
|
4
4
|
*/
|
|
5
|
-
export const
|
|
5
|
+
export const sensitive_tools = [
|
|
6
6
|
"write_file",
|
|
7
7
|
"edit_file",
|
|
8
8
|
"delete",
|
|
@@ -12,8 +12,8 @@ export const SENSITIVE_TOOLS = [
|
|
|
12
12
|
];
|
|
13
13
|
|
|
14
14
|
/** 模板已知的全部工具名称。 */
|
|
15
|
-
export const
|
|
16
|
-
...
|
|
15
|
+
export const known_tools = [
|
|
16
|
+
...sensitive_tools,
|
|
17
17
|
"read_file",
|
|
18
18
|
"read_workspace_file",
|
|
19
19
|
"list_workspace_files",
|
|
@@ -34,14 +34,14 @@ export const KNOWN_TOOLS = [
|
|
|
34
34
|
export const createApprovalPolicy = (mode) => {
|
|
35
35
|
if (mode === "none") return {};
|
|
36
36
|
|
|
37
|
-
const tools = mode === "all" ? [...
|
|
37
|
+
const tools = mode === "all" ? [...known_tools] : [...sensitive_tools];
|
|
38
38
|
|
|
39
39
|
return Object.fromEntries(tools.map((tool) => [tool, true]));
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export const requiresApproval = (mode, toolName) => {
|
|
43
43
|
if (mode === "none") return false;
|
|
44
|
-
if (mode === "all") return
|
|
44
|
+
if (mode === "all") return known_tools.includes(toolName);
|
|
45
45
|
|
|
46
|
-
return
|
|
46
|
+
return sensitive_tools.includes(toolName);
|
|
47
47
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export {
|
|
2
2
|
createApprovalPolicy,
|
|
3
|
-
|
|
3
|
+
known_tools,
|
|
4
4
|
requiresApproval,
|
|
5
|
-
|
|
5
|
+
sensitive_tools,
|
|
6
6
|
} from "./approval.js";
|
|
7
7
|
export { createContextMiddleware, runtimeContextSchema } from "./context.js";
|
|
8
8
|
export { createLoggingMiddleware } from "./logging.js";
|
|
9
|
-
export { createSecurityMiddleware,
|
|
9
|
+
export { createSecurityMiddleware, dangerous_patterns, findSecurityViolation } from "./security.js";
|
|
@@ -5,7 +5,7 @@ import { createMiddleware } from "langchain";
|
|
|
5
5
|
* 针对破坏性 shell/SQL 载荷的启发式规则。这是纵深防御,不是沙箱:
|
|
6
6
|
* 请以最小权限运行 Agent。
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const dangerous_patterns = [
|
|
9
9
|
{
|
|
10
10
|
pattern: /\brm\s+-(?:[a-z]*r[a-z]*f|[a-z]*f[a-z]*r)\s+\/(?:\s|$)/i,
|
|
11
11
|
reason: "递归删除根目录",
|
|
@@ -24,7 +24,7 @@ export const DANGEROUS_PATTERNS = [
|
|
|
24
24
|
];
|
|
25
25
|
|
|
26
26
|
export const findSecurityViolation = (value) => {
|
|
27
|
-
for (const { pattern, reason } of
|
|
27
|
+
for (const { pattern, reason } of dangerous_patterns) {
|
|
28
28
|
if (pattern.test(value)) return reason;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ConfigurationError } from "../utils/errors.js";
|
|
2
|
-
import {
|
|
2
|
+
import { openai_compatible_presets } from "./presets.js";
|
|
3
3
|
|
|
4
4
|
/** 未配置时的生成上限;MiniMax M3 最高支持 128K(含思考 token)。 */
|
|
5
|
-
export const
|
|
5
|
+
export const default_max_completion_tokens = 32_768;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 把环境变量解析成模型配置。
|
|
9
9
|
* `MODEL_BASE_URL` 优先于预设地址,用于自建网关、代理或私有化部署。
|
|
10
10
|
*/
|
|
11
11
|
export const resolveModelConfig = (env) => {
|
|
12
|
-
const preset =
|
|
12
|
+
const preset = openai_compatible_presets[env.MODEL_PROVIDER];
|
|
13
13
|
const baseUrl = env.MODEL_BASE_URL ?? preset.baseUrl;
|
|
14
14
|
const name = env.MODEL_NAME ?? preset.defaultModel;
|
|
15
15
|
|
|
@@ -33,6 +33,6 @@ export const resolveModelConfig = (env) => {
|
|
|
33
33
|
apiKey: env.MODEL_API_KEY ?? "",
|
|
34
34
|
temperature: env.MODEL_TEMPERATURE,
|
|
35
35
|
maxCompletionTokens:
|
|
36
|
-
env.MODEL_MAX_COMPLETION_TOKENS ?? env.MODEL_MAX_TOKENS ??
|
|
36
|
+
env.MODEL_MAX_COMPLETION_TOKENS ?? env.MODEL_MAX_TOKENS ?? default_max_completion_tokens,
|
|
37
37
|
};
|
|
38
38
|
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 因此这里只维护各家的接口地址与默认模型。只要服务实现了同一套协议,
|
|
6
6
|
* 增加一个预设就能接入,不需要引入新的 SDK。
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const model_providers = [
|
|
9
9
|
"openai",
|
|
10
10
|
"deepseek",
|
|
11
11
|
"moonshot",
|
|
@@ -18,7 +18,7 @@ export const MODEL_PROVIDERS = [
|
|
|
18
18
|
"custom",
|
|
19
19
|
];
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const openai_compatible_presets = {
|
|
22
22
|
openai: {
|
|
23
23
|
label: "OpenAI",
|
|
24
24
|
baseUrl: "https://api.openai.com/v1",
|
|
@@ -3,7 +3,7 @@ import { BaseSandbox } from "deepagents";
|
|
|
3
3
|
|
|
4
4
|
import { errorMessage } from "../utils/helpers.js";
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const max_output_chars = 100_000;
|
|
7
7
|
|
|
8
8
|
const parentDirectory = (filePath) => {
|
|
9
9
|
const index = filePath.lastIndexOf("/");
|
|
@@ -39,11 +39,11 @@ const formatExecution = (execution) => {
|
|
|
39
39
|
const stdout = execution.logs.stdout.map((message) => message.text);
|
|
40
40
|
const stderr = execution.logs.stderr.map((message) => `[stderr] ${message.text}`);
|
|
41
41
|
const output = [...stdout, ...stderr].join("\n");
|
|
42
|
-
const truncated = output.length >
|
|
42
|
+
const truncated = output.length > max_output_chars;
|
|
43
43
|
const exitCode = execution.exitCode ?? execution.error?.exitCode ?? (execution.error ? 1 : 0);
|
|
44
44
|
|
|
45
45
|
return {
|
|
46
|
-
output: truncated ? `${output.slice(0,
|
|
46
|
+
output: truncated ? `${output.slice(0, max_output_chars)}\n… 输出已截断` : output,
|
|
47
47
|
exitCode,
|
|
48
48
|
truncated,
|
|
49
49
|
};
|
|
@@ -3,7 +3,7 @@ import { discoverSkills } from "./loader.js";
|
|
|
3
3
|
export { discoverSkills, parseSkillFrontmatter } from "./loader.js";
|
|
4
4
|
|
|
5
5
|
/** Deep Agents skills 中间件扫描的虚拟后端路径。 */
|
|
6
|
-
export const
|
|
6
|
+
export const default_skill_sources = ["/skills/"];
|
|
7
7
|
|
|
8
8
|
/** 从磁盘发现技能(用于启动校验和 `scripts/check`)。 */
|
|
9
9
|
export const loadSkills = async ({ rootDir }) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pino from "pino";
|
|
2
2
|
|
|
3
3
|
/** `LOG_PRETTY=true` 时使用的 pino-pretty 传输配置。 */
|
|
4
|
-
const
|
|
4
|
+
const pretty_transport = {
|
|
5
5
|
transport: {
|
|
6
6
|
target: "pino-pretty",
|
|
7
7
|
options: {
|
|
@@ -16,6 +16,6 @@ export const createLogger = (config) => {
|
|
|
16
16
|
return pino({
|
|
17
17
|
level: config.logging.level,
|
|
18
18
|
base: { service: "deepagent", env: config.env.NODE_ENV },
|
|
19
|
-
...(config.logging.pretty ?
|
|
19
|
+
...(config.logging.pretty ? pretty_transport : {}),
|
|
20
20
|
});
|
|
21
21
|
};
|
|
@@ -3,8 +3,8 @@ import { z } from "zod";
|
|
|
3
3
|
|
|
4
4
|
import { getPool } from "../../storage/database/client.js";
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const read_only_start = /^\s*(?:select|with)\b/i;
|
|
7
|
+
const forbidden_keywords =
|
|
8
8
|
/\b(insert|update|delete|drop|alter|truncate|create|grant|revoke|copy|vacuum|reindex|call|do)\b/i;
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -14,13 +14,13 @@ const FORBIDDEN_KEYWORDS =
|
|
|
14
14
|
export const assertReadOnlyQuery = (sql) => {
|
|
15
15
|
const statement = sql.trim().replace(/;\s*$/, "");
|
|
16
16
|
|
|
17
|
-
if (!
|
|
17
|
+
if (!read_only_start.test(statement)) {
|
|
18
18
|
throw new Error("只允许 SELECT 和 WITH 查询。");
|
|
19
19
|
}
|
|
20
20
|
if (statement.includes(";")) {
|
|
21
21
|
throw new Error("只允许单条 SQL 语句。");
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (forbidden_keywords.test(statement)) {
|
|
24
24
|
throw new Error("查询包含写入或 DDL 关键字,已拒绝执行。");
|
|
25
25
|
}
|
|
26
26
|
};
|
|
@@ -6,10 +6,10 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
* `tsc` 只输出 JavaScript。提示词 Markdown 和 SQL 迁移文件需要复制到编译产物
|
|
7
7
|
* 旁边,保证从 `dist/` 运行时仍能按相对路径找到它们。
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
9
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
+
const source_root = path.join(root, "src");
|
|
11
|
+
const target_root = path.join(root, "dist");
|
|
12
|
+
const asset_extensions = new Set([".md", ".sql"]);
|
|
13
13
|
|
|
14
14
|
const copyAssets = async (sourceDir: string, targetDir: string): Promise<number> => {
|
|
15
15
|
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
@@ -23,7 +23,7 @@ const copyAssets = async (sourceDir: string, targetDir: string): Promise<number>
|
|
|
23
23
|
|
|
24
24
|
if (entry.isDirectory()) {
|
|
25
25
|
copied += await copyAssets(source, target);
|
|
26
|
-
} else if (entry.isFile() &&
|
|
26
|
+
} else if (entry.isFile() && asset_extensions.has(path.extname(entry.name))) {
|
|
27
27
|
await copyFile(source, target);
|
|
28
28
|
copied += 1;
|
|
29
29
|
}
|
|
@@ -32,6 +32,6 @@ const copyAssets = async (sourceDir: string, targetDir: string): Promise<number>
|
|
|
32
32
|
return copied;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
const copied = await copyAssets(
|
|
35
|
+
const copied = await copyAssets(source_root, target_root);
|
|
36
36
|
|
|
37
37
|
console.log(`已将 ${copied} 个资源文件复制到 dist/。`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const valid_name = /^[a-z0-9][a-z0-9/_-]*$/i;
|
|
5
5
|
const cache = new Map<string, string>();
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -10,7 +10,7 @@ const cache = new Map<string, string>();
|
|
|
10
10
|
* 相对路径保持一致。
|
|
11
11
|
*/
|
|
12
12
|
export const loadPrompt = (name: string): string => {
|
|
13
|
-
if (!
|
|
13
|
+
if (!valid_name.test(name) || name.includes("..")) {
|
|
14
14
|
throw new Error(`非法的提示词名称:${name}`);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -8,8 +8,8 @@ export interface SupervisorPromptOptions {
|
|
|
8
8
|
approvalMode: AgentConfig["approvals"];
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const no_approval_policy = "工具调用无需人工审批,直接执行。";
|
|
12
|
+
const approval_policy =
|
|
13
13
|
"有副作用的工具调用会暂停以等待人工审批。请说明为什么需要该工具,然后等待决定。";
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -23,7 +23,7 @@ export const buildSupervisorPrompt = ({
|
|
|
23
23
|
}: SupervisorPromptOptions): string => {
|
|
24
24
|
const team = subagents.map((agent) => `- **${agent.name}** — ${agent.description}`).join("\n");
|
|
25
25
|
|
|
26
|
-
const approvalPolicy = approvalMode === "none" ?
|
|
26
|
+
const approvalPolicy = approvalMode === "none" ? no_approval_policy : approval_policy;
|
|
27
27
|
|
|
28
28
|
return renderPrompt(loadPrompt("supervisor"), {
|
|
29
29
|
agentName: name,
|
|
@@ -4,7 +4,7 @@ import type { RequestHandler } from "express";
|
|
|
4
4
|
|
|
5
5
|
import { UnauthorizedError } from "../../utils/errors.js";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const bearer_prefix = "Bearer ";
|
|
8
8
|
|
|
9
9
|
const safeEqual = (provided: string, expected: string): boolean => {
|
|
10
10
|
const actual = Buffer.from(provided);
|
|
@@ -26,7 +26,7 @@ export const createAuthMiddleware = (apiKey?: string): RequestHandler => {
|
|
|
26
26
|
|
|
27
27
|
return (req, _res, next) => {
|
|
28
28
|
const header = req.header("authorization") ?? "";
|
|
29
|
-
const token = header.startsWith(
|
|
29
|
+
const token = header.startsWith(bearer_prefix) ? header.slice(bearer_prefix.length).trim() : "";
|
|
30
30
|
|
|
31
31
|
if (!token || !safeEqual(token, apiKey)) {
|
|
32
32
|
next(new UnauthorizedError());
|
|
@@ -21,13 +21,13 @@ export interface AgentConfig {
|
|
|
21
21
|
systemPromptAppendix?: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const default_agent_description =
|
|
25
25
|
"负责规划任务、把工作分派给专职子 Agent,并维护工作区文件的主 Agent。";
|
|
26
26
|
|
|
27
27
|
export const resolveAgentConfig = (env: Env): AgentConfig => {
|
|
28
28
|
return {
|
|
29
29
|
name: env.AGENT_NAME,
|
|
30
|
-
description:
|
|
30
|
+
description: default_agent_description,
|
|
31
31
|
recursionLimit: env.AGENT_RECURSION_LIMIT,
|
|
32
32
|
approvals: env.APPROVAL_MODE,
|
|
33
33
|
enableShell: env.ENABLE_SHELL,
|
|
@@ -2,7 +2,7 @@ import "../schemas/locale.js";
|
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { model_providers } from "../model/index.js";
|
|
6
6
|
import { ConfigurationError } from "../utils/errors.js";
|
|
7
7
|
|
|
8
8
|
const booleanFlag = z
|
|
@@ -25,7 +25,7 @@ export const envSchema = z.object({
|
|
|
25
25
|
LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace", "silent"]).default("info"),
|
|
26
26
|
|
|
27
27
|
// 模型统一通过 OpenAI 兼容协议接入,服务商预设见 src/model/presets。
|
|
28
|
-
MODEL_PROVIDER: z.enum(
|
|
28
|
+
MODEL_PROVIDER: z.enum(model_providers).default("minimax"),
|
|
29
29
|
MODEL_NAME: optionalString,
|
|
30
30
|
MODEL_BASE_URL: optionalString,
|
|
31
31
|
MODEL_API_KEY: optionalString,
|
|
@@ -4,7 +4,7 @@ import type { ApprovalMode } from "../config/index.js";
|
|
|
4
4
|
* 会修改状态或操作基础设施的工具。它们会通过 `interruptOn` 暂停,
|
|
5
5
|
* 等待人工批准后再执行。
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
7
|
+
export const sensitive_tools = [
|
|
8
8
|
"write_file",
|
|
9
9
|
"edit_file",
|
|
10
10
|
"delete",
|
|
@@ -14,8 +14,8 @@ export const SENSITIVE_TOOLS = [
|
|
|
14
14
|
] as const;
|
|
15
15
|
|
|
16
16
|
/** 模板已知的全部工具名称。 */
|
|
17
|
-
export const
|
|
18
|
-
...
|
|
17
|
+
export const known_tools = [
|
|
18
|
+
...sensitive_tools,
|
|
19
19
|
"read_file",
|
|
20
20
|
"read_workspace_file",
|
|
21
21
|
"list_workspace_files",
|
|
@@ -36,14 +36,14 @@ export const KNOWN_TOOLS = [
|
|
|
36
36
|
export const createApprovalPolicy = (mode: ApprovalMode): Record<string, boolean> => {
|
|
37
37
|
if (mode === "none") return {};
|
|
38
38
|
|
|
39
|
-
const tools = mode === "all" ? [...
|
|
39
|
+
const tools = mode === "all" ? [...known_tools] : [...sensitive_tools];
|
|
40
40
|
|
|
41
41
|
return Object.fromEntries(tools.map((tool) => [tool, true]));
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export const requiresApproval = (mode: ApprovalMode, toolName: string): boolean => {
|
|
45
45
|
if (mode === "none") return false;
|
|
46
|
-
if (mode === "all") return (
|
|
46
|
+
if (mode === "all") return (known_tools as readonly string[]).includes(toolName);
|
|
47
47
|
|
|
48
|
-
return (
|
|
48
|
+
return (sensitive_tools as readonly string[]).includes(toolName);
|
|
49
49
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export {
|
|
2
2
|
createApprovalPolicy,
|
|
3
|
-
|
|
3
|
+
known_tools,
|
|
4
4
|
requiresApproval,
|
|
5
|
-
|
|
5
|
+
sensitive_tools,
|
|
6
6
|
} from "./approval.js";
|
|
7
7
|
export { createContextMiddleware, runtimeContextSchema, type RuntimeContext } from "./context.js";
|
|
8
8
|
export { createLoggingMiddleware } from "./logging.js";
|
|
9
|
-
export { createSecurityMiddleware,
|
|
9
|
+
export { createSecurityMiddleware, dangerous_patterns, findSecurityViolation } from "./security.js";
|
|
@@ -5,7 +5,7 @@ import { createMiddleware } from "langchain";
|
|
|
5
5
|
* 针对破坏性 shell/SQL 载荷的启发式规则。这是纵深防御,不是沙箱:
|
|
6
6
|
* 请以最小权限运行 Agent。
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const dangerous_patterns: ReadonlyArray<{
|
|
9
9
|
pattern: RegExp;
|
|
10
10
|
reason: string;
|
|
11
11
|
}> = [
|
|
@@ -27,7 +27,7 @@ export const DANGEROUS_PATTERNS: ReadonlyArray<{
|
|
|
27
27
|
];
|
|
28
28
|
|
|
29
29
|
export const findSecurityViolation = (value: string): string | null => {
|
|
30
|
-
for (const { pattern, reason } of
|
|
30
|
+
for (const { pattern, reason } of dangerous_patterns) {
|
|
31
31
|
if (pattern.test(value)) return reason;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Env } from "../config/index.js";
|
|
2
2
|
import { ConfigurationError } from "../utils/errors.js";
|
|
3
|
-
import {
|
|
3
|
+
import { openai_compatible_presets, type ModelProvider } from "./presets.js";
|
|
4
4
|
|
|
5
5
|
/** 未配置时的生成上限;MiniMax M3 最高支持 128K(含思考 token)。 */
|
|
6
|
-
export const
|
|
6
|
+
export const default_max_completion_tokens = 32_768;
|
|
7
7
|
|
|
8
8
|
/** 构建聊天模型所需的全部参数,集中在一处解析。 */
|
|
9
9
|
export interface ModelConfig {
|
|
@@ -27,7 +27,7 @@ export interface ModelConfig {
|
|
|
27
27
|
* `MODEL_BASE_URL` 优先于预设地址,用于自建网关、代理或私有化部署。
|
|
28
28
|
*/
|
|
29
29
|
export const resolveModelConfig = (env: Env): ModelConfig => {
|
|
30
|
-
const preset =
|
|
30
|
+
const preset = openai_compatible_presets[env.MODEL_PROVIDER];
|
|
31
31
|
const baseUrl = env.MODEL_BASE_URL ?? preset.baseUrl;
|
|
32
32
|
const name = env.MODEL_NAME ?? preset.defaultModel;
|
|
33
33
|
|
|
@@ -51,6 +51,6 @@ export const resolveModelConfig = (env: Env): ModelConfig => {
|
|
|
51
51
|
apiKey: env.MODEL_API_KEY ?? "",
|
|
52
52
|
temperature: env.MODEL_TEMPERATURE,
|
|
53
53
|
maxCompletionTokens:
|
|
54
|
-
env.MODEL_MAX_COMPLETION_TOKENS ?? env.MODEL_MAX_TOKENS ??
|
|
54
|
+
env.MODEL_MAX_COMPLETION_TOKENS ?? env.MODEL_MAX_TOKENS ?? default_max_completion_tokens,
|
|
55
55
|
};
|
|
56
56
|
};
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
export { resolveModelConfig, type ModelConfig } from "./config.js";
|
|
8
8
|
export { createChatModel } from "./openai-compatible.js";
|
|
9
9
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
model_providers,
|
|
11
|
+
openai_compatible_presets,
|
|
12
12
|
type ModelPreset,
|
|
13
13
|
type ModelProvider,
|
|
14
14
|
} from "./presets.js";
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 因此这里只维护各家的接口地址与默认模型。只要服务实现了同一套协议,
|
|
6
6
|
* 增加一个预设就能接入,不需要引入新的 SDK。
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const model_providers = [
|
|
9
9
|
"openai",
|
|
10
10
|
"deepseek",
|
|
11
11
|
"moonshot",
|
|
@@ -18,7 +18,7 @@ export const MODEL_PROVIDERS = [
|
|
|
18
18
|
"custom",
|
|
19
19
|
] as const;
|
|
20
20
|
|
|
21
|
-
export type ModelProvider = (typeof
|
|
21
|
+
export type ModelProvider = (typeof model_providers)[number];
|
|
22
22
|
|
|
23
23
|
export interface ModelPreset {
|
|
24
24
|
/** 展示用名称,出现在日志与文档中。 */
|
|
@@ -29,7 +29,7 @@ export interface ModelPreset {
|
|
|
29
29
|
defaultModel?: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export const
|
|
32
|
+
export const openai_compatible_presets: Record<ModelProvider, ModelPreset> = {
|
|
33
33
|
openai: {
|
|
34
34
|
label: "OpenAI",
|
|
35
35
|
baseUrl: "https://api.openai.com/v1",
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { errorMessage } from "../utils/helpers.js";
|
|
16
16
|
import type { SandboxConfig } from "./config.js";
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const max_output_chars = 100_000;
|
|
19
19
|
|
|
20
20
|
export interface OpenSandboxBackendOptions {
|
|
21
21
|
sandbox: Sandbox;
|
|
@@ -58,11 +58,11 @@ const formatExecution = (execution: CommandExecution): ExecuteResponse => {
|
|
|
58
58
|
const stdout = execution.logs.stdout.map((message) => message.text);
|
|
59
59
|
const stderr = execution.logs.stderr.map((message) => `[stderr] ${message.text}`);
|
|
60
60
|
const output = [...stdout, ...stderr].join("\n");
|
|
61
|
-
const truncated = output.length >
|
|
61
|
+
const truncated = output.length > max_output_chars;
|
|
62
62
|
const exitCode = execution.exitCode ?? execution.error?.exitCode ?? (execution.error ? 1 : 0);
|
|
63
63
|
|
|
64
64
|
return {
|
|
65
|
-
output: truncated ? `${output.slice(0,
|
|
65
|
+
output: truncated ? `${output.slice(0, max_output_chars)}\n… 输出已截断` : output,
|
|
66
66
|
exitCode,
|
|
67
67
|
truncated,
|
|
68
68
|
};
|
|
@@ -4,7 +4,7 @@ export type { SkillMetadata } from "./loader.js";
|
|
|
4
4
|
export { discoverSkills, parseSkillFrontmatter } from "./loader.js";
|
|
5
5
|
|
|
6
6
|
/** Deep Agents skills 中间件扫描的虚拟后端路径。 */
|
|
7
|
-
export const
|
|
7
|
+
export const default_skill_sources = ["/skills/"] as const;
|
|
8
8
|
|
|
9
9
|
export interface LoadSkillsOptions {
|
|
10
10
|
rootDir: string;
|
|
@@ -5,7 +5,7 @@ import type { AppConfig } from "../../config/index.js";
|
|
|
5
5
|
export type { Logger };
|
|
6
6
|
|
|
7
7
|
/** `LOG_PRETTY=true` 时使用的 pino-pretty 传输配置。 */
|
|
8
|
-
const
|
|
8
|
+
const pretty_transport = {
|
|
9
9
|
transport: {
|
|
10
10
|
target: "pino-pretty",
|
|
11
11
|
options: {
|
|
@@ -20,6 +20,6 @@ export const createLogger = (config: Pick<AppConfig, "env" | "logging">): Logger
|
|
|
20
20
|
return pino({
|
|
21
21
|
level: config.logging.level,
|
|
22
22
|
base: { service: "deepagent", env: config.env.NODE_ENV },
|
|
23
|
-
...(config.logging.pretty ?
|
|
23
|
+
...(config.logging.pretty ? pretty_transport : {}),
|
|
24
24
|
});
|
|
25
25
|
};
|
|
@@ -3,8 +3,8 @@ import { z } from "zod";
|
|
|
3
3
|
|
|
4
4
|
import { getPool } from "../../storage/database/client.js";
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const read_only_start = /^\s*(?:select|with)\b/i;
|
|
7
|
+
const forbidden_keywords =
|
|
8
8
|
/\b(insert|update|delete|drop|alter|truncate|create|grant|revoke|copy|vacuum|reindex|call|do)\b/i;
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -14,13 +14,13 @@ const FORBIDDEN_KEYWORDS =
|
|
|
14
14
|
export const assertReadOnlyQuery = (sql: string): void => {
|
|
15
15
|
const statement = sql.trim().replace(/;\s*$/, "");
|
|
16
16
|
|
|
17
|
-
if (!
|
|
17
|
+
if (!read_only_start.test(statement)) {
|
|
18
18
|
throw new Error("只允许 SELECT 和 WITH 查询。");
|
|
19
19
|
}
|
|
20
20
|
if (statement.includes(";")) {
|
|
21
21
|
throw new Error("只允许单条 SQL 语句。");
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (forbidden_keywords.test(statement)) {
|
|
24
24
|
throw new Error("查询包含写入或 DDL 关键字,已拒绝执行。");
|
|
25
25
|
}
|
|
26
26
|
};
|