@ngosangns/ns-bridge 0.1.20 → 0.1.22
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 +7 -0
- package/dist/arnict.d.ts +30 -0
- package/dist/arnict.js +288 -0
- package/dist/arnict.js.map +1 -0
- package/dist/catalog.d.ts +9 -1
- package/dist/catalog.js +9 -3
- package/dist/catalog.js.map +1 -1
- package/dist/cli.d.ts +16 -0
- package/dist/cli.js +170 -12
- package/dist/cli.js.map +1 -1
- package/dist/providers.d.ts +5 -4
- package/dist/providers.js +9 -6
- package/dist/providers.js.map +1 -1
- package/dist/refresh-entry.js +86075 -85725
- package/dist/refresh.d.ts +1 -0
- package/dist/refresh.js.map +1 -1
- package/dist/selection.d.ts +3 -3
- package/dist/selection.js +7 -7
- package/dist/selection.js.map +1 -1
- package/dist/serve-entry.js +10917 -0
- package/dist/serve.d.ts +42 -0
- package/dist/serve.js +99 -0
- package/dist/serve.js.map +1 -0
- package/dist/usage.d.ts +3 -0
- package/dist/usage.js +8 -1
- package/dist/usage.js.map +1 -1
- package/dist/zcode-config.d.ts +17 -0
- package/dist/zcode-config.js +55 -0
- package/dist/zcode-config.js.map +1 -0
- package/dist/zcode.d.ts +235 -0
- package/dist/zcode.js +824 -0
- package/dist/zcode.js.map +1 -0
- package/package.json +6 -1
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ns-bridge serve` — a local Anthropic-Messages server ZCode points an
|
|
3
|
+
* Anthropic client at, with one mount per vendor core. The cores live in the
|
|
4
|
+
* esbuild bundle (serve-entry.js), loaded through a variable specifier exactly
|
|
5
|
+
* like refresh.ts does, so importing this module never loads them.
|
|
6
|
+
*/
|
|
7
|
+
import type { Server } from "node:http";
|
|
8
|
+
import type { AnthropicBackend } from "ns-bridge-core/anthropic";
|
|
9
|
+
export type ServeVendor = "kiro" | "devin" | "grok" | "arnict";
|
|
10
|
+
/** The surface of the serve bundle this module needs; matches serve-entry.ts. */
|
|
11
|
+
export interface ServeBundle {
|
|
12
|
+
createBundledBackends: () => Record<ServeVendor, AnthropicBackend>;
|
|
13
|
+
createAnthropicServer: (options: {
|
|
14
|
+
backends: Record<string, AnthropicBackend>;
|
|
15
|
+
token?: string;
|
|
16
|
+
log?: (line: string) => void;
|
|
17
|
+
}) => Server;
|
|
18
|
+
setUsageHost: (host: string) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface RunServeOptions {
|
|
21
|
+
port?: number;
|
|
22
|
+
host?: string;
|
|
23
|
+
/** Overrides the config file and NS_BRIDGE_SERVE_TOKEN. */
|
|
24
|
+
token?: string;
|
|
25
|
+
/** Permit a non-loopback bind. Off by default; the CLI passes --allow-remote. */
|
|
26
|
+
allowRemote?: boolean;
|
|
27
|
+
log?: (line: string) => void;
|
|
28
|
+
err?: (line: string) => void;
|
|
29
|
+
/** Resolves the run when it aborts; without one, SIGINT/SIGTERM stop the run. */
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/** Tests inject a fake so no vendor core loads. */
|
|
32
|
+
loadBundle?: () => Promise<ServeBundle>;
|
|
33
|
+
/** Tests point this at a temp dir so the real config file is never touched. */
|
|
34
|
+
configPath?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function isLoopbackHost(host: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A variable specifier so typecheck does not follow the esbuild bundle, which
|
|
39
|
+
* pulls in the vendor cores. The file exists only after `pnpm build`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadServeBundle(): Promise<ServeBundle>;
|
|
42
|
+
export declare function runServe(options?: RunServeOptions): Promise<number>;
|
package/dist/serve.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ns-bridge serve` — a local Anthropic-Messages server ZCode points an
|
|
3
|
+
* Anthropic client at, with one mount per vendor core. The cores live in the
|
|
4
|
+
* esbuild bundle (serve-entry.js), loaded through a variable specifier exactly
|
|
5
|
+
* like refresh.ts does, so importing this module never loads them.
|
|
6
|
+
*/
|
|
7
|
+
import { ensureZcodeServeConfig, zcodeConfigPath } from "./zcode-config.js";
|
|
8
|
+
export function isLoopbackHost(host) {
|
|
9
|
+
const normalized = host.trim().toLowerCase().replace(/^\[/, "").replace(/\]$/, "");
|
|
10
|
+
if (normalized === "localhost" || normalized === "::1" || normalized === "::ffff:127.0.0.1")
|
|
11
|
+
return true;
|
|
12
|
+
// A bare dotted quad only: `127.0.0.1.evil.com` is a hostname that may not
|
|
13
|
+
// resolve where the bind expects it to.
|
|
14
|
+
return /^127(\.\d{1,3}){3}$/.test(normalized);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A variable specifier so typecheck does not follow the esbuild bundle, which
|
|
18
|
+
* pulls in the vendor cores. The file exists only after `pnpm build`.
|
|
19
|
+
*/
|
|
20
|
+
export async function loadServeBundle() {
|
|
21
|
+
const specifier = "./serve-entry.js";
|
|
22
|
+
return (await import(specifier));
|
|
23
|
+
}
|
|
24
|
+
export async function runServe(options = {}) {
|
|
25
|
+
const log = options.log ?? ((line) => console.log(line));
|
|
26
|
+
const err = options.err ?? ((line) => console.error(line));
|
|
27
|
+
const host = options.host ?? "127.0.0.1";
|
|
28
|
+
if (!isLoopbackHost(host) && !options.allowRemote) {
|
|
29
|
+
err(`refusing to serve on ${host}: not a loopback address (pass --allow-remote to bind it anyway)`);
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
const config = ensureZcodeServeConfig(options.configPath ?? zcodeConfigPath());
|
|
33
|
+
const token = options.token ?? (process.env.NS_BRIDGE_SERVE_TOKEN?.trim() || config.token);
|
|
34
|
+
const port = options.port ?? config.port;
|
|
35
|
+
const load = options.loadBundle ?? loadServeBundle;
|
|
36
|
+
let bundle;
|
|
37
|
+
try {
|
|
38
|
+
bundle = await load();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
err(`serve: could not load the provider bundle: ${error instanceof Error ? error.message : String(error)}`);
|
|
42
|
+
err("run pnpm build so dist/serve-entry.js exists");
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
bundle.setUsageHost("zcode");
|
|
46
|
+
const server = bundle.createAnthropicServer({
|
|
47
|
+
backends: bundle.createBundledBackends(),
|
|
48
|
+
token,
|
|
49
|
+
log,
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
await listen(server, port, host);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
err(`serve: could not listen on ${host}:${port}: ${error instanceof Error ? error.message : String(error)}`);
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
const bound = server.address();
|
|
59
|
+
const boundPort = typeof bound === "object" && bound !== null ? bound.port : port;
|
|
60
|
+
log(`ns-bridge serve listening on http://${host}:${boundPort} (kiro, devin, grok, arnict)`);
|
|
61
|
+
await stopSignal(options.signal);
|
|
62
|
+
await close(server);
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
function listen(server, port, host) {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
server.once("error", reject);
|
|
68
|
+
server.listen(port, host, () => {
|
|
69
|
+
server.off("error", reject);
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** Without an injected signal the run stops on SIGINT/SIGTERM like a daemon. */
|
|
75
|
+
function stopSignal(signal) {
|
|
76
|
+
if (signal) {
|
|
77
|
+
if (signal.aborted)
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
return new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
80
|
+
}
|
|
81
|
+
return new Promise((resolve) => {
|
|
82
|
+
const stop = () => {
|
|
83
|
+
process.off("SIGINT", stop);
|
|
84
|
+
process.off("SIGTERM", stop);
|
|
85
|
+
resolve();
|
|
86
|
+
};
|
|
87
|
+
process.on("SIGINT", stop);
|
|
88
|
+
process.on("SIGTERM", stop);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** A shut-down serve drops idle keep-alive sockets and any in-flight stream. */
|
|
92
|
+
function close(server) {
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
server.close(() => resolve());
|
|
95
|
+
server.closeIdleConnections?.();
|
|
96
|
+
server.closeAllConnections?.();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAgC5E,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnF,IAAI,UAAU,KAAK,WAAW,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,kBAAkB;QAAE,OAAO,IAAI,CAAC;IACzG,2EAA2E;IAC3E,wCAAwC;IACxC,OAAO,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,SAAS,GAAG,kBAAkB,CAAC;IACrC,OAAO,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAgB,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,UAA2B,EAAE;IAC1D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,OAAO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,EAAE,CAAC;QAC7C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC7B,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;QACF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,gFAAgF;AAChF,SAAS,KAAK,CAAC,MAAc;IAC3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,oBAAoB,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,mBAAmB,EAAE,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/usage.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ export interface UsageLine {
|
|
|
25
25
|
cacheHitMax?: number;
|
|
26
26
|
contextFill?: number;
|
|
27
27
|
effort?: string;
|
|
28
|
+
/** What the provider billed for the step, denominated in `creditUnit` (arnict: "USD"). */
|
|
29
|
+
credits?: number;
|
|
30
|
+
creditUnit?: string;
|
|
28
31
|
}
|
|
29
32
|
export interface UsageQuery {
|
|
30
33
|
/** Newest N day folders. Ignored when `day` is set, or when `session` is set without `days`. */
|
package/dist/usage.js
CHANGED
|
@@ -146,6 +146,12 @@ function gap(ms) {
|
|
|
146
146
|
const seconds = Math.round(ms / 1000);
|
|
147
147
|
return seconds < 120 ? `${seconds}s` : `${Math.round(seconds / 60)}m`;
|
|
148
148
|
}
|
|
149
|
+
/** A USD bill reads as dollars; other units stay bare numbers so two units are never summed or confused. */
|
|
150
|
+
function cost(record) {
|
|
151
|
+
if (record.credits === undefined)
|
|
152
|
+
return "-";
|
|
153
|
+
return record.creditUnit === "USD" ? `$${record.credits}` : String(record.credits);
|
|
154
|
+
}
|
|
149
155
|
function pad(columns, widths) {
|
|
150
156
|
const sizes = widths ?? columns[0]?.map((_, index) => Math.max(...columns.map((row) => (row[index] ?? "").length))) ?? [];
|
|
151
157
|
return columns.map((row) => row
|
|
@@ -187,7 +193,7 @@ export function formatSession(records) {
|
|
|
187
193
|
if (records.length === 0)
|
|
188
194
|
return ["no usage recorded for that session"];
|
|
189
195
|
const table = [
|
|
190
|
-
["step", "vendor", "model", "prompt", "hit", "gap", "ctx"],
|
|
196
|
+
["step", "vendor", "model", "prompt", "hit", "gap", "ctx", "cost"],
|
|
191
197
|
...records.map((record, index) => [
|
|
192
198
|
String(record.step ?? index + 1),
|
|
193
199
|
record.vendor,
|
|
@@ -200,6 +206,7 @@ export function formatSession(records) {
|
|
|
200
206
|
: percent(record.cacheHitRatio),
|
|
201
207
|
gap(record.gapMs),
|
|
202
208
|
percent(record.contextFill),
|
|
209
|
+
cost(record),
|
|
203
210
|
]),
|
|
204
211
|
];
|
|
205
212
|
return pad(table);
|
package/dist/usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC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,MAAM,CAAC;SACb,CAAC;KACH,CAAC;IACF,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token and port for `ns-bridge serve`, kept in ~/.ns-bridge/zcode.json so
|
|
3
|
+
* ZCode and the server agree without them passing anything on a command line.
|
|
4
|
+
* The file is created once and then only read — a rewrite would silently
|
|
5
|
+
* rotate the token out from under a configured client.
|
|
6
|
+
*/
|
|
7
|
+
export interface ZcodeServeConfig {
|
|
8
|
+
port: number;
|
|
9
|
+
token: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_ZCODE_PORT = 47821;
|
|
12
|
+
/** `NS_BRIDGE_ZCODE_CONFIG` moves the file; the default lives in ~/.ns-bridge. */
|
|
13
|
+
export declare function zcodeConfigPath(env?: NodeJS.ProcessEnv): string;
|
|
14
|
+
/** Parse the file, or undefined when it is missing, unreadable, or incomplete. */
|
|
15
|
+
export declare function readZcodeServeConfig(path: string): ZcodeServeConfig | undefined;
|
|
16
|
+
/** Read the config, creating it first when missing or unusable. */
|
|
17
|
+
export declare function ensureZcodeServeConfig(path: string): ZcodeServeConfig;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token and port for `ns-bridge serve`, kept in ~/.ns-bridge/zcode.json so
|
|
3
|
+
* ZCode and the server agree without them passing anything on a command line.
|
|
4
|
+
* The file is created once and then only read — a rewrite would silently
|
|
5
|
+
* rotate the token out from under a configured client.
|
|
6
|
+
*/
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
export const DEFAULT_ZCODE_PORT = 47821;
|
|
12
|
+
/** `NS_BRIDGE_ZCODE_CONFIG` moves the file; the default lives in ~/.ns-bridge. */
|
|
13
|
+
export function zcodeConfigPath(env = process.env) {
|
|
14
|
+
const override = env.NS_BRIDGE_ZCODE_CONFIG?.trim();
|
|
15
|
+
if (override)
|
|
16
|
+
return override;
|
|
17
|
+
return join(homedir(), ".ns-bridge", "zcode.json");
|
|
18
|
+
}
|
|
19
|
+
/** Parse the file, or undefined when it is missing, unreadable, or incomplete. */
|
|
20
|
+
export function readZcodeServeConfig(path) {
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = readFileSync(path, "utf8");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
let parsed;
|
|
29
|
+
try {
|
|
30
|
+
parsed = JSON.parse(raw);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
36
|
+
return undefined;
|
|
37
|
+
const { port, token } = parsed;
|
|
38
|
+
if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (typeof token !== "string" || token.length === 0)
|
|
41
|
+
return undefined;
|
|
42
|
+
return { port, token };
|
|
43
|
+
}
|
|
44
|
+
/** Read the config, creating it first when missing or unusable. */
|
|
45
|
+
export function ensureZcodeServeConfig(path) {
|
|
46
|
+
const existing = readZcodeServeConfig(path);
|
|
47
|
+
if (existing)
|
|
48
|
+
return existing;
|
|
49
|
+
const config = { port: DEFAULT_ZCODE_PORT, token: randomBytes(24).toString("hex") };
|
|
50
|
+
// The directory and the file are secrets, not just their contents.
|
|
51
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
52
|
+
writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
53
|
+
return config;
|
|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C7F,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAiC,CAAC;IAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,SAAS,CAAC;IACtG,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACtE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,MAAM,GAAqB,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACtG,mEAAmE;IACnE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/zcode.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ns-bridge zcode setup|status|remove` — register the ns-bridge serve
|
|
3
|
+
* endpoints as personal providers in the ZCode app.
|
|
4
|
+
*
|
|
5
|
+
* ZCode stores personal providers in ~/.zcode/v2/provider_config.json and
|
|
6
|
+
* keeps that file in memory while the desktop app runs, so an edit while it
|
|
7
|
+
* runs is lost on the app's next save. setup and remove refuse --apply while
|
|
8
|
+
* ZCode runs unless --force. The file can hold other providers' entries and
|
|
9
|
+
* secrets, so its contents are never printed — only ids and counts we own.
|
|
10
|
+
*
|
|
11
|
+
* On darwin setup also installs a launchd agent that keeps `ns-bridge serve`
|
|
12
|
+
* running, pinned to the globally installed CLI when one is on PATH and to
|
|
13
|
+
* this checkout otherwise.
|
|
14
|
+
*/
|
|
15
|
+
import { type CatalogEntry, type CatalogPaths, type CatalogReport, type Vendor } from "./catalog.js";
|
|
16
|
+
import type { Runner } from "./cli.js";
|
|
17
|
+
/** Every provider id we write starts with this; anything else in the file is left alone. */
|
|
18
|
+
export declare const PROVIDER_ID_PREFIX = "ns-bridge-";
|
|
19
|
+
export declare const ZCODE_LAUNCH_AGENT_LABEL = "dev.ngosangns.ns-bridge.serve";
|
|
20
|
+
export declare function zcodeProviderConfigPath(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
21
|
+
export declare function launchAgentPlistPath(home: string): string;
|
|
22
|
+
export declare function serveLogPath(home: string): string;
|
|
23
|
+
export interface ZcodeModelWindow {
|
|
24
|
+
/** The contextWindow ZCode should see so it compacts near the catalog threshold. */
|
|
25
|
+
window: number;
|
|
26
|
+
maxOutputTokens: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Arnict's GLM 5.3 compaction policy, copied from ns-arnict-core for the same
|
|
30
|
+
* reason kiro's is copied above: every id the `zai/glm-5.3` prefix covers runs
|
|
31
|
+
* in the vendor's 400K agentic standard window, compacting with the shared
|
|
32
|
+
* 16,384 reserve, while Arnict serves those ids against a native 1,048,576
|
|
33
|
+
* window. `arnictGlm53Id` mirrors isArnictGlm53Id.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ARNICT_GLM_STANDARD_CONTEXT_WINDOW = 400000;
|
|
36
|
+
export declare function arnictGlm53Id(id: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Where ns-bridge's per-model policy compacts a model whose catalog recorded
|
|
39
|
+
* no threshold. Kiro: a Claude model with a window past 200K compacts at the
|
|
40
|
+
* 150K target; everything else compacts where the OMP provider's default rule
|
|
41
|
+
* lands on the model's standard-price window — OMP holds back
|
|
42
|
+
* max(floor(0.15·W), 16384) of a window W (omp-provider-kiro models.ts
|
|
43
|
+
* `ompWindowForThreshold`) — so ZCode compacts where OMP does: 170000 at 200K,
|
|
44
|
+
* 231200 at the 272K GPT-5.6 tier. The other vendors' cores record the window
|
|
45
|
+
* minus its 16384 reservation (ns-core-utils `compactionBudget`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function derivedThresholdTokens(vendor: Vendor, entry: CatalogEntry & {
|
|
48
|
+
contextWindow: number;
|
|
49
|
+
}): number;
|
|
50
|
+
/**
|
|
51
|
+
* ZCode compacts at W - min(min(maxOutputTokens ?? 32000, 21000), W) - 13000
|
|
52
|
+
* for a reported window W. Reporting W = threshold + 13000 +
|
|
53
|
+
* min(maxOutputTokens, 21000), capped at the real window, lands the
|
|
54
|
+
* compaction on the threshold the catalog recorded — or, when it recorded
|
|
55
|
+
* none, where ns-bridge's per-model policy for the vendor compacts. The real
|
|
56
|
+
* window is the catalog's maxContextWindow when it recorded one (arnict's
|
|
57
|
+
* native window), else the GLM 5.3 native window for a glm-5.3 id, else the
|
|
58
|
+
* window the compaction runs in.
|
|
59
|
+
*/
|
|
60
|
+
export declare function zcodeModelWindow(entry: CatalogEntry & {
|
|
61
|
+
contextWindow: number;
|
|
62
|
+
}, vendor: Vendor): ZcodeModelWindow;
|
|
63
|
+
export declare function supportsImage(entry: CatalogEntry): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Reasoning levels every model rule publishes — the BridgeEffort vocabulary
|
|
66
|
+
* the anthropic-messages bridge maps via toBridgeEffort (bridge-core
|
|
67
|
+
* effort.ts accepts each of them). ZCode ignores a defaultModelSelection
|
|
68
|
+
* whose options.reasoningLevel is missing from the selected model's values,
|
|
69
|
+
* so the rules must carry them explicitly.
|
|
70
|
+
*/
|
|
71
|
+
export declare const ZCODE_REASONING_LEVELS: readonly string[];
|
|
72
|
+
/** The level --default pins in defaultModelSelection; always in ZCODE_REASONING_LEVELS. */
|
|
73
|
+
export declare const ZCODE_DEFAULT_REASONING_LEVEL = "high";
|
|
74
|
+
export interface ZcodeModelRule {
|
|
75
|
+
providerId: string;
|
|
76
|
+
modelId: string;
|
|
77
|
+
config: {
|
|
78
|
+
properties: {
|
|
79
|
+
contextWindow: number;
|
|
80
|
+
inputFormat: {
|
|
81
|
+
supportsImage: boolean;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
optionSpecs: {
|
|
85
|
+
maxOutputTokens: {
|
|
86
|
+
max: number;
|
|
87
|
+
};
|
|
88
|
+
reasoningLevel: {
|
|
89
|
+
values: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export interface ZcodeProviderPlan {
|
|
95
|
+
vendor: Vendor;
|
|
96
|
+
providerId: string;
|
|
97
|
+
providerName: string;
|
|
98
|
+
baseUrl: string;
|
|
99
|
+
apiKey: string;
|
|
100
|
+
modelIds: string[];
|
|
101
|
+
modelRules: ZcodeModelRule[];
|
|
102
|
+
/** Catalog entries left out for lacking a context window. */
|
|
103
|
+
skippedModels: string[];
|
|
104
|
+
}
|
|
105
|
+
export interface ZcodePlan {
|
|
106
|
+
providers: ZcodeProviderPlan[];
|
|
107
|
+
skipped: {
|
|
108
|
+
vendor: Vendor;
|
|
109
|
+
reason: string;
|
|
110
|
+
}[];
|
|
111
|
+
}
|
|
112
|
+
/** One plan per ready catalog; catalogs that are missing or empty are skipped with a reason. */
|
|
113
|
+
export declare function planZcodeProviders(catalogs: readonly CatalogReport[], serve: {
|
|
114
|
+
port: number;
|
|
115
|
+
token: string;
|
|
116
|
+
}): ZcodePlan;
|
|
117
|
+
export interface ZcodeMergeOptions {
|
|
118
|
+
/**
|
|
119
|
+
* From --default <vendor>/<model>: replaces defaultModelSelection, carrying
|
|
120
|
+
* the reasoning level ZCode requires for the selection to take effect.
|
|
121
|
+
*/
|
|
122
|
+
defaultModel?: {
|
|
123
|
+
providerId: string;
|
|
124
|
+
modelId: string;
|
|
125
|
+
options?: {
|
|
126
|
+
reasoningLevel: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* ns-bridge provider ids whose existing entries stay as-is. setup passes the
|
|
131
|
+
* vendors whose catalog was skipped, so a missing catalog does not unregister
|
|
132
|
+
* a provider that still works.
|
|
133
|
+
*/
|
|
134
|
+
keepProviderIds?: string[];
|
|
135
|
+
}
|
|
136
|
+
export interface ZcodeMergeResult {
|
|
137
|
+
json: Record<string, unknown>;
|
|
138
|
+
changed: boolean;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Idempotent merge of the ns-bridge providers into ZCode's provider config.
|
|
142
|
+
* Re-registered providers replace their old entries at the same position, ids
|
|
143
|
+
* named by keepProviderIds keep their existing provider, model, and manual
|
|
144
|
+
* model entries and their providerOrder slot untouched, and stale ns-bridge-*
|
|
145
|
+
* entries are dropped, so running it twice changes nothing the second time.
|
|
146
|
+
* Unknown keys and other providers' entries pass through untouched;
|
|
147
|
+
* defaultModelSelection is only touched when mergeOptions names one. An
|
|
148
|
+
* undefined `existing` builds the skeleton ZCode accepts. Throws rather than
|
|
149
|
+
* editing a file whose shape it does not recognize.
|
|
150
|
+
*/
|
|
151
|
+
export declare function applyZcodeProviders(existing: unknown, plan: ZcodePlan, mergeOptions?: ZcodeMergeOptions): ZcodeMergeResult;
|
|
152
|
+
export declare function readProviderConfig(path: string): {
|
|
153
|
+
state: "missing";
|
|
154
|
+
} | {
|
|
155
|
+
state: "unreadable";
|
|
156
|
+
} | {
|
|
157
|
+
state: "ready";
|
|
158
|
+
json: unknown;
|
|
159
|
+
};
|
|
160
|
+
export declare function backupPathFor(path: string, now: Date): string;
|
|
161
|
+
export declare function backupProviderConfig(path: string, now: Date): string;
|
|
162
|
+
export declare function writeProviderConfigAtomic(path: string, json: unknown): void;
|
|
163
|
+
export interface ServeProgram {
|
|
164
|
+
node: string;
|
|
165
|
+
script: string;
|
|
166
|
+
/** "global": the ns-bridge found on PATH; "fallback": the running checkout. */
|
|
167
|
+
source: "global" | "fallback";
|
|
168
|
+
}
|
|
169
|
+
export interface ResolveServeProgramInputs {
|
|
170
|
+
/** Colon-separated PATH to walk for an ns-bridge bin. */
|
|
171
|
+
envPath: string;
|
|
172
|
+
/** Script to pin when PATH has no ns-bridge. */
|
|
173
|
+
fallbackScript: string;
|
|
174
|
+
/** Node to run when the found bin has no node beside it. */
|
|
175
|
+
execPath: string;
|
|
176
|
+
exists?: (path: string) => boolean;
|
|
177
|
+
realpath?: (path: string) => string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The agent outlives this process and repo checkouts move, so it pins the
|
|
181
|
+
* installed CLI: the first ns-bridge on PATH via its realpath, run by the node
|
|
182
|
+
* sitting next to the bin (a version-managed install keeps its matching
|
|
183
|
+
* runtime there) when present, else execPath.
|
|
184
|
+
*/
|
|
185
|
+
export declare function resolveServeProgram(inputs: ResolveServeProgramInputs): ServeProgram;
|
|
186
|
+
export interface LaunchAgentInputs {
|
|
187
|
+
label?: string;
|
|
188
|
+
programArguments: readonly string[];
|
|
189
|
+
logPath: string;
|
|
190
|
+
envPath: string;
|
|
191
|
+
/** Extra EnvironmentVariables, e.g. NS_BRIDGE_ZCODE_CONFIG when the serve config is off its default path. */
|
|
192
|
+
extraEnv?: Record<string, string>;
|
|
193
|
+
}
|
|
194
|
+
export declare function launchAgentPlist(inputs: LaunchAgentInputs): string;
|
|
195
|
+
export declare function parseVendorList(value: string): Vendor[] | {
|
|
196
|
+
error: string;
|
|
197
|
+
};
|
|
198
|
+
export declare function parseDefaultModel(value: string): {
|
|
199
|
+
vendor: Vendor;
|
|
200
|
+
modelId: string;
|
|
201
|
+
} | {
|
|
202
|
+
error: string;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Whether an Arnict key resolves, read the way the core resolves it:
|
|
206
|
+
* ARNICT_API_KEY, else the key file `ns-bridge arnict login` writes. The core's
|
|
207
|
+
* resolveArnictApiKey cannot be imported here — tsc emits dist/zcode.js
|
|
208
|
+
* verbatim and the published CLI ships no runtime dependency on the cores — so
|
|
209
|
+
* setup re-reads the same two sources. The value itself never reaches a log.
|
|
210
|
+
*/
|
|
211
|
+
export declare function arnictKeyPresent(home: string, env?: NodeJS.ProcessEnv): boolean;
|
|
212
|
+
export interface ZcodeCommandOptions {
|
|
213
|
+
action: "setup" | "status" | "remove";
|
|
214
|
+
apply: boolean;
|
|
215
|
+
force: boolean;
|
|
216
|
+
noService: boolean;
|
|
217
|
+
runner: Runner;
|
|
218
|
+
log: (line: string) => void;
|
|
219
|
+
err: (line: string) => void;
|
|
220
|
+
/** --vendors kiro,devin: narrows the provider selection further. */
|
|
221
|
+
vendors?: string;
|
|
222
|
+
/** --default <vendor>/<model>: also set ZCode's defaultModelSelection. */
|
|
223
|
+
default?: string;
|
|
224
|
+
/** HOME for the launch agent, logs, and default paths. Tests point this at a temp dir. */
|
|
225
|
+
home?: string;
|
|
226
|
+
/** Platform override so tests can exercise the darwin-only service. */
|
|
227
|
+
platform?: NodeJS.Platform;
|
|
228
|
+
catalogPaths?: CatalogPaths;
|
|
229
|
+
providerConfigPath?: string;
|
|
230
|
+
serveConfigPath?: string;
|
|
231
|
+
selectionFilePath?: string;
|
|
232
|
+
now?: Date;
|
|
233
|
+
}
|
|
234
|
+
export declare function runZcode(options: ZcodeCommandOptions): Promise<number>;
|
|
235
|
+
export declare function isZcodeRunning(runner: Runner): Promise<boolean>;
|