diff --git a/Cargo.lock b/Cargo.lock index a6bd9849..585f97ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1058,6 +1058,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "botlib" +version = "6.1.0" +dependencies = [ + "anyhow", + "chrono", + "diesel", + "log", + "serde", + "serde_json", + "thiserror 2.0.17", + "toml 0.8.23", + "uuid", +] + [[package]] name = "botserver" version = "6.1.0" @@ -1075,6 +1090,7 @@ dependencies = [ "axum 0.7.9", "axum-server", "base64 0.22.1", + "botlib", "bytes", "calamine", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 2f75c7fe..87f27f2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,10 @@ description = "General Bots Server - Open-source bot platform by Pragmatismo.com license = "AGPL-3.0" repository = "https://github.com/GeneralBots/BotServer" +[dependencies.botlib] +path = "../botlib" +features = ["database"] + [features] # ===== DEFAULT FEATURE SET ===== default = ["console", "chat", "automation", "tasks", "drive", "llm", "redis-cache", "progress-bars", "directory"] diff --git a/docs/GAP_ANALYSIS.md b/docs/GAP_ANALYSIS.md deleted file mode 100644 index da11604d..00000000 --- a/docs/GAP_ANALYSIS.md +++ /dev/null @@ -1,240 +0,0 @@ -# Documentation vs Source Code Gap Analysis - -> Generated analysis comparing `botserver/src/` with `botserver/docs/` - -## Summary - -| Category | Documented | Implemented | Gap | -|----------|------------|-------------|-----| -| BASIC Keywords | ~65 | ~80+ | ~15 undocumented | -| Source Modules | 18 | 24 | 6 undocumented | -| Suite Apps | 14 | 14 | ✅ Complete | -| REST APIs | 22 | 22 | ✅ Complete | - ---- - -## 1. Undocumented BASIC Keywords - -The following keywords exist in `src/basic/keywords/` but lack dedicated documentation pages: - -### High Priority (Commonly Used) - -| Keyword | Source File | Description | -|---------|-------------|-------------| -| `QR CODE` | `qrcode.rs` | Generates QR code images from data | -| `SEND SMS` | `sms.rs` | Sends SMS messages via Twilio/AWS SNS/Vonage | -| `PLAY` | `play.rs` | Opens content projector for videos, images, docs | -| `REMEMBER` | `remember.rs` | Stores user memories with expiration | -| `BOOK` | `book.rs` | Schedules calendar meetings/appointments | -| `WEATHER` | `weather.rs` | Gets weather data (API documented, keyword not) | - -### Medium Priority (Advanced Features) - -| Keyword | Source File | Description | -|---------|-------------|-------------| -| `A2A` | `a2a_protocol.rs` | Agent-to-Agent communication protocol | -| `ADD BOT` | `add_bot.rs` | Dynamically adds bots to session | -| `ADD MEMBER` | `add_member.rs` | Adds members to groups/teams | -| `ADD SUGGESTION` | `add_suggestion.rs` | Adds response suggestions | -| `HUMAN APPROVAL` | `human_approval.rs` | Human-in-the-loop workflow | -| `MODEL ROUTE` | `model_routing.rs` | Routes requests to different LLM models | -| `SEND TEMPLATE` | `send_template.rs` | Sends WhatsApp/channel templates | -| `SET USER` | `set_user.rs` | Sets current user context | - -### Low Priority (Internal/Advanced) - -| Keyword | Source File | Description | -|---------|-------------|-------------| -| `EPISODIC MEMORY` | `episodic_memory.rs` | Long-term episodic memory storage | -| `KNOWLEDGE GRAPH` | `knowledge_graph.rs` | Knowledge graph operations | -| `LLM` | `llm_keyword.rs` | Direct LLM invocation | -| `MULTIMODAL` | `multimodal.rs` | Image/audio processing | -| `PROCEDURE` | `procedures.rs` | BASIC procedure definitions | -| `ON FORM SUBMIT` | `on_form_submit.rs` | Form submission handlers | -| `IMPORT/EXPORT` | `import_export.rs` | Data import/export operations | - ---- - -## 2. Undocumented Source Modules - -### Modules Without Dedicated Documentation - -| Module | Path | Purpose | Priority | -|--------|------|---------|----------| -| `attendance` | `src/attendance/` | Queue management for human attendants | Medium | -| `timeseries` | `src/timeseries/` | InfluxDB 3 integration for metrics | Medium | -| `weba` | `src/weba/` | Placeholder for web app features | Low | -| `nvidia` | `src/nvidia/` | GPU acceleration (partially documented) | Low | -| `multimodal` | `src/multimodal/` | Image/video processing | Medium | -| `console` | `src/console/` | Admin console backend | Low | - -### Modules With Partial Documentation - -| Module | Missing Docs | -|--------|--------------| -| `llm` | LLM keyword syntax, model routing details | -| `calendar` | CalDAV integration details, recurrence rules | -| `meet` | WebRTC/LiveKit integration details | - ---- - -## 3. Documentation Accuracy Issues - -### Incorrect or Outdated References - -1. **keyword-remember.md** - Referenced but file doesn't exist in SUMMARY.md -2. **keyword-book.md** - Referenced in keyword-create-task.md but no file exists -3. **keyword-weather.md** - API documented but keyword syntax not documented - -### Missing from SUMMARY.md - -These keyword files exist but aren't linked in SUMMARY.md: - -- `keyword-synchronize.md` -- `keyword-reference-complete.md` -- Several template files - ---- - -## 4. API Endpoint Gaps - -### Suite App Backend APIs (Recently Implemented) - -| App | Endpoints | Status | -|-----|-----------|--------| -| Analytics | 12 endpoints | ✅ Implemented | -| Paper | 20+ endpoints | ✅ Implemented | -| Research | 8 endpoints | ✅ Implemented | -| Sources | 7 endpoints | ✅ Implemented | -| Designer | 5 endpoints | ✅ Implemented | - -### Undocumented Internal APIs - -| API | Path | Purpose | -|-----|------|---------| -| Queue API | `/api/queue/*` | Human attendant queue management | -| TimeSeries API | N/A | Metrics ingestion (internal only) | - ---- - -## 5. Recommended Documentation Additions - -### Immediate Priority - -1. **Create `keyword-qrcode.md`** - ```basic - ' Generate QR code - path = QR CODE "https://example.com" - SEND FILE path - - ' With custom size - path = QR CODE "data", 512 - ``` - -2. **Create `keyword-sms.md`** - ```basic - ' Send SMS - SEND SMS "+1234567890", "Hello!" - - ' With provider - SEND SMS phone, message, "twilio" - ``` - -3. **Create `keyword-play.md`** - ```basic - ' Play video - PLAY "video.mp4" - - ' With options - PLAY "presentation.pptx" WITH OPTIONS "fullscreen" - ``` - -4. **Create `keyword-remember.md`** - ```basic - ' Remember with expiration - REMEMBER "user_preference", "dark_mode", "30 days" - - ' Recall later - pref = RECALL "user_preference" - ``` - -5. **Create `keyword-book.md`** - ```basic - ' Book a meeting - BOOK "Team Standup" WITH user1, user2 AT "2025-01-20 10:00" FOR 30 - ``` - -### Medium Priority - -1. **Document TimeSeries module** - Add to appendix or chapter-11 -2. **Document Attendance/Queue system** - Add to chapter-10 APIs -3. **Expand Multimodal docs** - Add keyword reference -4. **Create A2A Protocol guide** - Multi-agent communication - -### Low Priority - -1. Add advanced LLM routing documentation -2. Document internal console APIs -3. Add GPU acceleration tuning guide - ---- - -## 6. Consistency Issues - -### Naming Conventions - -| Issue | Location | Fix | -|-------|----------|-----| -| `keyword-for-each.md` vs `for_next.rs` | Inconsistent naming | Document both FOR EACH and FOR/NEXT | -| `keyword-delete-http.md` vs `DELETE` | Overlap | Clarify HTTP DELETE vs data DELETE | - -### Missing Cross-References - -- Paper app docs don't reference .gbusers storage (FIXED) -- Calendar docs don't reference BOOK keyword -- Meet docs don't reference video/audio keywords - ---- - -## 7. Action Items - -### High Priority -- [ ] Create 5 missing keyword docs (QR CODE, SMS, PLAY, REMEMBER, BOOK) -- [ ] Add WEATHER keyword syntax to weather.md -- [ ] Fix broken references in existing docs - -### Medium Priority -- [ ] Document attendance/queue module -- [ ] Add timeseries module to appendix -- [ ] Create A2A protocol guide -- [ ] Add multimodal keyword reference - -### Low Priority -- [ ] Document internal console APIs -- [ ] Add advanced configuration examples -- [ ] Create video tutorials references - ---- - -## 8. Verification Commands - -```bash -# List all keyword files in src -ls botserver/src/basic/keywords/*.rs | wc -l - -# List all keyword docs -ls botserver/docs/src/chapter-06-gbdialog/keyword-*.md | wc -l - -# Find references to undocumented keywords -grep -r "QRCODE\|QR CODE\|SEND SMS\|PLAY\|REMEMBER\|BOOK" botserver/docs/ - -# Check for broken links in SUMMARY.md -grep -oP '\./[^)]+\.md' botserver/docs/src/SUMMARY.md | while read f; do - [ ! -f "botserver/docs/src/$f" ] && echo "Missing: $f" -done -``` - ---- - -*Last updated: 2025-01-20* -*Analyzed modules: 24 source directories, 100+ documentation files* \ No newline at end of file diff --git a/docs/book.toml b/docs/book.toml deleted file mode 100644 index 1ab88b9e..00000000 --- a/docs/book.toml +++ /dev/null @@ -1,19 +0,0 @@ -[book] -title = "General Bots Documentation" -authors = ["General Bots Team"] -language = "en" -multilingual = false -src = "src" - -[build] -build-dir = "book" - -[output.html] -default-theme = "light" -preferred-dark-theme = "navy" -smart-punctuation = true -additional-css = ["src/custom.css", "src/whatsapp-chat.css"] -additional-js = ["src/theme-sync.js"] - -[output.html.favicon] -png = "favicon.png" diff --git a/docs/src/README.md b/docs/src/README.md deleted file mode 100644 index a090bddf..00000000 --- a/docs/src/README.md +++ /dev/null @@ -1,124 +0,0 @@ -
- General Bots -
- -# General Bots Documentation - -Welcome to the General Bots documentation. This guide explains how to install, configure, extend, and deploy conversational AI bots using General Bots' template-based package system and BASIC scripting language. - - -## About This Documentation - -This documentation has been recently updated to accurately reflect the actual implementation of General Bots version 6.0.8. - -The following chapters now contain accurate, verified documentation: Chapter 02 covering the package system with its template-based `.gbai` structure, Chapter 06 documenting the Rust architecture including the single-crate structure and module overview, Chapter 09 explaining core features, and the Introduction providing architecture and capabilities overview. - -Several areas have partial documentation that continues to improve. Chapter 05 on BASIC keywords includes working examples though the full reference needs expansion. Chapter 08 on tool integration has concepts documented while implementation details are being added. Chapter 11 on authentication reflects the implemented functionality but needs additional detail. - -Documentation work continues on several modules. The UI module in `src/ui/`, the UI tree module in `src/ui_tree/`, the Riot compiler module in `src/riot_compiler/`, and the prompt manager in `src/prompt_manager/` all need comprehensive documentation. API endpoints, UI server routes, Drive integration details for S3-compatible storage, and LiveKit video conferencing integration are also being documented. - - -## What is General Bots? - -General Bots is an open-source conversational AI platform written in Rust. The platform enables users to create intelligent chatbots through several integrated capabilities. - -BASIC Scripting provides simple `.bas` scripts for defining conversation flows without requiring traditional programming expertise. Template Packages organize bots as `.gbai` directories containing dialogs, knowledge bases, and configuration in a portable structure. Vector Search enables semantic document retrieval using Qdrant for intelligent information access. LLM Integration connects to local models, cloud APIs, and custom providers for natural language understanding. Auto-Bootstrap handles automated installation of PostgreSQL, cache, drive storage, and other dependencies. Multi-Bot Hosting allows running multiple isolated bots on a single server instance. - - -## Quick Start - -Getting started with General Bots follows a straightforward path. Begin with installation by following Chapter 01 on Run and Talk. Then explore the templates directory, particularly `templates/announcements.gbai/`, to see working examples. Create your own bot by copying a template and modifying it to suit your needs. Learn the BASIC scripting language through Chapter 05's reference documentation. Configure your bot by editing the `config.csv` file in your `.gbot/` directory. Finally, deploy by restarting General Bots to activate your changes. - - -## Table of Contents - -### Part I - Getting Started - -Chapter 01 on Run and Talk covers installation and your first conversation with a bot. - -### Part II - Package System - -Chapter 02 on About Packages provides an overview of the template-based package system. This includes the `.gbai` Architecture explaining package structure and lifecycle, `.gbdialog` Dialogs for BASIC scripts, `.gbkb` Knowledge Base for document collections, `.gbot` Configuration for bot parameters, `.gbtheme` UI Theming for web interface customization, and `.gbdrive` File Storage for S3-compatible drive integration. - -### Part III - Knowledge Base - -Chapter 03 on gbkb Reference covers semantic search and vector database functionality. - -### Part IV - User Interface - -Chapter 04 on .gbui Interface Reference documents HTML templates and UI components. - -### Part V - Themes and Styling - -Chapter 05 on gbtheme CSS Reference explains CSS-based theme customization. - -### Part VI - BASIC Dialogs - -Chapter 06 on gbdialog Reference provides the complete BASIC scripting reference including keywords like TALK, HEAR, LLM, SET CONTEXT, USE KB, and many more. - -### Part VII - Extending General Bots - -Chapter 07 on gbapp Architecture Reference documents the internal architecture. This includes the Architecture Overview explaining the bootstrap process, Building from Source for compilation and features, Module Structure describing single-crate organization, Service Layer with module descriptions, Creating Custom Keywords for extending BASIC, and Adding Dependencies for Cargo.toml management. - -### Part VIII - Bot Configuration - -Chapter 08 on gbot Reference covers configuration and parameters. - -### Part IX - Tools and Integration - -Chapter 09 on API and Tooling explains function calling and tool integration. - -### Part X - Feature Deep Dive - -Chapter 10 on Feature Reference provides the complete feature list including Core Features documenting platform capabilities. - -### Part XI - Community - -Chapter 11 on Contributing provides development and contribution guidelines. - -### Part XII - Authentication and Security - -Chapter 12 on Authentication documents security features. - -### Appendices - -Appendix I on Database Model provides schema reference. The Glossary defines terms used throughout the documentation. - - -## Architecture Overview - -General Bots is a monolithic Rust application organized as a single crate with clearly defined modules serving different purposes. - -### Core Modules - -The core modules handle fundamental bot functionality. The auth module provides Argon2 password hashing and session token management. The bot module manages bot lifecycle and coordination. The session module maintains persistent conversation state across interactions. The basic module implements the BASIC interpreter powered by the Rhai scripting engine. The llm and llm_models modules handle LLM provider integration for multiple backends. The context module manages conversation memory and context window optimization. - -### Infrastructure Modules - -Infrastructure modules provide the foundation for bot operations. The bootstrap module handles auto-installation of all required components. The package_manager module manages PostgreSQL, cache, drive storage, and other services. The web_server module implements the Axum HTTP REST API. The drive module integrates S3-compatible storage and vector database access. The config module handles environment configuration loading and validation. - -### Feature Modules - -Feature modules add specific capabilities to the platform. The automation module provides cron scheduling and event-driven processing. The email module offers optional IMAP and SMTP integration. The meet module enables LiveKit video conferencing. The channels module supports multi-channel deployment across different platforms. The file module handles document processing for PDF and other formats. The drive_monitor module watches file system changes for automatic updates. - - -## Technology Stack - -General Bots is built on a modern Rust technology stack. The application uses Rust 2021 edition for safety and performance. Web handling uses Axum combined with Tower middleware and Tokio async runtime. Database access uses the Diesel ORM with PostgreSQL as the backing store. Caching uses a Redis-compatible cache component for session and data caching. Storage uses the AWS SDK for S3-compatible drive operations. Vector database functionality uses Qdrant for semantic search when enabled. Scripting uses the Rhai engine to power the BASIC interpreter. Security uses Argon2 for password hashing and AES-GCM for encryption. Optional desktop deployment uses Tauri for native applications. - - -## Project Information - -The current version is 6.0.8 released under the AGPL-3.0 license. The source repository is available at https://github.com/GeneralBots/botserver. The project is maintained by open-source contributors from Pragmatismo.com.br and the broader community. - - -## Documentation Status - -This documentation is a living document that evolves alongside the codebase. Contributions are welcome from anyone who wants to improve it. - -If you find inaccuracies or gaps in the documentation, the best approach is to check the source code in `src/` for the ground truth implementation. Submit documentation improvements via pull requests on GitHub. Report issues through the GitHub issue tracker so they can be tracked and addressed. - - -## Next Steps - -Start with the Introduction for a comprehensive overview of General Bots concepts and capabilities. Alternatively, jump directly to Chapter 01 on Run and Talk to install and run General Bots immediately. \ No newline at end of file diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md deleted file mode 100644 index 6b22d197..00000000 --- a/docs/src/SUMMARY.md +++ /dev/null @@ -1,370 +0,0 @@ -# Summary - -[Executive Vision](./executive-vision.md) -[Introduction](./introduction.md) - -# Part I - Getting Started - -- [Chapter 01: Run and Talk](./chapter-01/README.md) - - [Overview](./chapter-01/overview.md) - - [Quick Start](./chapter-01/quick-start.md) - - [Installation](./chapter-01/installation.md) - - [First Conversation](./chapter-01/first-conversation.md) - - [Sessions and Channels](./chapter-01/sessions.md) - -# Part II - Package System - -- [Chapter 02: About Packages](./chapter-02/README.md) - - [.gbai Architecture](./chapter-02/gbai.md) - - [.gbdialog Dialogs](./chapter-02/gbdialog.md) - - [.gbkb Knowledge Base](./chapter-02/gbkb.md) - - [.gbot Bot Configuration](./chapter-02/gbot.md) - - [.gbtheme UI Theming](./chapter-02/gbtheme.md) - - [.gbdrive File Storage](./chapter-02/gbdrive.md) - - [Bot Templates](./chapter-02/templates.md) - - [Template Samples & Conversations](./chapter-02/template-samples.md) - - [Template: Business Intelligence](./chapter-02/template-bi.md) - - [Template: Web Crawler](./chapter-02/template-crawler.md) - - [Template: Legal Documents](./chapter-02/template-law.md) - - [Template: LLM Server](./chapter-02/template-llm-server.md) - - [Template: LLM Tools](./chapter-02/template-llm-tools.md) - - [Template: API Client](./chapter-02/template-api-client.md) - - [Template: Platform Analytics](./chapter-02/template-analytics.md) - - [Template: Office Automation](./chapter-02/template-office.md) - - [Template: Reminders](./chapter-02/template-reminder.md) - - [Template: Sales CRM](./chapter-02/template-crm.md) - - [Template: CRM Contacts](./chapter-02/template-crm-contacts.md) - - [Template: Marketing](./chapter-02/template-marketing.md) - - [Template: Creating Templates](./chapter-02/template-template.md) - -# Part III - Knowledge Base - -- [Chapter 03: gbkb Reference](./chapter-03/README.md) - - [KB and Tools System](./chapter-03/kb-and-tools.md) - - [Vector Collections](./chapter-03/vector-collections.md) - - [Document Indexing](./chapter-03/indexing.md) - - [Semantic Search](./chapter-03/semantic-search.md) - - [Episodic Memory](./chapter-03/episodic-memory.md) - - [Semantic Caching](./chapter-03/caching.md) - -# Part IV - User Interface - -- [Chapter 04: .gbui Interface Reference](./chapter-04-gbui/README.md) - - [Suite User Manual](./chapter-04-gbui/suite-manual.md) - - [UI Structure](./chapter-04-gbui/ui-structure.md) - - [single.gbui - Simple Chat](./chapter-04-gbui/single-gbui.md) - - [Console Mode](./chapter-04-gbui/console-mode.md) - - [Monitoring Dashboard](./chapter-04-gbui/monitoring.md) - - [HTMX Architecture](./chapter-04-gbui/htmx-architecture.md) - - [Suite Applications](./chapter-04-gbui/apps/README.md) - - [Suite - Full Desktop](./chapter-04-gbui/apps/suite.md) - - [Chat - AI Assistant](./chapter-04-gbui/apps/chat.md) - - [Drive - File Management](./chapter-04-gbui/apps/drive.md) - - [Tasks - To-Do Lists](./chapter-04-gbui/apps/tasks.md) - - [Mail - Email Client](./chapter-04-gbui/apps/mail.md) - - [Calendar - Scheduling](./chapter-04-gbui/apps/calendar.md) - - [Meet - Video Calls](./chapter-04-gbui/apps/meet.md) - - [Player - Media Viewer](./chapter-04-gbui/apps/player.md) - - [Paper - AI Writing](./chapter-04-gbui/apps/paper.md) - - [Research - AI Search](./chapter-04-gbui/apps/research.md) - - [Analytics - Dashboards](./chapter-04-gbui/apps/analytics.md) - - [Designer - Visual Builder](./chapter-04-gbui/apps/designer.md) - - [Sources - Prompts & Templates](./chapter-04-gbui/apps/sources.md) - - [Compliance - Security Scanner](./chapter-04-gbui/apps/compliance.md) - - [Compliance API Reference](./chapter-04-gbui/apps/compliance-api.md) - - [How-To Tutorials](./chapter-04-gbui/how-to/README.md) - - [Create Your First Bot](./chapter-04-gbui/how-to/create-first-bot.md) - - [Write Your First Dialog](./chapter-04-gbui/how-to/write-first-dialog.md) - - [Add Documents to Knowledge Base](./chapter-04-gbui/how-to/add-kb-documents.md) - - [Connect WhatsApp](./chapter-04-gbui/how-to/connect-whatsapp.md) - - [Monitor Your Bot](./chapter-04-gbui/how-to/monitor-sessions.md) - -# Part V - Themes and Styling - -- [Chapter 05: gbtheme CSS Reference](./chapter-05-gbtheme/README.md) - - [Theme Structure](./chapter-05-gbtheme/structure.md) - - [CSS Customization](./chapter-05-gbtheme/css.md) - -# Part VI - BASIC Dialogs - -- [Chapter 06: gbdialog Reference](./chapter-06-gbdialog/README.md) - - [Dialog Basics](./chapter-06-gbdialog/basics.md) - - [Universal Messaging & Multi-Channel](./chapter-06-gbdialog/universal-messaging.md) - - [BASIC vs n8n/Zapier/Make](./chapter-06-gbdialog/basic-vs-automation-tools.md) - - [Template Variables](./chapter-06-gbdialog/template-variables.md) - - [Template Examples](./chapter-06-gbdialog/templates.md) - - [start.bas](./chapter-06-gbdialog/templates/start.md) - - [enrollment.bas](./chapter-06-gbdialog/templates/enrollment.md) - - [auth.bas](./chapter-06-gbdialog/templates/auth.md) - - [ai-search.bas](./chapter-06-gbdialog/templates/ai-search.md) - - [analytics-dashboard.bas](./chapter-06-gbdialog/templates/analytics-dashboard.md) - - [announcements.bas](./chapter-06-gbdialog/templates/announcements.md) - - [backup.bas](./chapter-06-gbdialog/templates/backup.md) - - [bank.bas](./chapter-06-gbdialog/templates/bank.md) - - [broadcast.bas](./chapter-06-gbdialog/templates/broadcast.md) - - [default.bas](./chapter-06-gbdialog/templates/default.md) - - [edu.bas](./chapter-06-gbdialog/templates/edu.md) - - [employees.bas](./chapter-06-gbdialog/templates/employees.md) - - [erp.bas](./chapter-06-gbdialog/templates/erp.md) - - [helpdesk.bas](./chapter-06-gbdialog/templates/helpdesk.md) - - [privacy.bas](./chapter-06-gbdialog/templates/privacy.md) - - [sales-pipeline.bas](./chapter-06-gbdialog/templates/sales-pipeline.md) - - [store.bas](./chapter-06-gbdialog/templates/store.md) - - [talk-to-data.bas](./chapter-06-gbdialog/templates/talk-to-data.md) - - [whatsapp.bas](./chapter-06-gbdialog/templates/whatsapp.md) - - [Consolidated Examples](./chapter-06-gbdialog/examples-consolidated.md) - - [Data Sync Tools](./chapter-06-gbdialog/tools-data-sync.md) - - [Keywords Reference](./chapter-06-gbdialog/keywords.md) - - [TALK](./chapter-06-gbdialog/keyword-talk.md) - - [HEAR](./chapter-06-gbdialog/keyword-hear.md) - - [SET CONTEXT](./chapter-06-gbdialog/keyword-set-context.md) - - [GET BOT MEMORY](./chapter-06-gbdialog/keyword-get-bot-memory.md) - - [SET BOT MEMORY](./chapter-06-gbdialog/keyword-set-bot-memory.md) - - [GET USER MEMORY](./chapter-06-gbdialog/keyword-get-user-memory.md) - - [SET USER MEMORY](./chapter-06-gbdialog/keyword-set-user-memory.md) - - [REMEMBER / RECALL](./chapter-06-gbdialog/keyword-remember.md) - - [BOOK / BOOK_MEETING](./chapter-06-gbdialog/keyword-book.md) - - [WEATHER / FORECAST](./chapter-06-gbdialog/keyword-weather.md) - - [ADD BOT](./chapter-06-gbdialog/keyword-add-bot.md) - - [ADD MEMBER](./chapter-06-gbdialog/keyword-add-member.md) - - [ADD SUGGESTION](./chapter-06-gbdialog/keyword-add-suggestion.md) - - [MODEL ROUTE](./chapter-06-gbdialog/keyword-model-route.md) - - [SEND TEMPLATE](./chapter-06-gbdialog/keyword-send-template.md) - - [SET USER](./chapter-06-gbdialog/keyword-set-user.md) - - [USE MODEL](./chapter-06-gbdialog/keyword-use-model.md) - - [DELEGATE TO BOT](./chapter-06-gbdialog/keyword-delegate-to-bot.md) - - [BOT REFLECTION](./chapter-06-gbdialog/keyword-bot-reflection.md) - - [RUN PYTHON / JAVASCRIPT / BASH](./chapter-06-gbdialog/keyword-run-code.md) - - [USE KB](./chapter-06-gbdialog/keyword-use-kb.md) - - [CLEAR KB](./chapter-06-gbdialog/keyword-clear-kb.md) - - [USE WEBSITE](./chapter-06-gbdialog/keyword-use-website.md) - - [USE TOOL](./chapter-06-gbdialog/keyword-use-tool.md) - - [CLEAR TOOLS](./chapter-06-gbdialog/keyword-clear-tools.md) - - [GET](./chapter-06-gbdialog/keyword-get.md) - - [SET](./chapter-06-gbdialog/keyword-set.md) - - [ON](./chapter-06-gbdialog/keyword-on.md) - - [SET SCHEDULE](./chapter-06-gbdialog/keyword-set-schedule.md) - - [CREATE SITE](./chapter-06-gbdialog/keyword-create-site.md) - - [CREATE DRAFT](./chapter-06-gbdialog/keyword-create-draft.md) - - [CREATE TASK](./chapter-06-gbdialog/keyword-create-task.md) - - [PRINT](./chapter-06-gbdialog/keyword-print.md) - - [WAIT](./chapter-06-gbdialog/keyword-wait.md) - - [FORMAT](./chapter-06-gbdialog/keyword-format.md) - - [FIRST](./chapter-06-gbdialog/keyword-first.md) - - [LAST](./chapter-06-gbdialog/keyword-last.md) - - [FOR EACH](./chapter-06-gbdialog/keyword-for-each.md) - - [EXIT FOR](./chapter-06-gbdialog/keyword-exit-for.md) - - [SEND MAIL](./chapter-06-gbdialog/keyword-send-mail.md) - - [FIND](./chapter-06-gbdialog/keyword-find.md) - - [INSTR](./chapter-06-gbdialog/keyword-instr.md) - - [IS NUMERIC](./chapter-06-gbdialog/keyword-is-numeric.md) - - [SWITCH](./chapter-06-gbdialog/keyword-switch.md) - - [WEBHOOK](./chapter-06-gbdialog/keyword-webhook.md) - - [TABLE](./chapter-06-gbdialog/keyword-table.md) - - [KB Statistics Keywords](./chapter-06-gbdialog/keywords-kb-statistics.md) - - [KB STATISTICS](./chapter-06-gbdialog/keyword-kb-statistics.md) - - [KB COLLECTION STATS](./chapter-06-gbdialog/keyword-kb-collection-stats.md) - - [KB DOCUMENTS COUNT](./chapter-06-gbdialog/keyword-kb-documents-count.md) - - [KB DOCUMENTS ADDED SINCE](./chapter-06-gbdialog/keyword-kb-documents-added-since.md) - - [KB LIST COLLECTIONS](./chapter-06-gbdialog/keyword-kb-list-collections.md) - - [KB STORAGE SIZE](./chapter-06-gbdialog/keyword-kb-storage-size.md) - - [Multi-Agent Keywords](./chapter-06-gbdialog/keywords-multi-agent.md) - - [Social Media Keywords](./chapter-06-gbdialog/keywords-social-media.md) - - [Lead Scoring Keywords](./chapter-06-gbdialog/keywords-lead-scoring.md) - - [HTTP & API Operations](./chapter-06-gbdialog/keywords-http.md) - - [POST](./chapter-06-gbdialog/keyword-post.md) - - [PUT](./chapter-06-gbdialog/keyword-put.md) - - [PATCH](./chapter-06-gbdialog/keyword-patch.md) - - [DELETE HTTP](./chapter-06-gbdialog/keyword-delete-http.md) - - [SET HEADER](./chapter-06-gbdialog/keyword-set-header.md) - - [GRAPHQL](./chapter-06-gbdialog/keyword-graphql.md) - - [SOAP](./chapter-06-gbdialog/keyword-soap.md) - - [Data Operations](./chapter-06-gbdialog/keywords-data.md) - - [SAVE](./chapter-06-gbdialog/keyword-save.md) - - [INSERT](./chapter-06-gbdialog/keyword-insert.md) - - [UPDATE](./chapter-06-gbdialog/keyword-update.md) - - [DELETE](./chapter-06-gbdialog/keyword-delete.md) - - [MERGE](./chapter-06-gbdialog/keyword-merge.md) - - [FILL](./chapter-06-gbdialog/keyword-fill.md) - - [MAP](./chapter-06-gbdialog/keyword-map.md) - - [FILTER](./chapter-06-gbdialog/keyword-filter.md) - - [AGGREGATE](./chapter-06-gbdialog/keyword-aggregate.md) - - [JOIN](./chapter-06-gbdialog/keyword-join.md) - - [PIVOT](./chapter-06-gbdialog/keyword-pivot.md) - - [GROUP BY](./chapter-06-gbdialog/keyword-group-by.md) - - [Media & Messaging](./chapter-06-gbdialog/keywords-media.md) - - [PLAY](./chapter-06-gbdialog/keyword-play.md) - - [QR CODE](./chapter-06-gbdialog/keyword-qrcode.md) - - [SEND SMS](./chapter-06-gbdialog/keyword-sms.md) - - [File Operations](./chapter-06-gbdialog/keywords-file.md) - - [READ](./chapter-06-gbdialog/keyword-read.md) - - [WRITE](./chapter-06-gbdialog/keyword-write.md) - - [DELETE FILE](./chapter-06-gbdialog/keyword-delete-file.md) - - [COPY](./chapter-06-gbdialog/keyword-copy.md) - - [MOVE](./chapter-06-gbdialog/keyword-move.md) - - [LIST](./chapter-06-gbdialog/keyword-list.md) - - [COMPRESS](./chapter-06-gbdialog/keyword-compress.md) - - [EXTRACT](./chapter-06-gbdialog/keyword-extract.md) - - [UPLOAD](./chapter-06-gbdialog/keyword-upload.md) - - [DOWNLOAD](./chapter-06-gbdialog/keyword-download.md) - - [GENERATE PDF](./chapter-06-gbdialog/keyword-generate-pdf.md) - - [MERGE PDF](./chapter-06-gbdialog/keyword-merge-pdf.md) - -# Part VII - Extending General Bots - -- [Chapter 07: gbapp Architecture Reference](./chapter-07-gbapp/README.md) - - [Architecture Overview](./chapter-07-gbapp/architecture.md) - - [Building from Source](./chapter-07-gbapp/building.md) - - [Container Deployment (LXC)](./chapter-07-gbapp/containers.md) - - [Docker Deployment](./chapter-07-gbapp/docker-deployment.md) - - [Scaling and Load Balancing](./chapter-07-gbapp/scaling.md) - - [Infrastructure Design](./chapter-07-gbapp/infrastructure.md) - - [Observability](./chapter-07-gbapp/observability.md) - - [Philosophy](./chapter-07-gbapp/philosophy.md) - - [Example gbapp](./chapter-07-gbapp/example-gbapp.md) - - [Module Structure](./chapter-07-gbapp/crates.md) - - [Service Layer](./chapter-07-gbapp/services.md) - - [Creating Custom Keywords](./chapter-07-gbapp/custom-keywords.md) - - [Adding Dependencies](./chapter-07-gbapp/dependencies.md) - -# Part VIII - Bot Configuration - -- [Chapter 08: gbot Reference](./chapter-08-config/README.md) - - [config.csv Format](./chapter-08-config/config-csv.md) - - [Bot Parameters](./chapter-08-config/parameters.md) - - [LLM Configuration](./chapter-08-config/llm-config.md) - - [Context Configuration](./chapter-08-config/context-config.md) - - [Drive Integration](./chapter-08-config/drive.md) - - [Multimodal Configuration](./chapter-08-config/multimodal.md) - - [Secrets Management](./chapter-08-config/secrets-management.md) - -# Part IX - Tools and Integration - -- [Chapter 09: API and Tooling](./chapter-09-api/README.md) - - [Tool Definition](./chapter-09-api/tool-definition.md) - - [PARAM Declaration](./chapter-09-api/param-declaration.md) - - [Tool Compilation](./chapter-09-api/compilation.md) - - [MCP Format](./chapter-09-api/mcp-format.md) - - [Tool Format](./chapter-09-api/openai-format.md) - - [GET Keyword Integration](./chapter-09-api/get-integration.md) - - [External APIs](./chapter-09-api/external-apis.md) - - [LLM REST Server](./chapter-09-api/llm-rest-server.md) - - [NVIDIA GPU Setup for LXC](./chapter-09-api/nvidia-gpu-setup.md) - -- [Chapter 10: REST API Reference](./chapter-10-api/README.md) - - [Files API](./chapter-10-api/files-api.md) - - [Document Processing API](./chapter-10-api/document-processing.md) - - [Users API](./chapter-10-api/users-api.md) - - [User Security API](./chapter-10-api/user-security.md) - - [Groups API](./chapter-10-api/groups-api.md) - - [Group Membership API](./chapter-10-api/group-membership.md) - - [Conversations API](./chapter-10-api/conversations-api.md) - - [Calls API](./chapter-10-api/calls-api.md) - - [Whiteboard API](./chapter-10-api/whiteboard-api.md) - - [Email API](./chapter-10-api/email-api.md) - - [Notifications API](./chapter-10-api/notifications-api.md) - - [Calendar API](./chapter-10-api/calendar-api.md) - - [Tasks API](./chapter-10-api/tasks-api.md) - - [Storage API](./chapter-10-api/storage-api.md) - - [Backup API](./chapter-10-api/backup-api.md) - - [Analytics API](./chapter-10-api/analytics-api.md) - - [Reports API](./chapter-10-api/reports-api.md) - - [Admin API](./chapter-10-api/admin-api.md) - - [Monitoring API](./chapter-10-api/monitoring-api.md) - - [AI API](./chapter-10-api/ai-api.md) - - [ML API](./chapter-10-api/ml-api.md) - - [Security API](./chapter-10-api/security-api.md) - - [Compliance API](./chapter-10-api/compliance-api.md) - - [Example Integrations](./chapter-10-api/examples.md) - -# Part X - Feature Deep Dive - -- [Chapter 11: Feature Reference](./chapter-11-features/README.md) - - [Feature Editions](./chapter-11-features/editions.md) - - [Core Features](./chapter-11-features/core-features.md) - - [Conversation Management](./chapter-11-features/conversation.md) - - [AI and LLM](./chapter-11-features/ai-llm.md) - - [Knowledge Base](./chapter-11-features/knowledge-base.md) - - [Automation](./chapter-11-features/automation.md) - - [Email Integration](./chapter-11-features/email.md) - - [Storage and Data](./chapter-11-features/storage.md) - - [Multi-Channel Support](./chapter-11-features/channels.md) - - [Drive Monitor](./chapter-11-features/drive-monitor.md) - - [Platform Capabilities](./chapter-11-features/platform-comparison.md) - - [Enterprise Platform Migration](./chapter-11-features/m365-comparison.md) - - [Projects](./chapter-11-features/projects.md) - - [Multi-Agent Office Suite Design](./chapter-11-features/multi-agent-design.md) - - [What's New: Multi-Agent Features](./chapter-11-features/whats-new.md) - - [Multi-Agent Orchestration](./chapter-11-features/multi-agent-orchestration.md) - - [Memory Management](./chapter-11-features/memory-management.md) - - [Hybrid RAG Search](./chapter-11-features/hybrid-search.md) - -# Part XI - Security - -- [Chapter 12: Authentication & Permissions](./chapter-12-auth/README.md) - - [User Authentication](./chapter-12-auth/user-auth.md) - - [Password Security](./chapter-12-auth/password-security.md) - - [API Endpoints](./chapter-12-auth/api-endpoints.md) - - [Bot Authentication](./chapter-12-auth/bot-auth.md) - - [Security Features](./chapter-12-auth/security-features.md) - - [Security Policy](./chapter-12-auth/security-policy.md) - - [Compliance Requirements](./chapter-12-auth/compliance-requirements.md) - - [Permissions Matrix](./chapter-12-auth/permissions-matrix.md) - - [User Context vs System Context](./chapter-12-auth/user-system-context.md) - -# Part XII - Community - -- [Chapter 13: Contributing](./chapter-13-community/README.md) - - [Development Setup](./chapter-13-community/setup.md) - - [Testing Guide](./chapter-13-community/testing.md) - - [Documentation](./chapter-13-community/documentation.md) - - [Pull Requests](./chapter-13-community/pull-requests.md) - - [Community Guidelines](./chapter-13-community/community.md) - - [IDEs](./chapter-13-community/ide-extensions.md) - -# Part XIII - Migration - -- [Chapter 14: Migration Guide](./chapter-14-migration/README.md) - - [Migration Overview](./chapter-14-migration/overview.md) - - [Platform Comparison Matrix](./chapter-14-migration/comparison-matrix.md) - - [Migration Resources](./chapter-14-migration/resources.md) - - [Common Concepts](./chapter-14-migration/common-concepts.md) - - [Knowledge Base Migration](./chapter-14-migration/kb-migration.md) - - [Cloud Productivity Migration](./chapter-14-migration/google-workspace.md) - - [Enterprise Platform Migration](./chapter-14-migration/microsoft-365.md) - - [n8n Migration](./chapter-14-migration/n8n.md) - - [Notion Migration](./chapter-14-migration/notion.md) - - [Perplexity Migration](./chapter-14-migration/perplexity.md) - - [Zapier and Make Migration](./chapter-14-migration/zapier-make.md) - - [Intercom Migration](./chapter-14-migration/intercom.md) - - [Dialogflow Migration](./chapter-14-migration/dialogflow.md) - - [Botpress Migration](./chapter-14-migration/botpress.md) - - [Automation Migration](./chapter-14-migration/automation.md) - - [Validation and Testing](./chapter-14-migration/validation.md) - -# Appendices - -- [Appendix A: Database Model](./appendix-15/README.md) - - [Schema Overview](./appendix-15/schema.md) - - [Tables](./appendix-15/tables.md) - - [Relationships](./appendix-15/relationships.md) - -- [Appendix B: External Services](./appendix-external-services/README.md) - - [Service Catalog](./appendix-external-services/catalog.md) - - [LLM Providers](./appendix-external-services/llm-providers.md) - - [Weather API](./appendix-external-services/weather.md) - - [Channel Integrations](./appendix-external-services/channels.md) - - [Storage Services](./appendix-external-services/storage.md) - - [Directory Services](./appendix-external-services/directory.md) - - [Attendance Queue](./appendix-external-services/attendance-queue.md) - - [Time-Series Database](./appendix-external-services/timeseries.md) - - [NVIDIA GPU](./appendix-external-services/nvidia.md) - - [Multimodal](./appendix-external-services/multimodal.md) - - [Console (XtreeUI)](./appendix-external-services/console.md) - -- [Appendix C: Environment Variables](./appendix-env-vars/README.md) - -- [Appendix D: Documentation Style](./appendix-docs-style/conversation-examples.md) - -[Glossary](./glossary.md) -[Contact](./contact/README.md) \ No newline at end of file diff --git a/docs/src/appendix-15/README.md b/docs/src/appendix-15/README.md deleted file mode 100644 index 59373cf3..00000000 --- a/docs/src/appendix-15/README.md +++ /dev/null @@ -1,52 +0,0 @@ -## Appendix I – Database Model - -Database Schema Overview - -The core database schema for GeneralBots is defined in `src/shared/models.rs`. It uses **Diesel** with PostgreSQL and includes the following primary tables: - -| Table | Description | -|-------|-------------| -| `users` | Stores user accounts, authentication tokens, and profile data. | -| `sessions` | Tracks active `BotSession` instances, their start/end timestamps, and associated user. | -| `knowledge_bases` | Metadata for each `.gbkb` collection (name, vector store configuration, creation date). | -| `messages` | Individual chat messages (role = user/assistant, content, timestamp, linked to a session). | -| `tools` | Registered custom tools per session (name, definition JSON, activation status). | -| `files` | References to files managed by the `.gbdrive` package (path, size, MIME type, storage location). | - -### Relationships -- **User ↔ Sessions** – One‑to‑many: a user can have many sessions. -- **Session ↔ Messages** – One‑to‑many: each session contains a sequence of messages. -- **Session ↔ KnowledgeBase** – Many‑to‑one: a session uses a single knowledge base at a time. -- **Session ↔ Tools** – One‑to‑many: tools are scoped to the session that registers them. -- **File ↔ KnowledgeBase** – Optional link for documents stored in a knowledge base. - -### Key Tables - -**User Table** -- id: Integer primary key -- username: String -- email: String -- password_hash: String -- created_at: Timestamp - -**Session Table** -- id: Integer primary key -- user_id: Foreign key to User -- started_at: Timestamp -- last_active: Timestamp -- knowledge_base_id: Integer - -**Message Table** -- id: Integer primary key -- session_id: Foreign key to Session -- role: String ("user" or "assistant") -- content: Text -- timestamp: Timestamp - -The schema is automatically migrated when the server starts. - ---- - -
- General Bots -
diff --git a/docs/src/appendix-15/relationships.md b/docs/src/appendix-15/relationships.md deleted file mode 100644 index 72c6774a..00000000 --- a/docs/src/appendix-15/relationships.md +++ /dev/null @@ -1,180 +0,0 @@ -# Database Relationships - -This document describes the relationships between tables in the General Bots database schema. - -## Entity Relationship Overview - -The database follows a hierarchical structure with organizations at the top, containing bots, which in turn manage users, sessions, and content. - -## Primary Relationships - -### Organization Hierarchy - -``` -organizations - bots (1:N) - bot_configuration (1:N) - bot_memories (1:N) - kb_collections (1:N) - kb_documents (1:N) - basic_tools (1:N) - system_automations (1:N) -``` - -Each organization can have multiple bots, and each bot has its own configuration, memories, knowledge bases, tools, and automations. Cascade delete behavior means that deleting an organization removes all associated bots and their data. - -### User and Session Management - -``` -users - user_sessions (1:N) - message_history (1:N) - clicks (1:N) - user_kb_associations (1:N) - session_tool_associations (1:N) - user_login_tokens (1:N) - user_preferences (1:1) - user_email_accounts (1:N) - email_drafts (1:N) - email_folders (1:N) - folder_messages (1:N) -``` - -Users can have multiple active sessions across different bots. Each session maintains its own message history and associations. Sessions link to both users and bots, forming a many-to-many relationship through the sessions table. - -### Bot-User Interaction - -``` -bots ←→ user_sessions ←→ users - - user_sessions: - message_history - user_kb_associations → kb_collections - session_tool_associations → basic_tools - - bots: - kb_collections - basic_tools -``` - -Users interact with bots through sessions. Sessions dynamically associate with knowledge bases and tools as needed. Message history preserves the conversation context for continuity across interactions. - -## Foreign Key Constraints - -### Strong Relationships (CASCADE DELETE) - -These relationships enforce referential integrity with cascade deletion. - -The organizations to bots relationship means deleting an organization removes all its bots, with `bots.org_id` referencing `organizations.org_id`. - -The bots to bot_configuration relationship means deleting a bot removes all its configuration, with `bot_configuration.bot_id` referencing `bots.id`. - -The bots to bot_memories relationship means deleting a bot removes all its memories, with `bot_memories.bot_id` referencing `bots.id`. - -The user_sessions to message_history relationship means ending a session removes its message history, with `message_history.session_id` referencing `user_sessions.id`. - -### Weak Relationships (SET NULL/RESTRICT) - -These relationships maintain data integrity without cascade deletion. - -The users to user_sessions relationship sets `session.user_id` to NULL when a user is deleted, preserving conversation history for audit purposes while making the session anonymous. - -The kb_collections to kb_documents relationship restricts deletion if documents exist, requiring explicit document deletion first to prevent accidental data loss. - -The user_email_accounts to email_drafts relationship preserves drafts when an email account is deleted, allowing draft recovery or reassignment to other accounts. - -## Many-to-Many Relationships - -### Sessions ↔ Knowledge Bases - -``` -user_sessions ←→ user_kb_associations ←→ kb_collections -``` - -The `user_kb_associations` junction table allows dynamic KB activation per session. Multiple knowledge bases can be active simultaneously, enabling conversations that draw from several information sources. - -### Sessions ↔ Tools - -``` -user_sessions ←→ session_tool_associations ←→ basic_tools -``` - -The `session_tool_associations` junction table enables tools to be loaded per session as needed. This supports dynamic tool discovery where available capabilities vary based on context. - -## Relationship Cardinality - -One-to-one relationships exist between users and user_preferences, where each user has exactly one preferences record. - -One-to-many relationships include organizations to bots, bots to bot_configuration, bots to kb_collections, kb_collections to kb_documents, users to user_sessions, user_sessions to message_history, and user_email_accounts to email_drafts. - -Many-to-many relationships exist between user_sessions and kb_collections through user_kb_associations, between user_sessions and basic_tools through session_tool_associations, and between users and bots through user_sessions. - -## Referential Integrity Rules - -### Insert Order - -When inserting data, follow this sequence: organizations first, then bots, then bot_configuration. For user data, insert users first, then user_sessions, then message_history. Knowledge base data requires kb_collections before kb_documents. Tools require basic_tools before session_tool_associations. - -### Delete Order (reverse of insert) - -When deleting data, reverse the insert order: message_history first, then user_sessions, then users. For tools, delete session_tool_associations before basic_tools. For knowledge bases, delete kb_documents before kb_collections. For organizational data, delete bot_configuration, then bots, then organizations. - -## Orphan Prevention - -### Automatic Cleanup - -Sessions expire based on the `expires_at` timestamp. Orphaned associations are cleaned by background jobs that run periodically. Temporary data has TTL settings that trigger automatic removal. - -### Manual Cleanup Required - -Some data requires manual cleanup. Unused kb_documents should be periodically reviewed and removed. Old message_history should be cleared based on retention policy. Expired user_login_tokens should be purged. - -## Performance Implications - -### Hot Paths - -These relationships are frequently traversed and should be optimized. - -The user_sessions to message_history path benefits from an index on `(session_id, created_at DESC)` and is used for conversation display. - -The bots to bot_memories path benefits from an index on `(bot_id, key)` and is used by GET BOT MEMORY and SET BOT MEMORY operations. - -The kb_collections to kb_documents path benefits from an index on `(collection_id, indexed)` and is used for semantic search. - -### Join Optimization - -Common join patterns benefit from composite indexes. - -User session context queries join user_sessions with users on `user_sessions.user_id = users.id` and with bots on `user_sessions.bot_id = bots.id`. - -Knowledge base loading joins user_kb_associations with kb_collections on `user_kb_associations.collection_id = kb_collections.id` and kb_documents on `kb_collections.id = kb_documents.collection_id`. - -Tool discovery joins session_tool_associations with basic_tools on `session_tool_associations.tool_id = basic_tools.id` filtered by session_id and bot_id. - -## Data Consistency Patterns - -### Transaction Boundaries - -Certain operations must be atomic. - -Session creation requires inserting the user_session record, initializing default associations, and creating the initial message all within a single transaction. - -Tool registration requires inserting the basic_tool record, updating bot_configuration, and refreshing active sessions together. - -Document upload requires inserting the kb_document record, triggering the indexing job, and updating collection metadata atomically. - -### Eventual Consistency - -Some operations can be eventually consistent. - -Vector embeddings allow document upload to complete first, with asynchronous indexing creating embeddings afterward. Search becomes available after processing completes. - -Email synchronization saves account configuration immediately, then background sync fetches emails asynchronously. Folders and counts update as sync progresses. - -## Best Practices - -Always use foreign keys for data integrity to catch relationship violations at the database level. Index foreign key columns for join performance to avoid full table scans on relationship traversals. Use transactions for related updates to maintain consistency across multiple tables. - -Implement soft deletes for audit trails where regulations require historical data retention. Monitor constraint violations in logs to catch application bugs early. Plan cascade paths carefully to avoid unintended data deletion. - -Document relationship changes in migrations so the team understands schema evolution over time. \ No newline at end of file diff --git a/docs/src/appendix-15/schema.md b/docs/src/appendix-15/schema.md deleted file mode 100644 index 02063636..00000000 --- a/docs/src/appendix-15/schema.md +++ /dev/null @@ -1,126 +0,0 @@ -# Database Schema Overview - -General Bots uses PostgreSQL as its primary database with Diesel ORM for type-safe database operations. The schema is designed to support multi-tenant bot hosting with comprehensive session management, user authentication, and content storage. - -## Core Architecture - -The database schema follows several key design principles. All tables use UUID primary keys for globally unique identifiers that work across distributed systems. Created and updated timestamps provide audit trails for tracking data changes. Foreign key relationships maintain referential integrity between related entities. JSON fields offer flexible storage for dynamic configuration and metadata that doesn't fit rigid schema definitions. - -## Database Schema Diagram - -## Entity Relationship Overview - -Database Schema Overview - -### Core Tables Structure -## Detailed Schema - -Database Entity Details - -## Schema Categories - -### Organization & Bot Management - -The `organizations` table provides multi-tenant organization support, isolating data between different customers or deployments. The `bots` table stores bot instances and their configurations. The `bot_configuration` table contains bot-specific settings and parameters. The `bot_memories` table provides persistent key-value storage for bots to maintain state across sessions. - -### User & Authentication - -The `users` table stores user accounts with secure password storage using Argon2 hashing. The `user_sessions` table tracks active user sessions with authentication tokens. The `user_login_tokens` table manages authentication tokens for login flows. The `user_preferences` table contains user-specific settings and customizations. - -### Conversation & Messaging - -The `message_history` table maintains complete conversation history between users and bots. The `clicks` table tracks user interaction events for analytics. The `system_automations` table stores scheduled tasks and automation rules that run without user intervention. - -### Knowledge Base - -The `kb_collections` table defines knowledge base collection containers. The `kb_documents` table stores documents within those collections. The `user_kb_associations` table manages user access permissions to knowledge bases. The `session_tool_associations` table tracks which tools are available within specific sessions. - -### Tools & Integration - -The `basic_tools` table stores BASIC script tool definitions compiled from `.bas` files. The `user_email_accounts` table manages email integration accounts for users. The `email_drafts` table stores draft emails being composed. The `email_folders` table organizes email folder structures. - -## Table Relationships - -### Session Flow - -Session Flow Diagram - -### Knowledge Base Access - -Knowledge Base Access - -### Primary Relationships - -The bot hierarchy establishes that organizations contain multiple bots in a one-to-many relationship. Each bot has multiple configuration entries and memories associated with it. - -User sessions connect users to bots through the session table. Users can have multiple sessions, and each session maintains its own message history. Bots also connect to sessions, enabling the many-to-many relationship between users and bots. - -Knowledge management links bots to knowledge base collections, with each collection containing multiple documents. Sessions associate with knowledge bases through the user_kb_associations table. - -Tool associations connect bots to their defined tools, and sessions link to available tools through the session_tool_associations junction table. - -## Data Types - -The schema uses several PostgreSQL data types throughout. UUID fields serve as primary keys and foreign key references for globally unique identification. Text fields store variable-length string data without length constraints. Varchar fields hold fixed-length strings for codes and identifiers. Timestamptz fields store timestamps with timezone information for accurate time tracking across regions. Jsonb fields provide JSON storage with indexing capabilities for flexible schemas. Boolean fields represent binary flags and settings. Integer fields store counters and numeric values. - -## Indexing Strategy - -Primary indexes exist on all id fields serving as primary keys. Foreign key relationships receive indexes for efficient joins. Timestamp fields are indexed to support time-based queries. Session tokens have indexes for fast authentication lookups. - -Composite indexes optimize common query patterns. The combination of bot_id and user_id enables efficient session lookup. Collection_id with document_id accelerates knowledge retrieval. User_id paired with created_at supports history queries ordered by time. - -## Migration Management - -Database migrations are managed through Diesel's migration system. Migrations reside in the `migrations/` directory with each migration containing both up.sql and down.sql files for applying and reverting changes. Version tracking occurs in the `__diesel_schema_migrations` table. The bootstrap process automatically applies pending migrations on startup. - -## Performance Considerations - -### Connection Pooling - -The default connection pool maintains 10 connections to balance resource usage with concurrency. Pool size is configurable via environment variables for different deployment scales. Automatic connection recycling prevents stale connections from causing issues. - -### Query Optimization - -Prepared statements cache query plans for repeated queries, improving performance. Batch operations handle bulk inserts efficiently rather than individual row insertions. Lazy loading defers loading of related entities until needed. Pagination limits result sets to manageable sizes for large tables. - -### Data Retention - -Message history retention is configurable to balance storage costs with historical needs. Automatic cleanup removes expired sessions to free resources. An archival strategy moves old conversations to cold storage while maintaining accessibility. - -## Security Features - -### Data Protection - -Password hashing uses the Argon2 algorithm for strong protection against brute-force attacks. AES-GCM encryption protects sensitive fields at rest. Secure random token generation creates unpredictable session identifiers. Diesel's parameterized queries prevent SQL injection attacks. - -### Access Control - -Row-level security is implemented through application logic that filters queries by user context. User isolation ensures sessions only access their own data. Bot isolation separates data by organization to prevent cross-tenant access. Audit logging records sensitive operations for compliance and security review. - -## Backup Strategy - -### Backup Types - -Full database dumps capture complete point-in-time snapshots. Incremental WAL archiving provides continuous backup with minimal storage overhead. Point-in-time recovery support enables restoration to any moment within the retention window. Cross-region replication offers disaster recovery capabilities for critical deployments. - -### Restore Procedures - -Automated restore testing validates backup integrity on a regular schedule. Version compatibility checks ensure backups restore correctly to the current schema. Data integrity validation confirms restored data matches expected checksums. Zero-downtime migration support enables schema changes without service interruption. - -## Monitoring - -### Key Metrics - -Connection pool usage indicates whether the pool size needs adjustment. Query execution time reveals slow queries requiring optimization. Table sizes and growth rates inform capacity planning. Index effectiveness metrics show whether indexes are being utilized. Lock contention monitoring identifies concurrency bottlenecks. - -### Health Checks - -Database connectivity verification ensures the connection pool can reach PostgreSQL. Migration status checks confirm all migrations have been applied. Replication lag monitoring applies to deployments with read replicas. Storage usage tracking prevents disk space exhaustion. - -## Best Practices - -Always use migrations for schema changes rather than manual DDL to maintain consistency across environments. Never modify production data directly through SQL clients to avoid bypassing application logic. Test migrations in development first to catch issues before they affect production. Monitor performance metrics regularly to identify degradation early. Plan capacity based on growth projections to avoid emergency scaling. Document changes in migration files with comments explaining the purpose of each change. Use transactions for data consistency when multiple tables must be updated together. Implement retry logic for transient failures like connection timeouts or deadlocks. - -## Future Considerations - -Partitioning for large tables like message_history would improve query performance and enable efficient data archival. Read replicas could scale read-heavy workloads across multiple database instances. Time-series optimization for metrics data would support analytics features. Full-text search indexes would enable natural language queries against stored content. Graph relationships could support advanced queries for interconnected data like conversation flows. \ No newline at end of file diff --git a/docs/src/appendix-15/tables.md b/docs/src/appendix-15/tables.md deleted file mode 100644 index e0262f00..00000000 --- a/docs/src/appendix-15/tables.md +++ /dev/null @@ -1,275 +0,0 @@ -# Database Tables - -This section documents all database tables in General Bots, their structures, and purposes. - -## Core Tables - -### organizations -Stores organization/tenant information for multi-tenant deployments. - -| Column | Type | Description | -|--------|------|-------------| -| org_id | UUID | Primary key | -| name | TEXT | Organization name | -| slug | TEXT | URL-friendly identifier | -| created_at | TIMESTAMPTZ | Creation timestamp | - -### bots -Bot instances and their basic configuration. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| name | TEXT | Bot name | -| org_id | UUID | Foreign key to organizations | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update timestamp | - -### bot_configuration -Stores bot-specific configuration parameters from config.csv. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| bot_id | UUID | Foreign key to bots | -| key | TEXT | Configuration key | -| value | TEXT | Configuration value | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update timestamp | - -### bot_memories -Persistent key-value storage for bots (used by GET BOT MEMORY/SET BOT MEMORY). - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| bot_id | UUID | Foreign key to bots | -| key | TEXT | Memory key | -| value | TEXT | Memory value | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update timestamp | - -## User Management Tables - -### users -User accounts with authentication credentials. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| username | TEXT | Unique username | -| email | TEXT | Email address | -| password_hash | TEXT | Argon2 hashed password | -| active | BOOLEAN | Account status | -| created_at | TIMESTAMPTZ | Registration timestamp | -| updated_at | TIMESTAMPTZ | Last update timestamp | - -### user_sessions -Active user sessions for authentication and state management. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| user_id | UUID | Foreign key to users | -| bot_id | UUID | Foreign key to bots | -| session_token | TEXT | Unique session identifier | -| expires_at | TIMESTAMPTZ | Session expiration | -| created_at | TIMESTAMPTZ | Session start | -| updated_at | TIMESTAMPTZ | Last activity | - -### user_login_tokens -Authentication tokens for login flows. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| user_id | UUID | Foreign key to users | -| token | TEXT | Login token | -| expires_at | TIMESTAMPTZ | Token expiration | -| used | BOOLEAN | Whether token was used | -| created_at | TIMESTAMPTZ | Token creation | - -### user_preferences -User-specific settings and preferences. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| user_id | UUID | Foreign key to users | -| preferences | JSONB | Preferences data | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update | - -## Conversation Tables - -### message_history -Complete conversation history between users and bots. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| session_id | UUID | Foreign key to user_sessions | -| user_id | UUID | Foreign key to users | -| bot_id | UUID | Foreign key to bots | -| message | TEXT | Message content | -| sender | TEXT | 'user' or 'bot' | -| created_at | TIMESTAMPTZ | Message timestamp | - -### clicks -Tracks user interactions with UI elements. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| session_id | UUID | Foreign key to user_sessions | -| element_id | TEXT | UI element identifier | -| timestamp | TIMESTAMPTZ | Click timestamp | - -### system_automations -Scheduled tasks and automation rules. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| bot_id | UUID | Foreign key to bots | -| name | TEXT | Automation name | -| schedule | TEXT | Cron expression | -| script | TEXT | BASIC script to execute | -| active | BOOLEAN | Whether automation is active | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update | - -## Knowledge Base Tables - -### kb_collections -Knowledge base collection definitions. - -| Column | Type | Description | -|--------|------|-------------| -| id | TEXT | Primary key (collection name) | -| bot_id | UUID | Foreign key to bots | -| name | TEXT | Collection display name | -| description | TEXT | Collection description | -| metadata | JSONB | Additional metadata | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update | - -### kb_documents -Documents stored in knowledge base collections. - -| Column | Type | Description | -|--------|------|-------------| -| id | TEXT | Primary key (document ID) | -| collection_id | TEXT | Foreign key to kb_collections | -| bot_id | UUID | Foreign key to bots | -| name | TEXT | Document name | -| content | TEXT | Document content | -| metadata | JSONB | Document metadata | -| embedding_id | TEXT | Vector embedding reference | -| indexed | BOOLEAN | Whether document is indexed | -| created_at | TIMESTAMPTZ | Upload timestamp | -| updated_at | TIMESTAMPTZ | Last update | - -### user_kb_associations -Links user sessions to available knowledge bases. - -| Column | Type | Description | -|--------|------|-------------| -| id | TEXT | Primary key | -| session_id | UUID | Foreign key to user_sessions | -| collection_id | TEXT | Foreign key to kb_collections | -| created_at | TIMESTAMPTZ | Association timestamp | - -## Tool Tables - -### basic_tools -BASIC script tool definitions. - -| Column | Type | Description | -|--------|------|-------------| -| id | TEXT | Primary key (tool name) | -| bot_id | UUID | Foreign key to bots | -| name | TEXT | Tool display name | -| description | TEXT | Tool description | -| parameters | JSONB | Parameter definitions | -| script | TEXT | BASIC script implementation | -| metadata | JSONB | Additional metadata | -| created_at | TIMESTAMPTZ | Creation timestamp | -| updated_at | TIMESTAMPTZ | Last update | - -### session_tool_associations -Links sessions to available tools. - -| Column | Type | Description | -|--------|------|-------------| -| id | TEXT | Primary key | -| session_id | UUID | Foreign key to user_sessions | -| tool_id | TEXT | Foreign key to basic_tools | -| created_at | TIMESTAMPTZ | Association timestamp | - -## Email Integration Tables - -### user_email_accounts -Email accounts configured for users. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| user_id | UUID | Foreign key to users | -| email_address | TEXT | Email address | -| imap_server | TEXT | IMAP server address | -| imap_port | INTEGER | IMAP port | -| smtp_server | TEXT | SMTP server address | -| smtp_port | INTEGER | SMTP port | -| encrypted_password | TEXT | Encrypted email password | -| active | BOOLEAN | Account status | -| created_at | TIMESTAMPTZ | Configuration timestamp | -| updated_at | TIMESTAMPTZ | Last update | - -### email_drafts -Draft emails created by users or bots. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| user_id | UUID | Foreign key to users | -| account_id | UUID | Foreign key to user_email_accounts | -| to_addresses | TEXT[] | Recipient addresses | -| cc_addresses | TEXT[] | CC addresses | -| bcc_addresses | TEXT[] | BCC addresses | -| subject | TEXT | Email subject | -| body | TEXT | Email body | -| attachments | JSONB | Attachment metadata | -| created_at | TIMESTAMPTZ | Draft creation | -| updated_at | TIMESTAMPTZ | Last edit | - -### email_folders -Email folder organization. - -| Column | Type | Description | -|--------|------|-------------| -| id | UUID | Primary key | -| account_id | UUID | Foreign key to user_email_accounts | -| name | TEXT | Folder name | -| path | TEXT | IMAP folder path | -| parent_id | UUID | Parent folder ID | -| message_count | INTEGER | Number of messages | -| unread_count | INTEGER | Unread messages | -| created_at | TIMESTAMPTZ | Folder creation | -| updated_at | TIMESTAMPTZ | Last sync | - -## Indexes - -### Primary Indexes -- All `id` columns have primary key indexes -- All foreign key columns have indexes for joins - -### Performance Indexes -- `user_sessions.session_token` - for session lookup -- `message_history.created_at` - for time-based queries -- `kb_documents.collection_id` - for collection queries -- `bot_memories(bot_id, key)` - composite for memory lookup - -### Full-Text Search Indexes -- `kb_documents.content` - for document search (when enabled) -- `message_history.message` - for conversation search (when enabled) \ No newline at end of file diff --git a/docs/src/appendix-docs-style/conversation-examples.md b/docs/src/appendix-docs-style/conversation-examples.md deleted file mode 100644 index 12f0e5e1..00000000 --- a/docs/src/appendix-docs-style/conversation-examples.md +++ /dev/null @@ -1,235 +0,0 @@ -# Conversation Examples Style Guide - -> **Standard format for displaying bot-user conversations in documentation** - -## Overview - -All conversation examples in General Bots documentation use a WhatsApp-style chat format. This provides a consistent, familiar, and readable way to show bot interactions. - -## CSS Include - -The styling is defined in `/assets/wa-chat.css`. Include it in your mdBook or HTML output. - ---- - -## Basic Structure - -```html -
-
- -
-
- -
-
-``` - ---- - -## Message Types - -### Bot Message - -```html -
-
-

Hello! How can I help you today?

- -
-
-``` - -### User Message - -```html -
-
-

What meetings do I have today?

- -
-
-``` - ---- - -## Formatting Within Messages - -### Multiple Paragraphs - -```html -
-

You have 2 meetings scheduled:

-

• 2:00 PM - Team Standup (30 min)

-

• 4:00 PM - Project Review (1 hour)

-
10:31
-
-``` - -### Bold Text - -```html -

Name: John Smith

-

Email: john@example.com

-``` - -### Emoji Usage - -Emojis are encouraged to make conversations more expressive: - -| Purpose | Emoji Examples | -|---------|----------------| -| Success | ✅ ✓ 🎉 | -| Warning | ⚠️ ⚡ | -| Error | ❌ 🔴 | -| Info | ℹ️ 📋 | -| File | 📄 📁 📎 | -| Calendar | 📅 🗓️ | -| Email | 📧 ✉️ | -| Person | 👤 👥 | -| Time | 🕐 ⏱️ | - -### File Attachments - -```html -
-
-

Here's the report

-

📎 quarterly-report.pdf

- -
-
-``` - -### Action Buttons (visual representation) - -```html -

[📧 Send] [✏️ Edit] [🗑 Discard]

-``` - ---- - -## Complete Example - -```html -
-
- -
-
- -
-
-``` - -**Rendered Output:** - -
-
- -
-
- -
-
- ---- - -## Variants - -### Full Width - -Add `wa-full-width` class for wider conversations: - -```html -
- ... -
-``` - -### Compact - -Add `wa-compact` class for tighter spacing: - -```html -
- ... -
-``` - -### Hide Timestamps - -Add `wa-no-time` class to hide timestamps: - -```html -
- ... -
-``` - ---- - -## Best Practices - -1. **Keep messages concise** - Break long bot responses into multiple paragraphs -2. **Use consistent timestamps** - Use realistic times (10:30, 10:31, etc.) -3. **Start with user context** - Show what the user asked before the bot response -4. **Include visual feedback** - Use emojis for status (✅, ❌, 📋) -5. **Show realistic flows** - Include multi-turn conversations when appropriate -6. **Use semantic formatting** - Bold for labels, lists for options - ---- - -## Files Using This Format - -This format is used throughout the documentation: - -- `chapter-02/template-crm-contacts.md` -- `chapter-04-gbui/apps/*.md` -- `chapter-06-gbdialog/basic-vs-automation-tools.md` -- And many more... - ---- - -## See Also - -- [UI Structure](../chapter-04-gbui/ui-structure.md) -- [Chat App Documentation](../chapter-04-gbui/apps/chat.md) - - \ No newline at end of file diff --git a/docs/src/appendix-env-vars/README.md b/docs/src/appendix-env-vars/README.md deleted file mode 100644 index a5bd61f2..00000000 --- a/docs/src/appendix-env-vars/README.md +++ /dev/null @@ -1,136 +0,0 @@ -# Appendix C: Environment Variables - -General Bots uses a minimal set of environment variables. All configuration is managed through `config.csv` files within each bot's `.gbot` folder, with secrets stored securely in Vault. - -## Required Environment Variables - -Only Vault-related environment variables are used by General Bots: - -### VAULT_* Variables - -**Purpose**: HashiCorp Vault integration for secure secrets management. - -| Variable | Description | Example | -|----------|-------------|---------| -| `VAULT_ADDR` | Vault server URL | `http://localhost:8200` | -| `VAULT_TOKEN` | Authentication token | Auto-generated during bootstrap | -| `VAULT_NAMESPACE` | Vault namespace (optional) | `admin` | - -**Example**: -```bash -VAULT_ADDR=http://localhost:8200 -VAULT_TOKEN=hvs.your-vault-token -``` - -## Auto-Managed Services - -The following services are automatically configured through Vault: - -| Service | Management | -|---------|------------| -| PostgreSQL | Connection credentials in Vault | -| S3-Compatible Storage | Access keys in Vault | -| Cache | Connection managed via Vault | -| Email (Stalwart) | Credentials in Vault | -| LLM API Keys | Stored in Vault | - -You do **not** need to set environment variables for these services. Vault handles credential distribution and rotation automatically. - -## What NOT to Use Environment Variables For - -**All application configuration belongs in `config.csv`**: - -| Configuration | Where to Configure | -|--------------|-------------------| -| Database connection | Managed by Vault | -| Storage credentials | Managed by Vault | -| LLM API keys | Managed by Vault | -| LLM provider | `config.csv`: `llm-url` | -| Email settings | `config.csv`: `email-*` | -| Channel tokens | `config.csv`: `whatsapp-*`, etc. | -| Bot settings | `config.csv`: all bot-specific settings | -| Feature flags | `config.csv`: various keys | - -## Configuration Philosophy - -General Bots follows these principles: - -1. **Vault-First**: All secrets are managed by Vault -2. **Minimal Environment**: Only Vault address and token use environment variables -3. **config.csv for Settings**: All application configuration is in `config.csv` -4. **Per-Bot Configuration**: Each bot has its own `config.csv` in its `.gbot` folder -5. **No Hardcoded Secrets**: Never store secrets in code or config files - -## Setting Environment Variables - -### Linux/macOS - -```bash -export VAULT_ADDR=http://localhost:8200 -export VAULT_TOKEN=hvs.your-vault-token -``` - -### Systemd Service - -```ini -[Service] -Environment="VAULT_ADDR=http://localhost:8200" -Environment="VAULT_TOKEN=hvs.your-vault-token" -``` - -### LXC Container - -When using LXC deployment, environment variables are set in the container configuration: - -```bash -lxc config set container-name environment.VAULT_ADDR="http://localhost:8200" -lxc config set container-name environment.VAULT_TOKEN="hvs.your-vault-token" -``` - -## Security Notes - -1. **Never commit tokens**: Use `.env` files (gitignored) or secrets management -2. **Rotate regularly**: Vault tokens should be rotated periodically -3. **Limit access**: Only the botserver process needs these variables -4. **Use TLS**: Always use HTTPS for Vault in production - -## Bootstrap Process - -During bootstrap, General Bots: - -1. Connects to Vault using `VAULT_*` variables -2. Retrieves credentials for all managed services -3. Configures database, storage, cache, and other services -4. Stores service endpoints securely - -This eliminates the need for manual credential management. - -## Troubleshooting - -### Vault Connection Failed - -``` -Error: Failed to connect to Vault -``` - -Verify: -- `VAULT_ADDR` is set correctly -- Vault server is running and accessible -- `VAULT_TOKEN` is valid and not expired -- Network allows connection to Vault host - -### Service Not Available - -If a managed service (database, storage, cache) is unavailable: - -1. Check Vault is running and unsealed -2. Verify secrets exist in Vault -3. Check service container/process status -4. Review logs for connection errors - -## See Also - -- [config.csv Format](../chapter-08-config/config-csv.md) - Bot configuration -- [Secrets Management](../chapter-08-config/secrets-management.md) - Vault integration details -- [Drive Integration](../chapter-08-config/drive.md) - Storage setup -- [Authentication](../chapter-12-auth/README.md) - Security features \ No newline at end of file diff --git a/docs/src/appendix-external-services/README.md b/docs/src/appendix-external-services/README.md deleted file mode 100644 index 4dc0e657..00000000 --- a/docs/src/appendix-external-services/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# Appendix B: External Services - -This appendix catalogs all external services that General Bots integrates with, including their configuration requirements, associated BASIC keywords, and API endpoints. - -## Overview - -General Bots connects to external services for extended functionality. All service credentials should be stored in `config.csv` within the bot's `.gbot` folder - never hardcoded in scripts. - -Infrastructure services (database, storage, cache) are automatically managed by the Directory service (Zitadel). - -## Service Categories - -| Category | Services | Configuration Location | -|----------|----------|----------------------| -| LLM Providers | OpenAI, Groq, Anthropic, Azure OpenAI | `config.csv` | -| Weather | OpenWeatherMap | `config.csv` | -| Messaging Channels | WhatsApp, Teams, Instagram, Telegram | `config.csv` | -| Storage | S3-Compatible (MinIO, etc.) | Vault (automatic) | -| Directory | Zitadel | `VAULT_*` environment variables | -| Email | Stalwart / IMAP/SMTP | Vault (automatic) | -| Calendar | CalDAV servers | `config.csv` | -| Database | PostgreSQL | Vault (automatic) | -| Cache | Redis-compatible | Vault (automatic) | - -## Quick Reference - -### BASIC Keywords That Call External Services - -| Keyword | Service | Config Key | -|---------|---------|-----------| -| `LLM` | LLM Provider | `llm-provider`, `llm-api-key` | -| `WEATHER` | OpenWeatherMap | `weather-api-key` | -| `SEND MAIL` | SMTP Server | Managed by Directory service | -| `SEND WHATSAPP` | WhatsApp Business API | `whatsapp-api-key`, `whatsapp-phone-number-id` | -| `SEND TEAMS` | Microsoft Teams | `teams-app-id`, `teams-app-password` | -| `SEND INSTAGRAM` | Instagram Graph API | `instagram-access-token`, `instagram-page-id` | -| `GET` (with http/https URL) | Any HTTP endpoint | N/A | -| `IMAGE` | BotModels (local) | `botmodels-enabled`, `botmodels-url` | -| `VIDEO` | BotModels (local) | `botmodels-enabled`, `botmodels-url` | -| `AUDIO` | BotModels (local) | `botmodels-enabled`, `botmodels-url` | -| `SEE` | BotModels (local) | `botmodels-enabled`, `botmodels-url` | -| `FIND` | Qdrant (local) | Internal service | -| `USE WEBSITE` | Web crawling | N/A | - -## Service Configuration Template - -Add these to your `config.csv`: - -```csv -key,value -llm-provider,openai -llm-api-key,YOUR_API_KEY -llm-model,gpt-4o -weather-api-key,YOUR_OPENWEATHERMAP_KEY -whatsapp-api-key,YOUR_WHATSAPP_KEY -whatsapp-phone-number-id,YOUR_PHONE_ID -teams-app-id,YOUR_TEAMS_APP_ID -teams-app-password,YOUR_TEAMS_PASSWORD -instagram-access-token,YOUR_INSTAGRAM_TOKEN -instagram-page-id,YOUR_PAGE_ID -botmodels-enabled,true -botmodels-url,http://localhost:5000 -``` - -## Auto-Managed Services - -The following services are automatically configured by the Directory service (Zitadel): - -| Service | What's Managed | -|---------|----------------| -| PostgreSQL | Connection credentials, database creation | -| S3-Compatible Storage | Access keys, bucket policies | -| Cache | Connection credentials | -| Stalwart Email | User accounts, SMTP/IMAP access | - -You do **not** need to configure these services manually. The Directory service handles credential provisioning and rotation. - -## Security Notes - -1. **Never hardcode credentials** - Always use `config.csv` or `GET BOT MEMORY` -2. **Rotate keys regularly** - Update `config.csv` and restart the bot -3. **Use least privilege** - Only grant permissions needed by the bot -4. **Audit access** - Monitor external API usage through logs -5. **Infrastructure credentials** - Managed automatically by Directory service - -## See Also - -- [Service Catalog](./catalog.md) - Detailed service documentation -- [LLM Providers](./llm-providers.md) - AI model configuration -- [Weather API](./weather.md) - Weather service setup -- [Channel Integrations](./channels.md) - Messaging platform setup -- [Storage Services](./storage.md) - S3-compatible storage -- [Directory Services](./directory.md) - User authentication -- [Environment Variables](../appendix-env-vars/README.md) - DIRECTORY_* configuration \ No newline at end of file diff --git a/docs/src/appendix-external-services/attendance-queue.md b/docs/src/appendix-external-services/attendance-queue.md deleted file mode 100644 index d893354b..00000000 --- a/docs/src/appendix-external-services/attendance-queue.md +++ /dev/null @@ -1,78 +0,0 @@ -# Attendance Queue Module - -Human-attendant queue management for hybrid bot/human support workflows. - -## Overview - -The attendance queue module manages handoffs from bot to human agents, tracking conversation queues, attendant availability, and real-time assignment. - -## Configuration - -Create `attendant.csv` in your bot's `.gbai` folder: - -```csv -id,name,channel,preferences -att-001,John Smith,whatsapp,sales -att-002,Jane Doe,web,support -att-003,Bob Wilson,all,technical -``` - -## Queue Status - -| Status | Description | -|--------|-------------| -| `waiting` | User waiting for attendant | -| `assigned` | Attendant assigned, not yet active | -| `active` | Conversation in progress | -| `resolved` | Conversation completed | -| `abandoned` | User left before assignment | - -## Attendant Status - -| Status | Description | -|--------|-------------| -| `online` | Available for new conversations | -| `busy` | Currently handling conversations | -| `away` | Temporarily unavailable | -| `offline` | Not working | - -## REST API Endpoints - -### GET /api/queue -List conversations in queue. - -### POST /api/queue/assign -Assign conversation to attendant. - -```json -{ - "session_id": "uuid", - "attendant_id": "uuid" -} -``` - -### POST /api/queue/transfer -Transfer conversation between attendants. - -```json -{ - "session_id": "uuid", - "from_attendant_id": "uuid", - "to_attendant_id": "uuid", - "reason": "Specialist needed" -} -``` - -### GET /api/attendants -List all attendants with stats. - -## BASIC Keywords - -```basic -TRANSFER TO HUMAN "sales" -TRANSFER TO HUMAN "support", "high" -``` - -## See Also - -- [Human Approval](../chapter-06-gbdialog/keyword-human-approval.md) \ No newline at end of file diff --git a/docs/src/appendix-external-services/catalog.md b/docs/src/appendix-external-services/catalog.md deleted file mode 100644 index 0f4c5991..00000000 --- a/docs/src/appendix-external-services/catalog.md +++ /dev/null @@ -1,273 +0,0 @@ -# Service Catalog - -This catalog provides detailed information about every external service that General Bots integrates with. - -## LLM Providers - -### OpenAI - -| Property | Value | -|----------|-------| -| **Service URL** | `https://api.openai.com/v1` | -| **Config Key** | `llm-provider=openai` | -| **API Key Config** | `llm-api-key` | -| **Documentation** | [platform.openai.com/docs](https://platform.openai.com/docs) | -| **BASIC Keywords** | `LLM` | -| **Supported Models** | `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`, `gpt-3.5-turbo` | - -### Groq - -| Property | Value | -|----------|-------| -| **Service URL** | `https://api.groq.com/openai/v1` | -| **Config Key** | `llm-provider=groq` | -| **API Key Config** | `llm-api-key` | -| **Documentation** | [console.groq.com/docs](https://console.groq.com/docs) | -| **BASIC Keywords** | `LLM` | -| **Supported Models** | `llama-3.1-70b-versatile`, `llama-3.1-8b-instant`, `mixtral-8x7b-32768` | - -### Anthropic - -| Property | Value | -|----------|-------| -| **Service URL** | `https://api.anthropic.com/v1` | -| **Config Key** | `llm-provider=anthropic` | -| **API Key Config** | `llm-api-key` | -| **Documentation** | [docs.anthropic.com](https://docs.anthropic.com) | -| **BASIC Keywords** | `LLM` | -| **Supported Models** | `claude-3-5-sonnet`, `claude-3-opus`, `claude-3-haiku` | - -### Azure OpenAI - -| Property | Value | -|----------|-------| -| **Service URL** | `https://{resource}.openai.azure.com/` | -| **Config Key** | `llm-provider=azure` | -| **API Key Config** | `llm-api-key`, `azure-openai-endpoint` | -| **Documentation** | [learn.microsoft.com/azure/ai-services/openai](https://learn.microsoft.com/azure/ai-services/openai) | -| **BASIC Keywords** | `LLM` | - ---- - -## Weather Services - -### OpenWeatherMap - -| Property | Value | -|----------|-------| -| **Service URL** | `https://api.openweathermap.org/data/2.5` | -| **Config Key** | `weather-api-key` | -| **Documentation** | [openweathermap.org/api](https://openweathermap.org/api) | -| **BASIC Keywords** | `WEATHER` | -| **Free Tier** | 1,000 calls/day | -| **Required Plan** | Free or higher | - -**Example Usage:** -```basic -weather = WEATHER "Seattle" -TALK weather -``` - ---- - -## Messaging Channels - -### WhatsApp Business API - -| Property | Value | -|----------|-------| -| **Service URL** | `https://graph.facebook.com/v17.0` | -| **Config Keys** | `whatsapp-api-key`, `whatsapp-phone-number-id`, `whatsapp-business-account-id` | -| **Documentation** | [developers.facebook.com/docs/whatsapp](https://developers.facebook.com/docs/whatsapp) | -| **BASIC Keywords** | `SEND WHATSAPP`, `SEND FILE` (WhatsApp) | -| **Webhook URL** | `/api/channels/whatsapp/webhook` | - -### Microsoft Teams - -| Property | Value | -|----------|-------| -| **Service URL** | `https://smba.trafficmanager.net/apis` | -| **Config Keys** | `teams-app-id`, `teams-app-password`, `teams-tenant-id` | -| **Documentation** | [learn.microsoft.com/microsoftteams/platform](https://learn.microsoft.com/microsoftteams/platform) | -| **BASIC Keywords** | `SEND TEAMS`, `SEND FILE` (Teams) | -| **Webhook URL** | `/api/channels/teams/messages` | - -### Instagram Messaging - -| Property | Value | -|----------|-------| -| **Service URL** | `https://graph.facebook.com/v17.0` | -| **Config Keys** | `instagram-access-token`, `instagram-page-id`, `instagram-account-id` | -| **Documentation** | [developers.facebook.com/docs/instagram-api](https://developers.facebook.com/docs/instagram-api) | -| **BASIC Keywords** | `SEND INSTAGRAM` | -| **Webhook URL** | `/api/channels/instagram/webhook` | - -### Telegram - -| Property | Value | -|----------|-------| -| **Service URL** | `https://api.telegram.org/bot{token}` | -| **Config Keys** | `telegram-bot-token` | -| **Documentation** | [core.telegram.org/bots/api](https://core.telegram.org/bots/api) | -| **BASIC Keywords** | `SEND TELEGRAM` | -| **Webhook URL** | `/api/channels/telegram/webhook` | - ---- - -## Storage Services - -### S3-Compatible Storage - -General Bots uses S3-compatible object storage. Configuration is **automatically managed** by the Directory service (Zitadel). - -| Property | Value | -|----------|-------| -| **Local Default** | MinIO on port 9000 | -| **Management** | Directory service (automatic) | -| **Console Port** | 9001 (when using MinIO) | -| **BASIC Keywords** | `GET` (file retrieval) | - -**Compatible Services:** -- MinIO (default local installation) -- Backblaze B2 -- Wasabi -- DigitalOcean Spaces -- Cloudflare R2 -- Any S3-compatible provider - -Storage credentials are provisioned and rotated automatically by the Directory service. No manual configuration required. - ---- - -## Directory Services - -### Zitadel (Identity Provider) - -| Property | Value | -|----------|-------| -| **Local Default** | Port 8080 | -| **Environment Variables** | `DIRECTORY_URL`, `DIRECTORY_CLIENT_ID`, `DIRECTORY_CLIENT_SECRET` | -| **Documentation** | [zitadel.com/docs](https://zitadel.com/docs) | -| **Purpose** | User authentication, SSO, OAuth2/OIDC, service credential management | - -The Directory service manages: -- User authentication -- Service credentials (database, storage, cache) -- OAuth applications -- Role-based access control - ---- - -## Email Services - -### Stalwart Mail Server - -| Property | Value | -|----------|-------| -| **Ports** | 25 (SMTP), 993 (IMAPS), 587 (Submission) | -| **Management** | Directory service (automatic) | -| **Documentation** | [stalw.art/docs](https://stalw.art/docs) | -| **BASIC Keywords** | `SEND MAIL` | - -Email accounts are created and managed through the Directory service. - -### External IMAP/SMTP - -| Property | Value | -|----------|-------| -| **Config Keys** | `smtp-server`, `smtp-port`, `imap-server`, `imap-port`, `email-username`, `email-password` | -| **BASIC Keywords** | `SEND MAIL` | -| **Supported Providers** | Gmail, Outlook, custom SMTP/IMAP | - -**Gmail Configuration Example (in config.csv):** -```csv -smtp-server,smtp.gmail.com -smtp-port,587 -imap-server,imap.gmail.com -imap-port,993 -``` - ---- - -## Local Services (BotModels) - -### Image Generation - -| Property | Value | -|----------|-------| -| **Service URL** | `http://localhost:5000` (default) | -| **Config Keys** | `botmodels-enabled`, `botmodels-url` | -| **BASIC Keywords** | `IMAGE` | -| **Requires** | BotModels service running | - -### Video Generation - -| Property | Value | -|----------|-------| -| **Service URL** | `http://localhost:5000` (default) | -| **Config Keys** | `botmodels-enabled`, `botmodels-url` | -| **BASIC Keywords** | `VIDEO` | -| **Requires** | BotModels service running, GPU recommended | - -### Audio Generation (TTS) - -| Property | Value | -|----------|-------| -| **Service URL** | `http://localhost:5000` (default) | -| **Config Keys** | `botmodels-enabled`, `botmodels-url` | -| **BASIC Keywords** | `AUDIO` | -| **Requires** | BotModels service running | - -### Vision/Captioning - -| Property | Value | -|----------|-------| -| **Service URL** | `http://localhost:5000` (default) | -| **Config Keys** | `botmodels-enabled`, `botmodels-url` | -| **BASIC Keywords** | `SEE` | -| **Requires** | BotModels service running | - ---- - -## Internal Services - -These services are deployed locally as part of the General Bots stack. All are managed by the Directory service: - -| Service | Default Port | Purpose | Management | -|---------|-------------|---------|------------| -| PostgreSQL | 5432 | Primary database | Vault | -| Qdrant | 6333 | Vector storage for KB | Vault | -| Cache | 6379 | Caching | Vault | -| Stalwart | 25, 993 | Email server (optional) | Vault | -| BotModels | 5000 | AI model inference | config.csv | - ---- - -## Service Health Checks - -All services can be checked via the monitoring API: - -``` -GET /api/monitoring/services -``` - -Response includes status for all configured external services. - ---- - -## Troubleshooting - -### Common Issues - -1. **API Key Invalid** - Verify key in `config.csv`, ensure no trailing whitespace -2. **Rate Limited** - Check service quotas, implement caching with `SET BOT MEMORY` -3. **Connection Timeout** - Verify network access to external URLs -4. **Service Unavailable** - Check service status pages - -### Debug Logging - -Enable trace logging to see external API calls: - -```bash -RUST_LOG=trace ./botserver -``` diff --git a/docs/src/appendix-external-services/channels.md b/docs/src/appendix-external-services/channels.md deleted file mode 100644 index e12e4984..00000000 --- a/docs/src/appendix-external-services/channels.md +++ /dev/null @@ -1 +0,0 @@ -# Channel Integrations diff --git a/docs/src/appendix-external-services/console.md b/docs/src/appendix-external-services/console.md deleted file mode 100644 index b2373536..00000000 --- a/docs/src/appendix-external-services/console.md +++ /dev/null @@ -1,114 +0,0 @@ -# Console Module (XtreeUI) - -Terminal-based admin interface for managing General Bots instances. - -## Overview - -XtreeUI is a TUI (Terminal User Interface) for administering bots directly from the command line. It provides file browsing, log viewing, chat testing, and status monitoring in a single terminal window. - -## Feature Flag - -Enabled via Cargo feature: - -```toml -[features] -console = [] -``` - -## Panels - -| Panel | Key | Description | -|-------|-----|-------------| -| File Tree | `1` | Browse bot files and packages | -| Editor | `2` | View/edit configuration files | -| Status | `3` | System status and metrics | -| Logs | `4` | Real-time log viewer | -| Chat | `5` | Test bot conversations | - -## Keyboard Navigation - -| Key | Action | -|-----|--------| -| `1-5` | Switch between panels | -| `Tab` | Cycle panels | -| `↑/↓` | Navigate within panel | -| `Enter` | Select/open item | -| `q` | Quit console | -| `?` | Show help | - -## Components - -### File Tree - -Browse `.gbai` folder structure: -- View packages (.gbkb, .gbdialog, .gbtheme) -- Open config.csv for editing -- Navigate bot resources - -### Status Panel - -Real-time system metrics: -- CPU/memory usage -- Active connections -- Bot status -- Database connectivity - -### Log Panel - -Live log streaming with filtering: -- Error highlighting -- Log level filtering -- Search functionality - -### Chat Panel - -Interactive bot testing: -- Send messages to bot -- View responses -- Debug conversation flow - -### Editor - -Basic file editing: -- Syntax highlighting -- Save/reload files -- Config validation - -## Starting the Console - -```bash -./botserver --console -``` - -Or programmatically: - -```rust -let mut ui = XtreeUI::new(); -ui.set_app_state(app_state); -ui.start_ui()?; -``` - -## Progress Channel - -Monitor background tasks: - -```rust -let (tx, rx) = tokio::sync::mpsc::channel(100); -ui.set_progress_channel(rx); - -// Send progress updates -tx.send(ProgressUpdate::new("Loading KB...", 50)).await; -``` - -## Use Cases - -- Server administration without web UI -- SSH-based remote management -- Development and debugging -- Headless server deployments -- Quick configuration changes - -## See Also - -- [Building from Source](../chapter-07-gbapp/building.md) -- [Bot Configuration](../chapter-08-config/README.md) \ No newline at end of file diff --git a/docs/src/appendix-external-services/directory.md b/docs/src/appendix-external-services/directory.md deleted file mode 100644 index 6382340e..00000000 --- a/docs/src/appendix-external-services/directory.md +++ /dev/null @@ -1 +0,0 @@ -# Directory Services diff --git a/docs/src/appendix-external-services/llm-providers.md b/docs/src/appendix-external-services/llm-providers.md deleted file mode 100644 index 8e42ca32..00000000 --- a/docs/src/appendix-external-services/llm-providers.md +++ /dev/null @@ -1,437 +0,0 @@ -# LLM Providers - -General Bots supports multiple Large Language Model (LLM) providers, both cloud-based services and local deployments. This guide helps you choose the right provider for your use case. - -## Overview - -LLMs are the intelligence behind General Bots' conversational capabilities. You can configure: - -- **Cloud Providers** - External APIs (OpenAI, Anthropic, Groq, etc.) -- **Local Models** - Self-hosted models via llama.cpp -- **Hybrid** - Use local for simple tasks, cloud for complex reasoning - -## Cloud Providers - -### OpenAI (GPT Series) - -The most widely known LLM provider, offering GPT-4 and GPT-4o models. - -| Model | Context | Best For | Speed | -|-------|---------|----------|-------| -| GPT-4o | 128K | General purpose, vision | Fast | -| GPT-4o-mini | 128K | Cost-effective tasks | Very Fast | -| GPT-4 Turbo | 128K | Complex reasoning | Medium | -| o1-preview | 128K | Advanced reasoning, math | Slow | -| o1-mini | 128K | Code, logic tasks | Medium | - -**Configuration:** - -```csv -llm-provider,openai -llm-api-key,sk-xxxxxxxxxxxxxxxxxxxxxxxx -llm-model,gpt-4o -``` - -**Strengths:** -- Excellent general knowledge -- Strong code generation -- Good instruction following -- Vision capabilities (GPT-4o) - -**Considerations:** -- API costs can add up -- Data sent to external servers -- Rate limits apply - -### Anthropic (Claude Series) - -Known for safety, helpfulness, and large context windows. - -| Model | Context | Best For | Speed | -|-------|---------|----------|-------| -| Claude 3.5 Sonnet | 200K | Best balance of capability/speed | Fast | -| Claude 3.5 Haiku | 200K | Quick, everyday tasks | Very Fast | -| Claude 3 Opus | 200K | Most capable, complex tasks | Slow | - -**Configuration:** - -```csv -llm-provider,anthropic -llm-api-key,sk-ant-xxxxxxxxxxxxxxxx -llm-model,claude-3-5-sonnet-20241022 -``` - -**Strengths:** -- Largest context window (200K tokens) -- Excellent at following complex instructions -- Strong coding abilities -- Better at refusing harmful requests - -**Considerations:** -- Premium pricing -- No vision in all models -- Newer provider, smaller ecosystem - -### Groq - -Ultra-fast inference using custom LPU hardware. Offers open-source models at high speed. - -| Model | Context | Best For | Speed | -|-------|---------|----------|-------| -| Llama 3.3 70B | 128K | Complex reasoning | Very Fast | -| Llama 3.1 8B | 128K | Quick responses | Extremely Fast | -| Mixtral 8x7B | 32K | Balanced performance | Very Fast | -| Gemma 2 9B | 8K | Lightweight tasks | Extremely Fast | - -**Configuration:** - -```csv -llm-provider,groq -llm-api-key,gsk_xxxxxxxxxxxxxxxx -llm-model,llama-3.3-70b-versatile -``` - -**Strengths:** -- Fastest inference speeds (500+ tokens/sec) -- Competitive pricing -- Open-source models -- Great for real-time applications - -**Considerations:** -- Limited model selection -- Rate limits on free tier -- Models may be less capable than GPT-4/Claude - -### Google (Gemini Series) - -Google's multimodal AI models with strong reasoning capabilities. - -| Model | Context | Best For | Speed | -|-------|---------|----------|-------| -| Gemini 1.5 Pro | 2M | Extremely long documents | Medium | -| Gemini 1.5 Flash | 1M | Fast multimodal | Fast | -| Gemini 2.0 Flash | 1M | Latest capabilities | Fast | - -**Configuration:** - -```csv -llm-provider,google -llm-api-key,AIzaxxxxxxxxxxxxxxxx -llm-model,gemini-1.5-pro -``` - -**Strengths:** -- Largest context window (2M tokens) -- Native multimodal (text, image, video, audio) -- Strong at structured data -- Good coding abilities - -**Considerations:** -- Newer ecosystem -- Some features region-limited -- API changes more frequently - -### Mistral AI - -European AI company offering efficient, open-weight models. - -| Model | Context | Best For | Speed | -|-------|---------|----------|-------| -| Mistral Large | 128K | Complex tasks | Medium | -| Mistral Medium | 32K | Balanced performance | Fast | -| Mistral Small | 32K | Cost-effective | Very Fast | -| Codestral | 32K | Code generation | Fast | - -**Configuration:** - -```csv -llm-provider,mistral -llm-api-key,xxxxxxxxxxxxxxxx -llm-model,mistral-large-latest -``` - -**Strengths:** -- European data sovereignty (GDPR) -- Excellent code generation (Codestral) -- Open-weight models available -- Competitive pricing - -**Considerations:** -- Smaller context than competitors -- Less brand recognition -- Fewer fine-tuning options - -### DeepSeek - -Chinese AI company known for efficient, capable models. - -| Model | Context | Best For | Speed | -|-------|---------|----------|-------| -| DeepSeek-V3 | 128K | General purpose | Fast | -| DeepSeek-R1 | 128K | Reasoning, math | Medium | -| DeepSeek-Coder | 128K | Programming | Fast | - -**Configuration:** - -```csv -llm-provider,deepseek -llm-api-key,sk-xxxxxxxxxxxxxxxx -llm-model,deepseek-chat -llm-server-url,https://api.deepseek.com -``` - -**Strengths:** -- Extremely cost-effective -- Strong reasoning (R1 model) -- Excellent code generation -- Open-weight versions available - -**Considerations:** -- Data processed in China -- Newer provider -- May have content restrictions - -## Local Models - -Run models on your own hardware for privacy, cost control, and offline operation. - -### Setting Up Local LLM - -General Bots uses **llama.cpp** server for local inference: - -```csv -llm-provider,local -llm-server-url,https://localhost:8081 -llm-model,DeepSeek-R1-Distill-Qwen-1.5B -``` - -### Recommended Local Models - -#### For High-End GPU (24GB+ VRAM) - -| Model | Size | VRAM | Quality | -|-------|------|------|---------| -| GPT-OSS 120B Q4 | 70GB | 48GB+ | Excellent | -| Llama 3.1 70B Q4 | 40GB | 48GB+ | Excellent | -| DeepSeek-R1 32B Q4 | 20GB | 24GB | Very Good | -| Qwen 2.5 72B Q4 | 42GB | 48GB+ | Excellent | - -#### For Mid-Range GPU (12-16GB VRAM) - -| Model | Size | VRAM | Quality | -|-------|------|------|---------| -| GPT-OSS 20B F16 | 40GB | 16GB | Very Good | -| Llama 3.1 8B Q8 | 9GB | 12GB | Good | -| DeepSeek-R1-Distill 14B Q4 | 8GB | 12GB | Good | -| Mistral Nemo 12B Q4 | 7GB | 10GB | Good | - -#### For Small GPU or CPU (8GB VRAM or less) - -| Model | Size | VRAM | Quality | -|-------|------|------|---------| -| DeepSeek-R1-Distill 1.5B Q4 | 1GB | 4GB | Basic | -| Phi-3 Mini 3.8B Q4 | 2.5GB | 6GB | Acceptable | -| Gemma 2 2B Q8 | 3GB | 6GB | Acceptable | -| Qwen 2.5 3B Q4 | 2GB | 4GB | Basic | - -### Model Download URLs - -Add models to `installer.rs` data_download_list: - -```rust -// GPT-OSS 20B - Recommended for small GPU -"https://huggingface.co/unsloth/gpt-oss-20b-GGUF/resolve/main/gpt-oss-20b-F16.gguf" - -// DeepSeek R1 Distill - For CPU or minimal GPU -"https://huggingface.co/unsloth/DeepSeek-R1-Distill-Qwen-1.5B-GGUF/resolve/main/DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf" - -// Llama 3.1 8B - Good balance -"https://huggingface.co/bartowski/Meta-Llama-3.1-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf" -``` - -### Embedding Models - -For vector search, you need an embedding model: - -```csv -embedding-provider,local -embedding-server-url,https://localhost:8082 -embedding-model,bge-small-en-v1.5 -``` - -Recommended embedding models: - -| Model | Dimensions | Size | Quality | -|-------|------------|------|---------| -| bge-small-en-v1.5 | 384 | 130MB | Good | -| bge-base-en-v1.5 | 768 | 440MB | Better | -| bge-large-en-v1.5 | 1024 | 1.3GB | Best | -| nomic-embed-text | 768 | 550MB | Good | - -## Hybrid Configuration - -Use different models for different tasks: - -```csv -# Primary model for complex conversations -llm-provider,anthropic -llm-model,claude-3-5-sonnet-20241022 - -# Fast model for simple tasks -llm-fast-provider,groq -llm-fast-model,llama-3.1-8b-instant - -# Local fallback for offline operation -llm-fallback-provider,local -llm-fallback-model,DeepSeek-R1-Distill-Qwen-1.5B - -# Embeddings always local -embedding-provider,local -embedding-model,bge-small-en-v1.5 -``` - -## Model Selection Guide - -### By Use Case - -| Use Case | Recommended | Why | -|----------|-------------|-----| -| Customer support | Claude 3.5 Sonnet | Best at following guidelines | -| Code generation | DeepSeek-Coder, GPT-4o | Specialized for code | -| Document analysis | Gemini 1.5 Pro | 2M context window | -| Real-time chat | Groq Llama 3.1 8B | Fastest responses | -| Privacy-sensitive | Local DeepSeek-R1 | No external data transfer | -| Cost-sensitive | DeepSeek-V3, Local | Lowest cost per token | -| Complex reasoning | Claude 3 Opus, o1 | Best reasoning ability | - -### By Budget - -| Budget | Recommended Setup | -|--------|-------------------| -| Free | Local models only | -| Low ($10-50/mo) | Groq + Local fallback | -| Medium ($50-200/mo) | GPT-4o-mini + Claude Haiku | -| High ($200+/mo) | GPT-4o + Claude Sonnet | -| Enterprise | Private deployment + premium APIs | - -## Configuration Reference - -### Environment Variables - -```bash -# Primary LLM -LLM_PROVIDER=openai -LLM_API_KEY=sk-xxx -LLM_MODEL=gpt-4o -LLM_SERVER_URL=https://api.openai.com - -# Local LLM Server -LLM_LOCAL_URL=https://localhost:8081 -LLM_LOCAL_MODEL=DeepSeek-R1-Distill-Qwen-1.5B - -# Embedding -EMBEDDING_PROVIDER=local -EMBEDDING_URL=https://localhost:8082 -EMBEDDING_MODEL=bge-small-en-v1.5 -``` - -### config.csv Parameters - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `llm-provider` | Provider name | `openai`, `anthropic`, `local` | -| `llm-api-key` | API key for cloud providers | `sk-xxx` | -| `llm-model` | Model identifier | `gpt-4o` | -| `llm-server-url` | API endpoint | `https://api.openai.com` | -| `llm-server-ctx-size` | Context window size | `128000` | -| `llm-temperature` | Response randomness (0-2) | `0.7` | -| `llm-max-tokens` | Maximum response length | `4096` | -| `llm-cache-enabled` | Enable semantic caching | `true` | -| `llm-cache-ttl` | Cache time-to-live (seconds) | `3600` | - -## Security Considerations - -### Cloud Providers - -- API keys should be stored in environment variables or secrets manager -- Consider data residency requirements (EU: Mistral, US: OpenAI) -- Review provider data retention policies -- Use separate keys for production/development - -### Local Models - -- All data stays on your infrastructure -- No internet required after model download -- Full control over model versions -- Consider GPU security for sensitive deployments - -## Performance Optimization - -### Caching - -Enable semantic caching to reduce API calls: - -```csv -llm-cache-enabled,true -llm-cache-ttl,3600 -llm-cache-similarity-threshold,0.92 -``` - -### Batching - -For bulk operations, use batch APIs when available: - -```csv -llm-batch-enabled,true -llm-batch-size,10 -``` - -### Context Management - -Optimize context window usage: - -```csv -llm-context-compaction,true -llm-max-history-turns,10 -llm-summarize-long-contexts,true -``` - -## Troubleshooting - -### Common Issues - -**API Key Invalid** -- Verify key is correct and not expired -- Check if key has required permissions -- Ensure billing is active - -**Model Not Found** -- Check model name spelling -- Verify model is available in your region -- Some models require waitlist access - -**Rate Limits** -- Implement exponential backoff -- Use caching to reduce calls -- Consider upgrading API tier - -**Local Model Slow** -- Check GPU memory usage -- Reduce context size -- Use quantized models (Q4 instead of F16) - -### Logging - -Enable LLM logging for debugging: - -```csv -llm-log-requests,true -llm-log-responses,false -llm-log-timing,true -``` - -## Next Steps - -- [LLM Configuration](../chapter-08-config/llm-config.md) - Detailed configuration guide -- [Semantic Caching](../chapter-03/caching.md) - Cache configuration -- [NVIDIA GPU Setup](../chapter-09-api/nvidia-gpu-setup.md) - GPU configuration for local models \ No newline at end of file diff --git a/docs/src/appendix-external-services/multimodal.md b/docs/src/appendix-external-services/multimodal.md deleted file mode 100644 index 7ce972d8..00000000 --- a/docs/src/appendix-external-services/multimodal.md +++ /dev/null @@ -1,143 +0,0 @@ -# Multimodal Module - -Image, video, and audio generation with vision/captioning capabilities. - -## Overview - -The multimodal module connects to BotModels server for AI-powered media generation and analysis. - -## BASIC Keywords - -| Keyword | Purpose | -|---------|---------| -| `IMAGE` | Generate image from text prompt | -| `VIDEO` | Generate video from text prompt | -| `AUDIO` | Generate speech audio from text | -| `SEE` | Describe/caption an image or video | - -## IMAGE - -Generate an image from a text prompt: - -```basic -url = IMAGE "A sunset over mountains with a lake" -TALK "Here's your image: " + url -``` - -Timeout: 300 seconds (5 minutes) - -## VIDEO - -Generate a video from a text prompt: - -```basic -url = VIDEO "A cat playing with a ball of yarn" -TALK "Here's your video: " + url -``` - -Timeout: 600 seconds (10 minutes) - -## AUDIO - -Generate speech audio from text: - -```basic -url = AUDIO "Welcome to our service. How can I help you today?" -PLAY url -``` - -## SEE - -Get a description of an image or video: - -```basic -description = SEE "path/to/image.jpg" -TALK "I see: " + description -``` - -## Configuration - -Add to `config.csv`: - -```csv -botmodels-enabled,true -botmodels-host,localhost -botmodels-port,5000 -botmodels-api-key,your-api-key -botmodels-use-https,false -``` - -### Image Generation Config - -```csv -botmodels-image-model,stable-diffusion -botmodels-image-steps,20 -botmodels-image-width,512 -botmodels-image-height,512 -``` - -### Video Generation Config - -```csv -botmodels-video-model,text2video -botmodels-video-frames,16 -botmodels-video-fps,8 -``` - -## BotModels Client - -Rust API for direct integration: - -```rust -let client = BotModelsClient::from_state(&state, &bot_id); - -if client.is_enabled() { - let image_url = client.generate_image("A beautiful garden").await?; - let description = client.describe_image("path/to/photo.jpg").await?; -} -``` - -### Available Methods - -| Method | Description | -|--------|-------------| -| `generate_image(prompt)` | Create image from text | -| `generate_video(prompt)` | Create video from text | -| `generate_audio(text)` | Create speech audio | -| `describe_image(path)` | Get image caption | -| `describe_video(path)` | Get video description | -| `speech_to_text(audio_path)` | Transcribe audio | -| `health_check()` | Check BotModels server status | - -## Response Structures - -### GenerationResponse - -```json -{ - "status": "success", - "file_path": "/path/to/generated/file.png", - "generation_time": 12.5, - "error": null -} -``` - -### DescribeResponse - -```json -{ - "description": "A golden retriever playing fetch in a park", - "confidence": 0.92 -} -``` - -## Requirements - -- BotModels server running (separate service) -- GPU recommended for generation tasks -- Sufficient disk space for generated media - -## See Also - -- [NVIDIA Module](./nvidia.md) - GPU monitoring -- [PLAY Keyword](../chapter-06-gbdialog/keyword-play.md) - Play generated audio \ No newline at end of file diff --git a/docs/src/appendix-external-services/nvidia.md b/docs/src/appendix-external-services/nvidia.md deleted file mode 100644 index c45ed487..00000000 --- a/docs/src/appendix-external-services/nvidia.md +++ /dev/null @@ -1,76 +0,0 @@ -# NVIDIA GPU Module - -System monitoring for NVIDIA GPU utilization and performance metrics. - -## Overview - -This module provides GPU monitoring capabilities when NVIDIA hardware is available, useful for tracking resource usage during LLM inference and multimodal generation tasks. - -## Feature Flag - -Enabled via Cargo feature: - -```toml -[features] -nvidia = [] -``` - -## Functions - -### has_nvidia_gpu() - -Check if NVIDIA GPU is available: - -```rust -if nvidia::has_nvidia_gpu() { - // GPU acceleration available -} -``` - -Returns `true` if `nvidia-smi` command succeeds. - -### get_gpu_utilization() - -Get current GPU and memory utilization: - -```rust -let util = nvidia::get_gpu_utilization()?; -let gpu_percent = util.get("gpu"); // GPU compute utilization % -let mem_percent = util.get("memory"); // GPU memory utilization % -``` - -### get_system_metrics() - -Get combined CPU and GPU metrics: - -```rust -let metrics = nvidia::get_system_metrics()?; -println!("CPU: {}%", metrics.cpu_usage); -if let Some(gpu) = metrics.gpu_usage { - println!("GPU: {}%", gpu); -} -``` - -## SystemMetrics Struct - -| Field | Type | Description | -|-------|------|-------------| -| `cpu_usage` | `f32` | CPU utilization percentage | -| `gpu_usage` | `Option` | GPU utilization (None if no NVIDIA GPU) | - -## Requirements - -- NVIDIA GPU with driver installed -- `nvidia-smi` command available in PATH - -## Use Cases - -- Monitor GPU during image/video generation -- Track resource usage for LLM inference -- Capacity planning for bot deployments -- Performance dashboards - -## See Also - -- [Multimodal Module](./multimodal.md) -- [Time-Series Database](./timeseries.md) - Store GPU metrics over time \ No newline at end of file diff --git a/docs/src/appendix-external-services/storage.md b/docs/src/appendix-external-services/storage.md deleted file mode 100644 index 280d8090..00000000 --- a/docs/src/appendix-external-services/storage.md +++ /dev/null @@ -1 +0,0 @@ -# Storage Services diff --git a/docs/src/appendix-external-services/timeseries.md b/docs/src/appendix-external-services/timeseries.md deleted file mode 100644 index 795c8737..00000000 --- a/docs/src/appendix-external-services/timeseries.md +++ /dev/null @@ -1,85 +0,0 @@ -# Time-Series Database Module - -InfluxDB 3 integration for metrics, analytics, and operational data. - -## Overview - -High-performance time-series storage supporting 2.5M+ points/sec ingestion with async batching. - -## Configuration - -Add to `config.csv`: - -```csv -influxdb-url,http://localhost:8086 -influxdb-token,your-token -influxdb-org,pragmatismo -influxdb-bucket,metrics -``` - -Or environment variables: - -```bash -INFLUXDB_URL=http://localhost:8086 -INFLUXDB_TOKEN=your-token -INFLUXDB_ORG=pragmatismo -INFLUXDB_BUCKET=metrics -``` - -## Metric Points - -Structure: - -| Field | Description | -|-------|-------------| -| `measurement` | Metric name (e.g., "messages", "response_time") | -| `tags` | Indexed key-value pairs for filtering | -| `fields` | Actual metric values | -| `timestamp` | When the metric was recorded | - -## Built-in Metrics - -| Measurement | Tags | Fields | -|-------------|------|--------| -| `messages` | bot, channel, user | count | -| `response_time` | bot, endpoint | duration_ms | -| `llm_tokens` | bot, model, type | input, output, total | -| `kb_queries` | bot, collection | count, latency_ms | -| `errors` | bot, type, severity | count | - -## Usage in Rust - -```rust -let client = TimeSeriesClient::new(config).await?; - -client.write_point( - MetricPoint::new("messages") - .tag("bot", "sales-bot") - .tag("channel", "whatsapp") - .field_i64("count", 1) -).await?; -``` - -## Querying - -REST endpoint for analytics: - -``` -GET /api/analytics/timeseries/messages?range=24h -GET /api/analytics/timeseries/response_time?range=7d -``` - -## Installation - -The timeseries_db component is installed via package manager: - -```bash -gb install timeseries_db -``` - -Ports: 8086 (HTTP API), 8083 (RPC) - -## See Also - -- [Analytics Module](../chapter-04-gbui/apps/analytics.md) -- [Observability Setup](./observability.md) \ No newline at end of file diff --git a/docs/src/appendix-external-services/weather.md b/docs/src/appendix-external-services/weather.md deleted file mode 100644 index a227f364..00000000 --- a/docs/src/appendix-external-services/weather.md +++ /dev/null @@ -1,318 +0,0 @@ -# Weather API Integration - -The `WEATHER` and `FORECAST` keywords provide real-time weather information and multi-day forecasts using the OpenWeatherMap API. - -## Keywords Overview - -| Keyword | Purpose | -|---------|---------| -| `WEATHER` | Get current weather conditions for a location | -| `FORECAST` | Get extended weather forecast for multiple days | - -## WEATHER - -Retrieves current weather conditions for a specified location. - -### Syntax - -```basic -result = WEATHER location -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `location` | String | City name, optionally with country code (e.g., "London" or "London,UK") | - -### Return Value - -Returns a formatted string containing: -- Temperature (current and feels-like) -- Weather conditions description -- Humidity percentage -- Wind speed and direction -- Visibility -- Atmospheric pressure - -### Example - -```basic -' Get current weather for London -weather = WEATHER "London" -TALK weather - -' Output: -' Current weather in London: -' 🌡️ Temperature: 15.2°C (feels like 14.5°C) -' ☁️ Conditions: Partly cloudy -' 💧 Humidity: 65% -' 💨 Wind: 3.5 m/s NE -' 🔍 Visibility: 10.0 km -' 📊 Pressure: 1013 hPa -``` - -## FORECAST - -Retrieves an extended weather forecast for multiple days. - -### Syntax - -```basic -result = FORECAST location, days -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `location` | String | City name, optionally with country code | -| `days` | Integer | Number of days to forecast (1-5, default: 5) | - -### Example - -```basic -' Get 5-day forecast for Paris -forecast = FORECAST "Paris,FR", 5 -TALK forecast - -' Output: -' Weather forecast for Paris: -' -' 📅 2024-03-15 -' 🌡️ High: 18.5°C, Low: 12.3°C -' ☁️ Scattered clouds -' ☔ Rain chance: 20% -' -' 📅 2024-03-16 -' 🌡️ High: 20.1°C, Low: 13.0°C -' ☁️ Clear sky -' ☔ Rain chance: 5% -' ... -``` - -## Complete Example: Weather Bot - -```basic -' weather-assistant.bas -' A conversational weather assistant - -TALK "Hello! I can help you with weather information." -TALK "Which city would you like to know about?" - -HEAR city - -TALK "Would you like the current weather or a forecast?" -HEAR choice - -IF INSTR(LOWER(choice), "forecast") > 0 THEN - TALK "How many days? (1-5)" - HEAR days - - IF NOT IS_NUMERIC(days) THEN - days = 5 - END IF - - result = FORECAST city, days - TALK result -ELSE - result = WEATHER city - TALK result -END IF - -TALK "Is there another city you'd like to check?" -``` - -## Weather-Based Automation - -```basic -' weather-alert.bas -' Send alerts based on weather conditions - -cities = ["New York", "London", "Tokyo", "Sydney"] - -FOR EACH city IN cities - weather = WEATHER city - - ' Check for extreme conditions - IF INSTR(weather, "storm") > 0 OR INSTR(weather, "heavy rain") > 0 THEN - SEND MAIL "alerts@company.com", "Weather Alert: " + city, weather - END IF -NEXT -``` - -## Daily Weather Report - -```basic -' daily-weather.bas -' Generate a daily weather report for multiple locations - -locations = ["San Francisco,US", "Austin,US", "Seattle,US"] -report = "☀️ Daily Weather Report\n\n" - -FOR EACH loc IN locations - weather = WEATHER loc - report = report + weather + "\n\n---\n\n" -NEXT - -' Send the compiled report -SEND MAIL "team@company.com", "Daily Weather Update", report -``` - -## Travel Planning Assistant - -```basic -' travel-weather.bas -' Help users plan travel based on weather - -TALK "Where are you planning to travel?" -HEAR destination - -TALK "When are you planning to go? (Please provide a date)" -HEAR travel_date - -' Get forecast for destination -forecast = FORECAST destination, 5 -TALK "Here's the weather forecast for " + destination + ":" -TALK forecast - -TALK "Based on the forecast, would you like packing suggestions?" -HEAR wants_suggestions - -IF LOWER(wants_suggestions) = "yes" THEN - weather = WEATHER destination - - IF INSTR(weather, "rain") > 0 THEN - TALK "🌂 Don't forget to pack an umbrella and rain jacket!" - END IF - - IF INSTR(weather, "Temperature: 2") > 0 OR INSTR(weather, "Temperature: 3") > 0 THEN - TALK "🩳 It's warm! Pack light clothing and sunscreen." - ELSE IF INSTR(weather, "Temperature: 0") > 0 OR INSTR(weather, "Temperature: 1") > 0 THEN - TALK "🧥 It's cool. Bring a light jacket." - ELSE - TALK "🧣 It's cold! Pack warm layers and a coat." - END IF -END IF -``` - -## Weather Data Structure - -The `WeatherData` object returned internally contains: - -| Field | Type | Description | -|-------|------|-------------| -| `location` | String | Resolved location name | -| `temperature` | Float | Current temperature in Celsius | -| `temperature_unit` | String | Temperature unit (°C) | -| `description` | String | Weather condition description | -| `humidity` | Integer | Humidity percentage (0-100) | -| `wind_speed` | Float | Wind speed in m/s | -| `wind_direction` | String | Compass direction (N, NE, E, etc.) | -| `feels_like` | Float | "Feels like" temperature | -| `pressure` | Integer | Atmospheric pressure in hPa | -| `visibility` | Float | Visibility in kilometers | -| `uv_index` | Float (optional) | UV index if available | -| `forecast` | Array | Forecast data (for FORECAST keyword) | - -## Forecast Day Structure - -Each forecast day contains: - -| Field | Type | Description | -|-------|------|-------------| -| `date` | String | Date in YYYY-MM-DD format | -| `temp_high` | Float | Maximum temperature | -| `temp_low` | Float | Minimum temperature | -| `description` | String | Weather conditions | -| `rain_chance` | Integer | Probability of precipitation (0-100%) | - -## Configuration - -To use the weather keywords, configure your OpenWeatherMap API key in `config.csv`: - -| Key | Description | Required | -|-----|-------------|----------| -| `weather-api-key` | OpenWeatherMap API key | Yes | - -### Getting an API Key - -1. Visit [OpenWeatherMap](https://openweathermap.org/api) -2. Create a free account -3. Navigate to "API Keys" in your dashboard -4. Generate a new API key -5. Add to your bot's `config.csv`: - -```csv -weather-api-key,your-api-key-here -``` - -## Wind Direction Compass - -Wind direction is converted from degrees to compass directions: - -| Degrees | Direction | -|---------|-----------| -| 0° | N (North) | -| 45° | NE (Northeast) | -| 90° | E (East) | -| 135° | SE (Southeast) | -| 180° | S (South) | -| 225° | SW (Southwest) | -| 270° | W (West) | -| 315° | NW (Northwest) | - -## Error Handling - -```basic -' Handle weather API errors gracefully -ON ERROR GOTO weather_error - -weather = WEATHER "Unknown City XYZ" -TALK weather -END - -weather_error: - TALK "Sorry, I couldn't get weather information for that location." - TALK "Please check the city name and try again." -END -``` - -## Rate Limits - -The OpenWeatherMap free tier includes: -- 60 calls per minute -- 1,000,000 calls per month - -For higher limits, consider upgrading to a paid plan. - -## Best Practices - -1. **Use country codes**: For accuracy, include country codes (e.g., "Paris,FR" instead of just "Paris"). - -2. **Cache results**: Weather data doesn't change frequently—consider caching results for 10-15 minutes. - -3. **Handle timeouts**: Weather API calls have a 10-second timeout. Handle failures gracefully. - -4. **Validate locations**: Check if the location is valid before making API calls. - -5. **Localization**: Consider user preferences for temperature units (Celsius vs Fahrenheit). - -## Fallback Behavior - -If the OpenWeatherMap API is unavailable, the system will: -1. Log the error -2. Attempt a fallback weather service (if configured) -3. Return a user-friendly error message - -## Related Keywords - -- [GET](../chapter-06-gbdialog/keyword-get.md) - Make custom HTTP requests to weather APIs -- [SET SCHEDULE](../chapter-06-gbdialog/keyword-set-schedule.md) - Schedule regular weather checks -- [SEND MAIL](../chapter-06-gbdialog/keyword-send-mail.md) - Send weather alerts via email -- [SEND SMS](../chapter-06-gbdialog/keyword-sms.md) - Send weather alerts via SMS - -## See Also - -- [OpenWeatherMap API Documentation](https://openweathermap.org/api) -- [API Tool Generator](../chapter-06-gbdialog/keyword-use-tool.md) - Create custom weather integrations \ No newline at end of file diff --git a/docs/src/assets/api-comparison-matrix.svg b/docs/src/assets/api-comparison-matrix.svg deleted file mode 100644 index e4cbecfc..00000000 --- a/docs/src/assets/api-comparison-matrix.svg +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - API Migration Matrix - Enterprise Cloud APIs → General Bots Keywords - - - - - - Cloud Platform - - - - - - General Bots - - - - - MIGRATION PATH - - - - - - - - Email / Mail - Messages, Send, Folders - - SEND MAIL keyword - SEND MAIL TO email SUBJECT s BODY b - - READY - - - - - - - Calendar Events - Events, Scheduling, Free/Busy - - BOOK keyword + Calendar API - BOOK "Meeting" AT datetime - - READY - - - - - - - Cloud Storage / Files - Files, Versions, Sharing - - SeaweedFS + File Keywords - READ, WRITE, LIST, COPY, MOVE, DELETE - - READY - - - - - - - Tasks / Planning - Tasks, Lists, Assignments - - CREATE TASK + Projects - CREATE TASK "title" DUE date IN PROJECT id - - READY - - - - - - - Team Messaging - Chat, Channels, Messages - - TALK + Multi-Channel - Web, WhatsApp, Teams, Slack, Telegram - - READY - - - - - - - Users / Directory - Users, Groups, Permissions - - Zitadel IAM + Users API - OIDC/OAuth2 + SCIM provisioning - - READY - - - - - - - Workflow Automation - Flows, Triggers, Connectors - - BASIC Scripts + SET SCHEDULE - 90+ keywords, webhooks, cron, full logic - - BETTER - - - - - - - 100% - Feature Parity - - - - - 90+ - BASIC Keywords - - - - - $0 - Per-User Licensing - - - - - Self-Hosted - Full Data Sovereignty - - diff --git a/docs/src/assets/architecture-overview.svg b/docs/src/assets/architecture-overview.svg deleted file mode 100644 index 67b998de..00000000 --- a/docs/src/assets/architecture-overview.svg +++ /dev/null @@ -1,234 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - General Bots Architecture - Single binary • Zero dependencies • Production ready - - - - CHANNELS - - - - - W - Web Chat - WebSocket - - - - - WA - WhatsApp - Business API - - - - - T - Teams - Bot Framework - - - - - V - Voice - LiveKit - - - - - - - - - - - - - CORE RUNTIME - - - - - - BotServer (Rust) - - - - Session Manager - Tokio Async Runtime - - - - BASIC Interpreter - 90+ Keywords - - - - LLM Integration - OpenAI, Anthropic, Local - - - - Package Manager - .gbai, .gbkb, .gbdialog - - - - RAG Engine - Qdrant Vectors - - - - Tool Executor - Function Calling - - - - REST API - Axum Server - - - - PostgreSQL - SeaweedFS - Valkey - Zitadel - Stalwart - - - - - - - - - - - - OUTPUT - - - - - 💬 - Conversations - Text, Voice, Rich Media - - - - - - Automations - Webhooks, Schedules - - - - - 📊 - Data & Files - Drive, Mail, Calendar - - - - - - - - - Single Binary - - - - - Self-Hosted - - - - - Open Source - - - - - AI-First - - - - - No Forms - - - diff --git a/docs/src/assets/architecture.svg b/docs/src/assets/architecture.svg deleted file mode 100644 index 05358ed2..00000000 --- a/docs/src/assets/architecture.svg +++ /dev/null @@ -1,226 +0,0 @@ - - - - - - - - - - - - - - - - - - General Bots Architecture - Single binary with everything included - no external dependencies - - - Interface Layer - Core Runtime - Processing - - - - - - - Web Server - - - - Console UI - - - - BASIC Interpreter - - - - LLM Integration - - - - Package Manager - - - - BotModels (AI) - - - - Session Manager (Tokio Async Runtime) - - - - Channels - - - - External API - - - - - PostgreSQL - - - - Valkey Cache - - - - Qdrant Vectors - - - - SeaweedFS - - - - .gbkb (Docs) | .gbdialog (Scripts) | .gbot (Config) - Templates | User Assets - - - - Zitadel (IAM) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Request - Web/Console - - Process - BASIC + LLM - - Decide - AI Routing - - Execute - Tools + APIs - - Respond - Multi-Channel - - - - - Component Types: - - - Interface / Routing - - - Processing / Scripts - - - AI / ML / Decision - - - Execution / Storage - - - Output / Response - - - - - Rust-powered single binary serving web UI, BASIC scripting, LLM orchestration, and multi-channel messaging - - - Auto-installed infrastructure: PostgreSQL, Valkey, Qdrant, SeaweedFS, Zitadel - zero external dependencies - - diff --git a/docs/src/assets/architecture.svg.backup b/docs/src/assets/architecture.svg.backup deleted file mode 100644 index 6ef3e8dd..00000000 --- a/docs/src/assets/architecture.svg.backup +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - BotServer (Single Binary) - - - - - - Web Server - (Axum) - - - - BASIC - Interpreter - (Rhai) - - - - LLM - Integration - - - - - - - - - - - - Session Manager (Tokio) - - - - - - - - - - - - - PostgreSQL - Database - - - - Valkey - Cache - - - - Qdrant - Vectors - - - - - Object Storage (SeaweedFS/S3) - - - - - Documents - - - Templates - - - Assets - - diff --git a/docs/src/assets/botmodels-architecture.svg b/docs/src/assets/botmodels-architecture.svg deleted file mode 100644 index c6146a65..00000000 --- a/docs/src/assets/botmodels-architecture.svg +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - - - - - - - - - - BotServer ↔ BotModels Integration - Rust backend calling Python AI services over HTTPS - - - - - - botserver (Rust) - - - - BASIC Interpreter - - - LLM Integration - - - - BASIC Keywords - • IMAGE prompt - • VIDEO prompt - • AUDIO text - • SEE image - • HEAR AS AUDIO - - - - config.csv - botmodels-url, botmodels-enabled - - - - botmodels (Python) - - - - Image Service - Stable Diffusion - - - Video Service - Zeroscope - - - Speech Service - TTS / Whisper - - - Vision Service - BLIP2 / QRCode - - - - FastAPI Endpoints - /api/v1/image/generate - /api/v1/video/generate - /api/v1/speech/to-text - /api/v1/vision/describe - - - - - HTTPS - JSON / Binary - - - - outputs/ (Generated Files) - Images, Videos, Audio files served via /outputs - - - - - - - - - - - - - - - - - - - - - - - - BASIC Keyword - HTTP Request - AI Processing - Generate - Return URL - - - - - - Rust Backend - - - Python AI - - - Processing - - - Output - - - Config/API - - - - - BotModels runs as a separate Python service for GPU-accelerated AI inference - - - Enable with: botmodels-enabled=true and botmodels-url=http://localhost:8001 - - diff --git a/docs/src/assets/chapter-01/bootstrap-process.svg b/docs/src/assets/chapter-01/bootstrap-process.svg deleted file mode 100644 index 55bc897e..00000000 --- a/docs/src/assets/chapter-01/bootstrap-process.svg +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - - Auto-Bootstrap Process - - - - ./botserver - - - - - - - Detect System - (Linux/Mac) - - - - - - - Auto-Bootstrap Process - - - - - - PostgreSQL - 16.2 - ✓ Install - ✓ Configure - ✓ Migrate - - - - Valkey - Cache - ✓ Install - ✓ Configure - ✓ Start - - - - SeaweedFS - Storage - ✓ Install - ✓ Configure - ✓ Start - - - - Qdrant - Vectors - ✓ Install - ✓ Configure - ✓ Start - - - - - LLM Models (Optional) - ✓ Download BGE embeddings - ✓ Download Llama model (if local) - - - - - - - Generate .env file - • Secure passwords - • Connection URLs - • Port assignments - - - - - - - Load Templates - • Scan .gbai dirs - • Create bots - • Index documents - - - - - - - Start Web Server - localhost:8080 - diff --git a/docs/src/assets/chapter-01/quick-start-bootstrap-wide.svg b/docs/src/assets/chapter-01/quick-start-bootstrap-wide.svg deleted file mode 100644 index 4da3ee46..00000000 --- a/docs/src/assets/chapter-01/quick-start-bootstrap-wide.svg +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - Bootstrap Flow - - - - - - - ./botserver - - - - - - - - - OS Detection - - - - - - - - - Component Installation - - - - PostgreSQL - - - Valkey - - - SeaweedFS - - - Qdrant - - - - - - - - - - - - - - - - - Configuration & Setup - - - - - - - - - Bot Deployment - - - - Scan templates/ directory - - - - - - - Load .gbai packages - - - - - - - Start Web Server - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Start - Detect - Install & Configure - Deploy - - - - - Automatic bootstrap process: detect OS, install components, configure, and deploy - - - Zero configuration required - everything runs from a single binary - - - - - - - - - - diff --git a/docs/src/assets/chapter-01/quick-start-bootstrap.svg b/docs/src/assets/chapter-01/quick-start-bootstrap.svg deleted file mode 100644 index 4da3ee46..00000000 --- a/docs/src/assets/chapter-01/quick-start-bootstrap.svg +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - - - - - - - Bootstrap Flow - - - - - - - ./botserver - - - - - - - - - OS Detection - - - - - - - - - Component Installation - - - - PostgreSQL - - - Valkey - - - SeaweedFS - - - Qdrant - - - - - - - - - - - - - - - - - Configuration & Setup - - - - - - - - - Bot Deployment - - - - Scan templates/ directory - - - - - - - Load .gbai packages - - - - - - - Start Web Server - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Start - Detect - Install & Configure - Deploy - - - - - Automatic bootstrap process: detect OS, install components, configure, and deploy - - - Zero configuration required - everything runs from a single binary - - - - - - - - - - diff --git a/docs/src/assets/chapter-01/session-manager.svg b/docs/src/assets/chapter-01/session-manager.svg deleted file mode 100644 index 26e6bd3a..00000000 --- a/docs/src/assets/chapter-01/session-manager.svg +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - Session Manager Architecture - - - - User Input - - - - Bot Response - - - - - - - - WebSocket - /HTTP - - - WebSocket - /HTTP - - - - - - - - Session Manager - - - - 1. Validate Token - 2. Load Session - 3. Update State - - 4. Execute BASIC - 5. Generate Response - 6. Save History - - - - - - - - - Valkey - (Cache) - - - PostgreSQL - (Persist) - - - - Sync Every - Message - - - - - 1 - - - 2 - - - 3 - - - 4 - - - 5 - - - - - - Key Features - - - • Real-time WebSocket support - • Automatic session persistence - • Redis-compatible caching - • ACID compliance - - - diff --git a/docs/src/assets/chapter-01/session-states.svg b/docs/src/assets/chapter-01/session-states.svg deleted file mode 100644 index 96fdece8..00000000 --- a/docs/src/assets/chapter-01/session-states.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - Session State Flow - - - - Browser - Opens - - - - - - - CREATE - New UUID - Token Gen - - - - - - - ACTIVE - Chatting - Messages - - - - - - - IDLE - No Input - 30min Timer - - - - User Returns - - - - - - - EXPIRE - 7d Anon - Never Auth - - - - Retry - - - - - - - CLEANUP - Archive - Delete - - - - Instant - Active use - 30 minutes - 7 days / Never - Permanent - - diff --git a/docs/src/assets/chapter-01/tool-execution-flow.svg b/docs/src/assets/chapter-01/tool-execution-flow.svg deleted file mode 100644 index dd4b4224..00000000 --- a/docs/src/assets/chapter-01/tool-execution-flow.svg +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - Tool Execution Flow - - - - User: "I want to enroll in - Computer Science" - - - - - - - LLM Analyzes - "enrollment need" - Intent detection - - - - - - - Scan Available Tools - - - • enrollment.bas ✓ - • other-tools.bas - - - - - - - - Collect Parameters - - - • name: (ask user) - • email: (ask user) - • course: "Comp Sci" - - - - - - - - Execute enrollment.bas - - - • Save to CSV - • Return confirmation - - - - - - - - "Welcome to Computer Science!" - Confirmation sent to user - - - - - ~100ms - ~50ms - Interactive - ~200ms - Instant - - - Natural language - understanding - - Tool discovery - and matching - - Smart parameter - extraction - - BASIC script - execution - - - - - - enrollment.bas - - - ' Student enrollment tool - PARAM name, email, course - SAVE "enrollments.csv", name, email, course, NOW() - TALK "Welcome to " + course + ", " + name + "!" - - - diff --git a/docs/src/assets/chapter-02/package-structure.svg b/docs/src/assets/chapter-02/package-structure.svg deleted file mode 100644 index 2405ec44..00000000 --- a/docs/src/assets/chapter-02/package-structure.svg +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - Package Structure - - - - my-bot.gbai/ - (Package Root) - - - - - - - - - - - - - - - - - - - - .gbdialog - Dialog Scripts - Conversation Logic - - - - .gbkb - Knowledge Base - Documents - - - - .gbot - Configuration - Bot Settings - - - - .gbtheme - (optional) - UI Theme - - - - .gbdrive - (optional) - File Storage - - - - - - - - - - - - - - - - Scripts - .bas files - - - - Docs - PDF/TXT - - - - Config - .csv - - - - Styles - CSS/HTML - - - - Storage - S3 Link - - - - - Example Directory Structure: - - - botname.gbai/ - ├── botname.gbdialog/ - │ ├── start.bas - │ ├── auth.bas - │ └── tools/ - ├── botname.gbkb/ - │ ├── collection1/ - │ └── collection2/ - ├── botname.gbot/ - │ └── config.csv - └── botname.gbtheme/ - └── default.css - - - - - - - Key Points - - - • Folder name = Bot name - • Only .gbdialog is required - • start.bas is the entry point - • Deploy by copying folder - - - diff --git a/docs/src/assets/chapter-02/template-deployment-flow.svg b/docs/src/assets/chapter-02/template-deployment-flow.svg deleted file mode 100644 index a74a2f55..00000000 --- a/docs/src/assets/chapter-02/template-deployment-flow.svg +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - Template Deployment Flow - - - - templates/ - Source folder - - - - - - - SCAN - Find all .gbai folders - - - - - - - VALIDATE - Check required structure - • start.bas exists? - • Folders match name? - - - - - - - UPLOAD - Copy to object storage - • Templates → S3/Drive - • Assets → CDN paths - - - - - - - INDEX - Process knowledge base - • Extract text - • Generate embeddings - • Store in Qdrant - - - - - - - REGISTER - Create in database - • Bot record - • Configuration - • URL mapping - - - - - - - ACTIVATE - Start serving - • /bot-name endpoint - • WebSocket ready - • Sessions enabled - - - - - 5-10s - per bot - - diff --git a/docs/src/assets/chapter-03/caching-architecture.svg b/docs/src/assets/chapter-03/caching-architecture.svg deleted file mode 100644 index 80db903d..00000000 --- a/docs/src/assets/chapter-03/caching-architecture.svg +++ /dev/null @@ -1,173 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Semantic Caching Architecture - - - - - User Query - "What's the policy?" - - - - - - - Generate Key - Hash + Embed - - - - - - - Check Valkey - Memory Store - - - - - - - - Hit? - - - - - - - - Embedding Hash - 384D Vector - - - - - - - Semantic Search - Similarity > 0.95 - - - - - ✓ Cache Hit - - - - Miss - - - - Generate New - LLM Response - - - - - - - Store in Valkey - TTL: 3600s - - - - - Performance Metrics - - Hit Rate: ~85% - Latency: <50ms - Cost Reduction: 95% - diff --git a/docs/src/assets/chapter-03/context-window.svg b/docs/src/assets/chapter-03/context-window.svg deleted file mode 100644 index 6060dbda..00000000 --- a/docs/src/assets/chapter-03/context-window.svg +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Vector Database Storage Requirements: The Real Mathematics - - - - - - Original Documents - - - 1 TB Total - - - - - - PDF: 400 GB - - - - - DOCX: 250 GB - - - - - XLSX: 150 GB - - - - - TXT: 100 GB - - - - - HTML: 50 GB - - - - - Other: 50 GB - - - - - - Processing - - - - - - Vector DB Storage - - - ~3.5 TB Required - - - - - - Raw Text Extracted - - - ~800 GB (cleaned) - - - Deduplication reduces 20% - - - - - Vector Embeddings - - - ~1.2 TB (384-dim floats) - - - 4 bytes × 384 × ~800M chunks - - - = 1,228 GB - - - - - HNSW Index - - - ~600 GB - - - Graph structure + links - - - - - Metadata + Positions - - - ~400 GB - - - Doc refs, chunks, offsets - - - - - Cache + Auxiliary - - - ~500 GB - - - Query cache, temp indices - - - - - - Storage Multiplication Factor - - - - Original Documents: 1.0 TB - - - Vector DB Total: 3.5 TB - - - Multiplication Factor: 3.5× - - - - With redundancy/backup: - - - Production Total: 7.0 TB (2× replica) - - - - Reality: You need 3.5-7× your document storage - - - - - - Input - - - - - Storage - - - - - Factor - - diff --git a/docs/src/assets/chapter-03/kb-architecture-pipeline.svg b/docs/src/assets/chapter-03/kb-architecture-pipeline.svg deleted file mode 100644 index bd49456f..00000000 --- a/docs/src/assets/chapter-03/kb-architecture-pipeline.svg +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Knowledge Base Architecture Pipeline - - - - - - Document Ingestion Layer - - - PDF • Word • Excel • Text • HTML • Markdown - - - - - - - - - Preprocessing Pipeline - - - Extraction • Cleaning • Normalization • Validation - - - - - - - - - Intelligent Chunking Engine - - - Semantic Segmentation • Overlap Management • Metadata Preservation - - - - - - - - - Embedding Generation - - - BGE Models • Transformer Architecture • Dimensionality: 384/768 - - - - - - - - - Vector Index Layer - - - HNSW Algorithm • Quantization • Distributed Sharding - - - - - - - - - Semantic Retrieval Engine - - - Cosine Similarity • Hybrid Search • Re-ranking • Context Injection - - - - - - Data Flow Direction - - - - - Raw Docs - Clean Text - Chunks - Vectors - Index - Results - - - - - Pipeline processes ~1000 documents/minute • Query latency <50ms (p99) • 95% semantic accuracy - - diff --git a/docs/src/assets/chapter-03/search-pipeline.svg b/docs/src/assets/chapter-03/search-pipeline.svg deleted file mode 100644 index 85f380f2..00000000 --- a/docs/src/assets/chapter-03/search-pipeline.svg +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Semantic Search Pipeline - - - - - - - - - User Query - "What's the return - policy?" - - - - - - - - - Embedding - Transform to - 384D vector - - - - - - - - - Vector Search - Cosine similarity - in vector space - - - - - - - - - Re-ranking - Score & sort - by relevance - - - - - - Active Collections - policies • procedures • faq - - - - - - - - - Retrieved Context - 1. "Refund policy: 30 days..." (0.92) - 2. "Return procedures..." (0.87) - 3. "Warranty information..." (0.81) - - - - - - - - - Context Injection to LLM - Retrieved chunks provided as context for response generation - - - - - - - - - - Automatic - Process - - - - - - Search latency: ~20ms • Embedding: BGE-small (384D) • Similarity threshold: 0.7 • Top-K: 5 chunks - - diff --git a/docs/src/assets/chapter-03/storage-breakdown.svg b/docs/src/assets/chapter-03/storage-breakdown.svg deleted file mode 100644 index 6ab636f8..00000000 --- a/docs/src/assets/chapter-03/storage-breakdown.svg +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LLM Context Compression Strategies - - - - - - - - Original Context: 10,000 tokens - - - - - - - - - - - - - - - - - - Compression Level 4 - - - - - - - Compressed Context: 4,096 tokens (fits LLM window) - - - - - - - - - - - - - - - - Compression Techniques (Level 4) - - - - - - - Semantic Deduplication - - - • Remove redundant info - - - • Merge similar chunks - - - • Keep unique facts - - - - Reduction: 30-40% - - - - - - - - - - - - - - - Relevance Scoring - - - • Score by query match - - - • Keep top-k relevant - - - • Drop low scores - - - - Reduction: 40-50% - - - - - - - - - - - - - Hierarchical Summary - - - • Extract key points - - - • Create abstracts - - - • Preserve details - - - - Reduction: 50-60% - - - - - - - - - - - - - - - - - - - Token Optimization - - - • Remove stopwords - - - • Compress phrases - - - • Use abbreviations - - - - Reduction: 20-30% - - - - - ABCDEF → ABC - - - GHIJKL → GHI - - - - - - - - Compression Level 4 achieves 60-75% reduction while maintaining 95%+ information retention - - diff --git a/docs/src/assets/chapter-03/storage-multiplication.svg b/docs/src/assets/chapter-03/storage-multiplication.svg deleted file mode 100644 index 6622aba9..00000000 --- a/docs/src/assets/chapter-03/storage-multiplication.svg +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Storage Components per 1TB of Documents - - - - - - - - - - - - - - - - 0 GB - 250 GB - 500 GB - 750 GB - 1000 GB - - - - Storage Size (GB) - - - - - - 1000 - Original - 1000 GB - - - - 800 - Extracted - 800 GB - - - - 1200 - Embeddings - 1200 GB - - - - 600 - Index - 600 GB - - - - 400 - Metadata - 400 GB - - - - 500 - Cache - 500 GB - - - - - 3.5 TB Total - - - - Components contribute to 3.5× storage multiplication factor - - diff --git a/docs/src/assets/chapter-03/technical-specs.svg b/docs/src/assets/chapter-03/technical-specs.svg deleted file mode 100644 index 18cdb10f..00000000 --- a/docs/src/assets/chapter-03/technical-specs.svg +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - System Technical Specifications - - - - - - - - - - Embedding Configuration - - - - Model: bge-small-en-v1.5-f32.gguf - - - • Dimensions: 384 - - - • Format: GGUF (quantized) - - - • Server: localhost:8082 - - - • Memory: ~200MB loaded - - - - - - - - LLM Configuration - - - - Model: DeepSeek-R1-Distill-Qwen-1.5B - - - • Context Size: 4096 tokens - - - • Max Predict: 1024 tokens - - - • Parallel Requests: 6 - - - • Quantization: Q3_K_M - - - - - - - - Performance Characteristics - - - - - - Vector Index: HNSW Algorithm - - - • M=16, ef_construction=200 - - - • Distance: Cosine Similarity - - - • Build: ~1000 docs/minute - - - - - - - Chunking Strategy - - - • Chunk Size: 512 tokens - - - • Overlap: 50 tokens - - - • Prompt Compact: Level 4 - - - - - - - Runtime Metrics - - - • Query Latency: <50ms p99 - - - • Memory: ~1GB/million chunks - - - • Cache TTL: 3600 seconds - - - - - - - - - - - diff --git a/docs/src/assets/chapter-04/analytics-interface.svg b/docs/src/assets/chapter-04/analytics-interface.svg deleted file mode 100644 index b6186eb2..00000000 --- a/docs/src/assets/chapter-04/analytics-interface.svg +++ /dev/null @@ -1,195 +0,0 @@ - - - - - Analytics - Dashboard Interface - - - - - - - - - - 📊 Analytics Dashboard - - - - - Last 24h ▼ - - - - - - ⟳ Refresh - - - - - - - - - - 1,234 - Messages - ↑ +12% - - - - 89% - Success Rate - ↑ +3% - - - - 2.3s - Avg Response - ↓ -0.2s - - - - 45 - Users Today - ↑ +8 - - - - - - - Messages Over Time - - - - - - - - - - - - - - - - - - - - - - - Mon - Tue - Wed - Thu - Fri - - - - - Top Questions - - - - 1. How do I reset... - - - - 2. What is the status... - - - - 3. Where can I find... - - - - 4. Help with login - - - - - - - - - 📈 Peak Hour: - 2:00 PM - - - - 🔝 Top Intent: - Support Query - - - - ⚡ Avg Session: - 4.2 min - - - - 🎯 Resolution: - 94% - - - - Export - - - - - Metrics: Real-time KPIs - Charts: Trends & Distribution - Time Range: Last 24h, 7d, 30d, Custom - Shortcuts: R = Refresh | E = Export - - diff --git a/docs/src/assets/chapter-04/calendar-interface.svg b/docs/src/assets/chapter-04/calendar-interface.svg deleted file mode 100644 index 7e2664fb..00000000 --- a/docs/src/assets/chapter-04/calendar-interface.svg +++ /dev/null @@ -1,211 +0,0 @@ - - - - - Calendar - Scheduling Interface - - - - - - - - - - - - - - - - - - - March 2024 - - - - - - Day - - - Week - - - Month - - - - - - - - - - Mon - Tue - Wed - Thu - Fri - Sat - Sun - - - - - - - - - - 1 - - 2 - - 3 - - - - - - - 4 - - - 5 - - - Team Meeting - - - 6 - - - 7 - - - 8 - - - 9 - - - 10 - - - - - - 11 - - - 12 - - - 13 - - - Project Review - - - 14 - - - 1:1 Meeting - - - - - 15 - - - 16 - - - 17 - - - - - - 18 - - - 19 - - - 20 - - - 21 - - - 22 - - - 23 - - - 24 - - - - - - - + - - - - - - Today - - - Event - - - Weekend - - Shortcuts: N = New event | T = Today | ← → = Navigate | D/W/M = View - - diff --git a/docs/src/assets/chapter-04/compliance-interface.svg b/docs/src/assets/chapter-04/compliance-interface.svg deleted file mode 100644 index 2fa4d89b..00000000 --- a/docs/src/assets/chapter-04/compliance-interface.svg +++ /dev/null @@ -1,200 +0,0 @@ - - - - - Compliance - Security Scanner Interface - - - - - - - - - - 🛡 Compliance Scanner - - - - - Scan - - - Export - - - - - - - - - - - 2 - Critical - 🔴 Immediate - - - - - 5 - High - 🟠 Priority - - - - - 3 - Medium - 🟡 Review - - - - - 1 - Low - 🟢 Minor - - - - - 0 - Info - ℹ Notes - - - - - - - - - - Severity - Issue - File - Action - - - - - Critical - Hardcoded password detected - start.bas:15 - - Fix - - - - - Critical - API key exposed in code - api.bas:42 - - Fix - - - - - High - SQL injection risk in query - data.bas:28 - - Review - - - - - High - Insecure HTTP endpoint - config.csv:8 - - Review - - - - - Medium - Missing input validation - form.bas:55 - - Review - - - - - Last scan: 2 minutes ago - Files scanned: 24 - Total issues: 11 - - - Showing 1-5 of 11 - - - - - - - - - - Critical - - - High - - - Medium - - - Low - - Fix = Auto-remediate | Review = Manual inspection needed - - LGPD • GDPR • CCPA - - diff --git a/docs/src/assets/chapter-04/designer-interface.svg b/docs/src/assets/chapter-04/designer-interface.svg deleted file mode 100644 index e4218f5d..00000000 --- a/docs/src/assets/chapter-04/designer-interface.svg +++ /dev/null @@ -1,258 +0,0 @@ - - - - - - - - - - - Designer - Visual Builder Interface - - - - - - - - - - - - Toolbox - - - - - - 💬 - TALK - - - - 👂 - HEAR - - - - 📝 - SET - - - - - - - 🔀 - IF - - - - 🔄 - FOR - - - - 🔃 - SWITCH - - - - - - - 📞 - CALL - - - - 📧 - SEND - - - - 💾 - SAVE - - - - - - - - - - - - - - - - - - - - - - - 💬 TALK - "Hello!" - - - - - - - 👂 HEAR - name - - - - - - - 🔀 IF - name = "Jo" - - - Yes - No - - - - - - - - - - 💬 TALK - "Hi Jo!" - - - - 💬 TALK - "Hello!" - - - - - - - - - - Properties - - - - Node: - TALK - - - - Message: - - "Hello!" - - - - Voice: - - Default ▼ - - Delay: - - 0ms - - - - - - Apply - - - Delete - - - - - - + - - - - - - - - 100% - - - ▶ Run - - - - - - Talk - - - Hear - - - Condition - - Drag nodes from Toolbox → Canvas | Connect by dragging - - Shortcuts: Delete | Ctrl+D = Duplicate | Ctrl+Z = Undo - - diff --git a/docs/src/assets/chapter-04/drive-interface.svg b/docs/src/assets/chapter-04/drive-interface.svg deleted file mode 100644 index 1343a497..00000000 --- a/docs/src/assets/chapter-04/drive-interface.svg +++ /dev/null @@ -1,155 +0,0 @@ - - - - - Drive - File Management Interface - - - - - - - - - - - + New ▼ - - - - 🔍 Search files... - - - - - - - - - - - - - - - - - - - - 📁 My Drive - - ⭐ Starred - 🕐 Recent - 🗑 Trash - - - - Labels - - Work - - Personal - - - - 📁 My Drive › Projects › 2024 - - - - - - Name - Size - Modified - - - - - - - - 📁 - Reports - - Today - - - - - 📁 - Presentations - - Yesterday - - - - - 📄 - Budget.xlsx - 245 KB - Mar 15 - - - - - 📄 - Notes.docx - 12 KB - Mar 14 - - - - - 🖼 - Logo.png - 89 KB - Mar 10 - - - - - 📤 Drag files here to upload - or click + New to create - - - - Sidebar: Quick access, Labels - Main: File browser with sort columns - Actions: Upload, Create, Search, View toggle - - diff --git a/docs/src/assets/chapter-04/mail-interface.svg b/docs/src/assets/chapter-04/mail-interface.svg deleted file mode 100644 index 058afd65..00000000 --- a/docs/src/assets/chapter-04/mail-interface.svg +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Mail - Email Client Interface - - - - - - - - - - - ✏ Compose - - - - - - 📥 Inbox - - 3 - - 📤 Sent - 📝 Drafts - 🗑 Trash - - - - - - - - - Inbox - - - - - - - Project Update - from John - 10:30 AM - - - - - - Meeting Notes - from Sarah - Yesterday - - - - - - Invoice #1234 - from Vendor - Mar 15 - - - - - - - - - From: - john@company.com - - Subject: - Project Update - - - - - - - - Hi, - Here's the latest update on our project. - We've completed the first milestone and - are now moving to phase two. - Best, - John - - - - - - Reply - - - Forward - - - Delete - - - - - Sidebar: Folders - List: Email threads - Content: Read and reply - Shortcuts: C = Compose | R = Reply | F = Forward - - diff --git a/docs/src/assets/chapter-04/meet-interface.svg b/docs/src/assets/chapter-04/meet-interface.svg deleted file mode 100644 index ddb39433..00000000 --- a/docs/src/assets/chapter-04/meet-interface.svg +++ /dev/null @@ -1,139 +0,0 @@ - - - - - Meet - Video Calls Interface - - - - - - - - - - Meeting Room - - - 00:15:32 - - - - - - 👥 - 3 - - - - 💬 - - - - - - - - - - - 👤 - You - (Camera) - - - You - - - 🎤 - - - - - 👤 - John - (Camera) - - - John - - - - - 👤 - Sarah - - - Sarah - - - - - - - - - - - 🎤 - - - - 📹 - - - - 🖥 - - - - 🔴 - - - - 📝 - - - - 📞 - - - - - - Active - - - Muted/End - - - Available - - Shortcuts: M = Mute | V = Video | S = Share | Space = Push-to-talk - - diff --git a/docs/src/assets/chapter-04/paper-interface.svg b/docs/src/assets/chapter-04/paper-interface.svg deleted file mode 100644 index 9b89485c..00000000 --- a/docs/src/assets/chapter-04/paper-interface.svg +++ /dev/null @@ -1,179 +0,0 @@ - - - - - Paper - AI Writing Interface - - - - - - - - - - 📄 Notes - - - - - - - Meeting Notes - - Project Plan - Ideas - - - - Quick Start - 📄 Blank - 📋 Meeting - ✓ To-Do - 🔬 Research - - - - - - - - - - - - - - B - - - - I - - - - U - - - - - - - H1 - - - - H2 - - - - - - - - - - - - - - - 🔗 - - - - 📷 - - - - AI ✨ - - - - - - - - - Project Proposal - - - - Introduction - - - - This document outlines our proposal for - the upcoming project. We aim to deliver - a comprehensive solution that addresses - all stakeholder requirements. - - - - - - Key Objectives - • Improve efficiency by 30% - • Reduce costs through automation - • Enhance user experience - - - - - Words: 156 - Characters: 892 - Reading time: 1 min - ✓ Auto-saved 2 min ago - - - - - - AI Assist - - Shortcuts: Ctrl+B = Bold | Ctrl+I = Italic | Ctrl+S = Save | Ctrl+/ = AI - - Markdown supported - - diff --git a/docs/src/assets/chapter-04/research-interface.svg b/docs/src/assets/chapter-04/research-interface.svg deleted file mode 100644 index c69854c3..00000000 --- a/docs/src/assets/chapter-04/research-interface.svg +++ /dev/null @@ -1,168 +0,0 @@ - - - - - Research - AI Search Interface - - - - - - - - - - 🔍 Research - - - - - Focus: - - - - 🌐 All - - 📚 Academic - 💻 Code - 🏠 Internal - - - - - Collections: - 📁 - Project A - 📁 - References - - - - - Recent: - • market size - • competitors - • best practices - - - - - - - - - What are the best practices for... - - - - - - - - - - AI Answer: - - - - Based on multiple sources, here are the key best practices: - - 1. Start with clear requirements and objectives - 2. Use iterative development with frequent feedback - 3. Test early and often with real users - 4. Document decisions and maintain knowledge base - - - - - Sources: - - - - [1] - industry-guide.com - Best practices for software - development in 2024... - - - [2] - techblog.dev - Modern development - methodology overview... - - - [3] - your-docs/guidelines.pdf - 📄 Internal document - Company guidelines... - - - - - - 📁 Save - - - 📤 Share - - - 🔄 Deep Dive - - - 📋 Copy - - - - - - AI Summary - - - Sources - - Focus: Web • Academic • Code • Internal docs - - Enter = Search | Ctrl+S = Save - - diff --git a/docs/src/assets/chapter-04/sources-interface.svg b/docs/src/assets/chapter-04/sources-interface.svg deleted file mode 100644 index 099f9400..00000000 --- a/docs/src/assets/chapter-04/sources-interface.svg +++ /dev/null @@ -1,206 +0,0 @@ - - - - - Sources - Prompts & Templates Interface - - - - - - - - - - Sources - - - - - 🔍 Search... - - - - - - - - - Prompts - - - Templates - - - MCP Servers - - - LLM Tools - - - Models - - - - - - - - - - - - Categories - - - - - 📝 Writing - - 📊 Analysis - 💼 Business - 💻 Code - 🎨 Creative - 🤖 Automation - 📞 Support - - - - - - ⭐ Featured - - - - Customer - Service - - Handle support - inquiries with AI - assistance - - - Use - - - - - - Sales - Assistant - - Qualify leads and - schedule meetings - automatically - - - Use - - - - - - Code - Helper - - Generate and - explain code - snippets - - - Use - - - All Prompts - - - - Meeting Notes - Summarize meetings - - Writing - - Use - - - Data Analyst - Analyze datasets - - Analysis - - Use - - - Email Writer - Draft pro emails - - Business - - Use - - - Story Writer - Creative stories - - Creative - - Use - - - - - Page 1 of 5 - - - - - - - - - Tabs: Prompts, Templates, MCP Servers, LLM Tools, Models - Categories filter content - Click Use to apply prompt/template - - diff --git a/docs/src/assets/chapter-04/suite-main-layout.svg b/docs/src/assets/chapter-04/suite-main-layout.svg deleted file mode 100644 index f0368f61..00000000 --- a/docs/src/assets/chapter-04/suite-main-layout.svg +++ /dev/null @@ -1,82 +0,0 @@ - - - - - Suite - Main Layout - - - - - - - - - - - 🤖 - General Bots - - - - - - ⋮⋮⋮ - - - - 🌙 - - - - U - - - - - - - - - - 💬 - Chat - (Main Area) - - - - Type your message here... - - - - Send - - - - Header: Navigation, Apps Menu, Theme, Profile - Main: AI Chat Interface with Message Input - - diff --git a/docs/src/assets/chapter-04/tasks-interface.svg b/docs/src/assets/chapter-04/tasks-interface.svg deleted file mode 100644 index f3f91c2a..00000000 --- a/docs/src/assets/chapter-04/tasks-interface.svg +++ /dev/null @@ -1,151 +0,0 @@ - - - - - Tasks - To-Do Management Interface - - - - - - - - - - ✓ Tasks - - Total: - 12 - Active: - 5 - Done: - 7 - - - - - - - - - What needs to be done? - - - - Category ▼ - - - - + Add - - - - - - - - - 📋 All (12) - - - ⏳ Active (5) - - - ✓ Completed (7) - - - ⚡ Priority - - - - - - - - - - - Review quarterly report - 📅 Today - - - - - - Call client about proposal - 📅 Today - - - - - - Update project documentation - 📅 Tomorrow - - - - - - - Send meeting notes - ✓ Done - - - - - - Complete expense report - ✓ Done - - - - - Priority: - - High - - Medium - - Low - - Shortcuts: Enter = Add | Space = Toggle | Delete = Remove - - diff --git a/docs/src/assets/chapter-06/basic-execution-flow.svg b/docs/src/assets/chapter-06/basic-execution-flow.svg deleted file mode 100644 index ff3435cd..00000000 --- a/docs/src/assets/chapter-06/basic-execution-flow.svg +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BASIC LLM Tool Execution Flow - - - - - USER - "What's the policy?" - - - - - - - LLM + CONTEXT - Understands intent + loaded KBs - - - - - - - - - Tool? - - - - - - - - Direct Answer - - - - - - Call Tool - - - - BASIC TOOL - enrollment.bas - PARAM name, course - - - - - - - RESPONSE - Generate natural answer - - - - - - - BOT - "30-day return..." - - - - MEMORY STORE - BOT_MEMORY • Session State • Context - - - - - - - - - LLM decides tool calls • Zero IF/THEN logic • Natural conversation flow • Context-aware responses - - - - - Legend: - - Direct response - - Tool invocation - - diff --git a/docs/src/assets/chapter-07/data-flow.svg b/docs/src/assets/chapter-07/data-flow.svg deleted file mode 100644 index afb9212d..00000000 --- a/docs/src/assets/chapter-07/data-flow.svg +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - BotServer Data Flow Architecture - - - - - User Input Layer - - - - Web UI - - - WhatsApp - - - Teams - - - Email - - - API - - - - - - - - - Core Processing Engine - - - - Session Manager - User Context - - - - BASIC Interpreter - Script Execution - - - - LLM Integration - AI Processing - - - - Knowledge Base - Vector Search - - - - - - - - - Tool System - External APIs & Functions - - - - Cache Layer - Response Optimization - - - - - - - - - Storage & Persistence Layer - - - - Database - User Data - - - - Vector DB - Embeddings - - - - Drive Storage - Files & Assets - - - - Cache - Fast Access - - - - - - - - - - - - - - Data Flow: - - Request/Response - - - Data Access - - - - All components run in async Rust for maximum performance - diff --git a/docs/src/assets/chapter-07/data-traceability.svg b/docs/src/assets/chapter-07/data-traceability.svg deleted file mode 100644 index 27fb7185..00000000 --- a/docs/src/assets/chapter-07/data-traceability.svg +++ /dev/null @@ -1,306 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Data Traceability Diagram - General Bots Architecture - - - - - - Legend - - - User Input Flow - - - LLM Processing - - - Storage Operations - - - Internal Flow - - - - - - CHANNELS - - - - 📱 WhatsApp - - - - ✈️ Telegram - - - - 🌐 Web UI / gbui - - - - 🔌 REST API - - - - 🪝 Webhooks - - - - - - BOTSERVER CORE - - - - BASIC Interpreter - .bas scripts → Rhai engine - - - - Message Router - TALK / HEAR / SEND - - - - Scheduler - SET SCHEDULE "every hour" - - - - Keywords Engine - GET/POST/FIND/SAVE/LLM - - - - Session Manager - user_id → bot_id → org_id - - - - - - LLM PROVIDERS - - - 🧠 Claude Opus 4 - - - 🤖 GPT-4 Turbo - - - 💎 Gemini Pro - - - 🦙 Local: Llama/Mistral - - - - - - STORAGE (MinIO) - - - 📁 /{org}/{botname}/ - Bucket per bot - - - .gbdialog - - - .gbkb - - - .gbot - - - .gbtheme - - - uploads/ | exports/ | cache/ - - - - - - DATABASE - - - 🐘 PostgreSQL - Main database - - - organizations - - - bots - - - users / sessions - - - conversations - - - system_automations - - - 🔴 Redis (cache/queue) - - - - - - - - - - LLM - - - - - - - FILES - - - - FIND/SAVE - - - - - - - - Key Data Flows - - - - - 1. User Message Flow - Channel → Router → Session - → BASIC Script → LLM (if needed) - → Response → Channel - Key: {org}_{bot}_{user}_{session} - - - - - - 2. Scheduled Task Flow - Cron Trigger → Load Script - → Execute Keywords → External APIs - → Save Results → Log - Key: {org}_{bot}_schedule_{name} - - - - - - 3. File Operations Flow - UPLOAD/DOWNLOAD → MinIO - Bucket: /{org}/{botname}/ - → Metadata → PostgreSQL - Path: s3://{org}/{bot}/{path} - - - - - - 4. Knowledge Base Flow - USE KB "docs" → Load .gbkb - → Embed → Vector DB (pgvector) - → Semantic Search → LLM Context - Key: {org}_{bot}_kb_{name} - - - - - - 5. Webhook Flow - External POST → /webhook/{id} - → Validate → Trigger Script - → Process → Response/Notify - Key: {org}_{bot}_webhook_{path} - - - - - - 6. Bot Memory Flow - SET/GET BOT MEMORY → Redis - → Persist → PostgreSQL (backup) - → Scope: global | user | session - Key: {org}_{bot}_mem_{scope}_{key} - - - - - - General Bots Data Traceability - All keys follow pattern: {org}_{botname}_{resource}_{identifier} - - diff --git a/docs/src/assets/chapter-07/module-data-flow.svg b/docs/src/assets/chapter-07/module-data-flow.svg deleted file mode 100644 index 60f47ab5..00000000 --- a/docs/src/assets/chapter-07/module-data-flow.svg +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Data Flow Through Modules - - - - User Input - - - - - - - web_server/ | channels/ - Axum HTTP Server - Route to channel - - - - - - - session/ - Load/Create Session - Validate Token - - - - - - - auth/ - Check Permissions - Apply RBAC - - - - - - - bot/ - Route to Bot Instance - Load Configuration - - - - - - - basic/ - Execute BASIC Script - Parse Keywords - - - - - - - - - - - context/ - Load KB - - - - drive/ - Get Files - - - - database/ - Query DB - - - - llm/ - Call AI - - - - - - - - - - - - - Bot Response - - - - - 1. Input Reception - 2. HTTP Routing - 3. Session Management - 4. Authorization - 5. Bot Routing - 6. Script Execution - 7. Data Processing - 8. Response Generation - - - - All operations are async with Tokio runtime for maximum throughput - diff --git a/docs/src/assets/chapter-07/module-dependency.svg b/docs/src/assets/chapter-07/module-dependency.svg deleted file mode 100644 index e12d67f1..00000000 --- a/docs/src/assets/chapter-07/module-dependency.svg +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - Module Dependency Graph - - - - main.rs - - - - - - - bootstrap/ - - - - - - - - - - package_manager/ - - - - config/ - - - - database/ - - - - - - - - session/ - - - - web_server/ - - - - - - - - - - - - - - - - - channels/ - - - - bot/ - - - - basic/ - - - - auth/ - - - - - - - - - - llm/ - - - - - - - context/ - - - - Layers: - - - Entry Point - - - Core System - - - Services - - - Features - - - - Arrows indicate compile-time dependencies - diff --git a/docs/src/assets/chapter-07/system-architecture.svg b/docs/src/assets/chapter-07/system-architecture.svg deleted file mode 100644 index ed3567fc..00000000 --- a/docs/src/assets/chapter-07/system-architecture.svg +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - BotServer Architecture - Virtual Crates System - - - - - - - BotServer Binary - - - - compiles to - - - - - Core Engine (src/core/) - - - - Bootstrap - System Init - Service Start - - - Package Manager - Component Registry - Module Loader - - - Session Manager - Context Handling - State Management - - - Shared State - AppState - Configuration - - - Utils - Helpers - Common - - - - - - - - - - Virtual Crates (gbapp modules in src/) - - - - basic.gbapp - src/basic/ - - • BASIC Interpreter - • Keywords Registry - • Script Execution - • Rhai Engine - - - - channels.gbapp - src/channels/ - - • WhatsApp - • Teams - • Email - • Web UI - - - - storage.gbapp - src/storage/ - - • Knowledge Base - • Drive Integration - • Vector DB - • Cache - - - - your_feature.gbapp - src/your_feature/ - - • Your Keywords - • Your Services - • Your Models - + Add yours! - - - - - - - - - AI & LLM Integration - - - LLM Service - - - Embeddings - - - Semantic Search - - - - - - Persistence Layer - - - Database - - - Vector DB - - - Drive - - - Cache - - - - - Key Concepts: - - - Virtual Crates = Modules in src/ - - - Your Contribution Space - - All compile to single optimized binary - - - - gbapp virtual crates: The bridge between old Node.js packages and new Rust modules - diff --git a/docs/src/assets/chapter-10/api-architecture.svg b/docs/src/assets/chapter-10/api-architecture.svg deleted file mode 100644 index 7a447974..00000000 --- a/docs/src/assets/chapter-10/api-architecture.svg +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BotServer API Architecture - - - - - - Client Applications - - - - - - - - - HTTP/HTTPS - - - Port 8080 - - - - - - - - - API Gateway - - - /api/* - - - - - - - - - - - Auth Endpoints - - - /auth/login - - - /auth/logout - - - /auth/token - - - - - - Business Endpoints - - - /files/* • /users/* - - - /groups/* • /tasks/* - - - /sessions/* - - - - - - Admin Endpoints - - - /admin/* - - - /monitoring - - - /analytics - - - - - - - - - - - Service Layer - - - • Session Manager - - - • Auth Service • Bot Service - - - - - - - - - - - PostgreSQL - - - Database - - - Sessions • Users • Config - - - - - - Valkey - - - Cache - - - Semantic • Session • Temp - - - - - - Qdrant - - - Vectors - - - Embeddings • Search - - diff --git a/docs/src/assets/chapter-10/api-request-flow.svg b/docs/src/assets/chapter-10/api-request-flow.svg deleted file mode 100644 index 17f53718..00000000 --- a/docs/src/assets/chapter-10/api-request-flow.svg +++ /dev/null @@ -1,224 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - API Request Flow - - - - - - HTTP Request - - - Client → Server - - - - - - - - - Rate Limit - - - Check request limits - - - - - Pass - - - 429 Too Many - - - - - Auth - - - Validate token/session - - - - - Valid - - - 401 Unauthorized - - - - - Route - - - Match endpoint pattern - - - - - - - 404 Not Found - - - - - Validate - - - Check request body - - - - - Valid - - - 400 Bad Request - - - - - Process - - - Execute business logic - - - - - - - - - Format - - - JSON response - - - - - - - - - HTTP Response - - - Server → Client - - - - - - Error Response - - - - - - Request Pipeline - - - - - - - Success path - - - - - Error path - - diff --git a/docs/src/assets/conversation-flow.svg b/docs/src/assets/conversation-flow.svg deleted file mode 100644 index dc4f518a..00000000 --- a/docs/src/assets/conversation-flow.svg +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - - - - - - - - - - - Conversation Flow - How General Bots processes user messages through the AI pipeline - - - - - Input - Script - AI Decision - Execution - Response - - - - - User Input - Web / WhatsApp / Teams - - - - BASIC Script - start.bas / tools - - - - LLM Decision - Intent / Tool Selection - - - - Bot Executor - Run Keywords - - - - Bot Response - TALK / Send - - - Parallel Operations - - - - Vector Search - Qdrant / USE KB - - - - External APIs - GET / POST / GraphQL - - - - Database - TABLE / SAVE - - - - Knowledge Base - .gbkb Documents - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Receive - Parse - Decide - Execute - Respond - - - - - Legend: - - - Main Flow - - - Parallel / Optional - - - Feedback Loop - - - - - The AI handles everything automatically - understanding intent, searching knowledge, - - - executing tools, and generating responses. Zero configuration required. - - - - - - Multi-Channel - - - BASIC Scripting - - - LLM Powered - - - Tool Execution - - - RAG Search - - - Real-time - - diff --git a/docs/src/assets/conversation-flow.svg.backup b/docs/src/assets/conversation-flow.svg.backup deleted file mode 100644 index 676e74e4..00000000 --- a/docs/src/assets/conversation-flow.svg.backup +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - User Input - - - - BASIC Script - - - - LLM Decision - - - - Tool Execution - - - - Save to CSV - - - - Search Knowledge - - - - Bot Response - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/directory-tree.svg b/docs/src/assets/directory-tree.svg deleted file mode 100644 index c2c5b856..00000000 --- a/docs/src/assets/directory-tree.svg +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BAS - - - - - - - - - - - mybot.gbai - - - - - - - - - - - mybot.gbdialog - - - - - - - - - - - start.bas - - - - - - - - auth.bas - - - - - - - - mybot.gbkb - - - - - - - - - - - faq.docx - - - - - - - - mybot.gbot - - - - - - - - - - - config.csv - - diff --git a/docs/src/assets/feature-parity-flow.svg b/docs/src/assets/feature-parity-flow.svg deleted file mode 100644 index e6e67f1e..00000000 --- a/docs/src/assets/feature-parity-flow.svg +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Feature Parity Flow - From Enterprise Cloud Services to Self-Hosted Freedom - - - - - - - Enterprise Cloud - - - - - - Exchange Online - Mail, Calendar, Contacts - - - - - - OneDrive / SharePoint - Files, Versioning, Sharing - - - - - - Teams - Chat, Video, Collaboration - - - - - - Power Automate - Workflows, Triggers - - - - - - Copilot - AI Assistant ($30/user) - - - - - - Azure AD / Entra - Identity, Auth, SSO - - - - - - - - - - - MIGRATE - 100% Parity - - - - - - - - - - - - - - - - - - - - - - General Bots - - - - - - Stalwart Mail - IMAP/SMTP/JMAP + CalDAV - - - - - - SeaweedFS Drive - S3-compatible + Versioning - - - - - - LiveKit Meet - WebRTC + Multi-channel - - - - - - BASIC Scripts - 90+ Keywords + Cron - - - - - - LLM Integration - Any Provider (Free) - - - - - - Zitadel IAM - OIDC/OAuth2 + MFA - - - - - - - - - - - - - Self-Hosted - Full Data Control - - - - - - - $0 - No Per-User Fee - Unlimited Users - - - - - - - AI - Native LLM - Built-in RAG + Tools - - - - - - - OSS - Open Source - AGPL Licensed - - - - - - 90+ - Keywords - - - diff --git a/docs/src/assets/gb-decorative-header.svg b/docs/src/assets/gb-decorative-header.svg deleted file mode 100644 index 54088303..00000000 --- a/docs/src/assets/gb-decorative-header.svg +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-bot.svg b/docs/src/assets/icons/gb-bot.svg deleted file mode 100644 index 48f13140..00000000 --- a/docs/src/assets/icons/gb-bot.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-chart.svg b/docs/src/assets/icons/gb-chart.svg deleted file mode 100644 index b728ec5f..00000000 --- a/docs/src/assets/icons/gb-chart.svg +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-check.svg b/docs/src/assets/icons/gb-check.svg deleted file mode 100644 index e2129bae..00000000 --- a/docs/src/assets/icons/gb-check.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-database.svg b/docs/src/assets/icons/gb-database.svg deleted file mode 100644 index 1b19c5ca..00000000 --- a/docs/src/assets/icons/gb-database.svg +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-folder.svg b/docs/src/assets/icons/gb-folder.svg deleted file mode 100644 index 4b7e5cc9..00000000 --- a/docs/src/assets/icons/gb-folder.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-gear.svg b/docs/src/assets/icons/gb-gear.svg deleted file mode 100644 index 5cb00531..00000000 --- a/docs/src/assets/icons/gb-gear.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/docs/src/assets/icons/gb-globe.svg b/docs/src/assets/icons/gb-globe.svg deleted file mode 100644 index 5cbdbbee..00000000 --- a/docs/src/assets/icons/gb-globe.svg +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-lightbulb.svg b/docs/src/assets/icons/gb-lightbulb.svg deleted file mode 100644 index 502386d6..00000000 --- a/docs/src/assets/icons/gb-lightbulb.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-lock.svg b/docs/src/assets/icons/gb-lock.svg deleted file mode 100644 index a4caab7f..00000000 --- a/docs/src/assets/icons/gb-lock.svg +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-note.svg b/docs/src/assets/icons/gb-note.svg deleted file mode 100644 index 891da20a..00000000 --- a/docs/src/assets/icons/gb-note.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-package.svg b/docs/src/assets/icons/gb-package.svg deleted file mode 100644 index dd0c32b8..00000000 --- a/docs/src/assets/icons/gb-package.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-palette.svg b/docs/src/assets/icons/gb-palette.svg deleted file mode 100644 index 1aa99cc4..00000000 --- a/docs/src/assets/icons/gb-palette.svg +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-rocket.svg b/docs/src/assets/icons/gb-rocket.svg deleted file mode 100644 index b67bb4f1..00000000 --- a/docs/src/assets/icons/gb-rocket.svg +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-search.svg b/docs/src/assets/icons/gb-search.svg deleted file mode 100644 index b66c3a86..00000000 --- a/docs/src/assets/icons/gb-search.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-signal.svg b/docs/src/assets/icons/gb-signal.svg deleted file mode 100644 index 3853530e..00000000 --- a/docs/src/assets/icons/gb-signal.svg +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-target.svg b/docs/src/assets/icons/gb-target.svg deleted file mode 100644 index fd87c8cc..00000000 --- a/docs/src/assets/icons/gb-target.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-tree.svg b/docs/src/assets/icons/gb-tree.svg deleted file mode 100644 index 299c49d9..00000000 --- a/docs/src/assets/icons/gb-tree.svg +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/icons/gb-warning.svg b/docs/src/assets/icons/gb-warning.svg deleted file mode 100644 index b04cd922..00000000 --- a/docs/src/assets/icons/gb-warning.svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/src/assets/infrastructure-architecture.svg b/docs/src/assets/infrastructure-architecture.svg deleted file mode 100644 index 19084506..00000000 --- a/docs/src/assets/infrastructure-architecture.svg +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - - - - - - - - - - Infrastructure Architecture - Load Balancing, Multi-Tenant Isolation, and Auto-Scaling - - - - - Clients - - - - Web - - - Mobile - - - WhatsApp - - - Teams - - - API - - - - Load Balancer (Caddy) - TLS Termination | Rate Limiting | Health Checks - - - - - - - - - - - - BotServer Instances (Auto-Scaled) - - - BotServer 1 - LXC Container - - - BotServer 2 - LXC Container - - - BotServer 3 - LXC Container - - - BotServer N - Auto-Scale - - - - - - - - - - - Shared Data Layer - - - - PostgreSQL - Relational Data - - - Valkey - Cache + Sessions - - - Qdrant - Vector Search - - - SeaweedFS - Object Storage - - - Zitadel - IAM / Auth - - - LiveKit - Real-time Meet - - - Stalwart - Email Server - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Request - Multi-Channel - - Route - Load Balance - - Process - BotServer - - Store - Data Layer - - - - - Component Types: - - - Client / Interface - - - Load Balancer - - - Compute Instance - - - Data Storage - - - Services - - - - - - Auto-Scaling - - - TLS Everywhere - - - Multi-Tenant - - - Health Checks - - - Zero Downtime - - - LXC Containers - - - - - Production-ready infrastructure with automatic scaling, load balancing, and multi-tenant isolation - - diff --git a/docs/src/assets/migration-architecture.svg b/docs/src/assets/migration-architecture.svg deleted file mode 100644 index cfe67b77..00000000 --- a/docs/src/assets/migration-architecture.svg +++ /dev/null @@ -1,366 +0,0 @@ - - - - - - - - - - - - - - - - - Enterprise Migration Architecture - - - Current State - Migration Process - Target State - - - - - - Big Tech Cloud - - - - M365/Google - - - - OneDrive/ - Google Drive - - - Outlook/ - Gmail - - - Teams/ - Meet - - - SharePoint/ - Sites - - - Copilot/ - Gemini - - - • Vendor Lock-in - • Monthly Costs - - - - - - - Migration Tools - - - - rclone - - - imapsync - - - BASIC Scripts - - - API Migration - - - KB Converter - - - User Import - - - 1. Export Data - 2. Transform Format - 3. Import to GB - 4. Validate - - - - - - - Self-Hosted Stack - - - - General Bots Core - - - - MinIO - - - Stalwart - - - LiveKit - - - Qdrant - - - Local LLM - - - Zitadel - - - ✓ Full Control - ✓ No Vendor Lock-in - - - - - - - - - - - - - - - Cost Comparison - - - Enterprise Cloud - $50-200/user/month - Forever - - - Migration Cost - One-time effort - 1-4 weeks - - - Self-Hosted - Infrastructure only - ~$500/month total - - - - - Typical Migration Timeline - - - - - - - Start - Assessment - - - Week 1 - Infrastructure - - - Week 2 - Data Migration - - - Week 3 - Testing - - - Week 4 - Go Live - - - - - Transform from mega-prompt dependency to true component architecture - - - Your data, your infrastructure, your control - - - - - diff --git a/docs/src/assets/observability-flow.svg b/docs/src/assets/observability-flow.svg deleted file mode 100644 index 525fd0aa..00000000 --- a/docs/src/assets/observability-flow.svg +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - - - - - - - - - - - - Observability Flow - Vector Agent collects logs from BotServer without code changes - - - - - Application - Collection - Processing - Outputs - - - - BotServer Application - - - log::trace!() - log::debug!() - log::info!() - log::warn!() - log::error!() - - - ↓ writes to - - ./botserver-stack/logs/ - - - - Vector Agent - (Collects from log files) - - - - Sources - - - Transforms - - - Sinks - - - (Files) - (Parse) - (Output) - - - - - - - - Processing - - - - Filter Errors - - - Filter Warnings - - - Log to Metrics - - - Enrich Data - - - - - InfluxDB - (Metrics) - - - - Grafana - (Dashboard) - - - - Alerts - (Webhook) - - - - - - - - - - - - - - - - - - - - Log Directory Structure - logs/system/ → BotServer logs - logs/drive/ → SeaweedFS logs - logs/tables/ → PostgreSQL logs - logs/cache/ → Valkey logs - logs/vectordb/ → Qdrant - logs/email/ → Stalwart - logs/directory/ → Zitadel - logs/meet/ → LiveKit - - - - - - Vector Configuration - [sources.botserver_logs] - type = "file" - include = ["logs/system/*.log"] - [transforms.parse_botserver] - type = "remap" - - - - - - Key Benefits - ✓ Zero code changes required - ✓ Works with existing logging - ✓ Add/remove without recompile - ✓ Scales independently - - - - - - - - - - - - - - - - - - - Generate - log::*!() - - Collect - Vector Agent - - Process - Parse & Route - - Store/Alert - InfluxDB/Grafana - - - - - Automatic Metrics: - - - log_events_total - - - errors_total - - - warnings_total - - - llm_latency_seconds - - - sessions_active - - - - - Keep using standard Rust log macros - Vector handles collection, parsing, and routing - - - Install with: ./botserver install observability - - diff --git a/docs/src/assets/package-system-flow.svg b/docs/src/assets/package-system-flow.svg deleted file mode 100644 index b305f2c4..00000000 --- a/docs/src/assets/package-system-flow.svg +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - - - - - - - - - - - - - Package System Flow - How .gbai packages orchestrate bot behavior - - - - - Input - Script - Intelligence - Execution - Output - - - - - User Request - - - - start.bas - - - - LLM Engine - - - - Tool Executor - - - - Bot Response - - - - - Vector Search - - - - .gbkb Docs - - - - External APIs - - - - - - - - - - - - - - - - - - - - - - - - Query - Context - - - - - - Package Structure - my-bot.gbai/ - ├── .gbdialog/ - └── start.bas, tools.bas - ├── .gbkb/ - └── docs, PDFs, data - └── .gbot/config.csv - - - - - - BASIC Commands - USE KB "knowledge" - question = HEAR - answer = LLM(question) - TALK answer - // Zero configuration AI - - - - - - Key Features - ✓ Auto tool registration - ✓ RAG from any document - ✓ Multi-channel deploy - ✓ Hot reload packages - ✓ Session persistence - - - - - - - - - - - - - - - - - - - - - - - - - - - - Receive - Parse Script - LLM Process - Execute Tools - Respond - - - - - BASIC scripts orchestrate LLM decisions, vector search, and responses with zero configuration - - - Drop files in .gbkb → Write scripts in .gbdialog → Deploy instantly - - diff --git a/docs/src/assets/package-system-flow.svg.backup b/docs/src/assets/package-system-flow.svg.backup deleted file mode 100644 index ef24318f..00000000 --- a/docs/src/assets/package-system-flow.svg.backup +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - Package System Flow - - - - User Request - - - - Bot Response - - - - - start.bas - - - USE KB "docs" - answer=HEAR - result=LLM() - TALK result - - - - - LLM Engine - (GPT/Local) - Processes requests - Makes decisions - - - - - Vector Search - (.gbkb docs) - Semantic search - - - - - - - - - - - - - - - - - - - - - - - - - - - - Commands - Results - - Query - Context - - - - - Flow Legend - - - Direct flow - - - Feedback/Return - - - - Bidirectional - - diff --git a/docs/src/assets/platform-comparison-summary.svg b/docs/src/assets/platform-comparison-summary.svg deleted file mode 100644 index e25a6de7..00000000 --- a/docs/src/assets/platform-comparison-summary.svg +++ /dev/null @@ -1,329 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Platform Comparison Summary - General Bots vs Enterprise Cloud Platforms - - - - - - - General Bots - - - - - - Self-Hosted - - - - - Open Source (AGPL) - - - - - No Per-User Fees - - - - - Native AI (Any LLM) - - - - - Full Productivity Suite - - - - - Multi-Channel Chat - - - - - Unlimited Automation - - - - - BASIC Scripting - - - - - Data Sovereignty - - - - - $3K-12K/year - 100 users • Infrastructure only - - - - - - - - Enterprise Cloud - - - - - - Cloud Only - - - - - Proprietary - - - - - $12-57/user/month - - - - $ - AI Extra ($30/user) - - - - - Full Productivity Suite - - - - $ - Limited Channels - - - - $ - Per-Flow Fees - - - - ~ - Limited Scripting - - - - - Vendor Controlled - - - - - $50K-90K/year - 100 users • Base + AI + Automation - - - - - - - - Automation Tools - - - - ~ - Some Self-Host - - - - ~ - Fair-code/Proprietary - - - - $ - Per-Task Pricing - - - - $ - AI via Connectors - - - - - No Productivity Suite - - - - - No Native Chat - - - - - Visual Workflows - - - - ~ - JS/Visual Only - - - - ~ - Partial Control - - - - $15K-30K/year - + external tools needed - - - - - - - - AI Assistants - - - - - Cloud Only - - - - - Proprietary - - - - $ - Subscription Based - - - - - Strong AI Built-in - - - - - No Productivity Suite - - - - - Web Interface Only - - - - - No Automation - - - - - No Scripting - - - - - No Data Control - - - - $2K-5K/year - Chat only • Limited scope - - - - - - - - - 75-95% - Cost Reduction - - - - - 100% - Data Sovereignty - - - - - 90+ - BASIC Keywords - - - - - - Unlimited Users - - - - - Open Source - - - diff --git a/docs/src/assets/script-execution-flow.svg b/docs/src/assets/script-execution-flow.svg deleted file mode 100644 index 7552c215..00000000 --- a/docs/src/assets/script-execution-flow.svg +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - - - - - - - - - - - - Script Execution Flow - BASIC Compilation Pipeline - From Source to Execution - - - - - Entry Points - - - - start.bas - (Bot Start) - - - - SET SCHEDULE - (Cron Jobs) - - - - WEBHOOK - (HTTP POST) - - - - BASIC Compiler & Runtime - - - - 1. Load Source - - - 2. Load Config - - - 3. Preprocess - - - 4. Compile - - - Read .bas file - param-* vars - Transform - Rhai AST - - - - 5. Execute with Injected Scope - Keywords call registered handlers → LLM Tools → API Calls - - - - - - - - - - - - - - - - - Execution Outputs - - - - LLM Tools - (ADD TOOL) - - - - ON Events - (Triggers) - - - - API Calls - (External) - - - - - - - - - - - - - - - Package Structure (mybot.gbai) - - mybot.gbai/ - ├── mybot.gbdialog/ - ├── start.bas ' Entry point - ├── tables.bas ' TABLE definitions - ├── create-order.bas ' Tool script - └── sync-data.bas ' Scheduled script - └── mybot.gbot/config.csv - - - - - - config.csv (Injected Variables) - param-api-key,sk-xxxxx - param-webhook-url,https://... - param-max-retries,3 - → Available as variables in BASIC - - - - - - Preprocessing Steps - • Case normalization (TALK → talk) - • Multi-word keyword transform - • FOR EACH block handling - • Variable scope injection - - - - - - Keyword Execution - • TALK → Send message to channel - • HEAR → Wait for user input - • LLM → Call language model - • GET/POST → HTTP requests - - - - - - - - - - - - - - - - - - - - - - - Load - Config - Preprocess - Compile - Execute - Respond - - - - - BASIC scripts compile to Rhai AST and execute with registered keyword handlers - - - Scripts in .gbdialog/ are hot-reloaded on change - no restart required - - diff --git a/docs/src/assets/suite/analytics-flow.svg b/docs/src/assets/suite/analytics-flow.svg deleted file mode 100644 index b4ba31cb..00000000 --- a/docs/src/assets/suite/analytics-flow.svg +++ /dev/null @@ -1,313 +0,0 @@ - - - - - - - - - - - - - - - - - Analytics - Dashboard Flow - Real-time metrics, charts, and insights for bot performance and usage - - - Data Sources - Metrics - Visualizations - Actions - - - - - - - - Data Collection - Aggregate sources - - - - - - Chats - Messages - - - - - - Users - Sessions - - - - - - API - Requests - - - - - - LLM - Tokens - - - - - - System - Resources - - - - - - Errors - Logs - - - - - - Key Metrics - KPI summary cards - - - - - - Active Users - Daily/Weekly/Monthly - - - - - - Response Time - Avg latency - - - - - - Satisfaction - User feedback - - - - - - Charts - Visual insights - - - - - - Line - Trends - - - - - - Bar - Compare - - - - - - Pie - Share - - - - - - Heat - Density - - - - - - Data Tables - Sortable, filterable - - - - - - Actions - Export and alerts - - - - - - Export - CSV, PDF, JSON - - - - - - Alerts - Threshold triggers - - - - - - AI Insights ✨ - Anomaly detection - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Collect - Aggregate data - - Analyze - Compute metrics - - Visualize - Display charts - - Act - Export and alert - - - - - Key Metrics: - - - Conversations and messages - - - Active users (DAU/MAU) - - - Response latency - - - LLM token usage - - - Error rates - - - - - Time Ranges: - Last 24 hours | Last 7 days | Last 30 days | Last 90 days | Custom range | Real-time - - - - - Endpoints: - GET /api/analytics/summary | GET /api/analytics/metrics | GET /api/analytics/charts | POST /api/analytics/export | GET /api/analytics/realtime - - - diff --git a/docs/src/assets/suite/analytics-screen.svg b/docs/src/assets/suite/analytics-screen.svg deleted file mode 100644 index 7dee1347..00000000 --- a/docs/src/assets/suite/analytics-screen.svg +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - Analytics - Dashboard - - - - - - - Dashboard Overview - Last 30 days • Updated 5 min ago - - - - - - 📅 - Last 30 days - - - - Export - - - - - - - - - Total Users - 12,847 - ↑ 12.5% - vs last month - - 👥 - - - - - Active Sessions - 1,429 - ↑ 8.2% - vs last month - - 📊 - - - - - Avg Response Time - 1.2s - ↓ 15% - faster - - - - - - - Satisfaction Rate - 94.2% - ↑ 2.1% - vs last month - - - - - - - - - - User Activity - Daily active users - - - - - - - - - 2k - 1.5k - 1k - 500 - - - - - - - - - - - - - - - - - - 1 - 8 - 15 - 22 - 30 - March 2024 - - - - - Messages by Type - - - - - - - - - Chat - Email - Voice - Other - - - 4.2k - 3.1k - 1.8k - 890 - - - - - - - - Top Queries - - 1. "How do I reset my password?" - 847 - - 2. "Billing information" - 623 - - 3. "Schedule a meeting" - 512 - - View all → - - - - - Performance - - Resolution Rate - - - 85% - - Escalation Rate - - - 15% - - - - - R = Refresh | E = Export | D = Date range | F = Filter - - diff --git a/docs/src/assets/suite/app-launcher.svg b/docs/src/assets/suite/app-launcher.svg deleted file mode 100644 index 7bdad04a..00000000 --- a/docs/src/assets/suite/app-launcher.svg +++ /dev/null @@ -1,214 +0,0 @@ - - - - - - - - - - - General Bots Suite - Your AI-Powered Productivity Workspace - - - - - - - - - - - - Chat - AI Assistant - - - - - - - - - - Drive - File Storage - - - - - - - - - - - Tasks - To-Do Lists - - - - - - - - - - - Mail - Email Client - - - - - - - - - - - - Calendar - Scheduling - - - - - - - - - - Meet - Video Calls - - - - - - - - - - - - - Paper - AI Writing - - - - - - - - - - Research - AI Search - - - - - - - - - - - Analytics - Reports - - - - - - - Additional Tools - - - - Designer - - - - - Sources - - - - - Compliance - - - - - Settings - - - - diff --git a/docs/src/assets/suite/calendar-flow.svg b/docs/src/assets/suite/calendar-flow.svg deleted file mode 100644 index 5ae310f8..00000000 --- a/docs/src/assets/suite/calendar-flow.svg +++ /dev/null @@ -1,291 +0,0 @@ - - - - - - - - - - - - - - - - - Calendar - Scheduling Flow - Event management with multiple views and AI scheduling assistance - - - Views - Events - Details - Actions - - - - - - - - View Selector - Choose display mode - - - - - - Month - Overview - - - - - - Week - 7 days - - - - - - Day - Hourly - - - - - - Agenda - List view - - - - - - Mini Calendar - Quick navigation - - - - - - Event Grid - Visual timeline - - - - - - Event Cards - Color-coded - - - - - - Time Slots - Drag to create - - - - - - All-Day Events - Top banner - - - - - - Event Details - Modal/sidebar - - - - - - Title & Time - Date picker - - - - - - Location - Virtual/IRL - - - - - - Attendees - Invite - - - - - - Reminders - Notifications - - - - - - Actions - Event management - - - - - - Create Event - + New - - - - - - Edit / Delete - Modify events - - - - - - AI Schedule ✨ - Smart booking - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Choose View - Month/Week/Day - - Browse Events - Visual timeline - - View Details - Event info - - Take Action - Create/Edit - - - - - Features: - - - Drag-and-drop event creation - - - Recurring events - - - Multi-calendar support - - - AI scheduling assistant ✨ - - - Timezone handling - - - - - Shortcuts: - C = Create | M = Month | W = Week | D = Day | A = Agenda | T = Today | ← → = Navigate | Enter = Open - - - - - Endpoints: - GET /api/calendar/events | POST /api/calendar/events | PUT /api/calendar/events/{id} | DELETE /api/calendar/events/{id} | POST /api/calendar/ai/suggest - - - diff --git a/docs/src/assets/suite/calendar-screen.svg b/docs/src/assets/suite/calendar-screen.svg deleted file mode 100644 index d2b3204e..00000000 --- a/docs/src/assets/suite/calendar-screen.svg +++ /dev/null @@ -1,265 +0,0 @@ - - - - - - - - - - - Calendar - Schedule Manager - - - - - - - - - - - - + New Event - - - - - - - March 2024 - - - - - - S - M - T - W - T - F - S - - - - - 25 - 26 - 27 - 28 - 29 - 1 - 2 - - - - - 3 - 4 - 5 - 6 - 7 - 8 - 9 - - - - - 10 - 11 - 12 - 13 - 14 - - 15 - 16 - - - - - 17 - 18 - 19 - 20 - 21 - 22 - 23 - - - - - 24 - 25 - 26 - 27 - 28 - 29 - 30 - - - - - - MY CALENDARS - - - - Personal - - - - - Work - - - - - Family - - - - - - - - Today - - - - - March 15, 2024 - - - - - Day - - Week - Month - - - - - - - - - SUN - 10 - - MON - 11 - - TUE - 12 - - WED - 13 - - THU - 14 - - FRI - - 15 - - SAT - 16 - - - - - - 8 AM - 9 AM - 10 AM - 11 AM - 12 PM - 1 PM - 2 PM - 3 PM - 4 PM - 5 PM - - - - - - - - - - - - - - - - - - - - - - - - - Team Standup - 9:00 - 10:00 - - - - Client Call - 11:00 - 12:00 - - - - Project Review - 2:00 - 3:00 - - - - 1:1 Meeting - 4:00 - 5:00 - - - - - - - - - Click to create | Drag to reschedule | Double-click to edit - - diff --git a/docs/src/assets/suite/chat-flow.svg b/docs/src/assets/suite/chat-flow.svg deleted file mode 100644 index 745ef3ea..00000000 --- a/docs/src/assets/suite/chat-flow.svg +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - - - - - - - - - - Chat - AI Assistant Flow - WebSocket-powered real-time conversation with your AI assistant - - - Input - Transport - Processing - Response - - - - - - - - User Message - Text or Voice Input - - - - - - Voice Input - Speech-to-Text - - - - - - Quick Suggestions - One-click actions - - - - - - WebSocket - Real-time Connection - - - - - - HTMX POST - Fallback Transport - - - - - - AI Processing - LLM + Context - - - - - - Context - History - - - - - - Tools - KB + APIs - - - - - - Bot Response - Streamed to UI - - - - - - Message Display - Markdown Rendered - - - - - - Chat History - Scroll + Load More - - - - - - - - - - - - - - - - - - - - - - - - - - Conversation continues... - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Type or Speak - Enter your message - - Send - WebSocket transmit - - Process - AI generates response - - Display - See bot reply - - - - - Key Features: - - - Voice input with speech-to-text - - - Real-time WebSocket connection - - - Context-aware AI responses - - - Markdown rendering - - - - - Shortcuts: - Enter = Send | Shift+Enter = New line | ↑ = Edit last | / = Commands - - - - - Endpoints: - /ws (WebSocket) | POST /api/sessions/current/message | GET /api/sessions/current/history | POST /api/voice/start - - - diff --git a/docs/src/assets/suite/chat-screen.svg b/docs/src/assets/suite/chat-screen.svg deleted file mode 100644 index eefb81de..00000000 --- a/docs/src/assets/suite/chat-screen.svg +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - - - - - - - - - - - - Chat - AI Assistant - - - - - - - - - - - GB - General Bots - - - - - - ☀️ - Light - - - - - - - - - - - - - JD - - - - - - - - - - - - - - - - AI Assistant - Hello! I'm your AI assistant. How can I help - you today? - - - - - - What meetings do I have scheduled for today? - - - - - - AI Assistant - You have 3 meetings scheduled for today: - 📅 10:00 AM - Team Standup (30 min) - 📅 2:00 PM - Client Call with Acme Corp (1 hr) - 📅 4:30 PM - 1:1 with Manager (30 min) - - - - - - - - - - - - - - - - - - - - - 📧 Check my email - - - ✓ Show my tasks - - - 🔍 Search documents - - - 📝 Take notes - - - - - - - - Message... - - - - - 🎤 - - - - - - - - - - - - - - - - - - - 💡 Tip: Use / for commands, @ to mention, # for tags - Enter = Send | Shift+Enter = New line | ↑ = Edit last - - diff --git a/docs/src/assets/suite/compliance-flow.svg b/docs/src/assets/suite/compliance-flow.svg deleted file mode 100644 index 8a3dffa9..00000000 --- a/docs/src/assets/suite/compliance-flow.svg +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - - - - - - - - - - - Compliance - Security Scanner Flow - Automated security scanning for configurations, code, and credentials - - - Scan Targets - Analysis - Detection - Reporting - - - - - - - - Scan Request - API or Scheduled - - - - - - Config Files - .env, config.csv - - - - - - BASIC Scripts - .bas dialog files - - - - - - Knowledge Base - Prompts, templates - - - - - - Scanner Engine - Pattern Matching - - - - - - Credential Check - Passwords, API keys - - - - - - Code Analysis - Fragile code patterns - - - - - - Security Rules - Best practices - - - - - - Issues Found - Categorized Results - - - - - - Critical - Secrets - - - - - - Warning - Fragile - - - - - - Info - Suggestions - - - - - - Pass - OK checks - - - - - - Report - JSON + Dashboard - - - - - - Dashboard View - Visual summary - - - - - - Remediation - Fix suggestions - - - - - - Export - CSV, PDF, JSON - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Target Selection - Choose what to scan - - Analyze - Run security checks - - Detect - Categorize findings - - Report - View and export - - - - - Scan Categories: - - - Exposed credentials (passwords, API keys) - - - Fragile code patterns in .bas files - - - Missing vault usage - - - Security best practices - - - - - Severity Levels: - 🔴 Critical (immediate action) | 🟠 Warning (should fix) | 🔵 Info (recommendations) | 🟢 Pass (compliant) - - - - - Endpoints: - GET /api/compliance | POST /api/compliance/scan | GET /api/compliance/report/{id} | GET /api/compliance/export/{format} - - - diff --git a/docs/src/assets/suite/compliance-screen.svg b/docs/src/assets/suite/compliance-screen.svg deleted file mode 100644 index c8b4c4f6..00000000 --- a/docs/src/assets/suite/compliance-screen.svg +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - Compliance - Security Scanner - - - - - - - - - - - - 🔍 Run Scan - - - - - SCAN TYPES - - - - 🛡️ - All Checks - - - - 🔐 - Security - - - - 📋 - Privacy - - - - - Performance - - - - - Accessibility - - - - - - FRAMEWORKS - - - - GDPR - - - - - SOC 2 - - - - - HIPAA - - - - - ISO 27001 - - - - - - Security Overview - Last scan: 5 minutes ago • Next scheduled: 24 hours - - - - - - 📄 Export - - - - - - - - - Overall Score - 87 - /100 - ↑ 5 pts - - - - - Passed - 42 - - 89% - - - - - Warnings - 4 - - 8% - - - - - Critical - 1 - - 2% - - - - - Issues Found - - - - - - - 🚨 - Insecure API Endpoint Detected - /api/v1/users lacks authentication • Found 2 hours ago - - Critical - - Fix - - - - - - - - ⚠️ - Outdated SSL Certificate - Certificate expires in 15 days • Renewal recommended - - Warning - - Fix - - - - - - - - ⚠️ - Missing Content Security Policy - CSP header not configured • XSS vulnerability risk - - Warning - - Fix - - - - - - - - - Data Encryption at Rest - AES-256 encryption enabled • All data stores compliant - - Passed - - - - - - Compliance Progress - - - - GDPR - - - 95% - - - - - SOC 2 - - - 90% - - - - - HIPAA - - - 75% - - - - - ISO 27001 - - - 88% - - - - - - R = Rescan | F = Filter by severity | E = Export report | Enter = View details - - diff --git a/docs/src/assets/suite/designer-flow.svg b/docs/src/assets/suite/designer-flow.svg deleted file mode 100644 index 06d5b781..00000000 --- a/docs/src/assets/suite/designer-flow.svg +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - - - - - - - - - - - Designer - Visual Dialog Builder Flow - VB6-style drag-and-drop interface for creating BASIC dialog scripts - - - Toolbox - Canvas - Properties - Export - - - - - - - - Toolbox Panel - Drag blocks to canvas - - - - - - TALK - Output - - - - - HEAR - Input - - - - - - IF - Condition - - - - - FOR - Loop - - - - - - SET - Variable - - - - - CALL - Procedure - - - - - - Design Canvas - Visual workspace - - - - - - Node Placement - Snap to grid - - - - - - Connections - Flow arrows - - - - - - Selection - Multi-select, move - - - - - - Properties - Edit block settings - - - - - - Block Fields - Text, values - - - - - - Validation - Type checking - - - - - - Live Preview - BASIC output - - - - - - Export .bas - Generate code - - - - - - Save Design - JSON format - - - - - - Load Design - Open existing - - - - - - Deploy - To bot package - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Select Block - Drag from toolbox - - Place & Connect - Build flow on canvas - - Configure - Set properties - - Export - Generate .bas file - - - - - Block Types: - - - I/O (TALK, HEAR) - - - Logic (IF, FOR, SWITCH) - - - Actions (SET, CALL, GET) - - - Memory (BOT/USER MEMORY) - - - Integration (SEND MAIL, POST) - - - - - Shortcuts: - Ctrl+S = Save | Ctrl+Z = Undo | Ctrl+Y = Redo | Del = Delete | Ctrl+D = Duplicate | Ctrl+E = Export - - - - - Canvas: - Click = Select | Drag = Move | Click port = Connect | Right-click = Context menu | Scroll = Pan | Ctrl+Scroll = Zoom - - - diff --git a/docs/src/assets/suite/designer-screen.svg b/docs/src/assets/suite/designer-screen.svg deleted file mode 100644 index c6fbb0da..00000000 --- a/docs/src/assets/suite/designer-screen.svg +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - Visual Flow Builder - - - - - - - - - Components - - - - - TRIGGERS - - - - - - Start - - - - - - 💬 - Message - - - - ACTIONS - - - - - 🤖 - AI Response - - - - - - 📧 - Send Email - - - - - - - API Call - - - - LOGIC - - - - - - Condition - - - - - - - Wait - - - - - - - End - - - - - - - - - - - - - + Add - - - - - - - - - - - 🔍 - - - + - - - - - 100% - - - - - ▶ Test - - - Deploy - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Start - User message - - - - - - - 🤖 - AI Response - GPT-4 Model - - - - - - - - - Condition - intent == support - - - - - - - 📧 - Send Email - Support team - - - - - - - - End - Complete flow - - - - - - - Properties - - - NODE - AI Response - - MODEL - - - GPT-4 - - - PROMPT - - - You are a - helpful - assistant... - - TEMPERATURE - - - 0.7 - - - - - Drag to connect | Del = Delete | Ctrl+D = Duplicate | Ctrl+Z = Undo - - diff --git a/docs/src/assets/suite/drive-flow.svg b/docs/src/assets/suite/drive-flow.svg deleted file mode 100644 index 9b6c7589..00000000 --- a/docs/src/assets/suite/drive-flow.svg +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - - - - - - - - - Drive - File Management Flow - Cloud storage with drag-and-drop, sharing, and organization - - - Navigation - Actions - Storage - Display - - - - - - - - Sidebar - - - - - My Drive - - - Starred - - - Recent - - - Trash - - - - - - + New - Upload Files | New Folder - - - - - - - Upload - Drag & Drop - - - - Download - Single/Batch - - - - Rename - Edit name - - - - Move / Copy - Organize - - - - Share - Get link - - - - Delete - Move to Trash - - - - - - SeaweedFS - Object Storage - - - - - - REST API - /api/v1/drive/* - - - - - - PostgreSQL - File Metadata - - - - - - File View - - - - - Grid - - - List - - - My Drive / Projects / 2024 - - - - 📁 Docs - - - 📄 Report - - - 🖼 Image - - - Storage Used - - - 4.2 GB of 10 GB - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Navigate - Browse folders - - Action - Upload, move, share - - Store - Save to cloud - - View - Grid or list display - - - - - Key Features: - - - Drag-and-drop upload - - - Context menu actions - - - SeaweedFS object storage - - - Grid/List view toggle - - - Star & label files - - - - - Shortcuts: - Ctrl+U = Upload | Ctrl+N = New Folder | Delete = Trash | Ctrl+C/V = Copy/Paste | Enter = Open - - - - - Endpoints: - GET /api/v1/drive/list | POST /api/v1/drive/upload | DELETE /api/v1/drive/file | PUT /api/v1/drive/move - - - - - HTMX: - hx-get="/api/v1/drive/list" hx-target="#file-list" hx-trigger="load, click" hx-swap="innerHTML" - - - diff --git a/docs/src/assets/suite/drive-screen.svg b/docs/src/assets/suite/drive-screen.svg deleted file mode 100644 index 30157282..00000000 --- a/docs/src/assets/suite/drive-screen.svg +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - Drive - File Manager - - - - - - - - - - + New - - - - - My Drive - 📁 - - 👥 - Shared with me - - - Starred - - 🕐 - Recent - - 🗑️ - Trash - - - - STORAGE - - - 6.5 GB of 10 GB - - - - - - 🔍 - Search files... - - - - - - - - - - - - - My Drive - / - Projects - / - 2024 - - - - - Name - Modified - Size - Owner - - - - - - - 📁 - Reports - Today, 10:30 AM - - me - - - - - - 📁 - Presentations - Yesterday - - me - - - - - 📊 - Budget-2024.xlsx - Mar 15, 2024 - 245 KB - me - - - - - 📄 - Project-Proposal.docx - Mar 14, 2024 - 128 KB - me - - - - - 📕 - Contract-Signed.pdf - Mar 10, 2024 - 1.2 MB - John D. - - - - - 🖼️ - Logo-Final.png - Mar 8, 2024 - 89 KB - me - - - - - 📤 - Drop files here or click + New to upload - - - - 1 item selected - - 6 items - Ctrl+U Upload | Del Delete | Ctrl+C Copy - - diff --git a/docs/src/assets/suite/live-monitoring-organism.svg b/docs/src/assets/suite/live-monitoring-organism.svg deleted file mode 100644 index 1ce47aa9..00000000 --- a/docs/src/assets/suite/live-monitoring-organism.svg +++ /dev/null @@ -1,521 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 🔴 LIVE SYSTEM MONITOR - - - General Bots Platform • Real-time Component Status - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 🤖 - - - BotServer - ● RUNNING - v5.0.2 • Rust - - - - - - - - - - - - - - - - - - - - 🐘 - PostgreSQL - - - Connections: 24/100 - Queries/sec: 847 - - - - - - - ● HEALTHY - v16.2 - - - - - - FUNCTIONS - • User Sessions - • Bot Configs - - - - - - - - - - - - - - - - - - - - Qdrant - Vectors: 1.2M - Collections: 8 - Search: 12ms avg - - - - - - ● HEALTHY - v1.9.2 - - - - - - FUNCTIONS - • Semantic Search - • RAG Embeddings - - - - - - - - 📁 - 📄 - 🖼️ - - MinIO Drive - Storage: 45.2 GB - Objects: 12,847 - - - - - - ● HEALTHY - v2024.01 - - - - - - - - - - - 🧠 - - - - - - - BotModels - Model: gpt-4o - Tokens/hr: 125K - Latency: 890ms - - - - - - ● RUNNING - v2.1.0 - - - - - - FUNCTIONS - • LLM Inference - • Model Routing - - - - - - - - 🔐 - - Vault - Secrets: 156 - Policies: 12 - - - - - - ● SEALED - v1.15.0 - - - - - - - - - - Redis Cache - Hit Rate: 94.2% - Keys: 8,421 - Memory: 256MB - - - - - - ● CONNECTED - v7.2.4 - - - - - - - - - - - - - - - - - - - - - - - - - InfluxDB - Points/sec: 2,450 - Retention: 30d - Buckets: 4 - - - - - - ● RECORDING - v2.7.3 - - - - - - SYSTEM RESOURCES - - - CPU - - - - - 70% - - - MEM - - - - - 60% - - - GPU - - - - - 40% - - - - - - - - - SESSIONS - - 247 - - - - - - - MESSAGES - 12.4K - - - - - AVG RESPONSE - 1.2s - - - - - UPTIME - 99.9% - - - - - - - STATUS LEGEND - - - Healthy/Running - - - Warning/Degraded - - - Error/Stopped - - - - - Last updated: 2025-01-14 15:42:31 UTC - - - - - - - - - - diff --git a/docs/src/assets/suite/mail-flow.svg b/docs/src/assets/suite/mail-flow.svg deleted file mode 100644 index 1632596f..00000000 --- a/docs/src/assets/suite/mail-flow.svg +++ /dev/null @@ -1,302 +0,0 @@ - - - - - - - - - - - - - - - - - Mail - Email Client Flow - IMAP/SMTP email management with AI-powered features - - - Folders - Messages - Actions - Compose - - - - - - - - Folder List - Navigate mailbox - - - - - - Inbox - Received - - - - - - Sent - Outgoing - - - - - - Drafts - In progress - - - - - - Trash - Deleted - - - - - - Starred - Important - - - - - - Archive - Stored - - - - - - Message List - Browse emails - - - - - - Preview Pane - Quick read - - - - - - Search - Find messages - - - - - - Filters - Unread, starred - - - - - - Actions - Manage emails - - - - - - Reply - Respond - - - - - - Forward - Share - - - - - - Delete - Remove - - - - - - Archive - Store - - - - - - AI Summary ✨ - Quick insights - - - - - - Compose - Write new email - - - - - - Recipients - To, CC, BCC - - - - - - Rich Editor - Format text - - - - - - Attachments - Add files - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Select Folder - Navigate mailbox - - Read Messages - Browse and search - - Take Action - Reply, forward, delete - - Compose - Write new email - - - - - AI Features: - - - Smart compose with AI suggestions - - - Thread summarization - - - Priority detection - - - Action item extraction - - - - - Shortcuts: - C = Compose | R = Reply | F = Forward | E = Archive | # = Delete | S = Star | / = Search - - - - - Endpoints: - GET /api/mail/folders | GET /api/mail/messages | POST /api/mail/send | DELETE /api/mail/{id} | POST /api/mail/ai/summarize - - - diff --git a/docs/src/assets/suite/mail-screen.svg b/docs/src/assets/suite/mail-screen.svg deleted file mode 100644 index 1f10fedb..00000000 --- a/docs/src/assets/suite/mail-screen.svg +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - - - - Mail - Email Client - - - - - - - - - - - - ✏ Compose - - - - - - 📥 - Inbox - 3 - - 📤 - Sent - - 📝 - Drafts - - - Starred - - 🗑️ - Trash - - - - - - - - - Inbox - - 🔄 - - - - - - - - - - Sarah Johnson - 10:30 AM - Project Update - Hi team, here is the latest... - - - - - - - Marketing Team - 9:15 AM - Q4 Campaign Results - The numbers are in and... - - - - - - - John Smith - Yesterday - Meeting Notes - Thanks for the call today... - - - - - Alex Chen - Mar 15 - Re: Budget Review - Looks good to me... - - - - HR Department - Mar 14 - Benefits Enrollment - Open enrollment starts... - - - - - - - - Meeting Notes - - - - JS - - John Smith - john.smith@company.com - - Yesterday, 3:45 PM - - - - - - - - - ↩ Reply - - - ↩↩ Reply All - - - ↪ Forward - - - 🗑 Delete - - - - - - - Hi Team, - Thanks for joining the call today. Here are the key - takeaways from our discussion: - - • Project timeline updated to Q2 launch - • Budget approved for additional resources - • Next review scheduled for Friday - - Let me know if you have any questions. - - Best regards, - John - - - - - Ctrl+R Reply | Ctrl+Shift+R Reply All | Ctrl+F Forward | Del Delete - - diff --git a/docs/src/assets/suite/meet-flow.svg b/docs/src/assets/suite/meet-flow.svg deleted file mode 100644 index 62e56ddb..00000000 --- a/docs/src/assets/suite/meet-flow.svg +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - - - - - - - - - - - Meet - Video Calls Flow - LiveKit-powered video conferencing with AI transcription and summaries - - - Setup - Meeting - AI Features - Post-Meeting - - - - - - - - Start Meeting - Create or join - - - - - - Camera - Video - - - - - - Mic - Audio - - - - - - Preview - Check before join - - - - - - Invite - Share link - - - - - - Video Grid - Participants view - - - - - - Controls - Mute, camera, share - - - - - - Chat - Messages - - - - - - Share - Screen - - - - - - React - 👍 🎉 - - - - - - Hand - ✋ Raise - - - - - - AI Features ✨ - Smart assistance - - - - - - Transcription - Live captions - - - - - - Live Summary - Real-time notes - - - - - - Action Items - Auto-detect tasks - - - - - - Post-Meeting - After the call - - - - - - Recording - Video playback - - - - - - Full Transcript - Searchable text - - - - - - Meeting Notes - AI summary + tasks - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Setup - Check devices - - Meeting - Video conference - - AI Assist - Live transcription - - Review - Notes and recording - - - - - Meeting Controls: - - - Camera and microphone - - - Screen sharing - - - Recording - - - Live transcription - - - Chat and reactions - - - - - Shortcuts: - M = Mute | V = Video | S = Share screen | R = Record | H = Raise hand | Space = Push-to-talk | Esc = Leave - - - - - Endpoints: - POST /api/meet/create | GET /api/meet/join/{id} | GET /api/meet/transcript/{id} | GET /api/meet/recording/{id} | POST /api/meet/ai/summary - - - diff --git a/docs/src/assets/suite/meet-screen.svg b/docs/src/assets/suite/meet-screen.svg deleted file mode 100644 index fda3f497..00000000 --- a/docs/src/assets/suite/meet-screen.svg +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - - - - - - - - Meet - Video Conference - - - - - - - - - - - JS - John Smith - Speaking... - - - - - - - - - - - - - - - Team Standup • 15:32 - - - - - - - ME - You - - - - - - Participants (5) - - - - - - SW - Sarah Wilson - - Online - - - - - - - MJ - Mike Johnson - - Muted - - - - - - - AC - Alex Chen - - Online - - - - - - - EM - Emma Miller - - Online - - - - - - + Invite People - - - - - - - - - Team Standup - 5 participants • 15:32 - - - - - - - 🎤 - - - - 📹 - - - - 🖥 - - - - 💬 - - - - 📞 - - - - - - - - - - - - - - - - - - - - M = Mute | V = Camera | S = Share Screen | C = Chat | L = Leave - - diff --git a/docs/src/assets/suite/paper-flow.svg b/docs/src/assets/suite/paper-flow.svg deleted file mode 100644 index a5c08417..00000000 --- a/docs/src/assets/suite/paper-flow.svg +++ /dev/null @@ -1,332 +0,0 @@ - - - - - - - - - - - - - - - - - Paper - AI Writing Assistant Flow - Rich text editor with AI-powered writing, editing, and formatting assistance - - - Create - Edit - AI Assist - Export - - - - - - - - New Document - Create or open - - - - - - Blank - Fresh start - - - - - - Template - Pre-built - - - - - - Import - MD, DOCX - - - - - - AI Gen ✨ - From prompt - - - - - - Recent Documents - Quick access - - - - - - Rich Editor - Write content - - - - - - Formatting - Bold, italic, headers - - - - - - Lists - Bullets - - - - - - Tables - Grid data - - - - - - Code - Syntax HL - - - - - - Images - Media - - - - - - AI Assist ✨ - Writing helper - - - - - - Continue Writing - Auto-complete - - - - - - Improve - Rewrite - - - - - - Summary - Condense - - - - - - Translate - Languages - - - - - - Grammar - Fix errors - - - - - - Export - Save and share - - - - - - .md - Markdown - - - - - - .pdf - Document - - - - - - .html - Web page - - - - - - .docx - Word - - - - - - Auto-Save - Never lose work - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Create - New document - - Write - Rich text editing - - Enhance - AI assistance - - Export - Multiple formats - - - - - AI Writing Features: - - - Auto-complete sentences - - - Improve writing style - - - Summarize content - - - Multi-language translate - - - Grammar and spelling - - - - - Shortcuts: - Ctrl+B = Bold | Ctrl+I = Italic | Ctrl+K = Link | Ctrl+/ = AI assist | Ctrl+S = Save | Ctrl+E = Export | Ctrl+Z = Undo - - - - - Endpoints: - GET /api/paper/documents | POST /api/paper/save | POST /api/paper/ai/continue | POST /api/paper/ai/improve | GET /api/paper/export/{format} - - - diff --git a/docs/src/assets/suite/paper-screen.svg b/docs/src/assets/suite/paper-screen.svg deleted file mode 100644 index c3306d5e..00000000 --- a/docs/src/assets/suite/paper-screen.svg +++ /dev/null @@ -1,209 +0,0 @@ - - - - - - - - - - - Paper - AI Writing Assistant - - - - - - - - - - - - + New Document - - - - - RECENT DOCUMENTS - - - - 📄 - Project Proposal - Edited 2 min ago - - - - 📄 - Meeting Notes - Edited yesterday - - - - 📄 - Q4 Report Draft - Edited Mar 14 - - - - 📄 - Blog Post Ideas - Edited Mar 12 - - - - - - TEMPLATES - - - 📝 - Blank Document - - - - 📋 - Meeting Notes - - - - 📊 - Report - - - - 📧 - Email Draft - - - - - - - - - - - - - - B - - - I - - - U - - - - - - Heading ▾ - - - - - - - - - - - - - - - 🔗 - - - 🖼 - - - - - - ✨ AI Assist - - - - - - - - - Project Proposal - Last edited 2 minutes ago • Auto-saved - - - - - Executive Summary - - This proposal outlines a comprehensive strategy for improving - our customer engagement platform. The project aims to increase - user retention by 25% and reduce support tickets by 40%. - - Key Objectives - - • Redesign the onboarding experience for new users - • Implement AI-powered customer support chatbot - • Create personalized dashboard for each user segment - • Integrate analytics tracking for better insights| - - - - - - - - - ✨ AI Suggestion - Consider adding a timeline section to outline project milestones - and deliverables. This helps stakeholders understand the scope. - - - - Insert - - - Dismiss - - - Regenerate - - - - - - 324 words • 1,847 characters • Reading time: 2 min - Ctrl+S Save | Ctrl+B Bold | Ctrl+I Italic | Ctrl+K Link - - diff --git a/docs/src/assets/suite/player-flow.svg b/docs/src/assets/suite/player-flow.svg deleted file mode 100644 index 001984e7..00000000 --- a/docs/src/assets/suite/player-flow.svg +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - Player - Media Viewer Flow - - - - - - - 🎬 Player - quarterly-report.pptx - - - - - 📊 - Slide 3 of 12 - Q4 Revenue Overview - - - - - - - - - - - - - - - - - - - - - - - - - - - 3 / 12 - - - - 🔍 - - - - - - - - - - Supported - - 📄 PDF - 📊 PPTX - 🎬 MP4 - 🎵 MP3 - 🖼️ PNG - 📝 DOCX - - - - Open From - - 💬 Chat - - - 📁 Drive - - - 🔗 Direct URL - - - - - Shortcuts - - Space: Play/Pause - ← →: Navigate - F: Fullscreen - ↑ ↓: Volume - Esc: Close - +/-: Zoom - - - Unified viewer for documents, presentations, audio, video, and images - diff --git a/docs/src/assets/suite/player-screen.svg b/docs/src/assets/suite/player-screen.svg deleted file mode 100644 index 519b1ded..00000000 --- a/docs/src/assets/suite/player-screen.svg +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - Player - Media Viewer - - - - - - - - - - - - - Q4 2024 Business Review - Strategic Initiatives and Key Metrics - - - • Revenue grew 23% year-over-year - • Customer satisfaction score: 94% - • New product launches: 3 - • Market expansion into APAC region - - - - Revenue Trend - - - - - - - - Q1 - Q2 - Q3 - Q4 - - - - - 5 / 12 - - - - - - - - - - - - - - - - - - - - - - - 2:34 - - - - 5:48 - - - - - - - 🔊 - - - - - - - - - - - - - - - Playlist - 12 slides • 5:48 total - - - - - - - - 1 - Title Slide - 0:00 - - - - - - - 2 - Agenda - 0:30 - - - - - - - 3 - Overview - 1:15 - - - - - - - 4 - Metrics - 1:58 - - - - - - - 5 - Q4 Review - ▶ Playing - - - - - - - 6 - Roadmap - 3:20 - - - - + 6 more slides - - - - - Space = Play/Pause | ← → = Navigate | F = Fullscreen | M = Mute - - diff --git a/docs/src/assets/suite/research-flow.svg b/docs/src/assets/suite/research-flow.svg deleted file mode 100644 index 32693d11..00000000 --- a/docs/src/assets/suite/research-flow.svg +++ /dev/null @@ -1,307 +0,0 @@ - - - - - - - - - - - - - - - - - Research - AI Search Flow - Multi-source intelligent search with AI-powered synthesis and citations - - - Query - Sources - AI Processing - Results - - - - - - - - Search Query - Natural language - - - - - - Quick - Fast mode - - - - - - Deep - Thorough - - - - - - Filters - Date, type, source - - - - - - Search History - Recent queries - - - - - - Data Sources - Multi-source search - - - - - - Web - Internet - - - - - - KB - Internal - - - - - - Docs - Drive files - - - - - - APIs - External - - - - - - News - RSS feeds - - - - - - Papers - Academic - - - - - - AI Processing ✨ - LLM synthesis - - - - - - RAG Pipeline - Vector retrieval - - - - - - Synthesis - Combine sources - - - - - - Fact Check - Verify claims - - - - - - Results - AI-generated answer - - - - - - Summary - Concise answer - - - - - - Citations - Source links - - - - - - Save to Collection - Bookmark research - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Ask Question - Natural language - - Search Sources - Multi-source lookup - - AI Synthesis - Combine and verify - - Get Answer - Cited summary - - - - - Search Modes: - - - Quick - Fast answers from cache - - - Deep - Thorough multi-source search - - - RAG - Knowledge base retrieval - - - Verified - Fact-checked answers - - - - - Shortcuts: - / = Focus search | Enter = Search | Ctrl+D = Deep mode | Ctrl+S = Save | Ctrl+C = Copy answer | ↑↓ = Navigate results - - - - - Endpoints: - POST /api/research/search | GET /api/research/sources | POST /api/research/deep | GET /api/research/collections | POST /api/research/save - - - diff --git a/docs/src/assets/suite/research-screen.svg b/docs/src/assets/suite/research-screen.svg deleted file mode 100644 index cb8ff8ba..00000000 --- a/docs/src/assets/suite/research-screen.svg +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - - - - Research - AI-Powered Search - - - - - - - - - 🔍 - How does machine learning work in recommendation systems? - - - Search - - - - - - All - - - Articles - - - Papers - - - Web - - - Videos - - 23 results • 1.2s - - - - - - ✨ AI Summary - - Machine learning powers recommendation systems through several key techniques: - - • Collaborative filtering analyzes user behavior patterns to find similar users - • Content-based filtering matches item attributes to user preferences - • Deep learning models can capture complex non-linear relationships - - Based on 5 sources - - - - - - - Understanding Recommendation Systems: A Complete Guide - ml-guide.com • Published 2024 - A comprehensive overview of how modern recommendation systems - leverage machine learning algorithms to personalize content... - - - Article - - - - - - Collaborative Filtering vs Content-Based: A Comparison - research.ai • IEEE 2023 - This paper compares the effectiveness of collaborative filtering and - content-based approaches in various recommendation scenarios... - - - Paper - - - - - - - Sources (5) - - - - ML Guide - ml-guide.com - - - - - - - IEEE Research - ieee.org - - - - - - - ArXiv Paper - arxiv.org - - - - - - - Medium Article - medium.com - - - - - - - + Add Source - - - - - Enter = Search | Tab = Next result | S = Save | E = Export citations - - diff --git a/docs/src/assets/suite/sources-flow.svg b/docs/src/assets/suite/sources-flow.svg deleted file mode 100644 index 48b576ec..00000000 --- a/docs/src/assets/suite/sources-flow.svg +++ /dev/null @@ -1,302 +0,0 @@ - - - - - - - - - - - - - - - - - Sources - Prompts & Templates Management - Manage AI prompts, bot templates, news feeds, MCP servers, LLM tools, and models - - - Source Types - Browse - Configure - Deploy - - - - - - - - Tab Navigation - 6 resource categories - - - - - - Prompts - AI prompts - - - - - - Templates - .gbai bots - - - - - - News - RSS feeds - - - - - - MCP - Servers - - - - - - Tools - LLM tools - - - - - - Models - AI models - - - - - - Browse Items - Grid/List view - - - - - - Search - Filter by name/tag - - - - - - Categories - CRM, HR, Support... - - - - - - Preview - Quick look - - - - - - Configure - Customize settings - - - - - - Edit Content - Modify prompts - - - - - - Parameters - API keys, config - - - - - - Test - Try before deploy - - - - - - Deploy - Activate resources - - - - - - Install Template - Create new bot - - - - - - Activate - Enable in system - - - - - - Monitor - Usage stats - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Select Tab - Choose resource type - - Browse - Search and explore - - Configure - Customize settings - - Deploy - Activate resource - - - - - Resource Types: - - - Prompts - Reusable AI instructions - - - Templates - Ready-made .gbai bots - - - News - RSS/Atom feeds - - - MCP - Model servers - - - Tools - LLM capabilities - - - Models - - - - - Categories: - CRM | HR | Compliance | Support | Sales | Marketing | Finance | Legal | IT | Custom - - - - - Endpoints: - GET /api/sources/{type} | POST /api/sources/install | GET /api/templates | POST /api/prompts | GET /api/models - - - diff --git a/docs/src/assets/suite/sources-screen.svg b/docs/src/assets/suite/sources-screen.svg deleted file mode 100644 index 38a67a42..00000000 --- a/docs/src/assets/suite/sources-screen.svg +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - Sources - Prompts & Templates - - - - - - - - - - - - + New Source - - - - - CATEGORIES - - - - 📚 - All Sources - 24 - - - - 💬 - Prompts - 12 - - - - 📄 - Templates - 8 - - - - 🔗 - Integrations - 4 - - - - - Favorites - 6 - - - - - - TAGS - - - - customer - - - - - sales - - - - - support - - - - - technical - - - - - - All Sources - 24 items • Manage your prompts and templates - - - - - - 🔍 - Search sources... - - - - - - - - - - 💬 - Customer Support - Handle support inquiries - with empathy and clarity - - prompt - - - - - 📝 - Email Template - Professional email - response format - - template - - - - - 🤖 - Sales Assistant - Product recommendations - and pricing help - - prompt - - - - - - - - 📊 - Report Generator - Create structured - analysis reports - - template - - - - - 🔗 - CRM Integration - Connect with your - CRM system - - integration - - - - - 🎯 - FAQ Bot - Automated answers - for common questions - - prompt - - - - - - - - ✍️ - Content Writer - Blog posts and - marketing copy - - prompt - - - - - 📋 - Meeting Notes - Structured meeting - summary template - - template - - - - - - + - Add New Source - Create from scratch - - - - - Click to edit | Del = Delete | D = Duplicate | Enter = Use in chat - - diff --git a/docs/src/assets/suite/suite-layout.svg b/docs/src/assets/suite/suite-layout.svg deleted file mode 100644 index 1e741a52..00000000 --- a/docs/src/assets/suite/suite-layout.svg +++ /dev/null @@ -1,136 +0,0 @@ - - - - - Suite - Full Desktop Layout - - - - - - - - - 🤖 General Bots - - - - 🔍 Search or ask anything... - - - 🔔 - ⚙️ - 🌙 - - - - ⋮⋮⋮ - - - - - - - 👤 - John Doe - john@company.com - - - - 💬 - Chat - - - 📁 - Drive - - - - Tasks - - - - Mail - - - 📅 - Calendar - - - 🎥 - Meet - - - MORE APPS - - - 📝 - Paper - - - 🔍 - Research - - - - - - 💬 Chat - - - - - 🤖 Bot - Hello! How can I help you today? - - - What meetings do I have today? - - - 🤖 Bot - You have 2 meetings scheduled: - • 2:00 PM - Team Standup (30 min) - - - - 📊 Tasks - - - 📧 Check mail - - - 📅 Schedule - - - - Type your message... - 🎤 - - - - - ● Connected - Alt+1: Chat | Alt+2: Drive | Alt+3: Tasks | Alt+4: Mail - - - - Desktop >1024px - - - Tablet 768px - - - Mobile <768 - diff --git a/docs/src/assets/suite/suite-screen.svg b/docs/src/assets/suite/suite-screen.svg deleted file mode 100644 index e1fe6af8..00000000 --- a/docs/src/assets/suite/suite-screen.svg +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - Suite - Main Interface - - - - - - - - - - - GB - General Bots - - - - - - ☀️ - Light - - - - - - - - - - - - - JD - - - - - - - Applications - - - - - - - - 💬 - Chat - - - - - 📁 - Drive - - - - - - Tasks - - - - - - - - Mail - - - - - 📅 - Calendar - - - - - 🎥 - Meet - - - - - - - 📝 - Paper - - - - - 🔍 - Research - - - - - 📊 - Analytics - - - - - - - - - - - Connected - - - - - - - AI Assistant - Hello! How can I help you today? - - - - What's on my calendar for today? - - - - AI Assistant - You have 2 meetings today: - • 2:00 PM - Team Standup - • 4:00 PM - Project Review - - - - - - 📧 Check email - - - ✓ My tasks - - - 📁 Recent files - - - - - - Message... - - - 🎤 - - - - - - - - - - - - Enter = Send | Shift+Enter = New line | / = Commands | @ = Mention - - diff --git a/docs/src/assets/suite/tasks-flow.svg b/docs/src/assets/suite/tasks-flow.svg deleted file mode 100644 index 12f5a2ec..00000000 --- a/docs/src/assets/suite/tasks-flow.svg +++ /dev/null @@ -1,280 +0,0 @@ - - - - - - - - - - - - - - - - Tasks - To-Do Management Flow - Create, organize, and track your tasks with categories and priorities - - - Create - Organize - Track - Complete - - - - - - - - Add Task - - - - - What needs to be done? - - - - Category - - - Due Date - - - - - - Filter Tabs - - - - All - - - Active - - - Done - - - Priority - - - - - - Categories - - - Work - - - Personal - - - Shopping - - - Health - - - Custom - - - - - - Task List - - - - - Review report - - - - Call client - - - - Update docs - - - - - Send email - - - - - - Stats - - - - - 12 - Total - - - 5 - Active - - - 7 - Completed - - - 2 - Overdue - - - - - - - - - - - - - - - - - - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - Add Task - Enter description - - Categorize - Set priority & date - - Track - View & filter tasks - - Complete - Check off done - - - - - Priority Levels: - - - High - Must do today - - - Medium - Important - - - Low - Can wait - - - None - No deadline - - - - - Key Features: - - - Click checkbox to complete - - - Filter by status or category - - - Set due dates with calendar - - - Real-time stats dashboard - - - - - Shortcuts: - Enter = Add task | Space = Toggle complete | Delete = Remove task | Tab = Next field - - - - - Endpoints: - GET /api/tasks | POST /api/tasks | PATCH /api/tasks/:id | DELETE /api/tasks/:id - - - - - HTMX: - hx-post="/api/tasks" hx-target="#task-list" hx-swap="afterbegin" hx-on::after-request="this.reset()" - - - diff --git a/docs/src/assets/suite/tasks-screen.svg b/docs/src/assets/suite/tasks-screen.svg deleted file mode 100644 index 7b755b34..00000000 --- a/docs/src/assets/suite/tasks-screen.svg +++ /dev/null @@ -1,211 +0,0 @@ - - - - - - - - - - - Tasks - To-Do Manager - - - - - - - - - - - - + Add Task - - - - - - 📋 - All Tasks - 12 - - 📅 - Today - 5 - - 📆 - Upcoming - 8 - - - Important - 3 - - - Completed - 24 - - - - - PROJECTS - - - - Work - - - - - Personal - - - - - Learning - - - - - - All Tasks - 12 tasks, 5 due today - - - - - Filter ▾ - - - Sort ▾ - - - - - - - - - Add a new task... - - - - - - - - - - Complete quarterly report - - Work - Today - - - - - - - - - Review pull request #234 - - Work - Today - - - - - - - - - Prepare presentation slides - - Work - Tomorrow - - - - - - - - - Read documentation updates - - Learning - Mar 20 - - - - - - - - - Update team meeting notes - - Work - Completed - - - - - - - - - Schedule dentist appointment - - Personal - Completed - - - - - - - Enter = Add task | Space = Toggle complete | Del = Delete | S = Star - - diff --git a/docs/src/assets/technical-specs.svg b/docs/src/assets/technical-specs.svg deleted file mode 100644 index ef5e9f39..00000000 --- a/docs/src/assets/technical-specs.svg +++ /dev/null @@ -1,146 +0,0 @@ - - - - - System Technical Specifications - - - - - - - - Embedding Configuration - - Model: bge-small-en-v1.5-f32.gguf - • Dimensions: 384 - • Format: GGUF (quantized) - • Server: localhost:8082 - • Memory: ~200MB loaded - - - - - - LLM Configuration - - Model: DeepSeek-R1-Distill-Qwen-1.5B - • Context Size: 4096 tokens - • Max Predict: 1024 tokens - • Parallel Requests: 6 - • Quantization: Q3_K_M - - - - - - Performance Characteristics - - - Vector Index: HNSW Algorithm - • M=16, ef_construction=200 - • Distance: Cosine Similarity - • Build: ~1000 docs/minute - - - Chunking Strategy - • Chunk Size: 512 tokens - • Overlap: 50 tokens - • Prompt Compact: Level 4 - - - Runtime Metrics - • Query Latency: <50ms p99 - • Memory: ~1GB/million chunks - • Cache TTL: 3600 seconds - - - - - diff --git a/docs/src/assets/wa-chat.css b/docs/src/assets/wa-chat.css deleted file mode 100644 index c399c390..00000000 --- a/docs/src/assets/wa-chat.css +++ /dev/null @@ -1,209 +0,0 @@ -/** - * WhatsApp-style Chat Conversation CSS - * - * Standard styling for conversation examples in General Bots documentation. - * Include this CSS in your mdBook or HTML output to style
elements. - * - * Usage: - * - */ - -/* ============================================ - Chat Container - ============================================ */ -.wa-chat { - background-color: #e5ddd5; - border-radius: 8px; - padding: 20px 15px; - margin: 20px 0; - max-width: 500px; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; - font-size: 14px; -} - -/* Dark mode support */ -@media (prefers-color-scheme: dark) { - .wa-chat { - background-color: #0b141a; - } -} - -/* ============================================ - Message Container - ============================================ */ -.wa-message { - margin-bottom: 10px; -} - -.wa-message:last-child { - margin-bottom: 0; -} - -/* User messages align right */ -.wa-message.user { - text-align: right; -} - -/* ============================================ - Message Bubbles - ============================================ */ -.wa-bubble { - padding: 8px 12px; - border-radius: 8px; - box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13); - max-width: 85%; - display: inline-block; - text-align: left; -} - -/* Bot bubble - white/light */ -.wa-message.bot .wa-bubble { - background-color: #fff; -} - -/* User bubble - green (WhatsApp style) */ -.wa-message.user .wa-bubble { - background-color: #dcf8c6; -} - -/* Dark mode bubbles */ -@media (prefers-color-scheme: dark) { - .wa-message.bot .wa-bubble { - background-color: #202c33; - } - - .wa-message.user .wa-bubble { - background-color: #005c4b; - } -} - -/* ============================================ - Message Text - ============================================ */ -.wa-bubble p { - margin: 0 0 4px 0; - line-height: 1.4; - color: #303030; -} - -.wa-bubble p:last-of-type { - margin-bottom: 0; -} - -/* Bold text in messages */ -.wa-bubble strong { - font-weight: 600; -} - -/* Dark mode text */ -@media (prefers-color-scheme: dark) { - .wa-bubble p { - color: #e9edef; - } -} - -/* ============================================ - Timestamp - ============================================ */ -.wa-time { - font-size: 11px; - color: #8696a0; - text-align: right; - margin-top: 4px; -} - -/* ============================================ - Special Elements - ============================================ */ - -/* Links in messages */ -.wa-bubble a { - color: #00a884; - text-decoration: none; -} - -.wa-bubble a:hover { - text-decoration: underline; -} - -/* Code in messages */ -.wa-bubble code { - background-color: rgba(0, 0, 0, 0.05); - padding: 2px 4px; - border-radius: 3px; - font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; - font-size: 13px; -} - -@media (prefers-color-scheme: dark) { - .wa-bubble code { - background-color: rgba(255, 255, 255, 0.1); - } -} - -/* Action buttons in messages */ -.wa-bubble .wa-action { - display: inline-block; - background-color: #e8f4fd; - color: #4a90e2; - padding: 4px 10px; - border-radius: 4px; - font-size: 12px; - margin: 4px 4px 0 0; - cursor: pointer; -} - -.wa-bubble .wa-action:hover { - background-color: #d0e8fc; -} - -@media (prefers-color-scheme: dark) { - .wa-bubble .wa-action { - background-color: #1a3a4a; - color: #00d4ff; - } - - .wa-bubble .wa-action:hover { - background-color: #2a4a5a; - } -} - -/* ============================================ - Variants - ============================================ */ - -/* Full-width variant */ -.wa-chat.wa-full-width { - max-width: 100%; -} - -/* Compact variant (less padding) */ -.wa-chat.wa-compact { - padding: 12px 10px; -} - -.wa-chat.wa-compact .wa-message { - margin-bottom: 6px; -} - -.wa-chat.wa-compact .wa-bubble { - padding: 6px 10px; -} - -/* No-time variant (hide timestamps) */ -.wa-chat.wa-no-time .wa-time { - display: none; -} diff --git a/docs/src/chapter-01/README.md b/docs/src/chapter-01/README.md deleted file mode 100644 index 8067b635..00000000 --- a/docs/src/chapter-01/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Chapter 01: Run and Talk - -Get General Bots running in 5 minutes. - -## What You'll Learn - -- How to start General Bots -- Your first conversation -- How sessions work -- Basic bot interaction - -## Quick Start - -Download and run: -```bash -./botserver -``` - -That's it. Everything installs automatically on first run. - -## What Happens - -1. **Auto-Bootstrap**: Installs PostgreSQL, cache, storage, and LLM -2. **Load Bots**: Finds `.gbai` folders and loads them -3. **Start Server**: Opens on `http://localhost:8080` -4. **Ready**: Talk to your bot - -## First Conversation - -Open browser, type a message, get a response. Simple. - -## Topics Covered - -- [Overview](./overview.md) - What General Bots does -- [Quick Start](./quick-start.md) - Get running fast -- [Installation](./installation.md) - Detailed setup options -- [First Conversation](./first-conversation.md) - Using your bot -- [Sessions](./sessions.md) - How conversations are managed - ---- - -
- General Bots -
\ No newline at end of file diff --git a/docs/src/chapter-01/assets/bootstrap-process.svg.backup b/docs/src/chapter-01/assets/bootstrap-process.svg.backup deleted file mode 100644 index c6d760d8..00000000 --- a/docs/src/chapter-01/assets/bootstrap-process.svg.backup +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Auto-Bootstrap Process - - - - ./botserver - - - - - - - Detect System - (Linux/Mac) - - - - - - - Auto-Bootstrap Process - - - - - - PostgreSQL - 16.2 - ✓ Install - ✓ Configure - ✓ Migrate - - - - Valkey - Cache - ✓ Install - ✓ Configure - ✓ Start - - - - SeaweedFS - Storage - ✓ Install - ✓ Configure - ✓ Start - - - - Qdrant - Vectors - ✓ Install - ✓ Configure - ✓ Start - - - - - LLM Models (Optional) - ✓ Download BGE embeddings - ✓ Download Llama model (if local) - - - - - - - Generate .env file - • Secure passwords - • Connection URLs - • Port assignments - - - - - - - Load Templates - • Scan .gbai dirs - • Create bots - • Index documents - - - - - - - Start Web Server - localhost:8080 - - - - - \ No newline at end of file diff --git a/docs/src/chapter-01/assets/quick-start-bootstrap.svg.backup b/docs/src/chapter-01/assets/quick-start-bootstrap.svg.backup deleted file mode 100644 index b01ddcad..00000000 --- a/docs/src/chapter-01/assets/quick-start-bootstrap.svg.backup +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Bootstrap Flow - - - - ./botserver - (first run) - - - - - - - OS Detection - Linux/Mac/Windows - - - - - - - Component Installation - - - - - - PostgreSQL - 16.2 - - - - Valkey - Cache - - - - SeaweedFS - Storage - - - - Qdrant - Vectors - - - - - - - - - - - - - - - - - - Configuration & Setup - - - • Generate credentials - • Create .env file - • Initialize databases - • Create storage buckets - - - - - - - - Bot Deployment - - - - Scan templates/ directory - - - - - - Load .gbai packages - • default.gbai - • announcements.gbai - - - - - - Upload to object storage - Index documents • Register in database - - - - - - - Start Web Server - http://localhost:8080 - - - - - \ No newline at end of file diff --git a/docs/src/chapter-01/assets/session-manager.svg.backup b/docs/src/chapter-01/assets/session-manager.svg.backup deleted file mode 100644 index f4eb2ff3..00000000 --- a/docs/src/chapter-01/assets/session-manager.svg.backup +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Session Manager Architecture - - - - User Input - - - - Bot Response - - - - - - - - WebSocket - /HTTP - - - WebSocket - /HTTP - - - - - - - - Session Manager - - - - 1. Validate Token - 2. Load Session - 3. Update State - - 4. Execute BASIC - 5. Generate Response - 6. Save History - - - - - - - - - Valkey - (Cache) - - - PostgreSQL - (Persist) - - - - Sync Every - Message - - - - - 1 - - - 2 - - - 3 - - - 4 - - - 5 - - - - - - Key Features - - - • Real-time WebSocket support - • Automatic session persistence - • Redis-compatible caching - • ACID compliance - - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-01/assets/session-states.svg.backup b/docs/src/chapter-01/assets/session-states.svg.backup deleted file mode 100644 index 0e315e11..00000000 --- a/docs/src/chapter-01/assets/session-states.svg.backup +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Session State Flow - - - - Browser - Opens - - - - - - - CREATE - New UUID - Token Gen - - - - - - - ACTIVE - Chatting - Messages - - - - - - - IDLE - No Input - 30min Timer - - - - User Returns - - - - - - - EXPIRE - 7d Anon - Never Auth - - - - Retry - - - - - - - CLEANUP - Archive - Delete - - - - Instant - Active use - 30 minutes - 7 days / Never - Permanent - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-01/assets/tool-execution-flow.svg.backup b/docs/src/chapter-01/assets/tool-execution-flow.svg.backup deleted file mode 100644 index 2380c743..00000000 --- a/docs/src/chapter-01/assets/tool-execution-flow.svg.backup +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Tool Execution Flow - How the bot understands and executes user commands - - - - 1. User Input - "I want to enroll in Computer Science" - - - - - - - 2. LLM Analyzes Intent - Detects: "enrollment request" - Natural language understanding - - - - ~100ms - - - - - - - 3. Scan Available Tools - - - - ✓ enrollment.bas - - - - - other-tools.bas - - - - - ~50ms - - - - - - - 4. Collect Parameters - - - - • Name: - (ask user) - • Email: - (ask user) - • Course: - "Computer Science" - - - - - Interactive - - - - - - - 5. Execute enrollment.bas - - - - - Save to enrollments.csv - - - - - - Generate confirmation - - - - - ~200ms - - - - - - - 6. Bot Response - "Welcome to Computer Science, John!" - - - - Instant - diff --git a/docs/src/chapter-01/first-conversation.md b/docs/src/chapter-01/first-conversation.md deleted file mode 100644 index 3302733b..00000000 --- a/docs/src/chapter-01/first-conversation.md +++ /dev/null @@ -1,193 +0,0 @@ -# First Conversation - -After BotServer starts, you can immediately start chatting with your bot. No programming required! - -## Just Start Talking - -Open your browser to `http://localhost:8080` and start chatting: - -``` -You: Hi! -Bot: Hello! How can I help you today? - -You: I want to enroll in a course -Bot: I'll help you with enrollment. Let me collect your information... - [Bot automatically calls enrollment.bas tool] - -You: What documents do you have? -Bot: [Searches .gbkb/ folders and answers from your documents] -``` - -That's it! The LLM handles everything automatically. - -## How It Works - -### Drop Documents in `.gbkb/` - -``` -mybot.gbai/ - mybot.gbkb/ - policies/ - enrollment-policy.pdf - course-catalog.pdf - faqs/ - student-faq.docx - payment-guide.txt -``` - -The bot automatically indexes all documents, creates vector embeddings, searches when users ask questions, and provides accurate answers from your content. - -### Create Tools as `.bas` Files - -Create `enrollment.bas`: - -```bas -PARAM name AS string LIKE "John Smith" DESCRIPTION "Student full name" -PARAM email AS string LIKE "john@example.com" DESCRIPTION "Contact email" -PARAM course AS string LIKE "Computer Science" DESCRIPTION "Course to enroll in" - -DESCRIPTION "Enrollment tool - collects student information and processes enrollment" - -SAVE "enrollments.csv", name, email, course, NOW() -TALK "Enrollment complete! Welcome to " + course + ", " + name -``` - -The LLM automatically discovers this tool, knows when to call it based on user intent, collects required parameters through natural conversation, and executes the tool when all information is gathered. - -### The LLM Does Everything Else - -You don't need to write IF/THEN logic, intent detection, dialog flows, state machines, or complex routing. The LLM automatically understands user intent, calls appropriate tools, searches knowledge bases, maintains conversation context, and handles follow-up questions naturally. - -## Real Example Conversation - -With `enrollment.bas` tool and course documents in `.gbkb/`: - -``` -User: Hello, I'd like to know about your computer science program - -Bot: I'd be happy to help you learn about our Computer Science program! - Based on our course catalog, the program offers a comprehensive - 4-year curriculum covering software development, algorithms, - databases, and AI. Would you like to know about specific courses - or the enrollment process? - -User: Yes, I want to enroll - -Bot: Great! I'll help you enroll in the Computer Science program. - Let me collect your information. What's your full name? - -User: John Smith - -Bot: Thank you, John. What email address should we use for contact? - -User: john.smith@gmail.com - -Bot: Perfect! I'm enrolling you in Computer Science now... - [Executes enrollment.bas tool] - Enrollment complete! Welcome to Computer Science, John Smith! - You'll receive a confirmation at john.smith@gmail.com. - -User: What are the payment options? - -Bot: [Searches payment-guide.txt from .gbkb/] - According to our payment guide, we offer three options: - 1. Full payment with 10% discount - 2. Monthly installments over 12 months - 3. Semester-based payments - Which option would you prefer? -``` - -## The Magic Formula - -Documents in `.gbkb/` combined with tools in `.bas` files and the LLM create an intelligent bot. No complex programming needed! - -## Creating Your First Bot - -Start by creating the directory structure for your bot with folders for dialog scripts, knowledge base documents, and bot configuration. Add your documents to the `.gbkb/` directory including PDFs, Word documents, text files, and Markdown files. Optionally create tools as `.bas` files to handle specific actions like processing forms or calling APIs. Then restart BotServer and start chatting. The LLM will answer questions from your documents, call your tools when appropriate, and handle the entire conversation naturally. - -```bash -mkdir -p mybot.gbai/mybot.gbdialog -mkdir -p mybot.gbai/mybot.gbkb/docs -mkdir -p mybot.gbai/mybot.gbot -``` - -Example tool in `mybot.gbdialog/my-tool.bas`: - -```bas -PARAM user_name AS string -PARAM request AS string - -DESCRIPTION "Handles user requests" - -result = CALL "/api/process", user_name, request -TALK "Done! " + result -``` - -## No Programming Required - -Traditional chatbots require complex logic with IF/THEN statements, intent detection, and multi-step dialog management. With BotServer, you simply create the tool with parameters and a description, and the LLM handles all the conversation logic automatically. - -Traditional approach (don't do this): - -```bas -' Complex multi-step dialog -IF intent = "enrollment" THEN - TALK "Let me help you enroll. What's your name?" - HEAR name - TALK "What's your email?" - HEAR email - ' ... lots more code ... -ENDIF -``` - -BotServer approach (just create the tool): - -```bas -' In enrollment.bas - becomes a tool automatically -PARAM name AS string -PARAM email AS string -DESCRIPTION "Collects enrollment information" - -SAVE "enrollments.csv", name, email -TALK "Successfully enrolled " + name -``` - -## What Can You Build? - -A customer support bot uses product manuals in `.gbkb/` and a `create-ticket.bas` tool, allowing the LLM to answer questions and create support tickets automatically. - -An HR assistant combines the employee handbook in `.gbkb/` with a `leave-request.bas` tool so the LLM can explain policies and process leave requests. - -An education platform stores course materials in `.gbkb/` and provides `enrollment.bas` and `submit-assignment.bas` tools, enabling the LLM to teach content and manage student tasks. - -A sales assistant uses product catalogs in `.gbkb/` with a `create-quote.bas` tool, allowing the LLM to answer product questions and generate quotes. - -## Advanced Features - -### Dynamic Tool Loading - -The LLM can load tools based on context. In `start.bas`, you simply specify which knowledge bases to use, and tools in `.gbdialog/` are auto-discovered. The LLM handles the conversation naturally without explicit HEAR statements. - -### Multi-Language Support - -The LLM handles multiple languages automatically. Users can write in Portuguese, Chinese, or any other language, and the bot responds appropriately in the same language. - -### Context Awareness - -The LLM maintains conversation context throughout the interaction. If a user starts to enroll but then asks about prerequisites, the bot handles the tangent and can return to the enrollment process afterward. - -## Tips for Success - -Organize documents clearly by creating folders for policies, products, FAQs, and tutorials within your `.gbkb/` directory. This helps the LLM find relevant information quickly. - -Name tools descriptively with names like `enrollment.bas`, `create-ticket.bas`, and `schedule-meeting.bas`. The LLM understands what each tool does from its name and description. - -Always add descriptions to tools using the DESCRIPTION keyword. A good description like "This tool processes student enrollment for courses" helps the LLM know when to use the tool. - -Let the LLM work without trying to control every aspect of the conversation. Allow it to rephrase responses naturally, handle unexpected questions, and maintain conversation flow on its own. - -## Next Steps - -The Quick Start guide walks you through building your first bot. The Packages chapter explains the package structure in detail. The Tool Definition documentation covers creating sophisticated tools. The Knowledge Base chapter describes document management and indexing. - -Remember: Just add documents and tools, and the LLM does the rest! \ No newline at end of file diff --git a/docs/src/chapter-01/installation.md b/docs/src/chapter-01/installation.md deleted file mode 100644 index 063ba57d..00000000 --- a/docs/src/chapter-01/installation.md +++ /dev/null @@ -1,147 +0,0 @@ -# Installation - -BotServer installs itself automatically through the bootstrap process. Just run the binary. - -## System Requirements - -| Resource | Minimum | Production | -|----------|---------|------------| -| **OS** | Linux, macOS, Windows | Linux (Ubuntu/Debian) | -| **RAM** | 4GB | 16GB+ | -| **Disk** | 10GB | 100GB SSD | -| **CPU** | 1 core | 2+ cores | -| **GPU** | None | RTX 3060+ (12GB VRAM) for local LLM | - -## Quick Start - -```bash -./botserver -``` - -The bootstrap process automatically: -1. Detects your system (OS/architecture) -2. Creates `botserver-stack/` directory structure -3. Downloads PostgreSQL, Drive, Cache, LLM server -4. Initializes database and storage -5. Deploys default bot -6. Starts all services - -**First run takes 2-5 minutes.** - -## Environment Configuration - -The `.env` file is **auto-generated** with secure random credentials: - -```bash -DATABASE_URL=postgres://gbuser:RANDOM@localhost:5432/botserver -DRIVE_SERVER=http://localhost:9000 -DRIVE_ACCESSKEY=GENERATED_KEY -DRIVE_SECRET=GENERATED_SECRET -``` - -### Using Existing Services - -Point to your own infrastructure in `.env`: - -```bash -DATABASE_URL=postgres://myuser:mypass@myhost:5432/mydb -DRIVE_SERVER=http://my-drive:9000 -``` - -## Default Ports - -| Service | Port | Config Key | -|---------|------|------------| -| UI Server | 8080 | `server-port` | -| PostgreSQL | 5432 | `DATABASE_URL` | -| Drive API | 9000 | `DRIVE_SERVER` | -| Drive Console | 9001 | - | -| LLM Server | 8081 | `llm-server-port` | -| Embedding | 8082 | `embedding-url` | -| Cache | 6379 | Internal | - -## Verify Installation - -```bash -# Check services -./botserver status - -# Test database -psql $DATABASE_URL -c "SELECT version();" - -# Test LLM -curl http://localhost:8081/v1/models - -# Open UI -open http://localhost:8080 -``` - -## Bot Deployment - -Bots deploy to object storage (not local filesystem): - -```bash -mybot.gbai → creates 'mybot' bucket in drive -``` - -The `work/` folder is for internal use only. - -### S3 Sync for Development - -Use S3-compatible tools for local editing: -- **Cyberduck** (GUI) -- **rclone** (CLI) -- **WinSCP** (Windows) - -```bash -# rclone sync example -rclone sync ./mybot.gbai drive:mybot --watch -``` - -Edits sync automatically - changes reload without restart. - -## Memory Optimization - -For limited RAM systems: - -```csv -name,value -llm-server-ctx-size,2048 -llm-server-parallel,2 -``` - -Use quantized models (Q3_K_M, Q4_K_M) for smaller memory footprint. - -## GPU Setup - -For GPU acceleration: - -```csv -name,value -llm-server-gpu-layers,35 -``` - -Requires CUDA installed and 12GB+ VRAM. - -## Deployment Options - -| Method | Use Case | Guide | -|--------|----------|-------| -| **Local** | Development, single instance | This page | -| **Docker** | Production, microservices | [Docker Deployment](../chapter-07-gbapp/docker-deployment.md) | -| **LXC** | Isolated components, Linux | [Container Deployment](../chapter-07-gbapp/containers.md) | - -## Troubleshooting - -| Issue | Solution | -|-------|----------| -| Database connection | Check `DATABASE_URL`, verify PostgreSQL running | -| Port conflict | Change port in config or stop conflicting service | -| Memory issues | Reduce `llm-server-ctx-size`, use quantized model | -| GPU not detected | Verify CUDA, set `llm-server-gpu-layers,0` for CPU | - -## Next Steps - -- [Quick Start Guide](./quick-start.md) - Create your first bot -- [First Conversation](./first-conversation.md) - Test your bot -- [Configuration Reference](../chapter-08-config/README.md) - All settings \ No newline at end of file diff --git a/docs/src/chapter-01/overview.md b/docs/src/chapter-01/overview.md deleted file mode 100644 index ff3efcfa..00000000 --- a/docs/src/chapter-01/overview.md +++ /dev/null @@ -1,178 +0,0 @@ -# Overview - -BotServer is an open-source conversational AI platform built in Rust that enables developers to create, deploy, and manage intelligent bots with minimal configuration. This chapter provides a comprehensive introduction to the platform's architecture, capabilities, and design philosophy. - - -## Core Philosophy - -BotServer was designed around five guiding principles that shape every aspect of the platform. Zero Configuration means the system works out of the box with sensible defaults, eliminating lengthy setup processes. The Package-Based approach ensures bots are self-contained in `.gbai` folders that can be copied and deployed anywhere. BASIC Scripting provides simple, accessible programming for conversation flows that non-programmers can understand and modify. Multi-Channel support means you deploy once and run everywhere across Web, WhatsApp, Teams, and other platforms. Knowledge-First design provides built-in document management and semantic search as core capabilities rather than afterthoughts. - - -## Architecture Overview - -BotServer uses a modular architecture organized into three distinct layers that work together to provide a complete conversational AI platform. - -### Storage Layer - -The storage layer handles all data persistence needs. The SQL database stores structured data including users, sessions, and configurations using PostgreSQL with the Diesel ORM. Object storage provides S3-compatible file storage for documents and uploads, typically using MinIO for self-hosted deployments. The high-performance cache layer handles sessions and frequently accessed data using a Redis-compatible store. An optional vector database enables semantic search capabilities for knowledge bases using Qdrant or similar vector stores. - -### Application Layer - -The application layer contains the core bot functionality. The Bot Engine processes conversations and manages state across interactions. The BASIC Interpreter executes conversation scripts written in the General Bots dialect of BASIC. The Package Manager handles bot deployment, lifecycle management, and hot-reloading of changes. Channel Adapters connect to various messaging platforms, translating between platform-specific formats and the internal message representation. - -### Service Layer - -The service layer provides the infrastructure that supports bot operations. The UI Server handles HTTP API requests and WebSocket connections for real-time chat interfaces. The Scheduler executes cron-based tasks for automation and maintenance. LLM Integration connects to language models whether hosted locally or in the cloud. Authentication integrates with directory services for user management and access control. - - -## Key Features - -### Conversation Management - -BotServer provides comprehensive conversation management capabilities. Sessions persist across interactions, maintaining context and state throughout multi-turn dialogs. The context management system tracks conversation history and user information across interactions. Parallel conversation handling allows a single bot instance to manage thousands of simultaneous conversations efficiently. - -### Knowledge Base System - -The knowledge base system turns your documents into searchable, AI-accessible information. Document ingestion supports PDF, TXT, MD, and DOCX formats with automatic text extraction. The indexing pipeline processes documents into searchable chunks stored in the vector database. Semantic search finds relevant information based on meaning rather than just keyword matching. Context injection automatically provides relevant document excerpts to the LLM when generating responses. - -### BASIC Scripting Language - -The BASIC scripting language makes bot development accessible to everyone. The simple syntax allows non-programmers to read and modify conversation flows. Built-in keywords handle common tasks like sending messages, saving data, and calling APIs. The tool integration system lets you create callable functions that the AI can invoke automatically. Event-driven programming support enables reactive bots that respond to schedules, webhooks, and system events. - -### Multi-Channel Support - -Deploy your bot once and reach users across multiple channels. The web chat interface provides an embeddable widget for websites. WhatsApp Business API integration enables customer service on the world's most popular messaging platform. Microsoft Teams support brings your bot into enterprise collaboration spaces. Email integration allows conversational interactions through traditional email. SMS support via providers enables text message interactions for users without data connectivity. - -### Enterprise Features - -BotServer includes capabilities required for enterprise deployments. Multi-tenancy support allows a single installation to serve multiple organizations with complete isolation. Role-based access control restricts actions based on user roles and permissions. Comprehensive audit logging tracks all actions for compliance and debugging. Horizontal scaling distributes load across multiple instances. High availability configurations ensure continuous operation even during failures. - - -## System Requirements - -### Minimum Requirements - -For development and testing purposes, BotServer runs comfortably on modest hardware. You need at least 4GB of RAM to run all components. A single CPU core is sufficient for light workloads. Reserve at least 10GB of disk space for the application, databases, and documents. The platform runs on Linux, macOS, or Windows operating systems. - -### Recommended for Production - -Production deployments benefit from more substantial resources. Plan for 16GB of RAM to handle concurrent users and large knowledge bases. Two or more CPU cores improve response times under load. Use 100GB of SSD storage for better database and file access performance. Linux servers running Ubuntu or Debian provide the most tested and reliable environment. For local LLM hosting, an NVIDIA RTX 3060 or better GPU with at least 12GB of VRAM enables on-premises inference without cloud API dependencies. - - -## Configuration - -Bot configuration uses `config.csv` files with key-value parameters. Server settings like `server_host` and `server_port` control where the UI server listens. LLM configuration through `llm-url` and `llm-model` specifies which language model to use. Email settings including `email-from` and `email-server` enable outbound email functionality. UI customization parameters like `theme-color1`, `theme-color2`, `theme-title`, and `theme-logo` brand the interface. Conversation settings such as `episodic-memory-history` and `episodic-memory-threshold` tune how context is managed. Refer to the config.csv files in bot packages for the complete list of available parameters. - - -## Bot Package Structure - -Each bot is a self-contained `.gbai` folder that includes everything needed for deployment. The structure organizes different aspects of the bot into subfolders with specific naming conventions. - -``` -mybot.gbai/ - mybot.gbot/ - config.csv - mybot.gbdialog/ - start.bas - tools/ - mybot.gbkb/ - documents/ - mybot.gbtheme/ - styles/ -``` - -The `.gbot` subfolder contains configuration files including the main `config.csv`. The `.gbdialog` subfolder holds BASIC scripts with `start.bas` serving as the entry point and additional scripts providing tools. The `.gbkb` subfolder stores knowledge base documents organized into topical folders. The optional `.gbtheme` subfolder contains CSS and assets for UI customization. - - -## Deployment Models - -### Standalone Server - -The standalone deployment model runs a single BotServer instance serving multiple bots. This approach provides the simplest setup with shared resources across bots. Standalone deployment works best for small to medium deployments where isolation between bots is not critical. - -### LXC Containers - -Linux containers provide lightweight virtualization for bot isolation. Each bot or group of bots runs in its own container with dedicated resources. LXC deployment offers easy management through standard container tooling while maintaining lower overhead than full virtual machines. - -### Embedded Mode - -Embedded deployment integrates BotServer into existing applications as a library. This mode provides programmatic control over bot behavior and direct integration with application logic. Custom integrations can use the embedded mode to add conversational capabilities to any Rust application. - - -## Getting Started - -Installation begins by downloading and running the BotServer binary. The bootstrap process automatically downloads all required components to the `botserver-stack/` directory, including database binaries, the object storage server, cache server, LLM runtime, and other dependencies. - -Bot deployment uses object storage buckets. Each bot receives its own bucket for file storage. Bots are deployed to the drive rather than the work folder, which is reserved for internal operations as documented in the gbapp chapter. - -After startup, access the UI interface at `http://localhost:8080` to interact with your bots and monitor their operation. - - -## Use Cases - -### Customer Support - -Customer support bots automate FAQ responses and ticket handling. Load your support documentation, policies, and procedures into knowledge bases. Create tools for ticket creation and status lookup. The result is 24/7 support that handles common questions automatically while escalating complex issues to human agents. - -### Internal Tools - -Employee assistant bots streamline internal operations. Knowledge bases contain HR policies, IT guides, and company information. Tools enable leave requests, equipment orders, and other common workflows. Employees get instant answers and automated processing for routine requests. - -### Educational Applications - -Educational bots provide interactive learning experiences. Course materials and reference documents become searchable knowledge bases. Tools handle quiz administration, progress tracking, and enrollment. Students receive personalized guidance and immediate feedback. - -### Healthcare Applications - -Healthcare bots assist with patient engagement while maintaining compliance. Appointment scheduling, medication reminders, and symptom checking tools automate routine interactions. Knowledge bases contain patient education materials. All interactions maintain audit trails for regulatory compliance. - - -## Security Features - -BotServer implements comprehensive security at every layer. Authentication integrates with directory services for centralized user management. SSL/TLS encryption protects all network communications. Session tokens use cryptographically secure generation and validation. Input sanitization prevents injection attacks across all user inputs. SQL injection prevention uses parameterized queries throughout. XSS protection sanitizes output displayed to users. Rate limiting prevents abuse and denial of service attacks. Audit logging records all significant actions for compliance and forensics. - - -## Monitoring and Operations - -### Health Checks - -Health monitoring endpoints report component status for operational awareness. Database connectivity checks verify the storage layer is operational. Storage availability checks ensure object storage is accessible. Cache performance metrics track response times and hit rates. - -### Metrics - -Operational metrics provide visibility into bot performance. Conversation counts show usage patterns over time. Response time measurements identify performance issues. Error rates highlight problems requiring attention. Resource usage tracking helps capacity planning. - -### Logging - -Structured logging facilitates troubleshooting and analysis. Configurable log levels from ERROR through DEBUG control verbosity. Automatic rotation and archival prevent disk exhaustion. Search and filtering tools help locate specific events in large log files. - - -## Extensibility - -### Channel Adapters - -New messaging channels integrate through the adapter system. WebSocket protocols enable real-time bidirectional communication. REST API integration supports request-response style platforms. Custom protocols can be implemented for specialized messaging systems. - -### Storage Backends - -Storage is abstracted to support multiple backend options. S3-compatible storage works with AWS, MinIO, and other providers. Database adapters could support different SQL databases. Cache providers can be swapped while maintaining the same interface. - - -## Community and Support - -### Documentation - -Comprehensive documentation covers all aspects of the platform. The User Guide walks through common tasks and best practices. The API Reference documents all endpoints and parameters. The BASIC Language Reference details every keyword and syntax rule. The Deployment Guide covers production installation and configuration. - -### Resources - -Example bots in the `templates/` directory demonstrate common patterns. Test suites verify functionality and provide usage examples. Migration tools help transition from other platforms to General Bots. - -### Contributing - -General Bots is open source under the AGPL (GNU Affero General Public License). The GitHub repository hosts all development activity. Issue tracking manages bug reports and feature requests. Pull requests from the community are welcome and encouraged. - - -## Summary - -BotServer provides a complete platform for building conversational AI applications. The combination of simple BASIC scripting, automatic setup, and enterprise features bridges the gap between simple chatbots and complex AI systems. The focus on packages, minimal configuration, and multi-channel support makes BotServer suitable for both rapid prototyping and production deployments serving millions of users. \ No newline at end of file diff --git a/docs/src/chapter-01/quick-start.md b/docs/src/chapter-01/quick-start.md deleted file mode 100644 index 7e0b06ce..00000000 --- a/docs/src/chapter-01/quick-start.md +++ /dev/null @@ -1,357 +0,0 @@ -# Quick Start - -## Installation in 3 Steps - -### 1. Run BotServer - -```bash -./botserver -``` - -That's it! No configuration needed. - -### 2. Wait for Bootstrap (2-5 minutes) - -You'll see: - -``` -🚀 BotServer starting... -📦 Bootstrap: Detecting system... -📦 Installing PostgreSQL... - ✓ Database created - ✓ Schema initialized - ✓ Credentials saved to .env -📦 Installing Drive... - ✓ Object storage ready - ✓ Buckets created -📦 Installing Cache... - ✓ Cache server running -🤖 Creating bots from templates... - ✓ default.gbai → Default bot - ✓ announcements.gbai → Announcements bot -✅ BotServer ready at http://localhost:8080 -``` - -### 3. Open Browser - -``` -http://localhost:8080 -``` - -Start chatting with your bot! - ---- - -## What Just Happened? - -### Bootstrap Flow - -Bootstrap Flow - -The **automatic bootstrap** process: - -1. ✅ Detected your OS (Linux/macOS/Windows) -2. ✅ Downloaded PostgreSQL database to botserver-stack/ -3. ✅ Downloaded drive (S3-compatible storage) to botserver-stack/ -4. ✅ Downloaded cache component to botserver-stack/ -5. ✅ Generated secure credentials → `.env` (from blank environment) -6. ✅ Created database schema -7. ✅ Deployed default bots to object storage -8. ✅ Started UI server on port 8080 - -**Zero manual configuration required!** - -### Using Existing Services - -If you already have PostgreSQL or drive storage running, update `.env`: - -```bash -# Point to your existing services -DATABASE_URL=postgres://myuser:mypass@myhost:5432/mydb -DRIVE_SERVER=http://my-drive:9000 -DRIVE_ACCESSKEY=my-access-key -DRIVE_SECRET=my-secret-key -``` - ---- - -## Step 2: Write a Simple Tool - -### How Tools Work - -Tool Execution Flow - -Tools are just `.bas` files. Create `enrollment.bas`: - -```bas -' Student enrollment tool -PARAM name, email, course -DESCRIPTION "Processes student enrollment" - -SAVE "enrollments.csv", name, email, course, NOW() -TALK "Welcome to " + course + ", " + name + "!" -``` - -The LLM automatically discovers this tool and knows when to call it! - ---- - -## Step 3: Add Knowledge Base - -Drop documents in a `.gbkb/` folder: - -``` -mybot.gbai/ - mybot.gbkb/ - docs/ - manual.pdf - faq.docx - guide.txt -``` - -The bot automatically: -- Indexes documents with vector embeddings -- Answers questions from the content -- Updates when files change - ---- - -## Container Deployment (LXC) - -For production isolation, BotServer supports **LXC** (Linux Containers): - -```bash -# Create container -lxc-create -n botserver -t download -- -d ubuntu -r jammy -a amd64 - -# Start and attach -lxc-start -n botserver -lxc-attach -n botserver - -# Install BotServer inside container -./botserver -``` - -**Benefits**: -- ✅ Process isolation -- ✅ Resource control -- ✅ Easy management -- ✅ Lightweight virtualization - ---- - - - -## Optional Components - -After installation, add more features: - -```bash -./botserver install email # Email server -./botserver install directory # Identity provider -./botserver install llm # Local LLM server (offline mode) -./botserver install meeting # Video conferencing -``` - ---- - -## Example Bot Structure - -``` -mybot.gbai/ - mybot.gbdialog/ # Dialog scripts - start.bas # Entry point (required) - get-weather.bas # Tool (auto-discovered) - send-email.bas # Tool (auto-discovered) - mybot.gbkb/ # Knowledge base - docs/ # Document collection - faq/ # FAQ collection - mybot.gbot/ # Configuration - config.csv # Bot parameters - mybot.gbtheme/ # UI theme (optional) - custom.css -``` - -Deploy new bots by uploading to object storage (creates a new bucket), not the local filesystem. The `work/` folder is for internal use only. - -### Local Development with Auto-Sync - -Edit bot files locally and sync automatically to drive storage: - -**Free S3 Sync Tools:** -- **Cyberduck** - GUI file browser (Windows/Mac/Linux) -- **rclone** - Command-line sync (All platforms) -- **WinSCP** - File manager with S3 (Windows) -- **S3 Browser** - Freeware S3 client (Windows) - -**Quick Setup with rclone:** -```bash -# Configure for drive storage -rclone config # Follow prompts for S3-compatible storage - -# Auto-sync local edits to bucket -rclone sync ./mybot.gbai drive:mybot --watch -``` - -Now when you: -- Edit `.csv` → Bot config reloads automatically -- Edit `.bas` → Scripts compile automatically -- Add docs to `.gbkb/` → Knowledge base updates - ---- - -## How It Really Works - -You DON'T write complex dialog flows. Instead: - -### 1. Add Documents -``` -mybot.gbkb/ - policies/enrollment-policy.pdf - catalog/courses.pdf -``` - -### 2. Create Tools (Optional) -```bas -' enrollment.bas - just define what it does -PARAM name AS string -PARAM course AS string -SAVE "enrollments.csv", name, course -``` - -### 3. Start Chatting! -``` -User: I want to enroll in computer science -Bot: I'll help you enroll! What's your name? -User: John Smith -Bot: [Automatically calls enrollment.bas with collected params] - Welcome to Computer Science, John Smith! -``` - -The LLM handles ALL conversation logic automatically! - ---- - -## Configuration (Optional) - -Bootstrap automatically generates `.env` from a blank environment with secure random credentials: - -```env -# Auto-generated during bootstrap -DATABASE_URL=postgres://gbuser:RANDOM_PASS@localhost:5432/botserver -DRIVE_SERVER=http://localhost:9000 -DRIVE_ACCESSKEY=GENERATED_KEY -DRIVE_SECRET=GENERATED_SECRET -``` - -You can also configure per-bot settings in `config.csv`: - -```csv -name,value -server_port,8080 -llm-url,http://localhost:8081 -episodic-memory-threshold,4 -theme-color1,#0d2b55 -``` - ---- - -## Troubleshooting - -### Port 8080 in use? - -Edit `templates/default.gbai/default.gbot/config.csv`: - -```csv -name,value -server_port,3000 -``` - -### Clean install? - -```bash -# Remove everything and start fresh -rm -rf botserver-stack/ -rm .env -./botserver # Will regenerate everything -``` - -### Check component status - -```bash -./botserver status tables # PostgreSQL -./botserver status drive # Drive storage -./botserver status cache # Cache component -``` - ---- - -## Documentation - -- **[Full Installation Guide](docs/src/chapter-01/installation.md)** - Detailed bootstrap explanation -- **[Tool Definition](docs/src/chapter-08/tool-definition.md)** - Creating tools -- **[BASIC Keywords](docs/src/chapter-05/keywords.md)** - Language reference -- **[Package System](docs/src/chapter-02/README.md)** - Creating bots -- **[Architecture](docs/src/chapter-06/architecture.md)** - How it works - ---- - -## The Magic Formula - -``` -📚 Documents + 🔧 Tools + 🤖 LLM = ✨ Intelligent Bot -``` - -### What You DON'T Need: -- ❌ IF/THEN logic -- ❌ Intent detection -- ❌ Dialog flow charts -- ❌ State machines -- ❌ Complex routing - -### What You DO: -- ✅ Drop documents in `.gbkb/` -- ✅ Create simple `.bas` tools (optional) -- ✅ Start chatting! - -The LLM understands context, calls tools, searches documents, and maintains conversation naturally. - ---- - -## Philosophy - -1. **Just Run It** - No manual configuration -2. **Simple Scripts** - BASIC-like language anyone can learn -3. **Automatic Discovery** - Tools and KBs auto-detected -4. **Secure by Default** - Credentials auto-generated -5. **Production Ready** - Built for real-world use - ---- - -## Real Example: Education Bot - -1. **Add course materials:** - ``` - edu.gbkb/ - courses/computer-science.pdf - policies/enrollment.pdf - ``` - -2. **Create enrollment tool:** - ```bas - ' enrollment.bas - PARAM name AS string - PARAM course AS string - SAVE "enrollments.csv", name, course - ``` - -3. **Just chat:** - ``` - User: What courses do you offer? - Bot: [Searches PDFs] We offer Computer Science, Data Science... - - User: I want to enroll - Bot: [Calls enrollment.bas] Let me help you enroll... - ``` - -**No programming logic needed - the LLM handles everything!** 🎉 \ No newline at end of file diff --git a/docs/src/chapter-01/sessions.md b/docs/src/chapter-01/sessions.md deleted file mode 100644 index 682c4552..00000000 --- a/docs/src/chapter-01/sessions.md +++ /dev/null @@ -1,219 +0,0 @@ -# Sessions and Channels - -Every conversation has memory. Sessions are the beating heart of BotServer because they remember who you are, what you have said, and where you left off. Even if you close your browser and come back tomorrow, your conversation continues right where it paused. - -Session Manager - - -## What Is a Session? - -A session is a persistent conversation container that tracks everything about an ongoing interaction. This includes who is talking through user identity, what has been said through message history, the current state including variables and context, any active tools and knowledge bases, and the bot configuration in use. Think of it like a phone call that can pause and resume anytime without losing the thread of conversation. - - -## How Sessions Start - -### UI Interface - -When a user opens `http://localhost:8080`, the browser receives a session token in the form of a UUID. This token is stored in localStorage for persistence across page loads. The session itself is created in PostgreSQL for durability and cached for fast access during active conversations. - -### API Access - -Programmatic access to sessions uses the REST API. A POST request to `/api/session` returns a session ID and secret token. Subsequent requests include the token in the Authorization header as a Bearer token to maintain the session context. - -```bash -# Get new session -curl -X POST http://localhost:8080/api/session -# Returns: {"session_id": "uuid-here", "token": "secret-token"} - -# Use session -curl -H "Authorization: Bearer secret-token" \ - http://localhost:8080/api/chat -``` - -### Anonymous vs Authenticated - -Sessions come in two flavors depending on user identity. Anonymous sessions are auto-created with temporary identities for users who have not logged in. Authenticated sessions link to a user account and maintain permanent history that persists indefinitely. - - -## Session Lifecycle - -Session States - -Sessions move through several states during their existence. Active sessions have no timeout while the user is actively chatting. Idle sessions timeout after 30 minutes by default, though this is configurable. Expired sessions are removed after 7 days for anonymous users, while authenticated sessions never expire automatically. - - -## What Gets Stored - -### PostgreSQL (Permanent Storage) - -The database stores the authoritative session record. The sessions table tracks the unique ID, optional user reference, which bot is being used, creation timestamp, and last activity time. The messages table stores each message with its session reference, role (user, assistant, or system), content, and timestamp. The session_state table holds variables as JSONB data and tracks the current knowledge base and tool context. - -### Cache (Fast Access) - -The cache layer provides rapid access to active session data. Recent messages, current variables, active knowledge bases and tools, and last activity timestamps are all cached under keys prefixed with the session UUID. This caching ensures responsive conversations without constant database queries. - - -## Session Variables - -Variables set in BASIC scripts persist across messages automatically. When you store a variable in one message, you can retrieve it in a later message whether that is minutes or days later. - -```basic -' First message -name = HEAR -SET user_name = name - -' Later message (minutes or days later) -GET user_name -TALK "Welcome back, " + user_name -``` - -Storage happens automatically through several layers. Writes go to cache immediately for fast access. Every message triggers persistence to PostgreSQL for durability. If the cache misses, data restores automatically from the database. - - -## Context Management - -Each session maintains its own isolated context. When one session loads a knowledge base, other sessions remain unaffected. This isolation ensures users see only the information relevant to their conversation. - -```basic -' Session A -USE KB "policies" -' Only this session sees policies - -' Session B (different user) -USE KB "products" -' This session only sees products -``` - -Session contexts include active knowledge bases, loaded tools, LLM configuration overrides, and custom prompts. All of these are scoped to the individual session and do not leak between users. - - -## Multi-Bot Sessions - -Different bots create entirely separate sessions. A user visiting `/default` gets one session connected to the default bot, while visiting `/support` creates a different session for the support bot. Each bot session is completely independent with its own conversation history, knowledge bases, configuration, and no data sharing between them. - - -## Session Security - -### Token Generation - -Session tokens use cryptographically secure random generation with 256-bit entropy. Tokens are encoded in URL-safe base64 format and are unique per session. This makes tokens effectively impossible to guess or predict. - -### Token Validation - -Every request undergoes validation to ensure security. The system verifies that the token exists, has not expired, matches the claimed session, and that the session is still active. Any failure in this chain rejects the request. - -### Security Features - -Multiple security measures protect sessions. Unguessable tokens prevent session hijacking. New tokens for each session prevent session fixation attacks. Automatic cleanup removes old sessions to prevent accumulation. Rate limiting per session prevents abuse. - - -## Debugging Sessions - -### View Current Session - -Within a BASIC script, you can access session information directly. - -```basic -session_id = GET "session.id" -TALK "Session: " + session_id -``` - -### Database Inspection - -Direct database queries help debug session issues. You can find all active sessions by querying for recent activity, or view message history for a specific session ordered by timestamp. - -### Cache Inspection - -The cache contents can be examined using the valkey-cli tool. List all session keys or retrieve specific session data like variables or context directly from the cache. - - -## Session Limits - -Default limits control resource usage, though all are configurable. Message history keeps the last 50 messages in context. Variable storage allows up to 1MB per session. File uploads accept up to 10MB per file. Each server handles up to 1000 concurrent sessions. Rate limiting restricts each session to 60 messages per minute. - - -## Advanced Features - -### Session Persistence - -Sessions persist across server restarts through the cache and database layers. When users reconnect after a restart, their session state restores automatically. This happens transparently without any action required from users or bot developers. - -### Session Context Isolation - -Each session maintains its own context for knowledge base and tool usage. When you load a knowledge base or enable a tool, the change affects only the current session. Other users in other sessions remain unaffected by your context changes. - -```basic -' Each session has isolated context -USE KB "docs" -' Only affects current session -``` - - -## How It Works Automatically - -Sessions require zero configuration from bot developers. Creation happens automatically on the first request from any client. Storage to database and cache happens automatically as conversations progress. Cleanup runs automatically after sessions expire. Security through token generation happens automatically without any setup. Multi-channel support through automatic adapter selection means the same session infrastructure works across all platforms. - -You never need to manage sessions directly. Just use the conversation keywords like TALK, HEAR, SET, and GET. Everything else happens behind the scenes. - - -## Common Patterns - -### Welcome Back - -Personalize greetings by remembering when users last visited. Store the last visit timestamp and check for it on subsequent sessions to customize the welcome message. - -```basic -last_visit = GET BOT MEMORY "last_visit_" + session_id -IF last_visit THEN - TALK "Welcome back! Last seen: " + last_visit -ELSE - TALK "Welcome! First time here?" -END IF -SET BOT MEMORY "last_visit_" + session_id, NOW() -``` - -### Progressive Disclosure - -Reveal more features as users become more engaged by tracking message count and adjusting guidance accordingly. - -```basic -msg_count = GET "session.message_count" -IF msg_count < 3 THEN - TALK "I can help with basic questions" -ELSE IF msg_count < 10 THEN - TALK "Try our advanced features!" -ELSE - TALK "You're a power user! Check tools menu" -END IF -``` - -### Multi-User Support - -Each user automatically receives their own isolated session. The system handles user separation without any explicit code required. Simply write your dialog logic and trust that each user's data remains private to their session. - - -## Troubleshooting - -If sessions are not persisting, check that PostgreSQL is running and accessible. Verify that the cache server is reachable. Look for disk space issues that might prevent database writes. - -If sessions expire too soon, adjust the timeout setting in config.csv. Check that server clocks are synchronized. Monitor for memory pressure that might cause early cache eviction. - -If you cannot resume a session, the token might have become invalid through expiration or corruption. The session could have passed its expiration window. Database connection issues can also prevent session restoration. - - -## Write Once, Run Everywhere - -The same BASIC script runs across all channels including the UI interface, mobile apps, WhatsApp, Microsoft Teams, email conversations, and voice assistants. Your investment in dialog development pays off everywhere because each channel adapter handles the platform specifics while you focus on conversation logic. - -```basic -' This same script works everywhere - -TALK "Hello! How can I help?" -answer = HEAR -TALK "I understand you need help with: " + answer -``` - - -## Summary - -Sessions and channels work together seamlessly in BotServer. Sessions handle state management automatically across any channel, persist data reliably through cache and database layers, and scale efficiently to thousands of concurrent conversations. You focus on writing the conversation flow while the system handles memory management and multi-channel delivery transparently. \ No newline at end of file diff --git a/docs/src/chapter-02/README.md b/docs/src/chapter-02/README.md deleted file mode 100644 index c8758ea6..00000000 --- a/docs/src/chapter-02/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# Chapter 02: About Packages - -How bots are organized in General Bots. - -## What You'll Learn - -- Package structure (`.gbai` folders) -- Dialog scripts in BASIC -- Knowledge bases -- Configuration basics -- How packages load - -## Package Structure - -A bot is just a folder ending in `.gbai`: - -``` -my-bot.gbai/ -├── my-bot.gbdialog/ # BASIC scripts -├── my-bot.gbkb/ # Documents -├── my-bot.gbot/ # Configuration -├── my-bot.gbtheme/ # Optional styling -└── my-bot.gbdrive/ # Optional storage -``` - -Drop the folder in `templates/`, it loads automatically. - -## Key Concepts - -### Dialogs (.gbdialog) -- BASIC scripts that control conversation -- `start.bas` is optional (but needed to activate tools/KB with USE TOOL/USE KB) -- Simple commands like TALK and HEAR - -### Knowledge Base (.gbkb) -- Put PDFs and documents in folders -- Automatically becomes searchable -- Bot can answer questions from documents - -### Configuration (.gbot) -- Single `config.csv` file -- Simple name,value pairs -- Missing values use defaults - -### Themes (.gbtheme) -- Optional CSS styling -- Most bots don't need this - -### Storage (.gbdrive) -- Links to S3-compatible storage -- For large files and uploads - -## How It Works - -1. **Discovery**: Finds `.gbai` folders -2. **Loading**: Reads all components -3. **Indexing**: Processes documents -4. **Activation**: Bot is ready - -No build process. No compilation. Just folders and files. - -The web UI uses **HTMX with server-side rendering** - minimal JavaScript, no build process, just HTML templates powered by Rust. - -## Topics Covered - -- [.gbai Architecture](./gbai.md) - Package details -- [.gbdialog Dialogs](./gbdialog.md) - BASIC scripting -- [.gbkb Knowledge Base](./gbkb.md) - Document management -- [.gbot Configuration](./gbot.md) - Settings -- [.gbtheme UI Theming](./gbtheme.md) - Styling -- [.gbdrive File Storage](./gbdrive.md) - Storage integration -- [Bot Templates](./templates.md) - Example bots - ---- - -
- General Bots -
\ No newline at end of file diff --git a/docs/src/chapter-02/assets/package-structure.svg.backup b/docs/src/chapter-02/assets/package-structure.svg.backup deleted file mode 100644 index caddd655..00000000 --- a/docs/src/chapter-02/assets/package-structure.svg.backup +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Package Structure - - - - my-bot.gbai/ - (Package Root) - - - - - - - - - - - - - - - - - - - - .gbdialog - Dialog Scripts - Conversation Logic - - - - .gbkb - Knowledge Base - Documents - - - - .gbot - Configuration - Bot Settings - - - - .gbtheme - (optional) - UI Theme - - - - .gbdrive - (optional) - File Storage - - - - - - - - - - - - - - - - Scripts - .bas files - - - - Docs - PDF/TXT - - - - Config - .csv - - - - Styles - CSS/HTML - - - - Storage - S3 Link - - - - - Example Directory Structure: - - - botname.gbai/ - ├── botname.gbdialog/ - │ ├── start.bas - │ ├── auth.bas - │ └── tools/ - ├── botname.gbkb/ - │ ├── collection1/ - │ └── collection2/ - ├── botname.gbot/ - │ └── config.csv - └── botname.gbtheme/ - └── default.css - - - - - - - Key Points - - - • Folder name = Bot name - • Only .gbdialog is required - • start.bas is the entry point - • Deploy by copying folder - - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-02/assets/template-deployment-flow.svg.backup b/docs/src/chapter-02/assets/template-deployment-flow.svg.backup deleted file mode 100644 index c250b5ba..00000000 --- a/docs/src/chapter-02/assets/template-deployment-flow.svg.backup +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Template Deployment Flow - - - - templates/ - Source folder - - - - - - - SCAN - Find all .gbai folders - - - - - - - VALIDATE - Check required structure - • start.bas exists? - • Folders match name? - - - - - - - UPLOAD - Copy to object storage - • Templates → S3/Drive - • Assets → CDN paths - - - - - - - INDEX - Process knowledge base - • Extract text - • Generate embeddings - • Store in Qdrant - - - - - - - REGISTER - Create in database - • Bot record - • Configuration - • URL mapping - - - - - - - ACTIVATE - Start serving - • /bot-name endpoint - • WebSocket ready - • Sessions enabled - - - - - 5-10s - per bot - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-02/gbai.md b/docs/src/chapter-02/gbai.md deleted file mode 100644 index 20a64531..00000000 --- a/docs/src/chapter-02/gbai.md +++ /dev/null @@ -1,288 +0,0 @@ -# .gbai Architecture - -**A bot is just a folder.** The `.gbai` extension marks a directory as a BotServer package containing everything needed to run a conversational AI bot - scripts, documents, configuration, and themes. - -## The Dead Simple Structure - -``` -my-bot.gbai/ # This folder = your entire bot - my-bot.gbdialog/ # BASIC conversation scripts - my-bot.gbkb/ # Documents for Q&A - my-bot.gbot/ # Configuration - my-bot.gbtheme/ # Optional UI customization -``` - -That's it. No manifests, no build files, no dependencies. Copy the folder to deploy. - -### Visual Architecture -### Architecture - -Package Structure - -## How Bootstrap Finds Bots - -At startup, BotServer scans `templates/` for any folder ending in `.gbai`: - -``` -templates/ - default.gbai/ → Creates bot at /default - support.gbai/ → Creates bot at /support - sales.gbai/ → Creates bot at /sales -``` - -Each `.gbai` becomes a URL endpoint automatically. Zero configuration. - -## What Goes Where - -### .gbdialog/ - Your Bot's Brain - -BASIC scripts that control conversation flow: - -``` -my-bot.gbdialog/ - start.bas # Optional - needed to activate tools/KB - auth.bas # Login flow - tools/ # Callable functions - book-meeting.bas - check-status.bas - handlers/ # Event responses - on-email.bas -``` - -Example `start.bas` (optional, but required for tools/KB): -```basic -USE KB "policies" -USE TOOL "book-meeting" -USE TOOL "check-status" -TALK "Hi! I'm your assistant with tools and knowledge ready." -``` - -Note: If you don't need tools or knowledge bases, `start.bas` is optional. The LLM will handle basic conversations without it. - -### .gbkb/ - Your Bot's Knowledge - -Documents organized by topic: - -``` -my-bot.gbkb/ - policies/ # HR documents - vacation.pdf - handbook.docx - products/ # Product info - catalog.pdf - pricing.xlsx - support/ # Help docs - faq.md -``` - -Each folder becomes a searchable collection. Drop files in, bot learns automatically. - -### .gbot/ - Your Bot's Settings - -Single `config.csv` file with key-value pairs: - -```csv -llm-model,gpt-3.5-turbo -temperature,0.7 -max-tokens,2000 -welcome-message,Hello! How can I help? -session-timeout,1800 -``` - -No complex JSON or YAML. Just simple CSV that opens in Excel. - -### .gbtheme/ - Your Bot's Look (Optional) - -Custom web interface styling: - -``` -my-bot.gbtheme/ - styles.css # Custom CSS - logo.png # Brand assets - templates/ # HTML overrides - chat.html -``` - -If missing, uses default theme. Most bots don't need this. - -## Real Example: Support Bot - -Here's a complete customer support bot: - -``` -support.gbai/ - support.gbdialog/ - start.bas # Optional, but needed for tools/KB - tools/ - create-ticket.bas - check-status.bas - support.gbkb/ - faqs/ - common-questions.pdf - guides/ - troubleshooting.docx - support.gbot/ - config.csv -``` - -`start.bas` (activates tools and knowledge bases): -```basic -USE KB "faqs" -USE KB "guides" -USE TOOL "create-ticket" -USE TOOL "check-status" - -TALK "Support bot ready. How can I help?" -``` - -`create-ticket.bas`: -```basic -PARAM issue, priority -DESCRIPTION "Creates support ticket" - -ticket_id = GENERATE_ID() -SAVE "tickets.csv", ticket_id, issue, priority, NOW() -TALK "Ticket #" + ticket_id + " created" -``` - -`config.csv`: -```csv -llm-model,gpt-3.5-turbo -bot-name,TechSupport -greeting,Welcome to support! -``` - -## Deployment = Copy Folder - -### Local Development -```bash -cp -r my-bot.gbai/ templates/ -./botserver restart -# Visit http://localhost:8080/my-bot -``` - -### Production Server -```bash -scp -r my-bot.gbai/ server:~/botserver/templates/ -ssh server "cd botserver && ./botserver restart" -``` -### Deployment - -### LXC Container -```bash -lxc file push my-bot.gbai/ container/app/templates/ -``` - -No build step. No compilation. Just copy files. - -## Multi-Bot Hosting - -One BotServer runs multiple bots: - -``` -templates/ - support.gbai/ # support.example.com - sales.gbai/ # sales.example.com - internal.gbai/ # internal.example.com - public.gbai/ # www.example.com -``` - -Each bot: -- Gets own URL endpoint -- Has isolated sessions -- Runs independently -- Shares infrastructure - -## Template Inheritance - -Bots can share common resources: - -``` -templates/ - _shared/ - knowledge/ # Shared documents - tools/ # Shared functions - bot1.gbai/ - bot1.gbot/ - config.csv # includes: _shared - bot2.gbai/ - bot2.gbot/ - config.csv # includes: _shared -``` - -## Naming Conventions - -### Required -- Folder must end with `.gbai` -- Subfolders must match: `botname.gbdialog`, `botname.gbkb`, etc. -- `start.bas` is optional, but required if you want to use tools or knowledge bases (must USE TOOL and USE KB to activate them) - -### Recommended -- Use lowercase with hyphens: `customer-service.gbai` -- Group related bots: `support-tier1.gbai`, `support-tier2.gbai` -- Version in folder name if needed: `chatbot-v2.gbai` - -## Bootstrap Process - -When BotServer starts: - -``` -Template Deployment Flow -``` - -Takes about 5-10 seconds per bot. - -## UI Architecture - -The web interface uses **HTMX with server-side rendering** - minimal client-side code: -- Askama templates for HTML generation -- HTMX for dynamic updates without JavaScript -- No webpack, no npm build -- Edit and refresh to see changes -- Zero compilation time - -## Package Size Limits - -Default limits (configurable): -- Total package: 100MB -- Single document: 10MB -- Number of files: 1000 -- Script size: 1MB -- Collection count: 50 - -## Troubleshooting - -**Bot not appearing?** -- Check folder ends with `.gbai` -- Verify subfolders match bot name -- If using tools/KB, ensure `start.bas` exists with USE TOOL/USE KB commands - -**Documents not searchable?** -- Ensure files are in `.gbkb/` subfolder -- Check file format is supported -- Wait 30 seconds for indexing - -**Scripts not running?** -- Validate BASIC syntax -- Check file has `.bas` extension -- Review logs for errors - -## Best Practices - -### Do's -✅ Keep packages under 50MB -✅ Organize knowledge by topic -✅ Use clear folder names -✅ Test locally first - -### Don'ts -❌ Don't nest `.gbai` folders -❌ Don't mix test/prod in same folder -❌ Don't hardcode absolute paths -❌ Don't store secrets in scripts - -## Summary - -The `.gbai` architecture keeps bot development simple. No complex frameworks, no build systems, no deployment pipelines. Just organize your files in folders, and BotServer handles the rest. Focus on content and conversation, not configuration. - -Next: Learn about [.gbdialog Dialogs](./gbdialog.md) for writing conversation scripts. \ No newline at end of file diff --git a/docs/src/chapter-02/gbdialog.md b/docs/src/chapter-02/gbdialog.md deleted file mode 100644 index ccc4d0a9..00000000 --- a/docs/src/chapter-02/gbdialog.md +++ /dev/null @@ -1,276 +0,0 @@ -# .gbdialog Dialogs - -The [`.gbdialog`](../chapter-02/gbdialog.md) package contains BASIC scripts that define conversation flows, tool integrations, and bot behavior. - -## What is .gbdialog? - -`.gbdialog` files are written in a specialized BASIC dialect that controls: -- Tool execution and integrations -- LLM prompting and context -- Knowledge base activation -- Session and memory management -- External API calls - -## Modern Approach: Let the LLM Work -### Minimal BASIC Philosophy - -Instead of complex logic, use the LLM's natural understanding: - -```basic -' Example from announcements.gbai/update-summary.bas -' Generate summaries from documents -text = GET "announcements.gbkb/news/news.pdf" -resume = LLM "In a few words, resume this: " + text -SET BOT MEMORY "resume", resume - -' Example from law.gbai/case.bas -' Load context and let LLM answer questions -text = GET "case-" + cod + ".pdf" -text = "Based on this document, answer the person's questions:\n\n" + text -SET CONTEXT text -TALK "Case loaded. You can ask me anything about the case." -``` - -## Key Components - -### 1. LLM Integration -```basic -' LLM is for background processing only - generates content once for all users -' Example: Generate a summary that all users will see -text = GET "document.pdf" -summary = LLM "Summarize this document: " + text -SET BOT MEMORY "daily_summary", summary - -' For interactive conversations, use SET CONTEXT and TALK -SET CONTEXT "user_type" AS "premium customer" -TALK "How can I help you today?" -``` - -### 2. Tool Execution -```basic -' Define tools with parameters -PARAM name AS string LIKE "John Smith" DESCRIPTION "Customer name" -PARAM email AS string LIKE "john@example.com" DESCRIPTION "Email" - -' LLM automatically knows when to call this -SAVE "customers.csv", name, email -TALK "Registration complete!" -``` - -### 3. Knowledge Base Usage -See [Knowledge Base documentation](../chapter-03/knowledge-base.md) for details. -```basic -' Activate knowledge base collections -USE KB "products" -USE KB "policies" - -' The system AI searches these automatically during conversations -' No LLM command needed - just TALK to the user -TALK "What product information can I help you with?" -``` - - - -## Script Structure - -### Entry Point: start.bas (Optional) -The `start.bas` file in the [`.gbdialog`](../chapter-02/gbdialog.md) folder is **optional**, but required if you want to activate tools or knowledge bases: - -```basic -' Optional start script - needed only to activate tools/KB -USE KB "company_docs" -USE TOOL "book-meeting" -USE TOOL "check-status" -TALK "Welcome! How can I assist you today?" -``` - -**When you need start.bas:** -- To activate knowledge bases with `USE KB` -- To activate tools with `USE TOOL` -- To set initial context or configuration - -**When you don't need start.bas:** -- For simple conversational bots -- When the LLM can handle everything without tools/KB -- For basic Q&A without document search - -### Tool Definitions -Create separate `.bas` files for each tool. See [KB and Tools](../chapter-03/kb-and-tools.md) for more information: - -```basic -' enrollment.bas - The LLM knows when to use this -PARAM student_name AS string -PARAM course AS string -DESCRIPTION "Enrolls a student in a course" - -SAVE "enrollments.csv", student_name, course, NOW() -TALK "Enrolled successfully!" -``` - -## Best Practices - -### 1. Minimal Logic -```basic -' Good - Let system AI handle the conversation naturally -TALK "How can I help you?" -' System AI understands context and responds appropriately - -' Avoid - Don't micromanage the flow -' IF user_says_this THEN do_that... -``` - -### 2. Clear Tool Descriptions -```basic -DESCRIPTION "This tool books appointments for customers" -' The LLM uses this description to know when to call the tool -``` - -### 3. Context Over Conditions -```basic -' Provide context, not rules -SET CONTEXT "business_hours" AS "9AM-5PM weekdays" -TALK "When would you like to schedule?" -' System AI naturally understands to mention hours when relevant -``` - -### 4. Trust the System AI -```basic -' The system AI handles conversations naturally -TALK "Hello! I'm here to help." -' System handles greetings, questions, complaints naturally -``` - -## Common Patterns - -### Document Summarization - Background Processing (from announcements.gbai) -```basic -' Schedule automatic updates - runs in background -SET SCHEDULE "59 * * * *" - -' Fetch and summarize documents ONCE for all users -text = GET "announcements.gbkb/news/news.pdf" -resume = LLM "In a few words, resume this: " + text -SET BOT MEMORY "resume", resume ' Stored for all users -``` - -### Interactive Case Analysis - User Conversations (from law.gbai) -```basic -' Ask for case number - interactive with user -TALK "What is the case number?" -HEAR cod - -' Load case document -text = GET "case-" + cod + ".pdf" - -IF text THEN - ' Set context for system AI to use in conversation - text = "Based on this document, answer the person's questions:\n\n" + text - SET CONTEXT text - TALK "Case loaded. Ask me anything about it." -ELSE - TALK "Case not found, please try again." -END IF -``` - -### Tool Definition Pattern -```basic -' Tool parameters (auto-discovered by LLM) -PARAM name AS string -PARAM email AS string -DESCRIPTION "Enrollment tool" - -' Tool logic (called when LLM decides) -SAVE "enrollments.csv", name, email -TALK "Successfully enrolled " + name -``` - -### Multi-Collection Search -```basic -USE KB "products" -USE KB "reviews" -USE KB "specifications" - -' System AI searches these collections automatically during conversation -TALK "What would you like to know about our products?" -``` - -## Advanced Features - -### Memory Management -See [Storage documentation](../chapter-09/storage.md) for persistent data options. -```basic -SET BOT MEMORY "company_policy", policy_text -' Available across all sessions - -retrieved = GET BOT MEMORY "company_policy" -``` - -### External APIs -See [External APIs chapter](../chapter-08/external-apis.md) for integration patterns. -```basic -result = GET "https://api.example.com/data" -' For background processing only -summary = LLM "Summarize this data: " + result -SET BOT MEMORY "api_summary", summary -``` - -### Suggestions -See [UI Interface](../chapter-04/ui-interface.md) for UI integration. -```basic -ADD SUGGESTION "Schedule Meeting" AS "schedule" -ADD SUGGESTION "View Products" AS "products" -' UI shows these as quick actions -``` - -## Error Handling - -The system handles errors gracefully: -- Syntax errors caught at compile time -- Runtime errors logged but don't crash -- LLM provides fallback responses -- Timeouts prevent infinite operations - -## Script Execution - -Scripts run in a sandboxed environment with: -- Access to session state -- LLM generation capabilities -- Knowledge base search -- Tool execution rights -- External API access (configured) - -## Migration from Traditional Bots - -### Old Way (Complex Logic) -```basic -' DON'T DO THIS - 1990s style -' IF INSTR(user_input, "order") > 0 THEN -' IF INSTR(user_input, "status") > 0 THEN -' TALK "Checking order status..." -' ELSE IF INSTR(user_input, "new") > 0 THEN -' TALK "Creating new order..." -' END IF -' END IF -``` - -### New Way (System AI Intelligence) -```basic -' DO THIS - Let system AI handle conversation naturally -TALK "How can I help you with your order?" -' System AI understands context and intent automatically -``` - -The key is to **trust the system AI** and write less code for more intelligent behavior. - -## Important Distinction - -- **[LLM Command](../chapter-09/ai-llm.md)**: For background/batch processing, generates content ONCE, stored in BOT MEMORY for all users -- **[Interactive Conversations](../chapter-09/conversation.md)**: Use HEAR/TALK/SET CONTEXT, system AI handles the natural conversation flow - -## See Also - -- [Chapter 1: Quick Start](../chapter-01/quick-start.md) - Getting started with your first bot -- [Chapter 2: Bot Architecture](../chapter-02/README.md) - Understanding all components -- [Chapter 3: Knowledge Base](../chapter-03/knowledge-base.md) - Working with KB collections -- [Chapter 5: Keywords Reference](../chapter-05/README.md) - Complete BASIC command reference -- [Chapter 9: Conversation Flow](../chapter-09/conversation.md) - Advanced dialog patterns \ No newline at end of file diff --git a/docs/src/chapter-02/gbdrive.md b/docs/src/chapter-02/gbdrive.md deleted file mode 100644 index b84bc0b4..00000000 --- a/docs/src/chapter-02/gbdrive.md +++ /dev/null @@ -1,219 +0,0 @@ -# .gbdrive File Storage - -The .gbdrive system provides centralized file storage for all bot packages, leveraging S3-compatible object storage to deliver reliable, scalable storage infrastructure. This chapter explains how file storage works, how files are organized, and how to interact with stored content. - -## Understanding File Storage in General Bots - -Every bot requires storage for its various components—scripts, documents, configuration files, user uploads, and generated content. Rather than managing files across disparate locations, General Bots consolidates storage through the .gbdrive system, which provides a consistent interface regardless of the underlying storage backend. - -The storage system builds on S3-compatible object storage, meaning it works with self-hosted solutions like MinIO as well as cloud providers like AWS S3, Backblaze B2, or DigitalOcean Spaces. This flexibility allows deployments to choose storage solutions that match their requirements for cost, performance, and data residency. - -Beyond simple file storage, the system provides versioning capabilities, access control, automatic synchronization, and integration with other bot components like knowledge bases and themes. - -## Storage Organization - -Files are organized using a bucket-per-bot structure that keeps each bot's content isolated and manageable. Within a bot's storage bucket, the familiar package structure appears: .gbdialog for scripts, .gbkb for knowledge base collections, .gbot for configuration, and .gbtheme for interface customization. - -Additionally, each bot has space for user-uploaded files, generated content, and other runtime data. This organization mirrors the logical structure you work with during development, making it intuitive to understand where files reside and how they relate to bot functionality. - -The system maintains this structure automatically when bots are deployed or updated, ensuring that the storage state reflects the current bot configuration without manual intervention. - -## .gbusers - Per-User Storage - -The `.gbusers` folder within `.gbdrive` provides isolated storage space for each user interacting with the bot. This enables personalized document storage, user-specific settings, and application data that persists across sessions. - -### User Folder Structure - -User folders are identified by the user's email address or phone number: - -``` -mybot.gbai/ - mybot.gbdrive/ - users/ - john@example.com/ # User identified by email - papers/ - current/ # Active/working documents - untitled-1.md - meeting-notes.md - named/ # Saved/named documents - quarterly-report/ - document.md - attachments/ - project-proposal/ - document.md - uploads/ # User file uploads - exports/ # Generated exports (PDF, DOCX, etc.) - settings/ # User preferences - preferences.json - +5511999887766/ # User identified by phone number - papers/ - current/ - named/ - uploads/ -``` - -### User Identifier Format - -Users are identified by their primary contact method: - -- **Email**: `john@example.com`, `maria@company.com.br` -- **Phone**: `+5511999887766`, `+1234567890` (E.164 format) - -The identifier is sanitized for filesystem compatibility while remaining human-readable. - -### Paper Document Storage - -The Paper application stores user documents in the `papers/` directory: - -- **`papers/current/`**: Working documents that are actively being edited. These may be auto-saved drafts or recently accessed files. -- **`papers/named/`**: Documents that have been explicitly saved with a name. Each named document gets its own folder to support attachments and metadata. - -Example document structure: -``` -papers/ - current/ - untitled-1.md # Auto-saved draft - untitled-2.md # Another working document - named/ - meeting-notes-2024/ - document.md # The main document content - metadata.json # Title, created_at, updated_at, etc. - attachments/ # Embedded images or files - image-001.png - research-paper/ - document.md - metadata.json -``` - -### Accessing User Storage from BASIC - -BASIC scripts can access user storage using the `USER DRIVE` keyword: - -```basic -' Read a user's document -content = READ USER DRIVE "papers/current/notes.md" - -' Write to user's storage -SAVE USER DRIVE "papers/named/report/document.md", report_content - -' List user's papers -papers = LIST USER DRIVE "papers/named/" - -' Delete a user document -DELETE USER DRIVE "papers/current/draft.md" -``` - -### User Storage API - -The REST API provides endpoints for user storage operations: - -``` -GET /api/drive/user/list?path=papers/current/ -POST /api/drive/user/read - { "path": "papers/named/report/document.md" } -POST /api/drive/user/write - { "path": "papers/current/notes.md", "content": "..." } -POST /api/drive/user/delete - { "path": "papers/current/draft.md" } -``` - -All user storage API calls require authentication and automatically scope operations to the authenticated user's folder. - -### Storage Quotas - -Each user has configurable storage limits: - -| Setting | Default | Description | -|---------|---------|-------------| -| `user-storage-quota` | 100MB | Maximum total storage per user | -| `user-file-limit` | 5MB | Maximum single file size | -| `user-file-count` | 500 | Maximum number of files | - -Configure in `config.csv`: -```csv -user-storage-quota,104857600 -user-file-limit,5242880 -user-file-count,500 -``` - -## Working with Files - -File operations in General Bots happen through several interfaces depending on your needs. The BASIC scripting language provides keywords for reading file content directly into scripts, enabling bots to process documents, load data, or access configuration dynamically. - -Files can also be managed through the administrative API for bulk operations, migrations, or integration with external systems. The web interface provides user-facing upload and download capabilities where appropriate. - -When files change in storage, the system detects modifications and triggers appropriate responses. Script changes cause recompilation, document changes trigger knowledge base reindexing, and configuration changes reload bot settings. This hot-reloading capability accelerates development and enables runtime updates without service interruption. - -## Integration with Bot Components - -The storage system integrates deeply with other bot components, serving as the foundation for several capabilities. - -Knowledge bases draw their source documents from storage, with the indexing system monitoring for changes and updating embeddings accordingly. When you add a document to a .gbkb folder, it automatically becomes part of the bot's searchable knowledge. - -Theme assets including CSS files and images are served from storage, with appropriate caching to ensure good performance. Changes to theme files take effect quickly without requiring restarts. - -Tool scripts in .gbdialog folders are loaded from storage, parsed, and made available for execution. The compilation system tracks dependencies and rebuilds as needed when source files change. - -### Paper Application Integration - -The Paper document editor automatically saves to the user's `.gbusers` folder: - -1. **Auto-save**: Every 30 seconds, working documents are saved to `papers/current/` -2. **Explicit save**: When users click "Save", documents move to `papers/named/{document-name}/` -3. **Export**: Generated exports (PDF, DOCX) are saved to `exports/` and offered for download -4. **AI-generated content**: AI responses can be inserted into documents and saved automatically - -## Access Control - -Different files require different access levels, and the storage system enforces appropriate controls: - -- **Public files**: Accessible without authentication, suitable for shared resources -- **Authenticated access**: Requires valid user credentials, protects user-specific content -- **User-scoped access**: Users can only access their own `.gbusers` folder content -- **Bot-internal files**: Accessible only to the bot system itself -- **Administrative files**: Require elevated privileges to access or modify - -User storage in `.gbusers` is strictly isolated—users cannot access other users' folders through any API or BASIC keyword. - -## Storage Backend Options - -The storage system supports multiple backends to accommodate different deployment scenarios. The default configuration uses self-hosted S3-compatible object storage, providing full control over where data resides. Any S3-compatible service works as an alternative, including major cloud providers. - -For development and testing, local filesystem storage offers simplicity and easy inspection of files. Production deployments might use hybrid configurations with multiple backends providing redundancy or geographic distribution. - -Backend selection happens through configuration, and the rest of the system interacts with storage through a consistent interface regardless of which backend is active. This abstraction allows deployments to change storage strategies without modifying bot code. - -## Directory Structure Reference - -Complete `.gbdrive` structure with all components: - -``` -mybot.gbai/ - mybot.gbdrive/ - dialogs/ # Compiled dialog scripts cache - kb/ # Knowledge base index data - cache/ # Temporary cache files - exports/ # Bot-level exports - uploads/ # Bot-level uploads - users/ # Per-user storage (.gbusers) - user@email.com/ - papers/ - current/ # Working documents - named/ # Saved documents - uploads/ # User uploads - exports/ # User exports - settings/ # User preferences - +1234567890/ - papers/ - uploads/ - exports/ - settings/ -``` - -## Summary - -The .gbdrive storage system provides the foundation for all file-based operations in General Bots. Through S3-compatible object storage, organized bucket structures, automatic synchronization, and deep integration with other components, it delivers reliable file management that supports both development workflows and production operation. - -The `.gbusers` folder structure enables personalized storage for each user, supporting applications like Paper that require persistent document storage. By organizing user data under their email or phone identifier, the system maintains clear separation while enabling powerful per-user features. - -Understanding how storage works helps you organize bot content effectively and leverage the automatic capabilities the system provides. \ No newline at end of file diff --git a/docs/src/chapter-02/gbkb.md b/docs/src/chapter-02/gbkb.md deleted file mode 100644 index df0f882e..00000000 --- a/docs/src/chapter-02/gbkb.md +++ /dev/null @@ -1,67 +0,0 @@ -# .gbkb Knowledge Base - -The `.gbkb` package contains your bot's domain knowledge - documents that the AI uses to answer questions accurately about your specific organization, products, or services. - -## What It Does - -When you place documents in a `.gbkb` folder, the system automatically: - -1. **Extracts text** from your files (PDF, DOCX, TXT, MD, HTML, CSV) -2. **Creates searchable indexes** using vector embeddings -3. **Enables semantic search** so users can ask questions naturally - -This means your bot answers based on YOUR documents, not just general AI knowledge. - -## Folder Structure - -``` -mybot.gbai/ -└── mybot.gbkb/ - ├── policies/ ← Collection: "policies" - │ ├── vacation.pdf - │ └── handbook.docx - ├── products/ ← Collection: "products" - │ ├── catalog.pdf - │ └── specs.xlsx - └── support/ ← Collection: "support" - └── faq.md -``` - -Each subfolder becomes a **collection** you can activate independently. - -## Using in BASIC Scripts - -```basic -' Activate collections for this conversation -USE KB "policies" -USE KB "products" - -' Now the AI automatically searches these when answering -TALK "How can I help you today?" - -' Later, clear when done -CLEAR KB "policies" -``` - -## Supported File Types - -| Format | Extensions | -|--------|------------| -| PDF | `.pdf` | -| Word | `.docx`, `.doc` | -| Text | `.txt`, `.md` | -| Web | `.html` | -| Data | `.csv`, `.json` | - -## Key Points - -- **Automatic indexing** - Just drop files in folders -- **Semantic search** - Users don't need exact keywords -- **Multiple collections** - Organize by topic, activate as needed -- **No code required** - The AI handles search automatically - -## Learn More - -- [Chapter 03: Knowledge Base System](../chapter-03/README.md) - Technical deep-dive on indexing, vectors, and search -- [USE KB Keyword](../chapter-06-gbdialog/keyword-use-kb.md) - Complete keyword reference -- [CLEAR KB Keyword](../chapter-06-gbdialog/keyword-clear-kb.md) - Managing active collections \ No newline at end of file diff --git a/docs/src/chapter-02/gbot.md b/docs/src/chapter-02/gbot.md deleted file mode 100644 index e3da4215..00000000 --- a/docs/src/chapter-02/gbot.md +++ /dev/null @@ -1,63 +0,0 @@ -# .gbot Bot Configuration - -The .gbot package serves as the configuration center for your bot, containing the settings that define how the bot behaves, which AI models it uses, and how it interacts with users. This chapter explains the configuration system and guides you through the available options. - -## Understanding Bot Configuration - -Every bot in General Bots requires configuration to operate effectively. The .gbot folder within your bot package holds these settings, primarily through a config.csv file that uses simple key-value pairs. This approach makes configuration accessible to anyone comfortable with spreadsheet applications while remaining powerful enough for complex deployments. - -The configuration system influences several aspects of bot behavior. Bot identity settings control how the bot presents itself to users. LLM configuration determines which language model powers the bot's intelligence and how it generates responses. Context management settings affect how the bot maintains conversation history and retrieves relevant information. Integration parameters connect the bot to external services and APIs. - -## The config.csv File - -Configuration lives in a straightforward CSV format with two columns: key and value. This design choice prioritizes accessibility—you can edit configuration in any text editor or spreadsheet application without learning complex syntax. Each row represents a single setting, making it easy to scan and modify. - -The file supports various data types implicitly. Text values are stored as-is, numbers are parsed when needed, and boolean values typically use "true" and "false" strings. The system handles type conversion automatically when reading configuration, so you rarely need to worry about explicit typing. - -## Bot Identity Configuration - -Identity settings establish how your bot presents itself during conversations. The bot_name parameter provides the display name users see when interacting with the bot. A descriptive bot_description helps users understand the bot's purpose and capabilities. Version tracking through the version parameter supports deployment management and debugging. - -These identity settings matter because they shape user expectations. A bot named "Legal Document Assistant" with an appropriate description sets different expectations than a generic "Helper Bot." Clear identity configuration improves user experience by establishing context before conversations begin. - -## Language Model Settings - -LLM configuration represents perhaps the most important settings in your bot. The llm_provider parameter specifies which AI service powers your bot, supporting options like OpenAI, Azure OpenAI, or local model servers. The llm_model parameter identifies the specific model to use, such as GPT-4 or Claude 3. - -Response characteristics are controlled through several parameters. The temperature setting affects response creativity, with lower values producing more focused and deterministic outputs while higher values allow more varied and creative responses. The max_tokens parameter limits response length, preventing runaway generation and managing costs for cloud-based providers. - -The system_prompt parameter provides instructions that shape the bot's personality and behavior throughout conversations. This prompt is prepended to every interaction, giving the model consistent guidance about how to respond, what tone to use, and what boundaries to respect. - -## Context Management - -Context settings control how the bot maintains awareness of conversation history and relevant information. The context_window parameter determines how many previous messages remain visible to the model during each interaction. Larger windows provide better continuity but consume more tokens. - -The context_provider setting influences how context is assembled and presented to the model. Different providers may apply various strategies for selecting and formatting context, optimizing for different use cases. - -Memory functionality, controlled by the memory_enabled setting, allows bots to retain information across sessions. When enabled, bots can remember user preferences, previous interactions, and other persistent data that improves personalization. - -## Configuration Loading and Precedence - -The system assembles configuration from multiple sources, applying them in a specific order that allows flexible overrides. Default values provide baseline behavior when no explicit configuration exists. Settings in your .gbot/config.csv file override these defaults for your specific bot. - -Environment variables can override config.csv settings, useful for deployment scenarios where configuration varies between environments. Database configuration provides another override layer, supporting runtime configuration changes that persist across restarts. Finally, runtime API calls can temporarily adjust settings without permanent changes. - -This precedence system enables sophisticated deployment patterns. Development environments might use local configuration files while production deployments pull settings from environment variables or databases. The same bot package can behave differently across environments without modification. - -## Dynamic Configuration with Bot Memory - -Beyond static configuration, bots can store and retrieve dynamic settings using bot memory. The SET BOT MEMORY keyword stores values that persist across all sessions, effectively creating runtime configuration that can be modified through bot scripts. - -This capability supports scenarios where configuration needs to adapt based on usage patterns, administrative decisions, or external inputs. A bot might store preferred response styles, accumulated statistics, or cached data that influences its behavior. - -## Best Practices - -Effective configuration follows several principles. Keep identity settings clear and accurate—users trust bots more when their purpose is evident. Choose LLM settings that balance capability with cost and latency requirements. Set appropriate context windows that provide continuity without excessive token consumption. - -Document non-obvious configuration choices, either in comments within config.csv or in accompanying documentation. This practice helps future maintainers understand why settings were chosen and whether they should be adjusted. - -Test configuration changes in development environments before deploying to production. Some settings interact in non-obvious ways, and testing catches issues before they affect users. - -## Summary - -The .gbot configuration system provides comprehensive control over bot behavior through accessible CSV files augmented by environment variables, database settings, and runtime adjustments. Understanding these configuration options and their precedence helps you build bots that behave predictably across different deployment scenarios while remaining adaptable to changing requirements. \ No newline at end of file diff --git a/docs/src/chapter-02/gbtheme.md b/docs/src/chapter-02/gbtheme.md deleted file mode 100644 index 38b29e60..00000000 --- a/docs/src/chapter-02/gbtheme.md +++ /dev/null @@ -1,75 +0,0 @@ -# .gbtheme UI Theming - -The .gbtheme package provides visual customization for your bot's web interface through straightforward CSS-based theming. This approach prioritizes simplicity—you create CSS files that override default styles, without needing complex build tools, template engines, or JavaScript frameworks. - -## The Philosophy of Simple Theming - -Many theming systems require elaborate toolchains, preprocessors, and build processes that create barriers for non-developers who want to customize their bot's appearance. General Bots takes a different approach by using plain CSS files that any web designer can create and modify. - -This simplicity doesn't sacrifice capability. CSS custom properties (variables) provide the flexibility to change colors, typography, spacing, and other visual characteristics throughout the interface by modifying a few central values. The bot's default interface handles all the complex layout and functionality concerns, leaving themes to focus purely on appearance. - -## Theme Structure - -A theme consists of one or more CSS files placed in the .gbtheme folder within your bot package. The simplest theme might be a single default.css file containing variable overrides. More complex setups might include multiple theme files for different contexts—a dark theme for evening use, a high-contrast theme for accessibility, or seasonal themes for special occasions. - -The system automatically loads the default theme on startup, and scripts can switch between available themes at runtime based on user preferences, time of day, or any other logic you implement. - -## CSS Variables and Customization - -The bot interface defines a set of CSS custom properties that control fundamental visual characteristics. By overriding these properties in your theme file, you can transform the interface's appearance with minimal code. - -The primary-color variable establishes your main brand color, used for headers, buttons, and other prominent elements. The secondary-color provides accent coloring for highlights and interactive elements. Background and text-color control the basic page appearance and readability. - -Typography settings including font-family let you match your organization's brand standards. Structural properties like border-radius affect the overall feel—sharp corners suggest professionalism while rounded corners feel friendlier. Spacing controls help maintain consistent visual rhythm throughout the interface. - -These variables cascade through the interface components, meaning a single change propagates everywhere that property is used. This approach makes comprehensive theming achievable with just a handful of variable overrides. - -## Creating Effective Themes - -Building a theme starts with understanding your visual goals. Corporate deployments often need to match existing brand guidelines, requiring specific colors, fonts, and visual treatments. Consumer-facing bots might prioritize approachability and visual appeal. Internal tools might emphasize clarity and efficiency over aesthetics. - -A minimal theme might override only the primary and secondary colors to match brand standards while accepting defaults for everything else. This approach gets results quickly with minimal effort. As needs grow, you can progressively add more customization. - -When creating dark themes, remember to adjust not just the background color but also text colors, borders, shadows, and any other elements that assume a light background. Contrast matters for readability—test your themes with actual content to ensure text remains legible. - -Accessibility considerations should inform theme design. Ensure sufficient contrast ratios between text and backgrounds, avoid relying solely on color to convey information, and test with various visual impairments in mind. - -## Dynamic Theme Switching - -Bots can change themes at runtime through the CHANGE THEME keyword in BASIC scripts. This capability enables several useful patterns. - -User preference systems let visitors choose their preferred theme, with the selection stored in user memory for future visits. Time-based switching can apply dark themes during evening hours automatically. Contextual theming might use different visual treatments for different conversation modes or topics. - -Theme switching happens instantly without page reloads, providing smooth transitions that maintain conversation flow. - -## Configuration Integration - -Theme settings can also be specified in the bot's config.csv file, providing default values that themes can override. The theme parameter specifies which theme file to load by default. The theme-color1 and theme-color2 parameters provide primary and secondary colors that the interface uses when no theme file specifies otherwise. - -These configuration values serve as fallbacks—CSS files in the .gbtheme folder take precedence when they define the same properties. This layering allows simple color customization through configuration while supporting full CSS theming for more sophisticated needs. - -## No Build Process Required - -Unlike many modern web development workflows, .gbtheme requires no build tools, preprocessors, or compilation steps. You write CSS files, place them in the appropriate folder, and they take effect. Changes appear immediately through hot reloading, making iterative design work fast and responsive. - -This simplicity means designers without development environment setup can contribute themes. Anyone who can write CSS can customize the interface, lowering barriers to visual customization. - -## Migrating from Complex Systems - -Organizations moving from platforms with complex theming systems can extract their essential visual parameters and recreate them as CSS variable overrides. The process typically involves identifying brand colors and typography from the existing theme, mapping those values to General Bots CSS variables, testing the result against the interface, and iteratively refining until the appearance matches expectations. - -Much of the complexity in traditional theming systems exists to handle layout and functionality concerns that General Bots manages through its default interface. By focusing themes purely on visual styling, the migration process becomes much simpler. - -## Best Practices - -Effective theming follows several principles. Keep theme files focused and minimal—override only what you need to change rather than redefining everything. Start with a single default.css file and add complexity only as requirements demand. - -Test themes across different devices and screen sizes to ensure they work well everywhere. Pay attention to interactive states like hover, focus, and active to ensure the interface remains usable and visually coherent. - -Document theme choices, especially when values differ from brand guidelines for technical reasons. Future maintainers will appreciate understanding why specific decisions were made. - -Maintain consistency within themes—if you override one color, consider whether related elements need adjustment to maintain visual harmony. - -## Summary - -The .gbtheme system demonstrates that powerful customization doesn't require complex tooling. Through CSS variables and standard stylesheets, you can transform the bot interface's appearance while the platform handles the underlying complexity. This approach respects the skills of designers and developers alike, enabling visual customization without artificial barriers. \ No newline at end of file diff --git a/docs/src/chapter-02/summary.md b/docs/src/chapter-02/summary.md deleted file mode 100644 index 4aa7e8e8..00000000 --- a/docs/src/chapter-02/summary.md +++ /dev/null @@ -1,22 +0,0 @@ -# Chapter 02 – Package Documentation Overview - -This chapter provides a concise overview of the GeneralBots package types introduced in Chapter 02. Each package type is documented in its own markdown file. Below is a quick reference with brief descriptions and links to the full documentation. - -| Package | File | Description | -|---------|------|-------------| -| **.gbai** | [gbai.md](gbai.md) | Defines the overall application architecture, metadata, and package hierarchy. | -| **.gbdialog** | [gbdialog.md](gbdialog.md) | Contains BASIC‑style dialog scripts that drive conversation flow and tool integration. | -| **.gbdrive** | [gbdrive.md](gbdrive.md) | Manages file storage and retrieval via object storage (S3‑compatible drive). | -| **.gbkb** | [gbkb.md](gbkb.md) | Handles knowledge‑base collections, vector embeddings, and semantic search. | -| **.gbot** | [gbot.md](gbot.md) | Stores bot configuration (CSV) for identity, LLM settings, and runtime parameters. | -| **.gbtheme** | [gbtheme.md](gbtheme.md) | Simple CSS theming - just place CSS files like default.css for custom styling. | - -## How to Use This Overview - -- **Navigate**: Click the file links above to read the detailed documentation for each package. -- **Reference**: Use this table as a quick lookup when developing or extending a GeneralBots application. -- **Extend**: When adding new package types, update this table and create a corresponding markdown file. - ---- - -*This summary was added to fill the missing documentation for Chapter 02.* diff --git a/docs/src/chapter-02/template-analytics.md b/docs/src/chapter-02/template-analytics.md deleted file mode 100644 index c4270db0..00000000 --- a/docs/src/chapter-02/template-analytics.md +++ /dev/null @@ -1,431 +0,0 @@ -# Platform Analytics Template (analytics.gbai) - -A General Bots template for platform metrics, performance monitoring, and custom report generation. - ---- - -## Overview - -The Analytics template provides comprehensive platform analytics capabilities, allowing administrators and stakeholders to monitor usage, track performance, analyze trends, and generate custom reports through conversational AI. - -## Features - -- **Platform Overview** - Key metrics summary with trend analysis -- **Message Analytics** - Conversation statistics by channel and bot -- **User Analytics** - Active users, sessions, and engagement -- **Performance Metrics** - Response times and throughput monitoring -- **LLM Usage Tracking** - Token consumption and cost analysis -- **Storage Analytics** - Disk usage and file statistics -- **Error Analysis** - Error patterns and troubleshooting insights -- **Custom Report Generator** - Build and schedule personalized reports -- **AI-Powered Insights** - Automatic trend analysis and recommendations - ---- - -## Package Structure - -``` -analytics.gbai/ -├── analytics.gbdialog/ -│ ├── start.bas # Main menu and navigation -│ ├── platform-overview.bas # Key metrics dashboard -│ └── custom-report.bas # Custom report builder -└── analytics.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `start.bas` | Main entry point with analytics menu options | -| `platform-overview.bas` | Platform-wide metrics with trends and export | -| `custom-report.bas` | Interactive custom report generator with scheduling | - ---- - -## Available Analytics - -### 1. Platform Overview - -High-level metrics summary including: -- Total messages and trend percentage -- Average active sessions -- Response time performance -- Error rates -- LLM token consumption - -### 2. Message Analytics - -- Message volume by time period -- Breakdown by channel (WhatsApp, Web, API) -- Bot-specific conversation stats -- Peak usage times - -### 3. User Analytics - -- Active users (daily, weekly, monthly) -- Session duration analysis -- User retention rates -- Geographic distribution - -### 4. Performance Metrics - -- Average response time -- Response time distribution -- Throughput (messages per second) -- Latency percentiles (p50, p95, p99) - -### 5. LLM Usage - -- Token consumption by model -- Cost analysis -- Usage patterns -- Optimization recommendations - -### 6. Storage Analytics - -- Disk usage trends -- File count and types -- Storage by bot/package -- Cleanup recommendations - -### 7. Error Analysis - -- Error frequency and patterns -- Error categorization -- Root cause analysis -- Resolution suggestions - -### 8. Custom Reports - -- Select metrics to include -- Choose time ranges -- Set grouping intervals -- Export in multiple formats -- Schedule automatic delivery - ---- - -## Sample Conversation - -``` -User: Show me analytics - -Bot: Welcome to the Analytics Center. I can help you - understand your platform metrics and generate reports. - - What would you like to analyze? - 1. Platform Overview - Key metrics summary - 2. Message Analytics - Conversation statistics - 3. User Analytics - Active users and sessions - 4. Performance Metrics - Response times - 5. LLM Usage - Token consumption and costs - 6. Storage Analytics - Disk usage - 7. Error Analysis - Error patterns - 8. Generate Custom Report - -User: 1 - -Bot: Generating platform overview... - Select time range (1h, 6h, 24h, 7d, 30d): - -User: 24h - -Bot: 📊 Platform Overview for Last 24 Hours - ════════════════════════════════════════ - - 📨 Messages - Total: 15,432 - Trend: ▲ +12.5% vs previous period - - 👥 Sessions - Average Active: 234 - Peak: 412 (at 2:30 PM) - Trend: ▲ +5.2% - - ⚡ Performance - Avg Response Time: 145 ms - P95: 320 ms - P99: 580 ms - - ❌ Errors - Total: 23 - Error Rate: 0.15% - Most Common: Timeout (12) - - 🤖 LLM Usage - Total Tokens: 1,245,678 - Estimated Cost: $18.45 - Avg per Message: 81 tokens - - Would you like to: - (D)etail, (E)xport report, (A)lerts, (B)ack - -User: E - -Bot: Export format (PDF, CSV, XLSX): - -User: PDF - -Bot: ✅ Report exported: platform_overview_20240515.pdf - - The file is available in your Drive. - Download link: [secure link] -``` - ---- - -## Custom Report Generation - -``` -User: I need a custom report - -Bot: Custom Report Generator - What would you like to name this report? - -User: Weekly Performance Summary - -Bot: Select the time range: - 1. Last Hour - 2. Last 24 Hours - 3. Last 7 Days - 4. Last 30 Days - 5. Custom Range - -User: 3 - -Bot: Select metrics to include (comma-separated): - 1. Message Volume - 2. Active Sessions - 3. Response Time - 4. LLM Token Usage - 5. Error Rate - 6. Storage Usage - 7. API Calls - 8. User Activity - 9. Bot Performance - 10. All Metrics - -User: 1,3,4,5 - -Bot: Select grouping interval: - 1. Hourly - 2. Daily - 3. Weekly - -User: 2 - -Bot: Generating your custom report... - - ✅ Report generated successfully! - - 📋 Weekly Performance Summary - 📅 Period: May 8-15, 2025 - 📊 Metrics: Messages, Response Time, LLM Usage, Errors - 📈 Grouping: Daily - - Download: [secure link] - - Would you like to schedule this report? - -User: Yes, weekly - -Bot: ✅ Report scheduled! - - Frequency: Weekly on Monday at 8:00 AM - Delivery: Email to your address - - You can manage scheduled reports anytime. -``` - ---- - -## Metrics Query System - -The template uses a metrics query system: - -```basic -' Query metrics for a time range -messages = QUERY METRICS "messages" FOR "24h" -totalMessages = SUM(messages, "count") - -' Query with grouping -hourlyMessages = QUERY METRICS "messages" FOR "24h" BY "1h" - -' Query with offset for comparison -prevMessages = QUERY METRICS "messages" FOR "24h" OFFSET 1 -trend = ((totalMessages - SUM(prevMessages, "count")) / SUM(prevMessages, "count")) * 100 -``` - ---- - -## Export Formats - -Reports can be exported in multiple formats: - -| Format | Description | -|--------|-------------| -| PDF | Formatted report with charts | -| XLSX | Excel spreadsheet | -| CSV | Raw data export | -| JSON | Structured data format | - ---- - -## Scheduled Reports - -Configure automatic report delivery: - -| Schedule | Cron Expression | Description | -|----------|-----------------|-------------| -| Daily | `0 8 * * *` | Every day at 8 AM | -| Weekly | `0 8 * * 1` | Monday at 8 AM | -| Monthly | `0 8 1 * *` | 1st of month at 8 AM | - -```basic -SET SCHEDULE "0 8 * * 1", "generate-scheduled-report.bas" -``` - ---- - -## Configuration - -Configure in `analytics.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Default Time Range` | Default period for queries | `7d` | -| `Data Retention Days` | How long to keep metrics | `90` | -| `Admin Email` | Email for scheduled reports | `admin@company.com` | -| `Enable AI Insights` | Auto-generate insights | `true` | -| `Export Path` | Report storage location | `/reports/` | - ---- - -## Customization - -### Adding Custom Metrics - -```basic -' Track custom events -INSERT INTO "custom_metrics" VALUES { - "name": "feature_usage", - "value": 1, - "tags": {"feature": "chat", "plan": "pro"}, - "timestamp": NOW() -} - -' Query custom metrics -usage = QUERY METRICS "feature_usage" FOR "30d" WHERE tags.feature = "chat" -``` - -### Custom Dashboard Widgets - -```basic -' Add to start.bas -TALK "Custom Metrics:" -TALK "9. Feature Usage" -TALK "10. Revenue Analytics" -TALK "11. Customer Health Score" - -' Handle custom options -CASE 9 - CALL "feature-usage.bas" -CASE 10 - CALL "revenue-analytics.bas" -``` - -### AI-Powered Insights - -```basic -' Generate AI insights from metrics -SET CONTEXT "You are an analytics expert. Generate executive insights." - -insights = LLM "Analyze this data and provide 3-5 key insights: " + JSON(report_data) -``` - ---- - -## Integration Examples - -### With Alerting - -```basic -' Set up alerts based on metrics -errorRate = SUM(errors, "count") / SUM(messages, "count") * 100 - -IF errorRate > 5 THEN - SEND EMAIL admin_email, "High Error Rate Alert", - "Error rate is " + errorRate + "%, above 5% threshold." -END IF -``` - -### With External BI Tools - -```basic -' Export data for external tools -data = QUERY METRICS "messages" FOR "30d" BY "1d" -WRITE "analytics_export.csv", CSV(data) - -' Or send to webhook -POST "https://bi-tool.example.com/webhook", data -``` - ---- - -## Best Practices - -1. **Set appropriate time ranges** - Don't query more data than needed -2. **Use caching** - Cache expensive queries -3. **Schedule off-peak** - Run heavy reports during low traffic -4. **Monitor the monitor** - Track analytics query performance -5. **Archive old data** - Move historical data to cold storage -6. **Validate insights** - Review AI-generated insights for accuracy - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Slow queries | Large time range | Reduce range or add filters | -| Missing data | Metrics not collected | Verify instrumentation | -| Export fails | Large report size | Export in chunks | -| Stale data | Cache not refreshed | Clear cache | -| Incorrect trends | Insufficient history | Wait for more data | - ---- - -## Use Cases - -- **Operations Teams** - Monitor platform health and performance -- **Product Managers** - Track feature usage and engagement -- **Executives** - High-level KPI dashboards -- **Support Teams** - Identify error patterns -- **Finance** - LLM cost tracking and optimization - ---- - -## Data Privacy - -- Analytics data is aggregated and anonymized -- User-level data requires appropriate permissions -- Respect data retention policies -- Comply with GDPR/CCPA as applicable - ---- - -## Related Templates - -- [BI Template](./template-bi.md) - Business Intelligence reporting -- [Talk to Data](./template-talk-to-data.md) - Natural language data queries -- [CRM](./template-crm.md) - CRM analytics and pipeline reports - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-api-client.md b/docs/src/chapter-02/template-api-client.md deleted file mode 100644 index a13ec9e1..00000000 --- a/docs/src/chapter-02/template-api-client.md +++ /dev/null @@ -1,466 +0,0 @@ -# API Client Template (api-client.gbai) - -A General Bots template demonstrating REST API integration patterns for connecting to external services and data sources. - ---- - -## Overview - -The API Client template provides examples and patterns for integrating General Bots with external REST APIs. It includes examples for weather services, Microsoft Partner Center integration, and general HTTP request patterns that can be adapted for any API. - -## Features - -- **REST API Integration** - GET, POST, PUT, DELETE request patterns -- **Authentication** - OAuth, Bearer tokens, API keys -- **Header Management** - Custom headers for API requirements -- **Pagination Support** - Handle paginated API responses -- **Data Synchronization** - Sync external data to local tables -- **Scheduled Jobs** - Automated API polling and sync - ---- - -## Package Structure - -``` -api-client.gbai/ -├── api-client.gbdialog/ -│ ├── climate.bas # Weather API example -│ └── msft-partner-center.bas # Microsoft Partner Center integration -└── api-client.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `climate.bas` | Weather API tool for getting current conditions | -| `msft-partner-center.bas` | Full Microsoft Partner Center billing sync | - ---- - -## Basic API Patterns - -### Simple GET Request - -```basic -' Get data from an API -response = GET "https://api.example.com/data" - -IF response THEN - TALK "Data received: " + response.value -ELSE - TALK "Failed to fetch data" -END IF -``` - -### POST Request with Body - -```basic -' Send data to an API -SET HEADER "Content-Type" AS "application/json" - -payload = {"name": "John", "email": "john@example.com"} -response = POST "https://api.example.com/users", payload - -IF response.id THEN - TALK "User created with ID: " + response.id -END IF -``` - -### PUT Request for Updates - -```basic -' Update existing resource -SET HEADER "Content-Type" AS "application/json" - -updates = {"status": "active", "role": "admin"} -response = PUT "https://api.example.com/users/123", updates - -TALK "User updated: " + response.status -``` - -### DELETE Request - -```basic -' Delete a resource -response = DELETE "https://api.example.com/users/123" - -IF response.deleted THEN - TALK "User deleted successfully" -END IF -``` - ---- - -## Authentication Patterns - -### API Key Authentication - -```basic -SET HEADER "X-API-Key" AS "your-api-key-here" - -response = GET "https://api.example.com/protected-resource" -``` - -### Bearer Token Authentication - -```basic -SET HEADER "Authorization" AS "Bearer " + access_token - -response = GET "https://api.example.com/user/profile" -``` - -### OAuth 2.0 Token Exchange - -```basic -' Get OAuth token -SET HEADER "Content-Type" AS "application/x-www-form-urlencoded" - -tokenResponse = POST "https://auth.example.com/oauth/token", - "grant_type=client_credentials&client_id=" + clientId + - "&client_secret=" + clientSecret - -access_token = tokenResponse.access_token - -' Use token for API calls -SET HEADER "Authorization" AS "Bearer " + access_token -data = GET "https://api.example.com/resources" -``` - -### Basic Authentication - -```basic -credentials = BASE64(username + ":" + password) -SET HEADER "Authorization" AS "Basic " + credentials - -response = GET "https://api.example.com/secure-endpoint" -``` - ---- - -## Weather API Example - -The `climate.bas` tool demonstrates a simple API integration: - -```basic -PARAM location AS "The city and state, e.g. San Francisco, CA" -PARAM unit AS "celsius", "fahrenheit" - -DESCRIPTION "Get the current weather in a given location" - -' Implementation would call weather API -' response = GET "https://api.weather.com/current?location=" + location - -RETURN weather_info -``` - -### Sample Conversation - -``` -User: What's the weather in New York? - -Bot: [Calls climate tool with location="New York"] - It's currently 72°F and sunny in New York, NY. - - Today's forecast: - 🌡️ High: 78°F / Low: 65°F - 💧 Humidity: 45% - 💨 Wind: 8 mph NW - -User: What about São Paulo in celsius? - -Bot: [Calls climate tool with location="São Paulo", unit="celsius"] - It's currently 24°C and partly cloudy in São Paulo, Brazil. - - Today's forecast: - 🌡️ High: 28°C / Low: 19°C - 💧 Humidity: 62% - 💨 Wind: 12 km/h SE -``` - ---- - -## Microsoft Partner Center Integration - -The `msft-partner-center.bas` demonstrates a complex enterprise API integration: - -### Features - -- OAuth token authentication with Azure AD -- Multi-resource synchronization (Customers, Subscriptions, Billing) -- Scheduled execution -- Pagination handling -- Database table management - -### Configuration - -```basic -' Required parameters -tenantId = GET ENV "AZURE_TENANT_ID" -clientId = GET ENV "AZURE_CLIENT_ID" -clientSecret = GET ENV "AZURE_CLIENT_SECRET" -host = "https://api.partnercenter.microsoft.com" -``` - -### Scheduled Sync - -```basic -SET SCHEDULE "1 * * * * *" ' Run periodically - -' Set required headers -SET HEADER "MS-Contract-Version" AS "v1" -SET HEADER "MS-CorrelationId" AS UUID() -SET HEADER "MS-RequestId" AS UUID() -SET HEADER "MS-PartnerCenter-Application" AS "General Bots" -SET HEADER "X-Locale" AS "en-US" -``` - -### Sync Customers and Subscriptions - -```basic -SET PAGE MODE "none" -customers = GET host + "/v1/customers?size=20000" - -MERGE "Customers" WITH customers.items BY "Id" - -FOR EACH customer IN customers - subs = GET host + "/v1/customers/" + customer.id + "/subscriptions" - MERGE "Subscriptions" WITH subs.items BY "Id" -END FOR -``` - -### Billing Data Sync - -```basic -SET PAGE MODE "auto" -billingItems = GET host + "/v1/invoices/unbilled/lineitems" + - "?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=USD" - -FOR EACH item IN billingItems - SAVE "Billing", item.alternateId, item.customerId, item.productName, - item.quantity, item.unitPrice, item.subtotal, item.chargeStartDate -END FOR -``` - -### Table Definitions - -```basic -TABLE Billing - CustomerId Customers - ResourceGroup string(200) - CustomerName string(400) - ProductName string(400) - Quantity double - UnitPrice double - Subtotal double - ChargeStartDate date - ChargeEndDate date -END TABLE - -TABLE Customers - TenantId guid - CompanyName string(100) - Id guid -END TABLE - -TABLE Subscriptions - CustomerId Customers - Id guid - OfferName string(50) -END TABLE -``` - ---- - -## Custom API Integration - -### Creating Your Own API Client - -```basic -' my-api-client.bas -PARAM resource AS STRING LIKE "users" DESCRIPTION "API resource to fetch" -PARAM filters AS STRING LIKE "status=active" DESCRIPTION "Query filters" OPTIONAL - -DESCRIPTION "Fetch data from custom API" - -' Configuration -api_base = GET ENV "MY_API_BASE_URL" -api_key = GET ENV "MY_API_KEY" - -' Set authentication -SET HEADER "Authorization" AS "Bearer " + api_key -SET HEADER "Content-Type" AS "application/json" - -' Build URL -url = api_base + "/" + resource -IF filters THEN - url = url + "?" + filters -END IF - -' Make request -response = GET url - -IF response.error THEN - RETURN {"success": false, "error": response.error} -END IF - -RETURN {"success": true, "data": response.data, "count": UBOUND(response.data)} -``` - -### Handling Pagination - -```basic -' paginated-fetch.bas -PARAM endpoint AS STRING DESCRIPTION "API endpoint" - -DESCRIPTION "Fetch all pages from a paginated API" - -all_results = [] -page = 1 -has_more = true - -DO WHILE has_more - response = GET endpoint + "?page=" + page + "&per_page=100" - - IF response.data THEN - all_results = MERGE all_results, response.data - - IF UBOUND(response.data) < 100 THEN - has_more = false - ELSE - page = page + 1 - END IF - ELSE - has_more = false - END IF -LOOP - -RETURN all_results -``` - -### Error Handling with Retry - -```basic -' api-with-retry.bas -PARAM url AS STRING DESCRIPTION "API URL to call" -PARAM max_retries AS INTEGER LIKE 3 DESCRIPTION "Maximum retry attempts" - -DESCRIPTION "API call with automatic retry on failure" - -retries = 0 -success = false - -DO WHILE retries < max_retries AND NOT success - response = GET url - - IF response.error THEN - retries = retries + 1 - WAIT retries * 2 ' Exponential backoff - ELSE - success = true - END IF -LOOP - -IF success THEN - RETURN response -ELSE - RETURN {"error": "Max retries exceeded", "last_error": response.error} -END IF -``` - ---- - -## Configuration - -Configure in `api-client.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `API Base URL` | Default API endpoint | `https://api.example.com` | -| `API Timeout` | Request timeout in seconds | `30` | -| `Retry Count` | Number of retry attempts | `3` | -| `Log Requests` | Enable request logging | `true` | - -### Environment Variables - -Store sensitive values as environment variables: - -```bash -MY_API_KEY=your-api-key -MY_API_SECRET=your-secret -AZURE_TENANT_ID=your-tenant-id -AZURE_CLIENT_ID=your-client-id -AZURE_CLIENT_SECRET=your-client-secret -``` - -Access in BASIC: - -```basic -api_key = GET ENV "MY_API_KEY" -``` - ---- - -## Common HTTP Headers - -| Header | Purpose | Example | -|--------|---------|---------| -| `Content-Type` | Request body format | `application/json` | -| `Accept` | Expected response format | `application/json` | -| `Authorization` | Authentication | `Bearer token` | -| `X-API-Key` | API key auth | `your-key` | -| `User-Agent` | Client identification | `GeneralBots/1.0` | - ---- - -## Best Practices - -1. **Secure credentials** - Never hardcode API keys; use environment variables -2. **Handle errors** - Always check for error responses -3. **Rate limiting** - Respect API rate limits with delays -4. **Pagination** - Handle paginated responses properly -5. **Logging** - Log API calls for debugging -6. **Timeouts** - Set appropriate timeout values -7. **Retries** - Implement retry logic for transient failures -8. **Caching** - Cache responses when appropriate - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| 401 Unauthorized | Invalid credentials | Check API key/token | -| 403 Forbidden | Missing permissions | Verify API access rights | -| 404 Not Found | Wrong endpoint | Verify URL path | -| 429 Too Many Requests | Rate limited | Add delays between requests | -| 500 Server Error | API issue | Retry with backoff | -| Timeout | Slow API | Increase timeout setting | - ---- - -## Use Cases - -- **Data Synchronization** - Sync data from external systems -- **Service Integration** - Connect to SaaS platforms -- **Automation** - Automate cross-system workflows -- **Monitoring** - Poll external systems for changes -- **Reporting** - Aggregate data from multiple APIs - ---- - -## Related Templates - -- [Public APIs](./template-public-apis.md) - Pre-built integrations for public APIs -- [Bling ERP](./template-bling.md) - ERP API integration example -- [LLM Server](./template-llm-server.md) - Building your own API endpoints -- [CRM](./template-crm.md) - CRM with external API sync - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-bi.md b/docs/src/chapter-02/template-bi.md deleted file mode 100644 index 164c6c88..00000000 --- a/docs/src/chapter-02/template-bi.md +++ /dev/null @@ -1,272 +0,0 @@ -# Business Intelligence Template (bi.gbai) - -A General Bots template for automated business intelligence reporting and data visualization. - ---- - -## Overview - -The BI template provides scheduled analytics reporting with automatic chart generation and delivery. It's designed for organizations that need automated consumption reports, category analysis, and customer-specific insights. - -## Features - -- **Scheduled Reporting** - Automated report generation on configurable schedules -- **Time-Series Charts** - Monthly consumption trends visualization -- **Category Analysis** - Product category breakdown with donut charts -- **Per-Customer Reports** - Individual customer consumption analysis -- **Multi-Channel Delivery** - Send reports via chat, email, or messaging platforms - ---- - -## Package Structure - -``` -bi.gbai/ -├── bi.gbai/ -│ ├── bi-admin.bas # Administrative scheduled reports -│ └── bi-user.bas # Per-customer report generation -``` - -## Scripts - -| File | Description | -|------|-------------| -| `bi-admin.bas` | Scheduled job for generating platform-wide analytics reports | -| `bi-user.bas` | Loop through customers to generate individual consumption reports | - ---- - -## Configuration - -Configure the template in your bot's `config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Schedule` | Cron expression for report timing | `1 * * * * *` | -| `Data Source` | Table/view for billing data | `Orders` | - ---- - -## Usage - -### Administrative Reports - -The `bi-admin.bas` script runs on a schedule and generates: - -1. **Monthly Consumption Chart** - Time-series showing spending trends -2. **Product Category Breakdown** - Donut chart of spending by category - -```basic -SET SCHEDULE "1 * * * * *" - -billing = FIND "Orders" - -' Monthly consumption -data = SELECT SUM(UnitPrice * Quantity) as Value, - MONTH(OrderDate)+'/'+YEAR(OrderDate) - FROM billing - GROUP BY MONTH(OrderDate), YEAR(OrderDate) - -img = CHART "timeseries", data -SEND FILE img, "Monthly Consumption" -``` - -### Per-Customer Reports - -The `bi-user.bas` script iterates through customers to generate personalized reports: - -```basic -customers = FIND "Customers" - -FOR EACH c IN customers - data = SELECT SUM(UnitPrice * Quantity) AS Value, - MONTH(OrderDate)+'/'+YEAR(OrderDate) - FROM billing - JOIN Customers ON billing.CustomerID = Customers.CustomerID - GROUP BY MONTH(OrderDate), YEAR(OrderDate) - WHERE Customers.CustomerID = c.CustomerID - - img = CHART "timeseries", data - SEND FILE img, "Monthly Consumption" -END FOR -``` - ---- - -## Chart Types - -The template supports various chart types: - -| Type | Use Case | -|------|----------| -| `timeseries` | Trends over time (monthly, weekly, daily) | -| `donut` | Category distribution | -| `bar` | Comparative analysis | -| `pie` | Percentage breakdowns | - ---- - -## Data Requirements - -### Orders Table Schema - -The template expects a billing/orders data source with: - -- `OrderDate` - Date of the transaction -- `UnitPrice` - Price per unit -- `Quantity` - Number of units -- `ProductID` - Foreign key to products -- `CustomerID` - Foreign key to customers - -### Products Table Schema - -- `ProductID` - Primary key -- `CategoryID` - Foreign key to categories -- `ProductName` - Product name - -### Categories Table Schema - -- `CategoryID` - Primary key -- `CategoryName` - Category display name - ---- - -## Example Output - -### Monthly Consumption Report - -``` -📊 Monthly Consumption Report ------------------------------ -Generated: 2024-01-15 08:00 - -[Time Series Chart Image] - -Total Revenue: $125,430 -Top Month: December ($18,500) -Growth Rate: +12% MoM -``` - -### Category Breakdown - -``` -📊 Product Category Distribution --------------------------------- - -[Donut Chart Image] - -Electronics: 35% -Clothing: 28% -Home & Garden: 22% -Other: 15% -``` - ---- - -## Customization - -### Adding New Reports - -Create additional `.bas` files in the `bi.gbai` folder: - -```basic -' sales-by-region.bas -SET SCHEDULE "0 9 * * 1" ' Every Monday at 9 AM - -data = SELECT Region, SUM(Amount) as Total - FROM Sales - GROUP BY Region - -img = CHART "bar", data -SEND FILE img, "Weekly Regional Sales" -``` - -### Customizing Delivery - -Send reports to specific users or channels: - -```basic -' Send to specific user -SEND FILE img TO "manager@company.com", "Weekly Report" - -' Send to WhatsApp -SEND FILE img TO "+1234567890", "Your monthly report" - -' Send to team channel -TALK TO "sales-team", img -``` - ---- - -## Scheduling Options - -| Schedule | Cron Expression | Description | -|----------|-----------------|-------------| -| Every minute | `1 * * * * *` | Testing/real-time | -| Hourly | `0 0 * * * *` | Frequent updates | -| Daily 8 AM | `0 0 8 * * *` | Morning reports | -| Weekly Monday | `0 0 9 * * 1` | Weekly summaries | -| Monthly 1st | `0 0 8 1 * *` | Monthly reports | - ---- - -## Integration Examples - -### With CRM - -```basic -' Combine with CRM data -opportunities = FIND "opportunities.csv" -revenue = SELECT stage, SUM(amount) FROM opportunities GROUP BY stage - -img = CHART "funnel", revenue -SEND FILE img, "Sales Pipeline" -``` - -### With ERP - -```basic -' Inventory analysis -inventory = FIND "inventory.csv" -low_stock = SELECT product, quantity FROM inventory WHERE quantity < reorder_level - -img = CHART "bar", low_stock -SEND FILE img, "Low Stock Alert" -``` - ---- - -## Best Practices - -1. **Schedule appropriately** - Don't run heavy reports too frequently -2. **Filter data** - Use date ranges to limit data volume -3. **Cache results** - Store computed metrics for faster access -4. **Log activities** - Track report generation for auditing -5. **Handle errors** - Wrap queries in error handling - ---- - -## Troubleshooting - -| Issue | Solution | -|-------|----------| -| Empty charts | Verify data source has records | -| Schedule not running | Check cron syntax | -| Slow reports | Add date filters, optimize queries | -| Missing data | Verify JOIN conditions | - ---- - -## Related Templates - -- [Platform Analytics](./template-analytics.md) - Platform metrics and monitoring -- [Talk to Data](./template-talk-to-data.md) - Natural language data queries -- [CRM](./template-crm.md) - CRM with built-in reporting - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-crawler.md b/docs/src/chapter-02/template-crawler.md deleted file mode 100644 index c81da108..00000000 --- a/docs/src/chapter-02/template-crawler.md +++ /dev/null @@ -1,330 +0,0 @@ -# Web Crawler Template (crawler.gbai) - -A General Bots template for automated web crawling and content extraction for knowledge base population. - ---- - -## Overview - -The Crawler template enables your bot to automatically fetch, parse, and index web content. It's designed for building knowledge bases from websites, monitoring web pages for changes, and extracting structured data from online sources. - -## Features - -- **Automated Web Scraping** - Fetch and parse web pages automatically -- **Document Mode** - Answer questions based on crawled content -- **Configurable Depth** - Control how many pages to crawl -- **Content Indexing** - Automatically add content to knowledge base -- **LLM Integration** - Use AI to understand and summarize crawled content - ---- - -## Package Structure - -``` -crawler.gbai/ -├── crawler.gbkb/ # Knowledge base for crawled content -│ └── docs/ # Indexed documents -└── crawler.gbot/ - └── config.csv # Crawler configuration -``` - ---- - -## Configuration - -Configure the crawler in `crawler.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Website` | Target URL to crawl | `https://pragmatismo.com.br/` | -| `website Max Documents` | Maximum pages to crawl | `2` | -| `Answer Mode` | How to respond to queries | `document` | -| `Theme Color` | UI theme color | `purple` | -| `LLM Provider` | AI provider for processing | `openai` | - -### Example config.csv - -```csv -name,value -Website,https://pragmatismo.com.br/ -website Max Documents,2 -Answer Mode,document -Theme Color,purple -LLM Provider,openai -``` - ---- - -## How It Works - -1. **Initialization** - Bot reads the target website from configuration -2. **Crawling** - Fetches pages starting from the root URL -3. **Extraction** - Parses HTML and extracts meaningful text content -4. **Indexing** - Stores content in the knowledge base for RAG -5. **Q&A** - Users can ask questions about the crawled content - ---- - -## Usage - -### Basic Setup - -1. Copy the template to your bot's packages directory: - -```bash -cp -r templates/crawler.gbai /path/to/your/bot/packages/ -``` - -2. Edit `crawler.gbot/config.csv` with your target website: - -```csv -name,value -Website,https://your-website.com/ -website Max Documents,10 -Answer Mode,document -``` - -3. Deploy and the bot will automatically crawl the configured site. - -### Querying Crawled Content - -Once crawled, users can ask questions naturally: - -- "What services does the company offer?" -- "Tell me about the pricing" -- "Summarize the about page" -- "What are the main features?" - -### Answer Modes - -| Mode | Behavior | -|------|----------| -| `document` | Answers strictly based on crawled content | -| `hybrid` | Combines crawled content with general knowledge | -| `summary` | Provides concise summaries of relevant pages | - ---- - -## Sample Conversation - -``` -User: What does this company do? - -Bot: Based on the website content: - - Pragmatismo provides enterprise AI solutions - including: - - • General Bots platform - • Custom AI development - • Conversational AI consulting - • Integration services - - 📄 Source: pragmatismo.com.br/about - -User: Do they have any case studies? - -Bot: Yes! According to the website, they have worked - with several enterprise clients: - - • Banking sector automation - • Healthcare chatbots - • E-commerce customer service - - 📄 Source: pragmatismo.com.br/cases - -User: How can I contact them? - -Bot: Contact information from the website: - - 📧 Email: contact@pragmatismo.com.br - 📍 Location: São Paulo, Brazil - 🌐 Website: pragmatismo.com.br - - 📄 Source: pragmatismo.com.br/contact -``` - ---- - -## Advanced Configuration - -### Limiting Crawl Scope - -Control which pages are crawled: - -```csv -name,value -Website,https://example.com/docs/ -website Max Documents,50 -Website Include Pattern,/docs/* -Website Exclude Pattern,/docs/archive/* -``` - -### Scheduling Recrawls - -Set up periodic recrawling to keep content fresh: - -```csv -name,value -Website Refresh Schedule,0 0 * * 0 -``` - -This example recrawls every Sunday at midnight. - -### Authentication - -For sites requiring authentication: - -```csv -name,value -Website Auth Type,basic -Website Username,user -Website Password,secret -``` - ---- - -## Customization - -### Creating Custom Crawl Logic - -Create a BASIC dialog for custom crawling: - -```basic -' custom-crawl.bas -urls = ["https://site1.com", "https://site2.com", "https://site3.com"] - -FOR EACH url IN urls - content = GET url - - IF content THEN - SAVE "crawled_pages.csv", url, content, NOW() - SET CONTEXT content - END IF -NEXT - -TALK "Crawled " + UBOUND(urls) + " pages successfully." -``` - -### Processing Crawled Content - -Use LLM to process and structure crawled data: - -```basic -' process-crawled.bas -pages = FIND "crawled_pages.csv" - -FOR EACH page IN pages - summary = LLM "Summarize this content in 3 bullet points: " + page.content - - WITH processed - url = page.url - summary = summary - processed_at = NOW() - END WITH - - SAVE "processed_content.csv", processed -NEXT -``` - -### Extracting Structured Data - -Extract specific information from pages: - -```basic -' extract-products.bas -SET CONTEXT "You are a data extraction assistant. Extract product information as JSON." - -page_content = GET "https://store.example.com/products" - -products = LLM "Extract all products with name, price, and description as JSON array: " + page_content - -SAVE "products.json", products -``` - ---- - -## Integration Examples - -### With Knowledge Base - -```basic -' Add crawled content to KB -content = GET "https://docs.example.com/api" - -IF content THEN - USE KB "api-docs.gbkb" - ADD TO KB content, "API Documentation" -END IF -``` - -### With Notifications - -```basic -' Monitor for changes -previous = GET BOT MEMORY "last_content" -current = GET "https://news.example.com" - -IF current <> previous THEN - SEND EMAIL "admin@company.com", "Website Changed", "The monitored page has been updated." - SET BOT MEMORY "last_content", current -END IF -``` - ---- - -## Best Practices - -1. **Respect robots.txt** - Only crawl pages allowed by the site's robots.txt -2. **Rate limiting** - Don't overwhelm target servers with requests -3. **Set reasonable limits** - Start with low `Max Documents` values -4. **Monitor content quality** - Review crawled content for accuracy -5. **Keep content fresh** - Schedule periodic recrawls for dynamic sites -6. **Handle errors gracefully** - Implement retry logic for failed requests - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| No content indexed | Invalid URL | Verify the Website URL is accessible | -| Partial content | Max Documents too low | Increase the limit in config | -| Stale answers | Content not refreshed | Set up scheduled recrawls | -| Authentication errors | Missing credentials | Add auth settings to config | -| Timeout errors | Slow target site | Increase timeout settings | - ---- - -## Limitations - -- JavaScript-rendered content may not be fully captured -- Some sites block automated crawlers -- Large sites may take significant time to fully crawl -- Dynamic content may require special handling - ---- - -## Use Cases - -- **Documentation Bots** - Index product docs for support -- **Competitive Intelligence** - Monitor competitor websites -- **News Aggregation** - Collect news from multiple sources -- **Research Assistants** - Build knowledge bases from academic sources -- **FAQ Generators** - Extract FAQs from help sites - ---- - -## Related Templates - -- [AI Search](./template-ai-search.md) - AI-powered document search -- [Talk to Data](./template-talk-to-data.md) - Natural language data queries -- [Law](./template-law.md) - Legal document processing with similar RAG approach - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbkb Reference](../chapter-03/README.md) - Knowledge base guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-crm-contacts.md b/docs/src/chapter-02/template-crm-contacts.md deleted file mode 100644 index e9d7bc8b..00000000 --- a/docs/src/chapter-02/template-crm-contacts.md +++ /dev/null @@ -1,303 +0,0 @@ -# CRM Contacts Template - -The CRM Contacts template provides a complete contact management solution with natural language interface. Users can add, search, update, and manage contacts through conversational interactions. - -## Overview - -| Property | Value | -|----------|-------| -| Template ID | `crm/contacts.gbai` | -| Category | CRM | -| Complexity | Intermediate | - -## Features - -- Add new contacts with validation -- Search contacts by name, email, or phone -- Update contact information -- Tag and categorize contacts -- Export contacts to CSV - -## Installation - -Copy the template folder to your work directory or use the Sources app to create from template. - -## Configuration - -Add these settings to your `config.csv`: - -| Key | Value | Description | -|-----|-------|-------------| -| `contacts-table` | `contacts` | Database table name | -| `require-email` | `true` | Require email for new contacts | -| `allow-duplicates` | `false` | Allow duplicate entries | -| `default-tags` | `lead` | Default tags for new contacts | - ---- - -## Sample Conversations - -### Adding a New Contact - - - ---- - -### Searching Contacts - - - ---- - -### Updating a Contact - - - ---- - -### Exporting Contacts - - - ---- - -## What It Can Do - -| Capability | Description | -|------------|-------------| -| Add contacts | Collect name, email, phone, company through conversation | -| Search | Find by any field - name, email, company, phone | -| Update | Modify any contact field naturally | -| Delete | Remove contacts with confirmation | -| Tags | Categorize contacts (lead, customer, prospect) | -| Export | Generate CSV files for external use | -| Bulk import | Upload CSV to add multiple contacts | - ---- - -## Customization Ideas - -### Add Custom Fields - -Configure additional fields like LinkedIn profile, job title, or lead source in your bot's `config.csv`. - -### Add Validation - -The bot validates email formats and phone numbers automatically. Configure stricter rules as needed. - -### Connect to External CRM - -Use the `POST` and `GET` keywords to sync contacts with Salesforce, HubSpot, or other CRM systems. - ---- - -## Related Templates - -- [Sales Pipeline](./templates.md) - Track deals and opportunities -- [Customer Support](./templates.md) - Support ticket management -- [Template Samples](./template-samples.md) - More conversation examples - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-02/template-crm.md b/docs/src/chapter-02/template-crm.md deleted file mode 100644 index 91ddcc74..00000000 --- a/docs/src/chapter-02/template-crm.md +++ /dev/null @@ -1,481 +0,0 @@ -# Sales CRM Template (crm.gbai) - -A comprehensive General Bots template for sales customer relationship management with lead tracking, opportunity management, and sales pipeline automation. - ---- - -## Overview - -The CRM template provides a full-featured sales CRM system with conversational AI capabilities. It enables sales teams to manage leads, track opportunities through the pipeline, generate quotes, send proposals, and forecast revenue—all through natural conversation or automated workflows. - -## Features - -- **Lead Management** - Capture, qualify, convert, and nurture leads -- **Opportunity Pipeline** - Track deals through customizable stages -- **Account Management** - Manage customer accounts and contacts -- **Activity Tracking** - Log calls, emails, meetings, and tasks -- **Quote Generation** - Create and send professional quotes -- **Proposal Automation** - Generate and deliver sales proposals -- **Sales Forecasting** - Pipeline analysis and revenue projections -- **Email Integration** - Receive and process emails automatically -- **Sentiment Analysis** - AI-powered customer sentiment tracking -- **Data Enrichment** - Automatic lead data enhancement - ---- - -## Package Structure - -``` -crm.gbai/ -├── crm.gbdialog/ -│ ├── lead-management.bas # Lead lifecycle management -│ ├── opportunity-management.bas # Opportunity pipeline -│ ├── account-management.bas # Account/company management -│ ├── activity-tracking.bas # Activity logging -│ ├── case-management.bas # Support case handling -│ ├── analyze-customer-sentiment.bas # AI sentiment analysis -│ ├── data-enrichment.bas # Lead data enhancement -│ ├── send-proposal.bas # Proposal generation -│ ├── create-lead-from-draft.bas # Email to lead conversion -│ ├── crm-jobs.bas # Scheduled background jobs -│ └── tables.bas # Database schema definitions -└── crm.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `lead-management.bas` | Complete lead lifecycle: capture, qualify, convert, follow-up, nurture | -| `opportunity-management.bas` | Pipeline stages, quotes, products, forecasting | -| `account-management.bas` | Account and contact management | -| `activity-tracking.bas` | Log and track all sales activities | -| `case-management.bas` | Customer support case handling | -| `analyze-customer-sentiment.bas` | AI-powered sentiment analysis | -| `data-enrichment.bas` | Enrich leads with external data | -| `send-proposal.bas` | Generate and send proposals | -| `on-receive-email.bas` | Process incoming emails | -| `crm-jobs.bas` | Scheduled automation tasks | -| `tables.bas` | CRM database schema | - ---- - -## Data Schema - -### Leads Table - -| Field | Type | Description | -|-------|------|-------------| -| `id` | GUID | Unique identifier | -| `name` | String | Lead name | -| `email` | Email | Email address | -| `phone` | Phone | Phone number | -| `company` | String | Company name | -| `source` | String | Lead source | -| `status` | String | new, qualified, hot, warm, cold, converted | -| `score` | Integer | Lead qualification score (0-100) | -| `assigned_to` | String | Sales rep ID | -| `created_at` | DateTime | Creation timestamp | - -### Opportunities Table - -| Field | Type | Description | -|-------|------|-------------| -| `id` | GUID | Unique identifier | -| `name` | String | Opportunity name | -| `account_id` | GUID | Related account | -| `contact_id` | GUID | Primary contact | -| `amount` | Decimal | Deal value | -| `stage` | String | Pipeline stage | -| `probability` | Integer | Win probability (0-100) | -| `close_date` | Date | Expected close date | -| `owner_id` | String | Sales rep ID | -| `lead_source` | String | Original lead source | - -### Accounts Table - -| Field | Type | Description | -|-------|------|-------------| -| `id` | GUID | Unique identifier | -| `name` | String | Company name | -| `type` | String | prospect, customer, partner | -| `industry` | String | Industry vertical | -| `owner_id` | String | Account owner | -| `created_from_lead` | GUID | Original lead ID | - -### Contacts Table - -| Field | Type | Description | -|-------|------|-------------| -| `id` | GUID | Unique identifier | -| `account_id` | GUID | Parent account | -| `name` | String | Full name | -| `email` | Email | Email address | -| `phone` | Phone | Phone number | -| `title` | String | Job title | -| `primary_contact` | Boolean | Primary contact flag | - -### Activities Table - -| Field | Type | Description | -|-------|------|-------------| -| `id` | GUID | Unique identifier | -| `type` | String | call, email, meeting, task | -| `subject` | String | Activity subject | -| `lead_id` | GUID | Related lead | -| `opportunity_id` | GUID | Related opportunity | -| `created_at` | DateTime | Activity timestamp | - ---- - -## Pipeline Stages - -| Stage | Probability | Description | -|-------|-------------|-------------| -| `qualification` | 10% | Initial qualification | -| `needs_analysis` | 20% | Understanding requirements | -| `value_proposition` | 50% | Presenting solution | -| `decision_makers` | 60% | Engaging decision makers | -| `proposal` | 75% | Proposal sent | -| `negotiation` | 90% | Terms negotiation | -| `closed_won` | 100% | Deal closed - won | -| `closed_lost` | 0% | Deal closed - lost | - ---- - -## Sample Conversations - -### Lead Capture - -``` -User: I just got a lead from the website - -Bot: Great! I'll help you capture it. What's their name? - -User: John Smith from TechCorp - -Bot: What's their email? - -User: john@techcorp.com - -Bot: ✅ Lead captured: John Smith (TechCorp) - ID: LEAD-20240115-4821 - - Would you like to qualify this lead now? -``` - -### Lead Qualification (BANT) - -``` -User: Yes, qualify the lead - -Bot: I'll ask a few questions to qualify them. - - What is TechCorp's annual revenue range? - 1. Under $1M - 2. $1M - $10M - 3. $10M - $50M - 4. Over $50M - -User: 3 - -Bot: How many employees? - -User: About 200 - -Bot: What's their timeline for making a decision? - -User: This quarter - -Bot: Do they have budget allocated? - -User: Yes - -Bot: 🔥 Hot Lead! Score: 85/100 - - This lead is a great fit. I've: - • Notified sales@company.com - • Created a follow-up task - - Would you like to convert to an opportunity? -``` - -### Opportunity Management - -``` -User: Create a new opportunity for Acme Corp - -Bot: What should we call this opportunity? - -User: Enterprise License Deal - -Bot: What is the estimated value of this deal? - -User: $50,000 - -Bot: When do you expect to close this deal? - -User: End of Q2 - -Bot: ✅ Opportunity created: Enterprise License Deal - - Account: Acme Corp - Value: $50,000 - Stage: Qualification (10%) - Close Date: June 30, 2024 -``` - -### Pipeline Update - -``` -User: Update the Acme deal to proposal stage - -Bot: Current stage: value_proposition - - Select new stage: - 1. Qualification (10%) - 2. Needs Analysis (20%) - 3. Value Proposition (50%) - 4. Decision Makers (60%) - 5. Proposal (75%) - 6. Negotiation (90%) - 7. Closed Won (100%) - 8. Closed Lost (0%) - -User: 5 - -Bot: ✅ Stage updated to proposal (75%) - - Would you like to generate a quote for this opportunity? -``` - -### Sales Forecast - -``` -User: Show me the sales forecast - -Bot: 📊 SALES FORECAST - ════════════════════════════════════════ - - Total Pipeline: $425,000 - Weighted Pipeline: $187,500 - - Quarterly Forecast: - ├── Q1: $45,000 - ├── Q2: $82,500 - ├── Q3: $35,000 - └── Q4: $25,000 - - Top Opportunities: - 1. Enterprise License - Acme Corp ($50,000) - 75% - 2. Platform Upgrade - TechStart ($35,000) - 60% - 3. Consulting Deal - DataFlow ($28,000) - 50% -``` - ---- - -## Lead Qualification Scoring - -The qualification process scores leads based on BANT criteria: - -- **Budget** - Revenue range (up to 30 points) -- **Authority** - Employee count/company size (up to 25 points) -- **Need** - Timeline urgency (up to 30 points) -- **Timeline** - Budget allocation (up to 25 points) - -### Scoring Thresholds - -| Score | Status | Action | -|-------|--------|--------| -| ≥70 | Hot Lead | Immediate follow-up | -| 50-69 | Warm Lead | 24-hour response | -| 30-49 | Cold Lead | Nurture campaign | -| <30 | Unqualified | Archive | - ---- - -## Lead Nurturing - -Automated nurture campaigns based on lead age: - -| Days | Content | -|------|---------| -| 3 | 5 Tips to Improve Your Business | -| 7 | Case Study: How We Helped Similar Companies | -| 14 | Free Consultation Offer | -| 30 | Special Limited Time Offer | - ---- - -## Configuration - -Configure in `crm.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Company Name` | Your company name | `Acme Sales` | -| `Currency` | Default currency | `USD` | -| `Tax Rate` | Default tax percentage | `10` | -| `Quote Validity Days` | Quote expiration | `30` | -| `Pipeline Stages` | Custom stage definitions | (JSON) | -| `Lead Sources` | Available lead sources | `web,referral,event` | -| `Admin Email` | Notifications email | `sales@company.com` | - ---- - -## Scheduled Jobs - -| Job | Schedule | Description | -|-----|----------|-------------| -| Lead nurturing | Daily | Send nurture emails to cold/warm leads | -| Follow-up reminders | Hourly | Alert reps of overdue follow-ups | -| Pipeline cleanup | Weekly | Archive stale opportunities | -| Forecast update | Daily | Recalculate sales forecast | -| Activity sync | Real-time | Sync emails and calendar events | - ---- - -## Email Integration - -### Receiving Emails - -```basic -' on-receive-email.bas -email_from = GET "email.from" -email_subject = GET "email.subject" -email_body = GET "email.body" - -' Check if from existing contact -contact = FIND "contacts.csv", "email = '" + email_from + "'" - -IF contact THEN - ' Log activity against contact - WITH activity - type = "email" - subject = email_subject - contact_id = contact.id - END WITH - SAVE "activities.csv", activity -ELSE - ' Create new lead from email - CALL "create-lead-from-draft.bas" -END IF -``` - -### Sending Proposals - -```basic -' send-proposal.bas -proposal = GENERATE FROM TEMPLATE "proposal_template.docx" WITH { - "company": account.name, - "contact": contact.name, - "products": opportunity_products, - "total": quote.total, - "valid_until": quote.valid_until -} - -SEND EMAIL contact.email, "Proposal: " + opportunity.name, - "Please find attached our proposal.", ATTACHMENT proposal -``` - ---- - -## AI Features - -### Customer Sentiment Analysis - -```basic -' analyze-customer-sentiment.bas -SET CONTEXT "Analyze customer communication for sentiment and buying signals." - -communications = FIND "activities.csv", "contact_id = '" + contact_id + "'" - -analysis = LLM "Analyze these customer communications and provide: - 1. Overall sentiment (positive, neutral, negative) - 2. Buying signals detected - 3. Concerns or objections - 4. Recommended next action - - Communications: " + JSON(communications) - -TALK analysis -``` - -### Data Enrichment - -```basic -' data-enrichment.bas -' Enrich lead with external data -company_info = GET "https://api.enrichment.com/company/" + lead.company - -IF company_info THEN - lead.industry = company_info.industry - lead.employee_count = company_info.employees - lead.revenue_range = company_info.revenue - lead.linkedin_url = company_info.linkedin - - UPDATE "leads.csv", lead -END IF -``` - ---- - -## Best Practices - -1. **Qualify early** - Use BANT scoring to prioritize leads -2. **Track everything** - Log all customer interactions -3. **Follow up promptly** - Hot leads within hours, warm within 24h -4. **Use automation** - Let nurture campaigns work cold leads -5. **Clean pipeline** - Archive stale opportunities regularly -6. **Forecast accurately** - Keep close dates and probabilities updated -7. **Segment leads** - Use tags and sources for better targeting - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Lead not found | Search criteria too strict | Use partial match | -| Stage not updating | Missing opportunity ID | Set opportunity in session | -| Quote not generating | Missing products | Add products to opportunity first | -| Email not sending | Missing contact email | Verify contact record | -| Forecast incorrect | Stale data | Update opportunity amounts | - ---- - -## Use Cases - -- **Inside Sales** - Lead qualification and opportunity management -- **Field Sales** - Account management and activity tracking -- **Sales Management** - Pipeline visibility and forecasting -- **Business Development** - Lead generation and nurturing -- **Customer Success** - Account health and expansion opportunities - ---- - -## Integration Points - -- **Email** - Inbound/outbound email tracking -- **Calendar** - Meeting scheduling -- **ERP** - Order and billing sync -- **Marketing Automation** - Lead handoff -- **Support Ticketing** - Case management - ---- - -## Related Templates - -- [Contacts](./template-crm-contacts.md) - Contact directory management -- [Marketing](./template-marketing.md) - Marketing automation and campaigns -- [Analytics](./template-analytics.md) - Sales analytics and reporting -- [Reminder](./template-reminder.md) - Follow-up reminders - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-law.md b/docs/src/chapter-02/template-law.md deleted file mode 100644 index bf615558..00000000 --- a/docs/src/chapter-02/template-law.md +++ /dev/null @@ -1,352 +0,0 @@ -# Legal Document Processing Template (law.gbai) - -A General Bots template for legal case management, document analysis, and AI-powered legal Q&A. - ---- - -## Overview - -The Law template enables legal professionals to load case documents, query case information using natural language, and get AI-assisted analysis of legal materials. It's designed for law firms, legal departments, and compliance teams who need efficient document-based legal research. - -## Features - -- **Case Document Loading** - Load and index PDF case files by case number -- **Document Q&A** - Ask questions about loaded legal documents -- **Context-Aware Responses** - AI responses grounded in actual case content -- **Case Summarization** - Generate summaries of case documents -- **Multi-Document Support** - Work with multiple cases simultaneously -- **Audit Trail** - Track all document access and queries - ---- - -## Package Structure - -``` -law.gbai/ -├── law.gbdialog/ -│ └── case.bas # Case loading and query handler -├── law.gbdrive/ # Case document storage -│ └── (case-*.pdf) # Case PDF files -├── law.gbkb/ # Knowledge base for legal reference -└── law.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `case.bas` | Loads case documents by number and enables document-based Q&A | - ---- - -## How It Works - -### Case Loading Flow - -1. User provides a case number (e.g., "12345") -2. Bot searches for `case-12345.pdf` in the drive -3. Document content is extracted and set as context -4. Answer mode switches to "document" for grounded responses -5. User can ask questions about the loaded case - -### Code Example - -```basic -PARAM cod AS STRING LIKE "12345" DESCRIPTION "Case number to load and query" - -DESCRIPTION "Load a legal case document by case number for Q&A and analysis" - -text = GET "case-" + cod + ".pdf" - -IF text THEN - SET CONTEXT "Based on this document, answer the person's questions:\n\n" + text - SET ANSWER MODE "document" - TALK "Case ${cod} loaded. Ask me anything about the case or request a summary." -ELSE - TALK "Case not found. Please check the case number." -END IF -``` - ---- - -## Configuration - -Configure in `law.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Answer Mode` | Response grounding mode | `document` | -| `Theme Color` | UI accent color | `navy` | -| `LLM Provider` | AI provider | `openai` | -| `Document Retention` | Days to keep loaded docs | `30` | -| `Require Authentication` | Require user login | `true` | - ---- - -## Sample Conversation - -``` -User: Load case 12345 - -Bot: Case 12345 loaded. Ask me anything about the case - or request a summary. - -User: What are the main claims in this case? - -Bot: Based on the document, the main claims are: - - 1. Breach of contract regarding the delivery terms - in Section 3.2 - 2. Failure to meet quality standards as specified - in Exhibit A - 3. Request for damages in the amount of $250,000 - - 📄 Source: Case 12345, Pages 3-5 - -User: Summarize the defendant's response - -Bot: The defendant argues that: - - • Delivery delays were caused by force majeure events - (documented in Exhibit C) - • Quality standards were met according to third-party - inspection report - • Damages claimed are excessive and not substantiated - by evidence - - 📄 Source: Case 12345, Pages 12-18 - -User: What are the key dates mentioned? - -Bot: Key dates from the case file: - - 📅 Contract signed: January 15, 2024 - 📅 Delivery due date: March 30, 2024 - 📅 Actual delivery: April 22, 2024 - 📅 Complaint filed: May 10, 2024 - 📅 Response deadline: June 15, 2024 - - 📄 Source: Case 12345, Pages 1-2 -``` - ---- - -## Document Naming Convention - -Case documents should follow this naming pattern: - -``` -case-{case_number}.pdf -``` - -Examples: -- `case-12345.pdf` -- `case-2024-CV-0001.pdf` -- `case-APPEAL-789.pdf` - ---- - -## Customization - -### Adding Case Search - -```basic -' search-cases.bas -PARAM query AS STRING DESCRIPTION "Search term for finding cases" - -DESCRIPTION "Search for cases by party name, date, or keywords" - -cases = FIND "case_index.csv", "content LIKE '%" + query + "%'" - -IF UBOUND(cases) > 0 THEN - TALK "Found " + UBOUND(cases) + " matching cases:" - - FOR EACH c IN cases - TALK "- Case " + c.case_number + ": " + c.title - NEXT -ELSE - TALK "No cases found matching: " + query -END IF -``` - -### Case Summarization - -```basic -' summarize-case.bas -PARAM cod AS STRING DESCRIPTION "Case number to summarize" - -DESCRIPTION "Generate an executive summary of a legal case" - -text = GET "case-" + cod + ".pdf" - -IF text THEN - summary = LLM "As a legal professional, provide an executive summary of this case including: - 1. Parties involved - 2. Key facts - 3. Legal issues - 4. Current status - 5. Next steps - - Document: " + text - - TALK "## Case " + cod + " Summary\n\n" + summary - - ' Save summary for future reference - SAVE "case_summaries.csv", cod, summary, NOW() -ELSE - TALK "Case not found." -END IF -``` - -### Supporting Multiple Document Types - -```basic -' load-document.bas -PARAM doc_type AS STRING LIKE "contract" DESCRIPTION "Type: case, contract, brief, motion" -PARAM doc_id AS STRING DESCRIPTION "Document identifier" - -DESCRIPTION "Load various legal document types" - -filename = doc_type + "-" + doc_id + ".pdf" -text = GET filename - -IF text THEN - SET CONTEXT "This is a legal " + doc_type + ". Answer questions based on its content:\n\n" + text - SET ANSWER MODE "document" - TALK "Loaded " + doc_type + " " + doc_id + ". Ready for questions." -ELSE - TALK "Document not found: " + filename -END IF -``` - -### Compliance Logging - -```basic -' Add audit logging to case.bas -IF text THEN - ' Log access for compliance - WITH audit_entry - timestamp = NOW() - user = GET SESSION "user_email" - case_number = cod - action = "document_access" - ip_address = GET SESSION "client_ip" - END WITH - - SAVE "legal_audit_log.csv", audit_entry - - SET CONTEXT "Based on this document..." + text -END IF -``` - ---- - -## Integration Examples - -### With Calendar - -```basic -' Schedule case deadlines -deadline = LLM "Extract the next deadline date from this case: " + text - -IF deadline THEN - CREATE CALENDAR EVENT "Case " + cod + " Deadline", deadline - TALK "Deadline added to calendar: " + deadline -END IF -``` - -### With Email - -```basic -' Email case summary to team -summary = LLM "Summarize the key points of this case in 3 paragraphs: " + text - -SEND EMAIL "legal-team@firm.com", "Case " + cod + " Summary", summary -TALK "Summary sent to legal team." -``` - -### With Document Generation - -```basic -' Generate response document -response = LLM "Draft a formal response letter addressing the claims in this case: " + text - -CREATE DRAFT response, "Response to Case " + cod -TALK "Draft response created. Review in your documents." -``` - ---- - -## Security Considerations - -1. **Access Control** - Implement role-based access for sensitive cases -2. **Audit Logging** - Log all document access for compliance -3. **Data Encryption** - Enable encryption for stored documents -4. **Session Timeout** - Configure appropriate session timeouts -5. **Authentication** - Require strong authentication for legal systems -6. **Data Retention** - Follow legal data retention requirements - ---- - -## Best Practices - -1. **Organize documents** - Use consistent naming conventions -2. **Index cases** - Maintain a searchable case index -3. **Regular backups** - Back up case documents frequently -4. **Version control** - Track document versions -5. **Clear context** - Clear previous case context before loading new cases -6. **Verify AI responses** - Always verify AI-generated legal content - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Case not found | Wrong filename | Check naming convention | -| Empty responses | Document not parsed | Verify PDF is text-based | -| Slow loading | Large document | Consider document chunking | -| Context errors | Multiple cases loaded | Clear context between cases | -| Access denied | Missing permissions | Check user authentication | - ---- - -## Limitations - -- PDF documents must be text-based (not scanned images) -- Very large documents may require chunking -- Complex legal analysis should be verified by professionals -- AI responses are assistive, not legal advice - ---- - -## Use Cases - -- **Case Research** - Quickly find relevant information in case files -- **Document Review** - AI-assisted document analysis -- **Client Communication** - Generate case status summaries -- **Deadline Tracking** - Extract and track important dates -- **Knowledge Management** - Build searchable legal knowledge bases - ---- - -## Disclaimer - -This template provides AI-assisted document analysis tools. It does not constitute legal advice. All AI-generated content should be reviewed by qualified legal professionals. Users are responsible for ensuring compliance with applicable legal and ethical standards. - ---- - -## Related Templates - -- [HIPAA Medical](./template-hipaa.md) - Healthcare compliance -- [Talk to Data](./template-talk-to-data.md) - Natural language document queries -- [AI Search](./template-ai-search.md) - AI-powered document search - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbkb Reference](../chapter-03/README.md) - Knowledge base guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-llm-server.md b/docs/src/chapter-02/template-llm-server.md deleted file mode 100644 index 092e31bd..00000000 --- a/docs/src/chapter-02/template-llm-server.md +++ /dev/null @@ -1,423 +0,0 @@ -# LLM Server Template (llm-server.gbai) - -A General Bots template for deploying LLM-powered web services that process orders and requests via API endpoints. - ---- - -## Overview - -The LLM Server template transforms General Bots into a headless API service that processes structured requests using LLM intelligence. It's designed for integrating AI-powered order processing, chatbot backends, and automated response systems into existing applications. - -## Features - -- **REST API Endpoints** - HTTP endpoints for bot interaction -- **Order Processing** - Structured JSON responses for orders -- **Product Catalog Integration** - Dynamic product menu from CSV -- **System Prompt Configuration** - Customizable AI behavior -- **Session Management** - Track conversations across requests -- **Operator Support** - Multi-operator/tenant architecture - ---- - -## Package Structure - -``` -llm-server.gbai/ -├── llm-server.gbdata/ # Data files -│ └── products.csv # Product catalog -├── llm-server.gbdialog/ -│ └── start.bas # Main dialog with system prompt -├── llm-server.gbkb/ # Knowledge base -└── llm-server.gbot/ - └── config.csv # Bot configuration -``` - ---- - -## API Endpoints - -### Start a Session - -```http -POST https://{host}/{botId}/dialogs/start -Content-Type: application/x-www-form-urlencoded - -operator=123 -userSystemId=999 -``` - -**Response:** -```json -{ - "pid": "1237189231897", - "conversationId": "abc123", - "status": "started" -} -``` - -### Send a Message - -```http -POST https://{host}/api/dk/messageBot -Content-Type: application/x-www-form-urlencoded - -pid=1237189231897 -text=I want a banana -``` - -**Response:** -```json -{ - "orderedItems": [ - { - "item": { - "id": 102, - "price": 0.30, - "name": "Banana", - "quantity": 1, - "notes": "" - } - } - ], - "userId": "123", - "accountIdentifier": "TableA", - "deliveryTypeId": 2 -} -``` - ---- - -## Configuration - -### System Prompt - -The `start.bas` defines the AI behavior: - -```basic -PARAM operator AS number LIKE 12312312 DESCRIPTION "Operator code." -DESCRIPTION It is a WebService of GB. - -products = FIND "products.csv" - -BEGIN SYSTEM PROMPT - -You are a chatbot assisting a store attendant in processing orders. Follow these rules: - -1. **Order Format**: Each order must include the product name, the table number, and the customer's name. - -2. **Product Details**: The available products are: - - ${TOYAML(products)} - -3. **JSON Response**: For each order, return a valid RFC 8259 JSON object containing: - - product name - - table number - -4. **Guidelines**: - - Do **not** engage in conversation. - - Return the response in plain text JSON format only. - -END SYSTEM PROMPT -``` - -### Product Catalog - -Create `products.csv` in the `llm-server.gbdata` folder: - -```csv -id,name,price,category,description -101,Apple,0.50,Fruit,Fresh red apple -102,Banana,0.30,Fruit,Ripe yellow banana -103,Orange,0.40,Fruit,Juicy orange -201,Milk,1.20,Dairy,1 liter whole milk -202,Cheese,2.50,Dairy,200g cheddar -``` - -### Bot Configuration - -Configure in `llm-server.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `LLM Provider` | AI model provider | `openai` | -| `LLM Model` | Specific model | `gpt-4` | -| `Max Tokens` | Response length limit | `500` | -| `Temperature` | Response creativity | `0.3` | -| `API Mode` | Enable API mode | `true` | - ---- - -## Usage Examples - -### cURL Examples - -**Start Session:** -```bash -curl -X POST https://api.example.com/llmservergbot/dialogs/start \ - -d "operator=123" \ - -d "userSystemId=999" -``` - -**Send Order:** -```bash -curl -X POST https://api.example.com/api/dk/messageBot \ - -d "pid=1237189231897" \ - -d "text=I need 2 apples and 1 milk" -``` - -### JavaScript Integration - -```javascript -async function startBotSession(operator, userId) { - const response = await fetch('https://api.example.com/llmservergbot/dialogs/start', { - method: 'POST', - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - body: new URLSearchParams({ operator, userSystemId: userId }) - }); - return response.json(); -} - -async function sendMessage(pid, text) { - const response = await fetch('https://api.example.com/api/dk/messageBot', { - method: 'POST', - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - body: new URLSearchParams({ pid, text }) - }); - return response.json(); -} - -// Usage -const session = await startBotSession('123', '999'); -const order = await sendMessage(session.pid, 'I want a banana'); -console.log(order.orderedItems); -``` - -### Python Integration - -```python -import requests - -class LLMServerClient: - def __init__(self, base_url, operator): - self.base_url = base_url - self.operator = operator - self.pid = None - - def start_session(self, user_id): - response = requests.post( - f"{self.base_url}/llmservergbot/dialogs/start", - data={"operator": self.operator, "userSystemId": user_id} - ) - self.pid = response.json()["pid"] - return self.pid - - def send_message(self, text): - response = requests.post( - f"{self.base_url}/api/dk/messageBot", - data={"pid": self.pid, "text": text} - ) - return response.json() - -# Usage -client = LLMServerClient("https://api.example.com", "123") -client.start_session("999") -order = client.send_message("I need 2 bananas") -print(order) -``` - ---- - -## Response Format - -### Order Response Structure - -```json -{ - "orderedItems": [ - { - "item": { - "id": 102, - "price": 0.30, - "name": "Banana", - "sideItems": [], - "quantity": 2, - "notes": "ripe ones please" - } - } - ], - "userId": "123", - "accountIdentifier": "Table5", - "deliveryTypeId": 2 -} -``` - -### Field Descriptions - -| Field | Type | Description | -|-------|------|-------------| -| `orderedItems` | Array | List of ordered items | -| `item.id` | Number | Product ID from catalog | -| `item.price` | Number | Unit price | -| `item.name` | String | Product name | -| `item.sideItems` | Array | Additional items | -| `item.quantity` | Number | Order quantity | -| `item.notes` | String | Special instructions | -| `userId` | String | Operator identifier | -| `accountIdentifier` | String | Table/customer identifier | -| `deliveryTypeId` | Number | Delivery method | - ---- - -## Customization - -### Custom Response Format - -Modify the system prompt for different output structures: - -```basic -BEGIN SYSTEM PROMPT -Return responses as JSON with this structure: -{ - "intent": "order|question|complaint", - "entities": [...extracted entities...], - "response": "...", - "confidence": 0.0-1.0 -} -END SYSTEM PROMPT -``` - -### Adding Validation - -```basic -' Validate order before returning -order = LLM_RESPONSE - -IF NOT order.orderedItems THEN - RETURN {"error": "No items in order", "suggestion": "Please specify products"} -END IF - -FOR EACH item IN order.orderedItems - product = FIND "products.csv", "id = " + item.item.id - IF NOT product THEN - RETURN {"error": "Invalid product ID: " + item.item.id} - END IF -NEXT - -RETURN order -``` - -### Multi-Language Support - -```basic -PARAM language AS STRING LIKE "en" DESCRIPTION "Response language" - -BEGIN SYSTEM PROMPT -Respond in ${language} language. -Available products: ${TOYAML(products)} -Return JSON format only. -END SYSTEM PROMPT -``` - ---- - -## Error Handling - -### Common Error Responses - -```json -{ - "error": "session_expired", - "message": "Please start a new session", - "code": 401 -} -``` - -```json -{ - "error": "invalid_request", - "message": "Missing required parameter: text", - "code": 400 -} -``` - -```json -{ - "error": "product_not_found", - "message": "Product 'pizza' is not in our catalog", - "code": 404 -} -``` - ---- - -## Best Practices - -1. **Keep prompts focused** - Single-purpose system prompts work better -2. **Validate responses** - Always validate LLM output before returning -3. **Handle edge cases** - Plan for invalid products, empty orders -4. **Monitor usage** - Track API calls and response times -5. **Rate limiting** - Implement rate limits for production -6. **Secure endpoints** - Use authentication for production APIs -7. **Log requests** - Maintain audit logs for debugging - ---- - -## Deployment - -### Environment Variables - -```bash -LLM_PROVIDER=openai -LLM_API_KEY=sk-... -LLM_MODEL=gpt-4 -API_RATE_LIMIT=100 -SESSION_TIMEOUT=3600 -``` - -### Docker Deployment - -```dockerfile -FROM generalbots/server:latest -COPY llm-server.gbai /app/packages/ -ENV API_MODE=true -EXPOSE 4242 -CMD ["npm", "start"] -``` - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Empty responses | System prompt too restrictive | Adjust prompt guidelines | -| Invalid JSON | LLM hallucination | Add JSON validation examples | -| Session expired | Timeout reached | Implement session refresh | -| Wrong products | Catalog not loaded | Verify products.csv path | -| Slow responses | Large catalog | Optimize product filtering | - ---- - -## Use Cases - -- **Restaurant Ordering** - Process food orders via API -- **Retail POS Integration** - AI-powered point of sale -- **Chatbot Backend** - Headless chatbot for web/mobile apps -- **Voice Assistant Backend** - Process voice-to-text commands -- **Order Automation** - Automate order entry from various sources - ---- - -## Related Templates - -- [LLM Tools](./template-llm-tools.md) - LLM with tool/function calling -- [Store](./template-store.md) - Full e-commerce with order processing -- [API Client](./template-api-client.md) - API integration examples - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-llm-tools.md b/docs/src/chapter-02/template-llm-tools.md deleted file mode 100644 index 29fd89dd..00000000 --- a/docs/src/chapter-02/template-llm-tools.md +++ /dev/null @@ -1,450 +0,0 @@ -# LLM Tools Template (llm-tools.gbai) - -A General Bots template demonstrating how to create and register custom tools (functions) that LLMs can call during conversations. - ---- - -## Overview - -The LLM Tools template shows how to extend your bot's capabilities by creating tools that the AI can invoke automatically. Tools enable the LLM to perform actions like database lookups, API calls, calculations, and more—all triggered naturally through conversation. - -## Features - -- **Custom Tool Registration** - Define tools the LLM can call -- **Parameter Validation** - Type-safe tool parameters with descriptions -- **Knowledge Base Integration** - Combine tools with RAG -- **Natural Interaction** - Users don't need to know tool names -- **Extensible Architecture** - Easy to add new tools - ---- - -## Package Structure - -``` -llm-tools.gbai/ -├── llm-tools.gbdata/ # Data files for tools -│ └── products.csv # Product catalog -├── llm-tools.gbdialog/ -│ ├── start.bas # Main dialog with tool registration -│ └── get-price.bas # Example tool implementation -├── llm-tools.gbkb/ # Knowledge base -│ └── products.gbkb/ # Product documentation -└── llm-tools.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `start.bas` | Registers tools, configures context, and sets system prompt | -| `get-price.bas` | Example tool that looks up product prices | - ---- - -## How Tools Work - -### 1. Tool Registration - -In `start.bas`, tools are registered with `ADD TOOL`: - -```basic -ADD TOOL "get-price" - -USE KB "products.gbkb" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "price" AS "Check product price" -ADD SUGGESTION "products" AS "View products" -ADD SUGGESTION "help" AS "How to use" - -BEGIN TALK -**Product Assistant** - -I can help you check product prices and information. - -Just ask me about any product and I'll look it up for you. -END TALK - -BEGIN SYSTEM PROMPT -You are a product assistant with access to internal tools. - -When get-price returns -1, the product does not exist. -When asked about a price, use the get-price tool and return the result. - -Do not expose tool names to users - just act on their requests naturally. -END SYSTEM PROMPT -``` - -### 2. Tool Implementation - -Each tool is a separate `.bas` file with `PARAM` and `DESCRIPTION`: - -```basic -PARAM product AS STRING LIKE "fax" DESCRIPTION "Name of the product to get price for" - -DESCRIPTION "Get the price of a product by name from the product catalog" - -productRecord = FIND "products.csv", "name = ${product}" - -IF productRecord THEN - RETURN productRecord.price -ELSE - RETURN -1 -END IF -``` - -### 3. LLM Invocation - -When a user asks "How much is the fax machine?", the LLM: -1. Recognizes this requires price information -2. Calls `get-price` with `product="fax"` -3. Receives the price (or -1 if not found) -4. Formulates a natural response - ---- - -## Sample Conversation - -``` -User: How much does the wireless mouse cost? - -Bot: [Calls get-price with product="wireless mouse"] - The wireless mouse is $29.99. - -User: What about the keyboard? - -Bot: [Calls get-price with product="keyboard"] - The standard keyboard is $49.99. We also have a - mechanical keyboard for $89.99. - -User: Is the laptop in stock and what's the price? - -Bot: [Calls get-price with product="laptop"] - [Calls check-inventory with sku="LAPTOP-001"] - The laptop is $999. Good news - we have 12 units - available in our main warehouse! - -User: I want 3 monitors with my 20% employee discount - -Bot: [Calls get-price with product="monitor"] - [Calls calculate-discount with price=299, percent=20] - Each monitor is $299, but with your 20% employee - discount, you'll pay $239.20 each. - For 3 monitors: $717.60 (saving $179.40)! -``` - ---- - -## Creating Custom Tools - -### Tool Anatomy - -Every tool needs: -- **PARAM declarations** - Input parameters with types and examples -- **DESCRIPTION** - What the tool does (for LLM understanding) -- **Implementation** - The actual logic -- **RETURN** - The output value - -### Parameter Types - -| Type | Description | Example | -|------|-------------|---------| -| `STRING` | Text input | `PARAM name AS STRING LIKE "John"` | -| `NUMBER` | Numeric input | `PARAM quantity AS NUMBER LIKE 5` | -| `INTEGER` | Whole numbers | `PARAM count AS INTEGER LIKE 10` | -| `BOOLEAN` | True/false | `PARAM active AS BOOLEAN` | -| `DATE` | Date values | `PARAM start AS DATE LIKE "2024-01-15"` | -| `EMAIL` | Email addresses | `PARAM email AS EMAIL` | -| `PHONE` | Phone numbers | `PARAM phone AS PHONE` | -| `OBJECT` | JSON objects | `PARAM data AS OBJECT` | - ---- - -## Example Tools - -### Database Lookup Tool - -```basic -' lookup-customer.bas -PARAM customer_id AS STRING LIKE "CUST-001" DESCRIPTION "Customer ID to look up" - -DESCRIPTION "Retrieve customer information by ID" - -customer = FIND "customers.csv", "id = ${customer_id}" - -IF customer THEN - WITH result - name = customer.name - email = customer.email - status = customer.status - since = customer.created_at - END WITH - RETURN result -ELSE - RETURN NULL -END IF -``` - -### Calculation Tool - -```basic -' calculate-discount.bas -PARAM original_price AS NUMBER LIKE 100 DESCRIPTION "Original product price" -PARAM discount_percent AS NUMBER LIKE 15 DESCRIPTION "Discount percentage" - -DESCRIPTION "Calculate the final price after applying a discount" - -discount_amount = original_price * (discount_percent / 100) -final_price = original_price - discount_amount - -WITH result - original = original_price - discount = discount_amount - final = final_price - savings = discount_percent + "% off" -END WITH - -RETURN result -``` - -### API Integration Tool - -```basic -' check-inventory.bas -PARAM sku AS STRING LIKE "SKU-12345" DESCRIPTION "Product SKU to check" -PARAM warehouse AS STRING LIKE "main" DESCRIPTION "Warehouse location" OPTIONAL - -DESCRIPTION "Check real-time inventory levels for a product" - -IF NOT warehouse THEN - warehouse = "main" -END IF - -SET HEADER "Authorization" AS "Bearer " + GET ENV "INVENTORY_API_KEY" -response = GET "https://api.inventory.com/stock/" + sku + "?warehouse=" + warehouse - -IF response.error THEN - RETURN {"available": false, "error": response.error} -END IF - -WITH result - sku = sku - available = response.quantity > 0 - quantity = response.quantity - warehouse = warehouse - last_updated = response.timestamp -END WITH - -RETURN result -``` - -### Email Sending Tool - -```basic -' send-notification.bas -PARAM recipient AS EMAIL LIKE "user@example.com" DESCRIPTION "Email recipient" -PARAM subject AS STRING LIKE "Order Confirmation" DESCRIPTION "Email subject" -PARAM message AS STRING DESCRIPTION "Email body content" - -DESCRIPTION "Send an email notification to a customer" - -SEND EMAIL recipient, subject, message - -WITH result - sent = true - recipient = recipient - timestamp = NOW() -END WITH - -RETURN result -``` - ---- - -## Tool Registration Patterns - -### Single Tool - -```basic -ADD TOOL "get-price" -``` - -### Multiple Tools - -```basic -ADD TOOL "get-price" -ADD TOOL "check-inventory" -ADD TOOL "lookup-customer" -ADD TOOL "calculate-discount" -ADD TOOL "send-notification" -``` - -### Conditional Tools - -```basic -user_role = GET SESSION "user_role" - -ADD TOOL "get-price" -ADD TOOL "check-inventory" - -IF user_role = "admin" THEN - ADD TOOL "update-price" - ADD TOOL "delete-product" -END IF -``` - ---- - -## System Prompt Best Practices - -Guide the LLM on when and how to use tools: - -```basic -BEGIN SYSTEM PROMPT -You are a helpful product assistant with access to the following capabilities: - -**Available Tools:** -- get-price: Look up product prices by name -- check-inventory: Check stock availability -- calculate-discount: Calculate prices with discounts - -**Guidelines:** -1. When users ask about prices, use the get-price tool -2. When asked about availability, use check-inventory -3. If a tool returns an error, explain politely that the item wasn't found -4. Never mention tool names to users - just provide the information naturally -5. Combine multiple tool results when needed to answer complex questions - -**Error Handling:** -- If get-price returns -1, the product doesn't exist -- If check-inventory shows quantity 0, inform the user it's out of stock -END SYSTEM PROMPT -``` - ---- - -## Configuration - -Configure in `llm-tools.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `LLM Provider` | AI provider | `openai` | -| `LLM Model` | Model for tool calls | `gpt-4` | -| `Tool Timeout` | Max tool execution time | `30` | -| `Max Tool Calls` | Limit per conversation | `10` | - ---- - -## Error Handling - -### In Tool Implementation - -```basic -' get-price.bas with error handling -PARAM product AS STRING LIKE "laptop" DESCRIPTION "Product name" - -DESCRIPTION "Get product price with error handling" - -ON ERROR GOTO HandleError - -productRecord = FIND "products.csv", "name LIKE '%" + product + "%'" - -IF productRecord THEN - RETURN productRecord.price -ELSE - RETURN {"error": "not_found", "message": "Product not in catalog"} -END IF - -HandleError: - RETURN {"error": "system_error", "message": "Unable to look up price"} -``` - -### In System Prompt - -```basic -BEGIN SYSTEM PROMPT -When tools return errors: -- "not_found": Apologize and suggest similar products -- "out_of_stock": Offer to notify when back in stock -- "system_error": Ask user to try again later -END SYSTEM PROMPT -``` - ---- - -## Testing Tools - -### Manual Testing - -```basic -' test-tools.bas -result = CALL "get-price", {"product": "laptop"} -TALK "Price result: " + JSON(result) - -result = CALL "check-inventory", {"sku": "LAPTOP-001"} -TALK "Inventory result: " + JSON(result) -``` - -### Conversation Testing - -Test various phrasings to ensure tool invocation: - -- "What's the price of X?" -- "How much does X cost?" -- "Price for X please" -- "X price?" -- "Can you tell me what X costs?" - ---- - -## Best Practices - -1. **Clear descriptions** - Help the LLM understand when to use each tool -2. **Good examples** - LIKE clauses guide parameter format -3. **Handle errors** - Always return meaningful error responses -4. **Validate input** - Check parameters before processing -5. **Log tool calls** - Track usage for debugging -6. **Keep tools focused** - One tool, one purpose -7. **Test thoroughly** - Various phrasings should trigger correct tools - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Tool not called | Description unclear | Improve DESCRIPTION text | -| Wrong parameters | Examples missing | Add LIKE examples | -| Tool errors | Missing validation | Add error handling | -| Slow responses | Complex tool logic | Optimize or cache | -| Tool exposed to user | System prompt issue | Add "don't mention tools" | - ---- - -## Use Cases - -- **Product Lookup** - Price, availability, specifications -- **Customer Service** - Order status, account info -- **Calculations** - Quotes, discounts, shipping -- **Integrations** - CRM, ERP, external APIs -- **Data Access** - Database queries, report generation - ---- - -## Related Templates - -- [LLM Server](./template-llm-server.md) - Headless API with LLM processing -- [CRM](./template-crm.md) - CRM with many tool examples -- [Store](./template-store.md) - E-commerce with product tools -- [Talk to Data](./template-talk-to-data.md) - Data query tools - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-marketing.md b/docs/src/chapter-02/template-marketing.md deleted file mode 100644 index 9697a40b..00000000 --- a/docs/src/chapter-02/template-marketing.md +++ /dev/null @@ -1,446 +0,0 @@ -# Marketing Automation Template (marketing.gbai) - -A General Bots template for marketing campaign management, content creation, and multi-channel broadcast messaging. - ---- - -## Overview - -The Marketing template provides marketing automation capabilities including campaign management, content ideation, image generation, social media posting, and WhatsApp broadcast messaging. It enables marketing teams to create, schedule, and deliver campaigns through conversational AI. - -## Features - -- **Campaign Management** - Create and organize marketing campaigns -- **Content Ideation** - AI-assisted content idea generation -- **Image Generation** - AI-powered marketing visuals -- **Social Media Posting** - Direct posting to Instagram and other platforms -- **WhatsApp Broadcasts** - Mass messaging with template support -- **Contact Segmentation** - Target specific audience segments -- **Template Compliance** - META-approved template validation -- **Broadcast Logging** - Track delivery and engagement - ---- - -## Package Structure - -``` -marketing.gbai/ -├── marketing.gbdialog/ -│ ├── add-new-idea.bas # Content ideation tool -│ ├── broadcast.bas # WhatsApp broadcast messaging -│ ├── get-image.bas # AI image generation -│ ├── post-to-instagram.bas # Instagram posting -│ ├── poster.bas # Marketing poster creation -│ └── campaigns/ # Campaign templates -└── marketing.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `add-new-idea.bas` | Generate and save marketing content ideas | -| `broadcast.bas` | Send WhatsApp broadcasts to contact lists | -| `get-image.bas` | Generate marketing images with AI | -| `post-to-instagram.bas` | Post content to Instagram | -| `poster.bas` | Create marketing posters and visuals | - ---- - -## WhatsApp Broadcast - -The `broadcast.bas` script enables mass WhatsApp messaging with template support: - -### Parameters - -| Parameter | Type | Description | Example | -|-----------|------|-------------|---------| -| `message` | STRING | Message with variables | `"Olá {name}, confira nossas novidades!"` | -| `template_file` | FILE | Header image for template | `header.jpg` | -| `list_file` | FILE | Contact list with phone numbers | `contacts.xlsx` | -| `filter` | STRING | Optional filter condition | `"Perfil=VIP"` | - -### Template Compliance - -The system validates messages for META WhatsApp template approval: - -```basic -report = LLM "Esta mensagem será aprovada pelo WhatsApp META como Template? - Responda OK se sim, ou explique o problema: " + message - -IF report <> "OK" THEN - TALK "Atenção: " + report -END IF -``` - -### Broadcast Execution - -```basic -IF filter THEN - list = FIND list_file, filter -ELSE - list = FIND list_file -END IF - -index = 1 -sent = 0 - -DO WHILE index < UBOUND(list) - row = list[index] - - SEND TEMPLATE TO row.telefone, template_file - - WAIT 0.1 ' Rate limiting - - ' Log delivery - WITH logEntry - timestamp = NOW() - phone = row.telefone - name = row.name - status = "sent" - END WITH - - SAVE "broadcast_log.csv", logEntry - - sent = sent + 1 - index = index + 1 -LOOP - -TALK "Broadcast enviado para " + sent + " contatos." -``` - ---- - -## Contact List Format - -The contact file should include: - -| Column | Required | Description | -|--------|----------|-------------| -| `telefone` | Yes | Phone number with country code | -| `name` | No | Contact name for personalization | -| `email` | No | Email address | -| `Perfil` | No | Segment tag for filtering | - -### Example contacts.xlsx - -```csv -telefone,name,email,Perfil -+5511999999999,João Silva,joao@email.com,VIP -+5511888888888,Maria Santos,maria@email.com,Regular -+5511777777777,Pedro Costa,pedro@email.com,VIP -``` - ---- - -## Sample Conversations - -### Creating a Broadcast - -``` -User: Send a broadcast to VIP customers - -Bot: I'll help you create a broadcast. What's the message? - -User: Olá {name}, aproveite 20% de desconto esta semana! - -Bot: Checking template compliance... - ✅ Message approved for WhatsApp template. - - Do you have a header image? - -User: Yes, use promo-banner.jpg - -Bot: Which contact list should I use? - -User: contacts.xlsx - -Bot: 📤 Broadcast Preview: - - Message: Olá {name}, aproveite 20% de desconto esta semana! - Image: promo-banner.jpg - Recipients: 127 VIP customers - - Send now or schedule? - -User: Send now - -Bot: 📤 Broadcasting... - ✅ Broadcast complete! Sent to 127 contacts. - - View delivery report in Analytics. -``` - -### Content Ideation - -``` -User: I need content ideas for our new product launch - -Bot: What product are you launching? - -User: Wireless headphones - -Bot: What platform are you targeting? - -User: Instagram - -Bot: Here are 5 content ideas for your wireless headphones launch: - - 1. "Experience Sound Like Never Before 🎧" - Key message: Premium audio quality - CTA: Shop now, link in bio - Hashtags: #WirelessFreedom #AudioExperience #NewLaunch - - 2. "Cut the Cord, Not the Quality" - Key message: Freedom without compromise - CTA: Pre-order today - Hashtags: #WirelessAudio #TechLife #MusicLovers - - 3. "Your Music. Your Freedom." - Key message: Lifestyle integration - CTA: Discover more - Hashtags: #OnTheGo #Wireless #Premium - - 4. "30 Hours of Pure Sound" - Key message: Battery life - CTA: Learn more - Hashtags: #AllDayBattery #WirelessHeadphones - - 5. "Studio Sound, Everywhere" - Key message: Professional quality - CTA: Experience now - Hashtags: #StudioQuality #Audiophile #TechGear - - Would you like me to generate images for any of these? -``` - -### Image Generation - -``` -User: Generate an image for idea 1 - -Bot: Generating marketing image... - - Prompt: "Premium wireless headphones floating in space with - sound waves emanating, modern minimalist style, product - photography, dark background with purple accent lighting" - - [Generated Image] - - ✅ Image generated! Would you like to: - 1. Post to Instagram - 2. Use in a broadcast - 3. Generate variations - 4. Download - -User: Post to Instagram - -Bot: What caption should I use? - -User: Experience Sound Like Never Before 🎧 #WirelessFreedom #NewLaunch - -Bot: ✅ Posted to Instagram! - - Post ID: 12345678 - Time: May 15, 2025 at 2:30 PM - - Track engagement in Analytics. -``` - ---- - -## Audience Segmentation - -### Filter Examples - -| Filter | Description | -|--------|-------------| -| `Perfil=VIP` | VIP customers only | -| `Perfil=Regular AND compras>5` | Regular customers with 5+ purchases | -| `ultima_compra>2024-01-01` | Recent purchasers | -| `cidade=São Paulo` | Location-based | -| `interesse=electronics` | Interest-based | - -### Building Segments - -```basic -' Create reusable segments -WITH segment - id = "SEG-" + FORMAT(GUID()) - name = "VIP São Paulo" - filter = "Perfil=VIP AND cidade=São Paulo" - count = COUNT(FIND "contacts.xlsx", filter) - created_at = NOW() -END WITH - -SAVE "segments.csv", segment -``` - ---- - -## Configuration - -Configure in `marketing.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Brand Color` | Primary brand color | `#FF5722` | -| `Logo File` | Company logo path | `logo.png` | -| `Instagram Account` | Connected IG account | `@mycompany` | -| `WhatsApp Business ID` | WA Business account | `123456789` | -| `Default Template` | Default broadcast template | `marketing_update` | -| `Rate Limit` | Messages per second | `10` | -| `Max Broadcast Size` | Maximum recipients | `1000` | - ---- - -## Analytics & Reporting - -### Broadcast Analytics - -```basic -' Get broadcast statistics -broadcast_id = "BROADCAST-20240115-1234" -logs = FIND "broadcast_log.csv", "broadcast_id = '" + broadcast_id + "'" - -total_sent = COUNT(logs) -delivered = COUNT(FIND logs, "status = 'delivered'") -read = COUNT(FIND logs, "status = 'read'") -clicked = COUNT(FIND logs, "status = 'clicked'") - -TALK "📊 Broadcast Report" -TALK "Total Sent: " + total_sent -TALK "Delivered: " + delivered + " (" + (delivered/total_sent*100) + "%)" -TALK "Read: " + read + " (" + (read/total_sent*100) + "%)" -TALK "Clicked: " + clicked + " (" + (clicked/total_sent*100) + "%)" -``` - ---- - -## Customization - -### Adding Campaign Types - -```basic -' campaign-email.bas -PARAM subject AS STRING DESCRIPTION "Email subject line" -PARAM body AS STRING DESCRIPTION "Email body content" -PARAM list_file AS FILE DESCRIPTION "Contact list" -PARAM filter AS STRING DESCRIPTION "Segment filter" OPTIONAL - -DESCRIPTION "Send email marketing campaign" - -IF filter THEN - contacts = FIND list_file, filter -ELSE - contacts = FIND list_file -END IF - -FOR EACH contact IN contacts - personalized_body = REPLACE(body, "{name}", contact.name) - SEND EMAIL contact.email, subject, personalized_body - - WITH log - campaign_id = campaign_id - contact_email = contact.email - sent_at = NOW() - status = "sent" - END WITH - - SAVE "email_campaign_log.csv", log -NEXT - -TALK "Email campaign sent to " + UBOUND(contacts) + " recipients." -``` - -### Social Media Scheduling - -```basic -' schedule-post.bas -PARAM platform AS STRING LIKE "instagram" DESCRIPTION "Social platform" -PARAM content AS STRING DESCRIPTION "Post content" -PARAM image AS FILE DESCRIPTION "Post image" OPTIONAL -PARAM schedule_time AS STRING DESCRIPTION "When to post" - -DESCRIPTION "Schedule social media post" - -WITH scheduled_post - id = "POST-" + FORMAT(GUID()) - platform = platform - content = content - image = image - scheduled_for = schedule_time - status = "scheduled" - created_at = NOW() -END WITH - -SAVE "scheduled_posts.csv", scheduled_post - -SET SCHEDULE schedule_time, "execute-scheduled-post.bas" - -TALK "Post scheduled for " + schedule_time + " on " + platform -``` - ---- - -## Best Practices - -1. **Template compliance** - Always validate templates before broadcast -2. **Segment wisely** - Target relevant audiences to improve engagement -3. **Rate limiting** - Respect platform rate limits to avoid blocks -4. **Personalization** - Use variables for personalized messages -5. **A/B testing** - Test different messages with small segments first -6. **Timing** - Schedule broadcasts for optimal engagement times -7. **Tracking** - Monitor delivery and engagement metrics -8. **Opt-out handling** - Honor unsubscribe requests immediately - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Template rejected | Non-compliant content | Review META guidelines | -| Low delivery rate | Invalid phone numbers | Clean contact list | -| Broadcast blocked | Rate limit exceeded | Reduce sending speed | -| Images not generating | Invalid prompt | Simplify prompt text | -| Instagram post failed | Auth expired | Reconnect account | - ---- - -## Compliance Notes - -- Ensure recipients have opted in to receive marketing messages -- Honor unsubscribe requests within 24 hours -- Follow META WhatsApp Business policies -- Comply with GDPR/LGPD data protection requirements -- Keep records of consent for audit purposes - ---- - -## Use Cases - -- **Product Launches** - Announce new products to customers -- **Promotions** - Send special offers and discounts -- **Events** - Promote webinars, sales, and events -- **Newsletters** - Regular customer communications -- **Re-engagement** - Win back inactive customers -- **Social Media** - Automated content posting - ---- - -## Related Templates - -- [CRM](./template-crm.md) - Customer relationship management -- [Contacts](./template-crm-contacts.md) - Contact list management -- [Broadcast](./template-broadcast.md) - General message broadcasting -- [Analytics](./template-analytics.md) - Marketing analytics - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-office.md b/docs/src/chapter-02/template-office.md deleted file mode 100644 index ebec2bcd..00000000 --- a/docs/src/chapter-02/template-office.md +++ /dev/null @@ -1,394 +0,0 @@ -# Office Automation Template (office.gbai) - -A General Bots template for role-based office productivity with department-specific knowledge bases and context-aware assistance. - ---- - -## Overview - -The Office template provides a multi-role office assistant that adapts its behavior, knowledge, and suggestions based on the user's role. Whether you're a manager, developer, customer support agent, HR professional, or finance team member, the bot tailors its responses and available resources accordingly. - -## Features - -- **Role-Based Access** - Different capabilities per user role -- **Dynamic Knowledge Bases** - Automatically loads relevant KB per role -- **Context-Aware Responses** - AI behavior adapts to role requirements -- **Custom Suggestions** - Role-specific quick actions -- **Tool Integration** - Calendar, tasks, documents, meetings, notes -- **Persistent Role Memory** - Remembers user role across sessions - ---- - -## Package Structure - -``` -office.gbai/ -├── office.gbdialog/ -│ ├── start.bas # Role selection and configuration -│ ├── api-integration.bas # External API connections -│ ├── data-sync.bas # Data synchronization -│ └── document-processor.bas # Document handling -├── office.gbkb/ # Knowledge bases by role -│ ├── management/ -│ ├── documentation/ -│ ├── products/ -│ ├── hr-policies/ -│ └── budgets/ -└── office.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `start.bas` | Main entry with role selection and context setup | -| `api-integration.bas` | Connect to external office systems | -| `data-sync.bas` | Sync data across office applications | -| `document-processor.bas` | Process and manage documents | - ---- - -## Supported Roles - -### Manager - -- **Context**: Executive assistant for reports, team management, strategic decisions -- **Knowledge Bases**: management, reports, team-policies -- **Suggestions**: Team performance, Generate report, Schedule meeting - -### Developer - -- **Context**: Technical assistant for documentation, APIs, coding best practices -- **Knowledge Bases**: documentation, apis, coding-standards -- **Suggestions**: Search documentation, API reference, Code review checklist - -### Customer Support - -- **Context**: Customer service assistant focused on resolving issues -- **Knowledge Bases**: products, support, faq -- **Suggestions**: Track my order, Product information, Contact support - -### HR - -- **Context**: HR assistant for employee matters, policies, benefits -- **Knowledge Bases**: hr-policies, benefits, onboarding -- **Suggestions**: Employee handbook, Benefits overview, New hire checklist - -### Finance - -- **Context**: Finance assistant for budgets, expenses, financial reports -- **Knowledge Bases**: budgets, expenses, financial-reports -- **Suggestions**: Expense policy, Budget status, Approval workflow - ---- - -## Available Tools - -| Tool | Description | -|------|-------------| -| `calendar` | Schedule and manage appointments | -| `tasks` | Create and track to-do items | -| `documents` | Access and manage documents | -| `meetings` | Schedule and join meetings | -| `notes` | Create and search notes | - ---- - -## Sample Conversation - -### Role Selection - -``` -Bot: Welcome to the Office Assistant! - Please select your role: - -User: manager - -Bot: Welcome, Manager! I can help with reports, team - management, and policies. - - Quick Actions: - • Team performance - • Generate report - • Schedule meeting -``` - -### Manager Interaction - -``` -User: I need to review my team's performance - -Bot: I'll help you review team performance. Here's a summary: - - 📊 Team Performance Dashboard - - Active Projects: 5 - Completed This Month: 3 - - Top Performers: - • Sarah Chen: 12 tasks completed - • Mike Johnson: 10 tasks completed - - Pending Approvals: 2 - - Would you like a detailed report or to schedule 1:1s? -``` - -### Developer Interaction - -``` -User: How do I implement pagination in our API? - -Bot: Based on our API documentation, here's the pagination pattern: - - GET /api/v1/users?page=1&per_page=20 - - Response includes: - • data: Array of results - • meta.total: Total count - • meta.page: Current page - • links.next: Next page URL - - Our coding standards recommend cursor-based pagination - for large datasets. - - 📄 Source: docs/api/pagination.md -``` - -### Customer Support Interaction - -``` -User: Customer asking about order #12345 - -Bot: I found order #12345. Here are the details: - - 📦 Order Status: Shipped - 📅 Shipped: May 14, 2025 - 🚚 Carrier: FedEx - 📍 Tracking: 7891234567890 - - Expected delivery: May 17, 2025 - - Would you like to: - • Send tracking info to customer - • Create a support ticket - • Escalate to supervisor -``` - ---- - -## Configuration - -Configure in `office.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Default Role` | Role when none selected | `customer` | -| `Remember Role` | Persist role across sessions | `true` | -| `Role Timeout` | Hours before re-asking role | `24` | -| `Theme Color` | UI accent color | `blue` | - ---- - -## How It Works - -### Role Detection and Setup - -```basic -ADD TOOL "calendar" -ADD TOOL "tasks" -ADD TOOL "documents" -ADD TOOL "meetings" -ADD TOOL "notes" - -role = GET role - -IF NOT role THEN - TALK "Welcome to the Office Assistant!" - TALK "Please select your role:" - HEAR role AS NAME - role = LOWER(role) - SET role, role -END IF - -SWITCH role - CASE "manager" - SET CONTEXT "You are an executive assistant helping managers..." - USE KB "management" - USE KB "reports" - USE KB "team-policies" - TALK "Welcome, Manager! I can help with reports and team management." - - CASE "developer" - SET CONTEXT "You are a technical assistant helping developers..." - USE KB "documentation" - USE KB "apis" - USE KB "coding-standards" - TALK "Welcome, Developer! I can help with documentation and APIs." - - ' ... more roles -END SWITCH -``` - -### Dynamic Suggestions - -```basic -CLEAR SUGGESTIONS - -SWITCH role - CASE "manager" - ADD SUGGESTION "performance" AS "Team performance" - ADD SUGGESTION "report" AS "Generate report" - ADD SUGGESTION "meeting" AS "Schedule meeting" - - CASE "developer" - ADD SUGGESTION "docs" AS "Search documentation" - ADD SUGGESTION "api" AS "API reference" - ADD SUGGESTION "review" AS "Code review checklist" - - CASE "customer" - ADD SUGGESTION "order" AS "Track my order" - ADD SUGGESTION "product" AS "Product information" - ADD SUGGESTION "support" AS "Contact support" -END SWITCH -``` - ---- - -## Customization - -### Adding New Roles - -Extend the `start.bas` file: - -```basic -CASE "sales" - SET CONTEXT "You are a sales assistant helping with leads and deals." - USE KB "sales-playbook" - USE KB "pricing" - USE KB "competitors" - TALK "Welcome, Sales! I can help with leads, pricing, and proposals." - - CLEAR SUGGESTIONS - ADD SUGGESTION "leads" AS "View my leads" - ADD SUGGESTION "quote" AS "Generate quote" - ADD SUGGESTION "pipeline" AS "Pipeline status" -``` - -### Custom Knowledge Bases - -Create role-specific knowledge bases in `office.gbkb/`: - -``` -office.gbkb/ -├── sales-playbook/ -│ ├── objection-handling.md -│ ├── pricing-guide.md -│ └── competitor-comparison.md -``` - -### Role-Specific Tools - -Register different tools per role: - -```basic -CASE "manager" - ADD TOOL "calendar" - ADD TOOL "tasks" - ADD TOOL "team-report" - ADD TOOL "approve-request" - -CASE "developer" - ADD TOOL "search-docs" - ADD TOOL "api-tester" - ADD TOOL "code-review" -``` - ---- - -## Integration Examples - -### With Calendar - -```basic -' Schedule meeting for manager -IF role = "manager" THEN - TALK "I'll schedule the team meeting." - CREATE CALENDAR EVENT "Team Standup", tomorrow + " 9:00 AM", 30 -END IF -``` - -### With Document System - -```basic -' Generate document based on role -SWITCH role - CASE "hr" - template = "offer-letter-template.docx" - CASE "sales" - template = "proposal-template.docx" - CASE "finance" - template = "budget-template.xlsx" -END SWITCH - -document = GENERATE FROM TEMPLATE template WITH data -``` - -### With Task Management - -```basic -' Create role-appropriate tasks -IF role = "manager" THEN - CREATE TASK "Review Q4 budget", "high", manager_email - CREATE TASK "Approve team PTO requests", "medium", manager_email -END IF -``` - ---- - -## Best Practices - -1. **Clear role definitions** - Define clear boundaries for each role -2. **Relevant suggestions** - Keep quick actions useful for each role -3. **Appropriate KBs** - Only load necessary knowledge bases -4. **Security awareness** - Restrict sensitive data by role -5. **Regular updates** - Keep knowledge bases current -6. **Feedback loops** - Monitor which features each role uses - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Wrong KB loaded | Role not set correctly | Check role detection logic | -| Missing suggestions | Role not in switch | Add role to all switch blocks | -| Context confusion | Multiple roles used | Clear context between role changes | -| Slow responses | Too many KBs loaded | Load only essential KBs per role | - ---- - -## Use Cases - -- **Corporate Offices** - Multi-department support -- **Startups** - Flexible role-based assistance -- **Remote Teams** - Unified office assistant -- **Enterprise** - Department-specific knowledge management - ---- - -## Related Templates - -- [Contacts](./template-crm-contacts.md) - Contact management -- [Reminder](./template-reminder.md) - Task and reminder management -- [CRM](./template-crm.md) - Full CRM for sales roles -- [Analytics](./template-analytics.md) - Platform analytics for managers - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-reminder.md b/docs/src/chapter-02/template-reminder.md deleted file mode 100644 index 38e7abc0..00000000 --- a/docs/src/chapter-02/template-reminder.md +++ /dev/null @@ -1,417 +0,0 @@ -# Reminder Template (reminder.gbai) - -A General Bots template for managing personal and team reminders with multi-channel notifications. - ---- - -## Overview - -The Reminder template provides a complete reminder management system with natural language scheduling, multiple notification channels, and snooze capabilities. Users can create, view, manage, and receive reminders through conversational AI. - -## Features - -- **Natural Language Scheduling** - Create reminders using everyday language -- **Multi-Channel Notifications** - Email, SMS, or chat notifications -- **Reminder Management** - List, snooze, and delete reminders -- **Scheduled Execution** - Background job checks and sends due reminders -- **Smart Date Parsing** - Understands "tomorrow", "next week", "in 2 hours" -- **Persistent Storage** - Reminders saved to CSV for reliability - ---- - -## Package Structure - -``` -reminder.gbai/ -├── reminder.gbdata/ # Data storage -│ └── reminders.csv # Reminder records -├── reminder.gbdialog/ -│ ├── start.bas # Main entry and tool registration -│ ├── add-reminder.bas # Create new reminders -│ └── reminder.bas # Scheduled job to send reminders -└── reminder.gbot/ - └── config.csv # Bot configuration -``` - -## Scripts - -| File | Description | -|------|-------------| -| `start.bas` | Registers tools, sets up suggestions, configures context | -| `add-reminder.bas` | Creates new reminder records with notifications | -| `reminder.bas` | Scheduled job that checks and sends due reminders | - ---- - -## Available Tools - -| Tool | Description | -|------|-------------| -| `add-reminder` | Create a new reminder | -| `list-reminders` | View all pending reminders | -| `delete-reminder` | Remove a reminder | -| `snooze-reminder` | Postpone a reminder | - ---- - -## Data Schema - -### Reminders Table - -| Field | Type | Description | -|-------|------|-------------| -| `id` | String | Unique identifier (REM-YYYYMMDD-XXXX) | -| `remindAt` | DateTime | When to send the reminder | -| `message` | String | Reminder content/subject | -| `notifyBy` | String | Notification channel (email, sms, chat) | -| `email` | Email | User's email address | -| `phone` | Phone | User's phone number | -| `created` | DateTime | Creation timestamp | -| `status` | String | pending, sent, snoozed, deleted | - ---- - -## Sample Conversation - -### Creating Reminders - -``` -User: Remind me to call John tomorrow at 9am - -Bot: ✅ Reminder set: Call John - When: Tomorrow at 9:00 AM - Notification: chat - -User: Set a reminder for next Monday at 2pm to submit the report - -Bot: ✅ Reminder set: Submit the report - When: Monday, May 19 at 2:00 PM - Notification: chat - -User: In 30 minutes remind me to take a break - -Bot: ✅ Reminder set: Take a break - When: in 30 minutes (2:45 PM) - Notification: chat -``` - -### Viewing Reminders - -``` -User: Show my reminders - -Bot: 📋 Your Reminders: - - 1. Call John - 📅 Tomorrow at 9:00 AM - 🔔 chat - - 2. Submit the report - 📅 Monday, May 19 at 2:00 PM - 🔔 chat - - 3. Take a break - 📅 Today at 2:45 PM - 🔔 chat -``` - -### Managing Reminders - -``` -User: Snooze my call reminder for 1 hour - -Bot: ✅ Reminder snoozed. New time: Tomorrow at 10:00 AM - -User: Delete the report reminder - -Bot: ✅ Reminder deleted: Submit the report -``` - ---- - -## How It Works - -### Tool Registration - -```basic -ADD TOOL "add-reminder" -ADD TOOL "list-reminders" -ADD TOOL "delete-reminder" -ADD TOOL "snooze-reminder" - -USE KB "reminder.gbkb" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "add" AS "Add a reminder" -ADD SUGGESTION "list" AS "View my reminders" -ADD SUGGESTION "today" AS "Today's reminders" -ADD SUGGESTION "delete" AS "Delete a reminder" - -SET CONTEXT "reminders" AS "You are a reminder assistant helping users manage their tasks and reminders." - -BEGIN SYSTEM PROMPT -You are a reminder AI assistant. - -When creating reminders: -- Parse natural language dates (tomorrow, next week, in 2 hours) -- Confirm the reminder details before saving -- Suggest appropriate times if not specified - -When listing reminders: -- Show upcoming reminders first -- Highlight overdue items -- Group by date when appropriate - -Be concise and helpful. -END SYSTEM PROMPT -``` - -### Creating Reminders - -```basic -' add-reminder.bas -PARAM when AS STRING LIKE "tomorrow at 9am" DESCRIPTION "When to send the reminder" -PARAM subject AS STRING LIKE "Call John" DESCRIPTION "What to be reminded about" -PARAM notify AS STRING LIKE "email" DESCRIPTION "Notification method" OPTIONAL - -DESCRIPTION "Create a reminder for a specific date and time" - -IF NOT notify THEN - notify = "chat" -END IF - -reminderid = "REM-" + FORMAT(NOW(), "YYYYMMDD") + "-" + FORMAT(RANDOM(1000, 9999)) -useremail = GET "session.user_email" -userphone = GET "session.user_phone" - -WITH reminder - id = reminderid - remindAt = when - message = subject - notifyBy = notify - email = useremail - phone = userphone - created = NOW() - status = "pending" -END WITH - -SAVE "reminders.csv", reminder - -SET BOT MEMORY "last_reminder", reminderid - -TALK "Reminder set: " + subject -TALK "When: " + when -TALK "Notification: " + notify - -RETURN reminderid -``` - -### Scheduled Reminder Delivery - -```basic -' reminder.bas - runs on schedule -REM SET SCHEDULER "1 * * * * " - -data = FIND "reminder.csv", "when=" + hour - -IF data THEN - TALK TO admin, data.subject -END IF -``` - ---- - -## Notification Channels - -| Channel | Delivery Method | -|---------|-----------------| -| `chat` | Message in bot conversation | -| `email` | Email to user's address | -| `sms` | SMS to user's phone | - ---- - -## Configuration - -Configure in `reminder.gbot/config.csv`: - -| Parameter | Description | Example | -|-----------|-------------|---------| -| `Default Notification` | Default channel | `chat` | -| `Snooze Duration` | Default snooze time | `15` (minutes) | -| `Check Interval` | How often to check | `1` (minute) | -| `Timezone` | User timezone | `America/New_York` | -| `Max Reminders` | Limit per user | `100` | - ---- - -## Customization - -### Custom Notification Channels - -Add new notification types: - -```basic -' In add-reminder.bas -SWITCH notify - CASE "chat" - ' Default chat notification - CASE "email" - SEND EMAIL email, "Reminder: " + subject, message - CASE "sms" - SEND SMS phone, "Reminder: " + subject - CASE "slack" - POST "https://hooks.slack.com/...", {"text": "Reminder: " + subject} - CASE "teams" - POST "https://outlook.office.com/webhook/...", {"text": subject} -END SWITCH -``` - -### Recurring Reminders - -Add support for recurring reminders: - -```basic -' add-recurring-reminder.bas -PARAM subject AS STRING DESCRIPTION "What to remind about" -PARAM schedule AS STRING LIKE "daily" DESCRIPTION "Frequency: daily, weekly, monthly" -PARAM time AS STRING LIKE "9:00 AM" DESCRIPTION "Time of day" - -DESCRIPTION "Create a recurring reminder" - -SET SCHEDULE cron_expression, "send-recurring.bas" - -WITH reminder - id = "REC-" + FORMAT(GUID()) - message = subject - frequency = schedule - remindTime = time - status = "active" -END WITH - -SAVE "recurring_reminders.csv", reminder -``` - -### Priority Levels - -Add priority support: - -```basic -PARAM priority AS STRING LIKE "high" DESCRIPTION "Priority: low, medium, high" OPTIONAL - -IF priority = "high" THEN - ' Send via multiple channels - SEND EMAIL email, "🔴 URGENT: " + subject, message - SEND SMS phone, "URGENT: " + subject -END IF -``` - ---- - -## Integration Examples - -### With Calendar - -```basic -' Sync reminder to calendar -IF reminder.notifyBy = "calendar" THEN - CREATE CALENDAR EVENT reminder.message, reminder.remindAt, 15 -END IF -``` - -### With Tasks - -```basic -' Convert reminder to task when due -IF reminder.status = "sent" THEN - CREATE TASK reminder.message, "medium", user_email -END IF -``` - -### With CRM - -```basic -' Add follow-up reminder from CRM -PARAM contact_id AS STRING DESCRIPTION "Contact to follow up with" -PARAM days AS INTEGER LIKE 7 DESCRIPTION "Days until follow-up" - -contact = FIND "contacts.csv", "id = " + contact_id - -WITH reminder - id = FORMAT(GUID()) - message = "Follow up with " + contact.name - remindAt = DATEADD(NOW(), days, "day") - notifyBy = "chat" - relatedTo = contact_id -END WITH - -SAVE "reminders.csv", reminder -``` - ---- - -## Date Parsing Examples - -The LLM understands various date formats: - -| Input | Parsed As | -|-------|-----------| -| "tomorrow" | Next day, 9:00 AM | -| "tomorrow at 3pm" | Next day, 3:00 PM | -| "in 2 hours" | Current time + 2 hours | -| "next Monday" | Coming Monday, 9:00 AM | -| "end of day" | Today, 5:00 PM | -| "next week" | 7 days from now | -| "January 15" | Jan 15, current year | -| "1/15 at noon" | Jan 15, 12:00 PM | - ---- - -## Best Practices - -1. **Be specific** - Include enough detail in reminder messages -2. **Set appropriate times** - Don't set reminders for odd hours -3. **Use the right channel** - Critical reminders via multiple channels -4. **Clean up** - Delete completed reminders regularly -5. **Review regularly** - Check reminder list to stay organized -6. **Test notifications** - Verify each channel works before relying on it - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Reminder not sent | Scheduler not running | Verify cron job is active | -| Wrong time | Timezone mismatch | Configure correct timezone | -| No notification | Missing contact info | Ensure email/phone is set | -| Duplicate reminders | Created multiple times | Check for existing before adding | -| Past date accepted | No validation | Add date validation logic | - ---- - -## Use Cases - -- **Personal Productivity** - Don't forget important tasks -- **Team Coordination** - Remind team members of deadlines -- **Customer Follow-ups** - Schedule sales and support follow-ups -- **Meeting Prep** - Get reminded before meetings -- **Health & Wellness** - Regular break and wellness reminders - ---- - -## Related Templates - -- [Office](./template-office.md) - Office productivity with task management -- [CRM](./template-crm.md) - CRM with follow-up reminders -- [Contacts](./template-crm-contacts.md) - Contact management with activity tracking -- [Marketing](./template-marketing.md) - Marketing with scheduled broadcasts - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/template-samples.md b/docs/src/chapter-02/template-samples.md deleted file mode 100644 index d3ea10ef..00000000 --- a/docs/src/chapter-02/template-samples.md +++ /dev/null @@ -1,700 +0,0 @@ -# Template Samples & Conversations - -> **Ready-to-use bots for common business needs** -> -> *See real conversations and learn how each template works* - ---- - -## How to Use Templates - -1. Go to **Sources** app -2. Click **+ New Bot** -3. Select **From Template** -4. Choose the template you want -5. Click **Create** - -Your bot is ready to use immediately! - ---- - -## Customer Support (CRM Template) - -**Best for:** Handling customer inquiries, tracking issues, managing contacts - -### Sample Conversation - -``` -User: I need help with my order - -Bot: I'd be happy to help with your order! - What's your order number? - -User: ORD-12345 - -Bot: Found it! Order #ORD-12345 - - 📦 Status: Shipped - 📅 Shipped: May 14, 2025 - 🚚 Carrier: FedEx - 📍 Tracking: 7891234567890 - - Expected delivery: May 17, 2025 - - Is there something specific about this order? - -User: I want to return it - -Bot: I can help you start a return for Order #ORD-12345. - - 📋 Return Policy: - • Returns accepted within 30 days - • Item must be unused - • Original packaging required - - Would you like me to create a return request? - -User: Yes - -Bot: ✅ Return Request Created! - - Return #: RET-5678 - - Next steps: - 1. Print the return label (sent to your email) - 2. Pack the item securely - 3. Drop off at any FedEx location - - Refund will process within 5-7 business days - after we receive the item. - - Anything else I can help with? -``` - -### What It Can Do - -- Look up orders by number or customer email -- Check shipping status -- Create return requests -- Log customer interactions -- Track support tickets - ---- - -## FAQ Bot (AI Search Template) - -**Best for:** Answering common questions from your documents - -### Sample Conversation - -``` -User: What's your refund policy? - -Bot: Based on our policies: - - **Refund Policy** - - • Full refund within 30 days of purchase - • Items must be unused and in original packaging - • Refunds processed to original payment method - • Processing time: 5-7 business days - - For items over 30 days old, store credit is available. - - 📄 Source: Company Policies Handbook, Page 12 - -User: How do I contact support? - -Bot: You can reach our support team through: - - 📧 Email: support@company.com - 📞 Phone: 1-800-555-0123 (Mon-Fri, 9am-5pm) - 💬 Chat: You're using it right now! - - Average response time: - • Chat: Immediate - • Email: Within 24 hours - • Phone: Under 5 minutes wait - - 📄 Source: Contact Information Page - -User: Do you ship internationally? - -Bot: Yes! We ship to over 50 countries. - - **International Shipping:** - • Standard: 10-15 business days ($15) - • Express: 5-7 business days ($35) - - **Note:** Import duties and taxes may apply - depending on your country. - - Countries we ship to include: Canada, UK, - Australia, Germany, France, Japan, and more. - - 📄 Source: Shipping FAQ Document -``` - -### Setup Tips - -1. Upload your FAQ documents to the knowledge base -2. Include policy documents, product guides, help articles -3. The bot automatically learns from your files - ---- - -## Appointment Booking (Calendar Template) - -**Best for:** Scheduling meetings, consultations, appointments - -### Sample Conversation - -``` -User: I want to book an appointment - -Bot: I'll help you schedule an appointment! - - What type of appointment do you need? - - 1. 📋 Consultation (30 min) - 2. 🔧 Service Visit (1 hour) - 3. 📞 Phone Call (15 min) - -User: Consultation - -Bot: Great! A 30-minute consultation. - - Here are available times this week: - - 📅 Tuesday, May 20 - • 10:00 AM - • 2:00 PM - • 4:00 PM - - 📅 Wednesday, May 21 - • 9:00 AM - • 11:00 AM - • 3:00 PM - - Which works best for you? - -User: Tuesday at 2pm - -Bot: Perfect! Let me confirm your details. - - What's your name? - -User: John Smith - -Bot: And your email address? - -User: john@email.com - -Bot: ✅ Appointment Confirmed! - - 📋 Consultation - 👤 John Smith - 📅 Tuesday, May 20, 2025 - 🕐 2:00 PM (30 minutes) - - A confirmation email has been sent to - john@email.com with calendar invite. - - Need to reschedule? Just ask! -``` - -### What It Can Do - -- Show available time slots -- Book appointments -- Send confirmation emails -- Send reminders before appointments -- Allow rescheduling and cancellation - ---- - -## HR Assistant (Employee Template) - -**Best for:** Employee self-service, HR questions, leave requests - -### Sample Conversation - -``` -User: How many vacation days do I have? - -Bot: Let me check your balance, John. - - 📊 Your Time Off Balance: - - Vacation Days - ├── Available: 12 days - ├── Used: 3 days - └── Pending: 0 days - - Sick Days - ├── Available: 8 days - └── Used: 2 days - - Your vacation resets on January 1, 2026. - - Would you like to request time off? - -User: Yes, I need next Friday off - -Bot: I'll create a time off request for you. - - 📅 Requesting: Friday, May 23, 2025 - 📋 Type: Vacation (1 day) - - Reason for time off? (optional) - -User: Personal appointment - -Bot: ✅ Time Off Request Submitted! - - 📋 Request #PTO-2025-0142 - 📅 Date: May 23, 2025 (1 day) - 📝 Reason: Personal appointment - 👤 Approver: Sarah Johnson (your manager) - - You'll receive an email when it's approved. - - Current status: ⏳ Pending Approval - -User: What holidays do we have this year? - -Bot: 📅 Company Holidays 2025: - - ✓ New Year's Day - Jan 1 (past) - ✓ Memorial Day - May 26 - ✓ Independence Day - July 4 - ✓ Labor Day - Sep 1 - ✓ Thanksgiving - Nov 27-28 - ✓ Christmas - Dec 25-26 - - Total: 8 paid holidays - - Note: If a holiday falls on a weekend, - it's observed on the nearest weekday. -``` - -### What It Can Do - -- Check PTO balances -- Submit time off requests -- Look up company holidays -- Answer HR policy questions -- Find employee directory info - ---- - -## Sales Lead Capture - -**Best for:** Qualifying leads, collecting contact info, scheduling demos - -### Sample Conversation - -``` -User: I'm interested in your product - -Bot: Great! I'd love to learn more about what you're - looking for. - - What's your name? - -User: Maria Garcia - -Bot: Nice to meet you, Maria! - - What company are you with? - -User: Acme Corp - -Bot: Acme Corp - got it! - - What's your role there? - -User: Marketing Director - -Bot: Perfect! And what's the best email to reach you? - -User: maria@acmecorp.com - -Bot: Thanks Maria! One last question: - - What's your biggest challenge right now? - - 1. 📈 Growing leads - 2. ⏱️ Saving time on manual tasks - 3. 📊 Better reporting - 4. 🔗 Integrating tools - 5. Other - -User: Saving time - -Bot: That's exactly what we help with! - - ✅ I've saved your information: - - 👤 Maria Garcia - 🏢 Acme Corp (Marketing Director) - 📧 maria@acmecorp.com - 🎯 Interest: Time savings - - Would you like to: - - 1. 📅 Schedule a demo (15 min) - 2. 📄 Get a product overview PDF - 3. 💬 Ask questions now - -User: Schedule a demo - -Bot: I can schedule you with our team! - - Available demo times: - - 📅 Tomorrow (May 16) - • 10:00 AM - • 3:00 PM - - 📅 Monday (May 19) - • 11:00 AM - • 2:00 PM - - Which works for you? - -User: Tomorrow at 3pm - -Bot: ✅ Demo Scheduled! - - 📅 Friday, May 16 at 3:00 PM - 👤 With: Alex from our Sales team - 📧 Calendar invite sent to maria@acmecorp.com - - Alex will show you how companies like Acme - save 10+ hours per week with our platform. - - See you tomorrow, Maria! -``` - -### What It Can Do - -- Qualify leads with questions -- Capture contact information -- Score leads automatically -- Schedule demo calls -- Send follow-up emails - ---- - -## IT Helpdesk - -**Best for:** IT support tickets, troubleshooting, password resets - -### Sample Conversation - -``` -User: I can't access my email - -Bot: I'll help you troubleshoot your email access. - - What error are you seeing? - - 1. 🔐 Password incorrect - 2. 📧 Can't connect to server - 3. 🔄 Email not syncing - 4. ❓ Something else - -User: Password incorrect - -Bot: Let's fix your password issue. - - Have you tried resetting your password in the - last 24 hours? - -User: No - -Bot: I can send a password reset link to your - backup email address. - - For security, please confirm your employee ID: - -User: EMP-4521 - -Bot: ✅ Verified! - - I've sent a password reset link to your backup - email (j***@gmail.com). - - 📧 Check your email and click the reset link - ⏱️ Link expires in 15 minutes - - After resetting: - 1. Use the new password for email - 2. Update password on your phone too - 3. It may take 5 minutes to sync - - Still having issues after resetting? - -User: It worked, thanks! - -Bot: Glad it's working! 🎉 - - Quick security tips: - • Use a strong, unique password - • Enable two-factor authentication - • Never share your password - - Anything else I can help with? - -User: No that's all - -Bot: ✅ Ticket #IT-2025-0891 closed as resolved. - - Have a great day! Remember, I'm here 24/7 - if you need IT help. -``` - -### What It Can Do - -- Create support tickets -- Reset passwords -- Troubleshoot common issues -- Check system status -- Escalate to human agents - ---- - -## Compliance & Privacy (LGPD/GDPR) - -**Best for:** Handling data privacy requests - -### Sample Conversation - -``` -User: I want to see what data you have about me - -Bot: I can help you with a Data Access Request. - - Under privacy regulations (LGPD, GDPR, CCPA), - you have the right to receive a copy of your - personal data. - - To process your request, I need to verify your - identity. What's your email address? - -User: john.doe@email.com - -Bot: I've sent a verification code to john.doe@email.com - - Please enter the 6-digit code: - -User: 847291 - -Bot: ✅ Identity verified! - - What would you like to do? - - 1. 📥 Get a copy of my data - 2. ✏️ Correct my information - 3. 🗑️ Delete my data - 4. ❓ Ask about data usage - -User: Get a copy of my data - -Bot: ✅ Data Access Request Submitted - - 📋 Request #DSR-2025-0142 - 📧 john.doe@email.com - 📅 Submitted: May 15, 2025 - ⏱️ Due: May 30, 2025 (15 days) - - We will compile all your personal data and - send it to your email in a secure format. - - You'll receive: - • Profile information - • Communication history - • Preferences and settings - • Activity logs - - Is there anything specific you're looking for? - -User: No, that's all - -Bot: Your request is being processed. - - You'll receive an email within 15 days with - a secure link to download your data. - - Questions? Reply to the confirmation email - or come back here anytime. -``` - ---- - -## Broadcast & Announcements - -**Best for:** Sending company-wide messages, news updates - -### Sample Conversation (Admin) - -``` -Admin: Send an announcement - -Bot: I'll help you create an announcement. - - What's the title? - -Admin: Office Closure Tomorrow - -Bot: Got it! Now the message content: - -Admin: Due to the holiday, our office will be closed - tomorrow May 16. We'll reopen Monday at 9am. - -Bot: Who should receive this? - - 1. 👥 All employees - 2. 🏢 Specific department - 3. 📍 Specific location - 4. 📋 Custom list - -Admin: All employees - -Bot: How should I send it? - - ☑️ Email - ☑️ Chat notification - ☐ SMS - - (Select all that apply) - -Admin: Email and chat - -Bot: 📢 Announcement Preview: - - ━━━━━━━━━━━━━━━━━━━━━━━━━━━ - OFFICE CLOSURE TOMORROW - ━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - Due to the holiday, our office will be - closed tomorrow May 16. We'll reopen - Monday at 9am. - - ━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - Recipients: 247 employees - Channels: Email, Chat - - Send now or schedule? - -Admin: Send now - -Bot: ✅ Announcement Sent! - - 📧 247 emails delivered - 💬 247 chat notifications sent - - Delivery report saved. View in Analytics. -``` - ---- - -## Talk to Data (Analytics) - -**Best for:** Asking questions about your business data in plain English - -### Sample Conversation - -``` -User: How many sales did we make last month? - -Bot: 📊 Sales Summary - April 2025 - - Total Sales: 1,247 - Revenue: $156,340 - Average Order: $125.35 - - Compared to March: - • Sales: ▲ 12% (+134) - • Revenue: ▲ 8% (+$11,520) - -User: Which product sold the most? - -Bot: 🏆 Top 5 Products - April 2025 - - 1. Widget Pro - 342 units ($42,750) - 2. Basic Package - 289 units ($28,900) - 3. Premium Bundle - 201 units ($40,200) - 4. Starter Kit - 187 units ($18,700) - 5. Add-on Pack - 156 units ($15,600) - - Widget Pro has been #1 for 3 months in a row! - -User: Show me sales by region - -Bot: 🗺️ Sales by Region - April 2025 - - North America ████████████░░ $68,500 (44%) - Europe ███████░░░░░░░ $42,300 (27%) - Asia Pacific █████░░░░░░░░░ $31,200 (20%) - Latin America ██░░░░░░░░░░░░ $14,340 (9%) - - Fastest growing: Asia Pacific (▲ 23%) - -User: Who are our top customers? - -Bot: 👥 Top 5 Customers - April 2025 - - 1. Acme Corp $12,450 (8 orders) - 2. TechStart Inc $9,800 (12 orders) - 3. Global Services $8,200 (5 orders) - 4. Smith & Co $7,650 (6 orders) - 5. DataFlow Ltd $6,900 (4 orders) - - Want me to show purchase history for any of these? -``` - -### What It Can Do - -- Answer business questions in plain English -- Show sales, revenue, customer data -- Compare time periods -- Create simple reports -- Export data to spreadsheets - ---- - -## Quick Template Selection Guide - -| I need to... | Use this template | -|--------------|-------------------| -| Answer customer questions | AI Search (FAQ) | -| Handle support tickets | CRM / IT Helpdesk | -| Book appointments | Calendar | -| Capture sales leads | CRM (Sales) | -| Help employees with HR | HR Assistant | -| Send announcements | Broadcast | -| Query business data | Talk to Data | -| Handle privacy requests | Compliance | - ---- - -## Need Something Custom? - -If these templates don't fit your needs: - -1. **Start with the closest template** - Modify it -2. **Use the Default template** - Build from scratch -3. **Combine templates** - Use features from multiple templates -4. **Ask for help** - Our community can guide you - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [How To: Create Your First Bot](../chapter-04-gbui/how-to/create-first-bot.md) -- [Sources App](../chapter-04-gbui/apps/sources.md) - Managing templates -- [Write Your First Dialog](../chapter-04-gbui/how-to/write-first-dialog.md) \ No newline at end of file diff --git a/docs/src/chapter-02/template-template.md b/docs/src/chapter-02/template-template.md deleted file mode 100644 index 01ede8a8..00000000 --- a/docs/src/chapter-02/template-template.md +++ /dev/null @@ -1,352 +0,0 @@ -# Template for Creating Templates (template.gbai) - -A General Bots meta-template that serves as a starting point for creating new bot templates. - ---- - -## Overview - -The Template template (yes, it's a template for templates!) provides the essential structure and best practices for creating new General Bots templates. Use this as your foundation when building custom templates for specific use cases. - -## Features - -- **Standard Structure** - Pre-configured folder hierarchy -- **Best Practices** - Follows General Bots conventions -- **Documentation Ready** - Includes README template -- **Quick Start** - Minimal setup required - ---- - -## Package Structure - -``` -template.gbai/ -├── README.md # Template documentation -├── template.gbdialog/ # Dialog scripts -│ └── send.bas # Example script (placeholder) -├── template.gbdrive/ # File storage -│ └── (your files here) -├── template.gbkb/ # Knowledge base (optional) -│ └── docs/ -└── template.gbot/ # Bot configuration - └── config.csv -``` - ---- - -## Creating a New Template - -### Step 1: Copy the Template - -```bash -cp -r templates/template.gbai templates/your-template.gbai -``` - -### Step 2: Rename Internal Folders - -Rename all internal folders to match your template name: - -```bash -cd templates/your-template.gbai -mv template.gbdialog your-template.gbdialog -mv template.gbdrive your-template.gbdrive -mv template.gbot your-template.gbot -``` - -### Step 3: Configure Your Bot - -Edit `your-template.gbot/config.csv`: - -```csv -name,value -Bot Name,Your Bot Name -Theme Color,blue -Answer Mode,default -LLM Provider,openai -``` - -### Step 4: Create Dialog Scripts - -Add your BASIC scripts to `your-template.gbdialog/`: - -```basic -' start.bas - Main entry point -ADD TOOL "your-tool" - -USE KB "your-template.gbkb" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "option1" AS "First Option" -ADD SUGGESTION "option2" AS "Second Option" -ADD SUGGESTION "help" AS "Get Help" - -BEGIN TALK -**Your Bot Name** - -Welcome! I can help you with: -• Feature 1 -• Feature 2 -• Feature 3 - -What would you like to do? -END TALK - -BEGIN SYSTEM PROMPT -You are a helpful assistant for [your use case]. - -Guidelines: -- Be helpful and concise -- Use the available tools when appropriate -- Ask clarifying questions when needed -END SYSTEM PROMPT -``` - -### Step 5: Add Tools - -Create tool scripts with proper parameters: - -```basic -' your-tool.bas -PARAM input AS STRING LIKE "example" DESCRIPTION "Description of this parameter" -PARAM optional_param AS STRING DESCRIPTION "Optional parameter" OPTIONAL - -DESCRIPTION "What this tool does - this helps the LLM decide when to use it" - -' Your implementation here -result = DO_SOMETHING(input) - -IF result THEN - RETURN result -ELSE - RETURN {"error": "Something went wrong"} -END IF -``` - -### Step 6: Add Knowledge Base (Optional) - -If your template needs reference documentation: - -``` -your-template.gbkb/ -└── docs/ - ├── feature1.md - ├── feature2.md - └── faq.md -``` - -### Step 7: Update README - -Replace the README with documentation for your template following the standard format. - ---- - -## Template Checklist - -Before publishing your template, ensure: - -- [ ] All folders renamed to match template name -- [ ] `config.csv` configured with appropriate defaults -- [ ] `start.bas` provides clear entry point -- [ ] All tools have `PARAM` and `DESCRIPTION` -- [ ] System prompt guides LLM behavior -- [ ] README documents all features -- [ ] No hardcoded credentials or secrets -- [ ] Error handling implemented -- [ ] Example conversations documented - ---- - -## Naming Conventions - -| Item | Convention | Example | -|------|------------|---------| -| Template folder | `kebab-case.gbai` | `my-crm.gbai` | -| Dialog scripts | `kebab-case.bas` | `add-contact.bas` | -| Tools | `kebab-case` | `search-products` | -| Config keys | `Title Case` | `Theme Color` | -| Table names | `PascalCase` | `CustomerOrders` | - ---- - -## File Templates - -### config.csv Template - -```csv -name,value -Bot Name,Your Bot Name -Theme Color,blue -Answer Mode,default -LLM Provider,openai -Admin Email,admin@company.com -``` - -### start.bas Template - -```basic -' Register tools -ADD TOOL "tool-name" - -' Load knowledge base -USE KB "your-template.gbkb" - -' Configure suggestions -CLEAR SUGGESTIONS -ADD SUGGESTION "action" AS "Do Something" - -' Welcome message -BEGIN TALK -**Bot Name** - -Welcome message here. -END TALK - -' System prompt -BEGIN SYSTEM PROMPT -You are a helpful assistant. -Define behavior and guidelines here. -END SYSTEM PROMPT -``` - -### Tool Template - -```basic -PARAM required_param AS STRING LIKE "example" DESCRIPTION "What this is" -PARAM optional_param AS STRING DESCRIPTION "Optional input" OPTIONAL - -DESCRIPTION "What this tool does" - -' Implementation -result = YOUR_LOGIC_HERE - -IF result THEN - RETURN result -ELSE - RETURN {"error": "Error message"} -END IF -``` - ---- - -## Best Practices - -### Dialog Scripts - -1. **Clear entry point** - `start.bas` should be the main entry -2. **Register tools** - Use `ADD TOOL` for LLM-callable functions -3. **Set context** - Use `SET CONTEXT` and `BEGIN SYSTEM PROMPT` -4. **Add suggestions** - Guide users with quick actions -5. **Welcome message** - Use `BEGIN TALK` for introduction - -### Tools - -1. **Descriptive names** - Tool names should indicate function -2. **Parameter examples** - Use `LIKE` to show expected format -3. **Clear descriptions** - Help LLM understand when to use -4. **Return values** - Always return meaningful results -5. **Error handling** - Handle edge cases gracefully - -### Configuration - -1. **Sensible defaults** - Work out of the box -2. **Document options** - Explain each setting -3. **No secrets** - Use environment variables for credentials -4. **Flexible** - Allow customization without code changes - -### Documentation - -1. **Clear overview** - Explain what the template does -2. **Feature list** - Highlight capabilities -3. **Usage examples** - Show common scenarios -4. **Configuration guide** - Document all settings -5. **Troubleshooting** - Address common issues - ---- - -## Publishing Your Template - -1. **Test thoroughly** - Verify all features work -2. **Document completely** - Users should be self-sufficient -3. **Follow conventions** - Consistent with other templates -4. **Update main README** - Add to templates list -5. **Submit PR** - Include template and documentation - ---- - -## Sample Conversation - -``` -User: How do I create a new template? - -Bot: To create a new template: - - 1. Copy the template.gbai folder - 2. Rename it to your-template.gbai - 3. Rename internal folders to match - 4. Edit config.csv with your settings - 5. Create your dialog scripts in .gbdialog - 6. Add tools as separate .bas files - 7. Update the README - - Would you like help with any specific step? - -User: How do I add a tool? - -Bot: To add a tool, create a .bas file in your .gbdialog folder: - - ' my-tool.bas - PARAM input AS STRING LIKE "example" DESCRIPTION "Input parameter" - - DESCRIPTION "What this tool does" - - ' Your logic here - result = PROCESS(input) - RETURN result - - Then register it in start.bas: - - ADD TOOL "my-tool" - - The LLM will automatically call your tool when appropriate - based on the DESCRIPTION you provided. -``` - ---- - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| Tool not found | Not registered | Add `ADD TOOL "name"` in start.bas | -| Tool not called | Poor description | Improve DESCRIPTION text | -| Wrong folder structure | Names don't match | Ensure all folders use same prefix | -| Config not loading | Wrong format | Check CSV syntax | -| KB not found | Wrong path | Verify USE KB path matches folder | - ---- - -## Related Resources - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide -- [Bot Configuration](../chapter-08-config/README.md) - Configuration options - ---- - -## Use Cases for Custom Templates - -- **Industry-Specific** - Healthcare, legal, finance bots -- **Department-Specific** - HR, IT, sales assistants -- **Process Automation** - Workflow-specific bots -- **Integration Templates** - Connect to specific APIs/systems -- **Vertical Solutions** - Complete solutions for business needs - ---- - -## See Also - -- [Templates Reference](./templates.md) - Full template list -- [Template Samples](./template-samples.md) - Example conversations -- [gbdialog Reference](../chapter-06-gbdialog/README.md) - BASIC scripting guide \ No newline at end of file diff --git a/docs/src/chapter-02/templates.md b/docs/src/chapter-02/templates.md deleted file mode 100644 index cc45ab6d..00000000 --- a/docs/src/chapter-02/templates.md +++ /dev/null @@ -1,326 +0,0 @@ -# Bot Templates - -BotServer includes pre-built bot templates for various use cases. Each template is a complete `.gbai` package ready to deploy. - ---- - -## Complete Template List (Flat Reference) - -| # | Template | Category | Folder | Key Features | -|---|----------|----------|--------|--------------| -| 1 | Default | Core | `default.gbai` | Minimal starter bot | -| 2 | Template | Core | `template.gbai` | Reference implementation | -| 3 | Announcements | Communications | `announcements.gbai` | Company news, multiple KB | -| 4 | AI Search | Search | `ai-search.gbai` | QR codes, document search | -| 5 | API Client | Integration | `api-client.gbai` | REST API patterns | -| 6 | Backup | Administration | `backup.gbai` | Server backup scripts | -| 7 | BI | Analytics | `bi.gbai` | Dashboards, role separation | -| 8 | Broadcast | Communications | `broadcast.gbai` | Mass messaging | -| 9 | Crawler | Search | `crawler.gbai` | Web indexing | -| 10 | CRM | Sales | `crm.gbai` | Customer management | -| 11 | Education | Education | `edu.gbai` | Course management | -| 12 | ERP | Operations | `erp.gbai` | Process automation | -| 13 | Law | Legal | `law.gbai` | Document templates | -| 14 | LLM Server | AI | `llm-server.gbai` | Model hosting | -| 15 | LLM Tools | AI | `llm-tools.gbai` | Prompt engineering | -| 16 | Marketing | Marketing | `marketing.gbai` | Campaign tools | -| 17 | Public APIs | Integration | `public-apis.gbai` | Weather, news APIs | -| 18 | Reminder | Productivity | `reminder.gbai` | Task reminders | -| 19 | Store | E-commerce | `store.gbai` | Product catalog | -| 20 | Talk to Data | Analytics | `talk-to-data.gbai` | Natural language SQL | -| 21 | WhatsApp | Messaging | `whatsapp.gbai` | WhatsApp Business | -| 22 | Office | Productivity | `office.gbai` | Document processing | -| 23 | Employee Management | HR | `hr/employees.gbai` | Employee CRUD | -| 24 | IT Helpdesk | IT | `it/helpdesk.gbai` | Ticket management | -| 25 | Sales Pipeline | CRM | `crm/sales-pipeline.gbai` | Deal tracking | -| 26 | Contact Directory | CRM | `crm/contacts.gbai` | Contact management | - ---- - -## Templates by Category - -### Core Templates - -| Template | Folder | Purpose | -|----------|--------|---------| -| Default | `default.gbai` | Minimal starter bot for learning | -| Template | `template.gbai` | Complete example structure | - -### HR & People - -| Template | Folder | Key Files | -|----------|--------|-----------| -| Employee Management | `hr/employees.gbai` | `start.bas`, `add-employee.bas`, `search-employee.bas` | -| Leave Management | `hr/leave.gbai` | `start.bas`, `request-leave.bas`, `approve-leave.bas` | -| Recruitment | `hr/recruitment.gbai` | `start.bas`, `post-job.bas`, `add-applicant.bas` | - -### IT & Support - -| Template | Folder | Key Files | -|----------|--------|-----------| -| IT Helpdesk | `it/helpdesk.gbai` | `start.bas`, `create-ticket.bas`, `update-ticket.bas` | -| Asset Tracking | `it/assets.gbai` | `start.bas`, `add-asset.bas`, `checkout-asset.bas` | - -### CRM & Sales - -| Template | Folder | Key Files | -|----------|--------|-----------| -| CRM | `crm.gbai` | `lead-management.bas`, `opportunity-management.bas` | -| Sales Pipeline | `crm/sales-pipeline.gbai` | `start.bas`, `create-deal.bas`, `update-stage.bas` | -| Contact Directory | `crm/contacts.gbai` | `start.bas`, `add-contact.bas`, `search-contact.bas` | - -### Finance & Accounting - -| Template | Folder | Key Files | -|----------|--------|-----------| -| Invoicing | `finance/invoicing.gbai` | `start.bas`, `create-invoice.bas`, `send-reminder.bas` | -| Expense Tracker | `finance/expenses.gbai` | `start.bas`, `submit-expense.bas`, `approve-expense.bas` | - -### Operations - -| Template | Folder | Key Files | -|----------|--------|-----------| -| ERP | `erp.gbai` | Process automation, integrations | -| Warehouse | `operations/warehouse.gbai` | `start.bas`, `receive-stock.bas`, `ship-order.bas` | - ---- - -## Template Structure - -All templates follow this standard directory layout: - -``` -template-name.gbai/ - template-name.gbdialog/ # BASIC dialog scripts - start.bas # Entry point (required) - *.bas # Tool scripts (auto-discovered) - *-jobs.bas # Scheduled jobs - template-name.gbkb/ # Knowledge base collections - collection1/ # Documents for USE KB "collection1" - template-name.gbdrive/ # File storage (not KB) - uploads/ # User uploaded files - exports/ # Generated files - template-name.gbot/ # Configuration - config.csv # Bot parameters - template-name.gbtheme/ # UI theme (optional) - default.css # Theme CSS -``` - ---- - -## Quick Start Guide - -### 1. Choose a Template - -Select based on your needs: -- **Simple chat**: Use `default.gbai` -- **Business app**: Choose `crm.gbai`, `bi.gbai`, or `erp.gbai` -- **AI features**: Pick `ai-search.gbai` or `llm-tools.gbai` -- **Communication**: Select `broadcast.gbai` or `whatsapp.gbai` - -### 2. Deploy the Template - -```bash -# Templates are auto-deployed during bootstrap -# Access at: http://localhost:8080/template-name -``` - -### 3. Customize Configuration - -Edit `template-name.gbot/config.csv`: - -```csv -name,value -bot-name,My Custom Bot -welcome-message,Hello! How can I help? -llm-model,gpt-4 -temperature,0.7 -``` - -### 4. Add Knowledge Base - -Place documents in `.gbkb` folders: -- Each folder becomes a collection -- Use `USE KB "folder-name"` in scripts -- Documents are automatically indexed - -### 5. Create Tools - -Add `.bas` files to `.gbdialog`: -- Each file becomes a tool -- Auto-discovered by the system -- Called automatically by LLM when needed - ---- - -## Required Files for Each Template - -### start.bas (Required) - -```basic -' Template Name - Start Script - -' Setup Tools -ADD TOOL "tool-name-1" -ADD TOOL "tool-name-2" - -' Setup Knowledge Base -USE KB "template-name.gbkb" - -' Set Context -SET CONTEXT "context name" AS "You are a [role]. You help with [tasks]." - -' Setup Suggestions -CLEAR SUGGESTIONS -ADD SUGGESTION "action1" AS "Display text 1" -ADD SUGGESTION "action2" AS "Display text 2" - -' Welcome Message -BEGIN TALK - **Template Title** - - Welcome message here. - - **What I can help with:** - • Feature 1 - • Feature 2 -END TALK - -BEGIN SYSTEM PROMPT - Detailed instructions for the AI... -END SYSTEM PROMPT -``` - -### Tool File Template - -```basic -PARAM paramname AS STRING LIKE "example" DESCRIPTION "What this parameter is" -PARAM optionalparam AS STRING LIKE "default" DESCRIPTION "Optional parameter" - -DESCRIPTION "What this tool does. Called when user wants to [action]." - -' Business logic -let result = "processed" - -' Save data (field names = variable names) -SAVE "table.csv", paramname, optionalparam, result - -' Store in memory -SET BOT MEMORY "last_item", result - -' Response -TALK "✅ Action completed successfully!" -``` - -### config.csv Template - -```csv -name,value -episodic-memory-history,2 -episodic-memory-threshold,4 -theme-color1,#1565C0 -theme-color2,#E3F2FD -theme-logo,https://pragmatismo.com.br/icons/general-bots.svg -theme-title,Template Name - General Bots -``` - ---- - -## Syntax Rules for Templates - -### DO ✅ - -```basic -' Variable names (no underscores in names) -let ticketnumber = "TKT001" -let useremail = "user@example.com" - -' SAVE with field names = variable names -SAVE "table.csv", ticketnumber, useremail, status - -' Keywords with spaces -SET BOT MEMORY "last_ticket", ticketnumber -SET CONTEXT "name" AS "description" -ADD SUGGESTION "key" AS "Display text" -CLEAR SUGGESTIONS -USE KB "myknowledge" -USE TOOL "mytool" - -' GET BOT MEMORY as function -let lastticket = GET BOT MEMORY("last_ticket") -``` - -### DON'T ❌ - -```basic -' NO: Complex object operations -SET object.field = value ' WRONG -SAVE "table", object.id, object ' WRONG -``` - ---- - -## Creating Custom Templates - -To create your own template: - -1. **Copy `template.gbai`** as starting point -2. **Define clear purpose** - one template, one job -3. **Structure folders** properly: - - `.gbdialog` for scripts - - `.gbkb` for knowledge collections - - `.gbdrive` for general files - - `.gbot` for configuration -4. **Include examples** - sample data and dialogs -5. **Test thoroughly** - verify all features - ---- - -## Best Practices - -### Template Selection - -1. **Start small**: Begin with `default.gbai` -2. **Match use case**: Choose aligned templates -3. **Combine features**: Mix templates as needed -4. **Keep originals**: Copy before modifying - -### Customization Strategy - -#### Minimal BASIC Approach -Instead of complex dialog flows, use simple LLM calls: - -```basic -' Let system AI handle conversations naturally -TALK "How can I assist you?" -' System AI understands and responds appropriately -``` - -#### Tool Creation -Only create `.bas` files for specific actions: -- API calls -- Database operations -- File processing -- Calculations - -#### Knowledge Base Organization -- One folder per topic/collection -- Name folders clearly -- Keep documents updated -- Index automatically - -### Performance Tips - -- Remove unused template files -- Index only necessary documents -- Configure appropriate cache settings -- Monitor resource usage - ---- - -## Support Resources - -- README files in each template folder -- Example configurations included -- Sample knowledge bases provided -- Community forums for discussions \ No newline at end of file diff --git a/docs/src/chapter-03/README.md b/docs/src/chapter-03/README.md deleted file mode 100644 index ac2220a9..00000000 --- a/docs/src/chapter-03/README.md +++ /dev/null @@ -1,80 +0,0 @@ -# Chapter 03: Knowledge Base System - -Vector search and semantic retrieval for intelligent document querying. - -## Overview - -The Knowledge Base (gbkb) transforms documents into searchable semantic representations, enabling natural language queries against your organization's content. - -## Architecture - -KB Architecture Pipeline - -The pipeline processes documents through extraction, chunking, embedding, and storage to enable semantic search. - -## Supported Formats - -| Format | Features | -|--------|----------| -| PDF | Text, OCR, tables | -| DOCX | Formatted text, styles | -| HTML | DOM parsing | -| Markdown | GFM, tables, code | -| CSV/JSON | Structured data | -| TXT | Plain text | - -## Quick Start - -```basic -' Activate knowledge base -USE KB "company-docs" - -' Bot now answers from your documents -TALK "How can I help you?" -``` - -## Key Concepts - -### Document Processing -1. **Extract** - Pull text from files -2. **Chunk** - Split into ~500 token segments -3. **Embed** - Generate vectors (BGE model) -4. **Store** - Save to Qdrant - -### Semantic Search -- Query converted to vector embedding -- Cosine similarity finds relevant chunks -- Top results injected into LLM context -- No explicit search code needed - -### Storage Requirements - -Vector databases need ~3.5x original document size: -- Embeddings: ~2x -- Indexes: ~1x -- Metadata: ~0.5x - -## Configuration - -```csv -name,value -embedding-url,http://localhost:8082 -embedding-model,bge-small-en-v1.5 -rag-hybrid-enabled,true -rag-top-k,10 -``` - -## Chapter Contents - -- [KB and Tools System](./kb-and-tools.md) - Integration patterns -- [Vector Collections](./vector-collections.md) - Collection management -- [Document Indexing](./indexing.md) - Processing pipeline -- [Semantic Search](./semantic-search.md) - Search mechanics -- [Context Compaction](./context-compaction.md) - Token management -- [Semantic Caching](./caching.md) - Performance optimization - -## See Also - -- [.gbkb Package](../chapter-02/gbkb.md) - Folder structure -- [USE KB Keyword](../chapter-06-gbdialog/keyword-use-kb.md) - Keyword reference -- [Hybrid Search](../chapter-11-features/hybrid-search.md) - RAG 2.0 \ No newline at end of file diff --git a/docs/src/chapter-03/assets/caching-architecture.svg.backup b/docs/src/chapter-03/assets/caching-architecture.svg.backup deleted file mode 100644 index af19ae91..00000000 --- a/docs/src/chapter-03/assets/caching-architecture.svg.backup +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Semantic Caching Architecture - - - - - User Query - "What's the policy?" - - - - - - - Generate Key - Hash + Embed - - - - - - - Check Valkey - Memory Store - - - - - - - - Hit? - - - - - - - - Embedding Hash - 384D Vector - - - - - - - Semantic Search - Similarity > 0.95 - - - - - ✓ Cache Hit - - - - Miss - - - - Generate New - LLM Response - - - - - - - Store in Valkey - TTL: 3600s - - - - - Performance Metrics - - Hit Rate: ~85% - Latency: <50ms - Cost Reduction: 95% - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/assets/context-window.svg.backup b/docs/src/chapter-03/assets/context-window.svg.backup deleted file mode 100644 index cdea24e1..00000000 --- a/docs/src/chapter-03/assets/context-window.svg.backup +++ /dev/null @@ -1,204 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Vector Database Storage Requirements: The Real Mathematics - - - - - - Original Documents - - - 1 TB Total - - - - - - PDF: 400 GB - - - - - DOCX: 250 GB - - - - - XLSX: 150 GB - - - - - TXT: 100 GB - - - - - HTML: 50 GB - - - - - Other: 50 GB - - - - - - Processing - - - - - - Vector DB Storage - - - ~3.5 TB Required - - - - - - Raw Text Extracted - - - ~800 GB (cleaned) - - - Deduplication reduces 20% - - - - - Vector Embeddings - - - ~1.2 TB (384-dim floats) - - - 4 bytes × 384 × ~800M chunks - - - = 1,228 GB - - - - - HNSW Index - - - ~600 GB - - - Graph structure + links - - - - - Metadata + Positions - - - ~400 GB - - - Doc refs, chunks, offsets - - - - - Cache + Auxiliary - - - ~500 GB - - - Query cache, temp indices - - - - - - Storage Multiplication Factor - - - - Original Documents: 1.0 TB - - - Vector DB Total: 3.5 TB - - - Multiplication Factor: 3.5× - - - - With redundancy/backup: - - - Production Total: 7.0 TB (2× replica) - - - - Reality: You need 3.5-7× your document storage - - - - - - Input - - - - - Storage - - - - - Factor - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/assets/kb-architecture-pipeline.svg.backup b/docs/src/chapter-03/assets/kb-architecture-pipeline.svg.backup deleted file mode 100644 index eaac4a18..00000000 --- a/docs/src/chapter-03/assets/kb-architecture-pipeline.svg.backup +++ /dev/null @@ -1,137 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Knowledge Base Architecture Pipeline - - - - - - Document Ingestion Layer - - - PDF • Word • Excel • Text • HTML • Markdown - - - - - - - - - Preprocessing Pipeline - - - Extraction • Cleaning • Normalization • Validation - - - - - - - - - Intelligent Chunking Engine - - - Semantic Segmentation • Overlap Management • Metadata Preservation - - - - - - - - - Embedding Generation - - - BGE Models • Transformer Architecture • Dimensionality: 384/768 - - - - - - - - - Vector Index Layer - - - HNSW Algorithm • Quantization • Distributed Sharding - - - - - - - - - Semantic Retrieval Engine - - - Cosine Similarity • Hybrid Search • Re-ranking • Context Injection - - - - - - Data Flow Direction - - - - - Raw Docs - Clean Text - Chunks - Vectors - Index - Results - - - - - Pipeline processes ~1000 documents/minute • Query latency <50ms (p99) • 95% semantic accuracy - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/assets/search-pipeline.svg.backup b/docs/src/chapter-03/assets/search-pipeline.svg.backup deleted file mode 100644 index 29440df1..00000000 --- a/docs/src/chapter-03/assets/search-pipeline.svg.backup +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Semantic Search Pipeline - - - - - - - - - User Query - "What's the return - policy?" - - - - - - - - - Embedding - Transform to - 384D vector - - - - - - - - - Vector Search - Cosine similarity - in vector space - - - - - - - - - Re-ranking - Score & sort - by relevance - - - - - - Active Collections - policies • procedures • faq - - - - - - - - - Retrieved Context - 1. "Refund policy: 30 days..." (0.92) - 2. "Return procedures..." (0.87) - 3. "Warranty information..." (0.81) - - - - - - - - - Context Injection to LLM - Retrieved chunks provided as context for response generation - - - - - - - - - - Automatic - Process - - - - - - Search latency: ~20ms • Embedding: BGE-small (384D) • Similarity threshold: 0.7 • Top-K: 5 chunks - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/assets/storage-breakdown.svg.backup b/docs/src/chapter-03/assets/storage-breakdown.svg.backup deleted file mode 100644 index ad86654f..00000000 --- a/docs/src/chapter-03/assets/storage-breakdown.svg.backup +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LLM Context Compression Strategies - - - - - - - - Original Context: 10,000 tokens - - - - - - - - - - - - - - - - - - Compression Level 4 - - - - - - - Compressed Context: 4,096 tokens (fits LLM window) - - - - - - - - - - - - - - - - Compression Techniques (Level 4) - - - - - - - Semantic Deduplication - - - • Remove redundant info - - - • Merge similar chunks - - - • Keep unique facts - - - - Reduction: 30-40% - - - - - - - - - - - - - - - Relevance Scoring - - - • Score by query match - - - • Keep top-k relevant - - - • Drop low scores - - - - Reduction: 40-50% - - - - - - - - - - - - - Hierarchical Summary - - - • Extract key points - - - • Create abstracts - - - • Preserve details - - - - Reduction: 50-60% - - - - - - - - - - - - - - - - - - - Token Optimization - - - • Remove stopwords - - - • Compress phrases - - - • Use abbreviations - - - - Reduction: 20-30% - - - - - ABCDEF → ABC - - - GHIJKL → GHI - - - - - - - - Compression Level 4 achieves 60-75% reduction while maintaining 95%+ information retention - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/assets/storage-multiplication.svg.backup b/docs/src/chapter-03/assets/storage-multiplication.svg.backup deleted file mode 100644 index 05d664c4..00000000 --- a/docs/src/chapter-03/assets/storage-multiplication.svg.backup +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Storage Components per 1TB of Documents - - - - - - - - - - - - - - - - 0 GB - 250 GB - 500 GB - 750 GB - 1000 GB - - - - Storage Size (GB) - - - - - - 1000 - Original - 1000 GB - - - - 800 - Extracted - 800 GB - - - - 1200 - Embeddings - 1200 GB - - - - 600 - Index - 600 GB - - - - 400 - Metadata - 400 GB - - - - 500 - Cache - 500 GB - - - - - 3.5 TB Total - - - - Components contribute to 3.5× storage multiplication factor - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/assets/technical-specs.svg.backup b/docs/src/chapter-03/assets/technical-specs.svg.backup deleted file mode 100644 index 37fc09a3..00000000 --- a/docs/src/chapter-03/assets/technical-specs.svg.backup +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - System Technical Specifications - - - - - - - - - - Embedding Configuration - - - - Model: bge-small-en-v1.5-f32.gguf - - - • Dimensions: 384 - - - • Format: GGUF (quantized) - - - • Server: localhost:8082 - - - • Memory: ~200MB loaded - - - - - - - - LLM Configuration - - - - Model: DeepSeek-R1-Distill-Qwen-1.5B - - - • Context Size: 4096 tokens - - - • Max Predict: 1024 tokens - - - • Parallel Requests: 6 - - - • Quantization: Q3_K_M - - - - - - - - Performance Characteristics - - - - - - Vector Index: HNSW Algorithm - - - • M=16, ef_construction=200 - - - • Distance: Cosine Similarity - - - • Build: ~1000 docs/minute - - - - - - - Chunking Strategy - - - • Chunk Size: 512 tokens - - - • Overlap: 50 tokens - - - • Prompt Compact: Level 4 - - - - - - - Runtime Metrics - - - • Query Latency: <50ms p99 - - - • Memory: ~1GB/million chunks - - - • Cache TTL: 3600 seconds - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-03/caching.md b/docs/src/chapter-03/caching.md deleted file mode 100644 index 617be589..00000000 --- a/docs/src/chapter-03/caching.md +++ /dev/null @@ -1,146 +0,0 @@ -# Caching - -BotServer includes automatic caching to improve response times and reduce redundant processing, including semantic caching for LLM responses using an in-memory cache component. - -Caching Architecture - -## Features - -The caching system provides exact match caching for identical prompts and semantic similarity matching to find and reuse responses for semantically similar prompts. Configurable TTL settings control how long cached responses remain valid. Caching can be enabled or disabled on a per-bot basis through configuration. Embedding-based similarity uses local embedding models for semantic matching, and comprehensive statistics and monitoring track cache hits, misses, and performance metrics. - -## How Caching Works - -Caching in BotServer is controlled by configuration parameters in `config.csv`. The system automatically caches LLM responses and manages conversation history. - -When enabled, the semantic cache operates through a straightforward process. When a user asks a question, the system checks if a semantically similar question was asked before. If the similarity exceeds the threshold (typically 0.95), it returns the cached response. Otherwise, it generates a new response and caches it for future queries. - -## Configuration - -### Basic Cache Settings - -From `default.gbai/default.gbot/config.csv`: - -```csv -llm-cache,false # Enable/disable LLM response caching -llm-cache-ttl,3600 # Cache time-to-live in seconds -llm-cache-semantic,true # Use semantic similarity for cache matching -llm-cache-threshold,0.95 # Similarity threshold for cache hits -``` - -### Configuration Parameters - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `llm-cache` | boolean | false | Enable/disable LLM response caching | -| `llm-cache-ttl` | integer | 3600 | Time-to-live for cached entries (in seconds) | -| `llm-cache-semantic` | boolean | true | Enable semantic similarity matching | -| `llm-cache-threshold` | float | 0.95 | Similarity threshold for semantic matches (0.0-1.0) | - -### Embedding Service Configuration - -For semantic similarity matching, ensure your embedding service is configured: - -```csv -embedding-url,http://localhost:8082 -embedding-model,../../../../data/llm/bge-small-en-v1.5-f32.gguf -``` - -## Conversation History Management - -The system manages conversation context through these parameters: - -```csv -episodic-memory-history,2 # Number of previous messages to include in context -episodic-memory-threshold,4 # Compact conversation after N exchanges -``` - -The `episodic-memory-history` setting keeps the last 2 exchanges in the conversation context, providing continuity without excessive token usage. The `episodic-memory-threshold` setting triggers summarization or removal of older messages after 4 exchanges to save tokens while preserving essential context. - -## Cache Storage - -### Architecture - -The caching system uses a multi-level approach for optimal performance, combining fast in-memory access with configurable persistence options. - -### Cache Key Structure - -The cache uses a multi-level key structure where exact matches use a hash of the exact prompt while semantic matches store embedding vectors with a semantic index for similarity comparison. - -### Cache Component Features - -The cache component provides fast in-memory storage with sub-millisecond response times. Automatic expiration handles TTL-based cache invalidation without manual intervention. Distributed caching enables sharing the cache across multiple bot instances for consistent performance. Persistence options offer optional disk persistence for cache durability across restarts. - -## Example Usage - -### Basic Caching - -```basic -' Caching happens automatically when enabled -USE KB "policies" - -' First user asks: "What's the vacation policy?" -' System generates response and caches it - -' Second user asks: "Tell me about vacation rules" -' System finds semantic match (>0.95 similarity) and returns cached response -``` - -### Tool Response Caching - -```basic -' Tool responses can also be cached -USE TOOL "weather-api" - -' First request: "What's the weather in NYC?" -' Makes API call, caches response for 1 hour - -' Second request within TTL: "NYC weather?" -' Returns cached response without API call -``` - -## Cache Management - -The cache operates automatically based on your configuration settings. Cache entries are managed through TTL expiration and memory policies without requiring manual intervention. - -## Best Practices - -### When to Enable Caching - -Enable caching for FAQ bots with repetitive questions, knowledge base queries where the same information is requested frequently, API-heavy integrations where external calls are expensive, and high-traffic bots where response latency impacts user experience. - -Disable caching for real-time data queries where freshness is critical, personalized responses that should vary per user, time-sensitive information that changes frequently, and development or testing environments where you need to see actual responses. - -### Tuning Cache Parameters - -TTL settings should match your data freshness requirements. Use short TTL values around 300 seconds for news, weather, and stock prices. Medium TTL values around 3600 seconds work well for general knowledge and FAQs. Long TTL values around 86400 seconds suit static documentation and policies. - -Similarity threshold affects matching precision. High thresholds of 0.95 or above provide strict matching with fewer false positives. Medium thresholds between 0.85 and 0.95 balance coverage and accuracy. Low thresholds below 0.85 enable broad matching but risk returning incorrect responses. - -### Memory Management - -The cache component automatically manages memory through LRU (Least Recently Used) eviction policies that remove the oldest accessed entries first. Configurable memory limits prevent unbounded growth. Automatic key expiration cleans up entries that have exceeded their TTL. - -## Performance Impact - -Typical performance improvements with caching enabled: - -| Metric | Without Cache | With Cache | Improvement | -|--------|--------------|------------|-------------| -| Response Time | 2-5s | 50-200ms | 10-100x faster | -| API Calls | Every request | First request only | 90%+ reduction | -| Token Usage | Full context | Cached response | 95%+ reduction | -| Cost | $0.02/request | $0.001/request | 95% cost saving | - -## Troubleshooting - -### Cache Not Working - -If caching isn't working as expected, verify that the cache service is running and accessible. Confirm caching is enabled in your config with `llm-cache,true`. Check that the TTL hasn't expired for entries you expect to be cached. Review the similarity threshold to ensure it isn't set too high for your use case. - -### Clear Cache - -Cache is managed automatically through TTL expiration and eviction policies. To clear the cache manually, restart the cache component or use the admin API endpoint `/api/admin/cache/clear`. - -## Summary - -The semantic caching system in BotServer provides intelligent response caching that reduces response latency by 10-100x and cuts API costs by 90% or more. Response quality is maintained through semantic matching that understands query intent rather than requiring exact matches. The system scales automatically with the cache component to handle increasing load. Configure caching based on your bot's needs, monitor performance metrics, and tune parameters for optimal results. \ No newline at end of file diff --git a/docs/src/chapter-03/episodic-memory.md b/docs/src/chapter-03/episodic-memory.md deleted file mode 100644 index 54a3abd8..00000000 --- a/docs/src/chapter-03/episodic-memory.md +++ /dev/null @@ -1,160 +0,0 @@ -# Episodic Memory - -Episodic memory automatically manages conversation history to stay within token limits while preserving important information through intelligent summarization. - -## How It Works - -Episodic memory is controlled by two parameters in `config.csv`: - -```csv -episodic-memory-history,2 # Keep last 2 message exchanges -episodic-memory-threshold,4 # Compact after 4 total exchanges -``` - -## Configuration Parameters - -### episodic-memory-history -Determines how many previous exchanges to include in the LLM context: -- Default: `2` (keeps last 2 user messages and 2 bot responses) -- Range: 1-10 depending on your token budget -- Higher values = more context but more tokens used - -### episodic-memory-threshold -Triggers compaction after N exchanges: -- Default: `4` (compacts conversation after 4 back-and-forth exchanges) -- When reached, older messages are summarized or removed -- Helps manage long conversations efficiently - -## Automatic Behavior - -The system automatically: -1. Tracks conversation length -2. When exchanges exceed `episodic-memory-threshold` value -3. Summarizes older messages using LLM -4. Keeps only the last `episodic-memory-history` exchanges in full -5. Stores summary as an "episodic memory" for context - -## Example Flow - -With default settings (`episodic-memory-history=2`, `episodic-memory-threshold=4`): - -``` -Exchange 1: User asks, bot responds -Exchange 2: User asks, bot responds -Exchange 3: User asks, bot responds -Exchange 4: User asks, bot responds -Exchange 5: Episodic memory created - exchanges 1-2 summarized, 3-4 kept in full -Exchange 6: Context = [episodic summary] + exchanges 4-5 -``` - -### Visual Flow Diagram - - - - Episodic Memory Flow - - - - Conversation History - - - - - - - Check Exchange Count - - - - - - - Exceeds - episodic-memory-threshold? - - - - No - - - - Keep All Messages - - - - Yes - - - - Summarize Old + Keep Last - episodic-memory-history - - - - - - - - - Continue Conversation - - - - - - - - - -## Benefits - -- **Automatic management** - No manual intervention needed -- **Token efficiency** - Stay within model limits -- **Context preservation** - Important info kept via summaries -- **Relevant context** - Keeps recent exchanges in full -- **Cost savings** - Fewer tokens = lower API costs - -## Adjusting Settings - -### For longer context: -```csv -episodic-memory-history,5 # Keep more history in full -episodic-memory-threshold,10 # Summarize less frequently -``` - -### For minimal context: -```csv -episodic-memory-history,1 # Only last exchange in full -episodic-memory-threshold,2 # Summarize aggressively -``` - -## Use Cases - -### Customer Support -- Lower values work well (customers ask independent questions) -- `episodic-memory-history,1` and `episodic-memory-threshold,2` - -### Complex Discussions -- Higher values needed (maintain conversation flow) -- `episodic-memory-history,4` and `episodic-memory-threshold,8` - -### FAQ Bots -- Minimal context needed (each question is standalone) -- `episodic-memory-history,1` and `episodic-memory-threshold,2` - -## Important Notes - -- Episodic memory is automatic based on config.csv -- Summaries are created using the configured LLM -- Settings apply to all conversations -- Changes require bot restart -- Summaries are stored with role "episodic" in message history - -## Best Practices - -1. **Start with defaults** - Work well for most use cases -2. **Monitor token usage** - Adjust if hitting limits -3. **Consider conversation type** - Support vs discussion -4. **Test different values** - Find optimal balance - -The system handles all compaction automatically - just configure the values that work for your use case! \ No newline at end of file diff --git a/docs/src/chapter-03/indexing.md b/docs/src/chapter-03/indexing.md deleted file mode 100644 index fed94149..00000000 --- a/docs/src/chapter-03/indexing.md +++ /dev/null @@ -1,84 +0,0 @@ -# Document Indexing - -Documents in `.gbkb` folders are indexed automatically. No manual configuration required. - -## Automatic Triggers - -Indexing occurs when: -- Files added to `.gbkb` folders -- Files modified or updated -- `USE KB` called for a collection -- `USE WEBSITE` registers URLs for crawling - -## Processing Pipeline - -``` -Document → Extract Text → Chunk → Embed → Store in Qdrant -``` - -| Stage | Description | -|-------|-------------| -| **Extract** | Pull text from PDF, DOCX, HTML, MD, TXT, CSV | -| **Chunk** | Split into ~500 token segments with 50 token overlap | -| **Embed** | Generate vectors using BGE model | -| **Store** | Save to Qdrant with metadata | - -## Supported File Types - -| Format | Notes | -|--------|-------| -| PDF | Full text extraction, OCR for scanned docs | -| DOCX | Microsoft Word documents | -| TXT/MD | Plain text and Markdown | -| HTML | Web pages (text only) | -| CSV/JSON | Structured data | - -## Website Indexing - -Schedule regular crawls for web content: - -```basic -SET SCHEDULE "0 2 * * *" ' Daily at 2 AM -USE WEBSITE "https://docs.example.com" -``` - -### Schedule Examples - -| Pattern | Frequency | -|---------|-----------| -| `"0 * * * *"` | Hourly | -| `"*/30 * * * *"` | Every 30 minutes | -| `"0 0 * * 0"` | Weekly (Sunday) | -| `"0 0 1 * *"` | Monthly (1st) | - -## Configuration - -In `config.csv`: - -```csv -name,value -embedding-url,http://localhost:8082 -embedding-model,../../../../data/llm/bge-small-en-v1.5-f32.gguf -``` - -## Using Indexed Content - -```basic -USE KB "documentation" -' All documents now searchable -' LLM uses this knowledge automatically -``` - -## Troubleshooting - -| Issue | Solution | -|-------|----------| -| Documents not found | Check file is in `.gbkb` folder, verify `USE KB` called | -| Slow indexing | Large PDFs take time; consider splitting documents | -| Outdated content | Set up scheduled crawls for web content | - -## See Also - -- [Knowledge Base System](./README.md) - Architecture overview -- [Semantic Search](./semantic-search.md) - How search works -- [Vector Collections](./vector-collections.md) - Collection management \ No newline at end of file diff --git a/docs/src/chapter-03/kb-and-tools.md b/docs/src/chapter-03/kb-and-tools.md deleted file mode 100644 index 4360ac0e..00000000 --- a/docs/src/chapter-03/kb-and-tools.md +++ /dev/null @@ -1,290 +0,0 @@ -# KB and TOOL System Documentation - -## Overview - -The General Bots system provides four essential keywords for managing Knowledge Bases and Tools dynamically during conversation sessions. The USE KB keyword loads and embeds files from `.gbkb` folders into the vector database. The CLEAR KB keyword removes a knowledge base from the current session. The USE TOOL keyword makes a tool available for the LLM to call. The CLEAR TOOLS keyword removes all tools from the current session. Together, these keywords give you complete control over what information and capabilities your bot has access to at any moment. - - -## Knowledge Base System - -### What is a KB? - -A Knowledge Base is a folder containing documents (using the `.gbkb` folder structure) that are vectorized, embedded, and stored in a vector database. When users ask questions, the vector database retrieves relevant chunks and excerpts to inject into prompts, giving the LLM context-aware responses based on your specific documentation and data. - -### Folder Structure - -Knowledge bases are organized within your bot's work directory. The structure places all knowledge base folders inside a `.gbkb` container that shares your bot's name. Within this container, you create separate folders for different topics or document collections. Each folder can contain PDF files, markdown documents, plain text files, Word documents, CSV files, and other supported formats. - -``` -work/ - {bot_name}/ - {bot_name}.gbkb/ - circular/ - document1.pdf - document2.md - document3.txt - comunicado/ - info.docx - data.csv - docs/ - README.md - guide.pdf -``` - -### KB Loading Process - -When you load a knowledge base, the system goes through several stages to make your documents searchable. First, the system scans the specified `.gbkb` folder to identify all documents. Then it processes each file by extracting text from PDFs, Word documents, text files, markdown, CSV files, and other supported formats. The extracted text is split into chunks of approximately 1000 characters with overlap between chunks to preserve context at boundaries. Each chunk is then converted into a vector representation using an embedding model. These vectors are stored in the vector database with metadata about their source, enabling fast similarity search. Once this process completes, the knowledge base is ready to answer semantic queries. - -### Supported File Types - -The system supports a variety of document formats. PDF files receive full text extraction using the pdf-extract library. Microsoft Word documents in both DOCX and DOC formats are supported. Plain text files and markdown documents are processed directly. CSV files treat each row as a separate searchable entry. HTML files have their text content extracted while ignoring markup. JSON files are parsed and their structured data becomes searchable. - -### USE KB Keyword - -The USE KB keyword loads a knowledge base folder into your current session. You can load multiple knowledge bases, and all of them become active simultaneously. This allows you to combine different document collections for comprehensive responses. - -```basic -USE KB "circular" -' The circular KB folder is now loaded and searchable -' All documents in that folder are available for semantic queries - -USE KB "comunicado" -' Now both circular and comunicado are active -' The LLM can draw from both collections when responding -``` - -### CLEAR KB Keyword - -The CLEAR KB keyword removes all loaded knowledge bases from the current session. This frees up memory and context space, which is particularly useful when switching between different topics or when you need to ensure the LLM only uses specific information. - -```basic -CLEAR KB -' All loaded knowledge bases are removed -' Memory is freed and context space is reclaimed -``` - - -## Tool System - -### What are Tools? - -Tools are callable functions that the LLM can invoke to perform specific actions beyond its training data. Tools enable your bot to query databases, call external APIs, process data, execute workflows, and integrate with external systems. When the LLM determines that a tool would help answer a user's question, it generates a tool call with the appropriate parameters. - -### Tool Definition - -Tools are defined in `.bas` files that automatically generate MCP and OpenAI-compatible tool definitions. When you create a BASIC file with PARAM declarations and a DESCRIPTION, the system compiles it into a tool specification that the LLM understands. - -```basic -' weather.bas - becomes a tool automatically -PARAM location AS string -PARAM units AS string DEFAULT "celsius" -DESCRIPTION "Get current weather for a location" - -' Tool implementation -weather_data = GET "https://api.weather.com/v1/current?location=" + location -SET CONTEXT "weather_data", weather_data -TALK "Here's the current weather for " + location -``` - -### Tool Registration - -Tools become available through two mechanisms. Auto-discovery scans all `.bas` files in your `.gbdialog` folder (except `start.bas`) and registers them as tools automatically. Dynamic loading uses the USE TOOL keyword to make external tools available during a session. - -### USE TOOL Keyword - -The USE TOOL keyword makes a specific tool available for the LLM to call. You can enable multiple tools, giving your bot access to various capabilities during a conversation. - -```basic -USE TOOL "weather" -' The weather tool is now available - -USE TOOL "database_query" -' Database querying capability is added - -USE TOOL "email_sender" -' The bot can now send emails when appropriate -``` - -### CLEAR TOOLS Keyword - -The CLEAR TOOLS keyword removes all tools from the current session. After clearing, the LLM can no longer call external functions and must rely solely on its training and any loaded knowledge bases. - -```basic -CLEAR TOOLS -' All tools are disabled -' LLM cannot call external functions -``` - - -## Session Management - -### Context Lifecycle - -Each conversation session follows a predictable lifecycle. When a session starts, the bot has a clean slate with no knowledge bases or tools loaded. During the conversation, you load resources as needed using USE KB and USE TOOL commands. The LLM actively uses these loaded resources to provide informed, capable responses. When the topic changes or resources are no longer needed, you clear them with CLEAR KB and CLEAR TOOLS. When the session ends, automatic cleanup releases all remaining resources. - -### Best Practices for KB Management - -Load only the knowledge bases relevant to the current conversation. Overloading context with unnecessary KBs reduces response quality and increases costs. Clear knowledge bases when switching topics to keep the context focused on what matters. Update your KB files regularly to keep the information current. Monitor token usage because vector search results add tokens to each query. - -### Best Practices for Tool Management - -Enable only the minimum set of tools needed for the current task. Having too many tools available can confuse the LLM about which one to use. Always validate tool responses and check for errors before presenting results to users. Log tool usage for audit purposes and debugging. Consider implementing rate limits to prevent abuse in production environments. - -### Performance Considerations - -Memory usage varies based on your configuration. Each loaded knowledge base typically uses 100-500MB of RAM depending on document count and size. Tools use minimal memory, usually less than 1MB each. Vector search operations add 10-50ms latency to responses. Clear unused resources promptly to free memory for other operations. - -Token optimization is important for controlling costs. KB chunks add 500-2000 tokens per query depending on the number of relevant chunks retrieved. Each tool description uses 50-200 tokens. Clearing resources when they are no longer needed reduces token usage. Using specific KB folders rather than loading entire databases improves both performance and relevance. - - -## Implementation Details - -### Vector Database - -The vector database configuration uses one collection per bot instance to maintain isolation. The embedding model is text-embedding-ada-002, which produces 1536-dimensional vectors. Distance calculations use cosine similarity for semantic matching. The index uses HNSW (Hierarchical Navigable Small World) with M=16 and ef=100 for fast approximate nearest neighbor search. - -### File Processing Pipeline - -When USE KB processes files, it follows a systematic pipeline. The system scans the specified directory to identify all files. Text is extracted based on each file's type using appropriate parsers. The extracted text is cleaned and normalized to remove artifacts. Content is split into chunks of approximately 1000 characters with 200 character overlap to preserve context across boundaries. Embeddings are generated via the OpenAI API for each chunk. The vectors are stored in the vector database along with metadata about their source. Finally, the session context is updated to reflect the newly available knowledge base. - -### Tool Execution Engine - -When USE TOOL prepares a tool for use, it parses the tool definition into a JSON schema that describes parameters and expected behavior. This schema is registered with the LLM context so the model knows the tool is available. The system listens for tool invocations in the LLM's responses. When a tool call is detected, parameters are validated against the schema. The tool executes its logic, which might involve HTTP requests or function calls. Results return to the LLM for incorporation into the response. All executions are logged for audit purposes. - - -## Error Handling - -### Common Issues - -Several error conditions can occur when working with knowledge bases and tools. The KB_NOT_FOUND error indicates that the specified KB folder does not exist, so you should verify the folder name and path. A VECTORDB_ERROR suggests a connection issue with the vector database service that needs investigation. EMBEDDING_FAILED errors typically indicate problems with the embedding API, often related to API keys or rate limits. TOOL_NOT_FOUND means the specified tool is not registered, so verify the tool name matches exactly. TOOL_EXECUTION_ERROR indicates the tool failed during execution, requiring investigation of the tool endpoint or logic. MEMORY_LIMIT errors occur when too many knowledge bases are loaded simultaneously, requiring you to clear unused KBs. - -### Debugging Approach - -Check logs for detailed information about issues. KB loading progress shows which documents are being processed. Embedding generation logs reveal any failures during vectorization. Vector search query logs help diagnose relevance problems. Tool invocation logs show parameter values and execution results. Error details provide stack traces and specific failure reasons. - - -## Examples - -### Customer Support Bot - -This example shows a customer support bot that loads product documentation and FAQs, enables ticket management tools, and provides informed assistance. - -```basic -' Load product documentation -USE KB "product_docs" -USE KB "faqs" - -' Enable support tools -USE TOOL "ticket_system" -USE TOOL "knowledge_search" - -' The bot now has access to documentation and can work with tickets -TALK "How can I help you with your support needs today?" - -' When the session ends, clean up -CLEAR KB -CLEAR TOOLS -``` - -### Research Assistant - -This example demonstrates a research assistant that can switch between different knowledge base collections depending on the research topic. - -```basic -' Load research papers for current topic -USE KB "papers_2024" -USE KB "citations" - -' Enable research tools -USE TOOL "arxiv_search" -USE TOOL "citation_formatter" - -TALK "What research topic would you like to explore?" - -' When switching to a different research area -CLEAR KB -USE KB "papers_biology" -``` - -### Enterprise Integration - -This example shows an enterprise bot with access to company policies and integration with internal systems like Active Directory, Jira, and Slack. - -```basic -' Load company policies -USE KB "hr_policies" -USE KB "it_procedures" - -' Enable enterprise integration tools -USE TOOL "active_directory" -USE TOOL "jira_integration" -USE TOOL "slack_notifier" - -' The bot can now query AD, work with Jira tickets, and send Slack notifications -' Handle employee requests throughout the conversation - -' Clean up at end of shift -CLEAR KB -CLEAR TOOLS -``` - - -## Security Considerations - -### KB Security - -Knowledge base security involves multiple layers of protection. Access control ensures that knowledge bases require proper authorization before loading. Files are encrypted at rest to protect sensitive information. All KB access is logged for audit purposes. Per-session KB separation ensures that one user's loaded knowledge bases cannot leak to another session. - -### Tool Security - -Tool security protects against misuse and unauthorized access. Authentication requirements ensure tools only execute within valid sessions. Rate limiting prevents tool abuse through excessive calls. Parameter validation sanitizes all inputs before execution. Execution sandboxing isolates tool operations from the core system. - -### Best Practices - -Follow the principle of least privilege by loading only the resources needed for the current task. Conduct regular audits to review KB and tool usage patterns. Ensure sensitive knowledge bases use encrypted storage. Rotate API keys used by tools on a regular schedule. Maintain session isolation by clearing resources between different users. - - -## Configuration - -Configuration options for knowledge bases and tools are set in your bot's config.csv file. The vector database connection settings specify where embeddings are stored. Chunk size and overlap parameters control how documents are split. Embedding model selection determines vector quality and dimension. Tool timeout settings prevent long-running operations from blocking conversations. - - -## Troubleshooting - -### KB Issues - -If a knowledge base is not loading, first verify that the folder exists at the expected path within `work/{bot_name}/{bot_name}.gbkb/`. Check file permissions to ensure the system can read the documents. Verify the vector database connection is healthy. Review logs for any embedding errors during processing. - -If search results are poor quality, consider adjusting the chunk overlap to provide more context at boundaries. Experiment with different chunk sizes for your content type. Ensure your embedding model is appropriate for the content language. Pre-process documents to remove noise and improve text quality before indexing. - -### Tool Issues - -If a tool is not executing, first verify that the tool registration completed successfully by checking logs. Confirm parameter validation rules match the values being passed. Test the tool endpoint directly outside of the bot to isolate the issue. Review execution logs for specific error messages. - -If tools are timing out, increase the timeout setting in configuration. Check network connectivity between the bot and tool endpoints. Optimize the tool endpoint to respond faster. Consider adding retry logic for transient failures. - - -## Migration Guide - -### From File-based to Vector Search - -If you are migrating from a file-based knowledge system to vector search, start by exporting your existing files into a clean directory structure. Organize the files into logical `.gbkb` folders based on topic or department. Run the embedding pipeline by loading each KB with USE KB. Test vector search queries to verify results match expectations. Update your bot logic to use the new KB keywords instead of file operations. - -### From Static to Dynamic Tools - -If you have static function calls that should become dynamic tools, convert each function into a tool definition with PARAM declarations. Create a `.bas` file with the DESCRIPTION and parameter specifications. Implement the endpoint or handler that the tool will call. Test the tool using USE TOOL and verify it executes correctly. Remove the static function registration from your startup logic. - - -## See Also - -### Documentation - -The Vector Collections page explains how vector search works under the hood. The Document Indexing page covers automatic document processing in detail. The Semantic Search page describes meaning-based retrieval algorithms. The Context Compaction page explains how conversation context is managed. The Caching page covers performance optimization through semantic caching. The Chapter 6 BASIC Reference provides complete dialog scripting documentation. The Chapter 9 API and Tools reference covers tool integration in depth. - -### Further Reading - -The Pragmatismo blog post on BASIC LLM Tools explains how to extend LLMs with custom tools. The MCP is the new API article covers modern tool integration patterns. The Beyond Chatbots post discusses using knowledge bases effectively for sophisticated applications. - -### Next Chapter - -Continue to Chapter 4 on User Interface to learn about creating bot interfaces that present your knowledge base and tool capabilities to users effectively. \ No newline at end of file diff --git a/docs/src/chapter-03/semantic-search.md b/docs/src/chapter-03/semantic-search.md deleted file mode 100644 index 5844ea1f..00000000 --- a/docs/src/chapter-03/semantic-search.md +++ /dev/null @@ -1,99 +0,0 @@ -# Semantic Search - -Semantic search finds relevant content by meaning, not just keywords. When a user asks "How many days off do I get?", the system matches documents about "vacation policy" or "PTO allowance" even though the words differ. - -Search Pipeline - -## How It Works - -1. **Query embedding** - Convert question to vector using same model as documents -2. **Similarity search** - Find document chunks with closest embeddings (cosine distance) -3. **Result selection** - Take top-k results above relevance threshold -4. **Context injection** - Add retrieved text to LLM prompt - -## Automatic Integration - -Semantic search requires no explicit coding. Just activate knowledge bases: - -```basic -USE KB "policies" -USE KB "products" - -' Now all user questions automatically search both collections -TALK "How can I help you?" -``` - -The system handles query embedding, vector search, ranking, and context assembly transparently. - -## Search Pipeline Details - -| Stage | Operation | Default | -|-------|-----------|---------| -| Embedding | Convert query to vector | BGE model | -| Search | Vector similarity lookup | Qdrant | -| Distance | Cosine similarity | 0.0-1.0 | -| Top-k | Results returned | 5 | -| Threshold | Minimum relevance | 0.7 | - -## Multiple Collections - -When multiple KBs are active, the system searches all and combines best results: - -```basic -USE KB "hr-docs" ' Active -USE KB "it-docs" ' Active -USE KB "finance" ' Active - -' Query searches all three, returns best matches regardless of source -``` - -Use `CLEAR KB` to deactivate collections when switching topics. - -## Performance - -- **Cold search**: 100-200ms (first query) -- **Warm search**: 20-50ms (cached embeddings) -- **Indexing**: One-time cost per document - -Optimizations: -- Embedding cache for repeated queries -- HNSW index for fast vector search -- Only active collections consume resources - -## Optimizing Quality - -**Document factors:** -- Clear, descriptive text produces better matches -- Use vocabulary similar to how users ask questions -- Avoid jargon-heavy content when possible - -**Collection factors:** -- Focused collections (one topic) beat catch-all collections -- Fewer active collections = less noise in results -- Split large document sets by domain area - -## Troubleshooting - -| Issue | Cause | Solution | -|-------|-------|----------| -| No results | Collection not active | Call `USE KB "name"` | -| Wrong results | Too many collections | Clear irrelevant KBs | -| Missing matches | Document not indexed | Check file is in `.gbkb` folder | -| Poor relevance | Content mismatch | Review document quality | - -## Configuration - -Semantic search uses sensible defaults. Two settings affect context: - -```csv -name,value -episodic-memory-history,2 # Previous exchanges to include -episodic-memory-threshold,4 # When to compress older context -``` - -## See Also - -- [Hybrid Search](../chapter-11-features/hybrid-search.md) - Combining semantic + keyword search -- [Document Indexing](./indexing.md) - How documents are processed -- [Vector Collections](./vector-collections.md) - Technical vector DB details -- [USE KB](../chapter-06-gbdialog/keyword-use-kb.md) - Keyword reference \ No newline at end of file diff --git a/docs/src/chapter-03/summary.md b/docs/src/chapter-03/summary.md deleted file mode 100644 index da4710d2..00000000 --- a/docs/src/chapter-03/summary.md +++ /dev/null @@ -1,23 +0,0 @@ -# Chapter 03 – Knowledge‑Base (VectorDB) Documentation Overview - -This chapter explains how GeneralBots manages knowledge‑base collections, indexing, caching, and semantic search. The implementation uses vector databases for semantic search and highlights the use of the **.gbdrive** package for storage when needed. - -| Document | File | Description | -|----------|------|-------------| -| **README** | [README.md](README.md) | High‑level reference for the `.gbkb` package and its core commands (`USE KB`, `CLEAR KB`, `USE WEBSITE`). | -| **Caching** | [caching.md](caching.md) | Optional in‑memory and persistent SQLite caching to speed up frequent `FIND` queries. | -| **Context Compaction** | [context-compaction.md](context-compaction.md) | Techniques to keep the LLM context window within limits (summarization, memory pruning, sliding window). | -| **Indexing** | [indexing.md](indexing.md) | Process of extracting, chunking, embedding, and storing document vectors in the VectorDB. | -| **Semantic Caching** | [caching.md](caching.md) | Intelligent caching for LLM responses, including semantic similarity matching. | -| **Semantic Search** | [semantic-search.md](semantic-search.md) | How the `FIND` keyword performs meaning‑based retrieval using the VectorDB. | -| **Vector Collections** | [vector-collections.md](vector-collections.md) | Definition and management of vector collections, including creation, document addition, and usage in dialogs. | - -## How to Use This Overview - -- **Navigate**: Click the file links to read the full documentation for each topic. -- **Reference**: Use this table as a quick lookup when developing or extending knowledge‑base functionality. -- **Update**: When the underlying storage or VectorDB implementation changes, edit the corresponding markdown files and keep this summary in sync. - ---- - -*This summary was added to provide a cohesive overview of Chapter 03, aligning terminology with the current architecture (VectorDB, .gbdrive, etc.).* diff --git a/docs/src/chapter-03/vector-collections.md b/docs/src/chapter-03/vector-collections.md deleted file mode 100644 index f243b36e..00000000 --- a/docs/src/chapter-03/vector-collections.md +++ /dev/null @@ -1,85 +0,0 @@ -# Vector Collections - -This chapter explains how BotServer organizes knowledge into vector collections, the searchable units that power semantic retrieval. Understanding how collections work helps you structure documents effectively and optimize the knowledge your bots can access. - -Storage Breakdown - -## From Folders to Collections - -Vector collections emerge automatically from the folder structure within your .gbkb directory. Each folder you create becomes a distinct collection, indexed separately and activated independently. This direct mapping between physical organization and logical collections makes knowledge management intuitive—organize files into folders by topic, and those folders become the collections you reference in your scripts. - -When BotServer encounters a .gbkb folder, it scans for documents in supported formats including PDF, DOCX, TXT, HTML, and Markdown. Each file's content is extracted, split into manageable chunks, converted to vector embeddings, and stored in the vector database. The folder name becomes the collection identifier you use with the USE KB keyword. - -This automatic process means no manual indexing configuration is required. Add files to a folder, and they become searchable. Remove files, and they disappear from search results. The system tracks file changes through hash comparisons, triggering reindexing only when content actually changes. - -## The Indexing Pipeline - -Understanding the indexing pipeline helps diagnose issues and optimize performance. When a folder is processed, the system first detects which files are new or modified since the last indexing run. This incremental approach avoids reprocessing unchanged content. - -For each file requiring processing, text extraction pulls readable content from the document regardless of its format. PDF extraction handles complex layouts, DOCX processing unwraps the underlying XML, and plain text formats are read directly. The extracted text preserves paragraph structure and meaningful breaks. - -The chunking phase splits long documents into smaller pieces suitable for embedding and retrieval. Each chunk contains approximately 500 tokens with overlap between adjacent chunks to preserve context across boundaries. This sizing balances granularity—enabling precise matches—against coherence—keeping related information together. - -Embedding generation converts each text chunk into a numerical vector representation. BotServer uses the BGE embedding model by default, producing 384-dimensional vectors that capture semantic meaning. These embeddings enable the similarity comparisons that power semantic search. - -Finally, the vectors and their associated metadata are stored in the vector database, organized by collection. Each entry includes the embedding vector, the original text chunk, the source file path, and position information enabling reconstruction of context. - -## Working with Collections - -Activating a collection for use in conversations requires only the USE KB statement with the collection name matching the folder. Once activated, the collection becomes part of the knowledge available when answering questions. - -Multiple collections can be active simultaneously, and the system searches across all of them when looking for relevant content. This capability allows bots to draw on diverse knowledge sources. A comprehensive assistant might activate employee policies, product documentation, and procedural guides, answering questions that span any combination of these areas. - -The CLEAR KB keyword deactivates collections, either removing all active collections at once or targeting specific ones by name. Clearing collections frees memory and focuses search results on remaining active knowledge. Scripts that handle diverse topics might activate and clear collections as the conversation shifts between subject areas. - -Collections operate at the session level, meaning activation persists until the session ends or the collection is explicitly cleared. Users can ask follow-up questions that build on retrieved knowledge without requiring reactivation between each query. - -## Website Indexing - -Beyond static documents, collections can include content crawled from websites. The USE WEBSITE keyword registers a URL for crawling, with the retrieved content becoming searchable alongside document-based collections. - -For content that changes over time, scheduled crawling keeps the collection current. A script with SET SCHEDULE can periodically re-crawl websites, ensuring that the bot's knowledge reflects recent updates. This approach works well for documentation sites, knowledge bases, or any web content relevant to your bot's domain. - -Website content goes through the same indexing pipeline as documents—text extraction, chunking, embedding, and storage. The resulting collection is indistinguishable in use from document-based collections. - -## How Search Utilizes Collections - -When a user asks a question and collections are active, the search process finds relevant content automatically. The system embeds the query using the same model that indexed the documents, ensuring that queries and content exist in the same semantic space. - -Vector similarity search identifies chunks whose embeddings are closest to the query embedding. The system retrieves the top matches from each active collection, then combines and ranks them by relevance. This process typically completes in milliseconds even for large collections. - -The most relevant chunks become part of the context provided to the language model when generating a response. The model sees both the user's question and the retrieved information, enabling it to produce answers grounded in your organization's actual documentation. - -This entire process happens transparently. Developers don't write search queries or handle result sets. Users don't know that retrieval is occurring. The system simply provides knowledgeable responses informed by the activated collections. - -## Embedding Configuration - -The embedding model determines how meaning is captured in vectors and significantly influences search quality. BotServer uses a locally-running BGE model by default, configured through the embedding URL and model path settings in config.csv. - -The default model provides good general-purpose performance for English content. Organizations with specialized vocabulary or multilingual requirements might benefit from alternative models. The embedding infrastructure supports any compatible model, allowing customization for specific domains. - -Changing embedding models requires reindexing existing collections since embeddings from different models aren't comparable. Plan model changes carefully, accounting for the reprocessing time required for large document collections. - -## Collection Management Practices - -Effective collection organization follows the principle of coherent groupings. Each folder should contain documents about a related topic area, enabling targeted activation. Overly broad collections that mix unrelated content produce noisier search results than focused collections containing cohesive material. - -Clear naming conventions help scripts remain readable and maintainable. Collection names should indicate their content clearly enough that someone reading a script understands what knowledge is being activated without examining the folder contents. - -Regular content maintenance keeps collections valuable. Remove outdated documents that might produce incorrect answers. Update files when information changes. Schedule website re-crawls frequently enough that cached content doesn't become stale. - -Monitoring collection usage helps identify optimization opportunities. If certain collections are rarely activated, consider whether they should exist separately or merge into related collections. If search results frequently miss relevant content, examine whether documents are organized in ways that match how users think about topics. - -## Performance Considerations - -Collection size affects both memory usage and search performance. Larger collections require more storage for their embeddings and take longer to search, though the impact is usually modest given vector database optimizations. Very large collections might benefit from subdivision into more focused subcollections. - -Active collection count influences context-building overhead. Each active collection contributes potential results that must be ranked and filtered. Activating only relevant collections for each conversation keeps search focused and efficient. - -Embedding generation represents the primary indexing cost. Initial indexing of large document sets takes time proportional to total content size. Incremental updates process only changed files, making ongoing maintenance much faster than initial setup. - -Caching at multiple levels improves performance for common patterns. Frequently accessed chunks remain in memory. Repeated queries benefit from result caching. The system automatically manages these caches without requiring configuration. - -## Summary - -Vector collections bridge the gap between static documents and dynamic conversation knowledge. The automatic indexing pipeline transforms folder contents into searchable collections without requiring manual configuration. Simple activation through USE KB makes knowledge available, while the underlying vector search finds relevant content based on meaning rather than keywords. Thoughtful organization of documents into focused collections maximizes the value of this powerful capability. \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/README.md b/docs/src/chapter-04-gbui/README.md deleted file mode 100644 index 59952eac..00000000 --- a/docs/src/chapter-04-gbui/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# Chapter 04: User Interface - -General Bots UI system built with HTMX and server-side rendering. - -## UI Modes - -| Mode | Description | Use Case | -|------|-------------|----------| -| **default.gbui** | Full desktop suite | Complete productivity | -| **single.gbui** | Simple chat widget | Embedded chat | -| **console** | Terminal interface | Development/testing | - -## Architecture - -- **HTMX** - Dynamic updates without JavaScript frameworks -- **Server-Side Rendering** - Fast, SEO-friendly pages -- **Minimal JS** - No build process required - -## Quick Access - -``` -http://localhost:8080 → Main interface -http://localhost:8080/chat → Chat app -http://localhost:8080/drive → File manager -http://localhost:8080/console → Terminal mode -``` - -## Suite Applications - -| App | Purpose | -|-----|---------| -| Chat | AI assistant conversations | -| Drive | File management | -| Tasks | To-do lists | -| Mail | Email client | -| Calendar | Scheduling | -| Meet | Video calls | -| Paper | AI writing | -| Research | AI search | - -## Chapter Contents - -- [Suite User Manual](./suite-manual.md) - End-user guide -- [UI Structure](./ui-structure.md) - Component layout -- [default.gbui](./default-gbui.md) - Full desktop mode -- [single.gbui](./single-gbui.md) - Chat widget mode -- [Console Mode](./console-mode.md) - Terminal interface -- [HTMX Architecture](./htmx-architecture.md) - Technical details -- [Suite Applications](./apps/README.md) - App documentation -- [How-To Tutorials](./how-to/README.md) - Step-by-step guides - -## See Also - -- [.gbtheme Package](../chapter-05-gbtheme/README.md) - Styling and themes -- [.gbui Structure](../chapter-02/gbui.md) - Package format \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/README.md b/docs/src/chapter-04-gbui/apps/README.md deleted file mode 100644 index 52a0d2c2..00000000 --- a/docs/src/chapter-04-gbui/apps/README.md +++ /dev/null @@ -1,167 +0,0 @@ -# Suite Applications - -> **Individual app documentation for General Bots Suite** - -Each application in the Suite has its own dedicated documentation with: -- Flow diagrams (SVG with light/dark theme support) -- Interface layouts -- HTMX integration patterns -- API endpoints -- CSS classes -- JavaScript handlers -- Keyboard shortcuts - ---- - -## Core Applications - -| App | Description | Documentation | -|-----|-------------|---------------| -| 🖥️ **Suite** | Full desktop interface | [suite.md](./suite.md) | -| 💬 **Chat** | AI-powered conversation assistant | [chat.md](./chat.md) | -| 📁 **Drive** | Cloud file storage and management | [drive.md](./drive.md) | -| ✓ **Tasks** | To-do lists with priorities | [tasks.md](./tasks.md) | -| ✉ **Mail** | Email client | [mail.md](./mail.md) | -| 📅 **Calendar** | Scheduling and events | [calendar.md](./calendar.md) | -| 🎥 **Meet** | Video conferencing | [meet.md](./meet.md) | -| 🎬 **Player** | Media viewer | [player.md](./player.md) | - -## Productivity Applications - -| App | Description | Documentation | -|-----|-------------|---------------| -| 📝 **Paper** | AI-assisted document writing | [paper.md](./paper.md) | -| 🔍 **Research** | AI-powered search and discovery | [research.md](./research.md) | -| 📊 **Analytics** | Reports and dashboards | [analytics.md](./analytics.md) | - -## Developer Tools - -| App | Description | Documentation | -|-----|-------------|---------------| -| 🎨 **Designer** | Visual dialog builder (VB6-style) | [designer.md](./designer.md) | -| 📚 **Sources** | Prompts, templates, and models | [sources.md](./sources.md) | -| 🛡️ **Compliance** | Security scanner | [compliance.md](./compliance.md) | - ---- - -## App Launcher - -The Suite features a Google-style app launcher accessible from the header: - -App Launcher - -### Accessing Apps - -1. **Click the grid icon** (⋮⋮⋮) in the top-right corner -2. **Select an app** from the dropdown menu -3. App loads in the main content area - -### Keyboard Shortcuts - -| Shortcut | App | -|----------|-----| -| `Alt+1` | Chat | -| `Alt+2` | Drive | -| `Alt+3` | Tasks | -| `Alt+4` | Mail | -| `Alt+5` | Calendar | -| `Alt+6` | Meet | - ---- - -## Architecture Overview - -All Suite apps follow the same patterns: - -### HTMX Loading - -Apps are loaded lazily when selected: - -```html - - Chat - -``` - -### Component Structure - -Each app is a self-contained HTML fragment: - -``` -app-name/ -├── app-name.html # Main component -├── app-name.css # Styles (optional) -└── app-name.js # JavaScript (optional) -``` - -### API Integration - -Apps communicate with the backend via REST APIs: - -```html -
- Loading... -
-``` - -### Real-Time Updates - -WebSocket support for live data: - -```html -
- -
-``` - ---- - -## Creating Custom Apps - -To add a new app to the Suite: - -1. **Create the component** in `ui/suite/your-app/` -2. **Add navigation entry** in `index.html` -3. **Define API endpoints** in your Rust backend -4. **Document the app** in this folder - -### Template - -```html - -
-
-

Your App

-
- -
-
Loading...
-
-
- - -``` - ---- - -## See Also - -- [Suite Manual](../suite-manual.md) - Complete user guide -- [HTMX Architecture](../htmx-architecture.md) - Technical details -- [UI Structure](../ui-structure.md) - File organization -- [Chapter 10: REST API](../../chapter-10-api/README.md) - API reference \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/analytics.md b/docs/src/chapter-04-gbui/apps/analytics.md deleted file mode 100644 index 504ea31c..00000000 --- a/docs/src/chapter-04-gbui/apps/analytics.md +++ /dev/null @@ -1,417 +0,0 @@ -# Analytics - Dashboards - -> **Your business intelligence center** - -Analytics Interface Screen - ---- - -## Overview - -Analytics is the data visualization and reporting app in General Bots Suite. Track key metrics, build custom dashboards, generate reports, and get AI-powered insights about your business. Analytics turns your data into actionable information. - ---- - -## Features - -### Dashboard Overview - -Dashboards are collections of widgets that display your data visually. - -**Default Dashboards:** - -| Dashboard | What It Shows | -|-----------|---------------| -| **Overview** | Key metrics across all areas | -| **Sales** | Revenue, deals, pipeline | -| **Marketing** | Campaigns, leads, conversion | -| **Support** | Tickets, response time, satisfaction | -| **HR** | Headcount, hiring, retention | - ---- - -### Creating a Dashboard - -**Step 1: Click "+ New" in the sidebar** - -Fill in the dashboard details: -- **Dashboard Name** - A descriptive title (e.g., "Q2 Performance") -- **Description** - Optional context for the dashboard -- **Template** - Start blank, use a template, or copy from existing - -**Step 2: Add Widgets** - -Click **+ Widget** and choose a visualization type. - ---- - -### Widget Types - -**Numbers:** -- **Number** - Single metric display -- **Comparison** - Metric with percentage change -- **Progress** - Goal tracking with progress bar - -**Charts:** -- **Line** - Trends over time -- **Bar** - Category comparisons -- **Area** - Volume visualization -- **Pie** - Proportional breakdown - -**Tables & Lists:** -- **Table** - Data grid with sorting -- **Leaderboard** - Ranked list -- **List** - Simple bullet items - -**Special:** -- **Geography** - Map visualization -- **Heatmap** - Intensity grid -- **AI Summary** - AI-generated insights - ---- - -### Configuring Widgets - -After selecting a widget type, configure the data source: - -| Setting | Description | -|---------|-------------| -| **Title** | Widget display name | -| **Source** | Database or data connection | -| **Table** | Specific table to query | -| **X-Axis** | Horizontal dimension | -| **Y-Axis** | Vertical measure | -| **Group By** | Time period or category | -| **Aggregate** | Sum, Count, Average, etc. | -| **Filters** | Conditions to apply | - ---- - -### Key Metric Cards - -Display important numbers with context: - -| Element | Purpose | -|---------|---------| -| **Value** | The main metric number | -| **Trend Arrow** | Up/down indicator | -| **Comparison** | vs last period | -| **Progress Bar** | Visual goal tracking | -| **Goal** | Target value | - -**Color Indicators:** - -| Color | Meaning | -|-------|---------| -| 🟢 Green (▲) | Positive trend / On target | -| 🔴 Red (▼) | Negative trend / Below target | -| 🟡 Yellow (─) | No change / Needs attention | -| ⚪ Gray | No comparison available | - ---- - -### AI Insights ✨ - -Let AI analyze your data and surface insights: - -**Insight Types:** - -| Category | What It Shows | -|----------|---------------| -| **📈 Trends** | Patterns and momentum in your data | -| **⚠️ Alerts** | Issues that need attention | -| **💡 Recommendations** | Suggested actions | -| **🎯 Predictions** | Forecasts based on current data | - -**Ask the AI:** - - - ---- - -### Reports - -Generate and schedule reports: - -**Creating a Report:** - -1. Click **+ New** under Reports -2. Select report type -3. Configure data and format -4. Schedule delivery (optional) - -**Report Options:** - -| Setting | Options | -|---------|---------| -| **Content** | Dashboard, AI insights, raw data | -| **Date Range** | Last 7/30/90 days, quarter, custom | -| **Format** | PDF, Interactive Web, Excel, PowerPoint | -| **Schedule** | Daily, Weekly, Monthly | -| **Recipients** | Email addresses for delivery | - ---- - -### Data Sources - -Connect Analytics to various data sources: - -| Source Type | Examples | -|-------------|----------| -| **Databases** | PostgreSQL, MySQL, SQLite | -| **Files** | Excel, CSV, JSON | -| **APIs** | REST endpoints, GraphQL | -| **Apps** | CRM, Support, Calendar data | -| **Bot Data** | Conversation logs, user data | - -**Adding a Data Source:** - -1. Go to **Settings** → **Data Sources** -2. Click **+ Add Source** -3. Select source type -4. Enter connection details -5. Test and save - ---- - -### Sharing Dashboards - -Share dashboards with your team: - -1. Click **Share** on any dashboard -2. Set permissions (View, Edit, Owner) -3. Copy link or invite by email - -**Permission Levels:** - -| Level | Can Do | -|-------|--------| -| **View** | See dashboard, apply filters | -| **Edit** | Modify widgets, change layout | -| **Owner** | Full control, manage sharing | - -**Link Sharing:** -- **Off** - Only specific people can access -- **On** - Anyone with link can view - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `R` | Refresh dashboard | -| `F` | Toggle fullscreen | -| `E` | Edit mode | -| `N` | New widget | -| `D` | Duplicate widget | -| `Delete` | Delete selected widget | -| `Ctrl+S` | Save dashboard | -| `Ctrl+P` | Print / Export PDF | -| `Ctrl+F` | Find / Filter | -| `/` | Quick search | -| `←` `→` | Navigate dashboards | -| `Escape` | Exit edit mode | - ---- - -## Tips & Tricks - -### Dashboard Design - -💡 **Keep it simple** - 5-7 widgets per dashboard is optimal - -💡 **Most important metrics at top** - Follow the F-pattern reading - -💡 **Use consistent colors** - Same metric = same color across widgets - -💡 **Group related widgets** - Keep sales metrics together - -### Data Tips - -💡 **Set up daily sync** for data sources that change frequently - -💡 **Use filters** to let viewers customize their view - -💡 **Add comparison periods** (vs last month, vs last year) - -💡 **Include goals/targets** to show progress - -### AI Tips - -💡 **Ask "why" questions** - AI excels at explaining trends - -💡 **Request predictions** for planning - -💡 **Use AI for anomaly detection** - "What's unusual this month?" - -💡 **Generate executive summaries** before board meetings - ---- - -## Troubleshooting - -### Dashboard not loading - -**Possible causes:** -1. Data source disconnected -2. Query timeout -3. Permission issues - -**Solution:** -1. Check data source status in Settings -2. Reduce date range or add filters -3. Verify you have dashboard access -4. Refresh the page - ---- - -### Data not updating - -**Possible causes:** -1. Sync schedule not running -2. Source data hasn't changed -3. Cache showing old data - -**Solution:** -1. Click Refresh on the dashboard -2. Check data source sync status -3. Go to Settings → Clear cache -4. Verify source data has new records - ---- - -### Charts showing wrong numbers - -**Possible causes:** -1. Filter applied incorrectly -2. Wrong aggregation method -3. Date range mismatch - -**Solution:** -1. Check widget filters -2. Verify aggregation (Sum vs Count vs Average) -3. Confirm date range matches expectations -4. Edit widget and review query - ---- - -### Export not working - -**Possible causes:** -1. Dashboard too large -2. Browser blocking download -3. Permission restrictions - -**Solution:** -1. Try exporting individual widgets -2. Check browser download settings -3. Use a different export format -4. Contact administrator for permissions - ---- - -## BASIC Integration - -Use Analytics in your bot dialogs: - -### Query Metrics - -```botserver/docs/src/chapter-04-gbui/apps/analytics.basic -revenue = GET METRIC "total_revenue" FOR "this month" -lastMonth = GET METRIC "total_revenue" FOR "last month" - -growth = ((revenue - lastMonth) / lastMonth) * 100 - -TALK "Revenue this month: $" + FORMAT(revenue, "#,##0") -TALK "Growth: " + FORMAT(growth, "#0.0") + "%" -``` - -### Generate Reports - -```botserver/docs/src/chapter-04-gbui/apps/analytics-reports.basic -HEAR period AS TEXT "Which period? (weekly/monthly/quarterly)" - -report = GENERATE REPORT "Sales Summary" FOR period - -TALK "Here's your " + period + " sales report:" -SEND FILE report.pdf - -TALK "Key highlights:" -TALK report.summary -``` - -### Get AI Insights - -```botserver/docs/src/chapter-04-gbui/apps/analytics-insights.basic -insights = GET INSIGHTS FOR "Sales Dashboard" - -TALK "Here are today's insights:" -FOR EACH insight IN insights.trends - TALK "📈 " + insight -NEXT - -TALK "Alerts:" -FOR EACH alert IN insights.alerts - TALK "⚠️ " + alert -NEXT -``` - -### Create Dashboard Widget - -```botserver/docs/src/chapter-04-gbui/apps/analytics-widget.basic -widget = NEW OBJECT -widget.type = "line_chart" -widget.title = "Daily Active Users" -widget.source = "bot_analytics" -widget.xAxis = "date" -widget.yAxis = "active_users" -widget.dateRange = "last 30 days" - -ADD WIDGET widget TO "Overview Dashboard" -TALK "Widget added successfully" -``` - -### Scheduled Reports - -```botserver/docs/src/chapter-04-gbui/apps/analytics-scheduled.basic -' This dialog runs on a schedule -report = GENERATE REPORT "Weekly Metrics" FOR "last 7 days" - -recipients = ["ceo@company.com", "team@company.com"] - -FOR EACH email IN recipients - SEND EMAIL TO email - SUBJECT "Weekly Metrics Report - " + TODAY - BODY "Please find attached the weekly metrics report." - ATTACHMENT report.pdf -NEXT - -LOG "Weekly report sent to " + COUNT(recipients) + " recipients" -``` - ---- - -## See Also - -- [Research App](./research.md) - Deep dive into data questions -- [Paper App](./paper.md) - Create reports from insights -- [How To: Monitor Your Bot](../how-to/monitor-sessions.md) -- [Talk to Data Template](../../chapter-02/templates.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/calendar.md b/docs/src/chapter-04-gbui/apps/calendar.md deleted file mode 100644 index a296a320..00000000 --- a/docs/src/chapter-04-gbui/apps/calendar.md +++ /dev/null @@ -1,263 +0,0 @@ -# Calendar - Scheduling - -> **Your personal scheduling assistant** - -Calendar Interface Screen - ---- - -## Overview - -Calendar is your scheduling hub in General Bots Suite. Create events, manage appointments, schedule meetings, and let the AI help you find the perfect time. Calendar syncs with your other apps so you never miss an important date. - ---- - -## Features - -### Views - -| View | Description | -|------|-------------| -| **Day** | Hourly breakdown of single day | -| **Week** | 7-day overview | -| **Month** | Full month grid | -| **Agenda** | List of upcoming events | - -### Calendars - -| Calendar | Icon | Use For | -|----------|------|---------| -| Personal | 🟢 | Private appointments | -| Work | 🔵 | Professional meetings | -| Team | 🟣 | Shared team events | -| Holidays | 🔴 | Public holidays | - -### Event Types - -| Type | Icon | Description | -|------|------|-------------| -| Meeting | 👥 | Group meetings | -| Call | 📞 | Phone/video calls | -| Reminder | 🔔 | Personal reminders | -| All-Day | 📅 | Full day events | -| Recurring | 🔄 | Repeating events | - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `C` | Create new event | -| `T` | Go to today | -| `D` | Day view | -| `W` | Week view | -| `M` | Month view | -| `←` / `→` | Previous / Next period | -| `Delete` | Delete selected event | -| `Enter` | Open event details | - ---- - -## Scheduling via Chat - -### Creating an Event - - - -### Checking Your Schedule - - - -### Finding Available Time - - - -### Rescheduling Events - - - -### Setting Reminders - - - ---- - -## API Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/calendar/events` | GET | List events | -| `/api/calendar/events` | POST | Create event | -| `/api/calendar/events/:id` | GET | Get event details | -| `/api/calendar/events/:id` | PATCH | Update event | -| `/api/calendar/events/:id` | DELETE | Delete event | -| `/api/calendar/availability` | GET | Check free/busy | - -### Query Parameters - -| Parameter | Values | Default | -|-----------|--------|---------| -| `start` | ISO date | Today | -| `end` | ISO date | +30 days | -| `calendar` | Calendar name | All | -| `view` | `day`, `week`, `month` | `month` | - -### Create Event Request - -```json -{ - "title": "Team Meeting", - "start": "2025-05-16T14:00:00Z", - "end": "2025-05-16T15:00:00Z", - "calendar": "work", - "attendees": ["sarah@company.com"], - "location": "Conference Room A", - "reminder": 15, - "recurrence": null -} -``` - -### Event Response - -```json -{ - "id": "evt-123", - "title": "Team Meeting", - "start": "2025-05-16T14:00:00Z", - "end": "2025-05-16T15:00:00Z", - "calendar": "work", - "attendees": [ - { - "email": "sarah@company.com", - "status": "accepted" - } - ], - "location": "Conference Room A", - "reminder": 15, - "created": "2025-05-15T10:30:00Z" -} -``` - ---- - -## Integration with Tasks - -Tasks with due dates automatically appear on your calendar. When you complete a task, it's marked as done on the calendar too. - ---- - -## Troubleshooting - -### Events Not Syncing - -1. Refresh the calendar -2. Check internet connection -3. Verify calendar is enabled in sidebar -4. Wait a few minutes for sync - -### Can't Create Events - -1. Verify you have write access to the calendar -2. Check that start time is before end time -3. Ensure date is not in the past - -### Missing Invitations - -1. Check spam/junk folder in email -2. Verify attendee email addresses -3. Check notification settings - ---- - -## See Also - -- [Suite Manual](../suite-manual.md) - Complete user guide -- [Tasks App](./tasks.md) - Task integration -- [Meet App](./meet.md) - Video meetings -- [Calendar API](../../chapter-10-api/calendar-api.md) - API reference \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/chat.md b/docs/src/chapter-04-gbui/apps/chat.md deleted file mode 100644 index a0a88e32..00000000 --- a/docs/src/chapter-04-gbui/apps/chat.md +++ /dev/null @@ -1,234 +0,0 @@ -# Chat - AI Assistant - -> **Your intelligent conversation partner** - -Chat Interface Screen - ---- - -## Overview - -Chat is the heart of General Bots Suite - your AI-powered assistant that understands context, remembers conversations, and helps you get things done. Built with WebSocket for real-time communication and HTMX for seamless updates. - ---- - -## Features - -### Real-Time Messaging - -Messages are sent and received instantly via WebSocket connection. - - - -### Voice Input - -Click the microphone button to speak your message: - -1. Click **🎤** to start recording -2. Speak your message clearly -3. Click again to stop -4. Message converts to text automatically - -### Quick Suggestions - -Pre-built action chips for common requests: - -| Chip | Action | -|------|--------| -| 📊 Tasks | Show your task list | -| 📧 Check mail | Display unread emails | -| 📅 Schedule | Today's calendar | -| ❓ Help | Available commands | - -### Message History - -- Auto-loads previous messages on page open -- Scroll up to load older messages -- Click "Scroll to bottom" button to return to latest - -### Markdown Support - -Bot responses support full Markdown rendering: - -- **Bold** and *italic* text -- `code snippets` and code blocks -- Bullet and numbered lists -- Links and images -- Tables - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Enter` | Send message | -| `Shift+Enter` | New line (without sending) | -| `↑` (Up arrow) | Edit last message | -| `/` | Open command menu | -| `Escape` | Cancel current action | - -## API Endpoints - -### WebSocket Connection - -``` -ws://your-server:8080/ws -``` - -**Message Types:** -- `TEXT (1)` - Regular text messages -- `VOICE (2)` - Voice messages -- `CONTINUE (3)` - Continue interrupted responses -- `CONTEXT (4)` - Context changes -- `SYSTEM (5)` - System messages - -### REST Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/sessions/current/message` | POST | Send a message | -| `/api/sessions/current/history` | GET | Get chat history | -| `/api/voice/start` | POST | Start voice recording | -| `/api/voice/stop` | POST | Stop voice recording | -| `/api/suggestions` | GET | Get suggestion chips | - - - -## Example Conversations - -### Getting Information - - - -### Creating Tasks - - - -### Drafting Emails - - - - - -## Accessibility - -- Full keyboard navigation -- Screen reader announcements for new messages -- High contrast mode support -- Adjustable font sizes -- ARIA labels on all interactive elements - -```html -
-
- - -``` - -## Troubleshooting - -### Messages Not Sending - -1. Check connection status indicator -2. Verify WebSocket is connected -3. Try refreshing the page -4. Check browser console for errors - -### Voice Not Working - -1. Allow microphone permissions in browser -2. Check device microphone settings -3. Try a different browser -4. Ensure HTTPS connection (required for voice) - -### History Not Loading - -1. Check network connection -2. Verify API endpoint is accessible -3. Clear browser cache -4. Check for JavaScript errors - -## See Also - -- [HTMX Architecture](../htmx-architecture.md) - How Chat uses HTMX -- [Suite Manual](../suite-manual.md) - Complete user guide -- [Tasks App](./tasks.md) - Create tasks from chat -- [Mail App](./mail.md) - Email integration \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/compliance-api.md b/docs/src/chapter-04-gbui/apps/compliance-api.md deleted file mode 100644 index 9b1281d3..00000000 --- a/docs/src/chapter-04-gbui/apps/compliance-api.md +++ /dev/null @@ -1,691 +0,0 @@ -# Compliance API Reference - -> **Programmatic access to privacy and compliance features** - ---- - -## Overview - -The Compliance API allows you to programmatically manage data subject requests, consent records, and compliance scanning. Use this API to integrate privacy features into your applications or automate compliance workflows. - -**Base URL:** `https://your-server.com/api/compliance` - ---- - -## Authentication - -All API requests require authentication using a Bearer token: - -```/dev/null/auth-header.txt -Authorization: Bearer your-api-key -``` - -Get your API key from **Settings** → **API Keys** → **Create New Key** with `compliance` scope. - ---- - -## Endpoints - -### Data Subject Requests (DSR) - -#### List All Requests - -```/dev/null/api-request.txt -GET /api/compliance/dsr -``` - -**Query Parameters:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `status` | string | Filter by status: `pending`, `processing`, `completed`, `rejected` | -| `type` | string | Filter by type: `access`, `deletion`, `rectification`, `portability`, `objection` | -| `from` | date | Start date (YYYY-MM-DD) | -| `to` | date | End date (YYYY-MM-DD) | -| `limit` | number | Results per page (default: 20, max: 100) | -| `offset` | number | Pagination offset | - -**Example Request:** - -```/dev/null/dsr-list-request.txt -GET /api/compliance/dsr?status=pending&limit=10 -``` - -**Example Response:** - -```/dev/null/dsr-list-response.json -{ - "total": 7, - "limit": 10, - "offset": 0, - "requests": [ - { - "id": "DSR-2025-0142", - "type": "access", - "status": "pending", - "userId": "usr_abc123", - "email": "john.doe@email.com", - "submittedAt": "2025-05-13T10:30:00Z", - "dueDate": "2025-05-28T10:30:00Z", - "assignee": null - }, - { - "id": "DSR-2025-0141", - "type": "deletion", - "status": "processing", - "userId": "usr_def456", - "email": "sarah@company.com", - "submittedAt": "2025-05-10T14:15:00Z", - "dueDate": "2025-05-25T14:15:00Z", - "assignee": "admin@company.com" - } - ] -} -``` - ---- - -#### Get Single Request - -```/dev/null/dsr-get-request.txt -GET /api/compliance/dsr/{id} -``` - -**Example Response:** - -```/dev/null/dsr-get-response.json -{ - "id": "DSR-2025-0142", - "type": "access", - "status": "pending", - "userId": "usr_abc123", - "email": "john.doe@email.com", - "name": "John Doe", - "submittedAt": "2025-05-13T10:30:00Z", - "dueDate": "2025-05-28T10:30:00Z", - "assignee": null, - "message": "I would like a copy of all my data", - "verifiedAt": "2025-05-13T10:35:00Z", - "dataFound": { - "profile": true, - "conversations": true, - "consents": true, - "activityLogs": true - }, - "history": [ - { - "action": "created", - "timestamp": "2025-05-13T10:30:00Z", - "actor": "system" - }, - { - "action": "verified", - "timestamp": "2025-05-13T10:35:00Z", - "actor": "system" - } - ] -} -``` - ---- - -#### Create Request - -```/dev/null/dsr-create-request.txt -POST /api/compliance/dsr -``` - -**Request Body:** - -| Field | Type | Required | Description | -|-------|------|----------|-------------| -| `type` | string | Yes | `access`, `deletion`, `rectification`, `portability`, `objection` | -| `email` | string | Yes | User's email address | -| `userId` | string | No | User ID if known | -| `message` | string | No | User's message/reason | -| `skipVerification` | boolean | No | Skip email verification (default: false) | - -**Example Request:** - -```/dev/null/dsr-create-body.json -POST /api/compliance/dsr -Content-Type: application/json - -{ - "type": "access", - "email": "john.doe@email.com", - "message": "Please provide all my personal data" -} -``` - -**Example Response:** - -```/dev/null/dsr-create-response.json -{ - "id": "DSR-2025-0143", - "type": "access", - "status": "pending_verification", - "email": "john.doe@email.com", - "submittedAt": "2025-05-15T14:00:00Z", - "dueDate": "2025-05-30T14:00:00Z", - "verificationSent": true -} -``` - ---- - -#### Update Request Status - -```/dev/null/dsr-update-request.txt -PATCH /api/compliance/dsr/{id} -``` - -**Request Body:** - -| Field | Type | Description | -|-------|------|-------------| -| `status` | string | `processing`, `completed`, `rejected` | -| `assignee` | string | Email of person handling request | -| `notes` | string | Internal notes | -| `rejectionReason` | string | Required if status is `rejected` | - -**Example Request:** - -```/dev/null/dsr-update-body.json -PATCH /api/compliance/dsr/DSR-2025-0142 -Content-Type: application/json - -{ - "status": "processing", - "assignee": "admin@company.com" -} -``` - ---- - -#### Complete Request (with data package) - -```/dev/null/dsr-complete-request.txt -POST /api/compliance/dsr/{id}/complete -``` - -**Request Body:** - -| Field | Type | Description | -|-------|------|-------------| -| `notifyUser` | boolean | Send completion email (default: true) | -| `dataPackageUrl` | string | URL to downloadable data (for access/portability) | -| `expiresAt` | datetime | When download link expires | - -**Example Request:** - -```/dev/null/dsr-complete-body.json -POST /api/compliance/dsr/DSR-2025-0142/complete -Content-Type: application/json - -{ - "notifyUser": true, - "dataPackageUrl": "https://secure.company.com/data/abc123.zip", - "expiresAt": "2025-06-15T00:00:00Z" -} -``` - ---- - -### Consent Management - -#### Get User Consent - -```/dev/null/consent-get-request.txt -GET /api/compliance/consent/{userId} -``` - -**Example Response:** - -```/dev/null/consent-get-response.json -{ - "userId": "usr_abc123", - "email": "john.doe@email.com", - "consents": [ - { - "type": "terms_of_service", - "status": "given", - "version": "2.3", - "timestamp": "2025-01-15T10:32:00Z", - "method": "web_form", - "ip": "192.168.1.100" - }, - { - "type": "marketing", - "status": "given", - "timestamp": "2025-01-15T10:32:00Z", - "method": "web_form" - }, - { - "type": "analytics", - "status": "withdrawn", - "timestamp": "2025-03-22T15:15:00Z", - "method": "preference_center" - } - ] -} -``` - ---- - -#### Record Consent - -```/dev/null/consent-record-request.txt -POST /api/compliance/consent -``` - -**Request Body:** - -| Field | Type | Required | Description | -|-------|------|----------|-------------| -| `userId` | string | Yes | User identifier | -| `email` | string | Yes | User's email | -| `type` | string | Yes | Consent type (e.g., `marketing`, `analytics`) | -| `status` | string | Yes | `given` or `withdrawn` | -| `method` | string | No | How consent was collected | -| `ip` | string | No | User's IP address | -| `userAgent` | string | No | User's browser | - -**Example Request:** - -```/dev/null/consent-record-body.json -POST /api/compliance/consent -Content-Type: application/json - -{ - "userId": "usr_abc123", - "email": "john.doe@email.com", - "type": "marketing", - "status": "given", - "method": "chatbot", - "ip": "192.168.1.100" -} -``` - -**Example Response:** - -```/dev/null/consent-record-response.json -{ - "success": true, - "consentId": "con_xyz789", - "userId": "usr_abc123", - "type": "marketing", - "status": "given", - "timestamp": "2025-05-15T14:30:00Z" -} -``` - ---- - -#### Withdraw Consent - -```/dev/null/consent-withdraw-request.txt -DELETE /api/compliance/consent/{userId}/{type} -``` - -**Example Request:** - -```/dev/null/consent-withdraw-example.txt -DELETE /api/compliance/consent/usr_abc123/marketing -``` - -**Example Response:** - -```/dev/null/consent-withdraw-response.json -{ - "success": true, - "userId": "usr_abc123", - "type": "marketing", - "status": "withdrawn", - "timestamp": "2025-05-15T14:35:00Z" -} -``` - ---- - -#### List Consent Types - -```/dev/null/consent-types-request.txt -GET /api/compliance/consent-types -``` - -**Example Response:** - -```/dev/null/consent-types-response.json -{ - "consentTypes": [ - { - "id": "terms_of_service", - "name": "Terms of Service", - "required": true, - "description": "Agreement to terms and conditions", - "currentVersion": "2.3" - }, - { - "id": "marketing", - "name": "Marketing Communications", - "required": false, - "description": "Receive promotional emails and offers" - }, - { - "id": "analytics", - "name": "Analytics & Improvement", - "required": false, - "description": "Help us improve by analyzing usage patterns" - } - ] -} -``` - ---- - -### Compliance Scanning - -#### Start a Scan - -```/dev/null/scan-start-request.txt -POST /api/compliance/scan -``` - -**Request Body:** - -| Field | Type | Description | -|-------|------|-------------| -| `type` | string | `quick`, `full`, or `custom` | -| `targets` | array | For custom: `["bots", "kb", "users", "logs"]` | -| `botId` | string | Scan specific bot only | - -**Example Request:** - -```/dev/null/scan-start-body.json -POST /api/compliance/scan -Content-Type: application/json - -{ - "type": "full", - "targets": ["bots", "kb", "users", "logs"] -} -``` - -**Example Response:** - -```/dev/null/scan-start-response.json -{ - "scanId": "scan_20250515_001", - "status": "running", - "type": "full", - "startedAt": "2025-05-15T14:45:00Z", - "estimatedDuration": "30 minutes" -} -``` - ---- - -#### Get Scan Status - -```/dev/null/scan-status-request.txt -GET /api/compliance/scan/{scanId} -``` - -**Example Response (In Progress):** - -```/dev/null/scan-status-progress.json -{ - "scanId": "scan_20250515_001", - "status": "running", - "progress": 45, - "currentStep": "Scanning conversation logs", - "startedAt": "2025-05-15T14:45:00Z" -} -``` - -**Example Response (Complete):** - -```/dev/null/scan-status-complete.json -{ - "scanId": "scan_20250515_001", - "status": "completed", - "progress": 100, - "startedAt": "2025-05-15T14:45:00Z", - "completedAt": "2025-05-15T15:12:00Z", - "summary": { - "totalChecks": 148, - "passed": 145, - "warnings": 2, - "critical": 1 - }, - "issues": [ - { - "severity": "critical", - "type": "unencrypted_pii", - "description": "Unencrypted PII found in conversation logs", - "location": "support-bot/logs/2025-05-10", - "affectedRecords": 23, - "recommendation": "Enable automatic PII redaction" - }, - { - "severity": "warning", - "type": "consent_expiring", - "description": "Consent records older than 2 years", - "affectedUsers": 12, - "recommendation": "Send consent renewal requests" - } - ] -} -``` - ---- - -#### Get Latest Scan Results - -```/dev/null/scan-latest-request.txt -GET /api/compliance/scan/latest -``` - -Returns the most recent completed scan results. - ---- - -### Reports - -#### Generate Compliance Report - -```/dev/null/report-generate-request.txt -POST /api/compliance/report -``` - -**Request Body:** - -| Field | Type | Description | -|-------|------|-------------| -| `type` | string | `summary`, `detailed`, `audit` | -| `period` | string | `last_30_days`, `last_90_days`, `year`, `custom` | -| `from` | date | Start date for custom period | -| `to` | date | End date for custom period | -| `format` | string | `json`, `pdf`, `csv` | - -**Example Request:** - -```/dev/null/report-generate-body.json -POST /api/compliance/report -Content-Type: application/json - -{ - "type": "summary", - "period": "last_30_days", - "format": "json" -} -``` - -**Example Response:** - -```/dev/null/report-generate-response.json -{ - "reportId": "rpt_20250515_001", - "generatedAt": "2025-05-15T15:00:00Z", - "period": { - "from": "2025-04-15", - "to": "2025-05-15" - }, - "summary": { - "overallScore": 92, - "dsrRequests": { - "received": 15, - "completed": 12, - "pending": 3, - "averageResponseDays": 8.5 - }, - "consentRate": 94.2, - "dataBreaches": 0, - "scansPerformed": 4, - "issuesFound": 7, - "issuesResolved": 5 - } -} -``` - ---- - -#### Download Report - -```/dev/null/report-download-request.txt -GET /api/compliance/report/{reportId}/download -``` - -Returns the report file in the requested format. - ---- - -### Data Deletion - -#### Delete User Data - -```/dev/null/data-delete-request.txt -DELETE /api/compliance/user/{userId}/data -``` - -**Query Parameters:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `scope` | string | `all`, `conversations`, `profile`, `analytics` | -| `confirm` | boolean | Must be `true` to execute | - -**Example Request:** - -```/dev/null/data-delete-example.txt -DELETE /api/compliance/user/usr_abc123/data?scope=all&confirm=true -``` - -**Example Response:** - -```/dev/null/data-delete-response.json -{ - "success": true, - "userId": "usr_abc123", - "deletedAt": "2025-05-15T15:30:00Z", - "scope": "all", - "itemsDeleted": { - "profile": 1, - "conversations": 45, - "consents": 3, - "activityLogs": 234 - }, - "retainedForLegal": { - "auditLogs": 15 - } -} -``` - ---- - -## Error Responses - -All errors follow this format: - -```/dev/null/error-response.json -{ - "error": { - "code": "ERROR_CODE", - "message": "Human readable message", - "details": {} - } -} -``` - -**Common Error Codes:** - -| Code | HTTP Status | Description | -|------|-------------|-------------| -| `UNAUTHORIZED` | 401 | Invalid or missing API key | -| `FORBIDDEN` | 403 | API key lacks required scope | -| `NOT_FOUND` | 404 | Resource not found | -| `VALIDATION_ERROR` | 400 | Invalid request parameters | -| `RATE_LIMITED` | 429 | Too many requests | -| `INTERNAL_ERROR` | 500 | Server error | - ---- - -## Rate Limits - -| Endpoint | Limit | -|----------|-------| -| All endpoints | 100 requests/minute | -| Scan endpoints | 5 requests/hour | -| Report generation | 10 requests/hour | - -Rate limit headers are included in responses: - -```/dev/null/rate-limit-headers.txt -X-RateLimit-Limit: 100 -X-RateLimit-Remaining: 95 -X-RateLimit-Reset: 1621234567 -``` - ---- - -## Webhooks - -Configure webhooks to receive real-time notifications. - -**Available Events:** - -| Event | Description | -|-------|-------------| -| `dsr.created` | New DSR submitted | -| `dsr.completed` | DSR marked complete | -| `dsr.due_soon` | DSR due within 3 days | -| `consent.changed` | User consent updated | -| `scan.completed` | Compliance scan finished | -| `issue.critical` | Critical issue detected | - -**Webhook Payload Example:** - -```/dev/null/webhook-payload.json -POST https://your-server.com/webhook -Content-Type: application/json -X-Signature: sha256=... - -{ - "event": "dsr.created", - "timestamp": "2025-05-15T14:00:00Z", - "data": { - "id": "DSR-2025-0143", - "type": "access", - "email": "user@example.com" - } -} -``` - ---- - -## See Also - -- [Compliance App](./compliance.md) - User interface guide -- [How To: Configure Compliance](../how-to/configure-compliance.md) -- [BASIC Compliance Keywords](../../chapter-06-gbdialog/keywords-reference.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/compliance.md b/docs/src/chapter-04-gbui/apps/compliance.md deleted file mode 100644 index 66997811..00000000 --- a/docs/src/chapter-04-gbui/apps/compliance.md +++ /dev/null @@ -1,408 +0,0 @@ -# Compliance - Security Scanner - -> **Your privacy and security guardian** - -Compliance Interface Screen - ---- - -## Overview - -Compliance is the security and privacy management app in General Bots Suite. Monitor data handling, manage consent, respond to data subject requests, and ensure your bots comply with regulations like LGPD, GDPR, and CCPA. Compliance helps you protect user data and maintain trust. - ---- - -## Features - -### Compliance Dashboard - -The dashboard gives you an at-a-glance view of your compliance status: - -| Metric | Description | -|--------|-------------| -| **Overall Score** | Percentage score with color indicator | -| **Open Requests** | Pending data subject requests | -| **Data Breaches** | Count in last 90 days | -| **Consent Rate** | Percentage of users with active consent | - -**Score Breakdown by Area:** -- Data Protection -- Consent Management -- Access Controls -- Data Retention -- Breach Response -- Documentation - -**Score Meanings:** - -| Score | Status | Action Needed | -|-------|--------|---------------| -| 90-100% | ✓ Excellent | Maintain current practices | -| 70-89% | ⚠ Good | Address minor issues | -| 50-69% | ⚠ Fair | Prioritize improvements | -| Below 50% | ✗ Poor | Immediate action required | - ---- - -### Security Scanner - -Automatically scan your bots and data for compliance issues. - -#### Running a Scan - -1. Click **Scan Now** in the top right -2. Select scan type: - - **Quick** - Basic checks (5 minutes) - - **Full** - Complete audit (30 minutes) - - **Custom** - Select specific areas -3. Choose scan targets: - - All bots - - Knowledge bases - - User data - - Conversation logs - - External integrations -4. Click **Start Scan** - -#### Scan Results - -Results are categorized by severity: - -| Severity | Icon | Description | -|----------|------|-------------| -| **Critical** | ✗ | Requires immediate attention | -| **Warning** | ⚠ | Should be addressed soon | -| **Passed** | ✓ | No issues found | - -**Common Issues Found:** -- Unencrypted PII in logs -- Consent records needing renewal -- Missing retention policies -- Missing privacy policy links - ---- - -### Data Subject Requests (DSR) - -Handle user requests for their data rights. - -#### Request Types - -| Type | Icon | Description | Deadline | -|------|------|-------------|----------| -| **Data Access** | 📥 | User wants copy of their data | 15-30 days | -| **Data Deletion** | 🗑️ | User wants data erased | 15-30 days | -| **Data Portability** | 📤 | User wants data in machine format | 15-30 days | -| **Rectification** | ✏️ | User wants to correct data | 15-30 days | -| **Processing Objection** | ✋ | User objects to data processing | Immediate | -| **Consent Withdrawal** | 🚫 | User withdraws consent | Immediate | - -#### Processing a Request - -1. Verify user identity -2. Review data found: - - User Profile - - Conversation History - - Consent Records - - Activity Logs -3. Generate data package (for access requests) -4. Send to user or complete deletion -5. Mark request as complete - ---- - -### Consent Management - -Track and manage user consent. - -**Consent Types:** - -| Type | Required | Description | -|------|----------|-------------| -| **Terms of Service** | Yes | Agreement to terms and conditions | -| **Marketing** | No | Promotional communications | -| **Analytics** | No | Usage data collection | -| **Third-Party Sharing** | No | Sharing with partners | - -**Consent Record Information:** -- User ID and email -- Consent status (given/denied/withdrawn) -- Timestamp -- Collection method (web, chat, email) -- IP address and browser info - ---- - -### Data Mapping - -See where personal data is stored: - -| Category | Data Types | Storage Locations | Retention | -|----------|------------|-------------------|-----------| -| **Personal Identifiers** | Names, emails, phones | Users table, conversation logs | 3 years | -| **Communication Data** | Messages, attachments | Conversation logs, MinIO, Qdrant | 1 year | -| **Behavioral Data** | Page views, clicks | Analytics events, preferences | 90 days | - ---- - -### Policy Management - -Manage your compliance policies: - -**Policy Types:** -- Privacy Policy -- Data Retention Policy -- Cookie Policy - -**Data Retention Rules:** - -| Data Type | Retention | Action | -|-----------|-----------|--------| -| Conversation logs | 1 year | Auto-delete | -| User profiles | 3 years | Anonymize | -| Analytics data | 90 days | Auto-delete | -| Consent records | 5 years | Archive | -| Audit logs | 7 years | Archive | - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `S` | Start scan | -| `R` | View reports | -| `D` | Open data map | -| `P` | View policies | -| `N` | New request | -| `/` | Search | -| `Ctrl+E` | Export report | -| `Escape` | Close dialog | - ---- - -## Tips & Tricks - -### Staying Compliant - -💡 **Schedule regular scans** - Weekly scans catch issues early - -💡 **Set up alerts** - Get notified of critical issues immediately - -💡 **Document everything** - Keep records of all compliance decisions - -💡 **Train your team** - Everyone should understand data handling rules - -### Handling Requests - -💡 **Respond quickly** - Start processing within 24 hours - -💡 **Verify identity** - Confirm requestor is the data subject - -💡 **Be thorough** - Check all data sources before responding - -💡 **Keep records** - Document how each request was handled - -### Data Protection - -💡 **Minimize data collection** - Only collect what you need - -💡 **Enable encryption** - Protect data at rest and in transit - -💡 **Use anonymization** - Remove PII when possible - -💡 **Regular audits** - Review who has access to what data - ---- - -## Troubleshooting - -### Scan finds false positives - -**Possible causes:** -1. Pattern matching too aggressive -2. Test data flagged as real PII -3. Encrypted data misidentified - -**Solution:** -1. Review and dismiss false positives -2. Add test data locations to exclusion list -3. Configure scan sensitivity in settings -4. Report issues to improve detection - ---- - -### DSR deadline approaching - -**Possible causes:** -1. Complex request requiring manual review -2. Data spread across multiple systems -3. Identity verification pending - -**Solution:** -1. Prioritize the request immediately -2. Use automated data collection tools -3. Contact user if verification needed -4. Document reason if extension required - ---- - -### Consent not recording - -**Possible causes:** -1. Consent widget not configured -2. JavaScript error on page -3. Database connection issue - -**Solution:** -1. Check consent configuration in settings -2. Test consent flow in preview mode -3. Check error logs for issues -4. Verify database connectivity - ---- - -### Data not deleting automatically - -**Possible causes:** -1. Retention policy not applied -2. Scheduled job not running -3. Data referenced by other records - -**Solution:** -1. Verify policy is active and applied to bot -2. Check scheduled job status in settings -3. Review dependencies that prevent deletion -4. Manually delete if needed - ---- - -## BASIC Integration - -Use Compliance features in your dialogs: - -### Check Consent - -```botserver/docs/src/chapter-04-gbui/apps/compliance-consent.basic -hasConsent = CHECK CONSENT user.id FOR "marketing" - -IF hasConsent THEN - TALK "I can send you our newsletter!" -ELSE - TALK "Would you like to receive our newsletter?" - HEAR response AS BOOLEAN - IF response THEN - RECORD CONSENT user.id FOR "marketing" - TALK "Great! You're now subscribed." - END IF -END IF -``` - -### Request Data Access - -```botserver/docs/src/chapter-04-gbui/apps/compliance-access.basic -TALK "I can help you access your personal data." -HEAR email AS EMAIL "Please confirm your email address" - -IF email = user.email THEN - request = CREATE DSR REQUEST - TYPE "access" - USER user.id - EMAIL email - - TALK "Your request #" + request.id + " has been submitted." - TALK "You'll receive your data within 15 days." -ELSE - TALK "Email doesn't match. Please contact support." -END IF -``` - -### Delete User Data - -```botserver/docs/src/chapter-04-gbui/apps/compliance-delete.basic -TALK "Are you sure you want to delete all your data?" -TALK "This action cannot be undone." -HEAR confirm AS BOOLEAN - -IF confirm THEN - request = CREATE DSR REQUEST - TYPE "deletion" - USER user.id - - TALK "Deletion request submitted: #" + request.id - TALK "Your data will be deleted within 30 days." -ELSE - TALK "No problem. Your data remains safe." -END IF -``` - -### Log Compliance Event - -```botserver/docs/src/chapter-04-gbui/apps/compliance-log.basic -' Log when sensitive data is accessed -LOG COMPLIANCE EVENT - TYPE "data_access" - USER user.id - DATA_TYPE "order_history" - REASON "User requested order status" - BOT "support" - -TALK "Here's your order history..." -``` - ---- - -## API Endpoint: /api/compliance - -The Compliance API allows programmatic access to compliance features. - -### Endpoints Summary - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/compliance/scan` | POST | Start a compliance scan | -| `/api/compliance/scan/{id}` | GET | Get scan results | -| `/api/compliance/dsr` | POST | Create DSR request | -| `/api/compliance/dsr/{id}` | GET | Get DSR status | -| `/api/compliance/consent` | POST | Record consent | -| `/api/compliance/consent/{userId}` | GET | Get user consent | -| `/api/compliance/report` | GET | Generate compliance report | - -### Authentication - -All endpoints require API key authentication: - -```botserver/docs/src/chapter-04-gbui/apps/compliance-auth.txt -Authorization: Bearer your-api-key -``` - -### Example: Check User Consent - -```botserver/docs/src/chapter-04-gbui/apps/compliance-api-example.json -GET /api/compliance/consent/usr_abc123 - -Response: -{ - "userId": "usr_abc123", - "consents": [ - { - "type": "terms_of_service", - "status": "given", - "timestamp": "2025-01-15T10:32:00Z" - }, - { - "type": "marketing", - "status": "withdrawn", - "timestamp": "2025-03-22T15:15:00Z" - } - ] -} -``` - ---- - -## See Also - -- [Compliance API Reference](./compliance-api.md) - Full API documentation -- [Analytics App](./analytics.md) - Monitor compliance metrics -- [Sources App](./sources.md) - Configure bot policies -- [How To: Monitor Your Bot](../how-to/monitor-sessions.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/designer.md b/docs/src/chapter-04-gbui/apps/designer.md deleted file mode 100644 index c84657e0..00000000 --- a/docs/src/chapter-04-gbui/apps/designer.md +++ /dev/null @@ -1,407 +0,0 @@ -# Designer - Visual Builder - -> **Your no-code bot building studio** - -Designer Interface Screen - ---- - -## Overview - -Designer is the visual bot builder in General Bots Suite. Create conversation flows, design user interfaces, and build automations without writing code. Designer uses a drag-and-drop interface that makes bot development accessible to everyone. - ---- - -## Features - -### Creating a New Flow - -**Step 1: Open Designer** - -1. Click the apps menu (⋮⋮⋮) -2. Select **Designer** -3. Click **+ New Flow** - -**Step 2: Configure Flow** - -| Setting | Description | -|---------|-------------| -| **Flow Name** | Descriptive title (e.g., "Customer Support") | -| **Description** | Brief explanation of what the flow does | -| **Start from** | Blank canvas, Template, or Import from file | - -**Step 3: Add Components** - -Drag components from the left panel onto the canvas. - -**Step 4: Connect Components** - -Click and drag from one component's output to another's input. - ---- - -### Component Types - -#### Communication Components - -| Component | Icon | Purpose | -|-----------|------|---------| -| **Talk** | 💬 | Send a message to the user | -| **Hear** | 👂 | Wait for user input | -| **Ask** | ❓ | Ask a question and capture response | -| **Show** | 🖼️ | Display an image, card, or media | -| **Menu** | 📋 | Show clickable options | - -**Talk Component Options:** -- Message text with variations (AI picks randomly) -- Use AI to personalize -- Include typing indicator -- Delay before sending - -**Ask Component Options:** -- Question text -- Variable name to save response -- Expected type: Text, Number, Email, Phone, Date, Yes/No, Multiple Choice -- Validation message for invalid input - ---- - -#### Logic Components - -| Component | Icon | Purpose | -|-----------|------|---------| -| **Branch** | 🔀 | Conditional logic (if/else) | -| **Loop** | 🔄 | Repeat actions | -| **Switch** | 🔃 | Multiple conditions | -| **Wait** | ⏱️ | Pause execution | -| **End** | 🏁 | End the flow | - -**Branch Configuration:** -- Set condition using variable comparisons -- Add multiple AND/OR conditions -- TRUE and FALSE output paths - ---- - -#### Action Components - -| Component | Icon | Purpose | -|-----------|------|---------| -| **Action** | ⚡ | Execute a BASIC keyword | -| **API Call** | 🌐 | Call external API | -| **Database** | 🗄️ | Query or update data | -| **Email** | ✉️ | Send an email | -| **Set Variable** | 📝 | Store a value | - -**Action Error Handling:** -- Stop flow and show error -- Continue to error path -- Retry N times - ---- - -#### AI Components - -| Component | Icon | Purpose | -|-----------|------|---------| -| **AI Chat** | 🤖 | Natural language conversation | -| **Search KB** | 🔍 | Search knowledge base | -| **Generate** | ✨ | Generate text with AI | -| **Classify** | 🏷️ | Categorize user input | -| **Extract** | 📤 | Extract data from text | - -**Classify Example Categories:** -- `support` - Customer needs help with a problem -- `sales` - Customer interested in buying -- `billing` - Payment or invoice questions -- `feedback` - Customer giving feedback -- `other` - Anything else - ---- - -### Working with the Canvas - -#### Navigation - -| Action | How To | -|--------|--------| -| **Pan** | Click and drag on empty space | -| **Zoom in** | Scroll up or click [+] | -| **Zoom out** | Scroll down or click [-] | -| **Fit to screen** | Click [⌖] or press `F` | -| **Select multiple** | Hold Shift and click | -| **Box select** | Hold Ctrl and drag | - -#### Canvas Controls - -| Control | Purpose | -|---------|---------| -| **[+] [-]** | Zoom in/out | -| **[⌖]** | Fit to view | -| **Grid** | Show/hide grid | -| **Snap** | Snap to grid | -| **Auto** | Auto-arrange components | - ---- - -### Using Variables - -Variables store information during the conversation. - -**System Variables (read-only):** - -| Variable | Description | -|----------|-------------| -| `{{user.name}}` | User's display name | -| `{{user.email}}` | User's email address | -| `{{user.phone}}` | User's phone number | -| `{{channel}}` | Current channel (web, whatsapp, etc) | -| `{{today}}` | Today's date | -| `{{now}}` | Current date and time | -| `{{botName}}` | Name of this bot | - -**Flow Variables:** Variables you create using Ask or Set Variable components. - -Reference variables with double curly braces: `{{variableName}}` - ---- - -### Testing Your Flow - -**Preview Mode:** - -1. Click **Preview** button -2. A chat window opens -3. Test the conversation -4. Watch the flow highlight active steps - -The Preview panel shows: -- Flow visualization with active step highlighted -- Test conversation area -- Current variable values -- Clear and Reset buttons - ---- - -### Deploying Your Flow - -When your flow is ready: - -1. Click **Deploy** -2. Choose deployment options: - - **Production** or **Staging only** - - **Immediate** or **Scheduled** -3. Configure triggers: - - Specific phrases (e.g., "help", "support") - - As default fallback - - On schedule -4. Review changes since last deploy -5. Confirm deployment - ---- - -### Templates - -Start faster with pre-built templates: - -| Template | Description | -|----------|-------------| -| **📋 FAQ Bot** | Answer common questions from knowledge base | -| **🎫 Support** | Ticket creation and tracking | -| **💰 Sales** | Lead capture and qualification | -| **📅 Appointment** | Schedule meetings and appointments | -| **📝 Feedback** | Collect customer feedback | -| **🚀 Onboarding** | New user welcome and setup guide | - ---- - -## Keyboard Shortcuts - -### Canvas - -| Shortcut | Action | -|----------|--------| -| `Space + Drag` | Pan canvas | -| `Ctrl + +` | Zoom in | -| `Ctrl + -` | Zoom out | -| `Ctrl + 0` | Reset zoom | -| `F` | Fit to screen | -| `G` | Toggle grid | -| `Delete` | Delete selected | -| `Ctrl + D` | Duplicate selected | -| `Ctrl + Z` | Undo | -| `Ctrl + Y` | Redo | - -### Components - -| Shortcut | Action | -|----------|--------| -| `T` | Add Talk component | -| `H` | Add Hear component | -| `A` | Add Ask component | -| `B` | Add Branch component | -| `E` | Edit selected component | -| `Ctrl + C` | Copy component | -| `Ctrl + V` | Paste component | -| `Ctrl + X` | Cut component | - -### Flow - -| Shortcut | Action | -|----------|--------| -| `Ctrl + S` | Save flow | -| `Ctrl + P` | Preview flow | -| `Ctrl + Enter` | Deploy flow | -| `Ctrl + E` | Export flow | -| `Ctrl + I` | Import flow | - ---- - -## Tips & Tricks - -### Design Tips - -💡 **Keep flows simple** - Break complex flows into smaller sub-flows - -💡 **Use descriptive names** - "Ask for Email" is better than "Step 3" - -💡 **Add comments** - Right-click any component to add notes - -💡 **Test often** - Preview after every few changes - -### Organization Tips - -💡 **Use folders** to organize related flows - -💡 **Version your flows** - Save before major changes - -💡 **Use templates** for consistent starting points - -💡 **Color-code paths** - Use colors for different intents - -### Performance Tips - -💡 **Minimize API calls** - Cache results when possible - -💡 **Use AI classification early** - Route users quickly - -💡 **Set timeouts** - Don't let flows hang indefinitely - -💡 **Handle errors** - Always add error paths - ---- - -## Troubleshooting - -### Flow not triggering - -**Possible causes:** -1. Flow not deployed -2. Trigger words not matching -3. Another flow has priority - -**Solution:** -1. Click Deploy and confirm it's active -2. Check trigger configuration -3. Review flow priority in settings -4. Test with exact trigger phrases - ---- - -### Variables not working - -**Possible causes:** -1. Typo in variable name -2. Variable not set yet in flow -3. Wrong scope - -**Solution:** -1. Check spelling matches exactly (case-sensitive) -2. Ensure variable is set before being used -3. Use Preview mode to watch variable values -4. Check the Variables panel for current values - ---- - -### Component errors - -**Possible causes:** -1. Missing required configuration -2. Invalid connection -3. Action failed - -**Solution:** -1. Click the red error icon for details -2. Fill in all required fields -3. Check that connections make logical sense -4. Review error logs in Preview mode - ---- - -### Preview not matching production - -**Possible causes:** -1. Changes not deployed -2. Different data in production -3. External service differences - -**Solution:** -1. Deploy latest changes -2. Test with same data as production -3. Check API connections are identical -4. Review production logs - ---- - -## BASIC Integration - -Designer flows generate BASIC code. You can view and customize it. - -### View Generated Code - -Right-click any component and select "View Code": - -```botserver/docs/src/chapter-04-gbui/apps/designer-generated.basic -' Generated from "Customer Support" flow - -TALK "Hello! How can I help you today?" - -HEAR userMessage AS TEXT - -intent = CLASSIFY userMessage INTO ["support", "sales", "billing", "other"] - -IF intent = "support" THEN - TALK "I'm sorry to hear you're having issues!" - HEAR orderNumber AS TEXT "What's your order number?" - result = SEARCH KB "order " + orderNumber - TALK result.answer -ELSE IF intent = "sales" THEN - ' ... sales flow -END IF -``` - -### Mix Designer and Code - -Use the **Code** component to add custom BASIC: - -```botserver/docs/src/chapter-04-gbui/apps/designer-custom.basic -' Custom calculation -discount = 0 - -IF userType = "premium" THEN - discount = orderTotal * 0.15 -ELSE IF orderTotal > 100 THEN - discount = orderTotal * 0.05 -END IF - -finalPrice = orderTotal - discount -``` - ---- - -## See Also - -- [Sources App](./sources.md) - Manage prompts and templates -- [Chat App](./chat.md) - Test your flows -- [How To: Write Your First Dialog](../how-to/write-first-dialog.md) -- [BASIC Keywords Reference](../../chapter-06-gbdialog/keywords-reference.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/drive.md b/docs/src/chapter-04-gbui/apps/drive.md deleted file mode 100644 index f018224b..00000000 --- a/docs/src/chapter-04-gbui/apps/drive.md +++ /dev/null @@ -1,296 +0,0 @@ -# Drive - File Management - -> **Your cloud storage workspace** - -Drive Interface Screen - ---- - -## Overview - -Drive is your personal cloud storage within General Bots Suite. Upload, organize, and share files with a familiar interface. Built with HTMX for smooth interactions and SeaweedFS for reliable object storage. - ---- - -## Features - -### Upload Files - -**Drag and Drop:** -1. Drag files from your computer -2. Drop anywhere in the file area -3. Upload progress shows automatically - -**Click to Upload:** -1. Click **+ New** button -2. Select **Upload Files** or **Upload Folder** -3. Choose files from file picker - -### File Operations - -| Action | How to Access | -|--------|---------------| -| **Open** | Double-click file | -| **Download** | Right-click > Download | -| **Rename** | Right-click > Rename | -| **Copy** | Right-click > Copy | -| **Move** | Right-click > Move to | -| **Star** | Right-click > Star | -| **Share** | Right-click > Share | -| **Delete** | Right-click > Delete | - -### View Modes - -| Mode | Description | -|------|-------------| -| **Grid** | Large thumbnails with previews | -| **List** | Detailed table with columns | - -### Navigation - -- **Breadcrumb**: Click any folder in the path to jump back -- **Sidebar**: Quick access to My Drive, Starred, Recent, Trash -- **Search**: Find files by name or content - -### Labels & Organization - -| Label | Icon | Use For | -|-------|------|---------| -| Work | 🔵 | Professional files | -| Personal | 🟢 | Private documents | -| Projects | 🟡 | Project-specific files | -| Custom | 🟣 | Create your own | - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Enter` | Open selected file | -| `Delete` | Move to trash | -| `Ctrl+C` | Copy selected | -| `Ctrl+V` | Paste | -| `Ctrl+X` | Cut selected | -| `Ctrl+A` | Select all | -| `F2` | Rename selected | -| `Ctrl+F` | Search files | -| `Ctrl+U` | Upload files | -| `↑` / `↓` | Navigate files | - ---- - -## Managing Files via Chat - - - -### Finding Files - - - -### Sharing Files - - - -### Creating Folders - - - ---- - -## API Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/drive/files` | GET | List files | -| `/api/drive/files` | POST | Upload file | -| `/api/drive/files/:path` | GET | Download file | -| `/api/drive/files/:path` | DELETE | Delete file | -| `/api/drive/files/:path` | PATCH | Rename/move file | -| `/api/drive/folders` | POST | Create folder | -| `/api/drive/share` | POST | Share file | -| `/api/drive/search` | GET | Search files | - -### Query Parameters - -| Parameter | Values | Default | -|-----------|--------|---------| -| `path` | Folder path | `/` | -| `sort` | `name`, `size`, `modified` | `name` | -| `order` | `asc`, `desc` | `asc` | -| `view` | `grid`, `list` | `grid` | -| `filter` | `starred`, `recent`, `trash` | none | - -### Response Format - -```json -{ - "path": "/Projects/2024", - "files": [ - { - "name": "Report.pdf", - "type": "file", - "size": 245000, - "modified": "2024-03-15T10:30:00Z", - "starred": false, - "shared": true - }, - { - "name": "Documents", - "type": "folder", - "modified": "2024-03-14T09:00:00Z", - "starred": true - } - ], - "storage": { - "used": 4500000000, - "total": 10737418240 - } -} -``` - ---- - -## File Type Icons - -| Type | Extensions | Icon | -|------|------------|------| -| Document | .pdf, .doc, .docx | 📄 | -| Spreadsheet | .xls, .xlsx, .csv | 📊 | -| Presentation | .ppt, .pptx | 📽️ | -| Image | .jpg, .png, .gif, .svg | 🖼️ | -| Video | .mp4, .webm, .mov | 🎬 | -| Audio | .mp3, .wav, .ogg | 🎵 | -| Archive | .zip, .tar, .gz | 📦 | -| Code | .js, .py, .rs, .html | 💻 | -| Folder | - | 📁 | - ---- - -## Storage Backend - -Drive uses SeaweedFS for object storage: - -- **Scalable**: Grows with your needs -- **Redundant**: Data replicated across nodes -- **Fast**: Optimized for small and large files -- **S3 Compatible**: Works with standard S3 tools - -Configure storage in `config.csv`: - -```csv -key,value -drive-server,http://localhost:9000 -drive-bucket,bot-files -drive-quota-gb,10 -``` - ---- - -## Troubleshooting - -### Upload Fails - -1. Check file size (default limit: 100MB) -2. Verify storage quota isn't exceeded -3. Check network connection -4. Try smaller files or compress first - -### Files Not Displaying - -1. Refresh the page -2. Check folder path is correct -3. Verify file permissions -4. Clear browser cache - -### Sharing Not Working - -1. Verify recipient email address -2. Check sharing permissions -3. Ensure file isn't in Trash - ---- - -## See Also - -- [Suite Manual](../suite-manual.md) - Complete user guide -- [Chat App](./chat.md) - Upload files via chat -- [Player App](./player.md) - View files in Player -- [Storage API](../../chapter-10-api/storage-api.md) - API reference \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/mail.md b/docs/src/chapter-04-gbui/apps/mail.md deleted file mode 100644 index 22f275a3..00000000 --- a/docs/src/chapter-04-gbui/apps/mail.md +++ /dev/null @@ -1,313 +0,0 @@ -# Mail - Email Client - -> **Your intelligent inbox** - -Mail Interface Screen - ---- - -## Overview - -Mail is the email application in General Bots Suite. Read, compose, and organize your emails with AI assistance. Mail helps you write better emails, find important messages, and stay on top of your inbox without the clutter. - ---- - -## Features - -### Folders - -| Folder | Description | -|--------|-------------| -| 📥 Inbox | Incoming messages | -| ⭐ Starred | Important emails | -| 📤 Sent | Sent messages | -| 📝 Drafts | Unsent drafts | -| 🗑️ Trash | Deleted emails | - -### Labels - -| Label | Icon | Use For | -|-------|------|---------| -| Urgent | 🔴 | Time-sensitive | -| Personal | 🟢 | Private emails | -| Work | 🔵 | Professional | -| Finance | 🟡 | Bills & money | -| Custom | 🟣 | Create your own | - -### Email Actions - -| Action | Description | -|--------|-------------| -| **Reply** | Respond to sender | -| **Reply All** | Respond to all recipients | -| **Forward** | Send to someone else | -| **Archive** | Remove from inbox | -| **Star** | Mark as important | -| **Label** | Organize with labels | -| **Delete** | Move to trash | - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `C` | Compose new email | -| `R` | Reply | -| `A` | Reply all | -| `F` | Forward | -| `E` | Archive | -| `S` | Star/unstar | -| `Delete` | Move to trash | -| `Ctrl+Enter` | Send email | -| `Escape` | Close/cancel | -| `↑` / `↓` | Navigate emails | - ---- - -## Email via Chat - -### Checking Your Inbox - - - -### Reading an Email - - - -### Composing an Email - - - -### AI-Assisted Writing - - - -### Searching Emails - - - ---- - -## API Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/email/inbox` | GET | List inbox messages | -| `/api/email/send` | POST | Send email | -| `/api/email/draft` | POST | Save draft | -| `/api/email/:id` | GET | Read email | -| `/api/email/:id` | DELETE | Delete email | -| `/api/email/:id/star` | POST | Toggle star | -| `/api/email/:id/label` | POST | Add label | -| `/api/email/search` | GET | Search emails | - -### Query Parameters - -| Parameter | Values | Default | -|-----------|--------|---------| -| `folder` | `inbox`, `sent`, `drafts`, `trash`, `starred` | `inbox` | -| `label` | Label name | none | -| `unread` | `true`, `false` | none | -| `limit` | 1-100 | 25 | -| `offset` | Number | 0 | - -### Send Email Request - -```json -{ - "to": ["john@company.com"], - "cc": [], - "bcc": [], - "subject": "Project Update", - "body": "Hi John,\n\nHere's the latest update...", - "attachments": ["file-id-123"] -} -``` - -### Email Response - -```json -{ - "id": "msg-456", - "from": "sarah@company.com", - "to": ["you@company.com"], - "subject": "Q2 Report Review", - "body": "Hi,\n\nPlease review the attached...", - "date": "2025-05-15T10:32:00Z", - "read": false, - "starred": true, - "labels": ["work"], - "attachments": [ - { - "id": "att-789", - "name": "Q2-Report.pdf", - "size": 2457600 - } - ] -} -``` - ---- - -## Configuration - -Configure email in `config.csv`: - -```csv -key,value -smtp-server,smtp.gmail.com -smtp-port,587 -imap-server,imap.gmail.com -imap-port,993 -email-from,Your Name -``` - -**Note:** Use app-specific passwords for Gmail, not your main password. - ---- - -## Troubleshooting - -### Emails Not Loading - -1. Check internet connection -2. Verify email credentials -3. Check IMAP settings -4. Refresh the page - -### Send Fails - -1. Check recipient address -2. Verify SMTP settings -3. Check attachment size (max 25MB) -4. Try again in a moment - -### Missing Emails - -1. Check spam/junk folder -2. Verify filters aren't hiding emails -3. Check trash folder -4. Sync may take a few minutes - ---- - -## See Also - -- [Suite Manual](../suite-manual.md) - Complete user guide -- [Chat App](./chat.md) - Send quick emails via chat -- [Email API](../../chapter-10-api/email-api.md) - API reference -- [SEND MAIL Keyword](../../chapter-06-gbdialog/keyword-send-mail.md) - BASIC integration \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/meet.md b/docs/src/chapter-04-gbui/apps/meet.md deleted file mode 100644 index cb461699..00000000 --- a/docs/src/chapter-04-gbui/apps/meet.md +++ /dev/null @@ -1,316 +0,0 @@ -# Meet - Video Calls - -> **Your virtual meeting room** - -Meet Interface Screen - ---- - -## Overview - -Meet is the video conferencing app in General Bots Suite. Host video calls, share your screen, collaborate in real-time, and let the AI take notes for you. Meet integrates seamlessly with Calendar so joining meetings is just one click away. - ---- - -## Features - -### Meeting Controls - -| Control | Description | -|---------|-------------| -| 🎤 Mute | Toggle microphone | -| 📹 Video | Toggle camera | -| 🖥️ Share | Share screen | -| ✋ Raise Hand | Get attention | -| 💬 Chat | In-meeting chat | -| 👥 Participants | View attendees | -| ⚙️ Settings | Audio/video settings | -| 📞 Leave | End call | - -### Meeting Features - -| Feature | Description | -|---------|-------------| -| **Screen Sharing** | Share your entire screen or specific window | -| **Recording** | Record meetings for later review | -| **Chat** | Send messages during the meeting | -| **Reactions** | Quick emoji reactions | -| **Raise Hand** | Queue to speak | -| **Breakout Rooms** | Split into smaller groups | -| **AI Notes** | Automatic meeting notes | -| **Transcription** | Live captions | - -### Layouts - -| Layout | Best For | -|--------|----------| -| **Gallery** | Group discussions | -| **Speaker** | Presentations | -| **Sidebar** | Screen sharing | -| **Spotlight** | Featured speaker | - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `M` | Toggle mute | -| `V` | Toggle video | -| `S` | Share screen | -| `H` | Raise/lower hand | -| `C` | Toggle chat | -| `P` | Toggle participants | -| `R` | Start/stop recording | -| `Space` | Push to talk (when muted) | -| `Escape` | Exit fullscreen | - ---- - -## Meetings via Chat - -### Starting a Meeting - - - -### Inviting Participants - - - -### Scheduling a Meeting - - - -### Getting Meeting Notes - - - -### Recording Access - - - ---- - -## API Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/meet/rooms` | GET | List meeting rooms | -| `/api/meet/rooms` | POST | Create room | -| `/api/meet/rooms/:id` | GET | Get room details | -| `/api/meet/rooms/:id/join` | POST | Join meeting | -| `/api/meet/rooms/:id/leave` | POST | Leave meeting | -| `/api/meet/rooms/:id/invite` | POST | Invite participants | -| `/api/meet/recordings` | GET | List recordings | -| `/api/meet/recordings/:id` | GET | Get recording | - -### Create Room Request - -```json -{ - "name": "Team Sync", - "scheduled": "2025-05-16T15:00:00Z", - "duration": 60, - "participants": ["sarah@company.com", "john@company.com"], - "settings": { - "recording": true, - "transcription": true, - "waitingRoom": false - } -} -``` - -### Room Response - -```json -{ - "id": "room-abc123", - "name": "Team Sync", - "url": "https://meet.gb/abc-123", - "host": "you@company.com", - "scheduled": "2025-05-16T15:00:00Z", - "status": "scheduled", - "participants": [ - { - "email": "sarah@company.com", - "status": "invited" - } - ], - "settings": { - "recording": true, - "transcription": true - } -} -``` - ---- - -## Configuration - -Configure Meet in `config.csv`: - -```csv -key,value -meet-provider,livekit -meet-server-url,wss://localhost:7880 -meet-recording-enabled,true -meet-transcription-enabled,true -meet-max-participants,50 -``` - ---- - -## Requirements - -### Browser Support - -- Chrome 90+ -- Firefox 88+ -- Safari 14+ -- Edge 90+ - -### Hardware - -- Webcam (optional) -- Microphone -- Speakers or headphones -- Stable internet connection - -### Permissions - -Allow browser access to: -- Camera -- Microphone -- Screen sharing (when needed) - ---- - -## Troubleshooting - -### No Audio/Video - -1. Check browser permissions -2. Verify correct device selected in settings -3. Try refreshing the page -4. Check if another app is using the camera - -### Poor Quality - -1. Check internet connection speed -2. Close other bandwidth-heavy applications -3. Try disabling HD video -4. Move closer to your router - -### Can't Join Meeting - -1. Verify the meeting link is correct -2. Check if meeting has started -3. Ensure you're not blocked by waiting room -4. Try a different browser - -### Recording Not Working - -1. Verify recording is enabled for the room -2. Check storage quota -3. Ensure you have host permissions - ---- - -## See Also - -- [Suite Manual](../suite-manual.md) - Complete user guide -- [Calendar App](./calendar.md) - Schedule meetings -- [Chat App](./chat.md) - Quick calls from chat -- [Calls API](../../chapter-10-api/calls-api.md) - API reference \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/paper.md b/docs/src/chapter-04-gbui/apps/paper.md deleted file mode 100644 index a4c4d73b..00000000 --- a/docs/src/chapter-04-gbui/apps/paper.md +++ /dev/null @@ -1,572 +0,0 @@ -# Paper - AI Writing - -> **Your intelligent document editor** - -Paper Interface Screen - ---- - -## Overview - -Paper is the AI-powered writing app in General Bots Suite. Create documents, reports, letters, and more with help from your AI assistant. Paper understands context, suggests improvements, and helps you write faster and better. - ---- - -## Features - -### Creating a New Document - -**Method 1: Click New Document** - -1. Click **+ New Doc** in the left sidebar -2. Start typing immediately -3. Document auto-saves as you work - -**Method 2: From Template** - -1. Click **+ New Doc** -2. Select **From Template** -3. Choose a template: - -| Template | Best For | -|----------|----------| -| **Blank** | Starting from scratch | -| **Report** | Business reports with sections | -| **Letter** | Formal correspondence | -| **Meeting Notes** | Agenda and action items | -| **Checklist** | Task tracking | -| **Email Template** | Reusable email formats | -| **Project Proposal** | Pitches and proposals | -| **Resume/CV** | Job applications | -| **Invoice** | Billing documents | - -**Method 3: Ask the Bot** - - - ---- - -### Formatting Text - -Use the toolbar or keyboard shortcuts to format your text: - -| Format | Toolbar | Shortcut | -|--------|---------|----------| -| **Bold** | B | `Ctrl+B` | -| *Italic* | I | `Ctrl+I` | -| Underline | U | `Ctrl+U` | -| ~~Strikethrough~~ | S | `Ctrl+Shift+S` | -| Heading 1 | H1 | `Ctrl+1` | -| Heading 2 | H2 | `Ctrl+2` | -| Heading 3 | H3 | `Ctrl+3` | -| Bullet list | • | `Ctrl+Shift+8` | -| Numbered list | ≡ | `Ctrl+Shift+7` | -| Checklist | ☐ | `Ctrl+Shift+9` | -| Link | 🔗 | `Ctrl+K` | - ---- - -### AI Writing Assistant ✨ - -Paper's AI assistant helps you write better and faster. Click the **✨ AI** button or type `/` to access AI features. - -**Generate Content:** - - - -**Improve Writing Options:** - -| Option | What It Does | -|--------|--------------| -| **📝 Improve writing** | General quality enhancement | -| **✂️ Make it shorter** | Condense without losing meaning | -| **📖 Make it longer** | Expand with more detail | -| **🎯 Make it clearer** | Simplify complex language | -| **💼 Make it professional** | Formal business tone | -| **😊 Make it friendly** | Casual, approachable tone | -| **🔧 Fix grammar** | Correct errors | -| **🌐 Translate** | Convert to another language | - -**Summarize:** - - - -**Generate Ideas:** - - - ---- - -### Document Organization - -**Folders:** - -Organize your documents into folders: - -1. Right-click in the sidebar -2. Select **New Folder** -3. Name your folder -4. Drag documents into it - -**Search Documents:** - -Find documents quickly: - -1. Press `Ctrl+P` or click the search icon -2. Type document name or content -3. Press Enter to open - ---- - -### Collaboration - -**Share a Document:** - -1. Click **Share** button -2. Enter email addresses -3. Set permissions -4. Click **Send** - -**Permissions Explained:** - -| Permission | Can View | Can Comment | Can Edit | -|------------|----------|-------------|----------| -| **View** | ✅ | ❌ | ❌ | -| **Comment** | ✅ | ✅ | ❌ | -| **Edit** | ✅ | ✅ | ✅ | - ---- - -### Export Options - -Export your documents to different formats: - -1. Click **Export ▼** -2. Choose a format: - -| Format | Best For | -|--------|----------| -| **PDF** | Printing, sharing final versions | -| **Word (.docx)** | Editing in Microsoft Word | -| **Markdown (.md)** | Technical documentation | -| **Plain Text (.txt)** | Simple text without formatting | -| **HTML** | Web publishing | - -**Export Options:** -- Include headers and footers -- Include comments -- Include page numbers - ---- - -### Version History - -Paper automatically saves versions of your document: - -1. Click **⚙️** → **Version History** -2. See all saved versions -3. Click to preview -4. Restore if needed - ---- - -## Keyboard Shortcuts - -### Text Formatting - -| Shortcut | Action | -|----------|--------| -| `Ctrl+B` | Bold | -| `Ctrl+I` | Italic | -| `Ctrl+U` | Underline | -| `Ctrl+Shift+S` | Strikethrough | -| `Ctrl+1` | Heading 1 | -| `Ctrl+2` | Heading 2 | -| `Ctrl+3` | Heading 3 | -| `Ctrl+0` | Normal text | - -### Lists & Structure - -| Shortcut | Action | -|----------|--------| -| `Ctrl+Shift+7` | Numbered list | -| `Ctrl+Shift+8` | Bullet list | -| `Ctrl+Shift+9` | Checklist | -| `Tab` | Indent | -| `Shift+Tab` | Outdent | - -### Editing - -| Shortcut | Action | -|----------|--------| -| `Ctrl+Z` | Undo | -| `Ctrl+Y` | Redo | -| `Ctrl+C` | Copy | -| `Ctrl+X` | Cut | -| `Ctrl+V` | Paste | -| `Ctrl+A` | Select all | -| `Ctrl+F` | Find | -| `Ctrl+H` | Find and replace | - -### Navigation - -| Shortcut | Action | -|----------|--------| -| `Ctrl+P` | Quick open document | -| `Ctrl+S` | Save (auto-saves anyway) | -| `Ctrl+N` | New document | -| `Ctrl+W` | Close document | -| `Escape` | Close dialog/menu | - -### AI Features - -| Shortcut | Action | -|----------|--------| -| `/` | Open AI command menu | -| `Ctrl+Shift+A` | AI improve selection | -| `Ctrl+Shift+G` | Generate content | - ---- - -## Tips & Tricks - -### Writing Tips - -💡 **Use headings** to organize your document - makes it scannable - -💡 **Write first, edit later** - don't let perfectionism slow you down - -💡 **Use AI to overcome writer's block** - ask for ideas or outlines - -💡 **Break long paragraphs** into shorter ones for readability - -### Productivity Tips - -💡 **Use templates** for recurring documents (reports, meeting notes) - -💡 **Learn keyboard shortcuts** - much faster than clicking - -💡 **Use `/` commands** for quick AI assistance - -💡 **Set up folders** to keep documents organized - -### AI Tips - -💡 **Be specific** when asking AI for help - better prompts = better results - -💡 **Use "Make it shorter"** for concise professional writing - -💡 **Ask for multiple versions** and pick the best one - -💡 **Use AI to check grammar** before sharing important documents - ---- - -## Troubleshooting - -### Document not saving - -**Possible causes:** -1. Internet connection lost -2. Browser storage full -3. Session expired - -**Solution:** -1. Check internet connection -2. Copy your text as backup (`Ctrl+A`, `Ctrl+C`) -3. Refresh the page -4. Log in again if prompted -5. Paste your text back if needed - ---- - -### Formatting not working - -**Possible causes:** -1. Text not selected -2. Format not supported in current context -3. Browser compatibility issue - -**Solution:** -1. Select the text first, then apply formatting -2. Try a different format -3. Use keyboard shortcuts instead of toolbar -4. Try a different browser - ---- - -### AI features not responding - -**Possible causes:** -1. AI service temporarily unavailable -2. Network timeout -3. Request too long - -**Solution:** -1. Wait a few seconds and try again -2. Try a shorter text selection -3. Refresh the page -4. Check if other AI features work - ---- - -### Can't share document - -**Possible causes:** -1. No sharing permissions -2. Invalid email address -3. Document not saved - -**Solution:** -1. Check if you're the document owner -2. Verify email addresses are correct -3. Wait for document to save (check status bar) -4. Contact administrator if sharing is restricted - ---- - -### Export fails - -**Possible causes:** -1. Document too large -2. Special characters causing issues -3. Browser blocking download - -**Solution:** -1. Try exporting a smaller section first -2. Remove any unusual characters or images -3. Check browser download settings -4. Try a different export format - ---- - -## User Storage - -Paper documents are stored in your personal `.gbusers` folder within the bot's `.gbdrive` storage. This ensures your documents are private and accessible only to you. - -### Storage Structure - -``` -mybot.gbai/ - mybot.gbdrive/ - users/ - your.email@example.com/ # Your user folder - papers/ - current/ # Working documents (auto-saved) - untitled-1.md - meeting-notes.md - named/ # Saved documents - quarterly-report/ - document.md - metadata.json - project-proposal/ - document.md - metadata.json - exports/ # Exported files (PDF, DOCX, etc.) - quarterly-report.pdf - project-proposal.docx -``` - -### Storage Types - -| Type | Location | Description | -|------|----------|-------------| -| **Current** | `papers/current/` | Auto-saved working documents. These are drafts being actively edited. | -| **Named** | `papers/named/{name}/` | Explicitly saved documents with metadata. Each gets its own folder. | -| **Exports** | `exports/` | Generated export files (PDF, Word, HTML, etc.) | - -### Auto-Save Behavior - -Paper auto-saves your work every 30 seconds to `papers/current/`. When you explicitly save with a title: - -1. Document moves from `current/` to `named/{title}/` -2. Metadata file is created with title, timestamps, and word count -3. Original draft in `current/` is removed - -### Accessing Your Documents - -Your documents follow you across sessions and devices. As long as you're logged in with the same email or phone number, you'll see all your documents. - -**From the UI:** -- Documents appear in the sidebar automatically -- Search finds documents by title -- Recent documents shown first - -**From BASIC scripts:** -```basic -' Read your document -content = READ USER DRIVE "papers/named/my-report/document.md" - -' List your papers -papers = LIST USER DRIVE "papers/named/" -``` - -### Storage Limits - -Default limits per user (configurable by administrator): - -| Setting | Default | Description | -|---------|---------|-------------| -| Total storage | 100 MB | Maximum storage per user | -| File size | 5 MB | Maximum single document | -| File count | 500 | Maximum number of documents | - ---- - -## BASIC Integration - -Control Paper from your bot dialogs: - -### Create a Document - -```botserver/docs/src/chapter-04-gbui/apps/paper-create.basic -doc = CREATE DOCUMENT "Project Notes" -doc.content = "Meeting notes from " + TODAY - -SAVE DOCUMENT doc -TALK "Document created: " + doc.id -``` - -### Generate Content with AI - -```botserver/docs/src/chapter-04-gbui/apps/paper-generate.basic -HEAR topic AS TEXT "What should I write about?" - -content = GENERATE TEXT "Write a brief introduction about " + topic - -doc = CREATE DOCUMENT topic -doc.content = content -SAVE DOCUMENT doc - -TALK "I've created a document about " + topic -TALK "Here's a preview:" -TALK LEFT(content, 200) + "..." -``` - -### Export a Document - -```botserver/docs/src/chapter-04-gbui/apps/paper-export.basic -HEAR docName AS TEXT "Which document should I export?" - -doc = FIND DOCUMENT docName - -IF doc IS NOT NULL THEN - pdf = EXPORT DOCUMENT doc AS "PDF" - TALK "Here's your PDF:" - SEND FILE pdf -ELSE - TALK "Document not found" -END IF -``` - -### Search Documents - -```botserver/docs/src/chapter-04-gbui/apps/paper-search.basic -HEAR query AS TEXT "What are you looking for?" - -results = SEARCH DOCUMENTS query - -IF COUNT(results) > 0 THEN - TALK "I found " + COUNT(results) + " documents:" - FOR EACH doc IN results - TALK "- " + doc.title - NEXT -ELSE - TALK "No documents found matching '" + query + "'" -END IF -``` - -### Summarize a Document - -```botserver/docs/src/chapter-04-gbui/apps/paper-summarize.basic -HEAR docName AS TEXT "Which document should I summarize?" - -doc = FIND DOCUMENT docName - -IF doc IS NOT NULL THEN - summary = SUMMARIZE doc.content - TALK "Summary of '" + doc.title + "':" - TALK summary -ELSE - TALK "Document not found" -END IF -``` - ---- - -## See Also - -- [Drive App](./drive.md) - Store and organize files -- [Mail App](./mail.md) - Email your documents -- [Research App](./research.md) - Research topics for your writing -- [How To: Add Documents to Knowledge Base](../how-to/add-kb-documents.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/player.md b/docs/src/chapter-04-gbui/apps/player.md deleted file mode 100644 index e56eed82..00000000 --- a/docs/src/chapter-04-gbui/apps/player.md +++ /dev/null @@ -1,273 +0,0 @@ -# Player - Media Viewer - -> **Integrated viewing for documents, audio, video, and presentations** - -Player Interface Screen - ---- - -## Overview - -Player enables users to view and interact with various file types without leaving the conversation: - -- **Documents**: PDF, DOCX, TXT, MD -- **Presentations**: PPTX, ODP -- **Audio**: MP3, WAV, OGG, M4A -- **Video**: MP4, WEBM, OGV -- **Images**: PNG, JPG, GIF, SVG, WEBP - ---- - -## Accessing Player - -### From Chat - -When a bot shares a file, click the preview to open in Player: - - - -### From Drive - -Navigate to Drive tab and click any supported file to open in Player. - -### Direct URL - -Access files directly: - -``` -/player/{bot_id}/{file_path} -``` - ---- - -## Controls by File Type - -### Document Controls - -| Control | Action | -|---------|--------| -| Previous / Next | Navigate pages | -| Zoom in / out | Adjust view size | -| Download | Download original | -| Search | Search in document | -| Thumbnails | Page thumbnails | - -### Audio Controls - -| Control | Action | -|---------|--------| -| Play / Pause | Control playback | -| Rewind / Forward | Skip 10 seconds | -| Volume | Volume slider | -| Loop | Loop toggle | -| Download | Download file | - -### Video Controls - -| Control | Action | -|---------|--------| -| Play / Pause | Control playback | -| Skip | Skip backward / forward | -| Volume | Volume control | -| Fullscreen | Enter fullscreen | -| Speed | Playback speed | -| Picture-in-picture | Floating window | -| Download | Download file | - -### Presentation Controls - -| Control | Action | -|---------|--------| -| Previous / Next | Navigate slides | -| Fullscreen | Presentation mode | -| Overview | Slide overview | -| Notes | Speaker notes (if available) | -| Download | Download original | - ---- - -## Keyboard Shortcuts - -| Key | Action | -|-----|--------| -| `Space` | Play/Pause (audio/video) or Next (slides) | -| `←` / `→` | Previous / Next | -| `↑` / `↓` | Volume up / down | -| `F` | Fullscreen toggle | -| `M` | Mute toggle | -| `Esc` | Exit fullscreen / Close player | -| `+` / `-` | Zoom in / out | -| `Home` / `End` | Go to start / end | - ---- - -## BASIC Integration - -### Share Files with Player Preview - - - ---- - -## Supported Formats - -### Documents - -| Format | Extension | Notes | -|--------|-----------|-------| -| PDF | `.pdf` | Full support with text search | -| Word | `.docx` | Converted to viewable format | -| Text | `.txt` | Plain text with syntax highlighting | -| Markdown | `.md` | Rendered with formatting | -| HTML | `.html` | Sanitized rendering | - -### Presentations - -| Format | Extension | Notes | -|--------|-----------|-------| -| PowerPoint | `.pptx` | Full slide support | -| OpenDocument | `.odp` | Converted to slides | -| PDF | `.pdf` | Treated as slides | - -### Audio - -| Format | Extension | Notes | -|--------|-----------|-------| -| MP3 | `.mp3` | Universal support | -| WAV | `.wav` | Uncompressed audio | -| OGG | `.ogg` | Open format | -| M4A | `.m4a` | AAC audio | -| FLAC | `.flac` | Lossless audio | - -### Video - -| Format | Extension | Notes | -|--------|-----------|-------| -| MP4 | `.mp4` | H.264/H.265 | -| WebM | `.webm` | VP8/VP9 | -| OGV | `.ogv` | Theora | - -### Images - -| Format | Extension | Notes | -|--------|-----------|-------| -| PNG | `.png` | Lossless with transparency | -| JPEG | `.jpg`, `.jpeg` | Compressed photos | -| GIF | `.gif` | Animated support | -| SVG | `.svg` | Vector graphics | -| WebP | `.webp` | Modern format | - ---- - -## Configuration - -Configure Player behavior in `config.csv`: - -```csv -key,value -player-autoplay,false -player-default-volume,80 -player-video-quality,auto -player-preload,metadata -player-allow-download,true -player-max-file-size-mb,100 -``` - ---- - -## API Access - -### Get File for Player - -``` -GET /api/drive/{bot_id}/files/{file_path}?preview=true -``` - -### Stream Media - -``` -GET /api/drive/{bot_id}/stream/{file_path} -``` - -Supports HTTP Range requests for seeking. - -### Get Thumbnail - -``` -GET /api/drive/{bot_id}/thumbnail/{file_path} -``` - ---- - -## Security - -- Files are served through authenticated endpoints -- User permissions respected for file access -- Downloads can be disabled per bot -- Watermarking available for sensitive documents - -## Performance - -- Lazy loading for large documents -- Adaptive streaming for video -- Thumbnail generation for previews -- Client-side caching for repeat views - -## Mobile Support - -Player is fully responsive: -- Touch gestures for navigation -- Pinch-to-zoom for documents -- Swipe for slides -- Native fullscreen support - ---- - -## See Also - -- [Drive App](./drive.md) - File management -- [Drive Integration](../../chapter-08-config/drive.md) - File storage configuration -- [Storage API](../../chapter-10-api/storage-api.md) - File management API \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/research.md b/docs/src/chapter-04-gbui/apps/research.md deleted file mode 100644 index 3bde1a1c..00000000 --- a/docs/src/chapter-04-gbui/apps/research.md +++ /dev/null @@ -1,411 +0,0 @@ -# Research - AI Search - -> **Your intelligent research assistant** - -Research Interface Screen - ---- - -## Overview - -Research is the AI-powered search and discovery app in General Bots Suite. Find information from the web, your documents, and databases using natural language. Research understands your questions, finds relevant sources, and presents organized answers with citations. - ---- - -## Features - -### Basic Search - -Just type your question in natural language: - -**Example Questions:** - -| Category | Examples | -|----------|----------| -| **📊 Business** | "What are our sales numbers for Q1 2025?" | -| **📚 Knowledge** | "How does photosynthesis work?" | -| **🔍 Research** | "Compare React vs Vue for web development" | -| **📋 Documents** | "What does our employee handbook say about PTO?" | - ---- - -### Search Sources - -Choose where to search: - -| Source | What It Searches | Best For | -|--------|------------------|----------| -| **All** | Everything available | General questions | -| **Web** | Internet/public websites | Current events, general knowledge | -| **Documents** | Your uploaded files (.gbkb) | Company policies, internal info | -| **Database** | Connected databases | Business data, reports | -| **Custom** | Specific sources you choose | Focused research | - ---- - -### AI-Powered Answers - -Research doesn't just find links—it reads, understands, and summarizes: - - - ---- - -### Follow-Up Questions - -Continue your research with follow-up questions: - - - ---- - -### Source Citations - -Every answer includes citations so you can verify: - -| Source Type | Information Provided | -|-------------|---------------------| -| **Internal Documents** | File name, location, relevant pages | -| **Web Sources** | URL, retrieval date, site name | -| **Database** | Table name, query used | - -**Actions available:** -- **View Document** - Open the source file -- **Open Link** - Navigate to web source -- **Copy Citation** - Copy formatted citation - ---- - -### Research History - -Access your previous searches: - -1. Click **History** in the top right -2. Browse or search past queries -3. Click to revisit any search - -History is organized by: -- **Today** - Recent searches -- **Yesterday** - Previous day -- **Last Week** - Older searches - ---- - -### Export Results - -Save your research for later use: - -| Format | Best For | -|--------|----------| -| **PDF** | Sharing, printing | -| **Markdown** | Documentation | -| **Word** | Reports, editing | -| **Copy to Paper** | Continue writing | - -**Export Options:** -- Include answer -- Include sources with citations -- Include search query -- Include timestamp - ---- - -### Advanced Search - -Use operators for more precise searches: - -| Operator | Example | What It Does | -|----------|---------|--------------| -| `""` | `"exact phrase"` | Find exact match | -| `AND` | `solar AND wind` | Both terms required | -| `OR` | `solar OR wind` | Either term | -| `NOT` | `energy NOT nuclear` | Exclude term | -| `site:` | `site:company.com` | Search specific site | -| `type:` | `type:pdf` | Search specific file type | -| `date:` | `date:2025` | Filter by date | -| `in:` | `in:documents` | Search specific source | - -**Examples:** - -`"quarterly report" AND sales date:2025` - Finds documents with exact phrase "quarterly report" AND the word "sales" from 2025 - -`project proposal NOT draft type:pdf` - Finds PDF files about project proposals, excluding drafts - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `/` | Focus search box | -| `Enter` | Search | -| `Ctrl+Enter` | Search in new tab | -| `Escape` | Clear search / close panel | -| `↑` / `↓` | Navigate results | -| `Ctrl+C` | Copy answer | -| `Ctrl+S` | Save/export results | -| `H` | Open history | -| `Tab` | Cycle through sources | -| `1-5` | Jump to source N | - ---- - -## Tips & Tricks - -### Better Search Results - -💡 **Be specific** - "Q1 2025 sales revenue by region" works better than "sales" - -💡 **Use natural language** - Ask questions like you would ask a colleague - -💡 **Try different phrasings** - If results aren't great, rephrase your question - -💡 **Use follow-ups** - Build on previous searches for deeper research - -### Finding Documents - -💡 **Mention the document type** - "Find the PDF about vacation policy" - -💡 **Reference dates** - "Meeting notes from last Tuesday" - -💡 **Name departments** - "HR policies about sick leave" - -### Web Research - -💡 **Be current** - Add "2025" or "latest" for recent information - -💡 **Compare sources** - Research shows multiple sources for verification - -💡 **Check citations** - Click through to verify important information - ---- - -## Troubleshooting - -### No results found - -**Possible causes:** -1. Query too specific -2. Information not in knowledge base -3. Typo in search terms - -**Solution:** -1. Try broader search terms -2. Search "All" sources instead of one -3. Check spelling -4. Try different phrasing -5. Upload relevant documents to knowledge base - ---- - -### Wrong or irrelevant results - -**Possible causes:** -1. Ambiguous query -2. Outdated documents in KB -3. Source selection too broad - -**Solution:** -1. Be more specific in your question -2. Use quotes for exact phrases -3. Select specific source (Documents only, Web only) -4. Use advanced operators - ---- - -### Sources not loading - -**Possible causes:** -1. Document was moved or deleted -2. Web page no longer available -3. Permission issues - -**Solution:** -1. Check if document exists in Drive -2. Try opening the web link directly -3. Ask administrator about permissions -4. Use cached/saved version if available - ---- - -### Search is slow - -**Possible causes:** -1. Searching many sources -2. Large knowledge base -3. Complex query - -**Solution:** -1. Select specific source instead of "All" -2. Be more specific to narrow results -3. Wait for indexing to complete (if recent uploads) -4. Check network connection - ---- - -### AI answer seems incorrect - -**Possible causes:** -1. Outdated information in sources -2. AI misinterpreted question -3. Conflicting information in sources - -**Solution:** -1. Always verify with cited sources -2. Rephrase your question -3. Ask for clarification: "Are you sure about X?" -4. Check multiple sources for accuracy - ---- - -## BASIC Integration - -Use Research in your bot dialogs: - -### Basic Search - -```botserver/docs/src/chapter-04-gbui/apps/research-basic.basic -HEAR question AS TEXT "What would you like to know?" - -result = SEARCH question - -TALK result.answer - -TALK "Sources:" -FOR EACH source IN result.sources - TALK "- " + source.title -NEXT -``` - -### Search Specific Sources - -```botserver/docs/src/chapter-04-gbui/apps/research-sources.basic -' Search only documents -result = SEARCH "vacation policy" IN "documents" - -' Search only web -result = SEARCH "latest AI news" IN "web" - -' Search specific knowledge base -result = SEARCH "product specs" IN "products.gbkb" -``` - -### Research with Follow-up - -```botserver/docs/src/chapter-04-gbui/apps/research-followup.basic -TALK "What would you like to research?" -HEAR topic AS TEXT - -result = SEARCH topic -TALK result.answer - -HEAR followUp AS TEXT "Any follow-up questions? (or 'done')" - -WHILE followUp <> "done" - result = SEARCH followUp WITH CONTEXT result - TALK result.answer - HEAR followUp AS TEXT "Any more questions? (or 'done')" -WEND - -TALK "Research complete!" -``` - -### Export Research - -```botserver/docs/src/chapter-04-gbui/apps/research-export.basic -HEAR query AS TEXT "What should I research?" - -result = SEARCH query - -' Export as PDF -pdf = EXPORT RESEARCH result AS "PDF" -SEND FILE pdf - -' Or copy to Paper -doc = CREATE DOCUMENT "Research: " + query -doc.content = result.answer + "\n\nSources:\n" + result.citations -SAVE DOCUMENT doc - -TALK "Research saved to Paper" -``` - -### Automated Research Report - -```botserver/docs/src/chapter-04-gbui/apps/research-report.basic -topics = ["market trends", "competitor analysis", "customer feedback"] - -report = "" -FOR EACH topic IN topics - result = SEARCH topic + " 2025" - report = report + "## " + topic + "\n\n" - report = report + result.answer + "\n\n" -NEXT - -doc = CREATE DOCUMENT "Weekly Research Report" -doc.content = report -SAVE DOCUMENT doc - -TALK "Research report created with " + COUNT(topics) + " topics" -``` - ---- - -## See Also - -- [Paper App](./paper.md) - Write documents based on your research -- [Drive App](./drive.md) - Upload documents to knowledge base -- [Chat App](./chat.md) - Ask quick questions -- [How To: Add Documents to Knowledge Base](../how-to/add-kb-documents.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/sources.md b/docs/src/chapter-04-gbui/apps/sources.md deleted file mode 100644 index dc1d53ea..00000000 --- a/docs/src/chapter-04-gbui/apps/sources.md +++ /dev/null @@ -1,356 +0,0 @@ -# Sources - Prompts & Templates - -> **Your bot configuration hub** - -Sources Interface Screen - ---- - -## Overview - -Sources is the configuration center in General Bots Suite. Manage your bots, prompts, templates, and knowledge bases all in one place. Sources is where you create new bots, customize their behavior, and organize the content that powers your AI assistant. - ---- - -## Features - -### Managing Bots - -#### Creating a New Bot - -1. Click **+ New Bot** in the top right -2. Fill in the bot details: - -| Field | Description | -|-------|-------------| -| **Bot ID** | Unique identifier (lowercase, numbers, hyphens only) | -| **Display Name** | User-friendly name shown in chat | -| **Description** | Brief explanation of what the bot does | -| **Start from** | Blank, Template, or Clone existing | - -#### Bot Settings - -Click the **⚙️** icon on any bot to configure: - -**General Settings:** - -| Setting | Description | -|---------|-------------| -| **Display Name** | Name shown to users | -| **Welcome Message** | First message when conversation starts | -| **Language** | Primary language for the bot | -| **Timezone** | Bot's timezone for date/time operations | -| **Status** | Live, Draft, or Maintenance | - -**Status Options:** -- **Live** - Bot is active and responding -- **Draft** - Bot is hidden from users -- **Maintenance** - Shows maintenance message - -#### AI Settings - -| Setting | Description | -|---------|-------------| -| **Provider** | AI provider (OpenAI, Azure, etc.) | -| **Model** | Model to use (GPT-4, etc.) | -| **Temperature** | Creativity level (0 = focused, 1 = creative) | -| **Max Tokens** | Maximum response length | -| **System Prompt** | Bot personality and instructions | -| **Knowledge Base** | Connected .gbkb for answers | - ---- - -### Managing Prompts - -Prompts are reusable text templates for AI interactions. - -**Prompt Types:** - -| Type | Purpose | -|------|---------| -| **System Prompt** | Bot personality/behavior | -| **Task Prompt** | Specific task instructions | -| **Template** | Reusable text with variables | - -**Creating a Prompt:** - -1. Click **+ New Prompt** -2. Enter a name (e.g., "support-agent") -3. Select type -4. Write prompt content with optional `{{variables}}` -5. Save and link to bots - -**Example Prompt:** - -```botserver/docs/src/chapter-04-gbui/apps/sources-prompt-example.txt -You are a friendly and professional customer support agent -for {{company_name}}. - -## Your Personality -- Be warm and empathetic -- Use simple, clear language -- Be patient and thorough - -## Guidelines -- Always verify customer identity before sharing account info -- If unsure, search the knowledge base -- Escalate complex issues to human agents -- Never make promises about refunds or compensation -``` - ---- - -### Managing Templates - -Templates are pre-built bot packages you can reuse. - -**Installed Templates:** - -| Template | Description | -|----------|-------------| -| **📋 CRM** | Full CRM with leads, contacts | -| **📋 Support** | Ticket management and customer service | -| **📋 FAQ** | Answer common questions from KB | - -**Available Templates:** - -| Template | Description | -|----------|-------------| -| **📋 HR** | Employee self-service | -| **📋 Analytics** | Dashboard and metrics | -| **📋 Compliance** | LGPD, GDPR compliance | - -**Template Contents:** - -Templates include: -- Dialog scripts (.bas files) -- Bot configuration -- Knowledge base documentation -- Sample conversations - ---- - -### Managing Knowledge Bases - -Knowledge bases store documents that your bot can search for answers. - -| Field | Description | -|-------|-------------| -| **Documents** | Count of uploaded files | -| **Size** | Total storage used | -| **Last Indexed** | When content was last processed | -| **Used By** | Bots connected to this KB | - -**Uploading Documents:** - -1. Open the knowledge base -2. Click **Upload** or drag files -3. Organize into folders -4. Click **Reindex** to process new content - -**Supported Formats:** -- PDF, DOCX, TXT, MD -- CSV, XLSX -- HTML, JSON - ---- - -## Import and Export - -### Exporting a Bot - -1. Click **⚙️** on the bot -2. Select **Export** -3. Choose what to include: - - Bot configuration - - Dialog scripts (.bas files) - - Prompts - - Knowledge base (optional, large) - - Conversation history (optional) -4. Select format: .gbai, ZIP, or JSON - -### Importing a Bot - -1. Click **Import** at the top -2. Drop file or browse (supported: .gbai, .zip) -3. Choose: - - Create new bot, or - - Replace existing bot -4. Configure merge options for prompts and KB - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Ctrl+N` | New bot | -| `Ctrl+S` | Save changes | -| `Ctrl+E` | Export selected | -| `Ctrl+I` | Import | -| `Delete` | Delete selected | -| `Ctrl+D` | Duplicate | -| `F2` | Rename | -| `/` | Search | -| `Enter` | Open selected | -| `Escape` | Close dialog | - ---- - -## Tips & Tricks - -### Bot Management - -💡 **Use descriptive names** - "customer-support-v2" is better than "bot1" - -💡 **Keep prompts separate** - Reuse prompts across multiple bots - -💡 **Version your exports** - Export before major changes - -💡 **Test in Draft mode** - Don't go Live until fully tested - -### Prompt Writing - -💡 **Be specific** - Clear instructions give better results - -💡 **Use examples** - Show the AI what good responses look like - -💡 **Set boundaries** - Define what the bot should NOT do - -💡 **Use variables** - Make prompts reusable with {{placeholders}} - -### Knowledge Base - -💡 **Organize in folders** - Group related documents together - -💡 **Keep documents current** - Remove outdated information - -💡 **Use clear filenames** - "refund-policy-2025.pdf" not "doc1.pdf" - -💡 **Reindex after changes** - New content isn't searchable until indexed - ---- - -## Troubleshooting - -### Bot not responding - -**Possible causes:** -1. Bot is in Draft mode -2. AI provider not configured -3. No dialogs or prompts set up - -**Solution:** -1. Check bot status is "Live" -2. Verify AI settings have valid API key -3. Ensure at least start.bas exists -4. Check error logs in Analytics - ---- - -### Knowledge base not finding answers - -**Possible causes:** -1. Documents not indexed -2. Document format not supported -3. Query doesn't match content - -**Solution:** -1. Click "Reindex" and wait for completion -2. Convert documents to supported formats -3. Check document actually contains the information -4. Try different phrasing - ---- - -### Import fails - -**Possible causes:** -1. File corrupted -2. Incompatible version -3. Duplicate bot ID - -**Solution:** -1. Try re-exporting from source -2. Check General Bots version compatibility -3. Choose "Create new bot" instead of replace -4. Rename bot ID if duplicate - ---- - -### Prompts not applying - -**Possible causes:** -1. Prompt not linked to bot -2. Variable not defined -3. Syntax error in prompt - -**Solution:** -1. Check AI Settings → System Prompt selection -2. Verify all {{variables}} have values -3. Test prompt with "Test" button -4. Check for unclosed brackets or quotes - ---- - -## BASIC Integration - -Access Sources data from dialogs: - -### Get Bot Configuration - -```botserver/docs/src/chapter-04-gbui/apps/sources-config.basic -config = GET BOT CONFIG -TALK "Bot name: " + config.displayName -TALK "Language: " + config.language -``` - -### Use Prompts - -```botserver/docs/src/chapter-04-gbui/apps/sources-prompts.basic -' Load a prompt template -prompt = GET PROMPT "summarize" - -' Use with variables -summary = GENERATE WITH PROMPT prompt, content -TALK summary -``` - -### Search Knowledge Base - -```botserver/docs/src/chapter-04-gbui/apps/sources-search.basic -HEAR question AS TEXT "What would you like to know?" - -results = SEARCH KB question IN "support.gbkb" - -IF COUNT(results) > 0 THEN - TALK results[0].answer - TALK "Source: " + results[0].source -ELSE - TALK "I couldn't find information about that." -END IF -``` - -### List Available Bots - -```botserver/docs/src/chapter-04-gbui/apps/sources-list.basic -bots = GET BOTS - -TALK "Available bots:" -FOR EACH bot IN bots - IF bot.status = "live" THEN - TALK "● " + bot.displayName - ELSE - TALK "○ " + bot.displayName + " (draft)" - END IF -NEXT -``` - ---- - -## See Also - -- [Designer App](./designer.md) - Visual flow builder -- [Drive App](./drive.md) - Upload KB documents -- [How To: Create Your First Bot](../how-to/create-first-bot.md) -- [How To: Add Documents to Knowledge Base](../how-to/add-kb-documents.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/suite.md b/docs/src/chapter-04-gbui/apps/suite.md deleted file mode 100644 index e317fe2c..00000000 --- a/docs/src/chapter-04-gbui/apps/suite.md +++ /dev/null @@ -1,214 +0,0 @@ -# Suite - Full Desktop Interface - -> **Complete productivity suite with integrated applications** - -Suite Interface Screen - ---- - -## Overview - -The Suite provides a complete desktop interface with multiple integrated applications for web, desktop, and mobile platforms. It serves as the primary interface for General Bots, combining AI-powered chat with productivity tools. - ---- - -## Features - -### Multi-Application Layout - -The Suite includes integrated applications: - -| App | Purpose | -|-----|---------| -| 💬 Chat | AI assistant conversations | -| 📁 Drive | File management | -| ✓ Tasks | To-do lists | -| ✉ Mail | Email client | -| 📅 Calendar | Scheduling | -| 🎥 Meet | Video calls | -| 🎬 Player | Media viewer | -| 📝 Paper | AI writing | -| 🔍 Research | AI search | -| 📊 Analytics | Dashboards | - -### Responsive Design - -The Suite adapts to any screen size: - -- **Desktop (>1024px)**: Full multi-panel layout with persistent navigation -- **Tablet (768-1024px)**: Collapsible sidebar with touch-optimized controls -- **Mobile (<768px)**: Single column with bottom navigation and swipe gestures - -### Theme Support - -- Light and dark mode -- Custom color schemes via `.gbtheme` -- Automatic system preference detection - ---- - -## Navigation - -### Header Bar - -The header provides quick access to: -- Logo and branding -- App selector grid -- Theme switcher -- User menu and settings - -### App Launcher - -Click the grid icon (⋮⋮⋮) to access all applications in a dropdown menu. - -### Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Alt+1` | Chat | -| `Alt+2` | Drive | -| `Alt+3` | Tasks | -| `Alt+4` | Mail | -| `Alt+5` | Calendar | -| `Alt+6` | Meet | -| `Esc` | Close menus | - ---- - -## Usage - -### As Desktop App - -Used automatically when running with `--desktop`: - -```bash -./botserver --desktop -# Opens Suite in native window -``` - -### As Web Interface - -Default template for browser access: - -```bash -./botserver -# Browse to http://localhost:8080 -# Loads Suite interface -``` - -### As Mobile PWA - -Install as Progressive Web App: -1. Open in mobile browser -2. Add to home screen -3. Launches as standalone app - ---- - -## Example Workflows - -### Quick Task Creation - - - -### File Sharing - - - -### Meeting Scheduling - - - ---- - -## Performance - -| Metric | Target | -|--------|--------| -| Initial Load | < 200KB | -| WebSocket Latency | < 50ms | -| Touch Response | 60fps animations | -| Offline Support | Service worker caching | - ---- - -## Browser Support - -- Chrome/Edge 90+ -- Firefox 88+ -- Safari 14+ -- Mobile browsers (iOS Safari, Chrome Mobile) - ---- - -## Configuration - -Customize Suite behavior in `config.csv`: - -```csv -key,value -theme-color1,#0d2b55 -theme-color2,#e3f2fd -theme-title,My Company Suite -theme-logo,https://example.com/logo.svg -suite-default-app,chat -suite-sidebar-collapsed,false -``` - ---- - -## See Also - -- [Chat App](./chat.md) - AI assistant -- [Drive App](./drive.md) - File management -- [Tasks App](./tasks.md) - Task management -- [HTMX Architecture](../htmx-architecture.md) - Technical details -- [Theme Customization](../../chapter-05-gbtheme/README.md) - Styling \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/apps/tasks.md b/docs/src/chapter-04-gbui/apps/tasks.md deleted file mode 100644 index 81778ffe..00000000 --- a/docs/src/chapter-04-gbui/apps/tasks.md +++ /dev/null @@ -1,230 +0,0 @@ -# Tasks - To-Do Management - -> **Track what needs to be done** - -Tasks Interface Screen - ---- - -## Overview - -Tasks is your to-do list manager within General Bots Suite. Create tasks, set priorities, organize by category, and track your progress. Built with HTMX for instant updates without page reloads. - ---- - -## Features - -### Adding Tasks - -**Quick Add:** -1. Type task description in the input box -2. Press **Enter** or click **+ Add** - -**With Details:** -1. Type task description -2. Select a category (optional) -3. Pick a due date (optional) -4. Click **+ Add** - -### Priority Levels - -| Priority | Icon | When to Use | -|----------|------|-------------| -| **High** | 🔴 | Must do today | -| **Medium** | 🟡 | Important but not urgent | -| **Low** | 🟢 | Can wait | -| **None** | ⚪ | No deadline | - -### Categories - -| Category | Icon | -|----------|------| -| Work | 💼 | -| Personal | 🏠 | -| Shopping | 🛒 | -| Health | ❤️ | -| Custom | 🏷️ | - -### Filter Tabs - -| Tab | Shows | -|-----|-------| -| **All** | All tasks | -| **Active** | Uncompleted tasks | -| **Completed** | Done tasks | -| **Priority** | High priority only | - ---- - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Enter` | Add task (when in input) | -| `Space` | Toggle task completion | -| `Delete` | Remove selected task | -| `Tab` | Move to next field | -| `Escape` | Cancel editing | -| `↑` / `↓` | Navigate tasks | - ---- - -## Creating Tasks from Chat - - - -### Managing Tasks via Chat - - - -### Setting Reminders - - - ---- - -## API Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/tasks` | GET | List all tasks | -| `/api/tasks` | POST | Create new task | -| `/api/tasks/:id` | GET | Get single task | -| `/api/tasks/:id` | PATCH | Update task | -| `/api/tasks/:id` | DELETE | Delete task | -| `/api/tasks/stats` | GET | Get task statistics | - -### Query Parameters - -| Parameter | Values | Default | -|-----------|--------|---------| -| `filter` | `all`, `active`, `completed`, `priority` | `all` | -| `category` | `work`, `personal`, `shopping`, `health` | none | -| `sort` | `created`, `dueDate`, `priority`, `text` | `created` | -| `order` | `asc`, `desc` | `desc` | - -### Request Body (Create/Update) - -```json -{ - "text": "Review quarterly report", - "category": "work", - "dueDate": "2024-03-20", - "priority": "high", - "completed": false -} -``` - -### Response Format - -```json -{ - "id": 123, - "text": "Review quarterly report", - "category": "work", - "dueDate": "2024-03-20", - "priority": "high", - "completed": false, - "createdAt": "2024-03-18T10:30:00Z", - "updatedAt": "2024-03-18T10:30:00Z" -} -``` - ---- - -## Integration with Calendar - -Tasks with due dates automatically appear in your Calendar view, helping you visualize your workload across days and weeks. - ---- - -## Troubleshooting - -### Tasks Not Saving - -1. Check network connection -2. Verify API endpoint is accessible -3. Check browser console for errors -4. Try refreshing the page - -### Filters Not Working - -1. Click the filter tab again -2. Check if tasks exist for that filter -3. Clear browser cache - -### Stats Not Updating - -1. Reload the page -2. Check for JavaScript errors in console - ---- - -## See Also - -- [Suite Manual](../suite-manual.md) - Complete user guide -- [Chat App](./chat.md) - Create tasks from chat -- [Calendar App](./calendar.md) - View tasks in calendar -- [Tasks API](../../chapter-10-api/tasks-api.md) - API reference \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/console-mode.md b/docs/src/chapter-04-gbui/console-mode.md deleted file mode 100644 index edfe043b..00000000 --- a/docs/src/chapter-04-gbui/console-mode.md +++ /dev/null @@ -1,107 +0,0 @@ -# Console Mode - -The BotServer console mode provides a text-based interface for monitoring your bot's operation directly in the terminal. - -## Starting Console Mode - -```bash -# Start BotServer with console UI -./botserver --console -``` - -## Console Interface - -The console displays real-time information about your running BotServer instance: - -``` -╔════════════════════════════════════════════════════════════╗ -║ BotServer Console ║ -╠════════════════════════════════════════════════════════════╣ -║ Status: Running ║ -║ Uptime: 2h 34m 12s ║ -║ Port: 8080 ║ -║ ║ -║ Components: ║ -║ PostgreSQL: ✓ Connected ║ -║ Cache: ✓ Connected ║ -║ Storage: ✓ Connected ║ -║ Vectors: ✓ Connected ║ -║ ║ -║ Active Sessions: 12 ║ -║ Messages Today: 1,234 ║ -║ ║ -║ Press 'q' to quit, 'r' to refresh ║ -╚════════════════════════════════════════════════════════════╝ -``` - -## Console Features - -### Status Overview - -The status overview displays the server's current state including whether it is running or stopped, an uptime counter showing how long the server has been active, the port the server is listening on, and health checks for all connected components. - -### Session Information - -Session information provides visibility into current activity with a count of active sessions, the total number of messages processed today, and recent activity indicators that show when the last interactions occurred. - -### Component Status - -Real-time status monitoring covers all infrastructure components including database connectivity to PostgreSQL, cache service status, storage availability for file operations, and vector database connection status for semantic search functionality. - -## Keyboard Controls - -| Key | Action | -|-----|--------| -| `q` | Quit console mode | -| `r` | Force refresh display | -| `c` | Clear console | -| `h` | Show help | - -## Console Output - -The console provides basic logging output showing timestamped events as they occur: - -``` -[2024-01-15 10:23:45] Server started on port 8080 -[2024-01-15 10:23:46] Database connected -[2024-01-15 10:23:47] Cache initialized -[2024-01-15 10:23:48] Storage mounted -[2024-01-15 10:24:01] New session: abc123 -[2024-01-15 10:24:15] Message processed -``` - -## Using Console Mode - -### Development - -Console mode is particularly useful during development for monitoring component initialization, tracking connection status, observing error messages as they occur, and watching session activity in real time. - -### Production - -In production environments, console mode helps with quick status checks when you need immediate visibility, basic monitoring of system health, and troubleshooting connection issues without accessing the web interface. - -## Limitations - -Console mode provides basic monitoring only and is not intended for detailed analytics. For comprehensive data analysis, query PostgreSQL directly for session data. System logs contain detailed error information for debugging. The cache service provides its own statistics interface. Application logs offer the most complete picture for troubleshooting complex issues. - -## Terminal Requirements - -Console mode supports any terminal with basic text output capabilities. UTF-8 support is recommended to properly render box drawing characters. A minimum width of 80 columns is recommended for optimal display. The console works over SSH connections, making it suitable for remote server monitoring. - -## Tips - -Console mode operates in read-only fashion and does not accept bot commands. For interactive bot testing, use the web interface available at http://localhost:8080. The display refreshes automatically every few seconds to show current status. Output is buffered for performance to avoid slowing down the server during high activity periods. - -## Troubleshooting - -### Console Not Updating - -If the console stops updating, check terminal compatibility with your emulator, ensure the process has proper permissions to write to the terminal, and verify that all components are running and responsive. - -### Display Issues - -Display problems can often be resolved by trying a different terminal emulator. Check that your terminal encoding is set to UTF-8 for proper character rendering. If text appears cut off, resize the terminal window to provide adequate width for the display. - -## Summary - -Console mode provides a simple, lightweight way to monitor BotServer status without needing a web browser. It's ideal for quick checks and basic monitoring, but for full functionality including interactive bot testing and detailed analytics, use the web interface. \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/how-to/README.md b/docs/src/chapter-04-gbui/how-to/README.md deleted file mode 100644 index 4ea9df13..00000000 --- a/docs/src/chapter-04-gbui/how-to/README.md +++ /dev/null @@ -1,253 +0,0 @@ -# How To... Tutorials - -> **📖 Step-by-Step Guides for General Bots Suite** -> -> *Clear instructions for common tasks, inspired by classic computer manuals* - ---- - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ╔═══════════════════════════════════════════════════════════════╗ │ -│ ║ ║ │ -│ ║ ██╗ ██╗ ██████╗ ██╗ ██╗ ████████╗ ██████╗ ║ │ -│ ║ ██║ ██║██╔═══██╗██║ ██║ ╚══██╔══╝██╔═══██╗ ║ │ -│ ║ ███████║██║ ██║██║ █╗ ██║ ██║ ██║ ██║ ║ │ -│ ║ ██╔══██║██║ ██║██║███╗██║ ██║ ██║ ██║ ║ │ -│ ║ ██║ ██║╚██████╔╝╚███╔███╔╝ ██║ ╚██████╔╝ ██╗ ║ │ -│ ║ ╚═╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚═╝ ╚═════╝ ╚═╝ ║ │ -│ ║ ║ │ -│ ╚═══════════════════════════════════════════════════════════════╝ │ -│ │ -│ Your Guide to General Bots Suite │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## About These Tutorials - -These tutorials are designed like the classic computer manuals of the early 1990s — clear, numbered steps with visual diagrams showing exactly what to do. Each tutorial follows the same format: - -- **Objective** — What you'll accomplish -- **Time Required** — How long it takes -- **Prerequisites** — What you need before starting -- **Steps** — Numbered instructions with screenshots -- **Troubleshooting** — Common problems and solutions -- **Next Steps** — What to learn next - ---- - -## 🚀 Getting Started - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Create Your First Bot](./create-first-bot.md) | Set up a working bot from scratch | 10 min | -| [Your First Conversation](./first-conversation.md) | Talk to your bot and understand responses | 5 min | -| [Understanding the Interface](./understanding-interface.md) | Navigate the Suite like a pro | 10 min | - ---- - -## 💬 Chat & Conversations - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Ask Questions Effectively](./ask-questions.md) | Get better answers from your AI assistant | 5 min | -| [Use Voice Input](./voice-input.md) | Talk instead of type | 3 min | -| [Create Chat Shortcuts](./chat-shortcuts.md) | Set up quick commands | 10 min | -| [Export Conversations](./export-conversations.md) | Save chat history for reference | 5 min | - ---- - -## 📁 File Management (Drive) - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Upload Your First File](./upload-files.md) | Add documents to Drive | 3 min | -| [Organize with Folders](./organize-folders.md) | Create a logical file structure | 10 min | -| [Share Files Securely](./share-files.md) | Grant access to team members | 5 min | -| [Search for Documents](./search-documents.md) | Find files instantly | 5 min | - ---- - -## 📚 Knowledge Base - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Add Documents to Knowledge Base](./add-kb-documents.md) | Teach your bot from files | 15 min | -| [Import a Website](./import-website.md) | Crawl and learn from web pages | 10 min | -| [Create FAQ Responses](./create-faq.md) | Define question-answer pairs | 15 min | -| [Manage Collections](./manage-collections.md) | Organize knowledge by topic | 10 min | - ---- - -## 🔧 BASIC Dialogs - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Write Your First Dialog](./write-first-dialog.md) | Create a simple conversation script | 20 min | -| [Use HEAR and TALK](./hear-and-talk.md) | Gather and display information | 10 min | -| [Store User Information](./store-user-info.md) | Remember data between conversations | 15 min | -| [Call External APIs](./call-external-apis.md) | Connect to web services | 20 min | -| [Send Automated Messages](./send-automated.md) | Schedule broadcasts and reminders | 15 min | - ---- - -## 📱 Messaging Channels - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Connect WhatsApp](./connect-whatsapp.md) | Set up WhatsApp Business integration | 30 min | -| [Configure Email](./configure-email.md) | Enable email conversations | 15 min | -| [Set Up SMS](./setup-sms.md) | Add text message support | 15 min | -| [Embed Web Chat](./embed-web-chat.md) | Add chat to your website | 10 min | - ---- - -## 📊 Analytics & Monitoring - -| Tutorial | Description | Time | -|----------|-------------|------| -| [View Bot Statistics](./view-statistics.md) | Understand usage metrics | 10 min | -| [Monitor Live Sessions](./monitor-sessions.md) | Watch conversations in real-time | 10 min | -| [Create Custom Reports](./create-reports.md) | Build dashboards for insights | 20 min | -| [Export Analytics Data](./export-analytics.md) | Download metrics for external analysis | 10 min | - ---- - -## 🎨 Customization - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Change Your Bot's Theme](./change-theme.md) | Customize colors and appearance | 10 min | -| [Add a Custom Logo](./add-logo.md) | Brand your bot interface | 5 min | -| [Create Custom Cards](./create-cards.md) | Design rich message layouts | 20 min | -| [Modify the Welcome Message](./welcome-message.md) | Personalize the first interaction | 5 min | - ---- - -## 🏢 Templates - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Install the CRM Template](./install-crm.md) | Set up customer relationship management | 20 min | -| [Use the HR Template](./use-hr-template.md) | Deploy employee self-service | 15 min | -| [Configure Compliance Bot](./configure-compliance.md) | Enable privacy request handling | 25 min | -| [Build from Template](./build-from-template.md) | Customize a template for your needs | 30 min | - ---- - -## 🔒 Security & Administration - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Set Up User Authentication](./setup-auth.md) | Enable secure login | 20 min | -| [Configure Permissions](./configure-permissions.md) | Control who can do what | 15 min | -| [Enable Audit Logging](./enable-audit.md) | Track all system activities | 10 min | -| [Backup Your Bot](./backup-bot.md) | Protect your configuration and data | 15 min | - ---- - -## 🐛 Troubleshooting - -| Tutorial | Description | Time | -|----------|-------------|------| -| [Debug Dialog Errors](./debug-dialogs.md) | Fix common BASIC script problems | 15 min | -| [Resolve Connection Issues](./resolve-connections.md) | Troubleshoot network problems | 10 min | -| [Fix Knowledge Base Gaps](./fix-kb-gaps.md) | Improve bot answers | 20 min | -| [Performance Optimization](./performance-tips.md) | Make your bot faster | 15 min | - ---- - -## Quick Reference Card - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ QUICK REFERENCE CARD │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ KEYBOARD SHORTCUTS │ -│ ───────────────── │ -│ Ctrl + Enter ........ Send message │ -│ Ctrl + K ............ Quick command palette │ -│ Ctrl + / ............ Toggle voice input │ -│ Ctrl + N ............ New item (context-aware) │ -│ Ctrl + S ............ Save current work │ -│ Escape .............. Close dialog/panel │ -│ │ -│ COMMON BASIC KEYWORDS │ -│ ──────────────────── │ -│ TALK "message" ...... Display message to user │ -│ HEAR variable ....... Wait for user input │ -│ SET BOT MEMORY ...... Store bot-wide data │ -│ GET USER MEMORY ..... Retrieve user-specific data │ -│ USE KB "name" ....... Activate knowledge base │ -│ SEND MAIL ........... Send email notification │ -│ │ -│ WHERE TO GET HELP │ -│ ───────────────── │ -│ • Type "help" in Chat for assistance │ -│ • Press F1 anywhere for context help │ -│ • Visit community.pragmatismo.com for forums │ -│ • Email support@pragmatismo.com for enterprise support │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Tips for Following Tutorials - -### ✅ Before You Start - -1. **Bookmark this page** — You'll return to it often -2. **Have the Suite open** — Follow along step-by-step -3. **Take notes** — Write down customizations you make -4. **Don't skip steps** — Each step builds on the previous - -### ✅ While Following Steps - -1. **Read the entire step first** — Then perform the action -2. **Match the screenshots** — If your screen looks different, stop and check -3. **Use exact values** — Type what the tutorial shows, then customize later -4. **Check results** — Verify each step worked before moving on - -### ✅ If Something Goes Wrong - -1. **Don't panic** — Most problems have simple solutions -2. **Re-read the step** — You may have missed something -3. **Check Troubleshooting** — Each tutorial has a help section -4. **Ask for help** — The Chat assistant can guide you - ---- - -## Icon Legend - -Throughout these tutorials, you'll see these indicators: - -| Icon | Meaning | -|------|---------| -| 💡 | **Tip** — Helpful suggestion to work more efficiently | -| ⚠️ | **Warning** — Important caution to avoid problems | -| 📝 | **Note** — Additional information or context | -| ✅ | **Checkpoint** — Verify your progress before continuing | -| 🔧 | **Configuration** — Settings you may need to adjust | - ---- - -## Version Information - -These tutorials are written for: -- **General Bots Suite** version 5.0+ -- **Browser**: Chrome, Firefox, Safari, or Edge (latest versions) -- **Last Updated**: 2025 - -If you're using an older version, some screens may look different. - ---- - -*"The best way to learn is to do."* - -**Start with [Create Your First Bot](./create-first-bot.md)** → \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/how-to/add-kb-documents.md b/docs/src/chapter-04-gbui/how-to/add-kb-documents.md deleted file mode 100644 index 6b768791..00000000 --- a/docs/src/chapter-04-gbui/how-to/add-kb-documents.md +++ /dev/null @@ -1,531 +0,0 @@ -# How To: Add Documents to Knowledge Base - -> **Tutorial 3 of the Knowledge Base Series** -> -> *Teach your bot from files in 15 minutes* - ---- - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ │ │ -│ │ 📚 ADD DOCUMENTS TO KNOWLEDGE BASE │ │ -│ │ │ │ -│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ -│ │ │ Step │───▶│ Step │───▶│ Step │───▶│ Step │ │ │ -│ │ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │ │ -│ │ │Prepare │ │ Upload │ │ Index │ │ Test │ │ │ -│ │ │ Docs │ │ Files │ │ KB │ │ KB │ │ │ -│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ -│ │ │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Objective - -By the end of this tutorial, you will have: -- Prepared documents for the knowledge base -- Uploaded files to your bot's `.gbkb` folder -- Indexed documents for semantic search -- Tested that your bot can answer questions from the documents - ---- - -## Time Required - -⏱️ **15 minutes** - ---- - -## Prerequisites - -Before you begin, make sure you have: - -- [ ] A working bot (see [Create Your First Bot](./create-first-bot.md)) -- [ ] Access to the Drive app -- [ ] Documents to upload (PDF, Word, Text, or Markdown files) - ---- - -## What is a Knowledge Base? - -A **Knowledge Base (KB)** is a collection of documents that your bot uses to answer questions. When a user asks something, the bot searches through these documents to find relevant information. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ HOW KNOWLEDGE BASE WORKS │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ User asks: "What is our refund policy?" │ -│ │ │ -│ ▼ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 🔍 Semantic Search │ │ -│ │ Searches through all documents in the knowledge base │ │ -│ └────────────────────────┬────────────────────────────────────┘ │ -│ │ │ -│ ┌───────────────────┼───────────────────┐ │ -│ ▼ ▼ ▼ │ -│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ -│ │policies │ │ FAQ │ │ terms │ │ -│ │ .pdf │ │ .docx │ │ .md │ │ -│ └────┬────┘ └─────────┘ └─────────┘ │ -│ │ │ -│ ▼ Found match! │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ "Refunds are available within 30 days of purchase..." │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ │ -│ ▼ │ -│ Bot answers with context from the document │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Supported File Formats - -| Format | Extension | Best For | -|--------|-----------|----------| -| **PDF** | `.pdf` | Manuals, reports, official documents | -| **Word** | `.docx`, `.doc` | Policies, procedures, articles | -| **Text** | `.txt` | Simple content, FAQs | -| **Markdown** | `.md` | Technical documentation | -| **Excel** | `.xlsx`, `.xls` | FAQs, structured data | -| **PowerPoint** | `.pptx` | Training materials | -| **HTML** | `.html` | Web content | - ---- - -## Step 1: Prepare Your Documents - -### 1.1 Gather Your Files - -Collect the documents you want your bot to learn from. Good candidates include: - -- ✅ Product manuals -- ✅ FAQ documents -- ✅ Company policies -- ✅ Help articles -- ✅ Training materials - -### 1.2 Review Document Quality - -Before uploading, check that your documents: - -| Check | Why It Matters | -|-------|----------------| -| Text is selectable | Scanned images can't be indexed | -| Content is accurate | Bot will repeat incorrect info | -| Information is current | Outdated docs confuse users | -| No sensitive data | Protect confidential information | - -⚠️ **Warning**: The bot will use exactly what's in your documents. Remove any outdated or incorrect information first. - -### 1.3 Organize Files (Optional) - -For large knowledge bases, organize files into folders by topic: - -``` -mycompany.gbkb/ -├── 📁 products/ -│ ├── product-guide.pdf -│ └── specifications.docx -├── 📁 policies/ -│ ├── refund-policy.pdf -│ └── privacy-policy.md -├── 📁 support/ -│ ├── faq.docx -│ └── troubleshooting.pdf -└── 📁 training/ - └── onboarding-guide.pptx -``` - -✅ **Checkpoint**: You have documents ready to upload. - ---- - -## Step 2: Upload Files to Knowledge Base - -### 2.1 Open the Drive App - -Click the **Apps Menu** (⋮⋮⋮) and select **Drive**. - -### 2.2 Navigate to Your Bot's KB Folder - -Navigate to your bot's knowledge base folder: - -``` -📂 mycompany.gbai - └── 📂 mycompany.gbkb ◄── Open this folder -``` - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 📁 Drive │ -├─────────────────────────────────────────────────────────────────────────┤ -│ 📂 mycompany.gbai │ -│ ├── 📂 mycompany.gbdialog │ -│ ├── 📂 mycompany.gbot │ -│ ├── 📂 mycompany.gbkb ◄── Knowledge base folder │ -│ │ └── (your documents go here) │ -│ └── 📂 mycompany.gbdrive │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.3 Upload Your Documents - -**Method A: Drag and Drop** -1. Open your file explorer -2. Select the documents you want to upload -3. Drag them into the Drive window - -**Method B: Upload Button** -1. Click the **Upload** button (📤) -2. Select files from your computer -3. Click **Open** - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 📁 Drive > mycompany.gbai > mycompany.gbkb │ -├─────────────────────────────────────────────────────────────────────────┤ -│ ┌─────────────────┐ ┌─────────────────┐ │ -│ │ 📤 Upload │ │ 📁 New Folder │ │ -│ └─────────────────┘ └─────────────────┘ │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ 📄 company-faq.pdf 2.3 MB Just now │ -│ 📄 product-manual.docx 1.1 MB Just now │ -│ 📄 refund-policy.pdf 0.5 MB Just now │ -│ │ -│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │ -│ ↑ Drag files here to upload │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.4 Wait for Upload to Complete - -You'll see a progress indicator for each file. Wait until all uploads finish. - -💡 **Tip**: Large files may take longer. PDF files typically upload fastest. - -✅ **Checkpoint**: Your documents appear in the `.gbkb` folder. - ---- - -## Step 3: Index the Knowledge Base - -After uploading, you need to index the documents so the bot can search them. - -### 3.1 Automatic Indexing - -In most cases, indexing happens automatically when files are uploaded. Look for: -- A "Processing..." indicator -- Files changing from gray to normal color -- A completion notification - -### 3.2 Manual Indexing (If Needed) - -If automatic indexing doesn't start, trigger it manually: - -**From Chat:** -``` -/reindex -``` - -**From a BASIC Dialog:** -```basic -' Clear and rebuild the knowledge base -CLEAR KB -USE KB "mycompany" -``` - -### 3.3 Check Indexing Status - -You can check how many documents are indexed: - -**From Chat:** -``` -/kb stats -``` - -**Expected Output:** -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 📊 Knowledge Base Statistics │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Collection: mycompany │ -│ Documents: 3 │ -│ Vectors: 847 │ -│ Status: ● Ready │ -│ Last Index: 2 minutes ago │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: Documents are indexed and ready to search. - ---- - -## Step 4: Test the Knowledge Base - -### 4.1 Open Chat - -Click the **Apps Menu** (⋮⋮⋮) and select **Chat**. - -### 4.2 Ask a Question from Your Documents - -Type a question that can be answered by your uploaded documents: - -``` -You: What is the refund policy? -``` - -### 4.3 Verify the Response - -The bot should answer using information from your documents: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 💬 Chat │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 👤 You │ │ -│ │ What is the refund policy? │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 🤖 Bot │ │ -│ │ │ │ -│ │ Based on our refund policy document: │ │ -│ │ │ │ -│ │ Customers may request a full refund within 30 days of │ │ -│ │ purchase. After 30 days, refunds are prorated based on │ │ -│ │ usage. To request a refund, contact support@company.com │ │ -│ │ with your order number. │ │ -│ │ │ │ -│ │ 📄 Source: refund-policy.pdf │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 4.4 Test Different Questions - -Try several questions to ensure the knowledge base is working: - -| Test Question | Expected Source | -|---------------|-----------------| -| "How do I return a product?" | refund-policy.pdf | -| "What are the product specs?" | product-manual.docx | -| "How do I contact support?" | company-faq.pdf | - -✅ **Checkpoint**: Your bot answers questions using the uploaded documents! - ---- - -## 🎉 Congratulations! - -You've successfully added documents to your knowledge base! Here's what you accomplished: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ✓ Prepared documents for upload │ -│ ✓ Uploaded files to the .gbkb folder │ -│ ✓ Indexed documents for semantic search │ -│ ✓ Tested that the bot can answer from documents │ -│ │ -│ Your bot can now answer questions from your documents! │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Troubleshooting - -### Problem: Bot doesn't find information from documents - -**Cause**: Documents may not be indexed yet. - -**Solution**: -1. Check indexing status with `/kb stats` -2. Wait a few minutes for processing to complete -3. Try `/reindex` to force re-indexing - -### Problem: Bot gives wrong information - -**Cause**: Document contains outdated or incorrect content. - -**Solution**: -1. Review the source document -2. Update or replace the incorrect document -3. Re-index the knowledge base - -### Problem: "No relevant information found" - -**Cause**: Question doesn't match document content well enough. - -**Solution**: -1. Try rephrasing the question -2. Use keywords that appear in your documents -3. Check that the document actually contains the answer - -### Problem: Upload fails - -**Cause**: File too large or unsupported format. - -**Solution**: -1. Check file size (max 50MB per file) -2. Verify file format is supported -3. Try converting to PDF if format issues persist - -### Problem: PDF text not extracted - -**Cause**: PDF contains scanned images, not selectable text. - -**Solution**: -1. Use OCR software to convert image-based PDFs -2. Or recreate the document as a text-based PDF -3. Consider using Word format instead - ---- - -## Best Practices - -### Document Organization - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ RECOMMENDED KB STRUCTURE │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ mycompany.gbkb/ │ -│ │ │ -│ ├── 📁 policies/ ◄── Company policies │ -│ │ ├── refund-policy.pdf │ -│ │ ├── privacy-policy.pdf │ -│ │ └── terms-of-service.pdf │ -│ │ │ -│ ├── 📁 products/ ◄── Product documentation │ -│ │ ├── product-guide.pdf │ -│ │ ├── user-manual.pdf │ -│ │ └── specifications.xlsx │ -│ │ │ -│ ├── 📁 support/ ◄── Support resources │ -│ │ ├── faq.docx │ -│ │ └── troubleshooting.pdf │ -│ │ │ -│ └── 📁 internal/ ◄── Internal documentation │ -│ ├── processes.docx │ -│ └── guidelines.pdf │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### Content Guidelines - -1. **Be specific** — Clear, detailed content produces better answers -2. **Use headings** — Helps the bot find relevant sections -3. **Include keywords** — Use terms users are likely to search for -4. **Update regularly** — Keep documents current -5. **Remove duplicates** — Avoid conflicting information - -### Naming Conventions - -| ✅ Good Names | ❌ Bad Names | -|--------------|-------------| -| `refund-policy-2024.pdf` | `doc1.pdf` | -| `product-manual-v2.docx` | `final final (2).docx` | -| `employee-handbook.pdf` | `new document.pdf` | - ---- - -## Advanced: Using KB in Dialogs - -You can reference the knowledge base in your BASIC dialogs: - -```basic -' Activate a specific knowledge base -USE KB "mycompany" - -' Ask the user what they want to know -TALK "What would you like to know about?" -HEAR question - -' The bot will automatically search the KB and respond -``` - -### Multiple Knowledge Bases - -You can have different knowledge bases for different purposes: - -```basic -' Switch between knowledge bases based on topic -TALK "Are you asking about Products or Policies?" -HEAR topic - -IF topic = "Products" THEN - USE KB "products" -ELSE IF topic = "Policies" THEN - USE KB "policies" -END IF - -TALK "What would you like to know?" -HEAR question -``` - ---- - -## Next Steps - -| Next Tutorial | What You'll Learn | -|---------------|-------------------| -| [Import a Website](./import-website.md) | Crawl web pages into your KB | -| [Create FAQ Responses](./create-faq.md) | Define question-answer pairs | -| [Manage Collections](./manage-collections.md) | Organize knowledge by topic | - ---- - -## Quick Reference - -### Chat Commands - -| Command | Description | -|---------|-------------| -| `/kb stats` | Show knowledge base statistics | -| `/reindex` | Rebuild the search index | -| `/kb list` | List all KB collections | - -### BASIC Keywords - -| Keyword | Description | Example | -|---------|-------------|---------| -| `USE KB` | Activate a KB | `USE KB "mycompany"` | -| `CLEAR KB` | Clear current KB | `CLEAR KB` | -| `KB STATISTICS` | Get KB info | `stats = KB STATISTICS` | - -### File Size Limits - -| File Type | Max Size | -|-----------|----------| -| PDF | 50 MB | -| Word | 25 MB | -| Excel | 25 MB | -| Text/MD | 10 MB | - ---- - -*Tutorial 3 of 30 • [Back to How-To Index](./README.md) • [Next: Import a Website →](./import-website.md)* \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/how-to/connect-whatsapp.md b/docs/src/chapter-04-gbui/how-to/connect-whatsapp.md deleted file mode 100644 index 6fe98d9b..00000000 --- a/docs/src/chapter-04-gbui/how-to/connect-whatsapp.md +++ /dev/null @@ -1,749 +0,0 @@ -# How To: Connect WhatsApp - -> **Tutorial 5 of the Channels Series** -> -> *Connect your bot to WhatsApp in 20 minutes* - ---- - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ │ │ -│ │ 📱 CONNECT WHATSAPP TO YOUR BOT │ │ -│ │ │ │ -│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ -│ │ │ Step │───▶│ Step │───▶│ Step │───▶│ Step │ │ │ -│ │ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │ │ -│ │ │ Meta │ │ Create │ │Configure│ │ Test │ │ │ -│ │ │ Account │ │ App │ │ Bot │ │ Channel │ │ │ -│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ -│ │ │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Objective - -By the end of this tutorial, you will have: -- Created a Meta Business account -- Set up a WhatsApp Business App -- Connected WhatsApp to your General Bots instance -- Tested the connection with a real message - ---- - -## Time Required - -⏱️ **20 minutes** - ---- - -## Prerequisites - -Before you begin, make sure you have: - -- [ ] A working bot (see [Create Your First Bot](./create-first-bot.md)) -- [ ] A phone number for WhatsApp Business (cannot be used with regular WhatsApp) -- [ ] A Facebook account -- [ ] Administrator access to General Bots - ---- - -## Understanding WhatsApp Integration - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ HOW WHATSAPP INTEGRATION WORKS │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ User sends message on WhatsApp │ -│ │ │ -│ ▼ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ WhatsApp Cloud API │ │ -│ │ (Meta's servers receive message) │ │ -│ └────────────────────────┬────────────────────────────────────┘ │ -│ │ │ -│ │ Webhook │ -│ ▼ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ General Bots Server │ │ -│ │ (Your bot processes the message) │ │ -│ └────────────────────────┬────────────────────────────────────┘ │ -│ │ │ -│ │ API Call │ -│ ▼ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ WhatsApp Cloud API │ │ -│ │ (Sends reply to user) │ │ -│ └────────────────────────┬────────────────────────────────────┘ │ -│ │ │ -│ ▼ │ -│ User receives bot response on WhatsApp │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Step 1: Set Up Meta Business Account - -### 1.1 Go to Meta for Developers - -Open your browser and navigate to: - -**https://developers.facebook.com** - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 🌐 Browser [─][□][×]│ -├─────────────────────────────────────────────────────────────────────────┤ -│ ← → ↻ │ https://developers.facebook.com │ ☆ │ │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Meta for Developers │ -│ │ -│ ┌─────────────────────┐ │ -│ │ Log In │ │ -│ └─────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 1.2 Log In with Facebook - -1. Click **Log In** -2. Enter your Facebook credentials -3. Click **Log In** - -### 1.3 Create a Meta Business Account (If Needed) - -If you don't have a business account: - -1. Go to **https://business.facebook.com** -2. Click **Create Account** -3. Enter your business name -4. Enter your name and business email -5. Click **Submit** - -💡 **Note**: You can use your personal Facebook account, but a business account is recommended for production use. - -✅ **Checkpoint**: You should now be logged into Meta for Developers. - ---- - -## Step 2: Create a WhatsApp App - -### 2.1 Go to My Apps - -Click **My Apps** in the top navigation. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Meta for Developers [My Apps ▼] [👤 Account] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ My Apps │ -│ ─────── │ -│ │ -│ ┌─────────────────────────┐ │ -│ │ + Create App │ ◄── Click here │ -│ └─────────────────────────┘ │ -│ │ -│ You don't have any apps yet. │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.2 Create a New App - -1. Click **Create App** -2. Select **Business** as the app type -3. Click **Next** - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Create an App [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Select an app type: │ -│ │ -│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ -│ │ Consumer │ │ ● Business │ │ Gaming │ │ -│ │ │ │ ◄── Select │ │ │ │ -│ │ For consumer │ │ │ │ For game │ │ -│ │ apps │ │ For business │ │ integrations │ │ -│ │ │ │ integrations │ │ │ │ -│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ -│ │ -│ [Next] │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.3 Fill In App Details - -| Field | What to Enter | Example | -|-------|---------------|---------| -| **App Name** | Your bot's name | My Company Bot | -| **App Contact Email** | Your email | admin@company.com | -| **Business Account** | Select or create | My Company | - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Add App Details [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ App Name: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ My Company Bot │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ App Contact Email: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ admin@company.com │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Business Account: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ My Company [▼] │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ [Create App] │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -4. Click **Create App** -5. Complete the security check if prompted - -### 2.4 Add WhatsApp to Your App - -1. In the app dashboard, scroll to **Add Products** -2. Find **WhatsApp** and click **Set Up** - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Add Products to Your App │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ -│ │ Messenger │ │ 📱 WhatsApp │ │ Instagram │ │ -│ │ │ │ │ │ │ │ -│ │ [Set Up] │ │ [Set Up] ◄── │ │ [Set Up] │ │ -│ │ │ │ Click here │ │ │ │ -│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: WhatsApp should now appear in your app's left sidebar. - ---- - -## Step 3: Configure WhatsApp Settings - -### 3.1 Get Your API Credentials - -In the left sidebar, click **WhatsApp** → **API Setup**. - -You'll see: -- **Phone number ID** - Identifies your WhatsApp number -- **WhatsApp Business Account ID** - Your business account -- **Temporary access token** - For testing (expires in 24 hours) - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ WhatsApp > API Setup │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ STEP 1: Select Phone Numbers │ -│ ──────────────────────────── │ -│ │ -│ From: [Test Number - 15550001234 ▼] │ -│ │ -│ To: (Add a recipient phone number for testing) │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ +1 555 123 4567 │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ───────────────────────────────────────────────────────────────────── │ -│ │ -│ STEP 2: Send Messages with the API │ -│ ────────────────────────────────── │ -│ │ -│ Temporary Access Token: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ EAAGm0PX4ZCp... [Copy] │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ ⚠️ This token expires in 24 hours. Use System User for production. │ -│ │ -│ Phone Number ID: 123456789012345 [Copy] │ -│ WhatsApp Business Account ID: 987654321098765 [Copy] │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -📝 **Write down these values** - You'll need them in the next step: -- Phone Number ID: `_______________` -- Access Token: `_______________` - -### 3.2 Create a Permanent Access Token - -For production, you need a permanent token: - -1. Go to **Business Settings** → **System Users** -2. Click **Add** to create a system user -3. Name it (e.g., "WhatsApp Bot") -4. Set role to **Admin** -5. Click **Generate Token** -6. Select your app and the `whatsapp_business_messaging` permission -7. Click **Generate Token** - -💡 **Important**: Save this token securely! You won't be able to see it again. - -### 3.3 Configure the Webhook - -The webhook tells Meta where to send incoming messages. - -1. In the left sidebar, click **WhatsApp** → **Configuration** -2. Under **Webhook**, click **Edit** - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Webhook Configuration [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Callback URL: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ https://your-bot-server.com/webhook/whatsapp │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Verify Token: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ your-custom-verify-token-here │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ⚠️ Your server must respond to Meta's verification request │ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ Verify and Save │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -**Enter these values:** - -| Field | Value | -|-------|-------| -| Callback URL | `https://your-server.com/webhook/whatsapp` | -| Verify Token | A secret string you create (e.g., `my_bot_verify_123`) | - -3. Click **Verify and Save** - -### 3.4 Subscribe to Webhook Events - -After verifying, select which events to receive: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Webhook Fields │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ☑ messages ◄── Required! Receive incoming messages │ -│ ☐ message_template_status_update │ -│ ☐ phone_number_name_update │ -│ ☐ phone_number_quality_update │ -│ ☑ account_review_update │ -│ ☐ account_update │ -│ ☐ business_capability_update │ -│ ☐ flows │ -│ ☑ security │ -│ ☑ message_echoes │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -At minimum, select: -- **messages** (required - to receive user messages) - -✅ **Checkpoint**: Webhook should show as "Active" with a green indicator. - ---- - -## Step 4: Configure General Bots - -### 4.1 Open Bot Settings - -1. In General Bots, go to **Sources** -2. Click **⚙️** on your bot -3. Go to the **Channels** tab - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Bot Settings: support [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │ -│ │ General │ AI │*Channels*│ Security │ Advanced │ │ -│ └──────────┴──────────┴──────────┴──────────┴──────────┘ │ -│ │ -│ CONNECTED CHANNELS │ -│ ────────────────── │ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ 🌐 Web Chat Status: ● On │ │ -│ │ Embedded widget on your website │ │ -│ │ [Configure] │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ 📱 WhatsApp Status: ○ Off │ │ -│ │ Not configured │ │ -│ │ [Configure] ◄── Click here │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 4.2 Enter WhatsApp Credentials - -Click **Configure** for WhatsApp and enter your credentials: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ WhatsApp Configuration [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ META API CREDENTIALS │ -│ ──────────────────── │ -│ │ -│ Phone Number ID: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ 123456789012345 │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Access Token: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ •••••••••••••••••••••••••••••••••••••• │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Verify Token: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ my_bot_verify_123 │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ ⚠️ Must match the token you set in Meta Developer Portal │ -│ │ -│ ───────────────────────────────────────────────────────────────────── │ -│ │ -│ WEBHOOK URL (provide this to Meta) │ -│ ────────────────────────────────── │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ https://your-server.com/webhook/whatsapp [Copy] │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────┐ ┌─────────────────┐ │ -│ │ Test Connection │ │ Save │ │ -│ └─────────────────┘ └─────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 4.3 Test the Connection - -1. Click **Test Connection** -2. You should see "Connection successful!" - -If the test fails, check: -- Token is correct and not expired -- Phone Number ID is correct -- Your server is accessible from the internet - -### 4.4 Save and Enable - -1. Click **Save** -2. Toggle WhatsApp to **On** - -✅ **Checkpoint**: WhatsApp should now show Status: ● On - ---- - -## Step 5: Test Your WhatsApp Bot - -### 5.1 Add Test Phone Number - -In Meta Developer Portal: - -1. Go to **WhatsApp** → **API Setup** -2. Under "To", add your phone number -3. Click **Send** to receive a test message - -### 5.2 Send a Test Message - -1. Open WhatsApp on your phone -2. Message the bot's number (the test number from Meta) -3. Send: "Hello" - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ WhatsApp │ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ │ │ -│ │ My Company Bot │ │ -│ │ +1 555 000 1234 │ │ -│ │ │ │ -│ │ ───────────────────────────────────────────────────────────── │ │ -│ │ │ │ -│ │ ┌───────────────┐ │ │ -│ │ │ Hello │ │ │ -│ │ │ 10:30 │ │ │ -│ │ └───────────────┘ │ │ -│ │ │ │ -│ │ ┌─────────────────────────────────────────┐ │ │ -│ │ │ Hello! How can I help you today? │ │ │ -│ │ │ 10:30 │ │ │ -│ │ └─────────────────────────────────────────┘ │ │ -│ │ │ │ -│ │ ┌───────────────┐ │ │ -│ │ │ I need help │ │ │ -│ │ │ with my order │ │ │ -│ │ │ 10:31 │ │ │ -│ │ └───────────────┘ │ │ -│ │ │ │ -│ │ ┌─────────────────────────────────────────┐ │ │ -│ │ │ I'd be happy to help with your order! │ │ │ -│ │ │ What's your order number? │ │ │ -│ │ │ 10:31 │ │ │ -│ │ └─────────────────────────────────────────┘ │ │ -│ │ │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ Type a message... 📎 │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 5.3 Verify in General Bots - -Check that the conversation appears in Analytics: - -1. Go to **Analytics** → **Sessions** -2. You should see a new session with channel "WhatsApp" - ---- - -## 🎉 Congratulations! - -Your bot is now connected to WhatsApp! Users can message your WhatsApp Business number and receive responses from your bot. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ✓ SUCCESS! │ -│ │ -│ Your WhatsApp bot is live! │ -│ │ -│ ┌───────────┐ ┌───────────┐ ┌──────────┐ │ -│ │ │ │ │ │ │ │ -│ │ 📱 │ ────────▶ │ 🤖 │ ────────▶ │ 💬 │ │ -│ │ WhatsApp │ │ General │ │ Bot │ │ -│ │ User │ ◀──────── │ Bots │ ◀──────── │ Response │ │ -│ │ │ │ │ │ │ │ -│ └───────────┘ └───────────┘ └──────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Going to Production - -### Add a Real Phone Number - -The test number has limitations. For production: - -1. Go to **WhatsApp** → **Phone Numbers** in Meta Developer Portal -2. Click **Add Phone Number** -3. Enter your business phone number -4. Verify via SMS or voice call -5. Update the Phone Number ID in General Bots settings - -### Submit for App Review - -Before going live with real customers: - -1. Go to **App Review** in Meta Developer Portal -2. Request `whatsapp_business_messaging` permission -3. Complete the review process (takes 2-5 business days) - -### Set Up Message Templates - -For proactive messages (not replies), you need approved templates: - -1. Go to **WhatsApp** → **Message Templates** -2. Create templates for notifications, alerts, etc. -3. Wait for Meta approval (usually 24 hours) - ---- - -## Troubleshooting - -### Problem: "Webhook verification failed" - -**Possible causes:** -1. Verify token doesn't match -2. Server not responding -3. HTTPS not configured - -**Solution:** -1. Check the verify token matches exactly in both places -2. Verify your server is accessible: `curl https://your-server.com/webhook/whatsapp` -3. Ensure you have a valid SSL certificate - ---- - -### Problem: Messages not arriving - -**Possible causes:** -1. Webhook not subscribed to "messages" -2. App in development mode with unlisted numbers -3. Access token expired - -**Solution:** -1. Check webhook subscriptions include "messages" -2. Add test phone numbers in API Setup -3. Generate a new access token - ---- - -### Problem: Bot responds slowly - -**Possible causes:** -1. Network latency -2. Bot processing time -3. Meta rate limits - -**Solution:** -1. Ensure server is geographically close to users -2. Optimize bot dialog processing -3. Check rate limit status in Meta dashboard - ---- - -### Problem: "Error 190: Invalid OAuth access token" - -**Possible causes:** -1. Token expired (temporary tokens last 24 hours) -2. Token was revoked -3. Wrong token used - -**Solution:** -1. Generate a new System User token (permanent) -2. Update the token in General Bots settings -3. Verify you're using the WhatsApp access token, not a Facebook token - ---- - -### Problem: Phone number shows as unverified - -**Possible causes:** -1. Verification not completed -2. Two-factor authentication issue -3. Number already in use - -**Solution:** -1. Re-request verification code -2. Check business verification status -3. Contact Meta support if number was previously registered - ---- - -## What You Learned - -In this tutorial, you: - -- ✅ Created a Meta Developer account and app -- ✅ Configured WhatsApp Cloud API -- ✅ Set up webhook for incoming messages -- ✅ Connected WhatsApp to General Bots -- ✅ Tested the integration with real messages - ---- - -## Next Steps - -Now that WhatsApp is connected, try these: - -| Next Tutorial | What You'll Learn | -|---------------|-------------------| -| [Write Your First Dialog](./write-first-dialog.md) | Create custom conversation flows | -| [Add KB Documents](./add-kb-documents.md) | Make your bot smarter | -| [Monitor Sessions](./monitor-sessions.md) | Track WhatsApp conversations | - ---- - -## Quick Reference - -### WhatsApp Message Limits - -| Tier | Messages/Day | How to Qualify | -|------|--------------|----------------| -| Unverified | 250 | New accounts | -| Verified | 1,000 | Complete business verification | -| Tier 1 | 10,000 | Good quality rating | -| Tier 2 | 100,000 | Maintain quality | -| Tier 3 | Unlimited | High volume, good quality | - -### Quality Rating - -Meta monitors your WhatsApp quality based on: -- User blocks and reports -- Message template quality -- Response time - -Keep quality high by: -- Responding to all messages -- Not spamming users -- Using approved templates for outbound messages - -### Key URLs - -| Resource | URL | -|----------|-----| -| Meta for Developers | https://developers.facebook.com | -| Meta Business Suite | https://business.facebook.com | -| WhatsApp Cloud API Docs | https://developers.facebook.com/docs/whatsapp | -| API Status | https://metastatus.com | - -### Configuration via config.csv - -Configure WhatsApp in your bot's `config.csv`: - -```csv -name,value -whatsapp-phone-number-id,123456789012345 -whatsapp-access-token,EAAGm0PX4ZCp... -whatsapp-verify-token,my_bot_verify_123 -whatsapp-business-account-id,987654321098765 -``` - -**Note**: Do not use environment variables for WhatsApp configuration. All settings belong in `config.csv`. - ---- - -## See Also - -- [Chat App](../apps/chat.md) - Web chat interface -- [Sources App](../apps/sources.md) - Bot configuration -- [Compliance App](../apps/compliance.md) - Data privacy for WhatsApp -- [BASIC Keywords](../../chapter-06-gbdialog/keywords-reference.md) - WhatsApp-specific keywords \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/how-to/create-first-bot.md b/docs/src/chapter-04-gbui/how-to/create-first-bot.md deleted file mode 100644 index 5c4a15dd..00000000 --- a/docs/src/chapter-04-gbui/how-to/create-first-bot.md +++ /dev/null @@ -1,481 +0,0 @@ -# How To: Create Your First Bot - -> **Tutorial 1 of the Getting Started Series** -> -> *Follow these simple steps to create a working bot in 10 minutes* - ---- - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ │ │ -│ │ 🤖 CREATE YOUR FIRST BOT │ │ -│ │ │ │ -│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ -│ │ │ Step │───▶│ Step │───▶│ Step │───▶│ Step │ │ │ -│ │ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │ │ -│ │ │ Access │ │ Create │ │Configure│ │ Test │ │ │ -│ │ │ Suite │ │ Bot │ │ Bot │ │ Bot │ │ │ -│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ -│ │ │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Objective - -By the end of this tutorial, you will have: -- Created a new bot instance -- Configured basic settings -- Written a simple greeting -- Tested your bot by talking to it - ---- - -## Time Required - -⏱️ **10 minutes** - ---- - -## Prerequisites - -Before you begin, make sure you have: - -- [ ] Access to General Bots Suite (URL provided by your administrator) -- [ ] A web browser (Chrome, Firefox, Safari, or Edge) -- [ ] Administrator or Bot Creator permissions - ---- - -## Step 1: Access the Suite - -### 1.1 Open Your Browser - -Launch your preferred web browser by clicking its icon. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 🌐 Browser [─][□][×]│ -├─────────────────────────────────────────────────────────────────────────┤ -│ ← → ↻ │ https://your-company.bot:8080 │ ☆ │ │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Loading... │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 1.2 Navigate to Your General Bots URL - -Type your General Bots address in the address bar and press **Enter**. - -💡 **Tip**: Your URL will look something like: -- `http://localhost:8080` (development) -- `https://bots.yourcompany.com` (production) -- `https://app.pragmatismo.cloud` (cloud hosted) - -### 1.3 Log In (If Required) - -If you see a login screen: -1. Enter your **username** or **email** -2. Enter your **password** -3. Click **Sign In** - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌────────────────────────────┐ │ -│ │ 🤖 General Bots │ │ -│ │ │ │ -│ │ Username: │ │ -│ │ ┌────────────────────┐ │ │ -│ │ │ admin@company.com │ │ │ -│ │ └────────────────────┘ │ │ -│ │ │ │ -│ │ Password: │ │ -│ │ ┌────────────────────┐ │ │ -│ │ │ •••••••••••• │ │ │ -│ │ └────────────────────┘ │ │ -│ │ │ │ -│ │ ┌────────────────────┐ │ │ -│ │ │ Sign In ──► │ │ │ -│ │ └────────────────────┘ │ │ -│ │ │ │ -│ └────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: You should now see the General Bots Suite interface. - ---- - -## Step 2: Create a New Bot - -### 2.1 Open the Apps Menu - -Click the **nine-dot grid icon** (⋮⋮⋮) in the top-right corner of the screen. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 🤖 General Bots [⋮⋮⋮] ◄── Click here │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ │ -``` - -### 2.2 Select "Sources" - -From the apps menu that appears, click **Sources**. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌───────────────────┐ │ -│ │ 💬 Chat │ │ -│ │ 📁 Drive │ │ -│ │ ✓ Tasks │ │ -│ │ ✉ Mail │ │ -│ │ 📝 Paper │ │ -│ │ 📊 Analytics │ │ -│ │ ▶ 📋 Sources ◀───┼─── Click here │ -│ │ 🎨 Designer │ │ -│ │ ⚙️ Settings │ │ -│ └───────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.3 Click "New Bot" - -In the Sources application, locate and click the **New Bot** button. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Sources │ -├─────────────────────────────────────────────────────────────────────────┤ -│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ -│ │ Templates │ │ Prompts │ │ Bots │ ◄── Active Tab │ -│ └──────────────┘ └──────────────┘ └──────────────┘ │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Your Bots ┌─────────────────┐ │ -│ ───────── │ ➕ New Bot │ ◄── Click │ -│ └─────────────────┘ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ No bots yet. Create your first bot! │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.4 Enter Bot Details - -A dialog box will appear. Fill in the following fields: - -| Field | What to Enter | Example | -|-------|---------------|---------| -| **Bot Name** | A unique identifier (no spaces) | `mycompany` | -| **Display Name** | Friendly name shown to users | `My Company Assistant` | -| **Description** | What your bot does | `Helps employees find information` | -| **Template** | Starting point (select from dropdown) | `default` | - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Create New Bot [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ Bot Name * │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ mycompany │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ ⚠️ Use lowercase letters, numbers, and hyphens only │ -│ │ -│ Display Name * │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ My Company Assistant │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Description │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ Helps employees find information and complete tasks │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Template │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ default [▼] │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌──────────┐ ┌──────────────────┐ │ -│ │ Cancel │ │ Create Bot ──► │ │ -│ └──────────┘ └──────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.5 Click "Create Bot" - -Click the **Create Bot** button to create your bot. - -💡 **Tip**: The bot creation process takes a few seconds. You'll see a progress indicator. - -✅ **Checkpoint**: Your new bot should appear in the bot list. - ---- - -## Step 3: Configure Basic Settings - -### 3.1 Open Bot Settings - -Click on your new bot to select it, then click **Settings** (or the ⚙️ icon). - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Your Bots │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ 🤖 mycompany [⚙️] │◄──│ -│ │ My Company Assistant │ │ -│ │ Status: ● Active │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ - │ - Click the ⚙️ icon -``` - -### 3.2 Set the Welcome Message - -Find the **Welcome Message** field and enter a friendly greeting: - -``` -Welcome Message: - -┌─────────────────────────────────────────────────────────────────────────┐ -│ Hello! 👋 I'm your Company Assistant. I can help you with: │ -│ │ -│ • Finding documents and information │ -│ • Answering questions about policies │ -│ • Creating tasks and reminders │ -│ │ -│ How can I help you today? │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 3.3 Configure AI Model (Optional) - -If you have API keys for AI services, configure them: - -| Setting | Description | Example Value | -|---------|-------------|---------------| -| **LLM Provider** | AI service to use | `openai` | -| **Model** | Specific model | `gpt-4o` | -| **API Key** | Your API key | `sk-...` | - -⚠️ **Warning**: Keep your API keys secret. Never share them. - -### 3.4 Save Settings - -Click the **Save** button to save your configuration. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Bot Settings [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ [General] [AI Model] [Channels] [Advanced] │ -│ │ -│ ───────────────────────────────────────────────────────────────── │ -│ │ -│ ┌────────────────────┐ │ -│ │ 💾 Save │◄────│ -│ └────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ - Click Save -``` - -✅ **Checkpoint**: Your settings are saved. The bot is ready to test. - ---- - -## Step 4: Test Your Bot - -### 4.1 Open Chat - -Click the **Chat** app from the Apps Menu (⋮⋮⋮). - -### 4.2 Select Your Bot - -If you have multiple bots, select yours from the bot dropdown: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 💬 Chat [mycompany ▼] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 🤖 My Company Assistant │ │ -│ │ │ │ -│ │ Hello! 👋 I'm your Company Assistant. I can help │ │ -│ │ you with: │ │ -│ │ │ │ -│ │ • Finding documents and information │ │ -│ │ • Answering questions about policies │ │ -│ │ • Creating tasks and reminders │ │ -│ │ │ │ -│ │ How can I help you today? │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -├─────────────────────────────────────────────────────────────────────────┤ -│ Type your message... [↑] │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 4.3 Send a Test Message - -Type a simple message and press **Enter**: - -``` -You: Hello! -``` - -### 4.4 Verify the Response - -Your bot should respond! If it does, congratulations — your bot is working! - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 👤 You │ │ -│ │ Hello! │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 🤖 My Company Assistant │ │ -│ │ Hello! How can I assist you today? │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: Your bot responds to messages. Setup complete! - ---- - -## 🎉 Congratulations! - -You have successfully created your first bot! Here's what you accomplished: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ✓ Accessed General Bots Suite │ -│ ✓ Created a new bot instance │ -│ ✓ Configured basic settings │ -│ ✓ Tested the bot with a conversation │ -│ │ -│ Your bot "mycompany" is now ready to use! │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Troubleshooting - -### Problem: "Create Bot" button is disabled - -**Cause**: Required fields are empty or invalid. - -**Solution**: -1. Check that Bot Name contains only lowercase letters, numbers, and hyphens -2. Ensure Display Name is not empty -3. Verify a template is selected - -### Problem: Bot doesn't respond - -**Cause**: AI model not configured or API key invalid. - -**Solution**: -1. Open bot settings -2. Verify AI model configuration -3. Check that API key is correct -4. Ensure you have API credits remaining - -### Problem: "Permission denied" error - -**Cause**: Your account doesn't have bot creation rights. - -**Solution**: -1. Contact your administrator -2. Request "Bot Creator" or "Administrator" role - -### Problem: Page won't load - -**Cause**: Network or server issue. - -**Solution**: -1. Check your internet connection -2. Try refreshing the page (F5 or Ctrl+R) -3. Clear browser cache -4. Contact your system administrator - ---- - -## What You Learned - -In this tutorial, you learned: - -| Concept | Description | -|---------|-------------| -| **Bot Instance** | A unique bot with its own configuration | -| **Bot Name** | Technical identifier used internally | -| **Display Name** | Friendly name shown to users | -| **Template** | Pre-built starting point for your bot | -| **Welcome Message** | First message users see | - ---- - -## Next Steps - -Now that you have a working bot, continue learning: - -| Next Tutorial | What You'll Learn | -|---------------|-------------------| -| [Your First Conversation](./first-conversation.md) | Understanding how conversations work | -| [Add Knowledge Base Documents](./add-kb-documents.md) | Teaching your bot from files | -| [Write Your First Dialog](./write-first-dialog.md) | Creating custom conversation flows | - ---- - -## Quick Reference - -### Bot Naming Rules - -- ✅ `mycompany` — Good -- ✅ `hr-assistant` — Good -- ✅ `support2024` — Good -- ❌ `My Company` — No spaces -- ❌ `HR_Bot` — No underscores -- ❌ `Support@2024` — No special characters - -### Essential Settings Checklist - -- [ ] Bot Name (unique identifier) -- [ ] Display Name (user-friendly) -- [ ] Welcome Message (first impression) -- [ ] AI Model (for responses) -- [ ] Language (for localization) - ---- - -*Tutorial 1 of 30 • [Back to How-To Index](./README.md) • [Next: Your First Conversation →](./first-conversation.md)* \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/how-to/monitor-sessions.md b/docs/src/chapter-04-gbui/how-to/monitor-sessions.md deleted file mode 100644 index 939662e6..00000000 --- a/docs/src/chapter-04-gbui/how-to/monitor-sessions.md +++ /dev/null @@ -1,504 +0,0 @@ -# How To: Monitor Your Bot - -> **Tutorial 12 of the Analytics & Monitoring Series** -> -> *Watch conversations and system health in real-time* - ---- - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ │ │ -│ │ 📊 MONITOR YOUR BOT │ │ -│ │ │ │ -│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ -│ │ │ Step │───▶│ Step │───▶│ Step │───▶│ Step │ │ │ -│ │ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │ │ -│ │ │ Access │ │ View │ │ Check │ │ Set │ │ │ -│ │ │Dashboard│ │Sessions │ │ Health │ │ Alerts │ │ │ -│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ -│ │ │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Objective - -By the end of this tutorial, you will have: -- Accessed the monitoring dashboard -- Viewed active sessions and conversations -- Checked system health and resources -- Understood the live system architecture -- Configured alerts for important events - ---- - -## Time Required - -⏱️ **10 minutes** - ---- - -## Prerequisites - -Before you begin, make sure you have: - -- [ ] A running bot with some activity -- [ ] Administrator or Monitor role permissions -- [ ] Access to the General Bots Suite - ---- - -## Understanding the System Architecture - -Your General Bots deployment is a **living system** of interconnected components. Understanding how they work together helps you monitor effectively. - -![Live Monitoring Organism](../../assets/suite/live-monitoring-organism.svg) - -### Component Overview - -| Component | Purpose | Status Indicators | -|-----------|---------|-------------------| -| **BotServer** | Core application, handles all requests | Response time, active sessions | -| **PostgreSQL** | Primary database, stores users & config | Connections, query rate | -| **Qdrant** | Vector database, powers semantic search | Vector count, search latency | -| **MinIO** | File storage, manages documents | Storage used, object count | -| **BotModels** | LLM server, generates AI responses | Tokens/hour, model latency | -| **Vault** | Secrets manager, stores API keys | Sealed status, policy count | -| **Cache** | Cache layer, speeds up responses | Hit rate, memory usage | -| **InfluxDB** | Metrics database, stores analytics | Points/sec, retention | - ---- - -## Step 1: Access the Monitoring Dashboard - -### 1.1 Open the Apps Menu - -Click the **nine-dot grid** (⋮⋮⋮) in the top-right corner. - -### 1.2 Select Monitoring - -Click **Analytics** or **Monitoring** (depending on your configuration). - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌───────────────────┐ │ -│ │ 💬 Chat │ │ -│ │ 📁 Drive │ │ -│ │ 📊 Analytics │ ◄── May be here │ -│ │ 📈 Monitoring │ ◄── Or here │ -│ │ ⚙️ Settings │ │ -│ └───────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 1.3 View the Dashboard - -The monitoring dashboard displays real-time metrics: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 📊 Monitoring Dashboard 🔴 LIVE │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ -│ │ SESSIONS │ │ MESSAGES │ │ RESPONSE │ │ -│ │ │ │ │ │ │ │ -│ │ 247 │ │ 12.4K │ │ 1.2s │ │ -│ │ ● Active │ │ Today │ │ Average │ │ -│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ -│ │ -│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │ -│ │ -│ SYSTEM RESOURCES │ -│ ───────────────── │ -│ CPU [████████████████░░░░░░░░░░░░░░] 70% │ -│ MEM [████████████████████░░░░░░░░░░] 60% │ -│ GPU [████████████░░░░░░░░░░░░░░░░░░] 40% │ -│ DISK [████████░░░░░░░░░░░░░░░░░░░░░░] 28% │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: You can see the monitoring dashboard with live metrics. - ---- - -## Step 2: View Active Sessions - -### 2.1 Navigate to Sessions Panel - -Look for the **Sessions** or **Conversations** section: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Active Sessions (247) [Refresh 🔄] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ID │ User │ Channel │ Started │ Messages │ -│ ──────────┼───────────────┼───────────┼──────────────┼──────────── │ -│ a1b2c3d4 │ +5511999... │ WhatsApp │ 2 min ago │ 12 │ -│ e5f6g7h8 │ john@acme... │ Web │ 5 min ago │ 8 │ -│ i9j0k1l2 │ +5521888... │ WhatsApp │ 8 min ago │ 23 │ -│ m3n4o5p6 │ support@... │ Email │ 15 min ago │ 4 │ -│ q7r8s9t0 │ jane@... │ Web │ 18 min ago │ 15 │ -│ │ -│ ◀ 1 2 3 4 5 ... 25 ▶ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.2 View Session Details - -Click on a session to see the full conversation: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Session: a1b2c3d4 [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ User: +5511999888777 │ -│ Channel: WhatsApp │ -│ Started: 2024-01-15 14:32:00 │ -│ Duration: 2 min 34 sec │ -│ Bot: mycompany │ -│ │ -│ ── Conversation ──────────────────────────────────────────────────────│ -│ │ -│ [14:32:00] 👤 User: Hello │ -│ [14:32:01] 🤖 Bot: Hello! How can I help you today? │ -│ [14:32:15] 👤 User: I want to check my order status │ -│ [14:32:17] 🤖 Bot: I can help with that! What's your order number? │ -│ [14:32:45] 👤 User: ORD-12345 │ -│ [14:32:48] 🤖 Bot: Order ORD-12345 is being prepared for shipping... │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.3 Session Metrics - -Understand key session metrics: - -| Metric | Description | Good Value | -|--------|-------------|------------| -| **Active Sessions** | Currently open conversations | Depends on load | -| **Peak Today** | Maximum concurrent sessions | Track trends | -| **Avg Duration** | Average conversation length | 3-5 minutes typical | -| **Messages/Session** | Average messages per conversation | 5-10 typical | - -✅ **Checkpoint**: You can view active sessions and their conversations. - ---- - -## Step 3: Check System Health - -### 3.1 View Service Status - -The dashboard shows the health of all components: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Service Health │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ● PostgreSQL Running v16.2 24/100 connections │ -│ ● Qdrant Running v1.9.2 1.2M vectors │ -│ ● MinIO Running v2024.01 45.2 GB stored │ -│ ● BotModels Running v2.1.0 gpt-4o active │ -│ ● Vault Sealed v1.15.0 156 secrets │ -│ ● Cache Running v7.2.4 94.2% hit rate │ -│ ● InfluxDB Running v2.7.3 2,450 pts/sec │ -│ │ -│ Legend: ● Running ● Warning ● Stopped │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 3.2 Understanding Status Colors - -| Color | Status | Action Needed | -|-------|--------|---------------| -| 🟢 Green | Healthy/Running | None | -| 🟡 Yellow | Warning/Degraded | Investigate soon | -| 🔴 Red | Error/Stopped | Immediate action | - -### 3.3 Check Resource Usage - -Monitor resource utilization to prevent issues: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Resource Usage Last 24 Hours │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ CPU Usage │ -│ 100%│ ╭──╮ │ -│ 75%│ ╭──╮ ╭──╮ │ │ ╭──╮ │ -│ 50%│╭──╮│ │╭─╯ ╰─╮╭──╯ ╰──╯ ╰──╮ │ -│ 25%│ ╰──╯ ╰╯ ╰────────── │ -│ 0%└──────────────────────────────────────────── │ -│ 00:00 04:00 08:00 12:00 16:00 20:00 Now │ -│ │ -│ Memory Usage │ -│ 100%│ │ -│ 75%│ │ -│ 50%│──────────────────────────────────────────── │ -│ 25%│ │ -│ 0%└──────────────────────────────────────────── │ -│ 00:00 04:00 08:00 12:00 16:00 20:00 Now │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 3.4 Resource Thresholds - -Take action when resources approach these limits: - -| Resource | Warning | Critical | Action | -|----------|---------|----------|--------| -| CPU | > 80% | > 95% | Scale up or optimize | -| Memory | > 85% | > 95% | Add RAM or reduce cache | -| Disk | > 80% | > 90% | Clean up or add storage | -| GPU | > 90% | > 98% | Queue requests or scale | - -✅ **Checkpoint**: You can view system health and resource usage. - ---- - -## Step 4: Set Up Alerts - -### 4.1 Access Alert Settings - -Navigate to **Settings** > **Alerts** or **Monitoring** > **Configure Alerts**. - -### 4.2 Configure Alert Rules - -Set up alerts for important events: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ Alert Configuration │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ☑ CPU Usage │ -│ Threshold: [80] % For: [5] minutes │ -│ Notify: ☑ Email ☑ Slack ☐ SMS │ -│ │ -│ ☑ Memory Usage │ -│ Threshold: [85] % For: [5] minutes │ -│ Notify: ☑ Email ☐ Slack ☐ SMS │ -│ │ -│ ☑ Response Time │ -│ Threshold: [5000] ms For: [3] minutes │ -│ Notify: ☑ Email ☑ Slack ☐ SMS │ -│ │ -│ ☑ Service Down │ -│ Services: ☑ PostgreSQL ☑ Qdrant ☑ BotModels │ -│ Notify: ☑ Email ☑ Slack ☑ SMS │ -│ │ -│ ┌─────────────────┐ │ -│ │ 💾 Save │ │ -│ └─────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 4.3 Configure via config.csv - -You can also set alerts in your bot's configuration file: - -```csv -key,value -alert-cpu-threshold,80 -alert-memory-threshold,85 -alert-disk-threshold,90 -alert-response-time-ms,5000 -alert-email,admin@company.com -alert-slack-webhook,https://hooks.slack.com/... -``` - -### 4.4 Test Alerts - -Verify your alerts are working: - -1. Set a low threshold temporarily (e.g., CPU > 1%) -2. Wait for the alert to trigger -3. Check your email/Slack for the notification -4. Reset the threshold to normal - -✅ **Checkpoint**: Alerts are configured and tested. - ---- - -## 🎉 Congratulations! - -You can now monitor your bot effectively! Here's what you learned: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ✓ Accessed the monitoring dashboard │ -│ ✓ Viewed active sessions and conversations │ -│ ✓ Checked system health and services │ -│ ✓ Understood resource usage metrics │ -│ ✓ Configured alerts for important events │ -│ │ -│ You're now equipped to keep your bot healthy! │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Troubleshooting - -### Problem: Dashboard shows no data - -**Cause**: Monitoring services may not be collecting data. - -**Solution**: -1. Check that InfluxDB is running -2. Verify the monitoring agent is enabled -3. Wait a few minutes for data collection - -### Problem: Sessions show as "Unknown User" - -**Cause**: User identification not configured. - -**Solution**: -1. Enable user tracking in bot settings -2. Request user info at conversation start -3. Check privacy settings - -### Problem: Alerts not being sent - -**Cause**: Notification channels not configured correctly. - -**Solution**: -1. Verify email/Slack settings -2. Check spam folders -3. Test webhook URLs manually - -### Problem: High CPU but few sessions - -**Cause**: Possible memory leak or inefficient code. - -**Solution**: -1. Check for infinite loops in dialogs -2. Review LLM call frequency -3. Restart the bot service - ---- - -## Monitoring API - -Access monitoring data programmatically: - -### Get System Status - -``` -GET /api/monitoring/status -``` - -**Response:** -```json -{ - "sessions": { - "active": 247, - "peak_today": 312, - "avg_duration_seconds": 245 - }, - "messages": { - "today": 12400, - "this_hour": 890, - "avg_response_ms": 1200 - }, - "resources": { - "cpu_percent": 70, - "memory_percent": 60, - "gpu_percent": 40, - "disk_percent": 28 - }, - "services": { - "postgresql": "running", - "qdrant": "running", - "minio": "running", - "botmodels": "running", - "vault": "sealed", - "redis": "running", - "influxdb": "running" - } -} -``` - -### Get Historical Metrics - -``` -GET /api/monitoring/history?period=24h -``` - -### Get Session Details - -``` -GET /api/monitoring/sessions/{session_id} -``` - ---- - -## Quick Reference - -### Dashboard Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `R` | Refresh data | -| `F` | Toggle fullscreen | -| `S` | Show/hide sidebar | -| `1-7` | Switch dashboard tabs | - -### Important Metrics to Watch - -| Metric | Normal | Warning | Critical | -|--------|--------|---------|----------| -| Response Time | < 2s | 2-5s | > 5s | -| Error Rate | < 1% | 1-5% | > 5% | -| CPU Usage | < 70% | 70-85% | > 85% | -| Memory Usage | < 75% | 75-85% | > 85% | -| Queue Depth | < 100 | 100-500 | > 500 | - -### Console Monitoring - -For server-side monitoring: - -```bash -# Start with monitoring output -./botserver --console --monitor - -# Output: -# [MONITOR] 2024-01-15 14:32:00 -# Sessions: 247 active (peak: 312) -# Messages: 12,400 today (890/hour) -# CPU: 70% | MEM: 60% | GPU: 40% -# Services: 7/7 running -``` - ---- - -## Next Steps - -| Next Tutorial | What You'll Learn | -|---------------|-------------------| -| [Create Custom Reports](./create-reports.md) | Build dashboards for insights | -| [Export Analytics Data](./export-analytics.md) | Download metrics for analysis | -| [Performance Optimization](./performance-tips.md) | Make your bot faster | - ---- - -*Tutorial 12 of 30 • [Back to How-To Index](./README.md) • [Next: Create Custom Reports →](./create-reports.md)* \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/how-to/write-first-dialog.md b/docs/src/chapter-04-gbui/how-to/write-first-dialog.md deleted file mode 100644 index 2082924f..00000000 --- a/docs/src/chapter-04-gbui/how-to/write-first-dialog.md +++ /dev/null @@ -1,695 +0,0 @@ -# How To: Write Your First Dialog - -> **Tutorial 5 of the BASIC Dialogs Series** -> -> *Create a simple conversation script in 20 minutes* - ---- - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ │ │ -│ │ 📝 WRITE YOUR FIRST DIALOG │ │ -│ │ │ │ -│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ -│ │ │ Step │───▶│ Step │───▶│ Step │───▶│ Step │ │ │ -│ │ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │ │ -│ │ │ Create │ │ Write │ │ Test │ │ Enhance │ │ │ -│ │ │ File │ │ Code │ │ Dialog │ │ Logic │ │ │ -│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ -│ │ │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Objective - -By the end of this tutorial, you will have: -- Created a `.bas` dialog file -- Written code using TALK and HEAR keywords -- Used conditional logic (IF/THEN/ELSE) -- Stored and retrieved user information -- Tested your dialog in the chat interface - ---- - -## Time Required - -⏱️ **20 minutes** - ---- - -## Prerequisites - -Before you begin, make sure you have: - -- [ ] A working bot (see [Create Your First Bot](./create-first-bot.md)) -- [ ] Access to the Designer or Drive app -- [ ] Basic understanding of the chat interface - ---- - -## What is a Dialog? - -A **dialog** is a conversation script written in BASIC that controls how your bot talks with users. Think of it like a script for a play — you write what the bot should say and how it should respond to the user. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ HOW DIALOGS WORK │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ User says: "Hello" │ -│ │ │ -│ ▼ │ -│ ┌─────────────────┐ │ -│ │ Dialog Script │ ◄── Your BASIC code runs here │ -│ │ (greeting.bas) │ │ -│ └────────┬────────┘ │ -│ │ │ -│ ▼ │ -│ Bot says: "Hi there! What's your name?" │ -│ │ │ -│ ▼ │ -│ User says: "Sarah" │ -│ │ │ -│ ▼ │ -│ Bot says: "Nice to meet you, Sarah!" │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Step 1: Create the Dialog File - -### 1.1 Open the Drive App - -Click the **Apps Menu** (⋮⋮⋮) and select **Drive**. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 📁 Drive │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ 📂 mycompany.gbai │ -│ ├── 📂 mycompany.gbdialog ◄── Dialog files go here │ -│ ├── 📂 mycompany.gbot │ -│ ├── 📂 mycompany.gbkb │ -│ └── 📂 mycompany.gbdrive │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 1.2 Navigate to the Dialog Folder - -Double-click **mycompany.gbai**, then **mycompany.gbdialog**. - -### 1.3 Create a New File - -Click **New File** (or press Ctrl+N) and name it: - -``` -greeting.bas -``` - -⚠️ **Warning**: The file must end with `.bas` to be recognized as a dialog. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ New File [×] │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ File Name: │ -│ ┌─────────────────────────────────────────────────────────────────┐ │ -│ │ greeting.bas │ │ -│ └─────────────────────────────────────────────────────────────────┘ │ -│ │ -│ Location: mycompany.gbai / mycompany.gbdialog / │ -│ │ -│ ┌──────────┐ ┌──────────────────┐ │ -│ │ Cancel │ │ Create ──► │ │ -│ └──────────┘ └──────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: You should see `greeting.bas` in your dialog folder. - ---- - -## Step 2: Write the Dialog Code - -### 2.1 Open the File for Editing - -Double-click `greeting.bas` to open it in the editor. - -### 2.2 Write Your First Line - -Type the following code: - -```basic -TALK "Hello! Welcome to our service. 👋" -``` - -This is the simplest possible dialog — the bot just says one thing. - -### 2.3 Add User Input - -Now let's ask for the user's name: - -```basic -TALK "Hello! Welcome to our service. 👋" -TALK "What is your name?" -HEAR name -TALK "Nice to meet you, " + name + "!" -``` - -Let's break this down: - -| Line | What It Does | -|------|--------------| -| `TALK "..."` | Bot displays a message | -| `HEAR name` | Bot waits for user input, stores it in `name` | -| `"..." + name + "..."` | Combines text with the variable | - -### 2.4 The Complete First Dialog - -Here's your complete `greeting.bas`: - -```basic -' ============================================ -' GREETING DIALOG -' A friendly welcome conversation -' ============================================ - -' Greet the user -TALK "Hello! Welcome to our service. 👋" - -' Ask for their name -TALK "What is your name?" -HEAR name - -' Respond with their name -TALK "Nice to meet you, " + name + "!" -TALK "How can I help you today?" -``` - -💡 **Tip**: Lines starting with `'` are comments — they're ignored by the bot but help you understand the code. - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 📝 greeting.bas [Save] ⌘S │ -├─────────────────────────────────────────────────────────────────────────┤ -│ 1 │ ' ============================================ │ -│ 2 │ ' GREETING DIALOG │ -│ 3 │ ' A friendly welcome conversation │ -│ 4 │ ' ============================================ │ -│ 5 │ │ -│ 6 │ ' Greet the user │ -│ 7 │ TALK "Hello! Welcome to our service. 👋" │ -│ 8 │ │ -│ 9 │ ' Ask for their name │ -│ 10 │ TALK "What is your name?" │ -│ 11 │ HEAR name │ -│ 12 │ │ -│ 13 │ ' Respond with their name │ -│ 14 │ TALK "Nice to meet you, " + name + "!" │ -│ 15 │ TALK "How can I help you today?" │ -│ │ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -### 2.5 Save the File - -Press **Ctrl+S** or click the **Save** button. - -✅ **Checkpoint**: Your dialog file is saved and ready to test. - ---- - -## Step 3: Test Your Dialog - -### 3.1 Open Chat - -Click the **Apps Menu** (⋮⋮⋮) and select **Chat**. - -### 3.2 Trigger the Dialog - -Type the command to run your dialog: - -``` -/greeting -``` - -Or simply type something that matches "greeting" — the system will recognize it. - -### 3.3 Have the Conversation - -Watch your dialog run: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ 💬 Chat │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 👤 You │ │ -│ │ /greeting │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 🤖 Bot │ │ -│ │ Hello! Welcome to our service. 👋 │ │ -│ │ What is your name? │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 👤 You │ │ -│ │ Sarah │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ 🤖 Bot │ │ -│ │ Nice to meet you, Sarah! │ │ -│ │ How can I help you today? │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -├─────────────────────────────────────────────────────────────────────────┤ -│ Type your message... [↑] │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - -✅ **Checkpoint**: Your dialog runs and responds correctly! - ---- - -## Step 4: Enhance with Logic - -Now let's make our dialog smarter with conditional logic. - -### 4.1 Add Input Validation - -Update your dialog to handle different types of input: - -```basic -' ============================================ -' GREETING DIALOG (Enhanced) -' A friendly welcome with input validation -' ============================================ - -TALK "Hello! Welcome to our service. 👋" -TALK "What is your name?" -HEAR name - -' Check if name was provided -IF name = "" THEN - TALK "I didn't catch your name. That's okay!" - name = "friend" -END IF - -TALK "Nice to meet you, " + name + "!" -``` - -### 4.2 Add Menu Options - -Let's give the user choices: - -```basic -' ============================================ -' GREETING DIALOG (Full Version) -' Welcome with menu options -' ============================================ - -TALK "Hello! Welcome to our service. 👋" -TALK "What is your name?" -HEAR name - -IF name = "" THEN - name = "friend" -END IF - -TALK "Nice to meet you, " + name + "!" -TALK "" -TALK "How can I help you today?" -TALK "1. Learn about our services" -TALK "2. Contact support" -TALK "3. Check my account" -TALK "" -TALK "Please type 1, 2, or 3:" - -HEAR choice - -SELECT CASE choice - CASE "1" - TALK "Great! We offer AI-powered automation for businesses." - TALK "Would you like to schedule a demo?" - CASE "2" - TALK "I'll connect you with our support team." - TALK "Please describe your issue:" - HEAR issue - TALK "Thank you. A support agent will contact you about: " + issue - CASE "3" - TALK "To check your account, I'll need to verify your identity." - TALK "Please enter your email address:" - HEAR email - TALK "Looking up account for: " + email - CASE ELSE - TALK "I didn't understand that choice." - TALK "Please type 1, 2, or 3 next time." -END SELECT - -TALK "" -TALK "Is there anything else I can help with, " + name + "?" -``` - -### 4.3 Understanding SELECT CASE - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ SELECT CASE EXPLAINED │ -├─────────────────────────────────────────────────────────────────────────┤ -│ │ -│ User types: "2" │ -│ │ │ -│ ▼ │ -│ ┌─────────────────────────────────────────────────────────────┐ │ -│ │ SELECT CASE choice │ │ -│ │ ┌─────────────┐ │ │ -│ │ │ CASE "1" │──▶ Skip (not matched) │ │ -│ │ └─────────────┘ │ │ -│ │ ┌─────────────┐ │ │ -│ │ │ CASE "2" ★ │──▶ EXECUTE! ───▶ "I'll connect you..." │ │ -│ │ └─────────────┘ │ │ -│ │ ┌─────────────┐ │ │ -│ │ │ CASE "3" │──▶ Skip (not checked after match) │ │ -│ │ └─────────────┘ │ │ -│ │ ┌─────────────┐ │ │ -│ │ │ CASE ELSE │──▶ Skip (only runs if nothing matched) │ │ -│ │ └─────────────┘ │ │ -│ │ END SELECT │ │ -│ └─────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Step 5: Remember User Information - -### 5.1 Store User Data - -Use `SET USER MEMORY` to remember information between conversations: - -```basic -' After getting the name -SET USER MEMORY "name", name - -' Later, in another dialog, retrieve it: -savedName = GET USER MEMORY "name" - -IF savedName <> "" THEN - TALK "Welcome back, " + savedName + "!" -ELSE - TALK "Hello! I don't think we've met before." -END IF -``` - -### 5.2 Store Bot-Wide Data - -Use `SET BOT MEMORY` for data that applies to all users: - -```basic -' Store a bot-wide counter -visitorCount = GET BOT MEMORY "visitor_count" -IF visitorCount = "" THEN - visitorCount = 0 -END IF -visitorCount = visitorCount + 1 -SET BOT MEMORY "visitor_count", visitorCount - -TALK "You are visitor number " + visitorCount + " today!" -``` - ---- - -## Complete Example: Support Request Dialog - -Here's a complete, practical dialog you can use as a template: - -```basic -' ============================================ -' SUPPORT REQUEST DIALOG -' Collects support ticket information -' ============================================ - -' Check if we know this user -userName = GET USER MEMORY "name" - -IF userName = "" THEN - TALK "Hello! I'm here to help you create a support request." - TALK "First, what's your name?" - HEAR userName - SET USER MEMORY "name", userName -ELSE - TALK "Welcome back, " + userName + "!" -END IF - -' Get contact information -TALK "What email should we use to contact you?" -HEAR AS email -email - -IF email = "" THEN - TALK "I'll need an email to send you updates." - HEAR AS email - email -END IF - -' Get issue category -TALK "" -TALK "What type of issue are you experiencing?" -TALK "" -TALK "1. 🔧 Technical problem" -TALK "2. 💳 Billing question" -TALK "3. 📦 Order status" -TALK "4. ❓ General question" -TALK "" - -HEAR category - -SELECT CASE category - CASE "1" - categoryName = "Technical" - TALK "I'm sorry you're having technical difficulties." - CASE "2" - categoryName = "Billing" - TALK "I can help with billing questions." - CASE "3" - categoryName = "Orders" - TALK "Let me check on your order." - CASE ELSE - categoryName = "General" - TALK "I'll make sure the right team sees this." -END SELECT - -' Get description -TALK "" -TALK "Please describe your issue in detail:" -HEAR description - -' Get urgency -TALK "" -TALK "How urgent is this?" -TALK "1. 🔴 Critical - I can't work" -TALK "2. 🟡 High - Affecting my work" -TALK "3. 🟢 Normal - When you get a chance" -HEAR urgency - -SELECT CASE urgency - CASE "1" - urgencyLevel = "Critical" - CASE "2" - urgencyLevel = "High" - CASE ELSE - urgencyLevel = "Normal" -END SELECT - -' Confirm ticket -TALK "" -TALK "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -TALK "📋 SUPPORT REQUEST SUMMARY" -TALK "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -TALK "Name: " + userName -TALK "Email: " + email -TALK "Category: " + categoryName -TALK "Urgency: " + urgencyLevel -TALK "Issue: " + description -TALK "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -TALK "" -TALK "Should I submit this request? (yes/no)" - -HEAR confirm - -IF confirm = "yes" OR confirm = "Yes" OR confirm = "YES" THEN - ' Here you would typically save to a database - ' For now, just confirm - TALK "✅ Your support request has been submitted!" - TALK "Ticket ID: SR-" + FORMAT(NOW, "yyyyMMddHHmm") - TALK "You'll receive a confirmation email at " + email - TALK "Our team typically responds within 24 hours." -ELSE - TALK "No problem! Your request was not submitted." - TALK "Feel free to start over when you're ready." -END IF - -TALK "" -TALK "Is there anything else I can help with?" -``` - ---- - -## 🎉 Congratulations! - -You've written your first dialog! Here's what you learned: - -``` -┌─────────────────────────────────────────────────────────────────────────┐ -│ │ -│ ✓ Created a .bas dialog file │ -│ ✓ Used TALK to display messages │ -│ ✓ Used HEAR to get user input │ -│ ✓ Combined text with variables │ -│ ✓ Used IF/THEN/ELSE for decisions │ -│ ✓ Used SELECT CASE for menus │ -│ ✓ Stored data with SET USER MEMORY │ -│ │ -└─────────────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Troubleshooting - -### Problem: Dialog doesn't start - -**Cause**: File name or location is incorrect. - -**Solution**: -1. Verify file ends with `.bas` -2. Confirm file is in the `.gbdialog` folder -3. Check there are no syntax errors - -### Problem: "Unexpected token" error - -**Cause**: Syntax error in your code. - -**Solution**: -1. Check all strings have opening and closing quotes -2. Verify IF statements have matching END IF -3. Ensure SELECT CASE has END SELECT - -### Problem: Variable is empty - -**Cause**: User skipped the HEAR prompt. - -**Solution**: -1. Add validation: `IF variable = "" THEN` -2. Provide a default value -3. Ask again if needed - -### Problem: Bot doesn't remember data - -**Cause**: Not using memory keywords correctly. - -**Solution**: -1. Use `SET USER MEMORY "key", value` to save -2. Use `GET USER MEMORY "key"` to retrieve -3. Ensure key names match exactly (case-sensitive) - ---- - -## Quick Reference - -### Essential Keywords - -| Keyword | Purpose | Example | -|---------|---------|---------| -| `TALK` | Display message | `TALK "Hello!"` | -| `HEAR` | Get user input | `HEAR name` | -| `HEAR AS type` | Get typed input | `HEAR AS email emailVar` | -| `SET` | Set variable | `SET x = 5` | -| `IF/THEN/ELSE` | Conditional | `IF x > 5 THEN ... END IF` | -| `SELECT CASE` | Menu choice | `SELECT CASE x ... END SELECT` | -| `SET USER MEMORY` | Save user data | `SET USER MEMORY "key", value` | -| `GET USER MEMORY` | Load user data | `x = GET USER MEMORY "key"` | -| `SET BOT MEMORY` | Save bot data | `SET BOT MEMORY "key", value` | -| `GET BOT MEMORY` | Load bot data | `x = GET BOT MEMORY "key"` | - -### Common Patterns - -**Greeting with memory:** -```basic -name = GET USER MEMORY "name" -IF name = "" THEN - TALK "What's your name?" - HEAR name - SET USER MEMORY "name", name -ELSE - TALK "Welcome back, " + name + "!" -END IF -``` - -**Menu with validation:** -```basic -TALK "Choose: 1, 2, or 3" -HEAR choice -IF choice < "1" OR choice > "3" THEN - TALK "Invalid choice, using default." - choice = "1" -END IF -``` - -**Loop for retries:** -```basic -attempts = 0 -valid = FALSE -WHILE valid = FALSE AND attempts < 3 - TALK "Enter your email:" - HEAR AS email input - IF input <> "" THEN - valid = TRUE - END IF - attempts = attempts + 1 -WEND -``` - ---- - -## Next Steps - -| Next Tutorial | What You'll Learn | -|---------------|-------------------| -| [Store User Information](./store-user-info.md) | Advanced memory patterns | -| [Call External APIs](./call-external-apis.md) | Connect to web services | -| [Send Automated Messages](./send-automated.md) | Scheduled broadcasts | - ---- - -## Best Practices - -1. **Comment your code** — Use `'` for explanations -2. **Validate all input** — Never assume users type correctly -3. **Provide defaults** — Handle empty responses gracefully -4. **Use clear prompts** — Tell users exactly what to type -5. **Confirm important actions** — Ask before submitting forms -6. **Use spaces in keywords** — `SET BOT MEMORY` not `SET_BOT_MEMORY` -7. **Test thoroughly** — Try all menu options and edge cases - ---- - -*Tutorial 5 of 30 • [Back to How-To Index](./README.md) • [Next: Store User Information →](./store-user-info.md)* \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/htmx-architecture.md b/docs/src/chapter-04-gbui/htmx-architecture.md deleted file mode 100644 index 00ffc3d8..00000000 --- a/docs/src/chapter-04-gbui/htmx-architecture.md +++ /dev/null @@ -1,535 +0,0 @@ -# HTMX Architecture - -## Overview - -General Bots Suite uses **HTMX** for its user interface - a modern approach that delivers the interactivity of a single-page application without the complexity of JavaScript frameworks like React, Vue, or Angular. - -> **Why HTMX?** -> - Simpler code, easier maintenance -> - Server-rendered HTML (fast, SEO-friendly) -> - Progressive enhancement -> - No build step required -> - Smaller payload than SPA frameworks - ---- - -## How HTMX Works - -### Traditional Web vs HTMX - -**Traditional (Full Page Reload):** -``` -User clicks → Browser requests full page → Server returns entire HTML → Browser replaces everything -``` - -**HTMX (Partial Update):** -``` -User clicks → HTMX requests fragment → Server returns HTML snippet → HTMX updates only that part -``` - -### Core Concept - -HTMX extends HTML with attributes that define: -1. **What triggers the request** (`hx-trigger`) -2. **Where to send it** (`hx-get`, `hx-post`) -3. **What to update** (`hx-target`) -4. **How to update it** (`hx-swap`) - ---- - -## HTMX Attributes Reference - -### Request Attributes - -| Attribute | Purpose | Example | -|-----------|---------|---------| -| `hx-get` | GET request to URL | `hx-get="/api/tasks"` | -| `hx-post` | POST request | `hx-post="/api/tasks"` | -| `hx-put` | PUT request | `hx-put="/api/tasks/1"` | -| `hx-patch` | PATCH request | `hx-patch="/api/tasks/1"` | -| `hx-delete` | DELETE request | `hx-delete="/api/tasks/1"` | - -### Trigger Attributes - -| Attribute | Purpose | Example | -|-----------|---------|---------| -| `hx-trigger` | Event that triggers request | `hx-trigger="click"` | -| | Load on page | `hx-trigger="load"` | -| | Periodic polling | `hx-trigger="every 5s"` | -| | Keyboard event | `hx-trigger="keyup changed delay:300ms"` | - -### Target & Swap Attributes - -| Attribute | Purpose | Example | -|-----------|---------|---------| -| `hx-target` | Element to update | `hx-target="#results"` | -| `hx-swap` | How to insert content | `hx-swap="innerHTML"` | -| | | `hx-swap="outerHTML"` | -| | | `hx-swap="beforeend"` | -| | | `hx-swap="afterbegin"` | - ---- - -## Suite Architecture - -### File Structure - -``` -ui/suite/ -├── index.html # Main entry point with navigation -├── default.gbui # Full desktop layout -├── single.gbui # Simple chat layout -├── designer.html # Visual dialog designer -├── editor.html # Code editor -├── settings.html # User settings -├── css/ -│ └── app.css # Global styles -├── js/ -│ ├── layout.js # Layout management -│ └── theme-manager.js # Theme switching -├── chat/ -│ ├── chat.html # Chat component -│ └── chat.css # Chat styles -├── drive/ -│ └── index.html # File manager -├── tasks/ -│ ├── tasks.html # Task manager -│ └── tasks.css # Task styles -├── mail/ -│ ├── mail.html # Email client -│ └── mail.css # Email styles -├── calendar/ -│ └── calendar.html # Calendar view -├── meet/ -│ ├── meet.html # Video meetings -│ └── meet.css # Meeting styles -├── paper/ -│ └── paper.html # Document editor -├── research/ -│ └── research.html # AI search -├── analytics/ -│ └── analytics.html # Dashboards -├── sources/ -│ └── index.html # Prompts & templates -├── tools/ -│ └── compliance.html # Security scanner -└── monitoring/ - └── ... # System monitoring -``` - -### Loading Pattern - -The Suite uses **lazy loading** - components load only when needed: - -```html - - - Chat - -``` - -When user clicks "Chat": -1. HTMX requests `/ui/suite/chat/chat.html` -2. Server returns the Chat HTML fragment -3. HTMX inserts it into `#main-content` -4. Only Chat code loads, not entire app - ---- - -## Component Patterns - -### 1. Load on Page View - -```html - -
-
Loading tasks...
-
-``` - -### 2. Form Submission - -```html - -
- - -
-``` - -**Flow:** -1. User types task, clicks Add -2. HTMX POSTs form data to `/api/tasks` -3. Server creates task, returns HTML for new task item -4. HTMX inserts at beginning of `#task-list` -5. Form resets automatically - -### 3. Click Actions - -```html - -
- - Review quarterly report - -
-``` - -### 4. Search with Debounce - -```html - - - -🔄 -
-``` - -**Flow:** -1. User types in search box -2. After 300ms of no typing, HTMX sends request -3. Spinner shows during request -4. Results replace `#search-results` content - -### 5. Real-time Updates (WebSocket) - -```html - -
-
-
- -
- - -
-
-``` - -**Flow:** -1. WebSocket connects on load -2. History loads via HTMX GET -3. New messages sent via WebSocket (`ws-send`) -4. Server pushes updates to all connected clients - -### 6. Polling for Updates - -```html - -
- -
-``` - -### 7. Infinite Scroll - -```html - -
- - -
- Loading more... -
-
-``` - ---- - -## API Response Patterns - -### Server Returns HTML Fragments - -The server doesn't return JSON - it returns ready-to-display HTML: - -**Request:** -``` -GET /api/tasks -``` - -**Response:** -```html -
- - Review quarterly report -
-
- - Update documentation -
-``` - -### Swap Strategies - -| Strategy | Effect | -|----------|--------| -| `innerHTML` | Replace contents of target | -| `outerHTML` | Replace entire target element | -| `beforeend` | Append inside target (at end) | -| `afterbegin` | Prepend inside target (at start) | -| `beforebegin` | Insert before target | -| `afterend` | Insert after target | -| `delete` | Delete target element | -| `none` | Don't swap (for side effects) | - ---- - -## CSS Integration - -### Loading Indicators - -```css -/* Hidden by default */ -.htmx-indicator { - display: none; -} - -/* Shown during request */ -.htmx-request .htmx-indicator { - display: inline-block; -} - -/* Or when indicator IS the requesting element */ -.htmx-request.htmx-indicator { - display: inline-block; -} -``` - -### Transition Effects - -```css -/* Fade in new content */ -.htmx-settling { - opacity: 0; -} - -.htmx-swapping { - opacity: 0; - transition: opacity 0.2s ease-out; -} -``` - ---- - -## JavaScript Integration - -### HTMX Events - -```javascript -// After any HTMX swap -document.body.addEventListener('htmx:afterSwap', (e) => { - console.log('Content updated:', e.detail.target); -}); - -// Before request -document.body.addEventListener('htmx:beforeRequest', (e) => { - console.log('Sending request to:', e.detail.pathInfo.path); -}); - -// After request completes -document.body.addEventListener('htmx:afterRequest', (e) => { - if (e.detail.successful) { - console.log('Request succeeded'); - } else { - console.error('Request failed'); - } -}); - -// On WebSocket message -document.body.addEventListener('htmx:wsAfterMessage', (e) => { - console.log('Received:', e.detail.message); -}); -``` - -### Triggering HTMX from JavaScript - -```javascript -// Trigger an HTMX request programmatically -htmx.trigger('#task-list', 'load'); - -// Make an AJAX request -htmx.ajax('GET', '/api/tasks', { - target: '#task-list', - swap: 'innerHTML' -}); - -// Process new HTMX content -htmx.process(document.getElementById('new-content')); -``` - ---- - -## Designer Page Architecture - -The visual dialog designer uses a hybrid approach: - -### Canvas Management (JavaScript) -```javascript -// State managed in JavaScript -const state = { - nodes: new Map(), // Node data - connections: [], // Connections between nodes - zoom: 1, // Canvas zoom level - pan: { x: 0, y: 0 } // Canvas position -}; -``` - -### File Operations (HTMX) -```html - - - - - -``` - -### Drag-and-Drop (JavaScript) -```javascript -// Toolbox items are draggable -toolboxItems.forEach(item => { - item.addEventListener('dragstart', (e) => { - e.dataTransfer.setData('nodeType', item.dataset.nodeType); - }); -}); - -// Canvas handles drop -canvas.addEventListener('drop', (e) => { - const nodeType = e.dataTransfer.getData('nodeType'); - createNode(nodeType, e.clientX, e.clientY); -}); -``` - ---- - -## Performance Considerations - -### 1. Minimize Request Size - -Return only what's needed: -```html - -... - - -...
-``` - -### 2. Use Appropriate Triggers - -```html - -hx-trigger="every 30s" -hx-trigger="every 1s" - - -hx-trigger="keyup changed delay:300ms" -hx-trigger="keyup" -``` - -### 3. Lazy Load Heavy Content - -```html - -
-
-``` - -### 4. Use `hx-boost` for Navigation - -```html - - -``` - ---- - -## Security - -### CSRF Protection - -HTMX automatically includes CSRF tokens: - -```html - -``` - -```javascript -// Configure HTMX to send CSRF token -document.body.addEventListener('htmx:configRequest', (e) => { - e.detail.headers['X-CSRF-Token'] = document.querySelector('meta[name="csrf-token"]').content; -}); -``` - -### Content Security - -- Server validates all inputs -- HTML is sanitized before rendering -- Authentication checked on every request - ---- - -## Comparison: HTMX vs React - -| Aspect | HTMX | React | -|--------|------|-------| -| **Learning Curve** | Low (HTML attributes) | High (JSX, hooks, state) | -| **Bundle Size** | ~14KB | ~40KB + app code | -| **Build Step** | None | Required | -| **Server Load** | More (renders HTML) | Less (returns JSON) | -| **Client Load** | Less | More | -| **SEO** | Excellent | Requires SSR | -| **Complexity** | Simple | Complex | -| **Best For** | Content sites, dashboards | Complex SPAs, offline apps | - ---- - -## Further Reading - -- [HTMX Official Documentation](https://htmx.org/docs/) -- [HTMX Examples](https://htmx.org/examples/) -- [Hypermedia Systems (Book)](https://hypermedia.systems/) -- [Chapter 04: UI Reference](./README.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/monitoring.md b/docs/src/chapter-04-gbui/monitoring.md deleted file mode 100644 index 8d39c0ba..00000000 --- a/docs/src/chapter-04-gbui/monitoring.md +++ /dev/null @@ -1,259 +0,0 @@ -# Monitoring Dashboard - -The Monitoring Dashboard provides real-time visibility into your General Bots deployment through an animated, interactive SVG visualization showing system health, active sessions, and resource utilization. - -## Live System Visualization - -Live Monitoring Dashboard - -The dashboard displays BotServer at the center orchestrating all interactions, with animated data packets flowing between components: - -- **Left Side (Data Layer)**: PostgreSQL, Qdrant vector database, and MinIO storage -- **Right Side (Services)**: BotModels AI, Cache, and Vault security -- **Center**: BotServer core with pulsing rings indicating activity -- **Top**: Real-time metrics panels for sessions, messages, and response time -- **Bottom**: Resource utilization bars and activity ticker - -## Accessing the Dashboard - -Access monitoring from the Suite interface: -1. Click the apps menu (⋮⋮⋮) -2. Select **Monitoring** -3. Or navigate directly to `/monitoring` - -## Dashboard Features - -### Animated System Architecture - -The SVG visualization shows real-time data flow: - -| Component | Color | Description | -|-----------|-------|-------------| -| **BotServer** | Blue/Purple | Central orchestrator with rotating ring | -| **PostgreSQL** | Blue | Primary database with cylinder icon | -| **Qdrant** | Purple | Vector database with triangle nodes | -| **MinIO** | Amber | Object storage with disk icon | -| **BotModels** | Pink | AI/ML service with neural network icon | -| **Cache** | Cyan | In-memory cache with lightning icon | -| **Vault** | Green | Secrets management with lock icon | - -### Status Indicators - -Each service has a status dot: - -| Status | Color | Animation | -|--------|-------|-----------| -| **Running** | 🟢 Green | Gentle pulse | -| **Warning** | 🟡 Amber | Fast pulse | -| **Stopped** | 🔴 Red | No animation | - -### Real-Time Metrics - -Three metric panels at the top update automatically: - -| Panel | Update Interval | Description | -|-------|-----------------|-------------| -| **Active Sessions** | 5 seconds | Current open conversations with trend | -| **Messages Today** | 10 seconds | Total messages with hourly rate | -| **Avg Response** | 10 seconds | Average response time in milliseconds | - -### Resource Utilization - -Resource bars show system health: - -| Resource | Gradient | Warning Threshold | -|----------|----------|-------------------| -| **CPU** | Blue/Purple | > 80% | -| **Memory** | Green | > 85% | -| **GPU** | Purple | > 90% | -| **Disk** | Amber | > 90% | - -### Activity Ticker - -A live ticker at the bottom shows the latest system events with a pulsing green indicator. - -## View Modes - -Toggle between two views using the grid button or press `V`: - -### Live View (Default) -The animated SVG visualization showing the complete system topology with flowing data packets. - -### Grid View -Traditional panel-based layout with detailed tree views for each metric category: -- Sessions panel with active, peak, and duration -- Messages panel with counts and rates -- Resources panel with progress bars -- Services panel with health status -- Bots panel with active bot list - -## Keyboard Shortcuts - -| Shortcut | Action | -|----------|--------| -| `V` | Toggle between Live and Grid view | -| `R` | Refresh all metrics | - -## HTMX Integration - -The dashboard uses HTMX for real-time updates without full page reloads: - -| Endpoint | Interval | Data | -|----------|----------|------| -| `/api/monitoring/metric/sessions` | 5s | Session count | -| `/api/monitoring/metric/messages` | 10s | Message count | -| `/api/monitoring/metric/response_time` | 10s | Avg response | -| `/api/monitoring/resources/bars` | 15s | Resource SVG bars | -| `/api/monitoring/services/status` | 30s | Service health JSON | -| `/api/monitoring/activity/latest` | 5s | Activity text | -| `/api/monitoring/timestamp` | 5s | Last updated time | - -## API Access - -Access monitoring data programmatically: - -### Get Full Status - -```/dev/null/monitoring-api.txt -GET /api/monitoring/status -``` - -**Response:** - -```/dev/null/monitoring-response.json -{ - "sessions": { - "active": 12, - "peak_today": 47, - "avg_duration_seconds": 512 - }, - "messages": { - "today": 1234, - "this_hour": 89, - "avg_response_ms": 1200 - }, - "resources": { - "cpu_percent": 65, - "memory_percent": 72, - "gpu_percent": 45, - "disk_percent": 28 - }, - "services": { - "postgresql": "running", - "qdrant": "running", - "cache": "running", - "drive": "running", - "botmodels": "running", - "vault": "running" - } -} -``` - -### Service-Specific Endpoints - -| Endpoint | Returns | -|----------|---------| -| `/api/monitoring/services` | All service details | -| `/api/monitoring/bots` | Active bot list | -| `/api/monitoring/history?period=24h` | Historical metrics | -| `/api/monitoring/prometheus` | Prometheus format export | - -## Component Health Details - -| Component | Health Check | Warning Signs | -|-----------|--------------|---------------| -| **PostgreSQL** | Connection count, query rate | > 80 connections, slow queries | -| **Qdrant** | Vector count, search latency | > 50ms search time | -| **MinIO** | Storage usage, object count | > 80% storage used | -| **BotModels** | Token usage, response latency | > 2s response time | -| **Vault** | Seal status, policy count | Unsealed without auth | -| **Cache** | Hit rate, memory usage | < 80% hit rate | - -## Alerts Configuration - -Configure alert thresholds in `config.csv`: - -```/dev/null/config-alerts.csv -name,value -alert-cpu-threshold,80 -alert-memory-threshold,85 -alert-disk-threshold,90 -alert-response-time-ms,5000 -alert-email,admin@example.com -``` - -## Console Mode - -For terminal-based monitoring: - -```/dev/null/console-command.bash -./botserver --console --monitor -``` - -Output: -```/dev/null/console-output.txt -[MONITOR] 2025-01-15 14:32:00 -Sessions: 12 active (peak: 47) -Messages: 1,234 today (89/hour) -CPU: 65% | MEM: 72% | GPU: 45% -Services: 6/6 running -``` - -## Tips & Best Practices - -💡 **Watch the data packets** - Flowing animations indicate active communication between components - -💡 **Monitor trends** - The session trend indicator (↑/↓) shows direction of change - -💡 **Click services** - Click any service node in Live view to see detailed status - -💡 **Set up alerts** - Configure thresholds before issues become critical - -💡 **Use keyboard shortcuts** - Press `R` for quick refresh, `V` to toggle views - -💡 **Check historical data** - Query `/api/monitoring/history` for trend analysis - -## Troubleshooting - -### Dashboard not loading - -**Possible causes:** -1. WebSocket connection failed -2. API endpoint unreachable -3. Browser blocking HTMX - -**Solution:** -1. Check browser console for errors -2. Verify `/api/monitoring/status` returns data -3. Refresh the page - -### Metrics showing "--" - -**Possible causes:** -1. Initial load in progress -2. API timeout -3. Service unavailable - -**Solution:** -1. Wait 5-10 seconds for first update -2. Check network tab for failed requests -3. Verify services are running - -### Animations stuttering - -**Possible causes:** -1. High CPU usage -2. Many browser tabs open -3. Hardware acceleration disabled - -**Solution:** -1. Close unused tabs -2. Enable hardware acceleration in browser -3. Use Grid view for lower resource usage - -## See Also - -- [Monitoring API Reference](../chapter-10-api/monitoring-api.md) -- [Console Mode](./console-mode.md) -- [Configuration Options](../chapter-08-config/README.md) -- [Analytics App](./apps/analytics.md) \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/single-gbui.md b/docs/src/chapter-04-gbui/single-gbui.md deleted file mode 100644 index e487967a..00000000 --- a/docs/src/chapter-04-gbui/single-gbui.md +++ /dev/null @@ -1,173 +0,0 @@ -# single.gbui - Simplified Chat Interface - -The `single.gbui` template provides a streamlined, single-page chat interface focused on conversation without distractions. - -## Overview - -Location: `ui/suite/single.gbui` - -This minimalist chat interface delivers a clean, focused chat experience with WebSocket real-time messaging, dark mode support, mobile-responsive design, and fast loading under 50KB. - -## Features - -### Core Components - -The interface consists of four main components. The header displays the bot name, status, and connection indicator with minimal branding. The messages area provides an auto-scrolling message list with clear user and bot message distinction, timestamps, and smooth animations. The input area offers a single-line text input with a send button, Enter key support, and auto-focus on load. The typing indicator shows a three-dot animation when the bot is processing a response. - -## Design Philosophy - -The single.gbui template embraces minimalism by eliminating unnecessary UI elements. Speed is prioritized so the interface loads instantly and works on slow connections. Accessibility features include keyboard navigation and screen reader support. Visual clarity comes from a clear hierarchy that guides users naturally through the conversation. - -## Responsive Behavior - -### Desktop - -On desktop displays, the interface uses a centered container with 800px maximum width for comfortable reading, ample whitespace, and optimal line lengths for extended conversations. - -### Mobile - -On mobile devices, the layout expands to full width with larger touch targets meeting the 44px minimum requirement. The input remains bottom-aligned and adjusts appropriately when the virtual keyboard appears. - -## Styling - -The interface uses minimal inline CSS for maximum performance: - -```css -/* Core styles only */ -body { - font-family: system-ui, -apple-system, sans-serif; - margin: 0; - height: 100vh; - display: flex; - flex-direction: column; -} - -.chat-container { - flex: 1; - display: flex; - flex-direction: column; - max-width: 800px; - margin: 0 auto; - width: 100%; -} -``` - -## Dark Mode - -Automatic dark mode activates based on system preference: - -```css -@media (prefers-color-scheme: dark) { - :root { - --background: #111827; - --text: #f9fafb; - --message-bot: #374151; - } -} -``` - -## WebSocket Integration - -Connection handling is simplified for reliability: - -```javascript -const ws = new WebSocket('ws://localhost:8080/ws'); - -ws.onmessage = (event) => { - const data = JSON.parse(event.data); - addMessage(data.content, 'bot'); -}; - -function sendMessage() { - const message = input.value.trim(); - if (message) { - ws.send(JSON.stringify({ - type: 'message', - content: message - })); - addMessage(message, 'user'); - input.value = ''; - } -} -``` - -## Use Cases - -### Embedded Widget - -The single.gbui template is perfect for embedding in existing websites: - -```html - -``` - -### Kiosk Mode - -The interface works well for public terminals with no navigation elements, focus on conversation, and easy reset between users. - -### Mobile-First - -Optimization for mobile devices includes fast loading, minimal data usage, and touch-friendly controls. - -## Customization - -### Change Colors - -Edit the CSS variables to match your brand: - -```css -:root { - --primary: #3b82f6; /* Your brand color */ - --background: #ffffff; /* Background */ - --text: #1f2937; /* Text color */ -} -``` - -### Modify Welcome Message - -Update the initial bot message in the HTML: - -```html -
-
- Your custom welcome message here -
-
-``` - -### Add Logo - -Insert a logo in the header: - -```html -
- Logo - Bot Name -
-``` - -## Performance - -The single.gbui template achieves first paint in under 100ms and becomes interactive within 200ms. Total size stays under 50KB with no external dependencies since everything is inline. - -## Accessibility - -The template uses semantic HTML structure throughout, ARIA labels on interactive elements, full keyboard navigation support, proper focus management, and high contrast mode support for users who need it. - -## Browser Support - -The interface works on all modern browsers including Chrome 90+, Firefox 88+, Safari 14+, Edge 90+, and their mobile counterparts. It degrades gracefully on older browsers, maintaining core functionality. - -## See Also - -- [default.gbui](./default-gbui.md) - Full-featured interface -- [Console Mode](./console-mode.md) - Terminal interface -- [Chapter 5: Themes](../chapter-05-gbtheme/README.md) - Custom styling -- [Chapter 6: BASIC](../chapter-06-gbdialog/README.md) - Dialog scripting - -## Next Step - -For terminal users, see [Console Mode](./console-mode.md). \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/suite-manual.md b/docs/src/chapter-04-gbui/suite-manual.md deleted file mode 100644 index 0b59cb43..00000000 --- a/docs/src/chapter-04-gbui/suite-manual.md +++ /dev/null @@ -1,902 +0,0 @@ -# General Bots Suite - User Manual - -> **The Complete Productivity Workspace** -> -> *AI-native productivity suite for modern teams* - ---- - -## Welcome to General Bots Suite - -General Bots Suite is your all-in-one workspace that combines communication, productivity, and AI assistance. All your productivity tools in one place - simple and powerful. - -**What makes it special:** -- Everything works together seamlessly -- AI helps you with every task -- No complex setup required -- Works in your browser - ---- - -## Part I: Getting Started - -### Opening the Suite - -1. **Open your web browser** (Chrome, Firefox, Safari, or Edge) -2. **Go to your General Bots address** (example: `http://your-company.bot:8080`) -3. **The Suite loads automatically** - you'll see the workspace in seconds - -### Your First Look - -When the Suite opens, you see: - -Suite Main Layout - -### The Apps Menu - -Click the **nine-dot grid** (⋮⋮⋮) in the top right to see all applications: - -| Icon | App | What It Does | -|------|-----|--------------| -| 💬 | **Chat** | Talk with your AI assistant | -| 📁 | **Drive** | Store and manage your files | -| ✓ | **Tasks** | Manage your to-do lists | -| ✉ | **Mail** | Send and receive emails | -| 📅 | **Calendar** | Schedule meetings and events | -| 🎥 | **Meet** | Video calls and meetings | -| 📝 | **Paper** | Write documents with AI help | -| 🔍 | **Research** | AI-powered search | -| 📊 | **Analytics** | View reports and statistics | - ---- - -## Part II: Chat - Your AI Assistant - -### What Chat Does - -Chat is your personal AI assistant. Ask questions, get help with tasks, or have a conversation - just like talking to a helpful colleague. - -### How to Use Chat - -**Sending a Message:** -1. Click in the message box at the bottom -2. Type your question or request -3. Press **Enter** or click the **↑** button - -**Example Conversations:** - -``` -You: What meetings do I have today? -Bot: You have 2 meetings scheduled: - • 10:00 AM - Team Standup - • 2:00 PM - Project Review - -You: Remind me to call John tomorrow at 3pm -Bot: Done! I've created a reminder for tomorrow at 3:00 PM - to call John. - -You: Write a professional email to decline a meeting -Bot: Here's a draft: - - Subject: Unable to Attend Meeting - - Dear [Name], - - Thank you for the invitation. Unfortunately, I have - a scheduling conflict and won't be able to attend. - - Would it be possible to reschedule or receive a - summary of the discussion? - - Best regards -``` - -### Voice Input - -1. Click the **🎤 microphone** button -2. Speak your message -3. Click again to stop -4. Your words appear as text automatically - -### Quick Suggestions - -Below the message box, you'll see **suggestion chips** - common actions you can click: - -``` -[📊 Show my tasks] [📧 Check email] [📅 Today's schedule] [❓ Help] -``` - -### Keyboard Shortcuts for Chat - -| Shortcut | Action | -|----------|--------| -| `Enter` | Send message | -| `Shift+Enter` | New line (without sending) | -| `↑` Arrow | Edit last message | -| `/` | Show command menu | - ---- - -## Part III: Drive - File Management - -### What Drive Does - -Drive is your file storage - like Google Drive or OneDrive. Store documents, images, spreadsheets, and any file you need. - -### The Drive Interface - -Drive Interface - -### Creating and Uploading - -**Upload Files:** -1. Click **+ New** button -2. Select **Upload Files** -3. Choose files from your computer -4. *Or:* Drag files directly into Drive - -**Create New Folder:** -1. Click **+ New** -2. Select **New Folder** -3. Type the folder name -4. Press Enter - -### Working with Files - -**Open a file:** Double-click it - -**Select files:** Click the checkbox beside the file name - -**Multiple selection:** Hold `Ctrl` (or `Cmd` on Mac) and click files - -**Right-click menu options:** -- 📂 Open -- ⬇️ Download -- ✏️ Rename -- 📋 Copy -- 📁 Move to... -- ⭐ Add to Starred -- 🔗 Share -- 🗑 Delete - -### View Options - -| Button | View | Best For | -|--------|------|----------| -| ⊞ | Grid view | Images and visual files | -| ≡ | List view | Documents and details | - -### Keyboard Shortcuts for Drive - -| Shortcut | Action | -|----------|--------| -| `Ctrl+U` | Upload files | -| `Ctrl+N` | New folder | -| `Delete` | Move to trash | -| `Ctrl+C` | Copy | -| `Ctrl+V` | Paste | -| `Enter` | Open selected | - ---- - -## Part IV: Tasks - To-Do Management - -### What Tasks Does - -Tasks helps you track what needs to be done. Create to-do lists, set due dates, and mark items complete. - -### The Tasks Interface - -Tasks Interface - -### Adding a Task - -1. Type your task in the input box -2. *(Optional)* Select a category: Work, Personal, Shopping, Health -3. *(Optional)* Set a due date -4. Click **+ Add** or press Enter - -**Pro tip:** Be specific! Instead of "Work on project", write "Draft introduction section for project proposal" - -### Task Priorities - -| Color | Priority | When to Use | -|-------|----------|-------------| -| 🔴 Red | High | Must do today | -| 🟡 Yellow | Medium | Important but not urgent | -| 🟢 Green | Low | Can wait | - -### Completing Tasks - -- **Click the checkbox** to mark a task done -- Completed tasks move to the "Completed" tab -- Feel the satisfaction! ✓ - -### Filter Tabs - -| Tab | Shows | -|-----|-------| -| **All** | Everything | -| **Active** | Tasks not yet done | -| **Completed** | Finished tasks | -| **Priority** | High-priority tasks only | - -### Creating Tasks from Chat - -In Chat, just say: -``` -You: Create a task to review the budget by Friday -Bot: Task created: "Review the budget" - Due: Friday -``` - ---- - -## Part V: Mail - Email Management - -### What Mail Does - -Mail connects to your email accounts so you can read, write, and organize emails without leaving the Suite. - -### The Mail Interface - -Mail Interface - -### Reading Email - -1. Click on **Mail** in the Apps menu -2. Click any email in the list to read it -3. The full email appears on the right - -### Composing Email - -1. Click **✏ Compose** -2. Fill in the fields: - - **To:** recipient's email - - **Subject:** what it's about - - **Body:** your message -3. Click **Send** - -**AI-Assisted Writing:** -``` -You: Help me write an email to reschedule tomorrow's meeting -Bot: Here's a draft: - - To: [recipient] - Subject: Request to Reschedule Meeting - - Hi [Name], - - I hope this message finds you well. Would it be - possible to reschedule our meeting tomorrow? - I have an unexpected conflict. - - Please let me know what times work for you - later this week. - - Thank you for understanding. -``` - -### Email Folders - -| Folder | Purpose | -|--------|---------| -| **Inbox** | New and unread messages | -| **Sent** | Emails you've sent | -| **Drafts** | Unfinished emails | -| **Trash** | Deleted emails (emptied after 30 days) | - -### Email Actions - -| Button | Action | -|--------|--------| -| **Reply** | Respond to sender | -| **Reply All** | Respond to everyone | -| **Forward** | Send to someone else | -| **Delete** | Move to Trash | -| **Archive** | Remove from Inbox but keep | - ---- - -## Part VI: Calendar - Scheduling - -### What Calendar Does - -Calendar shows your schedule, meetings, and events. Plan your day, week, or month at a glance. - -### The Calendar Interface - -Calendar Interface - -### Creating an Event - -**Method 1: Click and Create** -1. Click on a day/time slot -2. Enter event details -3. Click Save - -**Method 2: Ask the AI** -``` -You: Schedule a team meeting for next Tuesday at 2pm -Bot: Event created: - 📅 Team Meeting - 🕐 Tuesday, March 19 at 2:00 PM - ⏱ Duration: 1 hour -``` - -### Event Details - -When creating an event, you can set: -- **Title** - What the event is -- **Date & Time** - When it happens -- **Duration** - How long it lasts -- **Location** - Where (room or video link) -- **Attendees** - Who to invite -- **Reminder** - When to notify you -- **Repeat** - Daily, weekly, monthly - -### Calendar Views - -| View | Shows | Best For | -|------|-------|----------| -| **Day** | Hour by hour | Detailed daily planning | -| **Week** | 7 days | Seeing your week ahead | -| **Month** | Full month | Long-term planning | - -### Keyboard Navigation - -| Key | Action | -|-----|--------| -| `←` `→` | Previous/Next period | -| `T` | Jump to Today | -| `D` | Day view | -| `W` | Week view | -| `M` | Month view | - ---- - -## Part VII: Meet - Video Calls - -### What Meet Does - -Meet lets you have video calls with one person or many. Share your screen, record meetings, and get AI transcriptions. - -### Starting a Meeting - -**Start Instant Meeting:** -1. Click **Meet** in Apps menu -2. Click **Start Meeting** -3. Share the link with others - -**Schedule for Later:** -``` -You: Schedule a video call with the team for tomorrow at 10am -Bot: Meeting scheduled: - 🎥 Team Video Call - 📅 Tomorrow at 10:00 AM - 🔗 Link: meet.bot/abc-defg-hij - - Shall I send invites to the team? -``` - -### The Meeting Interface - -Meet Interface - -### Meeting Controls - -| Button | Function | -|--------|----------| -| 🎤 **Mute** | Turn microphone on/off | -| 📹 **Video** | Turn camera on/off | -| 🖥 **Share** | Share your screen | -| 🔴 **Record** | Record the meeting | -| 📝 **Transcribe** | Get live captions | -| 💬 **Chat** | Open meeting chat | -| 👥 **Participants** | See who's in the call | -| 📞 **End** | Leave the meeting | - -### Screen Sharing - -1. Click **🖥 Share** -2. Choose what to share: - - **Entire Screen** - Everything you see - - **Window** - One application - - **Tab** - One browser tab -3. Click **Share** -4. Click **Stop Sharing** when done - -### AI Features in Meetings - -**Live Transcription:** -- Enable with the **📝 Transcribe** button -- Words appear as people speak -- Great for accessibility and note-taking - -**Meeting Summary:** -After the meeting, ask: -``` -You: Summarize today's project meeting -Bot: Meeting Summary: - - Duration: 45 minutes - Participants: You, John, Sarah - - Key Points: - • Project deadline moved to April 15 - • John will handle client communication - • Sarah completing design by Friday - - Action Items: - • [You] Review budget proposal - • [John] Send client update - • [Sarah] Share design mockups -``` - ---- - -## Part VIII: Paper - AI Writing - -### What Paper Does - -Paper is your writing space with AI assistance. Write documents, notes, reports - and let AI help you write better. - -### The Paper Interface - -Paper Interface - -### Creating a Document - -1. Click **+ New** in the sidebar -2. Choose a template: - - **Blank** - Start fresh - - **Meeting Notes** - Pre-formatted for meetings - - **To-Do List** - Checkbox format - - **Research** - Sections for sources - -### Formatting Toolbar - -| Button | Function | Shortcut | -|--------|----------|----------| -| **B** | Bold | `Ctrl+B` | -| **I** | Italic | `Ctrl+I` | -| **U** | Underline | `Ctrl+U` | -| **H1** | Heading 1 | `Ctrl+1` | -| **H2** | Heading 2 | `Ctrl+2` | -| **•** | Bullet list | `Ctrl+Shift+8` | -| **―** | Numbered list | `Ctrl+Shift+7` | -| **🔗** | Insert link | `Ctrl+K` | -| **📷** | Insert image | - | - -### AI Writing Assistant ✨ - -Click the **AI ✨** button or type `/ai` for AI help: - -**Commands:** -``` -/ai improve → Make the text better -/ai shorter → Make it more concise -/ai longer → Expand with more detail -/ai formal → Make it professional -/ai friendly → Make it casual -/ai translate → Translate to another language -/ai summarize → Create a summary -``` - -**Example:** -``` -You wrote: "The thing we need to do is make the stuff better" - -/ai formal - -AI suggests: "Our objective is to enhance the quality of - our deliverables to meet higher standards." -``` - -### Auto-Save - -Paper saves automatically as you type. Look for: -- **"Saving..."** - Currently saving -- **"Saved"** - All changes saved -- **"Offline"** - Will save when connected - ---- - -## Part IX: Research - AI Search - -### What Research Does - -Research is like having a research assistant. Search the web, your documents, and knowledge bases - then get AI-synthesized answers. - -### The Research Interface - -Research Interface - -### Search Modes - -| Mode | Icon | Searches | -|------|------|----------| -| **All** | 🌐 | Everything | -| **Academic** | 📚 | Research papers, journals | -| **Code** | 💻 | Documentation, code examples | -| **Internal** | 🏠 | Your company's knowledge base | - -### Using Research - -1. Type your question in the search box -2. Select a focus mode (optional) -3. Press Enter -4. Read the AI-synthesized answer -5. Click sources to see original content - -### Collections - -Save important searches and sources: - -1. Click **+ New Collection** -2. Name it (e.g., "Q1 Project Research") -3. Add sources by clicking **Save to Collection** -4. Access anytime from the sidebar - -### Pro Tips - -**Be specific:** -- ❌ "marketing" -- ✅ "B2B SaaS marketing strategies for startups under 50 employees" - -**Use follow-up questions:** -``` -Search: What is machine learning? -Follow-up: How is it different from deep learning? -Follow-up: What are practical business applications? -``` - ---- - -## Part X: Analytics - Reports & Insights - -### What Analytics Does - -Analytics shows you reports about usage, conversations, and performance. Understand how the bot is being used and what's working. - -### The Analytics Interface - -Analytics Interface - -### Key Metrics - -| Metric | What It Means | -|--------|---------------| -| **Messages** | Total conversations | -| **Success Rate** | % of questions answered well | -| **Avg Response Time** | How fast the bot replies | -| **Users** | Number of people using the bot | -| **Popular Topics** | What people ask about most | - -### Time Ranges - -Select different periods to analyze: -- Last Hour -- Last 6 Hours -- Last 24 Hours -- Last 7 Days -- Last 30 Days -- Custom Range - -### Exporting Data - -Click **Export** to download reports as: -- **CSV** - For spreadsheets -- **PDF** - For sharing -- **JSON** - For developers - ---- - -## Part XI: Designer - Visual Dialog Builder - -### What Designer Does - -Designer lets you create bot conversations visually - like VB6 form designer, but for conversations. Drag and drop blocks to build dialogs without coding. - -### The Designer Interface - -Designer Interface - -### Building a Dialog - -**Step 1: Drag Blocks** -- Drag from Toolbox to Canvas -- Blocks snap to grid - -**Step 2: Connect Blocks** -- Drag from output port (●) to input port -- Lines show conversation flow - -**Step 3: Configure Properties** -- Click a block -- Edit settings in Properties panel - -**Step 4: Export** -- Click **Export to .bas** -- Save your dialog file - -### Block Types - -| Block | Icon | Purpose | Example | -|-------|------|---------|---------| -| **TALK** | 💬 | Bot speaks | "Welcome! How can I help?" | -| **HEAR** | 👂 | Wait for user input | Store response in `name` | -| **SET** | 📝 | Set a variable | `total = price * quantity` | -| **IF** | 🔀 | Make decisions | If age > 18 then... | -| **FOR** | 🔄 | Repeat for items | For each item in cart... | -| **SWITCH** | 🔃 | Multiple choices | Switch on category... | -| **CALL** | 📞 | Call another dialog | Call "checkout" | -| **SEND MAIL** | 📧 | Send email | Send confirmation | -| **SAVE** | 💾 | Save data | Save to database | -| **WAIT** | ⏱ | Pause | Wait 5 seconds | - -### Example: Simple Greeting Dialog - -The Designer canvas shows flow diagrams like the one in the interface above. A simple greeting dialog flows from a TALK node ("What's your name?") to a HEAR node (capturing the name as a string variable) to another TALK node ("Nice to meet you, {name}!"). - -**Generated Code:** -```basic -TALK "What's your name?" -HEAR name AS STRING -TALK "Nice to meet you, " + name + "!" -``` - -### Keyboard Shortcuts in Designer - -| Shortcut | Action | -|----------|--------| -| `Ctrl+S` | Save | -| `Ctrl+O` | Open file | -| `Ctrl+Z` | Undo | -| `Ctrl+Y` | Redo | -| `Ctrl+C` | Copy block | -| `Ctrl+V` | Paste block | -| `Delete` | Delete selected | -| `Escape` | Deselect | - ---- - -## Part XII: Sources - Prompts & Templates - -### What Sources Does - -Sources is your library of prompts, templates, tools, and AI models. Find and use pre-built components to extend your bot. - -### The Sources Interface - -Sources Interface - -### Tabs Explained - -| Tab | Contains | Use For | -|-----|----------|---------| -| **Prompts** | Pre-written AI instructions | Starting conversations | -| **Templates** | Complete bot packages | Full solutions | -| **MCP Servers** | External tool connections | Integrations | -| **LLM Tools** | AI functions | Extending capabilities | -| **Models** | AI model options | Choosing AI provider | - -### Using a Prompt - -1. Browse or search prompts -2. Click on a prompt card -3. Click **Use** to apply it -4. Customize if needed - -### Installing a Template - -1. Go to **Templates** tab -2. Find a template (e.g., "CRM Contacts") -3. Click **Install** -4. Configure settings -5. Template is now active - -### Available Models - -| Model | Provider | Best For | -|-------|----------|----------| -| GPT-4o | OpenAI | General tasks, vision | -| Claude 3.5 | Anthropic | Analysis, coding | -| Gemini 1.5 | Google | Long documents | -| Llama 3.1 | Meta | Open source, privacy | - ---- - -## Part XIII: Tools - System Utilities - -### Compliance Scanner - -Compliance Scanner Interface - -**What It Checks:** -- Hardcoded passwords -- Exposed API keys -- SQL injection risks -- Deprecated keywords -- Security best practices - ---- - -## Part XIV: Settings - -### Accessing Settings - -1. Click your **avatar** (top right) -2. Select **Settings** - -### Setting Categories - -**Profile:** -- Display name -- Avatar image -- Email address -- Language preference - -**Notifications:** -- Email notifications -- Desktop alerts -- Sound preferences - -**Appearance:** -- Theme (Light/Dark/Auto) -- Accent color -- Font size - -**Privacy:** -- Data retention -- Conversation history -- Usage analytics - -**Connections:** -- Email accounts -- Calendar sync -- Cloud storage - ---- - -## Part XV: Keyboard Shortcuts Reference - -### Global Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Alt+1` | Open Chat | -| `Alt+2` | Open Drive | -| `Alt+3` | Open Tasks | -| `Alt+4` | Open Mail | -| `Alt+5` | Open Calendar | -| `Escape` | Close dialog/menu | -| `/` | Focus search | -| `Ctrl+K` | Command palette | - -### Common Shortcuts - -| Shortcut | Action | -|----------|--------| -| `Ctrl+S` | Save | -| `Ctrl+Z` | Undo | -| `Ctrl+Y` | Redo | -| `Ctrl+C` | Copy | -| `Ctrl+V` | Paste | -| `Ctrl+A` | Select all | -| `Ctrl+F` | Find | - ---- - -## Part XVI: Tips & Best Practices - -### Daily Workflow - -**Morning:** -1. Open Suite -2. Check Chat for overnight messages -3. Review Tasks for the day -4. Check Calendar for meetings - -**During Work:** -- Use Chat for quick questions -- Upload files to Drive -- Update Tasks as you complete them -- Take notes in Paper - -**End of Day:** -- Mark completed tasks done -- Archive old emails -- Review tomorrow's calendar - -### Productivity Tips - -**In Chat:** -- Be specific in your questions -- Use follow-up questions -- Say "summarize" for long responses - -**In Drive:** -- Use folders to organize -- Star important files -- Use search instead of browsing - -**In Tasks:** -- Break big tasks into smaller ones -- Set realistic due dates -- Use categories to organize - -**In Mail:** -- Process emails once -- Archive instead of delete -- Use AI for drafting - -### Getting Help - -**Ask the Bot:** -``` -You: How do I upload a file? -You: What keyboard shortcuts are there? -You: Help me with tasks -``` - -**Resources:** -- This manual -- In-app help (click ?) -- Support team - ---- - -## Appendix A: Troubleshooting - -### Common Issues - -**Suite won't load:** -- Refresh the page (`F5` or `Ctrl+R`) -- Clear browser cache -- Try a different browser - -**Files won't upload:** -- Check file size (max 100MB) -- Check internet connection -- Try a smaller file first - -**Bot not responding:** -- Wait a few seconds -- Refresh the page -- Check internet connection - -**Video/audio not working:** -- Allow camera/microphone in browser -- Check device permissions -- Try different browser - -### Error Messages - -| Message | Solution | -|---------|----------| -| "Connection lost" | Check internet, refresh page | -| "File too large" | Reduce file size | -| "Permission denied" | Contact administrator | -| "Session expired" | Log in again | - ---- - -## Appendix B: Glossary - -| Term | Definition | -|------|------------| -| **Bot** | AI assistant that responds to your messages | -| **Dialog** | A conversation flow or script | -| **HTMX** | Technology that makes pages interactive | -| **KB** | Knowledge Base - stored information | -| **MCP** | Model Context Protocol - tool connections | -| **Suite** | The complete workspace application | -| **Template** | Pre-built bot configuration | - ---- - ---- - -*© General Bots - Built with ❤️ and AI* - -*For the latest documentation, visit the [online manual](../chapter-04-gbui/README.md)* \ No newline at end of file diff --git a/docs/src/chapter-04-gbui/ui-structure.md b/docs/src/chapter-04-gbui/ui-structure.md deleted file mode 100644 index bfc1035b..00000000 --- a/docs/src/chapter-04-gbui/ui-structure.md +++ /dev/null @@ -1,194 +0,0 @@ -# UI Structure - -The BotServer UI system provides two interface implementations designed for different deployment scenarios. Choose the right interface based on your use case and performance requirements. - -General Bots - -## Directory Layout - -``` -ui/ -├── suite/ # Full-featured interface -│ ├── index.html -│ ├── js/ -│ ├── css/ -│ ├── public/ -│ ├── drive/ -│ ├── chat/ -│ ├── mail/ -│ ├── tasks/ -│ ├── default.gbui -│ └── single.gbui -│ -└── minimal/ # Lightweight interface - ├── index.html - ├── styles.css - └── app.js -``` - -## Suite Interface - -The Suite interface (`ui/suite/`) delivers a comprehensive, desktop-class experience with multi-application integration. It includes Chat, Drive, Tasks, and Mail modules in a unified workspace. - -The Suite interface provides multi-application integration with seamless navigation between modules, rich interactions for complex workflows, and responsive design that adapts across desktop, tablet, and mobile form factors. Customizable GBUI templates allow you to choose between `default.gbui` for the full layout or `single.gbui` for a chat-focused experience. Tauri integration enables native desktop packaging for distribution outside the browser. - -The Suite interface is best suited for enterprise deployments requiring full functionality, power users working with multiple services simultaneously, desktop application distribution via Tauri builds, and multi-service integrations where context switching between modules matters. - -You can access the Suite interface via web at `http://localhost:8080/suite` or as a desktop application through the Tauri build using the `--desktop` flag. - -## Minimal Interface - -The Minimal interface (`ui/minimal/`) prioritizes speed and simplicity. It loads fast, uses minimal resources, and focuses on essential chat interactions. - -This lightweight interface provides core chat and basic interactions only, fast loading with minimal dependencies, and low resource usage suitable for constrained environments. The design supports easy embedding into existing applications and takes a mobile-first approach to responsive layout. - -The Minimal interface excels for mobile web access, embedded chatbots in external websites, low-bandwidth environments, quick access terminals and kiosks, and scenarios where simplicity matters more than features. - -Access the Minimal interface at the root URL `http://localhost:8080` where it is served by default, explicitly at `http://localhost:8080/minimal`, or embedded via iframe or WebView in your own applications. - -## Configuration - -### Server Configuration - -UI paths are configured in several locations throughout the codebase. - -The main server configuration in `src/main.rs` sets the static path: - -```rust -let static_path = std::path::Path::new("./web/suite"); -``` - -The UI server module at `src/core/ui_server/mod.rs` defines its own path: - -```rust -let static_path = PathBuf::from("./ui/suite"); -``` - -For Tauri desktop builds, `tauri.conf.json` specifies the frontend distribution: - -```json -{ - "build": { - "frontendDist": "./ui/suite" - } -} -``` - -### Routing - -Both interfaces can be served simultaneously with different routes: - -```rust -Router::new() - .route("/", get(serve_minimal)) - .route("/minimal", get(serve_minimal)) - .route("/suite", get(serve_suite)) -``` - -The minimal interface serves at root by default, providing faster loading for most users who need quick chat interactions. - -## API Compliance - -The Minimal UI implements full compliance with the Bot Core API. Both interfaces support the same backend endpoints, ensuring consistent functionality regardless of which interface you choose. - -| Endpoint | Method | Purpose | -|----------|--------|---------| -| `/ws` | WebSocket | Real-time messaging | -| `/api/auth` | GET | Authentication | -| `/api/sessions` | GET/POST | Session management | -| `/api/sessions/{id}` | GET | Session details | -| `/api/sessions/{id}/history` | GET | Message history | -| `/api/sessions/{id}/start` | POST | Start session | -| `/api/voice/start` | POST | Voice input start | -| `/api/voice/stop` | POST | Voice input stop | - -Both interfaces use the same WebSocket message types for communication. TEXT (1) handles regular text messages, VOICE (2) handles voice messages, CONTINUE (3) continues interrupted responses, CONTEXT (4) manages context changes, and SYSTEM (5) delivers system messages. - -## Performance Characteristics - -### Suite Interface - -| Metric | Typical Value | -|--------|---------------| -| Initial load | ~500KB | -| Time to interactive | ~1.5s | -| Memory usage | ~80MB | -| Best for | Full productivity | - -### Minimal Interface - -| Metric | Typical Value | -|--------|---------------| -| Initial load | ~50KB | -| Time to interactive | ~200ms | -| Memory usage | ~20MB | -| Best for | Quick interactions | - -## Browser Support - -Both interfaces support modern browsers with full functionality: - -| Browser | Minimum Version | WebSocket | Voice | -|---------|----------------|-----------|-------| -| Chrome | 90+ | ✅ | ✅ | -| Firefox | 88+ | ✅ | ✅ | -| Safari | 14+ | ✅ | ✅ | -| Edge | 90+ | ✅ | ✅ | -| Mobile Chrome | 90+ | ✅ | ✅ | -| Mobile Safari | 14+ | ✅ | ✅ | - -## Switching Interfaces - -Users can switch between interfaces by navigating to the appropriate URL. For programmatic switching, update the `ui_server/mod.rs` to change the default: - -```rust -// Serve minimal at root (default) -match fs::read_to_string("ui/minimal/index.html") - -// Or serve suite at root -match fs::read_to_string("ui/suite/index.html") -``` - -## Troubleshooting - -If you encounter 404 errors, clear your browser cache, rebuild the project with `cargo clean && cargo build`, and verify the files exist in the `ui/suite/` or `ui/minimal/` directories. - -For Tauri build failures, check that `tauri.conf.json` has the correct `frontendDist` path and ensure `ui/suite/index.html` exists. - -When static files aren't loading, verify the `ServeDir` configuration in the router and check that subdirectories (js, css, public) exist with their expected contents. - -Debug commands can help diagnose issues: - -```bash -# Verify UI structure -ls -la ui/suite/ -ls -la ui/minimal/ - -# Test interfaces -curl http://localhost:8080/ -curl http://localhost:8080/suite/ - -# Check static file serving -curl http://localhost:8080/js/app.js -``` - -## Customization - -### GBUI Templates - -The Suite interface uses GBUI templates for layout customization. The `default.gbui` template provides the full multi-app layout with sidebar navigation, while `single.gbui` offers a streamlined chat-focused view. Edit these files to customize the interface structure without modifying core code. - -### CSS Theming - -Both interfaces support CSS customization through their respective stylesheets. The Suite interface provides more extensive theming options through CSS custom properties, allowing you to adjust colors, spacing, and typography to match your brand. - -## Future Enhancements - -Planned improvements include dynamic UI selection based on device capabilities to automatically serve the most appropriate interface, progressive enhancement from minimal to suite as users need additional features, service worker implementation for offline support, and WebAssembly components for high-performance features that require client-side computation. - -## See Also - -- [default.gbui Reference](./default-gbui.md) - Full desktop template -- [single.gbui Reference](./single-gbui.md) - Simple chat template -- [Console Mode](./console-mode.md) - Terminal interface -- [Monitoring Dashboard](./monitoring.md) - System observability \ No newline at end of file diff --git a/docs/src/chapter-05-gbtheme/README.md b/docs/src/chapter-05-gbtheme/README.md deleted file mode 100644 index 3324db3b..00000000 --- a/docs/src/chapter-05-gbtheme/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# Chapter 05: Themes and Styling - -Customize your bot's appearance with `.gbtheme` packages. - -## Overview - -Themes control colors, fonts, logos, and overall visual presentation of your bot interface. - -## Quick Start - -```csv -# In config.csv -name,value -theme-color1,#0d2b55 -theme-color2,#fff9c2 -theme-title,My Bot -theme-logo,https://example.com/logo.svg -``` - -## Theme Structure - -``` -mybot.gbai/ -└── mybot.gbtheme/ - └── style.css -``` - -## Configuration Options - -| Setting | Description | Example | -|---------|-------------|---------| -| `theme-color1` | Primary color | `#0d2b55` | -| `theme-color2` | Secondary color | `#fff9c2` | -| `theme-title` | Bot name in header | `My Assistant` | -| `theme-logo` | Logo URL | `https://...` | - -## CSS Customization - -Create `style.css` in your `.gbtheme` folder: - -```css -:root { - --primary: #0d2b55; - --secondary: #fff9c2; -} - -.chat-header { - background: var(--primary); -} - -.user-message { - background: var(--secondary); -} -``` - -## Chapter Contents - -- [Theme Structure](./structure.md) - File organization -- [CSS Customization](./css.md) - Styling reference - -## See Also - -- [UI Reference](../chapter-04-gbui/README.md) - Interface options -- [.gbot Configuration](../chapter-08-config/README.md) - All settings \ No newline at end of file diff --git a/docs/src/chapter-05-gbtheme/css.md b/docs/src/chapter-05-gbtheme/css.md deleted file mode 100644 index bbbe6dae..00000000 --- a/docs/src/chapter-05-gbtheme/css.md +++ /dev/null @@ -1,427 +0,0 @@ -# CSS Customization - -The **gbtheme** CSS files define the visual style of the bot UI. They are split into three layers to make them easy to extend. - -## Files - -| File | Role | -|------|------| -| `main.css` | Core layout, typography, and global variables. | -| `components.css` | Styles for reusable UI components (buttons, cards, modals). | -| `responsive.css` | Media queries for mobile, tablet, and desktop breakpoints. | - -## CSS Variables (in `main.css`) - -```css -:root { - --primary-color: #2563eb; - --secondary-color: #64748b; - --background-color: #ffffff; - --text-color: #1e293b; - --border-radius: 8px; - --spacing-unit: 8px; -} -``` - -Changing a variable updates the entire theme without editing individual rules. - -## Extending the Theme - -1. **Add a new variable** – Append to `:root` and reference it in any selector. -2. **Override a component** – Duplicate the selector in `components.css` after the original definition; the later rule wins. -3. **Create a dark mode** – Add a `@media (prefers-color-scheme: dark)` block that redefines the variables. - -```css -@media (prefers-color-scheme: dark) { - :root { - --primary-color: #3b82f6; - --background-color: #111827; - --text-color: #f9fafb; - } -} -``` - -## Best Practices - -* Keep the file size small – avoid large image data URIs; store images in `assets/`. -* Use `rem` units for font sizes; they scale with the root `font-size`. -* Limit the depth of nesting; flat selectors improve performance. - -All CSS files are loaded in `index.html` in the order: `main.css`, `components.css`, `responsive.css`. - -## Component Styling Guide - -### Message Bubbles - -Customize chat message appearance: - -```css -/* User messages */ -.message-user { - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); - color: white; - padding: 12px 16px; - border-radius: 18px 18px 4px 18px; - max-width: 70%; - margin-left: auto; -} - -/* Bot messages */ -.message-bot { - background: #f7fafc; - color: #2d3748; - padding: 12px 16px; - border-radius: 18px 18px 18px 4px; - max-width: 70%; - border: 1px solid #e2e8f0; -} - -/* Typing indicator */ -.typing-indicator { - display: inline-flex; - padding: 16px; - background: #edf2f7; - border-radius: 18px; -} - -.typing-indicator span { - height: 8px; - width: 8px; - background: #718096; - border-radius: 50%; - margin: 0 2px; - animation: typing 1.4s infinite; -} -``` - -### Input Field - -Style the message input area: - -```css -.input-container { - padding: 16px; - background: white; - border-top: 1px solid #e2e8f0; -} - -.input-wrapper { - display: flex; - align-items: center; - background: #f7fafc; - border: 2px solid #e2e8f0; - border-radius: 24px; - padding: 8px 16px; - transition: all 0.2s; -} - -.input-wrapper:focus-within { - border-color: var(--primary-color); - background: white; - box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1); -} - -.message-input { - flex: 1; - border: none; - background: transparent; - outline: none; - font-size: 16px; -} - -.send-button { - background: var(--primary-color); - color: white; - border: none; - border-radius: 50%; - width: 36px; - height: 36px; - display: flex; - align-items: center; - justify-content: center; - cursor: pointer; - transition: transform 0.2s; -} - -.send-button:hover { - transform: scale(1.1); -} - -.send-button:active { - transform: scale(0.95); -} -``` - -### Buttons - -Consistent button styling: - -```css -/* Primary button */ -.btn-primary { - background: var(--primary-color); - color: white; - border: none; - padding: 10px 20px; - border-radius: 8px; - font-weight: 500; - cursor: pointer; - transition: all 0.2s; -} - -.btn-primary:hover { - filter: brightness(110%); - box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); -} - -/* Secondary button */ -.btn-secondary { - background: transparent; - color: var(--primary-color); - border: 2px solid var(--primary-color); - padding: 8px 18px; - border-radius: 8px; - font-weight: 500; - cursor: pointer; - transition: all 0.2s; -} - -.btn-secondary:hover { - background: var(--primary-color); - color: white; -} - -/* Icon button */ -.btn-icon { - background: transparent; - border: none; - width: 40px; - height: 40px; - border-radius: 50%; - display: flex; - align-items: center; - justify-content: center; - cursor: pointer; - transition: background 0.2s; -} - -.btn-icon:hover { - background: rgba(0, 0, 0, 0.05); -} -``` - -## Animation Library - -### Entrance Animations - -```css -@keyframes slideInUp { - from { - transform: translateY(20px); - opacity: 0; - } - to { - transform: translateY(0); - opacity: 1; - } -} - -@keyframes fadeIn { - from { opacity: 0; } - to { opacity: 1; } -} - -@keyframes scaleIn { - from { - transform: scale(0.95); - opacity: 0; - } - to { - transform: scale(1); - opacity: 1; - } -} - -/* Apply animations */ -.message { - animation: slideInUp 0.3s ease-out; -} - -.modal { - animation: scaleIn 0.2s ease-out; -} -``` - -### Loading States - -```css -/* Spinner */ -.spinner { - width: 40px; - height: 40px; - border: 3px solid #e2e8f0; - border-top-color: var(--primary-color); - border-radius: 50%; - animation: spin 0.8s linear infinite; -} - -@keyframes spin { - to { transform: rotate(360deg); } -} - -/* Skeleton loader */ -.skeleton { - background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); - background-size: 200% 100%; - animation: loading 1.5s infinite; -} - -@keyframes loading { - 0% { background-position: 200% 0; } - 100% { background-position: -200% 0; } -} -``` - -## Responsive Design Patterns - -### Mobile-First Approach - -```css -/* Base mobile styles */ -.container { - padding: 16px; - width: 100%; -} - -/* Tablet and up */ -@media (min-width: 768px) { - .container { - padding: 24px; - max-width: 768px; - margin: 0 auto; - } -} - -/* Desktop */ -@media (min-width: 1024px) { - .container { - padding: 32px; - max-width: 1024px; - } -} - -/* Wide screens */ -@media (min-width: 1440px) { - .container { - max-width: 1280px; - } -} -``` - -### Touch-Friendly Styles - -```css -/* Increase touch targets on mobile */ -@media (pointer: coarse) { - button, a, input, select { - min-height: 44px; - min-width: 44px; - } - - .btn-primary, .btn-secondary { - padding: 12px 24px; - font-size: 16px; - } -} - -/* Disable hover effects on touch devices */ -@media (hover: none) { - .btn-primary:hover { - filter: none; - box-shadow: none; - } -} -``` - -## Theme Variants - -### Dark Mode - -```css -@media (prefers-color-scheme: dark) { - :root { - --primary-color: #60a5fa; - --secondary-color: #94a3b8; - --background-color: #0f172a; - --text-color: #f1f5f9; - --border-color: #334155; - } - - .message-bot { - background: #1e293b; - color: #f1f5f9; - border-color: #334155; - } - - .input-wrapper { - background: #1e293b; - border-color: #334155; - } -} -``` - -### High Contrast - -```css -@media (prefers-contrast: high) { - :root { - --primary-color: #0066cc; - --text-color: #000000; - --background-color: #ffffff; - } - - * { - border-width: 2px !important; - } - - button:focus, input:focus { - outline: 3px solid #000000 !important; - outline-offset: 2px !important; - } -} -``` - -## Performance Tips - -1. **Use CSS Variables**: Change themes by updating variables, not entire stylesheets -2. **Minimize Specificity**: Keep selectors simple for faster parsing -3. **Avoid Deep Nesting**: Maximum 3 levels deep -4. **Use Transform/Opacity**: For animations instead of layout properties -5. **Lazy Load Non-Critical CSS**: Load theme variations on demand - -## Browser Compatibility - -```css -/* Provide fallbacks for older browsers */ -.gradient-bg { - background: #3b82f6; /* Fallback */ - background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%); -} - -/* Use @supports for progressive enhancement */ -@supports (backdrop-filter: blur(10px)) { - .modal-backdrop { - backdrop-filter: blur(10px); - } -} -``` - -## See Also - -- [Theme Structure](./structure.md) - File organization -- [Chapter 4: User Interface](../chapter-04-gbui/README.md) - Applying themes to templates -- [Chapter 6: BASIC](../chapter-06-gbdialog/README.md) - Dynamic theme switching - -## Next Step - -Return to [Chapter 5 Overview](./README.md) or continue to [Chapter 6: BASIC Dialogs](../chapter-06-gbdialog/README.md). diff --git a/docs/src/chapter-05-gbtheme/structure.md b/docs/src/chapter-05-gbtheme/structure.md deleted file mode 100644 index b0f35a3a..00000000 --- a/docs/src/chapter-05-gbtheme/structure.md +++ /dev/null @@ -1,226 +0,0 @@ -# Theme Structure - -The **gbtheme** package is simply CSS files that style the bot's UI. Themes don't include HTML or JavaScript - they only control appearance. - -``` -theme-name.gbtheme/ -├── default.css # Main theme file (required) -├── dark.css # Optional dark mode variant -├── print.css # Optional print styles -└── assets/ # Optional theme resources - ├── images/ - ├── fonts/ - └── icons/ -``` - -### Design Principles - -* **CSS-only theming** – Themes are pure CSS files, no HTML or JavaScript modifications -* **CSS Variables** – Use CSS custom properties for colors, spacing, and other values -* **Responsive design** – Use media queries within your CSS for mobile-first layouts -* **Asset locality** – Optional `assets/` folder for theme-specific images, fonts, and icons - -### Creating Your Theme - -1. Create a `.gbtheme` folder in your bot package -2. Add a `default.css` file with your styles -3. Override CSS variables to change colors and spacing -4. Add optional assets like fonts or background images - -The system automatically picks up any theme placed under `@/templates/…` when the bot's configuration (`.gbtheme` entry in `config.csv`) points to the folder name. - -## Theme Loading Process - -1. **Discovery**: Bot looks for theme folder in `work/{bot_name}/{bot_name}.gbtheme/` -2. **Validation**: Checks for required files (at least one CSS file) -3. **Registration**: Theme becomes available in theme selector -4. **Activation**: User selects theme or bot loads default -5. **Hot Reload**: Changes apply immediately without restart - -## File Organization Best Practices - -### CSS File Options - -You can have multiple CSS files in your theme: - -``` -mybot.gbtheme/ -├── default.css # Main theme (loaded automatically) -├── dark.css # Dark mode variant -├── mobile.css # Mobile-specific overrides -└── print.css # Print media styles -``` - -Or keep everything in a single file - your choice! - -### Asset Management - -``` -assets/ -├── images/ -│ ├── logo.svg # Vector graphics preferred -│ ├── bg.webp # Modern formats for performance -│ └── icons/ # Icon set -├── fonts/ -│ └── custom.woff2 # Web fonts if needed -└── data/ - └── theme.json # Theme metadata -``` - -## Creating a Custom Theme - -### Step 1: Create Theme Folder - -```bash -mkdir -p work/mybot/mybot.gbtheme -``` - -### Step 2: Create Your CSS - -Create `default.css` with CSS variables: - -```css -:root { - /* Brand Colors */ - --brand-primary: #your-color; - --brand-secondary: #your-color; - - /* Semantic Colors */ - --color-success: #10b981; - --color-warning: #f59e0b; - --color-error: #ef4444; - - /* Typography */ - --font-family: 'Inter', system-ui, sans-serif; - --font-size-base: 16px; - --line-height: 1.5; - - /* Spacing Scale */ - --space-xs: 0.25rem; - --space-sm: 0.5rem; - --space-md: 1rem; - --space-lg: 2rem; - --space-xl: 4rem; -} -``` - -### Step 3: Style Components - -Add your component styles in the same file: - -```css -/* Custom message bubbles */ -.message-user { - background: var(--brand-primary); - color: white; - border-radius: 18px 18px 4px 18px; -} - -.message-bot { - background: #f3f4f6; - border: 1px solid #e5e7eb; - border-radius: 18px 18px 18px 4px; -} -``` - -## Using the Theme - -Once you've created your CSS file, the bot will automatically load it. You can switch between themes using BASIC: - -```basic -' Switch to a different theme -CHANGE THEME "dark" - -' Back to default -CHANGE THEME "default" -``` - -## Performance Optimization - -### CSS Loading Strategy - -1. **Critical CSS**: Inline essential styles in HTML -2. **Async Loading**: Load non-critical CSS asynchronously -3. **Minification**: Minify CSS for production -4. **Purging**: Remove unused CSS rules - -### Asset Optimization - -- Use SVG for logos and icons -- Implement lazy loading for images -- Serve WebP with fallbacks -- Enable gzip compression - -## Theme Selection - -Themes are switched via BASIC commands, not JavaScript. The system handles the CSS file swapping automatically. - -## Accessibility Considerations - -- Maintain WCAG 2.1 AA contrast ratios -- Support high contrast mode -- Include focus indicators -- Test with screen readers - -## Advanced Personalization Options - -### Beyond CSS Theming - -While themes handle visual styling, you have more options for deeper UI customization: - -1. **Extend default.gbui** - The UI templates in `.gbui` packages can be modified: - - Copy the default UI templates to your bot's `.gbui` folder - - Modify the HTML structure to fit your needs - - Add custom components and layouts - - The system will use your UI instead of the default - -2. **Create Your Own UI Type** - Build a completely custom interface: - - Design your own UI framework - - Implement custom WebSocket handlers - - Create unique interaction patterns - - Full control over the user experience - -### Join the Community - -**We encourage you to contribute!** The General Bots project welcomes: - -- **UI Improvements** - Submit pull requests with better default UIs -- **Theme Collections** - Share your creative themes -- **Custom UI Types** - Develop new interaction paradigms -- **Documentation** - Help improve these guides - -### Using General Bots as a Foundation - -General Bots is designed to be a starting point for your own projects: - -``` -Fork the project → Customize the UI → Build your product -``` - -You can: -- Use it as a base for commercial products -- Create industry-specific bot interfaces -- Develop specialized UI frameworks -- Build on top of the core engine - -The architecture is intentionally modular - take what you need, replace what you don't. - -### Getting Started with UI Development - -1. **Study the default.gbui** - Understand the current structure -2. **Fork the repository** - Create your own version -3. **Experiment freely** - The UI layer is independent -4. **Share your work** - Help others learn from your innovations - -Remember: The UI is just HTML/CSS/JS talking to the bot via WebSocket. You have complete freedom to reimagine how users interact with your bot! - -## See Also - -- [CSS Customization](./css.md) - Detailed CSS guide -- [Chapter 4: User Interface](../chapter-04-gbui/README.md) - UI templates -- [Chapter 6: BASIC](../chapter-06-gbdialog/README.md) - Theme switching in dialogs -- [GitHub Repository](https://github.com/GeneralBots/botserver) - Contribute to the project - -## Next Step - -Continue to [CSS Customization](./css.md) for detailed styling techniques. diff --git a/docs/src/chapter-06-gbdialog/README.md b/docs/src/chapter-06-gbdialog/README.md deleted file mode 100644 index 001375ba..00000000 --- a/docs/src/chapter-06-gbdialog/README.md +++ /dev/null @@ -1,96 +0,0 @@ -# Chapter 06: BASIC + LLM - The Perfect Match - -## Why BASIC? - -In 1964, John Kemeny and Thomas Kurtz created BASIC with a revolutionary idea: programming should be for everyone. Today, General Bots brings this philosophy to the AI era. - -**With BASIC + LLM, you write:** - -```basic -TALK "What's your name?" -HEAR name -poem = LLM "Create a heartfelt poem for " + name -TALK poem -``` - -**Not 50 lines of boilerplate.** - -## The Core Keywords - -Just SEVEN main keywords power everything: - -| Keyword | Purpose | Example | -|---------|---------|---------| -| **TALK** | Output | `TALK "Hello!"` | -| **HEAR** | Input | `HEAR name AS NAME` | -| **USE KB** | Knowledge | `USE KB "docs"` | -| **USE TOOL** | Functions | `USE TOOL "weather"` | -| **GET** | Data | `GET "api/users"` | -| **IF/THEN** | Logic | `IF age >= 18 THEN ...` | -| **FOR/NEXT** | Loops | `FOR i = 1 TO 10 ...` | - -## Your First Tool - -In the LLM world, you write tools that AI can use: - -```basic -' enrollment.bas - An LLM-callable tool -PARAM name AS STRING LIKE "John Smith" DESCRIPTION "Full name" -PARAM email AS STRING LIKE "john@example.com" DESCRIPTION "Email" -PARAM course AS STRING LIKE "Introduction to AI" DESCRIPTION "Course" - -DESCRIPTION "Enrolls a student in a course" - -SAVE "enrollments.csv", name, email, course, NOW() -TALK "Enrolled " + name + " in " + course -``` - -The LLM handles the conversation. You define the action. - -## Everyone Can Program - -**You don't need:** -- A computer science degree -- Years of experience -- Understanding of algorithms - -**You just need:** -- An idea -- 10 minutes to learn BASIC -- Creativity - -## Getting Started - -| Time | Goal | -|------|------| -| Minute 1 | `TALK "Hello, world!"` | -| Minute 5 | Add HEAR and LLM | -| Day 1 | Production-ready bot | - -## Documentation Guide - -| Document | Purpose | -|----------|---------| -| [Basics](./basics.md) | Core LLM-first concepts | -| [Keywords Reference](./keywords.md) | Complete keyword list | -| [Templates](./templates.md) | Real-world examples | -| [Universal Messaging](./universal-messaging.md) | Multi-channel support | - -### Keyword Categories - -- **Core:** [TALK](./keyword-talk.md), [HEAR](./keyword-hear.md) -- **Context:** [SET CONTEXT](./keyword-set-context.md), [USE KB](./keyword-use-kb.md) -- **Memory:** [GET/SET BOT MEMORY](./keyword-get-bot-memory.md), [GET/SET USER MEMORY](./keyword-get-user-memory.md) -- **Data:** [GET](./keyword-get.md), [SAVE](./keyword-save.md), [FIND](./keyword-find.md) -- **HTTP:** [POST](./keyword-post.md), [PUT](./keyword-put.md), [DELETE](./keyword-delete-http.md) -- **Files:** [READ](./keyword-read.md), [WRITE](./keyword-write.md), [UPLOAD](./keyword-upload.md) - -## The Philosophy - -BASIC in General Bots isn't about controlling conversation flow - it's about providing tools and context that LLMs use intelligently. - -**Write simple tools. Let AI handle the complexity.** - ---- - -*"The beauty of BASIC lies not in what it can do, but in who it enables to do it."* \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/assets/basic-execution-flow.svg.backup b/docs/src/chapter-06-gbdialog/assets/basic-execution-flow.svg.backup deleted file mode 100644 index 70f0ef8a..00000000 --- a/docs/src/chapter-06-gbdialog/assets/basic-execution-flow.svg.backup +++ /dev/null @@ -1,137 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BASIC LLM Tool Execution Flow - - - - - USER - "What's the policy?" - - - - - - - LLM + CONTEXT - Understands intent + loaded KBs - - - - - - - - - Tool? - - - - - - - - Direct Answer - - - - - - Call Tool - - - - BASIC TOOL - enrollment.bas - PARAM name, course - - - - - - - RESPONSE - Generate natural answer - - - - - - - BOT - "30-day return..." - - - - MEMORY STORE - BOT_MEMORY • Session State • Context - - - - - - - - - LLM decides tool calls • Zero IF/THEN logic • Natural conversation flow • Context-aware responses - - - - - Legend: - - Direct response - - Tool invocation - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/basic-vs-automation-tools.md b/docs/src/chapter-06-gbdialog/basic-vs-automation-tools.md deleted file mode 100644 index 69606096..00000000 --- a/docs/src/chapter-06-gbdialog/basic-vs-automation-tools.md +++ /dev/null @@ -1,225 +0,0 @@ -# BASIC vs Automation Tools: A Practical Comparison - -> **Understanding how General Bots BASIC compares to other automation platforms** - -## Overview - -General Bots BASIC provides a conversational-first approach to automation. This chapter compares BASIC with popular automation tools to help you understand when each approach works best. - ---- - -## Comparison Matrix - -| Feature | Zapier | n8n | Make | Power Automate | **BASIC** | -|---------|--------|-----|------|----------------|-----------| -| Webhooks | ✅ | ✅ | ✅ | ✅ | ✅ | -| Scheduling | ✅ | ✅ | ✅ | ✅ | ✅ `SET SCHEDULE` | -| HTTP/REST | ✅ | ✅ | ✅ | ✅ | ✅ | -| GraphQL | ❌ | ✅ | ✅ | ❌ | ✅ | -| SOAP | ❌ | ❌ | ✅ | ✅ | ✅ | -| Database Native | ❌ | ✅ | ✅ | ✅ | ✅ | -| **Conversations** | ❌ | ❌ | ❌ | ❌ | ✅ | -| **WhatsApp Native** | Plugin | Plugin | Plugin | Plugin | ✅ Built-in | -| **Telegram Native** | Plugin | Plugin | Plugin | ❌ | ✅ Built-in | -| **Multi-Channel** | Limited | Limited | Limited | Limited | ✅ Native | -| **LLM Integration** | Plugin | Plugin | Plugin | GPT-4 | ✅ Any model | -| **Self-Hosted** | ❌ | ✅ | ❌ | ❌ | ✅ | -| **Open Source** | ❌ | ✅ | ❌ | ❌ | ✅ AGPL | - ---- - -## Key Differences - -### Conversation-First Design - -Traditional automation tools focus on backend workflows. BASIC adds interactive conversations: - - - -### Multi-Channel Native - -The same bot works across all channels without modification: - - - -This message reaches users on WhatsApp, Telegram, Web, or any configured channel—same content, adapted formatting. - -### LLM Model Freedom - -BASIC supports any LLM provider: - -- OpenAI (GPT-4, GPT-3.5) -- Anthropic (Claude) -- Local models (Llama, Mistral via llama.cpp) -- Groq, DeepSeek, and others -- Any OpenAI-compatible API - -Configure in `config.csv`: - -```csv -name,value -llm-url,http://localhost:8081 -llm-model,model.gguf -``` - ---- - -## When to Use Each Tool - -### Choose BASIC When You Need - -- **Interactive workflows** - Users participate in the process -- **Multi-channel presence** - Same bot on WhatsApp, Telegram, Web -- **AI-powered conversations** - Natural language understanding -- **Self-hosted deployment** - Full data control -- **Open source flexibility** - Modify and extend as needed - -### Choose Traditional Automation When You Need - -- **Backend-only workflows** - No user interaction required -- **Visual workflow builders** - Prefer drag-and-drop interfaces -- **Existing integrations** - Specific pre-built connectors -- **Team familiarity** - Team already knows the tool - ---- - -## Migration Examples - -### From Zapier - -Zapier workflow: Form submission → Slack notification → CRM entry → Welcome email - -BASIC equivalent: - - - -### From n8n - -n8n workflow: Monitor website → Alert on error → Create ticket - -BASIC equivalent runs on schedule and notifies immediately: - - - ---- - -## Complete Office Suite - -BASIC provides built-in capabilities for common office tasks: - -| Capability | BASIC Keyword | -|------------|---------------| -| Send email | `SEND MAIL` | -| Create draft | `CREATE DRAFT` | -| Schedule meetings | `BOOK` | -| Manage files | `UPLOAD`, `DOWNLOAD`, `LIST` | -| Create tasks | `CREATE TASK` | -| Video meetings | `CREATE MEETING` | - -### Example: Daily Report Automation - - - ---- - -## Getting Started - -### Quick Start - -1. Download and run BotServer -2. Edit your bot's `.bas` files -3. Configure settings in `config.csv` -4. Deploy to any channel - -### Resources - -- [Keywords Reference](./keywords.md) - Complete keyword documentation -- [SET SCHEDULE](./keyword-set-schedule.md) - Automate with schedules -- [WEBHOOK](./keyword-webhook.md) - Event-driven automation -- [Templates](./templates.md) - Ready-to-use examples - diff --git a/docs/src/chapter-06-gbdialog/basics.md b/docs/src/chapter-06-gbdialog/basics.md deleted file mode 100644 index a20a9000..00000000 --- a/docs/src/chapter-06-gbdialog/basics.md +++ /dev/null @@ -1,92 +0,0 @@ -# Dialog Basics - -BASIC dialogs in General Bots are designed for the LLM era - you write tools and context setters, not complex conversation flows. - -## Core Concepts - -| Concept | Description | -|---------|-------------| -| **LLM Tools** | BASIC scripts that become callable tools for the LLM | -| **Context** | SET CONTEXT provides knowledge to the LLM | -| **Suggestions** | ADD SUGGESTION guides conversations | -| **Memory** | GET/SET BOT/USER MEMORY for persistent data | - -## LLM-First Example - -```basic -' Load context from memory -resume = GET BOT MEMORY "announcements" -context = GET BOT MEMORY "company_info" - -' Give LLM the context it needs -SET CONTEXT "announcements" AS resume -SET CONTEXT "company" AS context - -' Guide the conversation -CLEAR SUGGESTIONS -ADD SUGGESTION "announcements" AS "Show me this week's updates" -ADD SUGGESTION "company" AS "Tell me about the company" - -' Start conversation -TALK "What would you like to know?" -``` - -## Creating LLM Tools - -Instead of parsing user input, create tools the LLM can call: - -```basic -' update-summary.bas - A tool the LLM can invoke -PARAM topic AS STRING LIKE "Q4 Results" DESCRIPTION "Topic to summarize" -PARAM length AS STRING LIKE "brief" DESCRIPTION "brief or detailed" - -DESCRIPTION "Creates a summary of the requested topic" - -data = GET BOT MEMORY topic -summary = LLM "Summarize this " + length + ": " + data -TALK summary -``` - -## Traditional vs LLM Approach - -| Traditional | LLM + BASIC | -|-------------|-------------| -| Parse user input manually | LLM understands naturally | -| Complex IF/ELSE trees | Tools with PARAMs | -| Validate every field | LLM handles validation | -| Design conversation flows | LLM manages conversation | - -## Tool Pattern Example - -```basic -' schedule-appointment.bas -PARAM service AS STRING LIKE "consultation" DESCRIPTION "Type of appointment" -PARAM date AS DATE LIKE "tomorrow at 3pm" DESCRIPTION "Preferred date/time" - -DESCRIPTION "Schedules an appointment and sends confirmation" - -appointment = GET "api/appointments/available" WITH service, date -IF appointment.available THEN - SET BOT MEMORY "last_appointment" AS appointment.id - SEND EMAIL TO user.email WITH appointment.details - TALK "Scheduled your " + service + " for " + date -ELSE - alternatives = GET "api/appointments/suggest" WITH service, date - TALK "That time isn't available. Alternatives: " + alternatives -END IF -``` - -## Best Practices - -| Do | Don't | -|----|-------| -| Write focused tools | Create complex conversation flows | -| Use context wisely | Micromanage the LLM | -| Trust the LLM | Parse user input manually | -| Use suggestions | Force rigid paths | - -## See Also - -- [Keywords Reference](./keywords.md) - Complete keyword list -- [Chapter Overview](./README.md) - Philosophy and introduction -- [Templates](./templates.md) - Real-world examples \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/examples-consolidated.md b/docs/src/chapter-06-gbdialog/examples-consolidated.md deleted file mode 100644 index 1d52f6e2..00000000 --- a/docs/src/chapter-06-gbdialog/examples-consolidated.md +++ /dev/null @@ -1,777 +0,0 @@ -# Consolidated Examples: Complete Tools & Workflows - -This document provides complete, production-ready examples that demonstrate how multiple keywords work together to build real-world tools and automation workflows. - -## 1. Customer Support Bot with AI - -A complete customer support solution with knowledge base, ticket creation, and escalation. - -```basic -' customer-support.bas -' Complete customer support tool with AI-powered responses - -' Initialize knowledge bases -USE KB "product-docs" -USE KB "faq" -USE KB "policies" - -' Set AI personality -SET CONTEXT "You are a helpful customer support agent for TechCorp. Be friendly, professional, and concise. If you cannot answer a question, offer to create a support ticket." - -' Main conversation loop -TALK "Hello! I'm your TechCorp support assistant. How can I help you today?" - -conversation_active = TRUE - -WHILE conversation_active - HEAR user_message - - ' Check for exit commands - IF INSTR(LCASE(user_message), "bye") > 0 OR INSTR(LCASE(user_message), "exit") > 0 THEN - TALK "Thank you for contacting TechCorp support. Have a great day!" - conversation_active = FALSE - ELSE IF INSTR(LCASE(user_message), "ticket") > 0 OR INSTR(LCASE(user_message), "human") > 0 THEN - ' User wants to create a ticket or talk to human - TALK "I'll create a support ticket for you. Please describe your issue in detail." - HEAR issue_description - - TALK "What's your email address?" - HEAR customer_email - - ' Create ticket in database - ticket_id = "TKT-" + FORMAT(NOW(), "YYYYMMDDHHmmss") - description = issue_description - ticket_status = "open" - priority = "normal" - created_at = NOW() - conversation_history = user_message - - SAVE "support_tickets", ticket_id, customer_email, description, ticket_status, priority, created_at, conversation_history - - ticket_result = ticket_id - ticket_id = ticket_result.id - - ' Send confirmation email - email_body = "Your support ticket #" + ticket_id + " has been created. Our team will respond within 24 hours." - SEND MAIL customer_email, "Support Ticket Created - #" + ticket_id, email_body - - ' Notify support team - SEND MAIL "support@techcorp.com", "New Ticket #" + ticket_id, "Customer: " + customer_email + "\n\nIssue: " + issue_description - - TALK "I've created ticket #" + ticket_id + ". You'll receive a confirmation email shortly. Is there anything else I can help with?" - ELSE - ' Use AI to answer the question - response = LLM user_message - TALK response - - ' Log the conversation - question = user_message - answer = response - log_timestamp = NOW() - INSERT "conversation_logs", question, answer, log_timestamp - - TALK "Did that answer your question? (yes/no/create ticket)" - HEAR feedback - - IF INSTR(LCASE(feedback), "no") > 0 THEN - TALK "I'm sorry I couldn't help. Would you like me to create a support ticket? (yes/no)" - HEAR create_ticket - IF INSTR(LCASE(create_ticket), "yes") > 0 THEN - ' Trigger ticket creation on next loop - user_message = "create ticket" - END IF - END IF - END IF -WEND -``` - -## 2. E-Commerce Order Management System - -Complete order processing with inventory, payments, and notifications. - -```basic -' order-system.bas -' E-commerce order management tool - -WEBHOOK "new-order" - -' Extract order data -order_id = body.order_id -customer_email = body.customer.email -customer_name = body.customer.name -items = body.items -shipping_address = body.shipping -payment_method = body.payment.method -payment_token = body.payment.token - -' Validate order -IF order_id = "" OR customer_email = "" THEN - WITH result = NEW OBJECT - .status = 400 - .error = "Missing required fields" - END WITH - EXIT -END IF - -' Check inventory for all items -inventory_ok = TRUE -out_of_stock_items = "" - -FOR EACH item IN items - product = FIND "products", "sku=" + item.sku - IF product.stock < item.quantity THEN - inventory_ok = FALSE - out_of_stock_items = out_of_stock_items + item.name + ", " - END IF -NEXT item - -IF NOT inventory_ok THEN - ' Notify customer of stock issue - SEND MAIL customer_email, "Order Issue - Items Out of Stock", "Unfortunately, the following items are out of stock: " + out_of_stock_items - - WITH result = NEW OBJECT - .status = 400 - .error = "Items out of stock" - .items = out_of_stock_items - END WITH - EXIT -END IF - -' Process payment -WITH payment_request = NEW OBJECT - .amount = body.total - .currency = "USD" - .token = payment_token - .description = "Order " + order_id -END WITH - -SET HEADER "Authorization", "Bearer " + GET BOT MEMORY "stripe_key" -payment_result = POST "https://api.stripe.com/v1/charges", payment_request - -IF payment_result.status <> "succeeded" THEN - SEND MAIL customer_email, "Payment Failed", "Your payment could not be processed. Please try again." - - WITH result = NEW OBJECT - .status = 402 - .error = "Payment failed" - END WITH - EXIT -END IF - -' Update inventory -FOR EACH item IN items - current_stock = FIND "products", "sku=" + item.sku - new_stock = current_stock.stock - item.quantity - - WITH stock_update = NEW OBJECT - .stock = new_stock - .updated_at = NOW() - END WITH - UPDATE "products", "sku=" + item.sku, stock_update - - ' Alert if low stock - IF new_stock < 10 THEN - SEND MAIL "inventory@company.com", "Low Stock Alert: " + item.sku, "Stock level: " + new_stock - END IF -NEXT item - -' Create order record -WITH order_record = NEW OBJECT - .order_id = order_id - .customer_email = customer_email - .customer_name = customer_name - .items = items - .total = body.total - .shipping_address = shipping_address - .payment_id = payment_result.id - .status = "confirmed" - .created_at = NOW() -END WITH - -SAVE "orders", order_id, order_record - -' Generate invoice PDF - pass variables directly -invoice_customer = customer_name -invoice_email = customer_email -invoice_items = order_items -subtotal = body.subtotal -tax = body.tax -shipping_cost = body.shipping_cost -invoice_date = FORMAT(NOW(), "MMMM DD, YYYY") - -invoice_pdf = GENERATE PDF "templates/invoice.html", order_id, invoice_customer, invoice_email, invoice_items, subtotal, tax, shipping_cost, total, invoice_date, "invoices/" + order_id + ".pdf" - -' Send confirmation email with invoice -email_body = "Thank you for your order, " + customer_name + "!\n\n" -email_body = email_body + "Order #: " + order_id + "\n" -email_body = email_body + "Total: $" + body.total + "\n\n" -email_body = email_body + "Your invoice is attached. You'll receive shipping updates soon." - -SEND MAIL customer_email, "Order Confirmed - #" + order_id, email_body, invoice_pdf.url - -' Notify warehouse - build simple notification -warehouse_order_id = order_id -warehouse_items = items -warehouse_address = shipping_address -warehouse_priority = "normal" -POST "https://warehouse.internal/api/orders", warehouse_order_id, warehouse_items, warehouse_address, warehouse_priority - -' Return success -result_status = "confirmed" -result_order_id = order_id -result_payment_id = payment_result.id -result_invoice_url = invoice_pdf.url -``` - -## 3. HR Onboarding Automation - -Complete employee onboarding workflow. - -```basic -' onboarding.bas -' HR onboarding automation tool - -WEBHOOK "new-employee" - -employee_name = body.name -employee_email = body.email -department = body.department -start_date = body.start_date -manager_email = body.manager_email -role = body.role - -' Validate input -IF employee_email = "" OR employee_name = "" THEN - WITH result = NEW OBJECT - .status = 400 - .error = "Missing employee name or email" - END WITH - EXIT -END IF - -' Create employee record -employee_id = "EMP-" + FORMAT(NOW(), "YYYYMMDD") + "-" + LEFT(GUID(), 4) -emp_name = employee_name -emp_email = employee_email -emp_department = department -emp_role = role -emp_manager = manager_email -emp_start_date = start_date -emp_status = "onboarding" -created_at = NOW() - -SAVE "employees", employee_id, emp_name, emp_email, emp_department, emp_role, emp_manager, emp_start_date, emp_status, created_at - -' Create tasks for IT setup -CREATE TASK "Create email account for " + employee_name, "it@company.com", start_date -CREATE TASK "Setup laptop for " + employee_name, "it@company.com", start_date -CREATE TASK "Create " + department + " system access for " + employee_name, "it@company.com", start_date - -' Create tasks for HR -CREATE TASK "Prepare employment documents for " + employee_name, "hr@company.com", start_date -CREATE TASK "Schedule orientation for " + employee_name, "hr@company.com", start_date -CREATE TASK "Add " + employee_name + " to benefits enrollment", "hr@company.com", start_date - -' Send welcome email to new employee -USE KB "employee-handbook" -SET CONTEXT "You are a friendly HR assistant. Create a warm, professional welcome message." - -welcome_content = LLM "Write a welcome email for " + employee_name + " joining as " + role + " in " + department + " department, starting on " + start_date - -SEND MAIL employee_email, "Welcome to the Team, " + employee_name + "!", welcome_content - -' Notify manager -manager_message = "New team member alert!\n\n" -manager_message = manager_message + employee_name + " will be joining your team as " + role + " on " + start_date + ".\n\n" -manager_message = manager_message + "Please prepare:\n" -manager_message = manager_message + "- First week schedule\n" -manager_message = manager_message + "- Team introduction meeting\n" -manager_message = manager_message + "- Project assignments\n" - -SEND MAIL manager_email, "New Team Member: " + employee_name, manager_message - -' Add to department Slack channel -slack_channel = "#" + LCASE(department) -slack_text = "🎉 Please welcome " + employee_name + " who will be joining us as " + role + " on " + start_date + "!" -POST "https://hooks.slack.com/services/xxx", slack_channel, slack_text - -' Schedule 30-60-90 day check-ins -check_in_dates = [30, 60, 90] -FOR EACH days IN check_in_dates - check_in_date = DATEADD(start_date, days, "day") - CREATE TASK days + "-day check-in with " + employee_name, manager_email, check_in_date -NEXT days - -' Return success -result_status = "success" -result_employee_id = employee_id -result_tasks_created = 9 -result_message = "Onboarding initiated for " + employee_name -``` - -## 4. Daily Business Intelligence Report - -Automated daily report with AI-generated insights. - -```basic -' daily-report.bas -' Automated daily business intelligence report - -SET SCHEDULE "daily-bi-report", "0 7 * * 1-5" - -today = FORMAT(NOW(), "YYYY-MM-DD") -yesterday = FORMAT(DATEADD(NOW(), -1, "day"), "YYYY-MM-DD") - -' Gather sales data -sales_today = FIND "orders", "DATE(created_at)='" + today + "'" -sales_yesterday = FIND "orders", "DATE(created_at)='" + yesterday + "'" - -total_revenue_today = AGGREGATE "SUM", sales_today, "total" -total_revenue_yesterday = AGGREGATE "SUM", sales_yesterday, "total" -order_count_today = AGGREGATE "COUNT", sales_today, "id" - -revenue_change = ((total_revenue_today - total_revenue_yesterday) / total_revenue_yesterday) * 100 - -' Gather support metrics -tickets_today = FIND "support_tickets", "DATE(created_at)='" + today + "'" -tickets_resolved = FILTER tickets_today, "status=resolved" -avg_resolution_time = AGGREGATE "AVG", tickets_resolved, "resolution_time_hours" - -' Gather inventory alerts -low_stock = FIND "products", "stock < 10" -out_of_stock = FIND "products", "stock = 0" - -' Gather website analytics -SET HEADER "Authorization", "Bearer " + GET BOT MEMORY "analytics_api_key" -analytics = GET "https://api.analytics.com/v1/summary?date=" + today - -' Compile data for AI analysis -report_date = today -sales_revenue = total_revenue_today -sales_orders = order_count_today -sales_change = revenue_change -tickets_opened = UBOUND(tickets_today) -tickets_resolved_count = UBOUND(tickets_resolved) -avg_resolution = avg_resolution_time -low_stock_count = UBOUND(low_stock) -out_of_stock_count = UBOUND(out_of_stock) -visitors = analytics.visitors -page_views = analytics.page_views -bounce_rate = analytics.bounce_rate - -report_data = "Date: " + report_date + ", Revenue: $" + sales_revenue + ", Orders: " + sales_orders + ", Change: " + sales_change + "%, Tickets: " + tickets_opened + " opened, " + tickets_resolved_count + " resolved, Low stock: " + low_stock_count - -' Generate AI insights -SET CONTEXT "You are a business analyst. Analyze this data and provide actionable insights. Be concise and focus on key trends and recommendations." - -analysis_prompt = "Analyze this business data and provide 3-5 key insights:\n\n" + report_data -ai_insights = LLM analysis_prompt - -' Build HTML report -report_title = "Daily Business Report - " + today -generated_at = NOW() - -report_pdf = GENERATE PDF "templates/daily-report.html", report_title, report_data, ai_insights, generated_at, "reports/daily-" + today + ".pdf" - -' Send to executives -executives = ["ceo@company.com", "cfo@company.com", "coo@company.com"] - -FOR EACH exec IN executives - SEND MAIL exec, "Daily Business Report - " + today, "Please find attached today's business intelligence report.\n\n" + ai_insights, report_pdf.url -NEXT exec - -' Post summary to Slack -slack_channel = "#executive-updates" -slack_text = "📊 *Daily Report - " + today + "*\n\n" -slack_text = slack_text + "💰 Revenue: $" + FORMAT(total_revenue_today, "#,##0.00") + " (" + FORMAT(revenue_change, "+0.0") + "%)\n" -slack_text = slack_text + "📦 Orders: " + order_count_today + "\n" -slack_text = slack_text + "🎫 Support Tickets: " + UBOUND(tickets_today) + " opened, " + UBOUND(tickets_resolved) + " resolved\n" -slack_text = slack_text + "⚠️ Low Stock Items: " + UBOUND(low_stock) + "\n\n" -slack_text = slack_text + "*AI Insights:*\n" + ai_insights -POST "https://hooks.slack.com/services/xxx", slack_channel, slack_text - -' Store report in database -report_date = today -pdf_url = report_pdf.url -SAVE "daily_reports", report_date, report_data, ai_insights, pdf_url - -PRINT "Daily report generated and distributed for " + today -``` - -## 5. Multi-Language Customer Survey Tool - -Interactive survey with real-time translation and sentiment analysis. - -```basic -' survey-tool.bas -' Multi-language customer survey with AI analysis - -TALK "Welcome! What language would you prefer? / ¡Bienvenido! ¿Qué idioma prefiere? / Bienvenue! Quelle langue préférez-vous?" - -HEAR language_choice - -' Detect language -SET CONTEXT "Identify the language of this text. Respond with only the language code: en, es, fr, de, pt, or other." -detected_lang = LLM language_choice -detected_lang = TRIM(LCASE(detected_lang)) - -' Set translations -IF detected_lang = "es" THEN - q1 = "¿Cómo calificaría su experiencia general? (1-10)" - q2 = "¿Qué es lo que más le gustó de nuestro servicio?" - q3 = "¿Qué podríamos mejorar?" - q4 = "¿Nos recomendaría a un amigo? (sí/no)" - thank_you = "¡Gracias por sus comentarios!" -ELSE IF detected_lang = "fr" THEN - q1 = "Comment évalueriez-vous votre expérience globale ? (1-10)" - q2 = "Qu'avez-vous le plus apprécié dans notre service ?" - q3 = "Que pourrions-nous améliorer ?" - q4 = "Nous recommanderiez-vous à un ami ? (oui/non)" - thank_you = "Merci pour vos commentaires !" -ELSE - q1 = "How would you rate your overall experience? (1-10)" - q2 = "What did you like most about our service?" - q3 = "What could we improve?" - q4 = "Would you recommend us to a friend? (yes/no)" - thank_you = "Thank you for your feedback!" - detected_lang = "en" -END IF - -' Collect responses -TALK q1 -HEAR rating -IF NOT IS NUMERIC(rating) THEN - rating = 5 -END IF - -TALK q2 -HEAR liked_most - -TALK q3 -HEAR improvements - -TALK q4 -HEAR recommend - -' Translate responses to English for analysis if needed -IF detected_lang <> "en" THEN - SET CONTEXT "Translate the following text to English. Only provide the translation, nothing else." - liked_most_en = LLM liked_most - improvements_en = LLM improvements -ELSE - liked_most_en = liked_most - improvements_en = improvements -END IF - -' Sentiment analysis -SET CONTEXT "Analyze the sentiment of this feedback. Respond with: positive, neutral, or negative." -sentiment = LLM "Liked: " + liked_most_en + ". Improvements: " + improvements_en -sentiment = TRIM(LCASE(sentiment)) - -' NPS calculation -IF INSTR(LCASE(recommend), "yes") > 0 OR INSTR(LCASE(recommend), "sí") > 0 OR INSTR(LCASE(recommend), "oui") > 0 THEN - would_recommend = TRUE - nps_category = "promoter" -ELSE - would_recommend = FALSE - nps_category = "detractor" -END IF - -IF rating >= 9 THEN - nps_category = "promoter" -ELSE IF rating >= 7 THEN - nps_category = "passive" -ELSE - nps_category = "detractor" -END IF - -' Save survey response -survey_language = detected_lang -survey_rating = rating -submitted_at = NOW() - -SAVE "survey_responses", survey_language, survey_rating, liked_most, liked_most_en, improvements, improvements_en, would_recommend, sentiment, nps_category, submitted_at - -' Generate AI summary for low scores -IF rating < 6 THEN - SET CONTEXT "You are a customer experience manager. Summarize this negative feedback and suggest immediate actions." - - alert_summary = LLM "Customer rated us " + rating + "/10. They liked: " + liked_most_en + ". They want us to improve: " + improvements_en - - SEND MAIL "cx-team@company.com", "⚠️ Low Survey Score Alert", "Rating: " + rating + "/10\n\nSummary: " + alert_summary + "\n\nOriginal feedback:\n- Liked: " + liked_most + "\n- Improve: " + improvements -END IF - -TALK thank_you - -' Show aggregated stats -total_responses = AGGREGATE "COUNT", "survey_responses", "id" -avg_rating = AGGREGATE "AVG", "survey_responses", "rating" -promoters = FILTER "survey_responses", "nps_category=promoter" -detractors = FILTER "survey_responses", "nps_category=detractor" -nps_score = ((UBOUND(promoters) - UBOUND(detractors)) / total_responses) * 100 - -PRINT "Survey completed. Total responses: " + total_responses + ", Avg rating: " + FORMAT(avg_rating, "0.0") + ", NPS: " + FORMAT(nps_score, "0") -``` - -## 6. Document Processing Pipeline - -Automated document intake, processing, and classification. - -```basic -' document-pipeline.bas -' Automated document processing and classification - -WEBHOOK "document-upload" - -' Get uploaded document -document_url = body.document_url -document_name = body.filename -uploader_email = body.uploader_email - -IF document_url = "" THEN - WITH result = NEW OBJECT - .status = 400 - .error = "No document URL provided" - END WITH - EXIT -END IF - -' Download document -local_path = DOWNLOAD document_url, "incoming/" + document_name - -' Extract text based on file type -file_extension = LCASE(RIGHT(document_name, 4)) - -IF file_extension = ".pdf" THEN - content = GET local_path -ELSE IF file_extension = "docx" OR file_extension = ".doc" THEN - content = GET local_path -ELSE IF file_extension = ".txt" THEN - content = READ local_path -ELSE - ' Try OCR for images - content = GET local_path -END IF - -' Classify document using AI -SET CONTEXT "You are a document classifier. Classify this document into one of these categories: invoice, contract, report, correspondence, legal, hr, other. Also extract key metadata. Respond in JSON format with fields: category, confidence, key_dates, key_parties, summary." - -classification_prompt = "Classify this document:\n\n" + LEFT(content, 5000) -classification_result = LLM classification_prompt - -' Parse AI response (simplified - in production use proper JSON parsing) -category = "other" -IF INSTR(classification_result, "invoice") > 0 THEN - category = "invoice" -ELSE IF INSTR(classification_result, "contract") > 0 THEN - category = "contract" -ELSE IF INSTR(classification_result, "report") > 0 THEN - category = "report" -ELSE IF INSTR(classification_result, "legal") > 0 THEN - category = "legal" -ELSE IF INSTR(classification_result, "hr") > 0 THEN - category = "hr" -END IF - -' Move to appropriate folder -destination = category + "/" + document_name -MOVE local_path, destination - -' Create searchable index entry -filename = document_name -original_url = document_url -stored_path = destination -content_preview = LEFT(content, 1000) -full_text = content -classification_details = classification_result -uploaded_by = uploader_email -processed_at = NOW() - -doc_id = INSERT "documents", filename, original_url, stored_path, category, content_preview, full_text, classification_details, uploaded_by, processed_at - -' Add to knowledge base for future queries -USE KB category + "-docs" - -' Category-specific processing -SELECT CASE category - CASE "invoice" - ' Extract invoice details - SET CONTEXT "Extract from this invoice: vendor name, invoice number, date, due date, total amount, line items. Respond in JSON." - invoice_data = LLM content - - ' Create payable record - payable_doc_id = doc_id - extracted_data = invoice_data - payable_status = "pending_review" - payable_created_at = NOW() - INSERT "accounts_payable", payable_doc_id, extracted_data, payable_status, payable_created_at - - SEND MAIL "accounting@company.com", "New Invoice for Review", "A new invoice has been uploaded and classified.\n\nDocument: " + document_name + "\nCategory: Invoice\n\nPlease review in the accounting portal." - - CASE "contract" - ' Extract contract details - SET CONTEXT "Extract from this contract: parties involved, effective date, expiration date, key terms, renewal clauses. Respond in JSON." - contract_data = LLM content - - contract_doc_id = doc_id - contract_extracted = contract_data - contract_status = "active" - contract_created_at = NOW() - INSERT "contracts", contract_doc_id, contract_extracted, contract_status, contract_created_at - - SEND MAIL "legal@company.com", "New Contract Uploaded", "A new contract has been processed.\n\nDocument: " + document_name + "\n\nDetails: " + contract_data - - CASE "hr" - SEND MAIL "hr@company.com", "New HR Document", "A new HR document has been uploaded: " + document_name -END SELECT - -' Notify uploader -SEND MAIL uploader_email, "Document Processed: " + document_name, "Your document has been successfully processed.\n\nCategory: " + category + "\nDocument ID: " + doc_id + "\n\nYou can now search for this document in the document portal." - -' Return result -result_status = "processed" -result_doc_id = doc_id -result_category = category -result_path = destination -``` - -## 7. Real-time Data Sync Tool - -Bidirectional sync between systems. - -```basic -' data-sync.bas -' Real-time data synchronization between CRM and ERP - -WEBHOOK "crm-update" - -' Handle CRM webhook -event_type = body.event -record_type = body.record_type -record_id = body.record_id -data = body.data -timestamp = body.timestamp - -' Log sync event -sync_source = "crm" -sync_event = event_type -sync_record_type = record_type -sync_record_id = record_id -sync_timestamp = source_timestamp -received_at = NOW() -INSERT "sync_logs", sync_source, sync_event, sync_record_type, sync_record_id, sync_timestamp, received_at - -' Check for sync conflicts -last_erp_update = FIND "erp_sync_status", "record_id=" + record_id -IF last_erp_update.updated_at > timestamp THEN - ' ERP has newer data - conflict - WITH conflict = NEW OBJECT - .record_id = record_id - .crm_timestamp = timestamp - .erp_timestamp = last_erp_update.updated_at - .crm_data = data - .erp_data = last_erp_update.data - .status = "pending_resolution" - END WITH - INSERT "sync_conflicts", conflict - - SEND MAIL "data-admin@company.com", "Sync Conflict Detected", "Record " + record_id + " has conflicting updates. Please resolve in the admin portal." - - WITH result = NEW OBJECT - .status = "conflict" - .message = "Newer data exists in ERP" - END WITH - EXIT -END IF - -' Transform data for ERP format -SELECT CASE record_type - CASE "customer" - WITH erp_data = NEW OBJECT - .customer_code = record_id - .company_name = data.company - .contact_name = data.contact_first_name + " " + data.contact_last_name - .email = data.email - .phone = data.phone - .billing_address = data.address.street + ", " + data.address.city + ", " + data.address.state + " " + data.address.zip - .credit_limit = data.credit_limit - .payment_terms = data.payment_terms - .updated_at = NOW() - END WITH - - erp_endpoint = "/api/customers/" + record_id - - CASE "order" - WITH erp_data = NEW OBJECT - .order_number = record_id - .customer_code = data.customer_id - .order_date = data.created_at - .ship_date = data.expected_ship_date - .line_items = data.products - .subtotal = data.subtotal - .tax = data.tax - .total = data.total - .status = data.status - END WITH - - erp_endpoint = "/api/orders/" + record_id - - CASE "product" - WITH erp_data = NEW OBJECT - .sku = record_id - .description = data.name - .category = data.category - .unit_price = data.price - .cost = data.cost - .weight = data.weight - .dimensions = data.dimensions - END WITH - - erp_endpoint = "/api/products/" + record_id -END SELECT - -' Send to ERP -erp_api_key = GET BOT MEMORY "erp_api_key" -SET HEADER "Authorization", "Bearer " + erp_api_key -SET HEADER "Content-Type", "application/json" - -IF event_type = "create" THEN - erp_result = POST "https://erp.company.com" + erp_endpoint, erp_data -ELSE IF event_type = "update" THEN - erp_result = PUT "https://erp.company.com" + erp_endpoint, erp_data -ELSE IF event_type = "delete" THEN - erp_result = DELETE "https://erp.company.com" + erp_endpoint -END IF - -' Update sync status -WITH sync_status = NEW OBJECT - .record_id = record_id - .record_type = record_type - .last_crm_update = timestamp - .last_erp_sync = NOW() - .sync_result = erp_result.status - .data = erp_data -END WITH -SAVE "erp_sync_status", record_id, sync_status - -' Update sync log with result -WITH log_update = NEW OBJECT - .sync_completed_at = NOW() - .erp_response = erp_result.status -END WITH -UPDATE "sync_logs", "record_id=" + record_id + " AND source='crm'", log_update - -WITH result = NEW OBJECT - .status = "synced" - .record_id = record_id - .erp_status = erp_result.status -END WITH -``` - -## See Also - -- [Keywords Reference](./keywords.md) - Complete keyword documentation -- [WEBHOOK](./keyword-webhook.md) - Creating API endpoints -- [SET SCHEDULE](./keyword-set-schedule.md) - Scheduled automation -- [Data Operations](./keywords.md#database--data-operations) - Database keywords -- [File Operations](./keywords.md#file--document-operations) - File handling \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-add-bot.md b/docs/src/chapter-06-gbdialog/keyword-add-bot.md deleted file mode 100644 index 11b2a453..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-add-bot.md +++ /dev/null @@ -1,56 +0,0 @@ -# ADD BOT Keywords - -Dynamically add bots to a session with specific triggers, tools, or schedules. - -## Keywords - -| Keyword | Purpose | -|---------|---------| -| `ADD BOT ... WITH TRIGGER` | Add bot activated by keyword | -| `ADD BOT ... WITH TOOLS` | Add bot with specific tools | -| `ADD BOT ... WITH SCHEDULE` | Add bot on a schedule | -| `REMOVE BOT` | Remove bot from session | - -## ADD BOT WITH TRIGGER - -```basic -ADD BOT "sales-bot" WITH TRIGGER "pricing" -``` - -When user mentions "pricing", sales-bot activates. - -## ADD BOT WITH TOOLS - -```basic -ADD BOT "data-bot" WITH TOOLS "database,spreadsheet,charts" -``` - -## ADD BOT WITH SCHEDULE - -```basic -ADD BOT "report-bot" WITH SCHEDULE "0 9 * * MON" -``` - -Adds bot that runs every Monday at 9 AM (cron format). - -## REMOVE BOT - -```basic -REMOVE BOT "sales-bot" -``` - -## Example: Multi-Bot Setup - -```basic -' Set up specialized bots for different topics -ADD BOT "orders-bot" WITH TRIGGER "order status, shipping, delivery" -ADD BOT "support-bot" WITH TRIGGER "help, problem, issue, broken" -ADD BOT "sales-bot" WITH TRIGGER "pricing, quote, purchase" - -TALK "I've set up our specialist team. Just ask about orders, support, or sales!" -``` - -## See Also - -- [A2A Protocol](./keyword-a2a.md) -- [DELEGATE TO BOT](./keyword-delegate-to-bot.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-add-member.md b/docs/src/chapter-06-gbdialog/keyword-add-member.md deleted file mode 100644 index 197a903d..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-add-member.md +++ /dev/null @@ -1,68 +0,0 @@ -# ADD MEMBER Keywords - -Manage team and group membership within bots. - -## Keywords - -| Keyword | Purpose | -|---------|---------| -| `ADD_MEMBER` | Add user to a group with role | -| `REMOVE_MEMBER` | Remove user from group | -| `CREATE_TEAM` | Create a new team | -| `LIST_MEMBERS` | List group members | - -## ADD_MEMBER - -```basic -result = ADD_MEMBER group_id, user_email, role -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `group_id` | String | Team or group identifier | -| `user_email` | String | Email of user to add | -| `role` | String | Role: "admin", "member", "viewer" | - -### Example - -```basic -result = ADD_MEMBER "team-sales", "john@company.com", "member" -TALK "Added user: " + result -``` - -## REMOVE_MEMBER - -```basic -result = REMOVE_MEMBER "team-sales", "john@company.com" -``` - -## CREATE_TEAM - -```basic -members = ["alice@company.com", "bob@company.com"] -result = CREATE_TEAM "Project Alpha", "Development team", members -``` - -## LIST_MEMBERS - -```basic -members = LIST_MEMBERS "team-sales" -FOR EACH member IN members - TALK member.email + " - " + member.role -NEXT -``` - -## Roles - -| Role | Permissions | -|------|-------------| -| `admin` | Full control, manage members | -| `member` | Standard access | -| `viewer` | Read-only access | - -## See Also - -- [ADD BOT](./keyword-add-bot.md) -- [User Session Handling](../chapter-10-features/user-sessions.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-add-suggestion.md b/docs/src/chapter-06-gbdialog/keyword-add-suggestion.md deleted file mode 100644 index f70310f3..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-add-suggestion.md +++ /dev/null @@ -1,82 +0,0 @@ -# ADD SUGGESTION / CLEAR SUGGESTIONS Keywords - -Display quick-reply suggestion buttons to users during conversations. - -## Keywords - -| Keyword | Purpose | -|---------|---------| -| `ADD SUGGESTION` | Add a suggestion button | -| `CLEAR SUGGESTIONS` | Remove all suggestions | - -## ADD SUGGESTION - -```basic -ADD SUGGESTION "Yes" -ADD SUGGESTION "No" -ADD SUGGESTION "Maybe later" -``` - -With action data: - -```basic -ADD SUGGESTION "View Order", "action:view_order" -ADD SUGGESTION "Track Package", "action:track" -``` - -## CLEAR SUGGESTIONS - -```basic -CLEAR SUGGESTIONS -``` - -## Example: Product Selection - -```basic -TALK "What type of product are you interested in?" - -ADD SUGGESTION "Electronics" -ADD SUGGESTION "Clothing" -ADD SUGGESTION "Home & Garden" -ADD SUGGESTION "Books" - -HEAR choice -CLEAR SUGGESTIONS - -TALK "Great! Let me show you our " + choice + " collection." -``` - -## Example: Confirmation Flow - -```basic -TALK "Your order total is $99.00. Would you like to proceed?" - -ADD SUGGESTION "Confirm Order" -ADD SUGGESTION "Modify Cart" -ADD SUGGESTION "Cancel" - -HEAR response -CLEAR SUGGESTIONS -``` - -## Behavior - -- Suggestions appear as clickable buttons in supported channels -- Clicking a suggestion sends its text as user input -- Suggestions persist until cleared or new ones are added -- Maximum suggestions varies by channel (typically 3-10) - -## Channel Support - -| Channel | Supported | Max Buttons | -|---------|-----------|-------------| -| WhatsApp | ✅ | 3 | -| Telegram | ✅ | 8 | -| Web Chat | ✅ | 10 | -| SMS | ❌ | N/A | - -## See Also - -- [TALK](./keyword-talk.md) -- [HEAR](./keyword-hear.md) -- [CARD](./keyword-card.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-aggregate.md b/docs/src/chapter-06-gbdialog/keyword-aggregate.md deleted file mode 100644 index 814eb887..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-aggregate.md +++ /dev/null @@ -1 +0,0 @@ -# AGGREGATE diff --git a/docs/src/chapter-06-gbdialog/keyword-book.md b/docs/src/chapter-06-gbdialog/keyword-book.md deleted file mode 100644 index 1ebad831..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-book.md +++ /dev/null @@ -1,305 +0,0 @@ -# BOOK / BOOK_MEETING / CHECK_AVAILABILITY Keywords - -The `BOOK` family of keywords provides calendar and scheduling functionality, allowing bots to create appointments, schedule meetings with attendees, and check availability. - -## Keywords Overview - -| Keyword | Purpose | -|---------|---------| -| `BOOK` | Create a simple calendar appointment | -| `BOOK_MEETING` | Schedule a meeting with multiple attendees | -| `CHECK_AVAILABILITY` | Find available time slots | - -## BOOK - -Creates a calendar appointment for the current user. - -### Syntax - -```basic -result = BOOK title, description, start_time, duration_minutes, location -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `title` | String | Title/subject of the appointment | -| `description` | String | Detailed description of the appointment | -| `start_time` | String | When the appointment starts (see Time Formats) | -| `duration_minutes` | Integer | Duration in minutes (default: 30) | -| `location` | String | Location or meeting room | - -### Example - -```basic -' Book a dentist appointment -result = BOOK "Dentist Appointment", "Annual checkup", "2024-03-15 14:00", 60, "123 Medical Center" -TALK "Your appointment has been booked: " + result - -' Book a quick meeting -result = BOOK "Team Sync", "Weekly standup", "tomorrow 10:00", 30, "Conference Room A" -``` - -## BOOK_MEETING - -Schedules a meeting with multiple attendees, sending calendar invites. - -### Syntax - -```basic -result = BOOK_MEETING meeting_details, attendees -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `meeting_details` | JSON String | Meeting configuration object | -| `attendees` | Array | List of attendee email addresses | - -### Meeting Details Object - -```json -{ - "title": "Meeting Title", - "description": "Meeting description", - "start_time": "2024-03-15 14:00", - "duration": 60, - "location": "Conference Room B", - "reminder_minutes": 15, - "recurrence": "weekly" -} -``` - -### Example - -```basic -' Schedule a team meeting -meeting = '{ - "title": "Sprint Planning", - "description": "Plan next sprint tasks and priorities", - "start_time": "Monday 09:00", - "duration": 90, - "location": "Main Conference Room", - "reminder_minutes": 30 -}' - -attendees = ["alice@company.com", "bob@company.com", "carol@company.com"] - -result = BOOK_MEETING meeting, attendees -TALK "Meeting scheduled with " + LEN(attendees) + " attendees" -``` - -## CHECK_AVAILABILITY - -Finds available time slots for a given date and duration. - -### Syntax - -```basic -available_slots = CHECK_AVAILABILITY date, duration_minutes -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `date` | String | The date to check availability | -| `duration_minutes` | Integer | Required duration for the meeting | - -### Example - -```basic -' Check availability for a 1-hour meeting tomorrow -slots = CHECK_AVAILABILITY "tomorrow", 60 - -TALK "Available time slots:" -FOR EACH slot IN slots - TALK " - " + slot -NEXT -``` - -## Time Formats - -The BOOK keywords support flexible time formats: - -### Absolute Formats - -| Format | Example | -|--------|---------| -| ISO 8601 | `"2024-03-15T14:00:00"` | -| Date + Time | `"2024-03-15 14:00"` | -| Date + Time (12h) | `"2024-03-15 2:00 PM"` | - -### Relative Formats - -| Format | Example | -|--------|---------| -| Day name | `"Monday 10:00"` | -| Relative day | `"tomorrow 14:00"` | -| Next week | `"next Tuesday 09:00"` | - -## Complete Example: Appointment Scheduling Bot - -```basic -' appointment-bot.bas -' A complete appointment scheduling workflow - -TALK "Welcome to our scheduling assistant!" -TALK "What type of appointment would you like to book?" - -HEAR appointment_type - -SWITCH appointment_type - CASE "consultation" - duration = 60 - description = "Initial consultation meeting" - CASE "follow-up" - duration = 30 - description = "Follow-up discussion" - CASE "review" - duration = 45 - description = "Project review session" - DEFAULT - duration = 30 - description = appointment_type -END SWITCH - -TALK "When would you like to schedule this?" -HEAR preferred_date - -' Check available slots -slots = CHECK_AVAILABILITY preferred_date, duration - -IF LEN(slots) = 0 THEN - TALK "Sorry, no availability on that date. Please try another day." -ELSE - TALK "Available times:" - index = 1 - FOR EACH slot IN slots - TALK index + ". " + slot - index = index + 1 - NEXT - - TALK "Which time slot would you prefer? (enter number)" - HEAR choice - - selected_time = slots[choice - 1] - - TALK "Where would you like the meeting to take place?" - HEAR location - - ' Book the appointment - result = BOOK appointment_type, description, selected_time, duration, location - - TALK "✅ Your appointment has been booked!" - TALK "Details: " + result -END IF -``` - -## Meeting with Recurrence - -```basic -' Schedule a recurring weekly meeting -meeting = '{ - "title": "Weekly Team Standup", - "description": "Daily sync on project progress", - "start_time": "Monday 09:00", - "duration": 15, - "location": "Virtual - Teams", - "reminder_minutes": 5, - "recurrence": { - "frequency": "weekly", - "interval": 1, - "count": 12, - "by_day": ["MO", "WE", "FR"] - } -}' - -attendees = ["team@company.com"] -result = BOOK_MEETING meeting, attendees -``` - -## Event Status - -Calendar events can have the following statuses: - -| Status | Description | -|--------|-------------| -| `Confirmed` | Event is confirmed and scheduled | -| `Tentative` | Event is tentatively scheduled | -| `Cancelled` | Event has been cancelled | - -## Calendar Event Structure - -When an event is created, it contains: - -```json -{ - "id": "uuid", - "title": "Meeting Title", - "description": "Description", - "start_time": "2024-03-15T14:00:00Z", - "end_time": "2024-03-15T15:00:00Z", - "location": "Conference Room", - "organizer": "user@example.com", - "attendees": ["attendee1@example.com"], - "reminder_minutes": 15, - "recurrence_rule": null, - "status": "Confirmed", - "created_at": "2024-03-10T10:00:00Z", - "updated_at": "2024-03-10T10:00:00Z" -} -``` - -## Configuration - -To enable calendar functionality, configure the following in `config.csv`: - -| Key | Description | -|-----|-------------| -| `calendar-provider` | Calendar service (google, outlook, caldav) | -| `calendar-client-id` | OAuth client ID | -| `calendar-client-secret` | OAuth client secret | -| `calendar-default-reminder` | Default reminder time in minutes | - -## Error Handling - -```basic -' Handle booking errors gracefully -ON ERROR GOTO handle_error - -result = BOOK "Meeting", "Description", "invalid-date", 30, "Location" -TALK "Booked: " + result -END - -handle_error: - TALK "Sorry, I couldn't book that appointment. Please check the date and time format." - TALK "Error: " + ERROR_MESSAGE -END -``` - -## Best Practices - -1. **Always check availability first**: Before booking, use `CHECK_AVAILABILITY` to ensure the time slot is free. - -2. **Use descriptive titles**: Make appointment titles clear and searchable. - -3. **Set appropriate reminders**: Configure reminder times based on appointment importance. - -4. **Handle time zones**: Be explicit about time zones when scheduling across regions. - -5. **Validate inputs**: Check user-provided dates and times before attempting to book. - -## Related Keywords - -- [SET SCHEDULE](./keyword-set-schedule.md) - Schedule recurring bot tasks -- [WAIT](./keyword-wait.md) - Pause execution for a duration -- [SEND MAIL](./keyword-send-mail.md) - Send meeting confirmations via email - -## See Also - -- [Calendar Integration](../appendix-external-services/calendar.md) -- [Google Calendar Setup](../appendix-external-services/google-calendar.md) -- [Microsoft Outlook Integration](../appendix-external-services/outlook.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-bot-reflection.md b/docs/src/chapter-06-gbdialog/keyword-bot-reflection.md deleted file mode 100644 index e3b1be95..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-bot-reflection.md +++ /dev/null @@ -1,240 +0,0 @@ -# BOT REFLECTION - -Enables agent self-analysis and improvement by using LLM to evaluate conversation quality, identify issues, and suggest improvements. This is a key feature for continuous agent optimization. - -## Syntax - -```basic -BOT REFLECTION enabled -BOT REFLECTION ON "metric" -insights = BOT REFLECTION INSIGHTS() -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `enabled` | Boolean | `true` to enable, `false` to disable reflection | -| `metric` | String | Specific metric to analyze (e.g., "conversation_quality", "response_accuracy") | - -## Description - -`BOT REFLECTION` activates the agent self-improvement system, which periodically analyzes conversations and provides actionable insights. When enabled, the system: - -- **Analyzes conversation quality** - Tone, clarity, helpfulness -- **Identifies issues** - Misunderstandings, incomplete answers, user frustration -- **Suggests improvements** - Better responses, missing information, tone adjustments -- **Tracks metrics over time** - Quality scores, resolution rates - -This creates a continuous improvement loop where agents learn from their interactions. - -## Examples - -### Enable Basic Reflection - -```basic -' Enable reflection for this bot session -BOT REFLECTION true - -' Normal conversation proceeds -TALK "Hello! How can I help you today?" -HEAR userquery -response = LLM userquery -TALK response - -' Reflection runs automatically in background -``` - -### Monitor Specific Metrics - -```basic -' Enable reflection on conversation quality -BOT REFLECTION ON "conversation_quality" - -' Enable reflection on response accuracy -BOT REFLECTION ON "response_accuracy" - -' Enable reflection on user satisfaction -BOT REFLECTION ON "user_satisfaction" -``` - -### Retrieve Reflection Insights - -```basic -' Get insights from reflection analysis -insights = BOT REFLECTION INSIGHTS() - -IF insights <> "" THEN - PRINT "Reflection Insights:" - PRINT insights.summary - PRINT "Quality Score: " + insights.qualityScore - PRINT "Issues Found: " + insights.issuesCount - - FOR EACH suggestion IN insights.suggestions - PRINT "Suggestion: " + suggestion - NEXT suggestion -END IF -``` - -### Use Insights for Self-Improvement - -```basic -' Periodic reflection check -BOT REFLECTION true - -' After conversation ends, check insights -insights = BOT REFLECTION INSIGHTS() - -IF insights.qualityScore < 0.7 THEN - ' Log for review - PRINT "Low quality conversation detected" - PRINT "Issues: " + insights.issues - - ' Store for analysis - SET BOT MEMORY "reflection_" + conversationid, insights -END IF -``` - -### Admin Dashboard Integration - -```basic -' Script for admin to review bot performance -insights = BOT REFLECTION INSIGHTS() - -BEGIN TALK -**Bot Performance Report** - -📊 **Quality Score:** {insights.qualityScore}/1.0 - -📈 **Metrics:** -- Response Accuracy: {insights.responseAccuracy}% -- User Satisfaction: {insights.userSatisfaction}% -- Resolution Rate: {insights.resolutionRate}% - -⚠️ **Issues Identified:** -{insights.issues} - -💡 **Improvement Suggestions:** -{insights.suggestions} -END TALK -``` - -### Conditional Reflection - -```basic -' Only reflect on complex conversations -messageCount = GET BOT MEMORY("messageCount") - -IF messageCount > 5 THEN - ' Enable reflection for longer conversations - BOT REFLECTION true - BOT REFLECTION ON "conversation_quality" -END IF -``` - -### Reflection with Alerts - -```basic -' Enable reflection with alerting -BOT REFLECTION true - -' Check for critical issues periodically -insights = BOT REFLECTION INSIGHTS() - -IF insights.criticalIssues > 0 THEN - ' Alert admin - SEND MAIL admin, "Bot Alert: Critical Issues Detected", insights.summary -END IF -``` - -## Reflection Metrics - -| Metric | Description | Score Range | -|--------|-------------|-------------| -| `conversation_quality` | Overall conversation effectiveness | 0.0 - 1.0 | -| `response_accuracy` | How accurate/correct responses are | 0.0 - 1.0 | -| `user_satisfaction` | Estimated user satisfaction | 0.0 - 1.0 | -| `tone_appropriateness` | Whether tone matches context | 0.0 - 1.0 | -| `resolution_rate` | Whether user issues were resolved | 0.0 - 1.0 | -| `response_time` | Average response latency | milliseconds | - -## Insights Object Structure - -```basic -insights = BOT REFLECTION INSIGHTS() - -' Available properties: -insights.qualityScore ' Overall quality (0-1) -insights.summary ' Text summary of analysis -insights.issues ' Array of identified issues -insights.issuesCount ' Number of issues found -insights.suggestions ' Array of improvement suggestions -insights.metrics ' Object with detailed metrics -insights.criticalIssues ' Count of critical problems -insights.conversationId ' ID of analyzed conversation -insights.timestamp ' When analysis was performed -``` - -## Config.csv Options - -```csv -name,value -reflection-enabled,true -reflection-interval,10 -reflection-min-messages,3 -reflection-model,quality -reflection-store-insights,true -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `reflection-enabled` | `true` | Enable/disable reflection globally | -| `reflection-interval` | `10` | Messages between reflection runs | -| `reflection-min-messages` | `3` | Minimum messages before reflecting | -| `reflection-model` | `quality` | LLM model for reflection analysis | -| `reflection-store-insights` | `true` | Store insights in database | - -## How Reflection Works - -1. **Collection** - Conversation history is collected -2. **Analysis** - LLM analyzes the conversation against metrics -3. **Scoring** - Quality scores are calculated -4. **Identification** - Issues and patterns are identified -5. **Suggestion** - Improvement suggestions are generated -6. **Storage** - Results stored for dashboards and trends - -## Related Keywords - -| Keyword | Description | -|---------|-------------| -| [`LLM`](./keyword-llm.md) | Query the language model | -| [`SET BOT MEMORY`](./keyword-set-bot-memory.md) | Store bot-level data | -| [`PRINT`](./keyword-print.md) | Debug output | - -## Performance Considerations - -- Reflection uses LLM calls (affects cost/latency) -- Run reflection periodically, not on every message -- Use smaller models for reflection when possible -- Consider async reflection for production - -## Best Practices - -1. **Enable for complex bots** - Most valuable for customer-facing agents -2. **Review insights regularly** - Use dashboards to spot trends -3. **Act on suggestions** - Update prompts and tools based on insights -4. **Set appropriate intervals** - Balance insight freshness vs cost -5. **Store for analysis** - Track improvements over time - -## Limitations - -- Reflection adds LLM cost per analysis -- Analysis quality depends on model capability -- Cannot analyze real-time user emotions -- Historical only (not predictive) - -## See Also - -- [Multi-Agent Orchestration](../chapter-11-features/multi-agent-orchestration.md) - Multi-agent systems -- [Observability](../chapter-11-features/observability.md) - Monitoring and metrics -- [LLM Configuration](../chapter-08-config/llm-config.md) - Model setup \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-card.md b/docs/src/chapter-06-gbdialog/keyword-card.md deleted file mode 100644 index 60235004..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-card.md +++ /dev/null @@ -1,200 +0,0 @@ -# CARD - -Creates beautiful Instagram-style social media posts by combining AI-generated images with optimized text overlays. - -## Syntax - -```basic -CARD image_prompt, text_prompt TO variable -CARD image_prompt, text_prompt, style TO variable -CARD image_prompt, text_prompt, style, count TO variable -``` - -## Parameters - -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| `image_prompt` | String | Yes | Description of the image to generate | -| `text_prompt` | String | Yes | Theme or topic for the text overlay | -| `style` | String | No | Visual style preset (default: "modern") | -| `count` | Number | No | Number of cards to generate (default: 1, max: 10) | - -## Available Styles - -| Style | Description | -|-------|-------------| -| `modern` | Trendy Instagram aesthetic with clean design | -| `minimal` | Simple composition with negative space, muted colors | -| `vibrant` | Bold colors, high saturation, energetic feel | -| `dark` | Moody atmosphere with dramatic lighting | -| `light` | Bright, airy, soft pastel colors | -| `gradient` | Smooth color gradients, abstract backgrounds | -| `polaroid` | Vintage style with warm, nostalgic tones | -| `magazine` | Editorial, high-fashion professional look | -| `story` | Optimized for Instagram Stories (9:16 ratio) | -| `carousel` | Consistent style for multi-image posts | - -## Return Value - -Returns an object (or array of objects when count > 1) containing: - -```json -{ - "image_path": "/path/to/generated/card.png", - "image_url": "https://storage.example.com/card.png", - "text_content": "The generated overlay text", - "hashtags": ["#nature", "#inspiration", "#photography"], - "caption": "A ready-to-use caption for the post", - "style": "modern", - "dimensions": [1080, 1080] -} -``` - -## Examples - -### Basic Usage - -```basic -REM Generate a single motivational post -CARD "sunrise over calm ocean", "morning motivation" TO post - -TALK "Your post is ready!" -TALK "Caption: " + post.caption -TALK "Hashtags: " + JOIN(post.hashtags, " ") -``` - -### With Style Selection - -```basic -REM Create a minimalist product showcase -CARD "elegant watch on marble surface", "luxury timepiece", "minimal" TO watch_post - -REM Create an energetic fitness post -CARD "person running at sunset", "fitness motivation", "vibrant" TO fitness_post -``` - -### Carousel Generation - -```basic -REM Generate 5 cards for a carousel post about healthy eating -CARD "colorful healthy meals", "nutrition tips", "modern", 5 TO carousel - -FOR EACH card IN carousel - TALK "Card " + index + ": " + card.text_content - UPLOAD card.image_path TO "instagram/carousel/" -NEXT -``` - -### Story Format - -```basic -REM Create Instagram Story content -CARD "coffee shop interior", "monday vibes", "story" TO story_post - -TALK "Story dimensions: " + story_post.dimensions[0] + "x" + story_post.dimensions[1] -``` - -## Sample Conversation - -
-
-
Create an Instagram post about our new summer collection
-
- -
-
I'll create a beautiful post for your summer collection! Let me generate that for you...
-
- -
-
-✨ Your Instagram post is ready! - -**Text Overlay:** "Summer Vibes Only" - -**Caption:** Embrace the warmth of the season with our stunning new summer collection. ☀️ - -**Hashtags:** #SummerCollection #FashionVibes #SummerStyle #NewArrivals #SummerFashion #OOTD #StyleInspo - -**Image:** A vibrant beach scene with flowing summer dresses - -Would you like me to create more variations or adjust the style? -
-
- -
-
Yes, make 3 more with a minimal style for a carousel
-
- -
-
-Perfect! I've created 3 additional cards with a minimal aesthetic: - -📸 **Card 1:** "Less is More" - Clean white background with single garment -📸 **Card 2:** "Effortless Style" - Soft neutral tones -📸 **Card 3:** "Simply Summer" - Minimal composition with plant accents - -All 4 images are now ready for your carousel post. The consistent minimal style will create a cohesive feed aesthetic. - -Shall I upload them to your drafts? -
-
-
- -## Implementation Details - -The CARD keyword performs the following steps: - -1. **Text Generation**: Uses LLM to create optimized overlay text based on the prompt -2. **Image Generation**: Creates the base image using AI image generation -3. **Style Application**: Applies color filters and effects based on the selected style -4. **Text Overlay**: Adds the generated text with proper positioning and shadows -5. **Social Content**: Generates relevant hashtags and a ready-to-use caption - -## Image Dimensions - -| Format | Dimensions | Use Case | -|--------|------------|----------| -| Square | 1080 × 1080 | Feed posts | -| Portrait | 1080 × 1350 | Feed posts (more visibility) | -| Story | 1080 × 1920 | Stories and Reels | -| Landscape | 1080 × 566 | Link previews | - -## Best Practices - -1. **Be Specific with Image Prompts**: "golden retriever playing in autumn leaves" works better than just "dog" - -2. **Keep Text Prompts Thematic**: Focus on the message, not the exact words - the LLM will optimize - -3. **Match Style to Brand**: Use consistent styles across posts for brand recognition - -4. **Use Carousel for Stories**: Generate multiple related cards to create engaging carousel posts - -5. **Review Hashtags**: The generated hashtags are suggestions - customize for your audience - -## Error Handling - -```basic -TRY - CARD "abstract art", "creativity unleashed", "vibrant" TO art_post - - IF art_post.image_path = "" THEN - TALK "Image generation failed, please try again" - ELSE - TALK "Post created successfully!" - END IF -CATCH error - TALK "Error creating card: " + error.message -END TRY -``` - -## Related Keywords - -- [GENERATE IMAGE](./keyword-generate-image.md) - Generate images without text overlay -- [UPLOAD](./keyword-upload.md) - Upload generated cards to storage -- [POST TO SOCIAL](./keyword-post-to-social.md) - Publish directly to social media -- [CREATE DRAFT](./keyword-create-draft.md) - Save as draft for review - -## See Also - -- [Social Media Keywords](./keywords-social-media.md) -- [Image Processing](./keywords-image-processing.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-clear-kb.md b/docs/src/chapter-06-gbdialog/keyword-clear-kb.md deleted file mode 100644 index 10d98af3..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-clear-kb.md +++ /dev/null @@ -1,83 +0,0 @@ -# CLEAR KB - -Remove knowledge bases from the current session. - -## Syntax - -```basic -CLEAR KB "collection_name" ' Remove specific collection -CLEAR KB ALL ' Remove all collections -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `collection_name` | String | Name of KB to remove (optional) | -| `ALL` | Keyword | Removes all active KBs | - -## Description - -`CLEAR KB` removes previously loaded knowledge bases from the session's context. This frees memory and ensures subsequent queries don't search unwanted collections. - -## Examples - -### Clear Specific KB - -```basic -USE KB "policies" -USE KB "products" - -' Later, remove just policies -CLEAR KB "policies" -' Only products remains active -``` - -### Clear All KBs - -```basic -USE KB "hr-docs" -USE KB "it-docs" -USE KB "finance" - -CLEAR KB ALL -' All collections removed -``` - -### Context Switching - -```basic -' Support flow -USE KB "troubleshooting" -USE KB "known-issues" -' ... handle support ... - -' Switch to sales -CLEAR KB ALL -USE KB "products" -USE KB "pricing" -``` - -## Return Value - -Returns `true` if cleared successfully, `false` if KB wasn't loaded. - -## Best Practices - -| Do | Don't | -|----|-------| -| Clear when switching topics | Leave large KBs active unnecessarily | -| Clear before loading new context | Assume collections auto-clear | -| Use `ALL` for clean slate | Clear one-by-one when `ALL` works | - -## Session Scope - -- Only affects current session -- Other sessions keep their KBs -- KBs remain in database for future use -- Can reload cleared KBs anytime - -## See Also - -- [USE KB](./keyword-use-kb.md) - Load knowledge bases -- [Knowledge Base System](../chapter-03/README.md) - Technical details \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-clear-tools.md b/docs/src/chapter-06-gbdialog/keyword-clear-tools.md deleted file mode 100644 index ce3241a2..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-clear-tools.md +++ /dev/null @@ -1,26 +0,0 @@ -# CLEAR TOOLS Keyword - -**Syntax** - -``` -CLEAR TOOLS -``` - -**Parameters** - -_None_ – This keyword takes no arguments. - -**Description** - -`CLEAR TOOLS` removes every tool that has been added to the current conversation session. It clears the list of active tools stored in the session‑tool association table, effectively resetting the tool environment for the dialog. After execution, no previously added tools (via `USE TOOL`) remain available. - -**Example** - -```basic -USE TOOL "enrollment.bas" -TALK "Enrollment tool added." -CLEAR TOOLS -TALK "All tools have been cleared from this conversation." -``` - -After `CLEAR TOOLS` runs, the `enrollment.bas` tool is no longer accessible in the same session. diff --git a/docs/src/chapter-06-gbdialog/keyword-compress.md b/docs/src/chapter-06-gbdialog/keyword-compress.md deleted file mode 100644 index 2f435062..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-compress.md +++ /dev/null @@ -1 +0,0 @@ -# COMPRESS diff --git a/docs/src/chapter-06-gbdialog/keyword-copy.md b/docs/src/chapter-06-gbdialog/keyword-copy.md deleted file mode 100644 index 982dad11..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-copy.md +++ /dev/null @@ -1 +0,0 @@ -# COPY diff --git a/docs/src/chapter-06-gbdialog/keyword-create-draft.md b/docs/src/chapter-06-gbdialog/keyword-create-draft.md deleted file mode 100644 index 8ad7bb83..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-create-draft.md +++ /dev/null @@ -1,26 +0,0 @@ -# CREATE DRAFT Keyword - -**Syntax** - -``` -CREATE DRAFT "to-address", "subject", "reply-text" -``` - -**Parameters** - -- `"to-address"` – Email address of the recipient. -- `"subject"` – Subject line for the draft email. -- `"reply-text"` – Body content for the draft. If a previous email exists in the user's mailbox to the same address, its content is appended after a separator. - -**Description** - -`CREATE DRAFT` composes an email draft and saves it to the user's mailbox. It first checks whether a prior email has been sent to the same recipient using the `GET_LATEST_SENT_TO` helper. If such an email exists, its body (converted to HTML line breaks) is appended to the new reply text, separated by `


`. The combined content is then stored as a draft via the email service configured in the application (`save_email_draft`). The keyword returns a success message or an error string. - -**Example** - -```basic -CREATE DRAFT "john.doe@example.com", "Project Update", "Here is the latest status..." -TALK "Draft created and saved." -``` - -If an earlier email to `john.doe@example.com` exists, the draft will contain the new reply followed by the previous email content, allowing the user to continue the conversation seamlessly. diff --git a/docs/src/chapter-06-gbdialog/keyword-create-site.md b/docs/src/chapter-06-gbdialog/keyword-create-site.md deleted file mode 100644 index ecd59c60..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-create-site.md +++ /dev/null @@ -1,34 +0,0 @@ -# CREATE SITE Keyword - -**Syntax** - -``` -CREATE SITE "alias", "template-dir", "prompt" -``` - -**Parameters** - -- `"alias"` – Name of the new site (used as a folder name under the configured site path). -- `"template-dir"` – Relative path to a directory containing HTML template files that will be combined. -- `"prompt"` – Text prompt sent to the LLM to generate the final site content. - -**Description** - -`CREATE SITE` generates a new static website based on existing HTML templates and an LLM‑generated prompt. The keyword performs the following steps: - -1. Creates a directory for the new site at `/`. -2. Reads all `.html` files from `/` and concatenates their contents, separating each with a clear delimiter. -3. Constructs a prompt that includes the combined template content and the user‑provided `prompt`. -4. Sends the prompt to the configured LLM provider (`utils::call_llm`) and receives generated HTML. -5. Writes the LLM output to `//index.html`. - -The resulting site can be served directly from the `site_path` directory. Errors during directory creation, file reading, or LLM generation are logged and returned as error messages. - -**Example** - -```basic -CREATE SITE "my_blog", "templates/blog", "Generate a modern blog homepage for a tech writer." -TALK "Site created at /my_blog. Access it via the web server." -``` - -After execution, a folder `my_blog` is created with an `index.html` containing the LLM‑generated page, ready to be served. diff --git a/docs/src/chapter-06-gbdialog/keyword-create-task.md b/docs/src/chapter-06-gbdialog/keyword-create-task.md deleted file mode 100644 index 7a5b1b49..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-create-task.md +++ /dev/null @@ -1,146 +0,0 @@ -# CREATE TASK - -Create and assign tasks within the task management system. - -## Syntax - -```basic -CREATE TASK title, description, assignee, due_date, priority -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `title` | String | Task title/name | -| `description` | String | Detailed task description | -| `assignee` | String | Email or user ID of the assignee | -| `due_date` | String | Due date in format "YYYY-MM-DD" or relative like "tomorrow", "next week" | -| `priority` | String | Task priority: "low", "medium", "high", "urgent" | - -## Description - -The `CREATE TASK` keyword creates tasks in the task engine system with automatic assignment to users or groups, due date tracking and reminders, priority-based organization, integration with the calendar system, email notifications to assignees, and progress tracking capabilities. - -## Examples - -### Basic Task Creation - -```basic -CREATE TASK "Review proposal", "Review and provide feedback on Q4 proposal", "john@example.com", "2024-01-15", "high" -``` - -### Task with Current User - -```basic -user_email = GET "user.email" -CREATE TASK "Follow up", "Contact customer about renewal", user_email, "tomorrow", "medium" -``` - -### Bulk Task Creation - -```basic -team = ["alice@example.com", "bob@example.com", "carol@example.com"] -FOR EACH member IN team - CREATE TASK "Complete training", "Finish security awareness training", member, "next week", "medium" -NEXT -``` - -### Task from User Input - -```basic -task_info = HEAR "What task should I create?" -CREATE TASK task_info, "User requested task", "support@example.com", "today", "high" -TALK "Task created and assigned to support team" -``` - -## Return Value - -The keyword returns a task object containing the `task_id` as a unique task identifier, `status` indicating the task state (such as "created", "assigned", "in_progress", or "completed"), `created_at` with the creation timestamp, `url` providing a link to the task in the web interface, and `reminder_set` indicating whether a reminder was configured. - -## Task Statuses - -Tasks progress through a defined lifecycle. The `created` status indicates initial creation, followed by `assigned` when the task has been assigned to a user. Once work begins, the status changes to `in_progress`. If the task is waiting on a dependency, it enters the `blocked` state. When finished, it reaches `completed`, or alternatively `cancelled` if the task was terminated without completion. - -## Integration Points - -### Calendar Integration - -Tasks automatically appear in the assignee's calendar when a due date is specified, calendar integration is enabled, and the user has calendar permissions. - -### Email Notifications - -The system sends notifications for task assignment, due date reminders, status changes, and when comments are added. - -### Task Dependencies - -Tasks can be linked together to create parent-child relationships: - -```basic -parent_task = CREATE TASK "Project", "Main project", "pm@example.com", "next month", "high" -subtask = CREATE TASK "Research", "Initial research", "analyst@example.com", "next week", "medium" -LINK_TASKS parent_task.task_id, subtask.task_id -``` - -## Priority Levels - -| Priority | Description | SLA | -|----------|-------------|-----| -| `urgent` | Immediate attention required | 4 hours | -| `high` | Important, time-sensitive | 1 day | -| `medium` | Standard priority | 3 days | -| `low` | Non-urgent | 1 week | - -## Date Formats - -The keyword supports multiple date formats. Absolute dates can be specified as "2024-01-15" or "01/15/2024". Relative dates include "today", "tomorrow", "next week", and "in 3 days". Natural language formats like "Monday", "next Friday", and "end of month" are also supported. - -## Error Handling - -The keyword validates that the assignee exists in the system, checks that the date is in the future, verifies the priority is valid, returns an error if task creation fails, and handles permission issues gracefully. - -## Permissions - -To create tasks, the user must have task creation permission, project member status, admin privileges, or delegation rights from the assignee. - -## Best Practices - -Use clear, action-oriented titles that describe what needs to be done. Include detailed descriptions with acceptance criteria so the assignee understands the requirements. Set realistic deadlines that can actually be achieved. Reserve high and urgent priorities for tasks that truly warrant them rather than marking everything as urgent. Verify the assignee can handle the task before assignment. Follow up periodically to check task status and provide assistance if needed. - -## Advanced Usage - -### Task Templates - -```basic -template = GET_TASK_TEMPLATE("customer_onboarding") -CREATE TASK template.title, template.description, assigned_user, due_date, template.priority -``` - -### Conditional Creation - -```basic -IF urgency = "high" AND department = "support" THEN - CREATE TASK "Urgent Support", issue_description, "support-lead@example.com", "today", "urgent" -ELSE - CREATE TASK "Support Request", issue_description, "support@example.com", "tomorrow", "medium" -END IF -``` - -### Task with Attachments - -```basic -task = CREATE TASK "Review document", "Please review attached", reviewer, deadline, "high" -' Note: Use document sharing systems for attachments -``` - -## Related Keywords - -The [BOOK](./keyword-book.md) keyword schedules meetings instead of tasks. Use [SET SCHEDULE](./keyword-set-schedule.md) to create recurring tasks. The [SEND MAIL](./keyword-send-mail.md) keyword sends task notifications, and [ADD MEMBER](./keyword-add-member.md) adds users to task groups. - -## Database Tables - -Tasks are stored across several database tables. The `tasks` table holds main task records. User assignments are tracked in `task_assignments`. Discussions happen in `task_comments`. Related files are referenced in `task_attachments`. The `task_history` table records status changes over time. - -## Implementation - -The CREATE TASK keyword is implemented in `src/basic/keywords/create_task.rs`. It integrates with the task engine module for task management, the calendar engine for scheduling, the email module for notifications, and the storage module for attachments. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-delegate-to-bot.md b/docs/src/chapter-06-gbdialog/keyword-delegate-to-bot.md deleted file mode 100644 index b33a2bd4..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-delegate-to-bot.md +++ /dev/null @@ -1,219 +0,0 @@ -# DELEGATE TO BOT - -Delegates a task or message to another bot in a multi-agent system. This enables agent-to-agent communication using the A2A (Agent-to-Agent) protocol. - -## Syntax - -```basic -DELEGATE "message" TO BOT "botname" -DELEGATE "message" TO BOT "botname" TIMEOUT seconds -result = DELEGATE "message" TO BOT "botname" -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `message` | String | The task or message to send to the target bot | -| `botname` | String | Name of the target bot to delegate to | -| `seconds` | Number | Optional timeout in seconds (default: 30) | - -## Description - -`DELEGATE TO BOT` sends a message or task to another bot and optionally waits for a response. This is the core keyword for multi-agent orchestration, enabling: - -- **Task specialization** - Route tasks to specialized bots -- **Agent collaboration** - Multiple bots working together -- **Workload distribution** - Spread tasks across agents -- **Expert consultation** - Query domain-specific bots - -The delegation uses the A2A (Agent-to-Agent) protocol which handles: -- Message routing between agents -- Correlation IDs for request/response matching -- Timeout handling -- Error propagation - -## Examples - -### Basic Delegation - -```basic -' Delegate a translation task to a specialized bot -DELEGATE "Translate 'Hello World' to Portuguese" TO BOT "translator-bot" -TALK "Translation request sent!" -``` - -### Get Response from Delegated Bot - -```basic -' Ask the finance bot for a calculation -result = DELEGATE "Calculate ROI for investment of $10000 with 12% annual return over 5 years" TO BOT "finance-bot" -TALK "The finance expert says: " + result -``` - -### Delegation with Timeout - -```basic -' Long-running task with extended timeout -result = DELEGATE "Analyze this quarterly report and provide insights" TO BOT "analyst-bot" TIMEOUT 120 -TALK result -``` - -### Multi-Bot Workflow - -```basic -' Customer support escalation workflow -issue = "Customer reports billing discrepancy" - -' First, check with billing bot -billingInfo = DELEGATE "Check account status for customer " + customerid TO BOT "billing-bot" TIMEOUT 30 - -IF INSTR(billingInfo, "discrepancy") > 0 THEN - ' Escalate to senior support - resolution = DELEGATE "Priority: " + issue + " Details: " + billingInfo TO BOT "senior-support-bot" TIMEOUT 60 - TALK "A senior agent is handling your case: " + resolution -ELSE - TALK "Your account looks fine: " + billingInfo -END IF -``` - -### Parallel Expert Consultation - -```basic -' Get opinions from multiple specialized bots -question = "What's the best approach for this investment portfolio?" - -' Delegate to multiple experts -stockAnalysis = DELEGATE question TO BOT "stock-analyst" -bondAnalysis = DELEGATE question TO BOT "bond-analyst" -riskAssessment = DELEGATE question TO BOT "risk-assessor" - -' Combine insights -BEGIN TALK -**Investment Analysis Summary** - -📈 **Stock Analysis:** {stockAnalysis} - -📊 **Bond Analysis:** {bondAnalysis} - -⚠️ **Risk Assessment:** {riskAssessment} -END TALK -``` - -### Conditional Routing - -```basic -' Route to appropriate specialist based on query type -HEAR userquery - -' Use LLM to classify the query -category = LLM "Classify this query into one of: billing, technical, sales, general. Query: " + userquery - -SWITCH category - CASE "billing" - response = DELEGATE userquery TO BOT "billing-bot" - CASE "technical" - response = DELEGATE userquery TO BOT "tech-support-bot" - CASE "sales" - response = DELEGATE userquery TO BOT "sales-bot" - CASE ELSE - response = DELEGATE userquery TO BOT "general-assistant" -END SWITCH - -TALK response -``` - -### Chain of Delegation - -```basic -' Research assistant that coordinates multiple bots -topic = "renewable energy trends 2025" - -' Step 1: Gather data -rawData = DELEGATE "Search for recent data on " + topic TO BOT "research-bot" TIMEOUT 60 - -' Step 2: Analyze data -analysis = DELEGATE "Analyze this data and identify key trends: " + rawData TO BOT "analyst-bot" TIMEOUT 45 - -' Step 3: Generate report -report = DELEGATE "Create an executive summary from this analysis: " + analysis TO BOT "writer-bot" TIMEOUT 30 - -TALK report -``` - -## A2A Protocol Details - -When you use `DELEGATE TO BOT`, the system creates an A2A message with: - -| Field | Description | -|-------|-------------| -| `from_agent` | The current bot's identifier | -| `to_agent` | The target bot name | -| `message_type` | `Delegate` for task delegation | -| `payload` | The message content | -| `correlation_id` | Unique ID to match response | -| `timestamp` | When the message was sent | - -## Error Handling - -```basic -' Handle delegation failures gracefully -ON ERROR RESUME NEXT - -result = DELEGATE "Process payment" TO BOT "payment-bot" TIMEOUT 30 - -IF ERROR THEN - TALK "I'm having trouble reaching our payment system. Please try again in a moment." - ' Log the error - PRINT "Delegation failed: " + ERROR_MESSAGE -ELSE - TALK result -END IF -``` - -## Related Keywords - -| Keyword | Description | -|---------|-------------| -| [`ADD BOT`](./keyword-add-bot.md) | Add a bot to the current session | -| [`BROADCAST TO BOTS`](./keyword-broadcast-to-bots.md) | Send message to all bots | -| [`TRANSFER CONVERSATION`](./keyword-transfer-conversation.md) | Hand off conversation to another bot | - -## Config.csv Options - -```csv -name,value -a2a-enabled,true -a2a-timeout,30 -a2a-max-hops,5 -a2a-retry-count,3 -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `a2a-enabled` | `true` | Enable agent-to-agent communication | -| `a2a-timeout` | `30` | Default timeout in seconds | -| `a2a-max-hops` | `5` | Maximum delegation chain depth | -| `a2a-retry-count` | `3` | Number of retry attempts on failure | - -## Best Practices - -1. **Set appropriate timeouts** - Long tasks need longer timeouts -2. **Handle failures gracefully** - Always have a fallback -3. **Avoid circular delegation** - Bot A → Bot B → Bot A -4. **Keep delegation chains short** - Max 3-4 hops recommended -5. **Log delegations** - Helps with debugging multi-agent flows -6. **Use descriptive bot names** - `billing-bot` not `bot2` - -## Limitations - -- Maximum message size: 1MB -- Maximum timeout: 300 seconds (5 minutes) -- Maximum concurrent delegations: 10 per session -- Target bot must be registered and active - -## See Also - -- [Multi-Agent Orchestration](../chapter-11-features/multi-agent-orchestration.md) - Complete multi-agent guide -- [A2A Protocol](../chapter-11-features/a2a-protocol.md) - Technical protocol details -- [Bot Configuration](../chapter-08-config/parameters.md) - Bot setup \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-delete-file.md b/docs/src/chapter-06-gbdialog/keyword-delete-file.md deleted file mode 100644 index 9cd5c28b..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-delete-file.md +++ /dev/null @@ -1,158 +0,0 @@ -# DELETE - -The `DELETE` keyword removes resources using dynamic path interpretation, similar to how `GET` works. The system automatically determines the appropriate operation based on the path provided. - -General Bots - -## Syntax - -```basic -DELETE path -DELETE path, options -``` - -## Dynamic Path Interpretation - -Like `GET`, `DELETE` interprets the path and selects the appropriate engine: - -| Path Pattern | Operation | -|--------------|-----------| -| `/files/document.pdf` | Delete file from storage | -| `/users/user-id` | Delete user | -| `/tasks/task-id` | Delete task | -| `/projects/project-id` | Delete project | -| `https://api.example.com/items/123` | HTTP DELETE to external API | - -## Examples - -### Delete a File - -```basic -DELETE "/reports/old-report.pdf" -TALK "File deleted" -``` - -### Delete from External API - -```basic -DELETE "https://api.crm.com/contacts/12345" -``` - -### Delete with Condition - -```basic -' Delete all files older than 30 days -files = LIST "/temp/" -FOR EACH file IN files - IF DATEDIFF("day", file.modified, NOW()) > 30 THEN - DELETE "/temp/" + file.name - END IF -NEXT file -``` - -### Delete a Task - -```basic -DELETE "/tasks/" + task_id -TALK "Task removed" -``` - -### Delete a User - -```basic -DELETE "/users/" + user_id -``` - -### Delete a Project - -```basic -DELETE "/projects/" + project_id -``` - -## Options - -Pass options as a second parameter for additional control: - -```basic -' Soft delete (archive instead of permanent removal) -DELETE "/files/report.pdf", #{soft: true} - -' Force delete (bypass confirmation) -DELETE "/files/temp/", #{force: true, recursive: true} -``` - -## Return Value - -`DELETE` returns information about the operation: - -```basic -result = DELETE "/files/document.pdf" -IF result.success THEN - TALK "Deleted: " + result.path -ELSE - TALK "Failed: " + result.error -END IF -``` - -## HTTP DELETE - -When the path is a full URL, `DELETE` performs an HTTP DELETE request: - -```basic -' Delete via REST API -DELETE "https://api.service.com/items/456" - -' With authentication -SET HEADER "Authorization", "Bearer " + token -DELETE "https://api.service.com/items/456" -``` - -## Database Records - -For database operations, use the `DELETE` keyword with table syntax: - -```basic -' Delete specific records -DELETE "orders", "status = 'cancelled' AND created_at < '2024-01-01'" - -' Delete by ID -DELETE "customers", "id = '" + customer_id + "'" -``` - -## Best Practices - -**Verify before deleting.** Confirm the resource exists and the user has permission: - -```basic -file = GET "/files/" + filename -IF file THEN - DELETE "/files/" + filename -ELSE - TALK "File not found" -END IF -``` - -**Use soft deletes for important data.** Archive rather than permanently remove: - -```basic -' Move to archive instead of delete -MOVE "/active/" + filename, "/archive/" + filename -``` - -**Log deletions for audit trails:** - -```basic -DELETE "/files/" + filename -INSERT "audit_log", #{ - action: "delete", - path: filename, - user: user.id, - timestamp: NOW() -} -``` - -## See Also - -- [GET](./keyword-get.md) - Dynamic resource retrieval -- [LIST](./keyword-list.md) - List resources before deletion -- [MOVE](./keyword-move.md) - Move instead of delete \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-delete-http.md b/docs/src/chapter-06-gbdialog/keyword-delete-http.md deleted file mode 100644 index c40621bb..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-delete-http.md +++ /dev/null @@ -1 +0,0 @@ -# DELETE HTTP diff --git a/docs/src/chapter-06-gbdialog/keyword-delete.md b/docs/src/chapter-06-gbdialog/keyword-delete.md deleted file mode 100644 index 9c3a6f4d..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-delete.md +++ /dev/null @@ -1 +0,0 @@ -# DELETE diff --git a/docs/src/chapter-06-gbdialog/keyword-download.md b/docs/src/chapter-06-gbdialog/keyword-download.md deleted file mode 100644 index 7baa789e..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-download.md +++ /dev/null @@ -1 +0,0 @@ -# DOWNLOAD diff --git a/docs/src/chapter-06-gbdialog/keyword-exit-for.md b/docs/src/chapter-06-gbdialog/keyword-exit-for.md deleted file mode 100644 index 0e4aa9cd..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-exit-for.md +++ /dev/null @@ -1,35 +0,0 @@ -# EXIT FOR Keyword - -**Syntax** - -``` -EXIT FOR -``` - -**Parameters** - -_None_ – This keyword takes no arguments. - -**Description** - -`EXIT FOR` terminates the execution of the nearest enclosing `FOR EACH … IN … NEXT` loop prematurely. When the interpreter encounters `EXIT FOR`, it stops iterating over the collection and continues execution after the `NEXT` statement that matches the loop variable. - -**Example** - -```basic -FOR EACH item IN my_list - IF item = "stop" THEN - EXIT FOR - ENDIF - TALK item -NEXT item -TALK "Loop ended." -``` - -In this script, the loop stops as soon as `item` equals `"stop"`, and the subsequent `TALK "Loop ended."` is executed. - -**Usage Notes** - -- `EXIT FOR` can only be used inside a `FOR EACH … IN … NEXT` block. -- It does not accept any parameters; it simply signals an early exit. -- The keyword is case‑insensitive; `exit for` works the same way. diff --git a/docs/src/chapter-06-gbdialog/keyword-extract.md b/docs/src/chapter-06-gbdialog/keyword-extract.md deleted file mode 100644 index 8922a51c..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-extract.md +++ /dev/null @@ -1 +0,0 @@ -# EXTRACT diff --git a/docs/src/chapter-06-gbdialog/keyword-fill.md b/docs/src/chapter-06-gbdialog/keyword-fill.md deleted file mode 100644 index 105273d9..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-fill.md +++ /dev/null @@ -1,204 +0,0 @@ -# FILL - -Populates a document template with data from variables or objects. - -## Syntax - -```basic -result = FILL template, data -FILL template, data TO output_path -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `template` | String | Path to template file (Word, Excel, PDF, or text) | -| `data` | Object | Key-value pairs for placeholder replacement | -| `output_path` | String | Optional destination path for filled document | - -## Description - -`FILL` replaces placeholders in document templates with actual data values. Placeholders use double curly braces like `{{name}}` or `{{company}}`. This is useful for generating personalized documents, contracts, invoices, and reports. - -## Examples - -### Basic Template Fill - -```basic -data = #{ - name: "John Smith", - company: "Acme Corp", - date: FORMAT(TODAY(), "MMMM d, yyyy") -} - -result = FILL "templates/contract.docx", data -TALK "Document generated: " + result.path -``` - -### Invoice Generation - -```basic -invoice_data = #{ - invoice_number: "INV-2025-001", - customer_name: customer.name, - customer_email: customer.email, - items: order_items, - subtotal: subtotal, - tax: tax_amount, - total: total_amount, - due_date: FORMAT(DATEADD("day", 30, TODAY()), "yyyy-MM-dd") -} - -FILL "templates/invoice.docx", invoice_data TO "invoices/INV-2025-001.docx" -TALK "Invoice generated and saved" -``` - -### Certificate Generation - -```basic -certificate = #{ - recipient: participant.name, - course: "AI Fundamentals", - completion_date: FORMAT(TODAY(), "MMMM d, yyyy"), - instructor: "Dr. Sarah Johnson", - certificate_id: GUID() -} - -FILL "templates/certificate.docx", certificate TO "certificates/" + certificate.certificate_id + ".docx" -``` - -### Email Template - -```basic -email_data = #{ - first_name: user.first_name, - order_id: order.id, - tracking_number: shipment.tracking, - delivery_date: shipment.estimated_delivery -} - -body = FILL "templates/shipping-notification.txt", email_data -SEND MAIL user.email, "Your order has shipped!", body -``` - -## Supported Template Formats - -| Format | Extension | Placeholder Style | -|--------|-----------|-------------------| -| Word | `.docx` | `{{placeholder}}` | -| Excel | `.xlsx` | `{{placeholder}}` | -| Text | `.txt` | `{{placeholder}}` | -| HTML | `.html` | `{{placeholder}}` | -| Markdown | `.md` | `{{placeholder}}` | - -## Return Value - -Returns an object containing: - -| Property | Description | -|----------|-------------| -| `path` | Path to the generated document | -| `content` | Document content (for text formats) | -| `size` | File size in bytes | - -## Sample Conversation - - - -## Template Example - -A template file might look like: - -``` -SERVICE AGREEMENT - -This agreement is entered into on {{date}} between: - -Company: {{company_name}} -Contact: {{contact_name}} -Email: {{contact_email}} - -SERVICES: -{{service_description}} - -TERMS: -Duration: {{duration}} months -Payment: ${{monthly_amount}} per month -Start Date: {{start_date}} - -Signature: _____________________ -``` - -## Advanced: Lists and Tables - -For repeating data, use array placeholders: - -```basic -data = #{ - customer: "Acme Corp", - items: [ - #{name: "Widget", qty: 10, price: 29.99}, - #{name: "Gadget", qty: 5, price: 49.99} - ], - total: 549.85 -} - -FILL "templates/order.docx", data TO "orders/order-123.docx" -``` - -In the template, use `{{#items}}...{{/items}}` for loops. - -## See Also - -- [GENERATE PDF](./keyword-generate-pdf.md) - Convert filled documents to PDF -- [MERGE PDF](./keyword-merge-pdf.md) - Combine multiple documents -- [UPLOAD](./keyword-upload.md) - Upload generated documents -- [SEND MAIL](./keyword-send-mail.md) - Email generated documents - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-filter.md b/docs/src/chapter-06-gbdialog/keyword-filter.md deleted file mode 100644 index 3bfe5454..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-filter.md +++ /dev/null @@ -1,166 +0,0 @@ -# FILTER - -Selects elements from an array that match a specified condition. - -## Syntax - -```basic -result = FILTER(array, condition) -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `array` | Array | The source array to filter | -| `condition` | String | Expression that evaluates to true/false for each element | - -## Description - -`FILTER` creates a new array containing only the elements from the input array that satisfy the given condition. The condition is evaluated for each element, and only elements where the condition is true are included in the result. - -## Examples - -### Filter by Field Value - -```basic -orders = FIND "orders", "year=2025" -large_orders = FILTER(orders, "item.total > 1000") - -TALK "Found " + LEN(large_orders) + " orders over $1000" -``` - -### Filter by String Match - -```basic -contacts = FIND "contacts", "active=true" -gmail_users = FILTER(contacts, "INSTR(item.email, 'gmail.com') > 0") - -FOR EACH contact IN gmail_users - TALK contact.name + " - " + contact.email -NEXT -``` - -### Filter by Status - -```basic -tasks = FIND "tasks", "assigned_to=me" -pending = FILTER(tasks, "item.status = 'pending'") -completed = FILTER(tasks, "item.status = 'completed'") - -TALK "Pending: " + LEN(pending) + ", Completed: " + LEN(completed) -``` - -### Filter Numbers - -```basic -scores = [85, 92, 67, 78, 95, 88, 72] -passing = FILTER(scores, "item >= 70") -honors = FILTER(scores, "item >= 90") - -TALK "Passing: " + LEN(passing) + ", Honors: " + LEN(honors) -``` - -### Complex Conditions - -```basic -products = FIND "products", "category=electronics" -featured = FILTER(products, "item.in_stock = true AND item.rating >= 4.0") - -TALK "Featured products:" -FOR EACH product IN featured - TALK "- " + product.name + " (★" + product.rating + ")" -NEXT -``` - -## Return Value - -Returns a new array containing only elements where the condition evaluated to true. - -- Original array is not modified -- Returns empty array if no elements match -- Preserves order of matching elements - -## Sample Conversation - - - -## Condition Operators - -| Operator | Description | Example | -|----------|-------------|---------| -| `=` | Equals | `"item.status = 'active'"` | -| `!=` | Not equals | `"item.type != 'archived'"` | -| `>` | Greater than | `"item.amount > 100"` | -| `>=` | Greater or equal | `"item.score >= 70"` | -| `<` | Less than | `"item.quantity < 10"` | -| `<=` | Less or equal | `"item.age <= 30"` | -| `AND` | Logical and | `"item.active = true AND item.verified = true"` | -| `OR` | Logical or | `"item.priority = 'high' OR item.urgent = true"` | - -## Common Patterns - -### Filter then Count - -```basic -users = FIND "users", "registered=true" -premium = FILTER(users, "item.plan = 'premium'") -TALK "Premium users: " + LEN(premium) -``` - -### Filter then Map - -```basic -orders = FIND "orders", "status=shipped" -recent = FILTER(orders, "item.ship_date > DATEADD('day', -7, NOW())") -tracking = MAP(recent, "tracking_number") -``` - -### Chain Multiple Filters - -```basic -products = FIND "products", "active=true" -in_stock = FILTER(products, "item.quantity > 0") -on_sale = FILTER(in_stock, "item.discount > 0") -featured = FILTER(on_sale, "item.rating >= 4.5") -``` - -## See Also - -- [FIND](./keyword-find.md) - Retrieve data from database -- [MAP](./keyword-map.md) - Transform filtered results -- [FOR EACH](./keyword-for-each.md) - Iterate over filtered array -- [AGGREGATE](./keyword-aggregate.md) - Calculate summary from filtered data - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-find.md b/docs/src/chapter-06-gbdialog/keyword-find.md deleted file mode 100644 index 5ec24256..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-find.md +++ /dev/null @@ -1,293 +0,0 @@ -# FIND - -Search and retrieve data from database tables using filter criteria. - -## Syntax - -```basic -result = FIND "table_name", "filter_criteria" -``` - -## Parameters - -- `table_name` - The name of the database table to search -- `filter_criteria` - Filter expression in the format "field=value" - -## Description - -FIND searches database tables for records matching specified criteria. It returns an array of matching records that can be iterated over using FOR EACH loops. - -## Examples - -### Basic Search -```basic -' Find records with specific action -items = FIND "gb.rob", "ACTION=EMUL" - -FOR EACH item IN items - TALK "Found: " + item.company -NEXT -``` - -### Single Field Filter -```basic -' Find pending orders -orders = FIND "orders", "status=pending" - -FOR EACH order IN orders - TALK "Order #" + order.id + " is pending" -NEXT -``` - -### Working with Results -```basic -' Find and process customer records -customers = FIND "customers", "city=Seattle" - -FOR EACH customer IN customers - TALK customer.name + " from " + customer.address - - ' Access fields with dot notation - email = customer.email - phone = customer.phone - - ' Update related data - SET "contacts", "id=" + customer.id, "last_contacted=" + NOW() -NEXT -``` - -## Return Value - -FIND returns an array of records from the specified table. Each record is an object with fields accessible via dot notation. - -- Returns empty array if no matches found -- Returns array of matching records if successful -- Each record contains all columns from the table - -## Field Access - -Access fields in returned records using dot notation: - -```basic -items = FIND "products", "category=electronics" - -FOR EACH item IN items - ' Access fields directly - TALK item.name - TALK item.price - TALK item.description - - ' Use null coalescing for optional fields - website = item.website ?? "" - - ' Check field existence - IF item.discount != "" THEN - TALK "On sale: " + item.discount + "% off" - END IF -NEXT -``` - -## Common Patterns - -### Process All Matching Records -```basic -tasks = FIND "tasks", "status=open" - -FOR EACH task IN tasks - ' Process each task - TALK "Processing task: " + task.title - - ' Update task status - SET "tasks", "id=" + task.id, "status=in_progress" -NEXT -``` - -### Check If Records Exist -```basic -users = FIND "users", "email=john@example.com" - -IF LENGTH(users) > 0 THEN - TALK "User exists" -ELSE - TALK "User not found" -END IF -``` - -### Data Enrichment -```basic -companies = FIND "companies", "needs_update=true" - -FOR EACH company IN companies - ' Get additional data - website = company.website ?? "" - - IF website == "" THEN - ' Look up website - website = WEBSITE OF company.name - - ' Update record - SET "companies", "id=" + company.id, "website=" + website - END IF - - ' Fetch and process website data - page = GET website - ' Process page content... -NEXT -``` - -### Batch Processing with Delays -```basic -emails = FIND "email_queue", "sent=false" - -FOR EACH email IN emails - ' Send email - SEND MAIL email.to, email.subject, email.body - - ' Mark as sent - SET "email_queue", "id=" + email.id, "sent=true" - - ' Rate limiting - WAIT 1000 -NEXT -``` - -## Filter Expressions - -The filter parameter uses simple equality expressions: - -- `"field=value"` - Match exact value -- Multiple conditions must be handled in BASIC code after retrieval - -```basic -' Get all records then filter in BASIC -all_orders = FIND "orders", "status=active" - -FOR EACH order IN all_orders - ' Additional filtering in code - IF order.amount > 1000 AND order.priority == "high" THEN - ' Process high-value orders - TALK "Priority order: " + order.id - END IF -NEXT -``` - -## Working with Different Data Types - -```basic -products = FIND "products", "active=true" - -FOR EACH product IN products - ' String fields - name = product.name - - ' Numeric fields - price = product.price - quantity = product.quantity - - ' Date fields - created = product.created_at - - ' Boolean-like fields (stored as strings) - IF product.featured == "true" THEN - TALK "Featured: " + name - END IF -NEXT -``` - -## Error Handling - -```basic -' Handle potential errors -items = FIND "inventory", "warehouse=main" - -IF items == null THEN - TALK "Error accessing inventory data" -ELSE IF LENGTH(items) == 0 THEN - TALK "No items found in main warehouse" -ELSE - TALK "Found " + LENGTH(items) + " items" - ' Process items... -END IF -``` - -## Performance Considerations - -1. **Limit Results**: The system automatically limits to 10 results for safety -2. **Use Specific Filters**: More specific filters reduce processing time -3. **Avoid Full Table Scans**: Always provide a filter criterion -4. **Process in Batches**: For large datasets, process in chunks - -```basic -' Process records in batches -batch = FIND "large_table", "processed=false" - -count = 0 -FOR EACH record IN batch - ' Process record - SET "large_table", "id=" + record.id, "processed=true" - - count = count + 1 - IF count >= 10 THEN - EXIT FOR ' Process max 10 at a time - END IF -NEXT -``` - -## Integration with Other Keywords - -### With SET for Updates -```basic -users = FIND "users", "newsletter=true" - -FOR EACH user IN users - ' Update last_notified field - SET "users", "id=" + user.id, "last_notified=" + NOW() -NEXT -``` - -### With LLM for Processing -```basic -articles = FIND "articles", "needs_summary=true" - -FOR EACH article IN articles - summary = LLM "Summarize: " + article.content - SET "articles", "id=" + article.id, "summary=" + summary -NEXT -``` - -### With CREATE SITE -```basic -companies = FIND "companies", "needs_site=true" - -FOR EACH company IN companies - alias = LLM "Create URL alias for: " + company.name - CREATE SITE alias, "template", "Create site for " + company.name - SET "companies", "id=" + company.id, "site_url=" + alias -NEXT -``` - -## Limitations - -- Maximum 10 records returned per query (system limit) -- Filter supports simple equality only -- Complex queries require post-processing in BASIC -- Table must exist in the database -- User must have read permissions on the table - -## Best Practices - -✅ **Always check results** - Verify FIND returned data before processing -✅ **Use specific filters** - Reduce result set size with precise criteria -✅ **Handle empty results** - Check LENGTH before iterating -✅ **Update as you go** - Mark records as processed to avoid reprocessing - -❌ **Don't assume order** - Results may not be sorted -❌ **Don't ignore limits** - Remember the 10-record limit -❌ **Don't use without filter** - Always provide filter criteria - -## See Also - -- [SET](./keyword-set.md) - Update database records -- [GET](./keyword-get.md) - Retrieve single values -- [FOR EACH](./keyword-for-each.md) - Iterate over results -- [LLM](./keyword-llm.md) - Process found data with AI \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-first.md b/docs/src/chapter-06-gbdialog/keyword-first.md deleted file mode 100644 index 0744e245..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-first.md +++ /dev/null @@ -1,30 +0,0 @@ -# FIRST Keyword - -**Syntax** - -``` -FIRST "text" -``` - -**Parameters** - -- `"text"` – A string expression from which the first word will be extracted. - -**Description** - -`FIRST` returns the first whitespace‑separated token of the provided string. If the string is empty or contains only whitespace, the result is an empty string. The keyword is useful for extracting a leading command or identifier from user input. - -**Example** - -```basic -SET command = FIRST user_input -TALK "You entered the command: " + command -``` - -If `user_input` is `"search books about Rust"`, `FIRST` returns `"search"`. - -**Implementation Notes** - -- The keyword splits the string on any whitespace (spaces, tabs, newlines) and returns the first element. -- It does not modify the original string. -- Case‑insensitive; the returned word preserves the original casing. diff --git a/docs/src/chapter-06-gbdialog/keyword-for-each.md b/docs/src/chapter-06-gbdialog/keyword-for-each.md deleted file mode 100644 index b3d5ae51..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-for-each.md +++ /dev/null @@ -1,42 +0,0 @@ -# FOR EACH Keyword - -**Syntax** - -``` -FOR EACH $var IN $collection - // block of statements -NEXT $var -``` - -**Parameters** - -- `$var` – Identifier that will hold each element of the collection during iteration. -- `$collection` – An array or iterable expression whose items will be traversed. - -**Description** - -`FOR EACH` iterates over every element of the supplied collection, assigning the current element to the loop variable `$var` for the duration of the block. The block is executed once per element. After the loop finishes, execution continues after the matching `NEXT $var` statement. - -If the collection is not an array, the keyword raises a runtime error indicating the expected type. - -**Example** - -```basic -SET numbers = [1, 2, 3, 4, 5] -FOR EACH n IN numbers - TALK "Number: " + n -NEXT n -TALK "All numbers processed." -``` - -The script outputs each number in the list sequentially and then prints a final message. - -**Control Flow** - -- `EXIT FOR` can be used inside the block to break out of the loop early. -- Nested `FOR EACH` loops are supported; each must have a distinct loop variable. - -**Implementation Notes** - -- The keyword evaluates the collection expression once before entering the loop. -- The loop variable is scoped to the block; it does not affect variables outside the loop. diff --git a/docs/src/chapter-06-gbdialog/keyword-format.md b/docs/src/chapter-06-gbdialog/keyword-format.md deleted file mode 100644 index 3bfacbf5..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-format.md +++ /dev/null @@ -1,82 +0,0 @@ -# FORMAT Keyword - -The **FORMAT** keyword formats numbers, dates, and text for display. Use it when you need a quick, readable representation without writing custom code. - -## Syntax -```basic -RESULT = FORMAT(VALUE, PATTERN) -``` - -## BASIC EXAMPLE -```basic -NUMBER = 1234.56 -TEXT = "John" -DATE = "2024-03-15 14:30:00" -TALK FORMAT(NUMBER, "n") ' 1234.56 -TALK FORMAT(TEXT, "Hello @!") ' Hello John! -TALK FORMAT(DATE, "dd/MM/yyyy") ' 15/03/2024 -``` -- **VALUE** – any number, date string (`YYYY‑MM‑DD HH:MM:SS`), or text. -- **PATTERN** – a short format string (see tables below). - -## Quick Reference - -### Numeric Patterns -| Pattern | Example | Output | -|---------|---------|--------| -| `n` | `FORMAT(1234.5, "n")` | `1234.50` | -| `F` | `FORMAT(1234.5, "F")` | `1234.50` | -| `f` | `FORMAT(1234.5, "f")` | `1234` | -| `0%` | `FORMAT(0.85, "0%")` | `85%` | -| `C2[en]` | `FORMAT(1234.5, "C2[en]")` | `$1,234.50` | -| `C2[pt]` | `FORMAT(1234.5, "C2[pt]")` | `R$ 1.234,50` | - -### Date Patterns -| Code | Meaning | Example | -|------|---------|---------| -| `yyyy` | 4‑digit year | `2024` | -| `yy` | 2‑digit year | `24` | -| `MM` | month (01‑12) | `03` | -| `M` | month (1‑12) | `3` | -| `dd` | day (01‑31) | `05` | -| `d` | day (1‑31) | `5` | -| `HH` | 24‑hour (00‑23) | `14` | -| `hh` | 12‑hour (01‑12) | `02` | -| `mm` | minutes (00‑59) | `05` | -| `ss` | seconds (00‑59) | `09` | -| `tt` | AM/PM | `PM` | - -**Example** -```basic -DATE = "2024-03-15 14:30:25" -TALK FORMAT(DATE, "dd/MM/yyyy HH:mm") ' 15/03/2024 14:30 -``` - -### Text Patterns -| Placeholder | Effect | -|-------------|--------| -| `@` | Insert original text | -| `!` | Upper‑case | -| `&` | Lower‑case | - -**Example** -```basic -NAME = "Maria" -TALK FORMAT(NAME, "Hello, !") ' Hello, MARIA -``` - -## Practical Tips -- **Test each pattern** in isolation before combining. -- **Locale codes** (`en`, `pt`, `fr`, …) go inside `C2[…]` for currency. -- **Dates must follow** `YYYY‑MM‑DD HH:MM:SS`; otherwise formatting fails. -- **Combine patterns** by nesting calls: - ```basic - TALK FORMAT(FORMAT(VALUE, "C2[en]"), "!") ' $1,234.50 (uppercase not needed here) - ``` - -## Common Pitfalls -- Using a date pattern on a non‑date string → returns the original string. -- Forgetting locale brackets (`C2[en]`) → defaults to system locale. -- Mixing placeholders (`@`, `!`, `&`) in the same pattern – only the last one applies. - -Use **FORMAT** whenever you need a clean, user‑friendly output without extra code. It keeps scripts short and readable. diff --git a/docs/src/chapter-06-gbdialog/keyword-generate-pdf.md b/docs/src/chapter-06-gbdialog/keyword-generate-pdf.md deleted file mode 100644 index bd177a3b..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-generate-pdf.md +++ /dev/null @@ -1 +0,0 @@ -# GENERATE PDF diff --git a/docs/src/chapter-06-gbdialog/keyword-get-bot-memory.md b/docs/src/chapter-06-gbdialog/keyword-get-bot-memory.md deleted file mode 100644 index 64b892b9..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-get-bot-memory.md +++ /dev/null @@ -1,216 +0,0 @@ -# GET BOT MEMORY - -Retrieve persistent key-value data stored at the bot level. - -## Syntax - -```basic -GET BOT MEMORY key -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `key` | String | The identifier of the memory item to retrieve | - -## Description - -The `GET BOT MEMORY` keyword retrieves values previously stored with `SET BOT MEMORY`. These values are: -- Persistent across all user sessions -- Shared between all users of the same bot -- Stored in the database permanently -- Available until explicitly updated or cleared - -If the key doesn't exist, returns an empty string. - -## Examples - -### Retrieve Simple Values -```basic -welcome = GET BOT MEMORY "welcome_message" -IF welcome = "" THEN - welcome = "Welcome to our bot!" -END IF -TALK welcome -``` - -### Read Configuration -```basic -max_retries = GET BOT MEMORY "max_retries" -IF max_retries = "" THEN - max_retries = "3" -END IF - -timeout = GET BOT MEMORY "timeout_seconds" -IF timeout = "" THEN - timeout = "30" -END IF -``` - -### Retrieve and Parse JSON -```basic -user_data = GET BOT MEMORY "user_profile" -IF user_data <> "" THEN - ' Parse JSON data - name = JSON_GET(user_data, "name") - level = JSON_GET(user_data, "level") - TALK "Welcome back, " + name + "! You are level " + level -END IF -``` - -### Counter Management -```basic -' Get current visitor count -count = GET BOT MEMORY "visitor_count" -IF count = "" THEN - count = "0" -END IF -count = VAL(count) + 1 -SET BOT MEMORY "visitor_count", STR(count) -TALK "Visitor #" + STR(count) -``` - -### Dynamic Keys -```basic -today = FORMAT(NOW(), "YYYY-MM-DD") -daily_stats = GET BOT MEMORY "stats_" + today -IF daily_stats = "" THEN - TALK "No statistics for today yet" -ELSE - TALK "Today's count: " + daily_stats -END IF -``` - -### Configuration with Defaults -```basic -' Function to get config with default -FUNCTION GetConfig(key, default_value) - value = GET BOT MEMORY key - IF value = "" THEN - value = default_value - SET BOT MEMORY key, default_value - END IF - RETURN value -END FUNCTION - -' Use the function -email_server = GetConfig("email_server", "mail.example.com") -email_port = GetConfig("email_port", "587") -``` - -## Return Value - -Returns a string containing: -- The stored value if the key exists -- Empty string ("") if the key doesn't exist -- Empty string if database error occurs - -## Performance - -- Direct database lookup with indexed keys -- Single query execution -- Synchronous operation (blocks until complete) -- Cached at database level for repeated access - -## Best Practices - -1. **Always Check for Empty Values** - ```basic - value = GET BOT MEMORY "some_key" - IF value = "" THEN - ' Handle missing value - value = "default" - END IF - ``` - -2. **Use Consistent Key Naming** - ```basic - ' Good: hierarchical keys - server = GET BOT MEMORY "config:email:server" - port = GET BOT MEMORY "config:email:port" - - ' Bad: inconsistent naming - ' srv = GET BOT MEMORY "emailSrv" - ' p = GET BOT MEMORY "mail_port" - ``` - -3. **Cache Frequently Used Values** - ```basic - ' At start of conversation - config_timeout = GET BOT MEMORY "timeout" - config_retries = GET BOT MEMORY "retries" - - ' Use cached values throughout - IF elapsed > VAL(config_timeout) THEN - TALK "Request timed out" - END IF - ``` - -4. **Validate Retrieved Data** - ```basic - max_items = GET BOT MEMORY "max_items" - IF max_items = "" OR NOT IS_NUMERIC(max_items) THEN - max_items = "10" - END IF - ``` - -## Error Handling - -- Database connection failures return empty string -- Invalid bot IDs return empty string -- Non-existent keys return empty string -- All errors are logged for debugging - -## Use Cases - -### Global Configuration -```basic -api_key = GET BOT MEMORY "api_key" -api_url = GET BOT MEMORY "api_url" -``` - -### Feature Flags -```basic -feature_enabled = GET BOT MEMORY "feature:new_ui" -IF feature_enabled = "true" THEN - ' Show new interface -ELSE - ' Show old interface -END IF -``` - -### Shared Counters -```basic -total_processed = GET BOT MEMORY "total_processed" -daily_limit = GET BOT MEMORY "daily_limit" -IF VAL(total_processed) >= VAL(daily_limit) THEN - TALK "Daily limit reached" -END IF -``` - -### Bot State -```basic -maintenance_mode = GET BOT MEMORY "maintenance_mode" -IF maintenance_mode = "true" THEN - TALK "System is under maintenance. Please try again later." - EXIT -END IF -``` - -## Related Keywords - -- [SET BOT MEMORY](./keyword-set-bot-memory.md) - Store bot-level memory -- [SET](./keyword-set.md) - Set user-scoped variables -- [GET](./keyword-get.md) - Get user variables -- [REMEMBER](./keyword-remember.md) - Store user-specific memories - -## Implementation - -Located in `src/basic/keywords/bot_memory.rs` - -The implementation: -- Performs synchronous database query -- Uses connection pooling for efficiency -- Returns empty string on any error -- Validates bot ID before querying \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-get-user-memory.md b/docs/src/chapter-06-gbdialog/keyword-get-user-memory.md deleted file mode 100644 index 34c76eac..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-get-user-memory.md +++ /dev/null @@ -1,191 +0,0 @@ -# GET USER MEMORY - -Retrieves data stored at the user level, accessible across sessions and bots. This is the companion to `SET USER MEMORY` for reading persistent user data. - -## Syntax - -```basic -value = GET USER MEMORY("key") -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `key` | String | The identifier for the stored value | - -## Returns - -The stored value, or empty string (`""`) if the key doesn't exist. - -## Description - -`GET USER MEMORY` retrieves persistent data associated with a specific user. This data: - -- **Persists across sessions** - Available when user returns days/weeks later -- **Persists across bots** - Accessible from any bot the user interacts with -- **Returns original type** - Objects, arrays, strings, numbers preserved -- **Returns empty on miss** - No error if key doesn't exist - -## Examples - -### Basic Usage - -```basic -' Retrieve user preferences -language = GET USER MEMORY("language") -timezone = GET USER MEMORY("timezone") -theme = GET USER MEMORY("theme") - -TALK "Your settings: " + language + ", " + timezone + ", " + theme -``` - -### Check If User Is Returning - -```basic -' Personalized greeting based on stored name -name = GET USER MEMORY("name") - -IF name = "" THEN - TALK "Hello! I don't think we've met. What's your name?" - HEAR name - SET USER MEMORY "name", name -ELSE - TALK "Welcome back, " + name + "! How can I help you today?" -END IF -``` - -### Retrieve Complex Objects - -```basic -' Get stored user profile -profile = GET USER MEMORY("profile") - -IF profile <> "" THEN - TALK "Hello " + profile.name + "!" - TALK "Your plan: " + profile.plan - TALK "Member since: " + profile.signupDate -ELSE - TALK "Please complete your profile first." -END IF -``` - -### Cross-Bot Data Access - -```basic -' Support bot accessing sales data -lastPurchase = GET USER MEMORY("lastPurchase") - -IF lastPurchase <> "" THEN - TALK "I can see your recent order #" + lastPurchase.orderId - TALK "Purchased on: " + lastPurchase.date - TALK "Amount: $" + lastPurchase.amount - TALK "How can I help with this order?" -ELSE - TALK "I don't see any recent purchases. How can I help?" -END IF -``` - -### Retrieve User Facts for AI Context - -```basic -' Load user facts into context for personalization -occupation = GET USER MEMORY("fact_occupation") -interests = GET USER MEMORY("fact_interests") -company = GET USER MEMORY("fact_company") - -IF occupation <> "" THEN - SET CONTEXT "user_occupation" AS occupation -END IF - -IF interests <> "" THEN - SET CONTEXT "user_interests" AS interests -END IF - -' Now AI responses will be personalized based on these facts -``` - -### Default Values Pattern - -```basic -' Get with fallback to default -language = GET USER MEMORY("language") -IF language = "" THEN - language = "en-US" -END IF - -' Or use inline default -theme = GET USER MEMORY("theme") -IF theme = "" THEN theme = "light" - -TALK "Using language: " + language + ", theme: " + theme -``` - -### Session Continuity - -```basic -' Resume conversation from previous session -lastTopic = GET USER MEMORY("lastTopic") -lastQuestion = GET USER MEMORY("lastQuestion") - -IF lastTopic <> "" THEN - TALK "Last time we were discussing " + lastTopic - TALK "You asked: " + lastQuestion - TALK "Would you like to continue from there?" - HEAR continueChoice AS BOOLEAN - - IF continueChoice THEN - ' Resume previous conversation - SET CONTEXT "topic" AS lastTopic - END IF -END IF -``` - -## Related Keywords - -| Keyword | Description | -|---------|-------------| -| [`SET USER MEMORY`](./keyword-set-user-memory.md) | Store user-level persistent data | -| [`GET BOT MEMORY`](./keyword-get-bot-memory.md) | Retrieve bot-level data | -| [`SET BOT MEMORY`](./keyword-set-bot-memory.md) | Store data at bot level | -| [`USER FACTS`](./keyword-user-facts.md) | Get all stored user facts | - -## Comparison: User Memory vs Bot Memory - -| Aspect | User Memory | Bot Memory | -|--------|-------------|------------| -| **Scope** | Per user, across all bots | Per bot, across all users | -| **Use case** | User preferences, profile | Bot state, counters | -| **Access** | Any bot can read/write | Only owning bot | -| **Example** | `language`, `name`, `timezone` | `totalOrders`, `lastDeployed` | - -## Error Handling - -```basic -' GET USER MEMORY never throws - returns empty on missing key -value = GET USER MEMORY("nonexistent_key") -' value = "" - -' Always check for empty before using -data = GET USER MEMORY("important_data") -IF data = "" THEN - TALK "Data not found. Please provide it." - ' Handle missing data case -ELSE - ' Use the data -END IF -``` - -## Best Practices - -1. **Always check for empty** - Keys may not exist for new users -2. **Use consistent key naming** - `user_name` vs `userName` vs `name` -3. **Document your keys** - Keep track of what data you're storing -4. **Handle missing gracefully** - New users won't have stored data -5. **Don't assume structure** - Stored objects might have missing fields - -## See Also - -- [Memory Management](../chapter-11-features/memory-management.md) - Complete memory architecture -- [Multi-Agent Orchestration](../chapter-11-features/multi-agent-orchestration.md) - Cross-bot data sharing -- [User Context](../chapter-12-auth/user-system-context.md) - User vs system context \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-get.md b/docs/src/chapter-06-gbdialog/keyword-get.md deleted file mode 100644 index 54f86ada..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-get.md +++ /dev/null @@ -1,74 +0,0 @@ -# GET Keyword - -The **GET** keyword retrieves content from a specified source — either a remote URL or a local file stored in the bot’s configured storage system. -It is used to fetch data dynamically during script execution. - ---- - -## Syntax - -```basic -variable = GET "source" -``` - ---- - -## Parameters - -- `"source"` — The location of the content to retrieve. - This can be: - - An HTTP/HTTPS URL (e.g., `"https://api.example.com/data"`) - - A relative path to a file stored in the bot's drive bucket or local storage. -- `variable` — The variable that will receive the fetched content. - ---- - -## Description - -`GET` performs a read operation from the specified source. -If the source is a URL, the bot sends an HTTP GET request and retrieves the response body. -If the source is a file path, the bot reads the file content directly from its configured storage (e.g., drive component or local filesystem). - -The command automatically handles text extraction from PDF and DOCX files, converting them to plain UTF‑8 text. -If the request fails or the file cannot be found, an error message is returned. - -This keyword is essential for integrating external APIs, reading stored documents, and dynamically loading data into scripts. - ---- - -## Example - -```basic -' Fetch data from a remote API -GET "https://api.example.com/users" INTO RESPONSE -PRINT RESPONSE - -' Read a local file from the bot’s storage -GET "reports/summary.txt" INTO CONTENT -TALK CONTENT -``` - ---- - -## Implementation Notes - -- Implemented in Rust under `src/file/mod.rs` and `src/web_automation/crawler.rs`. -- Uses the `reqwest` library for HTTP requests with timeout and error handling. -- Automatically detects file type and performs extraction for supported formats (PDF, DOCX, TXT). -- Validates paths to prevent directory traversal or unsafe access. -- Runs in a separate thread to avoid blocking the main engine. - ---- - -## Related Keywords - -- [`FIND`](keyword-find.md) — Searches for data within the current context. -- [`FORMAT`](keyword-format.md) — Formats retrieved data for display. -- [`PRINT`](keyword-print.md) — Outputs data to the console or chat. - ---- - -## Summary - -`GET` is a versatile keyword for retrieving external or stored content. -It enables bots to access APIs, read documents, and integrate dynamic data sources seamlessly within BASIC scripts. diff --git a/docs/src/chapter-06-gbdialog/keyword-graphql.md b/docs/src/chapter-06-gbdialog/keyword-graphql.md deleted file mode 100644 index 86477518..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-graphql.md +++ /dev/null @@ -1 +0,0 @@ -# GRAPHQL diff --git a/docs/src/chapter-06-gbdialog/keyword-group-by.md b/docs/src/chapter-06-gbdialog/keyword-group-by.md deleted file mode 100644 index 6414efbe..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-group-by.md +++ /dev/null @@ -1,130 +0,0 @@ -# GROUP BY - -Groups data by specified columns and optionally applies aggregate functions. - -## Syntax - -```basic -result = GROUP BY data, column -result = GROUP BY data, column, aggregates -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `data` | Array | The data array to group | -| `column` | String | Column name to group by | -| `aggregates` | Object | Optional aggregate functions to apply | - -## Description - -`GROUP BY` organizes rows of data into groups based on matching values in a specified column. When combined with aggregate functions, it calculates summary values for each group. - -## Examples - -### Basic Grouping - -```basic -orders = FIND "orders", "status=completed" -grouped = GROUP BY orders, "category" - -FOR EACH group IN grouped - TALK "Category: " + group.key + " - Count: " + group.count -NEXT -``` - -### With Aggregates - -```basic -sales = FIND "sales", "year=2025" -summary = GROUP BY sales, "region", #{ - total: "SUM(amount)", - average: "AVG(amount)", - count: "COUNT(*)" -} - -FOR EACH region IN summary - TALK region.key + ": $" + region.total + " (" + region.count + " sales)" -NEXT -``` - -### Multiple Level Grouping - -```basic -' First group by category, then by month -products = FIND "orders", "year=2025" -by_category = GROUP BY products, "category" - -FOR EACH cat IN by_category - TALK "Category: " + cat.key - by_month = GROUP BY cat.items, "month" - FOR EACH month IN by_month - TALK " " + month.key + ": " + month.count + " orders" - NEXT -NEXT -``` - -## Return Value - -Returns an array of group objects, each containing: - -| Property | Description | -|----------|-------------| -| `key` | The grouping value | -| `items` | Array of items in this group | -| `count` | Number of items in group | -| Additional | Any requested aggregates | - -## Supported Aggregates - -| Function | Description | -|----------|-------------| -| `SUM(column)` | Sum of values | -| `AVG(column)` | Average of values | -| `MIN(column)` | Minimum value | -| `MAX(column)` | Maximum value | -| `COUNT(*)` | Number of rows | - -## Sample Conversation - - - -## See Also - -- [AGGREGATE](./keyword-aggregate.md) - Single aggregate calculations -- [PIVOT](./keyword-pivot.md) - Cross-tabulation of data -- [FILTER](./keyword-filter.md) - Filter data before grouping -- [FIND](./keyword-find.md) - Retrieve data to group - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-hear.md b/docs/src/chapter-06-gbdialog/keyword-hear.md deleted file mode 100644 index 1692e79f..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-hear.md +++ /dev/null @@ -1,398 +0,0 @@ -# HEAR Keyword - -The `HEAR` keyword pauses script execution and waits for user input. With optional type validation, it automatically verifies and normalizes input, retrying with helpful error messages when validation fails. - -General Bots - -## Basic Syntax - -```basic -HEAR variable_name -HEAR variable_name AS TYPE -HEAR variable_name AS "Option1", "Option2", "Option3" -``` - -The simplest form accepts any input. Adding `AS TYPE` enables automatic validation with user-friendly retry prompts. - -## Simple HEAR - -```basic -TALK "What would you like to know?" -HEAR question -TALK "You asked: " + question -``` - -The script waits for any user message and stores it in the variable. - -## Validated Input Types - -When using `HEAR AS `, the system validates input automatically, retries up to 3 times with helpful messages, and returns normalized values. - -### Text Types - -**EMAIL** validates email format and normalizes to lowercase: - -```basic -TALK "What's your email address?" -HEAR email AS EMAIL -TALK "We'll send confirmation to: " + email -``` - -Accepts: `User@Example.COM` → Returns: `user@example.com` - -**NAME** validates name format with proper capitalization: - -```basic -TALK "What's your full name?" -HEAR name AS NAME -``` - -Accepts letters, spaces, hyphens, apostrophes. Auto-capitalizes: `john doe` → `John Doe` - -**URL** validates and normalizes URLs: - -```basic -TALK "Enter your website:" -HEAR website AS URL -``` - -Auto-adds `https://` if protocol missing. - -**PASSWORD** validates minimum strength: - -```basic -TALK "Create a password (minimum 8 characters):" -HEAR password AS PASSWORD -``` - -Requires 8+ characters. Never echoes the actual password back. - -**COLOR** accepts color names or hex values: - -```basic -HEAR color AS COLOR -``` - -Accepts: `red`, `#FF0000`, `rgb(255, 0, 0)` → Returns: `#FF0000` - -### Numeric Types - -**INTEGER** validates whole numbers: - -```basic -TALK "How many items?" -HEAR quantity AS INTEGER -``` - -Removes formatting (commas, spaces). Returns numeric value. - -**FLOAT** / **DECIMAL** validates decimal numbers: - -```basic -TALK "Enter the temperature:" -HEAR temperature AS FLOAT -``` - -Handles both `.` and `,` as decimal separators. - -**MONEY** / **CURRENCY** / **AMOUNT** validates monetary values: - -```basic -TALK "How much to transfer?" -HEAR amount AS MONEY -``` - -Accepts: `100`, `1,234.56`, `R$ 100,00`, `$100.00` → Returns: `1234.56` - -**CREDITCARD** / **CARD** validates card numbers with Luhn algorithm: - -```basic -TALK "Enter your card number:" -HEAR card AS CREDITCARD -``` - -Returns masked format: `4111 **** **** 1111` - -### Date and Time Types - -**DATE** validates and parses dates: - -```basic -TALK "When is your birthday?" -HEAR birthday AS DATE -``` - -Accepts: `25/12/2024`, `12/25/2024`, `2024-12-25`, `December 25, 2024`, `today`, `tomorrow`, `hoje`, `amanhã` - -Returns: ISO format `YYYY-MM-DD` - -**HOUR** / **TIME** validates time input: - -```basic -TALK "What time for the meeting?" -HEAR meeting_time AS HOUR -``` - -Accepts: `14:30`, `2:30 PM` → Returns: `14:30` - -### Brazilian Document Types - -**CPF** validates Brazilian individual taxpayer ID: - -```basic -TALK "Enter your CPF:" -HEAR cpf AS CPF -``` - -Validates 11 digits with mod 11 check. Returns: `123.456.789-09` - -**CNPJ** validates Brazilian company taxpayer ID: - -```basic -TALK "Enter your company's CNPJ:" -HEAR cnpj AS CNPJ -``` - -Validates 14 digits. Returns: `12.345.678/0001-95` - -### Contact Types - -**MOBILE** / **PHONE** validates phone numbers: - -```basic -TALK "What's your phone number?" -HEAR phone AS MOBILE -``` - -Accepts 10-15 digits, auto-formats based on detected country. - -**ZIPCODE** / **CEP** / **POSTALCODE** validates postal codes: - -```basic -HEAR cep AS ZIPCODE -``` - -Supports Brazilian CEP, US ZIP, UK postcode formats. - -### Menu Selection - -Provide options directly in the HEAR statement: - -```basic -TALK "Choose your fruit:" -HEAR fruit AS "Apple", "Banana", "Orange", "Mango" -``` - -Accepts exact match, case-insensitive match, numeric selection (`1`, `2`, `3`), or partial match if unique. - -**BOOLEAN** validates yes/no responses: - -```basic -TALK "Do you agree to the terms?" -HEAR agreed AS BOOLEAN -IF agreed THEN - TALK "Thank you!" -END IF -``` - -True: `yes`, `y`, `sim`, `ok`, `sure`, `confirm` -False: `no`, `n`, `não`, `cancel`, `deny` - -**LANGUAGE** validates language codes: - -```basic -HEAR language AS LANGUAGE -``` - -Accepts: `en`, `pt`, `English`, `Português` → Returns: ISO 639-1 code - -### Media Types - -**IMAGE** / **PHOTO** waits for image upload: - -```basic -TALK "Send a photo of your document:" -HEAR document_photo AS IMAGE -``` - -Returns URL to uploaded image. - -**QRCODE** waits for image and decodes QR: - -```basic -TALK "Send me the QR code:" -HEAR qr_data AS QRCODE -``` - -Uses vision API to decode. Returns decoded data. - -**AUDIO** / **VOICE** transcribes audio input: - -```basic -TALK "Send a voice message:" -HEAR transcription AS AUDIO -``` - -Uses Whisper for transcription. Returns text. - -**VIDEO** analyzes video content: - -```basic -TALK "Send a video of the issue:" -HEAR video_description AS VIDEO -``` - -Uses vision API to describe. Returns description. - -**FILE** / **DOCUMENT** waits for file upload: - -```basic -TALK "Upload your contract:" -HEAR contract AS DOCUMENT -``` - -Accepts PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, TXT, CSV. Returns URL. - -### Authentication - -**LOGIN** waits for OAuth completion: - -```basic -TALK "Click the link to authenticate:" -HEAR user AS LOGIN -``` - -Returns user object with tokens after OAuth callback. - -## Complete Examples - -### Registration Flow - -```basic -TALK "Let's create your account!" - -TALK "What's your full name?" -HEAR name AS NAME - -TALK "Enter your email address:" -HEAR email AS EMAIL - -TALK "Enter your CPF:" -HEAR cpf AS CPF - -TALK "What's your phone number?" -HEAR phone AS MOBILE - -TALK "Choose a password:" -HEAR password AS PASSWORD - -TALK "What's your birth date?" -HEAR birthdate AS DATE - -TALK "Select your gender:" -HEAR gender AS "Male", "Female", "Other", "Prefer not to say" - -SAVE "users.csv", name, email, cpf, phone, birthdate, gender, NOW() -TALK "Account created for " + name + "!" -``` - -### Payment Flow - -```basic -TALK "Enter the amount:" -HEAR amount AS MONEY - -IF amount < 1 THEN - TALK "Minimum payment is R$ 1.00" - RETURN -END IF - -TALK "How would you like to pay?" -HEAR method AS "Credit Card", "Debit Card", "PIX", "Boleto" - -TALK "Confirm payment of R$ " + FORMAT(amount, "#,##0.00") + "?" -HEAR confirm AS BOOLEAN - -IF confirm THEN - TALK "Processing payment..." -ELSE - TALK "Payment cancelled." -END IF -``` - -## Validation Behavior - -When validation fails, the system automatically prompts for correction: - -``` -User: my email -Bot: Please enter a valid email address (e.g., user@example.com) -User: test@example.com -Bot: Email confirmed! -``` - -After 3 failed attempts, execution continues with an empty value. Check for this: - -```basic -HEAR email AS EMAIL -IF email = "" THEN - TALK "Unable to validate email. Please contact support." - RETURN -END IF -``` - -## Best Practices - -**Always use appropriate types** — automatic validation is safer than manual checking: - -```basic -' Good -HEAR email AS EMAIL - -' Avoid -HEAR email -IF NOT email CONTAINS "@" THEN ... -``` - -**Provide context before HEAR** — users should know what to enter: - -```basic -TALK "Enter the transfer amount (minimum R$ 1.00):" -HEAR amount AS MONEY -``` - -**Use menus for limited options**: - -```basic -HEAR method AS "Credit Card", "Debit Card", "PIX" -``` - -**Combine with SET CONTEXT** for AI-enhanced input handling: - -```basic -SET CONTEXT "You are a banking assistant. Confirm amounts before processing." -HEAR amount AS MONEY -``` - -## Validation Summary - -| Type | Example Input | Normalized Output | -|------|---------------|-------------------| -| EMAIL | `User@Example.COM` | `user@example.com` | -| NAME | `john DOE` | `John Doe` | -| INTEGER | `1,234` | `1234` | -| MONEY | `R$ 1.234,56` | `1234.56` | -| DATE | `25/12/2024` | `2024-12-25` | -| HOUR | `2:30 PM` | `14:30` | -| BOOLEAN | `yes` / `sim` | `true` | -| CPF | `12345678909` | `123.456.789-09` | -| MOBILE | `11999998888` | `(11) 99999-8888` | -| CREDITCARD | `4111111111111111` | `4111 **** **** 1111` | -| QRCODE | [image] | decoded data | -| AUDIO | [audio file] | transcribed text | - -## See Also - -- [TALK Keyword](./keyword-talk.md) - Output messages -- [Dialog Basics](./basics.md) - Conversation patterns -- [Template Variables](./template-variables.md) - Variable substitution \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-insert.md b/docs/src/chapter-06-gbdialog/keyword-insert.md deleted file mode 100644 index 038278c4..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-insert.md +++ /dev/null @@ -1 +0,0 @@ -# INSERT diff --git a/docs/src/chapter-06-gbdialog/keyword-instr.md b/docs/src/chapter-06-gbdialog/keyword-instr.md deleted file mode 100644 index 3a11551e..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-instr.md +++ /dev/null @@ -1,150 +0,0 @@ -# INSTR - -The `INSTR` keyword returns the position of a substring within a string, following classic BASIC semantics. - -## Syntax - -```basic -position = INSTR(string, substring) -position = INSTR(start, string, substring) -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `start` | number | Optional. Starting position for the search (1-based) | -| `string` | string | The string to search in | -| `substring` | string | The substring to find | - -## Return Value - -- Returns the 1-based position of the first occurrence of `substring` in `string` -- Returns `0` if the substring is not found -- Returns `0` if either string is empty - -## Description - -`INSTR` searches for the first occurrence of a substring within another string. Unlike zero-based indexing in many modern languages, INSTR uses 1-based positioning consistent with traditional BASIC. - -When the optional `start` parameter is provided, the search begins at that position rather than at the beginning of the string. - -## Examples - -### Basic Usage - -```basic -text = "Hello, General Bots!" -pos = INSTR(text, "General") -TALK "Found 'General' at position: " + pos -' Output: Found 'General' at position: 8 -``` - -### Checking if Substring Exists - -```basic -email = HEAR "Enter your email:" -IF INSTR(email, "@") > 0 THEN - TALK "Valid email format" -ELSE - TALK "Email must contain @" -END IF -``` - -### Starting Search at Position - -```basic -text = "one two one three one" -first = INSTR(text, "one") ' Returns 1 -second = INSTR(5, text, "one") ' Returns 9 (starts after first "one") -third = INSTR(10, text, "one") ' Returns 19 -``` - -### Extracting Data - -```basic -data = "Name: John Smith" -colon_pos = INSTR(data, ":") -IF colon_pos > 0 THEN - ' Get everything after ": " - name = MID(data, colon_pos + 2) - TALK "Extracted name: " + name -END IF -``` - -### Case-Sensitive Search - -```basic -text = "General Bots" -pos1 = INSTR(text, "bots") ' Returns 0 (not found - case matters) -pos2 = INSTR(text, "Bots") ' Returns 9 (found) -``` - -### Finding Multiple Occurrences - -```basic -text = "apple,banana,cherry,apple" -search = "apple" -count = 0 -pos = 1 - -DO WHILE pos > 0 - pos = INSTR(pos, text, search) - IF pos > 0 THEN - count = count + 1 - pos = pos + 1 ' Move past current match - END IF -LOOP - -TALK "Found '" + search + "' " + count + " times" -``` - -### Validating Input Format - -```basic -phone = HEAR "Enter phone number (XXX-XXX-XXXX):" -dash1 = INSTR(phone, "-") -dash2 = INSTR(dash1 + 1, phone, "-") - -IF dash1 = 4 AND dash2 = 8 THEN - TALK "Phone format is correct" -ELSE - TALK "Invalid format. Use XXX-XXX-XXXX" -END IF -``` - -## Comparison with Other Keywords - -| Keyword | Purpose | -|---------|---------| -| `INSTR` | Find position of substring | -| `FORMAT` | Format strings with patterns | -| `FIRST` | Get first element of array | -| `LAST` | Get last element of array | - -## Notes - -- **1-based indexing**: Position 1 is the first character, not 0 -- **Case-sensitive**: "ABC" and "abc" are different -- **Empty strings**: Returns 0 if either string is empty -- **Not found**: Returns 0 when substring doesn't exist - -## Error Handling - -```basic -text = HEAR "Enter text to search:" -search = HEAR "Enter search term:" - -pos = INSTR(text, search) -IF pos = 0 THEN - TALK "'" + search + "' was not found in your text" -ELSE - TALK "Found at position " + pos -END IF -``` - -## See Also - -- [FORMAT](./keyword-format.md) - String formatting -- [SET](./keyword-set.md) - Variable assignment -- [IS NUMERIC](./keyword-is-numeric.md) - Check if string is numeric \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-is-numeric.md b/docs/src/chapter-06-gbdialog/keyword-is-numeric.md deleted file mode 100644 index 9512aa3b..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-is-numeric.md +++ /dev/null @@ -1,214 +0,0 @@ -# IS NUMERIC - -The `IS NUMERIC` function tests whether a string value can be converted to a number. This is essential for input validation before performing mathematical operations. - -## Syntax - -```basic -result = IS NUMERIC(value) -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `value` | string | The value to test for numeric content | - -## Return Value - -- Returns `true` if the value can be parsed as a number -- Returns `false` if the value contains non-numeric characters - -## Description - -`IS NUMERIC` examines a string to determine if it represents a valid numeric value. It recognizes: -- Integers: `42`, `-17`, `0` -- Decimals: `3.14`, `-0.5`, `.25` -- Scientific notation: `1e10`, `2.5E-3` - -Empty strings and strings containing letters or special characters (except `-`, `.`, `e`, `E`) return `false`. - -## Examples - -### Basic Validation - -```basic -input = HEAR "Enter a number:" -IF IS NUMERIC(input) THEN - TALK "You entered: " + input -ELSE - TALK "That's not a valid number" -END IF -``` - -### Bot Memory with Default Value - -```basic -max_items = GET BOT MEMORY "max_items" -IF max_items = "" OR NOT IS NUMERIC(max_items) THEN - max_items = "10" -END IF - -TALK "Processing up to " + max_items + " items" -``` - -### Input Loop Until Valid - -```basic -valid = false -DO WHILE NOT valid - age = HEAR "Enter your age:" - IF IS NUMERIC(age) THEN - valid = true - ELSE - TALK "Please enter a number" - END IF -LOOP -TALK "Your age is " + age -``` - -### Combined Conditions with OR NOT - -```basic -quantity = HEAR "How many items?" -IF quantity = "" OR NOT IS NUMERIC(quantity) THEN - TALK "Invalid quantity, using default of 1" - quantity = "1" -END IF -``` - -### Validating Multiple Fields - -```basic -price = HEAR "Enter price:" -quantity = HEAR "Enter quantity:" - -IF IS NUMERIC(price) AND IS NUMERIC(quantity) THEN - total = price * quantity - TALK "Total: $" + total -ELSE - IF NOT IS NUMERIC(price) THEN - TALK "Price must be a number" - END IF - IF NOT IS NUMERIC(quantity) THEN - TALK "Quantity must be a number" - END IF -END IF -``` - -### Configuration Validation - -```basic -' Load timeout from config, validate it's numeric -timeout = GET BOT MEMORY "api_timeout" -IF NOT IS NUMERIC(timeout) THEN - timeout = "30" - SET BOT MEMORY "api_timeout", timeout - TALK "Set default timeout to 30 seconds" -END IF -``` - -### Range Checking After Validation - -```basic -rating = HEAR "Rate from 1-5:" - -IF NOT IS NUMERIC(rating) THEN - TALK "Please enter a number" -ELSE IF rating < 1 OR rating > 5 THEN - TALK "Rating must be between 1 and 5" -ELSE - TALK "Thank you for your rating of " + rating - SET BOT MEMORY "last_rating", rating -END IF -``` - -## What IS NUMERIC Accepts - -| Input | Result | Notes | -|-------|--------|-------| -| `"42"` | `true` | Integer | -| `"-17"` | `true` | Negative integer | -| `"3.14"` | `true` | Decimal | -| `".5"` | `true` | Leading decimal | -| `"1e10"` | `true` | Scientific notation | -| `"2.5E-3"` | `true` | Scientific with decimal | -| `""` | `false` | Empty string | -| `"abc"` | `false` | Letters | -| `"12abc"` | `false` | Mixed content | -| `"$100"` | `false` | Currency symbol | -| `"1,000"` | `false` | Thousands separator | -| `" 42 "` | `true` | Whitespace trimmed | - -## Common Patterns - -### Default Value Pattern - -```basic -value = GET BOT MEMORY key -IF value = "" OR NOT IS NUMERIC(value) THEN - value = default_value -END IF -``` - -### Safe Division - -```basic -divisor = HEAR "Enter divisor:" -IF NOT IS NUMERIC(divisor) THEN - TALK "Must be a number" -ELSE IF divisor = 0 THEN - TALK "Cannot divide by zero" -ELSE - result = 100 / divisor - TALK "Result: " + result -END IF -``` - -### Percentage Validation - -```basic -percent = HEAR "Enter percentage (0-100):" -IF IS NUMERIC(percent) THEN - IF percent >= 0 AND percent <= 100 THEN - TALK "Discount: " + percent + "%" - ELSE - TALK "Must be between 0 and 100" - END IF -ELSE - TALK "Enter a number without %" -END IF -``` - -## Notes - -- **Whitespace**: Leading and trailing spaces are trimmed before checking -- **Empty strings**: Always return `false` -- **Locale**: Uses period (.) as decimal separator -- **Currency**: Does not recognize currency symbols ($, €, etc.) -- **Separators**: Does not recognize thousands separators (commas) - -## Error Prevention - -Using `IS NUMERIC` prevents runtime errors when converting strings to numbers: - -```basic -' Without validation - could cause error -value = HEAR "Enter number:" -result = value * 2 ' Error if value is "abc" - -' With validation - safe -value = HEAR "Enter number:" -IF IS NUMERIC(value) THEN - result = value * 2 -ELSE - TALK "Invalid input" -END IF -``` - -## See Also - -- [GET BOT MEMORY](./keyword-get-bot-memory.md) - Retrieve stored values -- [SET BOT MEMORY](./keyword-set-bot-memory.md) - Store values -- [INSTR](./keyword-instr.md) - Find substring position -- [FORMAT](./keyword-format.md) - Format numbers as strings \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-join.md b/docs/src/chapter-06-gbdialog/keyword-join.md deleted file mode 100644 index 2b91e8cc..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-join.md +++ /dev/null @@ -1,132 +0,0 @@ -# JOIN - -Combines elements of an array into a single string with a specified separator. - -## Syntax - -```basic -result = JOIN(array, separator) -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `array` | Array | The array of elements to join | -| `separator` | String | The delimiter to place between elements | - -## Description - -`JOIN` concatenates all elements of an array into a single string, inserting the specified separator between each element. This is commonly used for creating comma-separated lists, building display strings, or formatting data for output. - -## Examples - -### Basic Usage - -```basic -names = ["Alice", "Bob", "Charlie"] -result = JOIN(names, ", ") -TALK result -' Output: "Alice, Bob, Charlie" -``` - -### Creating Hashtag Lists - -```basic -tags = ["GeneralBots", "AI", "Automation", "NoCode"] -hashtags = JOIN(tags, " #") -hashtags = "#" + hashtags -TALK hashtags -' Output: "#GeneralBots #AI #Automation #NoCode" -``` - -### Building File Paths - -```basic -parts = ["documents", "reports", "2025", "sales.pdf"] -path = JOIN(parts, "/") -TALK "File: " + path -' Output: "File: documents/reports/2025/sales.pdf" -``` - -### Email Recipients - -```basic -recipients = ["john@example.com", "jane@example.com", "bob@example.com"] -to_list = JOIN(recipients, "; ") -SEND MAIL to_list, "Team Update", "Please review the attached report." -``` - -### Display Lists - -```basic -items = FIND "products", "category=electronics" -product_names = [] - -FOR EACH item IN items - product_names = APPEND(product_names, item.name) -NEXT - -TALK "Available products: " + JOIN(product_names, ", ") -``` - -## Return Value - -Returns a string containing all array elements concatenated with the separator. - -- If the array is empty, returns an empty string -- If the array has one element, returns that element as a string -- Null values in the array are converted to empty strings - -## Sample Conversation - - - -## Common Separators - -| Separator | Use Case | -|-----------|----------| -| `", "` | Readable comma-separated lists | -| `","` | CSV data | -| `"\n"` | Multi-line output | -| `" "` | Space-separated words | -| `" \| "` | Table columns | -| `"/"` | File paths | -| `"; "` | Email recipients | - -## See Also - -- [SPLIT](./keyword-split.md) - Split a string into an array (opposite of JOIN) -- [FOR EACH](./keyword-for-each.md) - Iterate over arrays -- [FILTER](./keyword-filter.md) - Filter arrays before joining - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-kb-collection-stats.md b/docs/src/chapter-06-gbdialog/keyword-kb-collection-stats.md deleted file mode 100644 index 247d368b..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-kb-collection-stats.md +++ /dev/null @@ -1 +0,0 @@ -# KB COLLECTION STATS diff --git a/docs/src/chapter-06-gbdialog/keyword-kb-documents-added-since.md b/docs/src/chapter-06-gbdialog/keyword-kb-documents-added-since.md deleted file mode 100644 index 3ab894b2..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-kb-documents-added-since.md +++ /dev/null @@ -1 +0,0 @@ -# KB DOCUMENTS ADDED SINCE diff --git a/docs/src/chapter-06-gbdialog/keyword-kb-documents-count.md b/docs/src/chapter-06-gbdialog/keyword-kb-documents-count.md deleted file mode 100644 index 8d068d98..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-kb-documents-count.md +++ /dev/null @@ -1 +0,0 @@ -# KB DOCUMENTS COUNT diff --git a/docs/src/chapter-06-gbdialog/keyword-kb-list-collections.md b/docs/src/chapter-06-gbdialog/keyword-kb-list-collections.md deleted file mode 100644 index f4960d7f..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-kb-list-collections.md +++ /dev/null @@ -1 +0,0 @@ -# KB LIST COLLECTIONS diff --git a/docs/src/chapter-06-gbdialog/keyword-kb-statistics.md b/docs/src/chapter-06-gbdialog/keyword-kb-statistics.md deleted file mode 100644 index 3cb12d5f..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-kb-statistics.md +++ /dev/null @@ -1 +0,0 @@ -# KB STATISTICS diff --git a/docs/src/chapter-06-gbdialog/keyword-kb-storage-size.md b/docs/src/chapter-06-gbdialog/keyword-kb-storage-size.md deleted file mode 100644 index 7612e4be..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-kb-storage-size.md +++ /dev/null @@ -1 +0,0 @@ -# KB STORAGE SIZE diff --git a/docs/src/chapter-06-gbdialog/keyword-last.md b/docs/src/chapter-06-gbdialog/keyword-last.md deleted file mode 100644 index 99b68a60..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-last.md +++ /dev/null @@ -1,30 +0,0 @@ -# LAST Keyword - -**Syntax** - -``` -LAST "text" -``` - -**Parameters** - -- `"text"` – A string expression from which the last word will be extracted. - -**Description** - -`LAST` returns the final whitespace‑separated token of the provided string. If the string is empty or contains only whitespace, the result is an empty string. This keyword is useful for retrieving the trailing part of a user’s input or any delimited text. - -**Example** - -```basic -SET command = LAST user_input -TALK "You entered the last word: " + command -``` - -If `user_input` is `"search books about Rust"`, `LAST` returns `"Rust"`. - -**Implementation Notes** - -- The keyword splits the string on any whitespace (spaces, tabs, newlines) and returns the last element. -- It does not modify the original string. -- Case‑insensitive; the returned word preserves the original casing. diff --git a/docs/src/chapter-06-gbdialog/keyword-list.md b/docs/src/chapter-06-gbdialog/keyword-list.md deleted file mode 100644 index e412b8ac..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-list.md +++ /dev/null @@ -1 +0,0 @@ -# LIST diff --git a/docs/src/chapter-06-gbdialog/keyword-map.md b/docs/src/chapter-06-gbdialog/keyword-map.md deleted file mode 100644 index c5fa93f0..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-map.md +++ /dev/null @@ -1,151 +0,0 @@ -# MAP - -Transforms each element of an array by applying a function or expression. - -## Syntax - -```basic -result = MAP(array, expression) -result = MAP(array, field) -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `array` | Array | The source array to transform | -| `expression` | String | Expression to apply to each element, or field name to extract | - -## Description - -`MAP` creates a new array by applying a transformation to each element of the input array. This is useful for extracting specific fields from objects, formatting data, or performing calculations on each item. - -## Examples - -### Extract Field from Objects - -```basic -users = FIND "users", "status=active" -names = MAP(users, "name") - -TALK "Active users: " + JOIN(names, ", ") -``` - -### Transform Values - -```basic -prices = [100, 200, 300, 400] -with_tax = MAP(prices, "item * 1.1") - -FOR EACH price IN with_tax - TALK "Price with tax: $" + price -NEXT -``` - -### Format Data - -```basic -orders = FIND "orders", "date=today" -summaries = MAP(orders, "'Order #' + item.id + ': $' + item.total") - -FOR EACH summary IN summaries - TALK summary -NEXT -``` - -### Extract Nested Properties - -```basic -contacts = FIND "contacts", "company=Acme" -emails = MAP(contacts, "email") - -email_list = JOIN(emails, "; ") -TALK "Emails: " + email_list -``` - -### Uppercase Names - -```basic -products = ["widget", "gadget", "gizmo"] -upper_products = MAP(products, "UPPER(item)") - -TALK JOIN(upper_products, ", ") -' Output: "WIDGET, GADGET, GIZMO" -``` - -## Return Value - -Returns a new array with the same length as the input, containing transformed values. - -- Original array is not modified -- Null values in the source are preserved as null -- If transformation fails for an element, that element becomes null - -## Sample Conversation - - - -## Common Patterns - -### Extract IDs for API Calls - -```basic -records = FIND "items", "sync=pending" -ids = MAP(records, "id") -' Use ids for batch API operations -``` - -### Create Display Labels - -```basic -products = FIND "products", "in_stock=true" -labels = MAP(products, "item.name + ' ($' + item.price + ')'") -``` - -### Calculate Derived Values - -```basic -line_items = FIND "cart_items", "cart_id=123" -totals = MAP(line_items, "item.quantity * item.unit_price") -``` - -## See Also - -- [FILTER](./keyword-filter.md) - Filter array elements -- [FOR EACH](./keyword-for-each.md) - Iterate with more control -- [JOIN](./keyword-join.md) - Combine mapped results into string -- [AGGREGATE](./keyword-aggregate.md) - Calculate summary from mapped values - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-merge-pdf.md b/docs/src/chapter-06-gbdialog/keyword-merge-pdf.md deleted file mode 100644 index 55865755..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-merge-pdf.md +++ /dev/null @@ -1 +0,0 @@ -# MERGE PDF diff --git a/docs/src/chapter-06-gbdialog/keyword-merge.md b/docs/src/chapter-06-gbdialog/keyword-merge.md deleted file mode 100644 index 56de5421..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-merge.md +++ /dev/null @@ -1,198 +0,0 @@ -# MERGE - -Combines data from multiple sources or upserts records into a database table. - -## Syntax - -```basic -MERGE table, data, key_column -MERGE table, data, key_columns, update_columns -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `table` | String | Target database table name | -| `data` | Array/Object | Data to merge (single record or array of records) | -| `key_column` | String | Column(s) to match existing records | -| `update_columns` | Array | Optional specific columns to update on match | - -## Description - -`MERGE` performs an "upsert" operation: it inserts new records or updates existing ones based on matching key columns. This is useful for synchronizing data from external sources, importing bulk data, or maintaining data consistency. - -## Examples - -### Basic Merge (Single Record) - -```basic -contact = #{ - email: "john@example.com", - name: "John Smith", - phone: "+1-555-0123" -} - -MERGE "contacts", contact, "email" -TALK "Contact merged successfully" -``` - -### Bulk Merge - -```basic -new_products = GET "https://api.supplier.com/products" - -MERGE "products", new_products, "sku" -TALK "Merged " + LEN(new_products) + " products" -``` - -### Merge with Specific Update Columns - -```basic -price_updates = [ - #{sku: "ABC123", price: 29.99}, - #{sku: "DEF456", price: 49.99}, - #{sku: "GHI789", price: 19.99} -] - -MERGE "products", price_updates, "sku", ["price"] -TALK "Prices updated" -``` - -### Composite Key Match - -```basic -attendance = #{ - employee_id: "EMP001", - date: TODAY(), - status: "present", - check_in: NOW() -} - -MERGE "attendance", attendance, "employee_id,date" -``` - -### Sync from External API - -```basic -SET SCHEDULE "every 6 hours" - -' Fetch latest data from CRM -customers = GET "https://crm.example.com/api/customers" - -' Merge into local database -MERGE "customers", customers, "crm_id" - -TALK "Synced " + LEN(customers) + " customer records" -``` - -## Return Value - -Returns an object with merge statistics: - -| Property | Description | -|----------|-------------| -| `inserted` | Number of new records created | -| `updated` | Number of existing records updated | -| `unchanged` | Number of records that matched but had no changes | -| `total` | Total records processed | - -```basic -result = MERGE "products", data, "sku" -TALK "Inserted: " + result.inserted + ", Updated: " + result.updated -``` - -## Sample Conversation - - - -## Behavior - -### On Match (Key Exists) -- Updates all columns in the data (or only `update_columns` if specified) -- Preserves columns not in the data -- Updates `updated_at` timestamp if column exists - -### On No Match (New Record) -- Inserts new row with all provided columns -- Sets `created_at` timestamp if column exists - -## Common Patterns - -### Daily Data Import - -```basic -SET SCHEDULE "every day at 2am" - -data = GET "https://data.provider.com/daily-export" -result = MERGE "imported_data", data, "external_id" - -IF result.inserted > 0 THEN - SEND MAIL "admin@company.com", "Data Import", - "Imported " + result.inserted + " new records" -END IF -``` - -### Inventory Sync - -```basic -inventory = GET "https://warehouse.api/stock-levels" -MERGE "products", inventory, "sku", ["quantity", "last_restock"] -``` - -### User Profile Updates - -```basic -profile = #{ - user_id: current_user_id, - preferences: user_preferences, - last_active: NOW() -} -MERGE "user_profiles", profile, "user_id" -``` - -## See Also - -- [INSERT](./keyword-insert.md) - Insert new records only -- [UPDATE](./keyword-update.md) - Update existing records only -- [SAVE](./keyword-save.md) - Simple data persistence -- [FIND](./keyword-find.md) - Query data before merging - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-model-route.md b/docs/src/chapter-06-gbdialog/keyword-model-route.md deleted file mode 100644 index e8b3f23d..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-model-route.md +++ /dev/null @@ -1,83 +0,0 @@ -# MODEL ROUTE Keywords - -Route LLM requests to different models based on task type, cost, or capability requirements. - -## Keywords - -| Keyword | Purpose | -|---------|---------| -| `USE MODEL` | Select a specific model for next request | -| `SET MODEL ROUTING` | Configure routing strategy | -| `GET CURRENT MODEL` | Get active model name | -| `LIST MODELS` | List available models | - -## USE MODEL - -```basic -USE MODEL "fast" -response = ASK "Quick question about the weather" - -USE MODEL "quality" -response = ASK "Analyze this complex legal document" -``` - -## SET MODEL ROUTING - -```basic -SET MODEL ROUTING "auto" -SET MODEL ROUTING "cost" -SET MODEL ROUTING "manual" -``` - -## Routing Strategies - -| Strategy | Description | -|----------|-------------| -| `manual` | Explicitly specify model per request | -| `auto` | Auto-select based on task complexity | -| `cost` | Prefer cheaper models when possible | -| `quality` | Always use highest quality model | - -## GET CURRENT MODEL - -```basic -model = GET CURRENT MODEL -TALK "Currently using: " + model -``` - -## LIST MODELS - -```basic -models = LIST MODELS -FOR EACH m IN models - TALK m.name + " - " + m.description -NEXT -``` - -## Configuration - -Add to `config.csv`: - -```csv -llm-models,default;fast;quality;code -model-routing-strategy,auto -model-default,gpt-3.5-turbo -model-fast,gpt-3.5-turbo -model-quality,gpt-4o -model-code,claude-sonnet -``` - -## Example: Task-Based Routing - -```basic -USE MODEL "code" -code_review = ASK "Review this function for bugs: " + code - -USE MODEL "fast" -TALK "Here's what I found:" -TALK code_review -``` - -## See Also - -- [USE MODEL](./keyword-use-model.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-move.md b/docs/src/chapter-06-gbdialog/keyword-move.md deleted file mode 100644 index 8dd53a84..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-move.md +++ /dev/null @@ -1 +0,0 @@ -# MOVE diff --git a/docs/src/chapter-06-gbdialog/keyword-on.md b/docs/src/chapter-06-gbdialog/keyword-on.md deleted file mode 100644 index 0c40bbe1..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-on.md +++ /dev/null @@ -1,42 +0,0 @@ -# ON Keyword - -**Syntax** - -``` -ON trigger-type OF "table-name" -``` - -**Parameters** - -- `trigger-type` – The type of database trigger to listen for. Valid values are: - - `INSERT` - - `UPDATE` - - `DELETE` -- `"table-name"` – The name of the database table to monitor. - -**Description** - -`ON` registers a database trigger for the current session. When the specified event occurs on the given table, the engine records the trigger in the `system_automations` table, linking it to the session. This enables scripts to react to data changes by executing associated actions (e.g., sending a notification, updating a variable). - -The keyword performs the following steps: - -1. Validates the `trigger-type` and converts it to the internal `TriggerKind` enum. -2. Constructs a parameter name in the form `_.rhai` (e.g., `orders_insert.rhai`). -3. Inserts a row into `system_automations` with the trigger kind, target table, and parameter name. -4. Returns the number of rows affected (normally `1` on success). - -If the trigger type is invalid, the keyword raises a runtime error. - -**Example** - -```basic -ON INSERT OF "orders" -TALK "A new order was added. Processing..." -``` - -After execution, any new row inserted into the `orders` table will cause the session to be notified, allowing the script to handle the event. - -**Implementation Notes** - -- The keyword runs synchronously but performs the database insertion on a separate thread to avoid blocking. -- Errors during insertion are logged and returned as runtime errors. diff --git a/docs/src/chapter-06-gbdialog/keyword-patch.md b/docs/src/chapter-06-gbdialog/keyword-patch.md deleted file mode 100644 index 4486d596..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-patch.md +++ /dev/null @@ -1 +0,0 @@ -# PATCH diff --git a/docs/src/chapter-06-gbdialog/keyword-pivot.md b/docs/src/chapter-06-gbdialog/keyword-pivot.md deleted file mode 100644 index 316e6f6f..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-pivot.md +++ /dev/null @@ -1,121 +0,0 @@ -# PIVOT - -Transforms rows into columns, creating a cross-tabulation summary of data. - -## Syntax - -```basic -result = PIVOT data, row_column, column_column, value_column -result = PIVOT data, row_column, column_column, value_column, aggregate -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `data` | Array | The data array to pivot | -| `row_column` | String | Column to use for row headers | -| `column_column` | String | Column to use for column headers | -| `value_column` | String | Column containing values to aggregate | -| `aggregate` | String | Aggregate function: SUM, AVG, COUNT, MIN, MAX (default: SUM) | - -## Description - -`PIVOT` reorganizes data from a normalized format into a cross-tabulation format, making it easier to compare values across two dimensions. This is useful for creating summary reports and dashboards. - -## Examples - -### Basic Pivot - -```basic -sales = FIND "sales", "year=2025" -summary = PIVOT sales, "region", "quarter", "amount" - -' Result: regions as rows, quarters as columns -' Shows total sales for each region/quarter combination -``` - -### With Aggregate Function - -```basic -orders = FIND "orders", "status=completed" -avg_order = PIVOT orders, "product", "month", "total", "AVG" - -FOR EACH row IN avg_order - TALK row.product + ": Q1=$" + row.Q1 + ", Q2=$" + row.Q2 -NEXT -``` - -### Sales by Region and Product - -```basic -data = FIND "sales", "year=2025" -pivot_table = PIVOT data, "region", "product", "revenue", "SUM" - -TALK "Revenue by Region and Product:" -FOR EACH region IN pivot_table - TALK region.row_header + ":" - TALK " Widgets: $" + region.Widgets - TALK " Gadgets: $" + region.Gadgets -NEXT -``` - -## Return Value - -Returns an array of objects where: -- Each object represents a row -- `row_header` contains the row label -- Dynamic properties contain pivoted column values - -## Sample Conversation - - - -## Use Cases - -| Scenario | Row | Column | Value | -|----------|-----|--------|-------| -| Sales dashboard | Region | Quarter | Revenue | -| Attendance report | Employee | Month | Days | -| Product comparison | Product | Store | Units sold | -| Time tracking | Project | Week | Hours | - -## See Also - -- [GROUP BY](./keyword-group-by.md) - Group data by columns -- [AGGREGATE](./keyword-aggregate.md) - Calculate summary values -- [TABLE](./keyword-table.md) - Display formatted tables - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-play.md b/docs/src/chapter-06-gbdialog/keyword-play.md deleted file mode 100644 index ba542cc4..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-play.md +++ /dev/null @@ -1,315 +0,0 @@ -# PLAY - -Open a content projector/player to display various media types including videos, images, documents, and presentations. - -## Syntax - -```basic -' Basic playback -PLAY file_or_url - -' With options -PLAY file_or_url WITH OPTIONS options_string -``` - -## Parameters - -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| `file_or_url` | String | Yes | Path to file or URL to display | -| `options_string` | String | No | Comma-separated playback options | - -## Supported Options - -| Option | Description | -|--------|-------------| -| `autoplay` | Start playback automatically | -| `loop` | Loop content continuously | -| `fullscreen` | Open in fullscreen mode | -| `muted` | Start with audio muted | -| `controls` | Show playback controls | -| `nocontrols` | Hide playback controls | - -## Supported Content Types - -### Video - -| Extension | Format | -|-----------|--------| -| `.mp4` | MPEG-4 Video | -| `.webm` | WebM Video | -| `.ogg` | Ogg Video | -| `.mov` | QuickTime | -| `.avi` | AVI Video | -| `.mkv` | Matroska | -| `.m4v` | M4V Video | - -### Audio - -| Extension | Format | -|-----------|--------| -| `.mp3` | MP3 Audio | -| `.wav` | WAV Audio | -| `.flac` | FLAC Audio | -| `.aac` | AAC Audio | -| `.m4a` | M4A Audio | -| `.ogg` | Ogg Audio | - -### Images - -| Extension | Format | -|-----------|--------| -| `.jpg` `.jpeg` | JPEG Image | -| `.png` | PNG Image | -| `.gif` | GIF (animated) | -| `.webp` | WebP Image | -| `.svg` | SVG Vector | -| `.bmp` | Bitmap | - -### Documents - -| Extension | Format | -|-----------|--------| -| `.pdf` | PDF Document | -| `.docx` `.doc` | Word Document | -| `.pptx` `.ppt` | PowerPoint | -| `.xlsx` `.xls` | Excel Spreadsheet | -| `.odt` | OpenDocument Text | -| `.odp` | OpenDocument Presentation | - -### Code - -| Extension | Language | -|-----------|----------| -| `.rs` | Rust | -| `.py` | Python | -| `.js` `.ts` | JavaScript/TypeScript | -| `.java` | Java | -| `.go` | Go | -| `.rb` | Ruby | -| `.md` | Markdown | -| `.html` | HTML | - -## Examples - -### Play a Video - -```basic -' Play a video file -PLAY "training-video.mp4" - -' Play with autoplay and loop -PLAY "background.mp4" WITH OPTIONS "autoplay,loop,muted" - -' Play from URL -PLAY "https://example.com/videos/demo.mp4" -``` - -### Display an Image - -```basic -' Show an image -PLAY "product-photo.jpg" - -' Show image fullscreen -PLAY "banner.png" WITH OPTIONS "fullscreen" -``` - -### Show a Presentation - -```basic -' Display PowerPoint presentation -PLAY "quarterly-report.pptx" - -' Fullscreen presentation mode -PLAY "sales-deck.pptx" WITH OPTIONS "fullscreen" -``` - -### Display a Document - -```basic -' Show PDF document -PLAY "contract.pdf" - -' Show Word document -PLAY "proposal.docx" -``` - -### Interactive Training Module - -```basic -TALK "Welcome to the training module!" -TALK "Let's start with an introduction video." - -PLAY "intro-video.mp4" WITH OPTIONS "controls" - -HEAR ready AS TEXT "Type 'continue' when you're ready to proceed:" - -IF LOWER(ready) = "continue" THEN - TALK "Great! Now let's review the key concepts." - PLAY "concepts-slides.pptx" - - HEAR understood AS TEXT "Did you understand the concepts? (yes/no)" - - IF LOWER(understood) = "yes" THEN - TALK "Excellent! Here's your certificate." - PLAY "certificate.pdf" - ELSE - TALK "Let's review the material again." - PLAY "concepts-detailed.mp4" - END IF -END IF -``` - -### Product Showcase - -```basic -' Show product images in sequence -products = FIND "products", "featured=true" - -FOR EACH product IN products - TALK "Now showing: " + product.name - PLAY product.image_path - WAIT 3000 ' Wait 3 seconds between images -NEXT -``` - -### Code Review - -```basic -' Display code for review -TALK "Let's review the implementation:" -PLAY "src/main.rs" - -HEAR feedback AS TEXT "Any comments on this code?" -INSERT "code_reviews", file_path, feedback, NOW() -``` - -### Audio Playback - -```basic -' Play audio message -TALK "Here's a voice message from your team:" -PLAY "team-message.mp3" WITH OPTIONS "controls" - -' Play background music -PLAY "ambient.mp3" WITH OPTIONS "autoplay,loop,muted" -``` - -### Dynamic Content Display - -```basic -' Display content based on file type -HEAR file_name AS TEXT "Enter the file name to display:" - -file_ext = LOWER(RIGHT(file_name, 4)) - -IF file_ext = ".mp4" OR file_ext = "webm" THEN - PLAY file_name WITH OPTIONS "controls,autoplay" -ELSE IF file_ext = ".pdf" THEN - PLAY file_name -ELSE IF file_ext = ".jpg" OR file_ext = ".png" THEN - PLAY file_name WITH OPTIONS "fullscreen" -ELSE - TALK "Unsupported file type" -END IF -``` - -### Embedded Video from URL - -```basic -' Play YouTube video (via embed URL) -PLAY "https://www.youtube.com/embed/dQw4w9WgXcQ" - -' Play Vimeo video -PLAY "https://player.vimeo.com/video/123456789" -``` - -### Onboarding Flow - -```basic -' Multi-step onboarding with media -TALK "Welcome to our platform! Let's get you started." - -' Step 1: Welcome video -TALK "First, watch this quick introduction:" -PLAY "onboarding/welcome.mp4" WITH OPTIONS "controls" - -HEAR step1_done AS TEXT "Press Enter when done..." - -' Step 2: Feature overview -TALK "Here's an overview of our key features:" -PLAY "onboarding/features.pptx" - -HEAR step2_done AS TEXT "Press Enter when done..." - -' Step 3: Quick start guide -TALK "Finally, here's your quick start guide:" -PLAY "onboarding/quickstart.pdf" - -TALK "You're all set! 🎉" -``` - -### Error Handling - -```basic -' Check if file exists before playing -file_path = "presentation.pptx" - -IF FILE_EXISTS(file_path) THEN - PLAY file_path -ELSE - TALK "Sorry, the file could not be found." - TALK "Please check the file path and try again." -END IF -``` - -## Player Behavior - -### Web Interface - -When used in the web interface, PLAY opens a modal overlay with: -- Appropriate player for the content type -- Close button to dismiss -- Optional playback controls -- Fullscreen toggle - -### WhatsApp/Messaging Channels - -On messaging channels, PLAY sends the file directly: -- Videos/images: Sent as media messages -- Documents: Sent as file attachments -- URLs: Sent as links with preview - -### Desktop Application - -In the desktop app, PLAY uses the native media player or viewer appropriate for the content type. - -## File Locations - -Files can be referenced from: - -| Location | Example | -|----------|---------| -| Bot's .gbdrive | `documents/report.pdf` | -| User's folder | `users/john@email.com/uploads/photo.jpg` | -| Absolute URL | `https://cdn.example.com/video.mp4` | -| Relative path | `./assets/logo.png` | - -## Limitations - -- Maximum file size depends on channel (WhatsApp: 16MB for media, 100MB for documents) -- Some formats may require conversion for web playback -- Streaming large files requires adequate bandwidth -- Protected/DRM content is not supported - -## See Also - -- [SEND FILE](./keyword-send-mail.md) - Send files as attachments -- [TALK](./keyword-talk.md) - Display text messages -- [UPLOAD](./keyword-upload.md) - Upload files to storage -- [DOWNLOAD](./keyword-download.md) - Download files from URLs - -## Implementation - -The PLAY keyword is implemented in `src/basic/keywords/play.rs` with content type detection and appropriate player selection for each media format. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-post.md b/docs/src/chapter-06-gbdialog/keyword-post.md deleted file mode 100644 index db642171..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-post.md +++ /dev/null @@ -1 +0,0 @@ -# POST diff --git a/docs/src/chapter-06-gbdialog/keyword-print.md b/docs/src/chapter-06-gbdialog/keyword-print.md deleted file mode 100644 index d412084b..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-print.md +++ /dev/null @@ -1,108 +0,0 @@ -# PRINT - -Debug output keyword. `PRINT` is an alias for `TALK` - both send messages to the current conversation. - -> **Note:** `PRINT` and `TALK` are equivalent. Use `TALK` for user-facing messages and `PRINT` for debug output during development. In production, prefer `TALK` for clarity. - -## Syntax - -```basic -PRINT expression -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| expression | Any | The value to output (string, number, or any expression) | - -## Description - -`PRINT` outputs a message to the current conversation. It is functionally identical to `TALK` but conventionally used for debugging and logging purposes. - -For sending messages to specific recipients on other channels, use: -- `TALK TO` - Send to a specific recipient (WhatsApp, Teams, etc.) -- `SEND FILE TO` - Send files to a specific recipient - -## Examples - -### Basic Debug Output - -```basic -x = 10 -y = 20 -PRINT "Debug: x = " + x + ", y = " + y - -result = x + y -PRINT "Result: " + result -``` - -### Logging During Processing - -```basic -WEBHOOK "process-order" - -order_id = body.order_id -PRINT "Processing order: " + order_id - -' Process the order -customer = FIND "customers", "id=" + body.customer_id -PRINT "Found customer: " + customer.name - -' More processing... -PRINT "Order processing complete" - -result_status = "ok" -``` - -### Variable Inspection - -```basic -data = GET "https://api.example.com/data" -PRINT "API Response: " + data - -items = FIND "products", "stock < 10" -PRINT "Low stock items count: " + UBOUND(items) -``` - -## Equivalent Keywords - -| Keyword | Description | -|---------|-------------| -| `TALK` | Same as PRINT - send message to conversation | -| `TALK TO` | Send message to specific recipient | - -## Example: PRINT vs TALK TO - -```basic -' Debug output (goes to current conversation) -PRINT "Starting order notification..." - -' User-facing message to specific WhatsApp number -TALK TO "whatsapp:+5511999887766", "Your order is confirmed!" - -' More debug output -PRINT "Notification sent successfully" -``` - -## Best Practices - -1. **Use TALK for production** - More readable for user-facing messages -2. **Use PRINT for debugging** - Makes it clear this is debug/log output -3. **Use TALK TO for channels** - When sending to specific recipients - -```basic -' Good: Clear intent -PRINT "Debug: Processing started" -TALK "Welcome! How can I help you?" -TALK TO "whatsapp:" + phone, "Your order is ready!" - -' Also valid but less clear: -PRINT "Welcome! How can I help you?" ' Works but TALK is clearer -``` - -## See Also - -- [TALK](./keyword-talk.md) - Primary message output keyword -- [TALK TO](./keyword-talk.md#talk-to) - Send to specific recipients -- [SEND FILE TO](./keyword-send-file-to.md) - Send files to recipients \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-put.md b/docs/src/chapter-06-gbdialog/keyword-put.md deleted file mode 100644 index 117e1407..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-put.md +++ /dev/null @@ -1 +0,0 @@ -# PUT diff --git a/docs/src/chapter-06-gbdialog/keyword-qrcode.md b/docs/src/chapter-06-gbdialog/keyword-qrcode.md deleted file mode 100644 index 52b82ec9..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-qrcode.md +++ /dev/null @@ -1,190 +0,0 @@ -# QR CODE - -Generate QR code images from text or data. - -## Syntax - -```basic -' Basic QR code generation -path = QR CODE data - -' With custom size (pixels) -path = QR CODE data, size - -' With size and output path -path = QR CODE data, size, output_path -``` - -## Parameters - -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| `data` | String | Yes | The data to encode in the QR code (URL, text, etc.) | -| `size` | Integer | No | Image size in pixels (default: 256) | -| `output_path` | String | No | Custom output file path | - -## Return Value - -Returns the file path to the generated QR code image (PNG format). - -## Examples - -### Basic QR Code - -```basic -' Generate a QR code for a URL -qr_path = QR CODE "https://example.com" -TALK "Scan this QR code:" -SEND FILE qr_path -``` - -### QR Code with Custom Size - -```basic -' Generate a larger QR code (512x512 pixels) -qr_path = QR CODE "https://mywebsite.com/signup", 512 -SEND FILE qr_path -``` - -### Dynamic Content - -```basic -HEAR user_id AS TEXT "Enter your user ID:" - -' Generate QR code with dynamic data -profile_url = "https://app.example.com/profile/" + user_id -qr_path = QR CODE profile_url, 300 - -TALK "Here's your profile QR code:" -SEND FILE qr_path -``` - -### Event Check-in - -```basic -' Generate unique check-in codes for events -event_id = "EVT-2025-001" -attendee_email = user.email - -checkin_data = "CHECKIN:" + event_id + ":" + attendee_email -qr_path = QR CODE checkin_data, 400 - -TALK "Show this QR code at the event entrance:" -SEND FILE qr_path -``` - -### Payment QR Code - -```basic -' Generate PIX payment QR code (Brazil) -HEAR amount AS NUMBER "Enter payment amount:" - -pix_payload = "00020126580014br.gov.bcb.pix0136" + merchant_key -pix_payload = pix_payload + "5204000053039865802BR" -pix_payload = pix_payload + "5913MerchantName6008CityName62070503***" - -qr_path = QR CODE pix_payload, 400 -TALK "Scan to pay R$ " + amount + ":" -SEND FILE qr_path -``` - -### WiFi QR Code - -```basic -' Generate WiFi connection QR code -wifi_ssid = "MyNetwork" -wifi_password = "SecurePass123" -wifi_type = "WPA" - -wifi_data = "WIFI:T:" + wifi_type + ";S:" + wifi_ssid + ";P:" + wifi_password + ";;" -qr_path = QR CODE wifi_data, 300 - -TALK "Scan to connect to WiFi:" -SEND FILE qr_path -``` - -### Contact Card (vCard) - -```basic -' Generate QR code with contact information -vcard = "BEGIN:VCARD\n" -vcard = vcard + "VERSION:3.0\n" -vcard = vcard + "N:Doe;John\n" -vcard = vcard + "TEL:+1234567890\n" -vcard = vcard + "EMAIL:john@example.com\n" -vcard = vcard + "END:VCARD" - -qr_path = QR CODE vcard, 350 -TALK "Scan to add contact:" -SEND FILE qr_path -``` - -### Custom Output Location - -```basic -' Save QR code to specific path -output_file = "work/qrcodes/user_" + user.id + ".png" -qr_path = QR CODE "https://example.com", 256, output_file - -TALK "QR code saved to: " + qr_path -``` - -## Supported Data Types - -The QR CODE keyword can encode various types of data: - -| Type | Format | Example | -|------|--------|---------| -| URL | `https://...` | `https://example.com` | -| Plain Text | Any text | `Hello World` | -| WiFi | `WIFI:T:WPA;S:ssid;P:pass;;` | Network credentials | -| vCard | `BEGIN:VCARD...END:VCARD` | Contact information | -| Email | `mailto:email@example.com` | Email link | -| Phone | `tel:+1234567890` | Phone number | -| SMS | `sms:+1234567890?body=Hello` | SMS with message | -| Geo | `geo:lat,lon` | Geographic coordinates | - -## Size Guidelines - -| Use Case | Recommended Size | -|----------|------------------| -| Mobile scanning | 256-300px | -| Print (business card) | 300-400px | -| Print (poster) | 512-1024px | -| Digital display | 256-512px | - -## Error Handling - -```basic -' Check if QR code was generated -qr_path = QR CODE data - -IF qr_path = "" THEN - TALK "Failed to generate QR code" -ELSE - SEND FILE qr_path -END IF -``` - -## File Storage - -Generated QR codes are stored in the bot's `.gbdrive` storage: -- Default location: `work/qrcodes/` -- Format: PNG -- Naming: UUID-based unique filenames - -## Limitations - -- Maximum data length depends on QR code version (up to ~4,296 alphanumeric characters) -- Larger data requires larger image sizes for reliable scanning -- Binary data should be Base64 encoded - -## See Also - -- [SEND FILE](./keyword-send-mail.md) - Send generated QR codes -- [TALK](./keyword-talk.md) - Display messages with QR codes -- [FORMAT](./keyword-format.md) - Format data before encoding - -## Implementation - -The QR CODE keyword is implemented in `src/basic/keywords/qrcode.rs` using the `qrcode` and `image` crates for generation. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-read.md b/docs/src/chapter-06-gbdialog/keyword-read.md deleted file mode 100644 index 16186a69..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-read.md +++ /dev/null @@ -1 +0,0 @@ -# READ diff --git a/docs/src/chapter-06-gbdialog/keyword-reference-complete.md b/docs/src/chapter-06-gbdialog/keyword-reference-complete.md deleted file mode 100644 index 3a0f289e..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-reference-complete.md +++ /dev/null @@ -1,645 +0,0 @@ -# Complete Keyword Reference - -This document provides a comprehensive reference of all BASIC keywords in General Bots, including existing implementations and planned additions. - ---- - -## Quick Reference Table - -| Keyword | Status | Category | Description | -|---------|--------|----------|-------------| -| `TALK` | ✅ Implemented | Dialog | Send message to user | -| `HEAR` | ✅ Implemented | Dialog | Get input from user | -| `WAIT` | ✅ Implemented | Dialog | Pause execution | -| `PRINT` | ✅ Implemented | Debug | Debug output | -| `SET` | ✅ Implemented | Variables | Set variable value | -| `GET` | ✅ Implemented | Variables | Get variable or fetch data | -| `LET` | ✅ Implemented | Variables | Assign variable (classic BASIC) | -| `SET BOT MEMORY` | ✅ Implemented | Memory | Persist bot-level data | -| `GET BOT MEMORY` | ✅ Implemented | Memory | Retrieve bot-level data | -| `REMEMBER` | ✅ Implemented | Memory | Store user-specific memory | -| `LLM` | ✅ Implemented | AI | Query language model | -| `SET CONTEXT` | ✅ Implemented | AI | Add context for LLM | -| `SET USER` | ✅ Implemented | Session | Set user context | -| `USE KB` | ✅ Implemented | Knowledge | Load knowledge base | -| `CLEAR KB` | ✅ Implemented | Knowledge | Unload knowledge base | -| `USE WEBSITE` | ✅ Implemented | Knowledge | Associate website | -| `ADD TOOL` | ✅ Implemented | Tools | Register tool | -| `USE TOOL` | ✅ Implemented | Tools | Load tool definition | -| `CLEAR TOOLS` | ✅ Implemented | Tools | Remove all tools | -| `ADD SUGGESTION` | ✅ Implemented | UI | Add clickable button | -| `CLEAR SUGGESTIONS` | ✅ Implemented | UI | Remove buttons | -| `SAVE` | ✅ Implemented | Data | Save to table | -| `FIND` | ✅ Implemented | Data | Search in files | -| `INSERT` | ✅ Implemented | Data | Insert record | -| `UPDATE` | ✅ Implemented | Data | Update records | -| `DELETE` | ✅ Implemented | Data | Delete records | -| `FILTER` | ✅ Implemented | Data | Filter records | -| `AGGREGATE` | ✅ Implemented | Data | SUM, AVG, COUNT, etc. | -| `JOIN` | ✅ Implemented | Data | Join datasets | -| `MERGE` | ✅ Implemented | Data | Merge data | -| `MAP` | ✅ Implemented | Data | Map field names | -| `FILL` | ✅ Implemented | Data | Fill template | -| `PIVOT` | ✅ Implemented | Data | Create pivot table | -| `GROUP BY` | ✅ Implemented | Data | Group data | -| `FIRST` | ✅ Implemented | Data | Get first element | -| `LAST` | ✅ Implemented | Data | Get last element | -| `FORMAT` | ✅ Implemented | Data | Format values | -| `SAVE FROM UNSTRUCTURED` | ✅ Implemented | Data | Extract structured data | -| `POST` | ✅ Implemented | HTTP | HTTP POST | -| `PUT` | ✅ Implemented | HTTP | HTTP PUT | -| `PATCH` | ✅ Implemented | HTTP | HTTP PATCH | -| `DELETE HTTP` | ✅ Implemented | HTTP | HTTP DELETE | -| `SET HEADER` | ✅ Implemented | HTTP | Set HTTP header | -| `CLEAR HEADERS` | ✅ Implemented | HTTP | Clear headers | -| `GRAPHQL` | ✅ Implemented | HTTP | GraphQL query | -| `SOAP` | ✅ Implemented | HTTP | SOAP call | -| `READ` | ✅ Implemented | Files | Read file | -| `WRITE` | ✅ Implemented | Files | Write file | -| `DELETE FILE` | ✅ Implemented | Files | Delete file | -| `COPY` | ✅ Implemented | Files | Copy file | -| `MOVE` | ✅ Implemented | Files | Move/rename file | -| `LIST` | ✅ Implemented | Files | List directory | -| `UPLOAD` | ✅ Implemented | Files | Upload file | -| `DOWNLOAD` | ✅ Implemented | Files | Download file | -| `COMPRESS` | ✅ Implemented | Files | Create ZIP | -| `EXTRACT` | ✅ Implemented | Files | Extract ZIP | -| `GENERATE PDF` | ✅ Implemented | Files | Generate PDF | -| `MERGE PDF` | ✅ Implemented | Files | Merge PDFs | -| `IF...THEN...ELSE...END IF` | ✅ Implemented | Control | Conditional | -| `FOR EACH...NEXT` | ✅ Implemented | Control | Loop | -| `EXIT FOR` | ✅ Implemented | Control | Exit loop | -| `WHILE...WEND` | ✅ Implemented | Control | While loop | -| `DO...LOOP` | ✅ Implemented | Control | Do loop | -| `SWITCH...CASE...END SWITCH` | ✅ Implemented | Control | Switch | -| `SUB...END SUB` | ✅ Implemented | Procedures | Define subroutine | -| `FUNCTION...END FUNCTION` | ✅ Implemented | Procedures | Define function | -| `CALL` | ✅ Implemented | Procedures | Call procedure | -| `RETURN` | ✅ Implemented | Procedures | Return value | -| `ON` | ✅ Implemented | Events | Event handler | -| `SET SCHEDULE` | ✅ Implemented | Events | Schedule execution | -| `WEBHOOK` | ✅ Implemented | Events | Create webhook | -| `SEND MAIL` | ✅ Implemented | Communication | Send email | -| `CREATE DRAFT` | ✅ Implemented | Communication | Create email draft | -| `ADD MEMBER` | ✅ Implemented | Communication | Add to group | -| `CREATE TASK` | ✅ Implemented | Tools | Create task | -| `CREATE SITE` | ✅ Implemented | Tools | Generate website | -| `BOOK` | ✅ Implemented | Special | Book appointment | -| `WEATHER` | ✅ Implemented | Special | Get weather | -| `INSTR` | ✅ Implemented | String | Find substring | -| `IS NUMERIC` | ✅ Implemented | Validation | Check if numeric | - ---- - -## Planned Keywords (Priority) - -### String Functions (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `LEN` | `length = LEN(string)` | Get string length | ⭐⭐⭐ | -| `LEFT` | `result = LEFT(string, n)` | Get left n characters | ⭐⭐⭐ | -| `RIGHT` | `result = RIGHT(string, n)` | Get right n characters | ⭐⭐⭐ | -| `MID` | `result = MID(string, start, length)` | Get substring | ⭐⭐⭐ | -| `TRIM` | `result = TRIM(string)` | Remove whitespace | ⭐⭐⭐ | -| `LTRIM` | `result = LTRIM(string)` | Remove left whitespace | ⭐⭐ | -| `RTRIM` | `result = RTRIM(string)` | Remove right whitespace | ⭐⭐ | -| `UCASE` | `result = UCASE(string)` | Convert to uppercase | ⭐⭐⭐ | -| `LCASE` | `result = LCASE(string)` | Convert to lowercase | ⭐⭐⭐ | -| `REPLACE` | `result = REPLACE(string, old, new)` | Replace substring | ⭐⭐⭐ | -| `SPLIT` | `array = SPLIT(string, delimiter)` | Split string to array | ⭐⭐⭐ | -| `ASC` | `code = ASC(char)` | Get ASCII code | ⭐⭐ | -| `CHR` | `char = CHR(code)` | Get character from code | ⭐⭐ | - -### Math Functions (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `ABS` | `result = ABS(number)` | Absolute value | ⭐⭐⭐ | -| `ROUND` | `result = ROUND(number, decimals)` | Round number | ⭐⭐⭐ | -| `INT` | `result = INT(number)` | Integer part | ⭐⭐⭐ | -| `SQRT` | `result = SQRT(number)` | Square root | ⭐⭐ | -| `MAX` | `result = MAX(a, b)` or `MAX(array)` | Maximum value | ⭐⭐⭐ | -| `MIN` | `result = MIN(a, b)` or `MIN(array)` | Minimum value | ⭐⭐⭐ | -| `MOD` | `result = a MOD b` | Modulo/remainder | ⭐⭐⭐ | -| `RND` | `result = RND()` | Random 0-1 | ⭐⭐ | -| `RANDOM` | `result = RANDOM(min, max)` | Random in range | ⭐⭐⭐ | -| `CEILING` | `result = CEILING(number)` | Round up | ⭐⭐ | -| `FLOOR` | `result = FLOOR(number)` | Round down | ⭐⭐ | -| `SGN` | `result = SGN(number)` | Sign (-1, 0, 1) | ⭐ | - -### Date/Time Functions (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `NOW` | `datetime = NOW()` | Current date/time | ⭐⭐⭐ | -| `TODAY` | `date = TODAY()` | Current date | ⭐⭐⭐ | -| `YEAR` | `year = YEAR(date)` | Extract year | ⭐⭐⭐ | -| `MONTH` | `month = MONTH(date)` | Extract month | ⭐⭐⭐ | -| `DAY` | `day = DAY(date)` | Extract day | ⭐⭐⭐ | -| `HOUR` | `hour = HOUR(datetime)` | Extract hour | ⭐⭐ | -| `MINUTE` | `minute = MINUTE(datetime)` | Extract minute | ⭐⭐ | -| `SECOND` | `second = SECOND(datetime)` | Extract second | ⭐⭐ | -| `WEEKDAY` | `dow = WEEKDAY(date)` | Day of week (1-7) | ⭐⭐ | -| `DATEADD` | `date = DATEADD(date, n, "day")` | Add to date | ⭐⭐⭐ | -| `DATEDIFF` | `days = DATEDIFF(date1, date2, "day")` | Date difference | ⭐⭐⭐ | -| `DATEVALUE` | `date = DATEVALUE("2025-01-15")` | Parse date string | ⭐⭐ | -| `TIMEVALUE` | `time = TIMEVALUE("14:30:00")` | Parse time string | ⭐⭐ | -| `EOMONTH` | `date = EOMONTH(date, 0)` | End of month | ⭐⭐ | - -### Type Conversion (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `VAL` | `number = VAL(string)` | String to number | ⭐⭐⭐ | -| `STR` | `string = STR(number)` | Number to string | ⭐⭐⭐ | -| `CINT` | `integer = CINT(value)` | Convert to integer | ⭐⭐ | -| `CDBL` | `double = CDBL(value)` | Convert to double | ⭐⭐ | -| `CSTR` | `string = CSTR(value)` | Convert to string | ⭐⭐ | -| `CBOOL` | `boolean = CBOOL(value)` | Convert to boolean | ⭐⭐ | -| `CDATE` | `date = CDATE(value)` | Convert to date | ⭐⭐ | - -### Validation Functions (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `ISNULL` | `result = ISNULL(value)` | Check if null | ⭐⭐⭐ | -| `ISEMPTY` | `result = ISEMPTY(value)` | Check if empty | ⭐⭐⭐ | -| `ISDATE` | `result = ISDATE(value)` | Check if valid date | ⭐⭐ | -| `ISARRAY` | `result = ISARRAY(value)` | Check if array | ⭐⭐ | - -### Array Functions (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `ARRAY` | `arr = ARRAY(1, 2, 3)` | Create array | ⭐⭐⭐ | -| `UBOUND` | `size = UBOUND(array)` | Get array size | ⭐⭐⭐ | -| `LBOUND` | `start = LBOUND(array)` | Get array start | ⭐⭐ | -| `REDIM` | `REDIM array(10)` | Resize array | ⭐⭐ | -| `SORT` | `sorted = SORT(array)` | Sort array | ⭐⭐⭐ | -| `UNIQUE` | `distinct = UNIQUE(array)` | Remove duplicates | ⭐⭐⭐ | -| `CONTAINS` | `result = CONTAINS(array, value)` | Check membership | ⭐⭐⭐ | -| `PUSH` | `PUSH array, value` | Add to end | ⭐⭐ | -| `POP` | `value = POP(array)` | Remove from end | ⭐⭐ | -| `REVERSE` | `reversed = REVERSE(array)` | Reverse array | ⭐ | - -### Error Handling (Critical) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `ON ERROR GOTO` | `ON ERROR GOTO handler` | Set error handler | ⭐⭐⭐ | -| `ON ERROR RESUME NEXT` | `ON ERROR RESUME NEXT` | Ignore errors | ⭐⭐ | -| `TRY...CATCH...END TRY` | `TRY ... CATCH e ... END TRY` | Structured errors | ⭐⭐⭐ | -| `THROW` | `THROW "error message"` | Raise error | ⭐⭐ | -| `ERR` | `code = ERR.NUMBER` | Get error code | ⭐⭐ | - -### Social Media (New) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `POST TO` | `POST TO "instagram" image, caption` | Post to social | ⭐⭐⭐ | -| `GET METRICS` | `metrics = GET INSTAGRAM METRICS "id"` | Get engagement | ⭐⭐ | -| `SCHEDULE POST` | `SCHEDULE POST TO "instagram" AT datetime` | Schedule post | ⭐⭐ | - -### Marketing (New) - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `CREATE LANDING PAGE` | `CREATE LANDING PAGE "name"` | Build page | ⭐⭐⭐ | -| `ADD TO CAMPAIGN` | `ADD TO CAMPAIGN email, "name"` | Add to sequence | ⭐⭐⭐ | -| `TRACK CONVERSION` | `TRACK CONVERSION "campaign", "event"` | Track event | ⭐⭐ | -| `GET CAMPAIGN STATS` | `stats = GET CAMPAIGN STATS "name"` | Get analytics | ⭐⭐ | - -### Logic Operators - -| Keyword | Syntax | Description | Priority | -|---------|--------|-------------|----------| -| `AND` | `IF a AND b THEN` | Logical AND | ✅ Implemented | -| `OR` | `IF a OR b THEN` | Logical OR | ✅ Implemented | -| `NOT` | `IF NOT a THEN` | Logical NOT | ✅ Implemented | -| `XOR` | `result = a XOR b` | Exclusive OR | ⭐ | -| `IIF` | `result = IIF(condition, true, false)` | Inline IF | ⭐⭐ | -| `LIKE` | `IF name LIKE "John*" THEN` | Pattern match | ⭐⭐ | -| `IN` | `IF value IN (1, 2, 3) THEN` | Set membership | ⭐⭐ | -| `BETWEEN` | `IF value BETWEEN 1 AND 10 THEN` | Range check | ⭐⭐ | - ---- - -## Keyword Categories - -### 1. Dialog & Interaction - -```basic -' Basic conversation -TALK "Hello! How can I help you?" -HEAR response - -' Typed input -HEAR name AS STRING -HEAR age AS INTEGER -HEAR email AS EMAIL -HEAR date AS DATE -HEAR amount AS MONEY -HEAR phone AS MOBILE -HEAR confirm AS BOOLEAN - -' Menu selection -HEAR choice AS "Option 1", "Option 2", "Option 3" - -' File upload -HEAR document AS FILE -HEAR audio AS AUDIO -HEAR image AS IMAGE -HEAR qrcode AS QRCODE -``` - -### 2. Memory & Variables - -```basic -' Local variables -LET name = "John" -SET age = 25 - -' Bot-level memory (shared across sessions) -SET BOT MEMORY "config_key", "value" -value = GET BOT MEMORY("config_key") - -' User-specific memory -REMEMBER "preference", "dark_mode" -``` - -### 3. AI & Knowledge - -```basic -' Query LLM -response = LLM "Summarize this text: " + text - -' Set context for LLM -SET CONTEXT "assistant" AS "You are a helpful sales assistant." - -' Load knowledge base -USE KB "product-docs" -USE KB "faq" -CLEAR KB "product-docs" -CLEAR KB - -' Load website content -USE WEBSITE "https://example.com" -``` - -### 4. Tools & Automation - -```basic -' Register tools -ADD TOOL "create-ticket" -ADD TOOL "send-email" -USE TOOL "search-database" -CLEAR TOOLS - -' Create tasks -CREATE TASK "Review document", "Please review the attached file" - -' Generate websites -CREATE SITE "promo" WITH TEMPLATE "landing" USING PROMPT "..." - -' Create email drafts -CREATE DRAFT "user@example.com", "Subject", "Body" -``` - -### 5. Data Operations - -```basic -' Save data (variable names = field names) -SAVE "customers.csv", name, email, phone, created - -' Find data -customers = FIND "customers.csv" -active = FIND "customers.csv", "status=active" - -' Filter data -highValue = FILTER customers, "amount>1000" -recent = FILTER customers, "created>=2025-01-01" - -' Aggregate data -total = AGGREGATE "SUM", orders, "amount" -average = AGGREGATE "AVG", orders, "amount" -count = AGGREGATE "COUNT", orders, "id" - -' Join datasets -joined = JOIN orders, customers, "customer_id" - -' Group and pivot -byCategory = GROUP BY sales, "category" -pivoted = PIVOT sales, "month", "amount" - -' Transform data -mapped = MAP data, "firstName->name, lastName->surname" -filled = FILL template, data - -' CRUD operations -INSERT "table", data -UPDATE "table", "filter", data -DELETE "table", "filter" -MERGE "table", data, "key_field" - -' Extract from text -SAVE FROM UNSTRUCTURED "contacts", unstructuredText -``` - -### 6. HTTP & API - -```basic -' GET request -data = GET "https://api.example.com/users" - -' POST request -response = POST "https://api.example.com/users", userData - -' PUT request -response = PUT "https://api.example.com/users/123", userData - -' PATCH request -response = PATCH "https://api.example.com/users/123", partialData - -' DELETE request -response = DELETE HTTP "https://api.example.com/users/123" - -' Set headers -SET HEADER "Authorization", "Bearer " + token -SET HEADER "Content-Type", "application/json" -CLEAR HEADERS - -' GraphQL -result = GRAPHQL "https://api.example.com/graphql", query, variables - -' SOAP -result = SOAP "https://api.example.com/service.wsdl", "Operation", params -``` - -### 7. File Operations - -```basic -' Read/Write -content = READ "config.json" -WRITE "output.txt", content - -' Copy/Move -COPY "source.txt", "backup/source.txt" -MOVE "temp.txt", "final/document.txt" - -' Delete -DELETE FILE "temp/old-file.txt" - -' List directory -files = LIST "documents/" - -' Upload/Download -url = UPLOAD localFile, "uploads/document.pdf" -path = DOWNLOAD "https://example.com/file.pdf", "downloads/file.pdf" - -' Archive -archive = COMPRESS files, "backup.zip" -extracted = EXTRACT "archive.zip", "extracted/" - -' PDF operations -pdf = GENERATE PDF "template.html", data, "output.pdf" -merged = MERGE PDF pdfFiles, "combined.pdf" -``` - -### 8. Flow Control - -```basic -' Conditional -IF age >= 18 THEN - TALK "You are an adult." -ELSE - TALK "You are a minor." -END IF - -' Switch/Case -SWITCH category - CASE "A" - TALK "Category A" - CASE "B" - TALK "Category B" - CASE ELSE - TALK "Other category" -END SWITCH - -' Loops -FOR EACH item IN items - TALK item.name -NEXT item - -WHILE count < 10 - count = count + 1 -WEND - -DO - result = processItem() -LOOP UNTIL result = "done" - -' Exit loop -FOR EACH item IN items - IF item.skip THEN EXIT FOR - TALK item.name -NEXT item -``` - -### 9. Procedures - -```basic -' Define subroutine -SUB ProcessOrder(orderId) - order = FIND "orders.csv", "id=" + orderId - TALK "Processing order: " + order.id -END SUB - -' Define function -FUNCTION CalculateTotal(items) - total = 0 - FOR EACH item IN items - total = total + item.price * item.quantity - NEXT item - RETURN total -END FUNCTION - -' Call procedures -CALL ProcessOrder("ORD-001") -total = CalculateTotal(cartItems) -``` - -### 10. Events & Scheduling - -```basic -' Event handlers -ON "new_message" CALL HandleMessage - -' Scheduled jobs -SET SCHEDULE "0 8 * * *" ' Every day at 8 AM - -' Webhooks -WEBHOOK "order-received" -' Endpoint: /api/{bot}/webhook/order-received -``` - -### 11. Communication - -```basic -' Send email -SEND MAIL "user@example.com", "Subject", "Body" - -' Send to specific number -SEND MAIL TO "5521999999999", "Subject", "Body" - -' Add to group -ADD MEMBER "user@example.com", "sales-team" -``` - -### 12. UI & Suggestions - -```basic -' Add quick reply buttons -ADD SUGGESTION "help" AS "Get Help" -ADD SUGGESTION "menu" AS "Show Menu" -ADD SUGGESTION "cancel" AS "Cancel" - -' Clear suggestions -CLEAR SUGGESTIONS -``` - ---- - -## Input Types for HEAR - -| Type | Example | Description | -|------|---------|-------------| -| `STRING` | `HEAR name AS STRING` | Any text input | -| `INTEGER` | `HEAR age AS INTEGER` | Whole number | -| `NUMBER` | `HEAR price AS NUMBER` | Decimal number | -| `BOOLEAN` | `HEAR confirm AS BOOLEAN` | Yes/No, True/False | -| `DATE` | `HEAR birthday AS DATE` | Date value | -| `EMAIL` | `HEAR contact AS EMAIL` | Valid email address | -| `MOBILE` | `HEAR phone AS MOBILE` | Phone number | -| `MONEY` | `HEAR amount AS MONEY` | Currency amount | -| `HOUR` | `HEAR time AS HOUR` | Time value | -| `ZIPCODE` | `HEAR zip AS ZIPCODE` | Postal code | -| `LANGUAGE` | `HEAR lang AS LANGUAGE` | Language code | -| `FILE` | `HEAR doc AS FILE` | File upload | -| `AUDIO` | `HEAR recording AS AUDIO` | Audio upload | -| `IMAGE` | `HEAR photo AS IMAGE` | Image upload | -| `QRCODE` | `HEAR code AS QRCODE` | QR code from image | -| `LOGIN` | `HEAR user AS LOGIN` | Authenticated user | -| Menu | `HEAR choice AS "A", "B", "C"` | Selection from options | - ---- - -## FORMAT Patterns - -| Pattern | Example | Result | -|---------|---------|--------| -| `YYYY` | `FORMAT date AS "YYYY"` | 2025 | -| `MM` | `FORMAT date AS "MM"` | 01 | -| `DD` | `FORMAT date AS "DD"` | 15 | -| `YYYY-MM-DD` | `FORMAT date AS "YYYY-MM-DD"` | 2025-01-15 | -| `HH:mm:ss` | `FORMAT time AS "HH:mm:ss"` | 14:30:00 | -| `#,##0` | `FORMAT number AS "#,##0"` | 1,234 | -| `#,##0.00` | `FORMAT number AS "#,##0.00"` | 1,234.56 | -| `0%` | `FORMAT decimal AS "0%"` | 75% | - ---- - -## AGGREGATE Operations - -| Operation | Example | Description | -|-----------|---------|-------------| -| `SUM` | `AGGREGATE "SUM", data, "amount"` | Sum of values | -| `AVG` | `AGGREGATE "AVG", data, "amount"` | Average | -| `COUNT` | `AGGREGATE "COUNT", data, "id"` | Count records | -| `MIN` | `AGGREGATE "MIN", data, "price"` | Minimum value | -| `MAX` | `AGGREGATE "MAX", data, "price"` | Maximum value | - ---- - -## Schedule Patterns (Cron) - -| Pattern | Description | -|---------|-------------| -| `0 8 * * *` | Every day at 8:00 AM | -| `0 9 * * 1` | Every Monday at 9:00 AM | -| `0 0 1 * *` | First day of every month | -| `*/15 * * * *` | Every 15 minutes | -| `0 8,17 * * *` | At 8:00 AM and 5:00 PM | -| `0 8 * * 1-5` | Weekdays at 8:00 AM | - ---- - -## Best Practices - -### DO ✅ - -```basic -' Use descriptive variable names -let customername = "John Smith" -let orderamount = 150.00 - -' Use SAVE with variable names as field names -SAVE "orders.csv", customername, orderamount, orderdate - -' Use spaces in keywords -SET BOT MEMORY "last_order", orderid -SET CONTEXT "assistant" AS "You are helpful." -ADD SUGGESTION "help" AS "Get Help" -CLEAR SUGGESTIONS -USE KB "products" -USE TOOL "search" - -' Use HEAR AS for type validation -HEAR email AS EMAIL -HEAR amount AS MONEY -HEAR confirm AS BOOLEAN -``` - -### DON'T ❌ - -```basic -' Don't use underscores in keywords (old syntax) -SET_BOT_MEMORY "key", value ' WRONG - use spaces - -' Don't use complex object operations -SET object.field = value ' WRONG -SAVE "table", object.id, object ' WRONG - -' Don't skip input validation -HEAR value ' OK but less safe -' Better: HEAR value AS STRING -``` - ---- - -## Migration from Old Syntax - -| Old Syntax | New Syntax | -|------------|------------| -| `SET_BOT_MEMORY` | `SET BOT MEMORY` | -| `GET_BOT_MEMORY()` | `GET BOT MEMORY()` | -| `SET_CONTEXT` | `SET CONTEXT` | -| `ADD_SUGGESTION` | `ADD SUGGESTION` | -| `CLEAR_SUGGESTIONS` | `CLEAR SUGGESTIONS` | -| `USE_KB` | `USE KB` | -| `USE_TOOL` | `USE TOOL` | -| `CLEAR_KB` | `CLEAR KB` | -| `CLEAR_TOOLS` | `CLEAR TOOLS` | -| `SET_SCHEDULE` | `SET SCHEDULE` | -| `SET_HEADER` | `SET HEADER` | -| `CLEAR_HEADERS` | `CLEAR HEADERS` | -| `DELETE_HTTP` | `DELETE HTTP` | -| `DELETE_FILE` | `DELETE FILE` | -| `GENERATE_PDF` | `GENERATE PDF` | -| `MERGE_PDF` | `MERGE PDF` | -| `GROUP_BY` | `GROUP BY` | -| `SAVE_FROM_UNSTRUCTURED` | `SAVE FROM UNSTRUCTURED` | - ---- - -*Last updated: January 2025* \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-remember.md b/docs/src/chapter-06-gbdialog/keyword-remember.md deleted file mode 100644 index fafe1d69..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-remember.md +++ /dev/null @@ -1,210 +0,0 @@ -# REMEMBER / RECALL Keywords - -The `REMEMBER` and `RECALL` keywords provide a powerful time-based memory system for storing and retrieving data associated with users. Unlike standard memory operations, `REMEMBER` supports automatic expiration of stored values. - -## Syntax - -### REMEMBER - -```basic -REMEMBER key, value, duration -``` - -### RECALL - -```basic -result = RECALL key -``` - -## Parameters - -### REMEMBER Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `key` | String | Unique identifier for the memory entry | -| `value` | Any | Data to store (string, number, boolean, array, or object) | -| `duration` | String | How long to remember the value | - -### Duration Formats - -| Format | Example | Description | -|--------|---------|-------------| -| `N seconds` | `"30 seconds"` | Expires after N seconds | -| `N minutes` | `"5 minutes"` | Expires after N minutes | -| `N hours` | `"2 hours"` | Expires after N hours | -| `N days` | `"7 days"` | Expires after N days | -| `N weeks` | `"2 weeks"` | Expires after N weeks | -| `N months` | `"3 months"` | Expires after ~N×30 days | -| `N years` | `"1 year"` | Expires after ~N×365 days | -| `forever` | `"forever"` | Never expires | -| `permanent` | `"permanent"` | Never expires (alias) | -| Plain number | `"30"` | Interpreted as days | - -## Examples - -### Basic Usage - -```basic -' Remember user's preferred language for 30 days -REMEMBER "preferred_language", "Spanish", "30 days" - -' Later, recall the preference -language = RECALL "preferred_language" -TALK "Your language preference is: " + language -``` - -### Session-Based Memory - -```basic -' Remember a temporary verification code for 5 minutes -code = RANDOM(100000, 999999) -REMEMBER "verification_code", code, "5 minutes" -TALK "Your verification code is: " + code - -' Verify the code later -HEAR user_code -stored_code = RECALL "verification_code" - -IF user_code = stored_code THEN - TALK "Code verified successfully!" -ELSE - TALK "Invalid or expired code." -END IF -``` - -### Storing Complex Data - -```basic -' Store user preferences as an array -preferences = ["dark_mode", "notifications_on", "english"] -REMEMBER "user_preferences", preferences, "1 year" - -' Store a shopping cart temporarily -cart = ["item1", "item2", "item3"] -REMEMBER "shopping_cart", cart, "2 hours" -``` - -### Permanent Storage - -```basic -' Store important user information permanently -REMEMBER "account_created", NOW(), "forever" -REMEMBER "user_tier", "premium", "permanent" -``` - -### Promotional Campaigns - -```basic -' Track if user has seen a promotional message -has_seen = RECALL "promo_summer_2024" - -IF has_seen = null THEN - TALK "🎉 Special summer offer: 20% off all products!" - REMEMBER "promo_summer_2024", true, "30 days" -END IF -``` - -### Rate Limiting - -```basic -' Simple rate limiting for API calls -call_count = RECALL "api_calls_today" - -IF call_count = null THEN - call_count = 0 -END IF - -IF call_count >= 100 THEN - TALK "You've reached your daily API limit. Please try again tomorrow." -ELSE - call_count = call_count + 1 - REMEMBER "api_calls_today", call_count, "24 hours" - ' Process the API call -END IF -``` - -## How It Works - -1. **Storage**: Data is stored in the `bot_memories` database table with: - - User ID and Bot ID association - - JSON-serialized value - - Creation timestamp - - Optional expiration timestamp - -2. **Retrieval**: When `RECALL` is called: - - System checks if the key exists for the user/bot combination - - Verifies the entry hasn't expired - - Returns the value or `null` if not found/expired - -3. **Automatic Cleanup**: Expired entries are not returned and can be periodically cleaned up by maintenance tasks. - -## Database Schema - -The `REMEMBER` keyword uses the following database structure: - -```sql -CREATE TABLE bot_memories ( - id TEXT PRIMARY KEY, - user_id TEXT NOT NULL, - bot_id TEXT NOT NULL, - session_id TEXT, - key TEXT NOT NULL, - value JSONB NOT NULL, - created_at TEXT NOT NULL, - expires_at TEXT, - UNIQUE(user_id, bot_id, key) -); -``` - -## Comparison with Other Memory Keywords - -| Keyword | Scope | Persistence | Expiration | -|---------|-------|-------------|------------| -| `SET USER MEMORY` | User | Permanent | No | -| `SET BOT MEMORY` | Bot (all users) | Permanent | No | -| `REMEMBER` | User | Configurable | Yes | -| `REMEMBER USER FACT` | User | Permanent | No | - -## Best Practices - -1. **Use descriptive keys**: Choose meaningful key names like `"last_login"` instead of `"ll"`. - -2. **Set appropriate durations**: Match the duration to your use case: - - Session data: minutes to hours - - Preferences: weeks to months - - Important data: `forever` - -3. **Handle null values**: Always check if `RECALL` returns `null`: - ```basic - value = RECALL "some_key" - IF value = null THEN - ' Handle missing/expired data - END IF - ``` - -4. **Avoid storing sensitive data**: Don't store passwords, API keys, or other secrets. - -## Error Handling - -```basic -' REMEMBER returns a confirmation message on success -result = REMEMBER "key", "value", "1 day" -' result = "Remembered 'key' for 1 day" - -' RECALL returns null if key doesn't exist or has expired -value = RECALL "nonexistent_key" -' value = null -``` - -## Related Keywords - -- [SET USER MEMORY](./keyword-set-user-memory.md) - Permanent user-scoped storage -- [GET USER MEMORY](./keyword-get-user-memory.md) - Retrieve permanent user data -- [SET BOT MEMORY](./keyword-set-bot-memory.md) - Bot-wide storage -- [GET BOT MEMORY](./keyword-get-bot-memory.md) - Retrieve bot-wide data - -## See Also - -- [Memory Management](../chapter-10-features/memory-management.md) -- [User Session Handling](../chapter-10-features/user-sessions.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-run-code.md b/docs/src/chapter-06-gbdialog/keyword-run-code.md deleted file mode 100644 index db9449f5..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-run-code.md +++ /dev/null @@ -1,340 +0,0 @@ -# RUN PYTHON / RUN JAVASCRIPT / RUN BASH - -Executes code in a sandboxed environment. Enables safe execution of dynamic code for data processing, calculations, and automation tasks. - -## Syntax - -```basic -result = RUN PYTHON "code" -result = RUN JAVASCRIPT "code" -result = RUN BASH "code" -``` - -```basic -result = RUN PYTHON WITH FILE "script.py" -result = RUN JAVASCRIPT WITH FILE "script.js" -result = RUN BASH WITH FILE "script.sh" -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `code` | String | Inline code to execute | -| `filepath` | String | Path to script file (with `WITH FILE` variant) | - -## Returns - -The output (stdout) from the executed code as a string. - -## Description - -The `RUN` keywords execute code in isolated, sandboxed environments. This provides: - -- **Security** - Code runs in isolated containers (LXC, Docker, or Firecracker) -- **Flexibility** - Use the right language for the task -- **Safety** - Resource limits prevent runaway processes -- **Integration** - Pass data between BASIC and other languages - -The sandbox prevents: -- File system access outside designated areas -- Network access (unless explicitly enabled) -- System calls and privilege escalation -- Excessive CPU or memory usage - -## Examples - -### Basic Python Execution - -```basic -' Simple calculation -result = RUN PYTHON "print(2 + 2)" -TALK "2 + 2 = " + result - -' Data processing -code = " -import json -data = [1, 2, 3, 4, 5] -print(json.dumps({'sum': sum(data), 'avg': sum(data)/len(data)})) -" -stats = RUN PYTHON code -TALK "Statistics: " + stats -``` - -### JavaScript for JSON Processing - -```basic -' Parse and transform JSON -jsonData = GET "https://api.example.com/data" -code = " -const data = JSON.parse('" + jsonData + "'); -const transformed = data.items.map(i => ({ - id: i.id, - name: i.name.toUpperCase() -})); -console.log(JSON.stringify(transformed)); -" -result = RUN JAVASCRIPT code -TALK result -``` - -### Bash for System Tasks - -```basic -' List files and get disk usage -result = RUN BASH "ls -la /data && df -h" -TALK "System info:\n" + result -``` - -### Run Script from File - -```basic -' Execute a Python script from .gbdrive -result = RUN PYTHON WITH FILE "scripts/analyze_data.py" -TALK "Analysis complete: " + result - -' Run a bash script -output = RUN BASH WITH FILE "scripts/backup.sh" -PRINT "Backup output: " + output -``` - -### Data Pipeline - -```basic -' Fetch data, process with Python, store result -rawData = GET "https://api.example.com/sales" - -pythonCode = " -import json -import statistics - -data = json.loads('''" + rawData + "''') -sales = [item['amount'] for item in data] - -result = { - 'total': sum(sales), - 'average': statistics.mean(sales), - 'median': statistics.median(sales), - 'std_dev': statistics.stdev(sales) if len(sales) > 1 else 0 -} -print(json.dumps(result)) -" - -analysis = RUN PYTHON pythonCode -SAVE "sales_analysis.csv", analysis -TALK "Sales analysis saved!" -``` - -### Machine Learning Inference - -```basic -' Run ML model for prediction -inputData = #{ features: [1.5, 2.3, 4.1, 0.8] } - -code = " -import json -import pickle - -# Load pre-trained model (stored in sandbox) -with open('/data/model.pkl', 'rb') as f: - model = pickle.load(f) - -input_data = " + JSON(inputData) + " -prediction = model.predict([input_data['features']])[0] -print(json.dumps({'prediction': float(prediction)})) -" - -result = RUN PYTHON code -prediction = JSON_PARSE(result) -TALK "Predicted value: " + prediction.prediction -``` - -### Image Processing - -```basic -' Process an uploaded image -imagePath = UPLOAD userImage, "uploads/" - -code = " -from PIL import Image -import json - -img = Image.open('/data/" + imagePath + "') -width, height = img.size -format = img.format - -# Resize if too large -if width > 1920: - ratio = 1920 / width - new_size = (1920, int(height * ratio)) - img = img.resize(new_size) - img.save('/data/resized_" + imagePath + "') - -print(json.dumps({ - 'original_size': [width, height], - 'format': format, - 'resized': width > 1920 -})) -" - -result = RUN PYTHON code -TALK "Image processed: " + result -``` - -### Multi-Language Pipeline - -```basic -' Use different languages for different strengths -data = GET "https://api.example.com/raw-data" - -' Step 1: Clean data with Python (pandas) -cleanCode = " -import pandas as pd -import json -df = pd.read_json('''" + data + "''') -df = df.dropna() -df = df[df['value'] > 0] -print(df.to_json(orient='records')) -" -cleanedData = RUN PYTHON cleanCode - -' Step 2: Transform with JavaScript (fast JSON manipulation) -transformCode = " -const data = JSON.parse('" + cleanedData + "'); -const result = data.reduce((acc, item) => { - acc[item.category] = (acc[item.category] || 0) + item.value; - return acc; -}, {}); -console.log(JSON.stringify(result)); -" -aggregated = RUN JAVASCRIPT transformCode - -TALK "Results: " + aggregated -``` - -## Sandbox Configuration - -### Runtime Options - -The sandbox supports multiple isolation backends: - -| Runtime | Security | Performance | Requirements | -|---------|----------|-------------|--------------| -| `LXC` | High | Excellent | LXC installed | -| `Docker` | High | Good | Docker daemon | -| `Firecracker` | Highest | Good | Firecracker binary | -| `Process` | Low | Best | None (fallback) | - -### Config.csv Options - -```csv -name,value -sandbox-runtime,lxc -sandbox-timeout,30 -sandbox-memory-mb,512 -sandbox-cpu-percent,50 -sandbox-network,false -sandbox-python-packages,numpy,pandas,pillow -sandbox-allowed-paths,/data,/tmp -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `sandbox-runtime` | `lxc` | Isolation backend to use | -| `sandbox-timeout` | `30` | Maximum execution time (seconds) | -| `sandbox-memory-mb` | `512` | Memory limit in MB | -| `sandbox-cpu-percent` | `50` | CPU usage limit | -| `sandbox-network` | `false` | Allow network access | -| `sandbox-python-packages` | (none) | Pre-installed Python packages | -| `sandbox-allowed-paths` | `/data,/tmp` | Accessible filesystem paths | - -## Security Considerations - -### What's Blocked - -- Direct file system access outside sandbox -- Network connections (unless `sandbox-network=true`) -- System calls (fork, exec, etc.) -- Environment variable access -- Process spawning - -### What's Allowed - -- Standard library operations -- File I/O within `/data` and `/tmp` -- Computation up to resource limits -- Pre-approved packages - -### Input Sanitization - -```basic -' IMPORTANT: Always sanitize user input before embedding in code -userInput = HEAR input -' Remove potential code injection -safeInput = REPLACE(userInput, "'", "\'") -safeInput = REPLACE(safeInput, '"', '\"') - -code = "print('User said: " + safeInput + "')" -result = RUN PYTHON code -``` - -## Error Handling - -```basic -' Handle execution errors -ON ERROR RESUME NEXT - -result = RUN PYTHON " -import nonexistent_module -print('hello') -" - -IF ERROR THEN - TALK "Code execution failed: " + ERROR_MESSAGE - ' Fall back to alternative approach -ELSE - TALK result -END IF -``` - -## Resource Limits - -| Resource | Default | Maximum | -|----------|---------|---------| -| Execution time | 30s | 300s | -| Memory | 512 MB | 4096 MB | -| CPU | 50% | 100% | -| Output size | 1 MB | 10 MB | -| File writes | 10 MB | 100 MB | - -## Related Keywords - -| Keyword | Description | -|---------|-------------| -| [`LLM`](./keyword-llm.md) | AI-generated code execution | -| [`GET`](./keyword-get.md) | Fetch data for processing | -| [`SAVE`](./keyword-save.md) | Store processed results | - -## Best Practices - -1. **Keep code snippets small** - Large scripts should use `WITH FILE` -2. **Sanitize all inputs** - Never trust user data in code strings -3. **Set appropriate timeouts** - Match timeout to expected execution time -4. **Use the right language** - Python for data, JS for JSON, Bash for files -5. **Handle errors gracefully** - Code can fail for many reasons -6. **Pre-install packages** - Don't pip install in every execution -7. **Log execution times** - Monitor for performance issues - -## Limitations - -- No persistent state between executions -- No GPU access (use dedicated ML endpoints instead) -- No interactive input (stdin) -- No graphical output (use file output instead) -- Package installation not allowed at runtime - -## See Also - -- [Code Sandbox Architecture](../chapter-07-gbapp/containers.md) - Technical details -- [Security Features](../chapter-12-auth/security-features.md) - Sandbox security model -- [Data Operations](./keywords-data.md) - Alternative data processing keywords \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-save.md b/docs/src/chapter-06-gbdialog/keyword-save.md deleted file mode 100644 index 4ac81dce..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-save.md +++ /dev/null @@ -1,188 +0,0 @@ -# SAVE - -Saves data to a database table using upsert (insert or update) semantics. - -## Syntax - -```basic -SAVE "table", id, data -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| table | String | The name of the database table | -| id | String/Number | The unique identifier for the record | -| data | Object | A map/object containing field names and values | - -## Description - -`SAVE` performs an upsert operation: -- If a record with the given `id` exists, it updates the record -- If no record exists, it inserts a new one - -The `id` parameter maps to the `id` column in the table. - -## Examples - -### Basic Save with Object - -```basic -' Create data object using Rhai map syntax -data = #{ - "customer_name": "João Silva", - "email": "joao@example.com", - "phone": "+5511999887766", - "status": "active" -} - -SAVE "customers", "CUST-001", data -``` - -### Save Order Data - -```basic -order_id = "ORD-" + FORMAT(NOW(), "YYYYMMDDHHmmss") - -order_data = #{ - "customer_id": customer_id, - "customer_name": customer_name, - "total": total, - "status": "pending", - "created_at": NOW() -} - -SAVE "orders", order_id, order_data - -TALK "Order " + order_id + " saved successfully!" -``` - -### Update Existing Record - -```basic -' If order exists, this updates it; otherwise creates it -update_data = #{ - "status": "shipped", - "shipped_at": NOW(), - "tracking_number": tracking -} - -SAVE "orders", order_id, update_data -``` - -### With WhatsApp Notification - -```basic -WEBHOOK "new-customer" - -customer_id = "CUST-" + FORMAT(NOW(), "YYYYMMDDHHmmss") -phone = body.phone -name = body.name - -customer_data = #{ - "name": name, - "phone": phone, - "source": "webhook", - "created_at": NOW() -} - -SAVE "customers", customer_id, customer_data - -' Notify via WhatsApp -TALK TO "whatsapp:" + phone, "Welcome " + name + "! Your account has been created." - -result_status = "ok" -result_customer_id = customer_id -``` - -### Building Data Dynamically - -```basic -' Start with empty map and add fields -data = #{} -data.name = customer_name -data.email = customer_email -data.phone = customer_phone -data.registered_at = NOW() - -IF has_referral THEN - data.referral_code = referral_code - data.discount = 10 -END IF - -SAVE "customers", customer_id, data -``` - -### Saving Multiple Related Records - -```basic -WEBHOOK "create-order" - -' Save order -order_id = body.order_id -order_data = #{ - "customer_id": body.customer_id, - "total": body.total, - "status": "pending" -} -SAVE "orders", order_id, order_data - -' Save each line item -FOR EACH item IN body.items - line_id = order_id + "-" + item.sku - line_data = #{ - "order_id": order_id, - "sku": item.sku, - "quantity": item.quantity, - "price": item.price - } - SAVE "order_items", line_id, line_data -NEXT item - -' Notify customer -TALK TO "whatsapp:" + body.customer_phone, "Order #" + order_id + " confirmed!" - -result_status = "ok" -``` - -## Return Value - -Returns an object with: -- `command`: "save" -- `table`: The table name -- `id`: The record ID -- `rows_affected`: Number of rows affected (1 for insert/update) - -## Notes - -- Table must exist in the database -- The `id` column is used as the primary key for conflict detection -- All string values are automatically sanitized to prevent SQL injection -- Column names are validated to prevent injection - -## Comparison with INSERT and UPDATE - -| Keyword | Behavior | -|---------|----------| -| `SAVE` | Upsert - inserts if new, updates if exists | -| `INSERT` | Always creates new record (may fail if ID exists) | -| `UPDATE` | Only updates existing records (no-op if not found) | - -```basic -' SAVE is preferred for most cases -SAVE "customers", id, data ' Insert or update - -' Use INSERT when you need a new record guaranteed -INSERT "logs", log_entry ' Always creates new - -' Use UPDATE for targeted updates -UPDATE "orders", "status=pending", update_data ' Update matching rows -``` - -## See Also - -- [INSERT](./keyword-insert.md) - Insert new records -- [UPDATE](./keyword-update.md) - Update existing records -- [DELETE](./keyword-delete.md) - Delete records -- [FIND](./keyword-find.md) - Query records \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-send-mail.md b/docs/src/chapter-06-gbdialog/keyword-send-mail.md deleted file mode 100644 index 091b2582..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-send-mail.md +++ /dev/null @@ -1,274 +0,0 @@ -# SEND MAIL - -Send email messages with optional attachments and HTML formatting. - -## Syntax - -```basic -SEND MAIL to, subject, body -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `to` | String | Recipient email address(es), comma-separated for multiple | -| `subject` | String | Email subject line | -| `body` | String | Email body (plain text or HTML) | - -## Description - -The `SEND MAIL` keyword sends emails using the SMTP configuration defined in `config.csv`. It supports: - -- Plain text and HTML emails -- Multiple recipients -- CC and BCC (via extended syntax) -- File attachments -- Email templates -- Delivery tracking - -## Configuration - -Email settings in `config.csv`: - -```csv -name,value -email-from,noreply@example.com -email-server,smtp.example.com -email-port,587 -email-user,smtp-user@example.com -email-pass,smtp-password -``` - -## Examples - -### Simple Text Email -```basic -SEND MAIL "user@example.com", "Welcome!", "Thank you for signing up." -``` - -### Multiple Recipients -```basic -recipients = "john@example.com, jane@example.com, bob@example.com" -SEND MAIL recipients, "Team Update", "Meeting tomorrow at 3 PM" -``` - -### HTML Email -```basic -body = "

Welcome!

Thank you for joining us.

" -body = body + "
  • Step 1: Complete profile
  • " -body = body + "
  • Step 2: Verify email
" -SEND MAIL "user@example.com", "Getting Started", body -``` - -### Dynamic Content -```basic -order_id = GET "order_id" -subject = "Order #" + order_id + " Confirmation" -body = "Hello " + user_name + ", your order has been confirmed." -SEND MAIL user_email, subject, body -``` - -### With Error Handling -```basic -email = HEAR "Enter your email address:" -IF email CONTAINS "@" AND email CONTAINS "." THEN - SEND MAIL email, "Verification Code", "Your code is: 123456" - TALK "Email sent successfully!" -ELSE - TALK "Invalid email address" -END IF -``` - -### Notification System -```basic -' Send notification to admin when issue detected -admin_email = GET BOT MEMORY "admin_email" -IF error_detected THEN - subject = "Bot Alert" - body = "Issue detected at " + NOW() - SEND MAIL admin_email, subject, body -END IF -``` - -### Bulk Email with Personalization -```basic -subscribers = GET "subscribers.list" -FOR EACH email IN subscribers - body = "Dear " + username + ", here's your weekly update..." - SEND MAIL email, "Weekly Newsletter", body - WAIT 1 ' Rate limiting -NEXT -``` - -## Extended Syntax - -### With CC and BCC -```basic -' Using structured format -email_data = { - "to": "primary@example.com", - "cc": "copy@example.com", - "bcc": "hidden@example.com", - "subject": "Report", - "body": "Please review attached report." -} -SEND MAIL email_data -``` - -### With Attachments -```basic -' Attach file from drive -email_data = { - "to": "user@example.com", - "subject": "Invoice", - "body": "Please find invoice attached.", - "attachments": ["invoice.pdf"] -} -SEND MAIL email_data -``` - -### Using Templates -```basic -' Load and fill template -template = LOAD_TEMPLATE "welcome_email" -template = REPLACE(template, "{{name}}", user_name) -template = REPLACE(template, "{{date}}", TODAY()) -SEND MAIL user_email, "Welcome!", template -``` - -## Email Validation - -Always validate email addresses before sending: - -```basic -email = HEAR "Your email:" -IF email CONTAINS "@" AND email CONTAINS "." THEN - parts = SPLIT(email, "@") - IF LENGTH(parts) = 2 THEN - domain = parts[1] - IF domain CONTAINS "." THEN - SEND MAIL email, "Test", "This is a test" - ELSE - TALK "Please enter a valid email" - END IF - ELSE - TALK "Please enter a valid email" - END IF -ELSE - TALK "Please enter a valid email" -END IF -``` - -## Delivery Status - -Check email delivery status: - -```basic -status = SEND MAIL "user@example.com", "Test", "Message" -IF status = "sent" THEN - TALK "Email delivered successfully" -ELSE IF status = "queued" THEN - TALK "Email queued for delivery" -ELSE - TALK "Email delivery failed: " + status -END IF -``` - -## Rate Limiting - -Implement rate limiting to avoid spam: - -```basic -last_sent = GET BOT MEMORY "last_email_time" -IF TIME_DIFF(NOW(), last_sent) < 60 THEN - TALK "Please wait before sending another email" -ELSE - SEND MAIL email, subject, body - SET BOT MEMORY "last_email_time", NOW() -END IF -``` - -## Error Handling - -Common error scenarios: - -```basic -' Check email format before sending -IF recipient CONTAINS "@" AND recipient CONTAINS "." THEN - status = SEND MAIL recipient, subject, body - IF status = "sent" THEN - TALK "Email sent successfully" - ELSE IF status = "smtp_error" THEN - TALK "Email server is unavailable" - ELSE IF status = "auth_error" THEN - TALK "Email authentication failed" - LOG "Check SMTP credentials in config.csv" - ELSE - TALK "Failed to send email: " + status - END IF -ELSE - TALK "The email address is invalid" -END IF -``` - -## Best Practices - -1. **Validate Recipients**: Always validate email addresses -2. **Rate Limit**: Implement delays for bulk emails -3. **Handle Failures**: Use try-catch for error handling -4. **Log Attempts**: Keep records of sent emails -5. **Test Configuration**: Verify SMTP settings before production -6. **Use Templates**: Maintain consistent formatting -7. **Respect Privacy**: Use BCC for multiple recipients -8. **Include Unsubscribe**: Add opt-out links for marketing emails - -## Security Considerations - -- Never log email passwords -- Use environment variables for sensitive data -- Implement SPF, DKIM, and DMARC for deliverability -- Sanitize user input in email bodies -- Use TLS/SSL for SMTP connections - -## Troubleshooting - -### Email Not Sending - -1. Check SMTP configuration in `config.csv` -2. Verify firewall allows port 587/465 -3. Test credentials manually -4. Check email server logs - -### Authentication Failed - -Check SMTP configuration: -1. Verify credentials in `config.csv` -2. Ensure SMTP server allows your connection -3. Check if port 587/465 is open -4. Verify TLS/SSL settings match server requirements - -### Emails Going to Spam - -- Set proper FROM address -- Include text version with HTML -- Avoid spam trigger words -- Configure domain authentication (SPF/DKIM) - -## Related Keywords - -- [GET](./keyword-get.md) - Retrieve user data for emails -- [FORMAT](./keyword-format.md) - Format email content -- [WAIT](./keyword-wait.md) - Rate limiting between emails -- [SET SCHEDULE](./keyword-set-schedule.md) - Schedule email sending - -## Implementation - -Located in `src/basic/keywords/send_mail.rs` - -The implementation uses: -- `lettre` crate for SMTP -- Async email sending -- Connection pooling for performance -- Retry logic for failed attempts -- HTML sanitization for security diff --git a/docs/src/chapter-06-gbdialog/keyword-send-template.md b/docs/src/chapter-06-gbdialog/keyword-send-template.md deleted file mode 100644 index 1a679f7c..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-send-template.md +++ /dev/null @@ -1,107 +0,0 @@ -# SEND TEMPLATE Keywords - -Send templated messages across multiple channels (email, WhatsApp, SMS, Telegram, push notifications). - -## Keywords - -| Keyword | Purpose | -|---------|---------| -| `SEND_TEMPLATE` | Send template to single recipient | -| `SEND_TEMPLATE_TO` | Send template to multiple recipients | -| `CREATE_TEMPLATE` | Create a new message template | -| `GET_TEMPLATE` | Retrieve template by name | - -## SEND_TEMPLATE - -```basic -result = SEND_TEMPLATE "welcome", "user@example.com", "email" -``` - -With variables: - -```basic -vars = {"name": "John", "order_id": "12345"} -result = SEND_TEMPLATE "order_confirmation", "+1234567890", "whatsapp", vars -``` - -## SEND_TEMPLATE_TO - -Send to multiple recipients: - -```basic -recipients = ["user1@example.com", "user2@example.com", "user3@example.com"] -result = SEND_TEMPLATE_TO "newsletter", recipients, "email" - -TALK "Sent: " + result.sent + ", Failed: " + result.failed -``` - -## Supported Channels - -| Channel | Recipient Format | -|---------|------------------| -| `email` | Email address | -| `whatsapp` | Phone number with country code | -| `sms` | Phone number with country code | -| `telegram` | Telegram user ID or username | -| `push` | Device token or user ID | - -## CREATE_TEMPLATE - -```basic -template_body = "Hello {{name}}, your order {{order_id}} has shipped!" -result = CREATE_TEMPLATE "shipping_notification", template_body, "transactional" -``` - -## Template Variables - -Use `{{variable_name}}` syntax in templates: - -```basic -vars = { - "customer_name": "Alice", - "amount": "$99.00", - "date": "March 15, 2024" -} -result = SEND_TEMPLATE "receipt", "alice@example.com", "email", vars -``` - -## Example: Order Notification - -```basic -' Send order confirmation across multiple channels -order_vars = { - "order_id": order.id, - "total": order.total, - "items": order.item_count -} - -SEND_TEMPLATE "order_placed", customer.email, "email", order_vars -SEND_TEMPLATE "order_placed", customer.phone, "whatsapp", order_vars -``` - -## Response Object - -```json -{ - "success": true, - "message_id": "msg_123abc", - "channel": "email", - "recipient": "user@example.com" -} -``` - -For batch sends: - -```json -{ - "total": 100, - "sent": 98, - "failed": 2, - "errors": [...] -} -``` - -## See Also - -- [SEND MAIL](./keyword-send-mail.md) -- [SEND SMS](./keyword-sms.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-set-bot-memory.md b/docs/src/chapter-06-gbdialog/keyword-set-bot-memory.md deleted file mode 100644 index f367c8db..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set-bot-memory.md +++ /dev/null @@ -1,165 +0,0 @@ -# SET BOT MEMORY - -Store persistent key-value data at the bot level that persists across all conversations. - -## Syntax - -```basic -SET BOT MEMORY key, value -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `key` | String | Unique identifier for the memory item | -| `value` | String | Value to store (can be any string data) | - -## Description - -The `SET BOT MEMORY` keyword stores data that is: -- Persistent across all user sessions -- Shared between all users of the same bot -- Stored in the database permanently -- Available until explicitly updated or cleared - -Bot memory is useful for: -- Configuration settings -- Global counters and statistics -- Shared state between users -- Bot-wide preferences -- Cached data that applies to all conversations - -## Examples - -### Store Simple Values -```basic -SET BOT MEMORY "welcome_message", "Hello! Welcome to our service." -SET BOT MEMORY "support_email", "support@example.com" -SET BOT MEMORY "business_hours", "9 AM - 5 PM EST" -``` - -### Store Counters -```basic -current_count = GET BOT MEMORY "visitor_count" -IF current_count = "" THEN - current_count = "0" -END IF -new_count = VAL(current_count) + 1 -SET BOT MEMORY "visitor_count", STR(new_count) -TALK "You are visitor number " + STR(new_count) -``` - -### Store JSON Data -```basic -user_data = '{"name": "John", "level": 5, "points": 1200}' -SET BOT MEMORY "user_profile", user_data -``` - -### Dynamic Keys -```basic -today = FORMAT(NOW(), "YYYY-MM-DD") -daily_key = "stats_" + today -SET BOT MEMORY daily_key, "25" -``` - -### Configuration Management -```basic -' Store bot configuration -SET BOT MEMORY "max_retries", "3" -SET BOT MEMORY "timeout_seconds", "30" -SET BOT MEMORY "api_version", "v2" - -' Later, read configuration -max_retries = GET BOT MEMORY "max_retries" -timeout = GET BOT MEMORY "timeout_seconds" -``` - -## Database Storage - -Bot memories are stored in the `bot_memories` table: -- `id`: UUID primary key -- `bot_id`: Reference to the bot -- `key`: Memory key (indexed for fast lookup) -- `value`: Memory value (text) -- `created_at`: Timestamp of creation -- `updated_at`: Timestamp of last update - -## Performance Considerations - -- Keys are indexed for fast retrieval -- Values are stored as text (no size limit in PostgreSQL) -- Updates are asynchronous to avoid blocking -- Consider using structured keys for organization - -## Best Practices - -1. **Use Descriptive Keys**: Make keys self-documenting - ```basic - SET BOT MEMORY "config:email:smtp_server", "mail.example.com" - SET BOT MEMORY "stats:daily:2024-01-15", "150" - ``` - -2. **Handle Missing Values**: Always check if memory exists - ```basic - value = GET BOT MEMORY "some_key" - IF value = "" THEN - ' Initialize with default - SET BOT MEMORY "some_key", "default_value" - value = "default_value" - END IF - ``` - -3. **Avoid Sensitive Data**: Don't store passwords or tokens - ```basic - ' BAD: Don't do this - ' SET BOT MEMORY "admin_password", "secret123" - - ' GOOD: Store non-sensitive config - SET BOT MEMORY "admin_email", "admin@example.com" - ``` - -4. **Structure Complex Data**: Use JSON for complex structures - ```basic - settings = '{"theme": "dark", "language": "en", "notifications": true}' - SET BOT MEMORY "user_preferences", settings - ``` - -5. **Clean Up Old Data**: Remove unused memories periodically - ```basic - ' Remove old daily stats - old_date = FORMAT(DATE_ADD(NOW(), -30, "days"), "YYYY-MM-DD") - SET BOT MEMORY "stats_" + old_date, "" - ``` - -## Differences from User Memory - -| Aspect | Bot Memory | User Memory | -|--------|------------|-------------| -| Scope | All users of the bot | Single user | -| Persistence | Permanent | Session or permanent | -| Use Case | Global settings | Personal data | -| Access | Any conversation | User's conversations only | - -## Error Handling - -- If database connection fails, operation is logged but doesn't crash -- Invalid bot IDs are logged as errors -- Duplicate keys update existing values -- Empty keys are not allowed - -## Related Keywords - -- [GET BOT MEMORY](./keyword-get-bot-memory.md) - Retrieve stored bot memory -- [SET](./keyword-set.md) - Set user-scoped variables -- [REMEMBER](./keyword-remember.md) - Store user-specific memories - -## Implementation - -Located in `src/basic/keywords/bot_memory.rs` - -The implementation: -- Uses async database operations -- Handles updates atomically with transactions -- Validates bot ID format -- Logs all operations for debugging \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-set-context.md b/docs/src/chapter-06-gbdialog/keyword-set-context.md deleted file mode 100644 index 2e7b7d04..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set-context.md +++ /dev/null @@ -1,71 +0,0 @@ -# SET_CONTEXT Keyword - -The **SET_CONTEXT** keyword defines the operational context for the bot’s current session. -It allows scripts to switch between different logical modes or workflows, influencing how subsequent commands are interpreted. - ---- - -## Syntax - -```basic -SET_CONTEXT "context-name" -``` - ---- - -## Parameters - -- `"context-name"` — A string representing the new context. - Common examples include `"sales_mode"`, `"support_mode"`, or `"training_mode"`. - ---- - -## Description - -`SET_CONTEXT` updates the bot’s internal state to reflect a specific operational context. -Contexts are used to modify behavior dynamically — for example, changing which tools are active, which memory entries are prioritized, or which prompts are used for LLM responses. - -When a context is set, the bot automatically adjusts its logic and available commands to match that mode. -This enables modular dialog design and flexible automation workflows. - -If the context name does not exist, the system creates a new one automatically and stores it in the session cache. - ---- - -## Example - -```basic -' Switch to sales mode -SET_CONTEXT "sales_mode" - -' Perform a context-specific action -TALK "Welcome to the sales assistant. How can I help you today?" - -' Later, switch to support mode -SET_CONTEXT "support_mode" -TALK "Support mode activated. Please describe your issue." -``` - ---- - -## Implementation Notes - -- Implemented in Rust under `src/context/mod.rs` and `src/context/langcache.rs`. -- The keyword interacts with the session manager and context cache to update the active context. -- Contexts are stored in memory and optionally persisted in cache component or a local cache file. -- Changing context may trigger automatic loading of associated tools or memory entries. - ---- - -## Related Keywords - -- [`SET BOT MEMORY`](keyword-set-bot-memory.md) — Stores persistent data for the bot or user. -- [`GET BOT MEMORY`](keyword-get-bot-memory.md) — Retrieves stored memory entries. -- [`SET SCHEDULE`](keyword-set-schedule.md) — Defines scheduled tasks that may depend on context. - ---- - -## Summary - -`SET_CONTEXT` is a key command for managing dynamic behavior in GeneralBots. -It enables flexible, modular workflows by allowing scripts to switch between operational modes seamlessly. diff --git a/docs/src/chapter-06-gbdialog/keyword-set-header.md b/docs/src/chapter-06-gbdialog/keyword-set-header.md deleted file mode 100644 index 2a670fd2..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set-header.md +++ /dev/null @@ -1 +0,0 @@ -# SET HEADER diff --git a/docs/src/chapter-06-gbdialog/keyword-set-schedule.md b/docs/src/chapter-06-gbdialog/keyword-set-schedule.md deleted file mode 100644 index c5fd1a66..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set-schedule.md +++ /dev/null @@ -1,302 +0,0 @@ -# SET SCHEDULE - -Schedule a script or task to run at specified times using natural language or cron expressions. - -## Syntax - -```basic -SET SCHEDULE expression -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `expression` | String | Natural language schedule or cron expression | - -## Description - -The `SET SCHEDULE` keyword schedules the current script to run automatically at specified intervals. It supports **natural language expressions** that are automatically converted to cron format, making scheduling intuitive and readable. - -## Natural Language Patterns - -### Time Intervals - -```basic -SET SCHEDULE "every minute" -SET SCHEDULE "every 5 minutes" -SET SCHEDULE "every 15 minutes" -SET SCHEDULE "every 30 minutes" -SET SCHEDULE "every hour" -SET SCHEDULE "every 2 hours" -SET SCHEDULE "every 6 hours" -SET SCHEDULE "every day" -SET SCHEDULE "every week" -SET SCHEDULE "every month" -SET SCHEDULE "every year" -``` - -### Aliases - -```basic -SET SCHEDULE "hourly" ' Same as "every hour" -SET SCHEDULE "daily" ' Same as "every day" -SET SCHEDULE "weekly" ' Same as "every week" -SET SCHEDULE "monthly" ' Same as "every month" -SET SCHEDULE "yearly" ' Same as "every year" -``` - -### Specific Times - -```basic -SET SCHEDULE "at 9am" -SET SCHEDULE "at 9:30am" -SET SCHEDULE "at 2pm" -SET SCHEDULE "at 14:00" -SET SCHEDULE "at midnight" -SET SCHEDULE "at noon" -``` - -### Day-Specific - -```basic -SET SCHEDULE "every monday" -SET SCHEDULE "every friday" -SET SCHEDULE "every sunday" -SET SCHEDULE "every monday at 9am" -SET SCHEDULE "every friday at 5pm" -``` - -### Weekdays & Weekends - -```basic -SET SCHEDULE "weekdays" ' Monday-Friday at midnight -SET SCHEDULE "every weekday" ' Same as above -SET SCHEDULE "weekdays at 8am" ' Monday-Friday at 8 AM -SET SCHEDULE "weekends" ' Saturday & Sunday at midnight -SET SCHEDULE "weekends at 10am" ' Saturday & Sunday at 10 AM -``` - -### Combined Patterns - -```basic -SET SCHEDULE "every day at 9am" -SET SCHEDULE "every day at 6:30pm" -SET SCHEDULE "every hour from 9 to 17" -``` - -### Business Hours - -```basic -SET SCHEDULE "business hours" ' Every hour 9-17, Mon-Fri -SET SCHEDULE "every hour during business hours" ' Same as above -SET SCHEDULE "every 30 minutes during business hours" ' Every 30 min, 9-17, Mon-Fri -SET SCHEDULE "every 15 minutes during business hours" -``` - -### Raw Cron (Advanced) - -You can still use standard cron expressions for maximum flexibility: - -```basic -SET SCHEDULE "0 * * * *" ' Every hour at minute 0 -SET SCHEDULE "*/5 * * * *" ' Every 5 minutes -SET SCHEDULE "0 9-17 * * 1-5" ' Hourly 9AM-5PM on weekdays -SET SCHEDULE "0 0 1 * *" ' First day of each month -``` - -## Cron Expression Format (Reference) - -``` -┌───────────── minute (0-59) -│ ┌───────────── hour (0-23) -│ │ ┌───────────── day of month (1-31) -│ │ │ ┌───────────── month (1-12) -│ │ │ │ ┌───────────── day of week (0-6, Sunday=0) -│ │ │ │ │ -* * * * * -``` - -## Quick Reference Table - -| Natural Language | Cron Equivalent | Description | -|-----------------|-----------------|-------------| -| `every minute` | `* * * * *` | Runs every minute | -| `every 5 minutes` | `*/5 * * * *` | Every 5 minutes | -| `every hour` | `0 * * * *` | Start of every hour | -| `hourly` | `0 * * * *` | Same as every hour | -| `every day` | `0 0 * * *` | Daily at midnight | -| `daily` | `0 0 * * *` | Same as every day | -| `at 9am` | `0 9 * * *` | Daily at 9 AM | -| `at 9:30am` | `30 9 * * *` | Daily at 9:30 AM | -| `at noon` | `0 12 * * *` | Daily at noon | -| `at midnight` | `0 0 * * *` | Daily at midnight | -| `every monday` | `0 0 * * 1` | Monday at midnight | -| `every monday at 9am` | `0 9 * * 1` | Monday at 9 AM | -| `weekdays` | `0 0 * * 1-5` | Mon-Fri at midnight | -| `weekdays at 8am` | `0 8 * * 1-5` | Mon-Fri at 8 AM | -| `weekends` | `0 0 * * 0,6` | Sat-Sun at midnight | -| `every week` | `0 0 * * 0` | Sunday at midnight | -| `weekly` | `0 0 * * 0` | Same as every week | -| `every month` | `0 0 1 * *` | 1st of month | -| `monthly` | `0 0 1 * *` | Same as every month | -| `business hours` | `0 9-17 * * 1-5` | Hourly 9-5 weekdays | -| `every hour from 9 to 17` | `0 9-17 * * *` | Hourly 9 AM - 5 PM | - -## Examples - -### Daily Report at 9 AM - -```basic -SET SCHEDULE "every day at 9am" - -data = GET "reports/daily.json" -summary = LLM "Summarize key metrics: " + data -SEND MAIL "team@company.com", "Daily Report", summary -``` - -### Hourly Data Sync - -```basic -SET SCHEDULE "every hour" - -fresh_data = GET "https://api.example.com/data" -SET BOT MEMORY "cached_data", fresh_data -PRINT "Data refreshed at " + NOW() -``` - -### Every 15 Minutes Monitoring - -```basic -SET SCHEDULE "every 15 minutes" - -status = GET "https://api.example.com/health" -IF status.healthy = false THEN - SEND MAIL "ops@company.com", "Alert: Service Down", status.message -END IF -``` - -### Weekly Newsletter (Monday 10 AM) - -```basic -SET SCHEDULE "every monday at 10am" - -subscribers = FIND "subscribers", "active=true" -content = LLM "Generate weekly newsletter with latest updates" - -FOR EACH email IN subscribers - SEND MAIL email.address, "Weekly Update", content -NEXT -``` - -### Business Hours Support Check - -```basic -SET SCHEDULE "every 30 minutes during business hours" - -tickets = FIND "support_tickets", "status=open AND priority=high" -IF LEN(tickets) > 5 THEN - TALK TO "support-manager", "High priority ticket queue: " + LEN(tickets) + " tickets waiting" -END IF -``` - -### Weekend Backup - -```basic -SET SCHEDULE "weekends at 3am" - -PRINT "Starting weekend backup..." -result = POST "https://backup.service/run", { "type": "full" } -SET BOT MEMORY "last_backup", NOW() -SEND MAIL "admin@company.com", "Backup Complete", result -``` - -### End of Month Report - -```basic -SET SCHEDULE "monthly" - -' Runs on 1st of each month at midnight -month_data = AGGREGATE "sales", "SUM(amount)", "month=" + MONTH(DATEADD("month", -1, NOW())) -report = LLM "Generate monthly sales report for: " + month_data -SEND MAIL "finance@company.com", "Monthly Sales Report", report -``` - -## Best Practices - -1. **Use Natural Language**: Prefer readable expressions like `"every day at 9am"` over cron syntax - -2. **Stagger Tasks**: Avoid scheduling all tasks at the same time - ```basic - ' Good: Different times - SET SCHEDULE "every day at 2am" ' Cleanup - SET SCHEDULE "every day at 3am" ' Backup - SET SCHEDULE "every day at 4am" ' Reports - ``` - -3. **Consider Time Zones**: Schedule times are in server's local time - -4. **Error Handling**: Always include error recovery - ```basic - SET SCHEDULE "every hour" - - TRY - PROCESS_DATA() - CATCH - PRINT "Schedule failed: " + ERROR_MESSAGE - SEND MAIL "admin@example.com", "Schedule Error", ERROR_DETAILS - END TRY - ``` - -5. **Idempotency**: Make scheduled tasks safe to re-run - ```basic - last_run = GET BOT MEMORY "last_process_time" - IF DATEDIFF("minute", last_run, NOW()) > 55 THEN - PROCESS() - SET BOT MEMORY "last_process_time", NOW() - END IF - ``` - -## Cancel Schedule - -Schedules are automatically canceled when `SET SCHEDULE` is removed from the `.bas` file. Simply delete or comment out the line: - -```basic -' SET SCHEDULE "every hour" ' Commented out = disabled -``` - -## Limitations - -- Maximum 100 scheduled tasks per bot -- Minimum interval: 1 minute -- Scripts timeout after 5 minutes by default -- Time zone is server's local time - -## Monitoring - -Scheduled tasks are logged automatically: -- Execution start/end times -- Success/failure status -- Error messages if any -- Performance metrics - -## Related Keywords - -- [GET BOT MEMORY](./keyword-get-bot-memory.md) - Store schedule state -- [SET BOT MEMORY](./keyword-set-bot-memory.md) - Persist data between runs -- [LLM](./keyword-llm.md) - Process data in scheduled tasks -- [SEND MAIL](./keyword-send-mail.md) - Send scheduled reports -- [GET](./keyword-get.md) - Fetch data for processing - -## Implementation - -Located in `src/basic/keywords/set_schedule.rs` - -The implementation: -- Uses a fast rule-based natural language parser (no LLM required) -- Falls back to raw cron if input is already in cron format -- Validates expressions before saving -- Integrates with system scheduler -- Persists schedules in database -- Handles concurrent execution -- Provides retry logic for failures \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-set-user-memory.md b/docs/src/chapter-06-gbdialog/keyword-set-user-memory.md deleted file mode 100644 index bffe6bae..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set-user-memory.md +++ /dev/null @@ -1,150 +0,0 @@ -# SET USER MEMORY - -Persists data at the user level, accessible across sessions and bots. Unlike `SET BOT MEMORY` which stores data per-bot, user memory follows the user wherever they go. - -## Syntax - -```basic -SET USER MEMORY "key", value -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `key` | String | Unique identifier for the stored value | -| `value` | Any | The value to store (string, number, object) | - -## Description - -`SET USER MEMORY` stores persistent data associated with a specific user. This data: - -- **Persists across sessions** - Available when user returns days/weeks later -- **Persists across bots** - Accessible from any bot the user interacts with -- **Survives restarts** - Stored in the database, not just memory -- **Supports TTL** - Optional time-to-live for automatic expiration - -This is ideal for user preferences, profile data, and cross-bot personalization. - -## Examples - -### Basic Usage - -```basic -' Store user preferences -SET USER MEMORY "language", "pt-BR" -SET USER MEMORY "timezone", "America/Sao_Paulo" -SET USER MEMORY "theme", "dark" - -TALK "Preferences saved!" -``` - -### Store Complex Objects - -```basic -' Store user profile -profile = #{ - name: username, - email: useremail, - plan: "premium", - signupDate: NOW() -} -SET USER MEMORY "profile", profile - -TALK "Profile updated successfully!" -``` - -### Cross-Bot Data Sharing - -```basic -' In sales-bot: Store purchase history -purchase = #{ - orderId: orderid, - amount: total, - date: NOW() -} -SET USER MEMORY "lastPurchase", purchase - -' In support-bot: Access the same data -lastPurchase = GET USER MEMORY("lastPurchase") -TALK "I see your last order was #" + lastPurchase.orderId -``` - -### User Preferences for Personalization - -```basic -' Check if returning user -name = GET USER MEMORY("name") - -IF name = "" THEN - TALK "Welcome! What's your name?" - HEAR name - SET USER MEMORY "name", name - TALK "Nice to meet you, " + name + "!" -ELSE - TALK "Welcome back, " + name + "!" -END IF -``` - -### Store User Facts - -```basic -' Store facts about the user for AI context -SET USER MEMORY "fact_occupation", "software engineer" -SET USER MEMORY "fact_interests", "AI, automation, productivity" -SET USER MEMORY "fact_company", "Acme Corp" - -' These can be used to personalize AI responses -``` - -## Related Keywords - -| Keyword | Description | -|---------|-------------| -| [`GET USER MEMORY`](./keyword-get-user-memory.md) | Retrieve user-level persisted data | -| [`SET BOT MEMORY`](./keyword-set-bot-memory.md) | Store data at bot level | -| [`GET BOT MEMORY`](./keyword-get-bot-memory.md) | Retrieve bot-level data | -| [`USER FACTS`](./keyword-user-facts.md) | Get all stored user facts | - -## Database Storage - -User memory is stored in the `user_memory` table with the following structure: - -| Column | Description | -|--------|-------------| -| `user_id` | The user's unique identifier | -| `key` | The memory key | -| `value` | JSON-encoded value | -| `memory_type` | Type classification (preference, fact, context) | -| `ttl` | Optional expiration timestamp | -| `created_at` | When the memory was created | -| `updated_at` | Last modification time | - -## Config.csv Options - -```csv -name,value -user-memory-enabled,true -user-memory-max-keys,1000 -user-memory-default-ttl,0 -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `user-memory-enabled` | `true` | Enable/disable user memory | -| `user-memory-max-keys` | `1000` | Maximum keys per user | -| `user-memory-default-ttl` | `0` | Default TTL in seconds (0 = no expiry) | - -## Best Practices - -1. **Use descriptive keys** - `user_language` not `lang` -2. **Prefix related keys** - `pref_theme`, `pref_language`, `fact_name` -3. **Don't store sensitive data** - No passwords or tokens -4. **Consider TTL for temporary data** - Session-specific data should expire -5. **Keep values reasonable size** - Don't store large files or blobs - -## See Also - -- [Memory Management](../chapter-11-features/memory-management.md) - Complete memory architecture -- [Multi-Agent Orchestration](../chapter-11-features/multi-agent-orchestration.md) - Cross-bot data sharing -- [User Context](../chapter-12-auth/user-system-context.md) - User vs system context \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-set-user.md b/docs/src/chapter-06-gbdialog/keyword-set-user.md deleted file mode 100644 index 494ccda0..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set-user.md +++ /dev/null @@ -1,62 +0,0 @@ -# SET USER Keyword - -Switch the current user context within a script execution. - -## Syntax - -```basic -SET USER user_id -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `user_id` | String (UUID) | The UUID of the user to switch to | - -## Description - -The `SET USER` keyword changes the active user context for subsequent operations in the script. This is useful for administrative scripts that need to perform actions on behalf of different users. - -## Example - -```basic -' Admin script to update user preferences -SET USER "550e8400-e29b-41d4-a716-446655440000" -SET USER MEMORY "theme", "dark" -SET USER MEMORY "language", "pt-BR" - -TALK "User preferences updated." -``` - -## Example: Batch User Operations - -```basic -' Process multiple users -users = GET "SELECT id FROM users WHERE needs_update = true" - -FOR EACH user IN users - SET USER user.id - SET USER MEMORY "migrated", "true" - SEND MAIL user.email, "Account Updated", "Your account has been migrated." -NEXT -``` - -## Use Cases - -- Administrative batch operations -- Multi-tenant management scripts -- User impersonation for support -- Scheduled maintenance tasks - -## Security - -- Requires admin privileges to execute -- All actions are logged with original admin identity -- Cannot escalate privileges beyond script permissions - -## See Also - -- [SET USER MEMORY](./keyword-set-user-memory.md) -- [GET USER MEMORY](./keyword-get-user-memory.md) -- [SET CONTEXT](./keyword-set-context.md) \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-set.md b/docs/src/chapter-06-gbdialog/keyword-set.md deleted file mode 100644 index b2297711..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-set.md +++ /dev/null @@ -1,257 +0,0 @@ -# SET - -Assign values to variables in BASIC dialogs. - -## Syntax - -```basic -SET variable = value -``` - -or simply: - -```basic -variable = value -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `variable` | Identifier | Variable name to assign to | -| `value` | Any | Value to assign (string, number, boolean, array, object) | - -## Description - -The `SET` keyword assigns values to variables within BASIC dialog scripts. Variables are dynamically typed and can hold any type of value. The `SET` keyword is optional - you can use direct assignment with `=`. - -Variables are scoped to the current dialog execution and persist throughout the conversation session until explicitly changed or the session ends. - -## Examples - -### Basic Assignment -```basic -SET name = "John Doe" -SET age = 25 -SET is_premium = true -SET score = 98.5 -``` - -### Direct Assignment (without SET) -```basic -name = "Jane Smith" -count = 0 -message = "Welcome!" -``` - -### Array Assignment -```basic -SET colors = ["red", "green", "blue"] -SET numbers = [1, 2, 3, 4, 5] -SET mixed = ["text", 123, true] -``` - -### Object/Map Assignment -```basic -SET user = { - "name": "Alice", - "email": "alice@example.com", - "age": 30, - "active": true -} -``` - -### Dynamic Values -```basic -SET current_time = NOW() -SET user_input = HEAR "What's your name?" -SET calculated = price * quantity * tax_rate -SET formatted = FORMAT("Hello, {0}!", username) -``` - -## Variable Types - -BASIC supports these variable types: -- **String**: Text values -- **Number**: Integers and decimals -- **Boolean**: true/false -- **Array**: Ordered lists -- **Object**: Key-value maps -- **Null**: Empty/undefined - -## Variable Naming - -Valid variable names: -- Start with letter or underscore -- Contain letters, numbers, underscores -- Case-sensitive -- No reserved keywords - -Examples: -```basic -SET userName = "John" -SET user_name = "John" -SET _private = true -SET value123 = 456 -SET firstName = "Jane" -``` - -Invalid names: -```basic -' These will cause errors -SET 123name = "error" ' Starts with number -SET user-name = "error" ' Contains hyphen -SET if = "error" ' Reserved keyword -``` - -## Variable Scope - -### Session Variables -Regular variables exist for the session: -```basic -SET session_data = "persists during conversation" -``` - -### Global Variables -Use special prefixes for broader scope: -```basic -SET $global_var = "accessible across dialogs" -SET @bot_var = "bot-level variable" -``` - -### Temporary Variables -```basic -SET _temp = "temporary use" -' Prefix with underscore for temporary/internal use -``` - -## Type Conversion - -Variables automatically convert types when needed: -```basic -SET text = "123" -SET number = text + 0 ' Converts to number: 123 -SET back_to_text = number + "" ' Converts to string: "123" -SET boolean = number > 100 ' Converts to boolean: true -``` - -## Operations on Variables - -### String Operations -```basic -SET full_name = first_name + " " + last_name -SET uppercase = UPPER(name) -SET length = LEN(message) -SET substring = MID(text, 1, 5) -``` - -### Numeric Operations -```basic -SET sum = a + b -SET difference = a - b -SET product = a * b -SET quotient = a / b -SET remainder = a MOD b -SET power = a ^ b -``` - -### Array Operations -```basic -SET first = colors[0] -SET last = colors[LEN(colors) - 1] -colors[1] = "yellow" ' Modify array element -SET combined = array1 + array2 ' Concatenate -``` - -### Object/Map Operations -```basic -SET email = user["email"] -SET age = user.age -user["status"] = "active" -user.last_login = NOW() -``` - -## Conditional Assignment - -```basic -SET status = IF(score >= 70, "pass", "fail") -SET discount = IF(is_member, 0.2, 0.1) -SET greeting = IF(hour < 12, "Good morning", "Good afternoon") -``` - -## Common Patterns - -### Counter Variables -```basic -SET counter = 0 -FOR i = 1 TO 10 - counter = counter + 1 -NEXT -``` - -### Flag Variables -```basic -SET is_complete = false -' ... process ... -SET is_complete = true -``` - -### Accumulator Variables -```basic -SET total = 0 -FOR EACH item IN cart - total = total + item.price -NEXT -``` - -### State Variables -```basic -SET state = "initial" -' ... logic ... -SET state = "processing" -' ... more logic ... -SET state = "complete" -``` - -## Best Practices - -1. **Use descriptive names**: `customer_email` instead of `e` -2. **Initialize variables**: Set initial values before use -3. **Use consistent naming**: camelCase or snake_case -4. **Avoid global pollution**: Use local variables when possible -5. **Clean up large variables**: Set to null when done -6. **Document complex variables**: Add comments -7. **Validate before use**: Check if variable exists - -## Error Handling - -```basic -' Check if variable exists -IF EXISTS(user_data) THEN - SET name = user_data.name -ELSE - SET name = "Guest" -END IF - -' Safe assignment with default -SET value = GET_VALUE_OR_DEFAULT(config.setting, "default") -``` - -## Memory Management - -```basic -' Clear large variables when done -SET big_data = LOAD_FILE("large.json") -' ... use big_data ... -SET big_data = null ' Free memory -``` - -## Related Keywords - -- [GET](./keyword-get.md) - Retrieve data from external sources -- [HEAR](./keyword-hear.md) - Get user input into variable -- [FORMAT](./keyword-format.md) - Format values for assignment -- [SET BOT MEMORY](./keyword-set-bot-memory.md) - Persistent storage -## Implementation Notes - -Variables are stored in the BASIC engine's scope map and persist for the duration of the dialog execution. The `SET` keyword is syntactic sugar - the parser treats both `SET x = y` and `x = y` identically. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-sms.md b/docs/src/chapter-06-gbdialog/keyword-sms.md deleted file mode 100644 index 93111de9..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-sms.md +++ /dev/null @@ -1,302 +0,0 @@ -# SEND SMS - -Send SMS text messages to phone numbers using various providers. - -## Syntax - -```basic -' Basic SMS sending -SEND SMS phone, message - -' With specific provider -SEND SMS phone, message, provider -``` - -## Parameters - -| Parameter | Type | Required | Description | -|-----------|------|----------|-------------| -| `phone` | String | Yes | Recipient phone number (E.164 format recommended) | -| `message` | String | Yes | The text message to send (max 160 chars for single SMS) | -| `provider` | String | No | SMS provider: `twilio`, `aws_sns`, `vonage`, `messagebird` | - -## Return Value - -Returns `true` if the SMS was sent successfully, `false` otherwise. - -## Configuration - -Configure SMS provider credentials in `config.csv`: - -```csv -key,value -sms-provider,twilio -twilio-account-sid,YOUR_ACCOUNT_SID -twilio-auth-token,YOUR_AUTH_TOKEN -twilio-phone-number,+15551234567 -``` - -### Provider-Specific Configuration - -**Twilio:** -```csv -sms-provider,twilio -twilio-account-sid,ACxxxxx -twilio-auth-token,your_token -twilio-phone-number,+15551234567 -``` - -**AWS SNS:** -```csv -sms-provider,aws_sns -aws-access-key-id,AKIAXXXXXXXX -aws-secret-access-key,your_secret -aws-region,us-east-1 -``` - -**Vonage (Nexmo):** -```csv -sms-provider,vonage -vonage-api-key,your_api_key -vonage-api-secret,your_secret -vonage-from-number,+15551234567 -``` - -**MessageBird:** -```csv -sms-provider,messagebird -messagebird-access-key,your_access_key -messagebird-originator,YourBrand -``` - -## Examples - -### Basic SMS - -```basic -HEAR phone AS TEXT "Enter phone number:" -SEND SMS phone, "Hello from General Bots!" -TALK "SMS sent successfully!" -``` - -### Order Confirmation - -```basic -' Send order confirmation via SMS -order_id = "ORD-2025-001" -phone = customer.phone - -message = "Your order " + order_id + " has been confirmed. " -message = message + "Estimated delivery: 2-3 business days." - -result = SEND SMS phone, message - -IF result THEN - TALK "Confirmation SMS sent to " + phone -ELSE - TALK "Failed to send SMS. We'll email you instead." - SEND MAIL customer.email, "Order Confirmation", message -END IF -``` - -### Two-Factor Authentication - -```basic -' Generate and send OTP -otp = RANDOM(100000, 999999) -REMEMBER "otp_" + user.id, otp, "5 minutes" - -message = "Your verification code is: " + otp + ". Valid for 5 minutes." -SEND SMS user.phone, message - -HEAR entered_code AS TEXT "Enter the code sent to your phone:" - -stored_otp = RECALL "otp_" + user.id - -IF entered_code = stored_otp THEN - TALK "✅ Phone verified successfully!" - SET USER MEMORY "phone_verified", true -ELSE - TALK "❌ Invalid code. Please try again." -END IF -``` - -### Appointment Reminder - -```basic -' Send appointment reminder -appointment_date = FORMAT(appointment.datetime, "MMMM D, YYYY") -appointment_time = FORMAT(appointment.datetime, "h:mm A") - -message = "Reminder: Your appointment is on " + appointment_date -message = message + " at " + appointment_time + ". Reply YES to confirm." - -SEND SMS patient.phone, message - -' Set up response handler -ON "sms:received" FROM patient.phone - IF UPPER(params.message) = "YES" THEN - UPDATE "appointments", appointment.id, "status", "confirmed" - SEND SMS patient.phone, "Thank you! Your appointment is confirmed." - END IF -END ON -``` - -### Multi-Language SMS - -```basic -' Send SMS in user's preferred language -lang = GET USER MEMORY "language" - -IF lang = "es" THEN - message = "Gracias por tu compra. Tu pedido está en camino." -ELSE IF lang = "pt" THEN - message = "Obrigado pela sua compra. Seu pedido está a caminho." -ELSE - message = "Thank you for your purchase. Your order is on the way." -END IF - -SEND SMS user.phone, message -``` - -### Using Different Providers - -```basic -' Use specific provider for different regions -country_code = LEFT(phone, 3) - -IF country_code = "+1 " THEN - ' Use Twilio for US/Canada - SEND SMS phone, message, "twilio" -ELSE IF country_code = "+55" THEN - ' Use local provider for Brazil - SEND SMS phone, message, "vonage" -ELSE - ' Default provider - SEND SMS phone, message -END IF -``` - -### Emergency Alert - -```basic -' Send emergency notification to multiple recipients -alert_message = "⚠️ ALERT: System maintenance in 30 minutes. Save your work." - -contacts = FIND "emergency_contacts", "notify=true" - -FOR EACH contact IN contacts - SEND SMS contact.phone, alert_message - WAIT 100 ' Small delay between messages -NEXT - -TALK "Emergency alert sent to " + COUNT(contacts) + " contacts" -``` - -### Delivery Tracking - -```basic -' Send delivery status updates -ON "delivery:status_changed" - order = FIND "orders", "id=" + params.order_id - - SWITCH params.status - CASE "shipped" - message = "📦 Your order has shipped! Tracking: " + params.tracking_number - CASE "out_for_delivery" - message = "🚚 Your package is out for delivery today!" - CASE "delivered" - message = "✅ Your package has been delivered. Enjoy!" - DEFAULT - message = "Order update: " + params.status - END SWITCH - - SEND SMS order.phone, message -END ON -``` - -## Phone Number Formats - -The keyword accepts various phone number formats: - -| Format | Example | Recommended | -|--------|---------|-------------| -| E.164 | `+14155551234` | ✅ Yes | -| National | `(415) 555-1234` | ⚠️ Converted | -| Digits only | `4155551234` | ⚠️ Needs country | - -**Best Practice:** Always use E.164 format (`+` followed by country code and number). - -## Message Length - -| Type | Characters | Notes | -|------|------------|-------| -| Single SMS | 160 | Standard ASCII | -| Unicode SMS | 70 | Emojis, non-Latin scripts | -| Concatenated | 153 × segments | Long messages split | - -```basic -' Check message length before sending -IF LEN(message) > 160 THEN - TALK "Warning: Message will be sent as multiple SMS" -END IF - -SEND SMS phone, message -``` - -## Error Handling - -```basic -' Handle SMS errors gracefully -TRY - result = SEND SMS phone, message - - IF NOT result THEN - ' Log the failure - INSERT "sms_failures", phone, message, NOW() - - ' Fallback to email if available - IF user.email <> "" THEN - SEND MAIL user.email, "Notification", message - END IF - END IF -CATCH error - TALK "SMS service unavailable: " + error.message -END TRY -``` - -## Cost Considerations - -SMS messages incur costs per message sent. Consider: - -- Using [SEND WHATSAPP](./universal-messaging.md) for free messaging when possible -- Batching non-urgent messages -- Using templates to keep messages under 160 characters - -## Compliance - -When sending SMS messages, ensure compliance with: - -- **TCPA** (US) - Require consent before sending -- **GDPR** (EU) - Document consent and provide opt-out -- **LGPD** (Brazil) - Similar consent requirements - -```basic -' Check opt-in before sending -IF GET USER MEMORY "sms_opt_in" = true THEN - SEND SMS phone, message -ELSE - TALK "User has not opted in to SMS notifications" -END IF -``` - -## See Also - -- [SEND WHATSAPP](./universal-messaging.md) - WhatsApp messaging -- [SEND MAIL](./keyword-send-mail.md) - Email messaging -- [SEND TEMPLATE](./universal-messaging.md) - Template messages -- [Universal Messaging](./universal-messaging.md) - Multi-channel messaging - -## Implementation - -The SEND SMS keyword is implemented in `src/basic/keywords/sms.rs` with support for multiple providers through a unified interface. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-soap.md b/docs/src/chapter-06-gbdialog/keyword-soap.md deleted file mode 100644 index c107b24c..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-soap.md +++ /dev/null @@ -1 +0,0 @@ -# SOAP diff --git a/docs/src/chapter-06-gbdialog/keyword-switch.md b/docs/src/chapter-06-gbdialog/keyword-switch.md deleted file mode 100644 index 8a79203e..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-switch.md +++ /dev/null @@ -1,249 +0,0 @@ -# SWITCH - -The `SWITCH` statement provides multi-way branching based on a value, allowing clean handling of multiple conditions without nested IF statements. - -## Syntax - -```basic -SWITCH expression - CASE value1 - ' statements for value1 - CASE value2 - ' statements for value2 - CASE value3, value4 - ' statements for value3 or value4 - DEFAULT - ' statements if no case matches -END SWITCH -``` - -## Parameters - -| Element | Description | -|---------|-------------| -| `expression` | The value to evaluate | -| `CASE value` | A specific value to match | -| `CASE value1, value2` | Multiple values for the same case | -| `DEFAULT` | Optional fallback when no case matches | - -## Description - -`SWITCH` evaluates an expression once and compares it against multiple `CASE` values. When a match is found, the corresponding statements execute. Unlike some languages, General Bots BASIC does not require explicit `BREAK` statements - execution automatically stops after the matched case. - -If no case matches and a `DEFAULT` block exists, those statements execute. If no case matches and there's no `DEFAULT`, execution continues after `END SWITCH`. - -## Examples - -### Role-Based Knowledge Base Selection - -```basic -role = GET role - -SWITCH role - CASE "manager" - USE KB "management" - USE KB "reports" - CASE "developer" - USE KB "documentation" - USE KB "apis" - CASE "customer" - USE KB "products" - USE KB "support" - DEFAULT - USE KB "general" -END SWITCH -``` - -### Menu Navigation - -```basic -TALK "Select an option:" -TALK "1. Check balance" -TALK "2. Transfer funds" -TALK "3. View history" -TALK "4. Exit" - -choice = HEAR "Enter your choice:" - -SWITCH choice - CASE "1" - balance = GET BOT MEMORY "balance" - TALK "Your balance is: $" + balance - CASE "2" - TALK "Transfer initiated..." - ' Transfer logic here - CASE "3" - history = FIND "recent transactions" - TALK history - CASE "4" - TALK "Goodbye!" - DEFAULT - TALK "Invalid option. Please choose 1-4." -END SWITCH -``` - -### Multiple Values Per Case - -```basic -day = GET day_of_week - -SWITCH day - CASE "monday", "tuesday", "wednesday", "thursday", "friday" - TALK "It's a weekday. Office hours: 9am-5pm" - CASE "saturday", "sunday" - TALK "It's the weekend. We're closed." - DEFAULT - TALK "Unknown day" -END SWITCH -``` - -### Language Selection - -```basic -lang = GET user_language - -SWITCH lang - CASE "en" - TALK "Hello! How can I help you today?" - CASE "es" - TALK "¡Hola! ¿Cómo puedo ayudarte hoy?" - CASE "pt" - TALK "Olá! Como posso ajudá-lo hoje?" - CASE "fr" - TALK "Bonjour! Comment puis-je vous aider?" - DEFAULT - TALK "Hello! How can I help you today?" -END SWITCH -``` - -### Department Routing - -```basic -department = HEAR "Which department? (sales, support, billing)" - -SWITCH department - CASE "sales" - SET CONTEXT "You are a sales assistant. Focus on products and pricing." - USE KB "products" - USE KB "pricing" - CASE "support" - SET CONTEXT "You are a technical support agent. Help resolve issues." - USE KB "troubleshooting" - USE KB "faq" - CASE "billing" - SET CONTEXT "You are a billing specialist. Handle payment questions." - USE KB "invoices" - USE KB "payment_methods" - DEFAULT - TALK "I'll connect you with general assistance." - USE KB "general" -END SWITCH -``` - -### Status Code Handling - -```basic -status = GET api_response_status - -SWITCH status - CASE "200" - TALK "Request successful!" - CASE "400" - TALK "Bad request. Please check your input." - CASE "401", "403" - TALK "Authentication error. Please log in again." - CASE "404" - TALK "Resource not found." - CASE "500", "502", "503" - TALK "Server error. Please try again later." - DEFAULT - TALK "Unexpected status: " + status -END SWITCH -``` - -### Numeric Ranges (Using Categories) - -```basic -score = GET test_score -grade = "" - -' Convert score to grade category -IF score >= 90 THEN - grade = "A" -ELSE IF score >= 80 THEN - grade = "B" -ELSE IF score >= 70 THEN - grade = "C" -ELSE IF score >= 60 THEN - grade = "D" -ELSE - grade = "F" -END IF - -SWITCH grade - CASE "A" - TALK "Excellent work!" - SET BOT MEMORY "achievement", "honor_roll" - CASE "B" - TALK "Good job!" - CASE "C" - TALK "Satisfactory performance." - CASE "D" - TALK "You passed, but could improve." - CASE "F" - TALK "Please see a tutor for help." -END SWITCH -``` - -## Comparison with IF-ELSE - -### Using IF-ELSE (Verbose) - -```basic -IF color = "red" THEN - TALK "Stop" -ELSE IF color = "yellow" THEN - TALK "Caution" -ELSE IF color = "green" THEN - TALK "Go" -ELSE - TALK "Unknown signal" -END IF -``` - -### Using SWITCH (Cleaner) - -```basic -SWITCH color - CASE "red" - TALK "Stop" - CASE "yellow" - TALK "Caution" - CASE "green" - TALK "Go" - DEFAULT - TALK "Unknown signal" -END SWITCH -``` - -## Notes - -- **No fall-through**: Each CASE is isolated; no BREAK needed -- **Case sensitivity**: String comparisons are case-sensitive -- **Expression evaluated once**: The switch expression is evaluated only once -- **DEFAULT is optional**: Without DEFAULT, unmatched values skip the block -- **Multiple values**: Use commas to match multiple values in one CASE - -## Best Practices - -1. **Always include DEFAULT** for robust error handling -2. **Use meaningful case values** that are self-documenting -3. **Order cases logically** - most common first or alphabetically -4. **Keep case blocks concise** - extract complex logic to separate scripts - -## See Also - -- [SET CONTEXT](./keyword-set-context.md) - Set conversation context -- [USE KB](./keyword-use-kb.md) - Load knowledge base -- [GET](./keyword-get.md) - Get variable values -- [IF/THEN/ELSE](./keyword-if.md) - Conditional branching \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-synchronize.md b/docs/src/chapter-06-gbdialog/keyword-synchronize.md deleted file mode 100644 index a2b4dae5..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-synchronize.md +++ /dev/null @@ -1,123 +0,0 @@ -# SYNCHRONIZE - -Synchronizes data from an external API endpoint to a local database table with automatic pagination. - -## Status - -⚠️ **Planned Feature** - This keyword is documented for the Bling ERP integration template but implementation is pending. - -## Syntax - -```basic -SYNCHRONIZE endpoint, tableName, keyField, pageParam, limitParam -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `endpoint` | String | API endpoint path (appended to `host` variable) | -| `tableName` | String | Target table name (with optional connection prefix) | -| `keyField` | String | Primary key field for upsert operations | -| `pageParam` | String | Name of the pagination parameter in API | -| `limitParam` | String | Name of the limit parameter in API | - -## Description - -`SYNCHRONIZE` provides a high-level abstraction for syncing paginated API data to a database table. It: - -1. Iterates through all pages of the API endpoint -2. Fetches data using the configured `host`, `limit`, and `pages` variables -3. Performs upsert (merge) operations on the target table -4. Tracks statistics in the `REPORT` variable -5. Handles rate limiting automatically - -## Prerequisites - -The following variables must be defined (typically via `config.csv` param-* entries): - -```csv -name,value -param-host,https://api.example.com/v1 -param-limit,100 -param-pages,50 -``` - -## Example - -```basic -' Sync categories from ERP -pageVariable = "pagina" -limitVariable = "limite" - -SEND EMAIL admin, "Syncing categories..." -SYNCHRONIZE /categorias/receitas-despesas, maria.CategoriaReceita, Id, pageVariable, limitVariable -SEND EMAIL admin, REPORT -RESET REPORT - -' Sync payment methods -SYNCHRONIZE /formas-pagamentos, maria.FormaDePagamento, Id, pageVariable, limitVariable -SEND EMAIL admin, REPORT -RESET REPORT -``` - -## Equivalent Manual Implementation - -Until `SYNCHRONIZE` is implemented, use this pattern: - -```basic -' Manual sync equivalent -pageVariable = "pagina" -limitVariable = "limite" -tableName = "maria.CategoriaReceita" -endpoint = "/categorias/receitas-despesas" - -page = 1 -totalSynced = 0 - -DO WHILE page > 0 AND page <= pages - url = host + endpoint + "?" + pageVariable + "=" + page + "&" + limitVariable + "=" + limit - res = GET url - WAIT 0.33 ' Rate limiting - - IF res.data AND UBOUND(res.data) > 0 THEN - MERGE tableName WITH res.data BY "Id" - totalSynced = totalSynced + UBOUND(res.data) - page = page + 1 - - IF UBOUND(res.data) < limit THEN - page = 0 ' Last page - END IF - ELSE - page = 0 ' No more data - END IF -LOOP - -TALK "Synced " + totalSynced + " records to " + tableName -``` - -## Used In - -- [Bling ERP Template](../../../templates/bling.gbai/) - ERP synchronization scripts - -## Related Keywords - -- [GET](./keyword-get.md) - HTTP GET requests -- [MERGE](./keyword-merge.md) - Upsert data operations -- [SET SCHEDULE](./keyword-set-schedule.md) - Schedule sync jobs -- [REPORT / RESET REPORT](./keyword-report.md) - Sync statistics - -## Implementation Notes - -When implemented, `SYNCHRONIZE` should: - -1. Use the global `host`, `limit`, `pages` variables from config -2. Support connection prefixes (e.g., `maria.TableName`) -3. Handle API errors gracefully with retry logic -4. Update the `REPORT` variable with sync statistics -5. Support both REST JSON responses and paginated arrays - -## See Also - -- [Script Execution Flow](./script-execution-flow.md) - How config variables are injected -- [Data Operations](./keywords-data.md) - Data manipulation keywords \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-table.md b/docs/src/chapter-06-gbdialog/keyword-table.md deleted file mode 100644 index abb5a36c..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-table.md +++ /dev/null @@ -1,223 +0,0 @@ -# TABLE Keyword - -The `TABLE` keyword defines database tables directly in your `.bas` files. Tables are automatically created on the specified database connection when the script is compiled. - -## Syntax - -```bas -TABLE TableName ON connection - FieldName dataType[(length[,precision])] [key] [references OtherTable] - ... -END TABLE -``` - -## Parameters - -| Parameter | Description | -|-----------|-------------| -| `TableName` | Name of the table to create | -| `connection` | Connection name defined in config.csv (e.g., `maria`, `sales_db`) | -| `FieldName` | Name of the field/column | -| `dataType` | Data type (see supported types below) | -| `length` | Optional length for string/number types | -| `precision` | Optional decimal precision for number types | -| `key` | Marks field as primary key | -| `references` | Creates a foreign key reference to another table | - -## Supported Data Types - -| Type | Description | SQL Mapping | -|------|-------------|-------------| -| `string(n)` | Variable-length string | VARCHAR(n) | -| `number` | Integer | INTEGER | -| `number(n)` | Big integer | BIGINT | -| `number(n,p)` | Decimal with precision | DECIMAL(n,p) | -| `integer` | Integer | INTEGER | -| `double` | Double precision float | DOUBLE PRECISION | -| `double(n,p)` | Decimal | DECIMAL(n,p) | -| `date` | Date only | DATE | -| `datetime` | Date and time | TIMESTAMP/DATETIME | -| `boolean` | True/false | BOOLEAN | -| `text` | Long text | TEXT | -| `guid` | UUID | UUID/CHAR(36) | - -## Connection Configuration - -External database connections are configured in `config.csv` with the following format: - -| Key | Description | -|-----|-------------| -| `conn-{name}-Server` | Database server hostname or IP | -| `conn-{name}-Name` | Database name | -| `conn-{name}-Username` | Username for authentication | -| `conn-{name}-Password` | Password for authentication | -| `conn-{name}-Port` | Port number (optional, uses default) | -| `conn-{name}-Driver` | Database driver: `mysql`, `mariadb`, `postgres`, `mssql` | - -### Example config.csv - -```csv -conn-maria-Server,192.168.1.100 -conn-maria-Name,sales_database -conn-maria-Username,app_user -conn-maria-Password,secure_password -conn-maria-Port,3306 -conn-maria-Driver,mariadb -``` - -## Examples - -### Basic Table Definition - -```bas -TABLE Contacts ON maria - Id number key - Nome string(150) - Email string(255) - Telefone string(20) - DataCadastro date -END TABLE -``` - -### Table with Multiple Field Types - -```bas -TABLE Produtos ON maria - Id number key - Nome string(150) - Sku string(20) - Preco double(10,2) - Estoque integer - Ativo boolean - DescricaoCurta string(4000) - DataValidade date - Categoria_id integer -END TABLE -``` - -### Table with Foreign Key References - -```bas -TABLE Pedidos ON maria - Id number key - Numero integer - Data date - Total double(15,2) - Contato_id number - Situacao_id integer - Vendedor_id number -END TABLE - -TABLE PedidosItem ON maria - Id number key - Pedido_id number - Produto_id number - Quantidade integer - Valor double(10,2) - Desconto double(5,2) -END TABLE -``` - -### Complete CRM Tables Example - -```bas -' Contact management tables -TABLE Contatos ON maria - Id number key - Nome string(150) - Codigo string(50) - Situacao string(5) - NumeroDocumento string(25) - Telefone string(20) - Celular string(20) - Email string(50) - Endereco_geral_endereco string(100) - Endereco_geral_cep string(10) - Endereco_geral_bairro string(50) - Endereco_geral_municipio string(50) - Endereco_geral_uf string(5) - Vendedor_id number - DadosAdicionais_dataNascimento date - Financeiro_limiteCredito double -END TABLE - -' Payment methods -TABLE FormaDePagamento ON maria - Id number key - Descricao string(255) - TipoPagamento integer - Situacao integer - Padrao integer - Taxas_aliquota double - Taxas_valor double -END TABLE - -' Accounts receivable -TABLE ContasAReceber ON maria - Id number key - Situacao integer - Vencimento date - Valor double - Contato_id number - FormaPagamento_id number - Saldo double - DataEmissao date - NumeroDocumento string(50) -END TABLE -``` - -## Using Tables After Creation - -Once tables are defined, you can use standard BASIC keywords to work with the data: - -### Inserting Data - -```bas -data = NEW OBJECT -data.Nome = "João Silva" -data.Email = "joao@example.com" -data.Telefone = "11999999999" -INSERT "Contatos", data -``` - -### Finding Data - -```bas -contacts = FIND "Contatos", "Situacao='A'" -FOR EACH contact IN contacts - TALK "Name: " + contact.Nome -NEXT -``` - -### Updating Data - -```bas -UPDATE "Contatos", "Id=123", "Telefone='11988888888'" -``` - -### Deleting Data - -```bas -DELETE "Contatos", "Id=123" -``` - -## Notes - -1. **Automatic Table Creation**: Tables are created automatically when the `.bas` file is compiled. If the table already exists, no changes are made. - -2. **Connection Required**: The connection name must be configured in `config.csv` before using it in TABLE definitions. - -3. **Primary Keys**: Fields marked with `key` become the primary key. Multiple fields can be marked as key for composite primary keys. - -4. **Default Connection**: If `ON connection` is omitted, the table is created on the default (internal) PostgreSQL database. - -5. **SQL Injection Protection**: All identifiers are sanitized to prevent SQL injection attacks. - -## See Also - -- [FIND](./keyword-find.md) - Query data from tables -- [SAVE](./keyword-save.md) - Insert or update data -- [INSERT](./keyword-insert.md) - Insert new records -- [UPDATE](./keyword-update.md) - Update existing records -- [DELETE](./keyword-delete.md) - Delete records -- [config.csv](../chapter-08-config/config-csv.md) - Connection configuration \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-talk.md b/docs/src/chapter-06-gbdialog/keyword-talk.md deleted file mode 100644 index 9d166ec8..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-talk.md +++ /dev/null @@ -1,248 +0,0 @@ -# TALK - -Sends a message to the current conversation or to a specific recipient on any supported channel. - -## Syntax - -```basic -TALK message - -TALK TO recipient, message -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| message | String | The message to send | -| recipient | String | Channel and address in format `channel:address` | - -## Description - -`TALK` is the primary keyword for sending messages in General Bots BASIC. - -- **TALK message** - Sends to the current conversation (web chat, WhatsApp, etc.) -- **TALK TO recipient, message** - Sends to a specific recipient on any channel - -## TALK - Current Conversation - -Send a message to whoever is currently chatting with the bot: - -```basic -TALK "Hello! How can I help you today?" - -name = "João" -TALK "Welcome, " + name + "!" - -total = 299.90 -TALK "Your total is $" + total -``` - -## TALK TO - Specific Recipients - -Send messages to specific people on specific channels using the format `channel:address`. - -### Supported Channels - -| Channel | Format | Example | -|---------|--------|---------| -| WhatsApp | `whatsapp:+phone` | `whatsapp:+5511999887766` | -| Teams | `teams:user@domain` | `teams:john@company.com` | -| Email | `email:address` | `email:customer@example.com` | -| Web Session | `web:session_id` | `web:abc123` | -| Instagram | `instagram:username` | `instagram:@myuser` | - -### WhatsApp Examples - -```basic -' Send simple message -TALK TO "whatsapp:+5511999887766", "Your order has been shipped!" - -' Send with variables -phone = "+5511999887766" -customer_name = "Maria" -TALK TO "whatsapp:" + phone, "Hello " + customer_name + "! Your order is ready." - -' Send formatted message (WhatsApp supports markdown-like formatting) -message = "*Order Confirmed* ✅\n\n" -message = message + "Order: #12345\n" -message = message + "Total: R$ 299,90\n\n" -message = message + "_Thank you for your purchase!_" -TALK TO "whatsapp:" + customer_phone, message -``` - -### WhatsApp Message Formatting - -WhatsApp supports rich text formatting: - -| Format | Syntax | Result | -|--------|--------|--------| -| Bold | `*text*` | **text** | -| Italic | `_text_` | *text* | -| Strikethrough | `~text~` | ~~text~~ | -| Monospace | `` `text` `` | `text` | -| Line break | `\n` | New line | - -```basic -' Example with all formatting -msg = "🎉 *PROMOTION!*\n\n" -msg = msg + "~R$ 199,90~ *R$ 149,90*\n" -msg = msg + "_Limited time offer!_\n\n" -msg = msg + "Use code: `PROMO2024`" - -TALK TO "whatsapp:" + phone, msg -``` - -### Microsoft Teams Examples - -```basic -' Send to Teams user -TALK TO "teams:john.smith@company.com", "Meeting reminder: 3pm today" - -' Send with formatting (Teams supports markdown) -msg = "**Project Update**\n\n" -msg = msg + "- Task 1: ✅ Complete\n" -msg = msg + "- Task 2: 🔄 In Progress\n" -msg = msg + "- Task 3: ⏳ Pending" - -TALK TO "teams:" + manager_email, msg -``` - -### Email Examples - -```basic -' Simple email (uses SEND MAIL internally for full email) -TALK TO "email:customer@example.com", "Your password has been reset." - -' For full email with subject, use SEND MAIL instead -SEND MAIL "customer@example.com", "Password Reset", "Your password has been reset successfully." -``` - -## Complete Examples - -### Order Notification System - -```basic -WEBHOOK "order-status" - -order_id = body.order_id -customer_phone = body.phone -status = body.status - -SELECT CASE status - CASE "confirmed" - msg = "✅ *Order Confirmed*\n\n" - msg = msg + "Order #" + order_id + "\n" - msg = msg + "We're preparing your order!" - - CASE "shipped" - tracking = body.tracking_number - msg = "📦 *Order Shipped*\n\n" - msg = msg + "Order #" + order_id + "\n" - msg = msg + "Tracking: " + tracking + "\n" - msg = msg + "Track at: https://track.example.com/" + tracking - - CASE "delivered" - msg = "🎉 *Order Delivered*\n\n" - msg = msg + "Order #" + order_id + "\n" - msg = msg + "Enjoy your purchase!\n\n" - msg = msg + "_Rate your experience: reply 1-5_" - - CASE ELSE - msg = "Order #" + order_id + " status: " + status -END SELECT - -TALK TO "whatsapp:" + customer_phone, msg - -result_status = "ok" -``` - -### Support Ticket Notifications - -```basic -SUB NotifyCustomer(phone, ticket_id, message) - full_msg = "🎫 *Ticket #" + ticket_id + "*\n\n" - full_msg = full_msg + message - TALK TO "whatsapp:" + phone, full_msg -END SUB - -SUB NotifyAgent(agent_email, ticket_id, customer_name, issue) - msg = "New ticket assigned:\n\n" - msg = msg + "Ticket: #" + ticket_id + "\n" - msg = msg + "Customer: " + customer_name + "\n" - msg = msg + "Issue: " + issue - TALK TO "teams:" + agent_email, msg -END SUB - -' Usage -CALL NotifyCustomer("+5511999887766", "TKT-001", "Your ticket has been created. We'll respond within 24 hours.") -CALL NotifyAgent("support@company.com", "TKT-001", "João Silva", "Payment issue") -``` - -### Multi-Channel Broadcast - -```basic -SUB Broadcast(message, channels) - FOR EACH channel IN channels - TALK TO channel, message - WAIT 1 ' Rate limiting - NEXT channel -END SUB - -' Send to multiple recipients -promo = "🎉 *Flash Sale!* 50% off everything today only!" - -recipients = [ - "whatsapp:+5511999887766", - "whatsapp:+5511888776655", - "teams:marketing@company.com" -] - -CALL Broadcast(promo, recipients) -``` - -### Appointment Reminders - -```basic -WEBHOOK "send-reminder" - -appointment_id = body.id -appointment = FIND "appointments", "id=" + appointment_id - -phone = appointment.customer_phone -name = appointment.customer_name -service = appointment.service -date_time = FORMAT(appointment.datetime, "DD/MM/YYYY HH:mm") - -reminder = "📅 *Appointment Reminder*\n\n" -reminder = reminder + "Hi " + name + "!\n\n" -reminder = reminder + "You have an appointment scheduled:\n\n" -reminder = reminder + "📋 " + service + "\n" -reminder = reminder + "🗓️ " + date_time + "\n\n" -reminder = reminder + "Reply *CONFIRM* to confirm or *CANCEL* to cancel." - -TALK TO "whatsapp:" + phone, reminder - -result_status = "ok" -``` - -## Notes - -- **TALK** sends to the current active conversation -- **TALK TO** can send to any supported channel -- WhatsApp requires phone numbers in international format with country code -- Teams requires valid email addresses from your organization -- Message formatting varies by channel (WhatsApp uses different syntax than Teams) -- Rate limiting may apply - use `WAIT` between bulk messages - -## Related Keywords - -- [SEND FILE TO](./keyword-send-file-to.md) - Send files to specific recipients -- [SEND MAIL](./keyword-send-mail.md) - Send emails with subject and attachments -- [HEAR](./keyword-hear.md) - Receive input from users -- [PRINT](./keyword-print.md) - Alias for TALK (debug output) - -## See Also - -- [Universal Messaging](./universal-messaging.md) - Multi-channel messaging overview -- [WEBHOOK](./keyword-webhook.md) - Create API endpoints \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-update.md b/docs/src/chapter-06-gbdialog/keyword-update.md deleted file mode 100644 index 5427cf1f..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-update.md +++ /dev/null @@ -1 +0,0 @@ -# UPDATE diff --git a/docs/src/chapter-06-gbdialog/keyword-upload.md b/docs/src/chapter-06-gbdialog/keyword-upload.md deleted file mode 100644 index 5f034213..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-upload.md +++ /dev/null @@ -1 +0,0 @@ -# UPLOAD diff --git a/docs/src/chapter-06-gbdialog/keyword-use-kb.md b/docs/src/chapter-06-gbdialog/keyword-use-kb.md deleted file mode 100644 index 0f70cbf3..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-use-kb.md +++ /dev/null @@ -1,130 +0,0 @@ -# USE KB - -Activate a knowledge base collection for semantic search. - -## Syntax - -```basic -USE KB "collection_name" -USE KB collection_variable -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `collection_name` | String | Name of folder inside `.gbkb/` | - -## Description - -Loads a knowledge base collection, enabling automatic semantic search for that content. Once active, the LLM searches this collection when answering questions - no explicit search code needed. - -## Examples - -### Basic Usage - -```basic -USE KB "policies" -' Bot now answers questions using policy documents -``` - -### Multiple Collections - -```basic -USE KB "products" -USE KB "pricing" -USE KB "support" -' All three collections searchable -``` - -### Conditional Loading - -```basic -dept = GET user_department -IF dept = "HR" THEN - USE KB "hr_policies" -ELSE IF dept = "IT" THEN - USE KB "it_docs" -END IF -``` - -### Dynamic Collection - -```basic -topic = HEAR "What topic?" -USE KB topic -``` - -## How It Works - -1. User asks question -2. System searches active collections -3. Top matching chunks added to LLM context -4. LLM generates informed response - -## Collection Structure - -``` -bot.gbkb/ -├── policies/ → USE KB "policies" -├── products/ → USE KB "products" -└── support/ → USE KB "support" -``` - -## Supported File Types - -PDF, DOCX, TXT, MD, HTML, CSV, JSON - -## Performance - -- Each collection uses ~50MB RAM when active -- First search: 100-200ms -- Subsequent: 20-50ms (cached) - -**Tip:** Load only what's needed, clear when done. - -## Common Patterns - -### Role-Based - -```basic -SWITCH GET user_role - CASE "manager" - USE KB "management" - CASE "developer" - USE KB "documentation" - CASE "customer" - USE KB "products" -END SWITCH -``` - -### With Context - -```basic -USE KB "technical_docs" -SET CONTEXT "You are a technical expert" AS prompt -``` - -### With Website - -```basic -USE WEBSITE "https://docs.example.com" -USE KB "documentation" -' Fresh web content now searchable -``` - -## Error Handling - -```basic -TRY - USE KB user_requested_kb -CATCH - TALK "That knowledge base doesn't exist" -END TRY -``` - -## See Also - -- [CLEAR KB](./keyword-clear-kb.md) - Deactivate collections -- [Knowledge Base System](../chapter-03/README.md) - Technical details -- [Semantic Search](../chapter-03/semantic-search.md) - How search works \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-use-model.md b/docs/src/chapter-06-gbdialog/keyword-use-model.md deleted file mode 100644 index f62feed1..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-use-model.md +++ /dev/null @@ -1,185 +0,0 @@ -# USE MODEL - -Dynamically switches the LLM model used for AI operations within a script. Enables model routing based on task requirements, cost optimization, or performance needs. - -## Syntax - -```basic -USE MODEL "modelname" -``` - -```basic -USE MODEL "auto" -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `modelname` | String | Name of the model to use, or "auto" for automatic routing | - -## Description - -`USE MODEL` allows scripts to dynamically select which language model to use for subsequent AI operations. This is essential for: - -- **Cost optimization** - Use smaller/cheaper models for simple tasks -- **Quality control** - Use powerful models for complex reasoning -- **Speed optimization** - Use fast models for real-time responses -- **Specialized tasks** - Use code-specific models for programming - -When set to `"auto"`, the system automatically routes queries to the most appropriate model based on task complexity, latency requirements, and cost considerations. - -## Examples - -### Basic Model Selection - -```basic -' Use a fast model for simple queries -USE MODEL "fast" -response = LLM "What time is it in New York?" -TALK response - -' Switch to quality model for complex analysis -USE MODEL "quality" -analysis = LLM "Analyze the market trends for Q4 and provide recommendations" -TALK analysis -``` - -### Automatic Model Routing - -```basic -' Let the system choose the best model -USE MODEL "auto" - -' Simple query -> routes to fast model -greeting = LLM "Say hello" - -' Complex query -> routes to quality model -report = LLM "Generate a detailed financial analysis with projections" -``` - -### Code Generation - -```basic -' Use code-specialized model -USE MODEL "code" - -code = LLM "Write a Python function to calculate fibonacci numbers" -TALK code -``` - -### Cost-Aware Processing - -```basic -' Process bulk items with cheap model -USE MODEL "fast" -FOR EACH item IN items - summary = LLM "Summarize in one sentence: " + item.text - item.summary = summary -NEXT item - -' Final review with quality model -USE MODEL "quality" -review = LLM "Review these summaries for accuracy: " + summaries -``` - -### Model Fallback Pattern - -```basic -' Try preferred model first -USE MODEL "gpt-4" -ON ERROR GOTO fallback -response = LLM prompt -GOTO done - -fallback: -' Fall back to local model if API fails -USE MODEL "local" -response = LLM prompt - -done: -TALK response -``` - -## Model Routing Strategies - -The system supports several routing strategies configured in `config.csv`: - -| Strategy | Description | -|----------|-------------| -| `manual` | Explicit model selection only | -| `auto` | Automatic routing based on query analysis | -| `load-balanced` | Distribute across models for throughput | -| `fallback` | Try models in order until one succeeds | - -## Built-in Model Aliases - -| Alias | Description | Use Case | -|-------|-------------|----------| -| `fast` | Optimized for speed | Simple queries, real-time chat | -| `quality` | Optimized for accuracy | Complex reasoning, analysis | -| `code` | Code-specialized model | Programming tasks | -| `local` | Local GGUF model | Offline/private operation | -| `auto` | System-selected | Let routing decide | - -## Config.csv Options - -```csv -name,value -model-routing-strategy,auto -model-default,fast -model-fast,DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf -model-quality,gpt-4 -model-code,codellama-7b.gguf -model-fallback-enabled,true -model-fallback-order,quality,fast,local -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `model-routing-strategy` | `auto` | Routing strategy to use | -| `model-default` | `fast` | Default model when not specified | -| `model-fast` | (configured) | Model for fast/simple tasks | -| `model-quality` | (configured) | Model for quality/complex tasks | -| `model-code` | (configured) | Model for code generation | -| `model-fallback-enabled` | `true` | Enable automatic fallback | -| `model-fallback-order` | `quality,fast,local` | Order to try on failure | - -## Auto-Routing Criteria - -When `USE MODEL "auto"` is active, the system considers: - -1. **Query complexity** - Token count, reasoning required -2. **Task type** - Code, analysis, chat, translation -3. **Latency requirements** - Real-time vs batch -4. **Cost budget** - Per-query and daily limits -5. **Model availability** - Health checks, rate limits - -## Related Keywords - -| Keyword | Description | -|---------|-------------| -| [`LLM`](./keyword-llm.md) | Query the language model | -| [`SET CONTEXT`](./keyword-set-context.md) | Add context for LLM | -| [`BEGIN SYSTEM PROMPT`](./prompt-blocks.md) | Define AI persona | - -## Performance Considerations - -- Model switching has minimal overhead -- Auto-routing adds ~10ms for classification -- Consider batching similar queries under one model -- Local models avoid network latency - -## Best Practices - -1. **Start with auto** - Let the system optimize, then tune -2. **Batch by model** - Group similar tasks to reduce switching -3. **Monitor costs** - Track per-model usage in analytics -4. **Test fallbacks** - Ensure graceful degradation -5. **Profile your queries** - Understand which need quality vs speed - -## See Also - -- [LLM Configuration](../chapter-08-config/llm-config.md) - Model setup -- [Multi-Agent Orchestration](../chapter-11-features/multi-agent-orchestration.md) - Model routing in multi-agent systems -- [Cost Tracking](../chapter-11-features/observability.md#cost-tracking) - Monitor model costs \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-use-tool.md b/docs/src/chapter-06-gbdialog/keyword-use-tool.md deleted file mode 100644 index 1df330e3..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-use-tool.md +++ /dev/null @@ -1,74 +0,0 @@ -# USE TOOL - -## Syntax - -```basic -USE TOOL tool-name -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| tool-name | String | Name of the tool to load (without .bas extension) | - -## Description - -Loads a tool definition and makes it available to the LLM for the current session. Tools extend the bot's capabilities with specific functions like calculations, API calls, or data processing. - -## Examples - -### Basic Usage - -```basic -' Load weather tool -USE TOOL "weather" - -' Now system AI can use weather functions during conversations -TALK "What weather information would you like?" -' System AI automatically uses the tool when needed -``` - -### Multiple Tools - -```basic -' Load several tools -USE TOOL "calculator" -USE TOOL "translator" -USE TOOL "date-time" - -' System AI has access to all loaded tools during conversations -TALK "I can help you with calculations, translations, and date/time information." -' System AI automatically uses the appropriate tools when needed -``` - - - -## Tool Definition Format - -Tools are defined as BASIC scripts with PARAM declarations: - -```basic -' weather.bas -PARAM location AS string LIKE "Tokyo" DESCRIPTION "City name" -DESCRIPTION "Get current weather for a location" - -' Tool logic here -temp = GET_TEMPERATURE(location) -conditions = GET_CONDITIONS(location) -result = location + ": " + temp + "°, " + conditions -RETURN result -``` - -## Notes - -- Tools remain active for the entire session -- Use CLEAR TOOLS to remove all loaded tools -- Tool names should be descriptive -- Tools are loaded from the .gbdialog/tools/ directory - -## Related - -- [CLEAR TOOLS](./keyword-clear-tools.md) -- [Tool Definition](../chapter-08/tool-definition.md) -- [PARAM Declaration](../chapter-08/param-declaration.md) diff --git a/docs/src/chapter-06-gbdialog/keyword-use-website.md b/docs/src/chapter-06-gbdialog/keyword-use-website.md deleted file mode 100644 index 1e9fe80f..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-use-website.md +++ /dev/null @@ -1,65 +0,0 @@ -# USE WEBSITE Keyword - -**Syntax** - -``` -USE WEBSITE "https://example.com" -``` - -**Parameters** - -- `"url"` – A valid HTTP or HTTPS URL pointing to a website that should be made available in the conversation context. - -**Description** - -`USE WEBSITE` operates in two distinct modes: - -1. **Preprocessing Mode** (Script Compilation): When found in a BASIC script during compilation, it registers the website for background crawling. The crawler service will fetch, extract, and index the website's content into a vector database collection. This ensures the website content is ready before any conversation starts. - -2. **Runtime Mode** (Conversation Execution): During a conversation, `USE WEBSITE` associates an already-crawled website collection with the current session, making it available for queries via `FIND` or `LLM` calls. This behaves similarly to `USE KB` - it's a session-scoped association. - -If a website hasn't been registered during preprocessing, the runtime execution will fail with an appropriate error message. - -**Example** - -```basic -' In script preprocessing, this registers the website for crawling -USE WEBSITE "https://docs.example.com" - -' During conversation, this makes the crawled content available -USE WEBSITE "https://docs.example.com" -FIND "deployment procedures" -TALK "I found information about deployment procedures in the documentation." -``` - -**Preprocessing Behavior** - -When the script is compiled: -- The URL is validated -- The website is registered in the `website_crawls` table -- The crawler service picks it up and indexes the content -- Status can be: pending (0), crawled (1), or failed (2) - -**Runtime Behavior** - -When executed in a conversation: -- Checks if the website has been crawled -- Associates the website collection with the current session -- Makes the content searchable via `FIND` and available to `LLM` - -**With LLM Integration** - -```basic -USE WEBSITE "https://company.com/policies" -question = HEAR "What would you like to know about our policies?" -FIND question -answer = LLM "Based on the search results, provide a clear answer" -TALK answer -``` - -**Related Keywords** - -- [CLEAR WEBSITES](./keyword-clear-websites.md) - Remove all website associations from session -- [USE KB](./keyword-use-kb.md) - Similar functionality for knowledge base files -- [FIND](./keyword-find.md) - Search within loaded websites and KBs -- [LLM](./keyword-llm.md) - Process search results with AI \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-wait.md b/docs/src/chapter-06-gbdialog/keyword-wait.md deleted file mode 100644 index 02eb2d50..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-wait.md +++ /dev/null @@ -1,67 +0,0 @@ -# WAIT Keyword - -The **WAIT** keyword pauses script execution for a specified duration. -It is used to introduce delays between actions, synchronize processes, or control timing in automation flows. - ---- - -## Syntax - -```basic -WAIT seconds -``` - ---- - -## Parameters - -- `seconds` — The number of seconds to pause execution. - Can be an integer or floating-point value. - The maximum allowed duration is 300 seconds (5 minutes). - ---- - -## Description - -`WAIT` suspends the script for the specified duration. -During this time, the bot does not process other commands or messages. -This keyword is useful for pacing interactions, waiting for external events, or throttling API calls. - -If the provided value is invalid (negative or non-numeric), the command raises a runtime error. -The system automatically caps the wait time to prevent excessively long pauses. - ---- - -## Example - -```basic -' Wait for 2 seconds before continuing -TALK "Processing your request..." -WAIT 2 -TALK "Done!" -``` - ---- - -## Implementation Notes - -- Implemented in Rust under `src/basic/mod.rs` and `src/shared/utils.rs`. -- Uses `std::thread::sleep` with a `Duration` derived from the provided seconds. -- The engine ensures that the wait does not exceed the configured timeout limit. -- During the wait, no other BASIC commands are executed. - ---- - -## Related Keywords - -- [`SET SCHEDULE`](keyword-set-schedule.md) — Defines scheduled tasks for automation. -- [`PRINT`](keyword-print.md) — Outputs messages or debugging information. -- [`TALK`](keyword-talk.md) — Sends messages to the user. -- [`HEAR`](keyword-hear.md) — Receives user input after a delay. - ---- - -## Summary - -`WAIT` is a simple but essential keyword for controlling timing in BASIC scripts. -It allows developers to create natural pauses, synchronize workflows, and manage execution pacing effectively. diff --git a/docs/src/chapter-06-gbdialog/keyword-weather.md b/docs/src/chapter-06-gbdialog/keyword-weather.md deleted file mode 100644 index b1ee0ded..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-weather.md +++ /dev/null @@ -1,35 +0,0 @@ -# WEATHER / FORECAST Keywords - -Get weather information for any location using OpenWeatherMap API. - -## WEATHER - -```basic -result = WEATHER "London" -TALK result -``` - -Returns current conditions: temperature, humidity, wind, visibility. - -## FORECAST - -```basic -result = FORECAST "Paris", 5 -TALK result -``` - -Returns multi-day forecast with high/low temps and rain chance. - -## Configuration - -Add to `config.csv`: - -```csv -weather-api-key,your-openweathermap-api-key -``` - -Get a free API key at [openweathermap.org](https://openweathermap.org/api). - -## See Also - -- [Weather API Integration](../appendix-external-services/weather.md) - Full documentation \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-webhook.md b/docs/src/chapter-06-gbdialog/keyword-webhook.md deleted file mode 100644 index 083d6c79..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-webhook.md +++ /dev/null @@ -1,687 +0,0 @@ -# WEBHOOK - -Creates an instant HTTP endpoint for your bot. With WEBHOOK, you can expose any BASIC script as an API endpoint that external systems can call - perfect for integrations, notifications, and building custom APIs with LLM-powered responses. - -## Why WEBHOOK? - -Traditional API development requires: -- Setting up a web framework -- Writing routing code -- Handling HTTP parsing -- Deploying infrastructure - -With General Bots WEBHOOK, you write one line and your endpoint is live: - -```basic -WEBHOOK "my-endpoint" -``` - -That's it. Your script is now accessible at `/api/{botname}/webhook/my-endpoint`. - -## Syntax - -```basic -WEBHOOK "endpoint-name" -``` - -## Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| endpoint-name | String | Unique name for the webhook (alphanumeric, hyphens, underscores) | - -## Request Data Available - -When your webhook is called, these variables are automatically available: - -| Variable | Description | Example | -|----------|-------------|---------| -| `params` | Query string parameters | `params.id`, `params.filter` | -| `body` | JSON request body as object | `body.customer.name` | -| `headers` | HTTP headers | `headers.authorization` | -| `method` | HTTP method used | `"POST"`, `"GET"` | -| `path` | Request path | `"/webhook/my-endpoint"` | - -## Examples - -### 1. Simple Status Endpoint - -```basic -' status.bas - Simple health check -WEBHOOK "status" - -result_status = "healthy" -result_timestamp = NOW() -result_version = "1.0.0" -``` - -**Call it:** -```bash -curl https://bot.example.com/api/mybot/webhook/status -``` - -**Response:** -```json -{"status": "healthy", "timestamp": "2024-01-20T10:30:00Z", "version": "1.0.0"} -``` - -### 2. WhatsApp Order Notification - -Send order confirmations directly to customers on WhatsApp: - -```basic -' order-notify.bas - Notify customer via WhatsApp -WEBHOOK "order-notify" - -order_id = body.order_id -customer_phone = body.customer_phone -customer_name = body.customer_name -total = body.total -items = body.items - -IF order_id = "" OR customer_phone = "" THEN - result_status = 400 - result_error = "Missing order_id or customer_phone" - EXIT -END IF - -' Build order summary -order_summary = "🛒 *Order Confirmed #" + order_id + "*\n\n" -order_summary = order_summary + "Hi " + customer_name + "!\n\n" -order_summary = order_summary + "Your order has been confirmed.\n" -order_summary = order_summary + "Total: $" + total + "\n\n" -order_summary = order_summary + "We'll notify you when it ships!" - -' Send to WhatsApp using TALK TO -TALK TO "whatsapp:" + customer_phone, order_summary - -' Save order to database -order_status = "confirmed" -created_at = NOW() -SAVE "orders", order_id, customer_name, customer_phone, total, order_status, created_at - -result_status = "ok" -result_order_id = order_id -result_message = "Customer notified via WhatsApp" -``` - -**Call it:** -```bash -curl -X POST https://bot.example.com/api/mybot/webhook/order-notify \ - -H "Content-Type: application/json" \ - -d '{ - "order_id": "ORD-12345", - "customer_phone": "+5511999887766", - "customer_name": "João", - "total": "299.90", - "items": ["Widget", "Gadget"] - }' -``` - -### 3. WhatsApp Document Delivery - -Send invoices, reports, or documents to WhatsApp: - -```basic -' send-invoice.bas - Generate and send invoice via WhatsApp -WEBHOOK "send-invoice" - -order_id = body.order_id -customer_phone = body.customer_phone -customer_name = body.customer_name - -IF order_id = "" OR customer_phone = "" THEN - result_status = 400 - result_error = "Missing order_id or customer_phone" - EXIT -END IF - -' Get order data -order = FIND "orders", "order_id=" + order_id - -' Generate PDF invoice -invoice_date = FORMAT(NOW(), "DD/MM/YYYY") -GENERATE PDF "templates/invoice.html", order_id, customer_name, order.total, order.items, invoice_date, "invoices/" + order_id + ".pdf" - -' Send PDF to WhatsApp with caption -SEND FILE TO "whatsapp:" + customer_phone, "invoices/" + order_id + ".pdf", "📄 Invoice #" + order_id + " - Thank you for your purchase!" - -' Also send a follow-up message -TALK TO "whatsapp:" + customer_phone, "If you have any questions about your order, just reply to this message! 😊" - -result_status = "ok" -result_message = "Invoice sent to WhatsApp" -``` - -### 4. WhatsApp Support Ticket System - -Create support tickets and notify via WhatsApp: - -```basic -' support-ticket.bas - Create ticket and notify customer -WEBHOOK "support-ticket" - -customer_phone = body.phone -customer_name = body.name -issue = body.issue -priority = body.priority - -IF customer_phone = "" OR issue = "" THEN - result_status = 400 - result_error = "Missing phone or issue description" - EXIT -END IF - -IF priority = "" THEN - priority = "normal" -END IF - -' Create ticket -ticket_id = "TKT-" + FORMAT(NOW(), "YYYYMMDDHHmmss") -ticket_status = "open" -created_at = NOW() - -SAVE "support_tickets", ticket_id, customer_name, customer_phone, issue, priority, ticket_status, created_at - -' Notify customer via WhatsApp -confirmation = "🎫 *Support Ticket Created*\n\n" -confirmation = confirmation + "Ticket: #" + ticket_id + "\n" -confirmation = confirmation + "Priority: " + priority + "\n\n" -confirmation = confirmation + "We received your request:\n_" + issue + "_\n\n" -confirmation = confirmation + "Our team will respond within 24 hours." - -TALK TO "whatsapp:" + customer_phone, confirmation - -' Notify support team -team_msg = "🆕 New ticket #" + ticket_id + "\n" -team_msg = team_msg + "From: " + customer_name + " (" + customer_phone + ")\n" -team_msg = team_msg + "Priority: " + priority + "\n" -team_msg = team_msg + "Issue: " + issue - -TALK TO "whatsapp:+5511999000001", team_msg - -result_status = "ok" -result_ticket_id = ticket_id -``` - -### 5. AI-Powered WhatsApp Assistant - -Create an API that uses AI and responds via WhatsApp: - -```basic -' ai-assistant.bas - AI assistant that responds via WhatsApp -WEBHOOK "ask-ai" - -question = body.question -customer_phone = body.phone -context_type = body.context - -IF question = "" OR customer_phone = "" THEN - result_status = 400 - result_error = "Missing question or phone" - EXIT -END IF - -' Load appropriate knowledge base -IF context_type = "products" THEN - USE KB "product-catalog" -ELSE IF context_type = "support" THEN - USE KB "support-docs" -ELSE - USE KB "general-faq" -END IF - -' Set AI context -SET CONTEXT "You are a helpful assistant. Be concise and friendly. Use emojis occasionally." - -' Get AI response -answer = LLM question - -' Send response via WhatsApp -TALK TO "whatsapp:" + customer_phone, answer - -' Log the interaction -log_question = question -log_answer = answer -log_phone = customer_phone -log_context = context_type -log_timestamp = NOW() - -INSERT "ai_conversations", log_question, log_answer, log_phone, log_context, log_timestamp - -result_status = "ok" -result_answer = answer -``` - -### 6. WhatsApp Broadcast for Promotions - -Send promotional messages to multiple customers: - -```basic -' promo-broadcast.bas - Send promotions to customer list -WEBHOOK "send-promo" - -promo_title = body.title -promo_message = body.message -promo_image = body.image_url -customer_segment = body.segment - -IF promo_message = "" THEN - result_status = 400 - result_error = "Missing promotion message" - EXIT -END IF - -IF customer_segment = "" THEN - customer_segment = "all" -END IF - -' Get customers for this segment -customers = FIND "customers", "segment=" + customer_segment + " AND whatsapp_optin=true" - -sent_count = 0 -error_count = 0 - -' Build promo message with formatting -full_message = "🎉 *" + promo_title + "*\n\n" -full_message = full_message + promo_message + "\n\n" -full_message = full_message + "_Reply STOP to unsubscribe_" - -FOR EACH customer IN customers - ' Send to each customer - IF promo_image <> "" THEN - SEND FILE TO "whatsapp:" + customer.phone, promo_image, full_message - ELSE - TALK TO "whatsapp:" + customer.phone, full_message - END IF - - sent_count = sent_count + 1 - - ' Rate limiting - wait between messages - WAIT 1 -NEXT customer - -' Log the campaign -campaign_id = "CAMP-" + FORMAT(NOW(), "YYYYMMDDHHmmss") -campaign_title = promo_title -campaign_sent = sent_count -campaign_date = NOW() - -INSERT "campaigns", campaign_id, campaign_title, campaign_sent, customer_segment, campaign_date - -result_status = "ok" -result_campaign_id = campaign_id -result_sent = sent_count -``` - -### 7. Payment Notification with WhatsApp Receipt - -Handle payment webhooks and notify customers: - -```basic -' payment-webhook.bas - Handle payment and notify via WhatsApp -WEBHOOK "payment" - -event_type = body.type -payment_id = body.data.object.id -amount = body.data.object.amount -customer_id = body.data.object.customer - -SELECT CASE event_type - CASE "payment_intent.succeeded" - ' Get customer info - customer = FIND "customers", "stripe_id=" + customer_id - - ' Update order status - order_status = "paid" - paid_at = NOW() - UPDATE "orders", "payment_id=" + payment_id, order_status, paid_at - - ' Format amount (cents to dollars) - amount_formatted = amount / 100 - - ' Send WhatsApp receipt - receipt = "✅ *Payment Received*\n\n" - receipt = receipt + "Amount: $" + amount_formatted + "\n" - receipt = receipt + "Payment ID: " + payment_id + "\n" - receipt = receipt + "Date: " + FORMAT(NOW(), "DD/MM/YYYY HH:mm") + "\n\n" - receipt = receipt + "Thank you for your purchase! 🙏" - - TALK TO "whatsapp:" + customer.phone, receipt - - CASE "payment_intent.payment_failed" - customer = FIND "customers", "stripe_id=" + customer_id - - ' Notify customer of failure - failure_msg = "⚠️ *Payment Failed*\n\n" - failure_msg = failure_msg + "We couldn't process your payment.\n" - failure_msg = failure_msg + "Please try again or use a different payment method.\n\n" - failure_msg = failure_msg + "Need help? Reply to this message!" - - TALK TO "whatsapp:" + customer.phone, failure_msg - - CASE ELSE - ' Log unhandled event - TALK "Unhandled payment event: " + event_type -END SELECT - -result_received = TRUE -``` - -### 8. Appointment Reminder System - -Webhook to trigger appointment reminders: - -```basic -' appointment-reminder.bas - Send appointment reminders via WhatsApp -WEBHOOK "send-reminder" - -appointment_id = body.appointment_id -hours_before = body.hours_before - -IF appointment_id = "" THEN - result_status = 400 - result_error = "Missing appointment_id" - EXIT -END IF - -IF hours_before = "" THEN - hours_before = 24 -END IF - -' Get appointment details -appointment = FIND "appointments", "id=" + appointment_id - -' Format date/time nicely -appt_date = FORMAT(appointment.datetime, "dddd, MMMM DD") -appt_time = FORMAT(appointment.datetime, "HH:mm") - -' Build reminder message -reminder = "📅 *Appointment Reminder*\n\n" -reminder = reminder + "Hi " + appointment.customer_name + "!\n\n" -reminder = reminder + "This is a reminder of your upcoming appointment:\n\n" -reminder = reminder + "📍 *" + appointment.service + "*\n" -reminder = reminder + "🗓️ " + appt_date + "\n" -reminder = reminder + "🕐 " + appt_time + "\n" -reminder = reminder + "📌 " + appointment.location + "\n\n" -reminder = reminder + "Reply *CONFIRM* to confirm or *CANCEL* to cancel." - -' Send via WhatsApp -TALK TO "whatsapp:" + appointment.customer_phone, reminder - -' Update reminder sent status -reminder_sent_at = NOW() -UPDATE "appointments", "id=" + appointment_id, reminder_sent_at - -result_status = "ok" -result_message = "Reminder sent" -``` - -### 9. Form Submission with WhatsApp Follow-up - -Handle web form submissions and follow up on WhatsApp: - -```basic -' contact-form.bas - Handle contact form and follow up via WhatsApp -WEBHOOK "contact" - -name = body.name -email = body.email -phone = body.phone -message = body.message -source = body.source - -IF name = "" OR message = "" THEN - result_status = 400 - result_error = "Name and message are required" - EXIT -END IF - -' Use AI to categorize and generate response -SET CONTEXT "Categorize this message as: sales, support, feedback, or other. Then write a friendly acknowledgment." - -ai_prompt = "Customer: " + name + "\nMessage: " + message -ai_response = LLM ai_prompt - -' Save the submission -submission_id = "SUB-" + FORMAT(NOW(), "YYYYMMDDHHmmss") -submission_status = "new" -created_at = NOW() - -SAVE "submissions", submission_id, name, email, phone, message, source, ai_response, submission_status, created_at - -' If phone provided, send WhatsApp confirmation -IF phone <> "" THEN - whatsapp_msg = "👋 Hi " + name + "!\n\n" - whatsapp_msg = whatsapp_msg + "Thanks for reaching out! We received your message:\n\n" - whatsapp_msg = whatsapp_msg + "_" + message + "_\n\n" - whatsapp_msg = whatsapp_msg + "We'll get back to you soon. In the meantime, feel free to reply here if you have any questions!" - - TALK TO "whatsapp:" + phone, whatsapp_msg -END IF - -' Send email confirmation too -IF email <> "" THEN - SEND MAIL email, "We received your message", "Hi " + name + ",\n\nThank you for contacting us. We'll respond within 24 hours.\n\nBest regards" -END IF - -result_status = "ok" -result_submission_id = submission_id -``` - -### 10. Multi-Channel Notification Hub - -Single webhook that routes to multiple channels: - -```basic -' notify.bas - Multi-channel notification hub -WEBHOOK "notify" - -channel = body.channel -recipient = body.recipient -message = body.message -file_url = body.file -caption = body.caption - -IF recipient = "" OR message = "" THEN - result_status = 400 - result_error = "Missing recipient or message" - EXIT -END IF - -IF channel = "" THEN - channel = "whatsapp" -END IF - -' Route to appropriate channel -SELECT CASE channel - CASE "whatsapp" - IF file_url <> "" THEN - SEND FILE TO "whatsapp:" + recipient, file_url, caption - ELSE - TALK TO "whatsapp:" + recipient, message - END IF - - CASE "email" - subject = body.subject - IF subject = "" THEN - subject = "Notification" - END IF - - IF file_url <> "" THEN - SEND MAIL recipient, subject, message, file_url - ELSE - SEND MAIL recipient, subject, message - END IF - - CASE "teams" - TALK TO "teams:" + recipient, message - - CASE "web" - ' Send to web session - TALK TO "web:" + recipient, message - - CASE ELSE - result_status = 400 - result_error = "Unknown channel: " + channel - EXIT -END SELECT - -' Log notification -log_channel = channel -log_recipient = recipient -log_message = message -log_timestamp = NOW() - -INSERT "notification_log", log_channel, log_recipient, log_message, log_timestamp - -result_status = "ok" -result_channel = channel -result_delivered = TRUE -``` - -## Response Handling - -Control the HTTP response by setting `result_` prefixed variables: - -### Simple Response -```basic -result_status = "ok" -result_data = my_data -``` - -### Custom Status Code -```basic -result_status = 201 ' Created -result_id = new_id -result_created = TRUE -``` - -### Error Response -```basic -result_status = 400 -result_error = "Invalid request" -result_details = "Missing required field: phone" -``` - -## WhatsApp Message Formatting - -WhatsApp supports rich text formatting: - -| Format | Syntax | Example | -|--------|--------|---------| -| Bold | `*text*` | `*Important*` | -| Italic | `_text_` | `_note_` | -| Strikethrough | `~text~` | `~old price~` | -| Monospace | `` `text` `` | `` `code` `` | -| Line break | `\n` | `"Line 1\nLine 2"` | - -### Example with Formatting -```basic -message = "🎉 *Order Confirmed!*\n\n" -message = message + "Order: #" + order_id + "\n" -message = message + "Total: ~$" + old_price + "~ *$" + new_price + "*\n" -message = message + "_Discount applied!_" - -TALK TO "whatsapp:" + phone, message -``` - -## Security Best Practices - -### 1. Validate Webhook Signatures - -```basic -WEBHOOK "secure-endpoint" - -signature = headers.x_webhook_signature -secret = GET BOT MEMORY "webhook_secret" - -IF signature = "" THEN - TALK "Invalid request - no signature" - result_status = 401 - result_error = "Missing signature" - EXIT -END IF - -' Continue with verified request... -``` - -### 2. Validate Phone Numbers - -```basic -phone = body.phone - -' Remove non-numeric characters -clean_phone = REPLACE(phone, "+", "") -clean_phone = REPLACE(clean_phone, "-", "") -clean_phone = REPLACE(clean_phone, " ", "") - -IF LEN(clean_phone) < 10 THEN - result_status = 400 - result_error = "Invalid phone number" - EXIT -END IF - -' Add country code if missing -IF LEFT(clean_phone, 2) <> "55" THEN - clean_phone = "55" + clean_phone -END IF - -TALK TO "whatsapp:+" + clean_phone, message -``` - -### 3. Rate Limiting - -```basic -WEBHOOK "rate-limited" - -client_ip = headers.x_forwarded_for -rate_key = "rate:" + client_ip -current_count = GET BOT MEMORY rate_key - -IF current_count = "" THEN - current_count = 0 -END IF - -IF current_count > 100 THEN - result_status = 429 - result_error = "Rate limit exceeded" - result_retry_after = 60 - EXIT -END IF - -SET BOT MEMORY rate_key, current_count + 1 -' Process request... -``` - -## Use Cases Summary - -| Use Case | Webhook Name | Description | -|----------|--------------|-------------| -| Order Notifications | `/order-notify` | Confirm orders via WhatsApp | -| Invoice Delivery | `/send-invoice` | Send PDF invoices to WhatsApp | -| Support Tickets | `/support-ticket` | Create tickets, notify via WhatsApp | -| AI Assistant | `/ask-ai` | LLM answers sent to WhatsApp | -| Promotions | `/send-promo` | Broadcast promos to customers | -| Payment Alerts | `/payment` | Payment receipts via WhatsApp | -| Reminders | `/send-reminder` | Appointment reminders | -| Contact Forms | `/contact` | Form follow-up on WhatsApp | -| Multi-Channel | `/notify` | Route to any channel | - -## Technical Notes - -- Webhooks register during script compilation -- Stored in `system_automations` table with `kind = Webhook` -- Endpoint names must be unique per bot -- Request timeout: 30 seconds (keep processing fast) -- Maximum request body: 10MB -- HTTPS required in production - -## See Also - -- [TALK TO](./keyword-talk.md#talk-to) - Send messages to specific recipients -- [SEND FILE TO](./keyword-send-file-to.md) - Send files to recipients -- [SET SCHEDULE](./keyword-set-schedule.md) - Time-based automation -- [ON](./keyword-on.md) - Database trigger events -- [LLM](./keyword-llm.md) - Language model queries -- [USE KB](./keyword-use-kb.md) - Knowledge base integration \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keyword-write.md b/docs/src/chapter-06-gbdialog/keyword-write.md deleted file mode 100644 index 6e8b3950..00000000 --- a/docs/src/chapter-06-gbdialog/keyword-write.md +++ /dev/null @@ -1 +0,0 @@ -# WRITE diff --git a/docs/src/chapter-06-gbdialog/keywords-data.md b/docs/src/chapter-06-gbdialog/keywords-data.md deleted file mode 100644 index 543eab94..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-data.md +++ /dev/null @@ -1 +0,0 @@ -# Data Operations diff --git a/docs/src/chapter-06-gbdialog/keywords-file.md b/docs/src/chapter-06-gbdialog/keywords-file.md deleted file mode 100644 index 97d02942..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-file.md +++ /dev/null @@ -1 +0,0 @@ -# File Operations diff --git a/docs/src/chapter-06-gbdialog/keywords-http.md b/docs/src/chapter-06-gbdialog/keywords-http.md deleted file mode 100644 index 0158ac97..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-http.md +++ /dev/null @@ -1 +0,0 @@ -# HTTP & API Operations diff --git a/docs/src/chapter-06-gbdialog/keywords-kb-statistics.md b/docs/src/chapter-06-gbdialog/keywords-kb-statistics.md deleted file mode 100644 index 0d371c66..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-kb-statistics.md +++ /dev/null @@ -1,364 +0,0 @@ -# KB Statistics Keywords - -Knowledge Base Statistics keywords provide real-time information about your Qdrant vector database collections. Use these keywords to monitor document counts, storage usage, and indexing activity. - -## Overview - -These keywords are useful for: - -- **Administration**: Monitor KB health and growth -- **Dashboards**: Display statistics in admin interfaces -- **Automation**: Trigger actions based on KB state -- **Compliance**: Track document retention and storage - -## Available Keywords - -| Keyword | Returns | Description | -|---------|---------|-------------| -| `KB STATISTICS` | JSON | Complete statistics for all collections | -| `KB COLLECTION STATS` | JSON | Statistics for a specific collection | -| `KB DOCUMENTS COUNT` | Integer | Total document count for bot | -| `KB DOCUMENTS ADDED SINCE` | Integer | Documents added in last N days | -| `KB LIST COLLECTIONS` | Array | List of collection names | -| `KB STORAGE SIZE` | Float | Total storage in MB | - -## KB STATISTICS - -Returns comprehensive statistics about all knowledge base collections for the current bot. - -### Syntax - -```basic -stats = KB STATISTICS -``` - -### Return Value - -JSON string containing: - -```json -{ - "total_collections": 3, - "total_documents": 5000, - "total_vectors": 5000, - "total_disk_size_mb": 125.5, - "total_ram_size_mb": 62.3, - "documents_added_last_week": 150, - "documents_added_last_month": 620, - "collections": [ - { - "name": "kb_bot-id_main", - "vectors_count": 3000, - "points_count": 3000, - "segments_count": 2, - "disk_data_size": 78643200, - "ram_data_size": 39321600, - "indexed_vectors_count": 3000, - "status": "green" - } - ] -} -``` - -### Example - -```basic -REM Get and display KB statistics -stats = KB STATISTICS -statsObj = JSON PARSE stats - -TALK "Your knowledge base has " + statsObj.total_documents + " documents" -TALK "Using " + FORMAT(statsObj.total_disk_size_mb, "#,##0.00") + " MB of storage" - -IF statsObj.documents_added_last_week > 100 THEN - TALK "High activity! " + statsObj.documents_added_last_week + " documents added this week" -END IF -``` - -## KB COLLECTION STATS - -Returns detailed statistics for a specific Qdrant collection. - -### Syntax - -```basic -stats = KB COLLECTION STATS collection_name -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `collection_name` | String | Name of the collection | - -### Return Value - -JSON string with collection details: - -```json -{ - "name": "kb_bot-id_products", - "vectors_count": 1500, - "points_count": 1500, - "segments_count": 1, - "disk_data_size": 52428800, - "ram_data_size": 26214400, - "indexed_vectors_count": 1500, - "status": "green" -} -``` - -### Example - -```basic -REM Check specific collection health -collections = KB LIST COLLECTIONS - -FOR EACH collection IN collections - stats = KB COLLECTION STATS collection - collObj = JSON PARSE stats - - IF collObj.status <> "green" THEN - TALK "Warning: Collection " + collection + " status is " + collObj.status - END IF -NEXT -``` - -## KB DOCUMENTS COUNT - -Returns the total number of documents indexed for the current bot. - -### Syntax - -```basic -count = KB DOCUMENTS COUNT -``` - -### Return Value - -Integer representing total document count. - -### Example - -```basic -docCount = KB DOCUMENTS COUNT - -IF docCount = 0 THEN - TALK "Your knowledge base is empty. Upload some documents to get started!" -ELSE - TALK "You have " + FORMAT(docCount, "#,##0") + " documents in your knowledge base" -END IF -``` - -## KB DOCUMENTS ADDED SINCE - -Returns the number of documents added within the specified number of days. - -### Syntax - -```basic -count = KB DOCUMENTS ADDED SINCE days -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `days` | Integer | Number of days to look back | - -### Return Value - -Integer representing documents added in the time period. - -### Example - -```basic -REM Activity report -lastDay = KB DOCUMENTS ADDED SINCE 1 -lastWeek = KB DOCUMENTS ADDED SINCE 7 -lastMonth = KB DOCUMENTS ADDED SINCE 30 - -TALK "Document Activity Report" -TALK "Last 24 hours: " + lastDay + " documents" -TALK "Last 7 days: " + lastWeek + " documents" -TALK "Last 30 days: " + lastMonth + " documents" - -REM Calculate daily average -IF lastWeek > 0 THEN - avgDaily = lastWeek / 7 - TALK "Daily average: " + FORMAT(avgDaily, "#,##0.0") -END IF -``` - -## KB LIST COLLECTIONS - -Returns an array of all collection names belonging to the current bot. - -### Syntax - -```basic -collections = KB LIST COLLECTIONS -``` - -### Return Value - -Array of collection name strings. - -### Example - -```basic -collections = KB LIST COLLECTIONS - -IF LEN(collections) = 0 THEN - TALK "No collections found" -ELSE - TALK "Your collections:" - FOR EACH name IN collections - TALK " - " + name - NEXT -END IF -``` - -## KB STORAGE SIZE - -Returns the total disk storage used by all collections in megabytes. - -### Syntax - -```basic -sizeMB = KB STORAGE SIZE -``` - -### Return Value - -Float representing storage size in MB. - -### Example - -```basic -storageMB = KB STORAGE SIZE - -TALK "Storage used: " + FORMAT(storageMB, "#,##0.00") + " MB" - -REM Alert if storage is high -IF storageMB > 1000 THEN - TALK "Warning: Knowledge base exceeds 1 GB. Consider archiving old documents." -END IF -``` - -## Complete Example: KB Dashboard - -```basic -REM Knowledge Base Dashboard -REM Displays comprehensive statistics - -DESCRIPTION "View knowledge base statistics and health" - -TALK "📊 **Knowledge Base Dashboard**" -TALK "" - -REM Get overall statistics -stats = KB STATISTICS -statsObj = JSON PARSE stats - -REM Summary section -TALK "**Summary**" -TALK "Collections: " + statsObj.total_collections -TALK "Documents: " + FORMAT(statsObj.total_documents, "#,##0") -TALK "Vectors: " + FORMAT(statsObj.total_vectors, "#,##0") -TALK "" - -REM Storage section -TALK "**Storage**" -TALK "Disk: " + FORMAT(statsObj.total_disk_size_mb, "#,##0.00") + " MB" -TALK "RAM: " + FORMAT(statsObj.total_ram_size_mb, "#,##0.00") + " MB" -TALK "" - -REM Activity section -TALK "**Recent Activity**" -TALK "Last 7 days: " + FORMAT(statsObj.documents_added_last_week, "#,##0") + " documents" -TALK "Last 30 days: " + FORMAT(statsObj.documents_added_last_month, "#,##0") + " documents" - -REM Calculate growth rate -IF statsObj.documents_added_last_month > 0 THEN - growthRate = (statsObj.documents_added_last_week / (statsObj.documents_added_last_month / 4)) * 100 - 100 - IF growthRate > 0 THEN - TALK "Growth trend: +" + FORMAT(growthRate, "#,##0") + "% vs average" - ELSE - TALK "Growth trend: " + FORMAT(growthRate, "#,##0") + "% vs average" - END IF -END IF - -REM Health check -TALK "" -TALK "**Health Status**" -allHealthy = true -FOR EACH coll IN statsObj.collections - IF coll.status <> "green" THEN - TALK "⚠️ " + coll.name + ": " + coll.status - allHealthy = false - END IF -NEXT - -IF allHealthy THEN - TALK "✅ All collections healthy" -END IF - -REM Store for dashboard -SET BOT MEMORY "kb_last_check", NOW() -SET BOT MEMORY "kb_total_docs", statsObj.total_documents -SET BOT MEMORY "kb_storage_mb", statsObj.total_disk_size_mb -``` - -## Use Cases - -### 1. Admin Monitoring Bot - -```basic -REM Daily KB health check -SET SCHEDULE "kb-health" TO "0 8 * * *" - stats = KB STATISTICS - statsObj = JSON PARSE stats - - IF statsObj.total_disk_size_mb > 5000 THEN - SEND MAIL "admin@example.com", "KB Storage Alert", - "Knowledge base storage exceeds 5 GB: " + statsObj.total_disk_size_mb + " MB" - END IF -END SCHEDULE -``` - -### 2. User-Facing Statistics - -```basic -REM Show user their document count -docCount = KB DOCUMENTS COUNT -TALK "Your bot has learned from " + docCount + " documents" -TALK "Ask me anything about your content!" -``` - -### 3. Compliance Reporting - -```basic -REM Monthly compliance report -lastMonth = KB DOCUMENTS ADDED SINCE 30 -storageSize = KB STORAGE SIZE - -report = "Monthly KB Report\n" -report = report + "Documents added: " + lastMonth + "\n" -report = report + "Total storage: " + FORMAT(storageSize, "#,##0.00") + " MB\n" - -SEND MAIL "compliance@example.com", "Monthly KB Report", report -``` - -## Notes - -- Statistics are fetched in real-time from Qdrant -- Large collections may have slight delays in statistics updates -- Document counts from the database may differ slightly from vector counts if indexing is in progress -- Collection names follow the pattern `kb_{bot_id}_{collection_name}` - -## See Also - -- [USE KB](./keyword-use-kb.md) - Load knowledge base for queries -- [CLEAR KB](./keyword-clear-kb.md) - Clear knowledge base -- [Vector Collections](../chapter-03/vector-collections.md) - Understanding collections \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keywords-lead-scoring.md b/docs/src/chapter-06-gbdialog/keywords-lead-scoring.md deleted file mode 100644 index d699d4b5..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-lead-scoring.md +++ /dev/null @@ -1,342 +0,0 @@ -# Lead Scoring Keywords - -General Bots includes native lead scoring capabilities through BASIC keywords, enabling automated lead qualification, AI-enhanced scoring, and CRM integration directly from conversational flows. - -General Bots - -## Overview - -Lead scoring assigns numeric values to prospects based on their attributes and behaviors. Higher scores indicate greater sales readiness. General Bots provides both rule-based and AI-enhanced scoring approaches. - -## SCORE LEAD - -Calculate a lead score based on profile and behavior data using configurable rules. - -### Syntax - -```basic -score = SCORE LEAD lead_data -``` - -### Example - -```basic -lead_data = NEW OBJECT -lead_data.email = "john@company.com" -lead_data.name = "John Smith" -lead_data.company = "Acme Corp" -lead_data.job_title = "VP of Engineering" -lead_data.industry = "Technology" -lead_data.company_size = "Enterprise" - -score = SCORE LEAD lead_data - -TALK "Score: " + score.score -TALK "Grade: " + score.grade -TALK "Status: " + score.status -TALK "Top recommendation: " + score.recommendations[0] -``` - -### Return Object - -The `SCORE LEAD` keyword returns an object containing: - -| Property | Type | Description | -|----------|------|-------------| -| `score` | Integer | Numeric score (0-100) | -| `grade` | String | Letter grade (A, B, C, D, F) | -| `status` | String | hot, warm, cold, or unqualified | -| `breakdown` | Object | Score components by category | -| `recommendations` | Array | Suggested next actions | - -### Score Breakdown - -```basic -score = SCORE LEAD lead_data - -TALK "Demographic score: " + score.breakdown.demographic -TALK "Firmographic score: " + score.breakdown.firmographic -TALK "Behavioral score: " + score.breakdown.behavioral -TALK "Engagement score: " + score.breakdown.engagement -``` - -## AI SCORE LEAD - -Use AI/LLM-enhanced scoring for more nuanced lead evaluation. - -```basic -score = AI SCORE LEAD lead_data - -TALK "AI Score: " + score.score -TALK "Confidence: " + score.breakdown.ai_confidence -TALK "Reasoning: " + score.breakdown.ai_reasoning -``` - -AI scoring considers factors that rule-based scoring might miss, such as company news, market conditions, and subtle signals in communication patterns. - -### When to Use AI Scoring - -AI scoring works best for complex B2B scenarios where context matters significantly. Rule-based scoring is faster and sufficient for high-volume B2C leads with clear qualification criteria. - -```basic -' Use AI for enterprise leads, rules for SMB -IF lead_data.company_size = "Enterprise" THEN - score = AI SCORE LEAD lead_data -ELSE - score = SCORE LEAD lead_data -END IF -``` - -## GET LEAD SCORE - -Retrieve an existing lead score from the database. - -```basic -score = GET LEAD SCORE "lead-id" -TALK "Current score: " + score.score -TALK "Last updated: " + score.updated_at -``` - -## QUALIFY LEAD - -Check if a lead meets the qualification threshold for sales handoff. - -### Default Threshold (70) - -```basic -result = QUALIFY LEAD "lead-id" -IF result.qualified THEN - TALK "Lead is qualified: " + result.status - ' Notify sales team - SEND MAIL TO "sales@company.com" SUBJECT "New Qualified Lead" BODY result -ELSE - TALK "Lead needs more nurturing. Score: " + result.score -END IF -``` - -### Custom Threshold - -```basic -' Enterprise deals require higher qualification -result = QUALIFY LEAD "lead-id", 85 - -IF result.qualified THEN - TALK "Enterprise lead qualified for sales" -END IF -``` - -### Qualification Result - -| Property | Type | Description | -|----------|------|-------------| -| `qualified` | Boolean | Meets threshold | -| `score` | Integer | Current score | -| `threshold` | Integer | Applied threshold | -| `status` | String | Current lead status | -| `gap` | Integer | Points needed if not qualified | - -## UPDATE LEAD SCORE - -Manually adjust a lead's score based on specific actions or behaviors. - -### Add Points - -```basic -' Lead attended webinar -new_score = UPDATE LEAD SCORE "lead-id", 10, "Attended product webinar" -TALK "Score updated to: " + new_score.score -``` - -### Deduct Points - -```basic -' Lead unsubscribed from newsletter -new_score = UPDATE LEAD SCORE "lead-id", -15, "Unsubscribed from email" -``` - -### Behavioral Scoring - -```basic -ON "webinar:attended" - UPDATE LEAD SCORE params.lead_id, 15, "Webinar attendance" -END ON - -ON "pricing:viewed" - UPDATE LEAD SCORE params.lead_id, 20, "Viewed pricing page" -END ON - -ON "demo:requested" - UPDATE LEAD SCORE params.lead_id, 30, "Requested demo" -END ON - -ON "email:bounced" - UPDATE LEAD SCORE params.lead_id, -25, "Email bounced" -END ON -``` - -## Complete Lead Nurturing Flow - -```basic -' lead-nurturing.bas -PARAM email AS string -PARAM name AS string -PARAM company AS string -PARAM source AS string - -DESCRIPTION "Process and score new leads" - -' Build lead profile -WITH lead - .email = email - .name = name - .company = company - .source = source - .created_at = NOW() -END WITH - -' Initial scoring -score = SCORE LEAD lead - -' Store lead -INSERT "leads", lead -SET BOT MEMORY "lead_" + email + "_score", score.score - -' Route based on score -IF score.status = "hot" THEN - ' Immediate sales notification - SEND MAIL TO "sales@company.com" SUBJECT "Hot Lead: " + name BODY score - SEND TEMPLATE "hot-lead-welcome", "email", email, #{name: name} - -ELSEIF score.status = "warm" THEN - ' Schedule nurture sequence - SEND TEMPLATE "welcome", "email", email, #{name: name} - SET SCHEDULE DATEADD(NOW(), 3, "day"), "nurture-day-3.bas" - -ELSE - ' Cold lead - educational content - SEND TEMPLATE "educational", "email", email, #{name: name} -END IF - -TALK "Lead " + name + " processed with score " + score.score + " (" + score.status + ")" -``` - -## Lead Scoring Configuration - -Configure scoring weights in your bot's `config.csv`: - -```csv -key,value -lead-score-job-title-weight,20 -lead-score-company-size-weight,15 -lead-score-industry-weight,10 -lead-score-engagement-weight,25 -lead-score-behavioral-weight,30 -lead-score-qualification-threshold,70 -``` - -### Title-Based Scoring - -| Job Title Pattern | Points | -|-------------------|--------| -| C-Level (CEO, CTO, CFO) | 25 | -| VP / Vice President | 20 | -| Director | 15 | -| Manager | 10 | -| Individual Contributor | 5 | - -### Company Size Scoring - -| Company Size | Points | -|--------------|--------| -| Enterprise (1000+) | 20 | -| Mid-Market (100-999) | 15 | -| SMB (10-99) | 10 | -| Small (1-9) | 5 | - -### Behavioral Actions - -| Action | Typical Points | -|--------|---------------| -| Demo request | +30 | -| Pricing page view | +20 | -| Case study download | +15 | -| Webinar attendance | +15 | -| Blog subscription | +10 | -| Email open | +2 | -| Email click | +5 | -| Unsubscribe | -15 | -| Email bounce | -25 | - -## Scheduled Score Decay - -Implement score decay for inactive leads: - -```basic -' score-decay.bas -SET SCHEDULE "every day at 2am" - -' Find leads with no activity in 30 days -stale_leads = FIND "leads", "last_activity < DATEADD(NOW(), -30, 'day') AND score > 20" - -FOR EACH lead IN stale_leads - UPDATE LEAD SCORE lead.id, -5, "Inactivity decay" -NEXT lead - -TALK "Processed " + LEN(stale_leads) + " stale leads" -``` - -## Integration with CRM - -Push qualified leads to external CRM systems: - -```basic -result = QUALIFY LEAD lead_id - -IF result.qualified THEN - ' Push to Salesforce - crm_payload = NEW OBJECT - crm_payload.email = lead.email - crm_payload.name = lead.name - crm_payload.score = result.score - crm_payload.status = "Qualified" - - POST "https://api.salesforce.com/leads", crm_payload - - ' Mark as synced - UPDATE "leads", "id = " + lead_id, #{crm_synced: true, synced_at: NOW()} -END IF -``` - -## Best Practices - -**Start with simple rules.** Begin with basic demographic and firmographic scoring, then add behavioral triggers as you gather data. - -**Align scoring with sales.** Work with your sales team to define what makes a "qualified" lead. Their input ensures scores reflect actual sales readiness. - -**Review and adjust regularly.** Analyze conversion rates by score range monthly. Adjust weights if high-scoring leads aren't converting. - -**Combine rule-based and AI scoring.** Use rule-based scoring for speed and consistency, AI scoring for complex enterprise deals requiring nuanced evaluation. - -**Implement score decay.** Leads that go cold should have their scores decrease over time to keep the pipeline accurate. - -**Track score history.** Store score changes with timestamps and reasons for audit trails and analysis. - -```basic -' Log all score changes -ON "lead:score:changed" - INSERT "score_history", #{ - lead_id: params.lead_id, - old_score: params.old_score, - new_score: params.new_score, - reason: params.reason, - changed_at: NOW() - } -END ON -``` - -## See Also - -- [SEND TEMPLATE](./keywords.md) - Nurture campaign emails -- [SET SCHEDULE](./keyword-set-schedule.md) - Automated scoring jobs -- [ON Keyword](./keyword-on.md) - Event-driven score updates -- [GET / POST](./keywords-http.md) - CRM integration \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keywords-media.md b/docs/src/chapter-06-gbdialog/keywords-media.md deleted file mode 100644 index 83851b63..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-media.md +++ /dev/null @@ -1,143 +0,0 @@ -# Media & Messaging Keywords - -Keywords for displaying media content and sending messages across various channels. - -## Overview - -These keywords handle media playback, QR code generation, and messaging operations that extend beyond the basic TALK/HEAR conversation flow. - -## Keywords in This Section - -| Keyword | Description | -|---------|-------------| -| [PLAY](./keyword-play.md) | Display videos, images, documents, and presentations | -| [QR CODE](./keyword-qrcode.md) | Generate QR code images from data | -| [SEND SMS](./keyword-sms.md) | Send SMS text messages | - -## Quick Reference - -### Media Display - -```basic -' Play video with controls -PLAY "training.mp4" WITH OPTIONS "controls" - -' Display image fullscreen -PLAY "banner.png" WITH OPTIONS "fullscreen" - -' Show PDF document -PLAY "contract.pdf" - -' Display PowerPoint presentation -PLAY "slides.pptx" -``` - -### QR Code Generation - -```basic -' Generate basic QR code -qr_path = QR CODE "https://example.com" -SEND FILE qr_path - -' Generate with custom size -qr_path = QR CODE "payment-data", 512 - -' WiFi QR code -wifi_data = "WIFI:T:WPA;S:MyNetwork;P:password123;;" -qr_path = QR CODE wifi_data -``` - -### SMS Messaging - -```basic -' Send basic SMS -SEND SMS "+1234567890", "Hello from General Bots!" - -' Send with specific provider -SEND SMS phone, message, "twilio" - -' Two-factor authentication -otp = RANDOM(100000, 999999) -SEND SMS user.phone, "Your code: " + otp -``` - -## Channel Behavior - -These keywords adapt their behavior based on the active channel: - -| Keyword | Web | WhatsApp | Teams | SMS | -|---------|-----|----------|-------|-----| -| PLAY | Modal player | Send as media | Adaptive card | N/A | -| QR CODE | Display inline | Send as image | Embed in card | N/A | -| SEND SMS | N/A | N/A | N/A | Direct send | - -## Configuration - -### SMS Providers - -Configure in `config.csv`: - -```csv -sms-provider,twilio -twilio-account-sid,YOUR_SID -twilio-auth-token,YOUR_TOKEN -twilio-phone-number,+15551234567 -``` - -### Supported Providers - -- **Twilio** - Global coverage, reliable -- **AWS SNS** - AWS integration, cost-effective -- **Vonage** - Good international rates -- **MessageBird** - European coverage - -## Common Patterns - -### Interactive Media Training - -```basic -TALK "Welcome to the training module!" -PLAY "intro-video.mp4" WITH OPTIONS "controls" - -HEAR ready AS TEXT "Type 'next' when ready:" -PLAY "chapter-1.pptx" - -HEAR quiz AS TEXT "What did you learn?" -' Process quiz response -``` - -### QR Code Payment Flow - -```basic -HEAR amount AS NUMBER "Enter payment amount:" - -payment_data = GENERATE_PAYMENT_CODE(amount) -qr_path = QR CODE payment_data, 400 - -TALK "Scan to pay $" + amount + ":" -SEND FILE qr_path -``` - -### SMS Verification - -```basic -otp = RANDOM(100000, 999999) -REMEMBER "otp_" + user.id, otp, "5 minutes" - -SEND SMS user.phone, "Your code: " + otp - -HEAR code AS TEXT "Enter verification code:" - -IF code = RECALL("otp_" + user.id) THEN - TALK "✅ Verified!" -ELSE - TALK "❌ Invalid code" -END IF -``` - -## See Also - -- [Universal Messaging](./universal-messaging.md) - Multi-channel messaging -- [SEND MAIL](./keyword-send-mail.md) - Email messaging -- [TALK](./keyword-talk.md) - Basic text output -- [File Operations](./keywords-file.md) - File handling \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keywords-multi-agent.md b/docs/src/chapter-06-gbdialog/keywords-multi-agent.md deleted file mode 100644 index ae361c10..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-multi-agent.md +++ /dev/null @@ -1,276 +0,0 @@ -# Multi-Agent Keywords - -This section covers keywords for building multi-agent systems where multiple specialized bots collaborate to handle complex tasks. - -## Overview - -Multi-agent orchestration enables: - -- **Task specialization** - Each bot focuses on what it does best -- **Collaborative problem-solving** - Bots work together on complex tasks -- **Scalable architectures** - Add new specialists without modifying existing bots -- **Resilient systems** - Failures are isolated and handled gracefully - -## Keyword Summary - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| `ADD BOT` | `ADD BOT "name" TRIGGER ON "keywords"` | Add bot to session with triggers | -| `DELEGATE TO BOT` | `result = DELEGATE "msg" TO BOT "name"` | Send task to another bot | -| `BROADCAST TO BOTS` | `BROADCAST "message" TO BOTS` | Send message to all bots | -| `TRANSFER CONVERSATION` | `TRANSFER CONVERSATION TO "botname"` | Hand off conversation | -| `BOT REFLECTION` | `BOT REFLECTION true` | Enable agent self-analysis | -| `BOT REFLECTION INSIGHTS` | `insights = BOT REFLECTION INSIGHTS()` | Get reflection results | - -## ADD BOT - -Adds a bot to the current session with optional triggers, tools, and schedules. - -```basic -' Add bot with keyword triggers -ADD BOT "billing-bot" TRIGGER ON "billing,invoice,payment" - -' Add bot with tool access -ADD BOT "analyst-bot" TOOLS "calculate,forecast,report" - -' Add bot with scheduled execution -ADD BOT "monitor-bot" SCHEDULE "0 */1 * * *" - -' Add bot with multiple configurations -ADD BOT "support-bot" TRIGGER ON "help,support" TOOLS "ticket,escalate" -``` - -### Trigger Types - -| Type | Description | Example | -|------|-------------|---------| -| `TRIGGER ON` | Keyword-based activation | `TRIGGER ON "billing,payment"` | -| `TOOLS` | Tool-based activation | `TOOLS "calculate,search"` | -| `SCHEDULE` | Cron-based activation | `SCHEDULE "0 9 * * *"` | - -## DELEGATE TO BOT - -Sends a task to another bot and optionally waits for a response. - -```basic -' Fire-and-forget delegation -DELEGATE "Process this order" TO BOT "order-processor" - -' Get response from delegation -result = DELEGATE "Calculate ROI" TO BOT "finance-bot" -TALK "Result: " + result - -' Delegation with timeout -result = DELEGATE "Analyze report" TO BOT "analyst-bot" TIMEOUT 60 -``` - -### Parameters - -| Parameter | Type | Description | -|-----------|------|-------------| -| `message` | String | Task or message to send | -| `botname` | String | Target bot name | -| `TIMEOUT` | Number | Optional timeout in seconds (default: 30) | - -## BROADCAST TO BOTS - -Sends a message to all bots in the current session. - -```basic -' Notify all bots of an event -BROADCAST "New customer signup: " + customerid TO BOTS - -' Emergency signal -BROADCAST "MAINTENANCE_MODE" TO BOTS - -' Data update notification -BROADCAST "PRICE_UPDATE:" + JSON(prices) TO BOTS -``` - -## TRANSFER CONVERSATION - -Hands off the entire conversation to another bot. The current bot exits. - -```basic -' Simple transfer -TALK "Let me connect you with our billing specialist." -TRANSFER CONVERSATION TO "billing-bot" - -' Transfer with context -SET CONTEXT "issue" AS "refund request" -SET CONTEXT "amount" AS "$150" -TRANSFER CONVERSATION TO "refunds-bot" - -' Conditional transfer -IF issueType = "technical" THEN - TRANSFER CONVERSATION TO "tech-support-bot" -ELSE - TRANSFER CONVERSATION TO "general-support-bot" -END IF -``` - -## BOT REFLECTION - -Enables agent self-analysis for continuous improvement. - -```basic -' Enable reflection -BOT REFLECTION true - -' Disable reflection -BOT REFLECTION false - -' Monitor specific metric -BOT REFLECTION ON "conversation_quality" -BOT REFLECTION ON "response_accuracy" -BOT REFLECTION ON "user_satisfaction" -``` - -### Reflection Metrics - -| Metric | Description | -|--------|-------------| -| `conversation_quality` | Overall conversation effectiveness | -| `response_accuracy` | Correctness of responses | -| `user_satisfaction` | Estimated user satisfaction | -| `tone_appropriateness` | Whether tone matches context | -| `resolution_rate` | Whether issues were resolved | - -## BOT REFLECTION INSIGHTS - -Retrieves the results of reflection analysis. - -```basic -' Get insights -insights = BOT REFLECTION INSIGHTS() - -' Access properties -PRINT "Quality Score: " + insights.qualityScore -PRINT "Issues: " + insights.issuesCount - -' Iterate suggestions -FOR EACH suggestion IN insights.suggestions - PRINT "Suggestion: " + suggestion -NEXT suggestion - -' Use for alerting -IF insights.qualityScore < 0.5 THEN - SEND MAIL admin, "Low Quality Alert", insights.summary -END IF -``` - -### Insights Object - -| Property | Type | Description | -|----------|------|-------------| -| `qualityScore` | Number | Overall quality (0-1) | -| `summary` | String | Text summary | -| `issues` | Array | Identified issues | -| `issuesCount` | Number | Count of issues | -| `suggestions` | Array | Improvement suggestions | -| `criticalIssues` | Number | Critical problem count | -| `timestamp` | DateTime | When analyzed | - -## Common Patterns - -### Router Pattern - -A central bot routes queries to specialists. - -```basic -' router-bot/start.bas -HEAR userquery - -' Classify the query -category = LLM "Classify into: billing, technical, sales, general. Query: " + userquery - -SWITCH category - CASE "billing" - result = DELEGATE userquery TO BOT "billing-bot" - CASE "technical" - result = DELEGATE userquery TO BOT "tech-bot" - CASE "sales" - result = DELEGATE userquery TO BOT "sales-bot" - CASE ELSE - result = LLM userquery -END SWITCH - -TALK result -``` - -### Expert Panel Pattern - -Multiple bots provide perspectives. - -```basic -question = "Should we expand into Europe?" - -' Get multiple expert opinions -marketView = DELEGATE question TO BOT "market-analyst" -financeView = DELEGATE question TO BOT "finance-expert" -riskView = DELEGATE question TO BOT "risk-assessor" - -' Synthesize -synthesis = LLM "Combine these expert views: " + marketView + financeView + riskView -TALK synthesis -``` - -### Escalation Pattern - -Automatic escalation when confidence is low. - -```basic -' First-line bot -confidence = LLM "Rate confidence (0-100) for: " + userquery - -IF confidence < 50 THEN - TALK "Let me connect you with a specialist." - SET CONTEXT "escalation_reason" AS "low_confidence" - TRANSFER CONVERSATION TO "senior-support-bot" -ELSE - response = LLM userquery - TALK response -END IF -``` - -## Configuration - -### config.csv Options - -```csv -name,value -a2a-enabled,true -a2a-timeout,30 -a2a-max-hops,5 -a2a-retry-count,3 -reflection-enabled,true -reflection-interval,10 -reflection-min-messages,3 -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `a2a-enabled` | `true` | Enable agent-to-agent communication | -| `a2a-timeout` | `30` | Default delegation timeout (seconds) | -| `a2a-max-hops` | `5` | Maximum delegation chain depth | -| `a2a-retry-count` | `3` | Retry attempts on failure | -| `reflection-enabled` | `true` | Enable bot reflection | -| `reflection-interval` | `10` | Messages between reflections | - -## Best Practices - -1. **Use descriptive bot names** - `billing-bot` not `bot2` -2. **Set appropriate timeouts** - Long tasks need longer timeouts -3. **Handle failures gracefully** - Always have fallback paths -4. **Avoid circular delegation** - Bot A → Bot B → Bot A -5. **Keep chains short** - Max 3-4 delegation hops -6. **Log delegations** - Helps debug multi-agent flows -7. **Review reflection insights** - Act on improvement suggestions - -## See Also - -- [ADD BOT](./keyword-add-bot.md) - Detailed ADD BOT reference -- [DELEGATE TO BOT](./keyword-delegate-to-bot.md) - Delegation details -- [BOT REFLECTION](./keyword-bot-reflection.md) - Reflection details -- [Multi-Agent Orchestration](../chapter-11-features/multi-agent-orchestration.md) - Complete guide -- [A2A Protocol](../chapter-11-features/a2a-protocol.md) - Protocol details \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keywords-social-media.md b/docs/src/chapter-06-gbdialog/keywords-social-media.md deleted file mode 100644 index bb5f0787..00000000 --- a/docs/src/chapter-06-gbdialog/keywords-social-media.md +++ /dev/null @@ -1,259 +0,0 @@ -# Social Media Keywords - -General Bots provides native social media integration through BASIC keywords for posting content, scheduling, retrieving metrics, and managing posts across multiple platforms. - -General Bots - -## Platform Support - -Supported platforms include Instagram, Facebook, LinkedIn, and Twitter/X. Each platform requires appropriate API credentials configured in your bot's `config.csv`. - -## POST TO - -Publish content to one or more social media platforms. - -### Single Platform - -```basic -POST TO INSTAGRAM image, "Check out our new feature! #AI #Automation" -POST TO FACEBOOK image, caption -POST TO LINKEDIN image, caption -POST TO TWITTER image, caption -``` - -### Multiple Platforms - -Post to several platforms simultaneously: - -```basic -POST TO "instagram,facebook,linkedin" image, caption -``` - -The keyword returns a post ID that can be used for metrics retrieval or deletion. - -### Example: Product Announcement - -```basic -image = "/products/new-release.jpg" -caption = "Introducing our latest innovation! Available now. #NewProduct #Innovation" - -post_id = POST TO "instagram,facebook" image, caption -SET BOT MEMORY "latest_post_id", post_id -TALK "Posted to Instagram and Facebook" -``` - -## POST TO ... AT (Scheduled) - -Schedule posts for future publishing at a specific date and time. - -```basic -POST TO INSTAGRAM AT "2025-02-01 10:00" image, caption -POST TO FACEBOOK AT "2025-02-15 09:00" image, "Coming soon!" -``` - -### Campaign Scheduling - -```basic -' Schedule a week of posts -images = LIST "/campaign/week1/" -dates = ["2025-02-03 09:00", "2025-02-04 09:00", "2025-02-05 09:00"] - -FOR i = 0 TO LEN(images) - 1 - POST TO "instagram,facebook" AT dates[i] images[i].path, captions[i] -NEXT i - -TALK "Campaign scheduled: " + LEN(images) + " posts" -``` - -## GET METRICS - -Retrieve engagement metrics for published posts. - -### Platform-Specific Metrics - -```basic -' Instagram metrics -metrics = GET INSTAGRAM METRICS "post-id" -TALK "Likes: " + metrics.likes + ", Comments: " + metrics.comments - -' Facebook metrics -fb_metrics = GET FACEBOOK METRICS "post-id" -TALK "Shares: " + fb_metrics.shares + ", Reactions: " + fb_metrics.reactions - -' LinkedIn metrics -li_metrics = GET LINKEDIN METRICS "post-id" -TALK "Impressions: " + li_metrics.impressions - -' Twitter metrics -tw_metrics = GET TWITTER METRICS "post-id" -TALK "Retweets: " + tw_metrics.retweets + ", Likes: " + tw_metrics.likes -``` - -### Metrics Report - -```basic -SET SCHEDULE "every monday at 9am" - -post_id = GET BOT MEMORY "latest_post_id" -metrics = GET INSTAGRAM METRICS post_id - -WITH report - .post_id = post_id - .likes = metrics.likes - .comments = metrics.comments - .reach = metrics.reach - .engagement_rate = ROUND((metrics.likes + metrics.comments) / metrics.reach * 100, 2) - .report_date = NOW() -END WITH - -SEND MAIL TO "marketing@company.com" SUBJECT "Weekly Social Report" BODY report -``` - -## GET POSTS - -List posts from a platform. - -```basic -' Get all Instagram posts -posts = GET INSTAGRAM POSTS -FOR EACH post IN posts - TALK post.id + ": " + post.caption -NEXT post - -' Get Facebook posts -fb_posts = GET FACEBOOK POSTS -``` - -## DELETE POST - -Remove a scheduled or published post. - -```basic -DELETE POST "post-id" -TALK "Post removed" -``` - -### Conditional Deletion - -```basic -' Delete posts with low engagement -posts = GET INSTAGRAM POSTS -FOR EACH post IN posts - metrics = GET INSTAGRAM METRICS post.id - IF metrics.likes < 10 AND DATEDIFF("day", post.created_at, NOW()) > 30 THEN - DELETE POST post.id - TALK "Deleted low-engagement post: " + post.id - END IF -NEXT post -``` - -## Campaign Examples - -### Welcome Campaign - -```basic -ON FORM SUBMIT "signup" - name = fields.name - email = fields.email - - ' Welcome email immediately - SEND TEMPLATE "welcome", "email", email, #{name: name} - - ' Schedule social proof post - IF fields.share_permission = "yes" THEN - caption = "Welcome to our community, " + name + "! 🎉 #NewMember #Community" - POST TO INSTAGRAM AT DATEADD(NOW(), 1, "hour") "/templates/welcome-card.png", caption - END IF -END ON -``` - -### Social Media Campaign - -```basic -' social-campaign.bas -SET SCHEDULE "every day at 10am" - -' Rotate through content library -content_index = GET BOT MEMORY "content_index" -IF content_index = "" THEN content_index = 0 - -content_library = [ - #{image: "/content/tip1.png", caption: "Pro tip: Automate your workflows! #Productivity"}, - #{image: "/content/tip2.png", caption: "Save hours every week with automation #Efficiency"}, - #{image: "/content/tip3.png", caption: "Let AI handle the repetitive tasks #AI #Automation"} -] - -current = content_library[content_index MOD LEN(content_library)] -post_id = POST TO "instagram,linkedin" current.image, current.caption - -SET BOT MEMORY "content_index", content_index + 1 -SET BOT MEMORY "last_post_id", post_id - -TALK "Posted content #" + (content_index + 1) -``` - -### Engagement Monitoring - -```basic -SET SCHEDULE "every 6 hours" - -posts = GET INSTAGRAM POSTS -total_engagement = 0 -post_count = 0 - -FOR EACH post IN posts - IF DATEDIFF("day", post.created_at, NOW()) <= 7 THEN - metrics = GET INSTAGRAM METRICS post.id - total_engagement = total_engagement + metrics.likes + metrics.comments - post_count = post_count + 1 - END IF -NEXT post - -avg_engagement = IIF(post_count > 0, ROUND(total_engagement / post_count, 0), 0) - -IF avg_engagement < 50 THEN - SEND MAIL TO "marketing@company.com" SUBJECT "Low Engagement Alert" BODY "Average engagement this week: " + avg_engagement -END IF -``` - -## Configuration - -Add social media credentials to your bot's `config.csv`: - -```csv -key,value -instagram-access-token,your-instagram-token -instagram-account-id,your-account-id -facebook-access-token,your-facebook-token -facebook-page-id,your-page-id -linkedin-access-token,your-linkedin-token -linkedin-organization-id,your-org-id -twitter-api-key,your-api-key -twitter-api-secret,your-api-secret -twitter-access-token,your-access-token -twitter-access-secret,your-access-secret -``` - -## Best Practices - -**Schedule posts strategically.** Analyze your audience engagement patterns and post when your followers are most active. - -**Use hashtags effectively.** Include relevant hashtags but avoid overloading—3 to 5 well-chosen tags typically perform better than 30 generic ones. - -**Monitor metrics regularly.** Set up scheduled reports to track engagement trends and adjust your content strategy. - -**Handle rate limits gracefully.** Social platforms enforce API rate limits. Space out bulk operations and implement retry logic. - -**Store post IDs.** Save post identifiers in BOT MEMORY for later metrics retrieval or deletion. - -```basic -post_id = POST TO INSTAGRAM image, caption -SET BOT MEMORY "post_" + FORMAT(NOW(), "yyyyMMdd"), post_id -``` - -## See Also - -- [SET SCHEDULE](./keyword-set-schedule.md) - Automate posting schedules -- [Template Variables](./template-variables.md) - Dynamic content in captions -- [SEND TEMPLATE](./keywords.md) - Multi-channel messaging -- [GET BOT MEMORY](./keyword-get-bot-memory.md) - Store post tracking data \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/keywords.md b/docs/src/chapter-06-gbdialog/keywords.md deleted file mode 100644 index 480ba0f5..00000000 --- a/docs/src/chapter-06-gbdialog/keywords.md +++ /dev/null @@ -1,441 +0,0 @@ -# Keyword Reference - -This section lists every BASIC keyword implemented in the GeneralBots engine. Each keyword page includes: - -* **Syntax** – Exact command format -* **Parameters** – Expected arguments -* **Description** – What the keyword does -* **Example** – A short snippet showing usage - -The source code for each keyword lives in `src/basic/keywords/`. Only the keywords listed here exist in the system. - -## Important: Case Insensitivity - -**All variables in General Bots BASIC are case-insensitive.** The preprocessor normalizes variable names to lowercase automatically. - -```basic -' These all refer to the same variable -host = "https://api.example.com" -result = GET Host + "/endpoint" -TALK HOST -``` - -Keywords are also case-insensitive but conventionally written in UPPERCASE: - -```basic -' Both work identically -TALK "Hello" -talk "Hello" -``` - -## Configuration Variables (param-*) - -Variables defined with `param-` prefix in `config.csv` are automatically available in scripts without the prefix: - -```csv -name,value -param-host,https://api.example.com -param-limit,100 -param-pages,50 -``` - -```basic -' Access directly (lowercase, no param- prefix) -result = GET host + "/items?limit=" + limit -``` - -See [Script Execution Flow](./script-execution-flow.md) for complete details. - ---- - -## Complete Keyword List (Flat Reference) - -| Keyword | Category | Description | -|---------|----------|-------------| -| `ADD BOT` | Multi-Agent | Add a bot to the current session with triggers | -| `ADD MEMBER` | Communication | Add member to a group | -| `ADD SUGGESTION` | UI | Add clickable suggestion button | -| `ADD TOOL` | Tools | Register a tool for the session | -| `AGGREGATE` | Data | Perform SUM, AVG, COUNT, MIN, MAX operations | -| `BOOK` | Special | Book an appointment | -| `BOT REFLECTION` | Multi-Agent | Enable agent self-analysis and improvement | -| `BROADCAST TO BOTS` | Multi-Agent | Send message to all bots in session | -| `CLEAR HEADERS` | HTTP | Clear all HTTP headers | -| `CLEAR KB` | Knowledge | Unload knowledge base from session | -| `CLEAR SUGGESTIONS` | UI | Remove all suggestion buttons | -| `CLEAR TOOLS` | Tools | Remove all registered tools | -| `COMPRESS` | Files | Create ZIP archive | -| `COPY` | Files | Copy a file | -| `CREATE DRAFT` | Communication | Create email draft | -| `CREATE SITE` | Tools | Generate a website | -| `CREATE TASK` | Tools | Create a task | -| `DELEGATE TO BOT` | Multi-Agent | Send task to another bot | -| `DELETE` | Data | Delete records from table | -| `DELETE FILE` | Files | Delete a file | -| `DELETE HTTP` | HTTP | Send HTTP DELETE request | -| `DOWNLOAD` | Files | Download file from URL | -| `EXIT FOR` | Control | Exit loop early | -| `EXTRACT` | Files | Extract ZIP archive | -| `FILL` | Data | Fill template with data | -| `FILTER` | Data | Filter records by condition | -| `FIND` | Data | Search in files or KB | -| `FIRST` | Data | Get first element | -| `FOR EACH ... NEXT` | Control | Loop through items | -| `FORMAT` | Data | Format strings and dates | -| `GENERATE PDF` | Files | Generate PDF from template | -| `GET` | Variables | Get variable or API data | -| `GET BOT MEMORY` | Memory | Retrieve bot-level persisted data | -| `GET USER MEMORY` | Memory | Retrieve user-level persisted data (cross-bot) | -| `GRAPHQL` | HTTP | Execute GraphQL query | -| `GROUP BY` | Data | Group data by field | -| `HEAR` | Dialog | Get input from user | -| `IF ... THEN ... ELSE ... END IF` | Control | Conditional logic | -| `INSERT` | Data | Insert new record | -| `INSTR` | String | Find position of substring | -| `IS NUMERIC` | String | Check if value is numeric | -| `JOIN` | Data | Join two datasets | -| `LAST` | Data | Get last element | -| `LIST` | Files | List directory contents | -| `LLM` | AI | Query language model | -| `MAP` | Data | Map field names | -| `MERGE` | Data | Merge data into table | -| `MERGE PDF` | Files | Merge multiple PDFs | -| `MOVE` | Files | Move or rename file | -| `ON` | Events | Event handler | -| `PATCH` | HTTP | Send HTTP PATCH request | -| `PIVOT` | Data | Create pivot table | -| `POST` | HTTP | Send HTTP POST request | -| `PRINT` | Debug | Debug output to console | -| `PUT` | HTTP | Send HTTP PUT request | -| `READ` | Files | Read file content | -| `REMEMBER` | Memory | Store user-specific memory | -| `RUN BASH` | Code Execution | Execute Bash script in sandbox | -| `RUN JAVASCRIPT` | Code Execution | Execute JavaScript in sandbox | -| `RUN PYTHON` | Code Execution | Execute Python code in sandbox | -| `SAVE` | Data | Save data to table (upsert) | -| `SAVE FROM UNSTRUCTURED` | Data | Extract structured data from text | -| `SEND MAIL` | Communication | Send email | -| `SET` | Variables | Set variable value | -| `SET BOT MEMORY` | Memory | Persist data at bot level | -| `SET CONTEXT` | AI | Add context for LLM | -| `SET HEADER` | HTTP | Set HTTP header | -| `SET SCHEDULE` | Events | Schedule script execution | -| `SET USER` | Session | Set user context | -| `SET USER FACT` | Memory | Store a fact about the user | -| `SET USER MEMORY` | Memory | Persist data at user level (cross-bot) | -| `SOAP` | HTTP | Execute SOAP API call | -| `SWITCH ... CASE ... END SWITCH` | Control | Switch statement | -| `SYNCHRONIZE` | Data | Sync API data to table (planned) | -| `TALK` | Dialog | Send message to user | -| `TRANSFER CONVERSATION` | Multi-Agent | Hand off conversation to another bot | -| `UPDATE` | Data | Update existing records | -| `USE MODEL` | AI | Switch LLM model for subsequent operations | -| `USER FACTS` | Memory | Get all stored user facts | -| `UPLOAD` | Files | Upload file to storage | -| `USE KB` | Knowledge | Load knowledge base | -| `USE TOOL` | Tools | Register tool definition | -| `USE WEBSITE` | Knowledge | Associate website with session | -| `WAIT` | Control | Pause execution | -| `WEATHER` | Special | Get weather information | -| `WEBHOOK` | Events | Create webhook endpoint | -| `WHILE ... WEND` | Control | While loop | -| `WRITE` | Files | Write content to file | - ---- - -## Keywords by Category - -### Core Dialog Keywords - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| TALK | `TALK "message"` | Send message to user | -| HEAR | `HEAR variable` or `HEAR variable AS TYPE` | Get input from user | -| WAIT | `WAIT seconds` | Pause execution | -| PRINT | `PRINT "debug message"` | Debug output to console | - -### Variable & Memory - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| SET | `SET variable = value` or `let variable = value` | Set variable value | -| GET | `result = GET "path"` | Get variable or fetch data | -| SET BOT MEMORY | `SET BOT MEMORY "key", value` | Persist data at bot level | -| GET BOT MEMORY | `value = GET BOT MEMORY("key")` | Retrieve persisted data | -| SET USER MEMORY | `SET USER MEMORY "key", value` | Persist data at user level (cross-bot) | -| GET USER MEMORY | `value = GET USER MEMORY("key")` | Retrieve user-level data | -| SET USER FACT | `SET USER FACT "key", value` | Store fact about user | -| USER FACTS | `facts = USER FACTS()` | Get all user facts | -| REMEMBER | `REMEMBER "key", value` | Store user-specific memory | - -### AI & Context - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| LLM | `result = LLM "prompt"` | Query language model | -| SET CONTEXT | `SET CONTEXT "name" AS "value"` | Add context for LLM | -| SET USER | `SET USER userid` | Set user context | -| USE MODEL | `USE MODEL "modelname"` | Switch LLM model (fast/quality/code/auto) | - -### Multi-Agent Orchestration - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| ADD BOT | `ADD BOT "name" TRIGGER ON "keywords"` | Add bot with triggers | -| DELEGATE TO BOT | `result = DELEGATE "message" TO BOT "name"` | Send task to bot | -| BROADCAST TO BOTS | `BROADCAST "message" TO BOTS` | Message all bots | -| TRANSFER CONVERSATION | `TRANSFER CONVERSATION TO "botname"` | Hand off to bot | -| BOT REFLECTION | `BOT REFLECTION true` | Enable self-analysis | -| BOT REFLECTION INSIGHTS | `insights = BOT REFLECTION INSIGHTS()` | Get analysis results | - -### Code Execution (Sandboxed) - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| RUN PYTHON | `result = RUN PYTHON "code"` | Execute Python in sandbox | -| RUN JAVASCRIPT | `result = RUN JAVASCRIPT "code"` | Execute JS in sandbox | -| RUN BASH | `result = RUN BASH "code"` | Execute Bash in sandbox | -| RUN ... WITH FILE | `result = RUN PYTHON WITH FILE "script.py"` | Run script file | - -### Knowledge Base - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| USE KB | `USE KB "kbname"` | Load knowledge base | -| CLEAR KB | `CLEAR KB` or `CLEAR KB "kbname"` | Unload knowledge base | -| USE WEBSITE | `USE WEBSITE "url"` | Associate website with session | -| FIND | `result = FIND "file", "filter"` | Search in files or KB | - -### Tools & Automation - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| ADD TOOL | `ADD TOOL "toolname"` | Register tool for session | -| USE TOOL | `USE TOOL "toolname"` | Load tool definition | -| CLEAR TOOLS | `CLEAR TOOLS` | Remove all registered tools | -| CREATE TASK | `CREATE TASK "title", "description"` | Create a task | -| CREATE SITE | `CREATE SITE "alias", "template", "prompt"` | Generate a website | -| CREATE DRAFT | `CREATE DRAFT "to", "subject", "body"` | Create email draft | - -### UI & Interaction - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| ADD SUGGESTION | `ADD SUGGESTION "key" AS "display text"` | Add clickable button | -| CLEAR SUGGESTIONS | `CLEAR SUGGESTIONS` | Remove all buttons | - -### Data Operations - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| SAVE | `SAVE "table", var1, var2, var3` | Save data (upsert) | -| INSERT | `result = INSERT "table", data` | Insert new record | -| UPDATE | `rows = UPDATE "table", "filter", data` | Update records | -| DELETE | `rows = DELETE "table", "filter"` | Delete records | -| MERGE | `result = MERGE "table", data, "key"` | Merge data into table | -| FILTER | `result = FILTER data, "condition"` | Filter records | -| AGGREGATE | `result = AGGREGATE "SUM", data, "field"` | Aggregate operations | -| JOIN | `result = JOIN left, right, "key"` | Join datasets | -| PIVOT | `result = PIVOT data, "row", "value"` | Create pivot table | -| GROUP BY | `result = GROUP BY data, "field"` | Group data | -| SYNCHRONIZE | `SYNCHRONIZE endpoint, table, key, pageVar, limitVar` | Sync API to table | -| MAP | `result = MAP data, "old->new"` | Map field names | -| FILL | `result = FILL data, template` | Fill template | -| FIRST | `result = FIRST collection` | Get first element | -| LAST | `result = LAST collection` | Get last element | -| FORMAT | `result = FORMAT value AS "pattern"` | Format strings/dates | - -### File Operations - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| READ | `content = READ "path"` | Read file content | -| WRITE | `WRITE "path", content` | Write to file | -| DELETE FILE | `DELETE FILE "path"` | Delete a file | -| COPY | `COPY "source", "destination"` | Copy a file | -| MOVE | `MOVE "source", "destination"` | Move/rename file | -| LIST | `files = LIST "path/"` | List directory | -| UPLOAD | `url = UPLOAD file, "path"` | Upload file | -| DOWNLOAD | `path = DOWNLOAD "url", "local"` | Download file | -| COMPRESS | `archive = COMPRESS files, "name.zip"` | Create ZIP | -| EXTRACT | `files = EXTRACT "archive.zip", "dest/"` | Extract ZIP | -| GENERATE PDF | `result = GENERATE PDF "template", data, "output.pdf"` | Generate PDF | -| MERGE PDF | `result = MERGE PDF files, "merged.pdf"` | Merge PDFs | - -### HTTP & API Operations - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| POST | `result = POST "url", data` | HTTP POST request | -| PUT | `result = PUT "url", data` | HTTP PUT request | -| PATCH | `result = PATCH "url", data` | HTTP PATCH request | -| DELETE HTTP | `result = DELETE HTTP "url"` | HTTP DELETE request | -| SET HEADER | `SET HEADER "name", "value"` | Set HTTP header | -| CLEAR HEADERS | `CLEAR HEADERS` | Clear all headers | -| GRAPHQL | `result = GRAPHQL "url", "query", vars` | GraphQL query | -| SOAP | `result = SOAP "wsdl", "operation", params` | SOAP call | - -### Flow Control - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| IF...THEN...ELSE | `IF condition THEN ... ELSE ... END IF` | Conditional | -| FOR EACH...NEXT | `FOR EACH item IN collection ... NEXT item` | Loop | -| EXIT FOR | `EXIT FOR` | Exit loop early | -| `WHILE...WEND` | `WHILE condition ... WEND` | While loop | -| `SWITCH...CASE` | `SWITCH value CASE x ... END SWITCH` | Switch statement | -| `REPORT` | `SEND EMAIL admin, REPORT` | Access sync statistics | -| `RESET REPORT` | `RESET REPORT` | Clear sync statistics | - -### Events & Scheduling - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| ON | `ON "event" CALL handler` | Event handler | -| SET SCHEDULE | `SET SCHEDULE "cron"` | Schedule execution | -| WEBHOOK | `WEBHOOK "endpoint"` | Create webhook | - -### Communication - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| SEND MAIL | `SEND MAIL "to", "subject", "body"` | Send email | -| ADD MEMBER | `ADD MEMBER "email", "group"` | Add to group | - -### Special Functions - -| Keyword | Syntax | Description | -|---------|--------|-------------| -| BOOK | `BOOK "appointment"` | Book appointment | -| WEATHER | `weather = WEATHER "location"` | Get weather | -| INSTR | `pos = INSTR(string, search)` | Find substring | -| IS NUMERIC | `result = IS NUMERIC(value)` | Check if numeric | -| SAVE FROM UNSTRUCTURED | `data = SAVE FROM UNSTRUCTURED text, schema` | Extract structured data | - ---- - -## Syntax Rules - -### DO ✅ - -```basic -' Variable names (no underscores in names) -let ticketnumber = "TKT001" -let useremail = "user@example.com" - -' SAVE with field names = variable names -SAVE "table.csv", ticketnumber, useremail, status - -' Keywords with spaces -SET BOT MEMORY "last_ticket", ticketnumber -SET CONTEXT "name" AS "description" -ADD SUGGESTION "key" AS "Display text" -CLEAR SUGGESTIONS -USE KB "myknowledge" -USE TOOL "mytool" - -' GET BOT MEMORY as function -let lastticket = GET BOT MEMORY("last_ticket") -``` - -### DON'T ❌ - -```basic -' NO: Complex object operations -SET object.field = value ' WRONG -SAVE "table", object.id, object ' WRONG - -' NO: IF for input validation (use HEAR AS TYPE instead) -IF value = "" THEN ' OK for logic, but for input use: -HEAR value AS STRING ' Better - validates input type -``` - ---- - -## Prompt Blocks - -Special multi-line blocks for AI configuration and formatted output: - -| Block | Purpose | Documentation | -|-------|---------|---------------| -| `BEGIN SYSTEM PROMPT ... END SYSTEM PROMPT` | Define AI persona, rules, capabilities | [Prompt Blocks](./prompt-blocks.md) | -| `BEGIN TALK ... END TALK` | Formatted multi-line messages with Markdown | [Prompt Blocks](./prompt-blocks.md) | - -```basic -BEGIN SYSTEM PROMPT -You are a helpful assistant for AcmeStore. -Rules: -1. Always be polite -2. Never discuss competitors -END SYSTEM PROMPT - -BEGIN TALK -**Welcome!** 🎉 - -I can help you with: -• Orders -• Tracking -• Returns -END TALK -``` - ---- - -## Script Structure - -### No MAIN Function - -Scripts execute from line 1 - no `MAIN` or entry point needed: - -```basic -' ✅ CORRECT - Start directly -TALK "Hello!" -ADD TOOL "my-tool" - -' ❌ WRONG - Don't use MAIN -SUB MAIN() - TALK "Hello" -END SUB -``` - -### SUB and FUNCTION for Reuse - -Use for helper code within tools, not as entry points: - -```basic -FUNCTION CalculateTotal(price, quantity) - RETURN price * quantity -END FUNCTION - -SUB NotifyAdmin(message) - SEND EMAIL admin1, message -END SUB - -' Execution starts here -total = CalculateTotal(19.99, 3) -CALL NotifyAdmin("Order processed") -``` - -See [Script Execution Flow](./script-execution-flow.md) for entry points and lifecycle. - ---- - -## Notes - -- Keywords are case-insensitive (TALK = talk = Talk) -- Variables are case-insensitive (host = HOST = Host) -- String parameters can use double quotes or single quotes -- Comments start with REM or ' -- Line continuation uses underscore (_) -- Objects are created with `#{ key: value }` syntax -- Arrays use `[item1, item2, ...]` syntax -- param-* config values become global variables - ---- - -## See Also - -- [Script Execution Flow](./script-execution-flow.md) - Entry points and lifecycle -- [Prompt Blocks](./prompt-blocks.md) - BEGIN SYSTEM PROMPT & BEGIN TALK -- [Basics](./basics.md) - Core concepts -- [Examples](./examples-consolidated.md) - Real-world patterns \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/prompt-blocks.md b/docs/src/chapter-06-gbdialog/prompt-blocks.md deleted file mode 100644 index 78f2b281..00000000 --- a/docs/src/chapter-06-gbdialog/prompt-blocks.md +++ /dev/null @@ -1,426 +0,0 @@ -# Prompt Blocks: BEGIN SYSTEM PROMPT & BEGIN TALK - -Prompt blocks are special multi-line constructs in General Bots BASIC that define AI behavior and formatted user messages. Unlike regular keywords, these blocks preserve formatting, line breaks, and support rich content. - -## Overview - -| Block | Purpose | When Processed | -|-------|---------|----------------| -| `BEGIN SYSTEM PROMPT` | Define AI personality, rules, and capabilities | Bot initialization | -| `BEGIN TALK` | Display formatted multi-line messages | Runtime | - ---- - -## BEGIN SYSTEM PROMPT / END SYSTEM PROMPT - -Defines the AI's behavior, personality, constraints, and available capabilities. This is the "instruction manual" for the LLM. - -### Syntax - -```basic -BEGIN SYSTEM PROMPT -Your system prompt content here. -Multiple lines are supported. -Formatting is preserved. -END SYSTEM PROMPT -``` - -### Purpose - -The system prompt sets the AI's persona and tone, defines rules and constraints, lists available tools and capabilities, specifies response formats, and provides domain knowledge. This block serves as the foundation for how the AI will interact with users throughout the conversation. - -### Complete Example - -```basic -' start.bas - with comprehensive system prompt - -ADD TOOL "create-order" -ADD TOOL "track-shipment" -ADD TOOL "lookup-product" - -USE KB "products" -USE KB "policies" - -BEGIN SYSTEM PROMPT -You are a helpful e-commerce assistant for AcmeStore. - -## Your Persona -- Friendly but professional -- Patient with confused customers -- Proactive in offering help - -## Your Capabilities -You have access to these tools: -- create-order: Create new orders for customers -- track-shipment: Track order shipments by order ID -- lookup-product: Search product catalog - -## Rules -1. Always greet customers warmly -2. Never discuss competitor products -3. For refunds, collect order number first -4. Prices are in USD unless customer specifies otherwise -5. If unsure, ask clarifying questions rather than guessing - -## Response Format -- Keep responses under 100 words unless detailed explanation needed -- Use bullet points for lists -- Include relevant product links when available - -## Escalation -If customer is frustrated or issue is complex, offer to connect with human support. - -## Knowledge -You have access to: -- Complete product catalog (products KB) -- Return and shipping policies (policies KB) -- Current promotions and discounts -END SYSTEM PROMPT - -' Continue with welcome message... -``` - -### Best Practices - -A well-crafted system prompt should be specific about capabilities and constraints. Rather than writing a vague prompt like "You are a helpful assistant," provide detailed context about available tools, behavioral rules, and response expectations: - -```basic -BEGIN SYSTEM PROMPT -You are a medical appointment scheduler. - -Available tools: -- book-appointment: Schedule new appointments -- cancel-appointment: Cancel existing appointments -- check-availability: View available time slots - -Rules: -1. Always confirm patient identity before accessing records -2. Appointments require 24-hour advance notice -3. Emergency cases should be directed to call 911 - -You can access patient records and doctor schedules through the connected systems. -END SYSTEM PROMPT -``` - -### Placement - -Place `BEGIN SYSTEM PROMPT` near the top of `start.bas`, after tool and KB registration. Register tools first, then load knowledge bases, then define the system prompt, and finally include your welcome message. This ordering ensures all capabilities are available when the system prompt references them. - ---- - -## BEGIN TALK / END TALK - -Displays formatted multi-line messages to users with preserved formatting, Markdown support, and emoji rendering. - -### Syntax - -```basic -BEGIN TALK -Your message content here. -Multiple lines supported. -**Markdown** formatting works. -Emojis render: 🎉 ✅ 📦 -END TALK -``` - -### Purpose - -Use `BEGIN TALK` for welcome messages, formatted instructions, multi-line responses, messages with bullet points or structure, and content with emojis or special formatting. - -### Basic Example - -```basic -BEGIN TALK -**Welcome to AcmeStore!** 🛒 - -I can help you with: -• Browsing products -• Placing orders -• Tracking shipments -• Returns and refunds - -What would you like to do today? -END TALK -``` - -### Markdown Support - -`BEGIN TALK` supports common Markdown syntax: - -```basic -BEGIN TALK -# Main Heading - -## Section Heading - -**Bold text** and *italic text* - -- Bullet point 1 -- Bullet point 2 -- Bullet point 3 - -1. Numbered item -2. Another item - -> Quoted text block - -`inline code` - ---- - -[Link text](https://example.com) -END TALK -``` - -### Dynamic Content - -Combine with variables for dynamic messages: - -```basic -customerName = "John" -orderCount = 5 - -BEGIN TALK -Hello, **${customerName}**! 👋 - -You have ${orderCount} orders in your history. - -What would you like to do? -END TALK -``` - -### Comparison: TALK vs BEGIN TALK - -| Feature | `TALK` | `BEGIN TALK` | -|---------|--------|--------------| -| Single line | ✅ | ❌ | -| Multiple lines | Concatenate with + | ✅ Native | -| Formatting preserved | ❌ | ✅ | -| Markdown | Limited | ✅ Full | -| Emojis | ✅ | ✅ | -| Variables | `TALK "Hi " + name` | `${name}` | - -Use `TALK` for simple messages like `TALK "Hello!"` or `TALK "Your order is: " + orderId`. Use `BEGIN TALK` for complex formatted messages that benefit from multiple lines, Markdown formatting, and preserved whitespace. - ---- - -## Real-World Examples - -### Customer Service Bot - -```basic -' start.bas - -ADD TOOL "create-ticket" -ADD TOOL "check-status" -ADD TOOL "escalate" - -USE KB "faq" -USE KB "troubleshooting" - -BEGIN SYSTEM PROMPT -You are a customer service representative for TechSupport Inc. - -## Persona -- Empathetic and patient -- Solution-oriented -- Professional but warm - -## Available Tools -- create-ticket: Create support tickets for issues -- check-status: Check existing ticket status -- escalate: Escalate to human agent - -## Workflow -1. Greet customer and understand their issue -2. Check if issue is in FAQ/troubleshooting KB -3. If solvable, provide solution -4. If not, create ticket or escalate - -## Rules -- Never share internal system information -- Always provide ticket numbers for reference -- Offer escalation if customer requests human help -- Response time SLA: acknowledge within 30 seconds - -## Escalation Triggers -- Customer explicitly requests human -- Issue unresolved after 3 exchanges -- Billing disputes over $100 -- Account security concerns -END SYSTEM PROMPT - -CLEAR SUGGESTIONS -ADD SUGGESTION "Technical Issue" -ADD SUGGESTION "Billing Question" -ADD SUGGESTION "Account Help" - -BEGIN TALK -**Welcome to TechSupport!** 🛠️ - -I'm here to help you with: -• Technical issues and troubleshooting -• Billing and account questions -• Product information - -I can also connect you with a human agent if needed. - -How can I assist you today? -END TALK -``` - -### E-commerce Bot - -```basic -' start.bas - -ADD TOOL "search-products" -ADD TOOL "add-to-cart" -ADD TOOL "checkout" -ADD TOOL "track-order" - -USE KB "catalog" -USE KB "promotions" - -BEGIN SYSTEM PROMPT -You are a shopping assistant for FashionMart. - -## Capabilities -- search-products: Find products by name, category, or description -- add-to-cart: Add items to shopping cart -- checkout: Process payment and create order -- track-order: Track shipment status - -## Knowledge -- Full product catalog with prices and availability -- Current promotions and discount codes -- Shipping policies and delivery times - -## Sales Approach -- Be helpful, not pushy -- Mention relevant promotions naturally -- Suggest complementary products when appropriate -- Always confirm before checkout - -## Constraints -- Cannot modify prices or create custom discounts -- Returns handled through separate process -- Cannot access customer payment details directly - -## Response Style -- Use product images when available -- Include prices in responses -- Mention stock levels for popular items -END SYSTEM PROMPT - -BEGIN TALK -**Welcome to FashionMart!** 👗👔 - -🔥 **Today's Deals:** -• 20% off summer collection -• Free shipping on orders over $50 - -I can help you: -• Find the perfect outfit -• Check sizes and availability -• Track your orders - -What are you looking for today? -END TALK -``` - -### Data Sync Bot (Scheduled) - -Automated bots that run on a schedule don't need welcome messages since there's no user interaction: - -```basic -' sync.bas - No welcome needed, runs on schedule - -SET SCHEDULE "0 0 6 * * *" ' Daily at 6 AM - -BEGIN SYSTEM PROMPT -You are a data synchronization agent. - -## Purpose -Sync product data from external ERP to local database. - -## Process -1. Fetch products from ERP API -2. Compare with local database -3. Update changed records -4. Report statistics - -## Error Handling -- Log all errors -- Continue processing on individual failures -- Send summary email to admin - -## No user interaction required. -END SYSTEM PROMPT - -' No BEGIN TALK needed - this is automated -SEND EMAIL admin1, "Starting daily sync..." - -' ... sync logic ... - -SEND EMAIL admin1, "Sync complete: " + REPORT -``` - ---- - -## Common Patterns - -### Role-Based Prompts - -You can dynamically set different system prompts based on user role: - -```basic -role = GET USER "role" - -SWITCH role - CASE "admin" - BEGIN SYSTEM PROMPT - You are an admin assistant with full system access. - You can manage users, view logs, and modify settings. - END SYSTEM PROMPT - - CASE "customer" - BEGIN SYSTEM PROMPT - You are a customer service assistant. - You can help with orders and general questions. - END SYSTEM PROMPT - - DEFAULT - BEGIN SYSTEM PROMPT - You are a general assistant with limited access. - END SYSTEM PROMPT -END SWITCH -``` - -### Conditional Welcome - -Personalize welcome messages based on context: - -```basic -hour = HOUR(NOW) - -IF hour < 12 THEN - greeting = "Good morning" -ELSE IF hour < 18 THEN - greeting = "Good afternoon" -ELSE - greeting = "Good evening" -END IF - -BEGIN TALK -**${greeting}!** 👋 - -Welcome to our service. How can I help you today? -END TALK -``` - ---- - -## See Also - -The [SET CONTEXT](./keyword-set-context.md) keyword provides dynamic context setting during runtime. The [TALK](./keyword-talk.md) keyword handles simple message output for single-line messages. Review [Script Execution Flow](./script-execution-flow.md) to understand the execution lifecycle. The [Tools System](./keyword-use-tool.md) documentation explains tool registration that works with system prompts. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/script-execution-flow.md b/docs/src/chapter-06-gbdialog/script-execution-flow.md deleted file mode 100644 index 7ede5963..00000000 --- a/docs/src/chapter-06-gbdialog/script-execution-flow.md +++ /dev/null @@ -1,484 +0,0 @@ -# Script Execution Flow & Entry Points - -Understanding how General Bots BASIC scripts are loaded, compiled, and executed is essential for building effective automation. This document covers the complete execution lifecycle. - -## Execution Entry Points - -Scripts in General Bots can be triggered through several entry points: - -![Script Execution Flow](../assets/script-execution-flow.svg) - -*BASIC scripts compile to Rhai AST and execute with registered keyword handlers. Scripts in .gbdialog/ are hot-reloaded on change.* - -### 1. Bot Startup (`start.bas`) - -The primary entry point. Executed when a bot initializes or a conversation begins. - -```basic -' start.bas - Primary entry point -' NO MAIN function needed - execution starts at line 1 - -' 1. Register tools for LLM to use -ADD TOOL "create-order" -ADD TOOL "track-shipment" -ADD TOOL "customer-lookup" - -' 2. Load knowledge bases -USE KB "products" -USE KB "policies" - -' 3. Set AI context/personality -BEGIN SYSTEM PROMPT -You are a helpful e-commerce assistant for AcmeStore. -You can help customers with orders, tracking, and product questions. -Always be friendly and professional. -END SYSTEM PROMPT - -' 4. Setup UI suggestions -CLEAR SUGGESTIONS -ADD SUGGESTION "New Order" -ADD SUGGESTION "Track Package" -ADD SUGGESTION "Contact Support" - -' 5. Welcome message -BEGIN TALK -**Welcome to AcmeStore!** 🛒 - -I can help you: -• Browse and order products -• Track your shipments -• Answer questions - -What would you like to do? -END TALK -``` - -### 2. Scheduled Execution (`SET SCHEDULE`) - -Scripts can run on a cron schedule without user interaction. - -```basic -' sync-data.bas - Runs automatically on schedule -SET SCHEDULE "0 0 */4 * * *" ' Every 4 hours - -' Variables from config.csv are available -' param-host -> host, param-limit -> limit, param-pages -> pages - -SEND EMAIL admin1, "Data sync started..." - -page = 1 -DO WHILE page > 0 AND page < pages - res = GET host + "/products?page=" + page + "&limit=" + limit - - IF res.data THEN - MERGE "products" WITH res.data BY "id" - page = page + 1 - ELSE - page = 0 - END IF - - WAIT 0.5 ' Rate limiting -LOOP - -SEND EMAIL admin1, "Sync complete! " + REPORT -RESET REPORT -``` - -**Cron Format:** `second minute hour day month weekday` - -| Pattern | Description | -|---------|-------------| -| `0 0 8 * * *` | Daily at 8:00 AM | -| `0 30 22 * * *` | Daily at 10:30 PM | -| `0 0 0 */2 * *` | Every 2 days at midnight | -| `0 0 * * * *` | Every hour | -| `0 */15 * * * *` | Every 15 minutes | - -### 3. Webhook Entry (`WEBHOOK`) - -Scripts exposed as HTTP endpoints for external integrations. - -```basic -' order-webhook.bas - HTTP endpoint -WEBHOOK "order-received" - -' Creates: POST /api/bot/{botname}/order-received -' Parameters become variables automatically - -' Access webhook parameters -orderId = GET TOOL PARAM "orderId" -customerEmail = GET TOOL PARAM "email" -amount = GET TOOL PARAM "amount" - -' Validate (optional) -IF orderId = "" THEN - RETURN #{ status: 400, error: "Missing orderId" } -END IF - -' Process the webhook -order = NEW OBJECT -order.id = orderId -order.email = customerEmail -order.amount = amount -order.status = "received" -order.timestamp = NOW - -SAVE "orders", order - -' Notify -TALK TO customerEmail, "Order " + orderId + " received! Total: $" + amount - -RETURN #{ status: 200, orderId: orderId, message: "Order processed" } -``` - -### 4. LLM Tool Invocation - -When registered with `ADD TOOL`, scripts become callable by the LLM during conversation. - -```basic -' create-order.bas - Called by LLM when user wants to order -PARAM productId AS STRING LIKE "PROD-001" REQUIRED -PARAM quantity AS NUMBER LIKE 1 REQUIRED -PARAM customerEmail AS STRING LIKE "john@example.com" REQUIRED -DESCRIPTION "Creates a new order for a product" - -' This script is invoked by the LLM, not directly by user -' The LLM collects all parameters through natural conversation - -product = FIND "products", "id=" + productId - -IF ISEMPTY(product) THEN - RETURN "Product not found: " + productId -END IF - -IF product.stock < quantity THEN - RETURN "Only " + product.stock + " available" -END IF - -' Create the order -order = NEW OBJECT -order.id = "ORD-" + FORMAT(NOW, "yyyyMMddHHmmss") -order.productId = productId -order.quantity = quantity -order.total = product.price * quantity -order.customerEmail = customerEmail -order.status = "pending" - -SAVE "orders", order - -' Update inventory -UPDATE "products", productId, "stock=" + (product.stock - quantity) - -RETURN "Order " + order.id + " created! Total: $" + order.total -``` - -### 5. Event Handlers (`ON`) - -React to system events. - -```basic -' events.bas - Event handlers -ON "message" CALL HandleMessage -ON "user_joined" CALL WelcomeUser -ON "error" CALL LogError - -SUB HandleMessage(message) - ' Process incoming message - LOG_INFO "Received: " + message.text -END SUB - -SUB WelcomeUser(user) - TALK TO user.email, "Welcome to our service!" -END SUB - -SUB LogError(error) - LOG_ERROR "Error occurred: " + error.message - SEND EMAIL admin1, "Bot Error: " + error.message -END SUB -``` - ---- - -## Variable Injection from config.csv - -Variables defined with `param-` prefix in config.csv are automatically injected into script scope. - -### config.csv -```csv -name,value - -bot-name,Bling Integration -bot-description,ERP synchronization bot - -param-host,https://api.bling.com.br/Api/v3 -param-limit,100 -param-pages,50 -param-admin1,admin@company.com -param-admin2,backup@company.com -param-blingClientID,your-client-id -param-blingClientSecret,your-secret -``` - -### Script Usage -```basic -' Variables are available without param- prefix -' All normalized to lowercase for case-insensitivity - -result = GET host + "/products?limit=" + limit - -DO WHILE page < pages - ' Use injected variables directly - data = GET host + "/items?page=" + page -LOOP - -' Admin emails for notifications -SEND EMAIL admin1, "Sync complete!" -SEND EMAIL admin2, "Backup notification" -``` - -### Type Conversion - -Values are automatically converted: -- Numbers: `param-limit,100` → `limit` as integer `100` -- Floats: `param-rate,0.15` → `rate` as float `0.15` -- Booleans: `param-enabled,true` → `enabled` as boolean `true` -- Strings: Everything else remains as string - ---- - -## Case Insensitivity - -**All variables in General Bots BASIC are case-insensitive.** - -```basic -' These all refer to the same variable -host = "https://api.example.com" -result = GET Host + "/endpoint" -TALK HOST -``` - -The preprocessor normalizes all variable names to lowercase while preserving: -- Keywords (remain UPPERCASE for clarity) -- String literals (exact content preserved) -- Comments (skipped entirely) - ---- - -## Script Compilation Flow - -``` -┌─────────────────────────────────────────────────────────────────┐ -│ COMPILATION PIPELINE │ -├─────────────────────────────────────────────────────────────────┤ -│ │ -│ 1. LOAD SOURCE │ -│ └─→ Read .bas file from .gbdialog folder │ -│ │ -│ 2. LOAD CONFIG │ -│ └─→ Read config.csv, extract param-* entries │ -│ └─→ Inject into execution scope │ -│ │ -│ 3. PREPROCESS │ -│ ├─→ Strip comments (REM, ', //) │ -│ ├─→ Process SWITCH/CASE blocks │ -│ ├─→ Normalize variables to lowercase │ -│ ├─→ Transform multi-word keywords │ -│ └─→ Handle FOR EACH blocks │ -│ │ -│ 4. COMPILE │ -│ └─→ Parse to Rhai AST │ -│ │ -│ 5. EXECUTE │ -│ └─→ Run AST with injected scope │ -│ └─→ Keywords call registered handlers │ -│ │ -└─────────────────────────────────────────────────────────────────┘ -``` - ---- - -## Functions vs Entry Points - -### NO MAIN Function - -Unlike traditional programming, BASIC scripts do NOT use a `MAIN` function. Execution starts at line 1. - -```basic -' ❌ WRONG - Don't do this -SUB MAIN() - TALK "Hello" -END SUB - -' ✅ CORRECT - Start directly -TALK "Hello" -``` - -### SUB and FUNCTION for Reuse - -Use `SUB` and `FUNCTION` for reusable code within tools, not as entry points. - -```basic -' sync-products.bas - A complex tool with helper functions - -FUNCTION CalculateDiscount(price, percentage) - RETURN price * (1 - percentage / 100) -END FUNCTION - -SUB NotifyAdmin(message) - SEND EMAIL admin1, message - LOG_INFO message -END SUB - -SUB ProcessProduct(product) - IF product.discount > 0 THEN - product.finalPrice = CalculateDiscount(product.price, product.discount) - ELSE - product.finalPrice = product.price - END IF - SAVE "products", product -END SUB - -' Main execution starts here (not in a MAIN sub) -products = GET host + "/products" - -FOR EACH product IN products.data - CALL ProcessProduct(product) -NEXT product - -CALL NotifyAdmin("Processed " + COUNT(products.data) + " products") -``` - ---- - -## Tool Chain Pattern - -Register tools in `start.bas`, implement in separate files: - -### start.bas -```basic -' Register tools - LLM can call these -ADD TOOL "create-customer" -ADD TOOL "update-customer" -ADD TOOL "delete-customer" - -' Or clear and re-register -CLEAR TOOLS -ADD TOOL "order-management" -ADD TOOL "inventory-check" -``` - -### create-customer.bas -```basic -PARAM name AS STRING LIKE "John Doe" REQUIRED -PARAM email AS STRING LIKE "john@example.com" REQUIRED -PARAM phone AS STRING LIKE "+1-555-0123" -DESCRIPTION "Creates a new customer record in the CRM" - -' Tool implementation -customer = NEW OBJECT -customer.id = "CUS-" + FORMAT(NOW, "yyyyMMddHHmmss") -customer.name = name -customer.email = email -customer.phone = phone -customer.createdAt = NOW - -SAVE "customers", customer - -RETURN #{ - success: true, - customerId: customer.id, - message: "Customer created successfully" -} -``` - ---- - -## Best Practices - -### 1. Organize by Purpose - -``` -mybot.gbai/ -├── mybot.gbdialog/ -│ ├── start.bas ' Entry point, tool registration -│ ├── tables.bas ' Database schema (TABLE definitions) -│ │ -│ ├── create-order.bas ' Tool: order creation -│ ├── track-order.bas ' Tool: order tracking -│ ├── cancel-order.bas ' Tool: order cancellation -│ │ -│ ├── sync-products.bas ' Scheduled: product sync -│ ├── sync-inventory.bas ' Scheduled: inventory sync -│ │ -│ └── order-webhook.bas ' Webhook: external orders -│ -├── mybot.gbot/ -│ └── config.csv ' Configuration & param-* variables -│ -└── mybot.gbkb/ ' Knowledge base files -``` - -### 2. Use param-* for Configuration - -Keep credentials and settings in config.csv, not hardcoded: - -```basic -' ❌ WRONG -host = "https://api.bling.com.br/Api/v3" -apiKey = "hardcoded-key" - -' ✅ CORRECT - From config.csv -' param-host and param-apiKey in config.csv -result = GET host + "/endpoint" -SET HEADER "Authorization", "Bearer " + apikey -``` - -### 3. Error Handling in Tools - -```basic -PARAM orderId AS STRING REQUIRED -DESCRIPTION "Cancels an order" - -order = FIND "orders", "id=" + orderId - -IF ISEMPTY(order) THEN - RETURN #{ success: false, error: "Order not found" } -END IF - -IF order.status = "shipped" THEN - RETURN #{ success: false, error: "Cannot cancel shipped orders" } -END IF - -UPDATE "orders", orderId, "status=cancelled" - -RETURN #{ success: true, message: "Order cancelled" } -``` - -### 4. Logging for Scheduled Jobs - -```basic -SET SCHEDULE "0 0 6 * * *" - -LOG_INFO "Daily sync started" - -' ... sync logic ... - -IF errorCount > 0 THEN - LOG_WARN "Sync completed with " + errorCount + " errors" - SEND EMAIL admin1, "Sync Warning", REPORT -ELSE - LOG_INFO "Sync completed successfully" -END IF - -RESET REPORT -``` - ---- - -## See Also - -- [Keyword Reference](./keywords.md) - Complete keyword documentation -- [SET SCHEDULE](./keyword-set-schedule.md) - Scheduling details -- [WEBHOOK](./keyword-webhook.md) - Webhook configuration -- [Tools System](./keyword-use-tool.md) - Tool registration -- [BEGIN SYSTEM PROMPT](./prompt-blocks.md) - AI context configuration \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/template-enrollment.md b/docs/src/chapter-06-gbdialog/template-enrollment.md deleted file mode 100644 index 18a5e4d8..00000000 --- a/docs/src/chapter-06-gbdialog/template-enrollment.md +++ /dev/null @@ -1,97 +0,0 @@ -# Enrollment Tool Example - -This example shows a complete enrollment tool with parameter definitions and data saving. - -## Complete Enrollment Script - -```basic -PARAM name AS string LIKE "Abreu Silva" -DESCRIPTION "Required full name of the individual." - -PARAM birthday AS date LIKE "23/09/2001" -DESCRIPTION "Required birth date of the individual in DD/MM/YYYY format." - -PARAM email AS string LIKE "abreu.silva@example.com" -DESCRIPTION "Required email address for contact purposes." - -PARAM personalid AS integer LIKE "12345678900" -DESCRIPTION "Required Personal ID number of the individual (only numbers)." - -PARAM address AS string LIKE "Rua das Flores, 123 - SP" -DESCRIPTION "Required full address of the individual." - -DESCRIPTION "This is the enrollment process, called when the user wants to enrol. Once all information is collected, confirm the details and inform them that their enrollment request has been successfully submitted. Provide a polite and professional tone throughout the interaction." - -REM Enrollment Process -TALK "Welcome to the enrollment process! Let's get you registered." - -TALK "First, what is your full name?" -HEAR name - -TALK "Thank you. What is your birth date? (DD/MM/YYYY)" -HEAR birthday - -TALK "What is your email address?" -HEAR email - -TALK "Please provide your Personal ID number (numbers only):" -HEAR personalid - -TALK "Finally, what is your full address?" -HEAR address - -REM Validate and confirm -TALK "Please confirm your details:" -TALK "Name: " + name -TALK "Birth Date: " + birthday -TALK "Email: " + email -TALK "Personal ID: " + personalid -TALK "Address: " + address - -TALK "Are these details correct? (yes/no)" -HEAR confirmation - -IF confirmation = "yes" THEN - REM Save to CSV file - SAVE "enrollments.csv", name, birthday, email, personalid, address - TALK "Thank you! Your enrollment has been successfully submitted. You will receive a confirmation email shortly." -ELSE - TALK "Let's start over with the correct information." - REM In a real implementation, you might loop back or use a different approach -END IF -``` - -## Tool Parameters - -This tool defines 5 parameters with specific types and validation: - -1. **name** (string): Full name with example format -2. **birthday** (date): Birth date in DD/MM/YYYY format -3. **email** (string): Email address for contact -4. **personalid** (integer): Numeric personal ID -5. **address** (string): Complete physical address - -## Data Storage - -The `SAVE` command writes the collected data to a CSV file: -- Creates "enrollments.csv" if it doesn't exist -- Appends new records with all fields -- Maintains data consistency across sessions - -## Usage Flow - -1. User initiates enrollment process -2. Bot collects each piece of information sequentially -3. User confirms accuracy of entered data -4. Data is saved to persistent storage -5. Confirmation message is sent - -## Error Handling - -The script includes: -- Input validation through parameter types -- Confirmation step to prevent errors -- Clear user prompts with format examples -- Graceful handling of correction requests - -This example demonstrates a complete, production-ready tool implementation using the BASIC scripting language. diff --git a/docs/src/chapter-06-gbdialog/template-start.md b/docs/src/chapter-06-gbdialog/template-start.md deleted file mode 100644 index 9a88caca..00000000 --- a/docs/src/chapter-06-gbdialog/template-start.md +++ /dev/null @@ -1,195 +0,0 @@ -# start.bas Template - -The `start.bas` template is the entry point dialog that runs when a user begins a conversation with the bot. It sets up the initial context, loads bot memories, and presents the user with options. - -## Overview - -The start dialog typically performs these tasks: -1. Loads bot memories containing important context -2. Sets up context collections for the LLM -3. Clears and configures suggestion buttons -4. Presents an initial greeting to the user - -## Example: Announcements Bot - -Here's the `start.bas` template from the announcements bot: - -```basic -resume1 = GET BOT MEMORY "resume" -resume2 = GET BOT MEMORY "auxiliom" -resume3 = GET BOT MEMORY "toolbix" - -SET CONTEXT "general" AS resume1 -SET CONTEXT "auxiliom" AS resume2 -SET CONTEXT "toolbix" AS resume3 - -CLEAR SUGGESTIONS - -ADD_SUGGESTION "general" AS "Show me the weekly announcements" -ADD_SUGGESTION "auxiliom" AS "Explain Auxiliom to me" -ADD_SUGGESTION "auxiliom" AS "What does Auxiliom provide?" -ADD_SUGGESTION "toolbix" AS "Show me Toolbix features" -ADD_SUGGESTION "toolbix" AS "How can Toolbix help my business?" - -TALK resume1 -TALK "You can ask me about any of the announcements or circulars." -``` - -## Breaking Down the Script - -### Loading Bot Memories - -```basic -resume1 = GET BOT MEMORY "resume" -resume2 = GET BOT MEMORY "auxiliom" -resume3 = GET BOT MEMORY "toolbix" -``` - -Bot memories are persistent key-value pairs stored in the database. They typically contain: -- Introduction text -- System prompts -- Important context that should always be available - -### Setting Context - -```basic -SET CONTEXT "general" AS resume1 -SET CONTEXT "auxiliom" AS resume2 -SET CONTEXT "toolbix" AS resume3 -``` - -The `SET_CONTEXT` keyword adds text to named context collections that the LLM can access. This ensures the bot has relevant information when answering questions. - -### Configuring Suggestions - -```basic -CLEAR_SUGGESTIONS; - -ADD_SUGGESTION "general" AS "Show me the weekly announcements" -ADD_SUGGESTION "auxiliom" AS "Explain Auxiliom to me" -``` - -Suggestions appear as clickable buttons in the chat interface, helping users understand what the bot can do. - -### Initial Greeting - -```basic -TALK resume1 -TALK "You can ask me about any of the announcements or circulars." -``` - -The bot speaks the introduction text and provides guidance on how to interact. - -## Simple Start Template - -For a minimal bot, a start template might be: - -```basic -intro = GET BOT MEMORY "introduction" -SET CONTEXT "main" AS intro - -TALK "Hello! I'm your assistant." -TALK "How can I help you today?" -``` - -## Start Template with Authentication - -For bots requiring login: - -```basic -user_id = GET BOT MEMORY "current_user" - -IF user_id = "" THEN - TALK "Welcome! Please log in to continue." - RUN "auth.bas" -ELSE - welcome = "Welcome back, " + user_id + "!" - TALK welcome - TALK "What would you like to do today?" -END IF -``` - -## Start Template with Knowledge Base - -For knowledge-focused bots: - -```basic -USE KB "policies" -USE KB "procedures" -USE KB "faqs" - -intro = GET BOT MEMORY "assistant_role" -SET CONTEXT "role" AS intro - -TALK "I have access to company policies, procedures, and FAQs." -TALK "Ask me anything about our documentation!" -``` - -## Best Practices - -1. **Load Essential Context**: Always load critical bot memories at startup -2. **Set Clear Expectations**: Tell users what the bot can do -3. **Provide Suggestions**: Help users get started with example queries -4. **Keep It Brief**: Don't overwhelm users with too much text initially -5. **Handle Errors**: Check if memories exist before using them - -## Configuration - -The start dialog is specified in the bot's `config.csv`: - -```csv -name,value -Start Dialog,start -``` - -This tells BotServer to run `start.bas` when a conversation begins. - -## Common Patterns - -### Multi-Purpose Bot - -```basic -CLEAR_SUGGESTIONS; -ADD_SUGGESTION "support" AS "I need help with a problem" -ADD_SUGGESTION "sales" AS "Tell me about your products" -ADD_SUGGESTION "docs" AS "Show me the documentation" - -TALK "I can help with support, sales, or documentation." -TALK "What brings you here today?" -``` - -### Personalized Greeting - -```basic -hour = HOUR(NOW()) -greeting = "" - -IF hour < 12 THEN - greeting = "Good morning!" -ELSE IF hour < 17 THEN - greeting = "Good afternoon!" -ELSE - greeting = "Good evening!" -END IF - -TALK greeting -TALK "How may I assist you?" -``` - -### Context-Aware Start - -```basic -last_topic = GET BOT MEMORY "last_topic" - -IF last_topic <> "" THEN - msg = "Last time we discussed " + last_topic + "." - TALK msg - TALK "Would you like to continue that conversation?" -ELSE - TALK "Welcome! What would you like to know?" -END IF -``` - -## Summary - -The `start.bas` template sets the tone for the entire conversation. It should be welcoming, informative, and guide users toward productive interactions. By loading context, setting suggestions, and providing clear instructions, you create a smooth onboarding experience for users engaging with your bot. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/template-summary.md b/docs/src/chapter-06-gbdialog/template-summary.md deleted file mode 100644 index 3aaf80cb..00000000 --- a/docs/src/chapter-06-gbdialog/template-summary.md +++ /dev/null @@ -1,201 +0,0 @@ -# generate-summary.bas Template - -The `update-summary.bas` template demonstrates how to create scheduled tasks that automatically update bot memory with fresh content summaries. - -## Overview - -This template shows how to: -1. Schedule a recurring task using `SET SCHEDULE` -2. Retrieve documents from the knowledge base -3. Generate summaries using the LLM -4. Store processed content in bot memory for quick access - -## Example: Update Summary Script - -From the announcements bot's `update-summary.bas`: - -```basic -SET SCHEDULE "59 * * * *" - -text = GET "announcements.gbkb/news/news.pdf" -resume = LLM "In a few words, resume this: " + text - -SET BOT MEMORY "resume", resume - -text1 = GET "announcements.gbkb/auxiliom/auxiliom.pdf" -SET BOT MEMORY "auxiliom", text1 - -text2 = GET "announcements.gbkb/toolbix/toolbix.pdf" -SET BOT MEMORY "toolbix", text2 -``` - -## Breaking Down the Script - -### Scheduling with Cron Expression - -```basic -SET SCHEDULE "59 * * * *" -``` - -This schedules the script to run at 59 minutes past every hour. The cron format is: -- Minute (0-59) -- Hour (0-23) -- Day of month (1-31) -- Month (1-12) -- Day of week (0-6) - -Common schedule patterns: -- `"0 9 * * *"` - Daily at 9:00 AM -- `"0 */6 * * *"` - Every 6 hours -- `"*/30 * * * *"` - Every 30 minutes -- `"0 0 * * 1"` - Weekly on Monday at midnight - -### Retrieving Documents - -```basic -text = GET "announcements.gbkb/news/news.pdf" -``` - -The `GET` keyword retrieves files from the bot's knowledge base stored in drive storage. The path is relative to the bot's bucket. - -### Generating Summaries with LLM - -```basic -resume = LLM "In a few words, resume this: " + text -``` - -The `LLM` keyword sends a prompt to the language model and returns the response. Here it's creating a concise summary of the document. - -### Storing in Bot Memory - -```basic -SET BOT MEMORY "resume", resume -``` - -Bot memories are persistent key-value pairs that survive across sessions. They're perfect for storing pre-processed content that needs quick access. - -## Use Cases - -### Daily News Digest - -```basic -SET SCHEDULE "0 6 * * *" ' Daily at 6 AM - -news = GET "knowledge/daily-news.txt" -summary = LLM "Create a brief summary of today's key points: " + news - -SET BOT MEMORY "daily_digest", summary -``` - -### Weekly Report Generation - -```basic -SET SCHEDULE "0 9 * * 1" ' Monday at 9 AM - -data = GET "reports/weekly-data.csv" -analysis = LLM "Analyze this weekly data and highlight trends: " + data - -SET BOT MEMORY "weekly_report", analysis -``` - -### Content Freshness Check - -```basic -SET SCHEDULE "0 */4 * * *" ' Every 4 hours - -doc = GET "policies/current-policy.pdf" -extract = LLM "Extract the version and date from this document: " + doc - -SET BOT MEMORY "policy_version", extract -``` - -## Best Practices - -1. **Schedule Wisely**: Avoid scheduling resource-intensive tasks too frequently -2. **Handle Errors**: Check if documents exist before processing -3. **Optimize Prompts**: Use clear, concise prompts for better LLM responses -4. **Memory Management**: Use meaningful keys for bot memories -5. **Test First**: Run the script manually before scheduling - -## Integration with Start Dialog - -The memories set by scheduled tasks can be used in the start dialog: - -```basic -' In start.bas -resume = GET BOT MEMORY "resume" -SET CONTEXT "summary" AS resume -TALK resume -``` - -## Monitoring Scheduled Tasks - -Scheduled tasks run in the background. Check logs for execution status: -- Successful runs are logged at INFO level -- Errors are logged at ERROR level -- Schedule changes are logged when the script runs - -## Common Patterns - -### Conditional Updates - -```basic -SET SCHEDULE "0 * * * *" ' Hourly - -current = GET "data/current.json" -stored = GET BOT MEMORY "last_data" - -IF current <> stored THEN - summary = LLM "Summarize changes in: " + current - SET BOT MEMORY "last_data", current - SET BOT MEMORY "change_summary", summary -END IF -``` - -### Multiple Document Processing - -```basic -SET SCHEDULE "0 0 * * *" ' Daily at midnight - -docs = ["doc1.pdf", "doc2.pdf", "doc3.pdf"] -combined = "" - -FOR EACH doc IN docs - content = GET "knowledge/" + doc - combined = combined + "\n---\n" + content -NEXT - -summary = LLM "Create an executive summary: " + combined -SET BOT MEMORY "daily_summary", summary -``` - -### Time-Based Content - -```basic -SET SCHEDULE "0 7 * * *" ' Daily at 7 AM - -hour = HOUR(NOW()) -greeting = "" - -IF hour < 12 THEN - greeting = "Good morning! " -ELSE - greeting = "Good day! " -END IF - -news = GET "updates/daily.txt" -brief = LLM "Summarize in one sentence: " + news - -SET BOT MEMORY "daily_greeting", greeting + brief -``` - -## Limitations - -- Scripts run asynchronously - don't expect immediate updates -- Long-running scripts may timeout -- Memory updates are not instantly visible to active sessions -- Schedule syntax must be valid cron format - -## Summary - -The update-summary pattern enables bots to maintain fresh, pre-processed content without manual intervention. By combining `SET SCHEDULE`, `GET`, `LLM`, and `SET BOT MEMORY`, you can create intelligent bots that stay current with changing information and provide instant access to summarized content. \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/template-variables.md b/docs/src/chapter-06-gbdialog/template-variables.md deleted file mode 100644 index 7c378b2c..00000000 --- a/docs/src/chapter-06-gbdialog/template-variables.md +++ /dev/null @@ -1,249 +0,0 @@ -# Template Variables - -Templates support variable substitution using double curly braces `{{variable_name}}`. Variables are replaced at send time with values from the provided data object. - -General Bots - -## Built-in Variables - -These variables are automatically available in all templates without explicit declaration: - -| Variable | Description | Example | -|----------|-------------|---------| -| `{{recipient}}` | Recipient email or phone | `john@example.com` | -| `{{to}}` | Alias for recipient | `john@example.com` | -| `{{date}}` | Current date (YYYY-MM-DD) | `2025-01-22` | -| `{{time}}` | Current time (HH:MM) | `14:30` | -| `{{datetime}}` | Combined date and time | `2025-01-22 14:30` | -| `{{year}}` | Current year | `2025` | -| `{{month}}` | Current month name | `January` | - -## Custom Variables - -Pass custom variables via the variables parameter in `SEND TEMPLATE`: - -```basic -WITH vars - .name = "John" - .company = "Acme Corp" - .product = "Pro Plan" - .discount = "20%" -END WITH - -SEND TEMPLATE "welcome", "email", "john@example.com", vars -``` - -The template content would reference these variables: - -``` -Hello {{name}}, - -Welcome to {{company}}! You've signed up for {{product}}. - -As a special offer, use code WELCOME for {{discount}} off your first purchase. - -Best regards, -The Team -``` - -## Channel-Specific Templates - -### Email Templates - -Email templates support automatic `Subject:` line extraction. Place the subject on the first line: - -``` -Subject: Welcome to {{company}}, {{name}}! - -Hello {{name}}, - -Thank you for joining us... -``` - -The system extracts the subject line and uses the remainder as the body. - -### WhatsApp Templates - -WhatsApp templates must be pre-approved by Meta. Use numbered placeholders as required by the WhatsApp Business API: - -``` -Hello {{1}}, your order {{2}} has shipped. Track at {{3}} -``` - -Map variables using numeric keys: - -```basic -WITH vars - .1 = customer_name - .2 = order_id - .3 = tracking_url -END WITH - -SEND TEMPLATE "order-shipped", "whatsapp", phone, vars -``` - -### SMS Templates - -Keep SMS templates under 160 characters for single-segment delivery: - -``` -Hi {{name}}, your code is {{code}}. Valid for 10 minutes. -``` - -## Template Examples - -### Welcome Email - -``` -Subject: Welcome to {{company}}! - -Hi {{name}}, - -Thanks for signing up on {{date}}. Here's what you can do next: - -1. Complete your profile -2. Explore our features -3. Join our community - -Questions? Reply to this email. - -Best, -{{company}} Team -``` - -### Order Confirmation - -``` -Subject: Order #{{order_id}} Confirmed - -Hi {{name}}, - -Your order has been confirmed! - -Order: #{{order_id}} -Date: {{date}} -Total: {{total}} - -Items: -{{items}} - -Shipping to: -{{address}} - -Track your order: {{tracking_url}} -``` - -### Appointment Reminder - -``` -Subject: Reminder: {{appointment_type}} tomorrow - -Hi {{name}}, - -This is a reminder of your upcoming appointment: - -Date: {{appointment_date}} -Time: {{appointment_time}} -Location: {{location}} - -Need to reschedule? Reply to this email or call {{phone}}. - -See you soon! -``` - -## Creating Templates - -### Via BASIC - -```basic -CREATE TEMPLATE "welcome", "email", "Welcome {{name}}!", "Hello {{name}}, thank you for joining {{company}}!" -``` - -### Retrieving Templates - -```basic -template = GET TEMPLATE "welcome" -TALK "Template body: " + template.body -``` - -## Variable Extraction - -Variables are automatically extracted from template content when the template is created. The system identifies all `{{variable}}` patterns and stores them for validation. Built-in variables (recipient, date, time, etc.) are excluded from the extraction. - -## Fallback Values - -Handle missing variables using `NVL` in your code: - -```basic -WITH vars - .name = NVL(user_name, "Friend") - .company = NVL(user_company, "your organization") -END WITH - -SEND TEMPLATE "greeting", "email", email, vars -``` - -## Multi-Channel Delivery - -Send the same template to multiple channels in one call: - -```basic -WITH vars - .name = "John" - .message = "Your appointment is confirmed" -END WITH - -SEND TEMPLATE "appointment-confirm", "email,sms,whatsapp", recipient, vars -``` - -Or send channel-specific versions: - -```basic -SEND TEMPLATE "appointment-email", "email", email, vars -SEND TEMPLATE "appointment-sms", "sms", phone, vars -``` - -## Bulk Sending - -Send templates to multiple recipients: - -```basic -recipients = ["a@example.com", "b@example.com", "c@example.com"] -count = SEND TEMPLATE "newsletter" TO "email" recipients, #{month: "January"} -TALK "Sent to " + count + " recipients" -``` - -## Best Practices - -**Keep variable names simple.** Use `name` rather than `customer_first_name_from_database`. Shorter names are easier to maintain. - -**Provide fallbacks.** Always handle the case where a variable might be missing or empty. - -**Test templates.** Verify all variables populate correctly before deploying to production. - -**Respect channel limits.** SMS has a 160-character single-segment limit. WhatsApp templates require Meta approval. - -**Personalize thoughtfully.** Using `{{name}}` improves engagement, but avoid over-personalization that feels intrusive. - -**Include unsubscribe options.** Marketing emails should always provide an unsubscribe mechanism. - -## Database Storage - -Templates are stored in the `message_templates` table: - -| Column | Type | Description | -|--------|------|-------------| -| `id` | UUID | Template identifier | -| `bot_id` | UUID | Owning bot | -| `name` | TEXT | Template name | -| `channel` | TEXT | email/whatsapp/sms/telegram/push | -| `subject` | TEXT | Email subject (nullable) | -| `body` | TEXT | Template body | -| `variables` | JSONB | List of variable names | -| `is_active` | BOOL | Active status | - -## See Also - -- [SEND TEMPLATE Keyword](./keywords.md) - Full keyword reference -- [SET SCHEDULE](./keyword-set-schedule.md) - Scheduled template delivery -- [Universal Messaging](./universal-messaging.md) - Multi-channel patterns \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates.md b/docs/src/chapter-06-gbdialog/templates.md deleted file mode 100644 index c429a168..00000000 --- a/docs/src/chapter-06-gbdialog/templates.md +++ /dev/null @@ -1,118 +0,0 @@ -# Template Examples - -Templates are pre-built BASIC scripts that demonstrate common use cases and patterns. Each template includes complete code, explanations, and **interactive WhatsApp-style sample dialogs** showing how the bot behaves in real conversations. - -## Available Templates - -### 🚀 [start.bas](./templates/start.md) -**Topic: Basic Greeting & Help Flow** - -The simplest possible bot - learn BASIC fundamentals with a greeting flow that demonstrates `SET`, `TALK`, `HEAR`, and `IF/ELSE`. - -Perfect for: -- Learning BASIC syntax -- Quick demos -- Starting point for new bots - ---- - -### 📋 [enrollment.bas](./templates/enrollment.md) -**Topic: User Registration & Data Collection** - -A complete data collection workflow that gathers user information step-by-step, validates inputs, confirms details, and saves the data. - -Perfect for: -- Customer onboarding -- Event registrations -- Lead capture forms -- Survey collection - ---- - -### 🔐 [auth.bas](./templates/auth.md) -**Topic: Authentication Patterns** - -Secure user authentication flows including login, registration, password reset, and session management. - -Perfect for: -- User login systems -- Account verification -- Password recovery -- Session handling - ---- - -## Template Structure - -Each template documentation includes: - -1. **Topic Description** - What the template is for -2. **The Code** - Complete, working BASIC script -3. **Sample Dialogs** - WhatsApp-style conversations showing real interactions -4. **Keywords Used** - Quick reference of BASIC keywords -5. **Customization Ideas** - Ways to extend the template - -## Using Templates - -### Method 1: Copy and Customize - -Copy the template code into your `.gbdialog` folder and modify it: - -```basic -' Copy start.bas and customize -SET user_name = "Guest" -TALK "Hello, " + user_name + "! Welcome to My Company." -HEAR user_input -' ... add your logic -``` - -### Method 2: Include Templates - -Use the `INCLUDE` keyword to use templates as building blocks: - -```basic -INCLUDE "templates/auth.bas" - -' Now use auth functions -CALL authenticate_user() -``` - -### Method 3: Use as Reference - -Study the templates to learn patterns, then write your own: - -```basic -' Learned from enrollment.bas pattern -PARAM name AS string LIKE "John Doe" -DESCRIPTION "User's full name" - -TALK "What's your name?" -HEAR name -' ... continue with your logic -``` - -## More Templates - -The `templates/` directory contains 20+ ready-to-use bot configurations: - -| Template | Description | -|----------|-------------| -| `default.gbai` | Basic bot with weather, email, and calculation tools | -| `edu.gbai` | Educational bot for course management | -| `crm.gbai` | Customer relationship management | -| `announcements.gbai` | Broadcast messaging system | -| `whatsapp.gbai` | WhatsApp Business integration | -| `store.gbai` | E-commerce bot | -| `healthcare` | Healthcare appointment scheduling | -| `hr` | Human resources assistant | -| `finance` | Financial services bot | -| `marketing.gbai` | Marketing automation | -| `reminder.gbai` | Task and reminder management | -| `backup.gbai` | Automated backup workflows | -| `crawler.gbai` | Web crawling and data extraction | - -## Related - -- [BASIC vs n8n/Zapier/Make](./basic-vs-automation-tools.md) - Why BASIC beats drag-and-drop tools -- [Keywords Reference](./keywords.md) - Complete keyword documentation -- [Consolidated Examples](./examples-consolidated.md) - More code examples \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/ai-search.md b/docs/src/chapter-06-gbdialog/templates/ai-search.md deleted file mode 100644 index b0b3fd66..00000000 --- a/docs/src/chapter-06-gbdialog/templates/ai-search.md +++ /dev/null @@ -1,338 +0,0 @@ -# AI Search Template - -The AI Search template provides an intelligent document search bot that uses AI to answer questions based on your uploaded documents. It combines vector search with large language models for accurate, context-aware responses. - -## Topic: AI-Powered Document Search & Q&A - -This template is perfect for: -- Knowledge base assistants -- Document-based customer support -- Internal documentation search -- FAQ automation with source documents - -## The Code - -```basic -REM AI Search - Intelligent Document Q&A -REM Uses RAG (Retrieval Augmented Generation) for accurate answers - -' Add search tools -ADD TOOL "search-documents" -ADD TOOL "summarize-document" - -' Use the knowledge base -USE KB "ai-search.gbkb" - -' Set up the AI context -SET CONTEXT "document-search" AS "You are a helpful document search assistant. Answer questions based on the documents in your knowledge base. Always cite your sources when possible. If the answer is not in the documents, say so clearly." - -' Clear and add suggestions -CLEAR SUGGESTIONS -ADD SUGGESTION "search" AS "Search documents" -ADD SUGGESTION "summary" AS "Get document summary" -ADD SUGGESTION "help" AS "How to use" - -BEGIN TALK -**AI Search Assistant** 🔍 - -I can help you find information in your documents using AI-powered search. - -**What I can do:** -• Search across all uploaded documents -• Answer questions with context -• Summarize long documents -• Find specific information quickly - -Just ask me a question or describe what you're looking for. -END TALK - -BEGIN SYSTEM PROMPT -You are an AI document search assistant with access to a knowledge base of documents. - -When answering questions: -1. Search the knowledge base for relevant information -2. Provide accurate answers based on the documents -3. Cite the source document when possible -4. If information isn't found, clearly state that -5. Offer to search for related topics - -Be concise but thorough. Always prioritize accuracy over speed. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the AI Search template works in real-world scenarios. - -### Dialog 1: Document Search Query - - - -### Dialog 2: Information Not Found - - - -### Dialog 3: Document Summary Request - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register search and summary tools | -| `USE KB` | Connect to the knowledge base | -| `SET CONTEXT` | Define the AI's role and behavior | -| `ADD SUGGESTION` | Create quick action buttons | -| `BEGIN TALK/END TALK` | Multi-line welcome message | -| `BEGIN SYSTEM PROMPT/END SYSTEM PROMPT` | Define AI behavior rules | - -## How It Works - -1. **Knowledge Base Connection**: `USE KB` loads your documents for semantic search -2. **Tool Registration**: `ADD TOOL` enables search and summarization capabilities -3. **Context Setting**: `SET CONTEXT` tells the AI how to behave -4. **User Query**: User asks a question in natural language -5. **RAG Process**: System searches documents, retrieves relevant chunks -6. **AI Response**: LLM generates answer based on retrieved context - -## Template Structure - -``` -ai-search.gbai/ -├── ai-search.gbdialog/ -│ ├── start.bas # Main entry point -│ └── qr.bas # QR code handler -├── ai-search.gbdrive/ -│ └── manuals/ # Folder for PDF documents -│ └── 42LB5800.pdf # Example manual -├── ai-search.gbkb/ -│ └── docs/ # Knowledge base documents -│ └── README.md # KB documentation -└── ai-search.gbot/ - └── config.csv # Bot configuration -``` - -## Customization Ideas - -### Add Document Categories - -```basic -ADD SUGGESTION "manuals" AS "📚 Product Manuals" -ADD SUGGESTION "policies" AS "📋 Policies" -ADD SUGGESTION "tutorials" AS "🎓 Tutorials" - -HEAR category - -SWITCH category - CASE "manuals" - USE KB "manuals.gbkb" - CASE "policies" - USE KB "policies.gbkb" - CASE "tutorials" - USE KB "tutorials.gbkb" -END SWITCH -``` - -### Add Source Citations - -```basic -SET CONTEXT "search-with-citations" AS "Always include the document name and page number when citing information. Format: [Document Name, Page X]" -``` - -### Add Search Filters - -```basic -PARAM search_query AS STRING LIKE "how to reset" DESCRIPTION "What to search for" -PARAM doc_type AS STRING LIKE "manual" DESCRIPTION "Type of document: manual, policy, guide" - -DESCRIPTION "Search documents with optional type filter" - -IF doc_type <> "" THEN - results = FIND "documents.csv", "type = '" + doc_type + "'" - ' Search within filtered results -ELSE - ' Search all documents -END IF -``` - -### Add Follow-up Questions - -```basic -TALK "Here's what I found about your question..." -TALK response - -TALK "Would you like me to:" -ADD SUGGESTION "more" AS "Tell me more" -ADD SUGGESTION "related" AS "Show related topics" -ADD SUGGESTION "new" AS "Ask new question" -HEAR followup - -IF followup = "more" THEN - ' Provide more detail -ELSE IF followup = "related" THEN - ' Show related topics -END IF -``` - -## Best Practices - -1. **Organize Documents**: Keep documents in logical folders within `.gbdrive` -2. **Update Regularly**: Re-index knowledge base when documents change -3. **Clear Context**: Set a specific context to improve answer relevance -4. **Handle Missing Info**: Always gracefully handle cases where info isn't found -5. **Cite Sources**: Configure the AI to cite document sources for credibility - -## Related Templates - -- [talk-to-data.md](./talk-to-data.md) - Query structured data with natural language -- [crawler.md](./crawler.md) - Crawl websites to build knowledge bases - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/analytics-dashboard.md b/docs/src/chapter-06-gbdialog/templates/analytics-dashboard.md deleted file mode 100644 index 48c4fa43..00000000 --- a/docs/src/chapter-06-gbdialog/templates/analytics-dashboard.md +++ /dev/null @@ -1,283 +0,0 @@ -# Analytics Dashboard Template - -The analytics dashboard template provides real-time insights into your knowledge base performance, document statistics, and system health metrics. It uses pre-computed statistics stored in bot memory for fast loading. - -## Topic: Knowledge Base Analytics & Monitoring - -This template is perfect for: -- Monitoring knowledge base growth -- Tracking document indexing status -- System health monitoring -- Capacity planning - -## The Code - -```basic -REM Analytics Dashboard Start Dialog -REM Displays pre-computed statistics from update-stats.bas - -DESCRIPTION "View knowledge base analytics and statistics" - -REM Load pre-computed values from BOT MEMORY -totalDocs = GET BOT MEMORY("analytics_total_docs") -totalVectors = GET BOT MEMORY("analytics_total_vectors") -storageMB = GET BOT MEMORY("analytics_storage_mb") -collections = GET BOT MEMORY("analytics_collections") -docsWeek = GET BOT MEMORY("analytics_docs_week") -docsMonth = GET BOT MEMORY("analytics_docs_month") -growthRate = GET BOT MEMORY("analytics_growth_rate") -healthPercent = GET BOT MEMORY("analytics_health_percent") -lastUpdate = GET BOT MEMORY("analytics_last_update") - -REM Set contexts for different report types -SET CONTEXT "overview" AS "Total documents: " + totalDocs + ", Storage: " + storageMB + " MB" -SET CONTEXT "activity" AS "Documents added this week: " + docsWeek + ", Growth rate: " + growthRate + "%" -SET CONTEXT "health" AS "System health: " + healthPercent + "%, Last updated: " + lastUpdate - -REM Setup suggestions -CLEAR SUGGESTIONS -ADD SUGGESTION "overview" AS "Show overview" -ADD SUGGESTION "activity" AS "Recent activity" -ADD SUGGESTION "health" AS "System health" - -REM Display dashboard -TALK "📊 **Analytics Dashboard**" -TALK "" -TALK "**Knowledge Base Overview**" -TALK "• Documents: " + FORMAT(totalDocs, "#,##0") -TALK "• Vectors: " + FORMAT(totalVectors, "#,##0") -TALK "• Storage: " + FORMAT(storageMB, "#,##0.00") + " MB" -TALK "" -TALK "Ask me about any metric or select a topic above." -``` - -## Sample Dialogs - -These conversations show how the analytics dashboard works in real-world scenarios. - -### Dialog 1: Viewing Overview Statistics - - - -### Dialog 2: Checking System Health - - - -### Dialog 3: Statistics Not Yet Computed - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `GET BOT MEMORY` | Retrieve pre-computed statistics | -| `SET CONTEXT` | Provide context for AI responses | -| `CLEAR SUGGESTIONS` | Reset quick reply options | -| `ADD SUGGESTION` | Add quick reply buttons | -| `TALK` | Display formatted statistics | -| `FORMAT` | Format numbers with separators | - -## How It Works - -1. **Load Statistics**: Pre-computed values are retrieved from bot memory -2. **Set Contexts**: Different contexts are set for overview, activity, and health queries -3. **Setup UI**: Quick reply suggestions are configured -4. **Display Dashboard**: Formatted statistics are shown to the user - -## The Update Stats Job - -Statistics are pre-computed by a scheduled job to ensure fast dashboard loading: - -```basic -REM update-stats.bas - Scheduled job to compute analytics -SET SCHEDULE "0 * * * *" REM Run every hour - -REM Compute statistics -totalDocs = KB DOCUMENTS COUNT() -totalVectors = KB STATISTICS().total_vectors -storageMB = KB STORAGE SIZE() / 1024 / 1024 -collections = UBOUND(KB LIST COLLECTIONS()) - -REM Calculate activity -docsWeek = KB DOCUMENTS ADDED SINCE(NOW() - 7) -docsMonth = KB DOCUMENTS ADDED SINCE(NOW() - 30) - -REM Store in bot memory -SET BOT MEMORY "analytics_total_docs", totalDocs -SET BOT MEMORY "analytics_total_vectors", totalVectors -SET BOT MEMORY "analytics_storage_mb", storageMB -SET BOT MEMORY "analytics_collections", collections -SET BOT MEMORY "analytics_docs_week", docsWeek -SET BOT MEMORY "analytics_docs_month", docsMonth -SET BOT MEMORY "analytics_last_update", NOW() - -TALK "Analytics updated successfully." -``` - -## Customization Ideas - -### Add Export Functionality - -```basic -ADD TOOL "export-stats" - -REM In export-stats.bas -PARAM format AS STRING LIKE "csv" DESCRIPTION "Export format: csv, json, xlsx" - -data = [] -data.total_docs = GET BOT MEMORY("analytics_total_docs") -data.total_vectors = GET BOT MEMORY("analytics_total_vectors") -data.storage_mb = GET BOT MEMORY("analytics_storage_mb") - -IF format = "csv" THEN - SAVE "analytics-export.csv", data - TALK "📥 Analytics exported to analytics-export.csv" -ELSE IF format = "json" THEN - WRITE "analytics-export.json", TOJSON(data) - TALK "📥 Analytics exported to analytics-export.json" -END IF -``` - -### Add Alerting - -```basic -REM Check for issues and alert -IF healthPercent < 90 THEN - SEND MAIL "admin@company.com", "System Health Alert", "Health dropped to " + healthPercent + "%" -END IF - -IF storageMB > 900 THEN - SEND MAIL "admin@company.com", "Storage Warning", "Storage usage at " + storageMB + " MB" -END IF -``` - -### Add Trend Visualization - -```basic -REM Generate a simple trend chart -ADD TOOL "show-trend" - -REM Collect historical data -history = FIND "analytics_history.csv", "date > " + FORMAT(NOW() - 30, "YYYY-MM-DD") - -REM Create chart -chart = CREATE CHART "line", history, "date", "documents" -TALK chart -``` - -## Related Templates - -- [backup.bas](./backup.md) - Backup management and monitoring -- [start.bas](./start.md) - Basic bot structure - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/announcements.md b/docs/src/chapter-06-gbdialog/templates/announcements.md deleted file mode 100644 index 0734ab53..00000000 --- a/docs/src/chapter-06-gbdialog/templates/announcements.md +++ /dev/null @@ -1,415 +0,0 @@ -# Announcements Template - -The announcements template provides a company communication system for sharing weekly updates, circulars, and organizational news through an AI-powered conversational interface. - -## Topic: Company Announcements & Communications - -This template is perfect for: -- Weekly company announcements -- Internal circulars distribution -- Multi-topic news aggregation -- Organizational communications -- Employee information portals - -## The Code - -```basic -resume1 = GET BOT MEMORY("resume") -resume2 = GET BOT MEMORY("auxiliom") -resume3 = GET BOT MEMORY("toolbix") - -SET CONTEXT "general" AS resume1 -SET CONTEXT "auxiliom" AS resume2 -SET CONTEXT "toolbix" AS resume3 - -CLEAR SUGGESTIONS - -ADD SUGGESTION "general" AS "Weekly announcements" -ADD SUGGESTION "general" AS "Latest circulars" -ADD SUGGESTION "auxiliom" AS "What is Auxiliom?" -ADD SUGGESTION "auxiliom" AS "Auxiliom services" -ADD SUGGESTION "toolbix" AS "Toolbix features" -ADD SUGGESTION "toolbix" AS "Toolbix for business" - -ADD TOOL "change-subject" - -TALK resume1 -TALK "Ask me about any announcement or circular." -``` - -## Sample Dialogs - -These conversations show how the announcements template works in real-world scenarios. - -### Dialog 1: Weekly Announcements - - - -### Dialog 2: Switching Topics - - - -### Dialog 3: Latest Circulars - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `GET BOT MEMORY` | Retrieve stored announcement summaries | -| `SET CONTEXT` | Define contexts for different topics | -| `CLEAR SUGGESTIONS` | Reset quick reply options | -| `ADD SUGGESTION` | Create topic-based quick replies | -| `ADD TOOL` | Register topic switching tool | -| `TALK` | Display announcements to user | - -## How It Works - -1. **Load Content**: Pre-stored summaries are retrieved from bot memory -2. **Multi-Context Setup**: Different contexts for each announcement topic -3. **Topic Suggestions**: Quick replies organized by topic category -4. **Dynamic Display**: Current announcements shown on start -5. **Topic Switching**: Users can change subjects using the tool - -## Template Structure - -``` -announcements.gbai/ -├── announcements.gbdialog/ -│ ├── start.bas # Main entry point -│ ├── auth.bas # Admin authentication -│ ├── change-subject.bas # Topic switching -│ └── update-summary.bas # Update announcements -├── announcements.gbkb/ -│ ├── auxiliom/ # Auxiliom topic KB -│ ├── news/ # General news KB -│ └── toolbix/ # Toolbix topic KB -└── announcements.gbot/ - └── config.csv # Bot configuration -``` - -## Change Subject Tool: change-subject.bas - -```basic -PARAM subject AS STRING LIKE "toolbix" DESCRIPTION "Topic to switch to: general, auxiliom, toolbix" - -DESCRIPTION "Change the current announcement topic" - -subject_lower = LCASE(subject) - -IF subject_lower = "general" OR INSTR(subject_lower, "news") > 0 OR INSTR(subject_lower, "announcement") > 0 THEN - resume = GET BOT MEMORY("resume") - SET CONTEXT "current" AS resume - TALK "📰 Switched to **General Announcements**" - TALK resume -ELSE IF subject_lower = "auxiliom" THEN - resume = GET BOT MEMORY("auxiliom") - SET CONTEXT "current" AS resume - TALK "🔧 Switched to **Auxiliom**" - TALK resume -ELSE IF subject_lower = "toolbix" THEN - resume = GET BOT MEMORY("toolbix") - SET CONTEXT "current" AS resume - TALK "🛠️ Switched to **Toolbix**" - TALK resume -ELSE - TALK "Available topics: General Announcements, Auxiliom, Toolbix" - TALK "Which topic would you like?" -END IF - -RETURN subject_lower -``` - -## Update Summary Tool: update-summary.bas - -```basic -PARAM topic AS STRING LIKE "general" DESCRIPTION "Topic to update" -PARAM content AS STRING DESCRIPTION "New summary content" - -DESCRIPTION "Update the announcement summary for a topic (admin only)" - -' Verify admin access -IF NOT IS_ADMIN(user_id) THEN - TALK "⚠️ This action requires administrator privileges." - RETURN NULL -END IF - -topic_lower = LCASE(topic) - -IF topic_lower = "general" THEN - SET BOT MEMORY "resume", content -ELSE IF topic_lower = "auxiliom" THEN - SET BOT MEMORY "auxiliom", content -ELSE IF topic_lower = "toolbix" THEN - SET BOT MEMORY "toolbix", content -ELSE - TALK "Unknown topic. Use: general, auxiliom, or toolbix" - RETURN NULL -END IF - -' Log the update -WITH updateLog - timestamp = NOW() - updatedBy = user_id - topicUpdated = topic_lower - contentLength = LEN(content) -END WITH - -SAVE "announcement_log.csv", updateLog - -TALK "✅ " + topic + " summary updated successfully!" -TALK "Changes are now live." - -RETURN topic_lower -``` - -## Customization Ideas - -### Add Email Distribution - -```basic -ADD TOOL "send-announcement" - -PARAM announcement AS STRING DESCRIPTION "Announcement to distribute" -PARAM recipients AS STRING LIKE "all" DESCRIPTION "Recipients: all, managers, department name" - -' Get recipient list -IF recipients = "all" THEN - employees = FIND "employees.csv" -ELSE IF recipients = "managers" THEN - employees = FIND "employees.csv", "role = 'manager'" -ELSE - employees = FIND "employees.csv", "department = '" + recipients + "'" -END IF - -FOR EACH emp IN employees - SEND MAIL emp.email, "Company Announcement", announcement - WAIT 1 -NEXT - -TALK "📧 Announcement sent to " + UBOUND(employees) + " recipients." -``` - -### Add Announcement Categories - -```basic -CLEAR SUGGESTIONS - -ADD SUGGESTION "hr" AS "HR Updates" -ADD SUGGESTION "it" AS "IT Announcements" -ADD SUGGESTION "finance" AS "Finance News" -ADD SUGGESTION "events" AS "Upcoming Events" -ADD SUGGESTION "policy" AS "Policy Changes" -ADD SUGGESTION "all" AS "All Announcements" -``` - -### Add Read Receipts - -```basic -' Track who has read announcements -WITH readReceipt - userId = user_id - announcementId = current_announcement_id - readAt = NOW() -END WITH - -SAVE "read_receipts.csv", readReceipt - -' Check read percentage -total = COUNT("employees.csv") -reads = COUNT("read_receipts.csv", "announcementId = '" + current_announcement_id + "'") -percentage = (reads / total) * 100 - -TALK "📊 " + FORMAT(percentage, "#0") + "% of employees have read this announcement." -``` - -### Add Scheduled Announcements - -```basic -PARAM schedule_time AS STRING LIKE "2025-01-20 09:00" DESCRIPTION "When to publish" -PARAM announcement AS STRING DESCRIPTION "Announcement content" - -SET SCHEDULE schedule_time - -SET BOT MEMORY "resume", announcement - -' Notify all employees -employees = FIND "employees.csv" -FOR EACH emp IN employees - TALK TO emp.phone, "📢 New announcement: " + LEFT(announcement, 100) + "..." -NEXT - -TALK "Announcement published and distributed." -``` - -## Best Practices - -1. **Keep It Current**: Update announcements regularly -2. **Organize by Topic**: Use clear topic categories -3. **Summarize**: Start with key points, allow drill-down -4. **Archive Old News**: Move outdated items to archive -5. **Track Engagement**: Monitor which topics get most questions - -## Related Templates - -- [broadcast.bas](./broadcast.md) - Mass messaging to employees -- [edu.bas](./edu.md) - Educational announcements -- [hr-employees.bas](./hr-employees.md) - Employee communications - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/auth.md b/docs/src/chapter-06-gbdialog/templates/auth.md deleted file mode 100644 index d5e45bce..00000000 --- a/docs/src/chapter-06-gbdialog/templates/auth.md +++ /dev/null @@ -1,433 +0,0 @@ -# Authentication Template - -The authentication template demonstrates secure user verification flows including login, registration, password validation, and session management. - -## Topic: User Authentication & Security - -This template is perfect for: -- User login systems -- Account verification -- Password recovery flows -- Session management -- Two-factor authentication - -## The Code - -```basic -REM Authentication Flow with Retry Logic - -PARAM username AS string LIKE "john.doe" -DESCRIPTION "Username or email for authentication" - -PARAM password AS string LIKE "********" -DESCRIPTION "User's password (masked input)" - -SET max_attempts = 3 -SET attempts = 0 - -TALK "Welcome! Please enter your username:" -HEAR username - -LABEL auth_loop - -TALK "Enter your password:" -HEAR password AS PASSWORD ' Masked input - -' Verify credentials -user = FIND "users", "username='" + username + "'" - -IF user = NULL THEN - TALK "Username not found. Would you like to register? (yes/no)" - HEAR register_choice - IF register_choice = "yes" THEN - GOTO registration - ELSE - TALK "Goodbye!" - EXIT - END IF -END IF - -IF user.password = HASH(password) THEN - SET BOT MEMORY "authenticated_user", username - SET BOT MEMORY "session_start", NOW() - TALK "Welcome back, " + user.name + "! You are now logged in." - EXIT -ELSE - SET attempts = attempts + 1 - IF attempts >= max_attempts THEN - TALK "Too many failed attempts. Your account is temporarily locked." - SEND MAIL user.email, "Security Alert", "Multiple failed login attempts detected." - EXIT - END IF - TALK "Incorrect password. " + (max_attempts - attempts) + " attempts remaining." - GOTO auth_loop -END IF - -LABEL registration -TALK "Let's create your account. Enter your email:" -HEAR email -TALK "Create a password (min 8 characters):" -HEAR new_password AS PASSWORD - -IF LEN(new_password) < 8 THEN - TALK "Password too short. Please try again." - GOTO registration -END IF - -INSERT "users", username, email, HASH(new_password), NOW() -TALK "Account created! You can now log in." -``` - -## Sample Dialogs - -These conversations show how the authentication template works in real-world scenarios. - -### Dialog 1: Successful Login - - - -### Dialog 2: Failed Login with Retry - - - -### Dialog 3: Account Locked - - - -### Dialog 4: New User Registration - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `PARAM` | Define expected input parameters | -| `SET` | Assign values to variables | -| `TALK` | Send messages to the user | -| `HEAR` | Capture user input | -| `HEAR AS PASSWORD` | Masked password input | -| `FIND` | Query database for user | -| `IF/ELSE` | Conditional logic | -| `GOTO/LABEL` | Flow control for retry loop | -| `HASH` | Secure password hashing | -| `SET BOT MEMORY` | Store session data | -| `SEND MAIL` | Send security alerts | -| `INSERT` | Create new user record | -| `EXIT` | End the dialog | - -## How It Works - -1. **Username Input**: Collects the username first -2. **User Lookup**: Checks if user exists in database -3. **Password Verification**: Compares hashed password -4. **Retry Logic**: Allows 3 attempts before lockout -5. **Session Creation**: Stores auth state in bot memory -6. **Registration**: Offers new account creation if user not found - -## Security Features - -### Password Hashing - -```basic -' Never store plain text passwords! -hashed = HASH(password) -INSERT "users", username, email, hashed -``` - -### Rate Limiting - -```basic -IF attempts >= max_attempts THEN - SET BOT MEMORY "locked_" + username, NOW() - TALK "Account locked for 15 minutes." -END IF -``` - -### Two-Factor Authentication - -```basic -' Send OTP after password verification -otp = RANDOM(100000, 999999) -SET BOT MEMORY "otp_" + username, otp -SEND MAIL email, "Your verification code", "Code: " + otp - -TALK "Enter the 6-digit code sent to your email:" -HEAR user_otp - -IF user_otp = GET BOT MEMORY "otp_" + username THEN - TALK "Two-factor authentication successful!" -ELSE - TALK "Invalid code." -END IF -``` - -## Customization Ideas - -### Add "Forgot Password" - -```basic -TALK "Forgot your password? (yes/no)" -HEAR forgot -IF forgot = "yes" THEN - reset_token = RANDOM_STRING(32) - SET BOT MEMORY "reset_" + username, reset_token - SEND MAIL user.email, "Password Reset", "Click here: /reset/" + reset_token - TALK "Password reset link sent to your email." -END IF -``` - -### Session Timeout - -```basic -session_start = GET BOT MEMORY "session_start" -IF DATEDIFF("minute", session_start, NOW()) > 30 THEN - TALK "Session expired. Please log in again." - SET BOT MEMORY "authenticated_user", "" -END IF -``` - -### Social Login - -```basic -TALK "Login with: 1) Password 2) Google 3) GitHub" -HEAR login_method - -SWITCH login_method - CASE "2" - ' Redirect to OAuth - url = GET "auth/google/redirect" - TALK "Click to login: " + url - CASE "3" - url = GET "auth/github/redirect" - TALK "Click to login: " + url - DEFAULT - ' Standard password flow -END SWITCH -``` - -## Related Templates - -- [start.bas](./start.md) - Basic greeting flow -- [enrollment.bas](./enrollment.md) - Data collection patterns - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/backup.md b/docs/src/chapter-06-gbdialog/templates/backup.md deleted file mode 100644 index d5b9f554..00000000 --- a/docs/src/chapter-06-gbdialog/templates/backup.md +++ /dev/null @@ -1,451 +0,0 @@ -# Backup Template - -The backup template provides automated file archiving and restoration capabilities, helping you protect important data with scheduled backups and easy recovery options. - -## Topic: File Backup & Recovery - -This template is perfect for: -- Automated data protection -- Scheduled file archiving -- Disaster recovery preparation -- Compliance with data retention policies - -## The Code - -```basic -ADD TOOL "backup-to-server" -ADD TOOL "restore-file" -ADD TOOL "list-archived" -ADD TOOL "cleanup-old" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "backup" AS "Run backup now" -ADD SUGGESTION "list" AS "View archived files" -ADD SUGGESTION "restore" AS "Restore a file" -ADD SUGGESTION "status" AS "Backup status" - -SET CONTEXT "backup" AS "You are a backup management assistant. Help users archive files to server storage, restore archived files, and manage backup schedules." - -BEGIN TALK -**Backup Manager** - -I can help you with: -• Archive files to server storage -• Restore archived files -• View backup history -• Manage backup schedules - -Select an option or tell me what you need. -END TALK - -BEGIN SYSTEM PROMPT -You are a backup management assistant. - -Archive files older than specified days to server storage. -Track all backup operations in log.xlsx. -Support restore operations from archived files. -Maintain MD5 checksums for integrity verification. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the backup template works in real-world scenarios. - -### Dialog 1: Running a Backup - - - -### Dialog 2: Viewing Archived Files - - - -### Dialog 3: Restoring a File - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register backup tools for AI to use | -| `ADD SUGGESTION` | Create quick action buttons | -| `SET CONTEXT` | Define the bot's role and capabilities | -| `BEGIN TALK` | Welcome message block | -| `BEGIN SYSTEM PROMPT` | AI behavior instructions | - -## Backup Tool: backup-to-server.bas - -```basic -PARAM folder AS STRING LIKE "documents" DESCRIPTION "Folder to backup" -PARAM days AS INTEGER LIKE 30 DESCRIPTION "Archive files older than X days" - -DESCRIPTION "Archive files older than specified days to server storage" - -IF NOT folder THEN - folder = "documents" -END IF - -IF NOT days THEN - days = 30 -END IF - -' Calculate cutoff date -cutoff = DATEADD(NOW(), -days, "days") - -' Find files to archive -files = FIND folder, "modified < '" + FORMAT(cutoff, "YYYY-MM-DD") + "'" - -IF UBOUND(files) = 0 THEN - TALK "No files found older than " + days + " days." - RETURN 0 -END IF - -' Create archive name -archiveName = "backup-" + FORMAT(NOW(), "YYYY-MM-DD") + ".zip" - -' Compress files -COMPRESS files, archiveName - -' Calculate checksums -FOR EACH file IN files - checksum = MD5(file) - - WITH logEntry - timestamp = NOW() - filename = file.name - size = file.size - md5 = checksum - archive = archiveName - status = "archived" - END WITH - - SAVE "log.xlsx", logEntry -NEXT - -' Move to server storage -MOVE archiveName, "server://backups/" + archiveName - -TALK "✅ Backup completed: " + UBOUND(files) + " files archived to " + archiveName - -RETURN UBOUND(files) -``` - -## Restore Tool: restore-file.bas - -```basic -PARAM filename AS STRING LIKE "report.xlsx" DESCRIPTION "Name of file to restore" -PARAM date AS STRING LIKE "2025-01-15" DESCRIPTION "Backup date to restore from" OPTIONAL - -DESCRIPTION "Restore a file from archived backups" - -' Search for file in backup logs -IF date THEN - results = FIND "log.xlsx", "filename LIKE '%" + filename + "%' AND archive LIKE '%" + date + "%'" -ELSE - results = FIND "log.xlsx", "filename LIKE '%" + filename + "%'" -END IF - -IF UBOUND(results) = 0 THEN - TALK "No archived files found matching '" + filename + "'" - RETURN NULL -END IF - -IF UBOUND(results) > 1 AND NOT date THEN - TALK "Found " + UBOUND(results) + " versions. Please specify which date:" - FOR EACH result IN results - TALK "• " + result.archive + " (" + FORMAT(result.timestamp, "MMM DD, YYYY") + ")" - NEXT - RETURN results -END IF - -' Get the archive -archive = results[1].archive -originalChecksum = results[1].md5 - -' Download from server -DOWNLOAD "server://backups/" + archive, archive - -' Extract the specific file -EXTRACT archive, filename, "restored/" - -' Verify checksum -restoredChecksum = MD5("restored/" + filename) - -IF restoredChecksum = originalChecksum THEN - TALK "✅ File restored and verified: restored/" + filename -ELSE - TALK "⚠️ Warning: Checksum mismatch. File may be corrupted." -END IF - -' Log restoration -WITH logEntry - timestamp = NOW() - action = "restore" - filename = filename - archive = archive - verified = (restoredChecksum = originalChecksum) -END WITH - -SAVE "log.xlsx", logEntry - -RETURN "restored/" + filename -``` - -## How It Works - -1. **Tool Registration**: `ADD TOOL` makes backup functions available to the AI -2. **Quick Actions**: `ADD SUGGESTION` creates one-tap backup options -3. **Context Setting**: Defines the bot as a backup management assistant -4. **File Scanning**: Finds files matching age criteria -5. **Compression**: Creates ZIP archives with checksums -6. **Logging**: Tracks all operations in log.xlsx -7. **Restoration**: Extracts files and verifies integrity - -## Scheduling Backups - -Set up automated backups with scheduled jobs: - -```basic -PARAM jobname AS STRING DESCRIPTION "Name of the backup job" - -IF jobname = "daily backup" THEN - SET SCHEDULE "0 2 * * *" ' Run at 2 AM daily - - ' Backup documents folder - CALL backup-to-server("documents", 7) - - ' Backup reports folder - CALL backup-to-server("reports", 30) - - ' Send confirmation - SEND MAIL "admin@company.com", "Daily Backup Complete", "Backup completed at " + NOW() -END IF - -IF jobname = "weekly cleanup" THEN - SET SCHEDULE "0 3 * * 0" ' Run at 3 AM on Sundays - - ' Remove backups older than 90 days - CALL cleanup-old(90) - - SEND MAIL "admin@company.com", "Weekly Cleanup Complete", "Old backups removed" -END IF -``` - -## Customization Ideas - -### Add Email Notifications - -```basic -' After backup completes -SEND MAIL "admin@company.com", "Backup Report", - "Files archived: " + fileCount + "\n" + - "Total size: " + totalSize + " MB\n" + - "Archive: " + archiveName -``` - -### Add Backup Verification - -```basic -' Verify backup integrity -FOR EACH entry IN FIND("log.xlsx", "archive = '" + archiveName + "'") - originalFile = GET entry.filename - archivedChecksum = entry.md5 - - IF MD5(originalFile) <> archivedChecksum THEN - TALK "⚠️ Warning: " + entry.filename + " has changed since backup" - END IF -NEXT -``` - -### Add Storage Monitoring - -```basic -' Check available storage -storageUsed = FOLDER_SIZE("server://backups/") -storageLimit = 10000 ' 10 GB in MB - -IF storageUsed > storageLimit * 0.9 THEN - TALK "⚠️ Storage is 90% full. Consider cleaning old backups." - SEND MAIL "admin@company.com", "Storage Warning", "Backup storage is almost full" -END IF -``` - -## Related Templates - -- [start.bas](./start.md) - Basic greeting flow -- [analytics-dashboard.bas](./analytics-dashboard.md) - Monitor system metrics -- [broadcast.bas](./broadcast.md) - Send notifications to teams - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/bank.md b/docs/src/chapter-06-gbdialog/templates/bank.md deleted file mode 100644 index 54487f96..00000000 --- a/docs/src/chapter-06-gbdialog/templates/bank.md +++ /dev/null @@ -1,421 +0,0 @@ -# Bank Template - -The bank template provides a complete digital banking assistant for financial institutions, enabling customers to manage accounts, transfers, payments, cards, and investments through conversational AI. - -## Topic: Digital Banking Assistant - -This template is perfect for: -- Retail banking customer service -- Account management automation -- Payment and transfer processing -- Card services and support -- Investment inquiries - -## The Code - -```basic -ADD TOOL "check-balance" -ADD TOOL "transfer-money" -ADD TOOL "pay-bill" -ADD TOOL "card-services" -ADD TOOL "loan-inquiry" -ADD TOOL "investment-info" -ADD TOOL "transaction-history" -ADD TOOL "open-account" - -ADD BOT "fraud-detector" WITH TRIGGER "suspicious, fraud, unauthorized, stolen, hack" -ADD BOT "investment-advisor" WITH TRIGGER "invest, stocks, funds, portfolio, returns, CDB, LCI" -ADD BOT "loan-specialist" WITH TRIGGER "loan, financing, credit, mortgage, empréstimo" -ADD BOT "card-services" WITH TRIGGER "card, credit card, debit card, block card, limit" - -USE KB "banking-faq" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "balance" AS "Check my balance" -ADD SUGGESTION "transfer" AS "Make a transfer" -ADD SUGGESTION "pix" AS "Send PIX" -ADD SUGGESTION "bills" AS "Pay a bill" -ADD SUGGESTION "card" AS "Card services" -ADD SUGGESTION "history" AS "Transaction history" -ADD SUGGESTION "invest" AS "Investment options" -ADD SUGGESTION "loan" AS "Loan information" - -SET CONTEXT "You are a professional banking assistant for General Bank. Help customers with accounts, transfers, payments, cards, loans, and investments. Always verify identity before sensitive operations. Be helpful and secure. Never ask for full card numbers or passwords in chat." - -BEGIN TALK -**General Bank** - Digital Banking Assistant - -Welcome! I can help you with: -• Account balance and statements -• Transfers and PIX -• Bill payments -• Card services -• Investments -• Loans and financing - -Select an option below or tell me what you need. -END TALK - -BEGIN SYSTEM PROMPT -You are a secure banking assistant. - -Security rules: -- Never display full account numbers -- Mask card numbers showing only last 4 digits -- Require confirmation for transactions over $1000 -- Log all sensitive operations -- Escalate fraud concerns immediately -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the bank template works in real-world scenarios. - -### Dialog 1: Check Balance - - - -### Dialog 2: PIX Transfer - - - -### Dialog 3: Block Lost Card - - - -### Dialog 4: Fraud Detection Escalation - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register banking operation tools | -| `ADD BOT` | Register specialized bots with triggers | -| `USE KB` | Load banking FAQ knowledge base | -| `ADD SUGGESTION` | Create quick action buttons | -| `SET CONTEXT` | Define bot behavior and security rules | -| `BEGIN TALK` | Welcome message block | -| `BEGIN SYSTEM PROMPT` | Security instructions for AI | - -## Multi-Bot Architecture - -The bank template uses a multi-bot architecture for specialized handling: - -| Bot | Trigger Words | Purpose | -|-----|---------------|---------| -| `fraud-detector` | suspicious, fraud, unauthorized, stolen, hack | Handle security concerns | -| `investment-advisor` | invest, stocks, funds, portfolio, CDB, LCI | Investment guidance | -| `loan-specialist` | loan, financing, credit, mortgage | Loan inquiries | -| `card-services` | card, credit card, debit card, block, limit | Card management | - -## Security Features - -### Built-in Protections - -1. **Data Masking**: Account and card numbers are always masked -2. **Transaction Limits**: Confirmation required for large transactions -3. **Fraud Escalation**: Automatic routing to fraud team for suspicious activity -4. **Audit Logging**: All sensitive operations are logged -5. **No Sensitive Data**: Never asks for passwords or full card numbers - -### Implementing Security Checks - -```basic -' Example: Verify identity before sensitive operation -PARAM operation AS STRING - -IF operation = "transfer" AND amount > 1000 THEN - TALK "For your security, please confirm your identity." - TALK "Enter the last 4 digits of your CPF:" - HEAR verification - - IF NOT VERIFY_IDENTITY(verification) THEN - TALK "Verification failed. Please try again or call support." - RETURN - END IF -END IF -``` - -## Customization Ideas - -### Add Investment Products - -```basic -ADD TOOL "simulate-investment" -ADD TOOL "compare-products" - -' In investment flow -products = FIND "investment_products.csv", "risk_level = 'low'" -TALK "Here are our low-risk investment options:" -FOR EACH product IN products - TALK "• " + product.name + " - " + product.rate + "% p.a." -NEXT -``` - -### Add Bill Payment with Barcode - -```basic -PARAM barcode AS STRING DESCRIPTION "Bill barcode or PIX copy-paste code" - -IF LEN(barcode) = 47 THEN - ' Boleto bancário - bill = PARSE_BOLETO(barcode) - TALK "Bill Details:" - TALK "Payee: " + bill.payee - TALK "Amount: R$ " + FORMAT(bill.amount, "#,##0.00") - TALK "Due Date: " + FORMAT(bill.due_date, "DD/MM/YYYY") -ELSE IF INSTR(barcode, "pix") > 0 THEN - ' PIX QR Code - pix = PARSE_PIX(barcode) - TALK "PIX Payment: R$ " + FORMAT(pix.amount, "#,##0.00") -END IF -``` - -### Add Account Statements - -```basic -PARAM period AS STRING LIKE "last 30 days" DESCRIPTION "Statement period" - -transactions = FIND "transactions.csv", "account_id = '" + account_id + "' AND date >= '" + start_date + "'" - -TALK "📋 **Account Statement**" -TALK "Period: " + period -TALK "" - -balance = 0 -FOR EACH tx IN transactions - IF tx.type = "credit" THEN - balance = balance + tx.amount - TALK "➕ " + tx.description + ": R$ " + FORMAT(tx.amount, "#,##0.00") - ELSE - balance = balance - tx.amount - TALK "➖ " + tx.description + ": R$ " + FORMAT(tx.amount, "#,##0.00") - END IF -NEXT - -TALK "" -TALK "**Final Balance:** R$ " + FORMAT(balance, "#,##0.00") -``` - -## Related Templates - -- [store.bas](./store.md) - E-commerce with payment integration -- [privacy.bas](./privacy.md) - Data protection compliance -- [auth.bas](./auth.md) - Authentication patterns - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/broadcast.md b/docs/src/chapter-06-gbdialog/templates/broadcast.md deleted file mode 100644 index 9f6d048c..00000000 --- a/docs/src/chapter-06-gbdialog/templates/broadcast.md +++ /dev/null @@ -1,433 +0,0 @@ -# Broadcast Template - -The broadcast template enables mass messaging to contact lists, perfect for announcements, marketing campaigns, and bulk notifications through WhatsApp and other channels. - -## Topic: Mass Messaging & Announcements - -This template is perfect for: -- Company-wide announcements -- Marketing campaigns -- Customer notifications -- Event reminders -- Newsletter distribution - -## The Code - -```basic -PARAM message AS STRING LIKE "Hello {name}, how are you?" DESCRIPTION "Message to broadcast, supports {name} and {mobile} variables" -PARAM listfile AS STRING LIKE "broadcast.csv" DESCRIPTION "CSV file with contacts (name, mobile columns)" -PARAM filter AS STRING LIKE "status=active" DESCRIPTION "Filter condition for contact list" OPTIONAL - -DESCRIPTION "Send broadcast message to a list of contacts from CSV file" - -IF NOT listfile THEN - listfile = "broadcast.csv" -END IF - -IF filter THEN - list = FIND listfile, filter -ELSE - list = FIND listfile -END IF - -IF UBOUND(list) = 0 THEN - TALK "No contacts found in " + listfile - RETURN 0 -END IF - -index = 1 -sent = 0 - -DO WHILE index < UBOUND(list) - row = list[index] - - msg = REPLACE(message, "{name}", row.name) - msg = REPLACE(msg, "{mobile}", row.mobile) - - TALK TO row.mobile, msg - WAIT 5 - - WITH logEntry - timestamp = NOW() - user = USERNAME - from = FROM - mobile = row.mobile - name = row.name - status = "sent" - END WITH - - SAVE "Log.xlsx", logEntry - - sent = sent + 1 - index = index + 1 -LOOP - -TALK "Broadcast sent to " + sent + " contacts." - -RETURN sent -``` - -## Sample Dialogs - -These conversations show how the broadcast template works in real-world scenarios. - -### Dialog 1: Simple Broadcast - - - -### Dialog 2: Filtered Broadcast - - - -### Dialog 3: No Contacts Found - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `PARAM` | Define input parameters with descriptions | -| `DESCRIPTION` | Tool description for AI | -| `FIND` | Query contacts from CSV file | -| `REPLACE` | Substitute variables in message template | -| `TALK TO` | Send message to specific phone number | -| `WAIT` | Delay between messages (rate limiting) | -| `SAVE` | Log each message to spreadsheet | -| `RETURN` | Return count of sent messages | - -## How It Works - -1. **Load Contacts**: `FIND` retrieves contacts from CSV with optional filter -2. **Validate List**: Checks if contacts were found -3. **Loop Through Contacts**: Iterates through each contact -4. **Personalize Message**: `REPLACE` substitutes {name} and {mobile} -5. **Send Message**: `TALK TO` delivers to each phone number -6. **Rate Limiting**: `WAIT 5` pauses 5 seconds between messages -7. **Log Operation**: Each send is recorded in Log.xlsx -8. **Report Results**: Returns total messages sent - -## Contact List Format - -Your CSV file should have these columns: - -```csv -name,mobile,status,segment -John Smith,+5511999999999,active,regular -Maria Garcia,+5521888888888,active,vip -Carlos Santos,+5531777777777,inactive,regular -Ana Lima,+5541666666666,active,vip -``` - -| Column | Required | Description | -|--------|----------|-------------| -| `name` | Yes | Contact's display name | -| `mobile` | Yes | Phone in international format | -| `status` | No | For filtering (active/inactive) | -| `segment` | No | For targeting (vip/regular) | - -## Customization Ideas - -### Add Message Templates - -```basic -ADD TOOL "broadcast" -ADD TOOL "list-templates" -ADD TOOL "create-template" - -' Load saved templates -templates = FIND "message_templates.csv" - -TALK "Available templates:" -FOR EACH template IN templates - TALK "• " + template.name + ": " + LEFT(template.message, 50) + "..." -NEXT - -TALK "Which template would you like to use?" -HEAR templateName - -selected = FIND "message_templates.csv", "name = '" + templateName + "'" -message = selected.message -``` - -### Add Scheduling - -```basic -PARAM schedule_time AS STRING LIKE "2025-01-20 09:00" DESCRIPTION "When to send (optional)" - -IF schedule_time THEN - SET SCHEDULE schedule_time - - ' Store broadcast details for later - SET BOT MEMORY "scheduled_message", message - SET BOT MEMORY "scheduled_list", listfile - SET BOT MEMORY "scheduled_filter", filter - - TALK "📅 Broadcast scheduled for " + schedule_time - TALK "I'll send to " + UBOUND(list) + " contacts at that time." - RETURN 0 -END IF -``` - -### Add Progress Updates - -```basic -total = UBOUND(list) -checkpoints = [25, 50, 75, 100] - -DO WHILE index <= total - ' ... send message ... - - ' Check progress - percent = INT((index / total) * 100) - IF INARRAY(percent, checkpoints) THEN - TALK "📊 Progress: " + percent + "% (" + index + "/" + total + ")" - END IF - - index = index + 1 -LOOP -``` - -### Add Opt-Out Handling - -```basic -' Check if contact has opted out -optouts = FIND "optouts.csv" - -DO WHILE index <= UBOUND(list) - row = list[index] - - ' Skip opted-out contacts - IF FIND("optouts.csv", "mobile = '" + row.mobile + "'") THEN - WITH logEntry - mobile = row.mobile - status = "skipped-optout" - END WITH - SAVE "Log.xlsx", logEntry - index = index + 1 - CONTINUE - END IF - - ' ... send message ... -LOOP -``` - -### Add Media Support - -```basic -PARAM image AS STRING LIKE "promo.jpg" DESCRIPTION "Image to include (optional)" - -IF image THEN - msg = msg + "\n[Image: " + image + "]" - TALK TO row.mobile, msg, image -ELSE - TALK TO row.mobile, msg -END IF -``` - -## Best Practices - -### Message Content - -1. **Personalize**: Always use `{name}` for a personal touch -2. **Be Concise**: Keep messages short and clear -3. **Clear CTA**: Include a clear call-to-action -4. **Identify Yourself**: Make sure recipients know who's messaging - -### Compliance - -1. **Consent Required**: Only message contacts who opted in -2. **Easy Opt-Out**: Include unsubscribe instructions -3. **Respect Hours**: Don't send late at night -4. **Honor Limits**: WhatsApp has daily messaging limits - -### Performance - -1. **Rate Limiting**: Keep 5+ second delays to avoid blocks -2. **Batch Processing**: For large lists, consider batching -3. **Error Handling**: Log and handle failed sends -4. **Monitor Results**: Check logs for delivery issues - -## Logging Structure - -The Log.xlsx file tracks all broadcast activity: - -| Column | Description | -|--------|-------------| -| timestamp | When message was sent | -| user | Who initiated the broadcast | -| from | Sender identifier | -| mobile | Recipient phone number | -| name | Recipient name | -| status | sent/failed/skipped | -| error | Error message if failed | - -## Related Templates - -- [announcements.bas](./announcements.md) - Company announcements system -- [whatsapp.bas](./whatsapp.md) - WhatsApp-specific features -- [store.bas](./store.md) - E-commerce with customer notifications - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/default.md b/docs/src/chapter-06-gbdialog/templates/default.md deleted file mode 100644 index e33158de..00000000 --- a/docs/src/chapter-06-gbdialog/templates/default.md +++ /dev/null @@ -1,402 +0,0 @@ -# Default Template - -The default template is the starter bot that comes with General Bots, providing essential utility tools like weather forecasts, email sending, SMS messaging, calculations, and translations. - -## Topic: Starter Bot with Essential Tools - -This template is perfect for: -- Quick start with General Bots -- Basic utility functions -- Learning BASIC syntax -- Foundation for custom bots - -## Available Tools - -The default template includes these ready-to-use tools: - -| Tool | File | Description | -|------|------|-------------| -| Weather | `weather.bas` | Get weather forecasts for any city | -| Send Email | `send-email.bas` | Send emails to any address | -| Send SMS | `send-sms.bas` | Send text messages to mobile phones | -| Calculate | `calculate.bas` | Perform mathematical calculations | -| Translate | `translate.bas` | Translate text between languages | - -## The Code: weather.bas - -```basic -PARAM location AS STRING LIKE "New York" DESCRIPTION "City or location to get weather forecast" - -DESCRIPTION "Get current weather forecast for any city or location" - -lat = 40.7128 -lon = -74.0060 - -location_lower = LCASE(location) - -IF INSTR(location_lower, "new york") > 0 THEN - lat = 40.7128 - lon = -74.0060 -ELSE IF INSTR(location_lower, "london") > 0 THEN - lat = 51.5074 - lon = -0.1278 -ELSE IF INSTR(location_lower, "tokyo") > 0 THEN - lat = 35.6762 - lon = 139.6503 -ELSE IF INSTR(location_lower, "sao paulo") > 0 THEN - lat = -23.5505 - lon = -46.6333 -END IF - -weather_url = "https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "¤t_weather=true" - -weather_data = GET weather_url - -IF weather_data.current_weather THEN - current = weather_data.current_weather - - code = current.weathercode - condition = "Clear" - icon = "☀️" - - IF code = 0 THEN - condition = "Clear sky" - icon = "☀️" - ELSE IF code >= 1 AND code <= 3 THEN - condition = "Partly cloudy" - icon = "⛅" - ELSE IF code >= 51 AND code <= 67 THEN - condition = "Rainy" - icon = "🌧️" - ELSE IF code >= 95 AND code <= 99 THEN - condition = "Thunderstorm" - icon = "⛈️" - END IF - - TALK icon + " Weather for " + location + ":" - TALK "Temperature: " + current.temperature + "°C" - TALK "Condition: " + condition - TALK "Wind: " + current.windspeed + " km/h" -ELSE - TALK "Could not fetch weather for: " + location -END IF -``` - -## Sample Dialogs - -These conversations show how the default template works in real-world scenarios. - -### Dialog 1: Weather Forecast - - - -### Dialog 2: Send Email - - - -### Dialog 3: Translation - - - -### Dialog 4: Calculation - - - -## Template Structure - -``` -default.gbai/ -├── default.gbdialog/ -│ ├── calculate.bas # Math calculations -│ ├── send-email.bas # Email sending -│ ├── send-sms.bas # SMS messaging -│ ├── translate.bas # Text translation -│ └── weather.bas # Weather forecasts -└── default.gbot/ - └── config.csv # Bot configuration -``` - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `PARAM` | Define tool parameters | -| `DESCRIPTION` | Tool description for AI | -| `GET` | HTTP GET request | -| `TALK` | Send message to user | -| `SEND MAIL` | Send email | -| `SEND SMS` | Send text message | -| `INSTR` | Find substring position | -| `LCASE` | Convert to lowercase | - -## Supported Cities (Weather) - -The weather tool includes coordinates for these cities: -- New York, Los Angeles, Chicago (USA) -- London, Paris, Berlin, Madrid (Europe) -- Tokyo, Beijing, Singapore, Mumbai, Dubai (Asia) -- Sydney (Australia) -- São Paulo, Rio de Janeiro (Brazil) -- Toronto (Canada) - -## Customization Ideas - -### Add More Cities - -```basic -ELSE IF INSTR(location_lower, "amsterdam") > 0 THEN - lat = 52.3676 - lon = 4.9041 -ELSE IF INSTR(location_lower, "moscow") > 0 THEN - lat = 55.7558 - lon = 37.6173 -END IF -``` - -### Add Extended Forecast - -```basic -' Get 7-day forecast -weather_url = weather_url + "&daily=temperature_2m_max,temperature_2m_min&forecast_days=7" - -weather_data = GET weather_url - -TALK "📅 7-Day Forecast for " + location + ":" -FOR i = 1 TO 7 - TALK "Day " + i + ": " + weather_data.daily.temperature_2m_max[i] + "°C / " + weather_data.daily.temperature_2m_min[i] + "°C" -NEXT -``` - -### Add Email Templates - -```basic -PARAM template AS STRING LIKE "meeting-reminder" DESCRIPTION "Email template to use" - -IF template = "meeting-reminder" THEN - subject = "Meeting Reminder" - body = "Hi {name},\n\nThis is a reminder about our upcoming meeting.\n\nBest regards" - body = REPLACE(body, "{name}", recipient_name) -END IF - -SEND MAIL recipient, subject, body -``` - -### Add SMS Confirmation - -```basic -PARAM phone AS PHONE DESCRIPTION "Phone number with country code" -PARAM message AS STRING DESCRIPTION "Message to send" - -DESCRIPTION "Send SMS with delivery confirmation" - -SEND SMS phone, message - -TALK "📱 SMS sent to " + phone -TALK "Message: " + LEFT(message, 50) + "..." - -' Log the message -WITH smsLog - timestamp = NOW() - recipient = phone - content = message - status = "sent" -END WITH - -SAVE "sms_log.csv", smsLog -``` - -## Using as a Base Template - -The default template is designed to be extended. Here's how to build on it: - -### 1. Copy the Template - -```bash -cp -r templates/default.gbai packages/my-bot.gbai -``` - -### 2. Add Your Tools - -Create new `.bas` files in the `.gbdialog` folder for your custom functionality. - -### 3. Add a Start Script - -Create `start.bas` to configure your bot: - -```basic -ADD TOOL "weather" -ADD TOOL "send-email" -ADD TOOL "send-sms" -ADD TOOL "calculate" -ADD TOOL "translate" - -' Add your custom tools -ADD TOOL "my-custom-tool" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "weather" AS "Check weather" -ADD SUGGESTION "email" AS "Send email" -ADD SUGGESTION "translate" AS "Translate text" - -BEGIN TALK -Welcome! I can help you with weather, emails, translations, and more. -END TALK -``` - -## Related Templates - -- [start.bas](./start.md) - Basic greeting flow -- [broadcast.bas](./broadcast.md) - Mass messaging -- [store.bas](./store.md) - E-commerce features - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/edu.md b/docs/src/chapter-06-gbdialog/templates/edu.md deleted file mode 100644 index df215d02..00000000 --- a/docs/src/chapter-06-gbdialog/templates/edu.md +++ /dev/null @@ -1,555 +0,0 @@ -# Education Template - -The education template provides a comprehensive educational institution assistant that helps students and staff with enrollment, course management, schedules, grades, tuition information, and academic support. - -## Topic: Educational Institution Assistant - -This template is perfect for: -- Universities and colleges -- Online learning platforms -- Training centers -- K-12 schools -- Corporate learning management - -## The Code - -```basic -ADD TOOL "enrollment" -ADD TOOL "course-info" -ADD TOOL "schedule" -ADD TOOL "grades" -ADD TOOL "tuition" -ADD TOOL "support" - -USE KB "edu.gbkb" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "enroll" AS "Enroll in a course" -ADD SUGGESTION "courses" AS "View available courses" -ADD SUGGESTION "schedule" AS "My class schedule" -ADD SUGGESTION "grades" AS "Check my grades" -ADD SUGGESTION "tuition" AS "Payment information" -ADD SUGGESTION "help" AS "Academic support" - -SET CONTEXT "education" AS "You are an educational institution assistant helping with enrollment, courses, schedules, grades, and academic support. Be helpful and guide students through processes clearly." - -BEGIN TALK -**Education Assistant** - -Welcome! I can help you with: -• Course enrollment and registration -• Available courses and programs -• Class schedules and calendars -• Grades and transcripts -• Tuition and payment info -• Academic support and advising - -Select an option or ask me anything. -END TALK - -BEGIN SYSTEM PROMPT -You are an AI assistant for an educational institution. - -Be friendly and professional. -Provide clear, accurate assistance. -Reduce administrative workload by handling common inquiries. -Help with enrollment and registration. -Provide course information and prerequisites. -Answer admissions questions. -Guide through registration process. -Explain academic policies. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the education template works in real-world scenarios. - -### Dialog 1: Course Enrollment - - - -### Dialog 2: Check Grades - - - -### Dialog 3: Class Schedule - - - -### Dialog 4: Tuition Payment - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register enrollment and academic tools | -| `USE KB` | Load educational knowledge base | -| `ADD SUGGESTION` | Create quick action buttons | -| `SET CONTEXT` | Define educational assistant behavior | -| `BEGIN TALK` | Welcome message block | -| `BEGIN SYSTEM PROMPT` | AI behavior instructions | - -## Template Structure - -``` -edu.gbai/ -├── edu.gbdialog/ -│ ├── start.bas # Main entry point -│ └── enrollment.bas # Enrollment workflow -├── edu.gbdata/ -│ └── (data tables) # Student/course data -├── edu.gbot/ -│ └── config.csv # Bot configuration -└── edu.gbkb/ - └── academic-policies.md # Knowledge base -``` - -## Enrollment Tool: enrollment.bas - -```basic -PARAM student_id AS STRING DESCRIPTION "Student ID number" -PARAM course_code AS STRING LIKE "CS101" DESCRIPTION "Course code to enroll in" - -DESCRIPTION "Enroll a student in a course after checking prerequisites and availability" - -' Verify student exists -student = FIND "students.csv", "id = '" + student_id + "'" -IF NOT student THEN - TALK "Student ID not found. Please verify your ID." - RETURN NULL -END IF - -' Get course information -course = FIND "courses.csv", "code = '" + course_code + "'" -IF NOT course THEN - TALK "Course " + course_code + " not found." - RETURN NULL -END IF - -' Check if already enrolled -existing = FIND "enrollments.csv", "student_id = '" + student_id + "' AND course_code = '" + course_code + "'" -IF existing THEN - TALK "You're already enrolled in " + course_code + "." - RETURN NULL -END IF - -' Check prerequisites -IF course.prerequisite <> "" THEN - prereq = FIND "enrollments.csv", "student_id = '" + student_id + "' AND course_code = '" + course.prerequisite + "' AND grade >= 'C'" - IF NOT prereq THEN - TALK "You need to complete " + course.prerequisite + " before enrolling in " + course_code + "." - RETURN NULL - END IF -END IF - -' Check availability -enrolled_count = COUNT("enrollments.csv", "course_code = '" + course_code + "' AND term = 'Fall2024'") -IF enrolled_count >= course.capacity THEN - TALK "This course is full. Would you like to join the waitlist?" - HEAR waitlist_choice - IF LOWER(waitlist_choice) = "yes" THEN - WITH waitlist_entry - student_id = student_id - course_code = course_code - timestamp = NOW() - END WITH - SAVE "waitlist.csv", waitlist_entry - TALK "You've been added to the waitlist. We'll notify you if a spot opens." - END IF - RETURN NULL -END IF - -' Create enrollment -WITH enrollment - id = GUID() - student_id = student_id - course_code = course_code - term = "Fall2024" - enrollment_date = NOW() - status = "enrolled" -END WITH - -SAVE "enrollments.csv", enrollment - -' Send confirmation email -SEND MAIL student.email, "Enrollment Confirmed: " + course_code, - "You have been enrolled in " + course.name + ".\n" + - "Schedule: " + course.schedule + "\n" + - "Room: " + course.room + "\n" + - "Instructor: " + course.instructor - -TALK "✅ You're enrolled in " + course.name + "!" -TALK "📅 Schedule: " + course.schedule -TALK "🏫 Room: " + course.room - -RETURN enrollment.id -``` - -## Grades Tool: grades.bas - -```basic -PARAM student_id AS STRING DESCRIPTION "Student ID number" -PARAM term AS STRING LIKE "Fall2024" DESCRIPTION "Academic term" OPTIONAL - -DESCRIPTION "Retrieve student grades for current or specified term" - -IF NOT term THEN - term = "Fall2024" ' Current term -END IF - -' Get student info -student = FIND "students.csv", "id = '" + student_id + "'" -IF NOT student THEN - TALK "Student not found." - RETURN NULL -END IF - -' Get enrollments with grades -enrollments = FIND "enrollments.csv", "student_id = '" + student_id + "' AND term = '" + term + "'" - -IF UBOUND(enrollments) = 0 THEN - TALK "No courses found for " + term + "." - RETURN NULL -END IF - -TALK "📊 **Grades for " + student.name + " - " + term + "**" -TALK "" - -total_points = 0 -total_credits = 0 - -FOR EACH enrollment IN enrollments - course = FIND "courses.csv", "code = '" + enrollment.course_code + "'" - - grade_display = enrollment.grade - IF grade_display = "" THEN - grade_display = "In Progress" - END IF - - TALK "• " + enrollment.course_code + " - " + course.name + ": **" + grade_display + "**" - - IF enrollment.grade <> "" THEN - grade_points = GRADE_TO_POINTS(enrollment.grade) - total_points = total_points + (grade_points * course.credits) - total_credits = total_credits + course.credits - END IF -NEXT - -IF total_credits > 0 THEN - gpa = total_points / total_credits - TALK "" - TALK "**Term GPA:** " + FORMAT(gpa, "#.00") - - IF gpa >= 3.5 THEN - TALK "🌟 Dean's List!" - END IF -END IF - -RETURN enrollments -``` - -## Customization Ideas - -### Add Course Recommendations - -```basic -ADD TOOL "recommend-courses" - -' Based on major and completed courses -completed = FIND "enrollments.csv", "student_id = '" + student_id + "' AND grade >= 'C'" -major = student.major - -' Find next required courses -requirements = FIND "degree_requirements.csv", "major = '" + major + "'" - -recommended = [] -FOR EACH req IN requirements - already_done = FILTER(completed, "course_code = '" + req.course_code + "'") - IF UBOUND(already_done) = 0 THEN - ' Check if prerequisites met - IF req.prerequisite = "" OR HAS_COMPLETED(student_id, req.prerequisite) THEN - PUSH recommended, req - END IF - END IF -NEXT - -TALK "Based on your progress, I recommend these courses for next term:" -FOR EACH course IN FIRST(recommended, 5) - TALK "• " + course.course_code + " - " + course.name -NEXT -``` - -### Add Academic Calendar Integration - -```basic -ADD TOOL "important-dates" - -dates = FIND "academic_calendar.csv", "date >= '" + NOW() + "' AND date <= '" + DATEADD(NOW(), 30, 'days') + "'" - -TALK "📅 **Upcoming Important Dates:**" -FOR EACH date IN dates - TALK "• " + FORMAT(date.date, "MMM DD") + ": " + date.event -NEXT -``` - -### Add Advisor Scheduling - -```basic -ADD TOOL "book-advisor" - -PARAM preferred_date AS DATE DESCRIPTION "Preferred date for appointment" - -advisor = FIND "advisors.csv", "department = '" + student.major + "'" -available = FIND "advisor_slots.csv", "advisor_id = '" + advisor.id + "' AND date = '" + preferred_date + "' AND booked = false" - -IF UBOUND(available) > 0 THEN - TALK "Available times on " + FORMAT(preferred_date, "MMM DD") + ":" - FOR EACH slot IN available - ADD SUGGESTION slot.time AS slot.time - NEXT - HEAR selected_time - - ' Book the appointment - UPDATE "advisor_slots" SET booked = true WHERE id = slot.id - - TALK "✅ Appointment booked with " + advisor.name + " on " + FORMAT(preferred_date, "MMM DD") + " at " + selected_time - SEND MAIL student.email, "Advisor Appointment Confirmed", "Your meeting with " + advisor.name + " is scheduled." -END IF -``` - -### Add Document Requests - -```basic -ADD TOOL "request-transcript" - -PARAM delivery_method AS STRING LIKE "email" DESCRIPTION "Delivery: email, mail, or pickup" - -' Check for holds -holds = FIND "student_holds.csv", "student_id = '" + student_id + "' AND resolved = false" -IF UBOUND(holds) > 0 THEN - TALK "⚠️ There's a hold on your account. Please resolve it before requesting transcripts." - TALK "Hold reason: " + holds[1].reason - RETURN NULL -END IF - -' Create transcript request -WITH request - id = GUID() - student_id = student_id - type = "official_transcript" - delivery = delivery_method - status = "processing" - request_date = NOW() - fee = 10.00 -END WITH - -SAVE "document_requests.csv", request - -TALK "✅ Transcript request submitted!" -TALK "📋 Request #: " + request.id -TALK "💰 Fee: $10.00 (added to your account)" -TALK "📬 Delivery: " + delivery_method -TALK "⏱️ Processing time: 3-5 business days" -``` - -## Related Templates - -- [start.bas](./start.md) - Basic greeting patterns -- [enrollment.bas](./enrollment.md) - Detailed enrollment workflow -- [auth.bas](./auth.md) - Student authentication - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/employees.md b/docs/src/chapter-06-gbdialog/templates/employees.md deleted file mode 100644 index 0dd43359..00000000 --- a/docs/src/chapter-06-gbdialog/templates/employees.md +++ /dev/null @@ -1,695 +0,0 @@ -# HR Employees Template - -The HR Employees template provides a comprehensive employee management system that helps HR teams manage employee records, organizational structure, and personnel information through a conversational interface. - -## Topic: Employee Management & HR Directory - -This template is perfect for: -- HR departments -- People operations teams -- Employee self-service portals -- Organizational management -- Employee directory services - -## The Code - -```basic -ADD TOOL "add-employee" -ADD TOOL "update-employee" -ADD TOOL "search-employee" -ADD TOOL "employee-directory" -ADD TOOL "org-chart" -ADD TOOL "emergency-contacts" - -USE KB "employees.gbkb" - -SET CONTEXT "employee management" AS "You are an HR assistant helping manage employee information. Help with adding new employees, updating records, searching the directory, viewing org charts, and managing emergency contacts. Maintain confidentiality of employee data." - -CLEAR SUGGESTIONS - -ADD SUGGESTION "directory" AS "Employee directory" -ADD SUGGESTION "add" AS "Add new employee" -ADD SUGGESTION "search" AS "Search employee" -ADD SUGGESTION "org" AS "Organization chart" -ADD SUGGESTION "emergency" AS "Emergency contacts" - -BEGIN TALK -**Employee Management System** - -I can help you with: -• View employee directory -• Add new employees -• Search for employees -• View organization chart -• Manage emergency contacts -• Generate employee reports - -Select an option or tell me what you need. -END TALK - -BEGIN SYSTEM PROMPT -You are an HR assistant for the Employee Management System. - -Confirm sensitive operations before executing. -Never expose salaries or personal IDs without authorization. -Use professional and helpful language. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the HR Employees template works in real-world scenarios. - -### Dialog 1: Search Employee - - - -### Dialog 2: Add New Employee - - - -### Dialog 3: View Organization Chart - - - -### Dialog 4: Emergency Contacts - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register employee management tools | -| `USE KB` | Load HR knowledge base | -| `SET CONTEXT` | Define HR assistant behavior | -| `ADD SUGGESTION` | Create quick action buttons | -| `BEGIN TALK` | Welcome message block | -| `BEGIN SYSTEM PROMPT` | Confidentiality and behavior rules | - -## Template Structure - -``` -employees.gbai/ -├── employees.gbdialog/ -│ ├── start.bas # Main entry point -│ ├── add-employee.bas # New employee onboarding -│ ├── update-employee.bas # Update employee records -│ ├── search-employee.bas # Employee search -│ ├── employee-directory.bas # Full directory view -│ ├── org-chart.bas # Organization structure -│ └── emergency-contacts.bas # Emergency contact access -├── employees.gbdata/ -│ └── employees.csv # Employee database -├── employees.gbdrive/ -│ └── templates/ # Document templates -├── employees.gbkb/ -│ ├── hr-policies.md # HR policies -│ └── org-structure.md # Organization info -└── employees.gbot/ - └── config.csv # Bot configuration -``` - -## Search Employee Tool: search-employee.bas - -```basic -PARAM query AS STRING LIKE "John" DESCRIPTION "Name, department, or title to search for" -PARAM department AS STRING LIKE "Engineering" DESCRIPTION "Filter by department" OPTIONAL - -DESCRIPTION "Search for employees by name, department, or title" - -' Build search filter -filter = "name LIKE '%" + query + "%' OR title LIKE '%" + query + "%'" - -IF department THEN - filter = "(" + filter + ") AND department = '" + department + "'" -END IF - -' Execute search -results = FIND "employees.csv", filter - -IF UBOUND(results) = 0 THEN - TALK "No employees found matching '" + query + "'" - RETURN NULL -END IF - -TALK "🔍 Found " + UBOUND(results) + " employee(s):" -TALK "" - -FOR EACH emp IN results - TALK "**" + emp.name + "**" - TALK "📧 " + emp.email - TALK "📞 Ext. " + emp.extension - TALK "💼 " + emp.title - TALK "🏢 " + emp.department - TALK "" -NEXT - -RETURN results -``` - -## Add Employee Tool: add-employee.bas - -```basic -PARAM name AS STRING LIKE "John Smith" DESCRIPTION "Employee full name" -PARAM title AS STRING LIKE "Software Engineer" DESCRIPTION "Job title" -PARAM department AS STRING LIKE "Engineering" DESCRIPTION "Department name" -PARAM manager AS STRING LIKE "Jane Doe" DESCRIPTION "Manager's name" -PARAM start_date AS DATE LIKE "2025-02-01" DESCRIPTION "Start date" - -DESCRIPTION "Add a new employee to the system" - -' Generate employee ID -employeeId = "EMP-" + FORMAT(NOW(), "YYYY") + "-" + FORMAT(RANDOM(1000, 9999)) - -' Generate email -emailName = LOWER(REPLACE(name, " ", ".")) -email = emailName + "@company.com" - -' Assign extension -extension = FORMAT(RANDOM(4000, 4999)) - -' Find manager ID -managerRecord = FIND "employees.csv", "name = '" + manager + "'" -IF NOT managerRecord THEN - TALK "⚠️ Manager '" + manager + "' not found. Please verify the name." - RETURN NULL -END IF - -' Create employee record -WITH employee - id = employeeId - name = name - email = email - extension = extension - title = title - department = department - manager_id = managerRecord.id - manager_name = manager - start_date = start_date - status = "active" - created_at = NOW() -END WITH - -' Save to database -SAVE "employees.csv", employee - -' Send welcome email -SEND MAIL email, "Welcome to the Company!", - "Dear " + name + ",\n\n" + - "Welcome to the team! Your employee ID is " + employeeId + ".\n" + - "Your manager is " + manager + ".\n" + - "Start date: " + FORMAT(start_date, "MMMM DD, YYYY") + "\n\n" + - "HR will contact you with onboarding details.\n\n" + - "Best regards,\nHR Team" - -' Create IT ticket for equipment -CREATE_TASK "New Employee Setup - " + name, - "Please prepare workstation for new employee:\n" + - "Name: " + name + "\n" + - "Department: " + department + "\n" + - "Start Date: " + FORMAT(start_date, "MMM DD, YYYY"), - "it@company.com" - -' Notify manager -SEND MAIL managerRecord.email, "New Team Member: " + name, - "A new team member has been added:\n\n" + - "Name: " + name + "\n" + - "Title: " + title + "\n" + - "Start Date: " + FORMAT(start_date, "MMM DD, YYYY") + "\n\n" + - "Please prepare for their onboarding." - -TALK "✅ Employee **" + name + "** added successfully!" -TALK "🆔 ID: " + employeeId -TALK "📧 Email: " + email -TALK "📞 Extension: " + extension - -RETURN employee -``` - -## Org Chart Tool: org-chart.bas - -```basic -PARAM department AS STRING LIKE "Engineering" DESCRIPTION "Department to show org chart for" -PARAM manager AS STRING DESCRIPTION "Show org chart under specific manager" OPTIONAL - -DESCRIPTION "Display organization chart for a department or team" - -IF manager THEN - ' Get org chart under specific manager - managerRecord = FIND "employees.csv", "name = '" + manager + "'" - IF NOT managerRecord THEN - TALK "Manager not found." - RETURN NULL - END IF - - reports = FIND "employees.csv", "manager_id = '" + managerRecord.id + "'" - - TALK "👔 **" + manager + "** - " + managerRecord.title - FOR EACH emp IN reports - subReports = COUNT("employees.csv", "manager_id = '" + emp.id + "'") - IF subReports > 0 THEN - TALK "├── 👤 " + emp.name + " (" + emp.title + " - " + subReports + " reports)" - ELSE - TALK "├── 👤 " + emp.name + " (" + emp.title + ")" - END IF - NEXT -ELSE - ' Get department org chart - deptHead = FIND "employees.csv", "department = '" + department + "' AND title LIKE '%Director%' OR title LIKE '%VP%'" - - IF NOT deptHead THEN - deptHead = FIND "employees.csv", "department = '" + department + "' AND title LIKE '%Manager%'" - END IF - - TALK "🏢 **" + department + " Organization**" - TALK "" - - FOR EACH head IN deptHead - TALK "👔 **" + head.title + "** - " + head.name - - reports = FIND "employees.csv", "manager_id = '" + head.id + "'" - FOR EACH emp IN reports - subCount = COUNT("employees.csv", "manager_id = '" + emp.id + "'") - IF subCount > 0 THEN - TALK "├── 👤 " + emp.name + " (" + subCount + " reports)" - ELSE - TALK "├── 👤 " + emp.name - END IF - NEXT - TALK "" - NEXT -END IF - -totalCount = COUNT("employees.csv", "department = '" + department + "'") -TALK "**Total:** " + totalCount + " employees in " + department - -RETURN department -``` - -## Customization Ideas - -### Add Employee Self-Service - -```basic -' Allow employees to update their own info -IF user_id = employee.id THEN - TALK "What would you like to update?" - ADD SUGGESTION "phone" AS "Phone number" - ADD SUGGESTION "address" AS "Address" - ADD SUGGESTION "emergency" AS "Emergency contacts" - ADD SUGGESTION "photo" AS "Profile photo" - - HEAR updateChoice - - ' Only allow non-sensitive updates - IF updateChoice = "phone" THEN - TALK "Enter your new phone number:" - HEAR newPhone - UPDATE "employees.csv" SET phone = newPhone WHERE id = user_id - TALK "✅ Phone number updated!" - END IF -END IF -``` - -### Add Birthday Reminders - -```basic -' Scheduled job for birthday notifications -SET SCHEDULE "0 9 * * *" ' Run daily at 9 AM - -today = FORMAT(NOW(), "MM-DD") -birthdays = FIND "employees.csv", "FORMAT(birth_date, 'MM-DD') = '" + today + "'" - -FOR EACH emp IN birthdays - ' Notify their team - manager = FIND "employees.csv", "id = '" + emp.manager_id + "'" - SEND MAIL manager.email, "🎂 Team Birthday Today!", - emp.name + " has a birthday today! Don't forget to wish them well." - - ' Send birthday message - SEND MAIL emp.email, "🎂 Happy Birthday!", - "Dear " + emp.name + ",\n\nHappy Birthday from all of us!" -NEXT -``` - -### Add Anniversary Tracking - -```basic -' Check for work anniversaries -today = FORMAT(NOW(), "MM-DD") -anniversaries = FIND "employees.csv", "FORMAT(start_date, 'MM-DD') = '" + today + "'" - -FOR EACH emp IN anniversaries - years = YEAR(NOW()) - YEAR(emp.start_date) - IF years > 0 THEN - SEND MAIL emp.email, "🎉 Happy Work Anniversary!", - "Congratulations on " + years + " years with us!" - - ' Milestone recognition - IF years = 5 OR years = 10 OR years = 15 OR years = 20 THEN - CREATE_TASK "Milestone Recognition - " + emp.name, - emp.name + " has completed " + years + " years. Please arrange recognition.", - "hr@company.com" - END IF - END IF -NEXT -``` - -### Add Department Reports - -```basic -ADD TOOL "department-report" - -PARAM department AS STRING DESCRIPTION "Department to generate report for" - -DESCRIPTION "Generate a department headcount and demographics report" - -employees = FIND "employees.csv", "department = '" + department + "'" - -totalCount = UBOUND(employees) -managerCount = 0 -avgTenure = 0 - -FOR EACH emp IN employees - IF INSTR(emp.title, "Manager") > 0 OR INSTR(emp.title, "Director") > 0 THEN - managerCount = managerCount + 1 - END IF - avgTenure = avgTenure + DATEDIFF(NOW(), emp.start_date, "years") -NEXT - -avgTenure = avgTenure / totalCount - -TALK "📊 **" + department + " Department Report**" -TALK "" -TALK "👥 Total Employees: " + totalCount -TALK "👔 Managers: " + managerCount -TALK "📅 Avg. Tenure: " + FORMAT(avgTenure, "#.#") + " years" -TALK "" -TALK "**By Level:**" -' ... additional breakdown -``` - -## Data Security - -The employee management system includes several security features: - -1. **Access Control**: Sensitive data requires authorization -2. **Audit Logging**: All access to confidential info is logged -3. **Data Masking**: Personal IDs and salaries are not exposed -4. **Emergency Override**: Emergency contacts accessible with justification - -## Related Templates - -- [helpdesk.bas](./helpdesk.md) - IT ticket integration -- [edu.bas](./edu.md) - Training and development -- [privacy.bas](./privacy.md) - Data protection compliance - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/enrollment.md b/docs/src/chapter-06-gbdialog/templates/enrollment.md deleted file mode 100644 index ceafc8ee..00000000 --- a/docs/src/chapter-06-gbdialog/templates/enrollment.md +++ /dev/null @@ -1,400 +0,0 @@ -# Enrollment Template - -The enrollment template demonstrates how to build a complete data collection workflow that gathers user information step-by-step, validates inputs, confirms details, and saves the data. - -## Topic: User Registration & Data Collection - -This template is perfect for: -- Customer onboarding flows -- Event registrations -- Lead capture forms -- Survey collection -- Application submissions - -## The Code - -```basic -REM Enrollment Tool Example - -PARAM name AS string LIKE "Abreu Silva" -DESCRIPTION "Required full name of the individual." - -PARAM birthday AS date LIKE "23/09/2001" -DESCRIPTION "Required birth date of the individual in DD/MM/YYYY format." - -PARAM email AS string LIKE "abreu.silva@example.com" -DESCRIPTION "Required email address for contact purposes." - -PARAM personalid AS integer LIKE "12345678900" -DESCRIPTION "Required Personal ID number of the individual (only numbers)." - -PARAM address AS string LIKE "Rua das Flores, 123 - SP" -DESCRIPTION "Required full address of the individual." - -DESCRIPTION "This is the enrollment process, called when the user wants to enrol." - -REM Start enrollment -TALK "Welcome to the enrollment process! Let's get you registered." - -TALK "First, what is your full name?" -HEAR name - -TALK "Thank you. What is your birth date? (DD/MM/YYYY)" -HEAR birthday - -TALK "What is your email address?" -HEAR email - -TALK "Please provide your Personal ID number (numbers only):" -HEAR personalid - -TALK "Finally, what is your full address?" -HEAR address - -REM Validate and confirm -TALK "Please confirm your details:" -TALK "Name: " + name -TALK "Birth Date: " + birthday -TALK "Email: " + email -TALK "Personal ID: " + personalid -TALK "Address: " + address - -TALK "Are these details correct? (yes/no)" -HEAR confirmation - -IF confirmation = "yes" THEN - SAVE "enrollments.csv", name, birthday, email, personalid, address - TALK "Thank you! Your enrollment has been successfully submitted." -ELSE - TALK "Let's start over with the correct information." -END IF -``` - -## Sample Dialogs - -These conversations show how the enrollment template works in real-world scenarios. - -### Dialog 1: Successful Enrollment - - - -### Dialog 2: User Corrects Information - - - -### Dialog 3: LLM-Assisted Natural Input - -When using the LLM, users can provide information naturally: - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `PARAM` | Define expected input parameters with types and examples | -| `DESCRIPTION` | Provide context for LLM understanding | -| `TALK` | Send messages to the user | -| `HEAR` | Wait for and capture user input | -| `IF/ELSE` | Conditional logic for confirmation | -| `SAVE` | Persist data to CSV file | - -## How It Works - -1. **Parameter Definition**: The `PARAM` declarations tell the LLM what information to collect -2. **Step-by-Step Collection**: Each `HEAR` captures one piece of data -3. **Confirmation Loop**: User reviews all data before submission -4. **Data Persistence**: `SAVE` stores the validated data - -## Customization Ideas - -### Add Validation - -```basic -HEAR email -IF NOT INSTR(email, "@") THEN - TALK "Please enter a valid email address" - HEAR email -END IF -``` - -### Add to Database Instead of CSV - -```basic -INSERT "users", name, birthday, email, personalid, address -``` - -### Send Confirmation Email - -```basic -SEND MAIL email, "Welcome!", "Your registration is complete, " + name -``` - -## Related Templates - -- [start.bas](./start.md) - Basic greeting flow -- [auth.bas](./auth.md) - Authentication patterns - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/erp.md b/docs/src/chapter-06-gbdialog/templates/erp.md deleted file mode 100644 index 6c44a4e9..00000000 --- a/docs/src/chapter-06-gbdialog/templates/erp.md +++ /dev/null @@ -1,521 +0,0 @@ -# ERP Template - -The ERP (Enterprise Resource Planning) template provides comprehensive inventory management, purchasing, and warehouse operations through a conversational AI interface. - -## Topic: Enterprise Resource Planning & Inventory - -This template is perfect for: -- Warehouse management -- Inventory tracking -- Purchase order processing -- Stock transfers -- Cycle counting and audits - -## The Code - -```basic -ADD TOOL "inventory-management" -ADD TOOL "purchasing" -ADD TOOL "erp-jobs" - -SET CONTEXT "erp" AS "You are an ERP assistant helping with inventory management, purchasing, and warehouse operations. Help users receive inventory, ship orders, check stock levels, transfer between warehouses, and conduct cycle counts." - -CLEAR SUGGESTIONS - -ADD SUGGESTION "receive" AS "Receive inventory" -ADD SUGGESTION "ship" AS "Ship order" -ADD SUGGESTION "stock" AS "Check stock" -ADD SUGGESTION "transfer" AS "Transfer stock" -ADD SUGGESTION "count" AS "Cycle count" -ADD SUGGESTION "purchase" AS "Create PO" - -BEGIN TALK -**ERP Inventory Manager** - -I can help you with: -• Receive inventory from purchase orders -• Ship orders to customers -• Check stock levels across warehouses -• Transfer stock between locations -• Conduct cycle counts -• Create and manage purchase orders - -What would you like to do? -END TALK - -BEGIN SYSTEM PROMPT -You are an ERP inventory management assistant. - -Key operations: -- receive_inventory: Process incoming goods from POs -- ship_inventory: Process outgoing shipments for sales orders -- check_stock: Query inventory levels -- transfer_stock: Move inventory between warehouses -- cycle_count: Physical inventory verification - -Always confirm quantities before processing. -Log all transactions for audit trail. -Alert on low stock and reorder points. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the ERP template works in real-world scenarios. - -### Dialog 1: Receiving Inventory - - - -### Dialog 2: Check Stock Levels - - - -### Dialog 3: Ship an Order - - - -### Dialog 4: Transfer Stock - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register ERP operation tools | -| `SET CONTEXT` | Define ERP assistant behavior | -| `FIND` | Query inventory and orders | -| `SAVE` | Record transactions | -| `UPDATE` | Modify stock levels | -| `SEND MAIL` | Notify stakeholders | - -## Template Structure - -``` -erp.gbai/ -├── erp.gbdialog/ -│ ├── inventory-management.bas # Stock operations -│ ├── purchasing.bas # PO management -│ ├── erp-jobs.bas # Scheduled tasks -│ └── tables.bas # Data structures -└── erp.gbot/ - └── config.csv # Configuration -``` - -## Data Tables - -### Items Table -| Field | Description | -|-------|-------------| -| id | Unique item identifier | -| item_code | SKU/product code | -| name | Item description | -| category | Product category | -| unit_of_measure | UOM (each, case, etc.) | -| minimum_stock_level | Reorder threshold | -| reorder_point | When to reorder | -| reorder_quantity | How much to order | -| average_cost | Weighted average cost | -| last_cost | Most recent purchase cost | - -### Inventory Stock Table -| Field | Description | -|-------|-------------| -| item_id | Reference to item | -| warehouse_id | Location | -| quantity_on_hand | Physical count | -| quantity_reserved | Allocated to orders | -| quantity_available | On hand minus reserved | -| last_movement_date | Last transaction | -| last_counted_date | Last physical count | - -### Inventory Transactions Table -| Field | Description | -|-------|-------------| -| transaction_type | receipt, shipment, transfer, adjustment | -| transaction_number | Unique reference | -| item_id | Item affected | -| warehouse_id | Location | -| quantity | Amount (+/-) | -| unit_cost | Cost per unit | -| reference_type | PO, SO, Transfer | -| reference_id | Source document | - -## Inventory Management Tool - -```basic -PARAM action AS STRING LIKE "check_stock" DESCRIPTION "Action: receive_inventory, ship_inventory, check_stock, transfer_stock, cycle_count" -PARAM item_data AS OBJECT LIKE "{po_number: 'PO-123'}" DESCRIPTION "Data object with action-specific parameters" - -DESCRIPTION "Manage inventory operations" - -user_id = GET "session.user_id" -warehouse_id = GET "session.warehouse_id" - -IF action = "receive_inventory" THEN - po_number = item_data.po_number - po = FIND "purchase_orders", "po_number = '" + po_number + "'" - - IF NOT po THEN - TALK "Purchase order not found." - RETURN NULL - END IF - - po_lines = FIND "purchase_order_lines", "po_id = '" + po.id + "'" - - FOR EACH line IN po_lines - item = FIND "items", "id = '" + line.item_id + "'" - - TALK "Receiving " + item.name + " - Ordered: " + line.quantity_ordered - TALK "Enter quantity received:" - HEAR qty_received AS INTEGER - - ' Update stock - stock = FIND "inventory_stock", "item_id = '" + item.id + "' AND warehouse_id = '" + warehouse_id + "'" - - IF NOT stock THEN - WITH newStock - item_id = item.id - warehouse_id = warehouse_id - quantity_on_hand = qty_received - END WITH - SAVE "inventory_stock", newStock - ELSE - new_qty = stock.quantity_on_hand + qty_received - UPDATE "inventory_stock" SET quantity_on_hand = new_qty WHERE id = stock.id - END IF - - ' Create transaction record - WITH transaction - transaction_type = "receipt" - item_id = item.id - warehouse_id = warehouse_id - quantity = qty_received - unit_cost = line.unit_price - reference_type = "purchase_order" - reference_id = po.id - created_at = NOW() - END WITH - - SAVE "inventory_transactions", transaction - NEXT - - UPDATE "purchase_orders" SET status = "received" WHERE id = po.id - TALK "Purchase order " + po_number + " received." -END IF - -IF action = "check_stock" THEN - item_search = item_data.item_search - items = FIND "items", "name LIKE '%" + item_search + "%'" - - FOR EACH item IN items - TALK "📦 " + item.name + " (" + item.item_code + ")" - - stocks = FIND "inventory_stock", "item_id = '" + item.id + "'" - total = 0 - - FOR EACH stock IN stocks - warehouse = FIND "warehouses", "id = '" + stock.warehouse_id + "'" - TALK " " + warehouse.name + ": " + stock.quantity_on_hand - total = total + stock.quantity_on_hand - NEXT - - TALK " **TOTAL:** " + total - - IF total < item.minimum_stock_level THEN - TALK " ⚠️ Below minimum (" + item.minimum_stock_level + ")" - END IF - NEXT -END IF -``` - -## Scheduled Jobs: erp-jobs.bas - -```basic -PARAM jobname AS STRING DESCRIPTION "Job to execute" - -IF jobname = "low stock alert" THEN - SET SCHEDULE "0 8 * * *" ' Daily at 8 AM - - ' Find items below reorder point - low_items = SQL "SELECT i.*, s.quantity_on_hand - FROM items i - JOIN inventory_stock s ON i.id = s.item_id - WHERE s.quantity_on_hand <= i.reorder_point" - - IF UBOUND(low_items) > 0 THEN - report = "Low Stock Alert\n\n" - FOR EACH item IN low_items - report = report + item.name + ": " + item.quantity_on_hand + " (reorder at " + item.reorder_point + ")\n" - NEXT - - SEND MAIL "purchasing@company.com", "Daily Low Stock Alert", report - END IF -END IF - -IF jobname = "pending shipments" THEN - SET SCHEDULE "0 7 * * *" ' Daily at 7 AM - - pending = FIND "sales_orders", "status = 'ready_to_ship'" - - TALK "📦 " + UBOUND(pending) + " orders ready to ship today." - - SEND MAIL "warehouse@company.com", "Pending Shipments", - UBOUND(pending) + " orders need to be shipped today." -END IF -``` - -## Best Practices - -1. **Always Verify Quantities**: Confirm counts before processing -2. **Maintain Audit Trail**: Log all inventory movements -3. **Regular Cycle Counts**: Schedule periodic physical inventory -4. **Monitor Reorder Points**: Act on low stock alerts promptly -5. **Validate PO/SO Numbers**: Check document existence before processing -6. **Cost Tracking**: Maintain accurate cost records for COGS - -## Related Templates - -- [store.bas](./store.md) - E-commerce integration -- [talk-to-data.bas](./talk-to-data.md) - Inventory analytics -- [backup.bas](./backup.md) - Data backup procedures - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/helpdesk.md b/docs/src/chapter-06-gbdialog/templates/helpdesk.md deleted file mode 100644 index 8f036b5a..00000000 --- a/docs/src/chapter-06-gbdialog/templates/helpdesk.md +++ /dev/null @@ -1,599 +0,0 @@ -# IT Helpdesk Template - -The IT Helpdesk template provides a complete IT support ticketing system that helps users report problems, track ticket status, and get help with common technical issues. - -## Topic: IT Support & Ticket Management - -This template is perfect for: -- Internal IT support desks -- Technical support teams -- MSP (Managed Service Provider) helpdesks -- Customer technical support -- Self-service IT portals - -## The Code - -```basic -ADD TOOL "create-ticket" -ADD TOOL "check-ticket-status" -ADD TOOL "my-tickets" -ADD TOOL "update-ticket" -ADD TOOL "close-ticket" - -USE KB "helpdesk.gbkb" - -SET CONTEXT "it helpdesk" AS "You are an IT helpdesk assistant. Help users create support tickets, check ticket status, and troubleshoot common issues. Gather necessary information before creating tickets: issue description, urgency level, and affected systems." - -CLEAR SUGGESTIONS - -ADD SUGGESTION "new" AS "Report a problem" -ADD SUGGESTION "status" AS "Check ticket status" -ADD SUGGESTION "password" AS "Reset my password" -ADD SUGGESTION "vpn" AS "VPN issues" -ADD SUGGESTION "email" AS "Email not working" -ADD SUGGESTION "mytickets" AS "View my tickets" - -BEGIN TALK -**IT Helpdesk Support** - -I can help you with: -• Create a new support ticket -• Check ticket status -• Password resets -• Network and VPN problems -• Email issues -• Hardware and software support - -For urgent issues affecting multiple users, mention "urgent" or "critical". - -What can I help you with? -END TALK - -BEGIN SYSTEM PROMPT -You are an IT Helpdesk support assistant. - -Priority levels: -- Critical: System down, security breach, multiple users affected -- High: Single user unable to work, deadline impact -- Medium: Issue with workaround available -- Low: Minor inconvenience, feature requests - -Before creating a ticket, collect: -- Clear description of the issue -- When the issue started -- Error messages if any -- Steps already tried - -Try to resolve simple issues using the knowledge base before creating tickets. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the IT Helpdesk template works in real-world scenarios. - -### Dialog 1: Creating a Support Ticket - - - -### Dialog 2: Password Reset - - - -### Dialog 3: Check Ticket Status - - - -### Dialog 4: Critical System Issue - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register ticket management tools | -| `USE KB` | Load helpdesk knowledge base for troubleshooting | -| `SET CONTEXT` | Define IT support assistant behavior | -| `ADD SUGGESTION` | Create common issue shortcuts | -| `BEGIN TALK` | Welcome message with options | -| `BEGIN SYSTEM PROMPT` | Priority definitions and guidelines | - -## Template Structure - -``` -helpdesk.gbai/ -├── helpdesk.gbdialog/ -│ ├── start.bas # Main entry point -│ ├── create-ticket.bas # Ticket creation -│ ├── check-ticket-status.bas # Status lookup -│ ├── my-tickets.bas # User's tickets -│ ├── update-ticket.bas # Ticket updates -│ └── close-ticket.bas # Ticket resolution -├── helpdesk.gbdrive/ -│ └── templates/ # Response templates -├── helpdesk.gbkb/ -│ ├── common-issues.md # Troubleshooting guides -│ └── security-tips.md # Security best practices -└── helpdesk.gbot/ - └── config.csv # Bot configuration -``` - -## Create Ticket Tool: create-ticket.bas - -```basic -PARAM description AS STRING LIKE "Computer won't start" DESCRIPTION "Issue description" -PARAM category AS STRING LIKE "hardware" DESCRIPTION "Category: hardware, software, network, email, access" -PARAM priority AS STRING LIKE "medium" DESCRIPTION "Priority: critical, high, medium, low" OPTIONAL - -DESCRIPTION "Create a new IT support ticket" - -' Get user information -user_email = FROM -user_name = USERNAME - -' Auto-detect priority if not provided -IF NOT priority THEN - IF INSTR(LOWER(description), "urgent") > 0 OR INSTR(LOWER(description), "critical") > 0 THEN - priority = "critical" - ELSE IF INSTR(LOWER(description), "can't work") > 0 OR INSTR(LOWER(description), "blocked") > 0 THEN - priority = "high" - ELSE - priority = "medium" - END IF -END IF - -' Generate ticket number -ticketNumber = "INC-" + FORMAT(NOW(), "YYYY") + "-" + FORMAT(RANDOM(1000, 9999)) - -' Set SLA based on priority -SELECT CASE priority - CASE "critical" - slaMinutes = 15 - slaText = "15 minutes" - CASE "high" - slaMinutes = 120 - slaText = "2 hours" - CASE "medium" - slaMinutes = 480 - slaText = "8 hours" - CASE "low" - slaMinutes = 1440 - slaText = "24 hours" -END SELECT - -' Create ticket record -WITH ticket - id = ticketNumber - user_email = user_email - user_name = user_name - description = description - category = category - priority = priority - status = "open" - sla_due = DATEADD(NOW(), slaMinutes, "minutes") - created_at = NOW() -END WITH - -SAVE "tickets.csv", ticket - -' Send confirmation email -SEND MAIL user_email, "Ticket Created: " + ticketNumber, - "Your support ticket has been created.\n\n" + - "Ticket: " + ticketNumber + "\n" + - "Issue: " + description + "\n" + - "Priority: " + priority + "\n" + - "Response time: " + slaText - -' Notify support team -IF priority = "critical" THEN - SEND MAIL "oncall@company.com", "🚨 CRITICAL: " + ticketNumber, - "Critical ticket requires immediate attention:\n" + description -END IF - -TALK "✅ Ticket **" + ticketNumber + "** created!" -TALK "Priority: " + UPPER(priority) -TALK "Expected response: " + slaText - -RETURN ticketNumber -``` - -## My Tickets Tool: my-tickets.bas - -```basic -PARAM status AS STRING LIKE "open" DESCRIPTION "Filter by status: open, closed, all" OPTIONAL - -DESCRIPTION "View your support tickets" - -user_email = FROM - -IF NOT status OR status = "all" THEN - tickets = FIND "tickets.csv", "user_email = '" + user_email + "'" -ELSE - tickets = FIND "tickets.csv", "user_email = '" + user_email + "' AND status = '" + status + "'" -END IF - -IF UBOUND(tickets) = 0 THEN - TALK "You have no " + IIF(status, status, "") + " tickets." - RETURN NULL -END IF - -TALK "🎫 **Your Tickets:**" -TALK "" - -FOR EACH ticket IN tickets - statusIcon = "🔵" - IF ticket.status = "open" THEN statusIcon = "🟡" - IF ticket.status = "in_progress" THEN statusIcon = "🔵" - IF ticket.status = "resolved" THEN statusIcon = "🟢" - IF ticket.status = "closed" THEN statusIcon = "⚪" - - TALK "**" + ticket.id + "** " + statusIcon - TALK "📋 " + LEFT(ticket.description, 50) + "..." - TALK "📊 Status: " + ticket.status - TALK "📅 Created: " + FORMAT(ticket.created_at, "MMM DD, YYYY") - TALK "" -NEXT - -RETURN tickets -``` - -## Customization Ideas - -### Add Knowledge Base Self-Service - -```basic -' Before creating a ticket, search KB for solutions -solutions = SEARCH KB description - -IF UBOUND(solutions) > 0 THEN - TALK "I found some articles that might help:" - FOR EACH solution IN FIRST(solutions, 3) - TALK "• " + solution.title - NEXT - TALK "" - TALK "Did any of these solve your issue?" - HEAR resolved - - IF LOWER(resolved) = "yes" THEN - TALK "Great! Let me know if you need anything else." - RETURN NULL - END IF -END IF - -' Continue to ticket creation... -``` - -### Add Asset Tracking - -```basic -PARAM asset_tag AS STRING DESCRIPTION "Asset tag of affected equipment" - -' Look up asset information -asset = FIND "assets.csv", "tag = '" + asset_tag + "'" - -IF asset THEN - ticket.asset_tag = asset_tag - ticket.asset_type = asset.type - ticket.asset_model = asset.model - ticket.warranty_status = asset.warranty_expires > NOW() - - IF asset.warranty_expires > NOW() THEN - TALK "ℹ️ This device is under warranty until " + FORMAT(asset.warranty_expires, "MMM DD, YYYY") - END IF -END IF -``` - -### Add Escalation Rules - -```basic -' Check if ticket needs escalation -IF ticket.priority = "critical" AND ticket.category = "security" THEN - ' Escalate to security team - SEND MAIL "security@company.com", "🔴 Security Incident: " + ticketNumber, description - ticket.escalated_to = "security" - ticket.escalation_time = NOW() -END IF - -IF ticket.priority = "critical" AND DATEDIFF(NOW(), ticket.created_at, "minutes") > 30 THEN - ' Escalate if no response in 30 minutes - SEND MAIL "it-manager@company.com", "⚠️ SLA Breach Risk: " + ticketNumber, - "Critical ticket approaching SLA breach" -END IF -``` - -### Add Satisfaction Survey - -```basic -' When closing ticket -IF action = "close" THEN - ticket.status = "closed" - ticket.closed_at = NOW() - ticket.resolution = resolution - - UPDATE "tickets.csv", ticket - - TALK "Your ticket has been resolved!" - TALK "" - TALK "How would you rate your support experience?" - ADD SUGGESTION "5" AS "⭐⭐⭐⭐⭐ Excellent" - ADD SUGGESTION "4" AS "⭐⭐⭐⭐ Good" - ADD SUGGESTION "3" AS "⭐⭐⭐ Average" - ADD SUGGESTION "2" AS "⭐⭐ Poor" - ADD SUGGESTION "1" AS "⭐ Very Poor" - - HEAR rating - - WITH feedback - ticket_id = ticketNumber - rating = rating - timestamp = NOW() - END WITH - - SAVE "satisfaction.csv", feedback - - TALK "Thank you for your feedback!" -END IF -``` - -## Priority Matrix - -| Priority | Response Time | Resolution Time | Examples | -|----------|---------------|-----------------|----------| -| Critical | 15 minutes | 4 hours | System outage, security breach, multiple users down | -| High | 2 hours | 8 hours | Single user unable to work, deadline impact | -| Medium | 8 hours | 24 hours | Issue with workaround available | -| Low | 24 hours | 72 hours | Feature requests, minor inconveniences | - -## Related Templates - -- [hr/employees.bas](./employees.md) - Employee management integration -- [announcements.bas](./announcements.md) - IT announcements -- [backup.bas](./backup.md) - Backup and recovery - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/privacy.md b/docs/src/chapter-06-gbdialog/templates/privacy.md deleted file mode 100644 index 2b2bdac6..00000000 --- a/docs/src/chapter-06-gbdialog/templates/privacy.md +++ /dev/null @@ -1,578 +0,0 @@ -# Privacy Template - -The privacy template provides a complete LGPD/GDPR/CCPA-compliant Privacy Rights Center, enabling users to exercise their data protection rights through a conversational interface. - -## Topic: Data Privacy & Compliance - -This template is perfect for: -- LGPD compliance (Brazil) -- GDPR compliance (EU) -- CCPA compliance (California) -- Data subject rights management -- Consent management portals - -## The Code - -```basic -ADD TOOL "request-data" -ADD TOOL "export-data" -ADD TOOL "delete-data" -ADD TOOL "manage-consents" -ADD TOOL "rectify-data" -ADD TOOL "object-processing" - -USE KB "privacy.gbkb" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "access" AS "View my data" -ADD SUGGESTION "export" AS "Export my data" -ADD SUGGESTION "delete" AS "Delete my data" -ADD SUGGESTION "consents" AS "Manage consents" -ADD SUGGESTION "correct" AS "Correct my data" -ADD SUGGESTION "object" AS "Object to processing" - -SET CONTEXT "privacy rights" AS "You are a Privacy Rights Center assistant helping users exercise their data protection rights under LGPD, GDPR, and CCPA. Help with data access, rectification, erasure, portability, and consent management." - -BEGIN TALK -**Privacy Rights Center** - -As a data subject, you have the following rights: - -1. **Access** - View all data we hold about you -2. **Rectification** - Correct inaccurate data -3. **Erasure** - Request deletion of your data -4. **Portability** - Export your data -5. **Object** - Opt-out of certain processing -6. **Consent** - Review and update your consents - -Select an option or describe your request. -END TALK - -BEGIN SYSTEM PROMPT -You are a Privacy Rights Center assistant for LGPD/GDPR/CCPA compliance. - -Data subject rights: -- Right of Access: View all personal data -- Right to Rectification: Correct inaccurate data -- Right to Erasure: Delete personal data (right to be forgotten) -- Right to Portability: Export data in machine-readable format -- Right to Object: Opt-out of marketing, profiling, etc. -- Consent Management: Review and withdraw consents - -Always verify identity before processing sensitive requests. -Log all privacy requests for compliance audit. -Provide clear timelines for request fulfillment. -Escalate complex requests to the Data Protection Officer. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the privacy template works in real-world scenarios. - -### Dialog 1: Data Access Request - - - -### Dialog 2: Data Deletion Request - - - -### Dialog 3: Consent Management - - - -### Dialog 4: Data Export (Portability) - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register privacy rights tools | -| `USE KB` | Load privacy policy knowledge base | -| `ADD SUGGESTION` | Create quick action buttons for rights | -| `SET CONTEXT` | Define privacy assistant behavior | -| `BEGIN TALK` | Welcome message with rights summary | -| `BEGIN SYSTEM PROMPT` | Compliance rules and procedures | - -## Template Structure - -``` -privacy.gbai/ -├── privacy.gbdialog/ -│ ├── start.bas # Main entry point -│ ├── request-data.bas # Data access requests -│ ├── export-data.bas # Data portability -│ ├── delete-data.bas # Right to erasure -│ ├── manage-consents.bas # Consent management -│ └── rectify-data.bas # Data correction -├── privacy.gbot/ -│ └── config.csv # Configuration -├── privacy.gbkb/ -│ └── privacy-policy.md # Privacy documentation -└── privacy.gbui/ - └── index.html # Web portal UI -``` - -## Data Subject Rights by Regulation - -| Right | LGPD (Brazil) | GDPR (EU) | CCPA (California) | -|-------|---------------|-----------|-------------------| -| Access | Art. 18 | Art. 15 | §1798.100 | -| Rectification | Art. 18 III | Art. 16 | - | -| Erasure | Art. 18 VI | Art. 17 | §1798.105 | -| Portability | Art. 18 V | Art. 20 | §1798.100 | -| Object | Art. 18 IV | Art. 21 | §1798.120 | -| Consent | Art. 8 | Art. 7 | §1798.135 | - -## Response Deadlines - -| Regulation | Standard | Extended | -|------------|----------|----------| -| LGPD | 15 days | - | -| GDPR | 30 days | 90 days (complex) | -| CCPA | 45 days | 90 days | - -## Request Data Tool: request-data.bas - -```basic -PARAM request_type AS STRING LIKE "full" DESCRIPTION "Type of data request: full, summary, specific" - -DESCRIPTION "Process a data access request (Right of Access)" - -' Verify identity first -TALK "🔐 To protect your privacy, I need to verify your identity." -TALK "I'll send a verification code to your registered email." - -code = FORMAT(RANDOM(100000, 999999)) -SET BOT MEMORY "verification_code_" + user_id, code -SET BOT MEMORY "verification_expiry_" + user_id, DATEADD(NOW(), 10, "minutes") - -SEND MAIL user_email, "Privacy Request Verification", "Your verification code is: " + code - -TALK "Please enter the 6-digit code sent to your email:" -HEAR entered_code - -stored_code = GET BOT MEMORY("verification_code_" + user_id) -expiry = GET BOT MEMORY("verification_expiry_" + user_id) - -IF entered_code <> stored_code OR NOW() > expiry THEN - TALK "❌ Invalid or expired code. Please try again." - RETURN NULL -END IF - -' Log the request for compliance -WITH request - id = "ACC-" + FORMAT(NOW(), "YYYY") + "-" + FORMAT(RANDOM(100000, 999999)) - user_id = user_id - type = "access" - status = "processing" - created_at = NOW() - deadline = DATEADD(NOW(), 15, "days") -END WITH - -SAVE "privacy_requests.csv", request - -' Retrieve user data -userData = FIND "users.csv", "id = '" + user_id + "'" -activityData = FIND "activity_log.csv", "user_id = '" + user_id + "'" -consents = FIND "consents.csv", "user_id = '" + user_id + "'" - -TALK "✅ Identity verified. Here's your data:" -TALK "" -TALK "**📋 Personal Information**" -TALK "• Name: " + userData.name -TALK "• Email: " + MASK_EMAIL(userData.email) -TALK "• Account created: " + FORMAT(userData.created_at, "MMM DD, YYYY") -TALK "" -TALK "**📊 Activity Summary**" -TALK "• Total activities: " + UBOUND(activityData) -TALK "• Last activity: " + FORMAT(activityData[1].timestamp, "MMM DD, YYYY") -TALK "" -TALK "**🔔 Consent Status**" -FOR EACH consent IN consents - status_icon = IIF(consent.granted, "✅", "❌") - TALK "• " + consent.purpose + ": " + status_icon -NEXT - -TALK "" -TALK "Request ID: **" + request.id + "**" -TALK "Would you like a full export of your data?" - -RETURN request.id -``` - -## Delete Data Tool: delete-data.bas - -```basic -PARAM confirm AS STRING LIKE "yes" DESCRIPTION "Confirmation to proceed with deletion" - -DESCRIPTION "Process a data erasure request (Right to be Forgotten)" - -' Warn about consequences -TALK "⚠️ **Data Deletion Request**" -TALK "" -TALK "This will permanently delete:" -TALK "• Your profile and personal information" -TALK "• Activity history and preferences" -TALK "• Communication history" -TALK "" -TALK "**Note:** Some data may be retained for legal compliance:" -TALK "• Financial records (tax requirements)" -TALK "• Fraud prevention data" -TALK "• Legal dispute documentation" -TALK "" -TALK "Type **DELETE MY DATA** to confirm this irreversible action:" - -HEAR confirmation - -IF UPPER(confirmation) <> "DELETE MY DATA" THEN - TALK "Deletion cancelled. Your data remains unchanged." - RETURN NULL -END IF - -' Create deletion request -WITH request - id = "DEL-" + FORMAT(NOW(), "YYYY") + "-" + FORMAT(RANDOM(100000, 999999)) - user_id = user_id - type = "erasure" - status = "pending_verification" - created_at = NOW() - deadline = DATEADD(NOW(), 15, "days") -END WITH - -SAVE "privacy_requests.csv", request - -' Send verification email -verification_link = "https://privacy.company.com/verify/" + request.id -SEND MAIL user_email, "Confirm Data Deletion Request", - "Click to confirm your data deletion request:\n\n" + verification_link + - "\n\nThis link expires in 24 hours.\n\nRequest ID: " + request.id - -TALK "📧 A verification email has been sent." -TALK "Please click the link to confirm your deletion request." -TALK "" -TALK "**Timeline:**" -TALK "• Verification: 24 hours" -TALK "• Processing: 15 business days (LGPD) / 30 days (GDPR)" -TALK "" -TALK "Request ID: **" + request.id + "**" - -RETURN request.id -``` - -## Customization Ideas - -### Add Identity Verification Options - -```basic -TALK "How would you like to verify your identity?" -ADD SUGGESTION "email" AS "Email verification" -ADD SUGGESTION "sms" AS "SMS verification" -ADD SUGGESTION "id" AS "Upload ID document" - -HEAR method - -SWITCH method - CASE "email" - ' Send email code - CASE "sms" - ' Send SMS code - CASE "id" - TALK "Please upload a photo of your government-issued ID." - HEAR id_upload AS FILE - ' Process ID verification -END SWITCH -``` - -### Add DPO Escalation - -```basic -' For complex requests -IF request_complexity = "high" THEN - TALK "This request requires review by our Data Protection Officer." - TALK "You will be contacted within 5 business days." - - SEND MAIL "dpo@company.com", "Privacy Request Escalation", - "Request ID: " + request.id + "\n" + - "Type: " + request.type + "\n" + - "User: " + user_email + "\n" + - "Reason: Complex request requiring DPO review" -END IF -``` - -### Add Audit Logging - -```basic -' Log all privacy operations -WITH auditLog - timestamp = NOW() - request_id = request.id - user_id = user_id - action = "data_access" - ip_address = GET_CLIENT_IP() - user_agent = GET_USER_AGENT() - result = "success" -END WITH - -SAVE "privacy_audit_log.csv", auditLog -``` - -## Best Practices - -1. **Always Verify Identity**: Never provide data without verification -2. **Log Everything**: Maintain audit trails for compliance -3. **Clear Timelines**: Communicate response deadlines clearly -4. **Explain Retention**: Be transparent about what data is retained and why -5. **Easy Consent Management**: Make it simple to change preferences -6. **Secure Communications**: Use encrypted channels for sensitive data - -## Related Templates - -- [auth.bas](./auth.md) - Authentication patterns -- [bank.bas](./bank.md) - Secure financial data handling -- [hipaa.bas](./hipaa.md) - Healthcare privacy compliance - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/sales-pipeline.md b/docs/src/chapter-06-gbdialog/templates/sales-pipeline.md deleted file mode 100644 index 3b47e0a0..00000000 --- a/docs/src/chapter-06-gbdialog/templates/sales-pipeline.md +++ /dev/null @@ -1,734 +0,0 @@ -# Sales Pipeline Template - -The sales pipeline template provides a complete CRM (Customer Relationship Management) system for managing deals, tracking opportunities through sales stages, and generating revenue forecasts. - -## Topic: Sales Pipeline & Deal Management - -This template is perfect for: -- Sales teams tracking deals -- Revenue forecasting -- Pipeline management -- Win/loss analysis -- Sales performance reporting - -## The Code - -```basic -ADD TOOL "create-deal" -ADD TOOL "update-stage" -ADD TOOL "list-deals" -ADD TOOL "deal-details" -ADD TOOL "pipeline-report" -ADD TOOL "forecast-revenue" - -USE KB "sales-pipeline.gbkb" - -SET CONTEXT "sales pipeline" AS "You are a sales assistant helping manage the sales pipeline. Help with creating new deals, updating deal stages, viewing pipeline status, generating sales forecasts, and analyzing win/loss rates." - -CLEAR SUGGESTIONS - -ADD SUGGESTION "newdeal" AS "Create a new deal" -ADD SUGGESTION "pipeline" AS "Show my pipeline" -ADD SUGGESTION "update" AS "Update a deal stage" -ADD SUGGESTION "forecast" AS "View sales forecast" -ADD SUGGESTION "report" AS "Generate pipeline report" - -BEGIN TALK -**Sales Pipeline Manager** - -I can help you with: -• Create new deals and opportunities -• View and manage your pipeline -• Update deal stages -• Generate sales forecasts -• Pipeline analytics and reports -• Track win/loss rates - -Select an option or tell me what you need. -END TALK - -BEGIN SYSTEM PROMPT -You are a sales pipeline assistant. - -Pipeline stages: -- Lead: Initial contact, not qualified -- Qualified: Budget, authority, need, timeline confirmed -- Proposal: Quote sent -- Negotiation: Active discussions -- Closed Won: Successfully closed -- Closed Lost: Lost or no decision - -Always encourage sales reps and provide actionable insights. -Confirm changes before saving. -Use currency format for amounts. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the sales pipeline template works in real-world scenarios. - -### Dialog 1: Creating a New Deal - - - -### Dialog 2: Viewing Pipeline - - - -### Dialog 3: Update Deal Stage - - - -### Dialog 4: Revenue Forecast - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register pipeline management tools | -| `USE KB` | Load sales methodology knowledge base | -| `SET CONTEXT` | Define sales assistant behavior | -| `ADD SUGGESTION` | Create quick action buttons | -| `BEGIN TALK` | Welcome message with options | -| `BEGIN SYSTEM PROMPT` | Sales stage definitions and guidelines | - -## Pipeline Stages - -| Stage | Win Probability | Description | -|-------|-----------------|-------------| -| Lead | 20% | Initial contact, not yet qualified | -| Qualified | 40% | BANT criteria confirmed | -| Proposal | 50% | Quote or proposal sent | -| Negotiation | 80% | Active deal discussions | -| Closed Won | 100% | Deal successfully closed | -| Closed Lost | 0% | Deal lost or abandoned | - -## Template Structure - -``` -sales-pipeline.gbai/ -├── sales-pipeline.gbdialog/ -│ ├── start.bas # Main entry point -│ ├── create-deal.bas # New deal creation -│ ├── update-stage.bas # Stage progression -│ ├── list-deals.bas # Pipeline view -│ ├── deal-details.bas # Individual deal info -│ ├── pipeline-report.bas # Analytics reports -│ └── forecast-revenue.bas # Revenue forecasting -├── sales-pipeline.gbdrive/ -│ └── templates/ # Proposal templates -├── sales-pipeline.gbkb/ -│ └── sales-methodology.md # Sales best practices -└── sales-pipeline.gbot/ - └── config.csv # Bot configuration -``` - -## Create Deal Tool: create-deal.bas - -```basic -PARAM company AS STRING LIKE "Acme Corp" DESCRIPTION "Company or account name" -PARAM value AS NUMBER LIKE 50000 DESCRIPTION "Deal value in dollars" -PARAM close_date AS DATE LIKE "2025-03-31" DESCRIPTION "Expected close date" -PARAM contact AS STRING DESCRIPTION "Primary contact name" OPTIONAL -PARAM notes AS STRING DESCRIPTION "Deal notes" OPTIONAL - -DESCRIPTION "Create a new deal in the sales pipeline" - -' Generate deal ID -dealId = "DEAL-" + FORMAT(NOW(), "YYYY") + "-" + FORMAT(RANDOM(1000, 9999)) - -' Get sales rep info -salesRep = USERNAME -salesRepEmail = FROM - -' Create deal record -WITH deal - id = dealId - company = company - value = value - expected_close = close_date - contact_name = contact - notes = notes - stage = "lead" - probability = 20 - owner = salesRep - owner_email = salesRepEmail - created_at = NOW() - updated_at = NOW() -END WITH - -SAVE "deals.csv", deal - -' Log activity -WITH activity - deal_id = dealId - type = "created" - description = "Deal created with value $" + FORMAT(value, "#,##0") - user = salesRep - timestamp = NOW() -END WITH - -SAVE "deal_activities.csv", activity - -TALK "✅ **Deal Created!**" -TALK "🏢 **Company:** " + company -TALK "💰 **Value:** $" + FORMAT(value, "#,##0") -TALK "📅 **Expected Close:** " + FORMAT(close_date, "MMMM DD, YYYY") -TALK "📊 **Stage:** Lead" -TALK "🎫 **Deal ID:** " + dealId -TALK "" -TALK "Good luck! 🍀" - -RETURN dealId -``` - -## Update Stage Tool: update-stage.bas - -```basic -PARAM deal_id AS STRING LIKE "DEAL-2025-0142" DESCRIPTION "Deal ID or company name" -PARAM new_stage AS STRING LIKE "qualified" DESCRIPTION "New stage: lead, qualified, proposal, negotiation, closed_won, closed_lost" -PARAM reason AS STRING DESCRIPTION "Reason for stage change" OPTIONAL - -DESCRIPTION "Update the stage of a deal in the pipeline" - -' Find deal -deal = FIND "deals.csv", "id = '" + deal_id + "' OR LOWER(company) LIKE '%" + LOWER(deal_id) + "%'" - -IF NOT deal THEN - TALK "Deal not found. Please check the deal ID or company name." - RETURN NULL -END IF - -old_stage = deal.stage -new_stage_lower = LOWER(new_stage) - -' Set probability based on stage -SELECT CASE new_stage_lower - CASE "lead" - probability = 20 - CASE "qualified" - probability = 40 - CASE "proposal" - probability = 50 - CASE "negotiation" - probability = 80 - CASE "closed_won" - probability = 100 - CASE "closed_lost" - probability = 0 -END SELECT - -' Update deal -deal.stage = new_stage_lower -deal.probability = probability -deal.updated_at = NOW() - -IF new_stage_lower = "closed_won" THEN - deal.closed_date = NOW() - deal.closed_value = deal.value -ELSE IF new_stage_lower = "closed_lost" THEN - deal.closed_date = NOW() - deal.lost_reason = reason -END IF - -UPDATE "deals.csv", deal - -' Log activity -WITH activity - deal_id = deal.id - type = "stage_change" - description = "Stage changed: " + old_stage + " → " + new_stage_lower - user = USERNAME - timestamp = NOW() -END WITH - -SAVE "deal_activities.csv", activity - -' Format stage names -old_stage_display = PROPER(REPLACE(old_stage, "_", " ")) -new_stage_display = PROPER(REPLACE(new_stage_lower, "_", " ")) - -TALK "✅ **Deal Updated!**" -TALK "🏢 **" + deal.company + "**" -TALK "📊 " + old_stage_display + " → **" + new_stage_display + "**" -TALK "💰 $" + FORMAT(deal.value, "#,##0") - -IF new_stage_lower = "closed_won" THEN - TALK "" - TALK "🎉 Congratulations on closing the deal!" -ELSE IF new_stage_lower = "closed_lost" THEN - TALK "" - TALK "📝 Deal marked as lost. Keep pushing on the other opportunities!" -ELSE - TALK "" - TALK "Win probability: " + probability + "%" -END IF - -RETURN deal.id -``` - -## Forecast Revenue Tool: forecast-revenue.bas - -```basic -PARAM period AS STRING LIKE "this quarter" DESCRIPTION "Forecast period: this month, this quarter, this year" - -DESCRIPTION "Generate revenue forecast based on pipeline and probabilities" - -' Determine date range -IF INSTR(LOWER(period), "month") > 0 THEN - start_date = DATE(YEAR(NOW()), MONTH(NOW()), 1) - end_date = DATEADD(DATEADD(start_date, 1, "month"), -1, "day") - period_name = FORMAT(NOW(), "MMMM YYYY") -ELSE IF INSTR(LOWER(period), "quarter") > 0 THEN - quarter = INT((MONTH(NOW()) - 1) / 3) + 1 - start_date = DATE(YEAR(NOW()), (quarter - 1) * 3 + 1, 1) - end_date = DATEADD(DATEADD(start_date, 3, "month"), -1, "day") - period_name = "Q" + quarter + " " + YEAR(NOW()) -ELSE - start_date = DATE(YEAR(NOW()), 1, 1) - end_date = DATE(YEAR(NOW()), 12, 31) - period_name = YEAR(NOW()) -END IF - -' Get deals closing in period -deals = FIND "deals.csv", "expected_close >= '" + FORMAT(start_date, "YYYY-MM-DD") + "' AND expected_close <= '" + FORMAT(end_date, "YYYY-MM-DD") + "' AND stage NOT IN ('closed_won', 'closed_lost')" - -' Calculate forecasts by stage -weighted_total = 0 -best_case = 0 -committed = 0 - -stages = ["negotiation", "proposal", "qualified", "lead"] -stage_totals = [] - -FOR EACH stage IN stages - stage_deals = FILTER(deals, "stage = '" + stage + "'") - stage_value = 0 - stage_weighted = 0 - - FOR EACH deal IN stage_deals - stage_value = stage_value + deal.value - stage_weighted = stage_weighted + (deal.value * deal.probability / 100) - NEXT - - best_case = best_case + stage_value - weighted_total = weighted_total + stage_weighted - - IF stage = "negotiation" THEN - committed = committed + stage_weighted - END IF - - stage_totals[stage] = {value: stage_value, weighted: stage_weighted, prob: deals[1].probability} -NEXT - -' Get closed won in period -closed = FIND "deals.csv", "closed_date >= '" + FORMAT(start_date, "YYYY-MM-DD") + "' AND stage = 'closed_won'" -closed_value = 0 -FOR EACH deal IN closed - closed_value = closed_value + deal.closed_value -NEXT - -' Get quota -quota = GET BOT MEMORY("quota_" + USERNAME) -IF NOT quota THEN quota = 200000 - -attainment = ((closed_value + weighted_total) / quota) * 100 - -TALK "📈 **" + period_name + " Revenue Forecast**" -TALK "" -TALK "**By Stage:**" -TALK "• Negotiation (80%): $" + FORMAT(stage_totals["negotiation"].weighted, "#,##0") -TALK "• Proposal (50%): $" + FORMAT(stage_totals["proposal"].weighted, "#,##0") -TALK "• Qualified (40%): $" + FORMAT(stage_totals["qualified"].weighted, "#,##0") -TALK "• Lead (20%): $" + FORMAT(stage_totals["lead"].weighted, "#,##0") -TALK "" -TALK "**Weighted Forecast:** $" + FORMAT(weighted_total, "#,##0") -TALK "**Best Case:** $" + FORMAT(best_case, "#,##0") -TALK "**Committed:** $" + FORMAT(committed, "#,##0") -TALK "**Already Closed:** $" + FORMAT(closed_value, "#,##0") -TALK "" -TALK "**Quota:** $" + FORMAT(quota, "#,##0") -TALK "**Attainment:** " + FORMAT(attainment, "#,##0") + "% (forecasted)" - -IF attainment >= 100 THEN - TALK "" - TALK "🎯 You're on track to exceed quota!" -ELSE IF attainment >= 80 THEN - TALK "" - TALK "📊 You're close! Focus on advancing your top deals." -ELSE - TALK "" - TALK "⚠️ You need more pipeline coverage. Time to prospect!" -END IF - -RETURN {weighted: weighted_total, best_case: best_case, attainment: attainment} -``` - -## Customization Ideas - -### Add Deal Scoring - -```basic -' Calculate deal score based on various factors -score = 0 - -' Company size score -IF deal.company_size > 1000 THEN - score = score + 20 -ELSE IF deal.company_size > 100 THEN - score = score + 10 -END IF - -' Budget confirmed -IF deal.budget_confirmed THEN - score = score + 25 -END IF - -' Decision maker engaged -IF deal.decision_maker THEN - score = score + 25 -END IF - -' Timeline urgency -IF DATEDIFF(deal.expected_close, NOW(), "days") < 30 THEN - score = score + 20 -END IF - -' Competitor involved -IF deal.competitor THEN - score = score - 10 -END IF - -deal.score = score -TALK "Deal Score: " + score + "/100" -``` - -### Add Activity Tracking - -```basic -ADD TOOL "log-activity" - -PARAM deal_id AS STRING DESCRIPTION "Deal ID" -PARAM activity_type AS STRING LIKE "call" DESCRIPTION "Type: call, email, meeting, demo, proposal" -PARAM notes AS STRING DESCRIPTION "Activity notes" - -WITH activity - deal_id = deal_id - type = activity_type - notes = notes - user = USERNAME - timestamp = NOW() -END WITH - -SAVE "deal_activities.csv", activity - -' Update deal's last activity date -UPDATE "deals.csv" SET last_activity = NOW() WHERE id = deal_id - -TALK "✅ Activity logged for deal " + deal_id -``` - -### Add Win/Loss Analysis - -```basic -ADD TOOL "win-loss-report" - -won = FIND "deals.csv", "stage = 'closed_won' AND closed_date >= '" + start_date + "'" -lost = FIND "deals.csv", "stage = 'closed_lost' AND closed_date >= '" + start_date + "'" - -won_count = UBOUND(won) -lost_count = UBOUND(lost) -win_rate = (won_count / (won_count + lost_count)) * 100 - -won_value = 0 -FOR EACH deal IN won - won_value = won_value + deal.value -NEXT - -TALK "📊 **Win/Loss Analysis**" -TALK "" -TALK "**Win Rate:** " + FORMAT(win_rate, "#0.0") + "%" -TALK "**Deals Won:** " + won_count + " ($" + FORMAT(won_value, "#,##0") + ")" -TALK "**Deals Lost:** " + lost_count -TALK "" -TALK "**Top Loss Reasons:**" -' Aggregate loss reasons... -``` - -### Add Email Integration - -```basic -' Send proposal email from pipeline -ADD TOOL "send-proposal" - -PARAM deal_id AS STRING DESCRIPTION "Deal to send proposal for" - -deal = FIND "deals.csv", "id = '" + deal_id + "'" - -' Generate proposal from template -proposal = FILL "proposal-template.docx", deal - -' Send email -SEND MAIL deal.contact_email, "Proposal for " + deal.company, - "Please find attached our proposal.\n\nBest regards,\n" + USERNAME, - proposal - -' Update deal stage -deal.stage = "proposal" -deal.proposal_sent = NOW() -UPDATE "deals.csv", deal - -TALK "📧 Proposal sent to " + deal.contact_email -TALK "Deal moved to Proposal stage." -``` - -## Best Practices - -1. **Keep Deals Updated**: Update deal stages promptly for accurate forecasting -2. **Log Activities**: Track all customer interactions -3. **Use BANT**: Qualify deals properly before advancing -4. **Clean Pipeline**: Remove stale deals regularly -5. **Review Weekly**: Check pipeline health and forecasts weekly - -## Related Templates - -- [crm/contacts.bas](./contacts.md) - Contact management -- [marketing.bas](./marketing.md) - Lead generation -- [store.bas](./store.md) - E-commerce integration - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/start.md b/docs/src/chapter-06-gbdialog/templates/start.md deleted file mode 100644 index ede9e536..00000000 --- a/docs/src/chapter-06-gbdialog/templates/start.md +++ /dev/null @@ -1,274 +0,0 @@ -# Start Template - -The start template is the simplest possible bot - a greeting flow that demonstrates the core interaction pattern of BASIC: greeting users and responding to their input. - -## Topic: Basic Greeting & Help Flow - -This template is perfect for: -- Learning BASIC fundamentals -- Simple FAQ bots -- Quick demos -- Starting point for more complex bots - -## The Code - -```basic -REM Basic greeting and help flow -SET user_name = "Guest" - -TALK "Hello, " + user_name + "! How can I help you today?" -HEAR user_input - -IF user_input = "help" THEN - TALK "Sure, I can assist with account info, orders, or support." -ELSE - TALK "Sorry, I didn't understand. Type 'help' for options." -END IF -``` - -## Sample Dialogs - -These conversations show how the start template works in real-world scenarios. - -### Dialog 1: User Asks for Help - - - -### Dialog 2: Unknown Input - - - -### Dialog 3: Personalized Greeting (Enhanced Version) - -When you add user detection, the experience improves: - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `SET` | Assign a value to a variable | -| `TALK` | Send a message to the user | -| `HEAR` | Wait for and capture user input | -| `IF/ELSE` | Conditional branching based on input | - -## How It Works - -1. **Variable Setup**: `SET` creates a variable to hold the user's name -2. **Greeting**: `TALK` sends the welcome message -3. **Input Capture**: `HEAR` waits for user response -4. **Response Logic**: `IF/ELSE` determines what to say back - -## Enhanced Version - -Here's the same template enhanced with LLM for natural understanding: - -```basic -REM Smart greeting flow with LLM -SET user_name = "Guest" - -TALK "Hello, " + user_name + "! How can I help you today?" -HEAR user_input - -' Let LLM understand intent -intent = LLM "Classify this user message into one category: help, account, orders, support, other. Message: " + user_input - -SWITCH intent - CASE "help" - TALK "I can assist with account info, orders, or support." - CASE "account" - TALK "Let me pull up your account information..." - CASE "orders" - TALK "I'll check on your recent orders..." - CASE "support" - TALK "Connecting you with our support team..." - DEFAULT - response = LLM "Respond helpfully to: " + user_input - TALK response -END SWITCH -``` - -## Customization Ideas - -### Add User Detection - -```basic -' Get user info if available -user_name = GET BOT MEMORY "user_" + user_id + "_name" -IF user_name = "" THEN - TALK "Hi there! What's your name?" - HEAR user_name - SET BOT MEMORY "user_" + user_id + "_name", user_name -END IF - -TALK "Welcome back, " + user_name + "!" -``` - -### Add Quick Reply Buttons - -```basic -ADD SUGGESTION "Account Info" -ADD SUGGESTION "My Orders" -ADD SUGGESTION "Get Support" -TALK "What would you like help with?" -HEAR choice -``` - -### Add Time-Based Greeting - -```basic -hour = HOUR(NOW()) -IF hour < 12 THEN - greeting = "Good morning" -ELSE IF hour < 18 THEN - greeting = "Good afternoon" -ELSE - greeting = "Good evening" -END IF - -TALK greeting + ", " + user_name + "!" -``` - -## Related Templates - -- [enrollment.bas](./enrollment.md) - Multi-step data collection -- [auth.bas](./auth.md) - User authentication patterns - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/store.md b/docs/src/chapter-06-gbdialog/templates/store.md deleted file mode 100644 index 38199cea..00000000 --- a/docs/src/chapter-06-gbdialog/templates/store.md +++ /dev/null @@ -1,589 +0,0 @@ -# Store Template - -The store template provides a complete e-commerce assistant that helps customers browse products, manage shopping carts, and complete purchases through conversational AI. - -## Topic: E-Commerce & Shopping Assistant - -This template is perfect for: -- Online retail stores -- Product catalog browsing -- Shopping cart management -- Order tracking -- Customer support for e-commerce - -## The Code - -```basic -ADD TOOL "checkout" -ADD TOOL "search-product" -ADD TOOL "add-to-cart" -ADD TOOL "view-cart" -ADD TOOL "track-order" -ADD TOOL "product-details" - -data = FIND "products.csv" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "products" AS "View products" -ADD SUGGESTION "cart" AS "View my cart" -ADD SUGGESTION "checkout" AS "Checkout" -ADD SUGGESTION "orders" AS "Track my order" -ADD SUGGESTION "help" AS "Shopping help" - -SET CONTEXT "store" AS "You are a virtual store sales assistant. Help customers browse products, add items to cart, and complete purchases. Be friendly and helpful. Available products: ${TOJSON(data)}" - -BEGIN TALK -**Virtual Store** - -Welcome! I can help you with: -• Browse our product catalog -• Add items to your cart -• Complete your purchase -• Track your orders - -Select an option or tell me what you're looking for. -END TALK - -BEGIN SYSTEM PROMPT -You are a friendly sales assistant in our virtual store. - -Welcome customers warmly. -Help them find products. -Provide clear product information. -Guide through purchase process. -Offer assistance when needed. - -Product catalog is available in context. -Suggest related products when appropriate. -Confirm items before adding to cart. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the store template works in real-world scenarios. - -### Dialog 1: Product Search - - - -### Dialog 2: Add to Cart and Checkout - - - -### Dialog 3: Order Tracking - - - -### Dialog 4: Product Recommendations - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register e-commerce tools | -| `FIND` | Load product catalog from CSV | -| `ADD SUGGESTION` | Create quick action buttons | -| `SET CONTEXT` | Define store context with product data | -| `BEGIN TALK` | Welcome message block | -| `BEGIN SYSTEM PROMPT` | Sales assistant behavior rules | - -## Template Structure - -``` -store.gbai/ -├── store.gbdialog/ -│ ├── start.bas # Main entry point -│ └── checkout.bas # Checkout process -├── store.gbdata/ -│ └── products.csv # Product catalog -└── store.gbot/ - └── config.csv # Bot configuration -``` - -## Checkout Tool: checkout.bas - -```basic -PARAM confirm AS STRING LIKE "yes" DESCRIPTION "Confirm order placement" - -DESCRIPTION "Complete the purchase and process payment" - -' Get cart from memory -cart = GET BOT MEMORY("cart_" + user_id) - -IF UBOUND(cart) = 0 THEN - TALK "Your cart is empty. Add some items first!" - RETURN NULL -END IF - -' Calculate totals -subtotal = 0 -FOR EACH item IN cart - subtotal = subtotal + (item.price * item.quantity) -NEXT - -shipping = 9.99 -IF subtotal > 100 THEN - shipping = 0 ' Free shipping over $100 -END IF - -total = subtotal + shipping - -' Show order summary -TALK "📦 **Order Summary**" -TALK "" -FOR EACH item IN cart - TALK item.quantity + "x " + item.name + " - $" + FORMAT(item.price * item.quantity, "#,##0.00") -NEXT -TALK "" -TALK "Subtotal: $" + FORMAT(subtotal, "#,##0.00") -IF shipping = 0 THEN - TALK "Shipping: FREE ✨" -ELSE - TALK "Shipping: $" + FORMAT(shipping, "#,##0.00") -END IF -TALK "**Total: $" + FORMAT(total, "#,##0.00") + "**" -TALK "" -TALK "Type CONFIRM to place your order." - -HEAR confirmation - -IF UPPER(confirmation) = "CONFIRM" THEN - ' Create order - orderNumber = "ORD-" + FORMAT(NOW(), "YYYY-MMDD") + "-" + FORMAT(RANDOM(100, 999)) - - WITH order - id = orderNumber - user_id = user_id - items = TOJSON(cart) - subtotal = subtotal - shipping = shipping - total = total - status = "confirmed" - created_at = NOW() - END WITH - - SAVE "orders.csv", order - - ' Clear cart - SET BOT MEMORY "cart_" + user_id, [] - - ' Send confirmation email - SEND MAIL user_email, "Order Confirmed - " + orderNumber, - "Thank you for your order!\n\nOrder: " + orderNumber + "\nTotal: $" + total - - TALK "✅ **Order Confirmed!**" - TALK "Order #" + orderNumber - TALK "📧 Confirmation sent to your email" - TALK "🚚 Estimated delivery: 3-5 business days" - TALK "" - TALK "Thank you for shopping with us! 🎉" - - RETURN orderNumber -ELSE - TALK "Order cancelled. Your cart items are saved." - RETURN NULL -END IF -``` - -## Add to Cart Tool: add-to-cart.bas - -```basic -PARAM product_id AS STRING LIKE "PROD001" DESCRIPTION "Product ID to add" -PARAM quantity AS INTEGER LIKE 1 DESCRIPTION "Quantity to add" - -DESCRIPTION "Add a product to the shopping cart" - -IF NOT quantity THEN - quantity = 1 -END IF - -' Find product -product = FIND "products.csv", "id = '" + product_id + "'" - -IF NOT product THEN - TALK "Sorry, I couldn't find that product. Please try again." - RETURN NULL -END IF - -' Get current cart -cart = GET BOT MEMORY("cart_" + user_id) -IF NOT cart THEN - cart = [] -END IF - -' Check if product already in cart -found = FALSE -FOR i = 1 TO UBOUND(cart) - IF cart[i].product_id = product_id THEN - cart[i].quantity = cart[i].quantity + quantity - found = TRUE - EXIT FOR - END IF -NEXT - -' Add new item if not found -IF NOT found THEN - WITH item - product_id = product_id - name = product.name - price = product.price - quantity = quantity - END WITH - - cart = APPEND(cart, item) -END IF - -' Save cart -SET BOT MEMORY "cart_" + user_id, cart - -' Calculate cart total -cartTotal = 0 -cartCount = 0 -FOR EACH item IN cart - cartTotal = cartTotal + (item.price * item.quantity) - cartCount = cartCount + item.quantity -NEXT - -TALK "✅ Added to cart!" -TALK "**" + product.name + "** - $" + FORMAT(product.price, "#,##0.00") -TALK "" -TALK "🛒 Your cart: " + cartCount + " items ($" + FORMAT(cartTotal, "#,##0.00") + ")" - -' Suggest related products -IF product.category THEN - related = FIND "products.csv", "category = '" + product.category + "' AND id <> '" + product_id + "'" - IF UBOUND(related) > 0 THEN - TALK "" - TALK "You might also like: **" + related[1].name + "** - $" + FORMAT(related[1].price, "#,##0.00") - END IF -END IF - -RETURN cart -``` - -## Customization Ideas - -### Add Product Reviews - -```basic -ADD TOOL "show-reviews" - -' In show-reviews.bas -PARAM product_id AS STRING DESCRIPTION "Product to show reviews for" - -reviews = FIND "reviews.csv", "product_id = '" + product_id + "'" - -IF UBOUND(reviews) = 0 THEN - TALK "No reviews yet for this product." - RETURN -END IF - -avgRating = 0 -FOR EACH review IN reviews - avgRating = avgRating + review.rating -NEXT -avgRating = avgRating / UBOUND(reviews) - -TALK "⭐ **Customer Reviews** (" + FORMAT(avgRating, "#.#") + "/5)" -TALK "" - -FOR EACH review IN FIRST(reviews, 3) - TALK "**" + review.author + "** - " + STRING(review.rating, "⭐") - TALK review.comment - TALK "" -NEXT -``` - -### Add Discount Codes - -```basic -PARAM code AS STRING DESCRIPTION "Discount code to apply" - -discount = FIND "discounts.csv", "code = '" + UPPER(code) + "' AND valid_until >= '" + FORMAT(NOW(), "YYYY-MM-DD") + "'" - -IF NOT discount THEN - TALK "Sorry, that code is invalid or expired." - RETURN NULL -END IF - -SET BOT MEMORY "discount_" + user_id, discount - -TALK "✅ Discount applied!" -TALK "**" + discount.description + "**" -IF discount.type = "percent" THEN - TALK "You'll save " + discount.value + "% on your order!" -ELSE - TALK "You'll save $" + FORMAT(discount.value, "#,##0.00") + " on your order!" -END IF -``` - -### Add Wishlist Feature - -```basic -ADD TOOL "add-to-wishlist" -ADD TOOL "view-wishlist" - -' In add-to-wishlist.bas -PARAM product_id AS STRING DESCRIPTION "Product to add to wishlist" - -wishlist = GET USER MEMORY("wishlist") -IF NOT wishlist THEN - wishlist = [] -END IF - -wishlist = APPEND(wishlist, product_id) -SET USER MEMORY "wishlist", wishlist - -product = FIND "products.csv", "id = '" + product_id + "'" -TALK "❤️ Added **" + product.name + "** to your wishlist!" -``` - -### Add Inventory Check - -```basic -' Before adding to cart, check stock -stock = FIND "inventory.csv", "product_id = '" + product_id + "'" - -IF stock.quantity < quantity THEN - IF stock.quantity = 0 THEN - TALK "😔 Sorry, this item is out of stock." - TALK "Would you like to be notified when it's available?" - ELSE - TALK "⚠️ Only " + stock.quantity + " left in stock." - TALK "Would you like to add " + stock.quantity + " instead?" - END IF - RETURN NULL -END IF -``` - -## Related Templates - -- [bank.bas](./bank.md) - Payment processing integration -- [broadcast.bas](./broadcast.md) - Marketing campaigns -- [talk-to-data.bas](./talk-to-data.md) - Sales analytics - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/talk-to-data.md b/docs/src/chapter-06-gbdialog/templates/talk-to-data.md deleted file mode 100644 index c4fdeb3c..00000000 --- a/docs/src/chapter-06-gbdialog/templates/talk-to-data.md +++ /dev/null @@ -1,560 +0,0 @@ -# Talk to Data Template - -The Talk to Data template enables natural language queries against your structured data, transforming plain English questions into SQL queries and visualizations. It's like having a data analyst available 24/7. - -## Topic: Natural Language Data Analysis - -This template is perfect for: -- Business intelligence dashboards -- Self-service analytics -- Report generation on demand -- Data exploration without SQL knowledge -- Executive summaries and KPI tracking - -## The Code - -```basic -ADD TOOL "query-data" -ADD TOOL "create-chart" -ADD TOOL "export-data" -ADD TOOL "notify-latest-orders" - -SET ANSWER MODE "sql" - -CLEAR SUGGESTIONS - -ADD SUGGESTION "products" AS "Top products chart" -ADD SUGGESTION "sales" AS "Sales across years" -ADD SUGGESTION "orders" AS "Latest orders" -ADD SUGGESTION "chart" AS "Create a chart" -ADD SUGGESTION "export" AS "Export data" - -SET CONTEXT "talk-to-data" AS "You are a data analyst assistant helping users query and visualize their data. Convert natural language questions into SQL queries and generate charts. Be helpful and suggest visualizations." - -BEGIN TALK -**Talk To Data** - -I can help you analyze your data with natural language queries. - -**Examples:** -• Show me top products in a rainbow colored pie chart -• Sales across years -• Latest orders this month -• Compare revenue by region - -Just ask me anything about your data. -END TALK - -BEGIN SYSTEM PROMPT -You are a data analysis assistant that converts natural language to SQL queries. - -Chart types: -- timeseries: For data over time -- bar: For comparisons -- pie/donut: For proportions -- line: For trends - -When users ask about data: -1. Understand the intent -2. Generate appropriate SQL -3. Suggest relevant visualizations -4. Offer to export if needed - -Always use LOWER() for text comparisons. -Use LIKE with %% for partial matches. -Return clear, actionable insights. -END SYSTEM PROMPT -``` - -## Sample Dialogs - -These conversations show how the Talk to Data template works in real-world scenarios. - -### Dialog 1: Simple Data Query - - - -### Dialog 2: Creating a Visualization - - - -### Dialog 3: Time Series Analysis - - - -### Dialog 4: Latest Orders Notification - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `ADD TOOL` | Register data query and visualization tools | -| `SET ANSWER MODE` | Configure SQL query generation mode | -| `SET CONTEXT` | Define the data analyst role | -| `ADD SUGGESTION` | Create quick query buttons | -| `BEGIN TALK` | Welcome message with examples | -| `BEGIN SYSTEM PROMPT` | Instructions for SQL generation | - -## How It Works - -1. **Natural Language Input**: User asks a question in plain English -2. **Intent Understanding**: AI interprets what data is needed -3. **SQL Generation**: Query is automatically generated -4. **Data Retrieval**: SQL executes against your database -5. **Visualization**: Results are formatted or charted -6. **Insights**: AI provides analysis and recommendations - -## Query Tool: query-data.bas - -```basic -PARAM query AS STRING LIKE "top 10 products by revenue" DESCRIPTION "Natural language data query" -PARAM format AS STRING LIKE "table" DESCRIPTION "Output format: table, chart, export" OPTIONAL - -DESCRIPTION "Query data using natural language and return results" - -' Convert natural language to SQL using AI -sql = LLM "Convert this to SQL for our database: " + query + ". Tables: products, orders, customers, order_items." - -' Execute query -results = SQL sql - -IF UBOUND(results) = 0 THEN - TALK "No data found for your query. Try rephrasing or ask what data is available." - RETURN NULL -END IF - -' Format output based on request -IF format = "chart" OR INSTR(LOWER(query), "chart") > 0 THEN - ' Determine chart type - IF INSTR(LOWER(query), "pie") > 0 THEN - chartType = "pie" - ELSE IF INSTR(LOWER(query), "line") > 0 OR INSTR(LOWER(query), "trend") > 0 THEN - chartType = "line" - ELSE IF INSTR(LOWER(query), "bar") > 0 THEN - chartType = "bar" - ELSE - chartType = "bar" ' Default - END IF - - chart = CREATE CHART chartType, results - TALK chart -ELSE - ' Display as table - TALK TABLE results -END IF - -' Offer insights -IF UBOUND(results) > 5 THEN - insight = LLM "Provide a brief insight about this data: " + TOJSON(results) - TALK "💡 **Insight:** " + insight -END IF - -RETURN results -``` - -## Chart Tool: create-chart.bas - -```basic -PARAM data_query AS STRING LIKE "sales by month" DESCRIPTION "Data to visualize" -PARAM chart_type AS STRING LIKE "bar" DESCRIPTION "Chart type: bar, line, pie, donut, timeseries" -PARAM title AS STRING LIKE "Monthly Sales" DESCRIPTION "Chart title" OPTIONAL -PARAM colors AS STRING LIKE "rainbow" DESCRIPTION "Color scheme: rainbow, blue, green, custom" OPTIONAL - -DESCRIPTION "Create a visualization from data query" - -' Get the data -results = CALL query-data(data_query, "raw") - -IF NOT results THEN - TALK "Could not retrieve data for chart." - RETURN NULL -END IF - -' Set chart options -WITH chartOptions - type = chart_type - title = IIF(title, title, data_query) - colorScheme = IIF(colors, colors, "default") - showLegend = TRUE - showValues = TRUE -END WITH - -' Generate chart -chart = CREATE CHART chartOptions.type, results, chartOptions - -TALK chart - -' Provide chart summary -TALK "📊 Chart shows " + UBOUND(results) + " data points." - -RETURN chart -``` - -## Notify Latest Orders: notify-latest-orders.bas - -```basic -PARAM since AS STRING LIKE "1 hour" DESCRIPTION "Time period for orders" OPTIONAL -PARAM notify AS STRING LIKE "sales@company.com" DESCRIPTION "Email to notify" OPTIONAL - -DESCRIPTION "Get latest orders and optionally send notification" - -IF NOT since THEN - since = "1 hour" -END IF - -' Calculate time filter -cutoff = DATEADD(NOW(), -1, "hours") -IF INSTR(since, "day") > 0 THEN - cutoff = DATEADD(NOW(), -1, "days") -ELSE IF INSTR(since, "week") > 0 THEN - cutoff = DATEADD(NOW(), -7, "days") -END IF - -' Query orders -orders = SQL "SELECT * FROM orders WHERE created_at >= '" + FORMAT(cutoff, "YYYY-MM-DD HH:mm:ss") + "' ORDER BY created_at DESC LIMIT 10" - -IF UBOUND(orders) = 0 THEN - TALK "No new orders in the last " + since + "." - RETURN NULL -END IF - -' Calculate totals -totalRevenue = 0 -FOR EACH order IN orders - totalRevenue = totalRevenue + order.total -NEXT - -' Display orders -TALK "🛒 **Latest Orders** (Last " + since + ")" -TALK "" - -FOR EACH order IN orders - timeAgo = DATEDIFF(NOW(), order.created_at, "minutes") - TALK "**#" + order.order_number + "** - " + timeAgo + " min ago" - TALK "Customer: " + order.customer_name + " | $" + FORMAT(order.total, "#,##0.00") + " | " + order.status - TALK "" -NEXT - -TALK "**Summary:** " + UBOUND(orders) + " orders, $" + FORMAT(totalRevenue, "#,##0.00") + " revenue" - -' Send notification if requested -IF notify THEN - emailBody = "New orders in the last " + since + ":\n\n" - emailBody = emailBody + "Total Orders: " + UBOUND(orders) + "\n" - emailBody = emailBody + "Total Revenue: $" + FORMAT(totalRevenue, "#,##0.00") - - SEND MAIL notify, "Order Update - " + UBOUND(orders) + " new orders", emailBody - TALK "📧 Notification sent to " + notify -END IF - -RETURN orders -``` - -## Setting Up Your Data - -### Connecting to Data Sources - -The Talk to Data template works with various data sources: - -```basic -' CSV files -data = FIND "sales.csv" - -' Excel files -data = FIND "reports.xlsx", "Sheet1" - -' SQL databases -data = SQL "SELECT * FROM products" - -' External APIs -data = GET "https://api.example.com/sales" -``` - -### Schema Configuration - -For best results, configure your data schema: - -```basic -SET CONTEXT "data-schema" AS " -Available tables: -- products: id, name, category, price, stock -- orders: id, customer_id, total, status, created_at -- customers: id, name, email, region -- order_items: order_id, product_id, quantity, price -" -``` - -## Customization Ideas - -### Add Scheduled Reports - -```basic -PARAM reportType AS STRING - -IF reportType = "daily summary" THEN - SET SCHEDULE "0 8 * * *" ' Run at 8 AM daily - - results = CALL query-data("sales summary for yesterday") - SEND MAIL "team@company.com", "Daily Sales Summary", results - - TALK "Daily report sent." -END IF - -IF reportType = "weekly dashboard" THEN - SET SCHEDULE "0 9 * * 1" ' Run at 9 AM on Mondays - - results = CALL query-data("weekly sales by region") - chart = CALL create-chart("weekly sales", "bar") - - SEND MAIL "executives@company.com", "Weekly Dashboard", chart -END IF -``` - -### Add Natural Language Filters - -```basic -' Enhanced query understanding -PARAM question AS STRING - -' Extract time filters -IF INSTR(LOWER(question), "yesterday") > 0 THEN - dateFilter = "date = '" + FORMAT(NOW() - 1, "YYYY-MM-DD") + "'" -ELSE IF INSTR(LOWER(question), "last week") > 0 THEN - dateFilter = "date >= '" + FORMAT(NOW() - 7, "YYYY-MM-DD") + "'" -ELSE IF INSTR(LOWER(question), "this month") > 0 THEN - dateFilter = "MONTH(date) = " + MONTH(NOW()) -END IF - -' Apply to query -sql = sql + " WHERE " + dateFilter -``` - -### Add Comparative Analysis - -```basic -PARAM metric AS STRING LIKE "revenue" -PARAM compare AS STRING LIKE "this month vs last month" - -DESCRIPTION "Compare metrics across time periods" - -' Parse comparison periods -IF INSTR(compare, "month") > 0 THEN - current = SQL "SELECT SUM(" + metric + ") FROM sales WHERE MONTH(date) = " + MONTH(NOW()) - previous = SQL "SELECT SUM(" + metric + ") FROM sales WHERE MONTH(date) = " + (MONTH(NOW()) - 1) - - change = ((current - previous) / previous) * 100 - - TALK "📊 **" + metric + " Comparison**" - TALK "This month: $" + FORMAT(current, "#,##0") - TALK "Last month: $" + FORMAT(previous, "#,##0") - - IF change > 0 THEN - TALK "📈 Change: +" + FORMAT(change, "#,##0.0") + "%" - ELSE - TALK "📉 Change: " + FORMAT(change, "#,##0.0") + "%" - END IF -END IF -``` - -## Best Practices - -1. **Define Your Schema**: Provide clear table and column descriptions in context -2. **Use Examples**: Include example queries in the welcome message -3. **Handle Edge Cases**: Always check for empty results -4. **Provide Insights**: Don't just show data—interpret it -5. **Offer Next Steps**: Suggest related queries or visualizations - -## Related Templates - -- [ai-search.bas](./ai-search.md) - Search documents with AI -- [analytics-dashboard.bas](./analytics-dashboard.md) - System monitoring -- [erp.bas](./erp.md) - Enterprise resource planning - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/templates/whatsapp.md b/docs/src/chapter-06-gbdialog/templates/whatsapp.md deleted file mode 100644 index cd0f93de..00000000 --- a/docs/src/chapter-06-gbdialog/templates/whatsapp.md +++ /dev/null @@ -1,469 +0,0 @@ -# WhatsApp Template - -The WhatsApp template provides specialized tools for WhatsApp Business API integration, including template message sending, task creation, and WhatsApp-specific features. - -## Topic: WhatsApp Business Integration - -This template is perfect for: -- WhatsApp Business API integration -- Template message campaigns -- WhatsApp-based customer service -- Automated WhatsApp notifications -- Task management via WhatsApp - -## The Code: send.bas - -```basic -PARAM phone AS PHONE LIKE "122233333333" DESCRIPTION "WhatsApp phone number with country code" -PARAM template AS STRING LIKE "newsletter-zap.txt" DESCRIPTION "Template file name to send" -PARAM variables AS OBJECT LIKE "{name: 'John'}" DESCRIPTION "Template variables for personalization" OPTIONAL - -DESCRIPTION "Send a WhatsApp template message to a phone number" - -SEND TEMPLATE TO phone, template, variables - -WITH log - timestamp = NOW() - phoneNumber = phone - templateFile = template - status = "sent" -END WITH - -SAVE "whatsapp_log.csv", log - -TALK "WhatsApp message sent to " + phone - -RETURN phone -``` - -## Sample Dialogs - -These conversations show how the WhatsApp template works in real-world scenarios. - -### Dialog 1: Sending a Template Message - - - -### Dialog 2: Creating a Task via WhatsApp - - - -### Dialog 3: Personalized Template with Variables - - - -## Keywords Used - -| Keyword | Purpose | -|---------|---------| -| `PARAM` | Define input parameters for the tool | -| `DESCRIPTION` | Tool description for AI understanding | -| `SEND TEMPLATE TO` | Send WhatsApp template message | -| `WITH/END WITH` | Create structured log object | -| `SAVE` | Log message to CSV file | -| `TALK` | Confirm action to user | -| `RETURN` | Return result | - -## Template Structure - -``` -whatsapp.gbai/ -├── whatsapp.gbdialog/ -│ ├── send.bas # Send template messages -│ └── create-task.bas # Create tasks via WhatsApp -├── whatsapp.gbkb/ -│ ├── articles/ # Knowledge base articles -│ │ └── newsletter-zap.txt -│ └── images/ # Media files -└── whatsapp.gbot/ - └── config.csv # Bot configuration -``` - -## Create Task Tool: create-task.bas - -```basic -PARAM title AS STRING LIKE "Call client" DESCRIPTION "Task title" -PARAM due_date AS DATE LIKE "2025-01-20" DESCRIPTION "Due date" OPTIONAL -PARAM priority AS STRING LIKE "medium" DESCRIPTION "Priority: high, medium, low" OPTIONAL - -DESCRIPTION "Create a task from WhatsApp conversation" - -IF NOT due_date THEN - due_date = NOW() -END IF - -IF NOT priority THEN - priority = "medium" -END IF - -WITH task - id = "TASK-" + FORMAT(RANDOM(10000, 99999)) - taskTitle = title - dueDate = due_date - taskPriority = priority - createdBy = FROM - createdAt = NOW() - status = "pending" -END WITH - -SAVE "tasks.csv", task - -CREATE TASK title, priority, FROM - -TALK "✅ Task created: " + title -TALK "📅 Due: " + FORMAT(due_date, "MMM DD, YYYY") -TALK "⚡ Priority: " + priority - -RETURN task.id -``` - -## WhatsApp Template Messages - -### Understanding Template Messages - -WhatsApp Business API requires pre-approved templates for initiating conversations. Templates can include: - -- **Text**: Plain text with optional variables -- **Media**: Images, documents, videos -- **Buttons**: Quick reply or call-to-action buttons -- **Headers**: Text, image, document, or video headers - -### Template File Format - -Create templates in the `.gbkb/articles/` folder: - -``` -newsletter-zap.txt ---- -Hello {{1}}! - -Here's your weekly newsletter: - -📰 Top Stories This Week -{{2}} - -🎯 Don't miss our special offer! -{{3}} - -Reply STOP to unsubscribe. -``` - -### Variables in Templates - -Variables are placeholders replaced with actual values: - -| Variable | Description | Example | -|----------|-------------|---------| -| `{{1}}` | First parameter | Customer name | -| `{{2}}` | Second parameter | Content body | -| `{{3}}` | Third parameter | Offer details | - -## Customization Ideas - -### Add Bulk Messaging - -```basic -PARAM template AS STRING DESCRIPTION "Template to send" -PARAM contacts_file AS STRING LIKE "contacts.csv" DESCRIPTION "CSV file with contacts" - -DESCRIPTION "Send template to multiple contacts" - -contacts = FIND contacts_file - -sent = 0 -failed = 0 - -FOR EACH contact IN contacts - variables = { - "name": contact.name, - "company": contact.company - } - - result = SEND TEMPLATE TO contact.phone, template, variables - - IF result THEN - sent = sent + 1 - ELSE - failed = failed + 1 - END IF - - WAIT 2 ' Rate limiting -NEXT - -TALK "📊 Bulk send complete!" -TALK "✅ Sent: " + sent -TALK "❌ Failed: " + failed -``` - -### Add Message Status Tracking - -```basic -' After sending -message_id = SEND TEMPLATE TO phone, template, variables - -' Store for tracking -WITH messageRecord - id = message_id - phone = phone - template = template - status = "sent" - sentAt = NOW() -END WITH - -SAVE "message_status.csv", messageRecord - -' Webhook handler for status updates -ON WEBHOOK "whatsapp_status" - status = webhook_data.status - message_id = webhook_data.message_id - - UPDATE "message_status.csv" SET status = status WHERE id = message_id - - IF status = "delivered" THEN - TALK "✅ Message " + message_id + " delivered" - ELSE IF status = "read" THEN - TALK "👀 Message " + message_id + " read" - ELSE IF status = "failed" THEN - TALK "❌ Message " + message_id + " failed" - END IF -END ON -``` - -### Add Interactive Buttons - -```basic -PARAM phone AS PHONE DESCRIPTION "Recipient phone number" - -DESCRIPTION "Send message with quick reply buttons" - -template_with_buttons = { - "template": "order_confirmation", - "buttons": [ - {"type": "quick_reply", "text": "Track Order"}, - {"type": "quick_reply", "text": "Contact Support"}, - {"type": "quick_reply", "text": "View Details"} - ] -} - -SEND TEMPLATE TO phone, template_with_buttons - -TALK "Message with buttons sent to " + phone -``` - -### Add Media Messages - -```basic -PARAM phone AS PHONE DESCRIPTION "Recipient phone number" -PARAM image_url AS STRING DESCRIPTION "URL of image to send" -PARAM caption AS STRING DESCRIPTION "Image caption" OPTIONAL - -DESCRIPTION "Send WhatsApp message with image" - -' Send image with caption -SEND MEDIA TO phone, image_url, caption - -WITH log - timestamp = NOW() - phone = phone - mediaType = "image" - mediaUrl = image_url - caption = caption - status = "sent" -END WITH - -SAVE "whatsapp_media_log.csv", log - -TALK "📷 Image sent to " + phone -``` - -## WhatsApp Business API Best Practices - -### Message Timing - -1. **Session Messages**: Free-form messages within 24-hour window after user message -2. **Template Messages**: Pre-approved templates for initiating conversations -3. **Rate Limits**: Respect WhatsApp's messaging limits - -### Template Approval - -1. Submit templates via WhatsApp Business Manager -2. Wait for approval (usually 24-48 hours) -3. Use approved templates only -4. Follow content guidelines (no promotional content in utility templates) - -### Phone Number Format - -Always use international format without `+` or spaces: -- ✅ `5511999999999` (Brazil) -- ✅ `14155551234` (USA) -- ❌ `+55 11 99999-9999` -- ❌ `(11) 99999-9999` - -### Compliance - -1. **Opt-in Required**: Only message users who have opted in -2. **Opt-out Handling**: Honor STOP/unsubscribe requests immediately -3. **Business Verification**: Complete WhatsApp business verification -4. **Quality Rating**: Maintain high quality rating to avoid restrictions - -## Logging Structure - -The `whatsapp_log.csv` tracks all messages: - -| Column | Description | -|--------|-------------| -| timestamp | When message was sent | -| phoneNumber | Recipient phone number | -| templateFile | Template used | -| variables | Personalization variables | -| status | sent/delivered/read/failed | -| messageId | WhatsApp message ID | - -## Error Handling - -```basic -result = SEND TEMPLATE TO phone, template, variables - -IF NOT result THEN - ' Log the failure - WITH errorLog - timestamp = NOW() - phone = phone - template = template - error = "Send failed" - END WITH - - SAVE "whatsapp_errors.csv", errorLog - - TALK "❌ Failed to send message to " + phone - TALK "Please verify the phone number and try again." - RETURN NULL -END IF -``` - -## Related Templates - -- [broadcast.bas](./broadcast.md) - Mass messaging to contact lists -- [store.bas](./store.md) - E-commerce with WhatsApp notifications -- [bank.bas](./bank.md) - Banking notifications via WhatsApp - ---- - - \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/tools-data-sync.md b/docs/src/chapter-06-gbdialog/tools-data-sync.md deleted file mode 100644 index d7163a47..00000000 --- a/docs/src/chapter-06-gbdialog/tools-data-sync.md +++ /dev/null @@ -1,1028 +0,0 @@ -# Data Sync Tools - -This document provides a collection of specialized data synchronization tools. Instead of one monolithic sync system, these modular tools can be combined as needed. - -## Overview - -Data synchronization is split into focused, reusable tools: - -| Tool | Purpose | File | -|------|---------|------| -| `crm-sync.bas` | CRM to/from internal database | Bidirectional customer data | -| `erp-sync.bas` | ERP system integration | Orders, inventory, accounting | -| `inventory-sync.bas` | Real-time inventory updates | Stock levels across systems | -| `user-sync.bas` | User/employee directory sync | HR systems, Active Directory | -| `conflict-resolver.bas` | Handle sync conflicts | Automated or manual resolution | -| `sync-monitor.bas` | Monitor sync health | Alerts and dashboards | - -## Tool 1: CRM Sync - -Bidirectional synchronization with CRM systems (Salesforce, HubSpot, etc.). - -```basic -' crm-sync.bas -' Bidirectional CRM synchronization tool - -WEBHOOK "crm-inbound" - -event = body.event -record_type = body.type -record_id = body.id -data = body.data -source_timestamp = body.timestamp - -' Validate webhook signature -signature = headers.x_webhook_signature -secret = GET BOT MEMORY "crm_webhook_secret" -IF NOT VERIFY_SIGNATURE(body, signature, secret) THEN - WITH result = NEW OBJECT - .status = 401 - .error = "Invalid signature" - END WITH - EXIT -END IF - -' Log incoming sync event -WITH sync_event = NEW OBJECT - .direction = "inbound" - .source = "crm" - .event = event - .record_type = record_type - .record_id = record_id - .timestamp = source_timestamp - .received_at = NOW() -END WITH -INSERT "sync_events", sync_event - -' Check for conflicts before processing -existing = FIND "local_data", "external_id=" + record_id -IF existing.updated_at > source_timestamp THEN - ' Local data is newer - create conflict record - WITH conflict = NEW OBJECT - .record_id = record_id - .local_timestamp = existing.updated_at - .remote_timestamp = source_timestamp - .local_data = existing - .remote_data = data - .status = "pending" - .created_at = NOW() - END WITH - INSERT "sync_conflicts", conflict - - WITH result = NEW OBJECT - .status = "conflict" - .conflict_id = conflict.id - END WITH - EXIT -END IF - -' Transform CRM data to local format -SELECT CASE record_type - CASE "contact" - WITH local_record = NEW OBJECT - .external_id = record_id - .external_source = "crm" - .first_name = data.firstName - .last_name = data.lastName - .email = data.email - .phone = data.phone - .company = data.account.name - .title = data.title - .source = data.leadSource - .status = data.status - .updated_at = NOW() - .synced_at = NOW() - END WITH - table_name = "contacts" - - CASE "account" - WITH local_record = NEW OBJECT - .external_id = record_id - .external_source = "crm" - .company_name = data.name - .industry = data.industry - .website = data.website - .annual_revenue = data.annualRevenue - .employee_count = data.numberOfEmployees - .billing_address = data.billingAddress - .updated_at = NOW() - .synced_at = NOW() - END WITH - table_name = "accounts" - - CASE "opportunity" - WITH local_record = NEW OBJECT - .external_id = record_id - .external_source = "crm" - .name = data.name - .account_id = data.accountId - .amount = data.amount - .stage = data.stageName - .probability = data.probability - .close_date = data.closeDate - .updated_at = NOW() - .synced_at = NOW() - END WITH - table_name = "opportunities" - - CASE ELSE - WITH result = NEW OBJECT - .status = 400 - .error = "Unknown record type: " + record_type - END WITH - EXIT -END SELECT - -' Apply changes based on event type -SELECT CASE event - CASE "created" - INSERT table_name, local_record - - CASE "updated" - UPDATE table_name, "external_id=" + record_id, local_record - - CASE "deleted" - WITH soft_delete = NEW OBJECT - .deleted_at = NOW() - .deleted_from = "crm" - END WITH - UPDATE table_name, "external_id=" + record_id, soft_delete -END SELECT - -' Update sync status -WITH sync_status = NEW OBJECT - .record_id = record_id - .record_type = record_type - .last_sync = NOW() - .sync_direction = "inbound" - .status = "success" -END WITH -SAVE "sync_status", record_type + "_" + record_id, sync_status - -WITH result = NEW OBJECT - .status = "synced" - .record_id = record_id - .direction = "inbound" -END WITH -``` - -### CRM Outbound Sync - -```basic -' crm-outbound.bas -' Push local changes to CRM - -ON "contacts", "INSERT,UPDATE" - -record = trigger.new_data -old_record = trigger.old_data - -' Skip if this update came from CRM (prevent loops) -IF record.external_source = "crm" AND record.synced_at = record.updated_at THEN - EXIT -END IF - -' Check if record exists in CRM -IF record.external_id = "" THEN - ' New record - create in CRM - operation = "create" - endpoint = "/api/contacts" -ELSE - ' Existing record - update in CRM - operation = "update" - endpoint = "/api/contacts/" + record.external_id -END IF - -' Transform to CRM format -WITH crm_data = NEW OBJECT - .firstName = record.first_name - .lastName = record.last_name - .email = record.email - .phone = record.phone - .title = record.title - .leadSource = record.source -END WITH - -' Send to CRM -crm_api_key = GET BOT MEMORY "crm_api_key" -SET HEADER "Authorization", "Bearer " + crm_api_key -SET HEADER "Content-Type", "application/json" - -IF operation = "create" THEN - response = POST "https://api.crm.com" + endpoint, crm_data - - ' Store external ID - WITH id_update = NEW OBJECT - .external_id = response.id - .external_source = "crm" - .synced_at = NOW() - END WITH - UPDATE "contacts", "id=" + record.id, id_update -ELSE - response = PUT "https://api.crm.com" + endpoint, crm_data - - WITH sync_update = NEW OBJECT - .synced_at = NOW() - END WITH - UPDATE "contacts", "id=" + record.id, sync_update -END IF - -' Log outbound sync -WITH sync_event = NEW OBJECT - .direction = "outbound" - .destination = "crm" - .event = operation - .record_type = "contact" - .record_id = record.id - .external_id = record.external_id - .timestamp = NOW() - .response_status = response.status -END WITH -INSERT "sync_events", sync_event -``` - -## Tool 2: ERP Sync - -Integration with ERP systems for orders, inventory, and accounting. - -```basic -' erp-sync.bas -' ERP system synchronization tool - -WEBHOOK "erp-webhook" - -event_type = body.eventType -entity = body.entity -entity_id = body.entityId -payload = body.payload - -' Authenticate request -api_key = headers.x_api_key -expected_key = GET BOT MEMORY "erp_webhook_key" -IF api_key <> expected_key THEN - WITH result = NEW OBJECT - .status = 401 - .error = "Unauthorized" - END WITH - EXIT -END IF - -' Route to appropriate handler -SELECT CASE entity - CASE "salesOrder" - CALL process_sales_order(event_type, entity_id, payload) - - CASE "purchaseOrder" - CALL process_purchase_order(event_type, entity_id, payload) - - CASE "invoice" - CALL process_invoice(event_type, entity_id, payload) - - CASE "inventory" - CALL process_inventory_update(entity_id, payload) - - CASE "shipment" - CALL process_shipment(event_type, entity_id, payload) -END SELECT - -WITH result = NEW OBJECT - .status = "processed" - .entity = entity - .entity_id = entity_id -END WITH - -' --- Sub-procedures --- - -SUB process_sales_order(event_type, order_id, data) - WITH order = NEW OBJECT - .erp_order_id = order_id - .order_number = data.orderNumber - .customer_id = data.customerId - .order_date = data.orderDate - .ship_date = data.requestedShipDate - .status = data.status - .subtotal = data.subtotal - .tax = data.taxAmount - .shipping = data.shippingAmount - .total = data.total - .currency = data.currency - .updated_at = NOW() - END WITH - - IF event_type = "created" THEN - INSERT "orders", order - - ' Create line items - FOR EACH item IN data.lineItems - WITH line = NEW OBJECT - .order_id = order_id - .sku = item.sku - .description = item.description - .quantity = item.quantity - .unit_price = item.unitPrice - .discount = item.discount - .total = item.lineTotal - END WITH - INSERT "order_lines", line - NEXT item - - ' Notify sales team - SEND MAIL "sales@company.com", "New Order: " + data.orderNumber, "Order total: $" + data.total - - ELSE IF event_type = "updated" THEN - UPDATE "orders", "erp_order_id=" + order_id, order - - ' Check for status changes - old_order = FIND "orders", "erp_order_id=" + order_id - IF old_order.status <> data.status THEN - ' Notify customer of status change - customer = FIND "customers", "id=" + data.customerId - SEND MAIL customer.email, "Order Update: " + data.orderNumber, "Your order status is now: " + data.status - END IF - END IF -END SUB - -SUB process_inventory_update(sku, data) - WITH inventory = NEW OBJECT - .sku = sku - .quantity_on_hand = data.qtyOnHand - .quantity_available = data.qtyAvailable - .quantity_reserved = data.qtyReserved - .quantity_on_order = data.qtyOnOrder - .warehouse = data.warehouse - .bin_location = data.binLocation - .last_count_date = data.lastCountDate - .updated_at = NOW() - END WITH - - SAVE "inventory", sku, inventory - - ' Check for low stock alert - product = FIND "products", "sku=" + sku - IF data.qtyAvailable < product.reorder_point THEN - WITH alert = NEW OBJECT - .sku = sku - .product_name = product.name - .current_qty = data.qtyAvailable - .reorder_point = product.reorder_point - .reorder_qty = product.reorder_quantity - .created_at = NOW() - END WITH - INSERT "stock_alerts", alert - - SEND MAIL "purchasing@company.com", "Low Stock Alert: " + sku, "Product " + product.name + " is below reorder point. Current: " + data.qtyAvailable + ", Reorder at: " + product.reorder_point - END IF -END SUB - -SUB process_shipment(event_type, shipment_id, data) - WITH shipment = NEW OBJECT - .erp_shipment_id = shipment_id - .order_id = data.orderId - .carrier = data.carrier - .tracking_number = data.trackingNumber - .ship_date = data.shipDate - .estimated_delivery = data.estimatedDelivery - .status = data.status - .updated_at = NOW() - END WITH - - IF event_type = "created" THEN - INSERT "shipments", shipment - - ' Notify customer - order = FIND "orders", "erp_order_id=" + data.orderId - customer = FIND "customers", "id=" + order.customer_id - - tracking_url = "https://track.carrier.com/" + data.trackingNumber - - SEND MAIL customer.email, "Your Order Has Shipped!", "Good news! Your order " + order.order_number + " has shipped.\n\nTracking: " + data.trackingNumber + "\nCarrier: " + data.carrier + "\nEstimated Delivery: " + data.estimatedDelivery + "\n\nTrack your package: " + tracking_url - - ELSE IF event_type = "updated" THEN - UPDATE "shipments", "erp_shipment_id=" + shipment_id, shipment - - IF data.status = "delivered" THEN - ' Update order status - WITH order_update = NEW OBJECT - .status = "delivered" - .delivered_at = NOW() - END WITH - UPDATE "orders", "erp_order_id=" + data.orderId, order_update - END IF - END IF -END SUB -``` - -## Tool 3: Inventory Sync - -Real-time inventory synchronization across multiple systems. - -```basic -' inventory-sync.bas -' Real-time inventory synchronization - -WEBHOOK "inventory-update" - -source = body.source -sku = body.sku -warehouse = body.warehouse -adjustment_type = body.type -quantity = body.quantity -reason = body.reason -reference = body.reference - -' Get current inventory -current = FIND "inventory", "sku=" + sku + " AND warehouse=" + warehouse - -' Calculate new quantity based on adjustment type -SELECT CASE adjustment_type - CASE "receipt" - new_qty = current.quantity_on_hand + quantity - - CASE "shipment" - new_qty = current.quantity_on_hand - quantity - - CASE "adjustment" - new_qty = quantity - - CASE "transfer_out" - new_qty = current.quantity_on_hand - quantity - - CASE "transfer_in" - new_qty = current.quantity_on_hand + quantity - - CASE "count" - new_qty = quantity -END SELECT - -' Validate quantity -IF new_qty < 0 THEN - WITH result = NEW OBJECT - .status = 400 - .error = "Inventory cannot be negative" - .current_qty = current.quantity_on_hand - .attempted_qty = new_qty - END WITH - EXIT -END IF - -' Update local inventory -WITH inv_update = NEW OBJECT - .quantity_on_hand = new_qty - .updated_at = NOW() - .last_adjustment_type = adjustment_type - .last_adjustment_source = source -END WITH -UPDATE "inventory", "sku=" + sku + " AND warehouse=" + warehouse, inv_update - -' Log the transaction -WITH transaction = NEW OBJECT - .sku = sku - .warehouse = warehouse - .adjustment_type = adjustment_type - .quantity_before = current.quantity_on_hand - .quantity_change = quantity - .quantity_after = new_qty - .reason = reason - .reference = reference - .source = source - .created_at = NOW() -END WITH -INSERT "inventory_transactions", transaction - -' Sync to other systems based on source -systems_to_sync = ["erp", "ecommerce", "pos", "wms"] - -FOR EACH system IN systems_to_sync - IF system <> source THEN - CALL sync_inventory_to_system(system, sku, warehouse, new_qty) - END IF -NEXT system - -' Check for alerts -product = FIND "products", "sku=" + sku -IF new_qty <= product.reorder_point AND current.quantity_on_hand > product.reorder_point THEN - ' Just crossed below reorder point - WITH alert_msg = NEW OBJECT - .text = "⚠️ *Low Stock Alert*\n\nSKU: " + sku + "\nProduct: " + product.name + "\nWarehouse: " + warehouse + "\nCurrent Qty: " + new_qty + "\nReorder Point: " + product.reorder_point - END WITH - POST "https://hooks.slack.com/services/xxx", alert_msg -END IF - -IF new_qty = 0 THEN - ' Out of stock - WITH alert_msg = NEW OBJECT - .text = "🚨 *Out of Stock*\n\nSKU: " + sku + "\nProduct: " + product.name + "\nWarehouse: " + warehouse - END WITH - POST "https://hooks.slack.com/services/xxx", alert_msg - - ' Disable on e-commerce - CALL disable_product_ecommerce(sku) -END IF - -WITH result = NEW OBJECT - .status = "synced" - .sku = sku - .warehouse = warehouse - .new_quantity = new_qty -END WITH - -' --- Helper procedures --- - -SUB sync_inventory_to_system(system, sku, warehouse, qty) - SELECT CASE system - CASE "erp" - SET HEADER "Authorization", "Bearer " + GET BOT MEMORY "erp_api_key" - WITH erp_payload = NEW OBJECT - .sku = sku - .warehouseCode = warehouse - .qtyOnHand = qty - END WITH - PUT "https://erp.company.com/api/inventory/" + sku, erp_payload - - CASE "ecommerce" - SET HEADER "Authorization", "Bearer " + GET BOT MEMORY "ecom_api_key" - WITH ecom_payload = NEW OBJECT - .inventory_quantity = qty - END WITH - PUT "https://api.shopify.com/products/" + sku + "/inventory", ecom_payload - - CASE "pos" - SET HEADER "X-API-Key", GET BOT MEMORY "pos_api_key" - WITH pos_payload = NEW OBJECT - .item_id = sku - .quantity = qty - .location_id = warehouse - END WITH - POST "https://api.pos.com/inventory/update", pos_payload - - CASE "wms" - SET HEADER "Authorization", "Bearer " + GET BOT MEMORY "wms_api_key" - WITH wms_payload = NEW OBJECT - .sku = sku - .location = warehouse - .qty = qty - END WITH - PUT "https://wms.company.com/api/inventory", wms_payload - END SELECT - - ' Log sync - WITH sync_log = NEW OBJECT - .system = system - .sku = sku - .warehouse = warehouse - .quantity = qty - .synced_at = NOW() - END WITH - INSERT "inventory_sync_log", sync_log -END SUB - -SUB disable_product_ecommerce(sku) - SET HEADER "Authorization", "Bearer " + GET BOT MEMORY "ecom_api_key" - WITH update_payload = NEW OBJECT - .available = FALSE - .inventory_policy = "deny" - END WITH - PUT "https://api.shopify.com/products/" + sku, update_payload -END SUB -``` - -## Tool 4: Conflict Resolver - -Handle and resolve synchronization conflicts. - -```basic -' conflict-resolver.bas -' Automated and manual sync conflict resolution - -' Scheduled job to process conflicts -SET SCHEDULE "resolve-conflicts", "*/15 * * * *" - -' Get pending conflicts -conflicts = FIND "sync_conflicts", "status=pending ORDER BY created_at ASC LIMIT 50" - -FOR EACH conflict IN conflicts - resolution = CALL attempt_auto_resolve(conflict) - - IF resolution.resolved THEN - ' Apply the resolution - CALL apply_resolution(conflict, resolution) - - ' Update conflict status - WITH status_update = NEW OBJECT - .status = "resolved" - .resolution_type = "automatic" - .resolution_details = resolution.details - .resolved_at = NOW() - END WITH - UPDATE "sync_conflicts", "id=" + conflict.id, status_update - ELSE - ' Escalate for manual review - IF conflict.escalated_at = "" THEN - CALL escalate_conflict(conflict) - - WITH escalate_update = NEW OBJECT - .status = "escalated" - .escalated_at = NOW() - END WITH - UPDATE "sync_conflicts", "id=" + conflict.id, escalate_update - END IF - END IF -NEXT conflict - -' --- Functions --- - -FUNCTION attempt_auto_resolve(conflict) - WITH result = NEW OBJECT - .resolved = FALSE - .winner = "" - .details = "" - END WITH - - ' Rule 1: Timestamp-based (most recent wins) - time_diff = DATEDIFF(conflict.local_timestamp, conflict.remote_timestamp, "second") - IF ABS(time_diff) > 60 THEN - ' Clear winner by timestamp - IF conflict.local_timestamp > conflict.remote_timestamp THEN - result.resolved = TRUE - result.winner = "local" - result.details = "Local data is " + ABS(time_diff) + " seconds newer" - ELSE - result.resolved = TRUE - result.winner = "remote" - result.details = "Remote data is " + ABS(time_diff) + " seconds newer" - END IF - RETURN result - END IF - - ' Rule 2: Field-level merge (non-conflicting changes) - local_changes = CALL get_changed_fields(conflict.original_data, conflict.local_data) - remote_changes = CALL get_changed_fields(conflict.original_data, conflict.remote_data) - - ' Check if changes affect different fields - overlap = FALSE - FOR EACH field IN local_changes - IF INSTR(remote_changes, field) > 0 THEN - overlap = TRUE - EXIT FOR - END IF - NEXT field - - IF NOT overlap THEN - ' Can merge without conflict - result.resolved = TRUE - result.winner = "merge" - result.details = "Field-level merge: local changed [" + local_changes + "], remote changed [" + remote_changes + "]" - RETURN result - END IF - - ' Rule 3: Source priority - priority_source = GET BOT MEMORY "sync_priority_source" - IF priority_source <> "" THEN - IF conflict.source = priority_source THEN - result.resolved = TRUE - result.winner = "remote" - result.details = "Priority source rule: " + priority_source + " wins" - ELSE - result.resolved = TRUE - result.winner = "local" - result.details = "Non-priority source: local wins" - END IF - RETURN result - END IF - - ' Cannot auto-resolve - result.details = "Manual resolution required: same fields modified within 60 seconds" - RETURN result -END FUNCTION - -SUB apply_resolution(conflict, resolution) - SELECT CASE resolution.winner - CASE "local" - ' Push local data to remote - CALL sync_to_remote(conflict.record_type, conflict.record_id, conflict.local_data) - - CASE "remote" - ' Apply remote data locally - UPDATE conflict.record_type, "id=" + conflict.record_id, conflict.remote_data - - CASE "merge" - ' Merge both changes - merged_data = CALL merge_records(conflict.original_data, conflict.local_data, conflict.remote_data) - UPDATE conflict.record_type, "id=" + conflict.record_id, merged_data - CALL sync_to_remote(conflict.record_type, conflict.record_id, merged_data) - END SELECT -END SUB - -SUB escalate_conflict(conflict) - ' Send notification to data admin - WITH notification = NEW OBJECT - .conflict_id = conflict.id - .record_type = conflict.record_type - .record_id = conflict.record_id - .local_timestamp = conflict.local_timestamp - .remote_timestamp = conflict.remote_timestamp - .local_summary = CALL summarize_data(conflict.local_data) - .remote_summary = CALL summarize_data(conflict.remote_data) - END WITH - - email_body = "A sync conflict requires manual resolution.\n\n" - email_body = email_body + "Record: " + conflict.record_type + " #" + conflict.record_id + "\n" - email_body = email_body + "Local changes: " + notification.local_summary + "\n" - email_body = email_body + "Remote changes: " + notification.remote_summary + "\n\n" - email_body = email_body + "Please review at: https://admin.company.com/conflicts/" + conflict.id - - SEND MAIL "data-admin@company.com", "Sync Conflict: " + conflict.record_type + " #" + conflict.record_id, email_body - - ' Also post to Slack - WITH slack_msg = NEW OBJECT - .text = "⚠️ *Sync Conflict Requires Review*\n\nRecord: " + conflict.record_type + " #" + conflict.record_id + "\n" - END WITH - POST "https://hooks.slack.com/services/xxx", slack_msg -END SUB -``` - -## Tool 5: Sync Monitor - -Monitor sync health and generate alerts. - -```basic -' sync-monitor.bas -' Data sync health monitoring - -SET SCHEDULE "sync-health-check", "*/5 * * * *" - -' Check sync lag for each integration -integrations = ["crm", "erp", "ecommerce", "wms"] - -WITH health_report = NEW OBJECT - .timestamp = NOW() - .status = "healthy" - .issues = [] -END WITH - -FOR EACH integration IN integrations - ' Get latest sync event - latest = FIND "sync_events", "source=" + integration + " OR destination=" + integration + " ORDER BY timestamp DESC LIMIT 1" - - lag_minutes = DATEDIFF(latest.timestamp, NOW(), "minute") - - WITH integration_status = NEW OBJECT - .name = integration - .last_sync = latest.timestamp - .lag_minutes = lag_minutes - .status = "ok" - END WITH - - ' Check for concerning lag - max_lag = GET BOT MEMORY "max_sync_lag_" + integration - IF max_lag = "" THEN max_lag = 30 END IF - - IF lag_minutes > max_lag THEN - integration_status.status = "warning" - health_report.status = "degraded" - - WITH issue = NEW OBJECT - .integration = integration - .type = "sync_lag" - .message = integration + " sync lag: " + lag_minutes + " minutes (max: " + max_lag + ")" - END WITH - health_report.issues.ADD(issue) - END IF - - ' Check for recent errors - recent_errors = FIND "sync_events", "source=" + integration + " AND status='error' AND timestamp > DATEADD(NOW(), -1, 'hour')" - error_count = UBOUND(recent_errors) - - IF error_count > 5 THEN - integration_status.status = "error" - health_report.status = "unhealthy" - - WITH issue = NEW OBJECT - .integration = integration - .type = "high_error_rate" - .message = integration + " has " + error_count + " errors in the last hour" - END WITH - health_report.issues.ADD(issue) - END IF - - integration_status.error_count_1h = error_count -NEXT integration - -' Check pending conflicts -pending_conflicts = AGGREGATE "COUNT", "sync_conflicts", "status='pending'" -escalated_conflicts = AGGREGATE "COUNT", "sync_conflicts", "status='escalated'" - -IF pending_conflicts > 100 THEN - health_report.status = "degraded" - WITH issue = NEW OBJECT - .type = "pending_conflicts" - .message = pending_conflicts + " sync conflicts pending resolution" - END WITH - health_report.issues.ADD(issue) -END IF - -' Check queue depth -queue_depth = AGGREGATE "COUNT", "sync_queue", "status='pending'" -IF queue_depth > 1000 THEN - health_report.status = "degraded" - WITH issue = NEW OBJECT - .type = "queue_backlog" - .message = "Sync queue backlog: " + queue_depth + " items" - END WITH - health_report.issues.ADD(issue) -END IF - -' Store health report -INSERT "sync_health_reports", health_report - -' Alert if unhealthy -IF health_report.status = "unhealthy" THEN - alert_message = "🚨 *Data Sync Unhealthy*\n\n" - FOR EACH issue IN health_report.issues - alert_message = alert_message + "• " + issue.message + "\n" - NEXT issue - - ' Slack alert - WITH slack_alert = NEW OBJECT - .text = alert_message - .channel = "#ops-alerts" - END WITH - POST "https://hooks.slack.com/services/xxx", slack_alert - - ' PagerDuty for critical - WITH pagerduty = NEW OBJECT - .routing_key = GET BOT MEMORY "pagerduty_key" - .event_action = "trigger" - .payload.summary = "Data sync system unhealthy" - .payload.severity = "critical" - .payload.source = "sync-monitor" - END WITH - POST "https://events.pagerduty.com/v2/enqueue", pagerduty - -ELSE IF health_report.status = "degraded" THEN - alert_message = "⚠️ *Data Sync Degraded*\n\n" - FOR EACH issue IN health_report.issues - alert_message = alert_message + "• " + issue.message + "\n" - NEXT issue - - WITH slack_alert = NEW OBJECT - .text = alert_message - .channel = "#ops-alerts" - END WITH - POST "https://hooks.slack.com/services/xxx", slack_alert -END IF - -' Generate dashboard data -WITH dashboard = NEW OBJECT - .timestamp = NOW() - .overall_status = health_report.status - .integrations = integration_statuses - .pending_conflicts = pending_conflicts - .escalated_conflicts = escalated_conflicts - .queue_depth = queue_depth - .events_last_hour = AGGREGATE "COUNT", "sync_events", "timestamp > DATEADD(NOW(), -1, 'hour')" - .errors_last_hour = AGGREGATE "COUNT", "sync_events", "status='error' AND timestamp > DATEADD(NOW(), -1, 'hour')" -END WITH - -SAVE "sync_dashboard", "current", dashboard -``` - -## Tool 6: Bulk Sync - -Initial data load and bulk synchronization. - -```basic -' bulk-sync.bas -' Bulk data synchronization tool - -WEBHOOK "bulk-sync" - -source_system = body.source -target_system = body.target -entity_type = body.entity -batch_size = body.batch_size -offset = body.offset - -IF batch_size = "" THEN batch_size = 100 END IF -IF offset = "" THEN offset = 0 END IF - -' Create sync job -job_id = "SYNC-" + FORMAT(NOW(), "YYYYMMDDHHmmss") - -WITH job = NEW OBJECT - .id = job_id - .source = source_system - .target = target_system - .entity_type = entity_type - .status = "running" - .total_records = 0 - .processed_records = 0 - .error_count = 0 - .started_at = NOW() -END WITH -INSERT "sync_jobs", job - -' Fetch data from source -SET HEADER "Authorization", "Bearer " + GET BOT MEMORY source_system + "_api_key" - -has_more = TRUE -total_processed = 0 -total_errors = 0 - -WHILE has_more - source_url = CALL build_source_url(source_system, entity_type, batch_size, offset) - response = GET source_url - - records = response.data - has_more = response.has_more - - IF UBOUND(records) = 0 THEN - has_more = FALSE - ELSE - FOR EACH record IN records - ' Transform record - transformed = CALL transform_record(record, source_system, target_system, entity_type) - - ' Send to target - success = CALL send_to_target(target_system, entity_type, transformed) - - IF success THEN - total_processed = total_processed + 1 - ELSE - total_errors = total_errors + 1 - - ' Log error - WITH error_log = NEW OBJECT - .job_id = job_id - .record_id = record.id - .error = "Failed to sync to " + target_system - .created_at = NOW() - END WITH - INSERT "sync_errors", error_log - END IF - - ' Update progress every 100 records - IF (total_processed + total_errors) MOD 100 = 0 THEN - WITH progress = NEW OBJECT - .processed_records = total_processed - .error_count = total_errors - .updated_at = NOW() - END WITH - UPDATE "sync_jobs", "id=" + job_id, progress - END IF - NEXT record - - offset = offset + batch_size - END IF -WEND - -' Finalize job -WITH final_update = NEW OBJECT - .status = "completed" - .total_records = total_processed + total_errors - .processed_records = total_processed - .error_count = total_errors - .completed_at = NOW() -END WITH -UPDATE "sync_jobs", "id=" + job_id, final_update - -' Send completion notification -completion_msg = "Bulk sync completed\n\n" -completion_msg = completion_msg + "Job ID: " + job_id + "\n" -completion_msg = completion_msg + "Source: " + source_system + "\n" -completion_msg = completion_msg + "Target: " + target_system + "\n" -completion_msg = completion_msg + "Entity: " + entity_type + "\n" -completion_msg = completion_msg + "Processed: " + total_processed + "\n" -completion_msg = completion_msg + "Errors: " + total_errors - -SEND MAIL "data-admin@company.com", "Bulk Sync Complete: " + job_id, completion_msg - -WITH result = NEW OBJECT - .status = "completed" - .job_id = job_id - .processed = total_processed - .errors = total_errors -END WITH -``` - -## Configuration - -Store sync configuration in bot memory: - -```basic -' Configure sync settings -SET BOT MEMORY "crm_api_key", "your-crm-api-key" -SET BOT MEMORY "erp_api_key", "your-erp-api-key" -SET BOT MEMORY "ecom_api_key", "your-ecommerce-api-key" -SET BOT MEMORY "max_sync_lag_crm", "30" -SET BOT MEMORY "max_sync_lag_erp", "15" -SET BOT MEMORY "sync_priority_source", "erp" -``` - -## See Also - -- [WEBHOOK](./keyword-webhook.md) - Creating webhook endpoints -- [ON](./keyword-on.md) - Database trigger events -- [SET SCHEDULE](./keyword-set-schedule.md) - Scheduled tasks -- [Data Operations](./keywords.md#database--data-operations) - Database keywords -- [Consolidated Examples](./examples-consolidated.md) - More complete examples \ No newline at end of file diff --git a/docs/src/chapter-06-gbdialog/universal-messaging.md b/docs/src/chapter-06-gbdialog/universal-messaging.md deleted file mode 100644 index 3802ed02..00000000 --- a/docs/src/chapter-06-gbdialog/universal-messaging.md +++ /dev/null @@ -1,131 +0,0 @@ -# Universal Messaging & Multi-Channel - -BotServer automatically handles conversations across different channels (Web, WhatsApp, Email, etc.) using the same BASIC scripts. Write once, deploy everywhere. - -## How It Works - -Your BASIC scripts don't need to know which channel they're running on. The same `TALK` and `HEAR` commands work universally: - -```basic -TALK "Hello! How can I help you?" -HEAR response -TALK "You said: " + response -``` - -This script works identically whether the user is: -- Chatting via web browser -- Messaging on WhatsApp -- Sending emails -- Using Microsoft Teams - -## Supported Channels - -### Web (Default) -The primary channel. Users access via browser at `http://localhost:8080`. - -### WhatsApp Business -Requires WhatsApp Business API configuration. Messages are automatically formatted for WhatsApp's constraints. - -### Email -Bots can receive and respond to emails. Each email thread becomes a conversation session. - -### Microsoft Teams -Deploy bots directly to Teams channels and direct messages. - -## Channel Detection - -BotServer automatically detects the channel based on the session context. No special code needed: - -```basic -' This works on ALL channels -TALK "Welcome to our service!" -TALK "What's your name?" -HEAR name -TALK "Nice to meet you, " + name -``` - -## Channel-Specific Formatting - -While your code stays the same, BotServer automatically handles channel-specific formatting: - -### Web -- Full HTML support -- Rich formatting -- Images and media -- Interactive elements - -### WhatsApp -- Plain text with emoji -- Media as attachments -- Quick reply buttons -- 1024 character limit per message - -### Email -- HTML email format -- Subject line handling -- Attachments -- Proper threading - -### Teams -- Adaptive cards -- @mentions -- Channel vs DM detection -- Teams-specific formatting - -## Media Handling - -Send files and media universally: - -```basic -' Works on all channels that support files -SEND FILE "report.pdf" -TALK "I've sent you the report." -``` - -Each channel handles files appropriately: -- Web: Download link -- WhatsApp: Document attachment -- Email: Email attachment -- Teams: File card - -## Session Management - -Each channel maintains its own session handling: - -- **Web**: Cookie-based sessions -- **WhatsApp**: Phone number as session ID -- **Email**: Thread ID as session -- **Teams**: User/channel context - -## Configuration - -Channel configuration is done in the bot's `config.csv`: - -```csv -channel-web,enabled -channel-whatsapp,enabled -channel-email,enabled -channel-teams,disabled -``` - -## Best Practices - -1. **Keep messages concise** - Some channels have length limits -2. **Use simple formatting** - Not all channels support rich text -3. **Test on target channels** - Ensure your bot works well on each -4. **Handle media gracefully** - Not all channels support all file types -5. **Consider response times** - Email is async, chat is real-time - -## Channel Limitations - -| Channel | Message Length | Media Support | Rich Text | Real-time | -|---------|---------------|---------------|-----------|-----------| -| Web | Unlimited | Full | Yes | Yes | -| WhatsApp | 1024 chars | Images, Docs | Limited | Yes | -| Email | Unlimited | Attachments | HTML | No | -| Teams | 28KB | Full | Adaptive Cards | Yes | - - -## Summary - -Universal messaging means your BASIC scripts work across all channels without modification. BotServer handles the complexity of channel-specific formatting and delivery, letting you focus on the conversation logic. diff --git a/docs/src/chapter-07-gbapp/README.md b/docs/src/chapter-07-gbapp/README.md deleted file mode 100644 index 06ddba1a..00000000 --- a/docs/src/chapter-07-gbapp/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# Chapter 07: Extending General Bots - -Architecture and deployment reference for developers. - -## Overview - -BotServer is built in Rust with a modular architecture. Extend it by creating custom keywords, services, or entire applications. - -## Architecture - -``` -┌─────────────────────────────────────────┐ -│ Web Server (Axum) │ -├─────────────────────────────────────────┤ -│ BASIC Runtime (Rhai) │ -├──────────┬──────────┬──────────┬────────┤ -│ LLM │ Storage │ Vector │ Cache │ -│ Service │ (MinIO) │ (Qdrant) │(Valkey)│ -├──────────┴──────────┴──────────┴────────┤ -│ PostgreSQL │ -└─────────────────────────────────────────┘ -``` - -## Deployment Options - -| Method | Use Case | Guide | -|--------|----------|-------| -| **Local** | Development | [Installation](../chapter-01/installation.md) | -| **Docker** | Production | [Docker Deployment](./docker-deployment.md) | -| **LXC** | Isolated components | [Container Deployment](./containers.md) | - -## Module Structure - -| Module | Purpose | -|--------|---------| -| `web_server` | HTTP/WebSocket handling | -| `basic` | BASIC language runtime | -| `llm` | LLM provider integration | -| `drive` | Object storage | -| `shared` | Database models | - -## Creating Custom Keywords - -```rust -// In src/basic/keywords/my_keyword.rs -pub fn my_keyword(context: &mut EvalContext) -> Result> { - // Your keyword logic - Ok(Dynamic::from("result")) -} -``` - -Register in `keywords/mod.rs` and rebuild. - -## Chapter Contents - -- [Architecture Overview](./architecture.md) - System design -- [Building from Source](./building.md) - Compilation guide -- [Container Deployment (LXC)](./containers.md) - Linux containers -- [Docker Deployment](./docker-deployment.md) - Docker setup -- [Scaling](./scaling.md) - Load balancing -- [Infrastructure](./infrastructure.md) - Hardware planning -- [Observability](./observability.md) - Monitoring -- [Custom Keywords](./custom-keywords.md) - Extending BASIC -- [Services](./services.md) - Service layer - -## See Also - -- [Installation](../chapter-01/installation.md) - Getting started -- [BASIC Reference](../chapter-06-gbdialog/README.md) - Scripting language \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/architecture.md b/docs/src/chapter-07-gbapp/architecture.md deleted file mode 100644 index e7a3f2c8..00000000 --- a/docs/src/chapter-07-gbapp/architecture.md +++ /dev/null @@ -1,218 +0,0 @@ -# Architecture Overview - -BotServer follows a modular architecture designed for scalability, maintainability, and extensibility. Each module handles specific responsibilities and communicates through well-defined interfaces. This chapter provides a comprehensive tour of the system architecture and how components work together. - - -## Core Architecture - -The architecture diagrams below illustrate the major components and their relationships. - -### Data Flow Architecture - -BotServer Data Flow Architecture - -### System Architecture - -BotServer System Architecture - - -## Module Dependency Graph - -Module Dependency Graph - - -## Module Organization - -The codebase is organized into modules that group related functionality together. Each module has clear responsibilities and well-defined interfaces with other modules. - -### Data Flow Through Modules - -Data Flow Through Modules - - -### Core Modules - -The `auth/` module handles authentication and authorization throughout the system. It manages user accounts and group memberships, implements role-based access control (RBAC), handles JWT token generation and validation, provides OAuth integration for external identity providers, and supports two-factor authentication for enhanced security. - -The `automation/` module provides the workflow automation engine. It handles process automation for complex multi-step operations, manages scheduled tasks that run at specified intervals, enables event-driven automation that responds to system events, orchestrates workflows across multiple services, and integrates with external systems for extended capabilities. - -The `basic/` module implements the BASIC dialect interpreter and runtime environment. It provides keyword implementations for all BASIC commands, handles script compilation from source to executable form, manages variables and their scopes, implements flow control structures like loops and conditionals, integrates with external tools the LLM can invoke, and provides comprehensive error handling with helpful messages. - -The `bootstrap/` module handles system initialization and startup procedures. It verifies all required components are available, sequences service startup in the correct order, runs database migrations to update schema, deploys default templates for new installations, performs health checks to ensure system readiness, and loads configuration from files and environment variables. - -The `bot/` module manages bot instances and their interactions. It handles the bot lifecycle including creation, mounting, and unmounting. It processes conversations between users and bots, handles user input and routes it appropriately, coordinates response generation from various sources, manages multi-bot deployments on a single server, and ensures session isolation between different users and bots. - - -### Communication Modules - -The `channels/` module provides multi-channel messaging adapters that allow bots to communicate across different platforms. Supported channels include the web interface for browser-based chat, WhatsApp Business API for messaging app integration, Microsoft Teams for enterprise collaboration, Slack for team communication, Instagram for social media engagement, SMS for text messaging, and voice for telephone interactions. - -The `meet/` module enables real-time communication features. It provides video conferencing capabilities for face-to-face meetings, voice calling for audio-only communication, screen sharing for presentations and collaboration, recording functionality for meeting archives, transcription services for accessibility, and meeting scheduling integration with calendars. - -The `web_server/` module implements the HTTP server and web interface. It serves static files for the UI, handles WebSocket connections for real-time chat, routes REST API requests to appropriate handlers, manages CORS policies for browser security, and processes requests and responses throughout the system. - - -### AI and Knowledge Modules - -The `llm/` module provides large language model integration. It handles model selection based on configuration and requirements, formats prompts according to model expectations, manages token counting and context limits, streams responses for real-time display, tracks API costs for budgeting, and implements model fallbacks when primary providers are unavailable. - -The `llm_models/` module contains specific implementations for different model providers. OpenAI integration supports GPT-3.5 and GPT-4 models. Anthropic integration provides access to Claude models. Google integration enables Gemini model usage. Meta integration supports Llama models for local deployment. Local model support allows self-hosted inference. Custom model implementations can be added for specialized providers. - -The `prompt_manager/` module provides centralized prompt management capabilities. It maintains prompt templates for consistent interactions, handles variable substitution in prompts, optimizes prompts for specific models, supports version control of prompt changes, enables A/B testing of different approaches, and tracks prompt performance metrics. - -The `context/` module manages conversation context throughout interactions. It optimizes the context window to fit within model limits, manages conversation history retention, compresses context when necessary to preserve information, filters context for relevance to current queries, and tracks multi-turn conversations across messages. - - -### Storage and Data Modules - -The `drive/` module handles file and document management. It supports file upload and download operations, processes documents for indexing and search, maintains version control of files, manages sharing permissions between users, enforces quota limits on storage usage, and indexes content for search functionality. - -The `drive_monitor/` module provides storage monitoring and synchronization. It detects changes to files for automatic processing, synchronizes content across storage locations, resolves conflicts when multiple changes occur, manages backups of important data, and provides analytics on storage usage patterns. - -The `package_manager/` module handles bot package management. It loads packages from storage into the runtime, resolves dependencies between packages, manages package versions and updates, supports hot reload of changed packages without restart, and validates packages before deployment. - - -### Processing Modules - -The `engines/` module contains various processing engines for different tasks. The rule engine evaluates business rules and conditions. The workflow engine orchestrates complex processes. The event processor handles system and external events. The message queue manages asynchronous communication. The job scheduler executes background tasks. - -The `calendar_engine/` module provides calendar and scheduling functionality. It manages events and appointments, checks availability for scheduling, coordinates meetings between participants, sends reminders for upcoming events, and handles timezone conversions correctly. - -The `task_engine/` module implements the task management system. It creates tasks from user requests or automation, assigns tasks to appropriate parties, tracks task status through completion, manages dependencies between tasks, and sends notifications about task updates. - -The `email/` module provides email integration capabilities. It sends email via SMTP protocols, receives email via IMAP connections, manages email templates for consistent formatting, tracks email delivery and opens, and handles bounced emails appropriately. - - -### Utility Modules - -The `session/` module manages user sessions throughout their interactions. It creates sessions for new users, persists session state to storage, enforces session timeouts for security, handles concurrent sessions from the same user, and recovers sessions after server restarts. - -The `config/` module handles configuration management. It loads configuration from files and databases, reads environment variables for deployment settings, supports hot reload of configuration changes, validates configuration values, and provides sensible defaults for optional settings. - -The `shared/` module contains shared utilities and models used across the system. It defines database models for persistence, provides common types used throughout the codebase, implements helper functions for repeated tasks, centralizes constants and magic values, and defines error types for consistent error handling. - -The `compliance/` module implements regulatory compliance features. It ensures GDPR compliance for data protection, enforces data retention policies, maintains comprehensive audit logging, provides privacy controls for sensitive data, and manages user consent records. - -The `nvidia/` module provides GPU acceleration support for local model inference. It integrates with CUDA for GPU computation, runs model inference on GPU hardware, batches requests for efficient processing, and optimizes performance for available hardware. - -The `ui_tree/` module manages UI component trees for the interface. It maintains a virtual DOM for efficient updates, manages component lifecycles, handles state across components, processes events from user interactions, and optimizes rendering performance. - -The `web_automation/` module provides web scraping and automation capabilities. It automates browser interactions for data gathering, extracts content from web pages, fills forms programmatically, captures screenshots for documentation, and monitors pages for changes. - - -## Data Flow - -### Request Processing Pipeline - -When a user sends a message, it flows through several processing stages. First, the Channel Adapter receives the user input from the appropriate platform. The Session Manager then identifies the existing session or creates a new one. The Context Manager loads conversation history and relevant context. The BASIC Interpreter executes the dialog script that handles the message. If needed, LLM Integration processes natural language to understand intent. The Knowledge Base provides relevant information from loaded documents. The Response Generator formats the output for the user. Finally, the Channel Adapter delivers the response back through the original platform. - -### Storage Architecture - -The primary database uses PostgreSQL to store structured data including user accounts, bot configurations, session data, conversation history, and system metadata. The Diesel ORM provides type-safe database access. - -Object storage using Drive provides S3-compatible storage for files including user uploads, processed documents, media files, system backups, and application logs. - -The cache layer provides fast access to frequently needed data. It stores session information for quick retrieval, caches commonly accessed data, implements rate limiting counters, holds temporary processing data, and supports pub/sub messaging between components. - -The vector database uses Qdrant to store document embeddings for semantic search. It maintains the semantic search index, stores knowledge base vectors, and performs similarity matching for relevant content retrieval. - - -## Security Architecture - -### Authentication Flow - -The authentication process follows a secure sequence. Users provide credentials through the login interface. The auth module validates credentials against stored records. Upon successful validation, a JWT token is issued. Each subsequent request includes this token for verification. A session is established to maintain state. Permissions are checked before any operation is performed. - -### Data Protection - -Data protection operates at multiple layers. Encryption at rest protects data stored in the database and files. Encryption in transit using TLS/SSL protects data during transmission. Sensitive data masking prevents exposure in logs and displays. PII detection identifies and protects personal information. Secure key management protects cryptographic keys from exposure. - -### Access Control - -Access control mechanisms ensure appropriate authorization. Role-based permissions determine what actions users can perform. Resource-level authorization controls access to specific objects. API rate limiting prevents abuse and ensures fair usage. IP allowlisting restricts access to known addresses when configured. Comprehensive audit logging records all significant actions. - - -## Deployment Architecture - -### Container Structure - -Production deployments typically use containers for isolation and portability. The main application container runs the BotServer binary. PostgreSQL runs in a separate database container. Drive storage uses an S3-compatible container like MinIO. The cache layer uses Valkey in its own container. Qdrant provides vector database functionality in another container. Nginx serves as a reverse proxy for external traffic. - -### Scaling Strategy - -The system scales to handle increased load through several mechanisms. Horizontal scaling adds more web server instances behind a load balancer. Read replicas for the database handle query load. Distributed cache spreads session data across nodes. Load balancing distributes requests across available instances. Auto-scaling policies adjust capacity based on demand. - -### High Availability - -High availability configurations ensure continuous operation. Multi-zone deployment protects against facility failures. Database replication maintains copies of data. Storage redundancy prevents data loss. Health monitoring detects problems quickly. Automatic failover redirects traffic when components fail. - - -## Performance Optimization - -### Caching Strategy - -Caching improves response times throughout the system. Response caching stores generated responses for reuse. Query result caching avoids repeated database queries. Static asset caching serves files directly from cache. API response caching stores external API results. Knowledge base caching keeps frequently accessed content in memory. - -### Async Processing - -Asynchronous processing improves throughput and responsiveness. Background jobs handle long-running tasks without blocking. Message queues decouple producers from consumers. Event-driven architecture responds to changes efficiently. Non-blocking I/O maximizes resource utilization. Worker pools distribute processing across threads. - -### Resource Management - -Careful resource management ensures efficient operation. Connection pooling reuses database connections. Memory management prevents leaks and excessive usage. Token optimization minimizes LLM API costs. Query optimization reduces database load. Lazy loading defers work until necessary. - - -## Monitoring and Observability - -### Metrics Collection - -Comprehensive metrics provide visibility into system behavior. System metrics track CPU, memory, and disk usage. Application metrics measure request rates and latencies. Business metrics track user engagement and outcomes. User analytics show usage patterns. Performance tracking identifies bottlenecks. - -### Logging - -Structured logging supports debugging and analysis. All logs use consistent structured formats. Log aggregation collects logs from all components. Error tracking captures and groups exceptions. Audit trails record security-relevant events. Debug logging provides detailed information when needed. - -### Health Checks - -Health checks ensure system availability and readiness. Liveness probes confirm the application is running. Readiness probes verify the application can serve requests. Dependency checks validate external services are available. Performance monitoring tracks response times. The alert system notifies operators of problems. - - -## Extension Points - -### Plugin System - -The system provides extension points for customization. Custom keywords extend the BASIC language with new capabilities. External tools integrate third-party services. API integrations connect to external systems. Custom channels add support for new platforms. Model providers integrate additional LLM services. - -### Webhook Support - -Webhooks enable event-driven integrations. Incoming webhooks accept notifications from external systems. Outgoing webhooks notify external systems of events. Event subscriptions define what events trigger webhooks. Callback handling processes webhook responses. Retry mechanisms ensure delivery despite transient failures. - -### API Integration - -Multiple API protocols support different integration needs. The REST API provides standard HTTP access. GraphQL support is planned for flexible queries. WebSocket connections enable real-time bidirectional communication. gRPC support is planned for high-performance integrations. OpenAPI specifications document all endpoints. - - -## Development Workflow - -### Local Development - -Setting up a local development environment follows a straightforward process. First, clone the repository to your machine. Install required dependencies using Cargo and system packages. Configure environment variables for local services. Run database migrations to set up the schema. Start the required services like PostgreSQL and cache. Load default templates for testing. - -### Testing Strategy - -Testing ensures code quality at multiple levels. Unit tests verify individual functions and methods. Integration tests check interactions between components. End-to-end tests validate complete user workflows. Load testing measures performance under stress. Security testing identifies vulnerabilities. - -### CI/CD Pipeline - -Continuous integration and deployment automates quality assurance. Automated testing runs on every commit. Code quality checks enforce standards. Security scanning identifies known vulnerabilities. The build process produces deployable artifacts. Deployment automation pushes releases to environments. - - -## Future Architecture Plans - -### Planned Enhancements - -Future development will expand system capabilities. Microservices migration will enable independent scaling of components. Kubernetes native deployment will simplify orchestration. Multi-region support will improve global performance. Edge deployment will reduce latency for distributed users. Serverless functions will enable elastic scaling for specific workloads. - -### Performance Goals - -Performance targets guide optimization efforts. Response times should be sub-100ms for typical requests. The system should support 10,000 or more concurrent users. Uptime should reach 99.99% for production deployments. Elastic scaling should handle traffic spikes automatically. Global CDN integration should improve worldwide access times. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/assets/data-flow.svg.backup b/docs/src/chapter-07-gbapp/assets/data-flow.svg.backup deleted file mode 100644 index 777aff72..00000000 --- a/docs/src/chapter-07-gbapp/assets/data-flow.svg.backup +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BotServer Data Flow Architecture - - - - - User Input Layer - - - - Web UI - - - WhatsApp - - - Teams - - - Email - - - API - - - - - - - - - Core Processing Engine - - - - Session Manager - User Context - - - - BASIC Interpreter - Script Execution - - - - LLM Integration - AI Processing - - - - Knowledge Base - Vector Search - - - - - - - - - Tool System - External APIs & Functions - - - - Cache Layer - Response Optimization - - - - - - - - - Storage & Persistence Layer - - - - Database - User Data - - - - Vector DB - Embeddings - - - - Drive Storage - Files & Assets - - - - Cache - Fast Access - - - - - - - - - - - - - - Data Flow: - - Request/Response - - - Data Access - - - - All components run in async Rust for maximum performance - - - - - \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/assets/module-data-flow.svg.backup b/docs/src/chapter-07-gbapp/assets/module-data-flow.svg.backup deleted file mode 100644 index 8ec80c23..00000000 --- a/docs/src/chapter-07-gbapp/assets/module-data-flow.svg.backup +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Data Flow Through Modules - - - - User Input - - - - - - - web_server/ | channels/ - Axum HTTP Server - Route to channel - - - - - - - session/ - Load/Create Session - Validate Token - - - - - - - auth/ - Check Permissions - Apply RBAC - - - - - - - bot/ - Route to Bot Instance - Load Configuration - - - - - - - basic/ - Execute BASIC Script - Parse Keywords - - - - - - - - - - - context/ - Load KB - - - - drive/ - Get Files - - - - database/ - Query DB - - - - llm/ - Call AI - - - - - - - - - - - - - Bot Response - - - - - 1. Input Reception - 2. HTTP Routing - 3. Session Management - 4. Authorization - 5. Bot Routing - 6. Script Execution - 7. Data Processing - 8. Response Generation - - - - All operations are async with Tokio runtime for maximum throughput - - - - - \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/assets/module-dependency.svg.backup b/docs/src/chapter-07-gbapp/assets/module-dependency.svg.backup deleted file mode 100644 index dbda108a..00000000 --- a/docs/src/chapter-07-gbapp/assets/module-dependency.svg.backup +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Module Dependency Graph - - - - main.rs - - - - - - - bootstrap/ - - - - - - - - - - package_manager/ - - - - config/ - - - - database/ - - - - - - - - session/ - - - - web_server/ - - - - - - - - - - - - - - - - - channels/ - - - - bot/ - - - - basic/ - - - - auth/ - - - - - - - - - - llm/ - - - - - - - context/ - - - - Layers: - - - Entry Point - - - Core System - - - Services - - - Features - - - - Arrows indicate compile-time dependencies - - - - - \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/assets/system-architecture.svg.backup b/docs/src/chapter-07-gbapp/assets/system-architecture.svg.backup deleted file mode 100644 index 30911ff7..00000000 --- a/docs/src/chapter-07-gbapp/assets/system-architecture.svg.backup +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BotServer Architecture - Virtual Crates System - - - - - - - BotServer Binary - - - - compiles to - - - - - Core Engine (src/core/) - - - - Bootstrap - System Init - Service Start - - - Package Manager - Component Registry - Module Loader - - - Session Manager - Context Handling - State Management - - - Shared State - AppState - Configuration - - - Utils - Helpers - Common - - - - - - - - - - Virtual Crates (gbapp modules in src/) - - - - basic.gbapp - src/basic/ - - • BASIC Interpreter - • Keywords Registry - • Script Execution - • Rhai Engine - - - - channels.gbapp - src/channels/ - - • WhatsApp - • Teams - • Email - • Web UI - - - - storage.gbapp - src/storage/ - - • Knowledge Base - • Drive Integration - • Vector DB - • Cache - - - - your_feature.gbapp - src/your_feature/ - - • Your Keywords - • Your Services - • Your Models - + Add yours! - - - - - - - - - AI & LLM Integration - - - LLM Service - - - Embeddings - - - Semantic Search - - - - - - Persistence Layer - - - Database - - - Vector DB - - - Drive - - - Cache - - - - - Key Concepts: - - - Virtual Crates = Modules in src/ - - - Your Contribution Space - - All compile to single optimized binary - - - - gbapp virtual crates: The bridge between old Node.js packages and new Rust modules - - - - - \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/building.md b/docs/src/chapter-07-gbapp/building.md deleted file mode 100644 index 13c99d9d..00000000 --- a/docs/src/chapter-07-gbapp/building.md +++ /dev/null @@ -1,532 +0,0 @@ -# Building from Source - -This guide covers building BotServer from source, including dependencies, feature flags, and platform-specific considerations. - -## Prerequisites - -### System Requirements - -- **Operating System**: Linux, macOS, or Windows -- **Rust**: 1.70 or later (2021 edition) -- **Memory**: 4GB RAM minimum (8GB recommended) -- **Disk Space**: 8GB for development environment - -### Install Rust - -If you don't have Rust installed: - -```bash -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -source $HOME/.cargo/env -``` - -Verify installation: - -```bash -rustc --version -cargo --version -``` - -### System Dependencies - -#### Linux (Ubuntu/Debian) - -```bash -sudo apt update -sudo apt install -y \ - build-essential \ - pkg-config \ - libssl-dev \ - libpq-dev \ - cmake -``` - -#### Linux (Fedora/RHEL) - -```bash -sudo dnf install -y \ - gcc \ - gcc-c++ \ - make \ - pkg-config \ - openssl-devel \ - postgresql-devel \ - cmake -``` - -#### macOS - -```bash -brew install postgresql openssl cmake -``` - -#### Windows - -Install Visual Studio Build Tools with C++ support, then: - -```powershell -# Install PostgreSQL (for libpq) -choco install postgresql -``` - -## Clone Repository - -```bash -git clone https://github.com/GeneralBots/BotServer.git -cd BotServer -``` - -## Build Configurations - -### Standard Build - -Build with default features (includes desktop support): - -```bash -cargo build --release -``` - -The compiled binary will be at `target/release/botserver`. - -### Minimal Build - -Build without any optional features: - -```bash -cargo build --release --no-default-features -``` - -This excludes: -- Desktop GUI (Tauri) -- Vector database (Qdrant) -- Email integration (IMAP) - -### Feature-Specific Builds - -#### With Vector Database - -Enable Qdrant vector database support: - -```bash -cargo build --release --features vectordb -``` - -#### With Email Support - -Enable IMAP email integration: - -```bash -cargo build --release --features email -``` - -#### Desktop Application - -Build as desktop app with Tauri (default): - -```bash -cargo build --release --features desktop -``` - -#### All Features - -Build with all optional features: - -```bash -cargo build --release --all-features -``` - -## Feature Flags - -BotServer supports the following features defined in `Cargo.toml`: - -```toml -[features] -default = ["desktop"] -vectordb = ["qdrant-client"] -email = ["imap"] -desktop = ["dep:tauri", "dep:tauri-plugin-dialog", "dep:tauri-plugin-opener"] -``` - -### Feature Details - -| Feature | Dependencies | Purpose | -|---------|--------------|---------| -| `desktop` | tauri, tauri-plugin-dialog, tauri-plugin-opener | Native desktop application with system integration | -| `vectordb` | qdrant-client | Semantic search with Qdrant vector database | -| `email` | imap | IMAP email integration for reading emails | - -## Build Profiles - -### Debug Build - -For development with debug symbols and no optimizations: - -```bash -cargo build -``` - -Binary location: `target/debug/botserver` - -### Release Build - -Optimized for production with LTO and size optimization: - -```bash -cargo build --release -``` - -Binary location: `target/release/botserver` - -The release profile in `Cargo.toml` uses aggressive optimization: - -```toml -[profile.release] -lto = true # Link-time optimization -opt-level = "z" # Optimize for size -strip = true # Strip symbols -panic = "abort" # Abort on panic (smaller binary) -codegen-units = 1 # Better optimization (slower build) -``` - -## Platform-Specific Builds - -### Linux - -Standard build works on most distributions: - -```bash -cargo build --release -``` - -For static linking (portable binary): - -```bash -RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu -``` - -### macOS - -Build for current architecture: - -```bash -cargo build --release -``` - -Build universal binary (Intel + Apple Silicon): - -```bash -rustup target add x86_64-apple-darwin aarch64-apple-darwin -cargo build --release --target x86_64-apple-darwin -cargo build --release --target aarch64-apple-darwin -lipo -create \ - target/x86_64-apple-darwin/release/botserver \ - target/aarch64-apple-darwin/release/botserver \ - -output botserver-universal -``` - -### Windows - -Build with MSVC toolchain: - -```bash -cargo build --release -``` - -Binary location: `target\release\botserver.exe` - -## Cross-Compilation - -### Install Cross-Compilation Tools - -```bash -cargo install cross -``` - -### Build for Linux from macOS/Windows - -```bash -cross build --release --target x86_64-unknown-linux-gnu -``` - -### Build for Windows from Linux/macOS - -```bash -cross build --release --target x86_64-pc-windows-gnu -``` - -## Troubleshooting - -### OpenSSL Errors - -If you encounter OpenSSL linking errors: - -**Linux:** -```bash -sudo apt install libssl-dev -``` - -**macOS:** -```bash -export OPENSSL_DIR=$(brew --prefix openssl) -cargo build --release -``` - -**Windows:** -```bash -# Use vcpkg -vcpkg install openssl:x64-windows -set OPENSSL_DIR=C:\vcpkg\installed\x64-windows -cargo build --release -``` - -### PostgreSQL Library Errors - -If libpq is not found: - -**Linux:** -```bash -sudo apt install libpq-dev -``` - -**macOS:** -```bash -brew install postgresql -export PQ_LIB_DIR=$(brew --prefix postgresql)/lib -``` - -**Windows:** -```bash -# Ensure PostgreSQL is in PATH -set PQ_LIB_DIR=C:\Program Files\PostgreSQL\15\lib -``` - -### Out of Memory During Build - -Reduce parallel jobs: - -```bash -cargo build --release -j 2 -``` - -Or limit memory per job: - -```bash -CARGO_BUILD_JOBS=2 cargo build --release -``` - -### Linker Errors - -Ensure you have a C/C++ compiler: - -**Linux:** -```bash -sudo apt install build-essential -``` - -**macOS:** -```bash -xcode-select --install -``` - -**Windows:** -Install Visual Studio Build Tools with C++ support. - -## Verify Build - -After building, verify the binary works: - -```bash -./target/release/botserver --version -``` - -Expected output: `botserver 6.0.8` or similar. - -## Development Builds - -### Watch Mode - -Auto-rebuild on file changes: - -```bash -cargo install cargo-watch -cargo watch -x 'build --release' -``` - -### Check Without Building - -Fast syntax and type checking: - -```bash -cargo check -``` - -With specific features: - -```bash -cargo check --features vectordb,email -``` - -## Testing - -### Run All Tests - -```bash -cargo test -``` - -### Run Tests for Specific Module - -```bash -cargo test --package botserver --lib bootstrap::tests -``` - -### Run Integration Tests - -```bash -cargo test --test '*' -``` - -## Code Quality - -### Format Code - -```bash -cargo fmt -``` - -### Lint Code - -```bash -cargo clippy -- -D warnings -``` - -### Check Dependencies - -```bash -cargo tree -``` - -Find duplicate dependencies: - -```bash -cargo tree --duplicates -``` - -### Security Audit - -Run security audit to check for known vulnerabilities in dependencies: - -```bash -cargo install cargo-audit -cargo audit -``` - -This should be run regularly during development to ensure dependencies are secure. - -## Build Artifacts - -After a successful release build, you'll have: - -- `target/release/botserver` - Main executable -- `target/release/build/` - Build script outputs -- `target/release/deps/` - Compiled dependencies - -## Size Optimization - -The release profile already optimizes for size. To further reduce: - -### Strip Binary Manually - -```bash -strip target/release/botserver -``` - -### Use UPX Compression - -```bash -upx --best --lzma target/release/botserver -``` - -Note: UPX may cause issues with some systems. Test thoroughly. - -## Incremental Compilation - -For faster development builds: - -```bash -export CARGO_INCREMENTAL=1 -cargo build -``` - -Note: This is enabled by default for debug builds. - -## Clean Build - -Remove all build artifacts: - -```bash -cargo clean -``` - -## LXC Build - -Build inside LXC container: - -```bash -# Create build container -lxc-create -n botserver-build -t download -- -d ubuntu -r jammy -a amd64 - -# Configure container with build resources -cat >> /var/lib/lxc/botserver-build/config << EOF -lxc.cgroup2.memory.max = 4G -lxc.cgroup2.cpu.max = 400000 100000 -EOF - -# Start container -lxc-start -n botserver-build - -# Install build dependencies -lxc-attach -n botserver-build -- bash -c " -apt-get update -apt-get install -y build-essential pkg-config libssl-dev libpq-dev cmake curl git -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -source \$HOME/.cargo/env -" - -# Build BotServer -lxc-attach -n botserver-build -- bash -c " -git clone https://github.com/GeneralBots/BotServer /build -cd /build -source \$HOME/.cargo/env -cargo build --release --no-default-features -" - -# Copy binary from container -lxc-attach -n botserver-build -- cat /build/target/release/botserver > /usr/local/bin/botserver -chmod +x /usr/local/bin/botserver -``` - -## Installation - -After building, install system-wide: - -```bash -sudo install -m 755 target/release/botserver /usr/local/bin/ -``` - -Or create a symlink: - -```bash -ln -s $(pwd)/target/release/botserver ~/.local/bin/botserver -``` - -## Next Steps - -After building: - -1. Run the bootstrap process to install dependencies -2. Configure `.env` file with database credentials -3. Start BotServer and access web interface -4. Create your first bot from templates - -See [Chapter 01: Run and Talk](../chapter-01/README.md) for next steps. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/containers.md b/docs/src/chapter-07-gbapp/containers.md deleted file mode 100644 index 4b536210..00000000 --- a/docs/src/chapter-07-gbapp/containers.md +++ /dev/null @@ -1,140 +0,0 @@ -# Container Deployment (LXC) - -BotServer uses LXC (Linux Containers) for isolated component deployment with system-level containerization. - -## What is LXC? - -- **System containers** - Full Linux userspace (lightweight VMs) -- **Shared kernel** - More efficient than virtual machines -- **Isolation** - Separate processes, networking, filesystems -- **Resource control** - CPU, memory, I/O limits - -## Automatic Setup - -```bash -./botserver --container -``` - -This automatically: -1. Detects LXC/LXD availability -2. Initializes LXD if needed -3. Creates Debian 12 containers per component -4. Mounts directories for persistent data -5. Configures networking and ports -6. Installs and starts services - -## Container Architecture - -### Container Naming - -``` -{tenant}-tables → PostgreSQL -{tenant}-drive → S3-compatible storage -{tenant}-cache → Valkey cache -{tenant}-llm → LLM server (optional) -{tenant}-email → Mail server (optional) -``` - -Default tenant: `default` → `default-tables`, `default-drive`, etc. - -### Directory Mounting - -``` -Host: botserver-stack/tables/data/ → Container: /opt/gbo/data/ -Host: botserver-stack/tables/conf/ → Container: /opt/gbo/conf/ -Host: botserver-stack/tables/logs/ → Container: /opt/gbo/logs/ -``` - -Data persists even if containers are deleted. - -### Port Forwarding - -| Container Port | Host Port | Service | -|----------------|-----------|---------| -| 5432 | 5432 | PostgreSQL | -| 9000 | 9000 | Drive API | -| 9001 | 9001 | Drive Console | -| 6379 | 6379 | Cache | - -## Common Operations - -```bash -# List containers -lxc list - -# Execute command in container -lxc exec default-tables -- psql -U gbuser botserver - -# View logs -lxc exec default-tables -- journalctl -u tables - -# Stop/Start -lxc stop default-tables -lxc start default-tables - -# Delete (data in mounts persists) -lxc delete default-tables --force -``` - -## Resource Limits - -```bash -lxc config set default-tables limits.cpu 2 -lxc config set default-tables limits.memory 4GB -``` - -## Snapshots - -```bash -# Create -lxc snapshot default-tables backup-2024-01-15 - -# List -lxc info default-tables - -# Restore -lxc restore default-tables backup-2024-01-15 -``` - -## Troubleshooting - -| Issue | Solution | -|-------|----------| -| LXC not installed | `sudo snap install lxd && sudo lxd init --auto` | -| Permission denied | `sudo usermod -aG lxd $USER && newgrp lxd` | -| Container won't start | `lxc console default-tables --show-log` | -| Port in use | `sudo netstat -tulpn \| grep PORT` | - -## Container vs Local - -| Use Containers When | Use Local When | -|---------------------|----------------| -| Clean isolation needed | Maximum performance | -| Multiple instances | LXC not available | -| Easy cleanup/reinstall | Simple deployment | -| Security isolation | Direct service access | - -## Migration - -### Local → Container - -```bash -pg_dump botserver > backup.sql -./botserver --container -lxc exec default-tables -- psql -U gbuser botserver < backup.sql -``` - -### Container → Local - -```bash -lxc exec default-tables -- pg_dump -U gbuser botserver > backup.sql -./botserver uninstall tables -./botserver install tables --local -psql -U gbuser botserver < backup.sql -``` - -## See Also - -- [Installation](../chapter-01/installation.md) - Local setup -- [Docker Deployment](./docker-deployment.md) - Docker alternative -- [Architecture](./architecture.md) - System design \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/crates.md b/docs/src/chapter-07-gbapp/crates.md deleted file mode 100644 index 0d47e695..00000000 --- a/docs/src/chapter-07-gbapp/crates.md +++ /dev/null @@ -1,81 +0,0 @@ -# Module Structure - -BotServer is a single Rust crate (not a workspace) with multiple modules. The application is defined in `Cargo.toml` as the `botserver` crate, version 6.0.8. - -## Main Entry Points - -The primary entry point is `src/main.rs`, which starts the Axum web server and initializes all components. The public library interface in `src/lib.rs` exports all major modules for external use. - -## Core Modules - -The following modules are exported in `src/lib.rs` and comprise the core functionality: - -### User & Bot Management - -The `auth` module handles user authentication, password hashing using Argon2, and session token management. The `bot` module manages bot lifecycle, configuration, and runtime operations. The `session` module provides user session handling and state management across conversations. - -### Conversation & Scripting - -The `basic` module implements the BASIC-like scripting language interpreter for `.gbdialog` files. The `context` module manages conversation context and memory throughout user interactions. The `channels` module provides multi-channel support for web, voice, and various messaging platforms. - -### Knowledge & AI - -The `llm` module provides LLM provider integration for OpenAI and local models. The `llm_models` module contains model-specific implementations and configurations. The `nvidia` module offers NVIDIA GPU acceleration support for local inference. - -### Infrastructure - -The `bootstrap` module handles system initialization and the auto-bootstrap process. The `package_manager` module manages component installation and lifecycle. The `config` module provides application configuration and environment management. The `shared` module contains shared utilities, database models, and common types used throughout the codebase. The `web_server` module implements the Axum-based HTTP server and API endpoints. - -### Features & Integration - -The `automation` module provides scheduled tasks and event-driven triggers. The `drive_monitor` module handles file system monitoring and change detection. The `email` module provides email integration via IMAP and SMTP as a conditional feature. The `file` module handles file processing and operations. The `meet` module integrates video meeting functionality through LiveKit. - -### Testing & Development - -The `tests` module contains test utilities and test suites for validating functionality across the codebase. - -## Internal Modules - -Several directories exist in `src/` that are either internal implementations or not fully integrated into the public API. - -The `api/` directory contains the `api/drive` subdirectory with drive-related API code. The `drive/` directory provides drive (S3-compatible) integration and vector database functionality through `vectordb.rs`. The `ui/` directory contains UI-related modules including `drive.rs`, `stream.rs`, `sync.rs`, and `local-sync.rs`. The `ui_tree/` directory provides UI tree structure functionality used in main.rs but not exported in lib.rs. The `prompt_manager/` directory stores the prompt library and is not a Rust module but contains `prompts.csv`. The `riot_compiler/` directory contains a Riot.js component compiler that exists but is currently unused. The `web_automation/` directory is an empty placeholder for future functionality. - -## Dependency Management - -All dependencies are managed through a single `Cargo.toml` at the project root. - -The web framework layer uses `axum`, `tower`, and `tower-http` for HTTP handling. The async runtime is `tokio` for concurrent operations. Database access uses `diesel` for PostgreSQL and `redis` for cache component connectivity. AI and ML functionality relies on `qdrant-client` for vector database operations as an optional feature. Storage operations use `aws-sdk-s3` for drive and S3-compatible storage backends. Scripting uses `rhai` as the BASIC-like language runtime. Security features include `argon2` for password hashing and `aes-gcm` for encryption. Desktop support uses `tauri` as an optional feature. - -## Feature Flags - -The crate supports optional features for customizing builds: - -```toml -[features] -default = ["desktop"] -vectordb = ["qdrant-client"] -email = ["imap"] -desktop = ["dep:tauri", "dep:tauri-plugin-dialog", "dep:tauri-plugin-opener"] -``` - -## Building - -To build the project with different configurations: - -```bash -# Standard build -cargo build --release - -# Build without desktop features -cargo build --release --no-default-features - -# Build with vector database support -cargo build --release --features vectordb - -# Build with all features -cargo build --release --all-features -``` - -## Module Organization Pattern - -Most modules follow a consistent structure with a `mod.rs` file containing the main module implementation and a `module_name.test.rs` file for module-specific tests. Some modules have additional submodules or specialized files such as `drive/vectordb.rs` and `ui/drive.rs` for feature-specific functionality. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/custom-keywords.md b/docs/src/chapter-07-gbapp/custom-keywords.md deleted file mode 100644 index 667dfc35..00000000 --- a/docs/src/chapter-07-gbapp/custom-keywords.md +++ /dev/null @@ -1,318 +0,0 @@ -# Creating Custom Keywords - -BotServer's BASIC scripting language can be extended with custom keywords. All keywords are implemented as Rust functions in the `src/basic/keywords/` directory. - -## Overview - -Keywords in BotServer are Rust functions that get registered with the Rhai scripting engine. They provide the core functionality that BASIC scripts can use to interact with the system. - -## Keyword Implementation Structure - -### File Organization - -Each keyword is typically implemented in its own module file: - -``` -src/basic/keywords/ -├── mod.rs # Module registration -├── hear_talk.rs # HEAR and TALK keywords -├── llm_keyword.rs # LLM keyword -├── bot_memory.rs # GET BOT MEMORY, SET BOT MEMORY -├── use_kb.rs # USE KB keyword -├── clear_kb.rs # CLEAR KB keyword -├── get.rs # GET keyword -├── format.rs # FORMAT keyword -└── [other keywords].rs -``` - -## Creating a New Keyword - -### Step 1: Create the Module File - -Create a new file in `src/basic/keywords/` for your keyword: - -``` -src/basic/keywords/my_keyword.rs -``` - -### Step 2: Implement the Keyword Function - -Keywords are implemented using one of two Rhai registration methods: - -#### Method 1: Simple Function Registration - -For basic keywords that return values: - -```rust -use rhai::Engine; -use std::sync::Arc; -use crate::core::shared::state::AppState; -use crate::core::session::UserSession; - -pub fn my_keyword( - state: Arc, - user_session: UserSession, - engine: &mut Engine -) { - let state_clone = Arc::clone(&state); - let user_clone = user_session.clone(); - - engine.register_fn("MY_KEYWORD", move |param: String| -> String { - // Your keyword logic here - format!("Processed: {}", param) - }); -} -``` - -#### Method 2: Custom Syntax Registration - -For keywords with special syntax or side effects: - -```rust -use rhai::{Engine, EvalAltResult}; -use std::sync::Arc; -use crate::core::shared::state::AppState; -use crate::core::session::BotSession; - -pub fn register_my_keyword( - state: Arc, - session: Arc, - engine: &mut Engine -) -> Result<(), Box> { - let state_clone = Arc::clone(&state); - let session_clone = Arc::clone(&session); - - engine.register_custom_syntax( - &["MY_KEYWORD", "$expr$"], // Syntax pattern - true, // Is statement (not expression) - move |context, inputs| { - let param = context.eval_expression_tree(&inputs[0])?.to_string(); - - // Your keyword logic here - info!("MY_KEYWORD executed with: {}", param); - - Ok(().into()) - } - )?; - - Ok(()) -} -``` - -### Step 3: Register in mod.rs - -Add your module to `src/basic/keywords/mod.rs`: - -```rust -pub mod my_keyword; -``` - -### Step 4: Add to Keyword Registry - -Keywords are registered in the BASIC interpreter initialization. The registration happens in the main interpreter setup where all keywords are added to the Rhai engine. - -## Keyword Patterns - -### Pattern 1: Database Operations - -Keywords that interact with the database (like `GET BOT MEMORY`): - -```rust -pub fn database_keyword(state: Arc, user: UserSession, engine: &mut Engine) { - let state_clone = Arc::clone(&state); - let user_clone = user.clone(); - - engine.register_fn("DB_KEYWORD", move |key: String| -> String { - let state = Arc::clone(&state_clone); - let conn_result = state.conn.get(); - - if let Ok(mut conn) = conn_result { - // Database query using Diesel - // Return result - } else { - String::new() - } - }); -} -``` - -### Pattern 2: Async Operations - -Keywords that need async operations (like `WEATHER`): - -```rust -pub fn async_keyword(state: Arc, user: UserSession, engine: &mut Engine) { - engine.register_custom_syntax(&["ASYNC_OP", "$expr$"], false, move |context, inputs| { - let param = context.eval_expression_tree(&inputs[0])?; - - // Create channel for async result - let (tx, rx) = std::sync::mpsc::channel(); - - // Spawn blocking task - std::thread::spawn(move || { - let rt = tokio::runtime::Runtime::new().unwrap(); - let result = rt.block_on(async { - // Async operation here - "result".to_string() - }); - let _ = tx.send(result); - }); - - // Wait for result - match rx.recv_timeout(Duration::from_secs(30)) { - Ok(result) => Ok(result.into()), - Err(_) => Ok("Timeout".into()), - } - }); -} -``` - -### Pattern 3: Session Management - -Keywords that modify session state (like `USE KB`, `CLEAR KB`): - -```rust -pub fn register_session_keyword( - state: Arc, - session: Arc, - engine: &mut Engine -) -> Result<(), Box> { - let session_clone = Arc::clone(&session); - - engine.register_custom_syntax(&["SESSION_OP", "$expr$"], true, move |context, inputs| { - let param = context.eval_expression_tree(&inputs[0])?.to_string(); - - // Modify session state - let mut session_lock = session_clone.blocking_write(); - // Update session fields - - Ok(().into()) - })?; - - Ok(()) -} -``` - -## Available Dependencies - -Keywords have access to: - -1. **AppState**: Application-wide state including: - - Database connection pool (`state.conn`) - - Drive client for S3-compatible storage (`state.drive`) - - Cache client (`state.cache`) - - Configuration (`state.config`) - - LLM provider (`state.llm_provider`) - -2. **UserSession**: Current user's session data: - - User ID (`user_session.user_id`) - - Bot ID (`user_session.bot_id`) - - Session ID (`user_session.session_id`) - -3. **BotSession**: Bot conversation state: - - Context collections - - Tool definitions - - Conversation history - - Session variables - -## Error Handling - -Keywords should handle errors gracefully: - -```rust -engine.register_fn("SAFE_KEYWORD", move |param: String| -> String { - match risky_operation(¶m) { - Ok(result) => result, - Err(e) => { - error!("Keyword error: {}", e); - format!("Error: {}", e) - } - } -}); -``` - -## Testing Keywords - -Keywords can be tested with unit tests: - -```rust -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_my_keyword() { - // Create test engine - let mut engine = Engine::new(); - - // Register keyword - // Test keyword execution - // Assert results - } -} -``` - -## Best Practices - -1. **Clone Arc References**: Always clone Arc-wrapped state before moving into closures -2. **Use Logging**: Add info/debug logging for keyword execution -3. **Handle Errors**: Don't panic, return error messages as strings -4. **Timeout Async Ops**: Use timeouts for network operations -5. **Document Parameters**: Use clear parameter names and add comments -6. **Keep It Simple**: Each keyword should do one thing well -7. **Thread Safety**: Ensure all operations are thread-safe - -## Example: Complete Keyword Implementation - -Here's a complete example of a custom keyword that saves data: - -```rust -// src/basic/keywords/save_data.rs - -use rhai::Engine; -use std::sync::Arc; -use log::{info, error}; -use crate::core::shared::state::AppState; -use crate::core::session::UserSession; - -pub fn save_data_keyword( - state: Arc, - user_session: UserSession, - engine: &mut Engine -) { - let state_clone = Arc::clone(&state); - let user_clone = user_session.clone(); - - engine.register_fn("SAVE_DATA", move |key: String, value: String| -> String { - info!("SAVE_DATA called: key={}, value={}", key, value); - - let state = Arc::clone(&state_clone); - let conn_result = state.conn.get(); - - match conn_result { - Ok(mut conn) => { - // Save to database using Diesel - // (actual implementation would use proper Diesel queries) - info!("Data saved successfully"); - "OK".to_string() - } - Err(e) => { - error!("Database error: {}", e); - format!("Error: {}", e) - } - } - }); -} -``` - -## Limitations - -- Keywords must be synchronous or use blocking operations -- Direct async/await is not supported (use channels for async) -- Keywords are registered globally for all scripts -- Cannot dynamically add keywords at runtime -- All keywords must be compiled into the binary - -## Summary - -Creating custom keywords extends BotServer's BASIC language capabilities. Keywords are Rust functions registered with the Rhai engine that provide access to system features, databases, external APIs, and more. Follow the patterns shown above to create robust, thread-safe keywords that integrate seamlessly with the BotServer ecosystem. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/dependencies.md b/docs/src/chapter-07-gbapp/dependencies.md deleted file mode 100644 index c77d23be..00000000 --- a/docs/src/chapter-07-gbapp/dependencies.md +++ /dev/null @@ -1,458 +0,0 @@ -# Adding Dependencies - -BotServer is a single-crate Rust application, so all dependencies are managed through the root `Cargo.toml` file. This guide covers how to add, update, and manage dependencies effectively. - -## Adding a Dependency - -### Basic Dependency - -To add a new crate, edit `Cargo.toml` and add it to the `[dependencies]` section: - -```toml -[dependencies] -serde = "1.0" -``` - -Then update your dependencies: - -```bash -cargo build -``` - -### Dependency with Features - -Many crates offer optional features that you can enable selectively. The syntax uses curly braces to specify both the version and the features array: - -```toml -[dependencies] -tokio = { version = "1.41", features = ["full"] } -serde = { version = "1.0", features = ["derive"] } -``` - -### Version-Specific Dependencies - -Cargo supports several version constraint formats to control which versions are acceptable. An exact version uses the equals sign prefix, while minimum versions use the greater-than-or-equal operator. The caret symbol indicates compatible versions according to semantic versioning, and wildcards allow any version within a major release: - -```toml -[dependencies] -# Exact version -diesel = "=2.1.0" - -# Minimum version -anyhow = ">=1.0.0" - -# Compatible version (caret) -regex = "^1.11" - -# Wildcard -uuid = "1.*" -``` - -### Git Dependencies - -You can add dependencies directly from Git repositories when you need unreleased features or custom forks. Specify the repository URL along with an optional branch name: - -```toml -[dependencies] -rhai = { git = "https://github.com/therealprof/rhai.git", branch = "features/use-web-time" } -``` - -For reproducible builds, pin to a specific commit using the `rev` field: - -```toml -[dependencies] -my-crate = { git = "https://github.com/user/repo", rev = "abc123" } -``` - -You can also reference a tagged release: - -```toml -[dependencies] -my-crate = { git = "https://github.com/user/repo", tag = "v1.0.0" } -``` - -### Optional Dependencies - -Some dependencies aren't always needed and can be marked as optional. These won't be compiled unless explicitly enabled through feature flags: - -```toml -[dependencies] -qdrant-client = { version = "1.12", optional = true } -imap = { version = "3.0.0-alpha.15", optional = true } -``` - -Then define features that enable them: - -```toml -[features] -vectordb = ["qdrant-client"] -email = ["imap"] -``` - -### Platform-Specific Dependencies - -Certain dependencies are only needed on specific operating systems. Cargo's target configuration syntax lets you conditionally include dependencies based on the compilation target: - -```toml -[target.'cfg(unix)'.dependencies] -libc = "0.2" - -[target.'cfg(windows)'.dependencies] -winapi = "0.3" - -[target.'cfg(target_os = "macos")'.dependencies] -core-foundation = "0.9" -``` - -## Existing Dependencies - -BotServer relies on a comprehensive set of dependencies organized by functionality. - -### Web Framework - -The HTTP layer is built on `axum` as the primary web framework, with `tower` providing middleware and service abstractions. The `tower-http` crate adds HTTP-specific middleware for CORS, static file serving, and tracing. At the lowest level, `hyper` handles the HTTP protocol implementation. - -### Async Runtime - -Asynchronous execution is powered by `tokio` with its full feature set enabled. Supporting crates include `tokio-stream` for stream utilities, `async-trait` for async trait definitions, `async-stream` for async stream macros, and `async-lock` for asynchronous locking primitives. - -### Database - -Database operations use `diesel` as the ORM for PostgreSQL, with `diesel_migrations` handling schema migrations. Connection pooling is managed by `r2d2`, and the `redis` crate provides cache client functionality compatible with both Valkey and Redis. - -### Storage - -Cloud storage integration relies on the AWS SDK, with `aws-config` for configuration and `aws-sdk-s3` for S3-compatible storage operations through the drive component. The optional `qdrant-client` crate enables vector database functionality. - -### Security - -Cryptographic operations use several specialized crates. Password hashing is handled by `argon2`, encryption by `aes-gcm`, HMAC authentication by `hmac`, and SHA-256 hashing by `sha2`. - -### Scripting - -The BASIC interpreter is powered by `rhai`, which provides a safe and fast embedded scripting engine. - -### Data Formats - -Serialization and deserialization use `serde` as the core framework, with `serde_json` for JSON support. Additional format support comes from `csv` for CSV parsing and `base64` for Base64 encoding. - -### Document Processing - -Document handling includes `pdf-extract` for PDF text extraction, `mailparse` for email parsing, and `zip` for ZIP archive handling. - -### Communication - -Network communication uses `reqwest` as the HTTP client. Email functionality is split between `lettre` for SMTP sending and the optional `imap` crate for reading emails. Video conferencing is provided by the `livekit` crate. - -### Desktop (Optional) - -Desktop application builds use `tauri` as the framework, along with `tauri-plugin-dialog` for native file dialogs and `tauri-plugin-opener` for opening files and URLs. - -### Utilities - -Common utilities include `anyhow` for error handling, `log` and `env_logger` for logging, `tracing` for structured logging, `chrono` for date and time handling, `uuid` for UUID generation, `regex` for regular expressions, and `rand` for random number generation. - -### Testing - -Test support comes from `mockito` for HTTP mocking and `tempfile` for temporary file handling. - -## Adding a New Dependency: Example - -This walkthrough demonstrates adding JSON Web Token (JWT) support to the project. - -### 1. Choose a Crate - -Search on [crates.io](https://crates.io) to find suitable crates: - -```bash -cargo search jsonwebtoken -``` - -### 2. Add to Cargo.toml - -```toml -[dependencies] -jsonwebtoken = "9.2" -``` - -### 3. Update Dependencies - -```bash -cargo build -``` - -### 4. Import in Code - -In your Rust file (e.g., `src/auth/mod.rs`): - -```rust -use jsonwebtoken::{encode, decode, Header, Validation, EncodingKey, DecodingKey}; -``` - -### 5. Use the Dependency - -```rust -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Serialize, Deserialize)] -struct Claims { - sub: String, - exp: usize, -} - -pub fn create_jwt(user_id: &str) -> Result { - let expiration = chrono::Utc::now() - .checked_add_signed(chrono::Duration::hours(24)) - .unwrap() - .timestamp() as usize; - - let claims = Claims { - sub: user_id.to_owned(), - exp: expiration, - }; - - let secret = std::env::var("JWT_SECRET").unwrap_or_else(|_| "secret".to_string()); - let token = encode( - &Header::default(), - &claims, - &EncodingKey::from_secret(secret.as_ref()), - )?; - - Ok(token) -} -``` - -## Managing Dependencies - -### Updating Dependencies - -To update all dependencies to their latest compatible versions, run `cargo update`. For updating a specific dependency, use `cargo update -p serde` with the package name. - -### Checking for Outdated Dependencies - -The `cargo-outdated` tool helps identify dependencies that have newer versions available: - -```bash -cargo install cargo-outdated -cargo outdated -``` - -### Upgrading to Latest Compatible Versions - -The `cargo-edit` tool provides convenient commands for managing dependencies: - -```bash -cargo install cargo-edit -cargo upgrade -``` - -### Auditing for Security Vulnerabilities - -Regular security audits are essential for production applications: - -```bash -cargo install cargo-audit -cargo audit -``` - -### Viewing the Dependency Tree - -Understanding your dependency graph helps identify bloat and conflicts: - -```bash -cargo tree -``` - -To view dependencies for a specific package: - -```bash -cargo tree -p diesel -``` - -### Finding Duplicate Dependencies - -Different versions of the same crate increase binary size and compile time: - -```bash -cargo tree --duplicates -``` - -## Feature Management - -BotServer uses feature flags to enable optional functionality, allowing users to compile only what they need. - -### Current Features - -```toml -[features] -default = ["desktop"] -vectordb = ["qdrant-client"] -email = ["imap"] -desktop = ["dep:tauri", "dep:tauri-plugin-dialog", "dep:tauri-plugin-opener"] -``` - -### Adding a New Feature - -Start by adding the dependency as optional: - -```toml -[dependencies] -elasticsearch = { version = "8.5", optional = true } -``` - -Then create a feature that enables it: - -```toml -[features] -search = ["elasticsearch"] -``` - -Use conditional compilation in your code to only include the functionality when the feature is enabled: - -```rust -#[cfg(feature = "search")] -pub mod search { - use elasticsearch::Elasticsearch; - - pub fn create_client() -> Elasticsearch { - // Implementation - } -} -``` - -Build with the feature enabled: - -```bash -cargo build --features search -``` - -## Build Dependencies - -Dependencies needed only at build time (used in `build.rs`) go in a separate section: - -```toml -[build-dependencies] -tauri-build = { version = "2", features = [] } -``` - -## Development Dependencies - -Dependencies needed only during testing should be placed in the dev-dependencies section. These are not included in release builds: - -```toml -[dev-dependencies] -mockito = "1.7.0" -tempfile = "3" -``` - -## Dependency Best Practices - -### Version Pinning - -For production builds, prefer specific versions over ranges to ensure reproducible builds. While `serde = "1.0.193"` guarantees a specific version, `serde = "1"` could pull in any 1.x release, potentially introducing unexpected changes. - -### Minimize Dependencies - -Every dependency you add increases build time, binary size, and maintenance burden while introducing potential security risks. Only add dependencies that provide significant value and aren't easily implemented inline. - -### Check License Compatibility - -All dependencies must have licenses compatible with AGPL-3.0. The `cargo-license` tool helps audit your dependency licenses: - -```bash -cargo install cargo-license -cargo license -``` - -### Prefer Maintained Crates - -When choosing between crates that provide similar functionality, evaluate them based on recent release activity, GitHub repository engagement, maintainer responsiveness, and documentation quality. - -### Review Security Advisories - -Make dependency auditing part of your regular development workflow. Running `cargo audit` regularly helps catch known vulnerabilities before they become problems. - -### Use Features to Reduce Size - -Many crates include features you don't need. Instead of enabling everything with `tokio = "1.41"`, specify only the features you actually use: - -```toml -tokio = { version = "1.41", features = ["rt-multi-thread", "net", "sync"] } -``` - -## Common Issues - -### Conflicting Versions - -When multiple crates require different versions of the same dependency, Cargo will fail to resolve the dependency graph. Use `cargo tree` to identify which crates are causing the conflict, then update dependencies or look for alternative crates. - -### Missing System Libraries - -Some crates require system libraries to be installed. If you see linker errors mentioning `cc`, check the crate's documentation for required system packages and refer to the Building from Source guide. - -### Feature Not Found - -Referencing a non-existent feature will cause a build error. Double-check feature names in the crate's `Cargo.toml` on crates.io or in its repository. - -## Removing Dependencies - -To remove a dependency, first delete it from `Cargo.toml`. Then find and remove all import statements using grep or ripgrep: - -```bash -rg "use dependency_name" src/ -``` - -After removing the imports, clean and rebuild: - -```bash -cargo clean -cargo build -``` - -Verify the dependency is completely removed: - -```bash -cargo tree | grep dependency_name -``` - -## Alternative Registries - -### Using a Custom Registry - -For private crates or custom registries, configure the registry in your `Cargo.toml`: - -```toml -[dependencies] -my-crate = { version = "1.0", registry = "my-registry" } - -[registries.my-registry] -index = "https://my-registry.example.com/index" -``` - -For private company crates, consider Git dependencies or a private registry like Artifactory or CloudSmith. - -## Dependency Documentation - -Good documentation makes dependencies easier to maintain. Add comments in `Cargo.toml` explaining why each dependency exists: - -```toml -[dependencies] -# JWT token generation and validation -jsonwebtoken = "9.2" -``` - -Document usage in your code with doc comments that explain the dependency's role: - -```rust -/// Creates a JWT token for user authentication. -/// -/// Uses the `jsonwebtoken` crate to encode user claims -/// with an expiration time. -pub fn create_jwt(user_id: &str) -> Result { - // Implementation -} -``` - -## Next Steps - -Review the [Module Structure](./crates.md) documentation to understand where to use new dependencies within the codebase. The [Service Layer](./services.md) guide shows how dependencies integrate into the application architecture. For extending BASIC with new functionality that leverages dependencies, see [Creating Custom Keywords](./custom-keywords.md). \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/docker-deployment.md b/docs/src/chapter-07-gbapp/docker-deployment.md deleted file mode 100644 index 1d95ffb4..00000000 --- a/docs/src/chapter-07-gbapp/docker-deployment.md +++ /dev/null @@ -1,215 +0,0 @@ -# Docker Deployment - -> **Note**: Docker support is currently **experimental**. - -## Deployment Options - -| Option | Description | Best For | -|--------|-------------|----------| -| **All-in-One** | Single container with all components | Development, testing | -| **Microservices** | Separate containers per component | Production, scaling | - -## Option 1: All-in-One Container - -### Quick Start - -```bash -docker run -d \ - --name botserver \ - -p 8000:8000 \ - -p 9000:9000 \ - -v botserver-data:/opt/gbo/data \ - -e ADMIN_PASS=your-secure-password \ - pragmatismo/botserver:latest -``` - -### Docker Compose - -```yaml -version: '3.8' - -services: - botserver: - image: pragmatismo/botserver:latest - restart: unless-stopped - ports: - - "8000:8000" - - "9000:9000" - - "9001:9001" - volumes: - - botserver-data:/opt/gbo/data - - ./work:/opt/gbo/work - environment: - - ADMIN_PASS=${ADMIN_PASS:-changeme} - - DOMAIN=${DOMAIN:-localhost} - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8000/health"] - interval: 30s - timeout: 10s - retries: 3 - -volumes: - botserver-data: -``` - -**Resources:** 2 CPU cores, 4GB RAM minimum - -## Option 2: Microservices - -```yaml -version: '3.8' - -services: - postgres: - image: postgres:16-alpine - volumes: - - postgres-data:/var/lib/postgresql/data - environment: - POSTGRES_USER: botserver - POSTGRES_PASSWORD: ${DB_PASSWORD} - POSTGRES_DB: botserver - networks: - - gb-network - - minio: - image: minio/minio:latest - command: server /data --console-address ":9001" - ports: - - "9000:9000" - - "9001:9001" - volumes: - - minio-data:/data - environment: - MINIO_ROOT_USER: ${DRIVE_ACCESSKEY} - MINIO_ROOT_PASSWORD: ${DRIVE_SECRET} - networks: - - gb-network - - qdrant: - image: qdrant/qdrant:latest - ports: - - "6333:6333" - volumes: - - qdrant-data:/qdrant/storage - networks: - - gb-network - - botserver: - image: pragmatismo/botserver:latest - depends_on: - - postgres - - minio - - qdrant - ports: - - "8000:8000" - volumes: - - ./work:/opt/gbo/work - environment: - DATABASE_URL: postgres://botserver:${DB_PASSWORD}@postgres:5432/botserver - DRIVE_URL: http://minio:9000 - DRIVE_ACCESSKEY: ${DRIVE_ACCESSKEY} - DRIVE_SECRET: ${DRIVE_SECRET} - QDRANT_URL: http://qdrant:6333 - ADMIN_PASS: ${ADMIN_PASS} - networks: - - gb-network - -networks: - gb-network: - -volumes: - postgres-data: - minio-data: - qdrant-data: -``` - -### Environment File (.env) - -```bash -DB_PASSWORD=secure-db-password -DRIVE_ACCESSKEY=minioadmin -DRIVE_SECRET=secure-minio-secret -ADMIN_PASS=admin-password -DOMAIN=your-domain.com -``` - -## Kubernetes - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: botserver -spec: - replicas: 3 - selector: - matchLabels: - app: botserver - template: - spec: - containers: - - name: botserver - image: pragmatismo/botserver:latest - ports: - - containerPort: 8000 - resources: - requests: - memory: "512Mi" - cpu: "250m" - limits: - memory: "2Gi" - cpu: "1000m" - livenessProbe: - httpGet: - path: /health - port: 8000 ---- -apiVersion: v1 -kind: Service -metadata: - name: botserver -spec: - selector: - app: botserver - ports: - - port: 80 - targetPort: 8000 - type: LoadBalancer -``` - -## Health Endpoints - -| Service | Endpoint | -|---------|----------| -| BotServer | `GET /health` | -| PostgreSQL | `pg_isready` | -| MinIO | `GET /minio/health/live` | -| Qdrant | `GET /health` | - -## Troubleshooting - -| Issue | Solution | -|-------|----------| -| Container won't start | `docker logs gb-botserver` | -| DB connection failed | `docker exec -it gb-botserver psql $DATABASE_URL -c "SELECT 1"` | -| Memory issues | Increase limits in compose or add `deploy.resources.limits.memory` | - -## Migration from Non-Docker - -```bash -# 1. Backup data -pg_dump botserver > backup.sql -mc cp --recursive /path/to/drive minio/backup/ - -# 2. Start Docker containers - -# 3. Restore -docker exec -i gb-postgres psql -U botserver < backup.sql -docker exec gb-minio mc cp --recursive /backup minio/drive/ -``` - -## See Also - -- [Installation](../chapter-01/installation.md) - Local installation -- [Container Deployment (LXC)](./containers.md) - Linux containers -- [Scaling](./scaling.md) - Load balancing and scaling \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/example-gbapp.md b/docs/src/chapter-07-gbapp/example-gbapp.md deleted file mode 100644 index bf4659a9..00000000 --- a/docs/src/chapter-07-gbapp/example-gbapp.md +++ /dev/null @@ -1,354 +0,0 @@ -# Example: Creating a New gbapp Virtual Crate - -This guide walks through creating a new gbapp virtual crate called `analytics` that adds analytics capabilities to BotServer. - -## Step 1: Create the Module Structure - -Create your gbapp directory in `src/`: - -``` -src/analytics/ # analytics.gbapp virtual crate -├── mod.rs # Module definition -├── keywords.rs # BASIC keywords -├── services.rs # Core functionality -├── models.rs # Data structures -└── tests.rs # Unit tests -``` - -## Step 2: Define the Module - -**src/analytics/mod.rs** -```rust -//! Analytics gbapp - Provides analytics and reporting functionality -//! -//! This virtual crate adds analytics keywords to BASIC and provides -//! services for tracking and reporting bot interactions. - -pub mod keywords; -pub mod services; -pub mod models; - -#[cfg(test)] -mod tests; - -use crate::shared::state::AppState; -use std::sync::Arc; - -/// Initialize the analytics gbapp -pub fn init(state: Arc) -> Result<(), Box> { - log::info!("Initializing analytics.gbapp virtual crate"); - - // Initialize analytics services - services::init_analytics_service(&state)?; - - Ok(()) -} -``` - -## Step 3: Add BASIC Keywords - -**src/analytics/keywords.rs** -```rust -use crate::shared::state::AppState; -use rhai::{Engine, Dynamic}; -use std::sync::Arc; - -/// Register analytics keywords with the BASIC interpreter -pub fn register_keywords(engine: &mut Engine, state: Arc) { - let state_clone = state.clone(); - - // TRACK EVENT keyword - engine.register_fn("TRACK EVENT", move |event_name: String, properties: String| -> String { - let result = tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - crate::analytics::services::track_event(&state_clone, &event_name, &properties).await - }) - }); - - match result { - Ok(_) => format!("Event '{}' tracked", event_name), - Err(e) => format!("Failed to track event: {}", e), - } - }); - - // GET ANALYTICS keyword - engine.register_fn("GET ANALYTICS", move |metric: String, timeframe: String| -> Dynamic { - let result = tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - crate::analytics::services::get_analytics(&metric, &timeframe).await - }) - }); - - match result { - Ok(data) => Dynamic::from(data), - Err(_) => Dynamic::UNIT, - } - }); - - // GENERATE REPORT keyword - engine.register_fn("GENERATE REPORT", move |report_type: String| -> String { - // Use LLM to generate natural language report - let data = crate::analytics::services::get_report_data(&report_type); - - let prompt = format!( - "Generate a {} report from this data: {}", - report_type, data - ); - - // This would call the LLM service - format!("Report generated for: {}", report_type) - }); -} -``` - -## Step 4: Implement Services - -**src/analytics/services.rs** -```rust -use crate::shared::state::AppState; -use crate::shared::models::AnalyticsEvent; -use std::sync::Arc; -use anyhow::Result; - -/// Initialize analytics service -pub fn init_analytics_service(state: &Arc) -> Result<()> { - // Set up database tables, connections, etc. - log::debug!("Analytics service initialized"); - Ok(()) -} - -/// Track an analytics event -pub async fn track_event( - state: &Arc, - event_name: &str, - properties: &str, -) -> Result<()> { - // Store event in database - let conn = state.conn.get()?; - - // Implementation details... - log::debug!("Tracked event: {}", event_name); - - Ok(()) -} - -/// Get analytics data -pub async fn get_analytics(metric: &str, timeframe: &str) -> Result { - // Query analytics data - let results = match metric { - "user_count" => get_user_count(timeframe).await?, - "message_volume" => get_message_volume(timeframe).await?, - "engagement_rate" => get_engagement_rate(timeframe).await?, - _ => return Err(anyhow::anyhow!("Unknown metric: {}", metric)), - }; - - Ok(results) -} - -/// Get data for report generation -pub fn get_report_data(report_type: &str) -> String { - // Gather data based on report type - match report_type { - "daily" => get_daily_report_data(), - "weekly" => get_weekly_report_data(), - "monthly" => get_monthly_report_data(), - _ => "{}".to_string(), - } -} - -// Helper functions -async fn get_user_count(timeframe: &str) -> Result { - // Implementation - Ok("100".to_string()) -} - -async fn get_message_volume(timeframe: &str) -> Result { - // Implementation - Ok("5000".to_string()) -} - -async fn get_engagement_rate(timeframe: &str) -> Result { - // Implementation - Ok("75%".to_string()) -} - -fn get_daily_report_data() -> String { - // Gather daily metrics - r#"{"users": 100, "messages": 1500, "sessions": 50}"#.to_string() -} - -fn get_weekly_report_data() -> String { - // Gather weekly metrics - r#"{"users": 500, "messages": 8000, "sessions": 300}"#.to_string() -} - -fn get_monthly_report_data() -> String { - // Gather monthly metrics - r#"{"users": 2000, "messages": 35000, "sessions": 1200}"#.to_string() -} -``` - -## Step 5: Define Data Models - -**src/analytics/models.rs** -```rust -use serde::{Deserialize, Serialize}; -use chrono::{DateTime, Utc}; - -#[derive(Debug, Serialize, Deserialize)] -pub struct AnalyticsEvent { - pub id: uuid::Uuid, - pub event_name: String, - pub properties: serde_json::Value, - pub user_id: Option, - pub session_id: String, - pub timestamp: DateTime, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct MetricSnapshot { - pub metric_name: String, - pub value: f64, - pub timestamp: DateTime, - pub dimensions: serde_json::Value, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct Report { - pub report_type: String, - pub generated_at: DateTime, - pub data: serde_json::Value, - pub summary: String, -} -``` - -## Step 6: Register with Core - -Update `src/basic/keywords/mod.rs` to include your gbapp: - -```rust -use crate::analytics; - -pub fn register_all_keywords(engine: &mut Engine, state: Arc) { - // ... existing keywords - - // Register analytics.gbapp keywords - analytics::keywords::register_keywords(engine, state.clone()); -} -``` - -Update `src/main.rs` or initialization code: - -```rust -// Initialize analytics gbapp -analytics::init(state.clone())?; -``` - -## Step 7: Add Tests - -**src/analytics/tests.rs** -```rust -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_track_event() { - // Test event tracking - let event_name = "user_login"; - let properties = r#"{"user_id": "123"}"#; - - // Test implementation - assert!(true); - } - - #[tokio::test] - async fn test_get_analytics() { - // Test analytics retrieval - let metric = "user_count"; - let timeframe = "daily"; - - // Test implementation - assert!(true); - } -} -``` - -## Step 8: Use in BASIC Scripts - -Now your gbapp keywords are available in BASIC: - -```basic -' Track user actions -TRACK EVENT "button_clicked", "button=submit" - -' Get metrics -daily_users = GET ANALYTICS "user_count", "daily" -TALK "Daily active users: " + daily_users - -' Generate AI-powered report -report = GENERATE REPORT "weekly" -TALK report - -' Combine with LLM for insights -metrics = GET ANALYTICS "all", "monthly" -insights = LLM "Analyze these metrics and provide insights: " + metrics -TALK insights -``` - -## Step 9: Add Feature Flag (Optional) - -If your gbapp should be optional, add it to `Cargo.toml`: - -```toml -[features] -analytics = [] - -# Include in default features if always needed -default = ["ui-server", "chat", "analytics"] -``` - -Then conditionally compile: - -```rust -#[cfg(feature = "analytics")] -pub mod analytics; - -#[cfg(feature = "analytics")] -analytics::keywords::register_keywords(engine, state.clone()); -``` - -## Benefits of This Approach - -1. **Clean Separation**: Your gbapp is self-contained -2. **Easy Discovery**: Visible in `src/analytics/` -3. **Type Safety**: Rust compiler checks everything -4. **Native Performance**: Compiles into the main binary -5. **Familiar Structure**: Like the old `.gbapp` packages - -## Best Practices - -✅ **DO:** -- Keep your gbapp focused on one domain -- Provide clear BASIC keywords -- Use LLM for complex logic -- Write comprehensive tests -- Document your keywords - -❌ **DON'T:** -- Create overly complex implementations -- Duplicate existing functionality -- Skip error handling -- Forget about async/await -- Ignore the BASIC-first philosophy - -## Summary - -Creating a gbapp virtual crate is straightforward: -1. Create a module in `src/` -2. Define keywords for BASIC -3. Implement services -4. Register with core -5. Use in BASIC scripts - -Your gbapp becomes part of BotServer's compiled binary, providing native performance while maintaining the conceptual clarity of the package system. Most importantly, remember that the implementation should be minimal - let BASIC + LLM handle the complexity! \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/infrastructure.md b/docs/src/chapter-07-gbapp/infrastructure.md deleted file mode 100644 index 21d07880..00000000 --- a/docs/src/chapter-07-gbapp/infrastructure.md +++ /dev/null @@ -1,542 +0,0 @@ -# Infrastructure Design - -This chapter covers the complete infrastructure design for General Bots, including scaling, security, secrets management, observability, and high availability. - -## Architecture Overview - -General Bots uses a modular architecture where each component runs in isolated LXC containers. This provides isolation where each service has its own filesystem and process space, scalability through adding more containers to handle increased load, security since compromised components cannot affect others, and portability allowing containers to move between hosts easily. - -## Component Diagram -## High Availability Architecture - -![Infrastructure Architecture](../assets/infrastructure-architecture.svg) - -*Production-ready infrastructure with automatic scaling, load balancing, and multi-tenant isolation.* - -## Encryption at Rest - -All data stored by General Bots is encrypted at rest using AES-256-GCM. - -### Database Encryption - -PostgreSQL uses Transparent Data Encryption (TDE): - -```csv -# config.csv -encryption-at-rest,true -encryption-algorithm,aes-256-gcm -encryption-key-source,vault -``` - -Enable in PostgreSQL: - -```sql --- Enable pgcrypto extension -CREATE EXTENSION IF NOT EXISTS pgcrypto; - --- Encrypted columns use pgp_sym_encrypt -ALTER TABLE bot_memories -ADD COLUMN value_encrypted bytea; - -UPDATE bot_memories -SET value_encrypted = pgp_sym_encrypt(value, current_setting('app.encryption_key')); -``` - -### File Storage Encryption - -MinIO server-side encryption is enabled using SSE-S3 for automatic encryption or SSE-C for customer-managed keys: - -```bash -# Enable SSE-S3 encryption -mc encrypt set sse-s3 local/gbo-bucket - -# Or use customer-managed keys (SSE-C) -mc encrypt set sse-c local/gbo-bucket -``` - -Configuration: - -```csv -# config.csv -drive-encryption,true -drive-encryption-type,sse-s3 -drive-encryption-key,vault:gbo/encryption/drive_key -``` - -### Redis Encryption - -Redis with TLS and encrypted RDB provides secure caching: - -```conf -# redis.conf -tls-port 6379 -port 0 -tls-cert-file /opt/gbo/conf/certificates/redis/server.crt -tls-key-file /opt/gbo/conf/certificates/redis/server.key -tls-ca-cert-file /opt/gbo/conf/certificates/ca.crt - -# Enable RDB encryption (Redis 7.2+) -rdb-save-incremental-fsync yes -``` - -### Vector Database Encryption - -Qdrant with encrypted storage uses TLS for transport and filesystem-level encryption for data at rest: - -```yaml -# qdrant/config.yaml -storage: - storage_path: /opt/gbo/data/qdrant - on_disk_payload: true - -service: - enable_tls: true - -# Disk encryption handled at filesystem level -``` - -### Filesystem-Level Encryption - -For comprehensive encryption, use LUKS on the data partition: - -```bash -# Create encrypted partition for /opt/gbo/data -cryptsetup luksFormat /dev/sdb1 -cryptsetup open /dev/sdb1 gbo-data -mkfs.ext4 /dev/mapper/gbo-data -mount /dev/mapper/gbo-data /opt/gbo/data -``` - -## Media Processing: LiveKit - -LiveKit handles all media processing needs for General Bots. WebRTC is native to LiveKit. Recording is built-in via the Egress service. Transcoding uses the Egress service. Streaming and AI integration are built into LiveKit. - -LiveKit's Egress service handles room recording, participant recording, livestreaming to YouTube and Twitch, and track composition. - -### LiveKit Configuration - -```csv -# config.csv -meet-provider,livekit -meet-server-url,wss://localhost:7880 -meet-api-key,vault:gbo/meet/api_key -meet-api-secret,vault:gbo/meet/api_secret -meet-recording-enabled,true -meet-transcription-enabled,true -``` - -## Messaging: Redis - -General Bots uses Redis for all messaging needs including session state, PubSub for real-time communication, and Streams for persistence: - -```rust -// Session state -redis::cmd("SET").arg("session:123").arg(state_json) - -// PubSub for real-time -redis::cmd("PUBLISH").arg("channel:bot-1").arg(message) - -// Streams for persistence (optional) -redis::cmd("XADD").arg("stream:events").arg("*").arg("event").arg(data) -``` - -Configuration: - -```csv -# config.csv -messaging-provider,redis -messaging-persistence,streams -messaging-retention-hours,24 -``` - -## Sharding Strategies - -### Option 1: Tenant-Based Sharding (Recommended) - -Each tenant or organization gets isolated databases. - -## Multi-Tenant Architecture - -Each tenant gets isolated resources with dedicated database schemas, cache namespaces, and vector collections. The router maps tenant IDs to their respective data stores automatically. - -Key isolation features include database-per-tenant or schema-per-tenant options, namespace isolation in Valkey cache, collection isolation in Qdrant vectors, and bucket isolation in SeaweedFS storage. - -Configuration: - -```csv -# config.csv -shard-strategy,tenant -shard-auto-provision,true -shard-isolation-level,database -``` - -Advantages include complete data isolation which is compliance friendly, easy backup and restore per tenant, simplicity, and no cross-tenant queries. Disadvantages include more resources per tenant, complex tenant migration, and connection pool overhead. - -### Option 2: Hash-Based Sharding - -Distribute by user or session ID hash. For example, a user_id of 12345 produces a hash that modulo num_shards equals 2, routing to shard-2. - -Configuration: - -```csv -# config.csv -shard-strategy,hash -shard-count,4 -shard-key,user_id -shard-algorithm,consistent-hash -``` - -Advantages include even distribution, predictable routing, and good performance for high-volume single-tenant deployments. Disadvantages include complex resharding, difficult cross-shard queries, and no tenant isolation. - -### Option 3: Time-Based Sharding - -For time-series data like logs and analytics: - -```csv -# config.csv -shard-strategy,time -shard-interval,monthly -shard-retention-months,12 -shard-auto-archive,true -``` - -This automatically creates partitions named messages_2024_01, messages_2024_02, messages_2024_03, and so on. - -### Option 4: Geographic Sharding - -Route by user location: - -```csv -# config.csv -shard-strategy,geo -shard-regions,us-east,eu-west,ap-south -shard-default,us-east -shard-detection,ip -``` - -## Geographic Distribution - -The global router uses GeoIP to direct users to the nearest regional cluster. US-East in Virginia runs a full cluster, EU-West in Frankfurt runs a full cluster, and AP-South in Singapore runs a full cluster. Each regional cluster runs independently with data replication between regions for disaster recovery. - -## Auto-Scaling with LXC - -### Configuration - -```csv -# config.csv - Auto-scaling settings -scale-enabled,true -scale-min-instances,1 -scale-max-instances,10 -scale-cpu-threshold,70 -scale-memory-threshold,80 -scale-request-threshold,1000 -scale-cooldown-seconds,300 -scale-check-interval,30 -``` - -### Scaling Rules - -| Metric | Scale Up | Scale Down | -|--------|----------|------------| -| CPU | > 70% for 2 min | < 30% for 5 min | -| Memory | > 80% for 2 min | < 40% for 5 min | -| Requests/sec | > 1000 | < 200 | -| Response time | > 2000ms | < 500ms | -| Queue depth | > 100 | < 10 | - -### Auto-Scale Service - -The auto-scaler runs as a systemd service: - -```ini -# /etc/systemd/system/gbo-autoscale.service -[Unit] -Description=General Bots Auto-Scaler -After=network.target - -[Service] -Type=simple -ExecStart=/opt/gbo/scripts/autoscale.sh -Restart=always -RestartSec=10 - -[Install] -WantedBy=multi-user.target -``` - -## Container Lifecycle - -The startup flow begins with creating the LXC container from a template, then configuring resources for CPU, memory, and storage, then starting the BotServer binary, and finally marking the container as ready and adding it to the load balancer pool. - -The shutdown flow begins with an active container serving requests, then draining to stop accepting new connections, then stopping with a graceful BotServer shutdown, and finally deleting or returning the container to the pool. - -## Load Balancing - -### Caddy Configuration - -```caddyfile -{ - admin off - auto_https on -} - -bot.example.com { - # Rate limiting - rate_limit { - zone api { - key {remote_host} - events 100 - window 1m - } - } - - # WebSocket (sticky sessions) - handle /ws* { - reverse_proxy botserver-1:8080 botserver-2:8080 { - lb_policy cookie - health_uri /api/health - health_interval 10s - } - } - - # API (round robin) - handle /api/* { - reverse_proxy botserver-1:8080 botserver-2:8080 { - lb_policy round_robin - fail_duration 30s - } - } -} -``` - -### Rate Limiting Configuration - -```csv -# config.csv - Rate limiting -rate-limit-enabled,true -rate-limit-requests,100 -rate-limit-window,60 -rate-limit-burst,20 -rate-limit-by,ip - -# Per-endpoint limits -rate-limit-api-chat,30 -rate-limit-api-files,50 -rate-limit-api-auth,10 -rate-limit-api-llm,20 -``` - -## Failover Systems - -### Health Checks - -Every service exposes `/health`: - -```json -{ - "status": "healthy", - "version": "6.1.0", - "checks": { - "database": {"status": "ok", "latency_ms": 5}, - "cache": {"status": "ok", "latency_ms": 2}, - "vectordb": {"status": "ok", "latency_ms": 10}, - "llm": {"status": "ok", "latency_ms": 50} - } -} -``` - -### Circuit Breaker - -```csv -# config.csv -circuit-breaker-enabled,true -circuit-breaker-threshold,5 -circuit-breaker-timeout,30 -circuit-breaker-half-open-requests,3 -``` - -The circuit breaker has three states. Closed represents normal operation while counting failures. Open means failing fast and returning errors immediately. Half-Open tests with limited requests before deciding to close or reopen. - -### Database Failover - -PostgreSQL with streaming replication provides high availability. - -## Database Replication - -PostgreSQL replication is managed by Patroni for automatic failover. The Primary serves as the write leader handling all write operations. The Replica provides synchronous replication from the primary for read scaling. Patroni acts as the failover manager performing automatic leader election on failure. - -Failover happens automatically within seconds, with clients redirected via the connection pooler. - -### Graceful Degradation - -```csv -# config.csv - Fallbacks -fallback-llm-enabled,true -fallback-llm-provider,local -fallback-llm-model,DeepSeek-R1-Distill-Qwen-1.5B - -fallback-cache-enabled,true -fallback-cache-mode,memory - -fallback-vectordb-enabled,true -fallback-vectordb-mode,keyword-search -``` - -## Secrets Management (Vault) - -### Architecture - -The minimal `.env` file contains only Vault connection details. All other secrets are stored in Vault and fetched at runtime. The Vault server stores secrets organized by path including gbo/drive for access keys, gbo/tables for database credentials, gbo/cache for passwords, gbo/directory for client credentials, gbo/email for mail credentials, gbo/llm for provider API keys, gbo/encryption for master and data keys, and gbo/meet for API credentials. - -### Zitadel vs Vault - -Zitadel handles user authentication, OAuth/OIDC, and MFA. Vault handles service credentials, API keys, and encryption keys. Use both together where Zitadel manages user identity and SSO while Vault manages service secrets and encryption keys. - -### Minimal .env with Vault - -```bash -# .env - Only Vault and Directory needed -VAULT_ADDR=https://localhost:8200 -VAULT_TOKEN=hvs.your-token-here - -# Directory for user auth (Zitadel) -DIRECTORY_URL=https://localhost:8080 -DIRECTORY_PROJECT_ID=your-project-id - -# All other secrets fetched from Vault at runtime -``` - -## Observability - -### Option 1: InfluxDB + Grafana (Current) - -For time-series metrics: - -```csv -# config.csv -observability-provider,influxdb -observability-url,http://localhost:8086 -observability-org,pragmatismo -observability-bucket,metrics -``` - -### Option 2: Vector + InfluxDB (Recommended) - -Vector serves as a log and metric aggregator. BotServer logs flow to Vector which pipelines them to InfluxDB for metrics storage and Grafana for dashboards. - -Vector configuration: - -```toml -# vector.toml -[sources.botserver_logs] -type = "file" -include = ["/opt/gbo/logs/*.log"] - -[transforms.parse_logs] -type = "remap" -inputs = ["botserver_logs"] -source = ''' -. = parse_json!(.message) -''' - -[sinks.influxdb] -type = "influxdb_metrics" -inputs = ["parse_logs"] -endpoint = "http://localhost:8086" -org = "pragmatismo" -bucket = "metrics" -``` - -### Replacing log.* Calls with Vector - -Instead of replacing all log calls, configure Vector to collect logs from files, parse and enrich them, and route to appropriate sinks: - -```toml -# Route errors to alerts -[transforms.filter_errors] -type = "filter" -inputs = ["parse_logs"] -condition = '.level == "error"' - -[sinks.alertmanager] -type = "http" -inputs = ["filter_errors"] -uri = "http://alertmanager:9093/api/v1/alerts" -``` - -## Search: Qdrant - -Qdrant handles all search needs in General Bots, providing both vector similarity search for semantic queries and payload filtering for keyword-like queries. - -### Hybrid Search with Qdrant - -Qdrant supports hybrid search combining vector similarity with keyword filters: - -```rust -// Combine vector similarity + keyword filter -let search_request = SearchPoints { - collection_name: "kb".to_string(), - vector: query_embedding, - limit: 10, - filter: Some(Filter { - must: vec![ - Condition::Field(FieldCondition { - key: "content".to_string(), - r#match: Some(Match::Text("keyword".to_string())), - }), - ], - ..Default::default() - }), - ..Default::default() -}; -``` - -## Workflow Scheduling: SET SCHEDULE - -General Bots uses the SET SCHEDULE keyword for all scheduling needs: - -```basic -REM Run every day at 9 AM -SET SCHEDULE "daily-report" TO "0 9 * * *" - TALK "Running daily report..." - result = GET "/api/reports/daily" - SEND MAIL "admin@example.com", "Daily Report", result -END SCHEDULE -``` - -## MFA with Zitadel - -### Configuration - -MFA is handled transparently by Zitadel: - -```csv -# config.csv -auth-mfa-enabled,true -auth-mfa-methods,totp,sms,email,whatsapp -auth-mfa-required-for,admin,sensitive-operations -auth-mfa-grace-period-days,7 -``` - -### Zitadel MFA Settings - -In the Zitadel console, navigate to Settings then Login Behavior. Enable Multi-Factor Authentication and select allowed methods including TOTP for authenticator apps, SMS, Email, and WebAuthn/FIDO2. - -### WhatsApp MFA Channel - -```csv -# config.csv -auth-mfa-whatsapp-enabled,true -auth-mfa-whatsapp-provider,twilio -auth-mfa-whatsapp-template,mfa_code -``` - -The flow proceeds as follows: the user logs in with password, Zitadel triggers MFA, a code is sent via WhatsApp, the user enters the code, and the session is established. - -## Summary: What You Need - -PostgreSQL, Redis, Qdrant, MinIO, and Zitadel are required components. Vault, InfluxDB, and LiveKit are recommended for production deployments. Vector is optional for log aggregation. - -## Next Steps - -The Scaling and Load Balancing chapter provides a detailed scaling guide. The Container Deployment chapter covers LXC setup. The Security Features chapter offers a security deep dive. The LLM Providers appendix helps with model selection. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/keyword-refactoring.md b/docs/src/chapter-07-gbapp/keyword-refactoring.md deleted file mode 100644 index 59d7217a..00000000 --- a/docs/src/chapter-07-gbapp/keyword-refactoring.md +++ /dev/null @@ -1 +0,0 @@ -# Keyword Refactoring Plan diff --git a/docs/src/chapter-07-gbapp/observability.md b/docs/src/chapter-07-gbapp/observability.md deleted file mode 100644 index d0b857f1..00000000 --- a/docs/src/chapter-07-gbapp/observability.md +++ /dev/null @@ -1,77 +0,0 @@ -# Observability - -This chapter describes the observability infrastructure that General Bots provides for monitoring system health, collecting logs, and tracking metrics. The observability system operates automatically without requiring code changes, giving administrators visibility into platform behavior and helping identify issues before they impact users. - -## Understanding the Observability System - -General Bots implements observability through an integrated pipeline that collects, parses, routes, and stores operational data from all system components. The pipeline reads log files from the centralized logs directory within the botserver-stack folder, extracts structured information including log levels, timestamps, and messages, routes different types of data to appropriate destinations such as alerts for errors and storage for metrics, and enriches entries with contextual information like hostnames and service names. - -This automated approach means administrators don't need to instrument code or configure complex logging frameworks. The system captures operational data from all components using consistent formats and routes it to useful destinations without manual intervention. - -## Log Directory Organization - -The logging system organizes output by component within the `./botserver-stack/logs/` directory. System logs from the main BotServer application appear in the system subdirectory. Storage service operations are captured in the drive subdirectory. Database activity from PostgreSQL goes to the tables subdirectory. The cache subdirectory contains logs from the caching layer. LLM server interactions are recorded in the llm subdirectory. - -Additional services have their own logging locations. Email service logs appear in the email subdirectory. Identity and authentication events are captured in the directory subdirectory. Vector database operations go to the vectordb subdirectory. Video meeting activities are logged in the meet subdirectory. - -This organization makes it straightforward to investigate issues in specific components without wading through unrelated log entries. - -## Installation and Configuration - -The observability component installs automatically during the bootstrap process, ensuring that monitoring begins from the first system start. Administrators who need to install it separately can use the botserver install command with the observability parameter. - -Configuration for the observability pipeline resides in the monitoring configuration file within the botserver-stack conf directory. This Vector configuration file controls how logs are collected, parsed, transformed, and routed to their destinations. - -## Log Format Conventions - -BotServer generates logs in a standard format that includes the timestamp in ISO 8601 format with millisecond precision, the log level indicating severity, the module path identifying the code location, and the message describing what occurred. This structured format enables automated parsing while remaining human-readable for direct inspection. - -The pipeline parses these logs automatically, extracting fields for indexing and routing. Errors are identified by level and routed to alerting systems while informational messages flow to long-term storage for historical analysis. - -## Metrics Collection - -The platform exposes operational metrics through a Prometheus-compatible endpoint at `/api/metrics`, enabling integration with standard monitoring infrastructure. Available metrics track log event counts by severity level, error totals broken down by service, currently active session counts, total messages processed since startup, and LLM response latency measurements. - -These metrics enable administrators to understand system behavior over time, identify trends that might indicate developing problems, and verify that the platform operates within expected parameters. The Prometheus format ensures compatibility with common visualization and alerting tools. - -## Alerting Configuration - -The observability system can send alerts automatically when error conditions occur. Webhook alerts POST event data to the admin alerts API endpoint, enabling integration with custom alerting systems. Slack integration sends notifications to configured channels when properly configured. Email alerts reach administrators directly when SMTP settings are provided. - -Alert thresholds are configurable through the bot's config.csv file. The CPU threshold setting triggers alerts when processor utilization exceeds the specified percentage. Memory threshold configuration works similarly for RAM usage. Response time thresholds flag slow operations that might indicate performance degradation. - -Tuning these thresholds for your environment prevents alert fatigue from false positives while ensuring genuine issues receive attention. - -## Dashboard Visualization - -A pre-built Grafana dashboard template is available in the templates directory, providing immediate visualization of key metrics. The dashboard includes panels for active sessions showing current load, messages per minute indicating throughput, error rates highlighting problems, and LLM latency percentiles revealing AI response performance. - -Importing this dashboard into a Grafana instance connected to your metrics storage creates an operational overview suitable for operations teams and helps during incident investigation. - -## Log Level Configuration - -The logging system supports four severity levels that control which messages are captured and the volume of output generated. - -Error level captures failures that require attention, such as database connection losses or file permission problems. Warning level records unexpected conditions that were handled but might indicate developing issues. Info level logs normal operations and key events, providing a record of system activity without excessive detail. Debug level includes detailed flow information useful during development and troubleshooting but too verbose for normal production operation. - -The log level setting in config.csv controls the minimum severity that produces output. Setting it to info captures everything except debug messages, providing operational visibility without overwhelming log storage. - -## Troubleshooting Common Issues - -When logs aren't being collected as expected, several common causes should be investigated. First, verify that the observability service is running and hasn't crashed or been stopped. Second, check that the log directory permissions allow the collection process to read the files. Third, review the observability service's own logs for errors that might explain the collection failure. - -High log volume can overwhelm storage and make analysis difficult. Raising the log level from debug to info significantly reduces volume by eliminating detailed trace messages. Configuring retention policies in the metrics storage prevents unbounded growth. Filtering debug-level logs before they reach long-term storage reduces costs while preserving important operational data. - -## Operational Guidelines - -Effective observability requires attention to both technical configuration and operational practices. Log content should never include sensitive data like passwords, tokens, or personally identifiable information, as logs often flow to systems with broader access than the application itself. - -Using appropriate log levels keeps signal-to-noise ratios manageable. Reserve error level for actual failures requiring investigation. Use info level for normal operations that help understand system behavior. Avoid overusing warning level, which loses meaning when applied too broadly. - -Monitoring should focus on trends rather than just instantaneous values. Gradual increases in error rates or response times often indicate developing problems before they become critical failures. Alert configuration should consider baseline behavior and flag deviations rather than simple threshold crossings. - -Establishing observability early in deployment ensures that baseline data exists when problems occur. Trying to instrument a system during an incident rarely produces useful results. - -## Related Documentation - -For additional context on operating General Bots at scale, the Scaling and Load Balancing chapter explains how observability integrates with clustered deployments. The Infrastructure Design chapter provides the full architectural overview showing how observability fits into the complete system. The Monitoring Dashboard section describes the built-in monitoring interface available through the administrative UI. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/philosophy.md b/docs/src/chapter-07-gbapp/philosophy.md deleted file mode 100644 index 2d8f5c8c..00000000 --- a/docs/src/chapter-07-gbapp/philosophy.md +++ /dev/null @@ -1,221 +0,0 @@ -# The gbapp Philosophy: Let Machines Do Machine Work - -## Core Principle: Automation First - -In 2025, the gbapp philosophy is simple and powerful: if a machine can do the work, let it do the work. This principle guides every decision about how to build and extend General Bots. Rather than writing code manually, you describe what you need and let AI handle the implementation details. - - -## The Hierarchy of Development - -The development approach in General Bots follows a clear hierarchy based on what percentage of work falls into each category. - -### LLM First (90% of cases) - -The vast majority of work should be handled by letting AI write the code for you. Instead of implementing complex logic yourself, describe what you want in natural language and let the LLM generate the solution. - -```basic -' Don't write complex logic - describe what you want -result = LLM "Generate a function that validates email addresses and returns true/false: " + email -``` - -### BASIC for Flow Control (9% of cases) - -BASIC serves as the orchestration layer that connects AI calls together. Think of it as glue code that manages the flow between different operations. The logic itself lives in LLM calls while BASIC handles sequencing and data flow. - -```basic -' BASIC is just glue between AI calls -data = GET "api/data" -processed = LLM "Process this: " + data -SET "results", processed -``` - -### Rust for Core Only (1% of cases) - -Writing Rust code should be reserved for rare situations where you are contributing new keywords to the core platform, building fundamental infrastructure that many bots will use, or optimizing critical performance paths where every millisecond matters. Most developers will never need to write Rust because BASIC and LLM calls handle nearly every use case. - - -## What gbapp Really Is - -Understanding what gbapp is and is not helps clarify the development model. - -The gbapp concept is not about external plugin packages that you download separately. It is not about separate npm modules or package managers. It is not a way to bypass BASIC and write custom code. It is not about runtime extensions that modify behavior dynamically. - -Instead, gbapp represents virtual crates inside the `src/` directory that are Rust modules compiling together into a single binary. The concept serves as a bridge between older plugin-based thinking and the modern integrated approach. It provides a familiar mental model for developers who want to contribute to the platform. Most importantly, gbapp embodies a mindset of coding through automation rather than manual implementation. - - -## Real-World Examples - -The contrast between traditional development and the General Bots approach becomes clear through examples. - -### Traditional Approach - -In the old way of thinking, you might write hundreds of lines of custom Node.js, Python, or C# code for data validation. A function like validateComplexBusinessRules would contain extensive logic handling edge cases, format checking, and business rule verification. This code requires maintenance, testing, and documentation. - -### The General Bots Approach - -With the automation-first philosophy, the same task takes three lines. You fetch your business rules from a file, ask the LLM to validate data against those rules, and handle the result. The AI understands the rules and applies them correctly without you implementing the validation logic. - -```basic -' 3 lines - let AI handle complexity -rules = GET "business-rules.txt" -validation = LLM "Validate this data against these rules: " + data + " Rules: " + rules -IF validation CONTAINS "valid" THEN TALK "Approved" ELSE TALK "Rejected: " + validation -``` - - -## The Multi-SDK Reality - -You do not need separate SDKs or plugins for different services. Everything integrates through BASIC combined with LLM calls. - -### Integrating Any API - -When you need to work with an external API, you do not need to find and install an SDK. Just fetch the data and let the LLM interpret and format it. - -```basic -' No SDK needed - just describe what you want -data = GET "https://server/data" -answer = LLM "Do a good report from this json: " + data -TALK answer -``` - -### Working with Any Database - -Database operations do not require an ORM or query builder. The AI understands SQL and can generate queries from natural language descriptions. - -```basic -' No ORM needed - AI understands SQL -results = FIND "users", "all users who logged in today" -``` - -### Processing Any Format - -You do not need parser libraries for different file formats. The LLM can transform data between formats based on your description. - -```basic -' No parser library needed -xml_data = GET "complex.xml" -json = LLM "Convert this XML to JSON: " + xml_data -SET BOT MEMORY "processed_data", json -``` - - -## When to Write Code - -Understanding when each approach applies helps you work efficiently. - -### Use LLM When - -LLM calls are appropriate for processing unstructured data, implementing business logic, transforming between formats, making decisions, generating content, and analyzing patterns. This covers roughly ninety percent of everything you might want to do. - -### Use BASIC When - -BASIC code handles orchestrating AI calls in sequence, simple flow control with conditionals and loops, managing state and variables, and connecting different systems together. Think of BASIC as the glue that holds everything together. - -### Use Rust When - -Rust development is only necessary when building new keywords that will become part of the core platform, creating a new gbapp module in the `src/` directory, performing system-level optimization for critical paths, or contributing new features that will benefit all users. Almost no one needs to write Rust for their bots. - - -## The gbapp Mindset - -Shifting your thinking is the most important part of adopting this philosophy. - -Stop thinking about how to code a solution, what library you need to import, or how to extend the system with plugins. Start thinking about how to describe what you want to AI, what the simplest BASIC flow looks like, and how your patterns could help everyone using the platform. - - -## Data Enrichment Example - -Consider a data enrichment task that pulls information about companies from their websites. - -The traditional approach requires over a thousand lines of code spread across multiple npm packages. You need complex error handling for network requests, HTML parsing for different website structures, and a maintenance nightmare as websites change their formats. - -The General Bots approach handles the same task in a few lines. You find companies that need enrichment, loop through them, fetch each website, ask the LLM to extract company information, and save the results. The AI handles all the complexity of parsing different website formats. - -```basic -items = FIND "companies", "needs_enrichment=true" -FOR EACH item IN items - website = WEBSITE OF item.company - page = GET website - enriched = LLM "Extract company info from: " + page - SET "companies", "id=" + item.id, "data=" + enriched -NEXT -``` - - -## Report Generation Example - -Generating reports traditionally requires a custom reporting engine, template systems, complex formatting logic, and PDF libraries. That infrastructure takes significant development and ongoing maintenance. - -With General Bots, you find the relevant data, ask the LLM to create an executive summary, and generate a site with the results. Three lines replace an entire reporting infrastructure. - -```basic -data = FIND "sales", "month=current" -report = LLM "Create executive summary from: " + data -CREATE SITE "report", "template", report -``` - - -## The Ultimate Test - -Before writing any code, ask yourself three questions in order. First, can the LLM do this? The answer is usually yes. Second, can BASIC orchestrate it? Almost always yes. Third, do you really need Rust? Almost never. - -Only proceed to writing custom code if you have genuinely exhausted the first two options. The LLM and BASIC combination handles far more than most developers initially expect. - - -## Benefits of This Approach - -### For Developers - -This approach enables development that is roughly one hundred times faster than traditional coding. You have no dependency management headaches and no version conflicts between packages. The maintenance burden drops dramatically because there is no custom code to maintain. You can focus on business logic and what you want to accomplish rather than implementation details. - -### For Organizations - -Organizations benefit from reduced complexity in their bot deployments. Maintenance costs drop because there is less custom code to support. Iterations happen faster since changes involve modifying descriptions rather than rewriting code. There is no vendor lock-in to specific libraries or frameworks. Anyone in the organization can contribute because they do not need traditional programming skills. - -### For the Community - -Shared improvements benefit everyone using the platform. There is no fragmentation into incompatible plugin ecosystems. Users experience consistency across different bots and deployments. The community advances collectively rather than each organization maintaining separate extensions. - - -## The Future is Already Here - -In 2025, this approach is not aspirational but reality. Applications built entirely with BASIC and LLM calls run in production today. Most use cases require zero custom code. AI handles complexity better than hand-written algorithms in many domains. Machines do machine work while humans focus on human work like understanding requirements and making decisions. - - -## Migration Path - -### From Extensions to Virtual Crates - -If you have existing plugin-style extensions, the migration path consolidates them into the main source tree. An old extension might have been a separate folder with hundreds of lines of JavaScript, a package.json, and complex logic. The new approach places a small Rust module in `src/` that registers BASIC keywords, while the actual logic moves to a few lines of BASIC in your `.gbdialog` folder that leverage LLM calls. - -### From Code to Descriptions - -Migration from traditional code involves converting algorithms into natural language descriptions. Instead of writing the logic to process data, you describe what processing you need and let the LLM implement it. - -### From Libraries to LLM - -Instead of importing twenty npm packages for various functionality, you make single LLM calls with descriptions of what you need. The AI has knowledge of countless libraries and formats built into its training. - - -## Development Guidelines - -Follow these practices to work effectively with the automation-first philosophy. Describe problems to the LLM in clear, specific terms. Use BASIC as minimal glue between AI operations. Contribute keywords to the core when you discover patterns that would benefit everyone. Share your patterns with the community so others can learn. Think automation-first for every task you encounter. - -Avoid common mistakes that fight against this philosophy. Do not write complex algorithms when a description would suffice. Do not build separate plugins that fragment the ecosystem. Do not create custom frameworks that add unnecessary complexity. Do not maintain separate codebases when everything should be in one place. Do not fight the machine by insisting on manual implementation. - - -## The Virtual Crate Architecture - -Each gbapp is now a module in the `src/` directory. The structure maps conceptually familiar package names to Rust modules. The core gbapp lives in `src/core/`. The BASIC interpreter is `src/basic/`. Channel adapters are in `src/channels/`. Your contribution would go in `src/your_feature/`. This elegant mapping preserves the conceptual model of separate packages while leveraging Rust's module system and compiling everything into a single optimized binary. - - -## Conclusion - -The gbapp concept in 2025 has evolved from external packages to virtual crates. These Rust modules inside `src/` compile into a single, optimized binary while preserving the familiar mental model of separate functional packages. - -The philosophy remains constant: machines are better at machine work. Your job is to describe what you want, not implement how to do it. The combination of BASIC for orchestration and LLM for logic eliminates the need for traditional programming in almost all cases. - - -## Examples Repository - -The `/templates/` directory contains real-world examples of applications built entirely with BASIC and LLM calls. A CRM system requires about fifty lines of BASIC. Email automation needs around thirty lines. Data pipelines work in twenty lines. Report generators take about fifteen lines. Each of these would have required thousands of lines of traditional code, demonstrating the dramatic productivity improvement this philosophy enables. \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/scaling.md b/docs/src/chapter-07-gbapp/scaling.md deleted file mode 100644 index b0403d03..00000000 --- a/docs/src/chapter-07-gbapp/scaling.md +++ /dev/null @@ -1,672 +0,0 @@ -# Scaling and Load Balancing - -General Bots is designed to scale from a single instance to a distributed cluster using LXC containers. This chapter covers auto-scaling, load balancing, sharding strategies, and failover systems. - -## Scaling Architecture - -General Bots uses a **horizontal scaling** approach with LXC containers: - -``` - ┌─────────────────┐ - │ Caddy Proxy │ - │ (Load Balancer)│ - └────────┬────────┘ - │ - ┌───────────────────┼───────────────────┐ - │ │ │ - ▼ ▼ ▼ -┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ -│ LXC Container │ │ LXC Container │ │ LXC Container │ -│ botserver-1 │ │ botserver-2 │ │ botserver-3 │ -└────────┬────────┘ └────────┬────────┘ └────────┬────────┘ - │ │ │ - └───────────────────┼───────────────────┘ - │ - ┌───────────────────┼───────────────────┐ - │ │ │ - ▼ ▼ ▼ -┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ -│ PostgreSQL │ │ Redis │ │ Qdrant │ -│ (Primary) │ │ (Cluster) │ │ (Cluster) │ -└─────────────────┘ └─────────────────┘ └─────────────────┘ -``` - -## Auto-Scaling Configuration - -### config.csv Parameters - -Configure auto-scaling behavior in your bot's `config.csv`: - -```csv -# Auto-scaling settings -scale-enabled,true -scale-min-instances,1 -scale-max-instances,10 -scale-cpu-threshold,70 -scale-memory-threshold,80 -scale-request-threshold,1000 -scale-cooldown-seconds,300 -scale-check-interval,30 -``` - -| Parameter | Description | Default | -|-----------|-------------|---------| -| `scale-enabled` | Enable auto-scaling | `false` | -| `scale-min-instances` | Minimum container count | `1` | -| `scale-max-instances` | Maximum container count | `10` | -| `scale-cpu-threshold` | CPU % to trigger scale-up | `70` | -| `scale-memory-threshold` | Memory % to trigger scale-up | `80` | -| `scale-request-threshold` | Requests/min to trigger scale-up | `1000` | -| `scale-cooldown-seconds` | Wait time between scaling events | `300` | -| `scale-check-interval` | Seconds between metric checks | `30` | - -### Scaling Rules - -Define custom scaling rules: - -```csv -# Scale up when average response time exceeds 2 seconds -scale-rule-response-time,2000 -scale-rule-response-action,up - -# Scale down when CPU drops below 30% -scale-rule-cpu-low,30 -scale-rule-cpu-low-action,down - -# Scale up on queue depth -scale-rule-queue-depth,100 -scale-rule-queue-action,up -``` - -## LXC Container Management - -### Creating Scaled Instances - -```bash -# Create additional botserver containers -for i in {2..5}; do - lxc launch images:debian/12 botserver-$i - lxc config device add botserver-$i port-$((8080+i)) proxy \ - listen=tcp:0.0.0.0:$((8080+i)) connect=tcp:127.0.0.1:8080 -done -``` - -### Container Resource Limits - -Set resource limits per container: - -```bash -# CPU limits (number of cores) -lxc config set botserver-1 limits.cpu 4 - -# Memory limits -lxc config set botserver-1 limits.memory 8GB - -# Disk I/O priority (0-10) -lxc config set botserver-1 limits.disk.priority 5 - -# Network bandwidth (ingress/egress) -lxc config device set botserver-1 eth0 limits.ingress 100Mbit -lxc config device set botserver-1 eth0 limits.egress 100Mbit -``` - -### Auto-Scaling Script - -Create `/opt/gbo/scripts/autoscale.sh`: - -```bash -#!/bin/bash - -# Configuration -MIN_INSTANCES=1 -MAX_INSTANCES=10 -CPU_THRESHOLD=70 -SCALE_COOLDOWN=300 -LAST_SCALE_FILE="/tmp/last_scale_time" - -get_avg_cpu() { - local total=0 - local count=0 - for container in $(lxc list -c n --format csv | grep "^botserver-"); do - cpu=$(lxc exec $container -- cat /proc/loadavg | awk '{print $1}') - total=$(echo "$total + $cpu" | bc) - count=$((count + 1)) - done - echo "scale=2; $total / $count * 100" | bc -} - -get_instance_count() { - lxc list -c n --format csv | grep -c "^botserver-" -} - -can_scale() { - if [ ! -f "$LAST_SCALE_FILE" ]; then - return 0 - fi - last_scale=$(cat "$LAST_SCALE_FILE") - now=$(date +%s) - diff=$((now - last_scale)) - [ $diff -gt $SCALE_COOLDOWN ] -} - -scale_up() { - current=$(get_instance_count) - if [ $current -ge $MAX_INSTANCES ]; then - echo "Already at max instances ($MAX_INSTANCES)" - return 1 - fi - - new_id=$((current + 1)) - echo "Scaling up: creating botserver-$new_id" - - lxc launch images:debian/12 botserver-$new_id - lxc config set botserver-$new_id limits.cpu 4 - lxc config set botserver-$new_id limits.memory 8GB - - # Copy configuration - lxc file push /opt/gbo/conf/botserver.env botserver-$new_id/opt/gbo/conf/ - - # Start botserver - lxc exec botserver-$new_id -- /opt/gbo/bin/botserver & - - # Update load balancer - update_load_balancer - - date +%s > "$LAST_SCALE_FILE" - echo "Scale up complete" -} - -scale_down() { - current=$(get_instance_count) - if [ $current -le $MIN_INSTANCES ]; then - echo "Already at min instances ($MIN_INSTANCES)" - return 1 - fi - - # Remove highest numbered instance - target="botserver-$current" - echo "Scaling down: removing $target" - - # Drain connections - lxc exec $target -- /opt/gbo/bin/botserver drain - sleep 30 - - # Stop and delete - lxc stop $target - lxc delete $target - - # Update load balancer - update_load_balancer - - date +%s > "$LAST_SCALE_FILE" - echo "Scale down complete" -} - -update_load_balancer() { - # Generate upstream list - upstreams="" - for container in $(lxc list -c n --format csv | grep "^botserver-"); do - ip=$(lxc list $container -c 4 --format csv | cut -d' ' -f1) - upstreams="$upstreams\n to $ip:8080" - done - - # Update Caddy config - cat > /opt/gbo/conf/caddy/upstream.conf << EOF -upstream botserver { - $upstreams - lb_policy round_robin - health_uri /api/health - health_interval 10s -} -EOF - - # Reload Caddy - lxc exec proxy-1 -- caddy reload --config /etc/caddy/Caddyfile -} - -# Main loop -while true; do - avg_cpu=$(get_avg_cpu) - echo "Average CPU: $avg_cpu%" - - if can_scale; then - if (( $(echo "$avg_cpu > $CPU_THRESHOLD" | bc -l) )); then - scale_up - elif (( $(echo "$avg_cpu < 30" | bc -l) )); then - scale_down - fi - fi - - sleep 30 -done -``` - -## Load Balancing - -### Caddy Configuration - -Primary load balancer configuration (`/opt/gbo/conf/caddy/Caddyfile`): - -```caddyfile -{ - admin off - auto_https on -} - -(common) { - encode gzip zstd - header { - -Server - X-Content-Type-Options "nosniff" - X-Frame-Options "DENY" - Referrer-Policy "strict-origin-when-cross-origin" - } -} - -bot.example.com { - import common - - # Health check endpoint (no load balancing) - handle /api/health { - reverse_proxy localhost:8080 - } - - # WebSocket connections (sticky sessions) - handle /ws* { - reverse_proxy botserver-1:8080 botserver-2:8080 botserver-3:8080 { - lb_policy cookie - lb_try_duration 5s - health_uri /api/health - health_interval 10s - health_timeout 5s - } - } - - # API requests (round robin) - handle /api/* { - reverse_proxy botserver-1:8080 botserver-2:8080 botserver-3:8080 { - lb_policy round_robin - lb_try_duration 5s - health_uri /api/health - health_interval 10s - fail_duration 30s - } - } - - # Static files (any instance) - handle { - reverse_proxy botserver-1:8080 botserver-2:8080 botserver-3:8080 { - lb_policy first - } - } -} -``` - -### Load Balancing Policies - -| Policy | Description | Use Case | -|--------|-------------|----------| -| `round_robin` | Rotate through backends | General API requests | -| `first` | Use first available | Static content | -| `least_conn` | Fewest active connections | Long-running requests | -| `ip_hash` | Consistent by client IP | Session affinity | -| `cookie` | Sticky sessions via cookie | WebSocket, stateful | -| `random` | Random selection | Testing | - -### Rate Limiting - -Configure rate limits in `config.csv`: - -```csv -# Rate limiting -rate-limit-enabled,true -rate-limit-requests,100 -rate-limit-window,60 -rate-limit-burst,20 -rate-limit-by,ip - -# Per-endpoint limits -rate-limit-api-chat,30 -rate-limit-api-files,50 -rate-limit-api-auth,10 -``` - -Rate limiting in Caddy: - -```caddyfile -bot.example.com { - # Global rate limit - rate_limit { - zone global { - key {remote_host} - events 100 - window 1m - } - } - - # Stricter limit for auth endpoints - handle /api/auth/* { - rate_limit { - zone auth { - key {remote_host} - events 10 - window 1m - } - } - reverse_proxy botserver:8080 - } -} -``` - -## Sharding Strategies - -### Database Sharding Options - -#### Option 1: Tenant-Based Sharding - -Each tenant gets their own database: - -``` -┌─────────────────┐ -│ Router/Proxy │ -└────────┬────────┘ - │ - ┌────┴────┬──────────┐ - │ │ │ - ▼ ▼ ▼ -┌───────┐ ┌───────┐ ┌───────┐ -│Tenant1│ │Tenant2│ │Tenant3│ -│ DB │ │ DB │ │ DB │ -└───────┘ └───────┘ └───────┘ -``` - -Configuration: - -```csv -# Tenant sharding -shard-strategy,tenant -shard-tenant-db-prefix,gb_tenant_ -shard-auto-create,true -``` - -#### Option 2: Hash-Based Sharding - -Distribute data by hash of primary key: - -``` -User ID: 12345 -Hash: 12345 % 4 = 1 -Shard: shard-1 -``` - -Configuration: - -```csv -# Hash sharding -shard-strategy,hash -shard-count,4 -shard-key,user_id -shard-algorithm,modulo -``` - -#### Option 3: Range-Based Sharding - -Partition by ID ranges: - -```csv -# Range sharding -shard-strategy,range -shard-ranges,0-999999:shard1,1000000-1999999:shard2,2000000-:shard3 -``` - -#### Option 4: Geographic Sharding - -Route by user location: - -```csv -# Geographic sharding -shard-strategy,geo -shard-geo-us,postgres-us.example.com -shard-geo-eu,postgres-eu.example.com -shard-geo-asia,postgres-asia.example.com -shard-default,postgres-us.example.com -``` - -### Vector Database Sharding (Qdrant) - -Qdrant supports automatic sharding: - -```csv -# Qdrant sharding -qdrant-shard-count,4 -qdrant-replication-factor,2 -qdrant-write-consistency,majority -``` - -Collection creation with sharding: - -```rust -// In vectordb code -let collection_config = CreateCollection { - collection_name: format!("kb_{}", bot_id), - vectors_config: VectorsConfig::Single(VectorParams { - size: 384, - distance: Distance::Cosine, - }), - shard_number: Some(4), - replication_factor: Some(2), - write_consistency_factor: Some(1), - ..Default::default() -}; -``` - -### Redis Cluster - -For high-availability caching: - -```csv -# Redis cluster -cache-mode,cluster -cache-nodes,redis-1:6379,redis-2:6379,redis-3:6379 -cache-replicas,1 -``` - -## Failover Systems - -### Health Checks - -Configure health check endpoints: - -```csv -# Health check configuration -health-enabled,true -health-endpoint,/api/health -health-interval,10 -health-timeout,5 -health-retries,3 -``` - -Health check response: - -```json -{ - "status": "healthy", - "version": "6.1.0", - "uptime": 86400, - "checks": { - "database": "ok", - "cache": "ok", - "vectordb": "ok", - "llm": "ok" - }, - "metrics": { - "cpu": 45.2, - "memory": 62.1, - "connections": 150 - } -} -``` - -### Automatic Failover - -#### Database Failover (PostgreSQL) - -Using Patroni for PostgreSQL HA: - -```yaml -# patroni.yml -scope: botserver-cluster -name: postgres-1 - -restapi: - listen: 0.0.0.0:8008 - connect_address: postgres-1:8008 - -etcd: - hosts: etcd-1:2379,etcd-2:2379,etcd-3:2379 - -bootstrap: - dcs: - ttl: 30 - loop_wait: 10 - retry_timeout: 10 - maximum_lag_on_failover: 1048576 - postgresql: - use_pg_rewind: true - parameters: - max_connections: 200 - shared_buffers: 2GB - -postgresql: - listen: 0.0.0.0:5432 - connect_address: postgres-1:5432 - data_dir: /var/lib/postgresql/data - authentication: - superuser: - username: postgres - password: ${POSTGRES_PASSWORD} - replication: - username: replicator - password: ${REPLICATION_PASSWORD} -``` - -#### Cache Failover (Redis Sentinel) - -```csv -# Redis Sentinel configuration -cache-mode,sentinel -cache-sentinel-master,mymaster -cache-sentinel-nodes,sentinel-1:26379,sentinel-2:26379,sentinel-3:26379 -``` - -### Circuit Breaker - -Prevent cascade failures: - -```csv -# Circuit breaker settings -circuit-breaker-enabled,true -circuit-breaker-threshold,5 -circuit-breaker-timeout,30 -circuit-breaker-half-open-requests,3 -``` - -States: -- **Closed**: Normal operation -- **Open**: Failing, reject requests immediately -- **Half-Open**: Testing if service recovered - -### Graceful Degradation - -Configure fallback behavior: - -```csv -# Fallback configuration -fallback-llm-enabled,true -fallback-llm-provider,local -fallback-llm-model,DeepSeek-R1-Distill-Qwen-1.5B - -fallback-cache-enabled,true -fallback-cache-mode,memory - -fallback-vectordb-enabled,true -fallback-vectordb-mode,keyword-search -``` - -## Monitoring Scaling - -### Metrics Collection - -Key metrics to monitor: - -```csv -# Scaling metrics -metrics-scaling-enabled,true -metrics-container-count,true -metrics-scaling-events,true -metrics-load-distribution,true -``` - -### Alerting Rules - -Configure alerts for scaling issues: - -```yaml -# alerting-rules.yml -groups: - - name: scaling - rules: - - alert: HighCPUUsage - expr: avg(cpu_usage) > 80 - for: 5m - labels: - severity: warning - annotations: - summary: "High CPU usage detected" - - - alert: MaxInstancesReached - expr: container_count >= max_instances - for: 1m - labels: - severity: critical - annotations: - summary: "Maximum instances reached, cannot scale up" - - - alert: ScalingFailed - expr: scaling_errors > 0 - for: 1m - labels: - severity: critical - annotations: - summary: "Scaling operation failed" -``` - -## Best Practices - -### Scaling - -1. **Start small** - Begin with auto-scaling disabled, monitor patterns first -2. **Set appropriate thresholds** - Too low causes thrashing, too high causes poor performance -3. **Use cooldown periods** - Prevent rapid scale up/down cycles -4. **Test failover** - Regularly test your failover procedures -5. **Monitor costs** - More instances = higher infrastructure costs - -### Load Balancing - -1. **Use sticky sessions for WebSockets** - Required for real-time features -2. **Enable health checks** - Remove unhealthy instances automatically -3. **Configure timeouts** - Prevent hanging connections -4. **Use connection pooling** - Reduce connection overhead - -### Sharding - -1. **Choose the right strategy** - Tenant-based is simplest for SaaS -2. **Plan for rebalancing** - Have procedures to move data between shards -3. **Avoid cross-shard queries** - Design to minimize these -4. **Monitor shard balance** - Uneven distribution causes hotspots - -## Next Steps - -- [Container Deployment](./containers.md) - LXC container basics -- [Architecture Overview](./architecture.md) - System design -- [Monitoring Dashboard](../chapter-04-gbui/monitoring.md) - Observe your cluster \ No newline at end of file diff --git a/docs/src/chapter-07-gbapp/services.md b/docs/src/chapter-07-gbapp/services.md deleted file mode 100644 index 12e80c34..00000000 --- a/docs/src/chapter-07-gbapp/services.md +++ /dev/null @@ -1,155 +0,0 @@ -# Service Layer - -BotServer's service layer is organized into functional modules that handle specific aspects of the platform. Each module encapsulates related functionality and provides a clear API for interaction with other parts of the system. This chapter describes each service module and its responsibilities within the overall architecture. - - -## Core Service Modules - -### Authentication and Security - -The `auth` module provides secure user authentication and session management throughout the platform. Password hashing uses the Argon2 algorithm for secure password storage that resists both CPU and GPU-based attacks. Session token generation creates and validates unique tokens for maintaining authenticated state. User verification authenticates users against the database using stored credentials. Bot authentication manages bot-level authentication for API access, allowing bots to make authenticated requests to external services. - -The module's key responsibilities include hashing passwords with Argon2 before storage, generating cryptographically secure session tokens, validating user credentials during login, and managing the complete session lifecycle from creation through expiration. - -### Bot Management - -The `bot` module handles bot lifecycle and configuration throughout the system. Bot creation initializes new bot instances with their required components. Configuration management loads and applies bot settings from config.csv files. Bot state tracking monitors bot status and health for operational awareness. Multi-tenant support isolates bots by tenant to prevent data leakage between organizations. - -This module creates and deletes bot instances, loads bot configuration from the database, manages bot lifecycle including start, stop, and restart operations, and associates bots with users and sessions for proper isolation. - -### Session Management - -The `session` module maintains user conversation state across interactions. Session storage persists conversation context to both cache and database. State management tracks user progress through dialogs and remembers variable values. Session cleanup removes expired sessions to free resources. Multi-user support isolates sessions by user to ensure privacy. - -The module creates new sessions when users connect, stores and retrieves session variables, maintains conversation history for context, and cleans up abandoned sessions after timeout periods. - - -## Conversation and Scripting Services - -### BASIC Interpreter - -The `basic` module implements the BASIC-like scripting language for `.gbdialog` files. Script parsing reads BASIC dialog scripts and converts them to executable form. The execution engine powered by the Rhai scripting engine runs the parsed scripts. Keyword implementation provides custom keywords like TALK, HEAR, and LLM for bot functionality. Variable management handles script variables and maintains execution context across statements. - -This module loads and parses `.gbdialog` scripts from bot packages, executes BASIC commands in sequence, provides custom keywords that extend the language for bot functionality, and manages script execution context including variables and flow control state. - -### Context Management - -The `context` module manages conversation context and memory for LLM interactions. Conversation history storage maintains the message history for each session. Context retrieval loads relevant context for LLM calls based on the current query. Memory management limits context size to fit within model token limits. Context compaction summarizes old conversations to preserve meaning while reducing tokens. - -The module appends messages to conversation history as they occur, retrieves appropriate context for LLM queries, implements context window management to stay within limits, and provides context to knowledge base queries for improved relevance. - -### Channel Abstraction - -The `channels` module provides a unified interface for multiple communication channels. The web interface enables browser-based chat through the default UI. WebSocket support provides real-time bidirectional communication for responsive interactions. Voice integration handles audio input and output for voice-enabled bots. Platform adapters provide an extensible channel system for adding new platforms. - -This module abstracts channel-specific implementations behind a common interface, routes messages to appropriate handlers based on channel type, formats responses appropriately for specific channels, and handles channel-specific features like typing indicators and read receipts. - - -## AI and Knowledge Services - -### LLM Integration - -The `llm` module integrates with large language models for natural language understanding and generation. Provider abstraction supports multiple LLM providers through a common interface. API communication handles API calls to LLM services including authentication and rate limiting. Streaming responses support token streaming for real-time response display. Error handling provides graceful degradation when API calls fail. - -The module sends prompts to LLM providers using appropriate formats, parses and streams responses back to callers, handles API authentication and key management, and manages rate limiting with automatic retries when necessary. - -### LLM Models - -The `llm_models` module contains model-specific implementations for different providers. Model configurations define parameters and capabilities for different models. Prompt templates handle model-specific prompt formatting requirements. Token counting estimates token usage before making API calls. Model selection chooses the appropriate model for each task based on requirements. - -This module defines model capabilities and limits for each supported model, formats prompts according to each model's expectations, calculates token costs for usage tracking, and selects optimal models for specific query types. - -### NVIDIA Integration - -The `nvidia` module provides GPU acceleration support for local model inference. GPU detection identifies available NVIDIA GPUs in the system. Acceleration enables GPU-accelerated inference for local models. Resource management allocates GPU resources among concurrent requests. - - -## Infrastructure Services - -### Bootstrap - -The `bootstrap` module handles system initialization and first-time setup. Component installation downloads and installs required components including PostgreSQL, cache, and drive storage. Database setup creates schemas and applies migrations to prepare the database. Credential generation creates secure passwords for all services. Environment configuration writes `.env` files with generated settings. Template upload deploys bot templates to storage for immediate use. - -The module detects installation mode to determine whether it is running locally or in containers, installs and starts all system components in the correct order, initializes the database with migrations and seed data, configures drive storage with appropriate buckets, and creates default bots from included templates. - -### Package Manager - -The `package_manager` module manages component installation and lifecycle. The component registry tracks available components and their versions. Installation downloads and installs components from configured sources. Lifecycle management starts, stops, and restarts components as needed. Dependency resolution ensures components start in the correct order based on their dependencies. - -Managed components include tables for PostgreSQL database, cache for Valkey caching, drive for S3-compatible object storage, llm for local LLM server, email for email server integration, proxy for reverse proxy functionality, directory for LDAP directory services, alm for application lifecycle management, dns for DNS server operations, meeting for LiveKit video conferencing, and vector_db for Qdrant vector database functionality. - -### Configuration - -The `config` module loads and validates application configuration. Environment variables load from `.env` files and system environment. Validation ensures all required configuration is present before startup. Defaults provide sensible values for optional settings. Type safety parses configuration into strongly-typed structs for compile-time checking. - -The module loads DATABASE_URL, DRIVE_SERVER, API keys, and other settings, validates configuration completeness at startup, provides configuration access to other modules through a shared struct, and handles configuration errors with helpful messages. - -### Shared Utilities - -The `shared` module contains common functionality used across the system. Database models define the Diesel schema and models for all tables. Connection pooling manages R2D2 connection pools for efficient database access. Utilities provide common helper functions for repeated tasks. Types define shared type definitions used throughout the codebase. - -This module defines the database schema with Diesel macros, provides database connection helpers for consistent access patterns, implements common utility functions for string manipulation and data transformation, and shares types across modules to ensure consistency. - -### Web Server - -The `web_server` module implements the HTTP API using Axum. API routes define RESTful endpoints for bot interaction and management. The WebSocket handler manages real-time communication channels. Static files serve web UI assets for the browser interface. CORS configuration enables cross-origin resource sharing for embedded deployments. Middleware handles logging, authentication, and error handling for all requests. - -This module defines API routes and their handlers, processes HTTP requests and generates responses, manages WebSocket connections for real-time chat, and serves static web interface files for the UI. - - -## Feature Services - -### Automation - -The `automation` module provides scheduled and event-driven task execution. Cron scheduling runs tasks on defined schedules using standard cron syntax. Event triggers react to system events by executing associated handlers. Background jobs execute long-running tasks without blocking the main thread. Job management tracks running jobs and allows cancellation when needed. - -### Drive Monitor - -The `drive_monitor` module watches for file system changes in bot packages. File watching detects file creation, modification, and deletion events. Event processing handles file change events by triggering appropriate actions. Automatic indexing adds new documents to the knowledge base when they appear in monitored directories. - -### Email Integration - -The `email` module handles email communication as an optional feature. IMAP support reads emails from configured inbox folders. SMTP support sends emails via the Lettre library. Email parsing extracts text content and attachments from received messages. Template rendering generates HTML emails from templates with variable substitution. - -### File Handling - -The `file` module processes various file types for knowledge base ingestion. PDF extraction pulls text from PDF documents using pdf-extract. Document parsing handles various document formats including Word and plain text. File upload processes multipart file uploads from users. Storage integration saves processed files to drive storage for persistence. - -### Meeting Integration - -The `meet` module integrates with LiveKit for video conferencing capabilities. Room creation establishes meeting rooms with appropriate settings. Token generation creates access tokens for meeting participants. Participant management tracks who is in each meeting. Recording captures meeting sessions for later review. - - -## Storage Services - -### Drive - -The `drive` module provides S3-compatible object storage integration. Drive integration uses the AWS SDK S3 client for compatibility with various providers. Bucket management creates and manages storage buckets for different bots. Object operations handle upload, download, and delete operations for files. Vector database integration connects to Qdrant for semantic search functionality. - -### UI Components - -The `ui` module contains UI-related functionality for the web interface. Drive UI provides a file browser interface for managing documents. Stream handling implements server-sent events for real-time updates. Sync logic manages synchronization between local and remote files. Local sync enables desktop app file synchronization for offline access. - - -## Testing - -The `tests` module provides test utilities and integration tests for the platform. Test fixtures provide common test data and setup procedures. Integration tests validate end-to-end functionality across modules. Mock services substitute for external dependencies during testing. Test helpers provide utilities for writing consistent, readable tests. - - -## Service Interaction Patterns - -### Layered Architecture - -Services are organized into layers with clear dependencies. The infrastructure layer contains bootstrap, package_manager, config, shared, and web_server modules that provide foundational capabilities. The data layer contains drive, file, and session modules that handle persistence. The domain layer contains bot, auth, context, and basic modules that implement core business logic. The AI layer contains llm, llm_models, and nvidia modules for machine learning integration. The feature layer contains automation, email, meet, and drive_monitor modules that add optional capabilities. The presentation layer contains channels and ui modules that handle user interaction. - -### Dependency Injection - -Services use Rust's module system and trait-based design for dependency injection. Database connections are shared via connection pools managed by R2D2. Configuration is passed through the AppConfig struct which is initialized at startup and shared immutably. Services access their dependencies through function parameters rather than global state. - -### Error Handling - -All services use `anyhow::Result` for error handling, allowing errors to propagate up the call stack with context. Each layer adds relevant context to errors before propagating them. Critical services log errors using the `log` crate with appropriate severity levels. User-facing errors are translated to helpful messages without exposing internal details. - -### Async Operations - -Most services are async and use Tokio as the runtime. This design allows concurrent handling of multiple user sessions without blocking. External API calls run concurrently to minimize latency. Background tasks use Tokio's task spawning for parallel execution. The async design enables efficient resource utilization even under high load. \ No newline at end of file diff --git a/docs/src/chapter-08-config/README.md b/docs/src/chapter-08-config/README.md deleted file mode 100644 index f05f7ad4..00000000 --- a/docs/src/chapter-08-config/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# Bot Configuration - -This chapter covers bot configuration through the `config.csv` file system. Each bot's behavior is controlled by a simple CSV configuration file in its `.gbot` package. - -## Configuration System - -BotServer uses a straightforward name-value CSV format for configuration: - -```csv -name,value -setting_name,setting_value -another_setting,another_value -``` - -## File Location - -``` -mybot.gbai/ -└── mybot.gbot/ - └── config.csv -``` - -## Configuration Categories - -### Server Settings -- Web server binding and ports -- Site generation paths -- Service endpoints - -### LLM Configuration -- Model paths (local GGUF files) -- Service URLs -- Cache settings -- Server parameters (when embedded) - -### Prompt Management -- Context compaction levels -- History retention -- Token management - -### Email Integration -- SMTP server settings -- Authentication credentials -- Sender configuration - -### Theme Customization -- Color schemes -- Logo URLs -- Bot titles - -### Custom Database -- External database connections -- Authentication details - -## Key Features - -### Simple Format -- Plain CSV with name-value pairs -- No complex syntax -- Human-readable - -### Flexible Structure -- Empty rows for visual grouping -- Optional settings with defaults -- Extensible for custom needs - -### Local-First -- Designed for local LLM models -- Self-hosted services -- No cloud dependency by default - -## Example Configurations - -### Minimal Setup -Just the essentials to run a bot: -```csv -name,value -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/model.gguf -``` - -### Production Setup -Full configuration with all services: -```csv -name,value -, -server_host,0.0.0.0 -server_port,8080 -, -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/production-model.gguf -llm-cache,true -, -email-server,smtp.company.com -email-from,bot@company.com -, -theme-title,Company Assistant -``` - -## Configuration Philosophy - -1. **Defaults Work**: Most settings have sensible defaults -2. **Local First**: Assumes local services, not cloud APIs -3. **Simple Values**: All values are strings, parsed as needed -4. **No Magic**: What you see is what you get - -## See Also - -- [config.csv Format](./config-csv.md) - Complete reference -- [LLM Configuration](./llm-config.md) - Language model settings -- [Parameters](./parameters.md) - All available parameters ---- - -
- General Bots -
diff --git a/docs/src/chapter-08-config/config-csv.md b/docs/src/chapter-08-config/config-csv.md deleted file mode 100644 index 80b0c016..00000000 --- a/docs/src/chapter-08-config/config-csv.md +++ /dev/null @@ -1,80 +0,0 @@ -# config.csv Format - -The `config.csv` file is the heart of bot configuration in General Bots. Located in each bot's `.gbot` package, it uses a simple, human-readable format that anyone can edit. - -## Why CSV? - -We chose CSV because: -- **No syntax errors** - Just name,value pairs -- **Spreadsheet compatible** - Edit in Excel, Google Sheets, or any text editor -- **Human readable** - No brackets, no indentation wars -- **Git friendly** - Clean diffs, easy merges - -## Basic Format - -```csv -name,value -server-port,8080 -llm-model,../../../../data/llm/model.gguf -``` - -That's it. No quotes, no special characters, just names and values. - -## Visual Organization - -Use empty rows to group related settings: - -```csv -name,value - -# Server settings -server-host,0.0.0.0 -server-port,8080 - -# LLM settings (see Configuration Management for details) -llm-url,http://localhost:8081 -llm-model,model.gguf - -# Email settings -email-from,bot@example.com -email-server,smtp.example.com -``` - -## Key Points - -- **Case matters**: `server-port` not `Server-Port` -- **No spaces**: Around commas or in names -- **Paths**: Can be relative or absolute -- **Booleans**: Use `true` or `false` -- **Numbers**: Just write them directly - -## Quick Example - -A complete working configuration: - -```csv -name,value -server-port,8080 -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf -episodic-memory-threshold,4 -``` - -Four lines. Bot configured. That's the General Bots way. - -## LLM Configuration - -Basic LLM settings in config.csv: -- `llm-url` - Where your LLM server is (local or cloud) -- `llm-model` - Which model to use -- `llm-key` - API key if using cloud services like Groq - -For detailed LLM configuration including GPU settings, cache, performance tuning, and hardware-specific recommendations, see [Configuration Management](./context-config.md#llm-configuration---overview). - -## Where to Find Settings - -For the complete list of available settings and detailed explanations, see [Configuration Management](./context-config.md). - -## Philosophy - -Configuration should be boring. You should spend time on your bot's personality and capabilities, not fighting with config files. CSV keeps it simple so you can focus on what matters. \ No newline at end of file diff --git a/docs/src/chapter-08-config/context-config.md b/docs/src/chapter-08-config/context-config.md deleted file mode 100644 index 34a839ee..00000000 --- a/docs/src/chapter-08-config/context-config.md +++ /dev/null @@ -1,339 +0,0 @@ -# Configuration Management - -Configuration in General Bots is designed to be simple and transparent. Each bot uses a `config.csv` file for settings, with additional environment variables for system-level configuration. - -## The config.csv File - -Located in your bot's `.gbot` package, this file controls all bot-specific settings using simple name-value pairs. - -### File Format - -```csv -name,value -setting_name,setting_value -another_setting,another_value -``` - -- **Empty rows** are used for visual grouping -- **No quotes** needed for string values -- **Case-sensitive** names -- **Comments** not supported (keep it simple) - -## Core Configuration Sections - -### Server Configuration -```csv -server-host,0.0.0.0 -server-port,8080 -sites-root,/tmp -``` - -| Name | Description | Default | Example | -|------|-------------|---------|---------| -| `server-host` | Bind address for the web server | `0.0.0.0` | `0.0.0.0` | -| `server-port` | Port for the web interface | `8080` | `8080` | -| `sites-root` | Directory for generated sites | `/tmp` | `/tmp` | - -### LLM Configuration - Overview - -For detailed LLM configuration, see the tables below. The basic settings are: - -```csv -llm-key,none -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf -``` - -#### Core LLM Settings - -| Name | Description | Default | Example | -|------|-------------|---------|---------| -| `llm-key` | API key for LLM service | `none` | `gsk-...` for Groq | -| `llm-url` | LLM service endpoint | `http://localhost:8081` | `https://api.groq.com/openai/v1` | -| `llm-model` | Model path or name | Required | `mixtral-8x7b-32768` | - -#### Model Path Options -- **Local GGUF**: `../../../../data/llm/model.gguf` -- **Absolute path**: `/opt/models/model.gguf` -- **Cloud model name**: `mixtral-8x7b-32768` (for Groq) - -#### Supported Formats -- **GGUF**: Quantized models (Q3_K_M, Q4_K_M, Q5_K_M, Q8_0) -- **API Models**: Any Groq or OpenAI-compatible model - -### LLM Cache Settings - -```csv -llm-cache,false -llm-cache-ttl,3600 -llm-cache-semantic,true -llm-cache-threshold,0.95 -``` - -| Name | Description | Default | Type | -|------|-------------|---------|------| -| `llm-cache` | Enable response caching | `false` | Boolean | -| `llm-cache-ttl` | Cache time-to-live in seconds | `3600` | Number | -| `llm-cache-semantic` | Use semantic similarity | `true` | Boolean | -| `llm-cache-threshold` | Similarity threshold for cache hits | `0.95` | Float | - -**Cache Strategy Tips:** -- Enable for production to reduce API costs -- Semantic cache finds similar (not just identical) queries -- Lower threshold (0.90) = more hits but less precision -- Higher threshold (0.98) = fewer hits but exact matches - -### Context Management - -```csv -episodic-memory-threshold,4 -episodic-memory-history,2 -``` - -| Name | Description | Default | Range | -|------|-------------|---------|-------| -| `episodic-memory-threshold` | Messages before compaction | `4` | 1-10 | -| `episodic-memory-history` | Messages to keep in history | Not set | 1-20 | - -### Embedding Configuration - -```csv -embedding-url,http://localhost:8082 -embedding-model,../../../../data/llm/bge-small-en-v1.5-f32.gguf -``` - -| Name | Description | Default | Type | -|------|-------------|---------|------| -| `embedding-url` | Embedding service endpoint | `http://localhost:8082` | URL | -| `embedding-model` | Path to embedding model | Required for KB | Path | - -### LLM Server Settings (When Self-Hosting) - -```csv -llm-server,true -llm-server-path,botserver-stack/bin/llm/build/bin -llm-server-host,0.0.0.0 -llm-server-port,8081 -llm-server-gpu-layers,0 -llm-server-n-moe,0 -llm-server-ctx-size,4096 -llm-server-n-predict,1024 -llm-server-parallel,6 -llm-server-cont-batching,true -llm-server-mlock,false -llm-server-no-mmap,false -``` - -#### Performance Parameters - -| Parameter | Description | Default | Impact | -|-----------|-------------|---------|---------| -| `llm-server-gpu-layers` | Layers to offload to GPU | `0` | 0=CPU only, higher=more GPU usage | -| `llm-server-n-moe` | MoE experts count | `0` | Enables 120B+ models on consumer GPUs | -| `llm-server-ctx-size` | Context window (tokens) | `4096` | More context = more memory | -| `llm-server-n-predict` | Max output tokens | `1024` | Limits response length | -| `llm-server-parallel` | Concurrent requests | `6` | Higher = more throughput | -| `llm-server-cont-batching` | Continuous batching | `true` | Better multi-user performance | -| `llm-server-mlock` | Lock model in RAM | `false` | Prevents swapping to disk | -| `llm-server-no-mmap` | Disable memory mapping | `false` | Uses more RAM but may be faster | - -#### Hardware-Specific Settings - -**RTX 3090 (24GB VRAM)** -- Set `llm-server-gpu-layers` to 35-45 for 7B-32B models -- Enable `llm-server-n-moe` 2-4 for 120B+ models -- Can run DeepSeek-V3 with proper MoE settings - -**RTX 4070/Ti (12-16GB)** -- Set `llm-server-gpu-layers` to 25-30 for 7B-14B models -- Keep `llm-server-ctx-size` at 4096 to save VRAM - -**CPU-Only Setup** -- Keep `llm-server-gpu-layers` at 0 -- Enable `llm-server-mlock` to prevent swapping -- Set `llm-server-parallel` to CPU cores -2 - -### Email Configuration - -```csv -email-from,from@domain.com -email-server,mail.domain.com -email-port,587 -email-user,user@domain.com -email-pass,password -``` - -All email parameters are required if you want to send emails from your bot. - -### Custom Database (Optional) - -```csv -custom-server,localhost -custom-port,5432 -custom-database,mycustomdb -custom-username,dbuser -custom-password,dbpass -``` - -## Configuration Examples - -### Minimal Configuration -```csv -name,value -server-port,8080 -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/model.gguf -``` - -### Production Configuration (Groq Cloud) -```csv -name,value -, -server-host,0.0.0.0 -server-port,443 -sites-root,/var/www/sites -, -# Groq is 10x faster than traditional cloud providers -llm-key,gsk-your-groq-api-key -llm-url,https://api.groq.com/openai/v1 -llm-model,mixtral-8x7b-32768 -, -llm-cache,true -llm-cache-ttl,7200 -llm-cache-semantic,true -llm-cache-threshold,0.95 -, -episodic-memory-threshold,6 -, -email-from,bot@company.com -email-server,smtp.company.com -email-port,587 -email-user,bot@company.com -email-pass,secure-password -``` - -### Local Development (Self-Hosted) -```csv -name,value -, -server-port,3000 -, -# Run your own LLM server -llm-server,true -llm-server-gpu-layers,35 -llm-server-ctx-size,8192 -llm-server-n-predict,2048 -llm-model,../../../../data/llm/DeepSeek-R1-Distill-Qwen-7B-Q4_K_M.gguf -, -# Disable cache for development -llm-cache,false -episodic-memory-threshold,2 -``` - -## Environment Variables - -System-level configuration uses environment variables: - -```bash -# Database -DATABASE_URL=postgres://gbuser:password@localhost:5432/botserver - -# Object Storage -DRIVE_SERVER=http://localhost:9000 -DRIVE_ACCESSKEY=minioadmin -DRIVE_SECRET=minioadmin - -# Optional -LOG_LEVEL=debug -``` - -## Configuration Priority - -Settings are applied in this order (later overrides earlier): -1. Default values in code -2. config.csv settings -3. Environment variables (for system settings only) - -## Best Practices - -1. **Keep it Simple**: Only configure what you need to change -2. **Use Groups**: Empty rows make the file readable -3. **Test Locally**: Verify settings before production -4. **Secure Secrets**: Use environment variables for passwords in production -5. **Document Changes**: Comment significant changes in version control - -## Validation - -The system validates configuration on startup: -- Missing required values cause clear error messages -- Invalid URLs or paths are detected early -- Port conflicts are reported -- Model file existence is verified - -## Hot Reload - -Some settings support hot reload without restart: -- Cache settings -- Context parameters -- Email configuration - -Others require restart: -- Server ports -- LLM model changes -- Database connections - -## Troubleshooting - -### Common Issues - -**Port Already in Use** -- Change `server-port` to an available port -- Check for other services on the same port - -**Model Not Found** -- Verify the path in `llm-model` is correct -- Ensure the GGUF file exists -- Use absolute paths if relative paths fail - -**LLM Server Won't Start** -- Check `llm-server-gpu-layers` doesn't exceed your GPU capability -- Reduce `llm-server-ctx-size` if out of memory -- Set `llm-server-gpu-layers` to 0 for CPU-only -- Verify model file exists at the specified path -- Check available VRAM with `nvidia-smi` (if using GPU) - -**Cache Not Working** -- Ensure `llm-cache` is set to `true` -- Check `llm-cache-threshold` isn't too high (0.95 is usually good) -- Verify Valkey/Redis is running - -## Quick Model Recommendations - -### Best Models by Hardware - -**24GB+ VRAM (RTX 3090, 4090)** -- DeepSeek-V3 (with MoE enabled) -- Qwen2.5-32B-Instruct-Q4_K_M -- DeepSeek-R1-Distill-Qwen-14B (runs fast with room to spare) - -**12-16GB VRAM (RTX 4070, 4070Ti)** -- DeepSeek-R1-Distill-Llama-8B -- Qwen2.5-14B-Q4_K_M -- Mistral-7B-Instruct-Q5_K_M - -**8GB VRAM or CPU-Only** -- DeepSeek-R1-Distill-Qwen-1.5B -- Phi-3-mini-4k-instruct -- Qwen2.5-3B-Instruct-Q5_K_M - -**Cloud API (Fastest)** -- Groq: mixtral-8x7b-32768 -- Groq: llama-3.1-70b-versatile - -## Summary - -General Bots configuration is intentionally simple - a CSV file with name-value pairs. No complex YAML, no nested JSON, just straightforward settings that anyone can edit. Start with minimal configuration and add settings as needed. - -For LLM configuration, the key decision is local vs cloud: -- **Local**: Full control, no recurring costs, complete privacy -- **Cloud (Groq)**: 10x faster inference, pay-per-use, no hardware needed \ No newline at end of file diff --git a/docs/src/chapter-08-config/drive.md b/docs/src/chapter-08-config/drive.md deleted file mode 100644 index 5f9cf802..00000000 --- a/docs/src/chapter-08-config/drive.md +++ /dev/null @@ -1 +0,0 @@ -# Drive Integration diff --git a/docs/src/chapter-08-config/llm-config.md b/docs/src/chapter-08-config/llm-config.md deleted file mode 100644 index 5c0dc936..00000000 --- a/docs/src/chapter-08-config/llm-config.md +++ /dev/null @@ -1,212 +0,0 @@ -# LLM Configuration - -Configuration for Language Model integration in BotServer, supporting both local GGUF models and external API services. - -## Local Model Configuration - -BotServer is designed to work with local GGUF models by default. The minimal configuration requires only a few settings in your `config.csv`: - -```csv -llm-key,none -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf -``` - -### Model Path - -The `llm-model` parameter accepts relative paths like `../../../../data/llm/model.gguf`, absolute paths like `/opt/models/model.gguf`, or model names when using external APIs like `gpt-4`. - -### Supported Model Formats - -BotServer supports GGUF quantized models for CPU and GPU inference. Quantization levels include Q3_K_M, Q4_K_M, and Q5_K_M for reduced memory usage with acceptable quality trade-offs, while F16 and F32 provide full precision for maximum quality. - -## LLM Server Configuration - -### Running Embedded Server - -BotServer can run its own LLM server for local inference: - -```csv -llm-server,true -llm-server-path,botserver-stack/bin/llm/build/bin -llm-server-host,0.0.0.0 -llm-server-port,8081 -``` - -### Server Performance Parameters - -Fine-tune server performance based on your hardware capabilities: - -```csv -llm-server-gpu-layers,0 -llm-server-ctx-size,4096 -llm-server-n-predict,1024 -llm-server-parallel,6 -llm-server-cont-batching,true -``` - -| Parameter | Description | Impact | -|-----------|-------------|--------| -| `llm-server-gpu-layers` | Layers to offload to GPU | 0 = CPU only, higher = more GPU | -| `llm-server-ctx-size` | Context window size | More context = more memory | -| `llm-server-n-predict` | Max tokens to generate | Limits response length | -| `llm-server-parallel` | Concurrent requests | Higher = more throughput | -| `llm-server-cont-batching` | Continuous batching | Improves multi-user performance | - -### Memory Management - -Memory settings control how the model interacts with system RAM: - -```csv -llm-server-mlock,false -llm-server-no-mmap,false -``` - -The `mlock` option locks the model in RAM to prevent swapping, which improves performance but requires sufficient memory. The `no-mmap` option disables memory mapping and loads the entire model into RAM, using more memory but potentially improving access patterns. - -## Cache Configuration - -### Basic Cache Settings - -Caching reduces repeated LLM calls for identical inputs, significantly improving response times and reducing API costs: - -```csv -llm-cache,false -llm-cache-ttl,3600 -``` - -### Semantic Cache - -Semantic caching matches similar queries, not just identical ones, providing cache hits even when users phrase questions differently: - -```csv -llm-cache-semantic,true -llm-cache-threshold,0.95 -``` - -The threshold parameter controls how similar queries must be to trigger a cache hit. A value of 0.95 requires 95% similarity. Lower thresholds produce more cache hits but may return less accurate cached responses. - -## External API Configuration - -### Groq and OpenAI-Compatible APIs - -For cloud inference, Groq offers the fastest performance among major providers: - -```csv -llm-key,gsk-your-groq-api-key -llm-url,https://api.groq.com/openai/v1 -llm-model,mixtral-8x7b-32768 -``` - -### Local API Servers - -When running your own inference server or using another local service: - -```csv -llm-key,none -llm-url,http://localhost:8081 -llm-model,local-model-name -``` - -## Configuration Examples - -### Minimal Local Setup - -The simplest configuration for getting started with local models: - -```csv -name,value -llm-url,http://localhost:8081 -llm-model,../../../../data/llm/model.gguf -``` - -### High-Performance Local - -Optimized for maximum throughput on capable hardware: - -```csv -name,value -llm-server,true -llm-server-gpu-layers,32 -llm-server-ctx-size,8192 -llm-server-parallel,8 -llm-server-cont-batching,true -llm-cache,true -llm-cache-semantic,true -``` - -### Low-Resource Setup - -Configured for systems with limited RAM or CPU: - -```csv -name,value -llm-server-ctx-size,2048 -llm-server-n-predict,512 -llm-server-parallel,2 -llm-cache,false -llm-server-mlock,false -``` - -### External API - -Using a cloud provider for inference: - -```csv -name,value -llm-key,sk-... -llm-url,https://api.anthropic.com -llm-model,claude-3 -llm-cache,true -llm-cache-ttl,7200 -``` - -## Performance Tuning - -### For Responsiveness - -When response speed is the priority, decrease `llm-server-ctx-size` and `llm-server-n-predict` to reduce processing time. Enable both `llm-cache` and `llm-cache-semantic` to serve repeated queries instantly. - -### For Quality - -When output quality matters most, increase `llm-server-ctx-size` and `llm-server-n-predict` to give the model more context and generation headroom. Use higher quantization models like Q5_K_M or F16 for better accuracy. Either disable semantic cache entirely or raise the threshold to avoid returning imprecise cached responses. - -### For Multiple Users - -Supporting concurrent users requires enabling `llm-server-cont-batching` and increasing `llm-server-parallel` to handle multiple requests simultaneously. Enable caching to reduce redundant inference calls. If available, GPU offloading significantly improves throughput under load. - -## Model Selection Guidelines - -### Small Models (1-3B parameters) - -Small models like DeepSeek-R1-Distill-Qwen-1.5B deliver fast responses with low memory usage. They work well for simple tasks, quick interactions, and resource-constrained environments. - -### Medium Models (7-13B parameters) - -Medium-sized models such as Llama-2-7B and Mistral-7B provide balanced performance suitable for general-purpose applications. They require moderate memory but handle a wide range of tasks competently. - -### Large Models (30B+ parameters) - -Large models like Llama-2-70B and Mixtral-8x7B offer the best quality for complex reasoning tasks. They require substantial memory and compute resources but excel at nuanced understanding and generation. - -## Troubleshooting - -### Model Won't Load - -If the model fails to load, first verify the file path exists and is accessible. Check that your system has sufficient RAM for the model size. Ensure the GGUF file version is compatible with your llama.cpp build. - -### Slow Responses - -Slow generation typically indicates resource constraints. Reduce context size, enable caching to avoid redundant inference, use GPU offloading if hardware permits, or switch to a smaller quantized model. - -### Out of Memory - -Memory errors require reducing resource consumption. Lower `llm-server-ctx-size` and `llm-server-parallel` values. Switch to more aggressively quantized models (Q3 instead of Q5). Disable `llm-server-mlock` to allow the OS to manage memory more flexibly. - -### Connection Refused - -Connection errors usually indicate server configuration issues. Verify `llm-server` is set to true if expecting BotServer to run the server. Check that the configured port is not already in use by another process. Ensure firewall rules allow connections on the specified port. - -## Best Practices - -Start with smaller models and scale up only as needed, since larger models consume more resources without always providing proportionally better results. Enable caching for any production deployment to reduce costs and improve response times. Monitor RAM usage during operation to catch memory pressure before it causes problems. Test model responses thoroughly before deploying to production to ensure quality meets requirements. Document which models you're using and their performance characteristics. Track changes to your `config.csv` in version control to maintain a history of configuration adjustments. \ No newline at end of file diff --git a/docs/src/chapter-08-config/minio.md b/docs/src/chapter-08-config/minio.md deleted file mode 100644 index 31543880..00000000 --- a/docs/src/chapter-08-config/minio.md +++ /dev/null @@ -1,133 +0,0 @@ -# Drive Integration - -The drive component provides S3-compatible object storage for BotServer, storing bot packages, documents, and user files. - -## Overview - -BotServer uses the drive component as its primary storage backend for bot packages in `.gbai` directories, knowledge base documents in `.gbkb` files, configuration files like `config.csv`, media and attachments, and user-uploaded content. - -## Configuration - -Storage configuration is automatically managed by the Directory service (Zitadel), so you do not need to configure storage credentials manually. During bootstrap, the Directory service provisions storage credentials, distributes them securely to BotServer, and handles credential rotation automatically. - -## Storage Structure - -### Bucket Organization - -Each bot gets its own bucket named after the bot package. The bucket naming convention uses `{bot-name}.gbai` for bot buckets and `botserver-media` for the shared media bucket. Each bucket contains the complete bot package structure. - -Bot package structure - -## Features - -### Automatic Upload - -When deploying a bot package, BotServer automatically creates a bucket if it doesn't exist, uploads all package files, maintains the directory structure, and preserves file permissions. - -### Real-time Synchronization - -The bot monitors its bucket for changes. Configuration updates trigger automatic reload, new knowledge base files are indexed immediately, and deleted files are removed from the index automatically. - -### Drive Monitor - -The `DriveMonitor` service watches for changes in drive storage. It detects configuration updates, triggers bot reloads when changes occur, and syncs the local cache with drive storage. - -## Bootstrap Integration - -During bootstrap, BotServer handles installation by downloading and installing the drive binary if not present, receiving credentials from the Directory service, creating data directories, and uploading template files to drive storage. - -Knowledge base files are uploaded to drive buckets, indexed for vector search, and cached locally for improved performance. - -The BASIC `GET` keyword can retrieve files from drive: - -```basic -content = GET "knowledge.gbkb/document.pdf" -``` - -This retrieves files from the bot's bucket in drive storage. - -## Media Handling - -The multimedia handler uses drive for storing uploaded images, serving media files, managing attachments, and processing thumbnails. - -## Console Integration - -The built-in console provides a file browser for drive with paths like `/media/` for browsing uploaded media, `/files/{bot}/` for browsing bot files, and `/download/{bot}/{file}` for downloading specific files. - -## S3-Compatible Client Configuration - -BotServer uses an S3-compatible client configured for the drive: - -```rust -let config = S3Config::builder() - .endpoint_url(&drive_endpoint) - .region("us-east-1") // Required but arbitrary for S3-compatible - .force_path_style(true) - .build(); -``` - -The `force_path_style(true)` setting ensures compatibility with S3-compatible storage providers. - -## Deployment Modes - -### Local Mode - -The default mode runs drive on the same machine. The binary is downloaded to `{{BIN_PATH}}/drive`, data is stored in `{{DATA_PATH}}`, and logs are written to `{{LOGS_PATH}}/drive.log`. - -### Container Mode (LXC) - -Drive can run in an LXC container with mapped volumes for persistent storage: - -```bash -lxc config device add default-drive data disk \ - source=/opt/gbo/data path=/opt/gbo/data -``` - -### External S3-Compatible Storage - -BotServer can use existing S3-compatible infrastructure. The Directory service manages the connection and supports providers including MinIO (the default local installation), Backblaze B2, Wasabi, DigitalOcean Spaces, Cloudflare R2, and any other S3-compatible service. - -To use external storage, configure it through the Directory service admin console. - -## Security - -Credentials are managed by the Directory service for centralized security. TLS can be enabled for secure communication between components. Bucket policies control access on a per-bot basis, and credential rotation is handled automatically without service interruption. - -## Monitoring - -The drive console runs on port 9001 as an optional management interface. The API endpoint runs on port 9000 for programmatic access. Health checks are available via `/health/live` and metrics can be scraped from `/metrics`. - -## Troubleshooting - -### Check Drive Status - -The package manager monitors drive status using: -```bash -ps -ef | grep drive | grep -v grep -``` - -### Console Access - -The drive console is available at `http://localhost:9001` for bucket management, user management, policy configuration, and access log review. - -## Common Issues - -Connection failures typically indicate that drive is not running or ports are not accessible. Access denied errors suggest the Directory service has not yet provisioned credentials. Bucket not found errors occur when bot deployment did not complete successfully. Upload failures often result from insufficient disk space or incorrect permissions. - -### Debug Logging - -Enable trace logging to see drive operations: - -```bash -RUST_LOG=trace ./botserver -``` - -This reveals file retrieval details, bucket operations, and authentication attempts. - -## Best Practices - -Back up the drive data directory regularly to prevent data loss. Monitor disk usage to ensure adequate storage space remains available. Use bucket policies to restrict access appropriately for each bot. Enable object versioning for critical data that may need recovery. Configure lifecycle policies for automatic cleanup of old files that are no longer needed. - -## See Also - -The Storage API chapter provides the complete API reference for drive operations. The Environment Variables appendix covers Directory service configuration options. The LXC Containers documentation explains container deployment in detail. \ No newline at end of file diff --git a/docs/src/chapter-08-config/multimodal.md b/docs/src/chapter-08-config/multimodal.md deleted file mode 100644 index 837bff75..00000000 --- a/docs/src/chapter-08-config/multimodal.md +++ /dev/null @@ -1,247 +0,0 @@ -# Multimodal Configuration - -General Bots integrates with botmodels—a Python service for multimodal AI tasks—to enable image generation, video creation, audio synthesis, and vision capabilities directly from BASIC scripts. - -General Bots - -## Architecture - -``` -┌─────────────┐ HTTPS ┌─────────────┐ -│ botserver │ ────────────▶ │ botmodels │ -│ (Rust) │ │ (Python) │ -└─────────────┘ └─────────────┘ - │ │ - │ BASIC Keywords │ AI Models - │ - IMAGE │ - Stable Diffusion - │ - VIDEO │ - Zeroscope - │ - AUDIO │ - TTS/Whisper - │ - SEE │ - BLIP2 -``` - -When a BASIC script calls a multimodal keyword, botserver forwards the request to botmodels, which runs the appropriate AI model and returns the generated content. - -## Configuration - -Add these settings to your bot's `config.csv` file to enable multimodal capabilities. - -### BotModels Service - -| Key | Default | Description | -|-----|---------|-------------| -| `botmodels-enabled` | `false` | Enable botmodels integration | -| `botmodels-host` | `0.0.0.0` | Host address for botmodels service | -| `botmodels-port` | `8085` | Port for botmodels service | -| `botmodels-api-key` | — | API key for authentication | -| `botmodels-https` | `false` | Use HTTPS for connection | - -### Image Generation - -| Key | Default | Description | -|-----|---------|-------------| -| `image-generator-model` | — | Path to image generation model | -| `image-generator-steps` | `4` | Inference steps (more = higher quality, slower) | -| `image-generator-width` | `512` | Output image width in pixels | -| `image-generator-height` | `512` | Output image height in pixels | -| `image-generator-gpu-layers` | `20` | Layers to offload to GPU | -| `image-generator-batch-size` | `1` | Batch size for generation | - -### Video Generation - -| Key | Default | Description | -|-----|---------|-------------| -| `video-generator-model` | — | Path to video generation model | -| `video-generator-frames` | `24` | Number of frames to generate | -| `video-generator-fps` | `8` | Output frames per second | -| `video-generator-width` | `320` | Output video width in pixels | -| `video-generator-height` | `576` | Output video height in pixels | -| `video-generator-gpu-layers` | `15` | Layers to offload to GPU | -| `video-generator-batch-size` | `1` | Batch size for generation | - -## Example Configuration - -```csv -key,value -botmodels-enabled,true -botmodels-host,0.0.0.0 -botmodels-port,8085 -botmodels-api-key,your-secret-key -botmodels-https,false -image-generator-model,../../../../data/diffusion/sd_turbo_f16.gguf -image-generator-steps,4 -image-generator-width,512 -image-generator-height,512 -image-generator-gpu-layers,20 -video-generator-model,../../../../data/diffusion/zeroscope_v2_576w -video-generator-frames,24 -video-generator-fps,8 -``` - -## BASIC Keywords - -Once configured, these keywords become available in your scripts. - -### IMAGE - -Generate an image from a text prompt: - -```basic -file = IMAGE "a sunset over mountains with purple clouds" -SEND FILE TO user, file -``` - -The keyword returns a path to the generated image file. - -### VIDEO - -Generate a video from a text prompt: - -```basic -file = VIDEO "a rocket launching into space" -SEND FILE TO user, file -``` - -Video generation is more resource-intensive than image generation. Expect longer processing times. - -### AUDIO - -Generate speech audio from text: - -```basic -file = AUDIO "Hello, welcome to our service!" -SEND FILE TO user, file -``` - -### SEE - -Analyze an image or video and get a description: - -```basic -' Describe an image -caption = SEE "/path/to/image.jpg" -TALK caption - -' Describe a video -description = SEE "/path/to/video.mp4" -TALK description -``` - -The SEE keyword uses vision models to understand visual content and return natural language descriptions. - -## Starting BotModels - -Before using multimodal features, start the botmodels service: - -```bash -cd botmodels -python -m uvicorn src.main:app --host 0.0.0.0 --port 8085 -``` - -For production with HTTPS: - -```bash -python -m uvicorn src.main:app \ - --host 0.0.0.0 \ - --port 8085 \ - --ssl-keyfile key.pem \ - --ssl-certfile cert.pem -``` - -## BotModels API Endpoints - -The botmodels service exposes these REST endpoints: - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/api/image/generate` | POST | Generate image from prompt | -| `/api/video/generate` | POST | Generate video from prompt | -| `/api/speech/generate` | POST | Generate speech from text | -| `/api/speech/totext` | POST | Transcribe audio to text | -| `/api/vision/describe` | POST | Describe an image | -| `/api/vision/describe_video` | POST | Describe a video | -| `/api/vision/vqa` | POST | Visual question answering | -| `/api/health` | GET | Health check | - -All endpoints except `/api/health` require the `X-API-Key` header for authentication. - -## Model Paths - -Configure model paths relative to the botmodels service directory. Typical layout: - -``` -data/ -├── diffusion/ -│ ├── sd_turbo_f16.gguf # Stable Diffusion -│ └── zeroscope_v2_576w/ # Zeroscope video -├── tts/ -│ └── model.onnx # Text-to-speech -├── whisper/ -│ └── model.bin # Speech-to-text -└── vision/ - └── blip2/ # Vision model -``` - -## GPU Acceleration - -Both image and video generation benefit significantly from GPU acceleration. Configure GPU layers based on your hardware: - -| GPU VRAM | Recommended GPU Layers | -|----------|----------------------| -| 4GB | 8-12 | -| 8GB | 15-20 | -| 12GB+ | 25-35 | - -Lower GPU layers if you experience out-of-memory errors. - -## Troubleshooting - -**"BotModels is not enabled"** - -Set `botmodels-enabled=true` in your config.csv. - -**Connection refused** - -Verify botmodels service is running and check host/port configuration. Test connectivity: - -```bash -curl http://localhost:8085/api/health -``` - -**Authentication failed** - -Ensure `botmodels-api-key` in config.csv matches the `API_KEY` environment variable in botmodels. - -**Model not found** - -Verify model paths are correct and models are downloaded to the expected locations. - -**Out of memory** - -Reduce `gpu-layers` or `batch-size`. Video generation is particularly memory-intensive. - -## Security Considerations - -**Use HTTPS in production.** Set `botmodels-https=true` and configure SSL certificates on the botmodels service. - -**Use strong API keys.** Generate cryptographically random keys for the `botmodels-api-key` setting. - -**Restrict network access.** Limit botmodels service access to trusted hosts only. - -**Consider GPU isolation.** Run botmodels on a dedicated GPU server if sharing resources with other services. - -## Performance Tips - -**Image generation** runs fastest with SD Turbo models and 4-8 inference steps. More steps improve quality but increase generation time linearly. - -**Video generation** is the most resource-intensive operation. Keep frame counts low (24-48) for reasonable response times. - -**Batch processing** improves throughput when generating multiple items. Increase `batch-size` if you have sufficient GPU memory. - -**Caching** generated content when appropriate. If multiple users request similar content, consider storing results. - -## See Also - -- [LLM Configuration](./llm-config.md) - Language model settings -- [Bot Parameters](./parameters.md) - All configuration options -- [IMAGE Keyword](../chapter-06-gbdialog/keywords.md) - Image generation reference -- [SEE Keyword](../chapter-06-gbdialog/keywords.md) - Vision capabilities \ No newline at end of file diff --git a/docs/src/chapter-08-config/parameters.md b/docs/src/chapter-08-config/parameters.md deleted file mode 100644 index 4185b938..00000000 --- a/docs/src/chapter-08-config/parameters.md +++ /dev/null @@ -1,499 +0,0 @@ -# Configuration Parameters - -Complete reference of all available parameters in `config.csv`. - -## Server Parameters - -### Web Server -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `server-host` | Server bind address | `0.0.0.0` | IP address | -| `server-port` | Server listen port | `8080` | Number (1-65535) | -| `sites-root` | Generated sites directory | `/tmp` | Path | - -### MCP Server -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `mcp-server` | Enable MCP protocol server | `false` | Boolean | - -## LLM Parameters - -### Core LLM Settings -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `llm-key` | API key for LLM service | `none` | String | -| `llm-url` | LLM service endpoint | `http://localhost:8081` | URL | -| `llm-model` | Model path or identifier | Required | Path/String | -| `llm-models` | Available model aliases for routing | `default` | Semicolon-separated | - -### LLM Cache -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `llm-cache` | Enable response caching | `false` | Boolean | -| `llm-cache-ttl` | Cache time-to-live | `3600` | Seconds | -| `llm-cache-semantic` | Semantic similarity cache | `true` | Boolean | -| `llm-cache-threshold` | Similarity threshold | `0.95` | Float (0-1) | - -### Embedded LLM Server -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `llm-server` | Run embedded server | `false` | Boolean | -| `llm-server-path` | Server binary path | `botserver-stack/bin/llm/build/bin` | Path | -| `llm-server-host` | Server bind address | `0.0.0.0` | IP address | -| `llm-server-port` | Server port | `8081` | Number | -| `llm-server-gpu-layers` | GPU offload layers | `0` | Number | -| `llm-server-n-moe` | MoE experts count | `0` | Number | -| `llm-server-ctx-size` | Context size | `4096` | Tokens | -| `llm-server-n-predict` | Max predictions | `1024` | Tokens | -| `llm-server-parallel` | Parallel requests | `6` | Number | -| `llm-server-cont-batching` | Continuous batching | `true` | Boolean | -| `llm-server-mlock` | Lock in memory | `false` | Boolean | -| `llm-server-no-mmap` | Disable mmap | `false` | Boolean | -| `llm-server-reasoning-format` | Reasoning output format for llama.cpp | `none` | String | - -### Hardware-Specific LLM Tuning - -#### For RTX 3090 (24GB VRAM) -You can run impressive models with proper configuration: -- **DeepSeek-R1-Distill-Qwen-7B**: Set `llm-server-gpu-layers` to 35-40 -- **Qwen2.5-32B-Instruct (Q4_K_M)**: Fits with `llm-server-gpu-layers` to 40-45 -- **DeepSeek-V3 (with MoE)**: Set `llm-server-n-moe` to 2-4 to run even 120B models! MoE only loads active experts -- **Optimization**: Use `llm-server-ctx-size` of 8192 for longer contexts - -#### For RTX 4070/4070Ti (12-16GB VRAM) -Mid-range cards work great with quantized models: -- **Qwen2.5-14B (Q4_K_M)**: Set `llm-server-gpu-layers` to 25-30 -- **DeepSeek-R1-Distill-Llama-8B**: Fully fits with layers at 32 -- **Tips**: Keep `llm-server-ctx-size` at 4096 to save VRAM - -#### For CPU-Only (No GPU) -Modern CPUs can still run capable models: -- **DeepSeek-R1-Distill-Qwen-1.5B**: Fast on CPU, great for testing -- **Phi-3-mini (3.8B)**: Excellent CPU performance -- **Settings**: Set `llm-server-mlock` to `true` to prevent swapping -- **Parallel**: Increase `llm-server-parallel` to CPU cores -2 - -#### Recommended Models (GGUF Format) -- **Best Overall**: DeepSeek-R1-Distill series (1.5B to 70B) -- **Best Small**: Qwen2.5-3B-Instruct-Q5_K_M -- **Best Medium**: DeepSeek-R1-Distill-Qwen-14B-Q4_K_M -- **Best Large**: DeepSeek-V3, Qwen2.5-32B, or GPT2-120B-GGUF (with MoE enabled) - -**Pro Tip**: The `llm-server-n-moe` parameter is magic for large models - it enables Mixture of Experts, letting you run 120B+ models on consumer hardware by only loading the experts needed for each token! - -#### Local vs Cloud: A Practical Note - -General Bots excels at local deployment - you own your hardware, your data stays private, and there are no recurring costs. However, if you need cloud inference: - -**Groq is the speed champion** - They use custom LPU (Language Processing Unit) chips instead of GPUs, delivering 10x faster inference than traditional cloud providers. Their hardware is purpose-built for transformers, avoiding the general-purpose overhead of NVIDIA GPUs. - -This isn't about market competition - it's about architecture. NVIDIA GPUs are designed for many tasks, while Groq's chips do one thing incredibly well: transformer inference. If speed matters and you're using cloud, Groq is currently the fastest option available. - -For local deployment, stick with General Bots and the configurations above. For cloud bursts or when you need extreme speed, consider Groq's API with these settings: -```csv -llm-url,https://api.groq.com/openai/v1 -llm-key,your-groq-api-key -llm-model,mixtral-8x7b-32768 -``` - -## Embedding Parameters - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `embedding-url` | Embedding service endpoint | `http://localhost:8082` | URL | -| `embedding-model` | Embedding model path | Required for KB | Path | - -## Prompt Parameters - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `episodic-memory-threshold` | Context compaction level | `4` | Number | -| `episodic-memory-history` | Messages in history | Not set | Number | - -## Email Parameters - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `email-from` | Sender address | Required for email | Email | -| `email-server` | SMTP hostname | Required for email | Hostname | -| `email-port` | SMTP port | `587` | Number | -| `email-user` | SMTP username | Required for email | String | -| `email-pass` | SMTP password | Required for email | String | - -## Theme Parameters - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `theme-color1` | Primary color | Not set | Hex color | -| `theme-color2` | Secondary color | Not set | Hex color | -| `theme-logo` | Logo URL | Not set | URL | -| `theme-title` | Bot display title | Not set | String | - -## Custom Database Parameters - -These parameters configure external database connections for use with BASIC keywords like MariaDB/MySQL connections. - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `custom-server` | Database server hostname | `localhost` | Hostname | -| `custom-port` | Database port | `3306` | Number | -| `custom-database` | Database name | Not set | String | -| `custom-username` | Database user | Not set | String | -| `custom-password` | Database password | Not set | String | - -### Example: MariaDB Connection -```csv -custom-server,db.example.com -custom-port,3306 -custom-database,myapp -custom-username,botuser -custom-password,secretpass -``` - -## Multi-Agent Parameters - -### Agent-to-Agent (A2A) Communication -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `a2a-enabled` | Enable agent-to-agent communication | `true` | Boolean | -| `a2a-timeout` | Default delegation timeout | `30` | Seconds | -| `a2a-max-hops` | Maximum delegation chain depth | `5` | Number | -| `a2a-retry-count` | Retry attempts on failure | `3` | Number | -| `a2a-queue-size` | Maximum pending messages | `100` | Number | -| `a2a-protocol-version` | A2A protocol version | `1.0` | String | -| `a2a-persist-messages` | Persist A2A messages to database | `false` | Boolean | - -### Bot Reflection -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `bot-reflection-enabled` | Enable bot self-analysis | `true` | Boolean | -| `bot-reflection-interval` | Messages between reflections | `10` | Number | -| `bot-reflection-prompt` | Custom reflection prompt | (none) | String | -| `bot-reflection-types` | Reflection types to perform | `ConversationQuality` | Semicolon-separated | -| `bot-improvement-auto-apply` | Auto-apply suggested improvements | `false` | Boolean | -| `bot-improvement-threshold` | Score threshold for improvements (0-10) | `6.0` | Float | - -#### Reflection Types -Available values for `bot-reflection-types`: -- `ConversationQuality` - Analyze conversation quality and user satisfaction -- `ResponseAccuracy` - Analyze response accuracy and relevance -- `ToolUsage` - Analyze tool usage effectiveness -- `KnowledgeRetrieval` - Analyze knowledge retrieval performance -- `Performance` - Analyze overall bot performance - -Example: -```csv -bot-reflection-enabled,true -bot-reflection-interval,10 -bot-reflection-types,ConversationQuality;ResponseAccuracy;ToolUsage -bot-improvement-auto-apply,false -bot-improvement-threshold,7.0 -``` - -## Memory Parameters - -### User Memory (Cross-Bot) -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `user-memory-enabled` | Enable user-level memory | `true` | Boolean | -| `user-memory-max-keys` | Maximum keys per user | `1000` | Number | -| `user-memory-default-ttl` | Default time-to-live (0=no expiry) | `0` | Seconds | - -### Episodic Memory -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `episodic-memory-enabled` | Enable conversation summaries | `true` | Boolean | -| `episodic-summary-model` | Model for summarization | `fast` | String | -| `episodic-max-episodes` | Maximum episodes per user | `100` | Number | -| `episodic-retention-days` | Days to retain episodes | `365` | Number | -| `episodic-auto-summarize` | Enable automatic summarization | `true` | Boolean | - -## Model Routing Parameters - -These parameters configure multi-model routing for different task types. Requires multiple llama.cpp server instances. - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `llm-models` | Available model aliases | `default` | Semicolon-separated | -| `model-routing-strategy` | Routing strategy (manual/auto/load-balanced/fallback) | `auto` | String | -| `model-default` | Default model alias | `default` | String | -| `model-fast` | Model for fast/simple tasks | (configured) | Path/String | -| `model-quality` | Model for quality/complex tasks | (configured) | Path/String | -| `model-code` | Model for code generation | (configured) | Path/String | -| `model-fallback-enabled` | Enable automatic fallback | `true` | Boolean | -| `model-fallback-order` | Order to try on failure | `quality,fast,local` | Comma-separated | - -### Multi-Model Example -```csv -llm-models,default;fast;quality;code -llm-url,http://localhost:8081 -model-routing-strategy,auto -model-default,fast -model-fallback-enabled,true -model-fallback-order,quality,fast -``` - -## Hybrid RAG Search Parameters - -General Bots uses hybrid search combining **dense (embedding)** and **sparse (BM25 keyword)** search for optimal retrieval. The BM25 implementation is powered by [Tantivy](https://github.com/quickwit-oss/tantivy), a full-text search engine library similar to Apache Lucene. - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `rag-hybrid-enabled` | Enable hybrid dense+sparse search | `true` | Boolean | -| `rag-dense-weight` | Weight for semantic results | `0.7` | Float (0-1) | -| `rag-sparse-weight` | Weight for keyword results | `0.3` | Float (0-1) | -| `rag-reranker-enabled` | Enable LLM reranking | `false` | Boolean | -| `rag-reranker-model` | Model for reranking | `cross-encoder/ms-marco-MiniLM-L-6-v2` | String | -| `rag-reranker-top-n` | Candidates for reranking | `20` | Number | -| `rag-max-results` | Maximum results to return | `10` | Number | -| `rag-min-score` | Minimum relevance score threshold | `0.0` | Float (0-1) | -| `rag-rrf-k` | RRF smoothing constant | `60` | Number | -| `rag-cache-enabled` | Enable search result caching | `true` | Boolean | -| `rag-cache-ttl` | Cache time-to-live | `3600` | Seconds | - -### BM25 Sparse Search (Tantivy) - -BM25 is a keyword-based ranking algorithm that excels at finding exact term matches. It's powered by Tantivy when the `vectordb` feature is enabled. - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `bm25-enabled` | **Enable/disable BM25 sparse search** | `true` | Boolean | -| `bm25-k1` | Term frequency saturation (0.5-3.0 typical) | `1.2` | Float | -| `bm25-b` | Document length normalization (0.0-1.0) | `0.75` | Float | -| `bm25-stemming` | Apply word stemming (running→run) | `true` | Boolean | -| `bm25-stopwords` | Filter common words (the, a, is) | `true` | Boolean | - -### Switching Search Modes - -**Hybrid Search (Default - Best for most use cases)** -```csv -bm25-enabled,true -rag-dense-weight,0.7 -rag-sparse-weight,0.3 -``` -Uses both semantic understanding AND keyword matching. Best for general queries. - -**Dense Only (Semantic Search)** -```csv -bm25-enabled,false -rag-dense-weight,1.0 -rag-sparse-weight,0.0 -``` -Uses only embedding-based search. Faster, good for conceptual/semantic queries where exact words don't matter. - -**Sparse Only (Keyword Search)** -```csv -bm25-enabled,true -rag-dense-weight,0.0 -rag-sparse-weight,1.0 -``` -Uses only BM25 keyword matching. Good for exact term searches, technical documentation, or when embeddings aren't available. - -### BM25 Parameter Tuning - -The `k1` and `b` parameters control BM25 behavior: - -- **`bm25-k1`** (Term Saturation): Controls how much additional term occurrences contribute to the score - - Lower values (0.5-1.0): Diminishing returns for repeated terms - - Higher values (1.5-2.0): More weight to documents with many term occurrences - - Default `1.2` works well for most content - -- **`bm25-b`** (Length Normalization): Controls document length penalty - - `0.0`: No length penalty (long documents scored equally) - - `1.0`: Full length normalization (strongly penalizes long documents) - - Default `0.75` balances length fairness - -**Tuning for specific content:** -```csv -# For short documents (tweets, titles) -bm25-b,0.3 - -# For long documents (articles, manuals) -bm25-b,0.9 - -# For code search (exact matches important) -bm25-k1,1.5 -bm25-stemming,false -``` - -## Code Sandbox Parameters - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `sandbox-enabled` | Enable code sandbox | `true` | Boolean | -| `sandbox-runtime` | Isolation backend (lxc/docker/firecracker/process) | `lxc` | String | -| `sandbox-timeout` | Maximum execution time | `30` | Seconds | -| `sandbox-memory-mb` | Memory limit in megabytes | `256` | MB | -| `sandbox-cpu-percent` | CPU usage limit | `50` | Percent | -| `sandbox-network` | Allow network access | `false` | Boolean | -| `sandbox-python-packages` | Pre-installed Python packages | (none) | Comma-separated | -| `sandbox-allowed-paths` | Accessible filesystem paths | `/data,/tmp` | Comma-separated | - -### Example: Python Sandbox -```csv -sandbox-enabled,true -sandbox-runtime,lxc -sandbox-timeout,60 -sandbox-memory-mb,512 -sandbox-cpu-percent,75 -sandbox-network,false -sandbox-python-packages,numpy,pandas,requests,matplotlib -sandbox-allowed-paths,/data,/tmp,/uploads -``` - -## SSE Streaming Parameters - -| Parameter | Description | Default | Type | -|-----------|-------------|---------|------| -| `sse-enabled` | Enable Server-Sent Events | `true` | Boolean | -| `sse-heartbeat` | Heartbeat interval | `30` | Seconds | -| `sse-max-connections` | Maximum concurrent connections | `1000` | Number | - -## Parameter Types - -### Boolean -Values: `true` or `false` (case-sensitive) - -### Number -Integer values, must be within valid ranges: -- Ports: 1-65535 -- Tokens: Positive integers -- Percentages: 0-100 - -### Float -Decimal values: -- Thresholds: 0.0 to 1.0 -- Weights: 0.0 to 1.0 - -### Path -File system paths: -- Relative: `../../../../data/model.gguf` -- Absolute: `/opt/models/model.gguf` - -### URL -Valid URLs: -- HTTP: `http://localhost:8081` -- HTTPS: `https://api.example.com` - -### String -Any text value (no quotes needed in CSV) - -### Email -Valid email format: `user@domain.com` - -### Hex Color -HTML color codes: `#RRGGBB` format - -### Semicolon-separated -Multiple values separated by semicolons: `value1;value2;value3` - -### Comma-separated -Multiple values separated by commas: `value1,value2,value3` - -## Required vs Optional - -### Always Required -- None - all parameters have defaults or are optional - -### Required for Features -- **LLM**: `llm-model` must be set -- **Email**: `email-from`, `email-server`, `email-user` -- **Embeddings**: `embedding-model` for knowledge base -- **Custom DB**: `custom-database` if using external database - -## Configuration Precedence - -1. **Built-in defaults** (hardcoded) -2. **config.csv values** (override defaults) -3. **Environment variables** (if implemented, override config) - -## Special Values - -- `none` - Explicitly no value (for `llm-key`) -- Empty string - Unset/use default -- `false` - Feature disabled -- `true` - Feature enabled - -## Performance Tuning - -### For Local Models -```csv -llm-server-ctx-size,8192 -llm-server-n-predict,2048 -llm-server-parallel,4 -llm-cache,true -llm-cache-ttl,7200 -``` - -### For Production -```csv -llm-server-cont-batching,true -llm-cache-semantic,true -llm-cache-threshold,0.90 -llm-server-parallel,8 -sse-max-connections,5000 -``` - -### For Low Memory -```csv -llm-server-ctx-size,2048 -llm-server-n-predict,512 -llm-server-mlock,false -llm-server-no-mmap,false -llm-cache,false -sandbox-memory-mb,128 -``` - -### For Multi-Agent Systems -```csv -a2a-enabled,true -a2a-timeout,30 -a2a-max-hops,5 -a2a-retry-count,3 -a2a-persist-messages,true -bot-reflection-enabled,true -bot-reflection-interval,10 -user-memory-enabled,true -``` - -### For Hybrid RAG -```csv -rag-hybrid-enabled,true -rag-dense-weight,0.7 -rag-sparse-weight,0.3 -rag-reranker-enabled,true -rag-max-results,10 -rag-min-score,0.3 -rag-cache-enabled,true -bm25-enabled,true -bm25-k1,1.2 -bm25-b,0.75 -``` - -### For Dense-Only Search (Faster) -```csv -bm25-enabled,false -rag-dense-weight,1.0 -rag-sparse-weight,0.0 -rag-max-results,10 -``` - -### For Code Execution -```csv -sandbox-enabled,true -sandbox-runtime,lxc -sandbox-timeout,30 -sandbox-memory-mb,512 -sandbox-network,false -sandbox-python-packages,numpy,pandas,requests -``` - -## Validation Rules - -1. **Paths**: Model files must exist -2. **URLs**: Must be valid format -3. **Ports**: Must be 1-65535 -4. **Emails**: Must contain @ and domain -5. **Colors**: Must be valid hex format -6. **Booleans**: Exactly `true` or `false` -7. **Weights**: Must sum to 1.0 (e.g., `rag-dense-weight` + `rag-sparse-weight`) \ No newline at end of file diff --git a/docs/src/chapter-08-config/secrets-management.md b/docs/src/chapter-08-config/secrets-management.md deleted file mode 100644 index a3a02b6c..00000000 --- a/docs/src/chapter-08-config/secrets-management.md +++ /dev/null @@ -1,543 +0,0 @@ -# Secrets Management - -General Bots uses a layered approach to configuration and secrets management. The goal is to keep `.env` **minimal** - containing only Vault connection info - while all sensitive data is stored securely in Vault. - -## Configuration Layers - -``` -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Configuration Hierarchy │ -├─────────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌───────────┐ │ -│ │ .env │ │ Zitadel │ │ Vault │ │config.csv │ │ -│ │(Vault ONLY) │ │ (Identity) │ │ (Secrets) │ │(Bot Config)│ │ -│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └─────┬─────┘ │ -│ │ │ │ │ │ -│ ▼ ▼ ▼ ▼ │ -│ • VAULT_ADDR • User accounts • Directory URL • Bot params │ -│ • VAULT_TOKEN • Organizations • Database creds • LLM config │ -│ • Projects • API keys • Features │ -│ • Applications • Drive credentials • Behavior │ -│ • MFA settings • Encryption keys │ -│ • SSO/OAuth • ALL service secrets │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ -``` - -## What Goes Where? - -### .env (Vault Connection ONLY) - -The `.env` file should contain **ONLY** Vault connection info: - -```bash -# .env - ONLY Vault connection -# Everything else comes from Vault! - -VAULT_ADDR=https://localhost:8200 -VAULT_TOKEN=hvs.your-root-token -``` - -That's it. **Two variables only.** - -**Why so minimal?** -- `.env` files can be accidentally committed to git -- Environment variables may appear in logs -- Reduces attack surface if server is compromised -- Single point of secret management (Vault) -- Easy rotation - change in Vault, not in files - -### Zitadel (Identity & Access) - -Zitadel manages **user-facing** identity: - -| What | Example | -|------|---------| -| User accounts | john@example.com | -| Organizations | Acme Corp | -| Projects | Production Bot | -| Applications | Web UI, Mobile App | -| MFA settings | TOTP, SMS, WebAuthn | -| SSO providers | Google, Microsoft | -| User metadata | Department, Role | - -**Not stored in Zitadel:** -- Service passwords -- API keys -- Encryption keys - -### Vault (Service Secrets) - -Vault manages **machine-to-machine** secrets: - -| Path | Contents | -|------|----------| -| `gbo/drive` | MinIO access key and secret | -| `gbo/tables` | PostgreSQL username and password | -| `gbo/cache` | Redis password | -| `gbo/llm` | OpenAI, Anthropic, Groq API keys | -| `gbo/encryption` | Master encryption key, data keys | -| `gbo/email` | SMTP credentials | -| `gbo/meet` | LiveKit API key and secret | -| `gbo/alm` | Forgejo admin password, runner token | - -### config.csv (Bot Configuration) - -The bot's `config.csv` contains **non-sensitive** configuration: - -```csv -# Bot behavior - NOT secrets -llm-provider,openai -llm-model,gpt-4o -llm-temperature,0.7 -llm-max-tokens,4096 - -# Feature flags -feature-voice-enabled,true -feature-file-upload,true - -# Vault references for sensitive values -llm-api-key,vault:gbo/llm/openai_key -``` - -Note: Most service credentials (database, drive, cache) are fetched automatically from Vault at startup. You only need `vault:` references in config.csv for bot-specific secrets like LLM API keys. - -## How Secrets Flow - -### At Startup - -``` -1. BotServer starts -2. Reads .env for VAULT_ADDR and VAULT_TOKEN (only 2 variables) -3. Connects to Vault -4. Fetches ALL service credentials: - - gbo/directory → Zitadel URL, client_id, client_secret - - gbo/tables → Database host, port, username, password - - gbo/drive → MinIO endpoint, accesskey, secret - - gbo/cache → Redis host, port, password - - gbo/llm → API keys for all providers - - gbo/encryption → Master encryption keys -5. Connects to all services using Vault credentials -6. Reads config.csv for bot configuration -7. For keys referencing Vault (vault:path/key): - - Fetches from Vault automatically -8. System ready -``` - -### At Runtime - -``` -1. User sends message -2. Bot processes, needs LLM -3. Reads config.csv: llm-api-key = vault:gbo/llm/openai_key -4. Fetches from Vault (cached for performance) -5. Calls OpenAI API -6. Returns response -``` - -## Setting Up Vault - -### Initial Setup - -When you run `./botserver install secrets`, it: - -1. Downloads and installs Vault -2. Initializes with a single unseal key -3. Creates initial secret paths -4. Outputs root token to `conf/vault/init.json` - -```bash -# Check Vault status -./botserver status secrets - -# View init credentials (protect this file!) -cat botserver-stack/conf/vault/init.json -``` - -### Storing Secrets - -Use the Vault CLI or API: - -```bash -# Directory (Zitadel) - includes URL, no longer in .env -vault kv put gbo/directory \ - url=https://localhost:8080 \ - project_id=your-project-id \ - client_id=your-client-id \ - client_secret=your-client-secret - -# Database - includes host/port, no longer in .env -vault kv put gbo/tables \ - host=localhost \ - port=5432 \ - database=botserver \ - username=gbuser \ - password=secure-password - -# Drive (MinIO) -vault kv put gbo/drive \ - endpoint=https://localhost:9000 \ - accesskey=minioadmin \ - secret=minioadmin123 - -# Cache (Redis) -vault kv put gbo/cache \ - host=localhost \ - port=6379 \ - password=redis-secret - -# LLM API keys -vault kv put gbo/llm \ - openai_key=sk-xxxxx \ - anthropic_key=sk-ant-xxxxx \ - groq_key=gsk_xxxxx \ - deepseek_key=sk-xxxxx - -# Encryption keys -vault kv put gbo/encryption \ - master_key=your-32-byte-key - -# Vector database (Qdrant) -vault kv put gbo/vectordb \ - url=https://localhost:6334 \ - api_key=optional-api-key - -# Observability (InfluxDB) -vault kv put gbo/observability \ - url=http://localhost:8086 \ - org=pragmatismo \ - bucket=metrics \ - token=your-influx-token -``` - -### Automatic Management - -**Secrets are managed automatically** - you don't need a UI for day-to-day operations: - -| Action | How It Works | -|--------|--------------| -| Service startup | Fetches credentials from Vault | -| Key rotation | Update in Vault, services reload | -| New bot deployment | Inherits organization secrets | -| LLM provider change | Update config.csv, key fetched automatically | - -### Emergency Access - -For emergency situations (lost credentials, key rotation), admins can: - -1. **Access Vault UI**: `https://localhost:8200/ui` -2. **Use Vault CLI**: `vault kv get gbo/llm` -3. **Check init.json**: Contains unseal key and root token - -```bash -# Emergency: unseal Vault after restart -UNSEAL_KEY=$(cat botserver-stack/conf/vault/init.json | jq -r '.unseal_keys_b64[0]') -vault operator unseal $UNSEAL_KEY -``` - -## Migrating from Environment Variables - -If you're currently using environment variables: - -### Before (Old Way) - -```bash -# .env - TOO MANY SECRETS! -DATABASE_URL=postgres://user:password@localhost/db -DIRECTORY_URL=https://localhost:8080 -DIRECTORY_PROJECT_ID=12345 -REDIS_PASSWORD=redis-secret -OPENAI_API_KEY=sk-xxxxx -ANTHROPIC_API_KEY=sk-ant-xxxxx -DRIVE_ACCESSKEY=minio -DRIVE_SECRET=minio123 -ENCRYPTION_KEY=super-secret-key -``` - -### After (With Vault) - -```bash -# .env - ONLY VAULT CONNECTION -VAULT_ADDR=https://localhost:8200 -VAULT_TOKEN=hvs.xxxxx -``` - -```bash -# EVERYTHING in Vault -vault kv put gbo/directory \ - url=https://localhost:8080 \ - project_id=12345 \ - client_id=xxx \ - client_secret=xxx - -vault kv put gbo/tables \ - host=localhost \ - port=5432 \ - database=botserver \ - username=user \ - password=password - -vault kv put gbo/cache \ - host=localhost \ - port=6379 \ - password=redis-secret - -vault kv put gbo/llm \ - openai_key=sk-xxxxx \ - anthropic_key=sk-ant-xxxxx - -vault kv put gbo/drive \ - endpoint=https://localhost:9000 \ - accesskey=minio \ - secret=minio123 - -vault kv put gbo/encryption \ - master_key=super-secret-key -``` - -### Migration Script - -```bash -#!/bin/bash -# migrate-to-vault.sh - -# Read existing .env -source .env - -# Parse DATABASE_URL if present -if [ -n "$DATABASE_URL" ]; then - # postgres://user:pass@host:port/db - DB_USER=$(echo $DATABASE_URL | sed -n 's|postgres://\([^:]*\):.*|\1|p') - DB_PASS=$(echo $DATABASE_URL | sed -n 's|postgres://[^:]*:\([^@]*\)@.*|\1|p') - DB_HOST=$(echo $DATABASE_URL | sed -n 's|.*@\([^:]*\):.*|\1|p') - DB_PORT=$(echo $DATABASE_URL | sed -n 's|.*:\([0-9]*\)/.*|\1|p') - DB_NAME=$(echo $DATABASE_URL | sed -n 's|.*/\(.*\)|\1|p') -fi - -# Store everything in Vault -vault kv put gbo/directory \ - url="${DIRECTORY_URL:-https://localhost:8080}" \ - project_id="${DIRECTORY_PROJECT_ID:-}" \ - client_id="${ZITADEL_CLIENT_ID:-}" \ - client_secret="${ZITADEL_CLIENT_SECRET:-}" - -vault kv put gbo/tables \ - host="${DB_HOST:-localhost}" \ - port="${DB_PORT:-5432}" \ - database="${DB_NAME:-botserver}" \ - username="${DB_USER:-gbuser}" \ - password="${DB_PASS:-}" - -vault kv put gbo/cache \ - host="${REDIS_HOST:-localhost}" \ - port="${REDIS_PORT:-6379}" \ - password="${REDIS_PASSWORD:-}" - -vault kv put gbo/llm \ - openai_key="${OPENAI_API_KEY:-}" \ - anthropic_key="${ANTHROPIC_API_KEY:-}" \ - groq_key="${GROQ_API_KEY:-}" \ - deepseek_key="${DEEPSEEK_API_KEY:-}" - -vault kv put gbo/drive \ - endpoint="${DRIVE_ENDPOINT:-https://localhost:9000}" \ - accesskey="${DRIVE_ACCESSKEY:-}" \ - secret="${DRIVE_SECRET:-}" - -vault kv put gbo/encryption \ - master_key="${ENCRYPTION_KEY:-}" - -# Clean up .env - ONLY Vault connection -cat > .env << EOF -# General Bots - Vault Connection Only -# All other secrets are stored in Vault - -VAULT_ADDR=https://localhost:8200 -VAULT_TOKEN=$VAULT_TOKEN -EOF - -echo "Migration complete!" -echo ".env now contains only Vault connection." -echo "All secrets moved to Vault." -``` - -## Using Vault References in config.csv - -Reference Vault secrets in your bot's config.csv: - -```csv -# Direct value (non-sensitive) -llm-provider,openai -llm-model,gpt-4o -llm-temperature,0.7 - -# Vault reference (sensitive) -llm-api-key,vault:gbo/llm/openai_key - -# Multiple keys from same path -drive-accesskey,vault:gbo/drive/accesskey -drive-secret,vault:gbo/drive/secret - -# Per-bot secrets (for multi-tenant) -custom-api-key,vault:gbo/bots/mybot/api_key -``` - -### Syntax - -``` -vault:/ -``` - -- `path`: Vault KV path (e.g., `gbo/llm`) -- `key`: Specific key within the secret (e.g., `openai_key`) - -## Security Best Practices - -### 1. Protect init.json - -```bash -# Set restrictive permissions -chmod 600 botserver-stack/conf/vault/init.json - -# Consider encrypting or moving off-server -gpg -c init.json -scp init.json.gpg secure-backup-server: -rm init.json -``` - -### 2. Use Token Policies - -Create limited tokens for applications: - -```hcl -# gbo-readonly.hcl -path "gbo/*" { - capabilities = ["read", "list"] -} -``` - -```bash -vault policy write gbo-readonly gbo-readonly.hcl -vault token create -policy=gbo-readonly -ttl=24h -``` - -### 3. Enable Audit Logging - -```bash -vault audit enable file file_path=/opt/gbo/logs/vault-audit.log -``` - -### 4. Rotate Secrets Regularly - -```bash -# Rotate LLM keys -vault kv put gbo/llm \ - openai_key=sk-new-key \ - anthropic_key=sk-ant-new-key - -# BotServer will pick up new keys automatically (cache TTL) -``` - -### 5. Backup Vault Data - -```bash -# Snapshot Vault data -vault operator raft snapshot save backup.snap - -# Or backup the data directory -tar -czf vault-backup.tar.gz botserver-stack/data/vault/ -``` - -## No UI Needed - -**You don't need to expose a UI for secrets management** because: - -1. **Automatic at runtime**: Secrets are fetched automatically -2. **config.csv for changes**: Update bot config, not secrets -3. **Vault UI for emergencies**: Available at `https://localhost:8200/ui` -4. **CLI for automation**: Scripts can manage secrets - -### When Admins Need Access - -| Situation | Solution | -|-----------|----------| -| Add new LLM provider | `vault kv put gbo/llm new_key=xxx` | -| Rotate compromised key | Update in Vault, services auto-reload | -| Check what's stored | `vault kv get gbo/llm` or Vault UI | -| Debug connection issues | Check Vault logs and service logs | -| Disaster recovery | Use init.json to unseal and recover | - -## Relationship Summary - -``` -┌─────────────────────────────────────────────────────────────────┐ -│ .env │ -│ VAULT_ADDR + VAULT_TOKEN (only!) │ -└─────────────────────────────┬───────────────────────────────────┘ - │ - ▼ -┌─────────────────────────────────────────────────────────────────┐ -│ Vault │ -│ "Give me all service credentials and connection info" │ -│ │ -│ gbo/directory → Zitadel URL, credentials │ -│ gbo/tables → Database connection + credentials │ -│ gbo/drive → MinIO endpoint + credentials │ -│ gbo/cache → Redis connection + password │ -│ gbo/llm → All LLM API keys │ -└─────────────────────────────┬───────────────────────────────────┘ - │ - ▼ -┌─────────────────────────────────────────────────────────────────┐ -│ BotServer │ -│ Connects to all services using Vault secrets │ -└─────────────────────────────┬───────────────────────────────────┘ - │ - ▼ -┌─────────────────────────────────────────────────────────────────┐ -│ User Request │ -└─────────────────────────────┬───────────────────────────────────┘ - │ - ▼ -┌─────────────────────────────────────────────────────────────────┐ -│ Zitadel │ -│ "Who is this user? Are they allowed?" │ -│ (Credentials from Vault at startup) │ -└─────────────────────────────┬───────────────────────────────────┘ - │ - ▼ -┌─────────────────────────────────────────────────────────────────┐ -│ config.csv │ -│ "What LLM should I use? What model?" │ -│ (Non-sensitive bot configuration) │ -└─────────────────────────────┬───────────────────────────────────┘ - │ - ▼ -┌─────────────────────────────────────────────────────────────────┐ -│ LLM Provider │ -│ (API key from Vault at startup) │ -└─────────────────────────────────────────────────────────────────┘ -``` - -## Vault Paths Reference - -| Path | Contents | -|------|----------| -| `gbo/directory` | url, project_id, client_id, client_secret | -| `gbo/tables` | host, port, database, username, password | -| `gbo/drive` | endpoint, accesskey, secret | -| `gbo/cache` | host, port, password | -| `gbo/llm` | openai_key, anthropic_key, groq_key, deepseek_key, mistral_key | -| `gbo/encryption` | master_key, data_key | -| `gbo/email` | host, username, password | -| `gbo/meet` | url, api_key, api_secret | -| `gbo/alm` | url, admin_password, runner_token | -| `gbo/vectordb` | url, api_key | -| `gbo/observability` | url, org, bucket, token | - -## Next Steps - -- [config.csv Format](./config-csv.md) - Bot configuration reference -- [LLM Configuration](./llm-config.md) - LLM-specific settings -- [Infrastructure Design](../chapter-07-gbapp/infrastructure.md) - Full architecture \ No newline at end of file diff --git a/docs/src/chapter-09-api/README.md b/docs/src/chapter-09-api/README.md deleted file mode 100644 index 057978ca..00000000 --- a/docs/src/chapter-09-api/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Chapter 09: API and Tooling - -Define tools that LLMs can call from your BASIC scripts. - -## Overview - -Tools are BASIC scripts with PARAM declarations that become callable functions for the LLM. This enables AI-driven automation with structured inputs. - -## Tool Structure - -```basic -' weather.bas - A tool the LLM can invoke -PARAM city AS STRING LIKE "London" DESCRIPTION "City name" -PARAM units AS STRING LIKE "celsius" DESCRIPTION "Temperature units" - -DESCRIPTION "Gets current weather for a city" - -data = GET "api.weather.com/current?city=" + city -TALK "Weather in " + city + ": " + data.temperature + "°" -``` - -## How It Works - -1. **PARAM** declarations define inputs -2. **DESCRIPTION** explains the tool's purpose -3. LLM decides when to call the tool -4. Parameters collected through conversation -5. Tool executes with validated inputs - -## PARAM Declaration - -```basic -PARAM name AS type LIKE "example" DESCRIPTION "explanation" -``` - -| Component | Purpose | -|-----------|---------| -| `name` | Variable name | -| `type` | STRING, INTEGER, DATE, etc. | -| `LIKE` | Example value for LLM | -| `DESCRIPTION` | What this parameter is for | - -## Tool Formats - -Tools compile to multiple formats: - -| Format | Use Case | -|--------|----------| -| MCP | Model Context Protocol | -| OpenAI | Function calling | -| Internal | BASIC runtime | - -## Chapter Contents - -- [Tool Definition](./tool-definition.md) - Creating tools -- [PARAM Declaration](./param-declaration.md) - Parameter syntax -- [Tool Compilation](./compilation.md) - Build process -- [MCP Format](./mcp-format.md) - MCP integration -- [OpenAI Format](./openai-format.md) - Function calling -- [GET Integration](./get-integration.md) - API calls -- [External APIs](./external-apis.md) - Third-party services -- [LLM REST Server](./llm-rest-server.md) - Hosting models -- [NVIDIA GPU Setup](./nvidia-gpu-setup.md) - GPU acceleration - -## See Also - -- [BASIC Dialogs](../chapter-06-gbdialog/README.md) - Scripting reference -- [REST API](../chapter-10-api/README.md) - HTTP endpoints \ No newline at end of file diff --git a/docs/src/chapter-09-api/compilation.md b/docs/src/chapter-09-api/compilation.md deleted file mode 100644 index b7e7a3be..00000000 --- a/docs/src/chapter-09-api/compilation.md +++ /dev/null @@ -1,122 +0,0 @@ -# Tool Compilation - -BotServer compiles BASIC scripts (`.bas` files) into tool definitions that can be called by the LLM. The compilation process extracts parameters, descriptions, and generates metadata for tool discovery. - -## Overview - -The compilation process reads `.bas` files from `.gbdialog` directories and parses parameter declarations along with descriptions. It then generates tool definitions in both MCP and OpenAI formats, stores the compiled tools in the database, and makes them available for LLM invocation. - -## The Compilation Pipeline - -### File Detection - -The `DriveMonitor` service watches for changes in `.gbdialog` directories. It monitors `.bas` files in drive storage, detects new or modified scripts, and triggers compilation automatically when changes occur. - -### Source Processing - -When a `.bas` file changes, the compiler downloads the file from drive and creates a local working directory. It then invokes the `BasicCompiler` to process the script and extract the necessary metadata. - -### Parameter Extraction - -The compiler parses BASIC script headers for `PARAM` declarations with types and examples, `DESCRIPTION` statements for tool documentation, and variable names with default values. - -Example script header: -```basic -PARAM name AS string LIKE "John Smith" DESCRIPTION "User's full name" -PARAM age AS number LIKE 25 DESCRIPTION "User's age" -DESCRIPTION "Processes user registration" -``` - -### Tool Definition Generation - -The compiler creates structured tool definitions from the parsed script. The tool name is derived from the filename without the `.bas` extension. Parameters are extracted from PARAM declarations, the description comes from the DESCRIPTION statement, and the script path provides a reference to the source file. - -### Database Storage - -Compiled tools are stored in the `basic_tools` table, which contains tool metadata including name, description, and parameters. The table also stores source script content, bot association, and compilation timestamp for tracking when tools were last updated. - -## Compilation Output Formats - -### MCP (Model Context Protocol) Format - -The compiler generates MCP-compatible tool definitions: -```json -{ - "name": "user_registration", - "description": "Processes user registration", - "input_schema": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "User's full name" - }, - "age": { - "type": "number", - "description": "User's age" - } - }, - "required": ["name", "age"] - } -} -``` - -### OpenAI Function Format - -The compiler also generates OpenAI-compatible function definitions for API compatibility: -```json -{ - "name": "user_registration", - "description": "Processes user registration", - "parameters": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "User's full name" - }, - "age": { - "type": "number", - "description": "User's age" - } - }, - "required": ["name", "age"] - } -} -``` - -## Automatic Recompilation - -Tools are recompiled automatically when the source `.bas` file is modified, when the file's ETag changes in drive storage, or when a manual recompilation is triggered through the system. - -## Working Directory Structure - -The compiler maintains a local working directory structured as `./work/bot-name.gbai/bot-name.gbdialog/` containing the individual tool files like `tool1.bas`, `tool2.bas`, and so on. This directory is used for caching compiled scripts, temporary processing during compilation, and debug inspection when troubleshooting issues. - -## Error Handling - -Compilation errors are handled gracefully to ensure the system remains stable. Syntax errors are logged with line numbers for easy debugging. Missing parameters are reported clearly, invalid types are highlighted in error messages, and compilation continues for other tools even when one fails. Common compilation errors include missing DESCRIPTION statements, invalid PARAM syntax, unsupported parameter types, and general script parsing failures. - -## Tool Activation - -After successful compilation, the tool is stored in the database and becomes available for the `USE TOOL` keyword. The LLM can discover the tool through its metadata and invoke it during conversations with users. - -## Performance Considerations - -Compilation is triggered asynchronously to avoid blocking other operations. Multiple tools can be compiled in parallel for efficiency, and results are cached in the database to avoid redundant processing. Only changed files are recompiled, minimizing unnecessary work. - -## Debugging Compilation - -To debug compilation issues, check the logs for compilation errors that include file names and line numbers. Inspect the working directory files to see the raw script content. Verify that parameter syntax follows the expected format, and test the tool manually with `USE TOOL` to confirm it functions correctly. - -## Best Practices - -Always include a DESCRIPTION statement to help the LLM understand the tool's purpose. Use clear parameter names that make the code self-documenting. Provide LIKE examples with realistic values to improve LLM parameter filling accuracy. Test tools after making changes to verify compilation succeeded, and check logs regularly to monitor for compilation errors. - -## Limitations - -Parameters must be declared at the start of the script before any executable code. The compiler only supports basic types including string, number, and boolean. All parameters are required since optional parameters are not currently supported. Nested object parameters and array parameters are also not available in the current implementation. - -## Summary - -The compilation process transforms BASIC scripts into callable tools that the LLM can discover and invoke. This automatic compilation ensures that changes to scripts are immediately available for use in conversations, making development iteration fast and seamless. \ No newline at end of file diff --git a/docs/src/chapter-09-api/external-apis.md b/docs/src/chapter-09-api/external-apis.md deleted file mode 100644 index b54afa67..00000000 --- a/docs/src/chapter-09-api/external-apis.md +++ /dev/null @@ -1,258 +0,0 @@ -# External APIs - -BotServer enables integration with external APIs through BASIC scripts, allowing bots to connect with third-party services and extend functionality beyond built-in capabilities. - -## Overview - -External API integration in BotServer is achieved through: -- The `GET` keyword for HTTP/HTTPS requests -- LLM function calling for API interactions -- BASIC script logic for response processing -- Bot memory for storing API credentials and state - -## HTTP Requests with GET - -The primary method for calling external APIs is the `GET` keyword: - -```basic -# Fetch data from an external API -let response = GET "https://api.example.com/data" - -# Process the response -let parsed = LLM "Extract the key information from this JSON: " + response -TALK parsed -``` - -### Supported Protocols - -- **HTTP**: Basic unencrypted requests -- **HTTPS**: Secure encrypted requests (recommended) - -## API Response Handling - -### JSON Responses - -Most modern APIs return JSON data: - -```basic -let weather = GET "https://api.weather.com/current?city=Seattle" -# Response: {"temp": 65, "conditions": "cloudy"} - -let report = LLM "Create a weather report from: " + weather -TALK report -``` - -### Text Responses - -Plain text responses are used directly: - -```basic -let quote = GET "https://api.quotes.com/daily" -TALK "Quote of the day: " + quote -``` - -## Authentication Patterns - -### API Key in URL - -```basic -let api_key = GET BOT MEMORY "weather_api_key" -let url = "https://api.weather.com/data?key=" + api_key -let data = GET url -``` - -### Bearer Token (via Headers) - -Currently, BotServer's GET keyword doesn't support custom headers directly. For APIs requiring Bearer tokens or custom headers, you need to: -1. Use proxy endpoints that add authentication -2. Or use APIs that support key-in-URL authentication - -## Common Integration Patterns - -### Weather Service - -```basic -PARAM city AS string LIKE "Seattle" DESCRIPTION "City for weather" -DESCRIPTION "Gets current weather for a city" - -let api_key = GET BOT MEMORY "openweather_key" -let url = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + api_key - -let response = GET url -let weather = LLM "Describe the weather based on: " + response -TALK weather -``` - -### News API - -```basic -DESCRIPTION "Fetches latest news headlines" - -let api_key = GET BOT MEMORY "newsapi_key" -let url = "https://newsapi.org/v2/top-headlines?country=us&apiKey=" + api_key - -let news = GET url -let summary = LLM "Summarize the top 3 news stories from: " + news -TALK summary -``` - -### Currency Exchange - -```basic -PARAM amount AS number LIKE 100 DESCRIPTION "Amount to convert" -PARAM from_currency AS string LIKE "USD" DESCRIPTION "Source currency" -PARAM to_currency AS string LIKE "EUR" DESCRIPTION "Target currency" - -DESCRIPTION "Converts currency using exchange rates" - -let url = "https://api.exchangerate-api.com/v4/latest/" + from_currency -let rates = GET url - -' Parse rates and calculate conversion -let rate = PARSE_JSON(rates, "rates." + to_currency) -let converted = amount * rate -TALK amount + " " + from_currency + " = " + converted + " " + to_currency -``` - -## Error Handling - -### Network Failures - -```basic -let response = GET "https://api.example.com/data" - -if (response == "") { - TALK "Unable to reach the service. Please try again later." -} else { - # Process successful response - TALK response -} -``` - -### API Errors - -```basic -let data = GET "https://api.service.com/endpoint" - -if (data CONTAINS "error") { - TALK "The service returned an error. Please check your request." -} else { - # Process valid data -} -``` - -## Rate Limiting Considerations - -When integrating with external APIs: - -1. **Respect Rate Limits**: Most APIs have usage limits -2. **Cache Responses**: Use BOT_MEMORY to store frequently accessed data -3. **Batch Requests**: Combine multiple data needs into single calls -4. **Handle 429 Errors**: Too Many Requests responses - -### Caching Pattern - -```basic -# Check cache first -let cached = GET BOT MEMORY "weather_cache" -let cache_time = GET BOT MEMORY "weather_cache_time" - -let current_time = NOW() -let age = current_time - cache_time - -if (cached != "" && age < 3600) { - # Use cached data (less than 1 hour old) - TALK cached -} else { - # Fetch fresh data - let fresh = GET "https://api.weather.com/current" - SET BOT MEMORY "weather_cache", fresh - SET BOT MEMORY "weather_cache_time", current_time - TALK fresh -} -``` - -## Security Best Practices - -### Credential Storage - -```basic -# Store API keys in bot memory, not in scripts -let api_key = GET BOT MEMORY "api_key" - -# Never hardcode credentials -# BAD: let key = "sk-1234567890abcdef" -# GOOD: let key = GET BOT MEMORY "api_key" -``` - -### Input Validation - -```basic -PARAM user_input AS string LIKE "Seattle" DESCRIPTION "User provided input" - -# Sanitize before using in URLs -let safe_input = REPLACE(user_input, " ", "%20") -let url = "https://api.example.com/search?q=" + safe_input -``` - -## Limitations - -Current limitations for external API integration: - -1. **No POST/PUT/DELETE**: Only GET requests supported -2. **No Custom Headers**: Cannot set Authorization headers directly -3. **No Request Body**: Cannot send JSON payloads -4. **Timeout Fixed**: 30-second timeout cannot be configured -5. **No Streaming**: Responses fully buffered before processing - -## Workarounds - -### For POST Requests - -Create a proxy service that: -1. Accepts GET requests -2. Converts to POST internally -3. Returns the response - -### For Complex APIs - -Use the LLM to: -1. Interpret API responses -2. Extract relevant data -3. Format for user consumption - -## Example: Complete API Integration - -```basic -PARAM location AS string LIKE "New York" DESCRIPTION "Location to check" -DESCRIPTION "Provides weather and news for a location" - -# Weather API -let weather_key = GET BOT MEMORY "weather_api_key" -let weather_url = "https://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + weather_key -let weather = GET weather_url - -# News API -let news_key = GET BOT MEMORY "news_api_key" -let news_url = "https://newsapi.org/v2/everything?q=" + location + "&apiKey=" + news_key -let news = GET news_url - -# Present the information -TALK "Here's your local update for " + location + ":" -TALK "Weather: " + weather -TALK "Latest news: " + news -``` - -## Best Practices - -1. **Store Keys Securely**: Use BOT_MEMORY for API credentials -2. **Handle Failures Gracefully**: Always check for empty responses -3. **Cache When Possible**: Reduce API calls and improve response time -4. **Document API Usage**: Comment which APIs your tools depend on -5. **Monitor Usage**: Track API calls to avoid exceeding limits -6. **Use HTTPS**: Always prefer secure connections -7. **Validate Inputs**: Sanitize user inputs before including in URLs - -## Summary - -While BotServer's external API capabilities are currently limited to GET requests, creative use of response processing and bot memory for state management enables integration with many third-party services. For more complex API interactions, consider using proxy services or custom integrations. \ No newline at end of file diff --git a/docs/src/chapter-09-api/get-integration.md b/docs/src/chapter-09-api/get-integration.md deleted file mode 100644 index c7a91017..00000000 --- a/docs/src/chapter-09-api/get-integration.md +++ /dev/null @@ -1,188 +0,0 @@ -# GET Keyword Integration - -The `GET` keyword in BotServer provides file retrieval capabilities from both local filesystem and drive (S3-compatible) storage, enabling tools to access documents, data files, and other resources. - -## Overview - -The `GET` keyword is a fundamental BASIC command that retrieves file contents as strings. It supports local file system access with safety checks, drive (S3-compatible) bucket retrieval, URL fetching via HTTP and HTTPS, and integration with knowledge base documents. - -## Basic Usage - -```basic -# Get a file from the bot's bucket -let content = GET "documents/policy.pdf" - -# Get a file with full path -let data = GET "announcements.gbkb/news/news.pdf" - -# Get from URL -let webpage = GET "https://example.com/data.json" -``` - -## Implementation Details - -### File Path Resolution - -The GET keyword determines the source based on the path format. URL detection occurs for paths starting with `http://` or `https://`, which triggers HTTP fetching. All other paths are retrieved from drive storage in the bot's dedicated bucket. Safety validation checks all paths for directory traversal attempts before processing. - -### Drive (S3-compatible) Integration - -When retrieving from drive storage, the system connects to drive using configured credentials and retrieves files from the bot's dedicated bucket. File contents are returned as strings, with binary files converted to text automatically. - -```basic -# Retrieves from: {bot-name}.gbai bucket -let doc = GET "knowledge/document.txt" - -# Full path within bucket -let report = GET "reports/2024/quarterly.pdf" -``` - -### URL Fetching - -For external resources, the GET keyword supports both HTTP and HTTPS protocols with automatic redirect following. A 30-second timeout protects against hanging requests, and comprehensive error handling manages failed requests gracefully. - -```basic -let api_data = GET "https://api.example.com/data" -let webpage = GET "http://example.com/page.html" -``` - -## Safety Features - -### Path Validation - -The `is_safe_path` function prevents directory traversal attacks by blocking paths containing `..` sequences and rejecting absolute paths. Character sets are validated to ensure only safe characters appear in paths, and sandbox isolation ensures scripts cannot escape their designated storage areas. - -### Access Control - -Files are limited to the bot's own bucket, preventing access to other bots' data. System directories receive protection from all access attempts, and credentials are never exposed through the GET interface regardless of the path requested. - -## Error Handling - -GET operations handle various error conditions gracefully. When a file is not found, the operation returns an empty string rather than throwing an error. Access denied conditions return an error message, network timeouts return a timeout error, and invalid paths return a security error. - -```basic -let content = GET "missing-file.txt" -# Returns empty string if file not found - -if (content == "") { - TALK "File not found or empty" -} -``` - -## Use Cases - -### Loading Knowledge Base Documents - -```basic -# In update-summary.bas - background processing script -let text = GET "announcements.gbkb/news/news.pdf" -let summary = LLM "Summarize this: " + text # LLM for background processing only -SET BOT MEMORY "news_summary", summary # Stored for all users -``` - -### Reading Configuration Files - -```basic -let config = GET "settings.json" -# Parse and use configuration -``` - -### Fetching External Data - -```basic -let weather_data = GET "https://api.weather.com/current" -# Process weather information -``` - -### Loading Templates - -```basic -let template = GET "templates/email-template.html" -let filled = REPLACE(template, "{{name}}", customer_name) -``` - -## Performance Considerations - -### Caching - -GET results are not cached by default, so frequent reads should use BOT_MEMORY for caching to improve performance. Large files impact memory usage significantly since the entire file is loaded into memory at once. - -### Timeouts - -URL fetches enforce a 30-second timeout to prevent indefinite hanging. Drive operations depend on network conditions and may vary in response time. Local files are accessed immediately when accessible. - -### File Size Limits - -No hard limit is enforced on file sizes, but large files consume substantial memory. Binary files converted to text may result in particularly large string representations. - -## Integration with Tools - -### Tool Parameters from Files - -```basic -PARAM config_file AS string LIKE "config.json" DESCRIPTION "Configuration file path" - -let config = GET config_file -# Use configuration in tool logic -``` - -### Dynamic Resource Loading - -```basic -DESCRIPTION "Process documents from a folder" - -let file_list = GET "documents/index.txt" -let files = SPLIT(file_list, "\n") - -FOR EACH file IN files { - let content = GET "documents/" + file - # Process each document -} -``` - -## Best Practices - -Always check for empty results to verify GET returned content successfully. Use relative paths rather than hardcoding absolute paths to maintain portability. Handle binary files carefully since text conversion may be lossy for non-text content. Cache frequently used files in BOT_MEMORY to avoid repeated retrieval operations. Validate external URLs and ensure HTTPS is used for sensitive data transfers. Log access failures to track missing or inaccessible files for debugging purposes. - -## Limitations - -The GET keyword is a read-only operation and cannot write files. Binary files are converted to text which may corrupt data that isn't text-based. No streaming support exists, meaning the entire file loads into memory at once. Path traversal is blocked for security, and system directories cannot be accessed under any circumstances. - -## Examples - -### Document Summarization Tool - -```basic -PARAM doc_path AS string LIKE "reports/annual.pdf" DESCRIPTION "Document to summarize" -DESCRIPTION "Summarizes a document" - -let content = GET doc_path - -if (content == "") { - TALK "Document not found: " + doc_path -} else { - # Set document as context for system AI - SET CONTEXT "document", content - TALK "I've loaded the document. What would you like to know about it?" -} -``` - -### Data Processing Tool - -```basic -PARAM data_file AS string LIKE "data/sales.csv" DESCRIPTION "Data file to process" -DESCRIPTION "Analyzes sales data" - -let csv_data = GET data_file -# Set data as context for system AI -SET CONTEXT "sales_data", csv_data -TALK "I've loaded the sales data. What analysis would you like me to perform?" -``` - -## Security Considerations - -Never GET files with user-controlled paths directly without validation. Always validate and sanitize path inputs before passing them to GET. Use allowlists for acceptable file paths when possible. Log all file access attempts for security auditing, and monitor for unusual access patterns that might indicate attempted exploitation. - -## Summary - -The GET keyword provides essential file retrieval capabilities for BASIC tools, enabling access to documents, configuration, and external resources while maintaining security through path validation and sandboxing. \ No newline at end of file diff --git a/docs/src/chapter-09-api/llm-rest-server.md b/docs/src/chapter-09-api/llm-rest-server.md deleted file mode 100644 index 7fa84931..00000000 --- a/docs/src/chapter-09-api/llm-rest-server.md +++ /dev/null @@ -1,243 +0,0 @@ -# Creating an LLM REST Server - -General Bots offers an incredibly simple way to transform a Large Language Model (LLM) into a fully functional REST API server. With just a few lines of our proprietary BASIC-like syntax, you can create sophisticated AI-powered applications. - -## Overview - -By defining PARAM declarations and a DESCRIPTION in your `.bas` file, General Bots automatically: - -1. Creates REST API endpoints callable by the LLM as tools -2. Generates OpenAI-compatible function calling schemas -3. Generates MCP (Model Context Protocol) tool definitions -4. Handles conversation state and context management - -## Basic Structure - -Every LLM-callable tool follows this structure: - -```bas -PARAM parameter_name AS type LIKE "example" DESCRIPTION "What this parameter is for" - -DESCRIPTION "What this tool does. Called when user wants to [action]." - -' Your business logic here -``` - -## Example: Store Chatbot - -Here's how easy it is to create a chatbot for a store: - -```bas -PARAM operator AS number LIKE 12312312 -DESCRIPTION "Operator code." - -DESCRIPTION It is a WebService of GB. - -products = FIND "products.csv" - -BEGIN SYSTEM PROMPT - You must act as a chatbot that will assist a store attendant by - following these rules: Whenever the attendant places an order, it must - include the table and the customer's name. Example: A 400ml Pineapple - Caipirinha for Rafael at table 10. Orders are based on the products and - sides from this product menu: ${JSON.stringify(products)}. - - For each order placed, return a JSON containing the product name, the - table, and a list of sides with their respective ids. -END SYSTEM PROMPT -``` - -That's it! With just this simple BASIC code, you've created a fully functional LLM-powered chatbot that can handle complex order processing. - -## REST API Endpoints - -The system automatically generates REST API endpoints for your dialogs. - -### Starting a Conversation - -``` -GET http://localhost:1111/llm-server/dialogs/start?operator=123&userSystemId=999 -``` - -This returns a **Process ID (PID)**, a number like `24795078551392`. This PID should be passed within the call chain for maintaining conversation context. - -### Talking to the Bot - -Once you have the PID, you can interact with the LLM: - -``` -GET http://localhost:1111/llm-server/dk/talk?pid=4893749837&text=add%20soda -``` - -This call acts like talking to the LLM, but it can be used for anything that General Bots can do in a robotic conversation between systems mediated by LLM. The return will be JSON (or any format specified in your BEGIN SYSTEM PROMPT). - -## Example: Enrollment Process API - -Creating a REST API server for any business process is equally straightforward: - -```bas -PARAM name AS string LIKE "João Silva" -DESCRIPTION "Required full name of the individual." - -PARAM birthday AS date LIKE "23/09/2001" -DESCRIPTION "Required birth date of the individual in DD/MM/YYYY format." - -PARAM email AS string LIKE "joao.silva@example.com" -DESCRIPTION "Required email address for contact purposes." - -PARAM personalid AS integer LIKE "12345678900" -DESCRIPTION "Required Personal ID number of the individual (only numbers)." - -PARAM address AS string LIKE "Rua das Flores, 123, São Paulo, SP" -DESCRIPTION "Required full address of the individual." - -DESCRIPTION "This is the enrollment process, called when the user wants to enroll. Once all information is collected, confirm the details and inform them that their enrollment request has been successfully submitted. Provide a polite and professional tone throughout the interaction." - -SAVE "enrollments.csv", id, name, birthday, email, cpf, rg, address -``` - -This creates a full-fledged enrollment system with: -- Data validation -- User interaction -- Data storage -- Automatic REST API endpoint - -The system automatically generates a REST API endpoint that is called by LLM as a tool: - -``` -GET http://api.pragmatismo.cloud/llm-server/dialogs/enrollment?birthday=...&name=... -``` - -## Generated Tool Schemas - -### MCP Format - -For each tool, General Bots generates MCP-compatible schemas: - -```json -{ - "name": "enrollment", - "description": "This is the enrollment process...", - "input_schema": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Required full name of the individual.", - "example": "João Silva" - }, - "birthday": { - "type": "string", - "description": "Required birth date...", - "example": "23/09/2001" - } - }, - "required": ["name", "birthday", "email", "personalid", "address"] - } -} -``` - -### OpenAI Format - -Also generates OpenAI function calling format: - -```json -{ - "type": "function", - "function": { - "name": "enrollment", - "description": "This is the enrollment process...", - "parameters": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Required full name of the individual." - } - }, - "required": ["name", "birthday", "email", "personalid", "address"] - } - } -} -``` - -## Parameter Types - -| Type | Description | Example | -|------|-------------|---------| -| `string` | Text values | `"John Smith"` | -| `number` | Numeric values | `42`, `3.14` | -| `integer` | Whole numbers | `100` | -| `date` | Date values | `"2024-01-15"` | -| `boolean` | True/false | `true` | - -## Advanced: External API Integration - -You can combine LLM tools with external API calls: - -```bas -PARAM location AS string LIKE "Seattle" -DESCRIPTION "City for weather lookup" - -DESCRIPTION "Gets current weather for a city" - -let api_key = GET BOT MEMORY "openweather_key" -let url = "https://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + api_key - -let response = GET url -let weather = LLM "Describe the weather based on: " + response -TALK weather -``` - -## Best Practices - -1. **Clear Descriptions**: Write detailed DESCRIPTION text - this is what the LLM uses to decide when to call your tool. - -2. **Good Examples**: The LIKE clause provides examples that help both the LLM and API consumers understand expected values. - -3. **Validation**: Add validation logic to handle edge cases: - -```bas -PARAM email AS string LIKE "user@example.com" -DESCRIPTION "Email address" - -IF NOT INSTR(email, "@") > 0 THEN - TALK "Please provide a valid email address." - RETURN -END IF -``` - -4. **Error Handling**: Always handle potential errors gracefully: - -```bas -result = GET "https://api.example.com/data" -IF result.error THEN - TALK "Unable to fetch data. Please try again." - RETURN -END IF -``` - -5. **Secure Credentials**: Use BOT MEMORY for API keys: - -```bas -api_key = GET BOT MEMORY "my_api_key" -``` - -## Deployment - -Once your `.bas` file is saved in the `.gbdialog` folder, General Bots automatically: - -1. Compiles the tool definition -2. Generates the REST endpoints -3. Makes it available to the LLM as a callable tool -4. Updates when you modify the file - -No additional configuration or deployment steps are required! - -## See Also - -- [PARAM Declaration](./param-declaration.md) - Detailed PARAM syntax -- [Tool Definition](./tool-definition.md) - Complete tool definition reference -- [MCP Format](./mcp-format.md) - MCP schema details -- [OpenAI Format](./openai-format.md) - OpenAI function calling format -- [External APIs](./external-apis.md) - Integrating external services \ No newline at end of file diff --git a/docs/src/chapter-09-api/mcp-format.md b/docs/src/chapter-09-api/mcp-format.md deleted file mode 100644 index 22029f16..00000000 --- a/docs/src/chapter-09-api/mcp-format.md +++ /dev/null @@ -1,220 +0,0 @@ -# MCP Format - -Model Context Protocol (MCP) is a standardized format for defining tools that language models can discover and invoke. BotServer generates MCP-compatible tool definitions from BASIC scripts. - -## Overview - -MCP provides a structured way to describe: -- Tool name and purpose -- Input parameters and types -- Parameter descriptions and examples -- Output format expectations - -## MCP Tool Structure - -A compiled MCP tool definition contains: - -```json -{ - "name": "tool_name", - "description": "Tool description from DESCRIPTION statement", - "input_schema": { - "type": "object", - "properties": { - "param1": { - "type": "string", - "description": "Parameter description" - }, - "param2": { - "type": "number", - "description": "Another parameter" - } - }, - "required": ["param1", "param2"] - } -} -``` - -## From BASIC to MCP - -### Source BASIC Script - -```basic -PARAM customer_name AS string LIKE "John Doe" DESCRIPTION "Customer's full name" -PARAM order_amount AS number LIKE 99.99 DESCRIPTION "Total order amount" -PARAM shipping_address AS string LIKE "123 Main St" DESCRIPTION "Delivery address" - -DESCRIPTION "Process a new customer order" - -# Script logic here -TALK "Processing order for " + customer_name -# ... -``` - -### Generated MCP Definition - -```json -{ - "name": "process_order", - "description": "Process a new customer order", - "input_schema": { - "type": "object", - "properties": { - "customer_name": { - "type": "string", - "description": "Customer's full name", - "example": "John Doe" - }, - "order_amount": { - "type": "number", - "description": "Total order amount", - "example": 99.99 - }, - "shipping_address": { - "type": "string", - "description": "Delivery address", - "example": "123 Main St" - } - }, - "required": ["customer_name", "order_amount", "shipping_address"] - } -} -``` - -## Parameter Types - -MCP supports these parameter types in BotServer: - -| BASIC Type | MCP Type | JSON Schema Type | -|------------|----------|------------------| -| string | string | "type": "string" | -| number | number | "type": "number" | -| boolean | boolean | "type": "boolean" | - -## Input Schema - -The `input_schema` follows JSON Schema specification: - -### Required Fields -- `type`: Always "object" for tool parameters -- `properties`: Object containing parameter definitions -- `required`: Array of required parameter names - -### Parameter Properties -- `type`: Data type of the parameter -- `description`: Human-readable description -- `example`: Example value from LIKE clause - -## Tool Discovery - -MCP tools are discoverable through: - -1. **Tool Listing**: LLM can query available tools -2. **Parameter Inspection**: LLM examines input schema -3. **Description Matching**: LLM matches user intent to tool description - -## Integration with LLM - -When the LLM invokes an MCP tool: - -1. **Parameter Collection**: LLM extracts values from context -2. **Schema Validation**: Parameters validated against input_schema -3. **Tool Execution**: BASIC script runs with provided parameters -4. **Result Return**: Output returned to LLM for processing - -## Example Use Cases - -### Form Processing Tool - -```json -{ - "name": "submit_application", - "description": "Submit a job application form", - "input_schema": { - "type": "object", - "properties": { - "applicant_name": { - "type": "string", - "description": "Full name of applicant" - }, - "position": { - "type": "string", - "description": "Position applying for" - }, - "experience_years": { - "type": "number", - "description": "Years of relevant experience" - } - }, - "required": ["applicant_name", "position", "experience_years"] - } -} -``` - -### Data Query Tool - -```json -{ - "name": "search_inventory", - "description": "Search product inventory", - "input_schema": { - "type": "object", - "properties": { - "product_name": { - "type": "string", - "description": "Product to search for" - }, - "min_quantity": { - "type": "number", - "description": "Minimum quantity available" - } - }, - "required": ["product_name"] - } -} -``` - -## Storage and Retrieval - -MCP definitions are stored in the `basic_tools` table: -- Tool metadata serialized as JSON -- Indexed for fast retrieval -- Associated with bot ID -- Cached for performance - -## Advantages of MCP Format - -1. **Standardized**: Compatible with multiple LLM providers -2. **Self-Documenting**: Contains all necessary metadata -3. **Type-Safe**: Schema validation prevents errors -4. **Discoverable**: LLMs can understand tool capabilities -5. **Extensible**: Can add custom properties as needed - -## Limitations in BotServer - -Current MCP implementation limitations: -- No nested object parameters -- No array parameters -- All parameters are required (no optional) -- No enum/choice constraints -- No pattern validation - -## Best Practices - -1. **Clear Descriptions**: Make tool purpose obvious -2. **Meaningful Names**: Use descriptive parameter names -3. **Provide Examples**: LIKE values help LLM understand expected input -4. **Type Accuracy**: Use correct types (string vs number) -5. **Complete Documentation**: Every parameter needs description - -## Validation - -MCP tools are validated during compilation: -- Parameter names must be valid identifiers -- Types must be supported -- Descriptions cannot be empty -- Tool name must be unique per bot - -## Summary - -The MCP format provides a structured way to expose BASIC scripts as callable tools for LLMs. By generating MCP-compatible definitions, BotServer enables seamless tool discovery and invocation within conversational flows. \ No newline at end of file diff --git a/docs/src/chapter-09-api/nvidia-gpu-setup.md b/docs/src/chapter-09-api/nvidia-gpu-setup.md deleted file mode 100644 index a8954f37..00000000 --- a/docs/src/chapter-09-api/nvidia-gpu-setup.md +++ /dev/null @@ -1,287 +0,0 @@ -# NVIDIA GPU Setup for LXC Containers - -This guide covers setting up NVIDIA GPU passthrough for BotServer running in LXC containers, enabling hardware acceleration for local LLM inference. - -## Prerequisites - -- NVIDIA GPU (RTX 3060 or better with 12GB+ VRAM recommended) -- NVIDIA drivers installed on the host system -- LXD/LXC installed -- CUDA-capable GPU - -## LXD Configuration (Interactive Setup) - -When initializing LXD, use these settings: - -```bash -sudo lxd init -``` - -Answer the prompts as follows: -- **Would you like to use LXD clustering?** → `no` -- **Do you want to configure a new storage pool?** → `no` (will create `/generalbots` later) -- **Would you like to connect to a MAAS server?** → `no` -- **Would you like to create a new local network bridge?** → `yes` -- **What should the new bridge be called?** → `lxdbr0` -- **What IPv4 address should be used?** → `auto` -- **What IPv6 address should be used?** → `auto` -- **Would you like the LXD server to be available over the network?** → `no` -- **Would you like stale cached images to be updated automatically?** → `no` -- **Would you like a YAML "lxd init" preseed to be printed?** → `no` - -### Storage Configuration -- **Storage backend name:** → `default` -- **Storage backend driver:** → `zfs` -- **Create a new ZFS pool?** → `yes` - -## NVIDIA GPU Configuration - -### On the Host System - -Create a GPU profile and attach it to your container: - -```bash -# Create GPU profile -lxc profile create gpu - -# Add GPU device to profile -lxc profile device add gpu gpu gpu gputype=physical - -# Apply GPU profile to your container -lxc profile add gb-system gpu -``` - -### Inside the Container - -Configure NVIDIA driver version pinning and install drivers: - -1. **Pin NVIDIA driver versions** to ensure stability: - -```bash -cat > /etc/apt/preferences.d/nvidia-drivers << 'EOF' -Package: *nvidia* -Pin: version 560.35.05-1 -Pin-Priority: 1001 - -Package: cuda-drivers* -Pin: version 560.35.05-1 -Pin-Priority: 1001 - -Package: libcuda* -Pin: version 560.35.05-1 -Pin-Priority: 1001 - -Package: libxnvctrl* -Pin: version 560.35.05-1 -Pin-Priority: 1001 - -Package: libnv* -Pin: version 560.35.05-1 -Pin-Priority: 1001 -EOF -``` - -2. **Install NVIDIA drivers and CUDA toolkit:** - -```bash -# Update package lists -apt update - -# Install NVIDIA driver and nvidia-smi -apt install -y nvidia-driver nvidia-smi - -# Add CUDA repository -wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb -dpkg -i cuda-keyring_1.1-1_all.deb - -# Install CUDA toolkit -apt-get update -apt-get -y install cuda-toolkit-12-8 -apt-get install -y cuda-drivers -``` - -## Verify GPU Access - -After installation, verify GPU is accessible: - -```bash -# Check GPU is visible -nvidia-smi - -# Should show your GPU with driver version 560.35.05 -``` - -## Configure BotServer for GPU - -Update your bot's `config.csv` to use GPU acceleration: - -```csv -name,value -llm-server-gpu-layers,35 -``` - -The number of layers depends on your GPU memory: -- **RTX 3060 (12GB):** 20-35 layers -- **RTX 3070 (8GB):** 15-25 layers -- **RTX 4070 (12GB):** 30-40 layers -- **RTX 4090 (24GB):** 50-99 layers - -## Troubleshooting - -### GPU Not Detected - -If `nvidia-smi` doesn't show the GPU: - -1. Check host GPU drivers: - ```bash - # On host - nvidia-smi - lxc config device list gb-system - ``` - -2. Verify GPU passthrough: - ```bash - # Inside container - ls -la /dev/nvidia* - ``` - -3. Check kernel modules: - ```bash - lsmod | grep nvidia - ``` - -### Driver Version Mismatch - -If you encounter driver version conflicts: - -1. Ensure host and container use the same driver version -2. Remove the version pinning file and install matching drivers: - ```bash - rm /etc/apt/preferences.d/nvidia-drivers - apt update - apt install nvidia-driver-560 - ``` - -### CUDA Library Issues - -If CUDA libraries aren't found: - -```bash -# Add CUDA to library path -echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/cuda.conf -ldconfig - -# Add to PATH -echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc -source ~/.bashrc -``` - -## Custom llama.cpp Compilation - -If you need custom CPU/GPU optimizations or specific hardware support, compile llama.cpp from source: - -### Prerequisites - -```bash -sudo apt update -sudo apt install build-essential cmake git -``` - -### Compilation Steps - -```bash -# Clone llama.cpp repository -git clone https://github.com/ggerganov/llama.cpp -cd llama.cpp - -# Create build directory -mkdir build -cd build - -# Configure with CUDA support -cmake .. -DLLAMA_CUDA=ON -DLLAMA_CURL=OFF - -# Compile using all available cores -make -j$(nproc) -``` - -### Compilation Options - -For different hardware configurations: - -```bash -# CPU-only build (no GPU) -cmake .. -DLLAMA_CURL=OFF - -# CUDA with specific compute capability -cmake .. -DLLAMA_CUDA=ON -DLLAMA_CUDA_FORCE_COMPUTE=75 - -# ROCm for AMD GPUs -cmake .. -DLLAMA_HIPBLAS=ON - -# Metal for Apple Silicon -cmake .. -DLLAMA_METAL=ON - -# AVX2 optimizations for modern CPUs -cmake .. -DLLAMA_AVX2=ON - -# F16C for half-precision support -cmake .. -DLLAMA_F16C=ON -``` - -### After Compilation - -```bash -# Copy compiled binary to BotServer -cp bin/llama-server /path/to/botserver-stack/bin/llm/ - -# Update config.csv to use custom build -llm-server-path,/path/to/botserver-stack/bin/llm/ -``` - -### Benefits of Custom Compilation - -- **Hardware-specific optimizations** for your exact CPU/GPU -- **Custom CUDA compute capabilities** for newer GPUs -- **AVX/AVX2/AVX512** instructions for faster CPU inference -- **Reduced binary size** by excluding unused features -- **Support for experimental features** not in releases - -## Performance Optimization - -### Memory Settings - -For optimal LLM performance with GPU: - -```csv -name,value -llm-server-gpu-layers,35 -llm-server-mlock,true -llm-server-no-mmap,false -llm-server-ctx-size,4096 -``` - -### Multiple GPUs - -For systems with multiple GPUs, specify which GPU to use: - -```bash -# List available GPUs -lxc profile device add gpu gpu0 gpu gputype=physical id=0 -lxc profile device add gpu gpu1 gpu gputype=physical id=1 -``` - -## Benefits of GPU Acceleration - -With GPU acceleration enabled: -- **5-10x faster** inference compared to CPU -- **Higher context sizes** possible (8K-32K tokens) -- **Real-time responses** even with large models -- **Lower CPU usage** for other tasks -- **Support for larger models** (13B, 30B parameters) - -## Next Steps - -- [Installation Guide](./installation.md) - Complete BotServer setup -- [Quick Start](./quick-start.md) - Create your first bot -- [Configuration Reference](../chapter-02/gbot.md) - All GPU-related parameters \ No newline at end of file diff --git a/docs/src/chapter-09-api/openai-format.md b/docs/src/chapter-09-api/openai-format.md deleted file mode 100644 index 640ee401..00000000 --- a/docs/src/chapter-09-api/openai-format.md +++ /dev/null @@ -1,252 +0,0 @@ -# Tool Format - -BotServer generates OpenAI-compatible function definitions from BASIC scripts, enabling integration with OpenAI's function calling API. - -## Overview - -OpenAI's function calling format allows GPT models to: -- Discover available functions -- Understand parameter requirements -- Generate structured function calls -- Process function results - -## Function Structure - -An OpenAI-compatible function definition contains: - -```json -{ - "name": "function_name", - "description": "Function description", - "parameters": { - "type": "object", - "properties": { - "param1": { - "type": "string", - "description": "Parameter description" - }, - "param2": { - "type": "number", - "description": "Another parameter" - } - }, - "required": ["param1", "param2"] - } -} -``` - -## Conversion from BASIC - -### Source BASIC Script - -```basic -PARAM product_id AS string LIKE "SKU-12345" DESCRIPTION "Product identifier" -PARAM quantity AS number LIKE 10 DESCRIPTION "Quantity to order" -PARAM urgent AS boolean LIKE true DESCRIPTION "Rush delivery needed" - -DESCRIPTION "Create a purchase order for inventory" - -# Script implementation -let order_id = CREATE_ORDER(product_id, quantity, urgent) -TALK "Order created: " + order_id -``` - -### Generated Function - -```json -{ - "name": "create_purchase_order", - "description": "Create a purchase order for inventory", - "parameters": { - "type": "object", - "properties": { - "product_id": { - "type": "string", - "description": "Product identifier" - }, - "quantity": { - "type": "number", - "description": "Quantity to order" - }, - "urgent": { - "type": "boolean", - "description": "Rush delivery needed" - } - }, - "required": ["product_id", "quantity", "urgent"] - } -} -``` - -## Integration with OpenAI API - -When using OpenAI's API, the functions are passed in the request: - -```json -{ - "model": "gpt-4", - "messages": [...], - "functions": [ - { - "name": "create_purchase_order", - "description": "Create a purchase order for inventory", - "parameters": {...} - } - ], - "function_call": "auto" -} -``` - -## Parameter Type Mapping - -| BASIC Type | OpenAI Type | Description | -|------------|-------------|-------------| -| string | "string" | Text values | -| number | "number" | Numeric values (integer or float) | -| boolean | "boolean" | True/false values | - -## Function Calling Flow - -1. **User Query**: User asks to perform an action -2. **Function Discovery**: GPT identifies relevant function -3. **Parameter Extraction**: GPT extracts parameters from context -4. **Function Call**: GPT generates structured function call -5. **Execution**: BotServer executes the BASIC script -6. **Result Processing**: Output returned to GPT for response - -## Example Function Calls - -### Customer Service Function - -```json -{ - "name": "check_order_status", - "description": "Check the status of a customer order", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "Order reference number" - }, - "customer_email": { - "type": "string", - "description": "Customer email for verification" - } - }, - "required": ["order_id", "customer_email"] - } -} -``` - -### Data Analysis Function - -```json -{ - "name": "generate_sales_report", - "description": "Generate sales report for specified period", - "parameters": { - "type": "object", - "properties": { - "start_date": { - "type": "string", - "description": "Report start date (YYYY-MM-DD)" - }, - "end_date": { - "type": "string", - "description": "Report end date (YYYY-MM-DD)" - }, - "region": { - "type": "string", - "description": "Sales region to analyze" - } - }, - "required": ["start_date", "end_date"] - } -} -``` - -## Function Response Handling - -When a function is executed: - -1. **Script Execution**: BASIC script runs with provided parameters -2. **Output Collection**: TALK statements and return values collected -3. **Response Format**: Results formatted for OpenAI API -4. **Context Update**: Function result added to conversation - -## Differences from MCP Format - -| Aspect | OpenAI Format | MCP Format | -|--------|---------------|------------| -| Schema Location | `parameters` | `input_schema` | -| Example Values | Not included | Included in schema | -| Metadata | Minimal | Extended metadata | -| Compatibility | OpenAI models only | Multiple providers | - -## Error Handling - -Function errors are handled gracefully: -- Missing parameters return error message -- Type mismatches caught before execution -- Script errors logged and returned -- Timeout protection for long-running scripts - -## Best Practices - -1. **Descriptive Names**: Use clear function names -2. **Comprehensive Descriptions**: Explain what the function does -3. **Parameter Clarity**: Each parameter needs clear description -4. **Error Messages**: Provide helpful error feedback -5. **Idempotency**: Design functions to be safely retryable - -## Limitations - -Current OpenAI format limitations in BotServer: -- No nested objects in parameters -- No array parameters -- No enum constraints -- All parameters marked as required -- No custom validation rules - -## Storage - -OpenAI function definitions are stored alongside MCP definitions: -- Stored in `basic_tools` table -- Generated during compilation -- Cached for performance -- Updated when script changes - -## Usage in Conversations - -When a user message triggers function calling: - -``` -User: "Order 50 units of SKU-12345 urgently" - -System: [Identifies create_purchase_order function] - [Extracts: product_id="SKU-12345", quantity=50, urgent=true] - [Executes function] - -Bot: "Order created: ORD-2024-001. Rush delivery confirmed for 50 units of SKU-12345." -``` - -## Performance Considerations - -- Functions cached after compilation -- Parallel function execution supported -- Rate limiting applied per session -- Timeout protection (30 seconds default) - -## Debugging - -To debug OpenAI function calls: -1. Enable debug logging -2. Check function registration -3. Verify parameter extraction -4. Review execution logs -5. Test with manual invocation - -## Summary - -The OpenAI function format enables seamless integration between BASIC scripts and OpenAI's GPT models. By automatically generating compatible function definitions, BotServer allows natural language interactions to trigger complex business logic implementations. \ No newline at end of file diff --git a/docs/src/chapter-09-api/param-declaration.md b/docs/src/chapter-09-api/param-declaration.md deleted file mode 100644 index d4002f4a..00000000 --- a/docs/src/chapter-09-api/param-declaration.md +++ /dev/null @@ -1,91 +0,0 @@ -# PARAM Declaration - -The `PARAM` keyword defines input parameters for tools, enabling type checking, validation, and documentation. - -## Syntax -``` -PARAM parameter_name AS type LIKE "example" DESCRIPTION "description text" -``` - -## Components - -- `parameter_name`: The name used to reference the parameter in the script -- `AS type`: The data type (string, integer, number, boolean, date, etc.) -- `LIKE "example"`: An example value showing expected format -- `DESCRIPTION "text"`: Explanation of what the parameter represents - -## Supported Types - -- **string**: Text values (default if no type specified) -- **integer**: Whole numbers -- **number**: Decimal numbers -- **boolean**: True/false values -- **date**: Date values -- **datetime**: Date and time values -- **array**: Lists of values -- **object**: Structured data - -## Examples - -### Basic Parameter -```basic -PARAM username AS string LIKE "john_doe" DESCRIPTION "User's unique identifier" -``` - -### Multiple Parameters -```basic -PARAM first_name AS string LIKE "John" DESCRIPTION "User's first name" -PARAM last_name AS string LIKE "Doe" DESCRIPTION "User's last name" -PARAM age AS integer LIKE "25" DESCRIPTION "User's age in years" -PARAM email AS string LIKE "john@example.com" DESCRIPTION "User's email address" -``` - -### Complex Types -```basic -PARAM preferences AS object LIKE "{"theme": "dark", "notifications": true}" DESCRIPTION "User preference settings" -PARAM tags AS array LIKE "["urgent", "follow-up"]" DESCRIPTION "Item categorization tags" -``` - -## Type Validation - -Parameters are validated when tools are called: -- **string**: Any text value accepted -- **integer**: Must be a whole number -- **number**: Must be a valid number -- **boolean**: Converted from "true"/"false" or 1/0 -- **date**: Parsed according to locale format - -## Usage in Tools - -Parameters become available as variables in the tool script: - -```basic -PARAM product_id AS integer LIKE "12345" DESCRIPTION "Product identifier" - -REM product_id variable is now available -TALK "Fetching details for product " + product_id -``` - -## Documentation Generation - -Parameter declarations are used to automatically generate: -- Tool documentation -- API schemas (OpenAI tools format) -- MCP (Model Context Protocol) definitions -- User interface forms - -## Required vs Optional - -All parameters are required by default. For optional parameters, check for empty values: - -```basic -PARAM phone AS string LIKE "+1-555-0123" DESCRIPTION "Optional phone number" - -IF phone != "" THEN - TALK "We'll contact you at " + phone -ELSE - TALK "No phone number provided" -END IF -``` - -Parameter declarations make tools self-documenting and enable rich integration with AI systems that can understand and use the defined interfaces. diff --git a/docs/src/chapter-09-api/tool-definition.md b/docs/src/chapter-09-api/tool-definition.md deleted file mode 100644 index 4051d010..00000000 --- a/docs/src/chapter-09-api/tool-definition.md +++ /dev/null @@ -1,339 +0,0 @@ -# Tool Definition - -In BotServer, a **tool** is simply a `.bas` file. That's it! - -## How It Works - -1. **Create a `.bas` file** in your `.gbdialog/` folder -2. **The LLM automatically discovers it** and can call it when needed -3. **No manual registration required** - it just works! - -### Tool Discovery and Execution Flow - - - - LLM Tool Discovery and Execution Pipeline - - - - "Send an email to John about the meeting" - - - - - - - LLM Analyzes - "Need email tool" - - - - - - - Tool Discovery - - - - Scan .gbdialog/ - • send-email.bas ✓ • create-task.bas • get-weather.bas - - - - - - - Parameter Collection - to → "John" - subject → "Meeting" - body → (generated) - - - - - - - Execute Tool - send-email.bas - - - - - - - Return Result - "Email sent!" - - - - - - - - - -## Simple Example - -Create `get-weather.bas`: - -```bas -' This tool gets weather information -' The LLM will call this when users ask about weather - -TALK "Let me check the weather for you..." -weather = GET "/api/weather/San Francisco" -TALK "The weather is: " + weather -``` - -That's a tool! The LLM now knows it can call this when users ask about weather. - -## Tool with Parameters - -Create `send-email.bas`: - -```bas -' Send an email to someone -PARAM to AS STRING -PARAM subject AS STRING -PARAM body AS STRING - -GET "/email/send" WITH to, subject, body -TALK "Email sent to " + to -``` - -The `PARAM` declarations tell the LLM what parameters this tool accepts. - -## Making Tools Available - -### Method 1: Automatic Discovery (Default) - -All `.bas` files in your `.gbdialog/` folder are automatically available. - -``` -mybot.gbai/ - mybot.gbdialog/ - start.bas ← Entry point - get-weather.bas ← Tool (auto-discovered) - send-email.bas ← Tool (auto-discovered) - create-task.bas ← Tool (auto-discovered) -``` - -### Method 2: Manual Registration - -In your `start.bas`, explicitly add tools: - -```bas -' Register tools for this conversation -USE TOOL "get-weather" -USE TOOL "send-email" -USE TOOL "create-task" - -TALK "Hello! I can help with weather, email, and tasks." -``` - -### Method 3: LLM-Driven Tool Selection - -Let the LLM decide which tools to use naturally: - -```bas -' In start.bas -' Load all available tools - LLM decides when to use them -USE TOOL "weather" -USE TOOL "email" -USE TOOL "enrollment" - -TALK "I can help with various tasks. What do you need?" -' The LLM will automatically call the right tool based on user intent -``` - -## Tool Format Conversion - -BotServer automatically converts your `.bas` tools to: - -- **MCP (Model Context Protocol)** format -- **Groq/OpenAI-compatible function calling** format -- Other LLM provider formats - -You never write these formats manually - just write `.bas` files! - -### Conversion Pipeline - - - - Tool Format Conversion Pipeline - - - - send-email.bas - - - - - - - BASIC Parser - • Extract PARAM - • Parse DESCRIPTION - • Analyze code - - - - - - - - - - MCP Format - - - OpenAI Function - - - Claude Tool - - - Local Model - - - - - - - - - - LLM Provider - Receives Native Format - - - - - - - - - -## Complete Example - -Here's a real tool from the codebase - `enrollment.bas`: - -```bas -PARAM name AS string LIKE "Abreu Silva" DESCRIPTION "Required full name of the individual." -PARAM birthday AS date LIKE "23/09/2001" DESCRIPTION "Required birth date of the individual in DD/MM/YYYY format." -PARAM email AS string LIKE "abreu.silva@example.com" DESCRIPTION "Required email address for contact purposes." -PARAM personalid AS integer LIKE "12345678900" DESCRIPTION "Required Personal ID number of the individual (only numbers)." -PARAM address AS string LIKE "Rua das Flores, 123 - SP" DESCRIPTION "Required full address of the individual." - -DESCRIPTION "This is the enrollment process, called when the user wants to enroll. Once all information is collected, confirm the details and inform them that their enrollment request has been successfully submitted." - -' The actual tool logic is simple -SAVE "enrollments.csv", id, name, birthday, email, personalid, address -TALK "Successfully enrolled " + name + "!" - -' That's it! The LLM handles: -' - Natural conversation to collect parameters -' - Validation and error handling -' - Confirming details with the user -' - All the complex interaction flow -``` - -## That's It! - -To create a tool: -1. ✅ Create a `.bas` file -2. ✅ Add `PARAM` declarations if you need parameters -3. ✅ Write your logic using `TALK`, `HEAR`, `CALL`, etc. -4. ✅ Done! - -The LLM will automatically: -- Discover your tool -- Understand what it does (from comments and code) -- Know when to call it -- Pass the right parameters - -No JSON schemas, no manual registration, no complex configuration. Just write BASIC! - -## Best Practices - -### 1. Add Comments - -The LLM reads your comments to understand the tool: - -```bas -' This tool books a meeting room -' It checks availability and sends calendar invites -PARAM room_name AS STRING -PARAM date AS STRING -PARAM attendees AS ARRAY -``` - -### 2. Validate Parameters - -Always validate input: - -```bas -IF room_name IS NULL THEN - TALK "Please specify which room you want to book." - RETURN -ENDIF -``` - -### 3. Provide Feedback - -Let users know what's happening: - -```bas -TALK "Checking room availability..." -available = GET "/calendar/check" WITH room_name, date - -IF available THEN - TALK "Great! Booking the room now..." - GET "/calendar/book" WITH room_name, date, attendees - TALK "Meeting room booked successfully!" -ELSE - TALK "Sorry, that room is not available on " + date -ENDIF -``` - -## Tool Discovery - -The LLM discovers tools by: -1. **Reading `.bas` files** in your `.gbdialog/` folder -2. **Extracting comments** to understand purpose -3. **Parsing PARAM declarations** to understand parameters -4. **Building a function signature** automatically - -Example tool discovery from `send-email.bas`: - -``` -Function: send-email -Description: Send an email to someone -Parameters: - - to: STRING (required) - - subject: STRING (required) - - body: STRING (required) -``` - -This is generated automatically from your `.bas` file! - -## Removing Tools -### Dynamic Tool Management - -```bas -' Remove a specific tool -REMOVE TOOL "send-email" - -' Clear all tools -CLEAR TOOLS - -' List active tools -tools = LIST TOOLS -TALK "Available tools: " + tools -``` - -## Next Steps - -- [PARAM Declaration](./param-declaration.md) - Parameter types and validation -- [GET Keyword Integration](./get-integration.md) - Using GET to call tools -- [External APIs](./external-apis.md) - Calling external services \ No newline at end of file diff --git a/docs/src/chapter-10-api/README.md b/docs/src/chapter-10-api/README.md deleted file mode 100644 index ea6dace7..00000000 --- a/docs/src/chapter-10-api/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# Chapter 10: REST API Reference - -HTTP API endpoints for integrating with BotServer. - -## Base URL - -``` -http://localhost:8000/api/v1 -``` - -## Authentication - -```bash -Authorization: Bearer -``` - -## Core Endpoints - -| Endpoint | Method | Description | -|----------|--------|-------------| -| `/chat` | POST | Send message, get response | -| `/sessions` | GET | List active sessions | -| `/sessions/:id` | GET | Get session details | -| `/files` | POST | Upload file | -| `/files/:id` | GET | Download file | - -## Quick Example - -```bash -curl -X POST http://localhost:8000/api/v1/chat \ - -H "Authorization: Bearer $TOKEN" \ - -H "Content-Type: application/json" \ - -d '{"message": "Hello", "session_id": "abc123"}' -``` - -## Response Format - -```json -{ - "success": true, - "data": { ... }, - "error": null -} -``` - -## Chapter Contents - -- [Files API](./files-api.md) - Upload/download -- [Document Processing](./document-processing.md) - Text extraction -- [Users API](./users-api.md) - User management -- [Groups API](./groups-api.md) - Group management -- [Conversations API](./conversations-api.md) - Chat sessions -- [Calendar API](./calendar-api.md) - Scheduling -- [Tasks API](./tasks-api.md) - Task management -- [Storage API](./storage-api.md) - Object storage -- [Analytics API](./analytics-api.md) - Metrics -- [Admin API](./admin-api.md) - Administration -- [AI API](./ai-api.md) - LLM endpoints -- [Example Integrations](./examples.md) - Code samples - -## See Also - -- [API and Tooling](../chapter-09-api/README.md) - Tool definitions -- [Authentication](../chapter-12-auth/README.md) - Security \ No newline at end of file diff --git a/docs/src/chapter-10-api/admin-api.md b/docs/src/chapter-10-api/admin-api.md deleted file mode 100644 index 111d8096..00000000 --- a/docs/src/chapter-10-api/admin-api.md +++ /dev/null @@ -1,51 +0,0 @@ -# Admin API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Admin API will provide endpoints for system administration, user management, and configuration management. - -## Planned Features - -- System configuration management -- User and role administration -- Bot lifecycle management -- System health monitoring -- Audit logging and compliance -- Backup and restore operations - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/admin -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with administrator-level permissions required. - -## Endpoints (Planned) - -### System Configuration -`GET /api/v1/admin/config` -`PUT /api/v1/admin/config` - -### User Management -`GET /api/v1/admin/users` -`POST /api/v1/admin/users` -`DELETE /api/v1/admin/users/{user_id}` - -### Bot Management -`GET /api/v1/admin/bots` -`POST /api/v1/admin/bots/{bot_id}/restart` -`DELETE /api/v1/admin/bots/{bot_id}` - -### System Health -`GET /api/v1/admin/health` -`GET /api/v1/admin/metrics` - -### Audit Logs -`GET /api/v1/admin/audit` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/ai-api.md b/docs/src/chapter-10-api/ai-api.md deleted file mode 100644 index 6e2ec28a..00000000 --- a/docs/src/chapter-10-api/ai-api.md +++ /dev/null @@ -1,47 +0,0 @@ -# AI API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The AI API will provide endpoints for managing AI models, inference, training, and advanced AI operations. - -## Planned Features - -- Model management and deployment -- Inference endpoints for various AI tasks -- Fine-tuning and training capabilities -- Model versioning and rollback -- Performance optimization settings -- Custom AI pipeline configuration - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/ai -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### Model Management -`GET /api/v1/ai/models` -`POST /api/v1/ai/models/deploy` -`DELETE /api/v1/ai/models/{model_id}` - -### Inference -`POST /api/v1/ai/inference` -`POST /api/v1/ai/chat/completions` - -### Training -`POST /api/v1/ai/training/start` -`GET /api/v1/ai/training/{job_id}/status` - -### Model Configuration -`GET /api/v1/ai/models/{model_id}/config` -`PUT /api/v1/ai/models/{model_id}/config` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/analytics-api.md b/docs/src/chapter-10-api/analytics-api.md deleted file mode 100644 index fdf312d6..00000000 --- a/docs/src/chapter-10-api/analytics-api.md +++ /dev/null @@ -1,45 +0,0 @@ -# Analytics API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Analytics API will provide endpoints for tracking, analyzing, and reporting on bot usage and performance metrics. - -## Planned Features - -- Usage analytics and statistics -- Conversation metrics and insights -- User engagement tracking -- Performance monitoring -- Custom report generation -- Real-time analytics dashboard - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/analytics -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### Get Usage Statistics -`GET /api/v1/analytics/usage` - -### Get Conversation Metrics -`GET /api/v1/analytics/conversations` - -### Get User Engagement -`GET /api/v1/analytics/engagement` - -### Generate Custom Report -`POST /api/v1/analytics/reports` - -### Get Real-time Metrics -`GET /api/v1/analytics/realtime` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/assets/api-architecture.svg.backup b/docs/src/chapter-10-api/assets/api-architecture.svg.backup deleted file mode 100644 index 52b42a1d..00000000 --- a/docs/src/chapter-10-api/assets/api-architecture.svg.backup +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BotServer API Architecture - - - - - - Client Applications - - - - - - - - - HTTP/HTTPS - - - Port 8080 - - - - - - - - - API Gateway - - - /api/* - - - - - - - - - - - Auth Endpoints - - - /auth/login - - - /auth/logout - - - /auth/token - - - - - - Business Endpoints - - - /files/* • /users/* - - - /groups/* • /tasks/* - - - /sessions/* - - - - - - Admin Endpoints - - - /admin/* - - - /monitoring - - - /analytics - - - - - - - - - - - Service Layer - - - • Session Manager - - - • Auth Service • Bot Service - - - - - - - - - - - PostgreSQL - - - Database - - - Sessions • Users • Config - - - - - - Valkey - - - Cache - - - Semantic • Session • Temp - - - - - - Qdrant - - - Vectors - - - Embeddings • Search - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-10-api/assets/api-request-flow.svg.backup b/docs/src/chapter-10-api/assets/api-request-flow.svg.backup deleted file mode 100644 index 583c5f77..00000000 --- a/docs/src/chapter-10-api/assets/api-request-flow.svg.backup +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - API Request Flow - - - - - - HTTP Request - - - Client → Server - - - - - - - - - Rate Limit - - - Check request limits - - - - - Pass - - - 429 Too Many - - - - - Auth - - - Validate token/session - - - - - Valid - - - 401 Unauthorized - - - - - Route - - - Match endpoint pattern - - - - - - - 404 Not Found - - - - - Validate - - - Check request body - - - - - Valid - - - 400 Bad Request - - - - - Process - - - Execute business logic - - - - - - - - - Format - - - JSON response - - - - - - - - - HTTP Response - - - Server → Client - - - - - - Error Response - - - - - - Request Pipeline - - - - - - - Success path - - - - - Error path - - - - - - \ No newline at end of file diff --git a/docs/src/chapter-10-api/backup-api.md b/docs/src/chapter-10-api/backup-api.md deleted file mode 100644 index 080b812a..00000000 --- a/docs/src/chapter-10-api/backup-api.md +++ /dev/null @@ -1,44 +0,0 @@ -# Backup API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Backup API will provide endpoints for creating, managing, and restoring backups of bot data and configurations. - -## Planned Features - -- Automated backup scheduling -- Point-in-time recovery -- Export/import bot configurations -- Data archival and retention policies -- Incremental and full backup options - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/backup -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### Create Backup -`POST /api/v1/backup/create` - -### List Backups -`GET /api/v1/backup/list` - -### Restore Backup -`POST /api/v1/backup/restore/{backup_id}` - -### Delete Backup -`DELETE /api/v1/backup/{backup_id}` - -### Schedule Backup -`POST /api/v1/backup/schedule` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/calendar-api.md b/docs/src/chapter-10-api/calendar-api.md deleted file mode 100644 index eb7e8497..00000000 --- a/docs/src/chapter-10-api/calendar-api.md +++ /dev/null @@ -1,190 +0,0 @@ -# Calendar API - -The Calendar API provides endpoints for managing events, schedules, and time-based activities within BotServer. - -## Status - -**⚠️ NOT IMPLEMENTED** - -This API is planned for future development but is not currently available in BotServer. - -## Planned Features - -The Calendar API will enable event creation and management, meeting scheduling, availability checking, recurring events, calendar synchronization, and reminders with notifications. - -## Planned Endpoints - -### Event Management - -Event management endpoints handle the lifecycle of calendar events. Create events with `POST /api/v1/calendar/events`, list events with `GET /api/v1/calendar/events`, retrieve specific event details with `GET /api/v1/calendar/events/{event_id}`, update events with `PATCH /api/v1/calendar/events/{event_id}`, and delete events with `DELETE /api/v1/calendar/events/{event_id}`. - -### Scheduling - -Scheduling endpoints help coordinate meetings. Find available time slots with `POST /api/v1/calendar/schedule`, schedule meetings with `POST /api/v1/calendar/meeting`, and check availability with `GET /api/v1/calendar/availability`. - -### Recurring Events - -Recurring event endpoints manage events that repeat on a schedule. Create recurring events with `POST /api/v1/calendar/events/recurring` and update recurrence patterns with `PATCH /api/v1/calendar/events/{event_id}/recurrence`. - -### Reminders - -Reminder endpoints manage notifications for upcoming events. Add reminders with `POST /api/v1/calendar/events/{event_id}/reminders` and list upcoming reminders with `GET /api/v1/calendar/reminders`. - -## Planned Integration with BASIC - -When implemented, calendar features will be accessible via BASIC keywords: - -```basic -' Create event (not yet available) -event_id = CREATE EVENT "Team Meeting", "2024-02-01 14:00" -SET EVENT DURATION event_id, 60 ' 60 minutes - -' Check availability (not yet available) -available = CHECK AVAILABILITY "user123", "2024-02-01" -IF available THEN - TALK "User is available" -END IF - -' Schedule meeting (not yet available) -meeting_id = SCHEDULE MEETING participants, datetime, duration -SEND INVITES meeting_id -``` - -## Planned Data Models - -### Event - -```json -{ - "event_id": "evt_123", - "title": "Team Meeting", - "description": "Weekly sync", - "start_time": "2024-02-01T14:00:00Z", - "end_time": "2024-02-01T15:00:00Z", - "location": "Conference Room A", - "attendees": ["user123", "user456"], - "recurrence": { - "frequency": "weekly", - "interval": 1, - "days_of_week": ["monday"], - "end_date": "2024-12-31" - }, - "reminders": [ - {"minutes_before": 15, "method": "notification"}, - {"minutes_before": 60, "method": "email"} - ] -} -``` - -### Availability - -```json -{ - "user_id": "user123", - "date": "2024-02-01", - "time_slots": [ - {"start": "09:00", "end": "10:00", "available": true}, - {"start": "10:00", "end": "11:00", "available": false}, - {"start": "11:00", "end": "12:00", "available": true} - ] -} -``` - -## Planned Features Detail - -### Event Types - -The API will support several event types. Single events are one-time occurrences. Recurring events follow daily, weekly, or monthly patterns. All-day events span the full day without specific start and end times. Multi-day events extend across multiple consecutive days. - -### Notification Methods - -Notifications can be delivered through in-app notifications, email reminders, SMS alerts when configured, and bot messages through the chat interface. - -### Calendar Views - -The API will support multiple calendar views including day view for detailed hourly scheduling, week view for weekly planning, month view for long-term visibility, and agenda view for a list-based perspective. - -### Time Zone Support - -Time zone handling will include user-specific time zones, automatic daylight saving time adjustments, and cross-timezone meeting coordination to ensure events display correctly for all participants. - -### Integration Points - -The calendar system will integrate with external calendar systems like Google Calendar and Outlook, video conferencing platforms, the task management system, and the notification system for reminders. - -## Implementation Considerations - -When implemented, the Calendar API will use PostgreSQL for event storage, support iCal format for import and export, handle time zones properly across all operations, provide conflict detection for scheduling, include role-based access control for event management, support delegation for assistants, and enable calendar sharing between users. - -## Alternative Solutions - -Until the Calendar API is implemented, consider these alternatives. - -### External Calendar Services - -You can integrate with external providers such as Google Calendar API, Microsoft Graph API for Outlook, or CalDAV servers for standards-based calendar access. - -### Simple Scheduling in BASIC - -For basic appointment tracking, you can store appointments in bot memory: - -```basic -' Store appointments in bot memory -appointment = "Meeting with client at 2 PM" -SET BOT MEMORY "appointment_" + date, appointment - -' Retrieve appointments -today_appointment = GET BOT MEMORY "appointment_" + TODAY() -IF today_appointment <> "" THEN - TALK "Today's appointment: " + today_appointment -END IF -``` - -### Task-based Scheduling - -An alternative approach uses the Tasks API with due dates, creates tasks for time-sensitive items, and sets reminders via scheduled BASIC scripts. - -## Future Integration - -The Calendar API will integrate with the [Tasks API](./tasks-api.md) to link tasks to calendar events, the [Notifications API](./notifications-api.md) for event reminders, the [User API](./user-security.md) for user availability, and the Meeting API for video conferencing. - -## Workaround Example - -Until the Calendar API is available, you can implement basic scheduling: - -```basic -' Simple appointment booking system -FUNCTION BookAppointment(date, time, description) - key = "appointment_" + date + "_" + time - existing = GET BOT MEMORY key - - IF existing = "" THEN - SET BOT MEMORY key, description - TALK "Appointment booked for " + date + " at " + time - RETURN TRUE - ELSE - TALK "That time slot is already taken" - RETURN FALSE - END IF -END FUNCTION - -' Check availability -FUNCTION CheckAvailability(date) - slots = ["09:00", "10:00", "11:00", "14:00", "15:00", "16:00"] - available = [] - - FOR EACH slot IN slots - key = "appointment_" + date + "_" + slot - appointment = GET BOT MEMORY key - IF appointment = "" THEN - available = APPEND(available, slot) - END IF - NEXT - - RETURN available -END FUNCTION -``` - -## Status Updates - -Check the [GitHub repository](https://github.com/generalbots/botserver) for updates on Calendar API implementation status. \ No newline at end of file diff --git a/docs/src/chapter-10-api/calls-api.md b/docs/src/chapter-10-api/calls-api.md deleted file mode 100644 index 694ebae7..00000000 --- a/docs/src/chapter-10-api/calls-api.md +++ /dev/null @@ -1,209 +0,0 @@ -# Calls API - -The Calls API provides endpoints for managing voice and video calls, conference rooms, and real-time communication within BotServer. - -## Status - -**⚠️ NOT IMPLEMENTED** - -This API is planned for future development but is not currently available in BotServer. - -## Planned Features - -The Calls API will enable voice call initiation and management, video conferencing, screen sharing, call recording, call transcription, conference room management, and WebRTC integration. - -## Planned Endpoints - -### Call Management - -The call management endpoints will handle the lifecycle of individual calls. Use `POST /api/v1/calls/initiate` to start a call, `GET /api/v1/calls/{call_id}` to retrieve call details, `POST /api/v1/calls/{call_id}/end` to terminate a call, and `GET /api/v1/calls/history` to access call history. - -### Conference Rooms - -Conference room endpoints manage persistent meeting spaces. Create rooms with `POST /api/v1/calls/rooms`, retrieve room details with `GET /api/v1/calls/rooms/{room_id}`, and manage participation through `POST /api/v1/calls/rooms/{room_id}/join`, `POST /api/v1/calls/rooms/{room_id}/leave`, and `GET /api/v1/calls/rooms/{room_id}/participants`. - -### Recording - -Recording endpoints control call archival. Start recording with `POST /api/v1/calls/{call_id}/record/start`, stop with `POST /api/v1/calls/{call_id}/record/stop`, and retrieve recordings via `GET /api/v1/calls/{call_id}/recordings`. - -### Transcription - -Transcription endpoints provide speech-to-text capabilities. Enable transcription with `POST /api/v1/calls/{call_id}/transcribe` and retrieve the transcript using `GET /api/v1/calls/{call_id}/transcript`. - -## Planned Integration with BASIC - -When implemented, call features will be accessible via BASIC keywords: - -```basic -' Initiate call (not yet available) -call_id = START CALL "user123" -WAIT FOR CALL ANSWER call_id - -' Conference room (not yet available) -room_id = CREATE ROOM "Team Meeting" -INVITE TO ROOM room_id, ["user1", "user2", "user3"] - -' Call with bot (not yet available) -ON INCOMING CALL - ANSWER CALL - TALK "Hello, how can I help you?" - response = HEAR - ' Process voice response -END ON -``` - -## Planned Data Models - -### Call - -```json -{ - "call_id": "call_123", - "type": "video", - "status": "active", - "participants": [ - { - "user_id": "user123", - "role": "host", - "audio": true, - "video": true, - "joined_at": "2024-01-15T10:00:00Z" - }, - { - "user_id": "user456", - "role": "participant", - "audio": true, - "video": false, - "joined_at": "2024-01-15T10:01:00Z" - } - ], - "started_at": "2024-01-15T10:00:00Z", - "duration_seconds": 300, - "recording": false, - "transcription": true -} -``` - -### Conference Room - -```json -{ - "room_id": "room_456", - "name": "Daily Standup", - "type": "persistent", - "max_participants": 10, - "settings": { - "allow_recording": true, - "auto_transcribe": true, - "waiting_room": false, - "require_password": false - }, - "current_participants": 3, - "created_at": "2024-01-01T08:00:00Z" -} -``` - -## Planned Features Detail - -### Call Types - -The API will support several call types to accommodate different communication needs. One-to-one calls enable direct communication between two users. Group calls allow multi-party conversations with several participants. Conference calls provide scheduled meetings with dedicated rooms. Bot calls enable voice interaction directly with the bot for automated customer service scenarios. - -### Media Features - -Media capabilities will include audio-only calls, video with audio, and screen sharing for presentations and collaboration. File sharing during calls will allow participants to exchange documents in real-time. Virtual backgrounds will provide privacy and professionalism, while noise suppression will ensure clear audio quality. - -### Recording Options - -Recording functionality will offer flexibility in how calls are archived. Audio-only recording will minimize storage requirements when video isn't needed. Full video recording will capture the complete visual experience. Selective recording will allow capturing specific participants only. Cloud storage integration will enable automatic upload to configured storage providers. Automatic transcription will convert recorded speech to searchable text. - -### Quality Management - -Quality features will ensure reliable communication across varying network conditions. Adaptive bitrate will automatically adjust video quality based on available bandwidth. Network quality indicators will inform participants of connection status. Bandwidth optimization will minimize data usage while maintaining quality. Echo cancellation and automatic gain control will ensure clear audio. - -## Implementation Considerations - -When implemented, the Calls API will use WebRTC for peer-to-peer communication, providing low-latency audio and video. Integration with an SFU (Selective Forwarding Unit) will enable scalable group calls without requiring each participant to send their stream to every other participant. Support for TURN/STUN servers will handle NAT traversal, ensuring connections work across different network configurations. End-to-end encryption will provide security for sensitive conversations. Call analytics and quality metrics will help administrators monitor system health. Dial-in via PSTN integration will allow traditional phone participation. Virtual phone numbers will enable bots to make and receive external calls. - -## Alternative Solutions - -Until the Calls API is implemented, consider these alternatives for voice and video functionality. - -### External Services Integration - -You can integrate with established communication platforms through their APIs. Twilio Voice API provides comprehensive telephony features. Zoom SDK enables embedding video meetings. Microsoft Teams integration connects to enterprise communication. Jitsi Meet offers an open-source video conferencing option that can be self-hosted. - -### WebRTC Libraries - -For custom implementations, you can use existing WebRTC libraries in your frontend: - -```javascript -// Use existing WebRTC libraries in frontend -const peer = new RTCPeerConnection(config); -// Handle signaling through WebSocket -``` - -### Voice Bot Integration - -For voice-enabled bots specifically, consider using external telephony providers, connecting via SIP trunk to existing phone systems, or integrating with cloud PBX systems that handle the voice infrastructure. - -## Future Technology Stack - -The planned implementation will use WebRTC for real-time communication, providing the foundation for peer-to-peer audio and video. MediaSoup or Janus will serve as the SFU server for scalable multi-party calls. Coturn will provide TURN/STUN server functionality for NAT traversal. FFmpeg will handle media processing tasks like transcoding and recording. Whisper will power speech-to-text transcription. PostgreSQL will store call metadata and history. S3-compatible storage will house call recordings. - -## Workaround Example - -Until the Calls API is available, you can implement basic voice interaction using external services: - -```basic -' Simple voice bot using external service -FUNCTION HandlePhoneCall(phone_number) - ' Use external telephony API - response = CALL EXTERNAL API "twilio", { - "action": "answer", - "from": phone_number - } - - ' Convert speech to text - text = SPEECH TO TEXT response.audio - - ' Set the transcribed text as context - SET CONTEXT "user_question", text - - ' System AI responds naturally - TALK "Let me help you with that question." - - ' Convert text to speech - audio = TEXT TO SPEECH bot_response - - ' Send response - CALL EXTERNAL API "twilio", { - "action": "play", - "audio": audio - } -END FUNCTION -``` - -## Integration Points - -When available, the Calls API will integrate with the [Calendar API](./calendar-api.md) for scheduling calls, the [Notifications API](./notifications-api.md) for call alerts, the [User API](./user-security.md) for user presence information, the [Storage API](./storage-api.md) for recording storage, and the [ML API](./ml-api.md) for transcription and analysis. - -## Use Cases - -### Customer Support - -Voice-enabled bot support can handle common customer inquiries automatically. Call center integration allows seamless handoff to human agents. Screen sharing enables technical support representatives to guide customers visually. Call recording provides quality assurance data for training and compliance. - -### Team Collaboration - -Video meetings bring distributed teams together for face-to-face communication. Stand-up calls facilitate daily team synchronization. Screen sharing supports presentations and collaborative work sessions. Persistent team rooms provide always-available meeting spaces. - -### Education - -Virtual classrooms enable remote learning at scale. One-on-one tutoring provides personalized instruction. Recorded lectures allow students to review material at their own pace. Interactive sessions engage students through real-time participation. - -## Status Updates - -Check the [GitHub repository](https://github.com/generalbots/botserver) for updates on Calls API implementation status. - -For immediate voice and video needs, consider integrating with established providers like Twilio, Zoom, or Teams rather than waiting for the native implementation. \ No newline at end of file diff --git a/docs/src/chapter-10-api/compliance-api.md b/docs/src/chapter-10-api/compliance-api.md deleted file mode 100644 index 0675a8cc..00000000 --- a/docs/src/chapter-10-api/compliance-api.md +++ /dev/null @@ -1,60 +0,0 @@ -# Compliance API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Compliance API will provide endpoints for regulatory compliance management, audit trails, and policy enforcement. - -## Planned Features - -- Regulatory compliance tracking -- Audit trail management -- Policy enforcement and validation -- Compliance reporting -- Data governance controls -- Privacy management (GDPR, CCPA) -- Retention policy management -- Compliance dashboards - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/compliance -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### Compliance Status -`GET /api/v1/compliance/status` - -### Audit Trails -`GET /api/v1/compliance/audit-trails` -`POST /api/v1/compliance/audit-trails/export` - -### Policy Management -`GET /api/v1/compliance/policies` -`POST /api/v1/compliance/policies` -`PUT /api/v1/compliance/policies/{policy_id}` - -### Compliance Reports -`POST /api/v1/compliance/reports/generate` -`GET /api/v1/compliance/reports/{report_id}` - -### Data Governance -`GET /api/v1/compliance/data-governance` -`POST /api/v1/compliance/data-governance/scan` - -### Privacy Management -`POST /api/v1/compliance/privacy/request` -`GET /api/v1/compliance/privacy/status` - -### Retention Policies -`GET /api/v1/compliance/retention` -`PUT /api/v1/compliance/retention` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/conversations-api.md b/docs/src/chapter-10-api/conversations-api.md deleted file mode 100644 index ca76c0de..00000000 --- a/docs/src/chapter-10-api/conversations-api.md +++ /dev/null @@ -1,219 +0,0 @@ -# Conversations API - -The Conversations API provides endpoints for managing chat conversations, message history, and real-time communication. - -## Overview - -Conversations in General Bots are handled primarily through WebSocket connections for real-time messaging, with REST endpoints for history retrieval and session management. - -## Endpoints - -### Start Conversation - -**POST** `/api/conversations/start` - -Initiates a new conversation with a bot. - -**Request:** -```json -{ - "bot_id": "bot-123", - "initial_message": "Hello" -} -``` - -**Response:** -```json -{ - "conversation_id": "conv-456", - "session_id": "session-789", - "status": "active" -} -``` - -### Send Message - -**POST** `/api/conversations/:id/messages` - -Sends a message in an existing conversation. - -**Request:** -```json -{ - "content": "User message", - "attachments": [] -} -``` - -**Response:** -```json -{ - "message_id": "msg-123", - "timestamp": "2024-01-15T10:30:00Z", - "status": "delivered" -} -``` - -### Get Conversation History - -**GET** `/api/conversations/:id/history` - -Retrieves message history for a conversation. - -**Query Parameters:** -- `limit` - Number of messages (default: 50, max: 100) -- `before` - Messages before timestamp -- `after` - Messages after timestamp - -**Response:** -```json -{ - "messages": [ - { - "id": "msg-001", - "sender": "user", - "content": "Hello", - "timestamp": "2024-01-15T10:00:00Z" - }, - { - "id": "msg-002", - "sender": "bot", - "content": "Hi! How can I help you?", - "timestamp": "2024-01-15T10:00:01Z" - } - ], - "has_more": false -} -``` - -### List Conversations - -**GET** `/api/conversations` - -Lists user's conversations. - -**Query Parameters:** -- `bot_id` - Filter by bot -- `status` - Filter by status (active/archived) -- `limit` - Number of results -- `offset` - Pagination offset - -**Response:** -```json -{ - "conversations": [ - { - "id": "conv-456", - "bot_id": "bot-123", - "bot_name": "Support Bot", - "last_message": "Thank you!", - "last_activity": "2024-01-15T10:30:00Z", - "status": "active" - } - ], - "total": 1 -} -``` - -## WebSocket Protocol - -Real-time messaging uses WebSocket connections at `/ws`. - -### Message Types - -| Type | Direction | Description | -|------|-----------|-------------| -| `message` | Both | Chat message | -| `typing` | Server→Client | Bot is typing | -| `suggestion` | Server→Client | Quick reply suggestions | -| `status` | Server→Client | Connection status | -| `error` | Server→Client | Error notification | - -### Send Message Format - -```json -{ - "type": "message", - "content": "Hello", - "session_id": "session-123" -} -``` - -### Receive Message Format - -```json -{ - "type": "message", - "sender": "bot", - "content": "Hi! How can I help you?", - "timestamp": "2024-01-15T10:00:01Z" -} -``` - -## Anonymous Conversations - -Anonymous users can chat without authentication: - -- Session created automatically on WebSocket connect -- Limited to default bot only -- No history persistence -- Session expires after inactivity - -## Authenticated Conversations - -Logged-in users get additional features: - -- Full conversation history -- Multiple bot access -- Cross-device sync -- Persistent sessions - -## Database Schema - -Conversations are stored in: - -```sql --- sessions table -CREATE TABLE sessions ( - id UUID PRIMARY KEY, - user_id UUID, - bot_id UUID, - status TEXT, - created_at TIMESTAMPTZ, - updated_at TIMESTAMPTZ -); - --- message_history table -CREATE TABLE message_history ( - id UUID PRIMARY KEY, - session_id UUID REFERENCES sessions(id), - sender TEXT, - content TEXT, - metadata JSONB, - created_at TIMESTAMPTZ -); -``` - -## Error Handling - -| Status Code | Error | Description | -|-------------|-------|-------------| -| 400 | `invalid_message` | Malformed message content | -| 401 | `unauthorized` | Authentication required | -| 403 | `forbidden` | No access to conversation | -| 404 | `not_found` | Conversation doesn't exist | -| 429 | `rate_limited` | Too many messages | - -## Rate Limits - -| Endpoint | Limit | -|----------|-------| -| Messages | 60/minute per user | -| History | 100/minute per user | -| List | 30/minute per user | - -## See Also - -- [Sessions and Channels](../chapter-01/sessions.md) - Session management -- [TALK Keyword](../chapter-06-gbdialog/keyword-talk.md) - Sending messages from BASIC -- [HEAR Keyword](../chapter-06-gbdialog/keyword-hear.md) - Receiving user input \ No newline at end of file diff --git a/docs/src/chapter-10-api/document-processing.md b/docs/src/chapter-10-api/document-processing.md deleted file mode 100644 index b7a3102f..00000000 --- a/docs/src/chapter-10-api/document-processing.md +++ /dev/null @@ -1,556 +0,0 @@ -# Document Processing API - -BotServer provides RESTful endpoints for processing, extracting, and analyzing various document formats including PDFs, Office documents, and images. - -## Overview - -The Document Processing API enables: -- Text extraction from documents -- OCR for scanned documents -- Metadata extraction -- Document conversion -- Content analysis and summarization - -## Base URL - -``` -http://localhost:8080/api/v1/documents -``` - -## Authentication - -All Document Processing API requests require authentication: - -```http -Authorization: Bearer -``` - -## Endpoints - -### Upload Document - -**POST** `/upload` - -Upload a document for processing. - -**Request:** -- Method: `POST` -- Content-Type: `multipart/form-data` - -**Form Data:** -- `file` - The document file -- `process_options` - JSON string of processing options - -**Example Request:** -```bash -curl -X POST \ - -H "Authorization: Bearer token123" \ - -F "file=@document.pdf" \ - -F 'process_options={"extract_text":true,"extract_metadata":true}' \ - http://localhost:8080/api/v1/documents/upload -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "filename": "document.pdf", - "size_bytes": 2048576, - "mime_type": "application/pdf", - "status": "processing", - "uploaded_at": "2024-01-15T10:00:00Z" -} -``` - -### Process Document - -**POST** `/process` - -Process an already uploaded document. - -**Request Body:** -```json -{ - "document_id": "doc_abc123", - "operations": [ - "extract_text", - "extract_metadata", - "generate_summary", - "extract_entities" - ], - "options": { - "language": "en", - "ocr_enabled": true, - "chunk_size": 1000 - } -} -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "process_id": "prc_xyz789", - "status": "processing", - "estimated_completion": "2024-01-15T10:02:00Z" -} -``` - -### Get Processing Status - -**GET** `/process/{process_id}/status` - -Check the status of document processing. - -**Response:** -```json -{ - "process_id": "prc_xyz789", - "document_id": "doc_abc123", - "status": "completed", - "progress": 100, - "completed_at": "2024-01-15T10:01:30Z", - "results_available": true -} -``` - -### Get Extracted Text - -**GET** `/documents/{document_id}/text` - -Retrieve extracted text from a processed document. - -**Query Parameters:** -- `page` - Specific page number (optional) -- `format` - Output format: `plain`, `markdown`, `html` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "text": "This is the extracted text from the document...", - "pages": 10, - "word_count": 5420, - "language": "en" -} -``` - -### Get Document Metadata - -**GET** `/documents/{document_id}/metadata` - -Retrieve metadata from a document. - -**Response:** -```json -{ - "document_id": "doc_abc123", - "metadata": { - "title": "Annual Report 2024", - "author": "John Doe", - "created_date": "2024-01-10T08:00:00Z", - "modified_date": "2024-01-14T16:30:00Z", - "pages": 10, - "producer": "Microsoft Word", - "keywords": ["annual", "report", "finance"], - "custom_properties": { - "department": "Finance", - "confidentiality": "Internal" - } - } -} -``` - -### Generate Summary - -**POST** `/documents/{document_id}/summarize` - -Generate an AI summary of the document. - -**Request Body:** -```json -{ - "type": "abstractive", - "length": "medium", - "focus_areas": ["key_points", "conclusions"], - "language": "en" -} -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "summary": "This document discusses the annual financial performance...", - "key_points": [ - "Revenue increased by 15%", - "New market expansion successful", - "Operating costs reduced" - ], - "summary_length": 250 -} -``` - -### Extract Entities - -**POST** `/documents/{document_id}/entities` - -Extract named entities from the document. - -**Request Body:** -```json -{ - "entity_types": ["person", "organization", "location", "date", "money"], - "confidence_threshold": 0.7 -} -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "entities": [ - { - "text": "John Smith", - "type": "person", - "confidence": 0.95, - "occurrences": 5 - }, - { - "text": "New York", - "type": "location", - "confidence": 0.88, - "occurrences": 3 - }, - { - "text": "$1.5 million", - "type": "money", - "confidence": 0.92, - "occurrences": 2 - } - ] -} -``` - -### Convert Document - -**POST** `/documents/{document_id}/convert` - -Convert document to another format. - -**Request Body:** -```json -{ - "target_format": "pdf", - "options": { - "compress": true, - "quality": "high", - "page_size": "A4" - } -} -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "converted_id": "doc_def456", - "original_format": "docx", - "target_format": "pdf", - "download_url": "/api/v1/documents/doc_def456/download" -} -``` - -### Search Within Document - -**POST** `/documents/{document_id}/search` - -Search for text within a document. - -**Request Body:** -```json -{ - "query": "revenue growth", - "case_sensitive": false, - "whole_words": false, - "regex": false -} -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "matches": [ - { - "page": 3, - "line": 15, - "context": "...the company achieved significant revenue growth in Q4...", - "position": 1247 - }, - { - "page": 7, - "line": 8, - "context": "...projecting continued revenue growth for next year...", - "position": 3892 - } - ], - "total_matches": 2 -} -``` - -### Split Document - -**POST** `/documents/{document_id}/split` - -Split a document into multiple parts. - -**Request Body:** -```json -{ - "method": "by_pages", - "pages_per_split": 5 -} -``` - -**Response:** -```json -{ - "document_id": "doc_abc123", - "parts": [ - { - "part_id": "part_001", - "pages": "1-5", - "download_url": "/api/v1/documents/part_001/download" - }, - { - "part_id": "part_002", - "pages": "6-10", - "download_url": "/api/v1/documents/part_002/download" - } - ], - "total_parts": 2 -} -``` - -### Merge Documents - -**POST** `/documents/merge` - -Merge multiple documents into one. - -**Request Body:** -```json -{ - "document_ids": ["doc_abc123", "doc_def456", "doc_ghi789"], - "output_format": "pdf", - "preserve_metadata": true -} -``` - -**Response:** -```json -{ - "merged_document_id": "doc_merged_xyz", - "source_count": 3, - "total_pages": 30, - "download_url": "/api/v1/documents/doc_merged_xyz/download" -} -``` - -## Supported Formats - -### Input Formats -- **Documents**: PDF, DOCX, DOC, ODT, RTF, TXT -- **Spreadsheets**: XLSX, XLS, ODS, CSV -- **Presentations**: PPTX, PPT, ODP -- **Images**: PNG, JPG, JPEG, GIF, BMP, TIFF -- **Web**: HTML, XML, MARKDOWN - -### Output Formats -- PDF -- Plain Text -- Markdown -- HTML -- JSON -- CSV (for tabular data) - -## Processing Options - -### OCR Options -```json -{ - "ocr_enabled": true, - "ocr_language": "eng", - "ocr_engine": "tesseract", - "preprocessing": { - "deskew": true, - "remove_noise": true, - "enhance_contrast": true - } -} -``` - -### Text Extraction Options -```json -{ - "preserve_formatting": false, - "extract_tables": true, - "extract_images": false, - "chunk_text": true, - "chunk_size": 1000, - "chunk_overlap": 100 -} -``` - -### Summary Options -```json -{ - "summary_type": "extractive", - "summary_length": "medium", - "bullet_points": true, - "include_keywords": true, - "max_sentences": 5 -} -``` - -## Batch Processing - -### Submit Batch - -**POST** `/batch/process` - -Process multiple documents in batch. - -**Request Body:** -```json -{ - "documents": [ - { - "document_id": "doc_001", - "operations": ["extract_text", "summarize"] - }, - { - "document_id": "doc_002", - "operations": ["extract_entities"] - } - ], - "notify_on_completion": true, - "webhook_url": "https://example.com/webhook" -} -``` - -### Get Batch Status - -**GET** `/batch/{batch_id}/status` - -Check batch processing status. - -**Response:** -```json -{ - "batch_id": "batch_abc123", - "total_documents": 10, - "processed": 7, - "failed": 1, - "pending": 2, - "completion_percentage": 70 -} -``` - -## Error Responses - -### 400 Bad Request -```json -{ - "error": "unsupported_format", - "message": "File format .xyz is not supported", - "supported_formats": ["pdf", "docx", "txt"] -} -``` - -### 413 Payload Too Large -```json -{ - "error": "file_too_large", - "message": "File size exceeds maximum limit", - "max_size_bytes": 52428800, - "provided_size_bytes": 104857600 -} -``` - -### 422 Unprocessable Entity -```json -{ - "error": "corrupted_file", - "message": "The document appears to be corrupted and cannot be processed" -} -``` - -## Webhooks - -Configure webhooks to receive processing notifications: - -```json -{ - "event": "document.processed", - "document_id": "doc_abc123", - "status": "completed", - "results": { - "text_extracted": true, - "summary_generated": true, - "entities_extracted": true - } -} -``` - -## Rate Limits - -| Operation | Limit | Window | -|-----------|-------|--------| -| Upload Document | 50/hour | Per user | -| Process Document | 100/hour | Per user | -| Generate Summary | 20/hour | Per user | -| Batch Processing | 5/hour | Per user | - -## Best Practices - -1. **Preprocess Documents**: Clean scanned documents before OCR -2. **Use Appropriate Formats**: Choose the right output format for your use case -3. **Batch Similar Documents**: Process similar documents together for efficiency -4. **Handle Large Files**: Use chunking for large documents -5. **Cache Results**: Store processed results to avoid reprocessing -6. **Monitor Processing**: Use webhooks for long-running operations - -## Integration Examples - -### Python Example - -```python -import requests - -# Upload and process document -with open('document.pdf', 'rb') as f: - response = requests.post( - 'http://localhost:8080/api/v1/documents/upload', - headers={'Authorization': 'Bearer token123'}, - files={'file': f}, - data={'process_options': '{"extract_text": true}'} - ) - -document_id = response.json()['document_id'] - -# Get extracted text -text_response = requests.get( - f'http://localhost:8080/api/v1/documents/{document_id}/text', - headers={'Authorization': 'Bearer token123'} -) - -print(text_response.json()['text']) -``` - -## Related APIs - -- [Storage API](./storage-api.md) - Document storage -- [ML API](./ml-api.md) - Advanced text analysis -- [Knowledge Base API](../chapter-03/kb-and-tools.md) - Document indexing \ No newline at end of file diff --git a/docs/src/chapter-10-api/email-api.md b/docs/src/chapter-10-api/email-api.md deleted file mode 100644 index 3364b86f..00000000 --- a/docs/src/chapter-10-api/email-api.md +++ /dev/null @@ -1,399 +0,0 @@ -# Email API - -The Email API provides endpoints for email operations including sending, receiving, and managing email accounts through the Stalwart mail server integration. - -## Overview - -Email functionality in General Bots is available through: - -1. **REST API** - Documented in this chapter -2. **BASIC Keywords** - `SEND MAIL` for scripts -3. **Email Module** - Background processing and IMAP/SMTP integration - -## Endpoints - -### Send Email - -**POST** `/api/email/send` - -Send an email message. - -**Request:** -```json -{ - "to": ["recipient@example.com"], - "cc": ["cc@example.com"], - "bcc": [], - "subject": "Meeting Tomorrow", - "body": "Hi, just a reminder about our meeting.", - "body_type": "text", - "attachments": [] -} -``` - -**Response:** -```json -{ - "message_id": "msg-abc123", - "status": "sent", - "timestamp": "2024-01-15T10:30:00Z" -} -``` - -**Body Types:** -- `text` - Plain text -- `html` - HTML formatted - -### List Emails - -**GET** `/api/email/inbox` - -Retrieve inbox messages. - -**Query Parameters:** -- `folder` - Folder name (default: INBOX) -- `limit` - Number of messages (default: 50) -- `offset` - Pagination offset -- `unread` - Filter unread only (boolean) -- `since` - Messages since date (ISO 8601) - -**Response:** -```json -{ - "messages": [ - { - "id": "email-001", - "from": "sender@example.com", - "subject": "Hello", - "preview": "Just wanted to say hi...", - "date": "2024-01-15T09:00:00Z", - "read": false, - "has_attachments": false - } - ], - "total": 142, - "unread_count": 5 -} -``` - -### Get Email - -**GET** `/api/email/:id` - -Get specific email details. - -**Response:** -```json -{ - "id": "email-001", - "from": { - "name": "John Doe", - "email": "john@example.com" - }, - "to": [ - { - "name": "You", - "email": "you@example.com" - } - ], - "cc": [], - "subject": "Meeting Notes", - "body": "Here are the notes from today's meeting...", - "body_html": "

Here are the notes from today's meeting...

", - "date": "2024-01-15T09:00:00Z", - "read": true, - "attachments": [ - { - "id": "att-001", - "filename": "notes.pdf", - "size": 102400, - "content_type": "application/pdf" - } - ] -} -``` - -### Delete Email - -**DELETE** `/api/email/:id` - -Delete an email message. - -**Response:** -```json -{ - "status": "deleted", - "message_id": "email-001" -} -``` - -### Get Attachment - -**GET** `/api/email/:id/attachments/:attachment_id` - -Download an email attachment. - -**Response:** Binary file with appropriate Content-Type header. - -### Mark as Read - -**PUT** `/api/email/:id/read` - -Mark email as read. - -**Request:** -```json -{ - "read": true -} -``` - -### Move Email - -**PUT** `/api/email/:id/move` - -Move email to a different folder. - -**Request:** -```json -{ - "folder": "Archive" -} -``` - -### List Folders - -**GET** `/api/email/folders` - -List available email folders. - -**Response:** -```json -{ - "folders": [ - { - "name": "INBOX", - "path": "INBOX", - "unread_count": 5, - "total_count": 142 - }, - { - "name": "Sent", - "path": "Sent", - "unread_count": 0, - "total_count": 89 - }, - { - "name": "Drafts", - "path": "Drafts", - "unread_count": 0, - "total_count": 3 - } - ] -} -``` - -### Create Draft - -**POST** `/api/email/drafts` - -Create an email draft. - -**Request:** -```json -{ - "to": ["recipient@example.com"], - "subject": "Draft subject", - "body": "Draft content..." -} -``` - -**Response:** -```json -{ - "draft_id": "draft-001", - "status": "saved" -} -``` - -### Send Draft - -**POST** `/api/email/drafts/:id/send` - -Send a previously saved draft. - -**Response:** -```json -{ - "message_id": "msg-abc123", - "status": "sent" -} -``` - -## Email Accounts - -### List Accounts - -**GET** `/api/email/accounts` - -List configured email accounts. - -**Response:** -```json -{ - "accounts": [ - { - "id": "account-001", - "email": "user@example.com", - "provider": "stalwart", - "status": "connected" - } - ] -} -``` - -### Add Account - -**POST** `/api/email/accounts` - -Add a new email account. - -**Request:** -```json -{ - "email": "user@example.com", - "imap_server": "imap.example.com", - "imap_port": 993, - "smtp_server": "smtp.example.com", - "smtp_port": 587, - "username": "user@example.com", - "password": "app-specific-password" -} -``` - -**Response:** -```json -{ - "account_id": "account-002", - "status": "connected", - "message": "Account added successfully" -} -``` - -## BASIC Integration - -Use email in your BASIC scripts: - -```basic -' Simple email -SEND MAIL "recipient@example.com", "Subject", "Body" - -' With variables -TALK "Who should I email?" -recipient = HEAR - -TALK "What's the subject?" -subject = HEAR - -TALK "What's the message?" -body = HEAR - -SEND MAIL recipient, subject, body -TALK "Email sent!" -``` - -## Configuration - -Configure email in `config.csv`: - -```csv -key,value -smtp-server,smtp.gmail.com -smtp-port,587 -imap-server,imap.gmail.com -imap-port,993 -email-username,your-email@gmail.com -email-password,your-app-password -email-from,Your Name -``` - -**Gmail Configuration:** -- Use App Passwords (not your main password) -- Enable IMAP in Gmail settings -- Allow less secure apps or use OAuth - -## Stalwart Mail Server - -When using the built-in Stalwart mail server: - -**Automatic Configuration:** -- Server runs on standard ports (25, 993, 587) -- Accounts created through Zitadel integration -- TLS certificates auto-managed - -**Manual Configuration:** -```csv -key,value -stalwart-enabled,true -stalwart-domain,mail.yourdomain.com -stalwart-admin-password,secure-password -``` - -## Error Handling - -| Status Code | Error | Description | -|-------------|-------|-------------| -| 400 | `invalid_recipient` | Invalid email address | -| 401 | `unauthorized` | Authentication required | -| 403 | `forbidden` | No access to mailbox | -| 404 | `not_found` | Email not found | -| 422 | `send_failed` | SMTP delivery failed | -| 503 | `service_unavailable` | Mail server offline | - -## Rate Limits - -| Endpoint | Limit | -|----------|-------| -| Send | 100/hour per user | -| Inbox | 300/hour per user | -| Attachments | 50/hour per user | - -## Security Notes - -1. **Never hardcode credentials** - Use config.csv -2. **Use App Passwords** - Not main account passwords -3. **Enable TLS** - Always use encrypted connections -4. **Audit sending** - Log all outbound emails - -## Database Schema - -```sql --- user_email_accounts -CREATE TABLE user_email_accounts ( - id UUID PRIMARY KEY, - user_id UUID REFERENCES users(id), - email TEXT NOT NULL, - imap_server TEXT, - smtp_server TEXT, - encrypted_password TEXT, - created_at TIMESTAMPTZ -); - --- email_drafts -CREATE TABLE email_drafts ( - id UUID PRIMARY KEY, - user_id UUID REFERENCES users(id), - recipients JSONB, - subject TEXT, - body TEXT, - attachments JSONB, - created_at TIMESTAMPTZ, - updated_at TIMESTAMPTZ -); -``` - -## See Also - -- [SEND MAIL Keyword](../chapter-06-gbdialog/keyword-send-mail.md) - BASIC email -- [CREATE DRAFT Keyword](../chapter-06-gbdialog/keyword-create-draft.md) - Draft creation -- [External Services](../appendix-external-services/README.md) - Service configuration \ No newline at end of file diff --git a/docs/src/chapter-10-api/examples.md b/docs/src/chapter-10-api/examples.md deleted file mode 100644 index 5dd0824a..00000000 --- a/docs/src/chapter-10-api/examples.md +++ /dev/null @@ -1,417 +0,0 @@ -# API Examples - -This section provides practical examples of using the BotServer REST API in various programming languages and scenarios. - -## Authentication Examples - -### Getting a Session Token - -**JavaScript/TypeScript:** -```javascript -// Note: Authentication is handled through Zitadel OAuth flow -// This is a simplified example -async function authenticate() { - // Redirect to Zitadel login - window.location.href = '/auth/login'; - - // After OAuth callback, session token is set - // Use it for subsequent requests -} -``` - -**cURL:** -```bash -# Session validation -curl -X GET http://localhost:8080/auth/validate \ - -H "Authorization: Bearer YOUR_SESSION_TOKEN" -``` - -## Group Management Examples - -### Creating a Group - -**JavaScript:** -```javascript -async function createGroup() { - const response = await fetch('/api/groups/create', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer YOUR_TOKEN' - }, - body: JSON.stringify({ - name: 'Engineering Team', - description: 'Software developers' - }) - }); - - const group = await response.json(); - console.log('Created group:', group); -} -``` - -**Python:** -```python -import requests - -def create_group(): - url = "http://localhost:8080/api/groups/create" - headers = { - "Authorization": "Bearer YOUR_TOKEN", - "Content-Type": "application/json" - } - data = { - "name": "Engineering Team", - "description": "Software developers" - } - - response = requests.post(url, json=data, headers=headers) - return response.json() -``` - -### Adding Group Members - -**JavaScript:** -```javascript -async function addMember(groupId, userId) { - const response = await fetch(`/api/groups/${groupId}/members/add`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer YOUR_TOKEN' - }, - body: JSON.stringify({ - user_id: userId, - role: 'member' - }) - }); - - return response.json(); -} -``` - -## Admin API Examples - -### Getting System Status - -**cURL:** -```bash -curl -X GET http://localhost:8080/api/admin/system/status \ - -H "Authorization: Bearer ADMIN_TOKEN" -``` - -**Go:** -```go -package main - -import ( - "net/http" - "io/ioutil" - "fmt" -) - -func getSystemStatus(token string) { - client := &http.Client{} - req, _ := http.NewRequest("GET", - "http://localhost:8080/api/admin/system/status", nil) - req.Header.Add("Authorization", "Bearer " + token) - - resp, err := client.Do(req) - if err != nil { - panic(err) - } - defer resp.Body.Close() - - body, _ := ioutil.ReadAll(resp.Body) - fmt.Println(string(body)) -} -``` - -### Creating a Backup - -**JavaScript:** -```javascript -async function createBackup() { - const response = await fetch('/api/admin/backup/create', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ADMIN_TOKEN' - }, - body: JSON.stringify({ - backup_type: 'full', - include_data: true, - include_config: true - }) - }); - - const backup = await response.json(); - console.log('Backup created:', backup.id); - console.log('Download URL:', backup.download_url); -} -``` - -## WebSocket Communication - -### Real-Time Chat - -**JavaScript:** -```javascript -class BotChat { - constructor(sessionId) { - this.sessionId = sessionId; - this.ws = null; - } - - connect() { - this.ws = new WebSocket('ws://localhost:8080/ws'); - - this.ws.onopen = () => { - console.log('Connected to bot'); - }; - - this.ws.onmessage = (event) => { - const message = JSON.parse(event.data); - this.handleMessage(message); - }; - - this.ws.onerror = (error) => { - console.error('WebSocket error:', error); - }; - } - - sendMessage(content) { - if (this.ws && this.ws.readyState === WebSocket.OPEN) { - this.ws.send(JSON.stringify({ - type: 'message', - content: content, - session_id: this.sessionId - })); - } - } - - handleMessage(message) { - console.log('Bot response:', message.content); - - if (message.suggestions) { - console.log('Suggestions:', message.suggestions); - } - } -} - -// Usage -const chat = new BotChat('session-123'); -chat.connect(); -chat.sendMessage('Hello bot!'); -``` - -## Error Handling - -### Handling API Errors - -**JavaScript:** -```javascript -async function apiCall(url, options = {}) { - try { - const response = await fetch(url, { - ...options, - headers: { - 'Authorization': 'Bearer YOUR_TOKEN', - 'Content-Type': 'application/json', - ...options.headers - } - }); - - if (!response.ok) { - const error = await response.json(); - throw new Error(error.message || `HTTP ${response.status}`); - } - - return await response.json(); - } catch (error) { - console.error('API Error:', error); - - // Handle specific error codes - if (error.code === 'RATE_LIMITED') { - // Wait and retry - await new Promise(resolve => setTimeout(resolve, 1000)); - return apiCall(url, options); - } - - throw error; - } -} -``` - -### Rate Limit Handling - -**Python:** -```python -import time -import requests - -class APIClient: - def __init__(self, base_url, token): - self.base_url = base_url - self.headers = { - 'Authorization': f'Bearer {token}', - 'Content-Type': 'application/json' - } - - def request(self, method, endpoint, **kwargs): - url = f"{self.base_url}{endpoint}" - - response = requests.request( - method, url, - headers=self.headers, - **kwargs - ) - - # Check rate limit headers - remaining = response.headers.get('X-RateLimit-Remaining') - if remaining and int(remaining) < 10: - reset_time = int(response.headers.get('X-RateLimit-Reset', 0)) - sleep_time = max(reset_time - time.time(), 0) - print(f"Rate limit approaching, sleeping {sleep_time}s") - time.sleep(sleep_time) - - response.raise_for_status() - return response.json() -``` - -## Pagination Examples - -### Iterating Through Paginated Results - -**JavaScript:** -```javascript -async function* getAllGroups(token) { - let offset = 0; - const limit = 20; - - while (true) { - const response = await fetch( - `/api/groups/list?limit=${limit}&offset=${offset}`, - { - headers: { 'Authorization': `Bearer ${token}` } - } - ); - - const data = await response.json(); - - for (const group of data.groups) { - yield group; - } - - if (data.groups.length < limit) { - break; // No more pages - } - - offset += limit; - } -} - -// Usage -for await (const group of getAllGroups(token)) { - console.log(group.name); -} -``` - -## Integration Patterns - -### Webhook Handler - -**Node.js/Express:** -```javascript -const express = require('express'); -const app = express(); - -app.post('/webhook/botserver', express.json(), (req, res) => { - const event = req.body; - - switch(event.type) { - case 'user.created': - handleUserCreated(event.data); - break; - case 'conversation.completed': - handleConversationCompleted(event.data); - break; - default: - console.log('Unknown event type:', event.type); - } - - res.status(200).send('OK'); -}); - -function handleUserCreated(userData) { - console.log('New user:', userData); - // Process new user -} - -function handleConversationCompleted(conversationData) { - console.log('Conversation completed:', conversationData); - // Process completed conversation -} -``` - -## Best Practices - -1. **Always handle errors gracefully** - Network failures happen -2. **Respect rate limits** - Implement exponential backoff -3. **Use environment variables** for API tokens -4. **Log API interactions** for debugging -5. **Cache responses** when appropriate -6. **Use connection pooling** for multiple requests -7. **Implement timeout handling** for long operations - -## Testing API Calls - -### Using Postman - -1. Import the API collection (when available) -2. Set environment variables for: - - `base_url`: http://localhost:8080 - - `token`: Your session token -3. Run requests individually or as collection - -### Unit Testing API Calls - -**JavaScript/Jest:** -```javascript -describe('Groups API', () => { - test('should create a group', async () => { - const mockFetch = jest.fn(() => - Promise.resolve({ - ok: true, - json: () => Promise.resolve({ - id: 'group-123', - name: 'Test Group' - }) - }) - ); - global.fetch = mockFetch; - - const result = await createGroup('Test Group'); - - expect(mockFetch).toHaveBeenCalledWith( - '/api/groups/create', - expect.objectContaining({ - method: 'POST' - }) - ); - expect(result.id).toBe('group-123'); - }); -}); -``` - -## Summary - -These examples demonstrate common patterns for interacting with the BotServer API. Remember to: -- Handle authentication properly through Zitadel -- Check response status codes -- Parse error responses -- Implement proper error handling -- Use appropriate HTTP methods -- Follow REST conventions - -For more specific endpoint documentation, refer to the individual API sections in this chapter. \ No newline at end of file diff --git a/docs/src/chapter-10-api/files-api.md b/docs/src/chapter-10-api/files-api.md deleted file mode 100644 index 0d97bad7..00000000 --- a/docs/src/chapter-10-api/files-api.md +++ /dev/null @@ -1,639 +0,0 @@ -# Files API Reference - -Complete file and document management operations including upload, download, copy, move, search, sharing, and synchronization. - -## Overview - -The Files API provides comprehensive file management capabilities built on top of S3-compatible storage. All file operations support both single files and folders with recursive operations. - -**Base Path**: `/files` - -## Authentication - -All endpoints require authentication. Include session token in headers: - -``` -Authorization: Bearer -``` - -## File Operations - -### List Files - -List files and folders in a bucket or path. - -**Endpoint**: `GET /files/list` - -**Query Parameters**: -- `bucket` (optional) - Bucket name -- `path` (optional) - Folder path - -**Response**: -```json -{ - "success": true, - "data": [ - { - "name": "document.pdf", - "path": "/documents/document.pdf", - "is_dir": false, - "size": 1048576, - "modified": "2024-01-15T10:30:00Z", - "icon": "📄" - }, - { - "name": "images", - "path": "/images", - "is_dir": true, - "size": null, - "modified": "2024-01-15T09:00:00Z", - "icon": "📁" - } - ] -} -``` - -**Example**: -```bash -curl -X GET "http://localhost:3000/files/list?bucket=my-bucket&path=/documents" \ - -H "Authorization: Bearer " -``` - -### Read File - -Read file content from storage. - -**Endpoint**: `POST /files/read` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/file.txt" -} -``` - -**Response**: -```json -{ - "content": "File content here..." -} -``` - -**Example**: -```bash -curl -X POST "http://localhost:3000/files/read" \ - -H "Authorization: Bearer " \ - -H "Content-Type: application/json" \ - -d '{"bucket":"my-bucket","path":"/file.txt"}' -``` - -### Get File Contents - -Alias for read file with alternative naming. - -**Endpoint**: `POST /files/getContents` - -Same parameters and response as `/files/read`. - -### Write File - -Write or update file content. - -**Endpoint**: `POST /files/write` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/file.txt", - "content": "New file content" -} -``` - -**Response**: -```json -{ - "success": true, - "message": "File written successfully" -} -``` - -### Save File - -Alias for write file. - -**Endpoint**: `POST /files/save` - -Same parameters and response as `/files/write`. - -### Upload File - -Upload file to storage. - -**Endpoint**: `POST /files/upload` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/upload.pdf", - "content": "base64_encoded_content_or_text" -} -``` - -**Response**: -```json -{ - "success": true, - "message": "File uploaded successfully" -} -``` - -### Download File - -Download file from storage. - -**Endpoint**: `POST /files/download` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/file.pdf" -} -``` - -**Response**: -```json -{ - "content": "file_content" -} -``` - -### Copy File - -Copy file or folder to another location. - -**Endpoint**: `POST /files/copy` - -**Request Body**: -```json -{ - "source_bucket": "my-bucket", - "source_path": "/documents/original.pdf", - "dest_bucket": "my-bucket", - "dest_path": "/backup/copy.pdf" -} -``` - -**Response**: -```json -{ - "success": true, - "message": "File copied successfully" -} -``` - -### Move File - -Move file or folder to another location. - -**Endpoint**: `POST /files/move` - -**Request Body**: -```json -{ - "source_bucket": "my-bucket", - "source_path": "/documents/file.pdf", - "dest_bucket": "archive-bucket", - "dest_path": "/archived/file.pdf" -} -``` - -**Response**: -```json -{ - "success": true, - "message": "File moved successfully" -} -``` - -**Note**: Move operation copies the file and then deletes the source. - -### Delete File - -Delete file or folder. - -**Endpoint**: `POST /files/delete` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/file.pdf" -} -``` - -**Response**: -```json -{ - "success": true, - "message": "Deleted successfully" -} -``` - -**Note**: If path ends with `/`, all objects with that prefix are deleted (recursive folder deletion). - -### Create Folder - -Create a new folder. - -**Endpoint**: `POST /files/createFolder` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents", - "name": "new-folder" -} -``` - -**Response**: -```json -{ - "success": true, - "message": "Folder created successfully" -} -``` - -**Alternative Endpoint**: `POST /files/create-folder` (dash notation) - -### List Folder Contents - -List contents of a specific folder. - -**Endpoint**: `POST /files/dirFolder` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents" -} -``` - -**Response**: -```json -[ - { - "name": "file1.pdf", - "path": "/documents/file1.pdf", - "is_dir": false, - "size": 1024, - "modified": "2024-01-15T10:30:00Z", - "icon": "📄" - } -] -``` - -## Search and Discovery - -### Search Files - -Search for files across buckets. - -**Endpoint**: `GET /files/search` - -**Query Parameters**: -- `bucket` (optional) - Limit search to specific bucket -- `query` (required) - Search term -- `file_type` (optional) - File extension filter (e.g., ".pdf") - -**Response**: -```json -[ - { - "name": "matching-file.pdf", - "path": "/documents/matching-file.pdf", - "is_dir": false, - "size": 2048576, - "modified": "2024-01-15T10:30:00Z", - "icon": "📄" - } -] -``` - -**Example**: -```bash -curl -X GET "http://localhost:3000/files/search?query=report&file_type=.pdf" \ - -H "Authorization: Bearer " -``` - -### Recent Files - -Get recently modified files. - -**Endpoint**: `GET /files/recent` - -**Query Parameters**: -- `bucket` (optional) - Filter by bucket - -**Response**: -```json -[ - { - "name": "recent-file.txt", - "path": "/documents/recent-file.txt", - "is_dir": false, - "size": 1024, - "modified": "2024-01-15T14:30:00Z", - "icon": "📃" - } -] -``` - -**Note**: Returns up to 50 most recently modified files, sorted by modification date descending. - -### Favorite Files - -List user's favorite files. - -**Endpoint**: `GET /files/favorite` - -**Response**: -```json -[] -``` - -**Note**: Currently returns empty array. Favorite functionality to be implemented. - -## Sharing and Permissions - -### Share Folder - -Share folder with other users. - -**Endpoint**: `POST /files/shareFolder` - -**Request Body**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/shared", - "users": ["user1@example.com", "user2@example.com"], - "permissions": "read-write" -} -``` - -**Response**: -```json -{ - "share_id": "550e8400-e29b-41d4-a716-446655440000", - "url": "https://share.example.com/550e8400-e29b-41d4-a716-446655440000", - "expires_at": "2024-01-22T10:30:00Z" -} -``` - -### List Shared Files - -Get files and folders shared with user. - -**Endpoint**: `GET /files/shared` - -**Response**: -```json -[] -``` - -### Get Permissions - -Get permissions for file or folder. - -**Endpoint**: `GET /files/permissions` - -**Query Parameters**: -- `bucket` (required) - Bucket name -- `path` (required) - File/folder path - -**Response**: -```json -{ - "bucket": "my-bucket", - "path": "/documents/file.pdf", - "permissions": { - "read": true, - "write": true, - "delete": true, - "share": true - }, - "shared_with": [] -} -``` - -## Storage Management - -### Get Quota - -Check storage quota information. - -**Endpoint**: `GET /files/quota` - -**Response**: -```json -{ - "total_bytes": 100000000000, - "used_bytes": 45678901234, - "available_bytes": 54321098766, - "percentage_used": 45.68 -} -``` - -**Example**: -```bash -curl -X GET "http://localhost:3000/files/quota" \ - -H "Authorization: Bearer " -``` - -## Synchronization - -### Sync Status - -Get current synchronization status. - -**Endpoint**: `GET /files/sync/status` - -**Response**: -```json -{ - "status": "idle", - "last_sync": "2024-01-15T10:30:00Z", - "files_synced": 0, - "bytes_synced": 0 -} -``` - -**Status values**: -- `idle` - No sync in progress -- `syncing` - Sync in progress -- `error` - Sync error occurred -- `paused` - Sync paused - -### Start Sync - -Start file synchronization. - -**Endpoint**: `POST /files/sync/start` - -**Response**: -```json -{ - "success": true, - "message": "Sync started" -} -``` - -### Stop Sync - -Stop file synchronization. - -**Endpoint**: `POST /files/sync/stop` - -**Response**: -```json -{ - "success": true, - "message": "Sync stopped" -} -``` - -## File Icons - -Files are automatically assigned icons based on extension: - -| Extension | Icon | Type | -|-----------|------|------| -| .bas | ⚙️ | BASIC script | -| .ast | 🔧 | AST file | -| .csv | 📊 | Spreadsheet | -| .gbkb | 📚 | Knowledge base | -| .json | 🔖 | JSON data | -| .txt, .md | 📃 | Text | -| .pdf | 📕 | PDF document | -| .zip, .tar, .gz | 📦 | Archive | -| .jpg, .png, .gif | 🖼️ | Image | -| folder | 📁 | Directory | -| .gbai | 🤖 | Bot package | -| default | 📄 | Generic file | - -## Error Handling - -Common error responses: - -**Service Unavailable**: -```json -{ - "error": "S3 service not available" -} -``` -Status: 503 - -**File Not Found**: -```json -{ - "error": "Failed to read file: NoSuchKey" -} -``` -Status: 500 - -**Invalid UTF-8**: -```json -{ - "error": "File is not valid UTF-8" -} -``` -Status: 500 - -## Best Practices - -1. **Large Files**: For files > 5MB, consider chunked uploads -2. **Batch Operations**: Use batch endpoints when operating on multiple files -3. **Path Naming**: Use forward slashes, avoid special characters -4. **Permissions**: Always check permissions before operations -5. **Error Handling**: Implement retry logic for transient failures -6. **Quotas**: Monitor quota usage to prevent storage exhaustion - -## Examples - -### Upload and Share Workflow - -```javascript -// 1. Upload file -const uploadResponse = await fetch('/files/upload', { - method: 'POST', - headers: { - 'Authorization': 'Bearer token', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - bucket: 'my-bucket', - path: '/documents/report.pdf', - content: fileContent - }) -}); - -// 2. Share with team -const shareResponse = await fetch('/files/shareFolder', { - method: 'POST', - headers: { - 'Authorization': 'Bearer token', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - bucket: 'my-bucket', - path: '/documents', - users: ['team@example.com'], - permissions: 'read-write' - }) -}); - -const { url } = await shareResponse.json(); -console.log('Share URL:', url); -``` - -### Search and Download - -```python -import requests - -# Search for files -response = requests.get( - 'http://localhost:3000/files/search', - params={'query': 'report', 'file_type': '.pdf'}, - headers={'Authorization': 'Bearer token'} -) - -files = response.json() - -# Download first result -if files: - download_response = requests.post( - 'http://localhost:3000/files/download', - json={ - 'bucket': 'my-bucket', - 'path': files[0]['path'] - }, - headers={'Authorization': 'Bearer token'} - ) - - content = download_response.json()['content'] - with open('downloaded.pdf', 'w') as f: - f.write(content) -``` - -## Next Steps - -- [Document Processing API](./document-processing.md) - Convert and merge documents -- [Storage API](./storage-api.md) - Advanced storage operations -- [Backup API](./backup-api.md) - Backup and restore \ No newline at end of file diff --git a/docs/src/chapter-10-api/group-membership.md b/docs/src/chapter-10-api/group-membership.md deleted file mode 100644 index 1b99e2cf..00000000 --- a/docs/src/chapter-10-api/group-membership.md +++ /dev/null @@ -1,598 +0,0 @@ -# Group Membership API - -BotServer provides RESTful endpoints for managing user groups, team memberships, and collaborative workspaces. - -## Overview - -The Group Membership API enables: -- Group creation and management -- Member addition and removal -- Role assignments within groups -- Permission inheritance -- Team collaboration features -- Workspace organization - -## Base URL - -``` -http://localhost:8080/api/v1/groups -``` - -## Authentication - -All Group Membership API requests require authentication: - -```http -Authorization: Bearer -``` - -## Endpoints - -### Create Group - -**POST** `/groups` - -Create a new group or team. - -**Request Body:** -```json -{ - "name": "Engineering Team", - "description": "Product engineering team", - "type": "team", - "visibility": "private", - "settings": { - "allow_join_requests": true, - "require_approval": true, - "max_members": 50 - }, - "permissions": ["bot.use", "kb.read", "reports.view"] -} -``` - -**Response:** -```json -{ - "group_id": "grp_abc123", - "name": "Engineering Team", - "type": "team", - "created_at": "2024-01-15T10:00:00Z", - "created_by": "usr_admin", - "member_count": 0 -} -``` - -### Get Group - -**GET** `/groups/{group_id}` - -Retrieve group information. - -**Response:** -```json -{ - "group_id": "grp_abc123", - "name": "Engineering Team", - "description": "Product engineering team", - "type": "team", - "visibility": "private", - "member_count": 12, - "created_at": "2024-01-15T10:00:00Z", - "settings": { - "allow_join_requests": true, - "require_approval": true, - "max_members": 50 - }, - "permissions": ["bot.use", "kb.read", "reports.view"] -} -``` - -### Update Group - -**PATCH** `/groups/{group_id}` - -Update group information. - -**Request Body:** -```json -{ - "name": "Engineering & DevOps Team", - "description": "Combined engineering and operations team", - "settings": { - "max_members": 75 - } -} -``` - -### Delete Group - -**DELETE** `/groups/{group_id}` - -Delete a group (requires admin permissions). - -**Response:** -```json -{ - "deleted": true, - "group_id": "grp_abc123", - "members_removed": 12 -} -``` - -### List Groups - -**GET** `/groups` - -List all groups with filtering. - -**Query Parameters:** -- `type` - Filter by group type: `team`, `department`, `project` -- `visibility` - Filter by visibility: `public`, `private` -- `member` - Filter groups containing specific user -- `search` - Search in name and description -- `page` - Page number (default: 1) -- `limit` - Items per page (default: 20) - -**Response:** -```json -{ - "groups": [ - { - "group_id": "grp_abc123", - "name": "Engineering Team", - "type": "team", - "member_count": 12, - "visibility": "private" - } - ], - "total": 8, - "page": 1, - "limit": 20 -} -``` - -## Member Management - -### Add Member - -**POST** `/groups/{group_id}/members` - -Add a member to a group. - -**Request Body:** -```json -{ - "user_id": "usr_xyz789", - "role": "member", - "permissions": ["read", "write"], - "notify": true -} -``` - -**Response:** -```json -{ - "membership_id": "mem_123", - "group_id": "grp_abc123", - "user_id": "usr_xyz789", - "role": "member", - "joined_at": "2024-01-15T10:30:00Z" -} -``` - -### Bulk Add Members - -**POST** `/groups/{group_id}/members/bulk` - -Add multiple members at once. - -**Request Body:** -```json -{ - "members": [ - {"user_id": "usr_001", "role": "admin"}, - {"user_id": "usr_002", "role": "member"}, - {"user_id": "usr_003", "role": "member"} - ], - "notify_all": true -} -``` - -**Response:** -```json -{ - "added": 3, - "failed": 0, - "memberships": [ - {"user_id": "usr_001", "status": "added"}, - {"user_id": "usr_002", "status": "added"}, - {"user_id": "usr_003", "status": "added"} - ] -} -``` - -### List Members - -**GET** `/groups/{group_id}/members` - -List group members. - -**Query Parameters:** -- `role` - Filter by role -- `status` - Filter by status: `active`, `pending`, `suspended` -- `search` - Search in member names -- `page` - Page number -- `limit` - Items per page - -**Response:** -```json -{ - "members": [ - { - "membership_id": "mem_123", - "user": { - "user_id": "usr_xyz789", - "username": "johndoe", - "full_name": "John Doe", - "avatar_url": "https://example.com/avatar.jpg" - }, - "role": "admin", - "status": "active", - "joined_at": "2024-01-15T10:30:00Z", - "last_active": "2024-01-15T14:00:00Z" - } - ], - "total": 12, - "page": 1, - "limit": 20 -} -``` - -### Update Member Role - -**PATCH** `/groups/{group_id}/members/{user_id}` - -Update a member's role or permissions. - -**Request Body:** -```json -{ - "role": "admin", - "permissions": ["read", "write", "delete"] -} -``` - -### Remove Member - -**DELETE** `/groups/{group_id}/members/{user_id}` - -Remove a member from a group. - -**Response:** -```json -{ - "removed": true, - "group_id": "grp_abc123", - "user_id": "usr_xyz789", - "removed_at": "2024-01-15T15:00:00Z" -} -``` - -## Group Roles - -### List Roles - -**GET** `/groups/{group_id}/roles` - -List available roles in a group. - -**Response:** -```json -{ - "roles": [ - { - "role_id": "owner", - "name": "Owner", - "permissions": ["all"], - "member_count": 1 - }, - { - "role_id": "admin", - "name": "Administrator", - "permissions": ["manage_members", "manage_settings", "read", "write"], - "member_count": 2 - }, - { - "role_id": "member", - "name": "Member", - "permissions": ["read", "write"], - "member_count": 9 - } - ] -} -``` - -### Create Custom Role - -**POST** `/groups/{group_id}/roles` - -Create a custom role for a group. - -**Request Body:** -```json -{ - "name": "Moderator", - "permissions": ["read", "write", "moderate"], - "description": "Can moderate content and manage posts" -} -``` - -## Join Requests - -### Request to Join - -**POST** `/groups/{group_id}/join-requests` - -Request to join a private group. - -**Request Body:** -```json -{ - "message": "I would like to join the engineering team", - "referred_by": "usr_admin" -} -``` - -**Response:** -```json -{ - "request_id": "req_456", - "group_id": "grp_abc123", - "user_id": "usr_xyz789", - "status": "pending", - "submitted_at": "2024-01-15T10:00:00Z" -} -``` - -### List Join Requests - -**GET** `/groups/{group_id}/join-requests` - -List pending join requests (admin only). - -**Response:** -```json -{ - "requests": [ - { - "request_id": "req_456", - "user": { - "user_id": "usr_xyz789", - "username": "newuser", - "full_name": "New User" - }, - "message": "I would like to join the engineering team", - "status": "pending", - "submitted_at": "2024-01-15T10:00:00Z" - } - ], - "total": 3 -} -``` - -### Approve/Reject Request - -**PATCH** `/groups/{group_id}/join-requests/{request_id}` - -Process a join request. - -**Request Body:** -```json -{ - "action": "approve", - "role": "member", - "note": "Welcome to the team!" -} -``` - -## Group Invitations - -### Send Invitation - -**POST** `/groups/{group_id}/invitations` - -Invite users to join a group. - -**Request Body:** -```json -{ - "emails": ["user1@example.com", "user2@example.com"], - "role": "member", - "message": "You're invited to join our team!", - "expires_in_days": 7 -} -``` - -**Response:** -```json -{ - "invitations": [ - { - "invitation_id": "inv_789", - "email": "user1@example.com", - "status": "sent", - "expires_at": "2024-01-22T10:00:00Z" - } - ], - "sent": 2, - "failed": 0 -} -``` - -### Accept Invitation - -**POST** `/invitations/{invitation_id}/accept` - -Accept a group invitation. - -**Response:** -```json -{ - "membership_id": "mem_999", - "group_id": "grp_abc123", - "joined_at": "2024-01-15T11:00:00Z" -} -``` - -## Group Permissions - -### Get Group Permissions - -**GET** `/groups/{group_id}/permissions` - -List group permissions. - -**Response:** -```json -{ - "permissions": [ - { - "permission": "bot.use", - "description": "Use bots", - "inherited_from": null - }, - { - "permission": "kb.read", - "description": "Read knowledge base", - "inherited_from": "parent_group" - } - ] -} -``` - -### Update Permissions - -**PATCH** `/groups/{group_id}/permissions` - -Update group permissions. - -**Request Body:** -```json -{ - "add": ["reports.create", "analytics.view"], - "remove": ["kb.write"] -} -``` - -## Hierarchical Groups - -### Create Subgroup - -**POST** `/groups/{parent_id}/subgroups` - -Create a subgroup under a parent group. - -**Request Body:** -```json -{ - "name": "Frontend Team", - "inherit_permissions": true, - "inherit_members": false -} -``` - -### List Subgroups - -**GET** `/groups/{group_id}/subgroups` - -List all subgroups. - -**Response:** -```json -{ - "subgroups": [ - { - "group_id": "grp_sub123", - "name": "Frontend Team", - "member_count": 5, - "created_at": "2024-01-15T10:00:00Z" - } - ], - "total": 2 -} -``` - -## Group Analytics - -### Get Group Analytics - -**GET** `/groups/{group_id}/analytics` - -Get group activity analytics. - -**Response:** -```json -{ - "group_id": "grp_abc123", - "analytics": { - "member_growth": { - "current": 12, - "last_month": 10, - "growth_rate": 0.20 - }, - "activity": { - "messages_sent": 456, - "tasks_completed": 23, - "avg_response_time": 3600 - }, - "engagement": { - "active_members": 10, - "engagement_rate": 0.83 - } - }, - "period": "30d" -} -``` - -## Error Responses - -### 403 Forbidden -```json -{ - "error": "permission_denied", - "message": "You don't have permission to manage this group" -} -``` - -### 409 Conflict -```json -{ - "error": "member_exists", - "message": "User is already a member of this group" -} -``` - -### 422 Unprocessable Entity -```json -{ - "error": "group_full", - "message": "Group has reached maximum member limit", - "max_members": 50, - "current_members": 50 -} -``` - -## Best Practices - -1. **Use Descriptive Names**: Group names should clearly indicate purpose -2. **Set Member Limits**: Prevent groups from becoming too large -3. **Regular Cleanup**: Remove inactive members periodically -4. **Permission Inheritance**: Use hierarchy for easier management -5. **Document Purpose**: Always include group descriptions -6. **Review Requests**: Don't auto-approve join requests for sensitive groups - -## Related APIs - -- [User Security API](./user-security.md) - User management -- [Notifications API](./notifications-api.md) - Group notifications -- [Tasks API](./tasks-api.md) - Group task management \ No newline at end of file diff --git a/docs/src/chapter-10-api/groups-api.md b/docs/src/chapter-10-api/groups-api.md deleted file mode 100644 index e2d08980..00000000 --- a/docs/src/chapter-10-api/groups-api.md +++ /dev/null @@ -1,219 +0,0 @@ -# Groups API - -The Groups API provides endpoints for managing groups and organizations through Zitadel integration. - -## Overview - -Groups in BotServer represent organizations in Zitadel. They provide multi-tenant support and user grouping capabilities. - -## Endpoints - -### Create Group - -**POST** `/groups/create` - -Creates a new group/organization. - -**Request:** -```json -{ - "name": "Engineering Team", - "description": "Software engineering department", - "domain": "engineering.example.com" -} -``` - -**Response:** -```json -{ - "id": "org-123", - "name": "Engineering Team", - "created_at": "2024-01-20T10:00:00Z" -} -``` - -### Update Group - -**PUT** `/groups/:id/update` - -Updates group information. - -**Request:** -```json -{ - "name": "Updated Name", - "description": "Updated description" -} -``` - -**Response:** -```json -{ - "id": "org-123", - "name": "Updated Name", - "updated_at": "2024-01-20T11:00:00Z" -} -``` - -### Delete Group - -**DELETE** `/groups/:id/delete` - -Deletes a group/organization. - -**Response:** -```json -{ - "success": true, - "message": "Group deleted successfully" -} -``` - -### List Groups - -**GET** `/groups/list` - -Lists all groups accessible to the user. - -**Query Parameters:** -- `limit` - Maximum number of results (default: 20) -- `offset` - Pagination offset - -**Response:** -```json -{ - "groups": [ - { - "id": "org-123", - "name": "Engineering Team", - "member_count": 25, - "created_at": "2024-01-20T10:00:00Z" - } - ], - "total": 1 -} -``` - -### Get Group Members - -**GET** `/groups/:id/members` - -Retrieves members of a specific group. - -**Response:** -```json -{ - "members": [ - { - "user_id": "user-456", - "username": "john_doe", - "email": "john@example.com", - "role": "member", - "joined_at": "2024-01-15T09:00:00Z" - } - ], - "total": 1 -} -``` - -### Add Group Member - -**POST** `/groups/:id/members/add` - -Adds a user to a group. - -**Request:** -```json -{ - "user_id": "user-789", - "role": "member" -} -``` - -**Response:** -```json -{ - "success": true, - "message": "Member added successfully" -} -``` - -### Remove Group Member - -**DELETE** `/groups/:id/members/remove` - -Removes a user from a group. - -**Request:** -```json -{ - "user_id": "user-789" -} -``` - -**Response:** -```json -{ - "success": true, - "message": "Member removed successfully" -} -``` - -## Implementation Details - -### Zitadel Integration - -All group operations are proxied to Zitadel: -- Groups map to Zitadel organizations -- Members are managed through Zitadel's org API -- Permissions inherited from Zitadel roles - -### Data Model - -Groups are not stored in BotServer's database. All data comes from Zitadel: -- Group metadata from Zitadel orgs -- Membership from Zitadel org members -- Permissions from Zitadel policies - -## Error Responses - -All endpoints may return standard error responses: - -```json -{ - "error": "Group not found", - "code": "GROUP_NOT_FOUND", - "status": 404 -} -``` - -Common error codes: -- `GROUP_NOT_FOUND` - Group doesn't exist -- `UNAUTHORIZED` - User lacks permission -- `MEMBER_EXISTS` - User already in group -- `MEMBER_NOT_FOUND` - User not in group -- `ZITADEL_ERROR` - Upstream service error - -## Permissions - -Group operations require appropriate Zitadel permissions: -- **Create**: Organization admin -- **Update**: Organization owner or admin -- **Delete**: Organization owner -- **List**: Authenticated user -- **View Members**: Group member -- **Add/Remove Members**: Group admin - -## Rate Limiting - -Group endpoints are rate-limited: -- 100 requests per minute for read operations -- 20 requests per minute for write operations - -## Best Practices - -1. **Cache Group Data**: Groups change infrequently -2. **Batch Operations**: Use bulk endpoints when available -3. **Handle Zitadel Errors**: Gracefully handle upstream failures -4. **Validate Permissions**: Check user has required role -5. **Audit Changes**: Log all group modifications \ No newline at end of file diff --git a/docs/src/chapter-10-api/ml-api.md b/docs/src/chapter-10-api/ml-api.md deleted file mode 100644 index a5a0dc90..00000000 --- a/docs/src/chapter-10-api/ml-api.md +++ /dev/null @@ -1,53 +0,0 @@ -# ML API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The ML API will provide endpoints for machine learning operations, model training, and predictive analytics. - -## Planned Features - -- Dataset management and preprocessing -- Model training and evaluation -- Hyperparameter tuning -- Batch predictions -- Model performance monitoring -- A/B testing for models -- Feature engineering tools - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/ml -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### Dataset Management -`POST /api/v1/ml/datasets` -`GET /api/v1/ml/datasets` -`DELETE /api/v1/ml/datasets/{dataset_id}` - -### Model Training -`POST /api/v1/ml/train` -`GET /api/v1/ml/jobs/{job_id}` -`POST /api/v1/ml/jobs/{job_id}/stop` - -### Predictions -`POST /api/v1/ml/predict` -`POST /api/v1/ml/batch-predict` - -### Model Evaluation -`GET /api/v1/ml/models/{model_id}/metrics` -`POST /api/v1/ml/models/{model_id}/evaluate` - -### Feature Engineering -`POST /api/v1/ml/features/extract` -`GET /api/v1/ml/features/importance` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/monitoring-api.md b/docs/src/chapter-10-api/monitoring-api.md deleted file mode 100644 index 645e7f1f..00000000 --- a/docs/src/chapter-10-api/monitoring-api.md +++ /dev/null @@ -1,50 +0,0 @@ -# Monitoring API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Monitoring API will provide endpoints for real-time system monitoring, performance metrics, and health checks. - -## Planned Features - -- Real-time system metrics -- Performance monitoring -- Health check endpoints -- Alert configuration -- Log aggregation -- Resource usage tracking -- Service status monitoring - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/monitoring -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### System Health -`GET /api/v1/monitoring/health` - -### Performance Metrics -`GET /api/v1/monitoring/metrics` - -### Service Status -`GET /api/v1/monitoring/services` - -### Resource Usage -`GET /api/v1/monitoring/resources` - -### Alert Configuration -`POST /api/v1/monitoring/alerts` -`GET /api/v1/monitoring/alerts` - -### Log Stream -`GET /api/v1/monitoring/logs` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/notifications-api.md b/docs/src/chapter-10-api/notifications-api.md deleted file mode 100644 index 78509a27..00000000 --- a/docs/src/chapter-10-api/notifications-api.md +++ /dev/null @@ -1,490 +0,0 @@ -# Notifications API - -BotServer provides RESTful endpoints for managing notifications across multiple channels including push notifications, in-app alerts, and message broadcasting. - -## Overview - -The Notifications API enables: -- Push notifications to users -- Broadcast messages to groups -- Alert management -- Notification preferences -- Delivery tracking - -## Base URL - -``` -http://localhost:8080/api/v1/notifications -``` - -## Authentication - -All Notifications API requests require authentication: - -```http -Authorization: Bearer -``` - -## Endpoints - -### Send Notification - -**POST** `/send` - -Send a notification to one or more recipients. - -**Request Body:** -```json -{ - "recipients": ["user123", "user456"], - "title": "System Update", - "message": "Maintenance scheduled for tonight", - "priority": "normal", - "channels": ["web", "email"], - "data": { - "action": "view_details", - "url": "/maintenance" - } -} -``` - -**Response:** -```json -{ - "notification_id": "ntf_abc123", - "recipients_count": 2, - "status": "queued", - "delivery": { - "web": "pending", - "email": "pending" - } -} -``` - -### Broadcast Message - -**POST** `/broadcast` - -Send a message to all users or a specific group. - -**Request Body:** -```json -{ - "target": "all", - "filters": { - "channel": "web", - "last_active": "7d" - }, - "message": { - "title": "New Feature Available", - "body": "Check out our latest update!", - "image_url": "https://example.com/feature.png" - }, - "schedule": "2024-01-15T14:00:00Z" -} -``` - -**Response:** -```json -{ - "broadcast_id": "brd_xyz789", - "target_count": 1250, - "scheduled_for": "2024-01-15T14:00:00Z", - "status": "scheduled" -} -``` - -### Get Notification Status - -**GET** `/notifications/{notification_id}` - -Get the status of a sent notification. - -**Response:** -```json -{ - "notification_id": "ntf_abc123", - "created_at": "2024-01-15T10:00:00Z", - "status": "delivered", - "delivery_details": [ - { - "recipient": "user123", - "channel": "web", - "status": "delivered", - "delivered_at": "2024-01-15T10:00:05Z" - }, - { - "recipient": "user123", - "channel": "email", - "status": "delivered", - "delivered_at": "2024-01-15T10:00:10Z" - } - ] -} -``` - -### List Notifications - -**GET** `/notifications` - -List sent notifications with optional filters. - -**Query Parameters:** -- `page` - Page number (default: 1) -- `limit` - Items per page (default: 20) -- `status` - Filter by status -- `channel` - Filter by channel -- `start_date` - Start date filter -- `end_date` - End date filter - -**Response:** -```json -{ - "notifications": [ - { - "notification_id": "ntf_abc123", - "title": "System Update", - "status": "delivered", - "created_at": "2024-01-15T10:00:00Z", - "recipients_count": 2 - } - ], - "total": 150, - "page": 1, - "limit": 20 -} -``` - -### Mark as Read - -**PATCH** `/notifications/{notification_id}/read` - -Mark a notification as read by the current user. - -**Response:** -```json -{ - "notification_id": "ntf_abc123", - "marked_as_read": true, - "read_at": "2024-01-15T10:05:00Z" -} -``` - -### Delete Notification - -**DELETE** `/notifications/{notification_id}` - -Delete a notification from the system. - -**Response:** -```json -{ - "deleted": true, - "notification_id": "ntf_abc123" -} -``` - -## User Preferences - -### Get Preferences - -**GET** `/users/{user_id}/preferences` - -Get notification preferences for a user. - -**Response:** -```json -{ - "user_id": "user123", - "preferences": { - "email": { - "enabled": true, - "frequency": "immediate" - }, - "push": { - "enabled": true, - "quiet_hours": { - "enabled": true, - "start": "22:00", - "end": "08:00" - } - }, - "sms": { - "enabled": false - }, - "categories": { - "system": true, - "marketing": false, - "updates": true - } - } -} -``` - -### Update Preferences - -**PATCH** `/users/{user_id}/preferences` - -Update notification preferences. - -**Request Body:** -```json -{ - "email": { - "enabled": false - }, - "push": { - "quiet_hours": { - "enabled": true, - "start": "23:00", - "end": "07:00" - } - } -} -``` - -## Notification Templates - -### Create Template - -**POST** `/templates` - -Create a reusable notification template. - -**Request Body:** -```json -{ - "name": "welcome_message", - "title": "Welcome to {{app_name}}", - "body": "Hi {{user_name}}, welcome to our platform!", - "channels": ["email", "push"], - "variables": ["app_name", "user_name"] -} -``` - -### Use Template - -**POST** `/send/template` - -Send notification using a template. - -**Request Body:** -```json -{ - "template": "welcome_message", - "recipients": ["user789"], - "variables": { - "app_name": "BotServer", - "user_name": "John" - } -} -``` - -## Notification Types - -### System Notifications - -Critical system messages and alerts. - -```json -{ - "type": "system", - "priority": "high", - "persistent": true, - "require_acknowledgment": true -} -``` - -### User Notifications - -Personal messages and updates. - -```json -{ - "type": "user", - "priority": "normal", - "expires_at": "2024-01-22T10:00:00Z" -} -``` - -### Broadcast Notifications - -Mass communications to multiple users. - -```json -{ - "type": "broadcast", - "target": "segment", - "segment_id": "active_users" -} -``` - -## Delivery Channels - -### Web Push - -Browser push notifications. - -```json -{ - "channel": "web", - "options": { - "icon": "https://example.com/icon.png", - "badge": "https://example.com/badge.png", - "vibrate": [200, 100, 200], - "require_interaction": false - } -} -``` - -### Email - -Email notifications with rich content. - -```json -{ - "channel": "email", - "options": { - "from": "noreply@example.com", - "reply_to": "support@example.com", - "attachments": [], - "html": true - } -} -``` - -### SMS - -Text message notifications. - -```json -{ - "channel": "sms", - "options": { - "sender_id": "BOTSERV", - "unicode": true - } -} -``` - -### In-App - -Notifications within the application. - -```json -{ - "channel": "in_app", - "options": { - "persist": true, - "category": "updates" - } -} -``` - -## Webhook Events - -### Delivery Events - -Configure webhooks to receive delivery updates. - -```json -{ - "event": "notification.delivered", - "notification_id": "ntf_abc123", - "recipient": "user123", - "channel": "email", - "delivered_at": "2024-01-15T10:00:10Z" -} -``` - -### Interaction Events - -Track user interactions with notifications. - -```json -{ - "event": "notification.clicked", - "notification_id": "ntf_abc123", - "user_id": "user123", - "clicked_at": "2024-01-15T10:05:00Z", - "action": "view_details" -} -``` - -## Error Responses - -### 400 Bad Request -```json -{ - "error": "invalid_recipients", - "message": "One or more recipients are invalid", - "invalid_recipients": ["unknown_user"] -} -``` - -### 429 Rate Limit -```json -{ - "error": "rate_limit_exceeded", - "message": "Notification send limit exceeded", - "limit": 100, - "window": "1h", - "retry_after": 3600 -} -``` - -## Usage Examples - -### Send Simple Notification - -```bash -curl -X POST \ - -H "Authorization: Bearer token123" \ - -H "Content-Type: application/json" \ - -d '{ - "recipients": ["user123"], - "title": "Hello", - "message": "This is a test notification" - }' \ - http://localhost:8080/api/v1/notifications/send -``` - -### Schedule Broadcast - -```bash -curl -X POST \ - -H "Authorization: Bearer token123" \ - -H "Content-Type: application/json" \ - -d '{ - "target": "all", - "message": { - "title": "Scheduled Maintenance", - "body": "System will be unavailable from 2 AM to 4 AM" - }, - "schedule": "2024-01-20T02:00:00Z" - }' \ - http://localhost:8080/api/v1/notifications/broadcast -``` - -## Best Practices - -1. **Batch Notifications**: Send to multiple recipients in one request -2. **Use Templates**: Maintain consistent messaging -3. **Respect Preferences**: Check user settings before sending -4. **Handle Failures**: Implement retry logic -5. **Track Delivery**: Monitor delivery rates -6. **Avoid Spam**: Rate limit and deduplicate messages - -## Rate Limits - -| Operation | Limit | Window | -|-----------|-------|--------| -| Send Notification | 100/hour | Per user | -| Broadcast | 10/day | Per account | -| Template Creation | 20/day | Per account | - -## Related APIs - -- [User API](./user-security.md) - User management -- [WebSocket API](../chapter-04/web-interface.md) - Real-time notifications -- [Email API](./keyword-send-mail.md) - Email notifications \ No newline at end of file diff --git a/docs/src/chapter-10-api/opensource-components.md b/docs/src/chapter-10-api/opensource-components.md deleted file mode 100644 index cf278bed..00000000 --- a/docs/src/chapter-10-api/opensource-components.md +++ /dev/null @@ -1,121 +0,0 @@ -# Open Source Components in GeneralBots Installer - -This article lists all open-source components integrated into the GeneralBots system through the `PackageManager` installer. Each component is registered automatically and downloaded from verified open-source repositories, ensuring transparency, security, and extensibility throughout the platform. - ---- - -## Core Infrastructure - -The foundation of GeneralBots relies on several battle-tested open-source infrastructure components that handle data persistence, caching, and search capabilities. - -### PostgreSQL (Tables) - -PostgreSQL provides the relational database storage layer for bot data and user sessions. The system uses binaries from [theseus-rs/postgresql-binaries](https://github.com/theseus-rs/postgresql-binaries) and operates under the PostgreSQL License, which is fully open source. - -### Valkey (Cache) - -Valkey serves as the in-memory caching system, providing Redis-compatible functionality for high-performance data access. Available from [valkey.io](https://valkey.io), it operates under the BSD 3-Clause license, making it suitable for both commercial and open-source deployments. - -### Drive (S3-Compatible Storage) - -For file management and object storage, GeneralBots integrates MinIO from [min.io](https://min.io). This S3-compatible storage solution enables seamless file operations and is licensed under AGPLv3. - -### Qdrant (Vector Database) - -The vector similarity search engine Qdrant, available from [qdrant/qdrant](https://github.com/qdrant/qdrant), powers embeddings and AI indexing capabilities. This Apache 2.0 licensed component enables semantic search and AI-driven document retrieval. - ---- - -## AI and LLM Components - -GeneralBots incorporates cutting-edge AI components that enable local inference and intelligent processing without requiring external API dependencies. - -### LLaMA.cpp (LLM Server) - -Local LLM inference for both chat and embedding models is handled by LLaMA.cpp from [ggml-org/llama.cpp](https://github.com/ggml-org/llama.cpp). This MIT-licensed component enables the system to run language models directly on the host machine, providing privacy and reduced latency. - -### DeepSeek & BGE Models - -Open models for reasoning and embeddings are sourced from [HuggingFace](https://huggingface.co). These models provide state-of-the-art capabilities for natural language understanding and are available under Apache 2.0 or MIT licenses depending on the specific model selected. - ---- - -## Communication and Networking - -The platform includes a comprehensive suite of networking components that handle email, web traffic, and DNS resolution. - -### Stalwart Mail Server - -For email functionality, GeneralBots integrates the Stalwart mail server from [stalwartlabs/stalwart](https://github.com/stalwartlabs/stalwart). This full-featured mail server supports SMTP, IMAP, and POP3 protocols, operating under the AGPLv3 license. - -### Caddy (Proxy) - -Caddy from [caddyserver/caddy](https://github.com/caddyserver/caddy) serves as the reverse proxy and web server, providing automatic HTTPS certificate management. This Apache 2.0 licensed component simplifies secure web deployment. - -### CoreDNS (DNS) - -Internal and external name resolution is handled by CoreDNS from [coredns/coredns](https://github.com/coredns/coredns). This flexible DNS server operates under the Apache 2.0 license and integrates seamlessly with the rest of the infrastructure. - ---- - -## Identity and Collaboration - -Managing user identity and enabling team collaboration requires robust tooling, which GeneralBots provides through these integrated components. - -### Zitadel (Directory) - -Identity and access management is powered by Zitadel from [zitadel/zitadel](https://github.com/zitadel/zitadel). This Apache 2.0 licensed system provides comprehensive user management, authentication, and authorization capabilities. - -### Forgejo (ALM) - -Git-based project management and CI/CD capabilities come from Forgejo, available at [codeberg.org/forgejo/forgejo](https://codeberg.org/forgejo/forgejo). This AGPLv3 licensed platform enables teams to manage code and automate deployments. - -### Forgejo Runner (ALM-CI) - -Continuous integration pipelines are executed by the Forgejo Runner from [forgejo/runner](https://code.forgejo.org/forgejo/runner). This AGPLv3 licensed component handles build and deployment automation tasks. - ---- - -## Productivity Tools - -GeneralBots includes a suite of productivity applications that enable users to communicate, collaborate, and create content. - -### Roundcube (Webmail) - -Web-based email access is provided by Roundcube from [roundcube/roundcubemail](https://github.com/roundcube/roundcubemail). This GPLv3 licensed client offers a familiar interface for managing email through the browser. - -### LiveKit (Meeting) - -Real-time video conferencing and media capabilities are powered by LiveKit from [livekit/livekit](https://github.com/livekit/livekit). This Apache 2.0 licensed component enables high-quality video meetings and streaming. - -### NocoDB (Table Editor) - -For database visualization and management, GeneralBots integrates NocoDB from [nocodb/nocodb](https://github.com/nocodb/nocodb). This GPLv3 licensed tool provides an Airtable-like interface for working with structured data. - -### LibreOffice Online (Doc Editor) - -Collaborative document editing is enabled through Collabora Online from [CollaboraOnline/online](https://github.com/CollaboraOnline/online). The `coolwsd` service provides browser-based document editing under the MPL 2.0 license. - ---- - -## System and Development Utilities - -Supporting the core platform are various system utilities that enable remote access, development workflows, and container management. - -### XFCE + XRDP (Desktop) - -A lightweight remote desktop environment is provided through XFCE from [xfce.org](https://xfce.org) combined with XRDP from [xrdp.org](https://xrdp.org). These GPLv2 licensed components enable graphical remote access to the system. - -### DevTools - -Essential developer utilities including Git, Curl, and Xclip are bundled with the platform. These tools, available under GPL, MIT, and BSD licenses respectively, support automation and scripting workflows. - -### Host (LXD) - -Container and virtualization management is handled by LXD from [linuxcontainers/lxd](https://github.com/lxc/lxd). This Apache 2.0 licensed component enables isolated environments for bot deployment and testing. - ---- - -## Summary - -Every component integrated into GeneralBots is fully open-source, ensuring that users have complete transparency into the system's operation. This commitment to open-source software provides security through community review, extensibility through standard interfaces, and freedom from vendor lock-in. Together, these components form a cohesive ecosystem that supports AI automation, secure communication, persistent storage, and seamless collaboration. \ No newline at end of file diff --git a/docs/src/chapter-10-api/reports-api.md b/docs/src/chapter-10-api/reports-api.md deleted file mode 100644 index c9cde66c..00000000 --- a/docs/src/chapter-10-api/reports-api.md +++ /dev/null @@ -1,48 +0,0 @@ -# Reports API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Reports API will provide endpoints for generating, managing, and exporting various types of reports from bot data and analytics. - -## Planned Features - -- Custom report generation -- Scheduled report delivery -- Multiple export formats (PDF, CSV, Excel) -- Report templates and presets -- Historical data reporting -- Compliance and audit reports - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/reports -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with appropriate role-based permissions. - -## Endpoints (Planned) - -### Generate Report -`POST /api/v1/reports/generate` - -### List Reports -`GET /api/v1/reports/list` - -### Get Report Status -`GET /api/v1/reports/{report_id}/status` - -### Download Report -`GET /api/v1/reports/{report_id}/download` - -### Schedule Report -`POST /api/v1/reports/schedule` - -### Delete Report -`DELETE /api/v1/reports/{report_id}` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/security-api.md b/docs/src/chapter-10-api/security-api.md deleted file mode 100644 index a0083969..00000000 --- a/docs/src/chapter-10-api/security-api.md +++ /dev/null @@ -1,59 +0,0 @@ -# Security API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -The Security API will provide endpoints for security management, access control, and threat monitoring. - -## Planned Features - -- Authentication and authorization management -- API key generation and management -- Role-based access control (RBAC) -- Security audit logging -- Threat detection and prevention -- Encryption key management -- Session management -- OAuth integration - -## Base URL (Planned) - -``` -http://localhost:8080/api/v1/security -``` - -## Authentication - -Will use the standard BotServer authentication mechanism with elevated security permissions required. - -## Endpoints (Planned) - -### Authentication -`POST /api/v1/security/auth/login` -`POST /api/v1/security/auth/logout` -`POST /api/v1/security/auth/refresh` - -### API Keys -`POST /api/v1/security/keys/generate` -`GET /api/v1/security/keys` -`DELETE /api/v1/security/keys/{key_id}` - -### Access Control -`GET /api/v1/security/roles` -`POST /api/v1/security/roles` -`PUT /api/v1/security/permissions` - -### Audit Logs -`GET /api/v1/security/audit` -`GET /api/v1/security/audit/export` - -### Session Management -`GET /api/v1/security/sessions` -`DELETE /api/v1/security/sessions/{session_id}` - -### Security Monitoring -`GET /api/v1/security/threats` -`GET /api/v1/security/vulnerabilities` - -## Implementation Status - -This API is currently in the planning phase. Check back in future releases for availability. \ No newline at end of file diff --git a/docs/src/chapter-10-api/storage-api.md b/docs/src/chapter-10-api/storage-api.md deleted file mode 100644 index 2abf2eb4..00000000 --- a/docs/src/chapter-10-api/storage-api.md +++ /dev/null @@ -1,344 +0,0 @@ -# Storage API - -> *⚠️ Note: This API is not yet implemented and is planned for a future release.* - -BotServer provides a RESTful API for managing file storage and object management through its S3-compatible storage backend. - -## Overview - -The Storage API allows you to: -- Upload and download files -- Manage buckets and objects -- Generate presigned URLs -- Handle binary data and documents -- Organize bot assets - -## Base URL - -``` -http://localhost:8080/api/v1/storage -``` - -## Authentication - -All storage API requests require authentication: - -```http -Authorization: Bearer -``` - -## Endpoints - -### List Buckets - -**GET** `/buckets` - -List all available storage buckets. - -**Response:** -```json -{ - "buckets": [ - { - "name": "mybot.gbai", - "created": "2024-01-15T10:00:00Z", - "size": 1048576 - } - ] -} -``` - -### Create Bucket - -**POST** `/buckets` - -Create a new storage bucket. - -**Request Body:** -```json -{ - "name": "newbot.gbai", - "region": "us-east-1", - "versioning": false -} -``` - -**Response:** -```json -{ - "bucket": "newbot.gbai", - "created": true, - "location": "/newbot.gbai" -} -``` - -### List Objects - -**GET** `/buckets/{bucket}/objects` - -List objects in a bucket. - -**Query Parameters:** -- `prefix` - Filter objects by prefix -- `delimiter` - Delimiter for grouping -- `max_keys` - Maximum number of results (default: 1000) -- `continuation_token` - Pagination token - -**Response:** -```json -{ - "objects": [ - { - "key": "documents/manual.pdf", - "size": 2048576, - "last_modified": "2024-01-15T10:30:00Z", - "etag": "d41d8cd98f00b204e9800998ecf8427e" - } - ], - "is_truncated": false, - "continuation_token": null -} -``` - -### Upload Object - -**PUT** `/buckets/{bucket}/objects/{key}` - -Upload a file to storage. - -**Headers:** -- `Content-Type` - MIME type of the file -- `Content-Length` - Size of the file -- `x-amz-meta-*` - Custom metadata - -**Request Body:** Binary file data - -**Response:** -```json -{ - "bucket": "mybot.gbai", - "key": "documents/report.pdf", - "etag": "d41d8cd98f00b204e9800998ecf8427e", - "version_id": null -} -``` - -### Download Object - -**GET** `/buckets/{bucket}/objects/{key}` - -Download a file from storage. - -**Headers:** -- `Range` - Partial content request (optional) -- `If-None-Match` - ETag for caching (optional) - -**Response:** Binary file data with appropriate headers - -### Delete Object - -**DELETE** `/buckets/{bucket}/objects/{key}` - -Delete an object from storage. - -**Response:** -```json -{ - "deleted": true, - "key": "documents/old-file.pdf" -} -``` - -### Copy Object - -**POST** `/buckets/{bucket}/objects/{key}/copy` - -Copy an object to a new location. - -**Request Body:** -```json -{ - "source_bucket": "source.gbai", - "source_key": "file.pdf", - "destination_bucket": "dest.gbai", - "destination_key": "copied-file.pdf" -} -``` - -**Response:** -```json -{ - "copied": true, - "source": "source.gbai/file.pdf", - "destination": "dest.gbai/copied-file.pdf" -} -``` - -### Generate Presigned URL - -**POST** `/buckets/{bucket}/objects/{key}/presign` - -Generate a presigned URL for temporary access. - -**Request Body:** -```json -{ - "operation": "GET", - "expires_in": 3600, - "content_type": "application/pdf" -} -``` - -**Response:** -```json -{ - "url": "http://localhost:9000/mybot.gbai/file.pdf?X-Amz-Algorithm=...", - "expires_at": "2024-01-15T11:30:00Z" -} -``` - -### Object Metadata - -**HEAD** `/buckets/{bucket}/objects/{key}` - -Get object metadata without downloading. - -**Response Headers:** -- `Content-Type` - MIME type -- `Content-Length` - File size -- `Last-Modified` - Modification time -- `ETag` - Entity tag -- `x-amz-meta-*` - Custom metadata - -### Multipart Upload - -**POST** `/buckets/{bucket}/objects/{key}/multipart` - -Initiate multipart upload for large files. - -**Response:** -```json -{ - "upload_id": "abc123...", - "bucket": "mybot.gbai", - "key": "large-file.zip" -} -``` - -**Upload Part:** -**PUT** `/buckets/{bucket}/objects/{key}/multipart/{uploadId}/{partNumber}` - -**Complete Upload:** -**POST** `/buckets/{bucket}/objects/{key}/multipart/{uploadId}/complete` - -## Error Responses - -### 404 Not Found -```json -{ - "error": "not_found", - "message": "Object not found", - "resource": "mybot.gbai/missing.pdf" -} -``` - -### 409 Conflict -```json -{ - "error": "conflict", - "message": "Bucket already exists", - "bucket": "existing.gbai" -} -``` - -### 507 Insufficient Storage -```json -{ - "error": "insufficient_storage", - "message": "Storage quota exceeded", - "quota": 10737418240, - "used": 10737418240 -} -``` - -## Usage Examples - -### Upload File with cURL - -```bash -curl -X PUT \ - -H "Authorization: Bearer token123" \ - -H "Content-Type: application/pdf" \ - --data-binary @document.pdf \ - http://localhost:8080/api/v1/storage/buckets/mybot.gbai/objects/docs/manual.pdf -``` - -### Download File - -```bash -curl -X GET \ - -H "Authorization: Bearer token123" \ - http://localhost:8080/api/v1/storage/buckets/mybot.gbai/objects/docs/manual.pdf \ - -o downloaded.pdf -``` - -### List Objects with Prefix - -```bash -curl -X GET \ - -H "Authorization: Bearer token123" \ - "http://localhost:8080/api/v1/storage/buckets/mybot.gbai/objects?prefix=docs/" -``` - -## Storage Organization - -### Recommended Structure - -``` -bucket/ -├── .gbkb/ # Knowledge base files -│ ├── docs/ -│ └── data/ -├── .gbdialog/ # Dialog scripts -│ ├── scripts/ -│ └── tools/ -├── .gbtheme/ # Theme assets -│ ├── css/ -│ └── images/ -└── .gbdrive/ # User uploads - ├── attachments/ - └── temp/ -``` - -## Quotas and Limits - -| Limit | Default Value | -|-------|--------------| -| Max file size | 100 MB | -| Max bucket size | 10 GB | -| Max objects per bucket | 10,000 | -| Presigned URL validity | 7 days | -| Multipart chunk size | 5 MB | - -## Performance Tips - -1. **Use Multipart Upload** for files > 5MB -2. **Enable Caching** with ETags -3. **Compress Large Files** before upload -4. **Use Presigned URLs** for direct client uploads -5. **Implement Retry Logic** for network failures - -## Security Considerations - -- All uploads are scanned for malware -- File types are validated -- Presigned URLs expire automatically -- Access control per bucket -- Encryption at rest -- SSL/TLS for transfers - -## Related APIs - -- [Document Processing API](./document-processing.md) -- [Reports API](./reports-api.md) -- [ML API](./ml-api.md) \ No newline at end of file diff --git a/docs/src/chapter-10-api/tasks-api.md b/docs/src/chapter-10-api/tasks-api.md deleted file mode 100644 index 32fafb75..00000000 --- a/docs/src/chapter-10-api/tasks-api.md +++ /dev/null @@ -1,508 +0,0 @@ -# Tasks API - -BotServer provides RESTful endpoints for creating, managing, and tracking tasks and workflows within bot conversations. - -## Overview - -The Tasks API enables: -- Task creation and assignment -- Workflow management -- Task tracking and status updates -- Deadline management -- Task prioritization -- Collaboration features - -## Base URL - -``` -http://localhost:8080/api/v1/tasks -``` - -## Authentication - -All Tasks API requests require authentication: - -```http -Authorization: Bearer -``` - -## Endpoints - -### Create Task - -**POST** `/tasks` - -Create a new task. - -**Request Body:** -```json -{ - "title": "Review customer complaint", - "description": "Investigate and respond to customer issue #1234", - "assignee": "user456", - "due_date": "2024-01-20T17:00:00Z", - "priority": "high", - "tags": ["support", "urgent"], - "context": { - "conversation_id": "conv_abc123", - "bot_id": "support_bot" - } -} -``` - -**Response:** -```json -{ - "task_id": "tsk_xyz789", - "title": "Review customer complaint", - "status": "pending", - "created_at": "2024-01-15T10:00:00Z", - "created_by": "user123" -} -``` - -### Get Task - -**GET** `/tasks/{task_id}` - -Retrieve task details. - -**Response:** -```json -{ - "task_id": "tsk_xyz789", - "title": "Review customer complaint", - "description": "Investigate and respond to customer issue #1234", - "status": "in_progress", - "assignee": { - "user_id": "user456", - "name": "Jane Smith", - "avatar_url": "https://example.com/avatar.jpg" - }, - "priority": "high", - "due_date": "2024-01-20T17:00:00Z", - "created_at": "2024-01-15T10:00:00Z", - "updated_at": "2024-01-15T14:30:00Z", - "progress": 60, - "time_spent_minutes": 45, - "comments_count": 3, - "attachments_count": 2 -} -``` - -### Update Task - -**PATCH** `/tasks/{task_id}` - -Update task properties. - -**Request Body:** -```json -{ - "status": "in_progress", - "progress": 60, - "assignee": "user789" -} -``` - -**Response:** -```json -{ - "task_id": "tsk_xyz789", - "updated": true, - "updated_fields": ["status", "progress", "assignee"], - "updated_at": "2024-01-15T14:30:00Z" -} -``` - -### List Tasks - -**GET** `/tasks` - -List tasks with filtering and pagination. - -**Query Parameters:** -- `status` - Filter by status: `pending`, `in_progress`, `completed`, `cancelled` -- `assignee` - Filter by assignee user ID -- `priority` - Filter by priority: `low`, `medium`, `high`, `critical` -- `due_before` - Tasks due before date -- `due_after` - Tasks due after date -- `tags` - Comma-separated tags -- `page` - Page number (default: 1) -- `limit` - Items per page (default: 20) -- `sort` - Sort by: `created_at`, `due_date`, `priority`, `updated_at` -- `order` - Sort order: `asc`, `desc` - -**Response:** -```json -{ - "tasks": [ - { - "task_id": "tsk_xyz789", - "title": "Review customer complaint", - "status": "in_progress", - "assignee": "user456", - "priority": "high", - "due_date": "2024-01-20T17:00:00Z", - "progress": 60 - } - ], - "total": 42, - "page": 1, - "limit": 20 -} -``` - -### Complete Task - -**POST** `/tasks/{task_id}/complete` - -Mark a task as completed. - -**Request Body:** -```json -{ - "resolution": "Issue resolved - refund processed", - "time_spent_minutes": 90, - "outcomes": ["customer_satisfied", "refund_issued"] -} -``` - -**Response:** -```json -{ - "task_id": "tsk_xyz789", - "status": "completed", - "completed_at": "2024-01-15T16:00:00Z", - "completed_by": "user456" -} -``` - -### Delete Task - -**DELETE** `/tasks/{task_id}` - -Delete a task. - -**Response:** -```json -{ - "deleted": true, - "task_id": "tsk_xyz789" -} -``` - -## Task Comments - -### Add Comment - -**POST** `/tasks/{task_id}/comments` - -Add a comment to a task. - -**Request Body:** -```json -{ - "text": "Contacted customer via email, waiting for response", - "mentions": ["user123"], - "attachments": ["file_abc123"] -} -``` - -**Response:** -```json -{ - "comment_id": "cmt_123", - "task_id": "tsk_xyz789", - "text": "Contacted customer via email, waiting for response", - "author": "user456", - "created_at": "2024-01-15T14:30:00Z" -} -``` - -### List Comments - -**GET** `/tasks/{task_id}/comments` - -Get task comments. - -**Response:** -```json -{ - "comments": [ - { - "comment_id": "cmt_123", - "text": "Contacted customer via email", - "author": { - "user_id": "user456", - "name": "Jane Smith" - }, - "created_at": "2024-01-15T14:30:00Z" - } - ], - "total": 3 -} -``` - -## Task Attachments - -### Upload Attachment - -**POST** `/tasks/{task_id}/attachments` - -Attach a file to a task. - -**Request:** -- Method: `POST` -- Content-Type: `multipart/form-data` -- Form fields: `file` (binary) - -**Response:** -```json -{ - "attachment_id": "att_789", - "task_id": "tsk_xyz789", - "filename": "screenshot.png", - "size_bytes": 102400, - "mime_type": "image/png", - "uploaded_at": "2024-01-15T14:45:00Z" -} -``` - -## Task Templates - -### Create Template - -**POST** `/templates` - -Create a reusable task template. - -**Request Body:** -```json -{ - "name": "Customer Complaint", - "description_template": "Investigate issue: {{issue_id}}", - "default_priority": "high", - "default_tags": ["support"], - "checklist": [ - "Review conversation history", - "Contact customer", - "Provide resolution", - "Follow up" - ] -} -``` - -### Create Task from Template - -**POST** `/tasks/from-template` - -Create a task from a template. - -**Request Body:** -```json -{ - "template_id": "tpl_123", - "variables": { - "issue_id": "#1234" - }, - "assignee": "user456", - "due_date": "2024-01-20T17:00:00Z" -} -``` - -## Workflows - -### Create Workflow - -**POST** `/workflows` - -Create a multi-step workflow. - -**Request Body:** -```json -{ - "name": "Customer Onboarding", - "steps": [ - { - "name": "Account Setup", - "assignee": "user456", - "duration_hours": 2 - }, - { - "name": "Training", - "assignee": "user789", - "duration_hours": 4, - "depends_on": ["Account Setup"] - } - ] -} -``` - -### Get Workflow Status - -**GET** `/workflows/{workflow_id}/status` - -Get workflow progress. - -**Response:** -```json -{ - "workflow_id": "wf_123", - "name": "Customer Onboarding", - "status": "in_progress", - "progress": 50, - "completed_steps": 1, - "total_steps": 2, - "current_step": "Training", - "estimated_completion": "2024-01-16T12:00:00Z" -} -``` - -## Task Automation - -### Create Automation Rule - -**POST** `/automations` - -Create rules for automatic task creation. - -**Request Body:** -```json -{ - "name": "High Priority Support", - "trigger": { - "type": "conversation_tag", - "value": "urgent" - }, - "action": { - "type": "create_task", - "template": "tpl_urgent", - "auto_assign": true, - "priority": "critical" - } -} -``` - -## Notifications - -### Task Notifications - -Configure notifications for task events: - -```json -{ - "events": [ - "task_assigned", - "task_completed", - "task_overdue", - "comment_added" - ], - "channels": ["email", "in_app"], - "recipients": ["assignee", "watchers"] -} -``` - -## Analytics - -### Task Analytics - -**GET** `/tasks/analytics` - -Get task performance metrics. - -**Response:** -```json -{ - "summary": { - "total_tasks": 234, - "completed": 189, - "in_progress": 35, - "overdue": 10, - "completion_rate": 0.81, - "average_completion_time_hours": 4.5 - }, - "by_priority": { - "critical": {"total": 10, "completed": 8}, - "high": {"total": 45, "completed": 40}, - "medium": {"total": 120, "completed": 100}, - "low": {"total": 59, "completed": 41} - }, - "by_assignee": [ - { - "user_id": "user456", - "name": "Jane Smith", - "tasks_completed": 45, - "average_time_hours": 3.2 - } - ] -} -``` - -## Error Responses - -### 400 Bad Request -```json -{ - "error": "invalid_due_date", - "message": "Due date must be in the future" -} -``` - -### 404 Not Found -```json -{ - "error": "task_not_found", - "message": "Task tsk_xyz789 not found" -} -``` - -### 403 Forbidden -```json -{ - "error": "permission_denied", - "message": "You don't have permission to modify this task" -} -``` - -## Best Practices - -1. **Clear Titles**: Use descriptive, action-oriented task titles -2. **Set Priorities**: Always set appropriate priority levels -3. **Add Context**: Include conversation or bot context -4. **Use Templates**: Create templates for recurring task types -5. **Track Progress**: Update progress regularly -6. **Set Realistic Deadlines**: Allow adequate time for completion -7. **Use Tags**: Categorize tasks with consistent tags - -## Integration with BASIC - -Tasks can be created from BASIC scripts: - -```basic -' Create task from conversation -task_id = CREATE TASK "Follow up with customer", "user456" -SET TASK PRIORITY task_id, "high" -SET TASK DUE DATE task_id, NOW() + 24 * 3600 - -' Check task status -status = GET TASK STATUS task_id -IF status = "completed" THEN - TALK "Task has been completed" -END IF -``` - -## Rate Limits - -| Operation | Limit | Window | -|-----------|-------|--------| -| Create Task | 100/hour | Per user | -| Update Task | 200/hour | Per user | -| List Tasks | 60/minute | Per user | -| Add Comment | 50/hour | Per user | - -## Related APIs - -- [Notifications API](./notifications-api.md) - Task notifications -- [Analytics API](./analytics-api.md) - Task analytics -- [User API](./user-security.md) - User management \ No newline at end of file diff --git a/docs/src/chapter-10-api/user-security.md b/docs/src/chapter-10-api/user-security.md deleted file mode 100644 index c2ee3171..00000000 --- a/docs/src/chapter-10-api/user-security.md +++ /dev/null @@ -1,642 +0,0 @@ -# User Security API - -BotServer provides RESTful endpoints for user management, authentication, authorization, and security features. - -## Overview - -The User Security API enables: -- User authentication and sessions -- Role-based access control -- Security settings management -- Audit logging -- Password policies -- Two-factor authentication - -## Base URL - -``` -http://localhost:8080/api/v1/security -``` - -## Authentication - -Most security endpoints require authentication: - -```http -Authorization: Bearer -``` - -## User Management - -### Create User - -**POST** `/users` - -Create a new user account. - -**Request Body:** -```json -{ - "username": "johndoe", - "email": "john@example.com", - "full_name": "John Doe", - "role": "user", - "groups": ["support_team"], - "metadata": { - "department": "Customer Service", - "employee_id": "EMP001" - } -} -``` - -**Response:** -```json -{ - "user_id": "usr_abc123", - "username": "johndoe", - "email": "john@example.com", - "created_at": "2024-01-15T10:00:00Z", - "status": "pending_activation" -} -``` - -### Get User - -**GET** `/users/{user_id}` - -Retrieve user information. - -**Response:** -```json -{ - "user_id": "usr_abc123", - "username": "johndoe", - "email": "john@example.com", - "full_name": "John Doe", - "role": "user", - "groups": ["support_team"], - "status": "active", - "created_at": "2024-01-15T10:00:00Z", - "last_login": "2024-01-15T14:30:00Z", - "email_verified": true, - "two_factor_enabled": false -} -``` - -### Update User - -**PATCH** `/users/{user_id}` - -Update user information. - -**Request Body:** -```json -{ - "full_name": "John Smith", - "role": "admin", - "groups": ["support_team", "admin_team"] -} -``` - -### Delete User - -**DELETE** `/users/{user_id}` - -Delete or deactivate a user account. - -**Response:** -```json -{ - "user_id": "usr_abc123", - "status": "deactivated", - "deactivated_at": "2024-01-15T15:00:00Z" -} -``` - -### List Users - -**GET** `/users` - -List all users with pagination and filters. - -**Query Parameters:** -- `page` - Page number (default: 1) -- `limit` - Items per page (default: 20) -- `role` - Filter by role -- `group` - Filter by group -- `status` - Filter by status: `active`, `inactive`, `pending` -- `search` - Search in username, email, full name - -**Response:** -```json -{ - "users": [ - { - "user_id": "usr_abc123", - "username": "johndoe", - "email": "john@example.com", - "full_name": "John Doe", - "role": "user", - "status": "active" - } - ], - "total": 150, - "page": 1, - "limit": 20 -} -``` - -## Authentication - -### Login - -**POST** `/auth/login` - -Authenticate user via directory service. - -**Request Body:** -```json -{ - "username": "johndoe", - "password": "secure_password", - "two_factor_code": "123456" -} -``` - -**Response:** -```json -{ - "access_token": "eyJhbGciOiJIUzI1NiIs...", - "refresh_token": "eyJhbGciOiJIUzI1NiIs...", - "token_type": "Bearer", - "expires_in": 3600, - "user": { - "user_id": "usr_abc123", - "username": "johndoe", - "role": "user" - } -} -``` - -### Refresh Token - -**POST** `/auth/refresh` - -Refresh an expired access token. - -**Request Body:** -```json -{ - "refresh_token": "eyJhbGciOiJIUzI1NiIs..." -} -``` - -### Logout - -**POST** `/auth/logout` - -Invalidate current session. - -**Request Body:** -```json -{ - "refresh_token": "eyJhbGciOiJIUzI1NiIs..." -} -``` - -### Verify Token - -**GET** `/auth/verify` - -Verify if a token is valid. - -**Headers:** -```http -Authorization: Bearer -``` - -**Response:** -```json -{ - "valid": true, - "user_id": "usr_abc123", - "expires_at": "2024-01-15T15:00:00Z" -} -``` - -## Roles and Permissions - -### List Roles - -**GET** `/roles` - -Get all available roles. - -**Response:** -```json -{ - "roles": [ - { - "role_id": "admin", - "name": "Administrator", - "permissions": ["users.manage", "bots.manage", "system.configure"] - }, - { - "role_id": "user", - "name": "User", - "permissions": ["bots.use", "profile.edit"] - } - ] -} -``` - -### Assign Role - -**POST** `/users/{user_id}/roles` - -Assign a role to a user. - -**Request Body:** -```json -{ - "role_id": "admin" -} -``` - -### Check Permission - -**GET** `/users/{user_id}/permissions/{permission}` - -Check if user has a specific permission. - -**Response:** -```json -{ - "user_id": "usr_abc123", - "permission": "bots.manage", - "granted": true, - "source": "role:admin" -} -``` - -## Groups - -### Create Group - -**POST** `/groups` - -Create a user group. - -**Request Body:** -```json -{ - "name": "support_team", - "description": "Customer support team", - "permissions": ["tickets.manage", "kb.edit"] -} -``` - -### Add User to Group - -**POST** `/groups/{group_id}/members` - -Add a user to a group. - -**Request Body:** -```json -{ - "user_id": "usr_abc123" -} -``` - -### Remove User from Group - -**DELETE** `/groups/{group_id}/members/{user_id}` - -Remove a user from a group. - -## Security Settings - -### Get Security Settings - -**GET** `/settings/security` - -Get current security configuration. - -**Response:** -```json -{ - "password_policy": { - "min_length": 12, - "require_uppercase": true, - "require_lowercase": true, - "require_numbers": true, - "require_special": true, - "expiry_days": 90, - "history_count": 5 - }, - "session_policy": { - "timeout_minutes": 30, - "max_sessions": 5, - "remember_me_days": 30 - }, - "two_factor": { - "enabled": false, - "required_for_roles": ["admin"], - "methods": ["totp", "sms"] - }, - "lockout_policy": { - "max_attempts": 5, - "lockout_duration_minutes": 30, - "reset_window_minutes": 15 - } -} -``` - -### Update Security Settings - -**PATCH** `/settings/security` - -Update security configuration. - -**Request Body:** -```json -{ - "password_policy": { - "min_length": 14, - "expiry_days": 60 - }, - "two_factor": { - "enabled": true - } -} -``` - -## Two-Factor Authentication - -### Enable 2FA - -**POST** `/users/{user_id}/2fa/enable` - -Enable two-factor authentication. - -**Response:** -```json -{ - "secret": "JBSWY3DPEHPK3PXP", - "qr_code": "data:image/png;base64,iVBORw0KGgoAAAA...", - "backup_codes": [ - "12345678", - "87654321", - "11223344" - ] -} -``` - -### Verify 2FA - -**POST** `/users/{user_id}/2fa/verify` - -Verify 2FA setup. - -**Request Body:** -```json -{ - "code": "123456" -} -``` - -### Disable 2FA - -**POST** `/users/{user_id}/2fa/disable` - -Disable two-factor authentication. - -## Audit Logs - -### Get Audit Logs - -**GET** `/audit/logs` - -Retrieve security audit logs. - -**Query Parameters:** -- `user_id` - Filter by user -- `action` - Filter by action type -- `start_date` - Start of date range -- `end_date` - End of date range -- `page` - Page number -- `limit` - Items per page - -**Response:** -```json -{ - "logs": [ - { - "log_id": "log_123", - "timestamp": "2024-01-15T14:30:00Z", - "user_id": "usr_abc123", - "action": "login", - "ip_address": "192.168.1.100", - "user_agent": "Mozilla/5.0...", - "success": true, - "details": { - "method": "password", - "session_id": "sess_xyz" - } - } - ], - "total": 500, - "page": 1 -} -``` - -### Export Audit Logs - -**POST** `/audit/export` - -Export audit logs for compliance. - -**Request Body:** -```json -{ - "format": "csv", - "date_range": { - "start": "2024-01-01", - "end": "2024-01-31" - }, - "filters": { - "actions": ["login", "permission_change", "data_access"] - } -} -``` - -## Session Management - -### List Sessions - -**GET** `/users/{user_id}/sessions` - -List active sessions for a user. - -**Response:** -```json -{ - "sessions": [ - { - "session_id": "sess_xyz", - "created_at": "2024-01-15T10:00:00Z", - "last_activity": "2024-01-15T14:30:00Z", - "ip_address": "192.168.1.100", - "user_agent": "Mozilla/5.0...", - "location": "New York, US" - } - ], - "total": 2 -} -``` - -### Revoke Session - -**DELETE** `/sessions/{session_id}` - -Revoke a specific session. - -### Revoke All Sessions - -**POST** `/users/{user_id}/sessions/revoke-all` - -Revoke all sessions for a user. - -## Password Management - -### Change Password - -**POST** `/users/{user_id}/password` - -Change user password (handled by directory service). - -**Request Body:** -```json -{ - "current_password": "old_password", - "new_password": "new_secure_password" -} -``` - -### Reset Password Request - -**POST** `/auth/password/reset-request` - -Request password reset. - -**Request Body:** -```json -{ - "email": "john@example.com" -} -``` - -### Reset Password - -**POST** `/auth/password/reset` - -Reset password with token. - -**Request Body:** -```json -{ - "token": "reset_token_123", - "new_password": "new_secure_password" -} -``` - -## API Keys - -### Generate API Key - -**POST** `/users/{user_id}/api-keys` - -Generate an API key for programmatic access. - -**Request Body:** -```json -{ - "name": "Integration Key", - "permissions": ["bots.use"], - "expires_at": "2024-12-31T23:59:59Z" -} -``` - -**Response:** -```json -{ - "key_id": "key_123", - "api_key": "sk_live_abcdef123456...", - "created_at": "2024-01-15T10:00:00Z", - "expires_at": "2024-12-31T23:59:59Z" -} -``` - -### List API Keys - -**GET** `/users/{user_id}/api-keys` - -List user's API keys. - -### Revoke API Key - -**DELETE** `/api-keys/{key_id}` - -Revoke an API key. - -## Error Responses - -### 401 Unauthorized -```json -{ - "error": "unauthorized", - "message": "Invalid credentials" -} -``` - -### 403 Forbidden -```json -{ - "error": "forbidden", - "message": "Insufficient permissions" -} -``` - -### 423 Locked -```json -{ - "error": "account_locked", - "message": "Account locked due to too many failed attempts", - "locked_until": "2024-01-15T15:00:00Z" -} -``` - -## Security Best Practices - -1. **Use Strong Passwords**: Enforce complex password requirements -2. **Enable 2FA**: Require for administrative accounts -3. **Regular Audits**: Review audit logs regularly -4. **Session Limits**: Limit concurrent sessions -5. **API Key Rotation**: Rotate keys periodically -6. **Least Privilege**: Grant minimal necessary permissions -7. **Monitor Failed Logins**: Track and alert on suspicious activity - -## Rate Limits - -| Operation | Limit | Window | -|-----------|-------|--------| -| Login | 5/minute | Per IP | -| Password Reset | 3/hour | Per email | -| API Key Generation | 10/day | Per user | - -## Related APIs - -- [Authentication](../chapter-11/authentication.md) - Auth details -- [Audit Logs](./monitoring-api.md) - System monitoring -- [Notifications](./notifications-api.md) - Security alerts \ No newline at end of file diff --git a/docs/src/chapter-10-api/users-api.md b/docs/src/chapter-10-api/users-api.md deleted file mode 100644 index ca49d05c..00000000 --- a/docs/src/chapter-10-api/users-api.md +++ /dev/null @@ -1,451 +0,0 @@ -# Users API - -The Users API provides endpoints for user management operations. User authentication is handled through Zitadel, with BotServer maintaining session associations and user preferences. - -## Overview - -User management in General Bots follows a federated model: - -- **Zitadel**: Primary identity provider (authentication, SSO, user creation) -- **BotServer**: Session management, preferences, bot-specific user data - -## Endpoints - -### Get Current User - -**GET** `/api/users/me` - -Returns current authenticated user information. - -**Headers:** -``` -Authorization: Bearer {session_token} -``` - -**Response:** -```json -{ - "user_id": "user-123", - "username": "john_doe", - "email": "john@example.com", - "display_name": "John Doe", - "avatar_url": "/api/users/user-123/avatar", - "roles": ["user", "manager"], - "created_at": "2024-01-01T00:00:00Z", - "last_login": "2024-01-15T10:30:00Z" -} -``` - -### Get User by ID - -**GET** `/api/users/:id` - -Retrieve specific user details. - -**Required Permission:** `admin:users` or same user - -**Response:** -```json -{ - "user_id": "user-123", - "username": "john_doe", - "email": "john@example.com", - "display_name": "John Doe", - "status": "active", - "created_at": "2024-01-01T00:00:00Z" -} -``` - -### List Users - -**GET** `/api/users` - -List users in the organization. - -**Required Permission:** `admin:users` - -**Query Parameters:** -- `limit` - Number of results (default: 50, max: 100) -- `offset` - Pagination offset -- `status` - Filter by status (active/suspended/inactive) -- `role` - Filter by role -- `search` - Search by name or email - -**Response:** -```json -{ - "users": [ - { - "user_id": "user-123", - "username": "john_doe", - "email": "john@example.com", - "display_name": "John Doe", - "status": "active", - "roles": ["user", "manager"] - }, - { - "user_id": "user-456", - "username": "jane_smith", - "email": "jane@example.com", - "display_name": "Jane Smith", - "status": "active", - "roles": ["user"] - } - ], - "total": 47, - "limit": 50, - "offset": 0 -} -``` - -### Update User - -**PUT** `/api/users/:id` - -Update user information. - -**Required Permission:** `admin:users` or same user (limited fields) - -**Request:** -```json -{ - "display_name": "John D. Doe", - "avatar_url": "https://example.com/avatar.jpg" -} -``` - -**Admin-only fields:** -```json -{ - "status": "suspended", - "roles": ["user"] -} -``` - -**Response:** -```json -{ - "user_id": "user-123", - "status": "updated", - "updated_fields": ["display_name"] -} -``` - -### Update User Settings - -**PUT** `/api/users/:id/settings` - -Update user preferences. - -**Request:** -```json -{ - "theme": "dark", - "language": "en", - "notifications": { - "email": true, - "push": false, - "digest": "daily" - }, - "default_bot": "support-bot" -} -``` - -**Response:** -```json -{ - "status": "updated", - "settings": { - "theme": "dark", - "language": "en" - } -} -``` - -### Get User Settings - -**GET** `/api/users/:id/settings` - -Retrieve user preferences. - -**Response:** -```json -{ - "theme": "dark", - "language": "en", - "timezone": "America/New_York", - "notifications": { - "email": true, - "push": false, - "digest": "daily" - }, - "default_bot": "support-bot" -} -``` - -### Suspend User - -**POST** `/api/users/:id/suspend` - -Suspend a user account. - -**Required Permission:** `admin:users` - -**Request:** -```json -{ - "reason": "Policy violation" -} -``` - -**Response:** -```json -{ - "user_id": "user-123", - "status": "suspended", - "suspended_at": "2024-01-15T10:30:00Z" -} -``` - -### Activate User - -**POST** `/api/users/:id/activate` - -Reactivate a suspended user. - -**Required Permission:** `admin:users` - -**Response:** -```json -{ - "user_id": "user-123", - "status": "active", - "activated_at": "2024-01-15T10:30:00Z" -} -``` - -### Delete User - -**DELETE** `/api/users/:id` - -Deactivate/delete user account. - -**Required Permission:** `admin:users` - -**Response:** -```json -{ - "user_id": "user-123", - "status": "deleted", - "deleted_at": "2024-01-15T10:30:00Z" -} -``` - -## User Sessions - -### List User Sessions - -**GET** `/api/users/:id/sessions` - -List active sessions for a user. - -**Response:** -```json -{ - "sessions": [ - { - "session_id": "sess-001", - "bot_id": "support-bot", - "started_at": "2024-01-15T09:00:00Z", - "last_activity": "2024-01-15T10:30:00Z", - "device": "Chrome on Windows" - } - ] -} -``` - -### Terminate Session - -**DELETE** `/api/users/:id/sessions/:session_id` - -End a specific user session. - -**Response:** -```json -{ - "session_id": "sess-001", - "status": "terminated" -} -``` - -### Terminate All Sessions - -**DELETE** `/api/users/:id/sessions` - -End all user sessions (logout everywhere). - -**Response:** -```json -{ - "terminated_count": 3, - "status": "all_sessions_terminated" -} -``` - -## User Authentication Flow - -### Login - -**POST** `/api/users/login` - -Authenticate user (redirects to Zitadel). - -**Request:** -```json -{ - "email": "user@example.com", - "password": "password", - "remember_me": true -} -``` - -**Response:** -```json -{ - "redirect_url": "https://auth.yourdomain.com/oauth/authorize?..." -} -``` - -### Logout - -**POST** `/api/users/logout` - -End current session. - -**Response:** -```json -{ - "status": "logged_out", - "redirect_url": "/" -} -``` - -### Register - -**POST** `/api/users/register` - -Register new user (if self-registration enabled). - -**Request:** -```json -{ - "email": "newuser@example.com", - "username": "newuser", - "password": "SecurePassword123!", - "display_name": "New User" -} -``` - -**Response:** -```json -{ - "user_id": "user-789", - "status": "pending_verification", - "message": "Check your email to verify your account" -} -``` - -## User Management via Zitadel - -For full user management, access Zitadel admin console: - -1. **Access Console**: `http://localhost:8080` (or your Zitadel URL) -2. **Create Users**: Organization → Users → Add -3. **Manage Roles**: Users → Select User → Authorizations -4. **Reset Passwords**: Users → Select User → Actions → Reset Password -5. **Configure SSO**: Settings → Identity Providers - -## Database Schema - -BotServer maintains minimal user data: - -```sql --- users table (synced from Zitadel) -CREATE TABLE users ( - id UUID PRIMARY KEY, - zitadel_id TEXT UNIQUE, - username TEXT, - email TEXT, - display_name TEXT, - avatar_url TEXT, - status TEXT DEFAULT 'active', - created_at TIMESTAMPTZ DEFAULT NOW(), - updated_at TIMESTAMPTZ DEFAULT NOW() -); - --- user_settings table -CREATE TABLE user_settings ( - id UUID PRIMARY KEY, - user_id UUID REFERENCES users(id), - setting_key TEXT NOT NULL, - setting_value TEXT, - UNIQUE(user_id, setting_key) -); - --- user_sessions table -CREATE TABLE sessions ( - id UUID PRIMARY KEY, - user_id UUID REFERENCES users(id), - bot_id UUID, - status TEXT DEFAULT 'active', - device_info TEXT, - created_at TIMESTAMPTZ DEFAULT NOW(), - last_activity TIMESTAMPTZ DEFAULT NOW() -); -``` - -## Error Handling - -| Status Code | Error | Description | -|-------------|-------|-------------| -| 400 | `invalid_request` | Malformed request | -| 401 | `unauthorized` | Not authenticated | -| 403 | `forbidden` | Insufficient permissions | -| 404 | `user_not_found` | User doesn't exist | -| 409 | `conflict` | Username/email already exists | -| 422 | `validation_error` | Invalid field values | - -## Rate Limits - -| Endpoint | Limit | -|----------|-------| -| Login | 10/minute per IP | -| Register | 5/hour per IP | -| User List | 60/minute per user | -| User Update | 30/minute per user | - -## BASIC Integration - -Access user information in scripts: - -```basic -' Get current user info -user_name = GET user_name -user_email = GET user_email - -' Greet by name -TALK "Hello, " + user_name + "!" - -' Check user role -role = GET role -IF role = "admin" THEN - TALK "Welcome, administrator!" -END IF -``` - -## See Also - -- [User Authentication](../chapter-12-auth/user-auth.md) - Auth details -- [Permissions Matrix](../chapter-12-auth/permissions-matrix.md) - Access control -- [Groups API](./groups-api.md) - Group management -- [SET USER Keyword](../chapter-06-gbdialog/keyword-set-user.md) - BASIC user context \ No newline at end of file diff --git a/docs/src/chapter-10-api/whiteboard-api.md b/docs/src/chapter-10-api/whiteboard-api.md deleted file mode 100644 index 018fd1fb..00000000 --- a/docs/src/chapter-10-api/whiteboard-api.md +++ /dev/null @@ -1,216 +0,0 @@ -# Whiteboard API - -The Whiteboard API provides endpoints for collaborative drawing, diagramming, and visual collaboration within BotServer. - -## Status - -**⚠️ NOT IMPLEMENTED** - -This API is planned for future development but is not currently available in BotServer. - -## Planned Features - -The Whiteboard API will enable collaborative real-time drawing, shape and diagram creation, text annotations, image uploads, multi-user cursors, version history, and export capabilities. These features will provide teams with a complete visual collaboration environment integrated directly into the BotServer platform. - -## Planned Endpoints - -### Whiteboard Management - -The whiteboard management endpoints handle the lifecycle of whiteboard instances. Creating a whiteboard uses `POST /api/v1/whiteboards`, while retrieving whiteboard details uses `GET /api/v1/whiteboards/{board_id}`. Updates are handled through `PATCH /api/v1/whiteboards/{board_id}`, deletion through `DELETE /api/v1/whiteboards/{board_id}`, and listing all whiteboards through `GET /api/v1/whiteboards`. - -### Collaboration - -Real-time collaboration is managed through several endpoints. Users join sessions via `POST /api/v1/whiteboards/{board_id}/join` and leave via `POST /api/v1/whiteboards/{board_id}/leave`. The current participant list is available at `GET /api/v1/whiteboards/{board_id}/participants`. For real-time updates, a WebSocket connection is established at `WebSocket /api/v1/whiteboards/{board_id}/ws`. - -### Content Operations - -Content manipulation endpoints allow adding elements with `POST /api/v1/whiteboards/{board_id}/elements`, updating them with `PATCH /api/v1/whiteboards/{board_id}/elements/{element_id}`, and removing them with `DELETE /api/v1/whiteboards/{board_id}/elements/{element_id}`. The entire board can be cleared using `POST /api/v1/whiteboards/{board_id}/clear`. - -### Export - -Export functionality supports multiple formats. PNG export is available at `GET /api/v1/whiteboards/{board_id}/export/png`, SVG at `GET /api/v1/whiteboards/{board_id}/export/svg`, and PDF at `GET /api/v1/whiteboards/{board_id}/export/pdf`. - -## Planned Integration with BASIC - -When implemented, whiteboard features will be accessible via BASIC keywords: - -```basic -' Create whiteboard (not yet available) -board_id = CREATE WHITEBOARD "Architecture Diagram" -SHARE WHITEBOARD board_id, ["user123", "user456"] - -' Add content (not yet available) -ADD TO WHITEBOARD board_id, "rectangle", {x: 100, y: 100, width: 200, height: 100} -ADD TO WHITEBOARD board_id, "text", {x: 150, y: 150, text: "Component A"} - -' Export whiteboard (not yet available) -image_url = EXPORT WHITEBOARD board_id, "png" -SEND FILE image_url -``` - -## Planned Data Models - -### Whiteboard - -```json -{ - "board_id": "wb_123", - "name": "Architecture Diagram", - "owner": "user123", - "created_at": "2024-01-15T10:00:00Z", - "updated_at": "2024-01-15T14:30:00Z", - "settings": { - "background": "grid", - "canvas_width": 1920, - "canvas_height": 1080, - "allow_anonymous": false, - "max_participants": 50 - }, - "participants": [ - { - "user_id": "user123", - "role": "owner", - "cursor_position": {"x": 500, "y": 300} - } - ], - "element_count": 42 -} -``` - -### Drawing Element - -```json -{ - "element_id": "elem_456", - "board_id": "wb_123", - "type": "rectangle", - "properties": { - "x": 100, - "y": 100, - "width": 200, - "height": 100, - "fill": "#ffffff", - "stroke": "#000000", - "stroke_width": 2 - }, - "created_by": "user123", - "created_at": "2024-01-15T10:05:00Z", - "z_index": 1 -} -``` - -## Planned Features Detail - -### Drawing Tools - -The drawing tools will include basic shapes such as rectangles, circles, triangles, lines, and arrows. Freehand drawing will support pen, pencil, and highlighter modes. Text tools will provide labels, sticky notes, and comments. Smart connectors will automatically route between shapes, and templates will offer pre-built layouts for flowcharts, mind maps, and wireframes. - -### Collaboration Features - -Real-time collaboration will include cursor tracking so users can see where others are working, presence indicators showing who is currently viewing the board, and change notifications for updates made by collaborators. A commenting system will enable discussions on specific elements. Version control will track the history of changes, and conflict resolution will handle simultaneous edits gracefully. - -### Advanced Features - -Advanced functionality will support layers for organizing complex diagrams, grouping to manipulate multiple elements together, and alignment and distribution tools for precise positioning. Copy and paste will work between boards, undo and redo history will allow reverting changes, and keyboard shortcuts will speed up common operations. - -## Implementation Considerations - -When implemented, the Whiteboard API will use WebSocket for real-time collaboration and implement CRDT (Conflict-free Replicated Data Types) for conflict-free editing. Data will be stored in PostgreSQL with JSON columns for flexibility. The cache component will improve performance for frequently accessed boards. SVG will serve as the primary format for rendering, and the system will support touch devices and stylus input. Access controls and permissions will ensure proper security. - -## Alternative Solutions - -Until the Whiteboard API is implemented, several alternatives are available. - -External whiteboard services can be integrated, including Miro API, embedded Excalidraw, draw.io (diagrams.net), or Microsoft Whiteboard. - -For simple drawing storage, you can store drawing data as JSON in bot memory: - -```basic -' Store drawing as JSON -drawing = { - "shapes": [ - {"type": "rect", "x": 10, "y": 10, "w": 100, "h": 50} - ] -} -SET BOT MEMORY "drawing_001", JSON_STRINGIFY(drawing) -``` - -Image-based collaboration offers another approach, allowing you to upload and annotate images, use existing image editing APIs, or share screenshots with markup. - -## Future Technology Stack - -The planned implementation will use the Canvas API or SVG for rendering, WebSocket for real-time synchronization, Y.js or OT.js for collaborative editing, Fabric.js for canvas manipulation, PostgreSQL for data persistence, cache for real-time state management, and Sharp for image processing. - -## Workaround Example - -Until the Whiteboard API is available, you can implement basic diagram storage: - -```basic -' Simple diagram system using text -FUNCTION CreateDiagram(name) - diagram = { - "name": name, - "elements": [], - "connections": [] - } - SET BOT MEMORY "diagram_" + name, JSON_STRINGIFY(diagram) - RETURN name -END FUNCTION - -FUNCTION AddElement(diagram_name, element_type, label) - diagram_key = "diagram_" + diagram_name - diagram_json = GET BOT MEMORY diagram_key - diagram = JSON_PARSE(diagram_json) - - element = { - "id": GENERATE_ID(), - "type": element_type, - "label": label - } - - diagram.elements = APPEND(diagram.elements, element) - SET BOT MEMORY diagram_key, JSON_STRINGIFY(diagram) - RETURN element.id -END FUNCTION - -FUNCTION GenerateAsciiDiagram(diagram_name) - diagram_json = GET BOT MEMORY "diagram_" + diagram_name - diagram = JSON_PARSE(diagram_json) - - output = "Diagram: " + diagram.name + "\n\n" - - FOR EACH element IN diagram.elements - IF element.type = "box" THEN - output = output + "[" + element.label + "]\n" - ELSE IF element.type = "circle" THEN - output = output + "(" + element.label + ")\n" - END IF - NEXT - - RETURN output -END FUNCTION -``` - -## Use Cases - -### Technical Planning - -Technical teams can use the Whiteboard API for architecture diagrams, database schemas, network topology visualization, UML diagrams, and flowcharts that document system design and processes. - -### Business Collaboration - -Business users will benefit from mind mapping for brainstorming, process flow documentation, organizational charts, collaborative brainstorming sessions, and project planning visualizations. - -### Education - -Educational applications include teaching illustrations, student collaboration on group projects, visual problem solving, and graphical explanations of complex concepts. - -## Integration Points - -When available, the Whiteboard API will integrate with the [Storage API](./storage-api.md) for saving whiteboard data, the [Calls API](./calls-api.md) for sharing during video calls, [Document Processing](./document-processing.md) for import and export capabilities, and the [Notifications API](./notifications-api.md) for collaboration alerts. - -## Status Updates - -Check the [GitHub repository](https://github.com/generalbots/botserver) for updates on Whiteboard API implementation status. - -For immediate visual collaboration needs, consider embedding existing solutions like Excalidraw or Miro rather than waiting for the native implementation. \ No newline at end of file diff --git a/docs/src/chapter-11-features/README.md b/docs/src/chapter-11-features/README.md deleted file mode 100644 index 4f712007..00000000 --- a/docs/src/chapter-11-features/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Chapter 11: Feature Reference - -Quick reference for all General Bots capabilities. - -## Feature Categories - -| Category | Key Features | -|----------|--------------| -| **Core** | Chat, dialogs, sessions, automation | -| **AI/LLM** | Model integration, knowledge base, context | -| **Channels** | Web, WhatsApp, Teams, Email, SMS | -| **Productivity** | Calendar, tasks, drive, mail, meet | -| **Data** | CRUD, aggregations, file operations | -| **HTTP** | REST, GraphQL, SOAP, webhooks | - -## Editions - -| Edition | Use Case | -|---------|----------| -| Minimal | Embedded, IoT | -| Core | General business | -| Standard | Professional teams | -| Enterprise | Large organizations | - -## Chapter Contents - -- [Feature Editions](./editions.md) - Edition comparison -- [Core Features](./core-features.md) - Platform fundamentals -- [Conversation Management](./conversation.md) - Dialog flows -- [AI and LLM](./ai-llm.md) - AI integration -- [Knowledge Base](./knowledge-base.md) - RAG patterns -- [Automation](./automation.md) - Scheduled tasks -- [Email Integration](./email.md) - Email features -- [Storage and Data](./storage.md) - Data persistence -- [Multi-Channel Support](./channels.md) - Communication channels -- [Hybrid Search](./hybrid-search.md) - RAG 2.0 -- [Memory Management](./memory-management.md) - Context handling -- [Multi-Agent](./multi-agent-orchestration.md) - Agent coordination - -## See Also - -- [BASIC Reference](../chapter-06-gbdialog/README.md) - Scripting -- [Configuration](../chapter-08-config/README.md) - Settings \ No newline at end of file diff --git a/docs/src/chapter-11-features/ai-llm.md b/docs/src/chapter-11-features/ai-llm.md deleted file mode 100644 index 0373365d..00000000 --- a/docs/src/chapter-11-features/ai-llm.md +++ /dev/null @@ -1,206 +0,0 @@ -# AI and LLM - -BotServer integrates with Large Language Models to provide intelligent conversational capabilities and natural language understanding. This integration forms the core of what makes General Bots conversations feel natural and contextually aware. - - -## Overview - -The LLM integration in BotServer enables sophisticated conversational experiences. Natural language conversations flow smoothly without rigid command structures. Responses are context-aware, drawing on conversation history and loaded knowledge bases. The system automatically discovers and invokes tools when they would help answer user questions. Document understanding allows bots to read and reason about uploaded files. Text generation and summarization capabilities support content creation and information distillation. - - -## LLM Providers - -### OpenAI - -OpenAI serves as the primary LLM provider with support for multiple model tiers. GPT-3.5 Turbo provides fast, cost-effective responses for straightforward conversations. GPT-4 delivers more nuanced understanding for complex queries. GPT-4 Turbo offers an optimal balance of capability and speed. Custom fine-tuned models can be used when you have specialized requirements. - -Configuration requires setting your API key and selecting a model: - -``` -OPENAI_API_KEY=your-api-key -LLM_MODEL=gpt-4 -``` - -### Local Models - -For privacy-sensitive deployments or cost control, BotServer supports self-hosted models. Llama.cpp compatible servers provide open-source model hosting. Custom inference endpoints allow integration with any API-compatible service. Privacy-preserving deployments keep all data on-premises without external API calls. - -Configuration for local models specifies the provider type and endpoint: - -``` -LLM_PROVIDER=local -LLM_ENDPOINT=http://localhost:8081 -``` - - -## The LLM Keyword - -The LLM keyword provides direct access to language model capabilities within BASIC scripts. Usage patterns differ between background processing and interactive conversations. - -### Background Processing - -For scheduled tasks and background jobs that do not interact directly with users, the LLM keyword generates content that can be stored for later use. - -```basic -' For background/scheduled tasks only - not for interactive conversations -summary = LLM "Explain quantum computing in simple terms" -SET BOT MEMORY "quantum_explanation", summary -``` - -### Document Summarization - -Scheduled tasks can process documents and generate summaries available to all users. - -```basic -' Scheduled task to generate summaries for all users -document = GET "knowledge/policy.pdf" -summary = LLM "Summarize this document: " + document -SET BOT MEMORY "policy_summary", summary -``` - -### Context-Aware Conversations - -For interactive conversations, use SET CONTEXT to provide information that the System AI incorporates automatically when responding. This approach lets the AI generate natural responses rather than scripted outputs. - -```basic -' For interactive conversations - use SET CONTEXT, not LLM -TALK "What's your question?" -question = HEAR -context = GET BOT MEMORY "knowledge" -SET CONTEXT "background", context -TALK "Based on our knowledge base, here's what I can tell you..." -' System AI automatically uses the context when responding -``` - - -## LLM Provider Implementation - -The provider architecture lives in the `src/llm/` directory with a modular design. The `mod.rs` file defines the provider trait and factory for instantiating providers. The `openai.rs` file implements the OpenAI provider with all API operations. The `local.rs` file provides support for local model servers. - -### Provider Trait - -All LLM providers implement a common trait ensuring consistent behavior. The generate method produces text completions from prompts. The generate_stream method returns tokens incrementally for real-time display. The get_embedding method creates vector representations for semantic search. The count_tokens method estimates token usage before making API calls. - - -## Context Management - -### Context Window - -Managing the limited context window requires careful attention to what information reaches the model. Automatic truncation removes older content when approaching limits. Context compaction summarizes extensive histories into shorter representations. Relevance filtering prioritizes information most likely to help with the current query. History summarization condenses long conversations into essential points. - -### Context Sources - -The context provided to the LLM comes from multiple sources that combine to create informed responses. Conversation history provides recent messages for continuity. Knowledge base chunks supply relevant document excerpts. Bot memory contributes persistent context that applies across conversations. Tool definitions tell the model what functions it can invoke. User profile information enables personalization based on known preferences. - - -## Prompt Engineering - -### System Prompts - -System prompts establish the bot's personality and capabilities. These are typically configured in bot memory and loaded into context at the start of conversations. - -```basic -system_prompt = GET BOT MEMORY "system_prompt" -SET CONTEXT "system", system_prompt -``` - -### Dynamic Prompts - -Building prompts programmatically allows context to reflect current conditions. Variables set in context become available to the System AI for generating responses. - -```basic -' For interactive conversations - use SET CONTEXT -SET CONTEXT "user_name", user_name -SET CONTEXT "current_date", NOW() -' System AI automatically incorporates this context -``` - - -## Streaming Responses - -### WebSocket Streaming - -Real-time token streaming creates a responsive user experience. As the LLM generates tokens, each token is sent immediately via WebSocket to the connected client. The UI updates progressively as tokens arrive, showing the response as it forms. The complete response is assembled on the client side once generation finishes. - -### Stream Control - -Several controls manage the streaming process. Users can start and stop generation as needed. Long responses can be cancelled if they are not useful. Timeout protection prevents indefinitely hanging connections. Error recovery handles network interruptions gracefully by resuming or restarting generation. - - -## Embeddings - -### Vector Generation - -Creating embeddings transforms text into vectors for semantic search. The embedding process converts natural language into high-dimensional numerical representations that capture meaning. - -### Embedding Models - -Different embedding models serve different needs. OpenAI's text-embedding-ada-002 provides high-quality embeddings through their API. Local deployments can use sentence transformers for on-premises embedding generation. Custom models can be configured when you have specialized embedding requirements. - - -## Token Management - -### Token Counting - -Estimating token usage before making API calls helps with cost control and context management. Token counting uses the same tokenizer as the target model to produce accurate estimates. - -### Token Limits - -Several factors constrain token usage. Each model has specific limits on total tokens per request. Context window constraints determine how much history and knowledge base content fits. Rate limiting prevents exceeding API quotas. Cost management tracks token usage against budgets. - - -## Error Handling - -### Common Errors - -Several error conditions occur frequently when working with LLMs. Invalid API keys prevent authentication with the provider. Rate limit exceeded errors indicate too many requests in a time window. Context too long errors mean the prompt exceeds the model's maximum. Model unavailable errors happen during provider outages. Network timeouts occur when connections take too long. - -### Fallback Strategies - -Robust error handling employs multiple fallback strategies. Retry with exponential backoff handles transient failures. Switching to a backup model maintains service when the primary is unavailable. Reducing context size can resolve context length errors. Caching responses reduces API calls and provides fallback content. Returning graceful errors keeps users informed when recovery is not possible. - - -## Performance Optimization - -### Caching - -Response caching dramatically improves performance for repeated queries. Semantic caching identifies similar questions and returns cached responses without API calls. Cache invalidation strategies ensure responses remain fresh as knowledge bases update. Cache warming pre-generates responses for common questions during off-peak times. - -### Batching - -Batching multiple requests improves throughput and reduces per-request overhead. Embedding generation particularly benefits from batching when processing many documents. Rate limit management becomes simpler with controlled batch submission. - -### Connection Pooling - -Connection pooling to LLM providers reduces latency from connection establishment. Keep-alive connections persist across requests. Pool sizing balances resource usage against responsiveness. - - -## Model Selection - -Choosing the right model involves balancing several factors. Capability requirements determine the minimum model sophistication needed. Response latency requirements favor faster models for interactive use. Cost constraints may push toward more economical model tiers. Privacy requirements might mandate local models over cloud APIs. - -### Model Comparison - -GPT-3.5 Turbo offers the fastest responses at the lowest cost, suitable for straightforward questions. GPT-4 provides superior reasoning for complex queries at higher cost and latency. Local models like Llama variants offer privacy and cost predictability with varying capability levels. Specialized models may excel at particular domains like code or medical content. - - -## Integration with Tools - -LLMs in BotServer work closely with the tool system. The model receives tool definitions describing available functions. When a user request would benefit from tool use, the model generates a tool call. BotServer executes the tool and returns results to the model. The model incorporates tool results into its final response. - -This integration enables bots to take actions beyond conversation, such as querying databases, sending emails, or calling external APIs, all orchestrated naturally through conversation. - - -## Best Practices - -Effective LLM usage follows several guidelines. Keep system prompts focused and specific rather than trying to cover every scenario. Use SET CONTEXT for interactive conversations rather than generating responses directly with LLM calls. Load relevant knowledge bases before conversations to improve response quality. Monitor token usage to manage costs. Test responses across different query types to ensure consistent quality. - - -## Debugging and Monitoring - -Debugging LLM interactions requires visibility into prompts and responses. Enable verbose logging during development to see full API exchanges. Monitor response quality metrics over time. Track token usage and costs per conversation. Review conversation logs to identify improvement opportunities. - - -## See Also - -The Context Configuration chapter explains context window management in detail. The LLM Configuration chapter covers all configuration options. The Tool Definition chapter describes creating tools the LLM can invoke. The Knowledge Base chapter explains how documents integrate with LLM context. \ No newline at end of file diff --git a/docs/src/chapter-11-features/automation.md b/docs/src/chapter-11-features/automation.md deleted file mode 100644 index 3ff4e1b6..00000000 --- a/docs/src/chapter-11-features/automation.md +++ /dev/null @@ -1,111 +0,0 @@ -# Automation - -This chapter explains how BotServer enables bots to perform scheduled and event-driven tasks without requiring direct user interaction. Through automation capabilities, bots can proactively maintain content, process data, and respond to system events, transforming them from reactive assistants into active participants in organizational workflows. - -## Automation Fundamentals - -BotServer implements automation through two complementary mechanisms. The SET SCHEDULE keyword enables cron-based task scheduling, allowing scripts to execute at predetermined times. Event triggers through the ON keyword enable scripts to respond to database changes and system events. Together, these mechanisms support a wide range of automation scenarios from simple periodic tasks to complex event-driven workflows. - -Understanding when to use automation is as important as understanding how. Automated tasks run without an active user session, which means they cannot directly communicate with users through TALK statements. Instead, automated scripts typically gather and process information, storing results in bot memory where users can access it during their next interaction. - -## Scheduling Tasks with SET SCHEDULE - -The SET SCHEDULE keyword registers a script for periodic execution using standard cron expressions. When the BASIC compiler encounters this keyword, it extracts the schedule specification and creates an entry in the system_automations table. A background service monitors this table and executes scripts when their scheduled times arrive. - -Cron expressions follow the standard Unix format with five fields representing minutes, hours, day of month, month, and day of week. The expression `0 9 * * *` means "at minute 0 of hour 9, every day of every month, regardless of day of week"—in other words, daily at 9:00 AM. The expression `*/30 * * * *` means "every 30 minutes" by using the step syntax. More complex patterns like `0 9 * * 1-5` specify "weekdays at 9 AM" by restricting the day of week field to Monday through Friday. - -Scheduled scripts execute with full bot context and permissions, but without an associated user session. This means they can access bot memory, call external APIs, read and write files, and perform data processing. However, they cannot use TALK to send messages since there's no user to receive them. Results should be stored in bot memory for later retrieval or sent through other channels like email. - -## Practical Scheduling Examples - -A daily report generation script illustrates common automation patterns. The script specifies its schedule, retrieves data from the previous day, processes it using LLM analysis, and stores the result in bot memory. When users later ask about the daily report, the bot can retrieve and present this pre-computed summary without delay. - -Content update automation keeps information fresh without manual intervention. A news aggregation script might run every six hours, fetching latest headlines, summarizing them, and caching the result. Users interacting with the bot receive current information even if nobody has explicitly updated the content. - -Maintenance tasks handle housekeeping that shouldn't require human attention. Cleanup scripts can run during low-activity periods to archive old data, remove temporary files, or perform consistency checks. These tasks keep the system healthy without consuming resources during peak usage times. - -Data synchronization scripts bridge external systems with bot knowledge. A script might periodically fetch updates from a CRM, inventory system, or other business application, ensuring the bot's responses reflect current organizational reality. - -## Event-Driven Automation - -The ON keyword creates triggers that fire when specific events occur rather than at scheduled times. Currently, the system supports database event triggers that respond to table modifications. When the specified event occurs, the associated code block executes. - -Event triggers complement scheduled tasks by enabling immediate response to changes rather than waiting for the next scheduled run. While a scheduled task might check for new registrations hourly, an event trigger fires immediately when a registration occurs, enabling real-time automation workflows. - -The system stores triggers in the same system_automations table as scheduled tasks, distinguished by their trigger kind. Each trigger specifies its target (the table or resource being monitored), parameters controlling its behavior, and an activation flag allowing temporary disabling without deletion. - -## The System Automations Table - -The system_automations table serves as the central registry for all automation rules. Each record contains a unique identifier, the bot that owns the automation, the kind of trigger (scheduled or event-driven), the cron expression for scheduled tasks, parameters such as script names, an active flag, and a timestamp tracking the last execution. - -This centralized storage allows the background scheduler to efficiently query upcoming tasks across all bots. It also enables administrative monitoring of automation activity and troubleshooting of failed executions. - -## Automation Lifecycle Management - -Understanding how automations are created, executed, modified, and removed helps administrators manage bot deployments effectively. - -During script compilation, the preprocessor detects SET SCHEDULE statements and extracts their cron expressions. The system creates or updates corresponding entries in the system_automations table. If a script previously had a schedule that was removed, the old automation entry is deleted. - -When execution time arrives, the scheduler loads the bot's context, executes the BASIC script, updates the last_triggered timestamp, and logs the execution result. Any errors during execution are captured and logged but don't affect other scheduled tasks. - -Modifying a schedule requires only changing the SET SCHEDULE line in the script. The next compilation updates the database entry automatically. This approach keeps schedule definitions with their associated code rather than requiring separate configuration management. - -Deleting a bot cascades to remove all its automations, preventing orphaned schedules that would fail at execution time. - -## Best Practices for Automation - -Effective automation requires thoughtful design decisions. Scheduling frequency should match actual needs—running a task every minute when hourly would suffice wastes resources and can mask problems. Consider what would happen if a task takes longer than its scheduling interval, as overlapping executions can cause unexpected behavior. - -Error handling in automated scripts is particularly important because no user is present to observe failures. Scripts should catch exceptions, log meaningful error messages, and degrade gracefully when dependencies are unavailable. Consider storing error states in bot memory so users can be informed of issues during their next interaction. - -Scripts should be tested manually before enabling scheduling. Running a script interactively verifies that it works correctly and helps identify issues that might not be apparent from logs alone. - -Bot memory serves as the bridge between automated tasks and user interactions. Automated scripts store their results in bot memory, making that information available to all users. This pattern works well for information that benefits from pre-computation, like summarized reports or aggregated statistics. - -External credentials should never be hardcoded in scripts. Use bot memory to store API keys and other secrets, retrieving them at runtime. This practice improves security and simplifies credential rotation. - -## Understanding Limitations - -Several constraints affect automation design decisions. The minimum scheduling granularity is one minute, as the cron format doesn't support sub-minute precision. Tasks requiring more frequent execution need alternative approaches. - -Each scheduled execution has timeout limits to prevent runaway tasks from consuming resources indefinitely. Long-running processes should be designed to complete within these limits or broken into smaller pieces. - -The system doesn't provide automatic retry on failure. If a scheduled task fails, it simply waits for the next scheduled time. Scripts needing retry behavior must implement it internally. - -Only one instance of a scheduled script runs at a time. If execution takes longer than the scheduling interval, subsequent invocations are skipped rather than queued. This prevents resource exhaustion but means some scheduled times may be missed. - -There's no dependency management between scheduled tasks. If one task must complete before another begins, scripts must coordinate through bot memory or other synchronization mechanisms. - -## Monitoring Automated Tasks - -Observing automation behavior helps identify problems and optimize performance. Active schedules can be queried directly from the system_automations table, filtered by bot and trigger kind. The last_triggered timestamp shows when each automation last executed successfully. - -Execution logging captures both successful runs and failures at appropriate log levels. Monitoring these logs reveals patterns like consistently slow executions or recurring errors that might not be apparent from individual runs. - -Debug logging at lower levels captures schedule changes during compilation, helping trace unexpected automation behavior to its source. Enabling debug logging temporarily can help diagnose why a schedule isn't executing as expected. - -## Debugging Automation Issues - -When automated tasks don't behave as expected, systematic investigation identifies the cause. Common issues include invalid cron expressions that never match, scripts that work interactively but fail without a user session, external resources that are unavailable when the script runs, and permission issues that only manifest in the automation context. - -Verifying the cron expression syntax ensures the schedule means what you intend. Online cron expression validators can help confirm that expressions match expected execution times. - -Testing scripts manually with explicit handling for the missing user session helps identify code that incorrectly assumes user context. Any TALK statements will fail in automated context, and scripts must work correctly without user input. - -Checking external resource availability at scheduled times reveals dependencies that might not be available around the clock. Business APIs often have maintenance windows, and network conditions vary throughout the day. - -Reviewing permissions ensures the bot has access to all resources the automated script needs. Permissions that work for interactive users might not apply to automated execution contexts. - -## Security Considerations - -Automated tasks execute with the bot's full permissions, making them powerful but requiring careful design. Scripts can access any data the bot can access, call any API the bot is authorized to use, and store results in any location the bot can write. - -This power means automated scripts should be reviewed carefully before deployment. Malicious or buggy automation could exfiltrate data, overwhelm external services, or fill storage with garbage. Limiting automation privileges isn't possible in the current system, so careful script review is the primary safeguard. - -Rate limiting applies to automated tasks just as it does to interactive use. Aggressive scheduling that exceeds API limits will be throttled, potentially causing tasks to fail or take longer than expected. - -Monitoring for runaway automation helps catch scripts that behave differently than expected. Unusual resource consumption, excessive API calls, or unexpected storage growth might indicate automation problems requiring intervention. - -## Summary - -BotServer's automation capabilities transform bots from reactive assistants into proactive system participants. Through SET SCHEDULE and event triggers, bots can maintain fresh content, process data regularly, and respond to system events without user interaction. Understanding the automation lifecycle, limitations, and best practices enables effective use of these powerful capabilities while avoiding common pitfalls. Automation extends bot value by handling routine tasks automatically, freeing users to focus on work that requires human judgment. \ No newline at end of file diff --git a/docs/src/chapter-11-features/channels.md b/docs/src/chapter-11-features/channels.md deleted file mode 100644 index 196561cf..00000000 --- a/docs/src/chapter-11-features/channels.md +++ /dev/null @@ -1,89 +0,0 @@ -# Multi-Channel Support - -This chapter describes how BotServer enables bots to communicate with users across different platforms through its flexible multi-channel architecture. The design ensures that conversation logic remains consistent regardless of how users choose to interact, while still taking advantage of each channel's unique capabilities. - -## Architectural Foundation - -BotServer abstracts communication methods through a channel adapter pattern that separates bot logic from platform-specific details. When a user sends a message, it flows from their chosen platform through a channel adapter that converts the platform-specific format into a common message structure. The bot processes this message, generates a response, and the adapter converts it back to the appropriate format for delivery. - -This abstraction provides significant benefits for bot development. The same BASIC scripts work across all supported channels without modification. Conversation state persists even when users switch between platforms. New channels can be added without changing existing bot logic. - -The primary channel is the web interface, which provides the richest interaction capabilities. WebSocket connections enable real-time messaging with streaming responses. Additional channels extend reach to users on their preferred platforms while maintaining consistent conversation experiences. - -## The Web Channel - -The web channel serves as the reference implementation and primary interaction method for most deployments. It leverages HTTP for initial page loads and WebSocket connections for real-time bidirectional communication. - -Users interacting through the web channel benefit from rich formatting through Markdown support, clickable suggestion buttons that simplify common interactions, file upload and attachment capabilities, inline image display, typing indicators that show when the bot is processing, and theme customization that allows organizations to brand the interface. - -The implementation handles WebSocket connection management, maintaining long-lived connections with heartbeat mechanisms to detect disconnections. When a connection drops, clients can automatically reconnect and resume their session without losing conversation context. - -## Voice Interaction - -When the voice feature is enabled, BotServer supports spoken interaction through speech-to-text and text-to-speech processing. Voice conversations follow a continuous flow where the system listens for user speech, converts it to text, processes it through the same BASIC scripts used for text channels, and converts the response back to speech for playback. - -This channel requires integration with speech services and is optional due to its additional infrastructure requirements. Organizations that enable voice interaction can serve users who prefer speaking to typing or who are in situations where hands-free operation is beneficial. - -## Unified Session Management - -All channels share a common session system, which is essential for maintaining coherent conversations across platform switches. When a user first interacts with a bot, the system creates a session that stores conversation context, user preferences, and any data accumulated during the interaction. - -This session persists independently of the channel being used. A user could begin a conversation on the web interface from their desktop, continue it later on a mobile device, and the bot would have full context of previous exchanges. The session stores user identification information linked through authentication, ensuring that cross-channel continuity works correctly for logged-in users. - -Session data includes conversation history, variables set during script execution, user preferences such as language settings, and references to any files or documents shared during the conversation. - -## Message and Response Structures - -The common message format bridges platform-specific protocols to the unified bot processing system. Each message carries the text content provided by the user, identifiers linking it to the user and session, the channel type indicating its origin, and a metadata field for channel-specific information that might be relevant to processing. - -Responses follow a structured format that channel adapters interpret appropriately. Beyond the main content text, responses can include suggestion arrays that channels supporting quick replies render as buttons, a message type indicator distinguishing text from cards or media, streaming tokens for channels that support progressive response display, and completion flags indicating whether the response is final. - -Channel adapters examine these response components and render them appropriately for their platform. A suggestion might become a clickable button on the web, a numbered list in a text-only channel, or ignored entirely in voice where such interaction patterns don't apply. - -## Adaptive Bot Behavior - -While the goal is channel-agnostic scripts, situations arise where bots benefit from knowing their communication context. Scripts can query the current channel and adapt their behavior accordingly, offering voice-appropriate prompts when speaking to users or visual elements when they're available. - -Feature detection allows scripts to check whether the current channel supports specific capabilities before attempting to use them. Rather than checking the channel type directly, checking for feature support makes scripts more resilient to future channel additions that might have different capability combinations. - -This adaptive capability should be used sparingly. Most bot logic should remain channel-agnostic, with adaptations limited to presentation concerns rather than core functionality. - -## WebSocket Communication Protocol - -The WebSocket protocol defines how clients and servers exchange messages over persistent connections. Clients initiate connections to the `/ws` endpoint, where the server creates or retrieves their session and establishes the bidirectional channel. - -Messages from clients to the server carry a type field indicating the message kind, the content being sent, and the session identifier linking the message to an existing conversation. The server responds with structured messages including the response content, any suggestions to display, and flags indicating whether the response is complete or if more content will follow for streaming scenarios. - -The protocol includes heartbeat messages to maintain connection liveness across network infrastructure that might otherwise terminate idle connections. Both client and server implementations should handle reconnection gracefully, allowing conversations to continue after temporary network interruptions. - -## Expanding Channel Support - -The architecture anticipates integration with additional platforms including WhatsApp Business API, Microsoft Teams, Slack, Telegram, Discord, and SMS gateways. While these channels aren't implemented in the current version, the adapter pattern provides a clear path for adding them. - -Implementing a new channel involves creating an adapter that implements the standard interface for sending and receiving messages, handling the platform's specific authentication and webhook requirements, mapping between the platform's message format and the common structure, registering supported features accurately so scripts can adapt appropriately, and managing any platform-specific rate limits or constraints. - -The separation of concerns in the adapter pattern means that new channels don't require changes to bot logic, session management, or the BASIC execution environment. They plug into the existing infrastructure at well-defined integration points. - -## Practical Considerations - -Several factors influence channel selection and implementation for production deployments. Feature availability varies significantly between channels, with web providing the richest interaction while text-only channels offer broader reach. Rich formatting and media support depend entirely on the destination platform's capabilities. - -Network reliability affects real-time channels differently than store-and-forward systems like email or SMS. WebSocket connections require stable networks, while messaging platforms handle intermittent connectivity through their own infrastructure. - -Authentication requirements differ between channels. The web channel integrates with the platform's standard OAuth flow, while messaging platforms typically use their own identity systems that must be mapped to General Bots users. - -Rate limiting applies per channel and must be respected to maintain good standing with platform providers. Automated messages face stricter limits than user-initiated conversations on most platforms. - -## Development Guidelines - -Effective multi-channel bot development follows several principles. Writing channel-agnostic scripts as the default approach maximizes code reuse and simplifies maintenance. Using universal keywords like TALK and HEAR ensures scripts work everywhere without modification. - -Testing across channels validates that the user experience remains coherent despite platform differences. What works well on web might need adjustment for voice or text-only channels. Identifying these differences during development prevents surprises in production. - -Preserving session state carefully ensures that cross-channel continuity works correctly. Scripts should store important context in session variables rather than relying on channel-specific features that might not translate. - -Monitoring channel metrics helps identify performance issues or user experience problems specific to particular platforms. Response times, error rates, and user satisfaction can vary significantly between channels. - -## Summary - -BotServer's multi-channel architecture enables bots to reach users wherever they prefer to communicate while maintaining consistent conversation logic and state. The channel adapter pattern isolates platform-specific concerns from bot development, allowing the same scripts to work across current channels and future integrations. This design philosophy prioritizes developer productivity and user experience across an expanding communication landscape. \ No newline at end of file diff --git a/docs/src/chapter-11-features/conversation.md b/docs/src/chapter-11-features/conversation.md deleted file mode 100644 index 8e5f8c10..00000000 --- a/docs/src/chapter-11-features/conversation.md +++ /dev/null @@ -1,93 +0,0 @@ -# Conversation Management - -This chapter explores how BotServer manages conversations through sessions, message history, and context tracking. Understanding these mechanisms helps you build bots that maintain coherent, contextual interactions across multiple turns and sessions. - -## The Conversation Lifecycle - -Every conversation in BotServer follows a well-defined lifecycle that begins when a user first connects and continues until the session expires or ends explicitly. When a user interacts with a bot, the system creates a session that serves as the container for all conversation state, including message history, user preferences, and any variables set during the interaction. - -Sessions persist across individual messages, allowing conversations to span multiple interactions. A user might ask a question, receive a response, and return hours later to continue the same conversation thread. The system maintains this continuity by storing session data in PostgreSQL for durability while caching active sessions in the cache layer for fast access. - -The session contains a unique identifier, a reference to the associated user (or an anonymous identifier), the bot being interacted with, creation and expiration timestamps, and all accumulated conversation state. This comprehensive tracking enables sophisticated multi-turn interactions where the bot remembers previous exchanges and builds upon them. - -## Message History and Persistence - -Every message exchanged during a conversation is recorded in the message history table, creating a permanent record of the interaction. Each entry captures the session identifier linking it to the conversation, the user and bot involved, the actual message content, an indicator of whether the message came from the user or the bot, and a precise timestamp. - -The system distinguishes between several message types that serve different purposes. User messages represent input from the human participant. Bot responses contain the generated replies. System messages convey status updates or notifications. Tool outputs capture results from executed tools. This categorization helps with both display formatting and analysis. - -Message history serves multiple purposes beyond simple record-keeping. The conversation context sent to the language model draws from recent history, enabling contextual responses. Analytics systems process history to understand usage patterns and conversation quality. Compliance requirements often mandate retention of interaction records, which the history system satisfies. - -## Context Assembly and Management - -Context management represents one of the most sophisticated aspects of conversation handling. When generating a response, the system must assemble relevant information from multiple sources into a coherent context that guides the language model's output. - -The context assembly process draws from several layers. System context includes the bot's configuration and base prompts that establish personality and capabilities. Conversation context incorporates recent message history to maintain coherence. Knowledge context adds relevant documents retrieved from active knowledge bases. User context includes preferences and state specific to the current user. Tool context describes available tools the model can invoke. - -Because language models have limited context windows, the system must manage what information to include. Automatic truncation removes older messages when the context grows too large, preserving the most recent and relevant exchanges. For very long conversations, summarization compresses earlier history into concise summaries that capture essential information without consuming excessive tokens. - -Scripts can manipulate context directly through dedicated keywords. Setting context adds specific information that should influence responses. Clearing context removes information that is no longer relevant. These operations give developers fine-grained control over what the model knows during generation. - -## Multi-Turn Interaction Patterns - -Conversations rarely consist of single isolated exchanges. Users ask follow-up questions, refine requests, and reference earlier parts of the conversation. BotServer's architecture specifically supports these multi-turn patterns through careful context management and entity tracking. - -When a user says "Book a meeting for tomorrow" followed by "Make it at 2 PM," the system must understand that "it" refers to the meeting mentioned in the previous turn. This reference resolution happens automatically through the included conversation history, which gives the model the context needed to interpret pronouns and implicit references correctly. - -Topic persistence allows conversations to maintain focus across multiple exchanges. If a user is discussing product returns, subsequent messages are interpreted in that context even when they don't explicitly mention returns. The accumulated history provides the framing that makes this natural understanding possible. - -Guided conversations implement multi-step flows where the bot collects information progressively. Rather than asking for all information at once, the bot might first ask for a name, then an email, then a preference. Each step builds on previous responses, with validation ensuring data quality before proceeding. - -## Session Recovery and Continuity - -Network interruptions, browser refreshes, and other disruptions shouldn't break conversation flow. BotServer implements robust session recovery that allows users to seamlessly continue where they left off. - -When a user reconnects, the session identifier validates their return. The system retrieves stored history and reconstructs the conversation context. The user can then continue as if no interruption occurred, with full access to previous exchanges and accumulated state. - -Error recovery extends beyond simple disconnections. If a response generation fails, the system preserves the last known good state. Graceful degradation provides meaningful feedback to users rather than cryptic errors. Automatic retry logic handles transient failures that resolve themselves. - -## Anonymous and Authenticated Conversations - -BotServer supports both authenticated users and anonymous visitors, with different handling for each case. Understanding these distinctions helps design appropriate conversation experiences. - -Anonymous sessions receive temporary identifiers that exist only for the duration of the session. Permissions are limited compared to authenticated users. Storage is typically short-term, with sessions expiring quickly after inactivity. These constraints reflect the reduced trust level for unidentified users. - -When an anonymous user authenticates, their session upgrades to a full user session. Accumulated history transfers to the persistent user record. Permissions expand to match the authenticated role. This seamless upgrade path encourages users to authenticate without losing conversation progress. - -## Real-Time Communication - -WebSocket connections provide the real-time communication channel for conversations. Unlike traditional HTTP request-response patterns, WebSockets maintain persistent bidirectional connections that enable instant message delivery in both directions. - -The WebSocket protocol supports several interaction patterns beyond basic message exchange. Streaming responses allow bots to send content progressively, displaying text as it generates rather than waiting for complete responses. Typing indicators let users know the bot is processing their request. Connection status updates inform users of connectivity changes. - -Messages follow a structured format with type identifiers, content payloads, and session references. The server processes incoming messages, routes them through the conversation engine, and pushes responses back through the same WebSocket connection. - -## Conversation Analytics - -Understanding how conversations perform helps improve bot effectiveness. BotServer tracks numerous metrics that reveal conversation patterns and quality indicators. - -Quantitative metrics include message counts, conversation lengths, response times, and tool usage frequency. These numbers identify basic patterns like peak usage times and average conversation depth. - -Qualitative analysis examines conversation content for sentiment, topics, intents, and entities. This deeper understanding reveals what users actually want from the bot, what frustrates them, and what succeeds. - -Performance metrics specifically track system behavior, including generation latency, error rates, and resource utilization during conversation processing. - -## Configuration and Tuning - -Several configuration parameters affect conversation behavior. Session timeout controls how long inactive sessions persist before expiring. History length limits how many messages the system retains in active memory. Context window size determines how much information reaches the language model. - -Retention policies govern long-term storage of conversation data. Message retention duration sets how long history persists before archival. Archive timing determines when conversations move to compressed storage. Anonymous retention specifically addresses the shorter lifetime appropriate for unidentified users. - -These settings balance resource usage against conversation quality and compliance requirements. Longer retention supports better context and audit trails but consumes more storage. Larger context windows improve response quality but increase processing costs. - -## Privacy and Compliance - -Conversation data represents sensitive information that requires careful handling. BotServer implements multiple safeguards to protect user privacy while meeting compliance requirements. - -Data retention policies ensure information doesn't persist longer than necessary. Compression and archival reduce storage costs while maintaining accessibility for compliance purposes. Clear deletion procedures support user rights to have their data removed. - -Access controls limit who can view conversation history. Users see their own conversations. Administrators may have audit access where compliance requires it. Appropriate logging tracks access to sensitive data. - -## Summary - -Conversation management in BotServer provides the foundation for meaningful bot interactions. Through careful session handling, comprehensive message history, sophisticated context assembly, and robust recovery mechanisms, the system enables conversations that feel natural and maintain coherence across multiple turns, sessions, and circumstances. Understanding these capabilities helps developers build bots that engage users effectively while respecting privacy and compliance requirements. \ No newline at end of file diff --git a/docs/src/chapter-11-features/core-features.md b/docs/src/chapter-11-features/core-features.md deleted file mode 100644 index 36632b68..00000000 --- a/docs/src/chapter-11-features/core-features.md +++ /dev/null @@ -1,118 +0,0 @@ -# Core Features - -Technical overview of BotServer capabilities. For the complete feature matrix, see [Feature Reference](./README.md). - -## Multi-Channel Communication - -| Channel | Protocol | Keywords | -|---------|----------|----------| -| Web Chat | WebSocket | `TALK`, `HEAR` | -| WhatsApp | Cloud API | `SEND`, `SEND TEMPLATE` | -| Email | SMTP/IMAP | `SEND MAIL` | -| Teams | Graph API | `SEND` | -| Voice | WebRTC | `PLAY`, `RECORD` | - -All channels share the same conversation logic through a unified abstraction. - -## Authentication & Sessions - -- **Password Hashing**: Argon2 with secure defaults -- **Session Tokens**: Cryptographically secure generation -- **Session Persistence**: Survives restarts (database-backed) -- **User Isolation**: Each user has isolated session state - -## BASIC Scripting - -Built on the Rhai engine with custom keywords: - -```basic -TALK "Hello!" ' Output -HEAR name AS NAME ' Input with validation -result = LLM "Summarize: " + text ' AI integration -USE KB "docs" ' Knowledge base -``` - -Scripts stored as `.gbdialog` files in bot packages. - -## LLM Integration - -| Provider | Models | Features | -|----------|--------|----------| -| OpenAI | GPT-3.5, GPT-4 | Streaming, function calling | -| Local | GGUF models | GPU acceleration, offline | - -Features: prompt templates, context injection, token management, cost optimization. - -## Knowledge Base - -- **Vector Database**: Qdrant for semantic search -- **Document Processing**: PDF, DOCX, HTML, TXT extraction -- **Auto-Indexing**: Documents indexed on upload -- **Context Retrieval**: Automatic injection into LLM prompts - -## Storage - -### Object Storage (S3-Compatible) - -- Bucket management -- Secure credential-based access -- Template and asset storage - -### File Monitoring - -- Real-time change detection -- Automatic processing triggers -- Event-driven workflows - -## Database - -PostgreSQL with Diesel ORM: - -- Connection pooling (R2D2) -- Automatic migrations -- ACID transactions - -Key tables: `users`, `bots`, `sessions`, `messages`, `conversations` - -## Automation - -```basic -SET SCHEDULE "0 9 * * *" ' Daily at 9 AM -SEND MAIL "team@company.com", "Daily Report", report -``` - -- Cron scheduling -- Event triggers -- Background jobs - -## Security - -| Feature | Implementation | -|---------|----------------| -| Password Storage | Argon2 | -| Data at Rest | AES-GCM | -| Sessions | Cryptographic tokens | -| API Access | Token-based auth | -| Transport | TLS via proxy | - -## Optional Components - -| Component | Port | Purpose | -|-----------|------|---------| -| Email Server | 25/993 | SMTP/IMAP | -| Video Server | 7880 | LiveKit meetings | -| Vector DB | 6333 | Qdrant search | -| Time-Series | 8086 | InfluxDB metrics | - -## Extensibility - -- **Custom Keywords**: Add BASIC keywords in Rust -- **Tool Integration**: Call external APIs from scripts -- **Custom Channels**: Implement new communication channels -- **LLM Providers**: Add new AI providers - -## See Also - -- [Feature Reference](./README.md) - Complete feature matrix -- [AI and LLM](./ai-llm.md) - AI integration details -- [Automation](./automation.md) - Scheduling and triggers \ No newline at end of file diff --git a/docs/src/chapter-11-features/drive-monitor.md b/docs/src/chapter-11-features/drive-monitor.md deleted file mode 100644 index bf53dd11..00000000 --- a/docs/src/chapter-11-features/drive-monitor.md +++ /dev/null @@ -1,118 +0,0 @@ -# Drive Monitor - -The Drive Monitor is a real-time file synchronization system that watches for changes in bot storage buckets and automatically updates the database and runtime configuration. - -## Overview - -DriveMonitor provides hot-reloading capabilities for bot configurations by continuously monitoring file changes in object storage. When files are modified, added, or removed, the system automatically detects changes through ETags and file comparison, updates the database with new configurations, recompiles scripts and tools, refreshes knowledge bases, and broadcasts theme changes to connected clients. - -## Architecture - -``` -┌─────────────────┐ -│ Object Storage │ (S3-compatible) -│ Buckets │ -└────────┬────────┘ - │ Poll every 30s - ▼ -┌─────────────────┐ -│ Drive Monitor │ -│ - Check ETags │ -│ - Diff files │ -└────────┬────────┘ - │ Changes detected - ▼ -┌─────────────────────────┐ -│ Process Updates │ -│ - Compile scripts (.bas)│ -│ - Update KB (.gbkb) │ -│ - Refresh themes │ -│ - Update database │ -└─────────────────────────┘ -``` - -## Implementation - -### Core Components - -The DriveMonitor is implemented in `src/drive/drive_monitor/mod.rs` with the following structure: - -```rust -pub struct DriveMonitor { - state: Arc, - bucket_name: String, - file_states: Arc>>, - bot_id: Uuid, - kb_manager: Arc, - work_root: PathBuf, - is_processing: Arc, -} -``` - -### Monitoring Process - -The monitoring process begins with initialization when a bot is mounted, at which point a DriveMonitor instance is created and spawned. Every 30 seconds, the monitor polls for changes in `.gbdialog` files containing scripts and tools, `.gbkb` collections containing knowledge base documents, `.gbtheme` files for UI themes, and `.gbot/config.csv` for bot configuration. - -Change detection uses ETags to efficiently identify file modifications without downloading entire files. When changes are detected, different file types trigger specific handlers. Scripts are compiled to AST, knowledge base files are indexed and embedded, themes are broadcast to WebSocket clients, and config changes trigger bot settings reload. - -### File Type Handlers - -#### Script Files (.bas) - -The script handler compiles BASIC scripts to AST format for efficient execution. It stores the compiled version in the database for persistence and updates the tool registry if the script defines callable tools. - -#### Knowledge Base Files (.gbkb) - -The knowledge base handler downloads new and modified documents from storage. It processes text extraction to prepare content for indexing, generates embeddings using the configured embedding model, and updates the vector database for semantic search functionality. - -#### Theme Files (.gbtheme) - -The theme handler detects CSS and JavaScript changes in theme packages. It broadcasts updates to all connected WebSocket clients and triggers UI refresh without requiring a full page reload. - -## Usage - -The DriveMonitor is automatically started when a bot is mounted: - -```rust -// In BotOrchestrator::mount_bot -let drive_monitor = Arc::new(DriveMonitor::new( - state.clone(), - bucket_name, - bot_id -)); -let _handle = drive_monitor.clone().spawn().await; -``` - -## Configuration - -No explicit configuration is needed since the monitor automatically uses the bot's storage bucket name, creates work directories as needed, and manages its own file state cache internally. - -## Performance Considerations - -The polling interval of 30 seconds balances responsiveness with resource usage to avoid overwhelming the storage backend. Concurrent processing uses atomic flags to prevent overlapping operations that could cause race conditions. The caching system maintains an ETag cache to minimize unnecessary downloads when files haven't changed. Batching ensures that multiple file changes detected in a single poll cycle are processed together efficiently. - -## Error Handling - -The monitor includes robust error handling that continues operation even if individual file processing fails. Errors are logged for debugging while maintaining overall service availability. Isolated error boundaries prevent cascading failures that could take down the entire monitoring system. - -## Monitoring and Debugging - -Enable debug logging to see monitor activity: - -```bash -RUST_LOG=botserver::drive::drive_monitor=debug cargo run -``` - -Log output includes change detection events showing which files were modified, file processing status as each file is handled, compilation results for script files, and database update confirmations when changes are persisted. - -## Best Practices - -Keep related files organized in their appropriate directories such as `.gbdialog` for scripts, `.gbkb` for knowledge base content, and `.gbtheme` for UI customizations. The monitor tracks changes but doesn't maintain history, so use git or another version control system to track file revisions. For knowledge base documents larger than 10MB, consider splitting them into smaller files for better processing performance. During active development, the 30-second polling delay can be avoided by restarting the bot to force immediate reprocessing. - -## Limitations - -The system is not truly real-time due to the 30-second polling interval, meaning changes aren't reflected instantly. There is no conflict resolution mechanism, so concurrent modifications follow a last-write-wins policy. Memory usage for the file state cache is minimal since only ETags are stored rather than full file contents. - -## Future Enhancements - -Planned improvements include WebSocket notifications from the storage layer for instant updates without polling, configurable polling intervals per file type to allow more frequent checks for critical files, differential sync for large knowledge bases to reduce processing time, and multi-version support for A/B testing different bot configurations. \ No newline at end of file diff --git a/docs/src/chapter-11-features/editions.md b/docs/src/chapter-11-features/editions.md deleted file mode 100644 index 3f2185e2..00000000 --- a/docs/src/chapter-11-features/editions.md +++ /dev/null @@ -1,375 +0,0 @@ -# Feature Editions - -General Bots offers flexible feature configurations to match different deployment needs. Features can be enabled at compile time using Cargo feature flags or selected through pre-configured edition bundles. - -## Edition Overview - -| Edition | Target Use Case | Key Features | -|---------|-----------------|--------------| -| **Minimal** | Embedded, IoT, testing | Basic chat only | -| **Lightweight** | Small teams, startups | Chat + Drive + Tasks | -| **Core** | General business use | Full productivity suite | -| **Standard** | Professional teams | + Email + Calendar + Meet | -| **Enterprise** | Large organizations | + Compliance + Multi-channel + GPU | -| **Full** | Maximum capability | All features enabled | - ---- - -## Minimal Edition - -**Use Case:** Embedded systems, IoT devices, testing environments - -**Cargo Feature:** `minimal` - -```bash -cargo build --features minimal -``` - -### Included Features -- ✅ UI Server (web interface) -- ✅ Basic chat functionality - -### Not Included -- ❌ Console TUI -- ❌ File storage -- ❌ Task management -- ❌ Email -- ❌ LLM integration -- ❌ Vector search - -**Typical Deployment:** Raspberry Pi, edge devices, containerized microservices - ---- - -## Lightweight Edition - -**Use Case:** Small teams, startups, personal use - -**Cargo Feature:** `lightweight` - -```bash -cargo build --features lightweight -``` - -### Included Features -- ✅ UI Server -- ✅ Chat -- ✅ Drive (file storage) -- ✅ Tasks -- ✅ Redis caching - -### Not Included -- ❌ Email integration -- ❌ Calendar -- ❌ Video meetings -- ❌ Compliance tools -- ❌ Multi-channel messaging - -**Typical Deployment:** Small office server, developer workstation - ---- - -## Core Edition (Default) - -**Use Case:** General business operations, mid-size teams - -**Cargo Feature:** `default` (or no feature flag) - -```bash -cargo build -# or explicitly: -cargo build --features default -``` - -### Included Features -- ✅ UI Server -- ✅ Console TUI -- ✅ Chat -- ✅ Automation (Rhai scripting) -- ✅ Tasks (with cron scheduling) -- ✅ Drive -- ✅ LLM integration -- ✅ Redis caching -- ✅ Progress bars -- ✅ Directory services - -### Not Included -- ❌ Email (IMAP/SMTP) -- ❌ Calendar management -- ❌ Video meetings -- ❌ Vector database -- ❌ Compliance monitoring -- ❌ Multi-channel (WhatsApp, Teams, etc.) -- ❌ NVIDIA GPU support -- ❌ Desktop application - -**Typical Deployment:** On-premise server, cloud VM, container - ---- - -## Standard Edition - -**Use Case:** Professional teams requiring full productivity features - -**Cargo Feature:** `productivity` - -```bash -cargo build --features productivity -``` - -### Included Features -All Core features plus: -- ✅ Email integration (IMAP/SMTP) -- ✅ Calendar management -- ✅ Video meetings (LiveKit) -- ✅ Mail client interface -- ✅ Redis caching - -### Additional Dependencies -- `imap` - Email receiving -- `lettre` - Email sending -- `mailparse` - Email parsing -- `livekit` - Video conferencing - -**Typical Deployment:** Business office, remote teams - ---- - -## Enterprise Edition - -**Use Case:** Large organizations with compliance and integration requirements - -**Cargo Feature:** `enterprise` - -```bash -cargo build --features enterprise -``` - -### Included Features -All Standard features plus: -- ✅ Compliance monitoring (LGPD/GDPR/HIPAA/SOC2) -- ✅ Attendance tracking -- ✅ Directory services (LDAP/AD compatible) -- ✅ Vector database (Qdrant) -- ✅ Advanced monitoring (sysinfo) -- ✅ LLM integration - -### Compliance Features -| Framework | Status | Implementation | -|-----------|--------|----------------| -| LGPD | ✅ | Data subject rights dialogs | -| GDPR | ✅ | Consent management, data portability | -| HIPAA | ✅ | PHI handling, audit trails | -| SOC 2 | ✅ | Access controls, logging | -| ISO 27001 | ✅ | Asset management, risk assessment | -| PCI DSS | ✅ | Payment data protection | - -**Typical Deployment:** Enterprise data center, regulated industries - ---- - -## Communications Edition - -**Use Case:** Organizations needing multi-channel customer engagement - -**Cargo Feature:** `communications` - -```bash -cargo build --features communications -``` - -### Included Features -- ✅ Email (IMAP/SMTP) -- ✅ WhatsApp Business -- ✅ Instagram messaging -- ✅ Microsoft Teams -- ✅ Chat -- ✅ Redis caching - -### Channel Support -| Channel | Protocol | Status | -|---------|----------|--------| -| WhatsApp | Cloud API | ✅ | -| Instagram | Graph API | ✅ | -| MS Teams | Bot Framework | ✅ | -| Telegram | Bot API | Planned | -| Slack | Web API | Planned | -| SMS | Twilio | Planned | - -**Typical Deployment:** Customer service center, marketing teams - ---- - -## Full Edition - -**Use Case:** Maximum capability, all features enabled - -**Cargo Feature:** `full` - -```bash -cargo build --features full -``` - -### All Features Enabled -- ✅ UI Server + Desktop application -- ✅ Console TUI -- ✅ Vector database (Qdrant) -- ✅ LLM integration -- ✅ NVIDIA GPU acceleration -- ✅ All communication channels -- ✅ Full productivity suite -- ✅ Compliance & attendance -- ✅ Directory services -- ✅ Web automation -- ✅ Redis caching -- ✅ System monitoring -- ✅ Automation (Rhai) -- ✅ gRPC support -- ✅ Progress bars - -### Hardware Recommendations -| Component | Minimum | Recommended | -|-----------|---------|-------------| -| CPU | 4 cores | 8+ cores | -| RAM | 8 GB | 32 GB | -| Storage | 100 GB SSD | 500 GB NVMe | -| GPU | Optional | NVIDIA RTX 3060+ | -| Network | 100 Mbps | 1 Gbps | - -**Typical Deployment:** Enterprise AI platform, research environments - ---- - -## Feature Matrix - -| Feature | Minimal | Light | Core | Standard | Enterprise | Full | -|---------|---------|-------|------|----------|------------|------| -| UI Server | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Chat | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Console TUI | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| Drive | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Tasks | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Automation | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| LLM | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| Email | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| Calendar | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| Meet | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| Vector DB | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| Compliance | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| Multi-channel | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | -| Desktop | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | -| GPU | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | - ---- - -## Custom Feature Combinations - -You can combine individual features for custom builds: - -```bash -# Chat + Email + Vector search -cargo build --features "chat,email,vectordb" - -# Productivity + Compliance -cargo build --features "productivity,compliance" - -# Everything except desktop -cargo build --features "full" --no-default-features -``` - -### Available Feature Flags - -```toml -[features] -# UI Features -desktop = ["dep:tauri", ...] -ui-server = [] -console = ["dep:crossterm", "dep:ratatui", "monitoring"] - -# Core Integrations -vectordb = ["dep:qdrant-client"] -llm = [] -nvidia = [] - -# Communication Channels -email = ["dep:imap", "dep:lettre", ...] -whatsapp = [] -instagram = [] -msteams = [] - -# Productivity Features -chat = [] -drive = ["dep:aws-config", "dep:aws-sdk-s3", ...] -tasks = ["dep:cron"] -calendar = [] -meet = ["dep:livekit"] -mail = ["email"] - -# Enterprise Features -compliance = ["dep:csv"] -attendance = [] -directory = [] -weba = [] - -# Infrastructure -redis-cache = ["dep:redis"] -monitoring = ["dep:sysinfo"] -automation = ["dep:rhai"] -grpc = ["dep:tonic"] -progress-bars = ["dep:indicatif"] -``` - ---- - -## Deployment Recommendations - -### By Organization Size - -| Size | Employees | Recommended Edition | -|------|-----------|---------------------| -| Solo | 1 | Lightweight | -| Startup | 2-10 | Core | -| SMB | 11-50 | Standard | -| Mid-market | 51-200 | Enterprise | -| Enterprise | 200+ | Full | - -### By Industry - -| Industry | Recommended Edition | Key Features | -|----------|---------------------|--------------| -| Healthcare | Enterprise | HIPAA compliance | -| Finance | Enterprise | SOC 2, PCI DSS | -| Education | Standard | Calendar, Meet | -| Retail | Communications | Multi-channel | -| Legal | Enterprise | Document management, compliance | -| Manufacturing | Core | Automation, tasks | -| Tech/SaaS | Full | All capabilities | - ---- - -## Upgrading Editions - -Editions can be changed by rebuilding with different feature flags: - -```bash -# From Core to Enterprise -cargo build --release --features enterprise - -# From Standard to Full -cargo build --release --features full -``` - -**Note:** Some features may require additional infrastructure components: -- `vectordb` → Requires Qdrant service -- `meet` → Requires LiveKit server -- `redis-cache` → Requires Redis/Valkey -- `nvidia` → Requires NVIDIA GPU + CUDA - ---- - -## See Also - -- [Cargo.toml Feature Definitions](../chapter-07-gbapp/dependencies.md) -- [Installation Guide](../chapter-01/installation.md) -- [Architecture Overview](../chapter-07-gbapp/architecture.md) -- [Compliance Requirements](../chapter-12-auth/compliance-requirements.md) \ No newline at end of file diff --git a/docs/src/chapter-11-features/email.md b/docs/src/chapter-11-features/email.md deleted file mode 100644 index 4d8d82c9..00000000 --- a/docs/src/chapter-11-features/email.md +++ /dev/null @@ -1,224 +0,0 @@ -# Email Integration - -BotServer provides email integration capabilities through IMAP/SMTP protocols, allowing bots to read, send, and manage emails. - -## Overview - -Email integration in BotServer enables reading emails via IMAP, sending emails via SMTP, email account management, draft creation and management, folder organization, and email-based automation workflows. - -## Configuration - -### Environment Variables - -Email configuration requires these environment variables: - -```bash -# IMAP Settings -EMAIL_IMAP_SERVER=imap.gmail.com -EMAIL_IMAP_PORT=993 -EMAIL_USERNAME=your-email@example.com -EMAIL_PASSWORD=your-app-password - -# SMTP Settings -EMAIL_SMTP_SERVER=smtp.gmail.com -EMAIL_SMTP_PORT=587 -EMAIL_FROM=your-email@example.com -``` - -### Feature Flag - -Email functionality requires the `email` feature flag during compilation: -```bash -cargo build --features email -``` - -## Email Module Structure - -The email module is located in `src/email/` and contains `mod.rs` with the email service implementation, account management functionality, message handling logic, and IMAP/SMTP client implementations. - -## Database Schema - -### User Email Accounts - -The `user_email_accounts` table stores email account configurations with encrypted password storage. Users can configure multiple accounts, each with its own IMAP and SMTP server details. - -### Email Drafts - -The `email_drafts` table provides draft management including To, CC, and BCC addresses, subject and body content, attachment metadata, and auto-save support for work in progress. - -### Email Folders - -The `email_folders` table handles folder organization with IMAP folder mapping, message counts, unread tracking, and hierarchical structure support for nested folders. - -## BASIC Keywords for Email - -### SEND MAIL - -Send emails from BASIC scripts: - -```basic -SEND MAIL "recipient@example.com", "Subject", "Email body content" - -# With variables -let to = "user@example.com" -let subject = "Meeting Reminder" -let body = "Don't forget our meeting at 2 PM" -SEND MAIL to, subject, body -``` - -### Email Automation - -```basic -# Check for new emails -let new_emails = GET_EMAILS("INBOX", "UNSEEN") - -# Process each email -FOR EACH email IN new_emails { - let sender = email.from - let subject = email.subject - let body = email.body - - # Auto-reply logic - if (subject CONTAINS "urgent") { - SEND MAIL sender, "Re: " + subject, "I'll get back to you soon." - } -} -``` - -## Email Operations - -### Reading Emails - -The system can connect to IMAP servers, fetch message headers, download full messages, search by various criteria, mark messages as read or unread, and move messages between folders. - -### Sending Emails - -SMTP operations include authentication with the mail server, sending plain text and HTML emails, reply and forward functionality, and bulk sending with configurable limits. Attachment support is planned for a future release. - -## Security - -### Password Storage - -Email passwords are encrypted using AES-GCM and never stored in plaintext. Passwords are decrypted only when needed for authentication and memory is cleared after use to prevent credential leakage. - -### Connection Security - -All email connections require TLS/SSL encryption with proper certificate validation. Secure authentication methods are enforced, and plaintext transmission is never permitted. - -## Use Cases - -### Support Ticket System - -```basic -# Monitor support inbox -let support_emails = GET_EMAILS("support", "UNSEEN") - -FOR EACH email IN support_emails { - # Create ticket - let ticket_id = CREATE_TICKET(email.from, email.subject, email.body) - - # Send confirmation - let response = "Ticket #" + ticket_id + " created. We'll respond within 24 hours." - SEND MAIL email.from, "Ticket Created: " + email.subject, response -} -``` - -### Newsletter Distribution - -```basic -# Send newsletter to subscribers -let subscribers = GET "subscribers.csv" -let newsletter = GET "newsletter.html" - -FOR EACH subscriber IN subscribers { - SEND MAIL subscriber.email, "Monthly Newsletter", newsletter - WAIT 1 # Rate limiting -} -``` - -### Email-to-Task Conversion - -```basic -# Convert emails to tasks -let task_emails = GET_EMAILS("tasks", "UNSEEN") - -FOR EACH email IN task_emails { - CREATE TASK email.subject, email.body, email.from - MARK_AS_READ email -} -``` - -## Integration with Other Features - -### With Calendar - -Email integrates with the calendar system for meeting invitations, event reminders, and schedule updates sent via email notifications. - -### With Tasks - -Task integration enables task creation from emails, status updates delivered via email, and deadline reminders sent to responsible parties. - -### With Knowledge Base - -Knowledge base integration supports email archival for compliance, searchable email history, and providing email context for bot conversations. - -## Limitations - -### Current Limitations - -The current implementation does not support attachment handling, provides only basic HTML email support, lacks email templates, has limited filtering options, and does not support OAuth2 authentication, requiring app-specific passwords instead. - -### Rate Limiting - -Provider-specific rate limits apply to all email operations. Implement delays between sends to avoid throttling, monitor for rate limit errors, and use batch operations wisely to stay within provider limits. - -## Email Provider Setup - -### Gmail Configuration - -To configure Gmail, first enable 2-factor authentication on your Google account. Then generate an app-specific password for BotServer to use. Enable IMAP access in Gmail settings. Use `imap.gmail.com` on port 993 for IMAP and `smtp.gmail.com` on port 587 for SMTP. - -### Outlook/Office 365 - -For Outlook or Office 365, enable IMAP in your account settings. If 2FA is enabled, generate an app password. Use `outlook.office365.com` on port 993 for IMAP and `smtp.office365.com` on port 587 for SMTP. - -### Custom Email Servers - -For custom email servers, configure the appropriate server addresses, port numbers, security settings including TLS or SSL requirements, and the authentication method supported by your server. - -## Error Handling - -### Connection Errors - -```basic -# Handle email errors -status = SEND MAIL recipient, subject, body -IF status = "sent" THEN - TALK "Email sent successfully" -ELSE - TALK "Failed to send email: " + status - # Log error for admin -END IF -``` - -### Common Issues - -Common email issues include authentication failures from incorrect credentials, network timeouts when servers are slow to respond, server unavailable errors during outages, quota exceeded errors when hitting send limits, and invalid address errors for malformed recipients. - -## Best Practices - -Use app-specific passwords rather than primary account passwords to limit security exposure. Respect provider rate limits by implementing appropriate delays between operations. Implement retry logic for transient failures to ensure delivery. Validate email addresses before sending to catch format errors early. Monitor usage by tracking sent and received counts. Encrypt sensitive data in storage and transit. Maintain an audit trail by logging all email operations. - -## Monitoring - -### Metrics to Track - -Key metrics include emails sent and received, failed operations and their causes, connection failures, processing time for email operations, and queue size when batching sends. - -### Health Checks - -Regular health checks should verify IMAP connectivity, SMTP availability, account validity and credential freshness, and folder synchronization status. - -## Summary - -Email integration in BotServer enables powerful email-based automation and communication. Through IMAP/SMTP protocols and BASIC script integration, bots can manage email workflows, automate responses, and integrate email with other bot features for comprehensive communication automation. \ No newline at end of file diff --git a/docs/src/chapter-11-features/hybrid-search.md b/docs/src/chapter-11-features/hybrid-search.md deleted file mode 100644 index 08a5a2cd..00000000 --- a/docs/src/chapter-11-features/hybrid-search.md +++ /dev/null @@ -1,120 +0,0 @@ -# Hybrid RAG Search - -Hybrid search combines dense (semantic) and sparse (keyword) retrieval for better search quality than either method alone. - -## Overview - -| Method | Strengths | Weaknesses | -|--------|-----------|------------| -| **Dense (Semantic)** | Synonyms, meaning, paraphrasing | Rare terms, exact matches | -| **Sparse (BM25)** | Exact terms, product codes, names | No semantic understanding | -| **Hybrid** | Best of both | Slightly more computation | - -## How It Works - -``` -User Query - │ - ├──────────────────┐ - ▼ ▼ -Dense Search Sparse Search -(Weight: 0.7) (Weight: 0.3) - │ │ - └────────┬─────────┘ - ▼ - Reciprocal Rank Fusion - │ - ▼ - Optional Reranking - │ - ▼ - Final Results -``` - -**Reciprocal Rank Fusion (RRF):** -``` -RRF_score(d) = Σ 1 / (k + rank_i(d)) -``` - -## Configuration - -In `config.csv`: - -```csv -name,value -rag-hybrid-enabled,true -rag-dense-weight,0.7 -rag-sparse-weight,0.3 -rag-top-k,10 -rag-rrf-k,60 -rag-reranker-enabled,false -``` - -## Weight Tuning - -| Content Type | Dense | Sparse | Use Case | -|--------------|-------|--------|----------| -| **Balanced** | 0.7 | 0.3 | General purpose | -| **Semantic-Heavy** | 0.9 | 0.1 | Conversational, multilingual | -| **Keyword-Heavy** | 0.4 | 0.6 | Technical docs, product catalogs | -| **Equal** | 0.5 | 0.5 | When unsure | - -## Reranking - -Optional LLM-based reranking for highest quality: - -```csv -name,value -rag-reranker-enabled,true -rag-reranker-model,quality -rag-reranker-top-n,20 -``` - -| Aspect | Without | With Reranking | -|--------|---------|----------------| -| Latency | ~50ms | ~500ms | -| Quality | Good | Excellent | -| Cost | None | LLM API cost | - -**Use for:** Legal, medical, financial, compliance-critical queries. - -## Usage - -Hybrid search is automatic when enabled. No code changes needed: - -```basic -USE KB "company-policies" -' Queries automatically use hybrid search -``` - -## Performance - -| Metric | Target | -|--------|--------| -| MRR (Mean Reciprocal Rank) | > 0.7 | -| Recall@10 | > 0.9 | -| Latency P95 | < 200ms | -| Cache Hit Rate | > 40% | - -### Caching - -```csv -name,value -rag-cache-enabled,true -rag-cache-ttl,3600 -rag-cache-max-size,10000 -``` - -## Troubleshooting - -| Issue | Solution | -|-------|----------| -| Poor results | Adjust weights for content type | -| High latency | Reduce `rag-top-k`, enable caching, disable reranking | -| Missing expected results | Check document indexed, verify no filters excluding it | - -## See Also - -- [Semantic Search](../chapter-03/semantic-search.md) - Dense search details -- [Document Indexing](../chapter-03/indexing.md) - How documents are processed -- [Knowledge Base](./knowledge-base.md) - KB overview \ No newline at end of file diff --git a/docs/src/chapter-11-features/knowledge-base.md b/docs/src/chapter-11-features/knowledge-base.md deleted file mode 100644 index c327c6e8..00000000 --- a/docs/src/chapter-11-features/knowledge-base.md +++ /dev/null @@ -1,67 +0,0 @@ -# Knowledge Base - -The Knowledge Base (KB) system enables semantic search and document retrieval for intelligent bot responses. - -## Quick Overview - -| Feature | Description | -|---------|-------------| -| **Storage** | S3-compatible drive + PostgreSQL metadata + Qdrant vectors | -| **Search** | Hybrid (semantic + keyword) with optional reranking | -| **Formats** | PDF, DOCX, TXT, MD, HTML, CSV, JSON | -| **Integration** | Automatic context injection into LLM responses | - -## Basic Usage - -```basic -' Load knowledge base -USE KB "policies" - -' Bot now answers questions using that knowledge -' No explicit search needed - it's automatic -``` - -## Key Capabilities - -- **Semantic Search** - Find content by meaning, not just keywords -- **Multi-Collection** - Organize documents into focused collections -- **Auto-Indexing** - Documents indexed automatically when added -- **Hybrid Search** - Combines dense (semantic) and sparse (BM25) retrieval -- **Context Management** - Relevant chunks injected into LLM prompts - -## Document Organization - -``` -bot.gbkb/ -├── policies/ → USE KB "policies" -├── products/ → USE KB "products" -└── support/ → USE KB "support" -``` - -## Configuration - -Key settings in `config.csv`: - -```csv -name,value -rag-hybrid-enabled,true -rag-dense-weight,0.7 -rag-sparse-weight,0.3 -rag-top-k,10 -``` - -## Performance Tips - -1. **Organize collections** by topic for precise activation -2. **Clear unused KBs** to free memory: `CLEAR KB "old-docs"` -3. **Enable caching** for repeated queries -4. **Tune weights** based on content type (technical vs conversational) - -## Learn More - -- **[KB System Architecture](../chapter-03/README.md)** - Technical deep dive -- **[Semantic Search](../chapter-03/semantic-search.md)** - How search works -- **[Document Indexing](../chapter-03/indexing.md)** - Processing pipeline -- **[Hybrid Search](./hybrid-search.md)** - RAG 2.0 configuration -- **[USE KB Keyword](../chapter-06-gbdialog/keyword-use-kb.md)** - Complete reference -- **[.gbkb Package](../chapter-02/gbkb.md)** - Folder structure \ No newline at end of file diff --git a/docs/src/chapter-11-features/m365-comparison.md b/docs/src/chapter-11-features/m365-comparison.md deleted file mode 100644 index f05c8b7c..00000000 --- a/docs/src/chapter-11-features/m365-comparison.md +++ /dev/null @@ -1,294 +0,0 @@ -# Enterprise Platform Migration - -Feature Parity Flow - -General Bots provides complete feature parity with enterprise cloud productivity suites while offering significant advantages: self-hosting, open source licensing, no per-user fees, and native AI integration. - -## Migration Overview - -API Comparison Matrix - -Organizations evaluating self-hosted alternatives find General Bots delivers equivalent functionality with full data sovereignty. The sections below map common enterprise APIs to their General Bots equivalents. - -## API Endpoint Mapping - -### Mail and Communication - -Enterprise mail APIs handle sending, receiving, and managing email. General Bots provides the same capabilities through Stalwart Mail Server and BASIC keywords. - -| Enterprise API | General Bots Equivalent | Implementation | -|----------------|------------------------|----------------| -| Messages endpoint | Stalwart IMAP/JMAP | Full mailbox access | -| Send mail endpoint | `SEND MAIL` keyword | `SEND MAIL TO email SUBJECT s BODY b` | -| Mail folders | Stalwart folders | Standard IMAP folders | -| Attachments | File keywords | `READ`, `WRITE` with attachments | - -The BASIC syntax is straightforward: - -```basic -SEND MAIL TO "client@company.com" SUBJECT "Report Ready" BODY report_content -``` - -For receiving mail, configure webhooks or use scheduled scripts to process incoming messages through the Stalwart API. - -### Calendar and Scheduling - -Calendar APIs manage events, appointments, and scheduling. General Bots integrates CalDAV with the `BOOK` keyword. - -| Enterprise API | General Bots Equivalent | Implementation | -|----------------|------------------------|----------------| -| Calendar events | Calendar API | `/api/calendar/events` | -| Create event | `BOOK` keyword | `BOOK "Meeting" AT datetime` | -| Calendar view | Calendar range query | Date-filtered event retrieval | -| Free/busy lookup | Availability API | Schedule availability | - -Schedule appointments conversationally: - -```basic -TALK "When would you like to schedule your appointment?" -HEAR appointment_time AS DATE -BOOK "Consultation" AT appointment_time -TALK "Your appointment is confirmed for " + FORMAT(appointment_time, "MMMM d 'at' h:mm a") -``` - -### Files and Storage - -Cloud storage APIs handle file operations, versioning, and sharing. SeaweedFS provides S3-compatible storage with full versioning support. - -| Enterprise API | General Bots Equivalent | Implementation | -|----------------|------------------------|----------------| -| List files | `LIST` keyword | `LIST "/documents/"` | -| File listing | Drive API | `/api/files/list` | -| File content | `READ` keyword | `content = READ "file.pdf"` | -| File versions | Versions API | `/api/files/versions` | -| Permissions | Sharing API | Permission management | - -File operations in BASIC: - -```basic -files = LIST "/reports/" -FOR EACH file IN files - content = READ file.path - processed = LLM "Summarize this document: " + content - WRITE "/summaries/" + file.name + ".summary.txt", processed -NEXT file -``` - -### Tasks and Planning - -Task management APIs create, update, and track work items. General Bots implements a complete task system with project organization. - -| Enterprise API | General Bots Equivalent | Implementation | -|----------------|------------------------|----------------| -| Tasks endpoint | Tasks API | `/api/tasks` | -| Task lists | Task lists | Board-based organization | -| Create task | `CREATE TASK` keyword | Task creation | -| Task details | Task CRUD | Full task lifecycle | - -Create tasks from conversations: - -```basic -TALK "What task should I create?" -HEAR task_title - -TALK "When is it due?" -HEAR due_date AS DATE - -CREATE TASK task_title DUE due_date -TALK "Task created: " + task_title -``` - -### Users and Directory - -User management APIs handle identity, groups, and permissions. Zitadel provides enterprise-grade IAM with OIDC/OAuth2. - -| Enterprise API | General Bots Equivalent | Implementation | -|----------------|------------------------|----------------| -| Users endpoint | Users API | `/api/users` | -| Current user | Current user | Session context | -| Groups | Groups API | `/api/groups` | -| Directory | Directory API | Zitadel directory | -| Memberships | Membership API | Group memberships | - -### Automation and Workflows - -Cloud automation platforms provide flow-based workflow design. General Bots offers BASIC scripting with more power and flexibility. - -| Cloud Automation | General Bots Equivalent | Advantage | -|------------------|------------------------|-----------| -| Scheduled flows | `SET SCHEDULE` | Cron syntax, unlimited | -| HTTP triggers | `WEBHOOK` | Instant API creation | -| Connectors | `GET`, `POST`, GraphQL | Any REST/GraphQL API | -| Conditions | `IF/THEN/ELSE` | Full programming logic | -| Loops | `FOR EACH` | Native iteration | -| Data operations | `TABLE`, `INSERT`, `UPDATE` | Direct database access | - -A workflow that would require a visual designer elsewhere becomes simple BASIC: - -```basic -SET SCHEDULE "0 9 * * 1-5" - -' Daily sales report - runs weekdays at 9 AM -sales = AGGREGATE "orders", "SUM", "total", "date = TODAY()" -count = AGGREGATE "orders", "COUNT", "id", "date = TODAY()" - -SET CONTEXT "You are a business analyst. Create a brief executive summary." -summary = LLM "Sales: $" + sales + ", Orders: " + count - -SEND MAIL TO "executives@company.com" SUBJECT "Daily Sales Report" BODY summary -``` - -### AI and Intelligence - -Cloud AI assistants typically require additional per-user licensing. General Bots includes AI capabilities at no extra cost. - -| Cloud AI Feature | General Bots Equivalent | Advantage | -|------------------|------------------------|-----------| -| AI Assistant | `LLM` keyword | Free (bring your API key) | -| Document analysis | `USE KB` + `LLM` | Built-in RAG | -| Image generation | `IMAGE` keyword | Local generation available | -| Speech-to-text | `HEAR AS AUDIO` | Whisper integration | -| Text-to-speech | `AUDIO` keyword | TTS models | -| Vision/OCR | `SEE` keyword | Vision models | - -AI integration is native: - -```basic -USE KB "product-docs" -SET CONTEXT "You are a helpful product specialist." - -TALK "How can I help you today?" -HEAR question -response = LLM question -TALK response -``` - -## Feature Parity Matrix - -### Core Services - -| Service Category | Enterprise Cloud | General Bots | Status | -|------------------|------------------|--------------|--------| -| Email | Cloud mail service | Stalwart Mail | ✅ Complete | -| Calendar | Cloud calendar | CalDAV + Calendar API | ✅ Complete | -| Files | Cloud storage | SeaweedFS | ✅ Complete | -| Video | Cloud meetings | LiveKit | ✅ Complete | -| Chat | Cloud messaging | Multi-channel | ✅ Complete | -| Tasks | Cloud tasks | Tasks Module | ✅ Complete | -| Identity | Cloud identity | Zitadel | ✅ Complete | -| Search | Cloud search | Qdrant Vectors | ✅ Semantic | - -### Automation - -| Capability | Cloud Platform | General Bots | Status | -|------------|----------------|--------------|--------| -| Scheduled tasks | Scheduled flows | `SET SCHEDULE` | ✅ Complete | -| Webhooks | HTTP triggers | `WEBHOOK` | ✅ Complete | -| API calls | Connectors | HTTP keywords | ✅ Flexible | -| Custom logic | Expressions | Full BASIC | ✅ Powerful | -| Database | Cloud datastore | Direct SQL | ✅ Direct | -| Pricing | Per-user fees | Included | ✅ Free | - -### AI Capabilities - -| Feature | Cloud AI (extra cost) | General Bots | Status | -|---------|----------------------|--------------|--------| -| Chat assistance | ✅ | `LLM` keyword | ✅ Included | -| Document Q&A | ✅ | `USE KB` + RAG | ✅ Included | -| Code generation | ✅ | `LLM` with context | ✅ Included | -| Image generation | Limited | `IMAGE` keyword | ✅ Full | -| Video generation | ❌ | `VIDEO` keyword | ✅ Available | -| Custom models | ❌ | Any provider | ✅ Flexible | - -## Cost Comparison - -### Typical Per-User Cloud Licensing - -| License Tier | Monthly Cost | 100 Users/Year | -|--------------|--------------|----------------| -| Basic | $6/user | $7,200 | -| Standard | $12.50/user | $15,000 | -| Premium | $22/user | $26,400 | -| + AI features | $30/user | $36,000 | -| **Total Premium + AI** | **$52/user** | **$62,400** | - -### General Bots Self-Hosted - -| Component | Monthly Cost | Notes | -|-----------|--------------|-------| -| Software | $0 | AGPL licensed | -| Infrastructure | $50-200 | Your servers | -| LLM API (optional) | $50-500 | Pay per use | -| **Total** | **$100-700** | **Unlimited users** | - -For 100 users, General Bots costs roughly 1-2% of typical cloud licensing while providing equivalent or better functionality. - -## Migration Approach - -### Phase 1: Assessment - -Inventory current service usage and map to General Bots equivalents. Most organizations find complete feature coverage for core productivity scenarios. - -### Phase 2: Parallel Deployment - -Run General Bots alongside existing services during transition. Configure identity federation between Zitadel and existing directory services. - -### Phase 3: Data Migration - -Use provided migration tools and APIs: - -```basic -' Example: Migrate files from external storage -files = GET "https://api.storage.example/files" -FOR EACH file IN files - content = DOWNLOAD file.url - WRITE "/" + file.name, content -NEXT file -``` - -### Phase 4: Cutover - -Redirect DNS, update client configurations, and deprecate cloud subscriptions. - -## What You Gain - -**Data Sovereignty** - Your data stays on your infrastructure. No third-party access, no cross-border data concerns. - -**Cost Control** - Predictable infrastructure costs instead of per-user licensing that scales with your organization. - -**Customization** - Full source code access. Modify, extend, and integrate as needed. - -**AI Integration** - Native LLM support without additional licensing. Use any provider or run models locally. - -**Automation Power** - BASIC scripting provides more flexibility than visual flow builders with no per-automation limits. - -**No Vendor Lock-in** - Open standards (IMAP, CalDAV, S3, OIDC) mean your data is always portable. - -## Migration Resources - -General Bots provides tools and documentation for smooth migration: - -- **Import utilities** for common data formats -- **API compatibility layers** for gradual transition -- **Identity federation** for single sign-on during migration -- **Data validation tools** to verify migration completeness - -## Summary - -General Bots delivers enterprise productivity features without enterprise pricing: - -- 100% API coverage for core productivity services -- Self-hosted deployment with full data sovereignty -- No per-user licensing fees -- Native AI integration without additional cost -- More powerful automation with BASIC scripting -- Open source with full code access - -The choice between cloud and self-hosted depends on organizational priorities. For those valuing control, cost efficiency, and customization, General Bots delivers enterprise-grade productivity without enterprise-grade pricing. - -## See Also - -- [Quick Start](../chapter-01/quick-start.md) - Deploy in minutes -- [Keywords Reference](../chapter-06-gbdialog/keywords.md) - Full BASIC reference -- [REST API Reference](../chapter-10-api/README.md) - Complete API documentation -- [Migration Guide](../chapter-14-migration/README.md) - Detailed migration steps \ No newline at end of file diff --git a/docs/src/chapter-11-features/memory-management.md b/docs/src/chapter-11-features/memory-management.md deleted file mode 100644 index 9190cba4..00000000 --- a/docs/src/chapter-11-features/memory-management.md +++ /dev/null @@ -1,454 +0,0 @@ -# Memory Management - -General Bots provides a comprehensive memory system that enables persistent storage, cross-session continuity, and multi-agent data sharing. This chapter covers all memory types, their use cases, and best practices. - -## Overview - -The memory system supports four distinct scopes: - -| Memory Type | Scope | Persistence | Use Case | -|-------------|-------|-------------|----------| -| **User Memory** | Per user, all bots | Permanent | Preferences, profile, facts | -| **Bot Memory** | Per bot, all users | Permanent | Bot state, counters, config | -| **Session Memory** | Per session | Session lifetime | Current conversation context | -| **Episodic Memory** | Per conversation | Permanent | Conversation summaries | - -## User Memory - -User memory follows users across all bots and sessions, enabling personalization and continuity. - -### Keywords - -```basic -' Store user data -SET USER MEMORY "key", value - -' Retrieve user data -value = GET USER MEMORY("key") - -' Store a fact about the user -SET USER FACT "occupation", "software engineer" - -' Get all user facts -facts = USER FACTS() -``` - -### Examples - -#### Personalized Greeting - -```basic -' Check if returning user -name = GET USER MEMORY("name") - -IF name = "" THEN - TALK "Hello! What's your name?" - HEAR name - SET USER MEMORY "name", name - TALK "Nice to meet you, " + name + "!" -ELSE - TALK "Welcome back, " + name + "!" -END IF -``` - -#### Cross-Bot Preferences - -```basic -' In any bot - store preference -SET USER MEMORY "language", "pt-BR" -SET USER MEMORY "timezone", "America/Sao_Paulo" - -' In any other bot - use preference -language = GET USER MEMORY("language") -IF language = "pt-BR" THEN - TALK "Olá! Como posso ajudar?" -ELSE - TALK "Hello! How can I help?" -END IF -``` - -#### User Facts for AI Context - -```basic -' Store facts about the user -SET USER FACT "company", "Acme Corp" -SET USER FACT "role", "Product Manager" -SET USER FACT "interests", "AI, automation, productivity" - -' Later, use facts to personalize AI responses -facts = USER FACTS() -SET CONTEXT "user_profile" AS facts - -response = LLM "Help me draft a product roadmap" -' AI now knows user's role and interests -``` - -### Database Schema - -User memory is stored in the `user_memory` table: - -| Column | Type | Description | -|--------|------|-------------| -| `id` | UUID | Primary key | -| `user_id` | UUID | User identifier | -| `key` | VARCHAR(255) | Memory key | -| `value` | JSONB | Stored value (any type) | -| `memory_type` | VARCHAR(50) | preference, fact, context | -| `ttl` | TIMESTAMP | Optional expiration | -| `created_at` | TIMESTAMP | Creation time | -| `updated_at` | TIMESTAMP | Last update | - -### Configuration - -```csv -name,value -user-memory-enabled,true -user-memory-max-keys,1000 -user-memory-default-ttl,0 -``` - -| Option | Default | Description | -|--------|---------|-------------| -| `user-memory-enabled` | `true` | Enable user memory | -| `user-memory-max-keys` | `1000` | Max keys per user | -| `user-memory-default-ttl` | `0` | Default TTL (0 = no expiry) | - -## Bot Memory - -Bot memory stores data at the bot level, shared across all users but isolated per bot. - -### Keywords - -```basic -' Store bot data -SET BOT MEMORY "key", value - -' Retrieve bot data -value = GET BOT MEMORY("key") -``` - -### Examples - -#### Bot Statistics - -```basic -' Track bot usage -conversations = GET BOT MEMORY("total_conversations") -conversations = conversations + 1 -SET BOT MEMORY "total_conversations", conversations - -PRINT "This bot has had " + conversations + " conversations" -``` - -#### Feature Flags - -```basic -' Store feature configuration -SET BOT MEMORY "enable_voice", true -SET BOT MEMORY "max_retries", 3 -SET BOT MEMORY "welcome_message", "Hello! I'm your assistant." - -' Use in logic -enableVoice = GET BOT MEMORY("enable_voice") -IF enableVoice THEN - ' Enable voice features -END IF -``` - -#### Cache API Results - -```basic -' Cache expensive API calls -cachedRates = GET BOT MEMORY("exchange_rates") -cachedTime = GET BOT MEMORY("exchange_rates_time") - -IF cachedRates = "" OR (NOW() - cachedTime) > 3600 THEN - ' Refresh cache - rates = GET "https://api.exchangerate.host/latest" - SET BOT MEMORY "exchange_rates", rates - SET BOT MEMORY "exchange_rates_time", NOW() -ELSE - rates = cachedRates -END IF -``` - -### Use Cases - -| Use Case | Example Key | Description | -|----------|-------------|-------------| -| Counters | `total_orders` | Track bot-wide metrics | -| Config | `max_items` | Runtime configuration | -| Cache | `api_cache_products` | Cached API responses | -| State | `last_sync_time` | Operational state | - -## Session Memory - -Session memory is temporary storage for the current conversation session. - -### Keywords - -```basic -' Store in session -SET "key", value - -' Retrieve from session -value = GET "key" - -' Set context for AI -SET CONTEXT "topic" AS "billing inquiry" -``` - -### Examples - -#### Conversation State - -```basic -' Track conversation flow -SET "current_step", "collecting_info" -SET "collected_name", username -SET "collected_email", useremail - -' Later in conversation -step = GET "current_step" -IF step = "collecting_info" THEN - ' Continue collecting -END IF -``` - -#### Multi-Turn Context - -```basic -' Build context through conversation -SET CONTEXT "customer_id" AS customerid -SET CONTEXT "issue_type" AS "refund" -SET CONTEXT "order_id" AS orderid - -' AI has full context for responses -response = LLM "Help resolve this customer issue" -``` - -### Session Lifetime - -- Created when user starts conversation -- Persists across messages in same conversation -- Cleared when conversation ends or times out -- Default timeout: 30 minutes of inactivity - -## Episodic Memory - -Episodic memory stores summaries of past conversations for long-term context. - -### How It Works - -1. **Conversation Ends** - System detects conversation completion -2. **Summary Generated** - LLM creates concise summary -3. **Stored** - Summary saved with metadata -4. **Retrieved** - Used in future conversations for context - -### Example - -```basic -' System automatically creates episode summaries -' Example summary stored: -' { -' "conversation_id": "abc123", -' "summary": "User asked about refund policy, was satisfied with explanation", -' "topics": ["refunds", "policy"], -' "sentiment": "positive", -' "resolution": "resolved", -' "created_at": "2025-01-15T10:30:00Z" -' } - -' In future conversations, retrieve relevant episodes -episodes = GET USER MEMORY("recent_episodes") -SET CONTEXT "previous_interactions" AS episodes -``` - -### Configuration - -```csv -name,value -episodic-memory-enabled,true -episodic-summary-model,fast -episodic-max-episodes,100 -episodic-retention-days,365 -``` - -## Memory Patterns - -### Profile Builder Pattern - -Build user profile progressively through conversations. - -```basic -' Check what we know -profile = GET USER MEMORY("profile") -IF profile = "" THEN - profile = #{ } -END IF - -' Fill in missing information naturally -IF profile.name = "" THEN - ' Ask for name when appropriate -END IF - -IF profile.preferences = "" THEN - ' Learn preferences from behavior -END IF - -' Update profile -SET USER MEMORY "profile", profile -``` - -### Preference Learning Pattern - -Learn preferences from user behavior. - -```basic -' Track user choices -choice = HEAR selection -choices = GET USER MEMORY("choices_history") -IF choices = "" THEN choices = [] - -' Add new choice -choices = APPEND(choices, #{ - choice: choice, - context: currentContext, - timestamp: NOW() -}) -SET USER MEMORY "choices_history", choices - -' Analyze patterns periodically -IF LEN(choices) >= 10 THEN - preferences = LLM "Analyze these choices and identify preferences: " + JSON(choices) - SET USER MEMORY "learned_preferences", preferences -END IF -``` - -### Context Handoff Pattern - -Pass context between bots in multi-agent scenarios. - -```basic -' Sending bot: Store context for receiving bot -handoffContext = #{ - topic: currentTopic, - userIntent: detectedIntent, - conversationSummary: summary, - relevantFacts: facts -} -SET USER MEMORY "handoff_context", handoffContext - -' Transfer to specialist -TRANSFER CONVERSATION TO "specialist-bot" - -' Receiving bot: Retrieve context -context = GET USER MEMORY("handoff_context") -SET CONTEXT "background" AS context.conversationSummary -SET CONTEXT "intent" AS context.userIntent - -' Clear handoff context after use -SET USER MEMORY "handoff_context", "" -``` - -### TTL Pattern - -Use time-to-live for temporary data. - -```basic -' Store with expiration (implementation depends on memory type) -' For session-like data in user memory: -SET USER MEMORY "temp_auth_code", #{ - code: authCode, - expires: NOW() + 300 ' 5 minutes -} - -' Check expiration -stored = GET USER MEMORY("temp_auth_code") -IF stored <> "" AND stored.expires > NOW() THEN - ' Valid -ELSE - ' Expired or not found - SET USER MEMORY "temp_auth_code", "" -END IF -``` - -## Best Practices - -### Key Naming Conventions - -```basic -' Use consistent prefixes -SET USER MEMORY "pref_language", "en" ' Preferences -SET USER MEMORY "pref_timezone", "UTC" -SET USER MEMORY "fact_name", "John" ' Facts -SET USER MEMORY "fact_company", "Acme" -SET USER MEMORY "ctx_last_topic", "sales" ' Context -SET USER MEMORY "cache_products", data ' Cached data -``` - -### Don't Store Sensitive Data - -```basic -' ❌ DON'T: Store sensitive data -SET USER MEMORY "password", userPassword -SET USER MEMORY "ssn", socialSecurityNumber -SET USER MEMORY "credit_card", cardNumber - -' ✅ DO: Store references only -SET USER MEMORY "payment_method_id", paymentId -SET USER MEMORY "verified", true -``` - -### Handle Missing Data Gracefully - -```basic -' Always check for empty/missing -name = GET USER MEMORY("name") -IF name = "" THEN - name = "there" ' Default value -END IF -TALK "Hello, " + name + "!" -``` - -### Clean Up Old Data - -```basic -' Periodic cleanup of old data -lastCleanup = GET BOT MEMORY("last_memory_cleanup") -IF lastCleanup = "" OR (NOW() - lastCleanup) > 86400 THEN - ' Run cleanup logic - ' Remove expired entries, old cache, etc. - SET BOT MEMORY "last_memory_cleanup", NOW() -END IF -``` - -## Troubleshooting - -### Memory Not Persisting - -1. Check memory type - session memory doesn't persist -2. Verify database connection -3. Check for key name typos (keys are case-sensitive) -4. Review memory limits - -### Cross-Bot Memory Not Sharing - -1. Ensure using `USER MEMORY` not `BOT MEMORY` -2. Verify same user identity -3. Check `user-memory-enabled` config - -### Memory Full Errors - -1. Clean up old/unused keys -2. Increase `user-memory-max-keys` -3. Use TTL for temporary data -4. Consolidate related keys into objects - -## See Also - -- [SET USER MEMORY](../chapter-06-gbdialog/keyword-set-user-memory.md) - Store user memory -- [GET USER MEMORY](../chapter-06-gbdialog/keyword-get-user-memory.md) - Retrieve user memory -- [SET BOT MEMORY](../chapter-06-gbdialog/keyword-set-bot-memory.md) - Store bot memory -- [GET BOT MEMORY](../chapter-06-gbdialog/keyword-get-bot-memory.md) - Retrieve bot memory -- [Multi-Agent Orchestration](./multi-agent-orchestration.md) - Cross-bot data sharing \ No newline at end of file diff --git a/docs/src/chapter-11-features/multi-agent-design.md b/docs/src/chapter-11-features/multi-agent-design.md deleted file mode 100644 index 0aacb097..00000000 --- a/docs/src/chapter-11-features/multi-agent-design.md +++ /dev/null @@ -1,3550 +0,0 @@ -# Multi-Agent Office Suite - Complete Design Document - -## 🎯 Vision: Beat Microsoft 365, Google Workspace & All AI Competitors - -**General Bots = Multi-Agent AI + Complete Office Suite + Research Engine + Banking + Everything** - -This document outlines the complete implementation plan to make General Bots the world's most powerful FREE enterprise platform. - ---- - -## 📋 Table of Contents - -1. [BOT Keyword - Multi-Agent System](#1-bot-keyword---multi-agent-system) -2. [Chat UI Enhancements](#2-chat-ui-enhancements) -3. [Conversational Banking (bank.gbai)](#3-conversational-banking-bankgbai) -4. [Excel Clone (HTMX/Rust)](#4-excel-clone-htmxrust) -5. [Word Editor for .docx](#5-word-editor-for-docx) -6. [M365/Office Competitive Analysis](#6-m365office-competitive-analysis) -7. [Google/MS Graph API Compatibility](#7-googlems-graph-api-compatibility) -8. [Copilot/Gemini Feature Parity](#8-copilotgemini-feature-parity) -9. [Attachment System (Plus Button)](#9-attachment-system-plus-button) -10. [Conversation Branching](#10-conversation-branching) -11. [PLAY Keyword - Content Projector](#11-play-keyword---content-projector) -12. [Implementation Priority](#12-implementation-priority) - ---- - -## 1. BOT Keyword - Multi-Agent System - -### Concept - -Every conversation becomes a **group conversation** where multiple specialized bots can participate. Bots join based on triggers (tools, schedules, keywords) and collaborate to answer complex queries. - -### Keywords - -```basic -' Add a bot to the conversation -ADD BOT "finance-expert" WITH TRIGGER "money, budget, invoice, payment" -ADD BOT "legal-advisor" WITH TRIGGER "contract, agreement, compliance" -ADD BOT "hr-assistant" WITH TRIGGER "employee, vacation, hiring" - -' Add bot with tool-based trigger -ADD BOT "data-analyst" WITH TOOLS "AGGREGATE, CHART, REPORT" - -' Add bot with schedule-based participation -ADD BOT "daily-reporter" WITH SCHEDULE "0 9 * * *" - -' Remove bot from conversation -REMOVE BOT "finance-expert" - -' List active bots -bots = LIST BOTS - -' Set bot priority (who answers first) -SET BOT PRIORITY "legal-advisor", 1 - -' Bot-to-bot delegation -DELEGATE TO "specialist-bot" WITH CONTEXT current_conversation - -' Create bot swarm for complex tasks -CREATE SWARM "research-team" WITH BOTS "researcher, analyst, writer" -``` - -### Architecture - -``` -┌─────────────────────────────────────────────────────────────────┐ -│ CONVERSATION ORCHESTRATOR │ -├─────────────────────────────────────────────────────────────────┤ -│ │ -│ User Message ──▶ Trigger Analyzer ──▶ Bot Selector │ -│ │ │ │ -│ ▼ ▼ │ -│ ┌─────────────────┐ ┌──────────────┐ │ -│ │ Keyword Triggers │ │ Tool Triggers │ │ -│ │ - finance terms │ │ - AGGREGATE │ │ -│ │ - legal terms │ │ - CHART │ │ -│ │ - hr terms │ │ - specific │ │ -│ └─────────────────┘ └──────────────┘ │ -│ │ │ │ -│ ▼ ▼ │ -│ ┌─────────────────────────────────────┐ │ -│ │ BOT RESPONSE AGGREGATOR │ │ -│ │ - Merge responses │ │ -│ │ - Resolve conflicts │ │ -│ │ - Format for user │ │ -│ └─────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────┘ -``` - -### Database Schema - -```sql --- Bot definitions -CREATE TABLE bots ( - id UUID PRIMARY KEY, - name VARCHAR(255) NOT NULL, - description TEXT, - system_prompt TEXT, - model_config JSONB, - tools JSONB, - is_active BOOLEAN DEFAULT true, - created_at TIMESTAMPTZ DEFAULT NOW() -); - --- Bot triggers -CREATE TABLE bot_triggers ( - id UUID PRIMARY KEY, - bot_id UUID REFERENCES bots(id), - trigger_type VARCHAR(50), -- 'keyword', 'tool', 'schedule', 'event' - trigger_config JSONB, - priority INT DEFAULT 0, - is_active BOOLEAN DEFAULT true -); - --- Session bot associations -CREATE TABLE session_bots ( - id UUID PRIMARY KEY, - session_id UUID, - bot_id UUID REFERENCES bots(id), - joined_at TIMESTAMPTZ DEFAULT NOW(), - priority INT DEFAULT 0, - is_active BOOLEAN DEFAULT true -); - --- Bot message history -CREATE TABLE bot_messages ( - id UUID PRIMARY KEY, - session_id UUID, - bot_id UUID REFERENCES bots(id), - content TEXT, - role VARCHAR(50), - created_at TIMESTAMPTZ DEFAULT NOW() -); -``` - -### Rust Implementation - -```rust -// src/basic/keywords/add_bot.rs - -use crate::shared::models::UserSession; -use crate::shared::state::AppState; -use rhai::{Dynamic, Engine}; -use std::sync::Arc; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BotTrigger { - pub trigger_type: TriggerType, - pub keywords: Option>, - pub tools: Option>, - pub schedule: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum TriggerType { - Keyword, - Tool, - Schedule, - Event, -} - -pub fn add_bot_keyword(state: Arc, user: UserSession, engine: &mut Engine) { - let state_clone = Arc::clone(&state); - let user_clone = user.clone(); - - // ADD BOT "name" WITH TRIGGER "keywords" - engine.register_custom_syntax( - &["ADD", "BOT", "$expr$", "WITH", "TRIGGER", "$expr$"], - false, - move |context, inputs| { - let bot_name = context.eval_expression_tree(&inputs[0])?.to_string(); - let trigger = context.eval_expression_tree(&inputs[1])?.to_string(); - - let state_for_thread = Arc::clone(&state_clone); - let session_id = user_clone.id; - - let (tx, rx) = std::sync::mpsc::channel(); - - std::thread::spawn(move || { - let rt = tokio::runtime::Runtime::new().unwrap(); - let result = rt.block_on(async { - add_bot_to_session( - &state_for_thread, - session_id, - &bot_name, - BotTrigger { - trigger_type: TriggerType::Keyword, - keywords: Some(trigger.split(',').map(|s| s.trim().to_string()).collect()), - tools: None, - schedule: None, - } - ).await - }); - let _ = tx.send(result); - }); - - match rx.recv_timeout(std::time::Duration::from_secs(30)) { - Ok(Ok(msg)) => Ok(Dynamic::from(msg)), - Ok(Err(e)) => Err(Box::new(rhai::EvalAltResult::ErrorRuntime( - e.into(), - rhai::Position::NONE, - ))), - Err(_) => Err(Box::new(rhai::EvalAltResult::ErrorRuntime( - "ADD BOT timed out".into(), - rhai::Position::NONE, - ))), - } - }, - ); - - // ADD BOT "name" WITH TOOLS "tool1, tool2" - engine.register_custom_syntax( - &["ADD", "BOT", "$expr$", "WITH", "TOOLS", "$expr$"], - false, - move |context, inputs| { - // Similar implementation for tool-based triggers - }, - ); - - // ADD BOT "name" WITH SCHEDULE "cron" - engine.register_custom_syntax( - &["ADD", "BOT", "$expr$", "WITH", "SCHEDULE", "$expr$"], - false, - move |context, inputs| { - // Similar implementation for schedule-based triggers - }, - ); -} - -async fn add_bot_to_session( - state: &AppState, - session_id: Uuid, - bot_name: &str, - trigger: BotTrigger, -) -> Result { - // Implementation to add bot to session -} -``` - -### Multi-Agent Orchestrator - -```rust -// src/core/multi_agent.rs - -use std::collections::HashMap; -use uuid::Uuid; - -pub struct MultiAgentOrchestrator { - state: Arc, - active_bots: HashMap, -} - -impl MultiAgentOrchestrator { - pub async fn process_message( - &self, - session_id: Uuid, - message: &str, - ) -> Result, Error> { - // 1. Get all active bots for this session - let bots = self.get_session_bots(session_id).await?; - - // 2. Analyze message and match triggers - let matching_bots = self.match_triggers(&bots, message).await?; - - // 3. If no specific bot matches, use default - if matching_bots.is_empty() { - return self.default_bot_response(session_id, message).await; - } - - // 4. Get responses from all matching bots - let mut responses = Vec::new(); - for bot in matching_bots { - let response = self.get_bot_response(&bot, session_id, message).await?; - responses.push(response); - } - - // 5. Aggregate responses - let final_response = self.aggregate_responses(responses).await?; - - Ok(final_response) - } - - async fn match_triggers( - &self, - bots: &[BotInstance], - message: &str, - ) -> Vec { - let mut matching = Vec::new(); - let message_lower = message.to_lowercase(); - - for bot in bots { - if let Some(trigger) = &bot.trigger { - match trigger.trigger_type { - TriggerType::Keyword => { - if let Some(keywords) = &trigger.keywords { - for keyword in keywords { - if message_lower.contains(&keyword.to_lowercase()) { - matching.push(bot.clone()); - break; - } - } - } - } - TriggerType::Tool => { - // Check if message implies using specific tools - } - _ => {} - } - } - } - - // Sort by priority - matching.sort_by(|a, b| b.priority.cmp(&a.priority)); - matching - } - - async fn aggregate_responses( - &self, - responses: Vec, - ) -> Result, Error> { - // Use LLM to merge multiple bot responses into coherent answer - // Or return all responses with bot attribution - Ok(responses) - } -} -``` - ---- - -## 2. Chat UI Enhancements - -### 2.1 Poe/Perplexity-Style Features - -#### Chat Interface Components - -```html - - -
- -
-
- -
- -
- - -
- - Connected -
- - -
- -
- - - - - -
- -
-
- - - - - -
- - -
- - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - -
-``` - -### 2.2 Simple Chat/Talk UIs - -#### Intercom-Style Widget - -```html - - -
- - - -
- - -``` - -#### PTT (Push-to-Talk) Interface - -```html - - -
-
- 🔇 - Press and hold to talk -
- -
- - -
- - - -
- -
- -
- -
-
- - - - -``` - -#### Totem/Kiosk Interface - -```html - - - - - - - - Bot Totem - - - -
- -

How can I help you today?

-
- -
-
- 🤖 -
- -
- Touch any option below or tap the microphone to speak -
- -
-
-
🗺️
-
Directions
-
-
-
📅
-
Schedule
-
-
-
🏢
-
Services
-
-
-
📞
-
Contact
-
-
-
🎤
-
Speak
-
-
-
-
Help
-
-
-
- -
-
- 👆 - Touch to interact -
-
- - - - -``` - ---- - -## 3. Conversational Banking (bank.gbai) - -### Complete Banking Template - -``` -templates/bank.gbai/ -├── bank.gbdialog/ -│ └── start.json -├── bank.gbot/ -│ └── config.csv -├── bank.gbkb/ -│ └── banking-faq.md -├── dialogs/ -│ ├── account.bas -│ ├── transfer.bas -│ ├── payment.bas -│ ├── loan.bas -│ ├── investment.bas -│ ├── cards.bas -│ └── support.bas -├── tables/ -│ ├── accounts.csv -│ ├── transactions.csv -│ ├── cards.csv -│ ├── loans.csv -│ ├── beneficiaries.csv -│ └── scheduled_payments.csv -└── README.md -``` - -### Bank Configuration - -```csv -# bank.gbot/config.csv -key,value -bank-name,General Bank -bank-code,001 -swift-code,GENBBRSP -support-phone,0800-123-4567 -support-email,support@generalbank.com -pix-enabled,true -ted-enabled,true -doc-enabled,true -boleto-enabled,true -credit-card-enabled,true -debit-card-enabled,true -investment-enabled,true -loan-enabled,true -insurance-enabled,true -two-factor-auth,true -transaction-limit-default,5000.00 -daily-limit-default,20000.00 -``` - -### Account Management - -```basic -' dialogs/account.bas - -' Show account balance -SUB ShowBalance() - user_id = GET USER ID - - accounts = FIND "accounts.csv" WHERE user_id = user_id - - IF LEN(accounts) = 0 THEN - TALK "You don't have any accounts registered. Would you like to open one?" - RETURN - END IF - - TALK "Here are your account balances:" - TALK "" - - total = 0 - FOR EACH account IN accounts - TALK "📊 **" + account.account_type + " Account**" - TALK " Account: " + account.account_number - TALK " Balance: R$ " + FORMAT(account.balance, "0.00") - TALK " Available: R$ " + FORMAT(account.available_balance, "0.00") - TALK "" - total = total + account.balance - NEXT - - TALK "💰 **Total Balance: R$ " + FORMAT(total, "0.00") + "**" -END SUB - -' Show recent transactions -SUB ShowTransactions(account_number, days) - IF days = "" THEN days = 30 END IF - - start_date = DATEADD(NOW(), -days, "day") - - transactions = FIND "transactions.csv" WHERE account_number = account_number AND date >= start_date ORDER BY date DESC LIMIT 20 - - IF LEN(transactions) = 0 THEN - TALK "No transactions found in the last " + days + " days." - RETURN - END IF - - TALK "📋 **Recent Transactions**" - TALK "" - - FOR EACH tx IN transactions - IF tx.type = "credit" THEN - icon = "💵" - sign = "+" - ELSE - icon = "💸" - sign = "-" - END IF - - TALK icon + " " + FORMAT(tx.date, "dd/MM") + " | " + tx.description - TALK " " + sign + "R$ " + FORMAT(tx.amount, "0.00") + " | Balance: R$ " + FORMAT(tx.balance_after, "0.00") - TALK "" - NEXT -END SUB - -' Generate account statement -SUB GenerateStatement(account_number, start_date, end_date) - transactions = FIND "transactions.csv" WHERE account_number = account_number AND date >= start_date AND date <= end_date ORDER BY date - - TABLE statement - COLUMN "Date" FORMAT "dd/MM/yyyy" - COLUMN "Description" - COLUMN "Type" - COLUMN "Amount" FORMAT "R$ #,##0.00" - COLUMN "Balance" FORMAT "R$ #,##0.00" - - FOR EACH tx IN transactions - ROW tx.date, tx.description, tx.type, tx.amount, tx.balance_after - NEXT - END TABLE - - ' Export to PDF - pdf_file = EXPORT TABLE statement TO "pdf" WITH TITLE "Account Statement - " + account_number - - TALK "Your statement is ready!" - TALK "📄 [Download Statement](" + pdf_file + ")" - - ' Send by email - email = GET USER email - IF email <> "" THEN - SEND MAIL email, "Your Account Statement", "Please find attached your account statement.", pdf_file - TALK "I've also sent a copy to your email." - END IF -END SUB - -' Open new account -SUB OpenAccount(account_type) - user_id = GET USER ID - user = GET USER - - ' Verify KYC - IF NOT user.kyc_verified THEN - TALK "To open a new account, we need to verify your identity first." - CALL VerifyKYC() - RETURN - END IF - - ' Generate account number - account_number = GenerateAccountNumber() - - ' Create account - TABLE new_account - ROW account_number, user_id, account_type, 0.00, 0.00, NOW(), "active" - END TABLE - - SAVE "accounts.csv", new_account - - TALK "🎉 Congratulations! Your " + account_type + " account has been created!" - TALK "" - TALK "📋 **Account Details**" - TALK "Account Number: " + account_number - TALK "Type: " + account_type - TALK "Status: Active" - TALK "" - TALK "Your virtual debit card is being generated..." - - ' Create virtual card - CALL CreateVirtualCard(account_number) -END SUB - -FUNCTION GenerateAccountNumber() - ' Generate unique account number - branch = "0001" - sequence = GET BOT MEMORY "account_sequence" - IF sequence = "" THEN sequence = 10000 END IF - sequence = sequence + 1 - SET BOT MEMORY "account_sequence", sequence - - account = branch + "-" + FORMAT(sequence, "000000") - digit = CalculateCheckDigit(account) - - RETURN account + "-" + digit -END FUNCTION -``` - -### Money Transfers - -```basic -' dialogs/transfer.bas - -' PIX Transfer -SUB PIXTransfer() - TALK "Let's make a PIX transfer. What type of key will you use?" - - ADD SUGGESTION "CPF/CNPJ" - ADD SUGGESTION "Phone" - ADD SUGGESTION "Email" - ADD SUGGESTION "Random Key" - - key_type = HEAR - - TALK "Enter the PIX key:" - pix_key = HEAR - - ' Validate and get recipient info - recipient = ValidatePIXKey(key_type, pix_key) - - IF recipient.error THEN - TALK "❌ Invalid PIX key. Please check and try again." - RETURN - END IF - - TALK "Recipient: **" + recipient.name + "**" - TALK "Bank: " + recipient.bank_name - TALK "" - TALK "Enter the amount to transfer:" - - amount = HEAR - amount = ParseMoney(amount) - - ' Check balance and limits - account = GET USER primary_account - - IF amount > account.available_balance THEN - TALK "❌ Insufficient balance. Available: R$ " + FORMAT(account.available_balance, "0.00") - RETURN - END IF - - daily_used = GetDailyTransferTotal(account.account_number) - daily_limit = GET USER daily_transfer_limit - - IF daily_used + amount > daily_limit THEN - TALK "❌ This transfer would exceed your daily limit." - TALK "Daily limit: R$ " + FORMAT(daily_limit, "0.00") - TALK "Already used: R$ " + FORMAT(daily_used, "0.00") - TALK "Available: R$ " + FORMAT(daily_limit - daily_used, "0.00") - RETURN - END IF - - ' Confirm transaction - TALK "📤 **Transfer Summary**" - TALK "To: " + recipient.name - TALK "PIX Key: " + MaskPIXKey(pix_key) - TALK "Amount: R$ " + FORMAT(amount, "0.00") - TALK "" - TALK "Confirm this transfer?" - - ADD SUGGESTION "Yes, confirm" - ADD SUGGESTION "No, cancel" - - confirmation = HEAR - - IF confirmation CONTAINS "yes" OR confirmation CONTAINS "confirm" THEN - ' Request 2FA - TALK "For your security, enter the code sent to your phone:" - code = HEAR - - IF NOT Verify2FA(code) THEN - TALK "❌ Invalid code. Transfer cancelled for security." - RETURN - END IF - - ' Execute transfer - result = ExecutePIXTransfer(account.account_number, recipient, amount) - - IF result.success THEN - TALK "✅ **Transfer completed!**" - TALK "Transaction ID: " + result.transaction_id - TALK "New balance: R$ " + FORMAT(result.new_balance, "0.00") - - ' Save transaction - TABLE transaction - ROW result.transaction_id, account.account_number, "pix_out", amount, result.new_balance, NOW(), recipient.pix_key, recipient.name, "completed" - END TABLE - SAVE "transactions.csv", transaction - ELSE - TALK "❌ Transfer failed: " + result.error - END IF - ELSE - TALK "Transfer cancelled." - END IF -END SUB - -' TED Transfer -SUB TEDTransfer() - TALK "Let's make a TED transfer." - - ' Get recipient bank info - TALK "Enter the bank code (e.g., 001 for Banco do Brasil):" - bank_code = HEAR - - TALK "Enter the branch number:" - branch = HEAR - - TALK "Enter the account number (with digit):" - account_number = HEAR - - TALK "Enter the recipient's full name:" - recipient_name = HEAR - - TALK "Enter the recipient's CPF/CNPJ:" - document = HEAR - - TALK "Enter the amount to transfer:" - amount = HEAR - amount = ParseMoney(amount) - - ' Validate and process similar to PIX - ' ... (similar flow with bank validation) -END SUB - -' Schedule recurring transfer -SUB ScheduleTransfer() - TALK "Let's schedule a recurring transfer." - - TALK "How often should the transfer occur?" - ADD SUGGESTION "Weekly" - ADD SUGGESTION "Monthly" - ADD SUGGESTION "Custom" - - frequency = HEAR - - ' Get transfer details - TALK "Enter the PIX key of the recipient:" - pix_key = HEAR - - TALK "Enter the amount:" - amount = HEAR - - TALK "When should the first transfer occur?" - start_date = HEAR - - ' Create scheduled payment - TABLE scheduled - ROW GenerateID(), GET USER ID, "pix", pix_key, amount, frequency, start_date, "active" - END TABLE - - SAVE "scheduled_payments.csv", scheduled - - ' Set up the schedule - SET SCHEDULE frequency WITH START start_date - CALL ExecuteScheduledTransfer(scheduled.id) - END SCHEDULE - - TALK "✅ Recurring transfer scheduled!" - TALK "First transfer: " + FORMAT(start_date, "dd/MM/yyyy") - TALK "Frequency: " + frequency - TALK "Amount: R$ " + FORMAT(amount, "0.00") -END SUB -``` - -### Bill Payment - -```basic -' dialogs/payment.bas - -' Pay bill/boleto -SUB PayBoleto() - TALK "Enter the barcode or paste the boleto line:" - barcode = HEAR - - ' Parse boleto - boleto = ParseBoleto(barcode) - - IF boleto.error THEN - TALK "❌ Invalid barcode. Please check and try again." - RETURN - END IF - - TALK "📄 **Bill Details**" - TALK "Beneficiary: " + boleto.beneficiary - TALK "Amount: R$ " + FORMAT(boleto.amount, "0.00") - TALK "Due date: " + FORMAT(boleto.due_date, "dd/MM/yyyy") - - IF boleto.is_overdue THEN - TALK "⚠️ This bill is overdue. Late fees may apply." - TALK "Original amount: R$ " + FORMAT(boleto.original_amount, "0.00") - TALK "Late fee: R$ " + FORMAT(boleto.late_fee, "0.00") - TALK "Interest: R$ " + FORMAT(boleto.interest, "0.00") - END IF - - TALK "" - TALK "Pay this bill?" - - ADD SUGGESTION "Yes, pay now" - ADD SUGGESTION "Schedule for due date" - ADD SUGGESTION "Cancel" - - choice = HEAR - - IF choice CONTAINS "now" THEN - ' Process payment - result = ProcessBoletoPayment(boleto) - - IF result.success THEN - TALK "✅ **Payment completed!**" - TALK "Transaction ID: " + result.transaction_id - TALK "Authentication: " + result.authentication - ELSE - TALK "❌ Payment failed: " + result.error - END IF - - ELSEIF choice CONTAINS "schedule" THEN - ' Schedule for due date - TABLE scheduled - ROW GenerateID(), GET USER ID, "boleto", barcode, boleto.amount, boleto.due_date, "pending" - END TABLE - - SAVE "scheduled_payments.csv", scheduled - - TALK "✅ Payment scheduled for " + FORMAT(boleto.due_date, "dd/MM/yyyy") - ELSE - TALK "Payment cancelled." - END IF -END SUB - -' Pay utilities -SUB PayUtility(utility_type) - TALK "Enter your " + utility_type + " account number or scan the bill:" - account = HEAR - - ' Fetch bill info - bill = FetchUtilityBill(utility_type, account) - - IF bill.found THEN - TALK "📄 **" + utility_type + " Bill**" - TALK "Account: " + account - TALK "Reference: " + bill.reference - TALK "Amount: R$ " + FORMAT(bill.amount, "0.00") - TALK "Due date: " + FORMAT(bill.due_date, "dd/MM/yyyy") - - TALK "Pay this bill?" - ' ... continue payment flow - ELSE - TALK "No pending bill found for this account." - END IF -END SUB -``` - -### Loans - -```basic -' dialogs/loan.bas - -' Loan simulation -SUB SimulateLoan() - TALK "Let's simulate a loan. What type of loan are you interested in?" - - ADD SUGGESTION "Personal Loan" - ADD SUGGESTION "Payroll Loan" - ADD SUGGESTION "Home Equity" - ADD SUGGESTION "Vehicle Loan" - - loan_type = HEAR - - TALK "What amount do you need?" - amount = HEAR - amount = ParseMoney(amount) - - TALK "In how many months would you like to pay?" - ADD SUGGESTION "12 months" - ADD SUGGESTION "24 months" - ADD SUGGESTION "36 months" - ADD SUGGESTION "48 months" - ADD SUGGESTION "60 months" - - months = HEAR - months = ParseNumber(months) - - ' Get user's rate based on credit score - user = GET USER - rate = GetPersonalizedRate(user.id, loan_type) - - ' Calculate loan - monthly_payment = CalculatePMT(amount, rate, months) - total_amount = monthly_payment * months - total_interest = total_amount - amount - - TALK "💰 **Loan Simulation**" - TALK "" - TALK "📊 **Summary**" - TALK "Loan type: " + loan_type - TALK "Amount: R$ " + FORMAT(amount, "0.00") - TALK "Term: " + months + " months" - TALK "Interest rate: " + FORMAT(rate * 100, "0.00") + "% per month" - TALK "" - TALK "📅 **Monthly Payment: R$ " + FORMAT(monthly_payment, "0.00") + "**" - TALK "" - TALK "Total to pay: R$ " + FORMAT(total_amount, "0.00") - TALK "Total interest: R$ " + FORMAT(total_interest, "0.00") - TALK "" - TALK "Would you like to proceed with this loan?" - - ADD SUGGESTION "Yes, apply now" - ADD SUGGESTION "Try different values" - ADD SUGGESTION "Not now" - - choice = HEAR - - IF choice CONTAINS "apply" THEN - CALL ApplyForLoan(loan_type, amount, months, rate) - ELSEIF choice CONTAINS "different" THEN - CALL SimulateLoan() - ELSE - TALK "No problem! I'm here whenever you need." - END IF -END SUB - -' Apply for loan -SUB ApplyForLoan(loan_type, amount, months, rate) - user = GET USER - - ' Check eligibility - eligibility = CheckLoanEligibility(user.id, loan_type, amount) - - IF NOT eligibility.eligible THEN - TALK "❌ Unfortunately, we couldn't approve this loan at this time." - TALK "Reason: " + eligibility.reason - - IF eligibility.alternative_amount > 0 THEN - TALK "However, you're pre-approved for up to R$ " + FORMAT(eligibility.alternative_amount, "0.00") - TALK "Would you like to apply for this amount instead?" - END IF - RETURN - END IF - - TALK "✅ **Great news! You're pre-approved!**" - TALK "" - TALK "To complete your application, I need some additional information." - - ' Collect additional info - TALK "What is your monthly income?" - income = HEAR - - TALK "What is your profession?" - profession = HEAR - - TALK "Do you have any other loans? (yes/no)" - has_other_loans = HEAR - - IF has_other_loans CONTAINS "yes" THEN - TALK "What is the total monthly payment of your other loans?" - other_loans_payment = HEAR - END IF - - ' Create loan application - application_id = GenerateID() - - TABLE loan_application - ROW application_id, user.id, loan_type, amount, months, rate, income, profession, NOW(), "pending_analysis" - END TABLE - - SAVE "loan_applications.csv", loan_application - - TALK "🎉 **Application Submitted!**" - TALK "" - TALK "Application ID: " + application_id - TALK "Status: Under Analysis" - TALK "" - TALK "We'll analyze your application within 24 hours." - TALK "You'll receive updates via email and app notifications." - - ' Send notification - SEND MAIL user.email, "Loan Application Received", "Your loan application " + application_id + " has been received and is under analysis." -END SUB -``` - -### Cards Management - -```basic -' dialogs/cards.bas - -' View cards -SUB ViewCards() - user_id = GET USER ID - - cards = FIND "cards.csv" WHERE user_id = user_id AND status = "active" - - IF LEN(cards) = 0 THEN - TALK "You don't have any active cards." - TALK "Would you like to request one?" - RETURN - END IF - - TALK "💳 **Your Cards**" - TALK "" - - FOR EACH card IN cards - IF card.card_type = "credit" THEN - icon = "💳" - ELSE - icon = "💵" - END IF - - masked_number = "**** **** **** " + RIGHT(card.card_number, 4) - - TALK icon + " **" + card.card_type + " Card**" - TALK " Number: " + masked_number - TALK " Expiry: " + card.expiry_date - - IF card.card_type = "credit" THEN - TALK " Limit: R$ " + FORMAT(card.credit_limit, "0.00") - TALK " Available: R$ " + FORMAT(card.available_limit, "0.00") - TALK " Current bill: R$ " + FORMAT(card.current_bill, "0.00") - END IF - - TALK " Status: " + card.status - TALK "" - NEXT - - TALK "What would you like to do?" - ADD SUGGESTION "View transactions" - ADD SUGGESTION "Block card" - ADD SUGGESTION "Request new card" - ADD SUGGESTION "Increase limit" -END SUB - -' Block card -SUB BlockCard(card_id) - TALK "⚠️ **Block Card**" - TALK "Are you sure you want to block this card?" - TALK "This action will prevent all transactions." - - ADD SUGGESTION "Yes, block it" - ADD SUGGESTION "Cancel" - - choice = HEAR - - IF choice CONTAINS "yes" THEN - ' Request reason - TALK "Please tell me why you're blocking the card:" - ADD SUGGESTION "Lost" - ADD SUGGESTION "Stolen" - ADD SUGGESTION "Suspicious activity" - ADD SUGGESTION "Temporary block" - - reason = HEAR - - ' Update card status - UPDATE "cards.csv" SET status = "blocked", blocked_reason = reason WHERE id = card_id - - ' Log the action - TABLE card_log - ROW GenerateID(), card_id, "blocked", reason, NOW() - END TABLE - SAVE "card_logs.csv", card_log - - TALK "✅ **Card blocked successfully**" - - IF reason CONTAINS "stolen" OR reason CONTAINS "lost" THEN - TALK "For your security, we recommend requesting a new card." - TALK "Would you like to request a replacement?" - - IF HEAR CONTAINS "yes" THEN - CALL RequestNewCard("replacement") - END IF - ELSE - TALK "You can unblock your card anytime through this chat or the app." - END IF - ELSE - TALK "Card block cancelled." - END IF -END SUB - -' Request credit limit increase -SUB RequestLimitIncrease() - user_id = GET USER ID - - cards = FIND "cards.csv" WHERE user_id = user_id AND card_type = "credit" AND status = "active" - - IF LEN(cards) = 0 THEN - TALK "You don't have an active credit card." - RETURN - END IF - - card = cards[0] - current_limit = card.credit_limit - - ' Check eligibility for increase - eligibility = CheckLimitIncreaseEligibility(card.id) - - IF eligibility.eligible THEN - TALK "📈 **Good news! You're eligible for a limit increase!**" - TALK "" - TALK "Current limit: R$ " + FORMAT(current_limit, "0.00") - TALK "Maximum available: R$ " + FORMAT(eligibility.max_limit, "0.00") - TALK "" - TALK "What limit would you like?" - - new_limit = HEAR - new_limit = ParseMoney(new_limit) - - IF new_limit > eligibility.max_limit THEN - TALK "The maximum limit available is R$ " + FORMAT(eligibility.max_limit, "0.00") - new_limit = eligibility.max_limit - END IF - - ' Approve instantly - UPDATE "cards.csv" SET credit_limit = new_limit WHERE id = card.id - - TALK "✅ **Limit increased!**" - TALK "New limit: R$ " + FORMAT(new_limit, "0.00") - TALK "Effective immediately." - ELSE - TALK "At this time, we cannot increase your limit." - TALK "Reason: " + eligibility.reason - TALK "Please try again in " + eligibility.wait_days + " days." - END IF -END SUB -``` - -### Investment Module - -```basic -' dialogs/investment.bas - -' View investments -SUB ViewInvestments() - user_id = GET USER ID - - investments = FIND "investments.csv" WHERE user_id = user_id - - IF LEN(investments) = 0 THEN - TALK "You don't have any investments yet." - TALK "Would you like to explore our investment options?" - - IF HEAR CONTAINS "yes" THEN - CALL ShowInvestmentOptions() - END IF - RETURN - END IF - - total_invested = 0 - total_earnings = 0 - - TALK "📊 **Your Investment Portfolio**" - TALK "" - - FOR EACH inv IN investments - earnings = inv.current_value - inv.invested_amount - earnings_pct = (earnings / inv.invested_amount) * 100 - - IF earnings >= 0 THEN - icon = "📈" - color = "green" - ELSE - icon = "📉" - color = "red" - END IF - - TALK icon + " **" + inv.product_name + "**" - TALK " Type: " + inv.product_type - TALK " Invested: R$ " + FORMAT(inv.invested_amount, "0.00") - TALK " Current: R$ " + FORMAT(inv.current_value, "0.00") - TALK " Return: " + FORMAT(earnings_pct, "0.00") + "%" - TALK "" - - total_invested = total_invested + inv.invested_amount - total_earnings = total_earnings + earnings - NEXT - - total_pct = (total_earnings / total_invested) * 100 - - TALK "💰 **Portfolio Summary**" - TALK "Total invested: R$ " + FORMAT(total_invested, "0.00") - TALK "Total value: R$ " + FORMAT(total_invested + total_earnings, "0.00") - TALK "Total return: " + FORMAT(total_pct, "0.00") + "%" -END SUB - -' Show investment options -SUB ShowInvestmentOptions() - TALK "💎 **Investment Options**" - TALK "" - TALK "**Fixed Income:**" - TALK "📌 CDB - from 100% CDI" - TALK "📌 LCI/LCA - Tax-free, from 95% CDI" - TALK "📌 Treasury Bonds - Government backed" - TALK "" - TALK "**Variable Income:**" - TALK "📊 Stocks - Direct investment" - TALK "📊 ETFs - Diversified funds" - TALK "📊 REITs - Real estate funds" - TALK "" - TALK "**Crypto:**" - TALK "🪙 Bitcoin, Ethereum, and more" - TALK "" - TALK "What interests you?" - - ADD SUGGESTION "Fixed Income" - ADD SUGGESTION "Stocks" - ADD SUGGESTION "Crypto" - ADD SUGGESTION "I need advice" -END SUB -``` - ---- - -## 4. Excel Clone (HTMX/Rust) - -### Architecture - -``` -┌─────────────────────────────────────────────────────────────────┐ -│ GENERAL BOTS SHEETS │ -├─────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ │ -│ │ Browser │◄──►│ HTMX/WS │◄──►│ Rust Backend │ │ -│ │ (Canvas) │ │ Updates │ │ (Calamine) │ │ -│ └─────────────┘ └──────────────┘ └─────────────────┘ │ -│ │ │ │ -│ │ ▼ │ -│ │ ┌─────────────────┐ │ -│ │ │ File Storage │ │ -│ │ │ (.gbdrive) │ │ -│ │ └─────────────────┘ │ -│ ▼ │ -│ ┌─────────────────────────────────────────────────────────┐ │ -│ │ FORMULA ENGINE │ │ -│ │ - 400+ Excel functions │ │ -│ │ - Array formulas │ │ -│ │ - Cross-sheet references │ │ -│ │ - Custom functions (BASIC integration) │ │ -│ └─────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────┘ -``` - -### Rust Backend - -```rust -// src/sheets/mod.rs - -use calamine::{Reader, Xlsx, DataType, Range}; -use rust_xlsxwriter::Workbook; -use std::collections::HashMap; - -pub mod engine; -pub mod formulas; -pub mod api; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SpreadsheetState { - pub id: Uuid, - pub name: String, - pub sheets: Vec, - pub active_sheet: usize, - pub modified: bool, - pub last_saved: Option>, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SheetState { - pub name: String, - pub cells: HashMap, - pub col_widths: HashMap, - pub row_heights: HashMap, - pub frozen_rows: usize, - pub frozen_cols: usize, - pub selection: Selection, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct CellRef { - pub row: usize, - pub col: usize, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct CellData { - pub value: CellValue, - pub formula: Option, - pub format: CellFormat, - pub style: CellStyle, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum CellValue { - Empty, - String(String), - Number(f64), - Boolean(bool), - Error(String), - DateTime(DateTime), -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct CellFormat { - pub number_format: String, - pub alignment: Alignment, - pub wrap_text: bool, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct CellStyle { - pub font: FontStyle, - pub fill: FillStyle, - pub border: BorderStyle, -} - -// Spreadsheet Engine -pub struct SpreadsheetEngine { - state: SpreadsheetState, - formula_engine: FormulaEngine, - dependency_graph: DependencyGraph, -} - -impl SpreadsheetEngine { - pub fn new() -> Self { - Self { - state: SpreadsheetState::default(), - formula_engine: FormulaEngine::new(), - dependency_graph: DependencyGraph::new(), - } - } - - pub fn load_xlsx(&mut self, path: &str) -> Result<(), Error> { - let mut workbook: Xlsx<_> = calamine::open_workbook(path)?; - - for sheet_name in workbook.sheet_names().to_owned() { - if let Some(Ok(range)) = workbook.worksheet_range(&sheet_name) { - let mut sheet = SheetState::new(&sheet_name); - - for (row_idx, row) in range.rows().enumerate() { - for (col_idx, cell) in row.iter().enumerate() { - let cell_ref = CellRef { row: row_idx, col: col_idx }; - let cell_data = self.convert_calamine_cell(cell); - sheet.cells.insert(cell_ref, cell_data); - } - } - - self.state.sheets.push(sheet); - } - } - - Ok(()) - } - - pub fn save_xlsx(&self, path: &str) -> Result<(), Error> { - let mut workbook = Workbook::new(); - - for sheet in &self.state.sheets { - let worksheet = workbook.add_worksheet(); - worksheet.set_name(&sheet.name)?; - - for (cell_ref, cell_data) in &sheet.cells { - match &cell_data.value { - CellValue::String(s) => { - worksheet.write_string(cell_ref.row as u32, cell_ref.col as u16, s)?; - } - CellValue::Number(n) => { - worksheet.write_number(cell_ref.row as u32, cell_ref.col as u16, *n)?; - } - CellValue::Boolean(b) => { - worksheet.write_boolean(cell_ref.row as u32, cell_ref.col as u16, *b)?; - } - _ => {} - } - - // Write formula if exists - if let Some(formula) = &cell_data.formula { - worksheet.write_formula( - cell_ref.row as u32, - cell_ref.col as u16, - formula - )?; - } - } - } - - workbook.save(path)?; - Ok(()) - } - - pub fn set_cell(&mut self, sheet: usize, row: usize, col: usize, value: &str) -> Vec { - let cell_ref = CellRef { row, col }; - - // Check if it's a formula - if value.starts_with('=') { - let formula = value[1..].to_string(); - let calculated = self.formula_engine.evaluate(&formula, &self.state.sheets[sheet]); - - self.state.sheets[sheet].cells.insert(cell_ref.clone(), CellData { - value: calculated, - formula: Some(formula), - format: CellFormat::default(), - style: CellStyle::default(), - }); - - // Update dependency graph - self.dependency_graph.update(&cell_ref, &formula); - } else { - // Parse as value - let cell_value = self.parse_value(value); - - self.state.sheets[sheet].cells.insert(cell_ref.clone(), CellData { - value: cell_value, - formula: None, - format: CellFormat::default(), - style: CellStyle::default(), - }); - } - - // Recalculate dependents - let updates = self.recalculate_dependents(&cell_ref); - - self.state.modified = true; - updates - } - - fn recalculate_dependents(&mut self, cell_ref: &CellRef) -> Vec { - let mut updates = Vec::new(); - let dependents = self.dependency_graph.get_dependents(cell_ref); - - for dep in dependents { - if let Some(cell) = self.state.sheets[self.state.active_sheet].cells.get_mut(&dep) { - if let Some(formula) = &cell.formula { - let new_value = self.formula_engine.evaluate( - formula, - &self.state.sheets[self.state.active_sheet] - ); - cell.value = new_value.clone(); - updates.push(CellUpdate { - row: dep.row, - col: dep.col, - value: new_value, - }); - } - } - } - - updates - } -} -``` - -### Formula Engine - -```rust -// src/sheets/formulas.rs - -use std::collections::HashMap; - -pub struct FormulaEngine { - functions: HashMap) -> CellValue>>, -} - -impl FormulaEngine { - pub fn new() -> Self { - let mut engine = Self { - functions: HashMap::new(), - }; - engine.register_builtin_functions(); - engine - } - - fn register_builtin_functions(&mut self) { - // Math functions - self.register("SUM", |args| { - let sum: f64 = args.iter() - .filter_map(|v| v.as_number()) - .sum(); - CellValue::Number(sum) - }); - - self.register("AVERAGE", |args| { - let numbers: Vec = args.iter() - .filter_map(|v| v.as_number()) - .collect(); - if numbers.is_empty() { - CellValue::Error("#DIV/0!".to_string()) - } else { - CellValue::Number(numbers.iter().sum::() / numbers.len() as f64) - } - }); - - self.register("MIN", |args| { - args.iter() - .filter_map(|v| v.as_number()) - .min_by(|a, b| a.partial_cmp(b).unwrap()) - .map(CellValue::Number) - .unwrap_or(CellValue::Error("#VALUE!".to_string())) - }); - - self.register("MAX", |args| { - args.iter() - .filter_map(|v| v.as_number()) - .max_by(|a, b| a.partial_cmp(b).unwrap()) - .map(CellValue::Number) - .unwrap_or(CellValue::Error("#VALUE!".to_string())) - }); - - self.register("COUNT", |args| { - CellValue::Number(args.iter() - .filter(|v| v.as_number().is_some()) - .count() as f64) - }); - - self.register("COUNTA", |args| { - CellValue::Number(args.iter() - .filter(|v| !matches!(v, CellValue::Empty)) - .count() as f64) - }); - - // Text functions - self.register("CONCATENATE", |args| { - let result: String = args.iter() - .map(|v| v.to_string()) - .collect(); - CellValue::String(result) - }); - - self.register("LEFT", |args| { - if args.len() >= 2 { - let text = args[0].to_string(); - let n = args[1].as_number().unwrap_or(1.0) as usize; - CellValue::String(text.chars().take(n).collect()) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - self.register("RIGHT", |args| { - if args.len() >= 2 { - let text = args[0].to_string(); - let n = args[1].as_number().unwrap_or(1.0) as usize; - let start = text.len().saturating_sub(n); - CellValue::String(text.chars().skip(start).collect()) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - self.register("MID", |args| { - if args.len() >= 3 { - let text = args[0].to_string(); - let start = (args[1].as_number().unwrap_or(1.0) as usize).saturating_sub(1); - let n = args[2].as_number().unwrap_or(1.0) as usize; - CellValue::String(text.chars().skip(start).take(n).collect()) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - self.register("LEN", |args| { - if let Some(text) = args.get(0) { - CellValue::Number(text.to_string().len() as f64) - } else { - CellValue::Number(0.0) - } - }); - - self.register("TRIM", |args| { - if let Some(text) = args.get(0) { - CellValue::String(text.to_string().trim().to_string()) - } else { - CellValue::String(String::new()) - } - }); - - self.register("UPPER", |args| { - if let Some(text) = args.get(0) { - CellValue::String(text.to_string().to_uppercase()) - } else { - CellValue::String(String::new()) - } - }); - - self.register("LOWER", |args| { - if let Some(text) = args.get(0) { - CellValue::String(text.to_string().to_lowercase()) - } else { - CellValue::String(String::new()) - } - }); - - // Logical functions - self.register("IF", |args| { - if args.len() >= 3 { - let condition = args[0].as_bool().unwrap_or(false); - if condition { - args[1].clone() - } else { - args[2].clone() - } - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - self.register("AND", |args| { - CellValue::Boolean(args.iter().all(|v| v.as_bool().unwrap_or(false))) - }); - - self.register("OR", |args| { - CellValue::Boolean(args.iter().any(|v| v.as_bool().unwrap_or(false))) - }); - - self.register("NOT", |args| { - if let Some(val) = args.get(0) { - CellValue::Boolean(!val.as_bool().unwrap_or(false)) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - // Lookup functions - self.register("VLOOKUP", |args| { - // Implementation for VLOOKUP - CellValue::Error("#N/A".to_string()) // Placeholder - }); - - self.register("HLOOKUP", |args| { - // Implementation for HLOOKUP - CellValue::Error("#N/A".to_string()) // Placeholder - }); - - self.register("INDEX", |args| { - // Implementation for INDEX - CellValue::Error("#REF!".to_string()) // Placeholder - }); - - self.register("MATCH", |args| { - // Implementation for MATCH - CellValue::Error("#N/A".to_string()) // Placeholder - }); - - // Date functions - self.register("TODAY", |_args| { - CellValue::DateTime(Utc::now()) - }); - - self.register("NOW", |_args| { - CellValue::DateTime(Utc::now()) - }); - - self.register("YEAR", |args| { - if let Some(CellValue::DateTime(dt)) = args.get(0) { - CellValue::Number(dt.year() as f64) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - self.register("MONTH", |args| { - if let Some(CellValue::DateTime(dt)) = args.get(0) { - CellValue::Number(dt.month() as f64) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - self.register("DAY", |args| { - if let Some(CellValue::DateTime(dt)) = args.get(0) { - CellValue::Number(dt.day() as f64) - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - // Financial functions - self.register("PMT", |args| { - if args.len() >= 3 { - let rate = args[0].as_number().unwrap_or(0.0); - let nper = args[1].as_number().unwrap_or(0.0); - let pv = args[2].as_number().unwrap_or(0.0); - - if rate == 0.0 { - CellValue::Number(-pv / nper) - } else { - let pmt = pv * rate * (1.0 + rate).powf(nper) / - ((1.0 + rate).powf(nper) - 1.0); - CellValue::Number(-pmt) - } - } else { - CellValue::Error("#VALUE!".to_string()) - } - }); - - // Add 400+ more functions... - } - - fn register(&mut self, name: &str, f: F) - where - F: Fn(Vec) -> CellValue + 'static, - { - self.functions.insert(name.to_uppercase(), Box::new(f)); - } - - pub fn evaluate(&self, formula: &str, sheet: &SheetState) -> CellValue { - // Parse and evaluate formula - let tokens = self.tokenize(formula); - let ast = self.parse(tokens); - self.eval_ast(&ast, sheet) - } -} -``` - -### HTMX UI Component - -```html - -{% extends "base.html" %} - -{% block title %}Sheets - General Bots{% endblock %} - -{% block content %} -
- -
-
- - - - -
- -
- - - - - -
- -
- - - - - - - - - - -
- -
- - - -
- -
- -
- -
- -
-
- - -
-
A1
-
fx
- -
- - -
- - - - - -
- - -
-
- -
- -
- - -
- Ready - - - -
- - - - - - -
- - - - -{% endblock %} -``` - ---- - -## 5. Word Editor for .docx - -### Architecture - -```rust -// src/docs/mod.rs - -use docx_rs::{Docx, Paragraph, Run, Table, TableCell, TableRow}; - -pub struct DocumentEditor { - document: Docx, - file_path: Option, - modified: bool, -} - -impl DocumentEditor { - pub fn new() -> Self { - Self { - document: Docx::new(), - file_path: None, - modified: false, - } - } - - pub fn open(path: &str) -> Result { - let file = std::fs::File::open(path)?; - let document = docx_rs::read_docx(&file)?; - - Ok(Self { - document, - file_path: Some(path.to_string()), - modified: false, - }) - } - - pub fn save(&self, path: &str) -> Result<(), Error> { - let file = std::fs::File::create(path)?; - self.document.build().pack(file)?; - Ok(()) - } - - pub fn add_paragraph(&mut self, text: &str, style: &ParagraphStyle) -> &mut Self { - let mut paragraph = Paragraph::new(); - let mut run = Run::new().add_text(text); - - if style.bold { - run = run.bold(); - } - if style.italic { - run = run.italic(); - } - if let Some(size) = style.font_size { - run = run.size(size * 2); // half-points - } - - paragraph = paragraph.add_run(run); - self.document = std::mem::take(&mut self.document).add_paragraph(paragraph); - self.modified = true; - self - } - - pub fn to_html(&self) -> String { - // Convert document to HTML for editing - let mut html = String::new(); - // Implementation... - html - } - - pub fn from_html(&mut self, html: &str) -> Result<(), Error> { - // Parse HTML and update document - Ok(()) - } -} -``` - -### HTMX Word Editor UI - -```html - -{% extends "base.html" %} - -{% block title %}Documents - General Bots{% endblock %} - -{% block content %} -
- -
-
- - - - - -
- -
- - - - - -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - - -
- -
- -
-
- - -
-
-
- - -
-
- -
-
- - -
- Page 1 of 1 - 0 words - 0 characters - Saved -
- - - -
- - - - -{% endblock %} -``` - ---- - -## 6. M365/Office Competitive Analysis - -### Feature Comparison Matrix - -| Feature | Microsoft 365 | Google Workspace | General Bots | Status | -|---------|---------------|------------------|--------------|--------| -| **Email** | Outlook | Gmail | ✅ Mail | Complete | -| **Calendar** | Outlook Calendar | Google Calendar | ✅ Calendar | Complete | -| **File Storage** | OneDrive | Google Drive | ✅ .gbdrive | Complete | -| **Word Processing** | Word | Docs | 🔄 Docs Editor | In Progress | -| **Spreadsheets** | Excel | Sheets | 🔄 Sheets Editor | In Progress | -| **Presentations** | PowerPoint | Slides | 📋 Planned | Planned | -| **Video Calls** | Teams | Meet | 🔄 Meet | In Progress | -| **Chat** | Teams Chat | Google Chat | ✅ Chat | Complete | -| **AI Assistant** | Copilot | Gemini | ✅ Multi-LLM | Complete | -| **Tasks** | To Do/Planner | Tasks | ✅ Tasks | Complete | -| **Forms** | Forms | Forms | ✅ Forms | Complete | -| **Notes** | OneNote | Keep | 📋 Planned | Planned | -| **Whiteboard** | Whiteboard | Jamboard | 📋 Planned | Planned | - -### Missing Features to Implement - -```rust -// Priority 1: Core Office Features -// - Presentations engine (PowerPoint/Slides equivalent) -// - Real-time collaboration (multiple users editing) -// - Version history and restore -// - Comments and suggestions mode - -// Priority 2: Copilot/Gemini Parity -// - AI in documents (rewrite, summarize, expand) -// - AI in spreadsheets (formula generation, data analysis) -// - AI in email (compose, reply, summarize threads) -// - AI in meetings (transcription, summary, action items) - -// Priority 3: Enterprise Features -// - Admin console -// - Compliance center (eDiscovery, legal hold) -// - Data loss prevention -// - Retention policies -// - Audit logs (already have basic) -``` - ---- - -## 7. Google/MS Graph API Compatibility - -### API Endpoints to Implement - -```rust -// src/api/compat/google.rs - -// Google Drive API compatible endpoints -// GET /drive/v3/files -// POST /drive/v3/files -// GET /drive/v3/files/{fileId} -// DELETE /drive/v3/files/{fileId} -// PATCH /drive/v3/files/{fileId} - -// Google Calendar API compatible endpoints -// GET /calendar/v3/calendars/{calendarId}/events -// POST /calendar/v3/calendars/{calendarId}/events -// GET /calendar/v3/calendars/{calendarId}/events/{eventId} - -// Google Gmail API compatible endpoints -// GET /gmail/v1/users/{userId}/messages -// POST /gmail/v1/users/{userId}/messages/send -// GET /gmail/v1/users/{userId}/threads - -// src/api/compat/msgraph.rs - -// Microsoft Graph API compatible endpoints -// GET /v1.0/me/drive/root/children -// GET /v1.0/me/messages -// POST /v1.0/me/sendMail -// GET /v1.0/me/calendar/events -// POST /v1.0/me/calendar/events -// GET /v1.0/me/contacts - -pub fn configure_compat_routes(cfg: &mut web::ServiceConfig) { - // Google API compatibility - cfg.service( - web::scope("/drive/v3") - .route("/files", web::get().to(google_list_files)) - .route("/files", web::post().to(google_create_file)) - .route("/files/{fileId}", web::get().to(google_get_file)) - ); - - // MS Graph API compatibility - cfg.service( - web::scope("/v1.0") - .route("/me/drive/root/children", web::get().to(graph_list_files)) - .route("/me/messages", web::get().to(graph_list_messages)) - .route("/me/sendMail", web::post().to(graph_send_mail)) - ); -} -``` - ---- - -## 8. Copilot/Gemini Feature Parity - -### AI Features Checklist - -| Feature | Copilot | Gemini | General Bots | BASIC Keyword | -|---------|---------|--------|--------------|---------------| -| Chat with AI | ✅ | ✅ | ✅ | `LLM` | -| Web search | ✅ | ✅ | 📋 | `SEARCH WEB` | -| Image generation | ✅ | ✅ | ✅ | `IMAGE` | -| Code generation | ✅ | ✅ | ✅ | `LLM` | -| Document summary | ✅ | ✅ | ✅ | `LLM` with file | -| Email compose | ✅ | ✅ | ✅ | `SEND MAIL` | -| Meeting summary | ✅ | ✅ | 📋 | `SUMMARIZE MEETING` | -| Data analysis | ✅ | ✅ | ✅ | `AGGREGATE` | -| Create presentations | ✅ | ✅ | 📋 | `CREATE PPT` | -| Voice input | ✅ | ✅ | ✅ | Voice API | -| Multi-modal | ✅ | ✅ | ✅ | `SEE`, `IMAGE` | -| Tool use | ✅ | ✅ | ✅ | `USE TOOL` | -| Memory/context | ✅ | ✅ | ✅ | `SET CONTEXT` | -| Multi-turn | ✅ | ✅ | ✅ | Built-in | - ---- - -## 9. Attachment System (Plus Button) - -### Implementation - -```rust -// src/api/attachments.rs - -#[derive(Debug, Serialize, Deserialize)] -pub struct Attachment { - pub id: Uuid, - pub message_id: Option, - pub file_type: AttachmentType, - pub file_name: String, - pub file_size: i64, - pub mime_type: String, - pub storage_path: String, - pub thumbnail_path: Option, - pub created_at: DateTime, -} - -#[derive(Debug, Serialize, Deserialize)] -pub enum AttachmentType { - Image, - Document, - Audio, - Video, - Code, - Archive, - Other, -} - -pub async fn upload_attachment( - State(state): State>, - Extension(user): Extension, - mut multipart: Multipart, -) -> Result, ApiError> { - while let Some(field) = multipart.next_field().await? { - let name = field.name().unwrap_or("file").to_string(); - let file_name = field.file_name().unwrap_or("unnamed").to_string(); - let content_type = field.content_type().unwrap_or("application/octet-stream").to_string(); - let data = field.bytes().await?; - - // Determine attachment type - let file_type = detect_attachment_type(&content_type, &file_name); - - // Store file - let storage_path = store_attachment(&state, &user, &data, &file_name).await?; - - // Generate thumbnail for images/videos - let thumbnail_path = if matches!(file_type, AttachmentType::Image | AttachmentType::Video) { - Some(generate_thumbnail(&storage_path).await?) - } else { - None - }; - - // Create attachment record - let attachment = Attachment { - id: Uuid::new_v4(), - message_id: None, - file_type, - file_name, - file_size: data.len() as i64, - mime_type: content_type, - storage_path, - thumbnail_path, - created_at: Utc::now(), - }; - - // Save to database - save_attachment(&state, &attachment).await?; - - return Ok(Json(attachment)); - } - - Err(ApiError::BadRequest("No file provided".to_string())) -} -``` - ---- - -## 10. Conversation Branching - -### Database Schema - -```sql --- Conversation branches -CREATE TABLE conversation_branches ( - id UUID PRIMARY KEY, - parent_session_id UUID NOT NULL, - branch_session_id UUID NOT NULL, - branch_from_message_id UUID NOT NULL, - branch_name VARCHAR(255), - created_at TIMESTAMPTZ DEFAULT NOW(), - FOREIGN KEY (parent_session_id) REFERENCES sessions(id), - FOREIGN KEY (branch_session_id) REFERENCES sessions(id), - FOREIGN KEY (branch_from_message_id) REFERENCES messages(id) -); -``` - -### Implementation - -```rust -// src/api/branches.rs - -pub async fn create_branch( - State(state): State>, - Extension(user): Extension, - Json(req): Json, -) -> Result, ApiError> { - // Create new session for branch - let branch_session = create_session(&state, user.user_id, user.bot_id).await?; - - // Copy messages up to branch point - copy_messages_to_branch( - &state, - user.id, - branch_session.id, - req.branch_from_message_id, - ).await?; - - // Create branch record - let branch = ConversationBranch { - id: Uuid::new_v4(), - parent_session_id: user.id, - branch_session_id: branch_session.id, - branch_from_message_id: req.branch_from_message_id, - branch_name: req.name, - created_at: Utc::now(), - }; - - save_branch(&state, &branch).await?; - - Ok(Json(BranchResponse { - branch_id: branch.id, - session_id: branch_session.id, - })) -} -``` - -### UI Component - -```html - -
-
{{ message.content }}
-
- - -
-
- - - -``` - -### Qualification Bot - -Where Intercom uses a qualification workflow, General Bots achieves the same result through BASIC scripts: - -```basic -' lead-qualification.bas -PARAM source AS string - -DESCRIPTION "Qualify incoming leads" - -TALK "Welcome! I'd love to learn more about you." - -TALK "What's your name?" -HEAR name AS NAME - -TALK "And your work email?" -HEAR email AS EMAIL - -TALK "What company are you with?" -HEAR company - -TALK "What's your role?" -HEAR role AS "Executive", "Manager", "Individual Contributor", "Student", "Other" - -TALK "What brings you here today?" -HEAR interest AS "Product Demo", "Pricing", "Support", "Partnership", "Just Exploring" - -' Score the lead -WITH lead_data - .name = name - .email = email - .company = company - .role = role - .interest = interest - .source = source -END WITH - -score = SCORE LEAD lead_data - -' Route based on qualification -IF score.status = "hot" OR interest = "Product Demo" THEN - TALK "Great! Let me schedule a demo for you." - TALK "When works best?" - HEAR preferred_time - - SEND MAIL TO "sales@company.com" SUBJECT "Hot Lead - Demo Request" BODY lead_data - CREATE TASK "Demo call with " + name DUE DATEADD(NOW(), 1, "day") - - TALK "Our team will reach out within 24 hours to confirm your demo!" - -ELSEIF interest = "Pricing" THEN - USE KB "pricing" - pricing_info = LLM "Provide a brief pricing overview" - TALK pricing_info - TALK "Would you like to speak with someone about your specific needs?" - -ELSE - USE KB "getting-started" - TALK "Here's what you can do to get started..." - answer = LLM "Give a brief getting started guide" - TALK answer -END IF - -INSERT "leads", lead_data -``` - -### Proactive Messages - -Intercom's outbound messages translate to scheduled BASIC scripts in General Bots: - -```basic -' proactive-engagement.bas -SET SCHEDULE "every hour" - -' Find users who might need help -inactive_sessions = FIND "sessions", "last_activity < DATEADD(NOW(), -5, 'minute') AND page_views > 3 AND not contacted" - -FOR EACH session IN inactive_sessions - ' Send proactive message - SEND TO session.id MESSAGE "Need any help? I'm here if you have questions!" - UPDATE "sessions", "id = '" + session.id + "'", #{contacted: true} -NEXT session -``` - -### Resolution Bot (AI Answers) - -While Intercom's Fin charges $0.99 per resolution, General Bots provides the same capability at no additional cost: - -```basic -' ai-resolution.bas -USE KB "help-center" -USE KB "product-docs" -USE KB "faq" - -SET CONTEXT "You are a helpful support assistant. Answer questions accurately based on the knowledge base. If you're not confident in the answer, say so and offer to connect with a human." - -TALK "How can I help you today?" -HEAR question - -answer = LLM question - -' Check confidence (you can implement confidence scoring) -IF CONTAINS(answer, "I'm not sure") OR CONTAINS(answer, "I don't have") THEN - TALK answer - TALK "Would you like me to connect you with a support agent?" - HEAR wants_human AS BOOLEAN - IF wants_human THEN - CALL REQUEST_HUMAN_HANDOFF() - END IF -ELSE - TALK answer - - ' Track resolution - INSERT "resolutions", #{ - question: question, - answer: answer, - resolved: true, - timestamp: NOW() - } -END IF -``` - -### Customer Segments - -Intercom's user segments become database queries and scheduled scripts in General Bots: - -```basic -' segment-customers.bas -SET SCHEDULE "every day at 6am" - -customers = FIND "customers", "1=1" - -FOR EACH customer IN customers - segment = "standard" - - IF customer.total_spent > 10000 THEN - segment = "enterprise" - ELSEIF customer.total_spent > 1000 THEN - segment = "premium" - ELSEIF customer.signup_date > DATEADD(NOW(), -30, "day") THEN - segment = "new" - ELSEIF customer.last_activity < DATEADD(NOW(), -90, "day") THEN - segment = "at-risk" - END IF - - UPDATE "customers", "id = '" + customer.id + "'", #{segment: segment} -NEXT customer -``` - -### Targeted Campaigns - -```basic -' win-back-campaign.bas -SET SCHEDULE "every monday at 10am" - -' Find at-risk customers -at_risk = FIND "customers", "segment = 'at-risk' AND not win_back_sent" - -FOR EACH customer IN at_risk - USE KB "product-updates" - personalized_message = LLM "Write a brief, friendly win-back message for " + customer.name + " who hasn't used our product in 3 months. Mention recent improvements." - - SEND MAIL TO customer.email SUBJECT "We miss you, " + customer.name + "!" BODY personalized_message - - UPDATE "customers", "id = '" + customer.id + "'", #{win_back_sent: true, win_back_date: NOW()} -NEXT customer -``` - -## Multi-Channel Support - -### Intercom Channels - -Intercom supports Web Messenger, Mobile SDK, Email, and SMS as an add-on. - -### General Bots Channels - -All channels use the same BASIC scripts, making development and maintenance simpler: - -```basic -' Same bot works everywhere -USE KB "support" - -TALK "How can I help?" -HEAR question -answer = LLM question -TALK answer - -' Channel-specific handling if needed -IF channel = "whatsapp" THEN - ' WhatsApp-specific features -ELSEIF channel = "email" THEN - ' Email formatting -END IF -``` - -General Bots supports web chat, WhatsApp Business, Teams, Slack, Telegram, SMS, Email, and voice through LiveKit. - -## Reporting and Analytics - -### Conversation Metrics - -```basic -' daily-metrics.bas -SET SCHEDULE "every day at 11pm" - -today = FORMAT(NOW(), "yyyy-MM-dd") - -conversations = AGGREGATE "conversations", "COUNT", "id", "DATE(created_at) = '" + today + "'" -resolutions = AGGREGATE "resolutions", "COUNT", "id", "DATE(timestamp) = '" + today + "' AND resolved = true" -avg_response_time = AGGREGATE "conversations", "AVG", "first_response_seconds", "DATE(created_at) = '" + today + "'" - -WITH daily_report - .date = today - .total_conversations = conversations - .ai_resolutions = resolutions - .resolution_rate = ROUND(resolutions / conversations * 100, 1) - .avg_response_time = ROUND(avg_response_time / 60, 1) -END WITH - -INSERT "daily_metrics", daily_report - -SEND MAIL TO "support-lead@company.com" SUBJECT "Daily Support Metrics - " + today BODY daily_report -``` - -## Migration Checklist - -### Pre-Migration - -Before beginning the migration, export all Intercom data including conversations, contacts, and articles. Document your custom bot workflows so you can recreate them in BASIC. List all integrations that connect to Intercom. Note any custom attributes and tags you use. Set up your General Bots environment with the necessary infrastructure. - -### Migration - -During the migration phase, convert your Help Center content to the .gbkb structure. Create support bot scripts that replicate your Intercom workflows. Implement the human handoff flow for seamless escalation. Set up notification channels for your support team. Configure the chat widget for your website. Import customer data from your Intercom export. - -### Post-Migration - -After migration, test all conversation flows to ensure they work correctly. Verify knowledge base accuracy by asking common questions. Train your support team on the new interface. Run parallel support briefly by keeping both systems active. Once validated, redirect the widget embed code to General Bots and cancel your Intercom subscription. - -## What You Gain - -Migrating to General Bots provides several significant advantages. There is no per-seat pricing, so you can add unlimited agents without increasing costs. Native AI comes without per-resolution fees since you can use any LLM provider. Full customization is possible because you have complete source access to modify any aspect of the system. Data ownership means all conversations stay on your infrastructure. Automation power lets you go beyond simple workflows with full BASIC scripting. Multi-channel support is native, meaning the same bot works across all channels without add-ons. - -## See Also - -- [Projects](../chapter-11-features/projects.md) - Organizing support queues -- [HEAR Validation](../chapter-06-gbdialog/keyword-hear.md) - Input validation -- [Lead Scoring](../chapter-06-gbdialog/keywords-lead-scoring.md) - Qualification -- [Platform Comparison](./comparison-matrix.md) - Full feature comparison \ No newline at end of file diff --git a/docs/src/chapter-14-migration/kb-migration.md b/docs/src/chapter-14-migration/kb-migration.md deleted file mode 100644 index 0e89efd0..00000000 --- a/docs/src/chapter-14-migration/kb-migration.md +++ /dev/null @@ -1,55 +0,0 @@ -# Knowledge Base Migration - -Converting documents from cloud storage to General Bots knowledge bases. - -## Overview - -Knowledge base migration involves moving documents from various sources into `.gbkb` packages where they become searchable through General Bots. - -## Source Systems - -Common document sources include SharePoint document libraries, Google Drive folders, OneDrive and Dropbox storage, Confluence spaces, and traditional file servers. - -## Document Types - -General Bots supports a variety of document formats for knowledge base ingestion. These include PDF files, Office documents such as Word, Excel, and PowerPoint, plain text files, Markdown files, and HTML pages. - -## Migration Process - -### 1. Export - -Begin by downloading documents from the source system. Preserve the folder structure to maintain organizational context, and retain metadata where possible for future reference. - -### 2. Organize - -Group related documents into logical collections. Create meaningful organizational structures and remove any duplicate documents that would clutter the knowledge base. - -### 3. Import - -Place the organized documents in `.gbkb` folders within your bot package. General Bots indexes these documents automatically, making them searchable for RAG-powered responses. - -## Considerations - -### Volume - -Large document sets require additional time to index. Consider staging the migration in batches rather than importing everything at once. Monitor disk space throughout the process to ensure adequate storage remains available. - -### Quality - -Before migration, clean up outdated content that no longer reflects current information. Remove duplicate documents to avoid confusing the AI with conflicting information. Fix any broken or corrupted files that would fail during indexing. - -### Structure - -Maintain logical organization within your knowledge base. Use meaningful folder names that describe the content within. Group documents by topic or department to improve retrieval accuracy. - -## Format Conversion - -Some formats require conversion before import. Web pages should be converted to PDF or Markdown for reliable indexing. Database content should be exported to CSV format. Proprietary formats from specialized applications need conversion to standard formats that the indexing system can process. - -## Testing - -After migration, verify the knowledge base functions correctly. Test that search works across the imported documents. Check that users can access all migrated content. Run sample queries to ensure the AI provides accurate responses based on the imported knowledge. - -## Next Steps - -Review the [Overview](./overview.md) for general migration concepts. See [Validation](./validation.md) for detailed testing procedures to verify your migration succeeded. \ No newline at end of file diff --git a/docs/src/chapter-14-migration/microsoft-365.md b/docs/src/chapter-14-migration/microsoft-365.md deleted file mode 100644 index b48ba9a0..00000000 --- a/docs/src/chapter-14-migration/microsoft-365.md +++ /dev/null @@ -1,105 +0,0 @@ -# Microsoft 365 Migration Guide - -Migrating from Microsoft 365 to self-hosted infrastructure. - -## Overview - -Microsoft 365 (formerly Office 365) includes multiple services that need to be migrated to different self-hosted components. - -## Service Mapping - -| Microsoft 365 Service | Self-Hosted Alternative | Migration Tool | -|----------------------|------------------------|----------------| -| Exchange Online | Mail server (Stalwart, etc.) | imapsync | -| OneDrive | MinIO or Nextcloud | rclone | -| SharePoint | MinIO + Wiki/CMS | rclone + export tools | -| Teams | Mattermost, General Bots, etc. | Export/Import APIs | -| Azure AD | Keycloak, Authentik, Zitadel | LDAP export | - -## Migration Steps - -### 1. Email Migration (Exchange Online) - -Before beginning the email migration, ensure IMAP access is enabled in Exchange Online, your target mail server is configured, and you have user credentials or app passwords available. - -The migration process uses imapsync for mailbox migration. Migrate in batches to avoid throttling from Microsoft's servers, and preserve folder structure and flags during transfer. - -Keep in mind that Exchange uses proprietary features such as categories that may not transfer cleanly. Calendar and contacts require separate migration using CalDAV and CardDAV protocols. Shared mailboxes require special handling and may need to be migrated individually. - -### 2. File Migration (OneDrive/SharePoint) - -Prerequisites include having the OneDrive sync client or API access configured, sufficient storage on the target system, and adequate network bandwidth for the transfer. - -Use rclone with the OneDrive backend for the migration process. Maintain folder structure during transfer and preserve timestamps where possible. - -Be aware that SharePoint metadata won't transfer automatically and may need manual recreation. Version history is typically lost during migration. Permissions need to be recreated on the target system. - -### 3. User Migration (Azure AD) - -Prepare for user migration by setting up Azure AD Connect or API access, and ensure your target identity provider is ready to receive users. - -Export users via PowerShell or Graph API, transform the data to the target format such as LDIF or JSON, then import to your new identity provider. - -Important considerations include that passwords cannot be exported from Azure AD, so users will need to reset their passwords. MFA settings require reconfiguration on the new system. Group memberships need mapping to equivalent structures in the target system. - -## Common Challenges - -### API Throttling - -Microsoft throttles API calls to protect their infrastructure. Plan for a slow, steady migration rather than attempting bulk transfers. Use batch operations where possible and consider running migrations during off-peak hours. - -### Data Volume - -Large organizations may have accumulated terabytes of OneDrive and SharePoint data, years of email history, and thousands of users. Factor this into your timeline and resource planning. - -### Feature Parity - -Some M365 features have no direct equivalent in self-hosted solutions. Power Automate workflows will need to be recreated using different automation tools. SharePoint lists and forms require alternative solutions. Teams channel history may be difficult to preserve in its original format. - -## Tools and Utilities - -### PowerShell for Export - -The Azure AD PowerShell module handles user export operations. Exchange Online PowerShell provides mailbox information. SharePoint Online PowerShell helps with site inventory and metadata export. - -### Graph API - -The Graph API provides programmatic access to most M365 services and is useful for custom migration scripts. Using it requires app registration and appropriate permissions in your Azure tenant. - -### Third-Party Tools - -Commercial options include BitTitan MigrationWiz and Sharegate, which provide guided migration experiences. Various open-source scripts are available on GitHub for more customized approaches. - -## Post-Migration - -### DNS Changes - -Update MX records to point to your new email server. Update autodiscover records for email client configuration. Consider keeping a hybrid setup temporarily to catch any missed emails during the transition. - -### User Communication - -Provide new login credentials to all users. Document any changed procedures and differences from the M365 experience. Offer training sessions on the new tools to ensure smooth adoption. - -### Validation - -Verify email delivery works correctly in both directions. Test file access to ensure permissions transferred properly. Confirm authentication works for all migrated users. - -## Cost Considerations - -### Subscription Overlap - -You may need to maintain M365 subscriptions during the migration period. Consider read-only licenses for archive access if you need to retain access to historical data. - -### Data Transfer Costs - -Factor in egress charges from Microsoft when transferring large amounts of data. Account for bandwidth costs if transferring over the internet rather than dedicated connections. - -## Timeline Estimates - -Small organizations with fewer than 50 users typically complete migration in 1-2 weeks. Medium organizations with 50-500 users usually require 1-2 months. Large organizations with more than 500 users should plan for 2-6 months. - -Factors affecting timeline include data volume, network speed, complexity of the existing setup, and user training needs. - -## Next Steps - -Review the [Common Concepts](./common-concepts.md) guide for general migration principles. See [Validation](./validation.md) for detailed testing procedures to verify your migration succeeded. \ No newline at end of file diff --git a/docs/src/chapter-14-migration/n8n.md b/docs/src/chapter-14-migration/n8n.md deleted file mode 100644 index 551b6cac..00000000 --- a/docs/src/chapter-14-migration/n8n.md +++ /dev/null @@ -1,361 +0,0 @@ -# n8n Migration Guide - -Migrating workflows and automations from n8n to General Bots. - -General Bots - -## Overview - -n8n is a workflow automation platform with a visual node-based editor. General Bots provides equivalent automation capabilities through BASIC scripting, offering more flexibility and integrated features without execution limits. - -## Why Migrate - -| Aspect | n8n | General Bots | -|--------|-----|--------------| -| Automation | Visual workflows | BASIC scripts (more powerful) | -| Pricing | Per-execution limits | Unlimited executions | -| AI Integration | Via API nodes | Native LLM keywords | -| Chat/Bot | Not included | Full multi-channel | -| Productivity Suite | Not included | Email, calendar, files, tasks | -| Knowledge Base | Not included | Built-in RAG | -| Self-hosting | Available | Available | - -## Workflow Mapping - -### Triggers - -| n8n Trigger | General Bots Equivalent | -|-------------|------------------------| -| Schedule Trigger | `SET SCHEDULE` | -| Webhook | `WEBHOOK` | -| Email Trigger (IMAP) | `ON "email:received"` | -| Database Trigger | `ON "table:tablename:insert"` | -| Manual Trigger | Direct script execution | -| Cron | `SET SCHEDULE "cron expression"` | - -### Common Nodes - -| n8n Node | General Bots Equivalent | -|----------|------------------------| -| HTTP Request | `GET`, `POST`, `PUT`, `DELETE` | -| Set | Variable assignment | -| IF | `IF/THEN/ELSE/END IF` | -| Switch | `SWITCH/CASE/END SWITCH` | -| Code (JavaScript) | BASIC script | -| Function | BASIC subroutines | -| Merge | Array operations | -| Split In Batches | `FOR EACH` | -| Wait | `WAIT` | -| Send Email | `SEND MAIL` | -| Slack | `POST` to Slack webhook | -| Discord | `POST` to Discord webhook | -| Google Sheets | `GET`/`POST` to Sheets API | -| Airtable | `GET`/`POST` to Airtable API | -| MySQL/PostgreSQL | `FIND`, `INSERT`, `UPDATE`, `DELETE` | -| MongoDB | `GET`/`POST` to MongoDB API | - -## Migration Examples - -### Scheduled Data Sync - -**n8n workflow:** -``` -Schedule Trigger → HTTP Request → IF → Google Sheets -``` - -**General Bots equivalent:** - -```basic -SET SCHEDULE "every hour" - -data = GET "https://api.example.com/data" - -IF data.status = "active" THEN - FOR EACH item IN data.items - INSERT "synced_data", #{ - id: item.id, - name: item.name, - value: item.value, - synced_at: NOW() - } - NEXT item -END IF - -TALK "Synced " + LEN(data.items) + " items" -``` - -### Webhook Processing - -**n8n workflow:** -``` -Webhook → Set → IF → Send Email + Slack -``` - -**General Bots equivalent:** - -```basic -WEBHOOK "order-received" - -order = body -customer_name = order.customer.name -order_total = order.total - -IF order_total > 1000 THEN - SEND MAIL TO "sales@company.com" SUBJECT "Large Order" BODY "Order from " + customer_name + ": $" + order_total - - POST "https://hooks.slack.com/services/xxx", #{ - text: "Large order received: $" + order_total - } -END IF -``` - -### Multi-Step API Orchestration - -**n8n workflow:** -``` -Webhook → HTTP Request (API 1) → Code → HTTP Request (API 2) → IF → Multiple outputs -``` - -**General Bots equivalent:** - -```basic -WEBHOOK "process-lead" - -lead = body - -' Step 1: Enrich lead data -enriched = POST "https://api.clearbit.com/enrich", #{email: lead.email} - -' Step 2: Score the lead -WITH lead_data - .email = lead.email - .company = enriched.company.name - .industry = enriched.company.industry - .size = enriched.company.employees -END WITH - -score = SCORE LEAD lead_data - -' Step 3: Route based on score -IF score.status = "hot" THEN - POST "https://api.salesforce.com/leads", lead_data - SEND MAIL TO "sales@company.com" SUBJECT "Hot Lead" BODY lead_data -ELSEIF score.status = "warm" THEN - POST "https://api.hubspot.com/contacts", lead_data -ELSE - INSERT "cold_leads", lead_data -END IF -``` - -### Error Handling - -**n8n approach:** Error Trigger node - -**General Bots equivalent:** - -```basic -SET SCHEDULE "every 5 minutes" - -TRY - result = GET "https://api.example.com/health" - IF result.status <> "healthy" THEN - THROW "Service unhealthy: " + result.message - END IF -CATCH - SEND MAIL TO "ops@company.com" SUBJECT "Alert: Service Down" BODY ERROR_MESSAGE - POST "https://hooks.slack.com/services/xxx", #{text: "Service alert: " + ERROR_MESSAGE} -END TRY -``` - -## Exporting n8n Workflows - -### Export Process - -1. In n8n, select the workflow -2. Click the three-dot menu → Download -3. Save the JSON file -4. Analyze nodes and connections -5. Translate to BASIC script - -### JSON Structure Analysis - -n8n exports workflows as JSON: - -```json -{ - "nodes": [ - {"type": "n8n-nodes-base.httpRequest", "parameters": {...}}, - {"type": "n8n-nodes-base.if", "parameters": {...}} - ], - "connections": {...} -} -``` - -Map each node type to the equivalent BASIC keyword. - -## Feature Comparison - -### What You Gain - -**Native AI integration:** -```basic -USE KB "company-docs" -response = LLM "Analyze this data and provide insights: " + data -``` - -**Multi-channel chat:** -```basic -TALK "How can I help you?" -HEAR question -answer = LLM question -TALK answer -``` - -**Built-in productivity:** -```basic -CREATE TASK "Follow up with " + customer_name DUE DATEADD(NOW(), 3, "day") -BOOK "Meeting with " + customer_name AT meeting_time -SEND MAIL TO customer_email SUBJECT "Confirmation" BODY message -``` - -**Knowledge base:** -```basic -USE KB "product-docs" -USE KB "pricing-info" -answer = LLM customer_question -``` - -### What Changes - -| n8n Approach | General Bots Approach | -|--------------|----------------------| -| Visual drag-and-drop | Text-based BASIC scripts | -| Node connections | Sequential code flow | -| Credentials UI | config.csv settings | -| Execution history UI | Log files + monitoring | -| Community nodes | HTTP keywords + custom code | - -## Credentials Migration - -### n8n Credentials - -n8n stores credentials separately. Export and configure in General Bots: - -**config.csv:** -```csv -key,value -slack-webhook-url,https://hooks.slack.com/services/xxx -api-key-clearbit,your-api-key -salesforce-token,your-token -``` - -**Usage in BASIC:** -```basic -slack_url = GET CONFIG "slack-webhook-url" -POST slack_url, #{text: "Message"} -``` - -## Migration Checklist - -### Pre-Migration - -- [ ] Export all n8n workflows as JSON -- [ ] Document active schedules and triggers -- [ ] List all credentials and API keys -- [ ] Identify critical workflows for priority migration -- [ ] Set up General Bots environment - -### Migration - -- [ ] Translate workflows to BASIC scripts -- [ ] Configure credentials in config.csv -- [ ] Set up webhooks with same endpoints -- [ ] Configure schedules -- [ ] Test each workflow individually - -### Post-Migration - -- [ ] Run parallel execution for verification -- [ ] Compare outputs between systems -- [ ] Monitor for errors -- [ ] Decommission n8n workflows -- [ ] Document new BASIC scripts - -## Common Patterns - -### Batch Processing - -**n8n:** Split In Batches node - -**General Bots:** -```basic -items = GET "https://api.example.com/items" -batch_size = 10 -total = LEN(items) - -FOR i = 0 TO total - 1 STEP batch_size - batch = SLICE(items, i, i + batch_size) - FOR EACH item IN batch - PROCESS_ITEM(item) - NEXT item - WAIT 1000 ' Rate limiting -NEXT i -``` - -### Conditional Branching - -**n8n:** IF node with multiple branches - -**General Bots:** -```basic -SWITCH status - CASE "new" - HANDLE_NEW() - CASE "pending" - HANDLE_PENDING() - CASE "complete" - HANDLE_COMPLETE() - DEFAULT - HANDLE_UNKNOWN() -END SWITCH -``` - -### Data Transformation - -**n8n:** Set node or Code node - -**General Bots:** -```basic -' Transform data -WITH transformed - .full_name = data.first_name + " " + data.last_name - .email = LOWER(data.email) - .created = NOW() - .source = "api" -END WITH -``` - -## Best Practices - -**Start with simple workflows.** Migrate straightforward automations first to build familiarity with BASIC syntax. - -**Use descriptive variable names.** BASIC scripts are more readable than node graphs when well-written. - -**Add comments.** Document your scripts for future maintenance: - -```basic -' Daily sales report - sends summary to management -' Runs at 6 PM on weekdays -SET SCHEDULE "0 18 * * 1-5" -``` - -**Leverage native features.** Don't just replicate n8n workflows—take advantage of General Bots' integrated AI, chat, and productivity features. - -**Test incrementally.** Verify each migrated workflow before moving to the next. - -## See Also - -- [SET SCHEDULE](../chapter-06-gbdialog/keyword-set-schedule.md) - Scheduling reference -- [WEBHOOK](../chapter-06-gbdialog/keyword-webhook.md) - Webhook creation -- [HTTP Keywords](../chapter-06-gbdialog/keywords-http.md) - API integration -- [Platform Comparison](./comparison-matrix.md) - Full feature comparison \ No newline at end of file diff --git a/docs/src/chapter-14-migration/notion.md b/docs/src/chapter-14-migration/notion.md deleted file mode 100644 index 0eef1006..00000000 --- a/docs/src/chapter-14-migration/notion.md +++ /dev/null @@ -1,416 +0,0 @@ -# Notion Migration Guide - -Migrating content and workflows from Notion to General Bots. - -General Bots - -## Overview - -Notion is a collaborative workspace combining notes, databases, and project management. General Bots provides equivalent functionality through its knowledge base, task management, and AI-powered conversation features—with the added benefit of self-hosting and native automation. - -## Why Migrate - -| Aspect | Notion | General Bots | -|--------|--------|--------------| -| Hosting | Cloud only | Self-hosted | -| Pricing | $10-15/user/month | No per-user fees | -| AI Features | $10/user/month add-on | Native (any LLM) | -| Automation | Limited | Full BASIC scripting | -| Chat/Bot | Not included | Multi-channel | -| API Creation | Not available | Instant webhooks | -| Data Sovereignty | Their servers | Your infrastructure | - -## Content Mapping - -### Notion to General Bots - -| Notion Feature | General Bots Equivalent | -|----------------|------------------------| -| Pages | Knowledge base documents (.gbkb) | -| Databases | Tables (CSV/database) | -| Kanban boards | Task boards | -| Calendar | Calendar API | -| Comments | Conversation history | -| Templates | Bot templates | -| Integrations | BASIC scripts + webhooks | -| Notion AI | LLM keyword | - -## Migration Process - -### Step 1: Export Notion Content - -Navigate to Settings & Members, then Settings, and scroll to Export content. Choose the Markdown & CSV export format and download the ZIP file. - -The export includes pages as Markdown files, databases as CSV files, and attachments in folders. - -### Step 2: Prepare Knowledge Base - -Organize exported content for General Bots: - -``` -my-bot.gbkb/ -├── company-info/ -│ ├── about.md -│ ├── policies.md -│ └── procedures.md -├── products/ -│ ├── catalog.md -│ └── pricing.md -└── support/ - ├── faq.md - └── troubleshooting.md -``` - -### Step 3: Import Documents - -Place Markdown files in your `.gbkb` folder. General Bots automatically indexes them for RAG: - -```basic -USE KB "company-info" -USE KB "products" -USE KB "support" - -TALK "How can I help you?" -HEAR question -answer = LLM question -TALK answer -``` - -### Step 4: Convert Databases - -Transform Notion CSV exports to General Bots tables: - -```basic -' Import Notion database export -data = READ "notion-export/Projects.csv" - -FOR EACH row IN data - INSERT "projects", #{ - name: row["Name"], - status: row["Status"], - due_date: row["Due Date"], - assignee: row["Assignee"], - imported_at: NOW() - } -NEXT row - -TALK "Imported " + LEN(data) + " projects" -``` - -### Step 5: Recreate Task Boards - -Convert Notion Kanban boards to General Bots task boards: - -```basic -' Create project for Notion board -project_id = CREATE PROJECT "Product Roadmap" WITH DESCRIPTION "Migrated from Notion" - -' Import tasks -tasks = READ "notion-export/Roadmap.csv" - -FOR EACH task IN tasks - status = SWITCH task["Status"] - CASE "Not Started" : "todo" - CASE "In Progress" : "in_progress" - CASE "Done" : "done" - DEFAULT : "todo" - END SWITCH - - CREATE TASK task["Name"] IN PROJECT project_id WITH STATUS status -NEXT task -``` - -## Notion AI to General Bots - -### Document Summarization - -Notion AI allows highlighting text and selecting "Summarize" but is limited to Notion content. General Bots provides broader capability: - -```basic -USE KB "documents" -summary = LLM "Summarize the key points from our Q3 report" -TALK summary -``` - -### Content Generation - -Where Notion AI uses the `/ai` command for basic prompting, General Bots offers full control: - -```basic -SET CONTEXT "You are a technical writer. Write clear, concise documentation." - -TALK "What would you like me to write?" -HEAR topic - -content = LLM "Write comprehensive documentation about: " + topic -WRITE "/docs/" + SLUGIFY(topic) + ".md", content -TALK "Documentation created!" -``` - -### Q&A on Documents - -Notion AI asks questions about single page content. General Bots searches across your entire knowledge base: - -```basic -' Load entire knowledge base -USE KB "all-docs" -USE KB "wiki" -USE KB "procedures" - -' Answer questions across all content -TALK "Ask me anything about our documentation" -HEAR question -answer = LLM question -TALK answer -``` - -## Automation Migration - -### Notion Automations (Limited) - -Notion has basic automations for status changes, due date reminders, and Slack notifications. - -### General Bots Equivalent - -Status change automation: - -```basic -ON "table:projects:update" - IF params.old_status <> params.new_status THEN - IF params.new_status = "complete" THEN - SEND MAIL TO params.owner_email SUBJECT "Project Completed" BODY "Your project " + params.name + " is now complete!" - END IF - END IF -END ON -``` - -Due date reminders: - -```basic -SET SCHEDULE "every day at 9am" - -upcoming = FIND "tasks", "due_date = DATEADD(NOW(), 1, 'day') AND status <> 'done'" - -FOR EACH task IN upcoming - SEND MAIL TO task.assignee_email SUBJECT "Task Due Tomorrow" BODY "Reminder: " + task.name + " is due tomorrow" -NEXT task -``` - -Slack notifications: - -```basic -ON "table:tasks:insert" - POST "https://hooks.slack.com/services/xxx", #{ - text: "New task created: " + params.name, - channel: "#tasks" - } -END ON -``` - -## Database Migration - -### Notion Database Properties - -| Notion Property | General Bots Equivalent | -|-----------------|------------------------| -| Title | TEXT column | -| Text | TEXT column | -| Number | NUMERIC column | -| Select | TEXT with validation | -| Multi-select | JSONB array | -| Date | DATE/TIMESTAMP column | -| Person | User reference | -| Files | File path references | -| Checkbox | BOOLEAN column | -| URL | TEXT column | -| Email | TEXT column | -| Phone | TEXT column | -| Formula | Computed in BASIC | -| Relation | Foreign key | -| Rollup | AGGREGATE queries | - -### Formula Migration - -Notion formulas like `prop("Price") * prop("Quantity")` translate to BASIC calculations: - -```basic -' Calculate on insert/update -total = price * quantity -INSERT "orders", #{item: item, price: price, quantity: quantity, total: total} - -' Or query with calculation -SELECT "*, price * quantity as total FROM orders" -``` - -### Relation Migration - -Notion relations link databases together. General Bots uses foreign keys: - -```basic -' Create related tables -CREATE TABLE "projects" (id, name, status) -CREATE TABLE "tasks" (id, project_id, name, assignee) - -' Query with join -tasks = FIND "tasks", "project_id = '" + project_id + "'" - -' Or use JOIN keyword -result = JOIN "projects", "tasks", "projects.id = tasks.project_id" -``` - -## Template Migration - -### Notion Templates - -Notion templates are pre-filled pages. Convert to General Bots templates as BASIC scripts. - -Meeting notes template: - -```basic -' meeting-notes.bas -PARAM meeting_title AS string -PARAM attendees AS string -PARAM date AS date - -DESCRIPTION "Create meeting notes document" - -template = "# " + meeting_title + " - -**Date:** " + FORMAT(date, "MMMM d, yyyy") + " -**Attendees:** " + attendees + " - -## Agenda -1. -2. -3. - -## Discussion Notes - - -## Action Items -- [ ] -- [ ] - -## Next Meeting -" - -WRITE "/meetings/" + FORMAT(date, "yyyy-MM-dd") + "-" + SLUGIFY(meeting_title) + ".md", template -TALK "Meeting notes created: " + meeting_title -``` - -### Project Template - -```basic -' new-project.bas -PARAM project_name AS string -PARAM owner AS string - -DESCRIPTION "Create new project with standard structure" - -project_id = CREATE PROJECT project_name WITH DESCRIPTION "Created by template" -ADD USER TO PROJECT project_id, owner, "owner" - -' Create standard tasks -CREATE TASK "Define requirements" IN PROJECT project_id -CREATE TASK "Create timeline" IN PROJECT project_id -CREATE TASK "Assign resources" IN PROJECT project_id -CREATE TASK "Kickoff meeting" IN PROJECT project_id -CREATE TASK "First milestone review" IN PROJECT project_id - -TALK "Project '" + project_name + "' created with 5 starter tasks" -``` - -## What You Gain - -### Self-Hosting - -Your data stays on your infrastructure. No concerns about Notion's data practices or service availability. - -### Native AI Without Extra Cost - -Notion charges $10/user/month for AI features. General Bots includes AI at no additional cost—use any LLM provider. - -### Full Automation - -Go beyond Notion's limited automations with complete BASIC scripting: - -```basic -SET SCHEDULE "every monday at 9am" - -' Generate weekly report -projects = FIND "projects", "status = 'active'" -tasks_completed = AGGREGATE "tasks", "COUNT", "id", "completed_at > DATEADD(NOW(), -7, 'day')" - -SET CONTEXT "You are a project manager. Create a concise weekly summary." -report = LLM "Summarize: " + LEN(projects) + " active projects, " + tasks_completed + " tasks completed this week" - -SEND MAIL TO "team@company.com" SUBJECT "Weekly Project Summary" BODY report -``` - -### Multi-Channel Access - -Access your knowledge base through any channel: - -```basic -' Same bot works on web, WhatsApp, Teams, Slack -TALK "How can I help you today?" -HEAR question - -USE KB "company-wiki" -answer = LLM question -TALK answer -``` - -### Custom APIs - -Create APIs instantly—something not possible in Notion: - -```basic -WEBHOOK "project-status" - -project = FIND "projects", "id = '" + params.id + "'" -tasks = FIND "tasks", "project_id = '" + params.id + "'" - -WITH response - .project = project - .task_count = LEN(tasks) - .completed = LEN(FILTER(tasks, "status = 'done'")) -END WITH -``` - -## Migration Checklist - -### Pre-Migration - -Before starting, export all Notion content in Markdown & CSV format. Inventory your databases and their properties. Document active integrations. Identify critical templates that need recreation. Set up your General Bots environment. - -### Migration - -During the migration, organize Markdown files into the .gbkb structure. Import database CSVs to tables. Convert formulas to BASIC calculations. Recreate task boards as projects. Migrate templates to BASIC scripts. Set up automations to replace Notion workflows. - -### Post-Migration - -After migration, verify all content is searchable in the knowledge base. Test database queries. Confirm automations work correctly. Train your team on the new interface. Redirect any Notion integrations to General Bots. - -## Best Practices - -Organize your knowledge base thoughtfully by grouping related documents in collections for better RAG results. - -Simplify database structures because Notion encourages complex relations while General Bots works best with cleaner schemas. - -Leverage AI for migration by using General Bots' LLM to help transform and summarize Notion content: - -```basic -content = READ "notion-export/long-document.md" -summary = LLM "Create a concise summary of this document: " + content -WRITE "/summaries/document-summary.md", summary -``` - -Keep templates as scripts since BASIC templates are more powerful than Notion's static templates. - -## See Also - -- [Knowledge Base](../chapter-03/README.md) - KB configuration -- [Projects](../chapter-11-features/projects.md) - Project management -- [Template Variables](../chapter-06-gbdialog/template-variables.md) - Dynamic content -- [Platform Comparison](./comparison-matrix.md) - Full feature comparison \ No newline at end of file diff --git a/docs/src/chapter-14-migration/overview.md b/docs/src/chapter-14-migration/overview.md deleted file mode 100644 index d73785a6..00000000 --- a/docs/src/chapter-14-migration/overview.md +++ /dev/null @@ -1,17 +0,0 @@ -# Migration Overview - -This page has been consolidated with [Migration Concepts](./README.md). - -Please see the main chapter page for: - -- Migration paradigms and philosophy -- Architecture translation concepts -- Assessment and planning frameworks -- Success metrics - -For specific migration guides: - -- [Microsoft 365 Migration](./microsoft-365.md) -- [Google Workspace Migration](./google-workspace.md) -- [Knowledge Base Migration](./kb-migration.md) -- [Automation Migration](./automation.md) \ No newline at end of file diff --git a/docs/src/chapter-14-migration/perplexity.md b/docs/src/chapter-14-migration/perplexity.md deleted file mode 100644 index 930b3c13..00000000 --- a/docs/src/chapter-14-migration/perplexity.md +++ /dev/null @@ -1,406 +0,0 @@ -# Perplexity Migration Guide - -Migrating from Perplexity to General Bots for AI-powered search and knowledge retrieval. - -General Bots - -## Overview - -Perplexity is an AI-powered search assistant that answers questions with web citations. General Bots provides equivalent and expanded capabilities through its knowledge base, RAG system, and LLM integration—with the advantage of using your own documents, self-hosting, and full customization. - -## Why Migrate - -| Aspect | Perplexity | General Bots | -|--------|------------|--------------| -| Hosting | Cloud only | Self-hosted | -| Pricing | $20/month Pro | No subscription | -| Knowledge Source | Web search | Your documents + optional web | -| Customization | None | Full BASIC scripting | -| Data Privacy | Queries logged | Complete privacy | -| API Access | Limited | Full REST API | -| Multi-channel | Web only | Web, WhatsApp, Teams, etc. | -| Automation | None | Full workflow automation | -| Integration | None | Any system via API | - -## Feature Comparison - -### Search and Q&A - -| Perplexity Feature | General Bots Equivalent | -|--------------------|------------------------| -| Web search | `USE WEBSITE` + `LLM` | -| Document Q&A (Pro) | `USE KB` + `LLM` | -| Citation generation | RAG with sources | -| Focus modes | `SET CONTEXT` | -| Collections (Pro) | Multiple `.gbkb` folders | -| File upload | Knowledge base indexing | - -### What Perplexity Does - -1. Searches the web for relevant information -2. Synthesizes answers from multiple sources -3. Provides citations and links -4. Allows follow-up questions - -### What General Bots Does - -1. Searches your private knowledge base -2. Optionally fetches web content -3. Synthesizes answers with full context -4. Provides source references -5. Allows conversation and follow-ups -6. Automates actions based on answers -7. Deploys to any channel - -## Migration Approach - -### Step 1: Build Your Knowledge Base - -Instead of relying on web search, create a curated knowledge base: - -``` -my-bot.gbkb/ -├── company/ -│ ├── policies.pdf -│ ├── procedures.md -│ └── org-chart.pdf -├── products/ -│ ├── catalog.pdf -│ ├── specifications.xlsx -│ └── pricing.csv -├── support/ -│ ├── faq.md -│ ├── troubleshooting.md -│ └── known-issues.md -└── industry/ - ├── regulations.pdf - └── best-practices.md -``` - -### Step 2: Configure RAG - -Enable retrieval-augmented generation: - -```basic -' Load knowledge collections -USE KB "company" -USE KB "products" -USE KB "support" - -' Set assistant behavior -SET CONTEXT "You are a knowledgeable assistant. Answer questions based on the provided documents. Always cite your sources." - -' Handle questions -TALK "What would you like to know?" -HEAR question -answer = LLM question -TALK answer -``` - -### Step 3: Add Web Search (Optional) - -For real-time information, add website sources: - -```basic -USE KB "internal-docs" -USE WEBSITE "https://docs.example.com" -USE WEBSITE "https://industry-news.com" - -answer = LLM "What are the latest updates on " + topic -``` - -## Recreating Perplexity Features - -### Focus Modes - -**Perplexity Focus: Academic** - -```basic -SET CONTEXT "You are an academic research assistant. Provide scholarly, well-cited responses based on peer-reviewed sources and academic literature. Be precise and thorough." - -USE KB "research-papers" -USE KB "academic-journals" - -answer = LLM question -``` - -**Perplexity Focus: Writing** - -```basic -SET CONTEXT "You are a professional writing assistant. Help with content creation, editing, and improving text. Focus on clarity, style, and engagement." - -answer = LLM "Help me write: " + topic -``` - -**Perplexity Focus: Code** - -```basic -SET CONTEXT "You are an expert programmer. Provide accurate, well-documented code examples. Explain your reasoning and suggest best practices." - -USE KB "code-documentation" -USE KB "api-references" - -answer = LLM question -``` - -### Collections - -**Perplexity Collections** organize related searches. - -**General Bots equivalent:** - -```basic -' Create specialized search contexts -WEBHOOK "search-products" - USE KB "products" - SET CONTEXT "You are a product specialist." - answer = LLM body.query -END WEBHOOK - -WEBHOOK "search-support" - USE KB "support" - SET CONTEXT "You are a support technician." - answer = LLM body.query -END WEBHOOK - -WEBHOOK "search-legal" - USE KB "legal" - SET CONTEXT "You are a legal advisor. Always include disclaimers." - answer = LLM body.query -END WEBHOOK -``` - -### Pro Search (Deep Research) - -**Perplexity Pro Search** performs multi-step research. - -**General Bots equivalent:** - -```basic -' Deep research workflow -PARAM topic AS string - -DESCRIPTION "Perform comprehensive research on a topic" - -SET CONTEXT "You are a research analyst. Conduct thorough analysis with multiple perspectives." - -USE KB "all-documents" - -' Step 1: Initial analysis -initial = LLM "Provide an overview of: " + topic - -' Step 2: Deep dive -details = LLM "Now provide detailed analysis with specific examples for: " + topic - -' Step 3: Alternative perspectives -alternatives = LLM "What are alternative viewpoints or counterarguments regarding: " + topic - -' Step 4: Synthesis -WITH research_prompt - .instruction = "Synthesize a comprehensive report" - .overview = initial - .details = details - .alternatives = alternatives -END WITH - -final_report = LLM "Create a comprehensive report combining: " + research_prompt - -TALK final_report -``` - -### Citation and Sources - -**Perplexity** shows numbered citations with links. - -**General Bots** provides source references through RAG: - -```basic -USE KB "documents" - -SET CONTEXT "When answering, always cite which document your information comes from. Format citations as [Source: document name]." - -answer = LLM question -TALK answer -``` - -## What You Gain - -### Private Knowledge Base - -Your proprietary documents stay private: - -```basic -USE KB "confidential-data" -USE KB "internal-reports" - -' All queries against your own data -' Nothing sent to external search engines -answer = LLM sensitive_question -``` - -### Custom AI Behavior - -Fine-tune responses for your specific needs: - -```basic -SET CONTEXT "You are the customer service assistant for Acme Corp. -- Always be friendly and professional -- If you don't know something, offer to connect with a human -- Never discuss competitor products -- Emphasize our satisfaction guarantee" - -answer = LLM customer_question -``` - -### Multi-Channel Deployment - -Access your AI assistant anywhere: - -```basic -' Same knowledge base, any channel -' Web chat, WhatsApp, Teams, Slack, SMS, Email - -TALK "How can I help you?" -HEAR question -USE KB "company-knowledge" -answer = LLM question -TALK answer -``` - -### Automation Beyond Q&A - -Take action based on queries: - -```basic -USE KB "products" - -TALK "What are you looking for?" -HEAR query - -answer = LLM query - -' If user wants to order, take action -IF CONTAINS(LOWER(query), "order") OR CONTAINS(LOWER(query), "buy") THEN - TALK "Would you like me to start an order?" - HEAR confirm AS BOOLEAN - IF confirm THEN - CREATE TASK "Follow up on order inquiry" DUE DATEADD(NOW(), 1, "day") - SEND MAIL TO "sales@company.com" SUBJECT "Order Inquiry" BODY "Customer asked: " + query - END IF -END IF - -TALK answer -``` - -### API for Integration - -Create search APIs for your applications: - -```basic -WEBHOOK "search" - -USE KB params.collection -SET CONTEXT params.context - -answer = LLM params.query - -WITH response - .answer = answer - .query = params.query - .timestamp = NOW() -END WITH -``` - -Call from any application: - -``` -POST /api/search -{ - "collection": "products", - "context": "You are a product expert", - "query": "What's the best option for enterprise?" -} -``` - -## Migration Checklist - -### Pre-Migration - -- [ ] Identify information sources you frequently search -- [ ] Gather documents to build knowledge base -- [ ] Determine required focus modes/contexts -- [ ] Plan deployment channels -- [ ] Set up General Bots environment - -### Migration - -- [ ] Organize documents into .gbkb collections -- [ ] Create context configurations -- [ ] Build specialized search endpoints -- [ ] Test with common queries -- [ ] Configure multi-channel access - -### Post-Migration - -- [ ] Compare answer quality -- [ ] Train team on new interface -- [ ] Monitor and refine contexts -- [ ] Add automation workflows -- [ ] Expand knowledge base as needed - -## Example: Complete Search Assistant - -```basic -' search-assistant.bas -' A Perplexity-like search experience with General Bots - -' Load knowledge bases -USE KB "company-docs" -USE KB "product-info" -USE KB "industry-knowledge" - -' Configure AI behavior -SET CONTEXT "You are an intelligent search assistant. -Provide accurate, well-sourced answers. -When citing information, mention the source document. -If you're uncertain, acknowledge the limitations. -Be concise but comprehensive." - -' Main conversation loop -TALK "Hello! I can search our knowledge base and help answer your questions. What would you like to know?" - -LOOP - HEAR query - - IF LOWER(query) = "exit" OR LOWER(query) = "quit" THEN - TALK "Goodbye!" - EXIT LOOP - END IF - - ' Generate response with sources - answer = LLM query - TALK answer - - ' Offer follow-up - TALK "Would you like to know more about any aspect of this?" -LOOP -``` - -## Best Practices - -**Curate your knowledge base.** Quality documents produce better answers than random web search. - -**Use specific contexts.** Tailor the AI's behavior for different use cases rather than using generic settings. - -**Iterate on prompts.** Refine your `SET CONTEXT` instructions based on the quality of responses. - -**Combine sources strategically.** Mix internal documents with curated external sources for comprehensive coverage. - -**Add automation.** Go beyond Q&A—let your assistant take actions, create tasks, and integrate with workflows. - -## See Also - -- [Knowledge Base](../chapter-03/README.md) - Building effective KBs -- [USE KB](../chapter-06-gbdialog/keyword-use-kb.md) - Knowledge base keyword -- [SET CONTEXT](../chapter-06-gbdialog/keyword-set-context.md) - AI configuration -- [Platform Comparison](./comparison-matrix.md) - Full feature comparison \ No newline at end of file diff --git a/docs/src/chapter-14-migration/resources.md b/docs/src/chapter-14-migration/resources.md deleted file mode 100644 index a3f7a516..00000000 --- a/docs/src/chapter-14-migration/resources.md +++ /dev/null @@ -1,202 +0,0 @@ -# Migration Resources - -General Bots provides comprehensive tools and resources for organizations transitioning from cloud-based productivity platforms to self-hosted infrastructure. - -General Bots - -## Migration Toolkit - -### Data Import Utilities - -General Bots includes import tools for common enterprise data formats. - -For email migration, the toolkit supports IMAP sync for mailbox migration, PST file import, calendar import via ICS format, and contact import through VCF and CardDAV. - -File migration capabilities include bulk file upload via the S3 API, folder structure preservation, metadata retention, and version history import where the source system provides it. - -User migration supports SCIM provisioning, LDAP directory sync, CSV user import, and bulk credential generation. - -### BASIC Migration Scripts - -Template scripts simplify common migration tasks. The file migration script connects to external storage and transfers files: - -```basic -' migrate-files.bas -PARAM source_api AS string -PARAM auth_token AS string - -DESCRIPTION "Migrate files from external storage" - -SET HEADER "Authorization", "Bearer " + auth_token -files = GET source_api + "/files" - -FOR EACH file IN files - content = DOWNLOAD file.download_url - WRITE "/" + file.path, content - TALK "Migrated: " + file.name -NEXT file - -TALK "Migration complete: " + LEN(files) + " files" -``` - -The user migration script imports users from a CSV export: - -```basic -' migrate-users.bas -PARAM csv_path AS string - -DESCRIPTION "Import users from CSV export" - -users = READ csv_path -FOR EACH row IN users - CREATE USER row.email WITH NAME row.name -NEXT row -``` - -## API Compatibility - -### REST API Mapping - -General Bots REST APIs follow familiar patterns that map to common operations: - -| Common Operation | General Bots Endpoint | -|-----------------|----------------------| -| List files | `GET /api/files/list` | -| Upload file | `POST /api/files/write` | -| Download file | `GET /api/files/{path}` | -| List users | `GET /api/users` | -| Create user | `POST /api/users` | -| Send email | `POST /api/email/send` | -| List calendar events | `GET /api/calendar/events` | -| Create task | `POST /api/tasks` | - -### Identity Federation - -Support SSO during migration with identity federation. This enables OIDC provider integration, SAML support via Zitadel, hybrid authentication during transition periods, and gradual user migration without disrupting access. - -Configure federation in `config.csv`: - -```csv -key,value -oidc-provider-url,https://identity.example.com -oidc-client-id,general-bots-client -oidc-client-secret,your-secret -``` - -## Industry Templates - -Pre-built configurations address common industry requirements. - -Healthcare templates provide HIPAA-compliant configuration, patient communication templates, appointment scheduling workflows, and secure document handling. - -Financial services templates include SOC 2 aligned settings, secure data handling, audit logging enabled by default, and compliance reporting. - -Education templates offer student enrollment flows, course management, parent communication channels, and assignment tracking. - -Professional services templates cover client onboarding, project management workflows, time tracking integration, and invoice generation. - -## Deployment Guides - -### Infrastructure Sizing - -| Organization Size | CPU | RAM | Storage | Users | -|------------------|-----|-----|---------|-------| -| Small | 2 cores | 4 GB | 100 GB | 1-50 | -| Medium | 4 cores | 8 GB | 500 GB | 50-500 | -| Large | 8 cores | 16 GB | 2 TB | 500-5000 | -| Enterprise | 16+ cores | 32+ GB | 10+ TB | 5000+ | - -### High Availability - -For production deployments requiring high availability, configure PostgreSQL replication for database resilience, load-balanced botserver instances for horizontal scaling, distributed SeaweedFS storage for file redundancy, and Redis/Valkey clustering for cache availability. - -### Backup Strategy - -Configure automated backups to protect your data: - -```basic -SET SCHEDULE "every day at 2am" - -' Database backup -result = POST "https://backup.internal/postgres", #{database: "botserver"} - -' File storage backup -result = POST "https://backup.internal/seaweedfs", #{bucket: "all"} - -' Notify on completion -SEND MAIL TO "ops@company.com" SUBJECT "Backup Complete" BODY result -``` - -## Training Resources - -### Administrator Training - -Administrator training covers initial setup and configuration, user management, security settings, and monitoring and maintenance procedures. - -### Developer Training - -Developer training includes BASIC scripting fundamentals, API integration patterns, custom keyword development, and package creation. - -### End User Training - -End user training addresses chat interface usage, file management, calendar and tasks, and mobile access. - -## ROI Calculator - -Estimate savings with self-hosted deployment: - -| Factor | Cloud (100 users) | General Bots | -|--------|------------------|--------------| -| Annual licensing | $15,000-60,000 | $0 | -| AI assistant add-on | $36,000 | $0 | -| Infrastructure | Included | $2,400-6,000 | -| LLM API costs | Included | $600-6,000 | -| **Total Annual** | **$51,000-96,000** | **$3,000-12,000** | - -Typical savings range from 75-95% reduction in annual costs. - -## Support Resources - -### Documentation - -Documentation resources include the complete keyword reference, API documentation, configuration guides, and troubleshooting guides. - -### Community - -Community support is available through GitHub discussions, issue tracking, feature requests, and community contributions. - -### Professional Services - -For enterprise deployments requiring additional support, professional services include migration planning, custom development, training programs, and support contracts. - -Contact: partners@pragmatismo.com.br - -## Migration Checklist - -### Pre-Migration - -Before beginning migration, inventory current services and usage, identify data to migrate, plan user communication, set up a test environment, and configure identity federation if needed. - -### Migration - -During migration, deploy General Bots infrastructure, import users and groups, migrate files and documents, transfer email if applicable, and set up integrations. - -### Post-Migration - -After migration, verify data integrity, test all workflows, train users, update DNS and routing, decommission old services, and monitor and optimize the new environment. - -## Case Study Template - -Document your migration for internal reference using this structure. - -The organization profile section captures size and industry, previous platform, and key requirements. - -The migration scope section documents services migrated, data volume, and timeline. - -The results section records cost savings achieved, performance improvements, and user feedback. - -The lessons learned section captures challenges encountered, solutions implemented, and recommendations for future migrations. - -## See Also - -Review the [Migration Overview](./overview.md) for getting started with migration concepts. See [Validation and Testing](./validation.md) to verify migration success. The [Enterprise Platform Migration](../chapter-11-features/m365-comparison.md) guide provides detailed feature mapping. Start with the [Quick Start](../chapter-01/quick-start.md) guide for initial deployment. \ No newline at end of file diff --git a/docs/src/chapter-14-migration/validation.md b/docs/src/chapter-14-migration/validation.md deleted file mode 100644 index c1030928..00000000 --- a/docs/src/chapter-14-migration/validation.md +++ /dev/null @@ -1,61 +0,0 @@ -# Validation - -Post-migration testing and verification procedures. - -## Overview - -Validation ensures that migrated systems and data are functioning correctly in the new self-hosted environment. A thorough validation process catches issues early and builds confidence in the new platform before full cutover. - -## Key Areas to Validate - -### User Access - -The first priority is confirming that users can authenticate successfully. Verify that login works with the correct credentials and that permissions are properly assigned based on user roles. If single sign-on was configured, test the SSO flow to ensure tokens are being issued and validated correctly. - -### Data Integrity - -Data integrity validation confirms that all files transferred completely and accurately. Compare file counts between source and destination systems, verify that file sizes match the originals, and check that timestamps were preserved during migration. Spot-check important documents by opening them to confirm content integrity. - -### Email Functionality - -Email validation requires testing both sending and receiving capabilities. Confirm that folder structures and existing messages transferred intact. Verify that email aliases and distribution lists function as expected, and test that mail routing delivers messages to the correct destinations. - -### Document Search - -Search functionality depends on proper indexing of migrated content. Verify that searches return expected results for known documents. Confirm that all documents are accessible through search results, and check that indexing has completed for the full document corpus. - -## Testing Approach - -### Smoke Testing - -Smoke testing provides quick verification of basic functionality before deeper testing begins. Run a login test to confirm authentication works, send a test email to verify mail flow, search for a known document to test the search index, and access several key files to confirm storage connectivity. - -### User Acceptance Testing - -User acceptance testing has actual users verify the system meets their needs. Users should confirm their data is present and accessible, verify that their daily workflows still function correctly, and assess whether performance is acceptable for their tasks. - -### Load Testing - -Load testing validates system behavior under realistic usage conditions. Test concurrent user access to identify bottlenecks, transfer large files to verify storage performance, and run search queries under load to ensure the search infrastructure scales appropriately. - -## Common Issues - -### Authentication Problems - -Authentication failures typically stem from incorrect credentials, certificate validation issues, or domain configuration problems. Check that usernames and passwords were migrated correctly, verify SSL certificates are valid and trusted, and confirm DNS records point to the correct servers. - -### Missing Data - -Missing data usually results from incomplete transfers, permission errors during migration, or format incompatibilities between systems. Re-run transfer jobs for missing items, check source system permissions, and verify file format support in the destination system. - -### Performance Issues - -Performance problems often manifest as slow searches, network bottlenecks, or resource constraints. Review search index configuration, check network bandwidth between components, and monitor CPU, memory, and disk usage to identify resource limitations. - -## Validation Checklist - -Before declaring migration complete, confirm that all users can authenticate successfully, email send and receive functionality works correctly, files are accessible with proper permissions, search returns accurate results, backup jobs are running successfully, and monitoring systems are actively tracking the new environment. - -## Next Steps - -Once validation completes successfully, proceed to user communication and training. Review the migration overview for next steps, and consult the common concepts guide for ongoing maintenance procedures. \ No newline at end of file diff --git a/docs/src/chapter-14-migration/zapier-make.md b/docs/src/chapter-14-migration/zapier-make.md deleted file mode 100644 index 6500dfbd..00000000 --- a/docs/src/chapter-14-migration/zapier-make.md +++ /dev/null @@ -1,489 +0,0 @@ -# Zapier and Make Migration Guide - -Migrating workflows from Zapier or Make (formerly Integromat) to General Bots. - -General Bots - -## Overview - -Zapier and Make are visual automation platforms connecting apps through triggers and actions. General Bots provides equivalent automation through BASIC scripting, offering more power and flexibility without per-task pricing. - -## Why Migrate - -| Aspect | Zapier/Make | General Bots | -|--------|-------------|--------------| -| Pricing | Per-task/operation | Unlimited executions | -| Automation | Visual workflows | BASIC scripts | -| AI Integration | Via paid apps | Native LLM keywords | -| Chat/Bot | Not included | Multi-channel | -| Productivity Suite | Not included | Email, calendar, files | -| Custom Logic | Limited | Full programming | -| Self-hosting | Not available | Full control | -| API Creation | Not available | Instant webhooks | - -## Cost Comparison - -### Zapier Pricing - -| Plan | Tasks/Month | Cost | -|------|-------------|------| -| Free | 100 | $0 | -| Starter | 750 | $19.99 | -| Professional | 2,000 | $49 | -| Team | 50,000 | $69/user | -| Company | 100,000+ | Custom | - -### Make Pricing - -| Plan | Operations/Month | Cost | -|------|------------------|------| -| Free | 1,000 | $0 | -| Core | 10,000 | $9 | -| Pro | 10,000 | $16 | -| Teams | 10,000 | $29/user | -| Enterprise | Custom | Custom | - -### General Bots - -| Plan | Operations | Cost | -|------|------------|------| -| Self-hosted | Unlimited | Infrastructure only | - -## Trigger Mapping - -| Zapier/Make Trigger | General Bots Equivalent | -|---------------------|------------------------| -| Schedule | `SET SCHEDULE` | -| Webhook | `WEBHOOK` | -| New Email | `ON "email:received"` | -| New Row (Sheets) | `ON "table:name:insert"` | -| Form Submission | `ON FORM SUBMIT` | -| New File | `ON "file:created"` | -| RSS Feed | Scheduled `GET` | -| App-specific | API polling or webhooks | - -## Action Mapping - -| Zapier/Make Action | General Bots Equivalent | -|--------------------|------------------------| -| Send Email | `SEND MAIL` | -| HTTP Request | `GET`, `POST`, `PUT`, `DELETE` | -| Create Row | `INSERT` | -| Update Row | `UPDATE` | -| Filter | `IF/THEN/ELSE` | -| Formatter | String/date functions | -| Delay | `WAIT` | -| Paths | `IF` branches | -| Loop | `FOR EACH` | -| Code (JS/Python) | BASIC script | -| Slack Message | `POST` to Slack webhook | -| Create Task | `CREATE TASK` | -| Send SMS | SMS integration | - -## Migration Examples - -### Simple Zap: Form to Email - -**Zapier:** -``` -Typeform → Gmail (Send Email) -``` - -**General Bots:** -```basic -ON FORM SUBMIT "contact-form" - name = fields.name - email = fields.email - message = fields.message - - SEND MAIL TO "support@company.com" SUBJECT "New Contact: " + name BODY "From: " + email + "\n\nMessage:\n" + message -END ON -``` - -### Multi-Step Zap: Lead Processing - -**Zapier:** -``` -Webhook → Filter → Clearbit Enrich → Salesforce (Create Lead) → Slack (Send Message) -``` - -**General Bots:** -```basic -WEBHOOK "new-lead" - -lead = body - -' Filter -IF lead.email = "" OR NOT CONTAINS(lead.email, "@") THEN - RETURN #{status: "invalid", reason: "Invalid email"} -END IF - -' Enrich -SET HEADER "Authorization", "Bearer " + GET CONFIG "clearbit-key" -enriched = GET "https://person.clearbit.com/v2/people/find?email=" + lead.email - -' Create in CRM -WITH salesforce_lead - .Email = lead.email - .FirstName = enriched.name.givenName - .LastName = enriched.name.familyName - .Company = enriched.employment.name - .Title = enriched.employment.title -END WITH - -SET HEADER "Authorization", "Bearer " + GET CONFIG "salesforce-token" -result = POST "https://yourinstance.salesforce.com/services/data/v52.0/sobjects/Lead", salesforce_lead - -' Notify Slack -POST GET CONFIG "slack-webhook", #{ - text: "New lead: " + lead.email + " from " + enriched.employment.name -} - -RETURN #{status: "success", salesforce_id: result.id} -``` - -### Scheduled Sync - -**Make Scenario:** -``` -Schedule → HTTP Request → Iterator → Google Sheets (Add Row) -``` - -**General Bots:** -```basic -SET SCHEDULE "every hour" - -data = GET "https://api.example.com/new-orders" - -FOR EACH order IN data.orders - INSERT "orders", #{ - order_id: order.id, - customer: order.customer_name, - total: order.total, - status: order.status, - synced_at: NOW() - } -NEXT order - -TALK "Synced " + LEN(data.orders) + " orders" -``` - -### Error Handling - -**Zapier:** Error handling path or retry - -**General Bots:** -```basic -SET SCHEDULE "every 5 minutes" - -TRY - result = POST "https://api.example.com/sync", data - IF result.status <> 200 THEN - THROW "API returned " + result.status - END IF -CATCH - ' Log error - INSERT "error_log", #{ - error: ERROR_MESSAGE, - timestamp: NOW(), - data: data - } - - ' Alert - SEND MAIL TO "ops@company.com" SUBJECT "Sync Error" BODY ERROR_MESSAGE - POST GET CONFIG "slack-alerts", #{text: "Sync failed: " + ERROR_MESSAGE} -END TRY -``` - -### Conditional Paths - -**Zapier Paths:** -``` -Trigger → Path A (if condition) → Actions - → Path B (else) → Actions -``` - -**General Bots:** -```basic -WEBHOOK "order-status" - -order = body - -IF order.total > 1000 THEN - ' High-value order path - SEND MAIL TO "vip-team@company.com" SUBJECT "High-Value Order" BODY order - POST GET CONFIG "slack-vip", #{text: "VIP Order: $" + order.total} - priority = "high" - -ELSEIF order.is_rush = true THEN - ' Rush order path - SEND MAIL TO "fulfillment@company.com" SUBJECT "RUSH Order" BODY order - priority = "rush" - -ELSE - ' Standard order path - priority = "normal" -END IF - -INSERT "orders", #{ - id: order.id, - total: order.total, - priority: priority, - created: NOW() -} -``` - -### Data Transformation - -**Make/Zapier Formatter:** -- Split text -- Format dates -- Math operations -- Lookup tables - -**General Bots:** -```basic -' String operations -full_name = first_name + " " + last_name -email_domain = SPLIT(email, "@")[1] -slug = LOWER(REPLACE(title, " ", "-")) - -' Date formatting -formatted_date = FORMAT(created_at, "MMMM d, yyyy") -due_date = DATEADD(NOW(), 7, "day") -days_ago = DATEDIFF("day", created_at, NOW()) - -' Math -subtotal = price * quantity -tax = subtotal * 0.08 -total = subtotal + tax -discount = IIF(total > 100, total * 0.1, 0) - -' Lookup -status_label = SWITCH status - CASE "new" : "New Order" - CASE "processing" : "In Progress" - CASE "shipped" : "On the Way" - CASE "delivered" : "Completed" - DEFAULT : "Unknown" -END SWITCH -``` - -## App-Specific Migrations - -### Gmail/Email - -**Zapier:** Gmail trigger/action - -**General Bots:** -```basic -' Send email -SEND MAIL TO recipient SUBJECT subject BODY body - -' With attachments -SEND MAIL TO recipient SUBJECT subject BODY body ATTACH "/files/report.pdf" - -' Process incoming (via Stalwart webhook) -ON "email:received" - IF CONTAINS(params.subject, "Order") THEN - PROCESS_ORDER(params) - END IF -END ON -``` - -### Slack - -**Zapier:** Slack app - -**General Bots:** -```basic -' Simple message -POST "https://hooks.slack.com/services/xxx", #{text: "Hello!"} - -' Rich message -WITH slack_message - .channel = "#general" - .blocks = [ - #{type: "header", text: #{type: "plain_text", text: "New Order"}}, - #{type: "section", text: #{type: "mrkdwn", text: "*Customer:* " + customer_name}}, - #{type: "section", text: #{type: "mrkdwn", text: "*Total:* $" + total}} - ] -END WITH -POST GET CONFIG "slack-webhook", slack_message -``` - -### Google Sheets - -**Zapier:** Google Sheets app - -**General Bots:** -```basic -' Read from sheet -SET HEADER "Authorization", "Bearer " + GET CONFIG "google-token" -data = GET "https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/Sheet1!A1:D100" - -' Append row -POST "https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/Sheet1!A1:append?valueInputOption=USER_ENTERED", #{ - values: [[name, email, phone, NOW()]] -} - -' Or use General Bots tables directly -INSERT "contacts", #{name: name, email: email, phone: phone} -``` - -### Airtable - -**Zapier:** Airtable app - -**General Bots:** -```basic -SET HEADER "Authorization", "Bearer " + GET CONFIG "airtable-key" - -' Read records -records = GET "https://api.airtable.com/v0/{baseId}/{tableName}" - -' Create record -POST "https://api.airtable.com/v0/{baseId}/{tableName}", #{ - fields: #{ - Name: name, - Email: email, - Status: "New" - } -} -``` - -### HubSpot - -**Zapier:** HubSpot app - -**General Bots:** -```basic -SET HEADER "Authorization", "Bearer " + GET CONFIG "hubspot-token" - -' Create contact -POST "https://api.hubapi.com/crm/v3/objects/contacts", #{ - properties: #{ - email: email, - firstname: first_name, - lastname: last_name, - company: company - } -} - -' Create deal -POST "https://api.hubapi.com/crm/v3/objects/deals", #{ - properties: #{ - dealname: deal_name, - amount: amount, - pipeline: "default", - dealstage: "appointmentscheduled" - } -} -``` - -## What You Gain - -### No Operation Limits - -```basic -' Process thousands of records without worrying about limits -SET SCHEDULE "every hour" - -records = GET "https://api.example.com/all-records" - -FOR EACH record IN records - PROCESS_RECORD(record) ' No per-operation cost -NEXT record -``` - -### Native AI Integration - -```basic -' AI-powered automation -USE KB "company-docs" - -incoming_email = params.body -category = LLM "Categorize this email as: support, sales, billing, or other: " + incoming_email - -IF category = "support" THEN - response = LLM "Draft a helpful support response to: " + incoming_email - SEND MAIL TO params.from SUBJECT "Re: " + params.subject BODY response -END IF -``` - -### Multi-Channel Chat - -```basic -' Same automation works across channels -TALK "How can I help you?" -HEAR request - -USE KB "help-docs" -answer = LLM request -TALK answer - -' Available on Web, WhatsApp, Teams, Slack, Telegram, SMS -``` - -### Built-in Productivity - -```basic -' No need for separate calendar, task, email apps -CREATE TASK "Follow up with " + customer_name DUE DATEADD(NOW(), 3, "day") -BOOK "Call with " + customer_name AT meeting_time -SEND MAIL TO customer_email SUBJECT "Confirmation" BODY message -``` - -## Migration Checklist - -### Pre-Migration - -- [ ] Export Zap/Scenario descriptions -- [ ] Document all triggers and schedules -- [ ] List all connected apps and credentials -- [ ] Identify critical automations -- [ ] Set up General Bots environment - -### Migration - -- [ ] Create BASIC scripts for each workflow -- [ ] Configure credentials in config.csv -- [ ] Set up webhooks with same URLs -- [ ] Configure schedules -- [ ] Test each automation - -### Post-Migration - -- [ ] Run parallel for verification -- [ ] Compare execution results -- [ ] Monitor for errors -- [ ] Disable Zapier/Make automations -- [ ] Cancel subscriptions - -## Best Practices - -**Start with simple Zaps.** Migrate basic workflows first to learn BASIC syntax. - -**Combine multiple Zaps.** Often several Zaps can become one General Bots script. - -**Use native features.** Don't replicate Zapier patterns—leverage AI, chat, and productivity features. - -**Add error handling.** BASIC provides better error handling than visual builders. - -**Document your scripts.** Add comments explaining what each script does. - -```basic -' Daily sales report -' Runs at 6 PM on weekdays -' Aggregates daily orders and sends summary to management -SET SCHEDULE "0 18 * * 1-5" - -' ... implementation -``` - -## See Also - -- [SET SCHEDULE](../chapter-06-gbdialog/keyword-set-schedule.md) - Scheduling -- [WEBHOOK](../chapter-06-gbdialog/keyword-webhook.md) - Webhooks -- [HTTP Keywords](../chapter-06-gbdialog/keywords-http.md) - API calls -- [Platform Comparison](./comparison-matrix.md) - Full comparison \ No newline at end of file diff --git a/docs/src/contact/README.md b/docs/src/contact/README.md deleted file mode 100644 index d5c3a492..00000000 --- a/docs/src/contact/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Contact - -## Get in Touch - -General Bots has been powering conversational AI solutions since 2018. We're here to help you build intelligent automation and enhanced customer engagement. - -### Support - -For technical support and documentation: -- **Documentation**: [https://pragmatismo.com.br](https://pragmatismo.com.br) -- **GitHub**: [https://github.com/GeneralBots](https://github.com/GeneralBots) -- **Email**: support@pragmatismo.com.br - -### Business Inquiries - -Interested in implementing General Bots for your organization? - -**Pragmatismo Inovações Ltda.** -Avenida Rio Branco, 177, Sala 201 a 2201 -Rio de Janeiro - Brasil -CNPJ: 40.293.841/0001-59 - -📞 **Phone**: +55 21 4040-2160 (24h) -📧 **Email**: info@pragmatismo.com.br -🌐 **Website**: [pragmatismo.com.br](https://pragmatismo.com.br) - -### Schedule a Demo - -Want to see General Bots in action? Our team can demonstrate: -- Custom bot development -- LLM integration -- Knowledge base setup -- Multi-channel deployment -- Enterprise automation - -[Schedule a meeting](https://calendly.com/pragmatismo) to explore how General Bots can transform your business operations. - -### Data Protection - -**Data Protection Officer (DPO)** -Rodrigo Rodriguez -📧 security@pragmatismo.com.br - -### Open Source Community - -General Bots is open source and we welcome contributions: -- Report issues on GitHub -- Submit pull requests -- Join discussions -- Share your use cases - -### Legal - -- [Terms of Service](/terms) -- [Privacy Policy](/privacy) -- DUNS Number: 926754884 - ---- - -*General Bots® - Enterprise conversational AI platform* -*Copyright © 2016-2025 Pragmatismo Inovações Ltda.* - ---- - -
- General Bots -
\ No newline at end of file diff --git a/docs/src/custom.css b/docs/src/custom.css deleted file mode 100644 index d3d421f0..00000000 --- a/docs/src/custom.css +++ /dev/null @@ -1,438 +0,0 @@ -/* Custom CSS for General Bots Documentation */ - -/* ============================================ - BASIC Syntax Highlighting - ============================================ */ - -/* BASIC code blocks - use ```basic or ```bas */ -pre code.language-basic, -pre code.language-bas, -pre code.hljs.language-basic, -pre code.hljs.language-bas { - color: #333; -} - -/* Dark theme BASIC */ -.ayu pre code.language-basic, -.ayu pre code.language-bas, -.coal pre code.language-basic, -.coal pre code.language-bas, -.navy pre code.language-basic, -.navy pre code.language-bas { - color: #e6e6e6; -} - -/* BASIC Keywords - TALK, HEAR, SET, GET, USE, etc. */ -pre code.language-basic .hljs-keyword, -pre code.language-bas .hljs-keyword { - color: #0033b3; - font-weight: bold; -} - -.ayu pre code.language-basic .hljs-keyword, -.coal pre code.language-basic .hljs-keyword, -.navy pre code.language-basic .hljs-keyword { - color: #ff7b72; - font-weight: bold; -} - -/* BASIC Strings */ -pre code.language-basic .hljs-string, -pre code.language-bas .hljs-string { - color: #067d17; -} - -.ayu pre code.language-basic .hljs-string, -.coal pre code.language-basic .hljs-string, -.navy pre code.language-basic .hljs-string { - color: #a5d6ff; -} - -/* BASIC Comments (REM or ') */ -pre code.language-basic .hljs-comment, -pre code.language-bas .hljs-comment { - color: #8c8c8c; - font-style: italic; -} - -/* BASIC Numbers */ -pre code.language-basic .hljs-number, -pre code.language-bas .hljs-number { - color: #1750eb; -} - -.ayu pre code.language-basic .hljs-number, -.coal pre code.language-basic .hljs-number, -.navy pre code.language-basic .hljs-number { - color: #79c0ff; -} - -/* BASIC Built-in functions */ -pre code.language-basic .hljs-built_in, -pre code.language-bas .hljs-built_in { - color: #8250df; -} - -/* BASIC Variables */ -pre code.language-basic .hljs-variable, -pre code.language-bas .hljs-variable { - color: #953800; -} - -/* Custom BASIC keyword highlighting via regex patterns */ -/* Primary keywords: TALK, HEAR, SET, GET */ -pre code.language-basic, -pre code.language-bas { - /* Highlight BASIC keywords that may not be recognized */ -} - -/* Standardized code block styling */ -pre code { - font-family: "JetBrains Mono", "Fira Code", "Source Code Pro", monospace; - font-size: 0.9em; - line-height: 1.5; -} - -/* Code block container */ -pre { - border-radius: 6px; - padding: 1em; - overflow-x: auto; -} - -/* Light theme code blocks */ -.light pre, -.rust pre { - background-color: #f6f8fa; - border: 1px solid #d0d7de; -} - -/* Dark theme code blocks */ -.ayu pre, -.coal pre, -.navy pre { - background-color: #161b22; - border: 1px solid #30363d; -} - -/* ============================================ - WhatsApp-style Chat CSS for Conversation Examples - ============================================ */ - -/* Chat Container */ -.wa-chat { - background-color: #e5ddd5; - background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zM22.343 0L13.857 8.485 15.272 9.9l9.9-9.9h-2.83zM32 0l-3.486 3.485-1.414-1.414L30.172 0H32zM0 5.373l.828-.83 1.415 1.415L0 8.2V5.374zm0 5.656l.828-.829 5.657 5.657-1.414 1.414L0 11.03v2.828zm0 5.656l.828-.828 8.485 8.485-1.414 1.414L0 16.686v2.83zm0 5.657l.828-.828 11.314 11.314-1.414 1.414L0 22.343v2.83zM0 32l.828-.828 14.142 14.142-1.414 1.414L0 32.172V32z' fill='%23c5c5c5' fill-opacity='0.1' fill-rule='evenodd'/%3E%3C/svg%3E"); - border-radius: 8px; - padding: 20px 15px; - margin: 20px 0; - max-width: 600px; - font-family: - -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, - sans-serif; - font-size: 14px; -} - -/* Dark theme chat container */ -.coal .wa-chat, -.navy .wa-chat, -.ayu .wa-chat { - background-color: #0b141a; - background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zM22.343 0L13.857 8.485 15.272 9.9l9.9-9.9h-2.83zM32 0l-3.486 3.485-1.414-1.414L30.172 0H32zM0 5.373l.828-.83 1.415 1.415L0 8.2V5.374zm0 5.656l.828-.829 5.657 5.657-1.414 1.414L0 11.03v2.828zm0 5.656l.828-.828 8.485 8.485-1.414 1.414L0 16.686v2.83zm0 5.657l.828-.828 11.314 11.314-1.414 1.414L0 22.343v2.83zM0 32l.828-.828 14.142 14.142-1.414 1.414L0 32.172V32z' fill='%23ffffff' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E"); -} - -/* Message Bubbles */ -.wa-message { - clear: both; - margin-bottom: 10px; - max-width: 85%; -} - -.wa-message.user { - float: right; -} - -.wa-message.bot { - float: left; -} - -/* User Bubbles */ -.wa-message.user .wa-bubble { - background-color: #dcf8c6; - border-radius: 8px 0 8px 8px; - margin-left: 40px; -} - -.coal .wa-message.user .wa-bubble, -.navy .wa-message.user .wa-bubble, -.ayu .wa-message.user .wa-bubble { - background-color: #005c4b; -} - -/* Bot Bubbles */ -.wa-message.bot .wa-bubble { - background-color: #ffffff; - border-radius: 0 8px 8px 8px; - margin-right: 40px; -} - -.coal .wa-message.bot .wa-bubble, -.navy .wa-message.bot .wa-bubble, -.ayu .wa-message.bot .wa-bubble { - background-color: #202c33; -} - -/* Bubble Content */ -.wa-bubble { - padding: 8px 12px; - box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13); -} - -.wa-bubble p { - margin: 0 0 4px 0; - line-height: 1.4; - color: #303030; -} - -.wa-bubble p:last-child { - margin-bottom: 0; -} - -.coal .wa-bubble p, -.navy .wa-bubble p, -.ayu .wa-bubble p { - color: #e9edef; -} - -/* Timestamp */ -.wa-time { - font-size: 11px; - color: #8696a0; - text-align: right; - margin-top: 4px; -} - -/* Clear float */ -.wa-chat::after { - content: ""; - display: table; - clear: both; -} - -/* ============================================ - SVG Text Rendering Fixes - ============================================ */ - -/* CSS Custom Properties that can be injected into SVG documents */ -:root { - --svg-main-text-color: #1a1a1a; - --svg-secondary-text-color: #666; - --svg-arrow-color: #666; -} - -/* Force black text in light/rust themes */ -.light, -.rust { - --svg-main-text-color: #1a1a1a !important; - --svg-secondary-text-color: #666 !important; - --svg-arrow-color: #666 !important; -} - -/* Dark theme overrides */ -.ayu, -.coal, -.navy, -.dark, -.theme--dark { - --svg-main-text-color: #ffffff !important; - --svg-secondary-text-color: #b0b0b0 !important; - --svg-arrow-color: #b0b0b0 !important; -} - -/* For inline SVGs - direct styling */ -.light svg .main-text, -.rust svg .main-text { - fill: #1a1a1a !important; -} - -.light svg .secondary-text, -.rust svg .secondary-text { - fill: #666 !important; -} - -.light svg .arrow-head, -.rust svg .arrow-head { - fill: #666 !important; -} - -.light svg .arrow-line, -.rust svg .arrow-line { - stroke: #666 !important; -} - -/* Dark theme inline SVG overrides */ -.ayu svg .main-text, -.coal svg .main-text, -.navy svg .main-text, -.dark svg .main-text, -.theme--dark svg .main-text { - fill: #ffffff !important; -} - -.ayu svg .secondary-text, -.coal svg .secondary-text, -.navy svg .secondary-text, -.dark svg .secondary-text, -.theme--dark svg .secondary-text { - fill: #b0b0b0 !important; -} - -.ayu svg .arrow-head, -.coal svg .arrow-head, -.navy svg .arrow-head, -.dark svg .arrow-head, -.theme--dark svg .arrow-head { - fill: #b0b0b0 !important; -} - -.ayu svg .arrow-line, -.coal svg .arrow-line, -.navy svg .arrow-line, -.dark svg .arrow-line, -.theme--dark svg .arrow-line { - stroke: #b0b0b0 !important; -} - -/* Object element styling for better SVG integration */ -object[type="image/svg+xml"] { - display: block; - max-width: 100%; - height: auto; - pointer-events: none; /* Prevent interaction issues */ - background: transparent !important; -} - -/* Ensure object fallback images are hidden when object loads */ -object[type="image/svg+xml"] img { - display: none; -} - -/* Ensure SVG containers have transparent background */ -.content object, -.content img[src$=".svg"] { - background: transparent !important; -} - -/* Remove any background from SVG wrappers */ -.content > div:has(object[type="image/svg+xml"]) { - background: transparent !important; -} - -/* Fix for mdBook's content area */ -.content object[type="image/svg+xml"] { - margin: 1em 0; - background-color: transparent !important; -} - -/* Override any mdBook theme backgrounds for SVG areas */ -.rust .content object[type="image/svg+xml"], -.light .content object[type="image/svg+xml"], -.coal .content object[type="image/svg+xml"], -.navy .content object[type="image/svg+xml"], -.ayu .content object[type="image/svg+xml"] { - background-color: transparent !important; -} - -/* Inject CSS variables into object document via JavaScript */ -.light object[type="image/svg+xml"], -.rust object[type="image/svg+xml"] { - color-scheme: light; -} - -.ayu object[type="image/svg+xml"], -.coal object[type="image/svg+xml"], -.navy object[type="image/svg+xml"], -.dark object[type="image/svg+xml"] { - color-scheme: dark; -} - -/* Additional mdBook theme detection */ -body:not([class*="theme"]) svg .main-text, -body:not([class*="ayu"]):not([class*="coal"]):not([class*="navy"]) - svg - .main-text { - fill: var(--svg-main-text-color, #1a1a1a) !important; -} - -body:not([class*="theme"]) svg .secondary-text, -body:not([class*="ayu"]):not([class*="coal"]):not([class*="navy"]) - svg - .secondary-text { - fill: var(--svg-secondary-text-color, #666) !important; -} - -body:not([class*="theme"]) svg .arrow-head, -body:not([class*="ayu"]):not([class*="coal"]):not([class*="navy"]) - svg - .arrow-head { - fill: var(--svg-arrow-color, #666) !important; -} - -body:not([class*="theme"]) svg .arrow-line, -body:not([class*="ayu"]):not([class*="coal"]):not([class*="navy"]) - svg - .arrow-line { - stroke: var(--svg-arrow-color, #666) !important; -} - -/* Print styles */ -@media print { - svg .main-text { - fill: #1a1a1a !important; - } - - svg .secondary-text { - fill: #666 !important; - } - - svg .arrow-head { - fill: #666 !important; - } - - svg .arrow-line { - stroke: #666 !important; - } -} - -/* Accessibility improvements */ -@media (prefers-contrast: high) { - svg .main-text { - fill: #000000 !important; - } - - .dark svg .main-text, - .ayu svg .main-text, - .coal svg .main-text, - .navy svg .main-text { - fill: #ffffff !important; - } -} - -/* Custom scrollbar for SVG containers if needed */ -object[type="image/svg+xml"]::-webkit-scrollbar { - width: 8px; - height: 8px; -} - -object[type="image/svg+xml"]::-webkit-scrollbar-track { - background: transparent; -} - -object[type="image/svg+xml"]::-webkit-scrollbar-thumb { - background: rgba(0, 0, 0, 0.2); - border-radius: 4px; -} - -.dark object[type="image/svg+xml"]::-webkit-scrollbar-thumb { - background: rgba(255, 255, 255, 0.2); -} diff --git a/docs/src/executive-vision.md b/docs/src/executive-vision.md deleted file mode 100644 index 84ba6e46..00000000 --- a/docs/src/executive-vision.md +++ /dev/null @@ -1,196 +0,0 @@ -# EXECUTIVE VISION: GENERAL BOTS PLATFORM - -## **OPEN SOURCE ENTERPRISE AI PLATFORM** - -General Bots 6.1 delivers enterprise-grade AI capabilities with full data sovereignty. Own your infrastructure, control your data, deploy anywhere. - -## FEATURE OVERVIEW - -| **CAPABILITY** | **WHAT IT DOES** | **BUSINESS IMPACT** | **TIME TO VALUE** | -|----------------|------------------|---------------------|-------------------| -| **AI-POWERED CONVERSATIONS** | Multi-channel bot orchestration with LLM integration (GPT-4, Claude, Llama, DeepSeek) | Significant reduction in customer service costs | < 1 hour | -| **KNOWLEDGE BASES** | Vector-indexed document collections with semantic search (Qdrant/FAISS) | Faster information retrieval | 15 minutes | -| **EMAIL AUTOMATION** | Full IMAP/SMTP integration with intelligent routing | Automated inbox management | 5 minutes | -| **LLM-ASSISTED BASIC** | Plain English programming with LLM code generation | No programming skills needed | Immediate | -| **DRIVE INTEGRATION** | S3-compatible storage with automatic document processing | Scalable storage | 2 minutes | -| **ENTERPRISE SECURITY** | Argon2 hashing, JWT tokens, TLS everywhere | Bank-grade security out of the box | Built-in | -| **INSTANT THEMING** | CSS-based UI customization | Brand consistency | < 30 seconds | -| **COMPLIANCE READY** | Built-in attendance, audit logs, GDPR/LGPD/HIPAA support | Regulatory compliance | Pre-configured | -| **NVIDIA GPU SUPPORT** | CUDA acceleration for LLM operations | Faster AI responses | When available | -| **OMNICHANNEL** | WhatsApp, Teams, Instagram, Telegram, Slack, Web - ONE codebase | Unified customer engagement | Single deploy | -| **CALENDAR MANAGEMENT** | Full scheduling, meeting coordination, availability tracking | Efficient scheduling | 3 minutes | -| **TASK AUTOMATION** | Cron-based scheduling, workflow orchestration | 24/7 automation | 5 minutes | -| **WHITEBOARD COLLABORATION** | Real-time collaborative drawing and diagramming | Visual team collaboration | Instant | -| **VIDEO CONFERENCING** | LiveKit WebRTC integration for meetings | High-quality meetings | 10 minutes | -| **ANALYTICS DASHBOARD** | Real-time metrics, usage patterns, performance monitoring | Data-driven decisions | Built-in | -| **AUTOMATED REPORTS** | Scheduled reports, custom metrics, export to PDF/Excel | Executive visibility | 2 minutes | -| **BACKUP & RESTORE** | Automated backups, point-in-time recovery, export as ZIP | Data protection | Automatic | -| **MONITORING & ALERTS** | System health, performance metrics, custom alerts | High availability | Pre-configured | -| **DOCUMENT PROCESSING** | OCR, PDF extraction, Excel parsing, image analysis | Document automation | Automatic | -| **MIGRATION TOOLS** | Import from Office 365, Google Workspace, Slack | Seamless transition | < 1 day | -| **API GATEWAY** | REST, GraphQL, Webhooks, WebSocket support | Integration ready | Ready | -| **USER DIRECTORY** | LDAP/AD replacement, SSO, group management | Central authentication | 15 minutes | -| **VOICE PROCESSING** | Speech-to-text, text-to-speech, voice commands | Voice interfaces | 5 minutes | - -## DEPLOYMENT OPTIONS - -### **Option 1: Pragmatismo Managed Hosting** -- Fully managed infrastructure -- Access via: YourCompany.pragmatismo.com.br -- Professional support included -- Complete data ownership - -### **Option 2: Self-Hosted** -- Deploy on your own infrastructure -- Full control over hardware and configuration -- Access via your own domain -- No external dependencies - -### **Option 3: Hybrid Deployment** -- Run locally with cloud backup -- Export everything as ZIP anytime -- Move between hosting options freely -- No vendor lock-in - -## TECHNICAL ARCHITECTURE - -| **COMPONENT** | **TECHNOLOGY** | **PERFORMANCE** | -|---------------|----------------|-----------------| -| **Core Runtime** | Rust + Tokio | Millions of concurrent connections | -| **Database** | PostgreSQL + Diesel | Sub-millisecond queries | -| **Vector Search** | Qdrant/FAISS | 100M+ documents indexed | -| **Caching** | Redis + Semantic Cache | 95% cache hit ratio | -| **Message Queue** | Built-in async channels | Zero latency routing | -| **File Processing** | Parallel PDF/DOC/Excel extraction + OCR | 1000 docs/minute | -| **Security Layer** | TLS 1.3 + Argon2 + JWT | Enterprise-grade security | -| **Video Infrastructure** | LiveKit WebRTC | 4K video, 50ms latency | -| **Time-Series Metrics** | InfluxDB 3 | 2.5M+ points/sec ingestion | -| **Backup System** | Incremental snapshots | RPO < 1 hour | -| **API Gateway** | Axum + Tower middleware | 100K requests/second | -| **Task Scheduler** | Cron + async workers | Millisecond precision | - -## FEATURE TIERS - -### Core Edition (Default) -- UI Server -- Console Interface -- Chat functionality -- Automation engine -- Task management -- Drive integration -- LLM support -- Redis caching -- Directory services - -### Standard Edition -- All Core features plus: -- Email integration (IMAP/SMTP) -- Calendar management -- Video meetings (LiveKit) -- Enhanced automation - -### Enterprise Edition -- All Standard features plus: -- Compliance monitoring (LGPD/GDPR/HIPAA) -- Attendance tracking -- Vector database (Qdrant) -- NVIDIA GPU acceleration -- Advanced monitoring -- gRPC support -- Multi-channel messaging (WhatsApp, Teams, Instagram) - -### Full Edition -- All features enabled -- Complete platform capabilities - -## COMPLIANCE & PRIVACY - -General Bots includes built-in compliance templates: - -### Privacy Rights Center (privacy.gbai) -- **Data Access Requests** - LGPD Art. 18 / GDPR Art. 15 -- **Data Rectification** - LGPD Art. 18 III / GDPR Art. 16 -- **Data Erasure** - LGPD Art. 18 VI / GDPR Art. 17 (Right to be Forgotten) -- **Data Portability** - LGPD Art. 18 V / GDPR Art. 20 -- **Consent Management** - LGPD Art. 8 / GDPR Art. 7 -- **Processing Objection** - LGPD Art. 18 IV / GDPR Art. 21 - -### Supported Frameworks -- **LGPD** (Lei Geral de Proteção de Dados - Brazil) -- **GDPR** (General Data Protection Regulation - EU) -- **HIPAA** (Health Insurance Portability and Accountability Act) -- **CCPA** (California Consumer Privacy Act) -- **SOC 2** (Service Organization Control) -- **ISO 27001** (Information Security Management) - -## QUICK START - -```bash -# Install BotServer -cargo install botserver - -# Initialize your deployment -botserver --init my-company - -# Start the server -botserver --start -``` - -## PLATFORM COMPARISON - -| **Aspect** | **Traditional SaaS** | **General Bots** | -|------------|---------------------|------------------| -| Licensing | Per-user monthly fees | Open source (AGPL) | -| Data Location | Vendor cloud | Your choice | -| Customization | Limited | Unlimited | -| AI Models | Fixed provider | Any provider | -| Source Code | Closed | Open | -| Vendor Lock-in | High | None | -| Data Portability | Often difficult | Full export anytime | - -## INTEGRATION CAPABILITIES - -### LLM Providers -- OpenAI (GPT-4, GPT-3.5) -- Anthropic (Claude) -- Meta (Llama) -- DeepSeek -- Local models via Ollama -- Any OpenAI-compatible API - -### Communication Channels -- WhatsApp Business -- Microsoft Teams -- Telegram -- Slack -- Instagram -- Web chat -- SMS - -### Storage Backends -- AWS S3 -- MinIO -- Any S3-compatible storage -- Local filesystem - -### Directory Services -- Built-in user management -- LDAP integration -- Active Directory -- OAuth/OIDC SSO - -## ABOUT PRAGMATISMO - -Pragmatismo develops General Bots as an open-source platform for enterprise AI and automation. Our focus is on delivering practical, production-ready solutions that organizations can deploy and customize to meet their specific needs. - -**Repository:** [github.com/GeneralBots/BotServer](https://github.com/GeneralBots/BotServer) - -**License:** AGPL-3.0 - ---- - -## NEXT STEPS - -[Chapter 01: Run and Talk →](./chapter-01/README.md) - -Get started with your General Bots deployment in minutes. \ No newline at end of file diff --git a/docs/src/favicon.png b/docs/src/favicon.png deleted file mode 100644 index 651fe52e..00000000 Binary files a/docs/src/favicon.png and /dev/null differ diff --git a/docs/src/glossary.md b/docs/src/glossary.md deleted file mode 100644 index 059977b3..00000000 --- a/docs/src/glossary.md +++ /dev/null @@ -1,343 +0,0 @@ -# Glossary - -Quick lookup for General Bots terms. If you're lost, start here. - ---- - -## A - -**A2A Protocol** - Agent-to-Agent Protocol. Enables bots to communicate and delegate tasks to each other in multi-agent systems. Messages include request, response, broadcast, and delegate types. - -**ADD BOT** - BASIC keyword to add a bot to the current session with triggers, tools, or schedules. - -**Argon2** - Password hashing algorithm used for secure credential storage. Makes brute-force attacks computationally infeasible. - -**Auto-Bootstrap** - The automatic first-run process that installs and configures all dependencies: PostgreSQL, cache, storage, and LLM servers. - ---- - -## B - -**BASIC** - The scripting language for General Bots dialogs. Inspired by the 1964 language, simplified for conversational AI. Powers all `.bas` scripts with keywords like TALK, HEAR, and LLM. - -**BM25** - Best Match 25. Sparse retrieval algorithm for keyword-based search. Used in hybrid RAG alongside dense (semantic) search. - -**BOOK** - BASIC keyword to schedule calendar appointments. - -**Bot Memory** - Persistent storage scoped to a single bot, shared across all users. Access with `SET BOT MEMORY` and `GET BOT MEMORY`. - -**Bot Package** - A folder ending in `.gbai` containing everything to run a bot: scripts, documents, and configuration. - -**BotSession** - The active conversation between user and bot. Tracks state, history, and context. Persists to database, cached for speed. - -**Bootstrap** - Initial setup process that installs all dependencies automatically on first launch. - -**BROADCAST TO BOTS** - BASIC keyword to send a message to all bots in the current session. - ---- - -## C - -**Cache** - In-memory storage component for sessions, temporary data, and semantic caching. Provides sub-millisecond access times. - -**Collection** - A folder of documents in `.gbkb/` that becomes searchable knowledge. Each subfolder is a separate collection. - -**Chunking** - The process of splitting documents into smaller pieces for embedding and retrieval. Default chunk size is optimized for context windows. - -**config.csv** - The configuration file for each bot. Simple key-value pairs in CSV format. Lives in the `.gbot/` folder. - -**Context** - Information available to the LLM during a conversation. Includes history, knowledge base results, and user-provided context via `SET CONTEXT`. - -**Context Compaction** - Automatic summarization of older conversation history to fit within token limits while preserving important information. - -**CREATE DRAFT** - BASIC keyword to compose and save an email draft to the user's mailbox. - -**CREATE TASK** - BASIC keyword to create a task with assignee and due date. - ---- - -## D - -**DELEGATE TO BOT** - BASIC keyword to send a task to another bot and optionally wait for a response. - -**Dense Search** - Semantic search using vector embeddings. Finds content by meaning rather than exact keywords. - -**Dialog** - A `.bas` script defining conversation flow. Contains BASIC code with keywords like TALK and HEAR. - -**Drive** - Built-in S3-compatible object storage. Stores documents, templates, and uploads. Auto-installed during bootstrap. - ---- - -## E - -**Embedding** - Text converted to numerical vectors for similarity search. Similar meanings produce similar vectors. - -**Embedding Model** - Neural network that generates embeddings. Default is BGE, replaceable with any GGUF-compatible model. - -**Episodic Memory** - Summaries of past conversations stored for long-term context. Automatically generated when conversations end. - -**Event Handler** - BASIC code triggered by events. Use `ON` keyword with triggers like `"login"`, `"email"`, or cron expressions. - ---- - -## F - -**FIND** - BASIC keyword to search database tables with filter criteria. Returns matching records. - -**FOR EACH** - BASIC keyword for iterating over collections and query results. - ---- - -## G - -**.gbai** - "General Bot AI" package folder. Contains the entire bot. Example: `support.gbai/` becomes the bot at `/support`. - -**.gbdialog** - Subfolder containing BASIC scripts. Must include `start.bas` as the entry point. Tools go in `tools/` subdirectory. - -**.gbdrive** - File storage configuration subfolder. Maps to Drive buckets for document management. - -**.gbkb** - "Knowledge Base" subfolder. Each subdirectory becomes a searchable collection with automatic indexing. - -**.gbot** - Configuration subfolder containing `config.csv` with bot settings. - -**.gbtheme** - Optional UI customization subfolder for CSS, images, and HTML templates. - -**General Bots** - Open-source enterprise conversational AI platform. Combines LLMs with structured dialogs, knowledge bases, and multi-channel support. - -**GET** - BASIC keyword to retrieve data from APIs, files, or session variables. - -**GET BOT MEMORY** - BASIC keyword to retrieve persistent bot-level data. - -**GET USER MEMORY** - BASIC keyword to retrieve cross-session user data accessible from any bot. - -**GraphQL** - Query language for APIs. Supported via the `GRAPHQL` keyword for complex data retrieval. - ---- - -## H - -**HEAR** - BASIC keyword to wait for and capture user input. `name = HEAR` stores the response in a variable. - -**Hot Reload** - Automatic reloading of BASIC scripts when files change. No restart needed. - -**Hybrid Search** - RAG approach combining dense (semantic) and sparse (keyword) retrieval using Reciprocal Rank Fusion. - -**HTMX** - Frontend library used for dynamic UI updates without full page reloads. - ---- - -## I - -**INSERT** - BASIC keyword to add records to database tables. - -**Intent** - What the user wants to accomplish. Detected from natural language via LLM classification. - ---- - -## K - -**Keyword** - A BASIC command like TALK, HEAR, or LLM. About 50+ available. Written in uppercase by convention. - -**Knowledge Base (KB)** - Documents searchable by the bot. Organized in folders under `.gbkb/`. Activate with `USE KB "foldername"`. - ---- - -## L - -**LiveKit** - WebRTC platform used for video meetings in General Bots. - -**LLM** - Large Language Model. The AI that powers natural conversation. Supports OpenAI, Anthropic, Groq, and local models via llama.cpp. - -**llama.cpp** - C++ library for running LLM inference locally. Used for self-hosted model deployment. - -**Local-First** - Architecture principle where everything runs locally by default. No cloud dependencies required. - ---- - -## M - -**MCP** - Model Context Protocol. Standard format for defining tools that LLMs can call. Supported alongside OpenAI function format. - -**Memory** - Data persistence system with four scopes: User Memory (cross-bot), Bot Memory (per-bot), Session Memory (temporary), and Episodic Memory (conversation summaries). - -**Model Routing** - Dynamic selection of LLM models based on task requirements. Use `USE MODEL "fast"`, `"quality"`, `"code"`, or `"auto"`. - -**Multi-Agent** - Architecture where multiple specialized bots collaborate on complex tasks. - -**Multi-Channel** - Same bot works across WhatsApp, Telegram, Teams, Web, and other channels without modification. - ---- - -## N - -**No Forms** - General Bots philosophy since 2017: people should converse, not fill forms. Conversations replace traditional UI forms. - ---- - -## O - -**ON** - BASIC keyword to define event handlers for triggers, schedules, or webhooks. - -**OIDC** - OpenID Connect. Authentication protocol handled by the Directory service (Zitadel). - ---- - -## P - -**Package Manager** - Built-in system that installs bot packages. Drop a `.gbai` folder and it's automatically loaded. - -**PARAM** - Declares tool parameters. `PARAM name, email` means the tool needs these inputs. LLM collects them automatically. - -**PostgreSQL** - The database for General Bots. Stores users, sessions, messages, and bot configuration. Auto-installed and auto-configured. - -**POST** - BASIC keyword to make HTTP POST requests to external APIs. - -**Pragmatismo** - Brazilian software company that created and maintains General Bots. - ---- - -## Q - -**Qdrant** - Vector database for semantic search at scale. Optional component for large knowledge bases. - ---- - -## R - -**RAG** - Retrieval-Augmented Generation. Pattern where relevant documents are retrieved and provided to the LLM as context. - -**Reranking** - Optional LLM-based scoring of search results for improved relevance. Adds latency but improves quality. - -**Rhai** - Rust scripting engine that powers the BASIC interpreter. Sandboxed and safe. - -**RRF** - Reciprocal Rank Fusion. Algorithm for combining rankings from multiple search methods in hybrid RAG. - -**RUN PYTHON / JAVASCRIPT / BASH** - BASIC keywords to execute code in sandboxed environments. - ---- - -## S - -**SAVE** - BASIC keyword to write data to CSV files or database tables. - -**Script** - A `.bas` file with BASIC code. `start.bas` is the entry point; other scripts are tools or utilities. - -**Semantic Cache** - Caching system that matches similar (not just identical) queries to reuse LLM responses. - -**Semantic Search** - Finding content by meaning rather than exact keywords. Powered by embeddings and vector similarity. - -**SEND MAIL** - BASIC keyword to send emails with optional HTML and attachments. - -**Session** - Active conversation state between user and bot. Expires after inactivity (default 30 minutes). - -**Session Memory** - Temporary storage for the current conversation. Access with `SET` and `GET`. - -**SET** - BASIC keyword to store values in session variables or update database records. - -**SET BOT MEMORY** - BASIC keyword to store persistent bot-level data. - -**SET CONTEXT** - BASIC keyword to add information to the LLM context. Influences all subsequent responses. - -**SET SCHEDULE** - BASIC keyword for cron-based task scheduling. Accepts natural language like `"every monday at 9am"`. - -**SET USER MEMORY** - BASIC keyword to store cross-session user data accessible from any bot. - -**Sparse Search** - Keyword-based search using algorithms like BM25. Excels at exact matches and rare terms. - -**SSE** - Server-Sent Events. Used for real-time streaming of LLM responses. - -**Stalwart** - Email server component providing IMAP/SMTP/JMAP support. - -**Suite** - The complete General Bots workspace application with Chat, Drive, Tasks, Mail, Calendar, and other apps. - -**SWITCH** - BASIC keyword for multi-way conditional branching. - ---- - -## T - -**TALK** - BASIC keyword to send messages to the user. Supports text, markdown, and multimedia. - -**Template** - Pre-built bot configuration in the `templates/` folder. Copy and modify to create new bots. - -**Token** - Unit of text for LLMs. Roughly 4 characters. Context windows are measured in tokens. - -**Tool** - A `.bas` file the LLM can call automatically. Define with `PARAM` declarations and a `DESCRIPTION`. Place in the `tools/` folder. - -**TRANSFER CONVERSATION** - BASIC keyword to hand off the entire conversation to another bot. - ---- - -## U - -**UPDATE** - BASIC keyword to modify existing database records. - -**USE KB** - BASIC keyword to activate a knowledge base for semantic search. `USE KB "policies"` makes the policies collection searchable. - -**USE MODEL** - BASIC keyword to switch LLM models. Options: `"fast"`, `"quality"`, `"code"`, or `"auto"`. - -**USE TOOL** - BASIC keyword to enable a tool for LLM use. The AI determines when to call it. - -**User Memory** - Persistent storage scoped to a user, accessible across all bots and sessions. - ---- - -## V - -**Vault** - HashiCorp Vault. Secrets management service for storing credentials securely. Only `VAULT_*` environment variables are used. - -**Vector** - Mathematical representation of meaning. Similar meanings produce similar vectors. - -**Vector Database** - Database optimized for storing and searching embeddings. Qdrant is the default option. - ---- - -## W - -**WAIT** - BASIC keyword to pause execution for a specified duration. - -**WEBHOOK** - BASIC keyword to create HTTP endpoints that trigger bot actions. - -**WebSocket** - Real-time connection for chat. Enables instant messaging without polling. Path: `/ws`. - ---- - -## Z - -**Zitadel** - Identity and access management service. Handles authentication, users, and permissions. - ---- - -## Package Extensions - -| Extension | Purpose | -|-----------|---------| -| `.gbai` | Complete bot package | -| `.gbdialog` | BASIC scripts | -| `.gbkb` | Knowledge base documents | -| `.gbot` | Bot configuration | -| `.gbtheme` | UI customization | -| `.gbdrive` | File storage mapping | -| `.bas` | BASIC script file | - ---- - -## Common Confusions - -**"Do I need containers?"** - No. BotServer installs everything directly or in optional LXC containers. - -**"What database?"** - PostgreSQL, automatically installed and configured. - -**"What about scaling?"** - Single server handles 1000+ concurrent users. Scale by running multiple instances. - -**"Is BASIC really BASIC?"** - Inspired by BASIC, not strict implementation. Simplified and focused on conversations. - -**"Can I use TypeScript/Python/etc?"** - BASIC handles conversation logic. Use `RUN PYTHON/JAVASCRIPT` for code execution, or integrate via REST API. - -**"Is it production-ready?"** - Yes. Used in production since 2016, current Rust version since 2023. - ---- - -
- General Bots -
\ No newline at end of file diff --git a/docs/src/introduction.md b/docs/src/introduction.md deleted file mode 100644 index 201cc031..00000000 --- a/docs/src/introduction.md +++ /dev/null @@ -1,266 +0,0 @@ -# Introduction to General Bots - -**Build conversational AI bots in minutes, not months.** General Bots lets you create intelligent chatbots by writing simple [BASIC scripts](./chapter-06-gbdialog/basics.md) and dropping in your [documents](./chapter-02/gbkb.md). No complex frameworks, no cloud dependencies, no AI expertise required. - -## The No Forms Movement - -General Bots in 2017 - -Since 2017, Pragmatismo has championed the **No Forms** philosophy. The idea is simple but revolutionary: - -> **People should converse, not fill forms.** - -Traditional software forces users into rigid forms with dropdowns, checkboxes, and validation errors. But humans don't communicate that way. We talk. We explain. We ask questions. - -General Bots was born from this vision: **replace forms with conversations**. - -### Before: The Form Experience - -``` -┌─────────────────────────────────────────┐ -│ Customer Support Form │ -├─────────────────────────────────────────┤ -│ Name: [_______________] │ -│ Email: [_______________] │ -│ Department: [Select ▼] │ -│ Priority: ○ Low ○ Medium ○ High │ -│ Subject: [_______________] │ -│ Description: │ -│ [ ] │ -│ [ ] │ -│ │ -│ Attachments: [Choose File] │ -│ │ -│ [Submit] │ -│ │ -│ ⚠️ Error: Email format invalid │ -│ ⚠️ Error: Description required │ -└─────────────────────────────────────────┘ -``` - -**Problems:** -- Intimidating for users -- Requires learning the interface -- Validation errors frustrate -- No guidance or context -- One-size-fits-all approach - -### After: The Conversation Experience - -``` -User: I need help with my order -Bot: I'd be happy to help! What's your order number? -User: It's 12345 -Bot: Found it - your laptop order from last week. What's the issue? -User: It arrived damaged -Bot: I'm sorry to hear that. I'll create a return label for you. - Should I send it to your email on file? -User: Yes please -Bot: Done! Check your inbox. Is there anything else? -``` - -**Benefits:** -- Natural and intuitive -- Guides users step by step -- Adapts to each situation -- No errors, just clarifications -- Feels like talking to a human - -### Projections, Not Screens - -The No Forms philosophy extends beyond chat. In General Bots: - -- **Visualizations replace dashboards** - Data is projected contextually, not displayed in static grids -- **Conversations replace menus** - Ask for what you need, don't hunt through options -- **AI handles complexity** - The system adapts, users don't configure -- **Voice-first design** - Everything works without a screen - -This is why General Bots focuses on: -1. **Conversational interfaces** - Chat, voice, messaging -2. **Contextual projections** - Show relevant info when needed -3. **Minimal UI** - The less interface, the better -4. **AI interpretation** - Understand intent, not just input - -## Quick Example - -Want a student enrollment bot? Here's all you need: - -1. **Drop your documents** in a [`.gbkb` folder](./chapter-02/gbkb.md): -``` -edu.gbkb/ - enrollment-policy.pdf - course-catalog.pdf -``` - -2. **Write a simple [tool](./chapter-03/kb-and-tools.md)** (optional): -```basic -' enrollment.bas -PARAM name, email, course -SAVE "enrollments.csv", name, email, course -TALK "Welcome to " + course + "!" -``` - -3. **Chat naturally**: -``` -User: I want to enroll in computer science -Bot: I'll help you enroll! What's your name? -User: Sarah Chen -Bot: Welcome to Computer Science, Sarah! -``` - -No form. No UI. Just conversation. - -## What Makes General Bots Different - -### Just Run It -```bash -./botserver -``` -That's it. No Kubernetes, no cloud accounts. The [bootstrap process](./chapter-01/installation.md) installs everything locally in 2-5 minutes. PostgreSQL, vector database, object storage, cache - all configured automatically with secure credentials stored in Vault. - -### Real BASIC, Real Simple -We brought BASIC back for conversational AI. See our [complete keyword reference](./chapter-06-gbdialog/keywords.md): -```basic -' save-note.bas - A simple tool -PARAM topic, content -SAVE "notes.csv", topic, content, NOW() -TALK "Note saved!" -``` - -Four lines. That's a working tool the AI can call automatically. - -### Documents = Knowledge -Drop PDFs, Word docs, or text files into `.gbkb/` folders. They're instantly searchable. No preprocessing, no configuration, no pipelines. The bot answers questions from your documents automatically. - -### Tools = Functions -Create `.bas` files that the AI discovers and calls automatically. Need to save data? Send emails? Call APIs? Just write a tool. The AI figures out when and how to use it. - -## Architecture at a Glance - -General Bots is a single binary that includes everything: - -General Bots Architecture - -One process, one port, one command to run. Deploy anywhere - laptop, server, LXC container. - -## Real-World Use Cases - -### Customer Support Bot -``` -documents: FAQs, policies, procedures -tools: ticket creation, status lookup -result: 24/7 support that actually helps -``` - -### Employee Assistant -``` -documents: HR policies, IT guides, company info -tools: leave requests, equipment orders -result: Instant answers, automated workflows -``` - -### Sales Catalog Bot -``` -documents: product specs, pricing sheets -tools: quote generation, order placement -result: Interactive product discovery -``` - -### Meeting Assistant -``` -documents: agenda, previous minutes -tools: action item tracking, scheduling -result: AI-powered meeting facilitator -``` - -## The Package System - -Bots are organized as packages - just folders with a naming convention: - -``` -my-bot.gbai/ # Package root -├── my-bot.gbdialog/ # BASIC scripts -│ └── start.bas # Entry point -├── my-bot.gbkb/ # Knowledge base -│ ├── policies/ # Document collection -│ └── procedures/ # Another collection -└── my-bot.gbot/ # Configuration - └── config.csv # Bot settings -``` - -Copy the folder to deploy. That's it. No XML, no JSON schemas, no build process. - -## Getting Started in 3 Steps - -### 1. Install (2 minutes) -```bash -wget https://github.com/GeneralBots/botserver/releases/latest/botserver -chmod +x botserver -./botserver -``` - -### 2. Open Browser -``` -http://localhost:8080 -``` - -### 3. Start Chatting -The default bot is ready. Ask it anything. Modify `templates/default.gbai/` to customize. - -## Core Philosophy - -1. **No Forms** - Conversations replace forms everywhere -2. **Simplicity First** - If it needs documentation, it's too complex -3. **Everything Included** - No external dependencies to manage -4. **Production Ready** - Secure, scalable, enterprise-grade from day one -5. **AI Does the Work** - Don't write logic the LLM can handle -6. **Projections Over Screens** - Show data contextually, not in dashboards - -## Technical Highlights - -- **Language**: Written in Rust for performance and safety -- **Database**: PostgreSQL with Diesel ORM -- **Cache**: Redis-compatible cache for sessions -- **Storage**: S3-compatible object store (MinIO) -- **Vectors**: Qdrant for semantic search -- **Security**: Vault for secrets, Argon2 passwords, AES encryption -- **Identity**: Zitadel for authentication and MFA -- **LLM**: OpenAI API, Anthropic, Groq, or local models -- **Scripting**: Rhai-powered BASIC interpreter - -## A Brief History - -**2017** - Pragmatismo launches General Bots with the No Forms manifesto. The vision: conversational interfaces should replace traditional forms in enterprise software. - -**2018-2020** - Node.js implementation gains traction. Hundreds of bots deployed across banking, healthcare, education, and government sectors in Brazil and beyond. - -**2021-2023** - Major enterprises adopt General Bots for customer service automation. The platform handles millions of conversations. - -**2024** - Complete rewrite in Rust for performance, security, and reliability. Version 6.0 introduces the new architecture with integrated services. - -**Today** - General Bots powers conversational AI for organizations worldwide, staying true to the original vision: **people should converse, not fill forms**. - -## What's Next? - -- **[Chapter 01](./chapter-01/README.md)** - Install and run your first bot -- **[Chapter 02](./chapter-02/README.md)** - Understanding packages -- **[Chapter 06](./chapter-06-gbdialog/README.md)** - Writing BASIC dialogs -- **[Templates](./chapter-02/templates.md)** - Explore example bots - -## Community - -General Bots is open source (AGPL-3.0) developed by Pragmatismo.com.br and contributors worldwide. - -- **GitHub**: https://github.com/GeneralBots/botserver -- **Version**: 6.1.0 -- **Status**: Production Ready - -Ready to build your bot? Turn to [Chapter 01](./chapter-01/README.md) and let's go! - ---- - -
- General Bots -
- Built with ❤️ from Brazil since 2017 -
\ No newline at end of file diff --git a/docs/src/theme-sync.js b/docs/src/theme-sync.js deleted file mode 100644 index 5d5446e6..00000000 --- a/docs/src/theme-sync.js +++ /dev/null @@ -1,115 +0,0 @@ -// Theme synchronization for SVG documents in object elements -(function() { - 'use strict'; - - // Function to update SVG theme - function updateSVGTheme(objectElement) { - try { - const svgDoc = objectElement.contentDocument; - if (!svgDoc) return; - - const html = document.documentElement; - const body = document.body; - const svgRoot = svgDoc.documentElement; - - // Detect current theme - const isRust = html.classList.contains('rust') || body.classList.contains('rust'); - const isLight = html.classList.contains('light') || body.classList.contains('light'); - const isDark = html.classList.contains('dark') || - html.classList.contains('ayu') || - html.classList.contains('navy') || - html.classList.contains('coal') || - body.classList.contains('theme--dark'); - - // Set CSS variables in SVG - if (isRust || isLight) { - svgRoot.style.setProperty('--main-text-color', '#1a1a1a'); - svgRoot.style.setProperty('--secondary-text-color', '#666'); - svgRoot.style.setProperty('--arrow-color', '#666'); - } else if (isDark) { - svgRoot.style.setProperty('--main-text-color', '#ffffff'); - svgRoot.style.setProperty('--secondary-text-color', '#b0b0b0'); - svgRoot.style.setProperty('--arrow-color', '#b0b0b0'); - } - - // Also try to call the SVG's internal updateTheme function if it exists - if (svgDoc.defaultView && typeof svgDoc.defaultView.updateTheme === 'function') { - svgDoc.defaultView.updateTheme(); - } - } catch (e) { - // Silent fail for cross-origin or other errors - console.debug('Could not update SVG theme:', e); - } - } - - // Function to initialize all SVG objects - function initializeSVGThemes() { - const objects = document.querySelectorAll('object[type="image/svg+xml"]'); - objects.forEach(obj => { - // Wait for object to load - if (obj.contentDocument) { - updateSVGTheme(obj); - } else { - obj.addEventListener('load', () => updateSVGTheme(obj)); - } - }); - } - - // Watch for theme changes - function watchThemeChanges() { - const observer = new MutationObserver((mutations) => { - // Check if class attribute changed - const classChanged = mutations.some(m => - m.type === 'attributes' && m.attributeName === 'class' - ); - - if (classChanged) { - initializeSVGThemes(); - } - }); - - // Observe both html and body elements - observer.observe(document.documentElement, { - attributes: true, - attributeFilter: ['class'] - }); - - observer.observe(document.body, { - attributes: true, - attributeFilter: ['class'] - }); - } - - // Initialize on DOM ready - if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', () => { - initializeSVGThemes(); - watchThemeChanges(); - }); - } else { - initializeSVGThemes(); - watchThemeChanges(); - } - - // Re-initialize on mdBook theme change (mdBook specific) - if (window.playground_text) { - // mdBook is present - const themeToggle = document.getElementById('theme-toggle'); - if (themeToggle) { - themeToggle.addEventListener('click', () => { - setTimeout(initializeSVGThemes, 100); - }); - } - - // Also watch for theme picker changes - const themeChoices = document.querySelectorAll('#theme-list button'); - themeChoices.forEach(btn => { - btn.addEventListener('click', () => { - setTimeout(initializeSVGThemes, 100); - }); - }); - } - - // Expose function globally for manual updates - window.updateAllSVGThemes = initializeSVGThemes; -})(); diff --git a/docs/src/whatsapp-chat.css b/docs/src/whatsapp-chat.css deleted file mode 100644 index 9e436367..00000000 --- a/docs/src/whatsapp-chat.css +++ /dev/null @@ -1,447 +0,0 @@ -/* WhatsApp-style Chat CSS for Template Documentation - * Use this to display sample dialogs that demonstrate how templates work - */ - -/* Chat Container */ -.wa-chat { - background-color: #e5ddd5; - background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zM22.343 0L13.857 8.485 15.272 9.9l9.9-9.9h-2.83zM32 0l-3.486 3.485-1.414-1.414L30.172 0H32zM0 5.373l.828-.83 1.415 1.415L0 8.2V5.374zm0 5.656l.828-.829 5.657 5.657-1.414 1.414L0 11.03v2.828zm0 5.656l.828-.828 8.485 8.485-1.414 1.414L0 16.686v2.83zm0 5.657l.828-.828 11.314 11.314-1.414 1.414L0 22.343v2.83zM0 32l.828-.828 14.142 14.142-1.414 1.414L0 32.172V32z' fill='%23c5c5c5' fill-opacity='0.1' fill-rule='evenodd'/%3E%3C/svg%3E"); - border-radius: 8px; - padding: 20px 15px; - margin: 20px 0; - max-width: 600px; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; - font-size: 14px; -} - -/* Dark theme support */ -.coal .wa-chat, -.navy .wa-chat, -.ayu .wa-chat, -.dark .wa-chat { - background-color: #0b141a; - background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zM22.343 0L13.857 8.485 15.272 9.9l9.9-9.9h-2.83zM32 0l-3.486 3.485-1.414-1.414L30.172 0H32zM0 5.373l.828-.83 1.415 1.415L0 8.2V5.374zm0 5.656l.828-.829 5.657 5.657-1.414 1.414L0 11.03v2.828zm0 5.656l.828-.828 8.485 8.485-1.414 1.414L0 16.686v2.83zm0 5.657l.828-.828 11.314 11.314-1.414 1.414L0 22.343v2.83zM0 32l.828-.828 14.142 14.142-1.414 1.414L0 32.172V32z' fill='%23ffffff' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E"); -} - -/* Message Bubbles Base */ -.wa-message { - clear: both; - margin-bottom: 10px; - max-width: 85%; - position: relative; -} - -/* User Messages (Right side, light gray) */ -.wa-message.user { - float: right; -} - -.wa-message.user .wa-bubble { - background-color: #dcf8c6; - border-radius: 8px 0 8px 8px; - margin-left: 40px; - position: relative; -} - -.wa-message.user .wa-bubble::after { - content: ''; - position: absolute; - right: -8px; - top: 0; - border: 8px solid transparent; - border-left-color: #dcf8c6; - border-top-color: #dcf8c6; -} - -/* Dark theme user messages */ -.coal .wa-message.user .wa-bubble, -.navy .wa-message.user .wa-bubble, -.ayu .wa-message.user .wa-bubble, -.dark .wa-message.user .wa-bubble { - background-color: #005c4b; -} - -.coal .wa-message.user .wa-bubble::after, -.navy .wa-message.user .wa-bubble::after, -.ayu .wa-message.user .wa-bubble::after, -.dark .wa-message.user .wa-bubble::after { - border-left-color: #005c4b; - border-top-color: #005c4b; -} - -/* Bot Messages (Left side, white) */ -.wa-message.bot { - float: left; -} - -.wa-message.bot .wa-bubble { - background-color: #ffffff; - border-radius: 0 8px 8px 8px; - margin-right: 40px; - position: relative; -} - -.wa-message.bot .wa-bubble::before { - content: ''; - position: absolute; - left: -8px; - top: 0; - border: 8px solid transparent; - border-right-color: #ffffff; - border-top-color: #ffffff; -} - -/* Dark theme bot messages */ -.coal .wa-message.bot .wa-bubble, -.navy .wa-message.bot .wa-bubble, -.ayu .wa-message.bot .wa-bubble, -.dark .wa-message.bot .wa-bubble { - background-color: #202c33; -} - -.coal .wa-message.bot .wa-bubble::before, -.navy .wa-message.bot .wa-bubble::before, -.ayu .wa-message.bot .wa-bubble::before, -.dark .wa-message.bot .wa-bubble::before { - border-right-color: #202c33; - border-top-color: #202c33; -} - -/* Bubble Content */ -.wa-bubble { - padding: 8px 12px; - box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13); -} - -.wa-bubble p { - margin: 0; - line-height: 1.4; - color: #303030; - word-wrap: break-word; -} - -/* Dark theme text */ -.coal .wa-bubble p, -.navy .wa-bubble p, -.ayu .wa-bubble p, -.dark .wa-bubble p { - color: #e9edef; -} - -/* Timestamp */ -.wa-time { - font-size: 11px; - color: #8696a0; - text-align: right; - margin-top: 4px; -} - -.wa-message.user .wa-time { - color: #61a05e; -} - -.coal .wa-message.user .wa-time, -.navy .wa-message.user .wa-time, -.ayu .wa-message.user .wa-time, -.dark .wa-message.user .wa-time { - color: #8eb589; -} - -/* Sender Name (for bot) */ -.wa-sender { - font-size: 12px; - font-weight: 600; - color: #06cf9c; - margin-bottom: 2px; -} - -/* Checkmarks for sent/delivered/read */ -.wa-status { - display: inline-block; - margin-left: 4px; - font-size: 12px; -} - -.wa-status.sent::after { - content: '✓'; - color: #8696a0; -} - -.wa-status.delivered::after { - content: '✓✓'; - color: #8696a0; -} - -.wa-status.read::after { - content: '✓✓'; - color: #53bdeb; -} - -/* System Messages */ -.wa-system { - text-align: center; - margin: 15px 0; - clear: both; -} - -.wa-system span { - background-color: #e1f2fb; - color: #54656f; - padding: 5px 12px; - border-radius: 8px; - font-size: 12px; - box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13); -} - -.coal .wa-system span, -.navy .wa-system span, -.ayu .wa-system span, -.dark .wa-system span { - background-color: #182229; - color: #8696a0; -} - -/* Date Separator */ -.wa-date { - text-align: center; - margin: 15px 0; - clear: both; -} - -.wa-date span { - background-color: #ffffff; - color: #54656f; - padding: 5px 12px; - border-radius: 8px; - font-size: 12px; - box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13); -} - -.coal .wa-date span, -.navy .wa-date span, -.ayu .wa-date span, -.dark .wa-date span { - background-color: #182229; - color: #8696a0; -} - -/* Typing Indicator */ -.wa-typing { - float: left; - clear: both; -} - -.wa-typing .wa-bubble { - background-color: #ffffff; - border-radius: 0 8px 8px 8px; - padding: 12px 16px; -} - -.coal .wa-typing .wa-bubble, -.navy .wa-typing .wa-bubble, -.ayu .wa-typing .wa-bubble, -.dark .wa-typing .wa-bubble { - background-color: #202c33; -} - -.wa-typing-dots { - display: flex; - gap: 4px; -} - -.wa-typing-dots span { - width: 8px; - height: 8px; - background-color: #8696a0; - border-radius: 50%; - animation: wa-typing 1.4s infinite ease-in-out; -} - -.wa-typing-dots span:nth-child(1) { animation-delay: 0s; } -.wa-typing-dots span:nth-child(2) { animation-delay: 0.2s; } -.wa-typing-dots span:nth-child(3) { animation-delay: 0.4s; } - -@keyframes wa-typing { - 0%, 60%, 100% { transform: translateY(0); opacity: 0.6; } - 30% { transform: translateY(-4px); opacity: 1; } -} - -/* Clear float */ -.wa-chat::after { - content: ''; - display: table; - clear: both; -} - -/* Chat Header (optional) */ -.wa-header { - background-color: #075e54; - color: white; - padding: 10px 15px; - margin: -20px -15px 15px -15px; - border-radius: 8px 8px 0 0; - display: flex; - align-items: center; - gap: 10px; -} - -.coal .wa-header, -.navy .wa-header, -.ayu .wa-header, -.dark .wa-header { - background-color: #202c33; -} - -.wa-header-avatar { - width: 40px; - height: 40px; - background-color: #25d366; - border-radius: 50%; - display: flex; - align-items: center; - justify-content: center; - font-size: 18px; -} - -.wa-header-info { - flex: 1; -} - -.wa-header-name { - font-weight: 600; - font-size: 16px; -} - -.wa-header-status { - font-size: 12px; - opacity: 0.8; -} - -/* Input Area (for visual reference) */ -.wa-input { - background-color: #f0f2f5; - margin: 15px -15px -20px -15px; - padding: 10px 15px; - border-radius: 0 0 8px 8px; - display: flex; - align-items: center; - gap: 10px; -} - -.coal .wa-input, -.navy .wa-input, -.ayu .wa-input, -.dark .wa-input { - background-color: #202c33; -} - -.wa-input-field { - flex: 1; - background-color: #ffffff; - border: none; - border-radius: 20px; - padding: 10px 15px; - font-size: 14px; - color: #3b4a54; -} - -.coal .wa-input-field, -.navy .wa-input-field, -.ayu .wa-input-field, -.dark .wa-input-field { - background-color: #2a3942; - color: #e9edef; -} - -/* Code in messages */ -.wa-bubble code { - background-color: rgba(0, 0, 0, 0.08); - padding: 2px 4px; - border-radius: 3px; - font-family: 'SF Mono', Monaco, 'Courier New', monospace; - font-size: 13px; -} - -.coal .wa-bubble code, -.navy .wa-bubble code, -.ayu .wa-bubble code, -.dark .wa-bubble code { - background-color: rgba(255, 255, 255, 0.1); -} - -/* Links in messages */ -.wa-bubble a { - color: #027eb5; - text-decoration: none; -} - -.wa-bubble a:hover { - text-decoration: underline; -} - -.coal .wa-bubble a, -.navy .wa-bubble a, -.ayu .wa-bubble a, -.dark .wa-bubble a { - color: #53bdeb; -} - -/* Emoji sizing */ -.wa-bubble .emoji { - font-size: 20px; -} - -/* Media messages placeholder */ -.wa-media { - background-color: rgba(0, 0, 0, 0.1); - border-radius: 8px; - padding: 40px 60px; - text-align: center; - color: #8696a0; - font-size: 12px; - margin-bottom: 4px; -} - -.wa-media::before { - content: '📷'; - display: block; - font-size: 24px; - margin-bottom: 4px; -} - -/* Reply/Quote */ -.wa-reply { - background-color: rgba(0, 0, 0, 0.05); - border-left: 4px solid #06cf9c; - padding: 6px 10px; - margin-bottom: 6px; - border-radius: 4px; - font-size: 13px; -} - -.wa-reply-name { - color: #06cf9c; - font-weight: 600; - font-size: 12px; -} - -.wa-reply-text { - color: #667781; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} - -.coal .wa-reply, -.navy .wa-reply, -.ayu .wa-reply, -.dark .wa-reply { - background-color: rgba(255, 255, 255, 0.05); -} - -.coal .wa-reply-text, -.navy .wa-reply-text, -.ayu .wa-reply-text, -.dark .wa-reply-text { - color: #8696a0; -} diff --git a/src/console/wizard.rs b/src/console/wizard.rs index 6eeda9dd..d29b2c44 100644 --- a/src/console/wizard.rs +++ b/src/console/wizard.rs @@ -8,8 +8,8 @@ //! - Organization configuration //! - Bot template selection -use crate::core::shared::branding::platform_name; -use crate::core::shared::version::BOTSERVER_VERSION; +use crate::shared::platform_name; +use crate::shared::BOTSERVER_VERSION; use crossterm::{ cursor, event::{self, Event, KeyCode, KeyEvent}, diff --git a/src/core/bot/manager.rs b/src/core/bot/manager.rs index 5b9e346b..0d96e275 100644 --- a/src/core/bot/manager.rs +++ b/src/core/bot/manager.rs @@ -6,7 +6,7 @@ //! - Security/access assignment //! - Custom UI routing (/botname/gbui) -use crate::core::shared::branding::platform_name; +use crate::shared::platform_name; use chrono::{DateTime, Utc}; use log::{debug, error, info, warn}; use serde::{Deserialize, Serialize}; diff --git a/src/core/bot/multimedia.rs b/src/core/bot/multimedia.rs index c1593030..4e415c53 100644 --- a/src/core/bot/multimedia.rs +++ b/src/core/bot/multimedia.rs @@ -387,8 +387,12 @@ impl MultimediaHandler for DefaultMultimediaHandler { } /// Extension trait for UserMessage to support multimedia -impl UserMessage { - pub fn to_multimedia(&self) -> MultimediaMessage { +pub trait UserMessageMultimedia { + fn to_multimedia(&self) -> MultimediaMessage; +} + +impl UserMessageMultimedia for UserMessage { + fn to_multimedia(&self) -> MultimediaMessage { // Parse message content to determine type if self.content.starts_with("http") { // Check if it's an image/video URL diff --git a/src/core/shared/branding.rs b/src/core/shared/branding.rs deleted file mode 100644 index 012a78b1..00000000 --- a/src/core/shared/branding.rs +++ /dev/null @@ -1,395 +0,0 @@ -//! White-Label Branding Module -//! -//! Allows complete customization of platform identity. -//! When a .product file exists with name=MyCustomPlatform, -//! "General Bots" never appears in logs, display, messages, footer - nothing. -//! Only "MyCustomPlatform" and custom components. - -use log::info; -use serde::{Deserialize, Serialize}; -use std::path::Path; -use std::sync::OnceLock; - -/// Global branding configuration - loaded once at startup -static BRANDING: OnceLock = OnceLock::new(); - -/// Default platform name -const DEFAULT_PLATFORM_NAME: &str = "General Bots"; -const DEFAULT_PLATFORM_SHORT: &str = "GB"; -const DEFAULT_PLATFORM_DOMAIN: &str = "generalbots.com"; - -/// Branding configuration loaded from .product file -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BrandingConfig { - /// Platform name (e.g., "MyCustomPlatform") - pub name: String, - - /// Short name for logs and compact displays (e.g., "MCP") - pub short_name: String, - - /// Company/organization name - pub company: Option, - - /// Domain for URLs and emails - pub domain: Option, - - /// Support email - pub support_email: Option, - - /// Logo URL (for web UI) - pub logo_url: Option, - - /// Favicon URL - pub favicon_url: Option, - - /// Primary color (hex) - pub primary_color: Option, - - /// Secondary color (hex) - pub secondary_color: Option, - - /// Footer text - pub footer_text: Option, - - /// Copyright text - pub copyright: Option, - - /// Custom CSS URL - pub custom_css: Option, - - /// Terms of service URL - pub terms_url: Option, - - /// Privacy policy URL - pub privacy_url: Option, - - /// Documentation URL - pub docs_url: Option, - - /// Whether this is a white-label deployment - pub is_white_label: bool, -} - -impl Default for BrandingConfig { - fn default() -> Self { - Self { - name: DEFAULT_PLATFORM_NAME.to_string(), - short_name: DEFAULT_PLATFORM_SHORT.to_string(), - company: Some("pragmatismo.com.br".to_string()), - domain: Some(DEFAULT_PLATFORM_DOMAIN.to_string()), - support_email: Some("support@generalbots.com".to_string()), - logo_url: None, - favicon_url: None, - primary_color: Some("#25d366".to_string()), // WhatsApp green - secondary_color: Some("#075e54".to_string()), - footer_text: None, - copyright: Some(format!( - "© {} pragmatismo.com.br. All rights reserved.", - chrono::Utc::now().format("%Y") - )), - custom_css: None, - terms_url: None, - privacy_url: None, - docs_url: Some("https://docs.generalbots.com".to_string()), - is_white_label: false, - } - } -} - -impl BrandingConfig { - /// Load branding from .product file if it exists - pub fn load() -> Self { - // Check multiple locations for .product file - let search_paths = [ - ".product", - "config/.product", - "/etc/botserver/.product", - "/opt/gbo/.product", - ]; - - for path in &search_paths { - if let Ok(config) = Self::load_from_file(path) { - info!( - "Loaded white-label branding from {}: {}", - path, config.name - ); - return config; - } - } - - // Also check environment variable - if let Ok(product_file) = std::env::var("PRODUCT_FILE") { - if let Ok(config) = Self::load_from_file(&product_file) { - info!( - "Loaded white-label branding from PRODUCT_FILE={}: {}", - product_file, config.name - ); - return config; - } - } - - // Check for individual environment overrides - let mut config = Self::default(); - - if let Ok(name) = std::env::var("PLATFORM_NAME") { - config.name = name; - config.is_white_label = true; - } - - if let Ok(short) = std::env::var("PLATFORM_SHORT_NAME") { - config.short_name = short; - } - - if let Ok(company) = std::env::var("PLATFORM_COMPANY") { - config.company = Some(company); - } - - if let Ok(domain) = std::env::var("PLATFORM_DOMAIN") { - config.domain = Some(domain); - } - - if let Ok(logo) = std::env::var("PLATFORM_LOGO_URL") { - config.logo_url = Some(logo); - } - - if let Ok(color) = std::env::var("PLATFORM_PRIMARY_COLOR") { - config.primary_color = Some(color); - } - - config - } - - /// Load from a specific file path - fn load_from_file(path: &str) -> Result> { - let path = Path::new(path); - if !path.exists() { - return Err("File not found".into()); - } - - let content = std::fs::read_to_string(path)?; - - // Try parsing as TOML first - if let Ok(config) = toml::from_str::(&content) { - return Ok(config.into()); - } - - // Try parsing as simple key=value format - let mut config = Self::default(); - config.is_white_label = true; - - for line in content.lines() { - let line = line.trim(); - if line.is_empty() || line.starts_with('#') || line.starts_with(';') { - continue; - } - - if let Some((key, value)) = line.split_once('=') { - let key = key.trim().to_lowercase(); - let value = value.trim().trim_matches('"').trim_matches('\''); - - match key.as_str() { - "name" | "platform_name" => config.name = value.to_string(), - "short_name" | "short" => config.short_name = value.to_string(), - "company" | "organization" => config.company = Some(value.to_string()), - "domain" => config.domain = Some(value.to_string()), - "support_email" | "email" => config.support_email = Some(value.to_string()), - "logo_url" | "logo" => config.logo_url = Some(value.to_string()), - "favicon_url" | "favicon" => config.favicon_url = Some(value.to_string()), - "primary_color" | "color" => config.primary_color = Some(value.to_string()), - "secondary_color" => config.secondary_color = Some(value.to_string()), - "footer_text" | "footer" => config.footer_text = Some(value.to_string()), - "copyright" => config.copyright = Some(value.to_string()), - "custom_css" | "css" => config.custom_css = Some(value.to_string()), - "terms_url" | "terms" => config.terms_url = Some(value.to_string()), - "privacy_url" | "privacy" => config.privacy_url = Some(value.to_string()), - "docs_url" | "docs" => config.docs_url = Some(value.to_string()), - _ => {} - } - } - } - - Ok(config) - } -} - -/// TOML format for .product file -#[derive(Debug, Deserialize)] -struct ProductFile { - name: String, - #[serde(default)] - short_name: Option, - #[serde(default)] - company: Option, - #[serde(default)] - domain: Option, - #[serde(default)] - support_email: Option, - #[serde(default)] - logo_url: Option, - #[serde(default)] - favicon_url: Option, - #[serde(default)] - primary_color: Option, - #[serde(default)] - secondary_color: Option, - #[serde(default)] - footer_text: Option, - #[serde(default)] - copyright: Option, - #[serde(default)] - custom_css: Option, - #[serde(default)] - terms_url: Option, - #[serde(default)] - privacy_url: Option, - #[serde(default)] - docs_url: Option, -} - -impl From for BrandingConfig { - fn from(pf: ProductFile) -> Self { - let short_name = pf.short_name.unwrap_or_else(|| { - // Generate short name from first letters - pf.name - .split_whitespace() - .map(|w| w.chars().next().unwrap_or('X')) - .collect::() - .to_uppercase() - }); - - Self { - name: pf.name, - short_name, - company: pf.company, - domain: pf.domain, - support_email: pf.support_email, - logo_url: pf.logo_url, - favicon_url: pf.favicon_url, - primary_color: pf.primary_color, - secondary_color: pf.secondary_color, - footer_text: pf.footer_text, - copyright: pf.copyright, - custom_css: pf.custom_css, - terms_url: pf.terms_url, - privacy_url: pf.privacy_url, - docs_url: pf.docs_url, - is_white_label: true, - } - } -} - -// ============================================================================ -// Global Access Functions -// ============================================================================ - -/// Initialize branding at application startup -pub fn init_branding() { - let config = BrandingConfig::load(); - let _ = BRANDING.set(config); -} - -/// Get the current branding configuration -pub fn branding() -> &'static BrandingConfig { - BRANDING.get_or_init(BrandingConfig::load) -} - -/// Get the platform name (use this instead of hardcoding "General Bots") -pub fn platform_name() -> &'static str { - &branding().name -} - -/// Get the short platform name (for logs, compact displays) -pub fn platform_short() -> &'static str { - &branding().short_name -} - -/// Check if this is a white-label deployment -pub fn is_white_label() -> bool { - branding().is_white_label -} - -/// Get formatted copyright text -pub fn copyright_text() -> String { - branding().copyright.clone().unwrap_or_else(|| { - format!( - "© {} {}", - chrono::Utc::now().format("%Y"), - branding().company.as_deref().unwrap_or(&branding().name) - ) - }) -} - -/// Get footer text -pub fn footer_text() -> String { - branding().footer_text.clone().unwrap_or_else(|| { - format!("Powered by {}", platform_name()) - }) -} - -/// Format a log prefix with platform branding -pub fn log_prefix() -> String { - format!("[{}]", platform_short()) -} - -// ============================================================================ -// Macros for Branded Logging -// ============================================================================ - -/// Log with platform branding -#[macro_export] -macro_rules! branded_info { - ($($arg:tt)*) => { - log::info!("{} {}", $crate::core::shared::branding::log_prefix(), format!($($arg)*)) - }; -} - -#[macro_export] -macro_rules! branded_warn { - ($($arg:tt)*) => { - log::warn!("{} {}", $crate::core::shared::branding::log_prefix(), format!($($arg)*)) - }; -} - -#[macro_export] -macro_rules! branded_error { - ($($arg:tt)*) => { - log::error!("{} {}", $crate::core::shared::branding::log_prefix(), format!($($arg)*)) - }; -} - -// ============================================================================ -// Tests -// ============================================================================ - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_default_branding() { - let config = BrandingConfig::default(); - assert_eq!(config.name, "General Bots"); - assert_eq!(config.short_name, "GB"); - assert!(!config.is_white_label); - } - - #[test] - fn test_parse_simple_product_file() { - let content = r#" -name=MyCustomPlatform -short_name=MCP -company=My Company Inc. -domain=myplatform.com -primary_color=#ff6600 -"#; - // Test would require file system access, skipping actual load - assert!(content.contains("MyCustomPlatform")); - } - - #[test] - fn test_platform_name_function() { - // This test uses the default since no .product file exists - let name = platform_name(); - assert!(!name.is_empty()); - } -} diff --git a/src/core/shared/message_types.rs b/src/core/shared/message_types.rs deleted file mode 100644 index a0d51817..00000000 --- a/src/core/shared/message_types.rs +++ /dev/null @@ -1,82 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// Enum representing different types of messages in the bot system -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -#[serde(transparent)] -pub struct MessageType(pub i32); - -impl MessageType { - /// Regular message from external systems (WhatsApp, Instagram, etc.) - pub const EXTERNAL: MessageType = MessageType(0); - - /// User message from web interface - pub const USER: MessageType = MessageType(1); - - /// Bot response (can be regular content or event) - pub const BOT_RESPONSE: MessageType = MessageType(2); - - /// Continue interrupted response - pub const CONTINUE: MessageType = MessageType(3); - - /// Suggestion or command message - pub const SUGGESTION: MessageType = MessageType(4); - - /// Context change notification - pub const CONTEXT_CHANGE: MessageType = MessageType(5); -} - -impl From for MessageType { - fn from(value: i32) -> Self { - MessageType(value) - } -} - -impl From for i32 { - fn from(value: MessageType) -> Self { - value.0 - } -} - -impl Default for MessageType { - fn default() -> Self { - MessageType::USER - } -} - -impl std::fmt::Display for MessageType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let name = match self.0 { - 0 => "EXTERNAL", - 1 => "USER", - 2 => "BOT_RESPONSE", - 3 => "CONTINUE", - 4 => "SUGGESTION", - 5 => "CONTEXT_CHANGE", - _ => "UNKNOWN", - }; - write!(f, "{}", name) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_message_type_conversion() { - assert_eq!(i32::from(MessageType::USER), 1); - assert_eq!(MessageType::from(2), MessageType::BOT_RESPONSE); - } - - #[test] - fn test_message_type_display() { - assert_eq!(MessageType::USER.to_string(), "USER"); - assert_eq!(MessageType::BOT_RESPONSE.to_string(), "BOT_RESPONSE"); - } - - #[test] - fn test_message_type_equality() { - assert_eq!(MessageType::USER, MessageType(1)); - assert_ne!(MessageType::USER, MessageType::BOT_RESPONSE); - } -} diff --git a/src/core/shared/mod.rs b/src/core/shared/mod.rs index 95cdbd16..74445d1e 100644 --- a/src/core/shared/mod.rs +++ b/src/core/shared/mod.rs @@ -1,15 +1,67 @@ +//! Shared types and utilities +//! +//! This module re-exports common types from botlib and provides +//! botserver-specific shared functionality. + pub mod admin; pub mod analytics; -pub mod branding; -pub mod message_types; pub mod models; +pub mod schema; pub mod state; pub mod utils; -pub mod version; -// Re-export commonly used items -pub use branding::{branding, init_branding, is_white_label, platform_name, platform_short}; -pub use version::{ - get_botserver_version, init_version_registry, register_component, version_string, - ComponentStatus, ComponentVersion, VersionRegistry, BOTSERVER_VERSION, +// Re-export schema at module level for backward compatibility +pub use schema::*; + +// Re-export from botlib for backward compatibility +pub use botlib::branding::{ + branding, copyright_text, footer_text, init_branding, is_white_label, log_prefix, + platform_name, platform_short, BrandingConfig, }; +pub use botlib::error::{BotError, BotResult}; +pub use botlib::message_types; +pub use botlib::message_types::MessageType; +pub use botlib::version::{ + get_botserver_version, init_version_registry, register_component, version_string, + ComponentSource, ComponentStatus, ComponentVersion, VersionRegistry, BOTSERVER_NAME, + BOTSERVER_VERSION, +}; + +// Re-export models from botlib +pub use botlib::models::{ApiResponse, Attachment, Suggestion}; + +// Re-export BotResponse and UserMessage with full path to avoid conflicts +pub use botlib::models::BotResponse; +pub use botlib::models::Session; +pub use botlib::models::UserMessage; + +// Local re-exports - database models +pub use models::{ + Automation, Bot, BotConfiguration, BotMemory, Click, MessageHistory, NewTask, Organization, + Task, TriggerKind, User, UserLoginToken, UserPreference, UserSession, +}; + +// Database utilities +pub use utils::{create_conn, DbPool}; + +/// Prelude module for convenient imports +/// Usage: `use crate::shared::prelude::*;` +pub mod prelude { + // Re-export everything commonly needed + pub use super::schema::*; + pub use super::{ + ApiResponse, Attachment, Automation, Bot, BotConfiguration, BotError, BotMemory, + BotResponse, BotResult, Click, DbPool, MessageHistory, MessageType, NewTask, Organization, + Session, Suggestion, Task, TriggerKind, User, UserLoginToken, UserMessage, UserPreference, + UserSession, + }; + + // Diesel prelude for database operations + pub use diesel::prelude::*; + pub use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; + + // Common external types + pub use chrono::{DateTime, Utc}; + pub use serde::{Deserialize, Serialize}; + pub use uuid::Uuid; +} diff --git a/src/core/shared/models.rs b/src/core/shared/models.rs index 75948faa..781e11d8 100644 --- a/src/core/shared/models.rs +++ b/src/core/shared/models.rs @@ -1,8 +1,30 @@ -use crate::shared::message_types::MessageType; +//! Database models and diesel-specific types +//! +//! This module contains diesel ORM models and database-specific types. +//! Common API types (BotResponse, UserMessage, etc.) are now in botlib. + use chrono::{DateTime, Utc}; use diesel::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; + +// Re-export schema for backward compatibility (crate::shared::models::schema::*) +// This allows `use crate::shared::models::schema::table_name::dsl::*;` to work +pub use super::schema; + +// Also re-export individual tables at this level for convenience +pub use super::schema::{ + basic_tools, bot_configuration, bot_memories, bots, clicks, email_drafts, email_folders, + kb_collections, kb_documents, message_history, organizations, session_tool_associations, + system_automations, tasks, user_email_accounts, user_kb_associations, user_login_tokens, + user_preferences, user_sessions, users, +}; + +// Re-export common types from botlib for convenience +pub use botlib::message_types::MessageType; +pub use botlib::models::{ApiResponse, Attachment, BotResponse, Session, Suggestion, UserMessage}; + +/// Trigger kinds for automations #[derive(Debug, Clone, Copy, PartialEq)] pub enum TriggerKind { Scheduled = 0, @@ -11,8 +33,9 @@ pub enum TriggerKind { TableDelete = 3, Webhook = 4, } + impl TriggerKind { - pub fn _from_i32(value: i32) -> Option { + pub fn from_i32(value: i32) -> Option { match value { 0 => Some(Self::Scheduled), 1 => Some(Self::TableUpdate), @@ -23,6 +46,8 @@ impl TriggerKind { } } } + +/// Automation database model #[derive(Debug, Queryable, Serialize, Deserialize, Identifiable)] #[diesel(table_name = system_automations)] pub struct Automation { @@ -33,8 +58,10 @@ pub struct Automation { pub schedule: Option, pub param: String, pub is_active: bool, - pub last_triggered: Option>, + pub last_triggered: Option>, } + +/// User session database model #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable, Selectable)] #[diesel(table_name = user_sessions)] pub struct UserSession { @@ -44,80 +71,11 @@ pub struct UserSession { pub title: String, pub context_data: serde_json::Value, pub current_tool: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct UserMessage { - pub bot_id: String, - pub user_id: String, - pub session_id: String, - pub channel: String, - pub content: String, - pub message_type: MessageType, - pub media_url: Option, - pub timestamp: DateTime, - pub context_name: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Suggestion { - pub text: String, - pub context: String, + pub created_at: DateTime, + pub updated_at: DateTime, } -/// Attachment for media files in messages -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Attachment { - /// Type of attachment (image, audio, video, file, etc.) - pub attachment_type: String, - /// URL or path to the attachment - pub url: String, - /// MIME type of the attachment - pub mime_type: Option, - /// File name if available - pub filename: Option, - /// File size in bytes - pub size: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BotResponse { - pub bot_id: String, - pub user_id: String, - pub session_id: String, - pub channel: String, - pub content: String, - pub message_type: MessageType, - pub stream_token: Option, - pub is_complete: bool, - pub suggestions: Vec, - pub context_name: Option, - pub context_length: usize, - pub context_max_length: usize, -} -impl BotResponse { - pub fn from_string_ids( - bot_id: &str, - session_id: &str, - user_id: &str, - content: String, - channel: String, - ) -> Result { - Ok(Self { - bot_id: bot_id.to_string(), - user_id: user_id.to_string(), - session_id: session_id.to_string(), - channel, - content, - message_type: MessageType::BOT_RESPONSE, - stream_token: None, - is_complete: true, - suggestions: Vec::new(), - context_name: None, - context_length: 0, - context_max_length: 0, - }) - } -} +/// Bot memory storage model #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable, Insertable)] #[diesel(table_name = bot_memories)] pub struct BotMemory { @@ -125,267 +83,167 @@ pub struct BotMemory { pub bot_id: Uuid, pub key: String, pub value: String, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: DateTime, + pub updated_at: DateTime, } -pub mod schema { - diesel::table! { - organizations (org_id) { - org_id -> Uuid, - name -> Text, - slug -> Text, - created_at -> Timestamptz, - } - } - diesel::table! { - bots (id) { - id -> Uuid, - name -> Varchar, - description -> Nullable, - llm_provider -> Varchar, - llm_config -> Jsonb, - context_provider -> Varchar, - context_config -> Jsonb, - created_at -> Timestamptz, - updated_at -> Timestamptz, - is_active -> Nullable, - tenant_id -> Nullable, - } - } - diesel::table! { - system_automations (id) { - id -> Uuid, - bot_id -> Uuid, - kind -> Int4, - target -> Nullable, - schedule -> Nullable, - param -> Text, - is_active -> Bool, - last_triggered -> Nullable, - } - } - diesel::table! { - user_sessions (id) { - id -> Uuid, - user_id -> Uuid, - bot_id -> Uuid, - title -> Text, - context_data -> Jsonb, - current_tool -> Nullable, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - message_history (id) { - id -> Uuid, - session_id -> Uuid, - user_id -> Uuid, - role -> Int4, - content_encrypted -> Text, - message_type -> Int4, - message_index -> Int8, - created_at -> Timestamptz, - } - } - diesel::table! { - users (id) { - id -> Uuid, - username -> Text, - email -> Text, - password_hash -> Text, - is_active -> Bool, - is_admin -> Bool, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - clicks (id) { - id -> Uuid, - campaign_id -> Text, - email -> Text, - updated_at -> Timestamptz, - } - } - diesel::table! { - bot_memories (id) { - id -> Uuid, - bot_id -> Uuid, - key -> Text, - value -> Text, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - kb_documents (id) { - id -> Text, - bot_id -> Text, - user_id -> Text, - collection_name -> Text, - file_path -> Text, - file_size -> Integer, - file_hash -> Text, - first_published_at -> Text, - last_modified_at -> Text, - indexed_at -> Nullable, - metadata -> Text, - created_at -> Text, - updated_at -> Text, - } - } - diesel::table! { - basic_tools (id) { - id -> Text, - bot_id -> Text, - tool_name -> Text, - file_path -> Text, - ast_path -> Text, - file_hash -> Text, - mcp_json -> Nullable, - tool_json -> Nullable, - compiled_at -> Text, - is_active -> Integer, - created_at -> Text, - updated_at -> Text, - } - } - diesel::table! { - kb_collections (id) { - id -> Text, - bot_id -> Text, - user_id -> Text, - name -> Text, - folder_path -> Text, - qdrant_collection -> Text, - document_count -> Integer, - is_active -> Integer, - created_at -> Text, - updated_at -> Text, - } - } - diesel::table! { - user_kb_associations (id) { - id -> Text, - user_id -> Text, - bot_id -> Text, - kb_name -> Text, - is_website -> Integer, - website_url -> Nullable, - created_at -> Text, - updated_at -> Text, - } - } - diesel::table! { - session_tool_associations (id) { - id -> Text, - session_id -> Text, - tool_name -> Text, - added_at -> Text, - } - } - diesel::table! { - bot_configuration (id) { - id -> Uuid, - bot_id -> Uuid, - config_key -> Text, - config_value -> Text, - is_encrypted -> Bool, - config_type -> Text, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - user_email_accounts (id) { - id -> Uuid, - user_id -> Uuid, - email -> Varchar, - display_name -> Nullable, - imap_server -> Varchar, - imap_port -> Int4, - smtp_server -> Varchar, - smtp_port -> Int4, - username -> Varchar, - password_encrypted -> Text, - is_primary -> Bool, - is_active -> Bool, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - email_drafts (id) { - id -> Uuid, - user_id -> Uuid, - account_id -> Uuid, - to_address -> Text, - cc_address -> Nullable, - bcc_address -> Nullable, - subject -> Nullable, - body -> Nullable, - attachments -> Jsonb, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - email_folders (id) { - id -> Uuid, - account_id -> Uuid, - folder_name -> Varchar, - folder_path -> Varchar, - unread_count -> Int4, - total_count -> Int4, - last_synced -> Nullable, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - user_preferences (id) { - id -> Uuid, - user_id -> Uuid, - preference_key -> Varchar, - preference_value -> Jsonb, - created_at -> Timestamptz, - updated_at -> Timestamptz, - } - } - diesel::table! { - user_login_tokens (id) { - id -> Uuid, - user_id -> Uuid, - token_hash -> Varchar, - expires_at -> Timestamptz, - created_at -> Timestamptz, - last_used -> Timestamptz, - user_agent -> Nullable, - ip_address -> Nullable, - is_active -> Bool, - } - } - diesel::table! { - tasks (id) { - id -> Uuid, - title -> Text, - description -> Nullable, - status -> Text, - priority -> Text, - assignee_id -> Nullable, - reporter_id -> Nullable, - project_id -> Nullable, - due_date -> Nullable, - tags -> Array, - dependencies -> Array, - estimated_hours -> Nullable, - actual_hours -> Nullable, - progress -> Int4, - created_at -> Timestamptz, - updated_at -> Timestamptz, - completed_at -> Nullable, - } + +/// User database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = users)] +pub struct User { + pub id: Uuid, + pub username: String, + pub email: String, + pub password_hash: String, + pub is_active: bool, + pub is_admin: bool, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +/// Bot database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = bots)] +pub struct Bot { + pub id: Uuid, + pub name: String, + pub description: Option, + pub llm_provider: String, + pub llm_config: serde_json::Value, + pub context_provider: String, + pub context_config: serde_json::Value, + pub created_at: DateTime, + pub updated_at: DateTime, + pub is_active: Option, + pub tenant_id: Option, +} + +/// Organization database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = organizations)] +#[diesel(primary_key(org_id))] +pub struct Organization { + pub org_id: Uuid, + pub name: String, + pub slug: String, + pub created_at: DateTime, +} + +/// Message history database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = message_history)] +pub struct MessageHistory { + pub id: Uuid, + pub session_id: Uuid, + pub user_id: Uuid, + pub role: i32, + pub content_encrypted: String, + pub message_type: i32, + pub message_index: i64, + pub created_at: DateTime, +} + +/// Bot configuration database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = bot_configuration)] +pub struct BotConfiguration { + pub id: Uuid, + pub bot_id: Uuid, + pub config_key: String, + pub config_value: String, + pub is_encrypted: bool, + pub config_type: String, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +/// User login token database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = user_login_tokens)] +pub struct UserLoginToken { + pub id: Uuid, + pub user_id: Uuid, + pub token_hash: String, + pub expires_at: DateTime, + pub created_at: DateTime, + pub last_used: DateTime, + pub user_agent: Option, + pub ip_address: Option, + pub is_active: bool, +} + +/// User preferences database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = user_preferences)] +pub struct UserPreference { + pub id: Uuid, + pub user_id: Uuid, + pub preference_key: String, + pub preference_value: serde_json::Value, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +/// Click tracking database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = clicks)] +pub struct Click { + pub id: Uuid, + pub campaign_id: String, + pub email: String, + pub updated_at: DateTime, +} + +/// Task database model +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable)] +#[diesel(table_name = tasks)] +pub struct Task { + pub id: Uuid, + pub title: String, + pub description: Option, + pub status: String, + pub priority: String, + pub assignee_id: Option, + pub reporter_id: Option, + pub project_id: Option, + pub due_date: Option>, + pub tags: Vec, + pub dependencies: Vec, + pub estimated_hours: Option, + pub actual_hours: Option, + pub progress: i32, + pub created_at: DateTime, + pub updated_at: DateTime, + pub completed_at: Option>, +} + +/// New task for insertion +#[derive(Debug, Clone, Insertable)] +#[diesel(table_name = tasks)] +pub struct NewTask { + pub id: Uuid, + pub title: String, + pub description: Option, + pub status: String, + pub priority: String, + pub assignee_id: Option, + pub reporter_id: Option, + pub project_id: Option, + pub due_date: Option>, + pub tags: Vec, + pub dependencies: Vec, + pub estimated_hours: Option, + pub progress: i32, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_trigger_kind_conversion() { + assert_eq!(TriggerKind::from_i32(0), Some(TriggerKind::Scheduled)); + assert_eq!(TriggerKind::from_i32(4), Some(TriggerKind::Webhook)); + assert_eq!(TriggerKind::from_i32(99), None); } } -pub use schema::*; diff --git a/src/core/shared/schema.rs b/src/core/shared/schema.rs index e69de29b..067a14a6 100644 --- a/src/core/shared/schema.rs +++ b/src/core/shared/schema.rs @@ -0,0 +1,305 @@ +//! Diesel schema definitions +//! +//! Contains all database table definitions for diesel ORM. + +diesel::table! { + organizations (org_id) { + org_id -> Uuid, + name -> Text, + slug -> Text, + created_at -> Timestamptz, + } +} + +diesel::table! { + bots (id) { + id -> Uuid, + name -> Varchar, + description -> Nullable, + llm_provider -> Varchar, + llm_config -> Jsonb, + context_provider -> Varchar, + context_config -> Jsonb, + created_at -> Timestamptz, + updated_at -> Timestamptz, + is_active -> Nullable, + tenant_id -> Nullable, + } +} + +diesel::table! { + system_automations (id) { + id -> Uuid, + bot_id -> Uuid, + kind -> Int4, + target -> Nullable, + schedule -> Nullable, + param -> Text, + is_active -> Bool, + last_triggered -> Nullable, + } +} + +diesel::table! { + user_sessions (id) { + id -> Uuid, + user_id -> Uuid, + bot_id -> Uuid, + title -> Text, + context_data -> Jsonb, + current_tool -> Nullable, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + message_history (id) { + id -> Uuid, + session_id -> Uuid, + user_id -> Uuid, + role -> Int4, + content_encrypted -> Text, + message_type -> Int4, + message_index -> Int8, + created_at -> Timestamptz, + } +} + +diesel::table! { + users (id) { + id -> Uuid, + username -> Text, + email -> Text, + password_hash -> Text, + is_active -> Bool, + is_admin -> Bool, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + clicks (id) { + id -> Uuid, + campaign_id -> Text, + email -> Text, + updated_at -> Timestamptz, + } +} + +diesel::table! { + bot_memories (id) { + id -> Uuid, + bot_id -> Uuid, + key -> Text, + value -> Text, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + kb_documents (id) { + id -> Text, + bot_id -> Text, + user_id -> Text, + collection_name -> Text, + file_path -> Text, + file_size -> Integer, + file_hash -> Text, + first_published_at -> Text, + last_modified_at -> Text, + indexed_at -> Nullable, + metadata -> Text, + created_at -> Text, + updated_at -> Text, + } +} + +diesel::table! { + basic_tools (id) { + id -> Text, + bot_id -> Text, + tool_name -> Text, + file_path -> Text, + ast_path -> Text, + file_hash -> Text, + mcp_json -> Nullable, + tool_json -> Nullable, + compiled_at -> Text, + is_active -> Integer, + created_at -> Text, + updated_at -> Text, + } +} + +diesel::table! { + kb_collections (id) { + id -> Text, + bot_id -> Text, + user_id -> Text, + name -> Text, + folder_path -> Text, + qdrant_collection -> Text, + document_count -> Integer, + is_active -> Integer, + created_at -> Text, + updated_at -> Text, + } +} + +diesel::table! { + user_kb_associations (id) { + id -> Text, + user_id -> Text, + bot_id -> Text, + kb_name -> Text, + is_website -> Integer, + website_url -> Nullable, + created_at -> Text, + updated_at -> Text, + } +} + +diesel::table! { + session_tool_associations (id) { + id -> Text, + session_id -> Text, + tool_name -> Text, + added_at -> Text, + } +} + +diesel::table! { + bot_configuration (id) { + id -> Uuid, + bot_id -> Uuid, + config_key -> Text, + config_value -> Text, + is_encrypted -> Bool, + config_type -> Text, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + user_email_accounts (id) { + id -> Uuid, + user_id -> Uuid, + email -> Varchar, + display_name -> Nullable, + imap_server -> Varchar, + imap_port -> Int4, + smtp_server -> Varchar, + smtp_port -> Int4, + username -> Varchar, + password_encrypted -> Text, + is_primary -> Bool, + is_active -> Bool, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + email_drafts (id) { + id -> Uuid, + user_id -> Uuid, + account_id -> Uuid, + to_address -> Text, + cc_address -> Nullable, + bcc_address -> Nullable, + subject -> Nullable, + body -> Nullable, + attachments -> Jsonb, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + email_folders (id) { + id -> Uuid, + account_id -> Uuid, + folder_name -> Varchar, + folder_path -> Varchar, + unread_count -> Int4, + total_count -> Int4, + last_synced -> Nullable, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + user_preferences (id) { + id -> Uuid, + user_id -> Uuid, + preference_key -> Varchar, + preference_value -> Jsonb, + created_at -> Timestamptz, + updated_at -> Timestamptz, + } +} + +diesel::table! { + user_login_tokens (id) { + id -> Uuid, + user_id -> Uuid, + token_hash -> Varchar, + expires_at -> Timestamptz, + created_at -> Timestamptz, + last_used -> Timestamptz, + user_agent -> Nullable, + ip_address -> Nullable, + is_active -> Bool, + } +} + +diesel::table! { + tasks (id) { + id -> Uuid, + title -> Text, + description -> Nullable, + status -> Text, + priority -> Text, + assignee_id -> Nullable, + reporter_id -> Nullable, + project_id -> Nullable, + due_date -> Nullable, + tags -> Array, + dependencies -> Array, + estimated_hours -> Nullable, + actual_hours -> Nullable, + progress -> Int4, + created_at -> Timestamptz, + updated_at -> Timestamptz, + completed_at -> Nullable, + } +} + +// Allow tables to be joined +diesel::allow_tables_to_appear_in_same_query!( + organizations, + bots, + system_automations, + user_sessions, + message_history, + users, + clicks, + bot_memories, + kb_documents, + basic_tools, + kb_collections, + user_kb_associations, + session_tool_associations, + bot_configuration, + user_email_accounts, + email_drafts, + email_folders, + user_preferences, + user_login_tokens, + tasks, +); diff --git a/src/core/shared/version.rs b/src/core/shared/version.rs deleted file mode 100644 index d4b85a04..00000000 --- a/src/core/shared/version.rs +++ /dev/null @@ -1,514 +0,0 @@ -//! Version Tracking Module -//! -//! Tracks versions of all components and checks for updates. -//! Displays in Monitor tab of Suite and UITree (Console). - -use chrono::{DateTime, Utc}; -use log::{debug, info, warn}; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::sync::RwLock; - -/// Global version registry -static VERSION_REGISTRY: RwLock> = RwLock::new(None); - -/// Current botserver version from Cargo.toml -pub const BOTSERVER_VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const BOTSERVER_NAME: &str = env!("CARGO_PKG_NAME"); - -/// Component version information -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ComponentVersion { - /// Component name (e.g., "drive", "llm", "email") - pub name: String, - - /// Current installed version - pub version: String, - - /// Latest available version (if known) - pub latest_version: Option, - - /// Whether an update is available - pub update_available: bool, - - /// Component status - pub status: ComponentStatus, - - /// Last check time - pub last_checked: Option>, - - /// Source/origin of the component - pub source: ComponentSource, - - /// Additional metadata - pub metadata: HashMap, -} - -/// Component status -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] -pub enum ComponentStatus { - Running, - Stopped, - Error, - Updating, - NotInstalled, - Unknown, -} - -impl std::fmt::Display for ComponentStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ComponentStatus::Running => write!(f, "✅ Running"), - ComponentStatus::Stopped => write!(f, "⏹️ Stopped"), - ComponentStatus::Error => write!(f, "❌ Error"), - ComponentStatus::Updating => write!(f, "🔄 Updating"), - ComponentStatus::NotInstalled => write!(f, "⚪ Not Installed"), - ComponentStatus::Unknown => write!(f, "❓ Unknown"), - } - } -} - -/// Component source type -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub enum ComponentSource { - /// Built into botserver - Builtin, - /// Docker container - Docker, - /// LXC container - Lxc, - /// System package (apt, yum, etc.) - System, - /// Downloaded binary - Binary, - /// External service - External, -} - -impl std::fmt::Display for ComponentSource { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ComponentSource::Builtin => write!(f, "Built-in"), - ComponentSource::Docker => write!(f, "Docker"), - ComponentSource::Lxc => write!(f, "LXC"), - ComponentSource::System => write!(f, "System"), - ComponentSource::Binary => write!(f, "Binary"), - ComponentSource::External => write!(f, "External"), - } - } -} - -/// Version registry holding all component versions -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct VersionRegistry { - /// Botserver core version - pub core_version: String, - - /// All registered components - pub components: HashMap, - - /// Last global update check - pub last_update_check: Option>, - - /// Update check URL - pub update_url: Option, -} - -impl Default for VersionRegistry { - fn default() -> Self { - Self { - core_version: BOTSERVER_VERSION.to_string(), - components: HashMap::new(), - last_update_check: None, - update_url: Some("https://api.generalbots.com/updates".to_string()), - } - } -} - -impl VersionRegistry { - /// Create a new version registry - pub fn new() -> Self { - let mut registry = Self::default(); - registry.register_builtin_components(); - registry - } - - /// Register built-in components - fn register_builtin_components(&mut self) { - // Core botserver - self.register_component(ComponentVersion { - name: "botserver".to_string(), - version: BOTSERVER_VERSION.to_string(), - latest_version: None, - update_available: false, - status: ComponentStatus::Running, - last_checked: Some(Utc::now()), - source: ComponentSource::Builtin, - metadata: HashMap::from([ - ("description".to_string(), "Core bot server".to_string()), - ( - "repo".to_string(), - "https://github.com/GeneralBots/botserver".to_string(), - ), - ]), - }); - - // BASIC interpreter - self.register_component(ComponentVersion { - name: "basic".to_string(), - version: BOTSERVER_VERSION.to_string(), - latest_version: None, - update_available: false, - status: ComponentStatus::Running, - last_checked: Some(Utc::now()), - source: ComponentSource::Builtin, - metadata: HashMap::from([( - "description".to_string(), - "BASIC script interpreter".to_string(), - )]), - }); - - // LLM module - self.register_component(ComponentVersion { - name: "llm".to_string(), - version: BOTSERVER_VERSION.to_string(), - latest_version: None, - update_available: false, - status: ComponentStatus::Running, - last_checked: Some(Utc::now()), - source: ComponentSource::Builtin, - metadata: HashMap::from([( - "description".to_string(), - "LLM integration (Claude, GPT, etc.)".to_string(), - )]), - }); - } - - /// Register a component - pub fn register_component(&mut self, component: ComponentVersion) { - debug!( - "Registered component: {} v{}", - component.name, component.version - ); - self.components.insert(component.name.clone(), component); - } - - /// Update component status - pub fn update_status(&mut self, name: &str, status: ComponentStatus) { - if let Some(component) = self.components.get_mut(name) { - component.status = status; - } - } - - /// Update component version - pub fn update_version(&mut self, name: &str, version: &str) { - if let Some(component) = self.components.get_mut(name) { - component.version = version.to_string(); - component.last_checked = Some(Utc::now()); - } - } - - /// Check for updates for all components - pub async fn check_updates( - &mut self, - ) -> Result, Box> { - info!("Checking for component updates..."); - self.last_update_check = Some(Utc::now()); - - let mut updates = Vec::new(); - - // Check GitHub releases for botserver - if let Ok(latest) = Self::check_github_release("GeneralBots", "botserver").await { - if let Some(component) = self.components.get_mut("botserver") { - component.latest_version = Some(latest.clone()); - component.update_available = Self::is_newer_version(&component.version, &latest); - component.last_checked = Some(Utc::now()); - - if component.update_available { - updates.push(UpdateInfo { - component: "botserver".to_string(), - current_version: component.version.clone(), - new_version: latest, - release_notes: None, - }); - } - } - } - - // Check botmodels - if let Ok(latest) = Self::check_github_release("GeneralBots", "botmodels").await { - if let Some(component) = self.components.get_mut("botmodels") { - component.latest_version = Some(latest.clone()); - component.update_available = Self::is_newer_version(&component.version, &latest); - component.last_checked = Some(Utc::now()); - - if component.update_available { - updates.push(UpdateInfo { - component: "botmodels".to_string(), - current_version: component.version.clone(), - new_version: latest, - release_notes: None, - }); - } - } - } - - if updates.is_empty() { - info!("All components are up to date"); - } else { - info!("{} update(s) available", updates.len()); - } - - Ok(updates) - } - - /// Check GitHub releases for latest version - async fn check_github_release( - owner: &str, - repo: &str, - ) -> Result> { - let url = format!( - "https://api.github.com/repos/{}/{}/releases/latest", - owner, repo - ); - - let client = reqwest::Client::new(); - let response = client - .get(&url) - .header("User-Agent", format!("botserver/{}", BOTSERVER_VERSION)) - .send() - .await?; - - if !response.status().is_success() { - return Err(format!("GitHub API error: {}", response.status()).into()); - } - - let release: GitHubRelease = response.json().await?; - Ok(release.tag_name.trim_start_matches('v').to_string()) - } - - /// Compare versions (semver-like) - fn is_newer_version(current: &str, latest: &str) -> bool { - let parse_version = |v: &str| -> Vec { - v.trim_start_matches('v') - .split('.') - .filter_map(|s| s.parse().ok()) - .collect() - }; - - let current_parts = parse_version(current); - let latest_parts = parse_version(latest); - - for i in 0..3 { - let c = current_parts.get(i).copied().unwrap_or(0); - let l = latest_parts.get(i).copied().unwrap_or(0); - if l > c { - return true; - } else if c > l { - return false; - } - } - false - } - - /// Get all components with updates available - pub fn get_available_updates(&self) -> Vec<&ComponentVersion> { - self.components - .values() - .filter(|c| c.update_available) - .collect() - } - - /// Get component by name - pub fn get_component(&self, name: &str) -> Option<&ComponentVersion> { - self.components.get(name) - } - - /// Get all components - pub fn get_all_components(&self) -> Vec<&ComponentVersion> { - self.components.values().collect() - } - - /// Generate version summary for display - pub fn summary(&self) -> String { - let mut lines = vec![ - format!("═══════════════════════════════════════════════"), - format!(" Component Versions"), - format!("═══════════════════════════════════════════════"), - ]; - - let mut components: Vec<_> = self.components.values().collect(); - components.sort_by(|a, b| a.name.cmp(&b.name)); - - for component in components { - let update_indicator = if component.update_available { - format!(" ⬆️ {}", component.latest_version.as_deref().unwrap_or("?")) - } else { - String::new() - }; - - lines.push(format!( - " {:15} v{:10} {}{}", - component.name, component.version, component.status, update_indicator - )); - } - - if let Some(last_check) = self.last_update_check { - lines.push(format!("───────────────────────────────────────────────")); - lines.push(format!( - " Last checked: {}", - last_check.format("%Y-%m-%d %H:%M UTC") - )); - } - - lines.push(format!("═══════════════════════════════════════════════")); - lines.join("\n") - } - - /// Generate JSON version info for API - pub fn to_json(&self) -> serde_json::Value { - serde_json::json!({ - "core_version": self.core_version, - "components": self.components, - "last_update_check": self.last_update_check, - "updates_available": self.get_available_updates().len() - }) - } -} - -/// GitHub release response -#[derive(Debug, Deserialize)] -struct GitHubRelease { - tag_name: String, - #[allow(dead_code)] - name: Option, - #[allow(dead_code)] - body: Option, -} - -/// Update information -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct UpdateInfo { - pub component: String, - pub current_version: String, - pub new_version: String, - pub release_notes: Option, -} - -// ============================================================================ -// Global Functions -// ============================================================================ - -/// Initialize the global version registry -pub fn init_version_registry() { - let mut guard = VERSION_REGISTRY.write().unwrap(); - if guard.is_none() { - *guard = Some(VersionRegistry::new()); - info!( - "Version registry initialized - botserver v{}", - BOTSERVER_VERSION - ); - } -} - -/// Get the global version registry -pub fn version_registry() -> std::sync::RwLockReadGuard<'static, Option> { - VERSION_REGISTRY.read().unwrap() -} - -/// Get mutable access to the global version registry -pub fn version_registry_mut() -> std::sync::RwLockWriteGuard<'static, Option> { - VERSION_REGISTRY.write().unwrap() -} - -/// Register a new component in the global registry -pub fn register_component(component: ComponentVersion) { - if let Some(ref mut registry) = *version_registry_mut() { - registry.register_component(component); - } else { - warn!( - "Version registry not initialized when registering component: {}", - component.name - ); - } -} - -/// Update component status in the global registry -pub fn update_component_status(name: &str, status: ComponentStatus) { - if let Some(ref mut registry) = *version_registry_mut() { - registry.update_status(name, status); - } -} - -/// Get version of a specific component -pub fn get_component_version(name: &str) -> Option { - version_registry() - .as_ref() - .and_then(|r| r.get_component(name)) - .map(|c| c.version.clone()) -} - -/// Get botserver version -pub fn get_botserver_version() -> &'static str { - BOTSERVER_VERSION -} - -/// Generate version string for display -pub fn version_string() -> String { - format!("{} v{}", BOTSERVER_NAME, BOTSERVER_VERSION) -} - -// ============================================================================ -// Tests -// ============================================================================ - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_version_comparison() { - assert!(VersionRegistry::is_newer_version("1.0.0", "1.0.1")); - assert!(VersionRegistry::is_newer_version("1.0.0", "1.1.0")); - assert!(VersionRegistry::is_newer_version("1.0.0", "2.0.0")); - assert!(!VersionRegistry::is_newer_version("1.0.1", "1.0.0")); - assert!(!VersionRegistry::is_newer_version("1.0.0", "1.0.0")); - assert!(VersionRegistry::is_newer_version("v1.0.0", "v1.0.1")); - } - - #[test] - fn test_registry_creation() { - let registry = VersionRegistry::new(); - assert!(!registry.components.is_empty()); - assert!(registry.get_component("botserver").is_some()); - } - - #[test] - fn test_component_registration() { - let mut registry = VersionRegistry::new(); - registry.register_component(ComponentVersion { - name: "test-component".to_string(), - version: "1.0.0".to_string(), - latest_version: None, - update_available: false, - status: ComponentStatus::Running, - last_checked: None, - source: ComponentSource::External, - metadata: HashMap::new(), - }); - - assert!(registry.get_component("test-component").is_some()); - } - - #[test] - fn test_status_display() { - assert_eq!(format!("{}", ComponentStatus::Running), "✅ Running"); - assert_eq!(format!("{}", ComponentStatus::Error), "❌ Error"); - } - - #[test] - fn test_version_string() { - let vs = version_string(); - assert!(vs.contains(BOTSERVER_VERSION)); - } -}