0047_platform_agents.sql 1.4 KB

123456789101112131415161718192021222324252627
  1. -- 0047_platform_agents — platform-level AI-agent registry for the admin cockpit.
  2. --
  3. -- Backs services/platform-agents.ts. One row per admin-registered agent
  4. -- (name + provider + optional endpoint + model + scope + enabled). The
  5. -- provider api key is stored as AES-256-GCM ciphertext produced by
  6. -- services/tenant-secret-store.ts (HKDF-SHA256 key salted with the agent id);
  7. -- plaintext never lands in this table. key_prefix / key_suffix are the only
  8. -- displayable fragments, mirroring the mcp_keys masking pattern.
  9. CREATE TABLE IF NOT EXISTS "platform_agents" (
  10. "id" text PRIMARY KEY NOT NULL,
  11. "name" text NOT NULL,
  12. "provider" text NOT NULL,
  13. "endpoint" text,
  14. "model" text NOT NULL,
  15. "scope" text DEFAULT 'read' NOT NULL,
  16. "enabled" boolean DEFAULT true NOT NULL,
  17. "encrypted_api_key" text,
  18. "key_prefix" text,
  19. "key_suffix" varchar(4),
  20. "created_by" text,
  21. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  22. "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  23. CONSTRAINT "platform_agents_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action
  24. );
  25. --> statement-breakpoint
  26. CREATE UNIQUE INDEX IF NOT EXISTS "platform_agents_name_idx" ON "platform_agents" USING btree ("name");--> statement-breakpoint
  27. CREATE INDEX IF NOT EXISTS "platform_agents_enabled_idx" ON "platform_agents" USING btree ("enabled");