@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,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerativeDecisionError = exports.MAX_SAMPLES = exports.DEFAULT_SAMPLES = void 0;
|
|
4
|
+
exports.registerGenerativeDecisionBackend = registerGenerativeDecisionBackend;
|
|
5
|
+
exports.createGenerativeDecisionBackend = createGenerativeDecisionBackend;
|
|
6
|
+
/**
|
|
7
|
+
* Built-in `decision` backend over a configured generative logical name (#2779). A call either
|
|
8
|
+
* scores every allowed value from the generative model's own likelihoods (#2838), when that name
|
|
9
|
+
* routes to a backend implementing `scoreChoices`, or asks the model for `samples`
|
|
10
|
+
* structured-output completions and reports the vote frequencies as the distribution. Configured
|
|
11
|
+
* as `models.decision.<name>: { backend: generative, scoring: auto | vote | score }`.
|
|
12
|
+
*
|
|
13
|
+
* Every sample and every scoring call flows through the `models` facade, so each one writes its
|
|
14
|
+
* own `hdb_model_calls` row and token metrics; the decide row itself reports no usage, or the
|
|
15
|
+
* tokens would be counted twice (the same reason the agent loop's outer call writes no row).
|
|
16
|
+
*/
|
|
17
|
+
const hdbError_ts_1 = require("../../utility/errors/hdbError.js");
|
|
18
|
+
const backendHelpers_ts_1 = require("./backendHelpers.js");
|
|
19
|
+
const backendRegistry_ts_1 = require("./backendRegistry.js");
|
|
20
|
+
const decision_ts_1 = require("./decision.js");
|
|
21
|
+
const Models_ts_1 = require("./Models.js");
|
|
22
|
+
const routing_ts_1 = require("./routing.js");
|
|
23
|
+
exports.DEFAULT_SAMPLES = 5;
|
|
24
|
+
exports.MAX_SAMPLES = 25;
|
|
25
|
+
const DEFAULT_CONCURRENCY = 5;
|
|
26
|
+
const STRUCTURED_OUTPUT = Object.freeze(['structuredOutput']);
|
|
27
|
+
const CAPABILITIES = Object.freeze({
|
|
28
|
+
embed: false,
|
|
29
|
+
generate: false,
|
|
30
|
+
stream: false,
|
|
31
|
+
tools: false,
|
|
32
|
+
adapters: false,
|
|
33
|
+
decide: true,
|
|
34
|
+
calibrated: false,
|
|
35
|
+
noMatch: true,
|
|
36
|
+
calibratedNoMatch: false,
|
|
37
|
+
});
|
|
38
|
+
const VOTE_SYSTEM_PROMPT = 'You make a decision about the input. Reply with a single JSON object that matches the required schema, choosing only from the allowed values.';
|
|
39
|
+
const SCORE_SYSTEM_PROMPT = 'You make a decision about the input, choosing only from the allowed values.';
|
|
40
|
+
const SCORE_NO_MATCH_SYSTEM_PROMPT = 'You make a decision about the input. Choose the allowed value that fits it, or the final option when none of the allowed values fits.';
|
|
41
|
+
const NO_MATCH_CHOICE = '(none of the listed values)';
|
|
42
|
+
class GenerativeDecisionError extends hdbError_ts_1.ServerError {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = 'GenerativeDecisionError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.GenerativeDecisionError = GenerativeDecisionError;
|
|
49
|
+
function registerGenerativeDecisionBackend(args) {
|
|
50
|
+
if (args.kind !== 'decision')
|
|
51
|
+
throw new GenerativeDecisionError(`backend 'generative' serves models.decision entries, not models.${args.kind}`);
|
|
52
|
+
(0, backendRegistry_ts_1.setDecision)(args.logicalName, createGenerativeDecisionBackend(args.config));
|
|
53
|
+
}
|
|
54
|
+
function createGenerativeDecisionBackend(config = {}, deps = {}) {
|
|
55
|
+
const generate = deps.generate ?? ((input, opts) => Models_ts_1.models.generate(input, opts));
|
|
56
|
+
const score = deps.score ?? ((input, choices, opts) => Models_ts_1.models.scoreChoices(input, choices, opts));
|
|
57
|
+
const canScore = deps.canScore ?? routesToScorer;
|
|
58
|
+
const logicalName = config.generative ?? 'default';
|
|
59
|
+
const samples = boundedCount(config.samples, exports.DEFAULT_SAMPLES);
|
|
60
|
+
const concurrency = boundedCount(config.concurrency, DEFAULT_CONCURRENCY);
|
|
61
|
+
const scoring = config.scoring ?? 'auto';
|
|
62
|
+
const { temperature, requestTimeoutMs } = config;
|
|
63
|
+
const vote = async (state, schema, instructions, signal) => {
|
|
64
|
+
const input = buildInput(state, schema, instructions, (0, decision_ts_1.wantsNoMatch)(schema) ? `${VOTE_SYSTEM_PROMPT} ${voteNoMatchLine(schema)}` : VOTE_SYSTEM_PROMPT, undefined);
|
|
65
|
+
const responseFormat = { schema: (0, decision_ts_1.toResponseSchema)(schema) };
|
|
66
|
+
const votes = await runPool(Array.from({ length: samples }, () => async (sampleSignal) => {
|
|
67
|
+
const result = await generate(input, {
|
|
68
|
+
model: logicalName,
|
|
69
|
+
responseFormat,
|
|
70
|
+
temperature,
|
|
71
|
+
signal: sampleSignal,
|
|
72
|
+
requires,
|
|
73
|
+
});
|
|
74
|
+
return parseSample(schema, result.content, logicalName);
|
|
75
|
+
}), concurrency, signal);
|
|
76
|
+
return tally(schema, votes);
|
|
77
|
+
};
|
|
78
|
+
const scoreLeaf = async (state, schema, field, leaf, instructions, signal) => {
|
|
79
|
+
const values = (0, decision_ts_1.allowedValues)(leaf);
|
|
80
|
+
const choices = values.map((value) => String(value));
|
|
81
|
+
if (leaf.noMatch !== true) {
|
|
82
|
+
const input = buildInput(state, schema, instructions, SCORE_SYSTEM_PROMPT, field);
|
|
83
|
+
const scored = await score(input, choices, { model: logicalName, signal });
|
|
84
|
+
return { distribution: softmax(values, scored?.logLikelihoods, logicalName) };
|
|
85
|
+
}
|
|
86
|
+
const input = buildInput(state, schema, instructions, SCORE_NO_MATCH_SYSTEM_PROMPT, field);
|
|
87
|
+
const scored = await score(input, [...choices, noMatchChoice(choices)], { model: logicalName, signal });
|
|
88
|
+
const all = softmax([...values, NO_MATCH], scored?.logLikelihoods, logicalName);
|
|
89
|
+
// Normalized over the allowed values' own scores, not by dividing out the none share, which can underflow to zero.
|
|
90
|
+
const distribution = softmax(values, scored.logLikelihoods.slice(0, values.length), logicalName);
|
|
91
|
+
return { distribution, noMatch: all[values.length].probability };
|
|
92
|
+
};
|
|
93
|
+
// One scoring call per leaf, through the same pool and budget as voting, so a 32-field schema
|
|
94
|
+
// does not open 32 provider connections at once and a caller abort settles every sibling.
|
|
95
|
+
const scoreAll = async (state, schema, instructions, signal) => {
|
|
96
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema)) {
|
|
97
|
+
const [scored] = await runPool([(leafSignal) => scoreLeaf(state, schema, undefined, schema, instructions, leafSignal)], concurrency, signal);
|
|
98
|
+
return scored;
|
|
99
|
+
}
|
|
100
|
+
const entries = Object.entries(schema.properties);
|
|
101
|
+
const marginals = await runPool(entries.map(([name, leaf]) => (leafSignal) => scoreLeaf(state, schema, name, leaf, instructions, leafSignal)), concurrency, signal);
|
|
102
|
+
return { fields: Object.fromEntries(entries.map(([name], i) => [name, marginals[i]])) };
|
|
103
|
+
};
|
|
104
|
+
const signatureFor = (mode) => `generative=${logicalName};mode=${mode};samples=${samples};temperature=${temperature ?? 'default'}`;
|
|
105
|
+
const requires = config.requireStructuredOutput === false ? undefined : STRUCTURED_OUTPUT;
|
|
106
|
+
return {
|
|
107
|
+
name: 'generative',
|
|
108
|
+
capabilities: () => CAPABILITIES,
|
|
109
|
+
async decide(state, schema, opts) {
|
|
110
|
+
const signal = (0, backendHelpers_ts_1.composeSignal)(opts.signal, requestTimeoutMs);
|
|
111
|
+
const mode = scoring === 'auto' ? (canScore(logicalName, largestLeaf(schema)) ? 'score' : 'vote') : scoring;
|
|
112
|
+
if (mode === 'score') {
|
|
113
|
+
try {
|
|
114
|
+
return {
|
|
115
|
+
status: 'completed',
|
|
116
|
+
output: { ...(await scoreAll(state, schema, opts.instructions, signal)), signature: signatureFor('score') },
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
if (scoring !== 'auto' || !isScoringUnsupported(err))
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
status: 'completed',
|
|
126
|
+
output: { ...(await vote(state, schema, opts.instructions, signal)), signature: signatureFor('vote') },
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// A candidate that advertises scoring without implementing it counts as able, so the facade reports
|
|
132
|
+
// that contract failure instead of the decision quietly voting.
|
|
133
|
+
function routesToScorer(logicalName, largestLeafSize) {
|
|
134
|
+
for (const backend of (0, routing_ts_1.getRouter)().route({ kind: 'generative', logicalName, requires: ['scoreChoices'] })) {
|
|
135
|
+
const limit = (0, Models_ts_1.scoringLimit)(backend.capabilities());
|
|
136
|
+
if (limit === undefined || largestLeafSize <= limit || typeof backend.scoreChoices !== 'function')
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
// Infinity for anything that is not a well-formed leaf, so an unexpected shape never reads as within a limit.
|
|
142
|
+
function leafSize(leaf) {
|
|
143
|
+
if (!leaf || typeof leaf !== 'object')
|
|
144
|
+
return Infinity;
|
|
145
|
+
if (Array.isArray(leaf.enum))
|
|
146
|
+
return leaf.enum.length;
|
|
147
|
+
if (leaf.type === 'boolean')
|
|
148
|
+
return 2;
|
|
149
|
+
const { type, minimum, maximum } = leaf;
|
|
150
|
+
if (type !== 'integer' || !Number.isSafeInteger(minimum) || !Number.isSafeInteger(maximum))
|
|
151
|
+
return Infinity;
|
|
152
|
+
const size = maximum - minimum + 1;
|
|
153
|
+
return size > 0 ? size : Infinity;
|
|
154
|
+
}
|
|
155
|
+
// A leaf that opted into no-match is scored with one extra choice, the "none" continuation.
|
|
156
|
+
function scoredChoices(leaf) {
|
|
157
|
+
return leafSize(leaf) + (leaf?.noMatch === true ? 1 : 0);
|
|
158
|
+
}
|
|
159
|
+
function largestLeaf(schema) {
|
|
160
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema))
|
|
161
|
+
return scoredChoices(schema);
|
|
162
|
+
let largest = 0;
|
|
163
|
+
for (const name in schema.properties)
|
|
164
|
+
if (Object.hasOwn(schema.properties, name))
|
|
165
|
+
largest = Math.max(largest, scoredChoices(schema.properties[name]));
|
|
166
|
+
return largest;
|
|
167
|
+
}
|
|
168
|
+
/** The errors after which `auto` votes: the backend declined this call, or lost the capability since the probe. */
|
|
169
|
+
function isScoringUnsupported(err) {
|
|
170
|
+
const name = err?.name;
|
|
171
|
+
return name === 'ChoiceScoringUnsupportedError' || name === 'ModelCapabilityError';
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Run `tasks` with at most `concurrency` in flight under one AbortController. The first failure
|
|
175
|
+
* aborts the rest, and the pool settles before that failure is thrown, so no task rejects
|
|
176
|
+
* unobserved and the facade never falls back to another candidate while calls are in flight.
|
|
177
|
+
* Siblings are aborted with a fresh reason, not the failure itself: a call that was cut short is
|
|
178
|
+
* recorded as aborted, not as a second copy of the failure with the same billed usage.
|
|
179
|
+
*/
|
|
180
|
+
async function runPool(tasks, concurrency, signal) {
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
const onAbort = () => controller.abort(signal?.reason);
|
|
183
|
+
if (signal?.aborted)
|
|
184
|
+
onAbort();
|
|
185
|
+
else
|
|
186
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
187
|
+
const results = new Array(tasks.length);
|
|
188
|
+
let failure;
|
|
189
|
+
let failed = false;
|
|
190
|
+
let next = 0;
|
|
191
|
+
const worker = async () => {
|
|
192
|
+
while (next < tasks.length && !controller.signal.aborted) {
|
|
193
|
+
const index = next++;
|
|
194
|
+
try {
|
|
195
|
+
results[index] = await tasks[index](controller.signal);
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
if (!failed) {
|
|
199
|
+
failed = true;
|
|
200
|
+
failure = err;
|
|
201
|
+
}
|
|
202
|
+
controller.abort(new DOMException('another call in this decision failed', 'AbortError'));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, tasks.length) }, worker));
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
signal?.removeEventListener('abort', onAbort);
|
|
212
|
+
}
|
|
213
|
+
if (failed)
|
|
214
|
+
throw failure;
|
|
215
|
+
signal?.throwIfAborted();
|
|
216
|
+
return results;
|
|
217
|
+
}
|
|
218
|
+
function boundedCount(value, fallback) {
|
|
219
|
+
if (!Number.isInteger(value) || value < 1)
|
|
220
|
+
return fallback;
|
|
221
|
+
return Math.min(value, exports.MAX_SAMPLES);
|
|
222
|
+
}
|
|
223
|
+
function parseSample(schema, content, logicalName) {
|
|
224
|
+
try {
|
|
225
|
+
return (0, decision_ts_1.parseDecisionSample)(schema, content);
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
throw new GenerativeDecisionError(`generative model '${logicalName}' produced a sample outside the decision schema: ${err.message}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** Normalize the backend's log-likelihoods over the leaf's values; the shape is checked because no backend's arithmetic is trusted. */
|
|
232
|
+
function softmax(values, logLikelihoods, logicalName) {
|
|
233
|
+
if (!Array.isArray(logLikelihoods) ||
|
|
234
|
+
logLikelihoods.length !== values.length ||
|
|
235
|
+
!logLikelihoods.every((x) => typeof x === 'number' && Number.isFinite(x)))
|
|
236
|
+
throw new GenerativeDecisionError(`generative model '${logicalName}' did not return one finite log-likelihood per allowed value (${values.length})`);
|
|
237
|
+
const scores = logLikelihoods;
|
|
238
|
+
const max = Math.max(...scores);
|
|
239
|
+
const weights = scores.map((x) => Math.exp(x - max));
|
|
240
|
+
const total = weights.reduce((sum, w) => sum + w, 0);
|
|
241
|
+
return values.map((value, i) => ({ value, probability: weights[i] / total }));
|
|
242
|
+
}
|
|
243
|
+
function buildInput(state, schema, instructions, system, field) {
|
|
244
|
+
const lines = [];
|
|
245
|
+
if (instructions)
|
|
246
|
+
lines.push(instructions, '');
|
|
247
|
+
if (schema.description)
|
|
248
|
+
lines.push(schema.description, '');
|
|
249
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema)) {
|
|
250
|
+
lines.push(`Decide "value": ${describeLeaf(schema)}`);
|
|
251
|
+
}
|
|
252
|
+
else if (field !== undefined) {
|
|
253
|
+
lines.push(`Decide "${field}": ${describeLeaf(schema.properties[field])}`);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
lines.push('Decide each field:');
|
|
257
|
+
for (const [name, leaf] of Object.entries(schema.properties))
|
|
258
|
+
lines.push(`- ${name}: ${describeLeaf(leaf)}`);
|
|
259
|
+
}
|
|
260
|
+
lines.push('', 'Input:', (0, decision_ts_1.stateToText)(state));
|
|
261
|
+
return { system, messages: [{ role: 'user', content: lines.join('\n') }] };
|
|
262
|
+
}
|
|
263
|
+
function describeLeaf(leaf) {
|
|
264
|
+
const range = !('enum' in leaf) && leaf.type === 'integer'
|
|
265
|
+
? `an integer from ${leaf.minimum} to ${leaf.maximum}`
|
|
266
|
+
: `one of ${(0, decision_ts_1.allowedValues)(leaf)
|
|
267
|
+
.map((value) => JSON.stringify(value))
|
|
268
|
+
.join(', ')}`;
|
|
269
|
+
return leaf.description ? `${leaf.description} (${range})` : range;
|
|
270
|
+
}
|
|
271
|
+
function tally(schema, votes) {
|
|
272
|
+
if ((0, decision_ts_1.isObjectSchema)(schema)) {
|
|
273
|
+
const fields = {};
|
|
274
|
+
for (const [name, leaf] of Object.entries(schema.properties))
|
|
275
|
+
fields[name] = tallyLeaf(leaf, votes.map((vote) => vote[name]));
|
|
276
|
+
return { fields };
|
|
277
|
+
}
|
|
278
|
+
return tallyLeaf(schema, votes);
|
|
279
|
+
}
|
|
280
|
+
function tallyLeaf(leaf, votes) {
|
|
281
|
+
if (leaf.noMatch !== true)
|
|
282
|
+
return { distribution: frequencies(leaf, votes) };
|
|
283
|
+
const values = new Array(votes.length);
|
|
284
|
+
let none = 0;
|
|
285
|
+
for (let i = 0; i < votes.length; i++) {
|
|
286
|
+
const pair = votes[i];
|
|
287
|
+
values[i] = pair.value;
|
|
288
|
+
if (pair.noMatch)
|
|
289
|
+
none++;
|
|
290
|
+
}
|
|
291
|
+
return { distribution: frequencies(leaf, values), noMatch: none / votes.length };
|
|
292
|
+
}
|
|
293
|
+
const NO_MATCH = Symbol('noMatch');
|
|
294
|
+
function voteNoMatchLine(schema) {
|
|
295
|
+
const rule = 'give the closest allowed value as "value", and set "noMatch" to true only when none of the allowed values truly fits the input.';
|
|
296
|
+
if (!(0, decision_ts_1.isObjectSchema)(schema))
|
|
297
|
+
return `Answer as { "value", "noMatch" }: ${rule}`;
|
|
298
|
+
const names = Object.entries(schema.properties)
|
|
299
|
+
.filter(([, leaf]) => leaf.noMatch === true)
|
|
300
|
+
.map(([name]) => JSON.stringify(name));
|
|
301
|
+
return `Answer ${names.join(', ')} each as { "value", "noMatch" }: ${rule}`;
|
|
302
|
+
}
|
|
303
|
+
function noMatchChoice(choices) {
|
|
304
|
+
let text = NO_MATCH_CHOICE;
|
|
305
|
+
while (choices.includes(text))
|
|
306
|
+
text = `(${text})`;
|
|
307
|
+
return text;
|
|
308
|
+
}
|
|
309
|
+
function frequencies(leaf, votes) {
|
|
310
|
+
const counts = new Map();
|
|
311
|
+
for (const vote of votes)
|
|
312
|
+
counts.set(vote, (counts.get(vote) ?? 0) + 1);
|
|
313
|
+
return (0, decision_ts_1.allowedValues)(leaf).map((value) => ({ value, probability: (counts.get(value) ?? 0) / votes.length }));
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=generativeDecision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generativeDecision.js","sourceRoot":"","sources":["../../../resources/models/generativeDecision.ts"],"names":[],"mappings":";;;AAsHA,8EAQC;AAED,0EA+HC;AA/PD;;;;;;;;;;GAUG;AACH,kEAA+D;AAC/D,2DAAoD;AACpD,6DAAmD;AACnD,+CAQuB;AACvB,2CAAmD;AACnD,6CAAyC;AAg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,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,OAAO,UAAU,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAoC,IAAI,EAAE,CAAC;AAC7E,CAAC;AAED,SAAS,aAAa,CAAC,OAA0B;IAChD,IAAI,IAAI,GAAG,eAAe,CAAC;IAC3B,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC;IAClD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,IAAkB,EAAE,KAAgB;IACxD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACxE,OAAO,IAAA,2BAAa,EAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAC9G,CAAC"}
|
|
@@ -10,8 +10,15 @@ export interface Models {
|
|
|
10
10
|
embed(input: string | string[], opts?: EmbedOpts): Promise<Float32Array[]>;
|
|
11
11
|
generate(input: GenerateInput, opts?: GenerateOpts): Promise<GenerateResult>;
|
|
12
12
|
generateStream(input: GenerateInput, opts?: GenerateOpts): AsyncIterable<GenerateChunk>;
|
|
13
|
+
/** Choose from a closed, schema-defined set and return the distribution over it. See #2779. */
|
|
14
|
+
decide<T = unknown>(state: DecideInput, schema: DecisionSchema, opts: RecordedDecideOpts): Promise<RecordedDecision<T>>;
|
|
15
|
+
decide<T = unknown>(state: DecideInput, schema: DecisionSchema, opts?: DecideOpts): Promise<Decision<T>>;
|
|
16
|
+
/** The durable record of a decision made with `persist: true`, with its recorded outcome, or undefined. See #2840. */
|
|
17
|
+
getDecision<T = unknown>(id: string): Promise<DecisionRecord<T> | undefined>;
|
|
18
|
+
/** Record what actually happened for a decision: its truth, the action taken, or both. See #2840. */
|
|
19
|
+
recordOutcome<T = unknown>(id: string, outcome: OutcomeReport): Promise<DecisionRecord<T>>;
|
|
13
20
|
/** Register a custom backend under a logical id, selectable via `opts.model`. See #1325. */
|
|
14
|
-
registerBackend(kind:
|
|
21
|
+
registerBackend(kind: ModelKind, id: string, backend: ModelBackend): void;
|
|
15
22
|
/** Build a `ModelBackend` from a spec; pair with `registerBackend`. See #1325. */
|
|
16
23
|
defineBackend(spec: DefineBackendSpec): ModelBackend;
|
|
17
24
|
/** Replace the model selection policy with a custom router. See #1326. */
|
|
@@ -23,19 +30,50 @@ export interface ModelBackend {
|
|
|
23
30
|
embed?(input: string | string[], opts: BackendOpts<EmbedOpts>): Promise<ModelCallResult<Float32Array[]>>;
|
|
24
31
|
generate?(input: GenerateInput, opts: BackendOpts<GenerateOpts>): Promise<ModelCallResult<GenerateResult>>;
|
|
25
32
|
generateStream?(input: GenerateInput, opts: BackendOpts<GenerateOpts>): AsyncIterable<GenerateChunk>;
|
|
33
|
+
decide?(state: DecideInput, schema: DecisionSchema, opts: BackendOpts<DecideOpts>): Promise<ModelCallResult<DecisionOutput<unknown>>>;
|
|
34
|
+
/**
|
|
35
|
+
* Score every entry of `choices` as the answer to `input` from the model's own likelihoods
|
|
36
|
+
* (#2838): one finite, unnormalized log-likelihood per choice, in order. A call the backend
|
|
37
|
+
* cannot score (too many choices for its alternatives list, a model that rejects
|
|
38
|
+
* log-probabilities, a response with no scored label) throws `ChoiceScoringUnsupportedError`
|
|
39
|
+
* so the caller can fall back; any other error is a failure.
|
|
40
|
+
*/
|
|
41
|
+
scoreChoices?(input: GenerateInput, choices: readonly string[], opts: BackendOpts<ScoreChoicesOpts>): Promise<ModelCallResult<ChoiceScores>>;
|
|
26
42
|
}
|
|
43
|
+
/** Registry kinds a backend is mapped under; a `decision` backend implements `decide` (#2779). */
|
|
44
|
+
export type ModelKind = 'embedding' | 'generative' | 'decision';
|
|
27
45
|
export interface ModelCapabilities {
|
|
28
46
|
embed: boolean;
|
|
29
47
|
generate: boolean;
|
|
30
48
|
stream: boolean;
|
|
31
49
|
tools: boolean;
|
|
32
50
|
adapters: boolean;
|
|
51
|
+
/** Implements `decide`. Optional so pre-#2779 backends stay source-compatible; absent reads as false. */
|
|
52
|
+
decide?: boolean;
|
|
53
|
+
/** `decide` probabilities are calibrated as returned. Absent reads as false. */
|
|
54
|
+
calibrated?: boolean;
|
|
55
|
+
/** Implements `scoreChoices`. Absent reads as false. */
|
|
56
|
+
scoreChoices?: boolean;
|
|
57
|
+
/** `decide` returns a no-match score for leaves that opt in with `noMatch: true` (#2846). Absent reads as false. */
|
|
58
|
+
noMatch?: boolean;
|
|
59
|
+
/** That no-match score is calibrated as returned. Absent reads as false. */
|
|
60
|
+
calibratedNoMatch?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* `generate` sends `responseFormat: { schema }` to the provider as a decoding constraint rather
|
|
63
|
+
* than a hint. Says what Harper sends, not what a remote endpoint honors. Absent reads as false.
|
|
64
|
+
*/
|
|
65
|
+
structuredOutput?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The most choices one `scoreChoices` call accepts. Absent means no stated limit. A limit, not a
|
|
68
|
+
* capability: it cannot be required, and a call above it is declined without a request.
|
|
69
|
+
*/
|
|
70
|
+
maxScoredChoices?: number;
|
|
33
71
|
}
|
|
34
|
-
/** A capability a call can require of its backend (a key of `ModelCapabilities`). */
|
|
35
|
-
export type Capability = keyof ModelCapabilities
|
|
72
|
+
/** A capability a call can require of its backend (a boolean key of `ModelCapabilities`). */
|
|
73
|
+
export type Capability = Exclude<keyof ModelCapabilities, 'maxScoredChoices'>;
|
|
36
74
|
/** What the router is asked to resolve for a single call. See #1326. */
|
|
37
75
|
export interface RouteRequest {
|
|
38
|
-
kind:
|
|
76
|
+
kind: ModelKind;
|
|
39
77
|
/** Logical name from `opts.model` (a role or a concrete backend id); defaults to `'default'`. */
|
|
40
78
|
logicalName: string;
|
|
41
79
|
/** Capabilities the chosen backend must satisfy — explicit `opts.requires` plus any auto-derived (e.g. tools present in the input). */
|
|
@@ -67,10 +105,22 @@ export interface DefineBackendSpec {
|
|
|
67
105
|
embed?: ModelBackend['embed'];
|
|
68
106
|
generate?: ModelBackend['generate'];
|
|
69
107
|
generateStream?: ModelBackend['generateStream'];
|
|
108
|
+
decide?: ModelBackend['decide'];
|
|
109
|
+
scoreChoices?: ModelBackend['scoreChoices'];
|
|
70
110
|
/** Backend supports tool calls in `generate` / `generateStream`. Default `false`. */
|
|
71
111
|
tools?: boolean;
|
|
72
112
|
/** Backend supports per-call LoRA / adapter selection. Default `false`. */
|
|
73
113
|
adapters?: boolean;
|
|
114
|
+
/** `decide` probabilities are calibrated as returned. Default `false`. */
|
|
115
|
+
calibrated?: boolean;
|
|
116
|
+
/** `decide` returns a no-match score for opted-in leaves. Default `false`. */
|
|
117
|
+
noMatch?: boolean;
|
|
118
|
+
/** That no-match score is calibrated as returned. Default `false`. */
|
|
119
|
+
calibratedNoMatch?: boolean;
|
|
120
|
+
/** `generate` sends `responseFormat: { schema }` as a decoding constraint. Default `false`. */
|
|
121
|
+
structuredOutput?: boolean;
|
|
122
|
+
/** The most choices one `scoreChoices` call accepts, a positive integer. Default: no limit. */
|
|
123
|
+
maxScoredChoices?: number;
|
|
74
124
|
}
|
|
75
125
|
export type EmbedOpts = {
|
|
76
126
|
model?: string;
|
|
@@ -80,6 +130,184 @@ export type EmbedOpts = {
|
|
|
80
130
|
inputType?: 'document' | 'query';
|
|
81
131
|
signal?: AbortSignal;
|
|
82
132
|
};
|
|
133
|
+
/** Text, or JSON-serializable program state, for `decide`. */
|
|
134
|
+
export type DecideInput = string | object;
|
|
135
|
+
/**
|
|
136
|
+
* One leaf of a decision schema: a closed set every backend family can score. `enum` holds
|
|
137
|
+
* 2..255 distinct values of one type; an integer range spans at most 255 values; booleans order
|
|
138
|
+
* as `[false, true]` for tie-breaking.
|
|
139
|
+
*/
|
|
140
|
+
export type DecisionLeaf = {
|
|
141
|
+
description?: string;
|
|
142
|
+
noMatch?: boolean;
|
|
143
|
+
} & ({
|
|
144
|
+
enum: readonly string[] | readonly number[] | readonly boolean[];
|
|
145
|
+
} | {
|
|
146
|
+
type: 'boolean';
|
|
147
|
+
} | {
|
|
148
|
+
type: 'integer';
|
|
149
|
+
minimum: number;
|
|
150
|
+
maximum: number;
|
|
151
|
+
});
|
|
152
|
+
/** A decision schema: one leaf, or one level of named leaves. Deeper nesting is deliberately unsupported. */
|
|
153
|
+
export type DecisionSchema = DecisionLeaf | {
|
|
154
|
+
type: 'object';
|
|
155
|
+
description?: string;
|
|
156
|
+
properties: Record<string, DecisionLeaf>;
|
|
157
|
+
};
|
|
158
|
+
export type DecideOpts = {
|
|
159
|
+
model?: string;
|
|
160
|
+
/** Capabilities the chosen backend must satisfy, e.g. `['calibrated']`; the router filters candidates (#1326). */
|
|
161
|
+
requires?: Capability[];
|
|
162
|
+
/** Task framing beyond the schema's own descriptions. */
|
|
163
|
+
instructions?: string;
|
|
164
|
+
signal?: AbortSignal;
|
|
165
|
+
/**
|
|
166
|
+
* `true` commits a durable record of the decision to `hdb_model_decisions` before returning, so its
|
|
167
|
+
* outcome can be recorded later; the result then carries its `id`. Default `false`: nothing is stored
|
|
168
|
+
* beyond the per-call analytics row, as with `embed` and `generate`.
|
|
169
|
+
*/
|
|
170
|
+
persist?: boolean;
|
|
171
|
+
};
|
|
172
|
+
/** Options that record the decision, so the result is a `RecordedDecision` with an `id`. */
|
|
173
|
+
export type RecordedDecideOpts = DecideOpts & {
|
|
174
|
+
persist: true;
|
|
175
|
+
};
|
|
176
|
+
export interface DecisionOutcome {
|
|
177
|
+
value: unknown;
|
|
178
|
+
probability: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* What a `decision` backend returns for one call. For a leaf schema `distribution` is required
|
|
182
|
+
* and complete (one entry per allowed value, summing to one); for an object schema `fields`
|
|
183
|
+
* carries one such entry per property. The facade derives `value` and `probability`, so a
|
|
184
|
+
* backend may omit them; a `value` it does supply must be a most-probable outcome, and on a
|
|
185
|
+
* tie it leads the distribution.
|
|
186
|
+
*/
|
|
187
|
+
export interface DecisionOutput<T = unknown> {
|
|
188
|
+
value?: T;
|
|
189
|
+
probability?: number;
|
|
190
|
+
distribution?: DecisionOutcome[];
|
|
191
|
+
fields?: Record<string, DecisionOutput<unknown>>;
|
|
192
|
+
/** For a leaf that opted in: the score in [0, 1] that the input matches none of the allowed values. */
|
|
193
|
+
noMatch?: number;
|
|
194
|
+
calibrated?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Opaque identity of the configuration that produced the scores (sampling, scoring method,
|
|
197
|
+
* prompt revision), stored with the decision so calibration is keyed per configuration (#2841).
|
|
198
|
+
*/
|
|
199
|
+
signature?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Result of `models.decide`. For a leaf schema `value` is the first entry of `distribution`,
|
|
203
|
+
* which is sorted descending with ties in schema order unless the backend chose one of the tied
|
|
204
|
+
* values; `probability` is its entry. For an object schema
|
|
205
|
+
* `value` is assembled from each field's marginal argmax — a combination no single sample may
|
|
206
|
+
* have produced — and the marginals live in `fields`.
|
|
207
|
+
*/
|
|
208
|
+
export interface Decision<T = unknown> {
|
|
209
|
+
/** Present only when the call passed `persist: true`: the cluster-unique id of the decision's record in `hdb_model_decisions`, committed before the decision is returned; pass it to `recordOutcome` (#2840). */
|
|
210
|
+
id?: string;
|
|
211
|
+
value: T;
|
|
212
|
+
probability?: number;
|
|
213
|
+
distribution?: DecisionOutcome[];
|
|
214
|
+
fields?: Record<string, FieldDecision>;
|
|
215
|
+
/** Leaf schemas that opted in: the score that the input matches none of the allowed values (#2846). */
|
|
216
|
+
noMatch?: number;
|
|
217
|
+
/** Whether the probabilities come from a calibrated source, as the backend reports it. */
|
|
218
|
+
calibrated: boolean;
|
|
219
|
+
usage?: TokenUsage;
|
|
220
|
+
}
|
|
221
|
+
/** A decision made with `persist: true`: its `id` is always present. */
|
|
222
|
+
export type RecordedDecision<T = unknown> = Decision<T> & {
|
|
223
|
+
id: string;
|
|
224
|
+
};
|
|
225
|
+
/** One field's marginal in an object-schema `Decision`. */
|
|
226
|
+
export interface FieldDecision {
|
|
227
|
+
value: unknown;
|
|
228
|
+
probability: number;
|
|
229
|
+
distribution: DecisionOutcome[];
|
|
230
|
+
/** Fields that opted in: the no-match score. */
|
|
231
|
+
noMatch?: number;
|
|
232
|
+
}
|
|
233
|
+
export type ScoreChoicesOpts = {
|
|
234
|
+
model?: string;
|
|
235
|
+
/** Capabilities the chosen backend must satisfy, beyond `scoreChoices` itself; the router filters candidates (#1326). */
|
|
236
|
+
requires?: Capability[];
|
|
237
|
+
signal?: AbortSignal;
|
|
238
|
+
};
|
|
239
|
+
/** Unnormalized; the caller normalizes. */
|
|
240
|
+
export interface ChoiceScores {
|
|
241
|
+
logLikelihoods: number[];
|
|
242
|
+
}
|
|
243
|
+
/** What turned out to be true for a decision: an allowed value, none of them, or not known. Tagged, so no label is a sentinel. */
|
|
244
|
+
export type OutcomeTruth = {
|
|
245
|
+
kind: 'value';
|
|
246
|
+
value: unknown;
|
|
247
|
+
} | {
|
|
248
|
+
kind: 'noMatch';
|
|
249
|
+
} | {
|
|
250
|
+
kind: 'unknown';
|
|
251
|
+
};
|
|
252
|
+
/** What the application did with a decision: acted on a value, routed it as no-match, abstained by policy, or not known. */
|
|
253
|
+
export type OutcomeAction = {
|
|
254
|
+
kind: 'value';
|
|
255
|
+
value: unknown;
|
|
256
|
+
} | {
|
|
257
|
+
kind: 'noMatch';
|
|
258
|
+
} | {
|
|
259
|
+
kind: 'abstained';
|
|
260
|
+
} | {
|
|
261
|
+
kind: 'unknown';
|
|
262
|
+
};
|
|
263
|
+
/** The facts reported for one leaf: either, or both. Each is stored on its own, so reports never overwrite each other. */
|
|
264
|
+
export interface LeafOutcomeReport {
|
|
265
|
+
truth?: OutcomeTruth;
|
|
266
|
+
action?: OutcomeAction;
|
|
267
|
+
}
|
|
268
|
+
/** A `recordOutcome` report: leaf facts for a leaf schema, or per-field facts for an object schema. */
|
|
269
|
+
export type OutcomeReport = LeafOutcomeReport | {
|
|
270
|
+
fields: Record<string, LeafOutcomeReport>;
|
|
271
|
+
};
|
|
272
|
+
export interface RecordedLeafOutcome extends LeafOutcomeReport {
|
|
273
|
+
truthAt?: number;
|
|
274
|
+
actionAt?: number;
|
|
275
|
+
}
|
|
276
|
+
export type RecordedOutcome = RecordedLeafOutcome | {
|
|
277
|
+
fields: Record<string, RecordedLeafOutcome>;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* The durable record of one decision (#2840): what was asked, what was answered, who answered,
|
|
281
|
+
* and what was recorded afterwards. Written once by `decide`; only `outcome` grows.
|
|
282
|
+
*/
|
|
283
|
+
export interface DecisionRecord<T = unknown> {
|
|
284
|
+
id: string;
|
|
285
|
+
/** The `hdb_model_calls` row of the call that produced it; correlation only. */
|
|
286
|
+
callId: number;
|
|
287
|
+
at: number;
|
|
288
|
+
/** When the record and its facts expire; a fact never extends it. */
|
|
289
|
+
expiresAt: number;
|
|
290
|
+
tenant?: string;
|
|
291
|
+
app?: string;
|
|
292
|
+
backend: string;
|
|
293
|
+
model: string;
|
|
294
|
+
signature?: string;
|
|
295
|
+
/** Identity of the `models` config block in force when the decision was made. */
|
|
296
|
+
configHash?: string;
|
|
297
|
+
/** sha256 of the per-call `instructions`, when any were given. */
|
|
298
|
+
instructionsHash?: string;
|
|
299
|
+
/** The schema's allowed values, without descriptions. */
|
|
300
|
+
schema: DecisionSchema;
|
|
301
|
+
/** Identity of the full schema, descriptions included. */
|
|
302
|
+
schemaHash: string;
|
|
303
|
+
value: T;
|
|
304
|
+
probability?: number;
|
|
305
|
+
distribution?: DecisionOutcome[];
|
|
306
|
+
fields?: Record<string, FieldDecision>;
|
|
307
|
+
noMatch?: number;
|
|
308
|
+
calibrated: boolean;
|
|
309
|
+
outcome: RecordedOutcome;
|
|
310
|
+
}
|
|
83
311
|
export type GenerateOpts = {
|
|
84
312
|
model?: string;
|
|
85
313
|
/** Capabilities the chosen backend must satisfy (e.g. `['tools']`); the router selects/filters candidates accordingly. Tools present in the input are auto-required. (#1326) */
|