ai-functions 0.2.13 → 0.2.14
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/cjs/utils/schema.js +13 -0
- package/dist/mjs/utils/schema.js +13 -0
- package/package.json +1 -1
- package/utils/schema.ts +12 -0
package/dist/cjs/utils/schema.js
CHANGED
|
@@ -55,6 +55,19 @@ const generateSchema = (propDescriptions) => {
|
|
|
55
55
|
// Recursive call for nested objects
|
|
56
56
|
properties[key] = (0, exports.generateSchema)(description);
|
|
57
57
|
}
|
|
58
|
+
else if (Array.isArray(description)) {
|
|
59
|
+
// Recursive call for nested objects
|
|
60
|
+
const [itemValue] = description;
|
|
61
|
+
const itemType = typeof itemValue;
|
|
62
|
+
if (itemType == 'string') {
|
|
63
|
+
// If the item is a string, then it is an array of strings
|
|
64
|
+
return { type: 'array', description: itemValue, items: { type: 'string' } };
|
|
65
|
+
}
|
|
66
|
+
else if (itemType == 'object') {
|
|
67
|
+
// If the item is an object, then it is an array of objects, and get the schema for the object
|
|
68
|
+
return { type: 'array', items: (0, exports.generateSchema)(itemValue) };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
else {
|
|
59
72
|
throw new Error(`Invalid description for key "${key}".`);
|
|
60
73
|
}
|
package/dist/mjs/utils/schema.js
CHANGED
|
@@ -51,6 +51,19 @@ export const generateSchema = (propDescriptions) => {
|
|
|
51
51
|
// Recursive call for nested objects
|
|
52
52
|
properties[key] = generateSchema(description);
|
|
53
53
|
}
|
|
54
|
+
else if (Array.isArray(description)) {
|
|
55
|
+
// Recursive call for nested objects
|
|
56
|
+
const [itemValue] = description;
|
|
57
|
+
const itemType = typeof itemValue;
|
|
58
|
+
if (itemType == 'string') {
|
|
59
|
+
// If the item is a string, then it is an array of strings
|
|
60
|
+
return { type: 'array', description: itemValue, items: { type: 'string' } };
|
|
61
|
+
}
|
|
62
|
+
else if (itemType == 'object') {
|
|
63
|
+
// If the item is an object, then it is an array of objects, and get the schema for the object
|
|
64
|
+
return { type: 'array', items: generateSchema(itemValue) };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
54
67
|
else {
|
|
55
68
|
throw new Error(`Invalid description for key "${key}".`);
|
|
56
69
|
}
|
package/package.json
CHANGED
package/utils/schema.ts
CHANGED
|
@@ -53,6 +53,18 @@ export const generateSchema = (propDescriptions: Record<string, string | Record<
|
|
|
53
53
|
} else if (typeof description === 'object' && !Array.isArray(description)) {
|
|
54
54
|
// Recursive call for nested objects
|
|
55
55
|
properties[key] = generateSchema(description)
|
|
56
|
+
|
|
57
|
+
} else if (Array.isArray(description)) {
|
|
58
|
+
// Recursive call for nested objects
|
|
59
|
+
const [ itemValue ] = description
|
|
60
|
+
const itemType = typeof itemValue
|
|
61
|
+
if (itemType == 'string') {
|
|
62
|
+
// If the item is a string, then it is an array of strings
|
|
63
|
+
return { type: 'array', description: itemValue, items: { type: 'string' }}
|
|
64
|
+
} else if (itemType == 'object') {
|
|
65
|
+
// If the item is an object, then it is an array of objects, and get the schema for the object
|
|
66
|
+
return { type: 'array', items: generateSchema(itemValue)}
|
|
67
|
+
}
|
|
56
68
|
} else {
|
|
57
69
|
throw new Error(`Invalid description for key "${key}".`)
|
|
58
70
|
}
|