@adcp/sdk 16.5.0 → 16.6.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 (236) hide show
  1. package/dist/lib/adapters/version/3.0/brand-fields.d.mts +7 -1
  2. package/dist/lib/adapters/version/3.0/brand-fields.d.ts +7 -1
  3. package/dist/lib/adapters/version/3.0/brand-fields.js +139 -3
  4. package/dist/lib/adapters/version/3.0/brand-fields.mjs +136 -2
  5. package/dist/lib/adapters/version/3.0/index.js +6 -0
  6. package/dist/lib/adapters/version/3.0/index.mjs +7 -1
  7. package/dist/lib/adapters/version/3.1/bidding.js +1 -1
  8. package/dist/lib/adapters/version/3.1/bidding.mjs +1 -1
  9. package/dist/lib/adapters/version/types.d.mts +5 -0
  10. package/dist/lib/adapters/version/types.d.ts +5 -0
  11. package/dist/lib/canonical-references/index.js +2 -0
  12. package/dist/lib/canonical-references/index.mjs +2 -0
  13. package/dist/lib/client/account-changes.d.mts +3 -1
  14. package/dist/lib/client/account-changes.d.ts +3 -1
  15. package/dist/lib/client/account-changes.js +22 -2
  16. package/dist/lib/client/account-changes.mjs +22 -2
  17. package/dist/lib/conformance/oracle.js +3 -2
  18. package/dist/lib/conformance/oracle.mjs +3 -2
  19. package/dist/lib/core/AgentClient.d.mts +165 -1
  20. package/dist/lib/core/AgentClient.d.ts +165 -1
  21. package/dist/lib/core/AgentClient.js +446 -8
  22. package/dist/lib/core/AgentClient.mjs +446 -8
  23. package/dist/lib/core/ConversationTypes.d.mts +8 -0
  24. package/dist/lib/core/ConversationTypes.d.ts +8 -0
  25. package/dist/lib/core/ProtocolResponseParser.d.mts +1 -1
  26. package/dist/lib/core/ProtocolResponseParser.d.ts +1 -1
  27. package/dist/lib/core/ProtocolResponseParser.js +28 -18
  28. package/dist/lib/core/ProtocolResponseParser.mjs +11 -1
  29. package/dist/lib/core/ResponseValidator.js +1 -1
  30. package/dist/lib/core/ResponseValidator.mjs +1 -1
  31. package/dist/lib/core/SingleAgentClient.d.mts +116 -6
  32. package/dist/lib/core/SingleAgentClient.d.ts +116 -6
  33. package/dist/lib/core/SingleAgentClient.js +556 -84
  34. package/dist/lib/core/SingleAgentClient.mjs +545 -72
  35. package/dist/lib/core/TaskExecutor.d.mts +7 -0
  36. package/dist/lib/core/TaskExecutor.d.ts +7 -0
  37. package/dist/lib/core/TaskExecutor.js +23 -8
  38. package/dist/lib/core/TaskExecutor.mjs +23 -8
  39. package/dist/lib/core/task-status.d.mts +2 -0
  40. package/dist/lib/core/task-status.d.ts +2 -0
  41. package/dist/lib/core/task-status.js +11 -2
  42. package/dist/lib/core/task-status.mjs +9 -1
  43. package/dist/lib/errors/index.d.mts +22 -0
  44. package/dist/lib/errors/index.d.ts +22 -0
  45. package/dist/lib/errors/index.js +43 -0
  46. package/dist/lib/errors/index.mjs +42 -0
  47. package/dist/lib/identity-3.3/trust.d.mts +1 -4
  48. package/dist/lib/identity-3.3/trust.d.ts +1 -4
  49. package/dist/lib/identity-3.3/trust.js +34 -21
  50. package/dist/lib/identity-3.3/trust.mjs +34 -21
  51. package/dist/lib/identity-3.3/validation.js +5 -3
  52. package/dist/lib/identity-3.3/validation.mjs +6 -4
  53. package/dist/lib/index.d.mts +8 -54
  54. package/dist/lib/index.d.ts +8 -54
  55. package/dist/lib/index.js +15 -0
  56. package/dist/lib/index.mjs +11 -0
  57. package/dist/lib/media-buy/action-assessment.js +29 -3
  58. package/dist/lib/media-buy/action-assessment.mjs +32 -4
  59. package/dist/lib/media-buy/action-contracts.d.mts +3 -0
  60. package/dist/lib/media-buy/action-contracts.d.ts +3 -0
  61. package/dist/lib/media-buy/action-contracts.js +24 -1
  62. package/dist/lib/media-buy/action-contracts.mjs +22 -1
  63. package/dist/lib/media-buy/compatibility.js +6 -1
  64. package/dist/lib/media-buy/compatibility.mjs +6 -1
  65. package/dist/lib/media-buy/preflight.js +1 -1
  66. package/dist/lib/media-buy/preflight.mjs +3 -2
  67. package/dist/lib/media-buy/types.d.mts +6 -1
  68. package/dist/lib/media-buy/types.d.ts +6 -1
  69. package/dist/lib/protocols/mcp-modern.d.mts +2 -0
  70. package/dist/lib/protocols/mcp-modern.d.ts +2 -0
  71. package/dist/lib/protocols/mcp-modern.js +31 -5
  72. package/dist/lib/protocols/mcp-modern.mjs +31 -5
  73. package/dist/lib/protocols/mcp-scope.d.mts +6 -1
  74. package/dist/lib/protocols/mcp-scope.d.ts +6 -1
  75. package/dist/lib/protocols/mcp-scope.js +25 -3
  76. package/dist/lib/protocols/mcp-scope.mjs +24 -3
  77. package/dist/lib/protocols/mcp.js +12 -6
  78. package/dist/lib/protocols/mcp.mjs +13 -6
  79. package/dist/lib/reporting/inspection.js +1 -0
  80. package/dist/lib/reporting/inspection.mjs +1 -0
  81. package/dist/lib/schemas/browser.d.mts +2 -0
  82. package/dist/lib/schemas/browser.d.ts +2 -0
  83. package/dist/lib/schemas/browser.js +3 -0
  84. package/dist/lib/schemas/browser.mjs +2 -0
  85. package/dist/lib/schemas/index.d.mts +5 -2
  86. package/dist/lib/schemas/index.d.ts +5 -2
  87. package/dist/lib/schemas/index.js +5 -0
  88. package/dist/lib/schemas/index.mjs +4 -0
  89. package/dist/lib/server/account-response-identity.d.mts +17 -0
  90. package/dist/lib/server/account-response-identity.d.ts +17 -0
  91. package/dist/lib/server/account-response-identity.js +52 -0
  92. package/dist/lib/server/account-response-identity.mjs +28 -0
  93. package/dist/lib/server/account-sync-contract.js +1 -0
  94. package/dist/lib/server/account-sync-contract.mjs +1 -0
  95. package/dist/lib/server/create-adcp-server.js +32 -19
  96. package/dist/lib/server/create-adcp-server.mjs +36 -12
  97. package/dist/lib/server/decisioning/account.d.mts +13 -6
  98. package/dist/lib/server/decisioning/account.d.ts +13 -6
  99. package/dist/lib/server/decisioning/account.js +37 -15
  100. package/dist/lib/server/decisioning/account.mjs +37 -15
  101. package/dist/lib/server/decisioning/runtime/from-platform.d.mts +5 -5
  102. package/dist/lib/server/decisioning/runtime/from-platform.d.ts +5 -5
  103. package/dist/lib/server/decisioning/runtime/from-platform.js +6 -6
  104. package/dist/lib/server/decisioning/runtime/from-platform.mjs +6 -6
  105. package/dist/lib/server/index.d.mts +1 -1
  106. package/dist/lib/server/index.d.ts +1 -1
  107. package/dist/lib/server/index.js +2 -0
  108. package/dist/lib/server/index.mjs +2 -0
  109. package/dist/lib/server/media-buy-action-resolver.d.mts +3 -0
  110. package/dist/lib/server/media-buy-action-resolver.d.ts +3 -0
  111. package/dist/lib/server/media-buy-action-resolver.js +32 -0
  112. package/dist/lib/server/media-buy-action-resolver.mjs +32 -0
  113. package/dist/lib/server/media-buy-store.d.mts +26 -12
  114. package/dist/lib/server/media-buy-store.d.ts +26 -12
  115. package/dist/lib/server/media-buy-store.js +69 -21
  116. package/dist/lib/server/media-buy-store.mjs +69 -21
  117. package/dist/lib/server/responses.js +9 -1
  118. package/dist/lib/server/responses.mjs +9 -1
  119. package/dist/lib/server/state-machine.d.mts +10 -11
  120. package/dist/lib/server/state-machine.d.ts +10 -11
  121. package/dist/lib/server/state-machine.js +20 -5
  122. package/dist/lib/server/state-machine.mjs +19 -5
  123. package/dist/lib/signing/agent-fetch.d.mts +1 -1
  124. package/dist/lib/signing/agent-fetch.d.ts +1 -1
  125. package/dist/lib/signing/agent-fetch.js +3 -3
  126. package/dist/lib/signing/agent-fetch.mjs +3 -3
  127. package/dist/lib/testing/client.d.mts +1 -0
  128. package/dist/lib/testing/client.d.ts +1 -0
  129. package/dist/lib/testing/client.js +6 -5
  130. package/dist/lib/testing/client.mjs +6 -5
  131. package/dist/lib/testing/storyboard/canonical-format-satisfaction.js +60 -14
  132. package/dist/lib/testing/storyboard/canonical-format-satisfaction.mjs +60 -14
  133. package/dist/lib/testing/storyboard/compliance.d.mts +2 -5
  134. package/dist/lib/testing/storyboard/compliance.d.ts +2 -5
  135. package/dist/lib/testing/storyboard/compliance.js +62 -13
  136. package/dist/lib/testing/storyboard/compliance.mjs +63 -14
  137. package/dist/lib/testing/storyboard/context.d.mts +13 -3
  138. package/dist/lib/testing/storyboard/context.d.ts +13 -3
  139. package/dist/lib/testing/storyboard/context.js +15 -10
  140. package/dist/lib/testing/storyboard/context.mjs +15 -10
  141. package/dist/lib/testing/storyboard/default-invariants.js +10 -8
  142. package/dist/lib/testing/storyboard/default-invariants.mjs +11 -9
  143. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.mts +2 -0
  144. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.ts +2 -0
  145. package/dist/lib/testing/storyboard/request-signing/vector-loader.js +11 -0
  146. package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +10 -0
  147. package/dist/lib/testing/storyboard/runner.js +23 -10
  148. package/dist/lib/testing/storyboard/runner.mjs +23 -10
  149. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  150. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  151. package/dist/lib/testing/storyboard/validations.js +4 -1
  152. package/dist/lib/testing/storyboard/validations.mjs +4 -1
  153. package/dist/lib/testing/test-controller.js +3 -0
  154. package/dist/lib/testing/test-controller.mjs +3 -0
  155. package/dist/lib/types/asset-instances.d.mts +1 -1
  156. package/dist/lib/types/asset-instances.d.ts +1 -1
  157. package/dist/lib/types/index.d.mts +5 -0
  158. package/dist/lib/types/index.d.ts +5 -0
  159. package/dist/lib/types/index.js +6 -1
  160. package/dist/lib/types/index.mjs +4 -1
  161. package/dist/lib/types/inline-enums.generated.d.mts +30 -4
  162. package/dist/lib/types/inline-enums.generated.d.ts +30 -4
  163. package/dist/lib/types/inline-enums.generated.js +41 -2
  164. package/dist/lib/types/inline-enums.generated.mjs +28 -2
  165. package/dist/lib/types/media-buy-delivery-report.d.mts +4 -0
  166. package/dist/lib/types/media-buy-delivery-report.d.ts +4 -0
  167. package/dist/lib/types/media-buy-delivery-report.js +16 -0
  168. package/dist/lib/types/media-buy-delivery-report.mjs +0 -0
  169. package/dist/lib/types/schemas.generated.d.ts +20 -69
  170. package/dist/lib/types/schemas.generated.js +29 -46
  171. package/dist/lib/types/schemas.generated.mjs +29 -46
  172. package/dist/lib/types/targeting-keys.generated.d.mts +4 -0
  173. package/dist/lib/types/targeting-keys.generated.d.ts +4 -0
  174. package/dist/lib/types/targeting-keys.generated.js +105 -0
  175. package/dist/lib/types/targeting-keys.generated.mjs +80 -0
  176. package/dist/lib/utils/adcp-version-config.js +5 -2
  177. package/dist/lib/utils/adcp-version-config.mjs +5 -2
  178. package/dist/lib/utils/envelope-status-compat.d.mts +18 -1
  179. package/dist/lib/utils/envelope-status-compat.d.ts +18 -1
  180. package/dist/lib/utils/envelope-status-compat.js +11 -5
  181. package/dist/lib/utils/envelope-status-compat.mjs +11 -5
  182. package/dist/lib/utils/response-unwrapper.js +18 -10
  183. package/dist/lib/utils/response-unwrapper.mjs +18 -10
  184. package/dist/lib/v2/format-schema/resolver.js +1 -1
  185. package/dist/lib/v2/format-schema/resolver.mjs +1 -1
  186. package/dist/lib/v2/projection/creative-delivery.js +123 -30
  187. package/dist/lib/v2/projection/creative-delivery.mjs +127 -30
  188. package/dist/lib/v2/projection/index.d.mts +1 -0
  189. package/dist/lib/v2/projection/index.d.ts +1 -0
  190. package/dist/lib/v2/projection/index.js +3 -0
  191. package/dist/lib/v2/projection/index.mjs +2 -0
  192. package/dist/lib/v2/projection/legacy-metadata.d.mts +19 -0
  193. package/dist/lib/v2/projection/legacy-metadata.d.ts +19 -0
  194. package/dist/lib/v2/projection/legacy-metadata.js +91 -0
  195. package/dist/lib/v2/projection/legacy-metadata.mjs +86 -0
  196. package/dist/lib/validation/compact-schema.d.mts +27 -0
  197. package/dist/lib/validation/compact-schema.d.ts +27 -0
  198. package/dist/lib/validation/compact-schema.js +276 -0
  199. package/dist/lib/validation/compact-schema.mjs +250 -0
  200. package/dist/lib/validation/media-buy-delivery-report.d.mts +8 -0
  201. package/dist/lib/validation/media-buy-delivery-report.d.ts +8 -0
  202. package/dist/lib/validation/media-buy-delivery-report.js +31 -0
  203. package/dist/lib/validation/media-buy-delivery-report.mjs +7 -0
  204. package/dist/lib/validation/schema-diagnostic-origins.d.mts +21 -0
  205. package/dist/lib/validation/schema-diagnostic-origins.d.ts +21 -0
  206. package/dist/lib/validation/schema-diagnostic-origins.js +193 -0
  207. package/dist/lib/validation/schema-diagnostic-origins.mjs +169 -0
  208. package/dist/lib/validation/schema-loader.js +86 -16
  209. package/dist/lib/validation/schema-loader.mjs +82 -16
  210. package/dist/lib/validation/schema-validator.d.mts +10 -19
  211. package/dist/lib/validation/schema-validator.d.ts +10 -19
  212. package/dist/lib/validation/schema-validator.js +136 -43
  213. package/dist/lib/validation/schema-validator.mjs +140 -44
  214. package/dist/lib/version.d.mts +3 -3
  215. package/dist/lib/version.d.ts +3 -3
  216. package/dist/lib/version.js +3 -3
  217. package/dist/lib/version.mjs +3 -3
  218. package/dist/lib/webhooks/index.d.mts +3 -0
  219. package/dist/lib/webhooks/index.d.ts +3 -0
  220. package/dist/lib/webhooks/index.js +3 -0
  221. package/dist/lib/webhooks/index.mjs +2 -0
  222. package/dist/lib/webhooks/media-buy-delivery.d.mts +43 -0
  223. package/dist/lib/webhooks/media-buy-delivery.d.ts +43 -0
  224. package/dist/lib/webhooks/media-buy-delivery.js +119 -0
  225. package/dist/lib/webhooks/media-buy-delivery.mjs +94 -0
  226. package/docs/TYPE-SUMMARY.md +2 -2
  227. package/docs/guides/BUILD-AN-AGENT.md +9 -1
  228. package/docs/guides/DELIVERY-WEBHOOK-PARSING.md +135 -0
  229. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +15 -0
  230. package/docs/guides/TYPED-CLIENT-TOOLS.md +49 -0
  231. package/docs/llms.txt +3 -3
  232. package/docs/migration-14.x-rc-worksheet.md +4 -4
  233. package/docs/migration-6.6-to-6.7.md +14 -0
  234. package/docs/migration-account-change-feed.md +19 -0
  235. package/docs/releases/sdk-16.6-adoption-fixes.md +33 -0
  236. package/package.json +2 -2
