aero/src/core.ts
2025-11-09 22:23:39 -06:00

78 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { GoogleGenAI } from "@google/genai";
import { Bot, EventStrategy } from "@skyware/bot";
import { env } from "./env";
import type { BinaryType } from "bun";
// Websocket patch was written by Claude, hopefully it doesn't suck
const OriginalWebSocket = global.WebSocket;
const binaryTypeDescriptor = Object.getOwnPropertyDescriptor(
OriginalWebSocket.prototype,
"binaryType",
);
const originalSetter = binaryTypeDescriptor?.set;
if (OriginalWebSocket && originalSetter) {
global.WebSocket = new Proxy(OriginalWebSocket, {
construct(target, args) {
//@ts-ignore
const ws = new target(...args) as WebSocket & {
_binaryType?: BinaryType;
};
Object.defineProperty(ws, "binaryType", {
get(): BinaryType {
return ws._binaryType ||
(binaryTypeDescriptor.get
? binaryTypeDescriptor.get.call(ws)
: "arraybuffer");
},
set(value: BinaryType) {
//@ts-ignore
if (value === "blob") {
originalSetter.call(ws, "arraybuffer");
//@ts-ignore
ws._binaryType = "blob";
} else {
originalSetter.call(ws, value);
ws._binaryType = value;
}
},
configurable: true,
});
return ws;
},
}) as typeof WebSocket;
}
export const bot = new Bot({
service: env.SERVICE,
emitChatEvents: true,
eventEmitterOptions: {
strategy: env.USE_JETSTREAM
? EventStrategy.Jetstream
: EventStrategy.Polling,
},
});
export const ai = new GoogleGenAI({
apiKey: env.GEMINI_API_KEY,
});
export const QUOTA_EXCEEDED_MESSAGE =
"You have exceeded your daily message quota (15). Please wait 24 hours before trying again.";
export const ERROR_MESSAGE =
"Sorry, I ran into an issue analyzing that post. Please try again.";
export const UNAUTHORIZED_MESSAGE =
"I cant make sense of your noise just yet. Youll need to be whitelisted before I can help.";
export const SUPPORTED_FUNCTION_CALLS = [
"search_posts",
] as const;
export const MAX_GRAPHEMES = 1000;
export const MAX_THREAD_DEPTH = 10;