@danypops/jittor 0.7.0 → 0.8.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/README.md CHANGED
@@ -80,7 +80,9 @@ Token-budget thresholds are optional and must be configured by the user; Jittor
80
80
 
81
81
  ### Benchmark evidence
82
82
 
83
- Jittor can ingest bounded OpenRouter model metadata, p50 latency/throughput ordering, and versioned Artificial Analysis benchmark indices as provenance-bearing evidence without treating OpenRouter as model-scope authority. Enable online ingestion explicitly with `JITTOR_OPENROUTER_BENCHMARKS=1`; it is off by default. OpenRouter model metadata and operational ordering are public; benchmark-index ingestion additionally uses `OPENROUTER_API_KEY` from the supervised service environment without retaining it. Snapshots preserve the upstream publisher, normalized model identities, immutable retrieval revisions, source URLs, confidence, license terms, and explicit freshness deadlines. A malformed or oversized refresh leaves the last complete snapshot visible and records only a payload-safe failure state.
83
+ Jittor can ingest bounded OpenRouter model metadata, p50 latency/throughput ordering, versioned Artificial Analysis benchmark indices, and Design Arena Elo rankings as provenance-bearing evidence without treating OpenRouter as model-scope authority. Enable online ingestion explicitly with `JITTOR_OPENROUTER_BENCHMARKS=1`; it is off by default. OpenRouter model metadata and operational ordering are public; benchmark-index and Design Arena ingestion additionally use `OPENROUTER_API_KEY` from the supervised service environment without retaining it. Snapshots preserve the upstream publisher, normalized model identities, immutable retrieval revisions, source URLs, confidence, license terms, and explicit freshness deadlines. A malformed or oversized refresh leaves the last complete snapshot visible and records only a payload-safe failure state.
84
+
85
+ Design Arena rates models across dozens of arena/category pairs (music, video, text-to-speech, ASCII art, ...); Jittor ingests only the bounded allowlist of categories (`codecategories`, `website`, `uicomponent`, `dataviz`, `svg`) that measure frontend/UI-generation skill relevant to routing a coding agent, tagged into one `design` domain distinct from `coding`. A model with no OpenRouter-reachable identity (proprietary platforms, image/video generators) is skipped rather than fabricated into unroutable evidence.
84
86
 
85
87
  Use the authenticated CLI channels independently:
86
88
 
@@ -85,7 +85,7 @@ export async function showBenchmarkPanel(
85
85
  context: MODEL_RANKING_DEFAULT_CONTEXT_WEIGHT,
86
86
  reliability: MODEL_RANKING_DEFAULT_RELIABILITY_WEIGHT,
87
87
  },
88
- sourceIds: ["openrouter-models", "openrouter-artificial-analysis"],
88
+ sourceIds: ["openrouter-models", "openrouter-artificial-analysis", "openrouter-design-arena"],
89
89
  }) as ModelRankingResult;
