eve 0.27.13 → 0.28.0

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 (144) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/src/channel/adapter.d.ts +5 -5
  3. package/dist/src/channel/session.d.ts +2 -2
  4. package/dist/src/channel/types.d.ts +10 -6
  5. package/dist/src/chunks/{use-eve-agent-CsSQOKnp.js → use-eve-agent-CZkX_ZTT.js} +90 -1
  6. package/dist/src/chunks/{use-eve-agent-CWYe-vqE.js → use-eve-agent-hdPX68_i.js} +90 -1
  7. package/dist/src/cli/dev/tui/runner.js +1 -1
  8. package/dist/src/cli/dev/tui/subagent-pump.d.ts +8 -2
  9. package/dist/src/cli/dev/tui/subagent-pump.js +1 -1
  10. package/dist/src/cli/invoke/result.d.ts +15 -0
  11. package/dist/src/cli/invoke/result.js +1 -1
  12. package/dist/src/client/eve-agent-store.d.ts +7 -4
  13. package/dist/src/client/eve-agent-store.js +1 -1
  14. package/dist/src/client/index.d.ts +3 -3
  15. package/dist/src/client/index.js +1 -1
  16. package/dist/src/client/message-action-parts.js +1 -1
  17. package/dist/src/client/message-reducer-types.d.ts +5 -3
  18. package/dist/src/client/message-response.d.ts +4 -4
  19. package/dist/src/client/ndjson.d.ts +3 -3
  20. package/dist/src/client/open-stream.d.ts +2 -2
  21. package/dist/src/client/output-schema.d.ts +2 -2
  22. package/dist/src/client/reducer.d.ts +2 -2
  23. package/dist/src/client/session-utils.d.ts +5 -5
  24. package/dist/src/client/session.d.ts +2 -2
  25. package/dist/src/client/types.d.ts +2 -2
  26. package/dist/src/compiler/compile-from-memory.d.ts +1 -0
  27. package/dist/src/compiler/extension-compatibility.d.ts +8 -8
  28. package/dist/src/compiler/extension-compatibility.js +1 -1
  29. package/dist/src/compiler/manifest.d.ts +2 -2
  30. package/dist/src/compiler/manifest.js +1 -1
  31. package/dist/src/compiler/normalize-agent-config.js +1 -1
  32. package/dist/src/context/dynamic-instruction-lifecycle.d.ts +2 -2
  33. package/dist/src/context/dynamic-model-lifecycle.d.ts +2 -2
  34. package/dist/src/context/dynamic-skill-lifecycle.d.ts +2 -2
  35. package/dist/src/context/dynamic-tool-lifecycle.d.ts +2 -2
  36. package/dist/src/context/hook-lifecycle.d.ts +2 -2
  37. package/dist/src/evals/assertions/run.d.ts +3 -3
  38. package/dist/src/evals/match.d.ts +4 -4
  39. package/dist/src/evals/runner/derive-run-facts.d.ts +2 -2
  40. package/dist/src/evals/session.d.ts +3 -3
  41. package/dist/src/evals/types.d.ts +12 -12
  42. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  43. package/dist/src/execution/route-child-delivery.d.ts +4 -3
  44. package/dist/src/execution/route-child-delivery.js +1 -1
  45. package/dist/src/execution/session-delivery-hook.d.ts +1 -0
  46. package/dist/src/execution/session-delivery-hook.js +1 -1
  47. package/dist/src/execution/session-timeout-control.d.ts +9 -0
  48. package/dist/src/execution/session-timeout-control.js +1 -0
  49. package/dist/src/execution/session-timeout-steps.d.ts +13 -0
  50. package/dist/src/execution/session-timeout-steps.js +1 -0
  51. package/dist/src/execution/session-timeout-workflow.d.ts +6 -0
  52. package/dist/src/execution/session-timeout-workflow.js +1 -0
  53. package/dist/src/execution/session-timeout.d.ts +2 -0
  54. package/dist/src/execution/session-timeout.js +1 -0
  55. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  56. package/dist/src/execution/subagent-event-proxy-step.js +1 -1
  57. package/dist/src/execution/subagent-hitl-proxy.d.ts +5 -1
  58. package/dist/src/execution/subagent-hitl-proxy.js +1 -1
  59. package/dist/src/execution/terminal-session-completion-step.d.ts +5 -0
  60. package/dist/src/execution/terminal-session-completion-step.js +1 -0
  61. package/dist/src/execution/terminal-session-failure-step.js +1 -1
  62. package/dist/src/execution/turn-workflow.js +1 -1
  63. package/dist/src/execution/workflow-entry.d.ts +1 -0
  64. package/dist/src/execution/workflow-entry.js +1 -1
  65. package/dist/src/execution/workflow-runtime.d.ts +4 -0
  66. package/dist/src/execution/workflow-runtime.js +1 -1
  67. package/dist/src/execution/workflow-steps.d.ts +5 -2
  68. package/dist/src/execution/workflow-steps.js +1 -1
  69. package/dist/src/harness/agent-otel-provider.js +1 -1
  70. package/dist/src/harness/ai-sdk-hook-bridge.js +1 -1
  71. package/dist/src/harness/input-extraction.js +1 -1
  72. package/dist/src/harness/input-request-class.d.ts +23 -0
  73. package/dist/src/harness/input-request-class.js +1 -0
  74. package/dist/src/harness/input-requests.d.ts +20 -9
  75. package/dist/src/harness/input-requests.js +1 -1
  76. package/dist/src/harness/instrumentation-lifecycle.d.ts +12 -1
  77. package/dist/src/harness/proxy-input-requests.d.ts +10 -4
  78. package/dist/src/harness/proxy-input-requests.js +1 -1
  79. package/dist/src/harness/session-limit-continuation.d.ts +0 -11
  80. package/dist/src/harness/session-limit-continuation.js +1 -1
  81. package/dist/src/harness/session-limit-enforcement.d.ts +3 -2
  82. package/dist/src/harness/session-limit-enforcement.js +1 -1
  83. package/dist/src/harness/session-token-limits.d.ts +41 -0
  84. package/dist/src/harness/session-token-limits.js +1 -0
  85. package/dist/src/harness/stale-input-responses.js +1 -1
  86. package/dist/src/harness/subagent-token-budget.d.ts +6 -4
  87. package/dist/src/harness/subagent-token-budget.js +1 -1
  88. package/dist/src/harness/tool-loop.js +1 -1
  89. package/dist/src/harness/turn-tag-state.d.ts +26 -17
  90. package/dist/src/harness/turn-tag-state.js +1 -1
  91. package/dist/src/harness/types.d.ts +4 -4
  92. package/dist/src/harness/workflow-lifecycle.d.ts +2 -2
  93. package/dist/src/internal/application/package.js +1 -1
  94. package/dist/src/internal/authored-definition/core.js +1 -1
  95. package/dist/src/internal/workflow-bundle/workflow-core-shim.d.ts +1 -1
  96. package/dist/src/internal/workflow-bundle/workflow-core-shim.js +1 -1
  97. package/dist/src/protocol/event-dedupe.d.ts +25 -0
  98. package/dist/src/protocol/event-dedupe.js +1 -0
  99. package/dist/src/protocol/event-id.d.ts +16 -0
  100. package/dist/src/protocol/event-id.js +1 -0
  101. package/dist/src/protocol/message.d.ts +39 -23
  102. package/dist/src/protocol/message.js +2 -2
  103. package/dist/src/public/channels/discord/discordChannel.d.ts +3 -3
  104. package/dist/src/public/channels/github/githubChannel.d.ts +3 -3
  105. package/dist/src/public/channels/linear/linearChannel.d.ts +3 -3
  106. package/dist/src/public/channels/slack/hitl.js +1 -1
  107. package/dist/src/public/channels/slack/slackChannel.d.ts +3 -3
  108. package/dist/src/public/channels/teams/hitl.js +1 -1
  109. package/dist/src/public/channels/teams/teamsChannel.d.ts +3 -3
  110. package/dist/src/public/channels/telegram/telegramChannel.d.ts +3 -3
  111. package/dist/src/public/channels/twilio/twilioChannel.d.ts +3 -3
  112. package/dist/src/public/definitions/channel.d.ts +4 -4
  113. package/dist/src/public/definitions/hook.d.ts +2 -2
  114. package/dist/src/react/use-eve-agent.d.ts +3 -2
  115. package/dist/src/runtime/framework-tools/ask-question.js +1 -1
  116. package/dist/src/runtime/hooks/registry.d.ts +2 -2
  117. package/dist/src/runtime/input/types.d.ts +19 -4
  118. package/dist/src/runtime/input/types.js +1 -1
  119. package/dist/src/runtime/resolve-agent.js +1 -1
  120. package/dist/src/runtime/types.d.ts +2 -2
  121. package/dist/src/setup/scaffold/create/project.js +1 -1
  122. package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
  123. package/dist/src/setup/scaffold/create/web-template.js +2 -2
  124. package/dist/src/shared/agent-definition.d.ts +12 -0
  125. package/dist/src/shared/dynamic-tool-definition.d.ts +2 -2
  126. package/dist/src/shared/ulid.d.ts +39 -0
  127. package/dist/src/shared/ulid.js +1 -0
  128. package/dist/src/svelte/index.js +1 -1
  129. package/dist/src/svelte/use-eve-agent.d.ts +4 -4
  130. package/dist/src/svelte/use-eve-agent.js +1 -1
  131. package/dist/src/vue/index.js +1 -1
  132. package/dist/src/vue/use-eve-agent.d.ts +4 -4
  133. package/dist/src/vue/use-eve-agent.js +1 -1
  134. package/docs/agent-config.md +28 -16
  135. package/docs/concepts/execution-model-and-durability.mdx +1 -1
  136. package/docs/concepts/sessions-runs-and-streaming.md +61 -0
  137. package/docs/guides/client/streaming.mdx +9 -3
  138. package/docs/guides/frontend/overview.mdx +4 -2
  139. package/docs/guides/frontend/use-eve-agent-svelte.mdx +1 -1
  140. package/docs/guides/frontend/use-eve-agent-vue.mdx +10 -10
  141. package/docs/guides/hooks.md +40 -2
  142. package/docs/guides/instrumentation.md +4 -0
  143. package/docs/tools/human-in-the-loop.md +5 -0
  144. package/package.json +1 -1
