@yolk-sdk/emulators 0.1.0-canary.123 → 0.1.0-canary.125

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 (276) hide show
  1. package/README.md +3 -1
  2. package/dist/anthropic.d.mts +45 -47
  3. package/dist/anthropic.d.mts.map +1 -1
  4. package/dist/anthropic.mjs +3 -4
  5. package/dist/anthropic.mjs.map +1 -1
  6. package/dist/chat-completions.d.mts +74 -55
  7. package/dist/chat-completions.d.mts.map +1 -1
  8. package/dist/chat-completions.mjs +3 -4
  9. package/dist/chat-completions.mjs.map +1 -1
  10. package/dist/codex.d.mts +45 -47
  11. package/dist/codex.d.mts.map +1 -1
  12. package/dist/codex.mjs +4 -5
  13. package/dist/codex.mjs.map +1 -1
  14. package/dist/dropbox/api.d.mts +40 -30
  15. package/dist/dropbox/api.d.mts.map +1 -1
  16. package/dist/dropbox/api.mjs +6 -5
  17. package/dist/dropbox/api.mjs.map +1 -1
  18. package/dist/dropbox/state.d.mts +36 -29
  19. package/dist/dropbox/state.d.mts.map +1 -1
  20. package/dist/dropbox/state.mjs +1 -2
  21. package/dist/dropbox/state.mjs.map +1 -1
  22. package/dist/dropbox.d.mts +26 -24
  23. package/dist/dropbox.d.mts.map +1 -1
  24. package/dist/dropbox.mjs +4 -5
  25. package/dist/dropbox.mjs.map +1 -1
  26. package/dist/email-fixtures.d.mts +4 -7
  27. package/dist/email-fixtures.d.mts.map +1 -1
  28. package/dist/email-fixtures.mjs +1 -2
  29. package/dist/email.d.mts +48 -40
  30. package/dist/email.d.mts.map +1 -1
  31. package/dist/email.mjs +3 -4
  32. package/dist/email.mjs.map +1 -1
  33. package/dist/emulator-compose.d.mts +12 -13
  34. package/dist/emulator-compose.d.mts.map +1 -1
  35. package/dist/emulator-compose.mjs +1 -2
  36. package/dist/emulator-compose.mjs.map +1 -1
  37. package/dist/emulator-http.d.mts +11 -15
  38. package/dist/emulator-http.d.mts.map +1 -1
  39. package/dist/emulator-http.mjs +3 -4
  40. package/dist/emulator-http.mjs.map +1 -1
  41. package/dist/emulator-kernel.d.mts +63 -50
  42. package/dist/emulator-kernel.d.mts.map +1 -1
  43. package/dist/emulator-kernel.mjs +10 -6
  44. package/dist/emulator-kernel.mjs.map +1 -1
  45. package/dist/fixture-route.d.mts +63 -43
  46. package/dist/fixture-route.d.mts.map +1 -1
  47. package/dist/fixture-route.mjs +3 -4
  48. package/dist/fixture-route.mjs.map +1 -1
  49. package/dist/fortnox/api.d.mts +15 -15
  50. package/dist/fortnox/api.d.mts.map +1 -1
  51. package/dist/fortnox/api.mjs +11 -8
  52. package/dist/fortnox/api.mjs.map +1 -1
  53. package/dist/fortnox/read-api.d.mts +1 -5
  54. package/dist/fortnox/read-api.d.mts.map +1 -1
  55. package/dist/fortnox/read-api.mjs +1 -2
  56. package/dist/fortnox/read-api.mjs.map +1 -1
  57. package/dist/fortnox/read-state.d.mts +320 -289
  58. package/dist/fortnox/read-state.d.mts.map +1 -1
  59. package/dist/fortnox/read-state.mjs +2 -3
  60. package/dist/fortnox/read-state.mjs.map +1 -1
  61. package/dist/fortnox/route-kit.d.mts +36 -33
  62. package/dist/fortnox/route-kit.d.mts.map +1 -1
  63. package/dist/fortnox/route-kit.mjs +1 -2
  64. package/dist/fortnox/route-kit.mjs.map +1 -1
  65. package/dist/fortnox/state.d.mts +199 -192
  66. package/dist/fortnox/state.d.mts.map +1 -1
  67. package/dist/fortnox/state.mjs +5 -4
  68. package/dist/fortnox/state.mjs.map +1 -1
  69. package/dist/fortnox.d.mts +55 -39
  70. package/dist/fortnox.d.mts.map +1 -1
  71. package/dist/fortnox.mjs +9 -8
  72. package/dist/fortnox.mjs.map +1 -1
  73. package/dist/gateway-evaluate-recordings.d.mts +5 -9
  74. package/dist/gateway-evaluate-recordings.d.mts.map +1 -1
  75. package/dist/gateway-evaluate-recordings.mjs +1 -2
  76. package/dist/gateway.d.mts +44 -45
  77. package/dist/gateway.d.mts.map +1 -1
  78. package/dist/gateway.mjs +4 -5
  79. package/dist/gateway.mjs.map +1 -1
  80. package/dist/github/api.d.mts +40 -35
  81. package/dist/github/api.d.mts.map +1 -1
  82. package/dist/github/api.mjs +3 -3
  83. package/dist/github/api.mjs.map +1 -1
  84. package/dist/github/state.d.mts +66 -52
  85. package/dist/github/state.d.mts.map +1 -1
  86. package/dist/github/state.mjs +4 -5
  87. package/dist/github/state.mjs.map +1 -1
  88. package/dist/github.d.mts +20 -21
  89. package/dist/github.d.mts.map +1 -1
  90. package/dist/github.mjs +17 -17
  91. package/dist/github.mjs.map +1 -1
  92. package/dist/google/calendar.d.mts +2 -6
  93. package/dist/google/calendar.d.mts.map +1 -1
  94. package/dist/google/calendar.mjs +1 -2
  95. package/dist/google/calendar.mjs.map +1 -1
  96. package/dist/google/drive.d.mts +1 -5
  97. package/dist/google/drive.d.mts.map +1 -1
  98. package/dist/google/drive.mjs +1 -2
  99. package/dist/google/drive.mjs.map +1 -1
  100. package/dist/google/gmail.d.mts +2 -6
  101. package/dist/google/gmail.d.mts.map +1 -1
  102. package/dist/google/gmail.mjs +32 -32
  103. package/dist/google/gmail.mjs.map +1 -1
  104. package/dist/google/shared.d.mts +61 -46
  105. package/dist/google/shared.d.mts.map +1 -1
  106. package/dist/google/shared.mjs +1 -2
  107. package/dist/google/state.d.mts +68 -59
  108. package/dist/google/state.d.mts.map +1 -1
  109. package/dist/google/state.mjs +3 -6
  110. package/dist/google/state.mjs.map +1 -1
  111. package/dist/google.d.mts +20 -21
  112. package/dist/google.d.mts.map +1 -1
  113. package/dist/google.mjs +6 -7
  114. package/dist/google.mjs.map +1 -1
  115. package/dist/linkedin-search/api.d.mts +25 -21
  116. package/dist/linkedin-search/api.d.mts.map +1 -1
  117. package/dist/linkedin-search/api.mjs +1 -2
  118. package/dist/linkedin-search/api.mjs.map +1 -1
  119. package/dist/linkedin-search/state.d.mts +27 -28
  120. package/dist/linkedin-search/state.d.mts.map +1 -1
  121. package/dist/linkedin-search/state.mjs +4 -4
  122. package/dist/linkedin-search/state.mjs.map +1 -1
  123. package/dist/linkedin-search.d.mts +19 -20
  124. package/dist/linkedin-search.d.mts.map +1 -1
  125. package/dist/linkedin-search.mjs +14 -14
  126. package/dist/linkedin-search.mjs.map +1 -1
  127. package/dist/mcp/afloat-recordings.d.mts +1 -5
  128. package/dist/mcp/afloat-recordings.d.mts.map +1 -1
  129. package/dist/mcp/afloat-recordings.mjs +1 -2
  130. package/dist/mcp/api.d.mts +30 -21
  131. package/dist/mcp/api.d.mts.map +1 -1
  132. package/dist/mcp/api.mjs +10 -8
  133. package/dist/mcp/api.mjs.map +1 -1
  134. package/dist/mcp/recordings.d.mts +5 -9
  135. package/dist/mcp/recordings.d.mts.map +1 -1
  136. package/dist/mcp/recordings.mjs +1 -2
  137. package/dist/mcp/state.d.mts +30 -30
  138. package/dist/mcp/state.d.mts.map +1 -1
  139. package/dist/mcp/state.mjs +1 -2
  140. package/dist/mcp/state.mjs.map +1 -1
  141. package/dist/mcp.d.mts +20 -21
  142. package/dist/mcp.d.mts.map +1 -1
  143. package/dist/mcp.mjs +23 -23
  144. package/dist/mcp.mjs.map +1 -1
  145. package/dist/messages.d.mts +43 -35
  146. package/dist/messages.d.mts.map +1 -1
  147. package/dist/messages.mjs +3 -4
  148. package/dist/messages.mjs.map +1 -1
  149. package/dist/microsoft/api.d.mts +12 -13
  150. package/dist/microsoft/api.d.mts.map +1 -1
  151. package/dist/microsoft/api.mjs +2 -3
  152. package/dist/microsoft/api.mjs.map +1 -1
  153. package/dist/microsoft/calendar.d.mts +6 -10
  154. package/dist/microsoft/calendar.d.mts.map +1 -1
  155. package/dist/microsoft/calendar.mjs +5 -5
  156. package/dist/microsoft/calendar.mjs.map +1 -1
  157. package/dist/microsoft/drive.d.mts +6 -10
  158. package/dist/microsoft/drive.d.mts.map +1 -1
  159. package/dist/microsoft/drive.mjs +1 -2
  160. package/dist/microsoft/drive.mjs.map +1 -1
  161. package/dist/microsoft/graph.d.mts +106 -88
  162. package/dist/microsoft/graph.d.mts.map +1 -1
  163. package/dist/microsoft/graph.mjs +1 -2
  164. package/dist/microsoft/graph.mjs.map +1 -1
  165. package/dist/microsoft/mail.d.mts +7 -11
  166. package/dist/microsoft/mail.d.mts.map +1 -1
  167. package/dist/microsoft/mail.mjs +7 -6
  168. package/dist/microsoft/mail.mjs.map +1 -1
  169. package/dist/microsoft/state.d.mts +84 -65
  170. package/dist/microsoft/state.d.mts.map +1 -1
  171. package/dist/microsoft/state.mjs +1 -2
  172. package/dist/microsoft/state.mjs.map +1 -1
  173. package/dist/microsoft.d.mts +65 -44
  174. package/dist/microsoft.d.mts.map +1 -1
  175. package/dist/microsoft.mjs +8 -7
  176. package/dist/microsoft.mjs.map +1 -1
  177. package/dist/node.d.mts +15 -15
  178. package/dist/node.d.mts.map +1 -1
  179. package/dist/node.mjs +1 -2
  180. package/dist/node.mjs.map +1 -1
  181. package/dist/notion/api.d.mts +34 -24
  182. package/dist/notion/api.d.mts.map +1 -1
  183. package/dist/notion/api.mjs +1 -2
  184. package/dist/notion/api.mjs.map +1 -1
  185. package/dist/notion/state.d.mts +62 -48
  186. package/dist/notion/state.d.mts.map +1 -1
  187. package/dist/notion/state.mjs +1 -2
  188. package/dist/notion/state.mjs.map +1 -1
  189. package/dist/notion.d.mts +21 -21
  190. package/dist/notion.d.mts.map +1 -1
  191. package/dist/notion.mjs +4 -5
  192. package/dist/notion.mjs.map +1 -1
  193. package/dist/openai.d.mts +31 -33
  194. package/dist/openai.d.mts.map +1 -1
  195. package/dist/openai.mjs +2 -3
  196. package/dist/openai.mjs.map +1 -1
  197. package/dist/opencode-recordings.d.mts +1 -5
  198. package/dist/opencode-recordings.d.mts.map +1 -1
  199. package/dist/opencode-recordings.mjs +1 -2
  200. package/dist/opencode.d.mts +28 -24
  201. package/dist/opencode.d.mts.map +1 -1
  202. package/dist/opencode.mjs +4 -5
  203. package/dist/opencode.mjs.map +1 -1
  204. package/dist/r2-fixtures.d.mts +4 -7
  205. package/dist/r2-fixtures.d.mts.map +1 -1
  206. package/dist/r2-fixtures.mjs +1 -2
  207. package/dist/r2-guard.d.mts +11 -14
  208. package/dist/r2-guard.d.mts.map +1 -1
  209. package/dist/r2-guard.mjs +3 -4
  210. package/dist/r2-guard.mjs.map +1 -1
  211. package/dist/r2.d.mts +53 -43
  212. package/dist/r2.d.mts.map +1 -1
  213. package/dist/r2.mjs +3 -4
  214. package/dist/r2.mjs.map +1 -1
  215. package/dist/responses.d.mts +56 -42
  216. package/dist/responses.d.mts.map +1 -1
  217. package/dist/responses.mjs +3 -5
  218. package/dist/responses.mjs.map +1 -1
  219. package/dist/route-evidence.d.mts +19 -16
  220. package/dist/route-evidence.d.mts.map +1 -1
  221. package/dist/route-evidence.mjs +1 -2
  222. package/dist/route-evidence.mjs.map +1 -1
  223. package/dist/router.d.mts +17 -18
  224. package/dist/router.d.mts.map +1 -1
  225. package/dist/router.mjs +3 -4
  226. package/dist/router.mjs.map +1 -1
  227. package/dist/stateful-core.d.mts +9 -9
  228. package/dist/stateful-core.d.mts.map +1 -1
  229. package/dist/stateful-core.mjs +1 -2
  230. package/dist/stateful-core.mjs.map +1 -1
  231. package/dist/stateful-emulator.d.mts +122 -104
  232. package/dist/stateful-emulator.d.mts.map +1 -1
  233. package/dist/stateful-emulator.mjs +6 -6
  234. package/dist/stateful-emulator.mjs.map +1 -1
  235. package/dist/stateful-secrets.d.mts +20 -21
  236. package/dist/stateful-secrets.d.mts.map +1 -1
  237. package/dist/stateful-secrets.mjs +5 -6
  238. package/dist/stateful-secrets.mjs.map +1 -1
  239. package/dist/subscription-usage-recordings.d.mts +3 -7
  240. package/dist/subscription-usage-recordings.d.mts.map +1 -1
  241. package/dist/subscription-usage-recordings.mjs +1 -2
  242. package/dist/subscription-usage.d.mts +15 -17
  243. package/dist/subscription-usage.d.mts.map +1 -1
  244. package/dist/subscription-usage.mjs +2 -3
  245. package/dist/telegram/api.d.mts +16 -13
  246. package/dist/telegram/api.d.mts.map +1 -1
  247. package/dist/telegram/api.mjs +1 -2
  248. package/dist/telegram/api.mjs.map +1 -1
  249. package/dist/telegram/state.d.mts +27 -25
  250. package/dist/telegram/state.d.mts.map +1 -1
  251. package/dist/telegram/state.mjs +1 -2
  252. package/dist/telegram/state.mjs.map +1 -1
  253. package/dist/telegram.d.mts +27 -22
  254. package/dist/telegram.d.mts.map +1 -1
  255. package/dist/telegram.mjs +3 -4
  256. package/dist/telegram.mjs.map +1 -1
  257. package/dist/todoist/api.d.mts +30 -22
  258. package/dist/todoist/api.d.mts.map +1 -1
  259. package/dist/todoist/api.mjs +5 -6
  260. package/dist/todoist/api.mjs.map +1 -1
  261. package/dist/todoist/state.d.mts +47 -40
  262. package/dist/todoist/state.d.mts.map +1 -1
  263. package/dist/todoist/state.mjs +1 -2
  264. package/dist/todoist/state.mjs.map +1 -1
  265. package/dist/todoist.d.mts +29 -23
  266. package/dist/todoist.d.mts.map +1 -1
  267. package/dist/todoist.mjs +4 -5
  268. package/dist/todoist.mjs.map +1 -1
  269. package/dist/xai.d.mts +45 -47
  270. package/dist/xai.d.mts.map +1 -1
  271. package/dist/xai.mjs +4 -5
  272. package/dist/xai.mjs.map +1 -1
  273. package/package.json +7 -7
  274. package/src/fortnox/api.ts +1 -1
  275. package/src/fortnox/state.ts +2 -0
  276. package/src/router.ts +12 -2
