@nolag/chat 0.1.2 → 0.2.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/types.d.ts CHANGED
@@ -56,8 +56,12 @@ export interface ChatMessage {
56
56
  data?: Record<string, unknown>;
57
57
  /** Timestamp (ms since epoch) */
58
58
  timestamp: number;
59
- /** Delivery status */
60
- status: 'sending' | 'sent' | 'delivered';
59
+ /**
60
+ * Delivery status. `streaming` = an in-progress streamed message whose `text`
61
+ * is still growing; it becomes `delivered`/`sent` when finalized, or `aborted`
62
+ * if the stream was cancelled.
63
+ */
64
+ status: 'sending' | 'sent' | 'delivered' | 'streaming' | 'aborted';
61
65
  /** Whether this message came from replay (history) */
62
66
  isReplay: boolean;
63
67
  }
@@ -65,6 +69,31 @@ export interface SendMessageOptions {
65
69
  /** Optional structured data to attach */
66
70
  data?: Record<string, unknown>;
67
71
  }
72
+ export interface StreamMessageOptions {
73
+ /** Optional structured data to attach to the final message */
74
+ data?: Record<string, unknown>;
75
+ /**
76
+ * Coalesce appended tokens and publish a network delta at most this often (ms).
77
+ * Lower = smoother but more messages; higher = fewer/larger chunks.
78
+ * Default 60. The local message text updates immediately regardless.
79
+ */
80
+ flushIntervalMs?: number;
81
+ }
82
+ /**
83
+ * Handle for an in-progress outgoing streamed message — e.g. an AI response
84
+ * generated token-by-token. Append tokens as they arrive, then `complete()` to
85
+ * finalize + persist, or `abort()` to cancel.
86
+ */
87
+ export interface MessageStream {
88
+ /** The optimistic streaming message; its `text` grows as you append. */
89
+ readonly message: ChatMessage;
90
+ /** Append a token/chunk; updates the message and (throttled) broadcasts a delta. */
91
+ append(text: string): void;
92
+ /** Finalize: flush, publish the persisted message, emit `streamEnd`. Returns the message. */
93
+ complete(): ChatMessage;
94
+ /** Cancel the stream; broadcasts an abort and does NOT persist a message. */
95
+ abort(error?: string): void;
96
+ }
68
97
  export interface ChatClientEvents {
69
98
  connected: [];
70
99
  disconnected: [reason: string];
@@ -92,6 +121,20 @@ export interface ChatRoomEvents {
92
121
  room: string;
93
122
  count: number;
94
123
  }];
124
+ /** A streamed message started (placeholder, status 'streaming') */
125
+ streamStart: [message: ChatMessage];
126
+ /** A streamed message grew by `delta` (message.text already updated) */
127
+ streamChunk: [data: {
128
+ message: ChatMessage;
129
+ delta: string;
130
+ }];
131
+ /** A streamed message finished (status 'delivered'/'sent', final text) */
132
+ streamEnd: [message: ChatMessage];
133
+ /** A streamed message was cancelled (status 'aborted') */
134
+ streamAbort: [data: {
135
+ message: ChatMessage;
136
+ error?: string;
137
+ }];
95
138
  }
96
139
  /** Shape of data stored in NoLag presence for chat users */
97
140
  export interface ChatPresenceData {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolag/chat",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -46,10 +46,10 @@
46
46
  "license": "MIT",
47
47
  "homepage": "https://nolag.app",
48
48
  "devDependencies": {
49
- "@nolag/js-sdk": "^1.8.0"
49
+ "@nolag/js-sdk": "^1.9.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@nolag/js-sdk": "^1.8.0"
52
+ "@nolag/js-sdk": "^1.9.0"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"