2025-11-28 18:15:09 -03:00
|
|
|
use crate::shared::message_types::MessageType;
|
2025-11-22 22:55:35 -03:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
|
use diesel::prelude::*;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
|
pub enum TriggerKind {
|
|
|
|
|
Scheduled = 0,
|
|
|
|
|
TableUpdate = 1,
|
|
|
|
|
TableInsert = 2,
|
|
|
|
|
TableDelete = 3,
|
Add tar/flate2 deps and document new BASIC keywords
Add flate2 and tar dependencies for archive extraction support in file
operations. Update documentation with:
- New BASIC keywords: SWITCH/CASE, WEBHOOK, INSTR, IS_NUMERIC
- HTTP operations: POST, PUT, PATCH, DELETE_HTTP, GRAPHQL, SOAP
- Data operations: SAVE, INSERT, UPDATE, DELETE, MERGE, FILTER, etc.
- File operations: READ, WRITE, COMPRESS, EXTRACT, GENERATE_PDF, etc.
Simplify README and add appendices for external services and environment
variables. Add monitoring dashboard and player UI docs.
2025-11-30 07:53:58 -03:00
|
|
|
Webhook = 4,
|
2025-11-22 22:55:35 -03:00
|
|
|
}
|
|
|
|
|
impl TriggerKind {
|
|
|
|
|
pub fn _from_i32(value: i32) -> Option<Self> {
|
|
|
|
|
match value {
|
|
|
|
|
0 => Some(Self::Scheduled),
|
|
|
|
|
1 => Some(Self::TableUpdate),
|
|
|
|
|
2 => Some(Self::TableInsert),
|
|
|
|
|
3 => Some(Self::TableDelete),
|
Add tar/flate2 deps and document new BASIC keywords
Add flate2 and tar dependencies for archive extraction support in file
operations. Update documentation with:
- New BASIC keywords: SWITCH/CASE, WEBHOOK, INSTR, IS_NUMERIC
- HTTP operations: POST, PUT, PATCH, DELETE_HTTP, GRAPHQL, SOAP
- Data operations: SAVE, INSERT, UPDATE, DELETE, MERGE, FILTER, etc.
- File operations: READ, WRITE, COMPRESS, EXTRACT, GENERATE_PDF, etc.
Simplify README and add appendices for external services and environment
variables. Add monitoring dashboard and player UI docs.
2025-11-30 07:53:58 -03:00
|
|
|
4 => Some(Self::Webhook),
|
2025-11-22 22:55:35 -03:00
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Queryable, Serialize, Deserialize, Identifiable)]
|
|
|
|
|
#[diesel(table_name = system_automations)]
|
|
|
|
|
pub struct Automation {
|
|
|
|
|
pub id: Uuid,
|
|
|
|
|
pub bot_id: Uuid,
|
|
|
|
|
pub kind: i32,
|
|
|
|
|
pub target: Option<String>,
|
|
|
|
|
pub schedule: Option<String>,
|
|
|
|
|
pub param: String,
|
|
|
|
|
pub is_active: bool,
|
|
|
|
|
pub last_triggered: Option<chrono::DateTime<chrono::Utc>>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable, Selectable)]
|
|
|
|
|
#[diesel(table_name = user_sessions)]
|
|
|
|
|
pub struct UserSession {
|
|
|
|
|
pub id: Uuid,
|
|
|
|
|
pub user_id: Uuid,
|
|
|
|
|
pub bot_id: Uuid,
|
|
|
|
|
pub title: String,
|
|
|
|
|
pub context_data: serde_json::Value,
|
|
|
|
|
pub current_tool: Option<String>,
|
|
|
|
|
pub created_at: chrono::DateTime<Utc>,
|
|
|
|
|
pub updated_at: chrono::DateTime<Utc>,
|
|
|
|
|
}
|
|
|
|
|
#[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,
|
2025-11-28 18:15:09 -03:00
|
|
|
pub message_type: MessageType,
|
2025-11-22 22:55:35 -03:00
|
|
|
pub media_url: Option<String>,
|
|
|
|
|
pub timestamp: DateTime<Utc>,
|
|
|
|
|
pub context_name: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Suggestion {
|
|
|
|
|
pub text: String,
|
|
|
|
|
pub context: String,
|
|
|
|
|
}
|
|
|
|
|
#[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,
|
2025-11-28 18:15:09 -03:00
|
|
|
pub message_type: MessageType,
|
2025-11-22 22:55:35 -03:00
|
|
|
pub stream_token: Option<String>,
|
|
|
|
|
pub is_complete: bool,
|
|
|
|
|
pub suggestions: Vec<Suggestion>,
|
|
|
|
|
pub context_name: Option<String>,
|
|
|
|
|
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<Self, anyhow::Error> {
|
|
|
|
|
Ok(Self {
|
|
|
|
|
bot_id: bot_id.to_string(),
|
|
|
|
|
user_id: user_id.to_string(),
|
|
|
|
|
session_id: session_id.to_string(),
|
|
|
|
|
channel,
|
|
|
|
|
content,
|
2025-11-28 18:15:09 -03:00
|
|
|
message_type: MessageType::BOT_RESPONSE,
|
2025-11-22 22:55:35 -03:00
|
|
|
stream_token: None,
|
|
|
|
|
is_complete: true,
|
|
|
|
|
suggestions: Vec::new(),
|
|
|
|
|
context_name: None,
|
|
|
|
|
context_length: 0,
|
|
|
|
|
context_max_length: 0,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Identifiable, Insertable)]
|
|
|
|
|
#[diesel(table_name = bot_memories)]
|
|
|
|
|
pub struct BotMemory {
|
|
|
|
|
pub id: Uuid,
|
|
|
|
|
pub bot_id: Uuid,
|
|
|
|
|
pub key: String,
|
|
|
|
|
pub value: String,
|
|
|
|
|
pub created_at: chrono::DateTime<Utc>,
|
|
|
|
|
pub updated_at: chrono::DateTime<Utc>,
|
|
|
|
|
}
|
|
|
|
|
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<Text>,
|
|
|
|
|
llm_provider -> Varchar,
|
|
|
|
|
llm_config -> Jsonb,
|
|
|
|
|
context_provider -> Varchar,
|
|
|
|
|
context_config -> Jsonb,
|
|
|
|
|
created_at -> Timestamptz,
|
|
|
|
|
updated_at -> Timestamptz,
|
|
|
|
|
is_active -> Nullable<Bool>,
|
|
|
|
|
tenant_id -> Nullable<Uuid>,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
diesel::table! {
|
|
|
|
|
system_automations (id) {
|
|
|
|
|
id -> Uuid,
|
|
|
|
|
bot_id -> Uuid,
|
|
|
|
|
kind -> Int4,
|
|
|
|
|
target -> Nullable<Text>,
|
|
|
|
|
schedule -> Nullable<Text>,
|
|
|
|
|
param -> Text,
|
|
|
|
|
is_active -> Bool,
|
|
|
|
|
last_triggered -> Nullable<Timestamptz>,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
diesel::table! {
|
|
|
|
|
user_sessions (id) {
|
|
|
|
|
id -> Uuid,
|
|
|
|
|
user_id -> Uuid,
|
|
|
|
|
bot_id -> Uuid,
|
|
|
|
|
title -> Text,
|
|
|
|
|
context_data -> Jsonb,
|
|
|
|
|
current_tool -> Nullable<Text>,
|
|
|
|
|
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,
|
|
|
|
|
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<Text>,
|
|
|
|
|
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<Text>,
|
|
|
|
|
tool_json -> Nullable<Text>,
|
|
|
|
|
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<Text>,
|
|
|
|
|
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<Varchar>,
|
|
|
|
|
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<Text>,
|
|
|
|
|
bcc_address -> Nullable<Text>,
|
|
|
|
|
subject -> Nullable<Varchar>,
|
|
|
|
|
body -> Nullable<Text>,
|
|
|
|
|
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<Timestamptz>,
|
|
|
|
|
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<Text>,
|
|
|
|
|
ip_address -> Nullable<Varchar>,
|
|
|
|
|
is_active -> Bool,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-27 08:34:24 -03:00
|
|
|
diesel::table! {
|
|
|
|
|
tasks (id) {
|
|
|
|
|
id -> Uuid,
|
|
|
|
|
title -> Text,
|
|
|
|
|
description -> Nullable<Text>,
|
|
|
|
|
status -> Text,
|
|
|
|
|
priority -> Text,
|
|
|
|
|
assignee_id -> Nullable<Uuid>,
|
|
|
|
|
reporter_id -> Nullable<Uuid>,
|
|
|
|
|
project_id -> Nullable<Uuid>,
|
|
|
|
|
due_date -> Nullable<Timestamptz>,
|
|
|
|
|
tags -> Array<Text>,
|
|
|
|
|
dependencies -> Array<Uuid>,
|
|
|
|
|
estimated_hours -> Nullable<Float8>,
|
|
|
|
|
actual_hours -> Nullable<Float8>,
|
|
|
|
|
progress -> Int4,
|
|
|
|
|
created_at -> Timestamptz,
|
|
|
|
|
updated_at -> Timestamptz,
|
|
|
|
|
completed_at -> Nullable<Timestamptz>,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-22 22:55:35 -03:00
|
|
|
}
|
|
|
|
|
pub use schema::*;
|