@tanstack/ai-groq 0.5.2 → 0.5.4
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.
- package/dist/esm/adapters/text.js +89 -61
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/adapters/transcription.js +210 -172
- package/dist/esm/adapters/transcription.js.map +1 -1
- package/dist/esm/adapters/tts.js +128 -66
- package/dist/esm/adapters/tts.js.map +1 -1
- package/dist/esm/audio/audio-provider-options.js +11 -8
- package/dist/esm/audio/audio-provider-options.js.map +1 -1
- package/dist/esm/index.js +1 -15
- package/dist/esm/model-meta.js +300 -69
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/tools/function-tool.js +31 -26
- package/dist/esm/tools/function-tool.js.map +1 -1
- package/dist/esm/tools/index.js +1 -5
- package/dist/esm/tools/tool-converter.js +12 -7
- package/dist/esm/tools/tool-converter.js.map +1 -1
- package/dist/esm/utils/client.js +23 -16
- package/dist/esm/utils/client.js.map +1 -1
- package/dist/esm/utils/schema-converter.d.ts +0 -2
- package/dist/esm/utils/schema-converter.js +66 -66
- package/dist/esm/utils/schema-converter.js.map +1 -1
- package/package.json +7 -7
- package/src/utils/schema-converter.ts +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/tools/index.js.map +0 -1
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
import { makeStructuredOutputCompatible } from "@tanstack/openai-base";
|
|
2
|
-
|
|
2
|
+
//#region src/utils/schema-converter.ts
|
|
3
|
+
/**
|
|
4
|
+
* Recursively removes `required: []` from a schema object.
|
|
5
|
+
* Groq rejects `required` when it is an empty array, even though
|
|
6
|
+
* OpenAI-compatible schemas allow it.
|
|
7
|
+
*/
|
|
3
8
|
function removeEmptyRequired(schema) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
for (const keyword of ["anyOf", "oneOf", "allOf"]) {
|
|
21
|
-
if (Array.isArray(result[keyword])) {
|
|
22
|
-
result[keyword] = result[keyword].map(
|
|
23
|
-
(entry) => removeEmptyRequired(entry)
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties)) {
|
|
28
|
-
result.additionalProperties = removeEmptyRequired(
|
|
29
|
-
result.additionalProperties
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
9
|
+
const result = { ...schema };
|
|
10
|
+
if (Array.isArray(result.required) && result.required.length === 0) delete result.required;
|
|
11
|
+
if (result.properties && typeof result.properties === "object") {
|
|
12
|
+
const properties = {};
|
|
13
|
+
for (const [key, value] of Object.entries(result.properties)) properties[key] = typeof value === "object" && value !== null && !Array.isArray(value) ? removeEmptyRequired(value) : value;
|
|
14
|
+
result.properties = properties;
|
|
15
|
+
}
|
|
16
|
+
if (result.items && typeof result.items === "object" && !Array.isArray(result.items)) result.items = removeEmptyRequired(result.items);
|
|
17
|
+
for (const keyword of [
|
|
18
|
+
"anyOf",
|
|
19
|
+
"oneOf",
|
|
20
|
+
"allOf"
|
|
21
|
+
]) if (Array.isArray(result[keyword])) result[keyword] = result[keyword].map((entry) => removeEmptyRequired(entry));
|
|
22
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties)) result.additionalProperties = removeEmptyRequired(result.additionalProperties);
|
|
23
|
+
return result;
|
|
33
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Recursively normalise object schemas so any `{ type: 'object' }` node
|
|
27
|
+
* without `properties` gets an empty `properties: {}` object. The
|
|
28
|
+
* ai-openai-base transformer only descends into objects that already have
|
|
29
|
+
* `properties` set, so a Zod `z.object({})` nested inside `properties`,
|
|
30
|
+
* `items`, `additionalProperties`, or a combinator branch would otherwise
|
|
31
|
+
* skip the strict-mode rewrite and fail Groq validation.
|
|
32
|
+
*/
|
|
34
33
|
function normalizeObjectSchemas(schema) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (Array.isArray(branch)) {
|
|
52
|
-
result[keyword] = branch.map(
|
|
53
|
-
(entry) => typeof entry === "object" && entry !== null ? normalizeObjectSchemas(entry) : entry
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties)) {
|
|
58
|
-
result.additionalProperties = normalizeObjectSchemas(
|
|
59
|
-
result.additionalProperties
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
34
|
+
const result = schema.type === "object" && !schema.properties ? {
|
|
35
|
+
...schema,
|
|
36
|
+
properties: {}
|
|
37
|
+
} : { ...schema };
|
|
38
|
+
if (result.properties && typeof result.properties === "object") result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, typeof value === "object" && value !== null && !Array.isArray(value) ? normalizeObjectSchemas(value) : value]));
|
|
39
|
+
if (result.items && typeof result.items === "object" && !Array.isArray(result.items)) result.items = normalizeObjectSchemas(result.items);
|
|
40
|
+
for (const keyword of [
|
|
41
|
+
"anyOf",
|
|
42
|
+
"oneOf",
|
|
43
|
+
"allOf"
|
|
44
|
+
]) {
|
|
45
|
+
const branch = result[keyword];
|
|
46
|
+
if (Array.isArray(branch)) result[keyword] = branch.map((entry) => typeof entry === "object" && entry !== null ? normalizeObjectSchemas(entry) : entry);
|
|
47
|
+
}
|
|
48
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object" && !Array.isArray(result.additionalProperties)) result.additionalProperties = normalizeObjectSchemas(result.additionalProperties);
|
|
49
|
+
return result;
|
|
63
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Transform a JSON schema to be compatible with Groq's structured output requirements.
|
|
53
|
+
*
|
|
54
|
+
* Groq requires:
|
|
55
|
+
* - All properties must be in the `required` array
|
|
56
|
+
* - Optional fields should have null added to their type union
|
|
57
|
+
* - additionalProperties must be false for objects
|
|
58
|
+
* - `required` must be omitted (not empty array) when there are no properties
|
|
59
|
+
*
|
|
60
|
+
* Delegates to the shared OpenAI-compatible transformer and applies the
|
|
61
|
+
* Groq-specific quirk of removing empty `required` arrays.
|
|
62
|
+
*
|
|
63
|
+
* @param schema - JSON schema to transform
|
|
64
|
+
* @param originalRequired - Original required array (to know which fields were optional)
|
|
65
|
+
* @returns Transformed schema compatible with Groq structured output
|
|
66
|
+
*/
|
|
64
67
|
function makeGroqStructuredOutputCompatible(schema, originalRequired = []) {
|
|
65
|
-
|
|
66
|
-
const result = makeStructuredOutputCompatible(normalised, originalRequired);
|
|
67
|
-
return removeEmptyRequired(result);
|
|
68
|
+
return removeEmptyRequired(makeStructuredOutputCompatible(normalizeObjectSchemas(schema), originalRequired));
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
//# sourceMappingURL=schema-converter.js.map
|
|
70
|
+
//#endregion
|
|
71
|
+
export { makeGroqStructuredOutputCompatible };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=schema-converter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-converter.js","sources":["../../../src/utils/schema-converter.ts"],"sourcesContent":["import { makeStructuredOutputCompatible } from '@tanstack/openai-base'\
|
|
1
|
+
{"version":3,"file":"schema-converter.js","names":[],"sources":["../../../src/utils/schema-converter.ts"],"sourcesContent":["import { makeStructuredOutputCompatible } from '@tanstack/openai-base'\n\n/**\n * Recursively removes `required: []` from a schema object.\n * Groq rejects `required` when it is an empty array, even though\n * OpenAI-compatible schemas allow it.\n */\nfunction removeEmptyRequired(schema: Record<string, any>): Record<string, any> {\n const result = { ...schema }\n\n if (Array.isArray(result.required) && result.required.length === 0) {\n delete result.required\n }\n\n if (result.properties && typeof result.properties === 'object') {\n const properties: Record<string, any> = {}\n for (const [key, value] of Object.entries(\n result.properties as Record<string, any>,\n )) {\n properties[key] =\n typeof value === 'object' && value !== null && !Array.isArray(value)\n ? removeEmptyRequired(value)\n : value\n }\n result.properties = properties\n }\n\n if (\n result.items &&\n typeof result.items === 'object' &&\n !Array.isArray(result.items)\n ) {\n result.items = removeEmptyRequired(result.items)\n }\n\n // Recurse into combinator arrays (anyOf, oneOf, allOf)\n for (const keyword of ['anyOf', 'oneOf', 'allOf'] as const) {\n if (Array.isArray(result[keyword])) {\n result[keyword] = result[keyword].map((entry: Record<string, any>) =>\n removeEmptyRequired(entry),\n )\n }\n }\n\n // Recurse into additionalProperties if it's a schema object\n if (\n result.additionalProperties &&\n typeof result.additionalProperties === 'object' &&\n !Array.isArray(result.additionalProperties)\n ) {\n result.additionalProperties = removeEmptyRequired(\n result.additionalProperties,\n )\n }\n\n return result\n}\n\n/**\n * Recursively normalise object schemas so any `{ type: 'object' }` node\n * without `properties` gets an empty `properties: {}` object. The\n * ai-openai-base transformer only descends into objects that already have\n * `properties` set, so a Zod `z.object({})` nested inside `properties`,\n * `items`, `additionalProperties`, or a combinator branch would otherwise\n * skip the strict-mode rewrite and fail Groq validation.\n */\nfunction normalizeObjectSchemas(\n schema: Record<string, any>,\n): Record<string, any> {\n const result: Record<string, any> =\n schema.type === 'object' && !schema.properties\n ? { ...schema, properties: {} }\n : { ...schema }\n\n if (result.properties && typeof result.properties === 'object') {\n result.properties = Object.fromEntries(\n Object.entries(result.properties as Record<string, any>).map(\n ([key, value]) => [\n key,\n typeof value === 'object' && value !== null && !Array.isArray(value)\n ? normalizeObjectSchemas(value)\n : value,\n ],\n ),\n )\n }\n\n if (\n result.items &&\n typeof result.items === 'object' &&\n !Array.isArray(result.items)\n ) {\n result.items = normalizeObjectSchemas(result.items)\n }\n\n for (const keyword of ['anyOf', 'oneOf', 'allOf'] as const) {\n const branch = result[keyword]\n if (Array.isArray(branch)) {\n result[keyword] = branch.map((entry) =>\n typeof entry === 'object' && entry !== null\n ? normalizeObjectSchemas(entry as Record<string, any>)\n : entry,\n )\n }\n }\n\n if (\n result.additionalProperties &&\n typeof result.additionalProperties === 'object' &&\n !Array.isArray(result.additionalProperties)\n ) {\n result.additionalProperties = normalizeObjectSchemas(\n result.additionalProperties as Record<string, any>,\n )\n }\n\n return result\n}\n\n/**\n * Transform a JSON schema to be compatible with Groq's structured output requirements.\n *\n * Groq requires:\n * - All properties must be in the `required` array\n * - Optional fields should have null added to their type union\n * - additionalProperties must be false for objects\n * - `required` must be omitted (not empty array) when there are no properties\n *\n * Delegates to the shared OpenAI-compatible transformer and applies the\n * Groq-specific quirk of removing empty `required` arrays.\n *\n * @param schema - JSON schema to transform\n * @param originalRequired - Original required array (to know which fields were optional)\n * @returns Transformed schema compatible with Groq structured output\n */\nexport function makeGroqStructuredOutputCompatible(\n schema: Record<string, any>,\n originalRequired: Array<string> = [],\n): Record<string, any> {\n // Recursively patch every `{ type: 'object' }` node so the ai-openai-base\n // transformer descends into nested empty objects too.\n const normalised = normalizeObjectSchemas(schema)\n\n const result = makeStructuredOutputCompatible(normalised, originalRequired)\n\n // Groq rejects `required` when it is an empty array\n return removeEmptyRequired(result)\n}\n"],"mappings":";;;;;;;AAOA,SAAS,oBAAoB,QAAkD;CAC7E,MAAM,SAAS,EAAE,GAAG,OAAO;CAE3B,IAAI,MAAM,QAAQ,OAAO,QAAQ,KAAK,OAAO,SAAS,WAAW,GAC/D,OAAO,OAAO;CAGhB,IAAI,OAAO,cAAc,OAAO,OAAO,eAAe,UAAU;EAC9D,MAAM,aAAkC,CAAC;EACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QACh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,YAAY,UAAU,OACnC,uBAAuB,KAA4B,IACnD,KACN;CAEJ;CAEA,IACE,OAAO,wBACP,OAAO,OAAO,yBAAyB,YACvC,CAAC,MAAM,QAAQ,OAAO,oBAAoB,GAE1C,OAAO,uBAAuB,uBAC5B,OAAO,oBACT;CAGF,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,SAAgB,mCACd,QACA,mBAAkC,CAAC,GACd;CAQrB,OAAO,oBAHQ,+BAFI,uBAAuB,MAEI,GAAY,gBAG/B,CAAM;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-groq",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Groq adapter for TanStack AI low-latency chat, tool calling, and structured outputs.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,23 +49,23 @@
|
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@vitest/coverage-v8": "4.0.14",
|
|
52
|
-
"vite": "^
|
|
52
|
+
"vite": "^8.1.4"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"zod": "^4.0.0",
|
|
56
|
-
"@tanstack/ai": "^0.
|
|
56
|
+
"@tanstack/ai": "^0.43.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"openai": "^6.41.0",
|
|
60
|
-
"@tanstack/ai-utils": "0.
|
|
61
|
-
"@tanstack/openai-base": "0.9.
|
|
60
|
+
"@tanstack/ai-utils": "0.4.0",
|
|
61
|
+
"@tanstack/openai-base": "0.9.10"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "vite build",
|
|
65
65
|
"clean": "premove ./build ./dist",
|
|
66
|
-
"lint:fix": "
|
|
66
|
+
"lint:fix": "oxlint src --type-aware --fix",
|
|
67
67
|
"test:build": "publint --strict",
|
|
68
|
-
"test:
|
|
68
|
+
"test:oxlint": "oxlint src --type-aware",
|
|
69
69
|
"test:lib": "vitest run",
|
|
70
70
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
71
71
|
"test:types": "tsc"
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|