@moonmath-ai/zro 0.2.0 → 0.2.2
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/README.md +24 -4
- package/SECURITY.md +14 -0
- package/dist/catalog.js +4 -1
- package/dist/catalog.js.map +1 -1
- package/dist/engine/constants.d.ts +42 -39
- package/dist/engine/constants.js +44 -36
- package/dist/engine/constants.js.map +1 -1
- package/dist/engine/tools/claude.js +3 -3
- package/dist/engine/tools/claude.js.map +1 -1
- package/dist/engine/tools/codex.js +4 -4
- package/dist/engine/tools/codex.js.map +1 -1
- package/dist/engine/tools/grok.js +4 -4
- package/dist/engine/tools/grok.js.map +1 -1
- package/dist/engine/tools/hermes.js +2 -2
- package/dist/engine/tools/hermes.js.map +1 -1
- package/dist/engine/tools/kilo.d.ts +4 -0
- package/dist/engine/tools/kilo.js +333 -0
- package/dist/engine/tools/kilo.js.map +1 -0
- package/dist/engine/tools/omp.d.ts +5 -0
- package/dist/engine/tools/omp.js +358 -0
- package/dist/engine/tools/omp.js.map +1 -0
- package/dist/engine/tools/openclaw.js +2 -2
- package/dist/engine/tools/openclaw.js.map +1 -1
- package/dist/engine/tools/opencode.js +5 -5
- package/dist/engine/tools/opencode.js.map +1 -1
- package/dist/engine/tools/pi.js +2 -2
- package/dist/engine/tools/pi.js.map +1 -1
- package/dist/engine/tools/prime.d.ts +2 -0
- package/dist/engine/tools/prime.js +119 -0
- package/dist/engine/tools/prime.js.map +1 -0
- package/dist/engine/types.d.ts +3 -0
- package/dist/model-catalog.d.ts +23 -0
- package/dist/model-catalog.js +148 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/run.js +64 -13
- package/dist/run.js.map +1 -1
- package/dist/ui.d.ts +2 -1
- package/dist/ui.js +2 -2
- package/dist/ui.js.map +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { BASE_URL, MCP_URL, PROVIDER_ID, ZRO_ENV_KEY } from "../constants.js";
|
|
3
|
+
import { readConfig } from "../files.js";
|
|
4
|
+
import { jsonSerializer } from "../serializers.js";
|
|
5
|
+
import { asPlainObject, objectAt } from "./helpers.js";
|
|
6
|
+
const PRIME_AGENT_DIR_ENV_KEY = "PRIME_AGENT_CODING_AGENT_DIR";
|
|
7
|
+
const PRIME_MCP_EXTENSION = "npm:pi-mcp-extension@1.5.0";
|
|
8
|
+
const PRIME_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
9
|
+
const PRIME_SUBCOMMANDS = new Set([
|
|
10
|
+
"agents", "attach", "config", "doctor", "help", "list", "model",
|
|
11
|
+
"rename", "schedule", "send", "session", "shutdown", "status", "stop", "update"
|
|
12
|
+
]);
|
|
13
|
+
function primeArgs(model, extraArgs) {
|
|
14
|
+
if (extraArgs[0] && PRIME_SUBCOMMANDS.has(extraArgs[0])) {
|
|
15
|
+
return extraArgs;
|
|
16
|
+
}
|
|
17
|
+
return ["--provider", PROVIDER_ID, "--model", model, "--extension", PRIME_MCP_EXTENSION, ...extraArgs];
|
|
18
|
+
}
|
|
19
|
+
export const primeTool = {
|
|
20
|
+
id: "prime",
|
|
21
|
+
label: "Prime Agent",
|
|
22
|
+
async launch(ctx) {
|
|
23
|
+
const existingAgentDir = process.env[PRIME_AGENT_DIR_ENV_KEY] ?? path.join(ctx.homeDir, ".prime", "agent");
|
|
24
|
+
const tempHome = path.join(ctx.tempDir, "prime", "home");
|
|
25
|
+
const tempAgentDir = path.join(tempHome, ".prime", "agent");
|
|
26
|
+
const filePath = path.join(tempAgentDir, "models.json");
|
|
27
|
+
const mcpConfigPath = path.join(tempAgentDir, "mcp.json");
|
|
28
|
+
const existing = await readConfig(path.join(existingAgentDir, "models.json"), jsonSerializer);
|
|
29
|
+
const nextConfig = buildPrimeModelsConfig(existing, ctx.models);
|
|
30
|
+
return {
|
|
31
|
+
tool: "prime",
|
|
32
|
+
label: "Prime Agent",
|
|
33
|
+
model: ctx.model,
|
|
34
|
+
command: "prime-agent",
|
|
35
|
+
args: primeArgs(ctx.model, ctx.extraArgs),
|
|
36
|
+
env: {
|
|
37
|
+
HOME: tempHome,
|
|
38
|
+
[PRIME_AGENT_DIR_ENV_KEY]: tempAgentDir,
|
|
39
|
+
[ZRO_ENV_KEY]: ctx.apiKey
|
|
40
|
+
},
|
|
41
|
+
files: [
|
|
42
|
+
{
|
|
43
|
+
path: filePath,
|
|
44
|
+
contents: jsonSerializer.stringify(nextConfig)
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
path: mcpConfigPath,
|
|
48
|
+
contents: jsonSerializer.stringify({
|
|
49
|
+
mcpServers: {
|
|
50
|
+
zro: {
|
|
51
|
+
transport: "streamable-http",
|
|
52
|
+
url: MCP_URL,
|
|
53
|
+
lifecycle: "eager",
|
|
54
|
+
headers: { Authorization: `Bearer ${ctx.apiKey}` }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
message: "Launch Prime Agent with Zro"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
function buildPrimeModelsConfig(existing, modelSpecs) {
|
|
65
|
+
const next = { ...existing };
|
|
66
|
+
const providers = objectAt(next, "providers");
|
|
67
|
+
const existingProvider = asPlainObject(providers[PROVIDER_ID]) ?? {};
|
|
68
|
+
const providerModels = Array.isArray(existingProvider.models) ? [...existingProvider.models] : [];
|
|
69
|
+
for (const zroModel of modelSpecs) {
|
|
70
|
+
upsertPrimeModel(providerModels, zroModel);
|
|
71
|
+
}
|
|
72
|
+
providers[PROVIDER_ID] = {
|
|
73
|
+
...existingProvider,
|
|
74
|
+
baseUrl: BASE_URL,
|
|
75
|
+
api: "openai-completions",
|
|
76
|
+
apiKey: ZRO_ENV_KEY,
|
|
77
|
+
headers: {
|
|
78
|
+
...(asPlainObject(existingProvider.headers) ?? {}),
|
|
79
|
+
"User-Agent": "prime-agent"
|
|
80
|
+
},
|
|
81
|
+
compat: {
|
|
82
|
+
...(asPlainObject(existingProvider.compat) ?? {}),
|
|
83
|
+
supportsDeveloperRole: false,
|
|
84
|
+
supportsReasoningEffort: true,
|
|
85
|
+
maxTokensField: "max_tokens"
|
|
86
|
+
},
|
|
87
|
+
models: providerModels
|
|
88
|
+
};
|
|
89
|
+
return next;
|
|
90
|
+
}
|
|
91
|
+
function upsertPrimeModel(models, model) {
|
|
92
|
+
const nextModel = {
|
|
93
|
+
id: model.id,
|
|
94
|
+
name: model.displayName,
|
|
95
|
+
reasoning: true,
|
|
96
|
+
thinkingLevelMap: buildPrimeThinkingLevelMap(model),
|
|
97
|
+
input: ["text"],
|
|
98
|
+
contextWindow: model.contextWindow,
|
|
99
|
+
maxTokens: model.maxOutputTokens
|
|
100
|
+
};
|
|
101
|
+
const index = models.findIndex((entry) => {
|
|
102
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
103
|
+
return false;
|
|
104
|
+
return entry.id === model.id;
|
|
105
|
+
});
|
|
106
|
+
if (index >= 0) {
|
|
107
|
+
models[index] = { ...models[index], ...nextModel };
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
models.push(nextModel);
|
|
111
|
+
}
|
|
112
|
+
function buildPrimeThinkingLevelMap(model) {
|
|
113
|
+
const result = Object.fromEntries(PRIME_THINKING_LEVELS.map((level) => [level, null]));
|
|
114
|
+
for (const level of model.reasoning.levels) {
|
|
115
|
+
result[level.piLevel] = level.id;
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=prime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prime.js","sourceRoot":"","sources":["../../../src/engine/tools/prime.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAiB,WAAW,EAAiB,MAAM,iBAAiB,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ChildProcess } from "node:child_process";
|
|
3
3
|
import type { SUPPORTED_TOOLS } from "./constants.js";
|
|
4
|
+
import type { ZroModel } from "./constants.js";
|
|
4
5
|
export type ToolId = (typeof SUPPORTED_TOOLS)[number];
|
|
5
6
|
export type ApiKeySource = "flag" | "env" | "stored";
|
|
6
7
|
export interface LaunchContext {
|
|
7
8
|
apiKey: string;
|
|
8
9
|
apiKeySource: ApiKeySource;
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
9
11
|
model: string;
|
|
12
|
+
models: readonly ZroModel[];
|
|
10
13
|
extraArgs: string[];
|
|
11
14
|
homeDir: string;
|
|
12
15
|
cwd: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ZroModel } from "./engine/constants.js";
|
|
2
|
+
export interface ModelCatalog {
|
|
3
|
+
version: 1;
|
|
4
|
+
default: string;
|
|
5
|
+
models: readonly ZroModel[];
|
|
6
|
+
}
|
|
7
|
+
type CatalogOptions = {
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
cacheRemote?: boolean;
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
11
|
+
homeDir: string;
|
|
12
|
+
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
13
|
+
};
|
|
14
|
+
export declare class CatalogAuthenticationError extends Error {
|
|
15
|
+
readonly status: number;
|
|
16
|
+
constructor(status: number);
|
|
17
|
+
}
|
|
18
|
+
export declare const BUNDLED_MODEL_CATALOG: ModelCatalog;
|
|
19
|
+
export declare function loadModelCatalog(options: CatalogOptions): Promise<ModelCatalog>;
|
|
20
|
+
export declare function invalidateModelCatalog(options: Pick<CatalogOptions, "env" | "homeDir">): Promise<void>;
|
|
21
|
+
export declare function modelCatalogCachePath(options: Pick<CatalogOptions, "env" | "homeDir">): string;
|
|
22
|
+
export declare function parseModelCatalog(value: unknown): ModelCatalog;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ENDPOINT_ROOT, ZRO_MODELS, DEFAULT_MODEL } from "./engine/constants.js";
|
|
4
|
+
export class CatalogAuthenticationError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
constructor(status) {
|
|
7
|
+
super(`Zro rejected the API key (HTTP ${status}).`);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.name = "CatalogAuthenticationError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const BUNDLED_MODEL_CATALOG = {
|
|
13
|
+
version: 1,
|
|
14
|
+
default: DEFAULT_MODEL,
|
|
15
|
+
models: ZRO_MODELS,
|
|
16
|
+
};
|
|
17
|
+
export async function loadModelCatalog(options) {
|
|
18
|
+
if (options.apiKey) {
|
|
19
|
+
try {
|
|
20
|
+
const catalog = await fetchModelCatalog(options);
|
|
21
|
+
if (options.cacheRemote !== false) {
|
|
22
|
+
await writeCachedCatalog(options, catalog).catch(() => { });
|
|
23
|
+
}
|
|
24
|
+
return catalog;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof CatalogAuthenticationError) {
|
|
28
|
+
await invalidateModelCatalog(options).catch(() => { });
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return await readCachedCatalog(options) ?? BUNDLED_MODEL_CATALOG;
|
|
34
|
+
}
|
|
35
|
+
export async function invalidateModelCatalog(options) {
|
|
36
|
+
try {
|
|
37
|
+
await fs.rm(modelCatalogCachePath(options));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
41
|
+
return;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function modelCatalogCachePath(options) {
|
|
46
|
+
const cacheRoot = options.env.XDG_CACHE_HOME || path.join(options.homeDir, ".cache");
|
|
47
|
+
return path.join(cacheRoot, "zro", "model-catalog.json");
|
|
48
|
+
}
|
|
49
|
+
async function fetchModelCatalog(options) {
|
|
50
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
51
|
+
const endpointRoot = (options.env.ZRO_AUTH_URL || options.env.ZRO_ENDPOINT_ROOT || ENDPOINT_ROOT).replace(/\/+$/, "");
|
|
52
|
+
const response = await fetcher(`${endpointRoot}/api/cli/models`, {
|
|
53
|
+
headers: { Authorization: `Bearer ${options.apiKey}` },
|
|
54
|
+
signal: AbortSignal.timeout(5_000),
|
|
55
|
+
});
|
|
56
|
+
if (response.status === 401 || response.status === 403) {
|
|
57
|
+
await response.body?.cancel().catch(() => { });
|
|
58
|
+
throw new CatalogAuthenticationError(response.status);
|
|
59
|
+
}
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
await response.body?.cancel().catch(() => { });
|
|
62
|
+
throw new Error(`Model catalog request failed with HTTP ${response.status}.`);
|
|
63
|
+
}
|
|
64
|
+
return parseModelCatalog(await response.json());
|
|
65
|
+
}
|
|
66
|
+
async function readCachedCatalog(options) {
|
|
67
|
+
try {
|
|
68
|
+
const contents = await fs.readFile(modelCatalogCachePath(options), "utf8");
|
|
69
|
+
return parseModelCatalog(JSON.parse(contents));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function writeCachedCatalog(options, catalog) {
|
|
76
|
+
const filePath = modelCatalogCachePath(options);
|
|
77
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
78
|
+
const temporaryPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
79
|
+
await fs.writeFile(temporaryPath, `${JSON.stringify(catalog, null, 2)}\n`, { mode: 0o600 });
|
|
80
|
+
await fs.rename(temporaryPath, filePath);
|
|
81
|
+
}
|
|
82
|
+
export function parseModelCatalog(value) {
|
|
83
|
+
const root = asRecord(value, "catalog");
|
|
84
|
+
if (root.version !== 1)
|
|
85
|
+
throw new Error("Unsupported model catalog version.");
|
|
86
|
+
if (!Array.isArray(root.models) || root.models.length === 0) {
|
|
87
|
+
throw new Error("The model catalog is empty.");
|
|
88
|
+
}
|
|
89
|
+
const models = root.models.map(parseModel);
|
|
90
|
+
const ids = new Set(models.map((model) => model.id));
|
|
91
|
+
if (ids.size !== models.length)
|
|
92
|
+
throw new Error("The model catalog contains duplicate IDs.");
|
|
93
|
+
if (typeof root.default !== "string" || !ids.has(root.default)) {
|
|
94
|
+
throw new Error("The model catalog default is invalid.");
|
|
95
|
+
}
|
|
96
|
+
return { version: 1, default: root.default, models };
|
|
97
|
+
}
|
|
98
|
+
function parseModel(value) {
|
|
99
|
+
const model = asRecord(value, "model");
|
|
100
|
+
const reasoning = asRecord(model.reasoning, "model reasoning");
|
|
101
|
+
if (!Array.isArray(reasoning.levels) || reasoning.levels.length === 0) {
|
|
102
|
+
throw new Error("A model has no reasoning levels.");
|
|
103
|
+
}
|
|
104
|
+
const levels = reasoning.levels.map((value) => {
|
|
105
|
+
const level = asRecord(value, "reasoning level");
|
|
106
|
+
const piLevel = requiredString(level.piLevel, "reasoning piLevel");
|
|
107
|
+
if (!["off", "minimal", "low", "medium", "high", "xhigh"].includes(piLevel)) {
|
|
108
|
+
throw new Error("A model has an invalid reasoning piLevel.");
|
|
109
|
+
}
|
|
110
|
+
const openCodeOptions = asRecord(level.openCodeOptions, "reasoning options");
|
|
111
|
+
return {
|
|
112
|
+
id: requiredString(level.id, "reasoning level ID"),
|
|
113
|
+
description: requiredString(level.description, "reasoning description"),
|
|
114
|
+
...(typeof level.codexEffort === "string" ? { codexEffort: level.codexEffort } : {}),
|
|
115
|
+
piLevel: piLevel,
|
|
116
|
+
openCodeOptions,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
const defaultLevel = requiredString(reasoning.defaultLevel, "default reasoning level");
|
|
120
|
+
if (!levels.some((level) => level.id === defaultLevel)) {
|
|
121
|
+
throw new Error("A model has an invalid default reasoning level.");
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
id: requiredString(model.id, "model ID"),
|
|
125
|
+
displayName: requiredString(model.displayName, "model display name"),
|
|
126
|
+
contextWindow: positiveInteger(model.contextWindow, "context window"),
|
|
127
|
+
maxOutputTokens: positiveInteger(model.maxOutputTokens, "max output tokens"),
|
|
128
|
+
reasoning: { defaultLevel, levels },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function asRecord(value, label) {
|
|
132
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
133
|
+
throw new Error(`Invalid ${label}.`);
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function requiredString(value, label) {
|
|
138
|
+
if (typeof value !== "string" || !value.trim())
|
|
139
|
+
throw new Error(`Invalid ${label}.`);
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
function positiveInteger(value, label) {
|
|
143
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
144
|
+
throw new Error(`Invalid ${label}.`);
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=model-catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-catalog.js","sourceRoot":"","sources":["../src/model-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAiB,MAAM,uBAAuB,CAAC;AAgBhG,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACvB;IAA5B,YAA4B,MAAc;QACxC,KAAK,CAAC,kCAAkC,MAAM,IAAI,CAAC,CAAC;QAD1B,WAAM,GAAN,MAAM,CAAQ;QAExC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED,MAAM,CAAC,MAAM,qBAA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Ae,EAAE,mBAAmB,CAAC;QAC5E,SAAS,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE;KACpC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAa;IAC7C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,GAAG,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,KAAa;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,GAAG,CAAC,CAAC;IACrF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,KAAa;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,GAAG,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/run.js
CHANGED
|
@@ -4,19 +4,23 @@ import fsSync from "node:fs";
|
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { ENDPOINT_ROOT, ZRO_ENV_KEY
|
|
7
|
+
import { ENDPOINT_ROOT, ZRO_ENV_KEY } from "./engine/constants.js";
|
|
8
8
|
import { credentialFilePath, deleteStoredApiKey, maskKey, promptHidden, readStoredApiKey, resolveApiKey, writeStoredApiKey } from "./engine/key.js";
|
|
9
9
|
import { claudeTool } from "./engine/tools/claude.js";
|
|
10
10
|
import { codexAppCredentialFilePath, codexAppTool, codexTool, } from "./engine/tools/codex.js";
|
|
11
11
|
import { grokTool } from "./engine/tools/grok.js";
|
|
12
12
|
import { hermesTool } from "./engine/tools/hermes.js";
|
|
13
|
+
import { kiloTool } from "./engine/tools/kilo.js";
|
|
14
|
+
import { ompTool } from "./engine/tools/omp.js";
|
|
13
15
|
import { openClawTool } from "./engine/tools/openclaw.js";
|
|
14
16
|
import { opencodeTool } from "./engine/tools/opencode.js";
|
|
15
17
|
import { piTool } from "./engine/tools/pi.js";
|
|
18
|
+
import { primeTool } from "./engine/tools/prime.js";
|
|
16
19
|
import { parseArgs } from "./args.js";
|
|
17
20
|
import { describeTool, TOOLS } from "./catalog.js";
|
|
18
21
|
import { commandExists, ensureHarnessInstalled, install } from "./install.js";
|
|
19
22
|
import { readPreferences, writePreferences } from "./preferences.js";
|
|
23
|
+
import { CatalogAuthenticationError, invalidateModelCatalog, loadModelCatalog, } from "./model-catalog.js";
|
|
20
24
|
import { banner, chooseConnectMethod, chooseTool, helpText, isTty, modelName, theme } from "./ui.js";
|
|
21
25
|
const tools = {
|
|
22
26
|
claude: claudeTool,
|
|
@@ -24,9 +28,12 @@ const tools = {
|
|
|
24
28
|
"codex-app": codexAppTool,
|
|
25
29
|
grok: grokTool,
|
|
26
30
|
hermes: hermesTool,
|
|
31
|
+
kilo: kiloTool,
|
|
32
|
+
omp: ompTool,
|
|
27
33
|
openclaw: openClawTool,
|
|
28
34
|
opencode: opencodeTool,
|
|
29
|
-
pi: piTool
|
|
35
|
+
pi: piTool,
|
|
36
|
+
prime: primeTool
|
|
30
37
|
};
|
|
31
38
|
const PACKAGE_VERSION = JSON.parse(fsSync.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
32
39
|
export async function run(argv, io = defaultIo()) {
|
|
@@ -63,7 +70,7 @@ export async function run(argv, io = defaultIo()) {
|
|
|
63
70
|
if (request.command === "status")
|
|
64
71
|
return status(request.output, io, env, colors);
|
|
65
72
|
if (request.command === "models")
|
|
66
|
-
return models(request.output, io, colors);
|
|
73
|
+
return models(request.output, io, env, colors);
|
|
67
74
|
if (request.command === "home") {
|
|
68
75
|
if (!isTty(io.stdin) || !isTty(io.stdout)) {
|
|
69
76
|
io.stdout.write(helpText(colors));
|
|
@@ -109,11 +116,6 @@ export async function run(argv, io = defaultIo()) {
|
|
|
109
116
|
return launch(request, io, env, colors);
|
|
110
117
|
}
|
|
111
118
|
async function launch(request, io, env, colors) {
|
|
112
|
-
const model = request.model ?? DEFAULT_MODEL;
|
|
113
|
-
if (!ZRO_MODELS.some((candidate) => candidate.id === model)) {
|
|
114
|
-
io.stderr.write(`Unknown model "${model}". Run zro models.\n`);
|
|
115
|
-
return 1;
|
|
116
|
-
}
|
|
117
119
|
let key;
|
|
118
120
|
try {
|
|
119
121
|
key = await resolveApiKey({ flagValue: request.apiKey, env, homeDir: io.homeDir });
|
|
@@ -143,6 +145,29 @@ async function launch(request, io, env, colors) {
|
|
|
143
145
|
if (request.apiKey) {
|
|
144
146
|
io.stderr.write(`Note: --api-key can land in shell history. Prefer zro login or ${ZRO_ENV_KEY}.\n`);
|
|
145
147
|
}
|
|
148
|
+
let catalog;
|
|
149
|
+
try {
|
|
150
|
+
catalog = await loadModelCatalog({
|
|
151
|
+
apiKey: key.apiKey,
|
|
152
|
+
env,
|
|
153
|
+
homeDir: io.homeDir,
|
|
154
|
+
fetch: io.fetch,
|
|
155
|
+
cacheRemote: !request.dryRun,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (error instanceof CatalogAuthenticationError) {
|
|
160
|
+
io.stderr.write(`Authentication failed: ${error.message} Run zro login --manual with a valid API key. Agent was not started.\n`);
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
163
|
+
io.stderr.write(`Could not load the Zro model catalog: ${messageOf(error)}\n`);
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
166
|
+
const model = request.model ?? catalog.default;
|
|
167
|
+
if (!catalog.models.some((candidate) => candidate.id === model)) {
|
|
168
|
+
io.stderr.write(`Unknown model "${model}". Run zro models.\n`);
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
146
171
|
const tempRoot = path.join(env.XDG_CACHE_HOME || path.join(io.homeDir, ".cache"), "zro", "sessions");
|
|
147
172
|
const tempDir = path.join(tempRoot, `session-${process.pid}-${Date.now()}`);
|
|
148
173
|
let plan;
|
|
@@ -150,7 +175,9 @@ async function launch(request, io, env, colors) {
|
|
|
150
175
|
plan = await tools[request.tool].launch({
|
|
151
176
|
apiKey: key.apiKey,
|
|
152
177
|
apiKeySource: key.source,
|
|
178
|
+
env,
|
|
153
179
|
model,
|
|
180
|
+
models: catalog.models,
|
|
154
181
|
extraArgs: request.extraArgs,
|
|
155
182
|
homeDir: io.homeDir,
|
|
156
183
|
cwd: io.cwd,
|
|
@@ -184,7 +211,7 @@ async function launch(request, io, env, colors) {
|
|
|
184
211
|
}
|
|
185
212
|
if (request.output === "human" && isTty(io.stdout)) {
|
|
186
213
|
io.stdout.write(`${colors.accent("◆")} ${colors.strong(describeTool(request.tool).name)} ` +
|
|
187
|
-
`${colors.muted(`${modelName(model)} · ${model}`)}\n` +
|
|
214
|
+
`${colors.muted(`${modelName(model, catalog.models)} · ${model}`)}\n` +
|
|
188
215
|
`${colors.muted(` ${compactPath(io.cwd, io.homeDir)}`)}\n\n`);
|
|
189
216
|
}
|
|
190
217
|
try {
|
|
@@ -224,6 +251,7 @@ async function verifyApiKey(apiKey, io, env) {
|
|
|
224
251
|
if (response.ok)
|
|
225
252
|
return true;
|
|
226
253
|
if (status === 401 || status === 403) {
|
|
254
|
+
await invalidateModelCatalog({ env, homeDir: io.homeDir }).catch(() => { });
|
|
227
255
|
io.stderr.write(`Authentication failed: Zro rejected the API key (HTTP ${status}). ` +
|
|
228
256
|
`Run zro login --manual with a valid API key. Agent was not started.\n`);
|
|
229
257
|
return false;
|
|
@@ -389,6 +417,7 @@ async function logout(output, io, env) {
|
|
|
389
417
|
const [storedKeyRemoved, codexAppKeyRemoved] = await Promise.all([
|
|
390
418
|
deleteStoredApiKey({ homeDir: io.homeDir, env }),
|
|
391
419
|
deleteOptionalFile(codexAppCredentialFilePath(io.homeDir)),
|
|
420
|
+
invalidateModelCatalog({ homeDir: io.homeDir, env }),
|
|
392
421
|
]);
|
|
393
422
|
const removed = storedKeyRemoved || codexAppKeyRemoved;
|
|
394
423
|
io.stdout.write(output === "json"
|
|
@@ -427,6 +456,9 @@ async function status(output, io, env, colors) {
|
|
|
427
456
|
: Promise.resolve({ state: "not_connected" }),
|
|
428
457
|
]);
|
|
429
458
|
const connected = source !== "none" && accountResult.state !== "rejected";
|
|
459
|
+
if (accountResult.state === "rejected") {
|
|
460
|
+
await invalidateModelCatalog({ homeDir: io.homeDir, env }).catch(() => { });
|
|
461
|
+
}
|
|
430
462
|
if (output === "json") {
|
|
431
463
|
io.stdout.write(`${JSON.stringify({
|
|
432
464
|
connected,
|
|
@@ -550,14 +582,33 @@ function money(value, currency) {
|
|
|
550
582
|
function formatInteger(value) {
|
|
551
583
|
return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(value);
|
|
552
584
|
}
|
|
553
|
-
function models(output, io, colors) {
|
|
585
|
+
async function models(output, io, env, colors) {
|
|
586
|
+
let apiKey;
|
|
587
|
+
try {
|
|
588
|
+
apiKey = (await resolveApiKey({ env, homeDir: io.homeDir })).apiKey;
|
|
589
|
+
}
|
|
590
|
+
catch {
|
|
591
|
+
// A cached or bundled catalog remains useful before the user signs in.
|
|
592
|
+
}
|
|
593
|
+
let catalog;
|
|
594
|
+
try {
|
|
595
|
+
catalog = await loadModelCatalog({ apiKey, env, homeDir: io.homeDir, fetch: io.fetch });
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
if (error instanceof CatalogAuthenticationError) {
|
|
599
|
+
io.stderr.write(`Authentication failed: ${error.message} Run zro login --manual with a valid API key.\n`);
|
|
600
|
+
return 1;
|
|
601
|
+
}
|
|
602
|
+
io.stderr.write(`Could not load the Zro model catalog: ${messageOf(error)}\n`);
|
|
603
|
+
return 1;
|
|
604
|
+
}
|
|
554
605
|
if (output === "json") {
|
|
555
|
-
io.stdout.write(`${JSON.stringify(
|
|
606
|
+
io.stdout.write(`${JSON.stringify(catalog, null, 2)}\n`);
|
|
556
607
|
return 0;
|
|
557
608
|
}
|
|
558
609
|
io.stdout.write(`${banner(colors)}\n\nModels\n`);
|
|
559
|
-
for (const model of
|
|
560
|
-
const isDefault = model.id ===
|
|
610
|
+
for (const model of catalog.models) {
|
|
611
|
+
const isDefault = model.id === catalog.default;
|
|
561
612
|
io.stdout.write(`\n ${isDefault ? colors.accent("◆") : colors.muted("◇")} ${colors.strong(model.displayName)} ${colors.muted(model.id)}${isDefault ? colors.accent(" default") : ""}\n`);
|
|
562
613
|
io.stdout.write(` ${formatTokens(model.contextWindow)} context · ${formatTokens(model.maxOutputTokens)} max output · ${model.reasoning.levels.map((level) => level.id).join(" / ")}\n`);
|
|
563
614
|
}
|