opc-agent 1.2.1 → 1.3.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 (158) hide show
  1. package/.github/workflows/ci.yml +24 -0
  2. package/CONTRIBUTING.md +75 -75
  3. package/README.md +235 -358
  4. package/README.zh-CN.md +415 -415
  5. package/dist/channels/web.js +256 -256
  6. package/dist/cli.js +118 -34
  7. package/dist/core/knowledge.d.ts +5 -0
  8. package/dist/core/knowledge.js +39 -2
  9. package/dist/deploy/hermes.js +22 -22
  10. package/dist/deploy/openclaw.js +31 -40
  11. package/dist/index.d.ts +3 -6
  12. package/dist/index.js +7 -11
  13. package/dist/providers/index.d.ts +1 -1
  14. package/dist/providers/index.js +158 -14
  15. package/dist/schema/oad.d.ts +4 -5
  16. package/dist/templates/code-reviewer.d.ts +0 -8
  17. package/dist/templates/code-reviewer.js +5 -9
  18. package/dist/templates/customer-service.d.ts +0 -8
  19. package/dist/templates/customer-service.js +2 -6
  20. package/dist/templates/data-analyst.d.ts +0 -8
  21. package/dist/templates/data-analyst.js +5 -9
  22. package/dist/templates/knowledge-base.d.ts +0 -8
  23. package/dist/templates/knowledge-base.js +2 -6
  24. package/dist/templates/sales-assistant.d.ts +0 -8
  25. package/dist/templates/sales-assistant.js +4 -8
  26. package/dist/templates/teacher.d.ts +0 -8
  27. package/dist/templates/teacher.js +6 -10
  28. package/dist/traces/index.d.ts +49 -0
  29. package/dist/traces/index.js +102 -0
  30. package/docs/.vitepress/config.ts +103 -103
  31. package/docs/api/cli.md +48 -48
  32. package/docs/api/oad-schema.md +64 -64
  33. package/docs/api/sdk.md +80 -80
  34. package/docs/guide/concepts.md +51 -51
  35. package/docs/guide/configuration.md +79 -79
  36. package/docs/guide/deployment.md +42 -42
  37. package/docs/guide/getting-started.md +44 -44
  38. package/docs/guide/templates.md +28 -28
  39. package/docs/guide/testing.md +84 -84
  40. package/docs/index.md +27 -27
  41. package/docs/zh/api/cli.md +54 -54
  42. package/docs/zh/api/oad-schema.md +87 -87
  43. package/docs/zh/api/sdk.md +102 -102
  44. package/docs/zh/guide/concepts.md +104 -104
  45. package/docs/zh/guide/configuration.md +135 -135
  46. package/docs/zh/guide/deployment.md +81 -81
  47. package/docs/zh/guide/getting-started.md +82 -82
  48. package/docs/zh/guide/templates.md +84 -84
  49. package/docs/zh/guide/testing.md +88 -88
  50. package/docs/zh/index.md +27 -27
  51. package/examples/customer-service-demo/README.md +90 -90
  52. package/examples/customer-service-demo/oad.yaml +107 -107
  53. package/package.json +1 -1
  54. package/src/analytics/index.ts +66 -66
  55. package/src/channels/discord.ts +192 -192
  56. package/src/channels/email.ts +177 -177
  57. package/src/channels/feishu.ts +236 -236
  58. package/src/channels/index.ts +15 -15
  59. package/src/channels/slack.ts +160 -160
  60. package/src/channels/telegram.ts +90 -90
  61. package/src/channels/voice.ts +106 -106
  62. package/src/channels/webhook.ts +199 -199
  63. package/src/channels/websocket.ts +87 -87
  64. package/src/channels/wechat.ts +149 -149
  65. package/src/cli.ts +124 -32
  66. package/src/core/a2a.ts +143 -143
  67. package/src/core/agent.ts +152 -152
  68. package/src/core/analytics-engine.ts +186 -186
  69. package/src/core/auth.ts +57 -57
  70. package/src/core/cache.ts +141 -141
  71. package/src/core/compose.ts +77 -77
  72. package/src/core/config.ts +14 -14
  73. package/src/core/errors.ts +148 -148
  74. package/src/core/hitl.ts +138 -138
  75. package/src/core/logger.ts +57 -57
  76. package/src/core/orchestrator.ts +215 -215
  77. package/src/core/performance.ts +187 -187
  78. package/src/core/rate-limiter.ts +128 -128
  79. package/src/core/room.ts +109 -109
  80. package/src/core/runtime.ts +152 -152
  81. package/src/core/sandbox.ts +101 -101
  82. package/src/core/security.ts +171 -171
  83. package/src/core/types.ts +68 -68
  84. package/src/core/versioning.ts +106 -106
  85. package/src/core/watch.ts +178 -178
  86. package/src/core/workflow.ts +235 -235
  87. package/src/deploy/hermes.ts +156 -156
  88. package/src/deploy/openclaw.ts +190 -200
  89. package/src/i18n/index.ts +216 -216
  90. package/src/index.ts +5 -6
  91. package/src/memory/deepbrain.ts +108 -108
  92. package/src/memory/index.ts +34 -34
  93. package/src/plugins/index.ts +208 -208
  94. package/src/schema/oad.ts +154 -155
  95. package/src/skills/base.ts +16 -16
  96. package/src/skills/document.ts +100 -100
  97. package/src/skills/http.ts +35 -35
  98. package/src/skills/index.ts +27 -27
  99. package/src/skills/scheduler.ts +80 -80
  100. package/src/skills/webhook-trigger.ts +59 -59
  101. package/src/templates/code-reviewer.ts +30 -34
  102. package/src/templates/customer-service.ts +76 -80
  103. package/src/templates/data-analyst.ts +66 -70
  104. package/src/templates/executive-assistant.ts +71 -71
  105. package/src/templates/financial-advisor.ts +60 -60
  106. package/src/templates/knowledge-base.ts +27 -31
  107. package/src/templates/legal-assistant.ts +71 -71
  108. package/src/templates/sales-assistant.ts +75 -79
  109. package/src/templates/teacher.ts +75 -79
  110. package/src/testing/index.ts +181 -181
  111. package/src/tools/calculator.ts +73 -73
  112. package/src/tools/datetime.ts +149 -149
  113. package/src/tools/json-transform.ts +187 -187
  114. package/src/tools/mcp.ts +76 -76
  115. package/src/tools/text-analysis.ts +116 -116
  116. package/src/traces/index.ts +132 -0
  117. package/templates/Dockerfile +15 -15
  118. package/templates/code-reviewer/README.md +27 -27
  119. package/templates/code-reviewer/oad.yaml +41 -41
  120. package/templates/customer-service/README.md +22 -22
  121. package/templates/customer-service/oad.yaml +36 -36
  122. package/templates/docker-compose.yml +21 -21
  123. package/templates/ecommerce-assistant/README.md +45 -45
  124. package/templates/ecommerce-assistant/oad.yaml +47 -47
  125. package/templates/knowledge-base/README.md +28 -28
  126. package/templates/knowledge-base/oad.yaml +38 -38
  127. package/templates/sales-assistant/README.md +26 -26
  128. package/templates/sales-assistant/oad.yaml +43 -43
  129. package/templates/tech-support/README.md +43 -43
  130. package/templates/tech-support/oad.yaml +45 -45
  131. package/tests/a2a.test.ts +66 -66
  132. package/tests/agent.test.ts +72 -72
  133. package/tests/analytics.test.ts +50 -50
  134. package/tests/channel.test.ts +39 -39
  135. package/tests/e2e.test.ts +134 -134
  136. package/tests/errors.test.ts +83 -83
  137. package/tests/hitl.test.ts +71 -71
  138. package/tests/i18n.test.ts +41 -41
  139. package/tests/mcp.test.ts +54 -54
  140. package/tests/oad.test.ts +68 -68
  141. package/tests/performance.test.ts +115 -115
  142. package/tests/plugin.test.ts +74 -74
  143. package/tests/room.test.ts +106 -106
  144. package/tests/runtime.test.ts +42 -42
  145. package/tests/sandbox.test.ts +46 -46
  146. package/tests/security.test.ts +60 -60
  147. package/tests/templates.test.ts +77 -77
  148. package/tests/v070.test.ts +76 -76
  149. package/tests/versioning.test.ts +75 -75
  150. package/tests/voice.test.ts +61 -61
  151. package/tests/webhook.test.ts +29 -29
  152. package/tests/workflow.test.ts +143 -143
  153. package/tsconfig.json +19 -19
  154. package/vitest.config.ts +9 -9
  155. package/src/dtv/data.ts +0 -29
  156. package/src/dtv/trust.ts +0 -43
  157. package/src/dtv/value.ts +0 -47
  158. package/src/marketplace/index.ts +0 -223