90
90
  if (ctx.mode !== "tui") {
91
91
  ctx.ui.notify(renderBenchmarkView(result, currentIdentity, 100, { fg: (_color, text) => text, bold: (text) => text }).join("\n"), "info");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danypops/jittor",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Just-in-Time Token Optimizing Router for Pi",
5
5
  "type": "module",
6
6
  "keywords": ["pi-package", "llm-router", "token-budget"],
@@ -0,0 +1,105 @@
1
+ import {
2
+ BENCHMARK_MAX_MODELS_PER_SOURCE,
3
+ BENCHMARK_REFRESH_INTERVAL_MS,
4
+ BENCHMARK_SOURCE_MAX_RESPONSE_BYTES,
5
+ } from "../constants.ts";
6
+ import { normalizeModelIdentity, validateBenchmarkObservation, type BenchmarkObservation, type BenchmarkSourceSnapshot } from "../domain/benchmark.ts";
7
+ import type { BenchmarkSource } from "../ports/benchmark-source.ts";
8
+ import { contractRecord } from "../providers/openrouter-contracts.ts";
9
+ import type { OpenRouterBenchmarkTransport } from "./openrouter-benchmark-source.ts";
10
+
11
+ const SOURCE_ID = "openrouter-design-arena";
12
+ const BASE_URL = `https://openrouter.ai/api/v1/benchmarks?source=design-arena&max_results=${BENCHMARK_MAX_MODELS_PER_SOURCE}`;
13
+
14
+ /**
15
+ * Design Arena publishes rankings across dozens of arena/category pairs (music, video, TTS,
16
+ * ASCII art, ...) -- most of them have nothing to do with a text coding agent's model choice.
17
+ * This is a deliberate, bounded allowlist of the categories that measure frontend/UI-generation
18
+ * skill, the one facet of "design" quality relevant to routing a coding agent. Extending this
19
+ * list is a data curation decision (does the category's skill actually predict something a
20
+ * coding agent needs), not a mechanical one.
21
+ */
22
+ const RELEVANT_CATEGORIES = ["codecategories", "website", "uicomponent", "dataviz", "svg"] as const;
23
+
24
+ function requiredText(value: unknown, name: string): string {
25
+ if (typeof value !== "string" || value.length === 0 || value.length > 500) throw new Error(`OpenRouter Design Arena benchmark ${name} schema changed`);
26
+ return value;
27
+ }
28
+
29
+ function requiredNumber(value: unknown, name: string): number {
30
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new Error(`OpenRouter Design Arena benchmark ${name} schema changed`);
31
+ return value;
32
+ }
33
+
34
+ function identityFromOpenRouterId(openRouterId: string): { provider: string; model: string } {
35
+ const separator = openRouterId.indexOf("/");
36
+ if (separator <= 0 || separator === openRouterId.length - 1) throw new Error("OpenRouter Design Arena model identity schema changed");
37
+ return { provider: openRouterId.slice(0, separator), model: openRouterId.slice(separator + 1) };
38
+ }
39
+
40
+ export class OpenRouterDesignArenaSource implements BenchmarkSource {
41
+ readonly id = SOURCE_ID;
42
+
43
+ constructor(
44
+ private readonly apiKey: string,
45
+ private readonly transport: OpenRouterBenchmarkTransport = fetch,
46
+ private readonly clock: () => number = Date.now,
47
+ ) {
48
+ if (apiKey.length === 0) throw new Error("OpenRouter API key is required for Design Arena benchmark evidence");
49
+ }
50
+
51
+ async fetch(): Promise<BenchmarkSourceSnapshot> {
52
+ const retrievedAt = this.clock();
53
+ if (!Number.isSafeInteger(retrievedAt) || retrievedAt <= 0) throw new Error("benchmark retrieval time is invalid");
54
+ const perCategory = await Promise.all(RELEVANT_CATEGORIES.map((category) => this.fetchCategory(category, retrievedAt)));
55
+ const revisions = new Set(perCategory.map((page) => page.revision));
56
+ const observations = perCategory.flatMap((page) => page.observations);
57
+ return { sourceId: this.id, snapshotId: `${this.id}:${[...revisions].sort().join(",")}`, retrievedAt, observations };
58
+ }
59
+
60
+ private async fetchCategory(category: string, retrievedAt: number): Promise<{ revision: string; observations: BenchmarkObservation[] }> {
61
+ const url = `${BASE_URL}&task_type=${category}`;
62
+ const response = await this.transport(new Request(url, { headers: { authorization: `Bearer ${this.apiKey}` } }));
63
+ if (!response.ok) throw new Error(`OpenRouter Design Arena benchmarks failed with HTTP ${response.status}`);
64
+ const text = await response.text();
65
+ if (new TextEncoder().encode(text).byteLength > BENCHMARK_SOURCE_MAX_RESPONSE_BYTES) throw new Error("OpenRouter Design Arena benchmark response exceeds the size limit");
66
+ let payload: unknown;
67
+ try { payload = JSON.parse(text); } catch { throw new Error("OpenRouter Design Arena benchmark response is not valid JSON"); }
68
+ const root = contractRecord(payload, "benchmark response");
69
+ const meta = contractRecord(root["meta"], "benchmark metadata");
70
+ if (!Array.isArray(root["data"]) || root["data"].length > BENCHMARK_MAX_MODELS_PER_SOURCE) throw new Error("OpenRouter Design Arena benchmark result count is invalid");
71
+ if (requiredText(meta["source"], "source") !== "design-arena") throw new Error("OpenRouter Design Arena benchmark source schema changed");
72
+ const asOf = requiredText(meta["as_of"], "as-of date");
73
+ const publishedAt = Date.parse(asOf);
74
+ if (!Number.isSafeInteger(publishedAt) || publishedAt <= 0) throw new Error("OpenRouter Design Arena benchmark publication date schema changed");
75
+ const revision = `${category}:${asOf}`;
76
+ const observations = root["data"].flatMap((value): BenchmarkObservation[] => {
77
+ const row = contractRecord(value, "benchmark row");
78
+ if (requiredText(row["source"], "row source") !== "design-arena") throw new Error("OpenRouter Design Arena benchmark row source schema changed");
79
+ // A null open_router_id means the model isn't reachable through OpenRouter at all
80
+ // (proprietary platform, image/video generator, deprecated model) -- not evidence
81
+ // Jittor can ever route against, so the row is skipped rather than rejected.
82
+ const openRouterId = row["open_router_id"];
83
+ if (openRouterId === null) return [];
84
+ const { provider, model } = identityFromOpenRouterId(requiredText(openRouterId, "open_router_id"));
85
+ const identity = normalizeModelIdentity(provider, model, [`openrouter/${provider}/${model}`]);
86
+ const provenance = {
87
+ sourceId: SOURCE_ID,
88
+ sourceType: "independent" as const,
89
+ publisher: "Design Arena via OpenRouter",
90
+ url: BASE_URL,
91
+ revision,
92
+ publishedAt,
93
+ retrievedAt,
94
+ freshUntil: retrievedAt + BENCHMARK_REFRESH_INTERVAL_MS,
95
+ license: "OpenRouter API terms; Design Arena terms apply",
96
+ confidence: 0.7,
97
+ };
98
+ const methodology = { basis: "Design Arena Elo rating via OpenRouter", category, asOf };
99
+ return [validateBenchmarkObservation({
100
+ model: identity, dimension: "quality-design", value: requiredNumber(row["elo"], "elo rating"), unit: "elo", provenance, methodology,
101
+ })];
102
+ });
103
+ return { revision, observations };
104
+ }
105
+ }
package/src/daemon.ts CHANGED
@@ -5,6 +5,7 @@ import { SQLiteMetricStore } from "./adapters/sqlite-metric-store.ts";
5
5
  import { MetricBenchmarkStore } from "./adapters/metric-benchmark-store.ts";
6
6
  import { OpenRouterBenchmarkIndexSource } from "./adapters/openrouter-benchmark-index-source.ts";
7
7
  import { OpenRouterBenchmarkSource } from "./adapters/openrouter-benchmark-source.ts";
8
+ import { OpenRouterDesignArenaSource } from "./adapters/openrouter-design-arena-source.ts";
8
9
  import { openJittorDb } from "./db.ts";
9
10
  import { BenchmarkCatalog } from "./domain/benchmark.ts";
10
11
  import { EvidenceModelRanker } from "./domain/model-ranking-service.ts";
@@ -28,7 +29,10 @@ export function reportMaintenanceFailure(event: string, error: unknown): void {
28
29
  export function benchmarkSourcesFromEnvironment(env: Record<string, string | undefined> = process.env): BenchmarkSource[] {
29
30
  if (env["JITTOR_OPENROUTER_BENCHMARKS"] !== "1") return [];
30
31
  const sources: BenchmarkSource[] = [new OpenRouterBenchmarkSource()];
31
- if (env["OPENROUTER_API_KEY"]) sources.push(new OpenRouterBenchmarkIndexSource(env["OPENROUTER_API_KEY"]));
32
+ if (env["OPENROUTER_API_KEY"]) {
33
+ sources.push(new OpenRouterBenchmarkIndexSource(env["OPENROUTER_API_KEY"]));
34
+ sources.push(new OpenRouterDesignArenaSource(env["OPENROUTER_API_KEY"]));
35
+ }
32
36
  return sources;
33
37
  }
34
38
 
@@ -1,6 +1,6 @@
1
1
  import { METRIC_ATTRIBUTES_MAX_DEPTH, METRIC_ATTRIBUTES_MAX_SERIALIZED_CHARACTERS, METRIC_IDENTITY_MAX_CHARACTERS } from "../constants.ts";
2
2
 
3
- export const METRIC_UNITS = ["ratio", "usd", "tokens", "tokens-per-second", "requests", "milliseconds", "count"] as const;
3
+ export const METRIC_UNITS = ["ratio", "usd", "tokens", "tokens-per-second", "requests", "milliseconds", "count", "elo"] as const;
4
4
  export type MetricUnit = typeof METRIC_UNITS[number];
5
5
 
6
6
  export interface MetricObservation {
@@ -16,7 +16,7 @@ import type { MetricObservation, MetricUnit, StoredMetricObservation } from "./m
16
16
  * usage carries no distinguishing signal for that axis; a run can score coding on domain and
17
17
  * research on type simultaneously (e.g. reading a file, then searching the web in one turn).
18
18
  */
19
- export const TASK_DOMAINS = ["coding", "general"] as const;
19
+ export const TASK_DOMAINS = ["coding", "design", "general"] as const;
20
20
  export type ModelTaskDomain = typeof TASK_DOMAINS[number];
21
21
  export const TASK_TYPES = ["research", "planning", "general"] as const;
22
22
  export type ModelTaskType = typeof TASK_TYPES[number];