@qlairoslabs/acp-client 0.11.0 → 0.12.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 (85) hide show
  1. package/CHANGELOG-consumer-fixes.md +55 -0
  2. package/CHANGELOG-operation-lifecycle.md +64 -0
  3. package/CONSUMER_GUIDE.md +311 -17
  4. package/MIGRATION-0.10-to-0.12.md +189 -0
  5. package/README.md +6 -3
  6. package/package.json +5 -2
  7. package/src/adapters.ts +3 -1
  8. package/src/agent/adoption/checkpoint-floor.ts +47 -0
  9. package/src/agent/adoption/index.ts +3 -1
  10. package/src/agent/adoption/replay.ts +15 -0
  11. package/src/agent/config.ts +4 -0
  12. package/src/agent/conversation-manager.ts +223 -153
  13. package/src/agent/error-record-writer.ts +77 -0
  14. package/src/agent/persisted-lifecycle.ts +152 -35
  15. package/src/agent/record-capture.ts +18 -18
  16. package/src/agent-adapter-registry.ts +2 -0
  17. package/src/agent-client.ts +9 -3
  18. package/src/agent-conversation-contracts.ts +6 -0
  19. package/src/agent-conversation-owner.ts +31 -6
  20. package/src/agent-conversation-presentation.ts +12 -1
  21. package/src/agent-conversation-queue.ts +3 -2
  22. package/src/agent-session.ts +537 -96
  23. package/src/agent.ts +46 -23
  24. package/src/audit/config.ts +4 -0
  25. package/src/audit/projection.ts +3 -0
  26. package/src/checkpointing/contracts.ts +28 -3
  27. package/src/checkpointing/persistence/sqlite-repository.ts +36 -8
  28. package/src/checkpointing/recovery.ts +9 -2
  29. package/src/checkpointing/strategy.ts +27 -2
  30. package/src/client.ts +120 -30
  31. package/src/controller.ts +116 -7
  32. package/src/degraded/pty-client.ts +25 -1
  33. package/src/identity/checkpoint-backed.ts +2 -2
  34. package/src/index.ts +17 -0
  35. package/src/internal-inference/config.ts +7 -0
  36. package/src/internal-inference/contracts.ts +3 -0
  37. package/src/internal-inference/coordination/handles.ts +11 -2
  38. package/src/internal-inference/coordination/manager.ts +20 -3
  39. package/src/internal-inference/index.ts +2 -0
  40. package/src/internal-inference/persistence/records.ts +3 -1
  41. package/src/internal-inference/persistence/sqlite-repository.ts +4 -1
  42. package/src/internal-inference/runtime/disposable-session-env.ts +84 -0
  43. package/src/internal-inference/runtime/harness-runtime.ts +19 -2
  44. package/src/media/acp.ts +118 -0
  45. package/src/media/capture.ts +15 -0
  46. package/src/media/content.ts +142 -0
  47. package/src/media/files.ts +28 -0
  48. package/src/media/parts.ts +145 -0
  49. package/src/media/pending.ts +51 -0
  50. package/src/media/redact.ts +14 -0
  51. package/src/media/store.ts +127 -0
  52. package/src/metering/provider.ts +8 -1
  53. package/src/operations/activity-tracker.ts +31 -0
  54. package/src/operations/contracts.ts +63 -0
  55. package/src/operations/errors.ts +31 -0
  56. package/src/operations/index.ts +6 -0
  57. package/src/operations/stale-policy.ts +51 -0
  58. package/src/operations/supervisor.ts +209 -0
  59. package/src/operations/timers.ts +12 -0
  60. package/src/out-of-band-messages.ts +49 -32
  61. package/src/persistence/audit-runtime.ts +14 -2
  62. package/src/persistence/backend.ts +108 -12
  63. package/src/persistence/error-records.ts +27 -0
  64. package/src/persistence/index.ts +8 -0
  65. package/src/persistence/presentation.ts +9 -1
  66. package/src/persistence/projection.ts +20 -0
  67. package/src/persistence/records.ts +45 -6
  68. package/src/persistence/sqlite-backend.ts +207 -16
  69. package/src/persistence/sqlite-conversation-records.ts +31 -4
  70. package/src/persistence/sqlite-files.ts +95 -0
  71. package/src/persistence/sqlite-media-store.ts +67 -0
  72. package/src/persistence/sqlite-schema.ts +146 -13
  73. package/src/persistence/state-runtime.ts +2 -0
  74. package/src/persistence/timeline-reconcile.ts +21 -4
  75. package/src/persistence/transcript-reader.ts +11 -4
  76. package/src/persistence/transcript-runtime.ts +105 -12
  77. package/src/repl/repl.ts +1 -1
  78. package/src/response.ts +40 -8
  79. package/src/steering/combine.ts +11 -4
  80. package/src/steering/contracts.ts +14 -4
  81. package/src/steering/controller.ts +96 -21
  82. package/src/steering/index.ts +1 -0
  83. package/src/transport/acp-transport.ts +18 -7
  84. package/src/types.ts +7 -0
  85. package/src/updates.ts +4 -4
