mirror of
https://github.com/Routstr/routstrd.git
synced 2026-08-11 20:47:58 +00:00
added small model and fixed cli init a bit .
This commit is contained in:
+2
-74
@@ -8,8 +8,6 @@ import {
|
||||
loadConfig,
|
||||
} from "./cli-shared";
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
import { readFile, writeFile } from "fs/promises";
|
||||
import { dirname, join } from "path";
|
||||
import {
|
||||
CONFIG_DIR,
|
||||
DB_PATH,
|
||||
@@ -18,8 +16,7 @@ import {
|
||||
type RoutstrdConfig,
|
||||
} from "./utils/config";
|
||||
import { logger } from "./utils/logger";
|
||||
|
||||
const OPENCODE_CONFIG_PATH = join(process.env.HOME || "", ".config/opencode/opencode.json");
|
||||
import { setupIntegration } from "./integrations";
|
||||
|
||||
const cliVersion = "0.1.0";
|
||||
|
||||
@@ -111,7 +108,7 @@ async function initDaemon(): Promise<void> {
|
||||
|
||||
const config = await loadConfig();
|
||||
await startDaemon({ port: String(config.port || 8008) });
|
||||
await installRoutstrModelsInOpencode(config);
|
||||
await setupIntegration(config);
|
||||
|
||||
logger.log("\nInitialization complete!");
|
||||
logger.log(`Run 'routstrd daemon' to start the daemon.`);
|
||||
@@ -130,75 +127,6 @@ async function checkCocodInstalled(): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
async function installRoutstrModelsInOpencode(config: RoutstrdConfig): Promise<void> {
|
||||
logger.log("\nInstalling routstr models in opencode.json...");
|
||||
|
||||
const port = config.port || 8008;
|
||||
|
||||
let opencodeConfig: {
|
||||
provider?: Record<string, {
|
||||
npm?: string;
|
||||
name?: string;
|
||||
options?: {
|
||||
baseURL?: string;
|
||||
apiKey?: string;
|
||||
includeUsage?: boolean;
|
||||
};
|
||||
models?: Record<string, { name: string }>;
|
||||
}>;
|
||||
small_model?: string;
|
||||
};
|
||||
|
||||
try {
|
||||
if (existsSync(OPENCODE_CONFIG_PATH)) {
|
||||
const content = await readFile(OPENCODE_CONFIG_PATH, "utf-8");
|
||||
opencodeConfig = JSON.parse(content);
|
||||
} else {
|
||||
opencodeConfig = { provider: {} };
|
||||
}
|
||||
} catch {
|
||||
opencodeConfig = { provider: {} };
|
||||
}
|
||||
|
||||
if (!opencodeConfig.provider) {
|
||||
opencodeConfig.provider = {};
|
||||
}
|
||||
|
||||
try {
|
||||
mkdirSync(dirname(OPENCODE_CONFIG_PATH), { recursive: true });
|
||||
|
||||
const response = await fetch(`http://localhost:${port}/models`);
|
||||
const data = await response.json() as { output?: { models: string[] } };
|
||||
const models = data.output?.models || [];
|
||||
|
||||
if (models.length === 0) {
|
||||
logger.log("No models found from routstr daemon.");
|
||||
return;
|
||||
}
|
||||
|
||||
const modelsObj: Record<string, { name: string }> = {};
|
||||
for (const model of models) {
|
||||
modelsObj[model] = { name: model };
|
||||
}
|
||||
|
||||
opencodeConfig.provider["routstr"] = {
|
||||
npm: "@ai-sdk/openai-compatible",
|
||||
name: "routstr",
|
||||
options: {
|
||||
baseURL: `http://localhost:${port}/`,
|
||||
apiKey: "",
|
||||
includeUsage: true,
|
||||
},
|
||||
models: modelsObj,
|
||||
};
|
||||
|
||||
await writeFile(OPENCODE_CONFIG_PATH, JSON.stringify(opencodeConfig, null, 2));
|
||||
logger.log(`Added "routstr" provider with ${models.length} models to opencode.json`);
|
||||
} catch (error) {
|
||||
logger.error("Failed to install models in opencode.json:", error);
|
||||
}
|
||||
}
|
||||
|
||||
program
|
||||
.name("routstrd")
|
||||
.description("Routstr daemon - Manage routstr processes")
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { RoutstrdConfig } from "../utils/config";
|
||||
import { logger } from "../utils/logger";
|
||||
import { installOpencodeIntegration } from "./opencode";
|
||||
|
||||
function ask(question: string): Promise<string> {
|
||||
process.stdout.write(question);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.once("data", (data) => {
|
||||
resolve(data.toString().trim());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function parseChoice(input: string): number {
|
||||
if (input === "") {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const parsed = Number.parseInt(input, 10);
|
||||
if (!Number.isNaN(parsed) && parsed >= 1 && parsed <= 3) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
export async function setupIntegration(config: RoutstrdConfig): Promise<void> {
|
||||
logger.log("\nChoose an integration to set up:");
|
||||
logger.log("1. OpenCode (default)");
|
||||
logger.log("2. Skip for now");
|
||||
logger.log("3. Skip for now");
|
||||
|
||||
const answer = await ask("Select integration [1]: ");
|
||||
const choice = parseChoice(answer);
|
||||
|
||||
if (choice === 1) {
|
||||
await installOpencodeIntegration(config);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log("Skipping integration setup.");
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
import { readFile, writeFile } from "fs/promises";
|
||||
import { dirname, join } from "path";
|
||||
import type { RoutstrdConfig } from "../utils/config";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
const OPENCODE_CONFIG_PATH = join(process.env.HOME || "", ".config/opencode/opencode.json");
|
||||
const OPENCODE_SMALL_MODEL = "routstr/minimax-m2.5";
|
||||
|
||||
export async function installOpencodeIntegration(config: RoutstrdConfig): Promise<void> {
|
||||
logger.log("\nInstalling routstr models in opencode.json...");
|
||||
|
||||
const port = config.port || 8008;
|
||||
|
||||
let opencodeConfig: {
|
||||
provider?: Record<string, {
|
||||
npm?: string;
|
||||
name?: string;
|
||||
options?: {
|
||||
baseURL?: string;
|
||||
apiKey?: string;
|
||||
includeUsage?: boolean;
|
||||
};
|
||||
models?: Record<string, { name: string }>;
|
||||
}>;
|
||||
small_model?: string;
|
||||
};
|
||||
|
||||
try {
|
||||
if (existsSync(OPENCODE_CONFIG_PATH)) {
|
||||
const content = await readFile(OPENCODE_CONFIG_PATH, "utf-8");
|
||||
opencodeConfig = JSON.parse(content);
|
||||
} else {
|
||||
opencodeConfig = { provider: {} };
|
||||
}
|
||||
} catch {
|
||||
opencodeConfig = { provider: {} };
|
||||
}
|
||||
|
||||
if (!opencodeConfig.provider) {
|
||||
opencodeConfig.provider = {};
|
||||
}
|
||||
|
||||
try {
|
||||
mkdirSync(dirname(OPENCODE_CONFIG_PATH), { recursive: true });
|
||||
|
||||
const response = await fetch(`http://localhost:${port}/models`);
|
||||
const data = await response.json() as { output?: { models: string[] } };
|
||||
const models = data.output?.models || [];
|
||||
|
||||
if (models.length === 0) {
|
||||
logger.log("No models found from routstr daemon.");
|
||||
return;
|
||||
}
|
||||
|
||||
const modelsObj: Record<string, { name: string }> = {};
|
||||
for (const model of models) {
|
||||
modelsObj[model] = { name: model };
|
||||
}
|
||||
|
||||
opencodeConfig.provider["routstr"] = {
|
||||
npm: "@ai-sdk/openai-compatible",
|
||||
name: "routstr",
|
||||
options: {
|
||||
baseURL: `http://localhost:${port}/`,
|
||||
apiKey: "",
|
||||
includeUsage: true,
|
||||
},
|
||||
models: modelsObj,
|
||||
};
|
||||
opencodeConfig.small_model = OPENCODE_SMALL_MODEL;
|
||||
|
||||
await writeFile(OPENCODE_CONFIG_PATH, JSON.stringify(opencodeConfig, null, 2));
|
||||
logger.log(`Added "routstr" provider with ${models.length} models to opencode.json`);
|
||||
} catch (error) {
|
||||
logger.error("Failed to install models in opencode.json:", error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user