opc-agent 1.4.0 → 2.0.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +91 -32
  3. package/dist/channels/telegram.d.ts +30 -9
  4. package/dist/channels/telegram.js +125 -33
  5. package/dist/cli.js +415 -8
  6. package/dist/core/agent.d.ts +23 -0
  7. package/dist/core/agent.js +120 -3
  8. package/dist/core/runtime.d.ts +1 -0
  9. package/dist/core/runtime.js +44 -0
  10. package/dist/core/scheduler.d.ts +52 -0
  11. package/dist/core/scheduler.js +168 -0
  12. package/dist/core/subagent.d.ts +28 -0
  13. package/dist/core/subagent.js +65 -0
  14. package/dist/daemon.d.ts +3 -0
  15. package/dist/daemon.js +134 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +17 -1
  18. package/dist/providers/index.d.ts +5 -1
  19. package/dist/providers/index.js +16 -9
  20. package/dist/schema/oad.d.ts +179 -4
  21. package/dist/schema/oad.js +12 -1
  22. package/dist/skills/auto-learn.d.ts +28 -0
  23. package/dist/skills/auto-learn.js +257 -0
  24. package/dist/tools/builtin/datetime.d.ts +3 -0
  25. package/dist/tools/builtin/datetime.js +44 -0
  26. package/dist/tools/builtin/file.d.ts +3 -0
  27. package/dist/tools/builtin/file.js +151 -0
  28. package/dist/tools/builtin/index.d.ts +15 -0
  29. package/dist/tools/builtin/index.js +30 -0
  30. package/dist/tools/builtin/shell.d.ts +3 -0
  31. package/dist/tools/builtin/shell.js +43 -0
  32. package/dist/tools/builtin/web.d.ts +3 -0
  33. package/dist/tools/builtin/web.js +37 -0
  34. package/dist/tools/mcp-client.d.ts +24 -0
  35. package/dist/tools/mcp-client.js +119 -0
  36. package/package.json +1 -1
  37. package/src/channels/telegram.ts +212 -90
  38. package/src/cli.ts +418 -8
  39. package/src/core/agent.ts +295 -152
  40. package/src/core/runtime.ts +47 -0
  41. package/src/core/scheduler.ts +187 -0
  42. package/src/core/subagent.ts +98 -0
  43. package/src/daemon.ts +96 -0
  44. package/src/index.ts +11 -0
  45. package/src/providers/index.ts +354 -339
  46. package/src/schema/oad.ts +167 -154
  47. package/src/skills/auto-learn.ts +262 -0
  48. package/src/tools/builtin/datetime.ts +41 -0
  49. package/src/tools/builtin/file.ts +107 -0
  50. package/src/tools/builtin/index.ts +28 -0
  51. package/src/tools/builtin/shell.ts +43 -0
  52. package/src/tools/builtin/web.ts +35 -0
  53. package/src/tools/mcp-client.ts +131 -0
  54. package/tests/auto-learn.test.ts +105 -0
  55. package/tests/builtin-tools.test.ts +83 -0
  56. package/tests/cli.test.ts +46 -0
  57. package/tests/subagent.test.ts +130 -0
  58. package/tests/telegram-discord.test.ts +60 -0
