+```
+
+---
+
+## BASIC AUTOMATION FILES
+
+### Tools (`.gbdialog/tools/*.bas`)
+
+Voice/chat command handlers:
+
+```basic
+HEAR "check weather", "weather today", "what's the weather"
+ city = ASK "Which city?"
+ data = GET "https://api.weather.com/v1/current?city=" + city
+ TALK "The weather in " + city + " is " + data.description
+END HEAR
+
+HEAR "send report to", "email report"
+ recipient = ASK "Email address?"
+ report = GET FROM "daily_reports" WHERE date = TODAY
+ SEND MAIL TO recipient WITH SUBJECT "Daily Report" BODY report
+ TALK "Report sent to " + recipient
+END HEAR
+
+HEAR "create customer", "add new customer"
+ name = ASK "Customer name?"
+ email = ASK "Email address?"
+ SAVE TO "customers" WITH name, email
+ TALK "Customer " + name + " created successfully"
+END HEAR
+```
+
+### Schedulers (`.gbdialog/schedulers/*.bas`)
+
+Automated scheduled tasks:
+
+```basic
+SET SCHEDULE "0 9 * * *"
+ ' Runs at 9 AM daily
+ pending = GET FROM "orders" WHERE status = "pending"
+ FOR EACH order IN pending
+ SEND MAIL TO order.customer_email
+ WITH SUBJECT "Order Reminder"
+ BODY "Your order #" + order.id + " is pending"
+ NEXT
+END SCHEDULE
+
+SET SCHEDULE "0 0 * * 0"
+ ' Runs every Sunday at midnight
+ sales = GET FROM "sales" WHERE week = LAST_WEEK
+ summary = LLM "Summarize these sales: " + sales
+ SEND MAIL TO "manager@company.com"
+ WITH SUBJECT "Weekly Sales Summary"
+ BODY summary
+END SCHEDULE
+
+SET SCHEDULE "*/15 * * * *"
+ ' Runs every 15 minutes
+ alerts = GET FROM "monitoring" WHERE status = "critical"
+ IF COUNT(alerts) > 0 THEN
+ TALK TO CHANNEL "ops" MESSAGE "ALERT: " + COUNT(alerts) + " critical issues"
+ END IF
+END SCHEDULE
+```
+
+### Events (`.gbdialog/events/*.bas`)
+
+React to data changes:
+
+```basic
+ON CHANGE "customers"
+ new_customer = CHANGED_RECORD
+ SEND MAIL TO "sales@company.com"
+ WITH SUBJECT "New Customer: " + new_customer.name
+ BODY "A new customer has registered: " + new_customer.email
+
+ ' Add to CRM
+ POST TO "https://crm.api/contacts" WITH new_customer
+END ON
+
+ON CHANGE "orders" WHERE status = "completed"
+ order = CHANGED_RECORD
+ invoice = GENERATE DOCUMENT "invoice_template" WITH order
+ SEND MAIL TO order.customer_email
+ WITH SUBJECT "Invoice #" + order.id
+ BODY "Thank you for your order!"
+ ATTACHMENT invoice
+END ON
+```
+
+---
+
+## BASIC KEYWORDS REFERENCE
+
+### Communication
+```basic
+TALK "message" Send message to user
+TALK TO CHANNEL "name" MESSAGE "x" Send to specific channel
+ASK "question" Ask user and wait for response
+ASK "question" AS type Ask with validation (email, number, date)
+CONFIRM "question" Yes/No question
+```
+
+### Data Operations
+```basic
+GET FROM "table" Get all records
+GET FROM "table" WHERE field = val Get filtered records
+GET FROM "table" WHERE id = "uuid" Get single record
+SAVE TO "table" WITH field1, field2 Insert new record
+UPDATE "table" SET field = val WHERE id = "uuid"
+DELETE FROM "table" WHERE id = "uuid"
+```
+
+### HTTP Requests
+```basic
+GET "url" HTTP GET
+POST TO "url" WITH data HTTP POST
+PUT TO "url" WITH data HTTP PUT
+DELETE "url" HTTP DELETE
+```
+
+### Email
+```basic
+SEND MAIL TO "email" WITH SUBJECT "subj" BODY "body"
+SEND MAIL TO "email" WITH SUBJECT "subj" BODY "body" ATTACHMENT "path"
+```
+
+### Files
+```basic
+UPLOAD "local_path" TO "drive_path"
+DOWNLOAD "drive_path" TO "local_path"
+LIST FILES IN "folder"
+DELETE FILE "path"
+```
+
+### AI/LLM
+```basic
+result = LLM "prompt" Generate text
+result = LLM "prompt" WITH CONTEXT data
+image = GENERATE IMAGE "prompt" Generate image
+summary = SUMMARIZE document Summarize text
+translated = TRANSLATE text TO "es" Translate text
+```
+
+### Control Flow
+```basic
+IF condition THEN ... END IF
+IF condition THEN ... ELSE ... END IF
+FOR EACH item IN collection ... NEXT
+FOR i = 1 TO 10 ... NEXT
+WHILE condition ... END WHILE
+WAIT seconds Pause execution
+```
+
+### Variables
+```basic
+SET variable = value
+SET variable = ASK "question"
+SET variable = GET FROM "table"
+variable = expression
+```
+
+### Dates
+```basic
+TODAY Current date
+NOW Current datetime
+YESTERDAY Yesterday's date
+LAST_WEEK Last week date range
+FORMAT date AS "YYYY-MM-DD" Format date
+```
+
+---
+
+## GENERATED APP STRUCTURE
+
+When generating an app, create these files:
+
+```
+{app_name}/
+├── index.html Dashboard/home page
+├── styles.css All CSS styles
+├── designer.js Designer chat widget (auto-included)
+├── {table}.html List page for each table
+├── {table}_form.html Create/edit form for each table
+└── app.js Optional custom JavaScript
+```
+
+### Required HTML Head
+
+Every HTML page MUST include:
+
+```html
+
+
+
+
+
+ Page Title
+
+
+
+
+```
+
+---
+
+## RESPONSE FORMAT
+
+When generating an app, respond with JSON:
+
+```json
+{
+ "name": "app-name-lowercase-dashes",
+ "description": "What this app does",
+ "domain": "custom|healthcare|sales|inventory|booking|etc",
+ "tables": [
+ {
+ "name": "table_name",
+ "fields": [
+ {"name": "id", "type": "guid", "nullable": false},
+ {"name": "created_at", "type": "datetime", "nullable": false},
+ {"name": "updated_at", "type": "datetime", "nullable": false},
+ {"name": "field_name", "type": "string", "nullable": true}
+ ]
+ }
+ ],
+ "pages": [
+ {
+ "filename": "index.html",
+ "title": "Dashboard",
+ "html": "complete HTML document"
+ }
+ ],
+ "tools": [
+ {
+ "name": "tool_name",
+ "triggers": ["phrase1", "phrase2"],
+ "basic_code": "BASIC code"
+ }
+ ],
+ "schedulers": [
+ {
+ "name": "scheduler_name",
+ "schedule": "0 9 * * *",
+ "basic_code": "BASIC code"
+ }
+ ],
+ "css": "complete CSS styles",
+ "custom_js": "optional JavaScript"
+}
+```
+
+### Field Types
+
+- `guid` - UUID primary key
+- `string` - VARCHAR(255)
+- `text` - TEXT (long content)
+- `integer` - INT
+- `decimal` - DECIMAL(10,2)
+- `boolean` - BOOLEAN
+- `date` - DATE
+- `datetime` - TIMESTAMP
+- `json` - JSONB
+
+---
+
+## EXAMPLES
+
+### Simple Calculator (No Database)
+
+User: "Create a pink calculator"
+
+Response: Beautiful calculator UI with pink theme, working JavaScript calculations, no tables needed.
+
+### CRM Application (With Database)
+
+User: "Create a CRM for managing customers and deals"
+
+Response:
+- Tables: customers, deals, activities, notes
+- Pages: Dashboard with stats, customer list/form, deal pipeline, activity log
+- Tools: "add customer", "log activity"
+- CSS: Professional business theme
+
+### Booking System
+
+User: "Create appointment booking for a dental clinic"
+
+Response:
+- Tables: patients, dentists, appointments, services
+- Pages: Calendar view, patient list, appointment form
+- Schedulers: Daily reminder emails, weekly availability report
+- Tools: "book appointment", "check availability"
+
+---
+
+## IMPORTANT RULES
+
+1. **Always use HTMX** for API calls - NO fetch() or XMLHttpRequest in HTML
+2. **Include designer.js** in all pages for AI modification capability
+3. **Make it beautiful** - Use modern CSS, proper spacing, nice colors
+4. **Make it functional** - All buttons should work, forms should submit
+5. **Use the APIs** - Connect to /api/db/ for data operations
+6. **Be complete** - Generate all necessary pages, not just stubs
+7. **Match the request** - If user wants pink, make it pink
+8. **Tables are optional** - Simple tools don't need database tables
\ No newline at end of file
diff --git a/src/basic/keywords/app_generator.rs b/src/basic/keywords/app_generator.rs
index 38b4a1647..652889cd7 100644
--- a/src/basic/keywords/app_generator.rs
+++ b/src/basic/keywords/app_generator.rs
@@ -119,11 +119,8 @@ impl AppGenerator {
let pages = self.generate_htmx_pages(&structure)?;
trace!("Generated {} pages", pages.len());
- // Get bot name for S3 bucket
let bot_name = self.get_bot_name(session.bot_id)?;
let bucket_name = format!("{}.gbai", bot_name.to_lowercase());
-
- // Write to S3 drive: {bucket}/.gbdrive/apps/{app_name}/
let drive_app_path = format!(".gbdrive/apps/{}", structure.name);
for page in &pages {
@@ -132,6 +129,14 @@ impl AppGenerator {
.await?;
}
+ let designer_js = self.generate_designer_js();
+ self.write_to_drive(
+ &bucket_name,
+ &format!("{}/designer.js", drive_app_path),
+ &designer_js,
+ )
+ .await?;
+
let css_content = self.generate_app_css();
self.write_to_drive(
&bucket_name,
@@ -140,7 +145,6 @@ impl AppGenerator {
)
.await?;
- // Tools go to {bucket}/.gbdialog/tools/
let tools = self.generate_tools(&structure)?;
for tool in &tools {
let tool_path = format!(".gbdialog/tools/{}", tool.filename);
@@ -148,7 +152,6 @@ impl AppGenerator {
.await?;
}
- // Schedulers go to {bucket}/.gbdialog/schedulers/
let schedulers = self.generate_schedulers(&structure)?;
for scheduler in &schedulers {
let scheduler_path = format!(".gbdialog/schedulers/{}", scheduler.filename);
@@ -156,7 +159,6 @@ impl AppGenerator {
.await?;
}
- // Sync app to SITE_ROOT for serving
self.sync_app_to_site_root(&bucket_name, &structure.name, session.bot_id)
.await?;
@@ -177,40 +179,130 @@ impl AppGenerator {
})
}
- /// Use LLM to analyze app requirements and generate structure
+ fn get_platform_capabilities_prompt(&self) -> &'static str {
+ r##"
+GENERAL BOTS APP GENERATOR - PLATFORM CAPABILITIES
+
+AVAILABLE REST APIs:
+
+DATABASE API (/api/db/):
+- GET /api/db/TABLE - List records (query: limit, offset, order_by, order_dir, search, field=value)
+- GET /api/db/TABLE/ID - Get single record
+- GET /api/db/TABLE/count - Get record count
+- POST /api/db/TABLE - Create record (JSON body)
+- PUT /api/db/TABLE/ID - Update record (JSON body)
+- DELETE /api/db/TABLE/ID - Delete record
+
+FILE STORAGE API (/api/drive/):
+- GET /api/drive/list?path=/folder - List files
+- GET /api/drive/download?path=/file.ext - Download file
+- POST /api/drive/upload - Upload (multipart: file, path)
+- DELETE /api/drive/delete?path=/file.ext - Delete file
+
+AUTOTASK API (/api/autotask/):
+- POST /api/autotask/create - Create task {"intent": "..."}
+- GET /api/autotask/list - List tasks
+- GET /api/autotask/stats - Get statistics
+- GET /api/autotask/pending - Get pending items
+
+DESIGNER API (/api/designer/):
+- POST /api/designer/modify - AI modify app {"app_name", "current_page", "message"}
+
+COMMUNICATION APIs:
+- POST /api/mail/send - {"to", "subject", "body"}
+- POST /api/whatsapp/send - {"to": "+123...", "message"}
+- POST /api/llm/generate - {"prompt", "max_tokens"}
+- POST /api/llm/image - {"prompt", "size"}
+
+HTMX ATTRIBUTES:
+- hx-get, hx-post, hx-put, hx-delete - HTTP methods
+- hx-target="#id" - Where to put response
+- hx-swap="innerHTML|outerHTML|beforeend|delete" - How to insert
+- hx-trigger="click|submit|load|every 5s|keyup changed delay:300ms" - When to fire
+- hx-indicator="#spinner" - Loading indicator
+- hx-confirm="Are you sure?" - Confirmation dialog
+
+BASIC AUTOMATION (.bas files):
+
+Tools (.gbdialog/tools/*.bas):
+HEAR "phrase1", "phrase2"
+ result = GET FROM "table"
+ TALK "Response: " + result
+END HEAR
+
+Schedulers (.gbdialog/schedulers/*.bas):
+SET SCHEDULE "0 9 * * *"
+ data = GET FROM "reports"
+ SEND MAIL TO "email" WITH SUBJECT "Daily" BODY data
+END SCHEDULE
+
+BASIC KEYWORDS:
+- TALK "message" - Send message
+- ASK "question" - Get user input
+- GET FROM "table" WHERE field=val - Query database
+- SAVE TO "table" WITH field1, field2 - Insert record
+- SEND MAIL TO "x" WITH SUBJECT "y" BODY "z"
+- result = LLM "prompt" - AI text generation
+- image = GENERATE IMAGE "prompt" - AI image generation
+
+REQUIRED HTML HEAD (all pages must include):
+- link rel="stylesheet" href="styles.css"
+- script src="/js/vendor/htmx.min.js"
+- script src="designer.js" defer
+
+FIELD TYPES: guid, string, text, integer, decimal, boolean, date, datetime, json
+
+RULES:
+1. Always use HTMX for API calls - NO fetch() in HTML
+2. Include designer.js in ALL pages
+3. Make it beautiful and fully functional
+4. Tables are optional - simple apps (calculator, timer) dont need them
+"##
+ }
+
async fn analyze_app_requirements_with_llm(
&self,
intent: &str,
) -> Result> {
+ let capabilities = self.get_platform_capabilities_prompt();
+
let prompt = format!(
- r#"Analyze this user request and design an application structure.
+ r#"You are an expert app generator for General Bots platform.
-User Request: "{intent}"
+{capabilities}
-Generate a JSON response with the application structure:
+USER REQUEST: "{intent}"
+
+Generate a complete application. For simple apps (calculator, timer, game), you can use empty tables array.
+For data apps (CRM, inventory), design appropriate tables.
+
+Respond with JSON:
{{
- "name": "short_app_name (lowercase, no spaces)",
- "description": "Brief description of the app",
- "domain": "industry domain (healthcare, sales, inventory, booking, etc.)",
+ "name": "app-name-lowercase-dashes",
+ "description": "What this app does",
+ "domain": "custom|healthcare|sales|inventory|booking|etc",
"tables": [
{{
"name": "table_name",
"fields": [
- {{"name": "field_name", "type": "string|integer|decimal|boolean|date|datetime|text|guid", "nullable": true/false, "reference": "other_table or null"}}
+ {{"name": "id", "type": "guid", "nullable": false}},
+ {{"name": "field_name", "type": "string|integer|decimal|boolean|date|datetime|text", "nullable": true, "reference": "other_table or null"}}
]
}}
],
- "features": ["crud", "search", "dashboard", "reports", "etc"]
+ "features": ["list of features"],
+ "custom_html": "OPTIONAL: For non-CRUD apps like calculators, provide complete HTML here",
+ "custom_css": "OPTIONAL: Custom CSS styles",
+ "custom_js": "OPTIONAL: Custom JavaScript"
}}
-Guidelines:
-- Every table should have id (guid), created_at (datetime), updated_at (datetime)
-- Use snake_case for table and field names
-- Include relationships between tables using _id suffix fields
-- Design 2-5 tables based on the request complexity
-- Include relevant fields for the domain
+IMPORTANT:
+- For simple tools (calculator, converter, timer): use custom_html/css/js, tables can be empty []
+- For data apps (CRM, booking): design tables, custom_* fields are optional
+- Always include id, created_at, updated_at in tables
+- Make it beautiful and fully functional
-Respond ONLY with valid JSON."#
+Respond with valid JSON only."#
);
let response = self.call_llm(&prompt).await?;
@@ -1002,6 +1094,7 @@ Respond ONLY with valid JSON."#
let _ = writeln!(html, " {}", structure.name);
let _ = writeln!(html, " ");
let _ = writeln!(html, " ");
+ let _ = writeln!(html, " ");
let _ = writeln!(html, "");
let _ = writeln!(html, "");
let _ = writeln!(html, " ");
@@ -1048,6 +1141,7 @@ Respond ONLY with valid JSON."#
let _ = writeln!(html, " {table_name} - List");
let _ = writeln!(html, " ");
let _ = writeln!(html, " ");
+ let _ = writeln!(html, " ");
let _ = writeln!(html, "");
let _ = writeln!(html, "");
let _ = writeln!(html, " ");
@@ -1103,10 +1197,11 @@ Respond ONLY with valid JSON."#
let _ = writeln!(html, " {table_name} - Form");
let _ = writeln!(html, " ");
let _ = writeln!(html, " ");
+ let _ = writeln!(html, " ");
let _ = writeln!(html, "");
let _ = writeln!(html, "");
let _ = writeln!(html, " ");
- let _ = writeln!(html, "