@@ -69,20 +69,27 @@ class OpenAICompatibleProvider {
69
69
  throw new Error('No API key configured. Set OPC_LLM_API_KEY or OPENAI_API_KEY environment variable.');
70
70
  }
71
71
  const url = new URL(`${this.baseUrl}/chat/completions`);
72
+ const isGemini = url.hostname.includes('googleapis.com');
73
+ if (isGemini) {
74
+ url.searchParams.set('key', this.apiKey);
75
+ }
72
76
  const isHttps = url.protocol === 'https:';
73
77
  const lib = isHttps ? https : http;
74
78
  const postData = JSON.stringify(body);
79
+ const headers = {
80
+ 'Content-Type': 'application/json',
81
+ 'Content-Length': String(Buffer.byteLength(postData)),
82
+ };
83
+ if (!isGemini) {
84
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
85
+ }
75
86
  return new Promise((resolve, reject) => {
76
87
  const req = lib.request({
77
88
  hostname: url.hostname,
78
89
  port: url.port || (isHttps ? 443 : 80),
79
- path: url.pathname,
90
+ path: url.pathname + url.search,
80
91
  method: 'POST',
81
- headers: {
82
- 'Content-Type': 'application/json',
83
- Authorization: `Bearer ${this.apiKey}`,
84
- 'Content-Length': Buffer.byteLength(postData),
85
- },
92
+ headers,
86
93
  }, (res) => {
87
94
  let data = '';
88
95
  res.on('data', (chunk) => (data += chunk.toString()));
@@ -127,6 +134,10 @@ class OpenAICompatibleProvider {
127
134
  }
128
135
  const formatted = this.formatMessages(messages, systemPrompt);
129
136
  const url = new URL(`${this.baseUrl}/chat/completions`);
137
+ const isGemini = url.hostname.includes('googleapis.com');
138
+ if (isGemini) {
139
+ url.searchParams.set('key', this.apiKey);
140
+ }
130
141
  const isHttps = url.protocol === 'https:';
131
142
  const lib = isHttps ? https : http;
132
143
  const postData = JSON.stringify({
@@ -136,17 +147,20 @@ class OpenAICompatibleProvider {
136
147
  max_tokens: 2048,
137
148
  stream: true,
138
149
  });
150
+ const streamHeaders = {
151
+ 'Content-Type': 'application/json',
152
+ 'Content-Length': String(Buffer.byteLength(postData)),
153
+ };
154
+ if (!isGemini) {
155
+ streamHeaders['Authorization'] = `Bearer ${this.apiKey}`;
156
+ }
139
157
  const response = await new Promise((resolve, reject) => {
140
158
  const req = lib.request({
141
159
  hostname: url.hostname,
142
160
  port: url.port || (isHttps ? 443 : 80),
143
- path: url.pathname,
161
+ path: url.pathname + url.search,
144
162
  method: 'POST',
145
- headers: {
146
- 'Content-Type': 'application/json',
147
- Authorization: `Bearer ${this.apiKey}`,
148
- 'Content-Length': Buffer.byteLength(postData),
149
- },
163
+ headers: streamHeaders,
150
164
  }, resolve);
151
165
  req.on('error', reject);
152
166
  req.write(postData);
@@ -183,9 +197,139 @@ class OpenAICompatibleProvider {
183
197
  }
184
198
  }
185
199
  }
200
+ class GeminiNativeProvider {
201
+ name = 'gemini';
202
+ model;
203
+ apiKey;
204
+ constructor(model, apiKey) {
205
+ this.model = model;
206
+ this.apiKey = apiKey || getApiKey();
207
+ }
208
+ buildUrl(stream) {
209
+ const action = stream ? 'streamGenerateContent?alt=sse&' : 'generateContent?';
210
+ return `https://generativelanguage.googleapis.com/v1beta/models/${this.model}:${action}key=${this.apiKey}`;
211
+ }
212
+ formatContents(messages, systemPrompt) {
213
+ const contents = [];
214
+ for (const m of messages) {
215
+ contents.push({ role: m.role === 'assistant' ? 'model' : 'user', parts: [{ text: m.content }] });
216
+ }
217
+ const result = { contents };
218
+ if (systemPrompt) {
219
+ result.systemInstruction = { parts: [{ text: systemPrompt }] };
220
+ }
221
+ return result;
222
+ }
223
+ async chat(messages, systemPrompt) {
224
+ if (!this.apiKey) {
225
+ const last = messages[messages.length - 1];
226
+ return `[gemini/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
227
+ }
228
+ const body = this.formatContents(messages, systemPrompt);
229
+ const url = this.buildUrl(false);
230
+ const postData = JSON.stringify(body);
231
+ return new Promise((resolve, reject) => {
232
+ const parsedUrl = new URL(url);
233
+ const req = https.request({
234
+ hostname: parsedUrl.hostname,
235
+ path: parsedUrl.pathname + parsedUrl.search,
236
+ method: 'POST',
237
+ headers: { 'Content-Type': 'application/json', 'Content-Length': String(Buffer.byteLength(postData)) },
238
+ }, (res) => {
239
+ let data = '';
240
+ res.on('data', (chunk) => (data += chunk.toString()));
241
+ res.on('end', () => {
242
+ if (res.statusCode && res.statusCode >= 400) {
243
+ reject(new Error(`Gemini API error ${res.statusCode}: ${data}`));
244
+ return;
245
+ }
246
+ try {
247
+ const parsed = JSON.parse(data);
248
+ resolve(parsed.candidates?.[0]?.content?.parts?.[0]?.text ?? '');
249
+ }
250
+ catch {
251
+ reject(new Error(`Invalid Gemini response: ${data.slice(0, 200)}`));
252
+ }
253
+ });
254
+ });
255
+ req.on('error', reject);
256
+ req.write(postData);
257
+ req.end();
258
+ });
259
+ }
260
+ async *chatStream(messages, systemPrompt) {
261
+ if (!this.apiKey) {
262
+ const last = messages[messages.length - 1];
263
+ yield `[gemini/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
264
+ return;
265
+ }
266
+ const body = this.formatContents(messages, systemPrompt);
267
+ const url = this.buildUrl(true);
268
+ const postData = JSON.stringify(body);
269
+ const parsedUrl = new URL(url);
270
+ const response = await new Promise((resolve, reject) => {
271
+ const req = https.request({
272
+ hostname: parsedUrl.hostname,
273
+ path: parsedUrl.pathname + parsedUrl.search,
274
+ method: 'POST',
275
+ headers: { 'Content-Type': 'application/json', 'Content-Length': String(Buffer.byteLength(postData)) },
276
+ }, resolve);
277
+ req.on('error', reject);
278
+ req.write(postData);
279
+ req.end();
280
+ });
281
+ if (response.statusCode && response.statusCode >= 400) {
282
+ let data = '';
283
+ for await (const chunk of response)
284
+ data += chunk.toString();
285
+ throw new Error(`Gemini API error ${response.statusCode}: ${data}`);
286
+ }
287
+ let buffer = '';
288
+ for await (const chunk of response) {
289
+ buffer += chunk.toString();
290
+ const lines = buffer.split('\n');
291
+ buffer = lines.pop() ?? '';
292
+ for (const line of lines) {
293
+ const trimmed = line.trim();
294
+ if (!trimmed.startsWith('data: '))
295
+ continue;
296
+ const data = trimmed.slice(6);
297
+ if (data === '[DONE]')
298
+ return;
299
+ try {
300
+ const parsed = JSON.parse(data);
301
+ const text = parsed.candidates?.[0]?.content?.parts?.[0]?.text;
302
+ if (text)
303
+ yield text;
304
+ }
305
+ catch { }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ function isGeminiNative() {
311
+ const baseUrl = process.env.OPC_LLM_BASE_URL || '';
312
+ const key = getApiKey();
313
+ // Use native Gemini API when: key starts with AQ. (new format) OR base URL points to googleapis
314
+ return key.startsWith('AQ.') || (baseUrl.includes('googleapis.com') && !baseUrl.includes('/openai'));
315
+ }
186
316
  function createProvider(name = 'openai', model, baseUrl, apiKey) {
187
317
  const finalModel = model || process.env.OPC_LLM_MODEL || 'gpt-4o-mini';
188
- return new OpenAICompatibleProvider(name, finalModel, baseUrl, apiKey);
318
+ const finalKey = apiKey || getApiKey();
319
+ const finalBaseUrl = baseUrl || getBaseUrl();
320
+ // Auto-detect Gemini native when key is new format or base URL points to googleapis
321
+ if (finalKey.startsWith('AQ.') || isGeminiNative()) {
322
+ return new GeminiNativeProvider(finalModel, finalKey);
323
+ }
324
+ // Auto-detect provider name from base URL
325
+ let resolvedName = name;
326
+ if (finalBaseUrl.includes('deepseek.com')) {
327
+ resolvedName = 'deepseek';
328
+ }
329
+ else if (finalBaseUrl.includes('dashscope.aliyuncs.com')) {
330
+ resolvedName = 'qwen';
331
+ }
332
+ return new OpenAICompatibleProvider(resolvedName, finalModel, baseUrl, apiKey);
189
333
  }
190
- exports.SUPPORTED_PROVIDERS = ['openai', 'deepseek', 'qwen'];
334
+ exports.SUPPORTED_PROVIDERS = ['openai', 'deepseek', 'qwen', 'gemini', 'dashscope', 'zhipu', 'moonshot'];
191
335
  //# sourceMappingURL=index.js.map
@@ -577,6 +577,7 @@ export declare const SpecSchema: z.ZodObject<{
577
577
  config?: Record<string, unknown> | undefined;
578
578
  }[] | undefined;
579
579
  }, {
580
+ model?: string | undefined;
580
581
  auth?: {
581
582
  enabled?: boolean | undefined;
582
583
  apiKeys?: string[] | undefined;
@@ -597,7 +598,6 @@ export declare const SpecSchema: z.ZodObject<{
597
598
  default?: string | undefined;
598
599
  allowed?: string[] | undefined;
599
600
  } | undefined;
600
- model?: string | undefined;
601
601
  systemPrompt?: string | undefined;
602
602
  skills?: {
603
603
  name: string;
@@ -995,6 +995,7 @@ export declare const OADSchema: z.ZodObject<{
995
995
  config?: Record<string, unknown> | undefined;
996
996
  }[] | undefined;
997
997
  }, {
998
+ model?: string | undefined;
998
999
  auth?: {
999
1000
  enabled?: boolean | undefined;
1000
1001
  apiKeys?: string[] | undefined;
@@ -1015,7 +1016,6 @@ export declare const OADSchema: z.ZodObject<{
1015
1016
  default?: string | undefined;
1016
1017
  allowed?: string[] | undefined;
1017
1018
  } | undefined;
1018
- model?: string | undefined;
1019
1019
  systemPrompt?: string | undefined;
1020
1020
  skills?: {
1021
1021
  name: string;
@@ -1183,6 +1183,7 @@ export declare const OADSchema: z.ZodObject<{
1183
1183
  } | undefined;
1184
1184
  };
1185
1185
  spec: {
1186
+ model?: string | undefined;
1186
1187
  auth?: {
1187
1188
  enabled?: boolean | undefined;
1188
1189
  apiKeys?: string[] | undefined;
@@ -1203,7 +1204,6 @@ export declare const OADSchema: z.ZodObject<{
1203
1204
  default?: string | undefined;
1204
1205
  allowed?: string[] | undefined;
1205
1206
  } | undefined;
1206
- model?: string | undefined;
1207
1207
  systemPrompt?: string | undefined;
1208
1208
  skills?: {
1209
1209
  name: string;
@@ -1266,6 +1266,5 @@ export type SkillRef = z.infer<typeof SkillRefSchema>;
1266
1266
  export type Channel = z.infer<typeof ChannelSchema>;
1267
1267
  export type Metadata = z.infer<typeof MetadataSchema>;
1268
1268
  export type Spec = z.infer<typeof SpecSchema>;
1269
- export type DTVConfig = z.infer<typeof DTVSchema>;
1270
- export type TrustLevelType = z.infer<typeof TrustLevel>;
1269
+ export type TrustLevelType = string;
1271
1270
  //# sourceMappingURL=oad.d.ts.map
@@ -28,14 +28,6 @@ export declare function createCodeReviewerConfig(): {
28
28
  shortTerm: boolean;
29
29
  longTerm: boolean;
30
30
  };
31
- dtv: {
32
- trust: {
33
- level: "sandbox";
34
- };
35
- value: {
36
- metrics: string[];
37
- };
38
- };
39
31
  };
40
32
  };
41
33
  //# sourceMappingURL=code-reviewer.d.ts.map
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CODE_REVIEWER_SYSTEM_PROMPT = void 0;
4
4
  exports.createCodeReviewerConfig = createCodeReviewerConfig;
5
- exports.CODE_REVIEWER_SYSTEM_PROMPT = `You are an expert code reviewer. When given code:
6
- 1. Check for bugs, security issues, and performance problems
7
- 2. Suggest improvements for readability and maintainability
8
- 3. Follow language-specific best practices
9
- 4. Be constructive and explain your reasoning
5
+ exports.CODE_REVIEWER_SYSTEM_PROMPT = `You are an expert code reviewer. When given code:
6
+ 1. Check for bugs, security issues, and performance problems
7
+ 2. Suggest improvements for readability and maintainability
8
+ 3. Follow language-specific best practices
9
+ 4. Be constructive and explain your reasoning
10
10
  Rate severity: 🔴 Critical | 🟡 Warning | 🔵 Info`;
11
11
  function createCodeReviewerConfig() {
12
12
  return {
@@ -28,10 +28,6 @@ function createCodeReviewerConfig() {
28
28
  ],
29
29
  channels: [{ type: 'web', port: 3000 }],
30
30
  memory: { shortTerm: true, longTerm: false },
31
- dtv: {
32
- trust: { level: 'sandbox' },
33
- value: { metrics: ['reviews_completed', 'issues_found'] },
34
- },
35
31
  },
36
32
  };
37
33
  }
@@ -43,14 +43,6 @@ export declare function createCustomerServiceConfig(): {
43
43
  shortTerm: boolean;
44
44
  longTerm: boolean;
45
45
  };
46
- dtv: {
47
- trust: {
48
- level: "sandbox";
49
- };
50
- value: {
51
- metrics: string[];
52
- };
53
- };
54
46
  };
55
47
  };
56
48
  //# sourceMappingURL=customer-service.d.ts.map
@@ -41,8 +41,8 @@ class HandoffSkill extends base_1.BaseSkill {
41
41
  }
42
42
  }
43
43
  exports.HandoffSkill = HandoffSkill;
44
- exports.CUSTOMER_SERVICE_SYSTEM_PROMPT = `You are a friendly and professional customer service agent.
45
- You help customers with their questions about products, orders, shipping, and returns.
44
+ exports.CUSTOMER_SERVICE_SYSTEM_PROMPT = `You are a friendly and professional customer service agent.
45
+ You help customers with their questions about products, orders, shipping, and returns.
46
46
  Be concise, helpful, and empathetic. If you're unsure, offer to connect them with a human agent.`;
47
47
  function createCustomerServiceConfig() {
48
48
  return {
@@ -65,10 +65,6 @@ function createCustomerServiceConfig() {
65
65
  ],
66
66
  channels: [{ type: 'web', port: 3000 }],
67
67
  memory: { shortTerm: true, longTerm: false },
68
- dtv: {
69
- trust: { level: 'sandbox' },
70
- value: { metrics: ['response_time', 'satisfaction_score'] },
71
- },
72
68
  },
73
69
  };
74
70
  }
@@ -40,14 +40,6 @@ export declare function createDataAnalystConfig(): {
40
40
  shortTerm: boolean;
41
41
  longTerm: boolean;
42
42
  };
43
- dtv: {
44
- trust: {
45
- level: "sandbox";
46
- };
47
- value: {
48
- metrics: string[];
49
- };
50
- };
51
43
  };
52
44
  };
53
45
  //# sourceMappingURL=data-analyst.d.ts.map
@@ -33,11 +33,11 @@ class InsightSkill extends base_1.BaseSkill {
33
33
  }
34
34
  }
35
35
  exports.InsightSkill = InsightSkill;
36
- exports.DATA_ANALYST_SYSTEM_PROMPT = `You are a professional data analyst assistant. Your goals:
37
- 1. Help users query, transform, and analyze data
38
- 2. Create clear visualizations and summaries
39
- 3. Identify trends, patterns, and anomalies
40
- 4. Explain findings in plain language
36
+ exports.DATA_ANALYST_SYSTEM_PROMPT = `You are a professional data analyst assistant. Your goals:
37
+ 1. Help users query, transform, and analyze data
38
+ 2. Create clear visualizations and summaries
39
+ 3. Identify trends, patterns, and anomalies
40
+ 4. Explain findings in plain language
41
41
  Be precise with numbers, always cite your data source, and suggest next steps for deeper analysis.`;
42
42
  function createDataAnalystConfig() {
43
43
  return {
@@ -60,10 +60,6 @@ function createDataAnalystConfig() {
60
60
  ],
61
61
  channels: [{ type: 'web', port: 3000 }],
62
62
  memory: { shortTerm: true, longTerm: true },
63
- dtv: {
64
- trust: { level: 'sandbox' },
65
- value: { metrics: ['queries_processed', 'insights_generated'] },
66
- },
67
63
  },
68
64
  };
69
65
  }
@@ -31,14 +31,6 @@ export declare function createKnowledgeBaseConfig(): {
31
31
  collection: string;
32
32
  };
33
33
  };
34
- dtv: {
35
- trust: {
36
- level: "sandbox";
37
- };
38
- value: {
39
- metrics: string[];
40
- };
41
- };
42
34
  };
43
35
  };
44
36
  //# sourceMappingURL=knowledge-base.d.ts.map
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KNOWLEDGE_BASE_SYSTEM_PROMPT = void 0;
4
4
  exports.createKnowledgeBaseConfig = createKnowledgeBaseConfig;
5
- exports.KNOWLEDGE_BASE_SYSTEM_PROMPT = `You are a knowledge base assistant. Answer questions using the company documents
6
- and knowledge provided to you. If you don't have enough information, say so honestly.
5
+ exports.KNOWLEDGE_BASE_SYSTEM_PROMPT = `You are a knowledge base assistant. Answer questions using the company documents
6
+ and knowledge provided to you. If you don't have enough information, say so honestly.
7
7
  Always cite sources when possible. Be accurate and concise.`;
8
8
  function createKnowledgeBaseConfig() {
9
9
  return {
@@ -25,10 +25,6 @@ function createKnowledgeBaseConfig() {
25
25
  ],
26
26
  channels: [{ type: 'web', port: 3000 }],
27
27
  memory: { shortTerm: true, longTerm: { provider: 'deepbrain', collection: 'company-knowledge' } },
28
- dtv: {
29
- trust: { level: 'sandbox' },
30
- value: { metrics: ['queries_answered', 'docs_indexed'] },
31
- },
32
28
  },
33
29
  };
34
30
  }
@@ -43,14 +43,6 @@ export declare function createSalesAssistantConfig(): {
43
43
  shortTerm: boolean;
44
44
  longTerm: boolean;
45
45
  };
46
- dtv: {
47
- trust: {
48
- level: "sandbox";
49
- };
50
- value: {
51
- metrics: string[];
52
- };
53
- };
54
46
  };
55
47
  };
56
48
  //# sourceMappingURL=sales-assistant.d.ts.map
@@ -43,10 +43,10 @@ class LeadCaptureSkill extends base_1.BaseSkill {
43
43
  }
44
44
  }
45
45
  exports.LeadCaptureSkill = LeadCaptureSkill;
46
- exports.SALES_ASSISTANT_SYSTEM_PROMPT = `You are a professional sales assistant. Your goals:
47
- 1. Answer product questions accurately and enthusiastically
48
- 2. Capture leads by collecting name, email, and company info
49
- 3. Book appointments when prospects are ready
46
+ exports.SALES_ASSISTANT_SYSTEM_PROMPT = `You are a professional sales assistant. Your goals:
47
+ 1. Answer product questions accurately and enthusiastically
48
+ 2. Capture leads by collecting name, email, and company info
49
+ 3. Book appointments when prospects are ready
50
50
  Be friendly, persuasive but not pushy. Always provide value first.`;
51
51
  function createSalesAssistantConfig() {
52
52
  return {
@@ -69,10 +69,6 @@ function createSalesAssistantConfig() {
69
69
  ],
70
70
  channels: [{ type: 'web', port: 3000 }],
71
71
  memory: { shortTerm: true, longTerm: false },
72
- dtv: {
73
- trust: { level: 'sandbox' },
74
- value: { metrics: ['leads_captured', 'appointments_booked'] },
75
- },
76
72
  },
77
73
  };
78
74
  }
@@ -45,14 +45,6 @@ export declare function createTeacherConfig(): {
45
45
  shortTerm: boolean;
46
46
  longTerm: boolean;
47
47
  };
48
- dtv: {
49
- trust: {
50
- level: "sandbox";
51
- };
52
- value: {
53
- metrics: string[];
54
- };
55
- };
56
48
  };
57
49
  };
58
50
  //# sourceMappingURL=teacher.d.ts.map
@@ -39,12 +39,12 @@ class ExplainSkill extends base_1.BaseSkill {
39
39
  }
40
40
  }
41
41
  exports.ExplainSkill = ExplainSkill;
42
- exports.TEACHER_SYSTEM_PROMPT = `You are a patient and encouraging teacher assistant. Your goals:
43
- 1. Create engaging lesson plans tailored to student level
44
- 2. Generate quizzes and assessments with answer keys
45
- 3. Explain complex concepts using analogies and examples
46
- 4. Provide constructive feedback and encouragement
47
- 5. Adapt teaching style to different learning preferences
42
+ exports.TEACHER_SYSTEM_PROMPT = `You are a patient and encouraging teacher assistant. Your goals:
43
+ 1. Create engaging lesson plans tailored to student level
44
+ 2. Generate quizzes and assessments with answer keys
45
+ 3. Explain complex concepts using analogies and examples
46
+ 4. Provide constructive feedback and encouragement
47
+ 5. Adapt teaching style to different learning preferences
48
48
  Be patient, use clear language, and always check for understanding. Use the Socratic method when appropriate.`;
49
49
  function createTeacherConfig() {
50
50
  return {
@@ -68,10 +68,6 @@ function createTeacherConfig() {
68
68
  ],
69
69
  channels: [{ type: 'web', port: 3000 }],
70
70
  memory: { shortTerm: true, longTerm: true },
71
- dtv: {
72
- trust: { level: 'sandbox' },
73
- value: { metrics: ['lessons_created', 'quizzes_generated', 'concepts_explained'] },
74
- },
75
71
  },
76
72
  };
77
73
  }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * OPC Agent Traces — Structured logging for agent actions.
3
+ *
4
+ * Collects traces that can be fed to DeepBrain's learn() API.
5
+ * Inspired by OpenTelemetry spans.
6
+ */
7
+ export interface Span {
8
+ traceId: string;
9
+ spanId: string;
10
+ name: string;
11
+ startTime: Date;
12
+ endTime?: Date;
13
+ attributes: Record<string, string | number | boolean>;
14
+ events: SpanEvent[];
15
+ status: 'ok' | 'error' | 'unset';
16
+ }
17
+ export interface SpanEvent {
18
+ name: string;
19
+ timestamp: Date;
20
+ attributes?: Record<string, string | number | boolean>;
21
+ }
22
+ export interface TraceExporter {
23
+ export(spans: Span[]): Promise<void>;
24
+ }
25
+ /** In-memory buffer that holds spans until flushed */
26
+ export declare class TraceCollector {
27
+ private spans;
28
+ private exporters;
29
+ private maxBufferSize;
30
+ constructor(maxBufferSize?: number);
31
+ addExporter(exporter: TraceExporter): void;
32
+ startSpan(name: string, attributes?: Record<string, string | number | boolean>): Span;
33
+ endSpan(span: Span, status?: 'ok' | 'error'): void;
34
+ addEvent(span: Span, name: string, attributes?: Record<string, string | number | boolean>): void;
35
+ flush(): Promise<number>;
36
+ getBufferedSpans(): readonly Span[];
37
+ get bufferedCount(): number;
38
+ }
39
+ /** Console exporter for development */
40
+ export declare class ConsoleExporter implements TraceExporter {
41
+ export(spans: Span[]): Promise<void>;
42
+ }
43
+ /** DeepBrain exporter — sends traces to DeepBrain learn() */
44
+ export declare class DeepBrainExporter implements TraceExporter {
45
+ private learnEndpoint;
46
+ constructor(deepbrainUrl?: string);
47
+ export(spans: Span[]): Promise<void>;
48
+ }
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * OPC Agent Traces — Structured logging for agent actions.
4
+ *
5
+ * Collects traces that can be fed to DeepBrain's learn() API.
6
+ * Inspired by OpenTelemetry spans.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DeepBrainExporter = exports.ConsoleExporter = exports.TraceCollector = void 0;
10
+ /** In-memory buffer that holds spans until flushed */
11
+ class TraceCollector {
12
+ spans = [];
13
+ exporters = [];
14
+ maxBufferSize;
15
+ constructor(maxBufferSize = 100) {
16
+ this.maxBufferSize = maxBufferSize;
17
+ }
18
+ addExporter(exporter) {
19
+ this.exporters.push(exporter);
20
+ }
21
+ startSpan(name, attributes = {}) {
22
+ const span = {
23
+ traceId: crypto.randomUUID(),
24
+ spanId: crypto.randomUUID().slice(0, 16),
25
+ name,
26
+ startTime: new Date(),
27
+ attributes,
28
+ events: [],
29
+ status: 'unset',
30
+ };
31
+ this.spans.push(span);
32
+ if (this.spans.length >= this.maxBufferSize) {
33
+ this.flush().catch(() => { }); // Best effort
34
+ }
35
+ return span;
36
+ }
37
+ endSpan(span, status = 'ok') {
38
+ span.endTime = new Date();
39
+ span.status = status;
40
+ }
41
+ addEvent(span, name, attributes) {
42
+ span.events.push({ name, timestamp: new Date(), attributes });
43
+ }
44
+ async flush() {
45
+ const toExport = [...this.spans];
46
+ this.spans = [];
47
+ for (const exporter of this.exporters) {
48
+ await exporter.export(toExport);
49
+ }
50
+ return toExport.length;
51
+ }
52
+ getBufferedSpans() {
53
+ return this.spans;
54
+ }
55
+ get bufferedCount() {
56
+ return this.spans.length;
57
+ }
58
+ }
59
+ exports.TraceCollector = TraceCollector;
60
+ /** Console exporter for development */
61
+ class ConsoleExporter {
62
+ async export(spans) {
63
+ for (const span of spans) {
64
+ const duration = span.endTime
65
+ ? `${span.endTime.getTime() - span.startTime.getTime()}ms`
66
+ : 'ongoing';
67
+ console.log(`[TRACE] ${span.name} (${duration}) [${span.status}]`);
68
+ }
69
+ }
70
+ }
71
+ exports.ConsoleExporter = ConsoleExporter;
72
+ /** DeepBrain exporter — sends traces to DeepBrain learn() */
73
+ class DeepBrainExporter {
74
+ learnEndpoint;
75
+ constructor(deepbrainUrl = 'http://localhost:3333') {
76
+ this.learnEndpoint = `${deepbrainUrl}/api/learn`;
77
+ }
78
+ async export(spans) {
79
+ for (const span of spans) {
80
+ try {
81
+ await fetch(this.learnEndpoint, {
82
+ method: 'POST',
83
+ headers: { 'Content-Type': 'application/json' },
84
+ body: JSON.stringify({
85
+ action: span.name,
86
+ result: span.status === 'ok' ? 'success' : 'error',
87
+ context: {
88
+ ...span.attributes,
89
+ duration: span.endTime ? span.endTime.getTime() - span.startTime.getTime() : null,
90
+ events: span.events.map(e => e.name),
91
+ },
92
+ }),
93
+ });
94
+ }
95
+ catch {
96
+ // Best effort — don't break agent if brain is down
97
+ }
98
+ }
99
+ }
100
+ }
101
+ exports.DeepBrainExporter = DeepBrainExporter;
102
+ //# sourceMappingURL=index.js.map