codebase-index.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { z } from "zod"
  2. /**
  3. * Codebase Index Constants
  4. */
  5. export const CODEBASE_INDEX_DEFAULTS = {
  6. MIN_SEARCH_RESULTS: 10,
  7. MAX_SEARCH_RESULTS: 200,
  8. DEFAULT_SEARCH_RESULTS: 50,
  9. SEARCH_RESULTS_STEP: 10,
  10. MIN_SEARCH_SCORE: 0,
  11. MAX_SEARCH_SCORE: 1,
  12. DEFAULT_SEARCH_MIN_SCORE: 0.4,
  13. SEARCH_SCORE_STEP: 0.05,
  14. } as const
  15. /**
  16. * CodebaseIndexConfig
  17. */
  18. export const codebaseIndexConfigSchema = z.object({
  19. codebaseIndexEnabled: z.boolean().optional(),
  20. codebaseIndexQdrantUrl: z.string().optional(),
  21. codebaseIndexEmbedderProvider: z.enum(["openai", "ollama", "openai-compatible", "gemini", "mistral"]).optional(),
  22. codebaseIndexEmbedderBaseUrl: z.string().optional(),
  23. codebaseIndexEmbedderModelId: z.string().optional(),
  24. codebaseIndexEmbedderModelDimension: z.number().optional(),
  25. codebaseIndexSearchMinScore: z.number().min(0).max(1).optional(),
  26. codebaseIndexSearchMaxResults: z
  27. .number()
  28. .min(CODEBASE_INDEX_DEFAULTS.MIN_SEARCH_RESULTS)
  29. .max(CODEBASE_INDEX_DEFAULTS.MAX_SEARCH_RESULTS)
  30. .optional(),
  31. // OpenAI Compatible specific fields
  32. codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
  33. codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
  34. })
  35. export type CodebaseIndexConfig = z.infer<typeof codebaseIndexConfigSchema>
  36. /**
  37. * CodebaseIndexModels
  38. */
  39. export const codebaseIndexModelsSchema = z.object({
  40. openai: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  41. ollama: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  42. "openai-compatible": z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  43. gemini: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  44. mistral: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  45. })
  46. export type CodebaseIndexModels = z.infer<typeof codebaseIndexModelsSchema>
  47. /**
  48. * CdebaseIndexProvider
  49. */
  50. export const codebaseIndexProviderSchema = z.object({
  51. codeIndexOpenAiKey: z.string().optional(),
  52. codeIndexQdrantApiKey: z.string().optional(),
  53. codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
  54. codebaseIndexOpenAiCompatibleApiKey: z.string().optional(),
  55. codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
  56. codebaseIndexGeminiApiKey: z.string().optional(),
  57. codebaseIndexMistralApiKey: z.string().optional(),
  58. })
  59. export type CodebaseIndexProvider = z.infer<typeof codebaseIndexProviderSchema>