@adcp/sdk 16.3.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.
Files changed (80) hide show
  1. package/dist/lib/adapters/version/3.1/assignments.d.mts +12 -0
  2. package/dist/lib/adapters/version/3.1/assignments.d.ts +12 -0
  3. package/dist/lib/adapters/version/3.1/assignments.js +67 -0
  4. package/dist/lib/adapters/version/3.1/assignments.mjs +43 -0
  5. package/dist/lib/adapters/version/3.1/bidding.d.mts +3 -0
  6. package/dist/lib/adapters/version/3.1/bidding.d.ts +3 -0
  7. package/dist/lib/adapters/version/3.1/bidding.js +115 -0
  8. package/dist/lib/adapters/version/3.1/bidding.mjs +90 -0
  9. package/dist/lib/adapters/version/3.1/delivery.d.mts +7 -0
  10. package/dist/lib/adapters/version/3.1/delivery.d.ts +7 -0
  11. package/dist/lib/adapters/version/3.1/delivery.js +78 -0
  12. package/dist/lib/adapters/version/3.1/delivery.mjs +54 -0
  13. package/dist/lib/adapters/version/3.1/index.d.mts +3 -0
  14. package/dist/lib/adapters/version/3.1/index.d.ts +3 -0
  15. package/dist/lib/adapters/version/3.1/index.js +36 -0
  16. package/dist/lib/adapters/version/3.1/index.mjs +12 -0
  17. package/dist/lib/adapters/version/index.d.mts +59 -7
  18. package/dist/lib/adapters/version/index.d.ts +59 -7
  19. package/dist/lib/adapters/version/index.js +51 -2
  20. package/dist/lib/adapters/version/index.mjs +49 -1
  21. package/dist/lib/adapters/version/negotiate.d.mts +71 -0
  22. package/dist/lib/adapters/version/negotiate.d.ts +71 -0
  23. package/dist/lib/adapters/version/negotiate.js +101 -0
  24. package/dist/lib/adapters/version/negotiate.mjs +73 -0
  25. package/dist/lib/adapters/version/schema-projection.d.mts +33 -0
  26. package/dist/lib/adapters/version/schema-projection.d.ts +33 -0
  27. package/dist/lib/adapters/version/schema-projection.js +294 -0
  28. package/dist/lib/adapters/version/schema-projection.mjs +269 -0
  29. package/dist/lib/adapters/version/translate.d.mts +122 -0
  30. package/dist/lib/adapters/version/translate.d.ts +122 -0
  31. package/dist/lib/adapters/version/translate.js +169 -0
  32. package/dist/lib/adapters/version/translate.mjs +141 -0
  33. package/dist/lib/adapters/version/types.d.mts +51 -10
  34. package/dist/lib/adapters/version/types.d.ts +51 -10
  35. package/dist/lib/core/AgentClient.d.mts +1 -1
  36. package/dist/lib/core/AgentClient.d.ts +1 -1
  37. package/dist/lib/core/ConversationTypes.d.mts +7 -0
  38. package/dist/lib/core/ConversationTypes.d.ts +7 -0
  39. package/dist/lib/core/SingleAgentClient.d.mts +82 -0
  40. package/dist/lib/core/SingleAgentClient.d.ts +82 -0
  41. package/dist/lib/core/SingleAgentClient.js +323 -15
  42. package/dist/lib/core/SingleAgentClient.mjs +337 -17
  43. package/dist/lib/core/TaskExecutor.d.mts +1 -1
  44. package/dist/lib/core/TaskExecutor.d.ts +1 -1
  45. package/dist/lib/core/TaskExecutor.js +97 -21
  46. package/dist/lib/core/TaskExecutor.mjs +97 -21
  47. package/dist/lib/core/account-reduction.d.mts +36 -0
  48. package/dist/lib/core/account-reduction.d.ts +36 -0
  49. package/dist/lib/core/account-reduction.js +127 -0
  50. package/dist/lib/core/account-reduction.mjs +98 -0
  51. package/dist/lib/core/buyer-account-registry.d.mts +52 -0
  52. package/dist/lib/core/buyer-account-registry.d.ts +52 -0
  53. package/dist/lib/core/buyer-account-registry.js +142 -6
  54. package/dist/lib/core/buyer-account-registry.mjs +142 -6
  55. package/dist/lib/media-buy/action-contracts.js +4 -4
  56. package/dist/lib/media-buy/action-contracts.mjs +4 -4
  57. package/dist/lib/media-buy/action-types.d.mts +3 -2
  58. package/dist/lib/media-buy/action-types.d.ts +3 -2
  59. package/dist/lib/media-buy/update-fields.generated.d.mts +3 -2
  60. package/dist/lib/media-buy/update-fields.generated.d.ts +3 -2
  61. package/dist/lib/registry/types.generated.d.mts +1 -1
  62. package/dist/lib/registry/types.generated.d.ts +1 -1
  63. package/dist/lib/server/create-adcp-server.d.mts +21 -0
  64. package/dist/lib/server/create-adcp-server.d.ts +21 -0
  65. package/dist/lib/server/create-adcp-server.js +97 -15
  66. package/dist/lib/server/create-adcp-server.mjs +83 -1
  67. package/dist/lib/server/index.d.mts +1 -1
  68. package/dist/lib/server/index.d.ts +1 -1
  69. package/dist/lib/storage/interfaces.d.mts +2 -0
  70. package/dist/lib/storage/interfaces.d.ts +2 -0
  71. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  72. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  73. package/dist/lib/version.d.mts +3 -3
  74. package/dist/lib/version.d.ts +3 -3
  75. package/dist/lib/version.js +3 -3
  76. package/dist/lib/version.mjs +3 -3
  77. package/docs/TYPE-SUMMARY.md +2 -2
  78. package/docs/llms.txt +3 -3
  79. package/docs/migration-14.x-rc-worksheet.md +4 -4
  80. package/package.json +1 -1