package/dist/daemon.js ADDED
@@ -0,0 +1,134 @@
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
+ /**
38
+ * Daemon entry point — spawned by `opc start` as a detached background process.
39
+ * Loads agent.yaml, creates runtime, starts all channels, writes heartbeat.
40
+ */
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const runtime_1 = require("./core/runtime");
44
+ const OPC_DIR = path.resolve('.opc');
45
+ const HEARTBEAT_FILE = path.join(OPC_DIR, 'heartbeat');
46
+ const LOG_FILE = path.join(OPC_DIR, 'agent.log');
47
+ const PID_FILE = path.join(OPC_DIR, 'agent.pid');
48
+ const HEARTBEAT_INTERVAL = 30_000;
49
+ function ensureDir(dir) {
50
+ if (!fs.existsSync(dir))
51
+ fs.mkdirSync(dir, { recursive: true });
52
+ }
53
+ function log(msg) {
54
+ const line = `[${new Date().toISOString()}] ${msg}\n`;
55
+ try {
56
+ fs.appendFileSync(LOG_FILE, line);
57
+ }
58
+ catch { /* ignore */ }
59
+ }
60
+ async function main() {
61
+ ensureDir(OPC_DIR);
62
+ // Redirect stdout/stderr to log file
63
+ const logStream = fs.createWriteStream(LOG_FILE, { flags: 'a' });
64
+ process.stdout.write = logStream.write.bind(logStream);
65
+ process.stderr.write = logStream.write.bind(logStream);
66
+ // Write PID
67
+ fs.writeFileSync(PID_FILE, String(process.pid));
68
+ log(`Daemon started, PID=${process.pid}`);
69
+ // Write start time for uptime calculation
70
+ fs.writeFileSync(path.join(OPC_DIR, 'started'), String(Date.now()));
71
+ // Heartbeat
72
+ const heartbeatTimer = setInterval(() => {
73
+ try {
74
+ fs.writeFileSync(HEARTBEAT_FILE, String(Date.now()));
75
+ }
76
+ catch { /* ignore */ }
77
+ }, HEARTBEAT_INTERVAL);
78
+ fs.writeFileSync(HEARTBEAT_FILE, String(Date.now()));
79
+ // Load .env
80
+ const envPath = path.resolve('.env');
81
+ if (fs.existsSync(envPath)) {
82
+ try {
83
+ const content = fs.readFileSync(envPath, 'utf-8');
84
+ for (const line of content.split('\n')) {
85
+ const trimmed = line.trim();
86
+ if (!trimmed || trimmed.startsWith('#'))
87
+ continue;
88
+ const eqIdx = trimmed.indexOf('=');
89
+ if (eqIdx === -1)
90
+ continue;
91
+ const key = trimmed.slice(0, eqIdx).trim();
92
+ const value = trimmed.slice(eqIdx + 1).trim();
93
+ if (!process.env[key])
94
+ process.env[key] = value;
95
+ }
96
+ }
97
+ catch { /* ignore */ }
98
+ }
99
+ // Determine config file
100
+ const configFile = fs.existsSync('agent.yaml') ? 'agent.yaml' : 'oad.yaml';
101
+ const runtime = new runtime_1.AgentRuntime();
102
+ await runtime.loadConfig(configFile);
103
+ await runtime.initialize();
104
+ await runtime.start();
105
+ log(`Agent running (config=${configFile})`);
106
+ // Graceful shutdown
107
+ const shutdown = async (signal) => {
108
+ log(`Received ${signal}, shutting down...`);
109
+ clearInterval(heartbeatTimer);
110
+ await runtime.stop();
111
+ try {
112
+ fs.unlinkSync(PID_FILE);
113
+ }
114
+ catch { /* ignore */ }
115
+ log('Daemon stopped');
116
+ process.exit(0);
117
+ };
118
+ process.on('SIGTERM', () => shutdown('SIGTERM'));
119
+ process.on('SIGINT', () => shutdown('SIGINT'));
120
+ // On Windows, handle the message-based kill
121
+ process.on('message', (msg) => {
122
+ if (msg === 'shutdown')
123
+ shutdown('message:shutdown');
124
+ });
125
+ }
126
+ main().catch((err) => {
127
+ log(`Fatal error: ${err instanceof Error ? err.message : String(err)}`);
128
+ try {
129
+ fs.unlinkSync(PID_FILE);
130
+ }
131
+ catch { /* ignore */ }
132
+ process.exit(1);
133
+ });
134
+ //# sourceMappingURL=daemon.js.map
package/dist/index.d.ts CHANGED
@@ -65,6 +65,8 @@ export { SchedulerSkill } from './skills/scheduler';
65
65
  export type { ScheduledTask } from './skills/scheduler';
66
66
  export { DocumentSkill } from './skills/document';
67
67
  export type { DocumentChunk } from './skills/document';
68
+ export { SkillLearner, skillToMarkdown, parseSkillMarkdown } from './skills/auto-learn';
69
+ export type { LearnedSkill } from './skills/auto-learn';
68
70
  export { runTests, loadTestCases, formatReport } from './testing';
69
71
  export type { TestCase, TestResult, TestReport } from './testing';
70
72
  export { AnalyticsEngine } from './core/analytics-engine';
@@ -92,4 +94,9 @@ export { StreamingManager, StreamableResponse } from './core/streaming';
92
94
  export type { StreamChunk, StreamOptions } from './core/streaming';
93
95
  export { TraceCollector, ConsoleExporter, DeepBrainExporter } from './traces';
94
96
  export type { Span, SpanEvent, TraceExporter } from './traces';
