@danypops/jittor 0.14.0 → 0.16.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/package.json +4 -3
- package/src/adapters/artificial-analysis-direct-source.ts +42 -11
- package/src/adapters/lmarena-hf-source.ts +37 -15
- package/src/adapters/metric-benchmark-store.ts +29 -18
- package/src/adapters/openrouter-benchmark-source.ts +75 -19
- package/src/adapters/openrouter-design-arena-source.ts +36 -19
- package/src/adapters/sqlite-metric-store.ts +48 -25
- package/src/adapters/sqlite-session-identity-store.ts +13 -7
- package/src/cli-commands/benchmarks.ts +87 -22
- package/src/cli-commands/compaction.ts +7 -2
- package/src/cli-commands/context.ts +10 -2
- package/src/cli-commands/metrics.ts +128 -31
- package/src/cli-commands/op.ts +6 -1
- package/src/cli-commands/route-args.ts +5 -1
- package/src/cli-commands/router.ts +61 -18
- package/src/cli-commands/service-daemon.ts +31 -13
- package/src/cli-commands/session.ts +15 -4
- package/src/cli-commands/support.ts +1 -1
- package/src/cli.ts +30 -23
- package/src/client.ts +1 -1
- package/src/constants.ts +1 -1
- package/src/daemon.ts +44 -24
- package/src/domain/benchmark.ts +72 -40
- package/src/domain/codex-recovery.ts +34 -25
- package/src/domain/context-hub.ts +35 -26
- package/src/domain/context-telemetry.ts +106 -35
- package/src/domain/metric.ts +11 -11
- package/src/domain/model-observation.ts +139 -55
- package/src/domain/model-ranking-service.ts +13 -3
- package/src/domain/model-ranking.ts +126 -60
- package/src/domain/task-cost.ts +52 -11
- package/src/domain/task-focus.ts +11 -8
- package/src/domain/usage.ts +2 -2
- package/src/index.ts +69 -69
- package/src/log.ts +7 -2
- package/src/operations/benchmark-operations.ts +1 -1
- package/src/operations/context-operations.ts +15 -6
- package/src/operations/metrics-operations.ts +63 -28
- package/src/operations/model-ranking-operations.ts +9 -2
- package/src/operations/router-operations.ts +8 -4
- package/src/operations/session-identity-operations.ts +1 -1
- package/src/operations/session-scope.ts +5 -3
- package/src/policy.ts +22 -17
- package/src/ports/benchmark-controller.ts +1 -5
- package/src/ports/metric-store.ts +1 -1
- package/src/providers/anthropic-contracts.ts +13 -3
- package/src/providers/codex-contracts.ts +60 -52
- package/src/providers/codex.ts +16 -19
- package/src/providers/google-vertex-budget-contracts.ts +24 -14
- package/src/providers/google-vertex-budget.ts +15 -13
- package/src/providers/google-vertex-contracts.ts +36 -24
- package/src/providers/openrouter-contracts.ts +49 -51
- package/src/providers/openrouter.ts +21 -15
- package/src/providers/telemetry-sources.ts +13 -10
- package/src/router.ts +92 -43
- package/src/service.ts +93 -32
- package/src/session-identity-service.ts +10 -2
- package/src/state.ts +4 -10
- package/src/vehicle-registration.ts +154 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CLI_AVAILABLE_ROUTES_MAX } from "../constants.ts";
|
|
2
2
|
import type { PolicyDecision, Route } from "../policy.ts";
|
|
3
3
|
import type { RouteOverride, RouterStatus, TelemetryPollResult } from "../ports/router-controller.ts";
|
|
4
|
-
import { callAndPrint, humanField, type CliDependencies } from "./support.ts";
|
|
5
4
|
import { parseRoute } from "./route-args.ts";
|
|
5
|
+
import { type CliDependencies, callAndPrint, humanField } from "./support.ts";
|
|
6
6
|
|
|
7
7
|
export const ROUTER_USAGE_LINES = [
|
|
8
8
|
" telemetry poll [--json]",
|
|
@@ -13,13 +13,19 @@ export const ROUTER_USAGE_LINES = [
|
|
|
13
13
|
" router available-routes [--route <provider/model@thinking> ...] [--session-id <id>] [--session-secret <secret>] [--json]",
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
-
interface SessionScope {
|
|
16
|
+
interface SessionScope {
|
|
17
|
+
session_id?: string;
|
|
18
|
+
session_secret?: string;
|
|
19
|
+
}
|
|
17
20
|
|
|
18
21
|
function sessionScopeInput(sessionId: string | undefined, sessionSecret: string | undefined): SessionScope {
|
|
19
22
|
return { ...(sessionId ? { session_id: sessionId } : {}), ...(sessionSecret ? { session_secret: sessionSecret } : {}) };
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
interface RouterOverrideArgs {
|
|
25
|
+
interface RouterOverrideArgs {
|
|
26
|
+
input: RouteOverride & SessionScope;
|
|
27
|
+
json: boolean;
|
|
28
|
+
}
|
|
23
29
|
|
|
24
30
|
function parseRouterOverrideArgs(args: string[]): RouterOverrideArgs | null {
|
|
25
31
|
let json = false;
|
|
@@ -29,7 +35,10 @@ function parseRouterOverrideArgs(args: string[]): RouterOverrideArgs | null {
|
|
|
29
35
|
let sessionSecret: string | undefined;
|
|
30
36
|
for (let index = 0; index < args.length; index += 1) {
|
|
31
37
|
const argument = args[index];
|
|
32
|
-
if (argument === "--json") {
|
|
38
|
+
if (argument === "--json") {
|
|
39
|
+
json = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
33
42
|
if (!["--route", "--expires-at", "--session-id", "--session-secret"].includes(argument ?? "")) return null;
|
|
34
43
|
const raw = args[++index];
|
|
35
44
|
if (raw === undefined || raw.length === 0) return null;
|
|
@@ -48,7 +57,10 @@ function parseRouterOverrideArgs(args: string[]): RouterOverrideArgs | null {
|
|
|
48
57
|
return { input: { route, expiresAt, ...sessionScopeInput(sessionId, sessionSecret) }, json };
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
interface RouterRouteArgs {
|
|
60
|
+
interface RouterRouteArgs {
|
|
61
|
+
input: Route & SessionScope;
|
|
62
|
+
json: boolean;
|
|
63
|
+
}
|
|
52
64
|
|
|
53
65
|
function parseRouterRouteArgs(args: string[]): RouterRouteArgs | null {
|
|
54
66
|
let json = false;
|
|
@@ -57,7 +69,10 @@ function parseRouterRouteArgs(args: string[]): RouterRouteArgs | null {
|
|
|
57
69
|
let sessionSecret: string | undefined;
|
|
58
70
|
for (let index = 0; index < args.length; index += 1) {
|
|
59
71
|
const argument = args[index];
|
|
60
|
-
if (argument === "--json") {
|
|
72
|
+
if (argument === "--json") {
|
|
73
|
+
json = true;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
61
76
|
if (!["--route", "--session-id", "--session-secret"].includes(argument ?? "")) return null;
|
|
62
77
|
const raw = args[++index];
|
|
63
78
|
if (raw === undefined || raw.length === 0) return null;
|
|
@@ -72,7 +87,10 @@ function parseRouterRouteArgs(args: string[]): RouterRouteArgs | null {
|
|
|
72
87
|
return { input: { ...route, ...sessionScopeInput(sessionId, sessionSecret) }, json };
|
|
73
88
|
}
|
|
74
89
|
|
|
75
|
-
interface RouterAvailableRoutesArgs {
|
|
90
|
+
interface RouterAvailableRoutesArgs {
|
|
91
|
+
input: { routes: Route[] } & SessionScope;
|
|
92
|
+
json: boolean;
|
|
93
|
+
}
|
|
76
94
|
|
|
77
95
|
function parseRouterAvailableRoutesArgs(args: string[]): RouterAvailableRoutesArgs | null {
|
|
78
96
|
let json = false;
|
|
@@ -81,7 +99,10 @@ function parseRouterAvailableRoutesArgs(args: string[]): RouterAvailableRoutesAr
|
|
|
81
99
|
const routes: Route[] = [];
|
|
82
100
|
for (let index = 0; index < args.length; index += 1) {
|
|
83
101
|
const argument = args[index];
|
|
84
|
-
if (argument === "--json") {
|
|
102
|
+
if (argument === "--json") {
|
|
103
|
+
json = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
85
106
|
if (!["--route", "--session-id", "--session-secret"].includes(argument ?? "")) return null;
|
|
86
107
|
const raw = args[++index];
|
|
87
108
|
if (raw === undefined || raw.length === 0) return null;
|
|
@@ -103,7 +124,10 @@ function parseRouterScopeArgs(args: string[]): { input: SessionScope; json: bool
|
|
|
103
124
|
let sessionSecret: string | undefined;
|
|
104
125
|
for (let index = 0; index < args.length; index += 1) {
|
|
105
126
|
const argument = args[index];
|
|
106
|
-
if (argument === "--json") {
|
|
127
|
+
if (argument === "--json") {
|
|
128
|
+
json = true;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
107
131
|
if (!["--session-id", "--session-secret"].includes(argument ?? "")) return null;
|
|
108
132
|
const raw = args[++index];
|
|
109
133
|
if (raw === undefined || raw.length === 0) return null;
|
|
@@ -128,10 +152,13 @@ function formatRoute(route: Route): string {
|
|
|
128
152
|
|
|
129
153
|
export function formatTelemetryPoll(result: TelemetryPollResult): string {
|
|
130
154
|
if (result.sources.length === 0) return "Telemetry: no sources configured";
|
|
131
|
-
return [
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
return [
|
|
156
|
+
"Telemetry:",
|
|
157
|
+
...result.sources.map((source) => {
|
|
158
|
+
const freshness = !source.ok ? `failed${source.error ? ` (${humanField(source.error)})` : ""}` : "ok";
|
|
159
|
+
return `- ${humanField(source.id)} (${humanField(source.provider)}): ${freshness} · ${source.metrics} metric(s)`;
|
|
160
|
+
}),
|
|
161
|
+
].join("\n");
|
|
135
162
|
}
|
|
136
163
|
|
|
137
164
|
export function formatRouterStatus(status: RouterStatus): string {
|
|
@@ -141,26 +168,41 @@ export function formatRouterStatus(status: RouterStatus): string {
|
|
|
141
168
|
`Available routes: ${status.availableRoutes.length.toLocaleString()}`,
|
|
142
169
|
`Override: ${status.override ? `${formatRoute(status.override.route)}${status.override.expiresAt === null ? "" : ` (expires ${new Date(status.override.expiresAt).toISOString()})`}` : "none"}`,
|
|
143
170
|
];
|
|
144
|
-
if (status.lastDecision)
|
|
171
|
+
if (status.lastDecision)
|
|
172
|
+
lines.push(
|
|
173
|
+
`Last decision: ${status.lastDecision.action} · pressure ${Number.isFinite(status.lastDecision.pressure) ? status.lastDecision.pressure.toFixed(3) : "∞"} · ${humanField(status.lastDecision.reason)}`,
|
|
174
|
+
);
|
|
145
175
|
lines.push(formatTelemetryPoll({ sources: status.sources, observedAt: Date.now() }));
|
|
146
176
|
return lines.join("\n");
|
|
147
177
|
}
|
|
148
178
|
|
|
149
179
|
export function formatPolicyDecision(decision: PolicyDecision): string {
|
|
150
|
-
const lines = [
|
|
180
|
+
const lines = [
|
|
181
|
+
`Decision: ${decision.action} · pressure ${Number.isFinite(decision.pressure) ? decision.pressure.toFixed(3) : "∞"} · ${humanField(decision.reason)}`,
|
|
182
|
+
];
|
|
151
183
|
if (decision.route) lines.push(`Route: ${formatRoute(decision.route)}`);
|
|
152
184
|
if (decision.delayMs !== undefined) lines.push(`Delay: ${decision.delayMs}ms`);
|
|
153
185
|
return lines.join("\n");
|
|
154
186
|
}
|
|
155
187
|
|
|
156
|
-
export async function runTelemetryCommand(
|
|
188
|
+
export async function runTelemetryCommand(
|
|
189
|
+
action: string | undefined,
|
|
190
|
+
rest: string[],
|
|
191
|
+
deps: CliDependencies,
|
|
192
|
+
usage: () => number,
|
|
193
|
+
): Promise<number> {
|
|
157
194
|
if (action !== "poll") return usage();
|
|
158
195
|
const parsed = parseJsonOnlyArgs(rest);
|
|
159
196
|
if (!parsed) return usage();
|
|
160
197
|
return callAndPrint(deps, "telemetry.poll", {}, parsed.json, formatTelemetryPoll);
|
|
161
198
|
}
|
|
162
199
|
|
|
163
|
-
export async function runRouterCommand(
|
|
200
|
+
export async function runRouterCommand(
|
|
201
|
+
action: string | undefined,
|
|
202
|
+
rest: string[],
|
|
203
|
+
deps: CliDependencies,
|
|
204
|
+
usage: () => number,
|
|
205
|
+
): Promise<number> {
|
|
164
206
|
switch (action) {
|
|
165
207
|
case "status": {
|
|
166
208
|
const parsed = parseRouterScopeArgs(rest);
|
|
@@ -202,6 +244,7 @@ export async function runRouterCommand(action: string | undefined, rest: string[
|
|
|
202
244
|
if (!parsed) return usage();
|
|
203
245
|
return callAndPrint(deps, "router.available_routes", parsed.input, parsed.json, formatRouterStatus);
|
|
204
246
|
}
|
|
205
|
-
default:
|
|
247
|
+
default:
|
|
248
|
+
return usage();
|
|
206
249
|
}
|
|
207
250
|
}
|
|
@@ -5,8 +5,9 @@ import { join } from "node:path";
|
|
|
5
5
|
import { createNodeServiceInstallDeps, generateSystemdUnit, installUserService, type ServiceSpec } from "@danypops/vehicle-server/service";
|
|
6
6
|
import { SYSTEMD_UNIT_NAME } from "../constants.ts";
|
|
7
7
|
import { resolveJittorPaths } from "../state.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { VERSION } from "../version.ts";
|
|
9
9
|
import { parseJsonOnlyArgs } from "./router.ts";
|
|
10
|
+
import { type CliDependencies, callAndPrint } from "./support.ts";
|
|
10
11
|
|
|
11
12
|
export const SERVICE_USAGE_LINES = [" service <install|start|stop|restart|status|checkpoint>"];
|
|
12
13
|
|
|
@@ -19,15 +20,16 @@ export interface SystemdUnitOptions {
|
|
|
19
20
|
|
|
20
21
|
function jittorServiceSpec(options: SystemdUnitOptions): ServiceSpec {
|
|
21
22
|
const env: Record<string, string> = {};
|
|
22
|
-
if (options.codexAuthFile) env
|
|
23
|
-
if (options.openRouterBenchmarks) env
|
|
23
|
+
if (options.codexAuthFile) env.JITTOR_CODEX_AUTH_FILE = options.codexAuthFile;
|
|
24
|
+
if (options.openRouterBenchmarks) env.JITTOR_OPENROUTER_BENCHMARKS = "1";
|
|
24
25
|
return {
|
|
25
26
|
name: "jittor",
|
|
26
27
|
displayName: "Jittor token optimizing router",
|
|
28
|
+
version: VERSION,
|
|
27
29
|
binPath: options.bunBin,
|
|
28
30
|
args: [options.cliPath, "serve"],
|
|
29
31
|
env,
|
|
30
|
-
|
|
32
|
+
handlePath: resolveJittorPaths().handle,
|
|
31
33
|
// Jittor's own client (connectJittorClient) never auto-spawns -- systemd's own
|
|
32
34
|
// supervision is this daemon's only recovery path, same as Lector's.
|
|
33
35
|
restartOnFailure: true,
|
|
@@ -49,12 +51,12 @@ export function systemctl(...args: string[]): void {
|
|
|
49
51
|
|
|
50
52
|
/** cliPath is the caller's own entrypoint file -- resolved from the real CLI script's `import.meta.url`, never this module's own, so the installed unit's ExecStart always points at the actual runnable CLI. */
|
|
51
53
|
export function installService(cliPath: string): void {
|
|
52
|
-
const codexAuthFile = join(process.env
|
|
54
|
+
const codexAuthFile = join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "auth.json");
|
|
53
55
|
const spec = jittorServiceSpec({
|
|
54
56
|
bunBin: process.execPath,
|
|
55
57
|
cliPath,
|
|
56
58
|
...(existsSync(codexAuthFile) ? { codexAuthFile } : {}),
|
|
57
|
-
openRouterBenchmarks: process.env
|
|
59
|
+
openRouterBenchmarks: process.env.JITTOR_OPENROUTER_BENCHMARKS === "1",
|
|
58
60
|
});
|
|
59
61
|
const result = installUserService(spec, createNodeServiceInstallDeps());
|
|
60
62
|
if (!result.installed) throw new Error(`failed to install the Jittor service: ${result.reason}`);
|
|
@@ -64,18 +66,34 @@ export function installService(cliPath: string): void {
|
|
|
64
66
|
systemctl("restart", SYSTEMD_UNIT_NAME);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
export async function runServiceCommand(
|
|
69
|
+
export async function runServiceCommand(
|
|
70
|
+
action: string | undefined,
|
|
71
|
+
rest: string[],
|
|
72
|
+
deps: CliDependencies,
|
|
73
|
+
usage: () => number,
|
|
74
|
+
): Promise<number> {
|
|
68
75
|
switch (action) {
|
|
69
|
-
case "install":
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
case "
|
|
73
|
-
|
|
76
|
+
case "install":
|
|
77
|
+
deps.installService();
|
|
78
|
+
return 0;
|
|
79
|
+
case "start":
|
|
80
|
+
deps.systemctl("start", SYSTEMD_UNIT_NAME);
|
|
81
|
+
return 0;
|
|
82
|
+
case "stop":
|
|
83
|
+
deps.systemctl("stop", SYSTEMD_UNIT_NAME);
|
|
84
|
+
return 0;
|
|
85
|
+
case "restart":
|
|
86
|
+
deps.systemctl("restart", SYSTEMD_UNIT_NAME);
|
|
87
|
+
return 0;
|
|
88
|
+
case "status":
|
|
89
|
+
deps.systemctl("status", SYSTEMD_UNIT_NAME);
|
|
90
|
+
return 0;
|
|
74
91
|
case "checkpoint": {
|
|
75
92
|
const parsed = parseJsonOnlyArgs(rest);
|
|
76
93
|
if (!parsed) return usage();
|
|
77
94
|
return callAndPrint(deps, "service.checkpoint", {}, parsed.json, () => "Checkpoint complete");
|
|
78
95
|
}
|
|
79
|
-
default:
|
|
96
|
+
default:
|
|
97
|
+
return usage();
|
|
80
98
|
}
|
|
81
99
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { callAndPrint, humanField
|
|
1
|
+
import { type CliDependencies, callAndPrint, humanField } from "./support.ts";
|
|
2
2
|
|
|
3
3
|
export const SESSION_USAGE_LINES = [
|
|
4
4
|
" session register --session-id <id> [--json]",
|
|
5
5
|
" session release --session-id <id> [--session-secret <secret>] [--json]",
|
|
6
6
|
];
|
|
7
7
|
|
|
8
|
-
interface SessionArgs {
|
|
8
|
+
interface SessionArgs {
|
|
9
|
+
input: { session_id: string; session_secret?: string };
|
|
10
|
+
json: boolean;
|
|
11
|
+
}
|
|
9
12
|
|
|
10
13
|
function parseSessionArgs(args: string[]): SessionArgs | null {
|
|
11
14
|
let json = false;
|
|
@@ -13,7 +16,10 @@ function parseSessionArgs(args: string[]): SessionArgs | null {
|
|
|
13
16
|
let sessionSecret: string | undefined;
|
|
14
17
|
for (let index = 0; index < args.length; index += 1) {
|
|
15
18
|
const argument = args[index];
|
|
16
|
-
if (argument === "--json") {
|
|
19
|
+
if (argument === "--json") {
|
|
20
|
+
json = true;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
17
23
|
if (!["--session-id", "--session-secret"].includes(argument ?? "")) return null;
|
|
18
24
|
const raw = args[++index];
|
|
19
25
|
if (raw === undefined || raw.length === 0) return null;
|
|
@@ -32,7 +38,12 @@ export function formatSessionRelease(result: { released: boolean }): string {
|
|
|
32
38
|
return result.released ? "Session released" : "Session was not registered, or the secret did not match";
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
export async function runSessionCommand(
|
|
41
|
+
export async function runSessionCommand(
|
|
42
|
+
action: string | undefined,
|
|
43
|
+
rest: string[],
|
|
44
|
+
deps: CliDependencies,
|
|
45
|
+
usage: () => number,
|
|
46
|
+
): Promise<number> {
|
|
36
47
|
if (action !== "register" && action !== "release") return usage();
|
|
37
48
|
const parsed = parseSessionArgs(rest);
|
|
38
49
|
if (!parsed) return usage();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HUMAN_TEXT_FIELD_MAX_CHARACTERS } from "../constants.ts";
|
|
2
1
|
import type { JittorClient } from "../client.ts";
|
|
2
|
+
import { HUMAN_TEXT_FIELD_MAX_CHARACTERS } from "../constants.ts";
|
|
3
3
|
import type { OperationInputs, OperationName, OperationOutputs } from "../service.ts";
|
|
4
4
|
|
|
5
5
|
export interface CliDependencies {
|
package/src/cli.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { BENCHMARKS_USAGE_LINES, runBenchmarksCommand } from "./cli-commands/benchmarks.ts";
|
|
4
|
+
import { runCompactionCommand } from "./cli-commands/compaction.ts";
|
|
5
|
+
import { CONTEXT_USAGE_LINES, formatContextAssessment, runContextCommand } from "./cli-commands/context.ts";
|
|
6
|
+
import { formatCostByTask, formatMetricsQuery, METRICS_USAGE_LINES, runMetricsCommand } from "./cli-commands/metrics.ts";
|
|
7
|
+
import { OP_USAGE_LINES, runOpCommand } from "./cli-commands/op.ts";
|
|
8
|
+
import { formatRouterStatus, ROUTER_USAGE_LINES, runRouterCommand, runTelemetryCommand } from "./cli-commands/router.ts";
|
|
9
|
+
import { installService, renderSystemdUnit, runServiceCommand, SERVICE_USAGE_LINES, systemctl } from "./cli-commands/service-daemon.ts";
|
|
10
|
+
import { runSessionCommand, SESSION_USAGE_LINES } from "./cli-commands/session.ts";
|
|
11
|
+
import type { CliDependencies } from "./cli-commands/support.ts";
|
|
3
12
|
import { connectJittorClient } from "./client.ts";
|
|
4
13
|
import { serveMain } from "./daemon.ts";
|
|
5
|
-
import type { CliDependencies } from "./cli-commands/support.ts";
|
|
6
|
-
import { installService, renderSystemdUnit, systemctl, runServiceCommand, SERVICE_USAGE_LINES } from "./cli-commands/service-daemon.ts";
|
|
7
|
-
import { runSessionCommand, SESSION_USAGE_LINES } from "./cli-commands/session.ts";
|
|
8
|
-
import { runMetricsCommand, METRICS_USAGE_LINES, formatMetricsQuery, formatCostByTask } from "./cli-commands/metrics.ts";
|
|
9
|
-
import { runTelemetryCommand, runRouterCommand, ROUTER_USAGE_LINES, formatRouterStatus } from "./cli-commands/router.ts";
|
|
10
|
-
import { runCompactionCommand } from "./cli-commands/compaction.ts";
|
|
11
|
-
import { runOpCommand, OP_USAGE_LINES } from "./cli-commands/op.ts";
|
|
12
|
-
import { runBenchmarksCommand, BENCHMARKS_USAGE_LINES } from "./cli-commands/benchmarks.ts";
|
|
13
|
-
import { runContextCommand, CONTEXT_USAGE_LINES, formatContextAssessment } from "./cli-commands/context.ts";
|
|
14
14
|
|
|
15
15
|
// Re-exported for external callers (tests, daemon.ts's systemd-unit test) that import these
|
|
16
16
|
// directly from cli.ts rather than reaching into src/cli-commands/*.
|
|
17
17
|
export type { CliDependencies };
|
|
18
|
-
export {
|
|
18
|
+
export { formatContextAssessment, formatCostByTask, formatMetricsQuery, formatRouterStatus, renderSystemdUnit };
|
|
19
19
|
|
|
20
20
|
const DEFAULT_DEPENDENCIES: CliDependencies = {
|
|
21
|
-
get client() {
|
|
21
|
+
get client() {
|
|
22
|
+
return connectJittorClient();
|
|
23
|
+
},
|
|
22
24
|
stdout: console.log,
|
|
23
25
|
stderr: console.error,
|
|
24
26
|
systemctl,
|
|
@@ -27,17 +29,19 @@ const DEFAULT_DEPENDENCIES: CliDependencies = {
|
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
function usage(stderr: (line: string) => void): number {
|
|
30
|
-
stderr(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
stderr(
|
|
33
|
+
[
|
|
34
|
+
"Usage: jittor <command> [options]",
|
|
35
|
+
" serve",
|
|
36
|
+
...SERVICE_USAGE_LINES,
|
|
37
|
+
...CONTEXT_USAGE_LINES,
|
|
38
|
+
...BENCHMARKS_USAGE_LINES,
|
|
39
|
+
...METRICS_USAGE_LINES,
|
|
40
|
+
...ROUTER_USAGE_LINES,
|
|
41
|
+
...SESSION_USAGE_LINES,
|
|
42
|
+
...OP_USAGE_LINES,
|
|
43
|
+
].join("\n"),
|
|
44
|
+
);
|
|
41
45
|
return 2;
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -52,7 +56,10 @@ function usage(stderr: (line: string) => void): number {
|
|
|
52
56
|
export async function runCli(args: string[], deps: CliDependencies = DEFAULT_DEPENDENCIES): Promise<number> {
|
|
53
57
|
const [command, action, ...rest] = args;
|
|
54
58
|
const fail = () => usage(deps.stderr);
|
|
55
|
-
if (command === "serve") {
|
|
59
|
+
if (command === "serve") {
|
|
60
|
+
await deps.serve();
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
56
63
|
if (command === "session") return runSessionCommand(action, rest, deps, fail);
|
|
57
64
|
if (command === "metrics") return runMetricsCommand(action, rest, deps, fail);
|
|
58
65
|
if (command === "telemetry") return runTelemetryCommand(action, rest, deps, fail);
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthenticatedRpcClient, type FetchTransport } from "@danypops/vehicle-client/rpc-client";
|
|
2
2
|
import type { OperationInputs, OperationName, OperationOutputs } from "./service.ts";
|
|
3
|
-
import { ensureAuthToken, readDaemonHandle, resolveJittorPaths
|
|
3
|
+
import { ensureAuthToken, type JittorPaths, readDaemonHandle, resolveJittorPaths } from "./state.ts";
|
|
4
4
|
|
|
5
5
|
export type { FetchTransport };
|
|
6
6
|
|
package/src/constants.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const BENCHMARK_IDENTITY_MAX_CHARACTERS = 160;
|
|
|
10
10
|
export const BENCHMARK_MAX_TEXT_CHARACTERS = 2_048;
|
|
11
11
|
export const BENCHMARK_MAX_MODELS_PER_SOURCE = 250;
|
|
12
12
|
export const BENCHMARK_MAX_OBSERVATIONS_PER_SNAPSHOT = 2_000;
|
|
13
|
-
export const BENCHMARK_STORE_QUERY_LIMIT =
|
|
13
|
+
export const BENCHMARK_STORE_QUERY_LIMIT = BENCHMARK_MAX_OBSERVATIONS_PER_SNAPSHOT * 2 + 1;
|
|
14
14
|
export const BENCHMARK_DEFAULT_QUERY_LIMIT = 100;
|
|
15
15
|
export const BENCHMARK_TUI_MAX_CANDIDATES = 20;
|
|
16
16
|
export const BENCHMARK_TUI_MAX_PROVENANCE_PER_CANDIDATE = 2;
|
package/src/daemon.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { startDaemon as startDaemonKit
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SQLiteMetricStore } from "./adapters/sqlite-metric-store.ts";
|
|
1
|
+
import { type RunningDaemon, startDaemon as startDaemonKit } from "@danypops/vehicle-server/daemon";
|
|
2
|
+
import { ArtificialAnalysisDirectSource } from "./adapters/artificial-analysis-direct-source.ts";
|
|
3
|
+
import { LmArenaHfSource } from "./adapters/lmarena-hf-source.ts";
|
|
5
4
|
import { MetricBenchmarkStore } from "./adapters/metric-benchmark-store.ts";
|
|
6
5
|
import { OpenRouterBenchmarkSource } from "./adapters/openrouter-benchmark-source.ts";
|
|
7
6
|
import { OpenRouterDesignArenaSource } from "./adapters/openrouter-design-arena-source.ts";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { SQLiteMetricStore } from "./adapters/sqlite-metric-store.ts";
|
|
8
|
+
import { SQLiteSessionIdentityStore } from "./adapters/sqlite-session-identity-store.ts";
|
|
9
|
+
import { DEFAULT_POLICY, UNCONFIGURED_ROUTE } from "./config.ts";
|
|
10
|
+
import { MAINTENANCE_INTERVAL_MS, TELEMETRY_POLL_INTERVAL_MS } from "./constants.ts";
|
|
10
11
|
import { openJittorDb } from "./db.ts";
|
|
11
12
|
import { BenchmarkCatalog } from "./domain/benchmark.ts";
|
|
12
13
|
import { EvidenceModelRanker } from "./domain/model-ranking-service.ts";
|
|
13
|
-
import {
|
|
14
|
-
import { JittorRouter } from "./router.ts";
|
|
15
|
-
import { SQLiteSessionIdentityStore } from "./adapters/sqlite-session-identity-store.ts";
|
|
16
|
-
import { SessionIdentity } from "./session-identity-service.ts";
|
|
14
|
+
import { logEvent, logger } from "./log.ts";
|
|
17
15
|
import type { BenchmarkSource } from "./ports/benchmark-source.ts";
|
|
18
16
|
import type { TelemetrySource } from "./ports/telemetry-source.ts";
|
|
19
|
-
import { CodexTelemetrySource, GoogleVertexBudgetTelemetrySource, OpenRouterTelemetrySource } from "./providers/telemetry-sources.ts";
|
|
20
17
|
import { createGoogleAdcTokenProvider } from "./providers/google-adc-auth.ts";
|
|
21
18
|
import { GOOGLE_PUBSUB_READONLY_SCOPE } from "./providers/google-vertex-budget.ts";
|
|
22
19
|
import type { GoogleVertexMetricSource } from "./providers/google-vertex-contracts.ts";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
20
|
+
import { CodexTelemetrySource, GoogleVertexBudgetTelemetrySource, OpenRouterTelemetrySource } from "./providers/telemetry-sources.ts";
|
|
21
|
+
import { JittorRouter } from "./router.ts";
|
|
22
|
+
import { createApp, JittorService } from "./service.ts";
|
|
23
|
+
import { SessionIdentity } from "./session-identity-service.ts";
|
|
24
|
+
import { ensureAuthToken, type JittorPaths, resolveJittorPaths } from "./state.ts";
|
|
25
25
|
|
|
26
26
|
export type { RunningDaemon } from "@danypops/vehicle-server/daemon";
|
|
27
27
|
|
|
@@ -32,12 +32,12 @@ export function reportMaintenanceFailure(event: string, error: unknown): void {
|
|
|
32
32
|
// Flag name predates non-OpenRouter sources; kept as the one "opt into online benchmark
|
|
33
33
|
// ingestion" toggle rather than adding a second flag for the same decision.
|
|
34
34
|
export function benchmarkSourcesFromEnvironment(env: Record<string, string | undefined> = process.env): BenchmarkSource[] {
|
|
35
|
-
if (env
|
|
35
|
+
if (env.JITTOR_OPENROUTER_BENCHMARKS !== "1") return [];
|
|
36
36
|
const sources: BenchmarkSource[] = [new OpenRouterBenchmarkSource(), new LmArenaHfSource()];
|
|
37
37
|
// Design Arena's own API needs manual approval, unlike Artificial Analysis's instant signup --
|
|
38
38
|
// no direct alternative exists yet, so the OpenRouter passthrough stays.
|
|
39
|
-
if (env
|
|
40
|
-
if (env
|
|
39
|
+
if (env.OPENROUTER_API_KEY) sources.push(new OpenRouterDesignArenaSource(env.OPENROUTER_API_KEY));
|
|
40
|
+
if (env.ARTIFICIAL_ANALYSIS_API_KEY) sources.push(new ArtificialAnalysisDirectSource(env.ARTIFICIAL_ANALYSIS_API_KEY));
|
|
41
41
|
return sources;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -49,15 +49,15 @@ function googleVertexMetricSource(value: string | undefined): GoogleVertexMetric
|
|
|
49
49
|
|
|
50
50
|
export function telemetrySourcesFromEnvironment(env: Record<string, string | undefined> = process.env): TelemetrySource[] {
|
|
51
51
|
const sources: TelemetrySource[] = [];
|
|
52
|
-
const codexAuthFile = env
|
|
52
|
+
const codexAuthFile = env.JITTOR_CODEX_AUTH_FILE;
|
|
53
53
|
if (codexAuthFile) sources.push(new CodexTelemetrySource(codexAuthFile));
|
|
54
|
-
const openRouterKey = env
|
|
54
|
+
const openRouterKey = env.OPENROUTER_API_KEY;
|
|
55
55
|
if (openRouterKey) sources.push(new OpenRouterTelemetrySource(openRouterKey));
|
|
56
56
|
// Opt-in only: the Pub/Sub subscription is one-time GCP console/CLI setup outside Jittor (see
|
|
57
57
|
// docs/PROVIDER_RESEARCH.md), so its absence must never attempt ADC discovery or a network call.
|
|
58
|
-
const vertexBudgetSubscription = env
|
|
58
|
+
const vertexBudgetSubscription = env.JITTOR_GOOGLE_VERTEX_BUDGET_SUBSCRIPTION;
|
|
59
59
|
if (vertexBudgetSubscription) {
|
|
60
|
-
const source = googleVertexMetricSource(env
|
|
60
|
+
const source = googleVertexMetricSource(env.JITTOR_GOOGLE_VERTEX_BUDGET_SOURCE);
|
|
61
61
|
const tokenProvider = createGoogleAdcTokenProvider([GOOGLE_PUBSUB_READONLY_SCOPE]);
|
|
62
62
|
sources.push(new GoogleVertexBudgetTelemetrySource(vertexBudgetSubscription, tokenProvider, Date.now, fetch, source));
|
|
63
63
|
}
|
|
@@ -102,11 +102,31 @@ export async function startDaemon(
|
|
|
102
102
|
logger,
|
|
103
103
|
buildApp: () => createApp({ service, token }),
|
|
104
104
|
maintenanceTasks: [
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
{
|
|
106
|
+
name: "checkpoint",
|
|
107
|
+
intervalMs: MAINTENANCE_INTERVAL_MS,
|
|
108
|
+
run: async () => {
|
|
109
|
+
await service.execute("service.checkpoint", {}).catch((error) => reportMaintenanceFailure("checkpoint_failed", error));
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "benchmark-refresh",
|
|
114
|
+
intervalMs: MAINTENANCE_INTERVAL_MS,
|
|
115
|
+
run: async () => {
|
|
116
|
+
await benchmarks.refresh().catch((error) => reportMaintenanceFailure("benchmark_refresh_failed", error));
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "telemetry-poll",
|
|
121
|
+
intervalMs: TELEMETRY_POLL_INTERVAL_MS,
|
|
122
|
+
run: async () => {
|
|
123
|
+
await router.poll().catch((error) => reportMaintenanceFailure("telemetry_poll_failed", error));
|
|
124
|
+
},
|
|
125
|
+
},
|
|
108
126
|
],
|
|
109
|
-
onShutdown: () => {
|
|
127
|
+
onShutdown: () => {
|
|
128
|
+
service.close();
|
|
129
|
+
},
|
|
110
130
|
});
|
|
111
131
|
|
|
112
132
|
if (sources.length > 0) router.poll().catch((error) => reportMaintenanceFailure("telemetry_poll_failed", error));
|