@tstdl/base 0.92.21 → 0.92.23

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 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
- return toArrayAsync(mapped);
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
@@ -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>;
@@ -82,7 +83,7 @@ export type GenerationResult = {
82
83
  finishReason: FinishReason;
83
84
  usage: GenerationUsage;
84
85
  };
85
- export declare function declareFunctions<T extends SchemaFunctionDeclarations>(declarations: T): T;
86
- export declare function declareFunction<T extends Record = Record>(description: string, parameters: ObjectSchema<T>): SchemaFunctionDeclaration<T, never>;
87
- export declare function declareFunction<T extends Record = Record, R = never>(description: string, parameters: ObjectSchema<T>, handler: (parameters: T) => R | Promise<R>): SchemaFunctionDeclaration<T, R>;
86
+ export declare function defineFunctions<T extends SchemaFunctionDeclarations>(declarations: T): T;
87
+ export declare function defineFunction<T extends Record = Record>(description: string, parameters: ValueOrAsyncProvider<ObjectSchema<T>>): SchemaFunctionDeclaration<T, never>;
88
+ export declare function defineFunction<T extends Record = Record, R = never>(description: string, parameters: ValueOrAsyncProvider<ObjectSchema<T>>, handler: (parameters: T) => R | Promise<R>): SchemaFunctionDeclaration<T, R>;
88
89
  export declare function isSchemaFunctionDeclarationWithHandler(declaration: SchemaFunctionDeclaration): declaration is SchemaFunctionDeclarationWithHandler;
package/ai/types.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { hasOwnProperty } from '../utils/object/object.js';
2
2
  import { isDefined } from '../utils/type-guards.js';
3
- export function declareFunctions(declarations) {
3
+ export function defineFunctions(declarations) {
4
4
  return declarations;
5
5
  }
6
- export function declareFunction(description, parameters, handler) {
6
+ export function defineFunction(description, parameters, handler) {
7
7
  if (isDefined(handler)) {
8
8
  return { description, parameters, handler };
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.21",
3
+ "version": "0.92.23",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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 {