aiden-runtime 3.16.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 +661 -0
- package/README.md +465 -0
- package/config/devos.config.json +186 -0
- package/config/hardware.json +9 -0
- package/config/model-selection.json +7 -0
- package/config/setup-complete.json +20 -0
- package/dist/api/routes/computerUse.js +112 -0
- package/dist/api/server.js +6870 -0
- package/dist/bin/npx-init.js +71 -0
- package/dist/coordination/commandGate.js +115 -0
- package/dist/coordination/livePulse.js +127 -0
- package/dist/core/agentLoop.js +2718 -0
- package/dist/core/agentShield.js +231 -0
- package/dist/core/aidenIdentity.js +215 -0
- package/dist/core/aidenPersonality.js +166 -0
- package/dist/core/aidenSdk.js +374 -0
- package/dist/core/asyncTasks.js +82 -0
- package/dist/core/auditTrail.js +61 -0
- package/dist/core/auxiliaryClient.js +114 -0
- package/dist/core/bgLLM.js +108 -0
- package/dist/core/bm25.js +68 -0
- package/dist/core/callbackSystem.js +64 -0
- package/dist/core/channels/adapter.js +6 -0
- package/dist/core/channels/discord.js +173 -0
- package/dist/core/channels/email.js +253 -0
- package/dist/core/channels/imessage.js +164 -0
- package/dist/core/channels/manager.js +96 -0
- package/dist/core/channels/signal.js +140 -0
- package/dist/core/channels/slack.js +139 -0
- package/dist/core/channels/twilio.js +144 -0
- package/dist/core/channels/webhook.js +186 -0
- package/dist/core/channels/whatsapp.js +185 -0
- package/dist/core/clarifyBus.js +75 -0
- package/dist/core/codeInterpreter.js +82 -0
- package/dist/core/computerControl.js +439 -0
- package/dist/core/conversationMemory.js +334 -0
- package/dist/core/costTracker.js +221 -0
- package/dist/core/cronManager.js +217 -0
- package/dist/core/deepKB.js +77 -0
- package/dist/core/doctor.js +279 -0
- package/dist/core/dreamEngine.js +334 -0
- package/dist/core/entityGraph.js +169 -0
- package/dist/core/eventBus.js +16 -0
- package/dist/core/evolutionAnalyzer.js +153 -0
- package/dist/core/executionLoop.js +309 -0
- package/dist/core/executor.js +224 -0
- package/dist/core/failureAnalyzer.js +166 -0
- package/dist/core/fastPathExpansion.js +82 -0
- package/dist/core/faultEngine.js +106 -0
- package/dist/core/featureGates.js +70 -0
- package/dist/core/fileIngestion.js +113 -0
- package/dist/core/gateway.js +97 -0
- package/dist/core/goalTracker.js +75 -0
- package/dist/core/growthEngine.js +168 -0
- package/dist/core/hardwareDetector.js +98 -0
- package/dist/core/hooks.js +45 -0
- package/dist/core/httpKeepalive.js +46 -0
- package/dist/core/hybridSearch.js +101 -0
- package/dist/core/importers.js +164 -0
- package/dist/core/instinctSystem.js +223 -0
- package/dist/core/knowledgeBase.js +351 -0
- package/dist/core/learningMemory.js +121 -0
- package/dist/core/lessonsBrowser.js +125 -0
- package/dist/core/licenseManager.js +399 -0
- package/dist/core/logBuffer.js +85 -0
- package/dist/core/machineId.js +87 -0
- package/dist/core/mcpClient.js +442 -0
- package/dist/core/memoryDistiller.js +165 -0
- package/dist/core/memoryExtractor.js +212 -0
- package/dist/core/memoryIds.js +213 -0
- package/dist/core/memoryPreamble.js +113 -0
- package/dist/core/memoryQuery.js +136 -0
- package/dist/core/memoryRecall.js +140 -0
- package/dist/core/memoryStrategy.js +201 -0
- package/dist/core/messageValidator.js +85 -0
- package/dist/core/modelDiscovery.js +108 -0
- package/dist/core/modelRouter.js +118 -0
- package/dist/core/morningBriefing.js +203 -0
- package/dist/core/multiGoalValidator.js +51 -0
- package/dist/core/parallelExecutor.js +43 -0
- package/dist/core/passiveSkillObserver.js +204 -0
- package/dist/core/paths.js +57 -0
- package/dist/core/patternDetector.js +83 -0
- package/dist/core/planResponseRepair.js +64 -0
- package/dist/core/planTool.js +111 -0
- package/dist/core/playwrightBridge.js +356 -0
- package/dist/core/pluginSystem.js +121 -0
- package/dist/core/privateMode.js +85 -0
- package/dist/core/reactLoop.js +156 -0
- package/dist/core/recipeEngine.js +166 -0
- package/dist/core/responseCache.js +128 -0
- package/dist/core/runSandbox.js +132 -0
- package/dist/core/sandboxRunner.js +200 -0
- package/dist/core/scheduler.js +543 -0
- package/dist/core/secretScanner.js +49 -0
- package/dist/core/semanticMemory.js +223 -0
- package/dist/core/sessionMemory.js +259 -0
- package/dist/core/sessionRouter.js +91 -0
- package/dist/core/sessionSearch.js +163 -0
- package/dist/core/setupWizard.js +225 -0
- package/dist/core/skillImporter.js +303 -0
- package/dist/core/skillLibrary.js +144 -0
- package/dist/core/skillLoader.js +471 -0
- package/dist/core/skillTeacher.js +352 -0
- package/dist/core/skillValidator.js +210 -0
- package/dist/core/skillWriter.js +384 -0
- package/dist/core/slashAsTool.js +226 -0
- package/dist/core/spawnManager.js +197 -0
- package/dist/core/statusVerbs.js +43 -0
- package/dist/core/swarmManager.js +109 -0
- package/dist/core/taskQueue.js +119 -0
- package/dist/core/taskRecovery.js +128 -0
- package/dist/core/taskState.js +168 -0
- package/dist/core/telegramBot.js +152 -0
- package/dist/core/todoManager.js +70 -0
- package/dist/core/toolNameRepair.js +71 -0
- package/dist/core/toolRegistry.js +2730 -0
- package/dist/core/tools/calendarTool.js +98 -0
- package/dist/core/tools/companyFilingsTool.js +98 -0
- package/dist/core/tools/gmailTool.js +87 -0
- package/dist/core/tools/marketDataTool.js +135 -0
- package/dist/core/tools/socialResearchTool.js +121 -0
- package/dist/core/truthCheck.js +57 -0
- package/dist/core/updateChecker.js +74 -0
- package/dist/core/userCognitionProfile.js +238 -0
- package/dist/core/userProfile.js +341 -0
- package/dist/core/version.js +5 -0
- package/dist/core/visionAnalyze.js +161 -0
- package/dist/core/voice/audio.js +187 -0
- package/dist/core/voice/stt.js +226 -0
- package/dist/core/voice/tts.js +310 -0
- package/dist/core/voiceInput.js +118 -0
- package/dist/core/voiceOutput.js +130 -0
- package/dist/core/webSearch.js +326 -0
- package/dist/core/workflowTracker.js +72 -0
- package/dist/core/workspaceMemory.js +54 -0
- package/dist/core/youtubeTranscript.js +224 -0
- package/dist/integrations/computerUse/apiRegistry.js +113 -0
- package/dist/integrations/computerUse/screenAgent.js +203 -0
- package/dist/integrations/computerUse/visionLoop.js +296 -0
- package/dist/memory/memoryLayers.js +143 -0
- package/dist/providers/boa.js +93 -0
- package/dist/providers/cerebras.js +70 -0
- package/dist/providers/custom.js +89 -0
- package/dist/providers/gemini.js +82 -0
- package/dist/providers/groq.js +92 -0
- package/dist/providers/index.js +149 -0
- package/dist/providers/nvidia.js +70 -0
- package/dist/providers/ollama.js +99 -0
- package/dist/providers/openrouter.js +74 -0
- package/dist/providers/router.js +497 -0
- package/dist/providers/types.js +6 -0
- package/dist/security/browserVault.js +129 -0
- package/dist/security/dataGuard.js +89 -0
- package/dist/tools/eonetTool.js +72 -0
- package/dist/types/computerUse.js +2 -0
- package/dist/types/executor.js +2 -0
- package/dist-bundle/cli.js +357859 -0
- package/package.json +256 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// DevOS — Autonomous AI Execution System
|
|
4
|
+
// Copyright (c) 2026 Shiva Deore. All rights reserved.
|
|
5
|
+
// ============================================================
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.getSdkMethods = getSdkMethods;
|
|
41
|
+
exports.getSdkNamespaces = getSdkNamespaces;
|
|
42
|
+
exports.buildSdkRuntime = buildSdkRuntime;
|
|
43
|
+
exports.buildSdkSurface = buildSdkSurface;
|
|
44
|
+
// core/aidenSdk.ts — Generates the Aiden SDK surface injected into
|
|
45
|
+
// the run-sandbox. Each registered tool becomes a typed function on
|
|
46
|
+
// the `aiden` namespace object. The LLM writes code against this
|
|
47
|
+
// surface instead of raw tool names.
|
|
48
|
+
//
|
|
49
|
+
// Namespace mapping:
|
|
50
|
+
// aiden.web.* → web_search, deep_research, fetch_url, fetch_page, social_research
|
|
51
|
+
// aiden.file.* → file_read, file_write, file_list
|
|
52
|
+
// aiden.shell.* → shell_exec, run_python, run_node, run_powershell
|
|
53
|
+
// aiden.browser.* → open_browser, browser_click, browser_type, browser_extract, browser_screenshot
|
|
54
|
+
// aiden.screen.* → screenshot, mouse_move, mouse_click, keyboard_type, keyboard_press, screen_read
|
|
55
|
+
// aiden.memory.* → recall (memory_show), remember (via conversationMemory)
|
|
56
|
+
// aiden.lessons.* → check (lessons)
|
|
57
|
+
// aiden.system.* → notify, system_info, clipboard_read, clipboard_write
|
|
58
|
+
// aiden.git.* → git_status, git_commit, git_push
|
|
59
|
+
// aiden.data.* → get_market_data, get_company_info, get_stocks, get_briefing, get_calendar
|
|
60
|
+
// aiden.* → top-level: run_agent, respond
|
|
61
|
+
const toolRegistry_1 = require("./toolRegistry");
|
|
62
|
+
const mcpClient_1 = require("./mcpClient");
|
|
63
|
+
const TOOL_SDK_MAP = [
|
|
64
|
+
// web
|
|
65
|
+
{ toolName: 'web_search', namespace: 'web', method: 'search', description: 'Search the web', signature: '(query: string) => Promise<any[]>' },
|
|
66
|
+
{ toolName: 'deep_research', namespace: 'web', method: 'research', description: 'In-depth research on a topic', signature: '(topic: string) => Promise<string>' },
|
|
67
|
+
{ toolName: 'fetch_url', namespace: 'web', method: 'fetch', description: 'Fetch URL content', signature: '(url: string) => Promise<string>' },
|
|
68
|
+
{ toolName: 'fetch_page', namespace: 'web', method: 'page', description: 'Full page content extraction', signature: '(url: string) => Promise<string>' },
|
|
69
|
+
{ toolName: 'social_research', namespace: 'web', method: 'social', description: 'Social media research', signature: '(query: string) => Promise<any>' },
|
|
70
|
+
{ toolName: 'ingest_youtube', namespace: 'web', method: 'youtube', description: 'Get YouTube transcript', signature: '(url: string) => Promise<string>' },
|
|
71
|
+
// file
|
|
72
|
+
{ toolName: 'file_read', namespace: 'file', method: 'read', description: 'Read a file', signature: '(path: string) => Promise<string>' },
|
|
73
|
+
{ toolName: 'file_write', namespace: 'file', method: 'write', description: 'Write a file', signature: '(path: string, content: string) => Promise<void>' },
|
|
74
|
+
{ toolName: 'file_list', namespace: 'file', method: 'list', description: 'List directory contents', signature: '(dir: string) => Promise<string[]>' },
|
|
75
|
+
// shell
|
|
76
|
+
{ toolName: 'shell_exec', namespace: 'shell', method: 'exec', description: 'Run a shell command', signature: '(command: string) => Promise<{stdout:string,stderr:string,exitCode:number}>' },
|
|
77
|
+
{ toolName: 'run_python', namespace: 'shell', method: 'python', description: 'Execute Python code', signature: '(script: string) => Promise<string>' },
|
|
78
|
+
{ toolName: 'run_node', namespace: 'shell', method: 'node', description: 'Execute Node.js code', signature: '(script: string) => Promise<string>' },
|
|
79
|
+
{ toolName: 'run_powershell', namespace: 'shell', method: 'powershell', description: 'Execute PowerShell', signature: '(script: string) => Promise<string>' },
|
|
80
|
+
{ toolName: 'cmd', namespace: 'shell', method: 'cmd', description: 'Run cmd.exe command', signature: '(command: string, options?: any) => Promise<{stdout:string,stderr:string,exitCode:number}>' },
|
|
81
|
+
{ toolName: 'ps', namespace: 'shell', method: 'ps', description: 'Run PowerShell directly', signature: '(command: string, options?: any) => Promise<{stdout:string,stderr:string,exitCode:number}>' },
|
|
82
|
+
{ toolName: 'wsl', namespace: 'shell', method: 'wsl', description: 'Run bash command in WSL', signature: '(command: string, options?: any) => Promise<{stdout:string,stderr:string,exitCode:number}>' },
|
|
83
|
+
// browser
|
|
84
|
+
{ toolName: 'open_browser', namespace: 'browser', method: 'open', description: 'Open a URL in the browser', signature: '(url: string) => Promise<void>' },
|
|
85
|
+
{ toolName: 'browser_click', namespace: 'browser', method: 'click', description: 'Click an element', signature: '(selector: string) => Promise<void>' },
|
|
86
|
+
{ toolName: 'browser_type', namespace: 'browser', method: 'type', description: 'Type text into an element', signature: '(selector: string, text: string) => Promise<void>' },
|
|
87
|
+
{ toolName: 'browser_extract', namespace: 'browser', method: 'extract', description: 'Extract content from page', signature: '(selector?: string) => Promise<string>' },
|
|
88
|
+
{ toolName: 'browser_screenshot', namespace: 'browser', method: 'screenshot', description: 'Take a browser screenshot', signature: '() => Promise<string>' },
|
|
89
|
+
// screen
|
|
90
|
+
{ toolName: 'screenshot', namespace: 'screen', method: 'capture', description: 'Capture desktop screenshot', signature: '() => Promise<string>' },
|
|
91
|
+
{ toolName: 'mouse_move', namespace: 'screen', method: 'mouseMov', description: 'Move mouse to coordinates', signature: '(x: number, y: number) => Promise<void>' },
|
|
92
|
+
{ toolName: 'mouse_click', namespace: 'screen', method: 'mouseClick', description: 'Click at coordinates', signature: '(x: number, y: number) => Promise<void>' },
|
|
93
|
+
{ toolName: 'keyboard_type', namespace: 'screen', method: 'type', description: 'Type text via keyboard', signature: '(text: string) => Promise<void>' },
|
|
94
|
+
{ toolName: 'keyboard_press', namespace: 'screen', method: 'press', description: 'Press a key combination', signature: '(key: string) => Promise<void>' },
|
|
95
|
+
{ toolName: 'screen_read', namespace: 'screen', method: 'read', description: 'Read text from screen', signature: '() => Promise<string>' },
|
|
96
|
+
{ toolName: 'vision_loop', namespace: 'screen', method: 'vision', description: 'Agentic vision control loop', signature: '(goal: string, maxSteps?: number) => Promise<string>' },
|
|
97
|
+
// memory
|
|
98
|
+
{ toolName: 'memory_show', namespace: 'memory', method: 'recall', description: 'Recall from memory', signature: '(query: string) => Promise<string>' },
|
|
99
|
+
// system
|
|
100
|
+
{ toolName: 'notify', namespace: 'system', method: 'notify', description: 'Send a system notification', signature: '(message: string, title?: string) => Promise<void>' },
|
|
101
|
+
{ toolName: 'system_info', namespace: 'system', method: 'info', description: 'Get system information', signature: '() => Promise<any>' },
|
|
102
|
+
{ toolName: 'clipboard_read', namespace: 'system', method: 'clipboardRead', description: 'Read clipboard content', signature: '() => Promise<string>' },
|
|
103
|
+
{ toolName: 'clipboard_write', namespace: 'system', method: 'clipboardWrite', description: 'Write to clipboard', signature: '(text: string) => Promise<void>' },
|
|
104
|
+
{ toolName: 'wait', namespace: 'system', method: 'wait', description: 'Wait for N milliseconds', signature: '(ms: number) => Promise<void>' },
|
|
105
|
+
// git
|
|
106
|
+
{ toolName: 'git_status', namespace: 'git', method: 'status', description: 'Git status and recent commits', signature: '(path?: string) => Promise<string>' },
|
|
107
|
+
{ toolName: 'git_commit', namespace: 'git', method: 'commit', description: 'Stage all and commit', signature: '(message: string) => Promise<string>' },
|
|
108
|
+
{ toolName: 'git_push', namespace: 'git', method: 'push', description: 'Push to remote', signature: '(remote?: string, branch?: string) => Promise<string>' },
|
|
109
|
+
// data
|
|
110
|
+
{ toolName: 'get_market_data', namespace: 'data', method: 'market', description: 'Real-time stock/market data', signature: '(symbol: string) => Promise<any>' },
|
|
111
|
+
{ toolName: 'get_company_info', namespace: 'data', method: 'company', description: 'Company profile and financials', signature: '(symbol: string) => Promise<any>' },
|
|
112
|
+
{ toolName: 'get_stocks', namespace: 'data', method: 'stocks', description: 'Market movers (gainers/losers)', signature: '(market: string, type: string) => Promise<any[]>' },
|
|
113
|
+
{ toolName: 'get_briefing', namespace: 'data', method: 'briefing', description: 'Daily news and market briefing', signature: '() => Promise<string>' },
|
|
114
|
+
{ toolName: 'get_calendar', namespace: 'data', method: 'calendar', description: 'Calendar events', signature: '(daysAhead?: number) => Promise<any[]>' },
|
|
115
|
+
{ toolName: 'read_email', namespace: 'data', method: 'email', description: 'Read recent emails', signature: '(limit?: number) => Promise<any[]>' },
|
|
116
|
+
// voice
|
|
117
|
+
{ toolName: 'voice_speak', namespace: 'voice', method: 'speak', description: 'Speak text via TTS provider chain', signature: '(text: string, opts?: {voice?:string,provider?:string,rate?:number,volume?:number}) => Promise<{provider:string,durationMs:number}>' },
|
|
118
|
+
{ toolName: 'voice_transcribe', namespace: 'voice', method: 'transcribe', description: 'Transcribe audio file to text', signature: '(audioFilePath: string, language?: string) => Promise<{text:string,provider:string,durationMs:number}>' },
|
|
119
|
+
{ toolName: 'voice_clone', namespace: 'voice', method: 'clone', description: 'Clone a voice and speak text', signature: '(text: string, referenceAudioPath: string) => Promise<{provider:string,durationMs:number}>' },
|
|
120
|
+
{ toolName: 'voice_design', namespace: 'voice', method: 'design', description: 'Design a voice from description', signature: '(text: string, voiceDescription: string) => Promise<{provider:string,durationMs:number}>' },
|
|
121
|
+
{ toolName: 'voice_record', namespace: 'voice', method: 'record', description: 'Record audio from microphone', signature: '(durationSeconds?: number, outputPath?: string) => Promise<string>' },
|
|
122
|
+
{ toolName: 'voice_play', namespace: 'voice', method: 'play', description: 'Play an audio file', signature: '(audioSource: string) => Promise<void>' },
|
|
123
|
+
// todo
|
|
124
|
+
{ toolName: 'todo', namespace: 'todo', method: 'add', description: 'Add a todo item', signature: '(text: string, priority?: string) => Promise<string>' },
|
|
125
|
+
{ toolName: 'todo', namespace: 'todo', method: 'complete', description: 'Mark a todo item done', signature: '(id: string) => Promise<string>' },
|
|
126
|
+
{ toolName: 'todo', namespace: 'todo', method: 'remove', description: 'Remove a todo item', signature: '(id: string) => Promise<string>' },
|
|
127
|
+
{ toolName: 'todo', namespace: 'todo', method: 'list', description: 'List todo items', signature: '(filter?: string) => Promise<string>' },
|
|
128
|
+
{ toolName: 'todo', namespace: 'todo', method: 'clear', description: 'Clear all todos', signature: '() => Promise<string>' },
|
|
129
|
+
// cron
|
|
130
|
+
{ toolName: 'cronjob', namespace: 'cron', method: 'create', description: 'Create a scheduled job', signature: '(description: string, schedule: string, action: string) => Promise<string>' },
|
|
131
|
+
{ toolName: 'cronjob', namespace: 'cron', method: 'list', description: 'List all cron jobs', signature: '() => Promise<string>' },
|
|
132
|
+
{ toolName: 'cronjob', namespace: 'cron', method: 'pause', description: 'Pause a cron job', signature: '(id: string) => Promise<string>' },
|
|
133
|
+
{ toolName: 'cronjob', namespace: 'cron', method: 'resume', description: 'Resume a paused cron job', signature: '(id: string) => Promise<string>' },
|
|
134
|
+
{ toolName: 'cronjob', namespace: 'cron', method: 'delete', description: 'Delete a cron job', signature: '(id: string) => Promise<string>' },
|
|
135
|
+
{ toolName: 'cronjob', namespace: 'cron', method: 'trigger', description: 'Immediately run a cron job', signature: '(id: string) => Promise<string>' },
|
|
136
|
+
// vision
|
|
137
|
+
{ toolName: 'vision_analyze', namespace: 'vision', method: 'analyze', description: 'Analyze an image with AI', signature: '(imageSource: string, prompt?: string) => Promise<string>' },
|
|
138
|
+
// top-level
|
|
139
|
+
{ toolName: 'run_agent', namespace: '', method: 'runAgent', description: 'Spawn a sub-agent', signature: '(task: string) => Promise<string>' },
|
|
140
|
+
];
|
|
141
|
+
/** Returns all SDK method definitions. */
|
|
142
|
+
function getSdkMethods() {
|
|
143
|
+
return TOOL_SDK_MAP.map(e => ({
|
|
144
|
+
namespace: e.namespace,
|
|
145
|
+
method: e.method,
|
|
146
|
+
toolName: e.toolName,
|
|
147
|
+
description: e.description,
|
|
148
|
+
signature: e.signature,
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
/** Returns namespaces present in the SDK (sorted). */
|
|
152
|
+
function getSdkNamespaces() {
|
|
153
|
+
const ns = new Set(TOOL_SDK_MAP.filter(e => e.namespace).map(e => e.namespace));
|
|
154
|
+
return Array.from(ns).sort();
|
|
155
|
+
}
|
|
156
|
+
// ── SDK surface builder ───────────────────────────────────────────────────────
|
|
157
|
+
/**
|
|
158
|
+
* Builds the runtime SDK object that is injected into the run sandbox.
|
|
159
|
+
* Returns a plain object tree matching `aiden.web.search(...)` etc.
|
|
160
|
+
*
|
|
161
|
+
* Each method:
|
|
162
|
+
* 1. Validates the tool exists in TOOLS
|
|
163
|
+
* 2. Calls executeTool with the appropriate input shape
|
|
164
|
+
* 3. Returns the output value (parsed JSON if possible)
|
|
165
|
+
*/
|
|
166
|
+
function buildSdkRuntime(onToolCall) {
|
|
167
|
+
/** Wraps a tool name into a callable that tracks usage. */
|
|
168
|
+
function makeMethod(toolName, inputMapper) {
|
|
169
|
+
return async (...args) => {
|
|
170
|
+
const input = inputMapper(...args);
|
|
171
|
+
onToolCall(toolName, input);
|
|
172
|
+
const result = await (0, toolRegistry_1.executeTool)(toolName, input, 0, 30000);
|
|
173
|
+
if (!result.success)
|
|
174
|
+
throw new Error(`${toolName} failed: ${result.error ?? result.output}`);
|
|
175
|
+
// Try to parse JSON output for structured data
|
|
176
|
+
try {
|
|
177
|
+
return JSON.parse(result.output);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return result.output;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const sdk = {
|
|
185
|
+
web: {
|
|
186
|
+
search: makeMethod('web_search', (q) => ({ query: q })),
|
|
187
|
+
research: makeMethod('deep_research', (t) => ({ topic: t })),
|
|
188
|
+
fetch: makeMethod('fetch_url', (u) => ({ url: u })),
|
|
189
|
+
page: makeMethod('fetch_page', (u) => ({ url: u })),
|
|
190
|
+
social: makeMethod('social_research', (q) => ({ query: q })),
|
|
191
|
+
youtube: makeMethod('ingest_youtube', (u) => ({ url: u })),
|
|
192
|
+
},
|
|
193
|
+
file: {
|
|
194
|
+
read: makeMethod('file_read', (p) => ({ path: p })),
|
|
195
|
+
write: makeMethod('file_write', (p, c) => ({ path: p, content: c })),
|
|
196
|
+
list: makeMethod('file_list', (d) => ({ path: d })),
|
|
197
|
+
},
|
|
198
|
+
shell: {
|
|
199
|
+
exec: makeMethod('shell_exec', (cmd) => ({ command: cmd })),
|
|
200
|
+
python: makeMethod('run_python', (s) => ({ script: s })),
|
|
201
|
+
node: makeMethod('run_node', (s) => ({ script: s })),
|
|
202
|
+
powershell: makeMethod('run_powershell', (s) => ({ script: s })),
|
|
203
|
+
cmd: makeMethod('cmd', (cmd, opts) => ({ command: cmd, ...opts })),
|
|
204
|
+
ps: makeMethod('ps', (cmd, opts) => ({ command: cmd, ...opts })),
|
|
205
|
+
wsl: makeMethod('wsl', (cmd, opts) => ({ command: cmd, ...opts })),
|
|
206
|
+
},
|
|
207
|
+
browser: {
|
|
208
|
+
open: makeMethod('open_browser', (u) => ({ url: u })),
|
|
209
|
+
click: makeMethod('browser_click', (sel) => ({ selector: sel })),
|
|
210
|
+
type: makeMethod('browser_type', (sel, t) => ({ selector: sel, text: t })),
|
|
211
|
+
extract: makeMethod('browser_extract', (sel) => ({ selector: sel ?? '' })),
|
|
212
|
+
screenshot: makeMethod('browser_screenshot', () => ({})),
|
|
213
|
+
},
|
|
214
|
+
screen: {
|
|
215
|
+
capture: makeMethod('screenshot', () => ({})),
|
|
216
|
+
mouseMov: makeMethod('mouse_move', (x, y) => ({ x, y })),
|
|
217
|
+
mouseClick: makeMethod('mouse_click', (x, y) => ({ x, y })),
|
|
218
|
+
type: makeMethod('keyboard_type', (text) => ({ text })),
|
|
219
|
+
press: makeMethod('keyboard_press', (key) => ({ key })),
|
|
220
|
+
read: makeMethod('screen_read', () => ({})),
|
|
221
|
+
vision: makeMethod('vision_loop', (goal, maxSteps = 10) => ({ goal, max_steps: maxSteps })),
|
|
222
|
+
},
|
|
223
|
+
memory: {
|
|
224
|
+
recall: makeMethod('memory_show', (q) => ({ query: q })),
|
|
225
|
+
remember: makeMethod('memory_show', (fact) => ({ query: fact, mode: 'store' })),
|
|
226
|
+
},
|
|
227
|
+
lessons: {
|
|
228
|
+
check: makeMethod('lessons', (q) => ({ query: q ?? '' })),
|
|
229
|
+
},
|
|
230
|
+
system: {
|
|
231
|
+
notify: makeMethod('notify', (msg, title) => ({ message: msg, title: title ?? 'Aiden' })),
|
|
232
|
+
info: makeMethod('system_info', () => ({})),
|
|
233
|
+
clipboardRead: makeMethod('clipboard_read', () => ({})),
|
|
234
|
+
clipboardWrite: makeMethod('clipboard_write', (text) => ({ text })),
|
|
235
|
+
wait: makeMethod('wait', (ms) => ({ ms })),
|
|
236
|
+
},
|
|
237
|
+
git: {
|
|
238
|
+
status: makeMethod('git_status', (p) => ({ path: p ?? process.cwd() })),
|
|
239
|
+
commit: makeMethod('git_commit', (msg) => ({ message: msg })),
|
|
240
|
+
push: makeMethod('git_push', (remote = 'origin', branch = 'master') => ({ remote, branch })),
|
|
241
|
+
},
|
|
242
|
+
data: {
|
|
243
|
+
market: makeMethod('get_market_data', (sym) => ({ symbol: sym })),
|
|
244
|
+
company: makeMethod('get_company_info', (sym) => ({ symbol: sym })),
|
|
245
|
+
stocks: makeMethod('get_stocks', (mkt, type) => ({ market: mkt, type })),
|
|
246
|
+
briefing: makeMethod('get_briefing', () => ({})),
|
|
247
|
+
calendar: makeMethod('get_calendar', (daysAhead = 7) => ({ days_ahead: daysAhead })),
|
|
248
|
+
email: makeMethod('read_email', (limit = 10) => ({ limit })),
|
|
249
|
+
},
|
|
250
|
+
// voice
|
|
251
|
+
voice: {
|
|
252
|
+
speak: async (text, opts = {}) => {
|
|
253
|
+
onToolCall('voice_speak', { text, ...opts });
|
|
254
|
+
const { synthesize } = await Promise.resolve().then(() => __importStar(require('./voice/tts')));
|
|
255
|
+
return synthesize({ text, voice: opts.voice, provider: opts.provider, rate: opts.rate, volume: opts.volume });
|
|
256
|
+
},
|
|
257
|
+
transcribe: async (audioFilePath, language) => {
|
|
258
|
+
onToolCall('voice_transcribe', { audioFilePath, language });
|
|
259
|
+
const { transcribe } = await Promise.resolve().then(() => __importStar(require('./voice/stt')));
|
|
260
|
+
return transcribe({ audioFilePath, language });
|
|
261
|
+
},
|
|
262
|
+
clone: async (text, referenceAudioPath) => {
|
|
263
|
+
onToolCall('voice_clone', { text, referenceAudioPath });
|
|
264
|
+
const { synthesize } = await Promise.resolve().then(() => __importStar(require('./voice/tts')));
|
|
265
|
+
return synthesize({ text, referenceAudioPath, provider: 'voxcpm' });
|
|
266
|
+
},
|
|
267
|
+
design: async (text, voiceDescription) => {
|
|
268
|
+
onToolCall('voice_design', { text, voiceDescription });
|
|
269
|
+
const { synthesize } = await Promise.resolve().then(() => __importStar(require('./voice/tts')));
|
|
270
|
+
return synthesize({ text, voiceDesignPrompt: voiceDescription, provider: 'voxcpm' });
|
|
271
|
+
},
|
|
272
|
+
reset: async () => {
|
|
273
|
+
// No-op in SDK context — state reset is a CLI concern
|
|
274
|
+
return { provider: 'none', durationMs: 0, note: 'voice reset (use /voice reset in CLI)' };
|
|
275
|
+
},
|
|
276
|
+
providers: async () => {
|
|
277
|
+
const { getTtsProviders } = await Promise.resolve().then(() => __importStar(require('./voice/tts')));
|
|
278
|
+
return getTtsProviders();
|
|
279
|
+
},
|
|
280
|
+
record: async (durationSeconds, outputPath) => {
|
|
281
|
+
onToolCall('voice_record', { durationSeconds, outputPath });
|
|
282
|
+
const { recordAudio } = await Promise.resolve().then(() => __importStar(require('./voice/audio')));
|
|
283
|
+
return recordAudio(durationSeconds, outputPath);
|
|
284
|
+
},
|
|
285
|
+
play: async (audioSource) => {
|
|
286
|
+
onToolCall('voice_play', { audioSource });
|
|
287
|
+
const { playAudio } = await Promise.resolve().then(() => __importStar(require('./voice/audio')));
|
|
288
|
+
return playAudio(audioSource);
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
// MCP namespace — direct access to connected MCP servers
|
|
292
|
+
mcp: {
|
|
293
|
+
/** List names of all connected MCP servers. */
|
|
294
|
+
list: () => (0, mcpClient_1.listMcpServers)(),
|
|
295
|
+
/** List all MCP tools (across all servers). */
|
|
296
|
+
tools: () => (0, mcpClient_1.listMcpTools)(),
|
|
297
|
+
/** Call an MCP tool by 'server:toolName' and args object. */
|
|
298
|
+
call: (toolName, args = {}) => {
|
|
299
|
+
onToolCall(`mcp:${toolName}`, args);
|
|
300
|
+
return (0, mcpClient_1.callMcpTool)(toolName, args);
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
// todo
|
|
304
|
+
todo: {
|
|
305
|
+
add: makeMethod('todo', (text, priority) => ({ op: 'add', text, priority: priority ?? 'normal' })),
|
|
306
|
+
complete: makeMethod('todo', (id) => ({ op: 'complete', id })),
|
|
307
|
+
remove: makeMethod('todo', (id) => ({ op: 'remove', id })),
|
|
308
|
+
list: makeMethod('todo', (filter) => ({ op: 'list', filter: filter ?? 'all' })),
|
|
309
|
+
clear: makeMethod('todo', () => ({ op: 'clear' })),
|
|
310
|
+
},
|
|
311
|
+
// cron
|
|
312
|
+
cron: {
|
|
313
|
+
create: makeMethod('cronjob', (description, schedule, action) => ({ op: 'create', description, schedule, action })),
|
|
314
|
+
list: makeMethod('cronjob', () => ({ op: 'list' })),
|
|
315
|
+
pause: makeMethod('cronjob', (id) => ({ op: 'pause', id })),
|
|
316
|
+
resume: makeMethod('cronjob', (id) => ({ op: 'resume', id })),
|
|
317
|
+
delete: makeMethod('cronjob', (id) => ({ op: 'delete', id })),
|
|
318
|
+
trigger: makeMethod('cronjob', (id) => ({ op: 'trigger', id })),
|
|
319
|
+
},
|
|
320
|
+
// vision
|
|
321
|
+
vision: {
|
|
322
|
+
analyze: makeMethod('vision_analyze', (imageSource, prompt) => ({ image: imageSource, prompt })),
|
|
323
|
+
},
|
|
324
|
+
// Top-level clarify — ask the user a question mid-task
|
|
325
|
+
clarify: async (question, options, allowFreeText = true) => {
|
|
326
|
+
onToolCall('clarify', { question, options, allow_free_text: allowFreeText });
|
|
327
|
+
const result = await (0, toolRegistry_1.executeTool)('clarify', { question, options, allow_free_text: allowFreeText }, 0, 300000);
|
|
328
|
+
if (!result.success)
|
|
329
|
+
throw new Error(`clarify failed: ${result.error ?? result.output}`);
|
|
330
|
+
return result.output;
|
|
331
|
+
},
|
|
332
|
+
// Top-level convenience
|
|
333
|
+
runAgent: makeMethod('run_agent', (task) => ({ task })),
|
|
334
|
+
};
|
|
335
|
+
return sdk;
|
|
336
|
+
}
|
|
337
|
+
// ── Prose SDK surface (for /run help display) ─────────────────────────────────
|
|
338
|
+
/**
|
|
339
|
+
* Generates a human-readable string describing the full SDK surface.
|
|
340
|
+
* Used by /run help and the LLM system prompt hint.
|
|
341
|
+
*/
|
|
342
|
+
function buildSdkSurface() {
|
|
343
|
+
const grouped = {};
|
|
344
|
+
for (const m of TOOL_SDK_MAP) {
|
|
345
|
+
const key = m.namespace || '_top';
|
|
346
|
+
if (!grouped[key])
|
|
347
|
+
grouped[key] = [];
|
|
348
|
+
grouped[key].push(m);
|
|
349
|
+
}
|
|
350
|
+
const lines = [
|
|
351
|
+
'// Aiden SDK — auto-generated from tool registry',
|
|
352
|
+
'// Use `aiden.<namespace>.<method>(...)` in /run scripts',
|
|
353
|
+
'',
|
|
354
|
+
];
|
|
355
|
+
const sortedNs = Object.keys(grouped).sort((a, b) => {
|
|
356
|
+
if (a === '_top')
|
|
357
|
+
return 1;
|
|
358
|
+
if (b === '_top')
|
|
359
|
+
return -1;
|
|
360
|
+
return a.localeCompare(b);
|
|
361
|
+
});
|
|
362
|
+
for (const ns of sortedNs) {
|
|
363
|
+
const label = ns === '_top' ? 'aiden (top-level)' : `aiden.${ns}`;
|
|
364
|
+
lines.push(`// ── ${label} ${'─'.repeat(Math.max(0, 50 - label.length - 6))}`);
|
|
365
|
+
for (const m of grouped[ns]) {
|
|
366
|
+
const call = ns === '_top'
|
|
367
|
+
? `aiden.${m.method}${m.signature.startsWith('(') ? m.signature.split('=>')[0].trim() : '(...)'}`
|
|
368
|
+
: `aiden.${ns}.${m.method}${m.signature.startsWith('(') ? m.signature.split('=>')[0].trim() : '(...)'}`;
|
|
369
|
+
lines.push(` ${call.padEnd(60)} // ${m.description}`);
|
|
370
|
+
}
|
|
371
|
+
lines.push('');
|
|
372
|
+
}
|
|
373
|
+
return lines.join('\n');
|
|
374
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// DevOS — Autonomous AI Execution System
|
|
4
|
+
// Copyright (c) 2026 Shiva Deore. All rights reserved.
|
|
5
|
+
// ============================================================
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.asyncTasks = void 0;
|
|
8
|
+
// core/asyncTasks.ts — Background task execution with completion notifications.
|
|
9
|
+
//
|
|
10
|
+
// Usage:
|
|
11
|
+
// const task = asyncTasks.spawn('research top AI frameworks 2026')
|
|
12
|
+
// // returns immediately; task runs in background
|
|
13
|
+
// // emits callbacks.async_complete when done → forwarded to all open SSE clients
|
|
14
|
+
const agentLoop_1 = require("./agentLoop");
|
|
15
|
+
const router_1 = require("../providers/router");
|
|
16
|
+
const conversationMemory_1 = require("./conversationMemory");
|
|
17
|
+
const callbackSystem_1 = require("./callbackSystem");
|
|
18
|
+
// ── Manager ───────────────────────────────────────────────────────────────────
|
|
19
|
+
class AsyncTaskManager {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.tasks = new Map();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Spawn a new background task. Returns the task record immediately;
|
|
25
|
+
* execution runs asynchronously. A `callbacks.async_complete` event
|
|
26
|
+
* fires when it finishes (success or failure).
|
|
27
|
+
*/
|
|
28
|
+
spawn(prompt) {
|
|
29
|
+
const id = `async_${Date.now()}`;
|
|
30
|
+
const task = { id, prompt, status: 'running', startedAt: Date.now() };
|
|
31
|
+
this.tasks.set(id, task);
|
|
32
|
+
// Fire-and-forget — top-level error captured here so it never becomes an
|
|
33
|
+
// unhandled rejection; execute() also updates the task internally on throw.
|
|
34
|
+
this.execute(task).catch(() => { });
|
|
35
|
+
return task;
|
|
36
|
+
}
|
|
37
|
+
async execute(task) {
|
|
38
|
+
const start = task.startedAt;
|
|
39
|
+
try {
|
|
40
|
+
const planner = (0, router_1.getModelForTask)('planner');
|
|
41
|
+
const responder = (0, router_1.getModelForTask)('responder');
|
|
42
|
+
const memCtx = conversationMemory_1.conversationMemory.buildContext();
|
|
43
|
+
// ── Step 1: Plan ────────────────────────────────────────────
|
|
44
|
+
const plan = await (0, agentLoop_1.planWithLLM)(task.prompt, [], planner.apiKey, planner.model, planner.providerName, memCtx);
|
|
45
|
+
// ── Step 2: Execute ─────────────────────────────────────────
|
|
46
|
+
const results = plan.requires_execution && plan.plan.length > 0
|
|
47
|
+
? await (0, agentLoop_1.executePlan)(plan, (_step, _result) => { })
|
|
48
|
+
: [];
|
|
49
|
+
// ── Step 3: Respond ─────────────────────────────────────────
|
|
50
|
+
const tokens = [];
|
|
51
|
+
await (0, agentLoop_1.respondWithResults)(task.prompt, plan, results, [], 'User', responder.apiKey, responder.model, responder.providerName, (t) => tokens.push(t));
|
|
52
|
+
task.result = tokens.join('').trim();
|
|
53
|
+
task.status = 'complete';
|
|
54
|
+
task.completedAt = Date.now();
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
task.status = 'failed';
|
|
58
|
+
task.error = err?.message || String(err);
|
|
59
|
+
task.completedAt = Date.now();
|
|
60
|
+
// re-throw so the spawn() .catch() fires for logging
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
// Notify all open SSE clients regardless of success/failure
|
|
65
|
+
await callbackSystem_1.callbacks.emit('async_complete', 'async', {
|
|
66
|
+
taskId: task.id,
|
|
67
|
+
status: task.status,
|
|
68
|
+
elapsed: Date.now() - start,
|
|
69
|
+
preview: (task.result || task.error || '').slice(0, 200),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Return all tasks (running, complete, failed). */
|
|
74
|
+
list() {
|
|
75
|
+
return Array.from(this.tasks.values()).sort((a, b) => b.startedAt - a.startedAt);
|
|
76
|
+
}
|
|
77
|
+
/** Return a single task by ID, or undefined if not found. */
|
|
78
|
+
get(id) {
|
|
79
|
+
return this.tasks.get(id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.asyncTasks = new AsyncTaskManager();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.auditTrail = exports.AuditTrail = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const AUDIT_PATH = path_1.default.join(process.cwd(), 'workspace', 'audit', 'audit.jsonl');
|
|
10
|
+
class AuditTrail {
|
|
11
|
+
constructor() {
|
|
12
|
+
fs_1.default.mkdirSync(path_1.default.dirname(AUDIT_PATH), { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
record(entry) {
|
|
15
|
+
const full = {
|
|
16
|
+
id: `a_${Date.now()}_${Math.random().toString(36).slice(2, 5)}`,
|
|
17
|
+
ts: Date.now(),
|
|
18
|
+
...entry,
|
|
19
|
+
};
|
|
20
|
+
fs_1.default.appendFileSync(AUDIT_PATH, JSON.stringify(full) + '\n');
|
|
21
|
+
}
|
|
22
|
+
getToday() {
|
|
23
|
+
if (!fs_1.default.existsSync(AUDIT_PATH))
|
|
24
|
+
return [];
|
|
25
|
+
const today = new Date().toDateString();
|
|
26
|
+
return fs_1.default.readFileSync(AUDIT_PATH, 'utf-8')
|
|
27
|
+
.trim().split('\n').filter(Boolean)
|
|
28
|
+
.map(l => { try {
|
|
29
|
+
return JSON.parse(l);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
} })
|
|
34
|
+
.filter(e => e && new Date(e.ts).toDateString() === today);
|
|
35
|
+
}
|
|
36
|
+
formatSummary(entries) {
|
|
37
|
+
if (entries.length === 0)
|
|
38
|
+
return 'No activity today.';
|
|
39
|
+
const success = entries.filter(e => e.success).length;
|
|
40
|
+
const failed = entries.length - success;
|
|
41
|
+
const tools = {};
|
|
42
|
+
for (const e of entries) {
|
|
43
|
+
if (e.tool)
|
|
44
|
+
tools[e.tool] = (tools[e.tool] || 0) + 1;
|
|
45
|
+
}
|
|
46
|
+
const topTools = Object.entries(tools)
|
|
47
|
+
.sort((a, b) => b[1] - a[1]).slice(0, 5)
|
|
48
|
+
.map(([t, c]) => ` ${t}: ${c}x`).join('\n');
|
|
49
|
+
const failures = entries.filter(e => !e.success).slice(-3)
|
|
50
|
+
.map(e => ` - ${e.tool || e.action}: ${e.error || 'unknown error'}`).join('\n');
|
|
51
|
+
return `DevOS Activity — ${new Date().toLocaleDateString()}
|
|
52
|
+
Actions: ${entries.length} total | ${success} succeeded | ${failed} failed
|
|
53
|
+
Avg duration: ${Math.round(entries.reduce((s, e) => s + e.durationMs, 0) / entries.length)}ms
|
|
54
|
+
|
|
55
|
+
Top tools:
|
|
56
|
+
${topTools || ' none'}
|
|
57
|
+
${failures ? `\nRecent failures:\n${failures}` : ''}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AuditTrail = AuditTrail;
|
|
61
|
+
exports.auditTrail = new AuditTrail();
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// DevOS — Autonomous AI Execution System
|
|
4
|
+
// Copyright (c) 2026 Shiva Deore. All rights reserved.
|
|
5
|
+
// ============================================================
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.auxiliaryClient = void 0;
|
|
8
|
+
// core/auxiliaryClient.ts — Cheap LLM client for side tasks.
|
|
9
|
+
// Side tasks (memory extraction, dream consolidation, session
|
|
10
|
+
// reflection, compression summaries) don't need the main model.
|
|
11
|
+
// Routes to the executor tier (Cerebras → Groq → Nvidia → Ollama)
|
|
12
|
+
// with lower max_tokens and shorter timeout than the main loop.
|
|
13
|
+
// Matches the agentLoop.ts direct-fetch pattern exactly.
|
|
14
|
+
// Falls back to callBgLLM if the executor route fails.
|
|
15
|
+
const router_1 = require("../providers/router");
|
|
16
|
+
const bgLLM_1 = require("./bgLLM");
|
|
17
|
+
const costTracker_1 = require("./costTracker");
|
|
18
|
+
// ── OpenAI-compat endpoints (mirrors agentLoop.ts) ────────────
|
|
19
|
+
const AUX_ENDPOINTS = {
|
|
20
|
+
groq: 'https://api.groq.com/openai/v1/chat/completions',
|
|
21
|
+
cerebras: 'https://api.cerebras.ai/v1/chat/completions',
|
|
22
|
+
openrouter: 'https://openrouter.ai/api/v1/chat/completions',
|
|
23
|
+
nvidia: 'https://integrate.api.nvidia.com/v1/chat/completions',
|
|
24
|
+
github: 'https://models.inference.ai.azure.com/chat/completions',
|
|
25
|
+
boa: 'https://api.boa.ai/v1/chat/completions',
|
|
26
|
+
};
|
|
27
|
+
const DEFAULT_AUX_CONFIG = {
|
|
28
|
+
preferLocal: true,
|
|
29
|
+
maxTokens: 500,
|
|
30
|
+
timeout: 10000,
|
|
31
|
+
fallbackToMain: true,
|
|
32
|
+
};
|
|
33
|
+
// ── AuxiliaryClient ───────────────────────────────────────────
|
|
34
|
+
class AuxiliaryClient {
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.config = { ...DEFAULT_AUX_CONFIG, ...config };
|
|
37
|
+
}
|
|
38
|
+
// ── Public: single-turn completion for a side task ─────────
|
|
39
|
+
async complete(prompt, options) {
|
|
40
|
+
const task = options?.task || 'general';
|
|
41
|
+
const maxTokens = options?.maxTokens || this.config.maxTokens;
|
|
42
|
+
// Executor tier: Cerebras → Groq → Nvidia → Ollama (cheapest available)
|
|
43
|
+
const { apiKey, model, providerName, apiName } = (0, router_1.getModelForTask)('executor');
|
|
44
|
+
console.log(`[Aux] ${task} — routing to ${apiName} (${providerName}/${model})`);
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.callProviderDirect(providerName, apiKey, model, prompt, maxTokens);
|
|
47
|
+
if (result) {
|
|
48
|
+
console.log(`[Aux] Side task "${task}" routed to ${apiName} ` +
|
|
49
|
+
`instead of main model — estimated savings: ~$0.001`);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.log(`[Aux] ${apiName} failed (${e.message}) — falling back`);
|
|
55
|
+
}
|
|
56
|
+
// Fallback: bgLLM (Cerebras → Ollama — safe, no global state)
|
|
57
|
+
if (this.config.fallbackToMain) {
|
|
58
|
+
console.log(`[Aux] Falling back to bgLLM for ${task}`);
|
|
59
|
+
return (0, bgLLM_1.callBgLLM)(prompt, `aux_${task}`);
|
|
60
|
+
}
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
// ── Direct fetch — matches agentLoop.ts pattern ────────────
|
|
64
|
+
// Lower max_tokens + shorter timeout vs. main loop.
|
|
65
|
+
// Does NOT touch currentAbortController (safe for side tasks).
|
|
66
|
+
async callProviderDirect(providerName, apiKey, model, prompt, maxTokens) {
|
|
67
|
+
const messages = [
|
|
68
|
+
{ role: 'system', content: 'You are a concise assistant. Respond briefly and accurately.' },
|
|
69
|
+
{ role: 'user', content: prompt },
|
|
70
|
+
];
|
|
71
|
+
// ── Ollama ───────────────────────────────────────────────
|
|
72
|
+
if (providerName === 'ollama') {
|
|
73
|
+
const r = await fetch('http://localhost:11434/api/chat', {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: { 'Content-Type': 'application/json' },
|
|
76
|
+
body: JSON.stringify({ model, stream: false, messages }),
|
|
77
|
+
signal: AbortSignal.timeout(this.config.timeout),
|
|
78
|
+
});
|
|
79
|
+
if (!r.ok)
|
|
80
|
+
throw new Error(`ollama ${r.status}`);
|
|
81
|
+
const d = await r.json();
|
|
82
|
+
try {
|
|
83
|
+
costTracker_1.costTracker.trackUsage('ollama', model, d?.prompt_eval_count ?? 0, d?.eval_count ?? 0, undefined, true);
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
return d?.message?.content || '';
|
|
87
|
+
}
|
|
88
|
+
// ── OpenAI-compatible (Cerebras, Groq, Nvidia, OpenRouter) ─
|
|
89
|
+
const url = AUX_ENDPOINTS[providerName];
|
|
90
|
+
if (!url || !apiKey)
|
|
91
|
+
return '';
|
|
92
|
+
const r = await fetch(url, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: {
|
|
95
|
+
'Content-Type': 'application/json',
|
|
96
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
97
|
+
},
|
|
98
|
+
body: JSON.stringify({ model, messages, stream: false, max_tokens: maxTokens }),
|
|
99
|
+
signal: AbortSignal.timeout(this.config.timeout),
|
|
100
|
+
});
|
|
101
|
+
if (r.status === 429)
|
|
102
|
+
throw new Error(`rate limited (429)`);
|
|
103
|
+
if (!r.ok)
|
|
104
|
+
throw new Error(`${providerName} ${r.status}`);
|
|
105
|
+
const d = await r.json();
|
|
106
|
+
try {
|
|
107
|
+
costTracker_1.costTracker.trackUsage(providerName, model, d?.usage?.prompt_tokens ?? 0, d?.usage?.completion_tokens ?? 0, undefined, true);
|
|
108
|
+
}
|
|
109
|
+
catch { }
|
|
110
|
+
return d?.choices?.[0]?.message?.content || '';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ── Singleton ──────────────────────────────────────────────────
|
|
114
|
+
exports.auxiliaryClient = new AuxiliaryClient();
|