@zenera/neo 1.3.48 → 1.3.50

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/events.d.ts CHANGED
@@ -98,7 +98,8 @@ export type CheckpointEvent = EventBase & ({
98
98
  /**
99
99
  * What the runner says while a provider keeps failing a model call it is
100
100
  * about to make again (see `RunnerOptions.modelRetry`). No state, so like a
101
- * delta it is safe to drop.
101
+ * delta it is safe to drop — except `model_output_discarded`, which a consumer
102
+ * that shows deltas must act on.
102
103
  */
103
104
  export type RetryNotice = {
104
105
  type: 'model_retry';
@@ -109,9 +110,22 @@ export type RetryNotice = {
109
110
  /** when the next attempt goes, ISO */
110
111
  retryAt: string;
111
112
  model: string;
113
+ /** the call's stream broke mid-answer (its output was discarded); it starts over */
114
+ restart?: boolean;
112
115
  } | {
113
116
  type: 'model_retry_recovered';
114
117
  attempts: number;
118
+ }
119
+ /**
120
+ * The stream of the current model call (since this run's or branch's last
121
+ * `before_llm_call`) broke after deltas went out, and they are not the
122
+ * answer: the call is made again (a `model_retry` follows) or the run
123
+ * stalls. Whoever drew those deltas drops them; none of it is in the state.
124
+ */
125
+ | {
126
+ type: 'model_output_discarded';
127
+ error: string;
128
+ model: string;
115
129
  };
116
130
  export type RetryEvent = EventBase & RetryNotice;
117
131
  export type AgentEvent = StreamEvent | CheckpointEvent | RetryEvent;
package/dist/failure.d.ts CHANGED
@@ -37,8 +37,8 @@ export interface Attempted {
37
37
  elapsedMs: number;
38
38
  /**
39
39
  * Chunks delivered before the stream broke. Any at all means the answer had
40
- * already started, and a stream that has emitted cannot be replayed: the
41
- * deltas are on screen.
40
+ * already started, and a stream that has emitted cannot be reopened here:
41
+ * the deltas are on screen, and only the runner can take them back.
42
42
  */
43
43
  chunks?: number;
44
44
  }
package/dist/failure.js CHANGED
@@ -53,10 +53,10 @@ function trailer(tried) {
53
53
  said.push(`${(tried.elapsedMs / 1000).toFixed(1)}s`);
54
54
  }
55
55
  if (tried.chunks) {
56
- // Says why it was not retried, which is the first thing asked of a
57
- // connection that dropped.
56
+ // Says why the stream was not reopened, which is the first thing asked
57
+ // of a connection that dropped.
58
58
  const many = tried.chunks === 1 ? '' : 's';
59
- said.push(`${tried.chunks} chunk${many} in, too late to retry`);
59
+ said.push(`${tried.chunks} chunk${many} in`);
60
60
  }
61
61
  return said.length ? ` [after ${said.join(', ')}]` : '';
62
62
  }
@@ -107,17 +107,20 @@ export async function* reading(site, source, reopen) {
107
107
  return;
108
108
  }
109
109
  catch (err) {
110
+ const wrapped = failed(site, err, {
111
+ attempts: attempt,
112
+ elapsedMs: Date.now() - started,
113
+ chunks,
114
+ });
115
+ // Classified as wrapped: inside a stream the status is often only
116
+ // the vendor's symbol, which the wrapper turns into one.
110
117
  const again = reopen &&
111
118
  chunks === 0 &&
112
119
  attempt <= REOPEN &&
113
120
  !isAbort(err) &&
114
- classify(err) !== 'fatal';
121
+ classify(wrapped) !== 'fatal';
115
122
  if (!again) {
116
- throw failed(site, err, {
117
- attempts: attempt,
118
- elapsedMs: Date.now() - started,
119
- chunks,
120
- });
123
+ throw wrapped;
121
124
  }
122
125
  await sleep(REOPEN_BACKOFF_MS * attempt);
123
126
  stream = await reopen();
@@ -228,6 +231,9 @@ const STATUS = new Map([
228
231
  ['resource_exhausted', 429],
229
232
  ['api_error', 500],
230
233
  ['internal', 500],
234
+ // Bifrost's word for an upstream connection that failed or ended
235
+ // mid-stream; inside a stream it arrives with no status of its own.
236
+ ['provider_connection_failed', 502],
231
237
  ['unavailable', 503],
232
238
  ['overloaded_error', 529],
233
239
  ]);
package/dist/runner.js CHANGED
@@ -273,15 +273,29 @@ export class AgentRunner {
273
273
  res = await call;
274
274
  }
275
275
  catch (err) {
276
- // Nothing of the answer is on screen yet, and the
277
- // provider may be back soon: the same call again,
278
- // after telling whoever watches.
279
- const retryable = !streamed && !signal?.aborted && classify(err) !== 'fatal';
280
- const delay = retryable
276
+ // The provider may be back soon: the same call
277
+ // again, after telling whoever watches. A stream
278
+ // that broke mid-answer is made again from the
279
+ // start, under the same policy: nothing of it
280
+ // reached the state (no tool ran, nothing was
281
+ // recorded), so only the screen has to forget it.
282
+ // Each restart bills the tokens again; the window
283
+ // bounds how many there are.
284
+ const transient = !signal?.aborted && classify(err) !== 'fatal';
285
+ const delay = transient
281
286
  ? nextRetryDelay(this.#retry, attempt, err)
282
287
  : undefined;
283
- if (delay !== undefined &&
284
- Date.now() - firstTry + delay <= this.#retry.windowMs) {
288
+ const again = delay !== undefined &&
289
+ Date.now() - firstTry + delay <= this.#retry.windowMs;
290
+ const stall = !again && transient && !branch && this.#retry.windowMs > 0;
291
+ if (streamed && (again || stall)) {
292
+ yield tag(state, branch, {
293
+ type: 'model_output_discarded',
294
+ error: errorText(err),
295
+ model: model.id,
296
+ });
297
+ }
298
+ if (again) {
285
299
  yield tag(state, branch, {
286
300
  type: 'model_retry',
287
301
  attempt,
@@ -289,6 +303,7 @@ export class AgentRunner {
289
303
  status: statusOf(err),
290
304
  retryAt: new Date(Date.now() + delay).toISOString(),
291
305
  model: model.id,
306
+ ...(streamed ? { restart: true } : {}),
292
307
  });
293
308
  await pause(delay, signal);
294
309
  if (signal?.aborted) {
@@ -313,7 +328,7 @@ export class AgentRunner {
313
328
  // Out of patience with a provider that may yet come
314
329
  // back: the run stops at this call, kept, so `retry`
315
330
  // makes it again rather than the message being lost.
316
- if (retryable && !branch && this.#retry.windowMs > 0) {
331
+ if (stall) {
317
332
  state = Kernel.applyStall(state, {
318
333
  callId: modelCallId(state),
319
334
  model: model.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/neo",
3
- "version": "1.3.48",
3
+ "version": "1.3.50",
4
4
  "description": "A multi-agent runtime for Node.js: agents, models, tools, skills, memory and an append-only trajectory.",
5
5
  "keywords": [
6
6
  "agents",
@@ -62,7 +62,7 @@
62
62
  "prepack": "tsc -b"
63
63
  },
64
64
  "dependencies": {
65
- "@zenera/sandbox": "^1.3.48",
65
+ "@zenera/sandbox": "^1.3.50",
66
66
  "graphology": "^0.26.0",
67
67
  "yaml": "^2.9.1",
68
68
  "zod": "^4.6.7"