97
+ export { Scheduler, parseCron, cronMatches } from './core/scheduler';
98
+ export type { CronJob, JobHandler } from './core/scheduler';
99
+ export { getBuiltinTools, getBuiltinToolsByName } from './tools/builtin';
100
+ export { MCPClient } from './tools/mcp-client';
101
+ export type { MCPServerConfig } from './tools/mcp-client';
95
102
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonTransformTool = exports.DateTimeTool = exports.CalculatorTool = exports.WeChatChannel = exports.SlackChannel = exports.EmailChannel = exports.compose = exports.AgentPipeline = exports.Orchestrator = exports.getActiveSessions = exports.createAuthMiddleware = exports.deployToHermes = exports.KnowledgeBase = exports.addMessages = exports.detectLocale = exports.getLocale = exports.setLocale = exports.t = exports.LazyLoader = exports.RequestBatcher = exports.ConnectionPool = exports.VersionManager = exports.WebhookChannel = exports.VoiceChannel = exports.HITLManager = exports.AgentRegistry = exports.WorkflowEngine = exports.Analytics = exports.Sandbox = exports.PluginManager = exports.createMCPTool = exports.MCPToolRegistry = exports.Room = exports.SUPPORTED_PROVIDERS = exports.createProvider = 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
- exports.DeepBrainExporter = exports.ConsoleExporter = exports.TraceCollector = exports.StreamableResponse = exports.StreamingManager = exports.ToolGateway = exports.ProcessWatcher = exports.DiscordChannel = exports.FeishuChannel = exports.createRateLimitPlugin = exports.createAnalyticsPlugin = exports.createLoggingPlugin = exports.inputValidation = exports.APIKeyManager = exports.corsMiddleware = exports.securityHeaders = exports.detectInjection = exports.sanitizeInput = exports.formatErrorForUser = exports.wrapError = exports.TimeoutError = exports.SecurityError = exports.RateLimitError = exports.PluginError = exports.ChannelError = exports.ConfigError = exports.ValidationError = exports.ProviderError = exports.OPCError = exports.createTeacherConfig = exports.createDataAnalystConfig = exports.getSupportedLocales = exports.LLMCache = exports.RateLimiter = exports.AnalyticsEngine = exports.formatReport = exports.loadTestCases = exports.runTests = exports.DocumentSkill = exports.SchedulerSkill = exports.WebhookTriggerSkill = exports.HttpSkill = exports.TextAnalysisTool = void 0;
4
+ exports.getBuiltinTools = exports.cronMatches = exports.parseCron = exports.Scheduler = exports.DeepBrainExporter = exports.ConsoleExporter = exports.TraceCollector = exports.StreamableResponse = exports.StreamingManager = exports.ToolGateway = exports.ProcessWatcher = exports.DiscordChannel = exports.FeishuChannel = exports.createRateLimitPlugin = exports.createAnalyticsPlugin = exports.createLoggingPlugin = exports.inputValidation = exports.APIKeyManager = exports.corsMiddleware = exports.securityHeaders = exports.detectInjection = exports.sanitizeInput = exports.formatErrorForUser = exports.wrapError = exports.TimeoutError = exports.SecurityError = exports.RateLimitError = exports.PluginError = exports.ChannelError = exports.ConfigError = exports.ValidationError = exports.ProviderError = exports.OPCError = exports.createTeacherConfig = exports.createDataAnalystConfig = exports.getSupportedLocales = exports.LLMCache = exports.RateLimiter = exports.AnalyticsEngine = exports.formatReport = exports.loadTestCases = exports.runTests = exports.parseSkillMarkdown = exports.skillToMarkdown = exports.SkillLearner = exports.DocumentSkill = exports.SchedulerSkill = exports.WebhookTriggerSkill = exports.HttpSkill = exports.TextAnalysisTool = void 0;
5
+ exports.MCPClient = exports.getBuiltinToolsByName = void 0;
5
6
  // OPC Agent — Open Agent Framework
6
7
  var agent_1 = require("./core/agent");
7
8
  Object.defineProperty(exports, "BaseAgent", { enumerable: true, get: function () { return agent_1.BaseAgent; } });
@@ -106,6 +107,10 @@ var scheduler_1 = require("./skills/scheduler");
106
107
  Object.defineProperty(exports, "SchedulerSkill", { enumerable: true, get: function () { return scheduler_1.SchedulerSkill; } });
107
108
  var document_1 = require("./skills/document");
108
109
  Object.defineProperty(exports, "DocumentSkill", { enumerable: true, get: function () { return document_1.DocumentSkill; } });
