Files
ERitors-Scribe-Desktop/lib/models/QuillSense.ts
natreex b4eafca3bc Add comprehensive models and script for handling inline scripts and structured data
- Implement `remove-inline-scripts.js` to externalize Next.js inline scripts, enhancing CSP compliance.
- Add models for `Book`, `Character`, `Story`, `Editor`, `System`, and `BookSerie` with relevant properties and utilities.
- Include macOS entitlements plist for app development with advanced permissions.
- Add utility functions to handle script hashing, cookie management, and content formatting.
2025-11-16 19:56:14 -05:00

129 lines
3.3 KiB
TypeScript

import User, {Subscription} from "@/lib/models/User";
import {SessionProps} from "@/lib/models/Session";
export type MessageType = "user" | "model";
export type QSView = 'list' | 'chat' | 'ghostwritter' | 'dictionary' | 'synonyms' | 'conjugator' | 'inspiration'
export type ConversationType = 'dictionary' | 'synonyms' | 'conjugator' | 'chatbot' | 'inspire';
export interface Message {
id: number;
type: MessageType;
message: string;
date: string;
}
export interface Conversation {
id: string;
title?: string;
date?: string;
type?: ConversationType;
messages: Message[];
status: number;
totalPrice?: number;
}
export interface AIGeneratedText {
totalTokens: number;
totalPrice: number;
response: string;
}
export interface AIResponseWithCredits<T> {
useYourKey: boolean;
totalPrice: number;
data: T;
}
export interface AIDictionary extends AIResponseWithCredits<DictionaryAIResponse> {}
export interface AIGeneratedTextData {
totalCost: number;
response: string;
}
export interface AIGeneratedText extends AIResponseWithCredits<AIGeneratedTextData> {}
export interface AIInspire extends AIResponseWithCredits<InspireAIResponse> {}
export interface AISynonyms extends AIResponseWithCredits<SynonymsAIResponse> {}
export interface AIVerbConjugation extends AIResponseWithCredits<unknown> {}
export interface AISimpleText extends AIResponseWithCredits<string> {}
interface InspireAIResponse {
ideas: {
idea: string,
reason: string;
relatedTo: string;
}[]
}
export interface DictionaryAIResponse {
word: string;
definition: string;
example: string;
literaryUsage: string
}
export interface SynonymAI {
word: string;
context: string;
}
export interface SynonymsAIResponse {
words: SynonymAI[];
}
export interface InspirationAIIdea {
idea: string;
reason: string;
relatedTo: string;
}
export interface InspiredAIResponse {
ideas: InspirationAIIdea[];
}
export interface ConversationProps {
id: string;
mode: string;
title: string;
startDate: string;
status: number;
}
export default class QuillSense {
static getSubLevel(session: SessionProps): number {
const currentSub: Subscription | null = User.getCurrentSubscription(session?.user, 'quill-sense');
if (!currentSub) return 0;
switch (currentSub?.subTier) {
case 1:
return 1;
case 2:
return 2;
case 3:
return 3;
default:
return 0;
}
};
static isBringYourKeys(session: SessionProps): boolean {
if (!session?.user) return false;
const currentSub: Subscription | null = User.getCurrentSubscription(session?.user, 'use-your-keys');
return currentSub?.status || session.user.groupId <= 4;
}
static isGeminiEnabled(session: SessionProps): boolean {
return session.user?.apiKeys.gemini || false;
}
static isAnthropicEnabled(session: SessionProps): boolean {
return session.user?.apiKeys.anthropic || false;
}
static isOpenAIEnabled(session: SessionProps): boolean {
return session.user?.apiKeys.openai || false;
}
}