mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
44 lines
956 B
TypeScript
44 lines
956 B
TypeScript
// FIXME ping telemetry server directly instead of going through the backend.
|
|
|
|
// We do this to work around CORS insanity.
|
|
export async function pingTelemetry(event: string, data: any) {
|
|
const requestBody: any = {
|
|
event: 'NutChat.' + event,
|
|
data,
|
|
};
|
|
|
|
fetch('/api/ping-telemetry', {
|
|
method: 'POST',
|
|
body: JSON.stringify(requestBody),
|
|
});
|
|
}
|
|
|
|
// Manage telemetry events for a single chat message.
|
|
|
|
export class ChatMessageTelemetry {
|
|
id: string;
|
|
numMessages: number;
|
|
|
|
constructor(numMessages: number) {
|
|
this.id = Math.random().toString(36).substring(2, 15);
|
|
this.numMessages = numMessages;
|
|
this._ping('StartMessage');
|
|
}
|
|
|
|
private _ping(event: string, data: any = {}) {
|
|
pingTelemetry(event, {
|
|
...data,
|
|
messageId: this.id,
|
|
numMessages: this.numMessages,
|
|
});
|
|
}
|
|
|
|
finish() {
|
|
this._ping('FinishMessage');
|
|
}
|
|
|
|
abort(reason: string) {
|
|
this._ping('AbortMessage', { reason });
|
|
}
|
|
}
|