@agent-assistant/core 0.2.19 → 0.2.21

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 (2) hide show
  1. package/dist/core.js +30 -13
  2. package/package.json +1 -1
package/dist/core.js CHANGED
@@ -1,6 +1,6 @@
1
- const DEFAULT_HANDLER_TIMEOUT_MS = 30_000;
1
+ const DEFAULT_HANDLER_TIMEOUT_MS = 5 * 60_000;
2
2
  const DEFAULT_MAX_CONCURRENT_HANDLERS = 10;
3
- const STOP_DRAIN_TIMEOUT_MS = 30_000;
3
+ const DRAIN_MARGIN_MS = 5_000;
4
4
  export class AssistantDefinitionError extends Error {
5
5
  constructor(message) {
6
6
  super(message);
@@ -206,14 +206,23 @@ export function createAssistant(definition, adapters) {
206
206
  return;
207
207
  }
208
208
  drainWaiter ??= createDeferred();
209
- await Promise.race([
210
- drainWaiter.promise,
211
- new Promise((_, reject) => {
212
- setTimeout(() => {
213
- reject(new Error(`Timed out waiting ${STOP_DRAIN_TIMEOUT_MS}ms for in-flight handlers to drain`));
214
- }, STOP_DRAIN_TIMEOUT_MS);
215
- }),
216
- ]);
209
+ const drainTimeoutMs = constraints.handlerTimeoutMs + DRAIN_MARGIN_MS;
210
+ let timeoutHandle;
211
+ try {
212
+ await Promise.race([
213
+ drainWaiter.promise,
214
+ new Promise((_, reject) => {
215
+ timeoutHandle = setTimeout(() => {
216
+ reject(new Error(`Timed out waiting ${drainTimeoutMs}ms for in-flight handlers to drain`));
217
+ }, drainTimeoutMs);
218
+ }),
219
+ ]);
220
+ }
221
+ finally {
222
+ if (timeoutHandle) {
223
+ clearTimeout(timeoutHandle);
224
+ }
225
+ }
217
226
  }
218
227
  function runNext() {
219
228
  while (lifecycleState === 'started' &&
@@ -227,6 +236,14 @@ export function createAssistant(definition, adapters) {
227
236
  void executeDispatch(nextDispatch);
228
237
  }
229
238
  }
239
+ function reportError(error, message) {
240
+ const userHandler = frozenDefinition.hooks?.onError;
241
+ if (typeof userHandler === 'function') {
242
+ userHandler(error, message);
243
+ return;
244
+ }
245
+ console.error(`[${frozenDefinition.id ?? 'agent'}] unhandled capability handler error (capability=${message.capability}, id=${message.id}):`, error);
246
+ }
230
247
  async function executeDispatch(dispatchJob) {
231
248
  const { message, resolve, reject } = dispatchJob;
232
249
  try {
@@ -237,7 +254,7 @@ export function createAssistant(definition, adapters) {
237
254
  }
238
255
  const handler = capabilityMap.get(message.capability);
239
256
  if (!handler) {
240
- frozenDefinition.hooks?.onError?.(new Error(`No capability registered for '${message.capability}'`), message);
257
+ reportError(new Error(`No capability registered for '${message.capability}'`), message);
241
258
  resolve();
242
259
  return;
243
260
  }
@@ -253,13 +270,13 @@ export function createAssistant(definition, adapters) {
253
270
  await withTimeout(handler, message, context, constraints.handlerTimeoutMs);
254
271
  }
255
272
  catch (error) {
256
- frozenDefinition.hooks?.onError?.(error instanceof Error ? error : new Error(String(error)), message);
273
+ reportError(error instanceof Error ? error : new Error(String(error)), message);
257
274
  }
258
275
  resolve();
259
276
  }
260
277
  catch (error) {
261
278
  const wrappedError = error instanceof Error ? error : new Error(String(error));
262
- frozenDefinition.hooks?.onError?.(wrappedError, message);
279
+ reportError(wrappedError, message);
263
280
  reject(wrappedError);
264
281
  }
265
282
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-assistant/core",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "Assistant definition, lifecycle, and runtime composition for Agent Assistant SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",