ai-functions 0.2.16 → 0.2.18
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/mjs/functions/ai.d.ts +2 -0
- package/dist/mjs/functions/ai.js +7 -3
- package/dist/mjs/functions/ai.test.js +4 -4
- package/functions/ai.test.ts +4 -4
- package/functions/ai.ts +7 -3
- package/package.json +1 -1
- package/dist/cjs/db/cache.d.ts +0 -1
- package/dist/cjs/db/cache.js +0 -12
- package/dist/cjs/db/mongo.d.ts +0 -31
- package/dist/cjs/db/mongo.js +0 -47
- package/dist/cjs/examples/data.d.ts +0 -1105
- package/dist/cjs/examples/data.js +0 -1108
- package/dist/cjs/functions/ai.d.ts +0 -18
- package/dist/cjs/functions/ai.js +0 -99
- package/dist/cjs/functions/ai.test.d.ts +0 -1
- package/dist/cjs/functions/ai.test.js +0 -40
- package/dist/cjs/functions/gpt.d.ts +0 -4
- package/dist/cjs/functions/gpt.js +0 -24
- package/dist/cjs/functions/list.d.ts +0 -7
- package/dist/cjs/functions/list.js +0 -134
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/queue/kafka.d.ts +0 -0
- package/dist/cjs/queue/kafka.js +0 -1
- package/dist/cjs/queue/memory.d.ts +0 -0
- package/dist/cjs/queue/memory.js +0 -1
- package/dist/cjs/queue/mongo.d.ts +0 -30
- package/dist/cjs/queue/mongo.js +0 -69
- package/dist/cjs/streams/kafka.d.ts +0 -0
- package/dist/cjs/streams/kafka.js +0 -1
- package/dist/cjs/streams/memory.d.ts +0 -0
- package/dist/cjs/streams/memory.js +0 -1
- package/dist/cjs/streams/mongo.d.ts +0 -0
- package/dist/cjs/streams/mongo.js +0 -1
- package/dist/cjs/streams/types.d.ts +0 -0
- package/dist/cjs/streams/types.js +0 -1
- package/dist/cjs/types.d.ts +0 -11
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/utils/completion.d.ts +0 -9
- package/dist/cjs/utils/completion.js +0 -45
- package/dist/cjs/utils/schema.d.ts +0 -10
- package/dist/cjs/utils/schema.js +0 -77
- package/dist/cjs/utils/schema.test.d.ts +0 -1
- package/dist/cjs/utils/schema.test.js +0 -62
- package/dist/cjs/utils/state.d.ts +0 -1
- package/dist/cjs/utils/state.js +0 -21
- package/dist/mjs/package.json +0 -3
package/dist/cjs/utils/schema.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateSchema = exports.parseStringDescription = void 0;
|
|
4
|
-
// This is a helper function to generate a JSON schema for string properties.
|
|
5
|
-
// It checks if a string includes '|' which would indicate an enum,
|
|
6
|
-
// or if it starts with 'number: ' or 'boolean: ' which would indicate
|
|
7
|
-
// a number or boolean type respectively, otherwise it defaults to string.
|
|
8
|
-
const parseStringDescription = (description) => {
|
|
9
|
-
// Check if the description indicates an enum for string type
|
|
10
|
-
if (description.includes('|')) {
|
|
11
|
-
return { type: 'string', enum: description.split('|').map((v) => v.trim()) };
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
// Check for 'number: ' prefix
|
|
15
|
-
if (description.startsWith('number: ')) {
|
|
16
|
-
return {
|
|
17
|
-
type: 'number',
|
|
18
|
-
description: description.replace('number: ', ''),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
// Check for 'boolean: ' prefix
|
|
22
|
-
else if (description.startsWith('boolean: ')) {
|
|
23
|
-
return {
|
|
24
|
-
type: 'boolean',
|
|
25
|
-
description: description.replace('boolean: ', ''),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
// Default to string type
|
|
29
|
-
else {
|
|
30
|
-
return { type: 'string', description };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
exports.parseStringDescription = parseStringDescription;
|
|
35
|
-
/**
|
|
36
|
-
* Given a property description object, generate a JSON schema.
|
|
37
|
-
*
|
|
38
|
-
* @param propDescriptions - A record object with keys as property names
|
|
39
|
-
* and values as descriptions or nested property description objects.
|
|
40
|
-
* @returns A JSON schema object based on the provided descriptions.
|
|
41
|
-
*/
|
|
42
|
-
const generateSchema = (propDescriptions) => {
|
|
43
|
-
// If the propDescriptions is for an object structure
|
|
44
|
-
if (typeof propDescriptions !== 'object' || propDescriptions === null || Array.isArray(propDescriptions)) {
|
|
45
|
-
throw new Error('The propDescriptions parameter should be an object.');
|
|
46
|
-
}
|
|
47
|
-
const properties = {};
|
|
48
|
-
const required = Object.keys(propDescriptions);
|
|
49
|
-
for (const [key, description] of Object.entries(propDescriptions)) {
|
|
50
|
-
if (typeof description === 'string') {
|
|
51
|
-
// Handle the string description
|
|
52
|
-
properties[key] = (0, exports.parseStringDescription)(description);
|
|
53
|
-
}
|
|
54
|
-
else if (typeof description === 'object' && !Array.isArray(description)) {
|
|
55
|
-
// Recursive call for nested objects
|
|
56
|
-
properties[key] = (0, exports.generateSchema)(description);
|
|
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
|
-
properties[key] = { 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
|
-
properties[key] = { type: 'array', items: (0, exports.generateSchema)(itemValue) };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new Error(`Invalid description for key "${key}".`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return { type: 'object', properties, required };
|
|
76
|
-
};
|
|
77
|
-
exports.generateSchema = generateSchema;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const schema_1 = require("./schema");
|
|
5
|
-
// Tests for parseStringDescription function
|
|
6
|
-
(0, vitest_1.describe)('parseStringDescription', () => {
|
|
7
|
-
(0, vitest_1.it)('should create a string schema for plain strings', () => {
|
|
8
|
-
const result = (0, schema_1.parseStringDescription)('A plain string description');
|
|
9
|
-
(0, vitest_1.expect)(result).toEqual({
|
|
10
|
-
type: 'string',
|
|
11
|
-
description: 'A plain string description',
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
(0, vitest_1.it)('should create a string schema with enum for piped strings', () => {
|
|
15
|
-
const result = (0, schema_1.parseStringDescription)('option1 | option2 | option3');
|
|
16
|
-
(0, vitest_1.expect)(result).toEqual({
|
|
17
|
-
type: 'string',
|
|
18
|
-
enum: ['option1', 'option2', 'option3'],
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
(0, vitest_1.it)('should create a number schema when prefixed with "number: "', () => {
|
|
22
|
-
const result = (0, schema_1.parseStringDescription)('number: A number description');
|
|
23
|
-
(0, vitest_1.expect)(result).toEqual({
|
|
24
|
-
type: 'number',
|
|
25
|
-
description: 'A number description',
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
(0, vitest_1.it)('should create a boolean schema when prefixed with "boolean: "', () => {
|
|
29
|
-
const result = (0, schema_1.parseStringDescription)('boolean: A boolean description');
|
|
30
|
-
(0, vitest_1.expect)(result).toEqual({
|
|
31
|
-
type: 'boolean',
|
|
32
|
-
description: 'A boolean description',
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
// Tests for generateSchema function
|
|
37
|
-
(0, vitest_1.describe)('generateSchema', () => {
|
|
38
|
-
(0, vitest_1.it)('should create a complex object schema', () => {
|
|
39
|
-
const result = (0, schema_1.generateSchema)({
|
|
40
|
-
name: 'The name of the person',
|
|
41
|
-
age: 'number: The age of the person',
|
|
42
|
-
isActive: 'boolean: Whether the person is active or not',
|
|
43
|
-
});
|
|
44
|
-
const expected = {
|
|
45
|
-
type: 'object',
|
|
46
|
-
properties: {
|
|
47
|
-
name: { type: 'string', description: 'The name of the person' },
|
|
48
|
-
age: { type: 'number', description: 'The age of the person' },
|
|
49
|
-
isActive: {
|
|
50
|
-
type: 'boolean',
|
|
51
|
-
description: 'Whether the person is active or not',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
required: ['name', 'age', 'isActive'],
|
|
55
|
-
};
|
|
56
|
-
(0, vitest_1.expect)(result).toEqual(expected);
|
|
57
|
-
});
|
|
58
|
-
(0, vitest_1.it)('should throw an error for invalid propDescriptions', () => {
|
|
59
|
-
const callWithInvalidArg = () => (0, schema_1.generateSchema)('invalid argument');
|
|
60
|
-
(0, vitest_1.expect)(callWithInvalidArg).toThrow('The propDescriptions parameter should be an object.');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/cjs/utils/state.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const xstate_1 = require("xstate");
|
|
4
|
-
// Stateless machine definition
|
|
5
|
-
// machine.transition(...) is a pure function used by the interpreter.
|
|
6
|
-
const toggleMachine = (0, xstate_1.createMachine)({
|
|
7
|
-
id: 'Switch',
|
|
8
|
-
initial: 'inactive',
|
|
9
|
-
states: {
|
|
10
|
-
inactive: { on: { Toggle: 'active' } },
|
|
11
|
-
active: { on: { Toggle: 'inactive' } },
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
// Machine instance with internal state
|
|
15
|
-
const toggleService = (0, xstate_1.createActor)(toggleMachine).start();
|
|
16
|
-
toggleService.subscribe((state) => console.log(state.value));
|
|
17
|
-
// => 'inactive'
|
|
18
|
-
toggleService.send({ type: 'Toggle' });
|
|
19
|
-
// => 'active'
|
|
20
|
-
toggleService.send({ type: 'Toggle' });
|
|
21
|
-
// => 'inactive'
|
package/dist/mjs/package.json
DELETED