@apifuse/provider-sdk 2.2.0-beta.5 → 2.2.0-beta.51

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 (368) hide show
  1. package/AUTHORING.md +537 -33
  2. package/CHANGELOG.md +205 -1
  3. package/README.md +83 -22
  4. package/SUBMISSION.md +2 -2
  5. package/bin/apifuse-check.ts +165 -11
  6. package/bin/apifuse-dev.ts +57 -13
  7. package/bin/apifuse-migrate-operation-declaration.ts +55 -0
  8. package/bin/apifuse-migrate-shape.ts +202 -0
  9. package/bin/apifuse-pack-check.ts +22 -2
  10. package/bin/apifuse-pack-smoke.ts +57 -2
  11. package/bin/apifuse-pack-types.ts +357 -38
  12. package/bin/apifuse-perf.ts +14 -13
  13. package/bin/apifuse-record.ts +709 -72
  14. package/bin/apifuse-submit-check.ts +2344 -324
  15. package/bin/apifuse-sync-assets.ts +117 -0
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/dist/auth-turn/index.d.ts +3 -3
  18. package/dist/auth-turn/index.js +1 -1
  19. package/dist/auth.d.ts +14 -0
  20. package/dist/auth.js +67 -0
  21. package/dist/ceremonies/index.d.ts +16 -0
  22. package/dist/ceremonies/index.js +141 -36
  23. package/dist/cli/commands.d.ts +1 -1
  24. package/dist/cli/commands.js +27 -0
  25. package/dist/cli/create.d.ts +4 -1
  26. package/dist/cli/create.js +42 -37
  27. package/dist/cli/migrate-operation-declaration.d.ts +59 -0
  28. package/dist/cli/migrate-operation-declaration.js +1249 -0
  29. package/dist/cli/migrate-operation-shape.d.ts +44 -0
  30. package/dist/cli/migrate-operation-shape.js +113 -0
  31. package/dist/cli/migrate-provider-shape.d.ts +52 -0
  32. package/dist/cli/migrate-provider-shape.js +578 -0
  33. package/dist/cli/prompt-assets.d.ts +80 -0
  34. package/dist/cli/prompt-assets.js +743 -0
  35. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  36. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  37. package/dist/cli/templates/provider/README.md.tpl +5 -5
  38. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  39. package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
  40. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  41. package/dist/config/loader.d.ts +179 -16
  42. package/dist/config/loader.js +435 -127
  43. package/dist/contract-serialization.js +4 -8
  44. package/dist/contract-types.d.ts +12 -5
  45. package/dist/contract.js +24 -10
  46. package/dist/declaration-validation.d.ts +33 -0
  47. package/dist/declaration-validation.js +266 -0
  48. package/dist/define.d.ts +66 -29
  49. package/dist/define.js +778 -69
  50. package/dist/dev.d.ts +3 -0
  51. package/dist/dev.js +1 -1
  52. package/dist/engine.d.ts +78 -0
  53. package/dist/engine.js +133 -0
  54. package/dist/error-observability.d.ts +7 -0
  55. package/dist/error-observability.js +61 -0
  56. package/dist/error-resolution.d.ts +4 -0
  57. package/dist/error-resolution.js +122 -0
  58. package/dist/errors.d.ts +33 -0
  59. package/dist/errors.js +40 -0
  60. package/dist/fixture-sanitization.d.ts +28 -0
  61. package/dist/fixture-sanitization.js +227 -0
  62. package/dist/health-scenario.d.ts +1842 -0
  63. package/dist/health-scenario.js +624 -0
  64. package/dist/index.d.ts +21 -10
  65. package/dist/index.js +12 -7
  66. package/dist/lint.d.ts +23 -11
  67. package/dist/lint.js +572 -69
  68. package/dist/native-address.d.ts +43 -0
  69. package/dist/native-address.js +281 -0
  70. package/dist/native-egress-policy.d.ts +31 -0
  71. package/dist/native-egress-policy.js +288 -0
  72. package/dist/observability.d.ts +5 -2
  73. package/dist/observability.js +48 -1
  74. package/dist/provider.d.ts +10 -2
  75. package/dist/provider.js +4 -1
  76. package/dist/runtime/auth-flow.d.ts +5 -1
  77. package/dist/runtime/auth-flow.js +6 -0
  78. package/dist/runtime/browser.d.ts +1 -0
  79. package/dist/runtime/browser.js +492 -49
  80. package/dist/runtime/cache.d.ts +1 -0
  81. package/dist/runtime/cache.js +169 -15
  82. package/dist/runtime/choice-wordlist.d.ts +9 -0
  83. package/dist/runtime/choice-wordlist.js +138 -0
  84. package/dist/runtime/choice.d.ts +13 -1
  85. package/dist/runtime/choice.js +490 -102
  86. package/dist/runtime/chrome149-header-order.d.ts +58 -0
  87. package/dist/runtime/chrome149-header-order.js +289 -0
  88. package/dist/runtime/env.js +12 -0
  89. package/dist/runtime/executor.d.ts +3 -2
  90. package/dist/runtime/executor.js +26 -25
  91. package/dist/runtime/http.d.ts +1 -0
  92. package/dist/runtime/http.js +515 -53
  93. package/dist/runtime/insights.js +2 -2
  94. package/dist/runtime/instrumentation.d.ts +2 -2
  95. package/dist/runtime/instrumentation.js +366 -8
  96. package/dist/runtime/native-network-errors.d.ts +33 -0
  97. package/dist/runtime/native-network-errors.js +69 -0
  98. package/dist/runtime/native-network.d.ts +96 -0
  99. package/dist/runtime/native-network.js +1232 -0
  100. package/dist/runtime/ocr.d.ts +29 -0
  101. package/dist/runtime/ocr.js +440 -0
  102. package/dist/runtime/otlp.d.ts +71 -2
  103. package/dist/runtime/otlp.js +397 -16
  104. package/dist/runtime/proxy-errors.js +6 -2
  105. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  106. package/dist/runtime/proxy-nodemaven.js +146 -0
  107. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  108. package/dist/runtime/proxy-telemetry.js +154 -47
  109. package/dist/runtime/redirects.d.ts +29 -0
  110. package/dist/runtime/redirects.js +36 -0
  111. package/dist/runtime/redis.d.ts +1 -1
  112. package/dist/runtime/redis.js +4 -2
  113. package/dist/runtime/request-options.d.ts +68 -1
  114. package/dist/runtime/request-options.js +548 -0
  115. package/dist/runtime/resolver-config.d.ts +6 -0
  116. package/dist/runtime/resolver-config.js +6 -0
  117. package/dist/runtime/resolver-public.d.ts +1 -0
  118. package/dist/runtime/resolver-public.js +1 -0
  119. package/dist/runtime/resolver-shared.d.ts +14 -0
  120. package/dist/runtime/resolver-shared.js +12 -0
  121. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  122. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  123. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  124. package/dist/runtime/resolver-vendors/browser.js +377 -0
  125. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  126. package/dist/runtime/resolver-vendors/capsolver.js +531 -0
  127. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  128. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  129. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  130. package/dist/runtime/resolver-vendors/twocaptcha.js +408 -0
  131. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  132. package/dist/runtime/resolver-vendors/types.js +96 -0
  133. package/dist/runtime/resolver.d.ts +72 -0
  134. package/dist/runtime/resolver.js +771 -0
  135. package/dist/runtime/secrets.d.ts +27 -0
  136. package/dist/runtime/secrets.js +51 -0
  137. package/dist/runtime/state.d.ts +3 -0
  138. package/dist/runtime/state.js +277 -71
  139. package/dist/runtime/stealth-cookies.d.ts +20 -0
  140. package/dist/runtime/stealth-cookies.js +111 -0
  141. package/dist/runtime/stealth.d.ts +41 -5
  142. package/dist/runtime/stealth.js +997 -291
  143. package/dist/runtime/stt.js +1 -12
  144. package/dist/runtime/timeout.d.ts +5 -0
  145. package/dist/runtime/timeout.js +12 -0
  146. package/dist/runtime/trace-config.d.ts +12 -0
  147. package/dist/runtime/trace-config.js +62 -0
  148. package/dist/runtime/trace.d.ts +5 -0
  149. package/dist/runtime/trace.js +43 -10
  150. package/dist/serve.d.ts +1 -1
  151. package/dist/serve.js +1 -1
  152. package/dist/server/error-observability.d.ts +1 -0
  153. package/dist/server/error-observability.js +1 -0
  154. package/dist/server/index.d.ts +5 -2
  155. package/dist/server/index.js +2 -2
  156. package/dist/server/self-test-input-tokens.d.ts +2 -1
  157. package/dist/server/self-test-input-tokens.js +18 -14
  158. package/dist/server/self-test.d.ts +14 -3
  159. package/dist/server/self-test.js +129 -58
  160. package/dist/server/serve-implementation.d.ts +230 -0
  161. package/dist/server/serve-implementation.js +2265 -0
  162. package/dist/server/serve.d.ts +1 -70
  163. package/dist/server/serve.js +1 -1131
  164. package/dist/server/trace-output.d.ts +6 -0
  165. package/dist/server/trace-output.js +79 -0
  166. package/dist/server/types.d.ts +30 -5
  167. package/dist/server/types.js +13 -1
  168. package/dist/stateful/errors.d.ts +19 -0
  169. package/dist/stateful/errors.js +24 -0
  170. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  171. package/dist/stateful/http-provider-event-emitter.js +237 -0
  172. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  173. package/dist/stateful/http-session-owner-registry.js +210 -0
  174. package/dist/stateful/index.d.ts +18 -0
  175. package/dist/stateful/index.js +18 -0
  176. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  177. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  178. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  179. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  180. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  181. package/dist/stateful/provider-event-pipeline.js +1 -0
  182. package/dist/stateful/provider-events.d.ts +101 -0
  183. package/dist/stateful/provider-events.js +289 -0
  184. package/dist/stateful/session-key.d.ts +15 -0
  185. package/dist/stateful/session-key.js +86 -0
  186. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  187. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  188. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  189. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  190. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  191. package/dist/stateful/stateful-provider-adapter.js +287 -0
  192. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  193. package/dist/stateful/stateful-provider-observability.js +161 -0
  194. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  195. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  196. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  197. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  198. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  199. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  200. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  201. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  202. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  203. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  204. package/dist/stateful-signing.d.ts +18 -0
  205. package/dist/stateful-signing.js +27 -0
  206. package/dist/stealth/profiles.d.ts +9 -4
  207. package/dist/stealth/profiles.js +160 -211
  208. package/dist/stream-evidence.d.ts +74 -0
  209. package/dist/stream-evidence.js +785 -0
  210. package/dist/stream.js +7 -1
  211. package/dist/testing/index.d.ts +2 -1
  212. package/dist/testing/index.js +2 -1
  213. package/dist/testing/run.d.ts +32 -2
  214. package/dist/testing/run.js +489 -21
  215. package/dist/trace-sanitization.d.ts +5 -0
  216. package/dist/trace-sanitization.js +45 -0
  217. package/dist/types.d.ts +673 -131
  218. package/dist/types.js +1 -0
  219. package/package.json +45 -5
  220. package/src/auth-turn/index.ts +1 -1
  221. package/src/auth.ts +118 -0
  222. package/src/ceremonies/index.ts +189 -46
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +15 -0
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +9 -0
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +24 -0
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
  246. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
  247. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
  248. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
  249. package/src/cli/commands.ts +33 -0
  250. package/src/cli/create.ts +50 -37
  251. package/src/cli/migrate-operation-declaration.ts +1751 -0
  252. package/src/cli/migrate-operation-shape.ts +184 -0
  253. package/src/cli/migrate-provider-shape.ts +772 -0
  254. package/src/cli/prompt-assets.ts +865 -0
  255. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  256. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  257. package/src/cli/templates/provider/README.md.tpl +5 -5
  258. package/src/cli/templates/provider/index.ts.tpl +6 -3
  259. package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
  260. package/src/cli/templates/provider/provider.json.tpl +6 -0
  261. package/src/config/loader.ts +690 -163
  262. package/src/contract-serialization.ts +5 -7
  263. package/src/contract-types.ts +12 -5
  264. package/src/contract.ts +24 -10
  265. package/src/declaration-validation.ts +330 -0
  266. package/src/define.ts +1048 -131
  267. package/src/dev.ts +4 -1
  268. package/src/engine.ts +279 -0
  269. package/src/error-observability.ts +64 -0
  270. package/src/error-resolution.ts +127 -0
  271. package/src/errors.ts +68 -0
  272. package/src/fixture-sanitization.ts +264 -0
  273. package/src/health-scenario.ts +875 -0
  274. package/src/index.ts +220 -13
  275. package/src/lint.ts +698 -90
  276. package/src/native-address.ts +340 -0
  277. package/src/native-egress-policy.ts +358 -0
  278. package/src/observability.ts +51 -1
  279. package/src/provider.ts +161 -3
  280. package/src/runtime/auth-flow.ts +12 -0
  281. package/src/runtime/browser.ts +661 -63
  282. package/src/runtime/cache.ts +189 -14
  283. package/src/runtime/choice-wordlist.ts +145 -0
  284. package/src/runtime/choice.ts +631 -120
  285. package/src/runtime/chrome149-header-order.ts +330 -0
  286. package/src/runtime/env.ts +13 -0
  287. package/src/runtime/executor.ts +43 -31
  288. package/src/runtime/http.ts +641 -61
  289. package/src/runtime/insights.ts +2 -2
  290. package/src/runtime/instrumentation.ts +520 -15
  291. package/src/runtime/native-network-errors.ts +99 -0
  292. package/src/runtime/native-network.ts +1605 -0
  293. package/src/runtime/ocr.ts +523 -0
  294. package/src/runtime/otlp.ts +467 -21
  295. package/src/runtime/proxy-errors.ts +12 -4
  296. package/src/runtime/proxy-nodemaven.ts +221 -0
  297. package/src/runtime/proxy-telemetry.ts +244 -75
  298. package/src/runtime/redirects.ts +66 -0
  299. package/src/runtime/redis.ts +7 -2
  300. package/src/runtime/request-options.ts +680 -1
  301. package/src/runtime/resolver-config.ts +6 -0
  302. package/src/runtime/resolver-public.ts +23 -0
  303. package/src/runtime/resolver-shared.ts +33 -0
  304. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  305. package/src/runtime/resolver-vendors/browser.ts +533 -0
  306. package/src/runtime/resolver-vendors/capsolver.ts +707 -0
  307. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  308. package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
  309. package/src/runtime/resolver-vendors/types.ts +212 -0
  310. package/src/runtime/resolver.ts +1157 -0
  311. package/src/runtime/secrets.ts +64 -0
  312. package/src/runtime/state.ts +394 -77
  313. package/src/runtime/stealth-cookies.ts +132 -0
  314. package/src/runtime/stealth.ts +1280 -336
  315. package/src/runtime/stt.ts +1 -19
  316. package/src/runtime/timeout.ts +18 -0
  317. package/src/runtime/trace-config.ts +78 -0
  318. package/src/runtime/trace.ts +57 -17
  319. package/src/serve.ts +6 -1
  320. package/src/server/error-observability.ts +1 -0
  321. package/src/server/index.ts +34 -2
  322. package/src/server/self-test-input-tokens.ts +29 -14
  323. package/src/server/self-test.ts +191 -68
  324. package/src/server/serve-implementation.ts +3378 -0
  325. package/src/server/serve.ts +1 -1632
  326. package/src/server/trace-output.ts +129 -0
  327. package/src/server/types.ts +13 -1
  328. package/src/stateful/README.md +146 -0
  329. package/src/stateful/errors.ts +35 -0
  330. package/src/stateful/http-provider-event-emitter.ts +314 -0
  331. package/src/stateful/http-session-owner-registry.ts +306 -0
  332. package/src/stateful/index.ts +18 -0
  333. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  334. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  335. package/src/stateful/provider-event-pipeline.ts +61 -0
  336. package/src/stateful/provider-events.ts +462 -0
  337. package/src/stateful/session-key.ts +111 -0
  338. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  339. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  340. package/src/stateful/stateful-provider-adapter.ts +562 -0
  341. package/src/stateful/stateful-provider-observability.ts +261 -0
  342. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  343. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  344. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  345. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  346. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  347. package/src/stateful-signing.ts +46 -0
  348. package/src/stealth/profiles.ts +202 -231
  349. package/src/stream-evidence.ts +988 -0
  350. package/src/stream.ts +8 -1
  351. package/src/testing/index.ts +10 -1
  352. package/src/testing/run.ts +658 -15
  353. package/src/trace-sanitization.ts +63 -0
  354. package/src/types.ts +788 -174
  355. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  356. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  357. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  358. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  359. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  360. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  361. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  362. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  363. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  364. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  365. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  366. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  367. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  368. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
