@tstdl/base 0.92.8 → 0.92.10

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.
Files changed (99) hide show
  1. package/ai/ai.service.d.ts +19 -4
  2. package/ai/ai.service.js +241 -3
  3. package/ai/functions.d.ts +5 -0
  4. package/ai/functions.js +40 -0
  5. package/ai/types.d.ts +27 -0
  6. package/ai/types.js +3 -0
  7. package/document-management/index.d.ts +0 -2
  8. package/document-management/index.js +0 -2
  9. package/document-management/models/schemas.d.ts +18 -18
  10. package/document-management/models/schemas.js +1 -1
  11. package/document-management/server/index.d.ts +2 -0
  12. package/document-management/server/index.js +2 -0
  13. package/document-management/{module.d.ts → server/module.d.ts} +3 -3
  14. package/document-management/{module.js → server/module.js} +4 -4
  15. package/document-management/{services → server/services}/document-management.service.d.ts +24 -23
  16. package/document-management/{services → server/services}/document-management.service.js +12 -12
  17. package/examples/document-management/main.js +2 -2
  18. package/examples/orm/schemas.d.ts +2 -2
  19. package/examples/orm/schemas.js +1 -1
  20. package/orm/decorators.d.ts +4 -2
  21. package/orm/entity.d.ts +1 -1
  22. package/orm/index.d.ts +0 -5
  23. package/orm/index.js +0 -5
  24. package/orm/schemas/json.d.ts +2 -2
  25. package/orm/schemas/numeric-date.d.ts +2 -2
  26. package/orm/schemas/timestamp.d.ts +2 -2
  27. package/orm/schemas/uuid.d.ts +2 -2
  28. package/orm/{database-schema.d.ts → server/database-schema.d.ts} +2 -2
  29. package/orm/{database.d.ts → server/database.d.ts} +1 -1
  30. package/orm/{database.js → server/database.js} +1 -1
  31. package/orm/{drizzle → server/drizzle}/schema-converter.d.ts +6 -6
  32. package/orm/{drizzle → server/drizzle}/schema-converter.js +15 -15
  33. package/orm/server/index.d.ts +6 -0
  34. package/orm/server/index.js +6 -0
  35. package/orm/{module.d.ts → server/module.d.ts} +1 -1
  36. package/orm/{module.js → server/module.js} +3 -3
  37. package/orm/{query-converter.d.ts → server/query-converter.d.ts} +2 -2
  38. package/orm/{query-converter.js → server/query-converter.js} +3 -3
  39. package/orm/{repository.d.ts → server/repository.d.ts} +4 -4
  40. package/orm/{repository.js → server/repository.js} +7 -7
  41. package/orm/{transaction.d.ts → server/transaction.d.ts} +1 -1
  42. package/orm/{transaction.js → server/transaction.js} +1 -1
  43. package/package.json +8 -6
  44. package/reflection/registry.js +2 -2
  45. package/reflection/utils.d.ts +1 -3
  46. package/schema/decorators/index.d.ts +2 -3
  47. package/schema/decorators/index.js +1 -3
  48. package/schema/decorators/schema.d.ts +21 -0
  49. package/schema/decorators/schema.js +36 -0
  50. package/schema/decorators/types.d.ts +10 -2
  51. package/schema/decorators/utils.d.ts +7 -2
  52. package/schema/decorators/utils.js +26 -7
  53. package/schema/schema.d.ts +2 -2
  54. package/schema/schemas/any.d.ts +2 -2
  55. package/schema/schemas/array.d.ts +2 -2
  56. package/schema/schemas/bigint.d.ts +2 -2
  57. package/schema/schemas/boolean.d.ts +2 -2
  58. package/schema/schemas/date.d.ts +2 -2
  59. package/schema/schemas/defaulted.d.ts +2 -2
  60. package/schema/schemas/deferred.d.ts +2 -2
  61. package/schema/schemas/enumeration.d.ts +2 -2
  62. package/schema/schemas/function.d.ts +20 -6
  63. package/schema/schemas/function.js +58 -7
  64. package/schema/schemas/instance.d.ts +2 -2
  65. package/schema/schemas/literal.d.ts +2 -2
  66. package/schema/schemas/never.d.ts +1 -1
  67. package/schema/schemas/nullable.d.ts +2 -2
  68. package/schema/schemas/nullable.js +2 -2
  69. package/schema/schemas/number.d.ts +4 -4
  70. package/schema/schemas/object.d.ts +2 -2
  71. package/schema/schemas/object.js +7 -18
  72. package/schema/schemas/one-or-many.d.ts +2 -2
  73. package/schema/schemas/optional.d.ts +2 -2
  74. package/schema/schemas/optional.js +2 -2
  75. package/schema/schemas/readable-stream.d.ts +2 -2
  76. package/schema/schemas/regexp.d.ts +2 -2
  77. package/schema/schemas/string.d.ts +2 -2
  78. package/schema/schemas/symbol.d.ts +2 -2
  79. package/schema/schemas/uint8-array.d.ts +2 -2
  80. package/schema/schemas/union.d.ts +2 -2
  81. package/schema/schemas/unknown.d.ts +2 -2
  82. package/schema/testable.d.ts +2 -2
  83. package/schema/testable.js +9 -9
  84. package/templates/resolvers/jsx.template-resolver.js +2 -2
  85. package/types.d.ts +1 -1
  86. package/utils/object/lazy-property.d.ts +2 -2
  87. package/utils/object/object.d.ts +2 -1
  88. package/schema/decorators/property.d.ts +0 -12
  89. package/schema/decorators/property.js +0 -21
  90. /package/document-management/{drizzle → server/drizzle}/0000_wakeful_firebrand.sql +0 -0
  91. /package/document-management/{drizzle → server/drizzle}/meta/0000_snapshot.json +0 -0
  92. /package/document-management/{drizzle → server/drizzle}/meta/_journal.json +0 -0
  93. /package/document-management/{drizzle.config.d.ts → server/drizzle.config.d.ts} +0 -0
  94. /package/document-management/{drizzle.config.js → server/drizzle.config.js} +0 -0
  95. /package/document-management/{services → server/services}/index.d.ts +0 -0
  96. /package/document-management/{services → server/services}/index.js +0 -0
  97. /package/orm/{database-schema.js → server/database-schema.js} +0 -0
  98. /package/orm/{drizzle → server/drizzle}/index.d.ts +0 -0
  99. /package/orm/{drizzle → server/drizzle}/index.js +0 -0
