@adcp/sdk 16.2.0 → 16.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -0
- package/dist/lib/adapters/version/3.1/assignments.d.mts +12 -0
- package/dist/lib/adapters/version/3.1/assignments.d.ts +12 -0
- package/dist/lib/adapters/version/3.1/assignments.js +67 -0
- package/dist/lib/adapters/version/3.1/assignments.mjs +43 -0
- package/dist/lib/adapters/version/3.1/bidding.d.mts +3 -0
- package/dist/lib/adapters/version/3.1/bidding.d.ts +3 -0
- package/dist/lib/adapters/version/3.1/bidding.js +115 -0
- package/dist/lib/adapters/version/3.1/bidding.mjs +90 -0
- package/dist/lib/adapters/version/3.1/delivery.d.mts +7 -0
- package/dist/lib/adapters/version/3.1/delivery.d.ts +7 -0
- package/dist/lib/adapters/version/3.1/delivery.js +78 -0
- package/dist/lib/adapters/version/3.1/delivery.mjs +54 -0
- package/dist/lib/adapters/version/3.1/index.d.mts +3 -0
- package/dist/lib/adapters/version/3.1/index.d.ts +3 -0
- package/dist/lib/adapters/version/3.1/index.js +36 -0
- package/dist/lib/adapters/version/3.1/index.mjs +12 -0
- package/dist/lib/adapters/version/index.d.mts +59 -7
- package/dist/lib/adapters/version/index.d.ts +59 -7
- package/dist/lib/adapters/version/index.js +51 -2
- package/dist/lib/adapters/version/index.mjs +49 -1
- package/dist/lib/adapters/version/negotiate.d.mts +71 -0
- package/dist/lib/adapters/version/negotiate.d.ts +71 -0
- package/dist/lib/adapters/version/negotiate.js +101 -0
- package/dist/lib/adapters/version/negotiate.mjs +73 -0
- package/dist/lib/adapters/version/schema-projection.d.mts +33 -0
- package/dist/lib/adapters/version/schema-projection.d.ts +33 -0
- package/dist/lib/adapters/version/schema-projection.js +294 -0
- package/dist/lib/adapters/version/schema-projection.mjs +269 -0
- package/dist/lib/adapters/version/translate.d.mts +122 -0
- package/dist/lib/adapters/version/translate.d.ts +122 -0
- package/dist/lib/adapters/version/translate.js +169 -0
- package/dist/lib/adapters/version/translate.mjs +141 -0
- package/dist/lib/adapters/version/types.d.mts +51 -10
- package/dist/lib/adapters/version/types.d.ts +51 -10
- package/dist/lib/core/AgentClient.d.mts +1 -1
- package/dist/lib/core/AgentClient.d.ts +1 -1
- package/dist/lib/core/AgentClient.js +17 -1
- package/dist/lib/core/AgentClient.mjs +17 -1
- package/dist/lib/core/ConversationTypes.d.mts +7 -0
- package/dist/lib/core/ConversationTypes.d.ts +7 -0
- package/dist/lib/core/SingleAgentClient.d.mts +82 -0
- package/dist/lib/core/SingleAgentClient.d.ts +82 -0
- package/dist/lib/core/SingleAgentClient.js +336 -15
- package/dist/lib/core/SingleAgentClient.mjs +350 -17
- package/dist/lib/core/TaskExecutor.d.mts +1 -1
- package/dist/lib/core/TaskExecutor.d.ts +1 -1
- package/dist/lib/core/TaskExecutor.js +182 -31
- package/dist/lib/core/TaskExecutor.mjs +183 -32
- package/dist/lib/core/account-reduction.d.mts +36 -0
- package/dist/lib/core/account-reduction.d.ts +36 -0
- package/dist/lib/core/account-reduction.js +127 -0
- package/dist/lib/core/account-reduction.mjs +98 -0
- package/dist/lib/core/buyer-account-registry.d.mts +52 -0
- package/dist/lib/core/buyer-account-registry.d.ts +52 -0
- package/dist/lib/core/buyer-account-registry.js +142 -6
- package/dist/lib/core/buyer-account-registry.mjs +142 -6
- package/dist/lib/errors/index.d.mts +34 -0
- package/dist/lib/errors/index.d.ts +34 -0
- package/dist/lib/errors/index.js +11 -0
- package/dist/lib/errors/index.mjs +10 -0
- package/dist/lib/index.d.mts +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.mjs +2 -0
- package/dist/lib/media-buy/action-contracts.js +4 -4
- package/dist/lib/media-buy/action-contracts.mjs +4 -4
- package/dist/lib/media-buy/action-types.d.mts +3 -2
- package/dist/lib/media-buy/action-types.d.ts +3 -2
- package/dist/lib/media-buy/compatibility.d.mts +1 -0
- package/dist/lib/media-buy/compatibility.d.ts +1 -0
- package/dist/lib/media-buy/compatibility.js +33 -10
- package/dist/lib/media-buy/compatibility.mjs +32 -14
- package/dist/lib/media-buy/update-fields.generated.d.mts +3 -2
- package/dist/lib/media-buy/update-fields.generated.d.ts +3 -2
- package/dist/lib/negotiation/buyer.js +11 -5
- package/dist/lib/negotiation/buyer.mjs +11 -5
- package/dist/lib/negotiation/types.d.mts +4 -2
- package/dist/lib/negotiation/types.d.ts +4 -2
- package/dist/lib/negotiation/verification.d.mts +15 -6
- package/dist/lib/negotiation/verification.d.ts +15 -6
- package/dist/lib/negotiation/verification.js +146 -27
- package/dist/lib/negotiation/verification.mjs +146 -28
- package/dist/lib/negotiation/version.d.mts +6 -0
- package/dist/lib/negotiation/version.d.ts +6 -0
- package/dist/lib/negotiation/version.js +60 -0
- package/dist/lib/negotiation/version.mjs +33 -0
- package/dist/lib/registry/types.generated.d.mts +1 -1
- package/dist/lib/registry/types.generated.d.ts +1 -1
- package/dist/lib/server/create-adcp-server.d.mts +21 -0
- package/dist/lib/server/create-adcp-server.d.ts +21 -0
- package/dist/lib/server/create-adcp-server.js +98 -16
- package/dist/lib/server/create-adcp-server.mjs +84 -2
- package/dist/lib/server/error-arm-tools.d.mts +10 -10
- package/dist/lib/server/error-arm-tools.d.ts +10 -10
- package/dist/lib/server/error-arm-tools.js +22 -58
- package/dist/lib/server/error-arm-tools.mjs +30 -65
- package/dist/lib/server/index.d.mts +1 -1
- package/dist/lib/server/index.d.ts +1 -1
- package/dist/lib/storage/interfaces.d.mts +2 -0
- package/dist/lib/storage/interfaces.d.ts +2 -0
- package/dist/lib/testing/compliance/comply.js +17 -0
- package/dist/lib/testing/compliance/comply.mjs +17 -0
- package/dist/lib/testing/index.d.mts +3 -0
- package/dist/lib/testing/index.d.ts +3 -0
- package/dist/lib/testing/index.js +44 -2
- package/dist/lib/testing/index.mjs +42 -0
- package/dist/lib/testing/storyboard/collection-selection.d.mts +259 -0
- package/dist/lib/testing/storyboard/collection-selection.d.ts +259 -0
- package/dist/lib/testing/storyboard/collection-selection.js +384 -0
- package/dist/lib/testing/storyboard/collection-selection.mjs +348 -0
- package/dist/lib/testing/storyboard/context.js +12 -6
- package/dist/lib/testing/storyboard/context.mjs +12 -6
- package/dist/lib/testing/storyboard/fixture-resolution.d.mts +39 -1
- package/dist/lib/testing/storyboard/fixture-resolution.d.ts +39 -1
- package/dist/lib/testing/storyboard/fixture-resolution.js +216 -12
- package/dist/lib/testing/storyboard/fixture-resolution.mjs +218 -12
- package/dist/lib/testing/storyboard/index.d.mts +9 -2
- package/dist/lib/testing/storyboard/index.d.ts +9 -2
- package/dist/lib/testing/storyboard/index.js +51 -2
- package/dist/lib/testing/storyboard/index.mjs +49 -1
- package/dist/lib/testing/storyboard/prepared-fixtures.d.mts +471 -0
- package/dist/lib/testing/storyboard/prepared-fixtures.d.ts +471 -0
- package/dist/lib/testing/storyboard/prepared-fixtures.js +434 -0
- package/dist/lib/testing/storyboard/prepared-fixtures.mjs +389 -0
- package/dist/lib/testing/storyboard/protected-context.d.mts +127 -0
- package/dist/lib/testing/storyboard/protected-context.d.ts +127 -0
- package/dist/lib/testing/storyboard/protected-context.js +301 -0
- package/dist/lib/testing/storyboard/protected-context.mjs +267 -0
- package/dist/lib/testing/storyboard/rejection-hints.js +13 -4
- package/dist/lib/testing/storyboard/rejection-hints.mjs +13 -4
- package/dist/lib/testing/storyboard/runner.d.mts +24 -0
- package/dist/lib/testing/storyboard/runner.d.ts +24 -0
- package/dist/lib/testing/storyboard/runner.js +1061 -105
- package/dist/lib/testing/storyboard/runner.mjs +1075 -106
- package/dist/lib/testing/storyboard/seeding.d.mts +15 -1
- package/dist/lib/testing/storyboard/seeding.d.ts +15 -1
- package/dist/lib/testing/storyboard/seeding.js +272 -12
- package/dist/lib/testing/storyboard/seeding.mjs +274 -13
- package/dist/lib/testing/storyboard/types.d.mts +207 -10
- package/dist/lib/testing/storyboard/types.d.ts +207 -10
- package/dist/lib/testing/storyboard/types.js +1 -1
- package/dist/lib/testing/storyboard/types.mjs +1 -1
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/testing/storyboard/validations.js +95 -0
- package/dist/lib/testing/storyboard/validations.mjs +95 -0
- package/dist/lib/validation/bundled-schema-store.js +5 -0
- package/dist/lib/validation/bundled-schema-store.mjs +4 -0
- package/dist/lib/validation/schema-loader.js +19 -2
- package/dist/lib/validation/schema-loader.mjs +22 -3
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/docs/TYPE-SUMMARY.md +2 -2
- package/docs/guides/COLLECTION-FIXTURE-FOUNDATION.md +850 -0
- package/docs/guides/PROPOSAL-TERMS-VERIFICATION.md +66 -0
- package/docs/llms.txt +4 -3
- package/docs/migration-14.x-rc-worksheet.md +4 -4
- package/package.json +1 -1
|
@@ -28,7 +28,9 @@ import {
|
|
|
28
28
|
} from "../validation/client-hooks.mjs";
|
|
29
29
|
import { formatIssues } from "../validation/schema-validator.mjs";
|
|
30
30
|
import { withServedValidationVersion } from "../validation/schema-loader.mjs";
|
|
31
|
-
import { ADCP_VERSION } from "../version.mjs";
|
|
31
|
+
import { ADCP_VERSION, toReleasePrecisionVersion } from "../version.mjs";
|
|
32
|
+
import { applicableRefinementServedVersion } from "../negotiation/version.mjs";
|
|
33
|
+
import { selectRefinementSchemaVersion } from "../negotiation/verification.mjs";
|
|
32
34
|
import { unwrapProtocolResponse, isAdcpOperationSuccess } from "../utils/response-unwrapper.mjs";
|
|
33
35
|
import { extractAdcpErrorInfo, extractCorrelationId } from "../utils/error-extraction.mjs";
|
|
34
36
|
import { generateIdempotencyKey, requestUsesIdempotency, redactIdempotencyKeyInArgs } from "../utils/idempotency.mjs";
|
|
@@ -665,7 +667,11 @@ class TaskExecutor {
|
|
|
665
667
|
* adaptation runs, so the validator sees the same object the caller wrote.
|
|
666
668
|
* Throws in strict, logs to `debugLogs` in warn, no-ops in off.
|
|
667
669
|
*/
|
|
668
|
-
validateRequest(taskName, params, debugLogs) {
|
|
670
|
+
validateRequest(taskName, params, debugLogs, adcpVersion) {
|
|
671
|
+
if (adcpVersion !== void 0) {
|
|
672
|
+
validateOutgoingRequest(taskName, params, this.requestValidationMode, debugLogs, adcpVersion);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
669
675
|
if (this.config.experimentalIdentity33?.() && this.requestValidationMode !== "off") {
|
|
670
676
|
const outcome = validateIdentity33Payload(taskName, "request", params, this.config.adcpVersion);
|
|
671
677
|
if (!outcome.valid) {
|
|
@@ -801,6 +807,13 @@ class TaskExecutor {
|
|
|
801
807
|
agent: { id: agent.id, name: agent.name, protocol: agent.protocol },
|
|
802
808
|
serverVersion: effectiveServerVersion,
|
|
803
809
|
serverVersionSynthetic: targetCapabilities?._synthetic ?? serverVersion === void 0,
|
|
810
|
+
...taskName === "refine_proposals" && targetCapabilities?._synthetic === false && {
|
|
811
|
+
refinementServedVersion: applicableRefinementServedVersion(
|
|
812
|
+
targetCapabilities.servedVersion,
|
|
813
|
+
params?.adcp_version ?? toReleasePrecisionVersion(wireAdcpVersion ?? this.config.adcpVersion ?? ADCP_VERSION),
|
|
814
|
+
toReleasePrecisionVersion(this.config.wireAdcpVersion ?? this.config.adcpVersion ?? ADCP_VERSION)
|
|
815
|
+
)
|
|
816
|
+
},
|
|
804
817
|
idempotencyKey
|
|
805
818
|
};
|
|
806
819
|
this.activeTasks.set(taskId, taskState);
|
|
@@ -1091,7 +1104,8 @@ class TaskExecutor {
|
|
|
1091
1104
|
dispatchSettlement?.persistPausedContinuation ?? true,
|
|
1092
1105
|
effectiveServerVersion,
|
|
1093
1106
|
deferredClientContext,
|
|
1094
|
-
dispatchSettlement?.requireDeferredSettlementResumeAuthorization === true
|
|
1107
|
+
dispatchSettlement?.requireDeferredSettlementResumeAuthorization === true,
|
|
1108
|
+
taskState.refinementServedVersion
|
|
1095
1109
|
);
|
|
1096
1110
|
throwIfAborted(postDispatchOptions.signal);
|
|
1097
1111
|
if (governanceResult) {
|
|
@@ -1234,17 +1248,36 @@ class TaskExecutor {
|
|
|
1234
1248
|
debug_logs: debugLogs
|
|
1235
1249
|
};
|
|
1236
1250
|
}
|
|
1237
|
-
async handleAsyncResponse(agent, taskId, taskName, params, response, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, persistPausedContinuation = true, serverVersion = "v3", deferredClientContext, requireDeferredSettlementResumeAuthorization = false) {
|
|
1251
|
+
async handleAsyncResponse(agent, taskId, taskName, params, response, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, persistPausedContinuation = true, serverVersion = "v3", deferredClientContext, requireDeferredSettlementResumeAuthorization = false, refinementServedVersion) {
|
|
1238
1252
|
const status = this.responseParser.getStatus(response);
|
|
1239
1253
|
const serverTaskId = this.responseParser.getTaskId(response);
|
|
1240
1254
|
const task = this.activeTasks.get(taskId);
|
|
1241
1255
|
if (task && serverTaskId) task.serverTaskId = serverTaskId;
|
|
1242
1256
|
switch (status) {
|
|
1243
1257
|
case ADCP_STATUS.COMPLETED:
|
|
1244
|
-
const completedData = this.extractResponseData(
|
|
1258
|
+
const completedData = this.extractResponseData(
|
|
1259
|
+
response,
|
|
1260
|
+
debugLogs,
|
|
1261
|
+
taskName,
|
|
1262
|
+
serverVersion,
|
|
1263
|
+
options.negotiatedAdcpVersion
|
|
1264
|
+
);
|
|
1245
1265
|
if (!deferTerminalTaskStatus) this.updateTaskStatus(taskId, "completed", completedData);
|
|
1246
|
-
const operationSuccess = this.isOperationSuccess(
|
|
1247
|
-
|
|
1266
|
+
const operationSuccess = this.isOperationSuccess(
|
|
1267
|
+
completedData,
|
|
1268
|
+
taskName,
|
|
1269
|
+
serverVersion,
|
|
1270
|
+
options.negotiatedAdcpVersion
|
|
1271
|
+
);
|
|
1272
|
+
const validationResult = this.validateResponseSchema(
|
|
1273
|
+
completedData,
|
|
1274
|
+
taskName,
|
|
1275
|
+
debugLogs,
|
|
1276
|
+
serverVersion,
|
|
1277
|
+
params,
|
|
1278
|
+
refinementServedVersion,
|
|
1279
|
+
options.negotiatedAdcpVersion
|
|
1280
|
+
);
|
|
1248
1281
|
const finalSuccess = operationSuccess && validationResult.valid;
|
|
1249
1282
|
const finalError = !finalSuccess ? validationResult.errors.length > 0 ? `Schema validation failed: ${validationResult.errors.join("; ")}` : this.extractOperationError(completedData) : void 0;
|
|
1250
1283
|
if (finalSuccess) {
|
|
@@ -1329,12 +1362,19 @@ class TaskExecutor {
|
|
|
1329
1362
|
persistPausedContinuation,
|
|
1330
1363
|
serverVersion,
|
|
1331
1364
|
deferredClientContext,
|
|
1332
|
-
requireDeferredSettlementResumeAuthorization
|
|
1365
|
+
requireDeferredSettlementResumeAuthorization,
|
|
1366
|
+
refinementServedVersion
|
|
1333
1367
|
);
|
|
1334
1368
|
case ADCP_STATUS.FAILED:
|
|
1335
1369
|
case ADCP_STATUS.REJECTED:
|
|
1336
1370
|
case ADCP_STATUS.CANCELED: {
|
|
1337
|
-
const failedData = this.extractResponseData(
|
|
1371
|
+
const failedData = this.extractResponseData(
|
|
1372
|
+
response,
|
|
1373
|
+
debugLogs,
|
|
1374
|
+
taskName,
|
|
1375
|
+
serverVersion,
|
|
1376
|
+
options.negotiatedAdcpVersion
|
|
1377
|
+
);
|
|
1338
1378
|
const failedPayload = response?.structuredContent === void 0 && response?.content === void 0 && response?.result === void 0 && response?.data != null && typeof response.data === "object" ? response.data : failedData;
|
|
1339
1379
|
const adcpErrorInfo = extractAdcpErrorInfo(failedPayload);
|
|
1340
1380
|
const hasStructuredError = !!adcpErrorInfo;
|
|
@@ -1362,10 +1402,29 @@ class TaskExecutor {
|
|
|
1362
1402
|
};
|
|
1363
1403
|
}
|
|
1364
1404
|
default:
|
|
1365
|
-
const defaultData = this.extractResponseData(
|
|
1405
|
+
const defaultData = this.extractResponseData(
|
|
1406
|
+
response,
|
|
1407
|
+
debugLogs,
|
|
1408
|
+
taskName,
|
|
1409
|
+
serverVersion,
|
|
1410
|
+
options.negotiatedAdcpVersion
|
|
1411
|
+
);
|
|
1366
1412
|
if (defaultData && (defaultData !== response || response.structuredContent || response.result || response.data)) {
|
|
1367
|
-
const defaultSuccess = this.isOperationSuccess(
|
|
1368
|
-
|
|
1413
|
+
const defaultSuccess = this.isOperationSuccess(
|
|
1414
|
+
defaultData,
|
|
1415
|
+
taskName,
|
|
1416
|
+
serverVersion,
|
|
1417
|
+
options.negotiatedAdcpVersion
|
|
1418
|
+
);
|
|
1419
|
+
const defaultValidation = this.validateResponseSchema(
|
|
1420
|
+
defaultData,
|
|
1421
|
+
taskName,
|
|
1422
|
+
debugLogs,
|
|
1423
|
+
serverVersion,
|
|
1424
|
+
params,
|
|
1425
|
+
refinementServedVersion,
|
|
1426
|
+
options.negotiatedAdcpVersion
|
|
1427
|
+
);
|
|
1369
1428
|
const defaultFinalSuccess = defaultSuccess && defaultValidation.valid;
|
|
1370
1429
|
const defaultFinalError = !defaultFinalSuccess ? defaultValidation.errors.length > 0 ? `Schema validation failed: ${defaultValidation.errors.join("; ")}` : this.extractOperationError(defaultData) : void 0;
|
|
1371
1430
|
if (defaultFinalSuccess) {
|
|
@@ -1415,7 +1474,7 @@ class TaskExecutor {
|
|
|
1415
1474
|
*
|
|
1416
1475
|
* @internal Exposed for testing purposes
|
|
1417
1476
|
*/
|
|
1418
|
-
extractResponseData(response, debugLogs, toolName, serverVersion) {
|
|
1477
|
+
extractResponseData(response, debugLogs, toolName, serverVersion, negotiatedAdcpVersion) {
|
|
1419
1478
|
const a2aState = response?.result?.status?.state;
|
|
1420
1479
|
if (a2aState === "input-required" || a2aState === "auth-required") {
|
|
1421
1480
|
const statusParts = response?.result?.status?.message?.parts;
|
|
@@ -1456,7 +1515,7 @@ class TaskExecutor {
|
|
|
1456
1515
|
}
|
|
1457
1516
|
const unwrapped = unwrapProtocolResponse(response, toolName, void 0, {
|
|
1458
1517
|
filterInvalidProducts: this.config.filterInvalidProducts,
|
|
1459
|
-
responseAdcpVersion: this.effectiveResponseAdcpVersion(serverVersion)
|
|
1518
|
+
responseAdcpVersion: this.effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion)
|
|
1460
1519
|
});
|
|
1461
1520
|
if (response?.structuredContent) {
|
|
1462
1521
|
this.logDebug(debugLogs, "info", "Successfully extracted MCP data", {
|
|
@@ -1487,8 +1546,12 @@ class TaskExecutor {
|
|
|
1487
1546
|
* Check if extracted response data represents a successful operation.
|
|
1488
1547
|
* Handles singular `error`, plural `errors` (AdCP schema), and `success: false`.
|
|
1489
1548
|
*/
|
|
1490
|
-
isOperationSuccess(data, taskName, serverVersion) {
|
|
1491
|
-
return isAdcpOperationSuccess(
|
|
1549
|
+
isOperationSuccess(data, taskName, serverVersion, negotiatedAdcpVersion) {
|
|
1550
|
+
return isAdcpOperationSuccess(
|
|
1551
|
+
data,
|
|
1552
|
+
taskName,
|
|
1553
|
+
this.effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion)
|
|
1554
|
+
);
|
|
1492
1555
|
}
|
|
1493
1556
|
/**
|
|
1494
1557
|
* Extract a human-readable error message from response data.
|
|
@@ -1519,7 +1582,13 @@ class TaskExecutor {
|
|
|
1519
1582
|
* Handle 'working' status - return as valid intermediate state
|
|
1520
1583
|
*/
|
|
1521
1584
|
async waitForWorkingCompletion(agent, taskId, taskName, params, initialResponse, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), serverVersion = "v3") {
|
|
1522
|
-
const partialData = this.extractResponseData(
|
|
1585
|
+
const partialData = this.extractResponseData(
|
|
1586
|
+
initialResponse,
|
|
1587
|
+
debugLogs,
|
|
1588
|
+
taskName,
|
|
1589
|
+
serverVersion,
|
|
1590
|
+
options.negotiatedAdcpVersion
|
|
1591
|
+
);
|
|
1523
1592
|
const metadata = this.buildMetadata({
|
|
1524
1593
|
taskId,
|
|
1525
1594
|
taskName,
|
|
@@ -1543,7 +1612,13 @@ class TaskExecutor {
|
|
|
1543
1612
|
* Set up submitted task with webhook
|
|
1544
1613
|
*/
|
|
1545
1614
|
async setupSubmittedTask(agent, taskId, taskName, response, messages, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, serverVersion = "v3") {
|
|
1546
|
-
const partialData = this.extractResponseData(
|
|
1615
|
+
const partialData = this.extractResponseData(
|
|
1616
|
+
response,
|
|
1617
|
+
debugLogs,
|
|
1618
|
+
taskName,
|
|
1619
|
+
serverVersion,
|
|
1620
|
+
options.negotiatedAdcpVersion
|
|
1621
|
+
);
|
|
1547
1622
|
let webhookUrl = response.webhookUrl;
|
|
1548
1623
|
if (!webhookUrl && this.config.webhookManager) {
|
|
1549
1624
|
webhookUrl = this.config.webhookManager.generateUrl(taskId);
|
|
@@ -1979,7 +2054,7 @@ class TaskExecutor {
|
|
|
1979
2054
|
* This is common for HITL (human-in-the-loop) workflows where the agent has already processed
|
|
1980
2055
|
* the request and is just signaling that async approval may be needed.
|
|
1981
2056
|
*/
|
|
1982
|
-
async handleInputRequired(agent, taskId, taskName, params, response, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, pauseStatus = "input-required", persistPausedContinuation = true, serverVersion = "v3", deferredClientContext, requireDeferredSettlementResumeAuthorization = false) {
|
|
2057
|
+
async handleInputRequired(agent, taskId, taskName, params, response, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, pauseStatus = "input-required", persistPausedContinuation = true, serverVersion = "v3", deferredClientContext, requireDeferredSettlementResumeAuthorization = false, refinementServedVersion) {
|
|
1983
2058
|
const inputRequest = this.responseParser.parseInputRequest(response);
|
|
1984
2059
|
const serverContextId = this.responseParser.getContextId(response) ?? response.contextId;
|
|
1985
2060
|
const a2aTaskId = this.responseParser.getA2AContinuationTaskId(response);
|
|
@@ -1987,7 +2062,13 @@ class TaskExecutor {
|
|
|
1987
2062
|
const operationRoutedContinuation = deferTerminalTaskStatus || directContinuationRecovery;
|
|
1988
2063
|
const settlementServerTaskId = operationRoutedContinuation ? this.responseParser.getTaskId(response) : void 0;
|
|
1989
2064
|
if (agent.protocol === "mcp" || !a2aTaskId) {
|
|
1990
|
-
const partialData = this.extractResponseData(
|
|
2065
|
+
const partialData = this.extractResponseData(
|
|
2066
|
+
response,
|
|
2067
|
+
debugLogs,
|
|
2068
|
+
taskName,
|
|
2069
|
+
serverVersion,
|
|
2070
|
+
options.negotiatedAdcpVersion
|
|
2071
|
+
);
|
|
1991
2072
|
const metadata = this.buildMetadata({
|
|
1992
2073
|
taskId,
|
|
1993
2074
|
taskName,
|
|
@@ -2008,7 +2089,13 @@ class TaskExecutor {
|
|
|
2008
2089
|
};
|
|
2009
2090
|
}
|
|
2010
2091
|
if (!inputHandler) {
|
|
2011
|
-
const partialData = this.extractResponseData(
|
|
2092
|
+
const partialData = this.extractResponseData(
|
|
2093
|
+
response,
|
|
2094
|
+
debugLogs,
|
|
2095
|
+
taskName,
|
|
2096
|
+
serverVersion,
|
|
2097
|
+
options.negotiatedAdcpVersion
|
|
2098
|
+
);
|
|
2012
2099
|
const metadata = this.buildMetadata({
|
|
2013
2100
|
taskId,
|
|
2014
2101
|
taskName,
|
|
@@ -2035,8 +2122,12 @@ class TaskExecutor {
|
|
|
2035
2122
|
a2aTaskId,
|
|
2036
2123
|
serverVersion,
|
|
2037
2124
|
...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
|
|
2125
|
+
...options.negotiatedAdcpVersion !== void 0 && {
|
|
2126
|
+
negotiatedAdcpVersion: options.negotiatedAdcpVersion
|
|
2127
|
+
},
|
|
2038
2128
|
...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
|
|
2039
2129
|
serverVersionSynthetic: this.activeTasks.get(taskId)?.serverVersionSynthetic,
|
|
2130
|
+
...refinementServedVersion !== void 0 && { refinementServedVersion },
|
|
2040
2131
|
agentId: agent.id,
|
|
2041
2132
|
taskName,
|
|
2042
2133
|
params: durableDeferredSnapshot(params),
|
|
@@ -2101,7 +2192,8 @@ class TaskExecutor {
|
|
|
2101
2192
|
persistPausedContinuation,
|
|
2102
2193
|
serverVersion,
|
|
2103
2194
|
deferredClientContext,
|
|
2104
|
-
requireDeferredSettlementResumeAuthorization
|
|
2195
|
+
requireDeferredSettlementResumeAuthorization,
|
|
2196
|
+
refinementServedVersion
|
|
2105
2197
|
);
|
|
2106
2198
|
};
|
|
2107
2199
|
const deferred = {
|
|
@@ -2177,8 +2269,12 @@ class TaskExecutor {
|
|
|
2177
2269
|
a2aTaskId,
|
|
2178
2270
|
serverVersion,
|
|
2179
2271
|
...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
|
|
2272
|
+
...options.negotiatedAdcpVersion !== void 0 && {
|
|
2273
|
+
negotiatedAdcpVersion: options.negotiatedAdcpVersion
|
|
2274
|
+
},
|
|
2180
2275
|
...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
|
|
2181
2276
|
serverVersionSynthetic: this.activeTasks.get(taskId)?.serverVersionSynthetic,
|
|
2277
|
+
...refinementServedVersion !== void 0 && { refinementServedVersion },
|
|
2182
2278
|
agentId: agent.id,
|
|
2183
2279
|
taskName,
|
|
2184
2280
|
params: durableDeferredSnapshot(params),
|
|
@@ -2244,7 +2340,8 @@ class TaskExecutor {
|
|
|
2244
2340
|
persistPausedContinuation,
|
|
2245
2341
|
serverVersion,
|
|
2246
2342
|
deferredClientContext,
|
|
2247
|
-
requireDeferredSettlementResumeAuthorization
|
|
2343
|
+
requireDeferredSettlementResumeAuthorization,
|
|
2344
|
+
refinementServedVersion
|
|
2248
2345
|
);
|
|
2249
2346
|
};
|
|
2250
2347
|
const deferred = {
|
|
@@ -2295,7 +2392,8 @@ class TaskExecutor {
|
|
|
2295
2392
|
persistPausedContinuation,
|
|
2296
2393
|
serverVersion,
|
|
2297
2394
|
deferredClientContext,
|
|
2298
|
-
requireDeferredSettlementResumeAuthorization
|
|
2395
|
+
requireDeferredSettlementResumeAuthorization,
|
|
2396
|
+
refinementServedVersion
|
|
2299
2397
|
);
|
|
2300
2398
|
}
|
|
2301
2399
|
/**
|
|
@@ -2511,7 +2609,12 @@ class TaskExecutor {
|
|
|
2511
2609
|
});
|
|
2512
2610
|
}
|
|
2513
2611
|
if (status.status === ADCP_STATUS.COMPLETED) {
|
|
2514
|
-
const pollSuccess = this.isOperationSuccess(
|
|
2612
|
+
const pollSuccess = this.isOperationSuccess(
|
|
2613
|
+
status.result,
|
|
2614
|
+
status.taskType,
|
|
2615
|
+
serverVersion,
|
|
2616
|
+
metadataTaskId ? this.activeTasks.get(metadataTaskId)?.options.negotiatedAdcpVersion : void 0
|
|
2617
|
+
);
|
|
2515
2618
|
if (pollSuccess) {
|
|
2516
2619
|
return markAuthoritativePolledTerminal(
|
|
2517
2620
|
attachMatch({
|
|
@@ -3066,6 +3169,7 @@ class TaskExecutor {
|
|
|
3066
3169
|
state.messages,
|
|
3067
3170
|
{
|
|
3068
3171
|
...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
|
|
3172
|
+
...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
|
|
3069
3173
|
...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope }
|
|
3070
3174
|
},
|
|
3071
3175
|
[],
|
|
@@ -3287,6 +3391,7 @@ class TaskExecutor {
|
|
|
3287
3391
|
// No handler for deferred tasks - input was provided by human
|
|
3288
3392
|
{
|
|
3289
3393
|
...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
|
|
3394
|
+
...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
|
|
3290
3395
|
...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope }
|
|
3291
3396
|
},
|
|
3292
3397
|
[],
|
|
@@ -3295,7 +3400,8 @@ class TaskExecutor {
|
|
|
3295
3400
|
false,
|
|
3296
3401
|
state.serverVersion,
|
|
3297
3402
|
state.clientContext,
|
|
3298
|
-
state.settlementResumeAuthorizationRequired === true
|
|
3403
|
+
state.settlementResumeAuthorizationRequired === true,
|
|
3404
|
+
state.refinementServedVersion
|
|
3299
3405
|
);
|
|
3300
3406
|
resumed = attachDeferredServerVersion(resumed, state);
|
|
3301
3407
|
const observedResumedServerTaskId = resumed.metadata.serverTaskId;
|
|
@@ -3321,7 +3427,11 @@ class TaskExecutor {
|
|
|
3321
3427
|
...resumed.metadata.contextId !== void 0 ? { contextId: resumed.metadata.contextId } : state.contextId !== void 0 ? { contextId: state.contextId } : {},
|
|
3322
3428
|
a2aTaskId: nextA2ATaskId,
|
|
3323
3429
|
serverVersion: state.serverVersion,
|
|
3430
|
+
...state.refinementServedVersion !== void 0 && {
|
|
3431
|
+
refinementServedVersion: state.refinementServedVersion
|
|
3432
|
+
},
|
|
3324
3433
|
...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
|
|
3434
|
+
...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
|
|
3325
3435
|
...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope },
|
|
3326
3436
|
...state.serverVersionSynthetic !== void 0 && {
|
|
3327
3437
|
serverVersionSynthetic: state.serverVersionSynthetic
|
|
@@ -4249,7 +4359,7 @@ class TaskExecutor {
|
|
|
4249
4359
|
/**
|
|
4250
4360
|
* Continue a task after receiving input
|
|
4251
4361
|
*/
|
|
4252
|
-
async continueTaskWithInput(agent, taskId, taskName, params, contextId, a2aTaskId, input, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, persistPausedContinuation = true, serverVersion = "v3", deferredClientContext, requireDeferredSettlementResumeAuthorization = false) {
|
|
4362
|
+
async continueTaskWithInput(agent, taskId, taskName, params, contextId, a2aTaskId, input, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, persistPausedContinuation = true, serverVersion = "v3", deferredClientContext, requireDeferredSettlementResumeAuthorization = false, refinementServedVersion) {
|
|
4253
4363
|
const inputSnapshot = structuredClone(input);
|
|
4254
4364
|
if (agent.protocol !== "a2a") {
|
|
4255
4365
|
throw new Error("MCP does not define a standard continuation for a returned input-required task.");
|
|
@@ -4315,7 +4425,8 @@ class TaskExecutor {
|
|
|
4315
4425
|
persistPausedContinuation,
|
|
4316
4426
|
serverVersion,
|
|
4317
4427
|
deferredClientContext,
|
|
4318
|
-
requireDeferredSettlementResumeAuthorization
|
|
4428
|
+
requireDeferredSettlementResumeAuthorization,
|
|
4429
|
+
refinementServedVersion
|
|
4319
4430
|
);
|
|
4320
4431
|
}
|
|
4321
4432
|
/**
|
|
@@ -4507,11 +4618,11 @@ class TaskExecutor {
|
|
|
4507
4618
|
* valid so the caller can continue. Off mode short-circuits before
|
|
4508
4619
|
* AJV runs.
|
|
4509
4620
|
*/
|
|
4510
|
-
validateResponseSchema(response, taskName, debugLogs, serverVersion) {
|
|
4621
|
+
validateResponseSchema(response, taskName, debugLogs, serverVersion, requestParams, refinementServedVersion, negotiatedAdcpVersion) {
|
|
4511
4622
|
const mode = this.responseValidationMode;
|
|
4512
4623
|
const logViolations = this.config.logSchemaViolations !== false;
|
|
4513
4624
|
try {
|
|
4514
|
-
const pinnedValidationVersion = this.responseAdcpVersionForValidation() ?? this.config.adcpVersion ?? ADCP_VERSION;
|
|
4625
|
+
const pinnedValidationVersion = this.responseAdcpVersionForValidation() ?? negotiatedAdcpVersion ?? this.config.adcpVersion ?? ADCP_VERSION;
|
|
4515
4626
|
if (taskName === "get_adcp_capabilities") {
|
|
4516
4627
|
return withServedValidationVersion(
|
|
4517
4628
|
response,
|
|
@@ -4519,6 +4630,46 @@ class TaskExecutor {
|
|
|
4519
4630
|
(validationVersion) => this.validateResponseSchemaAgainst(response, taskName, debugLogs, mode, logViolations, validationVersion)
|
|
4520
4631
|
);
|
|
4521
4632
|
}
|
|
4633
|
+
if (taskName === "refine_proposals" && mode !== "off") {
|
|
4634
|
+
const ceiling = requestParams?.adcp_version ?? toReleasePrecisionVersion(this.config.wireAdcpVersion ?? pinnedValidationVersion);
|
|
4635
|
+
const issues = [];
|
|
4636
|
+
const selected = selectRefinementSchemaVersion(
|
|
4637
|
+
ceiling,
|
|
4638
|
+
response,
|
|
4639
|
+
{
|
|
4640
|
+
adcpVersion: pinnedValidationVersion,
|
|
4641
|
+
servedAdcpVersion: applicableRefinementServedVersion(refinementServedVersion, ceiling)
|
|
4642
|
+
},
|
|
4643
|
+
issues
|
|
4644
|
+
);
|
|
4645
|
+
if (!selected) {
|
|
4646
|
+
const errors = issues.map((issue) => `${issue.path}: ${issue.message}`);
|
|
4647
|
+
if (logViolations) {
|
|
4648
|
+
debugLogs.push({
|
|
4649
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4650
|
+
type: mode === "strict" ? "error" : "warning",
|
|
4651
|
+
message: `Schema validation ${mode === "strict" ? "failed" : "warning"} for ${taskName}: ${errors.join("; ")}`,
|
|
4652
|
+
errors,
|
|
4653
|
+
issues,
|
|
4654
|
+
schemaVersion: pinnedValidationVersion,
|
|
4655
|
+
mode
|
|
4656
|
+
});
|
|
4657
|
+
if (mode === "warn") {
|
|
4658
|
+
console.warn(
|
|
4659
|
+
`Schema validation failed for ${taskName} against AdCP ${pinnedValidationVersion} (non-blocking):`,
|
|
4660
|
+
errors
|
|
4661
|
+
);
|
|
4662
|
+
} else {
|
|
4663
|
+
console.error(
|
|
4664
|
+
`Schema validation failed for ${taskName} against AdCP ${pinnedValidationVersion}:`,
|
|
4665
|
+
errors
|
|
4666
|
+
);
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4669
|
+
return { valid: mode !== "strict", errors: mode === "strict" ? errors : [] };
|
|
4670
|
+
}
|
|
4671
|
+
return this.validateResponseSchemaAgainst(response, taskName, debugLogs, mode, logViolations, selected);
|
|
4672
|
+
}
|
|
4522
4673
|
return this.validateResponseSchemaAgainst(
|
|
4523
4674
|
response,
|
|
4524
4675
|
taskName,
|
|
@@ -4573,8 +4724,8 @@ class TaskExecutor {
|
|
|
4573
4724
|
if (this.config.versionEnvelope === "major-only") return "3.0";
|
|
4574
4725
|
return void 0;
|
|
4575
4726
|
}
|
|
4576
|
-
effectiveResponseAdcpVersion(serverVersion) {
|
|
4577
|
-
return this.responseAdcpVersionForValidation() ?? this.config.adcpVersion ?? ADCP_VERSION;
|
|
4727
|
+
effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion) {
|
|
4728
|
+
return this.responseAdcpVersionForValidation() ?? negotiatedAdcpVersion ?? this.config.adcpVersion ?? ADCP_VERSION;
|
|
4578
4729
|
}
|
|
4579
4730
|
/**
|
|
4580
4731
|
* Update task status and emit events
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locating and rewriting account natural keys inside a request, for the
|
|
3
|
+
* client's `accountIdentityDowngrade: 'reduce'` bookkeeping.
|
|
4
|
+
*
|
|
5
|
+
* When a request reaches a seller on an older release, its account keys can
|
|
6
|
+
* lose fields the older release cannot express (AdCP 3.2's `operator_unit`,
|
|
7
|
+
* `currency`, `timezone` and `brand.countries`). The client records which
|
|
8
|
+
* reduced key each buyer key reached the seller with, refuses a second buyer
|
|
9
|
+
* key that would land on the same seller account, and keeps addressing the
|
|
10
|
+
* account by its reduced key after the seller upgrades, until the buyer moves
|
|
11
|
+
* it to the full key.
|
|
12
|
+
*/
|
|
13
|
+
import type { AccountReference } from '../types/index.mjs';
|
|
14
|
+
type Path = ReadonlyArray<string | number>;
|
|
15
|
+
/** The natural-key projection of an account reference or `sync_accounts` row. */
|
|
16
|
+
export declare function naturalAccountKey(value: unknown): AccountReference | undefined;
|
|
17
|
+
export interface AccountKeySite {
|
|
18
|
+
path: Path;
|
|
19
|
+
key: AccountReference;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Natural account keys in a request: every `account` object and every entry
|
|
23
|
+
* of an `accounts` array (sync_accounts rows, list filters), at any depth.
|
|
24
|
+
*/
|
|
25
|
+
export declare function accountKeySites(params: unknown): AccountKeySite[];
|
|
26
|
+
export declare function valueAt(root: unknown, path: Path): unknown;
|
|
27
|
+
/**
|
|
28
|
+
* Return `root` with the account key at `path` replaced by `reduced`: the
|
|
29
|
+
* reducible fields `reduced` lacks are removed and the rest of the object
|
|
30
|
+
* (billing, settings) is kept. Unchanged branches keep their identity.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withReducedKeyAt<T>(root: T, path: Path, reduced: AccountReference): T;
|
|
33
|
+
/** Fields present on `full` but absent from `reduced`, as account-relative paths. */
|
|
34
|
+
export declare function reducedFields(full: AccountReference, reduced: AccountReference): string[];
|
|
35
|
+
export declare function sameAccountKey(left: AccountReference, right: AccountReference): boolean;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locating and rewriting account natural keys inside a request, for the
|
|
3
|
+
* client's `accountIdentityDowngrade: 'reduce'` bookkeeping.
|
|
4
|
+
*
|
|
5
|
+
* When a request reaches a seller on an older release, its account keys can
|
|
6
|
+
* lose fields the older release cannot express (AdCP 3.2's `operator_unit`,
|
|
7
|
+
* `currency`, `timezone` and `brand.countries`). The client records which
|
|
8
|
+
* reduced key each buyer key reached the seller with, refuses a second buyer
|
|
9
|
+
* key that would land on the same seller account, and keeps addressing the
|
|
10
|
+
* account by its reduced key after the seller upgrades, until the buyer moves
|
|
11
|
+
* it to the full key.
|
|
12
|
+
*/
|
|
13
|
+
import type { AccountReference } from '../types';
|
|
14
|
+
type Path = ReadonlyArray<string | number>;
|
|
15
|
+
/** The natural-key projection of an account reference or `sync_accounts` row. */
|
|
16
|
+
export declare function naturalAccountKey(value: unknown): AccountReference | undefined;
|
|
17
|
+
export interface AccountKeySite {
|
|
18
|
+
path: Path;
|
|
19
|
+
key: AccountReference;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Natural account keys in a request: every `account` object and every entry
|
|
23
|
+
* of an `accounts` array (sync_accounts rows, list filters), at any depth.
|
|
24
|
+
*/
|
|
25
|
+
export declare function accountKeySites(params: unknown): AccountKeySite[];
|
|
26
|
+
export declare function valueAt(root: unknown, path: Path): unknown;
|
|
27
|
+
/**
|
|
28
|
+
* Return `root` with the account key at `path` replaced by `reduced`: the
|
|
29
|
+
* reducible fields `reduced` lacks are removed and the rest of the object
|
|
30
|
+
* (billing, settings) is kept. Unchanged branches keep their identity.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withReducedKeyAt<T>(root: T, path: Path, reduced: AccountReference): T;
|
|
33
|
+
/** Fields present on `full` but absent from `reduced`, as account-relative paths. */
|
|
34
|
+
export declare function reducedFields(full: AccountReference, reduced: AccountReference): string[];
|
|
35
|
+
export declare function sameAccountKey(left: AccountReference, right: AccountReference): boolean;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var account_reduction_exports = {};
|
|
20
|
+
__export(account_reduction_exports, {
|
|
21
|
+
accountKeySites: () => accountKeySites,
|
|
22
|
+
naturalAccountKey: () => naturalAccountKey,
|
|
23
|
+
reducedFields: () => reducedFields,
|
|
24
|
+
sameAccountKey: () => sameAccountKey,
|
|
25
|
+
valueAt: () => valueAt,
|
|
26
|
+
withReducedKeyAt: () => withReducedKeyAt
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(account_reduction_exports);
|
|
29
|
+
var import_account_key = require('./account-key.js');
|
|
30
|
+
function isObject(value) {
|
|
31
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
const REDUCIBLE_FIELDS = ["operator_unit", "currency", "timezone"];
|
|
34
|
+
function naturalAccountKey(value) {
|
|
35
|
+
if (!isObject(value) || typeof value.account_id === "string") return void 0;
|
|
36
|
+
const brand = value.brand;
|
|
37
|
+
if (!isObject(brand) || typeof brand.domain !== "string" || typeof value.operator !== "string") return void 0;
|
|
38
|
+
return {
|
|
39
|
+
brand: {
|
|
40
|
+
domain: brand.domain,
|
|
41
|
+
...typeof brand.brand_id === "string" && { brand_id: brand.brand_id },
|
|
42
|
+
...Array.isArray(brand.countries) && { countries: brand.countries }
|
|
43
|
+
},
|
|
44
|
+
operator: value.operator,
|
|
45
|
+
...isObject(value.operator_unit) && { operator_unit: value.operator_unit },
|
|
46
|
+
...typeof value.currency === "string" && { currency: value.currency },
|
|
47
|
+
...typeof value.timezone === "string" && { timezone: value.timezone },
|
|
48
|
+
...typeof value.sandbox === "boolean" && { sandbox: value.sandbox }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function accountKeySites(params) {
|
|
52
|
+
const sites = [];
|
|
53
|
+
const visit = (value, path, depth) => {
|
|
54
|
+
if (depth > 8) return;
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
value.forEach((item, index) => visit(item, [...path, index], depth + 1));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!isObject(value)) return;
|
|
60
|
+
for (const [field, child] of Object.entries(value)) {
|
|
61
|
+
if (field === "account") {
|
|
62
|
+
const key = naturalAccountKey(child);
|
|
63
|
+
if (key) sites.push({ path: [...path, field], key });
|
|
64
|
+
} else if (field === "accounts" && Array.isArray(child)) {
|
|
65
|
+
child.forEach((entry, index) => {
|
|
66
|
+
const key = naturalAccountKey(entry);
|
|
67
|
+
if (key) sites.push({ path: [...path, field, index], key });
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
visit(child, [...path, field], depth + 1);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
visit(params, [], 0);
|
|
74
|
+
return sites;
|
|
75
|
+
}
|
|
76
|
+
function valueAt(root, path) {
|
|
77
|
+
let current = root;
|
|
78
|
+
for (const segment of path) {
|
|
79
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
80
|
+
current = current[segment];
|
|
81
|
+
}
|
|
82
|
+
return current;
|
|
83
|
+
}
|
|
84
|
+
function withReducedKeyAt(root, path, reduced) {
|
|
85
|
+
if (path.length === 0) {
|
|
86
|
+
if (!isObject(root) || "account_id" in reduced) return root;
|
|
87
|
+
const next = { ...root };
|
|
88
|
+
for (const field of REDUCIBLE_FIELDS) {
|
|
89
|
+
if (reduced[field] === void 0) delete next[field];
|
|
90
|
+
}
|
|
91
|
+
if (isObject(next.brand) && reduced.brand.countries === void 0 && "countries" in next.brand) {
|
|
92
|
+
const { countries: _, ...brand } = next.brand;
|
|
93
|
+
next.brand = brand;
|
|
94
|
+
}
|
|
95
|
+
return next;
|
|
96
|
+
}
|
|
97
|
+
const [head, ...rest] = path;
|
|
98
|
+
if (Array.isArray(root) && typeof head === "number") {
|
|
99
|
+
const copy = [...root];
|
|
100
|
+
copy[head] = withReducedKeyAt(copy[head], rest, reduced);
|
|
101
|
+
return copy;
|
|
102
|
+
}
|
|
103
|
+
if (isObject(root) && typeof head === "string") {
|
|
104
|
+
return { ...root, [head]: withReducedKeyAt(root[head], rest, reduced) };
|
|
105
|
+
}
|
|
106
|
+
return root;
|
|
107
|
+
}
|
|
108
|
+
function reducedFields(full, reduced) {
|
|
109
|
+
if ("account_id" in full || "account_id" in reduced) return [];
|
|
110
|
+
const fields = REDUCIBLE_FIELDS.filter(
|
|
111
|
+
(field) => full[field] !== void 0 && reduced[field] === void 0
|
|
112
|
+
);
|
|
113
|
+
if (full.brand.countries !== void 0 && reduced.brand.countries === void 0) fields.push("brand.countries");
|
|
114
|
+
return fields;
|
|
115
|
+
}
|
|
116
|
+
function sameAccountKey(left, right) {
|
|
117
|
+
return (0, import_account_key.accountReferenceKey)(left) === (0, import_account_key.accountReferenceKey)(right);
|
|
118
|
+
}
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
accountKeySites,
|
|
122
|
+
naturalAccountKey,
|
|
123
|
+
reducedFields,
|
|
124
|
+
sameAccountKey,
|
|
125
|
+
valueAt,
|
|
126
|
+
withReducedKeyAt
|
|
127
|
+
});
|