@tstdl/base 0.92.109 → 0.92.111

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.js CHANGED
@@ -41,6 +41,7 @@ const functionCallingModeMap = {
41
41
  force: GoogleFunctionCallingMode.ANY,
42
42
  none: GoogleFunctionCallingMode.NONE
43
43
  };
44
+ let generationCounter = 0;
44
45
  let AiService = AiService_1 = class AiService {
45
46
  #options = injectArgument(this, { optional: true }) ?? inject(AiServiceOptions);
46
47
  #fileService = inject(AiFileService, this.#options);
@@ -206,7 +207,7 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
206
207
  return mergeGenerationStreamItems(items, request.generationSchema);
207
208
  }
208
209
  async *generateStream(request) {
209
- this.#logger.verbose('Generating...');
210
+ const generationNumber = ++generationCounter;
210
211
  const googleFunctionDeclarations = isDefined(request.functions) ? await this.convertFunctions(request.functions) : undefined;
211
212
  const generationConfig = {
212
213
  maxOutputTokens: request.generationOptions?.maxOutputTokens,
@@ -229,6 +230,7 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
229
230
  let generation;
230
231
  for (let i = 0;; i++) {
231
232
  try {
233
+ this.#logger.verbose(`[C:${generationNumber}] [I:${iterations + 1}] Generating...`);
232
234
  generation = await this.getModel(model).generateContentStream({
233
235
  generationConfig: {
234
236
  ...generationConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.109",
3
+ "version": "0.92.111",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -101,16 +101,24 @@ let PostgresQueue = class PostgresQueue extends Queue {
101
101
  return jobs[0];
102
102
  }
103
103
  async dequeueMany(count) {
104
- const rows = await this.#repository.session
105
- .update(job)
106
- .set(this.#dequeueUpdate)
107
- .where(inArray(job.id, this.#repository.session
104
+ /*
105
+ * Materialization required for LIMIT clause
106
+ * https://stackoverflow.com/questions/73966670/select-for-update-subquery-not-respecting-limit-clause-under-load
107
+ * https://dba.stackexchange.com/questions/69471/postgres-update-limit-1
108
+ */
109
+ const selection = this.#repository.session.$with('selection').as((qb) => qb
108
110
  .select({ id: job.id })
109
111
  .from(job)
110
- .where(this.#dequeueQuery)
112
+ .where(and(this.#dequeueQuery, sql `pg_sleep(0) IS NOT NULL` // workaround to force materialization until drizzle implements https://github.com/drizzle-team/drizzle-orm/issues/2318
113
+ ))
111
114
  .orderBy(asc(job.priority), asc(job.enqueueTimestamp), asc(job.lastDequeueTimestamp), asc(job.tries))
112
115
  .limit(count)
113
- .for('update', { skipLocked: true })))
116
+ .for('update', { skipLocked: true }));
117
+ const rows = await this.#repository.session
118
+ .with(selection)
119
+ .update(job)
120
+ .set(this.#dequeueUpdate)
121
+ .where(inArray(job.id, this.#repository.session.select().from(selection)))
114
122
  .returning();
115
123
  return this.#repository.mapManyToEntity(rows);
116
124
  }