@@ -0,0 +1,189 @@
1
+ # Migrating from 0.10.2 to 0.12.0
2
+
3
+ For agents-core and the webapp, which pin `@qlairoslabs/acp-client` `0.10.2`. This covers everything
4
+ since: `0.11.0`, the operation lifecycle (`0.11.2`), and the work done for the 2026-10-13
5
+ requirements list. `CONSUMER_GUIDE.md` is the full reference; this file says what changed and what to do
6
+ about it.
7
+
8
+ **Status.** 0.12.0 is on the library's `beta` branch, not yet pushed or published. Until it is,
9
+ point agents-core at a local checkout of the library to try it.
10
+
11
+ ## Before you upgrade
12
+
13
+ - **Back up the SQLite agent databases.** Opening one migrates it to schema 16 (from 14, through 15).
14
+ The migration is one way: an older library refuses the migrated file.
15
+ - Schema 15 rebuilds `conversation_records` to admit a new record kind, and recovers `operationId` on
16
+ older records from their record ids.
17
+ - Schema 16 adds a blob table for kept media and an out-of-band delivery table, and rebuilds the
18
+ message full-text index without inline bytes. On a large database the first open takes longer.
19
+ - JSONL transcripts and audit logs need no migration; they gain new line types (below).
20
+
21
+ ## Breaking changes checklist
22
+
23
+ Each item says what changed and what agents-core has to do.
24
+
25
+ | # | change | what to do |
26
+ |---|---|---|
27
+ | 1 | **A prompt sent while a turn runs is steered by default** (`busyDelivery: "steer"`, was `"queue"`). | agents-core already passes `delivery: "steer"` when a turn runs. Elsewhere, set `busyDelivery: "queue"` to keep the old behavior. |
28
+ | 2 | **Silent turns now fail as stalled.** No output for 120 s after the request, or 180 s between outputs (tools and permissions pause the clock), fails the operation with `OperationStalledError` (`code: "stalled"`). Agent-owned conversations record an error record and mark the partial reply failed. | Handle `stalled` like other turn failures. Raise or disable limits with `operationLifecycle: { turns: { firstOutputMs, nextOutputMs } }` (`false` disables one). |
29
+ | 3 | **The conversation reconnects by itself** after the provider process exits or is force-stopped, on the next operation (`provider_reconnected`, `via: loaded \| recovered \| fresh`). | If agents-core retires a conversation whose provider died, it can keep it instead and prompt again. |
30
+ | 4 | **Queued messages are held after a failed turn** the provider received. Pending steers run after recovery; the next consumer turn that completes releases the hold. | Show `state.pendingHold` and `pendingMessages[].heldBy` if the UI lists pending messages. With `busyDelivery: "queue"`, send one prompt with `delivery: "steer"` to release. |
31
+ | 5 | **Cancelled results say how the cancel ended:** `cancel: "acknowledged" \| "forced"`. Pending permissions are answered as cancelled, and the permission handler gets an optional `AbortSignal`. | Nothing required. Use the `AbortSignal` to close a permission dialog. |
32
+ | 6 | **Every record carries `operationId`** (typed field), not only messages in their metadata. | Prefer `record.operationId` over `JSON.parse(record.metadata).operationId`; both work for messages. |
33
+ | 7 | **Appended out-of-band messages have no operation.** `appendAssistantMessage` used to give each its own operation id; now the record is standalone, at the sequence it was appended. | Don't expect `operationId` on appended messages. |
34
+ | 8 | **New record kind `cancellation`** (SQLite and JSONL; audit key `cancellation`). It has `requested` (reason: `steer`, `interrupt`, `stalled`, `stop`, `abort`) and `resolved` (outcome: `acknowledged`, `forced`, `too_late`, `failed`) revisions, under the cancelled operation. | `projectSqliteChatRecord` maps unknown kinds to activities, so these show up as `cancellation` activity items. Decide whether to show them (a turn shown as stopped or redirected after reload) or skip them. |
35
+ | 9 | **Timeline item ids for tool calls, permissions, thinking and activity change once**: items are now keyed by operation, so two turns reusing a provider id stay two items. Message ids don't change. | If agents-core stores timeline item ids (from `conversationTimelineItemId`), expect them to change once for those kinds. |
36
+ | 10 | **Message content can be blocks, not just a string.** A message with media or a named paste stores `PersistedContentBlock[]`: `text`, `pasted`, `media`. Plain text messages stay strings. | `projectSqliteChatRecord` keeps only `type: "text"` blocks, so a pasted block's text disappears. Include `pasted`, and render `media` blocks (below). Note that it joins text blocks with `"\n"`, while the library joins a message's text parts with nothing (separators are their own parts). |
37
+ | 11 | **Attachments go out as their real kind.** `prompt(text, handlers, attachments)` used to send every attachment as an ACP `image`. Now an image is an `image`, audio is `audio`, and anything else is an embedded file, which needs the agent's `embeddedContext`. An agent that can't take the kind refuses the prompt with `agent does not support <kind> copies`. | Expect that error for non-image attachments to agents without that support. Claude's adapter advertises embedded context but silently drops binary files (PDFs), so send those to Claude as links (`mode: "link"`); text files work. |
38
+ | 12 | **Attachments are recorded** on Agent-owned conversations, as media blocks with name, type, size and hash (`keep: false`, no bytes). The user message's `content` becomes blocks when it has attachments (see 10). | Nothing required; it's the start of dropping the `chat-attachments` side store (below). |
39
+ | 13 | **Presentation items' `timestamp` is deprecated**, an alias of the new `updatedAt`. Timeline items gain `startedAt` and `updatedAt`. | Show a message's time with `startedAt`. |
40
+ | 14 | **`AgentConversation.listSessions()` is deprecated** and now throws when the harness listing fails, instead of silently returning the catalog half. | Use `agent.conversations.list()` for conversations and `agent.conversations.listProviderSessions()` for harness sessions. |
41
+ | 15 | **`setConfig` with the value the option already has does nothing**: no request, record or event. | Nothing required. The Hub's re-applied settings stop filling the history. |
42
+ | 16 | **`PromptPart` is renamed `CombinedMessage`** (steering's original messages of a combined prompt). `PromptPart` stays as a deprecated alias. | Rename when convenient. |
43
+
44
+ ## The requirements, before and after
45
+
46
+ ### 1, 2. Operation ids, and history pages that don't cut turns
47
+
48
+ `identity-store.ts` reads recent history with `listRecent({ limit })`, which counts records, so a page can
49
+ start in the middle of a turn.
50
+
51
+ ```ts
52
+ // now: N agent messages per page, each with what led to it; nothing is split
53
+ const page = await persistence.records.listRecent(conversationId, {
54
+ agentMessages: 20, // the page unit; the cut is right after an agent message
55
+ fold: true, // timeline items instead of records
56
+ detail: "summary", // tool calls without input/output
57
+ ...(cursor ? { olderCursor: cursor } : {}),
58
+ });
59
+ page.items; // ConversationTimelineItem[]
60
+ page.olderCursor; // next older page
61
+ page.truncated; // the page hit `limit` (default 2000)
62
+
63
+ // a tool call's full input/output, on demand
64
+ const record = await persistence.records.get(recordId);
65
+ ```
66
+
67
+ - Every record lands on the page where its item began, so an item never spans two pages.
68
+ - A cursor remembers its unit; a records cursor can't be used for an agent-messages page.
69
+ - `records.list(id, { operationId })` filters by operation.
70
+ - Without the new options, `listRecent` behaves as before.
71
+
72
+ ### 3. How a turn ended
73
+
74
+ The `cancellation` records (checklist item 8) say whether a turn was stopped, steered or interrupted,
75
+ and whether the cancel was acknowledged or forced. A failed turn already had an error record.
76
+
77
+ ### 4. Re-applied settings
78
+
79
+ Not recorded any more (checklist item 15).
80
+
81
+ ### 5. A message's time
82
+
83
+ `ConversationTimelineItem.startedAt` is the first revision's time, `updatedAt` the latest. Messages are
84
+ also recorded `completed` when the next message or a tool call starts, with that time, instead of all
85
+ at turn end with one timestamp. A tool call now ends the message before it, also when the agent sends
86
+ no message ids.
87
+
88
+ ### 6, 7, 10. Messages made of parts
89
+
90
+ agents-core keeps attachments in its own `chat-attachments` store (files under the agent's shared
91
+ directory, plus `prompt-records.json` joined to history by operation id). The library can now hold
92
+ them itself:
93
+
94
+ ```ts
95
+ await conversation.prompt({
96
+ text: "compare these",
97
+ parts: [
98
+ { kind: "image", data: bytes, name: "chart.png", mimeType: "image/png" }, // copy, kept by default
99
+ { kind: "file", path: "/srv/files/report.pdf" }, // copy or link, by size
100
+ { kind: "file", path: "/srv/files/big.log", mode: "link" }, // the agent opens it
101
+ { kind: "pasted", text: longPaste, name: "error output" }, // a named paste
102
+ { kind: "text", text: "Answer in Spanish.", record: false }, // sent, not recorded
103
+ ],
104
+ });
105
+ ```
106
+
107
+ - **A part's source:** `data` (bytes), `path` (a path or `file://` uri) or `ref` (a copy already kept).
108
+ - **`mode: "copy"`** sends the content in the prompt. **`mode: "link"`** sends a pointer and the agent
109
+ opens the file itself; later edits or deletion of the file affect what history shows. Without a mode,
110
+ a path goes as a link above 100 KB for files, 3.75 MB for images and 5 MB for audio (configurable:
111
+ `Agent.open({ media: { thresholds } })`).
112
+ - **`keep: false`** records name, type, size and hash without the bytes. **`record: false`** sends the
113
+ part without recording it. This is requirement 7: text for the provider only.
114
+ - **Where kept bytes go:** by default a table in the agent's SQLite database, written in the same
115
+ transaction as the message. To keep them elsewhere, pass your own store:
116
+ `Agent.open({ media: { store } })`, an object with `put`, `get`, `delete` and `list(owner)`.
117
+ - **What's recorded is controlled by `capture.media`** (`none`, `metadata`, `content`; default
118
+ `content`), separately from `capture.message`, and per conversation through the persistence resolver.
119
+ - **Reading media back:** a message's `media` block has `kind`, `mode`, `mimeType`, `name`, `size`,
120
+ `sha256`, and `ref` (kept copy) or `uri` (link). Get bytes with
121
+ `(agent.media.store ?? agent.persistence.media).get(ref)`. Delete bytes with `agent.deleteMedia(ref)`
122
+ (history keeps the metadata) or `agent.deleteMediaForConversation(id)`.
123
+ - **Search (10):** message search stays over text and pasted text. Files have their own listing and
124
+ search over name, kind, MIME type and size: `agent.persistence.files.list({ agentConversationId })`,
125
+ `files.search({ text: "report" })`.
126
+ - **Media the agent sends** (images, audio, links, embedded files) is recorded the same way and comes
127
+ back as `result.messages[].parts`; `text` stays the text-only view.
128
+ - **Shared directories:** `conversationDefaults: { additionalDirectories: ["/srv/files"] }` declares
129
+ directories to the harness, which applies its own permissions to links outside the workspace.
130
+ - Media is recorded on Agent-owned conversations only. The `SessionManager` / JSONL path can send parts
131
+ and records a line per part (`[image chart.png]`).
132
+
133
+ **For agents-core:** with `keep: true` copies (or links into the shared directory) the
134
+ `chat-attachments` store and the operation-id join in `identity-store.ts` and `hub/index.ts` can go.
135
+ `session.prompt({ text, attachments })` keeps working as before (attachments become `keep: false`
136
+ copies), so this can be done later.
137
+
138
+ ### 8. Out-of-band messages with media, delivered once
139
+
140
+ ```ts
141
+ await agent.conversations.appendAssistantMessage(conversationId, {
142
+ parts: [
143
+ { kind: "text", text: "Here is the chart I sent you on Telegram" },
144
+ { kind: "image", data: bytes, mimeType: "image/png", name: "chart.png" },
145
+ ],
146
+ });
147
+ ```
148
+
149
+ - `text` alone still works; media-only messages are allowed.
150
+ - The next successful turn delivers it once, in a `<messages-you-sent>` block, media included. After
151
+ that it is ordinary history.
152
+ - If the agent can't take a part's kind, or its bytes are gone, the part is named instead
153
+ (`[image chart.png: not supported by this agent]`), so the turn never fails because of it.
154
+ - Parts that aren't kept wait in memory until delivered. After a restart such a copy is named
155
+ (`[image chart.png: not available]`).
156
+
157
+ ### 13. Live message completion
158
+
159
+ No separate event: a message's record turns `completed` when the next message or a tool call starts
160
+ (see 5), and `agent.events` publishes that record as it commits.
161
+
162
+ ### Not done, or done differently
163
+
164
+ | # | requirement | status |
165
+ |---|---|---|
166
+ | 2 | paging by operations | done by agent messages instead (above) |
167
+ | 9 | persist agent capabilities | not stored: they come from `initialize`, so start the session to read them |
168
+ | 11 | Claude thinking rarely persisted | not investigated yet |
169
+ | 12 | Codex steer handover delay | not investigated yet; it may be in agents-core rather than the library |
170
+ | 13 | live completion event | done through the completed record, no event |
171
+
172
+ ## Also new since 0.10.2, not breaking
173
+
174
+ - Adopting a session the provider already holds: `agent.conversations.create({ adopt })`, with an
175
+ optional recap, and `listProviderSessions()` to choose one.
176
+ - Per-conversation persistence through a resolver (capture, audit, metering retention).
177
+ - `agent.conversations.clearTranscript(id)` and `agent.conversations.delete(id)`, optionally at the
178
+ provider.
179
+ - Operation visibility: the current operation's stage and last output time on conversation state.
180
+ - Codex per-turn usage counters in metering.
181
+
182
+ ## Known gaps
183
+
184
+ - The media probes on real harnesses ran before the last fix to embedded copies' uri, and need a rerun.
185
+ - Codex's tool output (sent through `_meta` terminal chunks) is not captured yet: its tool calls show
186
+ empty output.
187
+ - Claude's adapter silently drops binary embedded files (PDFs): its `promptToClaude` has no branch for
188
+ blobs. Send them as links (`mode: "link"`); Claude's Read tool opens PDFs. A fix belongs upstream
189
+ (map a PDF blob to an Anthropic `document` block).
package/README.md CHANGED
@@ -326,9 +326,12 @@ const session = await AgentSession.create({
326
326
 
327
327
  await session.prompt("Start working on the auth module.");
328
328
 
329
- // later. List everything we know about, catalog ∪ the agent's live list
330
- for (const s of await session.listSessions()) {
331
- console.log(s.source, s.agentSessionId, s.title); // source: "catalog" | "agent" | "both"
329
+ // later. List the two separately through an Agent (`Agent.open`, see the consumer guide);
330
+ // the merged `session.listSessions()` is deprecated
331
+ const { conversations } = await agent.conversations.list(); // our catalog
332
+ for (const c of conversations) console.log(c.agentConversationId, c.agentSessionId, c.title);
333
+ for (const s of await agent.conversations.listProviderSessions()) { // the harness's own sessions
334
+ console.log(s.providerSessionId, s.title, s.adoptedBy); // adoptedBy: the conversation that owns it, if any
332
335
  }
333
336
 
334
337
  await session.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlairoslabs/acp-client",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Embeddable Agent Client Protocol (ACP) client library with degraded PTY fallback.",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
@@ -35,7 +35,10 @@
35
35
  "src",
36
36
  "CONSUMER_GUIDE.md",
37
37
  "CHANGELOG-audit.md",
38
- "CHANGELOG-metering.md"
38
+ "CHANGELOG-metering.md",
39
+ "CHANGELOG-operation-lifecycle.md",
40
+ "CHANGELOG-consumer-fixes.md",
41
+ "MIGRATION-0.10-to-0.12.md"
39
42
  ],
40
43
  "exports": {
41
44
  ".": "./src/index.ts",
package/src/adapters.ts CHANGED
@@ -1,8 +1,10 @@
1
- // Adapters carry ONLY what's needed to LAUNCH the connection — the command.
1
+ // Adapters carry the launch command and the grace for terminating an unresponsive harness.
2
2
  // Everything else (auth methods, capabilities, features) is DISCOVERED from initialize.
3
3
  // See SPEC.md "Adapters" + "Core principles".
4
4
 
5
5
  export interface Adapter {
6
+ /** Maximum cancellation wait before terminating this provider process. */
7
+ cancelGraceMs?: number;
6
8
  /** The command to spawn the ACP agent binary, e.g. ["kimi", "acp"]. */
7
9
  command: string[];
8
10
  /**
@@ -0,0 +1,47 @@
1
+ import type { AgentConversationId } from "../../agent-ids.ts";
2
+ import { createConversationRecoveryCheckpointId } from "../../checkpointing/ids.ts";
3
+ import type { ConversationRecoveryCheckpointRepository } from "../../checkpointing/contracts.ts";
4
+
5
+ /** Messages left after the floor, so a recovery or a first checkpoint still sees the end of the history. */
6
+ export const DEFAULT_ADOPTION_TAIL_MESSAGES = 50;
7
+
8
+ export interface AdoptionRecapPlacement {
9
+ readonly summary: string;
10
+ /** Sequence of the stored recap message. */
11
+ readonly sequence: number;
12
+ }
13
+
14
+ /**
15
+ * Where checkpointing starts for an adopted conversation, so that nothing ever summarizes the history that
16
+ * came before it. Summarizing stored records is a prompt, and a long history does not fit one (a harness
17
+ * refuses a message past about a million characters), so the floor sits `tailMessages` before the end of
18
+ * what is stored: the recap's own message when that is later, so a conversation whose history is short
19
+ * keeps the recap as the first thing it recovers from.
20
+ *
21
+ * With a recap the checkpoint's summary is the recap, which covers the whole provider history; without one the
22
+ * checkpoint is a baseline with no summary, and recovery seeds only the messages after it. A conversation
23
+ * with no recap and no more than `tailMessages` stored messages has nothing to place a floor under, and gets
24
+ * none: its first scheduled checkpoint summarizes those few messages.
25
+ *
26
+ * The checkpoint schedule counts responses after the stored history, so an import does not use up the
27
+ * milestones a new conversation starts with.
28
+ */
29
+ export async function publishAdoptionFloor(
30
+ repository: ConversationRecoveryCheckpointRepository,
31
+ conversationId: AgentConversationId,
32
+ options: { readonly recap?: AdoptionRecapPlacement; readonly tailMessages?: number },
33
+ ): Promise<boolean> {
34
+ const tail = Math.max(0, options.tailMessages ?? DEFAULT_ADOPTION_TAIL_MESSAGES);
35
+ const lastSequence = await repository.latestMessageSequence(conversationId);
36
+ const floor = Math.max(options.recap?.sequence ?? 0, lastSequence - tail);
37
+ if (floor < 1) return false;
38
+ await repository.publish({
39
+ checkpointId: createConversationRecoveryCheckpointId(),
40
+ agentConversationId: conversationId,
41
+ coveredSequence: floor,
42
+ source: options.recap ? "adoption_recap" : "adoption_baseline",
43
+ summary: options.recap?.summary ?? "",
44
+ responsesCountedAfterSequence: lastSequence,
45
+ });
46
+ return true;
47
+ }
@@ -1,7 +1,9 @@
1
1
  export { DEFAULT_RECAP_TAIL_TURNS, normalizeAdoption } from "./config.ts";
2
2
  export { RECAP_INSTRUCTION, RECAP_ORIGIN } from "./recap.ts";
3
3
  export type { AdoptProviderSessionConfig, NormalizedAdoption } from "./config.ts";
4
- export { turnsFromReplay, selectTail } from "./replay.ts";
4
+ export { turnsFromReplay, selectTail, withoutRecapTurns } from "./replay.ts";
5
+ export { publishAdoptionFloor, DEFAULT_ADOPTION_TAIL_MESSAGES } from "./checkpoint-floor.ts";
6
+ export type { AdoptionRecapPlacement } from "./checkpoint-floor.ts";
5
7
  export { deleteProviderSession } from "./provider-session-delete.ts";
6
8
  export { listProviderSessions, DEFAULT_PROVIDER_SESSION_LIMIT } from "./provider-sessions.ts";
7
9
  export type { ListProviderSessionsOptions, ProviderSessionListing, ProviderSessionSummary } from "./provider-sessions.ts";
@@ -1,4 +1,5 @@
1
1
  import type { ActivityEvent } from "../../types.ts";
2
+ import { RECAP_INSTRUCTION } from "./recap.ts";
2
3
  import { extractResponseChunk, toActivityEvent } from "../../updates.ts";
3
4
 
4
5
  /** One piece of an imported turn, in the order the provider replayed it. */
@@ -33,6 +34,7 @@ export function turnsFromReplay(notifications: readonly unknown[]): ImportedTurn
33
34
  if (!update || typeof update.sessionUpdate !== "string") continue;
34
35
 
35
36
  const response = extractResponseChunk(update as never);
37
+ if (response?.part) continue; // Loaded media is already history; do not import duplicate copies.
36
38
  if (response) {
37
39
  if (!current) {
38
40
  current = { items: [] };
@@ -82,3 +84,16 @@ export function turnsFromReplay(notifications: readonly unknown[]): ImportedTurn
82
84
  export function selectTail(turns: readonly ImportedTurn[], last: number | undefined): ImportedTurn[] {
83
85
  return last === undefined ? [...turns] : turns.slice(-last);
84
86
  }
87
+
88
+ /**
89
+ * Drop the turns that are an earlier adoption's recap: the question is a turn of the provider's own history
90
+ * once it has been asked, so a later adoption of the same session replays it. It is not something the
91
+ * participants said, and the answer is the recap, which this adoption makes (or does not) for itself.
92
+ */
93
+ export function withoutRecapTurns(turns: readonly ImportedTurn[]): ImportedTurn[] {
94
+ const question = RECAP_INSTRUCTION.trim();
95
+ return turns.filter((turn) => {
96
+ const first = turn.items.find((item) => item.kind === "user");
97
+ return !(first && first.text.trim() === question);
98
+ });
99
+ }
@@ -1,3 +1,4 @@
1
+ import type { OperationLifecycleConfig } from "../operations/contracts.ts";
1
2
  import type * as schema from "@agentclientprotocol/sdk";
2
3
  import type { AgentConversationId, AgentSessionId } from "../agent-ids.ts";
3
4
  import type { AgentAdapterRegistration } from "../agent-adapter-registry.ts";
@@ -28,6 +29,7 @@ import type {
28
29
  import type { AppendAssistantMessageInput } from "../out-of-band-messages.ts";
29
30
  import type { ConversationPersistenceResolver } from "./persistence-policy/index.ts";
30
31
  import type { AdoptProviderSessionConfig, ListProviderSessionsOptions, ProviderSessionSummary } from "./adoption/index.ts";
32
+ import type { MediaConfig } from "../media/store.ts";
31
33
 
32
34
  export type AgentPersistenceConfig =
33
35
  | {
@@ -60,6 +62,8 @@ export type AgentConversationRuntimeDefaults = Omit<
60
62
  >;
61
63
 
62
64
  export interface AgentConfig {
65
+ readonly media?: MediaConfig;
66
+ readonly operationLifecycle?: OperationLifecycleConfig;
63
67
  readonly id?: AgentSessionId;
64
68
  readonly persistence: AgentPersistenceConfig;
65
69
  readonly adapters: Readonly<Record<string, import("../adapters.ts").Adapter>>