opc-agent 2.0.0 → 2.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/dist/channels/email.d.ts +32 -26
- package/dist/channels/email.js +239 -62
- package/dist/channels/feishu.d.ts +21 -6
- package/dist/channels/feishu.js +225 -126
- package/dist/channels/websocket.d.ts +46 -3
- package/dist/channels/websocket.js +306 -37
- package/dist/channels/wechat.d.ts +33 -13
- package/dist/channels/wechat.js +229 -42
- package/dist/cli.js +712 -11
- package/dist/core/a2a.d.ts +17 -0
- package/dist/core/a2a.js +43 -1
- package/dist/core/agent.d.ts +16 -0
- package/dist/core/agent.js +108 -0
- package/dist/core/runtime.d.ts +6 -0
- package/dist/core/runtime.js +161 -2
- package/dist/core/sandbox.d.ts +26 -0
- package/dist/core/sandbox.js +117 -0
- package/dist/core/workflow-graph.d.ts +93 -0
- package/dist/core/workflow-graph.js +247 -0
- package/dist/doctor.d.ts +15 -0
- package/dist/doctor.js +183 -0
- package/dist/eval/index.d.ts +65 -0
- package/dist/eval/index.js +191 -0
- package/dist/index.d.ts +30 -6
- package/dist/index.js +60 -4
- package/dist/plugins/content-filter.d.ts +7 -0
- package/dist/plugins/content-filter.js +25 -0
- package/dist/plugins/index.d.ts +42 -0
- package/dist/plugins/index.js +108 -2
- package/dist/plugins/logger.d.ts +6 -0
- package/dist/plugins/logger.js +20 -0
- package/dist/plugins/rate-limiter.d.ts +7 -0
- package/dist/plugins/rate-limiter.js +35 -0
- package/dist/protocols/a2a/client.d.ts +25 -0
- package/dist/protocols/a2a/client.js +115 -0
- package/dist/protocols/a2a/index.d.ts +6 -0
- package/dist/protocols/a2a/index.js +12 -0
- package/dist/protocols/a2a/server.d.ts +41 -0
- package/dist/protocols/a2a/server.js +295 -0
- package/dist/protocols/a2a/types.d.ts +91 -0
- package/dist/protocols/a2a/types.js +15 -0
- package/dist/protocols/a2a/utils.d.ts +6 -0
- package/dist/protocols/a2a/utils.js +47 -0
- package/dist/protocols/agui/client.d.ts +10 -0
- package/dist/protocols/agui/client.js +75 -0
- package/dist/protocols/agui/index.d.ts +4 -0
- package/dist/protocols/agui/index.js +25 -0
- package/dist/protocols/agui/server.d.ts +37 -0
- package/dist/protocols/agui/server.js +191 -0
- package/dist/protocols/agui/types.d.ts +107 -0
- package/dist/protocols/agui/types.js +17 -0
- package/dist/protocols/index.d.ts +2 -0
- package/dist/protocols/index.js +19 -0
- package/dist/protocols/mcp/agent-tools.d.ts +11 -0
- package/dist/protocols/mcp/agent-tools.js +129 -0
- package/dist/protocols/mcp/index.d.ts +5 -0
- package/dist/protocols/mcp/index.js +11 -0
- package/dist/protocols/mcp/server.d.ts +31 -0
- package/dist/protocols/mcp/server.js +248 -0
- package/dist/protocols/mcp/types.d.ts +92 -0
- package/dist/protocols/mcp/types.js +17 -0
- package/dist/publish/index.d.ts +45 -0
- package/dist/publish/index.js +350 -0
- package/dist/schema/oad.d.ts +682 -65
- package/dist/schema/oad.js +36 -3
- package/dist/security/approval.d.ts +36 -0
- package/dist/security/approval.js +113 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.js +8 -0
- package/dist/security/keys.d.ts +16 -0
- package/dist/security/keys.js +117 -0
- package/dist/studio/server.d.ts +63 -0
- package/dist/studio/server.js +625 -0
- package/dist/studio-ui/index.html +662 -0
- package/dist/telemetry/index.d.ts +93 -0
- package/dist/telemetry/index.js +285 -0
- package/package.json +5 -3
- package/scripts/install.ps1 +31 -0
- package/scripts/install.sh +40 -0
- package/src/channels/email.ts +351 -177
- package/src/channels/feishu.ts +349 -236
- package/src/channels/websocket.ts +399 -87
- package/src/channels/wechat.ts +329 -149
- package/src/cli.ts +783 -12
- package/src/core/a2a.ts +60 -0
- package/src/core/agent.ts +125 -0
- package/src/core/runtime.ts +127 -0
- package/src/core/sandbox.ts +143 -0
- package/src/core/workflow-graph.ts +365 -0
- package/src/doctor.ts +156 -0
- package/src/eval/index.ts +211 -0
- package/src/eval/suites/basic.json +16 -0
- package/src/eval/suites/memory.json +12 -0
- package/src/eval/suites/safety.json +14 -0
- package/src/index.ts +54 -6
- package/src/plugins/content-filter.ts +23 -0
- package/src/plugins/index.ts +133 -2
- package/src/plugins/logger.ts +18 -0
- package/src/plugins/rate-limiter.ts +38 -0
- package/src/protocols/a2a/client.ts +132 -0
- package/src/protocols/a2a/index.ts +8 -0
- package/src/protocols/a2a/server.ts +333 -0
- package/src/protocols/a2a/types.ts +88 -0
- package/src/protocols/a2a/utils.ts +50 -0
- package/src/protocols/agui/client.ts +83 -0
- package/src/protocols/agui/index.ts +4 -0
- package/src/protocols/agui/server.ts +218 -0
- package/src/protocols/agui/types.ts +153 -0
- package/src/protocols/index.ts +2 -0
- package/src/protocols/mcp/agent-tools.ts +134 -0
- package/src/protocols/mcp/index.ts +8 -0
- package/src/protocols/mcp/server.ts +262 -0
- package/src/protocols/mcp/types.ts +69 -0
- package/src/publish/index.ts +376 -0
- package/src/schema/oad.ts +39 -2
- package/src/security/approval.ts +131 -0
- package/src/security/index.ts +3 -0
- package/src/security/keys.ts +87 -0
- package/src/studio/server.ts +629 -0
- package/src/studio-ui/index.html +662 -0
- package/src/telemetry/index.ts +324 -0
- package/src/types/agent-workstation.d.ts +2 -0
- package/tests/a2a-protocol.test.ts +285 -0
- package/tests/agui-protocol.test.ts +246 -0
- package/tests/channels/discord.test.ts +79 -0
- package/tests/channels/email.test.ts +148 -0
- package/tests/channels/feishu.test.ts +123 -0
- package/tests/channels/telegram.test.ts +129 -0
- package/tests/channels/websocket.test.ts +53 -0
- package/tests/channels/wechat.test.ts +170 -0
- package/tests/chat-cli.test.ts +160 -0
- package/tests/daemon.test.ts +135 -0
- package/tests/deepbrain-wire.test.ts +234 -0
- package/tests/doctor.test.ts +38 -0
- package/tests/eval.test.ts +173 -0
- package/tests/init-role.test.ts +124 -0
- package/tests/mcp-client.test.ts +92 -0
- package/tests/mcp-server.test.ts +178 -0
- package/tests/plugin-a2a-enhanced.test.ts +230 -0
- package/tests/publish.test.ts +231 -0
- package/tests/scheduler.test.ts +200 -0
- package/tests/security-enhanced.test.ts +233 -0
- package/tests/skill-learner.test.ts +161 -0
- package/tests/studio.test.ts +229 -0
- package/tests/subagent.test.ts +63 -0
- package/tests/telemetry.test.ts +186 -0
- package/tests/tools/builtin-extended.test.ts +138 -0
- package/tests/workflow-graph.test.ts +279 -0
- package/tutorial/customer-service-agent/README.md +612 -0
- package/tutorial/customer-service-agent/SOUL.md +26 -0
- package/tutorial/customer-service-agent/agent.yaml +63 -0
- package/tutorial/customer-service-agent/package.json +19 -0
- package/tutorial/customer-service-agent/src/index.ts +69 -0
- package/tutorial/customer-service-agent/src/skills/faq.ts +27 -0
- package/tutorial/customer-service-agent/src/skills/ticket.ts +22 -0
- package/tutorial/customer-service-agent/tsconfig.json +14 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer Service Agent — Entry Point
|
|
3
|
+
* 客服 Agent 入口文件
|
|
4
|
+
*
|
|
5
|
+
* Demonstrates: Agent init, DeepBrain memory, skills, tools, workflows, plugins
|
|
6
|
+
*/
|
|
7
|
+
import { Agent, getBuiltinTools, WorkflowBuilder } from 'opc-agent';
|
|
8
|
+
import { loggerPlugin, rateLimiterPlugin } from 'opc-agent';
|
|
9
|
+
import { Brain } from 'deepbrain';
|
|
10
|
+
|
|
11
|
+
// === 1. DeepBrain 记忆初始化 / Initialize Memory ===
|
|
12
|
+
const brain = new Brain({
|
|
13
|
+
database: './data/customer-brain.db',
|
|
14
|
+
embedding_provider: 'ollama',
|
|
15
|
+
});
|
|
16
|
+
await brain.connect();
|
|
17
|
+
|
|
18
|
+
// === 2. 内置工具 / Built-in Tools ===
|
|
19
|
+
const tools = getBuiltinTools('./workspace');
|
|
20
|
+
|
|
21
|
+
// === 3. 创建 Agent / Create Agent ===
|
|
22
|
+
const agent = new Agent('./agent.yaml', {
|
|
23
|
+
tools,
|
|
24
|
+
plugins: [
|
|
25
|
+
loggerPlugin({ level: 'info', output: './logs/agent.log' }),
|
|
26
|
+
rateLimiterPlugin({ maxRequests: 60, windowMs: 60000 }),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// === 4. 记忆钩子 / Memory Hooks ===
|
|
31
|
+
agent.on('message', async (msg, response) => {
|
|
32
|
+
// 存储对话用于语义搜索 / Store conversations for semantic search
|
|
33
|
+
await brain.put(
|
|
34
|
+
`conv-${msg.id}`,
|
|
35
|
+
`Q: ${msg.content}\nA: ${response.content}`
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
agent.on('beforeReply', async (ctx) => {
|
|
40
|
+
// 搜索相关历史对话 / Search relevant past conversations
|
|
41
|
+
const relevant = await brain.query(ctx.message, { limit: 3 });
|
|
42
|
+
if (relevant.length > 0) {
|
|
43
|
+
ctx.additionalContext = relevant.map((r: { content: string }) => r.content).join('\n');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// === 5. 工作流 / Workflow: Customer Onboarding ===
|
|
48
|
+
const onboarding = new WorkflowBuilder()
|
|
49
|
+
.start('greet')
|
|
50
|
+
.addAction('greet', async (_ctx) => {
|
|
51
|
+
return '欢迎!请问您是新客户还是老客户?';
|
|
52
|
+
}, { next: 'check-type' })
|
|
53
|
+
.addCondition('check-type',
|
|
54
|
+
(ctx) => ctx.variables.get('isNewCustomer'),
|
|
55
|
+
'new-flow', 'existing-flow')
|
|
56
|
+
.addAction('new-flow', async (_ctx) => {
|
|
57
|
+
return '让我帮您注册账号。请提供您的邮箱地址。';
|
|
58
|
+
}, { next: 'done' })
|
|
59
|
+
.addAction('existing-flow', async (_ctx) => {
|
|
60
|
+
return '欢迎回来!有什么可以帮您?';
|
|
61
|
+
}, { next: 'done' })
|
|
62
|
+
.addAction('done', async () => 'Onboarding complete')
|
|
63
|
+
.build();
|
|
64
|
+
|
|
65
|
+
agent.registerWorkflow('onboarding', onboarding);
|
|
66
|
+
|
|
67
|
+
// === 6. 启动 / Start ===
|
|
68
|
+
await agent.start();
|
|
69
|
+
console.log('🚀 Customer Service Agent is running!');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FAQ Skill — FAQ 查询技能
|
|
3
|
+
* Looks up frequently asked questions by keyword matching.
|
|
4
|
+
*/
|
|
5
|
+
import { BaseSkill } from 'opc-agent';
|
|
6
|
+
|
|
7
|
+
export class FAQSkill extends BaseSkill {
|
|
8
|
+
name = 'faq';
|
|
9
|
+
description = 'Look up frequently asked questions';
|
|
10
|
+
triggers = [/常见问题|FAQ|怎么退款|退货|配送|支付/i];
|
|
11
|
+
|
|
12
|
+
async execute(input: string): Promise<string> {
|
|
13
|
+
// 常见问题知识库 / FAQ Knowledge Base
|
|
14
|
+
const faqs: Record<string, string> = {
|
|
15
|
+
'退款': '退款将在3-5个工作日内到账。如超时未到账,请联系银行确认。',
|
|
16
|
+
'退货': '请在收到商品7天内申请退货。商品需保持原包装,未使用。',
|
|
17
|
+
'配送': '标准配送3-5天,加急配送1-2天。偏远地区可能延迟1-2天。',
|
|
18
|
+
'支付': '支持支付宝、微信支付、银行卡(Visa/Mastercard/银联)。',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
for (const [key, answer] of Object.entries(faqs)) {
|
|
22
|
+
if (input.includes(key)) return answer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return '请问您想了解什么?我们有以下常见问题:退款、退货、配送、支付';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ticket Skill — 工单创建技能
|
|
3
|
+
* Creates a support ticket for human follow-up.
|
|
4
|
+
*/
|
|
5
|
+
import { BaseSkill } from 'opc-agent';
|
|
6
|
+
|
|
7
|
+
export class TicketSkill extends BaseSkill {
|
|
8
|
+
name = 'ticket';
|
|
9
|
+
description = 'Create a support ticket for human follow-up';
|
|
10
|
+
triggers = [/创建工单|提交问题|人工客服|投诉/i];
|
|
11
|
+
|
|
12
|
+
async execute(input: string): Promise<string> {
|
|
13
|
+
// 生成唯一工单号 / Generate unique ticket ID
|
|
14
|
+
const ticketId = `TK-${Date.now().toString(36).toUpperCase()}`;
|
|
15
|
+
|
|
16
|
+
// 实际项目中这里会写入数据库
|
|
17
|
+
// In production, this would persist to a database
|
|
18
|
+
console.log(`[Ticket Created] ${ticketId}: ${input}`);
|
|
19
|
+
|
|
20
|
+
return `已创建工单 ${ticketId},客服团队将在2小时内联系您。\nTicket ${ticketId} created. Our team will contact you within 2 hours.`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"]
|
|
14
|
+
}
|