collections.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Collections configuration management
  3. *
  4. * This module manages the YAML-based collection configuration at ~/.config/qmd/index.yml.
  5. * Collections define which directories to index and their associated contexts.
  6. */
  7. /**
  8. * Context definitions for a collection
  9. * Key is path prefix (e.g., "/", "/2024", "/Board of Directors")
  10. * Value is the context description
  11. */
  12. export type ContextMap = Record<string, string>;
  13. /**
  14. * A single collection configuration
  15. */
  16. export interface Collection {
  17. path: string;
  18. pattern: string;
  19. ignore?: string[];
  20. context?: ContextMap;
  21. update?: string;
  22. includeByDefault?: boolean;
  23. }
  24. /**
  25. * Model configuration for embedding, reranking, and generation
  26. */
  27. export interface ModelsConfig {
  28. embed?: string;
  29. rerank?: string;
  30. generate?: string;
  31. }
  32. /**
  33. * The complete configuration file structure
  34. */
  35. export interface CollectionConfig {
  36. global_context?: string;
  37. editor_uri?: string;
  38. editor_uri_template?: string;
  39. collections: Record<string, Collection>;
  40. models?: ModelsConfig;
  41. }
  42. /**
  43. * Collection with its name (for return values)
  44. */
  45. export interface NamedCollection extends Collection {
  46. name: string;
  47. }
  48. /**
  49. * Set the config source for SDK mode.
  50. * - File path: load/save from a specific YAML file
  51. * - Inline config: use an in-memory CollectionConfig (saveConfig updates in place, no file I/O)
  52. * - undefined: reset to default file-based config
  53. */
  54. export declare function setConfigSource(source?: {
  55. configPath?: string;
  56. config?: CollectionConfig;
  57. }): void;
  58. /**
  59. * Set the current index name for config file lookup
  60. * Config file will be ~/.config/qmd/{indexName}.yml
  61. */
  62. export declare function setConfigIndexName(name: string): void;
  63. /**
  64. * Load configuration from the configured source.
  65. * - Inline config: returns the in-memory object directly
  66. * - File-based: reads from YAML file (default ~/.config/qmd/index.yml)
  67. * Returns empty config if file doesn't exist
  68. */
  69. export declare function loadConfig(): CollectionConfig;
  70. /**
  71. * Save configuration to the configured source.
  72. * - Inline config: updates the in-memory object (no file I/O)
  73. * - File-based: writes to YAML file (default ~/.config/qmd/index.yml)
  74. */
  75. export declare function saveConfig(config: CollectionConfig): void;
  76. /**
  77. * Get a specific collection by name
  78. * Returns null if not found
  79. */
  80. export declare function getCollection(name: string): NamedCollection | null;
  81. /**
  82. * List all collections
  83. */
  84. export declare function listCollections(): NamedCollection[];
  85. /**
  86. * Get collections that are included by default in queries
  87. */
  88. export declare function getDefaultCollections(): NamedCollection[];
  89. /**
  90. * Get collection names that are included by default
  91. */
  92. export declare function getDefaultCollectionNames(): string[];
  93. /**
  94. * Update a collection's settings
  95. */
  96. export declare function updateCollectionSettings(name: string, settings: {
  97. update?: string | null;
  98. includeByDefault?: boolean;
  99. }): boolean;
  100. /**
  101. * Add or update a collection
  102. */
  103. export declare function addCollection(name: string, path: string, pattern?: string): void;
  104. /**
  105. * Remove a collection
  106. */
  107. export declare function removeCollection(name: string): boolean;
  108. /**
  109. * Rename a collection
  110. */
  111. export declare function renameCollection(oldName: string, newName: string): boolean;
  112. /**
  113. * Get global context
  114. */
  115. export declare function getGlobalContext(): string | undefined;
  116. /**
  117. * Set global context
  118. */
  119. export declare function setGlobalContext(context: string | undefined): void;
  120. /**
  121. * Get all contexts for a collection
  122. */
  123. export declare function getContexts(collectionName: string): ContextMap | undefined;
  124. /**
  125. * Add or update a context for a specific path in a collection
  126. */
  127. export declare function addContext(collectionName: string, pathPrefix: string, contextText: string): boolean;
  128. /**
  129. * Remove a context from a collection
  130. */
  131. export declare function removeContext(collectionName: string, pathPrefix: string): boolean;
  132. /**
  133. * List all contexts across all collections
  134. */
  135. export declare function listAllContexts(): Array<{
  136. collection: string;
  137. path: string;
  138. context: string;
  139. }>;
  140. /**
  141. * Find best matching context for a given collection and path
  142. * Returns the most specific matching context (longest path prefix match)
  143. */
  144. export declare function findContextForPath(collectionName: string, filePath: string): string | undefined;
  145. /**
  146. * Get the config file path (useful for error messages)
  147. */
  148. export declare function getConfigPath(): string;
  149. /**
  150. * Check if config file exists
  151. */
  152. export declare function configExists(): boolean;
  153. /**
  154. * Validate a collection name
  155. * Collection names must be valid and not contain special characters
  156. */
  157. export declare function isValidCollectionName(name: string): boolean;