@apifuse/provider-sdk 2.2.0-beta.61 → 2.2.0-beta.63

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 (258) hide show
  1. package/AUTHORING.md +268 -9
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +1 -0
  4. package/bin/apifuse-check.ts +84 -2
  5. package/bin/apifuse-dev.ts +11 -31
  6. package/bin/apifuse-migrate-deployment.ts +200 -0
  7. package/bin/apifuse-pack-check.ts +11 -4
  8. package/bin/apifuse-pack-types.ts +191 -4
  9. package/bin/apifuse-record.ts +44 -32
  10. package/bin/apifuse-test.ts +3 -1
  11. package/dist/cli/commands.d.ts +1 -1
  12. package/dist/cli/commands.js +11 -0
  13. package/dist/cli/deployment-intent.d.ts +178 -0
  14. package/dist/cli/deployment-intent.js +277 -0
  15. package/dist/cli/migrate-deployment-intent.d.ts +132 -0
  16. package/dist/cli/migrate-deployment-intent.js +1552 -0
  17. package/dist/cli/migrate-provider-shape.d.ts +5 -1
  18. package/dist/cli/migrate-provider-shape.js +4 -2
  19. package/dist/cli/resolver-runtime.d.ts +21 -0
  20. package/dist/cli/resolver-runtime.js +31 -0
  21. package/dist/define.d.ts +3 -0
  22. package/dist/define.js +5 -0
  23. package/dist/dev.d.ts +3 -1
  24. package/dist/dev.js +6 -1
  25. package/dist/engine.d.ts +35 -1
  26. package/dist/engine.js +21 -2
  27. package/dist/error-resolution.d.ts +1 -0
  28. package/dist/error-resolution.js +54 -0
  29. package/dist/errors.d.ts +39 -1
  30. package/dist/errors.js +50 -0
  31. package/dist/handle-meta.d.ts +18 -2
  32. package/dist/handle-meta.js +30 -2
  33. package/dist/handle.d.ts +33 -12
  34. package/dist/handle.js +69 -24
  35. package/dist/i18n/error-messages.d.ts +86 -0
  36. package/dist/i18n/error-messages.js +192 -0
  37. package/dist/i18n/index.d.ts +1 -0
  38. package/dist/i18n/index.js +1 -0
  39. package/dist/i18n/keys.d.ts +12 -0
  40. package/dist/i18n/keys.js +76 -5
  41. package/dist/index.d.ts +10 -2
  42. package/dist/index.js +9 -1
  43. package/dist/lint.d.ts +10 -0
  44. package/dist/lint.js +440 -57
  45. package/dist/provider.d.ts +7 -5
  46. package/dist/provider.js +4 -2
  47. package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
  48. package/dist/runtime/browser-telemetry-binding.js +83 -0
  49. package/dist/runtime/browser-telemetry.d.ts +76 -0
  50. package/dist/runtime/browser-telemetry.js +165 -0
  51. package/dist/runtime/browser.d.ts +3 -0
  52. package/dist/runtime/browser.js +208 -47
  53. package/dist/runtime/cache-telemetry.d.ts +71 -0
  54. package/dist/runtime/cache-telemetry.js +177 -0
  55. package/dist/runtime/cache.js +67 -7
  56. package/dist/runtime/capability-response.d.ts +3 -0
  57. package/dist/runtime/capability-response.js +56 -0
  58. package/dist/runtime/capability-telemetry.d.ts +46 -0
  59. package/dist/runtime/capability-telemetry.js +68 -0
  60. package/dist/runtime/diagnostic-env.d.ts +3 -0
  61. package/dist/runtime/diagnostic-env.js +10 -1
  62. package/dist/runtime/engine-mode.d.ts +74 -0
  63. package/dist/runtime/engine-mode.js +152 -0
  64. package/dist/runtime/handle.js +15 -10
  65. package/dist/runtime/http-telemetry-binding.d.ts +10 -0
  66. package/dist/runtime/http-telemetry-binding.js +152 -0
  67. package/dist/runtime/http-telemetry-guard.d.ts +16 -0
  68. package/dist/runtime/http-telemetry-guard.js +202 -0
  69. package/dist/runtime/http-telemetry.d.ts +104 -0
  70. package/dist/runtime/http-telemetry.js +190 -0
  71. package/dist/runtime/http.d.ts +31 -0
  72. package/dist/runtime/http.js +356 -174
  73. package/dist/runtime/instrumentation.js +92 -13
  74. package/dist/runtime/ocr-telemetry.d.ts +82 -0
  75. package/dist/runtime/ocr-telemetry.js +192 -0
  76. package/dist/runtime/ocr.js +30 -8
  77. package/dist/runtime/request-telemetry.d.ts +2 -0
  78. package/dist/runtime/request-telemetry.js +2 -1
  79. package/dist/runtime/resolver-runtime-options.d.ts +14 -0
  80. package/dist/runtime/resolver-runtime-options.js +33 -0
  81. package/dist/runtime/resolver-shared.d.ts +3 -2
  82. package/dist/runtime/resolver-shared.js +4 -4
  83. package/dist/runtime/resolver-telemetry.d.ts +1 -0
  84. package/dist/runtime/resolver-telemetry.js +1 -1
  85. package/dist/runtime/resolver-vendors/browser.d.ts +2 -0
  86. package/dist/runtime/resolver-vendors/browser.js +46 -0
  87. package/dist/runtime/resolver-vendors/hosts.d.ts +21 -0
  88. package/dist/runtime/resolver-vendors/hosts.js +35 -0
  89. package/dist/runtime/resolver-vendors/hypersolutions.js +2 -2
  90. package/dist/runtime/resolver-vendors/types.d.ts +5 -4
  91. package/dist/runtime/resolver.d.ts +4 -1
  92. package/dist/runtime/resolver.js +46 -13
  93. package/dist/runtime/state-telemetry.d.ts +79 -0
  94. package/dist/runtime/state-telemetry.js +194 -0
  95. package/dist/runtime/state.d.ts +3 -0
  96. package/dist/runtime/state.js +26 -7
  97. package/dist/runtime/stealth-cookies.d.ts +5 -1
  98. package/dist/runtime/stealth-cookies.js +21 -1
  99. package/dist/runtime/stealth-owned-headers.d.ts +26 -0
  100. package/dist/runtime/stealth-owned-headers.js +37 -0
  101. package/dist/runtime/stealth-telemetry.d.ts +92 -0
  102. package/dist/runtime/stealth-telemetry.js +179 -0
  103. package/dist/runtime/stealth.d.ts +4 -1
  104. package/dist/runtime/stealth.js +228 -85
  105. package/dist/runtime/stt-telemetry.d.ts +77 -0
  106. package/dist/runtime/stt-telemetry.js +176 -0
  107. package/dist/runtime/stt.js +15 -6
  108. package/dist/server/error-stack-frames.d.ts +35 -0
  109. package/dist/server/error-stack-frames.js +219 -0
  110. package/dist/server/index.d.ts +9 -0
  111. package/dist/server/index.js +5 -0
  112. package/dist/server/sdk-version.d.ts +3 -0
  113. package/dist/server/sdk-version.js +19 -0
  114. package/dist/server/self-test.js +1 -18
  115. package/dist/server/sensitive-values.d.ts +1 -1
  116. package/dist/server/sensitive-values.js +9 -0
  117. package/dist/server/serve-implementation.d.ts +53 -2
  118. package/dist/server/serve-implementation.js +369 -123
  119. package/dist/server/types.d.ts +1 -0
  120. package/dist/server/types.js +7 -0
  121. package/dist/stateful/stateful-provider-owner-forwarder.js +22 -0
  122. package/dist/stateful/stateful-provider-runtime-context.d.ts +3 -0
  123. package/dist/stateful/stateful-provider-runtime-context.js +1 -0
  124. package/dist/types.d.ts +94 -1
  125. package/package.json +6 -1
  126. package/src/cli/commands.ts +14 -0
  127. package/src/cli/deployment-intent.ts +364 -0
  128. package/src/cli/migrate-deployment-intent.ts +1908 -0
  129. package/src/cli/migrate-provider-shape.ts +10 -4
  130. package/src/cli/resolver-runtime.ts +72 -0
  131. package/src/define.ts +13 -0
  132. package/src/dev.ts +9 -2
  133. package/src/engine.ts +38 -2
  134. package/src/error-resolution.ts +58 -0
  135. package/src/errors.ts +77 -1
  136. package/src/handle-meta.ts +39 -4
  137. package/src/handle.ts +121 -38
  138. package/src/i18n/error-messages.ts +255 -0
  139. package/src/i18n/index.ts +1 -0
  140. package/src/i18n/keys.ts +80 -6
  141. package/src/index.ts +91 -0
  142. package/src/lint.ts +552 -57
  143. package/src/provider.ts +20 -0
  144. package/src/runtime/browser-telemetry-binding.ts +92 -0
  145. package/src/runtime/browser-telemetry.ts +289 -0
  146. package/src/runtime/browser.ts +249 -65
  147. package/src/runtime/cache-telemetry.ts +247 -0
  148. package/src/runtime/cache.ts +68 -17
  149. package/src/runtime/capability-response.ts +53 -0
  150. package/src/runtime/capability-telemetry.ts +101 -0
  151. package/src/runtime/diagnostic-env.ts +11 -1
  152. package/src/runtime/engine-mode.ts +233 -0
  153. package/src/runtime/handle.ts +20 -10
  154. package/src/runtime/http-telemetry-binding.ts +162 -0
  155. package/src/runtime/http-telemetry-guard.ts +208 -0
  156. package/src/runtime/http-telemetry.ts +292 -0
  157. package/src/runtime/http.ts +457 -204
  158. package/src/runtime/instrumentation.ts +105 -16
  159. package/src/runtime/ocr-telemetry.ts +308 -0
  160. package/src/runtime/ocr.ts +109 -74
  161. package/src/runtime/request-telemetry.ts +2 -1
  162. package/src/runtime/resolver-runtime-options.ts +50 -0
  163. package/src/runtime/resolver-shared.ts +9 -4
  164. package/src/runtime/resolver-telemetry.ts +1 -1
  165. package/src/runtime/resolver-vendors/browser.ts +65 -7
  166. package/src/runtime/resolver-vendors/hosts.ts +43 -0
  167. package/src/runtime/resolver-vendors/hypersolutions.ts +2 -2
  168. package/src/runtime/resolver-vendors/types.ts +5 -4
  169. package/src/runtime/resolver.ts +64 -21
  170. package/src/runtime/state-telemetry.ts +298 -0
  171. package/src/runtime/state.ts +46 -45
  172. package/src/runtime/stealth-cookies.ts +24 -1
  173. package/src/runtime/stealth-owned-headers.ts +41 -0
  174. package/src/runtime/stealth-telemetry.ts +304 -0
  175. package/src/runtime/stealth.ts +355 -150
  176. package/src/runtime/stt-telemetry.ts +282 -0
  177. package/src/runtime/stt.ts +93 -71
  178. package/src/server/error-stack-frames.ts +214 -0
  179. package/src/server/index.ts +66 -0
  180. package/src/server/sdk-version.ts +22 -0
  181. package/src/server/self-test.ts +1 -21
  182. package/src/server/sensitive-values.ts +14 -0
  183. package/src/server/serve-implementation.ts +601 -157
  184. package/src/server/types.ts +7 -0
  185. package/src/stateful/stateful-provider-owner-forwarder.ts +23 -0
  186. package/src/stateful/stateful-provider-runtime-context.ts +4 -0
  187. package/src/types.ts +99 -1
  188. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +0 -6
  189. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +0 -3
  190. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +0 -10
  191. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +0 -3
  192. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +0 -3
  193. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +0 -2
  194. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +0 -3
  195. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +0 -6
  196. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +0 -1
  197. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +0 -1
  198. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +0 -3
  199. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +0 -7
  200. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +0 -19
  201. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +0 -6
  202. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +0 -3
  203. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +0 -8
  204. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +0 -5
  205. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +0 -4
  206. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +0 -3
  207. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +0 -3
  208. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +0 -10
  209. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +0 -1
  210. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +0 -1
  211. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-index.ts.txt +0 -3
  212. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-one.ts.txt +0 -6
  213. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-two.ts.txt +0 -6
  214. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-mixed-index.ts.txt +0 -14
  215. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-registry.ts.txt +0 -3
  216. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +0 -2
  217. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +0 -3
  218. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +0 -3
  219. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +0 -8
  220. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +0 -15
  221. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +0 -9
  222. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-kebab-operation-id.ts.txt +0 -17
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +0 -5
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +0 -24
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +0 -16
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-snake-operation-id.ts.txt +0 -21
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +0 -11
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +0 -7
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +0 -3
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +0 -18
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +0 -13
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +0 -31
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +0 -11
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +0 -11
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +0 -11
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +0 -21
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +0 -11
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +0 -14
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-en.json +0 -1
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ja.json +0 -1
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ko.json +0 -1
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-existing-operation-namespace-en.json +0 -8
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +0 -7
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +0 -6
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +0 -7
  246. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +0 -6
  247. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-binding-ambiguous.ts.txt +0 -12
  248. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported-other.ts.txt +0 -7
  249. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported.ts.txt +0 -5
  250. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-key-ambiguous.ts.txt +0 -19
  251. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-shorthand.ts.txt +0 -9
  252. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-typed.ts.txt +0 -11
  253. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-unrelated.ts.txt +0 -13
  254. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +0 -7
  255. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +0 -7
  256. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +0 -15
  257. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +0 -4
  258. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +0 -12
