Initial open-source release
This commit is contained in:
34
src/lib/chat.ts
Normal file
34
src/lib/chat.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { Message } from "ai";
|
||||
import { IpcClient } from "../ipc/ipc_client";
|
||||
import type { ChatSummary } from "./schemas";
|
||||
import type { CreateAppParams, CreateAppResult } from "../ipc/ipc_types";
|
||||
|
||||
/**
|
||||
* Create a new app with an initial chat and prompt
|
||||
* @param params Object containing name, path, and initialPrompt
|
||||
* @returns The created app and chatId
|
||||
*/
|
||||
export async function createApp(
|
||||
params: CreateAppParams
|
||||
): Promise<CreateAppResult> {
|
||||
try {
|
||||
return await IpcClient.getInstance().createApp(params);
|
||||
} catch (error) {
|
||||
console.error("[CHAT] Error creating app:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all chats from the database
|
||||
* @param appId Optional app ID to filter chats by app
|
||||
* @returns Array of chat summaries with id, title, and createdAt
|
||||
*/
|
||||
export async function getAllChats(appId?: number): Promise<ChatSummary[]> {
|
||||
try {
|
||||
return await IpcClient.getInstance().getChats(appId);
|
||||
} catch (error) {
|
||||
console.error("[CHAT] Error getting all chats:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
75
src/lib/schemas.ts
Normal file
75
src/lib/schemas.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Zod schema for chat summary objects returned by the get-chats IPC
|
||||
*/
|
||||
export const ChatSummarySchema = z.object({
|
||||
id: z.number(),
|
||||
appId: z.number(),
|
||||
title: z.string().nullable(),
|
||||
createdAt: z.date(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Type derived from the ChatSummarySchema
|
||||
*/
|
||||
export type ChatSummary = z.infer<typeof ChatSummarySchema>;
|
||||
|
||||
/**
|
||||
* Zod schema for an array of chat summaries
|
||||
*/
|
||||
export const ChatSummariesSchema = z.array(ChatSummarySchema);
|
||||
|
||||
/**
|
||||
* Zod schema for model provider
|
||||
*/
|
||||
export const ModelProviderSchema = z.enum([
|
||||
"openai",
|
||||
"anthropic",
|
||||
"google",
|
||||
"auto",
|
||||
"openrouter",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Type derived from the ModelProviderSchema
|
||||
*/
|
||||
export type ModelProvider = z.infer<typeof ModelProviderSchema>;
|
||||
|
||||
/**
|
||||
* Zod schema for large language model configuration
|
||||
*/
|
||||
export const LargeLanguageModelSchema = z.object({
|
||||
name: z.string(),
|
||||
provider: ModelProviderSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* Type derived from the LargeLanguageModelSchema
|
||||
*/
|
||||
export type LargeLanguageModel = z.infer<typeof LargeLanguageModelSchema>;
|
||||
|
||||
/**
|
||||
* Zod schema for provider settings
|
||||
*/
|
||||
export const ProviderSettingSchema = z.object({
|
||||
apiKey: z.string().nullable(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Type derived from the ProviderSettingSchema
|
||||
*/
|
||||
export type ProviderSetting = z.infer<typeof ProviderSettingSchema>;
|
||||
|
||||
/**
|
||||
* Zod schema for user settings
|
||||
*/
|
||||
export const UserSettingsSchema = z.object({
|
||||
selectedModel: LargeLanguageModelSchema,
|
||||
providerSettings: z.record(z.string(), ProviderSettingSchema),
|
||||
});
|
||||
|
||||
/**
|
||||
* Type derived from the UserSettingsSchema
|
||||
*/
|
||||
export type UserSettings = z.infer<typeof UserSettingsSchema>;
|
||||
53
src/lib/toast.ts
Normal file
53
src/lib/toast.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { toast } from "sonner";
|
||||
|
||||
/**
|
||||
* Toast utility functions for consistent notifications across the app
|
||||
*/
|
||||
|
||||
/**
|
||||
* Show a success toast
|
||||
* @param message The message to display
|
||||
*/
|
||||
export const showSuccess = (message: string) => {
|
||||
toast.success(message);
|
||||
};
|
||||
|
||||
/**
|
||||
* Show an error toast
|
||||
* @param message The error message to display
|
||||
*/
|
||||
export const showError = (message: any) => {
|
||||
toast.error(message.toString());
|
||||
console.error(message);
|
||||
};
|
||||
|
||||
/**
|
||||
* Show an info toast
|
||||
* @param message The info message to display
|
||||
*/
|
||||
export const showInfo = (message: string) => {
|
||||
toast.info(message);
|
||||
};
|
||||
|
||||
/**
|
||||
* Show a loading toast that can be updated with success/error
|
||||
* @param loadingMessage The message to show while loading
|
||||
* @param promise The promise to track
|
||||
* @param successMessage Optional success message
|
||||
* @param errorMessage Optional error message
|
||||
*/
|
||||
export const showLoading = <T>(
|
||||
loadingMessage: string,
|
||||
promise: Promise<T>,
|
||||
successMessage?: string,
|
||||
errorMessage?: string
|
||||
) => {
|
||||
return toast.promise(promise, {
|
||||
loading: loadingMessage,
|
||||
success: (data) => successMessage || "Operation completed successfully",
|
||||
error: (err) => errorMessage || `Error: ${err.message || "Unknown error"}`,
|
||||
});
|
||||
};
|
||||
|
||||
// Re-export for direct use
|
||||
export { toast };
|
||||
152
src/lib/utils.ts
Normal file
152
src/lib/utils.ts
Normal file
@@ -0,0 +1,152 @@
|
||||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a cute app name like "blue-fox" or "jumping-zebra"
|
||||
*/
|
||||
export function generateCuteAppName(): string {
|
||||
const adjectives = [
|
||||
"happy",
|
||||
"gentle",
|
||||
"brave",
|
||||
"clever",
|
||||
"swift",
|
||||
"bright",
|
||||
"calm",
|
||||
"nimble",
|
||||
"sleepy",
|
||||
"fluffy",
|
||||
"wild",
|
||||
"tiny",
|
||||
"bold",
|
||||
"wise",
|
||||
"merry",
|
||||
"quick",
|
||||
"busy",
|
||||
"silent",
|
||||
"cozy",
|
||||
"jolly",
|
||||
"playful",
|
||||
"friendly",
|
||||
"curious",
|
||||
"peaceful",
|
||||
"silly",
|
||||
"dazzling",
|
||||
"graceful",
|
||||
"elegant",
|
||||
"cosmic",
|
||||
"whispering",
|
||||
"dancing",
|
||||
"sparkling",
|
||||
"mystical",
|
||||
"vibrant",
|
||||
"radiant",
|
||||
"dreamy",
|
||||
"patient",
|
||||
"energetic",
|
||||
"vigilant",
|
||||
"sincere",
|
||||
"electric",
|
||||
"stellar",
|
||||
"lunar",
|
||||
"serene",
|
||||
"mighty",
|
||||
"magical",
|
||||
"neon",
|
||||
"azure",
|
||||
"crimson",
|
||||
"emerald",
|
||||
"golden",
|
||||
"jade",
|
||||
"crystal",
|
||||
"snuggly",
|
||||
"glowing",
|
||||
"wandering",
|
||||
"whistling",
|
||||
"bubbling",
|
||||
"floating",
|
||||
"flying",
|
||||
"hopping",
|
||||
];
|
||||
|
||||
const animals = [
|
||||
"fox",
|
||||
"panda",
|
||||
"rabbit",
|
||||
"wolf",
|
||||
"bear",
|
||||
"owl",
|
||||
"koala",
|
||||
"beaver",
|
||||
"ferret",
|
||||
"squirrel",
|
||||
"zebra",
|
||||
"tiger",
|
||||
"lynx",
|
||||
"lemur",
|
||||
"penguin",
|
||||
"otter",
|
||||
"hedgehog",
|
||||
"deer",
|
||||
"badger",
|
||||
"raccoon",
|
||||
"turtle",
|
||||
"dolphin",
|
||||
"eagle",
|
||||
"falcon",
|
||||
"parrot",
|
||||
"capybara",
|
||||
"axolotl",
|
||||
"narwhal",
|
||||
"wombat",
|
||||
"meerkat",
|
||||
"platypus",
|
||||
"mongoose",
|
||||
"chinchilla",
|
||||
"quokka",
|
||||
"alpaca",
|
||||
"chameleon",
|
||||
"ocelot",
|
||||
"manatee",
|
||||
"puffin",
|
||||
"shiba",
|
||||
"sloth",
|
||||
"gecko",
|
||||
"hummingbird",
|
||||
"mantis",
|
||||
"jellyfish",
|
||||
"pangolin",
|
||||
"okapi",
|
||||
"binturong",
|
||||
"tardigrade",
|
||||
"beluga",
|
||||
"kiwi",
|
||||
"octopus",
|
||||
"salamander",
|
||||
"seahorse",
|
||||
"kookaburra",
|
||||
"gibbon",
|
||||
"jackrabbit",
|
||||
"lobster",
|
||||
"iguana",
|
||||
"tamarin",
|
||||
"armadillo",
|
||||
"starfish",
|
||||
"walrus",
|
||||
"phoenix",
|
||||
"griffin",
|
||||
"dragon",
|
||||
"unicorn",
|
||||
"kraken",
|
||||
];
|
||||
|
||||
const randomAdjective =
|
||||
adjectives[Math.floor(Math.random() * adjectives.length)];
|
||||
const randomAnimal = animals[Math.floor(Math.random() * animals.length)];
|
||||
|
||||
return `${randomAdjective}-${randomAnimal}`;
|
||||
}
|
||||
Reference in New Issue
Block a user