omnikey-cli 1.5.7 → 1.6.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/backend-dist/__tests__/ai-client.nemotron.test.js +127 -0
- package/backend-dist/agent/agentPrompts.js +4 -3
- package/backend-dist/agent/utils.js +6 -5
- package/backend-dist/ai-client.js +151 -16
- package/backend-dist/config.js +16 -1
- package/backend-dist/db.js +5 -1
- package/backend-dist/mcpServerRoutes.js +16 -4
- package/backend-dist/scheduledJobRoutes.js +5 -2
- package/dist/index.js +1 -1
- package/dist/onboard.js +38 -0
- package/dist/telegramClient.js +1 -1
- package/dist/telegramDaemon.js +6 -4
- package/package.json +8 -6
- package/src/index.ts +1 -1
- package/src/onboard.ts +38 -0
- package/src/telegramClient.ts +1 -1
- package/src/telegramDaemon.ts +6 -8
- package/telegram-client-dist/{dist/agentClient.js → agentClient.js} +91 -75
- package/telegram-client-dist/{dist/config.js → config.js} +10 -12
- package/telegram-client-dist/{dist/index.js → index.js} +23 -32
- package/telegram-client-dist/{dist/notifyTelegram.js → notifyTelegram.js} +193 -194
- package/telegram-client-dist/{dist/omnikeyAuth.js → omnikeyAuth.js} +8 -13
- package/telegram-client-dist/dist/db.js +0 -78
|
@@ -12,12 +12,12 @@ let cachedExpiresAtMs = null;
|
|
|
12
12
|
// Renew JWTs a few minutes before expiry to avoid mid-WebSocket failures.
|
|
13
13
|
const RENEW_BEFORE_MS = 60 * 1000;
|
|
14
14
|
function decodeJwtExpiry(token) {
|
|
15
|
-
const parts = token.split(
|
|
15
|
+
const parts = token.split('.');
|
|
16
16
|
if (parts.length < 2)
|
|
17
17
|
return null;
|
|
18
18
|
try {
|
|
19
|
-
const payload = JSON.parse(Buffer.from(parts[1].replace(/-/g,
|
|
20
|
-
return typeof payload.exp ===
|
|
19
|
+
const payload = JSON.parse(Buffer.from(parts[1].replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'));
|
|
20
|
+
return typeof payload.exp === 'number' ? payload.exp * 1000 : null;
|
|
21
21
|
}
|
|
22
22
|
catch {
|
|
23
23
|
return null;
|
|
@@ -25,25 +25,20 @@ function decodeJwtExpiry(token) {
|
|
|
25
25
|
}
|
|
26
26
|
async function fetchJwtToken(logger, force = false) {
|
|
27
27
|
const now = Date.now();
|
|
28
|
-
if (!force &&
|
|
29
|
-
cachedToken &&
|
|
30
|
-
cachedExpiresAtMs &&
|
|
31
|
-
cachedExpiresAtMs - RENEW_BEFORE_MS > now) {
|
|
28
|
+
if (!force && cachedToken && cachedExpiresAtMs && cachedExpiresAtMs - RENEW_BEFORE_MS > now) {
|
|
32
29
|
return cachedToken;
|
|
33
30
|
}
|
|
34
31
|
const url = `${(0, config_1.omnikeyBaseUrl)()}/api/subscription/activate`;
|
|
35
|
-
logger.info(
|
|
32
|
+
logger.info('Requesting JWT from omnikey-ai', { url });
|
|
36
33
|
const resp = await axios_1.default.post(url, {}, { timeout: 10000 });
|
|
37
34
|
if (!resp.data?.token) {
|
|
38
|
-
throw new Error(
|
|
35
|
+
throw new Error('activate endpoint returned no token');
|
|
39
36
|
}
|
|
40
37
|
cachedToken = resp.data.token;
|
|
41
38
|
cachedExpiresAtMs = decodeJwtExpiry(cachedToken);
|
|
42
|
-
logger.info(
|
|
39
|
+
logger.info('Received JWT from omnikey-ai', {
|
|
43
40
|
subscriptionStatus: resp.data.subscriptionStatus,
|
|
44
|
-
expiresAt: cachedExpiresAtMs
|
|
45
|
-
? new Date(cachedExpiresAtMs).toISOString()
|
|
46
|
-
: null,
|
|
41
|
+
expiresAt: cachedExpiresAtMs ? new Date(cachedExpiresAtMs).toISOString() : null,
|
|
47
42
|
});
|
|
48
43
|
return cachedToken;
|
|
49
44
|
}
|
|
@@ -1,78 +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.initDb = initDb;
|
|
7
|
-
exports.closeDb = closeDb;
|
|
8
|
-
exports.getRecentSessions = getRecentSessions;
|
|
9
|
-
exports.getSessionById = getSessionById;
|
|
10
|
-
exports.getMostRecentSession = getMostRecentSession;
|
|
11
|
-
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
12
|
-
const config_1 = require("./config");
|
|
13
|
-
let dbInstance = null;
|
|
14
|
-
function initDb(logger) {
|
|
15
|
-
if (dbInstance)
|
|
16
|
-
return dbInstance;
|
|
17
|
-
const { sqlitePath } = (0, config_1.loadOmnikeyConfig)();
|
|
18
|
-
dbInstance = new better_sqlite3_1.default(sqlitePath, {
|
|
19
|
-
readonly: true,
|
|
20
|
-
fileMustExist: true,
|
|
21
|
-
});
|
|
22
|
-
// WAL is set by the writer; we only read. Set busy timeout so concurrent
|
|
23
|
-
// writes from omnikey-ai never throw SQLITE_BUSY at us.
|
|
24
|
-
dbInstance.pragma("busy_timeout = 5000");
|
|
25
|
-
logger.info("Opened SQLite database (read-only)", { path: sqlitePath });
|
|
26
|
-
return dbInstance;
|
|
27
|
-
}
|
|
28
|
-
function closeDb(logger) {
|
|
29
|
-
if (!dbInstance)
|
|
30
|
-
return;
|
|
31
|
-
try {
|
|
32
|
-
dbInstance.close();
|
|
33
|
-
logger?.info("Closed SQLite database");
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
logger?.warn("Error closing SQLite database", {
|
|
37
|
-
error: err.message,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
dbInstance = null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function getRecentSessions(limit) {
|
|
45
|
-
const db = dbInstance;
|
|
46
|
-
if (!db)
|
|
47
|
-
throw new Error("Database not initialised. Call initDb() first.");
|
|
48
|
-
const rows = db
|
|
49
|
-
.prepare(`SELECT id, title, turns, last_active_at AS lastActiveAt, group_name AS groupName
|
|
50
|
-
FROM agent_sessions
|
|
51
|
-
ORDER BY last_active_at DESC
|
|
52
|
-
LIMIT ?`)
|
|
53
|
-
.all(limit);
|
|
54
|
-
return rows;
|
|
55
|
-
}
|
|
56
|
-
function getSessionById(sessionId) {
|
|
57
|
-
const db = dbInstance;
|
|
58
|
-
if (!db)
|
|
59
|
-
throw new Error("Database not initialised. Call initDb() first.");
|
|
60
|
-
const row = db
|
|
61
|
-
.prepare(`SELECT id, title, turns, last_active_at AS lastActiveAt, group_name AS groupName, history_json AS historyJson
|
|
62
|
-
FROM agent_sessions
|
|
63
|
-
WHERE id = ?`)
|
|
64
|
-
.get(sessionId);
|
|
65
|
-
return row ?? null;
|
|
66
|
-
}
|
|
67
|
-
function getMostRecentSession() {
|
|
68
|
-
const db = dbInstance;
|
|
69
|
-
if (!db)
|
|
70
|
-
throw new Error("Database not initialised. Call initDb() first.");
|
|
71
|
-
const row = db
|
|
72
|
-
.prepare(`SELECT id, title, turns, last_active_at AS lastActiveAt, group_name AS groupName, history_json AS historyJson
|
|
73
|
-
FROM agent_sessions
|
|
74
|
-
ORDER BY last_active_at DESC
|
|
75
|
-
LIMIT 1`)
|
|
76
|
-
.get();
|
|
77
|
-
return row ?? null;
|
|
78
|
-
}
|