@adcp/sdk 17.0.0-beta.0 → 17.0.0-beta.2

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 (277) hide show
  1. package/dist/lib/adapters/keyed-account-store.js +1 -1
  2. package/dist/lib/adapters/keyed-account-store.mjs +1 -1
  3. package/dist/lib/adapters/version/3.0/brand-fields.d.mts +7 -1
  4. package/dist/lib/adapters/version/3.0/brand-fields.d.ts +7 -1
  5. package/dist/lib/adapters/version/3.0/brand-fields.js +139 -3
  6. package/dist/lib/adapters/version/3.0/brand-fields.mjs +136 -2
  7. package/dist/lib/adapters/version/3.0/index.js +6 -0
  8. package/dist/lib/adapters/version/3.0/index.mjs +7 -1
  9. package/dist/lib/adapters/version/3.1/bidding.js +1 -1
  10. package/dist/lib/adapters/version/3.1/bidding.mjs +1 -1
  11. package/dist/lib/adapters/version/types.d.mts +5 -0
  12. package/dist/lib/adapters/version/types.d.ts +5 -0
  13. package/dist/lib/canonical-references/index.js +2 -0
  14. package/dist/lib/canonical-references/index.mjs +2 -0
  15. package/dist/lib/client/account-changes.d.mts +3 -1
  16. package/dist/lib/client/account-changes.d.ts +3 -1
  17. package/dist/lib/client/account-changes.js +22 -2
  18. package/dist/lib/client/account-changes.mjs +22 -2
  19. package/dist/lib/conformance/oracle.js +3 -2
  20. package/dist/lib/conformance/oracle.mjs +3 -2
  21. package/dist/lib/core/AgentClient.d.mts +165 -1
  22. package/dist/lib/core/AgentClient.d.ts +165 -1
  23. package/dist/lib/core/AgentClient.js +446 -8
  24. package/dist/lib/core/AgentClient.mjs +446 -8
  25. package/dist/lib/core/ConversationTypes.d.mts +8 -0
  26. package/dist/lib/core/ConversationTypes.d.ts +8 -0
  27. package/dist/lib/core/ProtocolResponseParser.d.mts +1 -1
  28. package/dist/lib/core/ProtocolResponseParser.d.ts +1 -1
  29. package/dist/lib/core/ProtocolResponseParser.js +28 -18
  30. package/dist/lib/core/ProtocolResponseParser.mjs +11 -1
  31. package/dist/lib/core/ResponseValidator.js +1 -1
  32. package/dist/lib/core/ResponseValidator.mjs +1 -1
  33. package/dist/lib/core/SingleAgentClient.d.mts +122 -7
  34. package/dist/lib/core/SingleAgentClient.d.ts +122 -7
  35. package/dist/lib/core/SingleAgentClient.js +601 -96
  36. package/dist/lib/core/SingleAgentClient.mjs +590 -84
  37. package/dist/lib/core/TaskExecutor.d.mts +7 -0
  38. package/dist/lib/core/TaskExecutor.d.ts +7 -0
  39. package/dist/lib/core/TaskExecutor.js +23 -8
  40. package/dist/lib/core/TaskExecutor.mjs +23 -8
  41. package/dist/lib/core/task-status.d.mts +2 -0
  42. package/dist/lib/core/task-status.d.ts +2 -0
  43. package/dist/lib/core/task-status.js +11 -2
  44. package/dist/lib/core/task-status.mjs +9 -1
  45. package/dist/lib/errors/index.d.mts +22 -0
  46. package/dist/lib/errors/index.d.ts +22 -0
  47. package/dist/lib/errors/index.js +43 -0
  48. package/dist/lib/errors/index.mjs +42 -0
  49. package/dist/lib/identity-3.3/trust.d.mts +1 -4
  50. package/dist/lib/identity-3.3/trust.d.ts +1 -4
  51. package/dist/lib/identity-3.3/trust.js +34 -21
  52. package/dist/lib/identity-3.3/trust.mjs +34 -21
  53. package/dist/lib/identity-3.3/validation.js +5 -3
  54. package/dist/lib/identity-3.3/validation.mjs +6 -4
  55. package/dist/lib/index.d.mts +7 -53
  56. package/dist/lib/index.d.ts +7 -53
  57. package/dist/lib/index.js +13 -0
  58. package/dist/lib/index.mjs +9 -0
  59. package/dist/lib/media-buy/compatibility.js +6 -1
  60. package/dist/lib/media-buy/compatibility.mjs +6 -1
  61. package/dist/lib/protocols/mcp-modern.d.mts +2 -0
  62. package/dist/lib/protocols/mcp-modern.d.ts +2 -0
  63. package/dist/lib/protocols/mcp-modern.js +31 -5
  64. package/dist/lib/protocols/mcp-modern.mjs +31 -5
  65. package/dist/lib/protocols/mcp-scope.d.mts +6 -1
  66. package/dist/lib/protocols/mcp-scope.d.ts +6 -1
  67. package/dist/lib/protocols/mcp-scope.js +25 -3
  68. package/dist/lib/protocols/mcp-scope.mjs +24 -3
  69. package/dist/lib/protocols/mcp.js +12 -6
  70. package/dist/lib/protocols/mcp.mjs +13 -6
  71. package/dist/lib/reporting/inspection.js +1 -0
  72. package/dist/lib/reporting/inspection.mjs +1 -0
  73. package/dist/lib/reporting/ledger/coverage.d.mts +5 -0
  74. package/dist/lib/reporting/ledger/coverage.d.ts +5 -0
  75. package/dist/lib/reporting/ledger/coverage.js +37 -3
  76. package/dist/lib/reporting/ledger/coverage.mjs +36 -3
  77. package/dist/lib/reporting/ledger/handler.js +7 -4
  78. package/dist/lib/reporting/ledger/handler.mjs +7 -4
  79. package/dist/lib/reporting/ledger/producer.js +215 -69
  80. package/dist/lib/reporting/ledger/producer.mjs +217 -70
  81. package/dist/lib/reporting/ledger/schedule.d.mts +2 -2
  82. package/dist/lib/reporting/ledger/schedule.d.ts +2 -2
  83. package/dist/lib/reporting/ledger/schedule.js +8 -5
  84. package/dist/lib/reporting/ledger/schedule.mjs +8 -5
  85. package/dist/lib/reporting/ledger/status-ingest.d.mts +1 -1
  86. package/dist/lib/reporting/ledger/status-ingest.d.ts +1 -1
  87. package/dist/lib/reporting/ledger/status-ingest.js +4 -3
  88. package/dist/lib/reporting/ledger/status-ingest.mjs +4 -3
  89. package/dist/lib/reporting/ledger/types.d.mts +36 -1
  90. package/dist/lib/reporting/ledger/types.d.ts +36 -1
  91. package/dist/lib/reporting/service/index.d.mts +14 -1
  92. package/dist/lib/reporting/service/index.d.ts +14 -1
  93. package/dist/lib/reporting/service/index.js +24 -12
  94. package/dist/lib/reporting/service/index.mjs +24 -12
  95. package/dist/lib/schemas/browser.d.mts +2 -0
  96. package/dist/lib/schemas/browser.d.ts +2 -0
  97. package/dist/lib/schemas/browser.js +3 -0
  98. package/dist/lib/schemas/browser.mjs +2 -0
  99. package/dist/lib/schemas/index.d.mts +5 -3
  100. package/dist/lib/schemas/index.d.ts +5 -3
  101. package/dist/lib/schemas/index.js +5 -0
  102. package/dist/lib/schemas/index.mjs +4 -0
  103. package/dist/lib/server/account-response-identity.d.mts +17 -0
  104. package/dist/lib/server/account-response-identity.d.ts +17 -0
  105. package/dist/lib/server/account-response-identity.js +52 -0
  106. package/dist/lib/server/account-response-identity.mjs +28 -0
  107. package/dist/lib/server/account-sync-contract.js +2 -2
  108. package/dist/lib/server/account-sync-contract.mjs +2 -2
  109. package/dist/lib/server/create-adcp-server.js +33 -20
  110. package/dist/lib/server/create-adcp-server.mjs +36 -12
  111. package/dist/lib/server/decisioning/account.d.mts +36 -10
  112. package/dist/lib/server/decisioning/account.d.ts +36 -10
  113. package/dist/lib/server/decisioning/account.js +33 -14
  114. package/dist/lib/server/decisioning/account.mjs +33 -14
  115. package/dist/lib/server/decisioning/runtime/from-platform.d.mts +5 -5
  116. package/dist/lib/server/decisioning/runtime/from-platform.d.ts +5 -5
  117. package/dist/lib/server/decisioning/runtime/from-platform.js +4 -4
  118. package/dist/lib/server/decisioning/runtime/from-platform.mjs +4 -4
  119. package/dist/lib/server/media-buy-store.d.mts +26 -12
  120. package/dist/lib/server/media-buy-store.d.ts +26 -12
  121. package/dist/lib/server/media-buy-store.js +69 -21
  122. package/dist/lib/server/media-buy-store.mjs +69 -21
  123. package/dist/lib/server/notification-subscriptions/runtime.d.mts +1 -1
  124. package/dist/lib/server/notification-subscriptions/runtime.d.ts +1 -1
  125. package/dist/lib/server/notification-subscriptions/runtime.js +4 -0
  126. package/dist/lib/server/notification-subscriptions/runtime.mjs +4 -0
  127. package/dist/lib/server/responses.js +9 -1
  128. package/dist/lib/server/responses.mjs +9 -1
  129. package/dist/lib/signing/agent-fetch.d.mts +1 -1
  130. package/dist/lib/signing/agent-fetch.d.ts +1 -1
  131. package/dist/lib/signing/agent-fetch.js +3 -3
  132. package/dist/lib/signing/agent-fetch.mjs +3 -3
  133. package/dist/lib/testing/client.d.mts +1 -0
  134. package/dist/lib/testing/client.d.ts +1 -0
  135. package/dist/lib/testing/client.js +6 -5
  136. package/dist/lib/testing/client.mjs +6 -5
  137. package/dist/lib/testing/storyboard/agent-routing.d.mts +5 -2
  138. package/dist/lib/testing/storyboard/agent-routing.d.ts +5 -2
  139. package/dist/lib/testing/storyboard/agent-routing.js +11 -4
  140. package/dist/lib/testing/storyboard/agent-routing.mjs +11 -4
  141. package/dist/lib/testing/storyboard/canonical-format-satisfaction.js +60 -14
  142. package/dist/lib/testing/storyboard/canonical-format-satisfaction.mjs +60 -14
  143. package/dist/lib/testing/storyboard/compliance.d.mts +2 -5
  144. package/dist/lib/testing/storyboard/compliance.d.ts +2 -5
  145. package/dist/lib/testing/storyboard/compliance.js +62 -13
  146. package/dist/lib/testing/storyboard/compliance.mjs +63 -14
  147. package/dist/lib/testing/storyboard/context.d.mts +13 -3
  148. package/dist/lib/testing/storyboard/context.d.ts +13 -3
  149. package/dist/lib/testing/storyboard/context.js +15 -10
  150. package/dist/lib/testing/storyboard/context.mjs +15 -10
  151. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.mts +2 -0
  152. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.ts +2 -0
  153. package/dist/lib/testing/storyboard/request-signing/vector-loader.js +11 -0
  154. package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +10 -0
  155. package/dist/lib/testing/storyboard/runner.js +141 -13
  156. package/dist/lib/testing/storyboard/runner.mjs +141 -13
  157. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  158. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  159. package/dist/lib/testing/storyboard/validations.js +4 -1
  160. package/dist/lib/testing/storyboard/validations.mjs +4 -1
  161. package/dist/lib/testing/test-controller.js +3 -0
  162. package/dist/lib/testing/test-controller.mjs +3 -0
  163. package/dist/lib/types/accept-proposal.d.ts +20 -28
  164. package/dist/lib/types/asset-instances.d.mts +1 -1
  165. package/dist/lib/types/asset-instances.d.ts +1 -1
  166. package/dist/lib/types/buy-products.d.ts +20 -28
  167. package/dist/lib/types/check-governance.d.ts +20 -28
  168. package/dist/lib/types/comply-test-controller.d.ts +20 -28
  169. package/dist/lib/types/control-media-buy.d.ts +20 -28
  170. package/dist/lib/types/core.generated.d.mts +273 -184
  171. package/dist/lib/types/core.generated.d.ts +273 -184
  172. package/dist/lib/types/create-media-buy.d.ts +20 -28
  173. package/dist/lib/types/get-media-buys.d.ts +20 -28
  174. package/dist/lib/types/get-products.d.ts +20 -28
  175. package/dist/lib/types/index.d.mts +6 -1
  176. package/dist/lib/types/index.d.ts +6 -1
  177. package/dist/lib/types/index.js +6 -1
  178. package/dist/lib/types/index.mjs +4 -1
  179. package/dist/lib/types/inline-enums.generated.d.mts +30 -4
  180. package/dist/lib/types/inline-enums.generated.d.ts +30 -4
  181. package/dist/lib/types/inline-enums.generated.js +41 -2
  182. package/dist/lib/types/inline-enums.generated.mjs +28 -2
  183. package/dist/lib/types/list-products.d.ts +20 -28
  184. package/dist/lib/types/list-proposals.d.ts +20 -28
  185. package/dist/lib/types/media-buy-delivery-report.d.mts +6 -0
  186. package/dist/lib/types/media-buy-delivery-report.d.ts +6 -0
  187. package/dist/lib/types/media-buy-delivery-report.js +16 -0
  188. package/dist/lib/types/media-buy-delivery-report.mjs +0 -0
  189. package/dist/lib/types/refine-proposals.d.ts +20 -28
  190. package/dist/lib/types/request-proposals.d.ts +20 -28
  191. package/dist/lib/types/schemas.generated.d.ts +63113 -127273
  192. package/dist/lib/types/schemas.generated.js +759 -770
  193. package/dist/lib/types/schemas.generated.mjs +759 -770
  194. package/dist/lib/types/targeting-keys.generated.d.mts +4 -0
  195. package/dist/lib/types/targeting-keys.generated.d.ts +4 -0
  196. package/dist/lib/types/targeting-keys.generated.js +109 -0
  197. package/dist/lib/types/targeting-keys.generated.mjs +84 -0
  198. package/dist/lib/types/tools.generated.d.mts +2 -68
  199. package/dist/lib/types/tools.generated.d.ts +2 -68
  200. package/dist/lib/types/update-media-buy.d.ts +20 -28
  201. package/dist/lib/utils/adcp-version-config.js +5 -2
  202. package/dist/lib/utils/adcp-version-config.mjs +5 -2
  203. package/dist/lib/utils/envelope-status-compat.d.mts +18 -1
  204. package/dist/lib/utils/envelope-status-compat.d.ts +18 -1
  205. package/dist/lib/utils/envelope-status-compat.js +11 -5
  206. package/dist/lib/utils/envelope-status-compat.mjs +11 -5
  207. package/dist/lib/utils/response-unwrapper.js +18 -10
  208. package/dist/lib/utils/response-unwrapper.mjs +18 -10
  209. package/dist/lib/v2/format-schema/resolver.js +1 -1
  210. package/dist/lib/v2/format-schema/resolver.mjs +1 -1
  211. package/dist/lib/v2/projection/creative-delivery.js +159 -39
  212. package/dist/lib/v2/projection/creative-delivery.mjs +163 -39
  213. package/dist/lib/v2/projection/index.d.mts +1 -0
  214. package/dist/lib/v2/projection/index.d.ts +1 -0
  215. package/dist/lib/v2/projection/index.js +3 -0
  216. package/dist/lib/v2/projection/index.mjs +2 -0
  217. package/dist/lib/v2/projection/legacy-metadata.d.mts +19 -0
  218. package/dist/lib/v2/projection/legacy-metadata.d.ts +19 -0
  219. package/dist/lib/v2/projection/legacy-metadata.js +91 -0
  220. package/dist/lib/v2/projection/legacy-metadata.mjs +86 -0
  221. package/dist/lib/v2/projection/v1-to-v2.d.mts +1 -1
  222. package/dist/lib/v2/projection/v1-to-v2.d.ts +1 -1
  223. package/dist/lib/v2/projection/v1-to-v2.js +12 -9
  224. package/dist/lib/v2/projection/v1-to-v2.mjs +12 -9
  225. package/dist/lib/validation/budget-allocation.d.mts +3 -3
  226. package/dist/lib/validation/budget-allocation.d.ts +3 -3
  227. package/dist/lib/validation/compact-schema.d.mts +27 -0
  228. package/dist/lib/validation/compact-schema.d.ts +27 -0
  229. package/dist/lib/validation/compact-schema.js +276 -0
  230. package/dist/lib/validation/compact-schema.mjs +250 -0
  231. package/dist/lib/validation/media-buy-delivery-report.d.mts +8 -0
  232. package/dist/lib/validation/media-buy-delivery-report.d.ts +8 -0
  233. package/dist/lib/validation/media-buy-delivery-report.js +31 -0
  234. package/dist/lib/validation/media-buy-delivery-report.mjs +7 -0
  235. package/dist/lib/validation/nonempty-array.d.mts +15 -0
  236. package/dist/lib/validation/nonempty-array.d.ts +15 -0
  237. package/dist/lib/validation/nonempty-array.js +41 -0
  238. package/dist/lib/validation/nonempty-array.mjs +7 -0
  239. package/dist/lib/validation/schema-diagnostic-origins.d.mts +21 -0
  240. package/dist/lib/validation/schema-diagnostic-origins.d.ts +21 -0
  241. package/dist/lib/validation/schema-diagnostic-origins.js +193 -0
  242. package/dist/lib/validation/schema-diagnostic-origins.mjs +169 -0
  243. package/dist/lib/validation/schema-loader.js +86 -16
  244. package/dist/lib/validation/schema-loader.mjs +82 -16
  245. package/dist/lib/validation/schema-validator.d.mts +10 -19
  246. package/dist/lib/validation/schema-validator.d.ts +10 -19
  247. package/dist/lib/validation/schema-validator.js +136 -43
  248. package/dist/lib/validation/schema-validator.mjs +140 -44
  249. package/dist/lib/validation/sync-creatives.d.mts +22 -22
  250. package/dist/lib/validation/sync-creatives.d.ts +22 -22
  251. package/dist/lib/version.d.mts +3 -3
  252. package/dist/lib/version.d.ts +3 -3
  253. package/dist/lib/version.js +3 -3
  254. package/dist/lib/version.mjs +3 -3
  255. package/dist/lib/webhooks/index.d.mts +3 -0
  256. package/dist/lib/webhooks/index.d.ts +3 -0
  257. package/dist/lib/webhooks/index.js +3 -0
  258. package/dist/lib/webhooks/index.mjs +2 -0
  259. package/dist/lib/webhooks/media-buy-delivery.d.mts +43 -0
  260. package/dist/lib/webhooks/media-buy-delivery.d.ts +43 -0
  261. package/dist/lib/webhooks/media-buy-delivery.js +119 -0
  262. package/dist/lib/webhooks/media-buy-delivery.mjs +94 -0
  263. package/docs/TYPE-SUMMARY.md +2 -2
  264. package/docs/guides/COLLECTION-FIXTURE-FOUNDATION.md +11 -0
  265. package/docs/guides/DELIVERY-WEBHOOK-PARSING.md +142 -0
  266. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +27 -1
  267. package/docs/guides/REPORTING-LEDGER.md +93 -0
  268. package/docs/guides/REPORTING-STABILITY.md +1 -1
  269. package/docs/guides/TYPED-CLIENT-TOOLS.md +49 -0
  270. package/docs/llms.txt +2 -2
  271. package/docs/migration-14.x-rc-worksheet.md +4 -4
  272. package/docs/migration-16-to-17.md +202 -2
  273. package/docs/migration-6.6-to-6.7.md +14 -0
  274. package/docs/migration-account-change-feed.md +15 -0
  275. package/docs/migration-reporting-storage-package.md +1 -1
  276. package/docs/recipes/verifying-inbound-webhooks.md +18 -2
  277. 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";