package/README.md CHANGED
@@ -30,9 +30,11 @@ Canary APIs are unstable. Keep all `@yolk-sdk/*` packages on the same version.
30
30
  ## Install
31
31
 
32
32
  ```bash
33
- pnpm add -D @yolk-sdk/emulators@canary effect@4.0.5
33
+ pnpm add -D @yolk-sdk/emulators@canary effect@4.1.2
34
34
  ```
35
35
 
36
+ Use the SDK's matching Effect version (`4.1.2`) in host code.
37
+
36
38
  ## Subpaths
37
39
 
38
40
  There is no root export. Import an explicit subpath:
@@ -1,46 +1,44 @@
1
- import { EmulatorEvidence, EmulatorRouteEvidence, emulatorEvidenceHeader } from "./route-evidence.mjs";
2
1
  import { EmulatorCoverage, EmulatorFaultMatch, EmulatorFaultState, EmulatorRouteCoverage, EmulatorScriptedError } from "./emulator-kernel.mjs";
3
2
  import { MessagesEmulator, MessagesErrorEventFault, MessagesFault, MessagesFaultKind, MessagesLedgerEntry, MessagesScriptedMessage, MessagesScriptedToolUse, MessagesScriptedTurn, MessagesScriptedUsage, MessagesWireError } from "./messages.mjs";
3
+ import { EmulatorEvidence, EmulatorRouteEvidence, emulatorEvidenceHeader } from "./route-evidence.mjs";
4
4
  import { SubscriptionUsageEmulator, SubscriptionUsageFault, SubscriptionUsageLedgerEntry, SubscriptionUsageScriptedTurn } from "./subscription-usage.mjs";
5
5
  import * as Schema from "effect/Schema";
6
-
7
- //#region src/anthropic.d.ts
8
- declare const anthropicMessagesPath = "/v1/messages";
6
+ export declare const anthropicMessagesPath = "/v1/messages";
9
7
  /** The Claude subscription-usage path (`anthropicClaudeSubscriptionUsageUrl` in the SDK). */
10
- declare const anthropicSubscriptionUsagePath = "/api/oauth/usage";
8
+ export declare const anthropicSubscriptionUsagePath = "/api/oauth/usage";
11
9
  /** The `anthropic-beta` value the Claude usage fetcher sends for OAuth credentials. */
12
- declare const anthropicOAuthBeta = "oauth-2025-04-20";
10
+ export declare const anthropicOAuthBeta = "oauth-2025-04-20";
13
11
  /**
14
12
  * Route evidence manifest of the Claude subscription-usage route (served by the same fetch
15
13
  * handler as the Messages route, with its own ledger and coverage). Synthetic, unverified.
16
14
  */
17
- declare const anthropicSubscriptionUsageEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence>;
15
+ export declare const anthropicSubscriptionUsageEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence>;
18
16
  /**
19
17
  * The recorded Claude usage body (the synthetic `anthropic.claude.usage.snapshot` fixture, copied
20
18
  * as data): `five_hour` and `seven_day` as `{ utilization, resets_at }`.
21
19
  */
22
- declare const anthropicSubscriptionUsageDefault: Schema.Json;
20
+ export declare const anthropicSubscriptionUsageDefault: Schema.Json;
23
21
  /** Synthetic-safe default model ids, including the Anthropic Messages conformance defaults. */
24
- declare const anthropicEmulatorDefaultModels: ReadonlyArray<string>;
22
+ export declare const anthropicEmulatorDefaultModels: ReadonlyArray<string>;
25
23
  /**
26
24
  * Route evidence manifest: every emulated Anthropic route and the conformance cases whose
27
25
  * (currently synthetic, unverified) wire shapes it follows.
28
26
  */
29
- declare const anthropicEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence>;
27
+ export declare const anthropicEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence>;
30
28
  /** Optional fault filter; an omitted field matches every request. `path` ending in `*` is a prefix. */
