sovkora 0.0.0-stage โ 1.1.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 +202 -0
- package/NOTICE +9 -0
- package/README.md +67 -2
- package/dist/commands/agent.command.js +267 -0
- package/dist/commands/chat.command.js +214 -0
- package/dist/commands/chat.handlers.js +150 -0
- package/dist/commands/chat.types.js +44 -0
- package/dist/commands/cinema.command.js +643 -0
- package/dist/commands/config.command.js +228 -0
- package/dist/commands/db.command.js +114 -0
- package/dist/commands/demo.command.js +55 -0
- package/dist/commands/dev.command.js +462 -0
- package/dist/commands/docs.command.js +135 -0
- package/dist/commands/doctor.command.js +119 -0
- package/dist/commands/forgot.command.js +57 -0
- package/dist/commands/generate.command.js +376 -0
- package/dist/commands/graph.command.js +54 -0
- package/dist/commands/init.command.js +380 -0
- package/dist/commands/init.steps.js +115 -0
- package/dist/commands/install.command.js +459 -0
- package/dist/commands/login.command.js +110 -0
- package/dist/commands/logs.command.js +215 -0
- package/dist/commands/logs.steps.js +130 -0
- package/dist/commands/mcp.command.js +104 -0
- package/dist/commands/models.command.js +164 -0
- package/dist/commands/onboard.command.js +236 -0
- package/dist/commands/pack.command.js +255 -0
- package/dist/commands/profile.command.js +51 -0
- package/dist/commands/recover.command.js +489 -0
- package/dist/commands/register.command.js +94 -0
- package/dist/commands/release.command.js +99 -0
- package/dist/commands/reset.command.js +79 -0
- package/dist/commands/runs.command.js +201 -0
- package/dist/commands/settings.command.js +85 -0
- package/dist/commands/start.command.js +590 -0
- package/dist/commands/status.command.js +167 -0
- package/dist/commands/stop.command.js +313 -0
- package/dist/commands/studio.command.js +266 -0
- package/dist/commands/test.command.js +134 -0
- package/dist/commands/verify.command.js +52 -0
- package/dist/commands/video.command.js +73 -0
- package/dist/commands/workspace-guard.js +72 -0
- package/dist/index.js +207 -0
- package/dist/renderers.js +250 -0
- package/dist/services/api-client.js +150 -0
- package/dist/services/auth.api.js +87 -0
- package/dist/services/chat.api.js +117 -0
- package/dist/services/cinema-estimate.json +42 -0
- package/dist/services/cinema.childsafe.js +52 -0
- package/dist/services/cinema.director.js +285 -0
- package/dist/services/cinema.production.js +417 -0
- package/dist/services/cinema.staging.js +323 -0
- package/dist/services/cinema.story.js +758 -0
- package/dist/services/cinema.treatment.js +393 -0
- package/dist/services/composer.run.js +94 -0
- package/dist/services/demo/demo.documents.js +108 -0
- package/dist/services/demo/demo.guard.js +49 -0
- package/dist/services/demo/demo.persona.js +114 -0
- package/dist/services/demo/demo.seed.js +281 -0
- package/dist/services/diagnostics.js +327 -0
- package/dist/services/image-model-recipes.json +93 -0
- package/dist/services/image-models.js +152 -0
- package/dist/services/local-store.js +145 -0
- package/dist/services/mcp.api.js +38 -0
- package/dist/services/model-catalog.js +70 -0
- package/dist/services/notify.js +55 -0
- package/dist/services/pack.api.js +23 -0
- package/dist/services/pack.bundle.js +241 -0
- package/dist/services/pack.sources.js +101 -0
- package/dist/services/release-manifest.js +266 -0
- package/dist/services/runs.view.js +80 -0
- package/dist/services/runs.wait.js +38 -0
- package/dist/services/semver.js +55 -0
- package/dist/services/settings.api.js +108 -0
- package/dist/services/string-utils.js +70 -0
- package/dist/services/studio.api.js +120 -0
- package/dist/services/templates.js +893 -0
- package/dist/services/tool-installer.js +353 -0
- package/dist/services/tool-path.js +72 -0
- package/dist/services/version-manager.js +253 -0
- package/dist/services/workspace-bootstrap.js +68 -0
- package/dist/threads.js +202 -0
- package/dist/types/api.types.js +6 -0
- package/dist/types/local.types.js +6 -0
- package/dist/ui/box.js +46 -0
- package/dist/ui/logger.js +28 -0
- package/dist/ui/platform.js +32 -0
- package/dist/ui/prompts.js +130 -0
- package/dist/ui/table.js +33 -0
- package/dist/utils/config.js +150 -0
- package/dist/utils/development-status.js +22 -0
- package/dist/utils/endpoints.js +41 -0
- package/dist/utils/health.js +94 -0
- package/dist/utils/pid.js +83 -0
- package/dist/utils/platform.js +358 -0
- package/dist/utils/process.js +139 -0
- package/dist/utils/state-dir.js +105 -0
- package/package.json +95 -4
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file logs.command.ts
|
|
4
|
+
* @description Real-time log streaming and historical log viewing.
|
|
5
|
+
* Supports multiplexed tailing, per-service filtering, and log listing.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.logsCommand = void 0;
|
|
45
|
+
const commander_1 = require("commander");
|
|
46
|
+
const fs = __importStar(require("node:fs"));
|
|
47
|
+
const path = __importStar(require("node:path"));
|
|
48
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
49
|
+
const prompts_1 = require("../ui/prompts");
|
|
50
|
+
const platform_1 = require("../ui/platform");
|
|
51
|
+
const logs_steps_1 = require("./logs.steps");
|
|
52
|
+
/** At most this many files are tailed, to avoid flooding the terminal. */
|
|
53
|
+
const MAX_TAILED_FILES = 5;
|
|
54
|
+
const TITLE = chalk_1.default.cyan.bold("๐ฅท Sovkora Logs");
|
|
55
|
+
/** Nothing to show: a title, a warning (and an optional hint), a closing line. */
|
|
56
|
+
async function bail(warning, closing, hint) {
|
|
57
|
+
await (0, prompts_1.intro)(TITLE);
|
|
58
|
+
await (0, prompts_1.logWarning)(warning);
|
|
59
|
+
if (hint)
|
|
60
|
+
await (0, prompts_1.logInfo)(hint);
|
|
61
|
+
await (0, prompts_1.outro)(closing);
|
|
62
|
+
}
|
|
63
|
+
/** The `.log` files of a directory, most recent name first. */
|
|
64
|
+
function listLogFiles(logDir) {
|
|
65
|
+
return fs
|
|
66
|
+
.readdirSync(logDir)
|
|
67
|
+
.filter((f) => f.endsWith(".log"))
|
|
68
|
+
.sort()
|
|
69
|
+
.reverse();
|
|
70
|
+
}
|
|
71
|
+
function describeLogFile(logDir, file) {
|
|
72
|
+
const stats = fs.statSync(path.join(logDir, file));
|
|
73
|
+
const colorFn = (0, logs_steps_1.getServiceColor)(file);
|
|
74
|
+
const label = (0, logs_steps_1.getServiceLabel)(file);
|
|
75
|
+
const ageStr = (0, logs_steps_1.formatAge)(stats.mtimeMs, Date.now());
|
|
76
|
+
const line = `${colorFn("[" + label + "]")} ${chalk_1.default.white(file.padEnd(45))} ${chalk_1.default.gray((0, logs_steps_1.formatFileSize)(stats.size).padStart(10))} ${chalk_1.default.gray(ageStr)}`;
|
|
77
|
+
return { line, size: stats.size };
|
|
78
|
+
}
|
|
79
|
+
async function showListing(logDir, allFiles) {
|
|
80
|
+
await (0, prompts_1.intro)(chalk_1.default.cyan.bold("๐ฅท Sovkora Logs โ File Listing"));
|
|
81
|
+
const described = allFiles.map((file) => describeLogFile(logDir, file));
|
|
82
|
+
const totalSize = described.reduce((sum, { size }) => sum + size, 0);
|
|
83
|
+
const lines = [
|
|
84
|
+
...described.map(({ line }) => line),
|
|
85
|
+
"",
|
|
86
|
+
`${chalk_1.default.gray("Total:")} ${String(allFiles.length)} file(s), ${(0, logs_steps_1.formatFileSize)(totalSize)}`,
|
|
87
|
+
];
|
|
88
|
+
await (0, prompts_1.note)(lines.join("\n"), "Available Log Files");
|
|
89
|
+
await (0, prompts_1.outro)(`Tail logs: ${chalk_1.default.cyan("npx sovkora logs")} or ${chalk_1.default.cyan("npx sovkora logs --service router")}`);
|
|
90
|
+
}
|
|
91
|
+
/** The files modified within the last `sinceMs`. */
|
|
92
|
+
function filterBySince(logDir, files, sinceMs) {
|
|
93
|
+
const cutoff = Date.now() - sinceMs;
|
|
94
|
+
return files.filter((f) => fs.statSync(path.join(logDir, f)).mtimeMs >= cutoff);
|
|
95
|
+
}
|
|
96
|
+
function printHeader(fileCount) {
|
|
97
|
+
console.log("");
|
|
98
|
+
console.log(chalk_1.default.cyan.bold("๐ฅท Sovkora Logs โ Real-time Stream"));
|
|
99
|
+
console.log(chalk_1.default.gray(` Tailing ${String(fileCount)} file(s) | Ctrl+C to stop`));
|
|
100
|
+
console.log(chalk_1.default.gray(" โ".repeat(30)));
|
|
101
|
+
console.log("");
|
|
102
|
+
}
|
|
103
|
+
/** Shows the last lines of one file under a rule; unreadable files are skipped. */
|
|
104
|
+
function printRecentLines(logDir, file, tailLines) {
|
|
105
|
+
const colorFn = (0, logs_steps_1.getServiceColor)(file);
|
|
106
|
+
const label = (0, logs_steps_1.getServiceLabel)(file);
|
|
107
|
+
try {
|
|
108
|
+
const lines = (0, logs_steps_1.lastLines)(fs.readFileSync(path.join(logDir, file), "utf-8"), tailLines);
|
|
109
|
+
if (lines.length === 0)
|
|
110
|
+
return;
|
|
111
|
+
console.log(colorFn(`โโ ${label} (${file}) ${"โ".repeat(Math.max(0, 50 - file.length))}`));
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
console.log(`${colorFn("[" + label + "]")} ${line}`);
|
|
114
|
+
}
|
|
115
|
+
console.log("");
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* skip unreadable files */
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Prints what was appended to a file since the last position and moves the position on. */
|
|
122
|
+
function printAppended(filePath, positions, print) {
|
|
123
|
+
try {
|
|
124
|
+
const size = fs.statSync(filePath).size;
|
|
125
|
+
const previous = positions.get(filePath) ?? 0;
|
|
126
|
+
if (size <= previous)
|
|
127
|
+
return;
|
|
128
|
+
for (const line of (0, logs_steps_1.appendedLines)((0, logs_steps_1.readRange)(filePath, previous, size))) {
|
|
129
|
+
print(line);
|
|
130
|
+
}
|
|
131
|
+
positions.set(filePath, size);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
/* ignore read errors during watch */
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Watches one file for appended lines; undefined when it cannot be watched. */
|
|
138
|
+
function watchLogFile(logDir, file, positions) {
|
|
139
|
+
const filePath = path.join(logDir, file);
|
|
140
|
+
const colorFn = (0, logs_steps_1.getServiceColor)(file);
|
|
141
|
+
const label = (0, logs_steps_1.getServiceLabel)(file);
|
|
142
|
+
try {
|
|
143
|
+
positions.set(filePath, fs.statSync(filePath).size);
|
|
144
|
+
return fs.watch(filePath, (eventType) => {
|
|
145
|
+
if (eventType !== "change")
|
|
146
|
+
return;
|
|
147
|
+
printAppended(filePath, positions, (line) => console.log(`${colorFn("[" + label + "]")} ${line}`));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
/* skip files that can't be watched */
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Keeps the process alive until Ctrl+C, then closes the watchers. */
|
|
156
|
+
function waitForInterrupt(watchers) {
|
|
157
|
+
return new Promise((resolve) => {
|
|
158
|
+
process.on("SIGINT", () => {
|
|
159
|
+
for (const watcher of watchers) {
|
|
160
|
+
watcher.close();
|
|
161
|
+
}
|
|
162
|
+
console.log("\n" + chalk_1.default.gray("Log streaming stopped."));
|
|
163
|
+
resolve();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async function streamLogs(logDir, files, tailLines) {
|
|
168
|
+
printHeader(files.length);
|
|
169
|
+
const tailed = files.slice(0, MAX_TAILED_FILES);
|
|
170
|
+
for (const file of tailed) {
|
|
171
|
+
printRecentLines(logDir, file, tailLines);
|
|
172
|
+
}
|
|
173
|
+
console.log(chalk_1.default.gray(" โโโ Watching for new log entries... โโโ"));
|
|
174
|
+
console.log("");
|
|
175
|
+
const positions = new Map();
|
|
176
|
+
const watchers = tailed
|
|
177
|
+
.map((file) => watchLogFile(logDir, file, positions))
|
|
178
|
+
.filter((watcher) => watcher !== undefined);
|
|
179
|
+
await waitForInterrupt(watchers);
|
|
180
|
+
}
|
|
181
|
+
exports.logsCommand = new commander_1.Command("logs")
|
|
182
|
+
.description("Stream and browse service logs")
|
|
183
|
+
.option("--service <name>", "Tail a specific service (router, ollama, media-worker, image-worker, ui)")
|
|
184
|
+
.option("--list", "List all available log files with sizes")
|
|
185
|
+
.option("--since <duration>", "Show logs from last N hours (e.g., 1h, 30m)", "24h")
|
|
186
|
+
.option("--tail <lines>", "Number of lines to show from end of file", "50")
|
|
187
|
+
.action(async (options) => {
|
|
188
|
+
const logDir = (0, platform_1.resolveLogDir)();
|
|
189
|
+
if (!fs.existsSync(logDir)) {
|
|
190
|
+
const relative = path.relative((0, platform_1.resolveWorkspaceRoot)(), logDir);
|
|
191
|
+
await bail(`Log directory not found: ${chalk_1.default.gray(relative)}\n` +
|
|
192
|
+
` Run ${chalk_1.default.cyan("npx sovkora start")} first to generate logs.`, "No logs available.");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const allFiles = listLogFiles(logDir); // Most recent first
|
|
196
|
+
if (allFiles.length === 0) {
|
|
197
|
+
await bail("No log files found.", "No logs available.");
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (options.list) {
|
|
201
|
+
await showListing(logDir, allFiles);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const byService = (0, logs_steps_1.filterByService)(allFiles, options.service);
|
|
205
|
+
if (byService.length === 0) {
|
|
206
|
+
await bail(`No logs found for service: ${chalk_1.default.yellow(options.service)}`, "Try a different service name.", `Available services: ${chalk_1.default.gray("router, ollama, media-worker, image-worker, ui")}`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const targetFiles = filterBySince(logDir, byService, (0, logs_steps_1.parseSinceMs)(options.since));
|
|
210
|
+
if (targetFiles.length === 0) {
|
|
211
|
+
await bail(`No logs found within the last ${options.since ?? "24h"}`, "Try a longer duration with --since.");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
await streamLogs(logDir, targetFiles, Number.parseInt(options.tail ?? "50"));
|
|
215
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file logs.steps.ts
|
|
4
|
+
* @description Pure steps of `sovkora logs`, kept out of the command so each one is small and tested:
|
|
5
|
+
* the duration parser, the file filters, the labels, the sizes and ages, the tail and the appended text.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.getServiceColor = getServiceColor;
|
|
45
|
+
exports.getServiceLabel = getServiceLabel;
|
|
46
|
+
exports.formatFileSize = formatFileSize;
|
|
47
|
+
exports.formatAge = formatAge;
|
|
48
|
+
exports.parseSinceMs = parseSinceMs;
|
|
49
|
+
exports.filterByService = filterByService;
|
|
50
|
+
exports.lastLines = lastLines;
|
|
51
|
+
exports.appendedLines = appendedLines;
|
|
52
|
+
exports.readRange = readRange;
|
|
53
|
+
const fs = __importStar(require("node:fs"));
|
|
54
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
55
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
56
|
+
const UNIT_MS = { m: 60 * 1000, h: HOUR_MS, d: 24 * HOUR_MS };
|
|
57
|
+
/** Color map for service log prefixes. */
|
|
58
|
+
const SERVICE_COLORS = {
|
|
59
|
+
router: chalk_1.default.cyan,
|
|
60
|
+
gateway: chalk_1.default.cyan, // legacy log filename alias
|
|
61
|
+
ollama: chalk_1.default.green,
|
|
62
|
+
"media-worker": chalk_1.default.magenta,
|
|
63
|
+
"video-worker": chalk_1.default.magenta, // legacy log filename alias
|
|
64
|
+
"image-worker": chalk_1.default.yellow,
|
|
65
|
+
ui: chalk_1.default.blue,
|
|
66
|
+
docker: chalk_1.default.gray,
|
|
67
|
+
};
|
|
68
|
+
/** Label of a log file's service, by the first fragment its name contains. */
|
|
69
|
+
const SERVICE_LABELS = [
|
|
70
|
+
{ fragments: ["router", "gateway"], label: "ROUTER " },
|
|
71
|
+
{ fragments: ["ollama"], label: "OLLAMA " },
|
|
72
|
+
{ fragments: ["media", "video"], label: "MEDIA " },
|
|
73
|
+
{ fragments: ["image"], label: "IMAGE " },
|
|
74
|
+
{ fragments: ["ui"], label: "UI " },
|
|
75
|
+
];
|
|
76
|
+
function getServiceColor(filename) {
|
|
77
|
+
const lower = filename.toLowerCase();
|
|
78
|
+
const match = Object.entries(SERVICE_COLORS).find(([key]) => lower.includes(key));
|
|
79
|
+
return match ? match[1] : chalk_1.default.white;
|
|
80
|
+
}
|
|
81
|
+
function getServiceLabel(filename) {
|
|
82
|
+
const match = SERVICE_LABELS.find(({ fragments }) => fragments.some((fragment) => filename.includes(fragment)));
|
|
83
|
+
return match ? match.label : "LOG ";
|
|
84
|
+
}
|
|
85
|
+
function formatFileSize(bytes) {
|
|
86
|
+
if (bytes < 1024)
|
|
87
|
+
return `${String(bytes)} B`;
|
|
88
|
+
if (bytes < 1024 * 1024)
|
|
89
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
90
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
91
|
+
}
|
|
92
|
+
/** ยซ 12m ago ยป under an hour, ยซ 3h ago ยป after. */
|
|
93
|
+
function formatAge(mtimeMs, nowMs) {
|
|
94
|
+
const minutes = Math.round((nowMs - mtimeMs) / (1000 * 60));
|
|
95
|
+
return minutes < 60 ? `${String(minutes)}m ago` : `${Math.round(minutes / 60)}h ago`;
|
|
96
|
+
}
|
|
97
|
+
/** `--since` (`30m`, `1h`, `2d`) in milliseconds; anything else is the default 24 hours. */
|
|
98
|
+
function parseSinceMs(since) {
|
|
99
|
+
const match = /^(\d+)([hmd])$/.exec(since ?? "");
|
|
100
|
+
if (!match)
|
|
101
|
+
return 24 * HOUR_MS;
|
|
102
|
+
return Number.parseInt(match[1]) * UNIT_MS[match[2]];
|
|
103
|
+
}
|
|
104
|
+
/** The files whose name contains the service name (case-insensitive); all of them without a service. */
|
|
105
|
+
function filterByService(files, service) {
|
|
106
|
+
if (!service)
|
|
107
|
+
return files;
|
|
108
|
+
const needle = service.toLowerCase();
|
|
109
|
+
return files.filter((file) => file.toLowerCase().includes(needle));
|
|
110
|
+
}
|
|
111
|
+
/** The last `count` non-empty lines of a text. */
|
|
112
|
+
function lastLines(content, count) {
|
|
113
|
+
return content.split("\n").filter(Boolean).slice(-count);
|
|
114
|
+
}
|
|
115
|
+
/** The non-blank lines of newly appended text. */
|
|
116
|
+
function appendedLines(text) {
|
|
117
|
+
return text.split("\n").filter((line) => line.trim());
|
|
118
|
+
}
|
|
119
|
+
/** The bytes of a file from `from` to `to`, as text. */
|
|
120
|
+
function readRange(filePath, from, to) {
|
|
121
|
+
const fd = fs.openSync(filePath, "r");
|
|
122
|
+
try {
|
|
123
|
+
const buffer = Buffer.alloc(to - from);
|
|
124
|
+
fs.readSync(fd, buffer, 0, buffer.length, from);
|
|
125
|
+
return buffer.toString("utf-8");
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
fs.closeSync(fd);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file mcp.command.ts
|
|
4
|
+
* @description Command to manage user private MCP server connections.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.mcpCommand = void 0;
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const prompts_1 = require("../ui/prompts");
|
|
10
|
+
const threads_1 = require("../threads");
|
|
11
|
+
const settings_api_1 = require("../services/settings.api");
|
|
12
|
+
const mcp_api_1 = require("../services/mcp.api");
|
|
13
|
+
const logger_1 = require("../ui/logger");
|
|
14
|
+
const box_1 = require("../ui/box");
|
|
15
|
+
exports.mcpCommand = new commander_1.Command("mcp").description("Manage your private dynamic MCP server connections");
|
|
16
|
+
exports.mcpCommand
|
|
17
|
+
.command("list")
|
|
18
|
+
.description("List your registered private MCP servers")
|
|
19
|
+
.action(async () => {
|
|
20
|
+
(0, threads_1.requireAuth)();
|
|
21
|
+
const s = await (0, prompts_1.createSpinner)();
|
|
22
|
+
s.start("Retrieving your MCP servers...");
|
|
23
|
+
try {
|
|
24
|
+
const servers = await mcp_api_1.McpApi.listUserServers();
|
|
25
|
+
s.stop("MCP servers retrieved");
|
|
26
|
+
const items = [];
|
|
27
|
+
if (servers.length === 0) {
|
|
28
|
+
items.push("No private MCP servers registered.");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
for (const srv of servers) {
|
|
32
|
+
items.push({ key: `ID: ${srv.id} [${srv.label}]`, value: srv.url });
|
|
33
|
+
if (srv.authToken) {
|
|
34
|
+
items.push({ key: " Auth Token", value: "********" });
|
|
35
|
+
}
|
|
36
|
+
items.push({ key: " Status", value: srv.enabled ? "Enabled" : "Disabled" });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
box_1.Box.render("My Private MCP Servers", items, {
|
|
40
|
+
borderColor: "cyan",
|
|
41
|
+
titleColor: "white",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
s.stop("Failed to retrieve MCP servers");
|
|
46
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
47
|
+
logger_1.Logger.error(`Failed to retrieve MCP servers: ${msg}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
exports.mcpCommand
|
|
52
|
+
.command("register")
|
|
53
|
+
.description("Register a new private MCP server")
|
|
54
|
+
.requiredOption("--label <label>", "Unique friendly label for the server")
|
|
55
|
+
.requiredOption("--url <url>", "Remote SSE/URL transport endpoint (e.g. http://localhost:3000/sse)")
|
|
56
|
+
.option("--auth-token <token>", "Optional authorization token/header")
|
|
57
|
+
.action(async (options) => {
|
|
58
|
+
(0, threads_1.requireAuth)();
|
|
59
|
+
const s = await (0, prompts_1.createSpinner)();
|
|
60
|
+
s.start("Fetching user profile...");
|
|
61
|
+
try {
|
|
62
|
+
const user = await settings_api_1.SettingsApi.getMe();
|
|
63
|
+
s.message("Registering MCP server...");
|
|
64
|
+
const newServer = await mcp_api_1.McpApi.registerUserServer({
|
|
65
|
+
userId: user.id,
|
|
66
|
+
label: options.label,
|
|
67
|
+
url: options.url,
|
|
68
|
+
authToken: options.authToken,
|
|
69
|
+
enabled: true,
|
|
70
|
+
});
|
|
71
|
+
s.stop("MCP server registered successfully");
|
|
72
|
+
logger_1.Logger.success(`Successfully registered MCP server: ${newServer.label} (ID: ${newServer.id})`);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
s.stop("Failed to register MCP server");
|
|
76
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
77
|
+
logger_1.Logger.error(`Failed to register MCP server: ${msg}`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
exports.mcpCommand
|
|
82
|
+
.command("delete <id>")
|
|
83
|
+
.description("Delete a private MCP server by ID")
|
|
84
|
+
.action(async (idStr) => {
|
|
85
|
+
(0, threads_1.requireAuth)();
|
|
86
|
+
const id = Number.parseInt(idStr, 10);
|
|
87
|
+
if (Number.isNaN(id)) {
|
|
88
|
+
logger_1.Logger.error("Invalid server ID. Must be a number.");
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
const s = await (0, prompts_1.createSpinner)();
|
|
92
|
+
s.start(`Deleting MCP server ID ${id}...`);
|
|
93
|
+
try {
|
|
94
|
+
await mcp_api_1.McpApi.deleteUserServer(id);
|
|
95
|
+
s.stop("MCP server deleted successfully");
|
|
96
|
+
logger_1.Logger.success(`Successfully deleted MCP server ID ${id}`);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
s.stop("Failed to delete MCP server");
|
|
100
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
101
|
+
logger_1.Logger.error(`Failed to delete MCP server: ${msg}`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file models.command.ts
|
|
4
|
+
* @description Scans the host hardware and reports which catalog models it can run.
|
|
5
|
+
* Mirrors the backend `HostCapability` rule so the CLI report and the UI greying agree:
|
|
6
|
+
* a model's `supported_hardware` must be blank/cpu/any, or match a host accelerator.
|
|
7
|
+
*
|
|
8
|
+
* `sovkora models image list|pull|use` installs the local image models (stable-diffusion.cpp
|
|
9
|
+
* recipes, services/image-model-recipes.json) and chooses which one the catalogue serves.
|
|
10
|
+
*/
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.modelsCommand = void 0;
|
|
16
|
+
const commander_1 = require("commander");
|
|
17
|
+
const node_child_process_1 = require("node:child_process");
|
|
18
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const prompts_1 = require("../ui/prompts");
|
|
20
|
+
const platform_1 = require("../utils/platform");
|
|
21
|
+
const image_models_1 = require("../services/image-models");
|
|
22
|
+
const model_catalog_1 = require("../services/model-catalog");
|
|
23
|
+
require("../utils/config"); // side-effect: loads .env into process.env (DB_NAME/DB_USERNAME)
|
|
24
|
+
/** Accelerators exposed by the host โ mirrors core `HostCapabilityDetector`. */
|
|
25
|
+
function hostAccelerators() {
|
|
26
|
+
return (0, platform_1.isAppleSilicon)() ? ["APPLE_SILICON_MLX", "mps", "coreml"] : ["cpu"];
|
|
27
|
+
}
|
|
28
|
+
/** Mirrors `HostCapability.supportsModelHardware`. */
|
|
29
|
+
function isCompatible(supportedHardware, host) {
|
|
30
|
+
const hw = (supportedHardware ?? "").trim().toLowerCase();
|
|
31
|
+
if (!hw || hw === "cpu" || hw === "any" || hw === "universal")
|
|
32
|
+
return true;
|
|
33
|
+
return host.some((accelerator) => accelerator.toLowerCase() === hw);
|
|
34
|
+
}
|
|
35
|
+
exports.modelsCommand = new commander_1.Command("models")
|
|
36
|
+
.description("Scan the host hardware and report which catalog models it can run")
|
|
37
|
+
.action(async () => {
|
|
38
|
+
await (0, prompts_1.intro)(chalk_1.default.cyan.bold("๐ฅท Sovkora Model Compatibility"));
|
|
39
|
+
const host = hostAccelerators();
|
|
40
|
+
await (0, prompts_1.logInfo)(`Host accelerators: ${chalk_1.default.white(host.join(", "))}`);
|
|
41
|
+
const dbName = process.env.DB_NAME ?? "orazaka_db";
|
|
42
|
+
const dbUser = process.env.DB_USERNAME ?? "orazaka_app";
|
|
43
|
+
const sql = "SELECT category, model_name, COALESCE(supported_hardware,'') " +
|
|
44
|
+
"FROM orazaka_models ORDER BY category, model_name";
|
|
45
|
+
let rows;
|
|
46
|
+
try {
|
|
47
|
+
const out = (0, node_child_process_1.execSync)(`docker exec -i orazaka-db-vector psql -U ${dbUser} -d ${dbName} -t -A -F'|' -c "${sql}"`, {
|
|
48
|
+
encoding: "utf-8",
|
|
49
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
50
|
+
});
|
|
51
|
+
rows = out
|
|
52
|
+
.split("\n")
|
|
53
|
+
.map((line) => line.trim())
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.map((line) => line.split("|"));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
await (0, prompts_1.logWarning)("Could not read orazaka_models โ is the database up? Run `npm run infra`.");
|
|
59
|
+
await (0, prompts_1.outro)(chalk_1.default.red("Compatibility scan aborted."));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let incompatible = 0;
|
|
63
|
+
for (const [category, model, hardware] of rows) {
|
|
64
|
+
const ok = isCompatible(hardware, host);
|
|
65
|
+
if (!ok)
|
|
66
|
+
incompatible++;
|
|
67
|
+
const tag = ok ? chalk_1.default.green("โ run ") : chalk_1.default.red("โ skip");
|
|
68
|
+
const requirement = hardware ? chalk_1.default.gray(`needs ${hardware}`) : chalk_1.default.gray("universal");
|
|
69
|
+
console.log(` ${tag} ${chalk_1.default.dim(category.padEnd(6))} ${model.padEnd(46)} ${requirement}`);
|
|
70
|
+
}
|
|
71
|
+
const summary = incompatible === 0
|
|
72
|
+
? chalk_1.default.green(`All ${String(rows.length)} models run on this host.`)
|
|
73
|
+
: chalk_1.default.yellow(`${String(incompatible)}/${String(rows.length)} model(s) need hardware this host lacks ` +
|
|
74
|
+
`(greyed out in the UI model picker).`);
|
|
75
|
+
await (0, prompts_1.outro)(summary);
|
|
76
|
+
});
|
|
77
|
+
const gb = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
|
|
78
|
+
function catalogueDefault() {
|
|
79
|
+
try {
|
|
80
|
+
return (0, model_catalog_1.defaultImageModel)();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const imageCommand = new commander_1.Command("image").description("Local image models (stable-diffusion.cpp, Metal): list, download, choose the one served");
|
|
87
|
+
imageCommand
|
|
88
|
+
.command("list")
|
|
89
|
+
.description("List the installable image models, their licence, size and whether they are installed")
|
|
90
|
+
.action(async () => {
|
|
91
|
+
await (0, prompts_1.intro)(chalk_1.default.cyan.bold("๐ฅท Sovkora image models"));
|
|
92
|
+
const modelsDir = (0, platform_1.resolveModelsDir)();
|
|
93
|
+
const current = catalogueDefault();
|
|
94
|
+
for (const recipe of image_models_1.IMAGE_MODELS) {
|
|
95
|
+
const installed = (0, image_models_1.isInstalled)(recipe, modelsDir);
|
|
96
|
+
const tag = installed ? chalk_1.default.green("โ installed") : chalk_1.default.gray("โ not pulled");
|
|
97
|
+
const star = recipe.id === current ? chalk_1.default.yellow(" โ
served") : "";
|
|
98
|
+
console.log(` ${tag} ${chalk_1.default.bold(recipe.id.padEnd(22))} ${recipe.label}${star}`);
|
|
99
|
+
console.log(chalk_1.default.gray(` ${recipe.licence} ยท ${gb((0, image_models_1.downloadBytes)(recipe))} on disk ยท ~${String(recipe.ramGb)} GB RAM ยท ${recipe.measured}`));
|
|
100
|
+
console.log(chalk_1.default.gray(` ${recipe.summary}`));
|
|
101
|
+
}
|
|
102
|
+
await (0, prompts_1.outro)(current
|
|
103
|
+
? `The catalogue serves ${chalk_1.default.bold(current)}. Change it with ${chalk_1.default.cyan("sovkora models image use <id>")}.`
|
|
104
|
+
: "Database unreachable: the served model is unknown (npm run infra).");
|
|
105
|
+
});
|
|
106
|
+
imageCommand
|
|
107
|
+
.command("pull")
|
|
108
|
+
.argument("<id>", "Model id (see `sovkora models image list`)")
|
|
109
|
+
.description("Download an image model into ~/models/stable-diffusion and verify its checksums")
|
|
110
|
+
.action(async (id) => {
|
|
111
|
+
const recipe = (0, image_models_1.findImageModel)(id);
|
|
112
|
+
if (!recipe) {
|
|
113
|
+
await (0, prompts_1.logError)(`Unknown image model '${id}'. Known: ${image_models_1.IMAGE_MODELS.map((m) => m.id).join(", ")}`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
await (0, prompts_1.intro)(chalk_1.default.cyan(`Pulling ${recipe.label} (${recipe.licence}, ${gb((0, image_models_1.downloadBytes)(recipe))})`));
|
|
117
|
+
let lastShown = 0;
|
|
118
|
+
try {
|
|
119
|
+
const pulled = await (0, image_models_1.pullImageModel)(recipe, (0, platform_1.resolveModelsDir)(), {
|
|
120
|
+
fetch: (url) => fetch(url),
|
|
121
|
+
onProgress: ({ file, received }) => {
|
|
122
|
+
const now = Date.now();
|
|
123
|
+
if (now - lastShown > 2000 || received === file.bytes) {
|
|
124
|
+
lastShown = now;
|
|
125
|
+
process.stdout.write(`\r ${file.path} ${String(Math.floor((received / file.bytes) * 100))}% `);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
process.stdout.write("\n");
|
|
130
|
+
await (0, prompts_1.logSuccess)(pulled.length === 0
|
|
131
|
+
? "โ Already installed โ nothing to download"
|
|
132
|
+
: `โ ${String(pulled.length)} file(s) downloaded and verified (sha256)`);
|
|
133
|
+
await (0, prompts_1.outro)(`Serve it with ${chalk_1.default.cyan("sovkora models image use " + recipe.id)}, then restart the image server.`);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
await (0, prompts_1.logError)(err instanceof Error ? err.message : String(err));
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
imageCommand
|
|
141
|
+
.command("use")
|
|
142
|
+
.argument("<id>", "Model id (see `sovkora models image list`)")
|
|
143
|
+
.description("Make an installed image model the catalogue's default โ the one `sovkora start` serves")
|
|
144
|
+
.action(async (id) => {
|
|
145
|
+
const recipe = (0, image_models_1.findImageModel)(id);
|
|
146
|
+
if (!recipe) {
|
|
147
|
+
await (0, prompts_1.logError)(`Unknown image model '${id}'.`);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
if (!(0, image_models_1.isInstalled)(recipe, (0, platform_1.resolveModelsDir)())) {
|
|
151
|
+
await (0, prompts_1.logError)(`${recipe.label} is not installed: run sovkora models image pull ${recipe.id}`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
(0, model_catalog_1.setDefaultImageModel)(recipe.id);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
await (0, prompts_1.logError)(err instanceof Error ? err.message : String(err));
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
await (0, prompts_1.logSuccess)(`โ ${recipe.label} is the default image model`);
|
|
162
|
+
await (0, prompts_1.logWarning)("sd-server serves one model at a time: restart the stack (sovkora stop, then sovkora start) to load it.");
|
|
163
|
+
});
|
|
164
|
+
exports.modelsCommand.addCommand(imageCommand);
|