import { Context } from 'effect' import type { Effect } from 'effect' import type { CreateKnowledgeDocumentInput, IndexedKnowledgeDocument, KnowledgeChunk, KnowledgeDocument, KnowledgeDocumentId, KnowledgeFile, KnowledgeScope, KnowledgeScopeId, KnowledgeSearchScope, UpdateKnowledgeDocumentInput } from './documents.ts' import type { KnowledgeEmbedding } from './embeddings.ts' import type { KnowledgeStoreError, SearchIndexStoreError } from './errors.ts' export type GetKnowledgeDocumentInput = { readonly scope: KnowledgeScope readonly id: KnowledgeDocumentId } export type GetKnowledgeDocumentBySlugInput = { readonly scope: KnowledgeScope readonly slug: string } export type ListKnowledgeDocumentsInput = { readonly scope: KnowledgeScope readonly limit: number readonly availability?: KnowledgeDocument['availability'] } export type ListKnowledgeDocumentsResult = { readonly documents: ReadonlyArray } export type ListPinnedKnowledgeInput = { readonly scope: KnowledgeScope readonly limit: number } export type ListPinnedKnowledgeResult = { readonly documents: ReadonlyArray } export type KnowledgeStoreApi = { readonly createDocument: ( input: CreateKnowledgeDocumentInput ) => Effect.Effect readonly updateDocument: ( input: UpdateKnowledgeDocumentInput ) => Effect.Effect readonly getDocument: ( input: GetKnowledgeDocumentInput ) => Effect.Effect readonly getDocumentBySlug: ( input: GetKnowledgeDocumentBySlugInput ) => Effect.Effect readonly listDocuments: ( input: ListKnowledgeDocumentsInput ) => Effect.Effect readonly listPinned: ( input: ListPinnedKnowledgeInput ) => Effect.Effect readonly deleteDocument: ( input: GetKnowledgeDocumentInput ) => Effect.Effect readonly listFiles: ( input: GetKnowledgeDocumentInput ) => Effect.Effect, KnowledgeStoreError> } export class KnowledgeStore extends Context.Service()( '@yolk-sdk/knowledge/KnowledgeStore' ) {} export type UpsertIndexedKnowledgeDocumentInput = { readonly document: IndexedKnowledgeDocument } export type ReplaceKnowledgeDocumentChunksInput = { readonly scopeId: KnowledgeScopeId readonly documentId: KnowledgeDocumentId readonly chunks: ReadonlyArray<{ readonly chunk: KnowledgeChunk readonly embedding: KnowledgeEmbedding }> } export type MarkKnowledgeDocumentReadyInput = { readonly scopeId: KnowledgeScopeId readonly documentId: KnowledgeDocumentId readonly title?: string readonly summary?: string readonly contentHash?: string readonly tokenCount: number readonly chunkCount: number } export type MarkKnowledgeDocumentErrorInput = { readonly scopeId: KnowledgeScopeId readonly documentId: KnowledgeDocumentId readonly message: string } export type KnowledgeChunkSearchInput = { readonly scope: KnowledgeSearchScope readonly embedding: KnowledgeEmbedding readonly limit: number readonly minScore?: number } export type KnowledgeChunkTextSearchInput = { readonly scope: KnowledgeSearchScope readonly query: string readonly limit: number } export type KnowledgeChunkSearchResult = { readonly chunk: KnowledgeChunk readonly score: number readonly document: IndexedKnowledgeDocument } export type KnowledgeSearchContextChunksInput = { readonly scopeId: KnowledgeScopeId readonly documentId: KnowledgeDocumentId readonly position: number readonly contextChunks: number } export type SearchIndexStoreApi = { readonly upsertDocument: ( input: UpsertIndexedKnowledgeDocumentInput ) => Effect.Effect readonly markDocumentProcessing: (input: { readonly scopeId: KnowledgeScopeId readonly documentId: KnowledgeDocumentId }) => Effect.Effect readonly replaceDocumentChunks: ( input: ReplaceKnowledgeDocumentChunksInput ) => Effect.Effect readonly markDocumentReady: ( input: MarkKnowledgeDocumentReadyInput ) => Effect.Effect readonly markDocumentError: ( input: MarkKnowledgeDocumentErrorInput ) => Effect.Effect readonly deleteDocument: (input: { readonly scopeId: KnowledgeScopeId readonly documentId: KnowledgeDocumentId }) => Effect.Effect readonly searchChunks: ( input: KnowledgeChunkSearchInput ) => Effect.Effect, SearchIndexStoreError> readonly searchChunksByText: ( input: KnowledgeChunkTextSearchInput ) => Effect.Effect, SearchIndexStoreError> readonly getContextChunks: ( input: KnowledgeSearchContextChunksInput ) => Effect.Effect, SearchIndexStoreError> } export class SearchIndexStore extends Context.Service()( '@yolk-sdk/knowledge/SearchIndexStore' ) {}