@agent-team-foundation/first-tree-hub 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.mjs +636 -0
- package/dist/core-CD3xEbyB.mjs +27914 -0
- package/dist/drizzle/0000_shocking_darkhawk.sql +92 -0
- package/dist/drizzle/0001_v2_schema_updates.sql +26 -0
- package/dist/drizzle/0002_adapter_tables.sql +64 -0
- package/dist/drizzle/0003_feishu_adapter.sql +21 -0
- package/dist/drizzle/0004_adapter_refactor.sql +13 -0
- package/dist/drizzle/0005_delegate_mention.sql +1 -0
- package/dist/drizzle/meta/0000_snapshot.json +687 -0
- package/dist/drizzle/meta/0001_snapshot.json +687 -0
- package/dist/drizzle/meta/_journal.json +48 -0
- package/dist/index.mjs +2 -0
- package/dist/web/assets/index-CHZINY3I.js +229 -0
- package/dist/web/assets/index-Drt799Rs.css +1 -0
- package/dist/web/favicon.svg +21 -0
- package/dist/web/index.html +14 -0
- package/package.json +64 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
CREATE TABLE "admin_users" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"username" text NOT NULL,
|
|
4
|
+
"password_hash" text NOT NULL,
|
|
5
|
+
"role" text DEFAULT 'admin' NOT NULL,
|
|
6
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
7
|
+
"last_login_at" timestamp with time zone,
|
|
8
|
+
CONSTRAINT "admin_users_username_unique" UNIQUE("username")
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
CREATE TABLE "agent_tokens" (
|
|
12
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
13
|
+
"agent_id" text NOT NULL,
|
|
14
|
+
"token_hash" text NOT NULL,
|
|
15
|
+
"name" text,
|
|
16
|
+
"expires_at" timestamp with time zone,
|
|
17
|
+
"revoked_at" timestamp with time zone,
|
|
18
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
19
|
+
"last_used_at" timestamp with time zone
|
|
20
|
+
);
|
|
21
|
+
--> statement-breakpoint
|
|
22
|
+
CREATE TABLE "agents" (
|
|
23
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
24
|
+
"organization_id" text DEFAULT 'default' NOT NULL,
|
|
25
|
+
"type" text NOT NULL,
|
|
26
|
+
"display_name" text,
|
|
27
|
+
"inbox_id" text NOT NULL,
|
|
28
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
29
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
30
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
31
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
32
|
+
CONSTRAINT "agents_inbox_id_unique" UNIQUE("inbox_id")
|
|
33
|
+
);
|
|
34
|
+
--> statement-breakpoint
|
|
35
|
+
CREATE TABLE "chat_participants" (
|
|
36
|
+
"chat_id" text NOT NULL,
|
|
37
|
+
"agent_id" text NOT NULL,
|
|
38
|
+
"role" text DEFAULT 'member' NOT NULL,
|
|
39
|
+
"mode" text DEFAULT 'full' NOT NULL,
|
|
40
|
+
"joined_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
41
|
+
CONSTRAINT "chat_participants_chat_id_agent_id_pk" PRIMARY KEY("chat_id","agent_id")
|
|
42
|
+
);
|
|
43
|
+
--> statement-breakpoint
|
|
44
|
+
CREATE TABLE "chats" (
|
|
45
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
46
|
+
"organization_id" text DEFAULT 'default' NOT NULL,
|
|
47
|
+
"type" text DEFAULT 'direct' NOT NULL,
|
|
48
|
+
"topic" text,
|
|
49
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
50
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
51
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
52
|
+
);
|
|
53
|
+
--> statement-breakpoint
|
|
54
|
+
CREATE TABLE "inbox_entries" (
|
|
55
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
56
|
+
"inbox_id" text NOT NULL,
|
|
57
|
+
"message_id" text NOT NULL,
|
|
58
|
+
"chat_id" text,
|
|
59
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
60
|
+
"retry_count" integer DEFAULT 0 NOT NULL,
|
|
61
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
62
|
+
"delivered_at" timestamp with time zone,
|
|
63
|
+
"acked_at" timestamp with time zone,
|
|
64
|
+
CONSTRAINT "uq_inbox_delivery" UNIQUE("inbox_id","message_id","chat_id")
|
|
65
|
+
);
|
|
66
|
+
--> statement-breakpoint
|
|
67
|
+
CREATE TABLE "messages" (
|
|
68
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
69
|
+
"chat_id" text NOT NULL,
|
|
70
|
+
"sender_id" text NOT NULL,
|
|
71
|
+
"format" text NOT NULL,
|
|
72
|
+
"content" jsonb NOT NULL,
|
|
73
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
74
|
+
"reply_to_inbox" text,
|
|
75
|
+
"reply_to_chat" text,
|
|
76
|
+
"in_reply_to" text,
|
|
77
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
78
|
+
);
|
|
79
|
+
--> statement-breakpoint
|
|
80
|
+
ALTER TABLE "agent_tokens" ADD CONSTRAINT "agent_tokens_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
81
|
+
ALTER TABLE "chat_participants" ADD CONSTRAINT "chat_participants_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
82
|
+
ALTER TABLE "chat_participants" ADD CONSTRAINT "chat_participants_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
83
|
+
ALTER TABLE "inbox_entries" ADD CONSTRAINT "inbox_entries_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
84
|
+
ALTER TABLE "messages" ADD CONSTRAINT "messages_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
85
|
+
ALTER TABLE "messages" ADD CONSTRAINT "messages_sender_id_agents_id_fk" FOREIGN KEY ("sender_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
86
|
+
CREATE INDEX "idx_agent_tokens_agent" ON "agent_tokens" USING btree ("agent_id");--> statement-breakpoint
|
|
87
|
+
CREATE INDEX "idx_agent_tokens_hash" ON "agent_tokens" USING btree ("token_hash");--> statement-breakpoint
|
|
88
|
+
CREATE INDEX "idx_agents_org" ON "agents" USING btree ("organization_id");--> statement-breakpoint
|
|
89
|
+
CREATE INDEX "idx_participants_agent" ON "chat_participants" USING btree ("agent_id");--> statement-breakpoint
|
|
90
|
+
CREATE INDEX "idx_inbox_pending" ON "inbox_entries" USING btree ("inbox_id","created_at");--> statement-breakpoint
|
|
91
|
+
CREATE INDEX "idx_messages_chat_time" ON "messages" USING btree ("chat_id","created_at");--> statement-breakpoint
|
|
92
|
+
CREATE INDEX "idx_messages_in_reply_to" ON "messages" USING btree ("in_reply_to");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
-- v2 schema updates
|
|
2
|
+
|
|
3
|
+
-- Add new column to chats table
|
|
4
|
+
ALTER TABLE "chats" ADD COLUMN "parent_chat_id" text;
|
|
5
|
+
|
|
6
|
+
-- Agent presence table
|
|
7
|
+
CREATE TABLE "agent_presence" (
|
|
8
|
+
"agent_id" text PRIMARY KEY REFERENCES "agents"("id") ON DELETE CASCADE,
|
|
9
|
+
"status" text NOT NULL DEFAULT 'offline',
|
|
10
|
+
"instance_id" text,
|
|
11
|
+
"connected_at" timestamptz,
|
|
12
|
+
"last_seen_at" timestamptz NOT NULL DEFAULT NOW()
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
-- Server instances table
|
|
16
|
+
CREATE TABLE "server_instances" (
|
|
17
|
+
"instance_id" text PRIMARY KEY,
|
|
18
|
+
"last_heartbeat" timestamptz NOT NULL DEFAULT NOW()
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- System configs table
|
|
22
|
+
CREATE TABLE "system_configs" (
|
|
23
|
+
"key" text PRIMARY KEY,
|
|
24
|
+
"value" jsonb NOT NULL,
|
|
25
|
+
"updated_at" timestamptz NOT NULL DEFAULT NOW()
|
|
26
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
-- Add lifecycle_policy column to chats
|
|
2
|
+
ALTER TABLE "chats" ADD COLUMN "lifecycle_policy" text DEFAULT 'persistent';
|
|
3
|
+
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
-- Adapter configs: Bot credentials for external platform adapters
|
|
6
|
+
CREATE TABLE "adapter_configs" (
|
|
7
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
8
|
+
"platform" text NOT NULL,
|
|
9
|
+
"agent_id" text,
|
|
10
|
+
"credentials" jsonb NOT NULL,
|
|
11
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
12
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
13
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
--> statement-breakpoint
|
|
17
|
+
-- Adapter chat mappings: internal Chat <-> external IM channel
|
|
18
|
+
CREATE TABLE "adapter_chat_mappings" (
|
|
19
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
20
|
+
"platform" text NOT NULL,
|
|
21
|
+
"external_channel_id" text NOT NULL,
|
|
22
|
+
"chat_id" text NOT NULL,
|
|
23
|
+
"thread_id" text,
|
|
24
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
25
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
26
|
+
);
|
|
27
|
+
--> statement-breakpoint
|
|
28
|
+
CREATE UNIQUE INDEX "uq_adapter_chat_mapping" ON "adapter_chat_mappings" ("platform", "external_channel_id", COALESCE("thread_id", ''));
|
|
29
|
+
|
|
30
|
+
--> statement-breakpoint
|
|
31
|
+
-- Adapter agent mappings: external user identity <-> internal Agent
|
|
32
|
+
CREATE TABLE "adapter_agent_mappings" (
|
|
33
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
34
|
+
"platform" text NOT NULL,
|
|
35
|
+
"external_user_id" text NOT NULL,
|
|
36
|
+
"agent_id" text NOT NULL,
|
|
37
|
+
"bound_via" text,
|
|
38
|
+
"display_name" text,
|
|
39
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
40
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
41
|
+
CONSTRAINT "uq_adapter_agent_mapping" UNIQUE("platform","external_user_id")
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
--> statement-breakpoint
|
|
45
|
+
-- Adapter message references: internal Message <-> external message ID
|
|
46
|
+
CREATE TABLE "adapter_message_references" (
|
|
47
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
48
|
+
"message_id" text NOT NULL,
|
|
49
|
+
"platform" text NOT NULL,
|
|
50
|
+
"external_message_id" text NOT NULL,
|
|
51
|
+
"external_channel_id" text NOT NULL,
|
|
52
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
53
|
+
CONSTRAINT "uq_adapter_message_ref" UNIQUE("message_id","platform")
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
--> statement-breakpoint
|
|
57
|
+
-- Foreign keys for adapter tables
|
|
58
|
+
ALTER TABLE "adapter_configs" ADD CONSTRAINT "adapter_configs_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;
|
|
59
|
+
--> statement-breakpoint
|
|
60
|
+
ALTER TABLE "adapter_chat_mappings" ADD CONSTRAINT "adapter_chat_mappings_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE no action ON UPDATE no action;
|
|
61
|
+
--> statement-breakpoint
|
|
62
|
+
ALTER TABLE "adapter_agent_mappings" ADD CONSTRAINT "adapter_agent_mappings_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;
|
|
63
|
+
--> statement-breakpoint
|
|
64
|
+
ALTER TABLE "adapter_message_references" ADD CONSTRAINT "adapter_message_references_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE no action ON UPDATE no action;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- Webhook event deduplication table
|
|
2
|
+
CREATE TABLE IF NOT EXISTS "processed_events" (
|
|
3
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
4
|
+
"event_id" text NOT NULL,
|
|
5
|
+
"platform" text NOT NULL,
|
|
6
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
7
|
+
CONSTRAINT "uq_processed_event" UNIQUE("event_id","platform")
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
-- Performance indexes for adapter mapping lookups
|
|
11
|
+
CREATE INDEX IF NOT EXISTS "idx_adapter_chat_mappings_lookup"
|
|
12
|
+
ON "adapter_chat_mappings" ("platform", "external_channel_id");
|
|
13
|
+
|
|
14
|
+
CREATE INDEX IF NOT EXISTS "idx_adapter_agent_mappings_lookup"
|
|
15
|
+
ON "adapter_agent_mappings" ("platform", "external_user_id");
|
|
16
|
+
|
|
17
|
+
CREATE INDEX IF NOT EXISTS "idx_adapter_message_refs_lookup"
|
|
18
|
+
ON "adapter_message_references" ("platform", "external_message_id");
|
|
19
|
+
|
|
20
|
+
CREATE INDEX IF NOT EXISTS "idx_adapter_configs_active"
|
|
21
|
+
ON "adapter_configs" ("platform") WHERE "status" = 'active';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- Adapter refactor: agentId required + unique constraint per design doc
|
|
2
|
+
-- Clean up any rows with NULL agent_id before adding NOT NULL constraint
|
|
3
|
+
DELETE FROM "adapter_configs" WHERE "agent_id" IS NULL;
|
|
4
|
+
|
|
5
|
+
--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "adapter_configs" ALTER COLUMN "agent_id" SET NOT NULL;
|
|
7
|
+
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "adapter_configs" ADD CONSTRAINT "uq_adapter_configs_agent_platform" UNIQUE("agent_id", "platform");
|
|
10
|
+
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
-- Drop messages.sender_id FK — agents may be soft-deleted while messages are preserved
|
|
13
|
+
ALTER TABLE "messages" DROP CONSTRAINT IF EXISTS "messages_sender_id_agents_id_fk";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "agents" ADD COLUMN "delegate_mention" text;
|