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

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 (365) hide show
  1. package/AUTHORING.md +537 -33
  2. package/CHANGELOG.md +201 -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 +1178 -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-map.ts.txt +5 -0
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
  246. package/src/cli/commands.ts +33 -0
  247. package/src/cli/create.ts +50 -37
  248. package/src/cli/migrate-operation-declaration.ts +1654 -0
  249. package/src/cli/migrate-operation-shape.ts +184 -0
  250. package/src/cli/migrate-provider-shape.ts +772 -0
  251. package/src/cli/prompt-assets.ts +865 -0
  252. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  253. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  254. package/src/cli/templates/provider/README.md.tpl +5 -5
  255. package/src/cli/templates/provider/index.ts.tpl +6 -3
  256. package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
  257. package/src/cli/templates/provider/provider.json.tpl +6 -0
  258. package/src/config/loader.ts +690 -163
  259. package/src/contract-serialization.ts +5 -7
  260. package/src/contract-types.ts +12 -5
  261. package/src/contract.ts +24 -10
  262. package/src/declaration-validation.ts +330 -0
  263. package/src/define.ts +1048 -131
  264. package/src/dev.ts +4 -1
  265. package/src/engine.ts +279 -0
  266. package/src/error-observability.ts +64 -0
  267. package/src/error-resolution.ts +127 -0
  268. package/src/errors.ts +68 -0
  269. package/src/fixture-sanitization.ts +264 -0
  270. package/src/health-scenario.ts +875 -0
  271. package/src/index.ts +220 -13
  272. package/src/lint.ts +698 -90
  273. package/src/native-address.ts +340 -0
  274. package/src/native-egress-policy.ts +358 -0
  275. package/src/observability.ts +51 -1
  276. package/src/provider.ts +161 -3
  277. package/src/runtime/auth-flow.ts +12 -0
  278. package/src/runtime/browser.ts +661 -63
  279. package/src/runtime/cache.ts +189 -14
  280. package/src/runtime/choice-wordlist.ts +145 -0
  281. package/src/runtime/choice.ts +631 -120
  282. package/src/runtime/chrome149-header-order.ts +330 -0
  283. package/src/runtime/env.ts +13 -0
  284. package/src/runtime/executor.ts +43 -31
  285. package/src/runtime/http.ts +641 -61
  286. package/src/runtime/insights.ts +2 -2
  287. package/src/runtime/instrumentation.ts +520 -15
  288. package/src/runtime/native-network-errors.ts +99 -0
  289. package/src/runtime/native-network.ts +1605 -0
  290. package/src/runtime/ocr.ts +523 -0
  291. package/src/runtime/otlp.ts +467 -21
  292. package/src/runtime/proxy-errors.ts +12 -4
  293. package/src/runtime/proxy-nodemaven.ts +221 -0
  294. package/src/runtime/proxy-telemetry.ts +244 -75
  295. package/src/runtime/redirects.ts +66 -0
  296. package/src/runtime/redis.ts +7 -2
  297. package/src/runtime/request-options.ts +680 -1
  298. package/src/runtime/resolver-config.ts +6 -0
  299. package/src/runtime/resolver-public.ts +23 -0
  300. package/src/runtime/resolver-shared.ts +33 -0
  301. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  302. package/src/runtime/resolver-vendors/browser.ts +533 -0
  303. package/src/runtime/resolver-vendors/capsolver.ts +707 -0
  304. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  305. package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
  306. package/src/runtime/resolver-vendors/types.ts +212 -0
  307. package/src/runtime/resolver.ts +1157 -0
  308. package/src/runtime/secrets.ts +64 -0
  309. package/src/runtime/state.ts +394 -77
  310. package/src/runtime/stealth-cookies.ts +132 -0
  311. package/src/runtime/stealth.ts +1280 -336
  312. package/src/runtime/stt.ts +1 -19
  313. package/src/runtime/timeout.ts +18 -0
  314. package/src/runtime/trace-config.ts +78 -0
  315. package/src/runtime/trace.ts +57 -17
  316. package/src/serve.ts +6 -1
  317. package/src/server/error-observability.ts +1 -0
  318. package/src/server/index.ts +34 -2
  319. package/src/server/self-test-input-tokens.ts +29 -14
  320. package/src/server/self-test.ts +191 -68
  321. package/src/server/serve-implementation.ts +3378 -0
  322. package/src/server/serve.ts +1 -1632
  323. package/src/server/trace-output.ts +129 -0
  324. package/src/server/types.ts +13 -1
  325. package/src/stateful/README.md +146 -0
  326. package/src/stateful/errors.ts +35 -0
  327. package/src/stateful/http-provider-event-emitter.ts +314 -0
  328. package/src/stateful/http-session-owner-registry.ts +306 -0
  329. package/src/stateful/index.ts +18 -0
  330. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  331. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  332. package/src/stateful/provider-event-pipeline.ts +61 -0
  333. package/src/stateful/provider-events.ts +462 -0
  334. package/src/stateful/session-key.ts +111 -0
  335. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  336. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  337. package/src/stateful/stateful-provider-adapter.ts +562 -0
  338. package/src/stateful/stateful-provider-observability.ts +261 -0
  339. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  340. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  341. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  342. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  343. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  344. package/src/stateful-signing.ts +46 -0
  345. package/src/stealth/profiles.ts +202 -231
  346. package/src/stream-evidence.ts +988 -0
  347. package/src/stream.ts +8 -1
  348. package/src/testing/index.ts +10 -1
  349. package/src/testing/run.ts +658 -15
  350. package/src/trace-sanitization.ts +63 -0
  351. package/src/types.ts +788 -174
  352. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  353. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  354. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  355. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  356. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  357. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  358. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  359. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  360. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  361. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  362. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  363. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  364. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  365. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
