@zyraxon-ai/llm 19.0.5

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 (218) hide show
  1. package/README.md +131 -0
  2. package/dist/cache-policy.d.ts +3 -0
  3. package/dist/cache-policy.d.ts.map +1 -0
  4. package/dist/cache-policy.js +109 -0
  5. package/dist/cache-policy.js.map +1 -0
  6. package/dist/index.d.ts +13 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +9 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/llm.d.ts +205 -0
  11. package/dist/llm.d.ts.map +1 -0
  12. package/dist/llm.js +82 -0
  13. package/dist/llm.js.map +1 -0
  14. package/dist/protocols/anthropic-messages.d.ts +340 -0
  15. package/dist/protocols/anthropic-messages.d.ts.map +1 -0
  16. package/dist/protocols/anthropic-messages.js +719 -0
  17. package/dist/protocols/anthropic-messages.js.map +1 -0
  18. package/dist/protocols/bedrock-converse.d.ts +472 -0
  19. package/dist/protocols/bedrock-converse.d.ts.map +1 -0
  20. package/dist/protocols/bedrock-converse.js +529 -0
  21. package/dist/protocols/bedrock-converse.js.map +1 -0
  22. package/dist/protocols/bedrock-event-stream.d.ts +10 -0
  23. package/dist/protocols/bedrock-event-stream.d.ts.map +1 -0
  24. package/dist/protocols/bedrock-event-stream.js +64 -0
  25. package/dist/protocols/bedrock-event-stream.js.map +1 -0
  26. package/dist/protocols/gemini.d.ts +165 -0
  27. package/dist/protocols/gemini.d.ts.map +1 -0
  28. package/dist/protocols/gemini.js +420 -0
  29. package/dist/protocols/gemini.js.map +1 -0
  30. package/dist/protocols/index.d.ts +7 -0
  31. package/dist/protocols/index.d.ts.map +1 -0
  32. package/dist/protocols/index.js +7 -0
  33. package/dist/protocols/index.js.map +1 -0
  34. package/dist/protocols/openai-chat.d.ts +297 -0
  35. package/dist/protocols/openai-chat.d.ts.map +1 -0
  36. package/dist/protocols/openai-chat.js +426 -0
  37. package/dist/protocols/openai-chat.js.map +1 -0
  38. package/dist/protocols/openai-compatible-chat.d.ts +12 -0
  39. package/dist/protocols/openai-compatible-chat.d.ts.map +1 -0
  40. package/dist/protocols/openai-compatible-chat.js +20 -0
  41. package/dist/protocols/openai-compatible-chat.js.map +1 -0
  42. package/dist/protocols/openai-responses.d.ts +615 -0
  43. package/dist/protocols/openai-responses.d.ts.map +1 -0
  44. package/dist/protocols/openai-responses.js +828 -0
  45. package/dist/protocols/openai-responses.js.map +1 -0
  46. package/dist/protocols/shared.d.ts +193 -0
  47. package/dist/protocols/shared.d.ts.map +1 -0
  48. package/dist/protocols/shared.js +237 -0
  49. package/dist/protocols/shared.js.map +1 -0
  50. package/dist/protocols/utils/bedrock-auth.d.ts +19 -0
  51. package/dist/protocols/utils/bedrock-auth.d.ts.map +1 -0
  52. package/dist/protocols/utils/bedrock-auth.js +42 -0
  53. package/dist/protocols/utils/bedrock-auth.js.map +1 -0
  54. package/dist/protocols/utils/bedrock-cache.d.ts +16 -0
  55. package/dist/protocols/utils/bedrock-cache.d.ts.map +1 -0
  56. package/dist/protocols/utils/bedrock-cache.js +30 -0
  57. package/dist/protocols/utils/bedrock-cache.js.map +1 -0
  58. package/dist/protocols/utils/bedrock-media.d.ts +50 -0
  59. package/dist/protocols/utils/bedrock-media.d.ts.map +1 -0
  60. package/dist/protocols/utils/bedrock-media.js +69 -0
  61. package/dist/protocols/utils/bedrock-media.js.map +1 -0
  62. package/dist/protocols/utils/cache.d.ts +7 -0
  63. package/dist/protocols/utils/cache.d.ts.map +1 -0
  64. package/dist/protocols/utils/cache.js +9 -0
  65. package/dist/protocols/utils/cache.js.map +1 -0
  66. package/dist/protocols/utils/gemini-tool-schema.d.ts +3 -0
  67. package/dist/protocols/utils/gemini-tool-schema.d.ts.map +1 -0
  68. package/dist/protocols/utils/gemini-tool-schema.js +84 -0
  69. package/dist/protocols/utils/gemini-tool-schema.js.map +1 -0
  70. package/dist/protocols/utils/lifecycle.d.ts +20 -0
  71. package/dist/protocols/utils/lifecycle.d.ts.map +1 -0
  72. package/dist/protocols/utils/lifecycle.js +66 -0
  73. package/dist/protocols/utils/lifecycle.js.map +1 -0
  74. package/dist/protocols/utils/openai-options.d.ts +23 -0
  75. package/dist/protocols/utils/openai-options.d.ts.map +1 -0
  76. package/dist/protocols/utils/openai-options.js +68 -0
  77. package/dist/protocols/utils/openai-options.js.map +1 -0
  78. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  79. package/dist/protocols/utils/tool-schema.d.ts.map +1 -0
  80. package/dist/protocols/utils/tool-schema.js +80 -0
  81. package/dist/protocols/utils/tool-schema.js.map +1 -0
  82. package/dist/protocols/utils/tool-stream.d.ts +156 -0
  83. package/dist/protocols/utils/tool-stream.d.ts.map +1 -0
  84. package/dist/protocols/utils/tool-stream.js +137 -0
  85. package/dist/protocols/utils/tool-stream.js.map +1 -0
  86. package/dist/provider-error.d.ts +3 -0
  87. package/dist/provider-error.d.ts.map +1 -0
  88. package/dist/provider-error.js +29 -0
  89. package/dist/provider-error.js.map +1 -0
  90. package/dist/provider.d.ts +24 -0
  91. package/dist/provider.d.ts.map +1 -0
  92. package/dist/provider.js +3 -0
  93. package/dist/provider.js.map +1 -0
  94. package/dist/providers/amazon-bedrock.d.ts +142 -0
  95. package/dist/providers/amazon-bedrock.d.ts.map +1 -0
  96. package/dist/providers/amazon-bedrock.js +27 -0
  97. package/dist/providers/amazon-bedrock.js.map +1 -0
  98. package/dist/providers/anthropic.d.ts +24 -0
  99. package/dist/providers/anthropic.d.ts.map +1 -0
  100. package/dist/providers/anthropic.js +27 -0
  101. package/dist/providers/anthropic.js.map +1 -0
  102. package/dist/providers/azure.d.ts +36 -0
  103. package/dist/providers/azure.d.ts.map +1 -0
  104. package/dist/providers/azure.js +70 -0
  105. package/dist/providers/azure.js.map +1 -0
  106. package/dist/providers/cloudflare.d.ts +47 -0
  107. package/dist/providers/cloudflare.d.ts.map +1 -0
  108. package/dist/providers/cloudflare.js +88 -0
  109. package/dist/providers/cloudflare.js.map +1 -0
  110. package/dist/providers/github-copilot.d.ts +30 -0
  111. package/dist/providers/github-copilot.d.ts.map +1 -0
  112. package/dist/providers/github-copilot.js +48 -0
  113. package/dist/providers/github-copilot.js.map +1 -0
  114. package/dist/providers/google.d.ts +24 -0
  115. package/dist/providers/google.d.ts.map +1 -0
  116. package/dist/providers/google.js +27 -0
  117. package/dist/providers/google.js.map +1 -0
  118. package/dist/providers/index.d.ts +12 -0
  119. package/dist/providers/index.d.ts.map +1 -0
  120. package/dist/providers/index.js +12 -0
  121. package/dist/providers/index.js.map +1 -0
  122. package/dist/providers/openai-compatible-profile.d.ts +44 -0
  123. package/dist/providers/openai-compatible-profile.d.ts.map +1 -0
  124. package/dist/providers/openai-compatible-profile.js +13 -0
  125. package/dist/providers/openai-compatible-profile.js.map +1 -0
  126. package/dist/providers/openai-compatible.d.ts +62 -0
  127. package/dist/providers/openai-compatible.d.ts.map +1 -0
  128. package/dist/providers/openai-compatible.js +48 -0
  129. package/dist/providers/openai-compatible.js.map +1 -0
  130. package/dist/providers/openai-options.d.ts +31 -0
  131. package/dist/providers/openai-options.d.ts.map +1 -0
  132. package/dist/providers/openai-options.js +43 -0
  133. package/dist/providers/openai-options.js.map +1 -0
  134. package/dist/providers/openai.d.ts +116 -0
  135. package/dist/providers/openai.d.ts.map +1 -0
  136. package/dist/providers/openai.js +39 -0
  137. package/dist/providers/openai.js.map +1 -0
  138. package/dist/providers/openrouter.d.ts +199 -0
  139. package/dist/providers/openrouter.d.ts.map +1 -0
  140. package/dist/providers/openrouter.js +66 -0
  141. package/dist/providers/openrouter.js.map +1 -0
  142. package/dist/providers/xai.d.ts +32 -0
  143. package/dist/providers/xai.d.ts.map +1 -0
  144. package/dist/providers/xai.js +44 -0
  145. package/dist/providers/xai.js.map +1 -0
  146. package/dist/route/auth-options.d.ts +35 -0
  147. package/dist/route/auth-options.d.ts.map +1 -0
  148. package/dist/route/auth-options.js +15 -0
  149. package/dist/route/auth-options.js.map +1 -0
  150. package/dist/route/auth.js +90 -0
  151. package/dist/route/auth.js.map +1 -0
  152. package/dist/route/client.d.ts +306 -0
  153. package/dist/route/client.d.ts.map +1 -0
  154. package/dist/route/client.js +197 -0
  155. package/dist/route/client.js.map +1 -0
  156. package/dist/route/endpoint.js +22 -0
  157. package/dist/route/endpoint.js.map +1 -0
  158. package/dist/route/executor.d.ts +13 -0
  159. package/dist/route/executor.d.ts.map +1 -0
  160. package/dist/route/executor.js +287 -0
  161. package/dist/route/executor.js.map +1 -0
  162. package/dist/route/framing.js +5 -0
  163. package/dist/route/framing.js.map +1 -0
  164. package/dist/route/index.d.ts +17 -0
  165. package/dist/route/index.d.ts.map +1 -0
  166. package/dist/route/index.js +10 -0
  167. package/dist/route/index.js.map +1 -0
  168. package/dist/route/protocol.d.ts +77 -0
  169. package/dist/route/protocol.d.ts.map +1 -0
  170. package/dist/route/protocol.js +18 -0
  171. package/dist/route/protocol.js.map +1 -0
  172. package/dist/route/transport/http.d.ts +34 -0
  173. package/dist/route/transport/http.d.ts.map +1 -0
  174. package/dist/route/transport/http.js +98 -0
  175. package/dist/route/transport/http.js.map +1 -0
  176. package/dist/route/transport/index.d.ts +28 -0
  177. package/dist/route/transport/index.d.ts.map +1 -0
  178. package/dist/route/transport/index.js +3 -0
  179. package/dist/route/transport/index.js.map +1 -0
  180. package/dist/route/transport/websocket.d.ts +57 -0
  181. package/dist/route/transport/websocket.d.ts.map +1 -0
  182. package/dist/route/transport/websocket.js +181 -0
  183. package/dist/route/transport/websocket.js.map +1 -0
  184. package/dist/schema/errors.d.ts +166 -0
  185. package/dist/schema/errors.d.ts.map +1 -0
  186. package/dist/schema/errors.js +187 -0
  187. package/dist/schema/errors.js.map +1 -0
  188. package/dist/schema/events.d.ts +3821 -0
  189. package/dist/schema/events.d.ts.map +1 -0
  190. package/dist/schema/events.js +484 -0
  191. package/dist/schema/events.js.map +1 -0
  192. package/dist/schema/ids.d.ts +31 -0
  193. package/dist/schema/ids.d.ts.map +1 -0
  194. package/dist/schema/ids.js +19 -0
  195. package/dist/schema/ids.js.map +1 -0
  196. package/dist/schema/index.d.ts +6 -0
  197. package/dist/schema/index.d.ts.map +1 -0
  198. package/dist/schema/index.js +6 -0
  199. package/dist/schema/index.js.map +1 -0
  200. package/dist/schema/messages.d.ts +294 -0
  201. package/dist/schema/messages.d.ts.map +1 -0
  202. package/dist/schema/messages.js +247 -0
  203. package/dist/schema/messages.js.map +1 -0
  204. package/dist/schema/options.d.ts +144 -0
  205. package/dist/schema/options.d.ts.map +1 -0
  206. package/dist/schema/options.js +196 -0
  207. package/dist/schema/options.js.map +1 -0
  208. package/dist/tool-runtime.d.ts +16 -0
  209. package/dist/tool-runtime.d.ts.map +1 -0
  210. package/dist/tool-runtime.js +35 -0
  211. package/dist/tool-runtime.js.map +1 -0
  212. package/dist/tool.js +67 -0
  213. package/dist/tool.js.map +1 -0
  214. package/dist/utils/record.d.ts +3 -0
  215. package/dist/utils/record.d.ts.map +1 -0
  216. package/dist/utils/record.js +3 -0
  217. package/dist/utils/record.js.map +1 -0
  218. package/package.json +37 -0
