Move src/ → apps/server/ and packages/web/ → apps/web/ to adopt standard monorepo conventions (apps/ for runnable apps, packages/ for reusable libraries). Update all config files, shared package imports, test fixtures, and documentation to reflect new paths. Key fixes: - Update workspace config to ["apps/*", "packages/*"] - Update tsconfig.json rootDir/include for apps/server/ - Add apps/web/** to vitest exclude list - Update drizzle.config.ts schema path - Fix ensure-schema.ts migration path detection (3 levels up in dev, 2 levels up in dist) - Fix tests/integration/cli-server.test.ts import paths - Update packages/shared imports to apps/server/ paths - Update all docs/ files with new paths
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
/**
|
|
* Drizzle Conversation Repository Adapter
|
|
*
|
|
* Implements ConversationRepository interface using Drizzle ORM.
|
|
*/
|
|
|
|
import { eq, and, asc } from 'drizzle-orm';
|
|
import { nanoid } from 'nanoid';
|
|
import type { DrizzleDatabase } from '../../index.js';
|
|
import { conversations, type Conversation } from '../../schema.js';
|
|
import type { ConversationRepository, CreateConversationData } from '../conversation-repository.js';
|
|
|
|
export class DrizzleConversationRepository implements ConversationRepository {
|
|
constructor(private db: DrizzleDatabase) {}
|
|
|
|
async create(data: CreateConversationData): Promise<Conversation> {
|
|
const now = new Date();
|
|
const id = nanoid();
|
|
await this.db.insert(conversations).values({
|
|
id,
|
|
fromAgentId: data.fromAgentId,
|
|
toAgentId: data.toAgentId,
|
|
initiativeId: data.initiativeId ?? null,
|
|
phaseId: data.phaseId ?? null,
|
|
taskId: data.taskId ?? null,
|
|
question: data.question,
|
|
status: 'pending',
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
});
|
|
return this.findById(id) as Promise<Conversation>;
|
|
}
|
|
|
|
async findById(id: string): Promise<Conversation | null> {
|
|
const rows = await this.db
|
|
.select()
|
|
.from(conversations)
|
|
.where(eq(conversations.id, id))
|
|
.limit(1);
|
|
return rows[0] ?? null;
|
|
}
|
|
|
|
async findPendingForAgent(toAgentId: string): Promise<Conversation[]> {
|
|
return this.db
|
|
.select()
|
|
.from(conversations)
|
|
.where(
|
|
and(
|
|
eq(conversations.toAgentId, toAgentId),
|
|
eq(conversations.status, 'pending' as 'pending' | 'answered'),
|
|
),
|
|
)
|
|
.orderBy(asc(conversations.createdAt));
|
|
}
|
|
|
|
async answer(id: string, answer: string): Promise<Conversation | null> {
|
|
await this.db
|
|
.update(conversations)
|
|
.set({
|
|
answer,
|
|
status: 'answered' as 'pending' | 'answered',
|
|
updatedAt: new Date(),
|
|
})
|
|
.where(eq(conversations.id, id));
|
|
return this.findById(id);
|
|
}
|
|
}
|