@luckystack/sync 0.10.2 → 0.11.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.
package/dist/index.d.ts CHANGED
@@ -1,91 +1,7 @@
1
- export { S as SYNC_ERROR_CODES, a as SyncErrorCode } from './errorCodes-B8GoTenr.js';
2
- import { syncMessage } from '@luckystack/core';
3
- import { Socket } from 'socket.io';
4
-
5
- declare function handleSyncRequest(args: {
6
- msg: syncMessage;
7
- socket: Socket;
8
- token: string | null;
9
- }): Promise<void>;
10
-
11
- type SyncStreamPayload = Record<string, unknown>;
12
-
13
- interface HttpSyncRequestParams {
14
- name: string;
15
- cb?: string;
16
- data: Record<string, unknown>;
17
- receiver: string;
18
- ignoreSelf?: boolean;
19
- token: string | null;
20
- requesterIp?: string;
21
- xLanguageHeader?: string | string[];
22
- acceptLanguageHeader?: string | string[];
23
- stream?: (payload: HttpSyncStreamEvent) => void;
24
- /**
25
- * Optional AbortSignal. The HTTP server (`@luckystack/server`) wires this
26
- * to `req.on('close', ...)` so a closed SSE connection aborts in-flight
27
- * stream emits. Sync handlers receive it as `abortSignal` in params.
28
- */
29
- abortSignal?: AbortSignal;
30
- }
31
- interface HttpSyncResponse {
32
- status: 'success' | 'error';
33
- message: string;
34
- result?: unknown;
35
- errorCode?: string;
36
- errorParams?: {
37
- key: string;
38
- value: string | number | boolean;
39
- }[];
40
- httpStatus?: number;
41
- }
42
- type HttpSyncStreamEvent = SyncStreamPayload;
43
- declare function handleHttpSyncRequest(args: HttpSyncRequestParams): Promise<HttpSyncResponse>;
44
-
45
- interface CreateStreamThrottleOptions {
46
- /**
47
- * Flush buffered text once it crosses this many characters. Default: 32.
48
- * Lower = more updates, more network traffic.
49
- * Higher = fewer updates, choppier UI.
50
- */
51
- flushAtChars?: number;
52
- /**
53
- * Flush buffered text after this many milliseconds even if the char
54
- * threshold hasn't been hit. Default: 50ms — fast enough that the user
55
- * perceives "live typing", slow enough that 50–100 tokens batch into a
56
- * single message on a fast LLM stream.
57
- *
58
- * Set to `false` to disable the timer (only flush at char threshold or
59
- * on explicit `flush()`).
60
- */
61
- flushEveryMs?: number | false;
62
- /**
63
- * Field name on the emitted payload that carries the buffered text.
64
- * Default: `'chunk'`. Override if your stream payload uses a different
65
- * key (e.g. `'text'`, `'delta'`).
66
- */
67
- field?: string;
68
- }
69
- interface StreamThrottle {
70
- /** Append text to the buffer. May trigger a flush. */
71
- push: (text: string, emit: (payload: Record<string, unknown>) => void) => void;
72
- /** Force-flush whatever is in the buffer right now. Call after the source loop ends. */
73
- flush: (emit: (payload: Record<string, unknown>) => void) => void;
74
- /** Drop the buffered text without emitting. Useful on abort. */
75
- reset: () => void;
76
- }
77
- /**
78
- * Build a chunk throttle for streaming use cases. Designed for LLM token
79
- * streams where the provider yields very small pieces (3–10 chars) and you
80
- * don't want to send a separate socket message for each one.
81
- *
82
- * @example
83
- * const throttle = createStreamThrottle({ flushEveryMs: 50, flushAtChars: 32 });
84
- * for await (const chunk of openaiStream) {
85
- * throttle.push(chunk.text, broadcastStream);
86
- * }
87
- * throttle.flush(broadcastStream);
88
- */
89
- declare const createStreamThrottle: (options?: CreateStreamThrottleOptions) => StreamThrottle;
90
-
91
- export { type CreateStreamThrottleOptions, type HttpSyncStreamEvent, type StreamThrottle, createStreamThrottle, handleHttpSyncRequest, handleSyncRequest };
1
+ export { SYNC_ERROR_CODES } from './_shared/errorCodes.js';
2
+ export type { SyncErrorCode } from './_shared/errorCodes.js';
3
+ export { default as handleSyncRequest } from './handleSyncRequest.js';
4
+ export { default as handleHttpSyncRequest } from './handleHttpSyncRequest.js';
5
+ export type { HttpSyncStreamEvent } from './handleHttpSyncRequest.js';
6
+ export { createStreamThrottle } from './streamThrottle.js';
7
+ export type { StreamThrottle, CreateStreamThrottleOptions, } from './streamThrottle.js';