@@ -0,0 +1,77 @@
1
+ import { Schema, type Effect } from "effect";
2
+ import type { LLMError, LLMEvent, LLMRequest, ProtocolID } from "../schema";
3
+ /**
4
+ * The semantic API contract of one model server family.
5
+ *
6
+ * A `Protocol` owns the parts of a route that are intrinsic to "what does
7
+ * this API look like": how a common `LLMRequest` becomes a provider-native
8
+ * body, what schema that body must satisfy before it is JSON-encoded, and
9
+ * how the streaming response decodes back into common `LLMEvent`s.
10
+ *
11
+ * Examples:
12
+ *
13
+ * - `OpenAIChat.protocol` — chat completions style
14
+ * - `OpenAIResponses.protocol` — responses API
15
+ * - `AnthropicMessages.protocol` — messages API with content blocks
16
+ * - `Gemini.protocol` — generateContent
17
+ * - `BedrockConverse.protocol` — Converse with binary event-stream framing
18
+ *
19
+ * A `Protocol` is **not** a deployment. It does not know which URL, which
20
+ * headers, or which auth scheme to use. Those are deployment concerns owned
21
+ * by `Route.make(...)` along with the chosen `Endpoint`, `Auth`,
22
+ * and `Framing`. This separation is what lets DeepSeek, TogetherAI, Cerebras,
23
+ * etc. all reuse `OpenAIChat.protocol` without forking 300 lines per provider.
24
+ *
25
+ * The four type parameters reflect the pipeline:
26
+ *
27
+ * - `Body` — provider-native request body candidate. `Route.make(...)`
28
+ * validates and JSON-encodes it with `body.schema`.
29
+ * - `Frame` — one unit of the framed response stream. SSE: a JSON data
30
+ * string. AWS event stream: a parsed binary frame.
31
+ * - `Event` — schema-decoded provider event produced from one frame.
32
+ * - `State` — accumulator threaded through `stream.step` to translate event
33
+ * sequences into `LLMEvent` sequences.
34
+ */
35
+ export interface Protocol<Body, Frame, Event, State> {
36
+ /** Stable id for the wire protocol implementation. */
37
+ readonly id: ProtocolID;
38
+ /** Request side: schema for the provider-native body and how to build it. */
39
+ readonly body: ProtocolBody<Body>;
40
+ /** Response side: streaming state machine. */
41
+ readonly stream: ProtocolStream<Frame, Event, State>;
42
+ }
43
+ export interface ProtocolBody<Body> {
44
+ /** Schema for the validated provider-native body sent as the JSON request. */
45
+ readonly schema: Schema.Codec<Body, unknown>;
46
+ /** Build the provider-native body from a common `LLMRequest`. */
47
+ readonly from: (request: LLMRequest) => Effect.Effect<Body, LLMError>;
48
+ }
49
+ export interface ProtocolStream<Frame, Event, State> {
50
+ /** Schema for one decoded streaming event, decoded from a transport frame. */
51
+ readonly event: Schema.Codec<Event, Frame>;
52
+ /** Initial parser state. Called once per response with the resolved request. */
53
+ readonly initial: (request: LLMRequest) => State;
54
+ /** Translate one event into emitted `LLMEvent`s plus the next state. */
55
+ readonly step: (state: State, event: Event) => Effect.Effect<readonly [State, ReadonlyArray<LLMEvent>], LLMError>;
56
+ /** Optional request-completion signal for transports that do not end naturally. */
57
+ readonly terminal?: (event: Event) => boolean;
58
+ /** Optional flush emitted when the framed stream ends. */
59
+ readonly onHalt?: (state: State) => ReadonlyArray<LLMEvent>;
60
+ }
61
+ /**
62
+ * Construct a `Protocol` from its body and stream pieces:
63
+ *
64
+ * - `body.schema` infers the provider-native request body shape.
65
+ * - `body.from` ties the common `LLMRequest` to the provider body.
66
+ * - `stream.event` infers the decoded streaming event and the wire frame.
67
+ * - `stream.initial`, `stream.step`, and `stream.onHalt` infer the parser state.
68
+ *
69
+ * Provider implementations should usually call `Protocol.make({ ... })`
70
+ * without explicit type arguments; the schemas and parser functions are the
71
+ * source of truth. The constructor remains as the public seam for future
72
+ * cross-cutting concerns such as tracing or instrumentation.
73
+ */
74
+ export declare const make: <Body, Frame, Event, State>(input: Protocol<Body, Frame, Event, State>) => Protocol<Body, Frame, Event, State>;
75
+ export declare const jsonEvent: <const S extends Schema.Top>(schema: S) => Schema.fromJsonString<S>;
76
+ export * as Protocol from "./protocol";
77
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/route/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IACjD,sDAAsD;IACtD,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAA;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,CAAA;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,YAAY,CAAC,IAAI;IAChC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;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{ Schema } from "effect";
2
+ /**
3
+ * Construct a `Protocol` from its body and stream pieces:
4
+ *
5
+ * - `body.schema` infers the provider-native request body shape.
6
+ * - `body.from` ties the common `LLMRequest` to the provider body.
7
+ * - `stream.event` infers the decoded streaming event and the wire frame.
8
+ * - `stream.initial`, `stream.step`, and `stream.onHalt` infer the parser state.
9
+ *
10
+ * Provider implementations should usually call `Protocol.make({ ... })`
11
+ * without explicit type arguments; the schemas and parser functions are the
12
+ * source of truth. The constructor remains as the public seam for future
13
+ * cross-cutting concerns such as tracing or instrumentation.
14
+ */
15
+ export const make = (input) => input;
16
+ export const jsonEvent = (schema) => Schema.fromJsonString(schema);
17
+ export * as Protocol from "./protocol";
18
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/route/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAA;AAgE5C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,KAA0C,EACL,EAAE,CAAC,KAAK,CAAA;AAE/C,MAAM,CAAC,MAAM,SAAS,GAAG,CAA6B,MAAS,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AAEjG,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA"}
@@ -0,0 +1,34 @@
1
+ import { Effect } from "effect";
2
+ import { Headers, HttpClientRequest } from "effect/unstable/http";
3
+ import { type Framing as FramingDef } from "../framing";
4
+ import type { Transport, TransportPrepareInput } from "./index";
5
+ export type JsonRequestInput<Body> = TransportPrepareInput<Body>;
6
+ export interface JsonRequestParts<Body = unknown> {
7
+ readonly url: string;
8
+ readonly jsonBody: Body | Record<string, unknown>;
9
+ readonly bodyText: string;
10
+ readonly headers: Headers.Headers;
11
+ }
12
+ export interface HttpPrepared<Frame> {
13
+ readonly request: HttpClientRequest.HttpClientRequest;
14
+ readonly framing: FramingDef<Frame>;
15
+ }
16
+ export declare const jsonRequestParts: <Body>(input: JsonRequestInput<Body>) => Effect.Effect<{
17
+ url: string;
18
+ jsonBody: Record<string, unknown> | Body;
19
+ bodyText: string;
20
+ headers: Headers.Headers;
21
+ }, import("../..").LLMError, never>;
22
+ export interface HttpJsonInput<_Body, Frame> {
23
+ readonly framing: FramingDef<Frame>;
24
+ }
25
+ export type HttpJsonPatch<Body, Frame> = Partial<HttpJsonInput<Body, Frame>>;
26
+ export interface HttpJsonTransport<Body, Frame> extends Transport<Body, HttpPrepared<Frame>, Frame> {
27
+ readonly with: (patch: HttpJsonPatch<Body, Frame>) => HttpJsonTransport<Body, Frame>;
28
+ }
29
+ export declare const httpJson: <Body, Frame>(input: HttpJsonInput<Body, Frame>) => HttpJsonTransport<Body, Frame>;
30
+ export declare const sseJson: {
31
+ readonly id: "http-json/sse";
32
+ readonly with: <Body>() => HttpJsonTransport<Body, string>;
33
+ };
34
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/route/transport/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAGjE,OAAO,EAAW,KAAK,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAI/D,MAAM,MAAM,gBAAgB,CAAC,IAAI,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAA;AAEhE,MAAM,WAAW,gBAAgB,CAAC,IAAI,GAAG,OAAO;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAA;CAClC;AAED,MAAM,WAAW,YAAY,CAAC,KAAK;IACjC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,iBAAiB,CAAA;IACrD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;CACpC;AAkED,eAAO,MAAM,gBAAgB,GAAI,IAAI,EAAE,OAAO,gBAAgB,CAAC,IAAI,CAAC;;;;;mCAkBhE,CAAA;AAEJ,MAAM,WAAW,aAAa,CAAC,KAAK,EAAE,KAAK;IACzC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;CACpC;AAED,MAAM,MAAM,aAAa,CAAC,IAAI,EAAE,KAAK,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;AAE5E,MAAM,WAAW,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAE,SAAQ,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACjG,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;CACrF;AAED,eAAO,MAAM,QAAQ,GAAI,IAAI,EAAE,KAAK,EAAE,OAAO,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,KAAG,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAgCrG,CAAA;AAEF,eAAO,MAAM,OAAO;;oBAEX,IAAI;CACH,CAAA"}
@@ -0,0 +1,98 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { Headers } from "effect/unstable/http";
3
+ import { Auth } from "../auth";
4
+ import { render as renderEndpoint } from "../endpoint";
5
+ import { Framing } from "../framing";
6
+ import * as ProviderShared from "../../protocols/shared";
7
+ import { mergeJsonRecords } from "../../schema";
8
+ const applyQuery = (url, query) => {
9
+ if (!query)
10
+ return url;
11
+ const next = new URL(url);
12
+ Object.entries(query).forEach(([key, value]) => next.searchParams.set(key, value));
13
+ return next.toString();
14
+ };
15
+ const PROTOCOL_BODY_OVERLAY_DENYLIST = new Set([
16
+ "content",
17
+ "contents",
18
+ "frequencyPenalty",
19
+ "frequency_penalty",
20
+ "generationConfig",
21
+ "inferenceConfig",
22
+ "input",
23
+ "maxTokens",
24
+ "max_tokens",
25
+ "messages",
26
+ "model",
27
+ "presencePenalty",
28
+ "presence_penalty",
29
+ "responseFormat",
30
+ "response_format",
31
+ "seed",
32
+ "stop",
33
+ "stopSequences",
34
+ "stop_sequences",
35
+ "stream",
36
+ "streamOptions",
37
+ "stream_options",
38
+ "system",
39
+ "systemInstruction",
40
+ "system_instruction",
41
+ "temperature",
42
+ "thinking",
43
+ "toolChoice",
44
+ "toolConfig",
45
+ "tool_choice",
46
+ "tool_config",
47
+ "tools",
48
+ "topK",
49
+ "topP",
50
+ "top_k",
51
+ "top_p",
52
+ ]);
53
+ const forbiddenBodyOverlayKeys = (body) => Object.keys(body).filter((key) => PROTOCOL_BODY_OVERLAY_DENYLIST.has(key));
54
+ const bodyWithOverlay = (body, request, encodeBody) => Effect.gen(function* () {
55
+ if (request.http?.body === undefined)
56
+ return { jsonBody: body, bodyText: encodeBody(body) };
57
+ const forbiddenKeys = forbiddenBodyOverlayKeys(request.http.body);
58
+ if (forbiddenKeys.length > 0)
59
+ return yield* ProviderShared.invalidRequest(`http.body cannot overlay protocol-owned field(s): ${forbiddenKeys.join(", ")}`);
60
+ if (ProviderShared.isRecord(body)) {
61
+ const overlaid = mergeJsonRecords(body, request.http.body) ?? {};
62
+ return { jsonBody: overlaid, bodyText: ProviderShared.encodeJson(overlaid) };
63
+ }
64
+ return yield* ProviderShared.invalidRequest("http.body can only overlay JSON object request bodies");
65
+ });
66
+ export const jsonRequestParts = (input) => Effect.gen(function* () {
67
+ const url = applyQuery(renderEndpoint(input.endpoint, { request: input.request, body: input.body }).toString(), input.request.http?.query);
68
+ const body = yield* bodyWithOverlay(input.body, input.request, input.encodeBody);
69
+ const headers = yield* Auth.toEffect(input.auth)({
70
+ request: input.request,
71
+ method: "POST",
72
+ url,
73
+ body: body.bodyText,
74
+ headers: Headers.fromInput({
75
+ ...input.headers?.({ request: input.request }),
76
+ ...input.request.http?.headers,
77
+ }),
78
+ });
79
+ return { url, jsonBody: body.jsonBody, bodyText: body.bodyText, headers };
80
+ });
81
+ export const httpJson = (input) => ({
82
+ id: "http-json",
83
+ with: (patch) => httpJson({ ...input, ...patch }),
84
+ prepare: (prepareInput) => jsonRequestParts({
85
+ ...prepareInput,
86
+ }).pipe(Effect.map((parts) => ({
87
+ request: ProviderShared.jsonPost({ url: parts.url, body: parts.bodyText, headers: parts.headers }),
88
+ framing: input.framing,
89
+ }))),
90
+ frames: (prepared, request, runtime) => Stream.unwrap(runtime.http
91
+ .execute(prepared.request)
92
+ .pipe(Effect.map((response) => prepared.framing.frame(response.stream.pipe(Stream.mapError((error) => ProviderShared.eventError(`${request.model.provider}/${request.model.route.id}`, `Failed to read ${request.model.provider}/${request.model.route.id} stream`, ProviderShared.errorText(error)))))))),
93
+ });
94
+ export const sseJson = {
95
+ id: "http-json/sse",
96
+ with: () => httpJson({ framing: Framing.sse }),
97
+ };
98
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/route/transport/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,OAAO,EAAqB,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,OAAO,EAA8B,MAAM,YAAY,CAAA;AAEh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ClG,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,CAAC,CACJ;IACH,MAAM,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CACrC,MAAM,CAAC,MAAM,CACX,OAAO,CAAC,IAAI;SACT,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;SACzB,IAAI,CACH,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACtB,QAAQ,CAAC,OAAO,CAAC,KAAK,CACpB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAClB,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CACxB,cAAc,CAAC,UAAU,CACvB,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EACrD,kBAAkB,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAC3E,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAChC,CACF,CACF,CACF,CACF,CACF,CACJ;CACJ,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,EAAE,EAAE,eAAe;IACnB,IAAI,EAAE,GAAS,EAAE,CAAC,QAAQ,CAAe,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;CAC1D,CAAA"}
@@ -0,0 +1,28 @@
1
+ import type { Effect, Stream } from "effect";
2
+ import type { Endpoint } from "../endpoint";
3
+ import type { Auth } from "../auth";
4
+ import type { Interface as RequestExecutorInterface } from "../executor";
5
+ import type { Interface as WebSocketExecutorInterface } from "./websocket";
6
+ import type { LLMError, LLMRequest } from "../../schema";
7
+ export interface TransportRuntime {
8
+ readonly http: RequestExecutorInterface;
9
+ readonly webSocket?: WebSocketExecutorInterface;
10
+ }
11
+ export interface Transport<Body, Prepared, Frame> {
12
+ readonly id: string;
13
+ readonly prepare: (input: TransportPrepareInput<Body>) => Effect.Effect<Prepared, LLMError>;
14
+ readonly frames: (prepared: Prepared, request: LLMRequest, runtime: TransportRuntime) => Stream.Stream<Frame, LLMError>;
15
+ }
16
+ export interface TransportPrepareInput<Body> {
17
+ readonly body: Body;
18
+ readonly request: LLMRequest;
19
+ readonly endpoint: Endpoint<Body>;
20
+ readonly auth: Auth;
21
+ readonly encodeBody: (body: Body) => string;
22
+ readonly headers?: (input: {
23
+ readonly request: LLMRequest;
24
+ }) => Record<string, string>;
25
+ }
26
+ export * as HttpTransport from "./http";
27
+ export { WebSocketExecutor, WebSocketTransport } from "./websocket";
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/route/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,KAAK,EAAE,SAAS,IAAI,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,IAAI,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAExD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAA;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,0BAA0B,CAAA;CAChD;AAED,MAAM,WAAW,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC3F,QAAQ,CAAC,MAAM,EAAE,CACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,gBAAgB,KACtB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,qBAAqB,CAAC,IAAI;IACzC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;IACjC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAA;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;KAAE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvF;AAED,OAAO,KAAK,aAAa,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * as HttpTransport from "./http";
2
+ export { WebSocketExecutor, WebSocketTransport } from "./websocket";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/route/transport/index.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,aAAa,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { Context, Effect, Layer, Stream } from "effect";
2
+ import { Headers } from "effect/unstable/http";
3
+ import { LLMError } from "../../schema";
4
+ import type { Transport } from "./index";
5
+ export interface WebSocketRequest {
6
+ readonly url: string;
7
+ readonly headers: Headers.Headers;
8
+ }
9
+ export interface WebSocketConnection {
10
+ readonly sendText: (message: string) => Effect.Effect<void, LLMError>;
11
+ readonly messages: Stream.Stream<string | Uint8Array, LLMError>;
12
+ readonly close: Effect.Effect<void, never>;
13
+ }
14
+ export interface Interface {
15
+ readonly open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection, LLMError>;
16
+ }
17
+ declare const Service_base: Context.ServiceClass<Service, "@zyraxon/LLM/WebSocketExecutor", Interface>;
18
+ export declare class Service extends Service_base {
19
+ }
20
+ export declare const open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection, LLMError, never>;
21
+ export declare const layer: Layer.Layer<Service>;
22
+ export declare const fromWebSocket: (ws: globalThis.WebSocket, input: WebSocketRequest) => Effect.Effect<WebSocketConnection, LLMError>;
23
+ export declare const messageText: (message: string | Uint8Array, decoder: TextDecoder) => string;
24
+ export interface JsonPrepared {
25
+ readonly url: string;
26
+ readonly headers: Headers.Headers;
27
+ readonly message: string;
28
+ }
29
+ export interface JsonInput<Body, Message> {
30
+ readonly toMessage: (body: Body | Record<string, unknown>) => Effect.Effect<Message, LLMError>;
31
+ readonly encodeMessage: (message: Message) => string;
32
+ }
33
+ export type JsonPatch<Body, Message> = Partial<JsonInput<Body, Message>>;
34
+ export interface JsonTransport<Body, Message> extends Transport<Body, JsonPrepared, string> {
35
+ readonly with: (patch: JsonPatch<Body, Message>) => JsonTransport<Body, Message>;
36
+ }
37
+ export declare const json: <Body, Message>(input: JsonInput<Body, Message>) => JsonTransport<Body, Message>;
38
+ export declare const jsonTransport: {
39
+ readonly id: "websocket-json";
40
+ readonly with: <Body, Message>(input: JsonInput<Body, Message>) => JsonTransport<Body, Message>;
41
+ };
42
+ export declare const WebSocketExecutor: {
43
+ readonly Service: typeof Service;
44
+ readonly layer: Layer.Layer<Service, never, never>;
45
+ readonly open: (input: WebSocketRequest) => Effect.Effect<WebSocketConnection, LLMError, never>;
46
+ readonly fromWebSocket: (ws: globalThis.WebSocket, input: WebSocketRequest) => Effect.Effect<WebSocketConnection, LLMError>;
47
+ readonly messageText: (message: string | Uint8Array, decoder: TextDecoder) => string;
48
+ };
49
+ export declare const WebSocketTransport: {
50
+ readonly json: <Body, Message>(input: JsonInput<Body, Message>) => JsonTransport<Body, Message>;
51
+ readonly jsonTransport: {
52
+ readonly id: "websocket-json";
53
+ readonly with: <Body, Message>(input: JsonInput<Body, Message>) => JsonTransport<Body, Message>;
54
+ };
55
+ };
56
+ export {};
57
+ //# sourceMappingURL=websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/route/transport/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,OAAO,EAAE,MAAM,EAAE,KAAK,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAmB,MAAM,cAAc,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAA;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;CAC3C;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,CAAC,K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AC,IAAI,EAAE,OAAO,CAAC,KAAK,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;CACjF;AAED,eAAO,MAAM,IAAI,GAAI,IAAI,EAAE,OAAO,EAAE,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,KAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAoC/F,CAAA;AAEF,eAAO,MAAM,aAAa;;oBAtCL,IAAI,EAAE,OAAO,SAAS,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,KAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC;CAyCxF,CAAA;AAEV,eAAO,MAAM,iBAAiB;;;2BAhJF,gBAAgB;iCActC,UAAU,CAAC,SAAS,SACjB,gBAAgB,KACtB,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,QAAQ,CAAC;oCAiEV,MAAM,GAAG,UAAU,WAAW,WAAW;CAqEpE,CAAA;AAEV,eAAO,MAAM,kBAAkB;oBAnDV,IAAI,EAAE,OAAO,SAAS,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,KAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC;;;wBAA7E,IAAI,EAAE,OAAO,SAAS,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,KAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC;;CAsDxF,CAAA"}
@@ -0,0 +1,181 @@
1
+ import { Cause, Context, Effect, Layer, Queue, Stream } from "effect";
2
+ import { LLMError, TransportReason } from "../../schema";
3
+ import * as HttpTransport from "./http";
4
+ export class Service extends Context.Service()("@zyraxon/LLM/WebSocketExecutor") {
5
+ }
6
+ const transportError = (method, message, input = {}) => new LLMError({
7
+ module: "WebSocketExecutor",
8
+ method,
9
+ reason: new TransportReason({ message, url: input.url, kind: input.kind }),
10
+ });
11
+ const eventMessage = (event) => {
12
+ if ("message" in event && typeof event.message === "string")
13
+ return event.message;
14
+ return event.type;
15
+ };
16
+ const binaryMessage = (data) => {
17
+ if (data instanceof Uint8Array)
18
+ return data;
19
+ if (data instanceof ArrayBuffer)
20
+ return new Uint8Array(data);
21
+ if (ArrayBuffer.isView(data))
22
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
23
+ return undefined;
24
+ };
25
+ const waitOpen = (ws, input) => {
26
+ if (ws.readyState === globalThis.WebSocket.OPEN)
27
+ return Effect.void;
28
+ if (ws.readyState === globalThis.WebSocket.CLOSING || ws.readyState === globalThis.WebSocket.CLOSED) {
29
+ return Effect.fail(transportError("open", `WebSocket closed before opening (state ${ws.readyState})`, {
30
+ url: input.url,
31
+ kind: "open",
32
+ }));
33
+ }
34
+ return Effect.callback((resume, signal) => {
35
+ const cleanup = () => {
36
+ ws.removeEventListener("open", onOpen);
37
+ ws.removeEventListener("error", onError);
38
+ ws.removeEventListener("close", onClose);
39
+ signal.removeEventListener("abort", onAbort);
40
+ };
41
+ const onAbort = () => {
42
+ cleanup();
43
+ if (ws.readyState !== globalThis.WebSocket.CLOSED && ws.readyState !== globalThis.WebSocket.CLOSING)
44
+ ws.close(1000);
45
+ };
46
+ const onOpen = () => {
47
+ cleanup();
48
+ resume(Effect.void);
49
+ };
50
+ const onError = (event) => {
51
+ cleanup();
52
+ resume(Effect.fail(transportError("open", `Failed to open WebSocket: ${eventMessage(event)}`, { url: input.url, kind: "open" })));
53
+ };
54
+ const onClose = (event) => {
55
+ cleanup();
56
+ resume(Effect.fail(transportError("open", `WebSocket closed before opening with code ${event.code}`, {
57
+ url: input.url,
58
+ kind: "open",
59
+ })));
60
+ };
61
+ ws.addEventListener("open", onOpen, { once: true });
62
+ ws.addEventListener("error", onError, { once: true });
63
+ ws.addEventListener("close", onClose, { once: true });
64
+ signal.addEventListener("abort", onAbort, { once: true });
65
+ });
66
+ };
67
+ const webSocketUrl = (value) => Effect.try({
68
+ try: () => {
69
+ const url = new URL(value);
70
+ if (url.protocol === "https:") {
71
+ url.protocol = "wss:";
72
+ return url.toString();
73
+ }
74
+ if (url.protocol === "http:") {
75
+ url.protocol = "ws:";
76
+ return url.toString();
77
+ }
78
+ throw new Error(`Unsupported WebSocket URL protocol ${url.protocol}`);
79
+ },
80
+ catch: (error) => transportError("prepare", error instanceof Error ? error.message : "Invalid WebSocket URL", {
81
+ url: value,
82
+ kind: "websocket",
83
+ }),
84
+ });
85
+ export const open = (input) => Effect.try({
86
+ try: () => new globalThis.WebSocket(input.url, { headers: input.headers }),
87
+ catch: (error) => transportError("open", error instanceof Error ? error.message : "Failed to construct WebSocket", {
88
+ url: input.url,
89
+ kind: "open",
90
+ }),
91
+ }).pipe(Effect.flatMap((ws) => fromWebSocket(ws, input)));
92
+ export const layer = Layer.succeed(Service, Service.of({ open }));
93
+ export const fromWebSocket = (ws, input) => Effect.gen(function* () {
94
+ yield* waitOpen(ws, input);
95
+ const messages = yield* Queue.bounded(128);
96
+ const onMessage = (event) => {
97
+ if (typeof event.data === "string")
98
+ return Queue.offerUnsafe(messages, event.data);
99
+ const binary = binaryMessage(event.data);
100
+ if (binary)
101
+ return Queue.offerUnsafe(messages, binary);
102
+ Queue.failCauseUnsafe(messages, Cause.fail(transportError("message", "Unsupported WebSocket message payload", { url: input.url, kind: "message" })));
103
+ };
104
+ const onError = (event) => {
105
+ Queue.failCauseUnsafe(messages, Cause.fail(transportError("message", `WebSocket error: ${eventMessage(event)}`, { url: input.url, kind: "message" })));
106
+ };
107
+ const onClose = (event) => {
108
+ if (event.code === 1000 || event.code === 1005)
109
+ return Queue.endUnsafe(messages);
110
+ Queue.failCauseUnsafe(messages, Cause.fail(transportError("message", `WebSocket closed with code ${event.code}`, { url: input.url, kind: "close" })));
111
+ };
112
+ const cleanup = Effect.sync(() => {
113
+ ws.removeEventListener("message", onMessage);
114
+ ws.removeEventListener("error", onError);
115
+ ws.removeEventListener("close", onClose);
116
+ }).pipe(Effect.andThen(Queue.shutdown(messages)));
117
+ ws.addEventListener("message", onMessage);
118
+ ws.addEventListener("error", onError);
119
+ ws.addEventListener("close", onClose);
120
+ return {
121
+ sendText: (message) => Effect.try({
122
+ try: () => ws.send(message),
123
+ catch: (error) => transportError("sendText", error instanceof Error ? error.message : "Failed to send WebSocket message", {
124
+ url: input.url,
125
+ kind: "write",
126
+ }),
127
+ }),
128
+ messages: Stream.fromQueue(messages),
129
+ close: cleanup.pipe(Effect.andThen(Effect.sync(() => {
130
+ if (ws.readyState === globalThis.WebSocket.CLOSED || ws.readyState === globalThis.WebSocket.CLOSING)
131
+ return;
132
+ ws.close(1000);
133
+ }))),
134
+ };
135
+ });
136
+ export const messageText = (message, decoder) => typeof message === "string" ? message : decoder.decode(message);
137
+ export const json = (input) => ({
138
+ id: "websocket-json",
139
+ with: (patch) => json({ ...input, ...patch }),
140
+ prepare: (prepareInput) => Effect.gen(function* () {
141
+ const parts = yield* HttpTransport.jsonRequestParts({
142
+ ...prepareInput,
143
+ });
144
+ return {
145
+ url: yield* webSocketUrl(parts.url),
146
+ headers: parts.headers,
147
+ message: input.encodeMessage(yield* input.toMessage(parts.jsonBody)),
148
+ };
149
+ }),
150
+ frames: (prepared, _request, runtime) => {
151
+ const webSocket = runtime.webSocket;
152
+ if (!webSocket) {
153
+ return Stream.fail(transportError("json", "WebSocket JSON transport requires WebSocketExecutor.Service", {
154
+ url: prepared.url,
155
+ kind: "websocket",
156
+ }));
157
+ }
158
+ const decoder = new TextDecoder();
159
+ return Stream.unwrap(Effect.gen(function* () {
160
+ const connection = yield* Effect.acquireRelease(webSocket.open({ url: prepared.url, headers: prepared.headers }), (connection) => connection.close);
161
+ yield* connection.sendText(prepared.message);
162
+ return connection.messages.pipe(Stream.map((message) => messageText(message, decoder)));
163
+ }));
164
+ },
165
+ });
166
+ export const jsonTransport = {
167
+ id: "websocket-json",
168
+ with: json,
169
+ };
170
+ export const WebSocketExecutor = {
171
+ Service,
172
+ layer,
173
+ open,
174
+ fromWebSocket,
175
+ messageText,
176
+ };
177
+ export const WebSocketTransport = {
178
+ json,
179
+ jsonTransport,
180
+ };
181
+ //# sourceMappingURL=websocket.js.map
@@ -0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