@jiayunxie/aerial 0.2.5 → 0.2.7

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.
@@ -1,19 +0,0 @@
1
- import fs from "node:fs";
2
-
3
- const PACKAGE_JSON_URL = new URL("../../package.json", import.meta.url);
4
-
5
- export function readPackageVersion(packageJsonUrl = PACKAGE_JSON_URL) {
6
- try {
7
- const pkg = JSON.parse(fs.readFileSync(packageJsonUrl, "utf8"));
8
- if (typeof pkg.version === "string" && pkg.version.length > 0) return pkg.version;
9
- throw new Error("missing version field");
10
- } catch (error) {
11
- const reason = error?.message || String(error);
12
- console.warn(`aerial: cannot read package version (${reason}); reporting "unknown"`);
13
- return "unknown";
14
- }
15
- }
16
-
17
- export function printVersion(packageJsonUrl = PACKAGE_JSON_URL) {
18
- console.log(readPackageVersion(packageJsonUrl));
19
- }
@@ -1,20 +0,0 @@
1
- export function aerialRoutes(model) {
2
- return Array.isArray(model?.aerial?.routes) ? model.aerial.routes : [];
3
- }
4
-
5
- export function modelsForRoute(models, route) {
6
- return models
7
- .filter((model) => typeof model?.id === "string" && aerialRoutes(model).includes(route))
8
- .map((model) => ({ id: model.id, routes: aerialRoutes(model), notes: model.aerial?.notes || [] }));
9
- }
10
-
11
- export function usageSummary(payload) {
12
- const usage = payload?.usage || payload?.response?.usage || {};
13
- return {
14
- input: usage.input_tokens ?? usage.prompt_tokens,
15
- output: usage.output_tokens ?? usage.completion_tokens,
16
- cached: usage.input_tokens_details?.cached_tokens
17
- ?? usage.prompt_tokens_details?.cached_tokens
18
- ?? usage.cache_read_input_tokens
19
- };
20
- }
@@ -1,38 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
-
4
- const BACKUP_PREFIX = ".aerial-backup-";
5
- const ISO_STAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/;
6
-
7
- export function backupIfExists(file) {
8
- if (!fs.existsSync(file)) return undefined;
9
- const backup = `${file}.aerial-backup-${new Date().toISOString().replace(/[:.]/g, "-")}`;
10
- fs.copyFileSync(file, backup);
11
- return backup;
12
- }
13
-
14
- function listBackups(file) {
15
- const dir = path.dirname(file);
16
- const base = path.basename(file);
17
- if (!fs.existsSync(dir)) return [];
18
- const prefix = `${base}${BACKUP_PREFIX}`;
19
- const entries = fs.readdirSync(dir);
20
- const matches = [];
21
- for (const entry of entries) {
22
- if (!entry.startsWith(prefix)) continue;
23
- const stamp = entry.slice(prefix.length);
24
- if (!ISO_STAMP_RE.test(stamp)) continue;
25
- matches.push({ name: entry, path: path.join(dir, entry), stamp });
26
- }
27
- matches.sort((a, b) => (a.stamp < b.stamp ? -1 : a.stamp > b.stamp ? 1 : 0));
28
- return matches;
29
- }
30
-
31
- export function findLatestBackup(file) {
32
- const all = listBackups(file);
33
- return all.length ? all[all.length - 1] : undefined;
34
- }
35
-
36
- export function backupPathsFor(file) {
37
- return listBackups(file).map((entry) => entry.path);
38
- }
@@ -1,24 +0,0 @@
1
- import fs from "node:fs";
2
- import { loadConfig } from "../shared/config.js";
3
- import { apiKeyPath, githubTokenPath } from "../shared/paths.js";
4
- import { gitHubTokenSource } from "../shared/auth.js";
5
- import { CLIENTS } from "./clients.js";
6
-
7
- export function setupStatus() {
8
- const config = loadConfig();
9
- const apiKeyFile = apiKeyPath();
10
- const githubTokenFile = githubTokenPath();
11
- return {
12
- schema: "aerial.setup-status.v1",
13
- platform: process.platform,
14
- config: { host: config.host, port: config.port },
15
- auth: {
16
- api_key: { file: apiKeyFile, exists: fs.existsSync(apiKeyFile) },
17
- github_token: (() => {
18
- const source = gitHubTokenSource();
19
- return { file: githubTokenFile, exists: source !== "missing", source };
20
- })()
21
- },
22
- clients: Object.fromEntries(Object.entries(CLIENTS).map(([target, client]) => [target, client.status()]))
23
- };
24
- }
@@ -1,9 +0,0 @@
1
- export async function readJsonSafely(response) {
2
- const text = await response.text();
3
- if (!text) return {};
4
- try {
5
- return JSON.parse(text);
6
- } catch {
7
- return { raw: text };
8
- }
9
- }
@@ -1,8 +0,0 @@
1
- export function parseNumberChoice(value, { max, defaultIndex = 0, oneBased = false } = {}) {
2
- const trimmed = String(value || "").trim();
3
- if (!trimmed) return defaultIndex;
4
- if (!/^\d+$/.test(trimmed)) return undefined;
5
- const n = Number(trimmed);
6
- if (n < 1 || n > max) return undefined;
7
- return oneBased ? n : n - 1;
8
- }