@ziggy-ai/client-sdk 0.8.0 → 0.8.1
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/dist/chat.d.ts.map +1 -1
- package/dist/index.js +23 -2
- package/dist/stream-parser.d.ts +10 -1
- package/dist/stream-parser.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,MAAM,CAAuB;gBAEzB,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc;IAKlE,8DAA8D;IAC9D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAavD;;;OAGG;IACI,MAAM,CACX,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACjC,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,C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,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,mBAAmB,EAAE,CAAA;KAAE,CAAC;IAQvG;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAC9F,aAAa,EAAE,mBAAmB,EAAE,CAAC;QACrC,UAAU,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAA;SAAE,CAAC;KACjE,CAAC;CAOH"}
|
package/dist/index.js
CHANGED
|
@@ -168,14 +168,23 @@ var SessionManager = class {
|
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
// src/stream-parser.ts
|
|
171
|
-
|
|
171
|
+
var DEFAULT_INACTIVITY_TIMEOUT = 12e4;
|
|
172
|
+
async function* parseNdjsonStream(response, options) {
|
|
172
173
|
const reader = response.body?.getReader();
|
|
173
174
|
if (!reader) throw new Error("Response has no body");
|
|
175
|
+
const timeoutMs = options?.inactivityTimeoutMs ?? DEFAULT_INACTIVITY_TIMEOUT;
|
|
174
176
|
const decoder = new TextDecoder();
|
|
175
177
|
let buffer = "";
|
|
176
178
|
try {
|
|
177
179
|
while (true) {
|
|
178
|
-
const
|
|
180
|
+
const readPromise = reader.read();
|
|
181
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
182
|
+
setTimeout(
|
|
183
|
+
() => reject(new Error(`Stream timed out \u2014 no data received for ${Math.round(timeoutMs / 1e3)}s`)),
|
|
184
|
+
timeoutMs
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
const { done, value } = await Promise.race([readPromise, timeoutPromise]);
|
|
179
188
|
if (done) break;
|
|
180
189
|
buffer += decoder.decode(value, { stream: true });
|
|
181
190
|
const lines = buffer.split("\n");
|
|
@@ -266,6 +275,18 @@ var ChatClient = class {
|
|
|
266
275
|
userId: this.userId,
|
|
267
276
|
...request
|
|
268
277
|
}, options?.signal);
|
|
278
|
+
const contentType = response.headers.get("Content-Type") || "";
|
|
279
|
+
if (contentType.includes("application/json")) {
|
|
280
|
+
const body = await response.json();
|
|
281
|
+
if (body.type === "coalesce.collecting") {
|
|
282
|
+
yield { type: "stream.collecting", pendingCount: body.pendingCount, debounceMs: body.debounceMs, seq: 0 };
|
|
283
|
+
} else if (body.type === "coalesce.queued") {
|
|
284
|
+
yield { type: "stream.queued", position: body.position, seq: 0 };
|
|
285
|
+
} else if (body.type === "coalesce.steering") {
|
|
286
|
+
yield { type: "stream.steering", interruptMessage: body.interruptMessage, seq: 0 };
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
269
290
|
const tracker = new SequenceTracker();
|
|
270
291
|
for await (const event of parseNdjsonStream(response)) {
|
|
271
292
|
tracker.update(event);
|
package/dist/stream-parser.d.ts
CHANGED
|
@@ -5,11 +5,20 @@
|
|
|
5
5
|
* and reconnection support.
|
|
6
6
|
*/
|
|
7
7
|
import type { StreamEvent } from './types.js';
|
|
8
|
+
/** Options for the NDJSON stream parser. */
|
|
9
|
+
export interface ParseNdjsonOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Inactivity timeout in ms. If no data arrives from the server
|
|
12
|
+
* within this window, the parser throws a timeout error.
|
|
13
|
+
* Default: 120_000 (2 minutes).
|
|
14
|
+
*/
|
|
15
|
+
inactivityTimeoutMs?: number;
|
|
16
|
+
}
|
|
8
17
|
/**
|
|
9
18
|
* Parse an ndjson Response body into an async iterable of StreamEvents.
|
|
10
19
|
* Tracks the last seen sequence number for reconnection.
|
|
11
20
|
*/
|
|
12
|
-
export declare function parseNdjsonStream(response: Response): AsyncGenerator<StreamEvent, void, undefined>;
|
|
21
|
+
export declare function parseNdjsonStream(response: Response, options?: ParseNdjsonOptions): AsyncGenerator<StreamEvent, void, undefined>;
|
|
13
22
|
/**
|
|
14
23
|
* Track last seen sequence number from a stream.
|
|
15
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../src/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;GAGG;AACH,wBAAuB,iBAAiB,CACtC,QAAQ,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../src/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAID;;;GAGG;AACH,wBAAuB,iBAAiB,CACtC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC,CAwD9C;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,SAAS,CAAuB;IAExC,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAShC,KAAK,IAAI,IAAI;CAId"}
|