🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(channel): add channel_agent_grants table for owner-approved Agent use in groups (#23746)
Arvin Xu7935f744af8f
diff --git a/docs/development/database-schema.dbml b/docs/development/database-schema.dbmlindex a52960504a5..034595472e0 100644--- a/docs/development/database-schema.dbml+++ b/docs/development/database-schema.dbml@@ -1630,6 +1630,33 @@ table verifications {}}+table channel_agent_grants {+ id uuid [pk, not null, default: `gen_random_uuid()`]+ channel_id text [not null]+ member_id uuid [not null]+ owner_id text [not null]+ grantee_member_id uuid+ thread_id text+ requested_by_member_id uuid+ status text [not null, default: 'pending']+ decided_at "timestamp with time zone"+ revoked_at "timestamp with time zone"+ revoke_reason text+ metadata jsonb [default: `{}`]+ created_at "timestamp with time zone" [not null, default: `now()`]+ updated_at "timestamp with time zone" [not null, default: `now()`]++ indexes {+ (member_id, grantee_member_id, thread_id) [name: 'channel_agent_grants_live_scope_unique', unique]+ (owner_id, status) [name: 'channel_agent_grants_owner_status_idx']+ grantee_member_id [name: 'channel_agent_grants_grantee_idx']+++++ }+}+table channel_audit {id uuid [pk, not null, default: `gen_random_uuid()`]channel_id text [not null]diff --git a/packages/database/migrations/0227_channel_agent_grants.sql b/packages/database/migrations/0227_channel_agent_grants.sqlnew file mode 100644index 00000000000..0543eda9b32--- /dev/null+++ b/packages/database/migrations/0227_channel_agent_grants.sql@@ -0,0 +1,32 @@+CREATE TABLE IF NOT EXISTS "channel_agent_grants" (+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,+ "channel_id" text NOT NULL,+ "member_id" uuid NOT NULL,+ "owner_id" text NOT NULL,+ "grantee_member_id" uuid,+ "thread_id" text,+ "requested_by_member_id" uuid,+ "status" text DEFAULT 'pending' NOT NULL,+ "decided_at" timestamp with time zone,+ "revoked_at" timestamp with time zone,+ "revoke_reason" text,+ "metadata" jsonb DEFAULT '{}'::jsonb,+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL+);+--> statement-breakpoint+ALTER TABLE "channel_agent_grants" DROP CONSTRAINT IF EXISTS "channel_agent_grants_channel_id_channels_id_fk";--> statement-breakpoint+ALTER TABLE "channel_agent_grants" ADD CONSTRAINT "channel_agent_grants_channel_id_channels_id_fk" FOREIGN KEY ("channel_id") REFERENCES "public"."channels"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "channel_agent_grants" DROP CONSTRAINT IF EXISTS "channel_agent_grants_owner_id_users_id_fk";--> statement-breakpoint+ALTER TABLE "channel_agent_grants" ADD CONSTRAINT "channel_agent_grants_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "channel_agent_grants" DROP CONSTRAINT IF EXISTS "channel_agent_grants_member_fk";--> statement-breakpoint+ALTER TABLE "channel_agent_grants" ADD CONSTRAINT "channel_agent_grants_member_fk" FOREIGN KEY ("channel_id","member_id") REFERENCES "public"."channel_members"("channel_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "channel_agent_grants" DROP CONSTRAINT IF EXISTS "channel_agent_grants_grantee_fk";--> statement-breakpoint+ALTER TABLE "channel_agent_grants" ADD CONSTRAINT "channel_agent_grants_grantee_fk" FOREIGN KEY ("channel_id","grantee_member_id") REFERENCES "public"."channel_members"("channel_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "channel_agent_grants" DROP CONSTRAINT IF EXISTS "channel_agent_grants_requester_fk";--> statement-breakpoint+ALTER TABLE "channel_agent_grants" ADD CONSTRAINT "channel_agent_grants_requester_fk" FOREIGN KEY ("channel_id","requested_by_member_id") REFERENCES "public"."channel_members"("channel_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint+ALTER TABLE "channel_agent_grants" DROP CONSTRAINT IF EXISTS "channel_agent_grants_thread_fk";--> statement-breakpoint+ALTER TABLE "channel_agent_grants" ADD CONSTRAINT "channel_agent_grants_thread_fk" FOREIGN KEY ("channel_id","thread_id") REFERENCES "public"."channel_threads"("channel_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint+CREATE UNIQUE INDEX IF NOT EXISTS "channel_agent_grants_live_scope_unique" ON "channel_agent_grants" USING btree ("member_id",coalesce("grantee_member_id"::text, ''),coalesce("thread_id", '')) WHERE "channel_agent_grants"."status" IN ('pending', 'approved');--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "channel_agent_grants_owner_status_idx" ON "channel_agent_grants" USING btree ("owner_id","status");--> statement-breakpoint+CREATE INDEX IF NOT EXISTS "channel_agent_grants_grantee_idx" ON "channel_agent_grants" USING btree ("grantee_member_id");\ No newline at end of filediff --git a/packages/database/migrations/meta/0217_snapshot.json b/packages/database/migrations/meta/0227_snapshot.jsonsimilarity index 97%rename from packages/database/migrations/meta/0217_snapshot.jsonrename to packages/database/migrations/meta/0227_snapshot.jsonindex 50a404bd5c7..77f81f79781 100644--- a/packages/database/migrations/meta/0217_snapshot.json+++ b/packages/database/migrations/meta/0227_snapshot.json@@ -6,9 +6,9 @@},"dialect": "postgresql","enums": {},- "id": "44fde6f5-404e-4745-a43d-3fa16db429c8",+ "id": "315a7566-001a-43ff-a05a-5187c926f646","policies": {},- "prevId": "7c29d9b7-1cda-4670-a1a0-27ecc5cf0017",+ "prevId": "8ec85155-fd27-45c2-b98d-3c7910174744","roles": {},"schemas": {},"sequences": {@@ -2752,6 +2752,596 @@"checkConstraints": {},"isRLSEnabled": false},+ "public.agent_deliveries": {+ "name": "agent_deliveries",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "subject_type": {+ "name": "subject_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "subject_id": {+ "name": "subject_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "parent_delivery_id": {+ "name": "parent_delivery_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "requester_user_id": {+ "name": "requester_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "project_id": {+ "name": "project_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "task_id": {+ "name": "task_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "category": {+ "name": "category",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "outcome": {+ "name": "outcome",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'unknown'"+ },+ "outcome_source": {+ "name": "outcome_source",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "outcome_confidence": {+ "name": "outcome_confidence",+ "type": "real",+ "primaryKey": false,+ "notNull": false+ },+ "shots": {+ "name": "shots",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "frictions": {+ "name": "frictions",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "total_cost": {+ "name": "total_cost",+ "type": "numeric(20, 6)",+ "primaryKey": false,+ "notNull": false+ },+ "total_tokens": {+ "name": "total_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "tool_calls": {+ "name": "tool_calls",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "user_messages": {+ "name": "user_messages",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "agent_messages": {+ "name": "agent_messages",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "delivered_at": {+ "name": "delivered_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "settled_at": {+ "name": "settled_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "distilled_at": {+ "name": "distilled_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_deliveries_subject_agent_unique": {+ "name": "agent_deliveries_subject_agent_unique",+ "columns": [+ {+ "expression": "subject_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "subject_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_deliveries_agent_id_settled_at_idx": {+ "name": "agent_deliveries_agent_id_settled_at_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "settled_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_deliveries_user_id_settled_at_idx": {+ "name": "agent_deliveries_user_id_settled_at_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "settled_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_deliveries_workspace_id_settled_at_idx": {+ "name": "agent_deliveries_workspace_id_settled_at_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "settled_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_deliveries\".\"workspace_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_deliveries_parent_delivery_id_idx": {+ "name": "agent_deliveries_parent_delivery_id_idx",+ "columns": [+ {+ "expression": "parent_delivery_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_deliveries\".\"parent_delivery_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_deliveries_project_id_idx": {+ "name": "agent_deliveries_project_id_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_deliveries\".\"project_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_deliveries_task_id_idx": {+ "name": "agent_deliveries_task_id_idx",+ "columns": [+ {+ "expression": "task_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_deliveries\".\"task_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_deliveries_agent_id_agents_id_fk": {+ "name": "agent_deliveries_agent_id_agents_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "agents",+ "columnsFrom": ["agent_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_deliveries_user_id_users_id_fk": {+ "name": "agent_deliveries_user_id_users_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_deliveries_workspace_id_workspaces_id_fk": {+ "name": "agent_deliveries_workspace_id_workspaces_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_deliveries_parent_delivery_id_agent_deliveries_id_fk": {+ "name": "agent_deliveries_parent_delivery_id_agent_deliveries_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "agent_deliveries",+ "columnsFrom": ["parent_delivery_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "agent_deliveries_requester_user_id_users_id_fk": {+ "name": "agent_deliveries_requester_user_id_users_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "users",+ "columnsFrom": ["requester_user_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "agent_deliveries_project_id_projects_id_fk": {+ "name": "agent_deliveries_project_id_projects_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "projects",+ "columnsFrom": ["project_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "agent_deliveries_channel_id_channels_id_fk": {+ "name": "agent_deliveries_channel_id_channels_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "channels",+ "columnsFrom": ["channel_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "agent_deliveries_task_id_tasks_id_fk": {+ "name": "agent_deliveries_task_id_tasks_id_fk",+ "tableFrom": "agent_deliveries",+ "tableTo": "tasks",+ "columnsFrom": ["task_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_delivery_works": {+ "name": "agent_delivery_works",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "delivery_id": {+ "name": "delivery_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "work_id": {+ "name": "work_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "work_version_id": {+ "name": "work_version_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "accessed_at": {+ "name": "accessed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_delivery_works_delivery_id_work_id_unique": {+ "name": "agent_delivery_works_delivery_id_work_id_unique",+ "columns": [+ {+ "expression": "delivery_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "work_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_delivery_works_work_id_idx": {+ "name": "agent_delivery_works_work_id_idx",+ "columns": [+ {+ "expression": "work_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_delivery_works_workspace_id_idx": {+ "name": "agent_delivery_works_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_delivery_works\".\"workspace_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_delivery_works_delivery_id_agent_deliveries_id_fk": {+ "name": "agent_delivery_works_delivery_id_agent_deliveries_id_fk",+ "tableFrom": "agent_delivery_works",+ "tableTo": "agent_deliveries",+ "columnsFrom": ["delivery_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_delivery_works_work_id_works_id_fk": {+ "name": "agent_delivery_works_work_id_works_id_fk",+ "tableFrom": "agent_delivery_works",+ "tableTo": "works",+ "columnsFrom": ["work_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_delivery_works_workspace_id_workspaces_id_fk": {+ "name": "agent_delivery_works_workspace_id_workspaces_id_fk",+ "tableFrom": "agent_delivery_works",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_delivery_works_work_version_id_work_versions_id_fk": {+ "name": "agent_delivery_works_work_version_id_work_versions_id_fk",+ "tableFrom": "agent_delivery_works",+ "tableTo": "work_versions",+ "columnsFrom": ["work_version_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },"public.agent_documents": {"name": "agent_documents","schema": "",@@ -7836,6 +8426,22 @@"method": "btree","with": {}},+ "agent_operations_running_created_at_idx": {+ "name": "agent_operations_running_created_at_idx",+ "columns": [+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"agent_operations\".\"status\" = 'running'",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"agent_operations_user_id_created_at_idx": {"name": "agent_operations_user_id_created_at_idx","columns": [@@ -9773,11 +10379,175 @@"name": "created_at","type": "timestamp with time zone","primaryKey": false,- "notNull": true,- "default": "now()"+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_quota_windows_natural_key_unique": {+ "name": "agent_quota_windows_natural_key_unique",+ "columns": [+ {+ "expression": "account_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "limit_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "resets_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_quota_windows_account_resets_idx": {+ "name": "agent_quota_windows_account_resets_idx",+ "columns": [+ {+ "expression": "account_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "resets_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_quota_windows_user_id_idx": {+ "name": "agent_quota_windows_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_quota_windows_workspace_id_idx": {+ "name": "agent_quota_windows_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_quota_windows_account_id_agent_provider_accounts_id_fk": {+ "name": "agent_quota_windows_account_id_agent_provider_accounts_id_fk",+ "tableFrom": "agent_quota_windows",+ "tableTo": "agent_provider_accounts",+ "columnsFrom": ["account_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_quota_windows_user_id_users_id_fk": {+ "name": "agent_quota_windows_user_id_users_id_fk",+ "tableFrom": "agent_quota_windows",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_quota_windows_workspace_id_workspaces_id_fk": {+ "name": "agent_quota_windows_workspace_id_workspaces_id_fk",+ "tableFrom": "agent_quota_windows",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_share_grants": {+ "name": "agent_share_grants",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "share_id": {+ "name": "share_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source": {+ "name": "source",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false},- "updated_at": {- "name": "updated_at",+ "created_at": {+ "name": "created_at","type": "timestamp with time zone","primaryKey": false,"notNull": true,@@ -9785,29 +10555,17 @@}},"indexes": {- "agent_quota_windows_natural_key_unique": {- "name": "agent_quota_windows_natural_key_unique",+ "agent_share_grants_share_user_unique": {+ "name": "agent_share_grants_share_user_unique","columns": [{- "expression": "account_id",- "isExpression": false,- "asc": true,- "nulls": "last"- },- {- "expression": "limit_type",- "isExpression": false,- "asc": true,- "nulls": "last"- },- {- "expression": "scope_key",+ "expression": "share_id","isExpression": false,"asc": true,"nulls": "last"},{- "expression": "resets_at",+ "expression": "user_id","isExpression": false,"asc": true,"nulls": "last"@@ -9818,29 +10576,8 @@"method": "btree","with": {}},- "agent_quota_windows_account_resets_idx": {- "name": "agent_quota_windows_account_resets_idx",- "columns": [- {- "expression": "account_id",- "isExpression": false,- "asc": true,- "nulls": "last"- },- {- "expression": "resets_at",- "isExpression": false,- "asc": true,- "nulls": "last"- }- ],- "isUnique": false,- "concurrently": false,- "method": "btree",- "with": {}- },- "agent_quota_windows_user_id_idx": {- "name": "agent_quota_windows_user_id_idx",+ "agent_share_grants_user_id_idx": {+ "name": "agent_share_grants_user_id_idx","columns": [{"expression": "user_id",@@ -9853,50 +10590,26 @@"concurrently": false,"method": "btree","with": {}- },- "agent_quota_windows_workspace_id_idx": {- "name": "agent_quota_windows_workspace_id_idx",- "columns": [- {- "expression": "workspace_id",- "isExpression": false,- "asc": true,- "nulls": "last"- }- ],- "isUnique": false,- "concurrently": false,- "method": "btree",- "with": {}}},"foreignKeys": {- "agent_quota_windows_account_id_agent_provider_accounts_id_fk": {- "name": "agent_quota_windows_account_id_agent_provider_accounts_id_fk",- "tableFrom": "agent_quota_windows",- "tableTo": "agent_provider_accounts",- "columnsFrom": ["account_id"],+ "agent_share_grants_share_id_agent_shares_id_fk": {+ "name": "agent_share_grants_share_id_agent_shares_id_fk",+ "tableFrom": "agent_share_grants",+ "tableTo": "agent_shares",+ "columnsFrom": ["share_id"],"columnsTo": ["id"],"onDelete": "cascade","onUpdate": "no action"},- "agent_quota_windows_user_id_users_id_fk": {- "name": "agent_quota_windows_user_id_users_id_fk",- "tableFrom": "agent_quota_windows",+ "agent_share_grants_user_id_users_id_fk": {+ "name": "agent_share_grants_user_id_users_id_fk",+ "tableFrom": "agent_share_grants","tableTo": "users","columnsFrom": ["user_id"],"columnsTo": ["id"],"onDelete": "cascade","onUpdate": "no action"- },- "agent_quota_windows_workspace_id_workspaces_id_fk": {- "name": "agent_quota_windows_workspace_id_workspaces_id_fk",- "tableFrom": "agent_quota_windows",- "tableTo": "workspaces",- "columnsFrom": ["workspace_id"],- "columnsTo": ["id"],- "onDelete": "cascade",- "onUpdate": "no action"}},"compositePrimaryKeys": {},@@ -10047,6 +10760,12 @@"primaryKey": false,"notNull": true},+ "upstream": {+ "name": "upstream",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },"manifest": {"name": "manifest","type": "jsonb",@@ -11016,24 +11735,12 @@"primaryKey": false,"notNull": true},- "source_work_version_id": {- "name": "source_work_version_id",- "type": "uuid",- "primaryKey": false,- "notNull": false- },"source_path": {"name": "source_path","type": "text","primaryKey": false,"notNull": false},- "source_file_id": {- "name": "source_file_id",- "type": "text",- "primaryKey": false,- "notNull": false- },"metadata": {"name": "metadata","type": "jsonb",@@ -11157,22 +11864,6 @@"method": "btree","with": {}},- "artboard_boards_source_work_version_id_idx": {- "name": "artboard_boards_source_work_version_id_idx",- "columns": [- {- "expression": "source_work_version_id",- "isExpression": false,- "asc": true,- "nulls": "last"- }- ],- "isUnique": false,- "where": "\"artboard_boards\".\"source_work_version_id\" IS NOT NULL",- "concurrently": false,- "method": "btree",- "with": {}- },"artboard_boards_user_id_idx": {"name": "artboard_boards_user_id_idx","columns": [@@ -11268,37 +11959,15 @@"columnsTo": ["id"],"onDelete": "set null","onUpdate": "no action"- },- "artboard_boards_source_work_version_id_work_versions_id_fk": {- "name": "artboard_boards_source_work_version_id_work_versions_id_fk",- "tableFrom": "artboard_boards",- "tableTo": "work_versions",- "columnsFrom": ["source_work_version_id"],- "columnsTo": ["id"],- "onDelete": "set null",- "onUpdate": "no action"- },- "artboard_boards_source_file_id_files_id_fk": {- "name": "artboard_boards_source_file_id_files_id_fk",- "tableFrom": "artboard_boards",- "tableTo": "files",- "columnsFrom": ["source_file_id"],- "columnsTo": ["id"],- "onDelete": "set null",- "onUpdate": "no action"}},"compositePrimaryKeys": {},"uniqueConstraints": {},"policies": {},"checkConstraints": {- "artboard_boards_single_source_check": {- "name": "artboard_boards_single_source_check",- "value": "num_nonnulls(\"artboard_boards\".\"source_work_version_id\", \"artboard_boards\".\"source_file_id\") <= 1"- },"artboard_boards_decision_no_source_check": {"name": "artboard_boards_decision_no_source_check",- "value": "\"artboard_boards\".\"type\" <> 'decision' OR num_nonnulls(\"artboard_boards\".\"source_work_version_id\", \"artboard_boards\".\"source_file_id\", \"artboard_boards\".\"source_path\") = 0"+ "value": "\"artboard_boards\".\"type\" <> 'decision' OR \"artboard_boards\".\"source_path\" IS NULL"}},"isRLSEnabled": false@@ -13506,19 +14175,186 @@"notNull": true,"default": "now()"},- "value": {- "name": "value",- "type": "text",- "primaryKey": false,- "notNull": true- }- },- "indexes": {- "verification_identifier_idx": {- "name": "verification_identifier_idx",+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "verification_identifier_idx": {+ "name": "verification_identifier_idx",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.channel_agent_grants": {+ "name": "channel_agent_grants",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "member_id": {+ "name": "member_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "owner_id": {+ "name": "owner_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "grantee_member_id": {+ "name": "grantee_member_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "thread_id": {+ "name": "thread_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "requested_by_member_id": {+ "name": "requested_by_member_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "decided_at": {+ "name": "decided_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "revoke_reason": {+ "name": "revoke_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "channel_agent_grants_live_scope_unique": {+ "name": "channel_agent_grants_live_scope_unique",+ "columns": [+ {+ "expression": "member_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "coalesce(\"grantee_member_id\"::text, '')",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ },+ {+ "expression": "coalesce(\"thread_id\", '')",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"channel_agent_grants\".\"status\" IN ('pending', 'approved')",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "channel_agent_grants_owner_status_idx": {+ "name": "channel_agent_grants_owner_status_idx","columns": [{- "expression": "identifier",+ "expression": "owner_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "channel_agent_grants_grantee_idx": {+ "name": "channel_agent_grants_grantee_idx",+ "columns": [+ {+ "expression": "grantee_member_id","isExpression": false,"asc": true,"nulls": "last"@@ -13530,7 +14366,62 @@"with": {}}},- "foreignKeys": {},+ "foreignKeys": {+ "channel_agent_grants_channel_id_channels_id_fk": {+ "name": "channel_agent_grants_channel_id_channels_id_fk",+ "tableFrom": "channel_agent_grants",+ "tableTo": "channels",+ "columnsFrom": ["channel_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_agent_grants_owner_id_users_id_fk": {+ "name": "channel_agent_grants_owner_id_users_id_fk",+ "tableFrom": "channel_agent_grants",+ "tableTo": "users",+ "columnsFrom": ["owner_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_agent_grants_member_fk": {+ "name": "channel_agent_grants_member_fk",+ "tableFrom": "channel_agent_grants",+ "tableTo": "channel_members",+ "columnsFrom": ["channel_id", "member_id"],+ "columnsTo": ["channel_id", "id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_agent_grants_grantee_fk": {+ "name": "channel_agent_grants_grantee_fk",+ "tableFrom": "channel_agent_grants",+ "tableTo": "channel_members",+ "columnsFrom": ["channel_id", "grantee_member_id"],+ "columnsTo": ["channel_id", "id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_agent_grants_requester_fk": {+ "name": "channel_agent_grants_requester_fk",+ "tableFrom": "channel_agent_grants",+ "tableTo": "channel_members",+ "columnsFrom": ["channel_id", "requested_by_member_id"],+ "columnsTo": ["channel_id", "id"],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "channel_agent_grants_thread_fk": {+ "name": "channel_agent_grants_thread_fk",+ "tableFrom": "channel_agent_grants",+ "tableTo": "channel_threads",+ "columnsFrom": ["channel_id", "thread_id"],+ "columnsTo": ["channel_id", "id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },"compositePrimaryKeys": {},"uniqueConstraints": {},"policies": {},@@ -13967,24 +14858,8 @@"method": "btree","with": {}},- "channel_jobs_active_member_unique": {- "name": "channel_jobs_active_member_unique",- "columns": [- {- "expression": "member_id",- "isExpression": false,- "asc": true,- "nulls": "last"- }- ],- "isUnique": true,- "where": "\"channel_jobs\".\"writer_held\" AND \"channel_jobs\".\"isolated_at\" IS NULL",- "concurrently": false,- "method": "btree",- "with": {}- },- "channel_jobs_active_directory_unique": {- "name": "channel_jobs_active_directory_unique",+ "channel_jobs_active_directory_idx": {+ "name": "channel_jobs_active_directory_idx","columns": [{"expression": "device_id",@@ -13999,8 +14874,8 @@"nulls": "last"}],- "isUnique": true,- "where": "\"channel_jobs\".\"device_id\" IS NOT NULL AND \"channel_jobs\".\"working_directory\" IS NOT NULL AND \"channel_jobs\".\"writer_held\"",+ "isUnique": false,+ "where": "\"channel_jobs\".\"writer_held\"","concurrently": false,"method": "btree","with": {}@@ -14305,6 +15180,32 @@"primaryKey": false,"notNull": false},+ "section_id": {+ "name": "section_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "pinned": {+ "name": "pinned",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "hidden": {+ "name": "hidden",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "pinned_at": {+ "name": "pinned_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },"agent_id": {"name": "agent_id","type": "text",@@ -14397,6 +15298,22 @@"method": "btree","with": {}},+ "channel_members_section_id_idx": {+ "name": "channel_members_section_id_idx",+ "columns": [+ {+ "expression": "section_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"channel_members\".\"section_id\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"channel_members_agent_id_idx": {"name": "channel_members_agent_id_idx","columns": [@@ -14432,6 +15349,15 @@"onDelete": "set null","onUpdate": "no action"},+ "channel_members_section_id_channel_sections_id_fk": {+ "name": "channel_members_section_id_channel_sections_id_fk",+ "tableFrom": "channel_members",+ "tableTo": "channel_sections",+ "columnsFrom": ["section_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },"channel_members_agent_id_agents_id_fk": {"name": "channel_members_agent_id_agents_id_fk","tableFrom": "channel_members",@@ -14476,6 +15402,10 @@"name": "channel_members_agent_id_owner_check","value": "\"channel_members\".\"agent_id\" IS NULL OR \"channel_members\".\"actor_type\" = 'agent'"},+ "channel_members_section_id_owner_check": {+ "name": "channel_members_section_id_owner_check",+ "value": "\"channel_members\".\"section_id\" IS NULL OR \"channel_members\".\"actor_type\" = 'user'"+ },"channel_members_config_owner_check": {"name": "channel_members_config_owner_check","value": "\"channel_members\".\"config\" IS NULL OR \"channel_members\".\"actor_type\" <> 'user'"@@ -14783,80 +15713,182 @@"nulls": "last"},{- "expression": "id",+ "expression": "id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"channel_messages\".\"routing_status\" = 'pending'",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "channel_messages_channel_id_channels_id_fk": {+ "name": "channel_messages_channel_id_channels_id_fk",+ "tableFrom": "channel_messages",+ "tableTo": "channels",+ "columnsFrom": ["channel_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_messages_user_id_users_id_fk": {+ "name": "channel_messages_user_id_users_id_fk",+ "tableFrom": "channel_messages",+ "tableTo": "users",+ "columnsFrom": ["user_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "channel_messages_agent_id_agents_id_fk": {+ "name": "channel_messages_agent_id_agents_id_fk",+ "tableFrom": "channel_messages",+ "tableTo": "agents",+ "columnsFrom": ["agent_id"],+ "columnsTo": ["id"],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "channel_messages_thread_fk": {+ "name": "channel_messages_thread_fk",+ "tableFrom": "channel_messages",+ "tableTo": "channel_threads",+ "columnsFrom": ["channel_id", "thread_id"],+ "columnsTo": ["channel_id", "id"],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "channel_messages_scope_unique": {+ "name": "channel_messages_scope_unique",+ "nullsNotDistinct": false,+ "columns": ["channel_id", "id"]+ }+ },+ "policies": {},+ "checkConstraints": {+ "channel_messages_sender_check": {+ "name": "channel_messages_sender_check",+ "value": "\"channel_messages\".\"user_id\" IS NULL OR \"channel_messages\".\"agent_id\" IS NULL"+ },+ "channel_messages_user_sender_check": {+ "name": "channel_messages_user_sender_check",+ "value": "\"channel_messages\".\"routing_status\" <> 'reply' OR \"channel_messages\".\"user_id\" IS NULL"+ }+ },+ "isRLSEnabled": false+ },+ "public.channel_sections": {+ "name": "channel_sections",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "sort": {+ "name": "sort",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "collapsed": {+ "name": "collapsed",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "channel_sections_user_id_workspace_id_idx": {+ "name": "channel_sections_user_id_workspace_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "workspace_id","isExpression": false,"asc": true,"nulls": "last"}],"isUnique": false,- "where": "\"channel_messages\".\"routing_status\" = 'pending'","concurrently": false,"method": "btree","with": {}}},"foreignKeys": {- "channel_messages_channel_id_channels_id_fk": {- "name": "channel_messages_channel_id_channels_id_fk",- "tableFrom": "channel_messages",- "tableTo": "channels",- "columnsFrom": ["channel_id"],- "columnsTo": ["id"],- "onDelete": "cascade",- "onUpdate": "no action"- },- "channel_messages_user_id_users_id_fk": {- "name": "channel_messages_user_id_users_id_fk",- "tableFrom": "channel_messages",+ "channel_sections_user_id_users_id_fk": {+ "name": "channel_sections_user_id_users_id_fk",+ "tableFrom": "channel_sections","tableTo": "users","columnsFrom": ["user_id"],"columnsTo": ["id"],- "onDelete": "set null",+ "onDelete": "cascade","onUpdate": "no action"},- "channel_messages_agent_id_agents_id_fk": {- "name": "channel_messages_agent_id_agents_id_fk",- "tableFrom": "channel_messages",- "tableTo": "agents",- "columnsFrom": ["agent_id"],+ "channel_sections_workspace_id_workspaces_id_fk": {+ "name": "channel_sections_workspace_id_workspaces_id_fk",+ "tableFrom": "channel_sections",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],"columnsTo": ["id"],- "onDelete": "set null",- "onUpdate": "no action"- },- "channel_messages_thread_fk": {- "name": "channel_messages_thread_fk",- "tableFrom": "channel_messages",- "tableTo": "channel_threads",- "columnsFrom": ["channel_id", "thread_id"],- "columnsTo": ["channel_id", "id"],- "onDelete": "no action",+ "onDelete": "cascade","onUpdate": "no action"}},"compositePrimaryKeys": {},- "uniqueConstraints": {- "channel_messages_scope_unique": {- "name": "channel_messages_scope_unique",- "nullsNotDistinct": false,- "columns": ["channel_id", "id"]- }- },+ "uniqueConstraints": {},"policies": {},- "checkConstraints": {- "channel_messages_sender_check": {- "name": "channel_messages_sender_check",- "value": "\"channel_messages\".\"user_id\" IS NULL OR \"channel_messages\".\"agent_id\" IS NULL"- },- "channel_messages_user_sender_check": {- "name": "channel_messages_user_sender_check",- "value": "\"channel_messages\".\"routing_status\" <> 'reply' OR \"channel_messages\".\"user_id\" IS NULL"- },- "channel_messages_agent_sender_check": {- "name": "channel_messages_agent_sender_check",- "value": "\"channel_messages\".\"routing_status\" = 'reply' OR \"channel_messages\".\"agent_id\" IS NULL"- }- },+ "checkConstraints": {},"isRLSEnabled": false},"public.channel_threads": {@@ -15024,6 +16056,12 @@"primaryKey": false,"notNull": false},+ "agent_pair_key": {+ "name": "agent_pair_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },"title": {"name": "title","type": "text",@@ -15135,6 +16173,34 @@"method": "btree","with": {}},+ "channels_agent_pair_unique": {+ "name": "channels_agent_pair_unique",+ "columns": [+ {+ "expression": "agent_pair_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "coalesce(\"workspace_id\", '')",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"channels\".\"agent_pair_key\" IS NOT NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"channels_project_id_idx": {"name": "channels_project_id_idx","columns": [@@ -16315,12 +17381,24 @@"primaryKey": false,"notNull": true},+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },"message": {"name": "message","type": "text","primaryKey": false,"notNull": false},+ "source": {+ "name": "source",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },"status": {"name": "status","type": "text",@@ -16374,7 +17452,35 @@}],"isUnique": true,- "where": "\"user_contact_requests\".\"status\" = 'pending'",+ "where": "\"user_contact_requests\".\"status\" = 'pending' AND \"user_contact_requests\".\"workspace_id\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_contact_requests_workspace_pending_unique": {+ "name": "user_contact_requests_workspace_pending_unique",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "requester_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "addressee_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"user_contact_requests\".\"status\" = 'pending' AND \"user_contact_requests\".\"workspace_id\" IS NOT NULL","concurrently": false,"method": "btree","with": {}@@ -16420,6 +17526,21 @@"concurrently": false,"method": "btree","with": {}+ },+ "user_contact_requests_workspace_id_idx": {+ "name": "user_contact_requests_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}}},"foreignKeys": {@@ -16440,6 +17561,15 @@"columnsTo": ["id"],"onDelete": "cascade","onUpdate": "no action"+ },+ "user_contact_requests_workspace_id_workspaces_id_fk": {+ "name": "user_contact_requests_workspace_id_workspaces_id_fk",+ "tableFrom": "user_contact_requests",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"}},"compositePrimaryKeys": {},@@ -16707,6 +17837,12 @@"primaryKey": false,"notNull": true},+ "workspace_id": {+ "name": "workspace_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },"type": {"name": "type","type": "text",@@ -16789,7 +17925,35 @@}],"isUnique": true,- "where": "\"user_contacts\".\"contact_user_id\" IS NOT NULL",+ "where": "\"user_contacts\".\"contact_user_id\" IS NOT NULL AND \"user_contacts\".\"workspace_id\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_contacts_workspace_user_unique": {+ "name": "user_contacts_workspace_user_unique",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "contact_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"user_contacts\".\"contact_user_id\" IS NOT NULL AND \"user_contacts\".\"workspace_id\" IS NOT NULL","concurrently": false,"method": "btree","with": {}@@ -16811,7 +17975,29 @@}],"isUnique": true,- "where": "\"user_contacts\".\"agent_id\" IS NOT NULL",+ "where": "\"user_contacts\".\"agent_id\" IS NOT NULL AND \"user_contacts\".\"workspace_id\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "user_contacts_workspace_agent_unique": {+ "name": "user_contacts_workspace_agent_unique",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"user_contacts\".\"agent_id\" IS NOT NULL AND \"user_contacts\".\"workspace_id\" IS NOT NULL","concurrently": false,"method": "btree","with": {}@@ -16845,6 +18031,21 @@"concurrently": false,"method": "btree","with": {}+ },+ "user_contacts_workspace_id_idx": {+ "name": "user_contacts_workspace_id_idx",+ "columns": [+ {+ "expression": "workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}}},"foreignKeys": {@@ -16857,6 +18058,15 @@"onDelete": "cascade","onUpdate": "no action"},+ "user_contacts_workspace_id_workspaces_id_fk": {+ "name": "user_contacts_workspace_id_workspaces_id_fk",+ "tableFrom": "user_contacts",+ "tableTo": "workspaces",+ "columnsFrom": ["workspace_id"],+ "columnsTo": ["id"],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },"user_contacts_contact_user_id_users_id_fk": {"name": "user_contacts_contact_user_id_users_id_fk","tableFrom": "user_contacts",@@ -18507,6 +19717,12 @@"primaryKey": false,"notNull": false},+ "project_id": {+ "name": "project_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },"name": {"name": "name","type": "varchar(255)",@@ -18592,6 +19808,22 @@"method": "btree","with": {}},+ "environments_project_id_unique": {+ "name": "environments_project_id_unique",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"environments\".\"project_id\" is not null",+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"environments_workspace_visibility_idx": {"name": "environments_workspace_visibility_idx","columns": [@@ -18636,7 +19868,7 @@}],"isUnique": true,- "where": "\"environments\".\"workspace_id\" is null",+ "where": "\"environments\".\"workspace_id\" IS NULL AND \"environments\".\"project_id\" IS NULL","concurrently": false,"method": "btree","with": {}@@ -18664,7 +19896,7 @@}],"isUnique": true,- "where": "\"environments\".\"workspace_id\" is not null",+ "where": "\"environments\".\"workspace_id\" IS NOT NULL AND \"environments\".\"project_id\" IS NULL","concurrently": false,"method": "btree","with": {}@@ -18688,6 +19920,15 @@"columnsTo": ["id"],"onDelete": "restrict","onUpdate": "no action"+ },+ "environments_project_id_projects_id_fk": {+ "name": "environments_project_id_projects_id_fk",+ "tableFrom": "environments",+ "tableTo": "projects",+ "columnsFrom": ["project_id"],+ "columnsTo": ["id"],+ "onDelete": "restrict",+ "onUpdate": "no action"}},"compositePrimaryKeys": {},@@ -28904,6 +30145,27 @@"method": "btree","with": {}},+ "messages_user_id_topic_id_idx": {+ "name": "messages_user_id_topic_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "topic_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },"messages_session_id_idx": {"name": "messages_session_id_idx","columns": [diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.jsonindex f89f76d22ac..f109d968bdf 100644--- a/packages/database/migrations/meta/_journal.json+++ b/packages/database/migrations/meta/_journal.json@@ -1589,6 +1589,13 @@"when": 1795232920077,"tag": "0226_agent_share_grants","breakpoints": true+ },+ {+ "idx": 227,+ "version": "7",+ "when": 1795445232107,+ "tag": "0227_channel_agent_grants",+ "breakpoints": true}],"version": "6"diff --git a/packages/database/src/schemas/__tests__/channel.test.ts b/packages/database/src/schemas/__tests__/channel.test.tsindex 263592db4b5..6140cd4a48c 100644--- a/packages/database/src/schemas/__tests__/channel.test.ts+++ b/packages/database/src/schemas/__tests__/channel.test.ts@@ -7,6 +7,7 @@ import { getTestDB } from '../../core/getTestDB';import {agentOperations,agents,+ channelAgentGrants,channelJobs,channelMemberGrants,channelMembers,@@ -436,6 +437,95 @@ describe('channel schema', () => {});});+ describe('agent grants', () => {+ const createGuest = async (channelId: string) => {+ const [guest] = await serverDB+ .insert(channelMembers)+ .values({ actorType: 'user', channelId, role: 'member', userId: otherId })+ .returning();+ return guest;+ };++ const createThread = async (channelId: string, authorMemberId: string, sequence: number) => {+ const root = await createMessage(channelId, authorMemberId, sequence);+ const [thread] = await serverDB+ .insert(channelThreads)+ .values({ channelId, rootMessageId: root.id, rootSequence: sequence })+ .returning();+ return thread;+ };++ it('keeps one live grant per scope and history for decided ones', async () => {+ const { agent, channel, owner } = await createChannel();+ const guest = await createGuest(channel.id);+ const thread = await createThread(channel.id, owner.id, 1);+ const base = { channelId: channel.id, memberId: agent.id, ownerId };++ const [whole] = await serverDB.insert(channelAgentGrants).values(base).returning();+ expect(whole.status).toBe('pending');+ expect(whole.metadata).toEqual({});+ await expect(serverDB.insert(channelAgentGrants).values(base)).rejects.toThrow();++ // Each narrower scope is its own grant.+ await expect(+ serverDB.insert(channelAgentGrants).values([+ { ...base, granteeMemberId: guest.id },+ { ...base, threadId: thread.id },+ { ...base, granteeMemberId: guest.id, threadId: thread.id },+ ]),+ ).resolves.toBeDefined();+ await expect(+ serverDB+ .insert(channelAgentGrants)+ .values({ ...base, granteeMemberId: guest.id, threadId: thread.id }),+ ).rejects.toThrow();++ // A revoked grant frees its scope for a fresh request.+ await serverDB+ .update(channelAgentGrants)+ .set({ revokeReason: 'revoked_by_owner', revokedAt: new Date(), status: 'revoked' })+ .where(eq(channelAgentGrants.id, whole.id));+ await expect(serverDB.insert(channelAgentGrants).values(base)).resolves.toBeDefined();+ });++ it('binds the member, grantee and Thread to the same channel', async () => {+ const { agent, channel } = await createChannel('First');+ const other = await createChannel('Second');+ const strangerThread = await createThread(other.channel.id, other.owner.id, 1);+ const base = { channelId: channel.id, memberId: agent.id, ownerId };++ await expect(+ serverDB.insert(channelAgentGrants).values({ ...base, memberId: other.agent.id }),+ ).rejects.toThrow();+ await expect(+ serverDB.insert(channelAgentGrants).values({ ...base, granteeMemberId: other.owner.id }),+ ).rejects.toThrow();+ await expect(+ serverDB.insert(channelAgentGrants).values({ ...base, threadId: strangerThread.id }),+ ).rejects.toThrow();+ });++ it('drops grants with the grantee or the Thread they cover', async () => {+ const { agent, channel, owner } = await createChannel();+ const guest = await createGuest(channel.id);+ const thread = await createThread(channel.id, owner.id, 1);+ const base = { channelId: channel.id, memberId: agent.id, ownerId };+ await serverDB.insert(channelAgentGrants).values([+ { ...base, granteeMemberId: guest.id },+ { ...base, threadId: thread.id },+ ]);++ await serverDB.delete(channelMembers).where(eq(channelMembers.id, guest.id));+ await serverDB.delete(channelThreads).where(eq(channelThreads.id, thread.id));++ const rest = await serverDB+ .select()+ .from(channelAgentGrants)+ .where(eq(channelAgentGrants.channelId, channel.id));+ expect(rest).toHaveLength(0);+ });+ });+describe('channels', () => {it('validates project associations and preserves history when the project is deleted', async () => {const { channel, owner } = await createChannel();diff --git a/packages/database/src/schemas/channel.ts b/packages/database/src/schemas/channel.tsindex b395c6527ac..0da93c9b3b3 100644--- a/packages/database/src/schemas/channel.ts+++ b/packages/database/src/schemas/channel.ts@@ -1,4 +1,7 @@import type {+ ChannelAgentGrantMetadata,+ ChannelAgentGrantRevokeReason,+ ChannelAgentGrantStatus,ChannelAuditDetails,ChannelConfig,ChannelExecutionConfig,@@ -297,6 +300,74 @@ export const channelMemberGrants = pgTable(],);+/**+ * An Agent owner's consent for others in the Channel to run their Agent member as the owner, at+ * the owner's cost. `granteeMemberId` and `threadId` narrow the scope; leaving both empty covers+ * the whole Channel, and a reply runs when any live grant matches its requester and Thread.+ * A changed scope is a new row, so a decision never carries over to a scope the owner did not see.+ */+export const channelAgentGrants = pgTable(+ 'channel_agent_grants',+ {+ id: uuid('id').defaultRandom().primaryKey().notNull(),+ channelId: text('channel_id')+ .references(() => channels.id, { onDelete: 'cascade' })+ .notNull(),+ /** The Agent member the grant lets others run. */+ memberId: uuid('member_id').notNull(),+ /** Agent owner who approves, rejects or revokes, and who pays for the runs. */+ ownerId: text('owner_id')+ .references(() => users.id, { onDelete: 'cascade' })+ .notNull(),+ /** Person the grant covers; empty covers everyone in the Channel. */+ granteeMemberId: uuid('grantee_member_id'),+ /** Thread the grant covers; empty covers the main timeline and every Thread. */+ threadId: text('thread_id'),+ /** Person who asked for it; empty when the owner granted it themselves. */+ requestedByMemberId: uuid('requested_by_member_id'),++ status: text('status').$type<ChannelAgentGrantStatus>().notNull().default('pending'),+ decidedAt: timestamptz('decided_at'),+ revokedAt: timestamptz('revoked_at'),+ revokeReason: text('revoke_reason').$type<ChannelAgentGrantRevokeReason>(),+ metadata: jsonb('metadata').$type<ChannelAgentGrantMetadata>().default({}),+ createdAt: createdAt(),+ updatedAt: updatedAt(),+ },+ (t) => [+ // One live grant per scope; decided-against and revoked rows stay as history.+ uniqueIndex('channel_agent_grants_live_scope_unique')+ .on(+ t.memberId,+ sql`coalesce(${t.granteeMemberId}::text, '')`,+ sql`coalesce(${t.threadId}, '')`,+ )+ .where(sql`${t.status} IN ('pending', 'approved')`),+ index('channel_agent_grants_owner_status_idx').on(t.ownerId, t.status),+ index('channel_agent_grants_grantee_idx').on(t.granteeMemberId),+ foreignKey({+ columns: [t.channelId, t.memberId],+ foreignColumns: [channelMembers.channelId, channelMembers.id],+ name: 'channel_agent_grants_member_fk',+ }).onDelete('cascade'),+ foreignKey({+ columns: [t.channelId, t.granteeMemberId],+ foreignColumns: [channelMembers.channelId, channelMembers.id],+ name: 'channel_agent_grants_grantee_fk',+ }).onDelete('cascade'),+ foreignKey({+ columns: [t.channelId, t.requestedByMemberId],+ foreignColumns: [channelMembers.channelId, channelMembers.id],+ name: 'channel_agent_grants_requester_fk',+ }),+ foreignKey({+ columns: [t.channelId, t.threadId],+ foreignColumns: [channelThreads.channelId, channelThreads.id],+ name: 'channel_agent_grants_thread_fk',+ }).onDelete('cascade'),+ ],+);+export const channelAudit = pgTable('channel_audit',{@@ -570,6 +641,8 @@ export type ChannelMemberItem = typeof channelMembers.$inferSelect;export type ChannelSectionItem = typeof channelSections.$inferSelect;export type NewChannelMember = typeof channelMembers.$inferInsert;export type ChannelMemberGrantItem = typeof channelMemberGrants.$inferSelect;+export type ChannelAgentGrantItem = typeof channelAgentGrants.$inferSelect;+export type NewChannelAgentGrant = typeof channelAgentGrants.$inferInsert;export type ChannelThreadItem = typeof channelThreads.$inferSelect;export type ChannelMessageItem = typeof channelMessages.$inferSelect;export type NewChannelMessage = typeof channelMessages.$inferInsert;diff --git a/packages/types/src/channel.ts b/packages/types/src/channel.tsindex db033a1178e..03ac8b42232 100644--- a/packages/types/src/channel.ts+++ b/packages/types/src/channel.ts@@ -449,6 +449,17 @@ export type ChannelMemberGrantStatus = 'approved' | 'pending' | 'rejected' | 'reexport type ChannelMemberGrantRevokeReason = 'device_owner_left' | 'revoked_by_owner';+/**+ * An Agent owner's consent for other people in a Channel to run their Agent, billed to the owner.+ * Its scope narrows from the whole Channel to one person, one Thread, or one person in one Thread.+ */+export type ChannelAgentGrantStatus = 'approved' | 'pending' | 'rejected' | 'revoked';++export type ChannelAgentGrantRevokeReason =+ 'agent_removed' | 'grantee_left' | 'owner_left' | 'revoked_by_owner';++export type ChannelAgentGrantMetadata = Record<string, unknown>;+export interface ChannelContextMessage {/** `id` is the actual user/Agent id, or NULL after author deletion. */author: { id: string | null; name: string; type: ChannelMemberActorType };