opc-agent 4.2.0 → 4.2.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.
Files changed (119) hide show
  1. package/.opc/memory.db +0 -0
  2. package/COMPETITIVE-GAP.md +92 -92
  3. package/CONTRIBUTING.md +36 -36
  4. package/README.md +290 -290
  5. package/README.zh-CN.md +269 -269
  6. package/STUDIO-REWRITE-TASK.md +76 -0
  7. package/dist/channels/telegram.d.ts +5 -0
  8. package/dist/channels/telegram.d.ts.map +1 -1
  9. package/dist/channels/telegram.js +108 -0
  10. package/dist/channels/telegram.js.map +1 -1
  11. package/dist/channels/voice.d.ts +71 -97
  12. package/dist/channels/voice.d.ts.map +1 -1
  13. package/dist/channels/voice.js +369 -347
  14. package/dist/channels/voice.js.map +1 -1
  15. package/dist/channels/web.d.ts.map +1 -1
  16. package/dist/channels/web.js +8 -2
  17. package/dist/channels/web.js.map +1 -1
  18. package/dist/channels/wechat.js +6 -6
  19. package/dist/cli/chat.d.ts +4 -1
  20. package/dist/cli/chat.d.ts.map +1 -1
  21. package/dist/cli/chat.js +680 -73
  22. package/dist/cli/chat.js.map +1 -1
  23. package/dist/cli/setup.js +1 -1
  24. package/dist/cli/setup.js.map +1 -1
  25. package/dist/cli.js +373 -280
  26. package/dist/cli.js.map +1 -1
  27. package/dist/core/a2a-http.d.ts +75 -0
  28. package/dist/core/a2a-http.d.ts.map +1 -0
  29. package/dist/core/a2a-http.js +217 -0
  30. package/dist/core/a2a-http.js.map +1 -0
  31. package/dist/core/a2a.d.ts +2 -0
  32. package/dist/core/a2a.d.ts.map +1 -1
  33. package/dist/core/a2a.js +6 -1
  34. package/dist/core/a2a.js.map +1 -1
  35. package/dist/core/agent.d.ts +1 -0
  36. package/dist/core/agent.d.ts.map +1 -1
  37. package/dist/core/agent.js +3 -0
  38. package/dist/core/agent.js.map +1 -1
  39. package/dist/core/gateway-registry.d.ts +116 -0
  40. package/dist/core/gateway-registry.d.ts.map +1 -0
  41. package/dist/core/gateway-registry.js +280 -0
  42. package/dist/core/gateway-registry.js.map +1 -0
  43. package/dist/core/model-recommender.d.ts +40 -0
  44. package/dist/core/model-recommender.d.ts.map +1 -0
  45. package/dist/core/model-recommender.js +186 -0
  46. package/dist/core/model-recommender.js.map +1 -0
  47. package/dist/core/priority-queue.d.ts +100 -0
  48. package/dist/core/priority-queue.d.ts.map +1 -0
  49. package/dist/core/priority-queue.js +181 -0
  50. package/dist/core/priority-queue.js.map +1 -0
  51. package/dist/core/runtime.d.ts.map +1 -1
  52. package/dist/core/runtime.js +192 -22
  53. package/dist/core/runtime.js.map +1 -1
  54. package/dist/deploy/index.js +56 -56
  55. package/dist/doctor.d.ts +1 -0
  56. package/dist/doctor.d.ts.map +1 -1
  57. package/dist/doctor.js +155 -10
  58. package/dist/doctor.js.map +1 -1
  59. package/dist/index.d.ts +10 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +24 -13
  62. package/dist/index.js.map +1 -1
  63. package/dist/memory/deepbrain.d.ts +1 -1
  64. package/dist/memory/deepbrain.d.ts.map +1 -1
  65. package/dist/memory/deepbrain.js +95 -4
  66. package/dist/memory/deepbrain.js.map +1 -1
  67. package/dist/memory/evolve-engine.d.ts +113 -0
  68. package/dist/memory/evolve-engine.d.ts.map +1 -0
  69. package/dist/memory/evolve-engine.js +549 -0
  70. package/dist/memory/evolve-engine.js.map +1 -0
  71. package/dist/memory/index.d.ts +2 -0
  72. package/dist/memory/index.d.ts.map +1 -1
  73. package/dist/memory/index.js +3 -1
  74. package/dist/memory/index.js.map +1 -1
  75. package/dist/memory/sqlite-store.d.ts +40 -0
  76. package/dist/memory/sqlite-store.d.ts.map +1 -0
  77. package/dist/memory/sqlite-store.js +269 -0
  78. package/dist/memory/sqlite-store.js.map +1 -0
  79. package/dist/memory/user-profiler.d.ts +8 -0
  80. package/dist/memory/user-profiler.d.ts.map +1 -1
  81. package/dist/memory/user-profiler.js +89 -0
  82. package/dist/memory/user-profiler.js.map +1 -1
  83. package/dist/scheduler/cron-engine.d.ts.map +1 -1
  84. package/dist/scheduler/cron-engine.js +3 -36
  85. package/dist/scheduler/cron-engine.js.map +1 -1
  86. package/dist/scheduler/proactive.d.ts +62 -0
  87. package/dist/scheduler/proactive.d.ts.map +1 -0
  88. package/dist/scheduler/proactive.js +185 -0
  89. package/dist/scheduler/proactive.js.map +1 -0
  90. package/dist/skills/auto-learn.d.ts.map +1 -1
  91. package/dist/skills/auto-learn.js +65 -11
  92. package/dist/skills/auto-learn.js.map +1 -1
  93. package/dist/skills/builtin/index.d.ts.map +1 -1
  94. package/dist/skills/builtin/index.js +163 -30
  95. package/dist/skills/builtin/index.js.map +1 -1
  96. package/dist/skills/types.d.ts +1 -1
  97. package/dist/skills/types.d.ts.map +1 -1
  98. package/dist/skills/types.js +1 -0
  99. package/dist/skills/types.js.map +1 -1
  100. package/dist/studio/server.d.ts +1 -0
  101. package/dist/studio/server.d.ts.map +1 -1
  102. package/dist/studio/server.js +148 -17
  103. package/dist/studio/server.js.map +1 -1
  104. package/dist/studio-ui/index.html +867 -2630
  105. package/dist/ui/components.js +105 -105
  106. package/examples/README.md +22 -22
  107. package/examples/basic-agent.ts +90 -90
  108. package/examples/brain-integration.ts +71 -71
  109. package/examples/multi-channel.ts +74 -74
  110. package/install.ps1 +127 -127
  111. package/install.sh +154 -154
  112. package/models.json +164 -164
  113. package/package.json +5 -2
  114. package/scripts/install.ps1 +31 -31
  115. package/scripts/install.sh +40 -40
  116. package/templates/ecommerce-assistant/README.md +45 -45
  117. package/templates/ecommerce-assistant/oad.yaml +47 -47
  118. package/templates/tech-support/README.md +43 -43
  119. package/templates/tech-support/oad.yaml +45 -45