@@ -27,7 +27,7 @@ const DNS_WARN_MS = 5;
27
27
  const BROWSER_IDLE_MS = 5_000;
28
28
  const REFRESH_WARN_RATE = 0.1;
29
29
 
30
- const TLS_REUSE_FIX = `const session = ctx.stealth.createSession({ profile: 'chrome-146' });
30
+ const TLS_REUSE_FIX = `const session = ctx.stealth.createSession({ stealth: { browser: 'chrome', os: 'macos' } });
31
31
  const resp = await session.fetch(url, opts);`;
32
32
 
33
33
  const TRANSFORM_FIX = `transformResponse: (raw) => {
@@ -39,7 +39,7 @@ const LARGE_RESPONSE_FIX = `const resp = await ctx.http.get('/items', {
39
39
  });`;
40
40
 
41
41
  const DNS_FIX = `// Enable DNS caching or reuse a long-lived session per host.
42
- const session = ctx.stealth.createSession({ profile: 'chrome-146' });
42
+ const session = ctx.stealth.createSession({ stealth: { browser: 'chrome', os: 'macos' } });
43
43
  await session.fetch(url, opts);`;
44
44
 
45
45
  const PROXY_FIX = `// Re-check whether this operation really needs a proxy.
@@ -1,20 +1,60 @@
1
- import type { ProviderContext } from "../types.js";
1
+ import type {
2
+ HttpStreamResponse,
3
+ ProviderContext,
4
+ RequestOptions,
5
+ SseMessage,
6
+ StealthSession,
7
+ StealthRedirectRunResult,
8
+ } from "../types.js";
9
+ import { readableBytes, readableLines, readableTextChunks } from "../stream.js";
10
+ import {
11
+ parseHttpRequestInvocation,
12
+ isSensitiveKey,
13
+ redactSensitiveError,
14
+ redactSensitiveText,
15
+ redactUrlQueryParams,
16
+ requestOptionsFromHttpInvocation,
17
+ serializeRequestUrl,
18
+ type SerializedRequestUrl,
19
+ } from "./request-options.js";
2
20
  import {
3
21
  type CreateTraceContextOptions,
4
22
  createTraceContext,
5
23
  getTraceRecorder,
6
24
  type TraceContext,
7
25
  } from "./trace.js";
26
+ import { RESOLVER_INSTRUMENTATION_METADATA } from "./resolver-shared.js";
8
27
 
9
28
  export interface InstrumentationOptions extends CreateTraceContextOptions {}
10
29
 
11
- export type InstrumentedProviderContext<T extends ProviderContext> = Omit<T, "trace"> & {
30
+ export type InstrumentedProviderContext<T extends Pick<ProviderContext, "trace">> = Omit<
31
+ T,
32
+ "trace"
33
+ > & {
12
34
  trace: TraceContext;
13
35
  };
14
36
 
15
- type InstrumentedNamespace = "http" | "stealth" | "browser" | "session" | "state";
37
+ type InstrumentedNamespace = "http" | "stealth" | "browser" | "session" | "state" | "resolver";
16
38
 
17
39
  const BROWSER_PAGE_METHODS = new Set(["goto", "fill", "click", "type", "waitForSelector"]);
40
+ const DIAGNOSTIC_BASE_URL = "http://apifuse-instrumentation.invalid";
41
+
42
+ type RequestDiagnostics = {
43
+ diagnosticUrlDegraded?: boolean;
44
+ requestId?: string;
45
+ serializedUrl?: SerializedRequestUrl;
46
+ sensitiveParamNames: readonly string[];
47
+ sensitiveValues: readonly string[];
48
+ traceUrl?: string;
49
+ };
50
+
51
+ function isThenable(value: unknown): value is PromiseLike<unknown> {
52
+ return (
53
+ (typeof value === "object" || typeof value === "function") &&
54
+ value !== null &&
55
+ typeof (value as { then?: unknown }).then === "function"
56
+ );
57
+ }
18
58
 
19
59
  function getErrorStatus(error: unknown): number | undefined {
20
60
  if (
@@ -84,12 +124,231 @@ function getUrl(
84
124
  return undefined;
85
125
  }
86
126
 
127
+ function requestOptionsForInvocation(
128
+ namespace: InstrumentedNamespace,
129
+ methodName: string,
130
+ args: readonly unknown[],
131
+ ): RequestOptions | undefined {
132
+ if (namespace === "http") {
133
+ const invocation = parseHttpRequestInvocation(methodName, [...args]);
134
+ return invocation ? requestOptionsFromHttpInvocation(invocation) : undefined;
135
+ }
136
+ if (namespace !== "stealth" || methodName !== "fetch" || typeof args[0] !== "string") {
137
+ return undefined;
138
+ }
139
+ const options = args[1];
140
+ return options !== null && typeof options === "object" && !Array.isArray(options)
141
+ ? (options as RequestOptions)
142
+ : undefined;
143
+ }
144
+
145
+ function fallbackSensitiveValues(options?: RequestOptions): readonly string[] {
146
+ const sensitiveParams = options?.sensitiveParams;
147
+ if (!sensitiveParams || typeof sensitiveParams !== "object") return [];
148
+ return Object.values(sensitiveParams).map(String);
149
+ }
150
+
151
+ function stripDiagnosticBase(url: string): string {
152
+ return url.startsWith(DIAGNOSTIC_BASE_URL) ? url.slice(DIAGNOSTIC_BASE_URL.length) || "/" : url;
153
+ }
154
+
155
+ function serializeDiagnosticUrl(
156
+ url: string,
157
+ options?: RequestOptions,
158
+ ): { degraded: boolean; serializedUrl: SerializedRequestUrl } {
159
+ try {
160
+ return {
161
+ degraded: false,
162
+ serializedUrl: serializeRequestUrl(url, options?.params, options?.sensitiveParams),
163
+ };
164
+ } catch {
165
+ try {
166
+ const absoluteUrl = new URL(url, DIAGNOSTIC_BASE_URL).toString();
167
+ const serialized = serializeRequestUrl(
168
+ absoluteUrl,
169
+ options?.params,
170
+ options?.sensitiveParams,
171
+ );
172
+ return {
173
+ degraded: false,
174
+ serializedUrl: {
175
+ requestUrl: stripDiagnosticBase(serialized.requestUrl),
176
+ redactedUrl: stripDiagnosticBase(serialized.redactedUrl),
177
+ sensitiveValues: serialized.sensitiveValues,
178
+ },
179
+ };
180
+ } catch {
181
+ const sensitiveParamNames = Object.keys(options?.sensitiveParams ?? {});
182
+ const structural = redactUrlQueryParams(url, sensitiveParamNames);
183
+ return {
184
+ degraded: true,
185
+ serializedUrl: {
186
+ requestUrl: url,
187
+ redactedUrl: structural.redactedUrl,
188
+ sensitiveValues: [
189
+ ...new Set([...fallbackSensitiveValues(options), ...structural.sensitiveValues]),
190
+ ],
191
+ },
192
+ };
193
+ }
194
+ }
195
+ }
196
+
197
+ function snapshotRequestDiagnostics(
198
+ namespace: InstrumentedNamespace,
199
+ methodName: string,
200
+ args: readonly unknown[],
201
+ ): RequestDiagnostics {
202
+ const options = requestOptionsForInvocation(namespace, methodName, args);
203
+ const url = typeof args[0] === "string" ? args[0] : undefined;
204
+ const hasSensitiveParams = Boolean(
205
+ options?.sensitiveParams && Object.keys(options.sensitiveParams).length > 0,
206
+ );
207
+ const sensitiveParamNames = Object.keys(options?.sensitiveParams ?? {});
208
+ const diagnosticUrl =
209
+ hasSensitiveParams && url ? serializeDiagnosticUrl(url, options) : undefined;
210
+ const traceUrl =
211
+ hasSensitiveParams && url
212
+ ? serializeDiagnosticUrl(url, { sensitiveParams: options?.sensitiveParams }).serializedUrl
213
+ .redactedUrl
214
+ : undefined;
215
+ return {
216
+ ...(diagnosticUrl?.degraded ? { diagnosticUrlDegraded: true } : {}),
217
+ ...(hasSensitiveParams ? { requestId: crypto.randomUUID() } : {}),
218
+ serializedUrl: diagnosticUrl?.serializedUrl,
219
+ sensitiveParamNames,
220
+ sensitiveValues:
221
+ diagnosticUrl?.serializedUrl.sensitiveValues ?? fallbackSensitiveValues(options),
222
+ traceUrl,
223
+ };
224
+ }
225
+
226
+ function sanitizeRequestError(error: unknown, diagnostics: RequestDiagnostics): unknown {
227
+ return redactSensitiveError(
228
+ error,
229
+ diagnostics.sensitiveValues,
230
+ diagnostics.serializedUrl?.requestUrl,
231
+ diagnostics.serializedUrl?.redactedUrl,
232
+ );
233
+ }
234
+
235
+ function isHttpStreamResponse(value: unknown): value is HttpStreamResponse {
236
+ return (
237
+ typeof value === "object" &&
238
+ value !== null &&
239
+ "body" in value &&
240
+ value.body instanceof ReadableStream
241
+ );
242
+ }
243
+
244
+ function instrumentHttpStreamConsumption(
245
+ value: HttpStreamResponse,
246
+ recorder: NonNullable<ReturnType<typeof getTraceRecorder>>,
247
+ args: unknown[],
248
+ diagnostics: RequestDiagnostics,
249
+ ): HttpStreamResponse {
250
+ const source = value.body;
251
+ let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
252
+ const body = new ReadableStream<Uint8Array>(
253
+ {
254
+ async pull(controller) {
255
+ try {
256
+ reader ??= source.getReader();
257
+ const chunk = await reader.read();
258
+ if (chunk.done) {
259
+ controller.close();
260
+ return;
261
+ }
262
+ controller.enqueue(chunk.value);
263
+ } catch (error) {
264
+ const sanitizedError = sanitizeRequestError(error, diagnostics);
265
+ try {
266
+ await recorder.runSpan(
267
+ "http.stream.consume",
268
+ () => {
269
+ throw sanitizedError;
270
+ },
271
+ {
272
+ onError: (spanError) =>
273
+ buildSpanAttributes("http", "stream", args, undefined, spanError, diagnostics),
274
+ },
275
+ );
276
+ } catch (recordedError) {
277
+ controller.error(recordedError);
278
+ }
279
+ }
280
+ },
281
+ async cancel(reason) {
282
+ try {
283
+ await (reader ? reader.cancel(reason) : source.cancel(reason));
284
+ } catch (error) {
285
+ throw sanitizeRequestError(error, diagnostics);
286
+ }
287
+ },
288
+ },
289
+ { highWaterMark: 0 },
290
+ );
291
+
292
+ const instrumented = {
293
+ ...value,
294
+ body,
295
+ bytes: () => readableBytes(body),
296
+ textChunks: () => readableTextChunks(body),
297
+ lines: () => readableLines(body),
298
+ } satisfies HttpStreamResponse;
299
+ try {
300
+ Object.assign(value, instrumented);
301
+ return value;
302
+ } catch {
303
+ return instrumented;
304
+ }
305
+ }
306
+
307
+ function isAsyncIterable<T = unknown>(value: unknown): value is AsyncIterable<T> {
308
+ return (
309
+ typeof value === "object" &&
310
+ value !== null &&
311
+ Symbol.asyncIterator in value &&
312
+ typeof value[Symbol.asyncIterator] === "function"
313
+ );
314
+ }
315
+
316
+ function instrumentHttpSseConsumption(
317
+ value: AsyncIterable<SseMessage>,
318
+ recorder: NonNullable<ReturnType<typeof getTraceRecorder>>,
319
+ args: unknown[],
320
+ diagnostics: RequestDiagnostics,
321
+ ): AsyncIterable<SseMessage> {
322
+ const source = value;
323
+ return {
324
+ async *[Symbol.asyncIterator]() {
325
+ try {
326
+ for await (const event of source) yield event;
327
+ } catch (error) {
328
+ const sanitizedError = sanitizeRequestError(error, diagnostics);
329
+ return await recorder.runSpan(
330
+ "http.sse.consume",
331
+ () => {
332
+ throw sanitizedError;
333
+ },
334
+ {
335
+ onError: (spanError) =>
336
+ buildSpanAttributes("http", "sse", args, undefined, spanError, diagnostics),
337
+ },
338
+ );
339
+ }
340
+ },
341
+ };
342
+ }
343
+
87
344
  function getMethod(
88
345
  namespace: InstrumentedNamespace,
89
346
  methodName: string,
90
347
  args: unknown[],
91
348
  ): string | undefined {
92
349
  if (namespace === "http") {
350
+ // Preserve the original instrumentation contract: generic entry points are
351
+ // reported as REQUEST/STREAM/SSE, independent of transport options.
93
352
  return methodName.toUpperCase();
94
353
  }
95
354
 
@@ -111,9 +370,19 @@ function buildSpanAttributes(
111
370
  args: unknown[],
112
371
  result?: unknown,
113
372
  error?: unknown,
373
+ diagnostics: RequestDiagnostics = { sensitiveParamNames: [], sensitiveValues: [] },
114
374
  ): Record<string, string | number | boolean> {
115
375
  const attributes: Record<string, string | number | boolean> = {};
116
- const url = getUrl(namespace, args, result);
376
+ const rawUrl = getUrl(namespace, args, result);
377
+ const structuralUrl = diagnostics.traceUrl ?? rawUrl;
378
+ const url = structuralUrl
379
+ ? redactSensitiveText(
380
+ structuralUrl,
381
+ diagnostics.sensitiveValues,
382
+ diagnostics.serializedUrl?.requestUrl,
383
+ diagnostics.serializedUrl?.redactedUrl,
384
+ )
385
+ : undefined;
117
386
  const method = getMethod(namespace, methodName, args);
118
387
  const status = error ? getErrorStatus(error) : getResponseStatus(namespace, result);
119
388
  const duration = error ? undefined : getResponseDuration(result);
@@ -121,6 +390,8 @@ function buildSpanAttributes(
121
390
  if (url) {
122
391
  attributes.url = url;
123
392
  }
393
+ if (diagnostics.requestId) attributes.request_id = diagnostics.requestId;
394
+ if (diagnostics.diagnosticUrlDegraded) attributes.redaction_degraded = true;
124
395
 
125
396
  if (method) {
126
397
  attributes.method = method;
@@ -145,6 +416,64 @@ function buildSpanAttributes(
145
416
  return attributes;
146
417
  }
147
418
 
419
+ function isStealthRedirectRunResult(value: unknown): value is StealthRedirectRunResult {
420
+ return (
421
+ typeof value === "object" &&
422
+ value !== null &&
423
+ "reason" in value &&
424
+ typeof value.reason === "string" &&
425
+ "hops" in value &&
426
+ Array.isArray(value.hops) &&
427
+ "final" in value &&
428
+ typeof value.final === "object" &&
429
+ value.final !== null
430
+ );
431
+ }
432
+
433
+ function buildStealthRedirectAttributes(
434
+ args: unknown[],
435
+ result: unknown,
436
+ error: unknown,
437
+ diagnostics: RequestDiagnostics,
438
+ ): Record<string, string | number | boolean> {
439
+ const attributes = buildSpanAttributes("stealth", "fetch", args, undefined, error, diagnostics);
440
+ if (!isStealthRedirectRunResult(result)) return attributes;
441
+
442
+ attributes.redirect_reason = result.reason;
443
+ attributes.redirect_hop_count = result.hops.length;
444
+ attributes.status = result.final.status;
445
+ if (result.hops.length > 0) {
446
+ const sensitiveValues = new Set(diagnostics.sensitiveValues);
447
+ const path = result.hops
448
+ .map((hop) => {
449
+ const hopUrl = hop.nextUrl ?? hop.url;
450
+ const responseSensitiveParamNames = [...queryParamNames(hopUrl)].filter(isSensitiveKey);
451
+ const structural = redactUrlQueryParams(hopUrl, [
452
+ ...new Set([...diagnostics.sensitiveParamNames, ...responseSensitiveParamNames]),
453
+ ]);
454
+ for (const value of structural.sensitiveValues) sensitiveValues.add(value);
455
+ const safeUrl = redactSensitiveText(structural.redactedUrl, [...sensitiveValues]);
456
+ return `${hop.method} ${hop.status} ${safeUrl}`;
457
+ })
458
+ .join(" -> ");
459
+ attributes.redirect_path = redactSensitiveText(
460
+ path,
461
+ [...sensitiveValues],
462
+ diagnostics.serializedUrl?.requestUrl,
463
+ diagnostics.serializedUrl?.redactedUrl,
464
+ );
465
+ }
466
+ return attributes;
467
+ }
468
+
469
+ function queryParamNames(url: string): Set<string> {
470
+ const queryStart = url.indexOf("?");
471
+ if (queryStart === -1) return new Set();
472
+ const fragmentStart = url.indexOf("#", queryStart);
473
+ const query = url.slice(queryStart + 1, fragmentStart === -1 ? undefined : fragmentStart);
474
+ return new Set(new URLSearchParams(query).keys());
475
+ }
476
+
148
477
  function getBrowserPageAttributes(
149
478
  methodName: string,
150
479
  args: unknown[],
@@ -230,10 +559,65 @@ function wrapPage<T extends object>(page: T, trace: TraceContext): T {
230
559
  });
231
560
  }
232
561
 
562
+ function wrapStealthRedirects(
563
+ redirects: StealthSession["redirects"],
564
+ trace: TraceContext,
565
+ ): StealthSession["redirects"] {
566
+ const recorder = getTraceRecorder(trace);
567
+ if (!recorder) return redirects;
568
+
569
+ return {
570
+ run(...args: Parameters<StealthSession["redirects"]["run"]>) {
571
+ const diagnosticArgs = [args[0].url, args[0]];
572
+ const diagnostics = snapshotRequestDiagnostics("stealth", "fetch", diagnosticArgs);
573
+ let result: ReturnType<StealthSession["redirects"]["run"]>;
574
+ try {
575
+ result = redirects.run(...args);
576
+ } catch (error) {
577
+ const sanitizedError = sanitizeRequestError(error, diagnostics);
578
+ recorder
579
+ .runSpan(
580
+ "stealth.redirects.run",
581
+ () => {
582
+ throw sanitizedError;
583
+ },
584
+ {
585
+ onError: (spanError) =>
586
+ buildStealthRedirectAttributes(diagnosticArgs, undefined, spanError, diagnostics),
587
+ },
588
+ )
589
+ .catch(() => undefined);
590
+ throw sanitizedError;
591
+ }
592
+
593
+ const sanitizedResult = Promise.resolve(result).catch((error: unknown) => {
594
+ throw sanitizeRequestError(error, diagnostics);
595
+ });
596
+ return recorder.runSpan("stealth.redirects.run", () => sanitizedResult, {
597
+ onSuccess: (spanResult) =>
598
+ buildStealthRedirectAttributes(diagnosticArgs, spanResult, undefined, diagnostics),
599
+ onError: (error) =>
600
+ buildStealthRedirectAttributes(diagnosticArgs, undefined, error, diagnostics),
601
+ });
602
+ },
603
+ };
604
+ }
605
+
606
+ function wrapStealthSession(session: StealthSession, trace: TraceContext): StealthSession {
607
+ const wrappedSession = wrapNamespace("stealth", session, trace);
608
+ const redirects = wrapStealthRedirects(session.redirects, trace);
609
+ return new Proxy(wrappedSession, {
610
+ get(target, property, receiver) {
611
+ return property === "redirects" ? redirects : Reflect.get(target, property, receiver);
612
+ },
613
+ });
614
+ }
615
+
233
616
  function wrapNamespace<T extends object>(
234
617
  namespace: InstrumentedNamespace,
235
618
  target: T,
236
619
  trace: TraceContext,
620
+ shouldInstrument?: (methodName: string, args: unknown[]) => boolean,
237
621
  ): T {
238
622
  const recorder = getTraceRecorder(trace);
239
623
  if (!recorder) {
@@ -241,15 +625,47 @@ function wrapNamespace<T extends object>(
241
625
  }
242
626
 
243
627
  const wrappedMethods = new Map<PropertyKey, unknown>();
628
+ const resolverMetadata =
629
+ namespace === "resolver" ? { target, traceRecorder: recorder } : undefined;
244
630
 
245
631
  return new Proxy(target, {
246
632
  get(namespaceTarget, property, receiver) {
633
+ if (property === RESOLVER_INSTRUMENTATION_METADATA && resolverMetadata) {
634
+ return resolverMetadata;
635
+ }
247
636
  const value = Reflect.get(namespaceTarget, property, receiver);
248
637
 
249
638
  if (typeof value !== "function" || property === "constructor") {
250
639
  return value;
251
640
  }
252
641
 
642
+ if (namespace === "resolver" && property === "solve") {
643
+ if (wrappedMethods.has(property)) {
644
+ return wrappedMethods.get(property);
645
+ }
646
+
647
+ const wrapped = (...args: unknown[]) => {
648
+ const challenge = args[0];
649
+ const challengeKind =
650
+ typeof challenge === "object" &&
651
+ challenge !== null &&
652
+ "kind" in challenge &&
653
+ typeof challenge.kind === "string"
654
+ ? challenge.kind
655
+ : undefined;
656
+ return recorder.runSpan(
657
+ "resolver.solve",
658
+ () => Reflect.apply(value, namespaceTarget, [args[0], args[1], recorder]),
659
+ {
660
+ attributes: challengeKind ? { challenge_kind: challengeKind } : undefined,
661
+ },
662
+ );
663
+ };
664
+
665
+ wrappedMethods.set(property, wrapped);
666
+ return wrapped;
667
+ }
668
+
253
669
  if (namespace === "browser" && property === "newPage") {
254
670
  if (wrappedMethods.has(property)) {
255
671
  return wrappedMethods.get(property);
@@ -329,15 +745,103 @@ function wrapNamespace<T extends object>(
329
745
  return wrapped;
330
746
  }
331
747
 
332
- const wrapped = (...args: unknown[]) =>
333
- recorder.runSpan(
334
- `${namespace}.${methodName}`,
335
- () => Reflect.apply(value, namespaceTarget, args),
336
- {
337
- onSuccess: (result) => buildSpanAttributes(namespace, methodName, args, result),
338
- onError: (error) => buildSpanAttributes(namespace, methodName, args, undefined, error),
339
- },
340
- );
748
+ const wrapped = (...args: unknown[]) => {
749
+ if (shouldInstrument && !shouldInstrument(methodName, args)) {
750
+ return Reflect.apply(value, namespaceTarget, args);
751
+ }
752
+ const requestDiagnostics = snapshotRequestDiagnostics(namespace, methodName, args);
753
+ // Invoke first and decide by the RETURN VALUE. `runSpan` always
754
+ // returns a Promise, so unconditionally span-wrapping every member
755
+ // silently rewrote synchronous contracts: `ctx.state.namespace()`
756
+ // (a sync factory) came back as a Promise, and every method call on
757
+ // it threw a raw TypeError — surfaced in production as catchtable's
758
+ // deterministic CONFIRM_STATE_UNAVAILABLE on 2026-07-27 (and the
759
+ // 2026-07-22 reserve internal_error loop before it). Sync members
760
+ // keep their sync contract; only genuinely async operations are
761
+ // recorded as spans.
762
+ let result: unknown;
763
+ try {
764
+ result = Reflect.apply(value, namespaceTarget, args);
765
+ } catch (error) {
766
+ const sanitizedError = sanitizeRequestError(error, requestDiagnostics);
767
+ // A promise-returning implementation may still throw
768
+ // SYNCHRONOUSLY during pre-flight validation. Preserve the
769
+ // synchronous throw contract, but keep recording the failure
770
+ // span (the pre-fidelity wrapper captured these).
771
+ recorder
772
+ .runSpan(
773
+ `${namespace}.${methodName}`,
774
+ () => {
775
+ throw sanitizedError;
776
+ },
777
+ {
778
+ onError: (spanError) =>
779
+ buildSpanAttributes(
780
+ namespace,
781
+ methodName,
782
+ args,
783
+ undefined,
784
+ spanError,
785
+ requestDiagnostics,
786
+ ),
787
+ },
788
+ )
789
+ .catch(() => undefined);
790
+ throw sanitizedError;
791
+ }
792
+ if (!isThenable(result)) {
793
+ // The state namespace factory returns the object whose METHODS
794
+ // are the operations worth tracing — instrument that object so
795
+ // `state.get`/`state.compareAndSet`/… spans exist (they never
796
+ // could before: the factory's return value was destroyed).
797
+ if (
798
+ namespace === "state" &&
799
+ methodName === "namespace" &&
800
+ typeof result === "object" &&
801
+ result !== null
802
+ ) {
803
+ return wrapNamespace(namespace, result, trace);
804
+ }
805
+ if (
806
+ namespace === "stealth" &&
807
+ methodName === "createSession" &&
808
+ typeof result === "object" &&
809
+ result !== null
810
+ ) {
811
+ return wrapStealthSession(result as StealthSession, trace);
812
+ }
813
+ return result;
814
+ }
815
+ const sanitizedResult = Promise.resolve(result).catch((error: unknown) => {
816
+ throw sanitizeRequestError(error, requestDiagnostics);
817
+ });
818
+ const tracedResult = recorder.runSpan(`${namespace}.${methodName}`, () => sanitizedResult, {
819
+ onSuccess: (spanResult) =>
820
+ buildSpanAttributes(
821
+ namespace,
822
+ methodName,
823
+ args,
824
+ spanResult,
825
+ undefined,
826
+ requestDiagnostics,
827
+ ),
828
+ onError: (error) =>
829
+ buildSpanAttributes(namespace, methodName, args, undefined, error, requestDiagnostics),
830
+ });
831
+ return namespace === "http" && methodName === "stream"
832
+ ? tracedResult.then((spanResult) =>
833
+ isHttpStreamResponse(spanResult)
834
+ ? instrumentHttpStreamConsumption(spanResult, recorder, args, requestDiagnostics)
835
+ : spanResult,
836
+ )
837
+ : namespace === "http" && methodName === "sse"
838
+ ? tracedResult.then((spanResult) =>
839
+ isAsyncIterable<SseMessage>(spanResult)
840
+ ? instrumentHttpSseConsumption(spanResult, recorder, args, requestDiagnostics)
841
+ : spanResult,
842
+ )
843
+ : tracedResult;
844
+ };
341
845
 
342
846
  wrappedMethods.set(property, wrapped);
343
847
  return wrapped;
@@ -349,7 +853,7 @@ function hasTraceOverrides(options: InstrumentationOptions): boolean {
349
853
  return options.maxSpans !== undefined || options.onSpan !== undefined;
350
854
  }
351
855
 
352
- export function wrapWithInstrumentation<T extends ProviderContext>(
856
+ export function wrapWithInstrumentation<T extends Pick<ProviderContext, "trace">>(
353
857
  ctx: T,
354
858
  options: InstrumentationOptions = {},
355
859
  ): InstrumentedProviderContext<T> {
@@ -370,7 +874,8 @@ export function wrapWithInstrumentation<T extends ProviderContext>(
370
874
  property === "stealth" ||
371
875
  property === "browser" ||
372
876
  property === "session" ||
373
- property === "state"
877
+ property === "state" ||
878
+ property === "resolver"
374
879
  ) {
375
880
  const namespace = property;
376
881
  if (wrappedTargets.has(namespace)) {