operon-managed-agents 0.1.0-alpha.30 → 0.1.0-alpha.31

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 (36) hide show
  1. package/README.md +141 -107
  2. package/dist/client/client.d.ts +57 -38
  3. package/dist/client/client.js +141 -117
  4. package/dist/client/errors.js +1 -1
  5. package/dist/client/run.d.ts +24 -29
  6. package/dist/client/run.js +45 -103
  7. package/dist/protocol/types.d.ts +185 -87
  8. package/dist/protocol/types.js +12 -0
  9. package/dist/server/broadcast.d.ts +11 -11
  10. package/dist/server/errors.d.ts +2 -1
  11. package/dist/server/errors.js +5 -5
  12. package/dist/server/http-server.d.ts +20 -18
  13. package/dist/server/http-server.js +120 -179
  14. package/dist/server/idempotency.d.ts +3 -3
  15. package/dist/server/inbox.d.ts +18 -56
  16. package/dist/server/inbox.js +1 -91
  17. package/dist/server/metadata-pg.d.ts +3 -1
  18. package/dist/server/metadata-pg.js +7 -0
  19. package/dist/server/metadata.d.ts +11 -0
  20. package/dist/server/metadata.js +11 -1
  21. package/dist/server/registries.d.ts +7 -7
  22. package/dist/server/request-schemas.d.ts +81 -136
  23. package/dist/server/request-schemas.js +33 -48
  24. package/dist/server/session-service.d.ts +63 -150
  25. package/dist/server/session-service.js +243 -492
  26. package/dist/server/session-worker.d.ts +55 -74
  27. package/dist/server/session-worker.js +459 -331
  28. package/dist/server/wire-events.d.ts +44 -0
  29. package/dist/server/wire-events.js +247 -0
  30. package/dist/server/work-memory.d.ts +17 -10
  31. package/dist/server/work-memory.js +81 -26
  32. package/dist/server/work-pg.d.ts +21 -17
  33. package/dist/server/work-pg.js +127 -20
  34. package/dist/server/work.d.ts +54 -21
  35. package/dist/server/work.js +10 -1
  36. package/package.json +4 -3
package/README.md CHANGED
@@ -1,147 +1,181 @@
1
1
  # operon-managed-agents
2
2
 
3
- Managed HTTP/SSE server and TypeScript client for `operon-agents`. One package contains
4
- three public surfaces:
3
+ Managed HTTP/SSE server and TypeScript client for `operon-agents`, with an API shaped after
4
+ Claude Managed Agents. One package contains three public surfaces:
5
5
 
6
6
  - `operon-managed-agents/protocol` — wire/resource types and SSE codec
7
- - `operon-managed-agents/server` — Session host, registries and HTTP server
7
+ - `operon-managed-agents/server` — session service, worker, work table and HTTP server
8
8
  - `operon-managed-agents/client` — typed client SDK
9
9
 
10
- The wire contract deliberately separates writes from observation. `messages.create()`
11
- returns an acceptance receipt immediately; `events.stream()` is a session-scoped stream
12
- that survives individual turns and therefore carries background completion and idle-wake
13
- events too.
10
+ ## The API
11
+
12
+ | Route | Client |
13
+ | --- | --- |
14
+ | `POST /v1/sessions` | `sessions.create({ agent, environment_id, title?, metadata?, initial_events? })` |
15
+ | `GET /v1/sessions` | `sessions.list({ limit?, page?, order? })` |
16
+ | `GET /v1/sessions/{id}` | `sessions.retrieve(id)` |
17
+ | `POST /v1/sessions/{id}` | `sessions.update(id, { title?, metadata? })` |
18
+ | `POST /v1/sessions/{id}/archive` | `sessions.archive(id)` |
19
+ | `DELETE /v1/sessions/{id}` | `sessions.delete(id)` |
20
+ | `POST /v1/sessions/{id}/events` | `sessions.events.send(id, { events })` |
21
+ | `GET /v1/sessions/{id}/events` | `sessions.events.list(id, { limit?, page?, order? })` |
22
+ | `GET /v1/sessions/{id}/events/stream` | `sessions.events.stream(id, { event_deltas? })` |
23
+
24
+ Work enters a session as **user events** — `user.message`, `user.interrupt`,
25
+ `user.tool_confirmation`, `user.custom_tool_result` — and everything the agent does comes back
26
+ as **session events**: `agent.message`, `agent.tool_use`, `agent.custom_tool_use`,
27
+ `agent.tool_result`, `span.model_request_start` / `span.model_request_end` (one pair per model
28
+ request, the end carrying `model_usage` and `is_error`), `session.status_running`,
29
+ `session.status_idle` (with a `stop_reason` of
30
+ `end_turn` or `requires_action`), `session.status_rescheduled` and `session.error`. Every
31
+ event has an `id` and a `processed_at`: a sent event comes back with `processed_at: null` and
32
+ shows a timestamp once a worker has dealt with it. Errors are Anthropic-shaped:
33
+ `{ type: "error", error: { type, message } }`.
14
34
 
