@tstdl/base 0.93.193 → 0.93.196
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/prompts/prompt-builder.d.ts +2 -0
- package/ai/prompts/prompt-builder.js +20 -6
- package/api/server/error-handler.d.ts +1 -1
- package/api/server/error-handler.js +0 -1
- package/api/types.d.ts +4 -4
- package/authentication/authentication.api.d.ts +6 -15
- package/authentication/authentication.api.js +0 -1
- package/authentication/client/authentication.service.d.ts +0 -2
- package/authentication/client/authentication.service.js +0 -5
- package/authentication/server/authentication.api-controller.d.ts +1 -1
- package/authentication/server/authentication.api-controller.js +0 -1
- package/authentication/server/authentication.service.d.ts +0 -1
- package/authentication/server/authentication.service.js +4 -9
- package/document-management/server/services/document-management-ai.prompts.d.ts +1 -1
- package/document-management/server/services/document-management-ai.prompts.js +6 -7
- package/document-management/server/services/document-management-ai.service.js +1 -1
- package/document-management/server/validators/ai-validation-executor.js +1 -1
- package/http/server/http-server-response.d.ts +12 -12
- package/package.json +3 -3
- package/schema/schema.d.ts +1 -1
|
@@ -16,6 +16,8 @@ export declare class PromptBuilder {
|
|
|
16
16
|
setOutputSchema<Input = ObjectLiteral, Output = ObjectLiteral>(schema: SchemaTestable<Output>, examples?: FewShotExample<Input, Output>[]): this;
|
|
17
17
|
setSystemOutputExamples<Input = ObjectLiteral, Output = ObjectLiteral>(examples: FewShotExample<Input, Output>[]): this;
|
|
18
18
|
setOutputExamples<Input = ObjectLiteral, Output = ObjectLiteral>(examples: FewShotExample<Input, Output>[]): this;
|
|
19
|
+
enableSystemOutputRules(enabled?: boolean): this;
|
|
20
|
+
enableOutputRules(enabled?: boolean): this;
|
|
19
21
|
setSystemInstructionsOverride(override: ((instructions: Instructions) => Instructions | string) | undefined): this;
|
|
20
22
|
setInstructionsOverride(override: ((instructions: Instructions) => Instructions | string) | undefined): this;
|
|
21
23
|
setLanguage(language: string): this;
|
|
@@ -14,8 +14,10 @@ export class PromptBuilder {
|
|
|
14
14
|
#task;
|
|
15
15
|
#systemOutputSchema;
|
|
16
16
|
#systemOutputExamples;
|
|
17
|
+
#systemOutputRules = false;
|
|
17
18
|
#outputSchema;
|
|
18
19
|
#outputExamples;
|
|
20
|
+
#outputRules = false;
|
|
19
21
|
#systemInstructions = {};
|
|
20
22
|
#instructions = {};
|
|
21
23
|
#systemContextParts = {};
|
|
@@ -57,6 +59,14 @@ export class PromptBuilder {
|
|
|
57
59
|
this.#outputExamples = examples;
|
|
58
60
|
return this;
|
|
59
61
|
}
|
|
62
|
+
enableSystemOutputRules(enabled = true) {
|
|
63
|
+
this.#systemOutputRules = enabled;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
enableOutputRules(enabled = true) {
|
|
67
|
+
this.#outputRules = enabled;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
60
70
|
setSystemInstructionsOverride(override) {
|
|
61
71
|
this.#systemInstructionsOverride = override;
|
|
62
72
|
return this;
|
|
@@ -108,6 +118,7 @@ export class PromptBuilder {
|
|
|
108
118
|
instructions: this.#systemInstructions,
|
|
109
119
|
outputSchema: this.#systemOutputSchema,
|
|
110
120
|
outputExamples: this.#systemOutputExamples,
|
|
121
|
+
outputRules: this.#systemOutputRules,
|
|
111
122
|
task: this.#systemTask,
|
|
112
123
|
media: this.#systemMedia,
|
|
113
124
|
language: this.#language,
|
|
@@ -121,6 +132,7 @@ export class PromptBuilder {
|
|
|
121
132
|
instructions: this.#instructions,
|
|
122
133
|
outputSchema: this.#outputSchema,
|
|
123
134
|
outputExamples: this.#outputExamples,
|
|
135
|
+
outputRules: this.#outputRules,
|
|
124
136
|
task: this.#task,
|
|
125
137
|
media: this.#media,
|
|
126
138
|
language: this.#language,
|
|
@@ -152,17 +164,19 @@ function buildPrompt(data) {
|
|
|
152
164
|
instructions['**Instructions**'] = data.instructions;
|
|
153
165
|
}
|
|
154
166
|
const hasOutputSchema = isDefined(data.outputSchema);
|
|
155
|
-
if (hasOutputSchema || isDefined(data.outputExamples)) {
|
|
167
|
+
if (hasOutputSchema || data.outputRules || isDefined(data.outputExamples)) {
|
|
156
168
|
if (hasOutputSchema) {
|
|
157
169
|
const schema = convertToOpenApiSchema(data.outputSchema);
|
|
158
170
|
const schemaJson = JSON.stringify(schema, null, 2);
|
|
159
171
|
instructions['**Output Schema**'] = `\`\`\`json\n${schemaJson}\n\`\`\``;
|
|
160
172
|
}
|
|
161
|
-
|
|
162
|
-
'Schema
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
if (data.outputRules) {
|
|
174
|
+
instructions['**Output Schema Instructions**'] = unorderedList({
|
|
175
|
+
'Schema Compliance': 'Generate valid JSON that strictly matches the provided schema.',
|
|
176
|
+
'Nullable fields with missing data': 'Must be set to literal `null`, not the string "null".',
|
|
177
|
+
'Optional fields with missing data': 'Omit the key entirely (sparse JSON).',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
166
180
|
if (isDefined(data.outputExamples) && (data.outputExamples.length > 0)) {
|
|
167
181
|
instructions['**Output Examples**'] = fewShotPrompt(data.outputExamples);
|
|
168
182
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { HttpServerResponse } from '../../http/server/index.js';
|
|
2
2
|
import type { Logger } from '../../logger/index.js';
|
|
3
3
|
import type { Type } from '../../types/index.js';
|
|
4
|
-
export declare function handleApiError(error: unknown, response: HttpServerResponse, supressedErrors: Set<Type<Error>>, logger: Logger):
|
|
4
|
+
export declare function handleApiError(error: unknown, response: HttpServerResponse, supressedErrors: Set<Type<Error>>, logger: Logger): void;
|
package/api/types.d.ts
CHANGED
|
@@ -109,12 +109,12 @@ export type ApiEndpointParametersSchema<T extends ApiDefinition, K extends ApiEn
|
|
|
109
109
|
export type ApiEndpointBodySchema<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = NonUndefinable<ApiEndpoint<T, K>['body']>;
|
|
110
110
|
export type ApiEndpointResultSchema<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = NonUndefinable<ApiEndpoint<T, K>['result']>;
|
|
111
111
|
export type ApiBinaryType = typeof Uint8Array | typeof Blob | typeof ReadableStream;
|
|
112
|
-
export type ApiInputType<T extends SchemaTestable> = T extends ApiBinaryType ? InstanceType<Exclude<ApiBinaryType, typeof ReadableStream> | typeof ReadableStream<Uint8Array<ArrayBuffer>>> : T extends typeof ServerSentEvents ? ServerSentEventsSource : T extends typeof DataStream<infer U> ? AsyncIterable<U> | DataStreamSource<U> :
|
|
113
|
-
export type ApiOutputType<T extends SchemaTestable> = T extends typeof ReadableStream ? ReadableStream<Uint8Array<ArrayBuffer>> : T extends typeof DataStream<infer U> ? Observable<U> :
|
|
112
|
+
export type ApiInputType<T extends SchemaTestable> = T extends ApiBinaryType ? InstanceType<Exclude<ApiBinaryType, typeof ReadableStream> | typeof ReadableStream<Uint8Array<ArrayBuffer>>> : T extends typeof ServerSentEvents ? ServerSentEventsSource : T extends typeof DataStream<infer U> ? AsyncIterable<U> | DataStreamSource<U> : SchemaOutput<T>;
|
|
113
|
+
export type ApiOutputType<T extends SchemaTestable> = T extends typeof ReadableStream ? ReadableStream<Uint8Array<ArrayBuffer>> : T extends typeof DataStream<infer U> ? Observable<U> : SchemaOutput<T>;
|
|
114
114
|
export type ApiParameters<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointParametersSchema<T, K>>;
|
|
115
115
|
export type ApiClientBody<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointBodySchema<T, K>>;
|
|
116
|
-
export type ApiServerBody<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiOutputType<
|
|
117
|
-
export type ApiServerResult<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointResultSchema<T, K>> | HttpServerResponse
|
|
116
|
+
export type ApiServerBody<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiOutputType<ApiEndpointResultSchema<T, K>>;
|
|
117
|
+
export type ApiServerResult<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointResultSchema<T, K>> | HttpServerResponse<ApiServerBody<T, K>>;
|
|
118
118
|
export type ApiClientResult<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiOutputType<ApiEndpointResultSchema<T, K>>;
|
|
119
119
|
export type ApiRequestData<T extends ApiDefinition = ApiDefinition, K extends ApiEndpointKeys<T> = ApiEndpointKeys<T>> = {
|
|
120
120
|
parameters: ApiParameters<T, K>;
|
|
@@ -36,7 +36,6 @@ export declare const authenticationApiDefinition: {
|
|
|
36
36
|
result: import("../schema/index.js").UnionSchema<[ObjectSchema<{
|
|
37
37
|
type: "success";
|
|
38
38
|
result: TokenPayload<import("type-fest").EmptyObject>;
|
|
39
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
40
39
|
}>, ObjectSchema<{
|
|
41
40
|
type: "totp";
|
|
42
41
|
challengeToken: string;
|
|
@@ -56,7 +55,6 @@ export declare const authenticationApiDefinition: {
|
|
|
56
55
|
result: ObjectSchema<{
|
|
57
56
|
type: "success";
|
|
58
57
|
result: TokenPayload<import("type-fest").EmptyObject>;
|
|
59
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
60
58
|
}>;
|
|
61
59
|
credentials: true;
|
|
62
60
|
data: {
|
|
@@ -73,7 +71,6 @@ export declare const authenticationApiDefinition: {
|
|
|
73
71
|
result: ObjectSchema<{
|
|
74
72
|
type: "success";
|
|
75
73
|
result: TokenPayload<import("type-fest").EmptyObject>;
|
|
76
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
77
74
|
}>;
|
|
78
75
|
credentials: true;
|
|
79
76
|
data: {
|
|
@@ -265,8 +262,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
265
262
|
}>;
|
|
266
263
|
result: import("../schema/index.js").UnionSchema<[ObjectSchema<{
|
|
267
264
|
type: "success";
|
|
268
|
-
result:
|
|
269
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
265
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
270
266
|
}>, ObjectSchema<{
|
|
271
267
|
type: "totp";
|
|
272
268
|
challengeToken: string;
|
|
@@ -285,8 +281,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
285
281
|
}>;
|
|
286
282
|
result: ObjectSchema<{
|
|
287
283
|
type: "success";
|
|
288
|
-
result:
|
|
289
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
284
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
290
285
|
}>;
|
|
291
286
|
credentials: true;
|
|
292
287
|
data: {
|
|
@@ -302,8 +297,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
302
297
|
}>;
|
|
303
298
|
result: ObjectSchema<{
|
|
304
299
|
type: "success";
|
|
305
|
-
result:
|
|
306
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
300
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
307
301
|
}>;
|
|
308
302
|
credentials: true;
|
|
309
303
|
data: {
|
|
@@ -490,8 +484,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
490
484
|
}>;
|
|
491
485
|
result: import("../schema/index.js").UnionSchema<[ObjectSchema<{
|
|
492
486
|
type: "success";
|
|
493
|
-
result:
|
|
494
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
487
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
495
488
|
}>, ObjectSchema<{
|
|
496
489
|
type: "totp";
|
|
497
490
|
challengeToken: string;
|
|
@@ -510,8 +503,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
510
503
|
}>;
|
|
511
504
|
result: ObjectSchema<{
|
|
512
505
|
type: "success";
|
|
513
|
-
result:
|
|
514
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
506
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
515
507
|
}>;
|
|
516
508
|
credentials: true;
|
|
517
509
|
data: {
|
|
@@ -527,8 +519,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
527
519
|
}>;
|
|
528
520
|
result: ObjectSchema<{
|
|
529
521
|
type: "success";
|
|
530
|
-
result:
|
|
531
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
522
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
532
523
|
}>;
|
|
533
524
|
credentials: true;
|
|
534
525
|
data: {
|
|
@@ -47,7 +47,6 @@ export function getAuthenticationApiEndpointsDefinition(additionalTokenPayloadSc
|
|
|
47
47
|
const loginSuccessResultSchema = object({
|
|
48
48
|
type: literal('success'),
|
|
49
49
|
result: tokenResultSchema,
|
|
50
|
-
lowRecoveryCodesWarning: optional(boolean()),
|
|
51
50
|
});
|
|
52
51
|
const loginTotpResultSchema = object({
|
|
53
52
|
type: literal('totp'),
|
|
@@ -46,8 +46,6 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
46
46
|
readonly rawRefreshToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
47
47
|
/** Current raw impersonator refresh token */
|
|
48
48
|
readonly rawImpersonatorRefreshToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
49
|
-
/** Whether the remaining recovery codes are low */
|
|
50
|
-
readonly lowRecoveryCodesWarning: import("../../signals/api.js").WritableSignal<boolean | undefined>;
|
|
51
49
|
/** Whether the user is logged in */
|
|
52
50
|
readonly isLoggedIn: import("../../signals/api.js").Signal<boolean>;
|
|
53
51
|
/** Current session id */
|
|
@@ -93,8 +93,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
93
93
|
rawRefreshToken = signal(undefined);
|
|
94
94
|
/** Current raw impersonator refresh token */
|
|
95
95
|
rawImpersonatorRefreshToken = signal(undefined);
|
|
96
|
-
/** Whether the remaining recovery codes are low */
|
|
97
|
-
lowRecoveryCodesWarning = signal(undefined);
|
|
98
96
|
/** Whether the user is logged in */
|
|
99
97
|
isLoggedIn = computed(() => isDefined(this.token()));
|
|
100
98
|
/** Current session id */
|
|
@@ -253,7 +251,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
253
251
|
if (result.type == 'totp') {
|
|
254
252
|
return result;
|
|
255
253
|
}
|
|
256
|
-
this.lowRecoveryCodesWarning.set(result.lowRecoveryCodesWarning);
|
|
257
254
|
this.setNewToken(result.result);
|
|
258
255
|
return { type: 'success' };
|
|
259
256
|
}
|
|
@@ -264,7 +261,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
264
261
|
*/
|
|
265
262
|
async verifyTotpLogin(challengeToken, token) {
|
|
266
263
|
const result = await this.client.loginVerifyTotp({ challengeToken, token });
|
|
267
|
-
this.lowRecoveryCodesWarning.set(result.lowRecoveryCodesWarning);
|
|
268
264
|
this.setNewToken(result.result);
|
|
269
265
|
}
|
|
270
266
|
/**
|
|
@@ -274,7 +270,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
274
270
|
*/
|
|
275
271
|
async loginRecovery(challengeToken, recoveryCode) {
|
|
276
272
|
const result = await this.client.loginRecovery({ challengeToken, recoveryCode });
|
|
277
|
-
this.lowRecoveryCodesWarning.set(result.lowRecoveryCodesWarning);
|
|
278
273
|
this.setNewToken(result.result);
|
|
279
274
|
}
|
|
280
275
|
/**
|
|
@@ -100,7 +100,7 @@ export declare class AuthenticationApiController<AdditionalTokenPayload extends
|
|
|
100
100
|
invalidateAllOtherSessions({ getToken, getAuditor }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitPasswordResetData>, 'invalidateAllOtherSessions'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitPasswordResetData>, 'invalidateAllOtherSessions'>>;
|
|
101
101
|
protected enforceRateLimit(ip: string, subjectResource: string, auditor: Auditor, targetId: string, action: string): Promise<void>;
|
|
102
102
|
protected refundRateLimit(ip: string, subjectResource: string): Promise<void>;
|
|
103
|
-
protected getTokenResponse<T>(result: TokenResult<AdditionalTokenPayload>, body:
|
|
103
|
+
protected getTokenResponse<T>(result: TokenResult<AdditionalTokenPayload>, body: T): HttpServerResponse<T>;
|
|
104
104
|
protected getLoginResponse(result: LoginResult<AdditionalTokenPayload>): ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitPasswordResetData>, 'login'>;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
@@ -381,7 +381,6 @@ let AuthenticationApiController = AuthenticationApiController_1 = class Authenti
|
|
|
381
381
|
return this.getTokenResponse(result.result, {
|
|
382
382
|
type: 'success',
|
|
383
383
|
result: result.result.jsonToken.payload,
|
|
384
|
-
lowRecoveryCodesWarning: result.lowRecoveryCodesWarning,
|
|
385
384
|
});
|
|
386
385
|
}
|
|
387
386
|
return result;
|
|
@@ -158,7 +158,6 @@ export type TokenResult<AdditionalTokenPayload extends Record> = {
|
|
|
158
158
|
export type LoginSuccessResult<AdditionalTokenPayload extends Record> = {
|
|
159
159
|
type: 'success';
|
|
160
160
|
result: TokenResult<AdditionalTokenPayload>;
|
|
161
|
-
lowRecoveryCodesWarning?: boolean;
|
|
162
161
|
};
|
|
163
162
|
export type LoginTotpResult = {
|
|
164
163
|
type: 'totp';
|
|
@@ -1105,9 +1105,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1105
1105
|
throw new ForbiddenError('Invalid recovery code');
|
|
1106
1106
|
}
|
|
1107
1107
|
const subject = await this.#subjectRepository.loadByQuery({ tenantId: tenant, id: subjectId });
|
|
1108
|
-
|
|
1109
|
-
const unusedRecoveryCodesCount = await this.#totpRecoveryCodeRepository.withTransaction(tx).countByQuery({ tenantId: tenant, totpId: totp.id, usedTimestamp: null });
|
|
1110
|
-
return { loginResult, unusedRecoveryCodesCount };
|
|
1108
|
+
return await this.#loginAlreadyValidatedSubject(subject, data, authAuditor, remember);
|
|
1111
1109
|
});
|
|
1112
1110
|
await authAuditor.info('recovery-login-success', {
|
|
1113
1111
|
tenantId: tenant,
|
|
@@ -1115,16 +1113,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1115
1113
|
actorType: ActorType.Subject,
|
|
1116
1114
|
targetId: subjectId,
|
|
1117
1115
|
targetType: 'Subject',
|
|
1118
|
-
network: { sessionId: result.
|
|
1116
|
+
network: { sessionId: result.result.jsonToken.payload.session },
|
|
1119
1117
|
details: {
|
|
1120
|
-
sessionId: result.
|
|
1118
|
+
sessionId: result.result.jsonToken.payload.session,
|
|
1121
1119
|
remember,
|
|
1122
1120
|
},
|
|
1123
1121
|
});
|
|
1124
|
-
return
|
|
1125
|
-
...result.loginResult,
|
|
1126
|
-
lowRecoveryCodesWarning: result.unusedRecoveryCodesCount <= 3,
|
|
1127
|
-
};
|
|
1122
|
+
return result;
|
|
1128
1123
|
}
|
|
1129
1124
|
async #loginVerifyTotp(challengeTokenString, token, authAuditor) {
|
|
1130
1125
|
const challengeToken = await this.validateTotpChallengeToken(challengeTokenString);
|
|
@@ -16,7 +16,7 @@ export declare const dataExtractionFields: {
|
|
|
16
16
|
Tags: string;
|
|
17
17
|
Date: string;
|
|
18
18
|
};
|
|
19
|
-
export declare function createDataExtractionPrompt(
|
|
19
|
+
export declare function createDataExtractionPrompt(): PromptBuilder;
|
|
20
20
|
export declare const assignCollectionSchema: import("../../../schema/index.js").ObjectSchema<{
|
|
21
21
|
collectionIds: string[];
|
|
22
22
|
}>;
|
|
@@ -8,7 +8,7 @@ export function createContentExtractionPrompt() {
|
|
|
8
8
|
return promptBuilder()
|
|
9
9
|
.setSystemRole(DOCUMENT_MANAGEMENT_SYSTEM_ROLE)
|
|
10
10
|
.setTask('Transcribe the attached document into Markdown following the instructions.')
|
|
11
|
-
.
|
|
11
|
+
.enableOutputRules()
|
|
12
12
|
.addInstructions({
|
|
13
13
|
'Objective': 'Convert the provided document into semantically structured, clean Markdown.',
|
|
14
14
|
'Critical Constraints': orderedList([
|
|
@@ -56,12 +56,11 @@ export function createClassifySchema(validTypes) {
|
|
|
56
56
|
return object({ documentType: enumeration(validTypes) });
|
|
57
57
|
}
|
|
58
58
|
export function createClassifyPrompt(validTypes) {
|
|
59
|
-
const schema = createClassifySchema(validTypes);
|
|
60
59
|
return promptBuilder()
|
|
61
60
|
.setSystemRole(DOCUMENT_MANAGEMENT_SYSTEM_ROLE)
|
|
62
61
|
.setRole('Document Taxonomy Specialist')
|
|
63
62
|
.setTask('Determine the single most accurate document type from the provided list based on the document.')
|
|
64
|
-
.
|
|
63
|
+
.setOutputExamples(CLASSIFY_FEW_SHOT)
|
|
65
64
|
.addInstructions({
|
|
66
65
|
'Analysis Strategy': orderedList([
|
|
67
66
|
'Scan the header and title for explicit document type names (e.g., "Invoice", "Contract", "Bill of Lading").',
|
|
@@ -85,12 +84,12 @@ export const dataExtractionFields = {
|
|
|
85
84
|
Tags: 'Generate 3-5 keywords for categorization. Only use important information missing in title, subtitle and properties. Prioritize reusing of existing tags where possible.',
|
|
86
85
|
Date: 'Identify the *creation* date of the document. If multiple dates exist, prioritize the primary date (like invoice or letter Date). Return as object with year, month and day.',
|
|
87
86
|
};
|
|
88
|
-
export function createDataExtractionPrompt(
|
|
87
|
+
export function createDataExtractionPrompt() {
|
|
89
88
|
return promptBuilder()
|
|
90
89
|
.setSystemRole(DOCUMENT_MANAGEMENT_SYSTEM_ROLE)
|
|
91
90
|
.setRole('Structured Data Extraction Analyst')
|
|
92
91
|
.setTask('Analyze the document and extract metadata and specific properties defined in the output schema following the instructions.')
|
|
93
|
-
.
|
|
92
|
+
.enableOutputRules()
|
|
94
93
|
.addInstructions({
|
|
95
94
|
'Field Specific Instructions': dataExtractionFields,
|
|
96
95
|
'Property Extraction': orderedList([
|
|
@@ -119,7 +118,7 @@ export function createAssignCollectionPrompt() {
|
|
|
119
118
|
.setSystemRole(DOCUMENT_MANAGEMENT_SYSTEM_ROLE)
|
|
120
119
|
.setRole('Digital Filing Assistant')
|
|
121
120
|
.setTask('Select the most appropriate collections for this document from the provided list following the instructions.')
|
|
122
|
-
.
|
|
121
|
+
.setOutputExamples(ASSIGN_COLLECTION_FEW_SHOT)
|
|
123
122
|
.addInstructions({
|
|
124
123
|
'Matching Logic': orderedList([
|
|
125
124
|
'Direct Key-Match: Look for exact keyword matches between the collection name and the document metadata.',
|
|
@@ -146,7 +145,7 @@ export function createAssignRequestPrompt() {
|
|
|
146
145
|
.setSystemRole(DOCUMENT_MANAGEMENT_SYSTEM_ROLE)
|
|
147
146
|
.setRole('Workflow Routing Agent')
|
|
148
147
|
.setTask('Evaluate the document against the list of open requests and find the best match following the instructions.')
|
|
149
|
-
.
|
|
148
|
+
.setOutputExamples(ASSIGN_REQUEST_FEW_SHOT)
|
|
150
149
|
.addInstructions({
|
|
151
150
|
'Matching Rules': orderedList({
|
|
152
151
|
'Hard Constraints': 'If a Request has a "Comment" or specific property requirement, the document MUST fulfill it strictly (e.g., "Need bill from July" must match date).',
|
|
@@ -134,7 +134,7 @@ let DocumentManagementAiService = DocumentManagementAiService_1 = class Document
|
|
|
134
134
|
const override = (isNotNull(property.key) ? aiConfig.extraction?.properties?.[property.key] : undefined) ?? aiConfig.extraction?.properties?.[property.label];
|
|
135
135
|
return isDefined(override) ? mergeInstructions(`Extract value for property "${property.label}".`, [override]) : undefined;
|
|
136
136
|
}).filter(isDefined);
|
|
137
|
-
const promptBuilder = createDataExtractionPrompt(
|
|
137
|
+
const promptBuilder = createDataExtractionPrompt();
|
|
138
138
|
promptBuilder.addInstructions({
|
|
139
139
|
'Field Specific Instructions': mergedFieldInstructions,
|
|
140
140
|
'Additional Property Extraction': isDefined(mergedPropertyInstructions) && (mergedPropertyInstructions.length > 0)
|
|
@@ -26,7 +26,7 @@ export class AiValidationExecutor extends DocumentValidationExecutor {
|
|
|
26
26
|
.setSystemTask('Validate a document based on the provided validation instructions and document content.')
|
|
27
27
|
.setTask('Validate the document based on the provided system and validation instructions and the document content.')
|
|
28
28
|
.addInstructions({ 'Validation Instructions': validationInstructions })
|
|
29
|
-
.
|
|
29
|
+
.enableOutputRules()
|
|
30
30
|
.addMedia(documentContent, context.document.mimeType);
|
|
31
31
|
if (isDefined(language)) {
|
|
32
32
|
builder.setLanguage(language);
|
|
@@ -7,33 +7,33 @@ import { ServerTiming } from '../server-timing.js';
|
|
|
7
7
|
export type SetCookieObject = SetCookieOptions & {
|
|
8
8
|
value: string;
|
|
9
9
|
};
|
|
10
|
-
export type HttpServerResponseBody = {
|
|
10
|
+
export type HttpServerResponseBody<out T = unknown> = {
|
|
11
11
|
stream?: ReadableStream<Uint8Array>;
|
|
12
12
|
buffer?: Uint8Array;
|
|
13
13
|
text?: string;
|
|
14
|
-
json?:
|
|
14
|
+
json?: T;
|
|
15
15
|
events?: ServerSentEventsSource;
|
|
16
16
|
};
|
|
17
17
|
export type HttpServerResponseBodyType = 'stream' | 'buffer' | 'text' | 'json' | 'events' | 'none';
|
|
18
|
-
export type HttpServerResponseOptions = {
|
|
18
|
+
export type HttpServerResponseOptions<out T = unknown> = {
|
|
19
19
|
statusCode?: number | undefined;
|
|
20
20
|
statusMessage?: string | undefined;
|
|
21
21
|
headers?: HttpHeadersInput | HttpHeaders;
|
|
22
22
|
cookies?: Record<string, SetCookieObject>;
|
|
23
|
-
body?: HttpServerResponseBody
|
|
23
|
+
body?: HttpServerResponseBody<T>;
|
|
24
24
|
};
|
|
25
|
-
export declare class HttpServerResponse {
|
|
25
|
+
export declare class HttpServerResponse<out T = unknown> {
|
|
26
26
|
#private;
|
|
27
27
|
readonly headers: HttpHeaders;
|
|
28
28
|
readonly serverTiming: ServerTiming;
|
|
29
29
|
statusCode: number | undefined;
|
|
30
30
|
statusMessage: string | undefined;
|
|
31
|
-
get body(): HttpServerResponseBody | undefined;
|
|
32
|
-
set body(value: HttpServerResponseBody | undefined);
|
|
31
|
+
get body(): HttpServerResponseBody<T> | undefined;
|
|
32
|
+
set body(value: HttpServerResponseBody<T> | undefined);
|
|
33
33
|
get bodyType(): HttpServerResponseBodyType;
|
|
34
|
-
constructor(response?: HttpServerResponseOptions);
|
|
35
|
-
static fromObject(options?: HttpServerResponseOptions): HttpServerResponse
|
|
36
|
-
static redirect(url: string, options?: HttpServerResponseOptions): HttpServerResponse
|
|
37
|
-
update(options: HttpServerResponseOptions): void;
|
|
34
|
+
constructor(response?: HttpServerResponseOptions<T>);
|
|
35
|
+
static fromObject<T>(options?: HttpServerResponseOptions<T>): HttpServerResponse<T>;
|
|
36
|
+
static redirect<T>(url: string, options?: HttpServerResponseOptions<T>): HttpServerResponse<T>;
|
|
37
|
+
update(options: HttpServerResponseOptions<T>): void;
|
|
38
38
|
}
|
|
39
|
-
export declare function redirect(url: string, options?: HttpServerResponseOptions): HttpServerResponse
|
|
39
|
+
export declare function redirect<T>(url: string, options?: HttpServerResponseOptions<T>): HttpServerResponse<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.196",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -153,8 +153,8 @@
|
|
|
153
153
|
"type-fest": "^5.5"
|
|
154
154
|
},
|
|
155
155
|
"peerDependencies": {
|
|
156
|
-
"@aws-sdk/client-s3": "^3.
|
|
157
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
156
|
+
"@aws-sdk/client-s3": "^3.1025",
|
|
157
|
+
"@aws-sdk/s3-request-presigner": "^3.1025",
|
|
158
158
|
"@genkit-ai/google-genai": "^1.31",
|
|
159
159
|
"@google-cloud/storage": "^7.19",
|
|
160
160
|
"@toon-format/toon": "^2.1.0",
|
package/schema/schema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type SchemaTestResult<T> = {
|
|
|
20
20
|
};
|
|
21
21
|
type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, String>> extends true ? typeof String : Or<IsEqual<T, number>, IsEqual<T, Number>> extends true ? typeof Number : Or<IsEqual<T, boolean>, IsEqual<T, Boolean>> extends true ? typeof Boolean : Or<IsEqual<T, bigint>, IsEqual<T, BigInt>> extends true ? typeof BigInt : Or<IsEqual<T, symbol>, IsEqual<T, Symbol>> extends true ? typeof Symbol : never;
|
|
22
22
|
export type SchemaTestable<T = any> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
23
|
-
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
23
|
+
export type SchemaOutput<T extends SchemaTestable> = T extends Schema<infer U> ? U : T extends SchemaTestable<infer U> ? U : never;
|
|
24
24
|
export declare const OPTIONAL: unique symbol;
|
|
25
25
|
export type SchemaOptions<_T> = {
|
|
26
26
|
description?: string | null;
|