@harperfast/harper 5.3.0-beta.3 → 5.3.0-beta.4
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/bin/cliOperations.ts +25 -3
- package/bin/run.ts +18 -0
- package/components/Application.ts +52 -78
- package/components/DESIGN.md +76 -3
- package/components/Scope.ts +10 -4
- package/components/anthropic/index.ts +10 -1
- package/components/bedrock/index.ts +10 -1
- package/components/componentLoader.ts +23 -14
- package/components/mcp/tools/operations.ts +3 -1
- package/components/ollama/index.ts +10 -1
- package/components/openai/index.ts +265 -18
- package/components/operations.js +40 -1
- package/config/configUtils.ts +3 -19
- package/dataLayer/DESIGN.md +29 -5
- package/dataLayer/harperBridge/ResourceBridge.ts +39 -3
- package/dataLayer/restoreMarker.ts +250 -14
- package/dataLayer/schema.ts +2 -7
- package/dataLayer/schemaDescribe.ts +10 -0
- package/dist/bin/cliOperations.js +28 -3
- package/dist/bin/cliOperations.js.map +1 -1
- package/dist/bin/run.js +19 -0
- package/dist/bin/run.js.map +1 -1
- package/dist/components/Application.d.ts +8 -2
- package/dist/components/Application.js +43 -69
- package/dist/components/Application.js.map +1 -1
- package/dist/components/Scope.d.ts +1 -1
- package/dist/components/Scope.js +9 -4
- package/dist/components/Scope.js.map +1 -1
- package/dist/components/anthropic/index.d.ts +0 -10
- package/dist/components/anthropic/index.js +9 -1
- package/dist/components/anthropic/index.js.map +1 -1
- package/dist/components/bedrock/index.d.ts +0 -12
- package/dist/components/bedrock/index.js +9 -1
- package/dist/components/bedrock/index.js.map +1 -1
- package/dist/components/componentLoader.js +23 -14
- package/dist/components/componentLoader.js.map +1 -1
- package/dist/components/mcp/tools/operations.js +1 -1
- package/dist/components/mcp/tools/operations.js.map +1 -1
- package/dist/components/ollama/index.d.ts +0 -13
- package/dist/components/ollama/index.js +9 -1
- package/dist/components/ollama/index.js.map +1 -1
- package/dist/components/openai/index.d.ts +11 -15
- package/dist/components/openai/index.js +224 -12
- package/dist/components/openai/index.js.map +1 -1
- package/dist/components/operations.d.ts +9 -0
- package/dist/components/operations.js +32 -2
- package/dist/components/operations.js.map +1 -1
- package/dist/config/configUtils.d.ts +1 -2
- package/dist/config/configUtils.js +7 -22
- package/dist/config/configUtils.js.map +1 -1
- package/dist/dataLayer/harperBridge/ResourceBridge.js +29 -2
- package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
- package/dist/dataLayer/restoreMarker.d.ts +25 -3
- package/dist/dataLayer/restoreMarker.js +213 -13
- package/dist/dataLayer/restoreMarker.js.map +1 -1
- package/dist/dataLayer/schema.js +1 -4
- package/dist/dataLayer/schema.js.map +1 -1
- package/dist/dataLayer/schemaDescribe.js +10 -0
- package/dist/dataLayer/schemaDescribe.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/json/systemSchema.json +28 -0
- package/dist/resources/DatabaseTransaction.d.ts +21 -1
- package/dist/resources/DatabaseTransaction.js +147 -8
- package/dist/resources/DatabaseTransaction.js.map +1 -1
- package/dist/resources/PrimaryRocksDatabase.js +1 -1
- package/dist/resources/PrimaryRocksDatabase.js.map +1 -1
- package/dist/resources/Table.d.ts +31 -3
- package/dist/resources/Table.js +397 -79
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/auditStore.js +16 -10
- package/dist/resources/auditStore.js.map +1 -1
- package/dist/resources/blob.d.ts +1 -0
- package/dist/resources/blob.js +14 -5
- package/dist/resources/blob.js.map +1 -1
- package/dist/resources/branchDatabase.js +3 -3
- package/dist/resources/branchDatabase.js.map +1 -1
- package/dist/resources/databaseDropPreparation.d.ts +20 -0
- package/dist/resources/databaseDropPreparation.js +106 -0
- package/dist/resources/databaseDropPreparation.js.map +1 -0
- package/dist/resources/databases.d.ts +26 -21
- package/dist/resources/databases.js +1040 -204
- package/dist/resources/databases.js.map +1 -1
- package/dist/resources/derivedIndexRegistry.d.ts +23 -0
- package/dist/resources/derivedIndexRegistry.js +92 -0
- package/dist/resources/derivedIndexRegistry.js.map +1 -1
- package/dist/resources/derivedIndexRuntime.d.ts +10 -0
- package/dist/resources/derivedIndexRuntime.js +136 -25
- package/dist/resources/derivedIndexRuntime.js.map +1 -1
- package/dist/resources/derivedIndexes.d.ts +39 -0
- package/dist/resources/derivedIndexes.js +733 -0
- package/dist/resources/derivedIndexes.js.map +1 -0
- package/dist/resources/fullTextSchema.d.ts +8 -0
- package/dist/resources/fullTextSchema.js +42 -0
- package/dist/resources/fullTextSchema.js.map +1 -1
- package/dist/resources/fullTextSchemaLifecycle.d.ts +0 -5
- package/dist/resources/fullTextSchemaLifecycle.js +0 -9
- package/dist/resources/fullTextSchemaLifecycle.js.map +1 -1
- package/dist/resources/graphql.js +101 -9
- package/dist/resources/graphql.js.map +1 -1
- package/dist/resources/indexes/hnswDerivedIndex.d.ts +0 -10
- package/dist/resources/indexes/hnswDerivedIndex.js +0 -230
- package/dist/resources/indexes/hnswDerivedIndex.js.map +1 -1
- package/dist/resources/indexes/nativeFullTextDerivedIndexLifecycle.d.ts +3 -0
- package/dist/resources/indexes/nativeFullTextDerivedIndexLifecycle.js +57 -8
- package/dist/resources/indexes/nativeFullTextDerivedIndexLifecycle.js.map +1 -1
- package/dist/resources/models/Models.d.ts +26 -3
- package/dist/resources/models/Models.js +256 -13
- package/dist/resources/models/Models.js.map +1 -1
- package/dist/resources/models/TestBackend.d.ts +3 -1
- package/dist/resources/models/TestBackend.js +35 -1
- package/dist/resources/models/TestBackend.js.map +1 -1
- package/dist/resources/models/analyticsTable.d.ts +2 -2
- package/dist/resources/models/analyticsTable.js +4 -2
- package/dist/resources/models/analyticsTable.js.map +1 -1
- package/dist/resources/models/backendHelpers.d.ts +24 -0
- package/dist/resources/models/backendHelpers.js +18 -1
- package/dist/resources/models/backendHelpers.js.map +1 -1
- package/dist/resources/models/backendRegistry.d.ts +10 -21
- package/dist/resources/models/backendRegistry.js +74 -18
- package/dist/resources/models/backendRegistry.js.map +1 -1
- package/dist/resources/models/bootstrap.d.ts +7 -0
- package/dist/resources/models/bootstrap.js +36 -4
- package/dist/resources/models/bootstrap.js.map +1 -1
- package/dist/resources/models/decideHook.d.ts +33 -0
- package/dist/resources/models/decideHook.js +105 -0
- package/dist/resources/models/decideHook.js.map +1 -0
- package/dist/resources/models/decision.d.ts +64 -0
- package/dist/resources/models/decision.js +507 -0
- package/dist/resources/models/decision.js.map +1 -0
- package/dist/resources/models/decisionStore.d.ts +134 -0
- package/dist/resources/models/decisionStore.js +350 -0
- package/dist/resources/models/decisionStore.js.map +1 -0
- package/dist/resources/models/embedHook.d.ts +66 -8
- package/dist/resources/models/embedHook.js +228 -61
- package/dist/resources/models/embedHook.js.map +1 -1
- package/dist/resources/models/generativeDecision.d.ts +58 -0
- package/dist/resources/models/generativeDecision.js +315 -0
- package/dist/resources/models/generativeDecision.js.map +1 -0
- package/dist/resources/models/types.d.ts +232 -4
- package/dist/security/authn/oidc/tokenExchange.js +3 -33
- package/dist/security/authn/oidc/tokenExchange.js.map +1 -1
- package/dist/security/authn/oidc/tokenUseTable.d.ts +9 -0
- package/dist/security/authn/oidc/tokenUseTable.js +28 -0
- package/dist/security/authn/oidc/tokenUseTable.js.map +1 -0
- package/dist/security/certificateVerification/certificateVerificationSource.d.ts +0 -1
- package/dist/security/certificateVerification/certificateVerificationSource.js +3 -3
- package/dist/security/certificateVerification/certificateVerificationSource.js.map +1 -1
- package/dist/security/certificateVerification/crlVerification.js +77 -165
- package/dist/security/certificateVerification/crlVerification.js.map +1 -1
- package/dist/security/certificateVerification/types.d.ts +0 -3
- package/dist/security/certificateVerification/verificationTables.d.ts +19 -0
- package/dist/security/certificateVerification/verificationTables.js +125 -0
- package/dist/security/certificateVerification/verificationTables.js.map +1 -0
- package/dist/security/certificateVerification/verificationUtils.d.ts +1 -1
- package/dist/security/certificateVerification/verificationUtils.js +6 -31
- package/dist/security/certificateVerification/verificationUtils.js.map +1 -1
- package/dist/security/jsLoader.d.ts +5 -0
- package/dist/security/jsLoader.js +8 -0
- package/dist/security/jsLoader.js.map +1 -1
- package/dist/server/Server.d.ts +1 -0
- package/dist/server/Server.js.map +1 -1
- package/dist/server/http.js +2 -2
- package/dist/server/http.js.map +1 -1
- package/dist/server/itc/serverHandlers.js +21 -2
- package/dist/server/itc/serverHandlers.js.map +1 -1
- package/dist/server/jobs/jobOwnership.d.ts +25 -0
- package/dist/server/jobs/jobOwnership.js +127 -0
- package/dist/server/jobs/jobOwnership.js.map +1 -0
- package/dist/server/jobs/jobProcess.js +9 -2
- package/dist/server/jobs/jobProcess.js.map +1 -1
- package/dist/server/jobs/jobs.js +18 -5
- package/dist/server/jobs/jobs.js.map +1 -1
- package/dist/server/loadRootComponents.js +10 -0
- package/dist/server/loadRootComponents.js.map +1 -1
- package/dist/server/serverHelpers/contentTypes.js +11 -1
- package/dist/server/serverHelpers/contentTypes.js.map +1 -1
- package/dist/server/serverHelpers/serverHandlers.js +12 -2
- package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
- package/dist/server/threads/itc.d.ts +4 -1
- package/dist/server/threads/itc.js +29 -6
- package/dist/server/threads/itc.js.map +1 -1
- package/dist/server/threads/manageThreads.d.ts +12 -4
- package/dist/server/threads/manageThreads.js +241 -119
- package/dist/server/threads/manageThreads.js.map +1 -1
- package/dist/server/threads/threadServer.d.ts +1 -0
- package/dist/server/threads/threadServer.js +15 -1
- package/dist/server/threads/threadServer.js.map +1 -1
- package/dist/server/threads/windowsProcessTree.d.ts +91 -0
- package/dist/server/threads/windowsProcessTree.js +361 -0
- package/dist/server/threads/windowsProcessTree.js.map +1 -0
- package/dist/server/throttle.d.ts +1 -1
- package/dist/server/throttle.js +8 -1
- package/dist/server/throttle.js.map +1 -1
- package/dist/upgrade/directives/5-3-0.js +53 -46
- package/dist/upgrade/directives/5-3-0.js.map +1 -1
- package/dist/utility/errors/hdbError.d.ts +10 -1
- package/dist/utility/errors/hdbError.js +55 -11
- package/dist/utility/errors/hdbError.js.map +1 -1
- package/dist/utility/fsync.d.ts +2 -0
- package/dist/utility/fsync.js +20 -0
- package/dist/utility/fsync.js.map +1 -0
- package/dist/utility/globalSchema.d.ts +18 -0
- package/dist/utility/hdbTerms.d.ts +3 -0
- package/dist/utility/hdbTerms.js +3 -0
- package/dist/utility/hdbTerms.js.map +1 -1
- package/dist/utility/signalling.d.ts +7 -1
- package/dist/utility/signalling.js +27 -3
- package/dist/utility/signalling.js.map +1 -1
- package/dist/utility/when.d.ts +1 -0
- package/dist/utility/when.js +21 -0
- package/dist/utility/when.js.map +1 -1
- package/dist/validation/configValidator.js +30 -3
- package/dist/validation/configValidator.js.map +1 -1
- package/index.ts +13 -0
- package/json/systemSchema.json +28 -0
- package/npm-shrinkwrap.json +151 -55
- package/package.json +14 -13
- package/resources/DESIGN.md +80 -100
- package/resources/DatabaseTransaction.ts +157 -10
- package/resources/PrimaryRocksDatabase.ts +2 -2
- package/resources/Table.ts +494 -101
- package/resources/auditStore.ts +18 -10
- package/resources/blob.ts +13 -6
- package/resources/branchDatabase.ts +3 -3
- package/resources/databaseDropPreparation.ts +120 -0
- package/resources/databases.ts +1155 -205
- package/resources/derivedIndexRegistry.ts +122 -0
- package/resources/derivedIndexRuntime.ts +157 -30
- package/resources/derivedIndexes.ts +856 -0
- package/resources/fullTextSchema.ts +55 -0
- package/resources/fullTextSchemaLifecycle.ts +0 -15
- package/resources/graphql.ts +107 -12
- package/resources/indexes/DESIGN.md +7 -0
- package/resources/indexes/hnswDerivedIndex.ts +0 -260
- package/resources/indexes/nativeFullTextDerivedIndexLifecycle.ts +72 -9
- package/resources/models/DESIGN.md +39 -0
- package/resources/models/Models.ts +361 -18
- package/resources/models/TestBackend.ts +56 -1
- package/resources/models/analyticsTable.ts +6 -4
- package/resources/models/backendHelpers.ts +17 -0
- package/resources/models/backendRegistry.ts +76 -21
- package/resources/models/bootstrap.ts +57 -7
- package/resources/models/decideHook.ts +135 -0
- package/resources/models/decision.ts +505 -0
- package/resources/models/decisionStore.ts +419 -0
- package/resources/models/embedHook.ts +272 -55
- package/resources/models/generativeDecision.ts +459 -0
- package/resources/models/types.ts +231 -4
- package/security/DESIGN.md +22 -2
- package/security/authn/oidc/tokenExchange.ts +6 -34
- package/security/authn/oidc/tokenUseTable.ts +27 -0
- package/security/certificateVerification/certificateVerificationSource.ts +2 -3
- package/security/certificateVerification/crlVerification.ts +96 -174
- package/security/certificateVerification/types.ts +0 -3
- package/security/certificateVerification/verificationTables.ts +124 -0
- package/security/certificateVerification/verificationUtils.ts +8 -32
- package/security/jsLoader.ts +9 -1
- package/server/DESIGN.md +27 -1
- package/server/Server.ts +2 -1
- package/server/http.ts +4 -2
- package/server/itc/serverHandlers.js +29 -1
- package/server/jobs/jobOwnership.ts +89 -0
- package/server/jobs/jobProcess.ts +8 -2
- package/server/jobs/jobs.ts +15 -4
- package/server/loadRootComponents.js +11 -0
- package/server/serverHelpers/contentTypes.ts +13 -1
- package/server/serverHelpers/serverHandlers.js +11 -2
- package/server/threads/itc.js +32 -6
- package/server/threads/manageThreads.js +268 -122
- package/server/threads/threadServer.js +13 -1
- package/server/threads/windowsProcessTree.ts +409 -0
- package/server/throttle.ts +11 -1
- package/studio/web/assets/{Chat-CveGbxe6.js → Chat-Bq60AO-g.js} +1 -1
- package/studio/web/assets/{FloatingChat-IpCFgYWL.js → FloatingChat-D4560T0p.js} +3 -3
- package/studio/web/assets/{apiToken-CS8fFTgL.js → apiToken-BEvbFPMc.js} +1 -1
- package/studio/web/assets/{applications-D7F4Jopl.js → applications-CSUVTH4E.js} +1 -1
- package/studio/web/assets/{cssMode-Daw_oLPq.js → cssMode-DJyc9mHj.js} +1 -1
- package/studio/web/assets/{editor-B3Bs1zWX.js → editor-DDIsQfj6.js} +1 -1
- package/studio/web/assets/{html-CDaQwWiE.js → html-g1BJHxLy.js} +1 -1
- package/studio/web/assets/{htmlMode-Cb6emO4U.js → htmlMode-Vh5IglCQ.js} +1 -1
- package/studio/web/assets/{index-B4g2Fu_2.js → index-DGRAzvO4.js} +5 -5
- package/studio/web/assets/{index.lazy-NwhvF1q1.js → index.lazy-vgSic7et.js} +1 -1
- package/studio/web/assets/{javascript-2_86gB9Q.js → javascript-5VIolqf7.js} +1 -1
- package/studio/web/assets/{jsonMode-DX-i86uQ.js → jsonMode-DG4zQraI.js} +1 -1
- package/studio/web/assets/{languageServices-B85WN-Ej.js → languageServices-t5FBpX-i.js} +1 -1
- package/studio/web/assets/{lspLanguageFeatures-JCWHIsKg.js → lspLanguageFeatures-DgVnNPh-.js} +1 -1
- package/studio/web/assets/{notifications-D9ejzt52.js → notifications-BeWcX04m.js} +1 -1
- package/studio/web/assets/{notifications-B7hjKhai.js → notifications-DUGWrWoO.js} +1 -1
- package/studio/web/assets/{profile-D8B6No3F.js → profile-BvUEDBzW.js} +1 -1
- package/studio/web/assets/{regions-DFazIfTK.js → regions-CB-_2m7M.js} +1 -1
- package/studio/web/assets/{register-CwFLviLF.js → register-1w1Zr3b2.js} +2 -2
- package/studio/web/assets/{setComponentFile-VnJ80SSJ.js → setComponentFile-z4-qJCbA.js} +1 -1
- package/studio/web/assets/{setup-BYQxFy-C.js → setup-CS50uJ4x.js} +2 -2
- package/studio/web/assets/{status-Cn5XjmsL.js → status-CI0wOdOE.js} +1 -1
- package/studio/web/assets/{toggleHighContrast-g9xIh6TX.js → toggleHighContrast-BsAE4jPe.js} +1 -1
- package/studio/web/assets/{tsMode-EC-n0Wqc.js → tsMode-D83Gg3cq.js} +1 -1
- package/studio/web/assets/{typescript-DHmM9JCO.js → typescript-Dfp-GrNq.js} +1 -1
- package/studio/web/assets/{useEntityRestURL-BUdnVSVv.js → useEntityRestURL-BKetlINf.js} +1 -1
- package/studio/web/assets/{workers-BVl9bBB-.js → workers-CCvmDLH3.js} +1 -1
- package/studio/web/assets/{xml-C4_sqOkX.js → xml-06pZp00U.js} +1 -1
- package/studio/web/assets/{yaml-CVkbDqtW.js → yaml-iSnWMVlV.js} +1 -1
- package/studio/web/index.html +1 -1
- package/upgrade/directives/5-3-0.ts +61 -54
- package/utility/DESIGN.md +5 -1
- package/utility/errors/hdbError.ts +56 -8
- package/utility/fsync.ts +16 -0
- package/utility/hdbTerms.ts +3 -0
- package/utility/signalling.ts +33 -4
- package/utility/when.ts +22 -0
- package/validation/configValidator.ts +36 -7
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DecisionContractError = exports.DecisionInputError = exports.DecisionSchemaError = exports.MAX_SCHEMA_VALUES = exports.MAX_OBJECT_FIELDS = exports.MAX_LEAF_VALUES = void 0;
|
|
4
|
+
exports.isObjectSchema = isObjectSchema;
|
|
5
|
+
exports.validateDecisionSchema = validateDecisionSchema;
|
|
6
|
+
exports.allowedValues = allowedValues;
|
|
7
|
+
exports.isAllowedValue = isAllowedValue;
|
|
8
|
+
exports.wantsNoMatch = wantsNoMatch;
|
|
9
|
+
exports.stateToText = stateToText;
|
|
10
|
+
exports.normalizeDecision = normalizeDecision;
|
|
11
|
+
exports.toResponseSchema = toResponseSchema;
|
|
12
|
+
exports.parseDecisionSample = parseDecisionSample;
|
|
13
|
+
exports.canonicalJson = canonicalJson;
|
|
14
|
+
exports.hashSchema = hashSchema;
|
|
15
|
+
exports.scoringSchema = scoringSchema;
|
|
16
|
+
exports.snapshotSchema = snapshotSchema;
|
|
17
|
+
exports.hashText = hashText;
|
|
18
|
+
const node_crypto_1 = require("node:crypto");
|
|
19
|
+
const hdbError_ts_1 = require("../../utility/errors/hdbError.js");
|
|
20
|
+
exports.MAX_LEAF_VALUES = 255;
|
|
21
|
+
exports.MAX_OBJECT_FIELDS = 32;
|
|
22
|
+
/** Aggregate allowed values across an object schema; also the ceiling strict structured-output providers place on enum values per request. */
|
|
23
|
+
exports.MAX_SCHEMA_VALUES = 500;
|
|
24
|
+
const PROBABILITY_SUM_TOLERANCE = 1e-3;
|
|
25
|
+
const UNSAFE_FIELD_NAMES = new Set(['__proto__', 'constructor', 'prototype']);
|
|
26
|
+
const BOOLEAN_VALUES = Object.freeze([false, true]);
|
|
27
|
+
function isObjectSchema(schema) {
|
|
28
|
+
return schema.type === 'object';
|
|
29
|
+
}
|
|
30
|
+
class DecisionSchemaError extends hdbError_ts_1.ClientError {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(`Invalid decision schema: ${message}`, 400);
|
|
33
|
+
this.name = 'DecisionSchemaError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DecisionSchemaError = DecisionSchemaError;
|
|
37
|
+
class DecisionInputError extends hdbError_ts_1.ClientError {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(`Invalid decision input: ${message}`, 400);
|
|
40
|
+
this.name = 'DecisionInputError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.DecisionInputError = DecisionInputError;
|
|
44
|
+
/** A backend's output violated the decision contract. A backend error: the facade records it and tries the next candidate. */
|
|
45
|
+
class DecisionContractError extends hdbError_ts_1.ServerError {
|
|
46
|
+
constructor(backendName, message) {
|
|
47
|
+
super(`Backend '${backendName}' returned an invalid decision: ${message}`);
|
|
48
|
+
this.name = 'DecisionContractError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.DecisionContractError = DecisionContractError;
|
|
52
|
+
function validateDecisionSchema(schema) {
|
|
53
|
+
if (!schema || typeof schema !== 'object' || Array.isArray(schema))
|
|
54
|
+
throw new DecisionSchemaError('schema must be an object');
|
|
55
|
+
const candidate = schema;
|
|
56
|
+
if (candidate.type === 'object') {
|
|
57
|
+
const properties = candidate.properties;
|
|
58
|
+
if (!properties || typeof properties !== 'object' || Array.isArray(properties))
|
|
59
|
+
throw new DecisionSchemaError('an object schema needs a properties map');
|
|
60
|
+
if (candidate.description !== undefined && typeof candidate.description !== 'string')
|
|
61
|
+
throw new DecisionSchemaError('description must be a string');
|
|
62
|
+
if (candidate.noMatch !== undefined)
|
|
63
|
+
throw new DecisionSchemaError('noMatch belongs on a property, not on an object schema');
|
|
64
|
+
const names = Object.keys(properties);
|
|
65
|
+
if (names.length === 0)
|
|
66
|
+
throw new DecisionSchemaError('an object schema needs at least one property');
|
|
67
|
+
if (names.length > exports.MAX_OBJECT_FIELDS)
|
|
68
|
+
throw new DecisionSchemaError(`an object schema has at most ${exports.MAX_OBJECT_FIELDS} properties, got ${names.length}`);
|
|
69
|
+
let total = 0;
|
|
70
|
+
for (const name of names) {
|
|
71
|
+
if (name.length === 0 || UNSAFE_FIELD_NAMES.has(name))
|
|
72
|
+
throw new DecisionSchemaError(`property name '${name}' is not allowed`);
|
|
73
|
+
total += validateLeaf(properties[name], `property '${name}'`);
|
|
74
|
+
}
|
|
75
|
+
if (total > exports.MAX_SCHEMA_VALUES)
|
|
76
|
+
throw new DecisionSchemaError(`an object schema spans at most ${exports.MAX_SCHEMA_VALUES} values across its properties, got ${total}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
validateLeaf(schema, 'schema');
|
|
80
|
+
}
|
|
81
|
+
function validateLeaf(leaf, label) {
|
|
82
|
+
if (!leaf || typeof leaf !== 'object' || Array.isArray(leaf))
|
|
83
|
+
throw new DecisionSchemaError(`${label} must be an object`);
|
|
84
|
+
const candidate = leaf;
|
|
85
|
+
if (candidate.description !== undefined && typeof candidate.description !== 'string')
|
|
86
|
+
throw new DecisionSchemaError(`${label}: description must be a string`);
|
|
87
|
+
if (candidate.noMatch !== undefined && typeof candidate.noMatch !== 'boolean')
|
|
88
|
+
throw new DecisionSchemaError(`${label}: noMatch must be a boolean`);
|
|
89
|
+
if (Array.isArray(candidate.enum)) {
|
|
90
|
+
if (candidate.enum.length < 2 || candidate.enum.length > exports.MAX_LEAF_VALUES)
|
|
91
|
+
throw new DecisionSchemaError(`${label}: enum needs 2..${exports.MAX_LEAF_VALUES} values, got ${candidate.enum.length}`);
|
|
92
|
+
const type = typeof candidate.enum[0];
|
|
93
|
+
if (type !== 'string' && type !== 'number' && type !== 'boolean')
|
|
94
|
+
throw new DecisionSchemaError(`${label}: enum values must be strings, finite numbers or booleans`);
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
for (const value of candidate.enum) {
|
|
97
|
+
if (typeof value !== type)
|
|
98
|
+
throw new DecisionSchemaError(`${label}: enum values must all be of one type (strings, numbers or booleans)`);
|
|
99
|
+
if (type === 'number' && !Number.isFinite(value))
|
|
100
|
+
throw new DecisionSchemaError(`${label}: enum values must be strings, finite numbers or booleans`);
|
|
101
|
+
if (seen.has(value))
|
|
102
|
+
throw new DecisionSchemaError(`${label}: enum values must be distinct`);
|
|
103
|
+
seen.add(value);
|
|
104
|
+
}
|
|
105
|
+
return candidate.enum.length;
|
|
106
|
+
}
|
|
107
|
+
if (candidate.type === 'boolean')
|
|
108
|
+
return BOOLEAN_VALUES.length;
|
|
109
|
+
if (candidate.type === 'integer') {
|
|
110
|
+
const { minimum, maximum } = candidate;
|
|
111
|
+
// Safe integers only: past 2^53 `value++` no longer advances, so a range could never end.
|
|
112
|
+
if (!Number.isSafeInteger(minimum) || !Number.isSafeInteger(maximum))
|
|
113
|
+
throw new DecisionSchemaError(`${label}: integer minimum and maximum must be safe integers`);
|
|
114
|
+
const span = maximum - minimum + 1;
|
|
115
|
+
if (span < 2 || span > exports.MAX_LEAF_VALUES)
|
|
116
|
+
throw new DecisionSchemaError(`${label}: an integer range spans 2..${exports.MAX_LEAF_VALUES} values, got ${span}`);
|
|
117
|
+
return span;
|
|
118
|
+
}
|
|
119
|
+
throw new DecisionSchemaError(`${label} must be an enum, a boolean, or a bounded integer`);
|
|
120
|
+
}
|
|
121
|
+
function integerRange(minimum, maximum) {
|
|
122
|
+
const span = maximum - minimum + 1;
|
|
123
|
+
const values = new Array(span);
|
|
124
|
+
for (let i = 0; i < span; i++)
|
|
125
|
+
values[i] = minimum + i;
|
|
126
|
+
return values;
|
|
127
|
+
}
|
|
128
|
+
/** In the order ties resolve; assumes a validated leaf. */
|
|
129
|
+
function allowedValues(leaf) {
|
|
130
|
+
if ('enum' in leaf)
|
|
131
|
+
return leaf.enum;
|
|
132
|
+
if (leaf.type === 'boolean')
|
|
133
|
+
return BOOLEAN_VALUES;
|
|
134
|
+
return integerRange(leaf.minimum, leaf.maximum);
|
|
135
|
+
}
|
|
136
|
+
/** Assumes a validated leaf. */
|
|
137
|
+
function isAllowedValue(leaf, raw) {
|
|
138
|
+
if ('enum' in leaf)
|
|
139
|
+
return leaf.enum.includes(raw);
|
|
140
|
+
if (leaf.type === 'boolean')
|
|
141
|
+
return typeof raw === 'boolean';
|
|
142
|
+
return Number.isInteger(raw) && raw >= leaf.minimum && raw <= leaf.maximum;
|
|
143
|
+
}
|
|
144
|
+
function wantsNoMatch(schema) {
|
|
145
|
+
if (!isObjectSchema(schema))
|
|
146
|
+
return schema.noMatch === true;
|
|
147
|
+
for (const name in schema.properties)
|
|
148
|
+
if (Object.hasOwn(schema.properties, name) && schema.properties[name].noMatch === true)
|
|
149
|
+
return true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
/** The text form of a `decide` state, or a `DecisionInputError` for a value no backend could serialize. */
|
|
153
|
+
function stateToText(state) {
|
|
154
|
+
if (typeof state === 'string')
|
|
155
|
+
return state;
|
|
156
|
+
if (!state || typeof state !== 'object')
|
|
157
|
+
throw new DecisionInputError('state must be a string or an object');
|
|
158
|
+
let text;
|
|
159
|
+
try {
|
|
160
|
+
text = JSON.stringify(state);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
throw new DecisionInputError(`state is not JSON-serializable (${err?.message ?? err})`);
|
|
164
|
+
}
|
|
165
|
+
if (typeof text !== 'string')
|
|
166
|
+
throw new DecisionInputError('state is not JSON-serializable');
|
|
167
|
+
return text;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check a backend's output against the schema and shape it for the caller: complete distributions
|
|
171
|
+
* sorted descending (ties keep schema order), the argmax as `value`, per-field marginals for object
|
|
172
|
+
* schemas. `calibrated` falls back to the backend's capability when the output does not say.
|
|
173
|
+
* Messages never echo backend-supplied values, because they can reach an error response.
|
|
174
|
+
*/
|
|
175
|
+
function normalizeDecision(schema, output, backendName, calibratedDefault, calibratedNoMatch = false) {
|
|
176
|
+
if (!output || typeof output !== 'object')
|
|
177
|
+
throw new DecisionContractError(backendName, 'output must be an object');
|
|
178
|
+
const reported = typeof output.calibrated === 'boolean' ? output.calibrated : calibratedDefault;
|
|
179
|
+
const calibrated = reported && (calibratedNoMatch || !wantsNoMatch(schema));
|
|
180
|
+
if (isObjectSchema(schema)) {
|
|
181
|
+
const fields = output.fields;
|
|
182
|
+
if (!fields || typeof fields !== 'object')
|
|
183
|
+
throw new DecisionContractError(backendName, 'an object schema needs a fields map');
|
|
184
|
+
const marginals = {};
|
|
185
|
+
const value = {};
|
|
186
|
+
for (const name of Object.keys(schema.properties)) {
|
|
187
|
+
if (!Object.hasOwn(fields, name))
|
|
188
|
+
throw new DecisionContractError(backendName, `missing field '${name}'`);
|
|
189
|
+
const marginal = normalizeLeaf(schema.properties[name], fields[name], backendName, `field '${name}'`);
|
|
190
|
+
marginals[name] = marginal;
|
|
191
|
+
value[name] = marginal.value;
|
|
192
|
+
}
|
|
193
|
+
for (const name of Object.keys(fields)) {
|
|
194
|
+
if (!Object.hasOwn(schema.properties, name))
|
|
195
|
+
throw new DecisionContractError(backendName, `unexpected field '${name}'`);
|
|
196
|
+
}
|
|
197
|
+
return { value: value, fields: marginals, calibrated };
|
|
198
|
+
}
|
|
199
|
+
const leaf = normalizeLeaf(schema, output, backendName, 'output');
|
|
200
|
+
const decision = {
|
|
201
|
+
value: leaf.value,
|
|
202
|
+
probability: leaf.probability,
|
|
203
|
+
distribution: leaf.distribution,
|
|
204
|
+
calibrated,
|
|
205
|
+
};
|
|
206
|
+
if (leaf.noMatch !== undefined)
|
|
207
|
+
decision.noMatch = leaf.noMatch;
|
|
208
|
+
return decision;
|
|
209
|
+
}
|
|
210
|
+
function normalizeLeaf(leaf, output, backendName, label) {
|
|
211
|
+
const allowed = allowedValues(leaf);
|
|
212
|
+
const distribution = output?.distribution;
|
|
213
|
+
if (!Array.isArray(distribution))
|
|
214
|
+
throw new DecisionContractError(backendName, `${label}: distribution is required`);
|
|
215
|
+
if (distribution.length !== allowed.length)
|
|
216
|
+
throw new DecisionContractError(backendName, `${label}: distribution needs one entry per allowed value (${allowed.length}), got ${distribution.length}`);
|
|
217
|
+
const byValue = new Map();
|
|
218
|
+
let sum = 0;
|
|
219
|
+
for (let i = 0; i < distribution.length; i++) {
|
|
220
|
+
const entry = distribution[i];
|
|
221
|
+
if (!entry || typeof entry !== 'object')
|
|
222
|
+
throw new DecisionContractError(backendName, `${label}: distribution entry ${i} is not an object`);
|
|
223
|
+
const { value, probability } = entry;
|
|
224
|
+
if (!isAllowedValue(leaf, value))
|
|
225
|
+
throw new DecisionContractError(backendName, `${label}: distribution entry ${i} is not an allowed value`);
|
|
226
|
+
if (typeof probability !== 'number' || !Number.isFinite(probability) || probability < 0 || probability > 1)
|
|
227
|
+
throw new DecisionContractError(backendName, `${label}: the probability of distribution entry ${i} must be a finite number in [0, 1]`);
|
|
228
|
+
if (byValue.has(value))
|
|
229
|
+
throw new DecisionContractError(backendName, `${label}: distribution entry ${i} duplicates an earlier entry`);
|
|
230
|
+
byValue.set(value, probability);
|
|
231
|
+
sum += probability;
|
|
232
|
+
}
|
|
233
|
+
if (Math.abs(sum - 1) > PROBABILITY_SUM_TOLERANCE)
|
|
234
|
+
throw new DecisionContractError(backendName, `${label}: probabilities sum to ${sum}, expected 1`);
|
|
235
|
+
const sorted = allowed.map((value) => ({ value, probability: byValue.get(value) }));
|
|
236
|
+
sorted.sort((a, b) => b.probability - a.probability);
|
|
237
|
+
const top = sorted[0].probability;
|
|
238
|
+
const chosen = output.value;
|
|
239
|
+
if (chosen !== undefined && chosen !== sorted[0].value) {
|
|
240
|
+
if (byValue.get(chosen) !== top)
|
|
241
|
+
throw new DecisionContractError(backendName, `${label}: value is not a most-probable outcome`);
|
|
242
|
+
const index = sorted.findIndex((entry) => entry.value === chosen);
|
|
243
|
+
sorted.unshift(...sorted.splice(index, 1));
|
|
244
|
+
}
|
|
245
|
+
const marginal = { value: sorted[0].value, probability: top, distribution: sorted };
|
|
246
|
+
if (leaf.noMatch === true) {
|
|
247
|
+
const score = output.noMatch;
|
|
248
|
+
if (typeof score !== 'number' || !Number.isFinite(score) || score < 0 || score > 1)
|
|
249
|
+
throw new DecisionContractError(backendName, `${label}: noMatch must be a finite number in [0, 1]`);
|
|
250
|
+
marginal.noMatch = score;
|
|
251
|
+
}
|
|
252
|
+
return marginal;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The JSON Schema a generative backend is asked to honor for one sample: an object at the root
|
|
256
|
+
* (leaf answers wrapped as `{ value }`), every property required, no additional properties, and
|
|
257
|
+
* bounded integers as an explicit enum — the shape strict structured-output modes accept.
|
|
258
|
+
*/
|
|
259
|
+
function toResponseSchema(schema) {
|
|
260
|
+
if (isObjectSchema(schema)) {
|
|
261
|
+
const properties = {};
|
|
262
|
+
for (const [name, leaf] of Object.entries(schema.properties))
|
|
263
|
+
properties[name] = leaf.noMatch === true ? pairJsonSchema(leafJsonSchema(leaf)) : leafJsonSchema(leaf);
|
|
264
|
+
const out = {
|
|
265
|
+
type: 'object',
|
|
266
|
+
properties,
|
|
267
|
+
required: Object.keys(schema.properties),
|
|
268
|
+
additionalProperties: false,
|
|
269
|
+
};
|
|
270
|
+
if (schema.description)
|
|
271
|
+
out.description = schema.description;
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
if (schema.noMatch === true)
|
|
275
|
+
return pairJsonSchema(leafJsonSchema(schema));
|
|
276
|
+
return {
|
|
277
|
+
type: 'object',
|
|
278
|
+
properties: { value: leafJsonSchema(schema) },
|
|
279
|
+
required: ['value'],
|
|
280
|
+
additionalProperties: false,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function pairJsonSchema(value) {
|
|
284
|
+
return {
|
|
285
|
+
type: 'object',
|
|
286
|
+
properties: { value, noMatch: { type: 'boolean' } },
|
|
287
|
+
required: ['value', 'noMatch'],
|
|
288
|
+
additionalProperties: false,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function leafJsonSchema(leaf) {
|
|
292
|
+
const out = {};
|
|
293
|
+
if ('enum' in leaf) {
|
|
294
|
+
out.type = typeof leaf.enum[0];
|
|
295
|
+
out.enum = [...leaf.enum];
|
|
296
|
+
}
|
|
297
|
+
else if (leaf.type === 'boolean') {
|
|
298
|
+
out.type = 'boolean';
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
out.type = 'integer';
|
|
302
|
+
out.enum = integerRange(leaf.minimum, leaf.maximum);
|
|
303
|
+
}
|
|
304
|
+
if (leaf.description)
|
|
305
|
+
out.description = leaf.description;
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Parse one generative sample against the schema: the leaf value, or a `{ [property]: value }`
|
|
310
|
+
* map for object schemas. Throws a plain `Error` naming what did not fit, never quoting the
|
|
311
|
+
* sample itself; the caller wraps it.
|
|
312
|
+
*/
|
|
313
|
+
function parseDecisionSample(schema, content) {
|
|
314
|
+
if (typeof content !== 'string')
|
|
315
|
+
throw new Error('the sample has no text');
|
|
316
|
+
let answer;
|
|
317
|
+
let answerKey;
|
|
318
|
+
let lastError;
|
|
319
|
+
for (const candidate of jsonObjectSpans(content)) {
|
|
320
|
+
let values;
|
|
321
|
+
try {
|
|
322
|
+
values = extractSampleValues(schema, candidate);
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
lastError = err;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const key = JSON.stringify(values);
|
|
329
|
+
if (answerKey === undefined) {
|
|
330
|
+
answer = values;
|
|
331
|
+
answerKey = key;
|
|
332
|
+
}
|
|
333
|
+
else if (key !== answerKey) {
|
|
334
|
+
throw new Error('the sample contains more than one answer');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (answerKey !== undefined)
|
|
338
|
+
return answer;
|
|
339
|
+
throw lastError ?? new Error('the sample contains no JSON object');
|
|
340
|
+
}
|
|
341
|
+
function extractSampleValues(schema, sample) {
|
|
342
|
+
if (isObjectSchema(schema)) {
|
|
343
|
+
const values = {};
|
|
344
|
+
for (const [name, leaf] of Object.entries(schema.properties)) {
|
|
345
|
+
if (!Object.hasOwn(sample, name))
|
|
346
|
+
throw new Error(`the sample has no '${name}'`);
|
|
347
|
+
values[name] =
|
|
348
|
+
leaf.noMatch === true
|
|
349
|
+
? checkSamplePair(leaf, sample[name], `'${name}'`)
|
|
350
|
+
: checkSampleValue(leaf, sample[name], `'${name}'`);
|
|
351
|
+
}
|
|
352
|
+
return values;
|
|
353
|
+
}
|
|
354
|
+
if (schema.noMatch === true)
|
|
355
|
+
return checkSamplePair(schema, sample, 'the sample');
|
|
356
|
+
return checkSampleValue(schema, sample.value, "'value'");
|
|
357
|
+
}
|
|
358
|
+
function checkSamplePair(leaf, raw, label) {
|
|
359
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
360
|
+
throw new Error(`${label} needs { value, noMatch }`);
|
|
361
|
+
const pair = raw;
|
|
362
|
+
if (typeof pair.noMatch !== 'boolean')
|
|
363
|
+
throw new Error(`${label} has no boolean noMatch`);
|
|
364
|
+
return { value: checkSampleValue(leaf, pair.value, `${label} value`), noMatch: pair.noMatch };
|
|
365
|
+
}
|
|
366
|
+
const MAX_OBJECT_SPANS = 64;
|
|
367
|
+
const MAX_SCAN_STEPS_PER_CHAR = 256;
|
|
368
|
+
/**
|
|
369
|
+
* Every balanced `{`…`}` span that parses to a JSON object. A backend that ignores
|
|
370
|
+
* `responseFormat` (Anthropic, Bedrock) answers from the prompt alone and may wrap the object in
|
|
371
|
+
* code fences or prose with braces and stray quotes of its own; the schema check on each candidate
|
|
372
|
+
* is what tells the answer from the rest, so no span is preferred over another. String tracking
|
|
373
|
+
* starts at each opening brace, so quotes in the prose before an object cannot hide it, while
|
|
374
|
+
* braces inside the object's own strings are text and are never tried as starts once that object
|
|
375
|
+
* has parsed. Those string ranges are recorded once, from the outermost object that parses, so
|
|
376
|
+
* they stay in text order and the skip is one forward pass over them. The scan fails loudly, never
|
|
377
|
+
* partially: past `MAX_OBJECT_SPANS` balanced spans, or once the character steps exceed
|
|
378
|
+
* `MAX_SCAN_STEPS_PER_CHAR` times the reply's length.
|
|
379
|
+
*/
|
|
380
|
+
function* jsonObjectSpans(text) {
|
|
381
|
+
const work = { left: MAX_SCAN_STEPS_PER_CHAR * text.length };
|
|
382
|
+
const stringRanges = [];
|
|
383
|
+
let range = 0;
|
|
384
|
+
let recordedEnd = -1;
|
|
385
|
+
let spans = 0;
|
|
386
|
+
for (let start = text.indexOf('{'); start >= 0; start = text.indexOf('{', start + 1)) {
|
|
387
|
+
while (range < stringRanges.length && stringRanges[range][1] < start)
|
|
388
|
+
range++;
|
|
389
|
+
if (range < stringRanges.length && stringRanges[range][0] < start)
|
|
390
|
+
continue;
|
|
391
|
+
const strings = [];
|
|
392
|
+
const end = balancedClose(text, start, work, strings);
|
|
393
|
+
if (end < 0)
|
|
394
|
+
continue;
|
|
395
|
+
if (++spans > MAX_OBJECT_SPANS)
|
|
396
|
+
throw new Error('the sample has too many objects');
|
|
397
|
+
let parsed;
|
|
398
|
+
try {
|
|
399
|
+
parsed = JSON.parse(text.slice(start, end + 1));
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (start > recordedEnd) {
|
|
405
|
+
stringRanges.push(...strings);
|
|
406
|
+
recordedEnd = end;
|
|
407
|
+
}
|
|
408
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
409
|
+
yield parsed;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Index of the `}` that balances the `{` at `start`, reading JSON strings as text, or -1. The
|
|
414
|
+
* `[from, to]` index range of every string read on the way is appended to `strings`.
|
|
415
|
+
*/
|
|
416
|
+
function balancedClose(text, start, work, strings) {
|
|
417
|
+
let depth = 0;
|
|
418
|
+
let stringStart = -1;
|
|
419
|
+
let escaped = false;
|
|
420
|
+
for (let i = start; i < text.length; i++) {
|
|
421
|
+
if (--work.left < 0)
|
|
422
|
+
throw new Error('the sample is too long to scan');
|
|
423
|
+
const ch = text[i];
|
|
424
|
+
if (stringStart >= 0) {
|
|
425
|
+
if (escaped)
|
|
426
|
+
escaped = false;
|
|
427
|
+
else if (ch === '\\')
|
|
428
|
+
escaped = true;
|
|
429
|
+
else if (ch === '"') {
|
|
430
|
+
strings.push([stringStart, i]);
|
|
431
|
+
stringStart = -1;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else if (ch === '"')
|
|
435
|
+
stringStart = i;
|
|
436
|
+
else if (ch === '{')
|
|
437
|
+
depth++;
|
|
438
|
+
else if (ch === '}' && --depth === 0)
|
|
439
|
+
return i;
|
|
440
|
+
}
|
|
441
|
+
return -1;
|
|
442
|
+
}
|
|
443
|
+
function checkSampleValue(leaf, raw, label) {
|
|
444
|
+
if (isAllowedValue(leaf, raw))
|
|
445
|
+
return raw;
|
|
446
|
+
throw new Error(`${label} is not an allowed value`);
|
|
447
|
+
}
|
|
448
|
+
/** JSON with object keys sorted at every level; array order is kept because enum order is meaning. */
|
|
449
|
+
function canonicalJson(value) {
|
|
450
|
+
return JSON.stringify(sortKeys(value));
|
|
451
|
+
}
|
|
452
|
+
function sortKeys(value) {
|
|
453
|
+
if (Array.isArray(value))
|
|
454
|
+
return value.map(sortKeys);
|
|
455
|
+
if (!value || typeof value !== 'object')
|
|
456
|
+
return value;
|
|
457
|
+
const sorted = {};
|
|
458
|
+
for (const key of Object.keys(value).sort())
|
|
459
|
+
sorted[key] = sortKeys(value[key]);
|
|
460
|
+
return sorted;
|
|
461
|
+
}
|
|
462
|
+
/** Identity of the schema as the model saw it: the allowed values and the descriptions, nothing else. */
|
|
463
|
+
function hashSchema(schema) {
|
|
464
|
+
return (0, node_crypto_1.createHash)('sha256')
|
|
465
|
+
.update(canonicalJson(knownSchema(schema, true)))
|
|
466
|
+
.digest('hex');
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The allowed values alone, for validating outcomes against. Descriptions are hashed, never stored,
|
|
470
|
+
* because they are free text that can carry request data; unknown keys are dropped from both.
|
|
471
|
+
*/
|
|
472
|
+
function scoringSchema(schema) {
|
|
473
|
+
return knownSchema(schema, false);
|
|
474
|
+
}
|
|
475
|
+
/** A copy of a validated schema with only its known keys, so a call and its record see one schema whatever the caller mutates afterwards. */
|
|
476
|
+
function snapshotSchema(schema) {
|
|
477
|
+
return knownSchema(schema, true);
|
|
478
|
+
}
|
|
479
|
+
/** sha256 of a caller's per-call text, so decisions made under different instructions do not share an identity. */
|
|
480
|
+
function hashText(text) {
|
|
481
|
+
return (0, node_crypto_1.createHash)('sha256').update(text).digest('hex');
|
|
482
|
+
}
|
|
483
|
+
function knownSchema(schema, withDescriptions) {
|
|
484
|
+
if (isObjectSchema(schema)) {
|
|
485
|
+
const properties = {};
|
|
486
|
+
for (const [name, leaf] of Object.entries(schema.properties))
|
|
487
|
+
properties[name] = knownLeaf(leaf, withDescriptions);
|
|
488
|
+
const known = { type: 'object', properties };
|
|
489
|
+
if (withDescriptions && schema.description !== undefined)
|
|
490
|
+
known.description = schema.description;
|
|
491
|
+
return known;
|
|
492
|
+
}
|
|
493
|
+
return knownLeaf(schema, withDescriptions);
|
|
494
|
+
}
|
|
495
|
+
function knownLeaf(leaf, withDescriptions) {
|
|
496
|
+
const known = 'enum' in leaf
|
|
497
|
+
? { enum: Array.from(leaf.enum) }
|
|
498
|
+
: leaf.type === 'boolean'
|
|
499
|
+
? { type: 'boolean' }
|
|
500
|
+
: { type: 'integer', minimum: leaf.minimum, maximum: leaf.maximum };
|
|
501
|
+
if (leaf.noMatch === true)
|
|
502
|
+
known.noMatch = true;
|
|
503
|
+
if (withDescriptions && leaf.description !== undefined)
|
|
504
|
+
known.description = leaf.description;
|
|
505
|
+
return known;
|
|
506
|
+
}
|
|
507
|
+
//# sourceMappingURL=decision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../../resources/models/decision.ts"],"names":[],"mappings":";;;AAsBA,wCAEC;AAwBD,wDA+BC;AAiDD,sCAIC;AAGD,wCAIC;AAED,oCAKC;AAGD,kCAWC;AAQD,8CAqCC;AA8DD,4CAqBC;AA+BD,kDAuBC;AAuGD,sCAEC;AAYD,gCAIC;AAMD,sCAEC;AAGD,wCAEC;AAGD,4BAEC;AAjeD,6CAAyC;AACzC,kEAA4E;AAW/D,QAAA,eAAe,GAAG,GAAG,CAAC;AACtB,QAAA,iBAAiB,GAAG,EAAE,CAAC;AACpC,8IAA8I;AACjI,QAAA,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AACvC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAC9E,MAAM,cAAc,GAAuB,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAIxE,SAAgB,cAAc,CAAC,MAAsB;IACpD,OAAQ,MAA6B,CAAC,IAAI,KAAK,QAAQ,CAAC;AACzD,CAAC;AAED,MAAa,mBAAoB,SAAQ,yBAAW;IACnD,YAAY,OAAe;QAC1B,KAAK,CAAC,4BAA4B,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACnC,CAAC;CACD;AALD,kDAKC;AAED,MAAa,kBAAmB,SAAQ,yBAAW;IAClD,YAAY,OAAe;QAC1B,KAAK,CAAC,2BAA2B,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAClC,CAAC;CACD;AALD,gDAKC;AAED,8HAA8H;AAC9H,MAAa,qBAAs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S,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QACnH,MAAM,KAAK,GAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;QACtE,IAAI,gBAAgB,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS;YAAE,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACjG,OAAO,KAAuB,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,SAAS,CAAC,IAAkB,EAAE,gBAAyB;IAC/D,MAAM,KAAK,GACV,MAAM,IAAI,IAAI;QACb,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAA0B,CAAC,EAAE;QACvD,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;YACxB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YACrB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACvE,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;QAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IAChD,IAAI,gBAAgB,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS;QAAE,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IAC7F,OAAO,KAAqB,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ClientError, ServerError } from '../../utility/errors/hdbError.ts';
|
|
2
|
+
import type { DecisionRecord, DecisionSchema, OutcomeReport } from './types.ts';
|
|
3
|
+
export declare const DECISIONS_TABLE = "hdb_model_decisions";
|
|
4
|
+
export declare const OUTCOMES_TABLE = "hdb_model_outcomes";
|
|
5
|
+
/** Facts copy the decision's instant, so a report never extends a decision's life. */
|
|
6
|
+
export declare const DECISION_RETENTION_MS: number;
|
|
7
|
+
/** A `hdb_model_decisions` row: written once by `models.decide`, never rewritten. */
|
|
8
|
+
export interface DecisionRow {
|
|
9
|
+
id: string;
|
|
10
|
+
callId: number;
|
|
11
|
+
at: number;
|
|
12
|
+
expiresAt: number;
|
|
13
|
+
tenant?: string;
|
|
14
|
+
app?: string;
|
|
15
|
+
backend: string;
|
|
16
|
+
model: string;
|
|
17
|
+
signature?: string;
|
|
18
|
+
configHash?: string;
|
|
19
|
+
instructionsHash?: string;
|
|
20
|
+
schema: DecisionSchema;
|
|
21
|
+
schemaHash: string;
|
|
22
|
+
value: unknown;
|
|
23
|
+
probability?: number;
|
|
24
|
+
distribution?: DecisionRecord['distribution'];
|
|
25
|
+
fields?: DecisionRecord['fields'];
|
|
26
|
+
noMatch?: number;
|
|
27
|
+
calibrated: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The catalog stub (`systemSchema.json` and the upgrade directive) declares only the primary key;
|
|
31
|
+
* these declarations add the attributes and the indexed `expiresAt` TTL. Writes go through the
|
|
32
|
+
* Resource API, which maintains the index, so `indexed` holds here, unlike in `hdb_model_calls`.
|
|
33
|
+
*/
|
|
34
|
+
export declare const DECISION_ATTRIBUTES: ({
|
|
35
|
+
name: string;
|
|
36
|
+
isPrimaryKey: boolean;
|
|
37
|
+
type?: undefined;
|
|
38
|
+
expiresAt?: undefined;
|
|
39
|
+
indexed?: undefined;
|
|
40
|
+
} | {
|
|
41
|
+
name: string;
|
|
42
|
+
type: string;
|
|
43
|
+
isPrimaryKey?: undefined;
|
|
44
|
+
expiresAt?: undefined;
|
|
45
|
+
indexed?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
name: string;
|
|
48
|
+
expiresAt: boolean;
|
|
49
|
+
indexed: boolean;
|
|
50
|
+
isPrimaryKey?: undefined;
|
|
51
|
+
type?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
name: string;
|
|
54
|
+
isPrimaryKey?: undefined;
|
|
55
|
+
type?: undefined;
|
|
56
|
+
expiresAt?: undefined;
|
|
57
|
+
indexed?: undefined;
|
|
58
|
+
})[];
|
|
59
|
+
export declare const OUTCOME_ATTRIBUTES: ({
|
|
60
|
+
name: string;
|
|
61
|
+
isPrimaryKey: boolean;
|
|
62
|
+
type?: undefined;
|
|
63
|
+
expiresAt?: undefined;
|
|
64
|
+
indexed?: undefined;
|
|
65
|
+
} | {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
isPrimaryKey?: undefined;
|
|
69
|
+
expiresAt?: undefined;
|
|
70
|
+
indexed?: undefined;
|
|
71
|
+
} | {
|
|
72
|
+
name: string;
|
|
73
|
+
isPrimaryKey?: undefined;
|
|
74
|
+
type?: undefined;
|
|
75
|
+
expiresAt?: undefined;
|
|
76
|
+
indexed?: undefined;
|
|
77
|
+
} | {
|
|
78
|
+
name: string;
|
|
79
|
+
expiresAt: boolean;
|
|
80
|
+
indexed: boolean;
|
|
81
|
+
isPrimaryKey?: undefined;
|
|
82
|
+
type?: undefined;
|
|
83
|
+
})[];
|
|
84
|
+
export interface DecisionTables {
|
|
85
|
+
decisions: any;
|
|
86
|
+
outcomes: any;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Declares both tables and memoizes the handles. A read-only node cannot write the catalog, so it
|
|
90
|
+
* takes whatever the catalog already holds and declares nothing; a table not there yet reads as empty.
|
|
91
|
+
*/
|
|
92
|
+
export declare function getDecisionTables(readOnly?: boolean): DecisionTables;
|
|
93
|
+
export declare function resetDecisionTables(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Declared at boot on every writable node so the TTL index exists where decisions are never made.
|
|
96
|
+
* A failure is logged, not thrown: the first `decide` declares again and reports its own error.
|
|
97
|
+
*/
|
|
98
|
+
export declare function declareDecisionTablesAtBoot(): void;
|
|
99
|
+
export declare class DecisionNotFoundError extends ClientError {
|
|
100
|
+
constructor(id: string);
|
|
101
|
+
}
|
|
102
|
+
export declare class OutcomeReportError extends ClientError {
|
|
103
|
+
constructor(message: string);
|
|
104
|
+
}
|
|
105
|
+
export declare class DecisionPersistenceError extends ServerError {
|
|
106
|
+
constructor(message: string, statusCode?: number);
|
|
107
|
+
}
|
|
108
|
+
export interface DecisionStoreOpts {
|
|
109
|
+
getTables?: () => DecisionTables;
|
|
110
|
+
isReadOnly?: () => boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Durable decisions and their recorded facts. Every operation runs in a transaction of its own
|
|
114
|
+
* (`transaction` with a context object that is not the ALS store), so a decision made inside an
|
|
115
|
+
* application transaction survives that transaction's abort, and the commit is awaited before the
|
|
116
|
+
* id is returned to the caller.
|
|
117
|
+
*/
|
|
118
|
+
export declare class DecisionStore {
|
|
119
|
+
#private;
|
|
120
|
+
constructor(opts?: DecisionStoreOpts);
|
|
121
|
+
assertWritable(what: 'Decisions' | 'Outcomes'): void;
|
|
122
|
+
persist(row: DecisionRow): Promise<void>;
|
|
123
|
+
get(id: string, tenant?: string): Promise<DecisionRecord | undefined>;
|
|
124
|
+
recordOutcome(id: string, report: OutcomeReport, tenant?: string): Promise<DecisionRecord>;
|
|
125
|
+
}
|
|
126
|
+
export declare function getDecisionStore(): DecisionStore;
|
|
127
|
+
export declare function newDecisionId(): string;
|
|
128
|
+
/**
|
|
129
|
+
* Identity of the model configuration actually installed, recorded on each decision so a reload
|
|
130
|
+
* that changes the model behind an unchanged logical name still separates the decisions it produced.
|
|
131
|
+
* Credential-looking keys are dropped before hashing.
|
|
132
|
+
*/
|
|
133
|
+
export declare function setModelsConfigHash(installed: unknown): void;
|
|
134
|
+
export declare function getModelsConfigHash(): string | undefined;
|