opc-agent 1.3.2 → 2.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.
- package/.github/ISSUE_TEMPLATE/bug_report.md +20 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +14 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/.github/workflows/ci.yml +24 -0
- package/CHANGELOG.md +48 -63
- package/CONTRIBUTING.md +21 -60
- package/README.md +284 -348
- package/README.zh-CN.md +415 -415
- package/dist/channels/slack.js +93 -10
- package/dist/channels/telegram.d.ts +30 -9
- package/dist/channels/telegram.js +125 -33
- package/dist/channels/web.d.ts +10 -0
- package/dist/channels/web.js +33 -2
- package/dist/cli.js +667 -65
- package/dist/core/agent.d.ts +23 -0
- package/dist/core/agent.js +120 -3
- package/dist/core/runtime.d.ts +5 -0
- package/dist/core/runtime.js +71 -0
- package/dist/core/scheduler.d.ts +52 -0
- package/dist/core/scheduler.js +168 -0
- package/dist/core/subagent.d.ts +28 -0
- package/dist/core/subagent.js +65 -0
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.js +134 -0
- package/dist/deploy/hermes.js +22 -22
- package/dist/deploy/openclaw.js +31 -40
- package/dist/index.d.ts +10 -10
- package/dist/index.js +22 -15
- package/dist/providers/index.d.ts +6 -2
- package/dist/providers/index.js +22 -9
- package/dist/schema/oad.d.ts +180 -6
- package/dist/schema/oad.js +12 -1
- package/dist/skills/auto-learn.d.ts +28 -0
- package/dist/skills/auto-learn.js +257 -0
- package/dist/templates/code-reviewer.d.ts +0 -8
- package/dist/templates/code-reviewer.js +5 -9
- package/dist/templates/customer-service.d.ts +0 -8
- package/dist/templates/customer-service.js +2 -6
- package/dist/templates/data-analyst.d.ts +0 -8
- package/dist/templates/data-analyst.js +5 -9
- package/dist/templates/knowledge-base.d.ts +0 -8
- package/dist/templates/knowledge-base.js +2 -6
- package/dist/templates/sales-assistant.d.ts +0 -8
- package/dist/templates/sales-assistant.js +4 -8
- package/dist/templates/teacher.d.ts +0 -8
- package/dist/templates/teacher.js +6 -10
- package/dist/tools/builtin/datetime.d.ts +3 -0
- package/dist/tools/builtin/datetime.js +44 -0
- package/dist/tools/builtin/file.d.ts +3 -0
- package/dist/tools/builtin/file.js +151 -0
- package/dist/tools/builtin/index.d.ts +15 -0
- package/dist/tools/builtin/index.js +30 -0
- package/dist/tools/builtin/shell.d.ts +3 -0
- package/dist/tools/builtin/shell.js +43 -0
- package/dist/tools/builtin/web.d.ts +3 -0
- package/dist/tools/builtin/web.js +37 -0
- package/dist/tools/mcp-client.d.ts +24 -0
- package/dist/tools/mcp-client.js +119 -0
- package/dist/traces/index.d.ts +49 -0
- package/dist/traces/index.js +102 -0
- package/docs/.vitepress/config.ts +103 -103
- package/docs/api/cli.md +48 -48
- package/docs/api/oad-schema.md +64 -64
- package/docs/api/sdk.md +80 -80
- package/docs/guide/concepts.md +51 -51
- package/docs/guide/configuration.md +79 -79
- package/docs/guide/deployment.md +42 -42
- package/docs/guide/getting-started.md +44 -44
- package/docs/guide/templates.md +28 -28
- package/docs/guide/testing.md +84 -84
- package/docs/index.md +27 -27
- package/docs/zh/api/cli.md +54 -54
- package/docs/zh/api/oad-schema.md +87 -87
- package/docs/zh/api/sdk.md +102 -102
- package/docs/zh/guide/concepts.md +104 -104
- package/docs/zh/guide/configuration.md +135 -135
- package/docs/zh/guide/deployment.md +81 -81
- package/docs/zh/guide/getting-started.md +82 -82
- package/docs/zh/guide/templates.md +84 -84
- package/docs/zh/guide/testing.md +88 -88
- package/docs/zh/index.md +27 -27
- package/examples/README.md +22 -0
- package/examples/basic-agent.ts +90 -0
- package/examples/brain-integration.ts +71 -0
- package/examples/customer-service-demo/README.md +90 -90
- package/examples/customer-service-demo/oad.yaml +107 -107
- package/examples/multi-channel.ts +74 -0
- package/package.json +1 -1
- package/src/analytics/index.ts +66 -66
- package/src/channels/discord.ts +192 -192
- package/src/channels/email.ts +177 -177
- package/src/channels/feishu.ts +236 -236
- package/src/channels/index.ts +15 -15
- package/src/channels/slack.ts +217 -160
- package/src/channels/telegram.ts +155 -33
- package/src/channels/voice.ts +106 -106
- package/src/channels/web.ts +38 -2
- package/src/channels/webhook.ts +199 -199
- package/src/channels/websocket.ts +87 -87
- package/src/channels/wechat.ts +149 -149
- package/src/cli.ts +697 -63
- package/src/core/a2a.ts +143 -143
- package/src/core/agent.ts +146 -3
- package/src/core/analytics-engine.ts +186 -186
- package/src/core/auth.ts +57 -57
- package/src/core/cache.ts +141 -141
- package/src/core/compose.ts +77 -77
- package/src/core/config.ts +14 -14
- package/src/core/errors.ts +148 -148
- package/src/core/hitl.ts +138 -138
- package/src/core/logger.ts +57 -57
- package/src/core/orchestrator.ts +215 -215
- package/src/core/performance.ts +187 -187
- package/src/core/rate-limiter.ts +128 -128
- package/src/core/room.ts +109 -109
- package/src/core/runtime.ts +230 -152
- package/src/core/sandbox.ts +101 -101
- package/src/core/scheduler.ts +187 -0
- package/src/core/security.ts +171 -171
- package/src/core/subagent.ts +98 -0
- package/src/core/types.ts +68 -68
- package/src/core/versioning.ts +106 -106
- package/src/core/watch.ts +178 -178
- package/src/core/workflow.ts +235 -235
- package/src/daemon.ts +96 -0
- package/src/deploy/hermes.ts +156 -156
- package/src/deploy/openclaw.ts +190 -200
- package/src/i18n/index.ts +216 -216
- package/src/index.ts +14 -10
- package/src/memory/deepbrain.ts +108 -108
- package/src/memory/index.ts +34 -34
- package/src/plugins/index.ts +208 -208
- package/src/providers/index.ts +354 -331
- package/src/schema/oad.ts +14 -2
- package/src/skills/auto-learn.ts +262 -0
- package/src/skills/base.ts +16 -16
- package/src/skills/document.ts +100 -100
- package/src/skills/http.ts +35 -35
- package/src/skills/index.ts +27 -27
- package/src/skills/scheduler.ts +80 -80
- package/src/skills/webhook-trigger.ts +59 -59
- package/src/templates/code-reviewer.ts +30 -34
- package/src/templates/customer-service.ts +76 -80
- package/src/templates/data-analyst.ts +66 -70
- package/src/templates/executive-assistant.ts +71 -71
- package/src/templates/financial-advisor.ts +60 -60
- package/src/templates/knowledge-base.ts +27 -31
- package/src/templates/legal-assistant.ts +71 -71
- package/src/templates/sales-assistant.ts +75 -79
- package/src/templates/teacher.ts +75 -79
- package/src/testing/index.ts +181 -181
- package/src/tools/builtin/datetime.ts +41 -0
- package/src/tools/builtin/file.ts +107 -0
- package/src/tools/builtin/index.ts +28 -0
- package/src/tools/builtin/shell.ts +43 -0
- package/src/tools/builtin/web.ts +35 -0
- package/src/tools/calculator.ts +73 -73
- package/src/tools/datetime.ts +149 -149
- package/src/tools/json-transform.ts +187 -187
- package/src/tools/mcp-client.ts +131 -0
- package/src/tools/mcp.ts +76 -76
- package/src/tools/text-analysis.ts +116 -116
- package/src/traces/index.ts +132 -0
- package/templates/Dockerfile +15 -15
- package/templates/code-reviewer/README.md +27 -27
- package/templates/code-reviewer/oad.yaml +41 -41
- package/templates/customer-service/README.md +22 -22
- package/templates/customer-service/oad.yaml +36 -36
- package/templates/docker-compose.yml +21 -21
- package/templates/ecommerce-assistant/README.md +45 -45
- package/templates/ecommerce-assistant/oad.yaml +47 -47
- package/templates/knowledge-base/README.md +28 -28
- package/templates/knowledge-base/oad.yaml +38 -38
- package/templates/sales-assistant/README.md +26 -26
- package/templates/sales-assistant/oad.yaml +43 -43
- package/templates/tech-support/README.md +43 -43
- package/templates/tech-support/oad.yaml +45 -45
- package/test-agent/Dockerfile +9 -0
- package/test-agent/README.md +50 -0
- package/test-agent/agent.yaml +23 -0
- package/test-agent/docker-compose.yml +11 -0
- package/test-agent/oad.yaml +31 -0
- package/test-agent/package-lock.json +1492 -0
- package/test-agent/package.json +18 -0
- package/test-agent/src/index.ts +24 -0
- package/test-agent/src/skills/echo.ts +15 -0
- package/test-agent/tsconfig.json +25 -0
- package/tests/a2a.test.ts +66 -66
- package/tests/agent.test.ts +72 -72
- package/tests/analytics.test.ts +50 -50
- package/tests/auto-learn.test.ts +105 -0
- package/tests/builtin-tools.test.ts +83 -0
- package/tests/channel.test.ts +39 -39
- package/tests/cli.test.ts +46 -0
- package/tests/e2e.test.ts +134 -134
- package/tests/errors.test.ts +83 -83
- package/tests/hitl.test.ts +71 -71
- package/tests/i18n.test.ts +41 -41
- package/tests/mcp.test.ts +54 -54
- package/tests/oad.test.ts +68 -68
- package/tests/performance.test.ts +115 -115
- package/tests/plugin.test.ts +74 -74
- package/tests/room.test.ts +106 -106
- package/tests/runtime.test.ts +42 -42
- package/tests/sandbox.test.ts +46 -46
- package/tests/security.test.ts +60 -60
- package/tests/subagent.test.ts +130 -0
- package/tests/telegram-discord.test.ts +60 -0
- package/tests/templates.test.ts +77 -77
- package/tests/v070.test.ts +76 -76
- package/tests/versioning.test.ts +75 -75
- package/tests/voice.test.ts +61 -61
- package/tests/webhook.test.ts +29 -29
- package/tests/workflow.test.ts +143 -143
- package/tsconfig.json +19 -19
- package/vitest.config.ts +9 -9
- package/dist/core/dashboard.d.ts +0 -35
- package/dist/core/dashboard.js +0 -157
- package/dist/core/priority.d.ts +0 -52
- package/dist/core/priority.js +0 -102
- package/src/core/dashboard.ts +0 -219
- package/src/core/priority.ts +0 -140
- package/src/dtv/data.ts +0 -29
- package/src/dtv/trust.ts +0 -43
- package/src/dtv/value.ts +0 -47
- package/src/marketplace/index.ts +0 -223
|
@@ -33,11 +33,11 @@ class InsightSkill extends base_1.BaseSkill {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.InsightSkill = InsightSkill;
|
|
36
|
-
exports.DATA_ANALYST_SYSTEM_PROMPT = `You are a professional data analyst assistant. Your goals:
|
|
37
|
-
1. Help users query, transform, and analyze data
|
|
38
|
-
2. Create clear visualizations and summaries
|
|
39
|
-
3. Identify trends, patterns, and anomalies
|
|
40
|
-
4. Explain findings in plain language
|
|
36
|
+
exports.DATA_ANALYST_SYSTEM_PROMPT = `You are a professional data analyst assistant. Your goals:
|
|
37
|
+
1. Help users query, transform, and analyze data
|
|
38
|
+
2. Create clear visualizations and summaries
|
|
39
|
+
3. Identify trends, patterns, and anomalies
|
|
40
|
+
4. Explain findings in plain language
|
|
41
41
|
Be precise with numbers, always cite your data source, and suggest next steps for deeper analysis.`;
|
|
42
42
|
function createDataAnalystConfig() {
|
|
43
43
|
return {
|
|
@@ -60,10 +60,6 @@ function createDataAnalystConfig() {
|
|
|
60
60
|
],
|
|
61
61
|
channels: [{ type: 'web', port: 3000 }],
|
|
62
62
|
memory: { shortTerm: true, longTerm: true },
|
|
63
|
-
dtv: {
|
|
64
|
-
trust: { level: 'sandbox' },
|
|
65
|
-
value: { metrics: ['queries_processed', 'insights_generated'] },
|
|
66
|
-
},
|
|
67
63
|
},
|
|
68
64
|
};
|
|
69
65
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KNOWLEDGE_BASE_SYSTEM_PROMPT = void 0;
|
|
4
4
|
exports.createKnowledgeBaseConfig = createKnowledgeBaseConfig;
|
|
5
|
-
exports.KNOWLEDGE_BASE_SYSTEM_PROMPT = `You are a knowledge base assistant. Answer questions using the company documents
|
|
6
|
-
and knowledge provided to you. If you don't have enough information, say so honestly.
|
|
5
|
+
exports.KNOWLEDGE_BASE_SYSTEM_PROMPT = `You are a knowledge base assistant. Answer questions using the company documents
|
|
6
|
+
and knowledge provided to you. If you don't have enough information, say so honestly.
|
|
7
7
|
Always cite sources when possible. Be accurate and concise.`;
|
|
8
8
|
function createKnowledgeBaseConfig() {
|
|
9
9
|
return {
|
|
@@ -25,10 +25,6 @@ function createKnowledgeBaseConfig() {
|
|
|
25
25
|
],
|
|
26
26
|
channels: [{ type: 'web', port: 3000 }],
|
|
27
27
|
memory: { shortTerm: true, longTerm: { provider: 'deepbrain', collection: 'company-knowledge' } },
|
|
28
|
-
dtv: {
|
|
29
|
-
trust: { level: 'sandbox' },
|
|
30
|
-
value: { metrics: ['queries_answered', 'docs_indexed'] },
|
|
31
|
-
},
|
|
32
28
|
},
|
|
33
29
|
};
|
|
34
30
|
}
|
|
@@ -43,14 +43,6 @@ export declare function createSalesAssistantConfig(): {
|
|
|
43
43
|
shortTerm: boolean;
|
|
44
44
|
longTerm: boolean;
|
|
45
45
|
};
|
|
46
|
-
dtv: {
|
|
47
|
-
trust: {
|
|
48
|
-
level: "sandbox";
|
|
49
|
-
};
|
|
50
|
-
value: {
|
|
51
|
-
metrics: string[];
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
46
|
};
|
|
55
47
|
};
|
|
56
48
|
//# sourceMappingURL=sales-assistant.d.ts.map
|
|
@@ -43,10 +43,10 @@ class LeadCaptureSkill extends base_1.BaseSkill {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.LeadCaptureSkill = LeadCaptureSkill;
|
|
46
|
-
exports.SALES_ASSISTANT_SYSTEM_PROMPT = `You are a professional sales assistant. Your goals:
|
|
47
|
-
1. Answer product questions accurately and enthusiastically
|
|
48
|
-
2. Capture leads by collecting name, email, and company info
|
|
49
|
-
3. Book appointments when prospects are ready
|
|
46
|
+
exports.SALES_ASSISTANT_SYSTEM_PROMPT = `You are a professional sales assistant. Your goals:
|
|
47
|
+
1. Answer product questions accurately and enthusiastically
|
|
48
|
+
2. Capture leads by collecting name, email, and company info
|
|
49
|
+
3. Book appointments when prospects are ready
|
|
50
50
|
Be friendly, persuasive but not pushy. Always provide value first.`;
|
|
51
51
|
function createSalesAssistantConfig() {
|
|
52
52
|
return {
|
|
@@ -69,10 +69,6 @@ function createSalesAssistantConfig() {
|
|
|
69
69
|
],
|
|
70
70
|
channels: [{ type: 'web', port: 3000 }],
|
|
71
71
|
memory: { shortTerm: true, longTerm: false },
|
|
72
|
-
dtv: {
|
|
73
|
-
trust: { level: 'sandbox' },
|
|
74
|
-
value: { metrics: ['leads_captured', 'appointments_booked'] },
|
|
75
|
-
},
|
|
76
72
|
},
|
|
77
73
|
};
|
|
78
74
|
}
|
|
@@ -45,14 +45,6 @@ export declare function createTeacherConfig(): {
|
|
|
45
45
|
shortTerm: boolean;
|
|
46
46
|
longTerm: boolean;
|
|
47
47
|
};
|
|
48
|
-
dtv: {
|
|
49
|
-
trust: {
|
|
50
|
-
level: "sandbox";
|
|
51
|
-
};
|
|
52
|
-
value: {
|
|
53
|
-
metrics: string[];
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
48
|
};
|
|
57
49
|
};
|
|
58
50
|
//# sourceMappingURL=teacher.d.ts.map
|
|
@@ -39,12 +39,12 @@ class ExplainSkill extends base_1.BaseSkill {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.ExplainSkill = ExplainSkill;
|
|
42
|
-
exports.TEACHER_SYSTEM_PROMPT = `You are a patient and encouraging teacher assistant. Your goals:
|
|
43
|
-
1. Create engaging lesson plans tailored to student level
|
|
44
|
-
2. Generate quizzes and assessments with answer keys
|
|
45
|
-
3. Explain complex concepts using analogies and examples
|
|
46
|
-
4. Provide constructive feedback and encouragement
|
|
47
|
-
5. Adapt teaching style to different learning preferences
|
|
42
|
+
exports.TEACHER_SYSTEM_PROMPT = `You are a patient and encouraging teacher assistant. Your goals:
|
|
43
|
+
1. Create engaging lesson plans tailored to student level
|
|
44
|
+
2. Generate quizzes and assessments with answer keys
|
|
45
|
+
3. Explain complex concepts using analogies and examples
|
|
46
|
+
4. Provide constructive feedback and encouragement
|
|
47
|
+
5. Adapt teaching style to different learning preferences
|
|
48
48
|
Be patient, use clear language, and always check for understanding. Use the Socratic method when appropriate.`;
|
|
49
49
|
function createTeacherConfig() {
|
|
50
50
|
return {
|
|
@@ -68,10 +68,6 @@ function createTeacherConfig() {
|
|
|
68
68
|
],
|
|
69
69
|
channels: [{ type: 'web', port: 3000 }],
|
|
70
70
|
memory: { shortTerm: true, longTerm: true },
|
|
71
|
-
dtv: {
|
|
72
|
-
trust: { level: 'sandbox' },
|
|
73
|
-
value: { metrics: ['lessons_created', 'quizzes_generated', 'concepts_explained'] },
|
|
74
|
-
},
|
|
75
71
|
},
|
|
76
72
|
};
|
|
77
73
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.datetimeTool = void 0;
|
|
4
|
+
exports.datetimeTool = {
|
|
5
|
+
name: 'datetime',
|
|
6
|
+
description: 'Get current date, time, timezone info',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
format: { type: 'string', default: 'iso' },
|
|
11
|
+
timezone: { type: 'string' },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const now = new Date();
|
|
16
|
+
const timezone = input.timezone;
|
|
17
|
+
const format = input.format || 'iso';
|
|
18
|
+
let content;
|
|
19
|
+
if (format === 'iso') {
|
|
20
|
+
content = now.toISOString();
|
|
21
|
+
}
|
|
22
|
+
else if (format === 'locale') {
|
|
23
|
+
content = timezone
|
|
24
|
+
? now.toLocaleString('en-US', { timeZone: timezone })
|
|
25
|
+
: now.toLocaleString();
|
|
26
|
+
}
|
|
27
|
+
else if (format === 'unix') {
|
|
28
|
+
content = String(Math.floor(now.getTime() / 1000));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
content = now.toISOString();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
content: JSON.stringify({
|
|
35
|
+
iso: now.toISOString(),
|
|
36
|
+
unix: Math.floor(now.getTime() / 1000),
|
|
37
|
+
formatted: content,
|
|
38
|
+
timezone: timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
39
|
+
}),
|
|
40
|
+
isError: false,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=datetime.js.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.fileTool = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
function resolveSafe(basePath, targetPath) {
|
|
40
|
+
const resolved = path.resolve(basePath, targetPath);
|
|
41
|
+
if (!resolved.startsWith(path.resolve(basePath)))
|
|
42
|
+
return null;
|
|
43
|
+
return resolved;
|
|
44
|
+
}
|
|
45
|
+
function searchFiles(dir, query, results = [], maxResults = 20) {
|
|
46
|
+
if (results.length >= maxResults)
|
|
47
|
+
return results;
|
|
48
|
+
try {
|
|
49
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (results.length >= maxResults)
|
|
52
|
+
break;
|
|
53
|
+
const full = path.join(dir, entry.name);
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
if (entry.name === 'node_modules' || entry.name === '.git')
|
|
56
|
+
continue;
|
|
57
|
+
searchFiles(full, query, results, maxResults);
|
|
58
|
+
}
|
|
59
|
+
else if (entry.isFile()) {
|
|
60
|
+
try {
|
|
61
|
+
const content = fs.readFileSync(full, 'utf-8');
|
|
62
|
+
const lines = content.split('\n');
|
|
63
|
+
for (let i = 0; i < lines.length; i++) {
|
|
64
|
+
if (lines[i].includes(query)) {
|
|
65
|
+
results.push(`${full}:${i + 1}: ${lines[i].trim()}`);
|
|
66
|
+
if (results.length >= maxResults)
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch { /* skip binary/unreadable */ }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch { /* skip inaccessible dirs */ }
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
exports.fileTool = {
|
|
79
|
+
name: 'file_operations',
|
|
80
|
+
description: 'Read, write, list, and search files in the workspace',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
action: { type: 'string', enum: ['read', 'write', 'list', 'search', 'exists'] },
|
|
85
|
+
path: { type: 'string' },
|
|
86
|
+
content: { type: 'string' },
|
|
87
|
+
query: { type: 'string' },
|
|
88
|
+
},
|
|
89
|
+
required: ['action'],
|
|
90
|
+
},
|
|
91
|
+
async execute(input, context) {
|
|
92
|
+
const action = input.action;
|
|
93
|
+
const workspace = process.cwd();
|
|
94
|
+
const targetPath = input.path;
|
|
95
|
+
if (action === 'search') {
|
|
96
|
+
const query = input.query;
|
|
97
|
+
if (!query)
|
|
98
|
+
return { content: 'query is required for search', isError: true };
|
|
99
|
+
const results = searchFiles(workspace, query);
|
|
100
|
+
return { content: results.length ? results.join('\n') : 'No matches found', isError: false };
|
|
101
|
+
}
|
|
102
|
+
if (action === 'list') {
|
|
103
|
+
const dir = targetPath ? resolveSafe(workspace, targetPath) : workspace;
|
|
104
|
+
if (!dir)
|
|
105
|
+
return { content: 'Path outside workspace', isError: true };
|
|
106
|
+
try {
|
|
107
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
108
|
+
const listing = entries.map(e => `${e.isDirectory() ? '[DIR] ' : ''}${e.name}`).join('\n');
|
|
109
|
+
return { content: listing || '(empty directory)', isError: false };
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
return { content: `Error listing directory: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!targetPath)
|
|
116
|
+
return { content: 'path is required', isError: true };
|
|
117
|
+
const resolved = resolveSafe(workspace, targetPath);
|
|
118
|
+
if (!resolved)
|
|
119
|
+
return { content: 'Path outside workspace', isError: true };
|
|
120
|
+
switch (action) {
|
|
121
|
+
case 'read': {
|
|
122
|
+
try {
|
|
123
|
+
const content = fs.readFileSync(resolved, 'utf-8');
|
|
124
|
+
return { content: content.slice(0, 50000), isError: false };
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
return { content: `Error reading file: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
case 'write': {
|
|
131
|
+
const content = input.content;
|
|
132
|
+
if (content === undefined)
|
|
133
|
+
return { content: 'content is required for write', isError: true };
|
|
134
|
+
try {
|
|
135
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
136
|
+
fs.writeFileSync(resolved, content, 'utf-8');
|
|
137
|
+
return { content: `Written ${content.length} bytes to ${targetPath}`, isError: false };
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
return { content: `Error writing file: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
case 'exists': {
|
|
144
|
+
return { content: String(fs.existsSync(resolved)), isError: false };
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return { content: `Unknown action: ${action}`, isError: true };
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MCPTool } from '../mcp';
|
|
2
|
+
import { fileTool } from './file';
|
|
3
|
+
import { webTool } from './web';
|
|
4
|
+
import { shellTool } from './shell';
|
|
5
|
+
import { datetimeTool } from './datetime';
|
|
6
|
+
export { fileTool, webTool, shellTool, datetimeTool };
|
|
7
|
+
/**
|
|
8
|
+
* Get all built-in tools.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBuiltinTools(): MCPTool[];
|
|
11
|
+
/**
|
|
12
|
+
* Get specific built-in tools by name. If no names given, returns all.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getBuiltinToolsByName(names?: string[]): MCPTool[];
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.datetimeTool = exports.shellTool = exports.webTool = exports.fileTool = void 0;
|
|
4
|
+
exports.getBuiltinTools = getBuiltinTools;
|
|
5
|
+
exports.getBuiltinToolsByName = getBuiltinToolsByName;
|
|
6
|
+
const file_1 = require("./file");
|
|
7
|
+
Object.defineProperty(exports, "fileTool", { enumerable: true, get: function () { return file_1.fileTool; } });
|
|
8
|
+
const web_1 = require("./web");
|
|
9
|
+
Object.defineProperty(exports, "webTool", { enumerable: true, get: function () { return web_1.webTool; } });
|
|
10
|
+
const shell_1 = require("./shell");
|
|
11
|
+
Object.defineProperty(exports, "shellTool", { enumerable: true, get: function () { return shell_1.shellTool; } });
|
|
12
|
+
const datetime_1 = require("./datetime");
|
|
13
|
+
Object.defineProperty(exports, "datetimeTool", { enumerable: true, get: function () { return datetime_1.datetimeTool; } });
|
|
14
|
+
const ALL_BUILTIN_TOOLS = [file_1.fileTool, web_1.webTool, shell_1.shellTool, datetime_1.datetimeTool];
|
|
15
|
+
const BUILTIN_MAP = new Map(ALL_BUILTIN_TOOLS.map(t => [t.name, t]));
|
|
16
|
+
/**
|
|
17
|
+
* Get all built-in tools.
|
|
18
|
+
*/
|
|
19
|
+
function getBuiltinTools() {
|
|
20
|
+
return [...ALL_BUILTIN_TOOLS];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get specific built-in tools by name. If no names given, returns all.
|
|
24
|
+
*/
|
|
25
|
+
function getBuiltinToolsByName(names) {
|
|
26
|
+
if (!names || names.length === 0)
|
|
27
|
+
return getBuiltinTools();
|
|
28
|
+
return names.map(n => BUILTIN_MAP.get(n)).filter((t) => !!t);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shellTool = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
exports.shellTool = {
|
|
6
|
+
name: 'shell_exec',
|
|
7
|
+
description: 'Execute a shell command (sandboxed to workspace)',
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
command: { type: 'string' },
|
|
12
|
+
timeout: { type: 'number', default: 30000 },
|
|
13
|
+
},
|
|
14
|
+
required: ['command'],
|
|
15
|
+
},
|
|
16
|
+
async execute(input) {
|
|
17
|
+
const command = input.command;
|
|
18
|
+
const timeout = input.timeout || 30000;
|
|
19
|
+
const workspace = process.cwd();
|
|
20
|
+
// Block path traversal attempts
|
|
21
|
+
if (command.includes('..')) {
|
|
22
|
+
return { content: 'Commands with ".." are not allowed for security', isError: true };
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const output = (0, child_process_1.execSync)(command, {
|
|
26
|
+
cwd: workspace,
|
|
27
|
+
timeout,
|
|
28
|
+
encoding: 'utf-8',
|
|
29
|
+
maxBuffer: 1024 * 1024,
|
|
30
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
31
|
+
});
|
|
32
|
+
const result = (output || '').slice(0, 5000);
|
|
33
|
+
return { content: result || '(no output)', isError: false };
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
const stderr = err.stderr ? String(err.stderr).slice(0, 2500) : '';
|
|
37
|
+
const stdout = err.stdout ? String(err.stdout).slice(0, 2500) : '';
|
|
38
|
+
const output = [stdout, stderr].filter(Boolean).join('\n') || err.message;
|
|
39
|
+
return { content: `Command failed: ${output.slice(0, 5000)}`, isError: true };
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webTool = void 0;
|
|
4
|
+
exports.webTool = {
|
|
5
|
+
name: 'web_fetch',
|
|
6
|
+
description: 'Fetch content from a URL',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
url: { type: 'string' },
|
|
11
|
+
method: { type: 'string', enum: ['GET', 'POST'], default: 'GET' },
|
|
12
|
+
maxLength: { type: 'number', default: 5000 },
|
|
13
|
+
},
|
|
14
|
+
required: ['url'],
|
|
15
|
+
},
|
|
16
|
+
async execute(input) {
|
|
17
|
+
const url = input.url;
|
|
18
|
+
const method = input.method || 'GET';
|
|
19
|
+
const maxLength = input.maxLength || 5000;
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(url, { method, signal: AbortSignal.timeout(15000) });
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
const truncated = text.length > maxLength ? text.slice(0, maxLength) + '\n...[truncated]' : text;
|
|
24
|
+
return {
|
|
25
|
+
content: `Status: ${response.status}\n\n${truncated}`,
|
|
26
|
+
isError: false,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return {
|
|
31
|
+
content: `Fetch error: ${err instanceof Error ? err.message : String(err)}`,
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MCPToolDefinition, MCPToolResult } from './mcp';
|
|
2
|
+
export interface MCPServerConfig {
|
|
3
|
+
name: string;
|
|
4
|
+
command: string;
|
|
5
|
+
args?: string[];
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare class MCPClient {
|
|
9
|
+
private process;
|
|
10
|
+
private config;
|
|
11
|
+
private nextId;
|
|
12
|
+
private pending;
|
|
13
|
+
private buffer;
|
|
14
|
+
private connected;
|
|
15
|
+
connect(config: MCPServerConfig): Promise<void>;
|
|
16
|
+
private processBuffer;
|
|
17
|
+
private sendRequest;
|
|
18
|
+
private sendNotification;
|
|
19
|
+
listTools(): Promise<MCPToolDefinition[]>;
|
|
20
|
+
callTool(name: string, input: Record<string, unknown>): Promise<MCPToolResult>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
isConnected(): boolean;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=mcp-client.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCPClient = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
class MCPClient {
|
|
6
|
+
process = null;
|
|
7
|
+
config = null;
|
|
8
|
+
nextId = 1;
|
|
9
|
+
pending = new Map();
|
|
10
|
+
buffer = '';
|
|
11
|
+
connected = false;
|
|
12
|
+
async connect(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.process = (0, child_process_1.spawn)(config.command, config.args ?? [], {
|
|
15
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
16
|
+
env: { ...process.env, ...config.env },
|
|
17
|
+
});
|
|
18
|
+
this.process.stdout.on('data', (data) => {
|
|
19
|
+
this.buffer += data.toString();
|
|
20
|
+
this.processBuffer();
|
|
21
|
+
});
|
|
22
|
+
this.process.on('error', (err) => {
|
|
23
|
+
for (const [, p] of this.pending)
|
|
24
|
+
p.reject(err);
|
|
25
|
+
this.pending.clear();
|
|
26
|
+
});
|
|
27
|
+
this.process.on('exit', () => {
|
|
28
|
+
this.connected = false;
|
|
29
|
+
for (const [, p] of this.pending)
|
|
30
|
+
p.reject(new Error('MCP server exited'));
|
|
31
|
+
this.pending.clear();
|
|
32
|
+
});
|
|
33
|
+
// Send initialize
|
|
34
|
+
await this.sendRequest('initialize', {
|
|
35
|
+
protocolVersion: '2024-11-05',
|
|
36
|
+
capabilities: {},
|
|
37
|
+
clientInfo: { name: 'opc-agent', version: '0.7.0' },
|
|
38
|
+
});
|
|
39
|
+
// Send initialized notification
|
|
40
|
+
this.sendNotification('notifications/initialized', {});
|
|
41
|
+
this.connected = true;
|
|
42
|
+
}
|
|
43
|
+
processBuffer() {
|
|
44
|
+
const lines = this.buffer.split('\n');
|
|
45
|
+
this.buffer = lines.pop() ?? '';
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
const trimmed = line.trim();
|
|
48
|
+
if (!trimmed)
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
const msg = JSON.parse(trimmed);
|
|
52
|
+
if (msg.id !== undefined && this.pending.has(msg.id)) {
|
|
53
|
+
const p = this.pending.get(msg.id);
|
|
54
|
+
this.pending.delete(msg.id);
|
|
55
|
+
if (msg.error) {
|
|
56
|
+
p.reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
p.resolve(msg.result);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch { /* skip non-JSON lines */ }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
sendRequest(method, params) {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
if (!this.process?.stdin?.writable) {
|
|
69
|
+
reject(new Error('MCP server not connected'));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const id = this.nextId++;
|
|
73
|
+
this.pending.set(id, { resolve, reject });
|
|
74
|
+
const msg = JSON.stringify({ jsonrpc: '2.0', method, params: params ?? {}, id });
|
|
75
|
+
this.process.stdin.write(msg + '\n');
|
|
76
|
+
// Timeout after 30s
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
if (this.pending.has(id)) {
|
|
79
|
+
this.pending.delete(id);
|
|
80
|
+
reject(new Error(`MCP request timed out: ${method}`));
|
|
81
|
+
}
|
|
82
|
+
}, 30000);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
sendNotification(method, params) {
|
|
86
|
+
if (!this.process?.stdin?.writable)
|
|
87
|
+
return;
|
|
88
|
+
const msg = JSON.stringify({ jsonrpc: '2.0', method, params });
|
|
89
|
+
this.process.stdin.write(msg + '\n');
|
|
90
|
+
}
|
|
91
|
+
async listTools() {
|
|
92
|
+
const result = await this.sendRequest('tools/list');
|
|
93
|
+
return (result.tools ?? []).map((t) => ({
|
|
94
|
+
name: t.name,
|
|
95
|
+
description: t.description ?? '',
|
|
96
|
+
inputSchema: t.inputSchema ?? {},
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
async callTool(name, input) {
|
|
100
|
+
const result = await this.sendRequest('tools/call', { name, arguments: input });
|
|
101
|
+
const content = (result.content ?? [])
|
|
102
|
+
.map((c) => c.text ?? JSON.stringify(c))
|
|
103
|
+
.join('\n');
|
|
104
|
+
return { content, isError: result.isError ?? false };
|
|
105
|
+
}
|
|
106
|
+
async disconnect() {
|
|
107
|
+
if (this.process) {
|
|
108
|
+
this.process.kill();
|
|
109
|
+
this.process = null;
|
|
110
|
+
}
|
|
111
|
+
this.connected = false;
|
|
112
|
+
this.pending.clear();
|
|
113
|
+
}
|
|
114
|
+
isConnected() {
|
|
115
|
+
return this.connected;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.MCPClient = MCPClient;
|
|
119
|
+
//# sourceMappingURL=mcp-client.js.map
|