@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,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DecisionStore = exports.DecisionPersistenceError = exports.OutcomeReportError = exports.DecisionNotFoundError = exports.OUTCOME_ATTRIBUTES = exports.DECISION_ATTRIBUTES = exports.DECISION_RETENTION_MS = exports.OUTCOMES_TABLE = exports.DECISIONS_TABLE = void 0;
|
|
7
|
+
exports.getDecisionTables = getDecisionTables;
|
|
8
|
+
exports.resetDecisionTables = resetDecisionTables;
|
|
9
|
+
exports.declareDecisionTablesAtBoot = declareDecisionTablesAtBoot;
|
|
10
|
+
exports.getDecisionStore = getDecisionStore;
|
|
11
|
+
exports.newDecisionId = newDecisionId;
|
|
12
|
+
exports.setModelsConfigHash = setModelsConfigHash;
|
|
13
|
+
exports.getModelsConfigHash = getModelsConfigHash;
|
|
14
|
+
const node_crypto_1 = require("node:crypto");
|
|
15
|
+
const databases_ts_1 = require("../databases.js");
|
|
16
|
+
const transaction_ts_1 = require("../transaction.js");
|
|
17
|
+
const hdbError_ts_1 = require("../../utility/errors/hdbError.js");
|
|
18
|
+
const harper_logger_ts_1 = __importDefault(require("../../utility/logging/harper_logger.js"));
|
|
19
|
+
const decision_ts_1 = require("./decision.js");
|
|
20
|
+
const log = harper_logger_ts_1.default.forComponent('models').conditional;
|
|
21
|
+
exports.DECISIONS_TABLE = 'hdb_model_decisions';
|
|
22
|
+
exports.OUTCOMES_TABLE = 'hdb_model_outcomes';
|
|
23
|
+
/** Facts copy the decision's instant, so a report never extends a decision's life. */
|
|
24
|
+
exports.DECISION_RETENTION_MS = 365 * 24 * 60 * 60 * 1000;
|
|
25
|
+
/**
|
|
26
|
+
* The catalog stub (`systemSchema.json` and the upgrade directive) declares only the primary key;
|
|
27
|
+
* these declarations add the attributes and the indexed `expiresAt` TTL. Writes go through the
|
|
28
|
+
* Resource API, which maintains the index, so `indexed` holds here, unlike in `hdb_model_calls`.
|
|
29
|
+
*/
|
|
30
|
+
exports.DECISION_ATTRIBUTES = [
|
|
31
|
+
{ name: 'id', isPrimaryKey: true },
|
|
32
|
+
{ name: 'callId', type: 'number' },
|
|
33
|
+
{ name: 'at', type: 'number' },
|
|
34
|
+
{ name: 'expiresAt', expiresAt: true, indexed: true },
|
|
35
|
+
{ name: 'tenant', type: 'string' },
|
|
36
|
+
{ name: 'app', type: 'string' },
|
|
37
|
+
{ name: 'backend', type: 'string' },
|
|
38
|
+
{ name: 'model', type: 'string' },
|
|
39
|
+
{ name: 'signature', type: 'string' },
|
|
40
|
+
{ name: 'configHash', type: 'string' },
|
|
41
|
+
{ name: 'instructionsHash', type: 'string' },
|
|
42
|
+
{ name: 'schema' },
|
|
43
|
+
{ name: 'schemaHash', type: 'string' },
|
|
44
|
+
{ name: 'value' },
|
|
45
|
+
{ name: 'probability', type: 'number' },
|
|
46
|
+
{ name: 'distribution' },
|
|
47
|
+
{ name: 'fields' },
|
|
48
|
+
{ name: 'noMatch', type: 'number' },
|
|
49
|
+
{ name: 'calibrated', type: 'boolean' },
|
|
50
|
+
];
|
|
51
|
+
exports.OUTCOME_ATTRIBUTES = [
|
|
52
|
+
{ name: 'id', isPrimaryKey: true },
|
|
53
|
+
{ name: 'decisionId', type: 'string' },
|
|
54
|
+
{ name: 'fact', type: 'string' },
|
|
55
|
+
{ name: 'field', type: 'string' },
|
|
56
|
+
{ name: 'state' },
|
|
57
|
+
{ name: 'at', type: 'number' },
|
|
58
|
+
{ name: 'expiresAt', expiresAt: true, indexed: true },
|
|
59
|
+
];
|
|
60
|
+
let tables;
|
|
61
|
+
/**
|
|
62
|
+
* Declares both tables and memoizes the handles. A read-only node cannot write the catalog, so it
|
|
63
|
+
* takes whatever the catalog already holds and declares nothing; a table not there yet reads as empty.
|
|
64
|
+
*/
|
|
65
|
+
function getDecisionTables(readOnly = (0, databases_ts_1.isReadOnlyMode)()) {
|
|
66
|
+
if (tables)
|
|
67
|
+
return tables;
|
|
68
|
+
const resolve = (name, attributes) => {
|
|
69
|
+
const handle = readOnly
|
|
70
|
+
? (0, databases_ts_1.getDatabases)().system?.[name]
|
|
71
|
+
: (0, databases_ts_1.table)({
|
|
72
|
+
table: name,
|
|
73
|
+
database: 'system',
|
|
74
|
+
// Declared positively, as the scheduler does: a scoped `replication.databases` must not
|
|
75
|
+
// exclude these, or an outcome recorded on one node never reaches the others.
|
|
76
|
+
replicate: true,
|
|
77
|
+
// auditing is the replication feed; must match systemSchema.json
|
|
78
|
+
audit: true,
|
|
79
|
+
attributes,
|
|
80
|
+
});
|
|
81
|
+
if (handle)
|
|
82
|
+
handle.loadAsInstance = false;
|
|
83
|
+
return handle;
|
|
84
|
+
};
|
|
85
|
+
const resolved = {
|
|
86
|
+
decisions: resolve(exports.DECISIONS_TABLE, exports.DECISION_ATTRIBUTES),
|
|
87
|
+
outcomes: resolve(exports.OUTCOMES_TABLE, exports.OUTCOME_ATTRIBUTES),
|
|
88
|
+
};
|
|
89
|
+
if (resolved.decisions && resolved.outcomes)
|
|
90
|
+
tables = resolved;
|
|
91
|
+
return resolved;
|
|
92
|
+
}
|
|
93
|
+
function resetDecisionTables() {
|
|
94
|
+
tables = undefined;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Declared at boot on every writable node so the TTL index exists where decisions are never made.
|
|
98
|
+
* A failure is logged, not thrown: the first `decide` declares again and reports its own error.
|
|
99
|
+
*/
|
|
100
|
+
function declareDecisionTablesAtBoot() {
|
|
101
|
+
if ((0, databases_ts_1.isReadOnlyMode)())
|
|
102
|
+
return;
|
|
103
|
+
try {
|
|
104
|
+
getDecisionTables();
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
log.warn?.(`Decision tables could not be declared at boot: ${err?.message ?? err}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class DecisionNotFoundError extends hdbError_ts_1.ClientError {
|
|
111
|
+
constructor(id) {
|
|
112
|
+
super(`No decision '${id}' on this node: it may not exist, may have expired, or may not have replicated here yet`, 404);
|
|
113
|
+
this.name = 'DecisionNotFoundError';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.DecisionNotFoundError = DecisionNotFoundError;
|
|
117
|
+
class OutcomeReportError extends hdbError_ts_1.ClientError {
|
|
118
|
+
constructor(message) {
|
|
119
|
+
super(`Invalid outcome report: ${message}`, 400);
|
|
120
|
+
this.name = 'OutcomeReportError';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.OutcomeReportError = OutcomeReportError;
|
|
124
|
+
class DecisionPersistenceError extends hdbError_ts_1.ServerError {
|
|
125
|
+
constructor(message, statusCode = 500) {
|
|
126
|
+
super(message, statusCode);
|
|
127
|
+
this.name = 'DecisionPersistenceError';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.DecisionPersistenceError = DecisionPersistenceError;
|
|
131
|
+
/**
|
|
132
|
+
* Durable decisions and their recorded facts. Every operation runs in a transaction of its own
|
|
133
|
+
* (`transaction` with a context object that is not the ALS store), so a decision made inside an
|
|
134
|
+
* application transaction survives that transaction's abort, and the commit is awaited before the
|
|
135
|
+
* id is returned to the caller.
|
|
136
|
+
*/
|
|
137
|
+
class DecisionStore {
|
|
138
|
+
#getTables;
|
|
139
|
+
#isReadOnly;
|
|
140
|
+
constructor(opts = {}) {
|
|
141
|
+
this.#getTables = opts.getTables ?? getDecisionTables;
|
|
142
|
+
this.#isReadOnly = opts.isReadOnly ?? databases_ts_1.isReadOnlyMode;
|
|
143
|
+
}
|
|
144
|
+
assertWritable(what) {
|
|
145
|
+
if (this.#isReadOnly())
|
|
146
|
+
throw new DecisionPersistenceError(`${what} cannot be recorded on a read-only node`, 503);
|
|
147
|
+
}
|
|
148
|
+
async persist(row) {
|
|
149
|
+
const { decisions } = this.#getTables();
|
|
150
|
+
await (0, transaction_ts_1.transaction)(freshContext(), () => decisions.put(row));
|
|
151
|
+
}
|
|
152
|
+
async get(id, tenant) {
|
|
153
|
+
return storageFaultsAs('Decision could not be read', () => (0, transaction_ts_1.transaction)(freshContext(), async () => {
|
|
154
|
+
const found = await this.#read(id, tenant);
|
|
155
|
+
return found && { ...found.row, outcome: assembleOutcome(found.row.schema, found.facts) };
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
async recordOutcome(id, report, tenant) {
|
|
159
|
+
this.assertWritable('Outcomes');
|
|
160
|
+
return storageFaultsAs('Outcome could not be recorded', () => (0, transaction_ts_1.transaction)(freshContext(), async () => {
|
|
161
|
+
const { outcomes } = this.#getTables();
|
|
162
|
+
const found = await this.#read(id, tenant);
|
|
163
|
+
if (!found)
|
|
164
|
+
throw new DecisionNotFoundError(id);
|
|
165
|
+
const { row, facts } = found;
|
|
166
|
+
const at = Date.now();
|
|
167
|
+
for (const reported of validateReport(row.schema, report)) {
|
|
168
|
+
const index = factIndex(row.schema, reported.fact, reported.field);
|
|
169
|
+
const existing = facts[index];
|
|
170
|
+
if (existing && (0, decision_ts_1.canonicalJson)(existing.state) === (0, decision_ts_1.canonicalJson)(reported.state))
|
|
171
|
+
continue;
|
|
172
|
+
const written = {
|
|
173
|
+
id: factKey(id, reported.fact, reported.field),
|
|
174
|
+
decisionId: id,
|
|
175
|
+
fact: reported.fact,
|
|
176
|
+
field: reported.field,
|
|
177
|
+
state: reported.state,
|
|
178
|
+
at,
|
|
179
|
+
expiresAt: row.expiresAt,
|
|
180
|
+
};
|
|
181
|
+
await outcomes.put(written);
|
|
182
|
+
facts[index] = written;
|
|
183
|
+
}
|
|
184
|
+
return { ...row, outcome: assembleOutcome(row.schema, facts) };
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
async #read(id, tenant) {
|
|
188
|
+
const { decisions, outcomes } = this.#getTables();
|
|
189
|
+
if (!decisions || !outcomes)
|
|
190
|
+
return undefined;
|
|
191
|
+
const row = await decisions.get(id);
|
|
192
|
+
if (!row || !visibleTo(row, tenant))
|
|
193
|
+
return undefined;
|
|
194
|
+
const facts = await Promise.all(factKeys(row.id, row.schema).map((key) => outcomes.get(key)));
|
|
195
|
+
return { row, facts };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.DecisionStore = DecisionStore;
|
|
199
|
+
let store;
|
|
200
|
+
function getDecisionStore() {
|
|
201
|
+
if (!store)
|
|
202
|
+
store = new DecisionStore();
|
|
203
|
+
return store;
|
|
204
|
+
}
|
|
205
|
+
function newDecisionId() {
|
|
206
|
+
return (0, node_crypto_1.randomUUID)();
|
|
207
|
+
}
|
|
208
|
+
/** A context of its own, so the transaction is separate, carrying the caller's user for the audit entry. */
|
|
209
|
+
function freshContext() {
|
|
210
|
+
const user = transaction_ts_1.contextStorage.getStore()?.user;
|
|
211
|
+
return (user ? { user } : {});
|
|
212
|
+
}
|
|
213
|
+
function visibleTo(row, tenant) {
|
|
214
|
+
return tenant == null || row.tenant == null || row.tenant === tenant;
|
|
215
|
+
}
|
|
216
|
+
function factKey(id, fact, field) {
|
|
217
|
+
return field == null ? `${id}/${fact}` : `${id}/${fact}/${field}`;
|
|
218
|
+
}
|
|
219
|
+
/** Truth then action, per property in schema order for object schemas; `factIndex` follows the same order. */
|
|
220
|
+
function factKeys(id, schema) {
|
|
221
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema))
|
|
222
|
+
return [factKey(id, 'truth'), factKey(id, 'action')];
|
|
223
|
+
return Object.keys(schema.properties).flatMap((field) => [factKey(id, 'truth', field), factKey(id, 'action', field)]);
|
|
224
|
+
}
|
|
225
|
+
function factIndex(schema, fact, field) {
|
|
226
|
+
const offset = fact === 'truth' ? 0 : 1;
|
|
227
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema))
|
|
228
|
+
return offset;
|
|
229
|
+
return Object.keys(schema.properties).indexOf(field) * 2 + offset;
|
|
230
|
+
}
|
|
231
|
+
function assembleOutcome(schema, facts) {
|
|
232
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema))
|
|
233
|
+
return leafOutcome(facts);
|
|
234
|
+
const fields = {};
|
|
235
|
+
const names = Object.keys(schema.properties);
|
|
236
|
+
for (let i = 0; i < names.length; i++)
|
|
237
|
+
fields[names[i]] = leafOutcome(facts.slice(i * 2, i * 2 + 2));
|
|
238
|
+
return { fields };
|
|
239
|
+
}
|
|
240
|
+
function leafOutcome(facts) {
|
|
241
|
+
const outcome = {};
|
|
242
|
+
for (const fact of facts) {
|
|
243
|
+
if (!fact)
|
|
244
|
+
continue;
|
|
245
|
+
if (fact.fact === 'truth') {
|
|
246
|
+
outcome.truth = fact.state;
|
|
247
|
+
outcome.truthAt = fact.at;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
outcome.action = fact.state;
|
|
251
|
+
outcome.actionAt = fact.at;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return outcome;
|
|
255
|
+
}
|
|
256
|
+
const TRUTH_KINDS = ['value', 'noMatch', 'unknown'];
|
|
257
|
+
const ACTION_KINDS = ['value', 'noMatch', 'abstained', 'unknown'];
|
|
258
|
+
/** Checks a report against the stored schema. Messages name fields, never reported values. */
|
|
259
|
+
function validateReport(schema, report) {
|
|
260
|
+
if (!report || typeof report !== 'object' || Array.isArray(report))
|
|
261
|
+
throw new OutcomeReportError('the report must be an object');
|
|
262
|
+
const facts = [];
|
|
263
|
+
if ((0, decision_ts_1.isObjectSchema)(schema)) {
|
|
264
|
+
if ('truth' in report || 'action' in report)
|
|
265
|
+
throw new OutcomeReportError('an object schema takes { fields: { <name>: { truth?, action? } } }');
|
|
266
|
+
const fields = report.fields;
|
|
267
|
+
if (!fields || typeof fields !== 'object' || Array.isArray(fields))
|
|
268
|
+
throw new OutcomeReportError('an object schema needs a fields map');
|
|
269
|
+
for (const [name, leafReport] of Object.entries(fields)) {
|
|
270
|
+
if (!Object.hasOwn(schema.properties, name))
|
|
271
|
+
throw new OutcomeReportError(`unknown field '${name}'`);
|
|
272
|
+
facts.push(...leafFacts(schema.properties[name], leafReport, name));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
if ('fields' in report)
|
|
277
|
+
throw new OutcomeReportError('a leaf schema takes { truth?, action? }');
|
|
278
|
+
facts.push(...leafFacts(schema, report, undefined));
|
|
279
|
+
}
|
|
280
|
+
if (facts.length === 0)
|
|
281
|
+
throw new OutcomeReportError('the report carries no fact');
|
|
282
|
+
return facts;
|
|
283
|
+
}
|
|
284
|
+
function leafFacts(leaf, report, field) {
|
|
285
|
+
const label = field === undefined ? 'the report' : `field '${field}'`;
|
|
286
|
+
if (!report || typeof report !== 'object' || Array.isArray(report))
|
|
287
|
+
throw new OutcomeReportError(`${label} must be an object`);
|
|
288
|
+
const facts = [];
|
|
289
|
+
if (report.truth !== undefined)
|
|
290
|
+
facts.push({ fact: 'truth', field, state: checkState(leaf, report.truth, TRUTH_KINDS, `${label}: truth`) });
|
|
291
|
+
if (report.action !== undefined)
|
|
292
|
+
facts.push({ fact: 'action', field, state: checkState(leaf, report.action, ACTION_KINDS, `${label}: action`) });
|
|
293
|
+
return facts;
|
|
294
|
+
}
|
|
295
|
+
function checkState(leaf, state, kinds, label) {
|
|
296
|
+
if (!state || typeof state !== 'object' || Array.isArray(state))
|
|
297
|
+
throw new OutcomeReportError(`${label} must be a tagged state`);
|
|
298
|
+
const { kind, value } = state;
|
|
299
|
+
if (typeof kind !== 'string' || !kinds.includes(kind))
|
|
300
|
+
throw new OutcomeReportError(`${label} has an unknown kind; expected one of ${kinds.join(', ')}`);
|
|
301
|
+
if (kind === 'value') {
|
|
302
|
+
if (!(0, decision_ts_1.isAllowedValue)(leaf, value))
|
|
303
|
+
throw new OutcomeReportError(`${label} is not an allowed value`);
|
|
304
|
+
return { kind, value };
|
|
305
|
+
}
|
|
306
|
+
return { kind };
|
|
307
|
+
}
|
|
308
|
+
let modelsConfigHash;
|
|
309
|
+
/**
|
|
310
|
+
* Identity of the model configuration actually installed, recorded on each decision so a reload
|
|
311
|
+
* that changes the model behind an unchanged logical name still separates the decisions it produced.
|
|
312
|
+
* Credential-looking keys are dropped before hashing.
|
|
313
|
+
*/
|
|
314
|
+
function setModelsConfigHash(installed) {
|
|
315
|
+
modelsConfigHash = installed
|
|
316
|
+
? (0, node_crypto_1.createHash)('sha256')
|
|
317
|
+
.update((0, decision_ts_1.canonicalJson)(withoutCredentials(installed)))
|
|
318
|
+
.digest('hex')
|
|
319
|
+
: undefined;
|
|
320
|
+
}
|
|
321
|
+
function getModelsConfigHash() {
|
|
322
|
+
return modelsConfigHash;
|
|
323
|
+
}
|
|
324
|
+
const CREDENTIAL_KEY = /^(apiKey|accessKeyId|authorization|.*secret.*|.*password.*|.*credential.*|.*key|.*token)$/i;
|
|
325
|
+
function withoutCredentials(value) {
|
|
326
|
+
if (Array.isArray(value))
|
|
327
|
+
return value.map(withoutCredentials);
|
|
328
|
+
if (!value || typeof value !== 'object')
|
|
329
|
+
return value;
|
|
330
|
+
const kept = {};
|
|
331
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
332
|
+
if (!CREDENTIAL_KEY.test(key))
|
|
333
|
+
kept[key] = withoutCredentials(entry);
|
|
334
|
+
}
|
|
335
|
+
return kept;
|
|
336
|
+
}
|
|
337
|
+
/** A fault from the storage layer can name a data path; only its class and a fixed message may reach a response body. */
|
|
338
|
+
async function storageFaultsAs(message, run) {
|
|
339
|
+
try {
|
|
340
|
+
return await run();
|
|
341
|
+
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
if (err instanceof hdbError_ts_1.ClientError || err instanceof DecisionPersistenceError)
|
|
344
|
+
throw err;
|
|
345
|
+
const error = new DecisionPersistenceError(message);
|
|
346
|
+
error.cause = err;
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=decisionStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decisionStore.js","sourceRoot":"","sources":["../../../resources/models/decisionStore.ts"],"names":[],"mappings":";;;;;;AA6GA,8CAwBC;AAED,kDAEC;AAMD,kEAOC;AAgHD,4CAGC;AAED,sCAEC;AAmHD,kDAMC;AAED,kDAEC;AA1YD,6CAAqD;AACrD,kDAAsE;AACtE,sDAAgE;AAEhE,kEAA4E;AAC5E,8FAAkE;AAClE,+CAA8E;AAa9E,MAAM,GAAG,GAAG,0BAAY,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC;AAE/C,QAAA,eAAe,GAAG,qBAAqB,CAAC;AACxC,QAAA,cAAc,GAAG,oBAAoB,CAAC;AACnD,sFAAsF;AACzE,QAAA,qBAAqB,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAqC/D;;;;GAIG;AACU,QAAA,mBAAmB,GAAG;IAClC,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;IAClC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IAClC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC9B,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IACrD,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IAClC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC/B,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACnC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;IACjC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QA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MAAM,cAAc,GAAG,4FAA4F,CAAC;AAEpH,SAAS,kBAAkB,CAAC,KAAc;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC/D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,IAAI,GAA4B,EAAE,CAAC;IACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;QAC7E,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,yHAAyH;AACzH,KAAK,UAAU,eAAe,CAAI,OAAe,EAAE,GAAqB;IACvE,IAAI,CAAC;QACJ,OAAO,MAAM,GAAG,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,IAAI,GAAG,YAAY,yBAAW,IAAI,GAAG,YAAY,wBAAwB;YAAE,MAAM,GAAG,CAAC;QACrF,MAAM,KAAK,GAAG,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC;QACnD,KAAqC,CAAC,KAAK,GAAG,GAAG,CAAC;QACnD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC"}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@embed` directive write-time hook. `createDefaultEmbedder` builds the embedder
|
|
3
|
-
* a table registers for an `@embed` attribute; `buildEmbedBefore` produces the
|
|
4
|
-
* pre-commit callback that runs registered embedders and writes their vectors onto
|
|
5
|
-
* the record before it commits.
|
|
6
|
-
*/
|
|
7
1
|
export type EmbedConfig = {
|
|
8
2
|
source: string;
|
|
9
3
|
model: string;
|
|
@@ -12,13 +6,77 @@ export type EmbedAttribute = {
|
|
|
12
6
|
name: string;
|
|
13
7
|
embed: EmbedConfig;
|
|
14
8
|
};
|
|
15
|
-
|
|
9
|
+
/** The signal aborts when a sibling hook of the same write fails; a hook that honors it lets the write fail promptly. */
|
|
10
|
+
export type WriteHookContext = {
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
};
|
|
13
|
+
export type Embedder = (record: any, hook?: WriteHookContext) => Promise<number[] | Float32Array | null | undefined>;
|
|
14
|
+
/** A pre-commit callback of one write; `signal` is the write's, aborted when another hook of the write fails. */
|
|
15
|
+
export type WriteHook = (signal?: AbortSignal) => Promise<void>;
|
|
16
16
|
type EmbedFn = (input: string | string[], opts: {
|
|
17
17
|
model?: string;
|
|
18
18
|
inputType?: 'document' | 'query';
|
|
19
|
+
signal?: AbortSignal;
|
|
19
20
|
}) => Promise<Float32Array[]>;
|
|
20
21
|
/** Test seam: override the embed function. Pass `undefined` to reset to `Models.embed`. */
|
|
21
22
|
export declare function __setEmbedFnForTest(fn: EmbedFn | undefined): void;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a write-time model hook runs for this write at all. Skip when the write already
|
|
25
|
+
* carries the derived attributes: a cluster-replication receiver (isNotification), REST
|
|
26
|
+
* x-replicate-from:none, or audit-log replay. Proactive source-subscribe pushes also set
|
|
27
|
+
* isNotification and so skip. One predicate for `@embed` and `@decide` so their trigger rules
|
|
28
|
+
* cannot drift.
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeHookApplies(record: any, context: any, options: any): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* How a hook treats one source field of the write payload: absent leaves the derived
|
|
33
|
+
* attributes alone (a PATCH that omits the source), null clears them, a CRDT op payload
|
|
34
|
+
* (`{__op__, value}`) is not a meaningful input and is skipped, and a value is derived from.
|
|
35
|
+
*/
|
|
36
|
+
export type SourceState = 'absent' | 'null' | 'op' | 'value';
|
|
37
|
+
export declare function sourceState(record: any, sourceKey: string | undefined): SourceState;
|
|
38
|
+
/**
|
|
39
|
+
* Run the jobs of one write. The first failure aborts the others, and every job settles before
|
|
40
|
+
* that failure is reported: a rejected write neither waits on a sibling that honors the signal
|
|
41
|
+
* nor keeps being mutated by one that has not finished. A job that ignores the signal is
|
|
42
|
+
* awaited regardless, so the model calls behind the built-in hooks forward it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function runWriteJobs(jobs: Array<(signal: AbortSignal) => Promise<void>>, signal?: AbortSignal): Promise<void>;
|
|
45
|
+
export declare function combineWriteHooks(a: WriteHook | undefined, b: WriteHook | undefined): WriteHook | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Backend errors can carry URLs / key tails; log raw, return a sanitized error to throw. Only
|
|
48
|
+
* safe identifiers are included (an identifier-shaped error class name, a finite upstream HTTP
|
|
49
|
+
* status) so the failure is diagnosable without hunting through server logs (#1593).
|
|
50
|
+
* `upstreamStatus` is the provider's status — NOT ServerError's statusCode, which is Harper's
|
|
51
|
+
* own response status and would misleadingly read 500 here.
|
|
52
|
+
*/
|
|
53
|
+
export declare function sanitizedHookError(actor: string, product: string, attributeName: string, err: unknown, log?: boolean): Error;
|
|
54
|
+
type DerivedAttribute = {
|
|
55
|
+
name: string;
|
|
56
|
+
type?: string;
|
|
57
|
+
nullable?: boolean;
|
|
58
|
+
isPrimaryKey?: boolean;
|
|
59
|
+
computed?: unknown;
|
|
60
|
+
embed?: {
|
|
61
|
+
source: string;
|
|
62
|
+
};
|
|
63
|
+
decide?: {
|
|
64
|
+
source: string;
|
|
65
|
+
confidence?: string;
|
|
66
|
+
decision?: string;
|
|
67
|
+
schema?: unknown;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Every derived field (an `@embed` target, a `@decide` target or confidence) has exactly one
|
|
72
|
+
* writer, and no directive derives from another directive's output: the hooks run concurrently
|
|
73
|
+
* within one write, so the stored pair would otherwise depend on scheduling. A source and a
|
|
74
|
+
* confidence field must be declared; a decided field and its confidence field are nullable,
|
|
75
|
+
* neither the primary key nor computed, the decided field's type matches its leaf and the leaf
|
|
76
|
+
* is a valid decision schema; and none of those fields may be named after an `Object.prototype`
|
|
77
|
+
* key, because `sourceState` tests presence with `in`. Run on the complete attribute list.
|
|
78
|
+
*/
|
|
79
|
+
export declare function assertDerivedFieldOwnership(attributes: DerivedAttribute[]): void;
|
|
22
80
|
export declare function createDefaultEmbedder(embedConfig: EmbedConfig): Embedder;
|
|
23
81
|
/**
|
|
24
82
|
* Build the pre-commit callback that runs embedders for every `@embed` attribute whose
|
|
@@ -29,5 +87,5 @@ export declare function createDefaultEmbedder(embedConfig: EmbedConfig): Embedde
|
|
|
29
87
|
* Source-field semantics: embed only when the source field is in the payload. A PATCH that
|
|
30
88
|
* omits it leaves the existing vector untouched; an explicit `source: null` clears the vector.
|
|
31
89
|
*/
|
|
32
|
-
export declare function buildEmbedBefore(record: any, context: any, options: any, embedAttributes: EmbedAttribute[] | undefined, userEmbedders: Record<string, Embedder>):
|
|
90
|
+
export declare function buildEmbedBefore(record: any, context: any, options: any, embedAttributes: EmbedAttribute[] | undefined, userEmbedders: Record<string, Embedder>): WriteHook | undefined;
|
|
33
91
|
export {};
|