mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 23:25:24 +00:00
feat: finish the ai plugin (B18)
This commit is contained in:
1 parent
6b4d1432ab
commit
21937a6b02
193 files changed
+23429
-4244
No files matched your search
@@ -0,0 +1,55 @@
|
||||
-- ai 0001: adopt_ai_tables
|
||||
-- Generated by termix-plugin migrations. Review before committing.
|
||||
-- Hand-edited: keeps the legacy foreign key from messages and proposals to
|
||||
-- their conversation, which the SDK cannot declare.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ai_providers` (
|
||||
`id` int AUTO_INCREMENT PRIMARY KEY,
|
||||
`user_id` varchar(255) NOT NULL,
|
||||
`provider_type` text NOT NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
`base_url` text,
|
||||
`api_key_prefix` text,
|
||||
`default_model` text,
|
||||
`enabled` boolean NOT NULL DEFAULT true,
|
||||
`created_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
`updated_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
);
|
||||
RENAME TABLE `ai_providers` TO `p_ai_providers`;
|
||||
CREATE TABLE IF NOT EXISTS `ai_conversations` (
|
||||
`id` int AUTO_INCREMENT PRIMARY KEY,
|
||||
`user_id` varchar(255) NOT NULL,
|
||||
`title` text,
|
||||
`provider_id` int,
|
||||
`model` text,
|
||||
`created_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
`updated_at` varchar(255) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
);
|
||||
RENAME TABLE `ai_conversations` TO `p_ai_conversations`;
|
||||
CREATE TABLE IF NOT EXISTS `ai_messages` (
|
||||
`id` int AUTO_INCREMENT PRIMARY KEY,
|
||||
`conversation_id` int NOT NULL,
|
||||
`role` text NOT NULL,
|
||||
`content` text NOT NULL DEFAULT (''),
|
||||
`tool_calls` text,
|
||||
`created_at` varchar(255) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
FOREIGN KEY (`conversation_id`) REFERENCES `p_ai_conversations` (`id`) ON DELETE CASCADE
|
||||
);
|
||||
RENAME TABLE `ai_messages` TO `p_ai_messages`;
|
||||
CREATE TABLE IF NOT EXISTS `ai_proposals` (
|
||||
`id` int AUTO_INCREMENT PRIMARY KEY,
|
||||
`conversation_id` int NOT NULL,
|
||||
`user_id` varchar(255) NOT NULL,
|
||||
`kind` varchar(255) NOT NULL,
|
||||
`summary` text,
|
||||
`payload` text NOT NULL DEFAULT ('{}'),
|
||||
`status` varchar(32) NOT NULL DEFAULT 'pending',
|
||||
`applied_at` text,
|
||||
`result_summary` text,
|
||||
`created_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`conversation_id`) REFERENCES `p_ai_conversations` (`id`) ON DELETE CASCADE
|
||||
);
|
||||
RENAME TABLE `ai_proposals` TO `p_ai_proposals`;
|
||||
@@ -0,0 +1,60 @@
|
||||
-- ai 0001: adopt_ai_tables
|
||||
-- Generated by termix-plugin migrations. Review before committing.
|
||||
-- Hand-edited: keeps the legacy foreign key from messages and proposals to
|
||||
-- their conversation, which the SDK cannot declare.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "ai_providers" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"user_id" varchar(255) NOT NULL,
|
||||
"provider_type" text NOT NULL,
|
||||
"label" varchar(255) NOT NULL,
|
||||
"base_url" text,
|
||||
"api_key_prefix" text,
|
||||
"default_model" text,
|
||||
"enabled" boolean NOT NULL DEFAULT true,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "idx_ai_providers_user_label" ON "ai_providers" ("user_id", "label");
|
||||
ALTER TABLE "ai_providers" RENAME TO "p_ai_providers";
|
||||
CREATE TABLE IF NOT EXISTS "ai_conversations" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"user_id" varchar(255) NOT NULL,
|
||||
"title" text,
|
||||
"provider_id" integer,
|
||||
"model" text,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" varchar(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_conversations_user" ON "ai_conversations" ("user_id", "updated_at");
|
||||
ALTER TABLE "ai_conversations" RENAME TO "p_ai_conversations";
|
||||
CREATE TABLE IF NOT EXISTS "ai_messages" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"conversation_id" integer NOT NULL,
|
||||
"role" text NOT NULL,
|
||||
"content" text NOT NULL DEFAULT '',
|
||||
"tool_calls" text,
|
||||
"created_at" varchar(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("conversation_id") REFERENCES "p_ai_conversations" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_messages_conversation" ON "ai_messages" ("conversation_id", "created_at");
|
||||
ALTER TABLE "ai_messages" RENAME TO "p_ai_messages";
|
||||
CREATE TABLE IF NOT EXISTS "ai_proposals" (
|
||||
"id" serial PRIMARY KEY,
|
||||
"conversation_id" integer NOT NULL,
|
||||
"user_id" varchar(255) NOT NULL,
|
||||
"kind" varchar(255) NOT NULL,
|
||||
"summary" text,
|
||||
"payload" text NOT NULL DEFAULT '{}',
|
||||
"status" varchar(32) NOT NULL DEFAULT 'pending',
|
||||
"applied_at" text,
|
||||
"result_summary" text,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE,
|
||||
FOREIGN KEY ("conversation_id") REFERENCES "p_ai_conversations" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_proposals_user" ON "ai_proposals" ("user_id", "status");
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_proposals_conversation" ON "ai_proposals" ("conversation_id");
|
||||
ALTER TABLE "ai_proposals" RENAME TO "p_ai_proposals";
|
||||
@@ -0,0 +1,196 @@
|
||||
{
|
||||
"version": 1,
|
||||
"tables": {
|
||||
"providers": {
|
||||
"columns": {
|
||||
"id": {
|
||||
"type": "id",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"type": "refUser",
|
||||
"length": 255,
|
||||
"notNull": true
|
||||
},
|
||||
"providerType": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
},
|
||||
"label": {
|
||||
"type": "varchar",
|
||||
"length": 255,
|
||||
"notNull": true
|
||||
},
|
||||
"baseUrl": {
|
||||
"type": "text"
|
||||
},
|
||||
"apiKeyPrefix": {
|
||||
"type": "text"
|
||||
},
|
||||
"defaultModel": {
|
||||
"type": "text"
|
||||
},
|
||||
"enabled": {
|
||||
"type": "boolean",
|
||||
"notNull": true,
|
||||
"defaultValue": true
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "timestamp",
|
||||
"notNull": true,
|
||||
"defaultNow": true
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "timestamp",
|
||||
"notNull": true,
|
||||
"defaultNow": true
|
||||
}
|
||||
},
|
||||
"indexes": [
|
||||
{
|
||||
"name": "idx_ai_providers_user_label",
|
||||
"columns": ["userId", "label"],
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"adopts": "ai_providers"
|
||||
},
|
||||
"conversations": {
|
||||
"columns": {
|
||||
"id": {
|
||||
"type": "id",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"type": "refUser",
|
||||
"length": 255,
|
||||
"notNull": true
|
||||
},
|
||||
"title": {
|
||||
"type": "text"
|
||||
},
|
||||
"providerId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"model": {
|
||||
"type": "text"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "timestamp",
|
||||
"notNull": true,
|
||||
"defaultNow": true
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "timestamp",
|
||||
"notNull": true,
|
||||
"defaultNow": true
|
||||
}
|
||||
},
|
||||
"indexes": [
|
||||
{
|
||||
"name": "idx_ai_conversations_user",
|
||||
"columns": ["userId", "updatedAt"]
|
||||
}
|
||||
],
|
||||
"adopts": "ai_conversations"
|
||||
},
|
||||
"messages": {
|
||||
"columns": {
|
||||
"id": {
|
||||
"type": "id",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"conversationId": {
|
||||
"type": "integer",
|
||||
"notNull": true
|
||||
},
|
||||
"role": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
},
|
||||
"content": {
|
||||
"type": "text",
|
||||
"notNull": true,
|
||||
"defaultValue": ""
|
||||
},
|
||||
"toolCalls": {
|
||||
"type": "text"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "timestamp",
|
||||
"notNull": true,
|
||||
"defaultNow": true
|
||||
}
|
||||
},
|
||||
"indexes": [
|
||||
{
|
||||
"name": "idx_ai_messages_conversation",
|
||||
"columns": ["conversationId", "createdAt"]
|
||||
}
|
||||
],
|
||||
"adopts": "ai_messages"
|
||||
},
|
||||
"proposals": {
|
||||
"columns": {
|
||||
"id": {
|
||||
"type": "id",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"conversationId": {
|
||||
"type": "integer",
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"type": "refUser",
|
||||
"length": 255,
|
||||
"notNull": true
|
||||
},
|
||||
"kind": {
|
||||
"type": "varchar",
|
||||
"length": 255,
|
||||
"notNull": true
|
||||
},
|
||||
"summary": {
|
||||
"type": "text"
|
||||
},
|
||||
"payload": {
|
||||
"type": "text",
|
||||
"notNull": true,
|
||||
"defaultValue": "{}"
|
||||
},
|
||||
"status": {
|
||||
"type": "varchar",
|
||||
"length": 32,
|
||||
"notNull": true,
|
||||
"defaultValue": "pending"
|
||||
},
|
||||
"appliedAt": {
|
||||
"type": "text"
|
||||
},
|
||||
"resultSummary": {
|
||||
"type": "text"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "timestamp",
|
||||
"notNull": true,
|
||||
"defaultNow": true
|
||||
}
|
||||
},
|
||||
"indexes": [
|
||||
{
|
||||
"name": "idx_ai_proposals_user",
|
||||
"columns": ["userId", "status"]
|
||||
},
|
||||
{
|
||||
"name": "idx_ai_proposals_conversation",
|
||||
"columns": ["conversationId"]
|
||||
}
|
||||
],
|
||||
"adopts": "ai_proposals"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
-- ai 0001: adopt_ai_tables
|
||||
-- Generated by termix-plugin migrations. Review before committing.
|
||||
-- Hand-edited: keeps the legacy foreign key from messages and proposals to
|
||||
-- their conversation, which the SDK cannot declare.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "ai_providers" (
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT,
|
||||
"user_id" text NOT NULL,
|
||||
"provider_type" text NOT NULL,
|
||||
"label" text NOT NULL,
|
||||
"base_url" text,
|
||||
"api_key_prefix" text,
|
||||
"default_model" text,
|
||||
"enabled" integer NOT NULL DEFAULT 1,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "idx_ai_providers_user_label" ON "ai_providers" ("user_id", "label");
|
||||
ALTER TABLE "ai_providers" RENAME TO "p_ai_providers";
|
||||
CREATE TABLE IF NOT EXISTS "ai_conversations" (
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT,
|
||||
"user_id" text NOT NULL,
|
||||
"title" text,
|
||||
"provider_id" integer,
|
||||
"model" text,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_conversations_user" ON "ai_conversations" ("user_id", "updated_at");
|
||||
ALTER TABLE "ai_conversations" RENAME TO "p_ai_conversations";
|
||||
CREATE TABLE IF NOT EXISTS "ai_messages" (
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT,
|
||||
"conversation_id" integer NOT NULL,
|
||||
"role" text NOT NULL,
|
||||
"content" text NOT NULL DEFAULT '',
|
||||
"tool_calls" text,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("conversation_id") REFERENCES "p_ai_conversations" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_messages_conversation" ON "ai_messages" ("conversation_id", "created_at");
|
||||
ALTER TABLE "ai_messages" RENAME TO "p_ai_messages";
|
||||
CREATE TABLE IF NOT EXISTS "ai_proposals" (
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT,
|
||||
"conversation_id" integer NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"kind" text NOT NULL,
|
||||
"summary" text,
|
||||
"payload" text NOT NULL DEFAULT '{}',
|
||||
"status" text NOT NULL DEFAULT 'pending',
|
||||
"applied_at" text,
|
||||
"result_summary" text,
|
||||
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE,
|
||||
FOREIGN KEY ("conversation_id") REFERENCES "p_ai_conversations" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_proposals_user" ON "ai_proposals" ("user_id", "status");
|
||||
CREATE INDEX IF NOT EXISTS "idx_ai_proposals_conversation" ON "ai_proposals" ("conversation_id");
|
||||
ALTER TABLE "ai_proposals" RENAME TO "p_ai_proposals";
|
||||
Reference in new issue
Block a user