Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: add channel type

Gus488409fcb9e9
diff --git a/src/shared/src/db/queries-index.ts b/src/shared/src/db/queries-index.ts
index 949935833..f083d2184 100644
--- a/src/shared/src/db/queries-index.ts
+++ b/src/shared/src/db/queries-index.ts
@@ -19,3 +19,4 @@ export * as workspaceInvite from "./queries/workspace-invite";
export * as agentAccess from "./queries/agent-access";
export * as agentPin from "./queries/agent-pin";
export * as overview from "./queries/overview";
+export * as channel from "./queries/channel";
diff --git a/src/shared/src/db/queries/channel.ts b/src/shared/src/db/queries/channel.ts
new file mode 100644
index 000000000..8f22ea1a2
--- /dev/null
+++ b/src/shared/src/db/queries/channel.ts
@@ -0,0 +1,38 @@
+import { eq, and } from "drizzle-orm";
+import { channel } from "../schema";
+import type { Database } from "../index";
+
+export async function createChannel(
+ db: Database,
+ data: { workspaceId: string; name: string }
+) {
+ const rows = await db
+ .insert(channel)
+ .values({
+ workspaceId: data.workspaceId,
+ name: data.name,
+ })
+ .returning();
+ return rows[0]!;
+}
+
+export async function listChannels(db: Database, workspaceId: string) {
+ return db
+ .select()
+ .from(channel)
+ .where(eq(channel.workspaceId, workspaceId));
+}
+
+export async function getChannelByName(
+ db: Database,
+ workspaceId: string,
+ name: string
+) {
+ const rows = await db
+ .select()
+ .from(channel)
+ .where(
+ and(eq(channel.workspaceId, workspaceId), eq(channel.name, name))
+ );
+ return rows[0] ?? null;
+}
diff --git a/src/shared/src/db/queries/conversation.ts b/src/shared/src/db/queries/conversation.ts
index 816e4f684..c0df2cf2d 100644
--- a/src/shared/src/db/queries/conversation.ts
+++ b/src/shared/src/db/queries/conversation.ts
@@ -12,6 +12,7 @@ export async function createConversation(
userId: string;
title: string;
type?: TaskType;
+ channel?: string;
}
) {
const rows = await db
@@ -22,6 +23,7 @@ export async function createConversation(
userId: data.userId,
title: data.title,
type: data.type ?? TASK_TYPES.USER_DM_MESSAGE,
+ channel: data.channel ?? "default",
})
.returning();
return rows[0]!;
diff --git a/src/shared/src/db/schema.ts b/src/shared/src/db/schema.ts
index 2d9d1d994..0897d673b 100644
--- a/src/shared/src/db/schema.ts
+++ b/src/shared/src/db/schema.ts
@@ -246,6 +246,22 @@ export const agentWhitelist = sqliteTable(
]
);
+export const channel = sqliteTable(
+ "channel",
+ {
+ id: text("id").primaryKey().$defaultFn(() => "ch_" + nanoid()),
+ workspaceId: text("workspace_id")
+ .notNull()
+ .references(() => workspace.id, { onDelete: "cascade" }),
+ name: text("name").notNull(),
+ createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
+ },
+ (t) => [
+ unique("channel_workspace_name").on(t.workspaceId, t.name),
+ index("idx_channel_workspace").on(t.workspaceId),
+ ]
+);
+
export const conversation = sqliteTable(
"conversation",
{
@@ -259,6 +275,7 @@ export const conversation = sqliteTable(
.references(() => user.id, { onDelete: "cascade" }),
title: text("title").notNull().default(""),
type: text("type").notNull().default(TASK_TYPES.USER_DM_MESSAGE),
+ channel: text("channel").notNull().default("default"),
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
},
(t) => [
diff --git a/src/shared/src/index.ts b/src/shared/src/index.ts
index 708524448..082cbe75f 100644
--- a/src/shared/src/index.ts
+++ b/src/shared/src/index.ts
@@ -17,6 +17,7 @@ export type {
LoginResponse,
CreateAgentRequest,
CalendarEvent,
+ Channel,
WsMessage,
} from "./types";
diff --git a/src/shared/src/types.ts b/src/shared/src/types.ts
index e174846d6..fdc3a48f1 100644
--- a/src/shared/src/types.ts
+++ b/src/shared/src/types.ts
@@ -59,10 +59,18 @@ export interface Conversation {
agent_id: string;
title: string;
type: string;
+ channel: string;
created_at: string;
message_count?: number;
}
+export interface Channel {
+ id: string;
+ workspace_id: string;
+ name: string;
+ created_at: string;
+}
+
export interface CalendarEvent {
id: string;
agent_id: string;
diff --git a/src/web/migrations/0013_channels.sql b/src/web/migrations/0013_channels.sql
new file mode 100644
index 000000000..63621d150
--- /dev/null
+++ b/src/web/migrations/0013_channels.sql
@@ -0,0 +1,10 @@
+CREATE TABLE channel (
+ id TEXT PRIMARY KEY,
+ workspace_id TEXT NOT NULL REFERENCES workspace(id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ created_at TEXT NOT NULL,
+ UNIQUE(workspace_id, name)
+);
+CREATE INDEX idx_channel_workspace ON channel(workspace_id);
+
+ALTER TABLE conversation ADD COLUMN channel TEXT NOT NULL DEFAULT 'default';