@@ -0,0 +1,58 @@
1
+ /** @internal Chromium 149 DeprecatedCaseFoldingHash for an LChar string. */
2
+ export declare function chrome149CaseFoldingHash(name: string): number;
3
+ /** @internal Numeric rapidhash fixture from Chromium's string_hasher_test.cc. */
4
+ export declare function chrome149RapidhashFixture(): {
5
+ full: bigint;
6
+ masked: number;
7
+ };
8
+ /**
9
+ * HTTPHeaderMap insertion sequence of the fixed headers in a real Chrome
10
+ * 149.0.7827.155 page fetch/XHR (insertion order, not bucket order). Caller
11
+ * headers precede all of these (core/fetch/fetch_manager.cc:1128-1130).
12
+ *
13
+ * platform/loader/fetch/resource_request_utils.cc:146 UpgradeResourceRequestForLoader
14
+ * :166 context.UpgradeResourceRequestForLoader
15
+ * -> core/loader/frame_fetch_context.cc:1000 AddClientHintsIfNecessary
16
+ * Set sec-ch-ua @737, sec-ch-ua-mobile @748, sec-ch-ua-platform @761
17
+ * -> :1001 AddReducedAcceptLanguageIfNecessary is a no-op
18
+ * (kReduceAcceptLanguage[HTTP] are FEATURE_DISABLED_BY_DEFAULT,
19
+ * services/network/public/cpp/features.cc:204,214)
20
+ * :214 context.PrepareRequest
21
+ * -> core/loader/frame_fetch_context.cc:419 SetHTTPUserAgent
22
+ * -> :455 probe::PrepareRequest, which only touches the map when a
23
+ * DevTools session has set an Accept-Language override:
24
+ * InspectorEmulationAgent::PrepareRequest (inspector_emulation_agent.cc
25
+ * :626-636, Emulation.setUserAgentOverride acceptLanguage; skips a key
26
+ * the page already set) or InspectorNetworkAgent::PrepareRequest
27
+ * (inspector_network_agent.cc:1524-1547, Network.setExtraHTTPHeaders;
28
+ * overwrites)
29
+ *
30
+ * Accept-Language is therefore NOT a map key in real Chrome. //net appends it
31
+ * in URLRequestHttpJob::AddExtraHeaders (net/url_request/url_request_http_job.cc
32
+ * :784-797) after Accept-Encoding, and only when the request does not already
33
+ * carry one (SetHeaderIfMissing), which is why a caller-supplied Accept-Language
34
+ * stays at its map bucket and is never emitted twice. al-placement-capture.json
35
+ * (B: no locale, C: --accept-lang=ja) confirms both the four-key map and the
36
+ * downstream slot.
37
+ *
38
+ * Every earlier corpus (placement-rule-sweep, expansion-sweep, holdout-capture,
39
+ * m1-capture) was captured through Playwright `newContext({ locale })`, which
40
+ * sets that override (Emulation.setUserAgentOverride acceptLanguage) and so
41
+ * inserts Accept-Language into the map as a fifth fixed key. Those fixtures still
42
+ * validate the hash and table mechanics;
43
+ * the tests interpret them through that harness insertion list. No production
44
+ * path uses it.
45
+ */
46
+ export declare const CHROME149_FIXED_MAP_INSERTION: readonly ["sec-ch-ua", "sec-ch-ua-mobile", "sec-ch-ua-platform", "User-Agent"];
47
+ /**
48
+ * @internal Header-name order model parameterised by the fixed map insertion
49
+ * sequence. Production always passes {@link CHROME149_FIXED_MAP_INSERTION};
50
+ * tests pass the DevTools-harness sequence to validate corpora captured through
51
+ * Playwright's `locale` option.
52
+ */
53
+ export declare function chrome149HeaderOrderForMapInsertion(callerNames: Iterable<string>, fixedMapInsertion: readonly string[]): string[];
54
+ /**
55
+ * @internal Predict real Chrome 149's non-pseudo HTTP/2 fetch/XHR header-name
56
+ * order for the given caller header names (no DevTools session attached).
57
+ */
58
+ export declare function chrome149HeaderOrder(callerNames: Iterable<string>): string[];
@@ -0,0 +1,289 @@
1
+ const U64_MASK = (1n << 64n) - 1n;
2
+ const RAPID_SEED = 0xbdd89aa982704029n;
3
+ const RAPID_SECRET = [0x2d358dccaa6c78a5n, 0x8bb84b93962eacc9n, 0x4b33a62ed433d4a3n];
4
+ function latin1CaseFold(character) {
5
+ if (character >= 0x41 && character <= 0x5a)
6
+ return character + 0x20;
7
+ if (character === 0xb5)
8
+ return 0x03bc;
9
+ if ((character >= 0xc0 && character <= 0xd6) || (character >= 0xd8 && character <= 0xde))
10
+ return character + 0x20;
11
+ return character;
12
+ }
13
+ function multiply128(a, b) {
14
+ const product = (a & U64_MASK) * (b & U64_MASK);
15
+ return [product & U64_MASK, (product >> 64n) & U64_MASK];
16
+ }
17
+ function rapidMix(a, b) {
18
+ const [low, high] = multiply128(a, b);
19
+ return low ^ high;
20
+ }
21
+ class PlainByteHashReader {
22
+ bytes;
23
+ compressionFactor = 1;
24
+ expansionFactor = 1;
25
+ constructor(bytes) {
26
+ this.bytes = bytes;
27
+ }
28
+ read64(offset) {
29
+ let result = 0n;
30
+ for (let index = 0; index < 8; index += 1) {
31
+ result |= BigInt(this.bytes[offset + index] ?? 0) << BigInt(index * 8);
32
+ }
33
+ return result;
34
+ }
35
+ read32(offset) {
36
+ let result = 0n;
37
+ for (let index = 0; index < 4; index += 1) {
38
+ result |= BigInt(this.bytes[offset + index] ?? 0) << BigInt(index * 8);
39
+ }
40
+ return result;
41
+ }
42
+ readSmall(offset, length) {
43
+ return ((BigInt(this.bytes[offset] ?? 0) << 56n) |
44
+ (BigInt(this.bytes[offset + (length >> 1)] ?? 0) << 32n) |
45
+ BigInt(this.bytes[offset + length - 1] ?? 0));
46
+ }
47
+ }
48
+ class CaseFoldingLatin1HashReader {
49
+ input;
50
+ compressionFactor = 1;
51
+ expansionFactor = 2;
52
+ constructor(input) {
53
+ this.input = input;
54
+ }
55
+ fold(offset) {
56
+ return BigInt(latin1CaseFold(this.input.charCodeAt(offset)));
57
+ }
58
+ read64(offset) {
59
+ return (this.fold(offset) |
60
+ (this.fold(offset + 1) << 16n) |
61
+ (this.fold(offset + 2) << 32n) |
62
+ (this.fold(offset + 3) << 48n));
63
+ }
64
+ read32(offset) {
65
+ return this.fold(offset) | (this.fold(offset + 1) << 16n);
66
+ }
67
+ readSmall(offset, length) {
68
+ if (length !== 2) {
69
+ throw new Error(`CaseFoldingHashReader<LChar> received length ${length}; expected 2.`);
70
+ }
71
+ return this.fold(offset);
72
+ }
73
+ }
74
+ function rapidHash(reader, producedLength) {
75
+ const x = reader.compressionFactor;
76
+ const y = reader.expansionFactor;
77
+ if (producedLength % y !== 0)
78
+ throw new Error("Invalid rapidhash reader length.");
79
+ let seed = RAPID_SEED;
80
+ seed ^= rapidMix(seed ^ RAPID_SECRET[0], RAPID_SECRET[1]) ^ BigInt(producedLength);
81
+ seed &= U64_MASK;
82
+ let offset = 0;
83
+ let a;
84
+ let b;
85
+ if (producedLength <= 16) {
86
+ if (producedLength >= 4) {
87
+ const last = offset + Math.trunc(((producedLength - 4) * x) / y);
88
+ a = (reader.read32(offset) << 32n) | reader.read32(last);
89
+ const delta = Math.trunc((((producedLength & 24) >> (producedLength >> 3)) * x) / y);
90
+ b = (reader.read32(offset + delta) << 32n) | reader.read32(last - delta);
91
+ }
92
+ else if (producedLength > 0) {
93
+ a = reader.readSmall(offset, producedLength);
94
+ b = 0n;
95
+ }
96
+ else {
97
+ a = 0n;
98
+ b = 0n;
99
+ }
100
+ }
101
+ else {
102
+ let remaining = producedLength;
103
+ if (remaining > 48) {
104
+ let see1 = seed;
105
+ let see2 = seed;
106
+ do {
107
+ seed = rapidMix(reader.read64(offset) ^ RAPID_SECRET[0], reader.read64(offset + Math.trunc((8 * x) / y)) ^ seed);
108
+ see1 = rapidMix(reader.read64(offset + Math.trunc((16 * x) / y)) ^ RAPID_SECRET[1], reader.read64(offset + Math.trunc((24 * x) / y)) ^ see1);
109
+ see2 = rapidMix(reader.read64(offset + Math.trunc((32 * x) / y)) ^ RAPID_SECRET[2], reader.read64(offset + Math.trunc((40 * x) / y)) ^ see2);
110
+ offset += Math.trunc((48 * x) / y);
111
+ remaining -= 48;
112
+ } while (remaining >= 48);
113
+ seed ^= see1 ^ see2;
114
+ }
115
+ if (remaining > 16) {
116
+ seed = rapidMix(reader.read64(offset) ^ RAPID_SECRET[2], reader.read64(offset + Math.trunc((8 * x) / y)) ^ seed ^ RAPID_SECRET[1]);
117
+ if (remaining > 32) {
118
+ seed = rapidMix(reader.read64(offset + Math.trunc((16 * x) / y)) ^ RAPID_SECRET[2], reader.read64(offset + Math.trunc((24 * x) / y)) ^ seed);
119
+ }
120
+ }
121
+ a = reader.read64(offset + Math.trunc(((remaining - 16) * x) / y));
122
+ b = reader.read64(offset + Math.trunc(((remaining - 8) * x) / y));
123
+ }
124
+ a ^= RAPID_SECRET[1];
125
+ b ^= seed;
126
+ [a, b] = multiply128(a, b);
127
+ return rapidMix(a ^ RAPID_SECRET[0] ^ BigInt(producedLength), b ^ RAPID_SECRET[1]);
128
+ }
129
+ function maskTopEightBits(hash) {
130
+ const masked = Number(hash & 0xffffffn);
131
+ return masked === 0 ? 0x800000 : masked;
132
+ }
133
+ /** @internal Chromium 149 DeprecatedCaseFoldingHash for an LChar string. */
134
+ export function chrome149CaseFoldingHash(name) {
135
+ const reader = new CaseFoldingLatin1HashReader(name);
136
+ return maskTopEightBits(rapidHash(reader, name.length * reader.expansionFactor));
137
+ }
138
+ /** @internal Numeric rapidhash fixture from Chromium's string_hasher_test.cc. */
139
+ export function chrome149RapidhashFixture() {
140
+ const fixture = [0x41, 0x95, 0xff, 0x50, 0x01];
141
+ const full = rapidHash(new PlainByteHashReader(fixture), fixture.length);
142
+ return { full, masked: maskTopEightBits(full) };
143
+ }
144
+ function asciiCaseKey(name) {
145
+ let result = "";
146
+ for (let index = 0; index < name.length; index += 1) {
147
+ const character = name.charCodeAt(index);
148
+ result += String.fromCharCode(character >= 0x41 && character <= 0x5a ? character + 0x20 : character);
149
+ }
150
+ return result;
151
+ }
152
+ class WtfHeaderHashMap {
153
+ table = [];
154
+ keyCount = 0;
155
+ insertWithoutExpansion(key) {
156
+ const mask = this.table.length - 1;
157
+ let index = chrome149CaseFoldingHash(key) & mask;
158
+ let probeCount = 0;
159
+ const keyCaseFolded = asciiCaseKey(key);
160
+ for (;;) {
161
+ const stored = this.table[index];
162
+ if (stored === undefined) {
163
+ this.table[index] = key;
164
+ this.keyCount += 1;
165
+ return true;
166
+ }
167
+ if (asciiCaseKey(stored) === keyCaseFolded)
168
+ return false;
169
+ probeCount += 1;
170
+ index = (index + probeCount) & mask;
171
+ }
172
+ }
173
+ rehash(newSize) {
174
+ const oldTable = this.table;
175
+ this.table = Array(newSize);
176
+ this.keyCount = 0;
177
+ for (const key of oldTable) {
178
+ if (key !== undefined)
179
+ this.insertWithoutExpansion(key);
180
+ }
181
+ }
182
+ insert(key) {
183
+ if (this.table.length === 0)
184
+ this.table = Array(8);
185
+ if (!this.insertWithoutExpansion(key))
186
+ return;
187
+ if (this.keyCount * 2 >= this.table.length)
188
+ this.rehash(this.table.length * 2);
189
+ }
190
+ iterationOrder() {
191
+ return this.table.filter((key) => key !== undefined);
192
+ }
193
+ }
194
+ /**
195
+ * HTTPHeaderMap insertion sequence of the fixed headers in a real Chrome
196
+ * 149.0.7827.155 page fetch/XHR (insertion order, not bucket order). Caller
197
+ * headers precede all of these (core/fetch/fetch_manager.cc:1128-1130).
198
+ *
199
+ * platform/loader/fetch/resource_request_utils.cc:146 UpgradeResourceRequestForLoader
200
+ * :166 context.UpgradeResourceRequestForLoader
201
+ * -> core/loader/frame_fetch_context.cc:1000 AddClientHintsIfNecessary
202
+ * Set sec-ch-ua @737, sec-ch-ua-mobile @748, sec-ch-ua-platform @761
203
+ * -> :1001 AddReducedAcceptLanguageIfNecessary is a no-op
204
+ * (kReduceAcceptLanguage[HTTP] are FEATURE_DISABLED_BY_DEFAULT,
205
+ * services/network/public/cpp/features.cc:204,214)
206
+ * :214 context.PrepareRequest
207
+ * -> core/loader/frame_fetch_context.cc:419 SetHTTPUserAgent
208
+ * -> :455 probe::PrepareRequest, which only touches the map when a
209
+ * DevTools session has set an Accept-Language override:
210
+ * InspectorEmulationAgent::PrepareRequest (inspector_emulation_agent.cc
211
+ * :626-636, Emulation.setUserAgentOverride acceptLanguage; skips a key
212
+ * the page already set) or InspectorNetworkAgent::PrepareRequest
213
+ * (inspector_network_agent.cc:1524-1547, Network.setExtraHTTPHeaders;
214
+ * overwrites)
215
+ *
216
+ * Accept-Language is therefore NOT a map key in real Chrome. //net appends it
217
+ * in URLRequestHttpJob::AddExtraHeaders (net/url_request/url_request_http_job.cc
218
+ * :784-797) after Accept-Encoding, and only when the request does not already
219
+ * carry one (SetHeaderIfMissing), which is why a caller-supplied Accept-Language
220
+ * stays at its map bucket and is never emitted twice. al-placement-capture.json
221
+ * (B: no locale, C: --accept-lang=ja) confirms both the four-key map and the
222
+ * downstream slot.
223
+ *
224
+ * Every earlier corpus (placement-rule-sweep, expansion-sweep, holdout-capture,
225
+ * m1-capture) was captured through Playwright `newContext({ locale })`, which
226
+ * sets that override (Emulation.setUserAgentOverride acceptLanguage) and so
227
+ * inserts Accept-Language into the map as a fifth fixed key. Those fixtures still
228
+ * validate the hash and table mechanics;
229
+ * the tests interpret them through that harness insertion list. No production
230
+ * path uses it.
231
+ */
232
+ export const CHROME149_FIXED_MAP_INSERTION = [
233
+ "sec-ch-ua",
234
+ "sec-ch-ua-mobile",
235
+ "sec-ch-ua-platform",
236
+ "User-Agent",
237
+ ];
238
+ /**
239
+ * Appended after PopulateResourceRequest has iterated the map: Fetch Metadata
240
+ * and Referer by the network service, then //net's Accept-Encoding and
241
+ * Accept-Language, then the HTTP/2 Priority header (net/spdy/spdy_http_utils.cc).
242
+ */
243
+ const DOWNSTREAM_SUFFIX = [
244
+ "sec-fetch-site",
245
+ "sec-fetch-mode",
246
+ "sec-fetch-dest",
247
+ "referer",
248
+ ];
249
+ /**
250
+ * @internal Header-name order model parameterised by the fixed map insertion
251
+ * sequence. Production always passes {@link CHROME149_FIXED_MAP_INSERTION};
252
+ * tests pass the DevTools-harness sequence to validate corpora captured through
253
+ * Playwright's `locale` option.
254
+ */
255
+ export function chrome149HeaderOrderForMapInsertion(callerNames, fixedMapInsertion) {
256
+ const unique = new Map();
257
+ for (const name of callerNames) {
258
+ const key = asciiCaseKey(name);
259
+ if (!unique.has(key))
260
+ unique.set(key, name);
261
+ }
262
+ const headerMap = new WtfHeaderHashMap();
263
+ for (const key of [...unique.keys()].sort())
264
+ headerMap.insert(unique.get(key));
265
+ for (const name of fixedMapInsertion)
266
+ headerMap.insert(name);
267
+ const order = headerMap.iterationOrder().map((name) => name.toLowerCase());
268
+ // SetAcceptHeader adds */* only when the caller Accept was absent.
269
+ if (!order.includes("accept"))
270
+ order.push("accept");
271
+ order.push(...DOWNSTREAM_SUFFIX);
272
+ // URLRequestHttpJob::AddExtraHeaders: Accept-Encoding, then Accept-Language,
273
+ // each only if the request does not already carry it.
274
+ if (!order.includes("accept-encoding"))
275
+ order.push("accept-encoding");
276
+ if (!order.includes("accept-language"))
277
+ order.push("accept-language");
278
+ // CreateSpdyHeadersFromHttpRequest appends the default Priority only if absent.
279
+ if (!order.includes("priority"))
280
+ order.push("priority");
281
+ return order;
282
+ }
283
+ /**
284
+ * @internal Predict real Chrome 149's non-pseudo HTTP/2 fetch/XHR header-name
285
+ * order for the given caller header names (no DevTools session attached).
286
+ */
287
+ export function chrome149HeaderOrder(callerNames) {
288
+ return chrome149HeaderOrderForMapInsertion(callerNames, CHROME149_FIXED_MAP_INSERTION);
289
+ }
@@ -1,9 +1,21 @@
1
+ import { isEngineOwnedEnvName } from "../engine.js";
2
+ /**
3
+ * A mixed-case spelling of an engine-owned name is an alias: on Windows it resolves to the
4
+ * engine's variable while evading an exact-name allowlist. Only the exact (upper-case) name,
5
+ * which engine-internal contexts allowlist explicitly, may read those values.
6
+ */
7
+ function isEngineOwnedEnvAlias(key) {
8
+ return isEngineOwnedEnvName(key) && key !== key.toUpperCase();
9
+ }
1
10
  export function createEnvContext(allowedKeys) {
2
11
  return {
3
12
  get(key) {
4
13
  if (allowedKeys && !allowedKeys.includes(key)) {
5
14
  return undefined;
6
15
  }
16
+ if (isEngineOwnedEnvAlias(key)) {
17
+ return undefined;
18
+ }
7
19
  return process.env[key];
8
20
  },
9
21
  };
@@ -1,4 +1,4 @@
1
- import type { ProviderContext, ProviderDefinition } from "../types.js";
1
+ import type { EnvContext, ProviderDefinition } from "../types.js";
2
2
  export declare function isStreamingOperation(provider: ProviderDefinition, operationId: string): boolean;
3
3
  /**
4
4
  * Execute a provider operation by calling its handler.
@@ -11,6 +11,7 @@ export declare function isStreamingOperation(provider: ProviderDefinition, opera
11
11
  *
12
12
  * @see openspec/provider-sdk/03-sdk-core.md §3.6
13
13
  */
14
- export declare function executeOperation(provider: ProviderDefinition, operationId: string, ctx: ProviderContext, input: unknown, _options?: {
14
+ export declare function executeOperation<const TProvider extends ProviderDefinition, const TOperationId extends keyof TProvider["operations"] & string>(provider: TProvider, operationId: TOperationId, ctx: NoInfer<Parameters<TProvider["operations"][TOperationId]["handler"]>[0]>, input: unknown, _options?: {
15
15
  skipAuth?: boolean;
16
+ env?: EnvContext;
16
17
  }): Promise<unknown>;
@@ -1,5 +1,7 @@
1
- import { isSessionExpiredError, ProviderError, SessionExpiredError } from "../errors.js";
1
+ import { isValidationError, ProviderError, ValidationError, } from "../errors.js";
2
+ import { z } from "zod";
2
3
  import { parseSchema } from "../schema.js";
4
+ import { assertRequiredSecretsPresent } from "./secrets.js";
3
5
  export function isStreamingOperation(provider, operationId) {
4
6
  const kind = provider.operations[operationId]?.transport?.kind ?? "json";
5
7
  return kind !== "json";
@@ -23,34 +25,33 @@ export async function executeOperation(provider, operationId, ctx, input, _optio
23
25
  fix: `Valid operations: ${Object.keys(provider.operations).join(", ")}`,
24
26
  });
25
27
  }
28
+ // SDK-owned secret presence gate (single source of truth): declared
29
+ // `required: true` secrets are validated here, before input parsing and the
30
+ // handler, so every invocation path (serve /v1, self-test probes, perf,
31
+ // record) fails with the same structured MISSING_SECRET error instead of a
32
+ // handler-specific crash. Providers must not re-check presence locally.
33
+ if (provider.secrets?.some((secret) => secret.required === true)) {
34
+ assertRequiredSecretsPresent(provider, _options?.env ?? ("env" in ctx ? ctx.env : { get: () => undefined }));
35
+ }
26
36
  const validatedInput = await parseSchema(operation.input, input, `operations.${operationId}.input`);
27
37
  const execute = () => ctx.trace.span(`handler:${operationId}`, () => Promise.resolve(operation.handler(ctx, validatedInput)));
28
- let result;
38
+ const result = await execute();
39
+ if (isStreamingOperation(provider, operationId)) {
40
+ return result;
41
+ }
29
42
  try {
30
- result = await execute();
43
+ return await parseSchema(operation.output, result, `operations.${operationId}.output`);
31
44
  }
32
- catch (error) {
33
- // Session expiry is renewed by Credential Service via the /auth/refresh
34
- // route, NOT in-process here: this executor cannot mutate ctx.credential,
35
- // so an in-process retry would just repeat the call with the same stale
36
- // credential (and risk repeating partial side-effects). Instead we surface
37
- // the expiry so Credential Service refreshes and re-drives the operation
38
- // with a fresh credential. `retryOnAuthRefresh` declares that this
39
- // operation is safe to re-drive after refresh, which we signal by marking
40
- // the surfaced error retryable; non-idempotent operations (the default)
41
- // stay non-retryable so they are not auto-re-driven. See design.md §4.3 D3.
42
- // Use the branded guard, not `instanceof`: a handler loaded through a
43
- // duplicate/published SDK module can throw a correctly branded
44
- // SessionExpiredError whose constructor identity differs from this
45
- // executor's, which `instanceof` would miss — dropping the retryable
46
- // upgrade and stranding an operation that opted into auth refresh.
47
- if (isSessionExpiredError(error) && operation.retryOnAuthRefresh) {
48
- throw new SessionExpiredError(error.message, { retryable: true });
45
+ catch (cause) {
46
+ if (!(cause instanceof z.ZodError) && !isValidationError(cause)) {
47
+ throw cause;
49
48
  }
50
- throw error;
51
- }
52
- if (isStreamingOperation(provider, operationId)) {
53
- return result;
49
+ throw new ValidationError(`Operation handler output failed schema validation.`, {
50
+ code: "OUTPUT_VALIDATION_FAILED",
51
+ category: "output_validation",
52
+ retryable: false,
53
+ zodError: isValidationError(cause) ? cause.zodError : cause,
54
+ ...(cause instanceof Error ? { cause } : {}),
55
+ });
54
56
  }
55
- return parseSchema(operation.output, result, `operations.${operationId}.output`);
56
57
  }
@@ -4,5 +4,6 @@ export type HttpClientOptions = ProxyResolutionOptions & {
4
4
  warn?: (message: string) => void;
5
5
  userAgent?: string;
6
6
  onRetrySummary?: (summary: HttpRetrySummary) => void;
7
+ signal?: AbortSignal;
7
8
  };
8
9
  export declare function createHttpClient(baseUrl?: string, clientOptions?: HttpClientOptions): HttpClient;