@agentforge/core 0.18.0 → 0.18.1
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/dist/index.cjs +48 -45
- package/dist/index.js +48 -45
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4244,6 +4244,23 @@ function createInitialPoolStats() {
|
|
|
4244
4244
|
healthChecksFailed: 0
|
|
4245
4245
|
};
|
|
4246
4246
|
}
|
|
4247
|
+
function checkoutConnection(runtime, pooled) {
|
|
4248
|
+
const previousLastUsedAt = pooled.lastUsedAt;
|
|
4249
|
+
pooled.inUse = true;
|
|
4250
|
+
pooled.lastUsedAt = Date.now();
|
|
4251
|
+
runtime.stats.available--;
|
|
4252
|
+
runtime.stats.acquired++;
|
|
4253
|
+
try {
|
|
4254
|
+
runtime.options.onAcquire?.(pooled.connection);
|
|
4255
|
+
return pooled.connection;
|
|
4256
|
+
} catch (error) {
|
|
4257
|
+
pooled.inUse = false;
|
|
4258
|
+
pooled.lastUsedAt = previousLastUsedAt;
|
|
4259
|
+
runtime.stats.available++;
|
|
4260
|
+
runtime.stats.acquired--;
|
|
4261
|
+
throw error;
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4247
4264
|
async function initializeConnections(runtime, count) {
|
|
4248
4265
|
runtime.creating += count;
|
|
4249
4266
|
const promises = Array.from({ length: count }, async () => {
|
|
@@ -4265,23 +4282,22 @@ async function initializeConnections(runtime, count) {
|
|
|
4265
4282
|
await Promise.all(promises);
|
|
4266
4283
|
}
|
|
4267
4284
|
function assignConnectionToPendingAcquire(runtime, connection) {
|
|
4268
|
-
const pending = runtime.pending.shift();
|
|
4269
|
-
if (!pending) {
|
|
4270
|
-
return;
|
|
4271
|
-
}
|
|
4272
4285
|
const pooled = runtime.connections.find((item) => item.connection === connection);
|
|
4273
4286
|
if (!pooled) {
|
|
4274
|
-
runtime.pending.unshift(pending);
|
|
4275
4287
|
return;
|
|
4276
4288
|
}
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4289
|
+
let pending = runtime.pending.shift();
|
|
4290
|
+
while (pending) {
|
|
4291
|
+
clearTimeout(pending.timeout);
|
|
4292
|
+
runtime.stats.pending--;
|
|
4293
|
+
try {
|
|
4294
|
+
pending.resolve(checkoutConnection(runtime, pooled));
|
|
4295
|
+
return;
|
|
4296
|
+
} catch (error) {
|
|
4297
|
+
pending.reject(error instanceof Error ? error : new Error(String(error)));
|
|
4298
|
+
pending = runtime.pending.shift();
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4285
4301
|
}
|
|
4286
4302
|
async function createConnection(runtime) {
|
|
4287
4303
|
const connection = await runtime.options.factory();
|
|
@@ -4297,22 +4313,30 @@ async function createConnection(runtime) {
|
|
|
4297
4313
|
runtime.stats.available++;
|
|
4298
4314
|
return connection;
|
|
4299
4315
|
}
|
|
4316
|
+
function finalizeDestroyedConnection(runtime, pooled) {
|
|
4317
|
+
runtime.stats.destroyed++;
|
|
4318
|
+
runtime.stats.size--;
|
|
4319
|
+
if (pooled.inUse) {
|
|
4320
|
+
runtime.stats.acquired--;
|
|
4321
|
+
} else {
|
|
4322
|
+
runtime.stats.available--;
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4300
4325
|
async function destroyConnection(runtime, pooled) {
|
|
4301
4326
|
const index = runtime.connections.indexOf(pooled);
|
|
4302
4327
|
if (index !== -1) {
|
|
4303
4328
|
runtime.connections.splice(index, 1);
|
|
4304
4329
|
}
|
|
4305
4330
|
if (runtime.options.destroyer) {
|
|
4306
|
-
|
|
4331
|
+
try {
|
|
4332
|
+
await runtime.options.destroyer(pooled.connection);
|
|
4333
|
+
} catch (error) {
|
|
4334
|
+
finalizeDestroyedConnection(runtime, pooled);
|
|
4335
|
+
throw error;
|
|
4336
|
+
}
|
|
4307
4337
|
}
|
|
4308
4338
|
runtime.options.onDestroy?.(pooled.connection);
|
|
4309
|
-
runtime
|
|
4310
|
-
runtime.stats.size--;
|
|
4311
|
-
if (pooled.inUse) {
|
|
4312
|
-
runtime.stats.acquired--;
|
|
4313
|
-
} else {
|
|
4314
|
-
runtime.stats.available--;
|
|
4315
|
-
}
|
|
4339
|
+
finalizeDestroyedConnection(runtime, pooled);
|
|
4316
4340
|
}
|
|
4317
4341
|
function getPoolConfig(runtime) {
|
|
4318
4342
|
return runtime.options.pool || {};
|
|
@@ -4331,12 +4355,7 @@ async function acquireConnection(runtime) {
|
|
|
4331
4355
|
}
|
|
4332
4356
|
const available = runtime.connections.find((connection) => !connection.inUse);
|
|
4333
4357
|
if (available) {
|
|
4334
|
-
|
|
4335
|
-
available.lastUsedAt = Date.now();
|
|
4336
|
-
runtime.stats.available--;
|
|
4337
|
-
runtime.stats.acquired++;
|
|
4338
|
-
runtime.options.onAcquire?.(available.connection);
|
|
4339
|
-
return available.connection;
|
|
4358
|
+
return checkoutConnection(runtime, available);
|
|
4340
4359
|
}
|
|
4341
4360
|
const poolConfig = getPoolConfig(runtime);
|
|
4342
4361
|
const max = poolConfig.max || 10;
|
|
@@ -4352,12 +4371,7 @@ async function acquireConnection(runtime) {
|
|
|
4352
4371
|
await destroyConnection(runtime, pooled);
|
|
4353
4372
|
throw new Error("Pool is draining");
|
|
4354
4373
|
}
|
|
4355
|
-
|
|
4356
|
-
pooled.lastUsedAt = Date.now();
|
|
4357
|
-
runtime.stats.available--;
|
|
4358
|
-
runtime.stats.acquired++;
|
|
4359
|
-
runtime.options.onAcquire?.(connection);
|
|
4360
|
-
return connection;
|
|
4374
|
+
return checkoutConnection(runtime, pooled);
|
|
4361
4375
|
} finally {
|
|
4362
4376
|
runtime.creating--;
|
|
4363
4377
|
}
|
|
@@ -4389,18 +4403,7 @@ async function releaseConnection(runtime, connection) {
|
|
|
4389
4403
|
runtime.stats.available++;
|
|
4390
4404
|
runtime.stats.acquired--;
|
|
4391
4405
|
runtime.options.onRelease?.(connection);
|
|
4392
|
-
|
|
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);
|
|
4406
|
+
assignConnectionToPendingAcquire(runtime, connection);
|
|
4404
4407
|
}
|
|
4405
4408
|
|
|
4406
4409
|
// src/resources/pool-eviction.ts
|
package/dist/index.js
CHANGED
|
@@ -4068,6 +4068,23 @@ function createInitialPoolStats() {
|
|
|
4068
4068
|
healthChecksFailed: 0
|
|
4069
4069
|
};
|
|
4070
4070
|
}
|
|
4071
|
+
function checkoutConnection(runtime, pooled) {
|
|
4072
|
+
const previousLastUsedAt = pooled.lastUsedAt;
|
|
4073
|
+
pooled.inUse = true;
|
|
4074
|
+
pooled.lastUsedAt = Date.now();
|
|
4075
|
+
runtime.stats.available--;
|
|
4076
|
+
runtime.stats.acquired++;
|
|
4077
|
+
try {
|
|
4078
|
+
runtime.options.onAcquire?.(pooled.connection);
|
|
4079
|
+
return pooled.connection;
|
|
4080
|
+
} catch (error) {
|
|
4081
|
+
pooled.inUse = false;
|
|
4082
|
+
pooled.lastUsedAt = previousLastUsedAt;
|
|
4083
|
+
runtime.stats.available++;
|
|
4084
|
+
runtime.stats.acquired--;
|
|
4085
|
+
throw error;
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4071
4088
|
async function initializeConnections(runtime, count) {
|
|
4072
4089
|
runtime.creating += count;
|
|
4073
4090
|
const promises = Array.from({ length: count }, async () => {
|
|
@@ -4089,23 +4106,22 @@ async function initializeConnections(runtime, count) {
|
|
|
4089
4106
|
await Promise.all(promises);
|
|
4090
4107
|
}
|
|
4091
4108
|
function assignConnectionToPendingAcquire(runtime, connection) {
|
|
4092
|
-
const pending = runtime.pending.shift();
|
|
4093
|
-
if (!pending) {
|
|
4094
|
-
return;
|
|
4095
|
-
}
|
|
4096
4109
|
const pooled = runtime.connections.find((item) => item.connection === connection);
|
|
4097
4110
|
if (!pooled) {
|
|
4098
|
-
runtime.pending.unshift(pending);
|
|
4099
4111
|
return;
|
|
4100
4112
|
}
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4113
|
+
let pending = runtime.pending.shift();
|
|
4114
|
+
while (pending) {
|
|
4115
|
+
clearTimeout(pending.timeout);
|
|
4116
|
+
runtime.stats.pending--;
|
|
4117
|
+
try {
|
|
4118
|
+
pending.resolve(checkoutConnection(runtime, pooled));
|
|
4119
|
+
return;
|
|
4120
|
+
} catch (error) {
|
|
4121
|
+
pending.reject(error instanceof Error ? error : new Error(String(error)));
|
|
4122
|
+
pending = runtime.pending.shift();
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4109
4125
|
}
|
|
4110
4126
|
async function createConnection(runtime) {
|
|
4111
4127
|
const connection = await runtime.options.factory();
|
|
@@ -4121,22 +4137,30 @@ async function createConnection(runtime) {
|
|
|
4121
4137
|
runtime.stats.available++;
|
|
4122
4138
|
return connection;
|
|
4123
4139
|
}
|
|
4140
|
+
function finalizeDestroyedConnection(runtime, pooled) {
|
|
4141
|
+
runtime.stats.destroyed++;
|
|
4142
|
+
runtime.stats.size--;
|
|
4143
|
+
if (pooled.inUse) {
|
|
4144
|
+
runtime.stats.acquired--;
|
|
4145
|
+
} else {
|
|
4146
|
+
runtime.stats.available--;
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4124
4149
|
async function destroyConnection(runtime, pooled) {
|
|
4125
4150
|
const index = runtime.connections.indexOf(pooled);
|
|
4126
4151
|
if (index !== -1) {
|
|
4127
4152
|
runtime.connections.splice(index, 1);
|
|
4128
4153
|
}
|
|
4129
4154
|
if (runtime.options.destroyer) {
|
|
4130
|
-
|
|
4155
|
+
try {
|
|
4156
|
+
await runtime.options.destroyer(pooled.connection);
|
|
4157
|
+
} catch (error) {
|
|
4158
|
+
finalizeDestroyedConnection(runtime, pooled);
|
|
4159
|
+
throw error;
|
|
4160
|
+
}
|
|
4131
4161
|
}
|
|
4132
4162
|
runtime.options.onDestroy?.(pooled.connection);
|
|
4133
|
-
runtime
|
|
4134
|
-
runtime.stats.size--;
|
|
4135
|
-
if (pooled.inUse) {
|
|
4136
|
-
runtime.stats.acquired--;
|
|
4137
|
-
} else {
|
|
4138
|
-
runtime.stats.available--;
|
|
4139
|
-
}
|
|
4163
|
+
finalizeDestroyedConnection(runtime, pooled);
|
|
4140
4164
|
}
|
|
4141
4165
|
function getPoolConfig(runtime) {
|
|
4142
4166
|
return runtime.options.pool || {};
|
|
@@ -4155,12 +4179,7 @@ async function acquireConnection(runtime) {
|
|
|
4155
4179
|
}
|
|
4156
4180
|
const available = runtime.connections.find((connection) => !connection.inUse);
|
|
4157
4181
|
if (available) {
|
|
4158
|
-
|
|
4159
|
-
available.lastUsedAt = Date.now();
|
|
4160
|
-
runtime.stats.available--;
|
|
4161
|
-
runtime.stats.acquired++;
|
|
4162
|
-
runtime.options.onAcquire?.(available.connection);
|
|
4163
|
-
return available.connection;
|
|
4182
|
+
return checkoutConnection(runtime, available);
|
|
4164
4183
|
}
|
|
4165
4184
|
const poolConfig = getPoolConfig(runtime);
|
|
4166
4185
|
const max = poolConfig.max || 10;
|
|
@@ -4176,12 +4195,7 @@ async function acquireConnection(runtime) {
|
|
|
4176
4195
|
await destroyConnection(runtime, pooled);
|
|
4177
4196
|
throw new Error("Pool is draining");
|
|
4178
4197
|
}
|
|
4179
|
-
|
|
4180
|
-
pooled.lastUsedAt = Date.now();
|
|
4181
|
-
runtime.stats.available--;
|
|
4182
|
-
runtime.stats.acquired++;
|
|
4183
|
-
runtime.options.onAcquire?.(connection);
|
|
4184
|
-
return connection;
|
|
4198
|
+
return checkoutConnection(runtime, pooled);
|
|
4185
4199
|
} finally {
|
|
4186
4200
|
runtime.creating--;
|
|
4187
4201
|
}
|
|
@@ -4213,18 +4227,7 @@ async function releaseConnection(runtime, connection) {
|
|
|
4213
4227
|
runtime.stats.available++;
|
|
4214
4228
|
runtime.stats.acquired--;
|
|
4215
4229
|
runtime.options.onRelease?.(connection);
|
|
4216
|
-
|
|
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);
|
|
4230
|
+
assignConnectionToPendingAcquire(runtime, connection);
|
|
4228
4231
|
}
|
|
4229
4232
|
|
|
4230
4233
|
// src/resources/pool-eviction.ts
|
package/package.json
CHANGED