opc-agent 0.1.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/LICENSE +201 -0
- package/README.md +179 -0
- package/README.zh-CN.md +126 -0
- package/dist/channels/index.d.ts +10 -0
- package/dist/channels/index.js +11 -0
- package/dist/channels/web.d.ts +12 -0
- package/dist/channels/web.js +81 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +146 -0
- package/dist/core/agent.d.ts +28 -0
- package/dist/core/agent.js +100 -0
- package/dist/core/config.d.ts +4 -0
- package/dist/core/config.js +50 -0
- package/dist/core/runtime.d.ts +14 -0
- package/dist/core/runtime.js +54 -0
- package/dist/core/types.d.ts +58 -0
- package/dist/core/types.js +3 -0
- package/dist/dtv/data.d.ts +18 -0
- package/dist/dtv/data.js +25 -0
- package/dist/dtv/trust.d.ts +19 -0
- package/dist/dtv/trust.js +40 -0
- package/dist/dtv/value.d.ts +23 -0
- package/dist/dtv/value.js +38 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +33 -0
- package/dist/memory/index.d.ts +11 -0
- package/dist/memory/index.js +33 -0
- package/dist/providers/index.d.ts +12 -0
- package/dist/providers/index.js +68 -0
- package/dist/schema/oad.d.ts +553 -0
- package/dist/schema/oad.js +61 -0
- package/dist/skills/base.d.ts +9 -0
- package/dist/skills/base.js +13 -0
- package/dist/skills/index.d.ts +10 -0
- package/dist/skills/index.js +25 -0
- package/dist/templates/customer-service.d.ts +56 -0
- package/dist/templates/customer-service.js +75 -0
- package/docs/api/oad-schema.md +64 -0
- package/docs/guide/concepts.md +51 -0
- package/docs/guide/getting-started.md +44 -0
- package/docs/guide/templates.md +28 -0
- package/package.json +37 -0
- package/src/channels/index.ts +15 -0
- package/src/channels/web.ts +85 -0
- package/src/cli.ts +131 -0
- package/src/core/agent.ts +116 -0
- package/src/core/config.ts +14 -0
- package/src/core/runtime.ts +57 -0
- package/src/core/types.ts +68 -0
- package/src/dtv/data.ts +29 -0
- package/src/dtv/trust.ts +43 -0
- package/src/dtv/value.ts +47 -0
- package/src/index.ts +16 -0
- package/src/memory/index.ts +34 -0
- package/src/providers/index.ts +44 -0
- package/src/schema/oad.ts +76 -0
- package/src/skills/base.ts +16 -0
- package/src/skills/index.ts +27 -0
- package/src/templates/customer-service.ts +80 -0
- package/templates/customer-service/README.md +22 -0
- package/templates/customer-service/oad.yaml +36 -0
- package/tests/agent.test.ts +72 -0
- package/tests/channel.test.ts +39 -0
- package/tests/oad.test.ts +68 -0
- package/tests/runtime.test.ts +42 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +9 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const commander_1 = require("commander");
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const yaml = __importStar(require("js-yaml"));
|
|
41
|
+
const runtime_1 = require("./core/runtime");
|
|
42
|
+
const customer_service_1 = require("./templates/customer-service");
|
|
43
|
+
const customer_service_2 = require("./templates/customer-service");
|
|
44
|
+
const program = new commander_1.Command();
|
|
45
|
+
program
|
|
46
|
+
.name('opc')
|
|
47
|
+
.description('OPC Agent — Open Agent Framework for business workstations')
|
|
48
|
+
.version('0.1.0');
|
|
49
|
+
program
|
|
50
|
+
.command('init')
|
|
51
|
+
.description('Initialize a new OPC agent project')
|
|
52
|
+
.argument('[name]', 'Project name', 'my-agent')
|
|
53
|
+
.option('-t, --template <template>', 'Template to use', 'customer-service')
|
|
54
|
+
.action(async (name, opts) => {
|
|
55
|
+
const dir = path.resolve(name);
|
|
56
|
+
if (fs.existsSync(dir)) {
|
|
57
|
+
console.error(`Directory ${name} already exists.`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
61
|
+
const config = (0, customer_service_1.createCustomerServiceConfig)();
|
|
62
|
+
config.metadata.name = name;
|
|
63
|
+
fs.writeFileSync(path.join(dir, 'oad.yaml'), yaml.dump(config, { lineWidth: 120 }));
|
|
64
|
+
fs.writeFileSync(path.join(dir, 'README.md'), `# ${name}\n\nCreated with OPC Agent.\n\n## Run\n\n\`\`\`bash\nopc run\n\`\`\`\n`);
|
|
65
|
+
console.log(`✅ Created agent project: ${name}/`);
|
|
66
|
+
console.log(` 📄 oad.yaml — Agent definition`);
|
|
67
|
+
console.log(` 📖 README.md`);
|
|
68
|
+
console.log(`\nNext: cd ${name} && opc run`);
|
|
69
|
+
});
|
|
70
|
+
program
|
|
71
|
+
.command('create')
|
|
72
|
+
.description('Create an agent from a template')
|
|
73
|
+
.argument('<name>', 'Agent name')
|
|
74
|
+
.option('-t, --template <template>', 'Template', 'customer-service')
|
|
75
|
+
.action(async (name) => {
|
|
76
|
+
const config = (0, customer_service_1.createCustomerServiceConfig)();
|
|
77
|
+
config.metadata.name = name;
|
|
78
|
+
const outFile = `${name}-oad.yaml`;
|
|
79
|
+
fs.writeFileSync(outFile, yaml.dump(config, { lineWidth: 120 }));
|
|
80
|
+
console.log(`✅ Created ${outFile}`);
|
|
81
|
+
});
|
|
82
|
+
program
|
|
83
|
+
.command('build')
|
|
84
|
+
.description('Validate OAD and compile')
|
|
85
|
+
.option('-f, --file <file>', 'OAD file', 'oad.yaml')
|
|
86
|
+
.action(async (opts) => {
|
|
87
|
+
try {
|
|
88
|
+
const runtime = new runtime_1.AgentRuntime();
|
|
89
|
+
const config = await runtime.loadConfig(opts.file);
|
|
90
|
+
console.log(`✅ Valid OAD: ${config.metadata.name} v${config.metadata.version}`);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.error('❌ Invalid OAD:', err instanceof Error ? err.message : err);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
program
|
|
98
|
+
.command('test')
|
|
99
|
+
.description('Run agent in sandbox mode')
|
|
100
|
+
.option('-f, --file <file>', 'OAD file', 'oad.yaml')
|
|
101
|
+
.action(async (opts) => {
|
|
102
|
+
console.log('🧪 Running agent in sandbox mode...');
|
|
103
|
+
const runtime = new runtime_1.AgentRuntime();
|
|
104
|
+
await runtime.loadConfig(opts.file);
|
|
105
|
+
const agent = await runtime.initialize();
|
|
106
|
+
runtime.registerSkill(new customer_service_2.FAQSkill());
|
|
107
|
+
runtime.registerSkill(new customer_service_2.HandoffSkill());
|
|
108
|
+
console.log(`✅ Agent "${agent.name}" initialized in sandbox.`);
|
|
109
|
+
console.log(` State: ${agent.state}`);
|
|
110
|
+
console.log(` Send test message...`);
|
|
111
|
+
const response = await agent.handleMessage({
|
|
112
|
+
id: 'test_1',
|
|
113
|
+
role: 'user',
|
|
114
|
+
content: 'What are your business hours?',
|
|
115
|
+
timestamp: Date.now(),
|
|
116
|
+
});
|
|
117
|
+
console.log(` Response: ${response.content}`);
|
|
118
|
+
console.log('✅ Sandbox test passed.');
|
|
119
|
+
});
|
|
120
|
+
program
|
|
121
|
+
.command('run')
|
|
122
|
+
.description('Start agent with channels')
|
|
123
|
+
.option('-f, --file <file>', 'OAD file', 'oad.yaml')
|
|
124
|
+
.action(async (opts) => {
|
|
125
|
+
const runtime = new runtime_1.AgentRuntime();
|
|
126
|
+
await runtime.loadConfig(opts.file);
|
|
127
|
+
await runtime.initialize();
|
|
128
|
+
runtime.registerSkill(new customer_service_2.FAQSkill());
|
|
129
|
+
runtime.registerSkill(new customer_service_2.HandoffSkill());
|
|
130
|
+
await runtime.start();
|
|
131
|
+
const agent = runtime.getAgent();
|
|
132
|
+
console.log(`🚀 Agent "${agent?.name}" is running.`);
|
|
133
|
+
process.on('SIGINT', async () => {
|
|
134
|
+
console.log('\nShutting down...');
|
|
135
|
+
await runtime.stop();
|
|
136
|
+
process.exit(0);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
program
|
|
140
|
+
.command('publish')
|
|
141
|
+
.description('Validate and package for OPC Registry (stub)')
|
|
142
|
+
.action(async () => {
|
|
143
|
+
console.log('📦 Publishing is not yet available. Coming soon in OPC Registry v1.');
|
|
144
|
+
});
|
|
145
|
+
program.parse();
|
|
146
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import type { AgentState, IAgent, IChannel, ISkill, Message, MemoryStore } from './types';
|
|
3
|
+
export declare class BaseAgent extends EventEmitter implements IAgent {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
private _state;
|
|
6
|
+
private skills;
|
|
7
|
+
private channels;
|
|
8
|
+
private memory;
|
|
9
|
+
private provider;
|
|
10
|
+
private systemPrompt;
|
|
11
|
+
constructor(options: {
|
|
12
|
+
name: string;
|
|
13
|
+
systemPrompt?: string;
|
|
14
|
+
provider?: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
memory?: MemoryStore;
|
|
17
|
+
});
|
|
18
|
+
get state(): AgentState;
|
|
19
|
+
private transition;
|
|
20
|
+
init(): Promise<void>;
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
stop(): Promise<void>;
|
|
23
|
+
registerSkill(skill: ISkill): void;
|
|
24
|
+
bindChannel(channel: IChannel): void;
|
|
25
|
+
handleMessage(message: Message): Promise<Message>;
|
|
26
|
+
private createResponse;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseAgent = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const memory_1 = require("../memory");
|
|
6
|
+
const providers_1 = require("../providers");
|
|
7
|
+
class BaseAgent extends events_1.EventEmitter {
|
|
8
|
+
name;
|
|
9
|
+
_state = 'init';
|
|
10
|
+
skills = new Map();
|
|
11
|
+
channels = [];
|
|
12
|
+
memory;
|
|
13
|
+
provider;
|
|
14
|
+
systemPrompt;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super();
|
|
17
|
+
this.name = options.name;
|
|
18
|
+
this.systemPrompt = options.systemPrompt ?? 'You are a helpful AI agent.';
|
|
19
|
+
this.memory = options.memory ?? new memory_1.InMemoryStore();
|
|
20
|
+
this.provider = (0, providers_1.createProvider)(options.provider ?? 'deepseek', options.model ?? 'deepseek-chat');
|
|
21
|
+
}
|
|
22
|
+
get state() {
|
|
23
|
+
return this._state;
|
|
24
|
+
}
|
|
25
|
+
transition(to) {
|
|
26
|
+
const from = this._state;
|
|
27
|
+
this._state = to;
|
|
28
|
+
this.emit('state:change', from, to);
|
|
29
|
+
}
|
|
30
|
+
async init() {
|
|
31
|
+
this.transition('ready');
|
|
32
|
+
}
|
|
33
|
+
async start() {
|
|
34
|
+
if (this._state !== 'ready') {
|
|
35
|
+
throw new Error(`Cannot start agent in state: ${this._state}`);
|
|
36
|
+
}
|
|
37
|
+
for (const channel of this.channels) {
|
|
38
|
+
channel.onMessage((msg) => this.handleMessage(msg));
|
|
39
|
+
await channel.start();
|
|
40
|
+
}
|
|
41
|
+
this.transition('running');
|
|
42
|
+
}
|
|
43
|
+
async stop() {
|
|
44
|
+
for (const channel of this.channels) {
|
|
45
|
+
await channel.stop();
|
|
46
|
+
}
|
|
47
|
+
this.transition('stopped');
|
|
48
|
+
}
|
|
49
|
+
registerSkill(skill) {
|
|
50
|
+
this.skills.set(skill.name, skill);
|
|
51
|
+
}
|
|
52
|
+
bindChannel(channel) {
|
|
53
|
+
this.channels.push(channel);
|
|
54
|
+
}
|
|
55
|
+
async handleMessage(message) {
|
|
56
|
+
this.emit('message:in', message);
|
|
57
|
+
const sessionId = message.metadata?.sessionId ?? 'default';
|
|
58
|
+
await this.memory.addMessage(sessionId, message);
|
|
59
|
+
const context = {
|
|
60
|
+
agentName: this.name,
|
|
61
|
+
sessionId,
|
|
62
|
+
messages: await this.memory.getConversation(sessionId),
|
|
63
|
+
memory: this.memory,
|
|
64
|
+
metadata: {},
|
|
65
|
+
};
|
|
66
|
+
// Try skills first
|
|
67
|
+
for (const [name, skill] of this.skills) {
|
|
68
|
+
try {
|
|
69
|
+
const result = await skill.execute(context, message);
|
|
70
|
+
this.emit('skill:execute', name, result);
|
|
71
|
+
if (result.handled && result.response) {
|
|
72
|
+
const response = this.createResponse(result.response, message);
|
|
73
|
+
await this.memory.addMessage(sessionId, response);
|
|
74
|
+
this.emit('message:out', response);
|
|
75
|
+
return response;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Fall back to LLM
|
|
83
|
+
const llmResponse = await this.provider.chat(context.messages, this.systemPrompt);
|
|
84
|
+
const response = this.createResponse(llmResponse, message);
|
|
85
|
+
await this.memory.addMessage(sessionId, response);
|
|
86
|
+
this.emit('message:out', response);
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
createResponse(content, inReplyTo) {
|
|
90
|
+
return {
|
|
91
|
+
id: `msg_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
92
|
+
role: 'assistant',
|
|
93
|
+
content,
|
|
94
|
+
timestamp: Date.now(),
|
|
95
|
+
metadata: { inReplyTo: inReplyTo.id },
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.BaseAgent = BaseAgent;
|
|
100
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
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.loadOAD = loadOAD;
|
|
37
|
+
exports.validateOAD = validateOAD;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const yaml = __importStar(require("js-yaml"));
|
|
40
|
+
const oad_1 = require("../schema/oad");
|
|
41
|
+
function loadOAD(filePath) {
|
|
42
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
43
|
+
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
44
|
+
const data = (ext === 'yaml' || ext === 'yml') ? yaml.load(raw) : JSON.parse(raw);
|
|
45
|
+
return oad_1.OADSchema.parse(data);
|
|
46
|
+
}
|
|
47
|
+
function validateOAD(data) {
|
|
48
|
+
return oad_1.OADSchema.parse(data);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseAgent } from './agent';
|
|
2
|
+
import type { OADDocument } from '../schema/oad';
|
|
3
|
+
import type { ISkill } from './types';
|
|
4
|
+
export declare class AgentRuntime {
|
|
5
|
+
private agent;
|
|
6
|
+
private config;
|
|
7
|
+
loadConfig(filePath: string): Promise<OADDocument>;
|
|
8
|
+
initialize(config?: OADDocument): Promise<BaseAgent>;
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
registerSkill(skill: ISkill): void;
|
|
12
|
+
getAgent(): BaseAgent | null;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentRuntime = void 0;
|
|
4
|
+
const agent_1 = require("./agent");
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
const web_1 = require("../channels/web");
|
|
7
|
+
class AgentRuntime {
|
|
8
|
+
agent = null;
|
|
9
|
+
config = null;
|
|
10
|
+
async loadConfig(filePath) {
|
|
11
|
+
this.config = (0, config_1.loadOAD)(filePath);
|
|
12
|
+
return this.config;
|
|
13
|
+
}
|
|
14
|
+
async initialize(config) {
|
|
15
|
+
const cfg = config ?? this.config;
|
|
16
|
+
if (!cfg)
|
|
17
|
+
throw new Error('No config loaded. Call loadConfig() first.');
|
|
18
|
+
this.agent = new agent_1.BaseAgent({
|
|
19
|
+
name: cfg.metadata.name,
|
|
20
|
+
systemPrompt: cfg.spec.systemPrompt,
|
|
21
|
+
provider: cfg.spec.provider?.default,
|
|
22
|
+
model: cfg.spec.model,
|
|
23
|
+
});
|
|
24
|
+
// Bind channels
|
|
25
|
+
for (const ch of cfg.spec.channels) {
|
|
26
|
+
if (ch.type === 'web') {
|
|
27
|
+
const port = ch.port ?? 3000;
|
|
28
|
+
this.agent.bindChannel(new web_1.WebChannel(port));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await this.agent.init();
|
|
32
|
+
return this.agent;
|
|
33
|
+
}
|
|
34
|
+
async start() {
|
|
35
|
+
if (!this.agent)
|
|
36
|
+
throw new Error('Agent not initialized.');
|
|
37
|
+
await this.agent.start();
|
|
38
|
+
}
|
|
39
|
+
async stop() {
|
|
40
|
+
if (!this.agent)
|
|
41
|
+
return;
|
|
42
|
+
await this.agent.stop();
|
|
43
|
+
}
|
|
44
|
+
registerSkill(skill) {
|
|
45
|
+
if (!this.agent)
|
|
46
|
+
throw new Error('Agent not initialized.');
|
|
47
|
+
this.agent.registerSkill(skill);
|
|
48
|
+
}
|
|
49
|
+
getAgent() {
|
|
50
|
+
return this.agent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.AgentRuntime = AgentRuntime;
|
|
54
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export type AgentState = 'init' | 'ready' | 'running' | 'stopped' | 'error';
|
|
3
|
+
export interface Message {
|
|
4
|
+
id: string;
|
|
5
|
+
role: 'user' | 'assistant' | 'system';
|
|
6
|
+
content: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentContext {
|
|
11
|
+
agentName: string;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
messages: Message[];
|
|
14
|
+
memory: MemoryStore;
|
|
15
|
+
metadata: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface SkillResult {
|
|
18
|
+
handled: boolean;
|
|
19
|
+
response?: string;
|
|
20
|
+
confidence: number;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export interface ISkill {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
execute(context: AgentContext, message: Message): Promise<SkillResult>;
|
|
27
|
+
}
|
|
28
|
+
export interface IChannel {
|
|
29
|
+
type: string;
|
|
30
|
+
start(): Promise<void>;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
onMessage(handler: (message: Message) => Promise<Message>): void;
|
|
33
|
+
}
|
|
34
|
+
export interface MemoryStore {
|
|
35
|
+
get(key: string): Promise<unknown>;
|
|
36
|
+
set(key: string, value: unknown): Promise<void>;
|
|
37
|
+
getConversation(sessionId: string): Promise<Message[]>;
|
|
38
|
+
addMessage(sessionId: string, message: Message): Promise<void>;
|
|
39
|
+
clear(sessionId?: string): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface AgentEvents {
|
|
42
|
+
'state:change': (from: AgentState, to: AgentState) => void;
|
|
43
|
+
'message:in': (message: Message) => void;
|
|
44
|
+
'message:out': (message: Message) => void;
|
|
45
|
+
'skill:execute': (skill: string, result: SkillResult) => void;
|
|
46
|
+
'error': (error: Error) => void;
|
|
47
|
+
}
|
|
48
|
+
export interface IAgent extends EventEmitter {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly state: AgentState;
|
|
51
|
+
init(): Promise<void>;
|
|
52
|
+
start(): Promise<void>;
|
|
53
|
+
stop(): Promise<void>;
|
|
54
|
+
handleMessage(message: Message): Promise<Message>;
|
|
55
|
+
registerSkill(skill: ISkill): void;
|
|
56
|
+
bindChannel(channel: IChannel): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface DataSource {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly type: string;
|
|
4
|
+
read(key: string): Promise<unknown>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* MRGConfig reader — read-only data layer for agents.
|
|
8
|
+
* Agents can read business data but cannot modify source systems.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MRGConfigReader implements DataSource {
|
|
11
|
+
readonly name = "mrg-config";
|
|
12
|
+
readonly type = "config";
|
|
13
|
+
private data;
|
|
14
|
+
constructor(initial?: Record<string, unknown>);
|
|
15
|
+
read(key: string): Promise<unknown>;
|
|
16
|
+
load(data: Record<string, unknown>): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=data.d.ts.map
|
package/dist/dtv/data.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MRGConfigReader = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* MRGConfig reader — read-only data layer for agents.
|
|
6
|
+
* Agents can read business data but cannot modify source systems.
|
|
7
|
+
*/
|
|
8
|
+
class MRGConfigReader {
|
|
9
|
+
name = 'mrg-config';
|
|
10
|
+
type = 'config';
|
|
11
|
+
data;
|
|
12
|
+
constructor(initial) {
|
|
13
|
+
this.data = new Map(Object.entries(initial ?? {}));
|
|
14
|
+
}
|
|
15
|
+
async read(key) {
|
|
16
|
+
return this.data.get(key);
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
for (const [k, v] of Object.entries(data)) {
|
|
20
|
+
this.data.set(k, v);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MRGConfigReader = MRGConfigReader;
|
|
25
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TrustLevelType } from '../schema/oad';
|
|
2
|
+
/**
|
|
3
|
+
* Trust levels: sandbox → verified → certified → listed
|
|
4
|
+
*
|
|
5
|
+
* - sandbox: No network, no file system, limited capabilities
|
|
6
|
+
* - verified: Identity verified, basic capabilities
|
|
7
|
+
* - certified: Passed security audit, full capabilities
|
|
8
|
+
* - listed: Published in OPC marketplace
|
|
9
|
+
*/
|
|
10
|
+
export declare class TrustManager {
|
|
11
|
+
private level;
|
|
12
|
+
constructor(level?: TrustLevelType);
|
|
13
|
+
getLevel(): TrustLevelType;
|
|
14
|
+
canAccessNetwork(): boolean;
|
|
15
|
+
canAccessFileSystem(): boolean;
|
|
16
|
+
canPublish(): boolean;
|
|
17
|
+
upgrade(to: TrustLevelType): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=trust.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrustManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Trust levels: sandbox → verified → certified → listed
|
|
6
|
+
*
|
|
7
|
+
* - sandbox: No network, no file system, limited capabilities
|
|
8
|
+
* - verified: Identity verified, basic capabilities
|
|
9
|
+
* - certified: Passed security audit, full capabilities
|
|
10
|
+
* - listed: Published in OPC marketplace
|
|
11
|
+
*/
|
|
12
|
+
class TrustManager {
|
|
13
|
+
level;
|
|
14
|
+
constructor(level = 'sandbox') {
|
|
15
|
+
this.level = level;
|
|
16
|
+
}
|
|
17
|
+
getLevel() {
|
|
18
|
+
return this.level;
|
|
19
|
+
}
|
|
20
|
+
canAccessNetwork() {
|
|
21
|
+
return this.level !== 'sandbox';
|
|
22
|
+
}
|
|
23
|
+
canAccessFileSystem() {
|
|
24
|
+
return this.level === 'certified' || this.level === 'listed';
|
|
25
|
+
}
|
|
26
|
+
canPublish() {
|
|
27
|
+
return this.level === 'listed';
|
|
28
|
+
}
|
|
29
|
+
upgrade(to) {
|
|
30
|
+
const order = ['sandbox', 'verified', 'certified', 'listed'];
|
|
31
|
+
const currentIdx = order.indexOf(this.level);
|
|
32
|
+
const targetIdx = order.indexOf(to);
|
|
33
|
+
if (targetIdx <= currentIdx) {
|
|
34
|
+
throw new Error(`Cannot downgrade trust from ${this.level} to ${to}`);
|
|
35
|
+
}
|
|
36
|
+
this.level = to;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.TrustManager = TrustManager;
|
|
40
|
+
//# sourceMappingURL=trust.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value tracking — metrics and ROI for agent operations.
|
|
3
|
+
*/
|
|
4
|
+
export interface ValueMetric {
|
|
5
|
+
name: string;
|
|
6
|
+
value: number;
|
|
7
|
+
unit: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class ValueTracker {
|
|
11
|
+
private metrics;
|
|
12
|
+
private trackedNames;
|
|
13
|
+
constructor(metricNames?: string[]);
|
|
14
|
+
record(name: string, value: number, unit?: string): void;
|
|
15
|
+
getMetrics(name: string): ValueMetric[];
|
|
16
|
+
getAverage(name: string): number;
|
|
17
|
+
getSummary(): Record<string, {
|
|
18
|
+
count: number;
|
|
19
|
+
average: number;
|
|
20
|
+
last: number;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueTracker = void 0;
|
|
4
|
+
class ValueTracker {
|
|
5
|
+
metrics = new Map();
|
|
6
|
+
trackedNames;
|
|
7
|
+
constructor(metricNames = []) {
|
|
8
|
+
this.trackedNames = new Set(metricNames);
|
|
9
|
+
}
|
|
10
|
+
record(name, value, unit = '') {
|
|
11
|
+
if (!this.metrics.has(name)) {
|
|
12
|
+
this.metrics.set(name, []);
|
|
13
|
+
}
|
|
14
|
+
this.metrics.get(name).push({ name, value, unit, timestamp: Date.now() });
|
|
15
|
+
}
|
|
16
|
+
getMetrics(name) {
|
|
17
|
+
return this.metrics.get(name) ?? [];
|
|
18
|
+
}
|
|
19
|
+
getAverage(name) {
|
|
20
|
+
const m = this.getMetrics(name);
|
|
21
|
+
if (m.length === 0)
|
|
22
|
+
return 0;
|
|
23
|
+
return m.reduce((sum, v) => sum + v.value, 0) / m.length;
|
|
24
|
+
}
|
|
25
|
+
getSummary() {
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const [name, values] of this.metrics) {
|
|
28
|
+
result[name] = {
|
|
29
|
+
count: values.length,
|
|
30
|
+
average: this.getAverage(name),
|
|
31
|
+
last: values[values.length - 1]?.value ?? 0,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ValueTracker = ValueTracker;
|
|
38
|
+
//# sourceMappingURL=value.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { BaseAgent } from './core/agent';
|
|
2
|
+
export { AgentRuntime } from './core/runtime';
|
|
3
|
+
export { loadOAD, validateOAD } from './core/config';
|
|
4
|
+
export { OADSchema } from './schema/oad';
|
|
5
|
+
export type { OADDocument, Metadata, Spec, DTVConfig, TrustLevelType } from './schema/oad';
|
|
6
|
+
export type { IAgent, IChannel, ISkill, Message, AgentContext, SkillResult, MemoryStore, AgentState } from './core/types';
|
|
7
|
+
export { BaseChannel } from './channels';
|
|
8
|
+
export { WebChannel } from './channels/web';
|
|
9
|
+
export { BaseSkill } from './skills/base';
|
|
10
|
+
export { SkillRegistry } from './skills';
|
|
11
|
+
export { InMemoryStore } from './memory';
|
|
12
|
+
export { TrustManager } from './dtv/trust';
|
|
13
|
+
export { ValueTracker } from './dtv/value';
|
|
14
|
+
export { MRGConfigReader } from './dtv/data';
|
|
15
|
+
export { createProvider, SUPPORTED_PROVIDERS } from './providers';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|