15
35
  ```ts
16
- const session = await client.sessions.create({
17
- agent: "default",
18
- environment: "workspace",
19
- });
36
+ const session = await client.sessions.create({ agent: "default", environment_id: "workspace" });
20
37
 
38
+ // Live-only: open the stream before sending, or what happens in between is missed.
21
39
  const stream = await client.sessions.events.stream(session.id);
22
- await client.sessions.messages.create(session.id, { input: "inspect this repository" });
40
+ await client.sessions.events.send(session.id, {
41
+ events: [{ type: "user.message", content: [{ type: "text", text: "inspect this repository" }] }],
42
+ });
23
43
 
24
- for await (const event of stream) console.log(event);
44
+ for await (const event of stream) console.log(event.type);
25
45
  ```
26
46
 
27
- The external observation API has two deliberately separate operations:
47
+ Creating a session without `initial_events` starts nothing and provisions nothing. A
48
+ `user.message` sent while the agent runs is taken at its next step boundary; one sent while
49
+ the session waits on a confirmation is held until the confirmation is answered. A
50
+ `requires_action` idle names the blocking `agent.tool_use` events in `stop_reason.event_ids`;
51
+ answer each with `{ type: "user.tool_confirmation", tool_use_id, result: "allow" | "deny" }`,
52
+ or an `agent.custom_tool_use` with `{ type: "user.custom_tool_result", custom_tool_use_id,
53
+ content }`; when the paused call asked questions (`AskUserQuestion`), the text answers each of
54
+ them as a freeform answer.
55
+ `user.interrupt` stops the run, and what was sent before it but not yet taken is dropped.
28
56
 
29
- - `sessions.events.list()` pages persisted history as `AgentEvent[]`; `nextPage` is opaque.
30
- - `sessions.events.stream()` is a pure live `AsyncIterable<AgentEvent>` with no synthetic first event.
57
+ `sessions.events.stream()` carries only what is emitted after it opens. On a dropped connection
58
+ the client reconnects by itself, fills the gap from `sessions.events.list()` and skips what it
59
+ already delivered; pass `reconnect: false` to see drops yourself.
31
60
 
32
- Every event has a stable `eventId`. Durable events keep that same identity in `list()` and
33
- `stream()`, so a reconnecting client can open the stream first, page history second, and
34
- deduplicate the overlap without a loss window. Low-frequency lifecycle events needed to
35
- rebuild state (`agent.*`, `turn.*`, pauses, messages and workflow journal progress) are
36
- persisted before publication in managed sessions. High-frequency deltas and progress are
37
- live-only: a client that joins midway reconstructs the committed structural state from
38
- `list()` and continues transient rendering from `stream()`.
61
+ ### Live previews
39
62
 
40
- `SessionProjection` remains the standard reducer from `AgentEvent` to state-shaped UI data.
41
- It is not exposed as a separate managed snapshot endpoint: fold the stream into a projection.
42
-
43
- The stream replays the session's durable history first and then follows live, so one
44
- subscription is the whole story. It carries a durable cursor — the SSE `id:` is stamped only
45
- on events the log can find again, never on a token delta — and the client reconnects on a
46
- dropped connection by itself, resuming after the last durable event it delivered and filtering
47
- the overlap by `eventId`. Pass `after` to start from a cursor you kept, or `reconnect: false`
48
- to see drops yourself.
63
+ By default `agent.message` arrives whole, once the model has finished it. To render text as it is
64
+ generated, opt in per connection with `event_deltas` (on the wire, `event_deltas[]=agent.message`,
65
+ repeated per type), as in Claude Managed Agents:
49
66
 
