@agentforge/core 0.18.0 → 0.18.2

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 (3) hide show
  1. package/dist/index.cjs +78 -117
  2. package/dist/index.js +78 -117
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -317,81 +317,64 @@ var MissingDescriptionError = class extends Error {
317
317
  this.name = "MissingDescriptionError";
318
318
  }
319
319
  };
320
- function validateSchemaDescriptions(schema, fieldPath = []) {
320
+ function* findMissingDescriptions(schema, fieldPath = []) {
321
321
  const def = schema._def;
322
322
  const typeName = def.typeName;
323
323
  if (schema instanceof import_zod2.z.ZodObject) {
324
- const shape = schema.shape;
325
- Object.entries(shape).forEach(([key, fieldSchema]) => {
326
- validateSchemaDescriptions(fieldSchema, [...fieldPath, key]);
327
- });
328
- return;
329
- }
330
- if (schema instanceof import_zod2.z.ZodArray) {
331
- validateSchemaDescriptions(def.type, [...fieldPath, "[]"]);
332
- return;
333
- }
334
- if (schema instanceof import_zod2.z.ZodOptional) {
335
- const wrapperDescription = def.description;
336
- const innerDescription = def.innerType._def.description;
337
- if (fieldPath.length > 0 && !wrapperDescription && !innerDescription) {
338
- throw new MissingDescriptionError(fieldPath, typeName);
339
- }
340
- if (!wrapperDescription) {
341
- validateSchemaDescriptions(def.innerType, fieldPath);
324
+ for (const [key, fieldSchema] of Object.entries(schema.shape)) {
325
+ yield* findMissingDescriptions(fieldSchema, [...fieldPath, key]);
342
326
  }
343
327
  return;
344
328
  }
345
- if (schema instanceof import_zod2.z.ZodNullable) {
346
- const wrapperDescription = def.description;
347
- const innerDescription = def.innerType._def.description;
348
- if (fieldPath.length > 0 && !wrapperDescription && !innerDescription) {
349
- throw new MissingDescriptionError(fieldPath, typeName);
350
- }
351
- if (!wrapperDescription) {
352
- validateSchemaDescriptions(def.innerType, fieldPath);
353
- }
329
+ if (schema instanceof import_zod2.z.ZodArray) {
330
+ yield* findMissingDescriptions(def.type, [...fieldPath, "[]"]);
354
331
  return;
355
332
  }
356
- if (schema instanceof import_zod2.z.ZodDefault) {
333
+ if (schema instanceof import_zod2.z.ZodOptional || schema instanceof import_zod2.z.ZodNullable || schema instanceof import_zod2.z.ZodDefault) {
357
334
  const wrapperDescription = def.description;
358
335
  const innerDescription = def.innerType._def.description;
359
336
  if (fieldPath.length > 0 && !wrapperDescription && !innerDescription) {
360
- throw new MissingDescriptionError(fieldPath, typeName);
337
+ yield { fieldPath, fieldType: typeName };
361
338
  }
362
339
  if (!wrapperDescription) {
363
- validateSchemaDescriptions(def.innerType, fieldPath);
340
+ yield* findMissingDescriptions(def.innerType, fieldPath);
364
341
  }
365
342
  return;
366
343
  }
367
344
  if (schema instanceof import_zod2.z.ZodUnion) {
368
- def.options.forEach((option, index) => {
369
- validateSchemaDescriptions(option, [...fieldPath, `option${index}`]);
370
- });
345
+ for (const [index, option] of def.options.entries()) {
346
+ yield* findMissingDescriptions(option, [...fieldPath, `option${index}`]);
347
+ }
371
348
  return;
372
349
  }
373
350
  if (schema instanceof import_zod2.z.ZodIntersection) {
374
- validateSchemaDescriptions(def.left, fieldPath);
375
- validateSchemaDescriptions(def.right, fieldPath);
351
+ yield* findMissingDescriptions(def.left, fieldPath);
352
+ yield* findMissingDescriptions(def.right, fieldPath);
376
353
  return;
377
354
  }
378
355
  if (schema instanceof import_zod2.z.ZodRecord) {
379
- validateSchemaDescriptions(def.valueType, [...fieldPath, "[key]"]);
356
+ yield* findMissingDescriptions(def.valueType, [...fieldPath, "[key]"]);
380
357
  return;
381
358
  }
382
359
  if (schema instanceof import_zod2.z.ZodTuple) {
383
- def.items.forEach((item, index) => {
384
- validateSchemaDescriptions(item, [...fieldPath, `[${index}]`]);
385
- });
360
+ for (const [index, item] of def.items.entries()) {
361
+ yield* findMissingDescriptions(item, [...fieldPath, `[${index}]`]);
362
+ }
386
363
  return;
387
364
  }
388
365
  if (fieldPath.length > 0) {
389
366
  const description = def.description;
390
367
  if (!description || description.trim() === "") {
391
- throw new MissingDescriptionError(fieldPath, typeName);
368
+ yield { fieldPath, fieldType: typeName };
392
369
  }
393
370
  }
394
371
  }
372
+ function validateSchemaDescriptions(schema, fieldPath = []) {
373
+ const firstFinding = findMissingDescriptions(schema, fieldPath).next();
374
+ if (!firstFinding.done) {
375
+ throw new MissingDescriptionError(firstFinding.value.fieldPath, firstFinding.value.fieldType);
376
+ }
377
+ }
395
378
  function safeValidateSchemaDescriptions(schema) {
396
379
  try {
397
380
  validateSchemaDescriptions(schema);
@@ -405,39 +388,14 @@ function safeValidateSchemaDescriptions(schema) {
405
388
  }
406
389
  function getMissingDescriptions(schema) {
407
390
  const missing = [];
408
- function check(s, path = []) {
409
- const def = s._def;
410
- const typeName = def.typeName;
411
- if (s instanceof import_zod2.z.ZodObject) {
412
- const shape = s.shape;
413
- Object.entries(shape).forEach(([key, fieldSchema]) => {
414
- check(fieldSchema, [...path, key]);
415
- });
416
- return;
417
- }
418
- if (s instanceof import_zod2.z.ZodOptional || s instanceof import_zod2.z.ZodNullable || s instanceof import_zod2.z.ZodDefault) {
419
- const wrapperDescription = def.description;
420
- const innerDescription = def.innerType._def.description;
421
- if (path.length > 0 && !wrapperDescription && !innerDescription) {
422
- missing.push(path.join("."));
423
- }
424
- if (!wrapperDescription) {
425
- check(def.innerType, path);
426
- }
427
- return;
428
- }
429
- if (s instanceof import_zod2.z.ZodArray) {
430
- check(def.type, [...path, "[]"]);
431
- return;
432
- }
433
- if (path.length > 0) {
434
- const description = def.description;
435
- if (!description || description.trim() === "") {
436
- missing.push(path.join("."));
437
- }
391
+ const seen = /* @__PURE__ */ new Set();
392
+ for (const finding of findMissingDescriptions(schema)) {
393
+ const path = finding.fieldPath.join(".");
394
+ if (!seen.has(path)) {
395
+ seen.add(path);
396
+ missing.push(path);
438
397
  }
439
398
  }
440
- check(schema);
441
399
  return missing;
442
400
  }
443
401
 
@@ -4244,6 +4202,23 @@ function createInitialPoolStats() {
4244
4202
  healthChecksFailed: 0
4245
4203
  };
4246
4204
  }
4205
+ function checkoutConnection(runtime, pooled) {
4206
+ const previousLastUsedAt = pooled.lastUsedAt;
4207
+ pooled.inUse = true;
4208
+ pooled.lastUsedAt = Date.now();
4209
+ runtime.stats.available--;
4210
+ runtime.stats.acquired++;
4211
+ try {
4212
+ runtime.options.onAcquire?.(pooled.connection);
4213
+ return pooled.connection;
4214
+ } catch (error) {
4215
+ pooled.inUse = false;
4216
+ pooled.lastUsedAt = previousLastUsedAt;
4217
+ runtime.stats.available++;
4218
+ runtime.stats.acquired--;
4219
+ throw error;
4220
+ }
4221
+ }
4247
4222
  async function initializeConnections(runtime, count) {
4248
4223
  runtime.creating += count;
4249
4224
  const promises = Array.from({ length: count }, async () => {
@@ -4265,23 +4240,22 @@ async function initializeConnections(runtime, count) {
4265
4240
  await Promise.all(promises);
4266
4241
  }
4267
4242
  function assignConnectionToPendingAcquire(runtime, connection) {
4268
- const pending = runtime.pending.shift();
4269
- if (!pending) {
4270
- return;
4271
- }
4272
4243
  const pooled = runtime.connections.find((item) => item.connection === connection);
4273
4244
  if (!pooled) {
4274
- runtime.pending.unshift(pending);
4275
4245
  return;
4276
4246
  }
4277
- clearTimeout(pending.timeout);
4278
- runtime.stats.pending--;
4279
- pooled.inUse = true;
4280
- pooled.lastUsedAt = Date.now();
4281
- runtime.stats.available--;
4282
- runtime.stats.acquired++;
4283
- runtime.options.onAcquire?.(connection);
4284
- pending.resolve(connection);
4247
+ let pending = runtime.pending.shift();
4248
+ while (pending) {
4249
+ clearTimeout(pending.timeout);
4250
+ runtime.stats.pending--;
4251
+ try {
4252
+ pending.resolve(checkoutConnection(runtime, pooled));
4253
+ return;
4254
+ } catch (error) {
4255
+ pending.reject(error instanceof Error ? error : new Error(String(error)));
4256
+ pending = runtime.pending.shift();
4257
+ }
4258
+ }
4285
4259
  }
4286
4260
  async function createConnection(runtime) {
4287
4261
  const connection = await runtime.options.factory();
@@ -4297,22 +4271,30 @@ async function createConnection(runtime) {
4297
4271
  runtime.stats.available++;
4298
4272
  return connection;
4299
4273
  }
4274
+ function finalizeDestroyedConnection(runtime, pooled) {
4275
+ runtime.stats.destroyed++;
4276
+ runtime.stats.size--;
4277
+ if (pooled.inUse) {
4278
+ runtime.stats.acquired--;
4279
+ } else {
4280
+ runtime.stats.available--;
4281
+ }
4282
+ }
4300
4283
  async function destroyConnection(runtime, pooled) {
4301
4284
  const index = runtime.connections.indexOf(pooled);
4302
4285
  if (index !== -1) {
4303
4286
  runtime.connections.splice(index, 1);
4304
4287
  }
4305
4288
  if (runtime.options.destroyer) {
4306
- await runtime.options.destroyer(pooled.connection);
4289
+ try {
4290
+ await runtime.options.destroyer(pooled.connection);
4291
+ } catch (error) {
4292
+ finalizeDestroyedConnection(runtime, pooled);
4293
+ throw error;
4294
+ }
4307
4295
  }
4308
4296
  runtime.options.onDestroy?.(pooled.connection);
4309
- runtime.stats.destroyed++;
4310
- runtime.stats.size--;
4311
- if (pooled.inUse) {
4312
- runtime.stats.acquired--;
4313
- } else {
4314
- runtime.stats.available--;
4315
- }
4297
+ finalizeDestroyedConnection(runtime, pooled);
4316
4298
  }
4317
4299
  function getPoolConfig(runtime) {
4318
4300
  return runtime.options.pool || {};
@@ -4331,12 +4313,7 @@ async function acquireConnection(runtime) {
4331
4313
  }
4332
4314
  const available = runtime.connections.find((connection) => !connection.inUse);
4333
4315
  if (available) {
4334
- available.inUse = true;
4335
- available.lastUsedAt = Date.now();
4336
- runtime.stats.available--;
4337
- runtime.stats.acquired++;
4338
- runtime.options.onAcquire?.(available.connection);
4339
- return available.connection;
4316
+ return checkoutConnection(runtime, available);
4340
4317
  }
4341
4318
  const poolConfig = getPoolConfig(runtime);
4342
4319
  const max = poolConfig.max || 10;
@@ -4352,12 +4329,7 @@ async function acquireConnection(runtime) {
4352
4329
  await destroyConnection(runtime, pooled);
4353
4330
  throw new Error("Pool is draining");
4354
4331
  }
4355
- pooled.inUse = true;
4356
- pooled.lastUsedAt = Date.now();
4357
- runtime.stats.available--;
4358
- runtime.stats.acquired++;
4359
- runtime.options.onAcquire?.(connection);
4360
- return connection;
4332
+ return checkoutConnection(runtime, pooled);
4361
4333
  } finally {
4362
4334
  runtime.creating--;
4363
4335
  }
@@ -4389,18 +4361,7 @@ async function releaseConnection(runtime, connection) {
4389
4361
  runtime.stats.available++;
4390
4362
  runtime.stats.acquired--;
4391
4363
  runtime.options.onRelease?.(connection);
4392
- const pending = runtime.pending.shift();
4393
- if (!pending) {
4394
- return;
4395
- }
4396
- clearTimeout(pending.timeout);
4397
- runtime.stats.pending--;
4398
- pooled.inUse = true;
4399
- pooled.lastUsedAt = Date.now();
4400
- runtime.stats.available--;
4401
- runtime.stats.acquired++;
4402
- runtime.options.onAcquire?.(connection);
4403
- pending.resolve(connection);
4364
+ assignConnectionToPendingAcquire(runtime, connection);
4404
4365
  }
4405
4366
 
4406
4367
  // src/resources/pool-eviction.ts
package/dist/index.js CHANGED
@@ -141,81 +141,64 @@ var MissingDescriptionError = class extends Error {
141
141
  this.name = "MissingDescriptionError";
142
142
  }
143
143
  };
144
- function validateSchemaDescriptions(schema, fieldPath = []) {
144
+ function* findMissingDescriptions(schema, fieldPath = []) {
145
145
  const def = schema._def;
146
146
  const typeName = def.typeName;
147
147
  if (schema instanceof z2.ZodObject) {
148
- const shape = schema.shape;
149
- Object.entries(shape).forEach(([key, fieldSchema]) => {
150
- validateSchemaDescriptions(fieldSchema, [...fieldPath, key]);
151
- });
152
- return;
153
- }
154
- if (schema instanceof z2.ZodArray) {
155
- validateSchemaDescriptions(def.type, [...fieldPath, "[]"]);
156
- return;
157
- }
158
- if (schema instanceof z2.ZodOptional) {
159
- const wrapperDescription = def.description;
160
- const innerDescription = def.innerType._def.description;
161
- if (fieldPath.length > 0 && !wrapperDescription && !innerDescription) {
162
- throw new MissingDescriptionError(fieldPath, typeName);
163
- }
164
- if (!wrapperDescription) {
165
- validateSchemaDescriptions(def.innerType, fieldPath);
148
+ for (const [key, fieldSchema] of Object.entries(schema.shape)) {
149
+ yield* findMissingDescriptions(fieldSchema, [...fieldPath, key]);
166
150
  }
167
151
  return;
168
152
  }
169
- if (schema instanceof z2.ZodNullable) {
170
- const wrapperDescription = def.description;
171
- const innerDescription = def.innerType._def.description;
172
- if (fieldPath.length > 0 && !wrapperDescription && !innerDescription) {
173
- throw new MissingDescriptionError(fieldPath, typeName);
174
- }
175
- if (!wrapperDescription) {
176
- validateSchemaDescriptions(def.innerType, fieldPath);
177
- }
153
+ if (schema instanceof z2.ZodArray) {
154
+ yield* findMissingDescriptions(def.type, [...fieldPath, "[]"]);
178
155
  return;
179
156
  }
180
- if (schema instanceof z2.ZodDefault) {
157
+ if (schema instanceof z2.ZodOptional || schema instanceof z2.ZodNullable || schema instanceof z2.ZodDefault) {
181
158
  const wrapperDescription = def.description;
182
159
  const innerDescription = def.innerType._def.description;
183
160
  if (fieldPath.length > 0 && !wrapperDescription && !innerDescription) {
184
- throw new MissingDescriptionError(fieldPath, typeName);
161
+ yield { fieldPath, fieldType: typeName };
185
162
  }
186
163
  if (!wrapperDescription) {
187
- validateSchemaDescriptions(def.innerType, fieldPath);
164
+ yield* findMissingDescriptions(def.innerType, fieldPath);
188
165
  }
189
166
  return;
190
167
  }
191
168
  if (schema instanceof z2.ZodUnion) {
192
- def.options.forEach((option, index) => {
193
- validateSchemaDescriptions(option, [...fieldPath, `option${index}`]);
194
- });
169
+ for (const [index, option] of def.options.entries()) {
170
+ yield* findMissingDescriptions(option, [...fieldPath, `option${index}`]);
171
+ }
195
172
  return;
196
173
  }
197
174
  if (schema instanceof z2.ZodIntersection) {
198
- validateSchemaDescriptions(def.left, fieldPath);
199
- validateSchemaDescriptions(def.right, fieldPath);
175
+ yield* findMissingDescriptions(def.left, fieldPath);
176
+ yield* findMissingDescriptions(def.right, fieldPath);
200
177
  return;
201
178
  }
202
179
  if (schema instanceof z2.ZodRecord) {
203
- validateSchemaDescriptions(def.valueType, [...fieldPath, "[key]"]);
180
+ yield* findMissingDescriptions(def.valueType, [...fieldPath, "[key]"]);
204
181
  return;
205
182
  }
206
183
  if (schema instanceof z2.ZodTuple) {
207
- def.items.forEach((item, index) => {
208
- validateSchemaDescriptions(item, [...fieldPath, `[${index}]`]);
209
- });
184
+ for (const [index, item] of def.items.entries()) {
185
+ yield* findMissingDescriptions(item, [...fieldPath, `[${index}]`]);
186
+ }
210
187
  return;
211
188
  }
212
189
  if (fieldPath.length > 0) {
213
190
  const description = def.description;
214
191
  if (!description || description.trim() === "") {
215
- throw new MissingDescriptionError(fieldPath, typeName);
192
+ yield { fieldPath, fieldType: typeName };
216
193
  }
217
194
  }
218
195
  }
196
+ function validateSchemaDescriptions(schema, fieldPath = []) {
197
+ const firstFinding = findMissingDescriptions(schema, fieldPath).next();
198
+ if (!firstFinding.done) {
199
+ throw new MissingDescriptionError(firstFinding.value.fieldPath, firstFinding.value.fieldType);
200
+ }
201
+ }
219
202
  function safeValidateSchemaDescriptions(schema) {
220
203
  try {
221
204
  validateSchemaDescriptions(schema);
@@ -229,39 +212,14 @@ function safeValidateSchemaDescriptions(schema) {
229
212
  }
230
213
  function getMissingDescriptions(schema) {
231
214
  const missing = [];
232
- function check(s, path = []) {
233
- const def = s._def;
234
- const typeName = def.typeName;
235
- if (s instanceof z2.ZodObject) {
236
- const shape = s.shape;
237
- Object.entries(shape).forEach(([key, fieldSchema]) => {
238
- check(fieldSchema, [...path, key]);
239
- });
240
- return;
241
- }
242
- if (s instanceof z2.ZodOptional || s instanceof z2.ZodNullable || s instanceof z2.ZodDefault) {
243
- const wrapperDescription = def.description;
244
- const innerDescription = def.innerType._def.description;
245
- if (path.length > 0 && !wrapperDescription && !innerDescription) {
246
- missing.push(path.join("."));
247
- }
248
- if (!wrapperDescription) {
249
- check(def.innerType, path);
250
- }
251
- return;
252
- }
253
- if (s instanceof z2.ZodArray) {
254
- check(def.type, [...path, "[]"]);
255
- return;
256
- }
257
- if (path.length > 0) {
258
- const description = def.description;
259
- if (!description || description.trim() === "") {
260
- missing.push(path.join("."));
261
- }
215
+ const seen = /* @__PURE__ */ new Set();
216
+ for (const finding of findMissingDescriptions(schema)) {
217
+ const path = finding.fieldPath.join(".");
218
+ if (!seen.has(path)) {
219
+ seen.add(path);
220
+ missing.push(path);
262
221
  }
263
222
  }
264
- check(schema);
265
223
  return missing;
266
224
  }
267
225
 
@@ -4068,6 +4026,23 @@ function createInitialPoolStats() {
4068
4026
  healthChecksFailed: 0
4069
4027
  };
4070
4028
  }
4029
+ function checkoutConnection(runtime, pooled) {
4030
+ const previousLastUsedAt = pooled.lastUsedAt;
4031
+ pooled.inUse = true;
4032
+ pooled.lastUsedAt = Date.now();
4033
+ runtime.stats.available--;
4034
+ runtime.stats.acquired++;
4035
+ try {
4036
+ runtime.options.onAcquire?.(pooled.connection);
4037
+ return pooled.connection;
4038
+ } catch (error) {
4039
+ pooled.inUse = false;
4040
+ pooled.lastUsedAt = previousLastUsedAt;
4041
+ runtime.stats.available++;
4042
+ runtime.stats.acquired--;
4043
+ throw error;
4044
+ }
4045
+ }
4071
4046
  async function initializeConnections(runtime, count) {
4072
4047
  runtime.creating += count;
4073
4048
  const promises = Array.from({ length: count }, async () => {
@@ -4089,23 +4064,22 @@ async function initializeConnections(runtime, count) {
4089
4064
  await Promise.all(promises);
4090
4065
  }
4091
4066
  function assignConnectionToPendingAcquire(runtime, connection) {
4092
- const pending = runtime.pending.shift();
4093
- if (!pending) {
4094
- return;
4095
- }
4096
4067
  const pooled = runtime.connections.find((item) => item.connection === connection);
4097
4068
  if (!pooled) {
4098
- runtime.pending.unshift(pending);
4099
4069
  return;
4100
4070
  }
4101
- clearTimeout(pending.timeout);
4102
- runtime.stats.pending--;
4103
- pooled.inUse = true;
4104
- pooled.lastUsedAt = Date.now();
4105
- runtime.stats.available--;
4106
- runtime.stats.acquired++;
4107
- runtime.options.onAcquire?.(connection);
4108
- pending.resolve(connection);
4071
+ let pending = runtime.pending.shift();
4072
+ while (pending) {
4073
+ clearTimeout(pending.timeout);
4074
+ runtime.stats.pending--;
4075
+ try {
4076
+ pending.resolve(checkoutConnection(runtime, pooled));
4077
+ return;
4078
+ } catch (error) {
4079
+ pending.reject(error instanceof Error ? error : new Error(String(error)));
4080
+ pending = runtime.pending.shift();
4081
+ }
4082
+ }
4109
4083
  }
4110
4084
  async function createConnection(runtime) {
4111
4085
  const connection = await runtime.options.factory();
@@ -4121,22 +4095,30 @@ async function createConnection(runtime) {
4121
4095
  runtime.stats.available++;
4122
4096
  return connection;
4123
4097
  }
4098
+ function finalizeDestroyedConnection(runtime, pooled) {
4099
+ runtime.stats.destroyed++;
4100
+ runtime.stats.size--;
4101
+ if (pooled.inUse) {
4102
+ runtime.stats.acquired--;
4103
+ } else {
4104
+ runtime.stats.available--;
4105
+ }
4106
+ }
4124
4107
  async function destroyConnection(runtime, pooled) {
4125
4108
  const index = runtime.connections.indexOf(pooled);
4126
4109
  if (index !== -1) {
4127
4110
  runtime.connections.splice(index, 1);
4128
4111
  }
4129
4112
  if (runtime.options.destroyer) {
4130
- await runtime.options.destroyer(pooled.connection);
4113
+ try {
4114
+ await runtime.options.destroyer(pooled.connection);
4115
+ } catch (error) {
4116
+ finalizeDestroyedConnection(runtime, pooled);
4117
+ throw error;
4118
+ }
4131
4119
  }
4132
4120
  runtime.options.onDestroy?.(pooled.connection);
4133
- runtime.stats.destroyed++;
4134
- runtime.stats.size--;
4135
- if (pooled.inUse) {
4136
- runtime.stats.acquired--;
4137
- } else {
4138
- runtime.stats.available--;
4139
- }
4121
+ finalizeDestroyedConnection(runtime, pooled);
4140
4122
  }
4141
4123
  function getPoolConfig(runtime) {
4142
4124
  return runtime.options.pool || {};
@@ -4155,12 +4137,7 @@ async function acquireConnection(runtime) {
4155
4137
  }
4156
4138
  const available = runtime.connections.find((connection) => !connection.inUse);
4157
4139
  if (available) {
4158
- available.inUse = true;
4159
- available.lastUsedAt = Date.now();
4160
- runtime.stats.available--;
4161
- runtime.stats.acquired++;
4162
- runtime.options.onAcquire?.(available.connection);
4163
- return available.connection;
4140
+ return checkoutConnection(runtime, available);
4164
4141
  }
4165
4142
  const poolConfig = getPoolConfig(runtime);
4166
4143
  const max = poolConfig.max || 10;
@@ -4176,12 +4153,7 @@ async function acquireConnection(runtime) {
4176
4153
  await destroyConnection(runtime, pooled);
4177
4154
  throw new Error("Pool is draining");
4178
4155
  }
4179
- pooled.inUse = true;
4180
- pooled.lastUsedAt = Date.now();
4181
- runtime.stats.available--;
4182
- runtime.stats.acquired++;
4183
- runtime.options.onAcquire?.(connection);
4184
- return connection;
4156
+ return checkoutConnection(runtime, pooled);
4185
4157
  } finally {
4186
4158
  runtime.creating--;
4187
4159
  }
@@ -4213,18 +4185,7 @@ async function releaseConnection(runtime, connection) {
4213
4185
  runtime.stats.available++;
4214
4186
  runtime.stats.acquired--;
4215
4187
  runtime.options.onRelease?.(connection);
4216
- const pending = runtime.pending.shift();
4217
- if (!pending) {
4218
- return;
4219
- }
4220
- clearTimeout(pending.timeout);
4221
- runtime.stats.pending--;
4222
- pooled.inUse = true;
4223
- pooled.lastUsedAt = Date.now();
4224
- runtime.stats.available--;
4225
- runtime.stats.acquired++;
4226
- runtime.options.onAcquire?.(connection);
4227
- pending.resolve(connection);
4188
+ assignConnectionToPendingAcquire(runtime, connection);
4228
4189
  }
4229
4190
 
4230
4191
  // src/resources/pool-eviction.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/core",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Production-ready TypeScript agent framework built on LangGraph with orchestration, middleware, and typed abstractions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",