@@ -5,19 +5,18 @@ import { LiteralUnion } from 'type-fest';
5
5
  import { Resolvable, type resolveArgumentType } from '../injector/interfaces.js';
6
6
  import { OneOrMany, SchemaTestable } from '../schema/index.js';
7
7
  import { Enumeration as EnumerationType, EnumerationValue } from '../types.js';
8
- export type FileInput = {
9
- path: string;
10
- mimeType: string;
11
- } | Blob;
8
+ import { Content, FileInput, SchemaFunctionDeclarations } from './types.js';
12
9
  export type GenerativeAIModel = LiteralUnion<'gemini-2.0-flash-exp' | 'gemini-exp-1206' | 'gemini-2.0-flash-thinking-exp-1219', string>;
13
10
  export type GenerationOptions = {
14
11
  model?: GenerativeAIModel;
12
+ systemInstruction?: string;
15
13
  maxOutputTokens?: number;
16
14
  temperature?: number;
17
15
  topP?: number;
18
16
  topK?: number;
19
17
  presencePenalty?: number;
20
18
  frequencyPenalty?: number;
19
+ forceFunctionCall?: boolean;
21
20
  };
22
21
  export type GenerationResult<T> = {
23
22
  result: T;
@@ -40,6 +39,7 @@ export declare class AiService implements Resolvable<AiServiceArgument> {
40
39
  readonly [resolveArgumentType]: AiServiceArgument;
41
40
  getFile(fileInput: FileInput): Promise<FileMetadataResponse>;
42
41
  getFiles(files: readonly FileInput[]): Promise<FileMetadataResponse[]>;
42
+ test(): Promise<void>;
43
43
  classify<T extends EnumerationType>(fileInput: OneOrMany<FileInput>, types: T, options?: GenerationOptions): Promise<GenerationResult<{
44
44
  types: {
45
45
  type: EnumerationValue<T>;
@@ -47,7 +47,22 @@ export declare class AiService implements Resolvable<AiServiceArgument> {
47
47
  }[] | null;
48
48
  }>>;
49
49
  extractData<T>(fileInput: OneOrMany<FileInput>, schema: SchemaTestable<T>, options?: GenerationOptions): Promise<GenerationResult<T>>;
50
+ analyzeDocument<T extends EnumerationType>(fileInput: FileInput, types: T, options?: GenerationOptions): Promise<GenerationResult<{
51
+ content: string[];
52
+ documentTypes: {
53
+ type: EnumerationValue<T>;
54
+ confidence: 'high' | 'medium' | 'low';
55
+ }[];
56
+ tags: string[];
57
+ }>>;
58
+ findActions(fileInput: OneOrMany<FileInput>, options?: GenerationOptions): Promise<GenerationResult<{
59
+ text: string;
60
+ functions: any;
61
+ }>>;
62
+ callFunctions<const T extends SchemaFunctionDeclarations>(functions: T, contents: Content[], options?: GenerationOptions): Promise<void>;
50
63
  private waitForFileActive;
51
64
  private waitForFilesActive;
65
+ private convertContents;
66
+ private convertContent;
52
67
  private getModel;
53
68
  }
package/ai/ai.service.js CHANGED
@@ -61,20 +61,24 @@ import { openAsBlob } from 'node:fs';
61
61
  import { unlink, writeFile } from 'node:fs/promises';
62
62
  import { tmpdir } from 'node:os';
63
63
  import { join } from 'node:path';
64
- import { GoogleGenerativeAI } from '@google/generative-ai';
64
+ import { inspect } from 'node:util';
65
+ import { FunctionCallingMode, GoogleGenerativeAI, SchemaType } from '@google/generative-ai';
65
66
  import { FileState, GoogleAIFileManager } from '@google/generative-ai/server';
67
+ import { AsyncEnumerable } from '../enumerable/async-enumerable.js';
66
68
  import { DetailsError } from '../errors/details.error.js';
69
+ import { NotSupportedError } from '../errors/not-supported.error.js';
67
70
  import { Singleton } from '../injector/decorators.js';
68
71
  import { inject, injectArgument } from '../injector/inject.js';
69
72
  import { Logger } from '../logger/logger.js';
70
73
  import { convertToOpenApiSchema } from '../schema/converters/openapi-converter.js';
71
- import { array, enumeration, nullable, object, Schema } from '../schema/index.js';
74
+ import { array, enumeration, nullable, object, Schema, string } from '../schema/index.js';
72
75
  import { toArray } from '../utils/array/array.js';
73
76
  import { digest } from '../utils/cryptography.js';
74
77
  import { formatBytes } from '../utils/format.js';
78
+ import { hasOwnProperty, objectEntries } from '../utils/object/object.js';
75
79
  import { timeout } from '../utils/timing.js';
76
80
  import { tryIgnoreAsync } from '../utils/try-ignore.js';
77
- import { isBlob } from '../utils/type-guards.js';
81
+ import { assertDefinedPass, isBlob } from '../utils/type-guards.js';
78
82
  import { millisecondsPerSecond } from '../utils/units.js';
79
83
  let AiService = class AiService {
80
84
  #options = injectArgument(this);
@@ -136,6 +140,59 @@ let AiService = class AiService {
136
140
  async getFiles(files) {
137
141
  return Promise.all(files.map(async (file) => this.getFile(file)));
138
142
  }
143
+ async test() {
144
+ const result = await this.getModel('gemini-2.0-flash-exp').generateContent({
145
+ generationConfig: {
146
+ maxOutputTokens: 4096
147
+ },
148
+ tools: [{
149
+ functionDeclarations: [
150
+ {
151
+ name: 'outputNumber',
152
+ description: 'outputs a number',
153
+ parameters: {
154
+ type: SchemaType.OBJECT,
155
+ properties: {
156
+ number: { type: SchemaType.INTEGER }
157
+ },
158
+ required: ['number']
159
+ }
160
+ }
161
+ ],
162
+ }],
163
+ toolConfig: {
164
+ functionCallingConfig: {
165
+ mode: FunctionCallingMode.ANY
166
+ }
167
+ },
168
+ contents: [
169
+ { role: 'user', parts: [{ text: 'Output 5 increasing numbers starting at 10' }] },
170
+ {
171
+ role: 'model',
172
+ parts: [
173
+ { functionCall: { name: 'outputNumber', args: { number: 10 } } },
174
+ { functionCall: { name: 'outputNumber', args: { number: 11 } } },
175
+ { functionCall: { name: 'outputNumber', args: { number: 12 } } },
176
+ { functionCall: { name: 'outputNumber', args: { number: 13 } } },
177
+ { functionCall: { name: 'outputNumber', args: { number: 14 } } }
178
+ ]
179
+ },
180
+ /*{
181
+ role: 'user',
182
+ parts: [
183
+ { functionResponse: { name: 'outputNumber', response: { result: 'outputted number 10' } } },
184
+ { functionResponse: { name: 'outputNumber', response: { result: 'outputted number 11' } } },
185
+ { functionResponse: { name: 'outputNumber', response: { result: 'outputted number 12' } } },
186
+ { functionResponse: { name: 'outputNumber', response: { result: 'outputted number 13' } } },
187
+ { functionResponse: { name: 'outputNumber', response: { result: 'outputted number 14' } } }
188
+ ]
189
+ },*/
190
+ // { role: 'model', parts: [{ text: 'Okay, I\'ve outputted the numbers 10, 11, 12, 13, and 14.' }] },
191
+ { role: 'user', parts: [{ text: 'Give me 5 more numbers. ONLY call functions, dont output text' }] }
192
+ ]
193
+ });
194
+ console.log(inspect(result.response, { depth: null }));
195
+ }
139
196
  async classify(fileInput, types, options) {
140
197
  const files = await this.getFiles(toArray(fileInput));
141
198
  const resultSchema = object({
@@ -201,6 +258,162 @@ Carefully read and analyze the provided document. Identify relevant information
201
258
  result: Schema.parse(schema, JSON.parse(result.response.text()))
202
259
  };
203
260
  }
261
+ async analyzeDocument(fileInput, types, options) {
262
+ const file = await this.getFile(fileInput);
263
+ const schema = object({
264
+ content: array(string({ description: 'Single content without data details' }), { description: 'List of contents' }),
265
+ documentTypes: array(object({
266
+ type: enumeration(types, { description: 'Type of document' }),
267
+ confidence: enumeration(['high', 'medium', 'low'], { description: 'How sure/certain you are about the classficiation.' })
268
+ }), { description: 'One or more document types that matches' }),
269
+ tags: array(string({ description: 'Tag which describes the content' }), { description: 'List of tags' })
270
+ });
271
+ const responseSchema = convertToOpenApiSchema(schema);
272
+ this.#logger.verbose('Extracting data...');
273
+ const result = await this.getModel(options?.model ?? this.defaultModel).generateContent({
274
+ generationConfig: {
275
+ maxOutputTokens: 2048,
276
+ temperature: 0.75,
277
+ ...options,
278
+ responseMimeType: 'application/json',
279
+ responseSchema
280
+ },
281
+ systemInstruction: `You are a highly skilled data extraction AI, specializing in accurately identifying and extracting information from unstructured text documents and converting it into a structured JSON format. Your primary goal is to meticulously follow the provided JSON schema and populate it with data extracted from the given document.
282
+
283
+ **Instructions:**
284
+ Carefully read and analyze the provided document.
285
+ Identify key points and relevant information that describes the content. Focus on a general overview without providing specific details.
286
+ Only output as many content items as it is necessary to describe relevant content. It should be around 5 to 10 items.
287
+ Classify the document based on the provided list of types.
288
+ Output up to 5 tags.
289
+ Always output the content and tags in Deutsch.`,
290
+ contents: [
291
+ {
292
+ role: 'user',
293
+ parts: [
294
+ { fileData: { mimeType: file.mimeType, fileUri: file.uri } },
295
+ { text: `Classify the document. Output as JSON using the following schema:\n${JSON.stringify(responseSchema, null, 2)}` }
296
+ ]
297
+ }
298
+ ]
299
+ });
300
+ return {
301
+ usage: result.response.usageMetadata,
302
+ result: Schema.parse(schema, JSON.parse(result.response.text()))
303
+ };
304
+ }
305
+ async findActions(fileInput, options) {
306
+ const files = await this.getFiles(toArray(fileInput));
307
+ this.#logger.verbose('Extracting data...');
308
+ const result = await this.getModel(options?.model ?? this.defaultModel).generateContent({
309
+ generationConfig: {
310
+ maxOutputTokens: 4096,
311
+ temperature: 0.75,
312
+ ...options
313
+ },
314
+ tools: [
315
+ {
316
+ functionDeclarations: [
317
+ {
318
+ name: 'createNewRealEstate',
319
+ description: 'creates a new real estate',
320
+ parameters: {
321
+ type: SchemaType.OBJECT,
322
+ properties: {
323
+ address: { type: SchemaType.STRING },
324
+ realEstateNumber: { type: SchemaType.STRING }
325
+ },
326
+ required: ['address', 'realEstateNumber']
327
+ }
328
+ },
329
+ {
330
+ name: 'createNewUnit',
331
+ description: 'creates a new unit in a real estate. Make sure to get the correct unit number, each unit has to get its own',
332
+ parameters: {
333
+ type: SchemaType.OBJECT,
334
+ description: 'data of the unit from documents',
335
+ properties: {
336
+ unitNumber: { type: SchemaType.STRING },
337
+ owner: { type: SchemaType.STRING },
338
+ dweller: { type: SchemaType.STRING }
339
+ },
340
+ required: ['unitNumber', 'owner', 'dweller']
341
+ }
342
+ },
343
+ {
344
+ name: 'createNewDevice',
345
+ description: 'creates a new device in a real estate / unit, for example HKV or WWZ',
346
+ parameters: {
347
+ type: SchemaType.OBJECT,
348
+ description: 'data of the device from documents like Ablesebeleg.',
349
+ properties: {
350
+ unitNumber: { type: SchemaType.STRING },
351
+ deviceNumber: { type: SchemaType.STRING },
352
+ factor: { type: SchemaType.NUMBER },
353
+ deviceType: { type: SchemaType.STRING },
354
+ roomType: { type: SchemaType.STRING }
355
+ },
356
+ required: ['unitNumber', 'deviceNumber', 'factor', 'deviceType', 'roomType']
357
+ }
358
+ }
359
+ ]
360
+ }
361
+ ],
362
+ toolConfig: { functionCallingConfig: { mode: FunctionCallingMode.ANY } },
363
+ systemInstruction: `You are a specialized AI assistant designed to extract structured data from various document types related to real estate and device management. Your goal is to understand the document's content and identify key information to populate specific function calls. You will be provided with document text and a set of predefined functions.
364
+
365
+ **Your task is:**
366
+
367
+ 1. **Analyze the document:** Carefully read the provided document text.
368
+ 2. **Identify relevant information:** Extract the key data points related to real estate (e.g., address, size, type) and devices (e.g., type, model, serial number, location).
369
+ 3. **Determine the appropriate function:** Based on the extracted information, select the most suitable function from the list below to perform the intended action.
370
+ 4. **Generate function call:** Output the selected function name along with its arguments, populated with the extracted data. Use JSON format for the output.`,
371
+ contents: [
372
+ {
373
+ role: 'user',
374
+ parts: [
375
+ ...files.map((file) => ({ fileData: { mimeType: file.mimeType, fileUri: file.uri } })),
376
+ { text: 'Extract the data from the document and call suitable functions.' }
377
+ ]
378
+ }
379
+ ]
380
+ });
381
+ return {
382
+ usage: result.response.usageMetadata,
383
+ result: {
384
+ functions: result.response.functionCalls(),
385
+ text: result.response.text()
386
+ }
387
+ };
388
+ }
389
+ async callFunctions(functions, contents, options) {
390
+ const googleContent = await this.convertContents(contents);
391
+ const googleFunctionDeclarations = objectEntries(functions).map(([name, declaration]) => ({
392
+ name: name,
393
+ description: declaration.description,
394
+ parameters: convertToOpenApiSchema(declaration.parameters)
395
+ }));
396
+ const result = await this.getModel(options?.model ?? this.defaultModel).generateContent({
397
+ generationConfig: {
398
+ maxOutputTokens: 4096,
399
+ temperature: 0.75,
400
+ ...options
401
+ },
402
+ systemInstruction: options?.systemInstruction,
403
+ tools: [{ functionDeclarations: googleFunctionDeclarations }],
404
+ toolConfig: {
405
+ functionCallingConfig: {
406
+ mode: (options?.forceFunctionCall == false) ? FunctionCallingMode.AUTO : FunctionCallingMode.ANY
407
+ }
408
+ },
409
+ contents: googleContent
410
+ });
411
+ for (const call of result.response.functionCalls() ?? []) {
412
+ const fn = assertDefinedPass(functions[call.name]);
413
+ const parameters = fn.parameters.parse(call.args);
414
+ const functionResult = await fn.handler(parameters);
415
+ }
416
+ }
204
417
  async waitForFileActive(fileMetadata) {
205
418
  let file = await this.fileManager.getFile(fileMetadata.name);
206
419
  while (file.state == FileState.PROCESSING) {
@@ -220,6 +433,31 @@ Carefully read and analyze the provided document. Identify relevant information
220
433
  }
221
434
  return responses;
222
435
  }
436
+ async convertContents(contents) {
437
+ return AsyncEnumerable.from(contents)
438
+ .map(async (content) => this.convertContent(content))
439
+ .toArray();
440
+ }
441
+ async convertContent(content) {
442
+ return {
443
+ role: content.role,
444
+ parts: await AsyncEnumerable.from(content.parts)
445
+ .map(async (part) => {
446
+ if (hasOwnProperty(part, 'text')) {
447
+ return { text: part.text };
448
+ }
449
+ if (hasOwnProperty(part, 'file')) {
450
+ const fileMetadata = await this.getFile(part.file);
451
+ return { fileData: { fileUri: fileMetadata.uri, mimeType: fileMetadata.mimeType } };
452
+ }
453
+ if (hasOwnProperty(part, 'functionResult')) {
454
+ return { functionResponse: { name: part.functionResult.name, response: { result: part.functionResult.value } } };
455
+ }
456
+ throw new NotSupportedError('Unsupported content part.');
457
+ })
458
+ .toArray()
459
+ };
460
+ }
223
461
  getModel(model) {
224
462
  return this.genAI.getGenerativeModel({ model });
225
463
  }
@@ -0,0 +1,5 @@
1
+ import type { FunctionDeclaration } from '@google/generative-ai';
2
+ import type { AbstractConstructor } from '../types.js';
3
+ import type { SchemaFunctionDeclarations } from './types.js';
4
+ export declare function convertFunctionDeclarations(declarations: SchemaFunctionDeclarations): void;
5
+ export declare function getFunctionDeclarations(type: AbstractConstructor): FunctionDeclaration[];
@@ -0,0 +1,40 @@
1
+ import { convertToOpenApiSchema } from '../schema/converters/openapi-converter.js';
2
+ import { FunctionSchema, getObjectSchema, object } from '../schema/index.js';
3
+ import { fromEntries, objectEntries } from '../utils/object/object.js';
4
+ import { isNotNull, isNull, isString } from '../utils/type-guards.js';
5
+ export function convertFunctionDeclarations(declarations) {
6
+ const entries = objectEntries(declarations)
7
+ .map(([name, declaration]) => ({
8
+ name,
9
+ description: declaration.description,
10
+ parameters: convertToOpenApiSchema(declaration.parameters)
11
+ }));
12
+ }
13
+ export function getFunctionDeclarations(type) {
14
+ const objectSchema = getObjectSchema(type);
15
+ return objectEntries(objectSchema.properties)
16
+ .map(([key, schema]) => {
17
+ if (!(schema instanceof FunctionSchema)) {
18
+ return null;
19
+ }
20
+ return {
21
+ name: `${type.name}.${key}`,
22
+ description: schema.description ?? undefined,
23
+ parameters: isNull(schema.parameterSchemas)
24
+ ? undefined
25
+ : getFunctionDeclarationParameters(schema)
26
+ };
27
+ })
28
+ .filter(isNotNull);
29
+ }
30
+ function getFunctionDeclarationParameters(functionSchema) {
31
+ const entries = functionSchema.parameterSchemas.map((schema, index) => {
32
+ const parameterName = functionSchema.parameterNames[index];
33
+ if (!isString(parameterName)) {
34
+ throw new Error(`Parameter ${index} requires a name.`);
35
+ }
36
+ return [parameterName, schema];
37
+ });
38
+ const parametersSchema = object(fromEntries(entries));
39
+ return convertToOpenApiSchema(parametersSchema);
40
+ }
package/ai/types.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { ObjectSchema } from '../schema/index.js';
2
+ import type { Record, UndefinableJson } from '../types.js';
3
+ export type FileInput = {
4
+ path: string;
5
+ mimeType: string;
6
+ } | Blob;
7
+ export type SchemaFunctionDeclarations = Record<string, SchemaFunctionDeclaration<any>>;
8
+ export type SchemaFunctionDeclaration<T extends Record = Record, R = unknown> = {
9
+ description: string;
10
+ parameters: ObjectSchema<T>;
11
+ handler: (parameters: T) => R | Promise<R>;
12
+ };
13
+ export type Content = {
14
+ role: 'user' | 'model';
15
+ parts: ContentPart[];
16
+ };
17
+ export type ContentPart = {
18
+ text: string;
19
+ } | {
20
+ file: FileInput;
21
+ } | {
22
+ functionResult: {
23
+ name: string;
24
+ value: NonNullable<UndefinableJson>;
25
+ };
26
+ };
27
+ export declare function declareFunction<T extends Record = Record, R = unknown>(description: string, parameters: ObjectSchema<T>, handler: (parameters: T) => R | Promise<R>): SchemaFunctionDeclaration<T, R>;
package/ai/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export function declareFunction(description, parameters, handler) {
2
+ return { description, parameters, handler };
3
+ }
@@ -1,5 +1,3 @@
1
1
  export * from './api/index.js';
2
2
  export * from './localizations/index.js';
3
3
  export * from './models/index.js';
4
- export * from './module.js';
5
- export * from './services/index.js';
@@ -1,5 +1,3 @@
1
1
  export * from './api/index.js';
2
2
  export * from './localizations/index.js';
3
3
  export * from './models/index.js';
4
- export * from './module.js';
5
- export * from './services/index.js';
@@ -12,22 +12,22 @@ import { DocumentRequestsTemplate } from './document-requests-template.js';
12
12
  import { DocumentTypeProperty } from './document-type-property.model.js';
13
13
  import { DocumentType } from './document-type.model.js';
14
14
  import { Document } from './document.model.js';
15
- export declare const documentManagementSchema: import("../../orm/database-schema.js").DatabaseSchema<"document_management">;
15
+ export declare const documentManagementSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"document_management">;
16
16
  export declare const dataType: import("drizzle-orm/pg-core").PgEnum<["0", "1", "3", "2"]>;
17
- export declare const documentCategory: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCategory>;
18
- export declare const documentCollectionDocument: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCollectionDocument>;
19
- export declare const documentCollection: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCollection>;
20
- export declare const documentFile: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentFile>;
21
- export declare const documentPropertyTextValue: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyTextValue>;
22
- export declare const documentPropertyIntegerValue: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyIntegerValue>;
23
- export declare const documentPropertyDecimalValue: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyDecimalValue>;
24
- export declare const documentPropertyBooleanValue: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyBooleanValue>;
25
- export declare const documentProperty: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentProperty>;
26
- export declare const documentRequestCollection: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestCollection>;
27
- export declare const documentRequestFile: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestFile>;
28
- export declare const documentRequestTemplate: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestTemplate>;
29
- export declare const documentRequest: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequest>;
30
- export declare const documentRequestsTemplate: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestsTemplate>;
31
- export declare const documentTypeProperty: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentTypeProperty>;
32
- export declare const documentType: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentType>;
33
- export declare const document: import("../../orm/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof Document>;
17
+ export declare const documentCategory: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCategory>;
18
+ export declare const documentCollectionDocument: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCollectionDocument>;
19
+ export declare const documentCollection: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentCollection>;
20
+ export declare const documentFile: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentFile>;
21
+ export declare const documentPropertyTextValue: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyTextValue>;
22
+ export declare const documentPropertyIntegerValue: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyIntegerValue>;
23
+ export declare const documentPropertyDecimalValue: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyDecimalValue>;
24
+ export declare const documentPropertyBooleanValue: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentPropertyBooleanValue>;
25
+ export declare const documentProperty: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentProperty>;
26
+ export declare const documentRequestCollection: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestCollection>;
27
+ export declare const documentRequestFile: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestFile>;
28
+ export declare const documentRequestTemplate: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestTemplate>;
29
+ export declare const documentRequest: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequest>;
30
+ export declare const documentRequestsTemplate: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentRequestsTemplate>;
31
+ export declare const documentTypeProperty: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentTypeProperty>;
32
+ export declare const documentType: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof DocumentType>;
33
+ export declare const document: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"document_management", typeof Document>;
@@ -1,4 +1,4 @@
1
- import { databaseSchema } from '../../orm/database-schema.js';
1
+ import { databaseSchema } from '../../orm/server/database-schema.js';
2
2
  import { DocumentCategory } from './document-category.model.js';
3
3
  import { DocumentCollectionDocument } from './document-collection-document.model.js';
4
4
  import { DocumentCollection } from './document-collection.model.js';
@@ -0,0 +1,2 @@
1
+ export * from './module.js';
2
+ export * from './services/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './module.js';
2
+ export * from './services/index.js';
@@ -1,6 +1,6 @@
1
- import './models/schemas.js';
2
- import { type InjectionToken } from '../injector/index.js';
3
- import type { DatabaseConfig } from '../orm/module.js';
1
+ import '../models/schemas.js';
2
+ import { type InjectionToken } from '../../injector/index.js';
3
+ import type { DatabaseConfig } from '../../orm/server/module.js';
4
4
  import { DocumentManagementService } from './services/document-management.service.js';
5
5
  export declare class DocumentManagementConfig {
6
6
  fileObjectStorageModule: string;
@@ -1,8 +1,8 @@
1
- import './models/schemas.js';
1
+ import '../models/schemas.js';
2
2
  import { migrate } from 'drizzle-orm/node-postgres/migrator';
3
- import { inject, Injector } from '../injector/index.js';
4
- import { Database } from '../orm/database.js';
5
- import { isDefined } from '../utils/type-guards.js';
3
+ import { inject, Injector } from '../../injector/index.js';
4
+ import { Database } from '../../orm/server/database.js';
5
+ import { isDefined } from '../../utils/type-guards.js';
6
6
  import { DocumentManagementService } from './services/document-management.service.js';
7
7
  export class DocumentManagementConfig {
8
8
  fileObjectStorageModule;
@@ -1,28 +1,29 @@
1
- import { Resolvable, resolveArgumentType } from '../../injector/index.js';
2
- import { ObjectStorage } from '../../object-storage/index.js';
3
- import { Query, Transaction } from '../../orm/index.js';
4
- import { OneOrMany } from '../../types.js';
5
- import { AddOrArchiveDocumentToOrFromCollectionParameters, ApplyDocumentRequestsTemplateParameters, ApproveDocumentRequestFileParameters, AssignPropertyToTypeParameters, CategoryAndTypesView, CreateCollectionParameters, CreateDocumentCategoryParameters, CreateDocumentParameters, CreateDocumentPropertyParameters, CreateDocumentRequestFileParameters, CreateDocumentRequestParameters, CreateDocumentRequestTemplateParameters, CreateDocumentRequestsTemplateParameters, CreateDocumentTypeParameters, DeleteDocumentRequestFileParameters, DeleteDocumentRequestParameters, DeleteDocumentRequestTemplateParameters, DeleteDocumentRequestsTemplateParameters, Document, DocumentCategory, DocumentCollection, DocumentCollectionDocument, DocumentFile, DocumentManagementData, DocumentProperty, DocumentPropertyBooleanValue, DocumentPropertyDataType, DocumentPropertyDecimalValue, DocumentPropertyIntegerValue, DocumentPropertyTextValue, DocumentRequest, DocumentRequestCollection, DocumentRequestFile, DocumentRequestTemplate, DocumentRequestsTemplate, DocumentRequestsTemplateData, DocumentType, DocumentTypeProperty, LoadDataCollectionsMetadataParameters, RejectDocumentRequestFileParameters, RequestFilesStats, SetDocumentPropertiesParameters, UpdateDocumentParameters, UpdateDocumentRequestFileParameters, UpdateDocumentRequestParameters, UpdateDocumentRequestTemplateParameters, UpdateDocumentRequestsTemplateParameters } from '../models/index.js';
1
+ import { Resolvable, resolveArgumentType } from '../../../injector/index.js';
2
+ import { ObjectStorage } from '../../../object-storage/index.js';
3
+ import { Query } from '../../../orm/index.js';
4
+ import { Transaction } from '../../../orm/server/index.js';
5
+ import { OneOrMany } from '../../../types.js';
6
+ import { AddOrArchiveDocumentToOrFromCollectionParameters, ApplyDocumentRequestsTemplateParameters, ApproveDocumentRequestFileParameters, AssignPropertyToTypeParameters, CategoryAndTypesView, CreateCollectionParameters, CreateDocumentCategoryParameters, CreateDocumentParameters, CreateDocumentPropertyParameters, CreateDocumentRequestFileParameters, CreateDocumentRequestParameters, CreateDocumentRequestTemplateParameters, CreateDocumentRequestsTemplateParameters, CreateDocumentTypeParameters, DeleteDocumentRequestFileParameters, DeleteDocumentRequestParameters, DeleteDocumentRequestTemplateParameters, DeleteDocumentRequestsTemplateParameters, Document, DocumentCategory, DocumentCollection, DocumentCollectionDocument, DocumentFile, DocumentManagementData, DocumentProperty, DocumentPropertyBooleanValue, DocumentPropertyDataType, DocumentPropertyDecimalValue, DocumentPropertyIntegerValue, DocumentPropertyTextValue, DocumentRequest, DocumentRequestCollection, DocumentRequestFile, DocumentRequestTemplate, DocumentRequestsTemplate, DocumentRequestsTemplateData, DocumentType, DocumentTypeProperty, LoadDataCollectionsMetadataParameters, RejectDocumentRequestFileParameters, RequestFilesStats, SetDocumentPropertiesParameters, UpdateDocumentParameters, UpdateDocumentRequestFileParameters, UpdateDocumentRequestParameters, UpdateDocumentRequestTemplateParameters, UpdateDocumentRequestsTemplateParameters } from '../../models/index.js';
6
7
  import { DocumentManagementConfig } from '../module.js';
7
8
  export type DocumentServiceArgument = DocumentManagementConfig;
8
9
  export declare class DocumentManagementService implements Resolvable<DocumentServiceArgument> {
9
- protected readonly documentService: import("../../orm/index.js").EntityRepository<Document>;
10
- protected readonly documentFileService: import("../../orm/index.js").EntityRepository<DocumentFile>;
11
- protected readonly documentCollectionService: import("../../orm/index.js").EntityRepository<DocumentCollection>;
12
- protected readonly documentCategoryService: import("../../orm/index.js").EntityRepository<DocumentCategory>;
13
- protected readonly documentTypeService: import("../../orm/index.js").EntityRepository<DocumentType>;
14
- protected readonly documentRequestService: import("../../orm/index.js").EntityRepository<DocumentRequest>;
15
- protected readonly documentRequestsTemplateService: import("../../orm/index.js").EntityRepository<DocumentRequestsTemplate>;
16
- protected readonly documentRequestTemplateService: import("../../orm/index.js").EntityRepository<DocumentRequestTemplate>;
17
- protected readonly documentRequestCollectionService: import("../../orm/index.js").EntityRepository<DocumentRequestCollection>;
18
- protected readonly documentRequestFileService: import("../../orm/index.js").EntityRepository<DocumentRequestFile>;
19
- protected readonly documentPropertyService: import("../../orm/index.js").EntityRepository<DocumentProperty>;
20
- protected readonly documentTypePropertyService: import("../../orm/index.js").EntityRepository<DocumentTypeProperty>;
21
- protected readonly documentPropertyTextValueService: import("../../orm/index.js").EntityRepository<DocumentPropertyTextValue>;
22
- protected readonly documentPropertyIntegerValueService: import("../../orm/index.js").EntityRepository<DocumentPropertyIntegerValue>;
23
- protected readonly documentPropertyDecimalValueService: import("../../orm/index.js").EntityRepository<DocumentPropertyDecimalValue>;
24
- protected readonly documentPropertyBooleanValueService: import("../../orm/index.js").EntityRepository<DocumentPropertyBooleanValue>;
25
- protected readonly documentCollectionDocumentService: import("../../orm/index.js").EntityRepository<DocumentCollectionDocument>;
10
+ protected readonly documentService: import("../../../orm/server/index.js").EntityRepository<Document>;
11
+ protected readonly documentFileService: import("../../../orm/server/index.js").EntityRepository<DocumentFile>;
12
+ protected readonly documentCollectionService: import("../../../orm/server/index.js").EntityRepository<DocumentCollection>;
13
+ protected readonly documentCategoryService: import("../../../orm/server/index.js").EntityRepository<DocumentCategory>;
14
+ protected readonly documentTypeService: import("../../../orm/server/index.js").EntityRepository<DocumentType>;
15
+ protected readonly documentRequestService: import("../../../orm/server/index.js").EntityRepository<DocumentRequest>;
16
+ protected readonly documentRequestsTemplateService: import("../../../orm/server/index.js").EntityRepository<DocumentRequestsTemplate>;
17
+ protected readonly documentRequestTemplateService: import("../../../orm/server/index.js").EntityRepository<DocumentRequestTemplate>;
18
+ protected readonly documentRequestCollectionService: import("../../../orm/server/index.js").EntityRepository<DocumentRequestCollection>;
19
+ protected readonly documentRequestFileService: import("../../../orm/server/index.js").EntityRepository<DocumentRequestFile>;
20
+ protected readonly documentPropertyService: import("../../../orm/server/index.js").EntityRepository<DocumentProperty>;
21
+ protected readonly documentTypePropertyService: import("../../../orm/server/index.js").EntityRepository<DocumentTypeProperty>;
22
+ protected readonly documentPropertyTextValueService: import("../../../orm/server/index.js").EntityRepository<DocumentPropertyTextValue>;
23
+ protected readonly documentPropertyIntegerValueService: import("../../../orm/server/index.js").EntityRepository<DocumentPropertyIntegerValue>;
24
+ protected readonly documentPropertyDecimalValueService: import("../../../orm/server/index.js").EntityRepository<DocumentPropertyDecimalValue>;
25
+ protected readonly documentPropertyBooleanValueService: import("../../../orm/server/index.js").EntityRepository<DocumentPropertyBooleanValue>;
26
+ protected readonly documentCollectionDocumentService: import("../../../orm/server/index.js").EntityRepository<DocumentCollectionDocument>;
26
27
  protected readonly fileObjectStorage: ObjectStorage;
27
28
  readonly [resolveArgumentType]: DocumentServiceArgument;
28
29
  loadData(collectionIds: string[], collectionsMetadata?: LoadDataCollectionsMetadataParameters): Promise<DocumentManagementData>;
@@ -60,6 +61,6 @@ export declare class DocumentManagementService implements Resolvable<DocumentSer
60
61
  archiveDocument({ collectionId, documentId, metadata }: AddOrArchiveDocumentToOrFromCollectionParameters): Promise<void>;
61
62
  createProperty(parameters: CreateDocumentPropertyParameters): Promise<DocumentProperty>;
62
63
  assignPropertyToType(parameters: AssignPropertyToTypeParameters): Promise<void>;
63
- protected getDocumentPropertyValueService(dataType: DocumentPropertyDataType): import("../../orm/index.js").EntityRepository<DocumentPropertyTextValue> | import("../../orm/index.js").EntityRepository<DocumentPropertyIntegerValue> | import("../../orm/index.js").EntityRepository<DocumentPropertyBooleanValue>;
64
+ protected getDocumentPropertyValueService(dataType: DocumentPropertyDataType): import("../../../orm/server/index.js").EntityRepository<DocumentPropertyTextValue> | import("../../../orm/server/index.js").EntityRepository<DocumentPropertyIntegerValue> | import("../../../orm/server/index.js").EntityRepository<DocumentPropertyBooleanValue>;
64
65
  protected getDocumentFileContentObjectUrl(title: string, file: DocumentFile, download: boolean): Promise<string>;
65
66
  }
@@ -4,18 +4,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { getEntityMap } from '../../database/index.js';
8
- import { Enumerable } from '../../enumerable/index.js';
9
- import { BadRequestError } from '../../errors/index.js';
10
- import { getMimeType, getMimeTypeExtensions } from '../../file/index.js';
11
- import { Singleton, inject, injectArgument, provide } from '../../injector/index.js';
12
- import { ObjectStorage } from '../../object-storage/index.js';
13
- import { DATABASE_CONFIG, EntityRepositoryConfig, injectRepository } from '../../orm/index.js';
14
- import { toArray } from '../../utils/array/index.js';
15
- import { assertDefinedPass, compareByValueSelectionToOrder, currentTimestamp, digest, isBoolean, isDefined, isNotNull, isNull, isNumber, isString, isUint8Array, millisecondsPerMinute } from '../../utils/index.js';
16
- import { groupToMap } from '../../utils/iterable-helpers/index.js';
17
- import { readBinaryStream } from '../../utils/stream/index.js';
18
- import { Document, DocumentCategory, DocumentCollection, DocumentCollectionDocument, DocumentFile, DocumentProperty, DocumentPropertyBooleanValue, DocumentPropertyDataType, DocumentPropertyDecimalValue, DocumentPropertyIntegerValue, DocumentPropertyTextValue, DocumentRequest, DocumentRequestCollection, DocumentRequestFile, DocumentRequestTemplate, DocumentRequestsTemplate, DocumentType, DocumentTypeProperty } from '../models/index.js';
7
+ import { getEntityMap } from '../../../database/index.js';
8
+ import { Enumerable } from '../../../enumerable/index.js';
9
+ import { BadRequestError } from '../../../errors/index.js';
10
+ import { getMimeType, getMimeTypeExtensions } from '../../../file/index.js';
11
+ import { Singleton, inject, injectArgument, provide } from '../../../injector/index.js';
12
+ import { ObjectStorage } from '../../../object-storage/index.js';
13
+ import { DATABASE_CONFIG, EntityRepositoryConfig, injectRepository } from '../../../orm/server/index.js';
14
+ import { toArray } from '../../../utils/array/index.js';
15
+ import { assertDefinedPass, compareByValueSelectionToOrder, currentTimestamp, digest, isBoolean, isDefined, isNotNull, isNull, isNumber, isString, isUint8Array, millisecondsPerMinute } from '../../../utils/index.js';
16
+ import { groupToMap } from '../../../utils/iterable-helpers/index.js';
17
+ import { readBinaryStream } from '../../../utils/stream/index.js';
18
+ import { Document, DocumentCategory, DocumentCollection, DocumentCollectionDocument, DocumentFile, DocumentProperty, DocumentPropertyBooleanValue, DocumentPropertyDataType, DocumentPropertyDecimalValue, DocumentPropertyIntegerValue, DocumentPropertyTextValue, DocumentRequest, DocumentRequestCollection, DocumentRequestFile, DocumentRequestTemplate, DocumentRequestsTemplate, DocumentType, DocumentTypeProperty } from '../../models/index.js';
19
19
  import { DocumentManagementConfig } from '../module.js';
20
20
  let DocumentManagementService = class DocumentManagementService {
21
21
  documentService = injectRepository(Document);