modelrig 0.9.0 → 0.11.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 +227 -0
- package/README.md +51 -27
- package/data/PROVENANCE.md +14 -0
- package/data/pricing-map.json +26 -0
- package/dist/adapters/attempt-meta-map.d.ts +8 -1
- package/dist/adapters/attempt-meta-map.d.ts.map +1 -1
- package/dist/adapters/attempt-meta-map.js +4 -0
- package/dist/adapters/build-adapters.js +2 -2
- package/dist/adapters/gemini.d.ts +28 -1
- package/dist/adapters/gemini.d.ts.map +1 -1
- package/dist/adapters/gemini.js +38 -9
- package/dist/adapters/grok.d.ts.map +1 -1
- package/dist/adapters/grok.js +53 -4
- package/dist/adapters/openai-compat.d.ts +8 -2
- package/dist/adapters/openai-compat.d.ts.map +1 -1
- package/dist/adapters/openai-compat.js +8 -1
- package/dist/adapters/openai-stream.d.ts +10 -2
- package/dist/adapters/openai-stream.d.ts.map +1 -1
- package/dist/adapters/openai-stream.js +5 -1
- package/dist/adapters/openai.d.ts +10 -1
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openai.js +57 -7
- package/dist/adapters/responses-api.d.ts +61 -0
- package/dist/adapters/responses-api.d.ts.map +1 -0
- package/dist/adapters/responses-api.js +124 -0
- package/dist/artifacts/artifact.d.ts +20 -0
- package/dist/artifacts/artifact.d.ts.map +1 -1
- package/dist/artifacts/artifact.js +207 -171
- package/dist/artifacts/index.d.ts +3 -1
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +8 -1
- package/dist/bakeoff/groundedness.d.ts +58 -0
- package/dist/bakeoff/groundedness.d.ts.map +1 -0
- package/dist/bakeoff/groundedness.js +165 -0
- package/dist/bakeoff/quality.d.ts +14 -1
- package/dist/bakeoff/quality.d.ts.map +1 -1
- package/dist/bakeoff/quality.js +10 -0
- package/dist/bakeoff/replay.d.ts.map +1 -1
- package/dist/bakeoff/replay.js +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -0
- package/dist/doctor-cli.d.ts +7 -0
- package/dist/doctor-cli.d.ts.map +1 -0
- package/dist/doctor-cli.js +68 -0
- package/dist/doctor-preflight.d.ts +64 -0
- package/dist/doctor-preflight.d.ts.map +1 -0
- package/dist/doctor-preflight.js +167 -0
- package/dist/feedback/coverage.d.ts.map +1 -1
- package/dist/feedback/coverage.js +9 -2
- package/dist/feedback/grade.d.ts +8 -1
- package/dist/feedback/grade.d.ts.map +1 -1
- package/dist/feedback/grade.js +4 -0
- package/dist/gateway/http-protocol.d.ts +19 -0
- package/dist/gateway/http-protocol.d.ts.map +1 -1
- package/dist/gateway/serve-client.d.ts +99 -0
- package/dist/gateway/serve-client.d.ts.map +1 -0
- package/dist/gateway/serve-client.js +360 -0
- package/dist/index.d.ts +31 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -8
- package/dist/prompts/manifest.d.ts +128 -0
- package/dist/prompts/manifest.d.ts.map +1 -0
- package/dist/prompts/manifest.js +214 -0
- package/dist/prompts/prompt-fetch.d.ts +84 -0
- package/dist/prompts/prompt-fetch.d.ts.map +1 -0
- package/dist/prompts/prompt-fetch.js +120 -0
- package/dist/prompts/prompt-resolve.d.ts +76 -0
- package/dist/prompts/prompt-resolve.d.ts.map +1 -0
- package/dist/prompts/prompt-resolve.js +93 -0
- package/dist/prompts/slot-resolver.d.ts +91 -0
- package/dist/prompts/slot-resolver.d.ts.map +1 -0
- package/dist/prompts/slot-resolver.js +135 -0
- package/dist/prompts/tools-register.d.ts +60 -0
- package/dist/prompts/tools-register.d.ts.map +1 -0
- package/dist/prompts/tools-register.js +48 -0
- package/dist/prompts/version-hash.d.ts +29 -0
- package/dist/prompts/version-hash.d.ts.map +1 -0
- package/dist/prompts/version-hash.js +54 -0
- package/dist/prompts-export-cli.d.ts +21 -0
- package/dist/prompts-export-cli.d.ts.map +1 -0
- package/dist/prompts-export-cli.js +130 -0
- package/dist/registry/cache-policy.d.ts.map +1 -1
- package/dist/registry/cache-policy.js +22 -0
- package/dist/registry/pricing-shape.d.ts +38 -8
- package/dist/registry/pricing-shape.d.ts.map +1 -1
- package/dist/registry/pricing-shape.js +40 -12
- package/dist/registry/pricing.d.ts +6 -5
- package/dist/registry/pricing.d.ts.map +1 -1
- package/dist/registry/pricing.js +9 -5
- package/dist/routes/destination-loader.d.ts +16 -0
- package/dist/routes/destination-loader.d.ts.map +1 -0
- package/dist/routes/destination-loader.js +29 -0
- package/dist/routes/draft.d.ts +7 -0
- package/dist/routes/draft.d.ts.map +1 -1
- package/dist/routes/draft.js +12 -0
- package/dist/routes/loader.d.ts.map +1 -1
- package/dist/routes/loader.js +27 -54
- package/dist/routes/output-loader.d.ts +42 -0
- package/dist/routes/output-loader.d.ts.map +1 -0
- package/dist/routes/output-loader.js +112 -0
- package/dist/routes/prompt-loader.d.ts +49 -0
- package/dist/routes/prompt-loader.d.ts.map +1 -0
- package/dist/routes/prompt-loader.js +113 -0
- package/dist/routes/resolved-bundle.d.ts +19 -0
- package/dist/routes/resolved-bundle.d.ts.map +1 -1
- package/dist/routes/resolved-bundle.js +24 -0
- package/dist/routes/screen-loader.d.ts +1 -1
- package/dist/routes/screen-loader.d.ts.map +1 -1
- package/dist/routes/screen-loader.js +8 -1
- package/dist/run/accept.d.ts +3 -0
- package/dist/run/accept.d.ts.map +1 -1
- package/dist/run/accept.js +1 -0
- package/dist/run/cost.d.ts +31 -2
- package/dist/run/cost.d.ts.map +1 -1
- package/dist/run/cost.js +57 -2
- package/dist/run/destination.d.ts +39 -0
- package/dist/run/destination.d.ts.map +1 -0
- package/dist/run/destination.js +45 -0
- package/dist/run/dispatch.d.ts +25 -3
- package/dist/run/dispatch.d.ts.map +1 -1
- package/dist/run/dispatch.js +26 -4
- package/dist/run/raw-defaults.d.ts.map +1 -1
- package/dist/run/raw-defaults.js +6 -1
- package/dist/run/raw-finalize.d.ts +96 -0
- package/dist/run/raw-finalize.d.ts.map +1 -0
- package/dist/run/raw-finalize.js +283 -0
- package/dist/run/raw-knobs.d.ts +36 -0
- package/dist/run/raw-knobs.d.ts.map +1 -0
- package/dist/run/raw-knobs.js +99 -0
- package/dist/run/raw-request.d.ts +24 -0
- package/dist/run/raw-request.d.ts.map +1 -0
- package/dist/run/raw-request.js +69 -0
- package/dist/run/raw-schema.d.ts +76 -0
- package/dist/run/raw-schema.d.ts.map +1 -0
- package/dist/run/raw-schema.js +166 -0
- package/dist/run/raw-search-cost.d.ts +49 -0
- package/dist/run/raw-search-cost.d.ts.map +1 -0
- package/dist/run/raw-search-cost.js +79 -0
- package/dist/run/raw-support.d.ts +64 -6
- package/dist/run/raw-support.d.ts.map +1 -1
- package/dist/run/raw-support.js +84 -11
- package/dist/run/raw.d.ts +25 -26
- package/dist/run/raw.d.ts.map +1 -1
- package/dist/run/raw.js +30 -351
- package/dist/run/record-attempt.d.ts +8 -0
- package/dist/run/record-attempt.d.ts.map +1 -1
- package/dist/run/record-attempt.js +26 -12
- package/dist/run/record-call.d.ts +104 -0
- package/dist/run/record-call.d.ts.map +1 -0
- package/dist/run/record-call.js +277 -0
- package/dist/run/repair-attempt.d.ts +68 -0
- package/dist/run/repair-attempt.d.ts.map +1 -0
- package/dist/run/repair-attempt.js +180 -0
- package/dist/run/resolve-destination.d.ts +49 -0
- package/dist/run/resolve-destination.d.ts.map +1 -0
- package/dist/run/resolve-destination.js +76 -0
- package/dist/run/routing-docs.d.ts.map +1 -1
- package/dist/run/routing-docs.js +9 -4
- package/dist/run/run.d.ts +30 -1
- package/dist/run/run.d.ts.map +1 -1
- package/dist/run/run.js +75 -148
- package/dist/run/telemetry-row.d.ts +92 -0
- package/dist/run/telemetry-row.d.ts.map +1 -0
- package/dist/run/telemetry-row.js +81 -0
- package/dist/run/validate.d.ts +12 -1
- package/dist/run/validate.d.ts.map +1 -1
- package/dist/run/validate.js +31 -0
- package/dist/run/web-search-pricing.d.ts +43 -0
- package/dist/run/web-search-pricing.d.ts.map +1 -0
- package/dist/run/web-search-pricing.js +56 -0
- package/dist/settings/grading-guide.d.ts +27 -1
- package/dist/settings/grading-guide.d.ts.map +1 -1
- package/dist/status.d.ts +6 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +4 -1
- package/dist/telemetry/artifact-store.d.ts.map +1 -1
- package/dist/telemetry/artifact-store.js +11 -0
- package/dist/telemetry/attempt-meta.d.ts +66 -1
- package/dist/telemetry/attempt-meta.d.ts.map +1 -1
- package/dist/telemetry/attempt-meta.js +27 -1
- package/dist/telemetry/exporter-setup.d.ts +2 -0
- package/dist/telemetry/exporter-setup.d.ts.map +1 -1
- package/dist/telemetry/exporter-setup.js +6 -1
- package/dist/telemetry/grade-mappers.d.ts +5 -2
- package/dist/telemetry/grade-mappers.d.ts.map +1 -1
- package/dist/telemetry/grade-mappers.js +8 -2
- package/dist/telemetry/grades-sql.d.ts +4 -1
- package/dist/telemetry/grades-sql.d.ts.map +1 -1
- package/dist/telemetry/grades-sql.js +26 -3
- package/dist/telemetry/ingest-protocol.d.ts +26 -2
- package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
- package/dist/telemetry/ingest-protocol.js +32 -29
- package/dist/telemetry/lanes.d.ts +31 -0
- package/dist/telemetry/lanes.d.ts.map +1 -0
- package/dist/telemetry/lanes.js +41 -0
- package/dist/telemetry/org-identity.d.ts +47 -0
- package/dist/telemetry/org-identity.d.ts.map +1 -0
- package/dist/telemetry/org-identity.js +100 -0
- package/dist/telemetry/route-registration.d.ts +48 -0
- package/dist/telemetry/route-registration.d.ts.map +1 -0
- package/dist/telemetry/route-registration.js +77 -0
- package/dist/telemetry/sinks.d.ts +10 -1
- package/dist/telemetry/sinks.d.ts.map +1 -1
- package/dist/telemetry/sinks.js +52 -6
- package/dist/telemetry/store-migrations.d.ts.map +1 -1
- package/dist/telemetry/store-migrations.js +13 -0
- package/dist/tenancy/api-key-format.d.ts +16 -1
- package/dist/tenancy/api-key-format.d.ts.map +1 -1
- package/dist/tenancy/api-key-format.js +17 -0
- package/dist/types/provider.d.ts +20 -3
- package/dist/types/provider.d.ts.map +1 -1
- package/dist/types/provider.js +1 -0
- package/dist/types/route.d.ts +76 -0
- package/dist/types/route.d.ts.map +1 -1
- package/dist/types/telemetry.d.ts +30 -2
- package/dist/types/telemetry.d.ts.map +1 -1
- package/docs/agent-skill/SKILL.md +75 -5
- package/docs/instrumentation.md +98 -36
- package/docs/llms.txt +96 -16
- package/docs/managed-serving.md +150 -0
- package/docs/mcp-oracle.md +75 -2
- package/docs/migration-playbook.md +5 -4
- package/docs/quickstart.md +169 -83
- package/package.json +3 -2
- package/registry/registry.json +82 -0
- package/dist/feedback/feedback.d.ts +0 -35
- package/dist/feedback/feedback.d.ts.map +0 -1
- package/dist/feedback/feedback.js +0 -39
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RigConfig } from "./config";
|
|
2
|
+
/** The subset of the whoami response we render. Every field optional/narrowed —
|
|
3
|
+
* an older or partial server response degrades to "(unknown org)", never a throw. */
|
|
4
|
+
export interface WhoamiResponse {
|
|
5
|
+
readonly org?: {
|
|
6
|
+
readonly id?: string;
|
|
7
|
+
readonly name?: string;
|
|
8
|
+
readonly slug?: string;
|
|
9
|
+
} | null;
|
|
10
|
+
readonly key?: {
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
readonly last_four?: string;
|
|
13
|
+
} | null;
|
|
14
|
+
readonly posture?: {
|
|
15
|
+
readonly telemetry?: string;
|
|
16
|
+
readonly artifact?: string;
|
|
17
|
+
} | null;
|
|
18
|
+
}
|
|
19
|
+
export interface PreflightResult {
|
|
20
|
+
readonly ok: boolean;
|
|
21
|
+
/** HTTP status; "network_error" when the request never completed;
|
|
22
|
+
* "malformed_key" when the key failed the local shape check and NOTHING was
|
|
23
|
+
* sent (QA N14); "not_rig_key" when the value is not a `rig_sk_` key at all
|
|
24
|
+
* (e.g. a deployment token) — doctor checks customer API keys only, so it
|
|
25
|
+
* is a usage error, never called "malformed", and nothing is sent (L6 NIT-6).
|
|
26
|
+
* A 2xx whose body names no org is `ok: false` with its HTTP status — it
|
|
27
|
+
* confirmed nothing. */
|
|
28
|
+
readonly status: number | "network_error" | "malformed_key" | "not_rig_key";
|
|
29
|
+
/** One human line, ready to print or log. */
|
|
30
|
+
readonly line: string;
|
|
31
|
+
readonly whoami?: WhoamiResponse;
|
|
32
|
+
/** The org's display name — present exactly when `ok` (a 2xx that names no
|
|
33
|
+
* org is not ok, QA N14). */
|
|
34
|
+
readonly orgName?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ask the configured api-mode sink who the key is. Returns null when there is
|
|
38
|
+
* nothing to check (no export, or a direct/local sink — whoami is an api-mode
|
|
39
|
+
* concept). Never throws: a network error is a `PreflightResult`, not an
|
|
40
|
+
* exception, so no caller can be broken by turning this on.
|
|
41
|
+
*/
|
|
42
|
+
export declare function runAuthPreflight(config: RigConfig, fetchFn?: typeof fetch): Promise<PreflightResult | null>;
|
|
43
|
+
/**
|
|
44
|
+
* The shared whoami worker: `runAuthPreflight` (doctor) and the api sink's
|
|
45
|
+
* first-flush org line (telemetry/org-identity.ts) both call it, so the two
|
|
46
|
+
* surfaces can never disagree about what a key resolves to. Never throws.
|
|
47
|
+
*/
|
|
48
|
+
export declare function whoamiPreflight(ingestUrl: string, apiKey: string, fetchFn?: typeof fetch,
|
|
49
|
+
/** Abort the request (e.g. `AbortSignal.timeout(ms)`) — the sink passes one so
|
|
50
|
+
* a hanging whoami can never hold the process open. An abort is a network_error. */
|
|
51
|
+
signal?: AbortSignal): Promise<PreflightResult>;
|
|
52
|
+
/** The display name of a whoami org (name, else id, else slug), or null when
|
|
53
|
+
* the server named none — never a placeholder glyph (QA N14). */
|
|
54
|
+
export declare function orgDisplayName(org: WhoamiResponse["org"]): string | null;
|
|
55
|
+
/** The org slug a successful preflight resolved, or null when unknown. */
|
|
56
|
+
export declare function resolvedOrgSlug(result: PreflightResult): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Compare a resolved org with the slug the caller expects (`--expect-org`,
|
|
59
|
+
* `createRig({ expectOrg })`). Returns null when they match, or the resolved
|
|
60
|
+
* slug (`"(unknown org)"` when the server did not name one) when they do not.
|
|
61
|
+
* Comparison is exact on the slug, case-insensitive — slugs are lowercase.
|
|
62
|
+
*/
|
|
63
|
+
export declare function expectedOrgMismatch(result: PreflightResult, expectOrg: string): string | null;
|
|
64
|
+
//# sourceMappingURL=doctor-preflight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor-preflight.d.ts","sourceRoot":"","sources":["../src/doctor-preflight.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;qFACqF;AACrF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC/F,QAAQ,CAAC,GAAG,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9E,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACvF;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB;;;;;;4BAMwB;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,eAAe,GAAG,aAAa,CAAC;IAC5E,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC;iCAC6B;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,OAAO,KAAa,GAC5B,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAIjC;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,OAAO,KAAa;AAC7B;oFACoF;AACpF,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,eAAe,CAAC,CA4F1B;AAED;iEACiE;AACjE,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAMxE;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAGtE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI7F"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAuthPreflight = runAuthPreflight;
|
|
4
|
+
exports.whoamiPreflight = whoamiPreflight;
|
|
5
|
+
exports.orgDisplayName = orgDisplayName;
|
|
6
|
+
exports.resolvedOrgSlug = resolvedOrgSlug;
|
|
7
|
+
exports.expectedOrgMismatch = expectedOrgMismatch;
|
|
8
|
+
/**
|
|
9
|
+
* Auth preflight — one legible line where there used to be silent 401 drops.
|
|
10
|
+
*
|
|
11
|
+
* Telemetry export is fire-and-forget by design: a rejected batch only logs a
|
|
12
|
+
* warning, never fails the pipeline. That is correct, but it means a WRONG key
|
|
13
|
+
* (revoked, or belonging to a different org than the console you watch) drops
|
|
14
|
+
* every run silently — the failure mode that cost InferWealth days of invisible
|
|
15
|
+
* telemetry. This module turns that into one line, by asking `GET /v1/whoami`
|
|
16
|
+
* (server-side companion) which org the key actually resolves to.
|
|
17
|
+
*
|
|
18
|
+
* `runAuthPreflight` is the pure worker: given the resolved config (config.ts is
|
|
19
|
+
* the only env reader) it returns a legible result and NEVER throws. `modelrig
|
|
20
|
+
* doctor` (doctor-cli.ts) calls it and prints the line — ✓ on success, a loud
|
|
21
|
+
* line on a rejected key.
|
|
22
|
+
*
|
|
23
|
+
* `--expect-org <slug>` (doctor) and `createRig({ expectOrg })` (the sink's
|
|
24
|
+
* first-flush line) compare the resolved slug with `expectedOrgMismatch` below.
|
|
25
|
+
*
|
|
26
|
+
* NOTE: there is no automatic boot-time preflight. The automatic safety net lives
|
|
27
|
+
* on the export path itself — the api sink emits a loud once-per-failure-streak
|
|
28
|
+
* "AUTH FAILED" warning when an ingest POST is rejected (telemetry/sinks.ts) — so
|
|
29
|
+
* a customer needs no extra env var: the one key they set is enough.
|
|
30
|
+
*/
|
|
31
|
+
const api_key_format_1 = require("./tenancy/api-key-format");
|
|
32
|
+
/**
|
|
33
|
+
* Ask the configured api-mode sink who the key is. Returns null when there is
|
|
34
|
+
* nothing to check (no export, or a direct/local sink — whoami is an api-mode
|
|
35
|
+
* concept). Never throws: a network error is a `PreflightResult`, not an
|
|
36
|
+
* exception, so no caller can be broken by turning this on.
|
|
37
|
+
*/
|
|
38
|
+
async function runAuthPreflight(config, fetchFn = fetch) {
|
|
39
|
+
const exp = config.export;
|
|
40
|
+
if (exp === undefined || exp.mode !== "api")
|
|
41
|
+
return null;
|
|
42
|
+
return whoamiPreflight(exp.ingestUrl, exp.apiKey, fetchFn);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The shared whoami worker: `runAuthPreflight` (doctor) and the api sink's
|
|
46
|
+
* first-flush org line (telemetry/org-identity.ts) both call it, so the two
|
|
47
|
+
* surfaces can never disagree about what a key resolves to. Never throws.
|
|
48
|
+
*/
|
|
49
|
+
async function whoamiPreflight(ingestUrl, apiKey, fetchFn = fetch,
|
|
50
|
+
/** Abort the request (e.g. `AbortSignal.timeout(ms)`) — the sink passes one so
|
|
51
|
+
* a hanging whoami can never hold the process open. An abort is a network_error. */
|
|
52
|
+
signal) {
|
|
53
|
+
const base = new URL(ingestUrl).origin;
|
|
54
|
+
const redacted = (0, api_key_format_1.redactApiKey)(apiKey);
|
|
55
|
+
// L6 NIT-6: a value that is not a rig_sk_ key at all (a deployment or other
|
|
56
|
+
// service token) is not "malformed" — it is the wrong kind of secret. Never
|
|
57
|
+
// sent over the wire.
|
|
58
|
+
// (Surrounding whitespace/quotes are a malformed rig_sk_ key, handled below.)
|
|
59
|
+
if (!apiKey.trim().replace(/^["']/, "").startsWith(api_key_format_1.API_KEY_PREFIX)) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
status: "not_rig_key",
|
|
63
|
+
line: `[modelrig] not a ${api_key_format_1.API_KEY_PREFIX} key — doctor checks customer API keys. MODELRIG_API_KEY holds a ` +
|
|
64
|
+
`different kind of secret, so nothing was sent. Set it to the ${api_key_format_1.API_KEY_PREFIX} key minted at ` +
|
|
65
|
+
"app.modelrig.ai → Keys.",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// QA N14: a rig_sk_ key that fails the local shape check is never sent over the wire.
|
|
69
|
+
if (!(0, api_key_format_1.looksLikeApiKey)(apiKey)) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
status: "malformed_key",
|
|
73
|
+
line: `[modelrig] malformed key — MODELRIG_API_KEY starts like a ${api_key_format_1.API_KEY_PREFIX} key but is truncated or ` +
|
|
74
|
+
"carries stray characters/whitespace, so nothing was sent to the server. Copy the full key from " +
|
|
75
|
+
"app.modelrig.ai → Keys and set it without quotes.",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetchFn(`${base}/v1/whoami`, {
|
|
80
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
81
|
+
...(signal !== undefined ? { signal } : {}),
|
|
82
|
+
});
|
|
83
|
+
if (res.status === 401 || res.status === 403) {
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
status: res.status,
|
|
87
|
+
line: `[modelrig] AUTH FAILED (${res.status}) at ${base} — key ${redacted} is not recognized ` +
|
|
88
|
+
"by this server/org. Check MODELRIG_API_KEY, and that the key belongs to the org you " +
|
|
89
|
+
"expect (mint it in that org at app.modelrig.ai). Telemetry is dropping silently until this is fixed.",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!res.ok) {
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
status: res.status,
|
|
96
|
+
line: `[modelrig] whoami ${res.status} at ${base} — could not confirm the key's org (retry \`modelrig doctor\`).`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const who = (await res.json().catch(() => null));
|
|
100
|
+
// QA N14: a 2xx that does not NAME an org confirmed nothing — never a ✓.
|
|
101
|
+
if (who === null || typeof who !== "object") {
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
status: res.status,
|
|
105
|
+
line: `[modelrig] whoami ${res.status} at ${base} returned a body that is not JSON — could not confirm ` +
|
|
106
|
+
`key ${redacted}'s org. Check that the ingest URL points at a ModelRig server, then retry \`modelrig doctor\`.`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const orgLabel = orgDisplayName(who.org);
|
|
110
|
+
if (orgLabel === null) {
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
status: res.status,
|
|
114
|
+
line: `[modelrig] whoami ${res.status} at ${base} named no org for key ${redacted} — could not confirm ` +
|
|
115
|
+
"where telemetry lands. The server may predate whoami's org field; retry `modelrig doctor`, " +
|
|
116
|
+
"or check the key at app.modelrig.ai → Keys.",
|
|
117
|
+
whoami: who,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const orgLabelQuoted = `«${orgLabel}»`;
|
|
121
|
+
const posture = who.posture?.telemetry;
|
|
122
|
+
const postureLabel = typeof posture === "string" ? `, telemetry: ${posture}` : "";
|
|
123
|
+
return {
|
|
124
|
+
ok: true,
|
|
125
|
+
status: res.status,
|
|
126
|
+
line: `[modelrig] key ${redacted} → org ${orgLabelQuoted} ✓ (ingest ${base}${postureLabel})`,
|
|
127
|
+
whoami: who,
|
|
128
|
+
orgName: orgLabel,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
return {
|
|
133
|
+
ok: false,
|
|
134
|
+
status: "network_error",
|
|
135
|
+
line: `[modelrig] whoami unreachable at ${base} (${err instanceof Error ? err.message : String(err)}) — ` +
|
|
136
|
+
"export is fire-and-forget, so this only means the preflight could not confirm your key.",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** The display name of a whoami org (name, else id, else slug), or null when
|
|
141
|
+
* the server named none — never a placeholder glyph (QA N14). */
|
|
142
|
+
function orgDisplayName(org) {
|
|
143
|
+
if (org === null || org === undefined || typeof org !== "object")
|
|
144
|
+
return null;
|
|
145
|
+
for (const v of [org.name, org.id, org.slug]) {
|
|
146
|
+
if (typeof v === "string" && v.trim() !== "")
|
|
147
|
+
return v;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/** The org slug a successful preflight resolved, or null when unknown. */
|
|
152
|
+
function resolvedOrgSlug(result) {
|
|
153
|
+
const slug = result.whoami?.org?.slug;
|
|
154
|
+
return typeof slug === "string" && slug !== "" ? slug : null;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Compare a resolved org with the slug the caller expects (`--expect-org`,
|
|
158
|
+
* `createRig({ expectOrg })`). Returns null when they match, or the resolved
|
|
159
|
+
* slug (`"(unknown org)"` when the server did not name one) when they do not.
|
|
160
|
+
* Comparison is exact on the slug, case-insensitive — slugs are lowercase.
|
|
161
|
+
*/
|
|
162
|
+
function expectedOrgMismatch(result, expectOrg) {
|
|
163
|
+
const actual = resolvedOrgSlug(result);
|
|
164
|
+
if (actual !== null && actual.toLowerCase() === expectOrg.trim().toLowerCase())
|
|
165
|
+
return null;
|
|
166
|
+
return actual ?? "(unknown org)";
|
|
167
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/feedback/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/feedback/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGjE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IACrB,oEAAoE;IACpE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;;;;+EAK+E;AAC/E,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,YAAY,EAAE,EAC7B,MAAM,EAAE,SAAS,QAAQ,EAAE,GAC1B,aAAa,EAAE,CA2FjB"}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.RUNG1_MIN_GRADES = void 0;
|
|
17
17
|
exports.computeCoverage = computeCoverage;
|
|
18
|
+
const lanes_1 = require("../telemetry/lanes");
|
|
18
19
|
exports.RUNG1_MIN_GRADES = 10;
|
|
19
20
|
/** Attribution: a grade joins a route via its inference-subject id, or via its
|
|
20
21
|
* run-subject (episode) id matching a row's run_id tag. Unmatched grades attach
|
|
@@ -31,14 +32,20 @@ function computeCoverage(rows, grades) {
|
|
|
31
32
|
// view): bake-off replays are candidate-variant experiments, not the
|
|
32
33
|
// route's production serving — counting them skews conformance/repair
|
|
33
34
|
// rates with losing variants that never served a real request.
|
|
35
|
+
// OBS-1 L6 MUST-1: coverage is ROUTE readiness — raw passthroughs and
|
|
36
|
+
// recorded calls (`tags.lane` raw / external) walked no route and never
|
|
37
|
+
// contribute samples, conformance or a rung.
|
|
34
38
|
let replayTagged = false;
|
|
39
|
+
let unrouted = false;
|
|
35
40
|
try {
|
|
36
|
-
|
|
41
|
+
const tags = JSON.parse(row.tagsJson);
|
|
42
|
+
replayTagged = tags.replay !== undefined;
|
|
43
|
+
unrouted = !(0, lanes_1.isRoutedLane)(tags.lane);
|
|
37
44
|
}
|
|
38
45
|
catch {
|
|
39
46
|
replayTagged = false;
|
|
40
47
|
}
|
|
41
|
-
if (replayTagged)
|
|
48
|
+
if (replayTagged || unrouted)
|
|
42
49
|
continue;
|
|
43
50
|
const agg = byRoute.get(row.route) ?? {
|
|
44
51
|
samples: 0,
|
package/dist/feedback/grade.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* (`rig.feedback` / `artifact.evaluate` / `run.evaluate`) and their adapters were
|
|
12
12
|
* removed in GP-3 — every judgment now builds a grade directly.
|
|
13
13
|
*/
|
|
14
|
-
import type { GradeRow, GradeSubject } from "../types/telemetry";
|
|
14
|
+
import type { GradeCriterion, GradeRow, GradeSubject } from "../types/telemetry";
|
|
15
15
|
/** Options for `rig.grade(subject, opts)`. `score` is the 0–1 primitive and is
|
|
16
16
|
* required; everything else is optional display / provenance. */
|
|
17
17
|
export interface GradeOpts {
|
|
@@ -31,6 +31,13 @@ export interface GradeOpts {
|
|
|
31
31
|
readonly grader?: string;
|
|
32
32
|
/** Provenance (e.g. "sdk", "console", a review-agent name). */
|
|
33
33
|
readonly source?: string;
|
|
34
|
+
/** OPTIONAL per-criterion breakdown (call-qa F4). When present on a human
|
|
35
|
+
* grade it rides the wire to the server, which persists it to `grade_criteria`
|
|
36
|
+
* (kind=human) so per-criterion agreement can pair the human vs model
|
|
37
|
+
* scorecards. Absent ⇒ today's single-score grade, unchanged. The server owns
|
|
38
|
+
* the scrub + dedup/drop-empty-id/clamp guard at persist; this is carried
|
|
39
|
+
* verbatim. */
|
|
40
|
+
readonly criteria?: readonly GradeCriterion[];
|
|
34
41
|
/** The grade's own org — server-supplied ONLY, already authorized (T3). Omit
|
|
35
42
|
* from application code (a rig has one org and the exporter knows it). */
|
|
36
43
|
readonly orgId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grade.d.ts","sourceRoot":"","sources":["../../src/feedback/grade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"grade.d.ts","sourceRoot":"","sources":["../../src/feedback/grade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEjF;iEACiE;AACjE,MAAM,WAAW,SAAS;IACxB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;6EACyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,kFAAkF;IAClF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,eAAe,CAAC;IACzD,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;mBAKe;IACf,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C;8EAC0E;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAQD;oFACoF;AACpF,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CA2B9E;AAED;;+DAE+D;AAC/D,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,GAAG;IACzE,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;CACzD,CAQA"}
|
package/dist/feedback/grade.js
CHANGED
|
@@ -47,6 +47,10 @@ function buildGradeRow(subject, opts) {
|
|
|
47
47
|
orgId: opts.orgId !== undefined && opts.orgId !== "" ? opts.orgId : null,
|
|
48
48
|
createdBy: opts.createdBy ?? null,
|
|
49
49
|
ts: new Date().toISOString(),
|
|
50
|
+
// F4: carry the per-criterion breakdown verbatim iff present (spread-iff so
|
|
51
|
+
// a single-score grade's row is byte-identical to pre-F4). Structural
|
|
52
|
+
// normalization (dedup/clamp/scrub) is the server's job at persist.
|
|
53
|
+
...(opts.criteria !== undefined ? { criteria: opts.criteria } : {}),
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
/** Build the rig's `grade` surface over a grade writer (the telemetry store).
|
|
@@ -114,6 +114,25 @@ export interface ChatCompletionRequest {
|
|
|
114
114
|
readonly envelope?: string;
|
|
115
115
|
readonly variant?: string;
|
|
116
116
|
readonly stream?: "buffered";
|
|
117
|
+
/**
|
|
118
|
+
* K1b (managed-serving-keyless) — the FAITHFUL carrier for a TEMPLATED /
|
|
119
|
+
* NON-CHAT route's named template variables. A provider-neutral JSON object
|
|
120
|
+
* of the route's `{{variable}}` bindings, DISTINCT from OpenAI `messages`:
|
|
121
|
+
* `messages` is the chat-relay bridge (the server derives `message`/`messages`
|
|
122
|
+
* from it), whereas `input` carries the route's OWN declared variables
|
|
123
|
+
* verbatim (e.g. a report route's structured `{ topic, holdings, … }`), so the
|
|
124
|
+
* server renders the route template exactly as a local `rig.run` would — no
|
|
125
|
+
* lossy messages round-trip.
|
|
126
|
+
*
|
|
127
|
+
* PRECEDENCE (server bind): when present, `modelrig.input` WINS — the run's
|
|
128
|
+
* `input` is these named variables; the chat `messages` binding is the
|
|
129
|
+
* fallback used only when it is absent. The server validates the object shape
|
|
130
|
+
* fail-closed (a non-object, or a prototype-polluting key, is a teaching 422)
|
|
131
|
+
* — a request that cannot be faithfully served is refused, never served with
|
|
132
|
+
* a silently-wrong prompt. ADDITIVE: a chat request that omits it is
|
|
133
|
+
* byte-identical to the K1 wire.
|
|
134
|
+
*/
|
|
135
|
+
readonly input?: Readonly<Record<string, unknown>>;
|
|
117
136
|
};
|
|
118
137
|
}
|
|
119
138
|
export interface ChatCompletionUsage {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-protocol.d.ts","sourceRoot":"","sources":["../../src/gateway/http-protocol.ts"],"names":[],"mappings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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,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* K1 (managed-serving-keyless §2/§3) — the SDK-side KEYLESS serving transport.
|
|
3
|
+
*
|
|
4
|
+
* This is the client half of `destination: modelrig-served`: instead of the
|
|
5
|
+
* local adapter dispatch, a served run is POSTed to the HOSTED gateway's
|
|
6
|
+
* `POST /v1/chat/completions` (the org's mirrored bundle, resolved BY SLUG and
|
|
7
|
+
* driven server-side through `runBundle` — see modelrig-server
|
|
8
|
+
* `handleMirroredSlugLane`). The gateway spends ModelRig's OWN managed provider
|
|
9
|
+
* key; the SDK sends ONLY its `rig_sk_` control-plane key (Bearer), NEVER a
|
|
10
|
+
* provider key.
|
|
11
|
+
*
|
|
12
|
+
* ONE wire contract: everything here is expressed in the SHARED
|
|
13
|
+
* `gateway/http-protocol.ts` shapes (`CHAT_COMPLETIONS_PATH`,
|
|
14
|
+
* `ChatCompletionRequest`, `ChatCompletionResponse`, `MODELRIG_HEADERS`,
|
|
15
|
+
* `MODELRIG_REQUEST_HEADERS`) — the same module `modelrig-server` compiles
|
|
16
|
+
* against, so the request this produces is exactly the one the endpoint
|
|
17
|
+
* consumes and the response it parses is exactly the one the endpoint emits.
|
|
18
|
+
*
|
|
19
|
+
* FAIL-CLOSED-BUT-DISCOVERABLE (spec §3 K1, ruling R3): a transport error, a
|
|
20
|
+
* non-2xx, a 402 (no prepaid balance), or a 403 (no serve entitlement) throws a
|
|
21
|
+
* TEACHING `RigFailureError` (class `invariant_violation`, TERMINAL) whose
|
|
22
|
+
* `fixHint` names the cause and the fix — NEVER a silent fall back to `direct`
|
|
23
|
+
* or a local key. `fetch` is injected (`fetchFn`) so tests mock the transport
|
|
24
|
+
* with no live network and no real key.
|
|
25
|
+
*
|
|
26
|
+
* TRANSPORT + MAPPING ONLY. The flag/capability gate + the run.ts branch point
|
|
27
|
+
* live in `run/resolve-destination.ts` / `run/run.ts`; this module is reached
|
|
28
|
+
* only AFTER the guard has passed.
|
|
29
|
+
*/
|
|
30
|
+
import type { ChatMessage } from "./http-protocol";
|
|
31
|
+
import type { RouteBundle, RunOptions, RunResult } from "../types/route";
|
|
32
|
+
/** Injected transport — the global `fetch` in production, a mock in tests. */
|
|
33
|
+
export type ServeFetch = typeof fetch;
|
|
34
|
+
/**
|
|
35
|
+
* Where + how to reach the hosted gateway. Resolved (in `index.ts`) from the
|
|
36
|
+
* SAME `api`-mode export config the telemetry sink uses: `baseUrl` is the ingest
|
|
37
|
+
* host (`MODELRIG_INGEST_URL` ‖ `DEFAULT_INGEST_URL`) and `apiKey` is the
|
|
38
|
+
* `rig_sk_` key. ABSENT ⇒ no hosted control plane is configured ⇒ a served run
|
|
39
|
+
* fails closed (there is nowhere to serve it, and we never invent a key).
|
|
40
|
+
*/
|
|
41
|
+
export interface ServeTransportConfig {
|
|
42
|
+
/** Ingest host base, e.g. `https://api.modelrig.ai` (no path). */
|
|
43
|
+
readonly baseUrl: string;
|
|
44
|
+
/** `rig_sk_…` control-plane key. The ONLY credential sent — never a provider key. */
|
|
45
|
+
readonly apiKey: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ServeRunInput {
|
|
48
|
+
readonly route: RouteBundle;
|
|
49
|
+
readonly opts: RunOptions;
|
|
50
|
+
/** The resolved variant name (Phase 3 WS1) — served via `x-modelrig-variant`. */
|
|
51
|
+
readonly servedVariant: string | null;
|
|
52
|
+
/** Resolved transport; `undefined` ⇒ fail closed (no hosted control plane). */
|
|
53
|
+
readonly serve: ServeTransportConfig | undefined;
|
|
54
|
+
/** Injected fetch (tests); defaults to the global `fetch`. */
|
|
55
|
+
readonly fetchFn?: ServeFetch;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Is this run's `input` a CHAT-SHAPED input — the shape the OpenAI `messages`
|
|
59
|
+
* bridge carries faithfully (`input.messages` a transcript, or `input.message` a
|
|
60
|
+
* single user turn)? A route authored for the OpenAI-compatible surface declares
|
|
61
|
+
* exactly these variables (PROXY_RELAYED_VARS, server-side). Anything else is a
|
|
62
|
+
* NAMED-variable input carried by `modelrig.input` (K1b) instead.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isChatShapedInput(input: RunOptions["input"]): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Map the run's CHAT-shaped `input` into OpenAI `messages` — the chat-relay
|
|
67
|
+
* bridge (the server rebuilds `message`/`messages` from it). Faithful for a
|
|
68
|
+
* chat-shaped route:
|
|
69
|
+
* - `input.messages` (an array of `{role, content}`) → the transcript verbatim;
|
|
70
|
+
* - else `input.message` (a string) → a single user turn.
|
|
71
|
+
*
|
|
72
|
+
* K1b: a route that templates over OTHER named variables is NO LONGER fails-closed
|
|
73
|
+
* here — `serveViaGateway` carries those faithfully via `modelrig.input`
|
|
74
|
+
* (`buildServedNamedInput`). This function is reached only for a chat-shaped
|
|
75
|
+
* input, so the final fail-closed branch stays as a defensive teaching error for
|
|
76
|
+
* a caller who invokes it directly on a non-chat input.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildServedMessages(route: RouteBundle, input: RunOptions["input"]): readonly ChatMessage[];
|
|
79
|
+
/**
|
|
80
|
+
* K1b — carry a NAMED-variable route's `input` faithfully as `modelrig.input`,
|
|
81
|
+
* INSTEAD of the K1 fail-closed. A templated/non-chat route (an InferWealth
|
|
82
|
+
* report route, say) declares structured variables (`{ topic, holdings, … }`),
|
|
83
|
+
* not `message`/`messages`; this is the provider-neutral object the server binds
|
|
84
|
+
* so the route template renders exactly as a local `rig.run` would.
|
|
85
|
+
*
|
|
86
|
+
* Still fail-closed-but-discoverable (K1's guarantee preserved): the only reason
|
|
87
|
+
* to refuse now is a genuinely UN-SERIALIZABLE input — one JSON cannot carry
|
|
88
|
+
* losslessly, which would degrade to a silently-wrong prompt server-side.
|
|
89
|
+
* `assertJsonFaithful` names the exact offending value; we wrap it as a teaching
|
|
90
|
+
* error, never a silent drop.
|
|
91
|
+
*/
|
|
92
|
+
export declare function buildServedNamedInput(route: RouteBundle, input: RunOptions["input"]): Readonly<Record<string, unknown>>;
|
|
93
|
+
/**
|
|
94
|
+
* Serve a run through the hosted gateway and map the completion back into a
|
|
95
|
+
* normal `RunResult`. Reached only after `assertDestinationServable` has passed
|
|
96
|
+
* (flag on + served-capable provider). Fail-closed-but-discoverable throughout.
|
|
97
|
+
*/
|
|
98
|
+
export declare function serveViaGateway(input: ServeRunInput): Promise<RunResult>;
|
|
99
|
+
//# sourceMappingURL=serve-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-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