110
+ var auto_learn_1 = require("./skills/auto-learn");
111
+ Object.defineProperty(exports, "SkillLearner", { enumerable: true, get: function () { return auto_learn_1.SkillLearner; } });
112
+ Object.defineProperty(exports, "skillToMarkdown", { enumerable: true, get: function () { return auto_learn_1.skillToMarkdown; } });
113
+ Object.defineProperty(exports, "parseSkillMarkdown", { enumerable: true, get: function () { return auto_learn_1.parseSkillMarkdown; } });
109
114
  // v0.9.0 modules
110
115
  var testing_1 = require("./testing");
111
116
  Object.defineProperty(exports, "runTests", { enumerable: true, get: function () { return testing_1.runTests; } });
@@ -165,4 +170,15 @@ var traces_1 = require("./traces");
165
170
  Object.defineProperty(exports, "TraceCollector", { enumerable: true, get: function () { return traces_1.TraceCollector; } });
166
171
  Object.defineProperty(exports, "ConsoleExporter", { enumerable: true, get: function () { return traces_1.ConsoleExporter; } });
167
172
  Object.defineProperty(exports, "DeepBrainExporter", { enumerable: true, get: function () { return traces_1.DeepBrainExporter; } });
173
+ // v1.4.0 modules
174
+ var scheduler_2 = require("./core/scheduler");
175
+ Object.defineProperty(exports, "Scheduler", { enumerable: true, get: function () { return scheduler_2.Scheduler; } });
176
+ Object.defineProperty(exports, "parseCron", { enumerable: true, get: function () { return scheduler_2.parseCron; } });
177
+ Object.defineProperty(exports, "cronMatches", { enumerable: true, get: function () { return scheduler_2.cronMatches; } });
178
+ // v1.5.0 — built-in tools + MCP client
179
+ var builtin_1 = require("./tools/builtin");
180
+ Object.defineProperty(exports, "getBuiltinTools", { enumerable: true, get: function () { return builtin_1.getBuiltinTools; } });
181
+ Object.defineProperty(exports, "getBuiltinToolsByName", { enumerable: true, get: function () { return builtin_1.getBuiltinToolsByName; } });
182
+ var mcp_client_1 = require("./tools/mcp-client");
183
+ Object.defineProperty(exports, "MCPClient", { enumerable: true, get: function () { return mcp_client_1.MCPClient; } });
168
184
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,11 @@
1
1
  import type { Message } from '../core/types';
2
+ import type { MCPToolDefinition } from '../tools/mcp';
3
+ export interface ChatOptions {
4
+ tools?: MCPToolDefinition[];
5
+ }
2
6
  export interface LLMProvider {
3
7
  name: string;
4
- chat(messages: Message[], systemPrompt?: string): Promise<string>;
8
+ chat(messages: Message[], systemPrompt?: string, options?: ChatOptions): Promise<string>;
5
9
  chatStream(messages: Message[], systemPrompt?: string): AsyncIterable<string>;
6
10
  }
7
11
  export declare function createProvider(name?: string, model?: string, baseUrl?: string, apiKey?: string): LLMProvider;
@@ -43,6 +43,10 @@ function getApiKey() {
43
43
  function getBaseUrl() {
44
44
  return process.env.OPC_LLM_BASE_URL || 'https://api.openai.com/v1';
45
45
  }
46
+ function buildToolPrompt(tools) {
47
+ const toolsDesc = tools.map(t => `- ${t.name}: ${t.description}\n Input schema: ${JSON.stringify(t.inputSchema)}`).join('\n');
48
+ return `\n\nYou have access to the following tools. To use a tool, respond with ONLY a JSON object in this format:\n<tool_call>{"name": "tool_name", "arguments": {...}}</tool_call>\n\nAvailable tools:\n${toolsDesc}\n\nIf you don't need a tool, respond normally with text.`;
49
+ }
46
50
  class OpenAICompatibleProvider {
47
51
  name;
48
52
  model;
@@ -111,13 +115,16 @@ class OpenAICompatibleProvider {
111
115
  req.end();
112
116
  });
113
117
  }