@@ -3,7 +3,8 @@ import { dirname as __adcpDirname } from "node:path";
3
3
  import { createRequire as __adcpCreateRequire } from "node:module";
4
4
  const __dirname = __adcpDirname(__adcpFileURLToPath(import.meta.url));
5
5
  const require2 = __adcpCreateRequire(import.meta.url);
6
- import { withMCPConnectionPolicy } from "../protocols/mcp-connection-policy.mjs";
6
+ import { shouldReuseMCPConnection, withMCPConnectionPolicy } from "../protocols/mcp-connection-policy.mjs";
7
+ import { withMCPConnectionScope } from "../protocols/mcp-scope.mjs";
7
8
  import { hasUnsignedCapabilityBootstrap } from "../signing/protocol-methods.mjs";
8
9
  import { normalizeGetProductsResponse } from "../utils/pricing-adapter.mjs";
9
10
  import { normalizeMediaBuyResponse } from "../utils/creative-adapter.mjs";
@@ -23,6 +24,16 @@ import {
23
24
  import { randomUUID, scryptSync } from "node:crypto";
24
25
  const SKIP_PRODUCT_CACHE = /* @__PURE__ */ Symbol("adcp.skipProductCache");
25
26
  const SKIP_ACCOUNT_REGISTRY_OBSERVATION = /* @__PURE__ */ Symbol("adcp.skipAccountRegistryObservation");
27
+ const NONTERMINAL_TASK_RESULT_STATUSES = /* @__PURE__ */ new Set([
28
+ "submitted",
29
+ "working",
30
+ "input-required",
31
+ "auth-required",
32
+ "deferred"
33
+ ]);
34
+ function isNonterminalTaskResult(result) {
35
+ return result !== null && typeof result === "object" && "success" in result && result.success === true && "status" in result && typeof result.status === "string" && NONTERMINAL_TASK_RESULT_STATUSES.has(result.status);
36
+ }
26
37
  import { accountKeySites, naturalAccountKey, reducedFields, valueAt, withReducedKeyAt } from "./account-reduction.mjs";
27
38
  import { ADCP_ENVELOPE_FIELDS } from "../types/adcp.mjs";
28
39
  import { parseAdcpMajorVersion, toReleasePrecisionVersion } from "../version.mjs";
@@ -73,6 +84,7 @@ import { getSignedRequestRejection } from "../protocols/signedRequestRejection.m
73
84
  import { withAmbientIdentityHeaders } from "../protocols/mcp-call-context.mjs";
74
85
  import { ProtocolClient, normalizeTransportOptions } from "../protocols/index.mjs";
75
86
  import {
87
+ AgentRateLimitedError,
76
88
  AuthenticationCredentialsRejectedError,
77
89
  AuthenticationRequiredError,
78
90
  ConfigurationError,
@@ -174,6 +186,7 @@ import {
174
186
  selectListedAccount
175
187
  } from "./account-resolution.mjs";
176
188
  import { normalizeRequestParams } from "../utils/request-normalizer.mjs";
189
+ import { getCreativeDeliveryDiagnostics } from "../v2/projection/legacy-metadata.mjs";
177
190
  import { globalAsyncLocalStorage } from "../utils/global-async-local-storage.mjs";
178
191
  import { validateUserAgent } from "../utils/validate-user-agent.mjs";
179
192
  import { resolveWebhookUrl, selectWebhookTemplate } from "./webhook-url.mjs";
@@ -735,10 +748,7 @@ const STANDARD_ADCP_TASK_NAMES = /* @__PURE__ */ new Set([
735
748
  "list_transformers",
736
749
  "preview_creative",
737
750
  "build_creative",
738
- // These standard protocol tools still carry legacy creative `format_id`
739
- // identity through artifacts, manifests, standards, or rights constraints.
740
- // They are available only through explicitly named *Legacy APIs until a
741
- // lossless canonical projection exists.
751
+ // Wire-level creative and content tools also have typed primary methods.
742
752
  "list_content_standards",
743
753
  "get_content_standards",
744
754
  "create_content_standards",
@@ -1022,7 +1032,19 @@ class SingleAgentClient {
1022
1032
  adcpVersion: this.resolvedAdcpVersion,
1023
1033
  ...config.wireAdcpVersion !== void 0 && { wireAdcpVersion: config.wireAdcpVersion },
1024
1034
  ...config.versionEnvelope !== void 0 && { versionEnvelope: config.versionEnvelope },
1025
- transport: config.transport
1035
+ transport: config.transport,
1036
+ resolveTaskStatusTool: async (pollAgent, options) => {
1037
+ const client = pollAgent.id === this.normalizedAgent.id ? this : new SingleAgentClient(pollAgent, {
1038
+ adcpVersion: this.resolvedAdcpVersion,
1039
+ wireAdcpVersion: this.config.wireAdcpVersion,
1040
+ versionEnvelope: this.config.versionEnvelope,
1041
+ userAgent: this.config.userAgent,
1042
+ discoveryCache: this.config.discoveryCache,
1043
+ onTransportActivity: this.config.onTransportActivity,
1044
+ transport: options.transport
1045
+ });
1046
+ return await client.advertisesTool("get_task_status", options) ? "get_task_status" : pollAgent.protocol === "mcp" ? "tasks_get" : "tasks/get";
1047
+ }
1026
1048
  });
1027
1049
  if (config.handlers) {
1028
1050
  this.asyncHandler = new AsyncHandler(config.handlers);
@@ -1830,8 +1852,18 @@ class SingleAgentClient {
1830
1852
  const agent = this.normalizedAgent.protocol === "a2a" ? await this.ensureCanonicalUrlResolved(snapshot) : await this.ensureEndpointDiscovered(snapshot);
1831
1853
  return this.executor.trackTask(agent, snapshot);
1832
1854
  }
1833
- /** Poll through the same discovered/canonical protocol endpoint used for dispatch. @internal */
1834
- async getTaskStatus(taskId, transport, signal, wireOptions) {
1855
+ async getTaskStatus(taskIdOrParams, transportOrHandler, signalOrOptions, wireOptions) {
1856
+ if (typeof taskIdOrParams !== "string") {
1857
+ return this.executeTaskUnprojected(
1858
+ "get_task_status",
1859
+ taskIdOrParams,
1860
+ transportOrHandler,
1861
+ signalOrOptions
1862
+ );
1863
+ }
1864
+ const taskId = taskIdOrParams;
1865
+ const transport = transportOrHandler;
1866
+ const signal = signalOrOptions;
1835
1867
  const transportSnapshot = transport === void 0 ? void 0 : { ...transport };
1836
1868
  const options = { transport: transportSnapshot, signal };
1837
1869
  const agent = this.normalizedAgent.protocol === "a2a" ? await this.ensureCanonicalUrlResolved(options) : await this.ensureEndpointDiscovered(options);
@@ -2304,6 +2336,9 @@ class SingleAgentClient {
2304
2336
  * - A validated MCP protected-resource metadata chain yields NeedsAuthorizationError
2305
2337
  * - Otherwise AuthenticationRequiredError carries the advertised challenge
2306
2338
  *
2339
+ * Rate limiting (429, or 503 with Retry-After) stops probing at that URL and
2340
+ * throws AgentRateLimitedError carrying the status and Retry-After.
2341
+ *
2307
2342
  * Note: This is async and called lazily on first agent interaction
2308
2343
  */
2309
2344
  async discoverMCPEndpoint(providedUri, options) {
@@ -2314,8 +2349,8 @@ class SingleAgentClient {
2314
2349
  }
2315
2350
  async discoverMCPEndpointWithConnectionPolicy(providedUri, options) {
2316
2351
  throwIfAborted(options?.signal);
2317
- const { connectMCPWithFallback } = await import("../protocols/mcp.mjs");
2318
- const { probeModernMCPConnection } = await import("../protocols/mcp-modern.mjs");
2352
+ const { connectMCPWithFallback, withScopedLegacyConnection } = await import("../protocols/mcp.mjs");
2353
+ const { probeModernMCPConnection, retryAfterOf } = await import("../protocols/mcp-modern.mjs");
2319
2354
  const transport = normalizeTransportOptions(options?.transport ?? this.config.transport);
2320
2355
  const usesScopedFetch = this.usesScopedDiscoveryTransport(options);
2321
2356
  const endpointEpoch = this.discoveryEpochSnapshot(options);
@@ -2345,19 +2380,35 @@ class SingleAgentClient {
2345
2380
  }
2346
2381
  return { success: true };
2347
2382
  }
2348
- const client = await connectMCPWithFallback(
2349
- new URL(url),
2350
- authHeaders,
2351
- [],
2352
- "endpoint discovery",
2353
- transport?.trustedFetchFn,
2383
+ const shared = await withScopedLegacyConnection(
2354
2384
  {
2385
+ agentUrl: url,
2386
+ authToken,
2387
+ customHeaders: agentHeaders,
2388
+ authProvider,
2355
2389
  signal: options?.signal,
2356
2390
  requestTimeoutMs: transport?.requestTimeoutMs,
2391
+ fetchFn: transport?.trustedFetchFn,
2357
2392
  allowPrivateIp: transport?.allowPrivateIp
2358
- }
2393
+ },
2394
+ "endpoint discovery",
2395
+ async () => void 0
2359
2396
  );
2360
- await client.close();
2397
+ if (!shared) {
2398
+ const client = await connectMCPWithFallback(
2399
+ new URL(url),
2400
+ authHeaders,
2401
+ [],
2402
+ "endpoint discovery",
2403
+ transport?.trustedFetchFn,
2404
+ {
2405
+ signal: options?.signal,
2406
+ requestTimeoutMs: transport?.requestTimeoutMs,
2407
+ allowPrivateIp: transport?.allowPrivateIp
2408
+ }
2409
+ );
2410
+ await client.close();
2411
+ }
2361
2412
  if (mayRetain()) {
2362
2413
  this.discoveredMcpEra = "legacy";
2363
2414
  this.discoveredMcpEraAt = Date.now();
@@ -2374,7 +2425,8 @@ class SingleAgentClient {
2374
2425
  }
2375
2426
  const errObj = error;
2376
2427
  const status = errObj?.status || errObj?.response?.status || errObj?.cause?.status;
2377
- return { success: false, status, error };
2428
+ const retryAfter = retryAfterOf(error);
2429
+ return { success: false, status, ...retryAfter !== void 0 && { retryAfter }, error };
2378
2430
  }
2379
2431
  };
2380
2432
  const urlsToTry = [];
@@ -2397,6 +2449,9 @@ class SingleAgentClient {
2397
2449
  firstWorkingUrl = url;
2398
2450
  break;
2399
2451
  }
2452
+ if (result.status === 429 || result.status === 503 && result.retryAfter !== void 0) {
2453
+ throw new AgentRateLimitedError(url, result.status, result.retryAfter, result.error);
2454
+ }
2400
2455
  if (result.status === 401) {
2401
2456
  got401 = true;
2402
2457
  first401Error ??= result.error;
@@ -2673,6 +2728,24 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
2673
2728
  };
2674
2729
  }
2675
2730
  }
2731
+ let artifactPayloadValidator;
2732
+ if (registration?.deliveryKind === "artifact") {
2733
+ try {
2734
+ const loader = require2("../validation/schema-loader");
2735
+ artifactPayloadValidator = loader.getSchemaValidatorByRef(
2736
+ "content-standards/artifact-webhook-payload.json",
2737
+ this.resolvedAdcpVersion
2738
+ );
2739
+ if (!artifactPayloadValidator) throw new ConfigurationError("Bundled artifact webhook schema is unavailable.");
2740
+ } catch (cause) {
2741
+ return {
2742
+ ok: false,
2743
+ code: "webhook_verification_unavailable",
2744
+ message: "Artifact webhook schema configuration is unavailable.",
2745
+ cause
2746
+ };
2747
+ }
2748
+ }
2676
2749
  if (registration?.mode === "rfc9421") {
2677
2750
  const { verifyWebBotAuth, selectSignatureProfile, WebBotAuthError, WebBotAuthUnavailableError } = loadWebBotAuth();
2678
2751
  const requestMethod = options.requestMethod;
@@ -2847,7 +2920,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
2847
2920
  const isReport = registration.deliveryKind === "reporting";
2848
2921
  const payload = isReport ? body.result : body;
2849
2922
  const schemaRef = isReport ? "media-buy/media-buy-delivery-webhook-result.json" : "content-standards/artifact-webhook-payload.json";
2850
- const validator = loader.getSchemaValidatorByRef(schemaRef, this.resolvedAdcpVersion);
2923
+ const validator = isReport ? loader.getSchemaValidatorByRef(schemaRef, this.resolvedAdcpVersion) : artifactPayloadValidator;
2851
2924
  const envelopeValidator = isReport ? loader.getSchemaValidatorByRef("core/mcp-webhook-payload.json", this.resolvedAdcpVersion) : void 0;
2852
2925
  if (!validator || !validator(payload) || isReport && (!envelopeValidator || !envelopeValidator(body) || body.task_type !== "media_buy_delivery"))
2853
2926
  return {
@@ -3609,17 +3682,32 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
3609
3682
  timestamp
3610
3683
  }).ok;
3611
3684
  }
3612
- /**
3613
- * Execute task and call appropriate handler on completion
3614
- *
3615
- * Adapts requests for maintained AdCP 3 releases and normalizes product responses.
3616
- */
3685
+ /** One task owns discovery and dispatch sessions unless the caller already owns reuse. */
3686
+ withConnectionScope(options, run, preserveSessionOnResult) {
3687
+ const transport = normalizeTransportOptions(options?.transport ?? this.config.transport);
3688
+ return withMCPConnectionPolicy(
3689
+ transport,
3690
+ () => shouldReuseMCPConnection(transport?.trustedFetchFn !== void 0) ? run() : withMCPConnectionScope(run, {
3691
+ signal: options?.signal,
3692
+ preserveOnInterruption: true,
3693
+ preserveSessionOnResult
3694
+ })
3695
+ );
3696
+ }
3697
+ withTaskConnectionScope(options, run) {
3698
+ return withTaskDeadline(
3699
+ options,
3700
+ (effective) => this.withConnectionScope(effective, () => run(effective), isNonterminalTaskResult)
3701
+ );
3702
+ }
3703
+ /** Execute a task, adapt maintained AdCP 3 releases, and call the completion handler. */
3617
3704
  async executeAndHandle(taskType, handlerName, params, inputHandler, options, transformCompletedResponse, legacyFormatConverter, canonicalRequest, projectionCatalogs) {
3705
+ const projectionDrifts = getCreativeDeliveryDiagnostics(params);
3618
3706
  const requestParamsSnapshot = structuredClone(params);
3619
3707
  const canonicalRequestSnapshot = canonicalRequest === void 0 ? void 0 : structuredClone(canonicalRequest);
3620
3708
  const deferredProjectionCatalogs = projectionCatalogs ? structuredClone(projectionCatalogs) : void 0;
3621
3709
  const taskOptionsSnapshot = snapshotTaskOptions(options);
3622
- return withTaskDeadline(
3710
+ return this.withTaskConnectionScope(
3623
3711
  taskOptionsSnapshot,
3624
3712
  (effectiveOptions) => this.executeAndHandleWithinDeadline(
3625
3713
  taskType,
@@ -3630,11 +3718,12 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
3630
3718
  transformCompletedResponse,
3631
3719
  legacyFormatConverter,
3632
3720
  canonicalRequestSnapshot,
3633
- deferredProjectionCatalogs
3721
+ deferredProjectionCatalogs,
3722
+ projectionDrifts
3634
3723
  )
3635
3724
  );
3636
3725
  }
3637
- async executeAndHandleWithinDeadline(taskType, handlerName, params, inputHandler, options, transformCompletedResponse, legacyFormatConverter, canonicalRequest, projectionCatalogs) {
3726
+ async executeAndHandleWithinDeadline(taskType, handlerName, params, inputHandler, options, transformCompletedResponse, legacyFormatConverter, canonicalRequest, projectionCatalogs, projectionDrifts = []) {
3638
3727
  throwIfAborted(options?.signal);
3639
3728
  const canonicalCreativeInvocation = CANONICAL_CREATIVE_ACTIVITY_TASKS.has(taskType) || canonicalRequest !== void 0;
3640
3729
  params = await this.applyAccountPolicy(taskType, params, options);
@@ -3710,7 +3799,15 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
3710
3799
  if (negotiatedRelease?.downgraded && !options?.skipIdempotencyAutoInject && !options?.skipAccountValidation && !options?.skipRequestValidation) {
3711
3800
  this.executor.validateRequest(taskType, adaptedParams, inputSchemaStripLogs, negotiatedRelease.version);
3712
3801
  }
3713
- const adaptationLogs = [...adaptDriftLogs];
3802
+ const adaptationLogs = [
3803
+ ...projectionDrifts.map((drift) => ({
3804
+ ...drift,
3805
+ taskName: taskType,
3806
+ clientVersion: this.resolvedAdcpVersion,
3807
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
3808
+ })),
3809
+ ...adaptDriftLogs
3810
+ ];
3714
3811
  if (webhookDriftLog) adaptationLogs.push(webhookDriftLog);
3715
3812
  const canonicalInputHandler = this.canonicalCreativeInputHandler(
3716
3813
  taskType,
@@ -4819,8 +4916,15 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
4819
4916
  * stamps it on the version envelope and validates the response against it.
4820
4917
  */
4821
4918
  withNegotiatedRelease(options, negotiated) {
4822
- if (!negotiated?.downgraded) return options;
4823
- return { ...options ?? {}, wireAdcpVersion: negotiated.version, negotiatedAdcpVersion: negotiated.version };
4919
+ if (!negotiated) return options;
4920
+ return {
4921
+ ...options ?? {},
4922
+ selectedAdcpVersion: negotiated.version,
4923
+ ...negotiated.downgraded && {
4924
+ wireAdcpVersion: negotiated.version,
4925
+ negotiatedAdcpVersion: negotiated.version
4926
+ }
4927
+ };
4824
4928
  }
4825
4929
  /**
4826
4930
  * Refuse a tool the negotiated release does not define (a 3.2-only task
@@ -5089,8 +5193,9 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5089
5193
  const adapterKey = resolveAdapterKey(this.resolvedAdcpVersion, perCallCapabilities ?? this.cachedCapabilities);
5090
5194
  if (adapterKey) {
5091
5195
  const versionAdapter = getVersionAdapter(adapterKey, taskType);
5092
- if (versionAdapter?.adaptRequest) {
5093
- const result = versionAdapter.adaptRequest(adapted);
5196
+ const adaptRequest = negotiated ? versionAdapter?.adaptRequest : versionAdapter?.adaptUnnegotiatedRequest ?? versionAdapter?.adaptRequest;
5197
+ if (adaptRequest) {
5198
+ const result = adaptRequest(adapted);
5094
5199
  adapted = result.params;
5095
5200
  if (result.drift) {
5096
5201
  driftLogs.push({
@@ -5152,7 +5257,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5152
5257
  legacyFormatConverter,
5153
5258
  projectionCatalogs ?? this.config.projectionCatalogs
5154
5259
  );
5155
- return withTaskDeadline(snapshotTaskOptions(taskOptions), async (effectiveOptions) => {
5260
+ return this.withTaskConnectionScope(snapshotTaskOptions(taskOptions), async (effectiveOptions) => {
5156
5261
  this.assertRequestSupportedByConfiguredVersion("get_products", params, effectiveOptions);
5157
5262
  let request = await this.applyAccountPolicy("get_products", params, effectiveOptions);
5158
5263
  const legacyAccountId = request.account_id;
@@ -5341,7 +5446,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5341
5446
  ...snapshotTaskOptions(options),
5342
5447
  ...projectionCatalogs !== void 0 && { projectionCatalogs }
5343
5448
  };
5344
- return withTaskDeadline(
5449
+ return this.withTaskConnectionScope(
5345
5450
  snapshottedOptions,
5346
5451
  (effectiveOptions) => this.createMediaBuyWithinDeadline(requestSnapshot, inputHandler, effectiveOptions)
5347
5452
  );
@@ -5500,7 +5605,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5500
5605
  ...snapshotTaskOptions(options),
5501
5606
  ...projectionCatalogs !== void 0 && { projectionCatalogs }
5502
5607
  };
5503
- return withTaskDeadline(
5608
+ return this.withTaskConnectionScope(
5504
5609
  snapshottedOptions,
5505
5610
  (effectiveOptions) => this.updateMediaBuyWithinDeadline(requestSnapshot, inputHandler, effectiveOptions)
5506
5611
  );
@@ -5591,7 +5696,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5591
5696
  ...projectionCatalogs !== void 0 && { projectionCatalogs },
5592
5697
  ...creativeFormatProjection !== void 0 && { creativeFormatProjection }
5593
5698
  };
5594
- return withTaskDeadline(
5699
+ return this.withTaskConnectionScope(
5595
5700
  snapshottedOptions,
5596
5701
  (effectiveOptions) => this.syncCreativesWithinDeadline(requestSnapshot, inputHandler, effectiveOptions)
5597
5702
  );
@@ -6043,25 +6148,31 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6043
6148
  * Pass an explicit agent via options.agent to override.
6044
6149
  */
6045
6150
  async syncPlans(params, inputHandler, options) {
6151
+ if (!options?.agent && !this.config.governance?.campaign?.agent) {
6152
+ return this.executeTaskUnprojected("sync_plans", params, inputHandler, options);
6153
+ }
6046
6154
  const agent = options?.agent ?? this.getGovernanceAgent();
6047
6155
  this.executor.validateRequest("sync_plans", params);
6048
6156
  return this.executor.executeTask(agent, "sync_plans", params, inputHandler, options);
6049
6157
  }
6050
- /**
6051
- * Get governance audit logs for one or more plans.
6052
- * Returns budget state, channel allocation, per-campaign breakdown, and audit trail.
6053
- *
6054
- * Uses the governance agent from config.governance.campaign.agent by default.
6055
- * Pass an explicit agent via options.agent to override.
6056
- */
6057
- async getPlanAuditLogs(params, options) {
6158
+ async getPlanAuditLogs(params, inputHandlerOrOptions, taskOptions) {
6159
+ const inputHandler = typeof inputHandlerOrOptions === "function" ? inputHandlerOrOptions : void 0;
6160
+ const options = inputHandlerOrOptions === void 0 || typeof inputHandlerOrOptions === "function" ? taskOptions : inputHandlerOrOptions;
6161
+ if (!options?.agent && !this.config.governance?.campaign?.agent) {
6162
+ return this.executeTaskUnprojected(
6163
+ "get_plan_audit_logs",
6164
+ params,
6165
+ inputHandler,
6166
+ options
6167
+ );
6168
+ }
6058
6169
  const agent = options?.agent ?? this.getGovernanceAgent();
6059
6170
  this.executor.validateRequest("get_plan_audit_logs", params);
6060
6171
  return this.executor.executeTask(
6061
6172
  agent,
6062
6173
  "get_plan_audit_logs",
6063
6174
  params,
6064
- void 0,
6175
+ inputHandler,
6065
6176
  options
6066
6177
  );
6067
6178
  }
@@ -6099,6 +6210,374 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6099
6210
  }
6100
6211
  return agent;
6101
6212
  }
6213
+ async advertisesTool(taskName, options) {
6214
+ const context = {};
6215
+ const capabilities = await this.getCapabilities({
6216
+ ...options,
6217
+ [CAPABILITY_DISCOVERY_CONTEXT]: context
6218
+ });
6219
+ return capabilities.discoveredTools?.includes(taskName) === true || context.toolSchemas?.has(taskName) === true;
6220
+ }
6221
+ /** Accept a committed proposal to create or amend a media buy, or apply a negotiated cancellation. */
6222
+ async acceptProposal(params, inputHandler, options) {
6223
+ return this.executeTaskUnprojected(
6224
+ "accept_proposal",
6225
+ params,
6226
+ inputHandler,
6227
+ options
6228
+ );
6229
+ }
6230
+ /** Execute the AdCP acquire_rights tool. */
6231
+ async acquireRights(params, inputHandler, options) {
6232
+ return this.executeTaskUnprojected(
6233
+ "acquire_rights",
6234
+ params,
6235
+ inputHandler,
6236
+ options
6237
+ );
6238
+ }
6239
+ /** Generate, transform, refine, retrieve, or adapt creative manifests for advertised creative capabilities. */
6240
+ async buildCreative(params, inputHandler, options) {
6241
+ return this.executeTaskUnprojected(
6242
+ "build_creative",
6243
+ params,
6244
+ inputHandler,
6245
+ options
6246
+ );
6247
+ }
6248
+ /** Create a media buy directly from published seller products and record its accepted commercial snapshot. */
6249
+ async buyProducts(params, inputHandler, options) {
6250
+ return this.executeTaskUnprojected("buy_products", params, inputHandler, options);
6251
+ }
6252
+ /** Execute the AdCP calibrate_content tool. */
6253
+ async calibrateContent(params, inputHandler, options) {
6254
+ return this.executeTaskUnprojected(
6255
+ "calibrate_content",
6256
+ params,
6257
+ inputHandler,
6258
+ options
6259
+ );
6260
+ }
6261
+ /** Execute the AdCP check_governance tool. */
6262
+ async checkGovernance(params, inputHandler, options) {
6263
+ return this.executeTaskUnprojected(
6264
+ "check_governance",
6265
+ params,
6266
+ inputHandler,
6267
+ options
6268
+ );
6269
+ }
6270
+ /** Control a seller compliance scenario. Intended for conformance testing. */
6271
+ async complyTestController(params, inputHandler, options) {
6272
+ return this.executeTaskUnprojected(
6273
+ "comply_test_controller",
6274
+ params,
6275
+ inputHandler,
6276
+ options
6277
+ );
6278
+ }
6279
+ /** Rename, pause, resume, cancel, or adjust delivery controls within accepted proposal change rights. */
6280
+ async controlMediaBuy(params, inputHandler, options) {
6281
+ return this.executeTaskUnprojected(
6282
+ "control_media_buy",
6283
+ params,
6284
+ inputHandler,
6285
+ options
6286
+ );
6287
+ }
6288
+ /** Execute the AdCP create_collection_list tool. */
6289
+ async createCollectionList(params, inputHandler, options) {
6290
+ return this.executeTaskUnprojected(
6291
+ "create_collection_list",
6292
+ params,
6293
+ inputHandler,
6294
+ options
6295
+ );
6296
+ }
6297
+ /** Execute the AdCP create_content_standards tool. */
6298
+ async createContentStandards(params, inputHandler, options) {
6299
+ return this.executeTaskUnprojected(
6300
+ "create_content_standards",
6301
+ params,
6302
+ inputHandler,
6303
+ options
6304
+ );
6305
+ }
6306
+ /** Terminally decline one or more proposals and record the buyer's reason. */
6307
+ async declineProposals(params, inputHandler, options) {
6308
+ return this.executeTaskUnprojected(
6309
+ "decline_proposals",
6310
+ params,
6311
+ inputHandler,
6312
+ options
6313
+ );
6314
+ }
6315
+ /** Execute the AdCP delete_collection_list tool. */
6316
+ async deleteCollectionList(params, inputHandler, options) {
6317
+ return this.executeTaskUnprojected(
6318
+ "delete_collection_list",
6319
+ params,
6320
+ inputHandler,
6321
+ options
6322
+ );
6323
+ }
6324
+ /** Retrieve spend, credit or balance status, and invoice history for an operator-billed account. */
6325
+ async getAccountFinancials(params, inputHandler, options) {
6326
+ return this.executeTaskUnprojected(
6327
+ "get_account_financials",
6328
+ params,
6329
+ inputHandler,
6330
+ options
6331
+ );
6332
+ }
6333
+ /** Execute the AdCP get_brand_identity tool. */
6334
+ async getBrandIdentity(params, inputHandler, options) {
6335
+ return this.executeTaskUnprojected(
6336
+ "get_brand_identity",
6337
+ params,
6338
+ inputHandler,
6339
+ options
6340
+ );
6341
+ }
6342
+ /** Execute the AdCP get_collection_list tool. */
6343
+ async getCollectionList(params, inputHandler, options) {
6344
+ return this.executeTaskUnprojected(
6345
+ "get_collection_list",
6346
+ params,
6347
+ inputHandler,
6348
+ options
6349
+ );
6350
+ }
6351
+ /** Execute the AdCP get_content_standards tool. */
6352
+ async getContentStandards(params, inputHandler, options) {
6353
+ return this.executeTaskUnprojected(
6354
+ "get_content_standards",
6355
+ params,
6356
+ inputHandler,
6357
+ options
6358
+ );
6359
+ }
6360
+ /** Evaluate a creative manifest and return scored safety, content, quality, and governance features. */
6361
+ async getCreativeFeatures(params, inputHandler, options) {
6362
+ return this.executeTaskUnprojected(
6363
+ "get_creative_features",
6364
+ params,
6365
+ inputHandler,
6366
+ options
6367
+ );
6368
+ }
6369
+ /** Execute the AdCP get_media_buy_artifacts tool. */
6370
+ async getMediaBuyArtifacts(params, inputHandler, options) {
6371
+ return this.executeTaskUnprojected(
6372
+ "get_media_buy_artifacts",
6373
+ params,
6374
+ inputHandler,
6375
+ options
6376
+ );
6377
+ }
6378
+ /** Check reporting health, enumerate expected periods and all retained revisions, or resolve one exact reporting revision. */
6379
+ async getReportingStatus(params, inputHandler, options) {
6380
+ return this.executeTaskUnprojected(
6381
+ "get_reporting_status",
6382
+ params,
6383
+ inputHandler,
6384
+ options
6385
+ );
6386
+ }
6387
+ /** Execute the AdCP get_rights tool. */
6388
+ async getRights(params, inputHandler, options) {
6389
+ return this.executeTaskUnprojected("get_rights", params, inputHandler, options);
6390
+ }
6391
+ /** Execute the AdCP list_collection_lists tool. */
6392
+ async listCollectionLists(params, inputHandler, options) {
6393
+ return this.executeTaskUnprojected(
6394
+ "list_collection_lists",
6395
+ params,
6396
+ inputHandler,
6397
+ options
6398
+ );
6399
+ }
6400
+ /** Execute the AdCP list_content_standards tool. */
6401
+ async listContentStandards(params, inputHandler, options) {
6402
+ return this.executeTaskUnprojected(
6403
+ "list_content_standards",
6404
+ params,
6405
+ inputHandler,
6406
+ options
6407
+ );
6408
+ }
6409
+ /** Execute the AdCP list_creative_formats tool. */
6410
+ async listCreativeFormats(params, inputHandler, options) {
6411
+ return this.executeTaskUnprojected(
6412
+ "list_creative_formats",
6413
+ params,
6414
+ inputHandler,
6415
+ options
6416
+ );
6417
+ }
6418
+ /** Discover account-scoped creative transformers and their selectable configuration options. */
6419
+ async listTransformers(params, inputHandler, options) {
6420
+ return this.executeTaskUnprojected(
6421
+ "list_transformers",
6422
+ params,
6423
+ inputHandler,
6424
+ options
6425
+ );
6426
+ }
6427
+ /** Log batches of marketing events against a configured event source for measurement and attribution. */
6428
+ async logEvent(params, inputHandler, options) {
6429
+ return this.executeTaskUnprojected("log_event", params, inputHandler, options);
6430
+ }
6431
+ /** Revise draft proposals, finalize them into committed, inventory-held snapshots, or extend a committed hold. */
6432
+ async refineProposals(params, inputHandler, options) {
6433
+ return this.executeTask("refine_proposals", params, inputHandler, options);
6434
+ }
6435
+ /** Execute the AdCP report_plan_adjustment tool. */
6436
+ async reportPlanAdjustment(params, inputHandler, options) {
6437
+ return this.executeTaskUnprojected(
6438
+ "report_plan_adjustment",
6439
+ params,
6440
+ inputHandler,
6441
+ options
6442
+ );
6443
+ }
6444
+ /** Execute the AdCP report_plan_outcome tool. */
6445
+ async reportPlanOutcome(params, inputHandler, options) {
6446
+ return this.executeTaskUnprojected(
6447
+ "report_plan_outcome",
6448
+ params,
6449
+ inputHandler,
6450
+ options
6451
+ );
6452
+ }
6453
+ /** Report vendor-service consumption and final measurements for revenue tracking and billing reconciliation. */
6454
+ async reportUsage(params, inputHandler, options) {
6455
+ return this.executeTaskUnprojected("report_usage", params, inputHandler, options);
6456
+ }
6457
+ /** Ask a seller to create one or more draft media-plan proposals from a campaign brief. */
6458
+ async requestProposals(params, inputHandler, options) {
6459
+ return this.executeTask("request_proposals", params, inputHandler, options);
6460
+ }
6461
+ /** Execute the AdCP search_brands tool. */
6462
+ async searchBrands(params, inputHandler, options) {
6463
+ return this.executeTaskUnprojected("search_brands", params, inputHandler, options);
6464
+ }
6465
+ /** Register, replace, pause, or clear caller-scoped webhooks for agent-level notifications. */
6466
+ async syncAgentNotificationConfigs(params, inputHandler, options) {
6467
+ return this.executeTaskUnprojected(
6468
+ "sync_agent_notification_configs",
6469
+ params,
6470
+ inputHandler,
6471
+ options
6472
+ );
6473
+ }
6474
+ /** List or synchronize buyer-managed account catalog feeds, suppress or restore specific items, and read current availability state. */
6475
+ async syncCatalogs(params, inputHandler, options) {
6476
+ return this.executeTaskUnprojected("sync_catalogs", params, inputHandler, options);
6477
+ }
6478
+ /** List or synchronize account event sources with upsert and optional replacement semantics. */
6479
+ async syncEventSources(params, inputHandler, options) {
6480
+ return this.executeTaskUnprojected(
6481
+ "sync_event_sources",
6482
+ params,
6483
+ inputHandler,
6484
+ options
6485
+ );
6486
+ }
6487
+ /** Bind or replace the governance agent used for approval across specific advertiser accounts. */
6488
+ async syncGovernance(params, inputHandler, options) {
6489
+ return this.executeTaskUnprojected(
6490
+ "sync_governance",
6491
+ params,
6492
+ inputHandler,
6493
+ options
6494
+ );
6495
+ }
6496
+ /** Record a consumer's independently verified reporting totals and destination evidence in the seller ledger. */
6497
+ async syncReportingReceipts(params, inputHandler, options) {
6498
+ return this.executeTaskUnprojected(
6499
+ "sync_reporting_receipts",
6500
+ params,
6501
+ inputHandler,
6502
+ options
6503
+ );
6504
+ }
6505
+ /** Tell a seller whether expected reporting was received, omitted, missing, unreadable, or contradictory. */
6506
+ async syncReportingStatus(params, inputHandler, options) {
6507
+ return this.executeTaskUnprojected(
6508
+ "sync_reporting_status",
6509
+ params,
6510
+ inputHandler,
6511
+ options
6512
+ );
6513
+ }
6514
+ /** Execute the AdCP update_collection_list tool. */
6515
+ async updateCollectionList(params, inputHandler, options) {
6516
+ return this.executeTaskUnprojected(
6517
+ "update_collection_list",
6518
+ params,
6519
+ inputHandler,
6520
+ options
6521
+ );
6522
+ }
6523
+ /** Execute the AdCP update_content_standards tool. */
6524
+ async updateContentStandards(params, inputHandler, options) {
6525
+ return this.executeTaskUnprojected(
6526
+ "update_content_standards",
6527
+ params,
6528
+ inputHandler,
6529
+ options
6530
+ );
6531
+ }
6532
+ /** Execute the AdCP update_rights tool. */
6533
+ async updateRights(params, inputHandler, options) {
6534
+ return this.executeTaskUnprojected("update_rights", params, inputHandler, options);
6535
+ }
6536
+ /** Execute the AdCP validate_content_delivery tool. */
6537
+ async validateContentDelivery(params, inputHandler, options) {
6538
+ return this.executeTaskUnprojected(
6539
+ "validate_content_delivery",
6540
+ params,
6541
+ inputHandler,
6542
+ options
6543
+ );
6544
+ }
6545
+ /** Preflight a creative manifest against canonical formats, products, third-party formats, or agent capabilities. */
6546
+ async validateInput(params, inputHandler, options) {
6547
+ return this.executeTaskUnprojected(
6548
+ "validate_input",
6549
+ params,
6550
+ inputHandler,
6551
+ options
6552
+ );
6553
+ }
6554
+ /** Execute the AdCP validate_property_delivery tool. */
6555
+ async validatePropertyDelivery(params, inputHandler, options) {
6556
+ return this.executeTaskUnprojected(
6557
+ "validate_property_delivery",
6558
+ params,
6559
+ inputHandler,
6560
+ options
6561
+ );
6562
+ }
6563
+ /** Execute the AdCP verify_brand_claim tool. */
6564
+ async verifyBrandClaim(params, inputHandler, options) {
6565
+ return this.executeTaskUnprojected(
6566
+ "verify_brand_claim",
6567
+ params,
6568
+ inputHandler,
6569
+ options
6570
+ );
6571
+ }
6572
+ /** Execute the AdCP verify_brand_claims tool. */
6573
+ async verifyBrandClaims(params, inputHandler, options) {
6574
+ return this.executeTaskUnprojected(
6575
+ "verify_brand_claims",
6576
+ params,
6577
+ inputHandler,
6578
+ options
6579
+ );
6580
+ }
6102
6581
  // ====== PROTOCOL TASKS ======
6103
6582
  /**
6104
6583
  * Get AdCP capabilities
@@ -6108,7 +6587,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6108
6587
  * @param options - Task execution options
6109
6588
  */
6110
6589
  async getAdcpCapabilities(params, inputHandler, options) {
6111
- return withTaskDeadline(
6590
+ return this.withTaskConnectionScope(
6112
6591
  snapshotTaskOptions(options),
6113
6592
  (effectiveOptions) => this.getAdcpCapabilitiesWithinDeadline(params, inputHandler, effectiveOptions)
6114
6593
  );
@@ -6190,7 +6669,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6190
6669
  );
6191
6670
  }
6192
6671
  async resolveAccount(hints = {}, options, onTaskResult) {
6193
- return withTaskDeadline(snapshotTaskOptions(options), async (effectiveOptions) => {
6672
+ return this.withTaskConnectionScope(snapshotTaskOptions(options), async (effectiveOptions) => {
6194
6673
  const capabilities = await this.getCapabilities(effectiveOptions);
6195
6674
  if (capabilities._synthetic || !capabilities.account) {
6196
6675
  throw new AccountRequiredError(
@@ -6630,6 +7109,12 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6630
7109
  return this.getMediaBuyDelivery(params, inputHandler, options);
6631
7110
  case "get_creative_delivery":
6632
7111
  return this.getCreativeDelivery(params, inputHandler, options);
7112
+ case "preview_creative":
7113
+ return this.previewCreative(params, inputHandler, options);
7114
+ case "sync_plans":
7115
+ return this.syncPlans(params, inputHandler, options);
7116
+ case "get_plan_audit_logs":
7117
+ return this.getPlanAuditLogs(params, inputHandler, options);
6633
7118
  case "get_principal":
6634
7119
  return this.getPrincipal(params, inputHandler, options);
6635
7120
  case "sync_principal":
@@ -6666,7 +7151,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6666
7151
  async executeTaskUnprojected(taskName, params, inputHandler, options, handlerName, beforeDispatch) {
6667
7152
  const requestParamsSnapshot = structuredClone(params);
6668
7153
  const taskOptionsSnapshot = snapshotTaskOptions(options);
6669
- return withTaskDeadline(taskOptionsSnapshot, async (effectiveOptions) => {
7154
+ return this.withTaskConnectionScope(taskOptionsSnapshot, async (effectiveOptions) => {
6670
7155
  const result = await this.executeTaskUnprojectedWithinDeadline(
6671
7156
  taskName,
6672
7157
  requestParamsSnapshot,
@@ -6708,6 +7193,11 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6708
7193
  const serverVersion = await this.detectServerVersion(detectionOptions);
6709
7194
  detectedServerVersion = serverVersion;
6710
7195
  detectedServerVersionSynthetic = capabilityDiscoveryContext.capabilities?._synthetic;
7196
+ if ((taskName === "sync_plans" || taskName === "get_plan_audit_logs") && capabilityDiscoveryContext.capabilities?.discoveredTools?.includes(taskName) !== true && capabilityDiscoveryContext.toolSchemas?.has(taskName) !== true) {
7197
+ throw new ConfigurationError(
7198
+ `No governance agent configured and this agent does not advertise ${taskName}. Pass options.agent or configure governance.campaign.agent.`
7199
+ );
7200
+ }
6711
7201
  const negotiatedRelease = this.negotiateCallRelease(capabilityDiscoveryContext.capabilities, options);
6712
7202
  this.assertToolAvailableAtRelease(taskName, negotiatedRelease, capabilityDiscoveryContext.toolSchemas);
6713
7203
  this.assertRequestSupportedByTargetVersion(
@@ -7081,21 +7571,10 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
7081
7571
  });
7082
7572
  });
7083
7573
  }
7084
- // ====== TASK MANAGEMENT & NOTIFICATIONS ======
7085
- /**
7086
- * List all tasks for this agent with detailed information
7087
- *
7088
- * @returns Promise resolving to array of task information
7089
- *
7090
- * @example
7091
- * ```typescript
7092
- * const tasks = await client.listTasks();
7093
- * tasks.forEach(task => {
7094
- * console.log(`${task.taskName}: ${task.status}`);
7095
- * });
7096
- * ```
7097
- */
7098
- async listTasks() {
7574
+ async listTasks(params, inputHandler, options) {
7575
+ if (params !== void 0) {
7576
+ return this.executeTaskUnprojected("list_tasks", params, inputHandler, options);
7577
+ }
7099
7578
  const tasks = await this.executor.getTaskList(this.agent.id);
7100
7579
  return tasks.map(
7101
7580
  (task) => assertNativeRequestProposalsTask(
@@ -7245,10 +7724,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
7245
7724
  * ```
7246
7725
  */
7247
7726
  async getAgentInfo(options) {
7248
- return withMCPConnectionPolicy(
7249
- normalizeTransportOptions(options?.transport ?? this.config.transport),
7250
- () => this.getAgentInfoWithConnectionPolicy(options)
7251
- );
7727
+ return this.withConnectionScope(options, () => this.getAgentInfoWithConnectionPolicy(options));
7252
7728
  }
7253
7729
  async getAgentInfoWithConnectionPolicy(options) {
7254
7730
  throwIfAborted(options?.signal);
@@ -7499,10 +7975,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
7499
7975
  * ```
7500
7976
  */
7501
7977
  async getCapabilities(options) {
7502
- return withMCPConnectionPolicy(
7503
- normalizeTransportOptions(options?.transport ?? this.config.transport),
7504
- () => this.getCapabilitiesWithConnectionPolicy(options)
7505
- );
7978
+ return this.withConnectionScope(options, () => this.getCapabilitiesWithConnectionPolicy(options));
7506
7979
  }
7507
7980
  async getCapabilitiesWithConnectionPolicy(options) {
7508
7981
  throwIfAborted(options?.signal);