Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 1 addition & 46 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,6 @@ CREATE TABLE users (
CONSTRAINT users_id_fkey FOREIGN KEY (id) REFERENCES auth.users(id) ON DELETE CASCADE -- Explicit FK definition
);

-- Agents table
CREATE TABLE agents (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
slug TEXT NOT NULL,
description TEXT NOT NULL,
avatar_url TEXT,
system_prompt TEXT NOT NULL,
model_preference TEXT,
is_public BOOLEAN DEFAULT false NOT NULL,
remixable BOOLEAN DEFAULT false NOT NULL,
tools_enabled BOOLEAN DEFAULT false NOT NULL,
example_inputs TEXT[],
tags TEXT[],
category TEXT,
creator_id UUID,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ,
tools TEXT[],
max_steps INTEGER,
mcp_config JSONB, -- Representing the object structure as JSONB
CONSTRAINT agents_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL -- Changed to SET NULL based on schema, could also be CASCADE
);

-- Projects table
CREATE TABLE projects (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
Expand All @@ -217,12 +193,10 @@ CREATE TABLE chats (
title TEXT,
model TEXT,
system_prompt TEXT,
agent_id UUID,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
public BOOLEAN DEFAULT FALSE NOT NULL,
CONSTRAINT chats_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT chats_agent_id_fkey FOREIGN KEY (agent_id) REFERENCES agents(id) ON DELETE SET NULL,
CONSTRAINT chats_project_id_fkey FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
);

Expand Down Expand Up @@ -281,7 +255,7 @@ CREATE TABLE user_keys (
-- ALTER TABLE users ENABLE ROW LEVEL SECURITY;
-- CREATE POLICY "Users can view their own data." ON users FOR SELECT USING (auth.uid() = id);
-- CREATE POLICY "Users can update their own data." ON users FOR UPDATE USING (auth.uid() = id);
-- ... add policies for other tables (agents, chats, messages, etc.) ...
-- ... add policies for other tables (chats, messages, etc.) ...
```

### Storage Setup
Expand All @@ -292,25 +266,6 @@ Create the buckets `chat-attachments` and `avatars` in your Supabase dashboard:
2. Click "New bucket" and create two buckets: `chat-attachments` and `avatars`
3. Configure public access permissions for both buckets

#### Agent Avatar Configuration

For agent profile pictures to work properly:

1. Create an `agents` folder inside your `avatars` bucket:

- Navigate to the `avatars` bucket
- Click "Create folder" and name it `agents`

2. Upload agent avatar images

3. Set up public access for the avatars bucket:
- Go to "Configuration" tab for the `avatars` bucket
- Under "Row Level Security (RLS)" ensure it's disabled or create a policy:
```sql
CREATE POLICY "Public Read Access" ON storage.objects
FOR SELECT USING (bucket_id = 'avatars');
```

## Ollama Setup (Local AI Models)

Ollama allows you to run AI models locally on your machine. Zola has built-in support for Ollama with automatic model detection.
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- Open-source and self-hostable
- Customizable: user system prompt, multiple layout options
- Local AI with Ollama: Run models locally with automatic model detection
- Basic agent (wip)
- Full MCP support (wip)

## Quick Start
Expand Down Expand Up @@ -57,7 +56,7 @@ docker-compose -f docker-compose.ollama.yml up

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/ibelick/zola)

To unlock features like auth, file uploads, and agents, see [INSTALL.md](./INSTALL.md).
To unlock features like auth, file uploads, see [INSTALL.md](./INSTALL.md).

## Built with

Expand Down
67 changes: 0 additions & 67 deletions app/agents/[...agentSlug]/page.tsx

This file was deleted.

57 changes: 0 additions & 57 deletions app/agents/page.tsx

This file was deleted.

19 changes: 6 additions & 13 deletions app/api/chat/api.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { saveFinalAssistantMessage } from "@/app/api/chat/db"
import { checkSpecialAgentUsage, incrementSpecialAgentUsage } from "@/lib/api"
import type {
ChatApiParams,
LogUserMessageParams,
StoreAssistantMessageParams,
SupabaseClientType,
} from "@/app/types/api.types"
import { sanitizeUserInput } from "@/lib/sanitize"
import { validateUserIdentity } from "@/lib/server/api"
import { checkUsageByModel, incrementUsageByModel } from "@/lib/usage"
import type {
SupabaseClientType,
ChatApiParams,
LogUserMessageParams,
StoreAssistantMessageParams
} from "@/app/types/api.types"

export async function validateAndTrackUsage({
userId,
Expand Down Expand Up @@ -48,12 +47,6 @@ export async function logUserMessage({
}
}

export async function trackSpecialAgentUsage(supabase: SupabaseClientType, userId: string): Promise<void> {
if (!supabase) return
await checkSpecialAgentUsage(supabase, userId)
await incrementSpecialAgentUsage(supabase, userId)
}

export async function storeAssistantMessage({
supabase,
chatId,
Expand Down
40 changes: 4 additions & 36 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { loadAgent } from "@/lib/agents/load-agent"
import { SYSTEM_PROMPT_DEFAULT } from "@/lib/config"
import { loadMCPToolsFromURL } from "@/lib/mcp/load-mcp-from-url"
import { getAllModels } from "@/lib/models"
import { getProviderForModel } from "@/lib/openproviders/provider-map"
import type { ProviderWithoutOllama } from "@/lib/user-keys"
Expand All @@ -9,14 +7,9 @@ import { Message as MessageAISDK, streamText, ToolSet } from "ai"
import {
logUserMessage,
storeAssistantMessage,
trackSpecialAgentUsage,
validateAndTrackUsage,
} from "./api"
import {
cleanMessagesForTools,
createErrorResponse,
extractErrorMessage,
} from "./utils"
import { createErrorResponse, extractErrorMessage } from "./utils"

export const maxDuration = 60

Expand All @@ -27,7 +20,6 @@ type ChatRequest = {
model: string
isAuthenticated: boolean
systemPrompt: string
agentId: string | null
enableSearch: boolean
}

Expand All @@ -40,7 +32,6 @@ export async function POST(req: Request) {
model,
isAuthenticated,
systemPrompt,
agentId,
enableSearch,
} = (await req.json()) as ChatRequest

Expand Down Expand Up @@ -71,37 +62,14 @@ export async function POST(req: Request) {
})
}

let agentConfig = null

if (agentId) {
agentConfig = await loadAgent(agentId)
}

const allModels = await getAllModels()
const modelConfig = allModels.find((m) => m.id === model)

if (!modelConfig || !modelConfig.apiSdk) {
throw new Error(`Model ${model} not found`)
}

const effectiveSystemPrompt =
agentConfig?.systemPrompt || systemPrompt || SYSTEM_PROMPT_DEFAULT

let toolsToUse = undefined

if (agentConfig?.mcpConfig) {
const { tools } = await loadMCPToolsFromURL(agentConfig.mcpConfig.server)
toolsToUse = tools
} else if (agentConfig?.tools) {
toolsToUse = agentConfig.tools
if (supabase) {
await trackSpecialAgentUsage(supabase, userId)
}
}

// Clean messages when switching between agents with different tool capabilities
const hasTools = !!toolsToUse && Object.keys(toolsToUse).length > 0
const cleanedMessages = cleanMessagesForTools(messages, hasTools)
const effectiveSystemPrompt = systemPrompt || SYSTEM_PROMPT_DEFAULT

let apiKey: string | undefined
if (isAuthenticated && userId) {
Expand All @@ -115,8 +83,8 @@ export async function POST(req: Request) {
const result = streamText({
model: modelConfig.apiSdk(apiKey, { enableSearch }),
system: effectiveSystemPrompt,
messages: cleanedMessages,
tools: toolsToUse as ToolSet,
messages: messages,
tools: {} as ToolSet,
maxSteps: 10,
onError: (err: unknown) => {
console.error("Streaming error occurred:", err)
Expand Down
Loading