src / types.ts
import { z } from "zod";
export const ArtifactSchema = z.object({
id: z.string(),
path: z.string(),
checksum: z.string(),
version: z.number(),
metadata: z.record(z.unknown()).default({}),
createdAt: z.number(),
updatedAt: z.number(),
});
export type Artifact = z.infer<typeof ArtifactSchema>;
export const ChunkSchema = z.object({
id: z.string(),
artifactId: z.string(),
content: z.string(),
startLine: z.number(),
endLine: z.number(),
vector: z.array(z.number()).optional(),
embeddingModel: z.string().optional(),
});
export type Chunk = z.infer<typeof ChunkSchema>;
export const QuerySchema = z.object({
text: z.string().optional(),
artifactId: z.string().optional(),
category: z.string().optional(),
limit: z.number().default(10),
offset: z.number().default(0),
});
export type Query = {
text?: string;
artifactId?: string;
category?: string;
limit?: number;
offset?: number;
};
export const QueryResultSchema = z.object({
chunks: z.array(ChunkSchema),
totalCount: z.number(),
queryTimeMs: z.number(),
});
export type QueryResult = z.infer<typeof QueryResultSchema>;
export const SyncActionSchema = z.enum(["create", "update", "delete"]);
export type SyncAction = z.infer<typeof SyncActionSchema>;
export const SyncEventSchema = z.object({
id: z.string(),
artifactId: z.string(),
action: SyncActionSchema,
timestamp: z.number(),
retries: z.number().default(0),
});
export type SyncEvent = z.infer<typeof SyncEventSchema>;
export const PluginConfigSchema = z.object({
enabled: z.boolean().default(true),
maxChunkSize: z.number().default(1000),
chunkOverlap: z.number().default(50),
syncEnabled: z.boolean().default(true),
maxFileSize: z.number().default(5_000_000),
allowedExtensions: z.array(z.string()).default([".md", ".txt", ".json", ".yaml", ".csv"]),
});
export type PluginConfig = z.infer<typeof PluginConfigSchema>;
export interface ArtifactFSProvider {
readFile(path: string): Promise<string>;
writeFile(path: string, content: string): Promise<Artifact>;
deleteFile(id: string): Promise<void>;
listFiles(path?: string): Promise<Artifact[]>;
queryFiles(query: Query): Promise<QueryResult>;
getChunks(artifactId: string): Promise<Chunk[]>;
sync(): Promise<SyncEvent[]>;
}