@@ -24,7 +24,11 @@ export type ProviderShapeKind =
24
24
  "single-phase-default-export"
25
25
  /** `const p = defineProvider({ ..., operations }); export default p;` */
26
26
  | "single-phase-variable-export"
27
- /** `const p = defineProvider({ ..., operations }); export default { ...p, deployment };` */
27
+ /**
28
+ * `const p = defineProvider({ ..., operations }); export default { ...p, extra };`
29
+ * — extras stay on the spread export; a `deployment` extra is a legacy
30
+ * surface that `apifuse migrate-deployment` hoists into the declaration.
31
+ */
28
32
  | "single-phase-variable-spread-export"
29
33
  /** Already `const b = defineProvider(...); export default b({ operations })` */
30
34
  | "two-phase";
@@ -218,7 +218,7 @@ function defaultExportCallsBuilder(exportAssignment, declarationCall) {
218
218
  * resolves to a builder-call result. Covers the three migrated layouts —
219
219
  * `export default buildProvider({...})`, an intermediate
220
220
  * `const provider = buildProvider({...}); export default provider;`, and the
221
- * spread export `export default { ...provider, deployment }` over such a
221
+ * spread export `export default { ...provider, ...extras }` over such a
222
222
  * binding. Without the latter two, re-running the transform on its own
223
223
  * spread-shape output reports "ambiguous" instead of "unchanged", which
224
224
  * breaks idempotency for repeated fan-out runs.
@@ -376,7 +376,9 @@ function rewriteDefaultExport(source, exportAssignment, shape, builderName, oper
376
376
  ];
377
377
  }