50
67
  ```ts
51
- const stream = await client.sessions.events.stream(session.id);
52
- const projection = new SessionProjection(session.id);
53
-
68
+ const stream = await client.sessions.events.stream(session.id, { event_deltas: ["agent.message"] });
69
+ const previews = new Map<string, string[]>();
54
70
  for await (const event of stream) {
55
- projection.apply(event);
56
- render(projection.snapshot());
71
+ if (event.type === "event_start") previews.set(event.event.id, []);
72
+ else if (event.type === "event_delta") {
73
+ const blocks = previews.get(event.event_id);
74
+ if (blocks) blocks[event.delta.index] = (blocks[event.delta.index] ?? "") + event.delta.content.text;
75
+ } else if (event.type === "agent.message") previews.delete(event.id); // authoritative; render this
76
+ else if (event.type === "span.model_request_end" || event.type === "session.status_rescheduled") {
77
+ previews.clear(); // still open = never delivered: drop or mark it
78
+ }
57
79
  }
58
- // stream.lastEventId is the cursor to continue from elsewhere.
59
- ```
60
-
61
- `sessions.update(id, { title })` renames a session (`PATCH /v1/sessions/{id}`); the title is the
62
- only field a client can change after creation, and it is durable before the call resolves.
63
-
64
- `run()` sends one input and resolves when the turn that took **that** delivery ends — not the
65
- first `turn.ended` in the replay, which on a session with history belongs to an older turn.
66
-
67
- The server accepts an `authorize(request, { action, sessionId, origin })` hook. Configure it for any
68
- networked deployment; it can verify credentials and enforce per-session ownership. The
69
- bundled in-memory idempotency store is atomic within one process and bounded by TTL/capacity;
70
- distributed deployments should provide a database-backed `ManagedDeliveryIdempotencyStore`.
71
-
72
- The service and the workers share one **work table** (`SessionWork`): one row per session that
73
- has been appended to or is being run. `work.append` writes an input to the session's log and
74
- wakes its row as one step — in Postgres, one transaction — and a worker's claim loop
75
- (`worker.start()`) takes woken rows, one indexed statement per ask (`FOR UPDATE SKIP LOCKED`).
76
- Taking the row *is* the lease: one runtime owner per session, with a fencing token, and no
77
- dispatcher anywhere. Workers only make outbound calls; nothing needs to know which node holds
78
- a session.
79
-
80
- Cancel and resume are journaled commands written the same way. The holder learns of them from
81
- its heartbeat — every lease renew reports whether anything was appended since the last one —
82
- so a command accepted on any node reaches the turn running on any other within one renew
83
- interval (2s by default). With no holder, the next claim reads them first.
84
-
85
- An input is processed once it is in the conversation: the worker's cursor advances when the
86
- session's record holds the message, not when the turn that took it finishes. A turn that fails
87
- or dies halfway leaves the history intact up to where it stopped, and the next message
88
- continues from there; nothing is re-run and nothing runs twice. A worker that dies leaves its
89
- row held past the TTL; the claim loop takes such a row like any other, closes the turn it left
90
- open (`turn.ended`, reason `failed`) and broadcasts the close, so a client waiting on it learns
91
- within a TTL rather than whenever the next message happens to arrive.
92
-
93
- In one process, `MemorySessionWork` — the service and the worker must share the instance.
94
- Across nodes, `PgSessionWork` over the same Postgres the log lives in (run
95
- `sessionWorkTableDDL()` once); no queue, no broker, no other component. An accepted input is
96
- durable and woken before its 202; the in-process nudge after it is latency, not correctness.
97
-
98
- Pass an idempotency key when an HTTP retry must not inject the same user message twice:
99
-
100
- ```ts
101
- await client.sessions.messages.create(
102
- session.id,
103
- { input: "continue" },
104
- { idempotencyKey: requestId },
105
- );
106
80
  ```
