Skip to content

Commit e6b6a3a

Browse files
authored
Improve prompt templates (#14)
* Show icon when anonymous user * Improved prompt templates * Review fixes * Fix stories
1 parent 0258558 commit e6b6a3a

45 files changed

Lines changed: 3068 additions & 1690 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

migrations_sqlx/postgres/20250101000000_initial.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,21 +1123,21 @@ END $$;
11231123
-- without cross-database joins. See VectorStore trait for chunk operations.
11241124

11251125
-- ======================================================================
1126-
-- Prompts
1126+
-- Templates
11271127
-- ======================================================================
11281128

11291129
-- Reusable system prompt templates.
11301130

11311131
DO $$ BEGIN
1132-
CREATE TYPE prompt_owner_type AS ENUM ('organization', 'team', 'project', 'user');
1132+
CREATE TYPE template_owner_type AS ENUM ('organization', 'team', 'project', 'user');
11331133
EXCEPTION
11341134
WHEN duplicate_object THEN null;
11351135
END $$;
11361136

1137-
CREATE TABLE IF NOT EXISTS prompts (
1137+
CREATE TABLE IF NOT EXISTS templates (
11381138
id UUID PRIMARY KEY NOT NULL,
1139-
-- Ownership (who can access this prompt)
1140-
owner_type prompt_owner_type NOT NULL,
1139+
-- Ownership (who can access this template)
1140+
owner_type template_owner_type NOT NULL,
11411141
owner_id UUID NOT NULL,
11421142
name VARCHAR(255) NOT NULL,
11431143
description TEXT,
@@ -1152,13 +1152,13 @@ CREATE TABLE IF NOT EXISTS prompts (
11521152
UNIQUE(owner_type, owner_id, name)
11531153
);
11541154

1155-
CREATE INDEX IF NOT EXISTS idx_prompts_owner ON prompts(owner_type, owner_id);
1156-
-- Partial index for non-deleted prompts (most queries filter by deleted_at IS NULL)
1157-
CREATE INDEX IF NOT EXISTS idx_prompts_owner_active ON prompts(owner_type, owner_id) WHERE deleted_at IS NULL;
1158-
CREATE INDEX IF NOT EXISTS idx_prompts_name ON prompts(name);
1155+
CREATE INDEX IF NOT EXISTS idx_templates_owner ON templates(owner_type, owner_id);
1156+
-- Partial index for non-deleted templates (most queries filter by deleted_at IS NULL)
1157+
CREATE INDEX IF NOT EXISTS idx_templates_owner_active ON templates(owner_type, owner_id) WHERE deleted_at IS NULL;
1158+
CREATE INDEX IF NOT EXISTS idx_templates_name ON templates(name);
11591159

11601160
DO $$ BEGIN
1161-
CREATE TRIGGER update_prompts_updated_at BEFORE UPDATE ON prompts FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
1161+
CREATE TRIGGER update_templates_updated_at BEFORE UPDATE ON templates FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
11621162
EXCEPTION WHEN duplicate_object THEN null;
11631163
END $$;
11641164

migrations_sqlx/sqlite/20250101000000_initial.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,14 @@ CREATE INDEX IF NOT EXISTS idx_vector_store_files_deleted_at ON vector_store_fil
916916
-- without cross-database joins. See VectorStore trait for chunk operations.
917917

918918
-- ======================================================================
919-
-- Prompts
919+
-- Templates
920920
-- ======================================================================
921921

922922
-- Reusable system prompt templates.
923923
-- owner_type: 'organization', 'team', 'project', 'user'
924-
CREATE TABLE IF NOT EXISTS prompts (
924+
CREATE TABLE IF NOT EXISTS templates (
925925
id TEXT PRIMARY KEY NOT NULL,
926-
-- Ownership (who can access this prompt)
926+
-- Ownership (who can access this template)
927927
owner_type TEXT NOT NULL CHECK (owner_type IN ('organization', 'team', 'project', 'user')),
928928
owner_id TEXT NOT NULL,
929929
name TEXT NOT NULL,
@@ -939,10 +939,10 @@ CREATE TABLE IF NOT EXISTS prompts (
939939
UNIQUE(owner_type, owner_id, name)
940940
);
941941

942-
CREATE INDEX IF NOT EXISTS idx_prompts_owner ON prompts(owner_type, owner_id);
943-
-- Partial index for non-deleted prompts (most queries filter by deleted_at IS NULL)
944-
CREATE INDEX IF NOT EXISTS idx_prompts_owner_active ON prompts(owner_type, owner_id) WHERE deleted_at IS NULL;
945-
CREATE INDEX IF NOT EXISTS idx_prompts_name ON prompts(name);
942+
CREATE INDEX IF NOT EXISTS idx_templates_owner ON templates(owner_type, owner_id);
943+
-- Partial index for non-deleted templates (most queries filter by deleted_at IS NULL)
944+
CREATE INDEX IF NOT EXISTS idx_templates_owner_active ON templates(owner_type, owner_id) WHERE deleted_at IS NULL;
945+
CREATE INDEX IF NOT EXISTS idx_templates_name ON templates(name);
946946

947947
-- ======================================================================
948948
-- Service Accounts

src/config/limits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ pub struct ResourceLimits {
9595
#[serde(default = "default_max_conversations_per_owner")]
9696
pub max_conversations_per_owner: u32,
9797

98-
/// Maximum prompts per owner (org/team/project/user). Default: 5,000.
99-
#[serde(default = "default_max_prompts_per_owner")]
100-
pub max_prompts_per_owner: u32,
98+
/// Maximum templates per owner (org/team/project/user). Default: 5,000.
99+
#[serde(default = "default_max_templates_per_owner")]
100+
pub max_templates_per_owner: u32,
101101

102102
/// Maximum domain verifications per SSO configuration. Default: 50.
103103
#[serde(default = "default_max_domains_per_sso_config")]
@@ -146,7 +146,7 @@ impl Default for ResourceLimits {
146146
max_vector_stores_per_owner: default_max_vector_stores_per_owner(),
147147
max_files_per_vector_store: default_max_files_per_vector_store(),
148148
max_conversations_per_owner: default_max_conversations_per_owner(),
149-
max_prompts_per_owner: default_max_prompts_per_owner(),
149+
max_templates_per_owner: default_max_templates_per_owner(),
150150
max_domains_per_sso_config: default_max_domains_per_sso_config(),
151151
max_sso_group_mappings_per_org: default_max_sso_group_mappings_per_org(),
152152
max_members_per_org: default_max_members_per_org(),
@@ -218,7 +218,7 @@ fn default_max_conversations_per_owner() -> u32 {
218218
10_000
219219
}
220220

221-
fn default_max_prompts_per_owner() -> u32 {
221+
fn default_max_templates_per_owner() -> u32 {
222222
5_000
223223
}
224224

src/db/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct CachedRepos {
5353
vector_stores: Arc<dyn VectorStoresRepo>,
5454
files: Arc<dyn FilesRepo>,
5555
teams: Arc<dyn TeamRepo>,
56-
prompts: Arc<dyn PromptRepo>,
56+
templates: Arc<dyn TemplateRepo>,
5757
#[cfg(feature = "sso")]
5858
sso_group_mappings: Arc<dyn SsoGroupMappingRepo>,
5959
#[cfg(feature = "sso")]
@@ -131,7 +131,7 @@ impl DbPool {
131131
vector_stores: Arc::new(sqlite::SqliteVectorStoresRepo::new(pool.clone())),
132132
files: Arc::new(sqlite::SqliteFilesRepo::new(pool.clone())),
133133
teams: Arc::new(sqlite::SqliteTeamRepo::new(pool.clone())),
134-
prompts: Arc::new(sqlite::SqlitePromptRepo::new(pool.clone())),
134+
templates: Arc::new(sqlite::SqliteTemplateRepo::new(pool.clone())),
135135
#[cfg(feature = "sso")]
136136
sso_group_mappings: Arc::new(sqlite::SqliteSsoGroupMappingRepo::new(pool.clone())),
137137
#[cfg(feature = "sso")]
@@ -169,7 +169,7 @@ impl DbPool {
169169
vector_stores: Arc::new(sqlite::SqliteVectorStoresRepo::new(pool.clone())),
170170
files: Arc::new(sqlite::SqliteFilesRepo::new(pool.clone())),
171171
teams: Arc::new(sqlite::SqliteTeamRepo::new(pool.clone())),
172-
prompts: Arc::new(sqlite::SqlitePromptRepo::new(pool.clone())),
172+
templates: Arc::new(sqlite::SqliteTemplateRepo::new(pool.clone())),
173173
#[cfg(feature = "sso")]
174174
sso_group_mappings: unreachable!("SSO not supported in WASM builds"),
175175
#[cfg(feature = "sso")]
@@ -244,7 +244,7 @@ impl DbPool {
244244
write_pool.clone(),
245245
read_pool.clone(),
246246
)),
247-
prompts: Arc::new(postgres::PostgresPromptRepo::new(
247+
templates: Arc::new(postgres::PostgresTemplateRepo::new(
248248
write_pool.clone(),
249249
read_pool.clone(),
250250
)),
@@ -330,7 +330,7 @@ impl DbPool {
330330
vector_stores: Arc::new(sqlite::SqliteVectorStoresRepo::new(pool.clone())),
331331
files: Arc::new(sqlite::SqliteFilesRepo::new(pool.clone())),
332332
teams: Arc::new(sqlite::SqliteTeamRepo::new(pool.clone())),
333-
prompts: Arc::new(sqlite::SqlitePromptRepo::new(pool.clone())),
333+
templates: Arc::new(sqlite::SqliteTemplateRepo::new(pool.clone())),
334334
#[cfg(feature = "sso")]
335335
sso_group_mappings: Arc::new(sqlite::SqliteSsoGroupMappingRepo::new(
336336
pool.clone(),
@@ -430,7 +430,7 @@ impl DbPool {
430430
write_pool.clone(),
431431
read_pool.clone(),
432432
)),
433-
prompts: Arc::new(postgres::PostgresPromptRepo::new(
433+
templates: Arc::new(postgres::PostgresTemplateRepo::new(
434434
write_pool.clone(),
435435
read_pool.clone(),
436436
)),
@@ -581,9 +581,9 @@ impl DbPool {
581581
Arc::clone(&self.repos.teams)
582582
}
583583

584-
/// Get prompt repository
585-
pub fn prompts(&self) -> Arc<dyn PromptRepo> {
586-
Arc::clone(&self.repos.prompts)
584+
/// Get template repository
585+
pub fn templates(&self) -> Arc<dyn TemplateRepo> {
586+
Arc::clone(&self.repos.templates)
587587
}
588588

589589
/// Get SSO group mapping repository

src/db/postgres/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod org_rbac_policies;
1010
mod org_sso_configs;
1111
mod organizations;
1212
mod projects;
13-
mod prompts;
1413
mod providers;
1514
#[cfg(feature = "sso")]
1615
mod scim_configs;
@@ -22,6 +21,7 @@ mod service_accounts;
2221
#[cfg(feature = "sso")]
2322
mod sso_group_mappings;
2423
mod teams;
24+
mod templates;
2525
mod usage;
2626
mod users;
2727
mod vector_stores;
@@ -38,7 +38,6 @@ pub use org_rbac_policies::PostgresOrgRbacPolicyRepo;
3838
pub use org_sso_configs::PostgresOrgSsoConfigRepo;
3939
pub use organizations::PostgresOrganizationRepo;
4040
pub use projects::PostgresProjectRepo;
41-
pub use prompts::PostgresPromptRepo;
4241
pub use providers::PostgresDynamicProviderRepo;
4342
#[cfg(feature = "sso")]
4443
pub use scim_configs::PostgresOrgScimConfigRepo;
@@ -50,6 +49,7 @@ pub use service_accounts::PostgresServiceAccountRepo;
5049
#[cfg(feature = "sso")]
5150
pub use sso_group_mappings::PostgresSsoGroupMappingRepo;
5251
pub use teams::PostgresTeamRepo;
52+
pub use templates::PostgresTemplateRepo;
5353
pub use usage::PostgresUsageRepo;
5454
pub use users::PostgresUserRepo;
5555
pub use vector_stores::PostgresVectorStoresRepo;

0 commit comments

Comments
 (0)