codebase-index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  22. .enum(["openai", "ollama", "openai-compatible", "gemini", "mistral", "vercel-ai-gateway", "openrouter"])
  23. .optional(),
  24. codebaseIndexEmbedderBaseUrl: z.string().optional(),
  25. codebaseIndexEmbedderModelId: z.string().optional(),
  26. codebaseIndexEmbedderModelDimension: z.number().optional(),
  27. codebaseIndexSearchMinScore: z.number().min(0).max(1).optional(),
  28. codebaseIndexSearchMaxResults: z
  29. .number()
  30. .min(CODEBASE_INDEX_DEFAULTS.MIN_SEARCH_RESULTS)
  31. .max(CODEBASE_INDEX_DEFAULTS.MAX_SEARCH_RESULTS)
  32. .optional(),
  33. // OpenAI Compatible specific fields
  34. codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
  35. codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
  36. })
  37. export type CodebaseIndexConfig = z.infer<typeof codebaseIndexConfigSchema>
  38. /**
  39. * CodebaseIndexModels
  40. */
  41. export const codebaseIndexModelsSchema = z.object({
  42. openai: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  43. ollama: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  44. "openai-compatible": z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  45. gemini: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  46. mistral: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  47. "vercel-ai-gateway": z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  48. openrouter: z.record(z.string(), z.object({ dimension: z.number() })).optional(),
  49. })
  50. export type CodebaseIndexModels = z.infer<typeof codebaseIndexModelsSchema>
  51. /**
  52. * CdebaseIndexProvider
  53. */
  54. export const codebaseIndexProviderSchema = z.object({
  55. codeIndexOpenAiKey: z.string().optional(),
  56. codeIndexQdrantApiKey: z.string().optional(),
  57. codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
  58. codebaseIndexOpenAiCompatibleApiKey: z.string().optional(),
  59. codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
  60. codebaseIndexGeminiApiKey: z.string().optional(),
  61. codebaseIndexMistralApiKey: z.string().optional(),
  62. codebaseIndexVercelAiGatewayApiKey: z.string().optional(),
  63. codebaseIndexOpenRouterApiKey: z.string().optional(),
  64. })
  65. export type CodebaseIndexProvider = z.infer<typeof codebaseIndexProviderSchema>