@@ -74,6 +85,7 @@ import { getSignedRequestRejection } from "../protocols/signedRequestRejection.m
74
85
  import { withAmbientIdentityHeaders } from "../protocols/mcp-call-context.mjs";
75
86
  import { ProtocolClient, normalizeTransportOptions } from "../protocols/index.mjs";
76
87
  import {
88
+ AgentRateLimitedError,
77
89
  AuthenticationCredentialsRejectedError,
78
90
  AuthenticationRequiredError,
79
91
  ConfigurationError,
@@ -175,6 +187,7 @@ import {
175
187
  selectListedAccount
176
188
  } from "./account-resolution.mjs";
177
189
  import { normalizeRequestParams } from "../utils/request-normalizer.mjs";
190
+ import { getCreativeDeliveryDiagnostics } from "../v2/projection/legacy-metadata.mjs";
178
191
  import { globalAsyncLocalStorage } from "../utils/global-async-local-storage.mjs";
179
192
  import { validateUserAgent } from "../utils/validate-user-agent.mjs";
180
193
  import { resolveWebhookUrl, selectWebhookTemplate } from "./webhook-url.mjs";
@@ -740,10 +753,7 @@ const STANDARD_ADCP_TASK_NAMES = /* @__PURE__ */ new Set([
740
753
  "list_transformers",
741
754
  "preview_creative",
742
755
  "build_creative",
743
- // These standard protocol tools still carry legacy creative `format_id`
744
- // identity through artifacts, manifests, standards, or rights constraints.
745
- // They are available only through explicitly named *Legacy APIs until a
746
- // lossless canonical projection exists.
756
+ // Wire-level creative and content tools also have typed primary methods.
747
757
  "list_content_standards",
748
758
  "get_content_standards",
749
759
  "create_content_standards",
@@ -1027,7 +1037,19 @@ class SingleAgentClient {
1027
1037
  adcpVersion: this.resolvedAdcpVersion,
1028
1038
  ...config.wireAdcpVersion !== void 0 && { wireAdcpVersion: config.wireAdcpVersion },
1029
1039
  ...config.versionEnvelope !== void 0 && { versionEnvelope: config.versionEnvelope },
1030
- transport: config.transport
1040
+ transport: config.transport,
1041
+ resolveTaskStatusTool: async (pollAgent, options) => {
1042
+ const client = pollAgent.id === this.normalizedAgent.id ? this : new SingleAgentClient(pollAgent, {
1043
+ adcpVersion: this.resolvedAdcpVersion,
1044
+ wireAdcpVersion: this.config.wireAdcpVersion,
1045
+ versionEnvelope: this.config.versionEnvelope,
1046
+ userAgent: this.config.userAgent,
1047
+ discoveryCache: this.config.discoveryCache,
1048
+ onTransportActivity: this.config.onTransportActivity,
1049
+ transport: options.transport
1050
+ });
1051
+ return await client.advertisesTool("get_task_status", options) ? "get_task_status" : pollAgent.protocol === "mcp" ? "tasks_get" : "tasks/get";
1052
+ }
1031
1053
  });
1032
1054
  if (config.handlers) {
1033
1055
  this.asyncHandler = new AsyncHandler(config.handlers);
@@ -1835,8 +1857,18 @@ class SingleAgentClient {
1835
1857
  const agent = this.normalizedAgent.protocol === "a2a" ? await this.ensureCanonicalUrlResolved(snapshot) : await this.ensureEndpointDiscovered(snapshot);
1836
1858
  return this.executor.trackTask(agent, snapshot);
1837
1859
  }
1838
- /** Poll through the same discovered/canonical protocol endpoint used for dispatch. @internal */
1839
- async getTaskStatus(taskId, transport, signal, wireOptions) {
1860
+ async getTaskStatus(taskIdOrParams, transportOrHandler, signalOrOptions, wireOptions) {
1861
+ if (typeof taskIdOrParams !== "string") {
1862
+ return this.executeTaskUnprojected(
1863
+ "get_task_status",
1864
+ taskIdOrParams,
1865
+ transportOrHandler,
1866
+ signalOrOptions
1867
+ );
1868
+ }
1869
+ const taskId = taskIdOrParams;
1870
+ const transport = transportOrHandler;
1871
+ const signal = signalOrOptions;
1840
1872
  const transportSnapshot = transport === void 0 ? void 0 : { ...transport };
1841
1873
  const options = { transport: transportSnapshot, signal };
1842
1874
  const agent = this.normalizedAgent.protocol === "a2a" ? await this.ensureCanonicalUrlResolved(options) : await this.ensureEndpointDiscovered(options);
@@ -2309,6 +2341,9 @@ class SingleAgentClient {
2309
2341
  * - A validated MCP protected-resource metadata chain yields NeedsAuthorizationError
2310
2342
  * - Otherwise AuthenticationRequiredError carries the advertised challenge
2311
2343
  *
2344
+ * Rate limiting (429, or 503 with Retry-After) stops probing at that URL and
2345
+ * throws AgentRateLimitedError carrying the status and Retry-After.
2346
+ *
2312
2347
  * Note: This is async and called lazily on first agent interaction
2313
2348
  */
2314
2349
  async discoverMCPEndpoint(providedUri, options) {
@@ -2319,8 +2354,8 @@ class SingleAgentClient {
2319
2354
  }
2320
2355
  async discoverMCPEndpointWithConnectionPolicy(providedUri, options) {
2321
2356
  throwIfAborted(options?.signal);
2322
- const { connectMCPWithFallback } = await import("../protocols/mcp.mjs");
2323
- const { probeModernMCPConnection } = await import("../protocols/mcp-modern.mjs");
2357
+ const { connectMCPWithFallback, withScopedLegacyConnection } = await import("../protocols/mcp.mjs");
2358
+ const { probeModernMCPConnection, retryAfterOf } = await import("../protocols/mcp-modern.mjs");
2324
2359
  const transport = normalizeTransportOptions(options?.transport ?? this.config.transport);
2325
2360
  const usesScopedFetch = this.usesScopedDiscoveryTransport(options);
2326
2361
  const endpointEpoch = this.discoveryEpochSnapshot(options);
@@ -2350,19 +2385,35 @@ class SingleAgentClient {
2350
2385
  }
2351
2386
  return { success: true };
2352
2387
  }
2353
- const client = await connectMCPWithFallback(
2354
- new URL(url),
2355
- authHeaders,
2356
- [],
2357
- "endpoint discovery",
2358
- transport?.trustedFetchFn,
2388
+ const shared = await withScopedLegacyConnection(
2359
2389
  {
2390
+ agentUrl: url,
2391
+ authToken,
2392
+ customHeaders: agentHeaders,
2393
+ authProvider,
2360
2394
  signal: options?.signal,
2361
2395
  requestTimeoutMs: transport?.requestTimeoutMs,
2396
+ fetchFn: transport?.trustedFetchFn,
2362
2397
  allowPrivateIp: transport?.allowPrivateIp
2363
- }
2398
+ },
2399
+ "endpoint discovery",
2400
+ async () => void 0
2364
2401
  );
2365
- await client.close();
2402
+ if (!shared) {
2403
+ const client = await connectMCPWithFallback(
2404
+ new URL(url),
2405
+ authHeaders,
2406
+ [],
2407
+ "endpoint discovery",
2408
+ transport?.trustedFetchFn,
2409
+ {
2410
+ signal: options?.signal,
2411
+ requestTimeoutMs: transport?.requestTimeoutMs,
2412
+ allowPrivateIp: transport?.allowPrivateIp
2413
+ }
2414
+ );
2415
+ await client.close();
2416
+ }
2366
2417
  if (mayRetain()) {
2367
2418
  this.discoveredMcpEra = "legacy";
2368
2419
  this.discoveredMcpEraAt = Date.now();
@@ -2379,7 +2430,8 @@ class SingleAgentClient {
2379
2430
  }
2380
2431
  const errObj = error;
2381
2432
  const status = errObj?.status || errObj?.response?.status || errObj?.cause?.status;
2382
- return { success: false, status, error };
2433
+ const retryAfter = retryAfterOf(error);
2434
+ return { success: false, status, ...retryAfter !== void 0 && { retryAfter }, error };
2383
2435
  }
2384
2436
  };
2385
2437
  const urlsToTry = [];
@@ -2402,6 +2454,9 @@ class SingleAgentClient {
2402
2454
  firstWorkingUrl = url;
2403
2455
  break;
2404
2456
  }
2457
+ if (result.status === 429 || result.status === 503 && result.retryAfter !== void 0) {
2458
+ throw new AgentRateLimitedError(url, result.status, result.retryAfter, result.error);
2459
+ }
2405
2460
  if (result.status === 401) {
2406
2461
  got401 = true;
2407
2462
  first401Error ??= result.error;
@@ -2678,6 +2733,33 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
2678
2733
  };
2679
2734
  }
2680
2735
  }
2736
+ let reportingAdcpVersion;
2737
+ let artifactPayloadValidator;
2738
+ if (registration?.deliveryKind) {
2739
+ try {
2740
+ if (registration.deliveryKind === "reporting") {
2741
+ const { prepareMediaBuyDeliveryWebhookValidation } = require2("../webhooks/media-buy-delivery");
2742
+ reportingAdcpVersion = prepareMediaBuyDeliveryWebhookValidation(
2743
+ options.adcpVersion ?? this.resolvedAdcpVersion
2744
+ ).adcpVersion;
2745
+ } else {
2746
+ const loader = require2("../validation/schema-loader");
2747
+ artifactPayloadValidator = loader.getSchemaValidatorByRef(
2748
+ "content-standards/artifact-webhook-payload.json",
2749
+ this.resolvedAdcpVersion
2750
+ );
2751
+ if (!artifactPayloadValidator)
2752
+ throw new ConfigurationError("Bundled artifact webhook schema is unavailable.");
2753
+ }
2754
+ } catch (cause) {
2755
+ return {
2756
+ ok: false,
2757
+ code: "webhook_verification_unavailable",
2758
+ message: registration.deliveryKind === "reporting" ? "Reporting webhook schema configuration is unavailable." : "Artifact webhook schema configuration is unavailable.",
2759
+ cause
2760
+ };
2761
+ }
2762
+ }
2681
2763
  if (registration?.mode === "rfc9421") {
2682
2764
  const { verifyWebBotAuth, selectSignatureProfile, WebBotAuthError, WebBotAuthUnavailableError } = loadWebBotAuth();
2683
2765
  const requestMethod = options.requestMethod;
@@ -2847,21 +2929,45 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
2847
2929
  return parsedPayload;
2848
2930
  }
2849
2931
  if (registration?.deliveryKind) {
2850
- const loader = require2("../validation/schema-loader");
2851
- const body = parsedPayload.payload;
2932
+ let body = parsedPayload.payload;
2852
2933
  const isReport = registration.deliveryKind === "reporting";
2853
- const payload = isReport ? body.result : body;
2854
- const schemaRef = isReport ? "media-buy/media-buy-delivery-webhook-result.json" : "content-standards/artifact-webhook-payload.json";
2855
- const validator = loader.getSchemaValidatorByRef(schemaRef, this.resolvedAdcpVersion);
2856
- const envelopeValidator = isReport ? loader.getSchemaValidatorByRef("core/mcp-webhook-payload.json", this.resolvedAdcpVersion) : void 0;
2857
- if (!validator || !validator(payload) || isReport && (!envelopeValidator || !envelopeValidator(body) || body.task_type !== "media_buy_delivery"))
2858
- return {
2859
- ok: false,
2860
- code: "webhook_envelope_invalid",
2861
- message: "Authenticated delivery does not match its registered payload kind"
2862
- };
2934
+ let payload;
2935
+ if (isReport) {
2936
+ const { parseMediaBuyDeliveryWebhook } = require2("../webhooks/media-buy-delivery");
2937
+ const report = parseMediaBuyDeliveryWebhook(body, {
2938
+ adcpVersion: reportingAdcpVersion
2939
+ });
2940
+ if (!report.ok) {
2941
+ if (report.code === "webhook_unsupported_payload") {
2942
+ return {
2943
+ ...report,
2944
+ message: "Registered reporting delivery requires a media_buy_delivery MCP envelope.",
2945
+ errors: ["Registered reporting delivery requires a media_buy_delivery MCP envelope."]
2946
+ };
2947
+ }
2948
+ return report;
2949
+ }
2950
+ if (report.wireFormat !== "mcp_envelope") {
2951
+ return {
2952
+ ok: false,
2953
+ code: "webhook_unsupported_payload",
2954
+ message: "Registered reporting delivery requires an MCP envelope."
2955
+ };
2956
+ }
2957
+ body = report.envelope;
2958
+ payload = report.result;
2959
+ } else {
2960
+ payload = body;
2961
+ if (!artifactPayloadValidator || !artifactPayloadValidator(payload)) {
2962
+ return {
2963
+ ok: false,
2964
+ code: "webhook_envelope_invalid",
2965
+ message: "Authenticated delivery does not match its registered payload kind"
2966
+ };
2967
+ }
2968
+ }
2863
2969
  const taskId = isReport && typeof body.task_id === "string" ? body.task_id : typeof body.media_buy_id === "string" ? body.media_buy_id : registration.operationId;
2864
- const operationId = isReport && typeof body.operation_id === "string" ? body.operation_id : registration.operationId;
2970
+ const operationId = registration.operationId;
2865
2971
  const status = isReport && isAdcpStatus(body.status) ? body.status : "completed";
2866
2972
  return {
2867
2973
  ok: true,
@@ -3614,17 +3720,32 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
3614
3720
  timestamp
3615
3721
  }).ok;
3616
3722
  }
3617
- /**
3618
- * Execute task and call appropriate handler on completion
3619
- *
3620
- * Adapts requests for maintained AdCP 3 releases and normalizes product responses.
3621
- */
3723
+ /** One task owns discovery and dispatch sessions unless the caller already owns reuse. */
3724
+ withConnectionScope(options, run, preserveSessionOnResult) {
3725
+ const transport = normalizeTransportOptions(options?.transport ?? this.config.transport);
3726
+ return withMCPConnectionPolicy(
3727
+ transport,
3728
+ () => shouldReuseMCPConnection(transport?.trustedFetchFn !== void 0) ? run() : withMCPConnectionScope(run, {
3729
+ signal: options?.signal,
3730
+ preserveOnInterruption: true,
3731
+ preserveSessionOnResult
3732
+ })
3733
+ );
3734
+ }
3735
+ withTaskConnectionScope(options, run) {
3736
+ return withTaskDeadline(
3737
+ options,
3738
+ (effective) => this.withConnectionScope(effective, () => run(effective), isNonterminalTaskResult)
3739
+ );
3740
+ }
3741
+ /** Execute a task, adapt maintained AdCP 3 releases, and call the completion handler. */
3622
3742
  async executeAndHandle(taskType, handlerName, params, inputHandler, options, transformCompletedResponse, legacyFormatConverter, canonicalRequest, projectionCatalogs) {
3743
+ const projectionDrifts = getCreativeDeliveryDiagnostics(params);
3623
3744
  const requestParamsSnapshot = structuredClone(params);
3624
3745
  const canonicalRequestSnapshot = canonicalRequest === void 0 ? void 0 : structuredClone(canonicalRequest);
3625
3746
  const deferredProjectionCatalogs = projectionCatalogs ? structuredClone(projectionCatalogs) : void 0;
3626
3747
  const taskOptionsSnapshot = snapshotTaskOptions(options);
3627
- return withTaskDeadline(
3748
+ return this.withTaskConnectionScope(
3628
3749
  taskOptionsSnapshot,
3629
3750
  (effectiveOptions) => this.executeAndHandleWithinDeadline(
3630
3751
  taskType,
@@ -3635,11 +3756,12 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
3635
3756
  transformCompletedResponse,
3636
3757
  legacyFormatConverter,
3637
3758
  canonicalRequestSnapshot,
3638
- deferredProjectionCatalogs
3759
+ deferredProjectionCatalogs,
3760
+ projectionDrifts
3639
3761
  )
3640
3762
  );
3641
3763
  }
3642
- async executeAndHandleWithinDeadline(taskType, handlerName, params, inputHandler, options, transformCompletedResponse, legacyFormatConverter, canonicalRequest, projectionCatalogs) {
3764
+ async executeAndHandleWithinDeadline(taskType, handlerName, params, inputHandler, options, transformCompletedResponse, legacyFormatConverter, canonicalRequest, projectionCatalogs, projectionDrifts = []) {
3643
3765
  throwIfAborted(options?.signal);
3644
3766
  const canonicalCreativeInvocation = CANONICAL_CREATIVE_ACTIVITY_TASKS.has(taskType) || canonicalRequest !== void 0;
3645
3767
  params = await this.applyAccountPolicy(taskType, params, options);
@@ -3715,7 +3837,15 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
3715
3837
  if (negotiatedRelease?.downgraded && !options?.skipIdempotencyAutoInject && !options?.skipAccountValidation && !options?.skipRequestValidation) {
3716
3838
  this.executor.validateRequest(taskType, adaptedParams, inputSchemaStripLogs, negotiatedRelease.version);
3717
3839
  }
3718
- const adaptationLogs = [...adaptDriftLogs];
3840
+ const adaptationLogs = [
3841
+ ...projectionDrifts.map((drift) => ({
3842
+ ...drift,
3843
+ taskName: taskType,
3844
+ clientVersion: this.resolvedAdcpVersion,
3845
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
3846
+ })),
3847
+ ...adaptDriftLogs
3848
+ ];
3719
3849
  if (webhookDriftLog) adaptationLogs.push(webhookDriftLog);
3720
3850
  const canonicalInputHandler = this.canonicalCreativeInputHandler(
3721
3851
  taskType,
@@ -4837,8 +4967,15 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
4837
4967
  * stamps it on the version envelope and validates the response against it.
4838
4968
  */
4839
4969
  withNegotiatedRelease(options, negotiated) {
4840
- if (!negotiated?.downgraded) return options;
4841
- return { ...options ?? {}, wireAdcpVersion: negotiated.version, negotiatedAdcpVersion: negotiated.version };
4970
+ if (!negotiated) return options;
4971
+ return {
4972
+ ...options ?? {},
4973
+ selectedAdcpVersion: negotiated.version,
4974
+ ...negotiated.downgraded && {
4975
+ wireAdcpVersion: negotiated.version,
4976
+ negotiatedAdcpVersion: negotiated.version
4977
+ }
4978
+ };
4842
4979
  }
4843
4980
  /**
4844
4981
  * Refuse a tool the negotiated release does not define (a 3.2-only task
@@ -5107,8 +5244,9 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5107
5244
  const adapterKey = resolveAdapterKey(this.resolvedAdcpVersion, perCallCapabilities ?? this.cachedCapabilities);
5108
5245
  if (adapterKey) {
5109
5246
  const versionAdapter = getVersionAdapter(adapterKey, taskType);
5110
- if (versionAdapter?.adaptRequest) {
5111
- const result = versionAdapter.adaptRequest(adapted);
5247
+ const adaptRequest = negotiated ? versionAdapter?.adaptRequest : versionAdapter?.adaptUnnegotiatedRequest ?? versionAdapter?.adaptRequest;
5248
+ if (adaptRequest) {
5249
+ const result = adaptRequest(adapted);
5112
5250
  adapted = result.params;
5113
5251
  if (result.drift) {
5114
5252
  driftLogs.push({
@@ -5170,7 +5308,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5170
5308
  legacyFormatConverter,
5171
5309
  projectionCatalogs ?? this.config.projectionCatalogs
5172
5310
  );
5173
- return withTaskDeadline(snapshotTaskOptions(taskOptions), async (effectiveOptions) => {
5311
+ return this.withTaskConnectionScope(snapshotTaskOptions(taskOptions), async (effectiveOptions) => {
5174
5312
  this.assertRequestSupportedByConfiguredVersion("get_products", params, effectiveOptions);
5175
5313
  let request = await this.applyAccountPolicy("get_products", params, effectiveOptions);
5176
5314
  const legacyAccountId = request.account_id;
@@ -5379,7 +5517,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5379
5517
  ...snapshotTaskOptions(options),
5380
5518
  ...projectionCatalogs !== void 0 && { projectionCatalogs }
5381
5519
  };
5382
- return withTaskDeadline(
5520
+ return this.withTaskConnectionScope(
5383
5521
  snapshottedOptions,
5384
5522
  (effectiveOptions) => this.createMediaBuyWithinDeadline(requestSnapshot, inputHandler, effectiveOptions)
5385
5523
  );
@@ -5538,7 +5676,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5538
5676
  ...snapshotTaskOptions(options),
5539
5677
  ...projectionCatalogs !== void 0 && { projectionCatalogs }
5540
5678
  };
5541
- return withTaskDeadline(
5679
+ return this.withTaskConnectionScope(
5542
5680
  snapshottedOptions,
5543
5681
  (effectiveOptions) => this.updateMediaBuyWithinDeadline(requestSnapshot, inputHandler, effectiveOptions)
5544
5682
  );
@@ -5629,7 +5767,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
5629
5767
  ...projectionCatalogs !== void 0 && { projectionCatalogs },
5630
5768
  ...creativeFormatProjection !== void 0 && { creativeFormatProjection }
5631
5769
  };
5632
- return withTaskDeadline(
5770
+ return this.withTaskConnectionScope(
5633
5771
  snapshottedOptions,
5634
5772
  (effectiveOptions) => this.syncCreativesWithinDeadline(requestSnapshot, inputHandler, effectiveOptions)
5635
5773
  );
@@ -6081,25 +6219,31 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6081
6219
  * Pass an explicit agent via options.agent to override.
6082
6220
  */
6083
6221
  async syncPlans(params, inputHandler, options) {
6222
+ if (!options?.agent && !this.config.governance?.campaign?.agent) {
6223
+ return this.executeTaskUnprojected("sync_plans", params, inputHandler, options);
6224
+ }
6084
6225
  const agent = options?.agent ?? this.getGovernanceAgent();
6085
6226
  this.executor.validateRequest("sync_plans", params);
6086
6227
  return this.executor.executeTask(agent, "sync_plans", params, inputHandler, options);
6087
6228
  }
6088
- /**
6089
- * Get governance audit logs for one or more plans.
6090
- * Returns budget state, channel allocation, per-campaign breakdown, and audit trail.
6091
- *
6092
- * Uses the governance agent from config.governance.campaign.agent by default.
6093
- * Pass an explicit agent via options.agent to override.
6094
- */
6095
- async getPlanAuditLogs(params, options) {
6229
+ async getPlanAuditLogs(params, inputHandlerOrOptions, taskOptions) {
6230
+ const inputHandler = typeof inputHandlerOrOptions === "function" ? inputHandlerOrOptions : void 0;
6231
+ const options = inputHandlerOrOptions === void 0 || typeof inputHandlerOrOptions === "function" ? taskOptions : inputHandlerOrOptions;
6232
+ if (!options?.agent && !this.config.governance?.campaign?.agent) {
6233
+ return this.executeTaskUnprojected(
6234
+ "get_plan_audit_logs",
6235
+ params,
6236
+ inputHandler,
6237
+ options
6238
+ );
6239
+ }
6096
6240
  const agent = options?.agent ?? this.getGovernanceAgent();
6097
6241
  this.executor.validateRequest("get_plan_audit_logs", params);
6098
6242
  return this.executor.executeTask(
6099
6243
  agent,
6100
6244
  "get_plan_audit_logs",
6101
6245
  params,
6102
- void 0,
6246
+ inputHandler,
6103
6247
  options
6104
6248
  );
6105
6249
  }
@@ -6137,6 +6281,374 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6137
6281
  }
6138
6282
  return agent;
6139
6283
  }
6284
+ async advertisesTool(taskName, options) {
6285
+ const context = {};
6286
+ const capabilities = await this.getCapabilities({
6287
+ ...options,
6288
+ [CAPABILITY_DISCOVERY_CONTEXT]: context
6289
+ });
6290
+ return capabilities.discoveredTools?.includes(taskName) === true || context.toolSchemas?.has(taskName) === true;
6291
+ }
6292
+ /** Accept a committed proposal to create or amend a media buy, or apply a negotiated cancellation. */
6293
+ async acceptProposal(params, inputHandler, options) {
6294
+ return this.executeTaskUnprojected(
6295
+ "accept_proposal",
6296
+ params,
6297
+ inputHandler,
6298
+ options
6299
+ );
6300
+ }
6301
+ /** Execute the AdCP acquire_rights tool. */
6302
+ async acquireRights(params, inputHandler, options) {
6303
+ return this.executeTaskUnprojected(
6304
+ "acquire_rights",
6305
+ params,
6306
+ inputHandler,
6307
+ options
6308
+ );
6309
+ }
6310
+ /** Generate, transform, refine, retrieve, or adapt creative manifests for advertised creative capabilities. */
6311
+ async buildCreative(params, inputHandler, options) {
6312
+ return this.executeTaskUnprojected(
6313
+ "build_creative",
6314
+ params,
6315
+ inputHandler,
6316
+ options
6317
+ );
6318
+ }
6319
+ /** Create a media buy directly from published seller products and record its accepted commercial snapshot. */
6320
+ async buyProducts(params, inputHandler, options) {
6321
+ return this.executeTaskUnprojected("buy_products", params, inputHandler, options);
6322
+ }
6323
+ /** Execute the AdCP calibrate_content tool. */
6324
+ async calibrateContent(params, inputHandler, options) {
6325
+ return this.executeTaskUnprojected(
6326
+ "calibrate_content",
6327
+ params,
6328
+ inputHandler,
6329
+ options
6330
+ );
6331
+ }
6332
+ /** Execute the AdCP check_governance tool. */
6333
+ async checkGovernance(params, inputHandler, options) {
6334
+ return this.executeTaskUnprojected(
6335
+ "check_governance",
6336
+ params,
6337
+ inputHandler,
6338
+ options
6339
+ );
6340
+ }
6341
+ /** Control a seller compliance scenario. Intended for conformance testing. */
6342
+ async complyTestController(params, inputHandler, options) {
6343
+ return this.executeTaskUnprojected(
6344
+ "comply_test_controller",
6345
+ params,
6346
+ inputHandler,
6347
+ options
6348
+ );
6349
+ }
6350
+ /** Rename, pause, resume, cancel, or adjust delivery controls within accepted proposal change rights. */
6351
+ async controlMediaBuy(params, inputHandler, options) {
6352
+ return this.executeTaskUnprojected(
6353
+ "control_media_buy",
6354
+ params,
6355
+ inputHandler,
6356
+ options
6357
+ );
6358
+ }
6359
+ /** Execute the AdCP create_collection_list tool. */
6360
+ async createCollectionList(params, inputHandler, options) {
6361
+ return this.executeTaskUnprojected(
6362
+ "create_collection_list",
6363
+ params,
6364
+ inputHandler,
6365
+ options
6366
+ );
6367
+ }
6368
+ /** Execute the AdCP create_content_standards tool. */
6369
+ async createContentStandards(params, inputHandler, options) {
6370
+ return this.executeTaskUnprojected(
6371
+ "create_content_standards",
6372
+ params,
6373
+ inputHandler,
6374
+ options
6375
+ );
6376
+ }
6377
+ /** Terminally decline one or more proposals and record the buyer's reason. */
6378
+ async declineProposals(params, inputHandler, options) {
6379
+ return this.executeTaskUnprojected(
6380
+ "decline_proposals",
6381
+ params,
6382
+ inputHandler,
6383
+ options
6384
+ );
6385
+ }
6386
+ /** Execute the AdCP delete_collection_list tool. */
6387
+ async deleteCollectionList(params, inputHandler, options) {
6388
+ return this.executeTaskUnprojected(
6389
+ "delete_collection_list",
6390
+ params,
6391
+ inputHandler,
6392
+ options
6393
+ );
6394
+ }
6395
+ /** Retrieve spend, credit or balance status, and invoice history for an operator-billed account. */
6396
+ async getAccountFinancials(params, inputHandler, options) {
6397
+ return this.executeTaskUnprojected(
6398
+ "get_account_financials",
6399
+ params,
6400
+ inputHandler,
6401
+ options
6402
+ );
6403
+ }
6404
+ /** Execute the AdCP get_brand_identity tool. */
6405
+ async getBrandIdentity(params, inputHandler, options) {
6406
+ return this.executeTaskUnprojected(
6407
+ "get_brand_identity",
6408
+ params,
6409
+ inputHandler,
6410
+ options
6411
+ );
6412
+ }
6413
+ /** Execute the AdCP get_collection_list tool. */
6414
+ async getCollectionList(params, inputHandler, options) {
6415
+ return this.executeTaskUnprojected(
6416
+ "get_collection_list",
6417
+ params,
6418
+ inputHandler,
6419
+ options
6420
+ );
6421
+ }
6422
+ /** Execute the AdCP get_content_standards tool. */
6423
+ async getContentStandards(params, inputHandler, options) {
6424
+ return this.executeTaskUnprojected(
6425
+ "get_content_standards",
6426
+ params,
6427
+ inputHandler,
6428
+ options
6429
+ );
6430
+ }
6431
+ /** Evaluate a creative manifest and return scored safety, content, quality, and governance features. */
6432
+ async getCreativeFeatures(params, inputHandler, options) {
6433
+ return this.executeTaskUnprojected(
6434
+ "get_creative_features",
6435
+ params,
6436
+ inputHandler,
6437
+ options
6438
+ );
6439
+ }
6440
+ /** Execute the AdCP get_media_buy_artifacts tool. */
6441
+ async getMediaBuyArtifacts(params, inputHandler, options) {
6442
+ return this.executeTaskUnprojected(
6443
+ "get_media_buy_artifacts",
6444
+ params,
6445
+ inputHandler,
6446
+ options
6447
+ );
6448
+ }
6449
+ /** Check reporting health, enumerate expected periods and all retained revisions, or resolve one exact reporting revision. */
6450
+ async getReportingStatus(params, inputHandler, options) {
6451
+ return this.executeTaskUnprojected(
6452
+ "get_reporting_status",
6453
+ params,
6454
+ inputHandler,
6455
+ options
6456
+ );
6457
+ }
6458
+ /** Execute the AdCP get_rights tool. */
6459
+ async getRights(params, inputHandler, options) {
6460
+ return this.executeTaskUnprojected("get_rights", params, inputHandler, options);
6461
+ }
6462
+ /** Execute the AdCP list_collection_lists tool. */
6463
+ async listCollectionLists(params, inputHandler, options) {
6464
+ return this.executeTaskUnprojected(
6465
+ "list_collection_lists",
6466
+ params,
6467
+ inputHandler,
6468
+ options
6469
+ );
6470
+ }
6471
+ /** Execute the AdCP list_content_standards tool. */
6472
+ async listContentStandards(params, inputHandler, options) {
6473
+ return this.executeTaskUnprojected(
6474
+ "list_content_standards",
6475
+ params,
6476
+ inputHandler,
6477
+ options
6478
+ );
6479
+ }
6480
+ /** Execute the AdCP list_creative_formats tool. */
6481
+ async listCreativeFormats(params, inputHandler, options) {
6482
+ return this.executeTaskUnprojected(
6483
+ "list_creative_formats",
6484
+ params,
6485
+ inputHandler,
6486
+ options
6487
+ );
6488
+ }
6489
+ /** Discover account-scoped creative transformers and their selectable configuration options. */
6490
+ async listTransformers(params, inputHandler, options) {
6491
+ return this.executeTaskUnprojected(
6492
+ "list_transformers",
6493
+ params,
6494
+ inputHandler,
6495
+ options
6496
+ );
6497
+ }
6498
+ /** Log batches of marketing events against a configured event source for measurement and attribution. */
6499
+ async logEvent(params, inputHandler, options) {
6500
+ return this.executeTaskUnprojected("log_event", params, inputHandler, options);
6501
+ }
6502
+ /** Revise draft proposals, finalize them into committed, inventory-held snapshots, or extend a committed hold. */
6503
+ async refineProposals(params, inputHandler, options) {
6504
+ return this.executeTask("refine_proposals", params, inputHandler, options);
6505
+ }
6506
+ /** Execute the AdCP report_plan_adjustment tool. */
6507
+ async reportPlanAdjustment(params, inputHandler, options) {
6508
+ return this.executeTaskUnprojected(
6509
+ "report_plan_adjustment",
6510
+ params,
6511
+ inputHandler,
6512
+ options
6513
+ );
6514
+ }
6515
+ /** Execute the AdCP report_plan_outcome tool. */
6516
+ async reportPlanOutcome(params, inputHandler, options) {
6517
+ return this.executeTaskUnprojected(
6518
+ "report_plan_outcome",
6519
+ params,
6520
+ inputHandler,
6521
+ options
6522
+ );
6523
+ }
6524
+ /** Report vendor-service consumption and final measurements for revenue tracking and billing reconciliation. */
6525
+ async reportUsage(params, inputHandler, options) {
6526
+ return this.executeTaskUnprojected("report_usage", params, inputHandler, options);
6527
+ }
6528
+ /** Ask a seller to create one or more draft media-plan proposals from a campaign brief. */
6529
+ async requestProposals(params, inputHandler, options) {
6530
+ return this.executeTask("request_proposals", params, inputHandler, options);
6531
+ }
6532
+ /** Execute the AdCP search_brands tool. */
6533
+ async searchBrands(params, inputHandler, options) {
6534
+ return this.executeTaskUnprojected("search_brands", params, inputHandler, options);
6535
+ }
6536
+ /** Register, replace, pause, or clear caller-scoped webhooks for agent-level notifications. */
6537
+ async syncAgentNotificationConfigs(params, inputHandler, options) {
6538
+ return this.executeTaskUnprojected(
6539
+ "sync_agent_notification_configs",
6540
+ params,
6541
+ inputHandler,
6542
+ options
6543
+ );
6544
+ }
6545
+ /** List or synchronize buyer-managed account catalog feeds, suppress or restore specific items, and read current availability state. */
6546
+ async syncCatalogs(params, inputHandler, options) {
6547
+ return this.executeTaskUnprojected("sync_catalogs", params, inputHandler, options);
6548
+ }
6549
+ /** List or synchronize account event sources with upsert and optional replacement semantics. */
6550
+ async syncEventSources(params, inputHandler, options) {
6551
+ return this.executeTaskUnprojected(
6552
+ "sync_event_sources",
6553
+ params,
6554
+ inputHandler,
6555
+ options
6556
+ );
6557
+ }
6558
+ /** Bind or replace the governance agent used for approval across specific advertiser accounts. */
6559
+ async syncGovernance(params, inputHandler, options) {
6560
+ return this.executeTaskUnprojected(
6561
+ "sync_governance",
6562
+ params,
6563
+ inputHandler,
6564
+ options
6565
+ );
6566
+ }
6567
+ /** Record a consumer's independently verified reporting totals and destination evidence in the seller ledger. */
6568
+ async syncReportingReceipts(params, inputHandler, options) {
6569
+ return this.executeTaskUnprojected(
6570
+ "sync_reporting_receipts",
6571
+ params,
6572
+ inputHandler,
6573
+ options
6574
+ );
6575
+ }
6576
+ /** Tell a seller whether expected reporting was received, omitted, missing, unreadable, or contradictory. */
6577
+ async syncReportingStatus(params, inputHandler, options) {
6578
+ return this.executeTaskUnprojected(
6579
+ "sync_reporting_status",
6580
+ params,
6581
+ inputHandler,
6582
+ options
6583
+ );
6584
+ }
6585
+ /** Execute the AdCP update_collection_list tool. */
6586
+ async updateCollectionList(params, inputHandler, options) {
6587
+ return this.executeTaskUnprojected(
6588
+ "update_collection_list",
6589
+ params,
6590
+ inputHandler,
6591
+ options
6592
+ );
6593
+ }
6594
+ /** Execute the AdCP update_content_standards tool. */
6595
+ async updateContentStandards(params, inputHandler, options) {
6596
+ return this.executeTaskUnprojected(
6597
+ "update_content_standards",
6598
+ params,
6599
+ inputHandler,
6600
+ options
6601
+ );
6602
+ }
6603
+ /** Execute the AdCP update_rights tool. */
6604
+ async updateRights(params, inputHandler, options) {
6605
+ return this.executeTaskUnprojected("update_rights", params, inputHandler, options);
6606
+ }
6607
+ /** Execute the AdCP validate_content_delivery tool. */
6608
+ async validateContentDelivery(params, inputHandler, options) {
6609
+ return this.executeTaskUnprojected(
6610
+ "validate_content_delivery",
6611
+ params,
6612
+ inputHandler,
6613
+ options
6614
+ );
6615
+ }
6616
+ /** Preflight a creative manifest against canonical formats, products, third-party formats, or agent capabilities. */
6617
+ async validateInput(params, inputHandler, options) {
6618
+ return this.executeTaskUnprojected(
6619
+ "validate_input",
6620
+ params,
6621
+ inputHandler,
6622
+ options
6623
+ );
6624
+ }
6625
+ /** Execute the AdCP validate_property_delivery tool. */
6626
+ async validatePropertyDelivery(params, inputHandler, options) {
6627
+ return this.executeTaskUnprojected(
6628
+ "validate_property_delivery",
6629
+ params,
6630
+ inputHandler,
6631
+ options
6632
+ );
6633
+ }
6634
+ /** Execute the AdCP verify_brand_claim tool. */
6635
+ async verifyBrandClaim(params, inputHandler, options) {
6636
+ return this.executeTaskUnprojected(
6637
+ "verify_brand_claim",
6638
+ params,
6639
+ inputHandler,
6640
+ options
6641
+ );
6642
+ }
6643
+ /** Execute the AdCP verify_brand_claims tool. */
6644
+ async verifyBrandClaims(params, inputHandler, options) {
6645
+ return this.executeTaskUnprojected(
6646
+ "verify_brand_claims",
6647
+ params,
6648
+ inputHandler,
6649
+ options
6650
+ );
6651
+ }
6140
6652
  // ====== PROTOCOL TASKS ======
6141
6653
  /**
6142
6654
  * Get AdCP capabilities
@@ -6146,7 +6658,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6146
6658
  * @param options - Task execution options
6147
6659
  */
6148
6660
  async getAdcpCapabilities(params, inputHandler, options) {
6149
- return withTaskDeadline(
6661
+ return this.withTaskConnectionScope(
6150
6662
  snapshotTaskOptions(options),
6151
6663
  (effectiveOptions) => this.getAdcpCapabilitiesWithinDeadline(params, inputHandler, effectiveOptions)
6152
6664
  );
@@ -6228,7 +6740,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6228
6740
  );
6229
6741
  }
6230
6742
  async resolveAccount(hints = {}, options, onTaskResult) {
6231
- return withTaskDeadline(snapshotTaskOptions(options), async (effectiveOptions) => {
6743
+ return this.withTaskConnectionScope(snapshotTaskOptions(options), async (effectiveOptions) => {
6232
6744
  const capabilities = await this.getCapabilities(effectiveOptions);
6233
6745
  if (capabilities._synthetic || !capabilities.account) {
6234
6746
  throw new AccountRequiredError(
@@ -6672,6 +7184,12 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6672
7184
  return this.getMediaBuyDelivery(params, inputHandler, options);
6673
7185
  case "get_creative_delivery":
6674
7186
  return this.getCreativeDelivery(params, inputHandler, options);
7187
+ case "preview_creative":
7188
+ return this.previewCreative(params, inputHandler, options);
7189
+ case "sync_plans":
7190
+ return this.syncPlans(params, inputHandler, options);
7191
+ case "get_plan_audit_logs":
7192
+ return this.getPlanAuditLogs(params, inputHandler, options);
6675
7193
  case "get_principal":
6676
7194
  return this.getPrincipal(params, inputHandler, options);
6677
7195
  case "sync_principal":
@@ -6708,7 +7226,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6708
7226
  async executeTaskUnprojected(taskName, params, inputHandler, options, handlerName, beforeDispatch) {
6709
7227
  const requestParamsSnapshot = structuredClone(params);
6710
7228
  const taskOptionsSnapshot = snapshotTaskOptions(options);
6711
- return withTaskDeadline(taskOptionsSnapshot, async (effectiveOptions) => {
7229
+ return this.withTaskConnectionScope(taskOptionsSnapshot, async (effectiveOptions) => {
6712
7230
  const result = await this.executeTaskUnprojectedWithinDeadline(
6713
7231
  taskName,
6714
7232
  requestParamsSnapshot,
@@ -6750,6 +7268,11 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
6750
7268
  const serverVersion = await this.detectServerVersion(detectionOptions);
6751
7269
  detectedServerVersion = serverVersion;
6752
7270
  detectedServerVersionSynthetic = capabilityDiscoveryContext.capabilities?._synthetic;
7271
+ if ((taskName === "sync_plans" || taskName === "get_plan_audit_logs") && capabilityDiscoveryContext.capabilities?.discoveredTools?.includes(taskName) !== true && capabilityDiscoveryContext.toolSchemas?.has(taskName) !== true) {
7272
+ throw new ConfigurationError(
7273
+ `No governance agent configured and this agent does not advertise ${taskName}. Pass options.agent or configure governance.campaign.agent.`
7274
+ );
7275
+ }
6753
7276
  const negotiatedRelease = this.negotiateCallRelease(capabilityDiscoveryContext.capabilities, options);
6754
7277
  this.assertToolAvailableAtRelease(taskName, negotiatedRelease, capabilityDiscoveryContext.toolSchemas);
6755
7278
  this.assertRequestSupportedByTargetVersion(
@@ -7123,21 +7646,10 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
7123
7646
  });
7124
7647
  });
7125
7648
  }
7126
- // ====== TASK MANAGEMENT & NOTIFICATIONS ======
7127
- /**
7128
- * List all tasks for this agent with detailed information
7129
- *
7130
- * @returns Promise resolving to array of task information
7131
- *
7132
- * @example
7133
- * ```typescript
7134
- * const tasks = await client.listTasks();
7135
- * tasks.forEach(task => {
7136
- * console.log(`${task.taskName}: ${task.status}`);
7137
- * });
7138
- * ```
7139
- */
7140
- async listTasks() {
7649
+ async listTasks(params, inputHandler, options) {
7650
+ if (params !== void 0) {
7651
+ return this.executeTaskUnprojected("list_tasks", params, inputHandler, options);
7652
+ }
7141
7653
  const tasks = await this.executor.getTaskList(this.agent.id);
7142
7654
  return tasks.map(
7143
7655
  (task) => assertNativeRequestProposalsTask(
@@ -7287,10 +7799,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
7287
7799
  * ```
7288
7800
  */
7289
7801
  async getAgentInfo(options) {
7290
- return withMCPConnectionPolicy(
7291
- normalizeTransportOptions(options?.transport ?? this.config.transport),
7292
- () => this.getAgentInfoWithConnectionPolicy(options)
7293
- );
7802
+ return this.withConnectionScope(options, () => this.getAgentInfoWithConnectionPolicy(options));
7294
7803
  }
7295
7804
  async getAgentInfoWithConnectionPolicy(options) {
7296
7805
  throwIfAborted(options?.signal);
@@ -7541,10 +8050,7 @@ Hint: this usually means agent_uri does not include the MCP endpoint path. The S
7541
8050
  * ```
7542
8051
  */
7543
8052
  async getCapabilities(options) {
7544
- return withMCPConnectionPolicy(
7545
- normalizeTransportOptions(options?.transport ?? this.config.transport),
7546
- () => this.getCapabilitiesWithConnectionPolicy(options)
7547
- );
8053
+ return this.withConnectionScope(options, () => this.getCapabilitiesWithConnectionPolicy(options));
7548
8054
  }
7549
8055
  async getCapabilitiesWithConnectionPolicy(options) {
7550
8056
  throwIfAborted(options?.signal);