114
- async chat(messages, systemPrompt) {
118
+ async chat(messages, systemPrompt, options) {
115
119
  if (!this.apiKey) {
116
- // Stub mode when no API key
117
120
  const last = messages[messages.length - 1];
118
121
  return `[${this.name}/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
119
122
  }
120
- const formatted = this.formatMessages(messages, systemPrompt);
123
+ let effectivePrompt = systemPrompt;
124
+ if (options?.tools && options.tools.length > 0) {
125
+ effectivePrompt = (systemPrompt || '') + buildToolPrompt(options.tools);
126
+ }
127
+ const formatted = this.formatMessages(messages, effectivePrompt);
121
128
  const result = await this.request({
122
129
  model: this.model,
123
130
  messages: formatted,
@@ -220,12 +227,16 @@ class GeminiNativeProvider {
220
227
  }
221
228
  return result;
222
229
  }
223
- async chat(messages, systemPrompt) {
230
+ async chat(messages, systemPrompt, options) {
224
231
  if (!this.apiKey) {
225
232
  const last = messages[messages.length - 1];
226
233
  return `[gemini/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
227
234
  }
228
- const body = this.formatContents(messages, systemPrompt);
235
+ let effectivePrompt = systemPrompt;
236
+ if (options?.tools && options.tools.length > 0) {
237
+ effectivePrompt = (systemPrompt || '') + buildToolPrompt(options.tools);
238
+ }
239
+ const body = this.formatContents(messages, effectivePrompt);
229
240
  const url = this.buildUrl(false);
230
241
  const postData = JSON.stringify(body);
231
242
  return new Promise((resolve, reject) => {
@@ -310,12 +321,10 @@ class GeminiNativeProvider {
310
321
  function isGeminiNative() {
311
322
  const baseUrl = process.env.OPC_LLM_BASE_URL || '';
312
323
  const key = getApiKey();
313
- // Use native Gemini API when: key starts with AQ. (new format) OR base URL points to googleapis
314
324
  return key.startsWith('AQ.') || (baseUrl.includes('googleapis.com') && !baseUrl.includes('/openai'));
315
325
  }
316
326
  function createProvider(name = 'openai', model, baseUrl, apiKey) {
317
327
  const finalModel = model || process.env.OPC_LLM_MODEL || 'gpt-4o-mini';
318
- // Auto-detect ollama: use localhost:11434/v1 and dummy apiKey
319
328
  if (name === 'ollama') {
320
329
  const ollamaBase = baseUrl || process.env.OPC_LLM_BASE_URL || 'http://localhost:11434/v1';
321
330
  const ollamaKey = apiKey || process.env.OPC_LLM_API_KEY || 'ollama';
@@ -323,11 +332,9 @@ function createProvider(name = 'openai', model, baseUrl, apiKey) {
323
332
  }
324
333
  const finalKey = apiKey || getApiKey();
325
334
  const finalBaseUrl = baseUrl || getBaseUrl();
326
- // Auto-detect Gemini native when key is new format or base URL points to googleapis
327
335
  if (finalKey.startsWith('AQ.') || isGeminiNative()) {
328
336
  return new GeminiNativeProvider(finalModel, finalKey);
329
337
  }
330
- // Auto-detect provider name from base URL
331
338
  let resolvedName = name;
332
339
  if (finalBaseUrl.includes('deepseek.com')) {
333
340
  resolvedName = 'deepseek';
@@ -286,6 +286,57 @@ export declare const StreamingSchema: z.ZodObject<{
286
286
  enabled?: boolean | undefined;
287
287
  chunkSize?: number | undefined;
288
288
  }>;
289
+ export declare const MCPServerSchema: z.ZodObject<{
290
+ name: z.ZodString;
291
+ command: z.ZodString;
292
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
293
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
294
+ }, "strip", z.ZodTypeAny, {
295
+ name: string;
296
+ command: string;
297
+ args?: string[] | undefined;
298
+ env?: Record<string, string> | undefined;
299
+ }, {
300
+ name: string;
301
+ command: string;
302
+ args?: string[] | undefined;
303
+ env?: Record<string, string> | undefined;
304
+ }>;
305
+ export declare const ToolsSchema: z.ZodObject<{
306
+ builtin: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
307
+ mcp: z.ZodOptional<z.ZodArray<z.ZodObject<{
308
+ name: z.ZodString;
309
+ command: z.ZodString;
310
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
311
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
312
+ }, "strip", z.ZodTypeAny, {
313
+ name: string;
314
+ command: string;
315
+ args?: string[] | undefined;
316
+ env?: Record<string, string> | undefined;
317
+ }, {
318
+ name: string;
319
+ command: string;
320
+ args?: string[] | undefined;
321
+ env?: Record<string, string> | undefined;
322
+ }>, "many">>;
323
+ }, "strip", z.ZodTypeAny, {
324
+ builtin?: string[] | undefined;
325
+ mcp?: {
326
+ name: string;
327
+ command: string;
328
+ args?: string[] | undefined;
329
+ env?: Record<string, string> | undefined;
330
+ }[] | undefined;
331
+ }, {
332
+ builtin?: string[] | undefined;
333
+ mcp?: {
334
+ name: string;
335
+ command: string;
336
+ args?: string[] | undefined;
337
+ env?: Record<string, string> | undefined;
338
+ }[] | undefined;
339
+ }>;
289
340
  export declare const SpecSchema: z.ZodObject<{
290
341
  provider: z.ZodOptional<z.ZodObject<{
291
342
  default: z.ZodDefault<z.ZodString>;
@@ -358,6 +409,41 @@ export declare const SpecSchema: z.ZodObject<{
358
409
  collection?: string | undefined;
359
410
  } | undefined;
360
411
  }>>;
412
+ tools: z.ZodOptional<z.ZodObject<{
413
+ builtin: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
414
+ mcp: z.ZodOptional<z.ZodArray<z.ZodObject<{
415
+ name: z.ZodString;
416
+ command: z.ZodString;
417
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
418
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
419
+ }, "strip", z.ZodTypeAny, {
420
+ name: string;
421
+ command: string;
422
+ args?: string[] | undefined;
423
+ env?: Record<string, string> | undefined;
424
+ }, {
425
+ name: string;
426
+ command: string;
427
+ args?: string[] | undefined;
428
+ env?: Record<string, string> | undefined;
429
+ }>, "many">>;
430
+ }, "strip", z.ZodTypeAny, {
431
+ builtin?: string[] | undefined;
432
+ mcp?: {
433
+ name: string;
434
+ command: string;
435
+ args?: string[] | undefined;
436
+ env?: Record<string, string> | undefined;
437
+ }[] | undefined;
438
+ }, {
439
+ builtin?: string[] | undefined;
440
+ mcp?: {
441
+ name: string;
442
+ command: string;
443
+ args?: string[] | undefined;
444
+ env?: Record<string, string> | undefined;
445
+ }[] | undefined;
446
+ }>>;
361
447
  dtv: z.ZodOptional<z.ZodObject<{
362
448
  trust: z.ZodOptional<z.ZodObject<{
363
449
  level: z.ZodDefault<z.ZodEnum<["sandbox", "verified", "certified", "listed"]>>;
@@ -515,6 +601,15 @@ export declare const SpecSchema: z.ZodObject<{
515
601
  enabled: boolean;
516
602
  chunkSize?: number | undefined;
517
603
  };
604
+ tools?: {
605
+ builtin?: string[] | undefined;
606
+ mcp?: {
607
+ name: string;
608
+ command: string;
609
+ args?: string[] | undefined;
610
+ env?: Record<string, string> | undefined;
611
+ }[] | undefined;
612
+ } | undefined;
518
613
  auth?: {
519
614
  enabled: boolean;
520
615
  apiKeys: string[];
@@ -577,6 +672,15 @@ export declare const SpecSchema: z.ZodObject<{
577
672
  config?: Record<string, unknown> | undefined;
578
673
  }[] | undefined;
579
674
  }, {
675
+ tools?: {
676
+ builtin?: string[] | undefined;
677
+ mcp?: {
678
+ name: string;
679
+ command: string;
680
+ args?: string[] | undefined;
681
+ env?: Record<string, string> | undefined;
682
+ }[] | undefined;
683
+ } | undefined;
580
684
  model?: string | undefined;
581
685
  auth?: {
582
686
  enabled?: boolean | undefined;
@@ -776,6 +880,41 @@ export declare const OADSchema: z.ZodObject<{
776
880
  collection?: string | undefined;
777
881
  } | undefined;
778
882
  }>>;
883
+ tools: z.ZodOptional<z.ZodObject<{
884
+ builtin: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
885
+ mcp: z.ZodOptional<z.ZodArray<z.ZodObject<{
886
+ name: z.ZodString;
887
+ command: z.ZodString;
888
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
889
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
890
+ }, "strip", z.ZodTypeAny, {
891
+ name: string;
892
+ command: string;
893
+ args?: string[] | undefined;
894
+ env?: Record<string, string> | undefined;
895
+ }, {
896
+ name: string;
897
+ command: string;
898
+ args?: string[] | undefined;
899
+ env?: Record<string, string> | undefined;
900
+ }>, "many">>;
901
+ }, "strip", z.ZodTypeAny, {
902
+ builtin?: string[] | undefined;
903
+ mcp?: {
904
+ name: string;
905
+ command: string;
906
+ args?: string[] | undefined;
907
+ env?: Record<string, string> | undefined;
908
+ }[] | undefined;
909
+ }, {
910
+ builtin?: string[] | undefined;
911
+ mcp?: {
912
+ name: string;
913
+ command: string;
914
+ args?: string[] | undefined;
915
+ env?: Record<string, string> | undefined;
916
+ }[] | undefined;
917
+ }>>;
779
918
  dtv: z.ZodOptional<z.ZodObject<{
780
919
  trust: z.ZodOptional<z.ZodObject<{
781
920
  level: z.ZodDefault<z.ZodEnum<["sandbox", "verified", "certified", "listed"]>>;
@@ -933,6 +1072,15 @@ export declare const OADSchema: z.ZodObject<{
933
1072
  enabled: boolean;
934
1073
  chunkSize?: number | undefined;
935
1074
  };
1075
+ tools?: {
1076
+ builtin?: string[] | undefined;
1077
+ mcp?: {
1078
+ name: string;
1079
+ command: string;
1080
+ args?: string[] | undefined;
1081
+ env?: Record<string, string> | undefined;
1082
+ }[] | undefined;
1083
+ } | undefined;
936
1084
  auth?: {
937
1085
  enabled: boolean;
938
1086
  apiKeys: string[];
@@ -995,6 +1143,15 @@ export declare const OADSchema: z.ZodObject<{
995
1143
  config?: Record<string, unknown> | undefined;
996
1144
  }[] | undefined;
997
1145
  }, {
1146
+ tools?: {
1147
+ builtin?: string[] | undefined;
1148
+ mcp?: {
1149
+ name: string;
1150
+ command: string;
1151
+ args?: string[] | undefined;
1152
+ env?: Record<string, string> | undefined;
1153
+ }[] | undefined;
1154
+ } | undefined;
998
1155
  model?: string | undefined;
999
1156
  auth?: {
1000
1157
  enabled?: boolean | undefined;
@@ -1073,8 +1230,6 @@ export declare const OADSchema: z.ZodObject<{
1073
1230
  }[] | undefined;
1074
1231
  }>;
1075
1232
  }, "strip", z.ZodTypeAny, {
1076
- apiVersion: "opc/v1";
1077
- kind: "Agent";
1078
1233
  metadata: {
1079
1234
  name: string;
1080
1235
  version: string;
@@ -1088,6 +1243,8 @@ export declare const OADSchema: z.ZodObject<{
1088
1243
  tags?: string[] | undefined;
1089
1244
  } | undefined;
1090
1245
  };
1246
+ apiVersion: "opc/v1";
1247
+ kind: "Agent";
1091
1248
  spec: {
1092
1249
  model: string;
1093
1250
  skills: {
@@ -1104,6 +1261,15 @@ export declare const OADSchema: z.ZodObject<{
1104
1261
  enabled: boolean;
1105
1262
  chunkSize?: number | undefined;
1106
1263
  };
1264
+ tools?: {
1265
+ builtin?: string[] | undefined;
1266
+ mcp?: {
1267
+ name: string;
1268
+ command: string;
1269
+ args?: string[] | undefined;
1270
+ env?: Record<string, string> | undefined;
1271
+ }[] | undefined;
1272
+ } | undefined;
1107
1273
  auth?: {
1108
1274
  enabled: boolean;
1109
1275
  apiKeys: string[];
@@ -1167,8 +1333,6 @@ export declare const OADSchema: z.ZodObject<{
1167
1333
  }[] | undefined;
1168
1334
  };
1169
1335
  }, {
1170
- apiVersion: "opc/v1";
1171
- kind: "Agent";
1172
1336
  metadata: {
1173
1337
  name: string;
1174
1338
  description?: string | undefined;
@@ -1182,7 +1346,18 @@ export declare const OADSchema: z.ZodObject<{
1182
1346
  tags?: string[] | undefined;
1183
1347
  } | undefined;
1184
1348
  };
1349
+ apiVersion: "opc/v1";
1350
+ kind: "Agent";
1185
1351
  spec: {
1352
+ tools?: {
1353
+ builtin?: string[] | undefined;
1354
+ mcp?: {
1355
+ name: string;
1356
+ command: string;
1357
+ args?: string[] | undefined;
1358
+ env?: Record<string, string> | undefined;
1359
+ }[] | undefined;
1360
+ } | undefined;
1186
1361
  model?: string | undefined;
1187
1362
  auth?: {
1188
1363
  enabled?: boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OADSchema = exports.SpecSchema = exports.StreamingSchema = exports.RoomSchema = exports.MetadataSchema = exports.MarketplaceSchema = exports.ProviderSchema = exports.DTVSchema = exports.TrustLevel = exports.MemorySchema = exports.LongTermMemorySchema = exports.ChannelSchema = exports.AuthSchema = exports.PluginRefSchema = exports.HITLSchema = exports.WebhookSchema = exports.VoiceSchema = exports.WorkflowSchema = exports.WorkflowStepSchema = exports.SkillRefSchema = void 0;
3
+ exports.OADSchema = exports.SpecSchema = exports.ToolsSchema = exports.MCPServerSchema = exports.StreamingSchema = exports.RoomSchema = exports.MetadataSchema = exports.MarketplaceSchema = exports.ProviderSchema = exports.DTVSchema = exports.TrustLevel = exports.MemorySchema = exports.LongTermMemorySchema = exports.ChannelSchema = exports.AuthSchema = exports.PluginRefSchema = exports.HITLSchema = exports.WebhookSchema = exports.VoiceSchema = exports.WorkflowSchema = exports.WorkflowStepSchema = exports.SkillRefSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  // ─── OAD Schema v1 ───────────────────────────────────────────
6
6
  exports.SkillRefSchema = zod_1.z.object({
@@ -103,6 +103,16 @@ exports.StreamingSchema = zod_1.z.object({
103
103
  enabled: zod_1.z.boolean().default(false),
104
104
  chunkSize: zod_1.z.number().optional(),
105
105
  });
106
+ exports.MCPServerSchema = zod_1.z.object({
107
+ name: zod_1.z.string(),
108
+ command: zod_1.z.string(),
109
+ args: zod_1.z.array(zod_1.z.string()).optional(),
110
+ env: zod_1.z.record(zod_1.z.string()).optional(),
111
+ });
112
+ exports.ToolsSchema = zod_1.z.object({
113
+ builtin: zod_1.z.array(zod_1.z.string()).optional(),
114
+ mcp: zod_1.z.array(exports.MCPServerSchema).optional(),
115
+ });
106
116
  exports.SpecSchema = zod_1.z.object({
107
117
  provider: exports.ProviderSchema.optional(),
108
118
  model: zod_1.z.string().default('deepseek-chat'),
@@ -110,6 +120,7 @@ exports.SpecSchema = zod_1.z.object({
110
120
  skills: zod_1.z.array(exports.SkillRefSchema).default([]),
111
121
  channels: zod_1.z.array(exports.ChannelSchema).default([]),
112
122
  memory: exports.MemorySchema.optional(),
123
+ tools: exports.ToolsSchema.optional(),
113
124
  dtv: exports.DTVSchema.optional(),
114
125
  room: exports.RoomSchema.optional(),
115
126
  streaming: zod_1.z.union([zod_1.z.boolean(), exports.StreamingSchema]).default(false),
@@ -0,0 +1,28 @@
1
+ import type { Message } from '../core/types';
2
+ import type { LLMProvider } from '../providers';
3
+ export interface LearnedSkill {
4
+ name: string;
5
+ description: string;
6
+ trigger: string;
7
+ instructions: string;
8
+ examples: string[];
9
+ createdAt: Date;
10
+ usageCount: number;
11
+ lastUsed?: Date;
12
+ version: number;
13
+ }
14
+ export declare class SkillLearner {
15
+ private skillsDir;
16
+ private skills;
17
+ private loaded;
18
+ constructor(skillsDir: string);
19
+ analyzeForSkillCreation(conversation: Message[], provider: LLMProvider): Promise<LearnedSkill | null>;
20
+ saveSkill(skill: LearnedSkill): Promise<void>;
21
+ loadLearnedSkills(): Promise<LearnedSkill[]>;
22
+ matchSkill(message: string): LearnedSkill | null;
23
+ improveSkill(skill: LearnedSkill, conversation: Message[], provider: LLMProvider): Promise<void>;
24
+ getSkills(): LearnedSkill[];
25
+ }
26
+ export declare function skillToMarkdown(skill: LearnedSkill): string;
27
+ export declare function parseSkillMarkdown(content: string): LearnedSkill | null;
28
+ //# sourceMappingURL=auto-learn.d.ts.map