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