378
378
  // Spread export: re-introduce the provider binding so the extra properties
379
- // (currently `deployment`) still spread over a built provider.
379
+ // (e.g. `healthAccountSeedInputs`, or a legacy `deployment` that
380
+ // `apifuse migrate-deployment` later hoists) still spread over a built
381
+ // provider.
380
382
  const providerName = shape.variableName ?? "provider";
381
383
  const extras = shape.spreadExportExtras ?? "";
382
384
  const rebuilt = extras.length > 0
@@ -0,0 +1,21 @@
1
+ import { ResolverTelemetryCollector } from "../runtime/resolver-telemetry.js";
2
+ import type { ProviderCache, ProviderDefinition, ResolverContext } from "../types.js";
3
+ export interface CliResolverRuntime {
4
+ readonly resolver: ResolverContext;
5
+ /** Per-context sink; `toLogPayload()` is the `resolver` sibling of the server request log. */
6
+ readonly resolverTelemetry: ResolverTelemetryCollector;
7
+ /**
8
+ * Extend the collector's redaction with values learned after construction (request-scoped
9
+ * `sensitiveParams` the recorder captures); the collector redacts at record time, before it
10
+ * truncates, so values must be registered before the vendor call that may echo them.
11
+ */
12
+ readonly registerSensitiveValues: (values: readonly string[]) => void;
13
+ }
14
+ /**
15
+ * Resolver chain for the CLI helper contexts (`apifuse record`, the `apifuse dev` helper), built
16
+ * like a server request scope: engine-owned solver keys, the CDP pool URL, and the resolver
17
+ * timeout come from the process environment, the runtime options come from the shared builder,
18
+ * and every vendor invocation lands in a collector redacted with the provider's static sensitive
19
+ * inventory. A CLI context has no server-owned identity scope and no proxy telemetry.
20
+ */
21
+ export declare function createCliResolverRuntime(provider: ProviderDefinition, cache: ProviderCache): CliResolverRuntime;
@@ -0,0 +1,31 @@
1
+ import { compileProcessDiagnosticSensitiveValues, createDiagnosticRedactor, } from "../runtime/diagnostic-redactor.js";
2
+ import { createResolverClientFromEnv, createUnsupportedResolverClient, } from "../runtime/resolver.js";
3
+ import { createResolverRuntimeOptions, resolveNativeProxyPolicy, } from "../runtime/resolver-runtime-options.js";
4
+ import { ResolverTelemetryCollector } from "../runtime/resolver-telemetry.js";
5
+ import { collectStaticDiagnosticSensitiveValues } from "../server/sensitive-values.js";
6
+ import { getStealthProfile } from "../stealth/profiles.js";
7
+ /**
8
+ * Resolver chain for the CLI helper contexts (`apifuse record`, the `apifuse dev` helper), built
9
+ * like a server request scope: engine-owned solver keys, the CDP pool URL, and the resolver
10
+ * timeout come from the process environment, the runtime options come from the shared builder,
11
+ * and every vendor invocation lands in a collector redacted with the provider's static sensitive
12
+ * inventory. A CLI context has no server-owned identity scope and no proxy telemetry.
13
+ */
14
+ export function createCliResolverRuntime(provider, cache) {
15
+ const sensitiveValues = createDiagnosticRedactor([], compileProcessDiagnosticSensitiveValues(collectStaticDiagnosticSensitiveValues(provider)));
16
+ const resolverTelemetry = new ResolverTelemetryCollector({ redact: sensitiveValues.redact });
17
+ const registerSensitiveValues = (values) => sensitiveValues.add(values);
18
+ if (!provider.resolver) {
19
+ return {
20
+ resolver: createUnsupportedResolverClient("Provider does not declare resolver capability"),
21
+ resolverTelemetry,
22
+ registerSensitiveValues,
23
+ };
24
+ }
25
+ const stealthProfile = provider.stealth ? getStealthProfile(provider.stealth) : undefined;
26
+ return {
27
+ resolver: createResolverClientFromEnv(provider.resolver, process.env, createResolverRuntimeOptions(provider, cache, undefined, resolveNativeProxyPolicy(provider), { upstream: { proxy: provider.proxy } }, stealthProfile, resolverTelemetry)),
28
+ resolverTelemetry,
29
+ registerSensitiveValues,
30
+ };
31
+ }
package/dist/define.d.ts CHANGED
@@ -54,6 +54,9 @@ export interface ProviderDeclaration {
54
54
  * provider definition. The SDK types this field but does not deep-validate
55
55
  * it — the APIFuse registry builder owns deployment validation and
56
56
  * resolves omitted fields against the runtime deployment profiles.
57
+ *
58
+ * This is the only authored deployment surface (no standalone
59
+ * `deploy.ts`); declare only the fields that differ from the profile.
57
60
  */
58
61
  deployment?: ProviderDeploymentOverrides;
59
62
  /** Declares the HTTP capability binding. A bare object states use without configuration. */
package/dist/define.js CHANGED
@@ -636,6 +636,11 @@ function validateProviderImplementationShape(config) {
636
636
  }
637
637
  function validateProviderProxy(config) {
638
638
  for (const secret of config.secrets ?? []) {
639
+ if (secret.issuer !== undefined &&
640
+ secret.issuer !== "apifuse" &&
641
+ secret.issuer !== "contributor") {
642
+ throw new ValidationError(`Provider "${config.id}" secret "${secret.name}" has invalid issuer "${String(secret.issuer)}"`, { fix: `Set issuer to "apifuse" or "contributor", or omit it.` });
643
+ }
639
644
  const engineName = engineOwnedResolverCredentialTarget(secret.name);
640
645
  if (engineName !== undefined) {
641
646
  throw new ValidationError(`Provider "${config.id}" cannot declare engine-owned resolver credential "${secret.name}"`, {
package/dist/dev.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import type { ProviderEngine } from "./engine.js";
1
+ import type { ProviderEngine, ProviderEngineMode } from "./engine.js";
2
2
  import type { ProviderDefinition } from "./types.js";
3
3
  export interface DevServerOptions {
4
4
  port?: number;
5
5
  sessionDbPath?: string;
6
6
  /** Override the default in-process engine attachment. */
7
7
  engine?: ProviderEngine;
8
+ /** Explicit engine mode; `APIFUSE__ENGINE__MODE` outranks it when both are set. */
9
+ engineMode?: ProviderEngineMode;
8
10
  }
9
11
  export declare function createDevServer(provider: ProviderDefinition, options?: DevServerOptions): {
10
12
  start: () => void;
package/dist/dev.js CHANGED
@@ -5,7 +5,12 @@ export function createDevServer(provider, options) {
5
5
  start: () => {
6
6
  // Local development has no Redis by default; handles (ADR-0012) need a
7
7
  // state backend, so fall back to memory state when none is configured.
8
- void serve(provider, { port, engine: options?.engine, allowMemoryStateFallback: true });
8
+ void serve(provider, {
9
+ port,
10
+ engine: options?.engine,
11
+ engineMode: options?.engineMode,
12
+ allowMemoryStateFallback: true,
13
+ });
9
14
  console.log(`[apifuse dev] ${provider.id}@${provider.version} running at http://localhost:${port}`);
10
15
  console.log(`[apifuse dev] Operations: ${Object.keys(provider.operations).join(", ")}`);
11
16
  console.log(`[apifuse dev] Health: http://localhost:${port}/health`);
package/dist/engine.d.ts CHANGED
@@ -2,6 +2,25 @@ import type { HandleContext } from "./handle.js";
2
2
  import type { AuthContext, BrowserClient, CredentialContext, EnvContext, HttpClient, NativeContext, OcrContext, ProviderCache, ProviderContext, ProviderDefinition, ProviderFilesContext, ProviderRequestContext, ProviderRuntimeState, ResolverContext, StealthClient, SttContext, TraceContext } from "./types.js";
3
3
  /** Versioned envelope protocol used by out-of-process engine transports. */
4
4
  export declare const PROVIDER_ENGINE_PROTOCOL_VERSION: "provider-engine.v1";
5
+ /**
6
+ * Environment variable that selects how a provider process attaches its capability
7
+ * bindings. Engine-owned by prefix (`APIFUSE__ENGINE__*`): never declarable as a
8
+ * provider secret and never projected into `ctx.env`.
9
+ *
10
+ * Values are trimmed and case-folded; absent or blank means "unset". An
11
+ * unrecognized value is reported on the `provider_engine_mode` boot event and
12
+ * ignored — a deployment-authored typo must never turn into CrashLoopBackOff.
13
+ */
14
+ export declare const PROVIDER_ENGINE_MODE_ENV = "APIFUSE__ENGINE__MODE";
15
+ /**
16
+ * How a provider process attaches its capability bindings: `"in-process"` today,
17
+ * `"remote"` for the authenticated engine (ADR-0011).
18
+ *
19
+ * The union is intentionally open so further lanes (for example a provider hosted
20
+ * inside the engine) can be named without a breaking change. Unknown values are
21
+ * rejected at runtime, not by the type.
22
+ */
23
+ export type ProviderEngineMode = "in-process" | "remote" | (string & {});
5
24
  /** Credential names owned by the engine and forbidden in provider declarations. */
6
25
  export declare const ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES: readonly ["APIFUSE__PROXY__SMARTPROXY_APP_KEY", "APIFUSE__PROXY__NODEMAVEN_USERNAME", "APIFUSE__PROXY__NODEMAVEN_PASSWORD"];
7
26
  export declare function isEngineOwnedProxyCredentialName(name: string): boolean;
@@ -89,7 +108,22 @@ export interface ProviderEngineAttachmentInput {
89
108
  }
90
109
  /** Attachment boundary shared by in-process development and remote RPC bridges. */
91
110
  export interface ProviderEngine {
111
+ /**
112
+ * Which attachment this engine performs. Lets the server report a truthful
113
+ * mode at boot and compare an explicit engine object against a requested
114
+ * `engineMode`; omit for opaque host engines (reported as `custom`).
115
+ */
116
+ readonly kind?: ProviderEngineMode;
92
117
  attach<TDeclaration extends object = Record<string, unknown>>(input: ProviderEngineAttachmentInput): ProviderContext<TDeclaration>;
93
118
  }
94
- /** Local engine attachment; deployed bridges implement the same interface with RPC clients. */
119
+ /**
120
+ * Local engine attachment; deployed bridges implement the same interface with RPC clients.
121
+ *
122
+ * ADR-0011 makes the authenticated remote engine the only attachment, so this one
123
+ * is scheduled for removal — but not deprecated yet: the remote client ships in a
124
+ * later release, and deprecating the only working constructor before its
125
+ * replacement exists would flag every current caller with no fix available. Until
126
+ * then it stays the default, and the server reports each in-process boot as
127
+ * `provider_engine_mode` with `deprecated: true`.
128
+ */
95
129
  export declare function createInProcessProviderEngine(): ProviderEngine;
package/dist/engine.js CHANGED
@@ -4,6 +4,16 @@ import { APIFUSE__RESOLVER__2CAPTCHA__API_KEY, APIFUSE__RESOLVER__CAPMONSTER__AP
4
4
  import { OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME, } from "./runtime/otlp.js";
5
5
  /** Versioned envelope protocol used by out-of-process engine transports. */
6
6
  export const PROVIDER_ENGINE_PROTOCOL_VERSION = "provider-engine.v1";
7
+ /**
8
+ * Environment variable that selects how a provider process attaches its capability
9
+ * bindings. Engine-owned by prefix (`APIFUSE__ENGINE__*`): never declarable as a
10
+ * provider secret and never projected into `ctx.env`.
11
+ *
12
+ * Values are trimmed and case-folded; absent or blank means "unset". An
13
+ * unrecognized value is reported on the `provider_engine_mode` boot event and
14
+ * ignored — a deployment-authored typo must never turn into CrashLoopBackOff.
15
+ */
16
+ export const PROVIDER_ENGINE_MODE_ENV = "APIFUSE__ENGINE__MODE";
7
17
  /** Credential names owned by the engine and forbidden in provider declarations. */
8
18
  export const ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES = [
9
19
  "APIFUSE__PROXY__SMARTPROXY_APP_KEY",
@@ -184,7 +194,16 @@ function attachInProcess(input) {
184
194
  },
185
195
  });
186
196
  }
187
- /** Local engine attachment; deployed bridges implement the same interface with RPC clients. */
197
+ /**
198
+ * Local engine attachment; deployed bridges implement the same interface with RPC clients.
199
+ *
200
+ * ADR-0011 makes the authenticated remote engine the only attachment, so this one
201
+ * is scheduled for removal — but not deprecated yet: the remote client ships in a
202
+ * later release, and deprecating the only working constructor before its
203
+ * replacement exists would flag every current caller with no fix available. Until
204
+ * then it stays the default, and the server reports each in-process boot as
205
+ * `provider_engine_mode` with `deprecated: true`.
206
+ */
188
207
  export function createInProcessProviderEngine() {
189
- return { attach: attachInProcess };
208
+ return { kind: "in-process", attach: attachInProcess };
190
209
  }
@@ -2,3 +2,4 @@ import type { ProviderErrorStatus } from "./types.js";
2
2
  export declare const SDK_OWNED_PROVIDER_ERROR_CODES: Set<string>;
3
3
  export declare const SDK_RUNTIME_OWNED_ERROR_CODES: Set<string>;
4
4
  export declare const SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES: ReadonlyMap<string, ProviderErrorStatus>;
5
+ export declare const SDK_CANONICAL_ERROR_CODE_RETRYABILITY: ReadonlyMap<string, boolean>;
@@ -18,6 +18,14 @@ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
18
18
  "refresh_not_supported",
19
19
  "RUNTIME_UNSUPPORTED",
20
20
  "PROVIDER_STATE_UNSUPPORTED",
21
+ // Engine attachment (ADR-0011). Registered here so an engine failure is served
22
+ // as a known SDK code instead of raising a false
23
+ // `unregistered_provider_error_code` signal on a 500.
24
+ "PROVIDER_ENGINE_AUTHENTICATION_FAILED",
25
+ "PROVIDER_ENGINE_PROTOCOL_VERSION_MISMATCH",
26
+ "PROVIDER_ENGINE_UNAVAILABLE",
27
+ "PROVIDER_ENGINE_MODE_UNSUPPORTED",
28
+ "PROVIDER_EGRESS_DENIED",
21
29
  "HANDLE_INVALID",
22
30
  "HANDLE_NOT_FOUND",
23
31
  "HANDLE_EXPIRED",
@@ -57,6 +65,7 @@ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
57
65
  "http_redirect_missing_location",
58
66
  "http_redirect_loop",
59
67
  "transport_invalid_url",
68
+ "http_header_factory_failed",
60
69
  "EGRESS_LEASE_INVALID",
61
70
  "EGRESS_LEASE_BINDING_INVALID",
62
71
  "EGRESS_LEASE_KEY_MISSING",
@@ -84,6 +93,7 @@ export const SDK_OWNED_PROVIDER_ERROR_CODES = new Set([
84
93
  "STATEFUL_FORWARDING_OWNER_FENCE_INVALID",
85
94
  "STATEFUL_FORWARDING_REQUEST_FAILED",
86
95
  "STATEFUL_FORWARDING_CONTEXT_MISSING",
96
+ "STATEFUL_FORWARDING_CONTEXT_INVALID",
87
97
  "STATEFUL_FORWARDING_BAD_RESPONSE",
88
98
  "STATEFUL_INTERNAL_EXECUTOR_NOT_CONFIGURED",
89
99
  "STATEFUL_FILE_FORWARDING_UNSUPPORTED",
@@ -144,9 +154,53 @@ export const SDK_STATUS_MAPPED_PROVIDER_ERROR_CODES = new Map([
144
154
  ["HANDLE_BUSY", 409],
145
155
  ["UPSTREAM_ERROR", 502],
146
156
  ["BLOCKED", 502],
157
+ // Fleet-consensus provider codes. These are thrown by provider code, not
158
+ // by the SDK, so they are registered here (status mapping) and not in
159
+ // SDK_RUNTIME_OWNED_ERROR_CODES: an operation-declared status still wins,
160
+ // exactly as it does for UPSTREAM_ERROR and BLOCKED above. Registering
161
+ // them stops the fleet from re-declaring the same three rows on every
162
+ // operation, and stops an undeclared throw from being served as 500.
163
+ //
164
+ // A platform-managed upstream service key the upstream refuses. With
165
+ // `auth.mode: "platform-managed"` the caller holds no credential, so 401
166
+ // ("re-authenticate") tells the caller to do something it cannot do, and
167
+ // 502 ("upstream is sick") promises a recovery that will never come. It is
168
+ // a deployment/config defect — the same class as MISSING_SECRET above,
169
+ // which is already an explicit 400 for that reason.
170
+ ["UPSTREAM_AUTH_ERROR", 400],
171
+ // The upstream changed its response shape and the provider cannot
172
+ // normalize it. 502 because the fault is upstream of us, non-retryable
173
+ // because a retry returns the same broken payload.
174
+ ["UPSTREAM_SCHEMA_ERROR", 502],
175
+ // Caller-side bad input rejected by the provider. The minority spellings
176
+ // (INVALID_INPUT / VALIDATION_ERROR / BAD_REQUEST) are deliberately not
177
+ // registered: they migrate to this spelling on the contract track, and
178
+ // registering them here would freeze the divergence.
179
+ ["INVALID_REQUEST", 400],
147
180
  ["OCR_UNAVAILABLE", 503],
148
181
  ["UNSUPPORTED_OCR_BACKEND", 503],
149
182
  ["STT_UNAVAILABLE", 503],
150
183
  ["UNSUPPORTED_STT_BACKEND", 503],
151
184
  ["STATEFUL_FORWARDING_REPLAY_CACHE_FULL", 503],
185
+ // The engine is reachable-in-principle but not now: retryable, so the
186
+ // caller may retry once the engine recovers. Authentication, protocol
187
+ // mismatch, an unsupported mode and denied egress stay unmapped (500) and
188
+ // non-retryable: they are deployment or provider faults that no caller
189
+ // retry can clear, and a retryable 5xx there would turn one bad rollout
190
+ // into gateway-driven load.
191
+ ["PROVIDER_ENGINE_UNAVAILABLE", 503],
192
+ ]);
193
+ // Canonical retryability for the fleet-consensus codes registered above.
194
+ //
195
+ // Runtime retryability still resolves as `instance option ?? declared ??
196
+ // false`, so this map changes no served response: an undeclared throw already
197
+ // defaults to false, which is what every entry here says. It exists so the
198
+ // authoring lint can tell a provider that its declared `retryable` contradicts
199
+ // the registered meaning of the code, instead of the fleet quietly shipping two
200
+ // answers for the same code. Only codes whose retryability was fixed as part of
201
+ // registration belong here — do not backfill opinions the SDK never made.
202
+ export const SDK_CANONICAL_ERROR_CODE_RETRYABILITY = new Map([
203
+ ["UPSTREAM_AUTH_ERROR", false],
204
+ ["UPSTREAM_SCHEMA_ERROR", false],
205
+ ["INVALID_REQUEST", false],
152
206
  ]);
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type { ProviderErrorMessageParams } from "./i18n/error-messages.js";
1
2
  import type { ProviderErrorCategory } from "./observability.js";
2
- import type { HttpRedirectFailureReason } from "./types.js";
3
+ import type { HttpRedirectFailureReason, ProviderLocaleKeyInput } from "./types.js";
3
4
  export type ProviderErrorOptions = {
4
5
  fix?: string;
5
6
  code?: string;
@@ -9,6 +10,25 @@ export type ProviderErrorOptions = {
9
10
  retryable?: boolean;
10
11
  /** Provider-authored, bounded metadata safe for operational logs and error headers. */
11
12
  observability?: ProviderErrorObservability;
13
+ /**
14
+ * Locale catalog key for the client-facing `message`, e.g.
15
+ * `"errors.upstreamSchema.message"`. Resolved at serve time against the
16
+ * provider's `locales/{en,ko,ja}.json` with the caller's `Accept-Language`,
17
+ * falling back to `en` and then to the positional `message`.
18
+ *
19
+ * The positional `message` stays English: it is what `error.message`, cause
20
+ * frames, logs and OTLP attributes carry. Only the response envelope is
21
+ * localized.
22
+ */
23
+ messageKey?: ProviderLocaleKeyInput;
24
+ /** Locale catalog key for the client-facing `fix`. Same resolution as {@link ProviderErrorOptions.messageKey}. */
25
+ fixKey?: ProviderLocaleKeyInput;
26
+ /**
27
+ * Values substituted into `{name}` placeholders of the resolved text.
28
+ * Strings and finite numbers only; string values are scrubbed and length
29
+ * capped before substitution because upstream text routinely lands here.
30
+ */
31
+ params?: ProviderErrorMessageParams;
12
32
  };
13
33
  /**
14
34
  * Provider-authored error diagnostics whose runtime values are validated before emission.
@@ -33,6 +53,24 @@ export declare class ProviderError extends Error {
33
53
  export declare class SDKError extends ProviderError {
34
54
  constructor(message: string, options?: ProviderErrorOptions);
35
55
  }
56
+ /** Raised when the remote provider engine speaks an incompatible protocol version. */
57
+ export declare class ProviderEngineProtocolVersionError extends SDKError {
58
+ readonly receivedVersion: unknown;
59
+ readonly expectedVersion: string;
60
+ constructor(receivedVersion: unknown, expectedVersion: string);
61
+ }
62
+ /** Raised when the remote provider engine rejects a workspace API key. */
63
+ export declare class ProviderEngineAuthenticationError extends SDKError {
64
+ constructor(message?: string, options?: ProviderErrorOptions);
65
+ }
66
+ /** Raised when the remote engine cannot be reached. There is no local fallback. */
67
+ export declare class ProviderEngineUnavailableError extends SDKError {
68
+ constructor(message?: string, cause?: Error);
69
+ }
70
+ /** Raised when the engine refuses egress outside the workspace's pinned allowlist. */
71
+ export declare class ProviderEgressDeniedError extends ProviderError {
72
+ constructor(message: string, details?: unknown);
73
+ }
36
74
  /** Raised when persisted stealth cookies use a store version this SDK cannot read. */
37
75
  export declare class StealthCookieStoreVersionError extends SDKError {
38
76
  readonly version: unknown;
package/dist/errors.js CHANGED
@@ -59,6 +59,56 @@ export class SDKError extends ProviderError {
59
59
  this.name = "SDKError";
60
60
  }
61
61
  }
62
+ /** Raised when the remote provider engine speaks an incompatible protocol version. */
63
+ export class ProviderEngineProtocolVersionError extends SDKError {
64
+ receivedVersion;
65
+ expectedVersion;
66
+ constructor(receivedVersion, expectedVersion) {
67
+ super(`Provider engine protocol version mismatch: expected ${expectedVersion}, received ${String(receivedVersion)}`, {
68
+ code: "PROVIDER_ENGINE_PROTOCOL_VERSION_MISMATCH",
69
+ details: { receivedVersion, expectedVersion },
70
+ fix: "Update @apifuse/provider-sdk or use a compatible APIFuse provider engine.",
71
+ });
72
+ this.receivedVersion = receivedVersion;
73
+ this.expectedVersion = expectedVersion;
74
+ this.name = "ProviderEngineProtocolVersionError";
75
+ }
76
+ }
77
+ /** Raised when the remote provider engine rejects a workspace API key. */
78
+ export class ProviderEngineAuthenticationError extends SDKError {
79
+ constructor(message = "Provider engine authentication failed", options) {
80
+ super(message, {
81
+ code: "PROVIDER_ENGINE_AUTHENTICATION_FAILED",
82
+ fix: "Set APIFUSE__ENGINE__API_KEY to the workspace API key from your APIFuse bounty dashboard.",
83
+ ...options,
84
+ });
85
+ this.name = "ProviderEngineAuthenticationError";
86
+ }
87
+ }
88
+ /** Raised when the remote engine cannot be reached. There is no local fallback. */
89
+ export class ProviderEngineUnavailableError extends SDKError {
90
+ constructor(message = "The remote APIFuse provider engine is unavailable", cause) {
91
+ super(message, {
92
+ code: "PROVIDER_ENGINE_UNAVAILABLE",
93
+ retryable: true,
94
+ fix: "Check network access and the provider engine endpoint, then retry.",
95
+ ...(cause ? { cause } : {}),
96
+ });
97
+ this.name = "ProviderEngineUnavailableError";
98
+ }
99
+ }
100
+ /** Raised when the engine refuses egress outside the workspace's pinned allowlist. */
101
+ export class ProviderEgressDeniedError extends ProviderError {
102
+ constructor(message, details) {
103
+ super(message, {
104
+ code: "PROVIDER_EGRESS_DENIED",
105
+ retryable: false,
106
+ details,
107
+ fix: "Use a host in the provider's pinned allowedHosts declaration, or request a trusted pin update.",
108
+ });
109
+ this.name = "ProviderEgressDeniedError";
110
+ }
111
+ }
62
112
  /** Raised when persisted stealth cookies use a store version this SDK cannot read. */
63
113
  export class StealthCookieStoreVersionError extends SDKError {
64
114
  version;
@@ -9,12 +9,18 @@
9
9
  export declare const APIFUSE_HANDLE_META_KEY: "x-apifuse-handle";
10
10
  export type HandleKindType = "cursor" | "draft";
11
11
  export type HandleAccess = "bound" | "public";
12
+ /**
13
+ * Operation key(s) that issue a handle. A single string is the common case; a
14
+ * list names every operation whose output carries the field (for example
15
+ * `search-address` and `reverse-geocode` both issuing `location_token`).
16
+ */
17
+ export type HandleIssuedBy = string | readonly string[];
12
18
  /** Value stored under {@link APIFUSE_HANDLE_META_KEY} on a handle field. */
13
19
  export interface HandleFieldMeta {
14
20
  readonly kind: string;
15
21
  readonly type: HandleKindType;
16
22
  readonly fieldName: string;
17
- readonly issuedBy?: string;
23
+ readonly issuedBy?: HandleIssuedBy;
18
24
  }
19
25
  /**
20
26
  * Structural view of a handle kind as seen by the provider declaration
@@ -26,10 +32,20 @@ export interface HandleKindDeclaration {
26
32
  readonly type: HandleKindType;
27
33
  readonly fieldName: string;
28
34
  readonly access: HandleAccess;
29
- readonly issuedBy?: string;
35
+ readonly issuedBy?: HandleIssuedBy;
30
36
  }
31
37
  /** Kind names are lowercase letters only so they never fuse with the word body. */
32
38
  export declare const HANDLE_KIND_NAME_PATTERN: RegExp;
39
+ /** True for a single operation key or a non-empty list of operation keys. */
40
+ export declare function isHandleIssuedBy(value: unknown): value is HandleIssuedBy;
41
+ /** Normalizes `issuedBy` to a list of operation keys (empty when undefined). */
42
+ export declare function handleIssuerList(issuedBy: HandleIssuedBy | undefined): readonly string[];
43
+ /**
44
+ * Renders the issuing operation(s) as inline code for error and description
45
+ * text: `` `a` ``, `` `a` or `b` ``, `` `a`, `b`, or `c` ``. Undefined when no
46
+ * issuer is declared.
47
+ */
48
+ export declare function formatHandleIssuers(issuedBy: HandleIssuedBy | undefined): string | undefined;
33
49
  export declare function isHandleFieldMeta(value: unknown): value is HandleFieldMeta;
34
50
  /**
35
51
  * The SDK-owned description `kind.field()` emits. Lint exempts a handle field
@@ -9,6 +9,33 @@
9
9
  export const APIFUSE_HANDLE_META_KEY = "x-apifuse-handle";
10
10
  /** Kind names are lowercase letters only so they never fuse with the word body. */
11
11
  export const HANDLE_KIND_NAME_PATTERN = /^[a-z]{2,12}$/;
12
+ /** True for a single operation key or a non-empty list of operation keys. */
13
+ export function isHandleIssuedBy(value) {
14
+ if (typeof value === "string")
15
+ return true;
16
+ return (Array.isArray(value) && value.length > 0 && value.every((entry) => typeof entry === "string"));
17
+ }
18
+ /** Normalizes `issuedBy` to a list of operation keys (empty when undefined). */
19
+ export function handleIssuerList(issuedBy) {
20
+ if (issuedBy === undefined)
21
+ return [];
22
+ return typeof issuedBy === "string" ? [issuedBy] : issuedBy;
23
+ }
24
+ /**
25
+ * Renders the issuing operation(s) as inline code for error and description
26
+ * text: `` `a` ``, `` `a` or `b` ``, `` `a`, `b`, or `c` ``. Undefined when no
27
+ * issuer is declared.
28
+ */
29
+ export function formatHandleIssuers(issuedBy) {
30
+ const issuers = handleIssuerList(issuedBy).map((operation) => `\`${operation}\``);
31
+ if (issuers.length === 0)
32
+ return undefined;
33
+ if (issuers.length === 1)
34
+ return issuers[0];
35
+ if (issuers.length === 2)
36
+ return `${issuers[0]} or ${issuers[1]}`;
37
+ return `${issuers.slice(0, -1).join(", ")}, or ${issuers[issuers.length - 1]}`;
38
+ }
12
39
  export function isHandleFieldMeta(value) {
13
40
  if (typeof value !== "object" || value === null)
14
41
  return false;
@@ -16,7 +43,7 @@ export function isHandleFieldMeta(value) {
16
43
  return (typeof record.kind === "string" &&
17
44
  (record.type === "cursor" || record.type === "draft") &&
18
45
  typeof record.fieldName === "string" &&
19
- (record.issuedBy === undefined || typeof record.issuedBy === "string"));
46
+ (record.issuedBy === undefined || isHandleIssuedBy(record.issuedBy)));
20
47
  }
21
48
  /**
22
49
  * The SDK-owned description `kind.field()` emits. Lint exempts a handle field
@@ -24,6 +51,7 @@ export function isHandleFieldMeta(value) {
24
51
  * provider override re-enters the localization rules.
25
52
  */
26
53
  export function handleFieldDescription(meta) {
27
- const origin = meta.issuedBy ? ` issued by \`${meta.issuedBy}\`` : "";
54
+ const issuers = formatHandleIssuers(meta.issuedBy);
55
+ const origin = issuers ? ` issued by ${issuers}` : "";
28
56
  return `Opaque handle${origin}. Copy it exactly as returned; do not edit or shorten it.`;
29
57
  }
package/dist/handle.d.ts CHANGED
@@ -9,9 +9,9 @@
9
9
  */
10
10
  import { type ZodString, type ZodType, z } from "zod";
11
11
  import { ProviderError, type ProviderErrorOptions } from "./errors.js";
12
- import { type HandleAccess, type HandleFieldMeta, type HandleKindDeclaration, type HandleKindType } from "./handle-meta.js";
12
+ import { type HandleAccess, type HandleFieldMeta, type HandleIssuedBy, type HandleKindDeclaration, type HandleKindType } from "./handle-meta.js";
13
13
  import type { ProviderStateDurationString } from "./types.js";
14
- export type { HandleAccess, HandleFieldMeta, HandleKindDeclaration, HandleKindType };
14
+ export type { HandleAccess, HandleFieldMeta, HandleIssuedBy, HandleKindDeclaration, HandleKindType, };
15
15
  export type HandleStrength = "standard" | "high";
16
16
  /** Words issued per handle: 2 for bound kinds, 4 for public, 5 for high-strength public. */
17
17
  export type HandleWordCount = 2 | 4 | 5;
@@ -41,7 +41,10 @@ export interface CursorKind<TSchema extends ZodType = ZodType> extends HandleKin
41
41
  }
42
42
  export interface DraftKind<TSchema extends ZodType = ZodType, TResultSchema extends ZodType | undefined = ZodType | undefined> extends HandleKindBase<TSchema> {
43
43
  readonly type: "draft";
44
- readonly access: "bound";
44
+ /** `"bound"` (default): connection-scoped, 2 words. `"public"`: provider-scoped, 4-5 words. */
45
+ readonly access: HandleAccess;
46
+ /** Public only; `"high"` forces 5 words. Always `"standard"` for bound drafts. */
47
+ readonly strength: HandleStrength;
45
48
  readonly ttl: {
46
49
  readonly idle: ProviderStateDurationString;
47
50
  readonly max: ProviderStateDurationString;
@@ -52,7 +55,6 @@ export interface DraftKind<TSchema extends ZodType = ZodType, TResultSchema exte
52
55
  readonly resultTtlMs: number;
53
56
  /** Optional schema describing the commit result; type-level only at runtime. */
54
57
  readonly result: TResultSchema | undefined;
55
- readonly wordCount: 2;
56
58
  }
57
59
  export type HandleKind = CursorKind<any> | DraftKind<any, any>;
58
60
  /** Stored record data type (schema output); what `read`, `update`, and `commit` callbacks receive. */
@@ -79,6 +81,12 @@ export interface HandleCommitResult<K extends HandleKind> {
79
81
  export interface HandleContext {
80
82
  /** Validates `data` with `kind.schema`, stores it, and returns the canonical handle. */
81
83
  create<K extends HandleKind>(kind: K, data: InputOf<K>): Promise<string>;
84
+ /**
85
+ * Same as `create` but returns the full record (`handle`, `status`, `data`,
86
+ * `createdAt`, `expiresAt`) so a provider can expose `expires_at` without
87
+ * recomputing ttl math. `create` is the string-returning shortcut.
88
+ */
89
+ createRecord<K extends HandleKind>(kind: K, data: InputOf<K>): Promise<HandleRecord<K>>;
82
90
  /** Tolerantly parses `handle`, loads the record; drafts get their idle TTL touched. */
83
91
  read<K extends HandleKind>(kind: K, handle: string): Promise<HandleRecord<K>>;
84
92
  /** CAS update of an active draft (3 retries) with sliding TTL. */
@@ -123,7 +131,7 @@ export declare function isHandleError(value: unknown): value is HandleError;
123
131
  */
124
132
  export declare function handleRecoverySentence(kind: {
125
133
  readonly fieldName: string;
126
- readonly issuedBy?: string;
134
+ readonly issuedBy?: HandleIssuedBy;
127
135
  }): string;
128
136
  /** Parses a `ProviderStateDurationString` to milliseconds; throws on invalid or non-positive input. */
129
137
  export declare function parseHandleDurationMs(value: ProviderStateDurationString, label: string): number;
@@ -142,8 +150,8 @@ export interface DefineCursorOptions<TSchema extends ZodType> {
142
150
  readonly maxValueBytes?: number;
143
151
  /** Public only; `"high"` forces 5 words. Auto-high when ttl > 1h. */
144
152
  readonly strength?: HandleStrength;
145
- /** Operation key that issues this handle; used in error text and lint. */
146
- readonly issuedBy?: string;
153
+ /** Operation key(s) that issue this handle; used in error text and lint. */
154
+ readonly issuedBy?: HandleIssuedBy;
147
155
  }
148
156
  export interface DefineDraftOptions<TSchema extends ZodType, TResultSchema extends ZodType | undefined> {
149
157
  readonly name: string;
@@ -157,15 +165,28 @@ export interface DefineDraftOptions<TSchema extends ZodType, TResultSchema exten
157
165
  };
158
166
  /** How long a committed record stays for replay. Default "24h". */
159
167
  readonly resultTtl?: ProviderStateDurationString;
160
- /** Default 200 per connection. */
168
+ /**
169
+ * `"bound"` (default): connection-scoped, 2 words. `"public"`: provider-scoped
170
+ * draft for connectionless providers (`auth: none`), 4-5 words, `maxEntries`
171
+ * required; every lookup failure collapses to `HANDLE_INVALID`.
172
+ */
173
+ readonly access?: HandleAccess;
174
+ /** Required when public. Bound default 200 per connection. */
161
175
  readonly maxEntries?: number;
162
176
  /** Default 64,000. */
163
177
  readonly maxValueBytes?: number;
164
- readonly issuedBy?: string;
178
+ /** Public only; `"high"` forces 5 words. Auto-high when ttl.max > 1h. */
179
+ readonly strength?: HandleStrength;
180
+ /** Operation key(s) that issue this handle; used in error text and lint. */
181
+ readonly issuedBy?: HandleIssuedBy;
165
182
  }
166
183
  /** Defines an immutable cursor kind (pagination, offered option lists). */
167
184
  export declare function defineCursor<TSchema extends ZodType>(options: DefineCursorOptions<TSchema>): CursorKind<TSchema>;
168
- /** Defines a mutable, always-bound draft kind (multi-turn forms with one-shot commit). */
185
+ /**
186
+ * Defines a mutable draft kind (multi-turn forms with one-shot commit). Bound
187
+ * by default; `access: "public"` opts a connectionless provider into a
188
+ * provider-scoped draft under the public guessing analysis (ADR-0012 D3).
189
+ */
169
190
  export declare function defineDraft<TSchema extends ZodType, TResultSchema extends ZodType | undefined = undefined>(options: DefineDraftOptions<TSchema, TResultSchema>): DraftKind<TSchema, TResultSchema>;
170
191
  export declare function isDraftKind(kind: HandleKind): kind is DraftKind<any, any>;
171
192
  export declare function isCursorKind(kind: HandleKind): kind is CursorKind<any>;
@@ -174,8 +195,8 @@ export interface PickOptions<T> {
174
195
  readonly field: string;
175
196
  /** Item property compared against `value`. Default = `field`. */
176
197
  readonly by?: keyof T & string;
177
- /** Operation that listed the items; used in the error message when known. */
178
- readonly issuedBy?: string;
198
+ /** Operation(s) that listed the items; used in the error message when known. */
199
+ readonly issuedBy?: HandleIssuedBy;
179
200
  }
180
201
  /**
181
202
  * Chooses one offered item by a plain value the LLM copied from the offer.