@@ -14,6 +14,12 @@ Two handles do two jobs, and mixing them up is the most common mistake. One hand
14
14
 
15
15
  A session has one active continuation at a time: each follow-up uses the current `continuationToken`, and a stale one is rejected.
16
16
 
17
+ Sessions last 30 days by default; configure `limits.sessionTimeoutMs` in
18
+ `agent.ts`, or set it to `false` to disable the deadline. At expiration, eve
19
+ lets an active turn settle, emits `session.completed`, and releases the
20
+ continuation so the next qualifying channel message starts fresh. Stored
21
+ session data is not deleted. See [Agent config](../agent-config#runtime-limits).
22
+
17
23
  React, Vue, and Svelte apps reach for [`useEveAgent()`](../guides/frontend/overview) instead of calling these routes by hand. Next.js and Nuxt apps can proxy them to the eve runtime from the same origin.
18
24
 
19
25
  ## Start a session
@@ -73,6 +79,59 @@ A delegated subagent publishes progress on its own child-session stream. The par
73
79
 
74
80
  `step.failed` and `turn.failed` carry `{ code, message, details? }` for the failed fragment or turn, and `session.failed` is the terminal session-level variant. `turn.cancelled` is not a failure: the cancelled turn ends without any failure event, `session.waiting` follows, and the session accepts the next message normally — whatever the turn streamed before cancellation stays on the stream, while durable history keeps only what had already settled. When a turn requested an output schema, the finalized payload lands on `result.completed` as `data.result` before the turn boundary. `authorization.required` carries the sign-in challenge (`data.authorization` may include `url`, `userCode`, `expiresAt`, `instructions`), and `authorization.completed` carries `data.outcome` (`"authorized" | "declined" | "failed" | "timed-out"`).
75
81
 
82
+ ## The event envelope
83
+
84
+ Alongside `type` and `data`, every event carries a `meta` envelope:
85
+
86
+ ```json
87
+ {
88
+ "type": "message.completed",
89
+ "data": {
90
+ "message": "Sunny and 72°F.",
91
+ "finishReason": "stop",
92
+ "sequence": 0,
93
+ "stepIndex": 0,
94
+ "turnId": "turn_0"
95
+ },
96
+ "meta": { "id": "evt_01KYJBZA88B4M9XN3RTC5FDGHJ", "at": "2026-07-27T18:04:11.912Z" }
97
+ }
98
+ ```
99
+
100
+ - **`meta.id`** uniquely identifies the event. It is an `evt_`-prefixed [ULID](https://github.com/ulid/spec): a millisecond timestamp followed by random bits, so ids are broadly time-ordered.
101
+ - **`meta.at`** is the ISO-8601 time the event was emitted.
102
+
103
+ `meta.id` is stable. eve mints it once, when the event is written to the durable stream, and stores it with the event. Reconnecting from a cursor, rewinding to `startIndex=0`, or replaying a finished session all return the same id for the same event.
104
+
105
+ `meta.at` has always been there; `meta.id` arrived in stream version 20. Events written by an earlier version are stored with the envelope but no id inside it, so rewinding into the part of a session that ran before you upgraded yields events whose `meta.id` is absent, even though the type says it is always a string. eve passes those events through rather than dropping them, and they cannot be deduplicated. The exposure ends when the sessions that predate your upgrade do.
106
+
107
+ That makes it the key for ingesting a stream into a database without duplicating rows when you re-read it:
108
+
109
+ ```sql
110
+ insert into agent_events (id, session_id, type, data, emitted_at)
111
+ values ($1, $2, $3, $4, $5)
112
+ on conflict (id) do nothing;
113
+ ```
114
+
115
+ Because ids lead with a timestamp, a `primary key (id)` stays roughly append-ordered and keeps inserts clustered.
116
+
117
+ **What the id covers.** Reconnecting is not the only way the same event reaches you twice. Keying on `meta.id` is what makes ingestion correct in all of these:
118
+
119
+ - Reconnecting mid-turn and overlapping events you already handled.
120
+ - Rewinding with `startIndex=0`, or reading back from the tail with a negative `startIndex`.
121
+ - Restoring a saved event log that overlaps the prefix the live stream replays.
122
+
123
+ **What it does not cover: a retried step re-emits under new ids.** eve runs each durable step up to four times. If a step is interrupted partway — a crash, a timeout, a model error it retries through — whatever it already wrote stays on the stream, and the new attempt emits its own events with their own ids. Both attempts carry the same `turnId`, `stepIndex`, and `sequence`, because the retry restores that state from the step's input, but they are distinct events and no field records which attempt finished.
124
+
125
+ Replaying a _completed_ step is a different thing and emits nothing at all: eve serves the recorded result from its journal without re-running the body. Crash recovery, redeploys, and resuming a parked turn therefore add nothing to the stream. Only an interrupted step re-runs.
126
+
127
+ Three more things to know:
128
+
129
+ - **Ids are time-ordered, not a total order.** The turn steps of one session can run in different processes, each generating ids from its own clock and its own random bits. Two events emitted in the same millisecond by different steps may sort either way, and clock skew between machines can invert neighbours. Record your own ingestion sequence, or read the stream in order and store the index, when you need an exact ordering to page against — do not use `where id > $cursor` as a lossless cursor. The stream itself is authoritative: `startIndex` is an absolute event count.
130
+ - **Ids identify events, not intent.** Two events with identical payloads — the `step.failed` → `turn.failed` → `session.failed` cascade, or two identical text deltas in one step — are distinct events with distinct ids. Deduplicate on `meta.id` only; matching on content would drop real data.
131
+ - **A subagent's event is re-emitted, not shared.** When a parent forwards a child's event onto its own stream, the parent's copy is a separate event with its own id. Correlate the two streams through `subagent.called.data.childSessionId`.
132
+
133
+ Authored [hooks](../guides/hooks) receive the same envelope, but observe each event as it is emitted rather than as it is read — so a hook sees a retry as new events, and `meta.id` is a key for a stored row rather than a retry guard. Two things a hook does not have to defend against: a turn that parks for human input resumes without re-emitting anything it already sent, and a retried turn dispatch cannot double-stream a turn, because only one turn run can claim a session's turn inbox.
134
+
76
135
  ## Send a follow-up message
77
136
 
78
137
  Once the session is waiting (you'll see `session.waiting`), POST your follow-up to the session endpoint with `event.data.continuationToken`:
@@ -112,6 +171,8 @@ Custom channel routes request the same cancellation without knowing the session
112
171
 
113
172
  The stream is durable. Every event is recorded before a step completes, so consumers can reconnect from their cursor when an HTTP connection ends. A nonnegative `startIndex` is an absolute event count: use it to pick up where you dropped off or pass `0` to rewind to the start.
114
173
 
174
+ If a reconnect overlaps events you already handled, [`meta.id`](#the-event-envelope) identifies the duplicates: it is unchanged across reconnects and rewinds, so a consumer keyed on it can replay safely.
175
+
115
176
  ```bash
116
177
  curl "http://127.0.0.1:2000/eve/v1/session/<sessionId>/stream?startIndex=<count>"
117
178
  ```
@@ -60,13 +60,17 @@ for await (const event of response) {
60
60
 
61
61
  ## Handle event types
62
62
 
63
- Import event types from `eve/client` when you want exhaustiveness or helpers:
63
+ Import event types from `eve/client` when you want exhaustiveness or helpers. Events read from a stream are `MessageStreamEvent`: the same union, with the `meta` envelope guaranteed present.
64
+
65
+ `HandleMessageStreamEvent` remains available as a deprecated alias, so existing type imports continue to compile.
64
66
 
65
67
  ```ts
66
- import type { HandleMessageStreamEvent } from "eve/client";
68
+ import type { MessageStreamEvent } from "eve/client";
67
69
  import { isCurrentTurnBoundaryEvent } from "eve/client";
68
70
 
69
- function handleEvent(event: HandleMessageStreamEvent) {
71
+ function handleEvent(event: MessageStreamEvent) {
72
+ console.log(event.meta.id, event.meta.at);
73
+
70
74
  if (isCurrentTurnBoundaryEvent(event)) {
71
75
  console.log("turn settled:", event.type);
72
76
  }
@@ -105,6 +109,8 @@ If you support refresh while an authorization prompt is pending, keep the sessio
105
109
 
106
110
  HTTP connections can end before a run does. The client reconnects from the number of events already consumed, so long turns continue without replaying events. It stops at a turn boundary, when aborted, or when the stream can no longer make progress.
107
111
 
112
+ If your consumer persists events, key on `event.meta.id`. It is stable across reconnects and rewinds, so an overlapping replay is safe to ingest twice. See [the event envelope](../../concepts/sessions-runs-and-streaming#the-event-envelope).
113
+
108
114
  Set `streamReconnectPolicy: { reconnect: false }` when a relay or proxy owns the cursor and reconnection policy. This makes a single stream GET attempt and returns when that connection ends; it does not stop the server-side turn:
109
115
 
110
116
  ```ts
@@ -226,10 +226,10 @@ const agent = useEveAgent({ reducer: toolCounter });
226
226
  The browser conversation lives durably on the server. Persist both the rendered event log and the `session` cursor to pick it back up after a reload:
227
227
 
228
228
  ```tsx
229
- import type { HandleMessageStreamEvent, SessionState } from "eve/client";
229
+ import type { SessionState, MessageStreamEvent } from "eve/client";
230
230
 
231
231
  type SavedEveChat = {
232
- events?: readonly HandleMessageStreamEvent[];
232
+ events?: readonly MessageStreamEvent[];
233
233
  session?: SessionState;
234
234
  };
235
235
 
@@ -255,6 +255,8 @@ const agent = useEveAgent({
255
255
 
256
256
  Store the full `session` object (`sessionId`, `continuationToken`, `streamIndex`), not a single field. The session cursor lets eve continue the durable conversation; the event log lets your UI render historical messages without replaying the whole stream. A database-backed chat app should usually persist stream events as they arrive with `onEvent` and then save a final snapshot in `onFinish`.
257
257
 
258
+ `initialEvents` must be an ordered prefix of the same session's stream, but its endpoint does not have to line up exactly with where the stream resumes. Every event carries a stable [`meta.id`](/docs/concepts/sessions-runs-and-streaming#the-event-envelope), and the store drops any event whose id it has already applied — so a saved log that overlaps the replayed prefix renders once, and `onEvent` only fires for events your UI has not seen.
259
+
258
260
  For multiple chat threads, keep one saved event log and session cursor per thread. `agent`, `host`, `reducer`, `session`, `initialEvents`, `initialSession`, `auth`, `headers`, and `optimistic` are read when the hook creates its store, so remount the chat component when switching threads, for example with `key={chat.id}`.
259
261
 
260
262
  If the user can refresh or navigate immediately after pressing send, create your app-level chat row and store the pending user message before calling `send()`. After the request starts, persist the session state as soon as it contains a `sessionId`, then reconnect an interrupted in-flight turn with `session.stream({ startIndex: savedEvents.length })` from the lower-level client.
@@ -28,7 +28,7 @@ Import from `eve/svelte` and read the reactive getters directly. No `$` prefix:
28
28
  | `data` | `TData` | Projected state. With the default reducer, `EveMessageData` (`messages`). |
29
29
  | `status` | `UseEveAgentStatus` | `"ready"`, `"submitted"`, `"streaming"`, or `"error"`. |
30
30
  | `error` | `Error \| undefined` | Last transport-level error. |
31
- | `events` | `readonly HandleMessageStreamEvent[]` | Raw server events for this session. |
31
+ | `events` | `readonly MessageStreamEvent[]` | Raw server events for this session. |
32
32
  | `session` | `SessionState` | Snapshot of session state. |
33
33
  | `send` | `(input: SendTurnPayload) => Promise<void>` | Send text or a full turn (multi-part, attachments, HITL responses). |
34
34
  | `stop` | `() => void` | Abort the client's in-flight stream. |
@@ -25,16 +25,16 @@ const { data } = useEveAgent();
25
25
 
26
26
  ## What it returns
27
27
 
28
- | Property | Type | Description |
29
- | --------- | -------------------------------------------------- | ------------------------------------------------------------------------- |
30
- | `data` | `ComputedRef<TData>` | Projected state. With the default reducer, `EveMessageData` (`messages`). |
31
- | `status` | `ComputedRef<UseEveAgentStatus>` | `"ready"`, `"submitted"`, `"streaming"`, or `"error"`. |
32
- | `error` | `ComputedRef<Error \| undefined>` | Last transport-level error. |
33
- | `events` | `ComputedRef<readonly HandleMessageStreamEvent[]>` | Raw server events for this session. |
34
- | `session` | `ComputedRef<SessionState>` | Snapshot of session state. |
35
- | `send` | `(input: SendTurnPayload) => Promise<void>` | Send text or a full turn (multi-part, attachments, HITL responses). |
36
- | `stop` | `() => void` | Abort the client's in-flight stream. |
37
- | `reset` | `() => void` | Clear state and start a new session. |
28
+ | Property | Type | Description |
29
+ | --------- | -------------------------------------------- | ------------------------------------------------------------------------- |
30
+ | `data` | `ComputedRef<TData>` | Projected state. With the default reducer, `EveMessageData` (`messages`). |
31
+ | `status` | `ComputedRef<UseEveAgentStatus>` | `"ready"`, `"submitted"`, `"streaming"`, or `"error"`. |
32
+ | `error` | `ComputedRef<Error \| undefined>` | Last transport-level error. |
33
+ | `events` | `ComputedRef<readonly MessageStreamEvent[]>` | Raw server events for this session. |
34
+ | `session` | `ComputedRef<SessionState>` | Snapshot of session state. |
35
+ | `send` | `(input: SendTurnPayload) => Promise<void>` | Send text or a full turn (multi-part, attachments, HITL responses). |
36
+ | `stop` | `() => void` | Abort the client's in-flight stream. |
37
+ | `reset` | `() => void` | Clear state and start a new session. |
38
38
 
39
39
  The first five are `ComputedRef`s; the rest are methods. Destructure whatever you need, since refs keep their reactivity through destructuring. Read them with `.value` in `<script>`, and unwrapped in `<template>`.
40
40
 
@@ -80,15 +80,53 @@ import { search } from "@acme/crm/tools";
80
80
  const crmSearch = toolResultFrom(event.data.result, search); // typed; matches crm__search
81
81
  ```
82
82
 
83
+ ### Persist events to your own database
84
+
85
+ Every event carries a `meta` envelope with `meta.id`, a unique, sortable identifier for that event. It makes a natural primary key for an events table:
86
+
87
+ ```ts title="agent/hooks/persist.ts"
88
+ import { defineHook } from "eve/hooks";
89
+
90
+ export default defineHook({
91
+ events: {
92
+ async "*"(event, ctx) {
93
+ await db.query(
94
+ `insert into agent_events (id, session_id, type, data, emitted_at)
95
+ values ($1, $2, $3, $4, $5)
96
+ on conflict (id) do nothing`,
97
+ [
98
+ event.meta.id,
99
+ ctx.session.id,
100
+ event.type,
101
+ "data" in event ? event.data : null,
102
+ event.meta.at,
103
+ ],
104
+ );
105
+ },
106
+ },
107
+ });
108
+ ```
109
+
110
+ `meta.id` is stable for the life of the persisted event, so a consumer that re-reads the stream can ingest the same event twice safely. It is not a retry guard for the hook itself: if a step is interrupted and re-runs, the turn re-emits its events as _new_ events with new ids, and your hook runs again for each one.
111
+
112
+ What to key on instead depends on what you are protecting:
113
+
114
+ - **A side effect that must happen once per turn or step** — a charge, an email, a ticket — keys well on the coordinates in `event.data` (`turnId`, `stepIndex`, `sequence`). A retry restores those from the step's input, so the second attempt computes the same key and your gate holds.
115
+ - **Stored content should not key on those coordinates.** The retry re-invokes the model, so one coordinate can carry different text on each attempt. `on conflict (turn_id, step_index, sequence) do nothing` would keep the abandoned attempt and drop the one that finished. Key on `meta.id`, and accept that an interrupted turn leaves both attempts in the table.
116
+
117
+ Behind that split is an asymmetry worth knowing: durable history keeps only the attempt that completed, while the event stream keeps every attempt, and no field marks which is which. Hooks are at-least-once, and no key collapses a retry.
118
+
119
+ See [the event envelope](../concepts/sessions-runs-and-streaming#the-event-envelope) for the full contract.
120
+
83
121
  ## Execution order
84
122
 
85
123
  When a stream event fires, three things happen in order:
86
124
 
87
- 1. Emit. The channel adapter handler runs, then the event is written to the durable stream.
125
+ 1. Emit. The channel adapter handler runs, the event is stamped with its `meta` envelope, then it is written to the durable stream.
88
126
  2. Hooks. Stream-event hooks fire (typed handlers first, then the `*` wildcard). Return values are ignored.
89
127
  3. Dynamic tool resolvers. Resolvers subscribed to the event type run and update the tool set.
90
128
 
91
- Hooks always run after the event is durably recorded, so if a hook throws, the stream stays consistent.
129
+ Hooks always run after the event is durably recorded, so if a hook throws, the stream stays consistent. The persisted event and every hook observe the same `meta.id`.
92
130
 
93
131
  ## What happens when a hook throws
94
132
 
@@ -15,6 +15,10 @@ The directory is an immutable OTLP/JSON spool and remains available after `eve d
15
15
 
16
16
  Use `eve trace ls` to list captured traces and `eve trace <trace>` to inspect a session's span tree.
17
17
 
18
+ When a model call is served by Vercel AI Gateway, its `agent.step` span also carries the cost the gateway reported: `gen_ai.usage.cost` (raw inference, USD), `gen_ai.usage.gateway_cost` (with the gateway surcharge), `gen_ai.usage.input_cost` / `gen_ai.usage.output_cost` (the split), and `gen_ai.generation.id` for reconciliation with the gateway dashboard. These attributes only exist for gateway-served calls — other providers emit nothing. Cost per turn is the sum across the turn's step spans.
19
+
20
+ Model and step spans also split token usage when the provider reports details: `gen_ai.usage.cache_read.input_tokens` and `gen_ai.usage.cache_creation.input_tokens` (named for the [OTel GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai)) alongside the `agent.usage.input_tokens` / `agent.usage.output_tokens` totals — cached tokens price differently, so the split makes cost attribution exact. Providers without detailed usage emit only the totals.
21
+
18
22
  The local writer is an internal development default, not a second provider layered over authored instrumentation. When `instrumentation.ts` exists, its setup retains control and the zero-config writer is not installed.
19
23
 
20
24
  ### Local trace retention
@@ -102,6 +102,11 @@ Approvals and questions share one protocol:
102
102
  3. The turn parks at `session.waiting`, durably, for as long as it takes.
103
103
  4. The client answers with `inputResponses` (structured, keyed by `requestId`) or a normal follow-up `message`. A follow-up whose text matches an option ID, option label, or numeric option index resolves automatically, including approval options such as `approve` and `deny`.
104
104
 
105
+ Each request includes a `kind` discriminator: `tool-approval`, `question`, or
106
+ `session-limit`. Clients should use `kind` to choose behavior and presentation;
107
+ `toolName` and `requestId` identify the action and request but do not encode its
108
+ semantics.
109
+
105
110
  The run picks back up exactly where it parked. Because the pause is durable, nothing is held in memory while it waits — the process can restart and the parked turn survives.
106
111
 
107
112
  For approval requests, unrelated follow-up text does not deny the tool call. eve keeps the approval pending and holds that text until the approval is answered, then replays it as the next message in the session.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve",
3
- "version": "0.27.13",
3
+ "version": "0.28.0",
4
4
  "private": false,
5
5
  "description": "Filesystem-first framework for durable backend AI agents that run anywhere.",
6
6
  "keywords": [