@tstdl/base 0.92.108 → 0.92.109

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.
@@ -2,7 +2,7 @@ import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js'
2
2
  import { type OneOrMany, type SchemaTestable } from '../schema/index.js';
3
3
  import type { Enumeration as EnumerationType, EnumerationValue } from '../types.js';
4
4
  import { AiSession } from './ai-session.js';
5
- import { type AiModel, type Content, type ContentPart, type FileContentPart, type FileInput, type GenerationOptions, type GenerationRequest, type GenerationResult, type SchemaFunctionDeclarations, type SchemaFunctionDeclarationsResult } from './types.js';
5
+ import { type AiModel, type Content, type ContentPart, type FileContentPart, type FileInput, type FunctionResultContentPart, type GenerationOptions, type GenerationRequest, type GenerationResult, type SchemaFunctionDeclarations, type SchemaFunctionDeclarationsResult } from './types.js';
6
6
  export type SpecializedGenerationResult<T> = {
7
7
  result: T;
8
8
  raw: GenerationResult;
@@ -32,7 +32,7 @@ export type AnalyzeContentResult<T extends EnumerationType> = {
32
32
  documentTypes: ClassificationResult<T>[];
33
33
  tags: string[];
34
34
  };
35
- export type CallFunctionsOptions<T extends SchemaFunctionDeclarations> = Pick<GenerationRequest, 'contents' | 'model' | 'systemInstruction'> & GenerationOptions & {
35
+ export type CallFunctionsOptions<T extends SchemaFunctionDeclarations> = Pick<GenerationRequest, 'contents' | 'model' | 'systemInstruction' | 'functionCallingMode'> & GenerationOptions & {
36
36
  functions: T;
37
37
  };
38
38
  export declare class AiService implements Resolvable<AiServiceArgument> {
@@ -52,7 +52,9 @@ export declare class AiService implements Resolvable<AiServiceArgument> {
52
52
  maximumNumberOfTags?: number;
53
53
  }): Promise<SpecializedGenerationResult<AnalyzeContentResult<T>>>;
54
54
  getAnalyzeContentConents(parts: OneOrMany<ContentPart>): Content[];
55
- callFunctions<const T extends SchemaFunctionDeclarations>(options: CallFunctionsOptions<T>): Promise<SpecializedGenerationResult<SchemaFunctionDeclarationsResult<T>[]>>;
55
+ callFunctions<const T extends SchemaFunctionDeclarations>(options: CallFunctionsOptions<T>): Promise<SpecializedGenerationResult<SchemaFunctionDeclarationsResult<T>[]> & {
56
+ getFunctionResultContentParts: () => FunctionResultContentPart[];
57
+ }>;
56
58
  callFunctionsStream<const T extends SchemaFunctionDeclarations>(options: CallFunctionsOptions<T>): SpecializedGenerationResultGenerator<SchemaFunctionDeclarationsResult<T>>;
57
59
  generate<S>(request: GenerationRequest<S>): Promise<GenerationResult<S>>;
58
60
  generateStream<S>(request: GenerationRequest<S>): AsyncGenerator<GenerationResult<S>>;
package/ai/ai.service.js CHANGED
@@ -170,7 +170,7 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
170
170
  },
171
171
  systemInstruction: options.systemInstruction,
172
172
  functions: options.functions,
173
- functionCallingMode: 'force',
173
+ functionCallingMode: options.functionCallingMode ?? 'force',
174
174
  contents: options.contents
175
175
  });
176
176
  const result = [];
@@ -179,11 +179,17 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
179
179
  const parametersSchema = await resolveValueOrAsyncProvider(fn.parameters);
180
180
  const parameters = isDefined(parametersSchema) ? parametersSchema.parse(call.parameters) : call.parameters;
181
181
  const handlerResult = isSchemaFunctionDeclarationWithHandler(fn) ? await fn.handler(parameters) : undefined;
