modelrig 0.9.0 → 0.10.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 +179 -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 +67 -0
- package/dist/doctor-preflight.d.ts +52 -0
- package/dist/doctor-preflight.d.ts.map +1 -0
- package/dist/doctor-preflight.js +112 -0
- 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 +25 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -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 +50 -0
- package/dist/run/raw-finalize.d.ts.map +1 -0
- package/dist/run/raw-finalize.js +266 -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 +48 -0
- package/dist/run/raw-search-cost.d.ts.map +1 -0
- package/dist/run/raw-search-cost.js +78 -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/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 +55 -1
- package/dist/telemetry/attempt-meta.d.ts.map +1 -1
- package/dist/telemetry/attempt-meta.js +24 -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/org-identity.d.ts +44 -0
- package/dist/telemetry/org-identity.d.ts.map +1 -0
- package/dist/telemetry/org-identity.js +98 -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 +73 -5
- package/docs/instrumentation.md +81 -36
- package/docs/llms.txt +95 -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
package/dist/index.js
CHANGED
|
@@ -24,11 +24,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
24
24
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
27
|
+
exports.redactApiKey = exports.looksLikeApiKey = exports.hashApiKeySecret = exports.API_KEY_SECRET_BYTES = exports.API_KEY_SCOPES = exports.API_KEY_PREFIX = exports.resolveArtifactsConfig = exports.createToolRegistry = exports.SlotResolutionError = exports.assemblePrompt = exports.createEmbeddedPrompts = exports.createPromptResolver = exports.parseServedPrompt = exports.createPromptCache = exports.createApiPromptFetcher = exports.promptTemplateSha = exports.normalizeManifest = exports.parseAuthoringDoc = exports.assertValidManifest = exports.validateManifest = exports.resolveOtlpConfig = exports.parseOtlpHeaders = exports.decodeOtlpProtobufTraces = exports.looksLikeLogsPayload = exports.normalizeOtlpTraces = exports.startOtlpEmitterIfConfigured = exports.createOtlpEmitter = exports.TRACEPARENT_TAG = exports.parseTraceparent = exports.buildExportTraceRequest = exports.inferenceToSpan = exports.SEMCONV_VERSION = exports.SinkSendError = exports.createDirectSink = exports.createApiSink = exports.createTelemetryExporter = exports.RESERVED_TAG_KEYS = exports.resolvePipelineSha = exports.reservedTagNearMisses = exports.renderRequestForHash = exports.sanitizeMetaForWire = exports.isMetaSafeString = exports.summarizeAttemptMeta = exports.DEFAULT_INGEST_URL = exports.INGEST_PROTOCOL_VERSION_V1 = exports.INGEST_PROTOCOL_VERSION = exports.INGEST_PATH = exports.foreignOrgGrades = exports.stampBatch = exports.loadConfigFromEnv = void 0;
|
|
28
|
+
exports.computeProposal = exports.mirrorBakeoff = exports.runBakeoff = exports.replayVariant = exports.openTelemetryStore = exports.openCaptureStore = exports.SSE_DONE = exports.MODELRIG_REQUEST_HEADERS = exports.MODELRIG_HEADERS = exports.GATEWAY_PROTOCOL_VERSION = exports.MODELS_PATH = exports.CHAT_COMPLETIONS_PATH = exports.classifyLane = exports.ALL_CAPABILITY_FLAGS = exports.PROVIDER_IDS = exports.RAW_ONLY_FIX_HINT = exports.rawOnlyRouteFailure = exports.requireRoutesDir = exports.runRawStream = exports.runRaw = exports.resolveCallConfigForRun = exports.hashUnitKey = exports.armName = exports.drawArm = exports.narrowExperiment = exports.pinFromResolved = exports.parseCallConfig = exports.narrowCallConfigPin = exports.getCallConfig = exports.createCallConfigResolver = exports.createApiCallConfigFetcher = exports.applyCallConfig = exports.assertMirrorSafe = exports.hashResolvedBundle = exports.resolveRouteBundle = exports.bundleFromResolved = exports.runStream = exports.evalCaseCaptureStore = exports.selectEvalCaseCaptures = exports.runBakeoffFromEvalCases = exports.extractEvidenceQuotes = exports.groundednessScore = exports.resolveDeterministicQuality = exports.fieldAccuracy = exports.exactMatch = exports.KEY_SHAPED_PREFIXES = exports.containsKeyShapedString = exports.scrubSecrets = exports.hasScope = exports.parseScopes = void 0;
|
|
29
|
+
exports.servedDestinations = exports.DEFAULT_DESTINATION = exports.DESTINATIONS = exports.GEMINI_THINKING_CAPABLE_MODELS = exports.createGeminiAdapter = exports.PROVIDER_KEY_ENV = exports.serveabilityWarnings = exports.checkServeability = exports.writeRouteDraft = exports.buildRouteDraft = exports.splitModelKey = exports.seedCandidates = exports.loadRegistryRows = exports.signatureFor = exports.PROVIDER_SIGNATURES = exports.readObjectLiteral = exports.findCallSitesInText = exports.scanRepoForCallSites = exports.capabilitiesFor = exports.routeNameFor = exports.buildMigrationMarkdown = exports.runInit = exports.renderConfigErrorForTerminal = exports.describeConfigFailure = exports.teachConfigError = exports.classifyConfigProblem = exports.CONFIG_TEACHING = exports.mergeLoadedRoutes = exports.loadRoutesWithExtra = exports.loadRoutes = exports.RouteConfigError = exports.renderFailureForTerminal = exports.teach = exports.FAILURE_TEACHING = exports.isRigFailure = exports.RigFailureError = exports.extractCitations = exports.createTavilySearchProvider = exports.sampleQuality = exports.pairedRegret = exports.wilson95 = exports.aggregateVariantMetrics = exports.OUTPUT_MAX_BYTES = exports.retentionExpiry = exports.truncateOutput = exports.selectArmsToKeep = exports.buildBakeoffSamples = exports.createBakeoffSamplesClient = exports.deriveSwapDirection = exports.bakeoffEvidence = void 0;
|
|
30
|
+
exports.PROPOSAL_TTL_DAYS = exports.regretBreachTriggerHash = exports.upgradeTriggerHash = exports.manualChallengerTriggerHash = exports.triggerHash = exports.evaluateEvents = exports.RUNG1_MIN_GRADES = exports.computeCoverage = exports.computeParity = exports.factsUnderCredential = exports.factsFor = exports.PROBE_FRESHNESS_SLO_DAYS = exports.stalenessSentence = exports.probeFreshness = exports.callNotesFor = exports.evaluateChallengerEligibility = exports.requirementPredicates = exports.PREDICATE_GLOSS = exports.ALL_CAPABILITY_PREDICATES = exports.explainEmptySelection = exports.hasCapability = exports.selectModels = exports.parseCapabilityQuery = exports.capabilityFactsFromEntry = exports.loadRegistryFacts = exports.fingerprintSchema = exports.loadManifest = exports.SNAPSHOT_BASIS = exports.describePricingV2 = exports.tierRates = exports.synthesizeFromFlat = exports.seededCachePolicyProviders = exports.getCachePolicy = exports.DEFAULT_CACHE_HYSTERESIS = exports.classifyCacheVerdict = exports.effectiveInputRate = exports.estimateCostUsd = exports.getPricingV2 = exports.getPricing = exports.resolveCandidates = exports.OPENAI_COMPAT_HOSTS = exports.shapeFireworksModelId = exports.classifyCompatFailure = exports.buildOpenAICompatParams = exports.createOpenAICompatAdapter = exports.createGrokAdapter = exports.createAnthropicAdapter = exports.createDeepSeekAdapter = exports.createOpenAIAdapter = exports.destinationSupported = void 0;
|
|
31
|
+
exports.RESERVED_DIMENSION_NAMES = exports.METRIC_COLUMNS = exports.DIMENSION_COLUMNS = exports.sinceIsoFor = exports.savedQueryById = exports.SAVED_QUERIES = exports.ANALYTICS_SCAN_CAP = exports.selectableColumnsAreMetaSafe = exports.planAnalyticsRead = exports.evaluateAnalyticsQuery = exports.describeAnalyticsSchema = exports.parseQuery = exports.QueryGrammarError = exports.compileQuery = exports.writePriorsCells = exports.aggregatePairwiseFromTelemetry = exports.aggregatePriors = exports.DEFAULT_WATCH_MONTHLY_USD = exports.watchEnvelopeKey = exports.reserveWatchBudget = exports.WATCH_STATE_KEY = exports.createFileWatchStateStore = exports.createControlPlaneWatchStateStore = exports.createWatchStateStore = exports.saveWatchState = exports.loadWatchState = exports.computeWatchEvents = exports.buildPriceUniverse = exports.runWatchCycle = exports.DEFAULT_MONITOR_CONFIG = exports.createMonitorReads = exports.rollupConformRate = exports.evaluateConformDegradation = exports.runMonitorCycle = exports.assertTransition = exports.createProposalsClient = exports.MONITOR_SOURCE_PREFIX = exports.MONITOR_CYCLE_MARKER = exports.REGRET_MONITOR_MARGIN = exports.REGRET_MONITOR_MIN_N = exports.REGRET_MONITOR_BASELINE_DAYS = exports.REGRET_MONITOR_WINDOW_DAYS = exports.createRegretMonitorReads = exports.regretMonitorConfig = exports.cyclePointFromArtifact = exports.aggregateRegretBand = exports.evaluateRegretDrift = exports.runRegretMonitorCycle = exports.evaluateUpgradeOpportunities = exports.explainCacheContext = void 0;
|
|
32
|
+
exports.computeOdometer = exports.createSwapsClient = exports.executeSwap = exports.trialVariantName = exports.buildDeclareTrialChange = exports.buildRestoreYaml = exports.buildSwapChange = exports.runTelemetryQuery = void 0;
|
|
32
33
|
exports.createRig = createRig;
|
|
33
34
|
const build_adapters_1 = require("./adapters/build-adapters");
|
|
34
35
|
const config_1 = require("./config");
|
|
@@ -36,6 +37,7 @@ const rawonly_1 = require("./run/rawonly");
|
|
|
36
37
|
const resolved_bundle_1 = require("./routes/resolved-bundle");
|
|
37
38
|
const serveability_1 = require("./routes/serveability");
|
|
38
39
|
const manifest_1 = require("./routes/manifest");
|
|
40
|
+
const tools_register_1 = require("./prompts/tools-register");
|
|
39
41
|
const run_1 = require("./run/run");
|
|
40
42
|
const stream_1 = require("./run/stream");
|
|
41
43
|
const raw_1 = require("./run/raw");
|
|
@@ -150,6 +152,7 @@ function createRig(config) {
|
|
|
150
152
|
artifactsEnabled,
|
|
151
153
|
artifactStore,
|
|
152
154
|
...(onArtifactsFlushed !== undefined ? { onArtifactsFlushed } : {}),
|
|
155
|
+
...(config.expectOrg !== undefined ? { expectOrg: config.expectOrg } : {}),
|
|
153
156
|
})
|
|
154
157
|
: null;
|
|
155
158
|
// Boot banner (§2) + one-time deprecation warnings (§3): posture, plus a loud
|
|
@@ -171,6 +174,16 @@ function createRig(config) {
|
|
|
171
174
|
captures,
|
|
172
175
|
search,
|
|
173
176
|
settings, // §1.5 resolver (null local-only); capture-WRITE gate consults it
|
|
177
|
+
managedServingEnabled: config.managedServing === true, // U3 (D-2): `config.managedServing`, set IN CODE via createRig (NOT an env var); default off ⇒ `modelrig-served` fails closed pre-dispatch
|
|
178
|
+
// K1 (managed-serving-keyless §2/§3): the hosted-gateway serving transport,
|
|
179
|
+
// resolved from the SAME `api`-mode export the telemetry sink uses — the
|
|
180
|
+
// ingest host (MODELRIG_INGEST_URL ‖ default) as `baseUrl`, the `rig_sk_` key
|
|
181
|
+
// as the Bearer credential (NO provider key ever). Absent for local-only /
|
|
182
|
+
// direct rigs ⇒ a `modelrig-served` run fails closed (no control plane to
|
|
183
|
+
// serve it), never a silent `direct` fall back. Read ONLY on the served path.
|
|
184
|
+
...(config.export?.mode === "api"
|
|
185
|
+
? { serve: { baseUrl: config.export.ingestUrl, apiKey: config.export.apiKey } }
|
|
186
|
+
: {}),
|
|
174
187
|
...(config.envelopeBudgetUsd !== undefined
|
|
175
188
|
? { envelopeBudgetUsd: config.envelopeBudgetUsd }
|
|
176
189
|
: {}),
|
|
@@ -197,11 +210,16 @@ function createRig(config) {
|
|
|
197
210
|
// Bake-off review-sample sink (addendum A3) — direct mode only (see buildDirectSamplesSink; undefined for api/local rigs). S7: scrubs input+output with the task ScrubMode before persist.
|
|
198
211
|
const samplesSink = config.export?.mode === "direct" ? (0, samples_1.buildDirectSamplesSink)({ ...config.export, resolver: settings, defaultScrub: config.artifacts?.content !== undefined ? config_1.DEFAULT_CONTENT_SCRUB_MODE : "off" }) : undefined;
|
|
199
212
|
const resolveReferenceAuto = (0, reference_1.makeReferenceAutoResolver)(config.registryPath); // RB-1 reference:auto
|
|
213
|
+
// PSR-2b (spec §4 ADJ-2): the client-fill tool registry backing rig.tools.
|
|
214
|
+
// One per rig; empty until the app calls rig.tools.register. In-process only —
|
|
215
|
+
// no network/telemetry reach, so bound tool keys never leave the process.
|
|
216
|
+
const tools = (0, tools_register_1.createToolRegistry)();
|
|
200
217
|
return {
|
|
201
218
|
serveability,
|
|
202
219
|
capabilities,
|
|
203
220
|
searchAvailable: search !== null && search !== undefined,
|
|
204
221
|
artifacts: artifactNamespace,
|
|
222
|
+
tools,
|
|
205
223
|
exporterStats: () => (exporter !== null ? exporter.stats() : { poisonSkipped: {} }),
|
|
206
224
|
status: () => (0, status_1.buildRigStatus)(config, settings?.snapshot() ?? new Map(), undefined, settings?.posture() ?? null),
|
|
207
225
|
run(route, opts) {
|
|
@@ -363,6 +381,33 @@ Object.defineProperty(exports, "resolveOtlpConfig", { enumerable: true, get: fun
|
|
|
363
381
|
// Artifact / execution-graph namespace (Expansion E2) — the barrel re-exports
|
|
364
382
|
// step/run-context/types; the run lifecycle is bound per-rig via rig.artifacts.
|
|
365
383
|
__exportStar(require("./artifacts"), exports);
|
|
384
|
+
// PSR-1 — the structure-only assembly-manifest model (spec §2.1), re-exported
|
|
385
|
+
// EXPLICITLY from the package entry (not only transitively via the artifacts
|
|
386
|
+
// star-export) so an external consumer resolving the built `dist/index.d.ts`
|
|
387
|
+
// gets `Manifest`/`Slot` + the validators on the public surface unambiguously.
|
|
388
|
+
var manifest_2 = require("./prompts/manifest");
|
|
389
|
+
Object.defineProperty(exports, "validateManifest", { enumerable: true, get: function () { return manifest_2.validateManifest; } });
|
|
390
|
+
Object.defineProperty(exports, "assertValidManifest", { enumerable: true, get: function () { return manifest_2.assertValidManifest; } });
|
|
391
|
+
Object.defineProperty(exports, "parseAuthoringDoc", { enumerable: true, get: function () { return manifest_2.parseAuthoringDoc; } });
|
|
392
|
+
Object.defineProperty(exports, "normalizeManifest", { enumerable: true, get: function () { return manifest_2.normalizeManifest; } });
|
|
393
|
+
// PSR-2 — the content-hash id (`template_sha`) the version store dedupes on.
|
|
394
|
+
var version_hash_1 = require("./prompts/version-hash");
|
|
395
|
+
Object.defineProperty(exports, "promptTemplateSha", { enumerable: true, get: function () { return version_hash_1.promptTemplateSha; } });
|
|
396
|
+
// PSR-2b — SDK fetch-by-label + content cache + fail-open resolver + the
|
|
397
|
+
// client-fill engine (slot resolver) + the tool-binding registry (rig.tools).
|
|
398
|
+
// All client-side / in-process (spec §3–§4).
|
|
399
|
+
var prompt_fetch_1 = require("./prompts/prompt-fetch");
|
|
400
|
+
Object.defineProperty(exports, "createApiPromptFetcher", { enumerable: true, get: function () { return prompt_fetch_1.createApiPromptFetcher; } });
|
|
401
|
+
Object.defineProperty(exports, "createPromptCache", { enumerable: true, get: function () { return prompt_fetch_1.createPromptCache; } });
|
|
402
|
+
Object.defineProperty(exports, "parseServedPrompt", { enumerable: true, get: function () { return prompt_fetch_1.parseServedPrompt; } });
|
|
403
|
+
var prompt_resolve_1 = require("./prompts/prompt-resolve");
|
|
404
|
+
Object.defineProperty(exports, "createPromptResolver", { enumerable: true, get: function () { return prompt_resolve_1.createPromptResolver; } });
|
|
405
|
+
Object.defineProperty(exports, "createEmbeddedPrompts", { enumerable: true, get: function () { return prompt_resolve_1.createEmbeddedPrompts; } });
|
|
406
|
+
var slot_resolver_1 = require("./prompts/slot-resolver");
|
|
407
|
+
Object.defineProperty(exports, "assemblePrompt", { enumerable: true, get: function () { return slot_resolver_1.assemblePrompt; } });
|
|
408
|
+
Object.defineProperty(exports, "SlotResolutionError", { enumerable: true, get: function () { return slot_resolver_1.SlotResolutionError; } });
|
|
409
|
+
var tools_register_2 = require("./prompts/tools-register");
|
|
410
|
+
Object.defineProperty(exports, "createToolRegistry", { enumerable: true, get: function () { return tools_register_2.createToolRegistry; } });
|
|
366
411
|
var config_4 = require("./config");
|
|
367
412
|
Object.defineProperty(exports, "resolveArtifactsConfig", { enumerable: true, get: function () { return config_4.resolveArtifactsConfig; } });
|
|
368
413
|
__exportStar(require("./detect/detector"), exports); // shared Detector interface (screening A1, types-only)
|
|
@@ -391,6 +436,9 @@ var quality_1 = require("./bakeoff/quality"); // LRE-1b graders
|
|
|
391
436
|
Object.defineProperty(exports, "exactMatch", { enumerable: true, get: function () { return quality_1.exactMatch; } });
|
|
392
437
|
Object.defineProperty(exports, "fieldAccuracy", { enumerable: true, get: function () { return quality_1.fieldAccuracy; } });
|
|
393
438
|
Object.defineProperty(exports, "resolveDeterministicQuality", { enumerable: true, get: function () { return quality_1.resolveDeterministicQuality; } });
|
|
439
|
+
var groundedness_1 = require("./bakeoff/groundedness"); // call-QA F3/G6 evidence-grounded grader
|
|
440
|
+
Object.defineProperty(exports, "groundednessScore", { enumerable: true, get: function () { return groundedness_1.groundednessScore; } });
|
|
441
|
+
Object.defineProperty(exports, "extractEvidenceQuotes", { enumerable: true, get: function () { return groundedness_1.extractEvidenceQuotes; } });
|
|
394
442
|
// LRE-1b server runner: the from-eval-cases orchestrator + injected-store contract so modelrig-server drives a cross-plane golden bake-off with the rig's keyed adapters (rig.bakeoffFromEvalCasesWith).
|
|
395
443
|
var eval_cases_1 = require("./bakeoff/eval-cases");
|
|
396
444
|
Object.defineProperty(exports, "runBakeoffFromEvalCases", { enumerable: true, get: function () { return eval_cases_1.runBakeoffFromEvalCases; } });
|
|
@@ -525,8 +573,14 @@ Object.defineProperty(exports, "PROVIDER_KEY_ENV", { enumerable: true, get: func
|
|
|
525
573
|
var gemini_1 = require("./adapters/gemini");
|
|
526
574
|
Object.defineProperty(exports, "createGeminiAdapter", { enumerable: true, get: function () { return gemini_1.createGeminiAdapter; } });
|
|
527
575
|
Object.defineProperty(exports, "GEMINI_THINKING_CAPABLE_MODELS", { enumerable: true, get: function () { return gemini_1.GEMINI_THINKING_CAPABLE_MODELS; } });
|
|
528
|
-
// CE-9 R5/R6 — the
|
|
576
|
+
// CE-9 R5/R6 + Unified Route U1 — the one provider × capability vocabulary (single source of truth for the guard, the docs matrix, AND the serving-destination lookups) + `rawKnobSupport(p)` / `destinationSupport(p)` so customers don't duplicate our provider lists.
|
|
529
577
|
__exportStar(require("./run/raw-support"), exports);
|
|
578
|
+
// Unified Route U1 (ruling D-2) — the serving `destination` vocabulary; its lookups read the `serving` cell of the capability table above (one source of truth). Managed serving is gated behind the `config.managedServing` flag (set in code via createRig, default off; U3).
|
|
579
|
+
var destination_1 = require("./run/destination");
|
|
580
|
+
Object.defineProperty(exports, "DESTINATIONS", { enumerable: true, get: function () { return destination_1.DESTINATIONS; } });
|
|
581
|
+
Object.defineProperty(exports, "DEFAULT_DESTINATION", { enumerable: true, get: function () { return destination_1.DEFAULT_DESTINATION; } });
|
|
582
|
+
Object.defineProperty(exports, "servedDestinations", { enumerable: true, get: function () { return destination_1.servedDestinations; } });
|
|
583
|
+
Object.defineProperty(exports, "destinationSupported", { enumerable: true, get: function () { return destination_1.destinationSupported; } });
|
|
530
584
|
var openai_1 = require("./adapters/openai");
|
|
531
585
|
Object.defineProperty(exports, "createOpenAIAdapter", { enumerable: true, get: function () { return openai_1.createOpenAIAdapter; } });
|
|
532
586
|
var deepseek_1 = require("./adapters/deepseek");
|
|
@@ -561,8 +615,8 @@ Object.defineProperty(exports, "synthesizeFromFlat", { enumerable: true, get: fu
|
|
|
561
615
|
Object.defineProperty(exports, "tierRates", { enumerable: true, get: function () { return pricing_shape_1.tierRates; } });
|
|
562
616
|
Object.defineProperty(exports, "describePricingV2", { enumerable: true, get: function () { return pricing_shape_1.describePricingV2; } });
|
|
563
617
|
Object.defineProperty(exports, "SNAPSHOT_BASIS", { enumerable: true, get: function () { return pricing_shape_1.SNAPSHOT_BASIS; } });
|
|
564
|
-
var
|
|
565
|
-
Object.defineProperty(exports, "loadManifest", { enumerable: true, get: function () { return
|
|
618
|
+
var manifest_3 = require("./routes/manifest");
|
|
619
|
+
Object.defineProperty(exports, "loadManifest", { enumerable: true, get: function () { return manifest_3.loadManifest; } });
|
|
566
620
|
var fingerprint_1 = require("./registry/fingerprint");
|
|
567
621
|
Object.defineProperty(exports, "fingerprintSchema", { enumerable: true, get: function () { return fingerprint_1.fingerprintSchema; } });
|
|
568
622
|
var facts_2 = require("./registry/facts");
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PSR-1 — the assembly-manifest model (spec §2.1, authoring-guide §2–§3).
|
|
3
|
+
*
|
|
4
|
+
* A prompt in ModelRig is TWO things: the authored `template` text and the
|
|
5
|
+
* `manifest` — the ordered recipe for assembling the final prompt at call time.
|
|
6
|
+
* This module is the **structure-only** manifest: its `Slot[]` records HOW each
|
|
7
|
+
* part of the prompt is filled, never the filled value (the privacy guarantee —
|
|
8
|
+
* a `dynamic·tool` slot names `search_tickets`, never what it returned).
|
|
9
|
+
*
|
|
10
|
+
* PSR-1 is ZERO-DDL and validate-only: nothing here serves or stores a version.
|
|
11
|
+
* It exists to prove the model against real prompts (the InferWealth inference)
|
|
12
|
+
* and a hand-authored doc (ADJ-1) before PSR-2 builds the `prompt_versions`
|
|
13
|
+
* store. Pure + dependency-free (no YAML dep — the authoring doc is accepted as
|
|
14
|
+
* JSON per §7; YAML is an optional future add).
|
|
15
|
+
*/
|
|
16
|
+
/** A slot is either authored text (`static`) or filled at run time (`dynamic`). */
|
|
17
|
+
export type SlotKind = "static" | "dynamic";
|
|
18
|
+
/** How a `dynamic` slot is filled (authoring-guide §2). Never the value. */
|
|
19
|
+
export type DynamicSourceKind = "tool" | "cache" | "upstream" | "variable";
|
|
20
|
+
/** Cache placement for a slot's content — `prefix` puts it at the front so the
|
|
21
|
+
* provider caches it across calls (maps to inferences.cache_key / prefix
|
|
22
|
+
* fingerprint); `none` is uncached. */
|
|
23
|
+
export type CachePolicy = "prefix" | "none";
|
|
24
|
+
/** Which authored field a `static` slot pulls its text from when it is not
|
|
25
|
+
* inlined (authoring-guide §3: the first static slot is `from: system`, the
|
|
26
|
+
* task instructions are `from: template`). */
|
|
27
|
+
export type StaticFrom = "system" | "template";
|
|
28
|
+
/** A `dynamic` slot's fill declaration — the source kind, the reference it
|
|
29
|
+
* resolves (tool name / cache handle / upstream step key / variable name), and
|
|
30
|
+
* an optional cache policy. Structure only; carries no resolved data (D6). */
|
|
31
|
+
export interface DynamicSource {
|
|
32
|
+
readonly kind: DynamicSourceKind;
|
|
33
|
+
readonly ref: string;
|
|
34
|
+
readonly cache_policy?: CachePolicy;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One slot in the assembly manifest.
|
|
38
|
+
*
|
|
39
|
+
* A `static` slot carries EITHER inline `text` OR a `from` reference to the
|
|
40
|
+
* doc's authored `system` / `template` field — exactly one (text XOR from;
|
|
41
|
+
* authoring-guide §3 uses `from`, spec §2.1 uses inline `text` — both are
|
|
42
|
+
* reconciled here). A `dynamic` slot carries a `source`.
|
|
43
|
+
*/
|
|
44
|
+
export interface Slot {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly kind: SlotKind;
|
|
47
|
+
/** static only — inline authored text (XOR `from`). */
|
|
48
|
+
readonly text?: string;
|
|
49
|
+
/** static only — pull the text from the doc's `system`/`template` (XOR `text`). */
|
|
50
|
+
readonly from?: StaticFrom;
|
|
51
|
+
/** dynamic only — how the slot is filled at run time. */
|
|
52
|
+
readonly source?: DynamicSource;
|
|
53
|
+
}
|
|
54
|
+
/** The assembly manifest — an ordered list of slots; list order = send order.
|
|
55
|
+
* No resolved values are ever present (structure only, D6). */
|
|
56
|
+
export interface Manifest {
|
|
57
|
+
readonly slots: readonly Slot[];
|
|
58
|
+
}
|
|
59
|
+
/** Result of {@link validateManifest} — a discriminated union so callers get the
|
|
60
|
+
* narrowed `Manifest` on success and a teaching error list on failure. */
|
|
61
|
+
export type ManifestValidation = {
|
|
62
|
+
readonly ok: true;
|
|
63
|
+
readonly manifest: Manifest;
|
|
64
|
+
} | {
|
|
65
|
+
readonly ok: false;
|
|
66
|
+
readonly errors: readonly string[];
|
|
67
|
+
};
|
|
68
|
+
/** Validate an untrusted value as a {@link Manifest} (spec §4). Rejects: an
|
|
69
|
+
* unknown slot kind, a `static` slot with BOTH or NEITHER `text`/`from`, a
|
|
70
|
+
* `dynamic` slot missing its `source` (or with a bad source kind / empty ref /
|
|
71
|
+
* bad cache_policy), a slot carrying fields of the wrong kind, and duplicate
|
|
72
|
+
* slot ids. Never throws — returns a result. */
|
|
73
|
+
export declare function validateManifest(input: unknown): ManifestValidation;
|
|
74
|
+
/** Throwing form of {@link validateManifest} — returns the narrowed manifest or
|
|
75
|
+
* throws with the joined error list. Use where an invalid manifest is a bug the
|
|
76
|
+
* caller wants surfaced (tests, the emit path's guard). */
|
|
77
|
+
export declare function assertValidManifest(input: unknown): Manifest;
|
|
78
|
+
/**
|
|
79
|
+
* Reduce a validated {@link Manifest} to ITS CANONICAL SHAPE — the ONE clean
|
|
80
|
+
* projection PSR-2 persists (spec §4 "re-validate + normalize on ingest").
|
|
81
|
+
*
|
|
82
|
+
* WHY (a PSR-1 QA finding): {@link validateManifest} NARROWS an untrusted value
|
|
83
|
+
* to `Manifest` but casts `slots as Slot[]` — it does NOT strip unknown keys, so
|
|
84
|
+
* a raw artifact blob can carry extra fields (`text` alongside a `from`, a stray
|
|
85
|
+
* `note`, a `source` on a static slot) that pass validation and would be stored
|
|
86
|
+
* verbatim. The ingest path (prompt-ingest.ts) must NEVER trust the artifact blob
|
|
87
|
+
* as-is: it re-validates AND normalizes here so `template_sha` (computed over the
|
|
88
|
+
* normalized manifest) is stable — identical content always dedupes to one row,
|
|
89
|
+
* regardless of incidental key noise in the source artifact.
|
|
90
|
+
*
|
|
91
|
+
* Each slot is rebuilt from scratch keeping ONLY the canonical keys:
|
|
92
|
+
* static → { id, kind, text } XOR { id, kind, from }
|
|
93
|
+
* dynamic → { id, kind, source: { kind, ref, cache_policy? } }
|
|
94
|
+
* Slot order is preserved (order = send order, D6). The rebuilt manifest is
|
|
95
|
+
* re-validated ({@link assertValidManifest}) so a caller that skipped validation
|
|
96
|
+
* still cannot persist a malformed shape.
|
|
97
|
+
*/
|
|
98
|
+
export declare function normalizeManifest(input: Manifest): Manifest;
|
|
99
|
+
/** The declared authoring document (authoring-guide §3). A superset of the
|
|
100
|
+
* manifest: the authored `system`/`template` text a `from`-slot references, plus
|
|
101
|
+
* the route metadata PSR-2/PSR-3 persist. PSR-1 reads only `manifest.slots`
|
|
102
|
+
* (validating that every `from` resolves to a present field). */
|
|
103
|
+
export interface AuthoringDoc {
|
|
104
|
+
readonly route?: string;
|
|
105
|
+
readonly segment?: string;
|
|
106
|
+
readonly system?: string;
|
|
107
|
+
readonly template?: string;
|
|
108
|
+
readonly manifest?: {
|
|
109
|
+
readonly slots?: unknown;
|
|
110
|
+
};
|
|
111
|
+
readonly output_schema?: unknown;
|
|
112
|
+
readonly candidates?: unknown;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* ADJ-1 — the "author from scratch" on-ramp. Parse a declared authoring doc
|
|
116
|
+
* (authoring-guide §3) into a validated {@link Manifest}. Accepts the doc as a
|
|
117
|
+
* JSON string OR an already-parsed object (§7: the MCP tool takes JSON; YAML is
|
|
118
|
+
* an optional future add and is NOT parsed here — a YAML string throws a
|
|
119
|
+
* teaching error). Beyond {@link validateManifest} it cross-checks that every
|
|
120
|
+
* `static` slot's `from: system|template` resolves to a present top-level field,
|
|
121
|
+
* so an author cannot reference authored text the doc does not carry.
|
|
122
|
+
*
|
|
123
|
+
* Structure-only: the returned manifest's slots are the authored slots verbatim
|
|
124
|
+
* (a `from`-slot keeps its `from`; the authored text is NOT inlined), so
|
|
125
|
+
* `parseAuthoringDoc` round-trips a hand-authored doc.
|
|
126
|
+
*/
|
|
127
|
+
export declare function parseAuthoringDoc(input: string | AuthoringDoc): Manifest;
|
|
128
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/prompts/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,mFAAmF;AACnF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE5C,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;AAE3E;;uCAEuC;AACvC,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5C;;8CAE8C;AAC9C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE/C;;8EAE8E;AAC9E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC;CACjC;AAED;+DAC+D;AAC/D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACjC;AAED;0EAC0E;AAC1E,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAmB/D;;;;gDAIgD;AAChD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CA2DnE;AAkBD;;2DAE2D;AAC3D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAM5D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAiB3D;AAED;;;iEAGiE;AACjE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACjD,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,CAmCxE"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PSR-1 — the assembly-manifest model (spec §2.1, authoring-guide §2–§3).
|
|
4
|
+
*
|
|
5
|
+
* A prompt in ModelRig is TWO things: the authored `template` text and the
|
|
6
|
+
* `manifest` — the ordered recipe for assembling the final prompt at call time.
|
|
7
|
+
* This module is the **structure-only** manifest: its `Slot[]` records HOW each
|
|
8
|
+
* part of the prompt is filled, never the filled value (the privacy guarantee —
|
|
9
|
+
* a `dynamic·tool` slot names `search_tickets`, never what it returned).
|
|
10
|
+
*
|
|
11
|
+
* PSR-1 is ZERO-DDL and validate-only: nothing here serves or stores a version.
|
|
12
|
+
* It exists to prove the model against real prompts (the InferWealth inference)
|
|
13
|
+
* and a hand-authored doc (ADJ-1) before PSR-2 builds the `prompt_versions`
|
|
14
|
+
* store. Pure + dependency-free (no YAML dep — the authoring doc is accepted as
|
|
15
|
+
* JSON per §7; YAML is an optional future add).
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.validateManifest = validateManifest;
|
|
19
|
+
exports.assertValidManifest = assertValidManifest;
|
|
20
|
+
exports.normalizeManifest = normalizeManifest;
|
|
21
|
+
exports.parseAuthoringDoc = parseAuthoringDoc;
|
|
22
|
+
const DYNAMIC_KINDS = new Set([
|
|
23
|
+
"tool",
|
|
24
|
+
"cache",
|
|
25
|
+
"upstream",
|
|
26
|
+
"variable",
|
|
27
|
+
]);
|
|
28
|
+
const CACHE_POLICIES = new Set(["prefix", "none"]);
|
|
29
|
+
const STATIC_FROMS = new Set(["system", "template"]);
|
|
30
|
+
function isRecord(v) {
|
|
31
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
32
|
+
}
|
|
33
|
+
function isNonEmptyString(v) {
|
|
34
|
+
return typeof v === "string" && v.length > 0;
|
|
35
|
+
}
|
|
36
|
+
/** Validate an untrusted value as a {@link Manifest} (spec §4). Rejects: an
|
|
37
|
+
* unknown slot kind, a `static` slot with BOTH or NEITHER `text`/`from`, a
|
|
38
|
+
* `dynamic` slot missing its `source` (or with a bad source kind / empty ref /
|
|
39
|
+
* bad cache_policy), a slot carrying fields of the wrong kind, and duplicate
|
|
40
|
+
* slot ids. Never throws — returns a result. */
|
|
41
|
+
function validateManifest(input) {
|
|
42
|
+
const errors = [];
|
|
43
|
+
if (!isRecord(input)) {
|
|
44
|
+
return { ok: false, errors: ["manifest must be an object with a `slots` array"] };
|
|
45
|
+
}
|
|
46
|
+
const slots = input["slots"];
|
|
47
|
+
if (!Array.isArray(slots)) {
|
|
48
|
+
return { ok: false, errors: ["manifest.slots must be an array"] };
|
|
49
|
+
}
|
|
50
|
+
const seenIds = new Set();
|
|
51
|
+
slots.forEach((raw, i) => {
|
|
52
|
+
const at = `slots[${i}]`;
|
|
53
|
+
if (!isRecord(raw)) {
|
|
54
|
+
errors.push(`${at} must be an object`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const id = raw["id"];
|
|
58
|
+
if (!isNonEmptyString(id)) {
|
|
59
|
+
errors.push(`${at}.id must be a non-empty string`);
|
|
60
|
+
}
|
|
61
|
+
else if (seenIds.has(id)) {
|
|
62
|
+
errors.push(`${at}.id "${id}" is a duplicate — slot ids must be unique`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
seenIds.add(id);
|
|
66
|
+
}
|
|
67
|
+
const kind = raw["kind"];
|
|
68
|
+
const hasText = raw["text"] !== undefined;
|
|
69
|
+
const hasFrom = raw["from"] !== undefined;
|
|
70
|
+
const hasSource = raw["source"] !== undefined;
|
|
71
|
+
if (kind === "static") {
|
|
72
|
+
if (hasSource)
|
|
73
|
+
errors.push(`${at} is static but carries a dynamic \`source\``);
|
|
74
|
+
if (hasText && hasFrom) {
|
|
75
|
+
errors.push(`${at} static slot has BOTH \`text\` and \`from\` — exactly one is allowed`);
|
|
76
|
+
}
|
|
77
|
+
else if (!hasText && !hasFrom) {
|
|
78
|
+
errors.push(`${at} static slot has NEITHER \`text\` nor \`from\` — exactly one is required`);
|
|
79
|
+
}
|
|
80
|
+
else if (hasText && typeof raw["text"] !== "string") {
|
|
81
|
+
errors.push(`${at}.text must be a string`);
|
|
82
|
+
}
|
|
83
|
+
else if (hasFrom && !STATIC_FROMS.has(raw["from"])) {
|
|
84
|
+
errors.push(`${at}.from must be one of system, template`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (kind === "dynamic") {
|
|
88
|
+
if (hasText || hasFrom) {
|
|
89
|
+
errors.push(`${at} is dynamic but carries static \`text\`/\`from\``);
|
|
90
|
+
}
|
|
91
|
+
if (!hasSource) {
|
|
92
|
+
errors.push(`${at} dynamic slot is missing its \`source\``);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
validateSource(raw["source"], at, errors);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
errors.push(`${at}.kind must be one of static, dynamic (got ${JSON.stringify(kind)})`);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (errors.length > 0)
|
|
103
|
+
return { ok: false, errors };
|
|
104
|
+
return { ok: true, manifest: { slots: slots } };
|
|
105
|
+
}
|
|
106
|
+
function validateSource(source, at, errors) {
|
|
107
|
+
if (!isRecord(source)) {
|
|
108
|
+
errors.push(`${at}.source must be an object`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!DYNAMIC_KINDS.has(source["kind"])) {
|
|
112
|
+
errors.push(`${at}.source.kind must be one of tool, cache, upstream, variable`);
|
|
113
|
+
}
|
|
114
|
+
if (!isNonEmptyString(source["ref"])) {
|
|
115
|
+
errors.push(`${at}.source.ref must be a non-empty string`);
|
|
116
|
+
}
|
|
117
|
+
if (source["cache_policy"] !== undefined && !CACHE_POLICIES.has(source["cache_policy"])) {
|
|
118
|
+
errors.push(`${at}.source.cache_policy must be one of prefix, none`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Throwing form of {@link validateManifest} — returns the narrowed manifest or
|
|
122
|
+
* throws with the joined error list. Use where an invalid manifest is a bug the
|
|
123
|
+
* caller wants surfaced (tests, the emit path's guard). */
|
|
124
|
+
function assertValidManifest(input) {
|
|
125
|
+
const result = validateManifest(input);
|
|
126
|
+
if (!result.ok) {
|
|
127
|
+
throw new Error(`invalid manifest: ${result.errors.join("; ")}`);
|
|
128
|
+
}
|
|
129
|
+
return result.manifest;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Reduce a validated {@link Manifest} to ITS CANONICAL SHAPE — the ONE clean
|
|
133
|
+
* projection PSR-2 persists (spec §4 "re-validate + normalize on ingest").
|
|
134
|
+
*
|
|
135
|
+
* WHY (a PSR-1 QA finding): {@link validateManifest} NARROWS an untrusted value
|
|
136
|
+
* to `Manifest` but casts `slots as Slot[]` — it does NOT strip unknown keys, so
|
|
137
|
+
* a raw artifact blob can carry extra fields (`text` alongside a `from`, a stray
|
|
138
|
+
* `note`, a `source` on a static slot) that pass validation and would be stored
|
|
139
|
+
* verbatim. The ingest path (prompt-ingest.ts) must NEVER trust the artifact blob
|
|
140
|
+
* as-is: it re-validates AND normalizes here so `template_sha` (computed over the
|
|
141
|
+
* normalized manifest) is stable — identical content always dedupes to one row,
|
|
142
|
+
* regardless of incidental key noise in the source artifact.
|
|
143
|
+
*
|
|
144
|
+
* Each slot is rebuilt from scratch keeping ONLY the canonical keys:
|
|
145
|
+
* static → { id, kind, text } XOR { id, kind, from }
|
|
146
|
+
* dynamic → { id, kind, source: { kind, ref, cache_policy? } }
|
|
147
|
+
* Slot order is preserved (order = send order, D6). The rebuilt manifest is
|
|
148
|
+
* re-validated ({@link assertValidManifest}) so a caller that skipped validation
|
|
149
|
+
* still cannot persist a malformed shape.
|
|
150
|
+
*/
|
|
151
|
+
function normalizeManifest(input) {
|
|
152
|
+
const slots = input.slots.map((slot) => {
|
|
153
|
+
if (slot.kind === "static") {
|
|
154
|
+
// text XOR from — validation guarantees exactly one is present.
|
|
155
|
+
if (slot.text !== undefined) {
|
|
156
|
+
return { id: slot.id, kind: "static", text: slot.text };
|
|
157
|
+
}
|
|
158
|
+
return { id: slot.id, kind: "static", from: slot.from };
|
|
159
|
+
}
|
|
160
|
+
const src = slot.source;
|
|
161
|
+
const source = src.cache_policy !== undefined
|
|
162
|
+
? { kind: src.kind, ref: src.ref, cache_policy: src.cache_policy }
|
|
163
|
+
: { kind: src.kind, ref: src.ref };
|
|
164
|
+
return { id: slot.id, kind: "dynamic", source };
|
|
165
|
+
});
|
|
166
|
+
return assertValidManifest({ slots });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* ADJ-1 — the "author from scratch" on-ramp. Parse a declared authoring doc
|
|
170
|
+
* (authoring-guide §3) into a validated {@link Manifest}. Accepts the doc as a
|
|
171
|
+
* JSON string OR an already-parsed object (§7: the MCP tool takes JSON; YAML is
|
|
172
|
+
* an optional future add and is NOT parsed here — a YAML string throws a
|
|
173
|
+
* teaching error). Beyond {@link validateManifest} it cross-checks that every
|
|
174
|
+
* `static` slot's `from: system|template` resolves to a present top-level field,
|
|
175
|
+
* so an author cannot reference authored text the doc does not carry.
|
|
176
|
+
*
|
|
177
|
+
* Structure-only: the returned manifest's slots are the authored slots verbatim
|
|
178
|
+
* (a `from`-slot keeps its `from`; the authored text is NOT inlined), so
|
|
179
|
+
* `parseAuthoringDoc` round-trips a hand-authored doc.
|
|
180
|
+
*/
|
|
181
|
+
function parseAuthoringDoc(input) {
|
|
182
|
+
let doc = input;
|
|
183
|
+
if (typeof input === "string") {
|
|
184
|
+
try {
|
|
185
|
+
doc = JSON.parse(input);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
throw new Error("authoring doc must be JSON (YAML is not parsed here — pass JSON per authoring-guide §7): " +
|
|
189
|
+
(err instanceof Error ? err.message : String(err)));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (!isRecord(doc)) {
|
|
193
|
+
throw new Error("authoring doc must be an object");
|
|
194
|
+
}
|
|
195
|
+
const manifestBlock = doc["manifest"];
|
|
196
|
+
if (!isRecord(manifestBlock)) {
|
|
197
|
+
throw new Error("authoring doc is missing a `manifest` block");
|
|
198
|
+
}
|
|
199
|
+
const manifest = assertValidManifest(manifestBlock);
|
|
200
|
+
// ADJ-1 cross-check: a `from` slot must reference a present authored field.
|
|
201
|
+
const hasSystem = typeof doc["system"] === "string";
|
|
202
|
+
const hasTemplate = typeof doc["template"] === "string";
|
|
203
|
+
const missing = [];
|
|
204
|
+
for (const slot of manifest.slots) {
|
|
205
|
+
if (slot.from === "system" && !hasSystem)
|
|
206
|
+
missing.push(`slot "${slot.id}" references \`system\``);
|
|
207
|
+
if (slot.from === "template" && !hasTemplate)
|
|
208
|
+
missing.push(`slot "${slot.id}" references \`template\``);
|
|
209
|
+
}
|
|
210
|
+
if (missing.length > 0) {
|
|
211
|
+
throw new Error(`authoring doc has \`from\` slots with no matching authored field: ${missing.join("; ")}`);
|
|
212
|
+
}
|
|
213
|
+
return manifest;
|
|
214
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PSR-2b — SDK fetch-by-label + the content-addressed prompt cache (spec §3
|
|
3
|
+
* "SDK read", §4). The remote half of serving a prompt by its movable `prod`
|
|
4
|
+
* label.
|
|
5
|
+
*
|
|
6
|
+
* The gateway already serves the promoted version's template+manifest through
|
|
7
|
+
* `routes.bundle` (PSR-2a's write-through). This module adds the OPTIONAL
|
|
8
|
+
* explicit read the SDK uses when it wants a prompt by label directly:
|
|
9
|
+
* GET /v1/prompts/:route?label=prod (key-auth, org-scoped)
|
|
10
|
+
* → { version, template, manifest, template_sha }
|
|
11
|
+
* ETag: <template_sha> (304 Not Modified when it matches)
|
|
12
|
+
*
|
|
13
|
+
* The fetcher mirrors `call-config.ts`'s leak discipline: header-only auth, no
|
|
14
|
+
* body/URL in an error (C2), and it NEVER throws — a network/HTTP failure
|
|
15
|
+
* resolves `null`, a 304 resolves `"not-modified"`, a malformed 200 resolves
|
|
16
|
+
* `null`. So the fail-open resolver ({@link ./prompt-resolve}) always stays
|
|
17
|
+
* fail-open around it.
|
|
18
|
+
*
|
|
19
|
+
* The cache is CONTENT-ADDRESSED, keyed `label+template_sha` (spec §3): the
|
|
20
|
+
* same served content is one entry regardless of how many times it is fetched,
|
|
21
|
+
* and a per-(route,label) pointer records the last-known-good sha — the tier the
|
|
22
|
+
* resolver falls back to when the control plane is unreachable.
|
|
23
|
+
*/
|
|
24
|
+
import { type Manifest } from "./manifest";
|
|
25
|
+
/** A prompt served by label — the explicit endpoint's body and the unit the
|
|
26
|
+
* client cache holds. `template_sha` is both the content id and the ETag. */
|
|
27
|
+
export interface ServedPrompt {
|
|
28
|
+
readonly version: number;
|
|
29
|
+
readonly template: string;
|
|
30
|
+
readonly manifest: Manifest;
|
|
31
|
+
readonly template_sha: string;
|
|
32
|
+
}
|
|
33
|
+
/** Pulls one route's prompt for a label, ETag-aware. Returns the prompt, `"not-
|
|
34
|
+
* modified"` (304 — keep the cache), or `null` (miss/error — the resolver keeps
|
|
35
|
+
* last-known-good). NEVER throws. */
|
|
36
|
+
export interface PromptFetcher {
|
|
37
|
+
fetch(route: string, label: string, etag: string | undefined): Promise<ServedPrompt | "not-modified" | null>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Narrow an untrusted endpoint body into a {@link ServedPrompt}, or null when the
|
|
41
|
+
* shape is not what the endpoint promises (a malformed 200 is a miss, never
|
|
42
|
+
* trusted — we never fabricate a served prompt from junk). The manifest is
|
|
43
|
+
* validated with the shared {@link validateManifest} so a structurally-broken
|
|
44
|
+
* manifest can never reach the client-fill engine.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseServedPrompt(body: unknown): ServedPrompt | null;
|
|
47
|
+
/**
|
|
48
|
+
* The content-addressed prompt cache (spec §3). Holds served content keyed
|
|
49
|
+
* `label+template_sha`, plus a per-(route,label) pointer to the last-known-good
|
|
50
|
+
* sha. `put` stores the content AND advances the pointer (a fetched version is
|
|
51
|
+
* now the last-known-good); `lastKnown` reads the current content for a label —
|
|
52
|
+
* the fail-open tier the resolver serves when a fetch cannot complete.
|
|
53
|
+
*/
|
|
54
|
+
export interface PromptCache {
|
|
55
|
+
/** The served content for an exact (route,label,sha), if held. */
|
|
56
|
+
get(route: string, label: string, sha: string): ServedPrompt | undefined;
|
|
57
|
+
/** The last-known-good served content for (route,label), if any has landed. */
|
|
58
|
+
lastKnown(route: string, label: string): ServedPrompt | undefined;
|
|
59
|
+
/** The last-known-good sha for (route,label) — the ETag to revalidate with. */
|
|
60
|
+
lastKnownSha(route: string, label: string): string | undefined;
|
|
61
|
+
/** Store content and advance the last-known-good pointer to its sha. */
|
|
62
|
+
put(route: string, label: string, prompt: ServedPrompt): void;
|
|
63
|
+
}
|
|
64
|
+
/** Build an empty {@link PromptCache}. One per rig. In-memory only — a prompt
|
|
65
|
+
* cache is a per-process convenience, never durable state. */
|
|
66
|
+
export declare function createPromptCache(): PromptCache;
|
|
67
|
+
export interface ApiPromptFetcherConfig {
|
|
68
|
+
/** Base URL of the hosted control plane — the SAME `ingestUrl` the api sink
|
|
69
|
+
* and call-config fetcher use (the prompt path hangs off the host). */
|
|
70
|
+
readonly ingestUrl: string;
|
|
71
|
+
/** `rig_sk_…` key. A read rides the readable route + prompt rows; header only,
|
|
72
|
+
* never a URL (C2). */
|
|
73
|
+
readonly apiKey: string;
|
|
74
|
+
readonly fetchFn?: typeof fetch;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The api-mode prompt fetcher: one authenticated, ETag-aware GET per (route,
|
|
78
|
+
* label). Mirrors the api sink's leak discipline (status only, never the
|
|
79
|
+
* body/URL in an error — C2). NEVER throws: a network/HTTP failure resolves
|
|
80
|
+
* null, a 304 resolves "not-modified", a malformed 200 resolves null — so the
|
|
81
|
+
* resolver stays fail-open.
|
|
82
|
+
*/
|
|
83
|
+
export declare function createApiPromptFetcher(config: ApiPromptFetcherConfig): PromptFetcher;
|
|
84
|
+
//# sourceMappingURL=prompt-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-fetch.d.ts","sourceRoot":"","sources":["../../src/prompts/prompt-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE7D;6EAC6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;qCAEqC;AACrC,MAAM,WAAW,aAAa;IAC5B,KAAK,CACH,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,OAAO,CAAC,YAAY,GAAG,cAAc,GAAG,IAAI,CAAC,CAAC;CAClD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CAcpE;AAYD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IACzE,+EAA+E;IAC/E,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IAClE,+EAA+E;IAC/E,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC/D,wEAAwE;IACxE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;CAC/D;AAED;8DAC8D;AAC9D,wBAAgB,iBAAiB,IAAI,WAAW,CAmB/C;AAED,MAAM,WAAW,sBAAsB;IACrC;2EACuE;IACvE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;2BACuB;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,aAAa,CA4BpF"}
|