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.
Files changed (159) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +465 -0
  3. package/config/devos.config.json +186 -0
  4. package/config/hardware.json +9 -0
  5. package/config/model-selection.json +7 -0
  6. package/config/setup-complete.json +20 -0
  7. package/dist/api/routes/computerUse.js +112 -0
  8. package/dist/api/server.js +6870 -0
  9. package/dist/bin/npx-init.js +71 -0
  10. package/dist/coordination/commandGate.js +115 -0
  11. package/dist/coordination/livePulse.js +127 -0
  12. package/dist/core/agentLoop.js +2718 -0
  13. package/dist/core/agentShield.js +231 -0
  14. package/dist/core/aidenIdentity.js +215 -0
  15. package/dist/core/aidenPersonality.js +166 -0
  16. package/dist/core/aidenSdk.js +374 -0
  17. package/dist/core/asyncTasks.js +82 -0
  18. package/dist/core/auditTrail.js +61 -0
  19. package/dist/core/auxiliaryClient.js +114 -0
  20. package/dist/core/bgLLM.js +108 -0
  21. package/dist/core/bm25.js +68 -0
  22. package/dist/core/callbackSystem.js +64 -0
  23. package/dist/core/channels/adapter.js +6 -0
  24. package/dist/core/channels/discord.js +173 -0
  25. package/dist/core/channels/email.js +253 -0
  26. package/dist/core/channels/imessage.js +164 -0
  27. package/dist/core/channels/manager.js +96 -0
  28. package/dist/core/channels/signal.js +140 -0
  29. package/dist/core/channels/slack.js +139 -0
  30. package/dist/core/channels/twilio.js +144 -0
  31. package/dist/core/channels/webhook.js +186 -0
  32. package/dist/core/channels/whatsapp.js +185 -0
  33. package/dist/core/clarifyBus.js +75 -0
  34. package/dist/core/codeInterpreter.js +82 -0
  35. package/dist/core/computerControl.js +439 -0
  36. package/dist/core/conversationMemory.js +334 -0
  37. package/dist/core/costTracker.js +221 -0
  38. package/dist/core/cronManager.js +217 -0
  39. package/dist/core/deepKB.js +77 -0
  40. package/dist/core/doctor.js +279 -0
  41. package/dist/core/dreamEngine.js +334 -0
  42. package/dist/core/entityGraph.js +169 -0
  43. package/dist/core/eventBus.js +16 -0
  44. package/dist/core/evolutionAnalyzer.js +153 -0
  45. package/dist/core/executionLoop.js +309 -0
  46. package/dist/core/executor.js +224 -0
  47. package/dist/core/failureAnalyzer.js +166 -0
  48. package/dist/core/fastPathExpansion.js +82 -0
  49. package/dist/core/faultEngine.js +106 -0
  50. package/dist/core/featureGates.js +70 -0
  51. package/dist/core/fileIngestion.js +113 -0
  52. package/dist/core/gateway.js +97 -0
  53. package/dist/core/goalTracker.js +75 -0
  54. package/dist/core/growthEngine.js +168 -0
  55. package/dist/core/hardwareDetector.js +98 -0
  56. package/dist/core/hooks.js +45 -0
  57. package/dist/core/httpKeepalive.js +46 -0
  58. package/dist/core/hybridSearch.js +101 -0
  59. package/dist/core/importers.js +164 -0
  60. package/dist/core/instinctSystem.js +223 -0
  61. package/dist/core/knowledgeBase.js +351 -0
  62. package/dist/core/learningMemory.js +121 -0
  63. package/dist/core/lessonsBrowser.js +125 -0
  64. package/dist/core/licenseManager.js +399 -0
  65. package/dist/core/logBuffer.js +85 -0
  66. package/dist/core/machineId.js +87 -0
  67. package/dist/core/mcpClient.js +442 -0
  68. package/dist/core/memoryDistiller.js +165 -0
  69. package/dist/core/memoryExtractor.js +212 -0
  70. package/dist/core/memoryIds.js +213 -0
  71. package/dist/core/memoryPreamble.js +113 -0
  72. package/dist/core/memoryQuery.js +136 -0
  73. package/dist/core/memoryRecall.js +140 -0
  74. package/dist/core/memoryStrategy.js +201 -0
  75. package/dist/core/messageValidator.js +85 -0
  76. package/dist/core/modelDiscovery.js +108 -0
  77. package/dist/core/modelRouter.js +118 -0
  78. package/dist/core/morningBriefing.js +203 -0
  79. package/dist/core/multiGoalValidator.js +51 -0
  80. package/dist/core/parallelExecutor.js +43 -0
  81. package/dist/core/passiveSkillObserver.js +204 -0
  82. package/dist/core/paths.js +57 -0
  83. package/dist/core/patternDetector.js +83 -0
  84. package/dist/core/planResponseRepair.js +64 -0
  85. package/dist/core/planTool.js +111 -0
  86. package/dist/core/playwrightBridge.js +356 -0
  87. package/dist/core/pluginSystem.js +121 -0
  88. package/dist/core/privateMode.js +85 -0
  89. package/dist/core/reactLoop.js +156 -0
  90. package/dist/core/recipeEngine.js +166 -0
  91. package/dist/core/responseCache.js +128 -0
  92. package/dist/core/runSandbox.js +132 -0
  93. package/dist/core/sandboxRunner.js +200 -0
  94. package/dist/core/scheduler.js +543 -0
  95. package/dist/core/secretScanner.js +49 -0
  96. package/dist/core/semanticMemory.js +223 -0
  97. package/dist/core/sessionMemory.js +259 -0
  98. package/dist/core/sessionRouter.js +91 -0
  99. package/dist/core/sessionSearch.js +163 -0
  100. package/dist/core/setupWizard.js +225 -0
  101. package/dist/core/skillImporter.js +303 -0
  102. package/dist/core/skillLibrary.js +144 -0
  103. package/dist/core/skillLoader.js +471 -0
  104. package/dist/core/skillTeacher.js +352 -0
  105. package/dist/core/skillValidator.js +210 -0
  106. package/dist/core/skillWriter.js +384 -0
  107. package/dist/core/slashAsTool.js +226 -0
  108. package/dist/core/spawnManager.js +197 -0
  109. package/dist/core/statusVerbs.js +43 -0
  110. package/dist/core/swarmManager.js +109 -0
  111. package/dist/core/taskQueue.js +119 -0
  112. package/dist/core/taskRecovery.js +128 -0
  113. package/dist/core/taskState.js +168 -0
  114. package/dist/core/telegramBot.js +152 -0
  115. package/dist/core/todoManager.js +70 -0
  116. package/dist/core/toolNameRepair.js +71 -0
  117. package/dist/core/toolRegistry.js +2730 -0
  118. package/dist/core/tools/calendarTool.js +98 -0
  119. package/dist/core/tools/companyFilingsTool.js +98 -0
  120. package/dist/core/tools/gmailTool.js +87 -0
  121. package/dist/core/tools/marketDataTool.js +135 -0
  122. package/dist/core/tools/socialResearchTool.js +121 -0
  123. package/dist/core/truthCheck.js +57 -0
  124. package/dist/core/updateChecker.js +74 -0
  125. package/dist/core/userCognitionProfile.js +238 -0
  126. package/dist/core/userProfile.js +341 -0
  127. package/dist/core/version.js +5 -0
  128. package/dist/core/visionAnalyze.js +161 -0
  129. package/dist/core/voice/audio.js +187 -0
  130. package/dist/core/voice/stt.js +226 -0
  131. package/dist/core/voice/tts.js +310 -0
  132. package/dist/core/voiceInput.js +118 -0
  133. package/dist/core/voiceOutput.js +130 -0
  134. package/dist/core/webSearch.js +326 -0
  135. package/dist/core/workflowTracker.js +72 -0
  136. package/dist/core/workspaceMemory.js +54 -0
  137. package/dist/core/youtubeTranscript.js +224 -0
  138. package/dist/integrations/computerUse/apiRegistry.js +113 -0
  139. package/dist/integrations/computerUse/screenAgent.js +203 -0
  140. package/dist/integrations/computerUse/visionLoop.js +296 -0
  141. package/dist/memory/memoryLayers.js +143 -0
  142. package/dist/providers/boa.js +93 -0
  143. package/dist/providers/cerebras.js +70 -0
  144. package/dist/providers/custom.js +89 -0
  145. package/dist/providers/gemini.js +82 -0
  146. package/dist/providers/groq.js +92 -0
  147. package/dist/providers/index.js +149 -0
  148. package/dist/providers/nvidia.js +70 -0
  149. package/dist/providers/ollama.js +99 -0
  150. package/dist/providers/openrouter.js +74 -0
  151. package/dist/providers/router.js +497 -0
  152. package/dist/providers/types.js +6 -0
  153. package/dist/security/browserVault.js +129 -0
  154. package/dist/security/dataGuard.js +89 -0
  155. package/dist/tools/eonetTool.js +72 -0
  156. package/dist/types/computerUse.js +2 -0
  157. package/dist/types/executor.js +2 -0
  158. package/dist-bundle/cli.js +357859 -0
  159. package/package.json +256 -0
