@tstdl/base 0.92.22 → 0.92.24
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/ai/ai.service.js +6 -1
- package/ai/types.d.ts +4 -3
- package/ai/types.js +2 -6
- package/package.json +1 -1
- package/schema/converters/openapi-converter.js +1 -1
package/ai/ai.service.js
CHANGED
|
@@ -262,6 +262,10 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
|
|
|
262
262
|
}
|
|
263
263
|
async convertFunctions(functions) {
|
|
264
264
|
const mapped = mapAsync(objectEntries(functions), async ([name, declaration]) => {
|
|
265
|
+
const enabled = await resolveValueOrAsyncProvider(declaration.enabled);
|
|
266
|
+
if (enabled == false) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
265
269
|
const parametersSchema = await resolveValueOrAsyncProvider(declaration.parameters);
|
|
266
270
|
return {
|
|
267
271
|
name,
|
|
@@ -269,7 +273,8 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
|
|
|
269
273
|
parameters: convertToOpenApiSchema(parametersSchema)
|
|
270
274
|
};
|
|
271
275
|
});
|
|
272
|
-
|
|
276
|
+
const functionsArray = await toArrayAsync(mapped);
|
|
277
|
+
return functionsArray.filter(isDefined);
|
|
273
278
|
}
|
|
274
279
|
convertGoogleContent(content) {
|
|
275
280
|
return {
|
package/ai/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LiteralUnion } from 'type-fest';
|
|
2
|
-
import type
|
|
2
|
+
import { type ObjectSchema, type SchemaOutput, type SchemaTestable } from '../schema/index.js';
|
|
3
3
|
import type { Record, UndefinableJsonObject } from '../types.js';
|
|
4
4
|
import type { ResolvedValueOrProvider, ValueOrAsyncProvider } from '../utils/value-or-provider.js';
|
|
5
5
|
export type FileInput = {
|
|
@@ -10,6 +10,7 @@ export type SchemaFunctionDeclarations = Record<string, SchemaFunctionDeclaratio
|
|
|
10
10
|
export type SchemaFunctionDeclarationWithoutHandler<T extends Record = Record> = {
|
|
11
11
|
description: string;
|
|
12
12
|
parameters: ValueOrAsyncProvider<ObjectSchema<T>>;
|
|
13
|
+
enabled?: ValueOrAsyncProvider<boolean>;
|
|
13
14
|
};
|
|
14
15
|
export type SchemaFunctionDeclarationWithHandler<T extends Record = Record, R = unknown> = SchemaFunctionDeclarationWithoutHandler<T> & {
|
|
15
16
|
handler: (parameters: T) => R | Promise<R>;
|
|
@@ -83,6 +84,6 @@ export type GenerationResult = {
|
|
|
83
84
|
usage: GenerationUsage;
|
|
84
85
|
};
|
|
85
86
|
export declare function defineFunctions<T extends SchemaFunctionDeclarations>(declarations: T): T;
|
|
86
|
-
export declare function defineFunction<T extends
|
|
87
|
-
export declare function defineFunction<T extends
|
|
87
|
+
export declare function defineFunction<T extends SchemaFunctionDeclarationWithHandler>(declaration: T): T;
|
|
88
|
+
export declare function defineFunction<T extends SchemaFunctionDeclarationWithoutHandler>(declaration: T): T;
|
|
88
89
|
export declare function isSchemaFunctionDeclarationWithHandler(declaration: SchemaFunctionDeclaration): declaration is SchemaFunctionDeclarationWithHandler;
|
package/ai/types.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { hasOwnProperty } from '../utils/object/object.js';
|
|
2
|
-
import { isDefined } from '../utils/type-guards.js';
|
|
3
2
|
export function defineFunctions(declarations) {
|
|
4
3
|
return declarations;
|
|
5
4
|
}
|
|
6
|
-
export function defineFunction(
|
|
7
|
-
|
|
8
|
-
return { description, parameters, handler };
|
|
9
|
-
}
|
|
10
|
-
return { description, parameters };
|
|
5
|
+
export function defineFunction(declaration) {
|
|
6
|
+
return declaration;
|
|
11
7
|
}
|
|
12
8
|
export function isSchemaFunctionDeclarationWithHandler(declaration) {
|
|
13
9
|
return hasOwnProperty(declaration, 'handler');
|
package/package.json
CHANGED
|
@@ -75,7 +75,7 @@ function convertToOpenApiSchemaBase(schema) {
|
|
|
75
75
|
if (schema instanceof EnumerationSchema) {
|
|
76
76
|
const hasString = schema.allowedValues.some(isString);
|
|
77
77
|
const hasNumber = schema.allowedValues.some(isNumber);
|
|
78
|
-
if (hasString && hasNumber) {
|
|
78
|
+
if (!hasString && !hasNumber) {
|
|
79
79
|
throw new NotSupportedError('Enum must be either string or number but not both.');
|
|
80
80
|
}
|
|
81
81
|
return {
|