@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,156 @@
1
+ import { Effect } from "effect";
2
+ import { LLMError, LLMEvent, type ProviderMetadata } from "../../schema";
3
+ import { type ToolAccumulator } from "../shared";
4
+ type StreamKey = string | number;
5
+ /**
6
+ * One pending streamed tool call. Providers emit the tool identity and JSON
7
+ * argument text across separate chunks; `input` is the raw JSON string collected
8
+ * so far, not the parsed object.
9
+ */
10
+ export interface PendingTool extends ToolAccumulator {
11
+ readonly providerExecuted?: boolean;
12
+ readonly providerMetadata?: ProviderMetadata;
13
+ }
14
+ /**
15
+ * Sparse parser state keyed by the provider's stream-local tool identifier.
16
+ *
17
+ * This key is not the final tool-call id (`call_...`). It is the id/index the
18
+ * provider uses while streaming a partial call: OpenAI Chat / Anthropic /
19
+ * Bedrock use numeric content indexes, while OpenAI Responses uses string
20
+ * `item_id`s. The generic keeps each protocol internally consistent.
21
+ */
22
+ export type State<K extends StreamKey> = Partial<Record<K, PendingTool>>;
23
+ /**
24
+ * Result of adding argument text to one pending tool call. It returns both the
25
+ * next `tools` state and the updated `tool` because parsers often need the
26
+ * current id/name immediately. `events` contains lifecycle and delta events
27
+ * produced by the append; metadata-only deltas update identity without output.
28
+ */
29
+ export interface AppendOutcome<K extends StreamKey> {
30
+ readonly tools: State<K>;
31
+ readonly tool: PendingTool;
32
+ readonly events: ReadonlyArray<LLMEvent>;
33
+ }
34
+ /** Create empty accumulator state for one provider stream. */
35
+ export declare const empty: <K extends StreamKey>() => State<K>;
36
+ export declare const isError: <K extends StreamKey>(result: AppendOutcome<K> | LLMError) => result is LLMError;
37
+ /**
38
+ * Register a tool call whose start event arrived before any argument deltas.
39
+ * Used by Anthropic `content_block_start`, Bedrock `contentBlockStart`, and
40
+ * OpenAI Responses `response.output_item.added`.
41
+ */
42
+ export declare const start: <K extends StreamKey>(tools: State<K>, key: K, tool: Omit<PendingTool, "input"> & {
43
+ readonly input?: string;
44
+ }) => Partial<Record<K, PendingTool>>;
45
+ /**
46
+ * Append a streamed argument delta, starting the tool if this provider encodes
47
+ * identity on the first delta instead of a separate start event. OpenAI Chat has
48
+ * this shape: `tool_calls[].index` is the stream key, and `id` / `name` may only
49
+ * appear on the first delta for that index.
50
+ */
51
+ export declare const appendOrStart: <K extends StreamKey>(route: string, tools: State<K>, key: K, delta: {
52
+ readonly id?: string;
53
+ readonly name?: string;
54
+ readonly text: string;
55
+ }, missingToolMessage: string) => AppendOutcome<K> | LLMError;
56
+ /**
57
+ * Append argument text to a tool that must already have been started. This keeps
58
+ * protocols honest when their stream grammar promises a start event before any
59
+ * argument delta.
60
+ */
61
+ export declare const appendExisting: <K extends StreamKey>(route: string, tools: State<K>, key: K, text: string, missingToolMessage: string) => AppendOutcome<K> | LLMError;
62
+ /**
63
+ * Finalize one pending tool call: parse the accumulated raw JSON, remove it
64
+ * from state, and return the optional public `tool-call` event. Missing keys are
65
+ * a no-op because some providers emit stop events for non-tool content blocks.
66
+ */
67
+ export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K) => Effect.Effect<{
68
+ tools: Partial<Record<K, PendingTool>>;
69
+ events?: undefined;
70
+ } | {
71
+ tools: Partial<Record<K, PendingTool>>;
72
+ events: ({
73
+ readonly type: "tool-input-end";
74
+ readonly id: string;
75
+ readonly name: string;
76
+ readonly providerMetadata?: {
77
+ readonly [x: string]: {
78
+ readonly [x: string]: unknown;
79
+ };
80
+ };
81
+ } | {
82
+ readonly type: "tool-call";
83
+ readonly id: string;
84
+ readonly name: string;
85
+ readonly input: unknown;
86
+ readonly providerExecuted?: boolean;
87
+ readonly providerMetadata?: {
88
+ readonly [x: string]: {
89
+ readonly [x: string]: unknown;
90
+ };
91
+ };
92
+ })[];
93
+ }, LLMError, never>;
94
+ /**
95
+ * Finalize one pending tool call with an authoritative final input string.
96
+ * OpenAI Responses can send accumulated deltas and then repeat the completed
97
+ * arguments on `response.output_item.done`; the final value wins.
98
+ */
99
+ export declare const finishWithInput: <K extends StreamKey>(route: string, tools: State<K>, key: K, input: string) => Effect.Effect<{
100
+ tools: Partial<Record<K, PendingTool>>;
101
+ events?: undefined;
102
+ } | {
103
+ tools: Partial<Record<K, PendingTool>>;
104
+ events: ({
105
+ readonly type: "tool-input-end";
106
+ readonly id: string;
107
+ readonly name: string;
108
+ readonly providerMetadata?: {
109
+ readonly [x: string]: {
110
+ readonly [x: string]: unknown;
111
+ };
112
+ };
113
+ } | {
114
+ readonly type: "tool-call";
115
+ readonly id: string;
116
+ readonly name: string;
117
+ readonly input: unknown;
118
+ readonly providerExecuted?: boolean;
119
+ readonly providerMetadata?: {
120
+ readonly [x: string]: {
121
+ readonly [x: string]: unknown;
122
+ };
123
+ };
124
+ })[];
125
+ }, LLMError, never>;
126
+ /**
127
+ * Finalize every pending tool call at once. OpenAI Chat has this shape: it does
128
+ * not emit per-tool stop events, so all accumulated calls finish when the choice
129
+ * receives a terminal `finish_reason`.
130
+ */
131
+ export declare const finishAll: <K extends StreamKey>(route: string, tools: State<K>) => Effect.Effect<{
132
+ tools: Partial<Record<K, PendingTool>>;
133
+ events: ({
134
+ readonly type: "tool-input-end";
135
+ readonly id: string;
136
+ readonly name: string;
137
+ readonly providerMetadata?: {
138
+ readonly [x: string]: {
139
+ readonly [x: string]: unknown;
140
+ };
141
+ };
142
+ } | {
143
+ readonly type: "tool-call";
144
+ readonly id: string;
145
+ readonly name: string;
146
+ readonly input: unknown;
147
+ readonly providerExecuted?: boolean;
148
+ readonly providerMetadata?: {
149
+ readonly [x: string]: {
150
+ readonly [x: string]: unknown;
151
+ };
152
+ };
153
+ })[];
154
+ }, LLMError, never>;
155
+ export * as ToolStream from "./tool-stream";
156
+ //# sourceMappingURL=tool-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-stream.d.ts","sourceRoot":"","sources":["../../../src/protocols/utils/tool-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,gBAAgB,EAAiB,MAAM,cAAc,CAAA;AACvF,OAAO,EAA8B,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAE5E,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAA;AAEhC;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;IACnC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CAC7C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAA;AAExE;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,SAAS;IAChD,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACxB,QAAQ,CAAC,IAAI,EAA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,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;mBAW9E,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,SAAS,EAAE,OAAO,MAAM,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;mBAWtG,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,SAAS,EAAE,OAAO,MAAM,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;mBAgBzE,CAAA;AAEJ,OAAO,KAAK,UAAU,MAAM,eAAe,CAAA"}
@@ -0,0 +1,137 @@
1
+ import { Effect } from "effect";
2
+ import { LLMError, LLMEvent } from "../../schema";
3
+ import { eventError, parseToolInput } from "../shared";
4
+ /** Create empty accumulator state for one provider stream. */
5
+ export const empty = () => ({});
6
+ const withTool = (tools, key, tool) => {
7
+ return { ...tools, [key]: tool };
8
+ };
9
+ const withoutTool = (tools, key) => {
10
+ const next = { ...tools };
11
+ delete next[key];
12
+ return next;
13
+ };
14
+ const inputStart = (tool) => LLMEvent.toolInputStart({
15
+ id: tool.id,
16
+ name: tool.name,
17
+ providerMetadata: tool.providerMetadata,
18
+ });
19
+ const inputDelta = (tool, text) => LLMEvent.toolInputDelta({
20
+ id: tool.id,
21
+ name: tool.name,
22
+ text,
23
+ });
24
+ const toolCall = (route, tool, inputOverride) => parseToolInput(route, tool.name, inputOverride ?? tool.input).pipe(Effect.map((input) => LLMEvent.toolCall({
25
+ id: tool.id,
26
+ name: tool.name,
27
+ input,
28
+ providerExecuted: tool.providerExecuted ? true : undefined,
29
+ providerMetadata: tool.providerMetadata,
30
+ })));
31
+ /** Store the updated tool and produce the optional public delta event. */
32
+ const appendTool = (tools, key, tool, text) => {
33
+ const events = [];
34
+ if (!tools[key])
35
+ events.push(inputStart(tool));
36
+ if (text.length > 0)
37
+ events.push(inputDelta(tool, text));
38
+ return {
39
+ tools: withTool(tools, key, tool),
40
+ tool,
41
+ events,
42
+ };
43
+ };
44
+ export const isError = (result) => result instanceof LLMError;
45
+ /**
46
+ * Register a tool call whose start event arrived before any argument deltas.
47
+ * Used by Anthropic `content_block_start`, Bedrock `contentBlockStart`, and
48
+ * OpenAI Responses `response.output_item.added`.
49
+ */
50
+ export const start = (tools, key, tool) => withTool(tools, key, { ...tool, input: tool.input ?? "" });
51
+ /**
52
+ * Append a streamed argument delta, starting the tool if this provider encodes
53
+ * identity on the first delta instead of a separate start event. OpenAI Chat has
54
+ * this shape: `tool_calls[].index` is the stream key, and `id` / `name` may only
55
+ * appear on the first delta for that index.
56
+ */
57
+ export const appendOrStart = (route, tools, key, delta, missingToolMessage) => {
58
+ const current = tools[key];
59
+ const id = delta.id ?? current?.id;
60
+ const name = delta.name ?? current?.name;
61
+ if (!id || !name)
62
+ return eventError(route, missingToolMessage);
63
+ const tool = {
64
+ id,
65
+ name,
66
+ input: `${current?.input ?? ""}${delta.text}`,
67
+ providerExecuted: current?.providerExecuted,
68
+ providerMetadata: current?.providerMetadata,
69
+ };
70
+ if (current && delta.text.length === 0 && current.id === id && current.name === name)
71
+ return { tools, tool: current, events: [] };
72
+ return appendTool(tools, key, tool, delta.text);
73
+ };
74
+ /**
75
+ * Append argument text to a tool that must already have been started. This keeps
76
+ * protocols honest when their stream grammar promises a start event before any
77
+ * argument delta.
78
+ */
79
+ export const appendExisting = (route, tools, key, text, missingToolMessage) => {
80
+ const current = tools[key];
81
+ if (!current)
82
+ return eventError(route, missingToolMessage);
83
+ if (text.length === 0)
84
+ return { tools, tool: current, events: [] };
85
+ return appendTool(tools, key, { ...current, input: `${current.input}${text}` }, text);
86
+ };
87
+ /**
88
+ * Finalize one pending tool call: parse the accumulated raw JSON, remove it
89
+ * from state, and return the optional public `tool-call` event. Missing keys are
90
+ * a no-op because some providers emit stop events for non-tool content blocks.
91
+ */
92
+ export const finish = (route, tools, key) => Effect.gen(function* () {
93
+ const tool = tools[key];
94
+ if (!tool)
95
+ return { tools };
96
+ return {
97
+ tools: withoutTool(tools, key),
98
+ events: [
99
+ LLMEvent.toolInputEnd({ id: tool.id, name: tool.name, providerMetadata: tool.providerMetadata }),
100
+ yield* toolCall(route, tool),
101
+ ],
102
+ };
103
+ });
104
+ /**
105
+ * Finalize one pending tool call with an authoritative final input string.
106
+ * OpenAI Responses can send accumulated deltas and then repeat the completed
107
+ * arguments on `response.output_item.done`; the final value wins.
108
+ */
109
+ export const finishWithInput = (route, tools, key, input) => Effect.gen(function* () {
110
+ const tool = tools[key];
111
+ if (!tool)
112
+ return { tools };
113
+ return {
114
+ tools: withoutTool(tools, key),
115
+ events: [
116
+ LLMEvent.toolInputEnd({ id: tool.id, name: tool.name, providerMetadata: tool.providerMetadata }),
117
+ yield* toolCall(route, tool, input),
118
+ ],
119
+ };
120
+ });
121
+ /**
122
+ * Finalize every pending tool call at once. OpenAI Chat has this shape: it does
123
+ * not emit per-tool stop events, so all accumulated calls finish when the choice
124
+ * receives a terminal `finish_reason`.
125
+ */
126
+ export const finishAll = (route, tools) => Effect.gen(function* () {
127
+ const pending = Object.values(tools).filter((tool) => tool !== undefined);
128
+ return {
129
+ tools: empty(),
130
+ events: yield* Effect.forEach(pending, (tool) => toolCall(route, tool).pipe(Effect.map((call) => [
131
+ LLMEvent.toolInputEnd({ id: tool.id, name: tool.name, providerMetadata: tool.providerMetadata }),
132
+ call,
133
+ ]))).pipe(Effect.map((events) => events.flat())),
134
+ };
135
+ });
136
+ export * as ToolStream from "./tool-stream";
137
+ //# sourceMappingURL=tool-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-stream.js","sourceRoot":"","sources":["../../../src/protocols/utils/tool-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ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AE,CAAC;YAChG,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;SACpC;KACF,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAsB,KAAa,EAAE,KAAe,EAAE,EAAE,CAC/E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAA0B,KAAK,CAAC,CAAC,MAAM,CAClE,CAAC,IAAI,EAAuB,EAAE,CAAC,IAAI,KAAK,SAAS,CAClD,CAAA;IACD,OAAO;QACL,KAAK,EAAE,KAAK,EAAK;QACjB,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAC9C,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CACxB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACnB,QAAQ,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAChG,IAAI;SACL,CAAC,CACH,CACF,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;KAC9C,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ,OAAO,KAAK,UAAU,MAAM,eAAe,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const isContextOverflow: (message: string) => boolean;
2
+ export declare const isContextOverflowFailure: (failure: unknown) => boolean;
3
+ //# sourceMappingURL=provider-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-error.d.ts","sourceRoot":"","sources":["../src/provider-error.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,YAC+D,CAAA;AAEhH,eAAO,MAAM,wBAAwB,GAAI,SAAS,OAAO,YAGoC,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { Schema } from "effect";
2
+ import { LLMError, ProviderErrorEvent } from "./schema";
3
+ const patterns = [
4
+ /prompt is too long/i,
5
+ /input is too long for requested model/i,
6
+ /exceeds the context window/i,
7
+ /input token count.*exceeds the maximum/i,
8
+ /tokens in request more than max tokens allowed/i,
9
+ /maximum prompt length is \d+/i,
10
+ /reduce the length of the messages/i,
11
+ /maximum context length is \d+ tokens/i,
12
+ /exceeds the limit of \d+/i,
13
+ /exceeds the available context size/i,
14
+ /greater than the context length/i,
15
+ /context window exceeds limit/i,
16
+ /exceeded model token limit/i,
17
+ /context[_ ]length[_ ]exceeded/i,
18
+ /request entity too large/i,
19
+ /context length is only \d+ tokens/i,
20
+ /input length.*exceeds.*context length/i,
21
+ /prompt too long; exceeded (?:max )?context length/i,
22
+ /too large for model with \d+ maximum context length/i,
23
+ /model_context_window_exceeded/i,
24
+ ];
25
+ export const isContextOverflow = (message) => patterns.some((pattern) => pattern.test(message)) || /^4(00|13)\s*(status code)?\s*\(no body\)/i.test(message);
26
+ export const isContextOverflowFailure = (failure) => failure instanceof LLMError
27
+ ? failure.reason._tag === "InvalidRequest" && failure.reason.classification === "context-overflow"
28
+ : Schema.is(ProviderErrorEvent)(failure) && failure.classification === "context-overflow";
29
+ //# sourceMappingURL=provider-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-error.js","sourceRoot":"","sources":["../src/provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAEvD,MAAM,QAAQ,GAAG;IACf,qBAAqB;IACrB,wCAAwC;IACxC,6BAA6B;IAC7B,yCAAyC;IACzC,iDAAiD;IACjD,+BAA+B;IAC/B,oCAAoC;IACpC,uCAAuC;IACvC,2BAA2B;IAC3B,qCAAqC;IACrC,kCAAkC;IAClC,+BAA+B;IAC/B,6BAA6B;IAC7B,gCAAgC;IAChC,2BAA2B;IAC3B,oCAAoC;IACpC,wCAAwC;IACxC,oDAAoD;IACpD,sDAAsD;IACtD,gCAAgC;CACjC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,EAAE,CACnD,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,2CAA2C,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAEhH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAgB,EAAE,EAAE,CAC3D,OAAO,YAAY,QAAQ;IACzB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,KAAK,kBAAkB;IAClG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,cAAc,KAAK,kBAAkB,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { Model, ModelID, ProviderID } from "./schema";
2
+ export type ModelOptions = Pick<Model.Input, "defaults" | "compatibility">;
3
+ /**
4
+ * Advanced structural provider definition helper. Built-in providers should
5
+ * prefer explicit `configure(options).model(id)` facades so deployment config is
6
+ * chosen before model selection. The optional `apis` map remains for external
7
+ * structural providers that expose multiple route selectors behind one provider.
8
+ */
9
+ export type ModelFactory<Options extends ModelOptions = ModelOptions> = (id: string | ModelID, options?: Options) => Model;
10
+ type AnyModelFactory = (...args: never[]) => Model;
11
+ export interface Definition<Factory extends AnyModelFactory = ModelFactory> {
12
+ readonly id: ProviderID;
13
+ readonly model: Factory;
14
+ readonly apis?: Record<string, AnyModelFactory>;
15
+ }
16
+ type DefinitionShape = {
17
+ readonly id: ProviderID;
18
+ readonly model: (...args: never[]) => Model;
19
+ readonly apis?: Record<string, (...args: never[]) => Model>;
20
+ };
21
+ type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>;
22
+ export declare const make: <DefinitionType extends DefinitionShape>(definition: NoExtraFields<DefinitionType, DefinitionShape>) => NoExtraFields<DefinitionType, DefinitionShape>;
23
+ export * as Provider from "./provider";
24
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe,CAAC,CAAA;AAE1E;;;;;GAKG;AACH,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,YAAY,GAAG,YAAY,IAAI,CACtE,EAAE,EAAE,MAAM,GAAG,OAAO,EACpB,OAAO,CAAC,EAAE,OAAO,KACd,KAAK,CAAA;AAEV,KAAK,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAA;AAElD,MAAM,WAAW,UAAU,CAAC,OAAO,SAAS,eAAe,GAAG,YAAY;IACxE,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAChD;AAED,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAA;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC,CAAA;CAC5D,CAAA;AAED,KAAK,aAAa,CAAC,KAAK,EAAE,KAAK,IAAI,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,EAAE,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;AAE3F,eAAO,MAAM,IAAI,GAAI,cAAc,SAAS,eAAe,EACzD,YAAY,aAAa,CAAC,cAAc,EAAE,eAAe,CAAC,mDAC7C,CAAA;AAEf,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ export const make = (definition) => definition;
2
+ export * as Provider from "./provider";
3
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,UAA0D,EAC1D,EAAE,CAAC,UAAU,CAAA;AAEf,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA"}
@@ -0,0 +1,142 @@
1
+ import type { RouteDefaultsInput } from "../route/client";
2
+ import { type ModelID } from "../schema";
3
+ import type { BedrockCredentials } from "../protocols/bedrock-converse";
4
+ export declare const id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
5
+ export type Config = RouteDefaultsInput & {
6
+ readonly apiKey?: string;
7
+ readonly headers?: Record<string, string>;
8
+ readonly credentials?: BedrockCredentials;
9
+ /** AWS region. Defaults to `us-east-1` when neither this nor `credentials.region` is set. */
10
+ readonly region?: string;
11
+ /** Override the computed `https://bedrock-runtime.<region>.amazonaws.com` URL. */
12
+ readonly baseURL?: string;
13
+ };
14
+ export declare const routes: import("../route").Route<{
15
+ readonly modelId: string;
16
+ readonly messages: readonly ({
17
+ readonly role: "user";
18
+ readonly content: readonly ({
19
+ readonly cachePoint: {
20
+ readonly type: "default";
21
+ readonly ttl?: "1h" | "5m";
22
+ };
23
+ } | {
24
+ readonly image: {
25
+ readonly format: "png" | "jpeg" | "gif" | "webp";
26
+ readonly source: {
27
+ readonly bytes: string;
28
+ };
29
+ };
30
+ } | {
31
+ readonly document: {
32
+ readonly format: "pdf" | "csv" | "doc" | "docx" | "xls" | "xlsx" | "html" | "txt" | "md";
33
+ readonly name: string;
34
+ readonly source: {
35
+ readonly bytes: string;
36
+ };
37
+ };
38
+ } | {
39
+ readonly text: string;
40
+ } | {
41
+ readonly toolResult: {
42
+ readonly toolUseId: string;
43
+ readonly content: readonly ({
44
+ readonly image: {
45
+ readonly format: "png" | "jpeg" | "gif" | "webp";
46
+ readonly source: {
47
+ readonly bytes: string;
48
+ };
49
+ };
50
+ } | {
51
+ readonly text: string;
52
+ } | {
53
+ readonly json: unknown;
54
+ })[];
55
+ readonly status?: "error" | "success";
56
+ };
57
+ })[];
58
+ } | {
59
+ readonly role: "assistant";
60
+ readonly content: readonly ({
61
+ readonly cachePoint: {
62
+ readonly type: "default";
63
+ readonly ttl?: "1h" | "5m";
64
+ };
65
+ } | {
66
+ readonly text: string;
67
+ } | {
68
+ readonly reasoningContent: {
69
+ readonly reasoningText?: {
70
+ readonly text: string;
71
+ readonly signature?: string;
72
+ };
73
+ };
74
+ } | {
75
+ readonly toolUse: {
76
+ readonly toolUseId: string;
77
+ readonly name: string;
78
+ readonly input: unknown;
79
+ };
80
+ })[];
81
+ })[];
82
+ readonly system?: readonly ({
83
+ readonly cachePoint: {
84
+ readonly type: "default";
85
+ readonly ttl?: "1h" | "5m";
86
+ };
87
+ } | {
88
+ readonly text: string;
89
+ })[];
90
+ readonly inferenceConfig?: {
91
+ readonly maxTokens?: number;
92
+ readonly temperature?: number;
93
+ readonly topP?: number;
94
+ readonly stopSequences?: readonly string[];
95
+ };
96
+ readonly toolConfig?: {
97
+ readonly tools: readonly ({
98
+ readonly cachePoint: {
99
+ readonly type: "default";
100
+ readonly ttl?: "1h" | "5m";
101
+ };
102
+ } | {
103
+ readonly toolSpec: {
104
+ readonly name: string;
105
+ readonly description: string;
106
+ readonly inputSchema: {
107
+ readonly json: {
108
+ readonly [x: string]: unknown;
109
+ };
110
+ };
111
+ };
112
+ })[];
113
+ readonly toolChoice?: {
114
+ readonly auto: {};
115
+ } | {
116
+ readonly any: {};
117
+ } | {
118
+ readonly tool: {
119
+ readonly name: string;
120
+ };
121
+ };
122
+ };
123
+ readonly additionalModelRequestFields?: {
124
+ readonly [x: string]: unknown;
125
+ };
126
+ }, import("../route/transport/http").HttpPrepared<object>>[];
127
+ export declare const configure: (input?: Config) => {
128
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
129
+ model: (modelID: string | ModelID) => import("..").Model;
130
+ configure: (input?: Config) => /*elided*/ any;
131
+ };
132
+ export declare const provider: {
133
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
134
+ model: (modelID: string | ModelID) => import("..").Model;
135
+ configure: (input?: Config) => {
136
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
137
+ model: (modelID: string | ModelID) => import("..").Model;
138
+ configure: /*elided*/ any;
139
+ };
140
+ };
141
+ export declare const model: (modelID: string | ModelID) => import("..").Model;
142
+ //# sourceMappingURL=amazon-bedrock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amazon-bedrock.d.ts","sourceRoot":"","sources":["../../src/providers/amazon-bedrock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,WAAW,CAAA;AAEpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAEvE,eAAO,MAAM,EAAE,yDAAoC,CAAA;AAEnD,MAAM,MAAM,MAAM,GAAG,kBAAkB,GAAG;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAA;IACzC,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AACD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4DAA0B,CAAA;AAe7C,eAAO,MAAM,SAAS,GAAI,QAAO,MAAW;;qBAIvB,MAAM,GAAG,OAAO;wBAJJ,MAAM;CAOtC,CAAA;AAED,eAAO,MAAM,QAAQ;;qBALA,MAAM,GAAG,OAAO;wBAJJ,MAAM;;yBAIlB,MAAM,GAAG,OAAO;;;CAKF,CAAA;AACnC,eAAO,MAAM,KAAK,YANG,MAAM,GAAG,OAAO,uBAMF,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { Auth } from "../route/auth";
2
+ import { ProviderID } from "../schema";
3
+ import * as BedrockConverse from "../protocols/bedrock-converse";
4
+ export const id = ProviderID.make("amazon-bedrock");
5
+ export const routes = [BedrockConverse.route];
6
+ const bedrockBaseURL = (region) => `https://bedrock-runtime.${region}.amazonaws.com`;
7
+ const configuredRoute = (input) => {
8
+ const { apiKey, credentials, region, baseURL, ...rest } = input;
9
+ const resolvedRegion = region ?? credentials?.region ?? "us-east-1";
10
+ return BedrockConverse.route.with({
11
+ ...rest,
12
+ provider: id,
13
+ endpoint: { baseURL: baseURL ?? bedrockBaseURL(resolvedRegion) },
14
+ auth: apiKey === undefined ? BedrockConverse.sigV4Auth(credentials) : Auth.bearer(apiKey),
15
+ });
16
+ };
17
+ export const configure = (input = {}) => {
18
+ const route = configuredRoute(input);
19
+ return {
20
+ id,
21
+ model: (modelID) => route.model({ id: modelID }),
22
+ configure,
23
+ };
24
+ };
25
+ export const provider = configure();
26
+ export const model = provider.model;
27
+ //# sourceMappingURL=amazon-bedrock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amazon-bedrock.js","sourceRoot":"","sources":["../../src/providers/amazon-bedrock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAA;AACpD,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAA;AAGhE,MAAM,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;AAWnD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;AAE7C,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,2BAA2B,MAAM,gBAAgB,CAAA;AAE5F,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,EAAE;IACxC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAA;IAC/D,MAAM,cAAc,GAAG,MAAM,IAAI,WAAW,EAAE,MAAM,IAAI,WAAW,CAAA;IACnE,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC;QAChC,GAAG,IAAI;QACP,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,cAAc,CAAC,cAAc,CAAC,EAAE;QAChE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;KAC1F,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAE,EAAE,EAAE;IAC9C,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IACpC,OAAO;QACL,EAAE;QACF,KAAK,EAAE,CAAC,OAAyB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;QAClE,SAAS;KACV,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAA;AACnC,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { RouteDefaultsInput } from "../route/client";
2
+ import type { ProviderAuthOption } from "../route/auth-options";
3
+ import { type ModelID } from "../schema";
4
+ export declare const id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
5
+ export declare const routes: import("../route").Route<unknown, import("../route/transport/http").HttpPrepared<string>>[];
6
+ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
7
+ readonly baseURL?: string;
8
+ };
9
+ export declare const configure: (input?: Config) => {
10
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
11
+ model: (modelID: string | ModelID) => import("..").Model;
12
+ configure: (input?: Config) => /*elided*/ any;
13
+ };
14
+ export declare const provider: {
15
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
16
+ model: (modelID: string | ModelID) => import("..").Model;
17
+ configure: (input?: Config) => {
18
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
19
+ model: (modelID: string | ModelID) => import("..").Model;
20
+ configure: /*elided*/ any;
21
+ };
22
+ };
23
+ export declare const model: (modelID: string | ModelID) => import("..").Model;
24
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,WAAW,CAAA;AAGpD,eAAO,MAAM,EAAE,yDAA+B,CAAA;AAE9C,eAAO,MAAM,MAAM,6FAA4B,CAAA;AAE/C,MAAM,MAAM,MAAM,GAAG,kBAAkB,GAAG,kBAAkB,CAAC,UAAU,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAcxG,eAAO,MAAM,SAAS,GAAI,QAAO,MAAW;;qBAIvB,MAAM,GAAG,OAAO;wBAJJ,MAAM;CAOtC,CAAA;AAED,eAAO,MAAM,QAAQ;;qBALA,MAAM,GAAG,OAAO;wBAJJ,MAAM;;yBAIlB,MAAM,GAAG,OAAO;;;CAKF,CAAA;AACnC,eAAO,MAAM,KAAK,YANG,MAAM,GAAG,OAAO,uBAMF,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { Auth } from "../route/auth";
2
+ import { ProviderID } from "../schema";
3
+ import * as AnthropicMessages from "../protocols/anthropic-messages";
4
+ export const id = ProviderID.make("anthropic");
5
+ export const routes = [AnthropicMessages.route];
6
+ const auth = (options) => {
7
+ if ("auth" in options && options.auth)
8
+ return options.auth;
9
+ return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
10
+ .orElse(Auth.config("ANTHROPIC_API_KEY"))
11
+ .pipe(Auth.header("x-api-key"));
12
+ };
13
+ const configuredRoute = (input) => {
14
+ const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
15
+ return AnthropicMessages.route.with({ ...rest, endpoint: { baseURL }, auth: auth(input) });
16
+ };
17
+ export const configure = (input = {}) => {
18
+ const route = configuredRoute(input);
19
+ return {
20
+ id,
21
+ model: (modelID) => route.model({ id: modelID }),
22
+ configure,
23
+ };
24
+ };
25
+ export const provider = configure();
26
+ export const model = provider.model;
27
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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