Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

7.9 KB
Raw Blame
generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "linux-musl-openssl-3.0.x", "darwin-arm64"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model User {
  id     Int     @id @default(autoincrement())
  email  String  @unique
  // firstName String?
  // lastName  String?
  name   String?
  avatar String? @db.MediumText

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  settings UserSetting[]

  team   Team?   @relation(fields: [teamId], references: [id], onDelete: SetNull)
  teamId String?

  // user role
  userTeamRole UserTeamRole[]

  agentChangeActivities AiAgentActivity[]

  agentContributions AiAgentContributor[]
  agentConversations AiAgentConversation[]

  @@index([email])
}

model UserSetting {
  id           Int      @id @default(autoincrement())
  createdAt    DateTime @default(now())
  updatedAt    DateTime @default(now()) @updatedAt
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId       Int
  settingKey   String
  settingValue String   @db.MediumText

  @@unique([userId, settingKey])
}

model Team {
  id        String   @id @default(cuid())
  name      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  salt      String   @unique @default(cuid()) // for M2M

  users          User[]
  subscription   Subscription? @relation(fields: [subscriptionId], references: [id], onDelete: SetNull)
  subscriptionId String?

  // stripeCustomerId String?
  externalCustomerId String?
  referredBy         String?

  aiAgents AiAgent[]

  // team roles
  teamRoles TeamRole[]

  // team invitations

  teamSettings TeamSetting[]

  agentConversations AiAgentConversation[]

  // team hierarchy 
  parent   Team?   @relation("TeamParent", fields: [parentId], references: [id], onDelete: SetNull)
  parentId String?
  subTeams Team[]  @relation("TeamParent")

  @@index([externalCustomerId])
}

model TeamSetting {
  id           Int      @id @default(autoincrement())
  settingKey   String
  settingValue String   @db.MediumText
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt

  team   Team   @relation(fields: [teamId], references: [id], onDelete: Cascade)
  teamId String

  @@unique([teamId, settingKey])
}

model TeamRole {
  id        Int      @id @default(autoincrement())
  name      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  acl           Json?
  canManageTeam Boolean @default(false)

  isOwnerRole Boolean @default(false)

  team   Team   @relation(fields: [teamId], references: [id], onDelete: Cascade)
  teamId String

  userTeamRole UserTeamRole[]

  @@unique([teamId, id])
}

model UserTeamRole {
  userId Int
  roleId Int
  user   User @relation(fields: [userId], references: [id], onDelete: Cascade)

  sharedTeamRole  TeamRole @relation(fields: [roleId], references: [id], onDelete: Cascade)
  userSpecificAcl Json?
  isTeamInitiator Boolean  @default(false)

  @@id([userId, roleId])
}

enum SubscriptionStatus {
  ACTIVE
  CANCELED
  PAST_DUE
  UNPAID
  TRIALING
}

model Subscription {
  id        String             @id @default(cuid())
  stripeId  String
  startDate DateTime           @default(now())
  endDate   DateTime?
  status    SubscriptionStatus
  updatedAt DateTime           @updatedAt

  properties Json?

  plan   Plan @relation(fields: [planId], references: [id])
  planId Int

  object Json?

  team Team[]
}

model Plan {
  id            Int      @id @default(autoincrement())
  stripeId      String
  priceId       String
  name          String   @unique
  friendlyName  String?
  description   String?  @db.MediumText
  price         Float
  paid          Boolean  @default(true)
  isDefaultPlan Boolean  @default(false)
  properties    Json?
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt

  HTMLDescription String? @db.MediumText
  HTMLFeatures    String? @db.MediumText

  isCustomPlan Boolean @default(false)

  subscriptions Subscription[]
}

model AiAgent {
  id          String   @id @default(cuid())
  name        String
  description String?  @db.MediumText
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  salt        String   @unique @default(cuid()) // for M2M

  changeActivity AiAgentActivity[]
  contributors   AiAgentContributor[]

  // AI Agent subscription
  team        Team?        @relation(fields: [teamId], references: [id], onDelete: Cascade)
  teamId      String?
  embodiments Embodiment[]

  // AI Agent data
  aiAgentData AiAgentData?

  // AI Agent state
  aiAgentState    AiAgentState[]
  aiAgentSettings AiAgentSettings[]

  // AI Agent Locking properties
  lockId                String?
  lockAt                DateTime?
  lockedByName          String? // I avoided using the user model here to avoid unnecessary joins. I think the name is enough
  lastLockBeat          DateTime?
  lastLockSaveOperation DateTime?

  // AI Agent deployments
  AiAgentDeployment AiAgentDeployment[]

  agentConversations AiAgentConversation[]

  @@unique([teamId, id])
  @@index([createdAt])
}

model AiAgentActivity {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  type      String?
  name      String

  user   User? @relation(fields: [userId], references: [id], onDelete: SetNull)
  userId Int?

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String
}

model AiAgentContributor {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())

  user      User    @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId    Int
  isCreator Boolean @default(false)

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String

  @@unique([userId, aiAgentId])
}

model AiAgentSettings {
  id        Int      @id @default(autoincrement())
  key       String
  value     String   @db.MediumText
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String
}

model AiAgentData {
  id        Int      @id @default(autoincrement())
  data      Json?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String  @unique
}

model AiAgentDeployment {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String

  aiAgentSettings Json?
  aiAgentData     Json?

  // version of the deployment
  majorVersion Int
  minorVersion Int

  releaseNotes String? @db.MediumText

  @@unique([aiAgentId, majorVersion, minorVersion])
  @@index([id, aiAgentId])
}

model AiAgentState {
  id        Int      @id @default(autoincrement())
  key       String
  value     String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String
}

model Embodiment {
  id         Int      @id @default(autoincrement())
  type       String
  properties Json?
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String
}

model AiAgentConversation {
  id        String   @id @default(cuid())
  label     String?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  summary   String?  @db.MediumText

  chunkSize   Int?
  lastChunkID String?

  aiAgent   AiAgent @relation(fields: [aiAgentId], references: [id], onDelete: Cascade)
  aiAgentId String

  team   Team   @relation(fields: [teamId], references: [id], onDelete: Cascade)
  teamId String

  user    User? @relation(fields: [ownerId], references: [id], onDelete: SetNull)
  ownerId Int?
}