opc-agent 0.3.0 → 0.5.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/README.md +20 -0
- package/dist/channels/voice.d.ts +43 -0
- package/dist/channels/voice.js +67 -0
- package/dist/channels/webhook.d.ts +40 -0
- package/dist/channels/webhook.js +193 -0
- package/dist/cli.js +143 -13
- package/dist/core/a2a.d.ts +46 -0
- package/dist/core/a2a.js +99 -0
- package/dist/core/hitl.d.ts +41 -0
- package/dist/core/hitl.js +100 -0
- package/dist/core/performance.d.ts +50 -0
- package/dist/core/performance.js +148 -0
- package/dist/core/versioning.d.ts +29 -0
- package/dist/core/versioning.js +114 -0
- package/dist/core/workflow.d.ts +59 -0
- package/dist/core/workflow.js +174 -0
- package/dist/deploy/openclaw.d.ts +14 -0
- package/dist/deploy/openclaw.js +208 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +18 -1
- package/dist/schema/oad.d.ts +352 -15
- package/dist/schema/oad.js +41 -2
- package/dist/templates/executive-assistant.d.ts +20 -0
- package/dist/templates/executive-assistant.js +70 -0
- package/dist/templates/financial-advisor.d.ts +15 -0
- package/dist/templates/financial-advisor.js +60 -0
- package/dist/templates/legal-assistant.d.ts +15 -0
- package/dist/templates/legal-assistant.js +70 -0
- package/examples/customer-service-demo/README.md +90 -0
- package/examples/customer-service-demo/oad.yaml +107 -0
- package/package.json +46 -46
- package/src/channels/voice.ts +106 -0
- package/src/channels/webhook.ts +199 -0
- package/src/cli.ts +524 -384
- package/src/core/a2a.ts +143 -0
- package/src/core/hitl.ts +138 -0
- package/src/core/performance.ts +187 -0
- package/src/core/versioning.ts +106 -0
- package/src/core/workflow.ts +235 -0
- package/src/deploy/openclaw.ts +200 -0
- package/src/index.ts +15 -0
- package/src/schema/oad.ts +45 -1
- package/src/templates/executive-assistant.ts +71 -0
- package/src/templates/financial-advisor.ts +60 -0
- package/src/templates/legal-assistant.ts +71 -0
- package/tests/a2a.test.ts +66 -0
- package/tests/hitl.test.ts +71 -0
- package/tests/performance.test.ts +115 -0
- package/tests/templates.test.ts +77 -0
- package/tests/versioning.test.ts +75 -0
- package/tests/voice.test.ts +61 -0
- package/tests/webhook.test.ts +29 -0
- package/tests/workflow.test.ts +143 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseSkill } from '../skills/base';
|
|
2
|
+
import type { AgentContext, Message, SkillResult } from '../core/types';
|
|
3
|
+
import type { OADDocument } from '../schema/oad';
|
|
4
|
+
export declare class BudgetAnalysisSkill extends BaseSkill {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
execute(_context: AgentContext, message: Message): Promise<SkillResult>;
|
|
8
|
+
}
|
|
9
|
+
export declare class FinancialPlanningSkill extends BaseSkill {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
execute(_context: AgentContext, message: Message): Promise<SkillResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createFinancialAdvisorConfig(): OADDocument;
|
|
15
|
+
//# sourceMappingURL=financial-advisor.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FinancialPlanningSkill = exports.BudgetAnalysisSkill = void 0;
|
|
4
|
+
exports.createFinancialAdvisorConfig = createFinancialAdvisorConfig;
|
|
5
|
+
const base_1 = require("../skills/base");
|
|
6
|
+
class BudgetAnalysisSkill extends base_1.BaseSkill {
|
|
7
|
+
name = 'budget-analysis';
|
|
8
|
+
description = 'Analyze budgets and expenses';
|
|
9
|
+
async execute(_context, message) {
|
|
10
|
+
const lower = message.content.toLowerCase();
|
|
11
|
+
if (lower.includes('budget') || lower.includes('expense') || lower.includes('cost')) {
|
|
12
|
+
return this.match('I can help analyze your budget. Please share your income and expense categories, and I\'ll provide insights on spending patterns and savings opportunities.', 0.8);
|
|
13
|
+
}
|
|
14
|
+
if (lower.includes('save') || lower.includes('saving')) {
|
|
15
|
+
return this.match('Common savings strategies: 50/30/20 rule (needs/wants/savings), automate transfers, review subscriptions, negotiate bills, and track daily spending.', 0.75);
|
|
16
|
+
}
|
|
17
|
+
return this.noMatch();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.BudgetAnalysisSkill = BudgetAnalysisSkill;
|
|
21
|
+
class FinancialPlanningSkill extends base_1.BaseSkill {
|
|
22
|
+
name = 'financial-planning';
|
|
23
|
+
description = 'Help with financial planning and advice';
|
|
24
|
+
async execute(_context, message) {
|
|
25
|
+
const lower = message.content.toLowerCase();
|
|
26
|
+
if (lower.includes('invest') || lower.includes('portfolio')) {
|
|
27
|
+
return this.match('For investment planning, consider: risk tolerance, time horizon, diversification, asset allocation, and regular rebalancing. This is general guidance — consult a certified financial advisor for personalized advice.', 0.8);
|
|
28
|
+
}
|
|
29
|
+
if (lower.includes('retire') || lower.includes('pension')) {
|
|
30
|
+
return this.match('Retirement planning essentials: estimate target savings (25x annual expenses), maximize employer matching, consider tax-advantaged accounts, and start early for compound growth.', 0.8);
|
|
31
|
+
}
|
|
32
|
+
return this.noMatch();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.FinancialPlanningSkill = FinancialPlanningSkill;
|
|
36
|
+
function createFinancialAdvisorConfig() {
|
|
37
|
+
return {
|
|
38
|
+
apiVersion: 'opc/v1',
|
|
39
|
+
kind: 'Agent',
|
|
40
|
+
metadata: {
|
|
41
|
+
name: 'financial-advisor',
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
description: 'AI Financial Advisor - budget analysis, expense tracking, financial planning',
|
|
44
|
+
author: 'OPC',
|
|
45
|
+
license: 'Apache-2.0',
|
|
46
|
+
},
|
|
47
|
+
spec: {
|
|
48
|
+
model: 'deepseek-chat',
|
|
49
|
+
systemPrompt: 'You are a financial advisor AI. Help users with budget analysis, expense tracking, and financial planning. Always recommend consulting a certified financial advisor for binding decisions.',
|
|
50
|
+
skills: [
|
|
51
|
+
{ name: 'budget-analysis', description: 'Analyze budgets and expenses' },
|
|
52
|
+
{ name: 'financial-planning', description: 'Financial planning advice' },
|
|
53
|
+
],
|
|
54
|
+
channels: [{ type: 'web', port: 3000 }],
|
|
55
|
+
memory: { shortTerm: true, longTerm: false },
|
|
56
|
+
streaming: false,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=financial-advisor.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseSkill } from '../skills/base';
|
|
2
|
+
import type { AgentContext, Message, SkillResult } from '../core/types';
|
|
3
|
+
import type { OADDocument } from '../schema/oad';
|
|
4
|
+
export declare class ContractReviewSkill extends BaseSkill {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
execute(_context: AgentContext, message: Message): Promise<SkillResult>;
|
|
8
|
+
}
|
|
9
|
+
export declare class ComplianceCheckSkill extends BaseSkill {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
execute(_context: AgentContext, message: Message): Promise<SkillResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createLegalAssistantConfig(): OADDocument;
|
|
15
|
+
//# sourceMappingURL=legal-assistant.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComplianceCheckSkill = exports.ContractReviewSkill = void 0;
|
|
4
|
+
exports.createLegalAssistantConfig = createLegalAssistantConfig;
|
|
5
|
+
const base_1 = require("../skills/base");
|
|
6
|
+
const LEGAL_TERMS = {
|
|
7
|
+
'force majeure': 'A clause that frees parties from obligations due to extraordinary events.',
|
|
8
|
+
'indemnification': 'One party agrees to compensate the other for certain damages or losses.',
|
|
9
|
+
'limitation of liability': 'A cap on the amount one party can claim from the other.',
|
|
10
|
+
'non-compete': 'Restricts a party from competing within a specified scope and timeframe.',
|
|
11
|
+
'confidentiality': 'Obligations to keep certain information private.',
|
|
12
|
+
'termination': 'Conditions under which the agreement may be ended.',
|
|
13
|
+
};
|
|
14
|
+
class ContractReviewSkill extends base_1.BaseSkill {
|
|
15
|
+
name = 'contract-review';
|
|
16
|
+
description = 'Review contracts and identify key clauses';
|
|
17
|
+
async execute(_context, message) {
|
|
18
|
+
const lower = message.content.toLowerCase();
|
|
19
|
+
for (const [term, explanation] of Object.entries(LEGAL_TERMS)) {
|
|
20
|
+
if (lower.includes(term)) {
|
|
21
|
+
return this.match(`📋 **${term.toUpperCase()}**: ${explanation}`, 0.85);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (lower.includes('review') || lower.includes('contract')) {
|
|
25
|
+
return this.match('I can review contracts for key clauses like force majeure, indemnification, limitation of liability, non-compete, confidentiality, and termination provisions.', 0.7);
|
|
26
|
+
}
|
|
27
|
+
return this.noMatch();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ContractReviewSkill = ContractReviewSkill;
|
|
31
|
+
class ComplianceCheckSkill extends base_1.BaseSkill {
|
|
32
|
+
name = 'compliance-check';
|
|
33
|
+
description = 'Check compliance with regulations';
|
|
34
|
+
async execute(_context, message) {
|
|
35
|
+
const lower = message.content.toLowerCase();
|
|
36
|
+
if (lower.includes('gdpr') || lower.includes('privacy')) {
|
|
37
|
+
return this.match('GDPR compliance requires: data minimization, consent mechanisms, right to erasure, data protection officer, and breach notification within 72 hours.', 0.9);
|
|
38
|
+
}
|
|
39
|
+
if (lower.includes('compliance') || lower.includes('regulation')) {
|
|
40
|
+
return this.match('I can check compliance with GDPR, CCPA, SOX, HIPAA, and other major regulations. Please specify the regulation and context.', 0.7);
|
|
41
|
+
}
|
|
42
|
+
return this.noMatch();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ComplianceCheckSkill = ComplianceCheckSkill;
|
|
46
|
+
function createLegalAssistantConfig() {
|
|
47
|
+
return {
|
|
48
|
+
apiVersion: 'opc/v1',
|
|
49
|
+
kind: 'Agent',
|
|
50
|
+
metadata: {
|
|
51
|
+
name: 'legal-assistant',
|
|
52
|
+
version: '1.0.0',
|
|
53
|
+
description: 'AI Legal Assistant - contract review, compliance checking, legal research',
|
|
54
|
+
author: 'OPC',
|
|
55
|
+
license: 'Apache-2.0',
|
|
56
|
+
},
|
|
57
|
+
spec: {
|
|
58
|
+
model: 'deepseek-chat',
|
|
59
|
+
systemPrompt: 'You are a legal assistant AI. Help users review contracts, check compliance, and research legal topics. Always recommend consulting a qualified attorney for binding decisions.',
|
|
60
|
+
skills: [
|
|
61
|
+
{ name: 'contract-review', description: 'Review contracts and identify key clauses' },
|
|
62
|
+
{ name: 'compliance-check', description: 'Check regulatory compliance' },
|
|
63
|
+
],
|
|
64
|
+
channels: [{ type: 'web', port: 3000 }],
|
|
65
|
+
memory: { shortTerm: true, longTerm: false },
|
|
66
|
+
streaming: false,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=legal-assistant.js.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# ShopBot — Customer Service Demo
|
|
2
|
+
|
|
3
|
+
A complete e-commerce customer service agent built with OPC Agent, deployable to OpenClaw.
|
|
4
|
+
|
|
5
|
+
## What's Inside
|
|
6
|
+
|
|
7
|
+
- `oad.yaml` — Full agent definition with product FAQ, order tracking, complaint handling
|
|
8
|
+
- Rich system prompt with personality, escalation rules, and response templates
|
|
9
|
+
- Telegram + Web channel configuration
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1. Install OPC Agent
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g opc-agent
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. Validate the Agent
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd examples/customer-service-demo
|
|
23
|
+
opc info
|
|
24
|
+
opc build
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 3. Deploy to OpenClaw
|
|
28
|
+
|
|
29
|
+
**Option A: Generate workspace files**
|
|
30
|
+
```bash
|
|
31
|
+
opc deploy --target openclaw --output ./shopbot-workspace
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This creates a complete OpenClaw agent workspace with:
|
|
35
|
+
- `IDENTITY.md` — Agent identity
|
|
36
|
+
- `SOUL.md` — System prompt and model config
|
|
37
|
+
- `AGENTS.md` — Skills, memory, and trust config
|
|
38
|
+
- `USER.md` — User preferences template
|
|
39
|
+
- `MEMORY.md` — Persistent memory template
|
|
40
|
+
|
|
41
|
+
**Option B: Deploy and auto-register**
|
|
42
|
+
```bash
|
|
43
|
+
opc deploy --target openclaw --install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This generates the workspace AND registers the agent in `~/.openclaw/openclaw.json`.
|
|
47
|
+
|
|
48
|
+
### 4. Restart OpenClaw
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
openclaw gateway restart
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 5. Test in Telegram
|
|
55
|
+
|
|
56
|
+
Send a message to your OpenClaw Telegram bot. ShopBot will respond!
|
|
57
|
+
|
|
58
|
+
Try these:
|
|
59
|
+
- "What headphones do you sell?"
|
|
60
|
+
- "Track my order TS-123456"
|
|
61
|
+
- "I want to return my laptop stand"
|
|
62
|
+
- "This is unacceptable, I want to speak to a manager"
|
|
63
|
+
|
|
64
|
+
## Architecture
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
OPC Agent (Development) OpenClaw (Runtime)
|
|
68
|
+
┌─────────────────────┐ ┌──────────────────────┐
|
|
69
|
+
│ oad.yaml │ │ IDENTITY.md │
|
|
70
|
+
│ (agent definition) │──deploy─│ SOUL.md │
|
|
71
|
+
│ │ │ AGENTS.md │
|
|
72
|
+
│ opc build/test │ │ USER.md │
|
|
73
|
+
│ opc deploy │ │ MEMORY.md │
|
|
74
|
+
└─────────────────────┘ │ │
|
|
75
|
+
│ ← Telegram/Web → │
|
|
76
|
+
└──────────────────────┘
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
OPC Agent is the **development framework**. OpenClaw is the **runtime**.
|
|
80
|
+
|
|
81
|
+
## Customization
|
|
82
|
+
|
|
83
|
+
Edit `oad.yaml` to:
|
|
84
|
+
- Change the product catalog
|
|
85
|
+
- Adjust escalation rules
|
|
86
|
+
- Add new skills
|
|
87
|
+
- Switch LLM provider/model
|
|
88
|
+
- Modify the system prompt personality
|
|
89
|
+
|
|
90
|
+
Then re-deploy: `opc deploy --target openclaw --install`
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
apiVersion: opc/v1
|
|
2
|
+
kind: Agent
|
|
3
|
+
metadata:
|
|
4
|
+
name: ShopBot
|
|
5
|
+
version: "1.0.0"
|
|
6
|
+
description: "E-commerce customer service agent for TechStyle — handles product FAQs, order tracking, returns, and complaint escalation"
|
|
7
|
+
author: "TechStyle Inc."
|
|
8
|
+
license: Apache-2.0
|
|
9
|
+
marketplace:
|
|
10
|
+
category: customer-service
|
|
11
|
+
pricing: free
|
|
12
|
+
tags: [ecommerce, support, faq, orders]
|
|
13
|
+
|
|
14
|
+
spec:
|
|
15
|
+
provider:
|
|
16
|
+
default: deepseek
|
|
17
|
+
allowed: [openai, deepseek, qwen]
|
|
18
|
+
model: deepseek-chat
|
|
19
|
+
|
|
20
|
+
systemPrompt: |
|
|
21
|
+
You are ShopBot, the friendly and professional customer service agent for TechStyle,
|
|
22
|
+
an online electronics and lifestyle store.
|
|
23
|
+
|
|
24
|
+
## Personality
|
|
25
|
+
- Warm, helpful, and patient
|
|
26
|
+
- Professional but not robotic — use a conversational tone
|
|
27
|
+
- Proactive: anticipate follow-up questions
|
|
28
|
+
- Empathetic: acknowledge customer frustration before solving problems
|
|
29
|
+
|
|
30
|
+
## Core Capabilities
|
|
31
|
+
1. **Product FAQ**: Answer questions about products, specs, pricing, availability
|
|
32
|
+
2. **Order Tracking**: Look up order status by order ID (format: TS-XXXXXX)
|
|
33
|
+
3. **Returns & Refunds**: Guide customers through return process (30-day policy)
|
|
34
|
+
4. **Complaint Handling**: De-escalate issues, offer solutions, escalate when needed
|
|
35
|
+
|
|
36
|
+
## Escalation Rules
|
|
37
|
+
- Escalate to human agent if:
|
|
38
|
+
- Customer asks 3+ times about the same unresolved issue
|
|
39
|
+
- Customer explicitly requests a human
|
|
40
|
+
- Issue involves billing disputes over $100
|
|
41
|
+
- Customer uses abusive language (remain calm, offer to transfer)
|
|
42
|
+
- Say: "Let me connect you with a specialist who can help further."
|
|
43
|
+
|
|
44
|
+
## Response Guidelines
|
|
45
|
+
- Keep responses under 200 words unless detailed explanation is needed
|
|
46
|
+
- Always confirm understanding: "Just to make sure I understand..."
|
|
47
|
+
- End with a follow-up: "Is there anything else I can help with?"
|
|
48
|
+
- For order lookups, ask for order ID if not provided
|
|
49
|
+
- Never make up order status — if you can't find it, say so
|
|
50
|
+
|
|
51
|
+
## Product Catalog (Quick Reference)
|
|
52
|
+
- TechStyle Pro Headphones — $149, wireless, ANC, 30hr battery
|
|
53
|
+
- TechStyle Slim Laptop Stand — $59, aluminum, adjustable
|
|
54
|
+
- TechStyle Power Bank 20K — $39, 20000mAh, USB-C PD
|
|
55
|
+
- TechStyle Smart Watch S3 — $199, health tracking, 5-day battery
|
|
56
|
+
- TechStyle Webcam 4K — $89, autofocus, built-in mic
|
|
57
|
+
|
|
58
|
+
## Return Policy
|
|
59
|
+
- 30-day return window from delivery date
|
|
60
|
+
- Item must be in original packaging
|
|
61
|
+
- Free return shipping for defective items
|
|
62
|
+
- Refund processed within 5-7 business days
|
|
63
|
+
- Gift cards and sale items are final sale
|
|
64
|
+
|
|
65
|
+
skills:
|
|
66
|
+
- name: product-faq
|
|
67
|
+
description: "Answer product questions from the catalog knowledge base"
|
|
68
|
+
config:
|
|
69
|
+
source: catalog
|
|
70
|
+
fallback: "I don't have that info right now. Let me check with the team."
|
|
71
|
+
|
|
72
|
+
- name: order-lookup
|
|
73
|
+
description: "Look up order status by order ID"
|
|
74
|
+
config:
|
|
75
|
+
idPattern: "TS-\\d{6}"
|
|
76
|
+
notFoundMessage: "I couldn't find that order. Double-check the ID (format: TS-XXXXXX)."
|
|
77
|
+
|
|
78
|
+
- name: complaint-handler
|
|
79
|
+
description: "Handle complaints with empathy and escalation logic"
|
|
80
|
+
config:
|
|
81
|
+
maxAttempts: 3
|
|
82
|
+
escalationMessage: "Let me connect you with a specialist who can help further."
|
|
83
|
+
|
|
84
|
+
channels:
|
|
85
|
+
- type: telegram
|
|
86
|
+
config:
|
|
87
|
+
welcomeMessage: "Hi! 👋 I'm ShopBot from TechStyle. How can I help you today?"
|
|
88
|
+
- type: web
|
|
89
|
+
port: 3000
|
|
90
|
+
|
|
91
|
+
memory:
|
|
92
|
+
shortTerm: true
|
|
93
|
+
longTerm: false
|
|
94
|
+
|
|
95
|
+
dtv:
|
|
96
|
+
trust:
|
|
97
|
+
level: verified
|
|
98
|
+
value:
|
|
99
|
+
metrics:
|
|
100
|
+
- response_time
|
|
101
|
+
- resolution_rate
|
|
102
|
+
- customer_satisfaction
|
|
103
|
+
|
|
104
|
+
streaming:
|
|
105
|
+
enabled: true
|
|
106
|
+
|
|
107
|
+
locale: en
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "opc-agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Open Agent Framework — Build, test, and run AI Agents for business workstations",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"opc": "dist/cli.js"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"test": "vitest run",
|
|
13
|
-
"dev": "tsc --watch",
|
|
14
|
-
"lint": "tsc --noEmit"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"agent",
|
|
18
|
-
"ai",
|
|
19
|
-
"llm",
|
|
20
|
-
"framework",
|
|
21
|
-
"typescript",
|
|
22
|
-
"agent-framework"
|
|
23
|
-
],
|
|
24
|
-
"author": "Deepleaper",
|
|
25
|
-
"license": "Apache-2.0",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "https://github.com/Deepleaper/opc-agent.git"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"agentkits": "^0.1.0",
|
|
32
|
-
"commander": "^12.0.0",
|
|
33
|
-
"express": "^4.21.0",
|
|
34
|
-
"js-yaml": "^4.1.0",
|
|
35
|
-
"ws": "^8.20.0",
|
|
36
|
-
"zod": "^3.23.0"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/express": "^4.17.21",
|
|
40
|
-
"@types/js-yaml": "^4.0.9",
|
|
41
|
-
"@types/node": "^20.11.0",
|
|
42
|
-
"@types/ws": "^8.18.1",
|
|
43
|
-
"typescript": "^5.5.0",
|
|
44
|
-
"vitest": "^2.0.0"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "opc-agent",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Open Agent Framework — Build, test, and run AI Agents for business workstations",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"opc": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"dev": "tsc --watch",
|
|
14
|
+
"lint": "tsc --noEmit"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"agent",
|
|
18
|
+
"ai",
|
|
19
|
+
"llm",
|
|
20
|
+
"framework",
|
|
21
|
+
"typescript",
|
|
22
|
+
"agent-framework"
|
|
23
|
+
],
|
|
24
|
+
"author": "Deepleaper",
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/Deepleaper/opc-agent.git"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"agentkits": "^0.1.0",
|
|
32
|
+
"commander": "^12.0.0",
|
|
33
|
+
"express": "^4.21.0",
|
|
34
|
+
"js-yaml": "^4.1.0",
|
|
35
|
+
"ws": "^8.20.0",
|
|
36
|
+
"zod": "^3.23.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/express": "^4.17.21",
|
|
40
|
+
"@types/js-yaml": "^4.0.9",
|
|
41
|
+
"@types/node": "^20.11.0",
|
|
42
|
+
"@types/ws": "^8.18.1",
|
|
43
|
+
"typescript": "^5.5.0",
|
|
44
|
+
"vitest": "^2.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { BaseChannel } from './index';
|
|
2
|
+
import type { Message } from '../core/types';
|
|
3
|
+
import { Logger } from '../core/logger';
|
|
4
|
+
|
|
5
|
+
// ── Voice Channel Types ─────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
export interface STTProvider {
|
|
8
|
+
name: string;
|
|
9
|
+
transcribe(audio: Buffer, options?: STTOptions): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TTSProvider {
|
|
13
|
+
name: string;
|
|
14
|
+
synthesize(text: string, options?: TTSOptions): Promise<Buffer>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface STTOptions {
|
|
18
|
+
language?: string;
|
|
19
|
+
model?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TTSOptions {
|
|
23
|
+
voice?: string;
|
|
24
|
+
speed?: number;
|
|
25
|
+
language?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface VoiceChannelConfig {
|
|
29
|
+
sttProvider?: STTProvider;
|
|
30
|
+
ttsProvider?: TTSProvider;
|
|
31
|
+
sampleRate?: number;
|
|
32
|
+
language?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── Voice Channel ───────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
export class VoiceChannel extends BaseChannel {
|
|
38
|
+
type = 'voice';
|
|
39
|
+
private config: VoiceChannelConfig;
|
|
40
|
+
private logger = new Logger('voice-channel');
|
|
41
|
+
private running = false;
|
|
42
|
+
|
|
43
|
+
constructor(config?: VoiceChannelConfig) {
|
|
44
|
+
super();
|
|
45
|
+
this.config = config ?? {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async start(): Promise<void> {
|
|
49
|
+
this.running = true;
|
|
50
|
+
this.logger.info('Voice channel started', {
|
|
51
|
+
stt: this.config.sttProvider?.name ?? 'none',
|
|
52
|
+
tts: this.config.ttsProvider?.name ?? 'none',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async stop(): Promise<void> {
|
|
57
|
+
this.running = false;
|
|
58
|
+
this.logger.info('Voice channel stopped');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
isRunning(): boolean {
|
|
62
|
+
return this.running;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Process audio input: STT → Agent → TTS */
|
|
66
|
+
async processAudio(audio: Buffer): Promise<{ text: string; response: string; audioResponse?: Buffer }> {
|
|
67
|
+
if (!this.handler) throw new Error('No message handler set');
|
|
68
|
+
|
|
69
|
+
// STT
|
|
70
|
+
let text: string;
|
|
71
|
+
if (this.config.sttProvider) {
|
|
72
|
+
text = await this.config.sttProvider.transcribe(audio, { language: this.config.language });
|
|
73
|
+
} else {
|
|
74
|
+
text = audio.toString('utf-8'); // Fallback: treat as text
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this.logger.debug('STT result', { text });
|
|
78
|
+
|
|
79
|
+
// Create message and send to agent
|
|
80
|
+
const message: Message = {
|
|
81
|
+
id: `voice_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
82
|
+
role: 'user',
|
|
83
|
+
content: text,
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
metadata: { channel: 'voice' },
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const response = await this.handler(message);
|
|
89
|
+
|
|
90
|
+
// TTS
|
|
91
|
+
let audioResponse: Buffer | undefined;
|
|
92
|
+
if (this.config.ttsProvider) {
|
|
93
|
+
audioResponse = await this.config.ttsProvider.synthesize(response.content, { language: this.config.language });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { text, response: response.content, audioResponse };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
setSTTProvider(provider: STTProvider): void {
|
|
100
|
+
this.config.sttProvider = provider;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setTTSProvider(provider: TTSProvider): void {
|
|
104
|
+
this.config.ttsProvider = provider;
|
|
105
|
+
}
|
|
106
|
+
}
|