Import source: src/types

Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
arsam
2026-09-18 23:14:57 +03:30
parent 284e60c4cc
commit 49e248400e
+250
View File
@@ -0,0 +1,250 @@
import type { KVNamespace } from './kv';
export const BOT_VERSION = "0.9.27";
export interface ExecutionContext {
waitUntil(promise: Promise<unknown>): void;
passThroughOnException?(): void;
}
export interface ToolResult {
name: string;
response: Record<string, unknown>;
}
export type AIEngine = "gemini";
export type MessageRole = "user" | "model" | "assistant" | "system" | "function";
export type ChatType = "private" | "group" | "supergroup";
export type Language = "fa" | "en";
export interface Part {
text?: string;
inline_data?: { mime_type: string; data: string };
functionCall?: { name: string; args: Record<string, unknown> };
functionResponse?: { name: string; response: Record<string, unknown> };
thoughtSignature?: string;
}
export interface HistoryItem {
role: MessageRole;
parts: Part[];
timestamp?: number;
userId?: number;
userName?: string;
}
export interface UserMemory {
userId: number;
userName: string;
firstName: string;
lastSeen: number;
messageCount: number;
topics: string[];
personality: string;
preferences: string[];
interactionStyle: string;
}
export interface GroupMessage {
messageId: number;
userId: number;
userName: string;
text: string;
timestamp: number;
isReply?: boolean;
replyToUser?: string;
}
export interface TgSticker { file_id: string; emoji?: string; file_size?: number }
export interface EngineState {
history: HistoryItem[];
userHistories: Map<number, HistoryItem[]>;
apiKeyIndex: number;
consecutiveErrors: number;
}
export interface ChatSession {
id: number;
type: ChatType;
activeEngine: AIEngine;
lastSeen: number;
messageCount: number;
language: Language;
userMemories: Map<number, UserMemory>;
groupContext: HistoryItem[];
customPrompts: { gemini: string | null };
userCustomPrompts: Map<number, string>;
engines: {
gemini: EngineState;
};
rateLimiting: { requests: number[] };
settings: {
autoCleanHistory: boolean;
typingIndicator: boolean;
groupResponseMode: "always" | "mention_only" | "smart";
personalizedResponses: boolean;
contextAwareness: boolean;
languageSet: boolean;
};
statistics: {
totalMessages: number;
geminiMessages: number;
voicesReceived: number;
firstUsed: number;
};
vipStatus: boolean;
dailyLimits: {
messages: number;
voicesSent: number;
voicesReceived: number;
imagesGenerated: number;
lastReset: number;
};
}
export interface ModelInfo {
id: string;
name: string;
description?: string;
context_length?: number;
type?: "text" | "image";
}
export interface ModelCache {
engine: AIEngine;
models: ModelInfo[];
lastUpdated: number;
}
export interface UserStatistics {
userId: number;
firstName: string;
userName: string;
chatType: ChatType;
statistics: ChatSession["statistics"];
activeEngine: AIEngine;
vipStatus: boolean;
dailyLimits: ChatSession["dailyLimits"];
}
export interface BroadcastJob {
id: string;
mode: "all" | "vip" | "free" | "specific";
targetUserId?: number;
message: string;
userIds: number[];
processedIndex: number;
sent: number;
failed: number;
totalUsers: number;
adminChatId: number;
adminMessageId: number;
createdAt: number;
status: "pending" | "running" | "done" | "error";
}
export interface Env {
TOKEN: string;
SESSIONS: KVNamespace;
BOT_OWNER_ID?: string;
ADDITIONAL_OWNER_IDS?: string;
GEMINI_KEY_1?: string;
GEMINI_KEY_2?: string;
GEMINI_KEY_3?: string;
GEMINI_KEY_4?: string;
GEMINI_KEY_5?: string;
GOOGLE_SEARCH_API_KEY?: string;
GOOGLE_SEARCH_ENGINE_ID?: string;
MAINTENANCE_MODE?: string;
CF_ID_1?: string; CF_TOKEN_1?: string;
CF_ID_2?: string; CF_TOKEN_2?: string;
CF_ID_3?: string; CF_TOKEN_3?: string;
ELEVENLABS_KEY_1?: string;
ELEVENLABS_KEY_2?: string;
ELEVENLABS_KEY_3?: string;
ELEVENLABS_KEY_4?: string;
ELEVENLABS_KEY_5?: string;
}
export interface BotConfig {
image_limit: number;
message_limit: number;
voice_limit: number;
system_prompt: string;
maintenance: boolean;
vip_contact: string;
}
export interface GroupInfo {
chatId: number;
title: string;
type: "group" | "supergroup";
username?: string;
memberCount?: number;
addedAt: number;
lastActivity: number;
vipStatus: boolean;
}
export interface TgUser { id: number; is_bot: boolean; first_name: string; username?: string; language_code?: string }
export interface TgChat { id: number; type: ChatType; title?: string }
export interface TgPhotoSize { file_id: string; file_unique_id: string; width: number; height: number; file_size?: number }
export interface TgDocument { file_id: string; file_name?: string; mime_type?: string; file_size?: number }
export interface TgVoice { file_id: string; file_unique_id: string; duration: number; mime_type?: string; file_size?: number }
export interface TgVideo { file_id: string; duration: number; mime_type?: string; file_size?: number }
export interface TgAnimation { file_id: string; mime_type?: string; file_size?: number }
export interface TgMessageEntity { type: string; offset: number; length: number }
export interface TgMessage {
message_id: number;
from?: TgUser;
chat: TgChat;
date: number;
text?: string;
caption?: string;
photo?: TgPhotoSize[];
document?: TgDocument;
voice?: TgVoice;
video?: TgVideo;
sticker?: TgSticker;
animation?: TgAnimation;
reply_to_message?: TgMessage;
entities?: TgMessageEntity[];
}
export interface TgCallbackQuery { id: string; from: TgUser; message?: TgMessage; data?: string }
export interface TgUpdate { update_id: number; message?: TgMessage; callback_query?: TgCallbackQuery }
export type ErrorType = "quota" | "auth" | "network" | "timeout" | "blocked" | "empty" | "server" | "unknown";
export interface GeminiFunctionCall {
name: string;
args: Record<string, unknown>;
}
export interface GeminiResponse {
text: string;
functionCalls: GeminiFunctionCall[];
modelParts?: Part[];
}
export type InlineBtn = { text: string; callback_data?: string; url?: string };
export type InlineKeyboard = { inline_keyboard: InlineBtn[][] };
export interface BotConfigChange {
key: keyof BotConfig;
value: string | number | boolean;
}
export interface AgentToolCall {
type: "image" | "search" | "websearch" | "voice" | "pdf" | "code" | "logs" | "selfcheck" | "sendmsg" | "adminpanel" | "setvip" | "setblock" | "viewmemory" | "resetmemory" | "exportstats";
param?: string;
extra?: string;
cleanResponse: string;
}
export interface LogEntry { timestamp: number; level: "info" | "warn" | "error"; message: string; context?: unknown }
export interface BucketEntry {
bucket: unknown;
lastUsed: number;
}