@mooncompany/uplink-chat 0.5.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.
Potentially problematic release.
This version of @mooncompany/uplink-chat might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +185 -0
- package/bin/uplink.js +279 -0
- package/middleware/error-handler.js +69 -0
- package/package.json +93 -0
- package/public/css/agents.36b98c0f.css +1469 -0
- package/public/css/agents.css +1469 -0
- package/public/css/app.a6a7f8f5.css +2731 -0
- package/public/css/app.css +2731 -0
- package/public/css/artifacts.css +444 -0
- package/public/css/commands.css +55 -0
- package/public/css/connection.css +131 -0
- package/public/css/dashboard.css +233 -0
- package/public/css/developer.css +328 -0
- package/public/css/files.css +123 -0
- package/public/css/markdown.css +156 -0
- package/public/css/message-actions.css +278 -0
- package/public/css/mobile.css +614 -0
- package/public/css/panels-unified.css +483 -0
- package/public/css/premium.css +415 -0
- package/public/css/realtime.css +189 -0
- package/public/css/satellites.css +401 -0
- package/public/css/shortcuts.css +185 -0
- package/public/css/split-view.4def0262.css +673 -0
- package/public/css/split-view.css +673 -0
- package/public/css/theme-generator.css +391 -0
- package/public/css/themes.css +387 -0
- package/public/css/timestamps.css +54 -0
- package/public/css/variables.css +78 -0
- package/public/dist/bundle.b55050c4.js +15757 -0
- package/public/favicon.svg +24 -0
- package/public/img/agents/ada.png +0 -0
- package/public/img/agents/clarice.png +0 -0
- package/public/img/agents/dennis-nedry.png +0 -0
- package/public/img/agents/elliot-alderson.png +0 -0
- package/public/img/agents/main.png +0 -0
- package/public/img/agents/scotty.png +0 -0
- package/public/img/agents/top-flight-security.png +0 -0
- package/public/index.html +1083 -0
- package/public/js/agents-data.js +234 -0
- package/public/js/agents-ui.js +72 -0
- package/public/js/agents.js +1525 -0
- package/public/js/app.js +79 -0
- package/public/js/appearance-settings.js +111 -0
- package/public/js/artifacts.js +432 -0
- package/public/js/audio-queue.js +168 -0
- package/public/js/bootstrap.js +54 -0
- package/public/js/chat.js +1211 -0
- package/public/js/commands.js +581 -0
- package/public/js/connection-api.js +121 -0
- package/public/js/connection.js +1231 -0
- package/public/js/context-tracker.js +271 -0
- package/public/js/core.js +172 -0
- package/public/js/dashboard.js +452 -0
- package/public/js/developer.js +432 -0
- package/public/js/encryption.js +124 -0
- package/public/js/errors.js +122 -0
- package/public/js/event-bus.js +77 -0
- package/public/js/fetch-utils.js +171 -0
- package/public/js/file-handler.js +229 -0
- package/public/js/files.js +352 -0
- package/public/js/gateway-chat.js +538 -0
- package/public/js/logger.js +112 -0
- package/public/js/markdown.js +190 -0
- package/public/js/message-actions.js +431 -0
- package/public/js/message-renderer.js +288 -0
- package/public/js/missed-messages.js +235 -0
- package/public/js/mobile-debug.js +95 -0
- package/public/js/notifications.js +367 -0
- package/public/js/offline-queue.js +178 -0
- package/public/js/onboarding.js +543 -0
- package/public/js/panels.js +156 -0
- package/public/js/premium.js +412 -0
- package/public/js/realtime-voice.js +844 -0
- package/public/js/satellite-sync.js +256 -0
- package/public/js/satellite-ui.js +175 -0
- package/public/js/satellites.js +1516 -0
- package/public/js/settings.js +1087 -0
- package/public/js/shortcuts.js +381 -0
- package/public/js/split-chat.js +1234 -0
- package/public/js/split-resize.js +211 -0
- package/public/js/splitview.js +340 -0
- package/public/js/storage.js +408 -0
- package/public/js/streaming-handler.js +324 -0
- package/public/js/stt-settings.js +316 -0
- package/public/js/theme-generator.js +661 -0
- package/public/js/themes.js +164 -0
- package/public/js/timestamps.js +198 -0
- package/public/js/tts-settings.js +575 -0
- package/public/js/ui.js +267 -0
- package/public/js/update-notifier.js +143 -0
- package/public/js/utils/constants.js +165 -0
- package/public/js/utils/sanitize.js +93 -0
- package/public/js/utils/sse-parser.js +195 -0
- package/public/js/voice.js +883 -0
- package/public/manifest.json +58 -0
- package/public/moon_texture.jpg +0 -0
- package/public/sw.js +221 -0
- package/public/three.min.js +6 -0
- package/server/channel.js +529 -0
- package/server/chat.js +270 -0
- package/server/config-store.js +362 -0
- package/server/config.js +159 -0
- package/server/context.js +131 -0
- package/server/gateway-commands.js +211 -0
- package/server/gateway-proxy.js +318 -0
- package/server/index.js +22 -0
- package/server/logger.js +89 -0
- package/server/middleware/auth.js +188 -0
- package/server/middleware.js +218 -0
- package/server/openclaw-discover.js +308 -0
- package/server/premium/index.js +156 -0
- package/server/premium/license.js +140 -0
- package/server/realtime/bridge.js +837 -0
- package/server/realtime/index.js +349 -0
- package/server/realtime/tts-stream.js +446 -0
- package/server/routes/agents.js +564 -0
- package/server/routes/artifacts.js +174 -0
- package/server/routes/chat.js +311 -0
- package/server/routes/config-settings.js +345 -0
- package/server/routes/config.js +603 -0
- package/server/routes/files.js +307 -0
- package/server/routes/index.js +18 -0
- package/server/routes/media.js +451 -0
- package/server/routes/missed-messages.js +107 -0
- package/server/routes/premium.js +75 -0
- package/server/routes/push.js +156 -0
- package/server/routes/satellite.js +406 -0
- package/server/routes/status.js +251 -0
- package/server/routes/stt.js +35 -0
- package/server/routes/voice.js +260 -0
- package/server/routes/webhooks.js +203 -0
- package/server/routes.js +206 -0
- package/server/runtime-config.js +336 -0
- package/server/share.js +305 -0
- package/server/stt/faster-whisper.js +72 -0
- package/server/stt/groq.js +51 -0
- package/server/stt/index.js +196 -0
- package/server/stt/openai.js +49 -0
- package/server/sync.js +244 -0
- package/server/tailscale-https.js +175 -0
- package/server/tts.js +646 -0
- package/server/update-checker.js +172 -0
- package/server/utils/filename.js +129 -0
- package/server/utils.js +147 -0
- package/server/watchdog.js +318 -0
- package/server/websocket/broadcast.js +359 -0
- package/server/websocket/connections.js +339 -0
- package/server/websocket/index.js +215 -0
- package/server/websocket/routing.js +277 -0
- package/server/websocket/sync.js +102 -0
- package/server.js +404 -0
- package/utils/detect-tool-usage.js +93 -0
- package/utils/errors.js +158 -0
- package/utils/html-escape.js +84 -0
- package/utils/id-sanitize.js +94 -0
- package/utils/response.js +130 -0
- package/utils/with-retry.js +105 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// ============================================
|
|
2
|
+
// SSE PARSER UTILITY
|
|
3
|
+
// Server-Sent Events stream parsing
|
|
4
|
+
// ============================================
|
|
5
|
+
//
|
|
6
|
+
// NOTE: The primary SSE handling for chat streaming is in streaming-handler.js
|
|
7
|
+
// (UplinkStreamingHandler). This utility provides a standalone parser
|
|
8
|
+
// for use by modules that need SSE parsing without the full streaming handler
|
|
9
|
+
// (e.g., image uploads, file uploads, standalone API calls).
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SSE Parser class for handling Server-Sent Events streams.
|
|
14
|
+
* Handles buffering, line parsing, and JSON decoding.
|
|
15
|
+
*/
|
|
16
|
+
export class SSEParser {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.buffer = '';
|
|
19
|
+
this.decoder = new TextDecoder();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reset the parser state.
|
|
24
|
+
*/
|
|
25
|
+
reset() {
|
|
26
|
+
this.buffer = '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Process a chunk of data and return parsed events.
|
|
31
|
+
*
|
|
32
|
+
* @param {Uint8Array} chunk - The raw chunk from the stream
|
|
33
|
+
* @returns {Array<Object>} Array of parsed event objects
|
|
34
|
+
*/
|
|
35
|
+
processChunk(chunk) {
|
|
36
|
+
const events = [];
|
|
37
|
+
|
|
38
|
+
// Decode and append to buffer
|
|
39
|
+
this.buffer += this.decoder.decode(chunk, { stream: true });
|
|
40
|
+
|
|
41
|
+
// Split into lines, keeping incomplete line in buffer
|
|
42
|
+
const lines = this.buffer.split('\n');
|
|
43
|
+
this.buffer = lines.pop() || '';
|
|
44
|
+
|
|
45
|
+
for (const line of lines) {
|
|
46
|
+
const event = this.parseLine(line);
|
|
47
|
+
if (event !== null) {
|
|
48
|
+
events.push(event);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return events;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Parse a single SSE line.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} line - The line to parse
|
|
59
|
+
* @returns {Object|null} Parsed event or null
|
|
60
|
+
*/
|
|
61
|
+
parseLine(line) {
|
|
62
|
+
// Skip empty lines
|
|
63
|
+
if (!line.trim()) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Skip SSE comments/keepalives
|
|
68
|
+
if (line.startsWith(':')) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Must be a data line
|
|
73
|
+
if (!line.startsWith('data: ')) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const data = line.slice(6); // Remove 'data: ' prefix
|
|
78
|
+
|
|
79
|
+
// Handle stream completion
|
|
80
|
+
if (data === '[DONE]') {
|
|
81
|
+
return { type: 'done' };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Try to parse as JSON
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(data);
|
|
87
|
+
return { type: 'data', payload: parsed };
|
|
88
|
+
} catch (e) {
|
|
89
|
+
// Return raw data if not valid JSON
|
|
90
|
+
return { type: 'raw', data };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Flush any remaining data in the buffer.
|
|
96
|
+
* Call this when the stream ends.
|
|
97
|
+
*
|
|
98
|
+
* @returns {Object|null} Final parsed event or null
|
|
99
|
+
*/
|
|
100
|
+
flush() {
|
|
101
|
+
if (this.buffer.trim()) {
|
|
102
|
+
const result = this.parseLine(this.buffer);
|
|
103
|
+
this.buffer = '';
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Dispatch a single parsed event to the appropriate handler.
|
|
112
|
+
*/
|
|
113
|
+
function handleEvent(event, handlers) {
|
|
114
|
+
switch (event.type) {
|
|
115
|
+
case 'data':
|
|
116
|
+
handlers.onData?.(event.payload);
|
|
117
|
+
break;
|
|
118
|
+
case 'done':
|
|
119
|
+
handlers.onDone?.();
|
|
120
|
+
break;
|
|
121
|
+
case 'raw':
|
|
122
|
+
handlers.onRaw?.(event.data);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Process an SSE stream from a fetch response with callbacks.
|
|
129
|
+
*
|
|
130
|
+
* @param {Response} response - Fetch response with SSE body
|
|
131
|
+
* @param {Object} handlers - Event handlers
|
|
132
|
+
* @param {Function} [handlers.onData] - Called for each parsed data event (receives payload)
|
|
133
|
+
* @param {Function} [handlers.onDone] - Called when stream completes
|
|
134
|
+
* @param {Function} [handlers.onError] - Called on errors
|
|
135
|
+
* @param {Function} [handlers.onRaw] - Called for unparseable raw data
|
|
136
|
+
* @param {AbortSignal} [signal] - Optional abort signal
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* await UplinkSSEParser.processStream(response, {
|
|
140
|
+
* onData: (payload) => console.log(payload),
|
|
141
|
+
* onDone: () => console.log('Done'),
|
|
142
|
+
* onError: (err) => console.error(err)
|
|
143
|
+
* });
|
|
144
|
+
*/
|
|
145
|
+
export async function processStream(response, handlers, signal) {
|
|
146
|
+
const { onData, onDone, onError, onRaw } = handlers;
|
|
147
|
+
const parser = new SSEParser();
|
|
148
|
+
const reader = response.body.getReader();
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
while (true) {
|
|
152
|
+
if (signal?.aborted) break;
|
|
153
|
+
|
|
154
|
+
const { done, value } = await reader.read();
|
|
155
|
+
|
|
156
|
+
if (done) {
|
|
157
|
+
const finalEvent = parser.flush();
|
|
158
|
+
if (finalEvent) {
|
|
159
|
+
handleEvent(finalEvent, { onData, onDone, onRaw });
|
|
160
|
+
}
|
|
161
|
+
onDone?.();
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const events = parser.processChunk(value);
|
|
166
|
+
for (const event of events) {
|
|
167
|
+
handleEvent(event, { onData, onDone, onRaw });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (err.name === 'AbortError') {
|
|
172
|
+
onDone?.();
|
|
173
|
+
} else {
|
|
174
|
+
onError?.(err);
|
|
175
|
+
}
|
|
176
|
+
} finally {
|
|
177
|
+
reader.releaseLock();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ============================================
|
|
182
|
+
// PUBLIC API
|
|
183
|
+
// ============================================
|
|
184
|
+
|
|
185
|
+
export const UplinkSSEParser = {
|
|
186
|
+
SSEParser,
|
|
187
|
+
processStream
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Backward compat: assign to window
|
|
191
|
+
window.UplinkSSEParser = UplinkSSEParser;
|
|
192
|
+
|
|
193
|
+
if (typeof logger !== 'undefined') {
|
|
194
|
+
logger.debug('SSEParser: Module loaded');
|
|
195
|
+
}
|