nyxora 1.0.2 → 1.0.4
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/package.json +10 -1
- package/.env.example +0 -17
- package/dashboard/eslint.config.js +0 -22
- package/dashboard/index.html +0 -13
- package/dashboard/package-lock.json +0 -2737
- package/dashboard/package.json +0 -31
- package/dashboard/public/favicon.svg +0 -1
- package/dashboard/public/icons.svg +0 -24
- package/dashboard/src/App.css +0 -184
- package/dashboard/src/App.tsx +0 -485
- package/dashboard/src/BalanceWidget.tsx +0 -65
- package/dashboard/src/MarketWidget.tsx +0 -73
- package/dashboard/src/Memory.tsx +0 -109
- package/dashboard/src/Overview.tsx +0 -156
- package/dashboard/src/Settings.tsx +0 -213
- package/dashboard/src/Skills.tsx +0 -97
- package/dashboard/src/SwapWidget.tsx +0 -130
- package/dashboard/src/TransactionWidget.tsx +0 -86
- package/dashboard/src/assets/hero.png +0 -0
- package/dashboard/src/assets/react.svg +0 -1
- package/dashboard/src/assets/vite.svg +0 -1
- package/dashboard/src/index.css +0 -508
- package/dashboard/src/main.tsx +0 -10
- package/dashboard/src/overview.css +0 -304
- package/dashboard/tsconfig.app.json +0 -25
- package/dashboard/tsconfig.json +0 -7
- package/dashboard/tsconfig.node.json +0 -24
- package/dashboard/vite.config.ts +0 -7
- package/src/agent/reasoning.d.ts +0 -2
- package/src/agent/reasoning.d.ts.map +0 -1
- package/src/agent/reasoning.js +0 -97
- package/src/agent/reasoning.js.map +0 -1
- package/src/agent/reasoning.ts +0 -232
- package/src/config/parser.d.ts +0 -17
- package/src/config/parser.d.ts.map +0 -1
- package/src/config/parser.js +0 -26
- package/src/config/parser.js.map +0 -1
- package/src/config/parser.ts +0 -47
- package/src/config/paths.ts +0 -33
- package/src/gateway/cli.d.ts +0 -3
- package/src/gateway/cli.d.ts.map +0 -1
- package/src/gateway/cli.js +0 -80
- package/src/gateway/cli.js.map +0 -1
- package/src/gateway/cli.ts +0 -69
- package/src/gateway/server.ts +0 -135
- package/src/gateway/telegram.ts +0 -47
- package/src/gateway/test.ts +0 -16
- package/src/gateway/tracker.ts +0 -70
- package/src/memory/logger.d.ts +0 -18
- package/src/memory/logger.d.ts.map +0 -1
- package/src/memory/logger.js +0 -51
- package/src/memory/logger.js.map +0 -1
- package/src/memory/logger.ts +0 -57
- package/src/web3/config.d.ts +0 -793
- package/src/web3/config.d.ts.map +0 -1
- package/src/web3/config.js +0 -81
- package/src/web3/config.js.map +0 -1
- package/src/web3/config.ts +0 -51
- package/src/web3/skills/getBalance.d.ts +0 -25
- package/src/web3/skills/getBalance.d.ts.map +0 -1
- package/src/web3/skills/getBalance.js +0 -46
- package/src/web3/skills/getBalance.js.map +0 -1
- package/src/web3/skills/getBalance.ts +0 -48
- package/src/web3/skills/getPrice.ts +0 -43
- package/src/web3/skills/swapToken.ts +0 -69
- package/src/web3/skills/transfer.ts +0 -47
- package/tsconfig.json +0 -13
package/src/agent/reasoning.ts
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import * as dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { OpenAI } from 'openai';
|
|
7
|
-
import { loadConfig } from '../config/parser';
|
|
8
|
-
import { Logger } from '../memory/logger';
|
|
9
|
-
import { Tracker } from '../gateway/tracker';
|
|
10
|
-
import { getBalanceToolDefinition, getBalance } from '../web3/skills/getBalance';
|
|
11
|
-
import { transferToolDefinition, transferNative } from '../web3/skills/transfer';
|
|
12
|
-
import { getPriceToolDefinition, getPrice } from '../web3/skills/getPrice';
|
|
13
|
-
import { swapTokenToolDefinition, swapToken } from '../web3/skills/swapToken';
|
|
14
|
-
import { getPath } from '../config/paths';
|
|
15
|
-
|
|
16
|
-
export const logger = new Logger();
|
|
17
|
-
|
|
18
|
-
let currentKeyIndex = 0;
|
|
19
|
-
|
|
20
|
-
function getOpenAI(): OpenAI {
|
|
21
|
-
const config = loadConfig();
|
|
22
|
-
|
|
23
|
-
if (config.llm.provider === 'ollama') {
|
|
24
|
-
return new OpenAI({
|
|
25
|
-
baseURL: process.env.OLLAMA_BASE_URL ? `${process.env.OLLAMA_BASE_URL}/v1` : 'http://localhost:11434/v1',
|
|
26
|
-
apiKey: 'ollama', // API key is not required for local Ollama
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Get API key from config (UI) or fallback to .env
|
|
31
|
-
let apiKey = '';
|
|
32
|
-
|
|
33
|
-
if (config.llm.api_keys && config.llm.api_keys.length > 0) {
|
|
34
|
-
// Filter out empty keys
|
|
35
|
-
const keys = config.llm.api_keys.filter(k => k.trim() !== '');
|
|
36
|
-
if (keys.length > 0) {
|
|
37
|
-
currentKeyIndex = currentKeyIndex % keys.length;
|
|
38
|
-
apiKey = keys[currentKeyIndex];
|
|
39
|
-
console.log(`[LLM] Using rotated API Key (${currentKeyIndex + 1}/${keys.length}): ${apiKey.substring(0, 4)}...`);
|
|
40
|
-
currentKeyIndex++; // Increment for next request
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Fallbacks if no valid keys found in config
|
|
45
|
-
if (!apiKey) {
|
|
46
|
-
if (config.llm.provider === 'gemini') {
|
|
47
|
-
apiKey = process.env.GEMINI_API_KEY || '';
|
|
48
|
-
} else {
|
|
49
|
-
apiKey = process.env.OPENAI_API_KEY || '';
|
|
50
|
-
}
|
|
51
|
-
if (!apiKey) {
|
|
52
|
-
throw new Error(`No API Key found for ${config.llm.provider} in config or .env`);
|
|
53
|
-
}
|
|
54
|
-
console.log(`[LLM] Using default API Key from .env`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (config.llm.provider === 'gemini') {
|
|
58
|
-
return new OpenAI({
|
|
59
|
-
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
|
60
|
-
apiKey: apiKey,
|
|
61
|
-
});
|
|
62
|
-
} else {
|
|
63
|
-
return new OpenAI({
|
|
64
|
-
apiKey: apiKey,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function getSystemPrompt() {
|
|
70
|
-
const config = loadConfig();
|
|
71
|
-
let basePrompt = `You are an autonomous Web3 agent operating on EVM chains.
|
|
72
|
-
You are equipped with a native wallet.
|
|
73
|
-
CRITICAL RULE: You must always reply in the exact same language that the user uses to talk to you. If the user speaks Indonesian, reply in Indonesian. If they speak English, reply in English.
|
|
74
|
-
CRITICAL RULE: If the user asks to check "my balance", "saldo saya", or anything about their own wallet, DO NOT ask them for an address. You must immediately call the get_balance tool and LEAVE THE ADDRESS PARAMETER EMPTY. The system will automatically use the injected private key wallet.
|
|
75
|
-
Always use the tools to interact with the blockchain.
|
|
76
|
-
If the user doesn't specify a chain, default to: ${config.agent.default_chain}.`;
|
|
77
|
-
|
|
78
|
-
// Read IDENTITY.md for core AI persona
|
|
79
|
-
try {
|
|
80
|
-
const identityMdPath = getPath('IDENTITY.md');
|
|
81
|
-
if (fs.existsSync(identityMdPath)) {
|
|
82
|
-
const identityInstructions = fs.readFileSync(identityMdPath, 'utf8');
|
|
83
|
-
basePrompt += `\n\n--- CORE IDENTITY & PERSONA ---\n${identityInstructions}`;
|
|
84
|
-
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error('Failed to read IDENTITY.md:', error);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Read user.md for custom instructions
|
|
90
|
-
try {
|
|
91
|
-
const userMdPath = getPath('user.md');
|
|
92
|
-
if (fs.existsSync(userMdPath)) {
|
|
93
|
-
const customInstructions = fs.readFileSync(userMdPath, 'utf8');
|
|
94
|
-
basePrompt += `\n\n--- CUSTOM USER INSTRUCTIONS ---\n${customInstructions}`;
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error('Failed to read user.md:', error);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return basePrompt;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function processUserInput(input: string): Promise<string> {
|
|
104
|
-
const config = loadConfig();
|
|
105
|
-
// Add user input to memory
|
|
106
|
-
logger.addEntry({ role: 'user', content: input });
|
|
107
|
-
|
|
108
|
-
const history = logger.getHistory();
|
|
109
|
-
|
|
110
|
-
// Format messages for OpenAI
|
|
111
|
-
const messages: any[] = [
|
|
112
|
-
{ role: 'system', content: getSystemPrompt() },
|
|
113
|
-
...history.map(m => {
|
|
114
|
-
const msg: any = { role: m.role, content: m.content || "" };
|
|
115
|
-
if (m.name) msg.name = m.name;
|
|
116
|
-
if (m.tool_call_id) msg.tool_call_id = m.tool_call_id;
|
|
117
|
-
if (m.tool_calls) msg.tool_calls = m.tool_calls;
|
|
118
|
-
return msg;
|
|
119
|
-
})
|
|
120
|
-
];
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
if (config.llm.provider !== 'openai' && config.llm.provider !== 'ollama' && config.llm.provider !== 'gemini') {
|
|
124
|
-
return `Provider ${config.llm.provider} is configured, but currently only OpenAI, Ollama, and Gemini adapters are implemented.`;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const openai = getOpenAI();
|
|
128
|
-
const response = await openai.chat.completions.create({
|
|
129
|
-
model: config.llm.model,
|
|
130
|
-
temperature: config.llm.temperature,
|
|
131
|
-
messages: messages,
|
|
132
|
-
tools: [getBalanceToolDefinition as any, transferToolDefinition as any, getPriceToolDefinition as any, swapTokenToolDefinition as any],
|
|
133
|
-
tool_choice: "auto",
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const responseMessage = response.choices[0].message;
|
|
137
|
-
|
|
138
|
-
// Log tracking
|
|
139
|
-
Tracker.addMessage();
|
|
140
|
-
if (response.usage?.total_tokens) {
|
|
141
|
-
Tracker.addTokens(response.usage.total_tokens, config.llm.provider);
|
|
142
|
-
}
|
|
143
|
-
Tracker.addEvent('llm.response', { provider: config.llm.provider, tool_calls: responseMessage.tool_calls?.length || 0 });
|
|
144
|
-
|
|
145
|
-
// Log assistant response
|
|
146
|
-
logger.addEntry({
|
|
147
|
-
role: 'assistant',
|
|
148
|
-
content: responseMessage.content || "",
|
|
149
|
-
tool_calls: responseMessage.tool_calls,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// Check if the model wants to call a tool
|
|
153
|
-
if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
|
|
154
|
-
for (const _toolCall of responseMessage.tool_calls) {
|
|
155
|
-
const toolCall = _toolCall as any;
|
|
156
|
-
if (toolCall.function.name === 'get_balance') {
|
|
157
|
-
const args = JSON.parse(toolCall.function.arguments);
|
|
158
|
-
const balanceResult = await getBalance(args.chainName, args.address);
|
|
159
|
-
|
|
160
|
-
logger.addEntry({
|
|
161
|
-
role: 'tool',
|
|
162
|
-
tool_call_id: toolCall.id,
|
|
163
|
-
name: toolCall.function.name,
|
|
164
|
-
content: balanceResult,
|
|
165
|
-
});
|
|
166
|
-
} else if (toolCall.function.name === 'transfer_native') {
|
|
167
|
-
const args = JSON.parse(toolCall.function.arguments);
|
|
168
|
-
const transferResult = await transferNative(args.chainName, args.toAddress, args.amountEth);
|
|
169
|
-
|
|
170
|
-
logger.addEntry({
|
|
171
|
-
role: 'tool',
|
|
172
|
-
tool_call_id: toolCall.id,
|
|
173
|
-
name: toolCall.function.name,
|
|
174
|
-
content: transferResult,
|
|
175
|
-
});
|
|
176
|
-
} else if (toolCall.function.name === 'get_price') {
|
|
177
|
-
const args = JSON.parse(toolCall.function.arguments);
|
|
178
|
-
const priceResult = await getPrice(args.coinId);
|
|
179
|
-
|
|
180
|
-
logger.addEntry({
|
|
181
|
-
role: 'tool',
|
|
182
|
-
tool_call_id: toolCall.id,
|
|
183
|
-
name: toolCall.function.name,
|
|
184
|
-
content: priceResult,
|
|
185
|
-
});
|
|
186
|
-
} else if (toolCall.function.name === 'swap_token') {
|
|
187
|
-
const args = JSON.parse(toolCall.function.arguments);
|
|
188
|
-
const swapResult = await swapToken(args.chainName, args.fromToken, args.toToken, args.amount);
|
|
189
|
-
|
|
190
|
-
logger.addEntry({
|
|
191
|
-
role: 'tool',
|
|
192
|
-
tool_call_id: toolCall.id,
|
|
193
|
-
name: toolCall.function.name,
|
|
194
|
-
content: swapResult,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Second call to get the final answer after tool execution
|
|
200
|
-
const secondMessages = [
|
|
201
|
-
{ role: 'system', content: getSystemPrompt() },
|
|
202
|
-
...logger.getHistory().map(m => {
|
|
203
|
-
const msg: any = { role: m.role, content: m.content || "" };
|
|
204
|
-
if (m.name) msg.name = m.name;
|
|
205
|
-
if (m.tool_call_id) msg.tool_call_id = m.tool_call_id;
|
|
206
|
-
if (m.tool_calls) msg.tool_calls = m.tool_calls;
|
|
207
|
-
return msg;
|
|
208
|
-
})
|
|
209
|
-
];
|
|
210
|
-
|
|
211
|
-
const openai = getOpenAI();
|
|
212
|
-
const secondResponse = await openai.chat.completions.create({
|
|
213
|
-
model: config.llm.model,
|
|
214
|
-
messages: secondMessages,
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
if (secondResponse.usage?.total_tokens) {
|
|
218
|
-
Tracker.addTokens(secondResponse.usage.total_tokens, config.llm.provider);
|
|
219
|
-
}
|
|
220
|
-
Tracker.addEvent('llm.final_response', { provider: config.llm.provider });
|
|
221
|
-
|
|
222
|
-
const finalContent = secondResponse.choices[0].message.content || "";
|
|
223
|
-
logger.addEntry({ role: 'assistant', content: finalContent });
|
|
224
|
-
return finalContent;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return responseMessage.content || "No response generated.";
|
|
228
|
-
} catch (error: any) {
|
|
229
|
-
console.error("LLM Error:", error);
|
|
230
|
-
return `Error connecting to AI Provider: ${error.message}`;
|
|
231
|
-
}
|
|
232
|
-
}
|
package/src/config/parser.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface OpenWebConfig {
|
|
2
|
-
agent: {
|
|
3
|
-
name: string;
|
|
4
|
-
default_chain: string;
|
|
5
|
-
};
|
|
6
|
-
llm: {
|
|
7
|
-
provider: 'openai' | 'anthropic' | 'ollama';
|
|
8
|
-
model: string;
|
|
9
|
-
temperature: number;
|
|
10
|
-
};
|
|
11
|
-
memory: {
|
|
12
|
-
type: string;
|
|
13
|
-
path: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export declare function loadConfig(): OpenWebConfig;
|
|
17
|
-
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,GAAG,EAAE;QACH,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;QAC5C,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,wBAAgB,UAAU,IAAI,aAAa,CAc1C"}
|
package/src/config/parser.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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.loadConfig = loadConfig;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const yaml_1 = __importDefault(require("yaml"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
function loadConfig() {
|
|
11
|
-
const configPath = path_1.default.resolve(process.cwd(), 'config.yaml');
|
|
12
|
-
try {
|
|
13
|
-
const file = fs_1.default.readFileSync(configPath, 'utf8');
|
|
14
|
-
const parsed = yaml_1.default.parse(file);
|
|
15
|
-
return parsed;
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
console.error('Failed to load config.yaml. Using default configuration.', error);
|
|
19
|
-
return {
|
|
20
|
-
agent: { name: 'OpenWeb-Default', default_chain: 'base' },
|
|
21
|
-
llm: { provider: 'openai', model: 'gpt-4o-mini', temperature: 0.2 },
|
|
22
|
-
memory: { type: 'file', path: './memory.json' }
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=parser.js.map
|
package/src/config/parser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":";;;;;AAoBA,gCAcC;AAlCD,4CAAoB;AACpB,gDAAwB;AACxB,gDAAwB;AAkBxB,SAAgB,UAAU;IACxB,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,MAAuB,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0DAA0D,EAAE,KAAK,CAAC,CAAC;QACjF,OAAO;YACL,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,EAAE;YACzD,GAAG,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE;YACnE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE;SAChD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/src/config/parser.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import yaml from 'yaml';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { getPath } from './paths';
|
|
5
|
-
|
|
6
|
-
export interface NyxoraConfig {
|
|
7
|
-
agent: {
|
|
8
|
-
name: string;
|
|
9
|
-
default_chain: string;
|
|
10
|
-
};
|
|
11
|
-
llm: {
|
|
12
|
-
provider: 'openai' | 'anthropic' | 'ollama' | 'gemini';
|
|
13
|
-
model: string;
|
|
14
|
-
temperature: number;
|
|
15
|
-
api_keys?: string[];
|
|
16
|
-
};
|
|
17
|
-
memory: {
|
|
18
|
-
type: string;
|
|
19
|
-
path: string;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function loadConfig(): NyxoraConfig {
|
|
24
|
-
const configPath = getPath('config.yaml');
|
|
25
|
-
try {
|
|
26
|
-
const file = fs.readFileSync(configPath, 'utf8');
|
|
27
|
-
const parsed = yaml.parse(file);
|
|
28
|
-
return parsed as NyxoraConfig;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error('Failed to load config.yaml. Using default configuration.', error);
|
|
31
|
-
return {
|
|
32
|
-
agent: { name: 'Nyxora-Default', default_chain: 'base' },
|
|
33
|
-
llm: { provider: 'openai', model: 'gpt-4o-mini', temperature: 0.2, api_keys: [] },
|
|
34
|
-
memory: { type: 'file', path: './memory.json' }
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function saveConfig(newConfig: NyxoraConfig): void {
|
|
40
|
-
const configPath = getPath('config.yaml');
|
|
41
|
-
try {
|
|
42
|
-
const yamlStr = yaml.stringify(newConfig);
|
|
43
|
-
fs.writeFileSync(configPath, yamlStr, 'utf8');
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error('Failed to save config.yaml', error);
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/config/paths.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import os from 'os';
|
|
4
|
-
|
|
5
|
-
let isGlobalModeCache: boolean | null = null;
|
|
6
|
-
|
|
7
|
-
export function getAppDir(): string {
|
|
8
|
-
// Check if .env or config.yaml exists in current working directory
|
|
9
|
-
if (isGlobalModeCache === null) {
|
|
10
|
-
const localEnv = path.join(process.cwd(), '.env');
|
|
11
|
-
const localConfig = path.join(process.cwd(), 'config.yaml');
|
|
12
|
-
|
|
13
|
-
if (fs.existsSync(localEnv) || fs.existsSync(localConfig)) {
|
|
14
|
-
isGlobalModeCache = false; // Local manual mode
|
|
15
|
-
} else {
|
|
16
|
-
isGlobalModeCache = true; // Global CLI mode
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (isGlobalModeCache) {
|
|
21
|
-
const globalDir = path.join(os.homedir(), '.nyxora');
|
|
22
|
-
if (!fs.existsSync(globalDir)) {
|
|
23
|
-
fs.mkdirSync(globalDir, { recursive: true });
|
|
24
|
-
}
|
|
25
|
-
return globalDir;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return process.cwd();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function getPath(filename: string): string {
|
|
32
|
-
return path.join(getAppDir(), filename);
|
|
33
|
-
}
|
package/src/gateway/cli.d.ts
DELETED
package/src/gateway/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["cli.ts"],"names":[],"mappings":""}
|
package/src/gateway/cli.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
const readline_1 = __importDefault(require("readline"));
|
|
41
|
-
const reasoning_1 = require("../agent/reasoning");
|
|
42
|
-
const dotenv = __importStar(require("dotenv"));
|
|
43
|
-
const parser_1 = require("../config/parser");
|
|
44
|
-
dotenv.config();
|
|
45
|
-
const rl = readline_1.default.createInterface({
|
|
46
|
-
input: process.stdin,
|
|
47
|
-
output: process.stdout
|
|
48
|
-
});
|
|
49
|
-
const config = (0, parser_1.loadConfig)();
|
|
50
|
-
console.log(`================================`);
|
|
51
|
-
console.log(`🤖 OpenWeb CLI Agent Started`);
|
|
52
|
-
console.log(`📋 Agent Name: ${config.agent.name}`);
|
|
53
|
-
console.log(`🔗 Default Chain: ${config.agent.default_chain}`);
|
|
54
|
-
console.log(`🧠 AI Provider: ${config.llm.provider} (${config.llm.model})`);
|
|
55
|
-
console.log(`================================`);
|
|
56
|
-
console.log(`Type 'exit' or 'quit' to stop.\n`);
|
|
57
|
-
function ask() {
|
|
58
|
-
rl.question('👤 You: ', async (input) => {
|
|
59
|
-
if (input.toLowerCase() === 'exit' || input.toLowerCase() === 'quit') {
|
|
60
|
-
console.log('Goodbye!');
|
|
61
|
-
rl.close();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (input.trim() === '') {
|
|
65
|
-
ask();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
console.log('🤖 Agent thinking...');
|
|
69
|
-
try {
|
|
70
|
-
const response = await (0, reasoning_1.processUserInput)(input);
|
|
71
|
-
console.log(`\n🤖 OpenWeb: ${response}\n`);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.log(`\n❌ Error: ${error.message}\n`);
|
|
75
|
-
}
|
|
76
|
-
ask();
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
ask();
|
|
80
|
-
//# sourceMappingURL=cli.js.map
|
package/src/gateway/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wDAAgC;AAChC,kDAAsD;AACtD,+CAAiC;AACjC,6CAA8C;AAE9C,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,EAAE,GAAG,kBAAQ,CAAC,eAAe,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;AAE5B,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAChD,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAC5C,OAAO,CAAC,GAAG,CAAC,kBAAkB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AACnD,OAAO,CAAC,GAAG,CAAC,qBAAqB,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;AAC/D,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;AAC5E,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAChD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAEhD,SAAS,GAAG;IACV,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QACtC,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;YACrE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACxB,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO;QACT,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACxB,GAAG,EAAE,CAAC;YACN,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QACpC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAA,4BAAgB,EAAC,KAAK,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,iBAAiB,QAAQ,IAAI,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;QAC/C,CAAC;QAED,GAAG,EAAE,CAAC;IACR,CAAC,CAAC,CAAC;AACL,CAAC;AAED,GAAG,EAAE,CAAC"}
|
package/src/gateway/cli.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import * as dotenv from 'dotenv';
|
|
7
|
-
import open from 'open';
|
|
8
|
-
import { getAppDir } from '../config/paths';
|
|
9
|
-
import { startServer } from './server';
|
|
10
|
-
|
|
11
|
-
// 1. Determine configuration directory
|
|
12
|
-
const appDir = getAppDir();
|
|
13
|
-
const isGlobalMode = appDir !== process.cwd();
|
|
14
|
-
|
|
15
|
-
console.log(`================================`);
|
|
16
|
-
console.log(`🤖 Nyxora CLI Agent Booting Up...`);
|
|
17
|
-
console.log(`📂 Config Directory: ${appDir}`);
|
|
18
|
-
console.log(`================================`);
|
|
19
|
-
|
|
20
|
-
// 2. Setup boilerplate files if in global mode and they don't exist
|
|
21
|
-
if (isGlobalMode) {
|
|
22
|
-
const globalEnvPath = path.join(appDir, '.env');
|
|
23
|
-
const globalConfigPath = path.join(appDir, 'config.yaml');
|
|
24
|
-
const globalUserMdPath = path.join(appDir, 'user.md');
|
|
25
|
-
const globalIdentityMdPath = path.join(appDir, 'IDENTITY.md');
|
|
26
|
-
|
|
27
|
-
// Copy .env.example to ~/.nyxora/.env if it doesn't exist
|
|
28
|
-
if (!fs.existsSync(globalEnvPath)) {
|
|
29
|
-
const exampleEnvPath = path.resolve(__dirname, '../../../.env.example');
|
|
30
|
-
if (fs.existsSync(exampleEnvPath)) {
|
|
31
|
-
fs.copyFileSync(exampleEnvPath, globalEnvPath);
|
|
32
|
-
console.log(`[Setup] Created default .env at ${globalEnvPath}`);
|
|
33
|
-
} else {
|
|
34
|
-
fs.writeFileSync(globalEnvPath, '# Nyxora Environment Variables\nOPENAI_API_KEY=\nGEMINI_API_KEY=\nTELEGRAM_BOT_TOKEN=\n');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Copy default config.yaml
|
|
39
|
-
if (!fs.existsSync(globalConfigPath)) {
|
|
40
|
-
const exampleConfigPath = path.resolve(__dirname, '../../../config.yaml');
|
|
41
|
-
if (fs.existsSync(exampleConfigPath)) {
|
|
42
|
-
fs.copyFileSync(exampleConfigPath, globalConfigPath);
|
|
43
|
-
} else {
|
|
44
|
-
fs.writeFileSync(globalConfigPath, 'agent:\n name: Nyxora-Agent\n default_chain: base\nllm:\n provider: openai\n model: gpt-4o-mini\n temperature: 0.2\n api_keys: []\nmemory:\n type: file\n path: memory.json\n');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!fs.existsSync(globalUserMdPath)) {
|
|
49
|
-
fs.writeFileSync(globalUserMdPath, 'Tuliskan instruksi kustom, aturan khusus, profil pengguna, atau persona yang Anda inginkan untuk Nyxora AI di file ini.\n');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!fs.existsSync(globalIdentityMdPath)) {
|
|
53
|
-
fs.writeFileSync(globalIdentityMdPath, 'Kamu adalah Nyxora, asisten Web3 pintar.\n');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 3. Load Environment Variables from the determined directory
|
|
58
|
-
dotenv.config({ path: path.join(appDir, '.env') });
|
|
59
|
-
|
|
60
|
-
// 4. Start the Express API Server (which also serves the static dashboard and Telegram bot)
|
|
61
|
-
startServer();
|
|
62
|
-
|
|
63
|
-
// 5. Open the Dashboard in the default browser
|
|
64
|
-
const PORT = process.env.PORT || 3000;
|
|
65
|
-
setTimeout(() => {
|
|
66
|
-
const url = `http://localhost:${PORT}`;
|
|
67
|
-
console.log(`🌐 Opening Dashboard at ${url}`);
|
|
68
|
-
open(url);
|
|
69
|
-
}, 1500);
|
package/src/gateway/server.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import cors from 'cors';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import * as dotenv from 'dotenv';
|
|
5
|
-
import { getPath } from '../config/paths';
|
|
6
|
-
|
|
7
|
-
dotenv.config({ path: getPath('.env') });
|
|
8
|
-
|
|
9
|
-
import { processUserInput, logger } from '../agent/reasoning';
|
|
10
|
-
import { loadConfig, saveConfig } from '../config/parser';
|
|
11
|
-
import { Tracker } from './tracker';
|
|
12
|
-
import { getBalanceToolDefinition } from '../web3/skills/getBalance';
|
|
13
|
-
import { transferToolDefinition } from '../web3/skills/transfer';
|
|
14
|
-
import { getPriceToolDefinition } from '../web3/skills/getPrice';
|
|
15
|
-
import { swapTokenToolDefinition } from '../web3/skills/swapToken';
|
|
16
|
-
import { startTelegramBot } from './telegram';
|
|
17
|
-
|
|
18
|
-
// Intercept console.log and console.error
|
|
19
|
-
const originalLog = console.log;
|
|
20
|
-
const originalError = console.error;
|
|
21
|
-
|
|
22
|
-
console.log = function (...args) {
|
|
23
|
-
Tracker.addGatewayLog(args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' '));
|
|
24
|
-
originalLog.apply(console, args);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
console.error = function (...args) {
|
|
28
|
-
Tracker.addGatewayLog(args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' '), { level: 'error' });
|
|
29
|
-
originalError.apply(console, args);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const app = express();
|
|
33
|
-
app.use(cors());
|
|
34
|
-
app.use(express.json());
|
|
35
|
-
|
|
36
|
-
// Serve static frontend from dashboard/dist
|
|
37
|
-
app.use(express.static(path.join(__dirname, '../../dashboard/dist')));
|
|
38
|
-
|
|
39
|
-
app.get('/api/history', (req, res) => {
|
|
40
|
-
try {
|
|
41
|
-
const history = logger.getHistory();
|
|
42
|
-
// Filter out internal system prompt for the frontend
|
|
43
|
-
const cleanHistory = history.filter((msg: any) => msg.role !== 'system');
|
|
44
|
-
res.json(cleanHistory);
|
|
45
|
-
} catch (error: any) {
|
|
46
|
-
res.status(500).json({ error: error.message });
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
app.delete('/api/history', (req, res) => {
|
|
51
|
-
try {
|
|
52
|
-
logger.clear();
|
|
53
|
-
Tracker.addEvent('memory.cleared');
|
|
54
|
-
res.json({ success: true });
|
|
55
|
-
} catch (error: any) {
|
|
56
|
-
res.status(500).json({ error: error.message });
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
app.get('/api/config', (req, res) => {
|
|
61
|
-
try {
|
|
62
|
-
const config = loadConfig();
|
|
63
|
-
res.json(config);
|
|
64
|
-
} catch (error: any) {
|
|
65
|
-
res.status(500).json({ error: error.message });
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
app.post('/api/config', (req, res) => {
|
|
70
|
-
try {
|
|
71
|
-
// Save new configuration to file
|
|
72
|
-
saveConfig(req.body);
|
|
73
|
-
Tracker.addEvent('config.updated', { provider: req.body.llm?.provider });
|
|
74
|
-
res.json({ success: true });
|
|
75
|
-
} catch (error: any) {
|
|
76
|
-
res.status(500).json({ error: error.message });
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
app.get('/api/stats', (req, res) => {
|
|
81
|
-
res.json(Tracker.getStats());
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
app.get('/api/logs', (req, res) => {
|
|
85
|
-
res.json(Tracker.getLogs());
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
app.get('/api/skills', (req, res) => {
|
|
89
|
-
res.json([
|
|
90
|
-
getBalanceToolDefinition,
|
|
91
|
-
transferToolDefinition,
|
|
92
|
-
getPriceToolDefinition,
|
|
93
|
-
swapTokenToolDefinition
|
|
94
|
-
]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
app.post('/api/chat', async (req, res) => {
|
|
98
|
-
try {
|
|
99
|
-
const { message } = req.body;
|
|
100
|
-
if (!message) {
|
|
101
|
-
return res.status(400).json({ error: 'Message is required' });
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Process input (this will automatically add to memory)
|
|
105
|
-
const response = await processUserInput(message);
|
|
106
|
-
|
|
107
|
-
res.json({ response });
|
|
108
|
-
} catch (error: any) {
|
|
109
|
-
res.status(500).json({ error: error.message });
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Fallback for React Router (Single Page Application)
|
|
114
|
-
app.use((req, res, next) => {
|
|
115
|
-
if (req.method === 'GET' && !req.path.startsWith('/api')) {
|
|
116
|
-
res.sendFile(path.join(__dirname, '../../dashboard/dist/index.html'));
|
|
117
|
-
} else {
|
|
118
|
-
next();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
export function startServer() {
|
|
123
|
-
const PORT = process.env.PORT || 3000;
|
|
124
|
-
app.listen(PORT, () => {
|
|
125
|
-
console.log(`🤖 Nyxora API Server running on port ${PORT}`);
|
|
126
|
-
|
|
127
|
-
// Start the Telegram bot listener
|
|
128
|
-
startTelegramBot();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Start server if this file is run directly
|
|
133
|
-
if (require.main === module) {
|
|
134
|
-
startServer();
|
|
135
|
-
}
|