### Install Dependencies and Start Database (Bash) Source: https://github.com/mail-0/zero/blob/staging/README.md This snippet demonstrates how to clone the Zero repository, install project dependencies using pnpm, and start the local PostgreSQL database using Docker Compose. It's a crucial first step for setting up the development environment. ```bash git clone https://github.com/Mail-0/Zero.git cd Zero pnpm install pnpm docker:db:up ``` -------------------------------- ### Initialize and Start Zero Application (Bash) Source: https://github.com/mail-0/zero/blob/staging/README.md This sequence of commands initializes the PostgreSQL database by pushing the schema and then starts the Zero development server. After running these, the application can be accessed via a local web browser. ```bash pnpm db:push pnpm dev ``` -------------------------------- ### Start Local PostgreSQL Database Source: https://github.com/mail-0/zero/blob/staging/README.md Initiate a local PostgreSQL instance using the provided pnpm command. This command sets up a database named 'zerodotemail' with default credentials and port. ```bash pnpm docker:db:up ``` -------------------------------- ### Run Zero Mail Scripts Source: https://github.com/mail-0/zero/blob/staging/scripts/README.md Demonstrates how to execute utility scripts for the Zero email application from the project root using pnpm. It shows the general command structure and an example for running the 'seed-style' script. ```bash # Run a script from the project root pnpm scripts [options] # Example: Run the seed-style script pnpm scripts seed-style ``` -------------------------------- ### Create New Script with cmd-ts Source: https://github.com/mail-0/zero/blob/staging/scripts/README.md A TypeScript example demonstrating how to create a new utility script using the cmd-ts library. It shows the basic structure for defining a command, its arguments, and the handler function for script logic. ```typescript import { command, option, string as stringType } from 'cmd-ts'; export const myScriptCommand = command({ name: 'my-script', description: 'Description of what my script does', args: { // Define command-line arguments param1: option({ type: stringType, long: 'param1', short: 'p', description: 'Description of param1', }), }, handler: async (inputs) => { // Script implementation console.log(`Running my script with param1: ${inputs.param1}`); // Do something useful here }, }); ``` -------------------------------- ### MCP Server Tools Integration (TypeScript) Source: https://context7.com/mail-0/zero/llms.txt Demonstrates how to connect to the MCP server and utilize available tools for AI assistant integration. This includes listing threads, getting thread details, managing read status, modifying labels, and building search queries. ```typescript const threads = await mcpClient.callTool('listThreads', { folder: 'inbox', maxResults: 10 }); const searchQuery = await mcpClient.callTool('buildGmailSearchQuery', { query: 'unread emails from last week about project updates' }); ``` -------------------------------- ### Get User Settings Source: https://context7.com/mail-0/zero/llms.txt Retrieves the current user settings and application preferences. This includes language, timezone, dynamic content settings, and more. ```typescript const settings = await api.settings.get.query(); // { settings: { // language: string, // timezone: string, // dynamicContent: boolean, // externalImages: 'always' | 'never' | 'ask', // customPrompt: string, // trustedSenders: string[], // commandPaletteEnabled: boolean, // undoSendEnabled: boolean, // ... // }} ``` -------------------------------- ### Register and Execute Dynamic Workflows (TypeScript) Source: https://github.com/mail-0/zero/blob/staging/apps/server/src/thread-workflow-utils/README.md Demonstrates how to dynamically discover and execute all registered workflows. The workflow engine provides methods to get all available workflow names and to execute a specific workflow with a given context. Results and errors from the execution are returned. ```typescript // Get all available workflow names from the engine const workflowNames = workflowEngine.getWorkflowNames(); // Execute all workflows dynamically for (const workflowName of workflowNames) { const { results, errors } = await workflowEngine.executeWorkflow(workflowName, context); } ``` -------------------------------- ### Get Thread Details Source: https://context7.com/mail-0/zero/llms.txt Fetches complete thread information including all messages, read status, and associated labels. ```APIDOC ## POST /mail/getThread ### Description Fetches complete thread information including all messages, read status, and associated labels. ### Method POST ### Endpoint /mail/getThread ### Parameters #### Request Body - **id** (string) - Required - The unique identifier of the thread to retrieve. ### Request Example ```json { "id": "thread_abc123" } ``` ### Response #### Success Response (200) - **messages** (array of objects) - An array of parsed message objects within the thread. - **latest** (object | undefined) - The latest message in the thread. - **hasUnread** (boolean) - Indicates if the thread has any unread messages. - **totalReplies** (integer) - The total number of replies in the thread. - **labels** (array of objects) - A list of labels associated with the thread, each with: - **id** (string) - The label ID. - **name** (string) - The label name. #### Response Example ```json { "messages": [ { "id": "message_1", "threadId": "thread_abc123", "sender": { "email": "sender@example.com", "name": "Sender Name" }, "to": [{ "email": "recipient@example.com", "name": "Recipient Name" }], "subject": "Original Subject", "decodedBody": "

This is the email body.

