@ellipsis-dev/sdk 0.35.0 → 0.37.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.
@@ -1,4 +1,4 @@
1
- import { d2 as StreamFrame, cm as Session } from '../types-BrLpRRde.js';
1
+ import { cr as Session, d1 as StreamFrame } from '../types-BXbnHOQe.js';
2
2
 
3
3
  declare const WS_CLOSE_NORMAL = 1000;
4
4
  declare const WS_CLOSE_GOING_AWAY = 1001;
@@ -8,8 +8,7 @@ declare const WS_CLOSE_OVER_CAPACITY = 1013;
8
8
  declare function sessionStatusWord(session: Session): string;
9
9
  type StreamOutcome = {
10
10
  type: 'done';
11
- status: string;
12
- reason: string | null;
11
+ session: Session;
13
12
  } | {
14
13
  type: 'error';
15
14
  message: string;
@@ -5,7 +5,7 @@ var WS_CLOSE_AUTH_FAILED = 1008;
5
5
  var WS_CLOSE_SERVER_ERROR = 1011;
6
6
  var WS_CLOSE_OVER_CAPACITY = 1013;
7
7
  function sessionStatusWord(session) {
8
- return session.turn?.status ?? "none";
8
+ return session.status;
9
9
  }
10
10
  var StreamUnavailableError = class extends Error {
11
11
  constructor(message) {
@@ -85,20 +85,12 @@ function connectOnce(sock, emit, signal) {
85
85
  } catch {
86
86
  return;
87
87
  }
88
- if (!frame || ![
89
- "snapshot",
90
- "records_append",
91
- "session",
92
- "delta",
93
- "heartbeat",
94
- "done",
95
- "error"
96
- ].includes(frame.type))
88
+ if (!frame || !["session", "records", "delta", "heartbeat", "error"].includes(
89
+ frame.type
90
+ ))
97
91
  return;
98
92
  emit(frame);
99
- if (frame.type === "done") {
100
- finish({ kind: "done" });
101
- } else if (frame.type === "error") {
93
+ if (frame.type === "error") {
102
94
  finish({
103
95
  kind: "frameError",
104
96
  message: frame.message ?? "stream error"
@@ -127,22 +119,19 @@ async function streamSession(opts) {
127
119
  let afterSeq = opts.afterSeq ?? 0;
128
120
  let everReceivedFrame = false;
129
121
  let attempt = 0;
130
- let lastStatusWord = "";
131
- let lastReason = null;
122
+ let lastSession = null;
132
123
  const emit = (frame) => {
133
124
  everReceivedFrame = true;
134
125
  attempt = 0;
135
- if (frame.type === "records_append") {
126
+ if (frame.type === "records") {
136
127
  const records = frame.records;
137
128
  for (const record of records) {
138
129
  if (typeof record.feed_seq === "number") {
139
130
  afterSeq = Math.max(afterSeq, record.feed_seq);
140
131
  }
141
132
  }
142
- } else if (frame.type === "snapshot" || frame.type === "session") {
143
- const session = frame.session;
144
- lastStatusWord = sessionStatusWord(session);
145
- lastReason = session.turn?.reason ?? null;
133
+ } else if (frame.type === "session") {
134
+ lastSession = frame.session;
146
135
  }
147
136
  opts.onFrame(frame);
148
137
  };
@@ -162,8 +151,8 @@ async function streamSession(opts) {
162
151
  err: err instanceof Error ? err : new Error(String(err))
163
152
  };
164
153
  }
165
- if (res.kind === "done") {
166
- return { type: "done", status: lastStatusWord, reason: lastReason };
154
+ if (res.kind === "closed" && res.code === WS_CLOSE_NORMAL && lastSession?.status === "closed") {
155
+ return { type: "done", session: lastSession };
167
156
  }
168
157
  if (res.kind === "frameError")
169
158
  return { type: "error", message: res.message };