@tanstack/ai-groq 0.1.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 (40) hide show
  1. package/README.md +91 -0
  2. package/dist/esm/adapters/text.d.ts +104 -0
  3. package/dist/esm/adapters/text.js +384 -0
  4. package/dist/esm/adapters/text.js.map +1 -0
  5. package/dist/esm/index.d.ts +10 -0
  6. package/dist/esm/index.js +9 -0
  7. package/dist/esm/index.js.map +1 -0
  8. package/dist/esm/message-types.d.ts +292 -0
  9. package/dist/esm/model-meta.d.ts +275 -0
  10. package/dist/esm/model-meta.js +54 -0
  11. package/dist/esm/model-meta.js.map +1 -0
  12. package/dist/esm/text/text-provider-options.d.ts +179 -0
  13. package/dist/esm/text/text-provider-options.js +6 -0
  14. package/dist/esm/text/text-provider-options.js.map +1 -0
  15. package/dist/esm/tools/function-tool.d.ts +13 -0
  16. package/dist/esm/tools/function-tool.js +29 -0
  17. package/dist/esm/tools/function-tool.js.map +1 -0
  18. package/dist/esm/tools/index.d.ts +2 -0
  19. package/dist/esm/tools/tool-converter.d.ts +7 -0
  20. package/dist/esm/tools/tool-converter.js +10 -0
  21. package/dist/esm/tools/tool-converter.js.map +1 -0
  22. package/dist/esm/utils/client.d.ts +17 -0
  23. package/dist/esm/utils/client.js +23 -0
  24. package/dist/esm/utils/client.js.map +1 -0
  25. package/dist/esm/utils/index.d.ts +2 -0
  26. package/dist/esm/utils/schema-converter.d.ts +25 -0
  27. package/dist/esm/utils/schema-converter.js +78 -0
  28. package/dist/esm/utils/schema-converter.js.map +1 -0
  29. package/package.json +52 -0
  30. package/src/adapters/text.ts +599 -0
  31. package/src/index.ts +33 -0
  32. package/src/message-types.ts +359 -0
  33. package/src/model-meta.ts +370 -0
  34. package/src/text/text-provider-options.ts +225 -0
  35. package/src/tools/function-tool.ts +44 -0
  36. package/src/tools/index.ts +5 -0
  37. package/src/tools/tool-converter.ts +15 -0
  38. package/src/utils/client.ts +42 -0
  39. package/src/utils/index.ts +10 -0
  40. package/src/utils/schema-converter.ts +110 -0