@@ -0,0 +1,143 @@
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.memoryLayers = void 0;
41
+ // memory/memoryLayers.ts — 3-tier memory: HOT (RAM) → WARM (SQLite) → COLD (JSON)
42
+ // Stub for sandbox; full implementation on user machine (committed in Sprint 18).
43
+ const fs = __importStar(require("fs"));
44
+ const path = __importStar(require("path"));
45
+ // ── Persistence paths ─────────────────────────────────────────
46
+ const WORKSPACE_MEM = path.join(process.cwd(), 'workspace', 'memory');
47
+ const COLD_JSON_PATH = path.join(WORKSPACE_MEM, 'cold.json');
48
+ function _makeId() {
49
+ return `ml_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
50
+ }
51
+ function _loadCold() {
52
+ try {
53
+ if (!fs.existsSync(COLD_JSON_PATH))
54
+ return [];
55
+ return JSON.parse(fs.readFileSync(COLD_JSON_PATH, 'utf-8'));
56
+ }
57
+ catch {
58
+ return [];
59
+ }
60
+ }
61
+ function _saveCold(entries) {
62
+ try {
63
+ fs.mkdirSync(path.dirname(COLD_JSON_PATH), { recursive: true });
64
+ fs.writeFileSync(COLD_JSON_PATH, JSON.stringify(entries.slice(-2000), null, 2), 'utf-8');
65
+ }
66
+ catch { /* non-fatal */ }
67
+ }
68
+ // ── MemoryLayers ──────────────────────────────────────────────
69
+ class MemoryLayers {
70
+ constructor() {
71
+ this.hot = new Map();
72
+ }
73
+ /** Write a new entry. Always lands in HOT first. */
74
+ write(content, tags) {
75
+ const now = Date.now();
76
+ const entry = {
77
+ id: _makeId(),
78
+ content: content.slice(0, 2000),
79
+ tier: 'hot',
80
+ timestamp: now,
81
+ tags,
82
+ accessCount: 0,
83
+ lastAccessed: now,
84
+ };
85
+ this.hot.set(entry.id, entry);
86
+ // Overflow: flush oldest to cold.json when HOT exceeds 20
87
+ if (this.hot.size > 20) {
88
+ const oldest = Array.from(this.hot.values())
89
+ .sort((a, b) => a.timestamp - b.timestamp)
90
+ .slice(0, 5);
91
+ const cold = _loadCold();
92
+ for (const e of oldest) {
93
+ cold.push({ ...e, tier: 'cold' });
94
+ this.hot.delete(e.id);
95
+ }
96
+ _saveCold(cold);
97
+ }
98
+ }
99
+ /** Simple keyword search across HOT then COLD. */
100
+ async read(query, maxTokens = 1000) {
101
+ const tokens = query.toLowerCase().split(/\s+/).filter(t => t.length > 2);
102
+ const charBudget = maxTokens * 4;
103
+ const score = (e) => {
104
+ const hay = (e.content + ' ' + e.tags.join(' ')).toLowerCase();
105
+ return tokens.reduce((s, t) => s + (hay.includes(t) ? 1 : 0), 0);
106
+ };
107
+ const hotResults = Array.from(this.hot.values())
108
+ .sort((a, b) => score(b) - score(a));
109
+ let used = 0;
110
+ const result = [];
111
+ for (const e of hotResults) {
112
+ used += e.content.length;
113
+ if (used > charBudget)
114
+ break;
115
+ result.push(e);
116
+ }
117
+ if (result.length < 3) {
118
+ const cold = _loadCold()
119
+ .sort((a, b) => score(b) - score(a))
120
+ .slice(0, 10);
121
+ for (const e of cold) {
122
+ used += e.content.length;
123
+ if (used > charBudget)
124
+ break;
125
+ result.push(e);
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ async getStats() {
131
+ return { hot: this.hot.size, warm: 0, cold: _loadCold().length };
132
+ }
133
+ async getContextForPrompt(maxTokens = 500) {
134
+ const entries = Array.from(this.hot.values())
135
+ .sort((a, b) => b.lastAccessed - a.lastAccessed)
136
+ .slice(0, 10);
137
+ if (entries.length === 0)
138
+ return '';
139
+ const lines = entries.map(e => `• [${e.tags.join(',')}] ${e.content.slice(0, 200)}`);
140
+ return `=== MEMORY CONTEXT ===\n${lines.join('\n')}\n=== END MEMORY ===`;
141
+ }
142
+ }
143
+ exports.memoryLayers = new MemoryLayers();
@@ -0,0 +1,93 @@
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.createBOAProvider = createBOAProvider;
8
+ const BOA_BASE = 'https://api.bayofassets.com/v1/chat/completions';
9
+ function createBOAProvider(apiKey) {
10
+ return {
11
+ name: 'boa',
12
+ async generateWithTools(messages, model, tools) {
13
+ const res = await fetch(BOA_BASE, {
14
+ method: 'POST',
15
+ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
16
+ body: JSON.stringify({
17
+ model,
18
+ messages,
19
+ tools: tools.map(t => ({ type: 'function', function: t })),
20
+ tool_choice: 'auto',
21
+ stream: false,
22
+ }),
23
+ });
24
+ const data = await res.json();
25
+ if (!res.ok)
26
+ throw new Error(`${res.status}: ${JSON.stringify(data)}`);
27
+ const message = data.choices?.[0]?.message;
28
+ const toolCalls = (message?.tool_calls || []).map((tc) => ({
29
+ name: tc.function.name,
30
+ arguments: JSON.parse(tc.function.arguments || '{}'),
31
+ }));
32
+ return { content: message?.content || '', toolCalls };
33
+ },
34
+ async generate(messages, model) {
35
+ const res = await fetch(BOA_BASE, {
36
+ method: 'POST',
37
+ headers: {
38
+ 'Content-Type': 'application/json',
39
+ 'Authorization': `Bearer ${apiKey}`,
40
+ },
41
+ body: JSON.stringify({ model, messages, stream: false }),
42
+ });
43
+ const data = await res.json();
44
+ return data?.choices?.[0]?.message?.content || '';
45
+ },
46
+ async generateStream(messages, model, onToken) {
47
+ try {
48
+ const res = await fetch(BOA_BASE, {
49
+ method: 'POST',
50
+ headers: {
51
+ 'Content-Type': 'application/json',
52
+ 'Authorization': `Bearer ${apiKey}`,
53
+ },
54
+ body: JSON.stringify({ model, messages, stream: true }),
55
+ });
56
+ if (!res.ok) {
57
+ const err = await res.text();
58
+ throw new Error(`${res.status}: ${err}`);
59
+ }
60
+ if (!res.body)
61
+ return;
62
+ const reader = res.body.getReader();
63
+ const decoder = new TextDecoder();
64
+ let buf = '';
65
+ while (true) {
66
+ const { done, value } = await reader.read();
67
+ if (done)
68
+ break;
69
+ buf += decoder.decode(value, { stream: true });
70
+ const lines = buf.split('\n');
71
+ buf = lines.pop() ?? '';
72
+ for (const line of lines) {
73
+ if (!line.startsWith('data: '))
74
+ continue;
75
+ const raw = line.replace('data: ', '').trim();
76
+ if (raw === '[DONE]')
77
+ return;
78
+ try {
79
+ const parsed = JSON.parse(raw);
80
+ const token = parsed?.choices?.[0]?.delta?.content;
81
+ if (token)
82
+ onToken(token);
83
+ }
84
+ catch { }
85
+ }
86
+ }
87
+ }
88
+ catch (err) {
89
+ throw err;
90
+ }
91
+ },
92
+ };
93
+ }
@@ -0,0 +1,70 @@
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.createCerebrasProvider = createCerebrasProvider;
8
+ function createCerebrasProvider(apiKey) {
9
+ return {
10
+ name: 'cerebras',
11
+ async generate(messages, model) {
12
+ const res = await fetch('https://api.cerebras.ai/v1/chat/completions', {
13
+ method: 'POST',
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ 'Authorization': `Bearer ${apiKey}`,
17
+ },
18
+ body: JSON.stringify({ model: model || 'llama3.1-8b', messages, stream: false }),
19
+ });
20
+ const data = await res.json();
21
+ return data?.choices?.[0]?.message?.content || '';
22
+ },
23
+ async generateStream(messages, model, onToken) {
24
+ try {
25
+ const res = await fetch('https://api.cerebras.ai/v1/chat/completions', {
26
+ method: 'POST',
27
+ headers: {
28
+ 'Content-Type': 'application/json',
29
+ 'Authorization': `Bearer ${apiKey}`,
30
+ },
31
+ body: JSON.stringify({ model: model || 'llama3.1-8b', messages, stream: true }),
32
+ });
33
+ if (!res.ok) {
34
+ const err = await res.text();
35
+ throw new Error(`${res.status}: ${err}`);
36
+ }
37
+ if (!res.body)
38
+ return;
39
+ const reader = res.body.getReader();
40
+ const decoder = new TextDecoder();
41
+ let buf = '';
42
+ while (true) {
43
+ const { done, value } = await reader.read();
44
+ if (done)
45
+ break;
46
+ buf += decoder.decode(value, { stream: true });
47
+ const lines = buf.split('\n');
48
+ buf = lines.pop() ?? '';
49
+ for (const line of lines) {
50
+ if (!line.startsWith('data: '))
51
+ continue;
52
+ const raw = line.replace('data: ', '').trim();
53
+ if (raw === '[DONE]')
54
+ return;
55
+ try {
56
+ const parsed = JSON.parse(raw);
57
+ const token = parsed?.choices?.[0]?.delta?.content;
58
+ if (token)
59
+ onToken(token);
60
+ }
61
+ catch { }
62
+ }
63
+ }
64
+ }
65
+ catch (err) {
66
+ throw err;
67
+ }
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,89 @@
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.createCustomProvider = createCustomProvider;
8
+ function createCustomProvider(baseUrl, apiKey, name) {
9
+ const headers = () => ({
10
+ 'Content-Type': 'application/json',
11
+ ...(apiKey ? { 'Authorization': `Bearer ${apiKey}` } : {}),
12
+ });
13
+ return {
14
+ name,
15
+ async generateWithTools(messages, model, tools) {
16
+ const res = await fetch(baseUrl, {
17
+ method: 'POST',
18
+ headers: headers(),
19
+ body: JSON.stringify({
20
+ model,
21
+ messages,
22
+ tools: tools.map(t => ({ type: 'function', function: t })),
23
+ tool_choice: 'auto',
24
+ stream: false,
25
+ }),
26
+ });
27
+ const data = await res.json();
28
+ if (!res.ok)
29
+ throw new Error(`${res.status}: ${JSON.stringify(data)}`);
30
+ const message = data.choices?.[0]?.message;
31
+ const toolCalls = (message?.tool_calls || []).map((tc) => ({
32
+ name: tc.function.name,
33
+ arguments: JSON.parse(tc.function.arguments || '{}'),
34
+ }));
35
+ return { content: message?.content || '', toolCalls };
36
+ },
37
+ async generate(messages, model) {
38
+ const res = await fetch(baseUrl, {
39
+ method: 'POST',
40
+ headers: headers(),
41
+ body: JSON.stringify({ model, messages, stream: false }),
42
+ });
43
+ if (!res.ok) {
44
+ const err = await res.text();
45
+ throw new Error(`${res.status}: ${err}`);
46
+ }
47
+ const data = await res.json();
48
+ return data?.choices?.[0]?.message?.content || '';
49
+ },
50
+ async generateStream(messages, model, onToken) {
51
+ const res = await fetch(baseUrl, {
52
+ method: 'POST',
53
+ headers: headers(),
54
+ body: JSON.stringify({ model, messages, stream: true }),
55
+ });
56
+ if (!res.ok) {
57
+ const err = await res.text();
58
+ throw new Error(`${res.status}: ${err}`);
59
+ }
60
+ if (!res.body)
61
+ return;
62
+ const reader = res.body.getReader();
63
+ const decoder = new TextDecoder();
64
+ let buf = '';
65
+ while (true) {
66
+ const { done, value } = await reader.read();
67
+ if (done)
68
+ break;
69
+ buf += decoder.decode(value, { stream: true });
70
+ const lines = buf.split('\n');
71
+ buf = lines.pop() ?? '';
72
+ for (const line of lines) {
73
+ if (!line.startsWith('data: '))
74
+ continue;
75
+ const raw = line.replace('data: ', '').trim();
76
+ if (raw === '[DONE]')
77
+ return;
78
+ try {
79
+ const parsed = JSON.parse(raw);
80
+ const token = parsed?.choices?.[0]?.delta?.content;
81
+ if (token)
82
+ onToken(token);
83
+ }
84
+ catch { /* skip malformed SSE chunks */ }
85
+ }
86
+ }
87
+ },
88
+ };
89
+ }
@@ -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.createGeminiProvider = createGeminiProvider;
8
+ function createGeminiProvider(apiKey) {
9
+ return {
10
+ name: 'gemini',
11
+ async generateWithTools(messages, model, tools) {
12
+ const geminiModel = model || 'gemini-1.5-flash';
13
+ const contents = messages
14
+ .filter(m => m.role !== 'system')
15
+ .map(m => ({
16
+ role: m.role === 'assistant' ? 'model' : 'user',
17
+ parts: [{ text: m.content }],
18
+ }));
19
+ const system = messages.find(m => m.role === 'system')?.content;
20
+ const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${geminiModel}:generateContent?key=${apiKey}`, {
21
+ method: 'POST',
22
+ headers: { 'Content-Type': 'application/json' },
23
+ body: JSON.stringify({
24
+ contents,
25
+ systemInstruction: system ? { parts: [{ text: system }] } : undefined,
26
+ tools: [{
27
+ functionDeclarations: tools.map(t => ({
28
+ name: t.name,
29
+ description: t.description,
30
+ parameters: t.parameters,
31
+ })),
32
+ }],
33
+ }),
34
+ });
35
+ const data = await res.json();
36
+ if (!res.ok)
37
+ throw new Error(`${res.status}: ${JSON.stringify(data)}`);
38
+ const candidate = data.candidates?.[0]?.content;
39
+ const toolCalls = [];
40
+ let content = '';
41
+ for (const part of candidate?.parts || []) {
42
+ if (part.text)
43
+ content += part.text;
44
+ if (part.functionCall)
45
+ toolCalls.push({
46
+ name: part.functionCall.name,
47
+ arguments: part.functionCall.args || {},
48
+ });
49
+ }
50
+ return { content, toolCalls };
51
+ },
52
+ async generate(messages, model) {
53
+ const geminiModel = model || 'gemini-1.5-flash';
54
+ const contents = messages
55
+ .filter(m => m.role !== 'system')
56
+ .map(m => ({
57
+ role: m.role === 'assistant' ? 'model' : 'user',
58
+ parts: [{ text: m.content }],
59
+ }));
60
+ const system = messages.find(m => m.role === 'system')?.content;
61
+ const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${geminiModel}:generateContent?key=${apiKey}`, {
62
+ method: 'POST',
63
+ headers: { 'Content-Type': 'application/json' },
64
+ body: JSON.stringify({
65
+ contents,
66
+ systemInstruction: system ? { parts: [{ text: system }] } : undefined,
67
+ }),
68
+ });
69
+ if (!res.ok) {
70
+ const err = await res.text();
71
+ throw new Error(`${res.status}: ${err}`);
72
+ }
73
+ const data = await res.json();
74
+ return data?.candidates?.[0]?.content?.parts?.[0]?.text || '';
75
+ },
76
+ async generateStream(messages, model, onToken) {
77
+ // Gemini streaming — generate full response and emit as single token
78
+ const result = await this.generate(messages, model);
79
+ onToken(result);
80
+ },
81
+ };
82
+ }
@@ -0,0 +1,92 @@
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.createGroqProvider = createGroqProvider;
8
+ function createGroqProvider(apiKey) {
9
+ return {
10
+ name: 'groq',
11
+ async generateWithTools(messages, model, tools) {
12
+ const res = await fetch('https://api.groq.com/openai/v1/chat/completions', {
13
+ method: 'POST',
14
+ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
15
+ body: JSON.stringify({
16
+ model,
17
+ messages,
18
+ tools: tools.map(t => ({ type: 'function', function: t })),
19
+ tool_choice: 'auto',
20
+ stream: false,
21
+ }),
22
+ });
23
+ const data = await res.json();
24
+ if (!res.ok)
25
+ throw new Error(`${res.status}: ${JSON.stringify(data)}`);
26
+ const message = data.choices?.[0]?.message;
27
+ const toolCalls = (message?.tool_calls || []).map((tc) => ({
28
+ name: tc.function.name,
29
+ arguments: JSON.parse(tc.function.arguments || '{}'),
30
+ }));
31
+ return { content: message?.content || '', toolCalls };
32
+ },
33
+ async generate(messages, model) {
34
+ const res = await fetch('https://api.groq.com/openai/v1/chat/completions', {
35
+ method: 'POST',
36
+ headers: {
37
+ 'Content-Type': 'application/json',
38
+ 'Authorization': `Bearer ${apiKey}`,
39
+ },
40
+ body: JSON.stringify({ model, messages, stream: false }),
41
+ });
42
+ const data = await res.json();
43
+ return data?.choices?.[0]?.message?.content || '';
44
+ },
45
+ async generateStream(messages, model, onToken) {
46
+ try {
47
+ const res = await fetch('https://api.groq.com/openai/v1/chat/completions', {
48
+ method: 'POST',
49
+ headers: {
50
+ 'Content-Type': 'application/json',
51
+ 'Authorization': `Bearer ${apiKey}`,
52
+ },
53
+ body: JSON.stringify({ model, messages, stream: true }),
54
+ });
55
+ if (!res.ok) {
56
+ const err = await res.text();
57
+ throw new Error(`${res.status}: ${err}`);
58
+ }
59
+ if (!res.body)
60
+ return;
61
+ const reader = res.body.getReader();
62
+ const decoder = new TextDecoder();
63
+ let buf = '';
64
+ while (true) {
65
+ const { done, value } = await reader.read();
66
+ if (done)
67
+ break;
68
+ buf += decoder.decode(value, { stream: true });
69
+ const lines = buf.split('\n');
70
+ buf = lines.pop() ?? '';
71
+ for (const line of lines) {
72
+ if (!line.startsWith('data: '))
73
+ continue;
74
+ const raw = line.replace('data: ', '').trim();
75
+ if (raw === '[DONE]')
76
+ return;
77
+ try {
78
+ const parsed = JSON.parse(raw);
79
+ const token = parsed?.choices?.[0]?.delta?.content;
80
+ if (token)
81
+ onToken(token);
82
+ }
83
+ catch { }
84
+ }
85
+ }
86
+ }
87
+ catch (err) {
88
+ throw err;
89
+ }
90
+ },
91
+ };
92
+ }