opc-agent 0.2.0 → 0.3.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/dist/analytics/index.d.ts +31 -0
- package/dist/analytics/index.js +52 -0
- package/dist/cli.js +66 -4
- package/dist/core/room.d.ts +24 -0
- package/dist/core/room.js +97 -0
- package/dist/core/sandbox.d.ts +28 -0
- package/dist/core/sandbox.js +118 -0
- package/dist/i18n/index.d.ts +13 -0
- package/dist/i18n/index.js +73 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +19 -1
- package/dist/plugins/index.d.ts +47 -0
- package/dist/plugins/index.js +59 -0
- package/dist/schema/oad.d.ts +131 -0
- package/dist/schema/oad.js +13 -1
- package/dist/templates/content-writer.d.ts +36 -0
- package/dist/templates/content-writer.js +52 -0
- package/dist/templates/hr-recruiter.d.ts +36 -0
- package/dist/templates/hr-recruiter.js +52 -0
- package/dist/templates/project-manager.d.ts +36 -0
- package/dist/templates/project-manager.js +52 -0
- package/dist/tools/mcp.d.ts +32 -0
- package/dist/tools/mcp.js +49 -0
- package/package.json +1 -1
- package/src/analytics/index.ts +66 -0
- package/src/cli.ts +76 -7
- package/src/core/room.ts +109 -0
- package/src/core/sandbox.ts +101 -0
- package/src/i18n/index.ts +79 -0
- package/src/index.ts +14 -0
- package/src/plugins/index.ts +87 -0
- package/src/schema/oad.ts +14 -0
- package/src/templates/content-writer.ts +58 -0
- package/src/templates/hr-recruiter.ts +58 -0
- package/src/templates/project-manager.ts +58 -0
- package/src/tools/mcp.ts +76 -0
- package/tests/analytics.test.ts +50 -0
- package/tests/i18n.test.ts +41 -0
- package/tests/mcp.test.ts +54 -0
- package/tests/plugin.test.ts +74 -0
- package/tests/room.test.ts +106 -0
- package/tests/sandbox.test.ts +46 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Analytics — track messages, response times, skill usage, errors, tokens.
|
|
3
|
+
*/
|
|
4
|
+
export interface AnalyticsSnapshot {
|
|
5
|
+
messagesProcessed: number;
|
|
6
|
+
avgResponseTimeMs: number;
|
|
7
|
+
skillUsage: Record<string, number>;
|
|
8
|
+
errorCount: number;
|
|
9
|
+
tokenUsage: {
|
|
10
|
+
input: number;
|
|
11
|
+
output: number;
|
|
12
|
+
total: number;
|
|
13
|
+
};
|
|
14
|
+
uptime: number;
|
|
15
|
+
startedAt: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class Analytics {
|
|
18
|
+
private messagesProcessed;
|
|
19
|
+
private totalResponseTimeMs;
|
|
20
|
+
private skillUsage;
|
|
21
|
+
private errorCount;
|
|
22
|
+
private tokenUsage;
|
|
23
|
+
private startedAt;
|
|
24
|
+
recordMessage(responseTimeMs: number): void;
|
|
25
|
+
recordSkillUsage(skillName: string): void;
|
|
26
|
+
recordError(): void;
|
|
27
|
+
recordTokens(input: number, output: number): void;
|
|
28
|
+
getSnapshot(): AnalyticsSnapshot;
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Analytics = void 0;
|
|
4
|
+
class Analytics {
|
|
5
|
+
messagesProcessed = 0;
|
|
6
|
+
totalResponseTimeMs = 0;
|
|
7
|
+
skillUsage = {};
|
|
8
|
+
errorCount = 0;
|
|
9
|
+
tokenUsage = { input: 0, output: 0 };
|
|
10
|
+
startedAt = Date.now();
|
|
11
|
+
recordMessage(responseTimeMs) {
|
|
12
|
+
this.messagesProcessed++;
|
|
13
|
+
this.totalResponseTimeMs += responseTimeMs;
|
|
14
|
+
}
|
|
15
|
+
recordSkillUsage(skillName) {
|
|
16
|
+
this.skillUsage[skillName] = (this.skillUsage[skillName] ?? 0) + 1;
|
|
17
|
+
}
|
|
18
|
+
recordError() {
|
|
19
|
+
this.errorCount++;
|
|
20
|
+
}
|
|
21
|
+
recordTokens(input, output) {
|
|
22
|
+
this.tokenUsage.input += input;
|
|
23
|
+
this.tokenUsage.output += output;
|
|
24
|
+
}
|
|
25
|
+
getSnapshot() {
|
|
26
|
+
return {
|
|
27
|
+
messagesProcessed: this.messagesProcessed,
|
|
28
|
+
avgResponseTimeMs: this.messagesProcessed > 0
|
|
29
|
+
? Math.round(this.totalResponseTimeMs / this.messagesProcessed)
|
|
30
|
+
: 0,
|
|
31
|
+
skillUsage: { ...this.skillUsage },
|
|
32
|
+
errorCount: this.errorCount,
|
|
33
|
+
tokenUsage: {
|
|
34
|
+
input: this.tokenUsage.input,
|
|
35
|
+
output: this.tokenUsage.output,
|
|
36
|
+
total: this.tokenUsage.input + this.tokenUsage.output,
|
|
37
|
+
},
|
|
38
|
+
uptime: Date.now() - this.startedAt,
|
|
39
|
+
startedAt: this.startedAt,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
reset() {
|
|
43
|
+
this.messagesProcessed = 0;
|
|
44
|
+
this.totalResponseTimeMs = 0;
|
|
45
|
+
this.skillUsage = {};
|
|
46
|
+
this.errorCount = 0;
|
|
47
|
+
this.tokenUsage = { input: 0, output: 0 };
|
|
48
|
+
this.startedAt = Date.now();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Analytics = Analytics;
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
package/dist/cli.js
CHANGED
|
@@ -44,9 +44,12 @@ const customer_service_1 = require("./templates/customer-service");
|
|
|
44
44
|
const sales_assistant_1 = require("./templates/sales-assistant");
|
|
45
45
|
const knowledge_base_1 = require("./templates/knowledge-base");
|
|
46
46
|
const code_reviewer_1 = require("./templates/code-reviewer");
|
|
47
|
+
const hr_recruiter_1 = require("./templates/hr-recruiter");
|
|
48
|
+
const project_manager_1 = require("./templates/project-manager");
|
|
49
|
+
const content_writer_1 = require("./templates/content-writer");
|
|
47
50
|
const customer_service_2 = require("./templates/customer-service");
|
|
51
|
+
const analytics_1 = require("./analytics");
|
|
48
52
|
const program = new commander_1.Command();
|
|
49
|
-
// ── Colorful output helpers ──────────────────────────────────
|
|
50
53
|
const color = {
|
|
51
54
|
green: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
52
55
|
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
@@ -72,6 +75,9 @@ const TEMPLATES = {
|
|
|
72
75
|
'sales-assistant': { label: 'Sales Assistant — product Q&A + lead capture', factory: sales_assistant_1.createSalesAssistantConfig },
|
|
73
76
|
'knowledge-base': { label: 'Knowledge Base — RAG with DeepBrain', factory: knowledge_base_1.createKnowledgeBaseConfig },
|
|
74
77
|
'code-reviewer': { label: 'Code Reviewer — bug detection + style checks', factory: code_reviewer_1.createCodeReviewerConfig },
|
|
78
|
+
'hr-recruiter': { label: 'HR Recruiter — resume screening + interview scheduling', factory: hr_recruiter_1.createHRRecruiterConfig },
|
|
79
|
+
'project-manager': { label: 'Project Manager — task tracking + meeting notes', factory: project_manager_1.createProjectManagerConfig },
|
|
80
|
+
'content-writer': { label: 'Content Writer — blog posts + social media + SEO', factory: content_writer_1.createContentWriterConfig },
|
|
75
81
|
};
|
|
76
82
|
async function prompt(question, defaultValue) {
|
|
77
83
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -95,7 +101,7 @@ async function select(question, options) {
|
|
|
95
101
|
program
|
|
96
102
|
.name('opc')
|
|
97
103
|
.description('OPC Agent — Open Agent Framework for business workstations')
|
|
98
|
-
.version('0.
|
|
104
|
+
.version('0.3.0');
|
|
99
105
|
program
|
|
100
106
|
.command('init')
|
|
101
107
|
.description('Initialize a new OPC agent project (interactive)')
|
|
@@ -159,6 +165,11 @@ program
|
|
|
159
165
|
console.log(` Channels: ${s.channels.map(c => c.type).join(', ') || color.dim('(none)')}`);
|
|
160
166
|
console.log(` Skills: ${s.skills.map(sk => sk.name).join(', ') || color.dim('(none)')}`);
|
|
161
167
|
console.log(` Trust: ${s.dtv?.trust?.level ?? 'sandbox'}`);
|
|
168
|
+
console.log(` Streaming: ${s.streaming ? 'enabled' : 'disabled'}`);
|
|
169
|
+
console.log(` Locale: ${s.locale ?? 'en'}`);
|
|
170
|
+
if (s.room) {
|
|
171
|
+
console.log(` Room: ${s.room.name}`);
|
|
172
|
+
}
|
|
162
173
|
if (m.marketplace) {
|
|
163
174
|
console.log(` Category: ${m.marketplace.category ?? color.dim('(none)')}`);
|
|
164
175
|
console.log(` Pricing: ${m.marketplace.pricing ?? 'free'}`);
|
|
@@ -247,12 +258,11 @@ program
|
|
|
247
258
|
}
|
|
248
259
|
};
|
|
249
260
|
await startAgent();
|
|
250
|
-
// Watch for file changes
|
|
251
261
|
const watchPaths = [opts.file, 'src'];
|
|
252
262
|
for (const watchPath of watchPaths) {
|
|
253
263
|
if (fs.existsSync(watchPath)) {
|
|
254
264
|
const isDir = fs.statSync(watchPath).isDirectory();
|
|
255
|
-
fs.watch(watchPath, { recursive: isDir }, async (
|
|
265
|
+
fs.watch(watchPath, { recursive: isDir }, async (_event, filename) => {
|
|
256
266
|
console.log(`\n${icon.info} ${color.dim(`Change detected: ${filename}`)} — restarting...`);
|
|
257
267
|
await startAgent();
|
|
258
268
|
});
|
|
@@ -314,5 +324,57 @@ program
|
|
|
314
324
|
console.log(` Browse templates with: ${color.cyan('opc init --template <name>')}`);
|
|
315
325
|
console.log(`\n Available templates: ${Object.keys(TEMPLATES).map(t => color.cyan(t)).join(', ')}\n`);
|
|
316
326
|
});
|
|
327
|
+
// ── Tool commands ────────────────────────────────────────────
|
|
328
|
+
const toolCmd = program.command('tool').description('Manage MCP tools');
|
|
329
|
+
toolCmd
|
|
330
|
+
.command('list')
|
|
331
|
+
.description('List available MCP tools')
|
|
332
|
+
.action(() => {
|
|
333
|
+
console.log(`\n${icon.gear} ${color.bold('MCP Tools')}\n`);
|
|
334
|
+
console.log(` ${color.dim('No tools installed yet.')}`);
|
|
335
|
+
console.log(`\n Add tools with: ${color.cyan('opc tool add <name>')}\n`);
|
|
336
|
+
});
|
|
337
|
+
toolCmd
|
|
338
|
+
.command('add')
|
|
339
|
+
.description('Add an MCP tool from registry')
|
|
340
|
+
.argument('<name>', 'Tool name')
|
|
341
|
+
.action((name) => {
|
|
342
|
+
console.log(`\n🚧 Tool registry coming soon!`);
|
|
343
|
+
console.log(` Would add tool: ${color.cyan(name)}\n`);
|
|
344
|
+
});
|
|
345
|
+
// ── Plugin commands ──────────────────────────────────────────
|
|
346
|
+
const pluginCmd = program.command('plugin').description('Manage plugins');
|
|
347
|
+
pluginCmd
|
|
348
|
+
.command('list')
|
|
349
|
+
.description('List installed plugins')
|
|
350
|
+
.action(() => {
|
|
351
|
+
console.log(`\n${icon.gear} ${color.bold('Installed Plugins')}\n`);
|
|
352
|
+
console.log(` ${color.dim('No plugins installed yet.')}`);
|
|
353
|
+
console.log(`\n Add plugins with: ${color.cyan('opc plugin add <name>')}\n`);
|
|
354
|
+
});
|
|
355
|
+
pluginCmd
|
|
356
|
+
.command('add')
|
|
357
|
+
.description('Add a plugin')
|
|
358
|
+
.argument('<name>', 'Plugin name')
|
|
359
|
+
.action((name) => {
|
|
360
|
+
console.log(`\n🚧 Plugin registry coming soon!`);
|
|
361
|
+
console.log(` Would add plugin: ${color.cyan(name)}\n`);
|
|
362
|
+
});
|
|
363
|
+
// ── Stats command ────────────────────────────────────────────
|
|
364
|
+
program
|
|
365
|
+
.command('stats')
|
|
366
|
+
.description('Show agent analytics')
|
|
367
|
+
.action(() => {
|
|
368
|
+
const analytics = new analytics_1.Analytics();
|
|
369
|
+
// Show demo stats
|
|
370
|
+
const snap = analytics.getSnapshot();
|
|
371
|
+
console.log(`\n${icon.gear} ${color.bold('Agent Analytics')}\n`);
|
|
372
|
+
console.log(` Messages Processed: ${snap.messagesProcessed}`);
|
|
373
|
+
console.log(` Avg Response Time: ${snap.avgResponseTimeMs}ms`);
|
|
374
|
+
console.log(` Error Count: ${snap.errorCount}`);
|
|
375
|
+
console.log(` Token Usage: ${snap.tokenUsage.total} (in: ${snap.tokenUsage.input}, out: ${snap.tokenUsage.output})`);
|
|
376
|
+
console.log(` Uptime: ${Math.round(snap.uptime / 1000)}s`);
|
|
377
|
+
console.log(`\n ${color.dim('Run an agent to collect analytics data.')}\n`);
|
|
378
|
+
});
|
|
317
379
|
program.parse();
|
|
318
380
|
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Message, IAgent } from './types';
|
|
3
|
+
export interface RoomMessage {
|
|
4
|
+
from: string;
|
|
5
|
+
to?: string;
|
|
6
|
+
topic?: string;
|
|
7
|
+
message: Message;
|
|
8
|
+
}
|
|
9
|
+
export declare class Room extends EventEmitter {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
private agents;
|
|
12
|
+
private subscriptions;
|
|
13
|
+
constructor(name: string);
|
|
14
|
+
addAgent(agent: IAgent): void;
|
|
15
|
+
removeAgent(name: string): void;
|
|
16
|
+
getAgents(): string[];
|
|
17
|
+
subscribe(agentName: string, topic: string): void;
|
|
18
|
+
unsubscribe(agentName: string, topic: string): void;
|
|
19
|
+
getSubscribers(topic: string): string[];
|
|
20
|
+
send(roomMessage: RoomMessage): Promise<Message[]>;
|
|
21
|
+
broadcast(from: string, content: string): Promise<Message[]>;
|
|
22
|
+
publishToTopic(from: string, topic: string, content: string): Promise<Message[]>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=room.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Room = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class Room extends events_1.EventEmitter {
|
|
6
|
+
name;
|
|
7
|
+
agents = new Map();
|
|
8
|
+
subscriptions = new Map(); // topic -> agentNames
|
|
9
|
+
constructor(name) {
|
|
10
|
+
super();
|
|
11
|
+
this.name = name;
|
|
12
|
+
}
|
|
13
|
+
addAgent(agent) {
|
|
14
|
+
this.agents.set(agent.name, agent);
|
|
15
|
+
this.emit('agent:join', agent.name);
|
|
16
|
+
}
|
|
17
|
+
removeAgent(name) {
|
|
18
|
+
this.agents.delete(name);
|
|
19
|
+
// Remove from all subscriptions
|
|
20
|
+
for (const [, subscribers] of this.subscriptions) {
|
|
21
|
+
subscribers.delete(name);
|
|
22
|
+
}
|
|
23
|
+
this.emit('agent:leave', name);
|
|
24
|
+
}
|
|
25
|
+
getAgents() {
|
|
26
|
+
return Array.from(this.agents.keys());
|
|
27
|
+
}
|
|
28
|
+
subscribe(agentName, topic) {
|
|
29
|
+
if (!this.subscriptions.has(topic)) {
|
|
30
|
+
this.subscriptions.set(topic, new Set());
|
|
31
|
+
}
|
|
32
|
+
this.subscriptions.get(topic).add(agentName);
|
|
33
|
+
}
|
|
34
|
+
unsubscribe(agentName, topic) {
|
|
35
|
+
this.subscriptions.get(topic)?.delete(agentName);
|
|
36
|
+
}
|
|
37
|
+
getSubscribers(topic) {
|
|
38
|
+
return Array.from(this.subscriptions.get(topic) ?? []);
|
|
39
|
+
}
|
|
40
|
+
async send(roomMessage) {
|
|
41
|
+
const responses = [];
|
|
42
|
+
this.emit('message', roomMessage);
|
|
43
|
+
if (roomMessage.to) {
|
|
44
|
+
// Direct message
|
|
45
|
+
const agent = this.agents.get(roomMessage.to);
|
|
46
|
+
if (agent) {
|
|
47
|
+
const response = await agent.handleMessage(roomMessage.message);
|
|
48
|
+
responses.push(response);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (roomMessage.topic) {
|
|
52
|
+
// Topic-based pub/sub
|
|
53
|
+
const subscribers = this.subscriptions.get(roomMessage.topic) ?? new Set();
|
|
54
|
+
for (const name of subscribers) {
|
|
55
|
+
if (name === roomMessage.from)
|
|
56
|
+
continue;
|
|
57
|
+
const agent = this.agents.get(name);
|
|
58
|
+
if (agent) {
|
|
59
|
+
const response = await agent.handleMessage(roomMessage.message);
|
|
60
|
+
responses.push(response);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Broadcast to all except sender
|
|
66
|
+
for (const [name, agent] of this.agents) {
|
|
67
|
+
if (name === roomMessage.from)
|
|
68
|
+
continue;
|
|
69
|
+
const response = await agent.handleMessage(roomMessage.message);
|
|
70
|
+
responses.push(response);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return responses;
|
|
74
|
+
}
|
|
75
|
+
async broadcast(from, content) {
|
|
76
|
+
const message = {
|
|
77
|
+
id: `room_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
78
|
+
role: 'user',
|
|
79
|
+
content,
|
|
80
|
+
timestamp: Date.now(),
|
|
81
|
+
metadata: { room: this.name, from },
|
|
82
|
+
};
|
|
83
|
+
return this.send({ from, message });
|
|
84
|
+
}
|
|
85
|
+
async publishToTopic(from, topic, content) {
|
|
86
|
+
const message = {
|
|
87
|
+
id: `room_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
88
|
+
role: 'user',
|
|
89
|
+
content,
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
metadata: { room: this.name, from, topic },
|
|
92
|
+
};
|
|
93
|
+
return this.send({ from, topic, message });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Room = Room;
|
|
97
|
+
//# sourceMappingURL=room.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TrustLevelType } from '../schema/oad';
|
|
2
|
+
export interface SandboxConfig {
|
|
3
|
+
trustLevel: TrustLevelType;
|
|
4
|
+
agentDir: string;
|
|
5
|
+
networkAllowlist?: string[];
|
|
6
|
+
shellAllowed?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SandboxRestrictions {
|
|
9
|
+
fileSystem: {
|
|
10
|
+
read: string[];
|
|
11
|
+
write: string[];
|
|
12
|
+
};
|
|
13
|
+
network: {
|
|
14
|
+
allowed: string[];
|
|
15
|
+
};
|
|
16
|
+
shell: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class Sandbox {
|
|
19
|
+
private config;
|
|
20
|
+
private restrictions;
|
|
21
|
+
constructor(config: SandboxConfig);
|
|
22
|
+
get trustLevel(): TrustLevelType;
|
|
23
|
+
getRestrictions(): SandboxRestrictions;
|
|
24
|
+
checkFileAccess(filePath: string, mode: 'read' | 'write'): boolean;
|
|
25
|
+
checkNetworkAccess(url: string): boolean;
|
|
26
|
+
checkShellAccess(): boolean;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1,118 @@
|
|
|
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.Sandbox = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const TRUST_RESTRICTIONS = {
|
|
39
|
+
sandbox: {
|
|
40
|
+
fileSystem: { read: ['.'], write: ['.'] },
|
|
41
|
+
network: { allowed: [] },
|
|
42
|
+
shell: false,
|
|
43
|
+
},
|
|
44
|
+
verified: {
|
|
45
|
+
fileSystem: { read: ['.', '..'], write: ['.'] },
|
|
46
|
+
network: { allowed: ['*.deepleaper.com', 'api.openai.com', 'api.deepseek.com'] },
|
|
47
|
+
shell: false,
|
|
48
|
+
},
|
|
49
|
+
certified: {
|
|
50
|
+
fileSystem: { read: ['*'], write: ['.', '..'] },
|
|
51
|
+
network: { allowed: ['*'] },
|
|
52
|
+
shell: true,
|
|
53
|
+
},
|
|
54
|
+
listed: {
|
|
55
|
+
fileSystem: { read: ['*'], write: ['*'] },
|
|
56
|
+
network: { allowed: ['*'] },
|
|
57
|
+
shell: true,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
class Sandbox {
|
|
61
|
+
config;
|
|
62
|
+
restrictions;
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.config = config;
|
|
65
|
+
this.restrictions = {
|
|
66
|
+
...TRUST_RESTRICTIONS[config.trustLevel] ?? TRUST_RESTRICTIONS.sandbox,
|
|
67
|
+
};
|
|
68
|
+
if (config.networkAllowlist) {
|
|
69
|
+
this.restrictions.network.allowed = config.networkAllowlist;
|
|
70
|
+
}
|
|
71
|
+
if (config.shellAllowed !== undefined) {
|
|
72
|
+
this.restrictions.shell = config.shellAllowed;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
get trustLevel() {
|
|
76
|
+
return this.config.trustLevel;
|
|
77
|
+
}
|
|
78
|
+
getRestrictions() {
|
|
79
|
+
return { ...this.restrictions };
|
|
80
|
+
}
|
|
81
|
+
checkFileAccess(filePath, mode) {
|
|
82
|
+
const resolved = path.resolve(filePath);
|
|
83
|
+
const agentDir = path.resolve(this.config.agentDir);
|
|
84
|
+
const allowedPaths = mode === 'read' ? this.restrictions.fileSystem.read : this.restrictions.fileSystem.write;
|
|
85
|
+
if (allowedPaths.includes('*'))
|
|
86
|
+
return true;
|
|
87
|
+
for (const allowed of allowedPaths) {
|
|
88
|
+
const allowedResolved = path.resolve(this.config.agentDir, allowed);
|
|
89
|
+
if (resolved.startsWith(allowedResolved))
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
// Always allow access within agent's own directory
|
|
93
|
+
return resolved.startsWith(agentDir);
|
|
94
|
+
}
|
|
95
|
+
checkNetworkAccess(url) {
|
|
96
|
+
if (this.restrictions.network.allowed.includes('*'))
|
|
97
|
+
return true;
|
|
98
|
+
if (this.restrictions.network.allowed.length === 0)
|
|
99
|
+
return false;
|
|
100
|
+
try {
|
|
101
|
+
const hostname = new URL(url).hostname;
|
|
102
|
+
return this.restrictions.network.allowed.some((pattern) => {
|
|
103
|
+
if (pattern.startsWith('*.')) {
|
|
104
|
+
return hostname.endsWith(pattern.slice(1));
|
|
105
|
+
}
|
|
106
|
+
return hostname === pattern;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
checkShellAccess() {
|
|
114
|
+
return this.restrictions.shell;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.Sandbox = Sandbox;
|
|
118
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internationalization (i18n) support for OPC Agent.
|
|
3
|
+
*/
|
|
4
|
+
export type Locale = 'en' | 'zh-CN';
|
|
5
|
+
export interface I18nMessages {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function setLocale(locale: Locale): void;
|
|
9
|
+
export declare function getLocale(): Locale;
|
|
10
|
+
export declare function t(key: string, params?: Record<string, string>): string;
|
|
11
|
+
export declare function detectLocale(): Locale;
|
|
12
|
+
export declare function addMessages(locale: Locale, newMessages: I18nMessages): void;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLocale = setLocale;
|
|
4
|
+
exports.getLocale = getLocale;
|
|
5
|
+
exports.t = t;
|
|
6
|
+
exports.detectLocale = detectLocale;
|
|
7
|
+
exports.addMessages = addMessages;
|
|
8
|
+
const messages = {
|
|
9
|
+
'en': {
|
|
10
|
+
'agent.started': 'Agent "{name}" started successfully',
|
|
11
|
+
'agent.stopped': 'Agent "{name}" stopped',
|
|
12
|
+
'agent.error': 'An error occurred: {error}',
|
|
13
|
+
'agent.greeting': 'Hello! How can I help you?',
|
|
14
|
+
'agent.farewell': 'Goodbye! Have a great day.',
|
|
15
|
+
'agent.notUnderstood': 'I\'m not sure I understand. Could you rephrase?',
|
|
16
|
+
'agent.handoff': 'Let me connect you with a human agent.',
|
|
17
|
+
'cli.init.success': 'Created agent project: {name}',
|
|
18
|
+
'cli.build.success': 'Build successful: {name} v{version}',
|
|
19
|
+
'cli.test.pass': 'All tests passed',
|
|
20
|
+
'cli.stats.title': 'Agent Analytics',
|
|
21
|
+
'cli.stats.messages': 'Messages Processed',
|
|
22
|
+
'cli.stats.avgTime': 'Avg Response Time',
|
|
23
|
+
'cli.stats.errors': 'Errors',
|
|
24
|
+
'cli.stats.uptime': 'Uptime',
|
|
25
|
+
'plugin.loaded': 'Plugin "{name}" loaded',
|
|
26
|
+
'plugin.error': 'Plugin "{name}" failed: {error}',
|
|
27
|
+
},
|
|
28
|
+
'zh-CN': {
|
|
29
|
+
'agent.started': '智能体 "{name}" 启动成功',
|
|
30
|
+
'agent.stopped': '智能体 "{name}" 已停止',
|
|
31
|
+
'agent.error': '发生错误: {error}',
|
|
32
|
+
'agent.greeting': '您好!有什么可以帮您的?',
|
|
33
|
+
'agent.farewell': '再见!祝您愉快。',
|
|
34
|
+
'agent.notUnderstood': '抱歉,我没有理解您的意思。能换个方式描述吗?',
|
|
35
|
+
'agent.handoff': '我来为您转接人工客服。',
|
|
36
|
+
'cli.init.success': '已创建智能体项目: {name}',
|
|
37
|
+
'cli.build.success': '构建成功: {name} v{version}',
|
|
38
|
+
'cli.test.pass': '所有测试通过',
|
|
39
|
+
'cli.stats.title': '智能体分析',
|
|
40
|
+
'cli.stats.messages': '已处理消息',
|
|
41
|
+
'cli.stats.avgTime': '平均响应时间',
|
|
42
|
+
'cli.stats.errors': '错误数',
|
|
43
|
+
'cli.stats.uptime': '运行时间',
|
|
44
|
+
'plugin.loaded': '插件 "{name}" 已加载',
|
|
45
|
+
'plugin.error': '插件 "{name}" 失败: {error}',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
let currentLocale = 'en';
|
|
49
|
+
function setLocale(locale) {
|
|
50
|
+
currentLocale = locale;
|
|
51
|
+
}
|
|
52
|
+
function getLocale() {
|
|
53
|
+
return currentLocale;
|
|
54
|
+
}
|
|
55
|
+
function t(key, params) {
|
|
56
|
+
let msg = messages[currentLocale]?.[key] ?? messages['en']?.[key] ?? key;
|
|
57
|
+
if (params) {
|
|
58
|
+
for (const [k, v] of Object.entries(params)) {
|
|
59
|
+
msg = msg.replace(new RegExp(`\\{${k}\\}`, 'g'), v);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return msg;
|
|
63
|
+
}
|
|
64
|
+
function detectLocale() {
|
|
65
|
+
const env = process.env.LANG ?? process.env.LC_ALL ?? process.env.LANGUAGE ?? '';
|
|
66
|
+
if (env.startsWith('zh'))
|
|
67
|
+
return 'zh-CN';
|
|
68
|
+
return 'en';
|
|
69
|
+
}
|
|
70
|
+
function addMessages(locale, newMessages) {
|
|
71
|
+
messages[locale] = { ...messages[locale], ...newMessages };
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -17,4 +17,16 @@ export { TrustManager } from './dtv/trust';
|
|
|
17
17
|
export { ValueTracker } from './dtv/value';
|
|
18
18
|
export { MRGConfigReader } from './dtv/data';
|
|
19
19
|
export { createProvider, SUPPORTED_PROVIDERS } from './providers';
|
|
20
|
+
export { Room } from './core/room';
|
|
21
|
+
export type { RoomMessage } from './core/room';
|
|
22
|
+
export { MCPToolRegistry, createMCPTool } from './tools/mcp';
|
|
23
|
+
export type { MCPTool, MCPToolDefinition, MCPToolResult } from './tools/mcp';
|
|
24
|
+
export { PluginManager } from './plugins';
|
|
25
|
+
export type { IPlugin, PluginHooks } from './plugins';
|
|
26
|
+
export { Sandbox } from './core/sandbox';
|
|
27
|
+
export type { SandboxConfig, SandboxRestrictions } from './core/sandbox';
|
|
28
|
+
export { Analytics } from './analytics';
|
|
29
|
+
export type { AnalyticsSnapshot } from './analytics';
|
|
30
|
+
export { t, setLocale, getLocale, detectLocale, addMessages } from './i18n';
|
|
31
|
+
export type { Locale } from './i18n';
|
|
20
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SUPPORTED_PROVIDERS = exports.createProvider = exports.MRGConfigReader = exports.ValueTracker = exports.TrustManager = exports.DeepBrainMemoryStore = exports.InMemoryStore = exports.SkillRegistry = exports.BaseSkill = exports.WebSocketChannel = exports.TelegramChannel = exports.WebChannel = exports.BaseChannel = exports.OADSchema = exports.validateOAD = exports.loadOAD = exports.Logger = exports.truncateOutput = exports.AgentRuntime = exports.BaseAgent = void 0;
|
|
3
|
+
exports.addMessages = exports.detectLocale = exports.getLocale = exports.setLocale = exports.t = exports.Analytics = exports.Sandbox = exports.PluginManager = exports.createMCPTool = exports.MCPToolRegistry = exports.Room = exports.SUPPORTED_PROVIDERS = exports.createProvider = exports.MRGConfigReader = exports.ValueTracker = exports.TrustManager = exports.DeepBrainMemoryStore = exports.InMemoryStore = exports.SkillRegistry = exports.BaseSkill = exports.WebSocketChannel = exports.TelegramChannel = exports.WebChannel = exports.BaseChannel = exports.OADSchema = exports.validateOAD = exports.loadOAD = exports.Logger = exports.truncateOutput = exports.AgentRuntime = exports.BaseAgent = void 0;
|
|
4
4
|
// OPC Agent — Open Agent Framework
|
|
5
5
|
var agent_1 = require("./core/agent");
|
|
6
6
|
Object.defineProperty(exports, "BaseAgent", { enumerable: true, get: function () { return agent_1.BaseAgent; } });
|
|
@@ -39,4 +39,22 @@ Object.defineProperty(exports, "MRGConfigReader", { enumerable: true, get: funct
|
|
|
39
39
|
var providers_1 = require("./providers");
|
|
40
40
|
Object.defineProperty(exports, "createProvider", { enumerable: true, get: function () { return providers_1.createProvider; } });
|
|
41
41
|
Object.defineProperty(exports, "SUPPORTED_PROVIDERS", { enumerable: true, get: function () { return providers_1.SUPPORTED_PROVIDERS; } });
|
|
42
|
+
// v0.3.0 new modules
|
|
43
|
+
var room_1 = require("./core/room");
|
|
44
|
+
Object.defineProperty(exports, "Room", { enumerable: true, get: function () { return room_1.Room; } });
|
|
45
|
+
var mcp_1 = require("./tools/mcp");
|
|
46
|
+
Object.defineProperty(exports, "MCPToolRegistry", { enumerable: true, get: function () { return mcp_1.MCPToolRegistry; } });
|
|
47
|
+
Object.defineProperty(exports, "createMCPTool", { enumerable: true, get: function () { return mcp_1.createMCPTool; } });
|
|
48
|
+
var plugins_1 = require("./plugins");
|
|
49
|
+
Object.defineProperty(exports, "PluginManager", { enumerable: true, get: function () { return plugins_1.PluginManager; } });
|
|
50
|
+
var sandbox_1 = require("./core/sandbox");
|
|
51
|
+
Object.defineProperty(exports, "Sandbox", { enumerable: true, get: function () { return sandbox_1.Sandbox; } });
|
|
52
|
+
var analytics_1 = require("./analytics");
|
|
53
|
+
Object.defineProperty(exports, "Analytics", { enumerable: true, get: function () { return analytics_1.Analytics; } });
|
|
54
|
+
var i18n_1 = require("./i18n");
|
|
55
|
+
Object.defineProperty(exports, "t", { enumerable: true, get: function () { return i18n_1.t; } });
|
|
56
|
+
Object.defineProperty(exports, "setLocale", { enumerable: true, get: function () { return i18n_1.setLocale; } });
|
|
57
|
+
Object.defineProperty(exports, "getLocale", { enumerable: true, get: function () { return i18n_1.getLocale; } });
|
|
58
|
+
Object.defineProperty(exports, "detectLocale", { enumerable: true, get: function () { return i18n_1.detectLocale; } });
|
|
59
|
+
Object.defineProperty(exports, "addMessages", { enumerable: true, get: function () { return i18n_1.addMessages; } });
|
|
42
60
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ISkill, IChannel } from '../core/types';
|
|
2
|
+
import type { MCPTool } from '../tools/mcp';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin lifecycle hooks.
|
|
5
|
+
*/
|
|
6
|
+
export interface PluginHooks {
|
|
7
|
+
beforeInit?: () => Promise<void>;
|
|
8
|
+
afterInit?: () => Promise<void>;
|
|
9
|
+
beforeMessage?: (message: {
|
|
10
|
+
content: string;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
afterMessage?: (message: {
|
|
13
|
+
content: string;
|
|
14
|
+
}, response: {
|
|
15
|
+
content: string;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
beforeShutdown?: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Plugin interface — extend agent with skills, tools, channels, and lifecycle hooks.
|
|
21
|
+
*/
|
|
22
|
+
export interface IPlugin {
|
|
23
|
+
name: string;
|
|
24
|
+
version: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
hooks?: PluginHooks;
|
|
27
|
+
skills?: ISkill[];
|
|
28
|
+
tools?: MCPTool[];
|
|
29
|
+
channels?: IChannel[];
|
|
30
|
+
}
|
|
31
|
+
export declare class PluginManager {
|
|
32
|
+
private plugins;
|
|
33
|
+
register(plugin: IPlugin): void;
|
|
34
|
+
unregister(name: string): void;
|
|
35
|
+
get(name: string): IPlugin | undefined;
|
|
36
|
+
list(): {
|
|
37
|
+
name: string;
|
|
38
|
+
version: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
}[];
|
|
41
|
+
has(name: string): boolean;
|
|
42
|
+
runHook(hookName: keyof PluginHooks, ...args: unknown[]): Promise<void>;
|
|
43
|
+
getAllSkills(): ISkill[];
|
|
44
|
+
getAllTools(): MCPTool[];
|
|
45
|
+
getAllChannels(): IChannel[];
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|