@@ -13,111 +13,111 @@ function generateChatWidget(config) {
13
13
  const msgUser = isDark ? '#0f3460' : '#e3f2fd';
14
14
  const msgBot = isDark ? '#1a1a2e' : '#f5f5f5';
15
15
  const accent = '#00d2ff';
16
- return `<!DOCTYPE html>
17
- <html lang="en">
18
- <head>
19
- <meta charset="UTF-8">
20
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
21
- <title>${title}</title>
22
- <style>
23
- * { margin: 0; padding: 0; box-sizing: border-box; }
24
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: ${bg}; color: ${fg}; height: 100vh; display: flex; flex-direction: column; }
25
- .chat-header { padding: 16px 20px; background: ${isDark ? '#16213e' : '#fafafa'}; border-bottom: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
26
- .chat-header::before { content: '💬'; }
27
- .chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
28
- .msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
29
- .msg.user { align-self: flex-end; background: ${msgUser}; border-bottom-right-radius: 4px; }
30
- .msg.assistant { align-self: flex-start; background: ${msgBot}; border: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; border-bottom-left-radius: 4px; }
31
- .msg.streaming::after { content: '▊'; animation: blink 0.7s infinite; }
32
- @keyframes blink { 50% { opacity: 0; } }
33
- .chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; background: ${isDark ? '#16213e' : '#fafafa'}; }
34
- .chat-input textarea { flex: 1; resize: none; border: 1px solid ${isDark ? '#2a2a4a' : '#ccc'}; border-radius: 8px; padding: 10px; font-size: 14px; background: ${inputBg}; color: ${fg}; outline: none; font-family: inherit; min-height: 42px; max-height: 120px; }
35
- .chat-input textarea:focus { border-color: ${accent}; }
36
- .chat-input button { background: ${accent}; color: #000; border: none; border-radius: 8px; padding: 0 20px; cursor: pointer; font-weight: 600; font-size: 14px; }
37
- .chat-input button:hover { opacity: 0.85; }
38
- .chat-input button:disabled { opacity: 0.4; cursor: not-allowed; }
39
- </style>
40
- </head>
41
- <body>
42
- <div class="chat-header">${title}</div>
43
- <div class="chat-messages" id="messages"></div>
44
- <div class="chat-input">
45
- <textarea id="input" rows="1" placeholder="Type a message..." onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();sendMessage()}"></textarea>
46
- <button id="sendBtn" onclick="sendMessage()">Send</button>
47
- </div>
48
- <script>
49
- const ENDPOINT = ${JSON.stringify(endpoint)};
50
- const messages = [];
51
- const $msgs = document.getElementById('messages');
52
- const $input = document.getElementById('input');
53
- const $btn = document.getElementById('sendBtn');
54
-
55
- function addMsg(role, text) {
56
- const div = document.createElement('div');
57
- div.className = 'msg ' + role;
58
- div.textContent = text;
59
- $msgs.appendChild(div);
60
- $msgs.scrollTop = $msgs.scrollHeight;
61
- return div;
62
- }
63
-
64
- async function sendMessage() {
65
- const text = $input.value.trim();
66
- if (!text) return;
67
- $input.value = '';
68
- $btn.disabled = true;
69
- messages.push({ role: 'user', content: text });
70
- addMsg('user', text);
71
-
72
- const div = addMsg('assistant', '');
73
- div.classList.add('streaming');
74
- let full = '';
75
-
76
- try {
77
- const res = await fetch(ENDPOINT, {
78
- method: 'POST',
79
- headers: { 'Content-Type': 'application/json' },
80
- body: JSON.stringify({ messages }),
81
- });
82
-
83
- if (res.headers.get('content-type')?.includes('text/event-stream')) {
84
- const reader = res.body.getReader();
85
- const decoder = new TextDecoder();
86
- let buf = '';
87
- while (true) {
88
- const { done, value } = await reader.read();
89
- if (done) break;
90
- buf += decoder.decode(value, { stream: true });
91
- const lines = buf.split('\\n');
92
- buf = lines.pop() || '';
93
- for (const line of lines) {
94
- if (line.startsWith('data: ')) {
95
- const data = line.slice(6);
96
- if (data === '[DONE]') break;
97
- try { const j = JSON.parse(data); full += j.content || j.delta || ''; div.textContent = full; } catch {}
98
- }
99
- }
100
- $msgs.scrollTop = $msgs.scrollHeight;
101
- }
102
- } else {
103
- const data = await res.json();
104
- full = data.content || data.message || JSON.stringify(data);
105
- div.textContent = full;
106
- }
107
- } catch (e) {
108
- full = 'Error: ' + e.message;
109
- div.textContent = full;
110
- }
111
-
112
- div.classList.remove('streaming');
113
- messages.push({ role: 'assistant', content: full });
114
- $btn.disabled = false;
115
- $input.focus();
116
- }
117
-
118
- $input.focus();
119
- </script>
120
- </body>
16
+ return `<!DOCTYPE html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="UTF-8">
20
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
21
+ <title>${title}</title>
22
+ <style>
23
+ * { margin: 0; padding: 0; box-sizing: border-box; }
24
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: ${bg}; color: ${fg}; height: 100vh; display: flex; flex-direction: column; }
25
+ .chat-header { padding: 16px 20px; background: ${isDark ? '#16213e' : '#fafafa'}; border-bottom: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
26
+ .chat-header::before { content: '💬'; }
27
+ .chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
28
+ .msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
29
+ .msg.user { align-self: flex-end; background: ${msgUser}; border-bottom-right-radius: 4px; }
30
+ .msg.assistant { align-self: flex-start; background: ${msgBot}; border: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; border-bottom-left-radius: 4px; }
31
+ .msg.streaming::after { content: '▊'; animation: blink 0.7s infinite; }
32
+ @keyframes blink { 50% { opacity: 0; } }
33
+ .chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid ${isDark ? '#2a2a4a' : '#e0e0e0'}; background: ${isDark ? '#16213e' : '#fafafa'}; }
34
+ .chat-input textarea { flex: 1; resize: none; border: 1px solid ${isDark ? '#2a2a4a' : '#ccc'}; border-radius: 8px; padding: 10px; font-size: 14px; background: ${inputBg}; color: ${fg}; outline: none; font-family: inherit; min-height: 42px; max-height: 120px; }
35
+ .chat-input textarea:focus { border-color: ${accent}; }
36
+ .chat-input button { background: ${accent}; color: #000; border: none; border-radius: 8px; padding: 0 20px; cursor: pointer; font-weight: 600; font-size: 14px; }
37
+ .chat-input button:hover { opacity: 0.85; }
38
+ .chat-input button:disabled { opacity: 0.4; cursor: not-allowed; }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <div class="chat-header">${title}</div>
43
+ <div class="chat-messages" id="messages"></div>
44
+ <div class="chat-input">
45
+ <textarea id="input" rows="1" placeholder="Type a message..." onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();sendMessage()}"></textarea>
46
+ <button id="sendBtn" onclick="sendMessage()">Send</button>
47
+ </div>
48
+ <script>
49
+ const ENDPOINT = ${JSON.stringify(endpoint)};
50
+ const messages = [];
51
+ const $msgs = document.getElementById('messages');
52
+ const $input = document.getElementById('input');
53
+ const $btn = document.getElementById('sendBtn');
54
+
55
+ function addMsg(role, text) {
56
+ const div = document.createElement('div');
57
+ div.className = 'msg ' + role;
58
+ div.textContent = text;
59
+ $msgs.appendChild(div);
60
+ $msgs.scrollTop = $msgs.scrollHeight;
61
+ return div;
62
+ }
63
+
64
+ async function sendMessage() {
65
+ const text = $input.value.trim();
66
+ if (!text) return;
67
+ $input.value = '';
68
+ $btn.disabled = true;
69
+ messages.push({ role: 'user', content: text });
70
+ addMsg('user', text);
71
+
72
+ const div = addMsg('assistant', '');
73
+ div.classList.add('streaming');
74
+ let full = '';
75
+
76
+ try {
77
+ const res = await fetch(ENDPOINT, {
78
+ method: 'POST',
79
+ headers: { 'Content-Type': 'application/json' },
80
+ body: JSON.stringify({ messages }),
81
+ });
82
+
83
+ if (res.headers.get('content-type')?.includes('text/event-stream')) {
84
+ const reader = res.body.getReader();
85
+ const decoder = new TextDecoder();
86
+ let buf = '';
87
+ while (true) {
88
+ const { done, value } = await reader.read();
89
+ if (done) break;
90
+ buf += decoder.decode(value, { stream: true });
91
+ const lines = buf.split('\\n');
92
+ buf = lines.pop() || '';
93
+ for (const line of lines) {
94
+ if (line.startsWith('data: ')) {
95
+ const data = line.slice(6);
96
+ if (data === '[DONE]') break;
97
+ try { const j = JSON.parse(data); full += j.content || j.delta || ''; div.textContent = full; } catch {}
98
+ }
99
+ }
100
+ $msgs.scrollTop = $msgs.scrollHeight;
101
+ }
102
+ } else {
103
+ const data = await res.json();
104
+ full = data.content || data.message || JSON.stringify(data);
105
+ div.textContent = full;
106
+ }
107
+ } catch (e) {
108
+ full = 'Error: ' + e.message;
109
+ div.textContent = full;
110
+ }
111
+
112
+ div.classList.remove('streaming');
113
+ messages.push({ role: 'assistant', content: full });
114
+ $btn.disabled = false;
115
+ $input.focus();
116
+ }
117
+
118
+ $input.focus();
119
+ </script>
120
+ </body>
121
121
  </html>`;
122
122
  }
123
123
  //# sourceMappingURL=components.js.map
@@ -1,22 +1,22 @@
1
- # OPC Agent Examples
2
-
3
- ## Run Examples
4
-
5
- ```bash
6
- # Basic agent with skills
7
- npx tsx examples/basic-agent.ts
8
-
9
- # Multi-channel setup (Web + Telegram)
10
- npx tsx examples/multi-channel.ts
11
-
12
- # DeepBrain memory integration
13
- npx tsx examples/brain-integration.ts
14
- ```
15
-
16
- ## What Each Example Shows
17
-
18
- | Example | Concepts |
19
- |---------|----------|
20
- | `basic-agent.ts` | `BaseAgent`, `AgentRuntime`, `BaseSkill`, message handling |
21
- | `multi-channel.ts` | `WebChannel`, `TelegramChannel`, multi-channel config |
22
- | `brain-integration.ts` | `DeepBrainMemoryStore`, `InMemoryStore`, memory backends |
1
+ # OPC Agent Examples
2
+
3
+ ## Run Examples
4
+
5
+ ```bash
6
+ # Basic agent with skills
7
+ npx tsx examples/basic-agent.ts
8
+
9
+ # Multi-channel setup (Web + Telegram)
10
+ npx tsx examples/multi-channel.ts
11
+
12
+ # DeepBrain memory integration
13
+ npx tsx examples/brain-integration.ts
14
+ ```
15
+
16
+ ## What Each Example Shows
17
+
18
+ | Example | Concepts |
19
+ |---------|----------|
20
+ | `basic-agent.ts` | `BaseAgent`, `AgentRuntime`, `BaseSkill`, message handling |
21
+ | `multi-channel.ts` | `WebChannel`, `TelegramChannel`, multi-channel config |
22
+ | `brain-integration.ts` | `DeepBrainMemoryStore`, `InMemoryStore`, memory backends |
@@ -1,90 +1,90 @@
1
- /**
2
- * OPC Agent Example: Basic Agent
3
- *
4
- * Create a simple agent with OAD config, register a skill, handle a message.
5
- *
6
- * Run: npx tsx examples/basic-agent.ts
7
- */
8
-
9
- import {
10
- BaseAgent,
11
- AgentRuntime,
12
- BaseSkill,
13
- InMemoryStore,
14
- type Message,
15
- type AgentContext,
16
- type SkillResult,
17
- } from 'opc-agent';
18
-
19
- // Define a custom skill
20
- class GreeterSkill extends BaseSkill {
21
- name = 'greeter';
22
- description = 'Responds to greetings';
23
-
24
- canHandle(message: Message): boolean {
25
- const text = message.content.toLowerCase();
26
- return text.includes('hello') || text.includes('hi') || text.includes('hey');
27
- }
28
-
29
- async execute(message: Message, context: AgentContext): Promise<SkillResult> {
30
- return {
31
- content: `Hello! I'm ${context.agent?.name || 'Agent'}. How can I help you today?`,
32
- confidence: 1.0,
33
- };
34
- }
35
- }
36
-
37
- async function main() {
38
- console.log('🤖 OPC Agent — Basic Agent Demo\n');
39
-
40
- try {
41
- // Create agent with OAD-style config
42
- const agent = new BaseAgent({
43
- name: 'demo-agent',
44
- description: 'A simple demo agent',
45
- version: '1.0.0',
46
- });
47
-
48
- // Set up memory store
49
- const memory = new InMemoryStore();
50
-
51
- // Create runtime
52
- const runtime = new AgentRuntime(agent, {
53
- memory,
54
- });
55
-
56
- // Register skill
57
- const greeter = new GreeterSkill();
58
- runtime.registerSkill(greeter);
59
-
60
- console.log(`✅ Agent "${agent.name}" created with ${1} skill\n`);
61
-
62
- // Simulate messages
63
- const testMessages: Message[] = [
64
- { role: 'user', content: 'Hello there!' },
65
- { role: 'user', content: 'What can you do?' },
66
- { role: 'user', content: 'Hey, nice to meet you' },
67
- ];
68
-
69
- for (const msg of testMessages) {
70
- console.log(`📨 User: ${msg.content}`);
71
- const response = await runtime.handleMessage(msg);
72
- console.log(`🤖 Agent: ${response?.content || '(no response)'}\n`);
73
- }
74
-
75
- console.log('✅ Done! OPC Agent supports:');
76
- console.log(' • OAD config (YAML/JSON agent definition)');
77
- console.log(' • Skill registration & routing');
78
- console.log(' • Multi-channel (Web, Telegram, Slack, etc.)');
79
- console.log(' • Memory stores (InMemory, DeepBrain)\n');
80
- console.log('Next: npx tsx examples/multi-channel.ts');
81
- } catch (e: any) {
82
- console.error(`❌ Error: ${e.message}`);
83
- process.exit(1);
84
- }
85
- }
86
-
87
- main().catch(e => {
88
- console.error(`\n❌ Error: ${e.message}\n`);
89
- process.exit(1);
90
- });
1
+ /**
2
+ * OPC Agent Example: Basic Agent
3
+ *
4
+ * Create a simple agent with OAD config, register a skill, handle a message.
5
+ *
6
+ * Run: npx tsx examples/basic-agent.ts
7
+ */
8
+
9
+ import {
10
+ BaseAgent,
11
+ AgentRuntime,
12
+ BaseSkill,
13
+ InMemoryStore,
14
+ type Message,
15
+ type AgentContext,
16
+ type SkillResult,
17
+ } from 'opc-agent';
18
+
19
+ // Define a custom skill
20
+ class GreeterSkill extends BaseSkill {
21
+ name = 'greeter';
22
+ description = 'Responds to greetings';
23
+
24
+ canHandle(message: Message): boolean {
25
+ const text = message.content.toLowerCase();
26
+ return text.includes('hello') || text.includes('hi') || text.includes('hey');
27
+ }
28
+
29
+ async execute(message: Message, context: AgentContext): Promise<SkillResult> {
30
+ return {
31
+ content: `Hello! I'm ${context.agent?.name || 'Agent'}. How can I help you today?`,
32
+ confidence: 1.0,
33
+ };
34
+ }
35
+ }
36
+
37
+ async function main() {
38
+ console.log('🤖 OPC Agent — Basic Agent Demo\n');
39
+
40
+ try {
41
+ // Create agent with OAD-style config
42
+ const agent = new BaseAgent({
43
+ name: 'demo-agent',
44
+ description: 'A simple demo agent',
45
+ version: '1.0.0',
46
+ });
47
+
48
+ // Set up memory store
49
+ const memory = new InMemoryStore();
50
+
51
+ // Create runtime
52
+ const runtime = new AgentRuntime(agent, {
53
+ memory,
54
+ });
55
+
56
+ // Register skill
57
+ const greeter = new GreeterSkill();
58
+ runtime.registerSkill(greeter);
59
+
60
+ console.log(`✅ Agent "${agent.name}" created with ${1} skill\n`);
61
+
62
+ // Simulate messages
63
+ const testMessages: Message[] = [
64
+ { role: 'user', content: 'Hello there!' },
65
+ { role: 'user', content: 'What can you do?' },
66
+ { role: 'user', content: 'Hey, nice to meet you' },
67
+ ];
68
+
69
+ for (const msg of testMessages) {
70
+ console.log(`📨 User: ${msg.content}`);
71
+ const response = await runtime.handleMessage(msg);
72
+ console.log(`🤖 Agent: ${response?.content || '(no response)'}\n`);
73
+ }
74
+
75
+ console.log('✅ Done! OPC Agent supports:');
76
+ console.log(' • OAD config (YAML/JSON agent definition)');
77
+ console.log(' • Skill registration & routing');
78
+ console.log(' • Multi-channel (Web, Telegram, Slack, etc.)');
79
+ console.log(' • Memory stores (InMemory, DeepBrain)\n');
80
+ console.log('Next: npx tsx examples/multi-channel.ts');
81
+ } catch (e: any) {
82
+ console.error(`❌ Error: ${e.message}`);
83
+ process.exit(1);
84
+ }
85
+ }
86
+
87
+ main().catch(e => {
88
+ console.error(`\n❌ Error: ${e.message}\n`);
89
+ process.exit(1);
90
+ });
@@ -1,71 +1,71 @@
1
- /**
2
- * OPC Agent Example: DeepBrain Memory Integration
3
- *
4
- * Shows how to use DeepBrainMemoryStore for persistent agent memory.
5
- * Requires a running DeepBrain instance (or falls back to InMemory).
6
- *
7
- * Run: npx tsx examples/brain-integration.ts
8
- */
9
-
10
- import {
11
- BaseAgent,
12
- AgentRuntime,
13
- InMemoryStore,
14
- DeepBrainMemoryStore,
15
- } from 'opc-agent';
16
-
17
- async function main() {
18
- console.log('🧠 OPC Agent — DeepBrain Memory Integration\n');
19
-
20
- try {
21
- const agent = new BaseAgent({
22
- name: 'brain-agent',
23
- description: 'Agent with DeepBrain-powered memory',
24
- version: '1.0.0',
25
- });
26
-
27
- // Try DeepBrain first, fall back to InMemory
28
- let memory;
29
- let memoryType: string;
30
-
31
- try {
32
- memory = new DeepBrainMemoryStore({
33
- brainUrl: process.env.DEEPBRAIN_URL || 'http://localhost:3333',
34
- agentId: 'brain-agent',
35
- });
36
- memoryType = 'DeepBrain';
37
- console.log('✅ Using DeepBrain memory store');
38
- } catch {
39
- memory = new InMemoryStore();
40
- memoryType = 'InMemory';
41
- console.log('⚠️ DeepBrain unavailable, using InMemory fallback');
42
- }
43
-
44
- const runtime = new AgentRuntime(agent, { memory });
45
-
46
- console.log(`\n📦 Memory store: ${memoryType}`);
47
- console.log('\nDeepBrain vs InMemory:');
48
- console.log(' ┌─────────────────┬────────────┬──────────────┐');
49
- console.log(' │ Feature │ InMemory │ DeepBrain │');
50
- console.log(' ├─────────────────┼────────────┼──────────────┤');
51
- console.log(' │ Persistence │ ❌ (RAM) │ ✅ (SQLite) │');
52
- console.log(' │ Semantic search │ ❌ │ ✅ │');
53
- console.log(' │ Evolve │ ❌ │ ✅ │');
54
- console.log(' │ Multi-agent │ ❌ │ ✅ │');
55
- console.log(' │ Zero config │ ✅ │ ✅ │');
56
- console.log(' └─────────────────┴────────────┴──────────────┘\n');
57
-
58
- console.log('✅ Done! To use DeepBrain:');
59
- console.log(' npm install deepbrain');
60
- console.log(' deepbrain serve # starts on :3333');
61
- console.log(' DEEPBRAIN_URL=http://localhost:3333 npx tsx examples/brain-integration.ts\n');
62
- } catch (e: any) {
63
- console.error(`❌ Error: ${e.message}`);
64
- process.exit(1);
65
- }
66
- }
67
-
68
- main().catch(e => {
69
- console.error(`\n❌ Error: ${e.message}\n`);
70
- process.exit(1);
71
- });
1
+ /**
2
+ * OPC Agent Example: DeepBrain Memory Integration
3
+ *
4
+ * Shows how to use DeepBrainMemoryStore for persistent agent memory.
5
+ * Requires a running DeepBrain instance (or falls back to InMemory).
6
+ *
7
+ * Run: npx tsx examples/brain-integration.ts
8
+ */
9
+
10
+ import {
11
+ BaseAgent,
12
+ AgentRuntime,
13
+ InMemoryStore,
14
+ DeepBrainMemoryStore,
15
+ } from 'opc-agent';
16
+
17
+ async function main() {
18
+ console.log('🧠 OPC Agent — DeepBrain Memory Integration\n');
19
+
20
+ try {
21
+ const agent = new BaseAgent({
22
+ name: 'brain-agent',
23
+ description: 'Agent with DeepBrain-powered memory',
24
+ version: '1.0.0',
25
+ });
26
+
27
+ // Try DeepBrain first, fall back to InMemory
28
+ let memory;
29
+ let memoryType: string;
30
+
31
+ try {
32
+ memory = new DeepBrainMemoryStore({
33
+ brainUrl: process.env.DEEPBRAIN_URL || 'http://localhost:3333',
34
+ agentId: 'brain-agent',
35
+ });
36
+ memoryType = 'DeepBrain';
37
+ console.log('✅ Using DeepBrain memory store');
38
+ } catch {
39
+ memory = new InMemoryStore();
40
+ memoryType = 'InMemory';
41
+ console.log('⚠️ DeepBrain unavailable, using InMemory fallback');
42
+ }
43
+
44
+ const runtime = new AgentRuntime(agent, { memory });
45
+
46
+ console.log(`\n📦 Memory store: ${memoryType}`);
47
+ console.log('\nDeepBrain vs InMemory:');
48
+ console.log(' ┌─────────────────┬────────────┬──────────────┐');
49
+ console.log(' │ Feature │ InMemory │ DeepBrain │');
50
+ console.log(' ├─────────────────┼────────────┼──────────────┤');
51
+ console.log(' │ Persistence │ ❌ (RAM) │ ✅ (SQLite) │');
52
+ console.log(' │ Semantic search │ ❌ │ ✅ │');
53
+ console.log(' │ Evolve │ ❌ │ ✅ │');
54
+ console.log(' │ Multi-agent │ ❌ │ ✅ │');
55
+ console.log(' │ Zero config │ ✅ │ ✅ │');
56
+ console.log(' └─────────────────┴────────────┴──────────────┘\n');
57
+
58
+ console.log('✅ Done! To use DeepBrain:');
59
+ console.log(' npm install deepbrain');
60
+ console.log(' deepbrain serve # starts on :3333');
61
+ console.log(' DEEPBRAIN_URL=http://localhost:3333 npx tsx examples/brain-integration.ts\n');
62
+ } catch (e: any) {
63
+ console.error(`❌ Error: ${e.message}`);
64
+ process.exit(1);
65
+ }
66
+ }
67
+
68
+ main().catch(e => {
69
+ console.error(`\n❌ Error: ${e.message}\n`);
70
+ process.exit(1);
71
+ });