@anthropic-ai/claude-agent-sdk 0.3.266 → 0.3.268

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/browser-sdk.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * Compiled by scripts/build-ant-sdk-typings.sh; see build-agent-sdk.sh for the
9
9
  * path rewrite and copy into the package.
10
10
  */
11
- import type { CanUseTool, HookCallbackMatcher, HookEvent, McpServerConfig, OnElicitation, OnUserDialog, Query, SDKUserMessage } from './agentSdkTypes.js';
11
+ import type { CanUseTool, HookCallbackMatcher, HookEvent, McpServerConfig, OnElicitation, OnUserDialog, Query, SDKMessage, SDKUserMessage } from './agentSdkTypes.js';
12
12
  export type { CanUseTool, ElicitationRequest, ElicitationResult, HookCallbackMatcher, HookEvent, McpSdkServerConfigWithInstance, McpServerConfig, OnElicitation, OnUserDialog, Query, SDKAssistantMessage, SDKMessage, SDKResultMessage, SDKSystemMessage, SDKUserMessage, UserDialogRequest, UserDialogResult, } from './agentSdkTypes.js';
13
13
  export { createSdkMcpServer, tool } from './agentSdkTypes.js';
14
14
  export type OAuthCredential = {
@@ -40,6 +40,40 @@ export type SSEOptions = {
40
40
  * surface (web / iOS / Android / desktop) itself.
41
41
  */
42
42
  headers?: Record<string, string>;
43
+ /**
44
+ * Resume cursor for the first connect: the stream delivers only events
45
+ * whose `sequence_num` is greater. For a consumer that seeded its
46
+ * transcript from the REST event list — pass the highest `sequence_num` it
47
+ * has already applied (for a query replacing an earlier one,
48
+ * `getSseLastSequenceNum()` of that query, which only ever covers messages
49
+ * it actually yielded). Omitted or 0 starts from the beginning of the
50
+ * retained stream.
51
+ */
52
+ fromSequenceNum?: number;
53
+ /**
54
+ * Called when the server reports (`catch_up_truncated`) that it could not
55
+ * replay every event after the resume cursor — the stream continues from a
56
+ * later point, so re-fetch the gap from the REST event list and reseed.
57
+ * Each occurrence is also counted in `getSseDropCounts()` under
58
+ * `catch_up_truncated`. Exceptions thrown by the handler are contained.
59
+ */
60
+ onCatchUpTruncated?: () => void;
61
+ /**
62
+ * Called for each `delivery_update` frame: the worker's acknowledgement of
63
+ * one event this session was sent (`event_id` — matches the `event_id` of
64
+ * that event's own durable echo, see `getCcrEvent()`), with the raw server
65
+ * status string — `"DELIVERY_STATUS_RECEIVED"`, `"DELIVERY_STATUS_PROCESSING"`
66
+ * (the worker began the turn) or `"DELIVERY_STATUS_PROCESSED"` (that turn
67
+ * ended); treat unknown values as informational — and the server
68
+ * `timestamp` when present. Not durable: a reconnect does not replay
69
+ * earlier updates. Malformed frames are counted in `getSseDropCounts()`
70
+ * under `malformed_delivery_update`; handler exceptions are contained.
71
+ */
72
+ onDeliveryUpdate?: (update: {
73
+ event_id: string;
74
+ status: string;
75
+ timestamp?: string;
76
+ }) => void;
43
77
  };
44
78
  type BrowserQueryOptionsBase = {
45
79
  prompt: AsyncIterable<SDKUserMessage>;
@@ -105,3 +139,46 @@ export declare const G4_TEXT_ENVELOPE_ARM_PORTED: boolean;
105
139
  * never frame contents). Returns undefined for WebSocket-transport queries.
106
140
  */
107
141
  export declare function getSseDropCounts(query: Query): Readonly<Record<string, number>> | undefined;
142
+ /**
143
+ * Resume cursor of a query() created with the `sse` transport: the highest
144
+ * `sequence_num` of a durable message this query has yielded (or the
145
+ * `fromSequenceNum` seed before any was). It is advanced immediately before
146
+ * each message is yielded, so while the consumer handles message `m` it is
147
+ * already `>= getCcrEvent(query, m).sequence_num`, and it never covers a
148
+ * message the consumer was not handed — frames still buffered when the
149
+ * consumer stops iterating, and durable events the SDK dropped or consumed
150
+ * internally, do not advance it. So at any point — mid-stream, after a
151
+ * `break`, or once the iterator has finished — it is where a REST catch-up
152
+ * fetch or a replacement query()'s `fromSequenceNum` should resume (the
153
+ * transport's own transparent reconnects use a separate internal wire
154
+ * cursor). Per-message ordering still reads `getCcrEvent(query, message)`.
155
+ * Returns undefined for WebSocket-transport queries and before any sequence
156
+ * number is known.
157
+ */
158
+ export declare function getSseLastSequenceNum(query: Query): number | undefined;
159
+ /**
160
+ * The wire envelope of the durable CCR event (SSE `client_event` frame) that
161
+ * delivered `message` on the `sse` query `query`: `sequence_num` is the
162
+ * session-wide order the server assigned, `event_id` is unique per event,
163
+ * `created_at` (RFC 3339 store time) and `source` (server-assigned channel,
164
+ * e.g. `worker`) appear when the frame carries them. Provenance contract:
165
+ * the transport records the envelope from the delivering frame, keyed by the
166
+ * exact message object it yields, and never writes it onto the message; a
167
+ * `ccr_event` field arriving inside any payload is a sender-authored claim
168
+ * and is stripped, so this accessor is the only way to read an envelope.
169
+ * Looked up by object identity — pass the message exactly as the query
170
+ * yielded it. Returns undefined for anything that transport did not itself
171
+ * yield from a durable frame: streaming deltas (`stream_event`,
172
+ * `system:thinking_tokens` are not sequenced), messages of a
173
+ * WebSocket-transport query, copies, and caller-constructed objects,
174
+ * regardless of the fields they carry. `sequence_num` is dense over ALL of
175
+ * the session's events, including control frames the SDK consumes
176
+ * internally and frames it drops, so consecutive yielded messages need not
177
+ * carry consecutive numbers.
178
+ */
179
+ export declare function getCcrEvent(query: Query, message: SDKMessage): {
180
+ event_id: string;
181
+ sequence_num: number;
182
+ created_at?: string;
183
+ source?: string;
184
+ } | undefined;