@@ -0,0 +1,359 @@
1
+ /**
2
+ * Groq-specific message types for the Chat Completions API.
3
+ *
4
+ * These type definitions mirror the Groq SDK types and are used internally
5
+ * by the adapter to avoid tight coupling to the SDK's exported types.
6
+ *
7
+ * @see https://console.groq.com/docs/api-reference#chat
8
+ */
9
+
10
+ export interface ChatCompletionContentPartText {
11
+ /** The text content. */
12
+ text: string
13
+
14
+ /** The type of the content part. */
15
+ type: 'text'
16
+ }
17
+
18
+ export interface ChatCompletionContentPartImage {
19
+ image_url: {
20
+ /** Either a URL of the image or the base64 encoded image data. */
21
+ url: string
22
+
23
+ /** Specifies the detail level of the image. */
24
+ detail?: 'auto' | 'low' | 'high'
25
+ }
26
+
27
+ /** The type of the content part. */
28
+ type: 'image_url'
29
+ }
30
+
31
+ export interface ChatCompletionMessageToolCall {
32
+ /** The ID of the tool call. */
33
+ id: string
34
+
35
+ /** The function that the model called. */
36
+ function: {
37
+ /**
38
+ * The arguments to call the function with, as generated by the model in JSON
39
+ * format. Note that the model does not always generate valid JSON, and may
40
+ * hallucinate parameters not defined by your function schema. Validate the
41
+ * arguments in your code before calling your function.
42
+ */
43
+ arguments: string
44
+
45
+ /** The name of the function to call. */
46
+ name: string
47
+ }
48
+
49
+ /** The type of the tool. Currently, only `function` is supported. */
50
+ type: 'function'
51
+ }
52
+
53
+ export interface ChatCompletionRequestMessageContentPartDocument {
54
+ document: {
55
+ /** The JSON document data. */
56
+ data: { [key: string]: unknown }
57
+
58
+ /** Optional unique identifier for the document. */
59
+ id?: string | null
60
+ }
61
+
62
+ /** The type of the content part. */
63
+ type: 'document'
64
+ }
65
+
66
+ export type FunctionParameters = { [key: string]: unknown }
67
+
68
+ export interface ChatCompletionNamedToolChoice {
69
+ Function: {
70
+ /** The name of the function to call. */
71
+ name: string
72
+ }
73
+ }
74
+
75
+ export interface FunctionDefinition {
76
+ /**
77
+ * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
78
+ * underscores and dashes, with a maximum length of 64.
79
+ */
80
+ name: string
81
+
82
+ /**
83
+ * A description of what the function does, used by the model to choose when and
84
+ * how to call the function.
85
+ */
86
+ description?: string
87
+
88
+ /**
89
+ * Function parameters defined as a JSON Schema object.
90
+ * @see https://json-schema.org/understanding-json-schema/
91
+ */
92
+ parameters?: FunctionParameters
93
+
94
+ /**
95
+ * Whether to enable strict schema adherence when generating the output. If set to
96
+ * true, the model will always follow the exact schema defined in the `schema`
97
+ * field. Only a subset of JSON Schema is supported when `strict` is `true`.
98
+ */
99
+ strict?: boolean
100
+ }
101
+
102
+ /**
103
+ * Controls which (if any) tool is called by the model.
104
+ *
105
+ * - `none` — the model will not call any tool and instead generates a message
106
+ * - `auto` — the model can pick between generating a message or calling tools
107
+ * - `required` — the model must call one or more tools
108
+ * - Named tool choice — forces the model to call a specific tool
109
+ */
110
+ export type ChatCompletionToolChoiceOption =
111
+ | 'none'
112
+ | 'auto'
113
+ | 'required'
114
+ | ChatCompletionNamedToolChoice
115
+
116
+ export type ChatCompletionContentPart =
117
+ | ChatCompletionContentPartText
118
+ | ChatCompletionContentPartImage
119
+ | ChatCompletionRequestMessageContentPartDocument
120
+
121
+ export interface ChatCompletionAssistantMessageParam {
122
+ /** The role of the messages author, in this case `assistant`. */
123
+ role: 'assistant'
124
+
125
+ /**
126
+ * The contents of the assistant message. Required unless `tool_calls` or
127
+ * `function_call` is specified.
128
+ */
129
+ content?: string | Array<ChatCompletionContentPartText> | null
130
+
131
+ /** An optional name for the participant. */
132
+ name?: string
133
+
134
+ /**
135
+ * The reasoning output by the assistant if reasoning_format was set to 'parsed'.
136
+ * This field is only useable with qwen3 models.
137
+ */
138
+ reasoning?: string | null
139
+
140
+ /** The tool calls generated by the model, such as function calls. */
141
+ tool_calls?: Array<ChatCompletionMessageToolCall>
142
+ }
143
+
144
+ export interface ChatCompletionTool {
145
+ /**
146
+ * The type of the tool. `function`, `browser_search`, and `code_interpreter` are
147
+ * supported.
148
+ */
149
+ type: 'function' | 'browser_search' | 'code_interpreter' | (string & {})
150
+
151
+ function?: FunctionDefinition
152
+ }
153
+
154
+ export interface ChatCompletionToolMessageParam {
155
+ /** The contents of the tool message. */
156
+ content: string | Array<ChatCompletionContentPart>
157
+
158
+ /** The role of the messages author, in this case `tool`. */
159
+ role: 'tool'
160
+
161
+ /** Tool call that this message is responding to. */
162
+ tool_call_id: string
163
+ }
164
+
165
+ export interface ChatCompletionSystemMessageParam {
166
+ /** The contents of the system message. */
167
+ content: string | Array<ChatCompletionContentPartText>
168
+
169
+ /** The role of the messages author, in this case `system`. */
170
+ role: 'system' | 'developer'
171
+
172
+ /** An optional name for the participant. */
173
+ name?: string
174
+ }
175
+
176
+ export interface ChatCompletionUserMessageParam {
177
+ /** The contents of the user message. */
178
+ content: string | Array<ChatCompletionContentPart>
179
+
180
+ /** The role of the messages author, in this case `user`. */
181
+ role: 'user'
182
+
183
+ /** An optional name for the participant. */
184
+ name?: string
185
+ }
186
+
187
+ /**
188
+ * Union of all supported chat completion message params.
189
+ */
190
+ export type ChatCompletionMessageParam =
191
+ | ChatCompletionSystemMessageParam
192
+ | ChatCompletionUserMessageParam
193
+ | ChatCompletionAssistantMessageParam
194
+ | ChatCompletionToolMessageParam
195
+
196
+ export interface CompoundCustomModels {
197
+ /** Custom model to use for answering. */
198
+ answering_model?: string | null
199
+
200
+ /** Custom model to use for reasoning. */
201
+ reasoning_model?: string | null
202
+ }
203
+
204
+ export interface CompoundCustomTools {
205
+ /** A list of tool names that are enabled for the request. */
206
+ enabled_tools?: Array<string> | null
207
+
208
+ /** Configuration for the Wolfram tool integration. */
209
+ wolfram_settings?: CompoundCustomToolsWolframSettings | null
210
+ }
211
+
212
+ export interface CompoundCustomToolsWolframSettings {
213
+ /** API key used to authorize requests to Wolfram services. */
214
+ authorization?: string | null
215
+ }
216
+
217
+ export interface CompoundCustom {
218
+ models?: CompoundCustomModels | null
219
+
220
+ /** Configuration options for tools available to Compound. */
221
+ tools?: CompoundCustomTools | null
222
+ }
223
+
224
+ export interface DocumentSourceText {
225
+ /** The document contents. */
226
+ text: string
227
+
228
+ /** Identifies this document source as inline text. */
229
+ type: 'text'
230
+ }
231
+
232
+ export interface DocumentSourceJson {
233
+ /** The JSON payload associated with the document. */
234
+ data: { [key: string]: unknown }
235
+
236
+ /** Identifies this document source as JSON data. */
237
+ type: 'json'
238
+ }
239
+
240
+ export interface Document {
241
+ /** The source of the document. Only text and JSON sources are currently supported. */
242
+ source: DocumentSourceText | DocumentSourceJson
243
+
244
+ /** Optional unique identifier that can be used for citations in responses. */
245
+ id?: string | null
246
+ }
247
+
248
+ export interface ResponseFormatText {
249
+ /** The type of response format being defined. Always `text`. */
250
+ type: 'text'
251
+ }
252
+
253
+ export interface ResponseFormatJsonSchemaJsonSchema {
254
+ /**
255
+ * The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores
256
+ * and dashes, with a maximum length of 64.
257
+ */
258
+ name: string
259
+
260
+ /**
261
+ * A description of what the response format is for, used by the model to determine
262
+ * how to respond in the format.
263
+ */
264
+ description?: string
265
+
266
+ /**
267
+ * The schema for the response format, described as a JSON Schema object.
268
+ * @see https://json-schema.org/
269
+ */
270
+ schema?: { [key: string]: unknown }
271
+
272
+ /**
273
+ * Whether to enable strict schema adherence when generating the output. If set to
274
+ * true, the model will always follow the exact schema defined in the `schema`
275
+ * field. Only a subset of JSON Schema is supported when `strict` is `true`.
276
+ */
277
+ strict?: boolean | null
278
+ }
279
+
280
+ export interface ResponseFormatJsonSchema {
281
+ /** Structured Outputs configuration options, including a JSON Schema. */
282
+ json_schema: ResponseFormatJsonSchemaJsonSchema
283
+
284
+ /** The type of response format being defined. Always `json_schema`. */
285
+ type: 'json_schema'
286
+ }
287
+
288
+ export interface ResponseFormatJsonObject {
289
+ /** The type of response format being defined. Always `json_object`. */
290
+ type: 'json_object'
291
+ }
292
+
293
+ export interface SearchSettings {
294
+ /**
295
+ * Name of country to prioritize search results from
296
+ * (e.g., "united states", "germany", "france").
297
+ */
298
+ country?: string | null
299
+
300
+ /** A list of domains to exclude from the search results. */
301
+ exclude_domains?: Array<string> | null
302
+
303
+ /** A list of domains to include in the search results. */
304
+ include_domains?: Array<string> | null
305
+
306
+ /** Whether to include images in the search results. */
307
+ include_images?: boolean | null
308
+ }
309
+
310
+ /**
311
+ * Metadata for Groq document content parts.
312
+ */
313
+ export interface GroqDocumentMetadata {}
314
+
315
+ /**
316
+ * Metadata for Groq text content parts.
317
+ * Currently no specific metadata options for text in Groq.
318
+ */
319
+ export interface GroqTextMetadata {}
320
+
321
+ /**
322
+ * Metadata for Groq image content parts.
323
+ * Controls how the model processes and analyzes images.
324
+ */
325
+ export interface GroqImageMetadata {
326
+ /**
327
+ * Specifies the detail level of the image.
328
+ * - 'auto': Let the model decide based on image size and content
329
+ * - 'low': Use low resolution processing (faster, cheaper, less detail)
330
+ * - 'high': Use high resolution processing (slower, more expensive, more detail)
331
+ *
332
+ * @default 'auto'
333
+ */
334
+ detail?: 'auto' | 'low' | 'high'
335
+ }
336
+
337
+ /**
338
+ * Metadata for Groq audio content parts.
339
+ * Note: Audio support in Groq is limited; check current API capabilities.
340
+ */
341
+ export interface GroqAudioMetadata {}
342
+
343
+ /**
344
+ * Metadata for Groq video content parts.
345
+ * Note: Groq does not currently support video input.
346
+ */
347
+ export interface GroqVideoMetadata {}
348
+
349
+ /**
350
+ * Map of modality types to their Groq-specific metadata types.
351
+ * Used for type inference when constructing multimodal messages.
352
+ */
353
+ export interface GroqMessageMetadataByModality {
354
+ text: GroqTextMetadata
355
+ image: GroqImageMetadata
356
+ audio: GroqAudioMetadata
357
+ video: GroqVideoMetadata
358
+ document: GroqDocumentMetadata
359
+ }