31
- declare const AnthropicFaultMatch: Schema.Struct<{
29
+ export declare const AnthropicFaultMatch: Schema.Struct<{
32
30
  readonly path: Schema.optionalKey<Schema.String>;
33
31
  readonly model: Schema.optionalKey<Schema.String>;
34
32
  }>;
35
- type AnthropicFaultMatch = typeof EmulatorFaultMatch.Type;
33
+ export type AnthropicFaultMatch = typeof EmulatorFaultMatch.Type;
36
34
  /** An Anthropic wire error (`{ type, message }`), as sent inside the error envelope. */
37
- declare const AnthropicWireError: Schema.Struct<{
35
+ export declare const AnthropicWireError: Schema.Struct<{
38
36
  readonly type: Schema.NonEmptyString;
39
37
  readonly message: Schema.String;
40
38
  }>;
41
- type AnthropicWireError = MessagesWireError;
39
+ export type AnthropicWireError = MessagesWireError;
42
40
  /** A mid-stream `error` event fault (default `overloaded_error`), streamed responses only. */
43
- declare const AnthropicErrorEventFault: Schema.Struct<{
41
+ export declare const AnthropicErrorEventFault: Schema.Struct<{
44
42
  readonly match: Schema.optionalKey<Schema.Struct<{
45
43
  readonly path: Schema.optionalKey<Schema.String>;
46
44
  readonly model: Schema.optionalKey<Schema.String>;
@@ -53,7 +51,7 @@ declare const AnthropicErrorEventFault: Schema.Struct<{
53
51
  readonly message: Schema.String;
54
52
  }>>;
55
53
  }>;
56
- type AnthropicErrorEventFault = typeof MessagesErrorEventFault.Type;
54
+ export type AnthropicErrorEventFault = typeof MessagesErrorEventFault.Type;
57
55
  /**
58
56
  * Wire faults:
59
57
  *
@@ -67,7 +65,7 @@ type AnthropicErrorEventFault = typeof MessagesErrorEventFault.Type;
67
65
  * Statuses that cannot carry a body and redirects are rejected, as are invalid headers and
68
66
  * `location`. A fault that cannot take effect answers 500 and is not consumed.
69
67
  */
70
- declare const AnthropicFault: Schema.Union<readonly [Schema.Struct<{
68
+ export declare const AnthropicFault: Schema.Union<readonly [Schema.Struct<{
71
69
  readonly match: Schema.optionalKey<Schema.Struct<{
72
70
  readonly path: Schema.optionalKey<Schema.String>;
73
71
  readonly model: Schema.optionalKey<Schema.String>;
@@ -106,27 +104,27 @@ declare const AnthropicFault: Schema.Union<readonly [Schema.Struct<{
106
104
  readonly message: Schema.String;
107
105
  }>>;
108
106
  }>]>;
109
- type AnthropicFault = MessagesFault;
110
- type AnthropicFaultKind = MessagesFaultKind;
107
+ export type AnthropicFault = MessagesFault;
108
+ export type AnthropicFaultKind = MessagesFaultKind;
111
109
  /** Usage for a scripted turn (sent in `message_start` and `message_delta`). */
112
- declare const AnthropicScriptedUsage: Schema.Struct<{
110
+ export declare const AnthropicScriptedUsage: Schema.Struct<{
113
111
  readonly inputTokens: Schema.Int;
114
112
  readonly outputTokens: Schema.Int;
115
113
  }>;
116
- type AnthropicScriptedUsage = MessagesScriptedUsage;
114
+ export type AnthropicScriptedUsage = MessagesScriptedUsage;
117
115
  /** One scripted `tool_use` block; its JSON input streams as these fragments. */
118
- declare const AnthropicScriptedToolUse: Schema.Struct<{
116
+ export declare const AnthropicScriptedToolUse: Schema.Struct<{
119
117
  readonly name: Schema.NonEmptyString;
120
118
  readonly inputFragments: Schema.$Array<Schema.String>;
121
119
  readonly id: Schema.optionalKey<Schema.NonEmptyString>;
122
120
  }>;
123
- type AnthropicScriptedToolUse = MessagesScriptedToolUse;
121
+ export type AnthropicScriptedToolUse = MessagesScriptedToolUse;
124
122
  /**
125
123
  * A scripted message. Every field is exact except: a block is sent only when its field is
126
124
  * present; `usage` omitted is synthesized and `null` drops it; `stopReason` omitted is
127
125
  * `tool_use` with tool uses, else `end_turn`; `order` defaults to `thinking-first`.
128
126
  */
129
- declare const AnthropicScriptedMessage: Schema.Struct<{
127
+ export declare const AnthropicScriptedMessage: Schema.Struct<{
130
128
  readonly thinking: Schema.optionalKey<Schema.$Array<Schema.String>>;
131
129
  readonly text: Schema.optionalKey<Schema.$Array<Schema.String>>;
132
130
  readonly toolUses: Schema.optionalKey<Schema.$Array<Schema.Struct<{
@@ -141,18 +139,18 @@ declare const AnthropicScriptedMessage: Schema.Struct<{
141
139
  }>>>;
142
140
  readonly stopReason: Schema.optionalKey<Schema.NonEmptyString>;
143
141
  }>;
144
- type AnthropicScriptedMessage = MessagesScriptedMessage;
142
+ export type AnthropicScriptedMessage = MessagesScriptedMessage;
145
143
  /** A scripted error response: status, body (a string is sent as is), and optional headers. */
146
- declare const AnthropicScriptedError: Schema.Struct<{
144
+ export declare const AnthropicScriptedError: Schema.Struct<{
147
145
  readonly error: Schema.Struct<{
148
146
  readonly status: Schema.Int;
149
147
  readonly body: Schema.Codec<Schema.Json, Schema.Json, never, never>;
150
148
  readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
151
149
  }>;
152
150
  }>;
153
- type AnthropicScriptedError = typeof EmulatorScriptedError.Type;
151
+ export type AnthropicScriptedError = typeof EmulatorScriptedError.Type;
154
152
  /** A turn queued for the next Messages request. */
155
- declare const AnthropicScriptedTurn: Schema.Union<readonly [Schema.Struct<{
153
+ export declare const AnthropicScriptedTurn: Schema.Union<readonly [Schema.Struct<{
156
154
  readonly error: Schema.Struct<{
157
155
  readonly status: Schema.Int;
158
156
  readonly body: Schema.Codec<Schema.Json, Schema.Json, never, never>;
@@ -173,24 +171,23 @@ declare const AnthropicScriptedTurn: Schema.Union<readonly [Schema.Struct<{
173
171
  }>>>;
174
172
  readonly stopReason: Schema.optionalKey<Schema.NonEmptyString>;
175
173
  }>]>;
176
- type AnthropicScriptedTurn = MessagesScriptedTurn;
177
- declare const AnthropicEmulatorInputInvalid_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
174
+ export type AnthropicScriptedTurn = MessagesScriptedTurn;
175
+ declare const AnthropicEmulatorInputInvalid_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
178
176
  readonly _tag: "AnthropicEmulatorInputInvalid";
179
177
  } & Readonly<A>;
180
178
  /** Thrown by the JS API (`faults.add`, `script.enqueue`) for invalid input; a programmer error. */
181
- declare class AnthropicEmulatorInputInvalid extends AnthropicEmulatorInputInvalid_base<{
179
+ export declare class AnthropicEmulatorInputInvalid extends AnthropicEmulatorInputInvalid_base<{
182
180
  readonly input: 'fault' | 'turn';
183
181
  readonly reason: string;
184
182
  }> {
185
183
  get message(): string;
186
184
  }
187
- type AnthropicLedgerEntry = MessagesLedgerEntry;
188
- type AnthropicFaultState = EmulatorFaultState<AnthropicFault>;
189
- type AnthropicRouteCoverage = EmulatorRouteCoverage;
190
- type AnthropicCoverage = EmulatorCoverage;
185
+ export type AnthropicLedgerEntry = MessagesLedgerEntry;
186
+ export type AnthropicFaultState = EmulatorFaultState<AnthropicFault>;
187
+ export type AnthropicRouteCoverage = EmulatorRouteCoverage;
188
+ export type AnthropicCoverage = EmulatorCoverage;
191
189
  /** A usage-route fault (`status`, `error-after-chunks`, `truncate-after-chunks`). */
192
- declare const AnthropicUsageFault: Schema.Union<readonly [Schema.Struct<{
193
- readonly status: Schema.Int;
190
+ export declare const AnthropicUsageFault: Schema.Union<readonly [Schema.Struct<{
194
191
  readonly match: Schema.optionalKey<Schema.Struct<{
195
192
  readonly path: Schema.optionalKey<Schema.String>;
196
193
  readonly model: Schema.optionalKey<Schema.String>;
@@ -199,6 +196,7 @@ declare const AnthropicUsageFault: Schema.Union<readonly [Schema.Struct<{
199
196
  readonly kind: Schema.Literal<"status">;
200
197
  readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
201
198
  readonly body: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
199
+ readonly status: Schema.Int;
202
200
  }>, Schema.Struct<{
203
201
  readonly match: Schema.optionalKey<Schema.Struct<{
204
202
  readonly path: Schema.optionalKey<Schema.String>;
@@ -216,13 +214,14 @@ declare const AnthropicUsageFault: Schema.Union<readonly [Schema.Struct<{
216
214
  readonly kind: Schema.Literal<"truncate-after-chunks">;
217
215
  readonly chunks: Schema.Int;
218
216
  }>]>;
219
- type AnthropicUsageFault = SubscriptionUsageFault;
217
+ export type AnthropicUsageFault = SubscriptionUsageFault;
220
218
  /** A usage turn: `{ usage }` (a body with the recorded JSON shape) or `{ error }`. */
221
- type AnthropicUsageScriptedTurn = SubscriptionUsageScriptedTurn;
222
- type AnthropicUsageLedgerEntry = SubscriptionUsageLedgerEntry;
223
- type AnthropicUsageEmulator = SubscriptionUsageEmulator;
224
- type AnthropicEmulatorOptions = {
225
- /** Model ids that exist. Defaults to `anthropicEmulatorDefaultModels`. */readonly knownModels?: ReadonlyArray<string>;
219
+ export type AnthropicUsageScriptedTurn = SubscriptionUsageScriptedTurn;
220
+ export type AnthropicUsageLedgerEntry = SubscriptionUsageLedgerEntry;
221
+ export type AnthropicUsageEmulator = SubscriptionUsageEmulator;
222
+ export type AnthropicEmulatorOptions = {
223
+ /** Model ids that exist. Defaults to `anthropicEmulatorDefaultModels`. */
224
+ readonly knownModels?: ReadonlyArray<string>;
226
225
  /**
227
226
  * Replacement usage-route body; must have the recorded JSON shape (same keys and value kinds).
228
227
  * Defaults to the recorded body (`anthropicSubscriptionUsageDefault`).
@@ -230,7 +229,7 @@ type AnthropicEmulatorOptions = {
230
229
  readonly subscriptionUsage?: Schema.Json;
231
230
  };
232
231
  /** The Messages emulator, plus `usage`: the subscription-usage route's own emulator API. */
233
- type AnthropicEmulator = MessagesEmulator & {
232
+ export type AnthropicEmulator = MessagesEmulator & {
234
233
  readonly usage: AnthropicUsageEmulator;
235
234
  };
236
235
  /**
@@ -263,7 +262,6 @@ type AnthropicEmulator = MessagesEmulator & {
263
262
  * `emulator.usage` (control plane `/_emulate/usage/*`); `emulator.faults` and the other top-level
264
263
  * APIs stay the Messages route's. `reset()` and `POST /_emulate/reset` reset both.
265
264
  */
266
- declare const makeAnthropicEmulator: (options?: AnthropicEmulatorOptions) => AnthropicEmulator;
267
- //#endregion
268
- export { AnthropicCoverage, AnthropicEmulator, AnthropicEmulatorInputInvalid, AnthropicEmulatorOptions, AnthropicErrorEventFault, AnthropicFault, AnthropicFaultKind, AnthropicFaultMatch, AnthropicFaultState, AnthropicLedgerEntry, AnthropicRouteCoverage, AnthropicScriptedError, AnthropicScriptedMessage, AnthropicScriptedToolUse, AnthropicScriptedTurn, AnthropicScriptedUsage, AnthropicUsageEmulator, AnthropicUsageFault, AnthropicUsageLedgerEntry, AnthropicUsageScriptedTurn, AnthropicWireError, type EmulatorEvidence, type EmulatorRouteEvidence, anthropicEmulatorDefaultModels, anthropicEmulatorRoutes, anthropicMessagesPath, anthropicOAuthBeta, anthropicSubscriptionUsageDefault, anthropicSubscriptionUsageEmulatorRoutes, anthropicSubscriptionUsagePath, emulatorEvidenceHeader, makeAnthropicEmulator };
265
+ export declare const makeAnthropicEmulator: (options?: AnthropicEmulatorOptions) => AnthropicEmulator;
266
+ export { type EmulatorEvidence, type EmulatorRouteEvidence, emulatorEvidenceHeader };
269
267
  //# sourceMappingURL=anthropic.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.d.mts","names":[],"sources":["../src/anthropic.ts"],"mappings":";;;;;;;cA+Da,qBAAA;;cAGA,8BAAA;AAHqB;AAAA,cAMrB,kBAAA;;;;AAH8B;cAS9B,wCAAA,EAA0C,aAAa,CAAC,qBAAA;;;;AANtC;cAsBlB,iCAAA,EAAmC,MAAA,CAAO,IAEtD;;cAGY,8BAAA,EAAgC,aAAa;;AArBgC;AAgB1F;;cAca,uBAAA,EAAyB,aAAa,CAAC,qBAAA;;cAmBvC,mBAAA,EAAmB,MAAA,CAAA,MAAA;EAAA;;;KAEpB,mBAAA,UAA6B,kBAAA,CAAmB,IAAI;AA9BN;AAAA,cAiC7C,kBAAA,EAAkB,MAAA,CAAA,MAAA;EAAA;;;KAEnB,kBAAA,GAAqB,iBAAiB;AAPlD;AAAA,cAUa,wBAAA,EAAwB,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;KAEzB,wBAAA,UAAkC,uBAAA,CAAwB,IAAI;;;;;;;;;;AAV1E;;;;cAyBa,cAAA,EAAc,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAEf,cAAA,GAAiB,aAAa;AAAA,KAE9B,kBAAA,GAAqB,iBAAiB;;cAGrC,sBAAA,EAAsB,MAAA,CAAA,MAAA;EAAA;;;KAEvB,sBAAA,GAAyB,qBAAqB;;cAG7C,wBAAA,EAAwB,MAAA,CAAA,MAAA;EAAA;;;;KAEzB,wBAAA,GAA2B,uBAAuB;;;;;;cAOjD,wBAAA,EAAwB,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;KAEzB,wBAAA,GAA2B,uBAAuB;;cAGjD,sBAAA,EAAsB,MAAA,CAAA,MAAA;EAAA;;;;;;KAEvB,sBAAA,UAAgC,qBAAA,CAAsB,IAAI;;cAGzD,qBAAA,EAAqB,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;KAEtB,qBAAA,GAAwB,oBAAoB;AAAA,cAAA,kCAAA;;;;cAG3C,6BAAA,SAAsC,kCAAA;EAAA,SAGxC,KAAA;EAAA,SACA,MAAA;AAAA;EAAA,IAEI,OAAA,CAAA;AAAA;AAAA,KAKH,oBAAA,GAAuB,mBAAmB;AAAA,KAE1C,mBAAA,GAAsB,kBAAkB,CAAC,cAAA;AAAA,KAEzC,sBAAA,GAAyB,qBAAqB;AAAA,KAE9C,iBAAA,GAAoB,gBAAgB;;cAGnC,mBAAA,EAAmB,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;KAEpB,mBAAA,GAAsB,sBAAsB;;KAG5C,0BAAA,GAA6B,6BAA6B;AAAA,KAE1D,yBAAA,GAA4B,4BAA4B;AAAA,KAExD,sBAAA,GAAyB,yBAAyB;AAAA,KAElD,wBAAA;EAnEe,mFAqEhB,WAAA,GAAc,aAAA;;;;;WAKd,iBAAA,GAAoB,MAAA,CAAO,IAAI;AAAA;;KAI9B,iBAAA,GAAoB,gBAAA;EAAA,SAA8B,KAAA,EAAO,sBAAsB;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgC9E,qBAAA,GAAyB,OAAA,GAAS,wBAAA,KAAgC,iBA2B5E"}
1
+ {"version":3,"file":"anthropic.d.mts","names":[],"sources":["../src/anthropic.ts"],"mappings":";;;;;qBA+Da;;qBAGA;;qBAGA;;;;;qBAMA,0CAA0C,cAAc;;;;;qBAgBxD,mCAAmC,OAAO;;qBAK1C,gCAAgC;;;;;qBAShC,yBAAyB,cAAc;;qBAmBvC,qBAAmB,OAAA;;;;YAEpB,6BAA6B,mBAAmB;;qBAG/C,oBAAkB,OAAA;;;;YAEnB,qBAAqB;;qBAGpB,0BAAwB,OAAA;;;;;;;;;;;;;YAEzB,kCAAkC,wBAAwB;;;;;;;;;;;;;;qBAezD,gBAAc,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAEf,iBAAiB;YAEjB,qBAAqB;;qBAGpB,wBAAsB,OAAA;;;;YAEvB,yBAAyB;;qBAGxB,0BAAwB,OAAA;;;;;YAEzB,2BAA2B;;;;;;qBAO1B,0BAAwB,OAAA;;;;;;;;;;;;;;;YAEzB,2BAA2B;;qBAG1B,wBAAsB,OAAA;;;;;;;YAEvB,gCAAgC,sBAAsB;;qBAGrD,uBAAqB,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;YAEtB,wBAAwB;;;;;qBAGvB,sCAAsC;WAGxC;WACA;;MAEI;;YAKH,uBAAuB;YAEvB,sBAAsB,mBAAmB;YAEzC,yBAAyB;YAEzB,oBAAoB;;qBAGnB,qBAAmB,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;YAEpB,sBAAsB;;YAGtB,6BAA6B;YAE7B,4BAA4B;YAE5B,yBAAyB;YAEzB;;WAED,cAAc;;;;;WAKd,oBAAoB,OAAO;;;YAI1B,oBAAoB;WAA8B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgCxD,wBAAqB,UAAa,6BAAgC"}
@@ -1,11 +1,11 @@
1
- import { emulatorEvidenceHeader } from "./route-evidence.mjs";
2
- import { EmulatorFaultMatch, EmulatorScriptedError } from "./emulator-kernel.mjs";
3
1
  import { withSubscriptionUsage } from "./emulator-compose.mjs";
2
+ import { EmulatorFaultMatch, EmulatorScriptedError } from "./emulator-kernel.mjs";
4
3
  import { MessagesErrorEventFault, MessagesFault, MessagesScriptedMessage, MessagesScriptedToolUse, MessagesScriptedTurn, MessagesScriptedUsage, MessagesWireError, makeMessagesEmulator } from "./messages.mjs";
5
4
  import { SubscriptionUsageFault, makeSubscriptionUsageEmulator, recordedUsageBody } from "./subscription-usage.mjs";
6
5
  import { anthropicClaudeUsageRecording } from "./subscription-usage-recordings.mjs";
6
+ import { emulatorEvidenceHeader } from "./route-evidence.mjs";
7
7
  import { Data } from "effect";
8
- //#region src/anthropic.ts
8
+ // src/anthropic.ts
9
9
  /**
10
10
  * Anthropic Messages emulator: a plain fetch handler for `POST /v1/messages` (origin
11
11
  * `https://api.anthropic.com`), with scripted turns, wire faults, a request ledger, and an
@@ -171,7 +171,6 @@ const makeAnthropicEmulator = (options = {}) => withSubscriptionUsage(makeMessag
171
171
  reason
172
172
  })
173
173
  }), anthropicSubscriptionUsagePath);
174
- //#endregion
175
174
  export { AnthropicEmulatorInputInvalid, AnthropicErrorEventFault, AnthropicFault, AnthropicFaultMatch, AnthropicScriptedError, AnthropicScriptedMessage, AnthropicScriptedToolUse, AnthropicScriptedTurn, AnthropicScriptedUsage, AnthropicUsageFault, AnthropicWireError, anthropicEmulatorDefaultModels, anthropicEmulatorRoutes, anthropicMessagesPath, anthropicOAuthBeta, anthropicSubscriptionUsageDefault, anthropicSubscriptionUsageEmulatorRoutes, anthropicSubscriptionUsagePath, emulatorEvidenceHeader, makeAnthropicEmulator };
176
175
 
177
176
  //# sourceMappingURL=anthropic.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.mjs","names":[],"sources":["../src/anthropic.ts"],"sourcesContent":["/**\n * Anthropic Messages emulator: a plain fetch handler for `POST /v1/messages` (origin\n * `https://api.anthropic.com`), with scripted turns, wire faults, a request ledger, and an\n * `/_emulate/*` control plane.\n *\n * It never imports SDK code: its wire shapes follow the synthetic Anthropic Messages conformance\n * fixtures (`message_start` / `content_block_*` / `message_delta` / `message_stop` SSE with\n * `text_delta`, `thinking_delta`, and `input_json_delta`, the `message` JSON body, and the\n * `{ type: 'error', error: { type, message } }` envelope) and are linked to those conformance\n * case ids in `anthropicEmulatorRoutes`. The Messages machinery lives in the internal\n * `messages.ts` core; faults, the ledger, and the control plane are shared with the Chat\n * Completions emulators.\n *\n * Requests authenticate with a non-empty `x-api-key` (native API keys) or `Authorization:\n * Bearer` (Claude OAuth) credential. Neither value is ever checked or stored.\n *\n * The same fetch handler also answers the Claude subscription-usage route\n * (`GET /api/oauth/usage`, `emulator.usage`) with its own manifest\n * (`anthropicSubscriptionUsageEmulatorRoutes`), ledger, faults, and turns; see\n * `makeAnthropicEmulator`.\n *\n * Runtime-portable Web APIs only (`Request`, `Response`, `ReadableStream`, `TextEncoder`, `URL`);\n * no Effect runtime is required to use it.\n *\n * @experimental\n */\nimport { Data } from 'effect'\nimport type * as Schema from 'effect/Schema'\nimport { withSubscriptionUsage } from './emulator-compose.ts'\nimport type {\n EmulatorCoverage,\n EmulatorFaultState,\n EmulatorRouteCoverage\n} from './emulator-kernel.ts'\nimport { EmulatorFaultMatch, EmulatorScriptedError } from './emulator-kernel.ts'\nimport {\n MessagesErrorEventFault,\n MessagesFault,\n MessagesScriptedMessage,\n MessagesScriptedToolUse,\n MessagesScriptedTurn,\n MessagesScriptedUsage,\n MessagesWireError,\n makeMessagesEmulator,\n type MessagesEmulator,\n type MessagesFaultKind,\n type MessagesLedgerEntry\n} from './messages.ts'\nimport type { EmulatorRouteEvidence } from './route-evidence.ts'\nimport {\n makeSubscriptionUsageEmulator,\n recordedUsageBody,\n SubscriptionUsageFault,\n type SubscriptionUsageEmulator,\n type SubscriptionUsageLedgerEntry,\n type SubscriptionUsageScriptedTurn\n} from './subscription-usage.ts'\nimport { anthropicClaudeUsageRecording } from './subscription-usage-recordings.ts'\n\nexport type { EmulatorEvidence, EmulatorRouteEvidence } from './route-evidence.ts'\n\nexport { emulatorEvidenceHeader } from './route-evidence.ts'\n\nexport const anthropicMessagesPath = '/v1/messages'\n\n/** The Claude subscription-usage path (`anthropicClaudeSubscriptionUsageUrl` in the SDK). */\nexport const anthropicSubscriptionUsagePath = '/api/oauth/usage'\n\n/** The `anthropic-beta` value the Claude usage fetcher sends for OAuth credentials. */\nexport const anthropicOAuthBeta = 'oauth-2025-04-20'\n\n/**\n * Route evidence manifest of the Claude subscription-usage route (served by the same fetch\n * handler as the Messages route, with its own ledger and coverage). Synthetic, unverified.\n */\nexport const anthropicSubscriptionUsageEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence> = [\n {\n method: 'GET',\n path: anthropicSubscriptionUsagePath,\n kind: 'provider',\n write: false,\n caseIds: ['anthropic.claude.usage.snapshot'],\n evidence: 'unverified',\n observedAt: undefined\n }\n]\n\n/**\n * The recorded Claude usage body (the synthetic `anthropic.claude.usage.snapshot` fixture, copied\n * as data): `five_hour` and `seven_day` as `{ utilization, resets_at }`.\n */\nexport const anthropicSubscriptionUsageDefault: Schema.Json = recordedUsageBody(\n anthropicClaudeUsageRecording\n)\n\n/** Synthetic-safe default model ids, including the Anthropic Messages conformance defaults. */\nexport const anthropicEmulatorDefaultModels: ReadonlyArray<string> = [\n 'claude-haiku-4-5',\n 'claude-sonnet-4-5'\n]\n\n/**\n * Route evidence manifest: every emulated Anthropic route and the conformance cases whose\n * (currently synthetic, unverified) wire shapes it follows.\n */\nexport const anthropicEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence> = [\n {\n method: 'POST',\n path: anthropicMessagesPath,\n kind: 'provider',\n write: false,\n caseIds: [\n 'anthropic.messages.stream.plain-text',\n 'anthropic.messages.stream.tool-use-input-deltas',\n 'anthropic.messages.stream.thinking-before-text',\n 'anthropic.messages.stream.error-envelope',\n 'anthropic.messages.stream.max-tokens'\n ],\n evidence: 'unverified',\n observedAt: undefined\n }\n]\n\n/** Optional fault filter; an omitted field matches every request. `path` ending in `*` is a prefix. */\nexport const AnthropicFaultMatch = EmulatorFaultMatch\n\nexport type AnthropicFaultMatch = typeof EmulatorFaultMatch.Type\n\n/** An Anthropic wire error (`{ type, message }`), as sent inside the error envelope. */\nexport const AnthropicWireError = MessagesWireError\n\nexport type AnthropicWireError = MessagesWireError\n\n/** A mid-stream `error` event fault (default `overloaded_error`), streamed responses only. */\nexport const AnthropicErrorEventFault = MessagesErrorEventFault\n\nexport type AnthropicErrorEventFault = typeof MessagesErrorEventFault.Type\n\n/**\n * Wire faults:\n *\n * - `status`: answer with this status, headers, and body (for example 429 with `retry-after`,\n * or 529). The body defaults to the Anthropic error envelope for the status\n * (`rate_limit_error` for 429, `overloaded_error` for 529, `api_error` for other 5xx).\n * - `error-after-chunks`: send N body chunks, then error the body stream (a dropped connection).\n * - `truncate-after-chunks`: send N body chunks, then close cleanly (no `message_stop`).\n * - `error-event-after-chunks`: send N SSE events, then one `event: error` event and close.\n *\n * Statuses that cannot carry a body and redirects are rejected, as are invalid headers and\n * `location`. A fault that cannot take effect answers 500 and is not consumed.\n */\nexport const AnthropicFault = MessagesFault\n\nexport type AnthropicFault = MessagesFault\n\nexport type AnthropicFaultKind = MessagesFaultKind\n\n/** Usage for a scripted turn (sent in `message_start` and `message_delta`). */\nexport const AnthropicScriptedUsage = MessagesScriptedUsage\n\nexport type AnthropicScriptedUsage = MessagesScriptedUsage\n\n/** One scripted `tool_use` block; its JSON input streams as these fragments. */\nexport const AnthropicScriptedToolUse = MessagesScriptedToolUse\n\nexport type AnthropicScriptedToolUse = MessagesScriptedToolUse\n\n/**\n * A scripted message. Every field is exact except: a block is sent only when its field is\n * present; `usage` omitted is synthesized and `null` drops it; `stopReason` omitted is\n * `tool_use` with tool uses, else `end_turn`; `order` defaults to `thinking-first`.\n */\nexport const AnthropicScriptedMessage = MessagesScriptedMessage\n\nexport type AnthropicScriptedMessage = MessagesScriptedMessage\n\n/** A scripted error response: status, body (a string is sent as is), and optional headers. */\nexport const AnthropicScriptedError = EmulatorScriptedError\n\nexport type AnthropicScriptedError = typeof EmulatorScriptedError.Type\n\n/** A turn queued for the next Messages request. */\nexport const AnthropicScriptedTurn = MessagesScriptedTurn\n\nexport type AnthropicScriptedTurn = MessagesScriptedTurn\n\n/** Thrown by the JS API (`faults.add`, `script.enqueue`) for invalid input; a programmer error. */\nexport class AnthropicEmulatorInputInvalid extends Data.TaggedError(\n 'AnthropicEmulatorInputInvalid'\n)<{\n readonly input: 'fault' | 'turn'\n readonly reason: string\n}> {\n override get message(): string {\n return `Invalid Anthropic emulator ${this.input}: ${this.reason}`\n }\n}\n\nexport type AnthropicLedgerEntry = MessagesLedgerEntry\n\nexport type AnthropicFaultState = EmulatorFaultState<AnthropicFault>\n\nexport type AnthropicRouteCoverage = EmulatorRouteCoverage\n\nexport type AnthropicCoverage = EmulatorCoverage\n\n/** A usage-route fault (`status`, `error-after-chunks`, `truncate-after-chunks`). */\nexport const AnthropicUsageFault = SubscriptionUsageFault\n\nexport type AnthropicUsageFault = SubscriptionUsageFault\n\n/** A usage turn: `{ usage }` (a body with the recorded JSON shape) or `{ error }`. */\nexport type AnthropicUsageScriptedTurn = SubscriptionUsageScriptedTurn\n\nexport type AnthropicUsageLedgerEntry = SubscriptionUsageLedgerEntry\n\nexport type AnthropicUsageEmulator = SubscriptionUsageEmulator\n\nexport type AnthropicEmulatorOptions = {\n /** Model ids that exist. Defaults to `anthropicEmulatorDefaultModels`. */\n readonly knownModels?: ReadonlyArray<string>\n /**\n * Replacement usage-route body; must have the recorded JSON shape (same keys and value kinds).\n * Defaults to the recorded body (`anthropicSubscriptionUsageDefault`).\n */\n readonly subscriptionUsage?: Schema.Json\n}\n\n/** The Messages emulator, plus `usage`: the subscription-usage route's own emulator API. */\nexport type AnthropicEmulator = MessagesEmulator & { readonly usage: AnthropicUsageEmulator }\n\n/**\n * Create an Anthropic Messages emulator. Each call has independent ledger, fault, and script\n * state.\n *\n * Without a script, `POST /v1/messages` answers a known model with synthetic content: `stream:\n * true` streams `message_start`, the content blocks (`content_block_start`, deltas,\n * `content_block_stop`, with a `ping` after the first block starts), `message_delta` (stop reason\n * and usage), and `message_stop`; `stream: false` returns one `message` JSON body. A request with\n * `thinking` enabled (`enabled` or `adaptive`) gets a thinking block before the answer. A request\n * with `tools` gets one `tool_use` block whose input is synthesized from the tool's `input_schema`\n * and streamed as `input_json_delta` fragments, stopping with `tool_use`; `tool_choice: { type:\n * 'tool', name }` picks that tool (otherwise the first) and `tool_choice: { type: 'none' }`\n * answers with text. An answer that would exceed `max_tokens` is cut and stops with `max_tokens`.\n * Unknown models get 404 `not_found_error`; a request with neither a non-empty `x-api-key` nor a\n * bearer credential gets 401 `authentication_error`; a missing or unsupported `anthropic-version`\n * (only `2023-06-01` is accepted), a missing or non-positive `max_tokens`, or `thinking` with a\n * forced `tool_choice` (`tool` or `any`) gets 400 `invalid_request_error`; unknown routes get a\n * 404 envelope. The OAuth `anthropic-beta` header and `budget_tokens` limits are not enforced. The\n * ledger records which header carried the credential, `anthropic-version`, and `anthropic-beta`,\n * never a credential value.\n *\n * `GET /api/oauth/usage` is fixture-only: a request with a non-empty bearer credential (never\n * checked or stored), an `anthropic-beta` header listing `oauth-2025-04-20`, `accept:\n * application/json`, and no query gets the recorded body (`anthropicSubscriptionUsageDefault`,\n * or a same-shaped `options.subscriptionUsage` / scripted `{ usage }`); anything else answers 400\n * not-emulated. Throws `AnthropicEmulatorInputInvalid` for a differently shaped\n * `subscriptionUsage`. Its ledger, faults, turns, and coverage are\n * `emulator.usage` (control plane `/_emulate/usage/*`); `emulator.faults` and the other top-level\n * APIs stay the Messages route's. `reset()` and `POST /_emulate/reset` reset both.\n */\nexport const makeAnthropicEmulator = (options: AnthropicEmulatorOptions = {}): AnthropicEmulator =>\n withSubscriptionUsage(\n makeMessagesEmulator({\n path: anthropicMessagesPath,\n routes: anthropicEmulatorRoutes,\n knownModels: options.knownModels ?? anthropicEmulatorDefaultModels,\n inputInvalid: (input, reason) => new AnthropicEmulatorInputInvalid({ input, reason })\n }),\n makeSubscriptionUsageEmulator({\n path: anthropicSubscriptionUsagePath,\n routes: anthropicSubscriptionUsageEmulatorRoutes,\n recording: anthropicClaudeUsageRecording,\n headers: [\n {\n name: 'anthropic-beta',\n record: true,\n accepts: value =>\n value\n .split(',')\n .map(beta => beta.trim())\n .includes(anthropicOAuthBeta)\n }\n ],\n subscriptionUsage: options.subscriptionUsage,\n inputInvalid: (input, reason) => new AnthropicEmulatorInputInvalid({ input, reason })\n }),\n anthropicSubscriptionUsagePath\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,wBAAwB;;AAGrC,MAAa,iCAAiC;;AAG9C,MAAa,qBAAqB;;;;;AAMlC,MAAa,2CAAiF,CAC5F;CACE,QAAQ;CACR,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS,CAAC,iCAAiC;CAC3C,UAAU;CACV,YAAY,KAAA;AACd,CACF;;;;;AAMA,MAAa,oCAAiD,kBAC5D,6BACF;;AAGA,MAAa,iCAAwD,CACnE,oBACA,mBACF;;;;;AAMA,MAAa,0BAAgE,CAC3E;CACE,QAAQ;CACR,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;EACP;EACA;EACA;EACA;EACA;CACF;CACA,UAAU;CACV,YAAY,KAAA;AACd,CACF;;AAGA,MAAa,sBAAsB;;AAKnC,MAAa,qBAAqB;;AAKlC,MAAa,2BAA2B;;;;;;;;;;;;;;AAiBxC,MAAa,iBAAiB;;AAO9B,MAAa,yBAAyB;;AAKtC,MAAa,2BAA2B;;;;;;AASxC,MAAa,2BAA2B;;AAKxC,MAAa,yBAAyB;;AAKtC,MAAa,wBAAwB;;AAKrC,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,EAGG;CACD,IAAa,UAAkB;EAC7B,OAAO,8BAA8B,KAAK,MAAM,IAAI,KAAK;CAC3D;AACF;;AAWA,MAAa,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDnC,MAAa,yBAAyB,UAAoC,CAAC,MACzE,sBACE,qBAAqB;CACnB,MAAM;CACN,QAAQ;CACR,aAAa,QAAQ,eAAe;CACpC,eAAe,OAAO,WAAW,IAAI,8BAA8B;EAAE;EAAO;CAAO,CAAC;AACtF,CAAC,GACD,8BAA8B;CAC5B,MAAM;CACN,QAAQ;CACR,WAAW;CACX,SAAS,CACP;EACE,MAAM;EACN,QAAQ;EACR,UAAS,UACP,MACG,MAAM,GAAG,EACT,KAAI,SAAQ,KAAK,KAAK,CAAC,EACvB,SAAS,kBAAkB;CAClC,CACF;CACA,mBAAmB,QAAQ;CAC3B,eAAe,OAAO,WAAW,IAAI,8BAA8B;EAAE;EAAO;CAAO,CAAC;AACtF,CAAC,GACD,8BACF"}
1
+ {"version":3,"file":"anthropic.mjs","names":[],"sources":["../src/anthropic.ts"],"sourcesContent":["/**\n * Anthropic Messages emulator: a plain fetch handler for `POST /v1/messages` (origin\n * `https://api.anthropic.com`), with scripted turns, wire faults, a request ledger, and an\n * `/_emulate/*` control plane.\n *\n * It never imports SDK code: its wire shapes follow the synthetic Anthropic Messages conformance\n * fixtures (`message_start` / `content_block_*` / `message_delta` / `message_stop` SSE with\n * `text_delta`, `thinking_delta`, and `input_json_delta`, the `message` JSON body, and the\n * `{ type: 'error', error: { type, message } }` envelope) and are linked to those conformance\n * case ids in `anthropicEmulatorRoutes`. The Messages machinery lives in the internal\n * `messages.ts` core; faults, the ledger, and the control plane are shared with the Chat\n * Completions emulators.\n *\n * Requests authenticate with a non-empty `x-api-key` (native API keys) or `Authorization:\n * Bearer` (Claude OAuth) credential. Neither value is ever checked or stored.\n *\n * The same fetch handler also answers the Claude subscription-usage route\n * (`GET /api/oauth/usage`, `emulator.usage`) with its own manifest\n * (`anthropicSubscriptionUsageEmulatorRoutes`), ledger, faults, and turns; see\n * `makeAnthropicEmulator`.\n *\n * Runtime-portable Web APIs only (`Request`, `Response`, `ReadableStream`, `TextEncoder`, `URL`);\n * no Effect runtime is required to use it.\n *\n * @experimental\n */\nimport { Data } from 'effect'\nimport type * as Schema from 'effect/Schema'\nimport { withSubscriptionUsage } from './emulator-compose.ts'\nimport type {\n EmulatorCoverage,\n EmulatorFaultState,\n EmulatorRouteCoverage\n} from './emulator-kernel.ts'\nimport { EmulatorFaultMatch, EmulatorScriptedError } from './emulator-kernel.ts'\nimport {\n MessagesErrorEventFault,\n MessagesFault,\n MessagesScriptedMessage,\n MessagesScriptedToolUse,\n MessagesScriptedTurn,\n MessagesScriptedUsage,\n MessagesWireError,\n makeMessagesEmulator,\n type MessagesEmulator,\n type MessagesFaultKind,\n type MessagesLedgerEntry\n} from './messages.ts'\nimport type { EmulatorRouteEvidence } from './route-evidence.ts'\nimport {\n makeSubscriptionUsageEmulator,\n recordedUsageBody,\n SubscriptionUsageFault,\n type SubscriptionUsageEmulator,\n type SubscriptionUsageLedgerEntry,\n type SubscriptionUsageScriptedTurn\n} from './subscription-usage.ts'\nimport { anthropicClaudeUsageRecording } from './subscription-usage-recordings.ts'\n\nexport type { EmulatorEvidence, EmulatorRouteEvidence } from './route-evidence.ts'\n\nexport { emulatorEvidenceHeader } from './route-evidence.ts'\n\nexport const anthropicMessagesPath = '/v1/messages'\n\n/** The Claude subscription-usage path (`anthropicClaudeSubscriptionUsageUrl` in the SDK). */\nexport const anthropicSubscriptionUsagePath = '/api/oauth/usage'\n\n/** The `anthropic-beta` value the Claude usage fetcher sends for OAuth credentials. */\nexport const anthropicOAuthBeta = 'oauth-2025-04-20'\n\n/**\n * Route evidence manifest of the Claude subscription-usage route (served by the same fetch\n * handler as the Messages route, with its own ledger and coverage). Synthetic, unverified.\n */\nexport const anthropicSubscriptionUsageEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence> = [\n {\n method: 'GET',\n path: anthropicSubscriptionUsagePath,\n kind: 'provider',\n write: false,\n caseIds: ['anthropic.claude.usage.snapshot'],\n evidence: 'unverified',\n observedAt: undefined\n }\n]\n\n/**\n * The recorded Claude usage body (the synthetic `anthropic.claude.usage.snapshot` fixture, copied\n * as data): `five_hour` and `seven_day` as `{ utilization, resets_at }`.\n */\nexport const anthropicSubscriptionUsageDefault: Schema.Json = recordedUsageBody(\n anthropicClaudeUsageRecording\n)\n\n/** Synthetic-safe default model ids, including the Anthropic Messages conformance defaults. */\nexport const anthropicEmulatorDefaultModels: ReadonlyArray<string> = [\n 'claude-haiku-4-5',\n 'claude-sonnet-4-5'\n]\n\n/**\n * Route evidence manifest: every emulated Anthropic route and the conformance cases whose\n * (currently synthetic, unverified) wire shapes it follows.\n */\nexport const anthropicEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence> = [\n {\n method: 'POST',\n path: anthropicMessagesPath,\n kind: 'provider',\n write: false,\n caseIds: [\n 'anthropic.messages.stream.plain-text',\n 'anthropic.messages.stream.tool-use-input-deltas',\n 'anthropic.messages.stream.thinking-before-text',\n 'anthropic.messages.stream.error-envelope',\n 'anthropic.messages.stream.max-tokens'\n ],\n evidence: 'unverified',\n observedAt: undefined\n }\n]\n\n/** Optional fault filter; an omitted field matches every request. `path` ending in `*` is a prefix. */\nexport const AnthropicFaultMatch = EmulatorFaultMatch\n\nexport type AnthropicFaultMatch = typeof EmulatorFaultMatch.Type\n\n/** An Anthropic wire error (`{ type, message }`), as sent inside the error envelope. */\nexport const AnthropicWireError = MessagesWireError\n\nexport type AnthropicWireError = MessagesWireError\n\n/** A mid-stream `error` event fault (default `overloaded_error`), streamed responses only. */\nexport const AnthropicErrorEventFault = MessagesErrorEventFault\n\nexport type AnthropicErrorEventFault = typeof MessagesErrorEventFault.Type\n\n/**\n * Wire faults:\n *\n * - `status`: answer with this status, headers, and body (for example 429 with `retry-after`,\n * or 529). The body defaults to the Anthropic error envelope for the status\n * (`rate_limit_error` for 429, `overloaded_error` for 529, `api_error` for other 5xx).\n * - `error-after-chunks`: send N body chunks, then error the body stream (a dropped connection).\n * - `truncate-after-chunks`: send N body chunks, then close cleanly (no `message_stop`).\n * - `error-event-after-chunks`: send N SSE events, then one `event: error` event and close.\n *\n * Statuses that cannot carry a body and redirects are rejected, as are invalid headers and\n * `location`. A fault that cannot take effect answers 500 and is not consumed.\n */\nexport const AnthropicFault = MessagesFault\n\nexport type AnthropicFault = MessagesFault\n\nexport type AnthropicFaultKind = MessagesFaultKind\n\n/** Usage for a scripted turn (sent in `message_start` and `message_delta`). */\nexport const AnthropicScriptedUsage = MessagesScriptedUsage\n\nexport type AnthropicScriptedUsage = MessagesScriptedUsage\n\n/** One scripted `tool_use` block; its JSON input streams as these fragments. */\nexport const AnthropicScriptedToolUse = MessagesScriptedToolUse\n\nexport type AnthropicScriptedToolUse = MessagesScriptedToolUse\n\n/**\n * A scripted message. Every field is exact except: a block is sent only when its field is\n * present; `usage` omitted is synthesized and `null` drops it; `stopReason` omitted is\n * `tool_use` with tool uses, else `end_turn`; `order` defaults to `thinking-first`.\n */\nexport const AnthropicScriptedMessage = MessagesScriptedMessage\n\nexport type AnthropicScriptedMessage = MessagesScriptedMessage\n\n/** A scripted error response: status, body (a string is sent as is), and optional headers. */\nexport const AnthropicScriptedError = EmulatorScriptedError\n\nexport type AnthropicScriptedError = typeof EmulatorScriptedError.Type\n\n/** A turn queued for the next Messages request. */\nexport const AnthropicScriptedTurn = MessagesScriptedTurn\n\nexport type AnthropicScriptedTurn = MessagesScriptedTurn\n\n/** Thrown by the JS API (`faults.add`, `script.enqueue`) for invalid input; a programmer error. */\nexport class AnthropicEmulatorInputInvalid extends Data.TaggedError(\n 'AnthropicEmulatorInputInvalid'\n)<{\n readonly input: 'fault' | 'turn'\n readonly reason: string\n}> {\n override get message(): string {\n return `Invalid Anthropic emulator ${this.input}: ${this.reason}`\n }\n}\n\nexport type AnthropicLedgerEntry = MessagesLedgerEntry\n\nexport type AnthropicFaultState = EmulatorFaultState<AnthropicFault>\n\nexport type AnthropicRouteCoverage = EmulatorRouteCoverage\n\nexport type AnthropicCoverage = EmulatorCoverage\n\n/** A usage-route fault (`status`, `error-after-chunks`, `truncate-after-chunks`). */\nexport const AnthropicUsageFault = SubscriptionUsageFault\n\nexport type AnthropicUsageFault = SubscriptionUsageFault\n\n/** A usage turn: `{ usage }` (a body with the recorded JSON shape) or `{ error }`. */\nexport type AnthropicUsageScriptedTurn = SubscriptionUsageScriptedTurn\n\nexport type AnthropicUsageLedgerEntry = SubscriptionUsageLedgerEntry\n\nexport type AnthropicUsageEmulator = SubscriptionUsageEmulator\n\nexport type AnthropicEmulatorOptions = {\n /** Model ids that exist. Defaults to `anthropicEmulatorDefaultModels`. */\n readonly knownModels?: ReadonlyArray<string>\n /**\n * Replacement usage-route body; must have the recorded JSON shape (same keys and value kinds).\n * Defaults to the recorded body (`anthropicSubscriptionUsageDefault`).\n */\n readonly subscriptionUsage?: Schema.Json\n}\n\n/** The Messages emulator, plus `usage`: the subscription-usage route's own emulator API. */\nexport type AnthropicEmulator = MessagesEmulator & { readonly usage: AnthropicUsageEmulator }\n\n/**\n * Create an Anthropic Messages emulator. Each call has independent ledger, fault, and script\n * state.\n *\n * Without a script, `POST /v1/messages` answers a known model with synthetic content: `stream:\n * true` streams `message_start`, the content blocks (`content_block_start`, deltas,\n * `content_block_stop`, with a `ping` after the first block starts), `message_delta` (stop reason\n * and usage), and `message_stop`; `stream: false` returns one `message` JSON body. A request with\n * `thinking` enabled (`enabled` or `adaptive`) gets a thinking block before the answer. A request\n * with `tools` gets one `tool_use` block whose input is synthesized from the tool's `input_schema`\n * and streamed as `input_json_delta` fragments, stopping with `tool_use`; `tool_choice: { type:\n * 'tool', name }` picks that tool (otherwise the first) and `tool_choice: { type: 'none' }`\n * answers with text. An answer that would exceed `max_tokens` is cut and stops with `max_tokens`.\n * Unknown models get 404 `not_found_error`; a request with neither a non-empty `x-api-key` nor a\n * bearer credential gets 401 `authentication_error`; a missing or unsupported `anthropic-version`\n * (only `2023-06-01` is accepted), a missing or non-positive `max_tokens`, or `thinking` with a\n * forced `tool_choice` (`tool` or `any`) gets 400 `invalid_request_error`; unknown routes get a\n * 404 envelope. The OAuth `anthropic-beta` header and `budget_tokens` limits are not enforced. The\n * ledger records which header carried the credential, `anthropic-version`, and `anthropic-beta`,\n * never a credential value.\n *\n * `GET /api/oauth/usage` is fixture-only: a request with a non-empty bearer credential (never\n * checked or stored), an `anthropic-beta` header listing `oauth-2025-04-20`, `accept:\n * application/json`, and no query gets the recorded body (`anthropicSubscriptionUsageDefault`,\n * or a same-shaped `options.subscriptionUsage` / scripted `{ usage }`); anything else answers 400\n * not-emulated. Throws `AnthropicEmulatorInputInvalid` for a differently shaped\n * `subscriptionUsage`. Its ledger, faults, turns, and coverage are\n * `emulator.usage` (control plane `/_emulate/usage/*`); `emulator.faults` and the other top-level\n * APIs stay the Messages route's. `reset()` and `POST /_emulate/reset` reset both.\n */\nexport const makeAnthropicEmulator = (options: AnthropicEmulatorOptions = {}): AnthropicEmulator =>\n withSubscriptionUsage(\n makeMessagesEmulator({\n path: anthropicMessagesPath,\n routes: anthropicEmulatorRoutes,\n knownModels: options.knownModels ?? anthropicEmulatorDefaultModels,\n inputInvalid: (input, reason) => new AnthropicEmulatorInputInvalid({ input, reason })\n }),\n makeSubscriptionUsageEmulator({\n path: anthropicSubscriptionUsagePath,\n routes: anthropicSubscriptionUsageEmulatorRoutes,\n recording: anthropicClaudeUsageRecording,\n headers: [\n {\n name: 'anthropic-beta',\n record: true,\n accepts: value =>\n value\n .split(',')\n .map(beta => beta.trim())\n .includes(anthropicOAuthBeta)\n }\n ],\n subscriptionUsage: options.subscriptionUsage,\n inputInvalid: (input, reason) => new AnthropicEmulatorInputInvalid({ input, reason })\n }),\n anthropicSubscriptionUsagePath\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,wBAAwB;;AAGrC,MAAa,iCAAiC;;AAG9C,MAAa,qBAAqB;;;;;AAMlC,MAAa,2CAAiF,CAC5F;CACE,QAAQ;CACR,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS,CAAC,iCAAiC;CAC3C,UAAU;CACV,YAAY,KAAA;AACd,CACF;;;;;AAMA,MAAa,oCAAiD,kBAC5D,6BACF;;AAGA,MAAa,iCAAwD,CACnE,oBACA,mBACF;;;;;AAMA,MAAa,0BAAgE,CAC3E;CACE,QAAQ;CACR,MAAM;CACN,MAAM;CACN,OAAO;CACP,SAAS;EACP;EACA;EACA;EACA;EACA;CACF;CACA,UAAU;CACV,YAAY,KAAA;AACd,CACF;;AAGA,MAAa,sBAAsB;;AAKnC,MAAa,qBAAqB;;AAKlC,MAAa,2BAA2B;;;;;;;;;;;;;;AAiBxC,MAAa,iBAAiB;;AAO9B,MAAa,yBAAyB;;AAKtC,MAAa,2BAA2B;;;;;;AASxC,MAAa,2BAA2B;;AAKxC,MAAa,yBAAyB;;AAKtC,MAAa,wBAAwB;;AAKrC,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,CAAC,CAGE;CACD,IAAa,UAAkB;EAC7B,OAAO,8BAA8B,KAAK,MAAM,IAAI,KAAK;CAC3D;AACF;;AAWA,MAAa,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDnC,MAAa,yBAAyB,UAAoC,CAAC,MACzE,sBACE,qBAAqB;CACnB,MAAM;CACN,QAAQ;CACR,aAAa,QAAQ,eAAe;CACpC,eAAe,OAAO,WAAW,IAAI,8BAA8B;EAAE;EAAO;CAAO,CAAC;AACtF,CAAC,GACD,8BAA8B;CAC5B,MAAM;CACN,QAAQ;CACR,WAAW;CACX,SAAS,CACP;EACE,MAAM;EACN,QAAQ;EACR,UAAS,UACP,MACG,MAAM,GAAG,CAAC,CACV,KAAI,SAAQ,KAAK,KAAK,CAAC,CAAC,CACxB,SAAS,kBAAkB;CAClC,CACF;CACA,mBAAmB,QAAQ;CAC3B,eAAe,OAAO,WAAW,IAAI,8BAA8B;EAAE;EAAO;CAAO,CAAC;AACtF,CAAC,GACD,8BACF"}
@@ -1,14 +1,12 @@
1
- import { EmulatorEvidence, EmulatorRouteEvidence } from "./route-evidence.mjs";
2
1
  import { EmulatorApi, EmulatorCoverage, EmulatorFaultState, EmulatorRouteCoverage } from "./emulator-kernel.mjs";
2
+ import { EmulatorEvidence, EmulatorRouteEvidence } from "./route-evidence.mjs";
3
3
  import * as Schema from "effect/Schema";
4
-
5
- //#region src/chat-completions.d.ts
6
4
  /** Optional fault filter; an omitted field matches every request. `path` ending in `*` is a prefix. */
7
- declare const ChatFaultMatch: Schema.Struct<{
5
+ export declare const ChatFaultMatch: Schema.Struct<{
8
6
  readonly path: Schema.optionalKey<Schema.String>;
9
7
  readonly model: Schema.optionalKey<Schema.String>;
10
8
  }>;
11
- type ChatFaultMatch = typeof ChatFaultMatch.Type;
9
+ export type ChatFaultMatch = typeof ChatFaultMatch.Type;
12
10
  /**
13
11
  * Wire faults for emulated routes:
14
12
  *
@@ -27,7 +25,7 @@ type ChatFaultMatch = typeof ChatFaultMatch.Type;
27
25
  * `truncate-after-chunks` at or beyond it) answers 500 with an emulator error
28
26
  * instead of silently doing nothing, and is not consumed.
29
27
  */
30
- declare const ChatFault: Schema.Union<readonly [Schema.Struct<{
28
+ export declare const ChatFault: Schema.Union<readonly [Schema.Struct<{
31
29
  readonly match: Schema.optionalKey<Schema.Struct<{
32
30
  readonly path: Schema.optionalKey<Schema.String>;
33
31
  readonly model: Schema.optionalKey<Schema.String>;
@@ -54,24 +52,24 @@ declare const ChatFault: Schema.Union<readonly [Schema.Struct<{
54
52
  readonly kind: Schema.Literal<"truncate-after-chunks">;
55
53
  readonly chunks: Schema.Int;
56
54
  }>]>;
57
- type ChatFault = typeof ChatFault.Type;
58
- type ChatFaultKind = ChatFault['kind'];
55
+ export type ChatFault = typeof ChatFault.Type;
56
+ export type ChatFaultKind = ChatFault['kind'];
59
57
  /** Usage for a scripted turn (sent as the wire `usage` object). */
60
- declare const ChatScriptedUsage: Schema.Struct<{
58
+ export declare const ChatScriptedUsage: Schema.Struct<{
61
59
  readonly promptTokens: Schema.Int;
62
60
  readonly completionTokens: Schema.Int;
63
61
  readonly reasoningTokens: Schema.optionalKey<Schema.Int>;
64
62
  }>;
65
- type ChatScriptedUsage = typeof ChatScriptedUsage.Type;
63
+ export type ChatScriptedUsage = typeof ChatScriptedUsage.Type;
66
64
  /** One scripted tool call; its JSON arguments stream as these fragments. */
67
- declare const ChatScriptedToolCall: Schema.Struct<{
65
+ export declare const ChatScriptedToolCall: Schema.Struct<{
68
66
  readonly name: Schema.NonEmptyString;
69
67
  readonly argumentFragments: Schema.$Array<Schema.String>;
70
68
  readonly id: Schema.optionalKey<Schema.NonEmptyString>;
71
69
  }>;
72
- type ChatScriptedToolCall = typeof ChatScriptedToolCall.Type;
70
+ export type ChatScriptedToolCall = typeof ChatScriptedToolCall.Type;
73
71
  /** Scripted completion fields every Chat Completions emulator accepts. */
74
- declare const chatScriptedCompletionFields: {
72
+ export declare const chatScriptedCompletionFields: {
75
73
  text: Schema.optionalKey<Schema.$Array<Schema.String>>;
76
74
  toolCalls: Schema.optionalKey<Schema.$Array<Schema.Struct<{
77
75
  readonly name: Schema.NonEmptyString;
@@ -86,7 +84,7 @@ declare const chatScriptedCompletionFields: {
86
84
  finishReason: Schema.optionalKey<Schema.NonEmptyString>;
87
85
  };
88
86
  /** Scripted completion fields for emulators that emulate streamed reasoning. */
89
- declare const chatScriptedReasoningFields: {
87
+ export declare const chatScriptedReasoningFields: {
90
88
  reasoning: Schema.optionalKey<Schema.$Array<Schema.String>>;
91
89
  reasoningField: Schema.optionalKey<Schema.Literals<readonly ["reasoning_content", "reasoning"]>>;
92
90
  order: Schema.optionalKey<Schema.Literals<readonly ["reasoning-first", "text-first"]>>;
@@ -100,7 +98,7 @@ declare const chatScriptedReasoningFields: {
100
98
  * defaults to the emulator's wire profile field (`reasoning` for the Gateway,
101
99
  * as recorded live; `reasoning_content` is the DeepSeek-native alternative).
102
100
  */
103
- declare const ChatScriptedReasoningCompletion: Schema.Struct<{
101
+ export declare const ChatScriptedReasoningCompletion: Schema.Struct<{
104
102
  readonly text: Schema.optionalKey<Schema.$Array<Schema.String>>;
105
103
  readonly reasoning: Schema.optionalKey<Schema.$Array<Schema.String>>;
106
104
  readonly reasoningField: Schema.optionalKey<Schema.Literals<readonly ["reasoning_content", "reasoning"]>>;
@@ -117,21 +115,21 @@ declare const ChatScriptedReasoningCompletion: Schema.Struct<{
117
115
  }>>>;
118
116
  readonly finishReason: Schema.optionalKey<Schema.NonEmptyString>;
119
117
  }>;
120
- type ChatScriptedReasoningCompletion = typeof ChatScriptedReasoningCompletion.Type;
118
+ export type ChatScriptedReasoningCompletion = typeof ChatScriptedReasoningCompletion.Type;
121
119
  /** A scripted error response: status, body (a string is sent as is), and optional headers. */
122
- declare const ChatScriptedError: Schema.Struct<{
120
+ export declare const ChatScriptedError: Schema.Struct<{
123
121
  readonly error: Schema.Struct<{
124
122
  readonly status: Schema.Int;
125
123
  readonly body: Schema.Codec<Schema.Json, Schema.Json, never, never>;
126
124
  readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
127
125
  }>;
128
126
  }>;
129
- type ChatScriptedError = typeof ChatScriptedError.Type;
127
+ export type ChatScriptedError = typeof ChatScriptedError.Type;
130
128
  /**
131
129
  * The reasoning variant of a scripted turn, queued for the next chat completion request. It is
132
130
  * also the widest turn shape, so it bounds every emulator's turn type.
133
131
  */
134
- declare const ChatScriptedReasoningTurn: Schema.Union<readonly [Schema.Struct<{
132
+ export declare const ChatScriptedReasoningTurn: Schema.Union<readonly [Schema.Struct<{
135
133
  readonly error: Schema.Struct<{
136
134
  readonly status: Schema.Int;
137
135
  readonly body: Schema.Codec<Schema.Json, Schema.Json, never, never>;
@@ -154,11 +152,13 @@ declare const ChatScriptedReasoningTurn: Schema.Union<readonly [Schema.Struct<{
154
152
  }>>>;
155
153
  readonly finishReason: Schema.optionalKey<Schema.NonEmptyString>;
156
154
  }>]>;
157
- type ChatScriptedReasoningTurn = typeof ChatScriptedReasoningTurn.Type;
158
- type ChatLedgerEntry = {
159
- /** 1-based arrival order since the last ledger clear or reset. */readonly seq: number;
155
+ export type ChatScriptedReasoningTurn = typeof ChatScriptedReasoningTurn.Type;
156
+ export type ChatLedgerEntry = {
157
+ /** 1-based arrival order since the last ledger clear or reset. */
158
+ readonly seq: number;
160
159
  readonly method: string;
161
- readonly path: string; /** Parsed JSON request body, when it was valid JSON. */
160
+ readonly path: string;
161
+ /** Parsed JSON request body, when it was valid JSON. */
162
162
  readonly body?: Schema.Json;
163
163
  readonly model?: string;
164
164
  readonly stream?: boolean;
@@ -169,36 +169,41 @@ type ChatLedgerEntry = {
169
169
  readonly maxCompletionTokens?: number;
170
170
  readonly reasoningEffort?: string;
171
171
  readonly thinking?: Schema.Json;
172
- readonly toolNames: ReadonlyArray<string>; /** Kind of the fault that shaped the response. */
173
- readonly fault?: ChatFaultKind; /** Why a matching fault could not take effect (the response was a 500 emulator error). */
172
+ readonly toolNames: ReadonlyArray<string>;
173
+ /** Kind of the fault that shaped the response. */
174
+ readonly fault?: ChatFaultKind;
175
+ /** Why a matching fault could not take effect (the response was a 500 emulator error). */
174
176
  readonly faultError?: string;
175
177
  /**
176
178
  * Set when the emulator could not build the planned response; the request was
177
179
  * answered with a 500 emulator error (still evidence-tagged) and no fault was used up.
178
180
  */
179
- readonly responseError?: string; /** Set when a scripted turn answered the request. */
180
- readonly scripted?: 'completion' | 'error'; /** Evidence of the matched route; `unknown-route` for requests that failed closed. */
181
+ readonly responseError?: string;
182
+ /** Set when a scripted turn answered the request. */
183
+ readonly scripted?: 'completion' | 'error';
184
+ /** Evidence of the matched route; `unknown-route` for requests that failed closed. */
181
185
  readonly evidence: EmulatorEvidence | 'unknown-route';
182
- readonly status: number; /** Body chunks handed to the transport so far (each produced when pulled). */
186
+ readonly status: number;
187
+ /** Body chunks handed to the transport so far (each produced when pulled). */
183
188
  readonly bodyChunks: number;
184
189
  };
185
- type ChatFaultState = EmulatorFaultState<ChatFault>;
186
- type ChatRouteCoverage = EmulatorRouteCoverage;
187
- type ChatCoverage = EmulatorCoverage;
188
- type ChatCompletionsEmulator<Turn> = EmulatorApi<Turn, ChatFault, ChatLedgerEntry>;
190
+ export type ChatFaultState = EmulatorFaultState<ChatFault>;
191
+ export type ChatRouteCoverage = EmulatorRouteCoverage;
192
+ export type ChatCoverage = EmulatorCoverage;
193
+ export type ChatCompletionsEmulator<Turn> = EmulatorApi<Turn, ChatFault, ChatLedgerEntry>;
189
194
  /** One wire error: the emulator's envelope renders it. */
190
- type ChatWireError = {
195
+ export type ChatWireError = {
191
196
  readonly message: string;
192
197
  readonly type: string;
193
198
  readonly code: string;
194
199
  };
195
200
  /** The id and model every chunk of one emulated response repeats. */
196
- type ChatResponseIdentity = {
201
+ export type ChatResponseIdentity = {
197
202
  readonly id: string;
198
203
  readonly model: string;
199
204
  };
200
205
  /** Token counts behind a wire `usage` object. */
201
- type ChatUsageCounts = {
206
+ export type ChatUsageCounts = {
202
207
  readonly promptTokens: number;
203
208
  readonly completionTokens: number;
204
209
  readonly reasoningTokens: number | undefined;
@@ -207,7 +212,7 @@ type ChatUsageCounts = {
207
212
  * Per-service response details on top of the shared framing. Every field is optional; an omitted
208
213
  * field keeps the plain OpenAI Chat Completions wire (the `/openai` emulator passes no profile).
209
214
  */
210
- type ChatWireProfile = {
215
+ export type ChatWireProfile = {
211
216
  /**
212
217
  * SSE events per network (body) chunk; default 1. Events are packed counting from the end, so
213
218
  * the last chunk carries the finish event together with `data: [DONE]` and the first chunk may
@@ -218,24 +223,33 @@ type ChatWireProfile = {
218
223
  * Where streamed usage goes when `stream_options.include_usage` is set: a trailing chunk with
219
224
  * empty `choices` (`usage-chunk`, default) or the finish event itself (`finish-event`).
220
225
  */
221
- readonly streamUsage?: 'usage-chunk' | 'finish-event'; /** The first streamed delta; default `{ role: 'assistant', content: '' }`. */
222
- readonly openingDelta?: Schema.JsonObject; /** Extra fields on every streamed choice, placed before `finish_reason` (for example `logprobs`). */
223
- readonly choiceFields?: Schema.JsonObject; /** The default reasoning field for default and scripted output; default `reasoning_content`. */
224
- readonly reasoningField?: 'reasoning_content' | 'reasoning'; /** Streamed `reasoning` deltas also carry `reasoning_details` (`reasoning.text` entries). */
225
- readonly reasoningDetails?: boolean; /** Extra top-level fields on every streamed chunk (for example `system_fingerprint`). */
226
- readonly chunkFields?: (identity: ChatResponseIdentity) => Schema.JsonObject; /** Extra fields on the finish event: top-level (`chunk`) and inside its `delta`. */
226
+ readonly streamUsage?: 'usage-chunk' | 'finish-event';
227
+ /** The first streamed delta; default `{ role: 'assistant', content: '' }`. */
228
+ readonly openingDelta?: Schema.JsonObject;
229
+ /** Extra fields on every streamed choice, placed before `finish_reason` (for example `logprobs`). */
230
+ readonly choiceFields?: Schema.JsonObject;
231
+ /** The default reasoning field for default and scripted output; default `reasoning_content`. */
232
+ readonly reasoningField?: 'reasoning_content' | 'reasoning';
233
+ /** Streamed `reasoning` deltas also carry `reasoning_details` (`reasoning.text` entries). */
234
+ readonly reasoningDetails?: boolean;
235
+ /** Extra top-level fields on every streamed chunk (for example `system_fingerprint`). */
236
+ readonly chunkFields?: (identity: ChatResponseIdentity) => Schema.JsonObject;
237
+ /** Extra fields on the finish event: top-level (`chunk`) and inside its `delta`. */
227
238
  readonly finishFields?: (identity: ChatResponseIdentity) => {
228
239
  readonly chunk: Schema.JsonObject;
229
240
  readonly delta: Schema.JsonObject;
230
- }; /** Renders token counts as the wire `usage` object (streamed and JSON). */
241
+ };
242
+ /** Renders token counts as the wire `usage` object (streamed and JSON). */
231
243
  readonly usage?: (counts: ChatUsageCounts) => Schema.JsonObject;
232
244
  };
233
245
  /**
234
246
  * What differs between Chat Completions emulators. The core owns everything else (framing,
235
247
  * faults, scripting, ledger, control plane, evidence).
236
248
  */
237
- type ChatCompletionsEmulatorConfig<Turn extends ChatScriptedReasoningTurn> = {
238
- /** The chat completions path, for example `/v1/chat/completions`. */readonly path: string; /** Route evidence manifest; must list exactly the chat completions route. */
249
+ export type ChatCompletionsEmulatorConfig<Turn extends ChatScriptedReasoningTurn> = {
250
+ /** The chat completions path, for example `/v1/chat/completions`. */
251
+ readonly path: string;
252
+ /** Route evidence manifest; must list exactly the chat completions route. */
239
253
  readonly routes: ReadonlyArray<EmulatorRouteEvidence>;
240
254
  readonly knownModels: ReadonlyArray<string>;
241
255
  /**
@@ -243,7 +257,8 @@ type ChatCompletionsEmulatorConfig<Turn extends ChatScriptedReasoningTurn> = {
243
257
  * never reason and `/_emulate/state` omits `reasoningModels`); otherwise the models that stream
244
258
  * reasoning when a request asks for it.
245
259
  */
246
- readonly reasoningModels: ReadonlyArray<string> | undefined; /** Renders a wire error as the service's JSON error envelope. */
260
+ readonly reasoningModels: ReadonlyArray<string> | undefined;
261
+ /** Renders a wire error as the service's JSON error envelope. */
247
262
  readonly errorEnvelope: (error: ChatWireError) => Schema.Json;
248
263
  /**
249
264
  * Status and answer for an unknown (or missing) model id: an `error` rendered with
@@ -263,12 +278,18 @@ type ChatCompletionsEmulatorConfig<Turn extends ChatScriptedReasoningTurn> = {
263
278
  */
264
279
  readonly auth: {
265
280
  readonly unauthorized: ChatWireError;
266
- }; /** Request field carrying the output-token limit, recorded in the ledger. */
267
- readonly completionTokenField: 'max_tokens' | 'max_completion_tokens'; /** Response id prefix; ids are `${prefix}-${seq}`. */
268
- readonly responseIdPrefix: string; /** Default answer text deltas. */
269
- readonly defaultText: ReadonlyArray<string>; /** The emulator's scripted-turn schema (decoded strictly). */
270
- readonly turnSchema: Schema.Decoder<Turn>; /** Builds the error thrown by the JS API (`faults.add`, `script.enqueue`) for invalid input. */
271
- readonly inputInvalid: (input: 'fault' | 'turn', reason: string) => Error; /** Per-service wire details; omitted: the plain OpenAI Chat Completions wire. */
281
+ };
282
+ /** Request field carrying the output-token limit, recorded in the ledger. */
283
+ readonly completionTokenField: 'max_tokens' | 'max_completion_tokens';
284
+ /** Response id prefix; ids are `${prefix}-${seq}`. */
285
+ readonly responseIdPrefix: string;
286
+ /** Default answer text deltas. */
287
+ readonly defaultText: ReadonlyArray<string>;
288
+ /** The emulator's scripted-turn schema (decoded strictly). */
289
+ readonly turnSchema: Schema.Decoder<Turn>;
290
+ /** Builds the error thrown by the JS API (`faults.add`, `script.enqueue`) for invalid input. */
291
+ readonly inputInvalid: (input: 'fault' | 'turn', reason: string) => Error;
292
+ /** Per-service wire details; omitted: the plain OpenAI Chat Completions wire. */
272
293
  readonly wire?: ChatWireProfile;
273
294
  };
274
295
  /**
@@ -282,7 +303,5 @@ type ChatCompletionsEmulatorConfig<Turn extends ChatScriptedReasoningTurn> = {
282
303
  * applies. Credential headers are never recorded, and the bearer value is
283
304
  * never checked or stored.
284
305
  */
285
- declare const makeChatCompletionsEmulator: <Turn extends ChatScriptedReasoningTurn>(config: ChatCompletionsEmulatorConfig<Turn>) => ChatCompletionsEmulator<Turn>;
286
- //#endregion
287
- export { ChatCompletionsEmulator, ChatCompletionsEmulatorConfig, ChatCoverage, ChatFault, ChatFaultKind, ChatFaultMatch, ChatFaultState, ChatLedgerEntry, ChatResponseIdentity, ChatRouteCoverage, ChatScriptedError, ChatScriptedReasoningCompletion, ChatScriptedReasoningTurn, ChatScriptedToolCall, ChatScriptedUsage, ChatUsageCounts, ChatWireError, ChatWireProfile, chatScriptedCompletionFields, chatScriptedReasoningFields, makeChatCompletionsEmulator };
306
+ export declare const makeChatCompletionsEmulator: <Turn extends ChatScriptedReasoningTurn>(config: ChatCompletionsEmulatorConfig<Turn>) => ChatCompletionsEmulator<Turn>;
288
307
  //# sourceMappingURL=chat-completions.d.mts.map