107
81
 
108
- Whose words a delivery is, the caller says. The party holding a session's credential is its
109
- user — the way a local session's stdin is — so by default `messages.create` delivers the
110
- caller's own words and the model sees them bare, as a prompt. A caller relaying someone else's
111
- words declares it:
82
+ `event_start` names the id the buffered `agent.message` will have, and every `event_delta`
83
+ carries it; concatenated per `delta.index`, the deltas are a prefix of that block's text. Order
84
+ on one connection is `session.status_running` → `span.model_request_start` → `event_start` →
85
+ `event_delta`* → `agent.message` → `span.model_request_end`. Previews are best effort and live only: never in `events.list()`, never
86
+ replayed on reconnect, not delivered for a message already in progress when the connection
87
+ opened, and shed (the rest of that message's deltas) when a connection falls too far behind.
88
+ A preview can outlive its message: the message is persisted only once the model has finished
89
+ it, so a request that fails, is retried or is cut short after streaming leaves a preview that is
90
+ never reconciled. Its `span.model_request_end` still arrives, with `is_error: true`, after any
91
+ message the request did produce — so a preview still open at the end of its request is over.
92
+ If the worker itself goes away mid-request, no end comes; `session.status_rescheduled` says the
93
+ next worker starts the request over. Only `agent.message` and `agent.thinking` are accepted,
94
+ at most 100 values, otherwise the stream answers 400; `agent.thinking` yields nothing, since
95
+ sessions do not emit it. Previews reach other processes only through a cross-process
96
+ broadcaster (`RedisEventBroadcaster`).
97
+
98
+ `run(client, sessionId, text)` sends one message and resolves when the agent is done with
99
+ **that** message — not at the idle of a turn that was already running when it was sent — and
100
+ answers `requires_action` through `onInterrupt`, or rejects at once without one.
101
+
102
+ Pass an idempotency key when an HTTP retry must not send the same events twice:
112
103
 
113
104
  ```ts
114
- await client.sessions.messages.create(session.id, {
115
- input: "deploy finished: 3 warnings",
116
- origin: "external",
117
- source: "ci",
118
- actor: "deploy-bot",
119
- });
105
+ await client.sessions.events.send(session.id, { events }, { idempotencyKey: requestId });
120
106
  ```
121
107
 
122
- The model then sees the text inside an `<external-message>` envelope stamped as not from the
123
- user — not an approval, not an answer to anything it asked. `source`, `actor` and `metadata`
124
- describe the relay and are refused without the declaration. Declaring `external` lowers trust,
125
- so it needs no permission of its own; the `authorize` hook receives `origin` on
126
- `messages.create`, and a deployment that hands a credential to something that only relays (a
127
- webhook bridge, a teammate agent) can refuse it anything else.
108
+ The server requires an `authorize(request, { action, sessionId })` hook. Configure it for any
109
+ networked deployment; it can verify credentials and enforce per-session ownership.
110
+ `SessionService({ validateCreate })` refuses an unknown agent or environment id before a
111
+ session is recorded. The bundled in-memory idempotency store is atomic within one process;
112
+ distributed deployments should provide a shared `ManagedDeliveryIdempotencyStore`.
113
+
114
+ ## How work reaches a worker
115
+
116
+ The API and the workers share exactly one thing: the **work table** (`SessionWork`). It holds
117
+ each session's managed event log — what was sent and what the session emitted, in the managed
118
+ vocabulary — and its lease. The API never writes into the framework's journal and never holds a
119
+ reference to a worker, not even in one process.
120
+
121
+ - **Accepting** an event persists it and wakes its session in one commit, before the response.
122
+ - **Idle workers claim.** `worker.start()` runs a claim loop that takes woken sessions, one
123
+ indexed statement per ask (`FOR UPDATE SKIP LOCKED` in Postgres). Taking the row *is* the
124
+ lease: one runtime owner per session, with a fencing token, and no dispatcher.
125
+ - **Holders pull.** A worker holding a session polls its pending events every
126
+ `inputPollIntervalMs` (500ms by default) while the agent runs, and hands them to the Harness
127
+ through its public interface: `steerTo` for a message, `cancel` for an interrupt, `respond`
128
+ for an answer. The first claim creates the runtime session; later ones reopen it.
129
+ - **Output** is translated to managed events on the worker, recorded in the history under the
130
+ lease, and broadcast (`MemoryEventBroadcaster` in one process, `RedisEventBroadcaster` across
131
+ nodes) for the SSE endpoint to forward.
132
+
133
+ A message is **processed** once it is in the conversation, not when it was pulled: a worker that
134
+ dies holding it leaves it pending, and the next holder delivers it. One that dies after the
135
+ conversation took it is recognised by the next holder in the transcript, marked, and not
136
+ delivered twice; if the turn it started never finished, the next holder continues it
137
+ (`session.status_rescheduled`). A worker that dies leaves its lease to lapse; the session reads
138
+ `rescheduling` meanwhile, and the next claim tells watchers the turn stopped.
139
+
140
+ In one process, `MemorySessionWork`. Across nodes, `PgSessionWork` (run `sessionWorkTableDDL()`
141
+ once); no queue, no broker, no other component. `test/e2e-pg-real.ts` runs its statements
142
+ against a real Postgres when `MANAGED_PG_URL` is set.
128
143
 
129
144
  A worker serves many tenants by default, and refuses what would leak between them or run outside
130
145
  the sandbox: a session whose environment does not come from the environment registry, a harness
131
146
  holding process-wide MCP connections or an OAuth service, MCP over stdio, and a token read from
132
- the process environment. A self-hosted, one-owner deployment says so —
147
+ the process environment. Isolation is stated once, on the harness, not on each open: a
148
+ multi-tenant worker requires `config.policy.strictIsolation: true` and
149
+ `config.eventPublication: "committed"` and refuses to construct on a harness without them. It also
150
+ refuses any session on that harness it did not open itself under a lease, so an extension cannot
151
+ create or wake one behind its back. A self-hosted, one-owner deployment says so —
133
152
  `new SessionWorker({ profile: "single-tenant", … })` — and the worker logs that it did.
134
153
 
135
- What a host decides per tenant goes through the registries, which are told whose session they
136
- resolve for: `resolve(ref, { sessionId, ownerKey, metadata })`. `ownerKey` is stamped by the
137
- service and trustworthy; `metadata` came from the client. Per-user MCP credentials — a vault —
154
+ ```ts
155
+ const harness = createHarness({
156
+ config: {
157
+ defaults: { model: "anthropic/claude-opus-4-8" },
158
+ policy: { strictIsolation: true }, // every session on its own environment, http-only MCP
159
+ eventPublication: "committed", // an event is durable before anyone sees it
160
+ },
161
+ infrastructure: () => ({ sessionRepository }),
162
+ });
163
+ ```
164
+
165
+ What a host decides per tenant goes through the registries, which the worker asks on every open
166
+ and which are told whose session they resolve for: `resolve(ref, { sessionId, ownerKey, metadata })`.
167
+ The agent registry returns `{ config, bindings }` — the session's configuration as data, and the
168
+ live objects it runs on — and the worker passes both on every open, the first included, so the
169
+ configuration is the host's to keep: change what the registry returns and the next open runs on it.
170
+ `ownerKey` is stamped by the service and trustworthy; `metadata` came from the client. Per-user MCP credentials — a vault —
138
171
  are a provider the agent registry hands out, asked on every connect:
139
172
 
140
173
  ```ts
141
174
  const agents: ManagedAgentRegistry = {
142
175
  resolve: (_ref, { ownerKey }) => ({
143
- resumeOptions: {
144
- mcpServers: { linear: { transport: "http", url: "https://mcp.linear.app/mcp" } },
176
+ // The complete set of MCP servers this session sees.
177
+ config: { mcp: { servers: { linear: { transport: "http", url: "https://mcp.linear.app/mcp" } } } },
178
+ bindings: {
145
179
  mcpCredentials: {
146
180
  credentialsFor: async ({ url }) => {
147
181
  const token = await vault.tokenFor(ownerKey!, url); // the host's store, refresh, lock
@@ -1,66 +1,86 @@
1
- import type { AgentEvent, InterruptAnswer } from "operon-agents";
1
+ /**
2
+ * A TypeScript client for the managed API, shaped after the Claude SDK's managed-agents surface:
3
+ * `sessions.create/retrieve/list/update/archive/delete` and
4
+ * `sessions.events.send/list/stream`.
5
+ */
2
6
  import { type SseFrame } from "../protocol/sse.ts";
3
- import type { CancelManagedSessionResponse, CreateManagedMessageRequest, CreateManagedSessionRequest, MessageReceiptResource, InterruptionsResponse, ListSessionEventsOptions, ListSessionEventsResponse, ListManagedSessionsResponse, ManagedSession, ResumeManagedSessionResponse, StreamSessionEventsOptions, UpdateManagedSessionRequest } from "../protocol/types.ts";
7
+ import type { CreateManagedSessionRequest, ListManagedSessionsOptions, ListManagedSessionsResponse, ListSessionEventsOptions, ListSessionEventsResponse, ManagedEventResource, ManagedPreviewableEventType, ManagedSessionResource, ManagedStreamEvent, SendManagedEventsRequest, SendManagedEventsResponse, StreamSessionEventsOptions, UpdateManagedSessionRequest } from "../protocol/types.ts";
4
8
  export interface ManagedAgentsClientOptions {
5
9
  readonly baseUrl: string;
6
10
  readonly apiKey?: string;
7
11
  readonly headers?: Readonly<Record<string, string>>;
8
12
  readonly fetch?: typeof globalThis.fetch;
9
13
  }
10
- export interface CreateManagedMessageOptions {
14
+ export interface SendManagedEventsOptions {
15
+ /** Retries with the same key are accepted once. */
11
16
  readonly idempotencyKey?: string;
12
17
  }
13
- /** Opens one SSE connection, resuming after `after` when given. */
14
- type StreamConnector = (after: string | undefined) => Promise<AsyncIterator<SseFrame>>;
18
+ type Connect = () => Promise<AsyncIterator<SseFrame>>;
19
+ type History = (page: string | undefined) => Promise<ListSessionEventsResponse>;
15
20
  /**
16
- * A session's events as one continuous iterable, across however many connections it takes.
21
+ * A session's live events as one continuous iterable, across however many connections it takes.
22
+ *
23
+ * The server's stream is live-only, so a dropped connection loses whatever was emitted while it
24
+ * was down. By default this reconnects and fills that gap from the event history — newest first,
25
+ * back to the last output it delivered — skipping ids it has already delivered.
17
26
  *
18
- * A dropped connection is not the end of the session, so by default it is not the end of the
19
- * iteration either: the stream reopens after the last durable event it delivered and filters
20
- * out what the overlap repeats. The cursor is the SSE `id:` the server stamps on durable events
21
- * only, so resuming never points at a live-only event (a token delta) that the log cannot find.
27
+ * Opened with `event_deltas`, it also yields the live previews (`event_start` / `event_delta`)
28
+ * as they come. Those are never deduplicated or recovered: a drop loses the deltas in flight,
29
+ * and the buffered `agent.message` they preview arrives complete either way.
22
30
  */
23
- export declare class ManagedSessionEventStream implements AsyncIterable<AgentEvent> {
24
- private readonly connect;
25
- private readonly reconnect;
26
- private readonly signal;
31
+ export declare class ManagedSessionEventStream<E extends ManagedStreamEvent = ManagedEventResource> implements AsyncIterable<E> {
27
32
  private frames;
33
+ private readonly buffered;
28
34
  private consumed;
29
- private cursor;
35
+ /** The newest history event this stream has accounted for — where a gap fill stops. */
36
+ private anchor;
30
37
  private readonly delivered;
31
38
  private attempts;
32
- constructor(connect: StreamConnector, first: AsyncIterator<SseFrame>, options: {
33
- readonly after?: string;
34
- readonly reconnect?: boolean;
39
+ private readonly connect;
40
+ private readonly history;
41
+ private readonly options;
42
+ constructor(connect: Connect, history: History, first: AsyncIterator<SseFrame>, anchor: string | undefined, options: {
43
+ readonly reconnect: boolean;
35
44
  readonly signal?: AbortSignal;
36
45
  });
37
- /** The last resume cursor this stream delivered — pass it as `after` to continue elsewhere. */
38
- get lastEventId(): string | undefined;
39
- [Symbol.asyncIterator](): AsyncIterator<AgentEvent>;
46
+ [Symbol.asyncIterator](): AsyncIterator<E>;
40
47
  private next;
41
- /** Reconnect after a drop. False when reconnecting is off or the caller has aborted. */
48
+ private accept;
49
+ /** Reconnect after a drop, then queue what the history holds that the drop cost us. */
42
50
  private reopen;
43
- private remember;
51
+ private gap;
44
52
  }
45
53
  export declare class ManagedSessionsClient {
46
54
  private readonly root;
47
55
  constructor(root: ManagedAgentsClient);
48
- create(request: CreateManagedSessionRequest): Promise<ManagedSession>;
49
- list(): Promise<ListManagedSessionsResponse>;
50
- retrieve(sessionId: string): Promise<ManagedSession>;
51
- /** Rename a session; the new title is durable before this resolves. */
52
- update(sessionId: string, request: UpdateManagedSessionRequest): Promise<ManagedSession>;
53
- messages: {
54
- create: (sessionId: string, request: CreateManagedMessageRequest, options?: CreateManagedMessageOptions) => Promise<MessageReceiptResource>;
55
- };
56
- events: {
56
+ create(request: CreateManagedSessionRequest): Promise<ManagedSessionResource>;
57
+ list(options?: ListManagedSessionsOptions): Promise<ListManagedSessionsResponse>;
58
+ retrieve(sessionId: string): Promise<ManagedSessionResource>;
59
+ update(sessionId: string, request: UpdateManagedSessionRequest): Promise<ManagedSessionResource>;
60
+ archive(sessionId: string): Promise<ManagedSessionResource>;
61
+ delete(sessionId: string): Promise<{
62
+ readonly id: string;
63
+ readonly type: "session_deleted";
64
+ }>;
65
+ readonly events: {
66
+ send: (sessionId: string, request: SendManagedEventsRequest, options?: SendManagedEventsOptions) => Promise<SendManagedEventsResponse>;
57
67
  list: (sessionId: string, options?: ListSessionEventsOptions) => Promise<ListSessionEventsResponse>;
58
- stream: (sessionId: string, options?: StreamSessionEventsOptions) => Promise<ManagedSessionEventStream>;
68
+ /**
69
+ * Follow live events. Open it BEFORE sending: a stream carries only what is emitted after it
70
+ * opens. Resolves once subscribed.
71
+ */
72
+ stream: StreamEvents;
59
73
  };
60
- cancel(sessionId: string): Promise<CancelManagedSessionResponse>;
61
- delete(sessionId: string): Promise<void>;
62
- interruptions(sessionId: string): Promise<InterruptionsResponse>;
63
- resume(sessionId: string, answers: Readonly<Record<string, InterruptAnswer>>): Promise<ResumeManagedSessionResponse>;
74
+ }
75
+ /**
76
+ * `sessions.events.stream`. Typed by whether previews were asked for: without `event_deltas`
77
+ * the stream carries persisted events only, each with an `id`.
78
+ */
79
+ export interface StreamEvents {
80
+ (sessionId: string, options: StreamSessionEventsOptions & {
81
+ readonly event_deltas: readonly ManagedPreviewableEventType[];
82
+ }): Promise<ManagedSessionEventStream<ManagedStreamEvent>>;
83
+ (sessionId: string, options?: Omit<StreamSessionEventsOptions, "event_deltas">): Promise<ManagedSessionEventStream>;
64
84
  }
65
85
  interface RequestOptions {
66
86
  readonly method?: string;
@@ -75,7 +95,6 @@ export declare class ManagedAgentsClient {
75
95
  private readonly defaultHeaders;
76
96
  constructor(options: ManagedAgentsClientOptions);
77
97
  request<T>(path: string, options?: RequestOptions): Promise<T>;
78
- requestVoid(path: string, options?: RequestOptions): Promise<void>;
79
98
  raw(path: string, options?: RequestOptions): Promise<Response>;
80
99
  }
81
100
  export {};