@tstdl/base 0.92.20 → 0.92.21

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.
@@ -33,6 +33,7 @@ export declare class AiService implements Resolvable<AiServiceArgument> {
33
33
  createSession(): AiSession;
34
34
  processFile(fileInput: FileInput): Promise<FileContentPart>;
35
35
  processFiles(fileInputs: FileInput[]): Promise<FileContentPart[]>;
36
+ getFileById(id: string): FileContentPart;
36
37
  classify<T extends EnumerationType>(parts: OneOrMany<ContentPart>, types: T, options?: GenerationOptions & Pick<GenerationRequest, 'model'>): Promise<SpecializedGenerationResult<ClassificationResult<T>>>;
37
38
  getClassifyConents(parts: OneOrMany<ContentPart>): Content[];
38
39
  extractData<T>(parts: OneOrMany<ContentPart>, schema: SchemaTestable<T>, options?: GenerationOptions & Pick<GenerationRequest, 'model'>): Promise<SpecializedGenerationResult<T>>;
package/ai/ai.service.js CHANGED
@@ -11,8 +11,11 @@ import { inject, injectArgument } from '../injector/inject.js';
11
11
  import { convertToOpenApiSchema } from '../schema/converters/openapi-converter.js';
12
12
  import { array, enumeration, nullable, object, string } from '../schema/index.js';
13
13
  import { toArray } from '../utils/array/array.js';
14
+ import { mapAsync } from '../utils/async-iterable-helpers/map.js';
15
+ import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
14
16
  import { hasOwnProperty, objectEntries } from '../utils/object/object.js';
15
17
  import { assertDefinedPass, assertNotNullPass, isDefined } from '../utils/type-guards.js';
18
+ import { resolveValueOrAsyncProvider } from '../utils/value-or-provider.js';
16
19
  import { AiFileService } from './ai-file.service.js';
17
20
  import { AiSession } from './ai-session.js';
18
21
  import { isSchemaFunctionDeclarationWithHandler } from './types.js';
@@ -40,6 +43,9 @@ let AiService = class AiService {
40
43
  async processFiles(fileInputs) {
41
44
  return this.#fileService.processFiles(fileInputs);
42
45
  }
46
+ getFileById(id) {
47
+ return { file: id };
48
+ }
43
49
  async classify(parts, types, options) {
44
50
  const generationSchema = object({
45
51
  types: nullable(array(object({
@@ -155,7 +161,8 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
155
161
  const result = [];
156
162
  for (const call of generation.functionCalls) {
157
163
  const fn = assertDefinedPass(options.functions[call.name], 'Function in response not declared.');
158
- const parameters = fn.parameters.parse(call.parameters);
164
+ const parametersSchema = await resolveValueOrAsyncProvider(fn.parameters);
165
+ const parameters = parametersSchema.parse(call.parameters);
159
166
  const handlerResult = isSchemaFunctionDeclarationWithHandler(fn) ? await fn.handler(parameters) : undefined;
160
167
  result.push({ functionName: call.name, parameters: parameters, handlerResult: handlerResult });
161
168
  }
@@ -165,7 +172,7 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
165
172
  };
166
173
  }
167
174
  async generate(request) {
168
- const googleFunctionDeclarations = isDefined(request.functions) ? this.convertFunctions(request.functions) : undefined;
175
+ const googleFunctionDeclarations = isDefined(request.functions) ? await this.convertFunctions(request.functions) : undefined;
169
176
  const generationConfig = {
170
177
  maxOutputTokens: request.generationOptions?.maxOutputTokens,
171
178
  temperature: request.generationOptions?.temperature,
@@ -253,12 +260,16 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
253
260
  })
254
261
  };
255
262
  }
256
- convertFunctions(functions) {
257
- return objectEntries(functions).map(([name, declaration]) => ({
258
- name,
259
- description: declaration.description,
260
- parameters: convertToOpenApiSchema(declaration.parameters)
261
- }));
263
+ async convertFunctions(functions) {
264
+ const mapped = mapAsync(objectEntries(functions), async ([name, declaration]) => {
265
+ const parametersSchema = await resolveValueOrAsyncProvider(declaration.parameters);
266
+ return {
267
+ name,
268
+ description: declaration.description,
269
+ parameters: convertToOpenApiSchema(parametersSchema)
270
+ };
271
+ });
272
+ return toArrayAsync(mapped);
262
273
  }
263
274
  convertGoogleContent(content) {
264
275
  return {
package/ai/functions.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  import type { FunctionDeclaration } from '@google/generative-ai';
2
2
  import type { AbstractConstructor } from '../types.js';
3
- import type { SchemaFunctionDeclarations } from './types.js';
4
- export declare function convertFunctionDeclarations(declarations: SchemaFunctionDeclarations): FunctionDeclaration[];
5
3
  export declare function getFunctionDeclarations(type: AbstractConstructor): FunctionDeclaration[];
package/ai/functions.js CHANGED
@@ -2,14 +2,6 @@ import { convertToOpenApiSchema } from '../schema/converters/openapi-converter.j
2
2
  import { FunctionSchema, getObjectSchema, object } from '../schema/index.js';
3
3
  import { fromEntries, objectEntries } from '../utils/object/object.js';
4
4
  import { isNotNull, isNull, isString } from '../utils/type-guards.js';
5
- export function convertFunctionDeclarations(declarations) {
6
- return objectEntries(declarations)
7
- .map(([name, declaration]) => ({
8
- name,
9
- description: declaration.description,
10
- parameters: convertToOpenApiSchema(declaration.parameters)
11
- }));
12
- }
13
5
  export function getFunctionDeclarations(type) {
14
6
  const objectSchema = getObjectSchema(type);
15
7
  return objectEntries(objectSchema.properties)
package/ai/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { LiteralUnion } from 'type-fest';
2
2
  import type { ObjectSchema, SchemaOutput, SchemaTestable } from '../schema/index.js';
3
3
  import type { Record, UndefinableJsonObject } from '../types.js';
4
+ import type { ResolvedValueOrProvider, ValueOrAsyncProvider } from '../utils/value-or-provider.js';
4
5
  export type FileInput = {
5
6
  path: string;
6
7
  mimeType: string;
@@ -8,7 +9,7 @@ export type FileInput = {
8
9
  export type SchemaFunctionDeclarations = Record<string, SchemaFunctionDeclaration<any>>;
9
10
  export type SchemaFunctionDeclarationWithoutHandler<T extends Record = Record> = {
10
11
  description: string;
11
- parameters: ObjectSchema<T>;
12
+ parameters: ValueOrAsyncProvider<ObjectSchema<T>>;
12
13
  };
13
14
  export type SchemaFunctionDeclarationWithHandler<T extends Record = Record, R = unknown> = SchemaFunctionDeclarationWithoutHandler<T> & {
14
15
  handler: (parameters: T) => R | Promise<R>;
@@ -18,7 +19,7 @@ export type SchemaFunctionDeclarationHandlerResult<T extends SchemaFunctionDecla
18
19
  export type SchemaFunctionDeclarationsResult<T extends SchemaFunctionDeclarations = SchemaFunctionDeclarations> = {
19
20
  [P in keyof T]: {
20
21
  functionName: P;
21
- parameters: SchemaOutput<T[P]['parameters']>;
22
+ parameters: SchemaOutput<ResolvedValueOrProvider<T[P]['parameters']>>;
22
23
  handlerResult: SchemaFunctionDeclarationHandlerResult<T[P]>;
23
24
  };
24
25
  }[keyof T];
@@ -1,8 +1,6 @@
1
1
  import type { TypedOmit } from '../../types.js';
2
- import type { HttpBodySource } from '../http-body.js';
3
- import { HttpBody } from '../http-body.js';
4
- import type { HttpHeadersObject } from '../http-headers.js';
5
- import { HttpHeaders } from '../http-headers.js';
2
+ import { HttpBody, type HttpBodySource } from '../http-body.js';
3
+ import { HttpHeaders, type HttpHeadersObject } from '../http-headers.js';
6
4
  import type { HttpClientRequest, HttpClientRequestObject } from './http-client-request.js';
7
5
  export type HttpClientResponseObject = TypedOmit<HttpClientResponse, 'hasBody' | 'request' | 'headers' | 'close' | 'asObject'> & {
8
6
  request: HttpClientRequestObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.20",
3
+ "version": "0.92.21",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -121,7 +121,7 @@
121
121
  "luxon": "^3.5",
122
122
  "reflect-metadata": "^0.2",
123
123
  "rxjs": "^7.8",
124
- "type-fest": "4.32"
124
+ "type-fest": "4.33"
125
125
  },
126
126
  "devDependencies": {
127
127
  "@mxssfd/typedoc-theme": "1.1",
@@ -134,7 +134,7 @@
134
134
  "@types/node": "22",
135
135
  "@types/nodemailer": "6.4",
136
136
  "@types/pg": "8.11",
137
- "@typescript-eslint/eslint-plugin": "8.20",
137
+ "@typescript-eslint/eslint-plugin": "8.21",
138
138
  "concurrently": "9.1",
139
139
  "drizzle-kit": "0.30",
140
140
  "eslint": "8.57",
@@ -167,7 +167,7 @@
167
167
  "playwright": "^1.49",
168
168
  "preact": "^10.25",
169
169
  "preact-render-to-string": "^6.5",
170
- "undici": "^7.2",
170
+ "undici": "^7.3",
171
171
  "urlpattern-polyfill": "^10.0"
172
172
  },
173
173
  "peerDependenciesMeta": {