@@ -689,7 +689,11 @@ class TaskExecutor {
689
689
  * adaptation runs, so the validator sees the same object the caller wrote.
690
690
  * Throws in strict, logs to `debugLogs` in warn, no-ops in off.
691
691
  */
692
- validateRequest(taskName, params, debugLogs) {
692
+ validateRequest(taskName, params, debugLogs, adcpVersion) {
693
+ if (adcpVersion !== void 0) {
694
+ (0, import_client_hooks.validateOutgoingRequest)(taskName, params, this.requestValidationMode, debugLogs, adcpVersion);
695
+ return;
696
+ }
693
697
  if (this.config.experimentalIdentity33?.() && this.requestValidationMode !== "off") {
694
698
  const outcome = validateIdentity33Payload(taskName, "request", params, this.config.adcpVersion);
695
699
  if (!outcome.valid) {
@@ -1273,16 +1277,28 @@ class TaskExecutor {
1273
1277
  if (task && serverTaskId) task.serverTaskId = serverTaskId;
1274
1278
  switch (status) {
1275
1279
  case import_ProtocolResponseParser.ADCP_STATUS.COMPLETED:
1276
- const completedData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1280
+ const completedData = this.extractResponseData(
1281
+ response,
1282
+ debugLogs,
1283
+ taskName,
1284
+ serverVersion,
1285
+ options.negotiatedAdcpVersion
1286
+ );
1277
1287
  if (!deferTerminalTaskStatus) this.updateTaskStatus(taskId, "completed", completedData);
1278
- const operationSuccess = this.isOperationSuccess(completedData, taskName, serverVersion);
1288
+ const operationSuccess = this.isOperationSuccess(
1289
+ completedData,
1290
+ taskName,
1291
+ serverVersion,
1292
+ options.negotiatedAdcpVersion
1293
+ );
1279
1294
  const validationResult = this.validateResponseSchema(
1280
1295
  completedData,
1281
1296
  taskName,
1282
1297
  debugLogs,
1283
1298
  serverVersion,
1284
1299
  params,
1285
- refinementServedVersion
1300
+ refinementServedVersion,
1301
+ options.negotiatedAdcpVersion
1286
1302
  );
1287
1303
  const finalSuccess = operationSuccess && validationResult.valid;
1288
1304
  const finalError = !finalSuccess ? validationResult.errors.length > 0 ? `Schema validation failed: ${validationResult.errors.join("; ")}` : this.extractOperationError(completedData) : void 0;
@@ -1374,7 +1390,13 @@ class TaskExecutor {
1374
1390
  case import_ProtocolResponseParser.ADCP_STATUS.FAILED:
1375
1391
  case import_ProtocolResponseParser.ADCP_STATUS.REJECTED:
1376
1392
  case import_ProtocolResponseParser.ADCP_STATUS.CANCELED: {
1377
- const failedData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1393
+ const failedData = this.extractResponseData(
1394
+ response,
1395
+ debugLogs,
1396
+ taskName,
1397
+ serverVersion,
1398
+ options.negotiatedAdcpVersion
1399
+ );
1378
1400
  const failedPayload = response?.structuredContent === void 0 && response?.content === void 0 && response?.result === void 0 && response?.data != null && typeof response.data === "object" ? response.data : failedData;
1379
1401
  const adcpErrorInfo = (0, import_error_extraction.extractAdcpErrorInfo)(failedPayload);
1380
1402
  const hasStructuredError = !!adcpErrorInfo;
@@ -1402,16 +1424,28 @@ class TaskExecutor {
1402
1424
  };
1403
1425
  }
1404
1426
  default:
1405
- const defaultData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1427
+ const defaultData = this.extractResponseData(
1428
+ response,
1429
+ debugLogs,
1430
+ taskName,
1431
+ serverVersion,
1432
+ options.negotiatedAdcpVersion
1433
+ );
1406
1434
  if (defaultData && (defaultData !== response || response.structuredContent || response.result || response.data)) {
1407
- const defaultSuccess = this.isOperationSuccess(defaultData, taskName, serverVersion);
1435
+ const defaultSuccess = this.isOperationSuccess(
1436
+ defaultData,
1437
+ taskName,
1438
+ serverVersion,
1439
+ options.negotiatedAdcpVersion
1440
+ );
1408
1441
  const defaultValidation = this.validateResponseSchema(
1409
1442
  defaultData,
1410
1443
  taskName,
1411
1444
  debugLogs,
1412
1445
  serverVersion,
1413
1446
  params,
1414
- refinementServedVersion
1447
+ refinementServedVersion,
1448
+ options.negotiatedAdcpVersion
1415
1449
  );
1416
1450
  const defaultFinalSuccess = defaultSuccess && defaultValidation.valid;
1417
1451
  const defaultFinalError = !defaultFinalSuccess ? defaultValidation.errors.length > 0 ? `Schema validation failed: ${defaultValidation.errors.join("; ")}` : this.extractOperationError(defaultData) : void 0;
@@ -1462,7 +1496,7 @@ class TaskExecutor {
1462
1496
  *
1463
1497
  * @internal Exposed for testing purposes
1464
1498
  */
1465
- extractResponseData(response, debugLogs, toolName, serverVersion) {
1499
+ extractResponseData(response, debugLogs, toolName, serverVersion, negotiatedAdcpVersion) {
1466
1500
  const a2aState = response?.result?.status?.state;
1467
1501
  if (a2aState === "input-required" || a2aState === "auth-required") {
1468
1502
  const statusParts = response?.result?.status?.message?.parts;
@@ -1503,7 +1537,7 @@ class TaskExecutor {
1503
1537
  }
1504
1538
  const unwrapped = (0, import_response_unwrapper.unwrapProtocolResponse)(response, toolName, void 0, {
1505
1539
  filterInvalidProducts: this.config.filterInvalidProducts,
1506
- responseAdcpVersion: this.effectiveResponseAdcpVersion(serverVersion)
1540
+ responseAdcpVersion: this.effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion)
1507
1541
  });
1508
1542
  if (response?.structuredContent) {
1509
1543
  this.logDebug(debugLogs, "info", "Successfully extracted MCP data", {
@@ -1534,8 +1568,12 @@ class TaskExecutor {
1534
1568
  * Check if extracted response data represents a successful operation.
1535
1569
  * Handles singular `error`, plural `errors` (AdCP schema), and `success: false`.
1536
1570
  */
1537
- isOperationSuccess(data, taskName, serverVersion) {
1538
- return (0, import_response_unwrapper.isAdcpOperationSuccess)(data, taskName, this.effectiveResponseAdcpVersion(serverVersion));
1571
+ isOperationSuccess(data, taskName, serverVersion, negotiatedAdcpVersion) {
1572
+ return (0, import_response_unwrapper.isAdcpOperationSuccess)(
1573
+ data,
1574
+ taskName,
1575
+ this.effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion)
1576
+ );
1539
1577
  }
1540
1578
  /**
1541
1579
  * Extract a human-readable error message from response data.
@@ -1566,7 +1604,13 @@ class TaskExecutor {
1566
1604
  * Handle 'working' status - return as valid intermediate state
1567
1605
  */
1568
1606
  async waitForWorkingCompletion(agent, taskId, taskName, params, initialResponse, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), serverVersion = "v3") {
1569
- const partialData = this.extractResponseData(initialResponse, debugLogs, taskName, serverVersion);
1607
+ const partialData = this.extractResponseData(
1608
+ initialResponse,
1609
+ debugLogs,
1610
+ taskName,
1611
+ serverVersion,
1612
+ options.negotiatedAdcpVersion
1613
+ );
1570
1614
  const metadata = this.buildMetadata({
1571
1615
  taskId,
1572
1616
  taskName,
@@ -1590,7 +1634,13 @@ class TaskExecutor {
1590
1634
  * Set up submitted task with webhook
1591
1635
  */
1592
1636
  async setupSubmittedTask(agent, taskId, taskName, response, messages, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, serverVersion = "v3") {
1593
- const partialData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1637
+ const partialData = this.extractResponseData(
1638
+ response,
1639
+ debugLogs,
1640
+ taskName,
1641
+ serverVersion,
1642
+ options.negotiatedAdcpVersion
1643
+ );
1594
1644
  let webhookUrl = response.webhookUrl;
1595
1645
  if (!webhookUrl && this.config.webhookManager) {
1596
1646
  webhookUrl = this.config.webhookManager.generateUrl(taskId);
@@ -2034,7 +2084,13 @@ class TaskExecutor {
2034
2084
  const operationRoutedContinuation = deferTerminalTaskStatus || directContinuationRecovery;
2035
2085
  const settlementServerTaskId = operationRoutedContinuation ? this.responseParser.getTaskId(response) : void 0;
2036
2086
  if (agent.protocol === "mcp" || !a2aTaskId) {
2037
- const partialData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
2087
+ const partialData = this.extractResponseData(
2088
+ response,
2089
+ debugLogs,
2090
+ taskName,
2091
+ serverVersion,
2092
+ options.negotiatedAdcpVersion
2093
+ );
2038
2094
  const metadata = this.buildMetadata({
2039
2095
  taskId,
2040
2096
  taskName,
@@ -2055,7 +2111,13 @@ class TaskExecutor {
2055
2111
  };
2056
2112
  }
2057
2113
  if (!inputHandler) {
2058
- const partialData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
2114
+ const partialData = this.extractResponseData(
2115
+ response,
2116
+ debugLogs,
2117
+ taskName,
2118
+ serverVersion,
2119
+ options.negotiatedAdcpVersion
2120
+ );
2059
2121
  const metadata = this.buildMetadata({
2060
2122
  taskId,
2061
2123
  taskName,
@@ -2082,6 +2144,9 @@ class TaskExecutor {
2082
2144
  a2aTaskId,
2083
2145
  serverVersion,
2084
2146
  ...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
2147
+ ...options.negotiatedAdcpVersion !== void 0 && {
2148
+ negotiatedAdcpVersion: options.negotiatedAdcpVersion
2149
+ },
2085
2150
  ...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
2086
2151
  serverVersionSynthetic: this.activeTasks.get(taskId)?.serverVersionSynthetic,
2087
2152
  ...refinementServedVersion !== void 0 && { refinementServedVersion },
@@ -2226,6 +2291,9 @@ class TaskExecutor {
2226
2291
  a2aTaskId,
2227
2292
  serverVersion,
2228
2293
  ...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
2294
+ ...options.negotiatedAdcpVersion !== void 0 && {
2295
+ negotiatedAdcpVersion: options.negotiatedAdcpVersion
2296
+ },
2229
2297
  ...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
2230
2298
  serverVersionSynthetic: this.activeTasks.get(taskId)?.serverVersionSynthetic,
2231
2299
  ...refinementServedVersion !== void 0 && { refinementServedVersion },
@@ -2563,7 +2631,12 @@ class TaskExecutor {
2563
2631
  });
2564
2632
  }
2565
2633
  if (status.status === import_ProtocolResponseParser.ADCP_STATUS.COMPLETED) {
2566
- const pollSuccess = this.isOperationSuccess(status.result, status.taskType, serverVersion);
2634
+ const pollSuccess = this.isOperationSuccess(
2635
+ status.result,
2636
+ status.taskType,
2637
+ serverVersion,
2638
+ metadataTaskId ? this.activeTasks.get(metadataTaskId)?.options.negotiatedAdcpVersion : void 0
2639
+ );
2567
2640
  if (pollSuccess) {
2568
2641
  return markAuthoritativePolledTerminal(
2569
2642
  (0, import_match.attachMatch)({
@@ -3118,6 +3191,7 @@ class TaskExecutor {
3118
3191
  state.messages,
3119
3192
  {
3120
3193
  ...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
3194
+ ...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
3121
3195
  ...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope }
3122
3196
  },
3123
3197
  [],
@@ -3339,6 +3413,7 @@ class TaskExecutor {
3339
3413
  // No handler for deferred tasks - input was provided by human
3340
3414
  {
3341
3415
  ...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
3416
+ ...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
3342
3417
  ...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope }
3343
3418
  },
3344
3419
  [],
@@ -3378,6 +3453,7 @@ class TaskExecutor {
3378
3453
  refinementServedVersion: state.refinementServedVersion
3379
3454
  },
3380
3455
  ...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
3456
+ ...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
3381
3457
  ...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope },
3382
3458
  ...state.serverVersionSynthetic !== void 0 && {
3383
3459
  serverVersionSynthetic: state.serverVersionSynthetic
@@ -4564,11 +4640,11 @@ class TaskExecutor {
4564
4640
  * valid so the caller can continue. Off mode short-circuits before
4565
4641
  * AJV runs.
4566
4642
  */
4567
- validateResponseSchema(response, taskName, debugLogs, serverVersion, requestParams, refinementServedVersion) {
4643
+ validateResponseSchema(response, taskName, debugLogs, serverVersion, requestParams, refinementServedVersion, negotiatedAdcpVersion) {
4568
4644
  const mode = this.responseValidationMode;
4569
4645
  const logViolations = this.config.logSchemaViolations !== false;
4570
4646
  try {
4571
- const pinnedValidationVersion = this.responseAdcpVersionForValidation() ?? this.config.adcpVersion ?? import_version.ADCP_VERSION;
4647
+ const pinnedValidationVersion = this.responseAdcpVersionForValidation() ?? negotiatedAdcpVersion ?? this.config.adcpVersion ?? import_version.ADCP_VERSION;
4572
4648
  if (taskName === "get_adcp_capabilities") {
4573
4649
  return (0, import_schema_loader.withServedValidationVersion)(
4574
4650
  response,
@@ -4670,8 +4746,8 @@ class TaskExecutor {
4670
4746
  if (this.config.versionEnvelope === "major-only") return "3.0";
4671
4747
  return void 0;
4672
4748
  }
4673
- effectiveResponseAdcpVersion(serverVersion) {
4674
- return this.responseAdcpVersionForValidation() ?? this.config.adcpVersion ?? import_version.ADCP_VERSION;
4749
+ effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion) {
4750
+ return this.responseAdcpVersionForValidation() ?? negotiatedAdcpVersion ?? this.config.adcpVersion ?? import_version.ADCP_VERSION;
4675
4751
  }
4676
4752
  /**
4677
4753
  * Update task status and emit events
@@ -667,7 +667,11 @@ class TaskExecutor {
667
667
  * adaptation runs, so the validator sees the same object the caller wrote.
668
668
  * Throws in strict, logs to `debugLogs` in warn, no-ops in off.
669
669
  */
670
- 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
+ }
671
675
  if (this.config.experimentalIdentity33?.() && this.requestValidationMode !== "off") {
672
676
  const outcome = validateIdentity33Payload(taskName, "request", params, this.config.adcpVersion);
673
677
  if (!outcome.valid) {
@@ -1251,16 +1255,28 @@ class TaskExecutor {
1251
1255
  if (task && serverTaskId) task.serverTaskId = serverTaskId;
1252
1256
  switch (status) {
1253
1257
  case ADCP_STATUS.COMPLETED:
1254
- const completedData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1258
+ const completedData = this.extractResponseData(
1259
+ response,
1260
+ debugLogs,
1261
+ taskName,
1262
+ serverVersion,
1263
+ options.negotiatedAdcpVersion
1264
+ );
1255
1265
  if (!deferTerminalTaskStatus) this.updateTaskStatus(taskId, "completed", completedData);
1256
- const operationSuccess = this.isOperationSuccess(completedData, taskName, serverVersion);
1266
+ const operationSuccess = this.isOperationSuccess(
1267
+ completedData,
1268
+ taskName,
1269
+ serverVersion,
1270
+ options.negotiatedAdcpVersion
1271
+ );
1257
1272
  const validationResult = this.validateResponseSchema(
1258
1273
  completedData,
1259
1274
  taskName,
1260
1275
  debugLogs,
1261
1276
  serverVersion,
1262
1277
  params,
1263
- refinementServedVersion
1278
+ refinementServedVersion,
1279
+ options.negotiatedAdcpVersion
1264
1280
  );
1265
1281
  const finalSuccess = operationSuccess && validationResult.valid;
1266
1282
  const finalError = !finalSuccess ? validationResult.errors.length > 0 ? `Schema validation failed: ${validationResult.errors.join("; ")}` : this.extractOperationError(completedData) : void 0;
@@ -1352,7 +1368,13 @@ class TaskExecutor {
1352
1368
  case ADCP_STATUS.FAILED:
1353
1369
  case ADCP_STATUS.REJECTED:
1354
1370
  case ADCP_STATUS.CANCELED: {
1355
- const failedData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1371
+ const failedData = this.extractResponseData(
1372
+ response,
1373
+ debugLogs,
1374
+ taskName,
1375
+ serverVersion,
1376
+ options.negotiatedAdcpVersion
1377
+ );
1356
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;
1357
1379
  const adcpErrorInfo = extractAdcpErrorInfo(failedPayload);
1358
1380
  const hasStructuredError = !!adcpErrorInfo;
@@ -1380,16 +1402,28 @@ class TaskExecutor {
1380
1402
  };
1381
1403
  }
1382
1404
  default:
1383
- const defaultData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1405
+ const defaultData = this.extractResponseData(
1406
+ response,
1407
+ debugLogs,
1408
+ taskName,
1409
+ serverVersion,
1410
+ options.negotiatedAdcpVersion
1411
+ );
1384
1412
  if (defaultData && (defaultData !== response || response.structuredContent || response.result || response.data)) {
1385
- const defaultSuccess = this.isOperationSuccess(defaultData, taskName, serverVersion);
1413
+ const defaultSuccess = this.isOperationSuccess(
1414
+ defaultData,
1415
+ taskName,
1416
+ serverVersion,
1417
+ options.negotiatedAdcpVersion
1418
+ );
1386
1419
  const defaultValidation = this.validateResponseSchema(
1387
1420
  defaultData,
1388
1421
  taskName,
1389
1422
  debugLogs,
1390
1423
  serverVersion,
1391
1424
  params,
1392
- refinementServedVersion
1425
+ refinementServedVersion,
1426
+ options.negotiatedAdcpVersion
1393
1427
  );
1394
1428
  const defaultFinalSuccess = defaultSuccess && defaultValidation.valid;
1395
1429
  const defaultFinalError = !defaultFinalSuccess ? defaultValidation.errors.length > 0 ? `Schema validation failed: ${defaultValidation.errors.join("; ")}` : this.extractOperationError(defaultData) : void 0;
@@ -1440,7 +1474,7 @@ class TaskExecutor {
1440
1474
  *
1441
1475
  * @internal Exposed for testing purposes
1442
1476
  */
1443
- extractResponseData(response, debugLogs, toolName, serverVersion) {
1477
+ extractResponseData(response, debugLogs, toolName, serverVersion, negotiatedAdcpVersion) {
1444
1478
  const a2aState = response?.result?.status?.state;
1445
1479
  if (a2aState === "input-required" || a2aState === "auth-required") {
1446
1480
  const statusParts = response?.result?.status?.message?.parts;
@@ -1481,7 +1515,7 @@ class TaskExecutor {
1481
1515
  }
1482
1516
  const unwrapped = unwrapProtocolResponse(response, toolName, void 0, {
1483
1517
  filterInvalidProducts: this.config.filterInvalidProducts,
1484
- responseAdcpVersion: this.effectiveResponseAdcpVersion(serverVersion)
1518
+ responseAdcpVersion: this.effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion)
1485
1519
  });
1486
1520
  if (response?.structuredContent) {
1487
1521
  this.logDebug(debugLogs, "info", "Successfully extracted MCP data", {
@@ -1512,8 +1546,12 @@ class TaskExecutor {
1512
1546
  * Check if extracted response data represents a successful operation.
1513
1547
  * Handles singular `error`, plural `errors` (AdCP schema), and `success: false`.
1514
1548
  */
1515
- isOperationSuccess(data, taskName, serverVersion) {
1516
- return isAdcpOperationSuccess(data, taskName, this.effectiveResponseAdcpVersion(serverVersion));
1549
+ isOperationSuccess(data, taskName, serverVersion, negotiatedAdcpVersion) {
1550
+ return isAdcpOperationSuccess(
1551
+ data,
1552
+ taskName,
1553
+ this.effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion)
1554
+ );
1517
1555
  }
1518
1556
  /**
1519
1557
  * Extract a human-readable error message from response data.
@@ -1544,7 +1582,13 @@ class TaskExecutor {
1544
1582
  * Handle 'working' status - return as valid intermediate state
1545
1583
  */
1546
1584
  async waitForWorkingCompletion(agent, taskId, taskName, params, initialResponse, messages, inputHandler, options = {}, debugLogs = [], startTime = Date.now(), serverVersion = "v3") {
1547
- const partialData = this.extractResponseData(initialResponse, debugLogs, taskName, serverVersion);
1585
+ const partialData = this.extractResponseData(
1586
+ initialResponse,
1587
+ debugLogs,
1588
+ taskName,
1589
+ serverVersion,
1590
+ options.negotiatedAdcpVersion
1591
+ );
1548
1592
  const metadata = this.buildMetadata({
1549
1593
  taskId,
1550
1594
  taskName,
@@ -1568,7 +1612,13 @@ class TaskExecutor {
1568
1612
  * Set up submitted task with webhook
1569
1613
  */
1570
1614
  async setupSubmittedTask(agent, taskId, taskName, response, messages, options = {}, debugLogs = [], startTime = Date.now(), deferTerminalTaskStatus = false, serverVersion = "v3") {
1571
- const partialData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
1615
+ const partialData = this.extractResponseData(
1616
+ response,
1617
+ debugLogs,
1618
+ taskName,
1619
+ serverVersion,
1620
+ options.negotiatedAdcpVersion
1621
+ );
1572
1622
  let webhookUrl = response.webhookUrl;
1573
1623
  if (!webhookUrl && this.config.webhookManager) {
1574
1624
  webhookUrl = this.config.webhookManager.generateUrl(taskId);
@@ -2012,7 +2062,13 @@ class TaskExecutor {
2012
2062
  const operationRoutedContinuation = deferTerminalTaskStatus || directContinuationRecovery;
2013
2063
  const settlementServerTaskId = operationRoutedContinuation ? this.responseParser.getTaskId(response) : void 0;
2014
2064
  if (agent.protocol === "mcp" || !a2aTaskId) {
2015
- const partialData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
2065
+ const partialData = this.extractResponseData(
2066
+ response,
2067
+ debugLogs,
2068
+ taskName,
2069
+ serverVersion,
2070
+ options.negotiatedAdcpVersion
2071
+ );
2016
2072
  const metadata = this.buildMetadata({
2017
2073
  taskId,
2018
2074
  taskName,
@@ -2033,7 +2089,13 @@ class TaskExecutor {
2033
2089
  };
2034
2090
  }
2035
2091
  if (!inputHandler) {
2036
- const partialData = this.extractResponseData(response, debugLogs, taskName, serverVersion);
2092
+ const partialData = this.extractResponseData(
2093
+ response,
2094
+ debugLogs,
2095
+ taskName,
2096
+ serverVersion,
2097
+ options.negotiatedAdcpVersion
2098
+ );
2037
2099
  const metadata = this.buildMetadata({
2038
2100
  taskId,
2039
2101
  taskName,
@@ -2060,6 +2122,9 @@ class TaskExecutor {
2060
2122
  a2aTaskId,
2061
2123
  serverVersion,
2062
2124
  ...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
2125
+ ...options.negotiatedAdcpVersion !== void 0 && {
2126
+ negotiatedAdcpVersion: options.negotiatedAdcpVersion
2127
+ },
2063
2128
  ...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
2064
2129
  serverVersionSynthetic: this.activeTasks.get(taskId)?.serverVersionSynthetic,
2065
2130
  ...refinementServedVersion !== void 0 && { refinementServedVersion },
@@ -2204,6 +2269,9 @@ class TaskExecutor {
2204
2269
  a2aTaskId,
2205
2270
  serverVersion,
2206
2271
  ...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
2272
+ ...options.negotiatedAdcpVersion !== void 0 && {
2273
+ negotiatedAdcpVersion: options.negotiatedAdcpVersion
2274
+ },
2207
2275
  ...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
2208
2276
  serverVersionSynthetic: this.activeTasks.get(taskId)?.serverVersionSynthetic,
2209
2277
  ...refinementServedVersion !== void 0 && { refinementServedVersion },
@@ -2541,7 +2609,12 @@ class TaskExecutor {
2541
2609
  });
2542
2610
  }
2543
2611
  if (status.status === ADCP_STATUS.COMPLETED) {
2544
- const pollSuccess = this.isOperationSuccess(status.result, status.taskType, serverVersion);
2612
+ const pollSuccess = this.isOperationSuccess(
2613
+ status.result,
2614
+ status.taskType,
2615
+ serverVersion,
2616
+ metadataTaskId ? this.activeTasks.get(metadataTaskId)?.options.negotiatedAdcpVersion : void 0
2617
+ );
2545
2618
  if (pollSuccess) {
2546
2619
  return markAuthoritativePolledTerminal(
2547
2620
  attachMatch({
@@ -3096,6 +3169,7 @@ class TaskExecutor {
3096
3169
  state.messages,
3097
3170
  {
3098
3171
  ...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
3172
+ ...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
3099
3173
  ...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope }
3100
3174
  },
3101
3175
  [],
@@ -3317,6 +3391,7 @@ class TaskExecutor {
3317
3391
  // No handler for deferred tasks - input was provided by human
3318
3392
  {
3319
3393
  ...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
3394
+ ...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
3320
3395
  ...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope }
3321
3396
  },
3322
3397
  [],
@@ -3356,6 +3431,7 @@ class TaskExecutor {
3356
3431
  refinementServedVersion: state.refinementServedVersion
3357
3432
  },
3358
3433
  ...state.wireAdcpVersion !== void 0 && { wireAdcpVersion: state.wireAdcpVersion },
3434
+ ...state.negotiatedAdcpVersion !== void 0 && { negotiatedAdcpVersion: state.negotiatedAdcpVersion },
3359
3435
  ...state.versionEnvelope !== void 0 && { versionEnvelope: state.versionEnvelope },
3360
3436
  ...state.serverVersionSynthetic !== void 0 && {
3361
3437
  serverVersionSynthetic: state.serverVersionSynthetic
@@ -4542,11 +4618,11 @@ class TaskExecutor {
4542
4618
  * valid so the caller can continue. Off mode short-circuits before
4543
4619
  * AJV runs.
4544
4620
  */
4545
- validateResponseSchema(response, taskName, debugLogs, serverVersion, requestParams, refinementServedVersion) {
4621
+ validateResponseSchema(response, taskName, debugLogs, serverVersion, requestParams, refinementServedVersion, negotiatedAdcpVersion) {
4546
4622
  const mode = this.responseValidationMode;
4547
4623
  const logViolations = this.config.logSchemaViolations !== false;
4548
4624
  try {
4549
- const pinnedValidationVersion = this.responseAdcpVersionForValidation() ?? this.config.adcpVersion ?? ADCP_VERSION;
4625
+ const pinnedValidationVersion = this.responseAdcpVersionForValidation() ?? negotiatedAdcpVersion ?? this.config.adcpVersion ?? ADCP_VERSION;
4550
4626
  if (taskName === "get_adcp_capabilities") {
4551
4627
  return withServedValidationVersion(
4552
4628
  response,
@@ -4648,8 +4724,8 @@ class TaskExecutor {
4648
4724
  if (this.config.versionEnvelope === "major-only") return "3.0";
4649
4725
  return void 0;
4650
4726
  }
4651
- effectiveResponseAdcpVersion(serverVersion) {
4652
- return this.responseAdcpVersionForValidation() ?? this.config.adcpVersion ?? ADCP_VERSION;
4727
+ effectiveResponseAdcpVersion(serverVersion, negotiatedAdcpVersion) {
4728
+ return this.responseAdcpVersionForValidation() ?? negotiatedAdcpVersion ?? this.config.adcpVersion ?? ADCP_VERSION;
4653
4729
  }
4654
4730
  /**
4655
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 {};