modelrig 0.1.0 → 0.3.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/CHANGELOG.md +158 -0
- package/README.md +53 -11
- package/data/PROVENANCE.md +19 -0
- package/data/pricing-manual.json +22 -0
- package/data/pricing-map.json +46362 -0
- package/data/pricing-overlay.json +419 -0
- package/dist/adapters/anthropic.d.ts +50 -6
- package/dist/adapters/anthropic.d.ts.map +1 -1
- package/dist/adapters/anthropic.js +123 -29
- package/dist/adapters/build-adapters.d.ts +11 -0
- package/dist/adapters/build-adapters.d.ts.map +1 -0
- package/dist/adapters/build-adapters.js +45 -0
- package/dist/adapters/deepseek.d.ts +6 -0
- package/dist/adapters/deepseek.d.ts.map +1 -1
- package/dist/adapters/deepseek.js +54 -1
- package/dist/adapters/gemini.d.ts +10 -0
- package/dist/adapters/gemini.d.ts.map +1 -1
- package/dist/adapters/gemini.js +78 -7
- package/dist/adapters/grok.d.ts +9 -0
- package/dist/adapters/grok.d.ts.map +1 -1
- package/dist/adapters/grok.js +67 -3
- package/dist/adapters/openai-compat.d.ts +6 -0
- package/dist/adapters/openai-compat.d.ts.map +1 -1
- package/dist/adapters/openai-compat.js +58 -1
- package/dist/adapters/openai-stream.d.ts +58 -0
- package/dist/adapters/openai-stream.d.ts.map +1 -0
- package/dist/adapters/openai-stream.js +120 -0
- package/dist/adapters/openai.d.ts +6 -0
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openai.js +60 -1
- package/dist/adapters/sampling.d.ts +28 -0
- package/dist/adapters/sampling.d.ts.map +1 -0
- package/dist/adapters/sampling.js +34 -0
- package/dist/adapters/tool-mapping.d.ts +92 -0
- package/dist/adapters/tool-mapping.d.ts.map +1 -0
- package/dist/adapters/tool-mapping.js +143 -0
- package/dist/artifacts/artifact.d.ts +137 -0
- package/dist/artifacts/artifact.d.ts.map +1 -0
- package/dist/artifacts/artifact.js +377 -0
- package/dist/artifacts/content-uploader.d.ts +87 -0
- package/dist/artifacts/content-uploader.d.ts.map +1 -0
- package/dist/artifacts/content-uploader.js +124 -0
- package/dist/artifacts/index.d.ts +63 -0
- package/dist/artifacts/index.d.ts.map +1 -0
- package/dist/artifacts/index.js +80 -0
- package/dist/artifacts/run-context.d.ts +129 -0
- package/dist/artifacts/run-context.d.ts.map +1 -0
- package/dist/artifacts/run-context.js +208 -0
- package/dist/artifacts/scrub.d.ts +60 -0
- package/dist/artifacts/scrub.d.ts.map +1 -0
- package/dist/artifacts/scrub.js +139 -0
- package/dist/artifacts/step.d.ts +26 -0
- package/dist/artifacts/step.d.ts.map +1 -0
- package/dist/artifacts/step.js +37 -0
- package/dist/artifacts/taint.d.ts +63 -0
- package/dist/artifacts/taint.d.ts.map +1 -0
- package/dist/artifacts/taint.js +76 -0
- package/dist/bakeoff/cache-sim.d.ts +99 -0
- package/dist/bakeoff/cache-sim.d.ts.map +1 -0
- package/dist/bakeoff/cache-sim.js +126 -0
- package/dist/bakeoff/eval-cases.d.ts +96 -0
- package/dist/bakeoff/eval-cases.d.ts.map +1 -0
- package/dist/bakeoff/eval-cases.js +105 -0
- package/dist/bakeoff/report.d.ts +41 -0
- package/dist/bakeoff/report.d.ts.map +1 -0
- package/dist/bakeoff/report.js +142 -0
- package/dist/bakeoff/samples.d.ts +15 -0
- package/dist/bakeoff/samples.d.ts.map +1 -1
- package/dist/bakeoff/samples.js +20 -0
- package/dist/cli.d.ts +1 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +134 -116
- package/dist/config.d.ts +100 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +104 -0
- package/dist/deprecations.d.ts +32 -0
- package/dist/deprecations.d.ts.map +1 -0
- package/dist/deprecations.js +59 -0
- package/dist/gateway/http-protocol.d.ts +175 -0
- package/dist/gateway/http-protocol.d.ts.map +1 -0
- package/dist/gateway/http-protocol.js +105 -0
- package/dist/index.d.ts +106 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +266 -138
- package/dist/init/finder.d.ts +15 -0
- package/dist/init/finder.d.ts.map +1 -1
- package/dist/init/finder.js +46 -0
- package/dist/init/init-cli.d.ts +10 -0
- package/dist/init/init-cli.d.ts.map +1 -0
- package/dist/init/init-cli.js +86 -0
- package/dist/init/observe-cli.d.ts +19 -0
- package/dist/init/observe-cli.d.ts.map +1 -0
- package/dist/init/observe-cli.js +73 -0
- package/dist/init/observe.d.ts +81 -0
- package/dist/init/observe.d.ts.map +1 -0
- package/dist/init/observe.js +245 -0
- package/dist/registry/build.d.ts +94 -1
- package/dist/registry/build.d.ts.map +1 -1
- package/dist/registry/build.js +125 -4
- package/dist/registry/cache-policy.d.ts +94 -0
- package/dist/registry/cache-policy.d.ts.map +1 -0
- package/dist/registry/cache-policy.js +238 -0
- package/dist/registry/call-notes.d.ts.map +1 -1
- package/dist/registry/call-notes.js +40 -2
- package/dist/registry/effective-rate.d.ts +151 -0
- package/dist/registry/effective-rate.d.ts.map +1 -0
- package/dist/registry/effective-rate.js +156 -0
- package/dist/registry/facts.d.ts.map +1 -1
- package/dist/registry/facts.js +16 -0
- package/dist/registry/parity.d.ts +26 -0
- package/dist/registry/parity.d.ts.map +1 -1
- package/dist/registry/parity.js +43 -2
- package/dist/registry/pricing-shape.d.ts +113 -0
- package/dist/registry/pricing-shape.d.ts.map +1 -0
- package/dist/registry/pricing-shape.js +123 -0
- package/dist/registry/pricing.d.ts +25 -1
- package/dist/registry/pricing.d.ts.map +1 -1
- package/dist/registry/pricing.js +64 -6
- package/dist/rigindex/bootstrap.d.ts +36 -0
- package/dist/rigindex/bootstrap.d.ts.map +1 -0
- package/dist/rigindex/bootstrap.js +97 -0
- package/dist/rigindex/fit.d.ts +24 -0
- package/dist/rigindex/fit.d.ts.map +1 -0
- package/dist/rigindex/fit.js +76 -0
- package/dist/rigindex/gates.d.ts +52 -0
- package/dist/rigindex/gates.d.ts.map +1 -0
- package/dist/rigindex/gates.js +109 -0
- package/dist/rigindex/graph.d.ts +31 -0
- package/dist/rigindex/graph.d.ts.map +1 -0
- package/dist/rigindex/graph.js +120 -0
- package/dist/rigindex/index.d.ts +23 -0
- package/dist/rigindex/index.d.ts.map +1 -0
- package/dist/rigindex/index.js +112 -0
- package/dist/rigindex/types.d.ts +76 -0
- package/dist/rigindex/types.d.ts.map +1 -0
- package/dist/rigindex/types.js +8 -0
- package/dist/routes/cache-lint.d.ts +41 -0
- package/dist/routes/cache-lint.d.ts.map +1 -0
- package/dist/routes/cache-lint.js +81 -0
- package/dist/routes/loader.d.ts +48 -0
- package/dist/routes/loader.d.ts.map +1 -1
- package/dist/routes/loader.js +167 -0
- package/dist/routes/resolved-bundle.d.ts +79 -0
- package/dist/routes/resolved-bundle.d.ts.map +1 -0
- package/dist/routes/resolved-bundle.js +148 -0
- package/dist/routes/sampling-config.d.ts +32 -0
- package/dist/routes/sampling-config.d.ts.map +1 -0
- package/dist/routes/sampling-config.js +91 -0
- package/dist/run/ajv.d.ts +22 -0
- package/dist/run/ajv.d.ts.map +1 -0
- package/dist/run/ajv.js +32 -0
- package/dist/run/cache-handle.d.ts +58 -0
- package/dist/run/cache-handle.d.ts.map +1 -0
- package/dist/run/cache-handle.js +54 -0
- package/dist/run/cache-stamp.d.ts +65 -0
- package/dist/run/cache-stamp.d.ts.map +1 -0
- package/dist/run/cache-stamp.js +0 -0
- package/dist/run/capture-write.d.ts +33 -0
- package/dist/run/capture-write.d.ts.map +1 -0
- package/dist/run/capture-write.js +55 -0
- package/dist/run/cost.d.ts.map +1 -1
- package/dist/run/cost.js +1 -1
- package/dist/run/dispatch.d.ts +99 -0
- package/dist/run/dispatch.d.ts.map +1 -0
- package/dist/run/dispatch.js +191 -0
- package/dist/run/raw.d.ts +130 -0
- package/dist/run/raw.d.ts.map +1 -0
- package/dist/run/raw.js +363 -0
- package/dist/run/record-attempt.d.ts +40 -0
- package/dist/run/record-attempt.d.ts.map +1 -0
- package/dist/run/record-attempt.js +99 -0
- package/dist/run/resolve.d.ts +75 -2
- package/dist/run/resolve.d.ts.map +1 -1
- package/dist/run/resolve.js +126 -4
- package/dist/run/run.d.ts +14 -0
- package/dist/run/run.d.ts.map +1 -1
- package/dist/run/run.js +0 -0
- package/dist/run/stream.d.ts +49 -0
- package/dist/run/stream.d.ts.map +1 -0
- package/dist/run/stream.js +87 -0
- package/dist/run/validate.d.ts.map +1 -1
- package/dist/run/validate.js +6 -7
- package/dist/savings/cache-ledger.d.ts +108 -0
- package/dist/savings/cache-ledger.d.ts.map +1 -0
- package/dist/savings/cache-ledger.js +174 -0
- package/dist/savings/cache-reconcile.d.ts +64 -0
- package/dist/savings/cache-reconcile.d.ts.map +1 -0
- package/dist/savings/cache-reconcile.js +59 -0
- package/dist/savings/cache-stats.d.ts +63 -0
- package/dist/savings/cache-stats.d.ts.map +1 -0
- package/dist/savings/cache-stats.js +108 -0
- package/dist/savings/emit.d.ts +13 -0
- package/dist/savings/emit.d.ts.map +1 -1
- package/dist/savings/emit.js +25 -0
- package/dist/savings/swap-execute.d.ts +14 -0
- package/dist/savings/swap-execute.d.ts.map +1 -1
- package/dist/savings/swap-execute.js +44 -1
- package/dist/savings/swaps-client.d.ts +14 -0
- package/dist/savings/swaps-client.d.ts.map +1 -1
- package/dist/savings/swaps-client.js +16 -2
- package/dist/settings/api-fetcher.d.ts +39 -0
- package/dist/settings/api-fetcher.d.ts.map +1 -0
- package/dist/settings/api-fetcher.js +92 -0
- package/dist/settings/index.d.ts +10 -0
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/settings/index.js +15 -0
- package/dist/settings/task-settings.d.ts +91 -0
- package/dist/settings/task-settings.d.ts.map +1 -0
- package/dist/settings/task-settings.js +116 -0
- package/dist/status.d.ts +77 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +113 -0
- package/dist/telemetry/artifact-store.d.ts +48 -0
- package/dist/telemetry/artifact-store.d.ts.map +1 -0
- package/dist/telemetry/artifact-store.js +189 -0
- package/dist/telemetry/cache-miss-streak.d.ts +79 -0
- package/dist/telemetry/cache-miss-streak.d.ts.map +1 -0
- package/dist/telemetry/cache-miss-streak.js +99 -0
- package/dist/telemetry/capture.d.ts +3 -0
- package/dist/telemetry/capture.d.ts.map +1 -1
- package/dist/telemetry/capture.js +15 -8
- package/dist/telemetry/exporter-setup.d.ts +28 -0
- package/dist/telemetry/exporter-setup.d.ts.map +1 -0
- package/dist/telemetry/exporter-setup.js +34 -0
- package/dist/telemetry/exporter.d.ts +75 -0
- package/dist/telemetry/exporter.d.ts.map +1 -1
- package/dist/telemetry/exporter.js +324 -47
- package/dist/telemetry/health.d.ts +76 -0
- package/dist/telemetry/health.d.ts.map +1 -0
- package/dist/telemetry/health.js +92 -0
- package/dist/telemetry/ingest-protocol.d.ts +152 -3
- package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
- package/dist/telemetry/ingest-protocol.js +204 -4
- package/dist/telemetry/load-error-report.d.ts +24 -0
- package/dist/telemetry/load-error-report.d.ts.map +1 -0
- package/dist/telemetry/load-error-report.js +50 -0
- package/dist/telemetry/otel-map.d.ts +121 -0
- package/dist/telemetry/otel-map.d.ts.map +1 -0
- package/dist/telemetry/otel-map.js +224 -0
- package/dist/telemetry/otel-normalize.d.ts +104 -0
- package/dist/telemetry/otel-normalize.d.ts.map +1 -0
- package/dist/telemetry/otel-normalize.js +530 -0
- package/dist/telemetry/otlp-emitter.d.ts +52 -0
- package/dist/telemetry/otlp-emitter.d.ts.map +1 -0
- package/dist/telemetry/otlp-emitter.js +144 -0
- package/dist/telemetry/otlp-proto.d.ts +29 -0
- package/dist/telemetry/otlp-proto.d.ts.map +1 -0
- package/dist/telemetry/otlp-proto.js +266 -0
- package/dist/telemetry/sinks.d.ts +37 -1
- package/dist/telemetry/sinks.d.ts.map +1 -1
- package/dist/telemetry/sinks.js +121 -30
- package/dist/telemetry/store.d.ts +28 -1
- package/dist/telemetry/store.d.ts.map +1 -1
- package/dist/telemetry/store.js +218 -3
- package/dist/tenancy/api-key-format.d.ts +15 -5
- package/dist/tenancy/api-key-format.d.ts.map +1 -1
- package/dist/tenancy/api-key-format.js +24 -5
- package/dist/types/config-teaching.d.ts +62 -0
- package/dist/types/config-teaching.d.ts.map +1 -0
- package/dist/types/config-teaching.js +183 -0
- package/dist/types/provider.d.ts +147 -1
- package/dist/types/provider.d.ts.map +1 -1
- package/dist/types/provider.js +21 -1
- package/dist/types/route.d.ts +79 -1
- package/dist/types/route.d.ts.map +1 -1
- package/dist/types/telemetry.d.ts +117 -0
- package/dist/types/telemetry.d.ts.map +1 -1
- package/dist/validate-cli.d.ts +12 -0
- package/dist/validate-cli.d.ts.map +1 -0
- package/dist/validate-cli.js +57 -0
- package/dist/verify/capture.d.ts +66 -0
- package/dist/verify/capture.d.ts.map +1 -0
- package/dist/verify/capture.js +180 -0
- package/dist/verify/cli-run.d.ts +23 -0
- package/dist/verify/cli-run.d.ts.map +1 -0
- package/dist/verify/cli-run.js +57 -0
- package/dist/verify/diff.d.ts +48 -0
- package/dist/verify/diff.d.ts.map +1 -0
- package/dist/verify/diff.js +157 -0
- package/dist/verify/index.d.ts +17 -0
- package/dist/verify/index.d.ts.map +1 -0
- package/dist/verify/index.js +24 -0
- package/dist/verify/report.d.ts +14 -0
- package/dist/verify/report.d.ts.map +1 -0
- package/dist/verify/report.js +88 -0
- package/dist/verify/types.d.ts +101 -0
- package/dist/verify/types.d.ts.map +1 -0
- package/dist/verify/types.js +17 -0
- package/dist/verify/verify.d.ts +29 -0
- package/dist/verify/verify.d.ts.map +1 -0
- package/dist/verify/verify.js +148 -0
- package/dist/watch/evaluate.d.ts +162 -3
- package/dist/watch/evaluate.d.ts.map +1 -1
- package/dist/watch/evaluate.js +61 -0
- package/dist/watch/monitor.d.ts +116 -0
- package/dist/watch/monitor.d.ts.map +1 -0
- package/dist/watch/monitor.js +199 -0
- package/dist/watch/proposals.d.ts +20 -4
- package/dist/watch/proposals.d.ts.map +1 -1
- package/dist/watch/proposals.js +31 -3
- package/dist/watch/run.d.ts +33 -0
- package/dist/watch/run.d.ts.map +1 -1
- package/dist/watch/run.js +39 -0
- package/package.json +7 -1
- package/registry/LICENSE +20 -0
- package/registry/leaderboard.json +3639 -0
- package/registry/registry.json +7263 -0
- package/dist/telemetry/supabase-exporter.d.ts +0 -64
- package/dist/telemetry/supabase-exporter.d.ts.map +0 -1
- package/dist/telemetry/supabase-exporter.js +0 -211
package/dist/config.d.ts
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
import type { CapabilityFlag, ProviderId } from "./types/provider";
|
|
7
7
|
export interface RigConfig {
|
|
8
8
|
readonly routesDir: string;
|
|
9
|
+
/** OPTIONAL directory of deployment-bundled INTERNAL infra routes, merged
|
|
10
|
+
* INTO `routesDir`'s routes (union, not replacement) by createRig. The server
|
|
11
|
+
* passes its gateway-internal-routes/ here so run-judge@v1 /
|
|
12
|
+
* analyst-summarize@v1 always resolve, independent of the operator's
|
|
13
|
+
* MODELRIG_ROUTES_DIR. Absent ⇒ exactly the pre-existing single-dir behavior. */
|
|
14
|
+
readonly extraRoutesDir?: string;
|
|
9
15
|
readonly telemetryDbPath: string;
|
|
10
16
|
readonly keys: {
|
|
11
17
|
readonly gemini?: string;
|
|
@@ -58,7 +64,101 @@ export interface RigConfig {
|
|
|
58
64
|
* direct self-host + our own deployments their own database
|
|
59
65
|
*/
|
|
60
66
|
readonly export?: ApiExportConfig | DirectExportConfig;
|
|
67
|
+
/**
|
|
68
|
+
* OTLP span emission (E1) — ADDITIVE alongside `export`, never instead of it.
|
|
69
|
+
* `null` means no endpoint configured ⇒ no emitter is ever constructed and
|
|
70
|
+
* behaviour is unchanged (spec §6a). Set via MODELRIG_OTLP_ENDPOINT (+ optional
|
|
71
|
+
* MODELRIG_OTLP_HEADERS). `loadConfigFromEnv` ALWAYS resolves this (to null or
|
|
72
|
+
* a config) so `/status` can answer "configured|disabled" honestly; the field
|
|
73
|
+
* is optional only so hand-built configs (tests) need not spell out the
|
|
74
|
+
* off case — an absent value is read identically to null.
|
|
75
|
+
*/
|
|
76
|
+
readonly otlp?: OtlpConfig | null;
|
|
77
|
+
/**
|
|
78
|
+
* Artifact / execution-graph namespace (Expansion E2). OFF by default —
|
|
79
|
+
* `enabled: false` (or absent) means the run/artifact SDK surface is inert,
|
|
80
|
+
* the exporter sends protocol v1 byte-identical to before, and zero new rows
|
|
81
|
+
* are written (spec §1.4). Set via `MODELRIG_ARTIFACTS=1`. Like `otlp`,
|
|
82
|
+
* `loadConfigFromEnv` ALWAYS resolves this so `/status` can answer
|
|
83
|
+
* "enabled|disabled" honestly; optional only so hand-built configs need not
|
|
84
|
+
* spell out the off case.
|
|
85
|
+
*/
|
|
86
|
+
readonly artifacts?: ArtifactsConfig;
|
|
87
|
+
}
|
|
88
|
+
/** Scrub mode applied to content BEFORE upload (E2-C chunk B). Default `detect`
|
|
89
|
+
* when content custody is on. */
|
|
90
|
+
export type ScrubMode = "off" | "detect" | "redact" | "block";
|
|
91
|
+
/** Per-rig content-custody config (E2-C chunk A/B). Present ONLY when content
|
|
92
|
+
* custody is turned ON and the transport is configured; ABSENT (the default)
|
|
93
|
+
* means metadata + hash only — today's behaviour, unchanged. Consent, off by
|
|
94
|
+
* default (ruling 6). */
|
|
95
|
+
export interface ArtifactContentConfig {
|
|
96
|
+
/** Full grant endpoint, e.g. https://server/v1/artifacts/uploads. */
|
|
97
|
+
readonly uploadsUrl: string;
|
|
98
|
+
/** `rig_sk_` key with the `artifact-write` scope (header only; never a URL — C2). */
|
|
99
|
+
readonly apiKey: string;
|
|
100
|
+
readonly scrub: ScrubMode;
|
|
101
|
+
/** Client-side ceiling short-circuit; the server enforces the real one. */
|
|
102
|
+
readonly maxBytes: number;
|
|
103
|
+
}
|
|
104
|
+
/** Resolved artifact-namespace config (E2 / E2-C). `enabled` is the E2 gate;
|
|
105
|
+
* `content` (E2-C) is present only when content custody is configured on. */
|
|
106
|
+
export interface ArtifactsConfig {
|
|
107
|
+
readonly enabled: boolean;
|
|
108
|
+
readonly content?: ArtifactContentConfig;
|
|
61
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolve the artifact config from raw env values (E2 / E2-C, default flip §2).
|
|
112
|
+
* Pure — env is read by the caller (the package's sole env-reader rule).
|
|
113
|
+
* MODELRIG_ARTIFACTS unset → namespace ON when a control plane
|
|
114
|
+
* is configured, OFF for local-only
|
|
115
|
+
* (§2: metadata-on by default).
|
|
116
|
+
* MODELRIG_ARTIFACTS=1|true|on → force the namespace ON.
|
|
117
|
+
* MODELRIG_ARTIFACTS=0|false|off → force it OFF (the explicit opt-out).
|
|
118
|
+
* MODELRIG_ARTIFACTS_CONTENT=on|1|true → content custody ON (E2-C).
|
|
119
|
+
* MODELRIG_CONTENT_UPLOAD_URL, MODELRIG_CONTENT_API_KEY → transport.
|
|
120
|
+
* MODELRIG_ARTIFACTS_SCRUB=off|detect|redact|block → scrub mode (default detect).
|
|
121
|
+
* MODELRIG_CONTENT_MAX_BYTES → client ceiling (default 50MB).
|
|
122
|
+
* Content custody stays OFF (content absent) unless it is explicitly on AND the
|
|
123
|
+
* transport is fully configured — a half-configured custody is refused into the
|
|
124
|
+
* safe default (metadata only), never silently half-on. The metadata default
|
|
125
|
+
* flip does NOT flip content: content is its own gate (§2 "content unchanged").
|
|
126
|
+
*/
|
|
127
|
+
export declare function resolveArtifactsConfig(env: {
|
|
128
|
+
readonly artifacts?: string;
|
|
129
|
+
readonly content?: string;
|
|
130
|
+
readonly uploadsUrl?: string;
|
|
131
|
+
readonly apiKey?: string;
|
|
132
|
+
readonly scrub?: string;
|
|
133
|
+
readonly maxBytes?: string;
|
|
134
|
+
},
|
|
135
|
+
/** Is a cloud sink (api or direct) configured? Unset gate defaults ON when so,
|
|
136
|
+
* OFF otherwise. Defaults false so existing callers/tests keep local-only
|
|
137
|
+
* semantics (gate-only) unless they opt into the flip. */
|
|
138
|
+
controlPlaneConfigured?: boolean): ArtifactsConfig;
|
|
139
|
+
/** Resolved OTLP config (E1). Endpoint + sink-auth headers only; the emitter
|
|
140
|
+
* derives batch/interval + watermark from defaults + the source id. */
|
|
141
|
+
export interface OtlpConfig {
|
|
142
|
+
/** OTLP/HTTP traces endpoint. NEVER logged/displayed — may embed a token (C2). */
|
|
143
|
+
readonly endpoint: string;
|
|
144
|
+
/** Sink auth headers from MODELRIG_OTLP_HEADERS (`k=v,k=v`). NEVER logged (C2). */
|
|
145
|
+
readonly headers: Record<string, string>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Parse `MODELRIG_OTLP_HEADERS` ("k=v,k=v") into a header map (E1). Split on the
|
|
149
|
+
* FIRST `=` only, so a base64 Basic-auth value keeping its `=` padding survives.
|
|
150
|
+
* Blank/whitespace pairs and pairs with an empty key are dropped. Pure — env is
|
|
151
|
+
* read by the caller, this only shapes the string (keeps this file the sole
|
|
152
|
+
* env reader without smearing parsing into it).
|
|
153
|
+
*/
|
|
154
|
+
export declare function parseOtlpHeaders(raw: string | undefined): Record<string, string>;
|
|
155
|
+
/**
|
|
156
|
+
* Resolve the OTLP config from raw env values (E1). Pure so it is testable
|
|
157
|
+
* without touching `process.env` (the package-invariants env-reader rule) —
|
|
158
|
+
* `loadConfigFromEnv` reads the two vars and hands them here. A blank/absent
|
|
159
|
+
* endpoint ⇒ `null` = off by default (spec §6a).
|
|
160
|
+
*/
|
|
161
|
+
export declare function resolveOtlpConfig(endpoint: string | undefined, headersRaw: string | undefined): OtlpConfig | null;
|
|
62
162
|
interface ExportCommon {
|
|
63
163
|
readonly sourceId?: string;
|
|
64
164
|
readonly batchSize?: number;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MA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EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAED;;kEAEkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ7D,CAAC;AAKF,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAgI3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,GACX;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAgB/F"}
|
package/dist/config.js
CHANGED
|
@@ -6,9 +6,94 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.PROVIDER_KEY_ENV = void 0;
|
|
9
|
+
exports.resolveArtifactsConfig = resolveArtifactsConfig;
|
|
10
|
+
exports.parseOtlpHeaders = parseOtlpHeaders;
|
|
11
|
+
exports.resolveOtlpConfig = resolveOtlpConfig;
|
|
9
12
|
exports.loadConfigFromEnv = loadConfigFromEnv;
|
|
10
13
|
exports.directExportOf = directExportOf;
|
|
11
14
|
const ingest_protocol_1 = require("./telemetry/ingest-protocol");
|
|
15
|
+
const DEFAULT_SDK_CONTENT_MAX_BYTES = 52428800;
|
|
16
|
+
function resolveScrubMode(raw, contentOn) {
|
|
17
|
+
const v = (raw ?? "").trim().toLowerCase();
|
|
18
|
+
if (v === "off" || v === "detect" || v === "redact" || v === "block")
|
|
19
|
+
return v;
|
|
20
|
+
// Default when content is on is `detect` — scan and count, upload verbatim.
|
|
21
|
+
return contentOn ? "detect" : "off";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the artifact config from raw env values (E2 / E2-C, default flip §2).
|
|
25
|
+
* Pure — env is read by the caller (the package's sole env-reader rule).
|
|
26
|
+
* MODELRIG_ARTIFACTS unset → namespace ON when a control plane
|
|
27
|
+
* is configured, OFF for local-only
|
|
28
|
+
* (§2: metadata-on by default).
|
|
29
|
+
* MODELRIG_ARTIFACTS=1|true|on → force the namespace ON.
|
|
30
|
+
* MODELRIG_ARTIFACTS=0|false|off → force it OFF (the explicit opt-out).
|
|
31
|
+
* MODELRIG_ARTIFACTS_CONTENT=on|1|true → content custody ON (E2-C).
|
|
32
|
+
* MODELRIG_CONTENT_UPLOAD_URL, MODELRIG_CONTENT_API_KEY → transport.
|
|
33
|
+
* MODELRIG_ARTIFACTS_SCRUB=off|detect|redact|block → scrub mode (default detect).
|
|
34
|
+
* MODELRIG_CONTENT_MAX_BYTES → client ceiling (default 50MB).
|
|
35
|
+
* Content custody stays OFF (content absent) unless it is explicitly on AND the
|
|
36
|
+
* transport is fully configured — a half-configured custody is refused into the
|
|
37
|
+
* safe default (metadata only), never silently half-on. The metadata default
|
|
38
|
+
* flip does NOT flip content: content is its own gate (§2 "content unchanged").
|
|
39
|
+
*/
|
|
40
|
+
function resolveArtifactsConfig(env,
|
|
41
|
+
/** Is a cloud sink (api or direct) configured? Unset gate defaults ON when so,
|
|
42
|
+
* OFF otherwise. Defaults false so existing callers/tests keep local-only
|
|
43
|
+
* semantics (gate-only) unless they opt into the flip. */
|
|
44
|
+
controlPlaneConfigured = false) {
|
|
45
|
+
const gate = (env.artifacts ?? "").trim().toLowerCase();
|
|
46
|
+
const explicitOn = gate === "1" || gate === "true" || gate === "on";
|
|
47
|
+
const explicitOff = gate === "0" || gate === "false" || gate === "off";
|
|
48
|
+
// §2 default flip: explicit wins; an unset gate follows the control plane.
|
|
49
|
+
const enabled = explicitOn || (!explicitOff && controlPlaneConfigured);
|
|
50
|
+
const contentGate = (env.content ?? "").trim().toLowerCase();
|
|
51
|
+
const contentOn = contentGate === "on" || contentGate === "1" || contentGate === "true";
|
|
52
|
+
const uploadsUrl = (env.uploadsUrl ?? "").trim();
|
|
53
|
+
const apiKey = (env.apiKey ?? "").trim();
|
|
54
|
+
const maxBytesRaw = env.maxBytes !== undefined && env.maxBytes !== "" ? Number(env.maxBytes) : NaN;
|
|
55
|
+
const maxBytes = Number.isInteger(maxBytesRaw) && maxBytesRaw > 0 ? maxBytesRaw : DEFAULT_SDK_CONTENT_MAX_BYTES;
|
|
56
|
+
// Content is on ONLY when the namespace is enabled, the gate is on, AND the
|
|
57
|
+
// transport is present. Missing transport → stays metadata-only (fail-safe).
|
|
58
|
+
const content = enabled && contentOn && uploadsUrl !== "" && apiKey !== ""
|
|
59
|
+
? { uploadsUrl, apiKey, scrub: resolveScrubMode(env.scrub, true), maxBytes }
|
|
60
|
+
: undefined;
|
|
61
|
+
return { enabled, ...(content !== undefined ? { content } : {}) };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse `MODELRIG_OTLP_HEADERS` ("k=v,k=v") into a header map (E1). Split on the
|
|
65
|
+
* FIRST `=` only, so a base64 Basic-auth value keeping its `=` padding survives.
|
|
66
|
+
* Blank/whitespace pairs and pairs with an empty key are dropped. Pure — env is
|
|
67
|
+
* read by the caller, this only shapes the string (keeps this file the sole
|
|
68
|
+
* env reader without smearing parsing into it).
|
|
69
|
+
*/
|
|
70
|
+
function parseOtlpHeaders(raw) {
|
|
71
|
+
const out = {};
|
|
72
|
+
if (raw === undefined || raw.trim() === "")
|
|
73
|
+
return out;
|
|
74
|
+
for (const pair of raw.split(",")) {
|
|
75
|
+
const eq = pair.indexOf("=");
|
|
76
|
+
if (eq === -1)
|
|
77
|
+
continue;
|
|
78
|
+
const key = pair.slice(0, eq).trim();
|
|
79
|
+
const value = pair.slice(eq + 1).trim();
|
|
80
|
+
if (key === "")
|
|
81
|
+
continue;
|
|
82
|
+
out[key] = value;
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resolve the OTLP config from raw env values (E1). Pure so it is testable
|
|
88
|
+
* without touching `process.env` (the package-invariants env-reader rule) —
|
|
89
|
+
* `loadConfigFromEnv` reads the two vars and hands them here. A blank/absent
|
|
90
|
+
* endpoint ⇒ `null` = off by default (spec §6a).
|
|
91
|
+
*/
|
|
92
|
+
function resolveOtlpConfig(endpoint, headersRaw) {
|
|
93
|
+
if (endpoint === undefined || endpoint.trim() === "")
|
|
94
|
+
return null;
|
|
95
|
+
return { endpoint: endpoint.trim(), headers: parseOtlpHeaders(headersRaw) };
|
|
96
|
+
}
|
|
12
97
|
/** Provider → the env var that keys it. One table so error surfaces can say
|
|
13
98
|
* WHICH variable to set rather than "no key configured" (F1 / WS3: errors
|
|
14
99
|
* that teach). `loadConfigFromEnv` below reads the same names. */
|
|
@@ -30,9 +115,28 @@ function loadConfigFromEnv(overrides) {
|
|
|
30
115
|
const supabaseUrl = env.MODELRIG_SUPABASE_URL;
|
|
31
116
|
const serviceRoleKey = env.MODELRIG_SUPABASE_SERVICE_ROLE_KEY;
|
|
32
117
|
const apiKey = env.MODELRIG_API_KEY;
|
|
118
|
+
// OTLP span emission (E1) — off unless an endpoint is set. Additive to
|
|
119
|
+
// `export`; a rig may emit OTLP with no control-plane sink and vice-versa.
|
|
120
|
+
const otlp = resolveOtlpConfig(env.MODELRIG_OTLP_ENDPOINT, env.MODELRIG_OTLP_HEADERS);
|
|
121
|
+
// Artifact / execution-graph namespace (E2, default flip §2) — ON by default
|
|
122
|
+
// when a control plane is configured (api key OR the direct supabase pair),
|
|
123
|
+
// OFF for a pure local-only rig; MODELRIG_ARTIFACTS=0 is the explicit opt-out.
|
|
124
|
+
// Always resolved so /status + the boot banner answer honestly. Content
|
|
125
|
+
// custody (E2-C) stays its own gate — the metadata flip never flips content.
|
|
126
|
+
const controlPlaneConfigured = Boolean(apiKey) || Boolean(supabaseUrl && serviceRoleKey);
|
|
127
|
+
const artifacts = resolveArtifactsConfig({
|
|
128
|
+
artifacts: env.MODELRIG_ARTIFACTS,
|
|
129
|
+
content: env.MODELRIG_ARTIFACTS_CONTENT,
|
|
130
|
+
uploadsUrl: env.MODELRIG_CONTENT_UPLOAD_URL,
|
|
131
|
+
apiKey: env.MODELRIG_CONTENT_API_KEY ?? env.MODELRIG_API_KEY,
|
|
132
|
+
scrub: env.MODELRIG_ARTIFACTS_SCRUB,
|
|
133
|
+
maxBytes: env.MODELRIG_CONTENT_MAX_BYTES,
|
|
134
|
+
}, controlPlaneConfigured);
|
|
33
135
|
const fromEnv = {
|
|
34
136
|
routesDir: env.MODELRIG_ROUTES_DIR ?? DEFAULT_ROUTES_DIR,
|
|
35
137
|
telemetryDbPath: env.MODELRIG_TELEMETRY_DB ?? DEFAULT_TELEMETRY_DB,
|
|
138
|
+
otlp,
|
|
139
|
+
artifacts,
|
|
36
140
|
...(env.MODELRIG_REGISTRY_PATH ? { registryPath: env.MODELRIG_REGISTRY_PATH } : {}),
|
|
37
141
|
keys: {
|
|
38
142
|
...(env.GEMINI_API_KEY ? { gemini: env.GEMINI_API_KEY } : {}),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loud, one-time deprecation warnings (settings-plane §3).
|
|
3
|
+
*
|
|
4
|
+
* Two flags are on their way out now that governance lives in the control plane:
|
|
5
|
+
* • YAML `capture:` — IGNORED when a control plane is configured; capture is a
|
|
6
|
+
* task setting (console / API / MCP). Honored only for local-only rigs.
|
|
7
|
+
* • the `direct` sink (MODELRIG_SUPABASE_*) — the supported path is api mode
|
|
8
|
+
* (a `rig_sk_` key). Still works; will be removed (Matt's §0-row-5 decision).
|
|
9
|
+
*
|
|
10
|
+
* "Loud, never silent divergence" (spec §1.5): each warning fires ONCE per
|
|
11
|
+
* process (a module-level guard) so a user learns their YAML flag is being
|
|
12
|
+
* ignored, rather than quietly diverging from the console. The parked chunk-0.2
|
|
13
|
+
* commit carried no warn-once mechanism, so it is authored here from scratch.
|
|
14
|
+
*/
|
|
15
|
+
import type { RigConfig } from "./config";
|
|
16
|
+
import type { RouteBundle } from "./types/route";
|
|
17
|
+
/**
|
|
18
|
+
* Warn (once) that YAML `capture:` is ignored under a control plane. Fires only
|
|
19
|
+
* when a control plane is configured AND at least one loaded route still sets
|
|
20
|
+
* `capture: true` in YAML — a local-only rig keeps YAML as its mechanism and
|
|
21
|
+
* hears nothing.
|
|
22
|
+
*/
|
|
23
|
+
export declare function warnYamlCaptureDeprecated(routes: readonly RouteBundle[], controlPlaneConfigured: boolean): void;
|
|
24
|
+
/**
|
|
25
|
+
* Warn (once) that the `direct` sink is deprecated, naming api mode as the path.
|
|
26
|
+
* Fires only for a rig actually configured in direct mode.
|
|
27
|
+
*/
|
|
28
|
+
export declare function warnDirectSinkDeprecated(config: RigConfig): void;
|
|
29
|
+
/** Reset the once-per-process guards — TESTS ONLY, so warn-once cases are
|
|
30
|
+
* independent of run order. */
|
|
31
|
+
export declare function __resetDeprecationWarningsForTest(): void;
|
|
32
|
+
//# sourceMappingURL=deprecations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecations.d.ts","sourceRoot":"","sources":["../src/deprecations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAKjD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,sBAAsB,EAAE,OAAO,GAC9B,IAAI,CAYN;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAShE;AAED;+BAC+B;AAC/B,wBAAgB,iCAAiC,IAAI,IAAI,CAGxD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Loud, one-time deprecation warnings (settings-plane §3).
|
|
4
|
+
*
|
|
5
|
+
* Two flags are on their way out now that governance lives in the control plane:
|
|
6
|
+
* • YAML `capture:` — IGNORED when a control plane is configured; capture is a
|
|
7
|
+
* task setting (console / API / MCP). Honored only for local-only rigs.
|
|
8
|
+
* • the `direct` sink (MODELRIG_SUPABASE_*) — the supported path is api mode
|
|
9
|
+
* (a `rig_sk_` key). Still works; will be removed (Matt's §0-row-5 decision).
|
|
10
|
+
*
|
|
11
|
+
* "Loud, never silent divergence" (spec §1.5): each warning fires ONCE per
|
|
12
|
+
* process (a module-level guard) so a user learns their YAML flag is being
|
|
13
|
+
* ignored, rather than quietly diverging from the console. The parked chunk-0.2
|
|
14
|
+
* commit carried no warn-once mechanism, so it is authored here from scratch.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.warnYamlCaptureDeprecated = warnYamlCaptureDeprecated;
|
|
18
|
+
exports.warnDirectSinkDeprecated = warnDirectSinkDeprecated;
|
|
19
|
+
exports.__resetDeprecationWarningsForTest = __resetDeprecationWarningsForTest;
|
|
20
|
+
let yamlCaptureWarned = false;
|
|
21
|
+
let directSinkWarned = false;
|
|
22
|
+
/**
|
|
23
|
+
* Warn (once) that YAML `capture:` is ignored under a control plane. Fires only
|
|
24
|
+
* when a control plane is configured AND at least one loaded route still sets
|
|
25
|
+
* `capture: true` in YAML — a local-only rig keeps YAML as its mechanism and
|
|
26
|
+
* hears nothing.
|
|
27
|
+
*/
|
|
28
|
+
function warnYamlCaptureDeprecated(routes, controlPlaneConfigured) {
|
|
29
|
+
if (yamlCaptureWarned || !controlPlaneConfigured)
|
|
30
|
+
return;
|
|
31
|
+
const withCapture = routes.filter((b) => b.capture).map((b) => b.route);
|
|
32
|
+
if (withCapture.length === 0)
|
|
33
|
+
return;
|
|
34
|
+
yamlCaptureWarned = true;
|
|
35
|
+
console.warn(`[modelrig] DEPRECATED: ${withCapture.length} route(s) set \`capture:\` in YAML ` +
|
|
36
|
+
`(${withCapture.join(", ")}). This flag is IGNORED when a control plane is configured — ` +
|
|
37
|
+
"capture is a task setting now. Set it in the console, the API " +
|
|
38
|
+
"(PATCH /v1/tasks/:task/settings), or via the MCP tool. YAML `capture:` is honored only " +
|
|
39
|
+
"for local-only rigs (no control plane).");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Warn (once) that the `direct` sink is deprecated, naming api mode as the path.
|
|
43
|
+
* Fires only for a rig actually configured in direct mode.
|
|
44
|
+
*/
|
|
45
|
+
function warnDirectSinkDeprecated(config) {
|
|
46
|
+
if (directSinkWarned || config.export?.mode !== "direct")
|
|
47
|
+
return;
|
|
48
|
+
directSinkWarned = true;
|
|
49
|
+
console.warn("[modelrig] DEPRECATED: the `direct` sink (MODELRIG_SUPABASE_URL + " +
|
|
50
|
+
"MODELRIG_SUPABASE_SERVICE_ROLE_KEY) is on its way out. The supported path is api mode — " +
|
|
51
|
+
"a `rig_sk_` key in MODELRIG_API_KEY, no database credentials in the client. Direct mode " +
|
|
52
|
+
"still works; migrate when convenient.");
|
|
53
|
+
}
|
|
54
|
+
/** Reset the once-per-process guards — TESTS ONLY, so warn-once cases are
|
|
55
|
+
* independent of run order. */
|
|
56
|
+
function __resetDeprecationWarningsForTest() {
|
|
57
|
+
yamlCaptureWarned = false;
|
|
58
|
+
directSinkWarned = false;
|
|
59
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP gateway wire contract — G-1/G-5 (http-gateway spec §3, §4.3, §4.4).
|
|
3
|
+
*
|
|
4
|
+
* ONE definition of what a `/v1/chat/completions` request, response, and SSE
|
|
5
|
+
* chunk look like, plus the lane-disambiguation rule and the `x-modelrig-*`
|
|
6
|
+
* provenance headers. Both sides compile against it:
|
|
7
|
+
*
|
|
8
|
+
* SDK (`packages/modelrig`) — this repo; consumes the streaming/tool
|
|
9
|
+
* surfaces the endpoint is built on.
|
|
10
|
+
* `modelrig-server` — separate repo (Phase B/C); implements the
|
|
11
|
+
* endpoint and imports these types so the wire
|
|
12
|
+
* shape cannot drift between the two.
|
|
13
|
+
*
|
|
14
|
+
* This mirrors `telemetry/ingest-protocol.ts`: a shared module is what makes
|
|
15
|
+
* "the two sides agree" enforceable rather than aspirational — a contract test
|
|
16
|
+
* round-trips the shapes on both sides instead of comparing two hand-written
|
|
17
|
+
* copies for similarity.
|
|
18
|
+
*
|
|
19
|
+
* TYPES + PURE FUNCTIONS ONLY. No transport, no auth, no I/O — the endpoint,
|
|
20
|
+
* SSE plumbing, and BYOK key resolution live server-side (spec §2).
|
|
21
|
+
*/
|
|
22
|
+
import type { ToolCall, ToolChoice, ToolDefinition } from "../types/provider";
|
|
23
|
+
/** The endpoint path. Spelled once. */
|
|
24
|
+
export declare const CHAT_COMPLETIONS_PATH = "/v1/chat/completions";
|
|
25
|
+
/** The model-catalog path (routes + registry models) for SDK discovery. */
|
|
26
|
+
export declare const MODELS_PATH = "/v1/models";
|
|
27
|
+
/** Bumped only for a breaking change to the shapes below. */
|
|
28
|
+
export declare const GATEWAY_PROTOCOL_VERSION = 1;
|
|
29
|
+
export declare const MODELRIG_HEADERS: {
|
|
30
|
+
/** "slug" (verified pipeline) or "raw" (zero-margin BYOK passthrough). */
|
|
31
|
+
readonly lane: "x-modelrig-lane";
|
|
32
|
+
/** Phase D (spec §13.1 rule 4): where the slug lane resolved its bundle —
|
|
33
|
+
* "local" (this deployment's own routes, the self-host path) or "mirror" (the
|
|
34
|
+
* org-scoped `routes` mirror, the hosted path). A deployment serves ONE or the
|
|
35
|
+
* OTHER and SAYS WHICH; the two must never silently blend. Absent on the raw
|
|
36
|
+
* lane. */
|
|
37
|
+
readonly routeSource: "x-modelrig-route-source";
|
|
38
|
+
readonly provider: "x-modelrig-provider";
|
|
39
|
+
readonly model: "x-modelrig-model";
|
|
40
|
+
/** "true"/"false" — was the output schema-validated (slug lane only). */
|
|
41
|
+
readonly validated: "x-modelrig-validated";
|
|
42
|
+
/** "provider/model" that repaired the output, when repair fired. */
|
|
43
|
+
readonly repairedBy: "x-modelrig-repaired-by";
|
|
44
|
+
readonly costUsd: "x-modelrig-cost-usd";
|
|
45
|
+
/** The `rig.feedback()` handle (telemetry inference id). */
|
|
46
|
+
readonly inferenceId: "x-modelrig-inference-id";
|
|
47
|
+
};
|
|
48
|
+
export declare const MODELRIG_REQUEST_HEADERS: {
|
|
49
|
+
/** Per-run envelope key (budget). */
|
|
50
|
+
readonly envelope: "x-modelrig-envelope";
|
|
51
|
+
/** Named route variant to serve. */
|
|
52
|
+
readonly variant: "x-modelrig-variant";
|
|
53
|
+
/** "buffered" opts out of true streaming for validated-only output (§4.3). */
|
|
54
|
+
readonly stream: "x-modelrig-stream";
|
|
55
|
+
};
|
|
56
|
+
export type Lane = "slug" | "raw";
|
|
57
|
+
/** The disambiguation verdict for a request's `model` field (spec §3.3). */
|
|
58
|
+
export type LaneResolution = {
|
|
59
|
+
readonly lane: "slug";
|
|
60
|
+
readonly slug: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly lane: "raw";
|
|
63
|
+
readonly provider: string;
|
|
64
|
+
readonly model: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly lane: "unknown";
|
|
67
|
+
readonly reason: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The core routing rule (spec §3.3), as a pure function so both sides classify
|
|
71
|
+
* a `model` string identically:
|
|
72
|
+
* 1. `@rig/…` OR an exact known route slug → slug lane (verified pipeline).
|
|
73
|
+
* 2. `^<providerId>/<model>$`, providerId ∈ PROVIDER_IDS → raw-model lane.
|
|
74
|
+
* 3. otherwise → unknown (the endpoint 404s; never silently guess).
|
|
75
|
+
*
|
|
76
|
+
* The namespaces don't collide: a route slug is a bare handle
|
|
77
|
+
* (`example.support_summarize`); a raw model always carries a known
|
|
78
|
+
* `provider/` prefix.
|
|
79
|
+
*/
|
|
80
|
+
export declare function classifyLane(model: string, knownRouteSlugs?: ReadonlySet<string>): LaneResolution;
|
|
81
|
+
export interface ChatMessage {
|
|
82
|
+
readonly role: "system" | "user" | "assistant" | "tool";
|
|
83
|
+
readonly content: string | null;
|
|
84
|
+
/** Assistant turns that called tools carry them (echoed OpenAI shape). */
|
|
85
|
+
readonly tool_calls?: readonly ToolCall[];
|
|
86
|
+
/** `tool` role replies reference the call they answer. */
|
|
87
|
+
readonly tool_call_id?: string;
|
|
88
|
+
readonly name?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ChatCompletionRequest {
|
|
91
|
+
readonly model: string;
|
|
92
|
+
readonly messages: readonly ChatMessage[];
|
|
93
|
+
readonly stream?: boolean;
|
|
94
|
+
readonly temperature?: number;
|
|
95
|
+
readonly top_p?: number;
|
|
96
|
+
readonly max_tokens?: number;
|
|
97
|
+
readonly tools?: readonly ToolDefinition[];
|
|
98
|
+
readonly tool_choice?: ToolChoice;
|
|
99
|
+
/** OpenAI structured-output request; the slug lane maps it to the route. */
|
|
100
|
+
readonly response_format?: {
|
|
101
|
+
readonly type: "text";
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: "json_object";
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "json_schema";
|
|
106
|
+
readonly json_schema: {
|
|
107
|
+
readonly name: string;
|
|
108
|
+
readonly schema: object;
|
|
109
|
+
readonly strict?: boolean;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/** ModelRig extensions may ride here instead of headers (spec §3.4). */
|
|
113
|
+
readonly modelrig?: {
|
|
114
|
+
readonly envelope?: string;
|
|
115
|
+
readonly variant?: string;
|
|
116
|
+
readonly stream?: "buffered";
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export interface ChatCompletionUsage {
|
|
120
|
+
readonly prompt_tokens: number;
|
|
121
|
+
readonly completion_tokens: number;
|
|
122
|
+
readonly total_tokens: number;
|
|
123
|
+
}
|
|
124
|
+
export interface ChatCompletionChoice {
|
|
125
|
+
readonly index: number;
|
|
126
|
+
readonly message: {
|
|
127
|
+
readonly role: "assistant";
|
|
128
|
+
readonly content: string | null;
|
|
129
|
+
readonly tool_calls?: readonly ToolCall[];
|
|
130
|
+
};
|
|
131
|
+
readonly finish_reason: "stop" | "length" | "tool_calls" | "content_filter" | null;
|
|
132
|
+
}
|
|
133
|
+
export interface ChatCompletionResponse {
|
|
134
|
+
readonly id: string;
|
|
135
|
+
readonly object: "chat.completion";
|
|
136
|
+
readonly created: number;
|
|
137
|
+
readonly model: string;
|
|
138
|
+
readonly choices: readonly ChatCompletionChoice[];
|
|
139
|
+
readonly usage: ChatCompletionUsage;
|
|
140
|
+
}
|
|
141
|
+
export interface ChatCompletionChunkChoice {
|
|
142
|
+
readonly index: number;
|
|
143
|
+
readonly delta: {
|
|
144
|
+
readonly role?: "assistant";
|
|
145
|
+
readonly content?: string | null;
|
|
146
|
+
readonly tool_calls?: readonly ToolCall[];
|
|
147
|
+
};
|
|
148
|
+
readonly finish_reason: ChatCompletionChoice["finish_reason"];
|
|
149
|
+
}
|
|
150
|
+
export interface ChatCompletionChunk {
|
|
151
|
+
readonly id: string;
|
|
152
|
+
readonly object: "chat.completion.chunk";
|
|
153
|
+
readonly created: number;
|
|
154
|
+
readonly model: string;
|
|
155
|
+
readonly choices: readonly ChatCompletionChunkChoice[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The structured-route terminal event (spec §4.3). Streamed bytes on a
|
|
159
|
+
* structured route are PRE-validation; the endpoint closes the stream with this
|
|
160
|
+
* authoritative event (as a chunk with a `modelrig` extension) before
|
|
161
|
+
* `data: [DONE]`. It carries the validation verdict and, when repair fired, the
|
|
162
|
+
* repaired final object.
|
|
163
|
+
*/
|
|
164
|
+
export interface TerminalValidationEvent {
|
|
165
|
+
readonly object: "modelrig.validation";
|
|
166
|
+
readonly validated: boolean;
|
|
167
|
+
/** The validated (and possibly repaired) output object. */
|
|
168
|
+
readonly output: unknown;
|
|
169
|
+
readonly repairedBy: string | null;
|
|
170
|
+
readonly inferenceId: string;
|
|
171
|
+
readonly errors?: readonly string[];
|
|
172
|
+
}
|
|
173
|
+
/** The SSE sentinel that closes an OpenAI-compatible stream. */
|
|
174
|
+
export declare const SSE_DONE = "[DONE]";
|
|
175
|
+
//# sourceMappingURL=http-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-protocol.d.ts","sourceRoot":"","sources":["../../src/gateway/http-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,uCAAuC;AACvC,eAAO,MAAM,qBAAqB,yBAAyB,CAAC;AAC5D,2EAA2E;AAC3E,eAAO,MAAM,WAAW,eAAe,CAAC;AAExC,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAO1C,eAAO,MAAM,gBAAgB;IAC3B,0EAA0E;;IAE1E;;;;eAIW;;;;IAIX,yEAAyE;;IAEzE,oEAAoE;;;IAGpE,4DAA4D;;CAEpD,CAAC;AAGX,eAAO,MAAM,wBAAwB;IACnC,qCAAqC;;IAErC,oCAAoC;;IAEpC,8EAA8E;;CAEtE,CAAC;AAEX,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;AAElC,4EAA4E;AAC5E,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC3E;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D;;;;;;;;;;GAUG;A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,KAAK,EAAE;QACd,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC;QAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;KAC3C,CAAC;IACF,QAAQ,CAAC,aAAa,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,yBAAyB,EAAE,CAAC;CACxD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,gEAAgE;AAChE,eAAO,MAAM,QAAQ,WAAW,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The HTTP gateway wire contract — G-1/G-5 (http-gateway spec §3, §4.3, §4.4).
|
|
4
|
+
*
|
|
5
|
+
* ONE definition of what a `/v1/chat/completions` request, response, and SSE
|
|
6
|
+
* chunk look like, plus the lane-disambiguation rule and the `x-modelrig-*`
|
|
7
|
+
* provenance headers. Both sides compile against it:
|
|
8
|
+
*
|
|
9
|
+
* SDK (`packages/modelrig`) — this repo; consumes the streaming/tool
|
|
10
|
+
* surfaces the endpoint is built on.
|
|
11
|
+
* `modelrig-server` — separate repo (Phase B/C); implements the
|
|
12
|
+
* endpoint and imports these types so the wire
|
|
13
|
+
* shape cannot drift between the two.
|
|
14
|
+
*
|
|
15
|
+
* This mirrors `telemetry/ingest-protocol.ts`: a shared module is what makes
|
|
16
|
+
* "the two sides agree" enforceable rather than aspirational — a contract test
|
|
17
|
+
* round-trips the shapes on both sides instead of comparing two hand-written
|
|
18
|
+
* copies for similarity.
|
|
19
|
+
*
|
|
20
|
+
* TYPES + PURE FUNCTIONS ONLY. No transport, no auth, no I/O — the endpoint,
|
|
21
|
+
* SSE plumbing, and BYOK key resolution live server-side (spec §2).
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.SSE_DONE = exports.MODELRIG_REQUEST_HEADERS = exports.MODELRIG_HEADERS = exports.GATEWAY_PROTOCOL_VERSION = exports.MODELS_PATH = exports.CHAT_COMPLETIONS_PATH = void 0;
|
|
25
|
+
exports.classifyLane = classifyLane;
|
|
26
|
+
const provider_1 = require("../types/provider");
|
|
27
|
+
/** The endpoint path. Spelled once. */
|
|
28
|
+
exports.CHAT_COMPLETIONS_PATH = "/v1/chat/completions";
|
|
29
|
+
/** The model-catalog path (routes + registry models) for SDK discovery. */
|
|
30
|
+
exports.MODELS_PATH = "/v1/models";
|
|
31
|
+
/** Bumped only for a breaking change to the shapes below. */
|
|
32
|
+
exports.GATEWAY_PROTOCOL_VERSION = 1;
|
|
33
|
+
// ── Provenance headers (spec §3.4) ───────────────────────────────────────────
|
|
34
|
+
// Response headers that make a completion auditable: which lane served it,
|
|
35
|
+
// which provider/model actually ran, whether the output was verified, and the
|
|
36
|
+
// feedback handle. Named once so the SDK, the server, and the console cannot
|
|
37
|
+
// disagree about the spelling.
|
|
38
|
+
exports.MODELRIG_HEADERS = {
|
|
39
|
+
/** "slug" (verified pipeline) or "raw" (zero-margin BYOK passthrough). */
|
|
40
|
+
lane: "x-modelrig-lane",
|
|
41
|
+
/** Phase D (spec §13.1 rule 4): where the slug lane resolved its bundle —
|
|
42
|
+
* "local" (this deployment's own routes, the self-host path) or "mirror" (the
|
|
43
|
+
* org-scoped `routes` mirror, the hosted path). A deployment serves ONE or the
|
|
44
|
+
* OTHER and SAYS WHICH; the two must never silently blend. Absent on the raw
|
|
45
|
+
* lane. */
|
|
46
|
+
routeSource: "x-modelrig-route-source",
|
|
47
|
+
provider: "x-modelrig-provider",
|
|
48
|
+
model: "x-modelrig-model",
|
|
49
|
+
/** "true"/"false" — was the output schema-validated (slug lane only). */
|
|
50
|
+
validated: "x-modelrig-validated",
|
|
51
|
+
/** "provider/model" that repaired the output, when repair fired. */
|
|
52
|
+
repairedBy: "x-modelrig-repaired-by",
|
|
53
|
+
costUsd: "x-modelrig-cost-usd",
|
|
54
|
+
/** The `rig.feedback()` handle (telemetry inference id). */
|
|
55
|
+
inferenceId: "x-modelrig-inference-id",
|
|
56
|
+
};
|
|
57
|
+
// Request-side extension headers (spec §3.4).
|
|
58
|
+
exports.MODELRIG_REQUEST_HEADERS = {
|
|
59
|
+
/** Per-run envelope key (budget). */
|
|
60
|
+
envelope: "x-modelrig-envelope",
|
|
61
|
+
/** Named route variant to serve. */
|
|
62
|
+
variant: "x-modelrig-variant",
|
|
63
|
+
/** "buffered" opts out of true streaming for validated-only output (§4.3). */
|
|
64
|
+
stream: "x-modelrig-stream",
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The core routing rule (spec §3.3), as a pure function so both sides classify
|
|
68
|
+
* a `model` string identically:
|
|
69
|
+
* 1. `@rig/…` OR an exact known route slug → slug lane (verified pipeline).
|
|
70
|
+
* 2. `^<providerId>/<model>$`, providerId ∈ PROVIDER_IDS → raw-model lane.
|
|
71
|
+
* 3. otherwise → unknown (the endpoint 404s; never silently guess).
|
|
72
|
+
*
|
|
73
|
+
* The namespaces don't collide: a route slug is a bare handle
|
|
74
|
+
* (`example.support_summarize`); a raw model always carries a known
|
|
75
|
+
* `provider/` prefix.
|
|
76
|
+
*/
|
|
77
|
+
function classifyLane(model, knownRouteSlugs = new Set()) {
|
|
78
|
+
const trimmed = model.trim();
|
|
79
|
+
if (trimmed === "") {
|
|
80
|
+
return { lane: "unknown", reason: "empty model field" };
|
|
81
|
+
}
|
|
82
|
+
if (trimmed.startsWith("@rig/")) {
|
|
83
|
+
const slug = trimmed.slice("@rig/".length);
|
|
84
|
+
if (slug === "")
|
|
85
|
+
return { lane: "unknown", reason: "empty route slug after @rig/" };
|
|
86
|
+
return { lane: "slug", slug };
|
|
87
|
+
}
|
|
88
|
+
if (knownRouteSlugs.has(trimmed)) {
|
|
89
|
+
return { lane: "slug", slug: trimmed };
|
|
90
|
+
}
|
|
91
|
+
const slash = trimmed.indexOf("/");
|
|
92
|
+
if (slash > 0) {
|
|
93
|
+
const provider = trimmed.slice(0, slash);
|
|
94
|
+
const rest = trimmed.slice(slash + 1);
|
|
95
|
+
if (rest !== "" && provider_1.PROVIDER_IDS.includes(provider)) {
|
|
96
|
+
return { lane: "raw", provider, model: rest };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
lane: "unknown",
|
|
101
|
+
reason: `"${trimmed}" is neither a known route slug nor a <provider>/<model> for a supported provider`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** The SSE sentinel that closes an OpenAI-compatible stream. */
|
|
105
|
+
exports.SSE_DONE = "[DONE]";
|