182
- result.push({ functionName: call.name, parameters: parameters, handlerResult: handlerResult });
182
+ result.push({
183
+ functionName: call.name,
184
+ parameters: parameters,
185
+ handlerResult: handlerResult,
186
+ getFunctionResultContentPart: () => ({ functionResult: { name: call.name, value: handlerResult } })
187
+ });
183
188
  }
184
189
  return {
185
190
  result,
186
- raw: generation
191
+ raw: generation,
192
+ getFunctionResultContentParts: () => result.map((result) => result.getFunctionResultContentPart())
187
193
  };
188
194
  }
189
195
  callFunctionsStream(options) {
@@ -308,7 +314,7 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
308
314
  },
309
315
  systemInstruction: options.systemInstruction,
310
316
  functions: options.functions,
311
- functionCallingMode: 'force',
317
+ functionCallingMode: options.functionCallingMode ?? 'force',
312
318
  contents: options.contents
313
319
  });
314
320
  const items = [];
@@ -319,7 +325,12 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
319
325
  const parametersSchema = await resolveValueOrAsyncProvider(fn.parameters);
320
326
  const parameters = isDefined(parametersSchema) ? parametersSchema.parse(call.parameters) : call.parameters;
321
327
  const handlerResult = isSchemaFunctionDeclarationWithHandler(fn) ? await fn.handler(parameters) : undefined;
322
- yield { functionName: call.name, parameters: parameters, handlerResult: handlerResult };
328
+ yield {
329
+ functionName: call.name,
330
+ parameters: parameters,
331
+ handlerResult: handlerResult,
332
+ getFunctionResultContentPart: () => ({ functionResult: { name: call.name, value: handlerResult } })
333
+ };
323
334
  }
324
335
  }
325
336
  itemsPromise.resolve(items);
package/ai/types.d.ts CHANGED
@@ -22,6 +22,7 @@ export type SchemaFunctionDeclarationsResult<T extends SchemaFunctionDeclaration
22
22
  functionName: P;
23
23
  parameters: SchemaOutput<NonNullable<ResolvedValueOrProvider<T[P]['parameters']>>>;
24
24
  handlerResult: SchemaFunctionDeclarationHandlerResult<T[P]>;
25
+ getFunctionResultContentPart: () => FunctionResultContentPart;
25
26
  };
26
27
  }[keyof T];
27
28
  export type ContentRole = 'user' | 'model';
@@ -132,7 +132,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
132
132
  return this.collectionChangeMessageBus.allMessages$.pipe(filter((message) => isUndefined(message) || collectionIdsArray.some((id) => message.includes(id))), debounceTime(250), map(() => undefined));
133
133
  }
134
134
  processQueues(cancellationSignal) {
135
- this.extractionQueue.process({ concurrency: 1, cancellationSignal }, async (job) => {
135
+ this.extractionQueue.process({ concurrency: 5, cancellationSignal }, async (job) => {
136
136
  const [entry] = objectEntries(job.data);
137
137
  this.logger.verbose(`Processing extraction job for ${entry?.[0]} ${entry?.[1]}`);
138
138
  await match(job.data)
@@ -141,7 +141,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
141
141
  .with({ requestAssignmentTaskId: P.string.select() }, async (requestAssignmentTaskId) => this.enrichDocumentRequestAssignmentTask(requestAssignmentTaskId))
142
142
  .exhaustive();
143
143
  }, this.logger);
144
- this.assignmentQueue.process({ concurrency: 1, cancellationSignal }, async (job) => {
144
+ this.assignmentQueue.process({ concurrency: 5, cancellationSignal }, async (job) => {
145
145
  this.logger.verbose(`Processing assignment job "${job.data.requestAssignmentTaskId}"`);
146
146
  await this.assignDocumentRequest(job.data.requestAssignmentTaskId);
147
147
  }, this.logger);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.108",
3
+ "version": "0.92.109",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"