@tstdl/base 0.92.19 → 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.
- package/ai/ai.service.d.ts +1 -0
- package/ai/ai.service.js +19 -8
- package/ai/functions.d.ts +0 -2
- package/ai/functions.js +0 -8
- package/ai/types.d.ts +3 -2
- package/http/client/http-client-response.d.ts +2 -4
- package/package.json +4 -4
- package/types.d.ts +1 -1
- package/utils/enum.d.ts +4 -1
- package/utils/enum.js +6 -3
package/ai/ai.service.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
|
3
|
-
import {
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
170
|
+
"undici": "^7.3",
|
|
171
171
|
"urlpattern-polyfill": "^10.0"
|
|
172
172
|
},
|
|
173
173
|
"peerDependenciesMeta": {
|
package/types.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export type UndefinableJsonArray = UndefinableJsonInnerNode[] | readonly Undefin
|
|
|
46
46
|
export type ArrayItem<T extends readonly any[]> = T extends readonly (infer U)[] ? U : never;
|
|
47
47
|
export type Enumeration = EnumerationArray | EnumerationObject;
|
|
48
48
|
export type EnumerationArray = readonly [string | number, ...(string | number)[]];
|
|
49
|
-
export type EnumerationObject
|
|
49
|
+
export type EnumerationObject<V extends string | number = string | number> = Record<string, V>;
|
|
50
50
|
export type EnumerationKey<T extends EnumerationObject = EnumerationObject> = Extract<keyof T, string>;
|
|
51
51
|
export type EnumerationMap<T extends EnumerationObject = EnumerationObject> = SimplifyObject<{
|
|
52
52
|
[P in EnumerationKey<T>]: (T[P] extends number ? (`${T[P]}` extends `${infer U extends number}` ? U : never) : `${T[P]}`) | T[P];
|
package/utils/enum.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { EnumerationEntries, EnumerationKey, EnumerationObject, EnumerationValue } from '../types.js';
|
|
2
|
-
export declare function enumValueName<T extends EnumerationObject>(enumeration: T, value: T[keyof T]):
|
|
2
|
+
export declare function enumValueName<T extends EnumerationObject>(enumeration: T, value: T[keyof T]): EnumerationKey<T>;
|
|
3
3
|
export declare function enumEntries<T extends EnumerationObject>(enumeration: T): EnumerationEntries<T>;
|
|
4
4
|
export declare function enumKeys<T extends EnumerationObject>(enumeration: T): EnumerationKey<T>[];
|
|
5
5
|
export declare function enumValues<T extends EnumerationObject>(enumeration: T): EnumerationValue<T>[];
|
|
6
6
|
export declare function randomEnumValue<T extends EnumerationObject>(enumeration: T): EnumerationValue<T>;
|
|
7
|
+
export declare function reversedEnum<T extends EnumerationObject>(enumeration: T): {
|
|
8
|
+
[P in keyof T as T[P]]: P;
|
|
9
|
+
};
|
package/utils/enum.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomItem } from './array/array.js';
|
|
2
2
|
import { memoizeSingle } from './function/memoize.js';
|
|
3
|
-
import { objectEntries } from './object/object.js';
|
|
4
|
-
import { isNumber } from './type-guards.js';
|
|
3
|
+
import { mapObject, objectEntries } from './object/object.js';
|
|
5
4
|
const memoizedEnumEntries = memoizeSingle((enumeration) => objectEntries(enumeration).filter((entry) => Number.isNaN(Number(entry[0]))), { weak: true });
|
|
6
5
|
const memoizedEnumKeys = memoizeSingle((enumeration) => {
|
|
7
6
|
const entries = enumEntries(enumeration);
|
|
@@ -11,8 +10,9 @@ const memoizedEnumValues = memoizeSingle((enumeration) => {
|
|
|
11
10
|
const entries = enumEntries(enumeration);
|
|
12
11
|
return entries.map((entry) => entry[1]);
|
|
13
12
|
}, { weak: true });
|
|
13
|
+
const memoizedReversedEnum = memoizeSingle((enumeration) => mapObject(enumeration, (value, key) => [value, key]), { weak: true });
|
|
14
14
|
export function enumValueName(enumeration, value) {
|
|
15
|
-
return
|
|
15
|
+
return reversedEnum(enumeration)[value];
|
|
16
16
|
}
|
|
17
17
|
export function enumEntries(enumeration) {
|
|
18
18
|
return memoizedEnumEntries(enumeration);
|
|
@@ -26,3 +26,6 @@ export function enumValues(enumeration) {
|
|
|
26
26
|
export function randomEnumValue(enumeration) {
|
|
27
27
|
return randomItem(enumValues(enumeration));
|
|
28
28
|
}
|
|
29
|
+
export function reversedEnum(enumeration) {
|
|
30
|
+
return memoizedReversedEnum(enumeration);
|
|
31
|
+
}
|