Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.

Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
John
2026-06-15 15:04:43 -07:00
commit 2e14873f2d
272 changed files with 64133 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
import { Transform } from 'node:stream';
function parseSseChunk(chunk) {
const events = [];
const blocks = chunk.split('\n\n');
for (const block of blocks) {
if (!block.trim()) continue;
let data;
for (const line of block.split('\n')) {
if (line.startsWith('data:')) {
data = line.slice(5).trim();
}
}
if (!data) continue;
try {
events.push(JSON.parse(data));
} catch {
// ignore malformed frames
}
}
return events;
}
export function createSseBillingTransform({ onFinish }) {
let buffer = '';
return new Transform({
transform(chunk, _encoding, callback) {
buffer += chunk.toString('utf8');
const parts = buffer.split('\n\n');
buffer = parts.pop() ?? '';
for (const block of parts) {
if (!block.trim()) continue;
let dataLine;
for (const line of block.split('\n')) {
if (line.startsWith('data:')) dataLine = line.slice(5).trim();
}
if (!dataLine) continue;
try {
const event = JSON.parse(dataLine);
if (event?.type === 'Finish' && event.token_state) {
void onFinish(event).catch(() => {});
}
} catch {
// ignore
}
}
callback(null, chunk);
},
flush(callback) {
if (buffer.trim()) {
for (const event of parseSseChunk(`${buffer}\n\n`)) {
if (event?.type === 'Finish' && event.token_state) {
void onFinish(event).catch(() => {});
}
}
}
callback();
},
});
}
export function appendBalanceEvent(balanceCents) {
return `event: balance\ndata: ${JSON.stringify({ balanceCents })}\n\n`;
}