File size: 3,338 Bytes
14ea677
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
create table if not exists studio_sessions (
  id text primary key,
  project_id text not null,
  workspace_id text,
  parent_session_id text references studio_sessions(id) on delete set null,
  agent_type text not null,
  title text not null,
  directory text not null,
  permission_level text not null,
  permission_rules jsonb not null default '[]'::jsonb,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table if not exists studio_messages (
  id text primary key,
  session_id text not null references studio_sessions(id) on delete cascade,
  role text not null,
  agent text,
  text text,
  summary text,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table if not exists studio_message_parts (
  id text primary key,
  message_id text not null references studio_messages(id) on delete cascade,
  session_id text not null references studio_sessions(id) on delete cascade,
  type text not null,
  text text,
  tool text,
  call_id text,
  state jsonb,
  metadata jsonb,
  time jsonb,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table if not exists studio_runs (
  id text primary key,
  session_id text not null references studio_sessions(id) on delete cascade,
  status text not null,
  input_text text not null,
  active_agent text not null,
  created_at timestamptz not null default now(),
  completed_at timestamptz,
  error text
);

create table if not exists studio_tasks (
  id text primary key,
  session_id text not null references studio_sessions(id) on delete cascade,
  run_id text references studio_runs(id) on delete set null,
  work_id text,
  type text not null,
  status text not null,
  title text not null,
  detail text,
  metadata jsonb,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table if not exists studio_works (
  id text primary key,
  session_id text not null references studio_sessions(id) on delete cascade,
  run_id text references studio_runs(id) on delete set null,
  type text not null,
  title text not null,
  status text not null,
  latest_task_id text,
  current_result_id text,
  metadata jsonb,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table if not exists studio_work_results (
  id text primary key,
  work_id text not null references studio_works(id) on delete cascade,
  kind text not null,
  summary text not null,
  attachments jsonb,
  metadata jsonb,
  created_at timestamptz not null default now()
);

create index if not exists idx_studio_messages_session_created
  on studio_messages(session_id, created_at);

create index if not exists idx_studio_message_parts_message_created
  on studio_message_parts(message_id, created_at);

create index if not exists idx_studio_runs_session_created
  on studio_runs(session_id, created_at desc);

create index if not exists idx_studio_tasks_session_updated
  on studio_tasks(session_id, updated_at desc);

create index if not exists idx_studio_works_session_updated
  on studio_works(session_id, updated_at desc);

create index if not exists idx_studio_work_results_work_created
  on studio_work_results(work_id, created_at);