@clinebot/llms 0.0.0

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 (219) hide show
  1. package/README.md +198 -0
  2. package/dist/config-browser.d.ts +3 -0
  3. package/dist/config.d.ts +3 -0
  4. package/dist/index.browser.d.ts +4 -0
  5. package/dist/index.browser.js +1 -0
  6. package/dist/index.d.ts +5 -0
  7. package/dist/index.js +7 -0
  8. package/dist/models/generated-access.d.ts +4 -0
  9. package/dist/models/generated-provider-loaders.d.ts +13 -0
  10. package/dist/models/generated.d.ts +14 -0
  11. package/dist/models/index.d.ts +43 -0
  12. package/dist/models/models-dev-catalog.d.ts +32 -0
  13. package/dist/models/providers/aihubmix.d.ts +5 -0
  14. package/dist/models/providers/anthropic.d.ts +53 -0
  15. package/dist/models/providers/asksage.d.ts +5 -0
  16. package/dist/models/providers/baseten.d.ts +5 -0
  17. package/dist/models/providers/bedrock.d.ts +7 -0
  18. package/dist/models/providers/cerebras.d.ts +7 -0
  19. package/dist/models/providers/claude-code.d.ts +4 -0
  20. package/dist/models/providers/cline.d.ts +34 -0
  21. package/dist/models/providers/deepseek.d.ts +8 -0
  22. package/dist/models/providers/dify.d.ts +5 -0
  23. package/dist/models/providers/doubao.d.ts +7 -0
  24. package/dist/models/providers/fireworks.d.ts +8 -0
  25. package/dist/models/providers/gemini.d.ts +9 -0
  26. package/dist/models/providers/groq.d.ts +8 -0
  27. package/dist/models/providers/hicap.d.ts +5 -0
  28. package/dist/models/providers/huawei-cloud-maas.d.ts +5 -0
  29. package/dist/models/providers/huggingface.d.ts +6 -0
  30. package/dist/models/providers/index.d.ts +45 -0
  31. package/dist/models/providers/litellm.d.ts +5 -0
  32. package/dist/models/providers/lmstudio.d.ts +5 -0
  33. package/dist/models/providers/minimax.d.ts +7 -0
  34. package/dist/models/providers/mistral.d.ts +5 -0
  35. package/dist/models/providers/moonshot.d.ts +7 -0
  36. package/dist/models/providers/nebius.d.ts +7 -0
  37. package/dist/models/providers/nous-research.d.ts +7 -0
  38. package/dist/models/providers/oca.d.ts +9 -0
  39. package/dist/models/providers/ollama.d.ts +5 -0
  40. package/dist/models/providers/openai-codex.d.ts +10 -0
  41. package/dist/models/providers/openai.d.ts +9 -0
  42. package/dist/models/providers/opencode.d.ts +10 -0
  43. package/dist/models/providers/openrouter.d.ts +7 -0
  44. package/dist/models/providers/qwen-code.d.ts +7 -0
  45. package/dist/models/providers/qwen.d.ts +7 -0
  46. package/dist/models/providers/requesty.d.ts +6 -0
  47. package/dist/models/providers/sambanova.d.ts +7 -0
  48. package/dist/models/providers/sapaicore.d.ts +7 -0
  49. package/dist/models/providers/together.d.ts +8 -0
  50. package/dist/models/providers/vercel-ai-gateway.d.ts +5 -0
  51. package/dist/models/providers/vertex.d.ts +7 -0
  52. package/dist/models/providers/xai.d.ts +8 -0
  53. package/dist/models/providers/zai.d.ts +7 -0
  54. package/dist/models/query.d.ts +181 -0
  55. package/dist/models/registry.d.ts +123 -0
  56. package/dist/models/schemas/index.d.ts +7 -0
  57. package/dist/models/schemas/model.d.ts +340 -0
  58. package/dist/models/schemas/query.d.ts +191 -0
  59. package/dist/providers/handlers/ai-sdk-community.d.ts +46 -0
  60. package/dist/providers/handlers/ai-sdk-provider-base.d.ts +32 -0
  61. package/dist/providers/handlers/anthropic-base.d.ts +26 -0
  62. package/dist/providers/handlers/asksage.d.ts +12 -0
  63. package/dist/providers/handlers/auth.d.ts +5 -0
  64. package/dist/providers/handlers/base.d.ts +55 -0
  65. package/dist/providers/handlers/bedrock-base.d.ts +23 -0
  66. package/dist/providers/handlers/bedrock-client.d.ts +4 -0
  67. package/dist/providers/handlers/community-sdk.d.ts +97 -0
  68. package/dist/providers/handlers/fetch-base.d.ts +18 -0
  69. package/dist/providers/handlers/gemini-base.d.ts +25 -0
  70. package/dist/providers/handlers/index.d.ts +19 -0
  71. package/dist/providers/handlers/openai-base.d.ts +54 -0
  72. package/dist/providers/handlers/openai-responses.d.ts +64 -0
  73. package/dist/providers/handlers/providers.d.ts +43 -0
  74. package/dist/providers/handlers/r1-base.d.ts +62 -0
  75. package/dist/providers/handlers/registry.d.ts +106 -0
  76. package/dist/providers/handlers/vertex.d.ts +32 -0
  77. package/dist/providers/index.d.ts +100 -0
  78. package/dist/providers/public.browser.d.ts +2 -0
  79. package/dist/providers/public.d.ts +3 -0
  80. package/dist/providers/shared/openai-compatible.d.ts +10 -0
  81. package/dist/providers/transform/ai-sdk-community-format.d.ts +9 -0
  82. package/dist/providers/transform/anthropic-format.d.ts +24 -0
  83. package/dist/providers/transform/content-format.d.ts +3 -0
  84. package/dist/providers/transform/gemini-format.d.ts +19 -0
  85. package/dist/providers/transform/index.d.ts +10 -0
  86. package/dist/providers/transform/openai-format.d.ts +36 -0
  87. package/dist/providers/transform/r1-format.d.ts +26 -0
  88. package/dist/providers/types/config.d.ts +261 -0
  89. package/dist/providers/types/handler.d.ts +71 -0
  90. package/dist/providers/types/index.d.ts +11 -0
  91. package/dist/providers/types/messages.d.ts +139 -0
  92. package/dist/providers/types/model-info.d.ts +32 -0
  93. package/dist/providers/types/provider-ids.d.ts +63 -0
  94. package/dist/providers/types/settings.d.ts +308 -0
  95. package/dist/providers/types/stream.d.ts +106 -0
  96. package/dist/providers/utils/index.d.ts +7 -0
  97. package/dist/providers/utils/retry.d.ts +38 -0
  98. package/dist/providers/utils/stream-processor.d.ts +110 -0
  99. package/dist/providers/utils/tool-processor.d.ts +34 -0
  100. package/dist/sdk.d.ts +18 -0
  101. package/dist/types.d.ts +60 -0
  102. package/package.json +66 -0
  103. package/src/catalog.ts +20 -0
  104. package/src/config-browser.ts +11 -0
  105. package/src/config.ts +49 -0
  106. package/src/index.browser.ts +9 -0
  107. package/src/index.ts +10 -0
  108. package/src/live-providers.test.ts +137 -0
  109. package/src/models/generated-access.ts +41 -0
  110. package/src/models/generated-provider-loaders.ts +166 -0
  111. package/src/models/generated.ts +11997 -0
  112. package/src/models/index.ts +271 -0
  113. package/src/models/models-dev-catalog.test.ts +161 -0
  114. package/src/models/models-dev-catalog.ts +161 -0
  115. package/src/models/providers/aihubmix.ts +19 -0
  116. package/src/models/providers/anthropic.ts +60 -0
  117. package/src/models/providers/asksage.ts +19 -0
  118. package/src/models/providers/baseten.ts +21 -0
  119. package/src/models/providers/bedrock.ts +30 -0
  120. package/src/models/providers/cerebras.ts +24 -0
  121. package/src/models/providers/claude-code.ts +51 -0
  122. package/src/models/providers/cline.ts +25 -0
  123. package/src/models/providers/deepseek.ts +33 -0
  124. package/src/models/providers/dify.ts +17 -0
  125. package/src/models/providers/doubao.ts +33 -0
  126. package/src/models/providers/fireworks.ts +34 -0
  127. package/src/models/providers/gemini.ts +43 -0
  128. package/src/models/providers/groq.ts +33 -0
  129. package/src/models/providers/hicap.ts +18 -0
  130. package/src/models/providers/huawei-cloud-maas.ts +18 -0
  131. package/src/models/providers/huggingface.ts +22 -0
  132. package/src/models/providers/index.ts +162 -0
  133. package/src/models/providers/litellm.ts +19 -0
  134. package/src/models/providers/lmstudio.ts +22 -0
  135. package/src/models/providers/minimax.ts +34 -0
  136. package/src/models/providers/mistral.ts +19 -0
  137. package/src/models/providers/moonshot.ts +34 -0
  138. package/src/models/providers/nebius.ts +24 -0
  139. package/src/models/providers/nous-research.ts +21 -0
  140. package/src/models/providers/oca.ts +30 -0
  141. package/src/models/providers/ollama.ts +18 -0
  142. package/src/models/providers/openai-codex.ts +30 -0
  143. package/src/models/providers/openai.ts +43 -0
  144. package/src/models/providers/opencode.ts +28 -0
  145. package/src/models/providers/openrouter.ts +24 -0
  146. package/src/models/providers/qwen-code.ts +33 -0
  147. package/src/models/providers/qwen.ts +34 -0
  148. package/src/models/providers/requesty.ts +23 -0
  149. package/src/models/providers/sambanova.ts +23 -0
  150. package/src/models/providers/sapaicore.ts +34 -0
  151. package/src/models/providers/together.ts +35 -0
  152. package/src/models/providers/vercel-ai-gateway.ts +23 -0
  153. package/src/models/providers/vertex.ts +36 -0
  154. package/src/models/providers/xai.ts +34 -0
  155. package/src/models/providers/zai.ts +25 -0
  156. package/src/models/query.ts +407 -0
  157. package/src/models/registry.ts +511 -0
  158. package/src/models/schemas/index.ts +62 -0
  159. package/src/models/schemas/model.ts +308 -0
  160. package/src/models/schemas/query.ts +336 -0
  161. package/src/providers/browser.ts +4 -0
  162. package/src/providers/handlers/ai-sdk-community.ts +226 -0
  163. package/src/providers/handlers/ai-sdk-provider-base.ts +193 -0
  164. package/src/providers/handlers/anthropic-base.ts +372 -0
  165. package/src/providers/handlers/asksage.test.ts +103 -0
  166. package/src/providers/handlers/asksage.ts +138 -0
  167. package/src/providers/handlers/auth.test.ts +19 -0
  168. package/src/providers/handlers/auth.ts +121 -0
  169. package/src/providers/handlers/base.test.ts +46 -0
  170. package/src/providers/handlers/base.ts +160 -0
  171. package/src/providers/handlers/bedrock-base.ts +390 -0
  172. package/src/providers/handlers/bedrock-client.ts +100 -0
  173. package/src/providers/handlers/codex.test.ts +123 -0
  174. package/src/providers/handlers/community-sdk.test.ts +288 -0
  175. package/src/providers/handlers/community-sdk.ts +392 -0
  176. package/src/providers/handlers/fetch-base.ts +68 -0
  177. package/src/providers/handlers/gemini-base.ts +302 -0
  178. package/src/providers/handlers/index.ts +67 -0
  179. package/src/providers/handlers/openai-base.ts +277 -0
  180. package/src/providers/handlers/openai-responses.ts +598 -0
  181. package/src/providers/handlers/providers.test.ts +120 -0
  182. package/src/providers/handlers/providers.ts +563 -0
  183. package/src/providers/handlers/r1-base.ts +280 -0
  184. package/src/providers/handlers/registry.ts +185 -0
  185. package/src/providers/handlers/vertex.test.ts +124 -0
  186. package/src/providers/handlers/vertex.ts +292 -0
  187. package/src/providers/index.ts +534 -0
  188. package/src/providers/public.browser.ts +20 -0
  189. package/src/providers/public.ts +51 -0
  190. package/src/providers/shared/openai-compatible.ts +63 -0
  191. package/src/providers/transform/ai-sdk-community-format.test.ts +73 -0
  192. package/src/providers/transform/ai-sdk-community-format.ts +115 -0
  193. package/src/providers/transform/anthropic-format.ts +218 -0
  194. package/src/providers/transform/content-format.ts +34 -0
  195. package/src/providers/transform/format-conversion.test.ts +310 -0
  196. package/src/providers/transform/gemini-format.ts +167 -0
  197. package/src/providers/transform/index.ts +22 -0
  198. package/src/providers/transform/openai-format.ts +247 -0
  199. package/src/providers/transform/r1-format.ts +287 -0
  200. package/src/providers/types/config.ts +388 -0
  201. package/src/providers/types/handler.ts +87 -0
  202. package/src/providers/types/index.ts +120 -0
  203. package/src/providers/types/messages.ts +158 -0
  204. package/src/providers/types/model-info.test.ts +57 -0
  205. package/src/providers/types/model-info.ts +65 -0
  206. package/src/providers/types/provider-ids.test.ts +12 -0
  207. package/src/providers/types/provider-ids.ts +89 -0
  208. package/src/providers/types/settings.test.ts +49 -0
  209. package/src/providers/types/settings.ts +533 -0
  210. package/src/providers/types/stream.ts +117 -0
  211. package/src/providers/utils/index.ts +27 -0
  212. package/src/providers/utils/retry.test.ts +140 -0
  213. package/src/providers/utils/retry.ts +188 -0
  214. package/src/providers/utils/stream-processor.test.ts +232 -0
  215. package/src/providers/utils/stream-processor.ts +472 -0
  216. package/src/providers/utils/tool-processor.test.ts +34 -0
  217. package/src/providers/utils/tool-processor.ts +111 -0
  218. package/src/sdk.ts +264 -0
  219. package/src/types.ts +79 -0
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Settings Schema
3
+ *
4
+ * User-friendly settings interface with Zod validation.
5
+ * Converts to internal ProviderConfig for handler creation.
6
+ */
7
+ import { z } from "zod";
8
+ import type { ProviderConfig } from "./config";
9
+ /**
10
+ * All supported provider IDs as a Zod enum
11
+ */
12
+ export declare const ProviderIdSchema: z.ZodString;
13
+ /**
14
+ * Authentication settings
15
+ */
16
+ export declare const AuthSettingsSchema: z.ZodObject<{
17
+ apiKey: z.ZodOptional<z.ZodString>;
18
+ accessToken: z.ZodOptional<z.ZodString>;
19
+ refreshToken: z.ZodOptional<z.ZodString>;
20
+ expiresAt: z.ZodOptional<z.ZodNumber>;
21
+ accountId: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>;
23
+ export type AuthSettings = z.infer<typeof AuthSettingsSchema>;
24
+ export declare const ReasoningSettingsSchema: z.ZodObject<{
25
+ enabled: z.ZodOptional<z.ZodBoolean>;
26
+ effort: z.ZodOptional<z.ZodEnum<{
27
+ low: "low";
28
+ high: "high";
29
+ medium: "medium";
30
+ none: "none";
31
+ }>>;
32
+ budgetTokens: z.ZodOptional<z.ZodNumber>;
33
+ }, z.core.$strip>;
34
+ export type ReasoningSettings = z.infer<typeof ReasoningSettingsSchema>;
35
+ /**
36
+ * AWS Bedrock configuration
37
+ */
38
+ export declare const AwsSettingsSchema: z.ZodObject<{
39
+ accessKey: z.ZodOptional<z.ZodString>;
40
+ secretKey: z.ZodOptional<z.ZodString>;
41
+ sessionToken: z.ZodOptional<z.ZodString>;
42
+ region: z.ZodOptional<z.ZodString>;
43
+ profile: z.ZodOptional<z.ZodString>;
44
+ authentication: z.ZodOptional<z.ZodEnum<{
45
+ iam: "iam";
46
+ "api-key": "api-key";
47
+ profile: "profile";
48
+ }>>;
49
+ usePromptCache: z.ZodOptional<z.ZodBoolean>;
50
+ useCrossRegionInference: z.ZodOptional<z.ZodBoolean>;
51
+ useGlobalInference: z.ZodOptional<z.ZodBoolean>;
52
+ endpoint: z.ZodOptional<z.ZodString>;
53
+ customModelBaseId: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>;
55
+ export type AwsSettings = z.infer<typeof AwsSettingsSchema>;
56
+ /**
57
+ * Google Cloud Vertex AI configuration
58
+ */
59
+ export declare const GcpSettingsSchema: z.ZodObject<{
60
+ projectId: z.ZodOptional<z.ZodString>;
61
+ region: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>;
63
+ export type GcpSettings = z.infer<typeof GcpSettingsSchema>;
64
+ /**
65
+ * Azure OpenAI configuration
66
+ */
67
+ export declare const AzureSettingsSchema: z.ZodObject<{
68
+ apiVersion: z.ZodOptional<z.ZodString>;
69
+ useIdentity: z.ZodOptional<z.ZodBoolean>;
70
+ }, z.core.$strip>;
71
+ export type AzureSettings = z.infer<typeof AzureSettingsSchema>;
72
+ /**
73
+ * SAP AI Core configuration
74
+ */
75
+ export declare const SapSettingsSchema: z.ZodObject<{
76
+ clientId: z.ZodOptional<z.ZodString>;
77
+ clientSecret: z.ZodOptional<z.ZodString>;
78
+ tokenUrl: z.ZodOptional<z.ZodString>;
79
+ resourceGroup: z.ZodOptional<z.ZodString>;
80
+ deploymentId: z.ZodOptional<z.ZodString>;
81
+ useOrchestrationMode: z.ZodOptional<z.ZodBoolean>;
82
+ api: z.ZodOptional<z.ZodEnum<{
83
+ orchestration: "orchestration";
84
+ "foundation-models": "foundation-models";
85
+ }>>;
86
+ defaultSettings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
87
+ }, z.core.$strip>;
88
+ export type SapSettings = z.infer<typeof SapSettingsSchema>;
89
+ /**
90
+ * Oracle Cloud AI configuration
91
+ */
92
+ export declare const OcaSettingsSchema: z.ZodObject<{
93
+ mode: z.ZodOptional<z.ZodEnum<{
94
+ internal: "internal";
95
+ external: "external";
96
+ }>>;
97
+ usePromptCache: z.ZodOptional<z.ZodBoolean>;
98
+ }, z.core.$strip>;
99
+ export type OcaSettings = z.infer<typeof OcaSettingsSchema>;
100
+ /**
101
+ * Runtime model catalog refresh configuration
102
+ */
103
+ export declare const ModelCatalogSettingsSchema: z.ZodObject<{
104
+ loadLatestOnInit: z.ZodOptional<z.ZodBoolean>;
105
+ loadPrivateOnAuth: z.ZodOptional<z.ZodBoolean>;
106
+ url: z.ZodOptional<z.ZodString>;
107
+ cacheTtlMs: z.ZodOptional<z.ZodNumber>;
108
+ failOnError: z.ZodOptional<z.ZodBoolean>;
109
+ }, z.core.$strip>;
110
+ export type ModelCatalogSettings = z.infer<typeof ModelCatalogSettingsSchema>;
111
+ /**
112
+ * Main provider settings schema
113
+ *
114
+ * This is the user-friendly interface for configuring providers.
115
+ * Use `parseSettings()` or `toProviderConfig()` to convert to ProviderConfig.
116
+ */
117
+ export declare const ProviderSettingsSchema: z.ZodObject<{
118
+ provider: z.ZodString;
119
+ apiKey: z.ZodOptional<z.ZodString>;
120
+ auth: z.ZodOptional<z.ZodObject<{
121
+ apiKey: z.ZodOptional<z.ZodString>;
122
+ accessToken: z.ZodOptional<z.ZodString>;
123
+ refreshToken: z.ZodOptional<z.ZodString>;
124
+ expiresAt: z.ZodOptional<z.ZodNumber>;
125
+ accountId: z.ZodOptional<z.ZodString>;
126
+ }, z.core.$strip>>;
127
+ model: z.ZodOptional<z.ZodString>;
128
+ maxTokens: z.ZodOptional<z.ZodNumber>;
129
+ contextWindow: z.ZodOptional<z.ZodNumber>;
130
+ baseUrl: z.ZodOptional<z.ZodString>;
131
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
132
+ timeout: z.ZodOptional<z.ZodNumber>;
133
+ reasoning: z.ZodOptional<z.ZodObject<{
134
+ enabled: z.ZodOptional<z.ZodBoolean>;
135
+ effort: z.ZodOptional<z.ZodEnum<{
136
+ low: "low";
137
+ high: "high";
138
+ medium: "medium";
139
+ none: "none";
140
+ }>>;
141
+ budgetTokens: z.ZodOptional<z.ZodNumber>;
142
+ }, z.core.$strip>>;
143
+ aws: z.ZodOptional<z.ZodObject<{
144
+ accessKey: z.ZodOptional<z.ZodString>;
145
+ secretKey: z.ZodOptional<z.ZodString>;
146
+ sessionToken: z.ZodOptional<z.ZodString>;
147
+ region: z.ZodOptional<z.ZodString>;
148
+ profile: z.ZodOptional<z.ZodString>;
149
+ authentication: z.ZodOptional<z.ZodEnum<{
150
+ iam: "iam";
151
+ "api-key": "api-key";
152
+ profile: "profile";
153
+ }>>;
154
+ usePromptCache: z.ZodOptional<z.ZodBoolean>;
155
+ useCrossRegionInference: z.ZodOptional<z.ZodBoolean>;
156
+ useGlobalInference: z.ZodOptional<z.ZodBoolean>;
157
+ endpoint: z.ZodOptional<z.ZodString>;
158
+ customModelBaseId: z.ZodOptional<z.ZodString>;
159
+ }, z.core.$strip>>;
160
+ gcp: z.ZodOptional<z.ZodObject<{
161
+ projectId: z.ZodOptional<z.ZodString>;
162
+ region: z.ZodOptional<z.ZodString>;
163
+ }, z.core.$strip>>;
164
+ azure: z.ZodOptional<z.ZodObject<{
165
+ apiVersion: z.ZodOptional<z.ZodString>;
166
+ useIdentity: z.ZodOptional<z.ZodBoolean>;
167
+ }, z.core.$strip>>;
168
+ sap: z.ZodOptional<z.ZodObject<{
169
+ clientId: z.ZodOptional<z.ZodString>;
170
+ clientSecret: z.ZodOptional<z.ZodString>;
171
+ tokenUrl: z.ZodOptional<z.ZodString>;
172
+ resourceGroup: z.ZodOptional<z.ZodString>;
173
+ deploymentId: z.ZodOptional<z.ZodString>;
174
+ useOrchestrationMode: z.ZodOptional<z.ZodBoolean>;
175
+ api: z.ZodOptional<z.ZodEnum<{
176
+ orchestration: "orchestration";
177
+ "foundation-models": "foundation-models";
178
+ }>>;
179
+ defaultSettings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
180
+ }, z.core.$strip>>;
181
+ oca: z.ZodOptional<z.ZodObject<{
182
+ mode: z.ZodOptional<z.ZodEnum<{
183
+ internal: "internal";
184
+ external: "external";
185
+ }>>;
186
+ usePromptCache: z.ZodOptional<z.ZodBoolean>;
187
+ }, z.core.$strip>>;
188
+ region: z.ZodOptional<z.ZodString>;
189
+ apiLine: z.ZodOptional<z.ZodEnum<{
190
+ china: "china";
191
+ international: "international";
192
+ }>>;
193
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
194
+ tools: "tools";
195
+ streaming: "streaming";
196
+ "prompt-cache": "prompt-cache";
197
+ reasoning: "reasoning";
198
+ "computer-use": "computer-use";
199
+ oauth: "oauth";
200
+ vision: "vision";
201
+ }>>>;
202
+ modelCatalog: z.ZodOptional<z.ZodObject<{
203
+ loadLatestOnInit: z.ZodOptional<z.ZodBoolean>;
204
+ loadPrivateOnAuth: z.ZodOptional<z.ZodBoolean>;
205
+ url: z.ZodOptional<z.ZodString>;
206
+ cacheTtlMs: z.ZodOptional<z.ZodNumber>;
207
+ failOnError: z.ZodOptional<z.ZodBoolean>;
208
+ }, z.core.$strip>>;
209
+ }, z.core.$strip>;
210
+ export type ProviderSettings = z.infer<typeof ProviderSettingsSchema>;
211
+ /**
212
+ * Parse and validate settings
213
+ *
214
+ * @param input - Raw settings input (unknown type)
215
+ * @returns Validated ProviderSettings
216
+ * @throws ZodError if validation fails
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const settings = parseSettings({
221
+ * provider: "anthropic",
222
+ * apiKey: "sk-...",
223
+ * model: "claude-sonnet-4-20250514",
224
+ * })
225
+ * ```
226
+ */
227
+ export declare function parseSettings(input: unknown): ProviderSettings;
228
+ /**
229
+ * Safely parse settings without throwing
230
+ *
231
+ * @param input - Raw settings input (unknown type)
232
+ * @returns SafeParseResult with success/error info
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const result = safeParseSettings({ provider: "anthropic" })
237
+ * if (result.success) {
238
+ * console.log(result.data)
239
+ * } else {
240
+ * console.error(result.error.issues)
241
+ * }
242
+ * ```
243
+ */
244
+ export declare function safeParseSettings(input: unknown): ReturnType<typeof ProviderSettingsSchema.safeParse>;
245
+ /**
246
+ * Convert validated settings to ProviderConfig
247
+ *
248
+ * This function takes validated ProviderSettings and converts them
249
+ * to the internal ProviderConfig format used by handlers.
250
+ *
251
+ * @param settings - Validated provider settings
252
+ * @returns ProviderConfig ready for handler creation
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const settings = parseSettings({ provider: "openai", apiKey: "sk-..." })
257
+ * const config = toProviderConfig(settings)
258
+ * const handler = createHandler(config)
259
+ * ```
260
+ */
261
+ export declare function toProviderConfig(settings: ProviderSettings): ProviderConfig;
262
+ /**
263
+ * Parse settings and convert to ProviderConfig in one step
264
+ *
265
+ * This is a convenience function that combines `parseSettings()` and `toProviderConfig()`.
266
+ *
267
+ * @param input - Raw settings input (unknown type)
268
+ * @returns ProviderConfig ready for handler creation
269
+ * @throws ZodError if validation fails
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * import { createHandler, createProviderConfig } from "@clinebot/providers"
274
+ *
275
+ * const config = createProviderConfig({
276
+ * provider: "anthropic",
277
+ * apiKey: process.env.ANTHROPIC_API_KEY,
278
+ * model: "claude-sonnet-4-20250514",
279
+ * reasoning: { effort: "high" },
280
+ * })
281
+ *
282
+ * const handler = createHandler(config)
283
+ * ```
284
+ */
285
+ export declare function createProviderConfig(input: unknown): ProviderConfig;
286
+ /**
287
+ * Safely create ProviderConfig without throwing
288
+ *
289
+ * @param input - Raw settings input
290
+ * @returns Object with either `config` on success or `error` on failure
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const result = safeCreateProviderConfig({ provider: "openai" })
295
+ * if (result.success) {
296
+ * const handler = createHandler(result.config)
297
+ * } else {
298
+ * console.error("Invalid settings:", result.error.issues)
299
+ * }
300
+ * ```
301
+ */
302
+ export declare function safeCreateProviderConfig(input: unknown): {
303
+ success: true;
304
+ config: ProviderConfig;
305
+ } | {
306
+ success: false;
307
+ error: z.ZodError;
308
+ };
@@ -0,0 +1,106 @@
1
+ /**
2
+ * API Stream Types
3
+ *
4
+ * Unified streaming response types that all providers yield.
5
+ * This provides a consistent interface regardless of the underlying provider.
6
+ */
7
+ /**
8
+ * The main stream type - an async generator that yields chunks
9
+ */
10
+ export type ApiStream = AsyncGenerator<ApiStreamChunk> & {
11
+ id?: string;
12
+ };
13
+ /**
14
+ * Union of all possible chunk types
15
+ */
16
+ export type ApiStreamChunk = ApiStreamTextChunk | ApiStreamReasoningChunk | ApiStreamUsageChunk | ApiStreamToolCallsChunk | ApiStreamDoneChunk;
17
+ /**
18
+ * Text content chunk
19
+ */
20
+ export interface ApiStreamTextChunk {
21
+ type: "text";
22
+ /** Text content generated by the model */
23
+ text: string;
24
+ /** Response ID associated with this chunk */
25
+ id: string;
26
+ /** Thought signature (used by Gemini) */
27
+ signature?: string;
28
+ }
29
+ /**
30
+ * Reasoning/thinking content chunk
31
+ */
32
+ export interface ApiStreamReasoningChunk {
33
+ type: "reasoning";
34
+ /** The reasoning text generated by the model */
35
+ reasoning: string;
36
+ /** Additional reasoning details (provider-specific) */
37
+ details?: unknown;
38
+ /** Signature for the thinking block (Anthropic, Gemini) */
39
+ signature?: string;
40
+ /** Redacted reasoning data */
41
+ redacted_data?: string;
42
+ /** Response ID associated with this chunk */
43
+ id: string;
44
+ }
45
+ /**
46
+ * Usage/token count chunk
47
+ */
48
+ export interface ApiStreamUsageChunk {
49
+ type: "usage";
50
+ /** Number of input tokens (excluding cached) */
51
+ inputTokens: number;
52
+ /** Number of output tokens */
53
+ outputTokens: number;
54
+ /** Number of tokens written to cache */
55
+ cacheWriteTokens?: number;
56
+ /** Number of tokens read from cache */
57
+ cacheReadTokens?: number;
58
+ /** Number of thinking/reasoning tokens */
59
+ thoughtsTokenCount?: number;
60
+ /** Total cost in USD (if calculable) */
61
+ totalCost?: number;
62
+ /** Response ID */
63
+ id: string;
64
+ }
65
+ /**
66
+ * Tool call chunk
67
+ */
68
+ export interface ApiStreamToolCallsChunk {
69
+ type: "tool_calls";
70
+ /** The tool call information */
71
+ tool_call: ApiStreamToolCall;
72
+ /** Response ID */
73
+ id: string;
74
+ /** Thought signature (Gemini) */
75
+ signature?: string;
76
+ }
77
+ /**
78
+ * Tool call details
79
+ */
80
+ export interface ApiStreamToolCall {
81
+ /** Call ID for this tool invocation */
82
+ call_id?: string;
83
+ /** Function/tool information */
84
+ function: {
85
+ /** Tool call ID */
86
+ id?: string;
87
+ /** Name of the tool */
88
+ name?: string;
89
+ /** Arguments passed to the tool (can be string or parsed object) */
90
+ arguments?: string | Record<string, unknown>;
91
+ };
92
+ }
93
+ /**
94
+ * Stream completion chunk - indicates the stream has finished
95
+ */
96
+ export interface ApiStreamDoneChunk {
97
+ type: "done";
98
+ /** Whether the stream completed successfully */
99
+ success: boolean;
100
+ /** Error message if the stream failed */
101
+ error?: string;
102
+ /** Reason for incomplete response (e.g., "max_output_tokens") */
103
+ incompleteReason?: string;
104
+ /** Response ID */
105
+ id: string;
106
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Utils Index
3
+ */
4
+ export type { RetryOptions } from "./retry";
5
+ export { calculateRetryDelay, isRetriableError, RetriableError, retryAsync, retryStream, sleep, } from "./retry";
6
+ export { type AssistantContentBlock, type AssistantRedactedThinkingBlock, type AssistantTextBlock, type AssistantThinkingBlock, type AssistantToolUseBlock, type ProcessedResponse, type ReasoningDetailParam, StreamResponseProcessor, type UsageInfo, } from "./stream-processor";
7
+ export { ToolCallProcessor } from "./tool-processor";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Retry Utilities
3
+ *
4
+ * Provides retry logic with exponential backoff for API calls.
5
+ */
6
+ export interface RetryOptions {
7
+ maxRetries?: number;
8
+ baseDelay?: number;
9
+ maxDelay?: number;
10
+ onRetryAttempt?: (attempt: number, maxRetries: number, delay: number, error: unknown) => void;
11
+ }
12
+ /**
13
+ * Error that indicates the operation should be retried
14
+ */
15
+ export declare class RetriableError extends Error {
16
+ readonly retryAfterSeconds?: number | undefined;
17
+ constructor(message: string, retryAfterSeconds?: number | undefined, options?: ErrorOptions);
18
+ }
19
+ /**
20
+ * Check if an error is retriable
21
+ */
22
+ export declare function isRetriableError(error: unknown): boolean;
23
+ /**
24
+ * Calculate delay for retry attempt with exponential backoff and jitter
25
+ */
26
+ export declare function calculateRetryDelay(attempt: number, options?: RetryOptions): number;
27
+ /**
28
+ * Sleep for a given number of milliseconds
29
+ */
30
+ export declare function sleep(ms: number): Promise<void>;
31
+ /**
32
+ * Retry an async generator factory using the same retry policy as retryAsync.
33
+ */
34
+ export declare function retryStream<T>(createStream: () => AsyncGenerator<T, void, unknown>, options?: RetryOptions): AsyncGenerator<T, void, unknown>;
35
+ /**
36
+ * Wrap an async function with retry logic
37
+ */
38
+ export declare function retryAsync<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Stream Response Processor
3
+ *
4
+ * Processes ApiStreamChunks and assembles them into Cline's message content format.
5
+ * This provides a clean interface between the streaming API and Cline's storage format.
6
+ */
7
+ import type { ApiStreamChunk } from "../types/stream";
8
+ export interface ReasoningDetailParam {
9
+ type: "reasoning.text" | string;
10
+ text: string;
11
+ signature: string;
12
+ format: "anthropic-claude-v1" | string;
13
+ index: number;
14
+ }
15
+ export interface AssistantTextBlock {
16
+ type: "text";
17
+ text: string;
18
+ call_id?: string;
19
+ reasoning_details?: ReasoningDetailParam[];
20
+ signature?: string;
21
+ }
22
+ export interface AssistantToolUseBlock {
23
+ type: "tool_use";
24
+ id: string;
25
+ name: string;
26
+ input: Record<string, unknown>;
27
+ call_id?: string;
28
+ reasoning_details?: ReasoningDetailParam[];
29
+ signature?: string;
30
+ }
31
+ export interface AssistantThinkingBlock {
32
+ type: "thinking";
33
+ thinking: string;
34
+ signature: string;
35
+ call_id?: string;
36
+ summary?: ReasoningDetailParam[];
37
+ }
38
+ export interface AssistantRedactedThinkingBlock {
39
+ type: "redacted_thinking";
40
+ data: string;
41
+ call_id?: string;
42
+ }
43
+ export type AssistantContentBlock = AssistantTextBlock | AssistantToolUseBlock | AssistantThinkingBlock | AssistantRedactedThinkingBlock;
44
+ export interface UsageInfo {
45
+ inputTokens: number;
46
+ outputTokens: number;
47
+ cacheWriteTokens?: number;
48
+ cacheReadTokens?: number;
49
+ thoughtsTokenCount?: number;
50
+ totalCost?: number;
51
+ }
52
+ export interface ProcessedResponse {
53
+ content: AssistantContentBlock[];
54
+ usage?: UsageInfo;
55
+ responseId?: string;
56
+ incompleteReason?: string;
57
+ }
58
+ /**
59
+ * Processes streaming API responses and assembles content blocks.
60
+ *
61
+ * Usage:
62
+ * ```ts
63
+ * const processor = new StreamResponseProcessor()
64
+ * for await (const chunk of apiStream) {
65
+ * const partial = processor.process(chunk)
66
+ * // Use partial for live updates
67
+ * }
68
+ * const final = processor.finalize()
69
+ * ```
70
+ */
71
+ export declare class StreamResponseProcessor {
72
+ private text;
73
+ private textSignature?;
74
+ private toolUses;
75
+ private reasoning;
76
+ private usage;
77
+ private responseId?;
78
+ private incompleteReason?;
79
+ /**
80
+ * Process a single stream chunk and return current partial state.
81
+ * Call this for each chunk to get live updates.
82
+ */
83
+ process(chunk: ApiStreamChunk): ProcessedResponse;
84
+ /**
85
+ * Finalize and return the complete response.
86
+ * Call this after all chunks have been processed.
87
+ */
88
+ finalize(): ProcessedResponse;
89
+ /**
90
+ * Get current partial response for live streaming updates.
91
+ */
92
+ getPartialResponse(): ProcessedResponse;
93
+ /**
94
+ * Reset processor state for reuse.
95
+ */
96
+ reset(): void;
97
+ private processText;
98
+ private processReasoning;
99
+ private processToolCall;
100
+ private processUsage;
101
+ private createPendingToolUse;
102
+ private finalizeToolInput;
103
+ /**
104
+ * Extract fields from incomplete JSON during streaming.
105
+ */
106
+ private extractPartialJson;
107
+ private unescapeString;
108
+ private isReasoningDetail;
109
+ private isRecord;
110
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tool Call Processor
3
+ *
4
+ * Handles incremental assembly of tool calls from streaming responses.
5
+ * Tool calls can arrive in chunks that need to be accumulated.
6
+ */
7
+ import type { ApiStreamToolCall, ApiStreamToolCallsChunk } from "../types/stream";
8
+ export type { ApiStreamToolCallsChunk };
9
+ interface ToolCallDelta {
10
+ index: number;
11
+ id?: string;
12
+ function?: {
13
+ name?: string;
14
+ arguments?: string;
15
+ };
16
+ }
17
+ /**
18
+ * Processes tool call deltas from streaming API responses
19
+ */
20
+ export declare class ToolCallProcessor {
21
+ private toolCalls;
22
+ /**
23
+ * Process tool call deltas and yield complete tool calls
24
+ */
25
+ processToolCallDeltas(deltas: ToolCallDelta[], responseId: string): ApiStreamToolCallsChunk[];
26
+ /**
27
+ * Get all accumulated tool calls
28
+ */
29
+ getToolCalls(): ApiStreamToolCall[];
30
+ /**
31
+ * Reset the processor state
32
+ */
33
+ reset(): void;
34
+ }
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type ApiHandler } from "./providers/index";
2
+ import type { CreateHandlerInput, LlmsConfig, LlmsSdk, RegisteredProviderSummary, RegisterModelInput, RegisterProviderInput } from "./types";
3
+ export declare class DefaultLlmsSdk implements LlmsSdk {
4
+ private readonly providerConfigs;
5
+ constructor(config: LlmsConfig);
6
+ createHandler(input: CreateHandlerInput): ApiHandler;
7
+ createHandlerAsync(input: CreateHandlerInput): Promise<ApiHandler>;
8
+ private toProviderHandlerConfig;
9
+ registerProvider(input: RegisterProviderInput): void;
10
+ registerModel(input: RegisterModelInput): void;
11
+ getProviders(): RegisteredProviderSummary[];
12
+ getModels(providerId: string): string[];
13
+ isProviderConfigured(providerId: string): boolean;
14
+ isModelConfigured(providerId: string, modelId: string): boolean;
15
+ private applyConfig;
16
+ private requireConfiguredProvider;
17
+ }
18
+ export declare function createLlmsSdk(config: LlmsConfig): LlmsSdk;
@@ -0,0 +1,60 @@
1
+ import type { ModelCollection, ModelInfo } from "./models/index";
2
+ import type { ApiHandler, HandlerFactory, LazyHandlerFactory, ProviderCapability, ProviderConfig } from "./providers/index";
3
+ export type ProviderConfigDefaults = Omit<ProviderConfig, "providerId" | "modelId">;
4
+ export interface ProviderSelectionConfig {
5
+ id: string;
6
+ models: string[];
7
+ defaultModel?: string;
8
+ apiKey?: string;
9
+ apiKeyEnv?: string;
10
+ baseUrl?: string;
11
+ headers?: Record<string, string>;
12
+ timeoutMs?: number;
13
+ capabilities?: ProviderCapability[];
14
+ settings?: ProviderConfigDefaults;
15
+ }
16
+ export interface AdditionalModelConfig {
17
+ providerId: string;
18
+ modelId: string;
19
+ info: ModelInfo;
20
+ }
21
+ export interface CustomProviderConfig {
22
+ collection: ModelCollection;
23
+ defaults?: ProviderConfigDefaults;
24
+ handlerFactory?: HandlerFactory;
25
+ asyncHandlerFactory?: LazyHandlerFactory;
26
+ }
27
+ export interface LlmsConfig {
28
+ providers: ProviderSelectionConfig[];
29
+ models?: AdditionalModelConfig[];
30
+ customProviders?: CustomProviderConfig[];
31
+ }
32
+ export interface CreateHandlerInput {
33
+ providerId: string;
34
+ modelId?: string;
35
+ overrides?: ProviderConfigDefaults;
36
+ }
37
+ export interface RegisteredProviderSummary {
38
+ id: string;
39
+ models: string[];
40
+ defaultModel: string;
41
+ }
42
+ export interface RegisterProviderInput extends CustomProviderConfig {
43
+ exposeModels?: string[];
44
+ defaultModel?: string;
45
+ }
46
+ export interface RegisterModelInput {
47
+ providerId: string;
48
+ modelId: string;
49
+ info: ModelInfo;
50
+ }
51
+ export interface LlmsSdk {
52
+ createHandler(input: CreateHandlerInput): ApiHandler;
53
+ createHandlerAsync(input: CreateHandlerInput): Promise<ApiHandler>;
54
+ registerProvider(input: RegisterProviderInput): void;
55
+ registerModel(input: RegisterModelInput): void;
56
+ getProviders(): RegisteredProviderSummary[];
57
+ getModels(providerId: string): string[];
58
+ isProviderConfigured(providerId: string): boolean;
59
+ isModelConfigured(providerId: string, modelId: string): boolean;
60
+ }