", "date": "2023-10-27T10:00:00Z", "isUnread": false } ], "latest": { "id": "message_1", "threadId": "thread_abc123", "sender": { "email": "sender@example.com", "name": "Sender Name" }, "to": [{ "email": "recipient@example.com", "name": "Recipient Name" }], "subject": "Original Subject", "decodedBody": "

This is the email body.

", "date": "2023-10-27T10:00:00Z", "isUnread": false }, "hasUnread": false, "totalReplies": 1, "labels": [ { "id": "label_1", "name": "INBOX" } ] } ``` ``` -------------------------------- ### Get and List Email Drafts Source: https://context7.com/mail-0/zero/llms.txt Retrieves individual email drafts by ID or lists all drafts with pagination support. Allows specifying the maximum number of results and a page token for fetching subsequent pages. ```typescript // Get a specific draft const draft = await api.drafts.get.query({ id: 'draft_123' }); // { // id: string, // to: string[], // subject: string, // content: string, // cc: string[], // bcc: string[] // } ``` ```typescript // List all drafts const drafts = await api.drafts.list.query({ maxResults: 20, pageToken: '' // for pagination }); ``` -------------------------------- ### Get Email Attachments Source: https://context7.com/mail-0/zero/llms.txt Retrieves attachments from a specific email message. ```APIDOC ## GET /mail/getMessageAttachments ### Description Retrieves attachments from a specific email message. ### Method GET ### Endpoint /mail/getMessageAttachments ### Parameters #### Query Parameters - **messageId** (string) - Required - The ID of the message to retrieve attachments from. ### Request Example ```json { "messageId": "message_123" } ``` ### Response #### Success Response (200) - **attachments** (array) - An array of attachment objects. - **filename** (string) - The name of the attachment file. - **mimeType** (string) - The MIME type of the attachment. - **size** (number) - The size of the attachment in bytes. - **attachmentId** (string) - The unique identifier for the attachment. - **body** (string) - The attachment content, base64 encoded. #### Response Example ```json [ { "filename": "document.pdf", "mimeType": "application/pdf", "size": 102400, "attachmentId": "att_xyz789", "body": "JVBERi0xLjQKJc..." } ] ``` ``` -------------------------------- ### Set Up Environment Variables (Bash) Source: https://github.com/mail-0/zero/blob/staging/README.md These commands are used to manage environment variables for the Zero project. 'pnpm nizzy env' sets up the necessary environment files, and 'pnpm nizzy sync' synchronizes these variables with type definitions, ensuring consistency across the application. ```bash pnpm nizzy env pnpm nizzy sync ``` -------------------------------- ### Get Email Attachments Source: https://context7.com/mail-0/zero/llms.txt Retrieves attachments from a specific email message. Requires the message ID and returns a list of attachments with their details and base64 encoded body. ```typescript const attachments = await api.mail.getMessageAttachments.query({ messageId: 'message_123' }); // Response structure // [{ // filename: string, // mimeType: string, // size: number, // attachmentId: string, // body: string (base64 encoded) // }] ``` -------------------------------- ### Environment Configuration (Bash) Source: https://context7.com/mail-0/zero/llms.txt Lists the required environment variables for deploying the Zero application. This includes application URLs, database connection strings, and authentication secrets. ```bash # Application URLs VITE_PUBLIC_APP_URL=http://localhost:3000 VITE_PUBLIC_BACKEND_URL=http://localhost:8787 # Database DATABASE_URL="postgresql://postgres:postgres@localhost:5432/zerodotemail" # Authentication BETTER_AUTH_SECRET=your-secret-key # Use: openssl rand -hex 32 COOKIE_DOMAIN="localhost" ``` -------------------------------- ### Run Custom Script with Arguments Source: https://github.com/mail-0/zero/blob/staging/scripts/README.md Demonstrates how to execute a custom script ('my-script') that has been added and registered within the Zero email application's script system. It shows passing a required argument using the command line. ```bash pnpm scripts my-script --param1 value ``` -------------------------------- ### Environment Configuration Source: https://context7.com/mail-0/zero/llms.txt Lists the required environment variables for deploying and running the Zero application. ```APIDOC ## Environment Configuration ### Description This section details the essential environment variables required for the deployment and operation of the Zero application. ### Required Environment Variables: ```bash # Application URLs VITE_PUBLIC_APP_URL=http://localhost:3000 VITE_PUBLIC_BACKEND_URL=http://localhost:8787 # Database DATABASE_URL="postgresql://postgres:postgres@localhost:5432/zerodotemail" # Authentication BETTER_AUTH_SECRET=your-secret-key # Use: openssl rand -hex 32 COOKIE_DOMAIN="localhost" ``` ``` -------------------------------- ### Local PostgreSQL Database Connection String Source: https://github.com/mail-0/zero/blob/staging/README.md Specify the DATABASE_URL in the .env file for local development to connect to the PostgreSQL instance. Ensure the connection string matches the database configuration. ```env DATABASE_URL="postgresql://postgres:postgres@localhost:5432/zerodotemail" ``` -------------------------------- ### Get Thread Details with Zero Mail API Source: https://context7.com/mail-0/zero/llms.txt Fetches comprehensive details for a specific email thread, including all associated messages, read status, and labels. This is used to display the full conversation when a user selects a thread. The response includes message content and metadata. ```typescript // Get a specific thread by ID const thread = await api.mail.get.query({ id: 'thread_abc123' }); // Response structure // { // messages: ParsedMessage[], // latest: ParsedMessage | undefined, // hasUnread: boolean, // totalReplies: number, // labels: [{ id: string, name: string }] // } // Access thread messages thread.messages.forEach(message => { console.log(`From: ${message.sender.email}`); console.log(`Subject: ${message.subject}`); console.log(`Body: ${message.decodedBody}`); }); ``` -------------------------------- ### Settings API Source: https://context7.com/mail-0/zero/llms.txt Manages user preferences and application settings. ```APIDOC ## Settings API Manages user preferences and application settings. ### Get Settings Retrieves current user settings with defaults. #### GET /settings ##### Description Retrieves current user settings with defaults. ##### Method GET ##### Endpoint /settings ##### Response ###### Success Response (200) - **settings** (object) - An object containing user settings. - **language** (string) - User's preferred language. - **timezone** (string) - User's timezone. - **dynamicContent** (boolean) - Whether dynamic content is enabled. - **externalImages** (string) - Policy for loading external images ('always', 'never', 'ask'). - **customPrompt** (string) - Custom prompt for AI features. - **trustedSenders** (array of strings) - List of trusted sender email addresses. - **commandPaletteEnabled** (boolean) - Whether the command palette is enabled. - **undoSendEnabled** (boolean) - Whether undo send is enabled. - ... (other settings) ###### Response Example ```json { "settings": { "language": "en-US", "timezone": "America/Los_Angeles", "dynamicContent": true, "externalImages": "ask", "customPrompt": "", "trustedSenders": [], "commandPaletteEnabled": true, "undoSendEnabled": false } } ``` ### Save Settings Updates user preferences (partial updates supported). #### PUT /settings ##### Description Updates user preferences (partial updates supported). ##### Method PUT ##### Endpoint /settings ##### Parameters ###### Request Body - **timezone** (string) - Optional - User's timezone. - **externalImages** (string) - Optional - Policy for loading external images ('always', 'never', 'ask'). - **undoSendEnabled** (boolean) - Optional - Whether undo send is enabled. - **trustedSenders** (array of strings) - Optional - List of trusted sender email addresses. - ... (other settable fields) ##### Request Example ```json { "timezone": "America/New_York", "externalImages": "always", "undoSendEnabled": true, "trustedSenders": ["trusted@company.com"] } ``` ##### Response ###### Success Response (200) - **success** (boolean) - Indicates if the settings were saved successfully. ###### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Database Management Commands Source: https://github.com/mail-0/zero/blob/staging/README.md A collection of pnpm commands for managing the PostgreSQL database, including pushing schema changes, generating migrations, applying migrations, and accessing the database studio. ```bash pnpm db:push pnpm db:generate pnpm db:migrate pnpm db:studio ``` -------------------------------- ### Define and Register a Workflow Definition (TypeScript) Source: https://github.com/mail-0/zero/blob/staging/apps/server/src/thread-workflow-utils/README.md Demonstrates how to define a workflow using the WorkflowDefinition type, including its name, description, and a series of steps. Each step has an ID, name, description, enablement status, an optional condition, and an action. The defined workflow is then registered with the workflow engine. ```typescript const autoDraftWorkflow: WorkflowDefinition = { name: 'auto-draft-generation', description: 'Automatically generates drafts for threads that require responses', steps: [ { id: 'check-draft-eligibility', name: 'Check Draft Eligibility', description: 'Determines if a draft should be generated for this thread', enabled: true, condition: async (context) => { return shouldGenerateDraft(context.thread, context.foundConnection); }, action: async (context) => { console.log('[WORKFLOW_ENGINE] Thread eligible for draft generation', context); return { eligible: true }; }, }, // ... more steps ], }; engine.registerWorkflow(autoDraftWorkflow); ``` -------------------------------- ### Configure Google OAuth Credentials Source: https://github.com/mail-0/zero/blob/staging/README.md Set up Google OAuth by obtaining client ID and secret from Google Cloud Console. These credentials, along with redirect URIs, are added to the .env file for Gmail integration. ```env GOOGLE_CLIENT_ID=your_client_id GOOGLE_CLIENT_SECRET=your_client_secret ``` -------------------------------- ### Seed Style Script Usage Source: https://github.com/mail-0/zero/blob/staging/scripts/README.md Illustrates the command-line usage for the 'seed-style' script in the Zero email application. It covers both interactive mode and running with specific command-line options for seeding or resetting the style matrix. ```bash # Interactive mode (will prompt for options) pnpm scripts seed-style # With command-line options pnpm scripts seed-style seed --connection-id --style